UNPKG

mermaid

Version:

Markdown-ish syntax for generating flowcharts, mindmaps, sequence diagrams, class diagrams, gantt charts, git graphs and more.

31 lines (30 loc) 8.85 kB
import{a as O}from"./chunk-T5OCTHI4.mjs";import{a as _}from"./chunk-JQRUD6KW.mjs";import{a as P}from"./chunk-DMV4VAQV.mjs";import"./chunk-HNC4WDU7.mjs";import"./chunk-SATU7PGQ.mjs";import"./chunk-224SPVON.mjs";import"./chunk-EQFTRU2I.mjs";import"./chunk-E5QJAATJ.mjs";import"./chunk-66DQ2XMT.mjs";import"./chunk-D6VWDJW2.mjs";import"./chunk-BI6VK774.mjs";import"./chunk-XNMVGMAZ.mjs";import"./chunk-4RFN2BYJ.mjs";import"./chunk-FWYVLQTC.mjs";import"./chunk-RRFMTAIC.mjs";import"./chunk-TZUXEDM2.mjs";import"./chunk-OIYT25JQ.mjs";import"./chunk-NV3KIAZN.mjs";import"./chunk-L5GCOVLC.mjs";import{a as H}from"./chunk-6BELYETK.mjs";import{b as k,d as B}from"./chunk-2SREHG4O.mjs";import{o as C}from"./chunk-7CWYLC5S.mjs";import"./chunk-STOV2HOB.mjs";import{A as E,O as G,S as R,T as $,U as A,V as v,W as M,X as L,Y as j,j as N,t as T}from"./chunk-2AEHWXPW.mjs";import{b as D}from"./chunk-LIEV3EAG.mjs";import{a as l}from"./chunk-AQ6EADP3.mjs";var q=/[─━│┃└┗├┣]/,Y=/[└┗├┣]/,re=/[─━]/,z=/^[\s│┃]+$/,X=/^\s*(title[\t ]|accTitle[\t ]*:|accDescr[\t ]*[:{])/,W=/^\s*%%/,ie=" ";function oe(n){return n.some(e=>q.test(e))}l(oe,"isBoxDrawingFormat");function se(n){for(let e of n){let t=Y.exec(e);if(t?.index&&t.index>0)return t.index}return 4}l(se,"inferSegmentWidth");function F(n,e){return n.replace(/\bline\s+(\d+)\b/gi,(t,r)=>{let i=parseInt(r,10),c=e.get(i);return c?`line ${c}`:t})}l(F,"remapErrorLines");function U(n){let e=n.split(` `),t=new Map,r=-1;for(let[s,o]of e.entries())if(o.trim()==="treeView-beta"){r=s;break}if(r===-1)return{text:n,lineMap:t};let i=[];for(let s=r+1;s<e.length;s++){let o=e[s];o.trim()===""||W.test(o)||X.test(o)||z.test(o)||i.push(o.replace(/\t/g," "))}if(!oe(i))return{text:n,lineMap:t};let c=se(i),a=[],d=0;for(let s=0;s<=r;s++)a.push(e[s]),d++,t.set(d,s+1);for(let s=r+1;s<e.length;s++){let o=e[s],m=o.trim(),f=s+1;if(m===""){a.push(o),d++,t.set(d,f);continue}if(W.test(o)){a.push(o),d++,t.set(d,f);continue}if(X.test(o)){a.push(o),d++,t.set(d,f);continue}if(z.test(o))continue;let p=o.replace(/\t/g," "),u=Y.exec(p);if(u?.index!==void 0){let g=u.index,w=Math.round(g/c)+1,h=g+1;for(;h<p.length&&re.test(p[h]);)h++;for(;h<p.length&&p[h]===" ";)h++;let y=p.slice(h).trimEnd();if(!y)throw new Error(`Line ${f}: Empty node \u2014 expected a filename or directory name after the box-drawing prefix`);let ne=ie.repeat(w);a.push(ne+y),d++,t.set(d,f)}else{if(/^[\s─━│┃└┗├┣]+$/.test(p))continue;if(q.test(p))a.push(o),d++,t.set(d,f);else{if(/^\s+/.test(p))throw new Error(`Line ${f}: Unexpected indentation without box-drawing characters. In box-drawing format, use \u251C\u2500\u2500 or \u2514\u2500\u2500 prefixes for indented nodes.`);a.push(o),d++,t.set(d,f)}}}return{text:a.join(` `),lineMap:t}}l(U,"preprocessBoxDrawing");var x=new O(()=>({cnt:1,stack:[{id:0,level:-1,name:"/",nodeType:"directory",children:[]}]})),ce=l(()=>{x.reset(),R()},"clear"),ae=l(()=>x.records.stack[0],"getRoot"),de=l(()=>x.records.cnt,"getCount"),le=N.treeView,pe=l(()=>C(le,T().treeView),"getConfig"),me=l((n,e,t,r,i,c)=>{for(;n<=x.records.stack[x.records.stack.length-1].level;)x.records.stack.pop();let a={id:x.records.cnt++,level:n,name:e,nodeType:t,icon:i,cssClass:r,description:c,children:[]};x.records.stack[x.records.stack.length-1].children.push(a),x.records.stack.push(a)},"addNode"),fe={clear:ce,addNode:me,getRoot:ae,getCount:de,getConfig:pe,getAccTitle:A,getAccDescription:M,getDiagramTitle:j,setAccDescription:v,setAccTitle:$,setDiagramTitle:L},V=fe;var ge=l(n=>{_(n,V);for(let e of n.nodes){let t=typeof e.indent=="number"?e.indent:0,r=e.name,i=r.endsWith("/");i&&(r=r.slice(0,-1));let c=i?"directory":"file",a=e.classAnnotation||void 0,d=e.iconAnnotation,s=d!==void 0?d||"none":void 0,o=e.descAnnotation||void 0,m=o?E(o,T()):void 0;V.addNode(t,r,c,a,s,m)}},"populate"),Z={parse:l(async n=>{let{text:e,lineMap:t}=U(n);try{let r=await P("treeView",e);D.debug(r),ge(r)}catch(r){throw t.size>0&&r instanceof Error&&(r.message=F(r.message,t)),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 he(n,e){let t=e?.filenameIcons?.[n];if(t)return t;let r=n.lastIndexOf(".");if(r>0){let i=n.substring(r).toLowerCase(),c=e?.extensionIcons;return c?.[i]??c?.[i.slice(1)]}}l(he,"detectIcon");function J(n,e){return n.includes(":")?n:n in b.icons||!e?`${b.prefix}:${n}`:`${e}:${n}`}l(J,"qualifyIcon");function I(n,e){if(n.icon!=="none"){if(n.icon)return J(n.icon,e.defaultIconPack);if(e.showIcons){if(n.nodeType==="file"){let t=he(n.name,e);if(t==="none")return;if(t)return J(t,e.defaultIconPack)}return`${b.prefix}:${n.nodeType==="directory"?"folder":"file"}`}}}l(I,"getNodeIcon");k([{name:b.prefix,icons:b}]);var S=14,ue=4,we=16,Q=l((n,e)=>`tv-icon-${n}-${e.replace(/[^\w-]/g,"-")}`,"iconSymbolId"),xe=l(async(n,e,t,r)=>{let i=new Set,c=l(s=>{let o=I(s,t);o&&i.add(o),s.children.forEach(c)},"collect");if(c(e),i.size===0)return;let a=await Promise.all([...i].map(async s=>({icon:s,svg:await B(s,{height:S,width:S})}))),d=n.append("defs");for(let{icon:s,svg:o}of a)d.append("g").attr("id",Q(r,s)).html(o)},"injectIconDefs"),ye=l((n,e,t,r,i,c)=>{let a=r.append("g"),d="treeView-node-label";t.nodeType==="directory"&&(d+=" treeView-node-dir"),t.cssClass&&(d+=` ${t.cssClass}`);let s=S+ue,o=I(t,i),m=o!==void 0;o&&a.append("use").attr("xlink:href",`#${Q(c,o)}`).attr("x",n+i.paddingX).attr("y",e+i.paddingY).attr("class","treeView-node-icon");let f=a.append("text").text(t.name).attr("dominant-baseline","middle").attr("class",d),{height:p,width:u}=f.node().getBBox(),g=p+i.paddingY*2,w=n+i.paddingX+(m?s:0);f.attr("x",w),f.attr("y",e+g/2);let h=w+u,y=u+i.paddingX*2+(m?s:0);return t.BBox={x:n,y:e,width:y,height:g},t.cssClass?.split(/\s+/).includes("highlight")&&a.insert("rect",":first-child").attr("x",n).attr("y",e+1).attr("width",0).attr("height",g-2).attr("rx",3).attr("class","treeView-highlight-bg"),{node:t,nodeGroup:a,labelRightEdge:h,centerY:e+g/2}},"positionLabel"),K=l((n,e,t,r,i,c)=>n.append("line").attr("x1",e).attr("y1",t).attr("x2",r).attr("y2",i).attr("stroke-width",c).attr("class","treeView-node-line"),"positionLine"),be=l((n,e,t,r)=>{let i=0,c=0,a=[],d=l((m,f,p,u)=>{let g=u*(p.rowIndent+p.paddingX),w=ye(g,i,f,m,p,r);a.push(w);let{height:h,width:y}=f.BBox;K(m,g-p.rowIndent,i+h/2,g,i+h/2,p.lineThickness),c=Math.max(c,g+y),i+=h},"drawNode"),s=l((m,f=0)=>{d(n,m,t,f),m.children.forEach(w=>{s(w,f+1)});let{x:p,y:u,height:g}=m.BBox;if(m.children.length){let{y:w,height:h}=m.children[m.children.length-1].BBox;K(n,p+t.paddingX,u+g,p+t.paddingX,w+h/2+t.lineThickness/2,t.lineThickness)}},"processNode");s(e);let o=a.filter(m=>m.node.description);if(o.length>0){let f=Math.max(...a.map(p=>p.labelRightEdge))+we;for(let p of o){let g=p.nodeGroup.append("text").text(p.node.description).attr("dominant-baseline","middle").attr("class","treeView-node-description").attr("x",f).attr("y",p.centerY).node().getBBox();c=Math.max(c,f+g.width+t.paddingX)}}for(let m of a)if(m.node.cssClass?.split(/\s+/).includes("highlight")){let f=m.nodeGroup.select(".treeView-highlight-bg");if(!f.empty()){let p=c-m.node.BBox.x+8;f.attr("width",p),c=Math.max(c,m.node.BBox.x+p+2)}}return{totalHeight:i,totalWidth:c}},"drawTree"),Ve=l(async(n,e,t,r)=>{D.debug(`Rendering treeView diagram `+n);let i=r.db,c=i.getRoot(),a=i.getConfig(),d=H(e);await xe(d,c,a,e);let s=d.append("g");s.attr("class","tree-view");let{totalHeight:o,totalWidth:m}=be(s,c,a,e);d.attr("viewBox",`-${a.lineThickness/2} 0 ${m} ${o}`),G(d,o,m,a.useMaxWidth)},"draw"),De={draw:Ve},ee=De;var Te={labelFontSize:"16px",labelColor:"black",lineColor:"black",iconColor:"#546e7a",descriptionColor:"#6a9955",highlightBg:"rgba(255, 193, 7, 0.15)",highlightStroke:"#ffc107"},Ce=l(({treeView:n})=>{let{labelFontSize:e,labelColor:t,lineColor:r,iconColor:i,descriptionColor:c,highlightBg:a,highlightStroke:d}=C(Te,n);return` .treeView-node-label { font-size: ${e}; fill: ${t}; white-space: pre; } .treeView-node-dir { font-weight: bold; } .treeView-node-line { stroke: ${r}; } .treeView-node-icon { color: ${i}; } .treeView-node-description { font-size: ${e}; fill: ${c}; font-style: italic; white-space: pre; } .treeView-highlight-bg { fill: ${a}; stroke: ${d}; stroke-width: 1; } `},"styles"),te=Ce;var ot={db:V,renderer:ee,parser:Z,styles:te};export{ot as diagram};