import{c as t}from"./chunk-4KE642ED-D2VUabb0.js";import{p as e}from"./treemap-KMMF4GRG-7ORZ52ND-DFBaIa1s.js";import{m as a,L as r,a6 as i,W as s,p as o,H as n,U as l,j as d,e as c,$ as p,G as h,O as b,r as k,N as g}from"./index-BDq3hoFe.js";import"./chunk-OMTJKCYW-D0VGaEv2.js";var f=k.packet,u=class{constructor(){this.packet=[],this.setAccTitle=n,this.getAccTitle=l,this.setDiagramTitle=d,this.getDiagramTitle=c,this.getAccDescription=p,this.setAccDescription=h}static{a(this,"PacketDB")}getConfig(){let t=r({...f,...b().packet});return t.showBits&&(t.paddingY+=10),t}getPacket(){return this.packet}pushWord(t){t.length>0&&this.packet.push(t)}clear(){g(),this.packet=[]}},w=a((e,a)=>{t(e,a);let r=-1,i=[],s=1,{bitsPerRow:n}=a.getConfig();for(let{start:t,end:l,bits:d,label:c}of e.blocks){if(void 0!==t&&void 0!==l&&l<t)throw new Error(`Packet block ${t} - ${l} is invalid. End must be greater than start.`);if(t??=r+1,t!==r+1)throw new Error(`Packet block ${t} - ${l??t} is not contiguous. It should start from ${r+1}.`);if(0===d)throw new Error(`Packet block ${t} is invalid. Cannot have a zero bit field.`);for(l??=t+(d??1)-1,d??=l-t+1,r=l,o.debug(`Packet block ${t} - ${r} with label ${c}`);i.length<=n+1&&a.getPacket().length<1e4;){let[e,r]=m({start:t,end:l,bits:d,label:c},s,n);if(i.push(e),e.end+1===s*n&&(a.pushWord(i),i=[],s++),!r)break;({start:t,end:l,bits:d,label:c}=r)}}a.pushWord(i)},"populate"),m=a((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];let r=e*a-1,i=e*a;return[{start:t.start,end:r,label:t.label,bits:r-t.start},{start:i,end:t.end,label:t.label,bits:t.end-i}]},"getNextFittingBlock"),x={parser:{yy:void 0},parse:a(async t=>{let a=await e("packet",t),r=x.parser?.yy;if(!(r instanceof u))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.");o.debug(a),w(a,r)},"parse")},y=a((t,e,a,r)=>{let o=r.db,n=o.getConfig(),{rowHeight:l,paddingY:d,bitWidth:c,bitsPerRow:p}=n,h=o.getPacket(),b=o.getDiagramTitle(),k=l+d,g=k*(h.length+1)-(b?0:l),f=c*p+2,u=i(e);u.attr("viewbox",`0 0 ${f} ${g}`),s(u,g,f,n.useMaxWidth);for(let[t,e]of h.entries())$(u,e,t,n);u.append("text").text(b).attr("x",f/2).attr("y",g-k/2).attr("dominant-baseline","middle").attr("text-anchor","middle").attr("class","packetTitle")},"draw"),$=a((t,e,a,{rowHeight:r,paddingX:i,paddingY:s,bitWidth:o,bitsPerRow:n,showBits:l})=>{let d=t.append("g"),c=a*(r+s)+s;for(let t of e){let e=t.start%n*o+1,a=(t.end-t.start+1)*o-i;if(d.append("rect").attr("x",e).attr("y",c).attr("width",a).attr("height",r).attr("class","packetBlock"),d.append("text").attr("x",e+a/2).attr("y",c+r/2).attr("class","packetLabel").attr("dominant-baseline","middle").attr("text-anchor","middle").text(t.label),!l)continue;let s=t.end===t.start,p=c-2;d.append("text").attr("x",e+(s?a/2:0)).attr("y",p).attr("class","packetByte start").attr("dominant-baseline","auto").attr("text-anchor",s?"middle":"start").text(t.start),s||d.append("text").attr("x",e+a).attr("y",p).attr("class","packetByte end").attr("dominant-baseline","auto").attr("text-anchor","end").text(t.end)}},"drawWord"),B={draw:y},C={byteFontSize:"10px",startByteColor:"black",endByteColor:"black",labelColor:"black",labelFontSize:"12px",titleColor:"black",titleFontSize:"14px",blockStrokeColor:"black",blockStrokeWidth:"1",blockFillColor:"#efefef"},v=a(({packet:t}={})=>{let e=r(C,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"),P={parser:x,get db(){return new u},renderer:B,styles:v};export{P as diagram};
//# sourceMappingURL=diagram-BZV4OSZQ-Dg9e8R6Y.js.map
