var P=e=>{throw TypeError(e)};var y=(e,t,r)=>t.has(e)?P("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,r);import"./index.es.min.CZjstcJ6.js";import{p as S}from"./treemap-KMMF4GRG--FdijCcy.BPiam5wc.js";import"./reduce-BFKSG9Rs.zv3q4g-a.js";import{_ as f,G as x,aj as T,e as D,l as w,b as z,a as A,t as E,v as F,g as W,s as _,H,I,A as L}from"./katex-D8o5-F7C.d_mIDReB.js";import{p as M}from"./chunk-4BX2VUAB-eAYYj1bL._QIYqV1t.js";import"./framework.Cre9sSJa.js";import"./index.BYYR_MCp.js";import"./index.Dyt75KH8.js";import"./flatten-CfPhNHUL.BEJm0GLS.js";var N=H.packet,m,u,$=(m=class{constructor(){this.packet=[],this.setAccTitle=z,this.getAccTitle=A,this.setDiagramTitle=E,this.getDiagramTitle=F,this.getAccDescription=W,this.setAccDescription=_}getConfig(){let t=x({...N,...I().packet});return t.showBits&&(t.paddingY+=10),t}getPacket(){return this.packet}pushWord(t){t.length>0&&this.packet.push(t)}clear(){L(),this.packet=[]}},u=new WeakMap,y(m,u,f(m,"PacketDB")),m),R=1e4,Y=f((e,t)=>{M(e,t);let r=-1,i=[],l=1,{bitsPerRow:n}=t.getConfig();for(let{start:a,end:s,bits:d,label:c}of e.blocks){if(a!==void 0&&s!==void 0&&s<a)throw Error(`Packet block ${a} - ${s} is invalid. End must be greater than start.`);if(a??(a=r+1),a!==r+1)throw Error(`Packet block ${a} - ${s??a} is not contiguous. It should start from ${r+1}.`);if(d===0)throw Error(`Packet block ${a} is invalid. Cannot have a zero bit field.`);for(s??(s=a+(d??1)-1),d??(d=s-a+1),r=s,w.debug(`Packet block ${a} - ${r} with label ${c}`);i.length<=n+1&&t.getPacket().length<R;){let[p,o]=j({start:a,end:s,bits:d,label:c},l,n);if(i.push(p),p.end+1===l*n&&(t.pushWord(i),i=[],l++),!o)break;({start:a,end:s,bits:d,label:c}=o)}}t.pushWord(i)},"populate"),j=f((e,t,r)=>{if(e.start===void 0)throw Error("start should have been set during first phase");if(e.end===void 0)throw Error("end should have been set during first phase");if(e.start>e.end)throw Error(`Block start ${e.start} is greater than block end ${e.end}.`);if(e.end+1<=t*r)return[e,void 0];let i=t*r-1,l=t*r;return[{start:e.start,end:i,label:e.label,bits:i-e.start},{start:l,end:e.end,label:e.label,bits:e.end-l}]},"getNextFittingBlock"),C={parser:{yy:void 0},parse:f(async e=>{var i;let t=await S("packet",e),r=(i=C.parser)==null?void 0:i.yy;if(!(r instanceof $))throw 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.");w.debug(t),Y(t,r)},"parse")},G=f((e,t,r,i)=>{let l=i.db,n=l.getConfig(),{rowHeight:a,paddingY:s,bitWidth:d,bitsPerRow:c}=n,p=l.getPacket(),o=l.getDiagramTitle(),h=a+s,b=h*(p.length+1)-(o?0:a),k=d*c+2,g=T(t);g.attr("viewbox",`0 0 ${k} ${b}`),D(g,b,k,n.useMaxWidth);for(let[B,v]of p.entries())O(g,v,B,n);g.append("text").text(o).attr("x",k/2).attr("y",b-h/2).attr("dominant-baseline","middle").attr("text-anchor","middle").attr("class","packetTitle")},"draw"),O=f((e,t,r,{rowHeight:i,paddingX:l,paddingY:n,bitWidth:a,bitsPerRow:s,showBits:d})=>{let c=e.append("g"),p=r*(i+n)+n;for(let o of t){let h=o.start%s*a+1,b=(o.end-o.start+1)*a-l;if(c.append("rect").attr("x",h).attr("y",p).attr("width",b).attr("height",i).attr("class","packetBlock"),c.append("text").attr("x",h+b/2).attr("y",p+i/2).attr("class","packetLabel").attr("dominant-baseline","middle").attr("text-anchor","middle").text(o.label),!d)continue;let k=o.end===o.start,g=p-2;c.append("text").attr("x",h+(k?b/2:0)).attr("y",g).attr("class","packetByte start").attr("dominant-baseline","auto").attr("text-anchor",k?"middle":"start").text(o.start),k||c.append("text").attr("x",h+b).attr("y",g).attr("class","packetByte end").attr("dominant-baseline","auto").attr("text-anchor","end").text(o.end)}},"drawWord"),K={draw:G},U={byteFontSize:"10px",startByteColor:"black",endByteColor:"black",labelColor:"black",labelFontSize:"12px",titleColor:"black",titleFontSize:"14px",blockStrokeColor:"black",blockStrokeWidth:"1",blockFillColor:"#efefef"},it={parser:C,get db(){return new $},renderer:K,styles:f(({packet:e}={})=>{let t=x(U,e);return`
	.packetByte {
		font-size: ${t.byteFontSize};
	}
	.packetByte.start {
		fill: ${t.startByteColor};
	}
	.packetByte.end {
		fill: ${t.endByteColor};
	}
	.packetLabel {
		fill: ${t.labelColor};
		font-size: ${t.labelFontSize};
	}
	.packetTitle {
		fill: ${t.titleColor};
		font-size: ${t.titleFontSize};
	}
	.packetBlock {
		stroke: ${t.blockStrokeColor};
		stroke-width: ${t.blockStrokeWidth};
		fill: ${t.blockFillColor};
	}
	`},"styles")};export{it as diagram};
