import{_asX,aoasM,apasF,aqasY,aras_,lasi,dasj,asasH,atasq,auasz,SasK,avasO,awasQ,axasU,ayasV,azasW}from"./index-CZs-Lug_.js";import{Gask}from"./graph-DGn5vx2J.js";import{lasZ}from"./layout-Cf6Z8Bks.js";import{wasN}from"./json-CoNznUFQ.js";import"./_baseUniq-swD-eudx.js";import"./min-b4xMd0Jf.js";varf=newMap,p=newMap,B=newMap,$=X(()=>{p.clear(),B.clear(),f.clear()},"clear"),D=X((e,t)=>{constn=p.get(t)||[];returni.trace("In isDescendant",t," ",e," = ",n.includes(e)),n.includes(e)},"isDescendant"),I=X((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"),A=X((e,t,n,o)=>{i.warn("Copying children of ",e,"root",o,"data",t.node(e),o);constd=t.children(e)||[];e!==o&&d.push(e),i.warn("Copying (nodes) clusterId",e,"nodes",d),d.forEach(c=>{if(t.children(c).length>0)A(c,t,n,o);else{constr=t.node(c);i.info("cp ",c," to ",o," with parent ",e),n.setNode(c,r),o!==t.parent(c)&&(i.warn("Setting parent",c,t.parent(c)),n.setParent(c,t.parent(c))),e!==o&&c!==e?(i.debug("Setting parent",c,e),n.setParent(c,e)):(i.info("In copy ",e,"root",o,"data",t.node(e),o),i.debug("Not Setting parent for node=",c,"cluster!==rootId",e!==o,"node!==clusterId",c!==e));constu=t.edges(c);i.debug("Copying Edges",u),u.forEach(l=>{i.info("Edge",l);constv=t.edge(l.v,l.w,l.name);i.info("Edge data",v,o);try{I(l,o)?(i.info("Copying as ",l.v,l.w,v,l.name),n.setEdge(l.v,l.w,v,l.name),i.info("newGraph edges ",n.edges(),n.edge(n.edges()[0]))):i.info("Skipping copy of edge ",l.v,"-->",l.w," rootId: ",o," clusterId:",e)}catch(C){i.error(C)}})}i.debug("Removing node",c),t.removeNode(c)})},"copy"),J=X((e,t)=>{constn=t.children(e);leto=[...n];for(constdofn)B.set(d,e),o=[...o,...J(d,t)];returno},"extractDescendants"),L=X((e,t,n)=>{consto=e.edges().filter(l=>l.v===t||l.w===t),d=e.edges().filter(l=>l.v===n||l.w===n),c=o.map(l=>({v:l.v===t?n:l.v,w:l.w===t?t:l.w})),r=d.map(l=>({v:l.v,w:l.w}));returnc.filter(l=>r.some(v=>l.v===v.v&&l.w===v.w))},"findCommonEdges"),S=X((e,t,n)=>{consto=t.children(e);if(i.trace("Searching children of id ",e,o),o.length<1)returne;letd;for(constcofo){constr=S(c,t,n),u=L(t,n,r);if(r)if(u.length>0)d=r;elsereturnr}returnd},"findNonClusterChild"),P=X(e=>!f.has(e)||!f.get(e).externalConnections?e:f.has(e)?f.get(e).id:e,"getAnchorId"),ee=X((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: ",S(n,e,n)),p.set(n,J(n,e)),f.set(n,{id:S(n,e,n),clusterData:e.node(n)}))}),e.nodes().forEach(function(n){consto=e.children(n),d=e.edges();o.length>0?(i.debug("Cluster identified",n,p),d.forEach(c=>{constr=D(c.v,n),u=D(c.w,n);r^u&&(i.warn("Edge: ",c," leaves cluster ",n),i.warn("Descendants of XXX ",n,": ",p.get(n)),f.get(n).externalConnections=!0)})):i.debug("Not a cluster ",n,p)});for(letnoff.keys()){consto=f.get(n).id,d=e.parent(o);d!==n&&f.has(d)&&!f.get(d).externalConnections&&(f.get(n).id=d)}e.edges().forEach(function(n){consto=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)));letd=n.v,c=n.w;if(i.warn("Fix XXX",f,"ids:",n.v,n.w,"Translating: ",f.get(n.v)," --- ",f.get(n.w)),f.get(n.v)||f.get(n.w)){if(i.warn("Fixing and trying - removing XXX",n.v,n.w,n.name),d=P(n.v),c=P(n.w),e.removeEdge(n.v,n.w,n.name),d!==n.v){constr=e.parent(d);f.get(r).externalConnections=!0,o.fromCluster=n.v}if(c!==n.w){constr=e.parent(c);f.get(r).externalConnections=!0,o.toCluster=n.w}i.warn("Fix Replacing with XXX",d,c,n.name),e.setEdge(d,c,o,n.name)}}),i.warn("Adjusted Graph",N(e)),G(e,0),i.trace(f)},"adjustClustersAndEdges"),G=X((e,t)=>{vard,c;if(i.warn("extractor - ",t,N(e),e.children("D")),t>10){i.error("Bailing out");return}letn=e.nodes(),o=!1;for(constrofn){constu=e.children(r);o=o||u.length>0}if(!o){i.deb