import{p as t}from"./c319b1ab1-DziMGCl9.js";import{_ as e,c as a,s as r,a as s,l as o,b as i,g as n,d as l,e as c,f as d,h as p,i as b,j as h,k}from"./c62760c51-8U2GJV_7.js";import{p as f}from"./cb7102abf-MK-Y_acg.js";import"./vendor--leCAzSo.js";import"./c2764ca9d-BNXd70jc.js";import"./c627fcdb6-StvihmuW.js";import"./ca9c256b9-7brFE8T2.js";import"./c2591c98b-qkhNq09y.js";import"./c51e217b4-KUwQQl_W.js";var g=b.packet,m=class{constructor(){this.packet=[],this.setAccTitle=i,this.getAccTitle=n,this.setDiagramTitle=l,this.getDiagramTitle=c,this.getAccDescription=d,this.setAccDescription=p}static{e(this,"PacketDB")}getConfig(){const t=a({...g,...h().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=[]}},u=e((e,a)=>{t(e,a);let r=-1,s=[],i=1;const{bitsPerRow:n}=a.getConfig();for(let{start:t,end:l,bits:c,label:d}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===c)throw new Error(`Packet block ${t} is invalid. Cannot have a zero bit field.`);for(l??=t+(c??1)-1,c??=l-t+1,r=l,o.debug(`Packet block ${t} - ${r} with label ${d}`);s.length<=n+1&&a.getPacket().length<1e4;){const[e,r]=w({start:t,end:l,bits:c,label:d},i,n);if(s.push(e),e.end+1===i*n&&(a.pushWord(s),s=[],i++),!r)break;({start:t,end:l,bits:c,label:d}=r)}}a.pushWord(s)},"populate"),w=e((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:e(async t=>{const e=await f("packet",t),a=y.parser?.yy;if(!(a instanceof m))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,a)},"parse")},x=e((t,e,a,o)=>{const i=o.db,n=i.getConfig(),{rowHeight:l,paddingY:c,bitWidth:d,bitsPerRow:p}=n,b=i.getPacket(),h=i.getDiagramTitle(),k=l+c,f=k*(b.length+1)-(h?0:l),g=d*p+2,m=r(e);m.attr("viewbox",`0 0 ${g} ${f}`),s(m,f,g,n.useMaxWidth);for(const[r,s]of b.entries())$(m,s,r,n);m.append("text").text(h).attr("x",g/2).attr("y",f-k/2).attr("dominant-baseline","middle").attr("text-anchor","middle").attr("class","packetTitle")},"draw"),$=e((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=e(({packet:t}={})=>{const e=a(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:y,get db(){return new m},renderer:B,styles:v};export{P as diagram};
