import{g as ut,t as w,p as S,r as x,P as k,j as u,H as ue,l as se,u as ae,a as oe,b as T,c as F,d as J,C as D,R as L,I as ft,T as v,A as pt,S as mt,e as De,f as Z,h as gt,i as bt,k as wt,M as xt,m as Et,n as vt,B as yt,o as _t,q as kt,s as ee,v as fe,w as R,x as pe,D as jt,y as Nt,z as Ot,E as Ct}from"./index-BLPf7Sv2.js";/* empty css */var It="\0",C="\0",me="";let $t=class{_isDirected=!0;_isMultigraph=!1;_isCompound=!1;_label;_defaultNodeLabelFn=()=>{};_defaultEdgeLabelFn=()=>{};_nodes={};_in={};_preds={};_out={};_sucs={};_edgeObjs={};_edgeLabels={};_nodeCount=0;_edgeCount=0;_parent;_children;constructor(t){t&&(this._isDirected=Object.hasOwn(t,"directed")?t.directed:!0,this._isMultigraph=Object.hasOwn(t,"multigraph")?t.multigraph:!1,this._isCompound=Object.hasOwn(t,"compound")?t.compound:!1),this._isCompound&&(this._parent={},this._children={},this._children[C]={})}isDirected(){return this._isDirected}isMultigraph(){return this._isMultigraph}isCompound(){return this._isCompound}setGraph(t){return this._label=t,this}graph(){return this._label}setDefaultNodeLabel(t){return this._defaultNodeLabelFn=t,typeof t!="function"&&(this._defaultNodeLabelFn=()=>t),this}nodeCount(){return this._nodeCount}nodes(){return Object.keys(this._nodes)}sources(){var t=this;return this.nodes().filter(n=>Object.keys(t._in[n]).length===0)}sinks(){var t=this;return this.nodes().filter(n=>Object.keys(t._out[n]).length===0)}setNodes(t,n){var r=arguments,i=this;return t.forEach(function(s){r.length>1?i.setNode(s,n):i.setNode(s)}),this}setNode(t,n){return Object.hasOwn(this._nodes,t)?(arguments.length>1&&(this._nodes[t]=n),this):(this._nodes[t]=arguments.length>1?n:this._defaultNodeLabelFn(t),this._isCompound&&(this._parent[t]=C,this._children[t]={},this._children[C][t]=!0),this._in[t]={},this._preds[t]={},this._out[t]={},this._sucs[t]={},++this._nodeCount,this)}node(t){return this._nodes[t]}hasNode(t){return Object.hasOwn(this._nodes,t)}removeNode(t){var n=this;if(Object.hasOwn(this._nodes,t)){var r=i=>n.removeEdge(n._edgeObjs[i]);delete this._nodes[t],this._isCompound&&(this._removeFromParentsChildList(t),delete this._parent[t],this.children(t).forEach(function(i){n.setParent(i)}),delete this._children[t]),Object.keys(this._in[t]).forEach(r),delete this._in[t],delete this._preds[t],Object.keys(this._out[t]).forEach(r),delete this._out[t],delete this._sucs[t],--this._nodeCount}return this}setParent(t,n){if(!this._isCompound)throw new Error("Cannot set parent in a non-compound graph");if(n===void 0)n=C;else{n+="";for(var r=n;r!==void 0;r=this.parent(r))if(r===t)throw new Error("Setting "+n+" as parent of "+t+" would create a cycle");this.setNode(n)}return this.setNode(t),this._removeFromParentsChildList(t),this._parent[t]=n,this._children[n][t]=!0,this}_removeFromParentsChildList(t){delete this._children[this._parent[t]][t]}parent(t){if(this._isCompound){var n=this._parent[t];if(n!==C)return n}}children(t=C){if(this._isCompound){var n=this._children[t];if(n)return Object.keys(n)}else{if(t===C)return this.nodes();if(this.hasNode(t))return[]}}predecessors(t){var n=this._preds[t];if(n)return Object.keys(n)}successors(t){var n=this._sucs[t];if(n)return Object.keys(n)}neighbors(t){var n=this.predecessors(t);if(n){const i=new Set(n);for(var r of this.successors(t))i.add(r);return Array.from(i.values())}}isLeaf(t){var n;return this.isDirected()?n=this.successors(t):n=this.neighbors(t),n.length===0}filterNodes(t){var n=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});n.setGraph(this.graph());var r=this;Object.entries(this._nodes).forEach(function([a,o]){t(a)&&n.setNode(a,o)}),Object.values(this._edgeObjs).forEach(function(a){n.hasNode(a.v)&&n.hasNode(a.w)&&n.setEdge(a,r.edge(a))});var i={};function s(a){var o=r.parent(a);return o===void 0||n.hasNode(o)?(i[a]=o,o):o in i?i[o]:s(o)}return this._isCompound&&n.nodes().forEach(a=>n.setParent(a,s(a))),n}setDefaultEdgeLabel(t){return this._defaultEdgeLabelFn=t,typeof t!="function"&&(this._defaultEdgeLabelFn=()=>t),this}edgeCount(){return this._edgeCount}edges(){return Object.values(this._edgeObjs)}setPath(t,n){var r=this,i=arguments;return t.reduce(function(s,a){return i.length>1?r.setEdge(s,a,n):r.setEdge(s,a),a}),this}setEdge(){var t,n,r,i,s=!1,a=arguments[0];typeof a=="object"&&a!==null&&"v"in a?(t=a.v,n=a.w,r=a.name,arguments.length===2&&(i=arguments[1],s=!0)):(t=a,n=arguments[1],r=arguments[3],arguments.length>2&&(i=arguments[2],s=!0)),t=""+t,n=""+n,r!==void 0&&(r=""+r);var o=$(this._isDirected,t,n,r);if(Object.hasOwn(this._edgeLabels,o))return s&&(this._edgeLabels[o]=i),this;if(r!==void 0&&!this._isMultigraph)throw new Error("Cannot set a named edge when isMultigraph = false");this.setNode(t),this.setNode(n),this._edgeLabels[o]=s?i:this._defaultEdgeLabelFn(t,n,r);var l=Lt(this._isDirected,t,n,r);return t=l.v,n=l.w,Object.freeze(l),this._edgeObjs[o]=l,ge(this._preds[n],t),ge(this._sucs[t],n),this._in[n][o]=l,this._out[t][o]=l,this._edgeCount++,this}edge(t,n,r){var i=arguments.length===1?W(this._isDirected,arguments[0]):$(this._isDirected,t,n,r);return this._edgeLabels[i]}edgeAsObj(){const t=this.edge(...arguments);return typeof t!="object"?{label:t}:t}hasEdge(t,n,r){var i=arguments.length===1?W(this._isDirected,arguments[0]):$(this._isDirected,t,n,r);return Object.hasOwn(this._edgeLabels,i)}removeEdge(t,n,r){var i=arguments.length===1?W(this._isDirected,arguments[0]):$(this._isDirected,t,n,r),s=this._edgeObjs[i];return s&&(t=s.v,n=s.w,delete this._edgeLabels[i],delete this._edgeObjs[i],be(this._preds[n],t),be(this._sucs[t],n),delete this._in[n][i],delete this._out[t][i],this._edgeCount--),this}inEdges(t,n){var r=this._in[t];if(r){var i=Object.values(r);return n?i.filter(s=>s.v===n):i}}outEdges(t,n){var r=this._out[t];if(r){var i=Object.values(r);return n?i.filter(s=>s.w===n):i}}nodeEdges(t,n){var r=this.inEdges(t,n);if(r)return r.concat(this.outEdges(t,n))}};function ge(e,t){e[t]?e[t]++:e[t]=1}function be(e,t){--e[t]||delete e[t]}function $(e,t,n,r){var i=""+t,s=""+n;if(!e&&i>s){var a=i;i=s,s=a}return i+me+s+me+(r===void 0?It:r)}function Lt(e,t,n,r){var i=""+t,s=""+n;if(!e&&i>s){var a=i;i=s,s=a}var o={v:i,w:s};return r&&(o.name=r),o}function W(e,t){return $(e,t.v,t.w,t.name)}var le=$t,Tt="2.2.4",St={Graph:le,version:Tt},Rt=le,Mt={write:Pt,read:Gt};function Pt(e){var t={options:{directed:e.isDirected(),multigraph:e.isMultigraph(),compound:e.isCompound()},nodes:Ft(e),edges:Dt(e)};return e.graph()!==void 0&&(t.value=structuredClone(e.graph())),t}function Ft(e){return e.nodes().map(function(t){var n=e.node(t),r=e.parent(t),i={v:t};return n!==void 0&&(i.value=n),r!==void 0&&(i.parent=r),i})}function Dt(e){return e.edges().map(function(t){var n=e.edge(t),r={v:t.v,w:t.w};return t.name!==void 0&&(r.name=t.name),n!==void 0&&(r.value=n),r})}function Gt(e){var t=new Rt(e.options).setGraph(e.value);return e.nodes.forEach(function(n){t.setNode(n.v,n.value),n.parent&&t.setParent(n.v,n.parent)}),e.edges.forEach(function(n){t.setEdge({v:n.v,w:n.w,name:n.name},n.value)}),t}var At=Vt;function Vt(e){var t={},n=[],r;function i(s){Object.hasOwn(t,s)||(t[s]=!0,r.push(s),e.successors(s).forEach(i),e.predecessors(s).forEach(i))}return e.nodes().forEach(function(s){r=[],i(s),r.length&&n.push(r)}),n}let Bt=class{_arr=[];_keyIndices={};size(){return this._arr.length}keys(){return this._arr.map(function(t){return t.key})}has(t){return Object.hasOwn(this._keyIndices,t)}priority(t){var n=this._keyIndices[t];if(n!==void 0)return this._arr[n].priority}min(){if(this.size()===0)throw new Error("Queue underflow");return this._arr[0].key}add(t,n){var r=this._keyIndices;if(t=String(t),!Object.hasOwn(r,t)){var i=this._arr,s=i.length;return r[t]=s,i.push({key:t,priority:n}),this._decrease(s),!0}return!1}removeMin(){this._swap(0,this._arr.length-1);var t=this._arr.pop();return delete this._keyIndices[t.key],this._heapify(0),t.key}decrease(t,n){var r=this._keyIndices[t];if(n>this._arr[r].priority)throw new Error("New priority is greater than current priority. Key: "+t+" Old: "+this._arr[r].priority+" New: "+n);this._arr[r].priority=n,this._decrease(r)}_heapify(t){var n=this._arr,r=2*t,i=r+1,s=t;r>1,!(n[i].priority1;function Yt(e,t,n,r){return qt(e,String(t),n||Wt,r||function(i){return e.outEdges(i)})}function qt(e,t,n,r){var i={},s=new zt,a,o,l=function(d){var c=d.v!==a?d.v:d.w,h=i[c],f=n(d),p=o.distance+f;if(f<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+d+" Weight: "+f);p0&&(a=s.removeMin(),o=i[a],o.distance!==Number.POSITIVE_INFINITY);)r(a).forEach(l);return i}var Ht=Ae,Ut=Xt;function Xt(e,t,n){return e.nodes().reduce(function(r,i){return r[i]=Ht(e,i,t,n),r},{})}var Ve=Qt;function Qt(e){var t=0,n=[],r={},i=[];function s(a){var o=r[a]={onStack:!0,lowlink:t,index:t++};if(n.push(a),e.successors(a).forEach(function(c){Object.hasOwn(r,c)?r[c].onStack&&(o.lowlink=Math.min(o.lowlink,r[c].index)):(s(c),o.lowlink=Math.min(o.lowlink,r[c].lowlink))}),o.lowlink===o.index){var l=[],d;do d=n.pop(),r[d].onStack=!1,l.push(d);while(a!==d);i.push(l)}}return e.nodes().forEach(function(a){Object.hasOwn(r,a)||s(a)}),i}var Kt=Ve,Jt=Zt;function Zt(e){return Kt(e).filter(function(t){return t.length>1||t.length===1&&e.hasEdge(t[0],t[0])})}var en=nn,tn=()=>1;function nn(e,t,n){return rn(e,t||tn,n||function(r){return e.outEdges(r)})}function rn(e,t,n){var r={},i=e.nodes();return i.forEach(function(s){r[s]={},r[s][s]={distance:0},i.forEach(function(a){s!==a&&(r[s][a]={distance:Number.POSITIVE_INFINITY})}),n(s).forEach(function(a){var o=a.v===s?a.w:a.v,l=t(a);r[s][o]={distance:l,predecessor:s}})}),i.forEach(function(s){var a=r[s];i.forEach(function(o){var l=r[o];i.forEach(function(d){var c=l[s],h=a[d],f=l[d],p=c.distance+h.distance;pe.successors(o):o=>e.neighbors(o),i=n==="post"?ln:dn,s=[],a={};return t.forEach(o=>{if(!e.hasNode(o))throw new Error("Graph does not have node: "+o);i(o,r,a,s)}),s}function ln(e,t,n,r){for(var i=[[e,!1]];i.length>0;){var s=i.pop();s[1]?r.push(s[0]):Object.hasOwn(n,s[0])||(n[s[0]]=!0,i.push([s[0],!0]),Ye(t(s[0]),a=>i.push([a,!1])))}}function dn(e,t,n,r){for(var i=[e];i.length>0;){var s=i.pop();Object.hasOwn(n,s)||(n[s]=!0,r.push(s),Ye(t(s),a=>i.push(a)))}}function Ye(e,t){for(var n=e.length;n--;)t(e[n],n,e);return e}var cn=We,hn=un;function un(e,t){return cn(e,t,"post")}var fn=We,pn=mn;function mn(e,t){return fn(e,t,"pre")}var gn=le,bn=Ge,wn=xn;function xn(e,t){var n=new gn,r={},i=new bn,s;function a(l){var d=l.v===s?l.w:l.v,c=i.priority(d);if(c!==void 0){var h=t(l);h0;){if(s=i.removeMin(),Object.hasOwn(r,s))n.setEdge(s,r[s]);else{if(o)throw new Error("Input graph is not connected: "+e);o=!0}e.nodeEdges(s).forEach(a)}return n}var En={components:At,dijkstra:Ae,dijkstraAll:Ut,findCycles:Jt,floydWarshall:en,isAcyclic:sn,postorder:hn,preorder:pn,prim:wn,tarjan:Ve,topsort:ze},xe=St,_={Graph:xe.Graph,json:Mt,alg:En,version:xe.version};let vn=class{constructor(){let t={};t._next=t._prev=t,this._sentinel=t}dequeue(){let t=this._sentinel,n=t._prev;if(n!==t)return Ee(n),n}enqueue(t){let n=this._sentinel;t._prev&&t._next&&Ee(t),t._next=n._next,n._next._prev=t,n._next=t,t._prev=n}toString(){let t=[],n=this._sentinel,r=n._prev;for(;r!==n;)t.push(JSON.stringify(r,yn)),r=r._prev;return"["+t.join(", ")+"]"}};function Ee(e){e._prev._next=e._next,e._next._prev=e._prev,delete e._next,delete e._prev}function yn(e,t){if(e!=="_next"&&e!=="_prev")return t}var _n=vn;let kn=_.Graph,jn=_n;var Nn=Cn;let On=()=>1;function Cn(e,t){if(e.nodeCount()<=1)return[];let n=$n(e,t||On);return In(n.graph,n.buckets,n.zeroIdx).flatMap(i=>e.outEdges(i.v,i.w))}function In(e,t,n){let r=[],i=t[t.length-1],s=t[0],a;for(;e.nodeCount();){for(;a=s.dequeue();)Y(e,t,n,a);for(;a=i.dequeue();)Y(e,t,n,a);if(e.nodeCount()){for(let o=t.length-2;o>0;--o)if(a=t[o].dequeue(),a){r=r.concat(Y(e,t,n,a,!0));break}}}return r}function Y(e,t,n,r,i){let s=i?[]:void 0;return e.inEdges(r.v).forEach(a=>{let o=e.edge(a),l=e.node(a.v);i&&s.push({v:a.v,w:a.w}),l.out-=o,ne(t,n,l)}),e.outEdges(r.v).forEach(a=>{let o=e.edge(a),l=a.w,d=e.node(l);d.in-=o,ne(t,n,d)}),e.removeNode(r.v),s}function $n(e,t){let n=new kn,r=0,i=0;e.nodes().forEach(o=>{n.setNode(o,{v:o,in:0,out:0})}),e.edges().forEach(o=>{let l=n.edge(o.v,o.w)||0,d=t(o),c=l+d;n.setEdge(o.v,o.w,c),i=Math.max(i,n.node(o.v).out+=d),r=Math.max(r,n.node(o.w).in+=d)});let s=Ln(i+r+3).map(()=>new jn),a=r+1;return n.nodes().forEach(o=>{ne(s,a,n.node(o))}),{graph:n,buckets:s,zeroIdx:a}}function ne(e,t,n){n.out?n.in?e[n.out-n.in+t].enqueue(n):e[e.length-1].enqueue(n):e[0].enqueue(n)}function Ln(e){const t=[];for(let n=0;nt.setNode(n,e.node(n))),e.edges().forEach(n=>{let r=t.edge(n.v,n.w)||{weight:0,minlen:1},i=e.edge(n);t.setEdge(n.v,n.w,{weight:r.weight+i.weight,minlen:Math.max(r.minlen,i.minlen)})}),t}function Sn(e){let t=new qe({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 Rn(e){let t=e.nodes().map(n=>{let r={};return e.outEdges(n).forEach(i=>{r[i.w]=(r[i.w]||0)+e.edge(i).weight}),r});return de(e.nodes(),t)}function Mn(e){let t=e.nodes().map(n=>{let r={};return e.inEdges(n).forEach(i=>{r[i.v]=(r[i.v]||0)+e.edge(i).weight}),r});return de(e.nodes(),t)}function Pn(e,t){let n=e.x,r=e.y,i=t.x-n,s=t.y-r,a=e.width/2,o=e.height/2;if(!i&&!s)throw new Error("Not possible to find intersection inside of the rectangle");let l,d;return Math.abs(s)*a>Math.abs(i)*o?(s<0&&(o=-o),l=o*i/s,d=o):(i<0&&(a=-a),l=a,d=a*s/i),{x:n+l,y:r+d}}function Fn(e){let t=Ke(Xe(e)+1).map(()=>[]);return e.nodes().forEach(n=>{let r=e.node(n),i=r.rank;i!==void 0&&(t[i][r.order]=n)}),t}function Dn(e){let t=e.nodes().map(r=>{let i=e.node(r).rank;return i===void 0?Number.MAX_VALUE:i}),n=B(Math.min,t);e.nodes().forEach(r=>{let i=e.node(r);Object.hasOwn(i,"rank")&&(i.rank-=n)})}function Gn(e){let t=e.nodes().map(a=>e.node(a).rank),n=B(Math.min,t),r=[];e.nodes().forEach(a=>{let o=e.node(a).rank-n;r[o]||(r[o]=[]),r[o].push(a)});let i=0,s=e.graph().nodeRankFactor;Array.from(r).forEach((a,o)=>{a===void 0&&o%s!==0?--i:a!==void 0&&i&&a.forEach(l=>e.node(l).rank+=i)})}function An(e,t,n,r){let i={width:0,height:0};return arguments.length>=4&&(i.rank=n,i.order=r),He(e,"border",i,t)}function Vn(e,t=Ue){const n=[];for(let r=0;rUe){const n=Vn(t);return e.apply(null,n.map(r=>e.apply(null,r)))}else return e.apply(null,t)}function Xe(e){const n=e.nodes().map(r=>{let i=e.node(r).rank;return i===void 0?Number.MIN_VALUE:i});return B(Math.max,n)}function Bn(e,t){let n={lhs:[],rhs:[]};return e.forEach(r=>{t(r)?n.lhs.push(r):n.rhs.push(r)}),n}function zn(e,t){let n=Date.now();try{return t()}finally{console.log(e+" time: "+(Date.now()-n)+"ms")}}function Wn(e,t){return t()}let Yn=0;function Qe(e){var t=++Yn;return toString(e)+t}function Ke(e,t,n=1){t==null&&(t=e,e=0);let r=s=>str[t]),Object.entries(e).reduce((r,[i,s])=>(r[i]=n(s,i),r),{})}function de(e,t){return e.reduce((n,r,i)=>(n[r]=t[i],n),{})}let Un=Nn,Xn=E.uniqueId;var Qn={run:Kn,undo:Zn};function Kn(e){(e.graph().acyclicer==="greedy"?Un(e,n(e)):Jn(e)).forEach(r=>{let i=e.edge(r);e.removeEdge(r),i.forwardName=r.name,i.reversed=!0,e.setEdge(r.w,r.v,i,Xn("rev"))});function n(r){return i=>r.edge(i).weight}}function Jn(e){let t=[],n={},r={};function i(s){Object.hasOwn(r,s)||(r[s]=!0,n[s]=!0,e.outEdges(s).forEach(a=>{Object.hasOwn(n,a.w)?t.push(a):i(a.w)}),delete n[s])}return e.nodes().forEach(i),t}function Zn(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)}})}let er=E;var tr={run:nr,undo:ir};function nr(e){e.graph().dummyChains=[],e.edges().forEach(t=>rr(e,t))}function rr(e,t){let n=t.v,r=e.node(n).rank,i=t.w,s=e.node(i).rank,a=t.name,o=e.edge(t),l=o.labelRank;if(s===r+1)return;e.removeEdge(t);let d,c,h;for(h=0,++r;r{let n=e.node(t),r=n.edgeLabel,i;for(e.setEdge(n.edgeObj,r);n.dummy;)i=e.successors(t)[0],e.removeNode(t),r.points.push({x:n.x,y:n.y}),n.dummy==="edge-label"&&(r.x=n.x,r.y=n.y,r.width=n.width,r.height=n.height),t=i,n=e.node(t)})}const{applyWithChunking:sr}=E;var z={longestPath:ar,slack:or};function ar(e){var t={};function n(r){var i=e.node(r);if(Object.hasOwn(t,r))return i.rank;t[r]=!0;let s=e.outEdges(r).map(o=>o==null?Number.POSITIVE_INFINITY:n(o.w)-e.edge(o).minlen);var a=sr(Math.min,s);return a===Number.POSITIVE_INFINITY&&(a=0),i.rank=a}e.sources().forEach(n)}function or(e,t){return e.node(t.w).rank-e.node(t.v).rank-e.edge(t).minlen}var lr=_.Graph,G=z.slack,Je=dr;function dr(e){var t=new lr({directed:!1}),n=e.nodes()[0],r=e.nodeCount();t.setNode(n,{});for(var i,s;cr(t,e){var s=i.v,a=r===s?i.w:s;!e.hasNode(a)&&!G(t,i)&&(e.setNode(a,{}),e.setEdge(r,a,{}),n(a))})}return e.nodes().forEach(n),e.nodeCount()}function hr(e,t){return t.edges().reduce((r,i)=>{let s=Number.POSITIVE_INFINITY;return e.hasNode(i.v)!==e.hasNode(i.w)&&(s=G(t,i)),st.node(r).rank+=n)}var fr=Je,ve=z.slack,pr=z.longestPath,mr=_.alg.preorder,gr=_.alg.postorder,br=E.simplify,wr=I;I.initLowLimValues=he;I.initCutValues=ce;I.calcCutValue=Ze;I.leaveEdge=tt;I.enterEdge=nt;I.exchangeEdges=rt;function I(e){e=br(e),pr(e);var t=fr(e);he(t),ce(t,e);for(var n,r;n=tt(t);)r=nt(t,e,n),rt(t,e,n,r)}function ce(e,t){var n=gr(e,e.nodes());n=n.slice(0,n.length-1),n.forEach(r=>xr(e,t,r))}function xr(e,t,n){var r=e.node(n),i=r.parent;e.edge(n,i).cutvalue=Ze(e,t,n)}function Ze(e,t,n){var r=e.node(n),i=r.parent,s=!0,a=t.edge(n,i),o=0;return a||(s=!1,a=t.edge(i,n)),o=a.weight,t.nodeEdges(n).forEach(l=>{var d=l.v===n,c=d?l.w:l.v;if(c!==i){var h=d===s,f=t.edge(l).weight;if(o+=h?f:-f,vr(e,n,c)){var p=e.edge(n,c).cutvalue;o+=h?-p:p}}}),o}function he(e,t){arguments.length<2&&(t=e.nodes()[0]),et(e,{},1,t)}function et(e,t,n,r,i){var s=n,a=e.node(r);return t[r]=!0,e.neighbors(r).forEach(o=>{Object.hasOwn(t,o)||(n=et(e,t,n,o,r))}),a.low=s,a.lim=n++,i?a.parent=i:delete a.parent,n}function tt(e){return e.edges().find(t=>e.edge(t).cutvalue<0)}function nt(e,t,n){var r=n.v,i=n.w;t.hasEdge(r,i)||(r=n.w,i=n.v);var s=e.node(r),a=e.node(i),o=s,l=!1;s.lim>a.lim&&(o=a,l=!0);var d=t.edges().filter(c=>l===ye(e,e.node(c.v),o)&&l!==ye(e,e.node(c.w),o));return d.reduce((c,h)=>ve(t,h)!t.node(i).parent),r=mr(e,n);r=r.slice(1),r.forEach(i=>{var s=e.node(i).parent,a=t.edge(i,s),o=!1;a||(a=t.edge(s,i),o=!0),t.node(i).rank=t.node(s).rank+(o?a.minlen:-a.minlen)})}function vr(e,t,n){return e.hasEdge(t,n)}function ye(e,t,n){return n.low<=t.lim&&t.lim<=n.lim}var yr=z,it=yr.longestPath,_r=Je,kr=wr,jr=Nr;function Nr(e){switch(e.graph().ranker){case"network-simplex":_e(e);break;case"tight-tree":Cr(e);break;case"longest-path":Or(e);break;default:_e(e)}}var Or=it;function Cr(e){it(e),_r(e)}function _e(e){kr(e)}var Ir=$r;function $r(e){let t=Tr(e);e.graph().dummyChains.forEach(n=>{let r=e.node(n),i=r.edgeObj,s=Lr(e,t,i.v,i.w),a=s.path,o=s.lca,l=0,d=a[l],c=!0;for(;n!==i.w;){if(r=e.node(n),c){for(;(d=a[l])!==o&&e.node(d).maxRanka||o>t[l].lim));for(d=l,l=r;(l=e.parent(l))!==d;)s.push(l);return{path:i.concat(s.reverse()),lca:d}}function Tr(e){let t={},n=0;function r(i){let s=n;e.children(i).forEach(r),t[i]={low:s,lim:n++}}return e.children().forEach(r),t}let A=E;var Sr={run:Rr,cleanup:Fr};function Rr(e){let t=A.addDummyNode(e,"root",{},"_root"),n=Mr(e),r=Object.values(n),i=A.applyWithChunking(Math.max,r)-1,s=2*i+1;e.graph().nestingRoot=t,e.edges().forEach(o=>e.edge(o).minlen*=s);let a=Pr(e)+1;e.children().forEach(o=>st(e,t,s,a,i,n,o)),e.graph().nodeRankFactor=s}function st(e,t,n,r,i,s,a){let o=e.children(a);if(!o.length){a!==t&&e.setEdge(t,a,{weight:0,minlen:n});return}let l=A.addBorderNode(e,"_bt"),d=A.addBorderNode(e,"_bb"),c=e.node(a);e.setParent(l,a),c.borderTop=l,e.setParent(d,a),c.borderBottom=d,o.forEach(h=>{st(e,t,n,r,i,s,h);let f=e.node(h),p=f.borderTop?f.borderTop:h,m=f.borderBottom?f.borderBottom:h,g=f.borderTop?r:2*r,b=p!==m?1:i-s[a]+1;e.setEdge(l,p,{weight:g,minlen:b,nestingEdge:!0}),e.setEdge(m,d,{weight:g,minlen:b,nestingEdge:!0})}),e.parent(a)||e.setEdge(t,l,{weight:0,minlen:i+s[a]})}function Mr(e){var t={};function n(r,i){var s=e.children(r);s&&s.length&&s.forEach(a=>n(a,i+1)),t[r]=i}return e.children().forEach(r=>n(r,1)),t}function Pr(e){return e.edges().reduce((t,n)=>t+e.edge(n).weight,0)}function Fr(e){var t=e.graph();e.removeNode(t.nestingRoot),delete t.nestingRoot,e.edges().forEach(n=>{var r=e.edge(n);r.nestingEdge&&e.removeEdge(n)})}let Dr=E;var Gr=Ar;function Ar(e){function t(n){let r=e.children(n),i=e.node(n);if(r.length&&r.forEach(t),Object.hasOwn(i,"minRank")){i.borderLeft=[],i.borderRight=[];for(let s=i.minRank,a=i.maxRank+1;sje(e.node(t))),e.edges().forEach(t=>je(e.edge(t)))}function je(e){let t=e.width;e.width=e.height,e.height=t}function Wr(e){e.nodes().forEach(t=>q(e.node(t))),e.edges().forEach(t=>{let n=e.edge(t);n.points.forEach(q),Object.hasOwn(n,"y")&&q(n)})}function q(e){e.y=-e.y}function Yr(e){e.nodes().forEach(t=>H(e.node(t))),e.edges().forEach(t=>{let n=e.edge(t);n.points.forEach(H),Object.hasOwn(n,"x")&&H(n)})}function H(e){let t=e.x;e.x=e.y,e.y=t}let Ne=E;var qr=Hr;function Hr(e){let t={},n=e.nodes().filter(l=>!e.children(l).length),r=n.map(l=>e.node(l).rank),i=Ne.applyWithChunking(Math.max,r),s=Ne.range(i+1).map(()=>[]);function a(l){if(t[l])return;t[l]=!0;let d=e.node(l);s[d.rank].push(l),e.successors(l).forEach(a)}return n.sort((l,d)=>e.node(l).rank-e.node(d).rank).forEach(a),s}let Ur=E.zipObject;var Xr=Qr;function Qr(e,t){let n=0;for(let r=1;rc)),i=t.flatMap(d=>e.outEdges(d).map(c=>({pos:r[c.w],weight:e.edge(c).weight})).sort((c,h)=>c.pos-h.pos)),s=1;for(;s{let c=d.pos+s;o[c]+=d.weight;let h=0;for(;c>0;)c%2&&(h+=o[c+1]),c=c-1>>1,o[c]+=d.weight;l+=d.weight*h}),l}var Jr=Zr;function Zr(e,t=[]){return t.map(n=>{let r=e.inEdges(n);if(r.length){let i=r.reduce((s,a)=>{let o=e.edge(a),l=e.node(a.v);return{sum:s.sum+o.weight*l.order,weight:s.weight+o.weight}},{sum:0,weight:0});return{v:n,barycenter:i.sum/i.weight,weight:i.weight}}else return{v:n}})}let ei=E;var ti=ni;function ni(e,t){let n={};e.forEach((i,s)=>{let a=n[i.v]={indegree:0,in:[],out:[],vs:[i.v],i:s};i.barycenter!==void 0&&(a.barycenter=i.barycenter,a.weight=i.weight)}),t.edges().forEach(i=>{let s=n[i.v],a=n[i.w];s!==void 0&&a!==void 0&&(a.indegree++,s.out.push(n[i.w]))});let r=Object.values(n).filter(i=>!i.indegree);return ri(r)}function ri(e){let t=[];function n(i){return s=>{s.merged||(s.barycenter===void 0||i.barycenter===void 0||s.barycenter>=i.barycenter)&&ii(i,s)}}function r(i){return s=>{s.in.push(i),--s.indegree===0&&e.push(s)}}for(;e.length;){let i=e.pop();t.push(i),i.in.reverse().forEach(n(i)),i.out.forEach(r(i))}return t.filter(i=>!i.merged).map(i=>ei.pick(i,["vs","i","barycenter","weight"]))}function ii(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}let si=E;var ai=oi;function oi(e,t){let n=si.partition(e,c=>Object.hasOwn(c,"barycenter")),r=n.lhs,i=n.rhs.sort((c,h)=>h.i-c.i),s=[],a=0,o=0,l=0;r.sort(li(!!t)),l=Oe(s,i,l),r.forEach(c=>{l+=c.vs.length,s.push(c.vs),a+=c.barycenter*c.weight,o+=c.weight,l=Oe(s,i,l)});let d={vs:s.flat(!0)};return o&&(d.barycenter=a/o,d.weight=o),d}function Oe(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 li(e){return(t,n)=>t.barycentern.barycenter?1:e?n.i-t.i:t.i-n.i}let di=Jr,ci=ti,hi=ai;var ui=ot;function ot(e,t,n,r){let i=e.children(t),s=e.node(t),a=s?s.borderLeft:void 0,o=s?s.borderRight:void 0,l={};a&&(i=i.filter(f=>f!==a&&f!==o));let d=di(e,i);d.forEach(f=>{if(e.children(f.v).length){let p=ot(e,f.v,n,r);l[f.v]=p,Object.hasOwn(p,"barycenter")&&pi(f,p)}});let c=ci(d,n);fi(c,l);let h=hi(c,r);if(a&&(h.vs=[a,h.vs,o].flat(!0),e.predecessors(a).length)){let f=e.node(e.predecessors(a)[0]),p=e.node(e.predecessors(o)[0]);Object.hasOwn(h,"barycenter")||(h.barycenter=0,h.weight=0),h.barycenter=(h.barycenter*h.weight+f.order+p.order)/(h.weight+2),h.weight+=2}return h}function fi(e,t){e.forEach(n=>{n.vs=n.vs.flatMap(r=>t[r]?t[r].vs:r)})}function pi(e,t){e.barycenter!==void 0?(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)}let mi=_.Graph,gi=E;var bi=wi;function wi(e,t,n){let r=xi(e),i=new mi({compound:!0}).setGraph({root:r}).setDefaultNodeLabel(s=>e.node(s));return e.nodes().forEach(s=>{let a=e.node(s),o=e.parent(s);(a.rank===t||a.minRank<=t&&t<=a.maxRank)&&(i.setNode(s),i.setParent(s,o||r),e[n](s).forEach(l=>{let d=l.v===s?l.w:l.v,c=i.edge(d,s),h=c!==void 0?c.weight:0;i.setEdge(d,s,{weight:e.edge(l).weight+h})}),Object.hasOwn(a,"minRank")&&i.setNode(s,{borderLeft:a.borderLeft[t],borderRight:a.borderRight[t]}))}),i}function xi(e){for(var t;e.hasNode(t=gi.uniqueId("_root")););return t}var Ei=vi;function vi(e,t,n){let r={},i;n.forEach(s=>{let a=e.parent(s),o,l;for(;a;){if(o=e.parent(a),o?(l=r[o],r[o]=a):(l=i,i=a),l&&l!==a){t.setEdge(l,a);return}a=o}})}let yi=qr,_i=Xr,ki=ui,ji=bi,Ni=Ei,Oi=_.Graph,M=E;var Ci=lt;function lt(e,t){if(t&&typeof t.customOrder=="function"){t.customOrder(e,lt);return}let n=M.maxRank(e),r=Ce(e,M.range(1,n+1),"inEdges"),i=Ce(e,M.range(n-1,-1,-1),"outEdges"),s=yi(e);if(Ie(e,s),t&&t.disableOptimalOrderHeuristic)return;let a=Number.POSITIVE_INFINITY,o;for(let l=0,d=0;d<4;++l,++d){Ii(l%2?r:i,l%4>=2),s=M.buildLayerMatrix(e);let c=_i(e,s);cr.node(a).order=o),Ni(r,n,s.vs)})}function Ie(e,t){Object.values(t).forEach(n=>n.forEach((r,i)=>e.node(r).order=i))}let $i=_.Graph,N=E;var Li={positionX:Bi};function Ti(e,t){let n={};function r(i,s){let a=0,o=0,l=i.length,d=s[s.length-1];return s.forEach((c,h)=>{let f=Ri(e,c),p=f?e.node(f).order:l;(f||c===d)&&(s.slice(o,h+1).forEach(m=>{e.predecessors(m).forEach(g=>{let b=e.node(g),j=b.order;(j{c=s[h],e.node(c).dummy&&e.predecessors(c).forEach(f=>{let p=e.node(f);p.dummy&&(p.orderd)&&dt(n,f,c)})})}function i(s,a){let o=-1,l,d=0;return a.forEach((c,h)=>{if(e.node(c).dummy==="border"){let f=e.predecessors(c);f.length&&(l=e.node(f[0]).order,r(a,d,h,o,l),d=h,o=l)}r(a,d,a.length,l,s.length)}),a}return t.length&&t.reduce(i),n}function Ri(e,t){if(e.node(t).dummy)return e.predecessors(t).find(n=>e.node(n).dummy)}function dt(e,t,n){if(t>n){let i=t;t=n,n=i}let r=e[t];r||(e[t]=r={}),r[n]=!0}function Mi(e,t,n){if(t>n){let r=t;t=n,n=r}return!!e[t]&&Object.hasOwn(e[t],n)}function Pi(e,t,n,r){let i={},s={},a={};return t.forEach(o=>{o.forEach((l,d)=>{i[l]=l,s[l]=l,a[l]=d})}),t.forEach(o=>{let l=-1;o.forEach(d=>{let c=r(d);if(c.length){c=c.sort((f,p)=>a[f]-a[p]);let h=(c.length-1)/2;for(let f=Math.floor(h),p=Math.ceil(h);f<=p;++f){let m=c[f];s[d]===d&&lMath.max(f,s[p.v]+a.edge(p)),0)}function c(h){let f=a.outEdges(h).reduce((m,g)=>Math.min(m,s[g.w]-a.edge(g)),Number.POSITIVE_INFINITY),p=e.node(h);f!==Number.POSITIVE_INFINITY&&p.borderType!==o&&(s[h]=Math.max(s[h],f))}return l(d,a.predecessors.bind(a)),l(c,a.successors.bind(a)),Object.keys(r).forEach(h=>s[h]=s[n[h]]),s}function Di(e,t,n,r){let i=new $i,s=e.graph(),a=zi(s.nodesep,s.edgesep,r);return t.forEach(o=>{let l;o.forEach(d=>{let c=n[d];if(i.setNode(c),l){var h=n[l],f=i.edge(h,c);i.setEdge(h,c,Math.max(a(e,d,l),f||0))}l=d})}),i}function Gi(e,t){return Object.values(t).reduce((n,r)=>{let i=Number.NEGATIVE_INFINITY,s=Number.POSITIVE_INFINITY;Object.entries(r).forEach(([o,l])=>{let d=Wi(e,o)/2;i=Math.max(l+d,i),s=Math.min(l-d,s)});const a=i-s;return a{["l","r"].forEach(a=>{let o=s+a,l=e[o];if(l===t)return;let d=Object.values(l),c=r-N.applyWithChunking(Math.min,d);a!=="l"&&(c=i-N.applyWithChunking(Math.max,d)),c&&(e[o]=N.mapValues(l,h=>h+c))})})}function Vi(e,t){return N.mapValues(e.ul,(n,r)=>{if(t)return e[t.toLowerCase()][r];{let i=Object.values(e).map(s=>s[r]).sort((s,a)=>s-a);return(i[1]+i[2])/2}})}function Bi(e){let t=N.buildLayerMatrix(e),n=Object.assign(Ti(e,t),Si(e,t)),r={},i;["u","d"].forEach(a=>{i=a==="u"?t:Object.values(t).reverse(),["l","r"].forEach(o=>{o==="r"&&(i=i.map(h=>Object.values(h).reverse()));let l=(a==="u"?e.predecessors:e.successors).bind(e),d=Pi(e,i,n,l),c=Fi(e,i,d.root,d.align,o==="r");o==="r"&&(c=N.mapValues(c,h=>-h)),r[a+o]=c})});let s=Gi(e,r);return Ai(r,s),Vi(r,e.graph().align)}function zi(e,t,n){return(r,i,s)=>{let a=r.node(i),o=r.node(s),l=0,d;if(l+=a.width/2,Object.hasOwn(a,"labelpos"))switch(a.labelpos.toLowerCase()){case"l":d=-a.width/2;break;case"r":d=a.width/2;break}if(d&&(l+=n?d:-d),d=0,l+=(a.dummy?t:e)/2,l+=(o.dummy?t:e)/2,l+=o.width/2,Object.hasOwn(o,"labelpos"))switch(o.labelpos.toLowerCase()){case"l":d=o.width/2;break;case"r":d=-o.width/2;break}return d&&(l+=n?d:-d),d=0,l}}function Wi(e,t){return e.node(t).width}let ct=E,Yi=Li.positionX;var qi=Hi;function Hi(e){e=ct.asNonCompoundGraph(e),Ui(e),Object.entries(Yi(e)).forEach(([t,n])=>e.node(t).x=n)}function Ui(e){let t=ct.buildLayerMatrix(e),n=e.graph().ranksep,r=0;t.forEach(i=>{const s=i.reduce((a,o)=>{const l=e.node(o).height;return a>l?a:l},0);i.forEach(a=>e.node(a).y=r+s/2),r+=s+n})}let $e=Qn,Le=tr,Xi=jr,Qi=E.normalizeRanks,Ki=Ir,Ji=E.removeEmptyRanks,Te=Sr,Zi=Gr,Se=Vr,es=Ci,ts=qi,y=E,ns=_.Graph;var rs=is;function is(e,t){let n=t&&t.debugTiming?y.time:y.notime;n("layout",()=>{let r=n(" buildLayoutGraph",()=>ps(e));n(" runLayout",()=>ss(r,n,t)),n(" updateInputGraph",()=>as(e,r))})}function ss(e,t,n){t(" makeSpaceForEdgeLabels",()=>ms(e)),t(" removeSelfEdges",()=>ks(e)),t(" acyclic",()=>$e.run(e)),t(" nestingGraph.run",()=>Te.run(e)),t(" rank",()=>Xi(y.asNonCompoundGraph(e))),t(" injectEdgeLabelProxies",()=>gs(e)),t(" removeEmptyRanks",()=>Ji(e)),t(" nestingGraph.cleanup",()=>Te.cleanup(e)),t(" normalizeRanks",()=>Qi(e)),t(" assignRankMinMax",()=>bs(e)),t(" removeEdgeLabelProxies",()=>ws(e)),t(" normalize.run",()=>Le.run(e)),t(" parentDummyChains",()=>Ki(e)),t(" addBorderSegments",()=>Zi(e)),t(" order",()=>es(e,n)),t(" insertSelfEdges",()=>js(e)),t(" adjustCoordinateSystem",()=>Se.adjust(e)),t(" position",()=>ts(e)),t(" positionSelfEdges",()=>Ns(e)),t(" removeBorderNodes",()=>_s(e)),t(" normalize.undo",()=>Le.undo(e)),t(" fixupEdgeLabelCoords",()=>vs(e)),t(" undoCoordinateSystem",()=>Se.undo(e)),t(" translateGraph",()=>xs(e)),t(" assignNodeIntersects",()=>Es(e)),t(" reversePoints",()=>ys(e)),t(" acyclic.undo",()=>$e.undo(e))}function as(e,t){e.nodes().forEach(n=>{let r=e.node(n),i=t.node(n);r&&(r.x=i.x,r.y=i.y,r.rank=i.rank,t.children(n).length&&(r.width=i.width,r.height=i.height))}),e.edges().forEach(n=>{let r=e.edge(n),i=t.edge(n);r.points=i.points,Object.hasOwn(i,"x")&&(r.x=i.x,r.y=i.y)}),e.graph().width=t.graph().width,e.graph().height=t.graph().height}let os=["nodesep","edgesep","ranksep","marginx","marginy"],ls={ranksep:50,edgesep:20,nodesep:50,rankdir:"tb"},ds=["acyclicer","ranker","rankdir","align"],cs=["width","height"],Re={width:0,height:0},hs=["minlen","weight","width","height","labeloffset"],us={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},fs=["labelpos"];function ps(e){let t=new ns({multigraph:!0,compound:!0}),n=X(e.graph());return t.setGraph(Object.assign({},ls,U(n,os),y.pick(n,ds))),e.nodes().forEach(r=>{let i=X(e.node(r));const s=U(i,cs);Object.keys(Re).forEach(a=>{s[a]===void 0&&(s[a]=Re[a])}),t.setNode(r,s),t.setParent(r,e.parent(r))}),e.edges().forEach(r=>{let i=X(e.edge(r));t.setEdge(r,Object.assign({},us,U(i,hs),y.pick(i,fs)))}),t}function ms(e){let t=e.graph();t.ranksep/=2,e.edges().forEach(n=>{let r=e.edge(n);r.minlen*=2,r.labelpos.toLowerCase()!=="c"&&(t.rankdir==="TB"||t.rankdir==="BT"?r.width+=r.labeloffset:r.height+=r.labeloffset)})}function gs(e){e.edges().forEach(t=>{let n=e.edge(t);if(n.width&&n.height){let r=e.node(t.v),s={rank:(e.node(t.w).rank-r.rank)/2+r.rank,e:t};y.addDummyNode(e,"edge-proxy",s,"_ep")}})}function bs(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}function ws(e){e.nodes().forEach(t=>{let n=e.node(t);n.dummy==="edge-proxy"&&(e.edge(n.e).labelRank=n.rank,e.removeNode(t))})}function xs(e){let t=Number.POSITIVE_INFINITY,n=0,r=Number.POSITIVE_INFINITY,i=0,s=e.graph(),a=s.marginx||0,o=s.marginy||0;function l(d){let c=d.x,h=d.y,f=d.width,p=d.height;t=Math.min(t,c-f/2),n=Math.max(n,c+f/2),r=Math.min(r,h-p/2),i=Math.max(i,h+p/2)}e.nodes().forEach(d=>l(e.node(d))),e.edges().forEach(d=>{let c=e.edge(d);Object.hasOwn(c,"x")&&l(c)}),t-=a,r-=o,e.nodes().forEach(d=>{let c=e.node(d);c.x-=t,c.y-=r}),e.edges().forEach(d=>{let c=e.edge(d);c.points.forEach(h=>{h.x-=t,h.y-=r}),Object.hasOwn(c,"x")&&(c.x-=t),Object.hasOwn(c,"y")&&(c.y-=r)}),s.width=n-t+a,s.height=i-r+o}function Es(e){e.edges().forEach(t=>{let n=e.edge(t),r=e.node(t.v),i=e.node(t.w),s,a;n.points?(s=n.points[0],a=n.points[n.points.length-1]):(n.points=[],s=i,a=r),n.points.unshift(y.intersectRect(r,s)),n.points.push(y.intersectRect(i,a))})}function vs(e){e.edges().forEach(t=>{let n=e.edge(t);if(Object.hasOwn(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}})}function ys(e){e.edges().forEach(t=>{let n=e.edge(t);n.reversed&&n.points.reverse()})}function _s(e){e.nodes().forEach(t=>{if(e.children(t).length){let n=e.node(t),r=e.node(n.borderTop),i=e.node(n.borderBottom),s=e.node(n.borderLeft[n.borderLeft.length-1]),a=e.node(n.borderRight[n.borderRight.length-1]);n.width=Math.abs(a.x-s.x),n.height=Math.abs(i.y-r.y),n.x=s.x+n.width/2,n.y=r.y+n.height/2}}),e.nodes().forEach(t=>{e.node(t).dummy==="border"&&e.removeNode(t)})}function ks(e){e.edges().forEach(t=>{if(t.v===t.w){var n=e.node(t.v);n.selfEdges||(n.selfEdges=[]),n.selfEdges.push({e:t,label:e.edge(t)}),e.removeEdge(t)}})}function js(e){var t=y.buildLayerMatrix(e);t.forEach(n=>{var r=0;n.forEach((i,s)=>{var a=e.node(i);a.order=s+r,(a.selfEdges||[]).forEach(o=>{y.addDummyNode(e,"selfedge",{width:o.label.width,height:o.label.height,rank:a.rank,order:s+ ++r,e:o.e,label:o.label},"_se")}),delete a.selfEdges})})}function Ns(e){e.nodes().forEach(t=>{var n=e.node(t);if(n.dummy==="selfedge"){var r=e.node(n.e.v),i=r.x+r.width/2,s=r.y,a=n.x-i,o=r.height/2;e.setEdge(n.e,n.label),e.removeNode(t),n.label.points=[{x:i+2*a/3,y:s-o},{x:i+5*a/6,y:s-o},{x:i+a,y:s},{x:i+5*a/6,y:s+o},{x:i+2*a/3,y:s+o}],n.label.x=n.x,n.label.y=n.y}})}function U(e,t){return y.mapValues(y.pick(e,t),Number)}function X(e){var t={};return e&&Object.entries(e).forEach(([n,r])=>{typeof n=="string"&&(n=n.toLowerCase()),t[n]=r}),t}let Os=E,Cs=_.Graph;var Is={debugOrdering:$s};function $s(e){let t=Os.buildLayerMatrix(e),n=new Cs({compound:!0,multigraph:!0}).setGraph({});return e.nodes().forEach(r=>{n.setNode(r,{label:r}),n.setParent(r,"layer"+e.node(r).rank)}),e.edges().forEach(r=>n.setEdge(r.v,r.w,{},r.name)),t.forEach((r,i)=>{let s="layer"+i;n.setNode(s,{rank:"same"}),r.reduce((a,o)=>(n.setEdge(a,o,{style:"invis"}),o))}),n}var Ls="1.1.4",Ts={graphlib:_,layout:rs,debug:Is,util:{time:E.time,notime:E.notime},version:Ls};const Me=ut(Ts),V={width:400,height:167},re={width:400,height:61},ie={width:400,height:40},Ss=S.div` width: 100%; height: 100%; .chart-node { display: flex; flex-direction: column; gap: 10px; padding: 6px; border-radius: 4px; border: 1px solid ${w.color.light[600]}; background-color: ${w.color.light[500]}; box-sizing: border-box; justify-content: center; width: 400px; &.pending .source-handle { opacity: 0.3; } .source-handle { transition: opacity 1s ease; opacity: 1; } &.running .source-handle { opacity: 0; } &.step { width: ${V.width}px; min-height: ${V.height}px; } &.planning { width: ${re.width}px; min-height: ${re.height}px; } &.answer { width: ${ie.width}px; min-height: ${ie.height}px; } header { display: flex; gap: 4px; align-items: center; .step-index { flex: 1; white-space: nowrap; text-overflow: ellipsis; } } .step-title { white-space: nowrap; text-overflow: ellipsis; color: ${w.color.light[700]}; overflow-x: clip; } .step-details { background-color: ${w.color.light[400]}; border-radius: 2px; padding: 8px; flex: 1; display: flex; flex-direction: column; align-items: start; justify-content: space-between; gap: 8px; overflow: hidden; .step-description { flex: 1; line-height: 18px; max-height: 72px; // line-height * 4 overflow: hidden; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; &.with-tools { max-height: 36px; // line-height * 2 -webkit-line-clamp: 2; } } } .wrapper-tool { &:not(:last-child) { border-bottom: 1px solid ${w.color.light[600]}; padding-bottom: 8px; } .tool { padding: 8px; border-radius: 4px; min-height: 48px; border: 1px solid ${w.color.light[500]}; background-color: ${w.color.light[400]}; border-bottom: 1px solid ${w.color.light[300]}; cursor: pointer; &:hover .title { text-decoration: underline; } } } } .source-handle { background-color: ${w.color.light[700]}; border: none; } .target-handle { opacity: 0; } .controls { background-color: ${w.color.light[300]}; border-radius: 4px; border: none; display: flex; button { background: transparent; border: none; } } .edge { path { stroke: ${w.color.light[700]}; stroke-width: 2px; } &.pending path { opacity: 0.3; } &.running path { stroke-dasharray: 5, 5; } } .react-flow__attribution { background-color: transparent; opacity: 0.1; } `,Pe={step:V,planning:re,answer:ie,tool:V},Rs=e=>{switch(e){case"TB":return{target:k.Top,source:k.Bottom};case"BT":return{target:k.Bottom,source:k.Top};case"LR":return{target:k.Left,source:k.Right};case"RL":return{target:k.Right,source:k.Left}}};function Ms(e,t,n="LR"){const r=x.useMemo(()=>new Me.graphlib.Graph().setDefaultEdgeLabel(()=>({})),[]);return x.useMemo(()=>{r.setGraph({rankdir:n}),e.forEach(o=>{const{width:l,height:d}=Pe[o.type],c=o.width??l,h=o.height??d;r.setNode(o.id,{width:c,height:h})}),t.forEach(o=>{r.setEdge(o.source,o.target)}),Me.layout(r);const{target:i,source:s}=Rs(n);return{nodes:e.map(o=>{const{width:l,height:d}=Pe[o.type],c=o?.width??l,h=o.height??d,f=r.node(o.id);return{...o,targetPosition:i,sourcePosition:s,position:{x:f.x-c/2,y:f.y-h/2}}}),edges:t}},[e,t])}const ht=({renderSource:e=!0,renderTarget:t=!0,targetPosition:n,sourcePosition:r})=>u.jsxs(u.Fragment,{children:[t&&u.jsx(ue,{type:"target",position:n||k.Left,isConnectable:!0,className:"target-handle"}),e&&u.jsx(ue,{type:"source",position:r||k.Right,isConnectable:!0,className:"source-handle"})]}),Ps=(e,t=50)=>{const n=x.useRef(null),r=x.useRef(null);return x.useEffect(()=>{if(!n.current||!e)return;const i=se.debounce(a=>{const o=r.current;(!o||o.width!==a.width||o.height!==a.height)&&(r.current=a,e(a))},t),s=new ResizeObserver(a=>{if(!a.length)return;const{width:o,height:l}=a[0].contentRect;i({width:o,height:l})});return s.observe(n.current),()=>{s.disconnect(),i.cancel()}},[e]),n},Fs=({tool:e,index:t,onClick:n})=>{const{name:r,image:i,input:s,status:a}=e;return a==="running"?u.jsx(mt,{height:"48px",bgLevel:600}):u.jsxs("div",{className:"tool",onClick:()=>n?.(t),children:[u.jsxs(L,{gap:"4px",alignItems:"center",mb:2,children:[i?u.jsx(De,{size:"xxs",image:i,name:r}):u.jsx(Z,{icon:"Cog",group:"outline"}),u.jsx(v,{weight:"500",className:"title",children:r})]}),u.jsx(v,{nowrapEllipsis:!0,color:"light.700",children:s})]})},Ds=({tools:e,onClick:t})=>u.jsx(pt,{children:u.jsx(D,{gap:"8px",children:e.map((n,r)=>u.jsx(D,{className:"wrapper-tool",children:u.jsx(Fs,{tool:n,index:r,onClick:t})},`${n.id}-${r}`))})}),Fe=({title:e,icon:t,content:n,onClick:r})=>u.jsxs(D,{onClick:r,style:{cursor:r?"pointer":"default"},children:[u.jsxs(L,{gap:"4px",alignItems:"center",children:[u.jsx(ft,{...t,appearance:"none",colorScheme:"light",size:"sm"}),u.jsx(v,{className:"step-index",weight:"500",children:e})]}),u.jsx(v,{nowrapEllipsis:!0,color:"light.700",children:n})]}),Q=({data:e,...t})=>{const{step:n,index:r,onClick:i,onResize:s,message:a}=e,o=ae(a)?.content,l=oe(),d=Ps(s),c=n.type==="step"?n?.attempts?.[0]?.tools:void 0,h=()=>{if(n.type==="planning")return u.jsx(Fe,{title:l.userPrompt,content:n.user_question,icon:{...J(n.type)}});if(n.type==="step")return c?.length?u.jsx(Ds,{onClick:i,tools:c}):null;if(n.type==="answer")return u.jsx(D,{p:3,bg:"light.400",onClick:()=>i?.(r),children:u.jsx(Fe,{onClick:i,title:l.finalAnswer,content:o,icon:{...J(n.type)}})})};return u.jsx("div",{ref:d,"aria-label":F(l,n,r),children:u.jsxs("div",{className:T(["chart-node",null,n.status]),children:[h(),u.jsx(ht,{...t,renderSource:n.type!=="answer",renderTarget:n.type!=="planning"})]})})},Gs=S.div` border-radius: 25px; background-color: ${w.color.light[600]}; border: 1px solid ${w.color.light[500]}; color: ${w.color.light[700]}; padding: 2px 7px; display: flex; gap: 5px; align-items: center; small { line-height: 0.75rem; } ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: row; li { border: 1px solid ${w.color.light[600]}; background-color: ${w.color.light[400]}; border-radius: 50%; width: 16px; height: 16px; overflow: hidden; display: flex; align-items: center; justify-content: center; &:not(:first-child) { margin-left: -12px; } } .citric-icon { margin: 1px; font-size: 10px; } img, svg { width: 100%; height: 100%; } } `,As=({label:e,images:t,...n})=>u.jsxs(Gs,{...n,children:[u.jsx(v,{appearance:"microtext1",children:e}),u.jsx("ul",{children:t.map(({key:r,name:i,url:s,icon:a},o)=>u.jsx("li",{children:s?u.jsx("img",{alt:i,"aria-label":i,title:i,src:s}):u.jsx("span",{"aria-label":i,title:i,children:a})},r||o))})]}),K=({data:{step:e,index:t,nextStatus:n,onClick:r},...i})=>{const s=oe();return u.jsxs("div",{className:T(["chart-node",e.type,n]),onClick:()=>r?.(),onKeyDown:a=>a.key==="Enter"&&r?.(),tabIndex:0,role:"button","aria-label":F(s,e,t),children:[u.jsxs("header",{children:[u.jsx(Z,{...J(e.type)}),u.jsx(v,{className:"step-index",children:F(s,e,t)}),gt(e.status)]}),e.type==="planning"&&u.jsx(v,{className:"step-title",children:e.goal}),e.type==="step"&&e.input&&u.jsx(v,{className:"step-title",children:e.input}),e.type==="step"&&u.jsxs("div",{className:"step-details",children:[u.jsx(v,{className:T(["step-description",!!e.attempts[0].tools?.length&&"with-tools"]),children:e.output}),!!e.attempts[0].tools?.length&&u.jsx(As,{label:s.tools,images:e.attempts[0].tools?.slice(0,3).map(a=>({key:a.id,name:a.name??"",url:a.image,icon:u.jsx(Z,{icon:"Cog"})}))})]}),u.jsx(ht,{...i,renderSource:e.type!=="answer",renderTarget:e.type!=="planning"})," "]})},Vs={step:{planning:K,step:K,answer:K},stepDynamic:{planning:Q,step:Q,answer:Q}},Bs=({message:e,onClick:t,direction:n="LR"})=>{const r=ae(e).steps,[i,s]=x.useState({}),a=wt(),o=x.useMemo(()=>r?.some(p=>p.id==="dynamic"),[r]),l=x.useMemo(()=>Vs[o?"stepDynamic":"step"],[o]),d=x.useCallback((p,m)=>{s(g=>{const b=g[p];return b?.width===m.width&&b?.height===m.height?g:{...g,[p]:m}})},[]),c=x.useMemo(()=>{const p=r?.map((g,b)=>{const j=i[g.id];return{id:g.id,type:g.type,focusable:!1,...j&&{width:j.width,height:j.height},origin:[1,0],data:{message:e,step:g,index:b,nextStatus:r[b+1]?.status,onClick:O=>t(g,O),onResize:O=>d(g.id,O)}}})??[],m=[];for(let g=0;g{const p=se.last(h),m=p?.data?.step?.status==="running";(h.length>2&&m||(p?.height??!1)&&m)&&a.fitView({duration:1e3,padding:{bottom:"120px",top:"20px"}})},[h,f,a]),u.jsx(Ss,{children:u.jsxs(Et,{nodes:h,edges:f,nodeTypes:l,snapToGrid:!0,fitView:!0,maxZoom:1,children:[u.jsx(vt,{orientation:"horizontal",className:"controls",showInteractive:!1}),u.jsx(yt,{})]})})},zs=e=>u.jsx(bt,{children:u.jsx(Bs,{...e})}),Ws=S.div` opacity: 0; transition: opacity ${({$durationMs:e})=>e/1e3}s; &.visible { opacity: 1; } `,Ys=x.forwardRef(({children:e,visible:t,durationMs:n=300},r)=>{const[i,s]=x.useState(t?e:null),a=x.useRef(),o=x.useRef();return x.useEffect(()=>{const l=o===void 0,d=t!==o.current;if(o.current=t,!l){if(d){if(a.current)return window.clearTimeout(a.current),a.current=void 0,s(t?e:null);t&&s(e),a.current=window.setTimeout(()=>{t||s(null),a.current=void 0},n)}else(t||!a.current)&&s(t?e:null);return()=>{window.clearTimeout(a.current)}}},[t,e]),u.jsx(Ws,{ref:r,$durationMs:n,className:T(["fade-animation",t&&"visible"]),children:i})}),qs=({title:e,children:t,onClose:n})=>{const r=kt(Us);return u.jsxs("div",{className:"chat-modal",children:[u.jsxs("header",{children:[typeof e=="string"?u.jsx(v,{appearance:"h6",children:e}):e,u.jsx(ee,{icon:"Times","aria-label":r.close,title:r.close,onClick:n})]}),u.jsx("article",{children:t})]})},Hs=({title:e,onClose:t,open:n,children:r})=>{const i=x.useRef(null),[s,a]=x.useState();return x.useEffect(()=>{if(!s){const h=i.current?.closest(".ai-chat-widget");if(!h)throw new Error("Could not find the chat widget (.ai-chat-widget) in the HTML tree.");return a(h)}if(!n)return;const o=s?.querySelector(".chat-window"),l=s?.querySelector(".chat-right-panel");function d(h){s?.querySelector(".chat-modal")?.contains(h.target)||t?.()}function c(h){h.key==="Escape"&&t?.()}return o?.setAttribute("inert",""),l?.setAttribute("inert",""),s?.addEventListener("click",d),document.addEventListener("keydown",c),()=>{o?.removeAttribute("inert"),l?.removeAttribute("inert"),s?.removeEventListener("click",d),document.removeEventListener("keydown",c)}},[n]),u.jsx("div",{ref:i,children:s&&_t.createPortal(u.jsx(Ys,{visible:n,children:u.jsx(qs,{title:e,onClose:t,children:r})}),s)})},Us={en:{close:"Close"},pt:{close:"Fechar"}},P=S.section` padding: 18px 14px; border-bottom: 1px solid var(--light-600); display: flex; flex-direction: column; gap: 12px; align-items: start; &:last-child { border-bottom: none; } &.restrict-image-size img { max-width: 100%; } .markdown p { margin-top: 0; } .tool { display: flex; flex-direction: column; align-items: start; align-self: stretch; gap: 6px; background-color: ${w.color.light[400]}; border-radius: 5px; padding: 0 6px; &:not(:last-child) { border-bottom: 1px solid ${w.color.light[500]}; } hr { margin: 16px 0; } .header-code { background-color: ${w.color.light[300]}; } .tool-input { align-self: stretch; border: 1px solid ${w.color.light[600]}; margin-top: 8px; &, .highlighter { background: ${w.color.light[300]} !important; } } } p { line-height: 20px; } ul.steps { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 8px; > li { padding: 8px 12px; background-color: ${w.color.light[500]}; border-radius: 6px; } .step-description { color: ${w.color.light[700]}; } } ul.side-by-side-tools { margin: 14px 0 0 0; padding: 0; list-style: none; display: flex; gap: 10px; flex-wrap: wrap; } `,Xs=S.div` border-radius: 4px; background-color: ${w.color.light[500]}; color: ${w.color.light[700]}; display: flex; align-items: center; .time { padding: 6px 8px; border-right: 1px solid ${w.color.light[600]}; } .navigator { display: flex; gap: 4px; align-items: center; padding: 2px 8px; button { width: 12px; height: 12px; padding: 0; } small { line-height: 0.75rem; } } `,Qs=({message:e,stepId:t,toolIndex:n,onClose:r})=>{const i=oe(),s=ae(e),[a,o]=x.useState(0),l=x.useMemo(()=>s.steps?.findIndex(b=>b.id===t)??-1,[s,t]),d=s.steps?.[l],c=!se.isNil(n),h=d?.type==="step"?d.attempts[a]?.tools:void 0,f=c&&h?[h[n]].filter(Boolean):h,p=f?.map(b=>u.jsxs("div",{className:"tool",children:[!c&&u.jsx(fe,{name:b.name??"",duration:b.duration,image:b.image,description:b.description}),b.input&&u.jsxs(u.Fragment,{children:[u.jsx(R,{appearance:"square",colorPalette:"cyan",children:i.input}),u.jsx(pe,{language:"json",className:"tool-input",showLineNumbers:!1,showActionBar:!0,children:b.input})]}),b.output&&u.jsxs(u.Fragment,{children:[u.jsx(jt,{}),u.jsx(R,{appearance:"square",colorPalette:"cyan",children:i.response}),u.jsx(pe,{language:"json",className:"tool-input",showLineNumbers:!1,showActionBar:!0,children:b.output})]})]},b.id)),m=c?f?.[0]:void 0,g=c?u.jsxs(L,{flex:1,gap:"8px",children:[!!m?.name&&u.jsx(De,{size:"xxs",image:m?.image,name:m?.name}),u.jsx(v,{appearance:"h6",children:m?.name??i.finalAnswer})]}):u.jsxs(L,{flex:1,justifyContent:"space-between",children:[u.jsx(v,{appearance:"h6",children:F(i,d,l)}),u.jsxs(Xs,{children:[u.jsxs(v,{className:"time",appearance:"microtext1",children:[d?.status==="running"&&i.running,d?.status==="pending"&&i.pending,d?.status==="success"&&`${i.executionTime}: ${d?.duration?`${Nt(d?.duration)}s`:i.unknown}`]}),d?.type==="step"&&d.attempts.length>1&&u.jsxs("div",{className:"navigator",children:[a>0&&u.jsx(ee,{icon:"ChevronLeft",size:"xs",title:i.previousAttempt,"aria-label":i.previousAttempt,onClick:()=>o(a-1)}),u.jsxs(v,{appearance:"microtext1",children:[a+1,"/",d.attempts.length]}),ao(a+1)})]})]})]});return u.jsxs(Hs,{open:!!d,onClose:r,title:g,children:[d?.type==="answer"&&u.jsx(P,{className:"restrict-image-size",children:s.type==="md"?u.jsx(Ot,{children:s.content}):u.jsx(v,{children:s.content})}),d?.type==="planning"&&u.jsxs(P,{style:{alignItems:"stretch"},children:[u.jsx(R,{appearance:"square",colorPalette:"blue",style:{alignSelf:"start"},children:"Prompt"}),u.jsx(v,{children:d.goal}),u.jsx("ul",{className:"steps",children:s.steps?.filter(b=>b.type==="step").map((b,j)=>u.jsxs("li",{children:[u.jsx(L,{mb:2,children:u.jsxs(v,{children:[i.step," ",j+1,": ",u.jsx("span",{className:"step-description",children:b.input})]})}),!!b.attempts[0].tools?.length&&u.jsx("ul",{className:"side-by-side-tools",children:b.attempts[0].tools.map(O=>u.jsx("li",{children:u.jsx(fe,{name:O.name??"",image:O.image})},O.id))})]},j))})]}),d?.type==="step"&&d?.input&&u.jsxs(P,{children:[u.jsx(R,{appearance:"square",colorPalette:"blue",children:"Prompt"}),u.jsx(v,{children:d.input})]}),!!p?.length&&u.jsx(P,{children:p})]})},na=({chatId:e,messageId:t})=>{const[n,r]=x.useState(),[i,s]=x.useState(),a=Ct(),o=x.useMemo(()=>a.chatTabs.getAll().find(d=>d.id===e)?.getMessages().find(d=>d.id===t),[e,t]),l=(d,c)=>{r(d.id),s(c)};return o?u.jsxs(u.Fragment,{children:[u.jsx(zs,{message:o,onClick:l,direction:"TB"}),u.jsx(Qs,{message:o,stepId:n,toolIndex:i,onClose:()=>r(void 0)})]}):null};export{na as default};