mermaid
Version:
Markdown-ish syntax for generating flowcharts, mindmaps, sequence diagrams, class diagrams, gantt charts, git graphs and more.
31 lines (30 loc) • 8.74 kB
JavaScript
import{a as O}from"./chunk-T5OCTHI4.mjs";import{a as j}from"./chunk-JQRUD6KW.mjs";import{a as _}from"./chunk-5IQCK5RY.mjs";import"./chunk-JZGDI5JK.mjs";import"./chunk-OJINMHTS.mjs";import"./chunk-VQC2EELJ.mjs";import"./chunk-KD6SPIPN.mjs";import"./chunk-Q6NGPIAH.mjs";import"./chunk-RT4MAWR3.mjs";import"./chunk-YBMQ5JGJ.mjs";import"./chunk-GDY2UAB4.mjs";import"./chunk-3SMGFRGC.mjs";import"./chunk-3NPNU5GP.mjs";import"./chunk-TCEHX7R3.mjs";import"./chunk-5MVFYWFU.mjs";import"./chunk-SFMINX4W.mjs";import"./chunk-JFFVMJIA.mjs";import"./chunk-ZUNWM646.mjs";import"./chunk-ZS6VBONO.mjs";import{a as H}from"./chunk-IJBDOHL6.mjs";import{b as k,d as B}from"./chunk-2NMSUPJH.mjs";import{o as C}from"./chunk-VY2OSTJR.mjs";import"./chunk-STOV2HOB.mjs";import{A as E,O as R,S as G,T as $,U as A,V as M,W as v,X as L,Y as P,j as S,t as T}from"./chunk-QJSWEUOL.mjs";import{b as V}from"./chunk-H7VHZCWX.mjs";import{a as l}from"./chunk-AQ6EADP3.mjs";var q=/[─━│┃└┗├┣]/,Y=/[└┗├┣]/,ne=/[─━]/,X=/^[\s│┃]+$/,z=/^\s*(title[\t ]|accTitle[\t ]*:|accDescr[\t ]*[:{])/,W=/^\s*%%/,re=" ";function ie(n){return n.some(t=>q.test(t))}l(ie,"isBoxDrawingFormat");function oe(n){for(let t of n){let e=Y.exec(t);if(e?.index&&e.index>0)return e.index}return 4}l(oe,"inferSegmentWidth");function F(n,t){return n.replace(/\bline\s+(\d+)\b/gi,(e,r)=>{let s=parseInt(r,10),i=t.get(s);return i?`line ${i}`:e})}l(F,"remapErrorLines");function U(n){let t=n.split(`
`),e=new Map,r=-1;for(let[g,c]of t.entries())if(c.trim()==="treeView-beta"){r=g;break}if(r===-1)return{text:n,lineMap:e};let s=[];for(let g=r+1;g<t.length;g++){let c=t[g];c.trim()===""||W.test(c)||z.test(c)||X.test(c)||s.push(c.replace(/\t/g," "))}if(!ie(s))return{text:n,lineMap:e};let i=oe(s),o=[],a=0;for(let g=0;g<=r;g++)o.push(t[g]),a++,e.set(a,g+1);for(let g=r+1;g<t.length;g++){let c=t[g],p=c.trim(),m=g+1;if(p===""){o.push(c),a++,e.set(a,m);continue}if(W.test(c)){o.push(c),a++,e.set(a,m);continue}if(z.test(c)){o.push(c),a++,e.set(a,m);continue}if(X.test(c))continue;let d=c.replace(/\t/g," "),u=Y.exec(d);if(u?.index!==void 0){let f=u.index,w=Math.round(f/i)+1,h=f+1;for(;h<d.length&&ne.test(d[h]);)h++;for(;h<d.length&&d[h]===" ";)h++;let y=d.slice(h).trimEnd();if(!y)throw new Error(`Line ${m}: Empty node \u2014 expected a filename or directory name after the box-drawing prefix`);let te=re.repeat(w);o.push(te+y),a++,e.set(a,m)}else{if(/^[\s─━│┃└┗├┣]+$/.test(d))continue;if(q.test(d))o.push(c),a++,e.set(a,m);else{if(/^\s+/.test(d))throw new Error(`Line ${m}: Unexpected indentation without box-drawing characters. In box-drawing format, use \u251C\u2500\u2500 or \u2514\u2500\u2500 prefixes for indented nodes.`);o.push(c),a++,e.set(a,m)}}}return{text:o.join(`
`),lineMap:e}}l(U,"preprocessBoxDrawing");var x=new O(()=>({cnt:1,stack:[{id:0,level:-1,name:"/",nodeType:"directory",children:[]}]})),se=l(()=>{x.reset(),G()},"clear"),ae=l(()=>x.records.stack[0],"getRoot"),ce=l(()=>x.records.cnt,"getCount"),de=S.treeView,le=l(()=>C(de,T().treeView),"getConfig"),pe=l((n,t,e,r,s,i)=>{for(;n<=x.records.stack[x.records.stack.length-1].level;)x.records.stack.pop();let o={id:x.records.cnt++,level:n,name:t,nodeType:e,icon:s,cssClass:r,description:i,children:[]};x.records.stack[x.records.stack.length-1].children.push(o),x.records.stack.push(o)},"addNode"),me={clear:se,addNode:pe,getRoot:ae,getCount:ce,getConfig:le,getAccTitle:A,getAccDescription:v,getDiagramTitle:P,setAccDescription:M,setAccTitle:$,setDiagramTitle:L},D=me;var ge=l(n=>{j(n,D);for(let t of n.nodes){let e=typeof t.indent=="number"?t.indent:0,r=t.name,s=r.endsWith("/");s&&(r=r.slice(0,-1));let i=s?"directory":"file",o=t.classAnnotation||void 0,a=t.iconAnnotation,g=a!==void 0?a||"none":void 0,c=t.descAnnotation||void 0,p=c?E(c,T()):void 0;D.addNode(e,r,i,o,g,p)}},"populate"),Z={parse:l(async n=>{let{text:t,lineMap:e}=U(n);try{let r=await _("treeView",t);V.debug(r),ge(r)}catch(r){throw e.size>0&&r instanceof Error&&(r.message=F(r.message,e)),r}},"parse")};var b={prefix:"mermaid-treeview",height:24,width:24,icons:{folder:{body:'<path fill="currentColor" d="M10.59 4.59A2 2 0 0 0 9.17 4H4a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.17z"/>'},file:{body:'<path fill="currentColor" fill-rule="evenodd" d="M6 2a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8.83a2 2 0 0 0-.59-1.42l-4.82-4.82A2 2 0 0 0 13.17 2H6Zm7.5 1.9l4.6 4.6h-3.6a1 1 0 0 1-1-1V3.9Z" clip-rule="evenodd"/>'}}};function fe(n,t){let e=t?.filenameIcons?.[n];if(e)return e;let r=n.lastIndexOf(".");if(r>0){let s=n.substring(r).toLowerCase(),i=t?.extensionIcons;return i?.[s]??i?.[s.slice(1)]}}l(fe,"detectIcon");function J(n,t){return n.includes(":")?n:n in b.icons||!t?`${b.prefix}:${n}`:`${t}:${n}`}l(J,"qualifyIcon");function I(n,t){if(n.icon!=="none"){if(n.icon)return J(n.icon,t.defaultIconPack);if(t.showIcons){if(n.nodeType==="file"){let e=fe(n.name,t);if(e==="none")return;if(e)return J(e,t.defaultIconPack)}return`${b.prefix}:${n.nodeType==="directory"?"folder":"file"}`}}}l(I,"getNodeIcon");k([{name:b.prefix,icons:b}]);var N=14,he=4,ue=16,we=l(async(n,t)=>{let e=[],r=l(i=>{let o=I(i,t);o&&e.push({icon:o,node:i}),i.children.forEach(r)},"collect");r(n);let s=await Promise.all(e.map(async({icon:i,node:o})=>({id:o.id,svg:await B(i,{height:N,width:N})})));return new Map(s.map(({id:i,svg:o})=>[i,o]))},"resolveNodeIcons"),xe=l((n,t,e,r,s,i)=>{let o=r.append("g"),a="treeView-node-label";e.nodeType==="directory"&&(a+=" treeView-node-dir"),e.cssClass&&(a+=` ${e.cssClass}`);let g=N+he,c=I(e,s),p=c!==void 0;c&&o.append("g").attr("class","treeView-node-icon").attr("transform",`translate(${n+s.paddingX}, ${t+s.paddingY})`).html(i.get(e.id)??"");let m=o.append("text").text(e.name).attr("dominant-baseline","middle").attr("class",a),{height:d,width:u}=m.node().getBBox(),f=d+s.paddingY*2,w=n+s.paddingX+(p?g:0);m.attr("x",w),m.attr("y",t+f/2);let h=w+u,y=u+s.paddingX*2+(p?g:0);return e.BBox={x:n,y:t,width:y,height:f},e.cssClass?.split(/\s+/).includes("highlight")&&o.insert("rect",":first-child").attr("x",n).attr("y",t+1).attr("width",0).attr("height",f-2).attr("rx",3).attr("class","treeView-highlight-bg"),{node:e,nodeGroup:o,labelRightEdge:h,centerY:t+f/2}},"positionLabel"),K=l((n,t,e,r,s,i)=>n.append("line").attr("x1",t).attr("y1",e).attr("x2",r).attr("y2",s).attr("stroke-width",i).attr("class","treeView-node-line"),"positionLine"),ye=l((n,t,e,r)=>{let s=0,i=0,o=[],a=l((p,m,d,u)=>{let f=u*(d.rowIndent+d.paddingX),w=xe(f,s,m,p,d,r);o.push(w);let{height:h,width:y}=m.BBox;K(p,f-d.rowIndent,s+h/2,f,s+h/2,d.lineThickness),i=Math.max(i,f+y),s+=h},"drawNode"),g=l((p,m=0)=>{a(n,p,e,m),p.children.forEach(w=>{g(w,m+1)});let{x:d,y:u,height:f}=p.BBox;if(p.children.length){let{y:w,height:h}=p.children[p.children.length-1].BBox;K(n,d+e.paddingX,u+f,d+e.paddingX,w+h/2+e.lineThickness/2,e.lineThickness)}},"processNode");g(t);let c=o.filter(p=>p.node.description);if(c.length>0){let m=Math.max(...o.map(d=>d.labelRightEdge))+ue;for(let d of c){let f=d.nodeGroup.append("text").text(d.node.description).attr("dominant-baseline","middle").attr("class","treeView-node-description").attr("x",m).attr("y",d.centerY).node().getBBox();i=Math.max(i,m+f.width+e.paddingX)}}for(let p of o)if(p.node.cssClass?.split(/\s+/).includes("highlight")){let m=p.nodeGroup.select(".treeView-highlight-bg");if(!m.empty()){let d=i-p.node.BBox.x+8;m.attr("width",d),i=Math.max(i,p.node.BBox.x+d+2)}}return{totalHeight:s,totalWidth:i}},"drawTree"),be=l(async(n,t,e,r)=>{V.debug(`Rendering treeView diagram
`+n);let s=r.db,i=s.getRoot(),o=s.getConfig(),a=H(t),g=a.append("g");g.attr("class","tree-view");let c=await we(i,o),{totalHeight:p,totalWidth:m}=ye(g,i,o,c);a.attr("viewBox",`-${o.lineThickness/2} 0 ${m} ${p}`),R(a,p,m,o.useMaxWidth)},"draw"),De={draw:be},Q=De;var Ve={labelFontSize:"16px",labelColor:"black",lineColor:"black",iconColor:"#546e7a",descriptionColor:"#6a9955",highlightBg:"rgba(255, 193, 7, 0.15)",highlightStroke:"#ffc107"},Te=l(({treeView:n})=>{let{labelFontSize:t,labelColor:e,lineColor:r,iconColor:s,descriptionColor:i,highlightBg:o,highlightStroke:a}=C(Ve,n);return`
.treeView-node-label {
font-size: ${t};
fill: ${e};
white-space: pre;
}
.treeView-node-dir {
font-weight: bold;
}
.treeView-node-line {
stroke: ${r};
}
.treeView-node-icon {
color: ${s};
}
.treeView-node-description {
font-size: ${t};
fill: ${i};
font-style: italic;
white-space: pre;
}
.treeView-highlight-bg {
fill: ${o};
stroke: ${a};
stroke-width: 1;
}
`},"styles"),ee=Te;var it={db:D,renderer:Q,parser:Z,styles:ee};export{it as diagram};