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