@dagrejs/dagre
Version:
Graph layout for JavaScript
4 lines (3 loc) • 28.7 kB
JavaScript
;var Ze=Object.create;var M=Object.defineProperty;var $e=Object.getOwnPropertyDescriptor;var en=Object.getOwnPropertyNames;var nn=Object.getPrototypeOf,tn=Object.prototype.hasOwnProperty;var rn=(e,n,t)=>n in e?M(e,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[n]=t;var on=(e,n)=>{for(var t in n)M(e,t,{get:n[t],enumerable:!0})},ue=(e,n,t,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let o of en(n))!tn.call(e,o)&&o!==t&&M(e,o,{get:()=>n[o],enumerable:!(r=$e(n,o))||r.enumerable});return e};var an=(e,n,t)=>(t=e!=null?Ze(nn(e)):{},ue(n||!e||!e.__esModule?M(t,"default",{value:e,enumerable:!0}):t,e)),sn=e=>ue(M({},"__esModule",{value:!0}),e);var ce=(e,n,t)=>rn(e,typeof n!="symbol"?n+"":n,t);var It={};on(It,{Graph:()=>Qe.Graph,debug:()=>D,default:()=>St,graphlib:()=>Je,layout:()=>B,util:()=>Pt,version:()=>F});module.exports=sn(It);var Je=an(require("@dagrejs/graphlib"));var p=require("@dagrejs/graphlib");function N(e,n,t,r){let o=r;for(;e.hasNode(o);)o=C(r);return t.dummy=n,e.setNode(o,t),o}function be(e){let n=new p.Graph().setGraph(e.graph());return e.nodes().forEach(t=>n.setNode(t,e.node(t))),e.edges().forEach(t=>{let r=n.edge(t.v,t.w)||{weight:0,minlen:1},o=e.edge(t);n.setEdge(t.v,t.w,{weight:r.weight+o.weight,minlen:Math.max(r.minlen,o.minlen)})}),n}function _(e){let n=new p.Graph({multigraph:e.isMultigraph()}).setGraph(e.graph());return e.nodes().forEach(t=>{e.children(t).length||n.setNode(t,e.node(t))}),e.edges().forEach(t=>{n.setEdge(t,e.edge(t))}),n}function Y(e,n){let t=e.x,r=e.y,o=n.x-t,i=n.y-r,a=e.width/2,s=e.height/2;if(!o&&!i)throw new Error("Not possible to find intersection inside of the rectangle");let d,l;return Math.abs(i)*a>Math.abs(o)*s?(i<0&&(s=-s),d=s*o/i,l=s):(o<0&&(a=-a),d=a,l=a*i/o),{x:t+d,y:r+l}}function G(e){let n=k(q(e)+1).map(()=>[]);return e.nodes().forEach(t=>{let r=e.node(t),o=r.rank;o!==void 0&&(n[o]||(n[o]=[]),n[o][r.order]=t)}),n}function fe(e){let n=e.nodes().map(r=>{let o=e.node(r).rank;return o===void 0?Number.MAX_VALUE:o}),t=E(Math.min,n);e.nodes().forEach(r=>{let o=e.node(r);Object.hasOwn(o,"rank")&&(o.rank-=t)})}function he(e){let n=e.nodes().map(a=>e.node(a).rank).filter(a=>a!==void 0),t=E(Math.min,n),r=[];e.nodes().forEach(a=>{let s=e.node(a).rank-t;r[s]||(r[s]=[]),r[s].push(a)});let o=0,i=e.graph().nodeRankFactor;Array.from(r).forEach((a,s)=>{a===void 0&&s%i!==0?--o:a!==void 0&&o&&a.forEach(d=>e.node(d).rank+=o)})}function H(e,n,t,r){let o={width:0,height:0};return arguments.length>=4&&(o.rank=t,o.order=r),N(e,"border",o,n)}function dn(e,n=ge){let t=[];for(let r=0;r<e.length;r+=n){let o=e.slice(r,r+n);t.push(o)}return t}var ge=65535;function E(e,n){if(n.length>ge){let t=dn(n);return e(...t.map(r=>e(...r)))}else return e(...n)}function q(e){let t=e.nodes().map(r=>{let o=e.node(r).rank;return o===void 0?Number.MIN_VALUE:o});return E(Math.max,t)}function pe(e,n){let t={lhs:[],rhs:[]};return e.forEach(r=>{n(r)?t.lhs.push(r):t.rhs.push(r)}),t}function S(e,n){let t=Date.now();try{return n()}finally{console.log(e+" time: "+(Date.now()-t)+"ms")}}function I(e,n){return n()}var ln=0;function C(e){let n=++ln;return e+(""+n)}function k(e,n,t=1){n==null&&(n=e,e=0);let r=i=>i<n;t<0&&(r=i=>n<i);let o=[];for(let i=e;r(i);i+=t)o.push(i);return o}function O(e,n){let t={};for(let r of n)e[r]!==void 0&&(t[r]=e[r]);return t}function R(e,n){let t;return typeof n=="string"?t=r=>r[n]:t=n,Object.entries(e).reduce((r,[o,i])=>(r[o]=t(i,o),r),{})}function me(e,n){return e.reduce((t,r,o)=>(t[r]=n[o],t),{})}var v="\0";var F="3.0.0";var z=class{constructor(){ce(this,"_sentinel");let n={};n._next=n._prev=n,this._sentinel=n}dequeue(){let n=this._sentinel,t=n._prev;if(t!==n)return Le(t),t}enqueue(n){let t=this._sentinel;n._prev&&n._next&&Le(n),n._next=t._next,t._next._prev=n,t._next=n,n._prev=t}toString(){let n=[],t=this._sentinel,r=t._prev;for(;r!==t;)n.push(JSON.stringify(r,un)),r=r._prev;return"["+n.join(", ")+"]"}};function Le(e){e._prev._next=e._next,e._next._prev=e._prev,delete e._next,delete e._prev}function un(e,n){if(e!=="_next"&&e!=="_prev")return n}var Ee=z;var cn=()=>1;function K(e,n){if(e.nodeCount()<=1)return[];let t=fn(e,n||cn);return bn(t.graph,t.buckets,t.zeroIdx).flatMap(o=>e.outEdges(o.v,o.w)||[])}function bn(e,n,t){var s;let r=[],o=n[n.length-1],i=n[0],a;for(;e.nodeCount();){for(;a=i.dequeue();)X(e,n,t,a);for(;a=o.dequeue();)X(e,n,t,a);if(e.nodeCount()){for(let d=n.length-2;d>0;--d)if(a=(s=n[d])==null?void 0:s.dequeue(),a){r=r.concat(X(e,n,t,a,!0)||[]);break}}}return r}function X(e,n,t,r,o){let i=[],a=o?i:void 0;return(e.inEdges(r.v)||[]).forEach(s=>{let d=e.edge(s),l=e.node(s.v);o&&i.push({v:s.v,w:s.w}),l.out-=d,U(n,t,l)}),(e.outEdges(r.v)||[]).forEach(s=>{let d=e.edge(s),l=s.w,u=e.node(l);u.in-=d,U(n,t,u)}),e.removeNode(r.v),a}function fn(e,n){let t=new p.Graph,r=0,o=0;e.nodes().forEach(s=>{t.setNode(s,{v:s,in:0,out:0})}),e.edges().forEach(s=>{let d=t.edge(s.v,s.w)||0,l=n(s),u=d+l;t.setEdge(s.v,s.w,u);let c=t.node(s.v),f=t.node(s.w);o=Math.max(o,c.out+=l),r=Math.max(r,f.in+=l)});let i=hn(o+r+3).map(()=>new Ee),a=r+1;return t.nodes().forEach(s=>{U(i,a,t.node(s))}),{graph:t,buckets:i,zeroIdx:a}}function U(e,n,t){var r,o,i;t.out?t.in?(i=e[t.out-t.in+n])==null||i.enqueue(t):(o=e[e.length-1])==null||o.enqueue(t):(r=e[0])==null||r.enqueue(t)}function hn(e){let n=[];for(let t=0;t<e;t++)n.push(t);return n}function ye(e){(e.graph().acyclicer==="greedy"?K(e,t(e)):gn(e)).forEach(r=>{let o=e.edge(r);e.removeEdge(r),o.forwardName=r.name,o.reversed=!0,e.setEdge(r.w,r.v,o,C("rev"))});function t(r){return o=>r.edge(o).weight}}function gn(e){let n=[],t={},r={};function o(i){Object.hasOwn(r,i)||(r[i]=!0,t[i]=!0,e.outEdges(i).forEach(a=>{Object.hasOwn(t,a.w)?n.push(a):o(a.w)}),delete t[i])}return e.nodes().forEach(o),n}function Ne(e){e.edges().forEach(n=>{let t=e.edge(n);if(t.reversed){e.removeEdge(n);let r=t.forwardName;delete t.reversed,delete t.forwardName,e.setEdge(n.w,n.v,t,r)}})}function Ge(e){e.graph().dummyChains=[],e.edges().forEach(n=>mn(e,n))}function mn(e,n){let t=n.v,r=e.node(t).rank,o=n.w,i=e.node(o).rank,a=n.name,s=e.edge(n),d=s.labelRank;if(i===r+1)return;e.removeEdge(n);let l,u,c;for(c=0,++r;r<i;++c,++r)s.points=[],u={width:0,height:0,edgeLabel:s,edgeObj:n,rank:r},l=N(e,"edge",u,"_d"),r===d&&(u.width=s.width,u.height=s.height,u.dummy="edge-label",u.labelpos=s.labelpos),e.setEdge(t,l,{weight:s.weight},a),c===0&&e.graph().dummyChains.push(l),t=l;e.setEdge(t,o,{weight:s.weight},a)}function we(e){e.graph().dummyChains.forEach(n=>{let t=e.node(n),r=t.edgeLabel,o;for(e.setEdge(t.edgeObj,r);t.dummy;)o=e.successors(n)[0],e.removeNode(n),r.points.push({x:t.x,y:t.y}),t.dummy==="edge-label"&&(r.x=t.x,r.y=t.y,r.width=t.width,r.height=t.height),n=o,t=e.node(n)})}function j(e){let n={};function t(r){let o=e.node(r);if(Object.hasOwn(n,r))return o.rank;n[r]=!0;let i=e.outEdges(r),a=i?i.map(d=>d==null?Number.POSITIVE_INFINITY:t(d.w)-e.edge(d).minlen):[],s=E(Math.min,a);return s===Number.POSITIVE_INFINITY&&(s=0),o.rank=s}e.sources().forEach(t)}function x(e,n){return e.node(n.w).rank-e.node(n.v).rank-e.edge(n).minlen}var A=En;function En(e){let n=new p.Graph({directed:!1}),t=e.nodes();if(t.length===0)throw new Error("Graph must have at least one node");let r=t[0],o=e.nodeCount();n.setNode(r,{});let i,a;for(;yn(n,e)<o&&(i=Nn(n,e),!!i);)a=n.hasNode(i.v)?x(e,i):-x(e,i),Gn(n,e,a);return n}function yn(e,n){function t(r){let o=n.nodeEdges(r);o&&o.forEach(i=>{let a=i.v,s=r===a?i.w:a;!e.hasNode(s)&&!x(n,i)&&(e.setNode(s,{}),e.setEdge(r,s,{}),t(s))})}return e.nodes().forEach(t),e.nodeCount()}function Nn(e,n){return n.edges().reduce((r,o)=>{let i=Number.POSITIVE_INFINITY;return e.hasNode(o.v)!==e.hasNode(o.w)&&(i=x(n,o)),i<r[0]?[i,o]:r},[Number.POSITIVE_INFINITY,null])[1]}function Gn(e,n,t){e.nodes().forEach(r=>n.node(r).rank+=t)}var{preorder:wn,postorder:kn}=p.alg,xe=T;T.initLowLimValues=Q;T.initCutValues=J;T.calcCutValue=ve;T.leaveEdge=Oe;T.enterEdge=Re;T.exchangeEdges=Pe;function T(e){e=be(e),j(e);let n=A(e);Q(n),J(n,e);let t,r;for(;t=Oe(n);)r=Re(n,e,t),Pe(n,e,t,r)}function J(e,n){let t=kn(e,e.nodes());t=t.slice(0,t.length-1),t.forEach(r=>xn(e,n,r))}function xn(e,n,t){let o=e.node(t).parent,i=e.edge(t,o);i.cutvalue=ve(e,n,t)}function ve(e,n,t){let o=e.node(t).parent,i=!0,a=n.edge(t,o),s=0;a||(i=!1,a=n.edge(o,t)),s=a.weight;let d=n.nodeEdges(t);return d&&d.forEach(l=>{let u=l.v===t,c=u?l.w:l.v;if(c!==o){let f=u===i,b=n.edge(l).weight;if(s+=f?b:-b,Tn(e,t,c)){let h=e.edge(t,c).cutvalue;s+=f?-h:h}}}),s}function Q(e,n){arguments.length<2&&(n=e.nodes()[0]),Te(e,{},1,n)}function Te(e,n,t,r,o){let i=t,a=e.node(r);n[r]=!0;let s=e.neighbors(r);return s&&s.forEach(d=>{Object.hasOwn(n,d)||(t=Te(e,n,t,d,r))}),a.low=i,a.lim=t++,o?a.parent=o:delete a.parent,t}function Oe(e){return e.edges().find(n=>e.edge(n).cutvalue<0)}function Re(e,n,t){let r=t.v,o=t.w;n.hasEdge(r,o)||(r=t.w,o=t.v);let i=e.node(r),a=e.node(o),s=i,d=!1;return i.lim>a.lim&&(s=a,d=!0),n.edges().filter(u=>d===ke(e,e.node(u.v),s)&&d!==ke(e,e.node(u.w),s)).reduce((u,c)=>x(n,c)<x(n,u)?c:u)}function Pe(e,n,t,r){let o=t.v,i=t.w;e.removeEdge(o,i),e.setEdge(r.v,r.w,{}),Q(e),J(e,n),vn(e,n)}function vn(e,n){let t=e.nodes().find(o=>!e.node(o).parent);if(!t)return;let r=wn(e,[t]);r=r.slice(1),r.forEach(o=>{let a=e.node(o).parent,s=n.edge(o,a),d=!1;s||(s=n.edge(a,o),d=!0),n.node(o).rank=n.node(a).rank+(d?s.minlen:-s.minlen)})}function Tn(e,n,t){return e.hasEdge(n,t)}function ke(e,n,t){return t.low<=n.lim&&n.lim<=t.lim}var Se=On;function On(e){let n=e.graph().ranker;if(typeof n=="function")return n(e);switch(n){case"network-simplex":Me(e);break;case"tight-tree":Pn(e);break;case"longest-path":Rn(e);break;case"none":break;default:Me(e)}}var Rn=j;function Pn(e){j(e),A(e)}function Me(e){xe(e)}var Ie=Mn;function Mn(e){let n=In(e);e.graph().dummyChains.forEach(t=>{let r=e.node(t),o=r.edgeObj,i=Sn(e,n,o.v,o.w),a=i.path,s=i.lca,d=0,l=a[d],u=!0;for(;t!==o.w;){if(r=e.node(t),u){for(;(l=a[d])!==s&&e.node(l).maxRank<r.rank;)d++;l===s&&(u=!1)}if(!u){for(;d<a.length-1&&e.node(a[d+1]).minRank<=r.rank;)d++;l=a[d]}l!==void 0&&e.setParent(t,l),t=e.successors(t)[0]}})}function Sn(e,n,t,r){let o=[],i=[],a=Math.min(n[t].low,n[r].low),s=Math.max(n[t].lim,n[r].lim),d;d=t;do d=e.parent(d),o.push(d);while(d&&(n[d].low>a||s>n[d].lim));let l=d,u=r;for(;(u=e.parent(u))!==l;)i.push(u);return{path:o.concat(i.reverse()),lca:l}}function In(e){let n={},t=0;function r(o){let i=t;e.children(o).forEach(r),n[o]={low:i,lim:t++}}return e.children(v).forEach(r),n}function Ce(e){let n=N(e,"root",{},"_root"),t=Cn(e),r=Object.values(t),o=E(Math.max,r)-1,i=2*o+1;e.graph().nestingRoot=n,e.edges().forEach(s=>e.edge(s).minlen*=i);let a=jn(e)+1;e.children(v).forEach(s=>je(e,n,i,a,o,t,s)),e.graph().nodeRankFactor=i}function je(e,n,t,r,o,i,a){var c;let s=e.children(a);if(!s.length){a!==n&&e.setEdge(n,a,{weight:0,minlen:t});return}let d=H(e,"_bt"),l=H(e,"_bb"),u=e.node(a);e.setParent(d,a),u.borderTop=d,e.setParent(l,a),u.borderBottom=l,s.forEach(f=>{var y;je(e,n,t,r,o,i,f);let b=e.node(f),g=b.borderTop?b.borderTop:f,h=b.borderBottom?b.borderBottom:f,m=b.borderTop?r:2*r,L=g!==h?1:o-((y=i[a])!=null?y:0)+1;e.setEdge(d,g,{weight:m,minlen:L,nestingEdge:!0}),e.setEdge(h,l,{weight:m,minlen:L,nestingEdge:!0})}),e.parent(a)||e.setEdge(n,d,{weight:0,minlen:o+((c=i[a])!=null?c:0)})}function Cn(e){let n={};function t(r,o){let i=e.children(r);i&&i.length&&i.forEach(a=>t(a,o+1)),n[r]=o}return e.children(v).forEach(r=>t(r,1)),n}function jn(e){return e.edges().reduce((n,t)=>n+e.edge(t).weight,0)}function _e(e){let n=e.graph();e.removeNode(n.nestingRoot),delete n.nestingRoot,e.edges().forEach(t=>{e.edge(t).nestingEdge&&e.removeEdge(t)})}var Ae=Fn;function Fn(e){function n(t){let r=e.children(t),o=e.node(t);if(r.length&&r.forEach(n),Object.hasOwn(o,"minRank")){o.borderLeft=[],o.borderRight=[];for(let i=o.minRank,a=o.maxRank+1;i<a;++i)Fe(e,"borderLeft","_bl",t,o,i),Fe(e,"borderRight","_br",t,o,i)}}e.children(v).forEach(n)}function Fe(e,n,t,r,o,i){let a={width:0,height:0,rank:i,borderType:n},s=o[n][i-1],d=N(e,"border",a,t);o[n][i]=d,e.setParent(d,r),s&&e.setEdge(s,d,{weight:1})}function We(e){var t;let n=(t=e.graph().rankdir)==null?void 0:t.toLowerCase();(n==="lr"||n==="rl")&&De(e)}function Be(e){var t;let n=(t=e.graph().rankdir)==null?void 0:t.toLowerCase();(n==="bt"||n==="rl")&&An(e),(n==="lr"||n==="rl")&&(Vn(e),De(e))}function De(e){e.nodes().forEach(n=>Ve(e.node(n))),e.edges().forEach(n=>Ve(e.edge(n)))}function Ve(e){let n=e.width;e.width=e.height,e.height=n}function An(e){e.nodes().forEach(n=>Z(e.node(n))),e.edges().forEach(n=>{var r;let t=e.edge(n);(r=t.points)==null||r.forEach(Z),Object.hasOwn(t,"y")&&Z(t)})}function Z(e){e.y=-e.y}function Vn(e){e.nodes().forEach(n=>$(e.node(n))),e.edges().forEach(n=>{var r;let t=e.edge(n);(r=t.points)==null||r.forEach($),Object.hasOwn(t,"x")&&$(t)})}function $(e){let n=e.x;e.x=e.y,e.y=n}function ee(e){let n={},t=e.nodes().filter(d=>!e.children(d).length),r=t.map(d=>e.node(d).rank),o=E(Math.max,r),i=k(o+1).map(()=>[]);function a(d){if(n[d])return;n[d]=!0;let l=e.node(d);i[l.rank].push(d);let u=e.successors(d);u&&u.forEach(a)}return t.sort((d,l)=>e.node(d).rank-e.node(l).rank).forEach(a),i}function ne(e,n){let t=0;for(let r=1;r<n.length;++r)t+=Bn(e,n[r-1],n[r]);return t}function Bn(e,n,t){let r=me(t,t.map((l,u)=>u)),o=n.flatMap(l=>{let u=e.outEdges(l);return u?u.map(c=>({pos:r[c.w],weight:e.edge(c).weight})).sort((c,f)=>c.pos-f.pos):[]}),i=1;for(;i<t.length;)i<<=1;let a=2*i-1;i-=1;let s=new Array(a).fill(0),d=0;return o.forEach(l=>{let u=l.pos+i;s[u]+=l.weight;let c=0;for(;u>0;)u%2&&(c+=s[u+1]),u=u-1>>1,s[u]+=l.weight;d+=l.weight*c}),d}function te(e,n=[]){return n.map(t=>{let r=e.inEdges(t);if(!r||!r.length)return{v:t};{let o=r.reduce((i,a)=>{let s=e.edge(a),d=e.node(a.v);return{sum:i.sum+s.weight*d.order,weight:i.weight+s.weight}},{sum:0,weight:0});return{v:t,barycenter:o.sum/o.weight,weight:o.weight}}})}function re(e,n){let t={};e.forEach((o,i)=>{let a={indegree:0,in:[],out:[],vs:[o.v],i};o.barycenter!==void 0&&(a.barycenter=o.barycenter,a.weight=o.weight),t[o.v]=a}),n.edges().forEach(o=>{let i=t[o.v],a=t[o.w];i!==void 0&&a!==void 0&&(a.indegree++,i.out.push(a))});let r=Object.values(t).filter(o=>!o.indegree);return Dn(r)}function Dn(e){let n=[];function t(o){return i=>{i.merged||(i.barycenter===void 0||o.barycenter===void 0||i.barycenter>=o.barycenter)&&Yn(o,i)}}function r(o){return i=>{i.in.push(o),--i.indegree===0&&e.push(i)}}for(;e.length;){let o=e.pop();n.push(o),o.in.reverse().forEach(t(o)),o.out.forEach(r(o))}return n.filter(o=>!o.merged).map(o=>O(o,["vs","i","barycenter","weight"]))}function Yn(e,n){let t=0,r=0;e.weight&&(t+=e.barycenter*e.weight,r+=e.weight),n.weight&&(t+=n.barycenter*n.weight,r+=n.weight),e.vs=n.vs.concat(e.vs),e.barycenter=t/r,e.weight=r,e.i=Math.min(n.i,e.i),n.merged=!0}function oe(e,n){let t=pe(e,u=>Object.hasOwn(u,"barycenter")),r=t.lhs,o=t.rhs.sort((u,c)=>c.i-u.i),i=[],a=0,s=0,d=0;r.sort(Hn(!!n)),d=Ye(i,o,d),r.forEach(u=>{d+=u.vs.length,i.push(u.vs),a+=u.barycenter*u.weight,s+=u.weight,d=Ye(i,o,d)});let l={vs:i.flat(1)};return s&&(l.barycenter=a/s,l.weight=s),l}function Ye(e,n,t){let r;for(;n.length&&(r=n[n.length-1]).i<=t;)n.pop(),e.push(r.vs),t++;return t}function Hn(e){return(n,t)=>n.barycenter<t.barycenter?-1:n.barycenter>t.barycenter?1:e?t.i-n.i:n.i-t.i}function V(e,n,t,r){let o=e.children(n),i=e.node(n),a=i?i.borderLeft:void 0,s=i?i.borderRight:void 0,d={};a&&(o=o.filter(f=>f!==a&&f!==s));let l=te(e,o);l.forEach(f=>{if(e.children(f.v).length){let b=V(e,f.v,t,r);d[f.v]=b,Object.hasOwn(b,"barycenter")&&zn(f,b)}});let u=re(l,t);qn(u,d);let c=oe(u,r);if(a&&s){c.vs=[a,c.vs,s].flat(1);let f=e.predecessors(a);if(f&&f.length){let b=e.node(f[0]),g=e.predecessors(s),h=e.node(g[0]);Object.hasOwn(c,"barycenter")||(c.barycenter=0,c.weight=0),c.barycenter=(c.barycenter*c.weight+b.order+h.order)/(c.weight+2),c.weight+=2}}return c}function qn(e,n){e.forEach(t=>{t.vs=t.vs.flatMap(r=>n[r]?n[r].vs:r)})}function zn(e,n){e.barycenter!==void 0?(e.barycenter=(e.barycenter*e.weight+n.barycenter*n.weight)/(e.weight+n.weight),e.weight+=n.weight):(e.barycenter=n.barycenter,e.weight=n.weight)}function ie(e,n,t,r){r||(r=e.nodes());let o=Xn(e),i=new p.Graph({compound:!0}).setGraph({root:o}).setDefaultNodeLabel(a=>e.node(a));return r.forEach(a=>{let s=e.node(a),d=e.parent(a);if(s.rank===n||s.minRank<=n&&n<=s.maxRank){i.setNode(a),i.setParent(a,d||o);let l=e[t](a);l&&l.forEach(u=>{let c=u.v===a?u.w:u.v,f=i.edge(c,a),b=f!==void 0?f.weight:0;i.setEdge(c,a,{weight:e.edge(u).weight+b})}),Object.hasOwn(s,"minRank")&&i.setNode(a,{borderLeft:s.borderLeft[n],borderRight:s.borderRight[n]})}}),i}function Xn(e){let n;for(;e.hasNode(n=C("_root")););return n}function ae(e,n,t){let r={},o;t.forEach(i=>{let a=e.parent(i),s,d;for(;a;){if(s=e.parent(a),s?(d=r[s],r[s]=a):(d=o,o=a),d&&d!==a){n.setEdge(d,a);return}a=s}})}function W(e,n={}){if(typeof n.customOrder=="function"){n.customOrder(e,W);return}let t=q(e),r=He(e,k(1,t+1),"inEdges"),o=He(e,k(t-1,-1,-1),"outEdges"),i=ee(e);if(qe(e,i),n.disableOptimalOrderHeuristic)return;let a=Number.POSITIVE_INFINITY,s,d=n.constraints||[];for(let l=0,u=0;u<4;++l,++u){Un(l%2?r:o,l%4>=2,d),i=G(e);let c=ne(e,i);c<a?(u=0,s=Object.assign({},i),a=c):c===a&&(s=structuredClone(i))}qe(e,s)}function He(e,n,t){let r=new Map,o=(i,a)=>{r.has(i)||r.set(i,[]),r.get(i).push(a)};for(let i of e.nodes()){let a=e.node(i);if(typeof a.rank=="number"&&o(a.rank,i),typeof a.minRank=="number"&&typeof a.maxRank=="number")for(let s=a.minRank;s<=a.maxRank;s++)s!==a.rank&&o(s,i)}return n.map(function(i){return ie(e,i,t,r.get(i)||[])})}function Un(e,n,t){let r=new p.Graph;e.forEach(function(o){t.forEach(s=>r.setEdge(s.left,s.right));let i=o.graph().root,a=V(o,i,r,n);a.vs.forEach((s,d)=>o.node(s).order=d),ae(o,r,a.vs)})}function qe(e,n){Object.values(n).forEach(t=>t.forEach((r,o)=>e.node(r).order=o))}function Kn(e,n){let t={};function r(o,i){let a=0,s=0,d=o.length,l=i[i.length-1];return i.forEach((u,c)=>{let f=Qn(e,u),b=f?e.node(f).order:d;(f||u===l)&&(i.slice(s,c+1).forEach(g=>{let h=e.predecessors(g);h&&h.forEach(m=>{let L=e.node(m),y=L.order;(y<a||b<y)&&!(L.dummy&&e.node(g).dummy)&&ze(t,m,g)})}),s=c+1,a=b)}),i}return n.length&&n.reduce(r),t}function Jn(e,n){let t={};function r(i,a,s,d,l){k(a,s).forEach(u=>{let c=i[u];if(c!==void 0&&e.node(c).dummy){let f=e.predecessors(c);f&&f.forEach(b=>{if(b===void 0)return;let g=e.node(b);g.dummy&&(g.order<d||g.order>l)&&ze(t,b,c)})}})}function o(i,a){let s=-1,d=-1,l=0;return a.forEach((u,c)=>{if(e.node(u).dummy==="border"){let f=e.predecessors(u);if(f&&f.length){let b=f[0];if(b===void 0)return;d=e.node(b).order,r(a,l,c,s,d),l=c,s=d}}r(a,l,a.length,d,i.length)}),a}return n.length&&n.reduce(o),t}function Qn(e,n){if(e.node(n).dummy){let t=e.predecessors(n);if(t)return t.find(r=>e.node(r).dummy)}}function ze(e,n,t){if(n>t){let o=n;n=t,t=o}let r=e[n];r||(e[n]=r={}),r[t]=!0}function Zn(e,n,t){if(n>t){let o=n;n=t,t=o}let r=e[n];return r!==void 0&&Object.hasOwn(r,t)}function $n(e,n,t,r){let o={},i={},a={};return n.forEach(s=>{s.forEach((d,l)=>{o[d]=d,i[d]=d,a[d]=l})}),n.forEach(s=>{let d=-1;s.forEach(l=>{let u=r(l);if(u&&u.length){let c=u.sort((b,g)=>{let h=a[b],m=a[g];return(h!==void 0?h:0)-(m!==void 0?m:0)}),f=(c.length-1)/2;for(let b=Math.floor(f),g=Math.ceil(f);b<=g;++b){let h=c[b];if(h===void 0)continue;let m=a[h];if(m!==void 0&&i[l]===l&&d<m&&!Zn(t,l,h)){let L=o[h];L!==void 0&&(i[h]=l,i[l]=o[l]=L,d=m)}}}})}),{root:o,align:i}}function et(e,n,t,r,o=!1){let i={},a=nt(e,n,t,o),s=o?"borderLeft":"borderRight";function d(b,g){let h=a.nodes().slice(),m={},L=h.pop();for(;L;){if(m[L])b(L);else{m[L]=!0,h.push(L);for(let y of g(L))h.push(y)}L=h.pop()}}function l(b){let g=a.inEdges(b);g?i[b]=g.reduce((h,m)=>{var P;let L=(P=i[m.v])!=null?P:0,y=a.edge(m);return Math.max(h,L+(y!==void 0?y:0))},0):i[b]=0}function u(b){let g=a.outEdges(b),h=Number.POSITIVE_INFINITY;g&&(h=g.reduce((L,y)=>{let P=i[y.w],le=a.edge(y);return Math.min(L,(P!==void 0?P:0)-(le!==void 0?le:0))},Number.POSITIVE_INFINITY));let m=e.node(b);h!==Number.POSITIVE_INFINITY&&m.borderType!==s&&(i[b]=Math.max(i[b]!==void 0?i[b]:0,h))}function c(b){return a.predecessors(b)||[]}function f(b){return a.successors(b)||[]}return d(l,c),d(u,f),Object.keys(r).forEach(b=>{var h;let g=t[b];g!==void 0&&(i[b]=(h=i[g])!=null?h:0)}),i}function nt(e,n,t,r){let o=new p.Graph,i=e.graph(),a=it(i.nodesep,i.edgesep,r);return n.forEach(s=>{let d;s.forEach(l=>{let u=t[l];if(u!==void 0){if(o.setNode(u),d!==void 0){let c=t[d];if(c!==void 0){let f=o.edge(c,u);o.setEdge(c,u,Math.max(a(e,l,d),f||0))}}d=l}})}),o}function tt(e,n){return Object.values(n).reduce((t,r)=>{let o=Number.NEGATIVE_INFINITY,i=Number.POSITIVE_INFINITY;Object.entries(r).forEach(([s,d])=>{let l=at(e,s)/2;o=Math.max(d+l,o),i=Math.min(d-l,i)});let a=o-i;return a<t[0]&&(t=[a,r]),t},[Number.POSITIVE_INFINITY,null])[1]}function rt(e,n){let t=Object.values(n),r=E(Math.min,t),o=E(Math.max,t);["u","d"].forEach(i=>{["l","r"].forEach(a=>{let s=i+a,d=e[s];if(!d||d===n)return;let l=Object.values(d),u=r-E(Math.min,l);a!=="l"&&(u=o-E(Math.max,l)),u&&(e[s]=R(d,c=>c+u))})})}function ot(e,n=void 0){let t=e.ul;return t?R(t,(r,o)=>{var a,s;if(n){let d=n.toLowerCase(),l=e[d];if(l&&l[o]!==void 0)return l[o]}let i=Object.values(e).map(d=>{let l=d[o];return l!==void 0?l:0}).sort((d,l)=>d-l);return(((a=i[1])!=null?a:0)+((s=i[2])!=null?s:0))/2}):{}}function Xe(e){let n=G(e),t=Object.assign(Kn(e,n),Jn(e,n)),r={},o;["u","d"].forEach(a=>{o=a==="u"?n:Object.values(n).reverse(),["l","r"].forEach(s=>{s==="r"&&(o=o.map(c=>Object.values(c).reverse()));let l=$n(e,o,t,c=>(a==="u"?e.predecessors(c):e.successors(c))||[]),u=et(e,o,l.root,l.align,s==="r");s==="r"&&(u=R(u,c=>-c)),r[a+s]=u})});let i=tt(e,r);return rt(r,i),ot(r,e.graph().align)}function it(e,n,t){return(r,o,i)=>{let a=r.node(o),s=r.node(i),d=0,l;if(d+=a.width/2,Object.hasOwn(a,"labelpos"))switch(a.labelpos.toLowerCase()){case"l":l=-a.width/2;break;case"r":l=a.width/2;break}if(l&&(d+=t?l:-l),l=void 0,d+=(a.dummy?n:e)/2,d+=(s.dummy?n:e)/2,d+=s.width/2,Object.hasOwn(s,"labelpos"))switch(s.labelpos.toLowerCase()){case"l":l=s.width/2;break;case"r":l=-s.width/2;break}return l&&(d+=t?l:-l),d}}function at(e,n){return e.node(n).width}function Ue(e){e=_(e),st(e),Object.entries(Xe(e)).forEach(([n,t])=>e.node(n).x=t)}function st(e){let n=G(e),t=e.graph(),r=t.ranksep,o=t.rankalign,i=0;n.forEach(a=>{let s=a.reduce((d,l)=>{var c;let u=(c=e.node(l).height)!=null?c:0;return d>u?d:u},0);a.forEach(d=>{let l=e.node(d);o==="top"?l.y=i+l.height/2:o==="bottom"?l.y=i+s-l.height/2:l.y=i+s/2}),i+=s+r})}function B(e,n={}){let t=n.debugTiming?S:I;return t("layout",()=>{let r=t(" buildLayoutGraph",()=>mt(e));return t(" runLayout",()=>dt(r,t,n)),t(" updateInputGraph",()=>lt(e,r)),r})}function dt(e,n,t){n(" makeSpaceForEdgeLabels",()=>Lt(e)),n(" removeSelfEdges",()=>Tt(e)),n(" acyclic",()=>ye(e)),n(" nestingGraph.run",()=>Ce(e)),n(" rank",()=>Se(_(e))),n(" injectEdgeLabelProxies",()=>Et(e)),n(" removeEmptyRanks",()=>he(e)),n(" nestingGraph.cleanup",()=>_e(e)),n(" normalizeRanks",()=>fe(e)),n(" assignRankMinMax",()=>yt(e)),n(" removeEdgeLabelProxies",()=>Nt(e)),n(" normalize.run",()=>Ge(e)),n(" parentDummyChains",()=>Ie(e)),n(" addBorderSegments",()=>Ae(e)),n(" order",()=>W(e,t)),n(" insertSelfEdges",()=>Ot(e)),n(" adjustCoordinateSystem",()=>We(e)),n(" position",()=>Ue(e)),n(" positionSelfEdges",()=>Rt(e)),n(" removeBorderNodes",()=>vt(e)),n(" normalize.undo",()=>we(e)),n(" fixupEdgeLabelCoords",()=>kt(e)),n(" undoCoordinateSystem",()=>Be(e)),n(" translateGraph",()=>Gt(e)),n(" assignNodeIntersects",()=>wt(e)),n(" reversePoints",()=>xt(e)),n(" acyclic.undo",()=>Ne(e))}function lt(e,n){e.nodes().forEach(t=>{let r=e.node(t),o=n.node(t);r&&(r.x=o.x,r.y=o.y,r.order=o.order,r.rank=o.rank,n.children(t).length&&(r.width=o.width,r.height=o.height))}),e.edges().forEach(t=>{let r=e.edge(t),o=n.edge(t);r.points=o.points,Object.hasOwn(o,"x")&&(r.x=o.x,r.y=o.y)}),e.graph().width=n.graph().width,e.graph().height=n.graph().height}var ut=["nodesep","edgesep","ranksep","marginx","marginy"],ct={ranksep:50,edgesep:20,nodesep:50,rankdir:"TB",rankalign:"center"},bt=["acyclicer","ranker","rankdir","align","rankalign"],ft=["width","height","rank"],Ke={width:0,height:0},ht=["minlen","weight","width","height","labeloffset"],gt={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},pt=["labelpos"];function mt(e){let n=new p.Graph({multigraph:!0,compound:!0}),t=de(e.graph());return n.setGraph(Object.assign({},ct,se(t,ut),O(t,bt))),e.nodes().forEach(r=>{let o=de(e.node(r)),i=se(o,ft);Object.keys(Ke).forEach(s=>{i[s]===void 0&&(i[s]=Ke[s])}),n.setNode(r,i);let a=e.parent(r);a!==void 0&&n.setParent(r,a)}),e.edges().forEach(r=>{let o=de(e.edge(r));n.setEdge(r,Object.assign({},gt,se(o,ht),O(o,pt)))}),n}function Lt(e){let n=e.graph();n.ranksep/=2,e.edges().forEach(t=>{let r=e.edge(t);r.minlen*=2,r.labelpos.toLowerCase()!=="c"&&(n.rankdir==="TB"||n.rankdir==="BT"?r.width+=r.labeloffset:r.height+=r.labeloffset)})}function Et(e){e.edges().forEach(n=>{let t=e.edge(n);if(t.width&&t.height){let r=e.node(n.v),i={rank:(e.node(n.w).rank-r.rank)/2+r.rank,e:n};N(e,"edge-proxy",i,"_ep")}})}function yt(e){let n=0;e.nodes().forEach(t=>{let r=e.node(t);r.borderTop&&(r.minRank=e.node(r.borderTop).rank,r.maxRank=e.node(r.borderBottom).rank,n=Math.max(n,r.maxRank))}),e.graph().maxRank=n}function Nt(e){e.nodes().forEach(n=>{let t=e.node(n);if(t.dummy==="edge-proxy"){let r=t;e.edge(r.e).labelRank=t.rank,e.removeNode(n)}})}function Gt(e){let n=Number.POSITIVE_INFINITY,t=0,r=Number.POSITIVE_INFINITY,o=0,i=e.graph(),a=i.marginx||0,s=i.marginy||0;function d(l){let u=l.x,c=l.y,f=l.width,b=l.height;n=Math.min(n,u-f/2),t=Math.max(t,u+f/2),r=Math.min(r,c-b/2),o=Math.max(o,c+b/2)}e.nodes().forEach(l=>d(e.node(l))),e.edges().forEach(l=>{let u=e.edge(l);Object.hasOwn(u,"x")&&d(u)}),n-=a,r-=s,e.nodes().forEach(l=>{let u=e.node(l);u.x-=n,u.y-=r}),e.edges().forEach(l=>{let u=e.edge(l);u.points.forEach(c=>{c.x-=n,c.y-=r}),Object.hasOwn(u,"x")&&(u.x-=n),Object.hasOwn(u,"y")&&(u.y-=r)}),i.width=t-n+a,i.height=o-r+s}function wt(e){e.edges().forEach(n=>{let t=e.edge(n),r=e.node(n.v),o=e.node(n.w),i,a;t.points?(i=t.points[0],a=t.points[t.points.length-1]):(t.points=[],i=o,a=r),t.points.unshift(Y(r,i)),t.points.push(Y(o,a))})}function kt(e){e.edges().forEach(n=>{let t=e.edge(n);if(Object.hasOwn(t,"x"))switch((t.labelpos==="l"||t.labelpos==="r")&&(t.width-=t.labeloffset),t.labelpos){case"l":t.x-=t.width/2+t.labeloffset;break;case"r":t.x+=t.width/2+t.labeloffset;break}})}function xt(e){e.edges().forEach(n=>{let t=e.edge(n);t.reversed&&t.points.reverse()})}function vt(e){e.nodes().forEach(n=>{if(e.children(n).length){let t=e.node(n),r=e.node(t.borderTop),o=e.node(t.borderBottom),i=e.node(t.borderLeft[t.borderLeft.length-1]),a=e.node(t.borderRight[t.borderRight.length-1]);t.width=Math.abs(a.x-i.x),t.height=Math.abs(o.y-r.y),t.x=i.x+t.width/2,t.y=r.y+t.height/2}}),e.nodes().forEach(n=>{e.node(n).dummy==="border"&&e.removeNode(n)})}function Tt(e){e.edges().forEach(n=>{if(n.v===n.w){let t=e.node(n.v);t.selfEdges||(t.selfEdges=[]),t.selfEdges.push({e:n,label:e.edge(n)}),e.removeEdge(n)}})}function Ot(e){G(e).forEach(t=>{let r=0;t.forEach((o,i)=>{let a=e.node(o);a.order=i+r,(a.selfEdges||[]).forEach(s=>{N(e,"selfedge",{width:s.label.width,height:s.label.height,rank:a.rank,order:i+ ++r,e:s.e,label:s.label},"_se")}),delete a.selfEdges})})}function Rt(e){e.nodes().forEach(n=>{let t=e.node(n);if(t.dummy==="selfedge"){let r=t,o=e.node(r.e.v),i=o.x+o.width/2,a=o.y,s=t.x-i,d=o.height/2;e.setEdge(r.e,r.label),e.removeNode(n),r.label.points=[{x:i+2*s/3,y:a-d},{x:i+5*s/6,y:a-d},{x:i+s,y:a},{x:i+5*s/6,y:a+d},{x:i+2*s/3,y:a+d}],r.label.x=t.x,r.label.y=t.y}})}function se(e,n){return R(O(e,n),Number)}function de(e){let n={};return e&&Object.entries(e).forEach(([t,r])=>{typeof t=="string"&&(t=t.toLowerCase()),n[t]=r}),n}function D(e){let n=G(e),t=new p.Graph({compound:!0,multigraph:!0}).setGraph({});return e.nodes().forEach(r=>{t.setNode(r,{label:r}),t.setParent(r,"layer"+e.node(r).rank)}),e.edges().forEach(r=>t.setEdge(r.v,r.w,{},r.name)),n.forEach((r,o)=>{let i="layer"+o;t.setNode(i,{rank:"same"}),r.reduce((a,s)=>(t.setEdge(a,s,{style:"invis"}),s))}),t}var Qe=require("@dagrejs/graphlib");var Pt={time:S,notime:I},Mt={graphlib:Je,version:F,layout:B,debug:D,util:{time:S,notime:I}},St=Mt;0&&(module.exports={Graph,debug,graphlib,layout,util,version});
/*! For license information please see dagre.cjs.js.LEGAL.txt */
//# sourceMappingURL=dagre.cjs.js.map