ranui
Version:
A framework-agnostic Web Components UI library built on native custom elements, with TypeScript types, light/dark theming, SSR and PWA support.
2 lines (1 loc) • 7.93 kB
JavaScript
const f=require("./chunk-Y2CYZVJY-DPaYLFFP.cjs"),s=require("./src-C9EhKhbk.cjs"),g=require("./graphlib-Du-578Js.cjs"),D=require("./map-BC2bk_rV.cjs");var P=4;function p(e){return D.baseClone(e,P)}function m(e){var r={options:{directed:e.isDirected(),multigraph:e.isMultigraph(),compound:e.isCompound()},nodes:k(e),edges:q(e)};return g.isUndefined(e.graph())||(r.value=p(e.graph())),r}function k(e){return D.map(e.nodes(),function(r){var n=e.node(r),o=e.parent(r),t={v:r};return g.isUndefined(n)||(t.value=n),g.isUndefined(o)||(t.parent=o),t})}function q(e){return D.map(e.edges(),function(r){var n=e.edge(r),o={v:r.v,w:r.w};return g.isUndefined(r.name)||(o.name=r.name),g.isUndefined(n)||(o.value=n),o})}var l=new Map,d=new Map,O=new Map,B=f.__name(()=>{d.clear(),O.clear(),l.clear()},"clear"),w=f.__name((e,r)=>{const n=d.get(r)||[];return s.log.trace("In isDescendant",r," ",e," = ",n.includes(e)),n.includes(e)},"isDescendant"),L=f.__name((e,r)=>{const n=d.get(r)||[];return s.log.info("Descendants of ",r," is ",n),s.log.info("Edge is ",e),e.v===r||e.w===r?!1:n?n.includes(e.v)||w(e.v,r)||w(e.w,r)||n.includes(e.w):(s.log.debug("Tilt, ",r,",not in descendants"),!1)},"edgeInCluster"),_=f.__name((e,r,n,o)=>{s.log.warn("Copying children of ",e,"root",o,"data",r.node(e),o);const t=r.children(e)||[];e!==o&&t.push(e),s.log.warn("Copying (nodes) clusterId",e,"nodes",t),t.forEach(i=>{if(r.children(i).length>0)_(i,r,n,o);else{const u=r.node(i);s.log.info("cp ",i," to ",o," with parent ",e),n.setNode(i,u),o!==r.parent(i)&&(s.log.warn("Setting parent",i,r.parent(i)),n.setParent(i,r.parent(i))),e!==o&&i!==e?(s.log.debug("Setting parent",i,e),n.setParent(i,e)):(s.log.info("In copy ",e,"root",o,"data",r.node(e),o),s.log.debug("Not Setting parent for node=",i,"cluster!==rootId",e!==o,"node!==clusterId",i!==e));const c=r.edges(i);s.log.debug("Copying Edges",c),c.forEach(a=>{s.log.info("Edge",a);const v=r.edge(a.v,a.w,a.name);s.log.info("Edge data",v,o);try{if(L(a,o)){const C=d.get(o)||[],E=C.includes(a.v)||w(a.v,o)||a.v===o,x=C.includes(a.w)||w(a.w,o)||a.w===o;if(E&&x)s.log.info("Copying as ",a.v,a.w,v,a.name),n.setEdge(a.v,a.w,v,a.name),s.log.info("newGraph edges ",n.edges(),n.edge(n.edges()[0]));else{const y=E?o:a.v,N=x?o:a.w;s.log.info("Rebinding cross-boundary edge as ",y,N,v,a.name),r.setEdge(y,N,v,a.name)}}else s.log.info("Skipping copy of edge ",a.v,"-->",a.w," rootId: ",o," clusterId:",e)}catch(C){s.log.error(C)}})}s.log.debug("Removing node",i),r.removeNode(i)})},"copy"),j=f.__name((e,r)=>{const n=r.children(e);let o=[...n];for(const t of n)O.set(t,e),o=[...o,...j(t,r)];return o},"extractDescendants"),F=f.__name((e,r,n)=>{const o=e.edges().filter(c=>c.v===r||c.w===r),t=e.edges().filter(c=>c.v===n||c.w===n),i=o.map(c=>({v:c.v===r?n:c.v,w:c.w===r?r:c.w})),u=t.map(c=>({v:c.v,w:c.w}));return i.filter(c=>u.some(a=>c.v===a.v&&c.w===a.w))},"findCommonEdges"),b=f.__name((e,r,n)=>{const o=r.children(e);if(s.log.trace("Searching children of id ",e,o),o.length<1)return e;let t;for(const i of o){const u=b(i,r,n),c=F(r,n,u);if(u)if(c.length>0)t=u;else return u}return t},"findNonClusterChild"),h=f.__name(e=>!l.has(e)||!l.get(e).externalConnections?e:l.has(e)?l.get(e).id:e,"getAnchorId"),M=f.__name((e,r)=>{if(!e||r>10){s.log.debug("Opting out, no graph ");return}else s.log.debug("Opting in, graph ");e.nodes().forEach(function(n){e.children(n).length>0&&(s.log.warn("Cluster identified",n," Replacement id in edges: ",b(n,e,n)),d.set(n,j(n,e)),l.set(n,{id:b(n,e,n),clusterData:e.node(n)}))}),e.nodes().forEach(function(n){const o=e.children(n),t=e.edges();o.length>0?(s.log.debug("Cluster identified",n,d),t.forEach(i=>{w(i.v,n)^w(i.w,n)&&(s.log.warn("Edge: ",i," leaves cluster ",n),s.log.warn("Descendants of XXX ",n,": ",d.get(n)),l.get(n).externalConnections=!0)})):s.log.debug("Not a cluster ",n,d)});for(let n of l.keys()){const o=l.get(n).id,t=e.parent(o);t!==n&&l.has(t)&&!l.get(t).externalConnections&&(l.get(n).id=t);const i=e.edges().some(u=>u.v===n);if(o&&l.get(n)?.externalConnections&&i&&A(e,o,n)){const u=U(e,n,e.parent(o));u&&(l.get(n).id=u)}}e.edges().forEach(function(n){const o=e.edge(n);s.log.warn("Edge "+n.v+" -> "+n.w+": "+JSON.stringify(n)),s.log.warn("Edge "+n.v+" -> "+n.w+": "+JSON.stringify(e.edge(n)));let t=n.v,i=n.w;if(s.log.warn("Fix XXX",l,"ids:",n.v,n.w,"Translating: ",l.get(n.v)," --- ",l.get(n.w)),l.get(n.v)||l.get(n.w)){if(s.log.warn("Fixing and trying - removing XXX",n.v,n.w,n.name),t=h(n.v),i=h(n.w),e.removeEdge(n.v,n.w,n.name),t!==n.v){const u=e.parent(t);l.get(u).externalConnections=!0,o.fromCluster=n.v}if(i!==n.w){const u=e.parent(i);l.get(u).externalConnections=!0,o.toCluster=n.w}s.log.warn("Fix Replacing with XXX",t,i,n.name),e.setEdge(t,i,o,n.name)}}),s.log.warn("Adjusted Graph",m(e)),S(e,0),s.log.trace(l)},"adjustClustersAndEdges"),S=f.__name((e,r)=>{if(s.log.warn("extractor - ",r,m(e),e.children("D")),r>10){s.log.error("Bailing out");return}let n=e.nodes(),o=!1;for(const t of n){const i=e.children(t);o=o||i.length>0}if(!o){s.log.debug("Done, no node has children",e.nodes());return}s.log.debug("Nodes = ",n,r);for(const t of n)if(s.log.debug("Extracting node",t,l,l.has(t)&&!l.get(t).externalConnections,!e.parent(t),e.node(t),e.children("D")," Depth ",r),!l.has(t))s.log.debug("Not a cluster",t,r);else if(l.get(t)?.clusterData?.explicitDir&&e.children(t)&&e.children(t).length>0){s.log.warn("Cluster with explicit dir, creating subgraph for children",t,r);const i=l.get(t).clusterData.dir,u=new g.Graph({multigraph:!0,compound:!0}).setGraph({rankdir:i,nodesep:50,ranksep:50,marginx:8,marginy:8}).setDefaultEdgeLabel(function(){return{}});_(t,e,u,t);const c=e.node(t)||{};e.setNode(t,{...c,clusterNode:!0,id:t,clusterData:l.get(t).clusterData,label:l.get(t).label,graph:u}),s.log.warn("Subgraph for cluster with explicit dir created:",t,m(u))}else if(!l.get(t).externalConnections&&e.children(t)&&e.children(t).length>0){s.log.warn("Cluster without external connections, without a parent and with children",t,r);let i=e.graph().rankdir==="TB"?"LR":"TB";l.get(t)?.clusterData?.dir&&(i=l.get(t).clusterData.dir,s.log.warn("Fixing dir",l.get(t).clusterData.dir,i));const u=new g.Graph({multigraph:!0,compound:!0}).setGraph({rankdir:i,nodesep:50,ranksep:50,marginx:8,marginy:8}).setDefaultEdgeLabel(function(){return{}});_(t,e,u,t);const c=e.node(t)||{};e.setNode(t,{...c,clusterNode:!0,id:t,clusterData:l.get(t).clusterData,label:l.get(t).label,graph:u}),s.log.debug("Old graph after copy",m(e))}else s.log.warn("Cluster ** ",t," **not meeting the criteria !externalConnections:",!l.get(t).externalConnections," no parent: ",!e.parent(t)," children ",e.children(t)&&e.children(t).length>0,e.children("D"),r),s.log.debug(l);n=e.nodes(),s.log.warn("New list of nodes",n);for(const t of n){const i=e.node(t);s.log.warn(" Now next level",t,i),i?.clusterNode&&S(i.graph,r+1)}},"extractor"),X=f.__name((e,r)=>{if(r.length===0)return[];let n=Object.assign([],r);return r.forEach(o=>{const t=X(e,e.children(o));n=[...n,...t]}),n},"sorter"),R=f.__name(e=>X(e,e.children()),"sortNodesByHierarchy"),A=f.__name((e,r,n)=>{let o=e.parent(r);for(;o&&o!==n;){const t=l.get(o);if(t&&!t.externalConnections)return!0;o=e.parent(o)}return!1},"isNodeInExtractableCluster"),U=f.__name((e,r,n)=>{const o=e.children(r)??[];for(const t of o){if(t===n||w(t,n))continue;const i=b(t,e,r);if(i&&!A(e,i,r))return i}return null},"findSafeAnchorNode");Object.defineProperty(exports,"adjustClustersAndEdges",{enumerable:!0,get:function(){return M}});Object.defineProperty(exports,"clear",{enumerable:!0,get:function(){return B}});Object.defineProperty(exports,"clusterDb",{enumerable:!0,get:function(){return l}});Object.defineProperty(exports,"findNonClusterChild",{enumerable:!0,get:function(){return b}});Object.defineProperty(exports,"sortNodesByHierarchy",{enumerable:!0,get:function(){return R}});Object.defineProperty(exports,"write",{enumerable:!0,get:function(){return m}});