import{p as t}from"./chunk-RYO7GUH3-xUM4ZbUs.js";import{A as e,s as a,g as r,p as o,q as n,b as s,c as l,_ as i,l as c,B as d,D as p,t as k,G as b,j as g}from"./mermaid-C2iOgJeu.js";import{p as h}from"./gitGraph-YCYPL57B-uDbxXOCi.js";import"./index-FKnJJang.js";import"./transform-0ILWlX8T.js";import"./timer-CK-RIWfW.js";import"./step-CNn2V7Th.js";import"./main-CEaoNRsh.js";import"./_baseEach-DIpKRMNf.js";import"./_baseUniq-DmSpOwc-.js";import"./min-BcCd9LO5.js";import"./_baseMap-C7H3vESs.js";import"./clone-CV2-s9tE.js";var m={packet:[]},f=structuredClone(m),u=e.packet,x=i((()=>{const t=d({...u,...p().packet});return t.showBits&&(t.paddingY+=10),t}),"getConfig"),$=i((()=>f.packet),"getPacket"),w={pushWord:i((t=>{t.length>0&&f.packet.push(t)}),"pushWord"),getPacket:$,getConfig:x,clear:i((()=>{k(),f=structuredClone(m)}),"clear"),setAccTitle:a,getAccTitle:r,setDiagramTitle:o,getDiagramTitle:n,getAccDescription:s,setAccDescription:l},y=i((e=>{t(e,w);let a=-1,r=[],o=1;const{bitsPerRow:n}=w.getConfig();for(let{start:t,end:s,label:l}of e.blocks){if(s&&s<t)throw new Error(`Packet block ${t} - ${s} is invalid. End must be greater than start.`);if(t!==a+1)throw new Error(`Packet block ${t} - ${s??t} is not contiguous. It should start from ${a+1}.`);for(a=s??t,c.debug(`Packet block ${t} - ${a} with label ${l}`);r.length<=n+1&&w.getPacket().length<1e4;){const[e,a]=C({start:t,end:s,label:l},o,n);if(r.push(e),e.end+1===o*n&&(w.pushWord(r),r=[],o++),!a)break;({start:t,end:s,label:l}=a)}}w.pushWord(r)}),"populate"),C=i(((t,e,a)=>{if(void 0===t.end&&(t.end=t.start),t.start>t.end)throw new Error(`Block start ${t.start} is greater than block end ${t.end}.`);return t.end+1<=e*a?[t,void 0]:[{start:t.start,end:e*a-1,label:t.label},{start:e*a,end:t.end,label:t.label}]}),"getNextFittingBlock"),B={parse:i((async t=>{const e=await h("packet",t);c.debug(e),y(e)}),"parse")},j=i(((t,e,a,r)=>{const o=r.db,n=o.getConfig(),{rowHeight:s,paddingY:l,bitWidth:i,bitsPerRow:c}=n,d=o.getPacket(),p=o.getDiagramTitle(),k=s+l,h=k*(d.length+1)-(p?0:s),m=i*c+2,f=b(e);f.attr("viewbox",`0 0 ${m} ${h}`),g(f,h,m,n.useMaxWidth);for(const[b,g]of d.entries())P(f,g,b,n);f.append("text").text(p).attr("x",m/2).attr("y",h-k/2).attr("dominant-baseline","middle").attr("text-anchor","middle").attr("class","packetTitle")}),"draw"),P=i(((t,e,a,{rowHeight:r,paddingX:o,paddingY:n,bitWidth:s,bitsPerRow:l,showBits:i})=>{const c=t.append("g"),d=a*(r+n)+n;for(const p of e){const t=p.start%l*s+1,e=(p.end-p.start+1)*s-o;if(c.append("rect").attr("x",t).attr("y",d).attr("width",e).attr("height",r).attr("class","packetBlock"),c.append("text").attr("x",t+e/2).attr("y",d+r/2).attr("class","packetLabel").attr("dominant-baseline","middle").attr("text-anchor","middle").text(p.label),!i)continue;const a=p.end===p.start,n=d-2;c.append("text").attr("x",t+(a?e/2:0)).attr("y",n).attr("class","packetByte start").attr("dominant-baseline","auto").attr("text-anchor",a?"middle":"start").text(p.start),a||c.append("text").attr("x",t+e).attr("y",n).attr("class","packetByte end").attr("dominant-baseline","auto").attr("text-anchor","end").text(p.end)}}),"drawWord"),W={byteFontSize:"10px",startByteColor:"black",endByteColor:"black",labelColor:"black",labelFontSize:"12px",titleColor:"black",titleFontSize:"14px",blockStrokeColor:"black",blockStrokeWidth:"1",blockFillColor:"#efefef"},S={parser:B,db:w,renderer:{draw:j},styles:i((({packet:t}={})=>{const e=d(W,t);return`\n\t.packetByte {\n\t\tfont-size: ${e.byteFontSize};\n\t}\n\t.packetByte.start {\n\t\tfill: ${e.startByteColor};\n\t}\n\t.packetByte.end {\n\t\tfill: ${e.endByteColor};\n\t}\n\t.packetLabel {\n\t\tfill: ${e.labelColor};\n\t\tfont-size: ${e.labelFontSize};\n\t}\n\t.packetTitle {\n\t\tfill: ${e.titleColor};\n\t\tfont-size: ${e.titleFontSize};\n\t}\n\t.packetBlock {\n\t\tstroke: ${e.blockStrokeColor};\n\t\tstroke-width: ${e.blockStrokeWidth};\n\t\tfill: ${e.blockFillColor};\n\t}\n\t`}),"styles")};export{S as diagram};
