You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2 lines
24 KiB

import{G as k}from"./graph-044629d9.js";import{r as y,u as q,m as R,a as x,b as W,f as z,z as Ee,s as C,c as O,e as ye,g as Ne,d as Le}from"./zipObject-0e7af259.js";import{f,h as m,a as T,v as N,r as F}from"./reduce-bb35cf56.js";import{ae as S,ac as w,af as Ie,ag as K,aa as g,ah as Re,p as M,ai as P,aj as _e,ak as j}from"./index-6b91f299.js";class Ce{constructor(){var n={};n._next=n._prev=n,this._sentinel=n}dequeue(){var n=this._sentinel,r=n._prev;if(r!==n)return Q(r),r}enqueue(n){var r=this._sentinel;n._prev&&n._next&&Q(n),n._next=r._next,r._next._prev=n,r._next=n,n._prev=r}toString(){for(var n=[],r=this._sentinel,t=r._prev;t!==r;)n.push(JSON.stringify(t,Te)),t=t._prev;return"["+n.join(", ")+"]"}}function Q(e){e._prev._next=e._next,e._next._prev=e._prev,delete e._next,delete e._prev}function Te(e,n){if(e!=="_next"&&e!=="_prev")return n}var Se=Ie(1);function Me(e,n){if(e.nodeCount()<=1)return[];var r=Oe(e,n||Se),t=Pe(r.graph,r.buckets,r.zeroIdx);return S(w(t,function(i){return e.outEdges(i.v,i.w)}))}function Pe(e,n,r){for(var t=[],i=n[n.length-1],o=n[0],a;e.nodeCount();){for(;a=o.dequeue();)B(e,n,r,a);for(;a=i.dequeue();)B(e,n,r,a);if(e.nodeCount()){for(var u=n.length-2;u>0;--u)if(a=n[u].dequeue(),a){t=t.concat(B(e,n,r,a,!0));break}}}return t}function B(e,n,r,t,i){var o=i?[]:void 0;return f(e.inEdges(t.v),function(a){var u=e.edge(a),d=e.node(a.v);i&&o.push({v:a.v,w:a.w}),d.out-=u,$(n,r,d)}),f(e.outEdges(t.v),function(a){var u=e.edge(a),d=a.w,s=e.node(d);s.in-=u,$(n,r,s)}),e.removeNode(t.v),o}function Oe(e,n){var r=new k,t=0,i=0;f(e.nodes(),function(u){r.setNode(u,{v:u,in:0,out:0})}),f(e.edges(),function(u){var d=r.edge(u.v,u.w)||0,s=n(u),c=d+s;r.setEdge(u.v,u.w,c),i=Math.max(i,r.node(u.v).out+=s),t=Math.max(t,r.node(u.w).in+=s)});var o=y(i+t+3).map(function(){return new Ce}),a=t+1;return f(r.nodes(),function(u){$(o,a,r.node(u))}),{graph:r,buckets:o,zeroIdx:a}}function $(e,n,r){r.out?r.in?e[r.out-r.in+n].enqueue(r):e[e.length-1].enqueue(r):e[0].enqueue(r)}function Fe(e){var n=e.graph().acyclicer==="greedy"?Me(e,r(e)):Ve(e);f(n,function(t){var i=e.edge(t);e.removeEdge(t),i.forwardName=t.name,i.reversed=!0,e.setEdge(t.w,t.v,i,q("rev"))});function r(t){return function(i){return t.edge(i).weight}}}function Ve(e){var n=[],r={},t={};function i(o){m(t,o)||(t[o]=!0,r[o]=!0,f(e.outEdges(o),function(a){m(r,a.w)?n.push(a):i(a.w)}),delete r[o])}return f(e.nodes(),i),n}function Be(e){f(e.edges(),function(n){var r=e.edge(n);if(r.reversed){e.removeEdge(n);var t=r.forwardName;delete r.reversed,delete r.forwardName,e.setEdge(n.w,n.v,r,t)}})}function L(e,n,r,t){var i;do i=q(t);while(e.hasNode(i));return r.dummy=n,e.setNode(i,r),i}function Ae(e){var n=new k().setGraph(e.graph());return f(e.nodes(),function(r){n.setNode(r,e.node(r))}),f(e.edges(),function(r){var t=n.edge(r.v,r.w)||{weight:0,minlen:1},i=e.edge(r);n.setEdge(r.v,r.w,{weight:t.weight+i.weight,minlen:Math.max(t.minlen,i.minlen)})}),n}function de(e){var n=new k({multigraph:e.isMultigraph()}).setGraph(e.graph());return f(e.nodes(),function(r){e.children(r).length||n.setNode(r,e.node(r))}),f(e.edges(),function(r){n.setEdge(r,e.edge(r))}),n}function Z(e,n){var r=e.x,t=e.y,i=n.x-r,o=n.y-t,a=e.width/2,u=e.height/2;if(!i&&!o)throw new Error("Not possible to find intersection inside of the rectangle");var d,s;return Math.abs(o)*a>Math.abs(i)*u?(o<0&&(u=-u),d=u*i/o,s=u):(i<0&&(a=-a),d=a,s=a*o/i),{x:r+d,y:t+s}}function V(e){var n=w(y(se(e)+1),function(){return[]});return f(e.nodes(),function(r){var t=e.node(r),i=t.rank;g(i)||(n[i][t.order]=r)}),n}function Ye(e){var n=R(w(e.nodes(),function(r){return e.node(r).rank}));f(e.nodes(),function(r){var t=e.node(r);m(t,"rank")&&(t.rank-=n)})}function De(e){var n=R(w(e.nodes(),function(o){return e.node(o).rank})),r=[];f(e.nodes(),function(o){var a=e.node(o).rank-n;r[a]||(r[a]=[]),r[a].push(o)});var t=0,i=e.graph().nodeRankFactor;f(r,function(o,a){g(o)&&a%i!==0?--t:t&&f(o,function(u){e.node(u).rank+=t})})}function ee(e,n,r,t){var i={width:0,height:0};return arguments.length>=4&&(i.rank=r,i.order=t),L(e,"border",i,n)}function se(e){return x(w(e.nodes(),function(n){var r=e.node(n).rank;if(!g(r))return r}))}function Ge(e,n){var r={lhs:[],rhs:[]};return f(e,function(t){n(t)?r.lhs.push(t):r.rhs.push(t)}),r}function je(e,n){var r=K();try{return n()}finally{console.log(e+" time: "+(K()-r)+"ms")}}function $e(e,n){return n()}function qe(e){function n(r){var t=e.children(r),i=e.node(r);if(t.length&&f(t,n),m(i,"minRank")){i.borderLeft=[],i.borderRight=[];for(var o=i.minRank,a=i.maxRank+1;o<a;++o)ne(e,"borderLeft","_bl",r,i,o),ne(e,"borderRight","_br",r,i,o)}}f(e.children(),n)}function ne(e,n,r,t,i,o){var a={width:0,height:0,rank:o,borderType:n},u=i[n][o-1],d=L(e,"border",a,r);i[n][o]=d,e.setParent(d,t),u&&e.setEdge(u,d,{weight:1})}function We(e){var n=e.graph().rankdir.toLowerCase();(n==="lr"||n==="rl")&&fe(e)}function ze(e){var n=e.graph().rankdir.toLowerCase();(n==="bt"||n==="rl")&&Xe(e),(n==="lr"||n==="rl")&&(Ue(e),fe(e))}function fe(e){f(e.nodes(),function(n){re(e.node(n))}),f(e.edges(),function(n){re(e.edge(n))})}function re(e){var n=e.width;e.width=e.height,e.height=n}function Xe(e){f(e.nodes(),function(n){A(e.node(n))}),f(e.edges(),function(n){var r=e.edge(n);f(r.points,A),m(r,"y")&&A(r)})}function A(e){e.y=-e.y}function Ue(e){f(e.nodes(),function(n){Y(e.node(n))}),f(e.edges(),function(n){var r=e.edge(n);f(r.points,Y),m(r,"x")&&Y(r)})}function Y(e){var n=e.x;e.x=e.y,e.y=n}function He(e){e.graph().dummyChains=[],f(e.edges(),function(n){Je(e,n)})}function Je(e,n){var r=n.v,t=e.node(r).rank,i=n.w,o=e.node(i).rank,a=n.name,u=e.edge(n),d=u.labelRank;if(o!==t+1){e.removeEdge(n);var s,c,l;for(l=0,++t;t<o;++l,++t)u.points=[],c={width:0,height:0,edgeLabel:u,edgeObj:n,rank:t},s=L(e,"edge",c,"_d"),t===d&&(c.width=u.width,c.height=u.height,c.dummy="edge-label",c.labelpos=u.labelpos),e.setEdge(r,s,{weight:u.weight},a),l===0&&e.graph().dummyChains.push(s),r=s;e.setEdge(r,i,{weight:u.weight},a)}}function Ke(e){f(e.graph().dummyChains,function(n){var r=e.node(n),t=r.edgeLabel,i;for(e.setEdge(r.edgeObj,t);r.dummy;)i=e.successors(n)[0],e.removeNode(n),t.points.push({x:r.x,y:r.y}),r.dummy==="edge-label"&&(t.x=r.x,t.y=r.y,t.width=r.width,t.height=r.height),n=i,r=e.node(n)})}function X(e){var n={};function r(t){var i=e.node(t);if(m(n,t))return i.rank;n[t]=!0;var o=R(w(e.outEdges(t),function(a){return r(a.w)-e.edge(a).minlen}));return(o===Number.POSITIVE_INFINITY||o===void 0||o===null)&&(o=0),i.rank=o}f(e.sources(),r)}function _(e,n){return e.node(n.w).rank-e.node(n.v).rank-e.edge(n).minlen}function ce(e){var n=new k({directed:!1}),r=e.nodes()[0],t=e.nodeCount();n.setNode(r,{});for(var i,o;Qe(n,e)<t;)i=Ze(n,e),o=n.hasNode(i.v)?_(e,i):-_(e,i),en(n,e,o);return n}function Qe(e,n){function r(t){f(n.nodeEdges(t),function(i){var o=i.v,a=t===o?i.w:o;!e.hasNode(a)&&!_(n,i)&&(e.setNode(a,{}),e.setEdge(t,a,{}),r(a))})}return f(e.nodes(),r),e.nodeCount()}function Ze(e,n){return W(n.edges(),function(r){if(e.hasNode(r.v)!==e.hasNode(r.w))return _(n,r)})}function en(e,n,r){f(e.nodes(),function(t){n.node(t).rank+=r})}function nn(){}nn.prototype=new Error;function le(e,n,r){Re(n)||(n=[n]);var t=(e.isDirected()?e.successors:e.neighbors).bind(e),i=[],o={};return f(n,function(a){if(!e.hasNode(a))throw new Error("Graph does not have node: "+a);he(e,a,r==="post",o,t,i)}),i}function he(e,n,r,t,i,o){m(t,n)||(t[n]=!0,r||o.push(n),f(i(n),function(a){he(e,a,r,t,i,o)}),r&&o.push(n))}function rn(e,n){return le(e,n,"post")}function tn(e,n){return le(e,n,"pre")}E.initLowLimValues=H;E.initCutValues=U;E.calcCutValue=ve;E.leaveEdge=me;E.enterEdge=we;E.exchangeEdges=be;function E(e){e=Ae(e),X(e);var n=ce(e);H(n),U(n,e);for(var r,t;r=me(n);)t=we(n,e,r),be(n,e,r,t)}function U(e,n){var r=rn(e,e.nodes());r=r.slice(0,r.length-1),f(r,function(t){an(e,n,t)})}function an(e,n,r){var t=e.node(r),i=t.parent;e.edge(r,i).cutvalue=ve(e,n,r)}function ve(e,n,r){var t=e.node(r),i=t.parent,o=!0,a=n.edge(r,i),u=0;return a||(o=!1,a=n.edge(i,r)),u=a.weight,f(n.nodeEdges(r),function(d){var s=d.v===r,c=s?d.w:d.v;if(c!==i){var l=s===o,h=n.edge(d).weight;if(u+=l?h:-h,un(e,r,c)){var v=e.edge(r,c).cutvalue;u+=l?-v:v}}}),u}function H(e,n){arguments.length<2&&(n=e.nodes()[0]),pe(e,{},1,n)}function pe(e,n,r,t,i){var o=r,a=e.node(t);return n[t]=!0,f(e.neighbors(t),function(u){m(n,u)||(r=pe(e,n,r,u,t))}),a.low=o,a.lim=r++,i?a.parent=i:delete a.parent,r}function me(e){return z(e.edges(),function(n){return e.edge(n).cutvalue<0})}function we(e,n,r){var t=r.v,i=r.w;n.hasEdge(t,i)||(t=r.w,i=r.v);var o=e.node(t),a=e.node(i),u=o,d=!1;o.lim>a.lim&&(u=a,d=!0);var s=T(n.edges(),function(c){return d===te(e,e.node(c.v),u)&&d!==te(e,e.node(c.w),u)});return W(s,function(c){return _(n,c)})}function be(e,n,r,t){var i=r.v,o=r.w;e.removeEdge(i,o),e.setEdge(t.v,t.w,{}),H(e),U(e,n),on(e,n)}function on(e,n){var r=z(e.nodes(),function(i){return!n.node(i).parent}),t=tn(e,r);t=t.slice(1),f(t,function(i){var o=e.node(i).parent,a=n.edge(i,o),u=!1;a||(a=n.edge(o,i),u=!0),n.node(i).rank=n.node(o).rank+(u?a.minlen:-a.minlen)})}function un(e,n,r){return e.hasEdge(n,r)}function te(e,n,r){return r.low<=n.lim&&n.lim<=r.lim}function dn(e){switch(e.graph().ranker){case"network-simplex":ie(e);break;case"tight-tree":fn(e);break;case"longest-path":sn(e);break;default:ie(e)}}var sn=X;function fn(e){X(e),ce(e)}function ie(e){E(e)}function cn(e){var n=L(e,"root",{},"_root"),r=ln(e),t=x(N(r))-1,i=2*t+1;e.graph().nestingRoot=n,f(e.edges(),function(a){e.edge(a).minlen*=i});var o=hn(e)+1;f(e.children(),function(a){ge(e,n,i,o,t,r,a)}),e.graph().nodeRankFactor=i}function ge(e,n,r,t,i,o,a){var u=e.children(a);if(!u.length){a!==n&&e.setEdge(n,a,{weight:0,minlen:r});return}var d=ee(e,"_bt"),s=ee(e,"_bb"),c=e.node(a);e.setParent(d,a),c.borderTop=d,e.setParent(s,a),c.borderBottom=s,f(u,function(l){ge(e,n,r,t,i,o,l);var h=e.node(l),v=h.borderTop?h.borderTop:l,p=h.borderBottom?h.borderBottom:l,b=h.borderTop?t:2*t,I=v!==p?1:i-o[a]+1;e.setEdge(d,v,{weight:b,minlen:I,nestingEdge:!0}),e.setEdge(p,s,{weight:b,minlen:I,nestingEdge:!0})}),e.parent(a)||e.setEdge(n,d,{weight:0,minlen:i+o[a]})}function ln(e){var n={};function r(t,i){var o=e.children(t);o&&o.length&&f(o,function(a){r(a,i+1)}),n[t]=i}return f(e.children(),function(t){r(t,1)}),n}function hn(e){return F(e.edges(),function(n,r){return n+e.edge(r).weight},0)}function vn(e){var n=e.graph();e.removeNode(n.nestingRoot),delete n.nestingRoot,f(e.edges(),function(r){var t=e.edge(r);t.nestingEdge&&e.removeEdge(r)})}function pn(e,n,r){var t={},i;f(r,function(o){for(var a=e.parent(o),u,d;a;){if(u=e.parent(a),u?(d=t[u],t[u]=a):(d=i,i=a),d&&d!==a){n.setEdge(d,a);return}a=u}})}function mn(e,n,r){var t=wn(e),i=new k({compound:!0}).setGraph({root:t}).setDefaultNodeLabel(function(o){return e.node(o)});return f(e.nodes(),function(o){var a=e.node(o),u=e.parent(o);(a.rank===n||a.minRank<=n&&n<=a.maxRank)&&(i.setNode(o),i.setParent(o,u||t),f(e[r](o),function(d){var s=d.v===o?d.w:d.v,c=i.edge(s,o),l=g(c)?0:c.weight;i.setEdge(s,o,{weight:e.edge(d).weight+l})}),m(a,"minRank")&&i.setNode(o,{borderLeft:a.borderLeft[n],borderRight:a.borderRight[n]}))}),i}function wn(e){for(var n;e.hasNode(n=q("_root")););return n}function bn(e,n){for(var r=0,t=1;t<n.length;++t)r+=gn(e,n[t-1],n[t]);return r}function gn(e,n,r){for(var t=Ee(r,w(r,function(s,c){return c})),i=S(w(n,function(s){return C(w(e.outEdges(s),function(c){return{pos:t[c.w],weight:e.edge(c).weight}}),"pos")})),o=1;o<r.length;)o<<=1;var a=2*o-1;o-=1;var u=w(new Array(a),function(){return 0}),d=0;return f(i.forEach(function(s){var c=s.pos+o;u[c]+=s.weight;for(var l=0;c>0;)c%2&&(l+=u[c+1]),c=c-1>>1,u[c]+=s.weight;d+=s.weight*l})),d}function kn(e){var n={},r=T(e.nodes(),function(u){return!e.children(u).length}),t=x(w(r,function(u){return e.node(u).rank})),i=w(y(t+1),function(){return[]});function o(u){if(!m(n,u)){n[u]=!0;var d=e.node(u);i[d.rank].push(u),f(e.successors(u),o)}}var a=C(r,function(u){return e.node(u).rank});return f(a,o),i}function xn(e,n){return w(n,function(r){var t=e.inEdges(r);if(t.length){var i=F(t,function(o,a){var u=e.edge(a),d=e.node(a.v);return{sum:o.sum+u.weight*d.order,weight:o.weight+u.weight}},{sum:0,weight:0});return{v:r,barycenter:i.sum/i.weight,weight:i.weight}}else return{v:r}})}function En(e,n){var r={};f(e,function(i,o){var a=r[i.v]={indegree:0,in:[],out:[],vs:[i.v],i:o};g(i.barycenter)||(a.barycenter=i.barycenter,a.weight=i.weight)}),f(n.edges(),function(i){var o=r[i.v],a=r[i.w];!g(o)&&!g(a)&&(a.indegree++,o.out.push(r[i.w]))});var t=T(r,function(i){return!i.indegree});return yn(t)}function yn(e){var n=[];function r(o){return function(a){a.merged||(g(a.barycenter)||g(o.barycenter)||a.barycenter>=o.barycenter)&&Nn(o,a)}}function t(o){return function(a){a.in.push(o),--a.indegree===0&&e.push(a)}}for(;e.length;){var i=e.pop();n.push(i),f(i.in.reverse(),r(i)),f(i.out,t(i))}return w(T(n,function(o){return!o.merged}),function(o){return M(o,["vs","i","barycenter","weight"])})}function Nn(e,n){var r=0,t=0;e.weight&&(r+=e.barycenter*e.weight,t+=e.weight),n.weight&&(r+=n.barycenter*n.weight,t+=n.weight),e.vs=n.vs.concat(e.vs),e.barycenter=r/t,e.weight=t,e.i=Math.min(n.i,e.i),n.merged=!0}function Ln(e,n){var r=Ge(e,function(c){return m(c,"barycenter")}),t=r.lhs,i=C(r.rhs,function(c){return-c.i}),o=[],a=0,u=0,d=0;t.sort(In(!!n)),d=ae(o,i,d),f(t,function(c){d+=c.vs.length,o.push(c.vs),a+=c.barycenter*c.weight,u+=c.weight,d=ae(o,i,d)});var s={vs:S(o)};return u&&(s.barycenter=a/u,s.weight=u),s}function ae(e,n,r){for(var t;n.length&&(t=P(n)).i<=r;)n.pop(),e.push(t.vs),r++;return r}function In(e){return function(n,r){return n.barycenter<r.barycenter?-1:n.barycenter>r.barycenter?1:e?r.i-n.i:n.i-r.i}}function ke(e,n,r,t){var i=e.children(n),o=e.node(n),a=o?o.borderLeft:void 0,u=o?o.borderRight:void 0,d={};a&&(i=T(i,function(p){return p!==a&&p!==u}));var s=xn(e,i);f(s,function(p){if(e.children(p.v).length){var b=ke(e,p.v,r,t);d[p.v]=b,m(b,"barycenter")&&_n(p,b)}});var c=En(s,r);Rn(c,d);var l=Ln(c,t);if(a&&(l.vs=S([a,l.vs,u]),e.predecessors(a).length)){var h=e.node(e.predecessors(a)[0]),v=e.node(e.predecessors(u)[0]);m(l,"barycenter")||(l.barycenter=0,l.weight=0),l.barycenter=(l.barycenter*l.weight+h.order+v.order)/(l.weight+2),l.weight+=2}return l}function Rn(e,n){f(e,function(r){r.vs=S(r.vs.map(function(t){return n[t]?n[t].vs:t}))})}function _n(e,n){g(e.barycenter)?(e.barycenter=n.barycenter,e.weight=n.weight):(e.barycenter=(e.barycenter*e.weight+n.barycenter*n.weight)/(e.weight+n.weight),e.weight+=n.weight)}function Cn(e){var n=se(e),r=oe(e,y(1,n+1),"inEdges"),t=oe(e,y(n-1,-1,-1),"outEdges"),i=kn(e);ue(e,i);for(var o=Number.POSITIVE_INFINITY,a,u=0,d=0;d<4;++u,++d){Tn(u%2?r:t,u%4>=2),i=V(e);var s=bn(e,i);s<o&&(d=0,a=_e(i),o=s)}ue(e,a)}function oe(e,n,r){return w(n,function(t){return mn(e,t,r)})}function Tn(e,n){var r=new k;f(e,function(t){var i=t.graph().root,o=ke(t,i,r,n);f(o.vs,function(a,u){t.node(a).order=u}),pn(t,r,o.vs)})}function ue(e,n){f(n,function(r){f(r,function(t,i){e.node(t).order=i})})}function Sn(e){var n=Pn(e);f(e.graph().dummyChains,function(r){for(var t=e.node(r),i=t.edgeObj,o=Mn(e,n,i.v,i.w),a=o.path,u=o.lca,d=0,s=a[d],c=!0;r!==i.w;){if(t=e.node(r),c){for(;(s=a[d])!==u&&e.node(s).maxRank<t.rank;)d++;s===u&&(c=!1)}if(!c){for(;d<a.length-1&&e.node(s=a[d+1]).minRank<=t.rank;)d++;s=a[d]}e.setParent(r,s),r=e.successors(r)[0]}})}function Mn(e,n,r,t){var i=[],o=[],a=Math.min(n[r].low,n[t].low),u=Math.max(n[r].lim,n[t].lim),d,s;d=r;do d=e.parent(d),i.push(d);while(d&&(n[d].low>a||u>n[d].lim));for(s=d,d=t;(d=e.parent(d))!==s;)o.push(d);return{path:i.concat(o.reverse()),lca:s}}function Pn(e){var n={},r=0;function t(i){var o=r;f(e.children(i),t),n[i]={low:o,lim:r++}}return f(e.children(),t),n}function On(e,n){var r={};function t(i,o){var a=0,u=0,d=i.length,s=P(o);return f(o,function(c,l){var h=Vn(e,c),v=h?e.node(h).order:d;(h||c===s)&&(f(o.slice(u,l+1),function(p){f(e.predecessors(p),function(b){var I=e.node(b),J=I.order;(J<a||v<J)&&!(I.dummy&&e.node(p).dummy)&&xe(r,b,p)})}),u=l+1,a=v)}),o}return F(n,t),r}function Fn(e,n){var r={};function t(o,a,u,d,s){var c;f(y(a,u),function(l){c=o[l],e.node(c).dummy&&f(e.predecessors(c),function(h){var v=e.node(h);v.dummy&&(v.order<d||v.order>s)&&xe(r,h,c)})})}function i(o,a){var u=-1,d,s=0;return f(a,function(c,l){if(e.node(c).dummy==="border"){var h=e.predecessors(c);h.length&&(d=e.node(h[0]).order,t(a,s,l,u,d),s=l,u=d)}t(a,s,a.length,d,o.length)}),a}return F(n,i),r}function Vn(e,n){if(e.node(n).dummy)return z(e.predecessors(n),function(r){return e.node(r).dummy})}function xe(e,n,r){if(n>r){var t=n;n=r,r=t}var i=e[n];i||(e[n]=i={}),i[r]=!0}function Bn(e,n,r){if(n>r){var t=n;n=r,r=t}return m(e[n],r)}function An(e,n,r,t){var i={},o={},a={};return f(n,function(u){f(u,function(d,s){i[d]=d,o[d]=d,a[d]=s})}),f(n,function(u){var d=-1;f(u,function(s){var c=t(s);if(c.length){c=C(c,function(b){return a[b]});for(var l=(c.length-1)/2,h=Math.floor(l),v=Math.ceil(l);h<=v;++h){var p=c[h];o[s]===s&&d<a[p]&&!Bn(r,s,p)&&(o[p]=s,o[s]=i[s]=i[p],d=a[p])}}})}),{root:i,align:o}}function Yn(e,n,r,t,i){var o={},a=Dn(e,n,r,i),u=i?"borderLeft":"borderRight";function d(l,h){for(var v=a.nodes(),p=v.pop(),b={};p;)b[p]?l(p):(b[p]=!0,v.push(p),v=v.concat(h(p))),p=v.pop()}function s(l){o[l]=a.inEdges(l).reduce(function(h,v){return Math.max(h,o[v.v]+a.edge(v))},0)}function c(l){var h=a.outEdges(l).reduce(function(p,b){return Math.min(p,o[b.w]-a.edge(b))},Number.POSITIVE_INFINITY),v=e.node(l);h!==Number.POSITIVE_INFINITY&&v.borderType!==u&&(o[l]=Math.max(o[l],h))}return d(s,a.predecessors.bind(a)),d(c,a.successors.bind(a)),f(t,function(l){o[l]=o[r[l]]}),o}function Dn(e,n,r,t){var i=new k,o=e.graph(),a=Wn(o.nodesep,o.edgesep,t);return f(n,function(u){var d;f(u,function(s){var c=r[s];if(i.setNode(c),d){var l=r[d],h=i.edge(l,c);i.setEdge(l,c,Math.max(a(e,s,d),h||0))}d=s})}),i}function Gn(e,n){return W(N(n),function(r){var t=Number.NEGATIVE_INFINITY,i=Number.POSITIVE_INFINITY;return ye(r,function(o,a){var u=zn(e,a)/2;t=Math.max(o+u,t),i=Math.min(o-u,i)}),t-i})}function jn(e,n){var r=N(n),t=R(r),i=x(r);f(["u","d"],function(o){f(["l","r"],function(a){var u=o+a,d=e[u],s;if(d!==n){var c=N(d);s=a==="l"?t-R(c):i-x(c),s&&(e[u]=O(d,function(l){return l+s}))}})})}function $n(e,n){return O(e.ul,function(r,t){if(n)return e[n.toLowerCase()][t];var i=C(w(e,t));return(i[1]+i[2])/2})}function qn(e){var n=V(e),r=j(On(e,n),Fn(e,n)),t={},i;f(["u","d"],function(a){i=a==="u"?n:N(n).reverse(),f(["l","r"],function(u){u==="r"&&(i=w(i,function(l){return N(l).reverse()}));var d=(a==="u"?e.predecessors:e.successors).bind(e),s=An(e,i,r,d),c=Yn(e,i,s.root,s.align,u==="r");u==="r"&&(c=O(c,function(l){return-l})),t[a+u]=c})});var o=Gn(e,t);return jn(t,o),$n(t,e.graph().align)}function Wn(e,n,r){return function(t,i,o){var a=t.node(i),u=t.node(o),d=0,s;if(d+=a.width/2,m(a,"labelpos"))switch(a.labelpos.toLowerCase()){case"l":s=-a.width/2;break;case"r":s=a.width/2;break}if(s&&(d+=r?s:-s),s=0,d+=(a.dummy?n:e)/2,d+=(u.dummy?n:e)/2,d+=u.width/2,m(u,"labelpos"))switch(u.labelpos.toLowerCase()){case"l":s=u.width/2;break;case"r":s=-u.width/2;break}return s&&(d+=r?s:-s),s=0,d}}function zn(e,n){return e.node(n).width}function Xn(e){e=de(e),Un(e),Ne(qn(e),function(n,r){e.node(r).x=n})}function Un(e){var n=V(e),r=e.graph().ranksep,t=0;f(n,function(i){var o=x(w(i,function(a){return e.node(a).height}));f(i,function(a){e.node(a).y=t+o/2}),t+=o+r})}function Er(e,n){var r=n&&n.debugTiming?je:$e;r("layout",function(){var t=r(" buildLayoutGraph",function(){return ar(e)});r(" runLayout",function(){Hn(t,r)}),r(" updateInputGraph",function(){Jn(e,t)})})}function Hn(e,n){n(" makeSpaceForEdgeLabels",function(){or(e)}),n(" removeSelfEdges",function(){pr(e)}),n(" acyclic",function(){Fe(e)}),n(" nestingGraph.run",function(){cn(e)}),n(" rank",function(){dn(de(e))}),n(" injectEdgeLabelProxies",function(){ur(e)}),n(" removeEmptyRanks",function(){De(e)}),n(" nestingGraph.cleanup",function(){vn(e)}),n(" normalizeRanks",function(){Ye(e)}),n(" assignRankMinMax",function(){dr(e)}),n(" removeEdgeLabelProxies",function(){sr(e)}),n(" normalize.run",function(){He(e)}),n(" parentDummyChains",function(){Sn(e)}),n(" addBorderSegments",function(){qe(e)}),n(" order",function(){Cn(e)}),n(" insertSelfEdges",function(){mr(e)}),n(" adjustCoordinateSystem",function(){We(e)}),n(" position",function(){Xn(e)}),n(" positionSelfEdges",function(){wr(e)}),n(" removeBorderNodes",function(){vr(e)}),n(" normalize.undo",function(){Ke(e)}),n(" fixupEdgeLabelCoords",function(){lr(e)}),n(" undoCoordinateSystem",function(){ze(e)}),n(" translateGraph",function(){fr(e)}),n(" assignNodeIntersects",function(){cr(e)}),n(" reversePoints",function(){hr(e)}),n(" acyclic.undo",function(){Be(e)})}function Jn(e,n){f(e.nodes(),function(r){var t=e.node(r),i=n.node(r);t&&(t.x=i.x,t.y=i.y,n.children(r).length&&(t.width=i.width,t.height=i.height))}),f(e.edges(),function(r){var t=e.edge(r),i=n.edge(r);t.points=i.points,m(i,"x")&&(t.x=i.x,t.y=i.y)}),e.graph().width=n.graph().width,e.graph().height=n.graph().height}var Kn=["nodesep","edgesep","ranksep","marginx","marginy"],Qn={ranksep:50,edgesep:20,nodesep:50,rankdir:"tb"},Zn=["acyclicer","ranker","rankdir","align"],er=["width","height"],nr={width:0,height:0},rr=["minlen","weight","width","height","labeloffset"],tr={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},ir=["labelpos"];function ar(e){var n=new k({multigraph:!0,compound:!0}),r=G(e.graph());return n.setGraph(j({},Qn,D(r,Kn),M(r,Zn))),f(e.nodes(),function(t){var i=G(e.node(t));n.setNode(t,Le(D(i,er),nr)),n.setParent(t,e.parent(t))}),f(e.edges(),function(t){var i=G(e.edge(t));n.setEdge(t,j({},tr,D(i,rr),M(i,ir)))}),n}function or(e){var n=e.graph();n.ranksep/=2,f(e.edges(),function(r){var t=e.edge(r);t.minlen*=2,t.labelpos.toLowerCase()!=="c"&&(n.rankdir==="TB"||n.rankdir==="BT"?t.width+=t.labeloffset:t.height+=t.labeloffset)})}function ur(e){f(e.edges(),function(n){var r=e.edge(n);if(r.width&&r.height){var t=e.node(n.v),i=e.node(n.w),o={rank:(i.rank-t.rank)/2+t.rank,e:n};L(e,"edge-proxy",o,"_ep")}})}function dr(e){var n=0;f(e.nodes(),function(r){var t=e.node(r);t.borderTop&&(t.minRank=e.node(t.borderTop).rank,t.maxRank=e.node(t.borderBottom).rank,n=x(n,t.maxRank))}),e.graph().maxRank=n}function sr(e){f(e.nodes(),function(n){var r=e.node(n);r.dummy==="edge-proxy"&&(e.edge(r.e).labelRank=r.rank,e.removeNode(n))})}function fr(e){var n=Number.POSITIVE_INFINITY,r=0,t=Number.POSITIVE_INFINITY,i=0,o=e.graph(),a=o.marginx||0,u=o.marginy||0;function d(s){var c=s.x,l=s.y,h=s.width,v=s.height;n=Math.min(n,c-h/2),r=Math.max(r,c+h/2),t=Math.min(t,l-v/2),i=Math.max(i,l+v/2)}f(e.nodes(),function(s){d(e.node(s))}),f(e.edges(),function(s){var c=e.edge(s);m(c,"x")&&d(c)}),n-=a,t-=u,f(e.nodes(),function(s){var c=e.node(s);c.x-=n,c.y-=t}),f(e.edges(),function(s){var c=e.edge(s);f(c.points,function(l){l.x-=n,l.y-=t}),m(c,"x")&&(c.x-=n),m(c,"y")&&(c.y-=t)}),o.width=r-n+a,o.height=i-t+u}function cr(e){f(e.edges(),function(n){var r=e.edge(n),t=e.node(n.v),i=e.node(n.w),o,a;r.points?(o=r.points[0],a=r.points[r.points.length-1]):(r.points=[],o=i,a=t),r.points.unshift(Z(t,o)),r.points.push(Z(i,a))})}function lr(e){f(e.edges(),function(n){var r=e.edge(n);if(m(r,"x"))switch((r.labelpos==="l"||r.labelpos==="r")&&(r.width-=r.labeloffset),r.labelpos){case"l":r.x-=r.width/2+r.labeloffset;break;case"r":r.x+=r.width/2+r.labeloffset;break}})}function hr(e){f(e.edges(),function(n){var r=e.edge(n);r.reversed&&r.points.reverse()})}function vr(e){f(e.nodes(),function(n){if(e.children(n).length){var r=e.node(n),t=e.node(r.borderTop),i=e.node(r.borderBottom),o=e.node(P(r.borderLeft)),a=e.node(P(r.borderRight));r.width=Math.abs(a.x-o.x),r.height=Math.abs(i.y-t.y),r.x=o.x+r.width/2,r.y=t.y+r.height/2}}),f(e.nodes(),function(n){e.node(n).dummy==="border"&&e.removeNode(n)})}function pr(e){f(e.edges(),function(n){if(n.v===n.w){var r=e.node(n.v);r.selfEdges||(r.selfEdges=[]),r.selfEdges.push({e:n,label:e.edge(n)}),e.removeEdge(n)}})}function mr(e){var n=V(e);f(n,function(r){var t=0;f(r,function(i,o){var a=e.node(i);a.order=o+t,f(a.selfEdges,function(u){L(e,"selfedge",{width:u.label.width,height:u.label.height,rank:a.rank,order:o+ ++t,e:u.e,label:u.label},"_se")}),delete a.selfEdges})})}function wr(e){f(e.nodes(),function(n){var r=e.node(n);if(r.dummy==="selfedge"){var t=e.node(r.e.v),i=t.x+t.width/2,o=t.y,a=r.x-i,u=t.height/2;e.setEdge(r.e,r.label),e.removeNode(n),r.label.points=[{x:i+2*a/3,y:o-u},{x:i+5*a/6,y:o-u},{x:i+a,y:o},{x:i+5*a/6,y:o+u},{x:i+2*a/3,y:o+u}],r.label.x=r.x,r.label.y=r.y}})}function D(e,n){return O(M(e,n),Number)}function G(e){var n={};return f(e,function(r,t){n[t.toLowerCase()]=r}),n}export{Er as l};