@ak-sara/sto-diagram 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).StoDiagram={})}(this,function(e){"use strict";var t=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),r=t((e,t)=>{var r=Object.defineProperty,n=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),i=(e,t,n)=>((e,t,n)=>t in e?r(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n)(e,"symbol"!=typeof t?t+"":t,n),o=n((e,t)=>{var r="\0";function n(e,t){e[t]?e[t]++:e[t]=1}function o(e,t){--e[t]||delete e[t]}function s(e,t,r,n){var i=""+t,o=""+r;if(!e&&i>o){var s=i;i=o,o=s}return i+""+o+""+(void 0===n?"\0":n)}function a(e,t){return s(e,t.v,t.w,t.name)}t.exports=class{constructor(e){i(this,"_isDirected",!0),i(this,"_isMultigraph",!1),i(this,"_isCompound",!1),i(this,"_label"),i(this,"_defaultNodeLabelFn",()=>{}),i(this,"_defaultEdgeLabelFn",()=>{}),i(this,"_nodes",{}),i(this,"_in",{}),i(this,"_preds",{}),i(this,"_out",{}),i(this,"_sucs",{}),i(this,"_edgeObjs",{}),i(this,"_edgeLabels",{}),i(this,"_nodeCount",0),i(this,"_edgeCount",0),i(this,"_parent"),i(this,"_children"),e&&(this._isDirected=!Object.hasOwn(e,"directed")||e.directed,this._isMultigraph=!!Object.hasOwn(e,"multigraph")&&e.multigraph,this._isCompound=!!Object.hasOwn(e,"compound")&&e.compound),this._isCompound&&(this._parent={},this._children={},this._children[r]={})}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 r=arguments,n=this;return e.forEach(function(e){r.length>1?n.setNode(e,t):n.setNode(e)}),this}setNode(e,t){return Object.hasOwn(this._nodes,e)?(arguments.length>1&&(this._nodes[e]=t),this):(this._nodes[e]=arguments.length>1?t:this._defaultNodeLabelFn(e),this._isCompound&&(this._parent[e]=r,this._children[e]={},this._children[r][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 Object.hasOwn(this._nodes,e)}removeNode(e){var t=this;if(Object.hasOwn(this._nodes,e)){var r=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(r),delete this._in[e],delete this._preds[e],Object.keys(this._out[e]).forEach(r),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=r;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!==r)return t}}children(e=r){if(this._isCompound){var t=this._children[e];if(t)return Object.keys(t)}else{if(e===r)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){let n=new Set(t);for(var r of this.successors(e))n.add(r);return Array.from(n.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 r=this;Object.entries(this._nodes).forEach(function([r,n]){e(r)&&t.setNode(r,n)}),Object.values(this._edgeObjs).forEach(function(e){t.hasNode(e.v)&&t.hasNode(e.w)&&t.setEdge(e,r.edge(e))});var n={};function i(e){var o=r.parent(e);return void 0===o||t.hasNode(o)?(n[e]=o,o):o in n?n[o]:i(o)}return this._isCompound&&t.nodes().forEach(e=>t.setParent(e,i(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 r=this,n=arguments;return e.reduce(function(e,i){return n.length>1?r.setEdge(e,i,t):r.setEdge(e,i),i}),this}setEdge(){var e,t,r,i,o=!1,a=arguments[0];"object"==typeof a&&null!==a&&"v"in a?(e=a.v,t=a.w,r=a.name,2===arguments.length&&(i=arguments[1],o=!0)):(e=a,t=arguments[1],r=arguments[3],arguments.length>2&&(i=arguments[2],o=!0)),e=""+e,t=""+t,void 0!==r&&(r=""+r);var h=s(this._isDirected,e,t,r);if(Object.hasOwn(this._edgeLabels,h))return o&&(this._edgeLabels[h]=i),this;if(void 0!==r&&!this._isMultigraph)throw new Error("Cannot set a named edge when isMultigraph = false");this.setNode(e),this.setNode(t),this._edgeLabels[h]=o?i:this._defaultEdgeLabelFn(e,t,r);var d=function(e,t,r,n){var i=""+t,o=""+r;if(!e&&i>o){var s=i;i=o,o=s}var a={v:i,w:o};return n&&(a.name=n),a}(this._isDirected,e,t,r);return e=d.v,t=d.w,Object.freeze(d),this._edgeObjs[h]=d,n(this._preds[t],e),n(this._sucs[e],t),this._in[t][h]=d,this._out[e][h]=d,this._edgeCount++,this}edge(e,t,r){var n=1===arguments.length?a(this._isDirected,arguments[0]):s(this._isDirected,e,t,r);return this._edgeLabels[n]}edgeAsObj(){let e=this.edge(...arguments);return"object"!=typeof e?{label:e}:e}hasEdge(e,t,r){var n=1===arguments.length?a(this._isDirected,arguments[0]):s(this._isDirected,e,t,r);return Object.hasOwn(this._edgeLabels,n)}removeEdge(e,t,r){var n=1===arguments.length?a(this._isDirected,arguments[0]):s(this._isDirected,e,t,r),i=this._edgeObjs[n];return i&&(e=i.v,t=i.w,delete this._edgeLabels[n],delete this._edgeObjs[n],o(this._preds[t],e),o(this._sucs[e],t),delete this._in[t][n],delete this._out[e][n],this._edgeCount--),this}inEdges(e,t){return this.isDirected()?this.filterEdges(this._in[e],e,t):this.nodeEdges(e,t)}outEdges(e,t){return this.isDirected()?this.filterEdges(this._out[e],e,t):this.nodeEdges(e,t)}nodeEdges(e,t){if(e in this._nodes)return this.filterEdges({...this._in[e],...this._out[e]},e,t)}filterEdges(e,t,r){if(e){var n=Object.values(e);return r?n.filter(function(e){return e.v===t&&e.w===r||e.v===r&&e.w===t}):n}}}}),s=n((e,t)=>{t.exports="3.0.2"}),a=n((e,t)=>{t.exports={Graph:o(),version:s()}}),h=n((e,t)=>{var r=o();function n(e){return e.nodes().map(function(t){var r=e.node(t),n=e.parent(t),i={v:t};return void 0!==r&&(i.value=r),void 0!==n&&(i.parent=n),i})}function i(e){return e.edges().map(function(t){var r=e.edge(t),n={v:t.v,w:t.w};return void 0!==t.name&&(n.name=t.name),void 0!==r&&(n.value=r),n})}t.exports={write:function(e){var t={options:{directed:e.isDirected(),multigraph:e.isMultigraph(),compound:e.isCompound()},nodes:n(e),edges:i(e)};return void 0!==e.graph()&&(t.value=structuredClone(e.graph())),t},read:function(e){var t=new r(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}}}),d=n((e,t)=>{t.exports=function(e,t,n,i){return function(e,t,r,n){var i={},o=!0,s=0,a=e.nodes(),h=function(e){var t=r(e);i[e.v].distance+t<i[e.w].distance&&(i[e.w]={distance:i[e.v].distance+t,predecessor:e.v},o=!0)},d=function(){a.forEach(function(e){n(e).forEach(function(t){var r=t.v===e?t.v:t.w,n=r===t.v?t.w:t.v;h({v:r,w:n})})})};a.forEach(function(e){var r=e===t?0:Number.POSITIVE_INFINITY;i[e]={distance:r}});for(var c=a.length,l=1;l<c&&(o=!1,s++,d(),o);l++);if(s===c-1&&(o=!1,d(),o))throw new Error("The graph contains a negative weight cycle");return i}(e,String(t),n||r,i||function(t){return e.outEdges(t)})};var r=()=>1}),c=n((e,t)=>{t.exports=function(e){var t,r={},n=[];function i(n){Object.hasOwn(r,n)||(r[n]=!0,t.push(n),e.successors(n).forEach(i),e.predecessors(n).forEach(i))}return e.nodes().forEach(function(e){t=[],i(e),t.length&&n.push(t)}),n}}),l=n((e,t)=>{t.exports=class{constructor(){i(this,"_arr",[]),i(this,"_keyIndices",{})}size(){return this._arr.length}keys(){return this._arr.map(function(e){return e.key})}has(e){return Object.hasOwn(this._keyIndices,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 r=this._keyIndices;if(e=String(e),!Object.hasOwn(r,e)){var n=this._arr,i=n.length;return r[e]=i,n.push({key:e,priority:t}),this._decrease(i),!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 r=this._keyIndices[e];if(t>this._arr[r].priority)throw new Error("New priority is greater than current priority. Key: "+e+" Old: "+this._arr[r].priority+" New: "+t);this._arr[r].priority=t,this._decrease(r)}_heapify(e){var t=this._arr,r=2*e,n=r+1,i=e;r<t.length&&(i=t[r].priority<t[i].priority?r:i,n<t.length&&(i=t[n].priority<t[i].priority?n:i),i!==e&&(this._swap(e,i),this._heapify(i)))}_decrease(e){for(var t,r=this._arr,n=r[e].priority;0!==e&&!(r[t=e>>1].priority<n);)this._swap(e,t),e=t}_swap(e,t){var r=this._arr,n=this._keyIndices,i=r[e],o=r[t];r[e]=o,r[t]=i,n[o.key]=e,n[i.key]=t}}}),u=n((e,t)=>{var r=l();t.exports=function(e,t,i,o){return function(e,t,n,i){var o,s,a={},h=new r,d=function(e){var t=e.v!==o?e.v:e.w,r=a[t],i=n(e),d=s.distance+i;if(i<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+e+" Weight: "+i);d<r.distance&&(r.distance=d,r.predecessor=o,h.decrease(t,d))};for(e.nodes().forEach(function(e){var r=e===t?0:Number.POSITIVE_INFINITY;a[e]={distance:r},h.add(e,r)});h.size()>0&&(o=h.removeMin(),(s=a[o]).distance!==Number.POSITIVE_INFINITY);)i(o).forEach(d);return a}(e,String(t),i||n,o||function(t){return e.outEdges(t)})};var n=()=>1}),f=n((e,t)=>{var r=u();t.exports=function(e,t,n){return e.nodes().reduce(function(i,o){return i[o]=r(e,o,t,n),i},{})}}),g=n((e,t)=>{function r(e,t,r){for(var n=[],i=r;i!==t;)n.push(i),i=e[i].predecessor;return n.push(t),n.reverse()}t.exports=function(e,t,n){if(void 0!==e[t].predecessor)throw new Error("Invalid source vertex");if(void 0===e[n].predecessor&&n!==t)throw new Error("Invalid destination vertex");return{weight:e[n].distance,path:r(e,t,n)}}}),p=n((e,t)=>{t.exports=function(e){var t=0,r=[],n={},i=[];function o(s){var a=n[s]={onStack:!0,lowlink:t,index:t++};if(r.push(s),e.successors(s).forEach(function(e){Object.hasOwn(n,e)?n[e].onStack&&(a.lowlink=Math.min(a.lowlink,n[e].index)):(o(e),a.lowlink=Math.min(a.lowlink,n[e].lowlink))}),a.lowlink===a.index){var h,d=[];do{h=r.pop(),n[h].onStack=!1,d.push(h)}while(s!==h);i.push(d)}}return e.nodes().forEach(function(e){Object.hasOwn(n,e)||o(e)}),i}}),m=n((e,t)=>{var r=p();t.exports=function(e){return r(e).filter(function(t){return t.length>1||1===t.length&&e.hasEdge(t[0],t[0])})}}),v=n((e,t)=>{t.exports=function(e,t,n){return function(e,t,r){var n={},i=e.nodes();return i.forEach(function(e){n[e]={},n[e][e]={distance:0},i.forEach(function(t){e!==t&&(n[e][t]={distance:Number.POSITIVE_INFINITY})}),r(e).forEach(function(r){var i=r.v===e?r.w:r.v,o=t(r);n[e][i]={distance:o,predecessor:e}})}),i.forEach(function(e){var t=n[e];i.forEach(function(r){var o=n[r];i.forEach(function(r){var n=o[e],i=t[r],s=o[r],a=n.distance+i.distance;a<s.distance&&(s.distance=a,s.predecessor=i.predecessor)})})}),n}(e,t||r,n||function(t){return e.outEdges(t)})};var r=()=>1}),w=n((e,t)=>{function r(e){var t={},r={},i=[];if(e.sinks().forEach(function o(s){if(Object.hasOwn(r,s))throw new n;Object.hasOwn(t,s)||(r[s]=!0,t[s]=!0,e.predecessors(s).forEach(o),delete r[s],i.push(s))}),Object.keys(t).length!==e.nodeCount())throw new n;return i}var n=class extends Error{constructor(){super(...arguments)}};t.exports=r,r.CycleException=n}),b=n((e,t)=>{var r=w();t.exports=function(e){try{r(e)}catch(e){if(e instanceof r.CycleException)return!1;throw e}return!0}}),y=n((e,t)=>{function r(e,t,n,i,o,s,a){return Object.hasOwn(i,t)||(i[t]=!0,n||(a=s(a,t)),o(t).forEach(function(t){a=r(e,t,n,i,o,s,a)}),n&&(a=s(a,t))),a}t.exports=function(e,t,n,i,o){Array.isArray(t)||(t=[t]);var s=(e.isDirected()?e.successors:e.neighbors).bind(e),a={};return t.forEach(function(t){if(!e.hasNode(t))throw new Error("Graph does not have node: "+t);o=r(e,t,"post"===n,a,s,i,o)}),o}}),E=n((e,t)=>{var r=y();t.exports=function(e,t,n){return r(e,t,n,function(e,t){return e.push(t),e},[])}}),x=n((e,t)=>{var r=E();t.exports=function(e,t){return r(e,t,"post")}}),_=n((e,t)=>{var r=E();t.exports=function(e,t){return r(e,t,"pre")}}),k=n((e,t)=>{var r=o(),n=l();t.exports=function(e,t){var i,o=new r,s={},a=new n;function h(e){var r=e.v===i?e.w:e.v,n=a.priority(r);if(void 0!==n){var o=t(e);o<n&&(s[r]=i,a.decrease(r,o))}}if(0===e.nodeCount())return o;e.nodes().forEach(function(e){a.add(e,Number.POSITIVE_INFINITY),o.setNode(e)}),a.decrease(e.nodes()[0],0);for(var d=!1;a.size()>0;){if(i=a.removeMin(),Object.hasOwn(s,i))o.setEdge(i,s[i]);else{if(d)throw new Error("Input graph is not connected: "+e);d=!0}e.nodeEdges(i).forEach(h)}return o}}),O=n((e,t)=>{var r=u(),n=d();t.exports=function(e,t,i,o){return function(e,t,i,o){if(void 0===i)return r(e,t,i,o);for(var s=!1,a=e.nodes(),h=0;h<a.length;h++){for(var d=o(a[h]),c=0;c<d.length;c++){var l=d[c],u=l.v===a[h]?l.v:l.w;i({v:u,w:u===l.v?l.w:l.v})<0&&(s=!0)}if(s)return n(e,t,i,o)}return r(e,t,i,o)}(e,t,i,o||function(t){return e.outEdges(t)})}}),N=n((e,t)=>{t.exports={bellmanFord:d(),components:c(),dijkstra:u(),dijkstraAll:f(),extractPath:g(),findCycles:m(),floydWarshall:v(),isAcyclic:b(),postorder:x(),preorder:_(),prim:k(),shortestPaths:O(),reduce:y(),tarjan:p(),topsort:w()}}),I=a();t.exports={Graph:I.Graph,json:h(),alg:N(),version:I.version}}),n=t((e,t)=>{function r(e){e._prev._next=e._next,e._next._prev=e._prev,delete e._next,delete e._prev}function n(e,t){if("_next"!==e&&"_prev"!==e)return t}t.exports=class{constructor(){let e={};e._next=e._prev=e,this._sentinel=e}dequeue(){let e=this._sentinel,t=e._prev;if(t!==e)return r(t),t}enqueue(e){let t=this._sentinel;e._prev&&e._next&&r(e),e._next=t._next,t._next._prev=e,t._next=e,e._prev=t}toString(){let e=[],t=this._sentinel,r=t._prev;for(;r!==t;)e.push(JSON.stringify(r,n)),r=r._prev;return"["+e.join(", ")+"]"}}}),i=t((e,t)=>{var i=r().Graph,o=n();t.exports=function(e,t){if(e.nodeCount()<=1)return[];let r=function(e,t){let r=new i,n=0,s=0;e.nodes().forEach(e=>{r.setNode(e,{v:e,in:0,out:0})}),e.edges().forEach(e=>{let i=r.edge(e.v,e.w)||0,o=t(e),a=i+o;r.setEdge(e.v,e.w,a),s=Math.max(s,r.node(e.v).out+=o),n=Math.max(n,r.node(e.w).in+=o)});let a=function(e){let t=[];for(let r=0;r<e;r++)t.push(r);return t}(s+n+3).map(()=>new o),d=n+1;return r.nodes().forEach(e=>{h(a,d,r.node(e))}),{graph:r,buckets:a,zeroIdx:d}}(e,t||s);return function(e,t,r){let n,i=[],o=t[t.length-1],s=t[0];for(;e.nodeCount();){for(;n=s.dequeue();)a(e,t,r,n);for(;n=o.dequeue();)a(e,t,r,n);if(e.nodeCount())for(let o=t.length-2;o>0;--o)if(n=t[o].dequeue(),n){i=i.concat(a(e,t,r,n,!0));break}}return i}(r.graph,r.buckets,r.zeroIdx).flatMap(t=>e.outEdges(t.v,t.w))};var s=()=>1;function a(e,t,r,n,i){let o=i?[]:void 0;return e.inEdges(n.v).forEach(n=>{let s=e.edge(n),a=e.node(n.v);i&&o.push({v:n.v,w:n.w}),a.out-=s,h(t,r,a)}),e.outEdges(n.v).forEach(n=>{let i=e.edge(n),o=n.w,s=e.node(o);s.in-=i,h(t,r,s)}),e.removeNode(n.v),o}function h(e,t,r){r.out?r.in?e[r.out-r.in+t].enqueue(r):e[e.length-1].enqueue(r):e[0].enqueue(r)}}),o=t((e,t)=>{var n=r().Graph;function i(e,t,r,n){for(var i=n;e.hasNode(i);)i=d(n);return r.dummy=t,e.setNode(i,r),i}t.exports={addBorderNode:function(e,t,r,n){let o={width:0,height:0};return arguments.length>=4&&(o.rank=r,o.order=n),i(e,"border",o,t)},addDummyNode:i,applyWithChunking:s,asNonCompoundGraph:function(e){let t=new n({multigraph:e.isMultigraph()}).setGraph(e.graph());return e.nodes().forEach(r=>{e.children(r).length||t.setNode(r,e.node(r))}),e.edges().forEach(r=>{t.setEdge(r,e.edge(r))}),t},buildLayerMatrix:function(e){let t=c(a(e)+1).map(()=>[]);return e.nodes().forEach(r=>{let n=e.node(r),i=n.rank;void 0!==i&&(t[i][n.order]=r)}),t},intersectRect:function(e,t){let r,n,i=e.x,o=e.y,s=t.x-i,a=t.y-o,h=e.width/2,d=e.height/2;if(!s&&!a)throw new Error("Not possible to find intersection inside of the rectangle");return Math.abs(a)*h>Math.abs(s)*d?(a<0&&(d=-d),r=d*s/a,n=d):(s<0&&(h=-h),r=h,n=h*a/s),{x:i+r,y:o+n}},mapValues:function(e,t){let r=t;return"string"==typeof t&&(r=e=>e[t]),Object.entries(e).reduce((e,[t,n])=>(e[t]=r(n,t),e),{})},maxRank:a,normalizeRanks:function(e){let t=e.nodes().map(t=>{let r=e.node(t).rank;return void 0===r?Number.MAX_VALUE:r}),r=s(Math.min,t);e.nodes().forEach(t=>{let n=e.node(t);Object.hasOwn(n,"rank")&&(n.rank-=r)})},notime:function(e,t){return t()},partition:function(e,t){let r={lhs:[],rhs:[]};return e.forEach(e=>{t(e)?r.lhs.push(e):r.rhs.push(e)}),r},pick:function(e,t){let r={};for(let n of t)void 0!==e[n]&&(r[n]=e[n]);return r},predecessorWeights:function(e){let t=e.nodes().map(t=>{let r={};return e.inEdges(t).forEach(t=>{r[t.v]=(r[t.v]||0)+e.edge(t).weight}),r});return l(e.nodes(),t)},range:c,removeEmptyRanks:function(e){let t=e.nodes().map(t=>e.node(t).rank).filter(e=>void 0!==e),r=s(Math.min,t),n=[];e.nodes().forEach(t=>{let i=e.node(t).rank-r;n[i]||(n[i]=[]),n[i].push(t)});let i=0,o=e.graph().nodeRankFactor;Array.from(n).forEach((t,r)=>{void 0===t&&r%o!==0?--i:void 0!==t&&i&&t.forEach(t=>e.node(t).rank+=i)})},simplify:function(e){let t=(new n).setGraph(e.graph());return e.nodes().forEach(r=>t.setNode(r,e.node(r))),e.edges().forEach(r=>{let n=t.edge(r.v,r.w)||{weight:0,minlen:1},i=e.edge(r);t.setEdge(r.v,r.w,{weight:n.weight+i.weight,minlen:Math.max(n.minlen,i.minlen)})}),t},successorWeights:function(e){let t=e.nodes().map(t=>{let r={};return e.outEdges(t).forEach(t=>{r[t.w]=(r[t.w]||0)+e.edge(t).weight}),r});return l(e.nodes(),t)},time:function(e,t){let r=Date.now();try{return t()}finally{console.log(e+" time: "+(Date.now()-r)+"ms")}},uniqueId:d,zipObject:l};var o=65535;function s(e,t){if(t.length>o){let r=function(e,t=o){let r=[];for(let n=0;n<e.length;n+=t){let i=e.slice(n,n+t);r.push(i)}return r}(t);return e.apply(null,r.map(t=>e.apply(null,t)))}return e.apply(null,t)}function a(e){let t=e.nodes().map(t=>{let r=e.node(t).rank;return void 0===r?Number.MIN_VALUE:r});return s(Math.max,t)}var h=0;function d(e){return e+""+ ++h}function c(e,t,r=1){null==t&&(t=e,e=0);let n=e=>e<t;r<0&&(n=e=>t<e);let i=[];for(let t=e;n(t);t+=r)i.push(t);return i}function l(e,t){return e.reduce((e,r,n)=>(e[r]=t[n],e),{})}}),s=t((e,t)=>{var r=i(),n=o().uniqueId;t.exports={run:function(e){("greedy"===e.graph().acyclicer?r(e,(t=e,e=>t.edge(e).weight)):function(e){let t=[],r={},n={};function i(o){Object.hasOwn(n,o)||(n[o]=!0,r[o]=!0,e.outEdges(o).forEach(e=>{Object.hasOwn(r,e.w)?t.push(e):i(e.w)}),delete r[o])}return e.nodes().forEach(i),t}(e)).forEach(t=>{let r=e.edge(t);e.removeEdge(t),r.forwardName=t.name,r.reversed=!0,e.setEdge(t.w,t.v,r,n("rev"))});var t},undo:function(e){e.edges().forEach(t=>{let r=e.edge(t);if(r.reversed){e.removeEdge(t);let n=r.forwardName;delete r.reversed,delete r.forwardName,e.setEdge(t.w,t.v,r,n)}})}}}),a=t((e,t)=>{var r=o();t.exports={run:function(e){e.graph().dummyChains=[],e.edges().forEach(t=>function(e,t){let n,i,o,s=t.v,a=e.node(s).rank,h=t.w,d=e.node(h).rank,c=t.name,l=e.edge(t),u=l.labelRank;if(d===a+1)return;for(e.removeEdge(t),o=0,++a;a<d;++o,++a)l.points=[],i={width:0,height:0,edgeLabel:l,edgeObj:t,rank:a},n=r.addDummyNode(e,"edge",i,"_d"),a===u&&(i.width=l.width,i.height=l.height,i.dummy="edge-label",i.labelpos=l.labelpos),e.setEdge(s,n,{weight:l.weight},c),0===o&&e.graph().dummyChains.push(n),s=n;e.setEdge(s,h,{weight:l.weight},c)}(e,t))},undo:function(e){e.graph().dummyChains.forEach(t=>{let r,n=e.node(t),i=n.edgeLabel;for(e.setEdge(n.edgeObj,i);n.dummy;)r=e.successors(t)[0],e.removeNode(t),i.points.push({x:n.x,y:n.y}),"edge-label"===n.dummy&&(i.x=n.x,i.y=n.y,i.width=n.width,i.height=n.height),t=r,n=e.node(t)})}}}),h=t((e,t)=>{var{applyWithChunking:r}=o();t.exports={longestPath:function(e){var t={};e.sources().forEach(function n(i){var o=e.node(i);if(Object.hasOwn(t,i))return o.rank;t[i]=!0;let s=e.outEdges(i).map(t=>null==t?Number.POSITIVE_INFINITY:n(t.w)-e.edge(t).minlen);var a=r(Math.min,s);return a===Number.POSITIVE_INFINITY&&(a=0),o.rank=a})},slack:function(e,t){return e.node(t.w).rank-e.node(t.v).rank-e.edge(t).minlen}}}),d=t((e,t)=>{var n=r().Graph,i=h().slack;function o(e,t){return e.nodes().forEach(function r(n){t.nodeEdges(n).forEach(o=>{var s=o.v,a=n===s?o.w:s;!e.hasNode(a)&&!i(t,o)&&(e.setNode(a,{}),e.setEdge(n,a,{}),r(a))})}),e.nodeCount()}function s(e,t){return t.edges().reduce((r,n)=>{let o=Number.POSITIVE_INFINITY;return e.hasNode(n.v)!==e.hasNode(n.w)&&(o=i(t,n)),o<r[0]?[o,n]:r},[Number.POSITIVE_INFINITY,null])[1]}function a(e,t,r){e.nodes().forEach(e=>t.node(e).rank+=r)}t.exports=function(e){var t,r,h=new n({directed:!1}),d=e.nodes()[0],c=e.nodeCount();for(h.setNode(d,{});o(h,e)<c;)t=s(h,e),r=h.hasNode(t.v)?i(e,t):-i(e,t),a(h,e,r);return h}}),c=t((e,t)=>{var n=d(),i=h().slack,s=h().longestPath,a=r().alg.preorder,c=r().alg.postorder,l=o().simplify;function u(e){e=l(e),s(e);var t,r=n(e);for(p(r),f(r,e);t=v(r);)b(r,e,t,w(r,e,t))}function f(e,t){var r=c(e,e.nodes());(r=r.slice(0,r.length-1)).forEach(r=>function(e,t,r){var n=e.node(r),i=n.parent;e.edge(r,i).cutvalue=g(e,t,r)}(e,t,r))}function g(e,t,r){var n=e.node(r).parent,i=!0,o=t.edge(r,n),s=0;return o||(i=!1,o=t.edge(n,r)),s=o.weight,t.nodeEdges(r).forEach(o=>{var a=o.v===r,h=a?o.w:o.v;if(h!==n){var d=a===i,c=t.edge(o).weight;if(s+=d?c:-c,function(e,t,r){return e.hasEdge(t,r)}(e,r,h)){var l=e.edge(r,h).cutvalue;s+=d?-l:l}}}),s}function p(e,t){arguments.length<2&&(t=e.nodes()[0]),m(e,{},1,t)}function m(e,t,r,n,i){var o=r,s=e.node(n);return t[n]=!0,e.neighbors(n).forEach(i=>{Object.hasOwn(t,i)||(r=m(e,t,r,i,n))}),s.low=o,s.lim=r++,i?s.parent=i:delete s.parent,r}function v(e){return e.edges().find(t=>e.edge(t).cutvalue<0)}function w(e,t,r){var n=r.v,o=r.w;t.hasEdge(n,o)||(n=r.w,o=r.v);var s=e.node(n),a=e.node(o),h=s,d=!1;return s.lim>a.lim&&(h=a,d=!0),t.edges().filter(t=>d===y(e,e.node(t.v),h)&&d!==y(e,e.node(t.w),h)).reduce((e,r)=>i(t,r)<i(t,e)?r:e)}function b(e,t,r,n){var i=r.v,o=r.w;e.removeEdge(i,o),e.setEdge(n.v,n.w,{}),p(e),f(e,t),function(e,t){var r=e.nodes().find(e=>!t.node(e).parent),n=a(e,r);n=n.slice(1),n.forEach(r=>{var n=e.node(r).parent,i=t.edge(r,n),o=!1;i||(i=t.edge(n,r),o=!0),t.node(r).rank=t.node(n).rank+(o?i.minlen:-i.minlen)})}(e,t)}function y(e,t,r){return r.low<=t.lim&&t.lim<=r.lim}t.exports=u,u.initLowLimValues=p,u.initCutValues=f,u.calcCutValue=g,u.leaveEdge=v,u.enterEdge=w,u.exchangeEdges=b}),l=t((e,t)=>{var r=h().longestPath,n=d(),i=c();t.exports=function(e){var t=e.graph().ranker;if(t instanceof Function)return t(e);switch(e.graph().ranker){case"network-simplex":default:s(e);break;case"tight-tree":!function(e){r(e),n(e)}(e);break;case"longest-path":o(e);case"none":}};var o=r;function s(e){i(e)}}),u=t((e,t)=>{t.exports=function(e){let t=function(e){let t={},r=0;function n(i){let o=r;e.children(i).forEach(n),t[i]={low:o,lim:r++}}return e.children().forEach(n),t}(e);e.graph().dummyChains.forEach(r=>{let n=e.node(r),i=n.edgeObj,o=function(e,t,r,n){let i,o,s=[],a=[],h=Math.min(t[r].low,t[n].low),d=Math.max(t[r].lim,t[n].lim);i=r;do{i=e.parent(i),s.push(i)}while(i&&(t[i].low>h||d>t[i].lim));for(o=i,i=n;(i=e.parent(i))!==o;)a.push(i);return{path:s.concat(a.reverse()),lca:o}}(e,t,i.v,i.w),s=o.path,a=o.lca,h=0,d=s[h],c=!0;for(;r!==i.w;){if(n=e.node(r),c){for(;(d=s[h])!==a&&e.node(d).maxRank<n.rank;)h++;d===a&&(c=!1)}if(!c){for(;h<s.length-1&&e.node(d=s[h+1]).minRank<=n.rank;)h++;d=s[h]}e.setParent(r,d),r=e.successors(r)[0]}})}}),f=t((e,t)=>{var r=o();function n(e,t,i,o,s,a,h){let d=e.children(h);if(!d.length)return void(h!==t&&e.setEdge(t,h,{weight:0,minlen:i}));let c=r.addBorderNode(e,"_bt"),l=r.addBorderNode(e,"_bb"),u=e.node(h);e.setParent(c,h),u.borderTop=c,e.setParent(l,h),u.borderBottom=l,d.forEach(r=>{n(e,t,i,o,s,a,r);let d=e.node(r),u=d.borderTop?d.borderTop:r,f=d.borderBottom?d.borderBottom:r,g=d.borderTop?o:2*o,p=u!==f?1:s-a[h]+1;e.setEdge(c,u,{weight:g,minlen:p,nestingEdge:!0}),e.setEdge(f,l,{weight:g,minlen:p,nestingEdge:!0})}),e.parent(h)||e.setEdge(t,c,{weight:0,minlen:s+a[h]})}t.exports={run:function(e){let t=r.addDummyNode(e,"root",{},"_root"),i=function(e){var t={};function r(n,i){var o=e.children(n);o&&o.length&&o.forEach(e=>r(e,i+1)),t[n]=i}return e.children().forEach(e=>r(e,1)),t}(e),o=Object.values(i),s=r.applyWithChunking(Math.max,o)-1,a=2*s+1;e.graph().nestingRoot=t,e.edges().forEach(t=>e.edge(t).minlen*=a);let h=function(e){return e.edges().reduce((t,r)=>t+e.edge(r).weight,0)}(e)+1;e.children().forEach(r=>n(e,t,a,h,s,i,r)),e.graph().nodeRankFactor=a},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)})}}}),g=t((e,t)=>{var r=o();function n(e,t,n,i,o,s){let a={width:0,height:0,rank:s,borderType:t},h=o[t][s-1],d=r.addDummyNode(e,"border",a,n);o[t][s]=d,e.setParent(d,i),h&&e.setEdge(h,d,{weight:1})}t.exports=function(e){e.children().forEach(function t(r){let i=e.children(r),o=e.node(r);if(i.length&&i.forEach(t),Object.hasOwn(o,"minRank")){o.borderLeft=[],o.borderRight=[];for(let t=o.minRank,i=o.maxRank+1;t<i;++t)n(e,"borderLeft","_bl",r,o,t),n(e,"borderRight","_br",r,o,t)}})}}),p=t((e,t)=>{function r(e){e.nodes().forEach(t=>n(e.node(t))),e.edges().forEach(t=>n(e.edge(t)))}function n(e){let t=e.width;e.width=e.height,e.height=t}function i(e){e.y=-e.y}function o(e){let t=e.x;e.x=e.y,e.y=t}t.exports={adjust:function(e){let t=e.graph().rankdir.toLowerCase();("lr"===t||"rl"===t)&&r(e)},undo:function(e){let t=e.graph().rankdir.toLowerCase();("bt"===t||"rl"===t)&&function(e){e.nodes().forEach(t=>i(e.node(t))),e.edges().forEach(t=>{let r=e.edge(t);r.points.forEach(i),Object.hasOwn(r,"y")&&i(r)})}(e),("lr"===t||"rl"===t)&&(function(e){e.nodes().forEach(t=>o(e.node(t))),e.edges().forEach(t=>{let r=e.edge(t);r.points.forEach(o),Object.hasOwn(r,"x")&&o(r)})}(e),r(e))}}}),m=t((e,t)=>{var r=o();t.exports=function(e){let t={},n=e.nodes().filter(t=>!e.children(t).length),i=n.map(t=>e.node(t).rank),o=r.applyWithChunking(Math.max,i),s=r.range(o+1).map(()=>[]);return n.sort((t,r)=>e.node(t).rank-e.node(r).rank).forEach(function r(n){if(t[n])return;t[n]=!0;let i=e.node(n);s[i.rank].push(n),e.successors(n).forEach(r)}),s}}),v=t((e,t)=>{var r=o().zipObject;function n(e,t,n){let i=r(n,n.map((e,t)=>t)),o=t.flatMap(t=>e.outEdges(t).map(t=>({pos:i[t.w],weight:e.edge(t).weight})).sort((e,t)=>e.pos-t.pos)),s=1;for(;s<n.length;)s<<=1;let a=2*s-1;s-=1;let h=new Array(a).fill(0),d=0;return o.forEach(e=>{let t=e.pos+s;h[t]+=e.weight;let r=0;for(;t>0;)t%2&&(r+=h[t+1]),t=t-1>>1,h[t]+=e.weight;d+=e.weight*r}),d}t.exports=function(e,t){let r=0;for(let i=1;i<t.length;++i)r+=n(e,t[i-1],t[i]);return r}}),w=t((e,t)=>{t.exports=function(e,t=[]){return t.map(t=>{let r=e.inEdges(t);if(r.length){let n=r.reduce((t,r)=>{let n=e.edge(r),i=e.node(r.v);return{sum:t.sum+n.weight*i.order,weight:t.weight+n.weight}},{sum:0,weight:0});return{v:t,barycenter:n.sum/n.weight,weight:n.weight}}return{v:t}})}}),b=t((e,t)=>{var r=o();t.exports=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 r=0,n=0;e.weight&&(r+=e.barycenter*e.weight,n+=e.weight),t.weight&&(r+=t.barycenter*t.weight,n+=t.weight),e.vs=t.vs.concat(e.vs),e.barycenter=r/n,e.weight=n,e.i=Math.min(t.i,e.i),t.merged=!0}(e,t)}}function i(t){return r=>{r.in.push(t),0===--r.indegree&&e.push(r)}}for(;e.length;){let r=e.pop();t.push(r),r.in.reverse().forEach(n(r)),r.out.forEach(i(r))}return t.filter(e=>!e.merged).map(e=>r.pick(e,["vs","i","barycenter","weight"]))}(Object.values(n).filter(e=>!e.indegree))}}),y=t((e,t)=>{var r=o();function n(e,t,r){let n;for(;t.length&&(n=t[t.length-1]).i<=r;)t.pop(),e.push(n.vs),r++;return r}t.exports=function(e,t){let i=r.partition(e,e=>Object.hasOwn(e,"barycenter")),o=i.lhs,s=i.rhs.sort((e,t)=>t.i-e.i),a=[],h=0,d=0,c=0;o.sort(function(e){return(t,r)=>t.barycenter<r.barycenter?-1:t.barycenter>r.barycenter?1:e?r.i-t.i:t.i-r.i}(!!t)),c=n(a,s,c),o.forEach(e=>{c+=e.vs.length,a.push(e.vs),h+=e.barycenter*e.weight,d+=e.weight,c=n(a,s,c)});let l={vs:a.flat(!0)};return d&&(l.barycenter=h/d,l.weight=d),l}}),E=t((e,t)=>{var r=w(),n=b(),i=y();t.exports=function e(t,o,s,a){let h=t.children(o),d=t.node(o),c=d?d.borderLeft:void 0,l=d?d.borderRight:void 0,u={};c&&(h=h.filter(e=>e!==c&&e!==l));let f=r(t,h);f.forEach(r=>{if(t.children(r.v).length){let n=e(t,r.v,s,a);u[r.v]=n,Object.hasOwn(n,"barycenter")&&function(e,t){void 0!==e.barycenter?(e.barycenter=(e.barycenter*e.weight+t.barycenter*t.weight)/(e.weight+t.weight),e.weight+=t.weight):(e.barycenter=t.barycenter,e.weight=t.weight)}(r,n)}});let g=n(f,s);!function(e,t){e.forEach(e=>{e.vs=e.vs.flatMap(e=>t[e]?t[e].vs:e)})}(g,u);let p=i(g,a);if(c&&(p.vs=[c,p.vs,l].flat(!0),t.predecessors(c).length)){let e=t.node(t.predecessors(c)[0]),r=t.node(t.predecessors(l)[0]);Object.hasOwn(p,"barycenter")||(p.barycenter=0,p.weight=0),p.barycenter=(p.barycenter*p.weight+e.order+r.order)/(p.weight+2),p.weight+=2}return p}}),x=t((e,t)=>{var n=r().Graph,i=o();t.exports=function(e,t,r,o){o||(o=e.nodes());let s=function(e){for(var t;e.hasNode(t=i.uniqueId("_root")););return t}(e),a=new n({compound:!0}).setGraph({root:s}).setDefaultNodeLabel(t=>e.node(t));return o.forEach(n=>{let i=e.node(n),o=e.parent(n);(i.rank===t||i.minRank<=t&&t<=i.maxRank)&&(a.setNode(n),a.setParent(n,o||s),e[r](n).forEach(t=>{let r=t.v===n?t.w:t.v,i=a.edge(r,n),o=void 0!==i?i.weight:0;a.setEdge(r,n,{weight:e.edge(t).weight+o})}),Object.hasOwn(i,"minRank")&&a.setNode(n,{borderLeft:i.borderLeft[t],borderRight:i.borderRight[t]}))}),a}}),_=t((e,t)=>{t.exports=function(e,t,r){let n,i={};r.forEach(r=>{let o,s,a=e.parent(r);for(;a;){if(o=e.parent(a),o?(s=i[o],i[o]=a):(s=n,n=a),s&&s!==a)return void t.setEdge(s,a);a=o}})}}),k=t((e,t)=>{var n=m(),i=v(),s=E(),a=x(),h=_(),d=r().Graph,c=o();function l(e,t,r){let n=new Map,i=(e,t)=>{n.has(e)||n.set(e,[]),n.get(e).push(t)};for(let t of e.nodes()){let r=e.node(t);if("number"==typeof r.rank&&i(r.rank,t),"number"==typeof r.minRank&&"number"==typeof r.maxRank)for(let e=r.minRank;e<=r.maxRank;e++)e!==r.rank&&i(e,t)}return t.map(function(t){return a(e,t,r,n.get(t)||[])})}function u(e,t,r){let n=new d;e.forEach(function(e){r.forEach(e=>n.setEdge(e.left,e.right));let i=e.graph().root,o=s(e,i,n,t);o.vs.forEach((t,r)=>e.node(t).order=r),h(e,n,o.vs)})}function f(e,t){Object.values(t).forEach(t=>t.forEach((t,r)=>e.node(t).order=r))}t.exports=function e(t,r={}){if("function"==typeof r.customOrder)return void r.customOrder(t,e);let o=c.maxRank(t),s=l(t,c.range(1,o+1),"inEdges"),a=l(t,c.range(o-1,-1,-1),"outEdges"),h=n(t);if(f(t,h),r.disableOptimalOrderHeuristic)return;let d,g=Number.POSITIVE_INFINITY,p=r.constraints||[];for(let e=0,r=0;r<4;++e,++r){u(e%2?s:a,e%4>=2,p),h=c.buildLayerMatrix(t);let n=i(t,h);n<g?(r=0,d=Object.assign({},h),g=n):n===g&&(d=structuredClone(h))}f(t,d)}}),O=t((e,t)=>{var n=r().Graph,i=o();function s(e,t){let r={};return t.length&&t.reduce(function(t,n){let i=0,o=0,s=t.length,a=n[n.length-1];return n.forEach((t,d)=>{let c=function(e,t){if(e.node(t).dummy)return e.predecessors(t).find(t=>e.node(t).dummy)}(e,t),l=c?e.node(c).order:s;(c||t===a)&&(n.slice(o,d+1).forEach(t=>{e.predecessors(t).forEach(n=>{let o=e.node(n),s=o.order;(s<i||l<s)&&(!o.dummy||!e.node(t).dummy)&&h(r,n,t)})}),o=d+1,i=l)}),n}),r}function a(e,t){let r={};function n(t,n,o,s,a){let d;i.range(n,o).forEach(n=>{d=t[n],e.node(d).dummy&&e.predecessors(d).forEach(t=>{let n=e.node(t);n.dummy&&(n.order<s||n.order>a)&&h(r,t,d)})})}return t.length&&t.reduce(function(t,r){let i,o=-1,s=0;return r.forEach((a,h)=>{if("border"===e.node(a).dummy){let t=e.predecessors(a);t.length&&(i=e.node(t[0]).order,n(r,s,h,o,i),s=h,o=i)}n(r,s,r.length,i,t.length)}),r}),r}function h(e,t,r){if(t>r){let e=t;t=r,r=e}let n=e[t];n||(e[t]=n={}),n[r]=!0}function d(e,t,r){if(t>r){let e=t;t=r,r=e}return!!e[t]&&Object.hasOwn(e[t],r)}function c(e,t,r,n){let i={},o={},s={};return t.forEach(e=>{e.forEach((e,t)=>{i[e]=e,o[e]=e,s[e]=t})}),t.forEach(e=>{let t=-1;e.forEach(e=>{let a=n(e);if(a.length){a=a.sort((e,t)=>s[e]-s[t]);let n=(a.length-1)/2;for(let h=Math.floor(n),c=Math.ceil(n);h<=c;++h){let n=a[h];o[e]===e&&t<s[n]&&!d(r,e,n)&&(o[n]=e,o[e]=i[e]=i[n],t=s[n])}}})}),{root:i,align:o}}function l(e,t,r,i,o){let s={},a=function(e,t,r,i){let o=new n,s=e.graph(),a=function(e,t,r){return(n,i,o)=>{let s,a=n.node(i),h=n.node(o),d=0;if(d+=a.width/2,Object.hasOwn(a,"labelpos"))switch(a.labelpos.toLowerCase()){case"l":s=-a.width/2;break;case"r":s=a.width/2}if(s&&(d+=r?s:-s),s=0,d+=(a.dummy?t:e)/2,d+=(h.dummy?t:e)/2,d+=h.width/2,Object.hasOwn(h,"labelpos"))switch(h.labelpos.toLowerCase()){case"l":s=h.width/2;break;case"r":s=-h.width/2}return s&&(d+=r?s:-s),s=0,d}}(s.nodesep,s.edgesep,i);return t.forEach(t=>{let n;t.forEach(t=>{let i=r[t];if(o.setNode(i),n){var s=r[n],h=o.edge(s,i);o.setEdge(s,i,Math.max(a(e,t,n),h||0))}n=t})}),o}(e,t,r,o),h=o?"borderLeft":"borderRight";function d(e,t){let r=a.nodes().slice(),n={},i=r.pop();for(;i;){if(n[i])e(i);else{n[i]=!0,r.push(i);for(let e of t(i))r.push(e)}i=r.pop()}}return d(function(e){s[e]=a.inEdges(e).reduce((e,t)=>Math.max(e,s[t.v]+a.edge(t)),0)},a.predecessors.bind(a)),d(function(t){let r=a.outEdges(t).reduce((e,t)=>Math.min(e,s[t.w]-a.edge(t)),Number.POSITIVE_INFINITY),n=e.node(t);r!==Number.POSITIVE_INFINITY&&n.borderType!==h&&(s[t]=Math.max(s[t],r))},a.successors.bind(a)),Object.keys(i).forEach(e=>s[e]=s[r[e]]),s}function u(e,t){return Object.values(t).reduce((t,r)=>{let n=Number.NEGATIVE_INFINITY,i=Number.POSITIVE_INFINITY;Object.entries(r).forEach(([t,r])=>{let o=function(e,t){return e.node(t).width}(e,t)/2;n=Math.max(r+o,n),i=Math.min(r-o,i)});let o=n-i;return o<t[0]&&(t=[o,r]),t},[Number.POSITIVE_INFINITY,null])[1]}function f(e,t){let r=Object.values(t),n=i.applyWithChunking(Math.min,r),o=i.applyWithChunking(Math.max,r);["u","d"].forEach(r=>{["l","r"].forEach(s=>{let a=r+s,h=e[a];if(h===t)return;let d=Object.values(h),c=n-i.applyWithChunking(Math.min,d);"l"!==s&&(c=o-i.applyWithChunking(Math.max,d)),c&&(e[a]=i.mapValues(h,e=>e+c))})})}function g(e,t){return i.mapValues(e.ul,(r,n)=>{if(t)return e[t.toLowerCase()][n];{let t=Object.values(e).map(e=>e[n]).sort((e,t)=>e-t);return(t[1]+t[2])/2}})}t.exports={positionX:function(e){let t,r=i.buildLayerMatrix(e),n=Object.assign(s(e,r),a(e,r)),o={};["u","d"].forEach(s=>{t="u"===s?r:Object.values(r).reverse(),["l","r"].forEach(r=>{"r"===r&&(t=t.map(e=>Object.values(e).reverse()));let a=("u"===s?e.predecessors:e.successors).bind(e),h=c(e,t,n,a),d=l(e,t,h.root,h.align,"r"===r);"r"===r&&(d=i.mapValues(d,e=>-e)),o[s+r]=d})});let h=u(e,o);return f(o,h),g(o,e.graph().align)},findType1Conflicts:s,findType2Conflicts:a,addConflict:h,hasConflict:d,verticalAlignment:c,horizontalCompaction:l,alignCoordinates:f,findSmallestWidthAlignment:u,balance:g}}),N=t((e,t)=>{var r=o(),n=O().positionX;t.exports=function(e){(function(e){let t=r.buildLayerMatrix(e),n=e.graph().ranksep,i=e.graph().rankalign,o=0;t.forEach(t=>{let r=t.reduce((t,r)=>{let n=e.node(r).height;return t>n?t:n},0);t.forEach(t=>{let n=e.node(t);n.y="top"===i?o+n.height/2:"bottom"===i?o+r-n.height/2:o+r/2}),o+=r+n})})(e=r.asNonCompoundGraph(e)),Object.entries(n(e)).forEach(([t,r])=>e.node(t).x=r)}}),I=t((e,t)=>{var n=s(),i=a(),h=l(),d=o().normalizeRanks,c=u(),m=o().removeEmptyRanks,v=f(),w=g(),b=p(),y=k(),E=N(),x=o(),_=r().Graph;t.exports=function(e,t={}){let r=t.debugTiming?x.time:x.notime;return r("layout",()=>{let o=r(" buildLayoutGraph",()=>function(e){let t=new _({multigraph:!0,compound:!0}),r=R(e.graph());return t.setGraph(Object.assign({},I,P(r,O),x.pick(r,M))),e.nodes().forEach(r=>{let n=P(R(e.node(r)),j);Object.keys(C).forEach(e=>{void 0===n[e]&&(n[e]=C[e])}),t.setNode(r,n),t.setParent(r,e.parent(r))}),e.edges().forEach(r=>{let n=R(e.edge(r));t.setEdge(r,Object.assign({},T,P(n,L),x.pick(n,S)))}),t}(e));return r(" runLayout",()=>function(e,t,r){t(" makeSpaceForEdgeLabels",()=>function(e){let t=e.graph();t.ranksep/=2,e.edges().forEach(r=>{let n=e.edge(r);n.minlen*=2,"c"!==n.labelpos.toLowerCase()&&("TB"===t.rankdir||"BT"===t.rankdir?n.width+=n.labeloffset:n.height+=n.labeloffset)})}(e)),t(" removeSelfEdges",()=>function(e){e.edges().forEach(t=>{if(t.v===t.w){var r=e.node(t.v);r.selfEdges||(r.selfEdges=[]),r.selfEdges.push({e:t,label:e.edge(t)}),e.removeEdge(t)}})}(e)),t(" acyclic",()=>n.run(e)),t(" nestingGraph.run",()=>v.run(e)),t(" rank",()=>h(x.asNonCompoundGraph(e))),t(" injectEdgeLabelProxies",()=>function(e){e.edges().forEach(t=>{let r=e.edge(t);if(r.width&&r.height){let r=e.node(t.v),n={rank:(e.node(t.w).rank-r.rank)/2+r.rank,e:t};x.addDummyNode(e,"edge-proxy",n,"_ep")}})}(e)),t(" removeEmptyRanks",()=>m(e)),t(" nestingGraph.cleanup",()=>v.cleanup(e)),t(" normalizeRanks",()=>d(e)),t(" assignRankMinMax",()=>function(e){let t=0;e.nodes().forEach(r=>{let n=e.node(r);n.borderTop&&(n.minRank=e.node(n.borderTop).rank,n.maxRank=e.node(n.borderBottom).rank,t=Math.max(t,n.maxRank))}),e.graph().maxRank=t}(e)),t(" removeEdgeLabelProxies",()=>function(e){e.nodes().forEach(t=>{let r=e.node(t);"edge-proxy"===r.dummy&&(e.edge(r.e).labelRank=r.rank,e.removeNode(t))})}(e)),t(" normalize.run",()=>i.run(e)),t(" parentDummyChains",()=>c(e)),t(" addBorderSegments",()=>w(e)),t(" order",()=>y(e,r)),t(" insertSelfEdges",()=>function(e){var t=x.buildLayerMatrix(e);t.forEach(t=>{var r=0;t.forEach((t,n)=>{var i=e.node(t);i.order=n+r,(i.selfEdges||[]).forEach(t=>{x.addDummyNode(e,"selfedge",{width:t.label.width,height:t.label.height,rank:i.rank,order:n+ ++r,e:t.e,label:t.label},"_se")}),delete i.selfEdges})})}(e)),t(" adjustCoordinateSystem",()=>b.adjust(e)),t(" position",()=>E(e)),t(" positionSelfEdges",()=>function(e){e.nodes().forEach(t=>{var r=e.node(t);if("selfedge"===r.dummy){var n=e.node(r.e.v),i=n.x+n.width/2,o=n.y,s=r.x-i,a=n.height/2;e.setEdge(r.e,r.label),e.removeNode(t),r.label.points=[{x:i+2*s/3,y:o-a},{x:i+5*s/6,y:o-a},{x:i+s,y:o},{x:i+5*s/6,y:o+a},{x:i+2*s/3,y:o+a}],r.label.x=r.x,r.label.y=r.y}})}(e)),t(" removeBorderNodes",()=>function(e){e.nodes().forEach(t=>{if(e.children(t).length){let r=e.node(t),n=e.node(r.borderTop),i=e.node(r.borderBottom),o=e.node(r.borderLeft[r.borderLeft.length-1]),s=e.node(r.borderRight[r.borderRight.length-1]);r.width=Math.abs(s.x-o.x),r.height=Math.abs(i.y-n.y),r.x=o.x+r.width/2,r.y=n.y+r.height/2}}),e.nodes().forEach(t=>{"border"===e.node(t).dummy&&e.removeNode(t)})}(e)),t(" normalize.undo",()=>i.undo(e)),t(" fixupEdgeLabelCoords",()=>function(e){e.edges().forEach(t=>{let r=e.edge(t);if(Object.hasOwn(r,"x"))switch(("l"===r.labelpos||"r"===r.labelpos)&&(r.width-=r.labeloffset),r.labelpos){case"l":r.x-=r.width/2+r.labeloffset;break;case"r":r.x+=r.width/2+r.labeloffset}})}(e)),t(" undoCoordinateSystem",()=>b.undo(e)),t(" translateGraph",()=>function(e){let t=Number.POSITIVE_INFINITY,r=0,n=Number.POSITIVE_INFINITY,i=0,o=e.graph(),s=o.marginx||0,a=o.marginy||0;function h(e){let o=e.x,s=e.y,a=e.width,h=e.height;t=Math.min(t,o-a/2),r=Math.max(r,o+a/2),n=Math.min(n,s-h/2),i=Math.max(i,s+h/2)}e.nodes().forEach(t=>h(e.node(t))),e.edges().forEach(t=>{let r=e.edge(t);Object.hasOwn(r,"x")&&h(r)}),t-=s,n-=a,e.nodes().forEach(r=>{let i=e.node(r);i.x-=t,i.y-=n}),e.edges().forEach(r=>{let i=e.edge(r);i.points.forEach(e=>{e.x-=t,e.y-=n}),Object.hasOwn(i,"x")&&(i.x-=t),Object.hasOwn(i,"y")&&(i.y-=n)}),o.width=r-t+s,o.height=i-n+a}(e)),t(" assignNodeIntersects",()=>function(e){e.edges().forEach(t=>{let r,n,i=e.edge(t),o=e.node(t.v),s=e.node(t.w);i.points?(r=i.points[0],n=i.points[i.points.length-1]):(i.points=[],r=s,n=o),i.points.unshift(x.intersectRect(o,r)),i.points.push(x.intersectRect(s,n))})}(e)),t(" reversePoints",()=>function(e){e.edges().forEach(t=>{let r=e.edge(t);r.reversed&&r.points.reverse()})}(e)),t(" acyclic.undo",()=>n.undo(e))}(o,r,t)),r(" updateInputGraph",()=>function(e,t){e.nodes().forEach(r=>{let n=e.node(r),i=t.node(r);n&&(n.x=i.x,n.y=i.y,n.order=i.order,n.rank=i.rank,t.children(r).length&&(n.width=i.width,n.height=i.height))}),e.edges().forEach(r=>{let n=e.edge(r),i=t.edge(r);n.points=i.points,Object.hasOwn(i,"x")&&(n.x=i.x,n.y=i.y)}),e.graph().width=t.graph().width,e.graph().height=t.graph().height}(e,o)),o})};var O=["nodesep","edgesep","ranksep","marginx","marginy"],I={ranksep:50,edgesep:20,nodesep:50,rankdir:"tb",rankalign:"center"},M=["acyclicer","ranker","rankdir","align","rankalign"],j=["width","height","rank"],C={width:0,height:0},L=["minlen","weight","width","height","labeloffset"],T={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},S=["labelpos"];function P(e,t){return x.mapValues(x.pick(e,t),Number)}function R(e){var t={};return e&&Object.entries(e).forEach(([e,r])=>{"string"==typeof e&&(e=e.toLowerCase()),t[e]=r}),t}}),M=t((e,t)=>{var n=o(),i=r().Graph;t.exports={debugOrdering:function(e){let t=n.buildLayerMatrix(e),r=new i({compound:!0,multigraph:!0}).setGraph({});return e.nodes().forEach(t=>{r.setNode(t,{label:t}),r.setParent(t,"layer"+e.node(t).rank)}),e.edges().forEach(e=>r.setEdge(e.v,e.w,{},e.name)),t.forEach((e,t)=>{let n="layer"+t;r.setNode(n,{rank:"same"}),e.reduce((e,t)=>(r.setEdge(e,t,{style:"invis"}),t))}),r}}}),j=t((e,t)=>{t.exports="2.0.4"}),C=t((e,t)=>{t.exports={graphlib:r(),layout:I(),debug:M(),util:{time:o().time,notime:o().notime},version:j()}})();function L(e,t,r){if(t.has(e))return e;const n=r.get(e);return n?L(n,t,r):null}function T(e,t,r,n,i,o){const s=new C.graphlib.Graph({multigraph:!0});s.setGraph({rankdir:"TB",nodesep:30,ranksep:50,marginx:20,marginy:36}),s.setDefaultEdgeLabel(()=>({}));const a=new Map;e.forEach(e=>{if(i.has(e)){const h=T(n.get(e),t,r,n,i,o);a.set(e,h),s.setNode(e,{width:h.width,height:h.height})}else{const r=t.get(e);s.setNode(e,{width:r.width,height:r.height})}}),r.forEach((t,r)=>{const n=L(t.sources[0],e,o),i=L(t.targets[0],e,o);n&&i&&n!==i&&s.setEdge(n,i,{},r)}),C.layout(s);const h=[];e.forEach(e=>{const t=s.node(e);if(!t)return;const r={id:e,x:t.x-t.width/2,y:t.y-t.height/2,width:t.width,height:t.height};a.has(e)&&(r.children=a.get(e).children),h.push(r)});const d=s.graph();return{children:h,width:(d.width||0)+40,height:(d.height||0)+36+20}}async function S({nodeMap:e,edgeMap:t,containerChildren:r,containerIds:n,childOf:i,topLevelContainerIds:o}){const s=new C.graphlib.Graph({multigraph:!0});s.setGraph({rankdir:"TB",nodesep:50,ranksep:80}),s.setDefaultEdgeLabel(()=>({}));const a=new Map;function h(e){const t=i.get(e);return t?h(t):e}o.forEach(o=>{const h=T(r.get(o),e,t,r,n,i);a.set(o,h),s.setNode(o,{width:h.width,height:h.height})}),e.forEach((e,t)=>{n.has(t)||i.has(t)||s.setNode(t,{width:e.width,height:e.height})}),t.forEach((e,t)=>{const r=h(e.sources[0]),n=h(e.targets[0]);r!==n&&s.hasNode(r)&&s.hasNode(n)&&s.setEdge(r,n,{},t)}),C.layout(s);const d=[];return s.nodes().forEach(e=>{const t=s.node(e),r={id:e,x:t.x-t.width/2,y:t.y-t.height/2,width:t.width,height:t.height};a.has(e)&&(r.children=a.get(e).children),d.push(r)}),{id:"root",children:d}}const P="http://www.w3.org/2000/svg",R={block:{fill:"#ffffff",stroke:"#2c7be5",strokeWidth:1.5,headBar:"#2c7be5",headText:"#ffffff",anchor:"#2c7be5",neckAnchor:"#e67e22"},group:{fill:"#eff6ff",stroke:"#1d4ed8",strokeWidth:2.5,headBar:"#1d4ed8",headText:"#ffffff",anchor:"#1d4ed8",neckAnchor:"#e67e22"},neck:{fill:"#fff7f0",stroke:"#e67e22",strokeWidth:1.5,headBar:"#c0571a",headText:"#ffffff",anchor:"#e67e22",neckAnchor:"#e67e22"}},D={regular:{stroke:"#2c7be5",dasharray:"none",width:1.5},neck:{stroke:"#e67e22",dasharray:"6,3",width:1.5},pic:{stroke:"#16a34a",dasharray:"4,3",width:1.5}};function F(e,t={},r=null){const n=document.createElementNS(P,e);return Object.entries(t).forEach(([e,t])=>n.setAttribute(e,t)),r&&r.appendChild(n),n}function G(e,t,r,n){(e||[]).forEach(e=>{const i=t+e.x,o=r+e.y;n.set(e.id,{x:i,y:o,w:e.width,h:e.height}),e.children&&G(e.children,i,o,n)})}function $(e,t,r,n){"logical-group"===t.type||t.type;const i=r?"neck"===n||"pic"===n?8:-8:"pic"===n?8:-8,o=e.x+e.w/2+i;return r?{x:o,y:e.y+e.h}:{x:o,y:e.y}}const V={regular:{src:30,tgt:10},neck:{src:10,tgt:10},pic:{src:10,tgt:20}};function z(e,t,r){F("path",{d:e.map((e,t)=>`${0===t?"M":"L"}${e.x},${e.y}`).join(" "),fill:"none",stroke:t.stroke,"stroke-width":t.width,"stroke-dasharray":t.dasharray,"stroke-linecap":"round","stroke-linejoin":"round"},r)}function A(e,t,r,n){const i=180*Math.atan2(e.y-t.y,e.x-t.x)/Math.PI;F("polygon",{points:"0,-4 8,0 0,4",fill:r.stroke,transform:`translate(${e.x},${e.y}) rotate(${i})`},n)}function Y(e,t,r,n,i,o){(e||[]).forEach(e=>{const s=t+e.x,a=r+e.y,h=n.get(e.id)||{};if("logical-group"===h.type){const t=F("g",{transform:`translate(${s},${a})`},o);F("rect",{x:0,y:0,width:e.width,height:e.height,rx:8,ry:8,fill:"#f0f7ff",stroke:"#93c5fd","stroke-width":1.5,"stroke-dasharray":"8,4"},t),h.label&&h.label.trim()&&(F("text",{x:12,y:18,"text-anchor":"start","dominant-baseline":"middle","font-family":"sans-serif","font-size":"10","font-weight":"700",fill:"#3b82f6","letter-spacing":"1"},t).textContent=h.label.toUpperCase()),F("circle",{cx:e.width/2-8,cy:0,r:3,fill:"#2c7be5"},t),F("circle",{cx:e.width/2+8,cy:0,r:3,fill:"#16a34a"},t),Y(e.children,s,a,n,i,o)}if("group"===h.type){const t=F("g",{transform:`translate(${s},${a})`},o);F("rect",{x:0,y:0,width:e.width,height:e.height,rx:8,ry:8,fill:"#eff6ff",stroke:"#1d4ed8","stroke-width":1.5,"stroke-dasharray":"6,3"},t),h.label&&h.label.trim()&&(F("text",{x:12,y:18,"text-anchor":"start","dominant-baseline":"middle","font-family":"sans-serif","font-size":"10","font-weight":"700",fill:"#1d4ed8","letter-spacing":"1"},t).textContent=h.label.toUpperCase()),F("circle",{cx:e.width/2-8,cy:0,r:3,fill:"#1d4ed8"},t),F("circle",{cx:e.width/2+8,cy:0,r:3,fill:"#16a34a"},t),Y(e.children,s,a,n,i,o)}})}function B(e,t,r,n,i,o){(e||[]).forEach(e=>{const s=t+e.x,a=r+e.y,h=n.get(e.id)||{};if("logical-group"===h.type||"group"===h.type){const t=function(e,t){return e.head&&t.has(e.head)?e.head:e.role&&t.has(e.role)?e.role:null}(h,n);B(e.children,s,a,n,i,t)}else{!function(e,t,r,n,i,o){const s=r.type||"block",a=R[s]||R.block,{width:h,height:d}=n,c=F("g",{class:`sto-node sto-node--${s}${i?" sto-node--head":""}`,"data-id":n.id,transform:`translate(${e},${t})`},o);if(F("rect",{x:2,y:2,width:h,height:d,rx:5,ry:5,fill:"rgba(0,0,0,0.07)",stroke:"none"},c),F("rect",{x:0,y:0,width:h,height:d,rx:5,ry:5,fill:a.fill,stroke:a.stroke,"stroke-width":a.strokeWidth,"stroke-dasharray":"neck"===s?"6,3":"none"},c),"group"===s){const e=`clip-grp-${n.id}`,t=F("defs",{},c),r=document.createElementNS(P,"clipPath");r.setAttribute("id",e),F("rect",{x:0,y:0,width:h,height:d,rx:5,ry:5},r),t.appendChild(r),F("rect",{x:0,y:0,width:5,height:d,fill:a.stroke,"clip-path":`url(#${e})`},c)}if(i){const e=`clip-head-${n.id}`,t=F("defs",{},c),r=document.createElementNS(P,"clipPath");r.setAttribute("id",e),F("rect",{x:0,y:0,width:h,height:d,rx:5,ry:5},r),t.appendChild(r),F("rect",{x:0,y:0,width:h,height:16,fill:a.headBar,"clip-path":`url(#${e})`},c),F("text",{x:h/2,y:8,"text-anchor":"middle","dominant-baseline":"middle","font-family":"sans-serif","font-size":"9","font-weight":"700",fill:a.headText,"letter-spacing":"0.8"},c).textContent="HEAD"}const l=i?16:0,u=d-l,f="group"===s?5+(h-5)/2:h/2;if(r.html){const e="group"===s?21:16,t=10,n=F("foreignObject",{x:e,y:l+t,width:Math.max(h-e-8,1),height:Math.max(u-2*t,1)},c),i=document.createElementNS("http://www.w3.org/1999/xhtml","div");i.innerHTML=r.html,i.style.cssText="width:100%;height:100%;overflow:hidden;font-size:12px;font-family:sans-serif;box-sizing:border-box;",n.appendChild(i)}else F("text",{x:f,y:l+u/2,"text-anchor":"middle","dominant-baseline":"middle","font-family":"sans-serif","font-size":"12","font-weight":i||"group"===s?"700":"400",fill:"group"===s?a.stroke:"#1a1a1a"},c).textContent=r.label||n.id;F("circle",{cx:h/2-8,cy:0,r:3,fill:a.anchor},c),F("circle",{cx:h/2+8,cy:0,r:3,fill:"#16a34a"},c),F("circle",{cx:h/2-8,cy:d,r:3,fill:a.anchor},c),F("circle",{cx:h/2+8,cy:d,r:3,fill:a.neckAnchor},c)}(s,a,h,e,e.id===o||"head"===h.role,i)}})}function W(e,t,r,n){for(;n.firstChild;)n.removeChild(n.firstChild);const i=F("g",{class:"sto-root"},n),o=F("g",{class:"sto-bg"},i),s=F("g",{class:"sto-edges"},i),a=F("g",{class:"sto-nodes"},i),h=new Map;G(e.children,0,0,h),Y(e.children,0,0,t,h,o);const d=new Map;r.forEach(e=>{const t=`${e.sources[0]}::${e.type}`;d.has(t)||d.set(t,[]),d.get(t).push(e)});const c=new Map,l=new Map;return d.forEach((e,r)=>{if(e.length>1)return;const n=e[0].sources[0],i=h.get(n);if(!i)return;const{src:o}=V[e[0].type]||V.regular,s=$(i,t.get(n)||{},!0,e[0].type),a=`${Math.round(s.y+o)}::${e[0].type}`;l.has(a)||l.set(a,[]),l.get(a).push({key:r,srcX:s.x})}),l.forEach(e=>{e.length<2||(e.sort((e,t)=>e.srcX-t.srcX),e.forEach(({key:e},t)=>c.set(e,15*t)))}),d.forEach((e,r)=>function(e,t,r,n,i=0){if(!e.length)return;const o=e[0].type,s=D[o]||D.regular,{src:a,tgt:h}=V[o]||V.regular,d=e[0].sources[0],c=r.get(d);if(!c)return;const l=$(c,t.get(d)||{},!0,o),u=l.y+a+i,f=e.flatMap(e=>{const n=r.get(e.targets[0]);return n?[$(n,t.get(e.targets[0])||{},!1,o)]:[]});if(!f.length)return;const g=[l.x,...f.map(e=>e.x)],p=Math.min(...g),m=Math.max(...g);z([l,{x:l.x,y:u}],s,n),m>p&&z([{x:p,y:u},{x:m,y:u}],s,n),f.forEach(e=>{const t=e.y-h;t>u?(z([{x:e.x,y:u},{x:e.x,y:t},e],s,n),A(e,{x:e.x,y:t},s,n)):(z([{x:e.x,y:u},e],s,n),A(e,{x:e.x,y:u},s,n))})}(e,t,h,s,c.get(r)||0)),B(e.children,0,0,t,a,null),i}class q{constructor(e,t={}){this._container="string"==typeof e?document.querySelector(e):e,this._options={zoom:!0,pan:!0,cardWidth:200,cardHeight:80,...t},this._data=[],this._users=[],this._template=null,this._svg=null,this._root=null,this._initSvg()}_initSvg(){this._svg=document.createElementNS("http://www.w3.org/2000/svg","svg"),this._svg.setAttribute("width","100%"),this._svg.setAttribute("height","100%"),this._svg.style.display="block",this._container.appendChild(this._svg)}load(e){return this._data=e,this}assign(e,t,r={}){return this._users=e||[],this._template=t||"",this._cardSize={width:r.width||this._options.cardWidth,height:r.height||this._options.cardHeight},this}_applyUsers(e){if(!this._users.length||!this._template)return e;const t=new Map(this._users.map(e=>[e.stoid,e]));return e.map(e=>{const r=t.get(e.id);if(!r)return e;const n=this._template.replace(/\{(\w+)\}/g,(e,t)=>{const n=r[t];return null!=n?String(n):""});return{...e,html:n,width:e.width||this._cardSize.width,height:e.height||this._cardSize.height}})}async render(){const e=this._applyUsers(this._data),t=function(e){const t=new Map(e.map(e=>[e.id,{...e,width:e.width||160,height:e.height||60}])),r=new Map,n=new Set(e.filter(e=>"group"===e.type||"logical-group"===e.type).map(e=>e.id)),i=new Map;n.forEach(e=>i.set(e,new Set)),e.forEach(e=>{if(e.groupId&&i.has(e.groupId)&&i.get(e.groupId).add(e.id),e.parentId&&i.has(e.parentId)){const r=t.get(e.parentId);"group"===r?.type&&i.get(e.parentId).add(e.id)}});const o=new Map;i.forEach((e,t)=>{e.forEach(e=>o.set(e,t))});let s=!0;for(;s;)s=!1,e.forEach(e=>{if(!e.parentId||o.has(e.id)||n.has(e.id))return;const r=o.get(e.parentId);r&&"group"===t.get(r)?.type&&(i.get(r).add(e.id),o.set(e.id,r),s=!0)});e.forEach(e=>{if(e.parentId&&!(o.get(e.id)===e.parentId||e.groupId&&e.groupId===e.parentId)){const t=`e_${e.parentId}_${e.id}`;r.set(t,{id:t,sources:[e.parentId],targets:[e.id],type:e.edge||"regular"})}if(e.picId){const t=`epic_${e.picId}_${e.id}`;r.set(t,{id:t,sources:[e.picId],targets:[e.id],type:"pic"})}});const a=[...n].filter(e=>!o.has(e));return{nodeMap:t,edgeMap:r,containerChildren:i,childOf:o,containerIds:n,topLevelContainerIds:a}}(await async function(e){const t=e.filter(e=>e.html&&(!e.width||!e.height));if(0===t.length)return e;const r=document.createElement("div");r.style.cssText=["position:absolute","top:-99999px","left:-99999px","visibility:hidden","pointer-events:none","display:flex","flex-direction:column","gap:0"].join(";"),document.body.appendChild(r);const n=t.map(e=>{const t=document.createElement("div"),n=e.maxWidth||280;return t.style.cssText=`display:inline-block;max-width:${n}px;font-size:12px;font-family:sans-serif;box-sizing:border-box;`,t.innerHTML=e.html,r.appendChild(t),{node:e,div:t}});await new Promise(e=>requestAnimationFrame(e));const i=new Map;return n.forEach(({node:e,div:t})=>{const r=t.getBoundingClientRect(),n="head"===e.role?16:0;i.set(e.id,{width:Math.max(Math.ceil(r.width)+32,e.width||160),height:Math.max(Math.ceil(r.height)+20+n,e.height||60)})}),document.body.removeChild(r),e.map(e=>{const t=i.get(e.id);return t?{...e,...t}:e})}(e)),r=await S(t);return this._root=W(r,t.nodeMap,t.edgeMap,this._svg),(this._options.zoom||this._options.pan)&&function(e,t){let r=!1,n=0,i=0,o=0,s=0,a=1;function h(){t.setAttribute("transform",`translate(${o},${s}) scale(${a})`)}e.addEventListener("wheel",t=>{t.preventDefault();const r=t.deltaY>0?.9:1.1,n=Math.min(4,Math.max(.1,a*r)),i=n/a,d=e.getBoundingClientRect(),c=t.clientX-d.left,l=t.clientY-d.top;o=c-i*(c-o),s=l-i*(l-s),a=n,h()},{passive:!1}),e.addEventListener("mousedown",t=>{0===t.button&&(r=!0,n=t.clientX-o,i=t.clientY-s,e.style.cursor="grabbing")}),window.addEventListener("mousemove",e=>{r&&(o=e.clientX-n,s=e.clientY-i,h())}),window.addEventListener("mouseup",()=>{r&&(r=!1,e.style.cursor="grab")});let d=null;e.addEventListener("touchstart",e=>{1===e.touches.length&&(r=!0,n=e.touches[0].clientX-o,i=e.touches[0].clientY-s)},{passive:!0}),e.addEventListener("touchmove",e=>{if(1===e.touches.length&&r)o=e.touches[0].clientX-n,s=e.touches[0].clientY-i,h();else if(2===e.touches.length){const t=e.touches[0].clientX-e.touches[1].clientX,r=e.touches[0].clientY-e.touches[1].clientY,n=Math.sqrt(t*t+r*r);if(null!==d){const e=n/d;a=Math.min(4,Math.max(.1,a*e)),h()}d=n}},{passive:!0}),e.addEventListener("touchend",()=>{r=!1,d=null},{passive:!0}),e.style.cursor="grab"}(this._svg,this._root),this._fitView(r),this}_fitView(e){let t=1/0,r=1/0,n=-1/0,i=-1/0;if(function e(o,s=0,a=0){(o||[]).forEach(o=>{const h=s+o.x,d=a+o.y;t=Math.min(t,h),r=Math.min(r,d),n=Math.max(n,h+o.width),i=Math.max(i,d+o.height),o.children&&o.children.length&&e(o.children,h,d)})}(e.children),t===1/0)return;const o=n-t+80,s=i-r+80,a=this._container.clientWidth||800,h=this._container.clientHeight||600,d=Math.min(a/o,h/s,1),c=(a-o*d)/2-t*d+40*d,l=(h-s*d)/2-r*d+40*d;this._root.setAttribute("transform",`translate(${c},${l}) scale(${d})`)}}e.StoChart=q,e.default=q,Object.defineProperty(e,"__esModule",{value:!0})});
@@ -0,0 +1 @@
1
+ var e=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),t=e((e,t)=>{var r=Object.defineProperty,n=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),i=(e,t,n)=>((e,t,n)=>t in e?r(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n)(e,"symbol"!=typeof t?t+"":t,n),o=n((e,t)=>{var r="\0";function n(e,t){e[t]?e[t]++:e[t]=1}function o(e,t){--e[t]||delete e[t]}function s(e,t,r,n){var i=""+t,o=""+r;if(!e&&i>o){var s=i;i=o,o=s}return i+""+o+""+(void 0===n?"\0":n)}function a(e,t){return s(e,t.v,t.w,t.name)}t.exports=class{constructor(e){i(this,"_isDirected",!0),i(this,"_isMultigraph",!1),i(this,"_isCompound",!1),i(this,"_label"),i(this,"_defaultNodeLabelFn",()=>{}),i(this,"_defaultEdgeLabelFn",()=>{}),i(this,"_nodes",{}),i(this,"_in",{}),i(this,"_preds",{}),i(this,"_out",{}),i(this,"_sucs",{}),i(this,"_edgeObjs",{}),i(this,"_edgeLabels",{}),i(this,"_nodeCount",0),i(this,"_edgeCount",0),i(this,"_parent"),i(this,"_children"),e&&(this._isDirected=!Object.hasOwn(e,"directed")||e.directed,this._isMultigraph=!!Object.hasOwn(e,"multigraph")&&e.multigraph,this._isCompound=!!Object.hasOwn(e,"compound")&&e.compound),this._isCompound&&(this._parent={},this._children={},this._children[r]={})}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 r=arguments,n=this;return e.forEach(function(e){r.length>1?n.setNode(e,t):n.setNode(e)}),this}setNode(e,t){return Object.hasOwn(this._nodes,e)?(arguments.length>1&&(this._nodes[e]=t),this):(this._nodes[e]=arguments.length>1?t:this._defaultNodeLabelFn(e),this._isCompound&&(this._parent[e]=r,this._children[e]={},this._children[r][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 Object.hasOwn(this._nodes,e)}removeNode(e){var t=this;if(Object.hasOwn(this._nodes,e)){var r=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(r),delete this._in[e],delete this._preds[e],Object.keys(this._out[e]).forEach(r),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=r;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!==r)return t}}children(e=r){if(this._isCompound){var t=this._children[e];if(t)return Object.keys(t)}else{if(e===r)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){let n=new Set(t);for(var r of this.successors(e))n.add(r);return Array.from(n.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 r=this;Object.entries(this._nodes).forEach(function([r,n]){e(r)&&t.setNode(r,n)}),Object.values(this._edgeObjs).forEach(function(e){t.hasNode(e.v)&&t.hasNode(e.w)&&t.setEdge(e,r.edge(e))});var n={};function i(e){var o=r.parent(e);return void 0===o||t.hasNode(o)?(n[e]=o,o):o in n?n[o]:i(o)}return this._isCompound&&t.nodes().forEach(e=>t.setParent(e,i(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 r=this,n=arguments;return e.reduce(function(e,i){return n.length>1?r.setEdge(e,i,t):r.setEdge(e,i),i}),this}setEdge(){var e,t,r,i,o=!1,a=arguments[0];"object"==typeof a&&null!==a&&"v"in a?(e=a.v,t=a.w,r=a.name,2===arguments.length&&(i=arguments[1],o=!0)):(e=a,t=arguments[1],r=arguments[3],arguments.length>2&&(i=arguments[2],o=!0)),e=""+e,t=""+t,void 0!==r&&(r=""+r);var h=s(this._isDirected,e,t,r);if(Object.hasOwn(this._edgeLabels,h))return o&&(this._edgeLabels[h]=i),this;if(void 0!==r&&!this._isMultigraph)throw new Error("Cannot set a named edge when isMultigraph = false");this.setNode(e),this.setNode(t),this._edgeLabels[h]=o?i:this._defaultEdgeLabelFn(e,t,r);var d=function(e,t,r,n){var i=""+t,o=""+r;if(!e&&i>o){var s=i;i=o,o=s}var a={v:i,w:o};return n&&(a.name=n),a}(this._isDirected,e,t,r);return e=d.v,t=d.w,Object.freeze(d),this._edgeObjs[h]=d,n(this._preds[t],e),n(this._sucs[e],t),this._in[t][h]=d,this._out[e][h]=d,this._edgeCount++,this}edge(e,t,r){var n=1===arguments.length?a(this._isDirected,arguments[0]):s(this._isDirected,e,t,r);return this._edgeLabels[n]}edgeAsObj(){let e=this.edge(...arguments);return"object"!=typeof e?{label:e}:e}hasEdge(e,t,r){var n=1===arguments.length?a(this._isDirected,arguments[0]):s(this._isDirected,e,t,r);return Object.hasOwn(this._edgeLabels,n)}removeEdge(e,t,r){var n=1===arguments.length?a(this._isDirected,arguments[0]):s(this._isDirected,e,t,r),i=this._edgeObjs[n];return i&&(e=i.v,t=i.w,delete this._edgeLabels[n],delete this._edgeObjs[n],o(this._preds[t],e),o(this._sucs[e],t),delete this._in[t][n],delete this._out[e][n],this._edgeCount--),this}inEdges(e,t){return this.isDirected()?this.filterEdges(this._in[e],e,t):this.nodeEdges(e,t)}outEdges(e,t){return this.isDirected()?this.filterEdges(this._out[e],e,t):this.nodeEdges(e,t)}nodeEdges(e,t){if(e in this._nodes)return this.filterEdges({...this._in[e],...this._out[e]},e,t)}filterEdges(e,t,r){if(e){var n=Object.values(e);return r?n.filter(function(e){return e.v===t&&e.w===r||e.v===r&&e.w===t}):n}}}}),s=n((e,t)=>{t.exports="3.0.2"}),a=n((e,t)=>{t.exports={Graph:o(),version:s()}}),h=n((e,t)=>{var r=o();function n(e){return e.nodes().map(function(t){var r=e.node(t),n=e.parent(t),i={v:t};return void 0!==r&&(i.value=r),void 0!==n&&(i.parent=n),i})}function i(e){return e.edges().map(function(t){var r=e.edge(t),n={v:t.v,w:t.w};return void 0!==t.name&&(n.name=t.name),void 0!==r&&(n.value=r),n})}t.exports={write:function(e){var t={options:{directed:e.isDirected(),multigraph:e.isMultigraph(),compound:e.isCompound()},nodes:n(e),edges:i(e)};return void 0!==e.graph()&&(t.value=structuredClone(e.graph())),t},read:function(e){var t=new r(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}}}),d=n((e,t)=>{t.exports=function(e,t,n,i){return function(e,t,r,n){var i={},o=!0,s=0,a=e.nodes(),h=function(e){var t=r(e);i[e.v].distance+t<i[e.w].distance&&(i[e.w]={distance:i[e.v].distance+t,predecessor:e.v},o=!0)},d=function(){a.forEach(function(e){n(e).forEach(function(t){var r=t.v===e?t.v:t.w,n=r===t.v?t.w:t.v;h({v:r,w:n})})})};a.forEach(function(e){var r=e===t?0:Number.POSITIVE_INFINITY;i[e]={distance:r}});for(var c=a.length,l=1;l<c&&(o=!1,s++,d(),o);l++);if(s===c-1&&(o=!1,d(),o))throw new Error("The graph contains a negative weight cycle");return i}(e,String(t),n||r,i||function(t){return e.outEdges(t)})};var r=()=>1}),c=n((e,t)=>{t.exports=function(e){var t,r={},n=[];function i(n){Object.hasOwn(r,n)||(r[n]=!0,t.push(n),e.successors(n).forEach(i),e.predecessors(n).forEach(i))}return e.nodes().forEach(function(e){t=[],i(e),t.length&&n.push(t)}),n}}),l=n((e,t)=>{t.exports=class{constructor(){i(this,"_arr",[]),i(this,"_keyIndices",{})}size(){return this._arr.length}keys(){return this._arr.map(function(e){return e.key})}has(e){return Object.hasOwn(this._keyIndices,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 r=this._keyIndices;if(e=String(e),!Object.hasOwn(r,e)){var n=this._arr,i=n.length;return r[e]=i,n.push({key:e,priority:t}),this._decrease(i),!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 r=this._keyIndices[e];if(t>this._arr[r].priority)throw new Error("New priority is greater than current priority. Key: "+e+" Old: "+this._arr[r].priority+" New: "+t);this._arr[r].priority=t,this._decrease(r)}_heapify(e){var t=this._arr,r=2*e,n=r+1,i=e;r<t.length&&(i=t[r].priority<t[i].priority?r:i,n<t.length&&(i=t[n].priority<t[i].priority?n:i),i!==e&&(this._swap(e,i),this._heapify(i)))}_decrease(e){for(var t,r=this._arr,n=r[e].priority;0!==e&&!(r[t=e>>1].priority<n);)this._swap(e,t),e=t}_swap(e,t){var r=this._arr,n=this._keyIndices,i=r[e],o=r[t];r[e]=o,r[t]=i,n[o.key]=e,n[i.key]=t}}}),u=n((e,t)=>{var r=l();t.exports=function(e,t,i,o){return function(e,t,n,i){var o,s,a={},h=new r,d=function(e){var t=e.v!==o?e.v:e.w,r=a[t],i=n(e),d=s.distance+i;if(i<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+e+" Weight: "+i);d<r.distance&&(r.distance=d,r.predecessor=o,h.decrease(t,d))};for(e.nodes().forEach(function(e){var r=e===t?0:Number.POSITIVE_INFINITY;a[e]={distance:r},h.add(e,r)});h.size()>0&&(o=h.removeMin(),(s=a[o]).distance!==Number.POSITIVE_INFINITY);)i(o).forEach(d);return a}(e,String(t),i||n,o||function(t){return e.outEdges(t)})};var n=()=>1}),f=n((e,t)=>{var r=u();t.exports=function(e,t,n){return e.nodes().reduce(function(i,o){return i[o]=r(e,o,t,n),i},{})}}),g=n((e,t)=>{function r(e,t,r){for(var n=[],i=r;i!==t;)n.push(i),i=e[i].predecessor;return n.push(t),n.reverse()}t.exports=function(e,t,n){if(void 0!==e[t].predecessor)throw new Error("Invalid source vertex");if(void 0===e[n].predecessor&&n!==t)throw new Error("Invalid destination vertex");return{weight:e[n].distance,path:r(e,t,n)}}}),p=n((e,t)=>{t.exports=function(e){var t=0,r=[],n={},i=[];function o(s){var a=n[s]={onStack:!0,lowlink:t,index:t++};if(r.push(s),e.successors(s).forEach(function(e){Object.hasOwn(n,e)?n[e].onStack&&(a.lowlink=Math.min(a.lowlink,n[e].index)):(o(e),a.lowlink=Math.min(a.lowlink,n[e].lowlink))}),a.lowlink===a.index){var h,d=[];do{h=r.pop(),n[h].onStack=!1,d.push(h)}while(s!==h);i.push(d)}}return e.nodes().forEach(function(e){Object.hasOwn(n,e)||o(e)}),i}}),v=n((e,t)=>{var r=p();t.exports=function(e){return r(e).filter(function(t){return t.length>1||1===t.length&&e.hasEdge(t[0],t[0])})}}),m=n((e,t)=>{t.exports=function(e,t,n){return function(e,t,r){var n={},i=e.nodes();return i.forEach(function(e){n[e]={},n[e][e]={distance:0},i.forEach(function(t){e!==t&&(n[e][t]={distance:Number.POSITIVE_INFINITY})}),r(e).forEach(function(r){var i=r.v===e?r.w:r.v,o=t(r);n[e][i]={distance:o,predecessor:e}})}),i.forEach(function(e){var t=n[e];i.forEach(function(r){var o=n[r];i.forEach(function(r){var n=o[e],i=t[r],s=o[r],a=n.distance+i.distance;a<s.distance&&(s.distance=a,s.predecessor=i.predecessor)})})}),n}(e,t||r,n||function(t){return e.outEdges(t)})};var r=()=>1}),w=n((e,t)=>{function r(e){var t={},r={},i=[];if(e.sinks().forEach(function o(s){if(Object.hasOwn(r,s))throw new n;Object.hasOwn(t,s)||(r[s]=!0,t[s]=!0,e.predecessors(s).forEach(o),delete r[s],i.push(s))}),Object.keys(t).length!==e.nodeCount())throw new n;return i}var n=class extends Error{constructor(){super(...arguments)}};t.exports=r,r.CycleException=n}),b=n((e,t)=>{var r=w();t.exports=function(e){try{r(e)}catch(e){if(e instanceof r.CycleException)return!1;throw e}return!0}}),E=n((e,t)=>{function r(e,t,n,i,o,s,a){return Object.hasOwn(i,t)||(i[t]=!0,n||(a=s(a,t)),o(t).forEach(function(t){a=r(e,t,n,i,o,s,a)}),n&&(a=s(a,t))),a}t.exports=function(e,t,n,i,o){Array.isArray(t)||(t=[t]);var s=(e.isDirected()?e.successors:e.neighbors).bind(e),a={};return t.forEach(function(t){if(!e.hasNode(t))throw new Error("Graph does not have node: "+t);o=r(e,t,"post"===n,a,s,i,o)}),o}}),y=n((e,t)=>{var r=E();t.exports=function(e,t,n){return r(e,t,n,function(e,t){return e.push(t),e},[])}}),x=n((e,t)=>{var r=y();t.exports=function(e,t){return r(e,t,"post")}}),_=n((e,t)=>{var r=y();t.exports=function(e,t){return r(e,t,"pre")}}),k=n((e,t)=>{var r=o(),n=l();t.exports=function(e,t){var i,o=new r,s={},a=new n;function h(e){var r=e.v===i?e.w:e.v,n=a.priority(r);if(void 0!==n){var o=t(e);o<n&&(s[r]=i,a.decrease(r,o))}}if(0===e.nodeCount())return o;e.nodes().forEach(function(e){a.add(e,Number.POSITIVE_INFINITY),o.setNode(e)}),a.decrease(e.nodes()[0],0);for(var d=!1;a.size()>0;){if(i=a.removeMin(),Object.hasOwn(s,i))o.setEdge(i,s[i]);else{if(d)throw new Error("Input graph is not connected: "+e);d=!0}e.nodeEdges(i).forEach(h)}return o}}),O=n((e,t)=>{var r=u(),n=d();t.exports=function(e,t,i,o){return function(e,t,i,o){if(void 0===i)return r(e,t,i,o);for(var s=!1,a=e.nodes(),h=0;h<a.length;h++){for(var d=o(a[h]),c=0;c<d.length;c++){var l=d[c],u=l.v===a[h]?l.v:l.w;i({v:u,w:u===l.v?l.w:l.v})<0&&(s=!0)}if(s)return n(e,t,i,o)}return r(e,t,i,o)}(e,t,i,o||function(t){return e.outEdges(t)})}}),N=n((e,t)=>{t.exports={bellmanFord:d(),components:c(),dijkstra:u(),dijkstraAll:f(),extractPath:g(),findCycles:v(),floydWarshall:m(),isAcyclic:b(),postorder:x(),preorder:_(),prim:k(),shortestPaths:O(),reduce:E(),tarjan:p(),topsort:w()}}),I=a();t.exports={Graph:I.Graph,json:h(),alg:N(),version:I.version}}),r=e((e,t)=>{function r(e){e._prev._next=e._next,e._next._prev=e._prev,delete e._next,delete e._prev}function n(e,t){if("_next"!==e&&"_prev"!==e)return t}t.exports=class{constructor(){let e={};e._next=e._prev=e,this._sentinel=e}dequeue(){let e=this._sentinel,t=e._prev;if(t!==e)return r(t),t}enqueue(e){let t=this._sentinel;e._prev&&e._next&&r(e),e._next=t._next,t._next._prev=e,t._next=e,e._prev=t}toString(){let e=[],t=this._sentinel,r=t._prev;for(;r!==t;)e.push(JSON.stringify(r,n)),r=r._prev;return"["+e.join(", ")+"]"}}}),n=e((e,n)=>{var i=t().Graph,o=r();n.exports=function(e,t){if(e.nodeCount()<=1)return[];let r=function(e,t){let r=new i,n=0,s=0;e.nodes().forEach(e=>{r.setNode(e,{v:e,in:0,out:0})}),e.edges().forEach(e=>{let i=r.edge(e.v,e.w)||0,o=t(e),a=i+o;r.setEdge(e.v,e.w,a),s=Math.max(s,r.node(e.v).out+=o),n=Math.max(n,r.node(e.w).in+=o)});let a=function(e){let t=[];for(let r=0;r<e;r++)t.push(r);return t}(s+n+3).map(()=>new o),d=n+1;return r.nodes().forEach(e=>{h(a,d,r.node(e))}),{graph:r,buckets:a,zeroIdx:d}}(e,t||s);return function(e,t,r){let n,i=[],o=t[t.length-1],s=t[0];for(;e.nodeCount();){for(;n=s.dequeue();)a(e,t,r,n);for(;n=o.dequeue();)a(e,t,r,n);if(e.nodeCount())for(let o=t.length-2;o>0;--o)if(n=t[o].dequeue(),n){i=i.concat(a(e,t,r,n,!0));break}}return i}(r.graph,r.buckets,r.zeroIdx).flatMap(t=>e.outEdges(t.v,t.w))};var s=()=>1;function a(e,t,r,n,i){let o=i?[]:void 0;return e.inEdges(n.v).forEach(n=>{let s=e.edge(n),a=e.node(n.v);i&&o.push({v:n.v,w:n.w}),a.out-=s,h(t,r,a)}),e.outEdges(n.v).forEach(n=>{let i=e.edge(n),o=n.w,s=e.node(o);s.in-=i,h(t,r,s)}),e.removeNode(n.v),o}function h(e,t,r){r.out?r.in?e[r.out-r.in+t].enqueue(r):e[e.length-1].enqueue(r):e[0].enqueue(r)}}),i=e((e,r)=>{var n=t().Graph;function i(e,t,r,n){for(var i=n;e.hasNode(i);)i=d(n);return r.dummy=t,e.setNode(i,r),i}r.exports={addBorderNode:function(e,t,r,n){let o={width:0,height:0};return arguments.length>=4&&(o.rank=r,o.order=n),i(e,"border",o,t)},addDummyNode:i,applyWithChunking:s,asNonCompoundGraph:function(e){let t=new n({multigraph:e.isMultigraph()}).setGraph(e.graph());return e.nodes().forEach(r=>{e.children(r).length||t.setNode(r,e.node(r))}),e.edges().forEach(r=>{t.setEdge(r,e.edge(r))}),t},buildLayerMatrix:function(e){let t=c(a(e)+1).map(()=>[]);return e.nodes().forEach(r=>{let n=e.node(r),i=n.rank;void 0!==i&&(t[i][n.order]=r)}),t},intersectRect:function(e,t){let r,n,i=e.x,o=e.y,s=t.x-i,a=t.y-o,h=e.width/2,d=e.height/2;if(!s&&!a)throw new Error("Not possible to find intersection inside of the rectangle");return Math.abs(a)*h>Math.abs(s)*d?(a<0&&(d=-d),r=d*s/a,n=d):(s<0&&(h=-h),r=h,n=h*a/s),{x:i+r,y:o+n}},mapValues:function(e,t){let r=t;return"string"==typeof t&&(r=e=>e[t]),Object.entries(e).reduce((e,[t,n])=>(e[t]=r(n,t),e),{})},maxRank:a,normalizeRanks:function(e){let t=e.nodes().map(t=>{let r=e.node(t).rank;return void 0===r?Number.MAX_VALUE:r}),r=s(Math.min,t);e.nodes().forEach(t=>{let n=e.node(t);Object.hasOwn(n,"rank")&&(n.rank-=r)})},notime:function(e,t){return t()},partition:function(e,t){let r={lhs:[],rhs:[]};return e.forEach(e=>{t(e)?r.lhs.push(e):r.rhs.push(e)}),r},pick:function(e,t){let r={};for(let n of t)void 0!==e[n]&&(r[n]=e[n]);return r},predecessorWeights:function(e){let t=e.nodes().map(t=>{let r={};return e.inEdges(t).forEach(t=>{r[t.v]=(r[t.v]||0)+e.edge(t).weight}),r});return l(e.nodes(),t)},range:c,removeEmptyRanks:function(e){let t=e.nodes().map(t=>e.node(t).rank).filter(e=>void 0!==e),r=s(Math.min,t),n=[];e.nodes().forEach(t=>{let i=e.node(t).rank-r;n[i]||(n[i]=[]),n[i].push(t)});let i=0,o=e.graph().nodeRankFactor;Array.from(n).forEach((t,r)=>{void 0===t&&r%o!==0?--i:void 0!==t&&i&&t.forEach(t=>e.node(t).rank+=i)})},simplify:function(e){let t=(new n).setGraph(e.graph());return e.nodes().forEach(r=>t.setNode(r,e.node(r))),e.edges().forEach(r=>{let n=t.edge(r.v,r.w)||{weight:0,minlen:1},i=e.edge(r);t.setEdge(r.v,r.w,{weight:n.weight+i.weight,minlen:Math.max(n.minlen,i.minlen)})}),t},successorWeights:function(e){let t=e.nodes().map(t=>{let r={};return e.outEdges(t).forEach(t=>{r[t.w]=(r[t.w]||0)+e.edge(t).weight}),r});return l(e.nodes(),t)},time:function(e,t){let r=Date.now();try{return t()}finally{console.log(e+" time: "+(Date.now()-r)+"ms")}},uniqueId:d,zipObject:l};var o=65535;function s(e,t){if(t.length>o){let r=function(e,t=o){let r=[];for(let n=0;n<e.length;n+=t){let i=e.slice(n,n+t);r.push(i)}return r}(t);return e.apply(null,r.map(t=>e.apply(null,t)))}return e.apply(null,t)}function a(e){let t=e.nodes().map(t=>{let r=e.node(t).rank;return void 0===r?Number.MIN_VALUE:r});return s(Math.max,t)}var h=0;function d(e){return e+""+ ++h}function c(e,t,r=1){null==t&&(t=e,e=0);let n=e=>e<t;r<0&&(n=e=>t<e);let i=[];for(let t=e;n(t);t+=r)i.push(t);return i}function l(e,t){return e.reduce((e,r,n)=>(e[r]=t[n],e),{})}}),o=e((e,t)=>{var r=n(),o=i().uniqueId;t.exports={run:function(e){("greedy"===e.graph().acyclicer?r(e,(t=e,e=>t.edge(e).weight)):function(e){let t=[],r={},n={};function i(o){Object.hasOwn(n,o)||(n[o]=!0,r[o]=!0,e.outEdges(o).forEach(e=>{Object.hasOwn(r,e.w)?t.push(e):i(e.w)}),delete r[o])}return e.nodes().forEach(i),t}(e)).forEach(t=>{let r=e.edge(t);e.removeEdge(t),r.forwardName=t.name,r.reversed=!0,e.setEdge(t.w,t.v,r,o("rev"))});var t},undo:function(e){e.edges().forEach(t=>{let r=e.edge(t);if(r.reversed){e.removeEdge(t);let n=r.forwardName;delete r.reversed,delete r.forwardName,e.setEdge(t.w,t.v,r,n)}})}}}),s=e((e,t)=>{var r=i();t.exports={run:function(e){e.graph().dummyChains=[],e.edges().forEach(t=>function(e,t){let n,i,o,s=t.v,a=e.node(s).rank,h=t.w,d=e.node(h).rank,c=t.name,l=e.edge(t),u=l.labelRank;if(d===a+1)return;for(e.removeEdge(t),o=0,++a;a<d;++o,++a)l.points=[],i={width:0,height:0,edgeLabel:l,edgeObj:t,rank:a},n=r.addDummyNode(e,"edge",i,"_d"),a===u&&(i.width=l.width,i.height=l.height,i.dummy="edge-label",i.labelpos=l.labelpos),e.setEdge(s,n,{weight:l.weight},c),0===o&&e.graph().dummyChains.push(n),s=n;e.setEdge(s,h,{weight:l.weight},c)}(e,t))},undo:function(e){e.graph().dummyChains.forEach(t=>{let r,n=e.node(t),i=n.edgeLabel;for(e.setEdge(n.edgeObj,i);n.dummy;)r=e.successors(t)[0],e.removeNode(t),i.points.push({x:n.x,y:n.y}),"edge-label"===n.dummy&&(i.x=n.x,i.y=n.y,i.width=n.width,i.height=n.height),t=r,n=e.node(t)})}}}),a=e((e,t)=>{var{applyWithChunking:r}=i();t.exports={longestPath:function(e){var t={};e.sources().forEach(function n(i){var o=e.node(i);if(Object.hasOwn(t,i))return o.rank;t[i]=!0;let s=e.outEdges(i).map(t=>null==t?Number.POSITIVE_INFINITY:n(t.w)-e.edge(t).minlen);var a=r(Math.min,s);return a===Number.POSITIVE_INFINITY&&(a=0),o.rank=a})},slack:function(e,t){return e.node(t.w).rank-e.node(t.v).rank-e.edge(t).minlen}}}),h=e((e,r)=>{var n=t().Graph,i=a().slack;function o(e,t){return e.nodes().forEach(function r(n){t.nodeEdges(n).forEach(o=>{var s=o.v,a=n===s?o.w:s;!e.hasNode(a)&&!i(t,o)&&(e.setNode(a,{}),e.setEdge(n,a,{}),r(a))})}),e.nodeCount()}function s(e,t){return t.edges().reduce((r,n)=>{let o=Number.POSITIVE_INFINITY;return e.hasNode(n.v)!==e.hasNode(n.w)&&(o=i(t,n)),o<r[0]?[o,n]:r},[Number.POSITIVE_INFINITY,null])[1]}function h(e,t,r){e.nodes().forEach(e=>t.node(e).rank+=r)}r.exports=function(e){var t,r,a=new n({directed:!1}),d=e.nodes()[0],c=e.nodeCount();for(a.setNode(d,{});o(a,e)<c;)t=s(a,e),r=a.hasNode(t.v)?i(e,t):-i(e,t),h(a,e,r);return a}}),d=e((e,r)=>{var n=h(),o=a().slack,s=a().longestPath,d=t().alg.preorder,c=t().alg.postorder,l=i().simplify;function u(e){e=l(e),s(e);var t,r=n(e);for(p(r),f(r,e);t=m(r);)b(r,e,t,w(r,e,t))}function f(e,t){var r=c(e,e.nodes());(r=r.slice(0,r.length-1)).forEach(r=>function(e,t,r){var n=e.node(r),i=n.parent;e.edge(r,i).cutvalue=g(e,t,r)}(e,t,r))}function g(e,t,r){var n=e.node(r).parent,i=!0,o=t.edge(r,n),s=0;return o||(i=!1,o=t.edge(n,r)),s=o.weight,t.nodeEdges(r).forEach(o=>{var a=o.v===r,h=a?o.w:o.v;if(h!==n){var d=a===i,c=t.edge(o).weight;if(s+=d?c:-c,function(e,t,r){return e.hasEdge(t,r)}(e,r,h)){var l=e.edge(r,h).cutvalue;s+=d?-l:l}}}),s}function p(e,t){arguments.length<2&&(t=e.nodes()[0]),v(e,{},1,t)}function v(e,t,r,n,i){var o=r,s=e.node(n);return t[n]=!0,e.neighbors(n).forEach(i=>{Object.hasOwn(t,i)||(r=v(e,t,r,i,n))}),s.low=o,s.lim=r++,i?s.parent=i:delete s.parent,r}function m(e){return e.edges().find(t=>e.edge(t).cutvalue<0)}function w(e,t,r){var n=r.v,i=r.w;t.hasEdge(n,i)||(n=r.w,i=r.v);var s=e.node(n),a=e.node(i),h=s,d=!1;return s.lim>a.lim&&(h=a,d=!0),t.edges().filter(t=>d===E(e,e.node(t.v),h)&&d!==E(e,e.node(t.w),h)).reduce((e,r)=>o(t,r)<o(t,e)?r:e)}function b(e,t,r,n){var i=r.v,o=r.w;e.removeEdge(i,o),e.setEdge(n.v,n.w,{}),p(e),f(e,t),function(e,t){var r=e.nodes().find(e=>!t.node(e).parent),n=d(e,r);n=n.slice(1),n.forEach(r=>{var n=e.node(r).parent,i=t.edge(r,n),o=!1;i||(i=t.edge(n,r),o=!0),t.node(r).rank=t.node(n).rank+(o?i.minlen:-i.minlen)})}(e,t)}function E(e,t,r){return r.low<=t.lim&&t.lim<=r.lim}r.exports=u,u.initLowLimValues=p,u.initCutValues=f,u.calcCutValue=g,u.leaveEdge=m,u.enterEdge=w,u.exchangeEdges=b}),c=e((e,t)=>{var r=a().longestPath,n=h(),i=d();t.exports=function(e){var t=e.graph().ranker;if(t instanceof Function)return t(e);switch(e.graph().ranker){case"network-simplex":default:s(e);break;case"tight-tree":!function(e){r(e),n(e)}(e);break;case"longest-path":o(e);case"none":}};var o=r;function s(e){i(e)}}),l=e((e,t)=>{t.exports=function(e){let t=function(e){let t={},r=0;function n(i){let o=r;e.children(i).forEach(n),t[i]={low:o,lim:r++}}return e.children().forEach(n),t}(e);e.graph().dummyChains.forEach(r=>{let n=e.node(r),i=n.edgeObj,o=function(e,t,r,n){let i,o,s=[],a=[],h=Math.min(t[r].low,t[n].low),d=Math.max(t[r].lim,t[n].lim);i=r;do{i=e.parent(i),s.push(i)}while(i&&(t[i].low>h||d>t[i].lim));for(o=i,i=n;(i=e.parent(i))!==o;)a.push(i);return{path:s.concat(a.reverse()),lca:o}}(e,t,i.v,i.w),s=o.path,a=o.lca,h=0,d=s[h],c=!0;for(;r!==i.w;){if(n=e.node(r),c){for(;(d=s[h])!==a&&e.node(d).maxRank<n.rank;)h++;d===a&&(c=!1)}if(!c){for(;h<s.length-1&&e.node(d=s[h+1]).minRank<=n.rank;)h++;d=s[h]}e.setParent(r,d),r=e.successors(r)[0]}})}}),u=e((e,t)=>{var r=i();function n(e,t,i,o,s,a,h){let d=e.children(h);if(!d.length)return void(h!==t&&e.setEdge(t,h,{weight:0,minlen:i}));let c=r.addBorderNode(e,"_bt"),l=r.addBorderNode(e,"_bb"),u=e.node(h);e.setParent(c,h),u.borderTop=c,e.setParent(l,h),u.borderBottom=l,d.forEach(r=>{n(e,t,i,o,s,a,r);let d=e.node(r),u=d.borderTop?d.borderTop:r,f=d.borderBottom?d.borderBottom:r,g=d.borderTop?o:2*o,p=u!==f?1:s-a[h]+1;e.setEdge(c,u,{weight:g,minlen:p,nestingEdge:!0}),e.setEdge(f,l,{weight:g,minlen:p,nestingEdge:!0})}),e.parent(h)||e.setEdge(t,c,{weight:0,minlen:s+a[h]})}t.exports={run:function(e){let t=r.addDummyNode(e,"root",{},"_root"),i=function(e){var t={};function r(n,i){var o=e.children(n);o&&o.length&&o.forEach(e=>r(e,i+1)),t[n]=i}return e.children().forEach(e=>r(e,1)),t}(e),o=Object.values(i),s=r.applyWithChunking(Math.max,o)-1,a=2*s+1;e.graph().nestingRoot=t,e.edges().forEach(t=>e.edge(t).minlen*=a);let h=function(e){return e.edges().reduce((t,r)=>t+e.edge(r).weight,0)}(e)+1;e.children().forEach(r=>n(e,t,a,h,s,i,r)),e.graph().nodeRankFactor=a},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)})}}}),f=e((e,t)=>{var r=i();function n(e,t,n,i,o,s){let a={width:0,height:0,rank:s,borderType:t},h=o[t][s-1],d=r.addDummyNode(e,"border",a,n);o[t][s]=d,e.setParent(d,i),h&&e.setEdge(h,d,{weight:1})}t.exports=function(e){e.children().forEach(function t(r){let i=e.children(r),o=e.node(r);if(i.length&&i.forEach(t),Object.hasOwn(o,"minRank")){o.borderLeft=[],o.borderRight=[];for(let t=o.minRank,i=o.maxRank+1;t<i;++t)n(e,"borderLeft","_bl",r,o,t),n(e,"borderRight","_br",r,o,t)}})}}),g=e((e,t)=>{function r(e){e.nodes().forEach(t=>n(e.node(t))),e.edges().forEach(t=>n(e.edge(t)))}function n(e){let t=e.width;e.width=e.height,e.height=t}function i(e){e.y=-e.y}function o(e){let t=e.x;e.x=e.y,e.y=t}t.exports={adjust:function(e){let t=e.graph().rankdir.toLowerCase();("lr"===t||"rl"===t)&&r(e)},undo:function(e){let t=e.graph().rankdir.toLowerCase();("bt"===t||"rl"===t)&&function(e){e.nodes().forEach(t=>i(e.node(t))),e.edges().forEach(t=>{let r=e.edge(t);r.points.forEach(i),Object.hasOwn(r,"y")&&i(r)})}(e),("lr"===t||"rl"===t)&&(function(e){e.nodes().forEach(t=>o(e.node(t))),e.edges().forEach(t=>{let r=e.edge(t);r.points.forEach(o),Object.hasOwn(r,"x")&&o(r)})}(e),r(e))}}}),p=e((e,t)=>{var r=i();t.exports=function(e){let t={},n=e.nodes().filter(t=>!e.children(t).length),i=n.map(t=>e.node(t).rank),o=r.applyWithChunking(Math.max,i),s=r.range(o+1).map(()=>[]);return n.sort((t,r)=>e.node(t).rank-e.node(r).rank).forEach(function r(n){if(t[n])return;t[n]=!0;let i=e.node(n);s[i.rank].push(n),e.successors(n).forEach(r)}),s}}),v=e((e,t)=>{var r=i().zipObject;function n(e,t,n){let i=r(n,n.map((e,t)=>t)),o=t.flatMap(t=>e.outEdges(t).map(t=>({pos:i[t.w],weight:e.edge(t).weight})).sort((e,t)=>e.pos-t.pos)),s=1;for(;s<n.length;)s<<=1;let a=2*s-1;s-=1;let h=new Array(a).fill(0),d=0;return o.forEach(e=>{let t=e.pos+s;h[t]+=e.weight;let r=0;for(;t>0;)t%2&&(r+=h[t+1]),t=t-1>>1,h[t]+=e.weight;d+=e.weight*r}),d}t.exports=function(e,t){let r=0;for(let i=1;i<t.length;++i)r+=n(e,t[i-1],t[i]);return r}}),m=e((e,t)=>{t.exports=function(e,t=[]){return t.map(t=>{let r=e.inEdges(t);if(r.length){let n=r.reduce((t,r)=>{let n=e.edge(r),i=e.node(r.v);return{sum:t.sum+n.weight*i.order,weight:t.weight+n.weight}},{sum:0,weight:0});return{v:t,barycenter:n.sum/n.weight,weight:n.weight}}return{v:t}})}}),w=e((e,t)=>{var r=i();t.exports=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 r=0,n=0;e.weight&&(r+=e.barycenter*e.weight,n+=e.weight),t.weight&&(r+=t.barycenter*t.weight,n+=t.weight),e.vs=t.vs.concat(e.vs),e.barycenter=r/n,e.weight=n,e.i=Math.min(t.i,e.i),t.merged=!0}(e,t)}}function i(t){return r=>{r.in.push(t),0===--r.indegree&&e.push(r)}}for(;e.length;){let r=e.pop();t.push(r),r.in.reverse().forEach(n(r)),r.out.forEach(i(r))}return t.filter(e=>!e.merged).map(e=>r.pick(e,["vs","i","barycenter","weight"]))}(Object.values(n).filter(e=>!e.indegree))}}),b=e((e,t)=>{var r=i();function n(e,t,r){let n;for(;t.length&&(n=t[t.length-1]).i<=r;)t.pop(),e.push(n.vs),r++;return r}t.exports=function(e,t){let i=r.partition(e,e=>Object.hasOwn(e,"barycenter")),o=i.lhs,s=i.rhs.sort((e,t)=>t.i-e.i),a=[],h=0,d=0,c=0;o.sort(function(e){return(t,r)=>t.barycenter<r.barycenter?-1:t.barycenter>r.barycenter?1:e?r.i-t.i:t.i-r.i}(!!t)),c=n(a,s,c),o.forEach(e=>{c+=e.vs.length,a.push(e.vs),h+=e.barycenter*e.weight,d+=e.weight,c=n(a,s,c)});let l={vs:a.flat(!0)};return d&&(l.barycenter=h/d,l.weight=d),l}}),E=e((e,t)=>{var r=m(),n=w(),i=b();t.exports=function e(t,o,s,a){let h=t.children(o),d=t.node(o),c=d?d.borderLeft:void 0,l=d?d.borderRight:void 0,u={};c&&(h=h.filter(e=>e!==c&&e!==l));let f=r(t,h);f.forEach(r=>{if(t.children(r.v).length){let n=e(t,r.v,s,a);u[r.v]=n,Object.hasOwn(n,"barycenter")&&function(e,t){void 0!==e.barycenter?(e.barycenter=(e.barycenter*e.weight+t.barycenter*t.weight)/(e.weight+t.weight),e.weight+=t.weight):(e.barycenter=t.barycenter,e.weight=t.weight)}(r,n)}});let g=n(f,s);!function(e,t){e.forEach(e=>{e.vs=e.vs.flatMap(e=>t[e]?t[e].vs:e)})}(g,u);let p=i(g,a);if(c&&(p.vs=[c,p.vs,l].flat(!0),t.predecessors(c).length)){let e=t.node(t.predecessors(c)[0]),r=t.node(t.predecessors(l)[0]);Object.hasOwn(p,"barycenter")||(p.barycenter=0,p.weight=0),p.barycenter=(p.barycenter*p.weight+e.order+r.order)/(p.weight+2),p.weight+=2}return p}}),y=e((e,r)=>{var n=t().Graph,o=i();r.exports=function(e,t,r,i){i||(i=e.nodes());let s=function(e){for(var t;e.hasNode(t=o.uniqueId("_root")););return t}(e),a=new n({compound:!0}).setGraph({root:s}).setDefaultNodeLabel(t=>e.node(t));return i.forEach(n=>{let i=e.node(n),o=e.parent(n);(i.rank===t||i.minRank<=t&&t<=i.maxRank)&&(a.setNode(n),a.setParent(n,o||s),e[r](n).forEach(t=>{let r=t.v===n?t.w:t.v,i=a.edge(r,n),o=void 0!==i?i.weight:0;a.setEdge(r,n,{weight:e.edge(t).weight+o})}),Object.hasOwn(i,"minRank")&&a.setNode(n,{borderLeft:i.borderLeft[t],borderRight:i.borderRight[t]}))}),a}}),x=e((e,t)=>{t.exports=function(e,t,r){let n,i={};r.forEach(r=>{let o,s,a=e.parent(r);for(;a;){if(o=e.parent(a),o?(s=i[o],i[o]=a):(s=n,n=a),s&&s!==a)return void t.setEdge(s,a);a=o}})}}),_=e((e,r)=>{var n=p(),o=v(),s=E(),a=y(),h=x(),d=t().Graph,c=i();function l(e,t,r){let n=new Map,i=(e,t)=>{n.has(e)||n.set(e,[]),n.get(e).push(t)};for(let t of e.nodes()){let r=e.node(t);if("number"==typeof r.rank&&i(r.rank,t),"number"==typeof r.minRank&&"number"==typeof r.maxRank)for(let e=r.minRank;e<=r.maxRank;e++)e!==r.rank&&i(e,t)}return t.map(function(t){return a(e,t,r,n.get(t)||[])})}function u(e,t,r){let n=new d;e.forEach(function(e){r.forEach(e=>n.setEdge(e.left,e.right));let i=e.graph().root,o=s(e,i,n,t);o.vs.forEach((t,r)=>e.node(t).order=r),h(e,n,o.vs)})}function f(e,t){Object.values(t).forEach(t=>t.forEach((t,r)=>e.node(t).order=r))}r.exports=function e(t,r={}){if("function"==typeof r.customOrder)return void r.customOrder(t,e);let i=c.maxRank(t),s=l(t,c.range(1,i+1),"inEdges"),a=l(t,c.range(i-1,-1,-1),"outEdges"),h=n(t);if(f(t,h),r.disableOptimalOrderHeuristic)return;let d,g=Number.POSITIVE_INFINITY,p=r.constraints||[];for(let e=0,r=0;r<4;++e,++r){u(e%2?s:a,e%4>=2,p),h=c.buildLayerMatrix(t);let n=o(t,h);n<g?(r=0,d=Object.assign({},h),g=n):n===g&&(d=structuredClone(h))}f(t,d)}}),k=e((e,r)=>{var n=t().Graph,o=i();function s(e,t){let r={};return t.length&&t.reduce(function(t,n){let i=0,o=0,s=t.length,a=n[n.length-1];return n.forEach((t,d)=>{let c=function(e,t){if(e.node(t).dummy)return e.predecessors(t).find(t=>e.node(t).dummy)}(e,t),l=c?e.node(c).order:s;(c||t===a)&&(n.slice(o,d+1).forEach(t=>{e.predecessors(t).forEach(n=>{let o=e.node(n),s=o.order;(s<i||l<s)&&(!o.dummy||!e.node(t).dummy)&&h(r,n,t)})}),o=d+1,i=l)}),n}),r}function a(e,t){let r={};function n(t,n,i,s,a){let d;o.range(n,i).forEach(n=>{d=t[n],e.node(d).dummy&&e.predecessors(d).forEach(t=>{let n=e.node(t);n.dummy&&(n.order<s||n.order>a)&&h(r,t,d)})})}return t.length&&t.reduce(function(t,r){let i,o=-1,s=0;return r.forEach((a,h)=>{if("border"===e.node(a).dummy){let t=e.predecessors(a);t.length&&(i=e.node(t[0]).order,n(r,s,h,o,i),s=h,o=i)}n(r,s,r.length,i,t.length)}),r}),r}function h(e,t,r){if(t>r){let e=t;t=r,r=e}let n=e[t];n||(e[t]=n={}),n[r]=!0}function d(e,t,r){if(t>r){let e=t;t=r,r=e}return!!e[t]&&Object.hasOwn(e[t],r)}function c(e,t,r,n){let i={},o={},s={};return t.forEach(e=>{e.forEach((e,t)=>{i[e]=e,o[e]=e,s[e]=t})}),t.forEach(e=>{let t=-1;e.forEach(e=>{let a=n(e);if(a.length){a=a.sort((e,t)=>s[e]-s[t]);let n=(a.length-1)/2;for(let h=Math.floor(n),c=Math.ceil(n);h<=c;++h){let n=a[h];o[e]===e&&t<s[n]&&!d(r,e,n)&&(o[n]=e,o[e]=i[e]=i[n],t=s[n])}}})}),{root:i,align:o}}function l(e,t,r,i,o){let s={},a=function(e,t,r,i){let o=new n,s=e.graph(),a=function(e,t,r){return(n,i,o)=>{let s,a=n.node(i),h=n.node(o),d=0;if(d+=a.width/2,Object.hasOwn(a,"labelpos"))switch(a.labelpos.toLowerCase()){case"l":s=-a.width/2;break;case"r":s=a.width/2}if(s&&(d+=r?s:-s),s=0,d+=(a.dummy?t:e)/2,d+=(h.dummy?t:e)/2,d+=h.width/2,Object.hasOwn(h,"labelpos"))switch(h.labelpos.toLowerCase()){case"l":s=h.width/2;break;case"r":s=-h.width/2}return s&&(d+=r?s:-s),s=0,d}}(s.nodesep,s.edgesep,i);return t.forEach(t=>{let n;t.forEach(t=>{let i=r[t];if(o.setNode(i),n){var s=r[n],h=o.edge(s,i);o.setEdge(s,i,Math.max(a(e,t,n),h||0))}n=t})}),o}(e,t,r,o),h=o?"borderLeft":"borderRight";function d(e,t){let r=a.nodes().slice(),n={},i=r.pop();for(;i;){if(n[i])e(i);else{n[i]=!0,r.push(i);for(let e of t(i))r.push(e)}i=r.pop()}}return d(function(e){s[e]=a.inEdges(e).reduce((e,t)=>Math.max(e,s[t.v]+a.edge(t)),0)},a.predecessors.bind(a)),d(function(t){let r=a.outEdges(t).reduce((e,t)=>Math.min(e,s[t.w]-a.edge(t)),Number.POSITIVE_INFINITY),n=e.node(t);r!==Number.POSITIVE_INFINITY&&n.borderType!==h&&(s[t]=Math.max(s[t],r))},a.successors.bind(a)),Object.keys(i).forEach(e=>s[e]=s[r[e]]),s}function u(e,t){return Object.values(t).reduce((t,r)=>{let n=Number.NEGATIVE_INFINITY,i=Number.POSITIVE_INFINITY;Object.entries(r).forEach(([t,r])=>{let o=function(e,t){return e.node(t).width}(e,t)/2;n=Math.max(r+o,n),i=Math.min(r-o,i)});let o=n-i;return o<t[0]&&(t=[o,r]),t},[Number.POSITIVE_INFINITY,null])[1]}function f(e,t){let r=Object.values(t),n=o.applyWithChunking(Math.min,r),i=o.applyWithChunking(Math.max,r);["u","d"].forEach(r=>{["l","r"].forEach(s=>{let a=r+s,h=e[a];if(h===t)return;let d=Object.values(h),c=n-o.applyWithChunking(Math.min,d);"l"!==s&&(c=i-o.applyWithChunking(Math.max,d)),c&&(e[a]=o.mapValues(h,e=>e+c))})})}function g(e,t){return o.mapValues(e.ul,(r,n)=>{if(t)return e[t.toLowerCase()][n];{let t=Object.values(e).map(e=>e[n]).sort((e,t)=>e-t);return(t[1]+t[2])/2}})}r.exports={positionX:function(e){let t,r=o.buildLayerMatrix(e),n=Object.assign(s(e,r),a(e,r)),i={};["u","d"].forEach(s=>{t="u"===s?r:Object.values(r).reverse(),["l","r"].forEach(r=>{"r"===r&&(t=t.map(e=>Object.values(e).reverse()));let a=("u"===s?e.predecessors:e.successors).bind(e),h=c(e,t,n,a),d=l(e,t,h.root,h.align,"r"===r);"r"===r&&(d=o.mapValues(d,e=>-e)),i[s+r]=d})});let h=u(e,i);return f(i,h),g(i,e.graph().align)},findType1Conflicts:s,findType2Conflicts:a,addConflict:h,hasConflict:d,verticalAlignment:c,horizontalCompaction:l,alignCoordinates:f,findSmallestWidthAlignment:u,balance:g}}),O=e((e,t)=>{var r=i(),n=k().positionX;t.exports=function(e){(function(e){let t=r.buildLayerMatrix(e),n=e.graph().ranksep,i=e.graph().rankalign,o=0;t.forEach(t=>{let r=t.reduce((t,r)=>{let n=e.node(r).height;return t>n?t:n},0);t.forEach(t=>{let n=e.node(t);n.y="top"===i?o+n.height/2:"bottom"===i?o+r-n.height/2:o+r/2}),o+=r+n})})(e=r.asNonCompoundGraph(e)),Object.entries(n(e)).forEach(([t,r])=>e.node(t).x=r)}}),N=e((e,r)=>{var n=o(),a=s(),h=c(),d=i().normalizeRanks,p=l(),v=i().removeEmptyRanks,m=u(),w=f(),b=g(),E=_(),y=O(),x=i(),k=t().Graph;r.exports=function(e,t={}){let r=t.debugTiming?x.time:x.notime;return r("layout",()=>{let i=r(" buildLayoutGraph",()=>function(e){let t=new k({multigraph:!0,compound:!0}),r=P(e.graph());return t.setGraph(Object.assign({},I,R(r,N),x.pick(r,M))),e.nodes().forEach(r=>{let n=R(P(e.node(r)),j);Object.keys(C).forEach(e=>{void 0===n[e]&&(n[e]=C[e])}),t.setNode(r,n),t.setParent(r,e.parent(r))}),e.edges().forEach(r=>{let n=P(e.edge(r));t.setEdge(r,Object.assign({},T,R(n,L),x.pick(n,S)))}),t}(e));return r(" runLayout",()=>function(e,t,r){t(" makeSpaceForEdgeLabels",()=>function(e){let t=e.graph();t.ranksep/=2,e.edges().forEach(r=>{let n=e.edge(r);n.minlen*=2,"c"!==n.labelpos.toLowerCase()&&("TB"===t.rankdir||"BT"===t.rankdir?n.width+=n.labeloffset:n.height+=n.labeloffset)})}(e)),t(" removeSelfEdges",()=>function(e){e.edges().forEach(t=>{if(t.v===t.w){var r=e.node(t.v);r.selfEdges||(r.selfEdges=[]),r.selfEdges.push({e:t,label:e.edge(t)}),e.removeEdge(t)}})}(e)),t(" acyclic",()=>n.run(e)),t(" nestingGraph.run",()=>m.run(e)),t(" rank",()=>h(x.asNonCompoundGraph(e))),t(" injectEdgeLabelProxies",()=>function(e){e.edges().forEach(t=>{let r=e.edge(t);if(r.width&&r.height){let r=e.node(t.v),n={rank:(e.node(t.w).rank-r.rank)/2+r.rank,e:t};x.addDummyNode(e,"edge-proxy",n,"_ep")}})}(e)),t(" removeEmptyRanks",()=>v(e)),t(" nestingGraph.cleanup",()=>m.cleanup(e)),t(" normalizeRanks",()=>d(e)),t(" assignRankMinMax",()=>function(e){let t=0;e.nodes().forEach(r=>{let n=e.node(r);n.borderTop&&(n.minRank=e.node(n.borderTop).rank,n.maxRank=e.node(n.borderBottom).rank,t=Math.max(t,n.maxRank))}),e.graph().maxRank=t}(e)),t(" removeEdgeLabelProxies",()=>function(e){e.nodes().forEach(t=>{let r=e.node(t);"edge-proxy"===r.dummy&&(e.edge(r.e).labelRank=r.rank,e.removeNode(t))})}(e)),t(" normalize.run",()=>a.run(e)),t(" parentDummyChains",()=>p(e)),t(" addBorderSegments",()=>w(e)),t(" order",()=>E(e,r)),t(" insertSelfEdges",()=>function(e){var t=x.buildLayerMatrix(e);t.forEach(t=>{var r=0;t.forEach((t,n)=>{var i=e.node(t);i.order=n+r,(i.selfEdges||[]).forEach(t=>{x.addDummyNode(e,"selfedge",{width:t.label.width,height:t.label.height,rank:i.rank,order:n+ ++r,e:t.e,label:t.label},"_se")}),delete i.selfEdges})})}(e)),t(" adjustCoordinateSystem",()=>b.adjust(e)),t(" position",()=>y(e)),t(" positionSelfEdges",()=>function(e){e.nodes().forEach(t=>{var r=e.node(t);if("selfedge"===r.dummy){var n=e.node(r.e.v),i=n.x+n.width/2,o=n.y,s=r.x-i,a=n.height/2;e.setEdge(r.e,r.label),e.removeNode(t),r.label.points=[{x:i+2*s/3,y:o-a},{x:i+5*s/6,y:o-a},{x:i+s,y:o},{x:i+5*s/6,y:o+a},{x:i+2*s/3,y:o+a}],r.label.x=r.x,r.label.y=r.y}})}(e)),t(" removeBorderNodes",()=>function(e){e.nodes().forEach(t=>{if(e.children(t).length){let r=e.node(t),n=e.node(r.borderTop),i=e.node(r.borderBottom),o=e.node(r.borderLeft[r.borderLeft.length-1]),s=e.node(r.borderRight[r.borderRight.length-1]);r.width=Math.abs(s.x-o.x),r.height=Math.abs(i.y-n.y),r.x=o.x+r.width/2,r.y=n.y+r.height/2}}),e.nodes().forEach(t=>{"border"===e.node(t).dummy&&e.removeNode(t)})}(e)),t(" normalize.undo",()=>a.undo(e)),t(" fixupEdgeLabelCoords",()=>function(e){e.edges().forEach(t=>{let r=e.edge(t);if(Object.hasOwn(r,"x"))switch(("l"===r.labelpos||"r"===r.labelpos)&&(r.width-=r.labeloffset),r.labelpos){case"l":r.x-=r.width/2+r.labeloffset;break;case"r":r.x+=r.width/2+r.labeloffset}})}(e)),t(" undoCoordinateSystem",()=>b.undo(e)),t(" translateGraph",()=>function(e){let t=Number.POSITIVE_INFINITY,r=0,n=Number.POSITIVE_INFINITY,i=0,o=e.graph(),s=o.marginx||0,a=o.marginy||0;function h(e){let o=e.x,s=e.y,a=e.width,h=e.height;t=Math.min(t,o-a/2),r=Math.max(r,o+a/2),n=Math.min(n,s-h/2),i=Math.max(i,s+h/2)}e.nodes().forEach(t=>h(e.node(t))),e.edges().forEach(t=>{let r=e.edge(t);Object.hasOwn(r,"x")&&h(r)}),t-=s,n-=a,e.nodes().forEach(r=>{let i=e.node(r);i.x-=t,i.y-=n}),e.edges().forEach(r=>{let i=e.edge(r);i.points.forEach(e=>{e.x-=t,e.y-=n}),Object.hasOwn(i,"x")&&(i.x-=t),Object.hasOwn(i,"y")&&(i.y-=n)}),o.width=r-t+s,o.height=i-n+a}(e)),t(" assignNodeIntersects",()=>function(e){e.edges().forEach(t=>{let r,n,i=e.edge(t),o=e.node(t.v),s=e.node(t.w);i.points?(r=i.points[0],n=i.points[i.points.length-1]):(i.points=[],r=s,n=o),i.points.unshift(x.intersectRect(o,r)),i.points.push(x.intersectRect(s,n))})}(e)),t(" reversePoints",()=>function(e){e.edges().forEach(t=>{let r=e.edge(t);r.reversed&&r.points.reverse()})}(e)),t(" acyclic.undo",()=>n.undo(e))}(i,r,t)),r(" updateInputGraph",()=>function(e,t){e.nodes().forEach(r=>{let n=e.node(r),i=t.node(r);n&&(n.x=i.x,n.y=i.y,n.order=i.order,n.rank=i.rank,t.children(r).length&&(n.width=i.width,n.height=i.height))}),e.edges().forEach(r=>{let n=e.edge(r),i=t.edge(r);n.points=i.points,Object.hasOwn(i,"x")&&(n.x=i.x,n.y=i.y)}),e.graph().width=t.graph().width,e.graph().height=t.graph().height}(e,i)),i})};var N=["nodesep","edgesep","ranksep","marginx","marginy"],I={ranksep:50,edgesep:20,nodesep:50,rankdir:"tb",rankalign:"center"},M=["acyclicer","ranker","rankdir","align","rankalign"],j=["width","height","rank"],C={width:0,height:0},L=["minlen","weight","width","height","labeloffset"],T={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},S=["labelpos"];function R(e,t){return x.mapValues(x.pick(e,t),Number)}function P(e){var t={};return e&&Object.entries(e).forEach(([e,r])=>{"string"==typeof e&&(e=e.toLowerCase()),t[e]=r}),t}}),I=e((e,r)=>{var n=i(),o=t().Graph;r.exports={debugOrdering:function(e){let t=n.buildLayerMatrix(e),r=new o({compound:!0,multigraph:!0}).setGraph({});return e.nodes().forEach(t=>{r.setNode(t,{label:t}),r.setParent(t,"layer"+e.node(t).rank)}),e.edges().forEach(e=>r.setEdge(e.v,e.w,{},e.name)),t.forEach((e,t)=>{let n="layer"+t;r.setNode(n,{rank:"same"}),e.reduce((e,t)=>(r.setEdge(e,t,{style:"invis"}),t))}),r}}}),M=e((e,t)=>{t.exports="2.0.4"}),j=e((e,r)=>{r.exports={graphlib:t(),layout:N(),debug:I(),util:{time:i().time,notime:i().notime},version:M()}})();function C(e,t,r){if(t.has(e))return e;const n=r.get(e);return n?C(n,t,r):null}function L(e,t,r,n,i,o){const s=new j.graphlib.Graph({multigraph:!0});s.setGraph({rankdir:"TB",nodesep:30,ranksep:50,marginx:20,marginy:36}),s.setDefaultEdgeLabel(()=>({}));const a=new Map;e.forEach(e=>{if(i.has(e)){const h=L(n.get(e),t,r,n,i,o);a.set(e,h),s.setNode(e,{width:h.width,height:h.height})}else{const r=t.get(e);s.setNode(e,{width:r.width,height:r.height})}}),r.forEach((t,r)=>{const n=C(t.sources[0],e,o),i=C(t.targets[0],e,o);n&&i&&n!==i&&s.setEdge(n,i,{},r)}),j.layout(s);const h=[];e.forEach(e=>{const t=s.node(e);if(!t)return;const r={id:e,x:t.x-t.width/2,y:t.y-t.height/2,width:t.width,height:t.height};a.has(e)&&(r.children=a.get(e).children),h.push(r)});const d=s.graph();return{children:h,width:(d.width||0)+40,height:(d.height||0)+36+20}}async function T({nodeMap:e,edgeMap:t,containerChildren:r,containerIds:n,childOf:i,topLevelContainerIds:o}){const s=new j.graphlib.Graph({multigraph:!0});s.setGraph({rankdir:"TB",nodesep:50,ranksep:80}),s.setDefaultEdgeLabel(()=>({}));const a=new Map;function h(e){const t=i.get(e);return t?h(t):e}o.forEach(o=>{const h=L(r.get(o),e,t,r,n,i);a.set(o,h),s.setNode(o,{width:h.width,height:h.height})}),e.forEach((e,t)=>{n.has(t)||i.has(t)||s.setNode(t,{width:e.width,height:e.height})}),t.forEach((e,t)=>{const r=h(e.sources[0]),n=h(e.targets[0]);r!==n&&s.hasNode(r)&&s.hasNode(n)&&s.setEdge(r,n,{},t)}),j.layout(s);const d=[];return s.nodes().forEach(e=>{const t=s.node(e),r={id:e,x:t.x-t.width/2,y:t.y-t.height/2,width:t.width,height:t.height};a.has(e)&&(r.children=a.get(e).children),d.push(r)}),{id:"root",children:d}}const S="http://www.w3.org/2000/svg",R={block:{fill:"#ffffff",stroke:"#2c7be5",strokeWidth:1.5,headBar:"#2c7be5",headText:"#ffffff",anchor:"#2c7be5",neckAnchor:"#e67e22"},group:{fill:"#eff6ff",stroke:"#1d4ed8",strokeWidth:2.5,headBar:"#1d4ed8",headText:"#ffffff",anchor:"#1d4ed8",neckAnchor:"#e67e22"},neck:{fill:"#fff7f0",stroke:"#e67e22",strokeWidth:1.5,headBar:"#c0571a",headText:"#ffffff",anchor:"#e67e22",neckAnchor:"#e67e22"}},P={regular:{stroke:"#2c7be5",dasharray:"none",width:1.5},neck:{stroke:"#e67e22",dasharray:"6,3",width:1.5},pic:{stroke:"#16a34a",dasharray:"4,3",width:1.5}};function D(e,t={},r=null){const n=document.createElementNS(S,e);return Object.entries(t).forEach(([e,t])=>n.setAttribute(e,t)),r&&r.appendChild(n),n}function F(e,t,r,n){(e||[]).forEach(e=>{const i=t+e.x,o=r+e.y;n.set(e.id,{x:i,y:o,w:e.width,h:e.height}),e.children&&F(e.children,i,o,n)})}function G(e,t,r,n){"logical-group"===t.type||t.type;const i=r?"neck"===n||"pic"===n?8:-8:"pic"===n?8:-8,o=e.x+e.w/2+i;return r?{x:o,y:e.y+e.h}:{x:o,y:e.y}}const $={regular:{src:30,tgt:10},neck:{src:10,tgt:10},pic:{src:10,tgt:20}};function V(e,t,r){D("path",{d:e.map((e,t)=>`${0===t?"M":"L"}${e.x},${e.y}`).join(" "),fill:"none",stroke:t.stroke,"stroke-width":t.width,"stroke-dasharray":t.dasharray,"stroke-linecap":"round","stroke-linejoin":"round"},r)}function z(e,t,r,n){const i=180*Math.atan2(e.y-t.y,e.x-t.x)/Math.PI;D("polygon",{points:"0,-4 8,0 0,4",fill:r.stroke,transform:`translate(${e.x},${e.y}) rotate(${i})`},n)}function A(e,t,r,n,i,o){(e||[]).forEach(e=>{const s=t+e.x,a=r+e.y,h=n.get(e.id)||{};if("logical-group"===h.type){const t=D("g",{transform:`translate(${s},${a})`},o);D("rect",{x:0,y:0,width:e.width,height:e.height,rx:8,ry:8,fill:"#f0f7ff",stroke:"#93c5fd","stroke-width":1.5,"stroke-dasharray":"8,4"},t),h.label&&h.label.trim()&&(D("text",{x:12,y:18,"text-anchor":"start","dominant-baseline":"middle","font-family":"sans-serif","font-size":"10","font-weight":"700",fill:"#3b82f6","letter-spacing":"1"},t).textContent=h.label.toUpperCase()),D("circle",{cx:e.width/2-8,cy:0,r:3,fill:"#2c7be5"},t),D("circle",{cx:e.width/2+8,cy:0,r:3,fill:"#16a34a"},t),A(e.children,s,a,n,i,o)}if("group"===h.type){const t=D("g",{transform:`translate(${s},${a})`},o);D("rect",{x:0,y:0,width:e.width,height:e.height,rx:8,ry:8,fill:"#eff6ff",stroke:"#1d4ed8","stroke-width":1.5,"stroke-dasharray":"6,3"},t),h.label&&h.label.trim()&&(D("text",{x:12,y:18,"text-anchor":"start","dominant-baseline":"middle","font-family":"sans-serif","font-size":"10","font-weight":"700",fill:"#1d4ed8","letter-spacing":"1"},t).textContent=h.label.toUpperCase()),D("circle",{cx:e.width/2-8,cy:0,r:3,fill:"#1d4ed8"},t),D("circle",{cx:e.width/2+8,cy:0,r:3,fill:"#16a34a"},t),A(e.children,s,a,n,i,o)}})}function Y(e,t,r,n,i,o){(e||[]).forEach(e=>{const s=t+e.x,a=r+e.y,h=n.get(e.id)||{};if("logical-group"===h.type||"group"===h.type){const t=function(e,t){return e.head&&t.has(e.head)?e.head:e.role&&t.has(e.role)?e.role:null}(h,n);Y(e.children,s,a,n,i,t)}else{!function(e,t,r,n,i,o){const s=r.type||"block",a=R[s]||R.block,{width:h,height:d}=n,c=D("g",{class:`sto-node sto-node--${s}${i?" sto-node--head":""}`,"data-id":n.id,transform:`translate(${e},${t})`},o);if(D("rect",{x:2,y:2,width:h,height:d,rx:5,ry:5,fill:"rgba(0,0,0,0.07)",stroke:"none"},c),D("rect",{x:0,y:0,width:h,height:d,rx:5,ry:5,fill:a.fill,stroke:a.stroke,"stroke-width":a.strokeWidth,"stroke-dasharray":"neck"===s?"6,3":"none"},c),"group"===s){const e=`clip-grp-${n.id}`,t=D("defs",{},c),r=document.createElementNS(S,"clipPath");r.setAttribute("id",e),D("rect",{x:0,y:0,width:h,height:d,rx:5,ry:5},r),t.appendChild(r),D("rect",{x:0,y:0,width:5,height:d,fill:a.stroke,"clip-path":`url(#${e})`},c)}if(i){const e=`clip-head-${n.id}`,t=D("defs",{},c),r=document.createElementNS(S,"clipPath");r.setAttribute("id",e),D("rect",{x:0,y:0,width:h,height:d,rx:5,ry:5},r),t.appendChild(r),D("rect",{x:0,y:0,width:h,height:16,fill:a.headBar,"clip-path":`url(#${e})`},c),D("text",{x:h/2,y:8,"text-anchor":"middle","dominant-baseline":"middle","font-family":"sans-serif","font-size":"9","font-weight":"700",fill:a.headText,"letter-spacing":"0.8"},c).textContent="HEAD"}const l=i?16:0,u=d-l,f="group"===s?5+(h-5)/2:h/2;if(r.html){const e="group"===s?21:16,t=10,n=D("foreignObject",{x:e,y:l+t,width:Math.max(h-e-8,1),height:Math.max(u-2*t,1)},c),i=document.createElementNS("http://www.w3.org/1999/xhtml","div");i.innerHTML=r.html,i.style.cssText="width:100%;height:100%;overflow:hidden;font-size:12px;font-family:sans-serif;box-sizing:border-box;",n.appendChild(i)}else D("text",{x:f,y:l+u/2,"text-anchor":"middle","dominant-baseline":"middle","font-family":"sans-serif","font-size":"12","font-weight":i||"group"===s?"700":"400",fill:"group"===s?a.stroke:"#1a1a1a"},c).textContent=r.label||n.id;D("circle",{cx:h/2-8,cy:0,r:3,fill:a.anchor},c),D("circle",{cx:h/2+8,cy:0,r:3,fill:"#16a34a"},c),D("circle",{cx:h/2-8,cy:d,r:3,fill:a.anchor},c),D("circle",{cx:h/2+8,cy:d,r:3,fill:a.neckAnchor},c)}(s,a,h,e,e.id===o||"head"===h.role,i)}})}function B(e,t,r,n){for(;n.firstChild;)n.removeChild(n.firstChild);const i=D("g",{class:"sto-root"},n),o=D("g",{class:"sto-bg"},i),s=D("g",{class:"sto-edges"},i),a=D("g",{class:"sto-nodes"},i),h=new Map;F(e.children,0,0,h),A(e.children,0,0,t,h,o);const d=new Map;r.forEach(e=>{const t=`${e.sources[0]}::${e.type}`;d.has(t)||d.set(t,[]),d.get(t).push(e)});const c=new Map,l=new Map;return d.forEach((e,r)=>{if(e.length>1)return;const n=e[0].sources[0],i=h.get(n);if(!i)return;const{src:o}=$[e[0].type]||$.regular,s=G(i,t.get(n)||{},!0,e[0].type),a=`${Math.round(s.y+o)}::${e[0].type}`;l.has(a)||l.set(a,[]),l.get(a).push({key:r,srcX:s.x})}),l.forEach(e=>{e.length<2||(e.sort((e,t)=>e.srcX-t.srcX),e.forEach(({key:e},t)=>c.set(e,15*t)))}),d.forEach((e,r)=>function(e,t,r,n,i=0){if(!e.length)return;const o=e[0].type,s=P[o]||P.regular,{src:a,tgt:h}=$[o]||$.regular,d=e[0].sources[0],c=r.get(d);if(!c)return;const l=G(c,t.get(d)||{},!0,o),u=l.y+a+i,f=e.flatMap(e=>{const n=r.get(e.targets[0]);return n?[G(n,t.get(e.targets[0])||{},!1,o)]:[]});if(!f.length)return;const g=[l.x,...f.map(e=>e.x)],p=Math.min(...g),v=Math.max(...g);V([l,{x:l.x,y:u}],s,n),v>p&&V([{x:p,y:u},{x:v,y:u}],s,n),f.forEach(e=>{const t=e.y-h;t>u?(V([{x:e.x,y:u},{x:e.x,y:t},e],s,n),z(e,{x:e.x,y:t},s,n)):(V([{x:e.x,y:u},e],s,n),z(e,{x:e.x,y:u},s,n))})}(e,t,h,s,c.get(r)||0)),Y(e.children,0,0,t,a,null),i}class W{constructor(e,t={}){this._container="string"==typeof e?document.querySelector(e):e,this._options={zoom:!0,pan:!0,cardWidth:200,cardHeight:80,...t},this._data=[],this._users=[],this._template=null,this._svg=null,this._root=null,this._initSvg()}_initSvg(){this._svg=document.createElementNS("http://www.w3.org/2000/svg","svg"),this._svg.setAttribute("width","100%"),this._svg.setAttribute("height","100%"),this._svg.style.display="block",this._container.appendChild(this._svg)}load(e){return this._data=e,this}assign(e,t,r={}){return this._users=e||[],this._template=t||"",this._cardSize={width:r.width||this._options.cardWidth,height:r.height||this._options.cardHeight},this}_applyUsers(e){if(!this._users.length||!this._template)return e;const t=new Map(this._users.map(e=>[e.stoid,e]));return e.map(e=>{const r=t.get(e.id);if(!r)return e;const n=this._template.replace(/\{(\w+)\}/g,(e,t)=>{const n=r[t];return null!=n?String(n):""});return{...e,html:n,width:e.width||this._cardSize.width,height:e.height||this._cardSize.height}})}async render(){const e=this._applyUsers(this._data),t=function(e){const t=new Map(e.map(e=>[e.id,{...e,width:e.width||160,height:e.height||60}])),r=new Map,n=new Set(e.filter(e=>"group"===e.type||"logical-group"===e.type).map(e=>e.id)),i=new Map;n.forEach(e=>i.set(e,new Set)),e.forEach(e=>{if(e.groupId&&i.has(e.groupId)&&i.get(e.groupId).add(e.id),e.parentId&&i.has(e.parentId)){const r=t.get(e.parentId);"group"===r?.type&&i.get(e.parentId).add(e.id)}});const o=new Map;i.forEach((e,t)=>{e.forEach(e=>o.set(e,t))});let s=!0;for(;s;)s=!1,e.forEach(e=>{if(!e.parentId||o.has(e.id)||n.has(e.id))return;const r=o.get(e.parentId);r&&"group"===t.get(r)?.type&&(i.get(r).add(e.id),o.set(e.id,r),s=!0)});e.forEach(e=>{if(e.parentId&&!(o.get(e.id)===e.parentId||e.groupId&&e.groupId===e.parentId)){const t=`e_${e.parentId}_${e.id}`;r.set(t,{id:t,sources:[e.parentId],targets:[e.id],type:e.edge||"regular"})}if(e.picId){const t=`epic_${e.picId}_${e.id}`;r.set(t,{id:t,sources:[e.picId],targets:[e.id],type:"pic"})}});const a=[...n].filter(e=>!o.has(e));return{nodeMap:t,edgeMap:r,containerChildren:i,childOf:o,containerIds:n,topLevelContainerIds:a}}(await async function(e){const t=e.filter(e=>e.html&&(!e.width||!e.height));if(0===t.length)return e;const r=document.createElement("div");r.style.cssText=["position:absolute","top:-99999px","left:-99999px","visibility:hidden","pointer-events:none","display:flex","flex-direction:column","gap:0"].join(";"),document.body.appendChild(r);const n=t.map(e=>{const t=document.createElement("div"),n=e.maxWidth||280;return t.style.cssText=`display:inline-block;max-width:${n}px;font-size:12px;font-family:sans-serif;box-sizing:border-box;`,t.innerHTML=e.html,r.appendChild(t),{node:e,div:t}});await new Promise(e=>requestAnimationFrame(e));const i=new Map;return n.forEach(({node:e,div:t})=>{const r=t.getBoundingClientRect(),n="head"===e.role?16:0;i.set(e.id,{width:Math.max(Math.ceil(r.width)+32,e.width||160),height:Math.max(Math.ceil(r.height)+20+n,e.height||60)})}),document.body.removeChild(r),e.map(e=>{const t=i.get(e.id);return t?{...e,...t}:e})}(e)),r=await T(t);return this._root=B(r,t.nodeMap,t.edgeMap,this._svg),(this._options.zoom||this._options.pan)&&function(e,t){let r=!1,n=0,i=0,o=0,s=0,a=1;function h(){t.setAttribute("transform",`translate(${o},${s}) scale(${a})`)}e.addEventListener("wheel",t=>{t.preventDefault();const r=t.deltaY>0?.9:1.1,n=Math.min(4,Math.max(.1,a*r)),i=n/a,d=e.getBoundingClientRect(),c=t.clientX-d.left,l=t.clientY-d.top;o=c-i*(c-o),s=l-i*(l-s),a=n,h()},{passive:!1}),e.addEventListener("mousedown",t=>{0===t.button&&(r=!0,n=t.clientX-o,i=t.clientY-s,e.style.cursor="grabbing")}),window.addEventListener("mousemove",e=>{r&&(o=e.clientX-n,s=e.clientY-i,h())}),window.addEventListener("mouseup",()=>{r&&(r=!1,e.style.cursor="grab")});let d=null;e.addEventListener("touchstart",e=>{1===e.touches.length&&(r=!0,n=e.touches[0].clientX-o,i=e.touches[0].clientY-s)},{passive:!0}),e.addEventListener("touchmove",e=>{if(1===e.touches.length&&r)o=e.touches[0].clientX-n,s=e.touches[0].clientY-i,h();else if(2===e.touches.length){const t=e.touches[0].clientX-e.touches[1].clientX,r=e.touches[0].clientY-e.touches[1].clientY,n=Math.sqrt(t*t+r*r);if(null!==d){const e=n/d;a=Math.min(4,Math.max(.1,a*e)),h()}d=n}},{passive:!0}),e.addEventListener("touchend",()=>{r=!1,d=null},{passive:!0}),e.style.cursor="grab"}(this._svg,this._root),this._fitView(r),this}_fitView(e){let t=1/0,r=1/0,n=-1/0,i=-1/0;if(function e(o,s=0,a=0){(o||[]).forEach(o=>{const h=s+o.x,d=a+o.y;t=Math.min(t,h),r=Math.min(r,d),n=Math.max(n,h+o.width),i=Math.max(i,d+o.height),o.children&&o.children.length&&e(o.children,h,d)})}(e.children),t===1/0)return;const o=n-t+80,s=i-r+80,a=this._container.clientWidth||800,h=this._container.clientHeight||600,d=Math.min(a/o,h/s,1),c=(a-o*d)/2-t*d+40*d,l=(h-s*d)/2-r*d+40*d;this._root.setAttribute("transform",`translate(${c},${l}) scale(${d})`)}}export{W as StoChart,W as default};
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@ak-sara/sto-diagram",
3
+ "version": "0.1.0",
4
+ "publishConfig": { "access": "public" },
5
+ "description": "SVG block/hierarchy diagram renderer for org structures",
6
+ "license": "MIT",
7
+ "files": [
8
+ "dist"
9
+ ],
10
+ "main": "dist/sto-diagram.ak-sara.js",
11
+ "module": "dist/sto-diagram.js",
12
+ "exports": {
13
+ ".": {
14
+ "import": "./dist/sto-diagram.js",
15
+ "require": "./dist/sto-diagram.ak-sara.js"
16
+ }
17
+ },
18
+ "scripts": {
19
+ "build": "rollup -c",
20
+ "dev": "rollup -c --watch"
21
+ },
22
+ "dependencies": {
23
+ "@dagrejs/dagre": "^2.0.4"
24
+ },
25
+ "type": "module",
26
+ "devDependencies": {
27
+ "@rollup/plugin-commonjs": "^25.0.0",
28
+ "@rollup/plugin-node-resolve": "^15.0.0",
29
+ "@rollup/plugin-terser": "^1.0.0",
30
+ "rollup": "^4.0.0"
31
+ }
32
+ }