vitepress-mermaid-preview
Version:
Mermaid preview for vitepress
25 lines (24 loc) • 4.22 kB
JavaScript
;Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const _=require("./chunk-353BL4L5-DxnmASPI.cjs"),a=require("./component-EjRj2lD0.cjs"),C=require("./mermaid-parser.core-BVAOqJFG.cjs");var v={packet:[]},m=structuredClone(v),$=a.defaultConfig_default.packet,y=a.__name(()=>{const t=a.cleanAndMerge({...$,...a.getConfig().packet});return t.showBits&&(t.paddingY+=10),t},"getConfig"),B=a.__name(()=>m.packet,"getPacket"),S=a.__name(t=>{t.length>0&&m.packet.push(t)},"pushWord"),P=a.__name(()=>{a.clear(),m=structuredClone(v)},"clear"),h={pushWord:S,getPacket:B,getConfig:y,clear:P,setAccTitle:a.setAccTitle,getAccTitle:a.getAccTitle,setDiagramTitle:a.setDiagramTitle,getDiagramTitle:a.getDiagramTitle,getAccDescription:a.getAccDescription,setAccDescription:a.setAccDescription},T=1e4,z=a.__name(t=>{_.populateCommonDb(t,h);let e=-1,n=[],i=1;const{bitsPerRow:l}=h.getConfig();for(let{start:r,end:o,bits:c,label:k}of t.blocks){if(r!==void 0&&o!==void 0&&o<r)throw new Error(`Packet block ${r} - ${o} is invalid. End must be greater than start.`);if(r??=e+1,r!==e+1)throw new Error(`Packet block ${r} - ${o??r} is not contiguous. It should start from ${e+1}.`);if(c===0)throw new Error(`Packet block ${r} is invalid. Cannot have a zero bit field.`);for(o??=r+(c??1)-1,c??=o-r+1,e=o,a.log.debug(`Packet block ${r} - ${e} with label ${k}`);n.length<=l+1&&h.getPacket().length<T;){const[d,g]=A({start:r,end:o,bits:c,label:k},i,l);if(n.push(d),d.end+1===i*l&&(h.pushWord(n),n=[],i++),!g)break;({start:r,end:o,bits:c,label:k}=g)}}h.pushWord(n)},"populate"),A=a.__name((t,e,n)=>{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*n)return[t,void 0];const i=e*n-1,l=e*n;return[{start:t.start,end:i,label:t.label,bits:i-t.start},{start:l,end:t.end,label:t.label,bits:t.end-l}]},"getNextFittingBlock"),D={parse:a.__name(async t=>{const e=await C.parse("packet",t);a.log.debug(e),z(e)},"parse")},F=a.__name((t,e,n,i)=>{const l=i.db,r=l.getConfig(),{rowHeight:o,paddingY:c,bitWidth:k,bitsPerRow:d}=r,g=l.getPacket(),s=l.getDiagramTitle(),f=o+c,p=f*(g.length+1)-(s?0:o),b=k*d+2,u=a.selectSvgElement(e);u.attr("viewbox",`0 0 ${b} ${p}`),a.configureSvgSize(u,p,b,r.useMaxWidth);for(const[w,x]of g.entries())E(u,x,w,r);u.append("text").text(s).attr("x",b/2).attr("y",p-f/2).attr("dominant-baseline","middle").attr("text-anchor","middle").attr("class","packetTitle")},"draw"),E=a.__name((t,e,n,{rowHeight:i,paddingX:l,paddingY:r,bitWidth:o,bitsPerRow:c,showBits:k})=>{const d=t.append("g"),g=n*(i+r)+r;for(const s of e){const f=s.start%c*o+1,p=(s.end-s.start+1)*o-l;if(d.append("rect").attr("x",f).attr("y",g).attr("width",p).attr("height",i).attr("class","packetBlock"),d.append("text").attr("x",f+p/2).attr("y",g+i/2).attr("class","packetLabel").attr("dominant-baseline","middle").attr("text-anchor","middle").text(s.label),!k)continue;const b=s.end===s.start,u=g-2;d.append("text").attr("x",f+(b?p/2:0)).attr("y",u).attr("class","packetByte start").attr("dominant-baseline","auto").attr("text-anchor",b?"middle":"start").text(s.start),b||d.append("text").attr("x",f+p).attr("y",u).attr("class","packetByte end").attr("dominant-baseline","auto").attr("text-anchor","end").text(s.end)}},"drawWord"),W={draw:F},L={byteFontSize:"10px",startByteColor:"black",endByteColor:"black",labelColor:"black",labelFontSize:"12px",titleColor:"black",titleFontSize:"14px",blockStrokeColor:"black",blockStrokeWidth:"1",blockFillColor:"#efefef"},M=a.__name(({packet:t}={})=>{const e=a.cleanAndMerge(L,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"),N={parser:D,db:h,renderer:W,styles:M};exports.diagram=N;