UNPKG

cytoscape-dagre

Version:

The Dagre layout for DAGs and trees for Cytoscape.js

8 lines (7 loc) 45.6 kB
/*! * cytoscape-dagre 3.0.0 * https://github.com/cytoscape/cytoscape.js-dagre * License: MIT */ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).cytoscapeDagre=t()}(this,function(){"use strict";function e(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function t(t,n){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!r){if(Array.isArray(t)||(r=function(t,n){if(t){if("string"==typeof t)return e(t,n);var r={}.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?e(t,n):void 0}}(t))||n){r&&(t=r);var o=0,i=function(){};return{s:i,n:function(){return o>=t.length?{done:!0}:{done:!1,value:t[o++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var s,a=!0,d=!1;return{s:function(){r=r.call(t)},n:function(){var e=r.next();return a=e.done,e},e:function(e){d=!0,s=e},f:function(){try{a||null==r.return||r.return()}finally{if(d)throw s}}}}function n(e){return n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},n(e)}var r={nodeSep:void 0,edgeSep:void 0,rankSep:void 0,rankDir:void 0,align:void 0,acyclicer:void 0,ranker:void 0,minLen:function(e){return 1},edgeWeight:function(e){return 1},fit:!0,padding:30,spacingFactor:void 0,nodeDimensionsIncludeLabels:!1,useDagreEdgeControlPoints:!1,automaticDagreEdgeStyle:!1,dagreEdgeStyle:{"curve-style":"unbundled-bezier","control-point-weights":function(e){return e.scratch("controlPointWeights")},"control-point-distances":function(e){return e.scratch("controlPointDistances")},"edge-distances":"intersection","edge-ends-overlap":!1},animate:!1,animateFilter:function(e,t){return!0},animationDuration:500,animationEasing:void 0,boundingBox:void 0,transform:function(e,t){return t},ready:function(){},sort:void 0,stop:function(){}},o=null!=Object.assign?Object.assign.bind(Object):function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];return n.forEach(function(t){Object.keys(t).forEach(function(n){return e[n]=t[n]})}),e},i=Object.defineProperty,s=(e,t,n)=>((e,t,n)=>t in e?i(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n)(e,t+"",n),a={};((e,t)=>{for(var n in t)i(e,n,{get:t[n],enumerable:!0})})(a,{Graph:()=>h,alg:()=>y,json:()=>v,version:()=>p});var d=Object.defineProperty,l=(e,t)=>{for(var n in t)d(e,n,{get:t[n],enumerable:!0})},h=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,this._isMultigraph="multigraph"in e&&e.multigraph,this._isCompound="compound"in e&&e.compound),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 this._defaultNodeLabelFn="function"!=typeof e?()=>e:e,this}nodeCount(){return this._nodeCount}nodes(){return Object.keys(this._nodes)}sources(){return this.nodes().filter(e=>0===Object.keys(this._in[e]).length)}sinks(){return this.nodes().filter(e=>0===Object.keys(this._out[e]).length)}setNodes(e,t){return e.forEach(e=>{void 0!==t?this.setNode(e,t):this.setNode(e)}),this}setNode(e,t){return e in this._nodes?(arguments.length>1&&(this._nodes[e]=t),this):(this._nodes[e]=arguments.length>1?t: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 t=e=>this.removeEdge(this._edgeObjs[e]);delete this._nodes[e],this._isCompound&&(this._removeFromParentsChildList(e),delete this._parent[e],this.children(e).forEach(e=>{this.setParent(e)}),delete this._children[e]),Object.keys(this._in[e]).forEach(t),delete this._in[e],delete this._preds[e],Object.keys(this._out[e]).forEach(t),delete this._out[e],delete this._sucs[e],--this._nodeCount}return this}setParent(e,t){if(!this._isCompound)throw new Error("Cannot set parent in a non-compound graph");if(void 0===t)t="\0";else{for(let n=t+="";void 0!==n;n=this.parent(n))if(n===e)throw new Error("Setting "+t+" as parent of "+e+" would create a cycle");this.setNode(t)}return this.setNode(e),this._removeFromParentsChildList(e),this._parent[e]=t,this._children[t][e]=!0,this}parent(e){if(this._isCompound){let t=this._parent[e];if("\0"!==t)return t}}children(e="\0"){if(this._isCompound){let t=this._children[e];if(t)return Object.keys(t)}else{if("\0"===e)return this.nodes();if(this.hasNode(e))return[]}return[]}predecessors(e){let t=this._preds[e];if(t)return Object.keys(t)}successors(e){let t=this._sucs[e];if(t)return Object.keys(t)}neighbors(e){let t=this.predecessors(e);if(t){let n=new Set(t);for(let t of this.successors(e))n.add(t);return Array.from(n.values())}}isLeaf(e){let t;return t=this.isDirected()?this.successors(e):this.neighbors(e),0===t.length}filterNodes(e){let t=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});t.setGraph(this.graph()),Object.entries(this._nodes).forEach(([n,r])=>{e(n)&&t.setNode(n,r)}),Object.values(this._edgeObjs).forEach(e=>{t.hasNode(e.v)&&t.hasNode(e.w)&&t.setEdge(e,this.edge(e))});let n={},r=e=>{let o=this.parent(e);return!o||t.hasNode(o)?(n[e]=null!=o?o:void 0,null!=o?o:void 0):o in n?n[o]:r(o)};return this._isCompound&&t.nodes().forEach(e=>t.setParent(e,r(e))),t}setDefaultEdgeLabel(e){return this._defaultEdgeLabelFn="function"!=typeof e?()=>e:e,this}edgeCount(){return this._edgeCount}edges(){return Object.values(this._edgeObjs)}setPath(e,t){return e.reduce((e,n)=>(void 0!==t?this.setEdge(e,n,t):this.setEdge(e,n),n)),this}setEdge(e,t,n,r){let o,i,s,a,d=!1;"object"==typeof e&&null!==e&&"v"in e?(o=e.v,i=e.w,s=e.name,2===arguments.length&&(a=t,d=!0)):(o=e,i=t,s=r,arguments.length>2&&(a=n,d=!0)),o=""+o,i=""+i,void 0!==s&&(s=""+s);let l=f(this._isDirected,o,i,s);if(l in this._edgeLabels)return d&&(this._edgeLabels[l]=a),this;if(void 0!==s&&!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 h=function(e,t,n,r){let o=""+t,i=""+n;if(!e&&o>i){let e=o;o=i,i=e}let s={v:o,w:i};return r&&(s.name=r),s}(this._isDirected,o,i,s);return o=h.v,i=h.w,Object.freeze(h),this._edgeObjs[l]=h,u(this._preds[i],o),u(this._sucs[o],i),this._in[i][l]=h,this._out[o][l]=h,this._edgeCount++,this}edge(e,t,n){let r=1===arguments.length?g(this._isDirected,e):f(this._isDirected,e,t,n);return this._edgeLabels[r]}edgeAsObj(e,t,n){let r=1===arguments.length?this.edge(e):this.edge(e,t,n);return"object"!=typeof r?{label:r}:r}hasEdge(e,t,n){return(1===arguments.length?g(this._isDirected,e):f(this._isDirected,e,t,n))in this._edgeLabels}removeEdge(e,t,n){let r=1===arguments.length?g(this._isDirected,e):f(this._isDirected,e,t,n),o=this._edgeObjs[r];if(o){let e=o.v,t=o.w;delete this._edgeLabels[r],delete this._edgeObjs[r],c(this._preds[t],e),c(this._sucs[e],t),delete this._in[t][r],delete this._out[e][r],this._edgeCount--}return this}inEdges(e,t){return this.isDirected()?this.filterEdges(this._in[e],e,t):this.nodeEdges(e,t)}outEdges(e,t){return this.isDirected()?this.filterEdges(this._out[e],e,t):this.nodeEdges(e,t)}nodeEdges(e,t){if(e in this._nodes)return this.filterEdges({...this._in[e],...this._out[e]},e,t)}_removeFromParentsChildList(e){delete this._children[this._parent[e]][e]}filterEdges(e,t,n){if(!e)return;let r=Object.values(e);return n?r.filter(e=>e.v===t&&e.w===n||e.v===n&&e.w===t):r}};function u(e,t){e[t]?e[t]++:e[t]=1}function c(e,t){void 0!==e[t]&&! --e[t]&&delete e[t]}function f(e,t,n,r){let o=""+t,i=""+n;if(!e&&o>i){let e=o;o=i,i=e}return o+""+i+""+(void 0===r?"\0":r)}function g(e,t){return f(e,t.v,t.w,t.name)}var p="4.0.1",v={};function m(e){let t={options:{directed:e.isDirected(),multigraph:e.isMultigraph(),compound:e.isCompound()},nodes:w(e),edges:E(e)},n=e.graph();return void 0!==n&&(t.value=structuredClone(n)),t}function w(e){return e.nodes().map(t=>{let n=e.node(t),r=e.parent(t),o={v:t};return void 0!==n&&(o.value=n),void 0!==r&&(o.parent=r),o})}function E(e){return e.edges().map(t=>{let n=e.edge(t),r={v:t.v,w:t.w};return void 0!==t.name&&(r.name=t.name),void 0!==n&&(r.value=n),r})}function b(e){let t=new h(e.options);return void 0!==e.value&&t.setGraph(e.value),e.nodes.forEach(e=>{t.setNode(e.v,e.value),e.parent&&t.setParent(e.v,e.parent)}),e.edges.forEach(e=>{t.setEdge({v:e.v,w:e.w,name:e.name},e.value)}),t}l(v,{read:()=>b,write:()=>m});var y={};l(y,{CycleException:()=>L,bellmanFord:()=>k,components:()=>x,dijkstra:()=>I,dijkstraAll:()=>j,findCycles:()=>M,floydWarshall:()=>T,isAcyclic:()=>D,postorder:()=>A,preorder:()=>G,prim:()=>Y,shortestPaths:()=>B,tarjan:()=>C,topsort:()=>P});var _=()=>1;function k(e,t,n,r){return function(e,t,n,r){let o,i={},s=0,a=e.nodes(),d=function(e){let t=n(e);i[e.v].distance+t<i[e.w].distance&&(i[e.w]={distance:i[e.v].distance+t,predecessor:e.v},o=!0)},l=function(){a.forEach(function(e){r(e).forEach(function(t){let n=t.v===e?t.v:t.w,r=n===t.v?t.w:t.v;d({v:n,w:r})})})};a.forEach(function(e){let n=e===t?0:Number.POSITIVE_INFINITY;i[e]={distance:n,predecessor:""}});let h=a.length;for(let e=1;e<h&&(o=!1,s++,l(),o);e++);if(s===h-1&&(o=!1,l(),o))throw new Error("The graph contains a negative weight cycle");return i}(e,String(t),n||_,r||function(t){return e.outEdges(t)})}function x(e){let t,n={},r=[];function o(r){r in n||(n[r]=!0,t.push(r),e.successors(r).forEach(o),e.predecessors(r).forEach(o))}return e.nodes().forEach(function(e){t=[],o(e),t.length&&r.push(t)}),r}var N=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 t=this._keyIndices[e];if(void 0!==t)return this._arr[t].priority}min(){if(0===this.size())throw new Error("Queue underflow");return this._arr[0].key}add(e,t){let n=this._keyIndices,r=String(e);if(!(r in n)){let e=this._arr,o=e.length;return n[r]=o,e.push({key:r,priority:t}),this._decrease(o),!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,t){let n=this._keyIndices[e];if(void 0===n)throw new Error(`Key not found: ${e}`);let r=this._arr[n].priority;if(t>r)throw new Error(`New priority is greater than current priority. Key: ${e} Old: ${r} New: ${t}`);this._arr[n].priority=t,this._decrease(n)}_heapify(e){let t=this._arr,n=2*e,r=n+1,o=e;n<t.length&&(o=t[n].priority<t[o].priority?n:o,r<t.length&&(o=t[r].priority<t[o].priority?r:o),o!==e&&(this._swap(e,o),this._heapify(o)))}_decrease(e){let t,n=this._arr,r=n[e].priority;for(;0!==e&&(t=e>>1,!(n[t].priority<r));)this._swap(e,t),e=t}_swap(e,t){let n=this._arr,r=this._keyIndices,o=n[e],i=n[t];n[e]=i,n[t]=o,r[i.key]=e,r[o.key]=t}},O=()=>1;function I(e,t,n,r){return function(e,t,n,r){let o,i,s={},a=new N,d=function(e){let t=e.v!==o?e.v:e.w,r=s[t],d=n(e),l=i.distance+d;if(d<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+e+" Weight: "+d);l<r.distance&&(r.distance=l,r.predecessor=o,a.decrease(t,l))};for(e.nodes().forEach(function(e){let n=e===t?0:Number.POSITIVE_INFINITY;s[e]={distance:n,predecessor:""},a.add(e,n)});a.size()>0&&(o=a.removeMin(),i=s[o],i.distance!==Number.POSITIVE_INFINITY);)r(o).forEach(d);return s}(e,String(t),n||O,r||function(t){return e.outEdges(t)})}function j(e,t,n){return e.nodes().reduce(function(r,o){return r[o]=I(e,o,t,n),r},{})}function C(e){let t=0,n=[],r={},o=[];function i(s){let a=r[s]={onStack:!0,lowlink:t,index:t++};if(n.push(s),e.successors(s).forEach(function(e){e in r?r[e].onStack&&(a.lowlink=Math.min(a.lowlink,r[e].index)):(i(e),a.lowlink=Math.min(a.lowlink,r[e].lowlink))}),a.lowlink===a.index){let e,t=[];do{e=n.pop(),r[e].onStack=!1,t.push(e)}while(s!==e);o.push(t)}}return e.nodes().forEach(function(e){e in r||i(e)}),o}function M(e){return C(e).filter(function(t){return t.length>1||1===t.length&&e.hasEdge(t[0],t[0])})}var S=()=>1;function T(e,t,n){return function(e,t,n){let r={},o=e.nodes();return o.forEach(function(e){r[e]={},r[e][e]={distance:0,predecessor:""},o.forEach(function(t){e!==t&&(r[e][t]={distance:Number.POSITIVE_INFINITY,predecessor:""})}),n(e).forEach(function(n){let o=n.v===e?n.w:n.v,i=t(n);r[e][o]={distance:i,predecessor:e}})}),o.forEach(function(e){let t=r[e];o.forEach(function(n){let i=r[n];o.forEach(function(n){let r=i[e],o=t[n],s=i[n],a=r.distance+o.distance;a<s.distance&&(s.distance=a,s.predecessor=o.predecessor)})})}),r}(e,t||S,n||function(t){return e.outEdges(t)})}var L=class extends Error{constructor(...e){super(...e)}};function P(e){let t={},n={},r=[];if(e.sinks().forEach(function o(i){if(i in n)throw new L;i in t||(n[i]=!0,t[i]=!0,e.predecessors(i).forEach(o),delete n[i],r.push(i))}),Object.keys(t).length!==e.nodeCount())throw new L;return r}function D(e){try{P(e)}catch(e){if(e instanceof L)return!1;throw e}return!0}function F(e,t,n,r,o){Array.isArray(t)||(t=[t]);let i=t=>{var n;return null!=(n=e.isDirected()?e.successors(t):e.neighbors(t))?n:[]},s={};return t.forEach(function(t){if(!e.hasNode(t))throw new Error("Graph does not have node: "+t);o=R(e,t,"post"===n,s,i,r,o)}),o}function R(e,t,n,r,o,i,s){return t in r||(r[t]=!0,n||(s=i(s,t)),o(t).forEach(function(t){s=R(e,t,n,r,o,i,s)}),n&&(s=i(s,t))),s}function V(e,t,n){return F(e,t,n,function(e,t){return e.push(t),e},[])}function A(e,t){return V(e,t,"post")}function G(e,t){return V(e,t,"pre")}function Y(e,t){let n,r=new h,o={},i=new N;function s(e){let r=e.v===n?e.w:e.v,s=i.priority(r);if(void 0!==s){let a=t(e);a<s&&(o[r]=n,i.decrease(r,a))}}if(0===e.nodeCount())return r;e.nodes().forEach(function(e){i.add(e,Number.POSITIVE_INFINITY),r.setNode(e)}),i.decrease(e.nodes()[0],0);let a=!1;for(;i.size()>0;){if(n=i.removeMin(),n in o)r.setEdge(n,o[n]);else{if(a)throw new Error("Input graph is not connected: "+e);a=!0}e.nodeEdges(n).forEach(s)}return r}function B(e,t,n,r){return function(e,t,n,r){if(void 0===n)return I(e,t,n,r);let o=!1,i=e.nodes();for(let s=0;s<i.length;s++){let a=r(i[s]);for(let e=0;e<a.length;e++){let t=a[e],r=t.v===i[s]?t.v:t.w;n({v:r,w:r===t.v?t.w:t.v})<0&&(o=!0)}if(o)return k(e,t,n,r)}return I(e,t,n,r)}(e,t,n,null!=r?r:t=>{let n=e.outEdges(t);return null!=n?n:[]})}function z(e,t,n,r){let o=r;for(;e.hasNode(o);)o=ee(r);return n.dummy=t,e.setNode(o,n),o}function q(e){let t=new h({multigraph:e.isMultigraph()}).setGraph(e.graph());return e.nodes().forEach(n=>{e.children(n).length||t.setNode(n,e.node(n))}),e.edges().forEach(n=>{t.setEdge(n,e.edge(n))}),t}function W(e,t){let n,r,o=e.x,i=e.y,s=t.x-o,a=t.y-i,d=e.width/2,l=e.height/2;if(!s&&!a)throw new Error("Not possible to find intersection inside of the rectangle");return Math.abs(a)*d>Math.abs(s)*l?(a<0&&(l=-l),n=l*s/a,r=l):(s<0&&(d=-d),n=d,r=d*a/s),{x:o+n,y:i+r}}function $(e){let t=te(J(e)+1).map(()=>[]);return e.nodes().forEach(n=>{let r=e.node(n),o=r.rank;void 0!==o&&(t[o]||(t[o]=[]),t[o][r.order]=n)}),t}function U(e,t,n,r){let o={width:0,height:0};return arguments.length>=4&&(o.rank=n,o.order=r),z(e,"border",o,t)}var K=65535;function H(e,t){if(t.length>K){let n=function(e,t=K){let n=[];for(let r=0;r<e.length;r+=t){let o=e.slice(r,r+t);n.push(o)}return n}(t);return e(...n.map(t=>e(...t)))}return e(...t)}function J(e){let t=e.nodes().map(t=>{let n=e.node(t).rank;return void 0===n?Number.MIN_VALUE:n});return H(Math.max,t)}function Q(e,t){let n=Date.now();try{return t()}finally{console.log(e+" time: "+(Date.now()-n)+"ms")}}function X(e,t){return t()}var Z=0;function ee(e){return e+""+ ++Z}function te(e,t,n=1){null==t&&(t=e,e=0);let r=e=>e<t;n<0&&(r=e=>t<e);let o=[];for(let t=e;r(t);t+=n)o.push(t);return o}function ne(e,t){let n={};for(let r of t)void 0!==e[r]&&(n[r]=e[r]);return n}function re(e,t){let n;return n="string"==typeof t?e=>e[t]:t,Object.entries(e).reduce((e,[t,r])=>(e[t]=n(r,t),e),{})}var oe="\0";function ie(e){e._prev._next=e._next,e._next._prev=e._prev,delete e._next,delete e._prev}function se(e,t){if("_next"!==e&&"_prev"!==e)return t}var ae=class{constructor(){s(this,"_sentinel");let e={};e._next=e._prev=e,this._sentinel=e}dequeue(){let e=this._sentinel,t=e._prev;if(t!==e)return ie(t),t}enqueue(e){let t=this._sentinel;e._prev&&e._next&&ie(e),e._next=t._next,t._next._prev=e,t._next=e,e._prev=t}toString(){let e=[],t=this._sentinel,n=t._prev;for(;n!==t;)e.push(JSON.stringify(n,se)),n=n._prev;return"["+e.join(", ")+"]"}},de=()=>1;function le(e,t){if(e.nodeCount()<=1)return[];let n=function(e,t){let n=new h,r=0,o=0;e.nodes().forEach(e=>{n.setNode(e,{v:e,in:0,out:0})}),e.edges().forEach(e=>{let i=n.edge(e.v,e.w)||0,s=t(e),a=i+s;n.setEdge(e.v,e.w,a);let d=n.node(e.v),l=n.node(e.w);o=Math.max(o,d.out+=s),r=Math.max(r,l.in+=s)});let i=function(e){let t=[];for(let n=0;n<e;n++)t.push(n);return t}(o+r+3).map(()=>new ae),s=r+1;return n.nodes().forEach(e=>{ue(i,s,n.node(e))}),{graph:n,buckets:i,zeroIdx:s}}(e,t||de);return function(e,t,n){var r;let o,i=[],s=t[t.length-1],a=t[0];for(;e.nodeCount();){for(;o=a.dequeue();)he(e,t,n,o);for(;o=s.dequeue();)he(e,t,n,o);if(e.nodeCount())for(let s=t.length-2;s>0;--s)if(o=null==(r=t[s])?void 0:r.dequeue(),o){i=i.concat(he(e,t,n,o,!0)||[]);break}}return i}(n.graph,n.buckets,n.zeroIdx).flatMap(t=>e.outEdges(t.v,t.w)||[])}function he(e,t,n,r,o){let i=[],s=o?i:void 0;return(e.inEdges(r.v)||[]).forEach(r=>{let s=e.edge(r),a=e.node(r.v);o&&i.push({v:r.v,w:r.w}),a.out-=s,ue(t,n,a)}),(e.outEdges(r.v)||[]).forEach(r=>{let o=e.edge(r),i=r.w,s=e.node(i);s.in-=o,ue(t,n,s)}),e.removeNode(r.v),s}function ue(e,t,n){var r,o,i;n.out?n.in?null==(i=e[n.out-n.in+t])||i.enqueue(n):null==(o=e[e.length-1])||o.enqueue(n):null==(r=e[0])||r.enqueue(n)}function ce(e){var t;("greedy"===e.graph().acyclicer?le(e,(t=e,e=>t.edge(e).weight)):function(e){let t=[],n={},r={};function o(i){Object.hasOwn(r,i)||(r[i]=!0,n[i]=!0,e.outEdges(i).forEach(e=>{Object.hasOwn(n,e.w)?t.push(e):o(e.w)}),delete n[i])}return e.nodes().forEach(o),t}(e)).forEach(t=>{let n=e.edge(t);e.removeEdge(t),n.forwardName=t.name,n.reversed=!0,e.setEdge(t.w,t.v,n,ee("rev"))})}function fe(e){e.graph().dummyChains=[],e.edges().forEach(t=>function(e,t){let n,r,o,i=t.v,s=e.node(i).rank,a=t.w,d=e.node(a).rank,l=t.name,h=e.edge(t),u=h.labelRank;if(d===s+1)return;for(e.removeEdge(t),o=0,++s;s<d;++o,++s)h.points=[],r={width:0,height:0,edgeLabel:h,edgeObj:t,rank:s},n=z(e,"edge",r,"_d"),s===u&&(r.width=h.width,r.height=h.height,r.dummy="edge-label",r.labelpos=h.labelpos),e.setEdge(i,n,{weight:h.weight},l),0===o&&e.graph().dummyChains.push(n),i=n;e.setEdge(i,a,{weight:h.weight},l)}(e,t))}function ge(e){let t={};e.sources().forEach(function n(r){let o=e.node(r);if(Object.hasOwn(t,r))return o.rank;t[r]=!0;let i=e.outEdges(r),s=i?i.map(t=>null==t?Number.POSITIVE_INFINITY:n(t.w)-e.edge(t).minlen):[],a=H(Math.min,s);return a===Number.POSITIVE_INFINITY&&(a=0),o.rank=a})}function pe(e,t){return e.node(t.w).rank-e.node(t.v).rank-e.edge(t).minlen}var ve=function(e){let t=new h({directed:!1}),n=e.nodes();if(0===n.length)throw new Error("Graph must have at least one node");let r,o,i=n[0],s=e.nodeCount();for(t.setNode(i,{});me(t,e)<s&&(r=we(t,e),r);)o=t.hasNode(r.v)?pe(e,r):-pe(e,r),Ee(t,e,o);return t};function me(e,t){return e.nodes().forEach(function n(r){let o=t.nodeEdges(r);o&&o.forEach(o=>{let i=o.v,s=r===i?o.w:i;!e.hasNode(s)&&!pe(t,o)&&(e.setNode(s,{}),e.setEdge(r,s,{}),n(s))})}),e.nodeCount()}function we(e,t){return t.edges().reduce((n,r)=>{let o=Number.POSITIVE_INFINITY;return e.hasNode(r.v)!==e.hasNode(r.w)&&(o=pe(t,r)),o<n[0]?[o,r]:n},[Number.POSITIVE_INFINITY,null])[1]}function Ee(e,t,n){e.nodes().forEach(e=>t.node(e).rank+=n)}var{preorder:be,postorder:ye}=y,_e=ke;function ke(e){e=function(e){let t=(new h).setGraph(e.graph());return e.nodes().forEach(n=>t.setNode(n,e.node(n))),e.edges().forEach(n=>{let r=t.edge(n.v,n.w)||{weight:0,minlen:1},o=e.edge(n);t.setEdge(n.v,n.w,{weight:r.weight+o.weight,minlen:Math.max(r.minlen,o.minlen)})}),t}(e),ge(e);let t,n,r=ve(e);for(Oe(r),xe(r,e);t=je(r);)n=Ce(r,e,t),Me(r,e,t,n)}function xe(e,t){let n=ye(e,e.nodes());n=n.slice(0,n.length-1),n.forEach(n=>function(e,t,n){let r=e.node(n).parent,o=e.edge(n,r);o.cutvalue=Ne(e,t,n)}(e,t,n))}function Ne(e,t,n){let r=e.node(n).parent,o=!0,i=t.edge(n,r),s=0;i||(o=!1,i=t.edge(r,n)),s=i.weight;let a=t.nodeEdges(n);return a&&a.forEach(i=>{let a=i.v===n,d=a?i.w:i.v;if(d!==r){let r=a===o,l=t.edge(i).weight;if(s+=r?l:-l,function(e,t,n){return e.hasEdge(t,n)}(e,n,d)){let t=e.edge(n,d).cutvalue;s+=r?-t:t}}}),s}function Oe(e,t){arguments.length<2&&(t=e.nodes()[0]),Ie(e,{},1,t)}function Ie(e,t,n,r,o){let i=n,s=e.node(r);t[r]=!0;let a=e.neighbors(r);return a&&a.forEach(o=>{Object.hasOwn(t,o)||(n=Ie(e,t,n,o,r))}),s.low=i,s.lim=n++,o?s.parent=o:delete s.parent,n}function je(e){return e.edges().find(t=>e.edge(t).cutvalue<0)}function Ce(e,t,n){let r=n.v,o=n.w;t.hasEdge(r,o)||(r=n.w,o=n.v);let i=e.node(r),s=e.node(o),a=i,d=!1;return i.lim>s.lim&&(a=s,d=!0),t.edges().filter(t=>d===Se(e,e.node(t.v),a)&&d!==Se(e,e.node(t.w),a)).reduce((e,n)=>pe(t,n)<pe(t,e)?n:e)}function Me(e,t,n,r){let o=n.v,i=n.w;e.removeEdge(o,i),e.setEdge(r.v,r.w,{}),Oe(e),xe(e,t),function(e,t){let n=e.nodes().find(t=>!e.node(t).parent);if(!n)return;let r=be(e,[n]);r=r.slice(1),r.forEach(n=>{let r=e.node(n).parent,o=t.edge(n,r),i=!1;o||(o=t.edge(r,n),i=!0),t.node(n).rank=t.node(r).rank+(i?o.minlen:-o.minlen)})}(e,t)}function Se(e,t,n){return n.low<=t.lim&&t.lim<=n.lim}ke.initLowLimValues=Oe,ke.initCutValues=xe,ke.calcCutValue=Ne,ke.leaveEdge=je,ke.enterEdge=Ce,ke.exchangeEdges=Me;var Te=function(e){let t=e.graph().ranker;if("function"==typeof t)return t(e);switch(t){case"network-simplex":default:Pe(e);break;case"tight-tree":!function(e){ge(e),ve(e)}(e);break;case"longest-path":Le(e);case"none":}};var Le=ge;function Pe(e){_e(e)}var De=function(e){let t=function(e){let t={},n=0;function r(o){let i=n;e.children(o).forEach(r),t[o]={low:i,lim:n++}}return e.children(oe).forEach(r),t}(e);e.graph().dummyChains.forEach(n=>{let r=e.node(n),o=r.edgeObj,i=function(e,t,n,r){let o,i=[],s=[],a=Math.min(t[n].low,t[r].low),d=Math.max(t[n].lim,t[r].lim);o=n;do{o=e.parent(o),i.push(o)}while(o&&(t[o].low>a||d>t[o].lim));let l=o,h=r;for(;(h=e.parent(h))!==l;)s.push(h);return{path:i.concat(s.reverse()),lca:l}}(e,t,o.v,o.w),s=i.path,a=i.lca,d=0,l=s[d],h=!0;for(;n!==o.w;){if(r=e.node(n),h){for(;(l=s[d])!==a&&e.node(l).maxRank<r.rank;)d++;l===a&&(h=!1)}if(!h){for(;d<s.length-1&&e.node(s[d+1]).minRank<=r.rank;)d++;l=s[d]}void 0!==l&&e.setParent(n,l),n=e.successors(n)[0]}})};function Fe(e){let t=z(e,"root",{},"_root"),n=function(e){let t={};function n(r,o){let i=e.children(r);i&&i.length&&i.forEach(e=>n(e,o+1)),t[r]=o}return e.children(oe).forEach(e=>n(e,1)),t}(e),r=Object.values(n),o=H(Math.max,r)-1,i=2*o+1;e.graph().nestingRoot=t,e.edges().forEach(t=>e.edge(t).minlen*=i);let s=function(e){return e.edges().reduce((t,n)=>t+e.edge(n).weight,0)}(e)+1;e.children(oe).forEach(r=>Re(e,t,i,s,o,n,r)),e.graph().nodeRankFactor=i}function Re(e,t,n,r,o,i,s){var a;let d=e.children(s);if(!d.length)return void(s!==t&&e.setEdge(t,s,{weight:0,minlen:n}));let l=U(e,"_bt"),h=U(e,"_bb"),u=e.node(s);e.setParent(l,s),u.borderTop=l,e.setParent(h,s),u.borderBottom=h,d.forEach(a=>{var d;Re(e,t,n,r,o,i,a);let u=e.node(a),c=u.borderTop?u.borderTop:a,f=u.borderBottom?u.borderBottom:a,g=u.borderTop?r:2*r,p=c!==f?1:o-(null!=(d=i[s])?d:0)+1;e.setEdge(l,c,{weight:g,minlen:p,nestingEdge:!0}),e.setEdge(f,h,{weight:g,minlen:p,nestingEdge:!0})}),e.parent(s)||e.setEdge(t,l,{weight:0,minlen:o+(null!=(a=i[s])?a:0)})}var Ve=function(e){e.children(oe).forEach(function t(n){let r=e.children(n),o=e.node(n);if(r.length&&r.forEach(t),Object.hasOwn(o,"minRank")){o.borderLeft=[],o.borderRight=[];for(let t=o.minRank,r=o.maxRank+1;t<r;++t)Ae(e,"borderLeft","_bl",n,o,t),Ae(e,"borderRight","_br",n,o,t)}})};function Ae(e,t,n,r,o,i){let s={width:0,height:0,rank:i,borderType:t},a=o[t][i-1],d=z(e,"border",s,n);o[t][i]=d,e.setParent(d,r),a&&e.setEdge(a,d,{weight:1})}function Ge(e){var t;let n=null==(t=e.graph().rankdir)?void 0:t.toLowerCase();("bt"===n||"rl"===n)&&function(e){e.nodes().forEach(t=>ze(e.node(t))),e.edges().forEach(t=>{var n;let r=e.edge(t);null==(n=r.points)||n.forEach(ze),Object.hasOwn(r,"y")&&ze(r)})}(e),("lr"===n||"rl"===n)&&(function(e){e.nodes().forEach(t=>qe(e.node(t))),e.edges().forEach(t=>{var n;let r=e.edge(t);null==(n=r.points)||n.forEach(qe),Object.hasOwn(r,"x")&&qe(r)})}(e),Ye(e))}function Ye(e){e.nodes().forEach(t=>Be(e.node(t))),e.edges().forEach(t=>Be(e.edge(t)))}function Be(e){let t=e.width;e.width=e.height,e.height=t}function ze(e){e.y=-e.y}function qe(e){let t=e.x;e.x=e.y,e.y=t}function We(e,t){let n=0;for(let r=1;r<t.length;++r)n+=$e(e,t[r-1],t[r]);return n}function $e(e,t,n){let r=function(e,t){return e.reduce((e,n,r)=>(e[n]=t[r],e),{})}(n,n.map((e,t)=>t)),o=t.flatMap(t=>{let n=e.outEdges(t);return n?n.map(t=>({pos:r[t.w],weight:e.edge(t).weight})).sort((e,t)=>e.pos-t.pos):[]}),i=1;for(;i<n.length;)i<<=1;let s=2*i-1;i-=1;let a=new Array(s).fill(0),d=0;return o.forEach(e=>{let t=e.pos+i;a[t]+=e.weight;let n=0;for(;t>0;)t%2&&(n+=a[t+1]),t=t-1>>1,a[t]+=e.weight;d+=e.weight*n}),d}function Ue(e,t){let n={};return e.forEach((e,t)=>{let r={indegree:0,in:[],out:[],vs:[e.v],i:t};void 0!==e.barycenter&&(r.barycenter=e.barycenter,r.weight=e.weight),n[e.v]=r}),t.edges().forEach(e=>{let t=n[e.v],r=n[e.w];void 0!==t&&void 0!==r&&(r.indegree++,t.out.push(r))}),function(e){let t=[];function n(e){return t=>{t.merged||(void 0===t.barycenter||void 0===e.barycenter||t.barycenter>=e.barycenter)&&function(e,t){let n=0,r=0;e.weight&&(n+=e.barycenter*e.weight,r+=e.weight),t.weight&&(n+=t.barycenter*t.weight,r+=t.weight),e.vs=t.vs.concat(e.vs),e.barycenter=n/r,e.weight=r,e.i=Math.min(t.i,e.i),t.merged=!0}(e,t)}}function r(t){return n=>{n.in.push(t),0===--n.indegree&&e.push(n)}}for(;e.length;){let o=e.pop();t.push(o),o.in.reverse().forEach(n(o)),o.out.forEach(r(o))}return t.filter(e=>!e.merged).map(e=>ne(e,["vs","i","barycenter","weight"]))}(Object.values(n).filter(e=>!e.indegree))}function Ke(e,t,n){let r;for(;t.length&&(r=t[t.length-1]).i<=n;)t.pop(),e.push(r.vs),n++;return n}function He(e,t,n,r){let o=e.children(t),i=e.node(t),s=i?i.borderLeft:void 0,a=i?i.borderRight:void 0,d={};s&&(o=o.filter(e=>e!==s&&e!==a));let l=function(e,t=[]){return t.map(t=>{let n=e.inEdges(t);if(!n||!n.length)return{v:t};{let r=n.reduce((t,n)=>{let r=e.edge(n),o=e.node(n.v);return{sum:t.sum+r.weight*o.order,weight:t.weight+r.weight}},{sum:0,weight:0});return{v:t,barycenter:r.sum/r.weight,weight:r.weight}}})}(e,o);l.forEach(t=>{if(e.children(t.v).length){let o=He(e,t.v,n,r);d[t.v]=o,Object.hasOwn(o,"barycenter")&&function(e,t){void 0!==e.barycenter?(e.barycenter=(e.barycenter*e.weight+t.barycenter*t.weight)/(e.weight+t.weight),e.weight+=t.weight):(e.barycenter=t.barycenter,e.weight=t.weight)}(t,o)}});let h=Ue(l,n);!function(e,t){e.forEach(e=>{e.vs=e.vs.flatMap(e=>t[e]?t[e].vs:e)})}(h,d);let u=function(e,t){let n=function(e,t){let n={lhs:[],rhs:[]};return e.forEach(e=>{t(e)?n.lhs.push(e):n.rhs.push(e)}),n}(e,e=>Object.hasOwn(e,"barycenter")),r=n.lhs,o=n.rhs.sort((e,t)=>t.i-e.i),i=[],s=0,a=0,d=0;r.sort(function(e){return(t,n)=>t.barycenter<n.barycenter?-1:t.barycenter>n.barycenter?1:e?n.i-t.i:t.i-n.i}(!!t)),d=Ke(i,o,d),r.forEach(e=>{d+=e.vs.length,i.push(e.vs),s+=e.barycenter*e.weight,a+=e.weight,d=Ke(i,o,d)});let l={vs:i.flat(1)};return a&&(l.barycenter=s/a,l.weight=a),l}(h,r);if(s&&a){u.vs=[s,u.vs,a].flat(1);let t=e.predecessors(s);if(t&&t.length){let n=e.node(t[0]),r=e.predecessors(a),o=e.node(r[0]);Object.hasOwn(u,"barycenter")||(u.barycenter=0,u.weight=0),u.barycenter=(u.barycenter*u.weight+n.order+o.order)/(u.weight+2),u.weight+=2}}return u}function Je(e,t,n,r){r||(r=e.nodes());let o=function(e){let t;for(;e.hasNode(t=ee("_root")););return t}(e),i=new h({compound:!0}).setGraph({root:o}).setDefaultNodeLabel(t=>e.node(t));return r.forEach(r=>{let s=e.node(r),a=e.parent(r);if(s.rank===t||s.minRank<=t&&t<=s.maxRank){i.setNode(r),i.setParent(r,a||o);let d=e[n](r);d&&d.forEach(t=>{let n=t.v===r?t.w:t.v,o=i.edge(n,r),s=void 0!==o?o.weight:0;i.setEdge(n,r,{weight:e.edge(t).weight+s})}),Object.hasOwn(s,"minRank")&&i.setNode(r,{borderLeft:s.borderLeft[t],borderRight:s.borderRight[t]})}}),i}function Qe(e,t={}){if("function"==typeof t.customOrder)return void t.customOrder(e,Qe);let n=J(e),r=Xe(e,te(1,n+1),"inEdges"),o=Xe(e,te(n-1,-1,-1),"outEdges"),i=function(e){let t={},n=e.nodes().filter(t=>!e.children(t).length),r=n.map(t=>e.node(t).rank),o=te(H(Math.max,r)+1).map(()=>[]);return n.sort((t,n)=>e.node(t).rank-e.node(n).rank).forEach(function n(r){if(t[r])return;t[r]=!0;let i=e.node(r);o[i.rank].push(r);let s=e.successors(r);s&&s.forEach(n)}),o}(e);if(et(e,i),t.disableOptimalOrderHeuristic)return;let s,a=Number.POSITIVE_INFINITY,d=t.constraints||[];for(let t=0,n=0;n<4;++t,++n){Ze(t%2?r:o,t%4>=2,d),i=$(e);let l=We(e,i);l<a?(n=0,s=Object.assign({},i),a=l):l===a&&(s=structuredClone(i))}et(e,s)}function Xe(e,t,n){let r=new Map,o=(e,t)=>{r.has(e)||r.set(e,[]),r.get(e).push(t)};for(let t of e.nodes()){let n=e.node(t);if("number"==typeof n.rank&&o(n.rank,t),"number"==typeof n.minRank&&"number"==typeof n.maxRank)for(let e=n.minRank;e<=n.maxRank;e++)e!==n.rank&&o(e,t)}return t.map(function(t){return Je(e,t,n,r.get(t)||[])})}function Ze(e,t,n){let r=new h;e.forEach(function(e){n.forEach(e=>r.setEdge(e.left,e.right));let o=e.graph().root,i=He(e,o,r,t);i.vs.forEach((t,n)=>e.node(t).order=n),function(e,t,n){let r,o={};n.forEach(n=>{let i,s,a=e.parent(n);for(;a;){if(i=e.parent(a),i?(s=o[i],o[i]=a):(s=r,r=a),s&&s!==a)return void t.setEdge(s,a);a=i}})}(e,r,i.vs)})}function et(e,t){Object.values(t).forEach(t=>t.forEach((t,n)=>e.node(t).order=n))}function tt(e,t,n){if(t>n){let e=t;t=n,n=e}let r=e[t];r||(e[t]=r={}),r[n]=!0}function nt(e,t,n){if(t>n){let e=t;t=n,n=e}let r=e[t];return void 0!==r&&Object.hasOwn(r,n)}function rt(e,t,n,r,o=!1){let i={},s=function(e,t,n,r){let o=new h,i=e.graph(),s=function(e,t,n){return(r,o,i)=>{let s,a=r.node(o),d=r.node(i),l=0;if(l+=a.width/2,Object.hasOwn(a,"labelpos"))switch(a.labelpos.toLowerCase()){case"l":s=-a.width/2;break;case"r":s=a.width/2}if(s&&(l+=n?s:-s),s=void 0,l+=(a.dummy?t:e)/2,l+=(d.dummy?t:e)/2,l+=d.width/2,Object.hasOwn(d,"labelpos"))switch(d.labelpos.toLowerCase()){case"l":s=d.width/2;break;case"r":s=-d.width/2}return s&&(l+=n?s:-s),l}}(i.nodesep,i.edgesep,r);return t.forEach(t=>{let r;t.forEach(t=>{let i=n[t];if(void 0!==i){if(o.setNode(i),void 0!==r){let a=n[r];if(void 0!==a){let n=o.edge(a,i);o.setEdge(a,i,Math.max(s(e,t,r),n||0))}}r=t}})}),o}(e,t,n,o),a=o?"borderLeft":"borderRight";function d(e,t){let n=s.nodes().slice(),r={},o=n.pop();for(;o;){if(r[o])e(o);else{r[o]=!0,n.push(o);for(let e of t(o))n.push(e)}o=n.pop()}}return d(function(e){let t=s.inEdges(e);i[e]=t?t.reduce((e,t)=>{var n;let r=null!=(n=i[t.v])?n:0,o=s.edge(t);return Math.max(e,r+(void 0!==o?o:0))},0):0},function(e){return s.predecessors(e)||[]}),d(function(t){let n=s.outEdges(t),r=Number.POSITIVE_INFINITY;n&&(r=n.reduce((e,t)=>{let n=i[t.w],r=s.edge(t);return Math.min(e,(void 0!==n?n:0)-(void 0!==r?r:0))},Number.POSITIVE_INFINITY));let o=e.node(t);r!==Number.POSITIVE_INFINITY&&o.borderType!==a&&(i[t]=Math.max(void 0!==i[t]?i[t]:0,r))},function(e){return s.successors(e)||[]}),Object.keys(r).forEach(e=>{var t;let r=n[e];void 0!==r&&(i[e]=null!=(t=i[r])?t:0)}),i}function ot(e){let t,n=$(e),r=Object.assign(function(e,t){let n={};return t.length&&t.reduce(function(t,r){let o=0,i=0,s=t.length,a=r[r.length-1];return r.forEach((t,d)=>{let l=function(e,t){if(e.node(t).dummy){let n=e.predecessors(t);if(n)return n.find(t=>e.node(t).dummy)}}(e,t),h=l?e.node(l).order:s;(l||t===a)&&(r.slice(i,d+1).forEach(t=>{let r=e.predecessors(t);r&&r.forEach(r=>{let i=e.node(r),s=i.order;(s<o||h<s)&&(!i.dummy||!e.node(t).dummy)&&tt(n,r,t)})}),i=d+1,o=h)}),r}),n}(e,n),function(e,t){let n={};function r(t,r,o,i,s){te(r,o).forEach(r=>{let o=t[r];if(void 0!==o&&e.node(o).dummy){let t=e.predecessors(o);t&&t.forEach(t=>{if(void 0===t)return;let r=e.node(t);r.dummy&&(r.order<i||r.order>s)&&tt(n,t,o)})}})}return t.length&&t.reduce(function(t,n){let o=-1,i=-1,s=0;return n.forEach((a,d)=>{if("border"===e.node(a).dummy){let t=e.predecessors(a);if(t&&t.length){let a=t[0];if(void 0===a)return;i=e.node(a).order,r(n,s,d,o,i),s=d,o=i}}r(n,s,n.length,i,t.length)}),n}),n}(e,n)),o={};["u","d"].forEach(i=>{t="u"===i?n:Object.values(n).reverse(),["l","r"].forEach(n=>{"r"===n&&(t=t.map(e=>Object.values(e).reverse()));let s=function(e,t,n,r){let o={},i={},s={};return t.forEach(e=>{e.forEach((e,t)=>{o[e]=e,i[e]=e,s[e]=t})}),t.forEach(e=>{let t=-1;e.forEach(e=>{let a=r(e);if(a&&a.length){let r=a.sort((e,t)=>{let n=s[e],r=s[t];return(void 0!==n?n:0)-(void 0!==r?r:0)}),d=(r.length-1)/2;for(let a=Math.floor(d),l=Math.ceil(d);a<=l;++a){let d=r[a];if(void 0===d)continue;let l=s[d];if(void 0!==l&&i[e]===e&&t<l&&!nt(n,e,d)){let n=o[d];void 0!==n&&(i[d]=e,i[e]=o[e]=n,t=l)}}}})}),{root:o,align:i}}(0,t,r,t=>("u"===i?e.predecessors(t):e.successors(t))||[]),a=rt(e,t,s.root,s.align,"r"===n);"r"===n&&(a=re(a,e=>-e)),o[i+n]=a})});let i=function(e,t){return Object.values(t).reduce((t,n)=>{let r=Number.NEGATIVE_INFINITY,o=Number.POSITIVE_INFINITY;Object.entries(n).forEach(([t,n])=>{let i=function(e,t){return e.node(t).width}(e,t)/2;r=Math.max(n+i,r),o=Math.min(n-i,o)});let i=r-o;return i<t[0]&&(t=[i,n]),t},[Number.POSITIVE_INFINITY,null])[1]}(e,o);return function(e,t){let n=Object.values(t),r=H(Math.min,n),o=H(Math.max,n);["u","d"].forEach(n=>{["l","r"].forEach(i=>{let s=n+i,a=e[s];if(!a||a===t)return;let d=Object.values(a),l=r-H(Math.min,d);"l"!==i&&(l=o-H(Math.max,d)),l&&(e[s]=re(a,e=>e+l))})})}(o,i),function(e,t){let n=e.ul;return n?re(n,(n,r)=>{var o,i;if(t){let n=t.toLowerCase(),o=e[n];if(o&&void 0!==o[r])return o[r]}let s=Object.values(e).map(e=>{let t=e[r];return void 0!==t?t:0}).sort((e,t)=>e-t);return((null!=(o=s[1])?o:0)+(null!=(i=s[2])?i:0))/2}):{}}(o,e.graph().align)}function it(e){(function(e){let t=$(e),n=e.graph(),r=n.ranksep,o=n.rankalign,i=0;t.forEach(t=>{let n=t.reduce((t,n)=>{var r;let o=null!=(r=e.node(n).height)?r:0;return t>o?t:o},0);t.forEach(t=>{let r=e.node(t);r.y="top"===o?i+r.height/2:"bottom"===o?i+n-r.height/2:i+n/2}),i+=n+r})})(e=q(e)),Object.entries(ot(e)).forEach(([t,n])=>e.node(t).x=n)}var st=["nodesep","edgesep","ranksep","marginx","marginy"],at={ranksep:50,edgesep:20,nodesep:50,rankdir:"TB",rankalign:"center"},dt=["acyclicer","ranker","rankdir","align","rankalign"],lt=["width","height","rank"],ht={width:0,height:0},ut=["minlen","weight","width","height","labeloffset"],ct={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},ft=["labelpos"];function gt(e,t){return re(ne(e,t),Number)}function pt(e){let t={};return e&&Object.entries(e).forEach(([e,n])=>{"string"==typeof e&&(e=e.toLowerCase()),t[e]=n}),t}var vt={graphlib:a,version:"3.0.0",layout:function(e,t={}){let n=t.debugTiming?Q:X;return n("layout",()=>{let r=n(" buildLayoutGraph",()=>function(e){let t=new h({multigraph:!0,compound:!0}),n=pt(e.graph());return t.setGraph(Object.assign({},at,gt(n,st),ne(n,dt))),e.nodes().forEach(n=>{let r=gt(pt(e.node(n)),lt);Object.keys(ht).forEach(e=>{void 0===r[e]&&(r[e]=ht[e])}),t.setNode(n,r);let o=e.parent(n);void 0!==o&&t.setParent(n,o)}),e.edges().forEach(n=>{let r=pt(e.edge(n));t.setEdge(n,Object.assign({},ct,gt(r,ut),ne(r,ft)))}),t}(e));return n(" runLayout",()=>function(e,t,n){t(" makeSpaceForEdgeLabels",()=>function(e){let t=e.graph();t.ranksep/=2,e.edges().forEach(n=>{let r=e.edge(n);r.minlen*=2,"c"!==r.labelpos.toLowerCase()&&("TB"===t.rankdir||"BT"===t.rankdir?r.width+=r.labeloffset:r.height+=r.labeloffset)})}(e)),t(" removeSelfEdges",()=>function(e){e.edges().forEach(t=>{if(t.v===t.w){let n=e.node(t.v);n.selfEdges||(n.selfEdges=[]),n.selfEdges.push({e:t,label:e.edge(t)}),e.removeEdge(t)}})}(e)),t(" acyclic",()=>ce(e)),t(" nestingGraph.run",()=>Fe(e)),t(" rank",()=>Te(q(e))),t(" injectEdgeLabelProxies",()=>function(e){e.edges().forEach(t=>{let n=e.edge(t);if(n.width&&n.height){let n=e.node(t.v),r={rank:(e.node(t.w).rank-n.rank)/2+n.rank,e:t};z(e,"edge-proxy",r,"_ep")}})}(e)),t(" removeEmptyRanks",()=>function(e){let t=e.nodes().map(t=>e.node(t).rank).filter(e=>void 0!==e),n=H(Math.min,t),r=[];e.nodes().forEach(t=>{let o=e.node(t).rank-n;r[o]||(r[o]=[]),r[o].push(t)});let o=0,i=e.graph().nodeRankFactor;Array.from(r).forEach((t,n)=>{void 0===t&&n%i!==0?--o:void 0!==t&&o&&t.forEach(t=>e.node(t).rank+=o)})}(e)),t(" nestingGraph.cleanup",()=>function(e){let t=e.graph();e.removeNode(t.nestingRoot),delete t.nestingRoot,e.edges().forEach(t=>{e.edge(t).nestingEdge&&e.removeEdge(t)})}(e)),t(" normalizeRanks",()=>function(e){let t=e.nodes().map(t=>{let n=e.node(t).rank;return void 0===n?Number.MAX_VALUE:n}),n=H(Math.min,t);e.nodes().forEach(t=>{let r=e.node(t);Object.hasOwn(r,"rank")&&(r.rank-=n)})}(e)),t(" assignRankMinMax",()=>function(e){let t=0;e.nodes().forEach(n=>{let r=e.node(n);r.borderTop&&(r.minRank=e.node(r.borderTop).rank,r.maxRank=e.node(r.borderBottom).rank,t=Math.max(t,r.maxRank))}),e.graph().maxRank=t}(e)),t(" removeEdgeLabelProxies",()=>function(e){e.nodes().forEach(t=>{let n=e.node(t);if("edge-proxy"===n.dummy){let r=n;e.edge(r.e).labelRank=n.rank,e.removeNode(t)}})}(e)),t(" normalize.run",()=>fe(e)),t(" parentDummyChains",()=>De(e)),t(" addBorderSegments",()=>Ve(e)),t(" order",()=>Qe(e,n)),t(" insertSelfEdges",()=>function(e){$(e).forEach(t=>{let n=0;t.forEach((t,r)=>{let o=e.node(t);o.order=r+n,(o.selfEdges||[]).forEach(t=>{z(e,"selfedge",{width:t.label.width,height:t.label.height,rank:o.rank,order:r+ ++n,e:t.e,label:t.label},"_se")}),delete o.selfEdges})})}(e)),t(" adjustCoordinateSystem",()=>function(e){var t;let n=null==(t=e.graph().rankdir)?void 0:t.toLowerCase();("lr"===n||"rl"===n)&&Ye(e)}(e)),t(" position",()=>it(e)),t(" positionSelfEdges",()=>function(e){e.nodes().forEach(t=>{let n=e.node(t);if("selfedge"===n.dummy){let r=n,o=e.node(r.e.v),i=o.x+o.width/2,s=o.y,a=n.x-i,d=o.height/2;e.setEdge(r.e,r.label),e.removeNode(t),r.label.points=[{x:i+2*a/3,y:s-d},{x:i+5*a/6,y:s-d},{x:i+a,y:s},{x:i+5*a/6,y:s+d},{x:i+2*a/3,y:s+d}],r.label.x=n.x,r.label.y=n.y}})}(e)),t(" removeBorderNodes",()=>function(e){e.nodes().forEach(t=>{if(e.children(t).length){let n=e.node(t),r=e.node(n.borderTop),o=e.node(n.borderBottom),i=e.node(n.borderLeft[n.borderLeft.length-1]),s=e.node(n.borderRight[n.borderRight.length-1]);n.width=Math.abs(s.x-i.x),n.height=Math.abs(o.y-r.y),n.x=i.x+n.width/2,n.y=r.y+n.height/2}}),e.nodes().forEach(t=>{"border"===e.node(t).dummy&&e.removeNode(t)})}(e)),t(" normalize.undo",()=>function(e){e.graph().dummyChains.forEach(t=>{let n,r=e.node(t),o=r.edgeLabel;for(e.setEdge(r.edgeObj,o);r.dummy;)n=e.successors(t)[0],e.removeNode(t),o.points.push({x:r.x,y:r.y}),"edge-label"===r.dummy&&(o.x=r.x,o.y=r.y,o.width=r.width,o.height=r.height),t=n,r=e.node(t)})}(e)),t(" fixupEdgeLabelCoords",()=>function(e){e.edges().forEach(t=>{let n=e.edge(t);if(Object.hasOwn(n,"x"))switch(("l"===n.labelpos||"r"===n.labelpos)&&(n.width-=n.labeloffset),n.labelpos){case"l":n.x-=n.width/2+n.labeloffset;break;case"r":n.x+=n.width/2+n.labeloffset}})}(e)),t(" undoCoordinateSystem",()=>Ge(e)),t(" translateGraph",()=>function(e){let t=Number.POSITIVE_INFINITY,n=0,r=Number.POSITIVE_INFINITY,o=0,i=e.graph(),s=i.marginx||0,a=i.marginy||0;function d(e){let i=e.x,s=e.y,a=e.width,d=e.height;t=Math.min(t,i-a/2),n=Math.max(n,i+a/2),r=Math.min(r,s-d/2),o=Math.max(o,s+d/2)}e.nodes().forEach(t=>d(e.node(t))),e.edges().forEach(t=>{let n=e.edge(t);Object.hasOwn(n,"x")&&d(n)}),t-=s,r-=a,e.nodes().forEach(n=>{let o=e.node(n);o.x-=t,o.y-=r}),e.edges().forEach(n=>{let o=e.edge(n);o.points.forEach(e=>{e.x-=t,e.y-=r}),Object.hasOwn(o,"x")&&(o.x-=t),Object.hasOwn(o,"y")&&(o.y-=r)}),i.width=n-t+s,i.height=o-r+a}(e)),t(" assignNodeIntersects",()=>function(e){e.edges().forEach(t=>{let n,r,o=e.edge(t),i=e.node(t.v),s=e.node(t.w);o.points?(n=o.points[0],r=o.points[o.points.length-1]):(o.points=[],n=s,r=i),o.points.unshift(W(i,n)),o.points.push(W(s,r))})}(e)),t(" reversePoints",()=>function(e){e.edges().forEach(t=>{let n=e.edge(t);n.reversed&&n.points.reverse()})}(e)),t(" acyclic.undo",()=>function(e){e.edges().forEach(t=>{let n=e.edge(t);if(n.reversed){e.removeEdge(t);let r=n.forwardName;delete n.reversed,delete n.forwardName,e.setEdge(t.w,t.v,n,r)}})}(e))}(r,n,t)),n(" updateInputGraph",()=>function(e,t){e.nodes().forEach(n=>{let r=e.node(n),o=t.node(n);r&&(r.x=o.x,r.y=o.y,r.order=o.order,r.rank=o.rank,t.children(n).length&&(r.width=o.width,r.height=o.height))}),e.edges().forEach(n=>{let r=e.edge(n),o=t.edge(n);r.points=o.points,Object.hasOwn(o,"x")&&(r.x=o.x,r.y=o.y)}),e.graph().width=t.graph().width,e.graph().height=t.graph().height}(e,r)),r})},debug:function(e){let t=$(e),n=new h({compound:!0,multigraph:!0}).setGraph({});return e.nodes().forEach(t=>{n.setNode(t,{label:t}),n.setParent(t,"layer"+e.node(t).rank)}),e.edges().forEach(e=>n.setEdge(e.v,e.w,{},e.name)),t.forEach((e,t)=>{let r="layer"+t;n.setNode(r,{rank:"same"}),e.reduce((e,t)=>(n.setEdge(e,t,{style:"invis"}),t))}),n},util:{time:Q,notime:X}},mt=function(e){return"function"==typeof e},wt=.001;/*! For license information please see dagre.esm.js.LEGAL.txt */function Et(e){this.options=o({},r,e)}function bt(e,t){return{x:kt(e.x-t.x),y:kt(e.y-t.y)}}function yt(e,t){return kt(e.x*t.x)+kt(e.y*t.y)}function _t(e,t){var n=function(e){var t=Math.hypot(e.x,e.y)||1;return{x:e.x/t,y:e.y/t,len:t}}(bt(t,e)),r=n.x,o=n.y,i=n.len,s={x:r,y:o},a=function(e){return{x:-e.y,y:e.x}}(s);return{src:e,tgt:t,dir:s,normal:a,len:i}}function kt(e){return Math.abs(e)<wt?e<0?-.001:wt:e}function xt(e,n){var r=_t(n.source().position(),n.target().position()),o=function(e){var n,r=1/0,o=-1/0,i=t(e);try{for(i.s();!(n=i.n()).done;){var s=n.value;s.weight<r&&(r=s.weight),s.weight>o&&(o=s.weight)}}catch(e){i.e(e)}finally{i.f()}var a=o-r||1;return e.map(function(e){return{distance:e.distance,weight:(e.weight-r)/a}})}(e.points.map(function(e){return function(e,t){var n=bt(e,t.src);return{weight:kt(yt(n,t.dir)/t.len),distance:kt(yt(n,t.normal))}}(e,r)}));return{controlPointWeights:o.slice(1,-1).map(function(e){return e.weight}),controlPointDistances:o.slice(1,-1).map(function(e){return e.distance})}}Et.prototype.run=function(){var e=this.options,t=e.cy,r=e.eles,o=function(e,t){return mt(t)?t.apply(e,[e]):t},i=e.boundingBox||{x1:0,y1:0,w:t.width(),h:t.height()};void 0===i.x2&&(i.x2=i.x1+i.w),void 0===i.w&&(i.w=i.x2-i.x1),void 0===i.y2&&(i.y2=i.y1+i.h),void 0===i.h&&(i.h=i.y2-i.y1);var s=new vt.graphlib.Graph({multigraph:!0,compound:!0}),a={},d=function(e,t){null!=t&&(a[e]=t)};d("nodesep",e.nodeSep),d("edgesep",e.edgeSep),d("ranksep",e.rankSep),d("rankdir",e.rankDir),d("align",e.align),d("ranker",e.ranker),d("acyclicer",e.acyclicer),s.setGraph(a),s.setDefaultEdgeLabel(function(){return{}}),s.setDefaultNodeLabel(function(){return{}});var l=r.nodes();mt(e.sort)&&(l=l.sort(e.sort));for(var h=0;h<l.length;h++){var u=l[h],c=u.layoutDimensions(e);s.setNode(u.id(),{width:c.w,height:c.h,shape:"ellipse",name:u.id()})}for(var f=0;f<l.length;f++){var g=l[f];g.isChild()&&s.setParent(g.id(),g.parent().id())}var p=r.edges().stdFilter(function(e){return!e.source().isParent()&&!e.target().isParent()});mt(e.sort)&&(p=p.sort(e.sort));for(var v=0;v<p.length;v++){var m=p[v];s.setEdge(m.source().id(),m.target().id(),{minlen:o(m,e.minLen),weight:o(m,e.edgeWeight),name:m.id()},m.id())}vt.layout(s);for(var w,E=s.nodes(),b=0;b<E.length;b++){var y=E[b],_=s.node(y);t.getElementById(y).scratch().dagre=_}e.boundingBox?(w={x1:1/0,x2:-1/0,y1:1/0,y2:-1/0},l.forEach(function(e){var t=e.scratch().dagre;w.x1=Math.min(w.x1,t.x),w.x2=Math.max(w.x2,t.x),w.y1=Math.min(w.y1,t.y),w.y2=Math.max(w.y2,t.y)}),w.w=w.x2-w.x1,w.h=w.y2-w.y1):w=i;return l.layoutPositions(this,e,function(t){var r=(t="object"===n(t)?t:this).scratch().dagre;return function(t){if(e.boundingBox){var n=0===w.w?0:(t.x-w.x1)/w.w,r=0===w.h?0:(t.y-w.y1)/w.h;return{x:i.x1+n*i.w,y:i.y1+r*i.h}}return t}({x:r.x,y:r.y})}),e.useDagreEdgeControlPoints&&(e.automaticDagreEdgeStyle&&(t.edges().addClass("useDagreEdgeControlPoints"),t.style().selector("edge.useDagreEdgeControlPoints").style(e.dagreEdgeStyle).update()),s.edges().forEach(function(e){var n=t.getElementById(e.name),r=s.edge(e);r&&r.points&&n.scratch(xt(r,n))})),this};var Nt=function(e){e&&e("layout","dagre",Et)};return"undefined"!=typeof window&&void 0!==window.cytoscape&&Nt(window.cytoscape),Nt}); //# sourceMappingURL=cytoscape-dagre.min.js.map