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