const e=require("./custom-Bl_fVJZ0.cjs"),t=require("./src-BMjps4Ui.cjs"),n=require("./chunk-ABZYJK2D-CbIYYZa_.cjs"),r=require("./chunk-S3R3BYOJ-B2ozcJNg.cjs"),i=require("./mermaid-parser.core-C9EbhVVg.cjs"),a=require("./chunk-4BX2VUAB-HXFjpyQg.cjs");var o=n.d.packet,s=class{constructor(){this.packet=[],this.setAccTitle=n.B,this.getAccTitle=n.v,this.setDiagramTitle=n.U,this.getDiagramTitle=n.C,this.getAccDescription=n._,this.setAccDescription=n.z}static{t.h(this,`PacketDB`)}getConfig(){let e=r.r({...o,...n.y().packet});return e.showBits&&(e.paddingY+=10),e}getPacket(){return this.packet}pushWord(e){e.length>0&&this.packet.push(e)}clear(){n.a(),this.packet=[]}},c=1e4,l=t.h((e,n)=>{a.t(e,n);let r=-1,i=[],o=1,{bitsPerRow:s}=n.getConfig();for(let{start:a,end:l,bits:d,label:f}of e.blocks){if(a!==void 0&&l!==void 0&&l<a)throw Error(`Packet block ${a} - ${l} is invalid. End must be greater than start.`);if(a??=r+1,a!==r+1)throw Error(`Packet block ${a} - ${l??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(l??=a+(d??1)-1,d??=l-a+1,r=l,t.g.debug(`Packet block ${a} - ${r} with label ${f}`);i.length<=s+1&&n.getPacket().length<c;){let[e,t]=u({start:a,end:l,bits:d,label:f},o,s);if(i.push(e),e.end+1===o*s&&(n.pushWord(i),i=[],o++),!t)break;({start:a,end:l,bits:d,label:f}=t)}}n.pushWord(i)},`populate`),u=t.h((e,t,n)=>{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*n)return[e,void 0];let r=t*n-1,i=t*n;return[{start:e.start,end:r,label:e.label,bits:r-e.start},{start:i,end:e.end,label:e.label,bits:e.end-i}]},`getNextFittingBlock`),d={parser:{yy:void 0},parse:t.h(async e=>{let n=await i.t(`packet`,e),r=d.parser?.yy;if(!(r instanceof s))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.`);t.g.debug(n),l(n,r)},`parse`)},f=t.h((t,r,i,a)=>{let o=a.db,s=o.getConfig(),{rowHeight:c,paddingY:l,bitWidth:u,bitsPerRow:d}=s,f=o.getPacket(),m=o.getDiagramTitle(),h=c+l,g=h*(f.length+1)-(m?0:c),_=u*d+2,v=e.f(r);v.attr(`viewbox`,`0 0 ${_} ${g}`),n.c(v,g,_,s.useMaxWidth);for(let[e,t]of f.entries())p(v,t,e,s);v.append(`text`).text(m).attr(`x`,_/2).attr(`y`,g-h/2).attr(`dominant-baseline`,`middle`).attr(`text-anchor`,`middle`).attr(`class`,`packetTitle`)},`draw`),p=t.h((e,t,n,{rowHeight:r,paddingX:i,paddingY:a,bitWidth:o,bitsPerRow:s,showBits:c})=>{let l=e.append(`g`),u=n*(r+a)+a;for(let e of t){let t=e.start%s*o+1,n=(e.end-e.start+1)*o-i;if(l.append(`rect`).attr(`x`,t).attr(`y`,u).attr(`width`,n).attr(`height`,r).attr(`class`,`packetBlock`),l.append(`text`).attr(`x`,t+n/2).attr(`y`,u+r/2).attr(`class`,`packetLabel`).attr(`dominant-baseline`,`middle`).attr(`text-anchor`,`middle`).text(e.label),!c)continue;let a=e.end===e.start,d=u-2;l.append(`text`).attr(`x`,t+(a?n/2:0)).attr(`y`,d).attr(`class`,`packetByte start`).attr(`dominant-baseline`,`auto`).attr(`text-anchor`,a?`middle`:`start`).text(e.start),a||l.append(`text`).attr(`x`,t+n).attr(`y`,d).attr(`class`,`packetByte end`).attr(`dominant-baseline`,`auto`).attr(`text-anchor`,`end`).text(e.end)}},`drawWord`),m={draw:f},h={byteFontSize:`10px`,startByteColor:`black`,endByteColor:`black`,labelColor:`black`,labelFontSize:`12px`,titleColor:`black`,titleFontSize:`14px`,blockStrokeColor:`black`,blockStrokeWidth:`1`,blockFillColor:`#efefef`},g={parser:d,get db(){return new s},renderer:m,styles:t.h(({packet:e}={})=>{let t=r.r(h,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`)};exports.diagram=g;