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 $=require("./chunk-Y2CYZVJY-DPaYLFFP.cjs"),q=require("./src-D8aDujwE.cjs"),b=require("./chunk-I66GZJ75-BzqGKy7F.cjs"),U=require("./ordinal-B4H1mW8J.cjs"),R=require("./defaultLocale-CHotNvk3.cjs"),Q=require("./chunk-NSK5VX7P-DcRXFc-R.cjs"),ce=require("./chunk-3NCLNEKW-CHPh0zzA.cjs"),ue=require("./chunk-JWPE2WC7-D8EnWK1B.cjs"),he=require("./mermaid-parser.core-DQClw8Il.cjs"),de=require("./chunk-KBJHAD2P-BGFVhtHr.cjs"),z=require("./chunk-W5SLKNZC-z8QxkdMj.cjs");function pe(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 fe(){return this.eachAfter(pe)}function ge(t,a){let n=-1;for(const r of this)t.call(a,r,++n,this);return this}function me(t,a){for(var n=this,r=[n],l,s,c=-1;n=r.pop();)if(t.call(a,n,++c,this),l=n.children)for(s=l.length-1;s>=0;--s)r.push(l[s]);return this}function ye(t,a){for(var n=this,r=[n],l=[],s,c,h,f=-1;n=r.pop();)if(l.push(n),s=n.children)for(c=0,h=s.length;c<h;++c)r.push(s[c]);for(;n=l.pop();)t.call(a,n,++f,this);return this}function Se(t,a){let n=-1;for(const r of this)if(t.call(a,r,++n,this))return r}function ve(t){return this.eachAfter(function(a){for(var n=+t(a.data)||0,r=a.children,l=r&&r.length;--l>=0;)n+=r[l].value;a.value=n})}function xe(t){return this.eachBefore(function(a){a.children&&a.children.sort(t)})}function _e(t){for(var a=this,n=be(a,t),r=[a];a!==n;)a=a.parent,r.push(a);for(var l=r.length;t!==n;)r.splice(l,0,t),t=t.parent;return r}function be(t,a){if(t===a)return t;var n=t.ancestors(),r=a.ancestors(),l=null;for(t=n.pop(),a=r.pop();t===a;)l=t,t=n.pop(),a=r.pop();return l}function we(){for(var t=this,a=[t];t=t.parent;)a.push(t);return a}function Ce(){return Array.from(this)}function $e(){var t=[];return this.eachBefore(function(a){a.children||t.push(a)}),t}function Te(){var t=this,a=[];return t.each(function(n){n!==t&&a.push({source:n.parent,target:n})}),a}function*Le(){var t=this,a,n=[t],r,l,s;do for(a=n.reverse(),n=[];t=a.pop();)if(yield t,r=t.children)for(l=0,s=r.length;l<s;++l)n.push(r[l]);while(n.length)}function ee(t,a){t instanceof Map?(t=[void 0,t],a===void 0&&(a=Me)):a===void 0&&(a=Ne);for(var n=new K(t),r,l=[n],s,c,h,f;r=l.pop();)if((c=a(r.data))&&(f=(c=Array.from(c)).length))for(r.children=c,h=f-1;h>=0;--h)l.push(s=c[h]=new K(c[h])),s.parent=r,s.depth=r.depth+1;return n.eachBefore(Ae)}function ke(){return ee(this).eachBefore(Fe)}function Ne(t){return t.children}function Me(t){return Array.isArray(t)?t[1]:null}function Fe(t){t.data.value!==void 0&&(t.value=t.data.value),t.data=t.data.data}function Ae(t){var a=0;do t.height=a;while((t=t.parent)&&t.height<++a)}function K(t){this.data=t,this.depth=this.height=0,this.parent=null}K.prototype=ee.prototype={constructor:K,count:fe,each:ge,eachAfter:ye,eachBefore:me,find:Se,sum:ve,sort:xe,path:_e,ancestors:we,descendants:Ce,leaves:$e,links:Te,copy:ke,[Symbol.iterator]:Le};function ze(t){if(typeof t!="function")throw new Error;return t}function H(){return 0}function G(t){return function(){return t}}function qe(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 De(t,a,n,r,l){for(var s=t.children,c,h=-1,f=s.length,o=t.value&&(r-a)/t.value;++h<f;)c=s[h],c.y0=n,c.y1=l,c.x0=a,c.x1=a+=c.value*o}function Pe(t,a,n,r,l){for(var s=t.children,c,h=-1,f=s.length,o=t.value&&(l-n)/t.value;++h<f;)c=s[h],c.x0=a,c.x1=r,c.y0=n,c.y1=n+=c.value*o}var Ve=(1+Math.sqrt(5))/2;function We(t,a,n,r,l,s){for(var c=[],h=a.children,f,o,d=0,x=0,i=h.length,v,y,S=a.value,p,g,A,N,D,B,k;d<i;){v=l-n,y=s-r;do p=h[x++].value;while(!p&&x<i);for(g=A=p,B=Math.max(y/v,v/y)/(S*t),k=p*p*B,D=Math.max(A/k,k/g);x<i;++x){if(p+=o=h[x].value,o<g&&(g=o),o>A&&(A=o),k=p*p*B,N=Math.max(A/k,k/g),N>D){p-=o;break}D=N}c.push(f={value:p,dice:v<y,children:h.slice(d,x)}),f.dice?De(f,n,r,l,S?r+=y*p/S:s):Pe(f,n,r,S?n+=v*p/S:l,s),S-=p,d=x}return c}var Be=(function t(a){function n(r,l,s,c,h){We(a,r,l,s,c,h)}return n.ratio=function(r){return t((r=+r)>1?r:1)},n})(Ve);function Ee(){var t=Be,a=!1,n=1,r=1,l=[0],s=H,c=H,h=H,f=H,o=H;function d(i){return i.x0=i.y0=0,i.x1=n,i.y1=r,i.eachBefore(x),l=[0],a&&i.eachBefore(qe),i}function x(i){var v=l[i.depth],y=i.x0+v,S=i.y0+v,p=i.x1-v,g=i.y1-v;p<y&&(y=p=(y+p)/2),g<S&&(S=g=(S+g)/2),i.x0=y,i.y0=S,i.x1=p,i.y1=g,i.children&&(v=l[i.depth+1]=s(i)/2,y+=o(i)-v,S+=c(i)-v,p-=h(i)-v,g-=f(i)-v,p<y&&(y=p=(y+p)/2),g<S&&(S=g=(S+g)/2),t(i,y,S,p,g))}return d.round=function(i){return arguments.length?(a=!!i,d):a},d.size=function(i){return arguments.length?(n=+i[0],r=+i[1],d):[n,r]},d.tile=function(i){return arguments.length?(t=ze(i),d):t},d.padding=function(i){return arguments.length?d.paddingInner(i).paddingOuter(i):d.paddingInner()},d.paddingInner=function(i){return arguments.length?(s=typeof i=="function"?i:G(+i),d):s},d.paddingOuter=function(i){return arguments.length?d.paddingTop(i).paddingRight(i).paddingBottom(i).paddingLeft(i):d.paddingTop()},d.paddingTop=function(i){return arguments.length?(c=typeof i=="function"?i:G(+i),d):c},d.paddingRight=function(i){return arguments.length?(h=typeof i=="function"?i:G(+i),d):h},d.paddingBottom=function(i){return arguments.length?(f=typeof i=="function"?i:G(+i),d):f},d.paddingLeft=function(i){return arguments.length?(o=typeof i=="function"?i:G(+i),d):o},d}var ne=class{constructor(){this.nodes=[],this.levels=new Map,this.outerNodes=[],this.classes=new Map,this.setAccTitle=b.setAccTitle,this.getAccTitle=b.getAccTitle,this.setDiagramTitle=b.setDiagramTitle,this.getDiagramTitle=b.getDiagramTitle,this.getAccDescription=b.getAccDescription,this.setAccDescription=b.setAccDescription}static{$.__name(this,"TreeMapDB")}getNodes(){return this.nodes}getConfig(){const t=b.defaultConfig_default,a=b.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(l=>{z.isLabelStyle(l)&&(n?.textStyles?n.textStyles.push(l):n.textStyles=[l]),n?.styles?n.styles.push(l):n.styles=[l]}),this.classes.set(t,n)}getClasses(){return this.classes}getStylesForClass(t){return this.classes.get(t)?.styles??[]}clear(){b.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 l={name:r.name,children:r.type==="Leaf"?void 0:[]};for(l.classSelector=r?.classSelector,r?.cssCompiledStyles&&(l.cssCompiledStyles=r.cssCompiledStyles),r.type==="Leaf"&&r.value!==void 0&&(l.value=r.value);n.length>0&&n[n.length-1].level>=r.level;)n.pop();if(n.length===0)a.push(l);else{const s=n[n.length-1].node;s.children?s.children.push(l):s.children=[l]}r.type!=="Leaf"&&n.push({node:l,level:r.level})}),a}$.__name(re,"buildHierarchy");var Ie=$.__name((t,a)=>{ue.populateCommonDb(t,a);const n=[];for(const s of t.TreemapRows??[])s.$type==="ClassDefStatement"&&a.addClass(s.className??"",s.styleText??"");for(const s of t.TreemapRows??[]){const c=s.item;if(!c)continue;const h=s.indent?parseInt(s.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),l=$.__name((s,c)=>{for(const h of s)a.addNode(h,c),h.children&&h.children.length>0&&l(h.children,c+1)},"addNodesRecursively");l(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 he.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.");Ie(a,n)}catch(a){throw q.log.error("Error parsing treemap:",a),a}},"parse")},He=10,W=10,O=25,Ge={draw:$.__name((t,a,n,r)=>{const l=r.db,s=l.getConfig(),c=s.padding??He,h=l.getDiagramTitle(),f=l.getRoot(),{themeVariables:o}=b.getConfig();if(!f)return;const d=h?30:0,x=ce.selectSvgElement(a),i=s.nodeWidth?s.nodeWidth*W:960,v=s.nodeHeight?s.nodeHeight*W:500,y=i,S=v+d;x.attr("viewBox",`0 0 ${y} ${S}`),b.configureSvgSize(x,S,y,s.useMaxWidth);let p;try{const e=s.valueFormat||",";if(e==="$0,0")p=$.__name(u=>"$"+R.format(",")(u),"valueFormat");else if(e.startsWith("$")&&e.includes(",")){const u=/\.\d+/.exec(e),w=u?u[0]:"";p=$.__name(L=>"$"+R.format(","+w)(L),"valueFormat")}else if(e.startsWith("$")){const u=e.substring(1);p=$.__name(w=>"$"+R.format(u||"")(w),"valueFormat")}else p=R.format(e)}catch(e){q.log.error("Error creating format function:",e),p=R.format(",")}const g=U.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=U.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=U.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 D=x.append("g").attr("transform",`translate(0, ${d})`).attr("class","treemapContainer"),B=ee(f).sum(e=>e.value??0).sort((e,u)=>(u.value??0)-(e.value??0)),k=Ee().size([i,v]).paddingTop(e=>e.children&&e.children.length>0?O+W:0).paddingInner(c).paddingLeft(e=>e.children&&e.children.length>0?W:0).paddingRight(e=>e.children&&e.children.length>0?W:0).paddingBottom(e=>e.children&&e.children.length>0?W:0).round(!0)(B),ie=k.descendants().filter(e=>e.children&&e.children.length>0),E=D.selectAll(".treemapSection").data(ie).enter().append("g").attr("class","treemapSection").attr("transform",e=>`translate(${e.x0},${e.y0})`);E.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;":""),E.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),E.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(";")}),E.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;s.showValues!==!1&&e.value?T=L-10-30-10-F:T=L-F-6;const C=Math.max(15,T),m=u.node();if(m.getComputedTextLength()>C){let _=w;for(;_.length>0;){if(_=w.substring(0,_.length-1),_.length===0){u.text("..."),m.getComputedTextLength()>C&&u.text("");break}if(u.text(_+"..."),m.getComputedTextLength()<=C)break}}}),s.showValues!==!1&&E.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,P=M?4:8,V=M?4:6,Z=M?2:4,ae=M?8:10,j=M?1:2,J=D.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*Z,C=L-2*Z;if(T<ae||C<ae){u.style("display","none");return}let m=parseInt(u.style("font-size"),10);const I=.6;for(;F.getComputedTextLength()>T&&m>P;)m--,u.style("font-size",`${m}px`);let _=Math.max(V,Math.min(Y,Math.round(m*I))),X=m+j+_;for(;X>C&&m>P&&(m--,_=Math.max(V,Math.min(Y,Math.round(m*I))),!(_<V&&m===P));)u.style("font-size",`${m}px`),X=m+j+_,_<=V&&X>C;u.style("font-size",`${m}px`),M?(m<P||C<P)&&u.style("display","none"):(F.getComputedTextLength()>T||m<P||C<m)&&u.style("display","none")}),s.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(V,Math.min(Y,Math.round(F*.6)));u.style("font-size",`${T}px`);const C=(e.y1-e.y0)/2+F/2+j;u.attr("y",C);const m=e.x1-e.x0,I=e.y1-e.y0-4,_=m-2*Z;u.node().getComputedTextLength()>_||C+T>I||T<V?u.style("display","none"):u.style("display",null)});const oe=s.diagramPadding??8;de.setupViewPortForSVG(x,oe,"flowchart",s?.useMaxWidth||!1)},"draw"),getClasses:$.__name(function(t,a){return a.db.getClasses()},"getClasses")},Oe={sectionStrokeColor:"black",sectionStrokeWidth:"1",sectionFillColor:"#efefef",leafStrokeColor:"black",leafStrokeWidth:"1",leafFillColor:"#efefef",labelFontSize:"12px",valueFontSize:"10px",titleFontSize:"14px"},Ye={parser:le,get db(){return new ne},renderer:Ge,styles:$.__name(({treemap:t}={})=>{const a=b.getThemeVariables3(),n=b.getConfig(),r=Q.cleanAndMerge(a,n.themeVariables),l=Q.cleanAndMerge(Oe,t),s=l.titleColor??r.titleColor,c=l.labelColor??r.textColor,h=l.valueColor??r.textColor;return`
.treemapNode.section {
stroke: ${l.sectionStrokeColor};
stroke-width: ${l.sectionStrokeWidth};
fill: ${l.sectionFillColor};
}
.treemapNode.leaf {
stroke: ${l.leafStrokeColor};
stroke-width: ${l.leafStrokeWidth};
fill: ${l.leafFillColor};
}
.treemapLabel {
fill: ${c};
font-size: ${l.labelFontSize};
}
.treemapValue {
fill: ${h};
font-size: ${l.valueFontSize};
}
.treemapTitle {
fill: ${s};
font-size: ${l.titleFontSize};
}
`},"getStyles")};exports.diagram=Ye;