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) • 16.4 kB
JavaScript
const oe=require("./mermaid-parser.core-DYumW1vq.cjs"),$=require("./chunk-Y2CYZVJY-DPaYLFFP.cjs"),q=require("./src-C9EhKhbk.cjs"),C=require("./chunk-WYO6CB5R-u4mJNOcO.cjs"),K=require("./ordinal-BplLHIij.cjs"),E=require("./defaultLocale-DSqtvhxg.cjs"),Q=require("./chunk-ICXQ74PX-BbT9JaEW.cjs"),ce=require("./chunk-VAUOI2AC-DfQf5L2_.cjs"),ue=require("./chunk-JWPE2WC7-D8EnWK1B.cjs"),he=require("./chunk-VR4S4FIN-KiwnPF31.cjs"),z=require("./chunk-C7G6YPKG-CKEeW9TM.cjs");function de(t){var a=0,n=t.children,r=n&&n.length;if(!r)a=1;else for(;--r>=0;)a+=n[r].value;t.value=a}function pe(){return this.eachAfter(de)}function fe(t,a){let n=-1;for(const r of this)t.call(a,r,++n,this);return this}function ge(t,a){for(var n=this,r=[n],s,i,c=-1;n=r.pop();)if(t.call(a,n,++c,this),s=n.children)for(i=s.length-1;i>=0;--i)r.push(s[i]);return this}function me(t,a){for(var n=this,r=[n],s=[],i,c,h,f=-1;n=r.pop();)if(s.push(n),i=n.children)for(c=0,h=i.length;c<h;++c)r.push(i[c]);for(;n=s.pop();)t.call(a,n,++f,this);return this}function ye(t,a){let n=-1;for(const r of this)if(t.call(a,r,++n,this))return r}function Se(t){return this.eachAfter(function(a){for(var n=+t(a.data)||0,r=a.children,s=r&&r.length;--s>=0;)n+=r[s].value;a.value=n})}function ve(t){return this.eachBefore(function(a){a.children&&a.children.sort(t)})}function xe(t){for(var a=this,n=_e(a,t),r=[a];a!==n;)a=a.parent,r.push(a);for(var s=r.length;t!==n;)r.splice(s,0,t),t=t.parent;return r}function _e(t,a){if(t===a)return t;var n=t.ancestors(),r=a.ancestors(),s=null;for(t=n.pop(),a=r.pop();t===a;)s=t,t=n.pop(),a=r.pop();return s}function Ce(){for(var t=this,a=[t];t=t.parent;)a.push(t);return a}function we(){return Array.from(this)}function be(){var t=[];return this.eachBefore(function(a){a.children||t.push(a)}),t}function $e(){var t=this,a=[];return t.each(function(n){n!==t&&a.push({source:n.parent,target:n})}),a}function*Te(){var t=this,a,n=[t],r,s,i;do for(a=n.reverse(),n=[];t=a.pop();)if(yield t,r=t.children)for(s=0,i=r.length;s<i;++s)n.push(r[s]);while(n.length)}function ee(t,a){t instanceof Map?(t=[void 0,t],a===void 0&&(a=Ne)):a===void 0&&(a=ke);for(var n=new X(t),r,s=[n],i,c,h,f;r=s.pop();)if((c=a(r.data))&&(f=(c=Array.from(c)).length))for(r.children=c,h=f-1;h>=0;--h)s.push(i=c[h]=new X(c[h])),i.parent=r,i.depth=r.depth+1;return n.eachBefore(Fe)}function Le(){return ee(this).eachBefore(Me)}function ke(t){return t.children}function Ne(t){return Array.isArray(t)?t[1]:null}function Me(t){t.data.value!==void 0&&(t.value=t.data.value),t.data=t.data.data}function Fe(t){var a=0;do t.height=a;while((t=t.parent)&&t.height<++a)}function X(t){this.data=t,this.depth=this.height=0,this.parent=null}X.prototype=ee.prototype={constructor:X,count:pe,each:fe,eachAfter:me,eachBefore:ge,find:ye,sum:Se,sort:ve,path:xe,ancestors:Ce,descendants:we,leaves:be,links:$e,copy:Le,[Symbol.iterator]:Te};function Ae(t){if(typeof t!="function")throw new Error;return t}function H(){return 0}function G(t){return function(){return t}}function ze(t){t.x0=Math.round(t.x0),t.y0=Math.round(t.y0),t.x1=Math.round(t.x1),t.y1=Math.round(t.y1)}function qe(t,a,n,r,s){for(var i=t.children,c,h=-1,f=i.length,o=t.value&&(r-a)/t.value;++h<f;)c=i[h],c.y0=n,c.y1=s,c.x0=a,c.x1=a+=c.value*o}function Ve(t,a,n,r,s){for(var i=t.children,c,h=-1,f=i.length,o=t.value&&(s-n)/t.value;++h<f;)c=i[h],c.x0=a,c.x1=r,c.y0=n,c.y1=n+=c.value*o}var De=(1+Math.sqrt(5))/2;function Pe(t,a,n,r,s,i){for(var c=[],h=a.children,f,o,d=0,x=0,l=h.length,v,y,S=a.value,p,g,A,N,V,W,k;d<l;){v=s-n,y=i-r;do p=h[x++].value;while(!p&&x<l);for(g=A=p,W=Math.max(y/v,v/y)/(S*t),k=p*p*W,V=Math.max(A/k,k/g);x<l;++x){if(p+=o=h[x].value,o<g&&(g=o),o>A&&(A=o),k=p*p*W,N=Math.max(A/k,k/g),N>V){p-=o;break}V=N}c.push(f={value:p,dice:v<y,children:h.slice(d,x)}),f.dice?qe(f,n,r,s,S?r+=y*p/S:i):Ve(f,n,r,S?n+=v*p/S:s,i),S-=p,d=x}return c}var Ie=(function t(a){function n(r,s,i,c,h){Pe(a,r,s,i,c,h)}return n.ratio=function(r){return t((r=+r)>1?r:1)},n})(De);function We(){var t=Ie,a=!1,n=1,r=1,s=[0],i=H,c=H,h=H,f=H,o=H;function d(l){return l.x0=l.y0=0,l.x1=n,l.y1=r,l.eachBefore(x),s=[0],a&&l.eachBefore(ze),l}function x(l){var v=s[l.depth],y=l.x0+v,S=l.y0+v,p=l.x1-v,g=l.y1-v;p<y&&(y=p=(y+p)/2),g<S&&(S=g=(S+g)/2),l.x0=y,l.y0=S,l.x1=p,l.y1=g,l.children&&(v=s[l.depth+1]=i(l)/2,y+=o(l)-v,S+=c(l)-v,p-=h(l)-v,g-=f(l)-v,p<y&&(y=p=(y+p)/2),g<S&&(S=g=(S+g)/2),t(l,y,S,p,g))}return d.round=function(l){return arguments.length?(a=!!l,d):a},d.size=function(l){return arguments.length?(n=+l[0],r=+l[1],d):[n,r]},d.tile=function(l){return arguments.length?(t=Ae(l),d):t},d.padding=function(l){return arguments.length?d.paddingInner(l).paddingOuter(l):d.paddingInner()},d.paddingInner=function(l){return arguments.length?(i=typeof l=="function"?l:G(+l),d):i},d.paddingOuter=function(l){return arguments.length?d.paddingTop(l).paddingRight(l).paddingBottom(l).paddingLeft(l):d.paddingTop()},d.paddingTop=function(l){return arguments.length?(c=typeof l=="function"?l:G(+l),d):c},d.paddingRight=function(l){return arguments.length?(h=typeof l=="function"?l:G(+l),d):h},d.paddingBottom=function(l){return arguments.length?(f=typeof l=="function"?l:G(+l),d):f},d.paddingLeft=function(l){return arguments.length?(o=typeof l=="function"?l:G(+l),d):o},d}var ne=class{constructor(){this.nodes=[],this.levels=new Map,this.outerNodes=[],this.classes=new Map,this.setAccTitle=C.setAccTitle,this.getAccTitle=C.getAccTitle,this.setDiagramTitle=C.setDiagramTitle,this.getDiagramTitle=C.getDiagramTitle,this.getAccDescription=C.getAccDescription,this.setAccDescription=C.setAccDescription}static{$.__name(this,"TreeMapDB")}getNodes(){return this.nodes}getConfig(){const t=C.defaultConfig_default,a=C.getConfig();return Q.cleanAndMerge({...t.treemap,...a.treemap??{}})}addNode(t,a){this.nodes.push(t),this.levels.set(t,a),a===0&&(this.outerNodes.push(t),this.root??=t)}getRoot(){return{name:"",children:this.outerNodes}}addClass(t,a){const n=this.classes.get(t)??{id:t,styles:[],textStyles:[]},r=a.replace(/\\,/g,"§§§").replace(/,/g,";").replace(/§§§/g,",").split(";");r&&r.forEach(s=>{z.isLabelStyle(s)&&(n?.textStyles?n.textStyles.push(s):n.textStyles=[s]),n?.styles?n.styles.push(s):n.styles=[s]}),this.classes.set(t,n)}getClasses(){return this.classes}getStylesForClass(t){return this.classes.get(t)?.styles??[]}clear(){C.clear(),this.nodes=[],this.levels=new Map,this.outerNodes=[],this.classes=new Map,this.root=void 0}};function re(t){if(!t.length)return[];const a=[],n=[];return t.forEach(r=>{const s={name:r.name,children:r.type==="Leaf"?void 0:[]};for(s.classSelector=r?.classSelector,r?.cssCompiledStyles&&(s.cssCompiledStyles=r.cssCompiledStyles),r.type==="Leaf"&&r.value!==void 0&&(s.value=r.value);n.length>0&&n[n.length-1].level>=r.level;)n.pop();if(n.length===0)a.push(s);else{const i=n[n.length-1].node;i.children?i.children.push(s):i.children=[s]}r.type!=="Leaf"&&n.push({node:s,level:r.level})}),a}$.__name(re,"buildHierarchy");var Be=$.__name((t,a)=>{ue.populateCommonDb(t,a);const n=[];for(const i of t.TreemapRows??[])i.$type==="ClassDefStatement"&&a.addClass(i.className??"",i.styleText??"");for(const i of t.TreemapRows??[]){const c=i.item;if(!c)continue;const h=i.indent?parseInt(i.indent):0,f=Re(c),o=c.classSelector?a.getStylesForClass(c.classSelector):[],d=o.length>0?o:void 0,x={level:h,name:f,type:c.$type,value:c.value,classSelector:c.classSelector,cssCompiledStyles:d};n.push(x)}const r=re(n),s=$.__name((i,c)=>{for(const h of i)a.addNode(h,c),h.children&&h.children.length>0&&s(h.children,c+1)},"addNodesRecursively");s(r,0)},"populate"),Re=$.__name(t=>t.name?String(t.name):"","getItemName"),le={parser:{yy:void 0},parse:$.__name(async t=>{try{const a=await oe.parse("treemap",t);q.log.debug("Treemap AST:",a);const n=le.parser?.yy;if(!(n instanceof ne))throw new Error("parser.parser?.yy was not a TreemapDB. This is due to a bug within Mermaid, please report this issue at https://github.com/mermaid-js/mermaid/issues.");Be(a,n)}catch(a){throw q.log.error("Error parsing treemap:",a),a}},"parse")},Ee=10,I=10,O=25,He={draw:$.__name((t,a,n,r)=>{const s=r.db,i=s.getConfig(),c=i.padding??Ee,h=s.getDiagramTitle(),f=s.getRoot(),{themeVariables:o}=C.getConfig();if(!f)return;const d=h?30:0,x=ce.selectSvgElement(a),l=i.nodeWidth?i.nodeWidth*I:960,v=i.nodeHeight?i.nodeHeight*I:500,y=l,S=v+d;x.attr("viewBox",`0 0 ${y} ${S}`),C.configureSvgSize(x,S,y,i.useMaxWidth);let p;try{const e=i.valueFormat||",";if(e==="$0,0")p=$.__name(u=>"$"+E.format(",")(u),"valueFormat");else if(e.startsWith("$")&&e.includes(",")){const u=/\.\d+/.exec(e),w=u?u[0]:"";p=$.__name(L=>"$"+E.format(","+w)(L),"valueFormat")}else if(e.startsWith("$")){const u=e.substring(1);p=$.__name(w=>"$"+E.format(u||"")(w),"valueFormat")}else p=E.format(e)}catch(e){q.log.error("Error creating format function:",e),p=E.format(",")}const g=K.ordinal().range(["transparent",o.cScale0,o.cScale1,o.cScale2,o.cScale3,o.cScale4,o.cScale5,o.cScale6,o.cScale7,o.cScale8,o.cScale9,o.cScale10,o.cScale11]),A=K.ordinal().range(["transparent",o.cScalePeer0,o.cScalePeer1,o.cScalePeer2,o.cScalePeer3,o.cScalePeer4,o.cScalePeer5,o.cScalePeer6,o.cScalePeer7,o.cScalePeer8,o.cScalePeer9,o.cScalePeer10,o.cScalePeer11]),N=K.ordinal().range([o.cScaleLabel0,o.cScaleLabel1,o.cScaleLabel2,o.cScaleLabel3,o.cScaleLabel4,o.cScaleLabel5,o.cScaleLabel6,o.cScaleLabel7,o.cScaleLabel8,o.cScaleLabel9,o.cScaleLabel10,o.cScaleLabel11]);h&&x.append("text").attr("x",y/2).attr("y",d/2).attr("class","treemapTitle").attr("text-anchor","middle").attr("dominant-baseline","middle").text(h);const V=x.append("g").attr("transform",`translate(0, ${d})`).attr("class","treemapContainer"),W=ee(f).sum(e=>e.value??0).sort((e,u)=>(u.value??0)-(e.value??0)),k=We().size([l,v]).paddingTop(e=>e.children&&e.children.length>0?O+I:0).paddingInner(c).paddingLeft(e=>e.children&&e.children.length>0?I:0).paddingRight(e=>e.children&&e.children.length>0?I:0).paddingBottom(e=>e.children&&e.children.length>0?I:0).round(!0)(W),ie=k.descendants().filter(e=>e.children&&e.children.length>0),B=V.selectAll(".treemapSection").data(ie).enter().append("g").attr("class","treemapSection").attr("transform",e=>`translate(${e.x0},${e.y0})`);B.append("rect").attr("width",e=>e.x1-e.x0).attr("height",O).attr("class","treemapSectionHeader").attr("fill","none").attr("fill-opacity",.6).attr("stroke-width",.6).attr("style",e=>e.depth===0?"display: none;":""),B.append("clipPath").attr("id",(e,u)=>`clip-section-${a}-${u}`).append("rect").attr("width",e=>Math.max(0,e.x1-e.x0-12)).attr("height",O),B.append("rect").attr("width",e=>e.x1-e.x0).attr("height",e=>e.y1-e.y0).attr("class",(e,u)=>`treemapSection section${u}`).attr("fill",e=>g(e.data.name)).attr("fill-opacity",.6).attr("stroke",e=>A(e.data.name)).attr("stroke-width",2).attr("stroke-opacity",.4).attr("style",e=>{if(e.depth===0)return"display: none;";const u=z.styles2String({cssCompiledStyles:e.data.cssCompiledStyles});return u.nodeStyles+";"+u.borderStyles.join(";")}),B.append("text").attr("class","treemapSectionLabel").attr("x",6).attr("y",O/2).attr("dominant-baseline","middle").text(e=>e.depth===0?"":e.data.name).attr("font-weight","bold").attr("clip-path",(e,u)=>`url(#clip-section-${a}-${u})`).attr("style",e=>e.depth===0?"display: none;":"dominant-baseline: middle; font-size: 12px; fill:"+N(e.data.name)+"; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;"+z.styles2String({cssCompiledStyles:e.data.cssCompiledStyles}).labelStyles.replace("color:","fill:")).each(function(e){if(e.depth===0)return;const u=q.select_default(this),w=e.data.name;u.text(w);const L=e.x1-e.x0,F=6;let T;i.showValues!==!1&&e.value?T=L-10-30-10-F:T=L-F-6;const b=Math.max(15,T),m=u.node();if(m.getComputedTextLength()>b){let _=w;for(;_.length>0;){if(_=w.substring(0,_.length-1),_.length===0){u.text("..."),m.getComputedTextLength()>b&&u.text("");break}if(u.text(_+"..."),m.getComputedTextLength()<=b)break}}}),i.showValues!==!1&&B.append("text").attr("class","treemapSectionValue").attr("x",e=>e.x1-e.x0-10).attr("y",O/2).attr("text-anchor","end").attr("dominant-baseline","middle").text(e=>e.value?p(e.value):"").attr("font-style","italic").attr("style",e=>e.depth===0?"display: none;":"text-anchor: end; dominant-baseline: middle; font-size: 10px; fill:"+N(e.data.name)+"; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;"+z.styles2String({cssCompiledStyles:e.data.cssCompiledStyles}).labelStyles.replace("color:","fill:"));const te=k.leaves(),M=te.length>20,se=M?16:38,Y=M?14:28,D=M?4:8,P=M?4:6,J=M?2:4,ae=M?8:10,U=M?1:2,j=V.selectAll(".treemapLeafGroup").data(te).enter().append("g").attr("class",(e,u)=>`treemapNode treemapLeafGroup leaf${u}${e.data.classSelector?` ${e.data.classSelector}`:""}x`).attr("transform",e=>`translate(${e.x0},${e.y0})`);j.append("rect").attr("width",e=>e.x1-e.x0).attr("height",e=>e.y1-e.y0).attr("class","treemapLeaf").attr("fill",e=>e.parent?g(e.parent.data.name):g(e.data.name)).attr("style",e=>z.styles2String({cssCompiledStyles:e.data.cssCompiledStyles}).nodeStyles).attr("fill-opacity",.3).attr("stroke",e=>e.parent?g(e.parent.data.name):g(e.data.name)).attr("stroke-width",3),j.append("clipPath").attr("id",(e,u)=>`clip-${a}-${u}`).append("rect").attr("width",e=>Math.max(0,e.x1-e.x0-4)).attr("height",e=>Math.max(0,e.y1-e.y0-4)),j.append("text").attr("class","treemapLabel").attr("x",e=>(e.x1-e.x0)/2).attr("y",e=>(e.y1-e.y0)/2).attr("style",e=>`text-anchor: middle; dominant-baseline: middle; font-size: ${se}px;fill:`+N(e.data.name)+";"+z.styles2String({cssCompiledStyles:e.data.cssCompiledStyles}).labelStyles.replace("color:","fill:")).attr("clip-path",(e,u)=>`url(#clip-${a}-${u})`).text(e=>e.data.name).each(function(e){const u=q.select_default(this),w=e.x1-e.x0,L=e.y1-e.y0,F=u.node(),T=w-2*J,b=L-2*J;if(T<ae||b<ae){u.style("display","none");return}let m=parseInt(u.style("font-size"),10);const R=.6;for(;F.getComputedTextLength()>T&&m>D;)m--,u.style("font-size",`${m}px`);let _=Math.max(P,Math.min(Y,Math.round(m*R))),Z=m+U+_;for(;Z>b&&m>D&&(m--,_=Math.max(P,Math.min(Y,Math.round(m*R))),!(_<P&&m===D));)u.style("font-size",`${m}px`),Z=m+U+_,_<=P&&Z>b;u.style("font-size",`${m}px`),M?(m<D||b<D)&&u.style("display","none"):(F.getComputedTextLength()>T||m<D||b<m)&&u.style("display","none")}),i.showValues!==!1&&j.append("text").attr("class","treemapValue").attr("x",e=>(e.x1-e.x0)/2).attr("y",function(e){return(e.y1-e.y0)/2}).attr("style",e=>`text-anchor: middle; dominant-baseline: hanging; font-size: ${Y}px;fill:`+N(e.data.name)+";"+z.styles2String({cssCompiledStyles:e.data.cssCompiledStyles}).labelStyles.replace("color:","fill:")).attr("clip-path",(e,u)=>`url(#clip-${a}-${u})`).text(e=>e.value?p(e.value):"").each(function(e){const u=q.select_default(this),w=this.parentNode;if(!w){u.style("display","none");return}const L=q.select_default(w).select(".treemapLabel");if(L.empty()||L.style("display")==="none"){u.style("display","none");return}const F=parseFloat(L.style("font-size")),T=Math.max(P,Math.min(Y,Math.round(F*.6)));u.style("font-size",`${T}px`);const b=(e.y1-e.y0)/2+F/2+U;u.attr("y",b);const m=e.x1-e.x0,R=e.y1-e.y0-4,_=m-2*J;u.node().getComputedTextLength()>_||b+T>R||T<P?u.style("display","none"):u.style("display",null)}),he.setupViewPortForSVG(x,i.diagramPadding??8,"flowchart",i?.useMaxWidth||!1)},"draw"),getClasses:$.__name(function(t,a){return a.db.getClasses()},"getClasses")},Ge={sectionStrokeColor:"black",sectionStrokeWidth:"1",sectionFillColor:"#efefef",leafStrokeColor:"black",leafStrokeWidth:"1",leafFillColor:"#efefef",labelFontSize:"12px",valueFontSize:"10px",titleFontSize:"14px"},Oe={parser:le,get db(){return new ne},renderer:He,styles:$.__name(({treemap:t}={})=>{const a=Q.cleanAndMerge(C.getThemeVariables3(),C.getConfig().themeVariables),n=Q.cleanAndMerge(Ge,t),r=n.titleColor??a.titleColor,s=n.labelColor??a.textColor,i=n.valueColor??a.textColor;return`
.treemapNode.section {
stroke: ${n.sectionStrokeColor};
stroke-width: ${n.sectionStrokeWidth};
fill: ${n.sectionFillColor};
}
.treemapNode.leaf {
stroke: ${n.leafStrokeColor};
stroke-width: ${n.leafStrokeWidth};
fill: ${n.leafFillColor};
}
.treemapLabel {
fill: ${s};
font-size: ${n.labelFontSize};
}
.treemapValue {
fill: ${i};
font-size: ${n.valueFontSize};
}
.treemapTitle {
fill: ${r};
font-size: ${n.titleFontSize};
}
`},"getStyles")};exports.diagram=Oe;