import{n as e}from"./chunk-Y2CYZVJY.DsF7k-Jl.js";import{t}from"./src.DMVfaFne.js";import{H as n,K as r,U as i,a,b as o,c as s,f as c,v as l,w as u,y as d,z as f}from"./chunk-I66GZJ75.DE9AwV3O.js";import{i as p}from"./chunk-NSK5VX7P.Bdf5aQAc.js";import{t as m}from"./chunk-3NCLNEKW.ceKyfhHo.js";import{t as h}from"./chunk-JWPE2WC7.A3RzWITa.js";import{n as g}from"./mermaid-parser.core.CG5TU4Z9.js";import{r as _,t as v}from"./chunk-4I5QYGJK.hg4ofZMO.js";import{t as y}from"./chunk-2Q5K7J3B.BsaEqoYJ.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))}e(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}e(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})}e(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}}e(A,`preprocessBoxDrawing`);var j=new y(()=>({cnt:1,stack:[{id:0,level:-1,name:`/`,nodeType:`directory`,children:[]}]})),M=e(()=>{j.reset(),a()},`clear`),N=e(()=>j.records.stack[0],`getRoot`),P=e(()=>j.records.cnt,`getCount`),F=c.treeView,I={clear:M,addNode:e((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:e(()=>p(F,o().treeView),`getConfig`),getAccTitle:d,getAccDescription:l,getDiagramTitle:u,setAccDescription:n,setAccTitle:i,setDiagramTitle:r},L=e(e=>{h(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,s=t.iconAnnotation,c=s===void 0?void 0:s||`none`,l=t.descAnnotation||void 0,u=l?f(l,o()):void 0;I.addNode(e,n,i,a,c,u)}},`populate`),R={parse:e(async e=>{let{text:n,lineMap:r}=A(e);try{let e=await g(`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)]}}e(B,`detectIcon`);function V(e,t){return e.includes(`:`)?e:e in z.icons||!t?`${z.prefix}:${e}`:`${t}:${e}`}e(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`}`}}}e(H,`getNodeIcon`),_([{name:z.prefix,icons:z}]);var U=14,W=4,G=16,K=e((e,t)=>`tv-icon-${e}-${t.replace(/[^\w-]/g,`-`)}`,`iconSymbolId`),q=e(async(t,n,r,i)=>{let a=new Set,o=e(e=>{let t=H(e,r);t&&a.add(t),e.children.forEach(o)},`collect`);if(o(n),a.size===0)return;let s=await Promise.all([...a].map(async e=>({icon:e,svg:await v(e,{height:U,width:U})}))),c=t.append(`defs`);for(let{icon:e,svg:t}of s)c.append(`g`).attr(`id`,K(i,e)).html(t)},`injectIconDefs`),J=e((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=e((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=e((t,n,r,i)=>{let a=0,o=0,s=[],c=e((e,t,n,r)=>{let c=r*(n.rowIndent+n.paddingX),l=J(c,a,t,e,n,i);s.push(l);let{height:u,width:d}=t.BBox;Y(e,c-n.rowIndent,a+u/2,c,a+u/2,n.lineThickness),o=Math.max(o,c+d),a+=u},`drawNode`),l=e((e,n=0)=>{c(t,e,r,n),e.children.forEach(e=>{l(e,n+1)});let{x:i,y:a,height:o}=e.BBox;if(e.children.length){let{y:n,height:s}=e.children[e.children.length-1].BBox;Y(t,i+r.paddingX,a+o,i+r.paddingX,n+s/2+r.lineThickness/2,r.lineThickness)}},`processNode`);l(n);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 n=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+n.width+r.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:a,totalWidth:o}},`drawTree`),Z={draw:e(async(e,n,r,i)=>{t.debug(`Rendering treeView diagram
`+e);let a=i.db,o=a.getRoot(),c=a.getConfig(),l=m(n);await q(l,o,c,n);let u=l.append(`g`);u.attr(`class`,`tree-view`);let{totalHeight:d,totalWidth:f}=X(u,o,c,n);l.attr(`viewBox`,`-${c.lineThickness/2} 0 ${f} ${d}`),s(l,d,f,c.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:e(({treeView:e})=>{let{labelFontSize:t,labelColor:n,lineColor:r,iconColor:i,descriptionColor:a,highlightBg:o,highlightStroke:s}=p(Q,e);return`
    .treeView-node-label {
        font-size: ${t};
        fill: ${n};
        white-space: pre;
    }
    .treeView-node-dir {
        font-weight: bold;
    }
    .treeView-node-line {
        stroke: ${r};
    }
    .treeView-node-icon {
        color: ${i};
    }
    .treeView-node-description {
        font-size: ${t};
        fill: ${a};
        font-style: italic;
        white-space: pre;
    }
    .treeView-highlight-bg {
        fill: ${o};
        stroke: ${s};
        stroke-width: 1;
    }
    `},`styles`)};export{$ as diagram};