1 line
No EOL
4.2 KiB
JavaScript
1 line
No EOL
4.2 KiB
JavaScript
"use strict";(globalThis.webpackChunkopenrag_docs=globalThis.webpackChunkopenrag_docs||[]).push([[6567],{6567:(t,e,a)=>{a.d(e,{diagram:()=>$});var r=a(3590),o=a(5871),i=a(3226),n=a(7633),s=a(797),l=a(8731),c=n.UI.packet,d=class{constructor(){this.packet=[],this.setAccTitle=n.SV,this.getAccTitle=n.iN,this.setDiagramTitle=n.ke,this.getDiagramTitle=n.ab,this.getAccDescription=n.m7,this.setAccDescription=n.EI}static{(0,s.K2)(this,"PacketDB")}getConfig(){const t=(0,i.$t)({...c,...(0,n.zj)().packet});return t.showBits&&(t.paddingY+=10),t}getPacket(){return this.packet}pushWord(t){t.length>0&&this.packet.push(t)}clear(){(0,n.IU)(),this.packet=[]}},b=(0,s.K2)((t,e)=>{(0,o.S)(t,e);let a=-1,r=[],i=1;const{bitsPerRow:n}=e.getConfig();for(let{start:o,end:l,bits:c,label:d}of t.blocks){if(void 0!==o&&void 0!==l&&l<o)throw new Error(`Packet block ${o} - ${l} is invalid. End must be greater than start.`);if(o??=a+1,o!==a+1)throw new Error(`Packet block ${o} - ${l??o} is not contiguous. It should start from ${a+1}.`);if(0===c)throw new Error(`Packet block ${o} is invalid. Cannot have a zero bit field.`);for(l??=o+(c??1)-1,c??=l-o+1,a=l,s.Rm.debug(`Packet block ${o} - ${a} with label ${d}`);r.length<=n+1&&e.getPacket().length<1e4;){const[t,a]=h({start:o,end:l,bits:c,label:d},i,n);if(r.push(t),t.end+1===i*n&&(e.pushWord(r),r=[],i++),!a)break;({start:o,end:l,bits:c,label:d}=a)}}e.pushWord(r)},"populate"),h=(0,s.K2)((t,e,a)=>{if(void 0===t.start)throw new Error("start should have been set during first phase");if(void 0===t.end)throw new Error("end should have been set during first phase");if(t.start>t.end)throw new Error(`Block start ${t.start} is greater than block end ${t.end}.`);if(t.end+1<=e*a)return[t,void 0];const r=e*a-1,o=e*a;return[{start:t.start,end:r,label:t.label,bits:r-t.start},{start:o,end:t.end,label:t.label,bits:t.end-o}]},"getNextFittingBlock"),p={parser:{yy:void 0},parse:(0,s.K2)(async t=>{const e=await(0,l.qg)("packet",t),a=p.parser?.yy;if(!(a instanceof d))throw new Error("parser.parser?.yy was not a PacketDB. This is due to a bug within Mermaid, please report this issue at https://github.com/mermaid-js/mermaid/issues.");s.Rm.debug(e),b(e,a)},"parse")},k=(0,s.K2)((t,e,a,o)=>{const i=o.db,s=i.getConfig(),{rowHeight:l,paddingY:c,bitWidth:d,bitsPerRow:b}=s,h=i.getPacket(),p=i.getDiagramTitle(),k=l+c,f=k*(h.length+1)-(p?0:l),u=d*b+2,w=(0,r.D)(e);w.attr("viewbox",`0 0 ${u} ${f}`),(0,n.a$)(w,f,u,s.useMaxWidth);for(const[r,n]of h.entries())g(w,n,r,s);w.append("text").text(p).attr("x",u/2).attr("y",f-k/2).attr("dominant-baseline","middle").attr("text-anchor","middle").attr("class","packetTitle")},"draw"),g=(0,s.K2)((t,e,a,{rowHeight:r,paddingX:o,paddingY:i,bitWidth:n,bitsPerRow:s,showBits:l})=>{const c=t.append("g"),d=a*(r+i)+i;for(const b of e){const t=b.start%s*n+1,e=(b.end-b.start+1)*n-o;if(c.append("rect").attr("x",t).attr("y",d).attr("width",e).attr("height",r).attr("class","packetBlock"),c.append("text").attr("x",t+e/2).attr("y",d+r/2).attr("class","packetLabel").attr("dominant-baseline","middle").attr("text-anchor","middle").text(b.label),!l)continue;const a=b.end===b.start,i=d-2;c.append("text").attr("x",t+(a?e/2:0)).attr("y",i).attr("class","packetByte start").attr("dominant-baseline","auto").attr("text-anchor",a?"middle":"start").text(b.start),a||c.append("text").attr("x",t+e).attr("y",i).attr("class","packetByte end").attr("dominant-baseline","auto").attr("text-anchor","end").text(b.end)}},"drawWord"),f={draw:k},u={byteFontSize:"10px",startByteColor:"black",endByteColor:"black",labelColor:"black",labelFontSize:"12px",titleColor:"black",titleFontSize:"14px",blockStrokeColor:"black",blockStrokeWidth:"1",blockFillColor:"#efefef"},w=(0,s.K2)(({packet:t}={})=>{const e=(0,i.$t)(u,t);return`\n\t.packetByte {\n\t\tfont-size: ${e.byteFontSize};\n\t}\n\t.packetByte.start {\n\t\tfill: ${e.startByteColor};\n\t}\n\t.packetByte.end {\n\t\tfill: ${e.endByteColor};\n\t}\n\t.packetLabel {\n\t\tfill: ${e.labelColor};\n\t\tfont-size: ${e.labelFontSize};\n\t}\n\t.packetTitle {\n\t\tfill: ${e.titleColor};\n\t\tfont-size: ${e.titleFontSize};\n\t}\n\t.packetBlock {\n\t\tstroke: ${e.blockStrokeColor};\n\t\tstroke-width: ${e.blockStrokeWidth};\n\t\tfill: ${e.blockFillColor};\n\t}\n\t`},"styles"),$={parser:p,get db(){return new d},renderer:f,styles:w}}}]); |