import{p as t}from"./chunk-4BMEZGHF-juS1ELLA.js";import{_ as e,s as a,g as r,q as o,p as n,a as s,b as l,E as i,I as c,d,y as p,F as b,G as k,l as g}from"./mermaid-BGnxfgCD.js";import{p as h}from"./radar-MK3ICKWK-BhxDMxL5.js";import"./index-D3XtisvU.js";import"./transform-DjHZbYKP.js";import"./timer-DFzT7np-.js";import"./step-BwsUM5iJ.js";import"./_baseEach-DHNYGtOc.js";import"./_baseUniq-BlNMZyiw.js";import"./min-DUpp_rh3.js";import"./_baseMap-BXW0_SVK.js";import"./clone-DZLovMrS.js";import"./_createAggregator-ReXtltZy.js";var m={packet:[]},f=structuredClone(m),u=k.packet,x=e((()=>{const t=i({...u,...b().packet});return t.showBits&&(t.paddingY+=10),t}),"getConfig"),$=e((()=>f.packet),"getPacket"),w={pushWord:e((t=>{t.length>0&&f.packet.push(t)}),"pushWord"),getPacket:$,getConfig:x,clear:e((()=>{p(),f=structuredClone(m)}),"clear"),setAccTitle:l,getAccTitle:s,setDiagramTitle:n,getDiagramTitle:o,getAccDescription:r,setAccDescription:a},y=e((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,g.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=e(((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:e((async t=>{const e=await h("packet",t);g.debug(e),y(e)}),"parse")},j=e(((t,e,a,r)=>{const o=r.db,n=o.getConfig(),{rowHeight:s,paddingY:l,bitWidth:i,bitsPerRow:p}=n,b=o.getPacket(),k=o.getDiagramTitle(),g=s+l,h=g*(b.length+1)-(k?0:s),m=i*p+2,f=c(e);f.attr("viewbox",`0 0 ${m} ${h}`),d(f,h,m,n.useMaxWidth);for(const[c,d]of b.entries())F(f,d,c,n);f.append("text").text(k).attr("x",m/2).attr("y",h-g/2).attr("dominant-baseline","middle").attr("text-anchor","middle").attr("class","packetTitle")}),"draw"),F=e(((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"},P={parser:B,db:w,renderer:{draw:j},styles:e((({packet:t}={})=>{const e=i(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{P as diagram};
