import{_asw,aVas_,aWasY,aXasj,aYasF,lasr,casH,aZasV,a_as$,aiasQ,aQasU,ajasP,ahasW,a$asZ,b0asq,b1asz}from"./mermaid.core.BrszyIat.js";import{iasN,GasB}from"./graph.CPCuV3C_.js";import{basK,masR,lasI}from"./layout.Dsmt3fdL.js";import"./framework.C2AwuPrQ.js";varee=4;functionne(e){returnK(e,ee)}functionb(e){vart={options:{directed:e.isDirected(),multigraph:e.isMultigraph(),compound:e.isCompound()},nodes:te(e),edges:se(e)};returnN(e.graph())||(t.value=ne(e.graph())),t}functionte(e){returnR(e.nodes(),function(t){varn=e.node(t),a=e.parent(t),i={v:t};returnN(n)||(i.value=n),N(a)||(i.parent=a),i})}functionse(e){returnR(e.edges(),function(t){varn=e.edge(t),a={v:t.v,w:t.w};returnN(t.name)||(a.name=t.name),N(n)||(a.value=n),a})}vard=newMap,y=newMap,A=newMap,re=w(()=>{y.clear(),A.clear(),d.clear()},"clear"),D=w((e,t)=>{constn=y.get(t)||[];returnr.trace("In isDescendant",t," ",e," = ",n.includes(e)),n.includes(e)},"isDescendant"),ie=w((e,t)=>{constn=y.get(t)||[];returnr.info("Descendants of ",t," is ",n),r.info("Edge is ",e),e.v===t||e.w===t?!1:n?n.includes(e.v)||D(e.v,t)||D(e.w,t)||n.includes(e.w):(r.debug("Tilt, ",t,",not in descendants"),!1)},"edgeInCluster"),G=w((e,t,n,a)=>{r.warn("Copying children of ",e,"root",a,"data",t.node(e),a);consti=t.children(e)||[];e!==a&&i.push(e),r.warn("Copying (nodes) clusterId",e,"nodes",i),i.forEach(o=>{if(t.children(o).length>0)G(o,t,n,a);else{constl=t.node(o);r.info("cp ",o," to ",a," with parent ",e),n.setNode(o,l),a!==t.parent(o)&&(r.warn("Setting parent",o,t.parent(o)),n.setParent(o,t.parent(o))),e!==a&&o!==e?(r.debug("Setting parent",o,e),n.setParent(o,e)):(r.info("In copy ",e,"root",a,"data",t.node(e),a),r.debug("Not Setting parent for node=",o,"cluster!==rootId",e!==a,"node!==clusterId",o!==e));constu=t.edges(o);r.debug("Copying Edges",u),u.forEach(c=>{r.info("Edge",c);constm=t.edge(c.v,c.w,c.name);r.info("Edge data",m,a);try{ie(c,a)?(r.info("Copying as ",c.v,c.w,m,c.name),n.setEdge(c.v,c.w,m,c.name),r.info("newGraph edges ",n.edges(),n.edge(n.edges()[0]))):r.info("Skipping copy of edge ",c.v,"-->",c.w," rootId: ",a," clusterId:",e)}catch(h){r.error(h)}})}r.debug("Removing node",o),t.removeNode(o)})},"copy"),J=w((e,t)=>{constn=t.children(e);leta=[...n];for(constiofn)A.set(i,e),a=[...a,...J(i,t)];returna},"extractDescendants"),oe=w((e,t,n)=>{consta=e.edges().filter(c=>c.v===t||c.w===t),i=e.edges().filter(c=>c.v===n||c.w===n),o=a.map(c=>({v:c.v===t?n:c.v,w:c.w===t?t:c.w})),l=i.map(c=>({v:c.v,w:c.w}));returno.filter(c=>l.some(m=>c.v===m.v&&c.w===m.w))},"findCommonEdges"),C=w((e,t,n)=>{consta=t.children(e);if(r.trace("Searching children of id ",e,a),a.length<1)returne;leti;for(constoofa){constl=C(o,t,n),u=oe(t,n,l);if(l)if(u.length>0)i=l;elsereturnl}returni},"findNonClusterChild"),k=w(e=>!d.has(e)||!d.get(e).externalConnections?e:d.has(e)?d.get(e).id:e,"getAnchorId"),ae=w((e,t)=>{if(!e||t>10){r.debug("Opting out, no graph ");return}elser.debug("Opting in, graph ");e.nodes().forEach(function(n){e.children(n).length>0&&(r.warn("Cluster identified",n," Replacement id in edges: ",C(n,e,n)),y.set(n,J(n,e)),d.set(n,{id:C(n,e,n),clusterData:e.node(n)}))}),e.nodes().forEach(function(n){consta=e.children(n),i=e.edges();a.length>0?(r.debug("Cluster identified",n,y),i.forEach(o=>{constl=D(o.v,n),u=D(o.w,n);l^u&&(r.warn("Edge: ",o," leaves cluster ",n),r.warn("Descendants of XXX ",n,": ",y.get(n)),d.get(n).externalConnections=!0)})):r.debug("Not a cluster ",n,y)});for(letnofd.keys()){consta=d.get(n).id,i=e.parent(a);i!==n&&d.has(i)&&!d.get(i).externalConnections&&(d.get(n).id=i)}e.edges().forEach(function(n){consta=e.edge(n);r.warn("Edge "+n.v+" -> "+n.w+": "+JSON.stringify(n)),r.warn("Edge "+n.v+" -> "+n.w+": "+JSON.stringify(e.edge(n)));leti=n.v,o=n.w;if(r.warn("Fix XXX",d,"ids:",n.v,n.w,"Translating: ",d.get(n.v)," --- ",d.get(n.w)),d.get(n.v)||d.get(n.w)){if(r.warn("Fixing and trying - removing XXX",n.v,n.w,n.name),i=k(n.v),o=k(n.w),e.removeEdge(n.v,n.w,n.name),i!==n.v){constl=e.parent(i);d.get(l).external