import{_asw,awasF,axasY,ayas_,azasH,lasi,casV,aAasz,aBasU,aias$,anasq,ajasP,ahasK,aCasQ,aDasW,aEasZ}from"./mermaid.core-Bp72wBaC.js";import{GasB}from"./graph-BI4iNatD.js";import{lasI}from"./layout-Dn20ATE3.js";import{iasb}from"./_baseUniq-Blm_akxr.js";import{casL}from"./clone-BbeogWA3.js";import{masA}from"./_basePickBy-BruevaAz.js";import"./index-BzKy-nNf.js";functionh(e){vart={options:{directed:e.isDirected(),multigraph:e.isMultigraph(),compound:e.isCompound()},nodes:ee(e),edges:ne(e)};returnb(e.graph())||(t.value=L(e.graph())),t}functionee(e){returnA(e.nodes(),function(t){varn=e.node(t),a=e.parent(t),r={v:t};returnb(n)||(r.value=n),b(a)||(r.parent=a),r})}functionne(e){returnA(e.edges(),function(t){varn=e.edge(t),a={v:t.v,w:t.w};returnb(t.name)||(a.name=t.name),b(n)||(a.value=n),a})}vard=newMap,p=newMap,J=newMap,te=w(()=>{p.clear(),J.clear(),d.clear()},"clear"),D=w((e,t)=>{constn=p.get(t)||[];returni.trace("In isDescendant",t," ",e," = ",n.includes(e)),n.includes(e)},"isDescendant"),se=w((e,t)=>{constn=p.get(t)||[];returni.info("Descendants of ",t," is ",n),i.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):(i.debug("Tilt, ",t,",not in descendants"),!1)},"edgeInCluster"),G=w((e,t,n,a)=>{i.warn("Copying children of ",e,"root",a,"data",t.node(e),a);constr=t.children(e)||[];e!==a&&r.push(e),i.warn("Copying (nodes) clusterId",e,"nodes",r),r.forEach(o=>{if(t.children(o).length>0)G(o,t,n,a);else{constl=t.node(o);i.info("cp ",o," to ",a," with parent ",e),n.setNode(o,l),a!==t.parent(o)&&(i.warn("Setting parent",o,t.parent(o)),n.setParent(o,t.parent(o))),e!==a&&o!==e?(i.debug("Setting parent",o,e),n.setParent(o,e)):(i.info("In copy ",e,"root",a,"data",t.node(e),a),i.debug("Not Setting parent for node=",o,"cluster!==rootId",e!==a,"node!==clusterId",o!==e));constu=t.edges(o);i.debug("Copying Edges",u),u.forEach(c=>{i.info("Edge",c);constm=t.edge(c.v,c.w,c.name);i.info("Edge data",m,a);try{se(c,a)?(i.info("Copying as ",c.v,c.w,m,c.name),n.setEdge(c.v,c.w,m,c.name),i.info("newGraph edges ",n.edges(),n.edge(n.edges()[0]))):i.info("Skipping copy of edge ",c.v,"-->",c.w," rootId: ",a," clusterId:",e)}catch(v){i.error(v)}})}i.debug("Removing node",o),t.removeNode(o)})},"copy"),R=w((e,t)=>{constn=t.children(e);leta=[...n];for(constrofn)J.set(r,e),a=[...a,...R(r,t)];returna},"extractDescendants"),ie=w((e,t,n)=>{consta=e.edges().filter(c=>c.v===t||c.w===t),r=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=r.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(i.trace("Searching children of id ",e,a),a.length<1)returne;letr;for(constoofa){constl=C(o,t,n),u=ie(t,n,l);if(l)if(u.length>0)r=l;elsereturnl}returnr},"findNonClusterChild"),k=w(e=>!d.has(e)||!d.get(e).externalConnections?e:d.has(e)?d.get(e).id:e,"getAnchorId"),re=w((e,t)=>{if(!e||t>10){i.debug("Opting out, no graph ");return}elsei.debug("Opting in, graph ");e.nodes().forEach(function(n){e.children(n).length>0&&(i.warn("Cluster identified",n," Replacement id in edges: ",C(n,e,n)),p.set(n,R(n,e)),d.set(n,{id:C(n,e,n),clusterData:e.node(n)}))}),e.nodes().forEach(function(n){consta=e.children(n),r=e.edges();a.length>0?(i.debug("Cluster identified",n,p),r.forEach(o=>{constl=D(o.v,n),u=D(o.w,n);l^u&&(i.warn("Edge: ",o," leaves cluster ",n),i.warn("Descendants of XXX ",n,": ",p.get(n)),d.get(n).externalConnections=!0)})):i.debug("Not a cluster ",n,p)});for(letnofd.keys()){consta=d.get(n).id,r=e.parent(a);r!==n&&d.has(r)&&!d.get(r).externalConnections&&(d.get(n).id=r)}e.edges().forEach(function(n){consta=e.edge(n);i.warn("Edge "+n.v+" -> "+n.w+": "+JSON.stringify(n)),i.warn("Edge "+n.v+" -> "+n.w+": "+JSON.stringify(e.edge(n)));letr=n.v,o=n.w;if(i.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(i.warn("Fixing and trying - removing XXX",n.v,n.w,n.name),r=k(n.v),o=k(n.w),e.removeEd