UNPKG

ranui

Version:

A framework-agnostic Web Components UI library built on native custom elements, with TypeScript types, light/dark theming, SSR and PWA support.

25 lines (24 loc) 4.51 kB
const C=require("./mermaid-parser.core-DYumW1vq.cjs"),b=require("./chunk-Y2CYZVJY-DPaYLFFP.cjs"),m=require("./src-C9EhKhbk.cjs"),d=require("./chunk-WYO6CB5R-u4mJNOcO.cjs"),w=require("./chunk-ICXQ74PX-BbT9JaEW.cjs"),B=require("./chunk-VAUOI2AC-DfQf5L2_.cjs"),$=require("./chunk-JWPE2WC7-D8EnWK1B.cjs");var S=d.defaultConfig_default.packet,_=class{constructor(){this.packet=[],this.setAccTitle=d.setAccTitle,this.getAccTitle=d.getAccTitle,this.setDiagramTitle=d.setDiagramTitle,this.getDiagramTitle=d.getDiagramTitle,this.getAccDescription=d.getAccDescription,this.setAccDescription=d.setAccDescription}static{b.__name(this,"PacketDB")}getConfig(){const t=w.cleanAndMerge({...S,...d.getConfig().packet});return t.showBits&&(t.paddingY+=10),t}getPacket(){return this.packet}pushWord(t){t.length>0&&this.packet.push(t)}clear(){d.clear(),this.packet=[]}},P=1e4,q=b.__name((t,e)=>{$.populateCommonDb(t,e);let a=-1,i=[],s=1;const{bitsPerRow:c}=e.getConfig();for(let{start:r,end:n,bits:p,label:l}of t.blocks){if(r!==void 0&&n!==void 0&&n<r)throw new Error(`Packet block ${r} - ${n} is invalid. End must be greater than start.`);if(r??=a+1,r!==a+1)throw new Error(`Packet block ${r} - ${n??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(n??=r+(p??1)-1,p??=n-r+1,a=n,m.log.debug(`Packet block ${r} - ${a} with label ${l}`);i.length<=c+1&&e.getPacket().length<P;){const[h,o]=A({start:r,end:n,bits:p,label:l},s,c);if(i.push(h),h.end+1===s*c&&(e.pushWord(i),i=[],s++),!o)break;({start:r,end:n,bits:p,label:l}=o)}}e.pushWord(i)},"populate"),A=b.__name((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 i=e*a-1,s=e*a;return[{start:t.start,end:i,label:t.label,bits:i-t.start},{start:s,end:t.end,label:t.label,bits:t.end-s}]},"getNextFittingBlock"),v={parser:{yy:void 0},parse:b.__name(async t=>{const e=await C.parse("packet",t),a=v.parser?.yy;if(!(a instanceof _))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.");m.log.debug(e),q(e,a)},"parse")},D=b.__name((t,e,a,i)=>{const s=i.db,c=s.getConfig(),{rowHeight:r,paddingY:n,bitWidth:p,bitsPerRow:l}=c,h=s.getPacket(),o=s.getDiagramTitle(),u=r+n,g=u*(h.length+1)-(o?0:r),k=p*l+2,f=B.selectSvgElement(e);f.attr("viewBox",`0 0 ${k} ${g}`),d.configureSvgSize(f,g,k,c.useMaxWidth);for(const[x,y]of h.entries())T(f,y,x,c);f.append("text").text(o).attr("x",k/2).attr("y",g-u/2).attr("dominant-baseline","middle").attr("text-anchor","middle").attr("class","packetTitle")},"draw"),T=b.__name((t,e,a,{rowHeight:i,paddingX:s,paddingY:c,bitWidth:r,bitsPerRow:n,showBits:p})=>{const l=t.append("g"),h=a*(i+c)+c;for(const o of e){const u=o.start%n*r+1,g=(o.end-o.start+1)*r-s;if(l.append("rect").attr("x",u).attr("y",h).attr("width",g).attr("height",i).attr("class","packetBlock"),l.append("text").attr("x",u+g/2).attr("y",h+i/2).attr("class","packetLabel").attr("dominant-baseline","middle").attr("text-anchor","middle").text(o.label),!p)continue;const k=o.end===o.start,f=h-2;l.append("text").attr("x",u+(k?g/2:0)).attr("y",f).attr("class","packetByte start").attr("dominant-baseline","auto").attr("text-anchor",k?"middle":"start").text(o.start),k||l.append("text").attr("x",u+g).attr("y",f).attr("class","packetByte end").attr("dominant-baseline","auto").attr("text-anchor","end").text(o.end)}},"drawWord"),E={draw:D},z={byteFontSize:"10px",startByteColor:"black",endByteColor:"black",labelColor:"black",labelFontSize:"12px",titleColor:"black",titleFontSize:"14px",blockStrokeColor:"black",blockStrokeWidth:"1",blockFillColor:"#efefef"},F={parser:v,get db(){return new _},renderer:E,styles:b.__name(({packet:t}={})=>{const e=w.cleanAndMerge(z,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")};exports.diagram=F;