UNPKG

@copyfactory/alpine-flow

Version:

Alpine Flow makes creating directed step based flowcharts and node based workflow UIs (DAG) in AlpineJS an easier task.

1 lines 110 kB
!function(e){"function"==typeof define&&define.amd?define(e):e()}((function(){"use strict";function e(e){let t=Alpine.reactive({id:null,data:{},position:{x:0,y:0},type:"",positionComputed:!1,selected:!1,selectable:!0,deletable:!0,allowBranching:!1,allowChildren:!0,width:0,height:0,...e,setComputedWidthHeight(e){let t=window.getComputedStyle(e);this.width=parseFloat(t.width),this.height=parseFloat(t.height)},toObject(){return{id:this.id,data:this.data,type:this.type,position:this.position,selected:this.selected,selectable:this.selectable,deletable:this.deletable,allowChildren:this.allowChildren,allowBranching:this.allowBranching,width:this.width,height:this.height}}});return t.id=t.id.toString(),t.positionComputed=!1,t}const t={default:{}},n=e=>{e.directive("node",((e,{value:n,expression:r,modifiers:o},{evaluate:i})=>{if(!r)return void console.warn('Node not registered due to missing config. Modify to `x-node="{type: myNodeName}"`');let a=i(r);!1 in a?console.warn('Node not registered due to missing name. Modify to `x-node="{type: myNodeName}"`'):(e.setAttribute("x-ignore",!0),e.removeAttribute("x-node"),o.length||o.push("default"),o.forEach((n=>{t.hasOwnProperty(n)||(t[n]={}),t[n][a.type]={ele:e,nodeConfig:a}})),e.remove())})).before("ignore"),e.magic("nodes",((e,{Alpine:n})=>t))},r=(e,t=0,n=1)=>Math.min(Math.max(e,t),n);function o(e){return e?e[0]:null}var i="\0",a="\0",s="";function u(e,t){e[t]?e[t]++:e[t]=1}function l(e,t){--e[t]||delete e[t]}function h(e,t,n,r){var o=""+t,a=""+n;if(!e&&o>a){var u=o;o=a,a=u}return o+s+a+s+(void 0===r?i:r)}function c(e,t){return h(e,t.v,t.w,t.name)}var d=class{_isDirected=!0;_isMultigraph=!1;_isCompound=!1;_label;_defaultNodeLabelFn=()=>{};_defaultEdgeLabelFn=()=>{};_nodes={};_in={};_preds={};_out={};_sucs={};_edgeObjs={};_edgeLabels={};_nodeCount=0;_edgeCount=0;_parent;_children;constructor(e){e&&(this._isDirected=!e.hasOwnProperty("directed")||e.directed,this._isMultigraph=!!e.hasOwnProperty("multigraph")&&e.multigraph,this._isCompound=!!e.hasOwnProperty("compound")&&e.compound),this._isCompound&&(this._parent={},this._children={},this._children[a]={})}isDirected(){return this._isDirected}isMultigraph(){return this._isMultigraph}isCompound(){return this._isCompound}setGraph(e){return this._label=e,this}graph(){return this._label}setDefaultNodeLabel(e){return this._defaultNodeLabelFn=e,"function"!=typeof e&&(this._defaultNodeLabelFn=()=>e),this}nodeCount(){return this._nodeCount}nodes(){return Object.keys(this._nodes)}sources(){var e=this;return this.nodes().filter((t=>0===Object.keys(e._in[t]).length))}sinks(){var e=this;return this.nodes().filter((t=>0===Object.keys(e._out[t]).length))}setNodes(e,t){var n=arguments,r=this;return e.forEach((function(e){n.length>1?r.setNode(e,t):r.setNode(e)})),this}setNode(e,t){return this._nodes.hasOwnProperty(e)?(arguments.length>1&&(this._nodes[e]=t),this):(this._nodes[e]=arguments.length>1?t:this._defaultNodeLabelFn(e),this._isCompound&&(this._parent[e]=a,this._children[e]={},this._children[a][e]=!0),this._in[e]={},this._preds[e]={},this._out[e]={},this._sucs[e]={},++this._nodeCount,this)}node(e){return this._nodes[e]}hasNode(e){return this._nodes.hasOwnProperty(e)}removeNode(e){var t=this;if(this._nodes.hasOwnProperty(e)){var n=e=>t.removeEdge(t._edgeObjs[e]);delete this._nodes[e],this._isCompound&&(this._removeFromParentsChildList(e),delete this._parent[e],this.children(e).forEach((function(e){t.setParent(e)})),delete this._children[e]),Object.keys(this._in[e]).forEach(n),delete this._in[e],delete this._preds[e],Object.keys(this._out[e]).forEach(n),delete this._out[e],delete this._sucs[e],--this._nodeCount}return this}setParent(e,t){if(!this._isCompound)throw new Error("Cannot set parent in a non-compound graph");if(void 0===t)t=a;else{for(var n=t+="";void 0!==n;n=this.parent(n))if(n===e)throw new Error("Setting "+t+" as parent of "+e+" would create a cycle");this.setNode(t)}return this.setNode(e),this._removeFromParentsChildList(e),this._parent[e]=t,this._children[t][e]=!0,this}_removeFromParentsChildList(e){delete this._children[this._parent[e]][e]}parent(e){if(this._isCompound){var t=this._parent[e];if(t!==a)return t}}children(e=a){if(this._isCompound){var t=this._children[e];if(t)return Object.keys(t)}else{if(e===a)return this.nodes();if(this.hasNode(e))return[]}}predecessors(e){var t=this._preds[e];if(t)return Object.keys(t)}successors(e){var t=this._sucs[e];if(t)return Object.keys(t)}neighbors(e){var t=this.predecessors(e);if(t){const r=new Set(t);for(var n of this.successors(e))r.add(n);return Array.from(r.values())}}isLeaf(e){return 0===(this.isDirected()?this.successors(e):this.neighbors(e)).length}filterNodes(e){var t=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});t.setGraph(this.graph());var n=this;Object.entries(this._nodes).forEach((function([n,r]){e(n)&&t.setNode(n,r)})),Object.values(this._edgeObjs).forEach((function(e){t.hasNode(e.v)&&t.hasNode(e.w)&&t.setEdge(e,n.edge(e))}));var r={};function o(e){var i=n.parent(e);return void 0===i||t.hasNode(i)?(r[e]=i,i):i in r?r[i]:o(i)}return this._isCompound&&t.nodes().forEach((e=>t.setParent(e,o(e)))),t}setDefaultEdgeLabel(e){return this._defaultEdgeLabelFn=e,"function"!=typeof e&&(this._defaultEdgeLabelFn=()=>e),this}edgeCount(){return this._edgeCount}edges(){return Object.values(this._edgeObjs)}setPath(e,t){var n=this,r=arguments;return e.reduce((function(e,o){return r.length>1?n.setEdge(e,o,t):n.setEdge(e,o),o})),this}setEdge(){var e,t,n,r,o=!1,i=arguments[0];"object"==typeof i&&null!==i&&"v"in i?(e=i.v,t=i.w,n=i.name,2===arguments.length&&(r=arguments[1],o=!0)):(e=i,t=arguments[1],n=arguments[3],arguments.length>2&&(r=arguments[2],o=!0)),e=""+e,t=""+t,void 0!==n&&(n=""+n);var a=h(this._isDirected,e,t,n);if(this._edgeLabels.hasOwnProperty(a))return o&&(this._edgeLabels[a]=r),this;if(void 0!==n&&!this._isMultigraph)throw new Error("Cannot set a named edge when isMultigraph = false");this.setNode(e),this.setNode(t),this._edgeLabels[a]=o?r:this._defaultEdgeLabelFn(e,t,n);var s=function(e,t,n,r){var o=""+t,i=""+n;if(!e&&o>i){var a=o;o=i,i=a}var s={v:o,w:i};r&&(s.name=r);return s}(this._isDirected,e,t,n);return e=s.v,t=s.w,Object.freeze(s),this._edgeObjs[a]=s,u(this._preds[t],e),u(this._sucs[e],t),this._in[t][a]=s,this._out[e][a]=s,this._edgeCount++,this}edge(e,t,n){var r=1===arguments.length?c(this._isDirected,arguments[0]):h(this._isDirected,e,t,n);return this._edgeLabels[r]}edgeAsObj(){const e=this.edge(...arguments);return"object"!=typeof e?{label:e}:e}hasEdge(e,t,n){var r=1===arguments.length?c(this._isDirected,arguments[0]):h(this._isDirected,e,t,n);return this._edgeLabels.hasOwnProperty(r)}removeEdge(e,t,n){var r=1===arguments.length?c(this._isDirected,arguments[0]):h(this._isDirected,e,t,n),o=this._edgeObjs[r];return o&&(e=o.v,t=o.w,delete this._edgeLabels[r],delete this._edgeObjs[r],l(this._preds[t],e),l(this._sucs[e],t),delete this._in[t][r],delete this._out[e][r],this._edgeCount--),this}inEdges(e,t){var n=this._in[e];if(n){var r=Object.values(n);return t?r.filter((e=>e.v===t)):r}}outEdges(e,t){var n=this._out[e];if(n){var r=Object.values(n);return t?r.filter((e=>e.w===t)):r}}nodeEdges(e,t){var n=this.inEdges(e,t);if(n)return n.concat(this.outEdges(e,t))}},f={Graph:d,version:"2.2.2"},p=d,g={write:function(e){var t={options:{directed:e.isDirected(),multigraph:e.isMultigraph(),compound:e.isCompound()},nodes:m(e),edges:v(e)};void 0!==e.graph()&&(t.value=structuredClone(e.graph()));return t},read:function(e){var t=new p(e.options).setGraph(e.value);return e.nodes.forEach((function(e){t.setNode(e.v,e.value),e.parent&&t.setParent(e.v,e.parent)})),e.edges.forEach((function(e){t.setEdge({v:e.v,w:e.w,name:e.name},e.value)})),t}};function m(e){return e.nodes().map((function(t){var n=e.node(t),r=e.parent(t),o={v:t};return void 0!==n&&(o.value=n),void 0!==r&&(o.parent=r),o}))}function v(e){return e.edges().map((function(t){var n=e.edge(t),r={v:t.v,w:t.w};return void 0!==t.name&&(r.name=t.name),void 0!==n&&(r.value=n),r}))}var y=function(e){var t,n={},r=[];function o(r){n.hasOwnProperty(r)||(n[r]=!0,t.push(r),e.successors(r).forEach(o),e.predecessors(r).forEach(o))}return e.nodes().forEach((function(e){t=[],o(e),t.length&&r.push(t)})),r};var w=class{_arr=[];_keyIndices={};size(){return this._arr.length}keys(){return this._arr.map((function(e){return e.key}))}has(e){return this._keyIndices.hasOwnProperty(e)}priority(e){var t=this._keyIndices[e];if(void 0!==t)return this._arr[t].priority}min(){if(0===this.size())throw new Error("Queue underflow");return this._arr[0].key}add(e,t){var n=this._keyIndices;if(e=String(e),!n.hasOwnProperty(e)){var r=this._arr,o=r.length;return n[e]=o,r.push({key:e,priority:t}),this._decrease(o),!0}return!1}removeMin(){this._swap(0,this._arr.length-1);var e=this._arr.pop();return delete this._keyIndices[e.key],this._heapify(0),e.key}decrease(e,t){var n=this._keyIndices[e];if(t>this._arr[n].priority)throw new Error("New priority is greater than current priority. Key: "+e+" Old: "+this._arr[n].priority+" New: "+t);this._arr[n].priority=t,this._decrease(n)}_heapify(e){var t=this._arr,n=2*e,r=n+1,o=e;n<t.length&&(o=t[n].priority<t[o].priority?n:o,r<t.length&&(o=t[r].priority<t[o].priority?r:o),o!==e&&(this._swap(e,o),this._heapify(o)))}_decrease(e){for(var t,n=this._arr,r=n[e].priority;0!==e&&!(n[t=e>>1].priority<r);)this._swap(e,t),e=t}_swap(e,t){var n=this._arr,r=this._keyIndices,o=n[e],i=n[t];n[e]=i,n[t]=o,r[i.key]=e,r[o.key]=t}},_=w,b=function(e,t,n,r){return function(e,t,n,r){var o,i,a={},s=new _,u=function(e){var t=e.v!==o?e.v:e.w,r=a[t],u=n(e),l=i.distance+u;if(u<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+e+" Weight: "+u);l<r.distance&&(r.distance=l,r.predecessor=o,s.decrease(t,l))};e.nodes().forEach((function(e){var n=e===t?0:Number.POSITIVE_INFINITY;a[e]={distance:n},s.add(e,n)}));for(;s.size()>0&&(o=s.removeMin(),(i=a[o]).distance!==Number.POSITIVE_INFINITY);)r(o).forEach(u);return a}(e,String(t),n||x,r||function(t){return e.outEdges(t)})},x=()=>1;var E=b,k=function(e,t,n){return e.nodes().reduce((function(r,o){return r[o]=E(e,o,t,n),r}),{})};var N=function(e){var t=0,n=[],r={},o=[];function i(a){var s=r[a]={onStack:!0,lowlink:t,index:t++};if(n.push(a),e.successors(a).forEach((function(e){r.hasOwnProperty(e)?r[e].onStack&&(s.lowlink=Math.min(s.lowlink,r[e].index)):(i(e),s.lowlink=Math.min(s.lowlink,r[e].lowlink))})),s.lowlink===s.index){var u,l=[];do{u=n.pop(),r[u].onStack=!1,l.push(u)}while(a!==u);o.push(l)}}return e.nodes().forEach((function(e){r.hasOwnProperty(e)||i(e)})),o};var O=N,P=function(e){return O(e).filter((function(t){return t.length>1||1===t.length&&e.hasEdge(t[0],t[0])}))};var M=function(e,t,n){return function(e,t,n){var r={},o=e.nodes();return o.forEach((function(e){r[e]={},r[e][e]={distance:0},o.forEach((function(t){e!==t&&(r[e][t]={distance:Number.POSITIVE_INFINITY})})),n(e).forEach((function(n){var o=n.v===e?n.w:n.v,i=t(n);r[e][o]={distance:i,predecessor:e}}))})),o.forEach((function(e){var t=r[e];o.forEach((function(n){var i=r[n];o.forEach((function(n){var r=i[e],o=t[n],a=i[n],s=r.distance+o.distance;s<a.distance&&(a.distance=s,a.predecessor=o.predecessor)}))}))})),r}(e,t||C,n||function(t){return e.outEdges(t)})},C=()=>1;function z(e){var t={},n={},r=[];if(e.sinks().forEach((function o(i){if(n.hasOwnProperty(i))throw new S;t.hasOwnProperty(i)||(n[i]=!0,t[i]=!0,e.predecessors(i).forEach(o),delete n[i],r.push(i))})),Object.keys(t).length!==e.nodeCount())throw new S;return r}class S extends Error{constructor(){super(...arguments)}}var I=z;z.CycleException=S;var T=I;var A=function(e,t,n){Array.isArray(t)||(t=[t]);var r=e.isDirected()?t=>e.successors(t):t=>e.neighbors(t),o="post"===n?L:$,i=[],a={};return t.forEach((t=>{if(!e.hasNode(t))throw new Error("Graph does not have node: "+t);o(t,r,a,i)})),i};function L(e,t,n,r){for(var o=[[e,!1]];o.length>0;){var i=o.pop();i[1]?r.push(i[0]):n.hasOwnProperty(i[0])||(n[i[0]]=!0,o.push([i[0],!0]),j(t(i[0]),(e=>o.push([e,!1]))))}}function $(e,t,n,r){for(var o=[e];o.length>0;){var i=o.pop();n.hasOwnProperty(i)||(n[i]=!0,r.push(i),j(t(i),(e=>o.push(e))))}}function j(e,t){for(var n=e.length;n--;)t(e[n],n,e);return e}var D=A;var R=A;var B=d,V=w,Y=function(e,t){var n,r=new B,o={},i=new V;function a(e){var r=e.v===n?e.w:e.v,a=i.priority(r);if(void 0!==a){var s=t(e);s<a&&(o[r]=n,i.decrease(r,s))}}if(0===e.nodeCount())return r;e.nodes().forEach((function(e){i.add(e,Number.POSITIVE_INFINITY),r.setNode(e)})),i.decrease(e.nodes()[0],0);var s=!1;for(;i.size()>0;){if(n=i.removeMin(),o.hasOwnProperty(n))r.setEdge(n,o[n]);else{if(s)throw new Error("Input graph is not connected: "+e);s=!0}e.nodeEdges(n).forEach(a)}return r};var Z={Graph:f.Graph,json:g,alg:{components:y,dijkstra:b,dijkstraAll:k,findCycles:P,floydWarshall:M,isAcyclic:function(e){try{T(e)}catch(e){if(e instanceof T.CycleException)return!1;throw e}return!0},postorder:function(e,t){return D(e,t,"post")},preorder:function(e,t){return R(e,t,"pre")},prim:Y,tarjan:N,topsort:I},version:f.version};function G(e){e._prev._next=e._next,e._next._prev=e._prev,delete e._next,delete e._prev}function X(e,t){if("_next"!==e&&"_prev"!==e)return t}let q=Z.Graph,F=class{constructor(){let e={};e._next=e._prev=e,this._sentinel=e}dequeue(){let e=this._sentinel,t=e._prev;if(t!==e)return G(t),t}enqueue(e){let t=this._sentinel;e._prev&&e._next&&G(e),e._next=t._next,t._next._prev=e,t._next=e,e._prev=t}toString(){let e=[],t=this._sentinel,n=t._prev;for(;n!==t;)e.push(JSON.stringify(n,X)),n=n._prev;return"["+e.join(", ")+"]"}};var H=function(e,t){if(e.nodeCount()<=1)return[];let n=function(e,t){let n=new q,r=0,o=0;e.nodes().forEach((e=>{n.setNode(e,{v:e,in:0,out:0})})),e.edges().forEach((e=>{let i=n.edge(e.v,e.w)||0,a=t(e),s=i+a;n.setEdge(e.v,e.w,s),o=Math.max(o,n.node(e.v).out+=a),r=Math.max(r,n.node(e.w).in+=a)}));let i=function(e){const t=[];for(let n=0;n<e;n++)t.push(n);return t}(o+r+3).map((()=>new F)),a=r+1;return n.nodes().forEach((e=>{K(i,a,n.node(e))})),{graph:n,buckets:i,zeroIdx:a}}(e,t||W);return function(e,t,n){let r,o=[],i=t[t.length-1],a=t[0];for(;e.nodeCount();){for(;r=a.dequeue();)Q(e,t,n,r);for(;r=i.dequeue();)Q(e,t,n,r);if(e.nodeCount())for(let i=t.length-2;i>0;--i)if(r=t[i].dequeue(),r){o=o.concat(Q(e,t,n,r,!0));break}}return o}(n.graph,n.buckets,n.zeroIdx).flatMap((t=>e.outEdges(t.v,t.w)))};let W=()=>1;function Q(e,t,n,r,o){let i=o?[]:void 0;return e.inEdges(r.v).forEach((r=>{let a=e.edge(r),s=e.node(r.v);o&&i.push({v:r.v,w:r.w}),s.out-=a,K(t,n,s)})),e.outEdges(r.v).forEach((r=>{let o=e.edge(r),i=r.w,a=e.node(i);a.in-=o,K(t,n,a)})),e.removeNode(r.v),i}function K(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)}let U=Z.Graph;var J={addBorderNode:function(e,t,n,r){let o={width:0,height:0};arguments.length>=4&&(o.rank=n,o.order=r);return ee(e,"border",o,t)},addDummyNode:ee,asNonCompoundGraph:function(e){let t=new U({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},buildLayerMatrix:function(e){let t=oe(te(e)+1).map((()=>[]));return e.nodes().forEach((n=>{let r=e.node(n),o=r.rank;void 0!==o&&(t[o][r.order]=n)})),t},intersectRect:function(e,t){let n,r,o=e.x,i=e.y,a=t.x-o,s=t.y-i,u=e.width/2,l=e.height/2;if(!a&&!s)throw new Error("Not possible to find intersection inside of the rectangle");Math.abs(s)*u>Math.abs(a)*l?(s<0&&(l=-l),n=l*a/s,r=l):(a<0&&(u=-u),n=u,r=u*s/a);return{x:o+n,y:i+r}},mapValues:function(e,t){let n=t;"string"==typeof t&&(n=e=>e[t]);return Object.entries(e).reduce(((e,[t,r])=>(e[t]=n(r,t),e)),{})},maxRank:te,normalizeRanks:function(e){let t=Math.min(...e.nodes().map((t=>{let n=e.node(t).rank;return void 0===n?Number.MAX_VALUE:n})));e.nodes().forEach((n=>{let r=e.node(n);r.hasOwnProperty("rank")&&(r.rank-=t)}))},notime:function(e,t){return t()},partition:function(e,t){let n={lhs:[],rhs:[]};return e.forEach((e=>{t(e)?n.lhs.push(e):n.rhs.push(e)})),n},pick:function(e,t){const n={};for(const r of t)void 0!==e[r]&&(n[r]=e[r]);return n},predecessorWeights:function(e){let t=e.nodes().map((t=>{let n={};return e.inEdges(t).forEach((t=>{n[t.v]=(n[t.v]||0)+e.edge(t).weight})),n}));return ie(e.nodes(),t)},range:oe,removeEmptyRanks:function(e){let t=Math.min(...e.nodes().map((t=>e.node(t).rank))),n=[];e.nodes().forEach((r=>{let o=e.node(r).rank-t;n[o]||(n[o]=[]),n[o].push(r)}));let r=0,o=e.graph().nodeRankFactor;Array.from(n).forEach(((t,n)=>{void 0===t&&n%o!=0?--r:void 0!==t&&r&&t.forEach((t=>e.node(t).rank+=r))}))},simplify:function(e){let t=(new U).setGraph(e.graph());return e.nodes().forEach((n=>t.setNode(n,e.node(n)))),e.edges().forEach((n=>{let r=t.edge(n.v,n.w)||{weight:0,minlen:1},o=e.edge(n);t.setEdge(n.v,n.w,{weight:r.weight+o.weight,minlen:Math.max(r.minlen,o.minlen)})})),t},successorWeights:function(e){let t=e.nodes().map((t=>{let n={};return e.outEdges(t).forEach((t=>{n[t.w]=(n[t.w]||0)+e.edge(t).weight})),n}));return ie(e.nodes(),t)},time:function(e,t){let n=Date.now();try{return t()}finally{console.log(e+" time: "+(Date.now()-n)+"ms")}},uniqueId:re,zipObject:ie};function ee(e,t,n,r){let o;do{o=re(r)}while(e.hasNode(o));return n.dummy=t,e.setNode(o,n),o}function te(e){return Math.max(...e.nodes().map((t=>{let n=e.node(t).rank;return void 0===n?Number.MIN_VALUE:n})))}let ne=0;function re(e){var t=++ne;return toString(e)+t}function oe(e,t,n=1){null==t&&(t=e,e=0);let r=e=>e<t;n<0&&(r=e=>t<e);const o=[];for(let t=e;r(t);t+=n)o.push(t);return o}function ie(e,t){return e.reduce(((e,n,r)=>(e[n]=t[r],e)),{})}let ae=H,se=J.uniqueId;var ue={run:function(e){("greedy"===e.graph().acyclicer?ae(e,function(e){return t=>e.edge(t).weight}(e)):function(e){let t=[],n={},r={};function o(i){r.hasOwnProperty(i)||(r[i]=!0,n[i]=!0,e.outEdges(i).forEach((e=>{n.hasOwnProperty(e.w)?t.push(e):o(e.w)})),delete n[i])}return e.nodes().forEach(o),t}(e)).forEach((t=>{let n=e.edge(t);e.removeEdge(t),n.forwardName=t.name,n.reversed=!0,e.setEdge(t.w,t.v,n,se("rev"))}))},undo:function(e){e.edges().forEach((t=>{let n=e.edge(t);if(n.reversed){e.removeEdge(t);let r=n.forwardName;delete n.reversed,delete n.forwardName,e.setEdge(t.w,t.v,n,r)}}))}};let le=J;var he={run:function(e){e.graph().dummyChains=[],e.edges().forEach((t=>function(e,t){let n,r,o,i=t.v,a=e.node(i).rank,s=t.w,u=e.node(s).rank,l=t.name,h=e.edge(t),c=h.labelRank;if(u===a+1)return;for(e.removeEdge(t),o=0,++a;a<u;++o,++a)h.points=[],r={width:0,height:0,edgeLabel:h,edgeObj:t,rank:a},n=le.addDummyNode(e,"edge",r,"_d"),a===c&&(r.width=h.width,r.height=h.height,r.dummy="edge-label",r.labelpos=h.labelpos),e.setEdge(i,n,{weight:h.weight},l),0===o&&e.graph().dummyChains.push(n),i=n;e.setEdge(i,s,{weight:h.weight},l)}(e,t)))},undo:function(e){e.graph().dummyChains.forEach((t=>{let n,r=e.node(t),o=r.edgeLabel;for(e.setEdge(r.edgeObj,o);r.dummy;)n=e.successors(t)[0],e.removeNode(t),o.points.push({x:r.x,y:r.y}),"edge-label"===r.dummy&&(o.x=r.x,o.y=r.y,o.width=r.width,o.height=r.height),t=n,r=e.node(t)}))}};var ce={longestPath:function(e){var t={};e.sources().forEach((function n(r){var o=e.node(r);if(t.hasOwnProperty(r))return o.rank;t[r]=!0;var i=Math.min(...e.outEdges(r).map((t=>null==t?Number.POSITIVE_INFINITY:n(t.w)-e.edge(t).minlen)));return i===Number.POSITIVE_INFINITY&&(i=0),o.rank=i}))},slack:function(e,t){return e.node(t.w).rank-e.node(t.v).rank-e.edge(t).minlen}};var de=Z.Graph,fe=ce.slack,pe=function(e){var t,n,r=new de({directed:!1}),o=e.nodes()[0],i=e.nodeCount();r.setNode(o,{});for(;ge(r,e)<i;)t=me(r,e),n=r.hasNode(t.v)?fe(e,t):-fe(e,t),ve(r,e,n);return r};function ge(e,t){return e.nodes().forEach((function n(r){t.nodeEdges(r).forEach((o=>{var i=o.v,a=r===i?o.w:i;e.hasNode(a)||fe(t,o)||(e.setNode(a,{}),e.setEdge(r,a,{}),n(a))}))})),e.nodeCount()}function me(e,t){return t.edges().reduce(((n,r)=>{let o=Number.POSITIVE_INFINITY;return e.hasNode(r.v)!==e.hasNode(r.w)&&(o=fe(t,r)),o<n[0]?[o,r]:n}),[Number.POSITIVE_INFINITY,null])[1]}function ve(e,t,n){e.nodes().forEach((e=>t.node(e).rank+=n))}var ye=pe,we=ce.slack,_e=ce.longestPath,be=Z.alg.preorder,xe=Z.alg.postorder,Ee=J.simplify,ke=Ne;function Ne(e){e=Ee(e),_e(e);var t,n=ye(e);for(Me(n),Oe(n,e);t=ze(n);)Ie(n,e,t,Se(n,e,t))}function Oe(e,t){var n=xe(e,e.nodes());(n=n.slice(0,n.length-1)).forEach((n=>function(e,t,n){var r=e.node(n),o=r.parent;e.edge(n,o).cutvalue=Pe(e,t,n)}(e,t,n)))}function Pe(e,t,n){var r=e.node(n).parent,o=!0,i=t.edge(n,r),a=0;return i||(o=!1,i=t.edge(r,n)),a=i.weight,t.nodeEdges(n).forEach((i=>{var s,u,l=i.v===n,h=l?i.w:i.v;if(h!==r){var c=l===o,d=t.edge(i).weight;if(a+=c?d:-d,s=n,u=h,e.hasEdge(s,u)){var f=e.edge(n,h).cutvalue;a+=c?-f:f}}})),a}function Me(e,t){arguments.length<2&&(t=e.nodes()[0]),Ce(e,{},1,t)}function Ce(e,t,n,r,o){var i=n,a=e.node(r);return t[r]=!0,e.neighbors(r).forEach((o=>{t.hasOwnProperty(o)||(n=Ce(e,t,n,o,r))})),a.low=i,a.lim=n++,o?a.parent=o:delete a.parent,n}function ze(e){return e.edges().find((t=>e.edge(t).cutvalue<0))}function Se(e,t,n){var r=n.v,o=n.w;t.hasEdge(r,o)||(r=n.w,o=n.v);var i=e.node(r),a=e.node(o),s=i,u=!1;i.lim>a.lim&&(s=a,u=!0);var l=t.edges().filter((t=>u===Te(e,e.node(t.v),s)&&u!==Te(e,e.node(t.w),s)));return l.reduce(((e,n)=>we(t,n)<we(t,e)?n:e))}function Ie(e,t,n,r){var o=n.v,i=n.w;e.removeEdge(o,i),e.setEdge(r.v,r.w,{}),Me(e),Oe(e,t),function(e,t){var n=e.nodes().find((e=>!t.node(e).parent)),r=be(e,n);(r=r.slice(1)).forEach((n=>{var r=e.node(n).parent,o=t.edge(n,r),i=!1;o||(o=t.edge(r,n),i=!0),t.node(n).rank=t.node(r).rank+(i?o.minlen:-o.minlen)}))}(e,t)}function Te(e,t,n){return n.low<=t.lim&&t.lim<=n.lim}Ne.initLowLimValues=Me,Ne.initCutValues=Oe,Ne.calcCutValue=Pe,Ne.leaveEdge=ze,Ne.enterEdge=Se,Ne.exchangeEdges=Ie;var Ae=ce.longestPath,Le=pe,$e=ke,je=function(e){switch(e.graph().ranker){case"network-simplex":default:Re(e);break;case"tight-tree":!function(e){Ae(e),Le(e)}(e);break;case"longest-path":De(e)}};var De=Ae;function Re(e){$e(e)}var Be=function(e){let t=function(e){let t={},n=0;function r(o){let i=n;e.children(o).forEach(r),t[o]={low:i,lim:n++}}return e.children().forEach(r),t}(e);e.graph().dummyChains.forEach((n=>{let r=e.node(n),o=r.edgeObj,i=function(e,t,n,r){let o,i,a=[],s=[],u=Math.min(t[n].low,t[r].low),l=Math.max(t[n].lim,t[r].lim);o=n;do{o=e.parent(o),a.push(o)}while(o&&(t[o].low>u||l>t[o].lim));i=o,o=r;for(;(o=e.parent(o))!==i;)s.push(o);return{path:a.concat(s.reverse()),lca:i}}(e,t,o.v,o.w),a=i.path,s=i.lca,u=0,l=a[u],h=!0;for(;n!==o.w;){if(r=e.node(n),h){for(;(l=a[u])!==s&&e.node(l).maxRank<r.rank;)u++;l===s&&(h=!1)}if(!h){for(;u<a.length-1&&e.node(l=a[u+1]).minRank<=r.rank;)u++;l=a[u]}e.setParent(n,l),n=e.successors(n)[0]}}))};let Ve=J;var Ye={run:function(e){let t=Ve.addDummyNode(e,"root",{},"_root"),n=function(e){var t={};function n(r,o){var i=e.children(r);i&&i.length&&i.forEach((e=>n(e,o+1))),t[r]=o}return e.children().forEach((e=>n(e,1))),t}(e),r=Math.max(...Object.values(n))-1,o=2*r+1;e.graph().nestingRoot=t,e.edges().forEach((t=>e.edge(t).minlen*=o));let i=function(e){return e.edges().reduce(((t,n)=>t+e.edge(n).weight),0)}(e)+1;e.children().forEach((a=>Ze(e,t,o,i,r,n,a))),e.graph().nodeRankFactor=o},cleanup:function(e){var t=e.graph();e.removeNode(t.nestingRoot),delete t.nestingRoot,e.edges().forEach((t=>{e.edge(t).nestingEdge&&e.removeEdge(t)}))}};function Ze(e,t,n,r,o,i,a){let s=e.children(a);if(!s.length)return void(a!==t&&e.setEdge(t,a,{weight:0,minlen:n}));let u=Ve.addBorderNode(e,"_bt"),l=Ve.addBorderNode(e,"_bb"),h=e.node(a);e.setParent(u,a),h.borderTop=u,e.setParent(l,a),h.borderBottom=l,s.forEach((s=>{Ze(e,t,n,r,o,i,s);let h=e.node(s),c=h.borderTop?h.borderTop:s,d=h.borderBottom?h.borderBottom:s,f=h.borderTop?r:2*r,p=c!==d?1:o-i[a]+1;e.setEdge(u,c,{weight:f,minlen:p,nestingEdge:!0}),e.setEdge(d,l,{weight:f,minlen:p,nestingEdge:!0})})),e.parent(a)||e.setEdge(t,u,{weight:0,minlen:o+i[a]})}let Ge=J;var Xe=function(e){e.children().forEach((function t(n){let r=e.children(n),o=e.node(n);if(r.length&&r.forEach(t),o.hasOwnProperty("minRank")){o.borderLeft=[],o.borderRight=[];for(let t=o.minRank,r=o.maxRank+1;t<r;++t)qe(e,"borderLeft","_bl",n,o,t),qe(e,"borderRight","_br",n,o,t)}}))};function qe(e,t,n,r,o,i){let a={width:0,height:0,rank:i,borderType:t},s=o[t][i-1],u=Ge.addDummyNode(e,"border",a,n);o[t][i]=u,e.setParent(u,r),s&&e.setEdge(s,u,{weight:1})}function Fe(e){e.nodes().forEach((t=>He(e.node(t)))),e.edges().forEach((t=>He(e.edge(t))))}function He(e){let t=e.width;e.width=e.height,e.height=t}function We(e){e.y=-e.y}function Qe(e){let t=e.x;e.x=e.y,e.y=t}let Ke=J;var Ue=function(e){let t={},n=e.nodes().filter((t=>!e.children(t).length)),r=Math.max(...n.map((t=>e.node(t).rank))),o=Ke.range(r+1).map((()=>[]));function i(n){if(t[n])return;t[n]=!0;let r=e.node(n);o[r.rank].push(n),e.successors(n).forEach(i)}return n.sort(((t,n)=>e.node(t).rank-e.node(n).rank)).forEach(i),o};let Je=J.zipObject;function et(e,t,n){let r=Je(n,n.map(((e,t)=>t))),o=t.flatMap((t=>e.outEdges(t).map((t=>({pos:r[t.w],weight:e.edge(t).weight}))).sort(((e,t)=>e.pos-t.pos)))),i=1;for(;i<n.length;)i<<=1;let a=2*i-1;i-=1;let s=new Array(a).fill(0),u=0;return o.forEach((e=>{let t=e.pos+i;s[t]+=e.weight;let n=0;for(;t>0;)t%2&&(n+=s[t+1]),t=t-1>>1,s[t]+=e.weight;u+=e.weight*n})),u}let tt=J;let nt=J;function rt(e,t,n){let r;for(;t.length&&(r=t[t.length-1]).i<=n;)t.pop(),e.push(r.vs),n++;return n}let ot=function(e,t=[]){return t.map((t=>{let n=e.inEdges(t);if(n.length){let r=n.reduce(((t,n)=>{let r=e.edge(n),o=e.node(n.v);return{sum:t.sum+r.weight*o.order,weight:t.weight+r.weight}}),{sum:0,weight:0});return{v:t,barycenter:r.sum/r.weight,weight:r.weight}}return{v:t}}))},it=function(e,t){let n={};return e.forEach(((e,t)=>{let r=n[e.v]={indegree:0,in:[],out:[],vs:[e.v],i:t};void 0!==e.barycenter&&(r.barycenter=e.barycenter,r.weight=e.weight)})),t.edges().forEach((e=>{let t=n[e.v],r=n[e.w];void 0!==t&&void 0!==r&&(r.indegree++,t.out.push(n[e.w]))})),function(e){let t=[];function n(e){return t=>{t.merged||(void 0===t.barycenter||void 0===e.barycenter||t.barycenter>=e.barycenter)&&function(e,t){let n=0,r=0;e.weight&&(n+=e.barycenter*e.weight,r+=e.weight);t.weight&&(n+=t.barycenter*t.weight,r+=t.weight);e.vs=t.vs.concat(e.vs),e.barycenter=n/r,e.weight=r,e.i=Math.min(t.i,e.i),t.merged=!0}(e,t)}}function r(t){return n=>{n.in.push(t),0==--n.indegree&&e.push(n)}}for(;e.length;){let o=e.pop();t.push(o),o.in.reverse().forEach(n(o)),o.out.forEach(r(o))}return t.filter((e=>!e.merged)).map((e=>tt.pick(e,["vs","i","barycenter","weight"])))}(Object.values(n).filter((e=>!e.indegree)))},at=function(e,t){let n=nt.partition(e,(e=>e.hasOwnProperty("barycenter"))),r=n.lhs,o=n.rhs.sort(((e,t)=>t.i-e.i)),i=[],a=0,s=0,u=0;r.sort((l=!!t,(e,t)=>e.barycenter<t.barycenter?-1:e.barycenter>t.barycenter?1:l?t.i-e.i:e.i-t.i)),u=rt(i,o,u),r.forEach((e=>{u+=e.vs.length,i.push(e.vs),a+=e.barycenter*e.weight,s+=e.weight,u=rt(i,o,u)}));var l;let h={vs:i.flat(!0)};s&&(h.barycenter=a/s,h.weight=s);return h};var st=function e(t,n,r,o){let i=t.children(n),a=t.node(n),s=a?a.borderLeft:void 0,u=a?a.borderRight:void 0,l={};s&&(i=i.filter((e=>e!==s&&e!==u)));let h=ot(t,i);h.forEach((n=>{if(t.children(n.v).length){let s=e(t,n.v,r,o);l[n.v]=s,s.hasOwnProperty("barycenter")&&(a=s,void 0!==(i=n).barycenter?(i.barycenter=(i.barycenter*i.weight+a.barycenter*a.weight)/(i.weight+a.weight),i.weight+=a.weight):(i.barycenter=a.barycenter,i.weight=a.weight))}var i,a}));let c=it(h,r);!function(e,t){e.forEach((e=>{e.vs=e.vs.flatMap((e=>t[e]?t[e].vs:e))}))}(c,l);let d=at(c,o);if(s&&(d.vs=[s,d.vs,u].flat(!0),t.predecessors(s).length)){let e=t.node(t.predecessors(s)[0]),n=t.node(t.predecessors(u)[0]);d.hasOwnProperty("barycenter")||(d.barycenter=0,d.weight=0),d.barycenter=(d.barycenter*d.weight+e.order+n.order)/(d.weight+2),d.weight+=2}return d};let ut=Z.Graph,lt=J;var ht=function(e,t,n){let r=function(e){var t;for(;e.hasNode(t=lt.uniqueId("_root")););return t}(e),o=new ut({compound:!0}).setGraph({root:r}).setDefaultNodeLabel((t=>e.node(t)));return e.nodes().forEach((i=>{let a=e.node(i),s=e.parent(i);(a.rank===t||a.minRank<=t&&t<=a.maxRank)&&(o.setNode(i),o.setParent(i,s||r),e[n](i).forEach((t=>{let n=t.v===i?t.w:t.v,r=o.edge(n,i),a=void 0!==r?r.weight:0;o.setEdge(n,i,{weight:e.edge(t).weight+a})})),a.hasOwnProperty("minRank")&&o.setNode(i,{borderLeft:a.borderLeft[t],borderRight:a.borderRight[t]}))})),o};let ct=Ue,dt=function(e,t){let n=0;for(let r=1;r<t.length;++r)n+=et(e,t[r-1],t[r]);return n},ft=st,pt=ht,gt=function(e,t,n){let r,o={};n.forEach((n=>{let i,a,s=e.parent(n);for(;s;){if(i=e.parent(s),i?(a=o[i],o[i]=s):(a=r,r=s),a&&a!==s)return void t.setEdge(a,s);s=i}}))},mt=Z.Graph,vt=J;var yt=function e(t,n){if(n&&"function"==typeof n.customOrder)return void n.customOrder(t,e);let r=vt.maxRank(t),o=wt(t,vt.range(1,r+1),"inEdges"),i=wt(t,vt.range(r-1,-1,-1),"outEdges"),a=ct(t);if(bt(t,a),n&&n.disableOptimalOrderHeuristic)return;let s,u=Number.POSITIVE_INFINITY;for(let e=0,n=0;n<4;++e,++n){_t(e%2?o:i,e%4>=2),a=vt.buildLayerMatrix(t);let r=dt(t,a);r<u&&(n=0,s=Object.assign({},a),u=r)}bt(t,s)};function wt(e,t,n){return t.map((function(t){return pt(e,t,n)}))}function _t(e,t){let n=new mt;e.forEach((function(e){let r=e.graph().root,o=ft(e,r,n,t);o.vs.forEach(((t,n)=>e.node(t).order=n)),gt(e,n,o.vs)}))}function bt(e,t){Object.values(t).forEach((t=>t.forEach(((t,n)=>e.node(t).order=n))))}let xt=Z.Graph,Et=J;var kt=function(e){let t,n=Et.buildLayerMatrix(e),r=Object.assign(Nt(e,n),Ot(e,n)),o={};["u","d"].forEach((i=>{t="u"===i?n:Object.values(n).reverse(),["l","r"].forEach((n=>{"r"===n&&(t=t.map((e=>Object.values(e).reverse())));let a=("u"===i?e.predecessors:e.successors).bind(e),s=Ct(e,t,r,a),u=zt(e,t,s.root,s.align,"r"===n);"r"===n&&(u=Et.mapValues(u,(e=>-e))),o[i+n]=u}))}));let i=St(e,o);return It(o,i),Tt(o,e.graph().align)};function Nt(e,t){let n={};return t.length&&t.reduce((function(t,r){let o=0,i=0,a=t.length,s=r[r.length-1];return r.forEach(((t,u)=>{let l=function(e,t){if(e.node(t).dummy)return e.predecessors(t).find((t=>e.node(t).dummy))}(e,t),h=l?e.node(l).order:a;(l||t===s)&&(r.slice(i,u+1).forEach((t=>{e.predecessors(t).forEach((r=>{let i=e.node(r),a=i.order;!(a<o||h<a)||i.dummy&&e.node(t).dummy||Pt(n,r,t)}))})),i=u+1,o=h)})),r})),n}function Ot(e,t){let n={};function r(t,r,o,i,a){let s;Et.range(r,o).forEach((r=>{s=t[r],e.node(s).dummy&&e.predecessors(s).forEach((t=>{let r=e.node(t);r.dummy&&(r.order<i||r.order>a)&&Pt(n,t,s)}))}))}return t.length&&t.reduce((function(t,n){let o,i=-1,a=0;return n.forEach(((s,u)=>{if("border"===e.node(s).dummy){let t=e.predecessors(s);t.length&&(o=e.node(t[0]).order,r(n,a,u,i,o),a=u,i=o)}r(n,a,n.length,o,t.length)})),n})),n}function Pt(e,t,n){if(t>n){let e=t;t=n,n=e}let r=e[t];r||(e[t]=r={}),r[n]=!0}function Mt(e,t,n){if(t>n){let e=t;t=n,n=e}return!!e[t]&&e[t].hasOwnProperty(n)}function Ct(e,t,n,r){let o={},i={},a={};return t.forEach((e=>{e.forEach(((e,t)=>{o[e]=e,i[e]=e,a[e]=t}))})),t.forEach((e=>{let t=-1;e.forEach((e=>{let s=r(e);if(s.length){s=s.sort(((e,t)=>a[e]-a[t]));let r=(s.length-1)/2;for(let u=Math.floor(r),l=Math.ceil(r);u<=l;++u){let r=s[u];i[e]===e&&t<a[r]&&!Mt(n,e,r)&&(i[r]=e,i[e]=o[e]=o[r],t=a[r])}}}))})),{root:o,align:i}}function zt(e,t,n,r,o){let i={},a=function(e,t,n,r){let o=new xt,i=e.graph(),a=function(e,t,n){return(r,o,i)=>{let a,s=r.node(o),u=r.node(i),l=0;if(l+=s.width/2,s.hasOwnProperty("labelpos"))switch(s.labelpos.toLowerCase()){case"l":a=-s.width/2;break;case"r":a=s.width/2}if(a&&(l+=n?a:-a),a=0,l+=(s.dummy?t:e)/2,l+=(u.dummy?t:e)/2,l+=u.width/2,u.hasOwnProperty("labelpos"))switch(u.labelpos.toLowerCase()){case"l":a=u.width/2;break;case"r":a=-u.width/2}return a&&(l+=n?a:-a),a=0,l}}(i.nodesep,i.edgesep,r);return t.forEach((t=>{let r;t.forEach((t=>{let i=n[t];if(o.setNode(i),r){var s=n[r],u=o.edge(s,i);o.setEdge(s,i,Math.max(a(e,t,r),u||0))}r=t}))})),o}(e,t,n,o),s=o?"borderLeft":"borderRight";function u(e,t){let n=a.nodes(),r=n.pop(),o={};for(;r;)o[r]?e(r):(o[r]=!0,n.push(r),n=n.concat(t(r))),r=n.pop()}return u((function(e){i[e]=a.inEdges(e).reduce(((e,t)=>Math.max(e,i[t.v]+a.edge(t))),0)}),a.predecessors.bind(a)),u((function(t){let n=a.outEdges(t).reduce(((e,t)=>Math.min(e,i[t.w]-a.edge(t))),Number.POSITIVE_INFINITY),r=e.node(t);n!==Number.POSITIVE_INFINITY&&r.borderType!==s&&(i[t]=Math.max(i[t],n))}),a.successors.bind(a)),Object.keys(r).forEach((e=>i[e]=i[n[e]])),i}function St(e,t){return Object.values(t).reduce(((t,n)=>{let r=Number.NEGATIVE_INFINITY,o=Number.POSITIVE_INFINITY;Object.entries(n).forEach((([t,n])=>{let i=function(e,t){return e.node(t).width}(e,t)/2;r=Math.max(n+i,r),o=Math.min(n-i,o)}));const i=r-o;return i<t[0]&&(t=[i,n]),t}),[Number.POSITIVE_INFINITY,null])[1]}function It(e,t){let n=Object.values(t),r=Math.min(...n),o=Math.max(...n);["u","d"].forEach((n=>{["l","r"].forEach((i=>{let a=n+i,s=e[a];if(s===t)return;let u=Object.values(s),l=r-Math.min(...u);"l"!==i&&(l=o-Math.max(...u)),l&&(e[a]=Et.mapValues(s,(e=>e+l)))}))}))}function Tt(e,t){return Et.mapValues(e.ul,((n,r)=>{if(t)return e[t.toLowerCase()][r];{let t=Object.values(e).map((e=>e[r])).sort(((e,t)=>e-t));return(t[1]+t[2])/2}}))}let At=J,Lt=kt;let $t=ue,jt=he,Dt=je,Rt=J.normalizeRanks,Bt=Be,Vt=J.removeEmptyRanks,Yt=Ye,Zt=Xe,Gt={adjust:function(e){let t=e.graph().rankdir.toLowerCase();"lr"!==t&&"rl"!==t||Fe(e)},undo:function(e){let t=e.graph().rankdir.toLowerCase();"bt"!==t&&"rl"!==t||function(e){e.nodes().forEach((t=>We(e.node(t)))),e.edges().forEach((t=>{let n=e.edge(t);n.points.forEach(We),n.hasOwnProperty("y")&&We(n)}))}(e);"lr"!==t&&"rl"!==t||(!function(e){e.nodes().forEach((t=>Qe(e.node(t)))),e.edges().forEach((t=>{let n=e.edge(t);n.points.forEach(Qe),n.hasOwnProperty("x")&&Qe(n)}))}(e),Fe(e))}},Xt=yt,qt=function(e){(function(e){let t=At.buildLayerMatrix(e),n=e.graph().ranksep,r=0;t.forEach((t=>{const o=t.reduce(((t,n)=>{const r=e.node(n).height;return t>r?t:r}),0);t.forEach((t=>e.node(t).y=r+o/2)),r+=o+n}))})(e=At.asNonCompoundGraph(e)),Object.entries(Lt(e)).forEach((([t,n])=>e.node(t).x=n))},Ft=J,Ht=Z.Graph;var Wt=function(e,t){let n=t&&t.debugTiming?Ft.time:Ft.notime;n("layout",(()=>{let t=n(" buildLayoutGraph",(()=>function(e){let t=new Ht({multigraph:!0,compound:!0}),n=an(e.graph());return t.setGraph(Object.assign({},Kt,on(n,Qt),Ft.pick(n,Ut))),e.nodes().forEach((n=>{const r=on(an(e.node(n)),Jt);Object.keys(en).forEach((e=>{void 0===r[e]&&(r[e]=en[e])})),t.setNode(n,r),t.setParent(n,e.parent(n))})),e.edges().forEach((n=>{let r=an(e.edge(n));t.setEdge(n,Object.assign({},nn,on(r,tn),Ft.pick(r,rn)))})),t}(e)));n(" runLayout",(()=>function(e,t){t(" makeSpaceForEdgeLabels",(()=>function(e){let t=e.graph();t.ranksep/=2,e.edges().forEach((n=>{let r=e.edge(n);r.minlen*=2,"c"!==r.labelpos.toLowerCase()&&("TB"===t.rankdir||"BT"===t.rankdir?r.width+=r.labeloffset:r.height+=r.labeloffset)}))}(e))),t(" removeSelfEdges",(()=>function(e){e.edges().forEach((t=>{if(t.v===t.w){var n=e.node(t.v);n.selfEdges||(n.selfEdges=[]),n.selfEdges.push({e:t,label:e.edge(t)}),e.removeEdge(t)}}))}(e))),t(" acyclic",(()=>$t.run(e))),t(" nestingGraph.run",(()=>Yt.run(e))),t(" rank",(()=>Dt(Ft.asNonCompoundGraph(e)))),t(" injectEdgeLabelProxies",(()=>function(e){e.edges().forEach((t=>{let n=e.edge(t);if(n.width&&n.height){let n=e.node(t.v),r={rank:(e.node(t.w).rank-n.rank)/2+n.rank,e:t};Ft.addDummyNode(e,"edge-proxy",r,"_ep")}}))}(e))),t(" removeEmptyRanks",(()=>Vt(e))),t(" nestingGraph.cleanup",(()=>Yt.cleanup(e))),t(" normalizeRanks",(()=>Rt(e))),t(" assignRankMinMax",(()=>function(e){let t=0;e.nodes().forEach((n=>{let r=e.node(n);r.borderTop&&(r.minRank=e.node(r.borderTop).rank,r.maxRank=e.node(r.borderBottom).rank,t=Math.max(t,r.maxRank))})),e.graph().maxRank=t}(e))),t(" removeEdgeLabelProxies",(()=>function(e){e.nodes().forEach((t=>{let n=e.node(t);"edge-proxy"===n.dummy&&(e.edge(n.e).labelRank=n.rank,e.removeNode(t))}))}(e))),t(" normalize.run",(()=>jt.run(e))),t(" parentDummyChains",(()=>Bt(e))),t(" addBorderSegments",(()=>Zt(e))),t(" order",(()=>Xt(e))),t(" insertSelfEdges",(()=>function(e){var t=Ft.buildLayerMatrix(e);t.forEach((t=>{var n=0;t.forEach(((t,r)=>{var o=e.node(t);o.order=r+n,(o.selfEdges||[]).forEach((t=>{Ft.addDummyNode(e,"selfedge",{width:t.label.width,height:t.label.height,rank:o.rank,order:r+ ++n,e:t.e,label:t.label},"_se")})),delete o.selfEdges}))}))}(e))),t(" adjustCoordinateSystem",(()=>Gt.adjust(e))),t(" position",(()=>qt(e))),t(" positionSelfEdges",(()=>function(e){e.nodes().forEach((t=>{var n=e.node(t);if("selfedge"===n.dummy){var r=e.node(n.e.v),o=r.x+r.width/2,i=r.y,a=n.x-o,s=r.height/2;e.setEdge(n.e,n.label),e.removeNode(t),n.label.points=[{x:o+2*a/3,y:i-s},{x:o+5*a/6,y:i-s},{x:o+a,y:i},{x:o+5*a/6,y:i+s},{x:o+2*a/3,y:i+s}],n.label.x=n.x,n.label.y=n.y}}))}(e))),t(" removeBorderNodes",(()=>function(e){e.nodes().forEach((t=>{if(e.children(t).length){let n=e.node(t),r=e.node(n.borderTop),o=e.node(n.borderBottom),i=e.node(n.borderLeft[n.borderLeft.length-1]),a=e.node(n.borderRight[n.borderRight.length-1]);n.width=Math.abs(a.x-i.x),n.height=Math.abs(o.y-r.y),n.x=i.x+n.width/2,n.y=r.y+n.height/2}})),e.nodes().forEach((t=>{"border"===e.node(t).dummy&&e.removeNode(t)}))}(e))),t(" normalize.undo",(()=>jt.undo(e))),t(" fixupEdgeLabelCoords",(()=>function(e){e.edges().forEach((t=>{let n=e.edge(t);if(n.hasOwnProperty("x"))switch("l"!==n.labelpos&&"r"!==n.labelpos||(n.width-=n.labeloffset),n.labelpos){case"l":n.x-=n.width/2+n.labeloffset;break;case"r":n.x+=n.width/2+n.labeloffset}}))}(e))),t(" undoCoordinateSystem",(()=>Gt.undo(e))),t(" translateGraph",(()=>function(e){let t=Number.POSITIVE_INFINITY,n=0,r=Number.POSITIVE_INFINITY,o=0,i=e.graph(),a=i.marginx||0,s=i.marginy||0;function u(e){let i=e.x,a=e.y,s=e.width,u=e.height;t=Math.min(t,i-s/2),n=Math.max(n,i+s/2),r=Math.min(r,a-u/2),o=Math.max(o,a+u/2)}e.nodes().forEach((t=>u(e.node(t)))),e.edges().forEach((t=>{let n=e.edge(t);n.hasOwnProperty("x")&&u(n)})),t-=a,r-=s,e.nodes().forEach((n=>{let o=e.node(n);o.x-=t,o.y-=r})),e.edges().forEach((n=>{let o=e.edge(n);o.points.forEach((e=>{e.x-=t,e.y-=r})),o.hasOwnProperty("x")&&(o.x-=t),o.hasOwnProperty("y")&&(o.y-=r)})),i.width=n-t+a,i.height=o-r+s}(e))),t(" assignNodeIntersects",(()=>function(e){e.edges().forEach((t=>{let n,r,o=e.edge(t),i=e.node(t.v),a=e.node(t.w);o.points?(n=o.points[0],r=o.points[o.points.length-1]):(o.points=[],n=a,r=i),o.points.unshift(Ft.intersectRect(i,n)),o.points.push(Ft.intersectRect(a,r))}))}(e))),t(" reversePoints",(()=>function(e){e.edges().forEach((t=>{let n=e.edge(t);n.reversed&&n.points.reverse()}))}(e))),t(" acyclic.undo",(()=>$t.undo(e)))}(t,n))),n(" updateInputGraph",(()=>function(e,t){e.nodes().forEach((n=>{let r=e.node(n),o=t.node(n);r&&(r.x=o.x,r.y=o.y,r.rank=o.rank,t.children(n).length&&(r.width=o.width,r.height=o.height))})),e.edges().forEach((n=>{let r=e.edge(n),o=t.edge(n);r.points=o.points,o.hasOwnProperty("x")&&(r.x=o.x,r.y=o.y)})),e.graph().width=t.graph().width,e.graph().height=t.graph().height}(e,t)))}))};let Qt=["nodesep","edgesep","ranksep","marginx","marginy"],Kt={ranksep:50,edgesep:20,nodesep:50,rankdir:"tb"},Ut=["acyclicer","ranker","rankdir","align"],Jt=["width","height"],en={width:0,height:0},tn=["minlen","weight","width","height","labeloffset"],nn={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},rn=["labelpos"];function on(e,t){return Ft.mapValues(Ft.pick(e,t),Number)}function an(e){var t={};return e&&Object.entries(e).forEach((([e,n])=>{"string"==typeof e&&(e=e.toLowerCase()),t[e]=n})),t}let sn=J,un=Z.Graph;var ln={graphlib:Z,layout:Wt,debug:{debugOrdering:function(e){let t=sn.buildLayerMatrix(e),n=new un({compound:!0,multigraph:!0}).setGraph({});return e.nodes().forEach((t=>{n.setNode(t,{label:t}),n.setParent(t,"layer"+e.node(t).rank)})),e.edges().forEach((e=>n.setEdge(e.v,e.w,{},e.name))),t.forEach(((e,t)=>{let r="layer"+t;n.setNode(r,{rank:"same"}),e.reduce(((e,t)=>(n.setEdge(e,t,{style:"invis"}),t)))})),n}},util:{time:J.time,notime:J.notime},version:"1.1.2"};let hn={Left:"left",Top:"top",Right:"right",Bottom:"bottom"};const cn={[hn.Left]:{x:-1,y:0},[hn.Right]:{x:1,y:0},[hn.Top]:{x:0,y:-1},[hn.Bottom]:{x:0,y:1}},dn=({source:e,sourcePosition:t=hn.Bottom,target:n})=>t===hn.Left||t===hn.Right?e.x<n.x?{x:1,y:0}:{x:-1,y:0}:e.y<n.y?{x:0,y:1}:{x:0,y:-1},fn=(e,t)=>Math.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2));function pn({source:e,sourcePosition:t=hn.Bottom,target:n,targetPosition:r=hn.Top,center:o,offset:i}){const a=cn[t],s=cn[r],u={x:e.x+a.x*i,y:e.y+a.y*i},l={x:n.x+s.x*i,y:n.y+s.y*i},h=dn({source:u,sourcePosition:t,target:l}),c=0!==h.x?"x":"y",d=h[c];let f,p,g=[];const m={x:0,y:0},v={x:0,y:0},[y,w,_,b]=function({sourceX:e,sourceY:t,targetX:n,targetY:r}){const o=Math.abs(n-e)/2,i=n<e?n+o:n-o,a=Math.abs(r-t)/2;return[i,r<t?r+a:r-a,o,a]}({sourceX:e.x,sourceY:e.y,targetX:n.x,targetY:n.y});if(a[c]*s[c]==-1){f=o.x??y,p=o.y??w;const e=[{x:f,y:u.y},{x:f,y:l.y}],t=[{x:u.x,y:p},{x:l.x,y:p}];g=a[c]===d?"x"===c?e:t:"x"===c?t:e}else{const o=[{x:u.x,y:l.y}],h=[{x:l.x,y:u.y}];if(g="x"===c?a.x===d?h:o:a.y===d?o:h,t===r){const t=Math.abs(e[c]-n[c]);if(t<=i){const r=Math.min(i-1,i-t);a[c]===d?m[c]=(u[c]>e[c]?-1:1)*r:v[c]=(l[c]>n[c]?-1:1)*r}}if(t!==r){const e="x"===c?"y":"x",t=a[c]===s[e],n=u[e]>l[e],r=u[e]<l[e];(1===a[c]&&(!t&&n||t&&r)||1!==a[c]&&(!t&&r||t&&n))&&(g="x"===c?o:h)}const y={x:u.x+m.x,y:u.y+m.y},w={x:l.x+v.x,y:l.y+v.y};Math.max(Math.abs(y.x-g[0].x),Math.abs(w.x-g[0].x))>=Math.max(Math.abs(y.y-g[0].y),Math.abs(w.y-g[0].y))?(f=(y.x+w.x)/2,p=g[0].y):(f=g[0].x,p=(y.y+w.y)/2)}return[[e,{x:u.x+m.x,y:u.y+m.y},...g,{x:l.x+v.x,y:l.y+v.y},n],f,p,_,b]}function gn({sourceX:e,sourceY:t,sourcePosition:n=hn.Bottom,targetX:r,targetY:o,targetPosition:i=hn.Top,borderRadius:a=5,centerX:s,centerY:u,offset:l=20}){const[h,c,d,f,p]=pn({source:{x:e,y:t},sourcePosition:n,target:{x:r,y:o},targetPosition:i,center:{x:s,y:u},offset:l});return[h.reduce(((e,t,n)=>{let r="";return r=n>0&&n<h.length-1?function(e,t,n,r){const o=Math.min(fn(e,t)/2,fn(t,n)/2,r),{x:i,y:a}=t;if(e.x===i&&i===n.x||e.y===a&&a===n.y)return`L${i} ${a}`;if(e.y===a)return`L ${i+o*(e.x<n.x?-1:1)},${a}Q ${i},${a} ${i},${a+o*(e.y<n.y?1:-1)}`;const s=e.x<n.x?1:-1;return`L ${i},${a+o*(e.y<n.y?-1:1)}Q ${i},${a} ${i+o*s},${a}`}(h[n-1],t,h[n+1],a):`${0===n?"M":"L"}${t.x} ${t.y}`,e+=r}),""),c,d,f,p]}function mn(e){let t=Alpine.reactive({id:null,type:"default",source:"",target:"",animated:!1,className:"",markerEnd:"arrow",markerStart:null,...e,toObject(){return{id:this.id,type:this.type,source:this.source,target:this.target,animated:this.animated,className:this.className}}});return t.id?t.id=t.id.toString():t.id=`${t.source}.${t.target}`,t}const vn='\n<div x-init="canvas = $el" x-ref="canvas" class="flow">\n <div @drop.prevent\n @dragover.prevent\n @wheel.prevent\n :class="{ \'dragging\': grabbing, \'grabbing\': !grabbing, [backgroundClasses]: true }" \n class="flow__background">\n <div class="flow__renderer">\n <template x-if="areNodesReady">\n <div x-init="_processQueue" :style="\'height:\' + height + \'px;width: \' + width + \'px;\'">\n <div x-init="_setupPanZoom" x-ref="viewportEle" class="flow__renderer">\n <div class="flow__viewport flow__canvas-container"\n :style="\'transform: translate(\' + canvasPosition.x + \'px, \' + canvasPosition.y + \'px) scale(\' + zoom + \');\'" \n >\n <div style="z-index: 0;" class="flow__canvas-container">\n <template x-for="(edge, index) in edgesWithPath" :key="edge.edge.id">\n <svg :width="width" :height="height"\n class="flow__canvas-container flow__edges">\n <g>\n <defs>\n <marker\n id="arrow"\n markerWidth="12.5"\n markerHeight="12.5"\n viewBox="-10 -10 20 20"\n markerUnits="strokeWidth"\n orient="auto-start-reverse"\n refX="0"\n refY="0">\n <polyline\n stroke-linecap="round"\n stroke-linejoin="round"\n fill="none"\n points="-5,-4 0,0 -5,4"\n style="stroke: rgb(177, 177, 183); stroke-width: 1;">\n </polyline>\n </marker>\n </defs>\n\n <path :d="edge.path" fill="none"\n :class="{ \'animated\': edge.edge.animated }"\n marker-end="url(#arrow)"\n class="flow__edge-path"></path>\n </g>\n </svg>\n </template>\n <div class="flow__nodes">\n <template x-for="(node, index) in nodes" :key="node.id">\n <div\n @wheel.passive.stop\n @mousedown.stop\n @mouseup.stop\n @mousemove.stop\n >\n <div x-data="{nodeHtml: \'\'}"\n @click.outside="node.selected = false;"\n @click="node.selected = true;"\n x-init="nodeHtml = getNodeHTMLToRender(node);"\n >\n <div x-ref="nodeContainer"\n x-html="nodeHtml"></div>\n </div>\n </div>\n </template>\n </div>\n </div>\n </div>\n </div>\n </div>\n </template>\n </div>\n\n <div\n @mousedown.stop\n @mouseup.stop\n @mousemove.stop\n :class="toolbarClasses ? toolbarClasses: \'\'"\n class="flow__panel flow__toolbar" x-init="toolbar = $el">\n \n <button \n :class="toolbarBtnClasses ? toolbarBtnClasses: \'\'"\n class="flow__toolbar__button"\n aria-label="Zoom in"\n @click.stop="zoomIn()" \n type="button" \n >\n <svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-plus"><path d="M5 12h14"/><path d="M12 5v14"/></svg>\n </button>\n <button\n :class="toolbarBtnClasses ? toolbarBtnClasses: \'\'"\n class="flow__toolbar__button" \n aria-label="Zoom out"\n @click.stop="zoomOut()" \n type="button"\n >\n <svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-minus"><path d="M5 12h14"/></svg>\n </button>\n <button\n :class="toolbarBtnClasses ? toolbarBtnClasses: \'\'"\n class="flow__toolbar__button"\n aria-label="Fit to view"\n @click.stop="setViewportToCenter()" \n type="button"\n >\n <svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-focus"><circle cx="12" cy="12" r="3"/><path d="M3 7V5a2 2 0 0 1 2-2h2"/><path d="M17 3h2a2 2 0 0 1 2 2v2"/><path d="M21 17v2a2 2 0 0 1-2 2h-2"/><path d="M7 21H5a2 2 0 0 1-2-2v-2"/></svg>\n </button>\n </div>\n </div>\n</div> \n';var yn={value:()=>{}};function wn(){for(var e,t=0,n=arguments.length,r={};t<n;++t){if(!(e=arguments[t]+"")||e in r||/[\s.]/.test(e))throw new Error("illegal type: "+e);r[e]=[]}return new _n(r)}function _n(e){this._=e}function bn(e,t){for(var n,r=0,o=e.length;r<o;++r)if((n=e[r]).name===t)return n.value}function xn(e,t,n){for(var r=0,o=e.length;r<o;++r)if(e[r].name===t){e[r]=yn,e=e.slice(0,r).concat(e.slice(r+1));break}return null!=n&&e.push({name:t,value:n}),e}_n.prototype=wn.prototype={constructor:_n,on:function(e,t){var n,