import{_ as t,e,f as r,h as a,l as o,a as s,d as i,s as n,g as l,c as d,b as c,j as p,i as b,k as h}from"./cc0da28d5-D8IdMWNe.js";import{p as k}from"./c3bb327b0-BCpgiKyQ.js";import{p as f}from"./c68b7746e-1ppaZ0uU.js";import"./vendor-react-AXa6hZO5.js";import"./vendor-lodash-D-zrMTUO.js";import"./c2764ca9d-Qp25jDHC.js";import"./c2f2d399f-CK3sZ6oI.js";import"./c6eedc03a-C8LSdtro.js";import"./vendor-intl-BdADXLLt.js";import"./vendor-zod-1gcJXWab.js";import"./vendor-zustand-CcZsBpBq.js";import"./vendor-icons-DsiQAprm.js";import"./vendor-motion-DGh7M6mr.js";import"./vendor-radix-jAWPQP1f.js";import"./vendor-infra-DayZK7Ds.js";import"./vendor-router-B4CxQ1po.js";import"./vendor-query-B8PP3rYl.js";import"./vendor-growthbook-XJcBFzji.js";import"./c34d1f91f-BBY2_7lk.js";var m=p.packet,g=class{constructor(){this.packet=[],this.setAccTitle=s,this.getAccTitle=i,this.setDiagramTitle=n,this.getDiagramTitle=l,this.getAccDescription=d,this.setAccDescription=c}static{t(this,"PacketDB")}getConfig(){const t=e({...m,...b().packet});return t.showBits&&(t.paddingY+=10),t}getPacket(){return this.packet}pushWord(t){t.length>0&&this.packet.push(t)}clear(){h(),this.packet=[]}},u=t((t,e)=>{k(t,e);let r=-1,a=[],s=1;const{bitsPerRow:i}=e.getConfig();for(let{start:n,end:l,bits:d,label:c}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??=r+1,n!==r+1)throw new Error(`Packet block ${n} - ${l??n} is not contiguous. It should start from ${r+1}.`);if(0===d)throw new Error(`Packet block ${n} is invalid. Cannot have a zero bit field.`);for(l??=n+(d??1)-1,d??=l-n+1,r=l,o.debug(`Packet block ${n} - ${r} with label ${c}`);a.length<=i+1&&e.getPacket().length<1e4;){const[t,r]=w({start:n,end:l,bits:d,label:c},s,i);if(a.push(t),t.end+1===s*i&&(e.pushWord(a),a=[],s++),!r)break;({start:n,end:l,bits:d,label:c}=r)}}e.pushWord(a)},"populate"),w=t((t,e,r)=>{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*r)return[t,void 0];const a=e*r-1,o=e*r;return[{start:t.start,end:a,label:t.label,bits:a-t.start},{start:o,end:t.end,label:t.label,bits:t.end-o}]},"getNextFittingBlock"),y={parser:{yy:void 0},parse:t(async t=>{const e=await f("packet",t),r=y.parser?.yy;if(!(r instanceof g))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(e),u(e,r)},"parse")},v=t((t,e,o,s)=>{const i=s.db,n=i.getConfig(),{rowHeight:l,paddingY:d,bitWidth:c,bitsPerRow:p}=n,b=i.getPacket(),h=i.getDiagramTitle(),k=l+d,f=k*(b.length+1)-(h?0:l),m=c*p+2,g=r(e);g.attr("viewBox",`0 0 ${m} ${f}`),a(g,f,m,n.useMaxWidth);for(const[r,a]of b.entries())x(g,a,r,n);g.append("text").text(h).attr("x",m/2).attr("y",f-k/2).attr("dominant-baseline","middle").attr("text-anchor","middle").attr("class","packetTitle")},"draw"),x=t((t,e,r,{rowHeight:a,paddingX:o,paddingY:s,bitWidth:i,bitsPerRow:n,showBits:l})=>{const d=t.append("g"),c=r*(a+s)+s;for(const p of e){const t=p.start%n*i+1,e=(p.end-p.start+1)*i-o;if(d.append("rect").attr("x",t).attr("y",c).attr("width",e).attr("height",a).attr("class","packetBlock"),d.append("text").attr("x",t+e/2).attr("y",c+a/2).attr("class","packetLabel").attr("dominant-baseline","middle").attr("text-anchor","middle").text(p.label),!l)continue;const r=p.end===p.start,s=c-2;d.append("text").attr("x",t+(r?e/2:0)).attr("y",s).attr("class","packetByte start").attr("dominant-baseline","auto").attr("text-anchor",r?"middle":"start").text(p.start),r||d.append("text").attr("x",t+e).attr("y",s).attr("class","packetByte end").attr("dominant-baseline","auto").attr("text-anchor","end").text(p.end)}},"drawWord"),$={draw:v},j={byteFontSize:"10px",startByteColor:"black",endByteColor:"black",labelColor:"black",labelFontSize:"12px",titleColor:"black",titleFontSize:"14px",blockStrokeColor:"black",blockStrokeWidth:"1",blockFillColor:"#efefef"},B=t(({packet:t}={})=>{const r=e(j,t);return`\n\t.packetByte {\n\t\tfont-size: ${r.byteFontSize};\n\t}\n\t.packetByte.start {\n\t\tfill: ${r.startByteColor};\n\t}\n\t.packetByte.end {\n\t\tfill: ${r.endByteColor};\n\t}\n\t.packetLabel {\n\t\tfill: ${r.labelColor};\n\t\tfont-size: ${r.labelFontSize};\n\t}\n\t.packetTitle {\n\t\tfill: ${r.titleColor};\n\t\tfont-size: ${r.titleFontSize};\n\t}\n\t.packetBlock {\n\t\tstroke: ${r.blockStrokeColor};\n\t\tstroke-width: ${r.blockStrokeWidth};\n\t\tfill: ${r.blockFillColor};\n\t}\n\t`},"styles"),C={parser:y,get db(){return new g},renderer:$,styles:B};export{C as diagram};
