mermaid
Version:
Markdown-ish syntax for generating flowcharts, mindmaps, sequence diagrams, class diagrams, gantt charts, git graphs and more.
5 lines (4 loc) • 39.6 kB
JavaScript
import{a as Ge,b as Ae,c as C,d as ie,e as Fe,f as Q,g as Ve}from"./chunk-4MZOTL6B.mjs";import{A as U,B as ae,C as x,a as Te,b as F,c as O,d as Me,e as oe,f as je,g as X,h as l,i as S,j as W,k as b,l as De,m as Be,n as K,o as T,p as k,q as V,r as N,s as q,t as M,u as Y,v as z,w as L,x as G,y as Xe,z as P}from"./chunk-D36F7FYG.mjs";import{b as Se}from"./chunk-JCBDXJ5W.mjs";import{g as ne,h as Pe,i as Ce}from"./chunk-OCMJQKYE.mjs";import{a as Oe,c as Re,e as te}from"./chunk-MNT3HHAC.mjs";import{b as Ie}from"./chunk-TECWHJ6D.mjs";import"./chunk-F6PIGZHG.mjs";import"./chunk-JGXDHUYS.mjs";import"./chunk-TINYC7RT.mjs";import"./chunk-TDFULVG6.mjs";import"./chunk-MIE3LDYP.mjs";import"./chunk-QADHU5CF.mjs";import"./chunk-ZZ52EIBP.mjs";import{$ as Le}from"./chunk-FE53TMRB.mjs";import{b as y}from"./chunk-L2B47AAZ.mjs";import{a as s}from"./chunk-QVIEFLGF.mjs";var Z=class{static{s(this,"List")}constructor(){var r={};r._next=r._prev=r,this._sentinel=r}dequeue(){var r=this._sentinel,n=r._prev;if(n!==r)return Ye(n),n}enqueue(r){var n=this._sentinel;r._prev&&r._next&&Ye(r),r._next=n._next,n._next._prev=r,n._next=r,r._prev=n}toString(){for(var r=[],n=this._sentinel,t=n._prev;t!==n;)r.push(JSON.stringify(t,Vr)),t=t._prev;return"["+r.join(", ")+"]"}};function Ye(e){e._prev._next=e._next,e._next._prev=e._prev,delete e._next,delete e._prev}s(Ye,"unlink");function Vr(e,r){if(e!=="_next"&&e!=="_prev")return r}s(Vr,"filterOutLinks");var Yr=F(1);function ze(e,r){if(e.nodeCount()<=1)return[];var n=Ur(e,r||Yr),t=zr(n.graph,n.buckets,n.zeroIdx);return O(b(t,function(o){return e.outEdges(o.v,o.w)}))}s(ze,"greedyFAS");function zr(e,r,n){for(var t=[],o=r[r.length-1],a=r[0],i;e.nodeCount();){for(;i=a.dequeue();)se(e,r,n,i);for(;i=o.dequeue();)se(e,r,n,i);if(e.nodeCount()){for(var d=r.length-2;d>0;--d)if(i=r[d].dequeue(),i){t=t.concat(se(e,r,n,i,!0));break}}}return t}s(zr,"doGreedyFAS");function se(e,r,n,t,o){var a=o?[]:void 0;return l(e.inEdges(t.v),function(i){var d=e.edge(i),f=e.node(i.v);o&&a.push({v:i.v,w:i.w}),f.out-=d,de(r,n,f)}),l(e.outEdges(t.v),function(i){var d=e.edge(i),f=i.w,c=e.node(f);c.in-=d,de(r,n,c)}),e.removeNode(t.v),a}s(se,"removeNode");function Ur(e,r){var n=new x,t=0,o=0;l(e.nodes(),function(d){n.setNode(d,{v:d,in:0,out:0})}),l(e.edges(),function(d){var f=n.edge(d.v,d.w)||0,c=r(d),u=f+c;n.setEdge(d.v,d.w,u),o=Math.max(o,n.node(d.v).out+=c),t=Math.max(t,n.node(d.w).in+=c)});var a=L(o+t+3).map(function(){return new Z}),i=t+1;return l(n.nodes(),function(d){de(a,i,n.node(d))}),{graph:n,buckets:a,zeroIdx:i}}s(Ur,"buildState");function de(e,r,n){n.out?n.in?e[n.out-n.in+r].enqueue(n):e[e.length-1].enqueue(n):e[0].enqueue(n)}s(de,"assignBucket");function Ue(e){var r=e.graph().acyclicer==="greedy"?ze(e,n(e)):Wr(e);l(r,function(t){var o=e.edge(t);e.removeEdge(t),o.forwardName=t.name,o.reversed=!0,e.setEdge(t.w,t.v,o,U("rev"))});function n(t){return function(o){return t.edge(o).weight}}s(n,"weightFn")}s(Ue,"run");function Wr(e){var r=[],n={},t={};function o(a){Object.prototype.hasOwnProperty.call(t,a)||(t[a]=!0,n[a]=!0,l(e.outEdges(a),function(i){Object.prototype.hasOwnProperty.call(n,i.w)?r.push(i):o(i.w)}),delete n[a])}return s(o,"dfs"),l(e.nodes(),o),r}s(Wr,"dfsFAS");function We(e){l(e.edges(),function(r){var n=e.edge(r);if(n.reversed){e.removeEdge(r);var t=n.forwardName;delete n.reversed,delete n.forwardName,e.setEdge(r.w,r.v,n,t)}})}s(We,"undo");function I(e,r,n,t){var o;do o=U(t);while(e.hasNode(o));return n.dummy=r,e.setNode(o,n),o}s(I,"addDummyNode");function He(e){var r=new x().setGraph(e.graph());return l(e.nodes(),function(n){r.setNode(n,e.node(n))}),l(e.edges(),function(n){var t=r.edge(n.v,n.w)||{weight:0,minlen:1},o=e.edge(n);r.setEdge(n.v,n.w,{weight:t.weight+o.weight,minlen:Math.max(t.minlen,o.minlen)})}),r}s(He,"simplify");function $(e){var r=new x({multigraph:e.isMultigraph()}).setGraph(e.graph());return l(e.nodes(),function(n){e.children(n).length||r.setNode(n,e.node(n))}),l(e.edges(),function(n){r.setEdge(n,e.edge(n))}),r}s($,"asNonCompoundGraph");function fe(e,r){var n=e.x,t=e.y,o=r.x-n,a=r.y-t,i=e.width/2,d=e.height/2;if(!o&&!a)throw new Error("Not possible to find intersection inside of the rectangle");var f,c;return Math.abs(a)*i>Math.abs(o)*d?(a<0&&(d=-d),f=d*o/a,c=d):(o<0&&(i=-i),f=i,c=i*a/o),{x:n+f,y:t+c}}s(fe,"intersectRect");function j(e){var r=b(L(ue(e)+1),function(){return[]});return l(e.nodes(),function(n){var t=e.node(n),o=t.rank;k(o)||(r[o][t.order]=n)}),r}s(j,"buildLayerMatrix");function Je(e){var r=M(b(e.nodes(),function(n){return e.node(n).rank}));l(e.nodes(),function(n){var t=e.node(n);K(t,"rank")&&(t.rank-=r)})}s(Je,"normalizeRanks");function Ke(e){var r=M(b(e.nodes(),function(a){return e.node(a).rank})),n=[];l(e.nodes(),function(a){var i=e.node(a).rank-r;n[i]||(n[i]=[]),n[i].push(a)});var t=0,o=e.graph().nodeRankFactor;l(n,function(a,i){k(a)&&i%o!==0?--t:t&&l(a,function(d){e.node(d).rank+=t})})}s(Ke,"removeEmptyRanks");function ce(e,r,n,t){var o={width:0,height:0};return arguments.length>=4&&(o.rank=n,o.order=t),I(e,"border",o,r)}s(ce,"addBorderNode");function ue(e){return N(b(e.nodes(),function(r){var n=e.node(r).rank;if(!k(n))return n}))}s(ue,"maxRank");function Qe(e,r){var n={lhs:[],rhs:[]};return l(e,function(t){r(t)?n.lhs.push(t):n.rhs.push(t)}),n}s(Qe,"partition");function Ze(e,r){var n=oe();try{return r()}finally{console.log(e+" time: "+(oe()-n)+"ms")}}s(Ze,"time");function $e(e,r){return r()}s($e,"notime");function rr(e){function r(n){var t=e.children(n),o=e.node(n);if(t.length&&l(t,r),Object.prototype.hasOwnProperty.call(o,"minRank")){o.borderLeft=[],o.borderRight=[];for(var a=o.minRank,i=o.maxRank+1;a<i;++a)er(e,"borderLeft","_bl",n,o,a),er(e,"borderRight","_br",n,o,a)}}s(r,"dfs"),l(e.children(),r)}s(rr,"addBorderSegments");function er(e,r,n,t,o,a){var i={width:0,height:0,rank:a,borderType:r},d=o[r][a-1],f=I(e,"border",i,n);o[r][a]=f,e.setParent(f,t),d&&e.setEdge(d,f,{weight:1})}s(er,"addBorderNode");function tr(e){var r=e.graph().rankdir.toLowerCase();(r==="lr"||r==="rl")&&ar(e)}s(tr,"adjust");function or(e){var r=e.graph().rankdir.toLowerCase();(r==="bt"||r==="rl")&&qr(e),(r==="lr"||r==="rl")&&(Hr(e),ar(e))}s(or,"undo");function ar(e){l(e.nodes(),function(r){nr(e.node(r))}),l(e.edges(),function(r){nr(e.edge(r))})}s(ar,"swapWidthHeight");function nr(e){var r=e.width;e.width=e.height,e.height=r}s(nr,"swapWidthHeightOne");function qr(e){l(e.nodes(),function(r){le(e.node(r))}),l(e.edges(),function(r){var n=e.edge(r);l(n.points,le),Object.prototype.hasOwnProperty.call(n,"y")&&le(n)})}s(qr,"reverseY");function le(e){e.y=-e.y}s(le,"reverseYOne");function Hr(e){l(e.nodes(),function(r){he(e.node(r))}),l(e.edges(),function(r){var n=e.edge(r);l(n.points,he),Object.prototype.hasOwnProperty.call(n,"x")&&he(n)})}s(Hr,"swapXY");function he(e){var r=e.x;e.x=e.y,e.y=r}s(he,"swapXYOne");function ir(e){e.graph().dummyChains=[],l(e.edges(),function(r){Kr(e,r)})}s(ir,"run");function Kr(e,r){var n=r.v,t=e.node(n).rank,o=r.w,a=e.node(o).rank,i=r.name,d=e.edge(r),f=d.labelRank;if(a!==t+1){e.removeEdge(r);var c=void 0,u,h;for(h=0,++t;t<a;++h,++t)d.points=[],c={width:0,height:0,edgeLabel:d,edgeObj:r,rank:t},u=I(e,"edge",c,"_d"),t===f&&(c.width=d.width,c.height=d.height,c.dummy="edge-label",c.labelpos=d.labelpos),e.setEdge(n,u,{weight:d.weight},i),h===0&&e.graph().dummyChains.push(u),n=u;e.setEdge(n,o,{weight:d.weight},i)}}s(Kr,"normalizeEdge");function sr(e){l(e.graph().dummyChains,function(r){var n=e.node(r),t=n.edgeLabel,o;for(e.setEdge(n.edgeObj,t);n.dummy;)o=e.successors(r)[0],e.removeNode(r),t.points.push({x:n.x,y:n.y}),n.dummy==="edge-label"&&(t.x=n.x,t.y=n.y,t.width=n.width,t.height=n.height),r=o,n=e.node(r)})}s(sr,"undo");function H(e){var r={};function n(t){var o=e.node(t);if(Object.prototype.hasOwnProperty.call(r,t))return o.rank;r[t]=!0;var a=M(b(e.outEdges(t),function(i){return n(i.w)-e.edge(i).minlen}));return(a===Number.POSITIVE_INFINITY||a===void 0||a===null)&&(a=0),o.rank=a}s(n,"dfs"),l(e.sources(),n)}s(H,"longestPath");function A(e,r){return e.node(r.w).rank-e.node(r.v).rank-e.edge(r).minlen}s(A,"slack");function ee(e){var r=new x({directed:!1}),n=e.nodes()[0],t=e.nodeCount();r.setNode(n,{});for(var o,a;Qr(r,e)<t;)o=Zr(r,e),a=r.hasNode(o.v)?A(e,o):-A(e,o),$r(r,e,a);return r}s(ee,"feasibleTree");function Qr(e,r){function n(t){l(r.nodeEdges(t),function(o){var a=o.v,i=t===a?o.w:a;!e.hasNode(i)&&!A(r,o)&&(e.setNode(i,{}),e.setEdge(t,i,{}),n(i))})}return s(n,"dfs"),l(e.nodes(),n),e.nodeCount()}s(Qr,"tightTree");function Zr(e,r){return Y(r.edges(),function(n){if(e.hasNode(n.v)!==e.hasNode(n.w))return A(r,n)})}s(Zr,"findMinSlackEdge");function $r(e,r,n){l(e.nodes(),function(t){r.node(t).rank+=n})}s($r,"shiftRanks");var zt=F(1);var ro=F(1);pe.CycleException=J;function pe(e){var r={},n={},t=[];function o(a){if(Object.prototype.hasOwnProperty.call(n,a))throw new J;Object.prototype.hasOwnProperty.call(r,a)||(n[a]=!0,r[a]=!0,l(e.predecessors(a),o),delete n[a],t.push(a))}if(s(o,"visit"),l(e.sinks(),o),Xe(r)!==e.nodeCount())throw new J;return t}s(pe,"topsort");function J(){}s(J,"CycleException");J.prototype=new Error;function re(e,r,n){Te(r)||(r=[r]);var t=(e.isDirected()?e.successors:e.neighbors).bind(e),o=[],a={};return l(r,function(i){if(!e.hasNode(i))throw new Error("Graph does not have node: "+i);fr(e,i,n==="post",a,t,o)}),o}s(re,"dfs");function fr(e,r,n,t,o,a){Object.prototype.hasOwnProperty.call(t,r)||(t[r]=!0,n||a.push(r),l(o(r),function(i){fr(e,i,n,t,o,a)}),n&&a.push(r))}s(fr,"doDfs");function me(e,r){return re(e,r,"post")}s(me,"postorder");function ve(e,r){return re(e,r,"pre")}s(ve,"preorder");B.initLowLimValues=_e;B.initCutValues=we;B.calcCutValue=ur;B.leaveEdge=hr;B.enterEdge=pr;B.exchangeEdges=mr;function B(e){e=He(e),H(e);var r=ee(e);_e(r),we(r,e);for(var n,t;n=hr(r);)t=pr(r,e,n),mr(r,e,n,t)}s(B,"networkSimplex");function we(e,r){var n=me(e,e.nodes());n=n.slice(0,n.length-1),l(n,function(t){on(e,r,t)})}s(we,"initCutValues");function on(e,r,n){var t=e.node(n),o=t.parent;e.edge(n,o).cutvalue=ur(e,r,n)}s(on,"assignCutValue");function ur(e,r,n){var t=e.node(n),o=t.parent,a=!0,i=r.edge(n,o),d=0;return i||(a=!1,i=r.edge(o,n)),d=i.weight,l(r.nodeEdges(n),function(f){var c=f.v===n,u=c?f.w:f.v;if(u!==o){var h=c===a,p=r.edge(f).weight;if(d+=h?p:-p,sn(e,n,u)){var v=e.edge(n,u).cutvalue;d+=h?-v:v}}}),d}s(ur,"calcCutValue");function _e(e,r){arguments.length<2&&(r=e.nodes()[0]),lr(e,{},1,r)}s(_e,"initLowLimValues");function lr(e,r,n,t,o){var a=n,i=e.node(t);return r[t]=!0,l(e.neighbors(t),function(d){Object.prototype.hasOwnProperty.call(r,d)||(n=lr(e,r,n,d,t))}),i.low=a,i.lim=n++,o?i.parent=o:delete i.parent,n}s(lr,"dfsAssignLowLim");function hr(e){return W(e.edges(),function(r){return e.edge(r).cutvalue<0})}s(hr,"leaveEdge");function pr(e,r,n){var t=n.v,o=n.w;r.hasEdge(t,o)||(t=n.w,o=n.v);var a=e.node(t),i=e.node(o),d=a,f=!1;a.lim>i.lim&&(d=i,f=!0);var c=S(r.edges(),function(u){return f===cr(e,e.node(u.v),d)&&f!==cr(e,e.node(u.w),d)});return Y(c,function(u){return A(r,u)})}s(pr,"enterEdge");function mr(e,r,n,t){var o=n.v,a=n.w;e.removeEdge(o,a),e.setEdge(t.v,t.w,{}),_e(e),we(e,r),an(e,r)}s(mr,"exchangeEdges");function an(e,r){var n=W(e.nodes(),function(o){return!r.node(o).parent}),t=ve(e,n);t=t.slice(1),l(t,function(o){var a=e.node(o).parent,i=r.edge(o,a),d=!1;i||(i=r.edge(a,o),d=!0),r.node(o).rank=r.node(a).rank+(d?i.minlen:-i.minlen)})}s(an,"updateRanks");function sn(e,r,n){return e.hasEdge(r,n)}s(sn,"isTreeEdge");function cr(e,r,n){return n.low<=r.lim&&r.lim<=n.lim}s(cr,"isDescendant");function ge(e){switch(e.graph().ranker){case"network-simplex":vr(e);break;case"tight-tree":fn(e);break;case"longest-path":dn(e);break;default:vr(e)}}s(ge,"rank");var dn=H;function fn(e){H(e),ee(e)}s(fn,"tightTreeRanker");function vr(e){B(e)}s(vr,"networkSimplexRanker");function wr(e){var r=I(e,"root",{},"_root"),n=cn(e),t=N(T(n))-1,o=2*t+1;e.graph().nestingRoot=r,l(e.edges(),function(i){e.edge(i).minlen*=o});var a=un(e)+1;l(e.children(),function(i){_r(e,r,o,a,t,n,i)}),e.graph().nodeRankFactor=o}s(wr,"run");function _r(e,r,n,t,o,a,i){var d=e.children(i);if(!d.length){i!==r&&e.setEdge(r,i,{weight:0,minlen:n});return}var f=ce(e,"_bt"),c=ce(e,"_bb"),u=e.node(i);e.setParent(f,i),u.borderTop=f,e.setParent(c,i),u.borderBottom=c,l(d,function(h){_r(e,r,n,t,o,a,h);var p=e.node(h),v=p.borderTop?p.borderTop:h,_=p.borderBottom?p.borderBottom:h,w=p.borderTop?t:2*t,m=v!==_?1:o-a[i]+1;e.setEdge(f,v,{weight:w,minlen:m,nestingEdge:!0}),e.setEdge(_,c,{weight:w,minlen:m,nestingEdge:!0})}),e.parent(i)||e.setEdge(r,f,{weight:0,minlen:o+a[i]})}s(_r,"dfs");function cn(e){var r={};function n(t,o){var a=e.children(t);a&&a.length&&l(a,function(i){n(i,o+1)}),r[t]=o}return s(n,"dfs"),l(e.children(),function(t){n(t,1)}),r}s(cn,"treeDepths");function un(e){return G(e.edges(),function(r,n){return r+e.edge(n).weight},0)}s(un,"sumWeights");function gr(e){var r=e.graph();e.removeNode(r.nestingRoot),delete r.nestingRoot,l(e.edges(),function(n){var t=e.edge(n);t.nestingEdge&&e.removeEdge(n)})}s(gr,"cleanup");function yr(e,r,n){var t={},o;l(n,function(a){for(var i=e.parent(a),d,f;i;){if(d=e.parent(i),d?(f=t[d],t[d]=i):(f=o,o=i),f&&f!==i){r.setEdge(f,i);return}i=d}})}s(yr,"addSubgraphConstraints");function br(e,r,n){var t=hn(e),o=new x({compound:!0}).setGraph({root:t}).setDefaultNodeLabel(function(a){return e.node(a)});return l(e.nodes(),function(a){var i=e.node(a),d=e.parent(a);(i.rank===r||i.minRank<=r&&r<=i.maxRank)&&(o.setNode(a),o.setParent(a,d||t),l(e[n](a),function(f){var c=f.v===a?f.w:f.v,u=o.edge(c,a),h=k(u)?0:u.weight;o.setEdge(c,a,{weight:e.edge(f).weight+h})}),Object.prototype.hasOwnProperty.call(i,"minRank")&&o.setNode(a,{borderLeft:i.borderLeft[r],borderRight:i.borderRight[r]}))}),o}s(br,"buildLayerGraph");function hn(e){for(var r;e.hasNode(r=U("_root")););return r}s(hn,"createRootNode");function Er(e,r){for(var n=0,t=1;t<r.length;++t)n+=pn(e,r[t-1],r[t]);return n}s(Er,"crossCount");function pn(e,r,n){for(var t=ae(n,b(n,function(c,u){return u})),o=O(b(r,function(c){return P(b(e.outEdges(c),function(u){return{pos:t[u.w],weight:e.edge(u).weight}}),"pos")})),a=1;a<n.length;)a<<=1;var i=2*a-1;a-=1;var d=b(new Array(i),function(){return 0}),f=0;return l(o.forEach(function(c){var u=c.pos+a;d[u]+=c.weight;for(var h=0;u>0;)u%2&&(h+=d[u+1]),u=u-1>>1,d[u]+=c.weight;f+=c.weight*h})),f}s(pn,"twoLayerCrossCount");function xr(e){var r={},n=S(e.nodes(),function(d){return!e.children(d).length}),t=N(b(n,function(d){return e.node(d).rank})),o=b(L(t+1),function(){return[]});function a(d){if(!K(r,d)){r[d]=!0;var f=e.node(d);o[f.rank].push(d),l(e.successors(d),a)}}s(a,"dfs");var i=P(n,function(d){return e.node(d).rank});return l(i,a),o}s(xr,"initOrder");function kr(e,r){return b(r,function(n){var t=e.inEdges(n);if(t.length){var o=G(t,function(a,i){var d=e.edge(i),f=e.node(i.v);return{sum:a.sum+d.weight*f.order,weight:a.weight+d.weight}},{sum:0,weight:0});return{v:n,barycenter:o.sum/o.weight,weight:o.weight}}else return{v:n}})}s(kr,"barycenter");function Nr(e,r){var n={};l(e,function(o,a){var i=n[o.v]={indegree:0,in:[],out:[],vs:[o.v],i:a};k(o.barycenter)||(i.barycenter=o.barycenter,i.weight=o.weight)}),l(r.edges(),function(o){var a=n[o.v],i=n[o.w];!k(a)&&!k(i)&&(i.indegree++,a.out.push(n[o.w]))});var t=S(n,function(o){return!o.indegree});return mn(t)}s(Nr,"resolveConflicts");function mn(e){var r=[];function n(a){return function(i){i.merged||(k(i.barycenter)||k(a.barycenter)||i.barycenter>=a.barycenter)&&vn(a,i)}}s(n,"handleIn");function t(a){return function(i){i.in.push(a),--i.indegree===0&&e.push(i)}}for(s(t,"handleOut");e.length;){var o=e.pop();r.push(o),l(o.in.reverse(),n(o)),l(o.out,t(o))}return b(S(r,function(a){return!a.merged}),function(a){return z(a,["vs","i","barycenter","weight"])})}s(mn,"doResolveConflicts");function vn(e,r){var n=0,t=0;e.weight&&(n+=e.barycenter*e.weight,t+=e.weight),r.weight&&(n+=r.barycenter*r.weight,t+=r.weight),e.vs=r.vs.concat(e.vs),e.barycenter=n/t,e.weight=t,e.i=Math.min(r.i,e.i),r.merged=!0}s(vn,"mergeEntries");function Ir(e,r){var n=Qe(e,function(u){return Object.prototype.hasOwnProperty.call(u,"barycenter")}),t=n.lhs,o=P(n.rhs,function(u){return-u.i}),a=[],i=0,d=0,f=0;t.sort(wn(!!r)),f=Lr(a,o,f),l(t,function(u){f+=u.vs.length,a.push(u.vs),i+=u.barycenter*u.weight,d+=u.weight,f=Lr(a,o,f)});var c={vs:O(a)};return d&&(c.barycenter=i/d,c.weight=d),c}s(Ir,"sort");function Lr(e,r,n){for(var t;r.length&&(t=X(r)).i<=n;)r.pop(),e.push(t.vs),n++;return n}s(Lr,"consumeUnsortable");function wn(e){return function(r,n){return r.barycenter<n.barycenter?-1:r.barycenter>n.barycenter?1:e?n.i-r.i:r.i-n.i}}s(wn,"compareWithBias");function ye(e,r,n,t){var o=e.children(r),a=e.node(r),i=a?a.borderLeft:void 0,d=a?a.borderRight:void 0,f={};i&&(o=S(o,function(_){return _!==i&&_!==d}));var c=kr(e,o);l(c,function(_){if(e.children(_.v).length){var w=ye(e,_.v,n,t);f[_.v]=w,Object.prototype.hasOwnProperty.call(w,"barycenter")&&gn(_,w)}});var u=Nr(c,n);_n(u,f);var h=Ir(u,t);if(i&&(h.vs=O([i,h.vs,d]),e.predecessors(i).length)){var p=e.node(e.predecessors(i)[0]),v=e.node(e.predecessors(d)[0]);Object.prototype.hasOwnProperty.call(h,"barycenter")||(h.barycenter=0,h.weight=0),h.barycenter=(h.barycenter*h.weight+p.order+v.order)/(h.weight+2),h.weight+=2}return h}s(ye,"sortSubgraph");function _n(e,r){l(e,function(n){n.vs=O(n.vs.map(function(t){return r[t]?r[t].vs:t}))})}s(_n,"expandSubgraphs");function gn(e,r){k(e.barycenter)?(e.barycenter=r.barycenter,e.weight=r.weight):(e.barycenter=(e.barycenter*e.weight+r.barycenter*r.weight)/(e.weight+r.weight),e.weight+=r.weight)}s(gn,"mergeBarycenters");function Pr(e){var r=ue(e),n=Or(e,L(1,r+1),"inEdges"),t=Or(e,L(r-1,-1,-1),"outEdges"),o=xr(e);Sr(e,o);for(var a=Number.POSITIVE_INFINITY,i,d=0,f=0;f<4;++d,++f){yn(d%2?n:t,d%4>=2),o=j(e);var c=Er(e,o);c<a&&(f=0,i=Me(o),a=c)}Sr(e,i)}s(Pr,"order");function Or(e,r,n){return b(r,function(t){return br(e,t,n)})}s(Or,"buildLayerGraphs");function yn(e,r){var n=new x;l(e,function(t){var o=t.graph().root,a=ye(t,o,n,r);l(a.vs,function(i,d){t.node(i).order=d}),yr(t,n,a.vs)})}s(yn,"sweepLayerGraphs");function Sr(e,r){l(r,function(n){l(n,function(t,o){e.node(t).order=o})})}s(Sr,"assignOrder");function Cr(e){var r=En(e);l(e.graph().dummyChains,function(n){for(var t=e.node(n),o=t.edgeObj,a=bn(e,r,o.v,o.w),i=a.path,d=a.lca,f=0,c=i[f],u=!0;n!==o.w;){if(t=e.node(n),u){for(;(c=i[f])!==d&&e.node(c).maxRank<t.rank;)f++;c===d&&(u=!1)}if(!u){for(;f<i.length-1&&e.node(c=i[f+1]).minRank<=t.rank;)f++;c=i[f]}e.setParent(n,c),n=e.successors(n)[0]}})}s(Cr,"parentDummyChains");function bn(e,r,n,t){var o=[],a=[],i=Math.min(r[n].low,r[t].low),d=Math.max(r[n].lim,r[t].lim),f,c;f=n;do f=e.parent(f),o.push(f);while(f&&(r[f].low>i||d>r[f].lim));for(c=f,f=t;(f=e.parent(f))!==c;)a.push(f);return{path:o.concat(a.reverse()),lca:c}}s(bn,"findPath");function En(e){var r={},n=0;function t(o){var a=n;l(e.children(o),t),r[o]={low:a,lim:n++}}return s(t,"dfs"),l(e.children(),t),r}s(En,"postorder");function xn(e,r){var n={};function t(o,a){var i=0,d=0,f=o.length,c=X(a);return l(a,function(u,h){var p=Nn(e,u),v=p?e.node(p).order:f;(p||u===c)&&(l(a.slice(d,h+1),function(_){l(e.predecessors(_),function(w){var m=e.node(w),g=m.order;(g<i||v<g)&&!(m.dummy&&e.node(_).dummy)&&Rr(n,w,_)})}),d=h+1,i=v)}),a}return s(t,"visitLayer"),G(r,t),n}s(xn,"findType1Conflicts");function kn(e,r){var n={};function t(a,i,d,f,c){var u;l(L(i,d),function(h){u=a[h],e.node(u).dummy&&l(e.predecessors(u),function(p){var v=e.node(p);v.dummy&&(v.order<f||v.order>c)&&Rr(n,p,u)})})}s(t,"scan");function o(a,i){var d=-1,f,c=0;return l(i,function(u,h){if(e.node(u).dummy==="border"){var p=e.predecessors(u);p.length&&(f=e.node(p[0]).order,t(i,c,h,d,f),c=h,d=f)}t(i,c,i.length,f,a.length)}),i}return s(o,"visitLayer"),G(r,o),n}s(kn,"findType2Conflicts");function Nn(e,r){if(e.node(r).dummy)return W(e.predecessors(r),function(n){return e.node(n).dummy})}s(Nn,"findOtherInnerSegmentNode");function Rr(e,r,n){if(r>n){var t=r;r=n,n=t}Object.prototype.hasOwnProperty.call(e,r)||Object.defineProperty(e,r,{enumerable:!0,configurable:!0,value:{},writable:!0});var o=e[r];Object.defineProperty(o,n,{enumerable:!0,configurable:!0,value:!0,writable:!0})}s(Rr,"addConflict");function Ln(e,r,n){if(r>n){var t=r;r=n,n=t}return!!e[r]&&Object.prototype.hasOwnProperty.call(e[r],n)}s(Ln,"hasConflict");function In(e,r,n,t){var o={},a={},i={};return l(r,function(d){l(d,function(f,c){o[f]=f,a[f]=f,i[f]=c})}),l(r,function(d){var f=-1;l(d,function(c){var u=t(c);if(u.length){u=P(u,function(w){return i[w]});for(var h=(u.length-1)/2,p=Math.floor(h),v=Math.ceil(h);p<=v;++p){var _=u[p];a[c]===c&&f<i[_]&&!Ln(n,c,_)&&(a[_]=c,a[c]=o[c]=o[_],f=i[_])}}})}),{root:o,align:a}}s(In,"verticalAlignment");function On(e,r,n,t,o){var a={},i=Sn(e,r,n,o),d=o?"borderLeft":"borderRight";function f(h,p){for(var v=i.nodes(),_=v.pop(),w={};_;)w[_]?h(_):(w[_]=!0,v.push(_),v=v.concat(p(_))),_=v.pop()}s(f,"iterate");function c(h){a[h]=i.inEdges(h).reduce(function(p,v){return Math.max(p,a[v.v]+i.edge(v))},0)}s(c,"pass1");function u(h){var p=i.outEdges(h).reduce(function(_,w){return Math.min(_,a[w.w]-i.edge(w))},Number.POSITIVE_INFINITY),v=e.node(h);p!==Number.POSITIVE_INFINITY&&v.borderType!==d&&(a[h]=Math.max(a[h],p))}return s(u,"pass2"),f(c,i.predecessors.bind(i)),f(u,i.successors.bind(i)),l(t,function(h){a[h]=a[n[h]]}),a}s(On,"horizontalCompaction");function Sn(e,r,n,t){var o=new x,a=e.graph(),i=Tn(a.nodesep,a.edgesep,t);return l(r,function(d){var f;l(d,function(c){var u=n[c];if(o.setNode(u),f){var h=n[f],p=o.edge(h,u);o.setEdge(h,u,Math.max(i(e,c,f),p||0))}f=c})}),o}s(Sn,"buildBlockGraph");function Pn(e,r){return Y(T(r),function(n){var t=Number.NEGATIVE_INFINITY,o=Number.POSITIVE_INFINITY;return De(n,function(a,i){var d=Mn(e,i)/2;t=Math.max(a+d,t),o=Math.min(a-d,o)}),t-o})}s(Pn,"findSmallestWidthAlignment");function Cn(e,r){var n=T(r),t=M(n),o=N(n);l(["u","d"],function(a){l(["l","r"],function(i){var d=a+i,f=e[d],c;if(f!==r){var u=T(f);c=i==="l"?t-M(u):o-N(u),c&&(e[d]=V(f,function(h){return h+c}))}})})}s(Cn,"alignCoordinates");function Rn(e,r){return V(e.ul,function(n,t){if(r)return e[r.toLowerCase()][t];var o=P(b(e,t));return(o[1]+o[2])/2})}s(Rn,"balance");function Tr(e){var r=j(e),n=q(xn(e,r),kn(e,r)),t={},o;l(["u","d"],function(i){o=i==="u"?r:T(r).reverse(),l(["l","r"],function(d){d==="r"&&(o=b(o,function(h){return T(h).reverse()}));var f=(i==="u"?e.predecessors:e.successors).bind(e),c=In(e,o,n,f),u=On(e,o,c.root,c.align,d==="r");d==="r"&&(u=V(u,function(h){return-h})),t[i+d]=u})});var a=Pn(e,t);return Cn(t,a),Rn(t,e.graph().align)}s(Tr,"positionX");function Tn(e,r,n){return function(t,o,a){var i=t.node(o),d=t.node(a),f=0,c;if(f+=i.width/2,Object.prototype.hasOwnProperty.call(i,"labelpos"))switch(i.labelpos.toLowerCase()){case"l":c=-i.width/2;break;case"r":c=i.width/2;break}if(c&&(f+=n?c:-c),c=0,f+=(i.dummy?r:e)/2,f+=(d.dummy?r:e)/2,f+=d.width/2,Object.prototype.hasOwnProperty.call(d,"labelpos"))switch(d.labelpos.toLowerCase()){case"l":c=d.width/2;break;case"r":c=-d.width/2;break}return c&&(f+=n?c:-c),c=0,f}}s(Tn,"sep");function Mn(e,r){return e.node(r).width}s(Mn,"width");function Mr(e){e=$(e),jn(e),Be(Tr(e),function(r,n){e.node(n).x=r})}s(Mr,"position");function jn(e){var r=j(e),n=e.graph().ranksep,t=0;l(r,function(o){var a=N(b(o,function(i){return e.node(i).height}));l(o,function(i){e.node(i).y=t+a/2}),t+=a+n})}s(jn,"positionY");function xe(e,r){var n=r&&r.debugTiming?Ze:$e;n("layout",()=>{var t=n(" buildLayoutGraph",()=>Wn(e));n(" runLayout",()=>Dn(t,n)),n(" updateInputGraph",()=>Bn(e,t))})}s(xe,"layout");function Dn(e,r){r(" makeSpaceForEdgeLabels",()=>qn(e)),r(" removeSelfEdges",()=>nt(e)),r(" acyclic",()=>Ue(e)),r(" nestingGraph.run",()=>wr(e)),r(" rank",()=>ge($(e))),r(" injectEdgeLabelProxies",()=>Hn(e)),r(" removeEmptyRanks",()=>Ke(e)),r(" nestingGraph.cleanup",()=>gr(e)),r(" normalizeRanks",()=>Je(e)),r(" assignRankMinMax",()=>Jn(e)),r(" removeEdgeLabelProxies",()=>Kn(e)),r(" normalize.run",()=>ir(e)),r(" parentDummyChains",()=>Cr(e)),r(" addBorderSegments",()=>rr(e)),r(" order",()=>Pr(e)),r(" insertSelfEdges",()=>tt(e)),r(" adjustCoordinateSystem",()=>tr(e)),r(" position",()=>Mr(e)),r(" positionSelfEdges",()=>ot(e)),r(" removeBorderNodes",()=>rt(e)),r(" normalize.undo",()=>sr(e)),r(" fixupEdgeLabelCoords",()=>$n(e)),r(" undoCoordinateSystem",()=>or(e)),r(" translateGraph",()=>Qn(e)),r(" assignNodeIntersects",()=>Zn(e)),r(" reversePoints",()=>et(e)),r(" acyclic.undo",()=>We(e))}s(Dn,"runLayout");function Bn(e,r){l(e.nodes(),function(n){var t=e.node(n),o=r.node(n);t&&(t.x=o.x,t.y=o.y,r.children(n).length&&(t.width=o.width,t.height=o.height))}),l(e.edges(),function(n){var t=e.edge(n),o=r.edge(n);t.points=o.points,Object.prototype.hasOwnProperty.call(o,"x")&&(t.x=o.x,t.y=o.y)}),e.graph().width=r.graph().width,e.graph().height=r.graph().height}s(Bn,"updateInputGraph");var Xn=["nodesep","edgesep","ranksep","marginx","marginy"],Gn={ranksep:50,edgesep:20,nodesep:50,rankdir:"tb"},An=["acyclicer","ranker","rankdir","align"],Fn=["width","height"],Vn={width:0,height:0},Yn=["minlen","weight","width","height","labeloffset"],zn={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},Un=["labelpos"];function Wn(e){var r=new x({multigraph:!0,compound:!0}),n=Ee(e.graph());return r.setGraph(q({},Gn,be(n,Xn),z(n,An))),l(e.nodes(),function(t){var o=Ee(e.node(t));r.setNode(t,je(be(o,Fn),Vn)),r.setParent(t,e.parent(t))}),l(e.edges(),function(t){var o=Ee(e.edge(t));r.setEdge(t,q({},zn,be(o,Yn),z(o,Un)))}),r}s(Wn,"buildLayoutGraph");function qn(e){var r=e.graph();r.ranksep/=2,l(e.edges(),function(n){var t=e.edge(n);t.minlen*=2,t.labelpos.toLowerCase()!=="c"&&(r.rankdir==="TB"||r.rankdir==="BT"?t.width+=t.labeloffset:t.height+=t.labeloffset)})}s(qn,"makeSpaceForEdgeLabels");function Hn(e){l(e.edges(),function(r){var n=e.edge(r);if(n.width&&n.height){var t=e.node(r.v),o=e.node(r.w),a={rank:(o.rank-t.rank)/2+t.rank,e:r};I(e,"edge-proxy",a,"_ep")}})}s(Hn,"injectEdgeLabelProxies");function Jn(e){var r=0;l(e.nodes(),function(n){var t=e.node(n);t.borderTop&&(t.minRank=e.node(t.borderTop).rank,t.maxRank=e.node(t.borderBottom).rank,r=N(r,t.maxRank))}),e.graph().maxRank=r}s(Jn,"assignRankMinMax");function Kn(e){l(e.nodes(),function(r){var n=e.node(r);n.dummy==="edge-proxy"&&(e.edge(n.e).labelRank=n.rank,e.removeNode(r))})}s(Kn,"removeEdgeLabelProxies");function Qn(e){var r=Number.POSITIVE_INFINITY,n=0,t=Number.POSITIVE_INFINITY,o=0,a=e.graph(),i=a.marginx||0,d=a.marginy||0;function f(c){var u=c.x,h=c.y,p=c.width,v=c.height;r=Math.min(r,u-p/2),n=Math.max(n,u+p/2),t=Math.min(t,h-v/2),o=Math.max(o,h+v/2)}s(f,"getExtremes"),l(e.nodes(),function(c){f(e.node(c))}),l(e.edges(),function(c){var u=e.edge(c);Object.prototype.hasOwnProperty.call(u,"x")&&f(u)}),r-=i,t-=d,l(e.nodes(),function(c){var u=e.node(c);u.x-=r,u.y-=t}),l(e.edges(),function(c){var u=e.edge(c);l(u.points,function(h){h.x-=r,h.y-=t}),Object.prototype.hasOwnProperty.call(u,"x")&&(u.x-=r),Object.prototype.hasOwnProperty.call(u,"y")&&(u.y-=t)}),a.width=n-r+i,a.height=o-t+d}s(Qn,"translateGraph");function Zn(e){l(e.edges(),function(r){var n=e.edge(r),t=e.node(r.v),o=e.node(r.w),a,i;n.points?(a=n.points[0],i=n.points[n.points.length-1]):(n.points=[],a=o,i=t),n.points.unshift(fe(t,a)),n.points.push(fe(o,i))})}s(Zn,"assignNodeIntersects");function $n(e){l(e.edges(),function(r){var n=e.edge(r);if(Object.prototype.hasOwnProperty.call(n,"x"))switch((n.labelpos==="l"||n.labelpos==="r")&&(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;break}})}s($n,"fixupEdgeLabelCoords");function et(e){l(e.edges(),function(r){var n=e.edge(r);n.reversed&&n.points.reverse()})}s(et,"reversePointsForReversedEdges");function rt(e){l(e.nodes(),function(r){if(e.children(r).length){var n=e.node(r),t=e.node(n.borderTop),o=e.node(n.borderBottom),a=e.node(X(n.borderLeft)),i=e.node(X(n.borderRight));n.width=Math.abs(i.x-a.x),n.height=Math.abs(o.y-t.y),n.x=a.x+n.width/2,n.y=t.y+n.height/2}}),l(e.nodes(),function(r){e.node(r).dummy==="border"&&e.removeNode(r)})}s(rt,"removeBorderNodes");function nt(e){l(e.edges(),function(r){if(r.v===r.w){var n=e.node(r.v);n.selfEdges||(n.selfEdges=[]),n.selfEdges.push({e:r,label:e.edge(r)}),e.removeEdge(r)}})}s(nt,"removeSelfEdges");function tt(e){var r=j(e);l(r,function(n){var t=0;l(n,function(o,a){var i=e.node(o);i.order=a+t,l(i.selfEdges,function(d){I(e,"selfedge",{width:d.label.width,height:d.label.height,rank:i.rank,order:a+ ++t,e:d.e,label:d.label},"_se")}),delete i.selfEdges})})}s(tt,"insertSelfEdges");function ot(e){l(e.nodes(),function(r){var n=e.node(r);if(n.dummy==="selfedge"){var t=e.node(n.e.v),o=t.x+t.width/2,a=t.y,i=n.x-o,d=t.height/2;e.setEdge(n.e,n.label),e.removeNode(r),n.label.points=[{x:o+2*i/3,y:a-d},{x:o+5*i/6,y:a-d},{x:o+i,y:a},{x:o+5*i/6,y:a+d},{x:o+2*i/3,y:a+d}],n.label.x=n.x,n.label.y=n.y}})}s(ot,"positionSelfEdges");function be(e,r){return V(z(e,r),Number)}s(be,"selectNumberAttrs");function Ee(e){var r={};return l(e,function(n,t){r[t.toLowerCase()]=n}),r}s(Ee,"canonicalize");var jr=s((e,r,n)=>Math.max(r,Math.min(n,e)),"clamp"),Dr=s((e="TB")=>{switch(e){case"BT":return"bottom";case"LR":return"right";case"RL":return"left";case"TB":default:return"top"}},"getDefaultSelfLoopSide"),at=s(e=>e==="flowchart"||e==="flowchart-v2"||e==="stateDiagram"||e==="er"||e==="classDiagram","shouldMergeSelfLoopSegments"),it=["x","y","width","height","labelBBox","intersect","calcIntersect","diff","clusterNode"],st=s((e,r,n,t,o)=>{let a=[],i=new Set;if(n.forEach(({start:u,end:h})=>{u!==t&&i.add(u),h!==t&&i.add(h)}),i.forEach(u=>{let h=e.node(u);typeof h?.x=="number"&&typeof h?.y=="number"&&a.push(h)}),a.length===0&&n.forEach(({edge:u})=>{(u.points??[]).forEach(h=>{typeof h?.x=="number"&&typeof h?.y=="number"&&a.push(h)})}),a.length===0)return Dr(o);let d=a.reduce((u,h)=>({x:u.x+h.x/a.length,y:u.y+h.y/a.length}),{x:0,y:0}),f=d.x-r.x,c=d.y-r.y;return Math.abs(f)>Math.abs(c)?f>0?"right":"left":Math.abs(c)>0?c>0?"bottom":"top":Dr(o)},"getSelfLoopSide"),dt=s((e,r="top",n=0,t=0)=>{let o=e.x,a=e.y-n,i=e.width/2,d=e.height/2,f=Math.max(36,Math.min(100,e.width*.8)),c=jr(Math.max(t,e.width*.35),36,f),u=jr(Math.min(e.width,e.height)*.45,24,48);switch(r){case"bottom":{let h=a+d;return[{x:o-c/2,y:h},{x:o-c/2,y:h+u},{x:o+c/2,y:h+u},{x:o+c/2,y:h}]}case"right":{let h=o+i;return[{x:h,y:a-c/2},{x:h+u,y:a-c/2},{x:h+u,y:a+c/2},{x:h,y:a+c/2}]}case"left":{let h=o-i;return[{x:h,y:a-c/2},{x:h-u,y:a-c/2},{x:h-u,y:a+c/2},{x:h,y:a+c/2}]}case"top":default:{let h=a-d;return[{x:o-c/2,y:h},{x:o-c/2,y:h-u},{x:o+c/2,y:h-u},{x:o+c/2,y:h}]}}},"getSelfLoopPoints"),ft=s((e,r,n="top",t=0,o={})=>{let i=e.x,d=e.y-t,f=o.width??0,c=o.height??0;switch(n){case"bottom":return{x:i,y:Math.max(...r.map(u=>u.y))+c/2+4};case"right":return{x:Math.max(...r.map(u=>u.x))+f/2+4,y:d};case"left":return{x:Math.min(...r.map(u=>u.x))-f/2-4,y:d};case"top":default:return{x:i,y:Math.min(...r.map(u=>u.y))-c/2-4}}},"getSelfLoopLabelPosition"),Xr=s((e,r=0,{mergeSelfLoops:n=!0}={})=>{let t=new Map,o=[],a=e.graph()?.rankdir;return e.edges().forEach(i=>{let d=e.edge(i);if(n&&d.selfLoop){let f=d.selfLoop.id;t.has(f)||t.set(f,[]),t.get(f).push({edge:d,start:i.v,end:i.w})}else o.push({edge:d,start:i.v,end:i.w})}),t.forEach(i=>{if(i.length!==3){i.forEach(g=>o.push(g));return}i.sort((g,R)=>g.edge.selfLoop.order-R.edge.selfLoop.order);let[d,f,c]=i,u=d.edge.originalEdge??f.edge.originalEdge??c.edge.originalEdge??f.edge,h=e.node(u.start);if(!h){i.forEach(g=>o.push(g));return}let p={width:f.edge.width,height:f.edge.height},v=st(e,h,i,u.start,a),_=dt(h,v,r,p.width??0),w=ft(h,_,v,r,p),m={...f.edge,...u,id:u.id,points:_,start:u.start,end:u.end,x:w.x,y:w.y,width:p.width,height:p.height,labelStyle:f.edge.labelStyle,fromCluster:d.edge.fromCluster??f.edge.fromCluster??c.edge.fromCluster,toCluster:d.edge.toCluster??f.edge.toCluster??c.edge.toCluster};delete m.selfLoop,delete m.originalEdge,o.push({edge:m,start:m.start,end:m.end})}),o},"getEdgesToRender"),Gr=s(async({element:e,graph:r,diagramType:n,id:t,parentCluster:o,siteConfig:a})=>{let i=r.graph().rankdir;y.trace("Dir in recursive render - dir:",i);let{clusters:d,edgePaths:f,edgeLabels:c,nodes:u,rootGroups:h}=Ge(e,{edgePathsClass:"edgePaths"});r.nodes()?y.info("Recursive render XXX",r.nodes()):y.info("No nodes found for",r),r.edges().length>0&&y.info("Recursive edges",r.edge(r.edges()[0]));let p=at(n);await Promise.all(r.nodes().map(async function(w){let m=r.node(w);if(o!==void 0){let g=JSON.parse(JSON.stringify(o.clusterData));y.trace(`Setting data for parent cluster XXX
Node.id = `,w,`
data=`,g.height,`
Parent cluster`,o.height),r.setNode(o.id,g),r.parent(w)||(y.trace("Setting parent",w,o.id),r.setParent(w,o.id,g))}if(y.info("(Insert) Node XXX"+w+": "+JSON.stringify(r.node(w))),m?.clusterNode){y.info("Cluster identified XBX",w,m.width,r.node(w));let{ranksep:g,nodesep:R}=r.graph();m.graph.setGraph({...m.graph.graph(),ranksep:g+25,nodesep:R});let ke=await pt({element:u,graph:m.graph,diagramType:n,id:t,parentCluster:r.node(w),siteConfig:a}),Ne=ke.elem;Ie(m,Ne),m.diff=ke.diff||0,y.info("New compound node after recursive render XAX",w,"width",m.width,"height",m.height),Re(Ne,m)}else r.children(w).length>0?(y.trace("Cluster - the non recursive path XBX",w,m.id,m,m.width,"Graph:",r),y.trace(ie(m.id,r)),C.set(m.id,{id:ie(m.id,r),node:m})):(y.trace("Node - the non recursive path XAX",w,u,r.node(w),i),await Ae(u,r.node(w),{config:a,dir:i}))})),await s(async()=>{let w=r.edges().map(async function(m){let g=r.edge(m.v,m.w,m.name);if(y.info("Edge "+m.v+" -> "+m.w+": "+JSON.stringify(m)),y.info("Edge "+m.v+" -> "+m.w+": ",m," ",JSON.stringify(r.edge(m))),y.info("Fix",C,"ids:",m.v,m.w,"Translating: ",C.get(m.v),C.get(m.w)),p&&g.selfLoop){if(g.selfLoop.order!==1)return;let R={...g.originalEdge,...g,id:g.selfLoop.id,startLabelLeft:g.originalEdge?.startLabelLeft??g.startLabelLeft,startLabelRight:g.originalEdge?.startLabelRight??g.startLabelRight,endLabelLeft:g.originalEdge?.endLabelLeft??g.endLabelLeft,endLabelRight:g.originalEdge?.endLabelRight??g.endLabelRight};await ne(c,R),g.width=R.width,g.height=R.height,g.labelStyle=R.labelStyle;return}await ne(c,g)});await Promise.all(w)},"processEdges")();let{subGraphTitleTotalMargin:_}=Oe(a);return{elem:h,graph:r,groups:{clusters:d,edgePaths:f,edgeLabels:c,nodes:u,rootGroups:h},diagramType:n,id:t,mergeSelfLoops:p,subGraphTitleTotalMargin:_}},"measureDagreGraph"),Ar=s(e=>{y.info("############################################# XXX"),y.info("### Layout ### XXX"),y.info("############################################# XXX"),xe(e)},"runDagreGraphLayout"),ct=s((e,r,n)=>{let t=e.node(r);if(!t)return;let o={...t};return t?.clusterNode?o.y=(t.y??0)+n:e.children(r).length>0?o.height=(t.height??0)+n:o.y=(t.y??0)+n/2,o},"normalizeDagreNode"),Br=s((e,r)=>{it.forEach(n=>{r[n]!==void 0&&(e[n]=r[n])})},"applyDagreNodeLayout"),ut=s((e,r,n,t)=>({...e,start:e.start??r,end:e.end??n,points:(e.points??[]).map(o=>({...o,y:typeof o.y=="number"?o.y+t:o.y}))}),"normalizeDagreEdge"),lt=s((e,r)=>{let{graph:n,mergeSelfLoops:t,subGraphTitleTotalMargin:o=0}=r,a=new Map(e.nodes.map(d=>[d.id,d]));Q(n).forEach(d=>{let f=ct(n,d,o);if(!f)return;Br(n.node(d),f);let c=a.get(d);c&&Br(c,f)});let i=o/2;return e.edges=Xr(n,i,{mergeSelfLoops:t}).map(({edge:d,start:f,end:c})=>ut(d,f,c,i)),e},"applyDagreLayoutResult"),ht=s(async({elem:e,graph:r,groups:{clusters:n,edgePaths:t},diagramType:o,id:a,mergeSelfLoops:i,subGraphTitleTotalMargin:d})=>{let f=0;await Promise.all(Q(r).map(async function(h){let p=r.node(h);if(y.info("Position XBX => "+h+": ("+p.x,","+p.y,") width: ",p.width," height: ",p.height),p?.clusterNode)p.y+=d,y.info("A tainted cluster node XBX1",h,p.id,p.width,p.height,p.x,p.y,r.parent(h)),C.get(p.id).node=p,te(p);else if(r.children(h).length>0){y.info("A pure cluster node XBX1",h,p.id,p.x,p.y,p.width,p.height,r.parent(h)),p.height+=d,r.node(p.parentId);let v=p?.padding/2||0,_=p?.labelBBox?.height||0,w=_-v||0;y.debug("OffsetY",w,"labelHeight",_,"halfPadding",v),await Se(n,p),C.get(p.id).node=p}else{let v=r.node(p.parentId);p.y+=d/2,y.info("A regular node XBX1 - using the padding",p.id,"parent",p.parentId,p.width,p.height,p.x,p.y,"offsetY",p.offsetY,"parent",v,v?.offsetY,p),te(p)}}));let c=d/2;return Xr(r,c,{mergeSelfLoops:i}).forEach(function({edge:h,start:p,end:v}){y.info("Edge "+p+" -> "+v+": "+JSON.stringify(h),h),h.points.forEach(g=>g.y+=c);let _=r.node(p),w=r.node(v),m=Ce(t,h,C,o,_,w,a);Pe(h,m)}),r.nodes().forEach(function(h){let p=r.node(h);y.info(h,p.type,p.diff),p.isGroup&&(f=p.diff)}),y.warn("Returning from recursive render XAX",e,f),{elem:e,diff:f}},"paintDagreLayoutCore"),pt=s(async e=>{let r=await Gr(e);return Ar(r.graph),await ht(r)},"renderDagreSubgraph"),Fr=s(e=>{let r=new x({multigraph:!0,compound:!0}).setGraph({rankdir:e.direction,nodesep:e.config?.nodeSpacing||e.nodeSpacing||e.config?.flowchart?.nodeSpacing,ranksep:e.config?.rankSpacing||e.rankSpacing||e.config?.flowchart?.rankSpacing,marginx:8,marginy:8}).setDefaultEdgeLabel(function(){return{}});return e.nodes.forEach(n=>{r.setNode(n.id,{...n}),n.parentId&&r.setParent(n.id,n.parentId)}),y.debug("Edges:",e.edges),e.edges.forEach(n=>{if(n.start===n.end){let t=n.start,o=t+"---"+t+"---1",a=t+"---"+t+"---2",i=r.node(t);r.setNode(o,{domId:o,id:o,parentId:i.parentId,labelStyle:"",label:"",padding:0,shape:"labelRect",style:"",width:10,height:10}),r.setParent(o,i.parentId),r.setNode(a,{domId:a,id:a,parentId:i.parentId,labelStyle:"",padding:0,shape:"labelRect",label:"",style:"",width:10,height:10}),r.setParent(a,i.parentId);let d=structuredClone(n),f=structuredClone(n),c=structuredClone(n),u=structuredClone(n);f.originalEdge=d,f.selfLoop={id:d.id,order:0},c.originalEdge=d,c.selfLoop={id:d.id,order:1},u.originalEdge=d,u.selfLoop={id:d.id,order:2},f.label="",f.arrowTypeEnd="none",f.endLabelLeft="",f.endLabelRight="",f.startLabelLeft="",f.id=t+"-cyclic-special-1",c.startLabelRight="",c.startLabelLeft="",c.endLabelLeft="",c.endLabelRight="",c.arrowTypeStart="none",c.arrowTypeEnd="none",c.id=t+"-cyclic-special-mid",u.label="",u.startLabelRight="",u.startLabelLeft="",u.arrowTypeStart="none",i.isGroup&&(f.fromCluster=t,u.toCluster=t),u.id=t+"-cyclic-special-2",u.arrowTypeStart="none",r.setEdge(t,o,f,t+"-cyclic-special-0"),r.setEdge(o,a,c,t+"-cyclic-special-1"),r.setEdge(a,t,u,t+"-cyclic-special-2")}else r.setEdge(n.start,n.end,{...n},n.id)}),Fe(r),{graph:r}},"prepareLayoutForDagre"),mt=s(async(e,{element:r,preparedLayout:n})=>{let t=n??Fr(e),o=Le(),a=await Gr({element:r,graph:t.graph,diagramType:e.type,id:e.diagramId,parentCluster:void 0,siteConfig:o});return t.measuredLayout=a,a},"measureDagreLayout"),vt=s((e,r)=>{let n=r.preparedLayout?.measuredLayout;if(!n)throw new Error("runDagreLayoutCore requires measureDagreLayout to run first");return Ar(n.graph),lt(e,n),n},"runDagreLayoutCore"),wt=s((e,{measure:r})=>Q(r.graph).map(n=>r.graph.node(n)).filter(Boolean),"getDagrePaintNodes"),_t=s((e,r,{measure:n})=>e?n.graph.node(e):void 0,"getDagreEdgeNode"),ti=Ve({prepareLayout:Fr,measureLayout:mt,runLayoutCore:vt,paintOptions:{clusterDb:C,getNodes:wt,getEdgeNode:_t,skipNode:s((e,{measure:r})=>!r.graph.hasNode(e.id),"skipNode"),isCluster:s((e,{measure:r})=>r.graph.hasNode(e.id)&&(r.graph.children(e.id)??[]).length>0,"isCluster")}});export{lt as applyDagreLayoutResult,Xr as getEdgesToRender,mt as measureDagreLayout,Fr as prepareLayoutForDagre,ti as render,vt as runDagreLayoutCore};