import{_ as f,D as u,H as B,e as C,l as v,b as S,a as D,p as T,q as E,g as F,s as P,E as z,F as A,y as _}from"./mermaid.core-BN1TdaiK-CkX93Jpj.js";import{p as W}from"./chunk-4BX2VUAB-CxusDcOF-BgF98TWZ.js";import{p as N}from"./treemap-KMMF4GRG-CvaGS1yA-NJdGYCDs.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"./Index-BpHS9YhG.js";import"./i18n-BldJSFLV.js";import"./utils.svelte-Ceck75cM.js";import"./index-tFQomdd2.js";import"./dsv-DB8NKgIY.js";import"./index-CnqicUFC.js";import"./ModifyUpload-BzsLgPw2.js";import"./IconButtonWrapper-Cljb5D-5.js";import"./MarkdownCode-C2b9iIxl.js";import"./prism-python-CpYAgONt.js";import"./Index-aAgh1OXe.js";import"./StreamingBar-b2qVLPYU.js";import"./FullscreenButton-Cqzqqtq6.js";import"./Example-BRN12iqL.js";import"./_baseUniq-BCzTs16Z-BRql6QeN.js";import"./_basePickBy-BSV_1zpR-D13SnWW2.js";import"./clone-04FuOcyX-A55wydoQ.js";var b,L=A.packet,w=(b=class{constructor(){this.packet=[],this.setAccTitle=S,this.getAccTitle=D,this.setDiagramTitle=T,this.getDiagramTitle=E,this.getAccDescription=F,this.setAccDescription=P}getConfig(){const t=u({...L,...z().packet});return t.showBits&&(t.paddingY+=10),t}getPacket(){return this.packet}pushWord(t){t.length>0&&this.packet.push(t)}clear(){_(),this.packet=[]}},f(b,"PacketDB"),b),M=1e4,Y=f((t,e)=>{W(t,e);let o=-1,a=[],n=1;const{bitsPerRow:l}=e.getConfig();for(let{start:r,end:i,bits:c,label:p}of t.blocks){if(r!==void 0&&i!==void 0&&i<r)throw new Error(`Packet block ${r} - ${i} is invalid. End must be greater than start.`);if(r??(r=o+1),r!==o+1)throw new Error(`Packet block ${r} - ${i??r} is not contiguous. It should start from ${o+1}.`);if(c===0)throw new Error(`Packet block ${r} is invalid. Cannot have a zero bit field.`);for(i??(i=r+(c??1)-1),c??(c=i-r+1),o=i,v.debug(`Packet block ${r} - ${o} with label ${p}`);a.length<=l+1&&e.getPacket().length<M;){const[d,s]=H({start:r,end:i,bits:c,label:p},n,l);if(a.push(d),d.end+1===n*l&&(e.pushWord(a),a=[],n++),!s)break;({start:r,end:i,bits:c,label:p}=s)}}e.pushWord(a)},"populate"),H=f((t,e,o)=>{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*o)return[t,void 0];const a=e*o-1,n=e*o;return[{start:t.start,end:a,label:t.label,bits:a-t.start},{start:n,end:t.end,label:t.label,bits:t.end-n}]},"getNextFittingBlock"),x={parser:{yy:void 0},parse:f(async t=>{var e;const o=await N("packet",t),a=(e=x.parser)==null?void 0:e.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.");v.debug(o),Y(o,a)},"parse")},I=f((t,e,o,a)=>{const n=a.db,l=n.getConfig(),{rowHeight:r,paddingY:i,bitWidth:c,bitsPerRow:p}=l,d=n.getPacket(),s=n.getDiagramTitle(),g=r+i,m=g*(d.length+1)-(s?0:r),h=c*p+2,k=B(e);k.attr("viewbox",`0 0 ${h} ${m}`),C(k,m,h,l.useMaxWidth);for(const[y,$]of d.entries())O(k,$,y,l);k.append("text").text(s).attr("x",h/2).attr("y",m-g/2).attr("dominant-baseline","middle").attr("text-anchor","middle").attr("class","packetTitle")},"draw"),O=f((t,e,o,{rowHeight:a,paddingX:n,paddingY:l,bitWidth:r,bitsPerRow:i,showBits:c})=>{const p=t.append("g"),d=o*(a+l)+l;for(const s of e){const g=s.start%i*r+1,m=(s.end-s.start+1)*r-n;if(p.append("rect").attr("x",g).attr("y",d).attr("width",m).attr("height",a).attr("class","packetBlock"),p.append("text").attr("x",g+m/2).attr("y",d+a/2).attr("class","packetLabel").attr("dominant-baseline","middle").attr("text-anchor","middle").text(s.label),!c)continue;const h=s.end===s.start,k=d-2;p.append("text").attr("x",g+(h?m/2:0)).attr("y",k).attr("class","packetByte start").attr("dominant-baseline","auto").attr("text-anchor",h?"middle":"start").text(s.start),h||p.append("text").attr("x",g+m).attr("y",k).attr("class","packetByte end").attr("dominant-baseline","auto").attr("text-anchor","end").text(s.end)}},"drawWord"),j={draw:I},q={byteFontSize:"10px",startByteColor:"black",endByteColor:"black",labelColor:"black",labelFontSize:"12px",titleColor:"black",titleFontSize:"14px",blockStrokeColor:"black",blockStrokeWidth:"1",blockFillColor:"#efefef"},G=f(({packet:t}={})=>{const e=u(q,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"),Ft={parser:x,get db(){return new w},renderer:j,styles:G};export{Ft as diagram};
