@dagrejs/dagre 3.1.0 → 3.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dagre.cjs +3 -0
- package/dist/dagre.cjs.map +7 -0
- package/dist/dagre.esm.js +1 -1
- package/dist/dagre.esm.js.map +4 -4
- package/dist/dagre.js +287 -245
- package/dist/dagre.js.map +4 -4
- package/dist/dagre.min.js +1 -1
- package/dist/dagre.min.js.map +4 -4
- package/dist/types/index.d.ts +2 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/lib/acyclic.d.ts +1 -1
- package/dist/types/lib/acyclic.d.ts.map +1 -1
- package/dist/types/lib/graph-lib.d.ts +5 -2
- package/dist/types/lib/graph-lib.d.ts.map +1 -1
- package/dist/types/lib/layout.d.ts +2 -2
- package/dist/types/lib/layout.d.ts.map +1 -1
- package/dist/types/lib/types.d.ts +3 -2
- package/dist/types/lib/types.d.ts.map +1 -1
- package/dist/types/lib/version.d.ts +1 -1
- package/package.json +5 -4
- package/dist/dagre.cjs.js +0 -3
- package/dist/dagre.cjs.js.map +0 -7
- /package/dist/{dagre.cjs.js.LEGAL.txt → dagre.cjs.LEGAL.txt} +0 -0
package/dist/dagre.esm.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
var Re=Object.defineProperty;var Sn=(e,n,t)=>n in e?Re(e,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[n]=t;var Mn=(e,n)=>{for(var t in n)Re(e,t,{get:n[t],enumerable:!0})};var je=(e,n,t)=>Sn(e,typeof n!="symbol"?n+"":n,t);var oe={};Mn(oe,{Graph:()=>x,alg:()=>X,json:()=>Pe,version:()=>An});var Pn=Object.defineProperty,Me=(e,n)=>{for(var t in n)Pn(e,t,{get:n[t],enumerable:!0})},x=class{constructor(e){this._isDirected=!0,this._isMultigraph=!1,this._isCompound=!1,this._nodes={},this._in={},this._preds={},this._out={},this._sucs={},this._edgeObjs={},this._edgeLabels={},this._nodeCount=0,this._edgeCount=0,this._defaultNodeLabelFn=()=>{},this._defaultEdgeLabelFn=()=>{},e&&(this._isDirected="directed"in e?e.directed:!0,this._isMultigraph="multigraph"in e?e.multigraph:!1,this._isCompound="compound"in e?e.compound:!1),this._isCompound&&(this._parent={},this._children={},this._children["\0"]={})}isDirected(){return this._isDirected}isMultigraph(){return this._isMultigraph}isCompound(){return this._isCompound}setGraph(e){return this._label=e,this}graph(){return this._label}setDefaultNodeLabel(e){return typeof e!="function"?this._defaultNodeLabelFn=()=>e:this._defaultNodeLabelFn=e,this}nodeCount(){return this._nodeCount}nodes(){return Object.keys(this._nodes)}sources(){return this.nodes().filter(e=>Object.keys(this._in[e]).length===0)}sinks(){return this.nodes().filter(e=>Object.keys(this._out[e]).length===0)}setNodes(e,n){return e.forEach(t=>{n!==void 0?this.setNode(t,n):this.setNode(t)}),this}setNode(e,n){return e in this._nodes?(arguments.length>1&&(this._nodes[e]=n),this):(this._nodes[e]=arguments.length>1?n:this._defaultNodeLabelFn(e),this._isCompound&&(this._parent[e]="\0",this._children[e]={},this._children["\0"][e]=!0),this._in[e]={},this._preds[e]={},this._out[e]={},this._sucs[e]={},++this._nodeCount,this)}node(e){return this._nodes[e]}hasNode(e){return e in this._nodes}removeNode(e){if(e in this._nodes){let n=t=>this.removeEdge(this._edgeObjs[t]);delete this._nodes[e],this._isCompound&&(this._removeFromParentsChildList(e),delete this._parent[e],this.children(e).forEach(t=>{this.setParent(t)}),delete this._children[e]),Object.keys(this._in[e]).forEach(n),delete this._in[e],delete this._preds[e],Object.keys(this._out[e]).forEach(n),delete this._out[e],delete this._sucs[e],--this._nodeCount}return this}setParent(e,n){if(!this._isCompound)throw new Error("Cannot set parent in a non-compound graph");if(n===void 0)n="\0";else{n+="";for(let t=n;t!==void 0;t=this.parent(t))if(t===e)throw new Error("Setting "+n+" as parent of "+e+" would create a cycle");this.setNode(n)}return this.setNode(e),this._removeFromParentsChildList(e),this._parent[e]=n,this._children[n][e]=!0,this}parent(e){if(this._isCompound){let n=this._parent[e];if(n!=="\0")return n}}children(e="\0"){if(this._isCompound){let n=this._children[e];if(n)return Object.keys(n)}else{if(e==="\0")return this.nodes();if(this.hasNode(e))return[]}return[]}predecessors(e){let n=this._preds[e];if(n)return Object.keys(n)}successors(e){let n=this._sucs[e];if(n)return Object.keys(n)}neighbors(e){let n=this.predecessors(e);if(n){let t=new Set(n);for(let r of this.successors(e))t.add(r);return Array.from(t.values())}}isLeaf(e){let n;return this.isDirected()?n=this.successors(e):n=this.neighbors(e),n.length===0}filterNodes(e){let n=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});n.setGraph(this.graph()),Object.entries(this._nodes).forEach(([o,i])=>{e(o)&&n.setNode(o,i)}),Object.values(this._edgeObjs).forEach(o=>{n.hasNode(o.v)&&n.hasNode(o.w)&&n.setEdge(o,this.edge(o))});let t={},r=o=>{let i=this.parent(o);return!i||n.hasNode(i)?(t[o]=i!=null?i:void 0,i!=null?i:void 0):i in t?t[i]:r(i)};return this._isCompound&&n.nodes().forEach(o=>n.setParent(o,r(o))),n}setDefaultEdgeLabel(e){return typeof e!="function"?this._defaultEdgeLabelFn=()=>e:this._defaultEdgeLabelFn=e,this}edgeCount(){return this._edgeCount}edges(){return Object.values(this._edgeObjs)}setPath(e,n){return e.reduce((t,r)=>(n!==void 0?this.setEdge(t,r,n):this.setEdge(t,r),r)),this}setEdge(e,n,t,r){let o,i,s,a,d=!1;typeof e=="object"&&e!==null&&"v"in e?(o=e.v,i=e.w,s=e.name,arguments.length===2&&(a=n,d=!0)):(o=e,i=n,s=r,arguments.length>2&&(a=t,d=!0)),o=""+o,i=""+i,s!==void 0&&(s=""+s);let l=B(this._isDirected,o,i,s);if(l in this._edgeLabels)return d&&(this._edgeLabels[l]=a),this;if(s!==void 0&&!this._isMultigraph)throw new Error("Cannot set a named edge when isMultigraph = false");this.setNode(o),this.setNode(i),this._edgeLabels[l]=d?a:this._defaultEdgeLabelFn(o,i,s);let u=Fn(this._isDirected,o,i,s);return o=u.v,i=u.w,Object.freeze(u),this._edgeObjs[l]=u,Ie(this._preds[i],o),Ie(this._sucs[o],i),this._in[i][l]=u,this._out[o][l]=u,this._edgeCount++,this}edge(e,n,t){let r=arguments.length===1?re(this._isDirected,e):B(this._isDirected,e,n,t);return this._edgeLabels[r]}edgeAsObj(e,n,t){let r=arguments.length===1?this.edge(e):this.edge(e,n,t);return typeof r!="object"?{label:r}:r}hasEdge(e,n,t){return(arguments.length===1?re(this._isDirected,e):B(this._isDirected,e,n,t))in this._edgeLabels}removeEdge(e,n,t){let r=arguments.length===1?re(this._isDirected,e):B(this._isDirected,e,n,t),o=this._edgeObjs[r];if(o){let i=o.v,s=o.w;delete this._edgeLabels[r],delete this._edgeObjs[r],Se(this._preds[s],i),Se(this._sucs[i],s),delete this._in[s][r],delete this._out[i][r],this._edgeCount--}return this}inEdges(e,n){return this.isDirected()?this.filterEdges(this._in[e],e,n):this.nodeEdges(e,n)}outEdges(e,n){return this.isDirected()?this.filterEdges(this._out[e],e,n):this.nodeEdges(e,n)}nodeEdges(e,n){if(e in this._nodes)return this.filterEdges({...this._in[e],...this._out[e]},e,n)}_removeFromParentsChildList(e){delete this._children[this._parent[e]][e]}filterEdges(e,n,t){if(!e)return;let r=Object.values(e);return t?r.filter(o=>o.v===n&&o.w===t||o.v===t&&o.w===n):r}};function Ie(e,n){e[n]?e[n]++:e[n]=1}function Se(e,n){e[n]!==void 0&&!--e[n]&&delete e[n]}function B(e,n,t,r){let o=""+n,i=""+t;if(!e&&o>i){let s=o;o=i,i=s}return o+""+i+""+(r===void 0?"\0":r)}function Fn(e,n,t,r){let o=""+n,i=""+t;if(!e&&o>i){let a=o;o=i,i=a}let s={v:o,w:i};return r&&(s.name=r),s}function re(e,n){return B(e,n.v,n.w,n.name)}var An="4.0.1",Pe={};Me(Pe,{read:()=>Wn,write:()=>Vn});function Vn(e){let n={options:{directed:e.isDirected(),multigraph:e.isMultigraph(),compound:e.isCompound()},nodes:Dn(e),edges:Yn(e)},t=e.graph();return t!==void 0&&(n.value=structuredClone(t)),n}function Dn(e){return e.nodes().map(n=>{let t=e.node(n),r=e.parent(n),o={v:n};return t!==void 0&&(o.value=t),r!==void 0&&(o.parent=r),o})}function Yn(e){return e.edges().map(n=>{let t=e.edge(n),r={v:n.v,w:n.w};return n.name!==void 0&&(r.name=n.name),t!==void 0&&(r.value=t),r})}function Wn(e){let n=new x(e.options);return e.value!==void 0&&n.setGraph(e.value),e.nodes.forEach(t=>{n.setNode(t.v,t.value),t.parent&&n.setParent(t.v,t.parent)}),e.edges.forEach(t=>{n.setEdge({v:t.v,w:t.w,name:t.name},t.value)}),n}var X={};Me(X,{CycleException:()=>J,bellmanFord:()=>Fe,components:()=>zn,dijkstra:()=>U,dijkstraAll:()=>$n,findCycles:()=>Un,floydWarshall:()=>Kn,isAcyclic:()=>Zn,postorder:()=>nt,preorder:()=>tt,prim:()=>rt,shortestPaths:()=>ot,tarjan:()=>Ve,topsort:()=>De});var Bn=()=>1;function Fe(e,n,t,r){return Xn(e,String(n),t||Bn,r||function(o){return e.outEdges(o)})}function Xn(e,n,t,r){let o={},i,s=0,a=e.nodes(),d=function(c){let f=t(c);o[c.v].distance+f<o[c.w].distance&&(o[c.w]={distance:o[c.v].distance+f,predecessor:c.v},i=!0)},l=function(){a.forEach(function(c){r(c).forEach(function(f){let b=f.v===c?f.v:f.w,m=b===f.v?f.w:f.v;d({v:b,w:m})})})};a.forEach(function(c){let f=c===n?0:Number.POSITIVE_INFINITY;o[c]={distance:f,predecessor:""}});let u=a.length;for(let c=1;c<u&&(i=!1,s++,l(),!!i);c++);if(s===u-1&&(i=!1,l(),i))throw new Error("The graph contains a negative weight cycle");return o}function zn(e){let n={},t=[],r;function o(i){i in n||(n[i]=!0,r.push(i),e.successors(i).forEach(o),e.predecessors(i).forEach(o))}return e.nodes().forEach(function(i){r=[],o(i),r.length&&t.push(r)}),t}var Ae=class{constructor(){this._arr=[],this._keyIndices={}}size(){return this._arr.length}keys(){return this._arr.map(e=>e.key)}has(e){return e in this._keyIndices}priority(e){let n=this._keyIndices[e];if(n!==void 0)return this._arr[n].priority}min(){if(this.size()===0)throw new Error("Queue underflow");return this._arr[0].key}add(e,n){let t=this._keyIndices,r=String(e);if(!(r in t)){let o=this._arr,i=o.length;return t[r]=i,o.push({key:r,priority:n}),this._decrease(i),!0}return!1}removeMin(){this._swap(0,this._arr.length-1);let e=this._arr.pop();return delete this._keyIndices[e.key],this._heapify(0),e.key}decrease(e,n){let t=this._keyIndices[e];if(t===void 0)throw new Error(`Key not found: ${e}`);let r=this._arr[t].priority;if(n>r)throw new Error(`New priority is greater than current priority. Key: ${e} Old: ${r} New: ${n}`);this._arr[t].priority=n,this._decrease(t)}_heapify(e){let n=this._arr,t=2*e,r=t+1,o=e;t<n.length&&(o=n[t].priority<n[o].priority?t:o,r<n.length&&(o=n[r].priority<n[o].priority?r:o),o!==e&&(this._swap(e,o),this._heapify(o)))}_decrease(e){let n=this._arr,t=n[e].priority,r;for(;e!==0&&(r=e>>1,!(n[r].priority<t));)this._swap(e,r),e=r}_swap(e,n){let t=this._arr,r=this._keyIndices,o=t[e],i=t[n];t[e]=i,t[n]=o,r[i.key]=e,r[o.key]=n}},Hn=()=>1;function U(e,n,t,r){let o=function(i){return e.outEdges(i)};return qn(e,String(n),t||Hn,r||o)}function qn(e,n,t,r){let o={},i=new Ae,s,a,d=function(l){let u=l.v!==s?l.v:l.w,c=o[u],f=t(l),b=a.distance+f;if(f<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+l+" Weight: "+f);b<c.distance&&(c.distance=b,c.predecessor=s,i.decrease(u,b))};for(e.nodes().forEach(function(l){let u=l===n?0:Number.POSITIVE_INFINITY;o[l]={distance:u,predecessor:""},i.add(l,u)});i.size()>0&&(s=i.removeMin(),a=o[s],a.distance!==Number.POSITIVE_INFINITY);)r(s).forEach(d);return o}function $n(e,n,t){return e.nodes().reduce(function(r,o){return r[o]=U(e,o,n,t),r},{})}function Ve(e){let n=0,t=[],r={},o=[];function i(s){let a=r[s]={onStack:!0,lowlink:n,index:n++};if(t.push(s),e.successors(s).forEach(function(d){d in r?r[d].onStack&&(a.lowlink=Math.min(a.lowlink,r[d].index)):(i(d),a.lowlink=Math.min(a.lowlink,r[d].lowlink))}),a.lowlink===a.index){let d=[],l;do l=t.pop(),r[l].onStack=!1,d.push(l);while(s!==l);o.push(d)}}return e.nodes().forEach(function(s){s in r||i(s)}),o}function Un(e){return Ve(e).filter(function(n){return n.length>1||n.length===1&&e.hasEdge(n[0],n[0])})}var Jn=()=>1;function Kn(e,n,t){return Qn(e,n||Jn,t||function(r){return e.outEdges(r)})}function Qn(e,n,t){let r={},o=e.nodes();return o.forEach(function(i){r[i]={},r[i][i]={distance:0,predecessor:""},o.forEach(function(s){i!==s&&(r[i][s]={distance:Number.POSITIVE_INFINITY,predecessor:""})}),t(i).forEach(function(s){let a=s.v===i?s.w:s.v,d=n(s);r[i][a]={distance:d,predecessor:i}})}),o.forEach(function(i){let s=r[i];o.forEach(function(a){let d=r[a];o.forEach(function(l){let u=d[i],c=s[l],f=d[l],b=u.distance+c.distance;b<f.distance&&(f.distance=b,f.predecessor=c.predecessor)})})}),r}var J=class extends Error{constructor(...e){super(...e)}};function De(e){let n={},t={},r=[];function o(i){if(i in t)throw new J;i in n||(t[i]=!0,n[i]=!0,e.predecessors(i).forEach(o),delete t[i],r.push(i))}if(e.sinks().forEach(o),Object.keys(n).length!==e.nodeCount())throw new J;return r}function Zn(e){try{De(e)}catch(n){if(n instanceof J)return!1;throw n}return!0}function et(e,n,t,r,o){Array.isArray(n)||(n=[n]);let i=(a=>{var d;return(d=e.isDirected()?e.successors(a):e.neighbors(a))!=null?d:[]}),s={};return n.forEach(function(a){if(!e.hasNode(a))throw new Error("Graph does not have node: "+a);o=Ye(e,a,t==="post",s,i,r,o)}),o}function Ye(e,n,t,r,o,i,s){return n in r||(r[n]=!0,t||(s=i(s,n)),o(n).forEach(function(a){s=Ye(e,a,t,r,o,i,s)}),t&&(s=i(s,n))),s}function We(e,n,t){return et(e,n,t,function(r,o){return r.push(o),r},[])}function nt(e,n){return We(e,n,"post")}function tt(e,n){return We(e,n,"pre")}function rt(e,n){let t=new x,r={},o=new Ae,i;function s(d){let l=d.v===i?d.w:d.v,u=o.priority(l);if(u!==void 0){let c=n(d);c<u&&(r[l]=i,o.decrease(l,c))}}if(e.nodeCount()===0)return t;e.nodes().forEach(function(d){o.add(d,Number.POSITIVE_INFINITY),t.setNode(d)}),o.decrease(e.nodes()[0],0);let a=!1;for(;o.size()>0;){if(i=o.removeMin(),i in r)t.setEdge(i,r[i]);else{if(a)throw new Error("Input graph is not connected: "+e);a=!0}e.nodeEdges(i).forEach(s)}return t}function ot(e,n,t,r){return it(e,n,t,r!=null?r:(o=>{let i=e.outEdges(o);return i!=null?i:[]}))}function it(e,n,t,r){if(t===void 0)return U(e,n,t,r);let o=!1,i=e.nodes();for(let s=0;s<i.length;s++){let a=r(i[s]);for(let d=0;d<a.length;d++){let l=a[d],u=l.v===i[s]?l.v:l.w,c=u===l.v?l.w:l.v;t({v:u,w:c})<0&&(o=!0)}if(o)return Fe(e,n,t,r)}return U(e,n,t,r)}function I(e,n,t,r){let o=r;for(;e.hasNode(o);)o=H(r);return t.dummy=n,e.setNode(o,t),o}function Be(e){let n=new x().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 K(e){let n=new x({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 ie(e,n){let t=e.x,r=e.y,o=n.x-t,i=n.y-r,s=e.width/2,a=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)*s>Math.abs(o)*a?(i<0&&(a=-a),d=a*o/i,l=a):(o<0&&(s=-s),d=s,l=s*i/o),{x:t+d,y:r+l}}function S(e){let n=P(ae(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 Xe(e){let n=e.nodes().map(r=>{let o=e.node(r).rank;return o===void 0?Number.MAX_VALUE:o}),t=O(Math.min,n);e.nodes().forEach(r=>{let o=e.node(r);Object.hasOwn(o,"rank")&&(o.rank-=t)})}function ze(e){let n=e.nodes().map(s=>e.node(s).rank).filter(s=>s!==void 0),t=O(Math.min,n),r=[];e.nodes().forEach(s=>{let a=e.node(s).rank-t;r[a]||(r[a]=[]),r[a].push(s)});let o=0,i=e.graph().nodeRankFactor;Array.from(r).forEach((s,a)=>{s===void 0&&a%i!==0?--o:s!==void 0&&o&&s.forEach(d=>e.node(d).rank+=o)})}function se(e,n,t,r){let o={width:0,height:0};return arguments.length>=4&&(o.rank=t,o.order=r),I(e,"border",o,n)}function st(e,n=He){let t=[];for(let r=0;r<e.length;r+=n){let o=e.slice(r,r+n);t.push(o)}return t}var He=65535;function O(e,n){if(n.length>He){let t=st(n);return e(...t.map(r=>e(...r)))}else return e(...n)}function ae(e){let t=e.nodes().map(r=>{let o=e.node(r).rank;return o===void 0?Number.MIN_VALUE:o});return O(Math.max,t)}function qe(e,n){let t={lhs:[],rhs:[]};return e.forEach(r=>{n(r)?t.lhs.push(r):t.rhs.push(r)}),t}function de(e,n){let t=Date.now();try{return n()}finally{console.log(e+" time: "+(Date.now()-t)+"ms")}}function z(e,n){return n()}var at=0;function H(e){let n=++at;return e+(""+n)}function P(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 Y(e,n){let t={};for(let r of n)e[r]!==void 0&&(t[r]=e[r]);return t}function W(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 $e(e,n){return e.reduce((t,r,o)=>(t[r]=n[o],t),{})}var V="\0";function Q(e,n,t){var l,u,c,f,b,m;if(!(e&&n&&t&&n.dummy==="edge"&&t.dummy==="edge"&&n.edgeObj&&t.edgeObj&&e[n.edgeObj.v]&&e[t.edgeObj.v]&&e[n.edgeObj.w]&&e[t.edgeObj.w]))return 0;let r=!0;n.edgeObj.w===t.edgeObj.w&&(r=!1);let o=r?(u=(l=e[n.edgeObj.v])==null?void 0:l.rank)!=null?u:NaN+1:(f=(c=e[n.edgeObj.w])==null?void 0:c.rank)!=null?f:NaN-1,i=Object.entries(e).find(E=>{var h,g;return((h=E[1].edgeObj)==null?void 0:h.v)===n.edgeObj.v&&((g=E[1].edgeObj)==null?void 0:g.w)===n.edgeObj.w&&E[1].rank===o}),s=Object.entries(e).find(E=>{var h,g;return((h=E[1].edgeObj)==null?void 0:h.v)===t.edgeObj.v&&((g=E[1].edgeObj)==null?void 0:g.w)===t.edgeObj.w&&E[1].rank===o});if(!i||!s)return 0;let a=(b=i[1].order)!=null?b:NaN,d=(m=s[1].order)!=null?m:NaN;return isNaN(a-d)?0:a-d}var le="3.1.0";var ue=class{constructor(){je(this,"_sentinel");let n={};n._next=n._prev=n,this._sentinel=n}dequeue(){let n=this._sentinel,t=n._prev;if(t!==n)return Ue(t),t}enqueue(n){let t=this._sentinel;n._prev&&n._next&&Ue(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,dt)),r=r._prev;return"["+n.join(", ")+"]"}};function Ue(e){e._prev._next=e._next,e._next._prev=e._prev,delete e._next,delete e._prev}function dt(e,n){if(e!=="_next"&&e!=="_prev")return n}var Je=ue;var lt=()=>1;function be(e,n){if(e.nodeCount()<=1)return[];let t=ct(e,n||lt);return ut(t.graph,t.buckets,t.zeroIdx).flatMap(o=>e.outEdges(o.v,o.w)||[])}function ut(e,n,t){var a;let r=[],o=n[n.length-1],i=n[0],s;for(;e.nodeCount();){for(;s=i.dequeue();)ce(e,n,t,s);for(;s=o.dequeue();)ce(e,n,t,s);if(e.nodeCount()){for(let d=n.length-2;d>0;--d)if(s=(a=n[d])==null?void 0:a.dequeue(),s){r=r.concat(ce(e,n,t,s,!0)||[]);break}}}return r}function ce(e,n,t,r,o){let i=[],s=o?i:void 0;return(e.inEdges(r.v)||[]).forEach(a=>{let d=e.edge(a),l=e.node(a.v);o&&i.push({v:a.v,w:a.w}),l.out-=d,fe(n,t,l)}),(e.outEdges(r.v)||[]).forEach(a=>{let d=e.edge(a),l=a.w,u=e.node(l);u.in-=d,fe(n,t,u)}),e.removeNode(r.v),s}function ct(e,n){let t=new x,r=0,o=0;e.nodes().forEach(a=>{t.setNode(a,{v:a,in:0,out:0})}),e.edges().forEach(a=>{let d=t.edge(a.v,a.w)||0,l=n(a),u=d+l;t.setEdge(a.v,a.w,u);let c=t.node(a.v),f=t.node(a.w);o=Math.max(o,c.out+=l),r=Math.max(r,f.in+=l)});let i=ft(o+r+3).map(()=>new Je),s=r+1;return t.nodes().forEach(a=>{fe(i,s,t.node(a))}),{graph:t,buckets:i,zeroIdx:s}}function fe(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 ft(e){let n=[];for(let t=0;t<e;t++)n.push(t);return n}function Ke(e,n){(e.graph().acyclicer==="greedy"?be(e,r(e)):bt(e,n!=null?n:null)).forEach(o=>{let i=e.edge(o);e.removeEdge(o),i.forwardName=o.name,i.reversed=!0,e.setEdge(o.w,o.v,i,H("rev"))});function r(o){return i=>o.edge(i).weight}}function bt(e,n){let t=[],r={},o={};function i(d){Object.hasOwn(o,d)||(o[d]=!0,r[d]=!0,e.outEdges(d).forEach(l=>{Object.hasOwn(r,l.w)?t.push(l):i(l.w)}),delete r[d])}function s(d){var l;Object.hasOwn(o,d)||(o[d]=!0,r[d]=!0,(l=e.outEdges(d))==null||l.forEach(u=>{var c,f;Object.hasOwn(r,u.w)||((c=n.node(d))==null?void 0:c.rank)>((f=n.node(u.w))==null?void 0:f.rank)&&ht(e,u.w,u)?t.push(u):s(u.w)}),delete r[d])}let a=i;return n&&typeof n.node=="function"&&(a=s),e.sources().forEach(a),e.nodes().forEach(a),t}function Qe(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 ht(e,n,t){let r=new Set;function o(i){var s;if(e.sources().includes(i))return!0;r.add(i);for(let a of(s=e.inEdges(i))!=null?s:[])if(!(a.v===t.v&&a.w===t.w)&&!r.has(a.v)&&o(a.v))return!0;return!1}return o(n)}function Ze(e){e.graph().dummyChains=[],e.edges().forEach(n=>pt(e,n))}function pt(e,n){let t=n.v,r=e.node(t).rank,o=n.w,i=e.node(o).rank,s=n.name,a=e.edge(n),d=a.labelRank;if(i===r+1)return;e.removeEdge(n);let l,u,c;for(c=0,++r;r<i;++c,++r)a.points=[],u={width:0,height:0,edgeLabel:a,edgeObj:n,rank:r},l=I(e,"edge",u,"_d"),r===d&&(u.width=a.width,u.height=a.height,u.dummy="edge-label",u.labelpos=a.labelpos),e.setEdge(t,l,{weight:a.weight},s),c===0&&e.graph().dummyChains.push(l),t=l;e.setEdge(t,o,{weight:a.weight},s)}function en(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 q(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),s=i?i.map(d=>d==null?Number.POSITIVE_INFINITY:t(d.w)-e.edge(d).minlen):[],a=O(Math.min,s);return a===Number.POSITIVE_INFINITY&&(a=0),o.rank=a}e.sources().forEach(t)}function F(e,n){return e.node(n.w).rank-e.node(n.v).rank-e.edge(n).minlen}var Z=Et;function Et(e){let n=new x({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,s;for(;Lt(n,e)<o&&(i=yt(n,e),!!i);)s=n.hasNode(i.v)?F(e,i):-F(e,i),wt(n,e,s);return n}function Lt(e,n){function t(r){let o=n.nodeEdges(r);o&&o.forEach(i=>{let s=i.v,a=r===s?i.w:s;!e.hasNode(a)&&!F(n,i)&&(e.setNode(a,{}),e.setEdge(r,a,{}),t(a))})}return e.nodes().forEach(t),e.nodeCount()}function yt(e,n){return n.edges().reduce((r,o)=>{let i=Number.POSITIVE_INFINITY;return e.hasNode(o.v)!==e.hasNode(o.w)&&(i=F(n,o)),i<r[0]?[i,o]:r},[Number.POSITIVE_INFINITY,null])[1]}function wt(e,n,t){e.nodes().forEach(r=>n.node(r).rank+=t)}var{preorder:Nt,postorder:Gt}=X,tn=D;D.initLowLimValues=ge;D.initCutValues=he;D.calcCutValue=rn;D.leaveEdge=sn;D.enterEdge=an;D.exchangeEdges=dn;function D(e){e=Be(e),q(e);let n=Z(e);ge(n),he(n,e);let t,r;for(;t=sn(n);)r=an(n,e,t),dn(n,e,t,r)}function he(e,n){let t=Gt(e,e.nodes());t=t.slice(0,t.length-1),t.forEach(r=>vt(e,n,r))}function vt(e,n,t){let o=e.node(t).parent,i=e.edge(t,o);i.cutvalue=rn(e,n,t)}function rn(e,n,t){let o=e.node(t).parent,i=!0,s=n.edge(t,o),a=0;s||(i=!1,s=n.edge(o,t)),a=s.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(a+=f?b:-b,xt(e,t,c)){let E=e.edge(t,c).cutvalue;a+=f?-E:E}}}),a}function ge(e,n){arguments.length<2&&(n=e.nodes()[0]),on(e,{},1,n)}function on(e,n,t,r,o){let i=t,s=e.node(r);n[r]=!0;let a=e.neighbors(r);return a&&a.forEach(d=>{Object.hasOwn(n,d)||(t=on(e,n,t,d,r))}),s.low=i,s.lim=t++,o?s.parent=o:delete s.parent,t}function sn(e){return e.edges().find(n=>e.edge(n).cutvalue<0)}function an(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),s=e.node(o),a=i,d=!1;return i.lim>s.lim&&(a=s,d=!0),n.edges().filter(u=>d===nn(e,e.node(u.v),a)&&d!==nn(e,e.node(u.w),a)).reduce((u,c)=>F(n,c)<F(n,u)?c:u)}function dn(e,n,t,r){let o=t.v,i=t.w;e.removeEdge(o,i),e.setEdge(r.v,r.w,{}),ge(e),he(e,n),kt(e,n)}function kt(e,n){let t=e.nodes().find(o=>!e.node(o).parent);if(!t)return;let r=Nt(e,[t]);r=r.slice(1),r.forEach(o=>{let s=e.node(o).parent,a=n.edge(o,s),d=!1;a||(a=n.edge(s,o),d=!0),n.node(o).rank=n.node(s).rank+(d?a.minlen:-a.minlen)})}function xt(e,n,t){return e.hasEdge(n,t)}function nn(e,n,t){return t.low<=n.lim&&n.lim<=t.lim}var un=_t;function _t(e){let n=e.graph().ranker;if(typeof n=="function")return n(e);switch(n){case"network-simplex":ln(e);break;case"tight-tree":Ct(e);break;case"longest-path":Ot(e);break;case"none":break;default:ln(e)}}var Ot=q;function Ct(e){q(e),Z(e)}function ln(e){tn(e)}var cn=Tt;function Tt(e){let n=jt(e),t=e.graph();if(!Array.isArray(t.dummyChains))return;t.dummyChains.forEach(o=>{let i=e.node(o),s=i.edgeObj,a=Rt(e,n,s.v,s.w),d=a.path,l=a.lca,u=0,c=d[u],f=!0;for(;o!==s.w;){if(i=e.node(o),f){for(;(c=d[u])!==l&&e.node(c).maxRank<i.rank;)u++;c===l&&(f=!1)}if(!f){for(;u<d.length-1&&e.node(d[u+1]).minRank<=i.rank;)u++;c=d[u]}c!==void 0&&e.setParent(o,c),o=e.successors(o)[0]}})}function Rt(e,n,t,r){let o=[],i=[],s=Math.min(n[t].low,n[r].low),a=Math.max(n[t].lim,n[r].lim),d;d=t;do d=e.parent(d),o.push(d);while(d&&(n[d].low>s||a>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 jt(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 fn(e){let n=I(e,"root",{},"_root"),t=It(e),r=Object.values(t),o=O(Math.max,r)-1,i=2*o+1;e.graph().nestingRoot=n,e.edges().forEach(a=>e.edge(a).minlen*=i);let s=St(e)+1;e.children(V).forEach(a=>{bn(e,n,i,s,o,t,a)}),e.graph().nodeRankFactor=i}function bn(e,n,t,r,o,i,s){var c;let a=e.children(s);if(!a.length){s!==n&&e.setEdge(n,s,{weight:0,minlen:t});return}let d=se(e,"_bt"),l=se(e,"_bb"),u=e.node(s);e.setParent(d,s),u.borderTop=d,e.setParent(l,s),u.borderBottom=l,a.forEach(f=>{var p;bn(e,n,t,r,o,i,f);let b=e.node(f),m=b.borderTop?b.borderTop:f,E=b.borderBottom?b.borderBottom:f,h=b.borderTop?r:2*r,g=m!==E?1:o-((p=i[s])!=null?p:0)+1;e.setEdge(d,m,{weight:h,minlen:g,nestingEdge:!0}),e.setEdge(E,l,{weight:h,minlen:g,nestingEdge:!0})}),e.parent(s)||e.setEdge(n,d,{weight:0,minlen:o+((c=i[s])!=null?c:0)})}function It(e){let n={};function t(r,o){let i=e.children(r);i&&i.length&&i.forEach(s=>t(s,o+1)),n[r]=o}return e.children(V).forEach(r=>t(r,1)),n}function St(e){return e.edges().reduce((n,t)=>n+e.edge(t).weight,0)}function hn(e){let n=e.graph();e.removeNode(n.nestingRoot),delete n.nestingRoot,e.edges().forEach(t=>{e.edge(t).nestingEdge&&e.removeEdge(t)})}var pn=Pt;function Pt(e){function n(t){let r=e.children(t),o=e.node(t);if(r.length&&r.forEach(n),o&&Object.hasOwn(o,"minRank")){o.borderLeft=[],o.borderRight=[];for(let i=o.minRank,s=o.maxRank+1;i<s;++i)gn(e,"borderLeft","_bl",t,o,i),gn(e,"borderRight","_br",t,o,i)}}e.children(V).forEach(n)}function gn(e,n,t,r,o,i){let s={width:0,height:0,rank:i,borderType:n},a=o[n][i-1],d=I(e,"border",s,t);o[n][i]=d,e.setParent(d,r),a&&e.setEdge(a,d,{weight:1})}function En(e){var t;let n=(t=e.graph().rankdir)==null?void 0:t.toLowerCase();(n==="lr"||n==="rl")&&yn(e)}function Ln(e){var t;let n=(t=e.graph().rankdir)==null?void 0:t.toLowerCase();(n==="bt"||n==="rl")&&Ft(e),(n==="lr"||n==="rl")&&(At(e),yn(e))}function yn(e){e.nodes().forEach(n=>mn(e.node(n))),e.edges().forEach(n=>mn(e.edge(n)))}function mn(e){let n=e.width;e.width=e.height,e.height=n}function Ft(e){e.nodes().forEach(n=>pe(e.node(n))),e.edges().forEach(n=>{var r;let t=e.edge(n);(r=t.points)==null||r.forEach(pe),Object.hasOwn(t,"y")&&pe(t)})}function pe(e){e.y=-e.y}function At(e){e.nodes().forEach(n=>me(e.node(n))),e.edges().forEach(n=>{var r;let t=e.edge(n);(r=t.points)==null||r.forEach(me),Object.hasOwn(t,"x")&&me(t)})}function me(e){let n=e.x;e.x=e.y,e.y=n}function Ee(e,n=null){let t={},r=e.nodes().filter(u=>!e.children(u).length),o=r.map(u=>e.node(u).rank),i=O(Math.max,o),s=P(i+1).map(()=>[]);function a(u){if(t[u])return;t[u]=!0;let c=e.node(u);s[c.rank].push(u);let f=e.successors(u);f&&[...f].sort((m,E)=>l(m,E)).forEach(a)}r.sort((u,c)=>e.node(u).rank-e.node(c).rank).forEach(a);function l(u,c){let f=e.node(u),b=e.node(c);return Q(n,f,b)}return s}function Le(e,n){let t=0;for(let r=1;r<n.length;++r)t+=Dt(e,n[r-1],n[r]);return t}function Dt(e,n,t){let r=$e(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 s=2*i-1;i-=1;let a=new Array(s).fill(0),d=0;return o.forEach(l=>{let u=l.pos+i;a[u]+=l.weight;let c=0;for(;u>0;)u%2&&(c+=a[u+1]),u=u-1>>1,a[u]+=l.weight;d+=l.weight*c}),d}function ye(e,n=[]){return n.map(t=>{let r=e.inEdges(t);if(!r||!r.length)return{v:t};{let o=r.reduce((i,s)=>{let a=e.edge(s),d=e.node(s.v);return{sum:i.sum+a.weight*d.order,weight:i.weight+a.weight}},{sum:0,weight:0});return{v:t,barycenter:o.sum/o.weight,weight:o.weight}}})}function we(e,n){let t={};e.forEach((o,i)=>{let s={indegree:0,in:[],out:[],vs:[o.v],i};o.barycenter!==void 0&&(s.barycenter=o.barycenter,s.weight=o.weight),t[o.v]=s}),n.edges().forEach(o=>{let i=t[o.v],s=t[o.w];i!==void 0&&s!==void 0&&(s.indegree++,i.out.push(s))});let r=Object.values(t).filter(o=>!o.indegree);return Yt(r)}function Yt(e){let n=[];function t(o){return i=>{i.merged||(i.barycenter===void 0||o.barycenter===void 0||i.barycenter>=o.barycenter)&&Wt(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=>Y(o,["vs","i","barycenter","weight"]))}function Wt(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 Ne(e,n,t,r,o){let i={},s=null,a=null,d=o;typeof n=="boolean"?(d=n,i={}):n&&(i=n,s=t!=null?t:null,a=r!=null?r:null);let l=qe(e,g=>Object.hasOwn(g,"barycenter")),u=l.lhs,c=l.rhs.sort((g,p)=>p.i-g.i),f=[],b=0,m=0,E=0;u.sort(Bt(a,s,!!d));for(let[g,p]of Object.entries(i)){let w=u.findIndex(v=>v.vs[0]===g);u.splice(w+1,0,p)}E=wn(f,c,E),u.forEach(g=>{E+=g.vs.length,f.push(g.vs),b+=g.barycenter*g.weight,m+=g.weight,E=wn(f,c,E)});let h={vs:f.flat(1)};return m&&(h.barycenter=b/m,h.weight=m),h}function wn(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 Bt(e,n,t){return(r,o)=>{if(r.barycenter<o.barycenter)return-1;if(r.barycenter>o.barycenter)return 1;if(e&&(typeof r.vs[0]=="string"||typeof o.vs[0]=="string")){let i=e.node(r.vs[0]),s=e.node(o.vs[0]),a=Q(n,i,s);if(a!==0)return a}return t?o.i-r.i:r.i-o.i}}function ee(e,n,t,r,o){var g,p,w,v,N,G,_,C,T,j,R;let i=null,s=o;typeof r=="boolean"?(s=r,i=null):r!==void 0&&(i=r);let a=e.children(n),d=e.node(n),l=d?d.borderLeft:void 0,u=d?d.borderRight:void 0,c={};l&&(a=a.filter(y=>y!==l&&y!==u));let f=ye(e,a);f.forEach(y=>{if(e.children(y.v).length){let{result:L}=ee(e,y.v,t,i,s);c[y.v]=L,Object.hasOwn(L,"barycenter")&&zt(y,L)}});let b=we(f,t);Xt(b,c);let m={},E=!1;for(let y=0;y<b.length;y++)for(let L=y+1;L<b.length;L++)if(!(!b[y]||!b[L]||!((g=b[y])!=null&&g.barycenter)||!((p=b[L])!=null&&p.barycenter))&&((w=b[y])==null?void 0:w.barycenter)===b[L].barycenter){let k=(N=(v=b[y])==null?void 0:v.vs[0])!=null?N:"",A=(_=(G=b[L])==null?void 0:G.vs[0])!=null?_:"",$=e.node(k),te=e.node(A);if($.dummy==="edge"&&te.dummy==="edge"&&((C=$.edgeObj)==null?void 0:C.v)===((T=te.edgeObj)==null?void 0:T.v)&&((j=$.edgeObj)==null?void 0:j.w)===((R=te.edgeObj)==null?void 0:R.w))if($.edgeLabel.reversed){m[A]=b[y],b.splice(y,1),y--;break}else m[k]=b[L],b.splice(L,1),L--;else E=!0}let h=Ne(b,m,i,e,s);if(l&&u){h.vs=[l,h.vs,u].flat(1);let y=e.predecessors(l);if(y&&y.length){let L=e.node(y[0]),k=e.predecessors(u),A=e.node(k[0]);Object.hasOwn(h,"barycenter")||(h.barycenter=0,h.weight=0),h.barycenter=(h.barycenter*h.weight+L.order+A.order)/(h.weight+2),h.weight+=2}}return Object.defineProperty(h,"result",{value:h,enumerable:!1,configurable:!0,writable:!0}),Object.defineProperty(h,"usedBias",{value:E,enumerable:!1,configurable:!0,writable:!0}),h}function Xt(e,n){e.forEach(t=>{t.vs=t.vs.flatMap(r=>n[r]?n[r].vs:r)})}function zt(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 Ge(e,n,t,r){r||(r=e.nodes());let o=Ht(e),i=new x({compound:!0}).setGraph({root:o}).setDefaultNodeLabel(s=>e.node(s));return r.forEach(s=>{let a=e.node(s),d=e.parent(s);if(a.rank===n||a.minRank<=n&&n<=a.maxRank){i.setNode(s),i.setParent(s,d||o);let l=e[t](s);l&&l.forEach(u=>{let c=u.v===s?u.w:u.v,f=i.edge(c,s),b=f!==void 0?f.weight:0;i.setEdge(c,s,{weight:e.edge(u).weight+b})}),Object.hasOwn(a,"minRank")&&i.setNode(s,{borderLeft:a.borderLeft[n],borderRight:a.borderRight[n]})}}),i}function Ht(e){let n;for(;e.hasNode(n=H("_root")););return n}function ve(e,n,t){let r={},o;t.forEach(i=>{let s=e.parent(i),a,d;for(;s;){if(a=e.parent(s),a?(d=r[a],r[a]=s):(d=o,o=s),d&&d!==s){n.setEdge(d,s);return}s=a}})}function ne(e,n={},t=null){if(typeof n.customOrder=="function"){n.customOrder(e,ne);return}let r=ae(e),o=Nn(e,P(1,r+1),"inEdges"),i=Nn(e,P(r-1,-1,-1),"outEdges"),s=Ee(e,t);if(Gn(e,s),n.disableOptimalOrderHeuristic)return;let a=Number.POSITIVE_INFINITY,d,l=n.constraints||[];for(let u=0,c=0;c<4;++u,++c){qt(u%2?o:i,u%4>=2,l,t),s=S(e);let f=Le(e,s);f<a?(c=0,d=Object.assign({},s),a=f):f===a&&(d=structuredClone(s))}Gn(e,d)}function Nn(e,n,t){let r=new Map,o=(i,s)=>{r.has(i)||r.set(i,[]),r.get(i).push(s)};for(let i of e.nodes()){let s=e.node(i);if(typeof s.rank=="number"&&o(s.rank,i),typeof s.minRank=="number"&&typeof s.maxRank=="number")for(let a=s.minRank;a<=s.maxRank;a++)a!==s.rank&&o(a,i)}return n.map(function(i){return Ge(e,i,t,r.get(i)||[])})}function qt(e,n,t,r){let o=!0,i=new x;e.forEach(function(s){t.forEach(u=>i.setEdge(u.left,u.right));let a=s.graph().root,{result:d,usedBias:l}=ee(s,a,i,r,o);n&&l&&(o=!o),d.vs.forEach((u,c)=>s.node(u).order=c),ve(s,i,d.vs)})}function Gn(e,n){Object.values(n).forEach(t=>t.forEach((r,o)=>e.node(r).order=o))}function $t(e,n){let t={};function r(o,i){let s=0,a=0,d=o.length,l=i[i.length-1];return i.forEach((u,c)=>{let f=Jt(e,u),b=f?e.node(f).order:d;(f||u===l)&&(i.slice(a,c+1).forEach(m=>{let E=e.predecessors(m);E&&E.forEach(h=>{let g=e.node(h),p=g.order;(p<s||b<p)&&!(g.dummy&&e.node(m).dummy)&&kn(t,h,m)})}),a=c+1,s=b)}),i}return n.length&&n.reduce(r),t}function Ut(e,n){let t={};function r(i,s,a,d,l){P(s,a).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 m=e.node(b);m.dummy&&(m.order<d||m.order>l)&&kn(t,b,c)})}})}function o(i,s){let a=-1,d=-1,l=0;return s.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(s,l,c,a,d),l=c,a=d}}r(s,l,s.length,d,i.length)}),s}return n.length&&n.reduce(o),t}function Jt(e,n){if(e.node(n).dummy){let t=e.predecessors(n);if(t)return t.find(r=>e.node(r).dummy)}}function kn(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 Kt(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 Qt(e,n,t,r,o){let i={},s={},a={};return n.forEach(d=>{d.forEach((l,u)=>{i[l]=l,s[l]=l,a[l]=u})}),n.forEach(d=>{let l=-1,u=-1,c=!1,f=d,b=d.findIndex(m=>(o==null?void 0:o.includes(m))||vn(m,e,o));b>0&&(f=[d[b],...d.slice(0,b),...d.slice(b+1)],c=!0),f.forEach(m=>{var h;let E=r(m);if(E&&E.length){o!=null&&o.includes(m)&&(E=E.filter(w=>vn(w,e,o)));let g=E.sort((w,v)=>{let N=a[w],G=a[v];return(N!==void 0?N:0)-(G!==void 0?G:0)}),p=(g.length-1)/2;for(let w=Math.floor(p),v=Math.ceil(p);w<=v;++w){let N=g[w];if(N===void 0)continue;let G=a[N];if(G!==void 0&&s[m]===m&&l<G&&a[N]!==u&&!Kt(t,m,N)){let _=i[N];_!==void 0&&(s[N]=m,s[m]=i[m]=_,l=G,c&&(l=-1,u=(h=a[N])!=null?h:-1,c=!1))}}}})}),{root:i,align:s}}function Zt(e,n,t,r,o=!1){let i={},s=er(e,n,t,o),a=o?"borderLeft":"borderRight";function d(b,m){let E=s.nodes().slice(),h={},g=E.pop();for(;g;){if(h[g])b(g);else{h[g]=!0,E.push(g);for(let p of m(g))E.push(p)}g=E.pop()}}function l(b){let m=s.inEdges(b);m?i[b]=m.reduce((E,h)=>{var w;let g=(w=i[h.v])!=null?w:0,p=s.edge(h);return Math.max(E,g+(p!==void 0?p:0))},0):i[b]=0}function u(b){let m=s.outEdges(b),E=Number.POSITIVE_INFINITY;m&&(E=m.reduce((g,p)=>{let w=i[p.w],v=s.edge(p);return Math.min(g,(w!==void 0?w:0)-(v!==void 0?v:0))},Number.POSITIVE_INFINITY));let h=e.node(b);E!==Number.POSITIVE_INFINITY&&h.borderType!==a&&(i[b]=Math.max(i[b]!==void 0?i[b]:0,E))}function c(b){return s.predecessors(b)||[]}function f(b){return s.successors(b)||[]}return d(l,c),d(u,f),Object.keys(r).forEach(b=>{var E;let m=t[b];m!==void 0&&(i[b]=(E=i[m])!=null?E:0)}),i}function er(e,n,t,r){let o=new x,i=e.graph(),s=or(i.nodesep,i.edgesep,r);return n.forEach(a=>{let d;a.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(s(e,l,d),f||0))}}d=l}})}),o}function nr(e,n){return Object.values(n).reduce((t,r)=>{let o=Number.NEGATIVE_INFINITY,i=Number.POSITIVE_INFINITY;Object.entries(r).forEach(([a,d])=>{let l=ir(e,a)/2;o=Math.max(d+l,o),i=Math.min(d-l,i)});let s=o-i;return s<t[0]&&(t=[s,r]),t},[Number.POSITIVE_INFINITY,null])[1]}function tr(e,n){let t=Object.values(n),r=O(Math.min,t),o=O(Math.max,t);["u","d"].forEach(i=>{["l","r"].forEach(s=>{let a=i+s,d=e[a];if(!d||d===n)return;let l=Object.values(d),u=r-O(Math.min,l);s!=="l"&&(u=o-O(Math.max,l)),u&&(e[a]=W(d,c=>c+u))})})}function rr(e,n=void 0){let t=e.ul;return t?W(t,(r,o)=>{var s,a;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(((s=i[1])!=null?s:0)+((a=i[2])!=null?a:0))/2}):{}}function xn(e,n){let t=S(e),r=Object.assign($t(e,t),Ut(e,t)),o={},i;["u","d"].forEach(a=>{i=a==="u"?t:Object.values(t).reverse(),["l","r"].forEach(d=>{d==="r"&&(i=i.map(f=>Object.values(f).reverse()));let u=Qt(e,i,r,f=>(a==="u"?e.predecessors(f):e.successors(f))||[],n),c=Zt(e,i,u.root,u.align,d==="r");d==="r"&&(c=W(c,f=>-f)),o[a+d]=c})});let s=nr(e,o);return tr(o,s),rr(o,e.graph().align)}function or(e,n,t){return(r,o,i)=>{let s=r.node(o),a=r.node(i),d=0,l;if(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}if(l&&(d+=t?l:-l),l=void 0,d+=(s.dummy?n:e)/2,d+=(a.dummy?n:e)/2,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}return l&&(d+=t?l:-l),d}}function ir(e,n){return e.node(n).width}function vn(e,n,t){var s;if(!t)return!1;let r=(s=n.node(e))==null?void 0:s.edgeObj;if(!r||n.node(e).edgeLabel.reversed)return!1;let o=t.indexOf(r==null?void 0:r.v),i=t.indexOf(r==null?void 0:r.w);return o!==-1&&i!==-1&&o===(i+1)%t.length||o===(i-1)%t.length}function _n(e,n){e=K(e),sr(e),Object.entries(xn(e,n)).forEach(([t,r])=>e.node(t).x=r)}function sr(e){let n=S(e),t=e.graph(),r=t.ranksep,o=t.rankalign,i=0;n.forEach(s=>{let a=s.reduce((d,l)=>{var c;let u=(c=e.node(l).height)!=null?c:0;return d>u?d:u},0);s.forEach(d=>{let l=e.node(d);o==="top"?l.y=i+l.height/2:o==="bottom"?l.y=i+a-l.height/2:l.y=i+a/2}),i+=a+r})}var ke=null,xe=null;function Ce(e,n={}){return In(e,z,n),e}function On(e,n,t){let r=n;for(;r!==void 0;){let o=e.parent(r);if(o===t)return r;r=o}}function In(e,n,t){let r=e.nodes().filter(h=>e.children(h).length),o={};r.forEach(h=>{let g=e.node(h);if(g&&g.rankdir){let p=new x({multigraph:!0,compound:!0});p.setGraph({rankdir:g.rankdir});let w=e.children(h);w.forEach(y=>{let L={...e.node(y)};p.setNode(y,L);let k=e.parent(y);k&&k!==h&&w.includes(k)&&p.setParent(y,k)});let v=new Set;e.edges().forEach(y=>{let L=On(e,y.v,h),k=On(e,y.w,h);if(L&&k&&L!==k){let A=`${L}\0${k}`;v.has(A)||(v.add(A),p.setEdge(L,k,{...e.edge(y)}))}}),In(p,n,t);let N=jn(p);Cn(N,n,t),Tn(p,N);let G=1/0,_=1/0,C=-1/0,T=-1/0;p.nodes().forEach(y=>{if(y===h)return;let L=p.node(y);L&&typeof L.x=="number"&&typeof L.y=="number"&&typeof L.width=="number"&&typeof L.height=="number"&&(G=Math.min(G,L.x-L.width/2),C=Math.max(C,L.x+L.width/2),_=Math.min(_,L.y-L.height/2),T=Math.max(T,L.y+L.height/2))}),(!isFinite(G)||!isFinite(_)||!isFinite(C)||!isFinite(T))&&(G=_=0,C=T=0);let j=C-G,R=T-_;o[h]={minX:G,minY:_,maxX:C,maxY:T,width:j,height:R,offsetX:G,offsetY:_},g._dagreClusterSubgraph=p}});let i=[],s=h=>{let g=[],p=(e.children(h)||[]).filter(w=>w!==h);for(;p.length>0;){let w=p.shift();g.push(w),(e.children(w)||[]).filter(v=>v!==w).forEach(v=>p.push(v))}return g},a=new Map;r.forEach(h=>{let g=e.node(h);g&&g.rankdir&&o[h]&&a.set(h,(e.children(h)||[]).filter(p=>p!==h))});let d=new Set([...a.values()].flat()),l=new Map;a.forEach((h,g)=>{d.has(g)||l.set(g,s(g))});let u=new Set([...l.values()].flat()),c=h=>{for(let[g,p]of l)if(p.includes(h))return g;return h},f=[];e.edges().forEach(h=>{(u.has(h.v)||u.has(h.w))&&f.push({edge:h,label:e.edge(h)})});let b=new Map;u.forEach(h=>{let g=e.parent(h);b.set(h,typeof g=="string"?g:void 0)}),l.forEach((h,g)=>{let p=e.node(g),w=[];h.forEach(G=>{let _=e.node(G);_&&(w.push({id:G,node:_,parent:b.get(G)}),e.removeNode(G))});let v=f.filter(({edge:G})=>h.includes(G.v)||h.includes(G.w)),N=o[g];p&&(i.push({clusterId:g,subgraph:p._dagreClusterSubgraph,bounds:N,children:h,removedNodes:w,removedEdges:v}),p.width=N.width,p.height=N.height)});let m=new Set;f.forEach(({edge:h,label:g})=>{let p=c(h.v),w=c(h.w);if(p!==w&&e.hasNode(p)&&e.hasNode(w)){let v=`${p}\0${w}`;m.has(v)||(m.add(v),e.setEdge(p,w,{...g,width:0,height:0}))}});let E=jn(e);Cn(E,n,t),Tn(e,E),m.forEach(h=>{let g=h.indexOf("\0"),p=h.slice(0,g),w=h.slice(g+1);e.hasEdge(p,w)&&e.removeEdge(p,w)}),i.forEach(({clusterId:h,subgraph:g,bounds:p,removedNodes:w,removedEdges:v})=>{var j,R;let N=e.node(h),G=(j=N==null?void 0:N.x)!=null?j:0,_=(R=N==null?void 0:N.y)!=null?R:0,C=(p.minX+p.maxX)/2,T=(p.minY+p.maxY)/2;w.forEach(({id:y,node:L,parent:k})=>{e.setNode(y,L),k!==void 0&&e.setParent(y,k)}),v.forEach(({edge:y,label:L})=>{e.setEdge(y,L)}),g.nodes().forEach(y=>{if(y===h)return;let L=g.node(y),k=e.node(y);k&&L&&typeof L.x=="number"&&typeof L.y=="number"&&(k.x=G+(L.x-C),k.y=_+(L.y-T))}),delete N._dagreClusterSubgraph}),r.forEach(h=>{var w,v;let g=e.node(h),p=o[h];if(g&&g.rankdir&&g._dagreClusterSubgraph&&p){let N=g._dagreClusterSubgraph,G=(w=g.x)!=null?w:0,_=(v=g.y)!=null?v:0,C=(p.minX+p.maxX)/2,T=(p.minY+p.maxY)/2;N.nodes().forEach(j=>{if(j===h)return;let R=N.node(j),y=e.node(j);if(y&&R&&typeof R.x=="number"&&typeof R.y=="number"){let L=R.x-C,k=R.y-T;y.x=G+L,y.y=_+k}}),delete g._dagreClusterSubgraph}})}function Cn(e,n,t){(t==null?void 0:t.useDynamic)===!1&&(ke=null,xe=null),n(" makeSpaceForEdgeLabels",()=>hr(e)),n(" removeSelfEdges",()=>Gr(e)),n(" acyclic",()=>Ke(e,ke)),n(" nestingGraph.run",()=>fn(e)),n(" rank",()=>un(K(e))),n(" injectEdgeLabelProxies",()=>gr(e)),n(" removeEmptyRanks",()=>ze(e)),n(" nestingGraph.cleanup",()=>hn(e)),n(" normalizeRanks",()=>Xe(e)),n(" assignRankMinMax",()=>pr(e)),n(" removeEdgeLabelProxies",()=>mr(e)),n(" normalize.run",()=>Ze(e)),n(" parentDummyChains",()=>cn(e)),n(" addBorderSegments",()=>pn(e)),n(" order",()=>ne(e,t,xe)),n(" insertSelfEdges",()=>vr(e)),n(" adjustCoordinateSystem",()=>En(e)),n(" position",()=>_n(e,t.corePath)),n(" positionSelfEdges",()=>kr(e)),xe=JSON.parse(JSON.stringify(e._nodes)),n(" removeBorderNodes",()=>Nr(e)),n(" normalize.undo",()=>en(e)),n(" fixupEdgeLabelCoords",()=>yr(e)),n(" undoCoordinateSystem",()=>Ln(e)),n(" translateGraph",()=>Er(e)),n(" assignNodeIntersects",()=>Lr(e)),n(" reversePoints",()=>wr(e)),n(" acyclic.undo",()=>Qe(e)),ke=e}function Tn(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 ar=["nodesep","edgesep","ranksep","marginx","marginy"],dr={ranksep:50,edgesep:20,nodesep:50,rankdir:"TB",rankalign:"center"},lr=["acyclicer","ranker","rankdir","align","rankalign"],ur=["width","height","rank"],Rn={width:0,height:0},cr=["minlen","weight","width","height","labeloffset"],fr={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},br=["labelpos"];function jn(e){let n=new x({multigraph:!0,compound:!0}),t=Oe(e.graph());return n.setGraph(Object.assign({},dr,_e(t,ar),Y(t,lr))),e.nodes().forEach(r=>{let o=Oe(e.node(r)),i=_e(o,ur);Object.keys(Rn).forEach(a=>{i[a]===void 0&&(i[a]=Rn[a])}),n.setNode(r,i);let s=e.parent(r);s!==void 0&&n.setParent(r,s)}),e.edges().forEach(r=>{let o=Oe(e.edge(r));n.setEdge(r,Object.assign({},fr,_e(o,cr),Y(o,br)))}),n}function hr(e){let n=e.graph();n.ranksep/=2,e.edges().forEach(t=>{var o;let r=e.edge(t);r.minlen*=2,((o=r.labelpos)!=null?o:"r").toLowerCase()!=="c"&&(n.rankdir==="TB"||n.rankdir==="BT"?r.width+=r.labeloffset:r.height+=r.labeloffset)})}function gr(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};I(e,"edge-proxy",i,"_ep")}})}function pr(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 mr(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 Er(e){let n=Number.POSITIVE_INFINITY,t=0,r=Number.POSITIVE_INFINITY,o=0,i=e.graph(),s=i.marginx||0,a=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-=s,r-=a,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+s,i.height=o-r+a}function Lr(e){e.edges().forEach(n=>{if(n.v===n.w)return;let t=e.edge(n),r=e.node(n.v),o=e.node(n.w),i,s;t.points?(i=t.points[0],s=t.points[t.points.length-1]):(t.points=[],i=o,s=r),t.points.unshift(ie(r,i)),t.points.push(ie(o,s))})}function yr(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 wr(e){e.edges().forEach(n=>{let t=e.edge(n);t.reversed&&t.points.reverse()})}function Nr(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]),s=e.node(t.borderRight[t.borderRight.length-1]);t.width=Math.abs(s.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 Gr(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 vr(e){S(e).forEach(t=>{let r=0;t.forEach((o,i)=>{let s=e.node(o);typeof s.rank!="number"&&(s.rank=0),s.order=i+r,(s.selfEdges||[]).forEach(a=>{I(e,"selfedge",{width:a.label.width,height:a.label.height,rank:s.rank,order:i+ ++r,e:a.e,edgeLabel:a.label},"_se"),(!Array.isArray(a.label.points)||a.label.points.length!==7)&&(a.label.points=[{x:0,y:-10},{x:0,y:-10},{x:0,y:0},{x:0,y:10},{x:0,y:10},{x:0,y:0},{x:0,y:0}])}),delete s.selfEdges})})}function kr(e){e.nodes().forEach(n=>{let t=e.node(n),r=o=>typeof o=="number"&&isFinite(o);if(t.dummy==="selfedge"){let o=t,i=e.node(o.e.v),s=r(i==null?void 0:i.x)?i.x:0,a=r(i==null?void 0:i.y)?i.y:0,d=r(i==null?void 0:i.width)?i.width:0,l=r(i==null?void 0:i.height)?i.height:0,u=r(t.x)?t.x:s,c=r(t.y)?t.y:a,f=d/2,b=l/2;o.edgeLabel.points=[{x:u+f,y:c-b},{x:u+f,y:c-b},{x:u,y:c},{x:u-f,y:c+b},{x:u-f,y:c+b},{x:u,y:c},{x:u,y:c}],o.edgeLabel.x=u,o.edgeLabel.y=c,e.setEdge(o.e,o.edgeLabel),e.removeNode(n)}else t&&Array.isArray(t.selfEdges)&&t.selfEdges.forEach(o=>{if(!Array.isArray(o.label.points)||o.label.points.length!==7){let i=r(t.x)?t.x:0,s=r(t.y)?t.y:0,a=r(t.width)?t.width:0,d=r(t.height)?t.height:0,l=a/2,u=d/2;o.label.points=[{x:i+l,y:s-u},{x:i+l,y:s-u},{x:i,y:s},{x:i-l,y:s+u},{x:i-l,y:s+u},{x:i,y:s},{x:i,y:s}]}})})}function _e(e,n){return W(Y(e,n),Number)}function Oe(e){let n={};return e&&Object.entries(e).forEach(([t,r])=>{typeof t=="string"&&(t=t.toLowerCase()),n[t]=r}),n}function Te(e){let n=S(e),t=new x({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((s,a)=>(t.setEdge(s,a,{style:"invis"}),a))}),t}var $o={time:de,notime:z},xr={graphlib:oe,version:le,layout:Ce,debug:Te,util:{time:de,notime:z}},Uo=xr;export{x as Graph,Te as debug,Uo as default,oe as graphlib,Ce as layout,$o as util,le as version};
|
|
1
|
+
var Te=Object.defineProperty;var In=(e,n,t)=>n in e?Te(e,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[n]=t;var Sn=(e,n)=>{for(var t in n)Te(e,t,{get:n[t],enumerable:!0})};var je=(e,n,t)=>In(e,typeof n!="symbol"?n+"":n,t);var ie={};Sn(ie,{Graph:()=>T,alg:()=>H});var Mn=Object.defineProperty,Se=(e,n)=>{for(var t in n)Mn(e,t,{get:n[t],enumerable:!0})},Q=class{constructor(e){this._isDirected=!0,this._isMultigraph=!1,this._isCompound=!1,this._nodes={},this._in={},this._preds={},this._out={},this._sucs={},this._edgeObjs={},this._edgeLabels={},this._nodeCount=0,this._edgeCount=0,this._defaultNodeLabelFn=()=>{},this._defaultEdgeLabelFn=()=>{},e&&(this._isDirected="directed"in e?e.directed:!0,this._isMultigraph="multigraph"in e?e.multigraph:!1,this._isCompound="compound"in e?e.compound:!1),this._isCompound&&(this._parent={},this._children={},this._children["\0"]={})}isDirected(){return this._isDirected}isMultigraph(){return this._isMultigraph}isCompound(){return this._isCompound}setGraph(e){return this._label=e,this}graph(){return this._label}setDefaultNodeLabel(e){return typeof e!="function"?this._defaultNodeLabelFn=()=>e:this._defaultNodeLabelFn=e,this}nodeCount(){return this._nodeCount}nodes(){return Object.keys(this._nodes)}sources(){return this.nodes().filter(e=>Object.keys(this._in[e]).length===0)}sinks(){return this.nodes().filter(e=>Object.keys(this._out[e]).length===0)}setNodes(e,n){return e.forEach(t=>{n!==void 0?this.setNode(t,n):this.setNode(t)}),this}setNode(e,n){return e in this._nodes?(arguments.length>1&&(this._nodes[e]=n),this):(this._nodes[e]=arguments.length>1?n:this._defaultNodeLabelFn(e),this._isCompound&&(this._parent[e]="\0",this._children[e]={},this._children["\0"][e]=!0),this._in[e]={},this._preds[e]={},this._out[e]={},this._sucs[e]={},++this._nodeCount,this)}node(e){return this._nodes[e]}hasNode(e){return e in this._nodes}removeNode(e){if(e in this._nodes){let n=t=>this.removeEdge(this._edgeObjs[t]);delete this._nodes[e],this._isCompound&&(this._removeFromParentsChildList(e),delete this._parent[e],this.children(e).forEach(t=>{this.setParent(t)}),delete this._children[e]),Object.keys(this._in[e]).forEach(n),delete this._in[e],delete this._preds[e],Object.keys(this._out[e]).forEach(n),delete this._out[e],delete this._sucs[e],--this._nodeCount}return this}setParent(e,n){if(!this._isCompound)throw new Error("Cannot set parent in a non-compound graph");if(n===void 0)n="\0";else{n+="";for(let t=n;t!==void 0;t=this.parent(t))if(t===e)throw new Error("Setting "+n+" as parent of "+e+" would create a cycle");this.setNode(n)}return this.setNode(e),this._removeFromParentsChildList(e),this._parent[e]=n,this._children[n][e]=!0,this}parent(e){if(this._isCompound){let n=this._parent[e];if(n!=="\0")return n}}children(e="\0"){if(this._isCompound){let n=this._children[e];if(n)return Object.keys(n)}else{if(e==="\0")return this.nodes();if(this.hasNode(e))return[]}return[]}predecessors(e){let n=this._preds[e];if(n)return Object.keys(n)}successors(e){let n=this._sucs[e];if(n)return Object.keys(n)}neighbors(e){let n=this.predecessors(e);if(n){let t=new Set(n),r=this.successors(e);if(r)for(let o of r)t.add(o);return Array.from(t.values())}}isLeaf(e){var n;let t;return this.isDirected()?t=this.successors(e):t=this.neighbors(e),((n=t==null?void 0:t.length)!=null?n:0)===0}filterNodes(e){let n=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});n.setGraph(this.graph()),Object.entries(this._nodes).forEach(([o,i])=>{e(o)&&n.setNode(o,i)}),Object.values(this._edgeObjs).forEach(o=>{n.hasNode(o.v)&&n.hasNode(o.w)&&n.setEdge(o,this.edge(o))});let t={},r=o=>{let i=this.parent(o);return!i||n.hasNode(i)?(t[o]=i,i):i in t?t[i]:r(i)};return this._isCompound&&n.nodes().forEach(o=>n.setParent(o,r(o))),n}setDefaultEdgeLabel(e){return typeof e!="function"?this._defaultEdgeLabelFn=()=>e:this._defaultEdgeLabelFn=e,this}edgeCount(){return this._edgeCount}edges(){return Object.values(this._edgeObjs)}setPath(e,n){return e.reduce((t,r)=>(n!==void 0?this.setEdge(t,r,n):this.setEdge(t,r),r)),this}setEdge(e,n,t,r){let o,i,s,a,l=!1;typeof e=="object"&&e!==null&&"v"in e?(o=e.v,i=e.w,s=e.name,arguments.length===2&&(a=n,l=!0)):(o=e,i=n,s=r,arguments.length>2&&(a=t,l=!0)),o=""+o,i=""+i,s!==void 0&&(s=""+s);let u=z(this._isDirected,o,i,s);if(u in this._edgeLabels)return l&&(this._edgeLabels[u]=a),this;if(s!==void 0&&!this._isMultigraph)throw new Error("Cannot set a named edge when isMultigraph = false");this.setNode(o),this.setNode(i),this._edgeLabels[u]=l?a:this._defaultEdgeLabelFn(o,i,s);let d=Pn(this._isDirected,o,i,s);return o=d.v,i=d.w,Object.freeze(d),this._edgeObjs[u]=d,Re(this._preds[i],o),Re(this._sucs[o],i),this._in[i][u]=d,this._out[o][u]=d,this._edgeCount++,this}edge(e,n,t){let r=arguments.length===1?oe(this._isDirected,e):z(this._isDirected,e,n,t);return this._edgeLabels[r]}edgeAsObj(e,n,t){let r=arguments.length===1?this.edge(e):this.edge(e,n,t);return typeof r!="object"||r===null?{label:r}:r}hasEdge(e,n,t){return(arguments.length===1?oe(this._isDirected,e):z(this._isDirected,e,n,t))in this._edgeLabels}removeEdge(e,n,t){let r=arguments.length===1?oe(this._isDirected,e):z(this._isDirected,e,n,t),o=this._edgeObjs[r];if(o){let i=o.v,s=o.w;delete this._edgeLabels[r],delete this._edgeObjs[r],Ie(this._preds[s],i),Ie(this._sucs[i],s),delete this._in[s][r],delete this._out[i][r],this._edgeCount--}return this}inEdges(e,n){return this.isDirected()?this.filterEdges(this._in[e],e,n):this.nodeEdges(e,n)}outEdges(e,n){return this.isDirected()?this.filterEdges(this._out[e],e,n):this.nodeEdges(e,n)}nodeEdges(e,n){if(e in this._nodes)return this.filterEdges({...this._in[e],...this._out[e]},e,n)}_removeFromParentsChildList(e){delete this._children[this._parent[e]][e]}filterEdges(e,n,t){if(!e)return;let r=Object.values(e);return t?r.filter(o=>o.v===n&&o.w===t||o.v===t&&o.w===n):r}};function Re(e,n){e[n]?e[n]++:e[n]=1}function Ie(e,n){e[n]!==void 0&&!--e[n]&&delete e[n]}function z(e,n,t,r){let o=""+n,i=""+t;if(!e&&o>i){let s=o;o=i,i=s}return o+""+i+""+(r===void 0?"\0":r)}function Pn(e,n,t,r){let o=""+n,i=""+t;if(!e&&o>i){let a=o;o=i,i=a}let s={v:o,w:i};return r&&(s.name=r),s}function oe(e,n){return z(e,n.v,n.w,n.name)}var Fn={};Se(Fn,{read:()=>Yn,write:()=>An});function An(e){let n={options:{directed:e.isDirected(),multigraph:e.isMultigraph(),compound:e.isCompound()},nodes:Vn(e),edges:Dn(e)},t=e.graph();return t!==void 0&&(n.value=structuredClone(t)),n}function Vn(e){return e.nodes().map(n=>{let t=e.node(n),r=e.parent(n),o={v:n};return t!==void 0&&(o.value=t),r!==void 0&&(o.parent=r),o})}function Dn(e){return e.edges().map(n=>{let t=e.edge(n),r={v:n.v,w:n.w};return n.name!==void 0&&(r.name=n.name),t!==void 0&&(r.value=t),r})}function Yn(e){let n=new Q(e.options);return e.value!==void 0&&n.setGraph(e.value),e.nodes.forEach(t=>{n.setNode(t.v,t.value),t.parent&&n.setParent(t.v,t.parent)}),e.edges.forEach(t=>{n.setEdge({v:t.v,w:t.w,name:t.name},t.value)}),n}var H={};Se(H,{CycleException:()=>K,bellmanFord:()=>Me,components:()=>Xn,dijkstra:()=>J,dijkstraAll:()=>qn,findCycles:()=>$n,floydWarshall:()=>Jn,isAcyclic:()=>Qn,postorder:()=>et,preorder:()=>nt,prim:()=>tt,shortestPaths:()=>rt,tarjan:()=>Fe,topsort:()=>Ae});var Wn=()=>1;function Me(e,n,t,r){return Bn(e,String(n),t||Wn,r||function(o){var i;return(i=e.outEdges(o))!=null?i:[]})}function Bn(e,n,t,r){let o={},i,s=0,a=e.nodes(),l=function(c){let f=o[c.v],h=o[c.w];if(!f||!h)return;let p=t(c);f.distance+p<h.distance&&(o[c.w]={distance:f.distance+p,predecessor:c.v},i=!0)},u=function(){a.forEach(function(c){r(c).forEach(function(f){let h=f.v===c?f.v:f.w,p=h===f.v?f.w:f.v;l({v:h,w:p})})})};a.forEach(function(c){let f=c===n?0:Number.POSITIVE_INFINITY;o[c]={distance:f,predecessor:""}});let d=a.length;for(let c=1;c<d&&(i=!1,s++,u(),!!i);c++);if(s===d-1&&(i=!1,u(),i))throw new Error("The graph contains a negative weight cycle");return o}function Xn(e){let n={},t=[],r;function o(i){var s,a;i in n||(n[i]=!0,r.push(i),(s=e.successors(i))==null||s.forEach(o),(a=e.predecessors(i))==null||a.forEach(o))}return e.nodes().forEach(function(i){r=[],o(i),r.length&&t.push(r)}),t}var Pe=class{constructor(){this._arr=[],this._keyIndices={}}size(){return this._arr.length}keys(){return this._arr.map(e=>e.key)}has(e){return e in this._keyIndices}priority(e){let n=this._keyIndices[e];if(n!==void 0)return this._arr[n].priority}min(){if(this.size()===0)throw new Error("Queue underflow");return this._arr[0].key}add(e,n){let t=this._keyIndices,r=String(e);if(!(r in t)){let o=this._arr,i=o.length;return t[r]=i,o.push({key:r,priority:n}),this._decrease(i),!0}return!1}removeMin(){if(this.size()===0)throw new Error("Queue underflow");this._swap(0,this._arr.length-1);let e=this._arr.pop();return delete this._keyIndices[e.key],this._heapify(0),e.key}decrease(e,n){let t=this._keyIndices[e];if(t===void 0)throw new Error(`Key not found: ${e}`);let r=this._arr[t].priority;if(n>r)throw new Error(`New priority is greater than current priority. Key: ${e} Old: ${r} New: ${n}`);this._arr[t].priority=n,this._decrease(t)}_heapify(e){let n=this._arr,t=2*e,r=t+1,o=e;t<n.length&&(o=n[t].priority<n[o].priority?t:o,r<n.length&&(o=n[r].priority<n[o].priority?r:o),o!==e&&(this._swap(e,o),this._heapify(o)))}_decrease(e){let n=this._arr,t=n[e].priority,r;for(;e!==0&&(r=e>>1,!(n[r].priority<t));)this._swap(e,r),e=r}_swap(e,n){let t=this._arr,r=this._keyIndices,o=t[e],i=t[n];t[e]=i,t[n]=o,r[i.key]=e,r[o.key]=n}},zn=()=>1;function J(e,n,t,r){let o=function(i){var s;return(s=e.outEdges(i))!=null?s:[]};return Hn(e,String(n),t||zn,r||o)}function Hn(e,n,t,r){let o={},i=new Pe,s,a,l=function(u){let d=u.v!==s?u.v:u.w,c=o[d];if(!c)return;let f=t(u),h=a.distance+f;if(f<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+u+" Weight: "+f);h<c.distance&&(c.distance=h,c.predecessor=s,i.decrease(d,h))};for(e.nodes().forEach(function(u){let d=u===n?0:Number.POSITIVE_INFINITY;o[u]={distance:d,predecessor:""},i.add(u,d)});i.size()>0;){s=i.removeMin();let u=o[s];if(!u||u.distance===Number.POSITIVE_INFINITY)break;a=u,r(s).forEach(l)}return o}function qn(e,n,t){return e.nodes().reduce(function(r,o){return r[o]=J(e,o,n,t),r},{})}function Fe(e){let n=0,t=[],r={},o=[];function i(s){var a;let l=r[s]={onStack:!0,lowlink:n,index:n++};if(t.push(s),(a=e.successors(s))==null||a.forEach(function(u){if(u in r){let d=r[u];d!=null&&d.onStack&&(l.lowlink=Math.min(l.lowlink,d.index))}else{i(u);let d=r[u];d&&(l.lowlink=Math.min(l.lowlink,d.lowlink))}}),l.lowlink===l.index){let u=[],d;do{d=t.pop();let c=r[d];c&&(c.onStack=!1),u.push(d)}while(s!==d);o.push(u)}}return e.nodes().forEach(function(s){s in r||i(s)}),o}function $n(e){return Fe(e).filter(function(n){var t;let r=n[0];return r?n.length>1||n.length===1&&((t=e.outEdges(r,r))!=null?t:[]).length>0:!1})}var Un=()=>1;function Jn(e,n,t){return Kn(e,n||Un,t||function(r){var o;return(o=e.outEdges(r))!=null?o:[]})}function Kn(e,n,t){let r={},o=e.nodes();return o.forEach(function(i){let s={};r[i]=s,s[i]={distance:0,predecessor:""},o.forEach(function(a){i!==a&&(s[a]={distance:Number.POSITIVE_INFINITY,predecessor:""})}),t(i).forEach(function(a){let l=a.v===i?a.w:a.v,u=n(a);s[l]={distance:u,predecessor:i}})}),o.forEach(function(i){let s=r[i];s&&o.forEach(function(a){let l=r[a];l&&o.forEach(function(u){let d=l[i],c=s[u],f=l[u];if(d&&c&&f){let h=d.distance+c.distance;h<f.distance&&(f.distance=h,f.predecessor=c.predecessor)}})})}),r}var K=class extends Error{constructor(e){super(e),this.name="CycleException"}};function Ae(e){let n={},t={},r=[];function o(i){var s;if(i in t)throw new K;i in n||(t[i]=!0,n[i]=!0,(s=e.predecessors(i))==null||s.forEach(o),delete t[i],r.push(i))}if(e.sinks().forEach(o),Object.keys(n).length!==e.nodeCount())throw new K;return r}function Qn(e){try{Ae(e)}catch(n){if(n instanceof K)return!1;throw n}return!0}function Zn(e,n,t,r,o){Array.isArray(n)||(n=[n]);let i=(a=>{var l;return(l=e.isDirected()?e.successors(a):e.neighbors(a))!=null?l:[]}),s={};return n.forEach(function(a){if(!e.hasNode(a))throw new Error("Graph does not have node: "+a);o=Ve(e,a,t==="post",s,i,r,o)}),o}function Ve(e,n,t,r,o,i,s){return n in r||(r[n]=!0,t||(s=i(s,n)),o(n).forEach(function(a){s=Ve(e,a,t,r,o,i,s)}),t&&(s=i(s,n))),s}function De(e,n,t){return Zn(e,n,t,function(r,o){return r.push(o),r},[])}function et(e,n){return De(e,n,"post")}function nt(e,n){return De(e,n,"pre")}function tt(e,n){var t;let r=new Q,o={},i=new Pe,s;function a(d){let c=d.v===s?d.w:d.v,f=i.priority(c);if(f!==void 0){let h=n(d);h<f&&(o[c]=s,i.decrease(c,h))}}if(e.nodeCount()===0)return r;e.nodes().forEach(function(d){i.add(d,Number.POSITIVE_INFINITY),r.setNode(d)});let l=e.nodes()[0];l!==void 0&&i.decrease(l,0);let u=!1;for(;i.size()>0;){if(s=i.removeMin(),s in o)r.setEdge(s,o[s]);else{if(u)throw new Error("Input graph is not connected: "+e);u=!0}(t=e.nodeEdges(s))==null||t.forEach(a)}return r}function rt(e,n,t,r){return ot(e,n,t,r!=null?r:(o=>{var i;return(i=e.outEdges(o))!=null?i:[]}))}function ot(e,n,t,r){if(t===void 0)return J(e,n,t,r);let o=!1,i=e.nodes();for(let s=0;s<i.length;s++){let a=i[s];if(a===void 0)continue;let l=r(a);for(let u=0;u<l.length;u++){let d=l[u];if(!d)continue;let c=d.v===a?d.v:d.w,f=c===d.v?d.w:d.v;t({v:c,w:f})<0&&(o=!0)}if(o)return Me(e,n,t,r)}return J(e,n,t,r)}var T=Q;function M(e,n,t,r){let o=r;for(;e.hasNode(o);)o=$(r);return t.dummy=n,e.setNode(o,t),o}function Ye(e){let n=new T().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 Z(e){let n=new T({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 se(e,n){let t=e.x,r=e.y,o=n.x-t,i=n.y-r,s=e.width/2,a=e.height/2;if(!o&&!i)throw new Error("Not possible to find intersection inside of the rectangle");let l,u;return Math.abs(i)*s>Math.abs(o)*a?(i<0&&(a=-a),l=a*o/i,u=a):(o<0&&(s=-s),l=s,u=s*i/o),{x:t+l,y:r+u}}function P(e){let n=A(de(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 We(e){let n=e.nodes().map(r=>{let o=e.node(r).rank;return o===void 0?Number.MAX_VALUE:o}),t=R(Math.min,n);e.nodes().forEach(r=>{let o=e.node(r);Object.hasOwn(o,"rank")&&(o.rank-=t)})}function Be(e){let n=e.nodes().map(s=>e.node(s).rank).filter(s=>s!==void 0),t=R(Math.min,n),r=[];e.nodes().forEach(s=>{let a=e.node(s).rank-t;r[a]||(r[a]=[]),r[a].push(s)});let o=0,i=e.graph().nodeRankFactor;Array.from(r).forEach((s,a)=>{s===void 0&&a%i!==0?--o:s!==void 0&&o&&s.forEach(l=>e.node(l).rank+=o)})}function ae(e,n,t,r){let o={width:0,height:0};return arguments.length>=4&&(o.rank=t,o.order=r),M(e,"border",o,n)}function it(e,n=Xe){let t=[];for(let r=0;r<e.length;r+=n){let o=e.slice(r,r+n);t.push(o)}return t}var Xe=65535;function R(e,n){if(n.length>Xe){let t=it(n);return e(...t.map(r=>e(...r)))}else return e(...n)}function de(e){let t=e.nodes().map(r=>{let o=e.node(r).rank;return o===void 0?Number.MIN_VALUE:o});return R(Math.max,t)}function ze(e,n){let t={lhs:[],rhs:[]};return e.forEach(r=>{n(r)?t.lhs.push(r):t.rhs.push(r)}),t}function le(e,n){let t=Date.now();try{return n()}finally{console.log(e+" time: "+(Date.now()-t)+"ms")}}function q(e,n){return n()}var st=0;function $(e){let n=++st;return e+(""+n)}function A(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 B(e,n){let t={};for(let r of n)e[r]!==void 0&&(t[r]=e[r]);return t}function X(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 He(e,n){return e.reduce((t,r,o)=>(t[r]=n[o],t),{})}var D="\0";function ee(e,n,t){var u,d,c,f,h,p;if(!(e&&n&&t&&n.dummy==="edge"&&t.dummy==="edge"&&n.edgeObj&&t.edgeObj&&e[n.edgeObj.v]&&e[t.edgeObj.v]&&e[n.edgeObj.w]&&e[t.edgeObj.w]))return 0;let r=!0;n.edgeObj.w===t.edgeObj.w&&(r=!1);let o=r?(d=(u=e[n.edgeObj.v])==null?void 0:u.rank)!=null?d:NaN+1:(f=(c=e[n.edgeObj.w])==null?void 0:c.rank)!=null?f:NaN-1,i=Object.entries(e).find(E=>{var y,L;return((y=E[1].edgeObj)==null?void 0:y.v)===n.edgeObj.v&&((L=E[1].edgeObj)==null?void 0:L.w)===n.edgeObj.w&&E[1].rank===o}),s=Object.entries(e).find(E=>{var y,L;return((y=E[1].edgeObj)==null?void 0:y.v)===t.edgeObj.v&&((L=E[1].edgeObj)==null?void 0:L.w)===t.edgeObj.w&&E[1].rank===o});if(!i||!s)return 0;let a=(h=i[1].order)!=null?h:NaN,l=(p=s[1].order)!=null?p:NaN;return isNaN(a-l)?0:a-l}var ue="3.1.1";var ce=class{constructor(){je(this,"_sentinel");let n={};n._next=n._prev=n,this._sentinel=n}dequeue(){let n=this._sentinel,t=n._prev;if(t!==n)return qe(t),t}enqueue(n){let t=this._sentinel;n._prev&&n._next&&qe(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,at)),r=r._prev;return"["+n.join(", ")+"]"}};function qe(e){e._prev._next=e._next,e._next._prev=e._prev,delete e._next,delete e._prev}function at(e,n){if(e!=="_next"&&e!=="_prev")return n}var $e=ce;var dt=()=>1;function be(e,n){if(e.nodeCount()<=1)return[];let t=ut(e,n||dt);return lt(t.graph,t.buckets,t.zeroIdx).flatMap(o=>e.outEdges(o.v,o.w)||[])}function lt(e,n,t){var a;let r=[],o=n[n.length-1],i=n[0],s;for(;e.nodeCount();){for(;s=i.dequeue();)fe(e,n,t,s);for(;s=o.dequeue();)fe(e,n,t,s);if(e.nodeCount()){for(let l=n.length-2;l>0;--l)if(s=(a=n[l])==null?void 0:a.dequeue(),s){r=r.concat(fe(e,n,t,s,!0)||[]);break}}}return r}function fe(e,n,t,r,o){let i=[],s=o?i:void 0;return(e.inEdges(r.v)||[]).forEach(a=>{let l=e.edge(a),u=e.node(a.v);o&&i.push({v:a.v,w:a.w}),u.out-=l,he(n,t,u)}),(e.outEdges(r.v)||[]).forEach(a=>{let l=e.edge(a),u=a.w,d=e.node(u);d.in-=l,he(n,t,d)}),e.removeNode(r.v),s}function ut(e,n){let t=new T,r=0,o=0;e.nodes().forEach(a=>{t.setNode(a,{v:a,in:0,out:0})}),e.edges().forEach(a=>{let l=t.edge(a.v,a.w)||0,u=n(a),d=l+u;t.setEdge(a.v,a.w,d);let c=t.node(a.v),f=t.node(a.w);o=Math.max(o,c.out+=u),r=Math.max(r,f.in+=u)});let i=ct(o+r+3).map(()=>new $e),s=r+1;return t.nodes().forEach(a=>{he(i,s,t.node(a))}),{graph:t,buckets:i,zeroIdx:s}}function he(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 ct(e){let n=[];for(let t=0;t<e;t++)n.push(t);return n}function Ue(e,n){(e.graph().acyclicer==="greedy"?be(e,r(e)):ft(e,n!=null?n:null)).forEach(o=>{let i=e.edge(o);e.removeEdge(o),i.forwardName=o.name,i.reversed=!0,e.setEdge(o.w,o.v,i,$("rev"))});function r(o){return i=>o.edge(i).weight}}function ft(e,n){let t=[],r={},o={};function i(l){Object.hasOwn(o,l)||(o[l]=!0,r[l]=!0,e.outEdges(l).forEach(u=>{Object.hasOwn(r,u.w)?t.push(u):i(u.w)}),delete r[l])}function s(l){var u;Object.hasOwn(o,l)||(o[l]=!0,r[l]=!0,(u=e.outEdges(l))==null||u.forEach(d=>{var c,f;Object.hasOwn(r,d.w)||((c=n.node(l))==null?void 0:c.rank)>((f=n.node(d.w))==null?void 0:f.rank)&&ht(e,d.w,d)?t.push(d):s(d.w)}),delete r[l])}let a=i;return n&&typeof n.node=="function"&&(a=s),e.sources().forEach(a),e.nodes().forEach(a),t}function Je(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 ht(e,n,t){let r=new Set;function o(i){var s;if(e.sources().includes(i))return!0;r.add(i);for(let a of(s=e.inEdges(i))!=null?s:[])if(!(a.v===t.v&&a.w===t.w)&&!r.has(a.v)&&o(a.v))return!0;return!1}return o(n)}function Ke(e){e.graph().dummyChains=[],e.edges().forEach(n=>gt(e,n))}function gt(e,n){let t=n.v,r=e.node(t).rank,o=n.w,i=e.node(o).rank,s=n.name,a=e.edge(n),l=a.labelRank;if(i===r+1)return;e.removeEdge(n);let u,d,c;for(c=0,++r;r<i;++c,++r)a.points=[],d={width:0,height:0,edgeLabel:a,edgeObj:n,rank:r},u=M(e,"edge",d,"_d"),r===l&&(d.width=a.width,d.height=a.height,d.dummy="edge-label",d.labelpos=a.labelpos),e.setEdge(t,u,{weight:a.weight},s),c===0&&e.graph().dummyChains.push(u),t=u;e.setEdge(t,o,{weight:a.weight},s)}function Qe(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 U(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),s=i?i.map(l=>l==null?Number.POSITIVE_INFINITY:t(l.w)-e.edge(l).minlen):[],a=R(Math.min,s);return a===Number.POSITIVE_INFINITY&&(a=0),o.rank=a}e.sources().forEach(t)}function V(e,n){return e.node(n.w).rank-e.node(n.v).rank-e.edge(n).minlen}var ne=mt;function mt(e){let n=new T({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,s;for(;Et(n,e)<o&&(i=Lt(n,e),!!i);)s=n.hasNode(i.v)?V(e,i):-V(e,i),yt(n,e,s);return n}function Et(e,n){function t(r){let o=n.nodeEdges(r);o&&o.forEach(i=>{let s=i.v,a=r===s?i.w:s;!e.hasNode(a)&&!V(n,i)&&(e.setNode(a,{}),e.setEdge(r,a,{}),t(a))})}return e.nodes().forEach(t),e.nodeCount()}function Lt(e,n){return n.edges().reduce((r,o)=>{let i=Number.POSITIVE_INFINITY;return e.hasNode(o.v)!==e.hasNode(o.w)&&(i=V(n,o)),i<r[0]?[i,o]:r},[Number.POSITIVE_INFINITY,null])[1]}function yt(e,n,t){e.nodes().forEach(r=>n.node(r).rank+=t)}var{preorder:wt,postorder:Nt}=H,en=Y;Y.initLowLimValues=pe;Y.initCutValues=ge;Y.calcCutValue=nn;Y.leaveEdge=rn;Y.enterEdge=on;Y.exchangeEdges=sn;function Y(e){e=Ye(e),U(e);let n=ne(e);pe(n),ge(n,e);let t,r;for(;t=rn(n);)r=on(n,e,t),sn(n,e,t,r)}function ge(e,n){let t=Nt(e,e.nodes());t=t.slice(0,t.length-1),t.forEach(r=>Gt(e,n,r))}function Gt(e,n,t){let o=e.node(t).parent,i=e.edge(t,o);i.cutvalue=nn(e,n,t)}function nn(e,n,t){let o=e.node(t).parent,i=!0,s=n.edge(t,o),a=0;s||(i=!1,s=n.edge(o,t)),a=s.weight;let l=n.nodeEdges(t);return l&&l.forEach(u=>{let d=u.v===t,c=d?u.w:u.v;if(c!==o){let f=d===i,h=n.edge(u).weight;if(a+=f?h:-h,kt(e,t,c)){let E=e.edge(t,c).cutvalue;a+=f?-E:E}}}),a}function pe(e,n){arguments.length<2&&(n=e.nodes()[0]),tn(e,{},1,n)}function tn(e,n,t,r,o){let i=t,s=e.node(r);n[r]=!0;let a=e.neighbors(r);return a&&a.forEach(l=>{Object.hasOwn(n,l)||(t=tn(e,n,t,l,r))}),s.low=i,s.lim=t++,o?s.parent=o:delete s.parent,t}function rn(e){return e.edges().find(n=>e.edge(n).cutvalue<0)}function on(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),s=e.node(o),a=i,l=!1;return i.lim>s.lim&&(a=s,l=!0),n.edges().filter(d=>l===Ze(e,e.node(d.v),a)&&l!==Ze(e,e.node(d.w),a)).reduce((d,c)=>V(n,c)<V(n,d)?c:d)}function sn(e,n,t,r){let o=t.v,i=t.w;e.removeEdge(o,i),e.setEdge(r.v,r.w,{}),pe(e),ge(e,n),vt(e,n)}function vt(e,n){let t=e.nodes().find(o=>!e.node(o).parent);if(!t)return;let r=wt(e,[t]);r=r.slice(1),r.forEach(o=>{let s=e.node(o).parent,a=n.edge(o,s),l=!1;a||(a=n.edge(s,o),l=!0),n.node(o).rank=n.node(s).rank+(l?a.minlen:-a.minlen)})}function kt(e,n,t){return e.hasEdge(n,t)}function Ze(e,n,t){return t.low<=n.lim&&n.lim<=t.lim}var dn=xt;function xt(e){let n=e.graph().ranker;if(typeof n=="function")return n(e);switch(n){case"network-simplex":an(e);break;case"tight-tree":Ot(e);break;case"longest-path":_t(e);break;case"none":break;default:an(e)}}var _t=U;function Ot(e){U(e),ne(e)}function an(e){en(e)}var ln=Ct;function Ct(e){let n=jt(e),t=e.graph();if(!Array.isArray(t.dummyChains))return;t.dummyChains.forEach(o=>{let i=e.node(o),s=i.edgeObj,a=Tt(e,n,s.v,s.w),l=a.path,u=a.lca,d=0,c=l[d],f=!0;for(;o!==s.w;){if(i=e.node(o),f){for(;(c=l[d])!==u&&e.node(c).maxRank<i.rank;)d++;c===u&&(f=!1)}if(!f){for(;d<l.length-1&&e.node(l[d+1]).minRank<=i.rank;)d++;c=l[d]}c!==void 0&&e.setParent(o,c),o=e.successors(o)[0]}})}function Tt(e,n,t,r){let o=[],i=[],s=Math.min(n[t].low,n[r].low),a=Math.max(n[t].lim,n[r].lim),l;l=t;do l=e.parent(l),o.push(l);while(l&&(n[l].low>s||a>n[l].lim));let u=l,d=r;for(;(d=e.parent(d))!==u;)i.push(d);return{path:o.concat(i.reverse()),lca:u}}function jt(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(D).forEach(r),n}function un(e){let n=M(e,"root",{},"_root"),t=Rt(e),r=Object.values(t),o=R(Math.max,r)-1,i=2*o+1;e.graph().nestingRoot=n,e.edges().forEach(a=>e.edge(a).minlen*=i);let s=It(e)+1;e.children(D).forEach(a=>{cn(e,n,i,s,o,t,a)}),e.graph().nodeRankFactor=i}function cn(e,n,t,r,o,i,s){var c;let a=e.children(s);if(!a.length){s!==n&&e.setEdge(n,s,{weight:0,minlen:t});return}let l=ae(e,"_bt"),u=ae(e,"_bb"),d=e.node(s);e.setParent(l,s),d.borderTop=l,e.setParent(u,s),d.borderBottom=u,a.forEach(f=>{var b;cn(e,n,t,r,o,i,f);let h=e.node(f),p=h.borderTop?h.borderTop:f,E=h.borderBottom?h.borderBottom:f,y=h.borderTop?r:2*r,L=p!==E?1:o-((b=i[s])!=null?b:0)+1;e.setEdge(l,p,{weight:y,minlen:L,nestingEdge:!0}),e.setEdge(E,u,{weight:y,minlen:L,nestingEdge:!0})}),e.parent(s)||e.setEdge(n,l,{weight:0,minlen:o+((c=i[s])!=null?c:0)})}function Rt(e){let n={};function t(r,o){let i=e.children(r);i&&i.length&&i.forEach(s=>t(s,o+1)),n[r]=o}return e.children(D).forEach(r=>t(r,1)),n}function It(e){return e.edges().reduce((n,t)=>n+e.edge(t).weight,0)}function fn(e){let n=e.graph();e.removeNode(n.nestingRoot),delete n.nestingRoot,e.edges().forEach(t=>{e.edge(t).nestingEdge&&e.removeEdge(t)})}var bn=Mt;function Mt(e){function n(t){let r=e.children(t),o=e.node(t);if(r.length&&r.forEach(n),o&&Object.hasOwn(o,"minRank")){o.borderLeft=[],o.borderRight=[];for(let i=o.minRank,s=o.maxRank+1;i<s;++i)hn(e,"borderLeft","_bl",t,o,i),hn(e,"borderRight","_br",t,o,i)}}e.children(D).forEach(n)}function hn(e,n,t,r,o,i){let s={width:0,height:0,rank:i,borderType:n},a=o[n][i-1],l=M(e,"border",s,t);o[n][i]=l,e.setParent(l,r),a&&e.setEdge(a,l,{weight:1})}function pn(e){var t;let n=(t=e.graph().rankdir)==null?void 0:t.toLowerCase();(n==="lr"||n==="rl")&&En(e)}function mn(e){var t;let n=(t=e.graph().rankdir)==null?void 0:t.toLowerCase();(n==="bt"||n==="rl")&&Pt(e),(n==="lr"||n==="rl")&&(Ft(e),En(e))}function En(e){e.nodes().forEach(n=>gn(e.node(n))),e.edges().forEach(n=>gn(e.edge(n)))}function gn(e){let n=e.width;e.width=e.height,e.height=n}function Pt(e){e.nodes().forEach(n=>me(e.node(n))),e.edges().forEach(n=>{var r;let t=e.edge(n);(r=t.points)==null||r.forEach(me),Object.hasOwn(t,"y")&&me(t)})}function me(e){e.y=-e.y}function Ft(e){e.nodes().forEach(n=>Ee(e.node(n))),e.edges().forEach(n=>{var r;let t=e.edge(n);(r=t.points)==null||r.forEach(Ee),Object.hasOwn(t,"x")&&Ee(t)})}function Ee(e){let n=e.x;e.x=e.y,e.y=n}function Le(e,n=null){let t={},r=e.nodes().filter(d=>!e.children(d).length),o=r.map(d=>e.node(d).rank),i=R(Math.max,o),s=A(i+1).map(()=>[]);function a(d){if(t[d])return;t[d]=!0;let c=e.node(d);s[c.rank].push(d);let f=e.successors(d);f&&[...f].sort((p,E)=>u(p,E)).forEach(a)}r.sort((d,c)=>e.node(d).rank-e.node(c).rank).forEach(a);function u(d,c){let f=e.node(d),h=e.node(c);return ee(n,f,h)}return s}function ye(e,n){let t=0;for(let r=1;r<n.length;++r)t+=Vt(e,n[r-1],n[r]);return t}function Vt(e,n,t){let r=He(t,t.map((u,d)=>d)),o=n.flatMap(u=>{let d=e.outEdges(u);return d?d.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 s=2*i-1;i-=1;let a=new Array(s).fill(0),l=0;return o.forEach(u=>{let d=u.pos+i;a[d]+=u.weight;let c=0;for(;d>0;)d%2&&(c+=a[d+1]),d=d-1>>1,a[d]+=u.weight;l+=u.weight*c}),l}function we(e,n=[]){return n.map(t=>{let r=e.inEdges(t);if(!r||!r.length)return{v:t};{let o=r.reduce((i,s)=>{let a=e.edge(s),l=e.node(s.v);return{sum:i.sum+a.weight*l.order,weight:i.weight+a.weight}},{sum:0,weight:0});return{v:t,barycenter:o.sum/o.weight,weight:o.weight}}})}function Ne(e,n){let t={};e.forEach((o,i)=>{let s={indegree:0,in:[],out:[],vs:[o.v],i};o.barycenter!==void 0&&(s.barycenter=o.barycenter,s.weight=o.weight),t[o.v]=s}),n.edges().forEach(o=>{let i=t[o.v],s=t[o.w];i!==void 0&&s!==void 0&&(s.indegree++,i.out.push(s))});let r=Object.values(t).filter(o=>!o.indegree);return Dt(r)}function Dt(e){let n=[];function t(o){return i=>{i.merged||(i.barycenter===void 0||o.barycenter===void 0||i.barycenter>=o.barycenter)&&Yt(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=>B(o,["vs","i","barycenter","weight"]))}function Yt(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 Ge(e,n,t,r,o){let i={},s=null,a=null,l=o;typeof n=="boolean"?(l=n,i={}):n&&(i=n,s=t!=null?t:null,a=r!=null?r:null);let u=ze(e,L=>Object.hasOwn(L,"barycenter")),d=u.lhs,c=u.rhs.sort((L,b)=>b.i-L.i),f=[],h=0,p=0,E=0;d.sort(Wt(a,s,!!l));for(let[L,b]of Object.entries(i)){let g=d.findIndex(m=>m.vs[0]===L);d.splice(g+1,0,b)}E=Ln(f,c,E),d.forEach(L=>{E+=L.vs.length,f.push(L.vs),h+=L.barycenter*L.weight,p+=L.weight,E=Ln(f,c,E)});let y={vs:f.flat(1)};return p&&(y.barycenter=h/p,y.weight=p),y}function Ln(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 Wt(e,n,t){return(r,o)=>{if(r.barycenter<o.barycenter)return-1;if(r.barycenter>o.barycenter)return 1;if(e&&(typeof r.vs[0]=="string"||typeof o.vs[0]=="string")){let i=e.node(r.vs[0]),s=e.node(o.vs[0]),a=ee(n,i,s);if(a!==0)return a}return t?o.i-r.i:r.i-o.i}}function te(e,n,t,r,o){var L,b,g,m,w,k,_,C,j,I,S;let i=null,s=o;typeof r=="boolean"?(s=r,i=null):r!==void 0&&(i=r);let a=e.children(n),l=e.node(n),u=l?l.borderLeft:void 0,d=l?l.borderRight:void 0,c={};u&&(a=a.filter(G=>G!==u&&G!==d));let f=we(e,a);f.forEach(G=>{if(e.children(G.v).length){let{result:x}=te(e,G.v,t,i,s);c[G.v]=x,Object.hasOwn(x,"barycenter")&&Xt(G,x)}});let h=Ne(f,t);Bt(h,c);let p={},E=!1;for(let G=0;G<h.length;G++)for(let x=G+1;x<h.length;x++)if(!(!h[G]||!h[x]||!((L=h[G])!=null&&L.barycenter)||!((b=h[x])!=null&&b.barycenter))&&((g=h[G])==null?void 0:g.barycenter)===h[x].barycenter){let v=(w=(m=h[G])==null?void 0:m.vs[0])!=null?w:"",N=(_=(k=h[x])==null?void 0:k.vs[0])!=null?_:"",O=e.node(v),W=e.node(N);if(O.dummy==="edge"&&W.dummy==="edge"&&((C=O.edgeObj)==null?void 0:C.v)===((j=W.edgeObj)==null?void 0:j.v)&&((I=O.edgeObj)==null?void 0:I.w)===((S=W.edgeObj)==null?void 0:S.w))if(O.edgeLabel.reversed){p[N]=h[G],h.splice(G,1),G--;break}else p[v]=h[x],h.splice(x,1),x--;else E=!0}let y=Ge(h,p,i,e,s);if(u&&d){y.vs=[u,y.vs,d].flat(1);let G=e.predecessors(u);if(G&&G.length){let x=e.node(G[0]),v=e.predecessors(d),N=e.node(v[0]);Object.hasOwn(y,"barycenter")||(y.barycenter=0,y.weight=0),y.barycenter=(y.barycenter*y.weight+x.order+N.order)/(y.weight+2),y.weight+=2}}return Object.defineProperty(y,"result",{value:y,enumerable:!1,configurable:!0,writable:!0}),Object.defineProperty(y,"usedBias",{value:E,enumerable:!1,configurable:!0,writable:!0}),y}function Bt(e,n){e.forEach(t=>{t.vs=t.vs.flatMap(r=>n[r]?n[r].vs:r)})}function Xt(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 ve(e,n,t,r){r||(r=e.nodes());let o=zt(e),i=new T({compound:!0}).setGraph({root:o}).setDefaultNodeLabel(s=>e.node(s));return r.forEach(s=>{let a=e.node(s),l=e.parent(s);if(a.rank===n||a.minRank<=n&&n<=a.maxRank){i.setNode(s),i.setParent(s,l||o);let u=e[t](s);u&&u.forEach(d=>{let c=d.v===s?d.w:d.v,f=i.edge(c,s),h=f!==void 0?f.weight:0;i.setEdge(c,s,{weight:e.edge(d).weight+h})}),Object.hasOwn(a,"minRank")&&i.setNode(s,{borderLeft:a.borderLeft[n],borderRight:a.borderRight[n]})}}),i}function zt(e){let n;for(;e.hasNode(n=$("_root")););return n}function ke(e,n,t){let r={},o;t.forEach(i=>{let s=e.parent(i),a,l;for(;s;){if(a=e.parent(s),a?(l=r[a],r[a]=s):(l=o,o=s),l&&l!==s){n.setEdge(l,s);return}s=a}})}function re(e,n={},t=null){if(typeof n.customOrder=="function"){n.customOrder(e,re);return}let r=de(e),o=yn(e,A(1,r+1),"inEdges"),i=yn(e,A(r-1,-1,-1),"outEdges"),s=Le(e,t);if(wn(e,s),n.disableOptimalOrderHeuristic)return;let a=Number.POSITIVE_INFINITY,l,u=n.constraints||[];for(let d=0,c=0;c<4;++d,++c){Ht(d%2?o:i,d%4>=2,u,t),s=P(e);let f=ye(e,s);f<a?(c=0,l=Object.assign({},s),a=f):f===a&&(l=structuredClone(s))}wn(e,l)}function yn(e,n,t){let r=new Map,o=(i,s)=>{r.has(i)||r.set(i,[]),r.get(i).push(s)};for(let i of e.nodes()){let s=e.node(i);if(typeof s.rank=="number"&&o(s.rank,i),typeof s.minRank=="number"&&typeof s.maxRank=="number")for(let a=s.minRank;a<=s.maxRank;a++)a!==s.rank&&o(a,i)}return n.map(function(i){return ve(e,i,t,r.get(i)||[])})}function Ht(e,n,t,r){let o=!0,i=new T;e.forEach(function(s){t.forEach(d=>i.setEdge(d.left,d.right));let a=s.graph().root,{result:l,usedBias:u}=te(s,a,i,r,o);n&&u&&(o=!o),l.vs.forEach((d,c)=>s.node(d).order=c),ke(s,i,l.vs)})}function wn(e,n){Object.values(n).forEach(t=>t.forEach((r,o)=>e.node(r).order=o))}function qt(e,n){let t={};function r(o,i){let s=0,a=0,l=o.length,u=i[i.length-1];return i.forEach((d,c)=>{let f=Ut(e,d),h=f?e.node(f).order:l;(f||d===u)&&(i.slice(a,c+1).forEach(p=>{let E=e.predecessors(p);E&&E.forEach(y=>{let L=e.node(y),b=L.order;(b<s||h<b)&&!(L.dummy&&e.node(p).dummy)&&Gn(t,y,p)})}),a=c+1,s=h)}),i}return n.length&&n.reduce(r),t}function $t(e,n){let t={};function r(i,s,a,l,u){A(s,a).forEach(d=>{let c=i[d];if(c!==void 0&&e.node(c).dummy){let f=e.predecessors(c);f&&f.forEach(h=>{if(h===void 0)return;let p=e.node(h);p.dummy&&(p.order<l||p.order>u)&&Gn(t,h,c)})}})}function o(i,s){let a=-1,l=-1,u=0;return s.forEach((d,c)=>{if(e.node(d).dummy==="border"){let f=e.predecessors(d);if(f&&f.length){let h=f[0];if(h===void 0)return;l=e.node(h).order,r(s,u,c,a,l),u=c,a=l}}r(s,u,s.length,l,i.length)}),s}return n.length&&n.reduce(o),t}function Ut(e,n){if(e.node(n).dummy){let t=e.predecessors(n);if(t)return t.find(r=>e.node(r).dummy)}}function Gn(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 Jt(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 Kt(e,n,t,r,o){let i={},s={},a={};return n.forEach(l=>{l.forEach((u,d)=>{i[u]=u,s[u]=u,a[u]=d})}),n.forEach(l=>{let u=-1,d=-1,c=!1,f=l,h=l.findIndex(p=>(o==null?void 0:o.includes(p))||Nn(p,e,o));h>0&&(f=[l[h],...l.slice(0,h),...l.slice(h+1)],c=!0),f.forEach(p=>{var y;let E=r(p);if(E&&E.length){o!=null&&o.includes(p)&&(E=E.filter(g=>Nn(g,e,o)));let L=E.sort((g,m)=>{let w=a[g],k=a[m];return(w!==void 0?w:0)-(k!==void 0?k:0)}),b=(L.length-1)/2;for(let g=Math.floor(b),m=Math.ceil(b);g<=m;++g){let w=L[g];if(w===void 0)continue;let k=a[w];if(k!==void 0&&s[p]===p&&u<k&&a[w]!==d&&!Jt(t,p,w)){let _=i[w];_!==void 0&&(s[w]=p,s[p]=i[p]=_,u=k,c&&(u=-1,d=(y=a[w])!=null?y:-1,c=!1))}}}})}),{root:i,align:s}}function Qt(e,n,t,r,o=!1){let i={},s=Zt(e,n,t,o),a=o?"borderLeft":"borderRight";function l(h,p){let E=s.nodes().slice(),y={},L=E.pop();for(;L;){if(y[L])h(L);else{y[L]=!0,E.push(L);for(let b of p(L))E.push(b)}L=E.pop()}}function u(h){let p=s.inEdges(h);p?i[h]=p.reduce((E,y)=>{var g;let L=(g=i[y.v])!=null?g:0,b=s.edge(y);return Math.max(E,L+(b!==void 0?b:0))},0):i[h]=0}function d(h){let p=s.outEdges(h),E=Number.POSITIVE_INFINITY;p&&(E=p.reduce((L,b)=>{let g=i[b.w],m=s.edge(b);return Math.min(L,(g!==void 0?g:0)-(m!==void 0?m:0))},Number.POSITIVE_INFINITY));let y=e.node(h);E!==Number.POSITIVE_INFINITY&&y.borderType!==a&&(i[h]=Math.max(i[h]!==void 0?i[h]:0,E))}function c(h){return s.predecessors(h)||[]}function f(h){return s.successors(h)||[]}return l(u,c),l(d,f),Object.keys(r).forEach(h=>{var E;let p=t[h];p!==void 0&&(i[h]=(E=i[p])!=null?E:0)}),i}function Zt(e,n,t,r){let o=new T,i=e.graph(),s=rr(i.nodesep,i.edgesep,r);return n.forEach(a=>{let l;a.forEach(u=>{let d=t[u];if(d!==void 0){if(o.setNode(d),l!==void 0){let c=t[l];if(c!==void 0){let f=o.edge(c,d);o.setEdge(c,d,Math.max(s(e,u,l),f||0))}}l=u}})}),o}function er(e,n){return Object.values(n).reduce((t,r)=>{let o=Number.NEGATIVE_INFINITY,i=Number.POSITIVE_INFINITY;Object.entries(r).forEach(([a,l])=>{let u=or(e,a)/2;o=Math.max(l+u,o),i=Math.min(l-u,i)});let s=o-i;return s<t[0]&&(t=[s,r]),t},[Number.POSITIVE_INFINITY,null])[1]}function nr(e,n){let t=Object.values(n),r=R(Math.min,t),o=R(Math.max,t);["u","d"].forEach(i=>{["l","r"].forEach(s=>{let a=i+s,l=e[a];if(!l||l===n)return;let u=Object.values(l),d=r-R(Math.min,u);s!=="l"&&(d=o-R(Math.max,u)),d&&(e[a]=X(l,c=>c+d))})})}function tr(e,n=void 0){let t=e.ul;return t?X(t,(r,o)=>{var s,a;if(n){let l=n.toLowerCase(),u=e[l];if(u&&u[o]!==void 0)return u[o]}let i=Object.values(e).map(l=>{let u=l[o];return u!==void 0?u:0}).sort((l,u)=>l-u);return(((s=i[1])!=null?s:0)+((a=i[2])!=null?a:0))/2}):{}}function vn(e,n){let t=P(e),r=Object.assign(qt(e,t),$t(e,t)),o={},i;["u","d"].forEach(a=>{i=a==="u"?t:Object.values(t).reverse(),["l","r"].forEach(l=>{l==="r"&&(i=i.map(f=>Object.values(f).reverse()));let d=Kt(e,i,r,f=>(a==="u"?e.predecessors(f):e.successors(f))||[],n),c=Qt(e,i,d.root,d.align,l==="r");l==="r"&&(c=X(c,f=>-f)),o[a+l]=c})});let s=er(e,o);return nr(o,s),tr(o,e.graph().align)}function rr(e,n,t){return(r,o,i)=>{let s=r.node(o),a=r.node(i),l=0,u;if(l+=s.width/2,Object.hasOwn(s,"labelpos"))switch(s.labelpos.toLowerCase()){case"l":u=-s.width/2;break;case"r":u=s.width/2;break}if(u&&(l+=t?u:-u),u=void 0,l+=(s.dummy?n:e)/2,l+=(a.dummy?n:e)/2,l+=a.width/2,Object.hasOwn(a,"labelpos"))switch(a.labelpos.toLowerCase()){case"l":u=a.width/2;break;case"r":u=-a.width/2;break}return u&&(l+=t?u:-u),l}}function or(e,n){return e.node(n).width}function Nn(e,n,t){var s;if(!t)return!1;let r=(s=n.node(e))==null?void 0:s.edgeObj;if(!r||n.node(e).edgeLabel.reversed)return!1;let o=t.indexOf(r==null?void 0:r.v),i=t.indexOf(r==null?void 0:r.w);return o!==-1&&i!==-1&&o===(i+1)%t.length||o===(i-1)%t.length}function kn(e,n){e=Z(e),ir(e),Object.entries(vn(e,n)).forEach(([t,r])=>e.node(t).x=r)}function ir(e){let n=P(e),t=e.graph(),r=t.ranksep,o=t.rankalign,i=0;n.forEach(s=>{let a=s.reduce((l,u)=>{var c;let d=(c=e.node(u).height)!=null?c:0;return l>d?l:d},0);s.forEach(l=>{let u=e.node(l);o==="top"?u.y=i+u.height/2:o==="bottom"?u.y=i+a-u.height/2:u.y=i+a/2}),i+=a+r})}var xn=new WeakMap;function Oe(e,n={}){return Rn(e,q,n),e}function _n(e,n,t){let r=n;for(;r!==void 0;){let o=e.parent(r);if(o===t)return r;r=o}}function Rn(e,n,t){var L;let r=e.nodes().filter(b=>e.children(b).length),o={};r.forEach(b=>{let g=e.node(b);if(g&&g.rankdir){let m=new T({multigraph:!0,compound:!0});m.setGraph({rankdir:g.rankdir});let w=e.children(b);w.forEach(v=>{let N={...e.node(v)};m.setNode(v,N);let O=e.parent(v);O&&O!==b&&w.includes(O)&&m.setParent(v,O)});let k=new Set;e.edges().forEach(v=>{let N=_n(e,v.v,b),O=_n(e,v.w,b);if(N&&O&&N!==O){let W=`${N}\0${O}`;k.has(W)||(k.add(W),m.setEdge(N,O,{...e.edge(v)}))}}),Rn(m,n,t);let _=jn(m);On(_,n,t,null),Cn(m,_);let C=1/0,j=1/0,I=-1/0,S=-1/0;m.nodes().forEach(v=>{if(v===b)return;let N=m.node(v);N&&typeof N.x=="number"&&typeof N.y=="number"&&typeof N.width=="number"&&typeof N.height=="number"&&(C=Math.min(C,N.x-N.width/2),I=Math.max(I,N.x+N.width/2),j=Math.min(j,N.y-N.height/2),S=Math.max(S,N.y+N.height/2))}),(!isFinite(C)||!isFinite(j)||!isFinite(I)||!isFinite(S))&&(C=j=0,I=S=0);let G=I-C,x=S-j;o[b]={minX:C,minY:j,maxX:I,maxY:S,width:G,height:x,offsetX:C,offsetY:j},g._dagreClusterSubgraph=m}});let i=[],s=b=>{let g=[],m=(e.children(b)||[]).filter(w=>w!==b);for(;m.length>0;){let w=m.shift();g.push(w),(e.children(w)||[]).filter(k=>k!==w).forEach(k=>m.push(k))}return g},a=new Map;r.forEach(b=>{let g=e.node(b);g&&g.rankdir&&o[b]&&a.set(b,(e.children(b)||[]).filter(m=>m!==b))});let l=new Set([...a.values()].flat()),u=new Map;a.forEach((b,g)=>{l.has(g)||u.set(g,s(g))});let d=new Set([...u.values()].flat()),c=b=>{for(let[g,m]of u)if(m.includes(b))return g;return b},f=[];e.edges().forEach(b=>{(d.has(b.v)||d.has(b.w))&&f.push({edge:b,label:e.edge(b)})});let h=new Map;d.forEach(b=>{let g=e.parent(b);h.set(b,typeof g=="string"?g:void 0)}),u.forEach((b,g)=>{let m=e.node(g),w=[];b.forEach(C=>{let j=e.node(C);j&&(w.push({id:C,node:j,parent:h.get(C)}),e.removeNode(C))});let k=f.filter(({edge:C})=>b.includes(C.v)||b.includes(C.w)),_=o[g];m&&(i.push({clusterId:g,subgraph:m._dagreClusterSubgraph,bounds:_,children:b,removedNodes:w,removedEdges:k}),m.width=_.width,m.height=_.height)});let p=new Set;f.forEach(({edge:b,label:g})=>{let m=c(b.v),w=c(b.w);if(m!==w&&e.hasNode(m)&&e.hasNode(w)){let k=`${m}\0${w}`;p.has(k)||(p.add(k),e.setEdge(m,w,{...g,width:0,height:0}))}});let E=jn(e),y=On(E,n,t,(L=xn.get(e))!=null?L:null);xn.set(e,y),Cn(e,E),p.forEach(b=>{let g=b.indexOf("\0"),m=b.slice(0,g),w=b.slice(g+1);e.hasEdge(m,w)&&e.removeEdge(m,w)}),i.forEach(({clusterId:b,subgraph:g,bounds:m,removedNodes:w,removedEdges:k})=>{var G,x;let _=e.node(b),C=(G=_==null?void 0:_.x)!=null?G:0,j=(x=_==null?void 0:_.y)!=null?x:0,I=(m.minX+m.maxX)/2,S=(m.minY+m.maxY)/2;w.forEach(({id:v,node:N,parent:O})=>{e.setNode(v,N),O!==void 0&&e.setParent(v,O)}),k.forEach(({edge:v,label:N})=>{e.setEdge(v,N)}),g.nodes().forEach(v=>{if(v===b)return;let N=g.node(v),O=e.node(v);O&&N&&typeof N.x=="number"&&typeof N.y=="number"&&(O.x=C+(N.x-I),O.y=j+(N.y-S))}),delete _._dagreClusterSubgraph}),r.forEach(b=>{var w,k;let g=e.node(b),m=o[b];if(g&&g.rankdir&&g._dagreClusterSubgraph&&m){let _=g._dagreClusterSubgraph,C=(w=g.x)!=null?w:0,j=(k=g.y)!=null?k:0,I=(m.minX+m.maxX)/2,S=(m.minY+m.maxY)/2;_.nodes().forEach(G=>{if(G===b)return;let x=_.node(G),v=e.node(G);if(v&&x&&typeof x.x=="number"&&typeof x.y=="number"){let N=x.x-I,O=x.y-S;v.x=C+N,v.y=j+O}}),delete g._dagreClusterSubgraph}})}function On(e,n,t,r=null){var l,u;let o=(t==null?void 0:t.useDynamic)!==!1,i=o&&(l=r==null?void 0:r.graph)!=null?l:null,s=o&&(u=r==null?void 0:r.rawNodes)!=null?u:null;n(" makeSpaceForEdgeLabels",()=>hr(e)),n(" removeSelfEdges",()=>Nr(e)),n(" acyclic",()=>Ue(e,i)),n(" nestingGraph.run",()=>un(e)),n(" rank",()=>dn(Z(e))),n(" injectEdgeLabelProxies",()=>br(e)),n(" removeEmptyRanks",()=>Be(e)),n(" nestingGraph.cleanup",()=>fn(e)),n(" normalizeRanks",()=>We(e)),n(" assignRankMinMax",()=>gr(e)),n(" removeEdgeLabelProxies",()=>pr(e)),n(" normalize.run",()=>Ke(e)),n(" parentDummyChains",()=>ln(e)),n(" addBorderSegments",()=>bn(e)),n(" order",()=>re(e,t,s)),n(" insertSelfEdges",()=>Gr(e)),n(" adjustCoordinateSystem",()=>pn(e)),n(" position",()=>kn(e,t.corePath)),n(" positionSelfEdges",()=>vr(e));let a=JSON.parse(JSON.stringify(e._nodes));return n(" removeBorderNodes",()=>wr(e)),n(" normalize.undo",()=>Qe(e)),n(" fixupEdgeLabelCoords",()=>Lr(e)),n(" undoCoordinateSystem",()=>mn(e)),n(" translateGraph",()=>mr(e)),n(" assignNodeIntersects",()=>Er(e)),n(" reversePoints",()=>yr(e)),n(" acyclic.undo",()=>Je(e)),{graph:e,rawNodes:a}}function Cn(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 sr=["nodesep","edgesep","ranksep","marginx","marginy"],ar={ranksep:50,edgesep:20,nodesep:50,rankdir:"TB",rankalign:"center"},dr=["acyclicer","ranker","rankdir","align","rankalign"],lr=["width","height","rank"],Tn={width:0,height:0},ur=["minlen","weight","width","height","labeloffset"],cr={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},fr=["labelpos"];function jn(e){let n=new T({multigraph:!0,compound:!0}),t=_e(e.graph());return n.setGraph(Object.assign({},ar,xe(t,sr),B(t,dr))),e.nodes().forEach(r=>{let o=_e(e.node(r)),i=xe(o,lr);Object.keys(Tn).forEach(a=>{i[a]===void 0&&(i[a]=Tn[a])}),n.setNode(r,i);let s=e.parent(r);s!==void 0&&n.setParent(r,s)}),e.edges().forEach(r=>{let o=_e(e.edge(r));n.setEdge(r,Object.assign({},cr,xe(o,ur),B(o,fr)))}),n}function hr(e){let n=e.graph();n.ranksep/=2,e.edges().forEach(t=>{var o;let r=e.edge(t);r.minlen*=2,((o=r.labelpos)!=null?o:"r").toLowerCase()!=="c"&&(n.rankdir==="TB"||n.rankdir==="BT"?r.width+=r.labeloffset:r.height+=r.labeloffset)})}function br(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};M(e,"edge-proxy",i,"_ep")}})}function gr(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 pr(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 mr(e){let n=Number.POSITIVE_INFINITY,t=0,r=Number.POSITIVE_INFINITY,o=0,i=e.graph(),s=i.marginx||0,a=i.marginy||0;function l(u){let d=u.x,c=u.y,f=u.width,h=u.height;n=Math.min(n,d-f/2),t=Math.max(t,d+f/2),r=Math.min(r,c-h/2),o=Math.max(o,c+h/2)}e.nodes().forEach(u=>l(e.node(u))),e.edges().forEach(u=>{let d=e.edge(u);Object.hasOwn(d,"x")&&l(d)}),n-=s,r-=a,e.nodes().forEach(u=>{let d=e.node(u);d.x-=n,d.y-=r}),e.edges().forEach(u=>{let d=e.edge(u);d.points.forEach(c=>{c.x-=n,c.y-=r}),Object.hasOwn(d,"x")&&(d.x-=n),Object.hasOwn(d,"y")&&(d.y-=r)}),i.width=t-n+s,i.height=o-r+a}function Er(e){e.edges().forEach(n=>{if(n.v===n.w)return;let t=e.edge(n),r=e.node(n.v),o=e.node(n.w),i,s;t.points?(i=t.points[0],s=t.points[t.points.length-1]):(t.points=[],i=o,s=r),t.points.unshift(se(r,i)),t.points.push(se(o,s))})}function Lr(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 yr(e){e.edges().forEach(n=>{let t=e.edge(n);t.reversed&&t.points.reverse()})}function wr(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]),s=e.node(t.borderRight[t.borderRight.length-1]);t.width=Math.abs(s.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 Nr(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 Gr(e){P(e).forEach(t=>{let r=0;t.forEach((o,i)=>{let s=e.node(o);typeof s.rank!="number"&&(s.rank=0),s.order=i+r,(s.selfEdges||[]).forEach(a=>{M(e,"selfedge",{width:a.label.width,height:a.label.height,rank:s.rank,order:i+ ++r,e:a.e,edgeLabel:a.label},"_se"),(!Array.isArray(a.label.points)||a.label.points.length!==7)&&(a.label.points=[{x:0,y:-10},{x:0,y:-10},{x:0,y:0},{x:0,y:10},{x:0,y:10},{x:0,y:0},{x:0,y:0}])}),delete s.selfEdges})})}function vr(e){e.nodes().forEach(n=>{let t=e.node(n),r=o=>typeof o=="number"&&isFinite(o);if(t.dummy==="selfedge"){let o=t,i=e.node(o.e.v),s=r(i==null?void 0:i.x)?i.x:0,a=r(i==null?void 0:i.y)?i.y:0,l=r(i==null?void 0:i.width)?i.width:0,u=r(i==null?void 0:i.height)?i.height:0,d=r(t.x)?t.x:s,c=r(t.y)?t.y:a,f=l/2,h=u/2;o.edgeLabel.points=[{x:d+f,y:c-h},{x:d+f,y:c-h},{x:d,y:c},{x:d-f,y:c+h},{x:d-f,y:c+h},{x:d,y:c},{x:d,y:c}],o.edgeLabel.x=d,o.edgeLabel.y=c,e.setEdge(o.e,o.edgeLabel),e.removeNode(n)}else t&&Array.isArray(t.selfEdges)&&t.selfEdges.forEach(o=>{if(!Array.isArray(o.label.points)||o.label.points.length!==7){let i=r(t.x)?t.x:0,s=r(t.y)?t.y:0,a=r(t.width)?t.width:0,l=r(t.height)?t.height:0,u=a/2,d=l/2;o.label.points=[{x:i+u,y:s-d},{x:i+u,y:s-d},{x:i,y:s},{x:i-u,y:s+d},{x:i-u,y:s+d},{x:i,y:s},{x:i,y:s}]}})})}function xe(e,n){return X(B(e,n),Number)}function _e(e){let n={};return e&&Object.entries(e).forEach(([t,r])=>{typeof t=="string"&&(t=t.toLowerCase()),n[t]=r}),n}function Ce(e){let n=P(e),t=new T({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((s,a)=>(t.setEdge(s,a,{style:"invis"}),a))}),t}var qo={time:le,notime:q},kr={graphlib:ie,version:ue,layout:Oe,debug:Ce,util:{time:le,notime:q}},$o=kr;export{T as Graph,Ce as debug,$o as default,ie as graphlib,Oe as layout,qo as util,ue as version};
|
|
2
2
|
/*! For license information please see dagre.esm.js.LEGAL.txt */
|
|
3
3
|
//# sourceMappingURL=dagre.esm.js.map
|