import{_asX,arasF,asasY,atas_,auasH,lasi,dasV,avasz,awasU,afas$,akasq,agasP,aeasK,axasQ,ayasW,azasZ}from"./md-index-TGP-egEp.js";import{GasB}from"./md-graph-BqJ5nvx-.js";import{lasI}from"./md-layout-D5yfjIxP.js";import{iasS}from"./md-_baseUniq-Bm0iSxF4.js";import{casL}from"./md-clone-Bb0Qs8zN.js";import{masA}from"./md-_basePickBy-D2Yv_vSZ.js";functionp(e){vart={options:{directed:e.isDirected(),multigraph:e.isMultigraph(),compound:e.isCompound()},nodes:ee(e),edges:ne(e)};returnS(e.graph())||(t.value=L(e.graph())),t}functionee(e){returnA(e.nodes(),function(t){varn=e.node(t),o=e.parent(t),c={v:t};returnS(n)||(c.value=n),S(o)||(c.parent=o),c})}functionne(e){returnA(e.edges(),function(t){varn=e.edge(t),o={v:t.v,w:t.w};returnS(t.name)||(o.name=t.name),S(n)||(o.value=n),o})}varf=newMap,b=newMap,J=newMap,te=X(()=>{b.clear(),J.clear(),f.clear()},"clear"),O=X((e,t)=>{constn=b.get(t)||[];returni.trace("In isDescendant",t," ",e," = ",n.includes(e)),n.includes(e)},"isDescendant"),se=X((e,t)=>{constn=b.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)||O(e.v,t)||O(e.w,t)||n.includes(e.w):(i.debug("Tilt, ",t,",not in descendants"),!1)},"edgeInCluster"),G=X((e,t,n,o)=>{i.warn("Copying children of ",e,"root",o,"data",t.node(e),o);constc=t.children(e)||[];e!==o&&c.push(e),i.warn("Copying (nodes) clusterId",e,"nodes",c),c.forEach(a=>{if(t.children(a).length>0)G(a,t,n,o);else{constr=t.node(a);i.info("cp ",a," to ",o," with parent ",e),n.setNode(a,r),o!==t.parent(a)&&(i.warn("Setting parent",a,t.parent(a)),n.setParent(a,t.parent(a))),e!==o&&a!==e?(i.debug("Setting parent",a,e),n.setParent(a,e)):(i.info("In copy ",e,"root",o,"data",t.node(e),o),i.debug("Not Setting parent for node=",a,"cluster!==rootId",e!==o,"node!==clusterId",a!==e));constu=t.edges(a);i.debug("Copying Edges",u),u.forEach(l=>{i.info("Edge",l);consth=t.edge(l.v,l.w,l.name);i.info("Edge data",h,o);try{se(l,o)?(i.info("Copying as ",l.v,l.w,h,l.name),n.setEdge(l.v,l.w,h,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",a),t.removeNode(a)})},"copy"),R=X((e,t)=>{constn=t.children(e);leto=[...n];for(constcofn)J.set(c,e),o=[...o,...R(c,t)];returno},"extractDescendants"),ie=X((e,t,n)=>{consto=e.edges().filter(l=>l.v===t||l.w===t),c=e.edges().filter(l=>l.v===n||l.w===n),a=o.map(l=>({v:l.v===t?n:l.v,w:l.w===t?t:l.w})),r=c.map(l=>({v:l.v,w:l.w}));returna.filter(l=>r.some(h=>l.v===h.v&&l.w===h.w))},"findCommonEdges"),D=X((e,t,n)=>{consto=t.children(e);if(i.trace("Searching children of id ",e,o),o.length<1)returne;letc;for(constaofo){constr=D(a,t,n),u=ie(t,n,r);if(r)if(u.length>0)c=r;elsereturnr}returnc},"findNonClusterChild"),k=X(e=>!f.has(e)||!f.get(e).externalConnections?e:f.has(e)?f.get(e).id:e,"getAnchorId"),re=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: ",D(n,e,n)),b.set(n,R(n,e)),f.set(n,{id:D(n,e,n),clusterData:e.node(n)}))}),e.nodes().forEach(function(n){consto=e.children(n),c=e.edges();o.length>0?(i.debug("Cluster identified",n,b),c.forEach(a=>{constr=O(a.v,n),u=O(a.w,n);r^u&&(i.warn("Edge: ",a," leaves cluster ",n),i.warn("Descendants of XXX ",n,": ",b.get(n)),f.get(n).externalConnections=!0)})):i.debug("Not a cluster ",n,b)});for(letnoff.keys()){consto=f.get(n).id,c=e.parent(o);c!==n&&f.has(c)&&!f.get(c).externalConnections&&(f.get(n).id=c)}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)));letc=n.v,a=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),c=k(n.v),a=k(n.w),e.removeEdge(n.v,n.w,n.name