/*! third party licenses: js/vendor.LICENSE.txt */ import{G as M}from"./graph-BOKMr-rC.chunk.mjs";import{l as q}from"./layout-_kSBx-Bz.chunk.mjs";import{i as E}from"./_baseUniq-CE6homwJ.chunk.mjs";import{c as A}from"./clone-Dt8ItUbV.chunk.mjs";import{m as J}from"./_basePickBy-0DU--7tw.chunk.mjs";import{i as H,u as W,s as z,c as K,b as Q,g as D,d as O,a as U,p as V,e as T,f as G,h as Y,j as Z}from"./edges-e0da2a9e-DwTLA3-l.chunk.mjs";import{l as n,g as B,q as C}from"./index-CyCAgei9.chunk.mjs";import{c as _}from"./createText-2e5e7dd3-DGO2Nq3C.chunk.mjs";import{s as I}from"./isEmpty-nTVdZyYD.chunk.mjs";function v(r){var e={options:{directed:r.isDirected(),multigraph:r.isMultigraph(),compound:r.isCompound()},nodes:ee(r),edges:te(r)};return E(r.graph())||(e.value=A(r.graph())),e}function ee(r){return J(r.nodes(),function(e){var t=r.node(e),a=r.parent(e),i={v:e};return E(t)||(i.value=t),E(a)||(i.parent=a),i})}function te(r){return J(r.edges(),function(e){var t=r.edge(e),a={v:e.v,w:e.w};return E(e.name)||(a.name=e.name),E(t)||(a.value=t),a})}let l={},u={},R={};const re=()=>{u={},R={},l={}},S=(r,e)=>(n.trace("In isDescendant",e," ",r," = ",u[e].includes(r)),!!u[e].includes(r)),ie=(r,e)=>(n.info("Descendants of ",e," is ",u[e]),n.info("Edge is ",r),r.v===e||r.w===e?!1:u[e]?u[e].includes(r.v)||S(r.v,e)||S(r.w,e)||u[e].includes(r.w):(n.debug("Tilt, ",e,",not in descendants"),!1)),L=(r,e,t,a)=>{n.warn("Copying children of ",r,"root",a,"data",e.node(r),a);const i=e.children(r)||[];r!==a&&i.push(r),n.warn("Copying (nodes) clusterId",r,"nodes",i),i.forEach(o=>{if(e.children(o).length>0)L(o,e,t,a);else{const c=e.node(o);n.info("cp ",o," to ",a," with parent ",r),t.setNode(o,c),a!==e.parent(o)&&(n.warn("Setting parent",o,e.parent(o)),t.setParent(o,e.parent(o))),r!==a&&o!==r?(n.debug("Setting parent",o,r),t.setParent(o,r)):(n.info("In copy ",r,"root",a,"data",e.node(r),a),n.debug("Not Setting parent for node=",o,"cluster!==rootId",r!==a,"node!==clusterId",o!==r));const g=e.edges(o);n.debug("Copying Edges",g),g.forEach(h=>{n.info("Edge",h);const f=e.edge(h.v,h.w,h.name);n.info("Edge data",f,a);try{ie(h,a)?(n.info("Copying as ",h.v,h.w,f,h.name),t.setEdge(h.v,h.w,f,h.name),n.info("newGraph edges ",t.edges(),t.edge(t.edges()[0]))):n.info("Skipping copy of edge ",h.v,"-->",h.w," rootId: ",a," clusterId:",r)}catch(w){n.error(w)}})}n.debug("Removing node",o),e.removeNode(o)})},k=(r,e)=>{const t=e.children(r);let a=[...t];for(const i of t)R[i]=r,a=[...a,...k(i,e)];return a},N=(r,e)=>{n.trace("Searching",r);const t=e.children(r);if(n.trace("Searching children of id ",r,t),t.length<1)return n.trace("This is a valid node",r),r;for(const a of t){const i=N(a,e);if(i)return n.trace("Found replacement for",r," => ",i),i}},X=r=>!l[r]||!l[r].externalConnections?r:l[r]?l[r].id:r,ne=(r,e)=>{if(!r||e>10){n.debug("Opting out, no graph ");return}else n.debug("Opting in, graph ");r.nodes().forEach(function(t){r.children(t).length>0&&(n.warn("Cluster identified",t," Replacement id in edges: ",N(t,r)),u[t]=k(t,r),l[t]={id:N(t,r),clusterData:r.node(t)})}),r.nodes().forEach(function(t){const a=r.children(t),i=r.edges();a.length>0?(n.debug("Cluster identified",t,u),i.forEach(o=>{if(o.v!==t&&o.w!==t){const c=S(o.v,t),g=S(o.w,t);c^g&&(n.warn("Edge: ",o," leaves cluster ",t),n.warn("Descendants of XXX ",t,": ",u[t]),l[t].externalConnections=!0)}})):n.debug("Not a cluster ",t,u)});for(let t of Object.keys(l)){const a=l[t].id,i=r.parent(a);i!==t&&l[i]&&!l[i].externalConnections&&(l[t].id=i)}r.edges().forEach(function(t){const a=r.edge(t);n.warn("Edge "+t.v+" -> "+t.w+": "+JSON.stringify(t)),n.warn("Edge "+t.v+" -> "+t.w+": "+JSON.stringify(r.edge(t)));let i=t.v,o=t.w;if(n.warn("Fix XXX",l,"ids:",t.v,t.w,"Translating: ",l[t.v]," --- ",l[t.w]),l[t.v]&&l[t.w]&&l[t.v]===l[t.w]){n.warn("Fixing and trixing link to self - removing XXX",t.v,t.w,t.name),n.warn("Fixing and trixing - removing XXX",t.v,t.w,t.name),i=X(t.v),o=X(t.w),r.removeEdge(t.v,t.w,t.name);const c=t.w+"---"+t.v;r.setNode(c,{domId:c,id:c,labelStyle:"",labelText:a.label,padding:0,shape:"labelRect",style:""});const g=structuredClone(a),h=structuredClone(a);g.label="",g.arrowTypeEnd="none",h.label="",g.fromCluster=t.v,h.toCluster=t.v,r.setEdge(i,c,g,t.name+"-cyclic-special"),r.setEdge(c,o,h,t.name+"-cyclic-special")}else if(l[t.v]||l[t.w]){if(n.warn("Fixing and trixing - removing XXX",t.v,t.w,t.name),i=X(t.v),o=X(t.w),r.removeEdge(t.v,t.w,t.name),i!==t.v){const c=r.parent(i);l[c].externalConnections=!0,a.fromCluster=t.v}if(o!==t.w){const c=r.parent(o);l[c].externalConnections=!0,a.toCluster=t.w}n.warn("Fix Replacing with XXX",i,o,t.name),r.setEdge(i,o,a,t.name)}}),n.warn("Adjusted Graph",v(r)),F(r,0),n.trace(l)},F=(r,e)=>{if(n.warn("extractor - ",e,v(r),r.children("D")),e>10){n.error("Bailing out");return}let t=r.nodes(),a=!1;for(const i of t){const o=r.children(i);a=a||o.length>0}if(!a){n.debug("Done, no node has children",r.nodes());return}n.debug("Nodes = ",t,e);for(const i of t)if(n.debug("Extracting node",i,l,l[i]&&!l[i].externalConnections,!r.parent(i),r.node(i),r.children("D")," Depth ",e),!l[i])n.debug("Not a cluster",i,e);else if(!l[i].externalConnections&&r.children(i)&&r.children(i).length>0){n.warn("Cluster without external connections, without a parent and with children",i,e);let o=r.graph().rankdir==="TB"?"LR":"TB";l[i]&&l[i].clusterData&&l[i].clusterData.dir&&(o=l[i].clusterData.dir,n.warn("Fixing dir",l[i].clusterData.dir,o));const c=new M({multigraph:!0,compound:!0}).setGraph({rankdir:o,nodesep:50,ranksep:50,marginx:8,marginy:8}).setDefaultEdgeLabel(function(){return{}});n.warn("Old graph before copy",v(r)),L(i,r,c,i),r.setNode(i,{clusterNode:!0,id:i,clusterData:l[i].clusterData,labelText:l[i].labelText,graph:c}),n.warn("New graph after copy node: (",i,")",v(c)),n.debug("Old graph after copy",v(r))}else n.warn("Cluster ** ",i," **not meeting the criteria !externalConnections:",!l[i].externalConnections," no parent: ",!r.parent(i)," children ",r.children(i)&&r.children(i).length>0,r.children("D"),e),n.debug(l);t=r.nodes(),n.warn("New list of nodes",t);for(const i of t){const o=r.node(i);n.warn(" Now next level",i,o),o.clusterNode&&F(o.graph,e+1)}},P=(r,e)=>{if(e.length===0)return[];let t=Object.assign(e);return e.forEach(a=>{const i=r.children(a),o=P(r,i);t=[...t,...o]}),t},ae=r=>P(r,r.children()),oe=(r,e)=>{n.info("Creating subgraph rect for ",e.id,e);const t=B(),a=r.insert("g").attr("class","cluster"+(e.class?" "+e.class:"")).attr("id",e.id),i=a.insert("rect",":first-child"),o=C(t.flowchart.htmlLabels),c=a.insert("g").attr("class","cluster-label"),g=e.labelType==="markdown"?_(c,e.labelText,{style:e.labelStyle,useHtmlLabels:o}):c.node().appendChild(G(e.labelText,e.labelStyle,void 0,!0));let h=g.getBBox();if(C(t.flowchart.htmlLabels)){const d=g.children[0],s=I(g);h=d.getBoundingClientRect(),s.attr("width",h.width),s.attr("height",h.height)}const f=0*e.padding,w=f/2,p=e.width<=h.width+f?h.width+f:e.width;e.width<=h.width+f?e.diff=(h.width-e.width)/2-e.padding/2:e.diff=-e.padding/2,n.trace("Data ",e,JSON.stringify(e)),i.attr("style",e.style).attr("rx",e.rx).attr("ry",e.ry).attr("x",e.x-p/2).attr("y",e.y-e.height/2-w).attr("width",p).attr("height",e.height+f);const{subGraphTitleTopMargin:x}=D(t);o?c.attr("transform",`translate(${e.x-h.width/2}, ${e.y-e.height/2+x})`):c.attr("transform",`translate(${e.x}, ${e.y-e.height/2+x})`);const m=i.node().getBBox();return e.width=m.width,e.height=m.height,e.intersect=function(d){return T(e,d)},a},de=(r,e)=>{const t=r.insert("g").attr("class","note-cluster").attr("id",e.id),a=t.insert("rect",":first-child"),i=0*e.padding,o=i/2;a.attr("rx",e.rx).attr("ry",e.ry).attr("x",e.x-e.width/2-o).attr("y",e.y-e.height/2-o).attr("width",e.width+i).attr("height",e.height+i).attr("fill","none");const c=a.node().getBBox();return e.width=c.width,e.height=c.height,e.intersect=function(g){return T(e,g)},t},se=(r,e)=>{const t=B(),a=r.insert("g").attr("class",e.classes).attr("id",e.id),i=a.insert("rect",":first-child"),o=a.insert("g").attr("class","cluster-label"),c=a.append("rect"),g=o.node().appendChild(G(e.labelText,e.labelStyle,void 0,!0));let h=g.getBBox();if(C(t.flowchart.htmlLabels)){const d=g.children[0],s=I(g);h=d.getBoundingClientRect(),s.attr("width",h.width),s.attr("height",h.height)}h=g.getBBox();const f=0*e.padding,w=f/2,p=e.width<=h.width+e.padding?h.width+e.padding:e.width;e.width<=h.width+e.padding?e.diff=(h.width+e.padding*0-e.width)/2:e.diff=-e.padding/2,i.attr("class","outer").attr("x",e.x-p/2-w).attr("y",e.y-e.height/2-w).attr("width",p+f).attr("height",e.height+f),c.attr("class","inner").attr("x",e.x-p/2-w).attr("y",e.y-e.height/2-w+h.height-1).attr("width",p+f).attr("height",e.height+f-h.height-3);const{subGraphTitleTopMargin:x}=D(t);o.attr("transform",`translate(${e.x-h.width/2}, ${e.y-e.height/2-e.padding/3+(C(t.flowchart.htmlLabels)?5:3)+x})`);const m=i.node().getBBox();return e.height=m.height,e.intersect=function(d){return T(e,d)},a},le=(r,e)=>{const t=r.insert("g").attr("class",e.classes).attr("id",e.id),a=t.insert("rect",":first-child"),i=0*e.padding,o=i/2;a.attr("class","divider").attr("x",e.x-e.width/2-o).attr("y",e.y-e.height/2).attr("width",e.width+i).attr("height",e.height+i);const c=a.node().getBBox();return e.width=c.width,e.height=c.height,e.diff=-e.padding/2,e.intersect=function(g){return T(e,g)},t},he={rect:oe,roundedWithTitle:se,noteGroup:de,divider:le};let $={};const ce=(r,e)=>{n.trace("Inserting cluster");const t=e.shape||"rect";$[e.id]=he[t](r,e)},ge=()=>{$={}},j=async(r,e,t,a,i,o)=>{n.info("Graph in recursive render: XXX",v(e),i);const c=e.graph().rankdir;n.trace("Dir in recursive render - dir:",c);const g=r.insert("g").attr("class","root");e.nodes()?n.info("Recursive render XXX",e.nodes()):n.info("No nodes found for",e),e.edges().length>0&&n.trace("Recursive edges",e.edge(e.edges()[0]));const h=g.insert("g").attr("class","clusters"),f=g.insert("g").attr("class","edgePaths"),w=g.insert("g").attr("class","edgeLabels"),p=g.insert("g").attr("class","nodes");await Promise.all(e.nodes().map(async function(d){const s=e.node(d);if(i!==void 0){const y=JSON.parse(JSON.stringify(i.clusterData));n.info("Setting data for cluster XXX (",d,") ",y,i),e.setNode(i.id,y),e.parent(d)||(n.trace("Setting parent",d,i.id),e.setParent(d,i.id,y))}if(n.info("(Insert) Node XXX"+d+": "+JSON.stringify(e.node(d))),s&&s.clusterNode){n.info("Cluster identified",d,s.width,e.node(d));const y=await j(p,s.graph,t,a,e.node(d),o),b=y.elem;W(s,b),s.diff=y.diff||0,n.info("Node bounds (abc123)",d,s,s.width,s.x,s.y),z(b,s),n.warn("Recursive render complete ",b,s)}else e.children(d).length>0?(n.info("Cluster - the non recursive path XXX",d,s.id,s,e),n.info(N(s.id,e)),l[s.id]={id:N(s.id,e),node:s}):(n.info("Node - the non recursive path",d,s.id,s),await K(p,e.node(d),c))})),e.edges().forEach(function(d){const s=e.edge(d.v,d.w,d.name);n.info("Edge "+d.v+" -> "+d.w+": "+JSON.stringify(d)),n.info("Edge "+d.v+" -> "+d.w+": ",d," ",JSON.stringify(e.edge(d))),n.info("Fix",l,"ids:",d.v,d.w,"Translating: ",l[d.v],l[d.w]),Q(w,s)}),e.edges().forEach(function(d){n.info("Edge "+d.v+" -> "+d.w+": "+JSON.stringify(d))}),n.info("#############################################"),n.info("### Layout ###"),n.info("#############################################"),n.info(e),q(e),n.info("Graph after layout:",v(e));let x=0;const{subGraphTitleTotalMargin:m}=D(o);return ae(e).forEach(function(d){const s=e.node(d);n.info("Position "+d+": "+JSON.stringify(e.node(d))),n.info("Position "+d+": ("+s.x,","+s.y,") width: ",s.width," height: ",s.height),s&&s.clusterNode?(s.y+=m,O(s)):e.children(d).length>0?(s.height+=m,ce(h,s),l[s.id].node=s):(s.y+=m/2,O(s))}),e.edges().forEach(function(d){const s=e.edge(d);n.info("Edge "+d.v+" -> "+d.w+": "+JSON.stringify(s),s),s.points.forEach(b=>b.y+=m/2);const y=U(f,d,s,l,t,e,a);V(s,y)}),e.nodes().forEach(function(d){const s=e.node(d);n.info(d,s.type,s.diff),s.type==="group"&&(x=s.diff)}),{elem:g,diff:x}},Ee=async(r,e,t,a,i)=>{H(r,t,a,i),Y(),Z(),ge(),re(),n.warn("Graph at first:",JSON.stringify(v(e))),ne(e),n.warn("Graph after:",JSON.stringify(v(e)));const o=B();await j(r,e,a,i,void 0,o)};export{Ee as r}; //# sourceMappingURL=index-3862675e-HIKCu2iF.chunk.mjs.map