import{p as setDiagramTitle,b as setAccTitle,s as setAccDescription,q as getDiagramTitle,g as getAccDescription,a as getAccTitle,_ as __name,E as cleanAndMerge,l as log,H as selectSvgElement,e as configureSvgSize,C as getConfig,F as defaultConfig_default,y as clear}from"./mermaid.core-BV3ugHFm.js";import{p as populateCommonDb}from"./chunk-4BX2VUAB-CMTnvZkS.js";import{I as ImperativeState}from"./chunk-QZHKN3VN-CoYnjUpS.js";import{p as parse}from"./wardley-RL74JXVD-ByDpAPp1.js";import"./vendor-mdxeditor-Cco3AQJS.js";import"./vendor-antd-Bur5ZxWE.js";import"./vendor-codemirror-Si44UqBp.js";import"./vendor-markdown-DOJHsAxX.js";import"./min-D-YA3MGY.js";import"./_baseUniq-r3p3rodd.js";var state=new ImperativeState(()=>({cnt:1,stack:[{id:0,level:-1,name:"/",children:[]}]})),clear2=__name(()=>{state.reset(),clear()},"clear"),getRoot=__name(()=>state.records.stack[0],"getRoot"),getCount=__name(()=>state.records.cnt,"getCount"),defaultConfig=defaultConfig_default.treeView,getConfig2=__name(()=>cleanAndMerge(defaultConfig,getConfig().treeView),"getConfig"),db_default={clear:clear2,addNode:__name((level,name)=>{for(;level<=state.records.stack[state.records.stack.length-1].level;)state.records.stack.pop();const node={id:state.records.cnt++,level:level,name:name,children:[]};state.records.stack[state.records.stack.length-1].children.push(node),state.records.stack.push(node)},"addNode"),getRoot:getRoot,getCount:getCount,getConfig:getConfig2,getAccTitle:getAccTitle,getAccDescription:getAccDescription,getDiagramTitle:getDiagramTitle,setAccDescription:setAccDescription,setAccTitle:setAccTitle,setDiagramTitle:setDiagramTitle},populate=__name(ast=>{populateCommonDb(ast,db_default),ast.nodes.map(node=>db_default.addNode(node.indent?parseInt(node.indent):0,node.name))},"populate"),parser={parse:__name(async input=>{const ast=await parse("treeView",input);log.debug(ast),populate(ast)},"parse")},positionLabel=__name((x,y,node,domElem,config)=>{const label=domElem.append("text").text(node.name).attr("dominant-baseline","middle").attr("class","treeView-node-label"),{height:labelHeight,width:labelWidth}=label.node().getBBox(),height=labelHeight+2*config.paddingY,width=labelWidth+2*config.paddingX;label.attr("x",x+config.paddingX),label.attr("y",y+height/2),node.BBox={x:x,y:y,width:width,height:height}},"positionLabel"),positionLine=__name((domElem,x1,y1,x2,y2,lineThickness)=>domElem.append("line").attr("x1",x1).attr("y1",y1).attr("x2",x2).attr("y2",y2).attr("stroke-width",lineThickness).attr("class","treeView-node-line"),"positionLine"),drawTree=__name((elem,root,config)=>{let totalHeight=0,totalWidth=0;const drawNode=__name((elem2,node,config2,depth)=>{const indent=depth*(config2.rowIndent+config2.paddingX);positionLabel(indent,totalHeight,node,elem2,config2);const{height:height,width:width}=node.BBox;positionLine(elem2,indent-config2.rowIndent,totalHeight+height/2,indent,totalHeight+height/2,config2.lineThickness),totalWidth=Math.max(totalWidth,indent+width),totalHeight+=height},"drawNode"),processNode=__name((node,depth=0)=>{drawNode(elem,node,config,depth),node.children.forEach(child=>{processNode(child,depth+1)});const{x:x,y:y,height:height}=node.BBox;if(node.children.length){const{y:endY,height:endHeight}=node.children[node.children.length-1].BBox;positionLine(elem,x+config.paddingX,y+height,x+config.paddingX,endY+endHeight/2+config.lineThickness/2,config.lineThickness)}},"processNode");return processNode(root),{totalHeight:totalHeight,totalWidth:totalWidth}},"drawTree"),defaultTreeViewDiagramStyles={labelFontSize:"16px",labelColor:"black",lineColor:"black"},diagram={db:db_default,renderer:{draw:__name((text,id,_ver,diagObj)=>{log.debug("Rendering treeView diagram\n"+text);const db2=diagObj.db,root=db2.getRoot(),config=db2.getConfig(),svg=selectSvgElement(id),treeElem=svg.append("g");treeElem.attr("class","tree-view");const{totalHeight:totalHeight,totalWidth:totalWidth}=drawTree(treeElem,root,config);svg.attr("viewBox",`-${config.lineThickness/2} 0 ${totalWidth} ${totalHeight}`),configureSvgSize(svg,totalHeight,totalWidth,config.useMaxWidth)},"draw")},parser:parser,styles:__name(({treeView:treeView})=>{const{labelFontSize:labelFontSize,labelColor:labelColor,lineColor:lineColor}=cleanAndMerge(defaultTreeViewDiagramStyles,treeView);return`\n    .treeView-node-label {\n        font-size: ${labelFontSize};\n        fill: ${labelColor};\n    }\n    .treeView-node-line {\n        stroke: ${lineColor};\n    }\n    `},"styles")};export{diagram};
