import{a as T}from"./chunk-IVXEP2GX.js";import{a as D}from"./chunk-5VULEZUR.js";import"./chunk-I7AX7T7O.js";import"./chunk-XK4G7G7T.js";import"./chunk-VEXGBG23.js";import"./chunk-3UY5EKAG.js";import"./chunk-VWRMTJIG.js";import"./chunk-UKDM673Y.js";import{a as E}from"./chunk-E44FJ4V5.js";import{l as w}from"./chunk-EC3EU6U5.js";import"./chunk-T62BAALO.js";import{L as v,P as B,Q as C,R as P,S,T as z,U as F,V as W,p as x,x as $}from"./chunk-JB23YLA3.js";import{b as u}from"./chunk-TUEROSNP.js";import"./chunk-PLDLE5YP.js";import"./chunk-YFOJOJKZ.js";import"./chunk-EIBZ4D3G.js";import"./chunk-N4TPONBE.js";import"./chunk-WCWYUUX6.js";import{a as g,g as y,h}from"./chunk-7DHJDT2N.js";var Y=x.packet,A=class{constructor(){this.packet=[],this.setAccTitle=C,this.getAccTitle=P,this.setDiagramTitle=F,this.getDiagramTitle=W,this.getAccDescription=z,this.setAccDescription=S}static{h(this,"PacketDB")}getConfig(){let t=w(g(g({},Y),$().packet));return t.showBits&&(t.paddingY+=10),t}getPacket(){return this.packet}pushWord(t){t.length>0&&this.packet.push(t)}clear(){B(),this.packet=[]}},j=1e4,q=h((t,e)=>{T(t,e);let a=-1,i=[],l=1,{bitsPerRow:n}=e.getConfig();for(let{start:r,end:s,bits:p,label:d}of t.blocks){if(r!==void 0&&s!==void 0&&s<r)throw new Error(`Packet block ${r} - ${s} is invalid. End must be greater than start.`);if(r??=a+1,r!==a+1)throw new Error(`Packet block ${r} - ${s??r} is not contiguous. It should start from ${a+1}.`);if(p===0)throw new Error(`Packet block ${r} is invalid. Cannot have a zero bit field.`);for(s??=r+(p??1)-1,p??=s-r+1,a=s,u.debug(`Packet block ${r} - ${a} with label ${d}`);i.length<=n+1&&e.getPacket().length<j;){let[c,o]=H({start:r,end:s,bits:p,label:d},l,n);if(i.push(c),c.end+1===l*n&&(e.pushWord(i),i=[],l++),!o)break;({start:r,end:s,bits:p,label:d}=o)}}e.pushWord(i)},"populate"),H=h((t,e,a)=>{if(t.start===void 0)throw new Error("start should have been set during first phase");if(t.end===void 0)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 i=e*a-1,l=e*a;return[{start:t.start,end:i,label:t.label,bits:i-t.start},{start:l,end:t.end,label:t.label,bits:t.end-l}]},"getNextFittingBlock"),R={parser:{yy:void 0},parse:h(t=>y(null,null,function*(){let e=yield D("packet",t),a=R.parser?.yy;if(!(a instanceof A))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.");u.debug(e),q(e,a)}),"parse")},N=h((t,e,a,i)=>{let l=i.db,n=l.getConfig(),{rowHeight:r,paddingY:s,bitWidth:p,bitsPerRow:d}=n,c=l.getPacket(),o=l.getDiagramTitle(),k=r+s,b=k*(c.length+1)-(o?0:r),m=p*d+2,f=E(e);f.attr("viewbox",`0 0 ${m} ${b}`),v(f,b,m,n.useMaxWidth);for(let[L,M]of c.entries())O(f,M,L,n);f.append("text").text(o).attr("x",m/2).attr("y",b-k/2).attr("dominant-baseline","middle").attr("text-anchor","middle").attr("class","packetTitle")},"draw"),O=h((t,e,a,{rowHeight:i,paddingX:l,paddingY:n,bitWidth:r,bitsPerRow:s,showBits:p})=>{let d=t.append("g"),c=a*(i+n)+n;for(let o of e){let k=o.start%s*r+1,b=(o.end-o.start+1)*r-l;if(d.append("rect").attr("x",k).attr("y",c).attr("width",b).attr("height",i).attr("class","packetBlock"),d.append("text").attr("x",k+b/2).attr("y",c+i/2).attr("class","packetLabel").attr("dominant-baseline","middle").attr("text-anchor","middle").text(o.label),!p)continue;let m=o.end===o.start,f=c-2;d.append("text").attr("x",k+(m?b/2:0)).attr("y",f).attr("class","packetByte start").attr("dominant-baseline","auto").attr("text-anchor",m?"middle":"start").text(o.start),m||d.append("text").attr("x",k+b).attr("y",f).attr("class","packetByte end").attr("dominant-baseline","auto").attr("text-anchor","end").text(o.end)}},"drawWord"),G={draw:N},I={byteFontSize:"10px",startByteColor:"black",endByteColor:"black",labelColor:"black",labelFontSize:"12px",titleColor:"black",titleFontSize:"14px",blockStrokeColor:"black",blockStrokeWidth:"1",blockFillColor:"#efefef"},Q=h(({packet:t}={})=>{let e=w(I,t);return`
	.packetByte {
		font-size: ${e.byteFontSize};
	}
	.packetByte.start {
		fill: ${e.startByteColor};
	}
	.packetByte.end {
		fill: ${e.endByteColor};
	}
	.packetLabel {
		fill: ${e.labelColor};
		font-size: ${e.labelFontSize};
	}
	.packetTitle {
		fill: ${e.titleColor};
		font-size: ${e.titleFontSize};
	}
	.packetBlock {
		stroke: ${e.blockStrokeColor};
		stroke-width: ${e.blockStrokeWidth};
		fill: ${e.blockFillColor};
	}
	`},"styles"),bt={parser:R,get db(){return new A},renderer:G,styles:Q};export{bt as diagram};
