import{r as t}from"./chunk-S3R3BYOJ-BD3jWbtJ.js";import{i as e,r as a}from"./src-DK-XqvI0.js";import{B as r,C as s,U as o,_ as i,a as n,c as l,d as c,v as d,y as p,z as h}from"./chunk-ABZYJK2D-C_UkrUYA.js";import{t as k}from"./chunk-EXTU4WIE-Cpgy1tqE.js";import{t as b}from"./chunk-4BX2VUAB-CWGhd0_0.js";import{t as f}from"./mermaid-parser.core-Cj9gkd6P.js";var g=c.packet,u=class{constructor(){this.packet=[],this.setAccTitle=r,this.getAccTitle=d,this.setDiagramTitle=o,this.getDiagramTitle=s,this.getAccDescription=i,this.setAccDescription=h}static{a(this,"PacketDB")}getConfig(){const e=t({...g,...p().packet});return e.showBits&&(e.paddingY+=10),e}getPacket(){return this.packet}pushWord(t){t.length>0&&this.packet.push(t)}clear(){n(),this.packet=[]}},m=a((t,a)=>{b(t,a);let r=-1,s=[],o=1;const{bitsPerRow:i}=a.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??=r+1,n!==r+1)throw new Error(`Packet block ${n} - ${l??n} is not contiguous. It should start from ${r+1}.`);if(0===c)throw new Error(`Packet block ${n} is invalid. Cannot have a zero bit field.`);for(l??=n+(c??1)-1,c??=l-n+1,r=l,e.debug(`Packet block ${n} - ${r} with label ${d}`);s.length<=i+1&&a.getPacket().length<1e4;){const[t,e]=w({start:n,end:l,bits:c,label:d},o,i);if(s.push(t),t.end+1===o*i&&(a.pushWord(s),s=[],o++),!e)break;({start:n,end:l,bits:c,label:d}=e)}}a.pushWord(s)},"populate"),w=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];const r=e*a-1,s=e*a;return[{start:t.start,end:r,label:t.label,bits:r-t.start},{start:s,end:t.end,label:t.label,bits:t.end-s}]},"getNextFittingBlock"),y={parser:{yy:void 0},parse:a(async t=>{const a=await f("packet",t),r=y.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.");e.debug(a),m(a,r)},"parse")},x=a((t,e,a,r)=>{const s=r.db,o=s.getConfig(),{rowHeight:i,paddingY:n,bitWidth:c,bitsPerRow:d}=o,p=s.getPacket(),h=s.getDiagramTitle(),b=i+n,f=b*(p.length+1)-(h?0:i),g=c*d+2,u=k(e);u.attr("viewbox",`0 0 ${g} ${f}`),l(u,f,g,o.useMaxWidth);for(const[l,k]of p.entries())$(u,k,l,o);u.append("text").text(h).attr("x",g/2).attr("y",f-b/2).attr("dominant-baseline","middle").attr("text-anchor","middle").attr("class","packetTitle")},"draw"),$=a((t,e,a,{rowHeight:r,paddingX:s,paddingY:o,bitWidth:i,bitsPerRow:n,showBits:l})=>{const c=t.append("g"),d=a*(r+o)+o;for(const p of e){const t=p.start%n*i+1,e=(p.end-p.start+1)*i-s;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(p.label),!l)continue;const a=p.end===p.start,o=d-2;c.append("text").attr("x",t+(a?e/2:0)).attr("y",o).attr("class","packetByte start").attr("dominant-baseline","auto").attr("text-anchor",a?"middle":"start").text(p.start),a||c.append("text").attr("x",t+e).attr("y",o).attr("class","packetByte end").attr("dominant-baseline","auto").attr("text-anchor","end").text(p.end)}},"drawWord"),B={draw:x},C={byteFontSize:"10px",startByteColor:"black",endByteColor:"black",labelColor:"black",labelFontSize:"12px",titleColor:"black",titleFontSize:"14px",blockStrokeColor:"black",blockStrokeWidth:"1",blockFillColor:"#efefef"},v={parser:y,get db(){return new u},renderer:B,styles:a(({packet:e}={})=>{const a=t(C,e);return`\n\t.packetByte {\n\t\tfont-size: ${a.byteFontSize};\n\t}\n\t.packetByte.start {\n\t\tfill: ${a.startByteColor};\n\t}\n\t.packetByte.end {\n\t\tfill: ${a.endByteColor};\n\t}\n\t.packetLabel {\n\t\tfill: ${a.labelColor};\n\t\tfont-size: ${a.labelFontSize};\n\t}\n\t.packetTitle {\n\t\tfill: ${a.titleColor};\n\t\tfont-size: ${a.titleFontSize};\n\t}\n\t.packetBlock {\n\t\tstroke: ${a.blockStrokeColor};\n\t\tstroke-width: ${a.blockStrokeWidth};\n\t\tfill: ${a.blockFillColor};\n\t}\n\t`},"styles")};export{v as diagram};