import{_ as f,E as b,I as $,d as B,l as u,b as C,a as S,p as D,q as T,g as E,s as F,F as P,G as z,y as A}from"./mermaid.core-BpC-PC5Q.js";import{p as W}from"./chunk-4BX2VUAB-CNRgqLX7.js";import{p as _}from"./mermaid-parser.core-BtU_vgPO.js";import"./index-Ds2meNS5.js";import"./svelte/svelte_svelte.js";import"./svelte/svelte_animate.js";import"./svelte/svelte_attachments.js";import"./svelte/svelte_easing.js";import"./svelte/svelte_internal_client.js";import"./svelte/svelte_internal_flags_async.js";import"./svelte/svelte_internal_flags_legacy.js";import"./svelte/svelte_internal_flags_tracing.js";import"./svelte/svelte_internal_server.js";import"./svelte/svelte_legacy.js";import"./svelte/svelte_motion.js";import"./svelte/svelte_reactivity.js";import"./svelte/svelte_reactivity_window.js";import"./svelte/svelte_server.js";import"./svelte/svelte_store.js";import"./svelte/svelte_transition.js";import"./svelte/svelte_events.js";import"./i18n-BldJSFLV.js";import"./step-ChYay-CR.js";import"./dispatch-kxCwF96_.js";import"./select-BigU4G0v.js";import"./_baseUniq-5LrHMaZn.js";import"./_basePickBy-BwaeXrxs.js";import"./clone-BetsKl5T.js";var N=z.packet,w=class{constructor(){this.packet=[],this.setAccTitle=C,this.getAccTitle=S,this.setDiagramTitle=D,this.getDiagramTitle=T,this.getAccDescription=E,this.setAccDescription=F}static{f(this,"PacketDB")}getConfig(){const t=b({...N,...P().packet});return t.showBits&&(t.paddingY+=10),t}getPacket(){return this.packet}pushWord(t){t.length>0&&this.packet.push(t)}clear(){A(),this.packet=[]}},I=1e4,L=f((t,e)=>{W(t,e);let a=-1,o=[],n=1;const{bitsPerRow:l}=e.getConfig();for(let{start:r,end:s,bits:p,label:c}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 ${c}`);o.length<=l+1&&e.getPacket().length<I;){const[d,i]=M({start:r,end:s,bits:p,label:c},n,l);if(o.push(d),d.end+1===n*l&&(e.pushWord(o),o=[],n++),!i)break;({start:r,end:s,bits:p,label:c}=i)}}e.pushWord(o)},"populate"),M=f((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];const o=e*a-1,n=e*a;return[{start:t.start,end:o,label:t.label,bits:o-t.start},{start:n,end:t.end,label:t.label,bits:t.end-n}]},"getNextFittingBlock"),v={parser:{yy:void 0},parse:f(async t=>{const e=await _("packet",t),a=v.parser?.yy;if(!(a instanceof w))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),L(e,a)},"parse")},Y=f((t,e,a,o)=>{const n=o.db,l=n.getConfig(),{rowHeight:r,paddingY:s,bitWidth:p,bitsPerRow:c}=l,d=n.getPacket(),i=n.getDiagramTitle(),m=r+s,g=m*(d.length+1)-(i?0:r),h=p*c+2,k=$(e);k.attr("viewbox",`0 0 ${h} ${g}`),B(k,g,h,l.useMaxWidth);for(const[x,y]of d.entries())G(k,y,x,l);k.append("text").text(i).attr("x",h/2).attr("y",g-m/2).attr("dominant-baseline","middle").attr("text-anchor","middle").attr("class","packetTitle")},"draw"),G=f((t,e,a,{rowHeight:o,paddingX:n,paddingY:l,bitWidth:r,bitsPerRow:s,showBits:p})=>{const c=t.append("g"),d=a*(o+l)+l;for(const i of e){const m=i.start%s*r+1,g=(i.end-i.start+1)*r-n;if(c.append("rect").attr("x",m).attr("y",d).attr("width",g).attr("height",o).attr("class","packetBlock"),c.append("text").attr("x",m+g/2).attr("y",d+o/2).attr("class","packetLabel").attr("dominant-baseline","middle").attr("text-anchor","middle").text(i.label),!p)continue;const h=i.end===i.start,k=d-2;c.append("text").attr("x",m+(h?g/2:0)).attr("y",k).attr("class","packetByte start").attr("dominant-baseline","auto").attr("text-anchor",h?"middle":"start").text(i.start),h||c.append("text").attr("x",m+g).attr("y",k).attr("class","packetByte end").attr("dominant-baseline","auto").attr("text-anchor","end").text(i.end)}},"drawWord"),O={draw:Y},j={byteFontSize:"10px",startByteColor:"black",endByteColor:"black",labelColor:"black",labelFontSize:"12px",titleColor:"black",titleFontSize:"14px",blockStrokeColor:"black",blockStrokeWidth:"1",blockFillColor:"#efefef"},q=f(({packet:t}={})=>{const e=b(j,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"),wt={parser:v,get db(){return new w},renderer:O,styles:q};export{wt as diagram};
