ggn-layout 0.1.0 → 0.1.2

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.
Files changed (58) hide show
  1. package/CHANGELOG.md +110 -0
  2. package/LICENSE +15 -0
  3. package/README.md +17 -5
  4. package/THIRD_PARTY_NOTICES.md +35 -3
  5. package/dist/{algorithms-CNhihjzf.js → algorithms-JOaPA3B9.js} +11 -0
  6. package/dist/{algorithms-DXUI06fi.cjs → algorithms-X6GKNYEw.cjs} +11 -0
  7. package/dist/api/index.cjs +12 -1
  8. package/dist/api/index.d.cts +14 -3
  9. package/dist/api/index.d.ts +14 -3
  10. package/dist/api/index.js +12 -1
  11. package/dist/api/layered.cjs +12 -1
  12. package/dist/api/layered.d.cts +13 -2
  13. package/dist/api/layered.d.ts +13 -2
  14. package/dist/api/layered.js +12 -1
  15. package/dist/{api-BRaDa6RG.js → api-D4FVITVw.js} +12 -1
  16. package/dist/{api-DWBi7ngO.cjs → api-DTHTxaol.cjs} +12 -1
  17. package/dist/{internal-BOuvVTiR.d.cts → core-DWo6Sbh9.d.ts} +13 -2
  18. package/dist/{internal-Coxrnk9C.d.ts → core-Or66h-Jn.d.cts} +13 -2
  19. package/dist/{internal.cjs → core.cjs} +12 -1
  20. package/dist/{internal.d.ts → core.d.cts} +14 -3
  21. package/dist/{internal.d.cts → core.d.ts} +14 -3
  22. package/dist/{internal.js → core.js} +12 -1
  23. package/dist/{elk-json-ibWtLFj2.d.cts → elk-json-BiUIDEHd.d.cts} +11 -0
  24. package/dist/{elk-json-ibWtLFj2.d.ts → elk-json-BiUIDEHd.d.ts} +11 -0
  25. package/dist/{elk-json-BtGnwuQE.cjs → elk-json-BqpJCr7A.cjs} +12 -1
  26. package/dist/{elk-json-B9eLYtu6.js → elk-json-Dm4r-Nqy.js} +12 -1
  27. package/dist/{index-C_0jvfEV.d.ts → index-DprqHh4K.d.ts} +13 -2
  28. package/dist/{index-Dl2hrLFA.d.cts → index-DwemPNSn.d.cts} +13 -2
  29. package/dist/index.cjs +12 -1
  30. package/dist/index.d.cts +16 -5
  31. package/dist/index.d.ts +16 -5
  32. package/dist/index.js +12 -1
  33. package/dist/layered-options-CWVVspE4.d.cts +17 -0
  34. package/dist/layered-options-vH0HCu1n.d.ts +17 -0
  35. package/dist/layout-worker.cjs +12 -1
  36. package/dist/layout-worker.d.cts +12 -1
  37. package/dist/layout-worker.d.ts +12 -1
  38. package/dist/layout-worker.js +12 -1
  39. package/dist/options.cjs +12 -1
  40. package/dist/options.d.cts +13 -2
  41. package/dist/options.d.ts +13 -2
  42. package/dist/options.js +12 -1
  43. package/dist/{validate-B9vX3T2G.d.ts → validate-YGFYSdxd.d.cts} +11 -0
  44. package/dist/{validate-B9vX3T2G.d.cts → validate-YGFYSdxd.d.ts} +11 -0
  45. package/docs/API.md +1 -1
  46. package/docs/reference/elk-algorithm-catalog.md +2 -2
  47. package/docs/reference/elk-algorithm-guide.md +4 -4
  48. package/docs/reference/elk-edge-routing-investigation.md +10 -13
  49. package/docs/reference/elk-json-format.md +1 -1
  50. package/docs/reference/elk-layout-options-mechanism.md +1 -1
  51. package/docs/reference/elk-layout-options.md +4 -4
  52. package/docs/reference/elk-node-labels.md +11 -8
  53. package/docs/reference/elk-spacing-options.md +1 -1
  54. package/docs/reference/elkjs-feature-coverage.md +2 -3
  55. package/package.json +18 -9
  56. package/dist/layered-options-COPhjoOB.d.ts +0 -6
  57. package/dist/layered-options-Dm7nJC1R.d.cts +0 -6
  58. /package/{src/api → schema}/layout-input.schema.json +0 -0
@@ -1 +1,12 @@
1
- const e=require("./algorithms-DXUI06fi.cjs"),t=25214903917n,n=(1n<<48n)-1n,r=15525485;var i=class{seed;constructor(e){this.seed=Number(e==null?(BigInt(Date.now()^Math.random()*4294967295)^t)&n:(BigInt(e)^t)&n)}next(e){let t=this.seed,n=t&16777215,i=Math.floor(t/16777216),a=n*r+11,o=Math.floor(a/16777216),s=i*r+n*1502+o;return this.seed=(s&16777215)*16777216+(a&16777215),Math.floor(this.seed/2**(48-e))}nextInt(e){if((e&-e)===e)return Math.floor(e*this.next(31)/2147483648);let t,n;do t=this.next(31),n=t%e;while(t-n+(e-1)<0);return n}nextBoolean(){return this.next(1)!==0}nextFloat(){return this.next(24)/16777216}nextLong(){let e=this.next(32),t=this.next(32),n=t>=2147483648?1n:0n,r=(BigInt(e)-n<<32n)+BigInt(t);return Number(r&281474976710655n)}nextDouble(){return(this.next(26)*134217728+this.next(27))/9007199254740992}setSeed(e){this.seed=Number((BigInt(e)^t)&n)}next31(){return this.next(31)}};const a=/* @__PURE__ */ new Map;function o(e,t){a.set(e,t)}function s(e){return a.get(e)}var c=class extends e.ii{constructor(){super(),this.setProperty(e.Gn,/* @__PURE__ */ new Set)}id=0;size={x:0,y:0};padding={left:12,top:12,right:12,bottom:12};offset={x:0,y:0};layerlessNodes=[];layers=[];parentNode=null;direction=`UNDEFINED`;getSize(){return this.size}getPadding(){return this.padding}setPadding(e){this.padding={...this.padding,...e}}getActualSize(){return{x:this.size.x+this.padding.left+this.padding.right,y:this.size.y+this.padding.top+this.padding.bottom}}getOffset(){return this.offset}getLayerlessNodes(){return this.layerlessNodes}getLayers(){return this.layers}getParentNode(){return this.parentNode}setParentNode(e){this.parentNode=e}getDirection(){return this.direction}setDirection(e){this.direction=e}toNodeArray(){return this.layers.map(e=>[...e.getNodes()])}getAllNodes(){let e=this.layerlessNodes.length;for(let t of this.layers)e+=t.getNodes().length;let t=Array(e),n=0;for(let e of this.layers)for(let r of e.getNodes())t[n++]=r;for(let e of this.layerlessNodes)t[n++]=e;return t}};let l=0;var u=class extends e.ii{id=l++;getId(){return this.id}},d=class extends u{position={x:0,y:0};size={x:0,y:0};getPosition(){return this.position}getSize(){return this.size}},f=class extends d{graph=null;layer=null;type=`NORMAL`;ports=[];labels=[];nestedGraph=null;margin={left:0,top:0,right:0,bottom:0};padding={left:0,top:0,right:0,bottom:0};layerConstraint=null;inLayerConstraint=null;edgeConstraint=null;portConstraints=null;constructor(e=null){super(),this.graph=e,e&&e.getLayerlessNodes().push(this)}getGraph(){return this.graph===null&&this.layer!==null?this.layer.getGraph():this.graph}setGraph(e){this.graph=e}getLayer(){return this.layer}setLayer(e){if(this.layer!==null){let e=this.layer.getNodes(),t=e.indexOf(this);t!==-1&&e.splice(t,1)}this.layer=e,this.layer!==null&&this.layer.getNodes().push(this)}setLayerAt(e,t){if(this.layer!==null){let e=this.layer.getNodes(),t=e.indexOf(this);t!==-1&&e.splice(t,1)}this.layer=t,t.getNodes().splice(e,0,this)}getType(){return this.type}setType(e){this.type=e}getPorts(e){if(e===void 0)return this.ports;if(typeof e==`string`&&(e===`NORTH`||e===`EAST`||e===`SOUTH`||e===`WEST`))return this.ports.filter(t=>t.getSide()===e);let t=e;return t===`INPUT`?this.ports.filter(e=>e.getIncomingEdges().length>0):t===`OUTPUT`?this.ports.filter(e=>e.getOutgoingEdges().length>0):[]}getPortSideView(e){return this.ports.filter(t=>t.getSide()===e)}setPorts(e){this.ports=e}getLabels(){return this.labels}setLabels(e){this.labels=e}getNestedGraph(){return this.nestedGraph}setNestedGraph(e){this.nestedGraph=e}getMargin(){return this.margin}getPadding(){return this.padding}getLayerConstraint(){if(this.layerConstraint!==null)return this.layerConstraint;let t=this.getProperty(`org.eclipse.elk.layered.layering.layerConstraint`);if(typeof t==`string`){let n=e.Fr[t];if(n!==void 0)return n}return null}setLayerConstraint(e){this.layerConstraint=e,this.setProperty(`org.eclipse.elk.layered.layering.layerConstraint`,e)}getInLayerConstraint(){return this.inLayerConstraint}setInLayerConstraint(e){this.inLayerConstraint=e}getEdgeConstraint(){return this.edgeConstraint}setEdgeConstraint(e){this.edgeConstraint=e}getPortConstraints(){return this.portConstraints}setPortConstraints(e){this.portConstraints=e}getIndex(){return this.layer===null?-1:this.layer.getNodes().indexOf(this)}getOutgoingEdges(){let e=0;for(let t of this.ports)e+=t.getOutgoingEdges().length;let t=Array(e),n=0;for(let e of this.ports)for(let r of e.getOutgoingEdges())t[n++]=r;return t}getIncomingEdges(){let e=0;for(let t of this.ports)e+=t.getIncomingEdges().length;let t=Array(e),n=0;for(let e of this.ports)for(let r of e.getIncomingEdges())t[n++]=r;return t}getConnectedEdges(){let e=[];for(let t of this.ports)e.push(...t.getIncomingEdges(),...t.getOutgoingEdges());return e}},p=class extends d{owner=null;side=`UNDEFINED`;explicitSide=!1;anchor={x:0,y:0};explicitlySuppliedPortAnchor=!1;incomingEdges=[];outgoingEdges=[];margin={left:0,top:0,right:0,bottom:0};labels=[];getNode(){return this.owner}setNode(e){if(this.owner!==null){let e=this.owner.getPorts(),t=e.indexOf(this);t!==-1&&e.splice(t,1)}this.owner=e,this.owner!==null&&this.owner.getPorts().push(this)}getSide(){return this.side}setSide(e){this.applySideAndAnchor(e),this.explicitSide=!0}setSideInferred(e){this.applySideAndAnchor(e)}isExplicitSide(){return this.explicitSide}applySideAndAnchor(e){if(this.side=e,!this.explicitlySuppliedPortAnchor)switch(this.side){case`NORTH`:this.anchor.x=this.size.x/2,this.anchor.y=0;break;case`EAST`:this.anchor.x=this.size.x,this.anchor.y=this.size.y/2;break;case`SOUTH`:this.anchor.x=this.size.x/2,this.anchor.y=this.size.y;break;case`WEST`:this.anchor.x=0,this.anchor.y=this.size.y/2}}getAnchor(){return this.anchor}setAnchor(e){this.anchor.x=e.x,this.anchor.y=e.y}isExplicitlySuppliedPortAnchor(){return this.explicitlySuppliedPortAnchor}setExplicitlySuppliedPortAnchor(e){this.explicitlySuppliedPortAnchor=e}getAbsoluteAnchor(){let e=this.owner;return{x:e.position.x+this.position.x+this.anchor.x,y:e.position.y+this.position.y+this.anchor.y}}getIncomingEdges(){return this.incomingEdges}getOutgoingEdges(){return this.outgoingEdges}getConnectedEdges(){return[...this.incomingEdges,...this.outgoingEdges]}getConnectedPorts(){let e=[];for(let t of this.getConnectedEdges())e.push(this.otherEnd(t));return e}getPredecessorPorts(){return this.incomingEdges.map(e=>e.getSource()).filter(Boolean)}getSuccessorPorts(){return this.outgoingEdges.map(e=>e.getTarget()).filter(Boolean)}otherEnd(e){return e.getSource()===this?e.getTarget():e.getSource()}getDegree(){return this.incomingEdges.length+this.outgoingEdges.length}getNetFlow(){return this.incomingEdges.length-this.outgoingEdges.length}getMargin(){return this.margin}getLabels(){return this.labels}setLabels(e){this.labels=e}getIndex(){return this.owner===null?-1:this.owner.getPorts().indexOf(this)}},m=class extends u{source=null;target=null;bendPoints=[];labels=[];getSource(){return this.source}setSource(e){if(this.source!==null){let e=this.source.getOutgoingEdges(),t=e.indexOf(this);t!==-1&&e.splice(t,1)}this.source=e,this.source!==null&&this.source.getOutgoingEdges().push(this)}getTarget(){return this.target}setTarget(e){if(this.target!==null){let e=this.target.getIncomingEdges(),t=e.indexOf(this);t!==-1&&e.splice(t,1)}this.target=e,this.target!==null&&this.target.getIncomingEdges().push(this)}setTargetAndInsertAtIndex(e,t){if(this.target!==null){let e=this.target.getIncomingEdges(),t=e.indexOf(this);t!==-1&&e.splice(t,1)}this.target=e,this.target!==null&&this.target.getIncomingEdges().splice(t,0,this)}getBendPoints(){return this.bendPoints}getLabels(){return this.labels}isSelfLoop(){return this.source!==null&&this.target!==null&&this.source.getNode()!==null&&this.source.getNode()===this.target.getNode()}isInLayerEdge(){return this.source!==null&&this.target!==null&&!this.isSelfLoop()&&this.source.getNode().getLayer()===this.target.getNode().getLayer()}getOther(e){return this.source===e?this.target:this.target===e?this.source:null}getOtherNode(e){return this.source!==null&&this.source.getNode()===e?this.target?.getNode()??null:this.target!==null&&this.target.getNode()===e?this.source?.getNode()??null:null}reverse(t,n){this.setProperty(e.Sr,!this.getProperty(e.Sr));let r=this.source,i=this.target;this.setSource(i),this.setTarget(r),this.bendPoints.reverse();for(let e of this.labels)e.placement===`HEAD`?e.placement=`TAIL`:e.placement===`TAIL`&&(e.placement=`HEAD`)}},h=class{indeg=[];outdeg=[];mark=[];sources=[];sinks=[];random=null;process(t,n){n.begin(`Greedy cycle removal`,1);let r=t.getLayerlessNodes(),i=r.length;this.indeg=Array(i).fill(0),this.outdeg=Array(i).fill(0),this.mark=Array(i).fill(0);let a=0;for(let n of r){n.setGraph(t),n.id=a;for(let t of n.getPorts()){for(let r of t.getIncomingEdges()){if(r.getSource()!==null&&r.getSource().getNode()===n)continue;let t=r.getProperty(e.Ut);this.indeg[a]+=t>0?t+1:1}for(let r of t.getOutgoingEdges()){if(r.getTarget()!==null&&r.getTarget().getNode()===n)continue;let t=r.getProperty(e.Ut);this.outdeg[a]+=t>0?t+1:1}}this.outdeg[a]===0?this.sinks.push(n):this.indeg[a]===0&&this.sources.push(n),a++}let o=-1,s=1,c=[];for(this.random=t.getProperty(e.br);i>0;){for(;this.sinks.length>0;){let e=this.sinks.shift();this.mark[r.indexOf(e)]=o--,this.updateNeighbors(e,r),i--}for(;this.sources.length>0;){let e=this.sources.shift();this.mark[r.indexOf(e)]=s++,this.updateNeighbors(e,r),i--}if(i>0){let e=-(2**53-1);for(let t=0;t<r.length;t++)if(this.mark[t]===0){let n=this.outdeg[t]-this.indeg[t];n>=e&&(n>e&&(c.length=0,e=n),c.push(r[t]))}let t=this.chooseNodeWithMaxOutflow(c);this.mark[r.indexOf(t)]=s++,this.updateNeighbors(t,r),i--}}let l=r.length+1;for(let e=0;e<r.length;e++)this.mark[e]<0&&(this.mark[e]+=l);for(let n of r)for(let i of[...n.getPorts()])for(let a of[...i.getOutgoingEdges()]){let i=r.indexOf(a.getTarget().getNode());this.mark[r.indexOf(n)]>this.mark[i]&&(a.reverse(t,!0),t.setProperty(e.Ln,!0))}this.dispose(),n.done()}chooseNodeWithMaxOutflow(e){return e[this.random.nextInt(e.length)]}updateNeighbors(t,n){for(let r of t.getPorts())for(let i of r.getConnectedEdges()){let a=i.getSource()===r?i.getTarget():i.getSource();if(a===null)continue;let o=a.getNode();if(o===null||t===o)continue;let s=i.getProperty(e.Ut),c=s<0?0:s,l=n.indexOf(o);this.mark[l]===0&&(i.getTarget()===a?(this.indeg[l]-=c+1,this.indeg[l]<=0&&this.outdeg[l]>0&&this.sources.push(o)):(this.outdeg[l]-=c+1,this.outdeg[l]<=0&&this.indeg[l]>0&&this.sinks.push(o)))}}dispose(){this.indeg=[],this.outdeg=[],this.mark=[],this.sources=[],this.sinks=[]}};function g(t){let n=t.getGraph()?.getProperty(e.tt),r=t.getPosition();return n===`TOP_LEFT`?{x:r.x,y:r.y}:{x:r.x+t.getSize().x/2,y:r.y+t.getSize().y/2}}function _(e){let t=[];for(let n of e.getLayerlessNodes()){n.id=1;let e=g(n).x;for(let r of n.getPorts(`OUTPUT`))for(let i of r.getOutgoingEdges()){let r=i.getTarget()?.getNode();r!=null&&r!==n&&g(r).x<e&&t.push(i)}}for(let n of t)n.reverse(e,!0);t.length=0;for(let n of e.getLayerlessNodes())n.id>0&&v(n,t,e);for(let n of t)n.reverse(e,!0)}function v(e,t,n){e.id=-1;for(let r of e.getPorts(`OUTPUT`))for(let i of r.getOutgoingEdges()){let r=i.getTarget()?.getNode();r!=null&&e!==r&&(r.id<0?t.push(i):r.id>0&&v(r,t,n))}e.id=0}var y=class{firstSeparateNodes=0;lastSeparateNodes=0;computeConstraintModelOrder(t,n){let r=0;switch(t.getProperty(e.it)){case`FIRST_SEPARATE`:r=2*-n+this.firstSeparateNodes,this.firstSeparateNodes++;break;case`FIRST`:r=-n;break;case`LAST`:r=n;break;case`LAST_SEPARATE`:r=2*n+this.lastSeparateNodes,this.lastSeparateNodes++}return t.hasProperty(e.cr)&&(r+=t.getProperty(e.cr)),r}computeConstraintGroupModelOrder(t,n,r){let i=0;switch(t.getProperty(e.it)){case`FIRST_SEPARATE`:i=2*-n+this.firstSeparateNodes,this.firstSeparateNodes++;break;case`FIRST`:i=-n;break;case`LAST`:i=n;break;case`LAST_SEPARATE`:i=2*n+this.lastSeparateNodes,this.lastSeparateNodes++}if(t.hasProperty(e.cr)){let n=t.getProperty(e.w);if(n==null)throw TypeError(`Cannot invoke "java.lang.Integer.intValue()" because the return value of "org.eclipse.elk.alg.layered.graph.LGraph.getProperty(org.eclipse.elk.graph.properties.IProperty)" is null`);i+=n*r+t.getProperty(e.cr)}return i}resetInternalCounters(){this.firstSeparateNodes=0,this.lastSeparateNodes=0}};function b(t,n){n.begin(`Model order cycle breaking`,1);let r=[];if(!t.hasProperty(e.sr))throw TypeError(`NullPointerException: Cannot invoke "java.lang.Integer.intValue()" because the return value of "org.eclipse.elk.alg.layered.graph.LGraph.getProperty(org.eclipse.elk.graph.properties.IProperty)" is null`);let i=Math.max(t.getLayerlessNodes().length,t.getProperty(e.sr)),a=i*t.getProperty(e.jn),o=t.getProperty(e.b)===`ENFORCED`;for(let e of t.getLayerlessNodes()){let t=new y,n=o?t.computeConstraintGroupModelOrder(e,a,i):t.computeConstraintModelOrder(e,i);for(let s of e.getPorts(`OUTPUT`))for(let e of s.getOutgoingEdges()){let s=e.getTarget().getNode();(o?t.computeConstraintGroupModelOrder(s,a,i):t.computeConstraintModelOrder(s,i))<n&&r.push(e)}}for(let n of r)n.reverse(t,!0),t.setProperty(e.Ln,!0);n.done()}var x=class extends h{layeredGraph;process(e,t){this.layeredGraph=e,super.process(e,t)}chooseNodeWithMaxOutflow(t){let n=null,r=2**53-1,i=Math.max(this.layeredGraph.getLayerlessNodes().length,this.layeredGraph.getProperty(e.sr)),a=i*this.layeredGraph.getProperty(e.jn),o=new y,s=this.layeredGraph.getProperty(e.b)===`ENFORCED`;for(let c of t)if(c.hasProperty(e.cr)){let e=s?o.computeConstraintGroupModelOrder(c,a,i):o.computeConstraintModelOrder(c,i);r>e&&(r=e,n=c)}return n===null?t[this.layeredGraph.getProperty(e.br).nextInt(t.length)]:n}},S=class{process(e){let t=this.handleOuterNodes(e);this.handleInnerNodes(e,t)}handleOuterNodes(e){let t=[];for(let n of e.getLayerlessNodes())this.handleLayerConstraintNode(e,n)||t.push(n);return t}handleInnerNodes(t,n){for(let r of n)if(this.handleLayerConstraintNode(t,r),e.Lr.isSideFixed(r.getProperty(e.Lt))&&r.getPorts().length>0){let e=!0;for(let t of r.getPorts()){let n=t.getSide(),r=t.getNetFlow();if(!(n===`EAST`&&r>0||n===`WEST`&&r<0)){e=!1;break}for(let n of t.getOutgoingEdges()){let t=n.getTarget()?.getNode()?.getLayerConstraint();if(t===`LAST`||t===`LAST_SEPARATE`){e=!1;break}}if(!e)break;for(let n of t.getIncomingEdges()){let t=n.getSource()?.getNode()?.getLayerConstraint();if(t===`FIRST`||t===`FIRST_SEPARATE`){e=!1;break}}if(!e)break}e&&this.reverseEdges(t,r,`NONE`,`UNDEFINED`)}}handleLayerConstraintNode(t,n){let r=n.getLayerConstraint(),i=null;switch(r){case`FIRST`:case`FIRST_SEPARATE`:i=`OUTGOING_ONLY`;break;case`LAST`:case`LAST_SEPARATE`:i=`INCOMING_ONLY`}return i!==null&&(n.setProperty(e.L,`OUTGOING_ONLY`),i===`INCOMING_ONLY`?this.reverseEdges(t,n,r,`INPUT`):this.reverseEdges(t,n,r,`OUTPUT`),!0)}reverseEdges(e,t,n,r){for(let i of[...t.getPorts()]){if(r===`INPUT`||r===`UNDEFINED`)for(let t of[...i.getOutgoingEdges()])this.canReverseOutgoingEdge(n,t)&&t.reverse(e,!0);if(r===`OUTPUT`||r===`UNDEFINED`)for(let t of[...i.getIncomingEdges()])this.canReverseIncomingEdge(n,t)&&t.reverse(e,!0)}}canReverseOutgoingEdge(t,n){if(n.getProperty(e.Sr))return!1;let r=n.getTarget()?.getNode();return!(r==null||t===`LAST`&&r.getType()===`LABEL`||r.getLayerConstraint()===`LAST_SEPARATE`)}canReverseIncomingEdge(t,n){if(n.getProperty(e.Sr))return!1;let r=n.getSource()?.getNode();return!(r==null||t===`FIRST`&&r.getType()===`LABEL`||r.getLayerConstraint()===`FIRST_SEPARATE`)}},C=class{process(e){this.identifyHyperedges(e);for(let t of e.getLayers()){let e=t.getNodes();if(e.length===0)continue;let n=null,r=null;for(let t=0;t<e.length;t++){let i=e[t],a=i.getType();if(a===`LONG_EDGE`&&r===`LONG_EDGE`&&n!==null){let r=this.checkMergeAllowed(i,n);if(r.allowMerge){this.mergeNodes(i,n,r.sameSource,r.sameTarget),e.splice(t,1),t--;continue}}n=i,r=a}}}checkMergeAllowed(t,n){let r=t.getProperty(e.nr),i=n.getProperty(e.nr),a=t.getProperty(e.rr),o=n.getProperty(e.rr),s=t.getProperty(e.ir),c=n.getProperty(e.ir),l=a!=null&&a===o,u=s!=null&&s===c;if(!r&&!i)return{allowMerge:t.getPorts()[0]?.id===n.getPorts()[0]?.id,sameSource:l,sameTarget:u};let d=(!r||t.getProperty(e.tr))&&(!i||n.getProperty(e.tr)),f=(!r||!t.getProperty(e.tr))&&(!i||!n.getProperty(e.tr));return{allowMerge:l&&d||u&&f,sameSource:l,sameTarget:u}}mergeNodes(t,n,r,i){let a=n.getPorts(`WEST`)[0],o=n.getPorts(`EAST`)[0];for(let e of t.getPorts()){for(;e.getIncomingEdges().length>0;)e.getIncomingEdges()[0].setTarget(a);for(;e.getOutgoingEdges().length>0;)e.getOutgoingEdges()[0].setSource(o)}r||n.setProperty(e.rr,null),i||n.setProperty(e.ir,null)}identifyHyperedges(e){let t=[];for(let n of e.getLayers())for(let e of n.getNodes())t.push(...e.getPorts());for(let e of t)e.id=-1;let n=0;for(let e of t)e.id===-1&&this.dfs(e,n++)}dfs(e,t){e.id=t;for(let n of e.getConnectedPorts())n.id===-1&&this.dfs(n,t);if(e.getNode().getType()===`LONG_EDGE`)for(let n of e.getNode().getPorts())n!==e&&n.id===-1&&this.dfs(n,t)}},w=class{id=0;owner=null;size={x:0,y:0};nodes=[];constructor(e=null){this.owner=e}getGraph(){return this.owner}getSize(){return this.size}getNodes(){return this.nodes}getIndex(){return this.owner===null?-1:this.owner.getLayers().indexOf(this)}},ee=class{id=0;internalId=0;origin=null;type=``;layer=0;outgoingEdges=[];incomingEdges=[];allEdgesCache=null;treeNode=!1;unknownCutvalues=[];getOutgoingEdges(){return this.outgoingEdges}getIncomingEdges(){return this.incomingEdges}getConnectedEdges(){return this.allEdgesCache===null&&(this.allEdgesCache=[...this.incomingEdges,...this.outgoingEdges]),this.allEdgesCache}invalidateConnectedEdges(){this.allEdgesCache=null}},te=class{node;constructor(){this.node=new ee}id(e){return this.node.id=e,this}origin(e){return this.node.origin=e,this}type(e){return this.node.type=e,this}create(e){return e.nodes.push(this.node),this.node}};function T(){return new te}var E=class{id=0;internalId=0;origin=null;source;target;weight=0;delta=1;treeEdge=!1;getSource(){return this.source}getTarget(){return this.target}getOther(e){if(e===this.source)return this.target;if(e===this.target)return this.source;throw Error(`Node not part of edge`)}reverse(){let e=this.source;this.source=this.target,this.target=e;let t=this.target.getOutgoingEdges(),n=t.indexOf(this);n!==-1&&t.splice(n,1),this.target.getIncomingEdges().push(this);let r=this.source.getIncomingEdges(),i=r.indexOf(this);return i!==-1&&r.splice(i,1),this.source.getOutgoingEdges().push(this),this.source.invalidateConnectedEdges(),this.target.invalidateConnectedEdges(),this}},ne=class{edge;constructor(){this.edge=new E}id(e){return this.edge.id=e,this}origin(e){return this.edge.origin=e,this}weight(e){return this.edge.weight=e,this}delta(e){return this.edge.delta=e,this}source(e){return this.edge.source=e,this}target(e){return this.edge.target=e,this}create(){if(this.edge.source===void 0||this.edge.target===void 0)throw Error(`NEdge must have a source and target NNode specified.`);if(this.edge.source===this.edge.target)throw Error(`Network simplex does not support self-loops`);return this.edge.source.getOutgoingEdges().push(this.edge),this.edge.target.getIncomingEdges().push(this.edge),this.edge.source.invalidateConnectedEdges(),this.edge.target.invalidateConnectedEdges(),this.edge}};function D(){return new ne}var re=class{nodes=[];addNode(e){let t=new ee;return t.origin=e,this.nodes.push(t),t}addEdge(e,t,n,r,i){if(r===i)throw Error(`Network simplex does not support self-loops`);let a=new E;return a.origin=e,a.weight=t,a.delta=n,a.source=r,a.target=i,a.source.getOutgoingEdges().push(a),a.target.getIncomingEdges().push(a),a.source.invalidateConnectedEdges(),a.target.invalidateConnectedEdges(),a}createArtificialRootAndConnect(e){let t=T().create(this);for(let n of e)D().delta(0).weight(0).source(t).target(n).create();return t}findConCompRepresentatives(){let e=[],t=Array(this.nodes.length).fill(!1);for(let n of this.nodes)t[n.internalId]||(e.push(n),this.dfs(n,t));return e}dfs(e,t){if(!t[e.internalId]){t[e.internalId]=!0;for(let n of e.getConnectedEdges())this.dfs(n.getOther(e),t)}}makeConnected(){let e=0;for(let t of this.nodes)t.internalId=e++;let t=this.findConCompRepresentatives(),n=null;return t.length>1&&(n=this.createArtificialRootAndConnect(t)),n}isAcyclic(){let e=0;for(let t of this.nodes)t.internalId=e++;let t=Array(this.nodes.length).fill(0),n=Array(this.nodes.length).fill(0);for(let e of this.nodes)t[e.internalId]+=e.getIncomingEdges().length;let r=[];for(let e of this.nodes)e.getIncomingEdges().length===0&&r.push(e);if(r.length===0&&this.nodes.length>0)return!1;for(;r.length>0;){let e=r.shift();for(let i of e.getOutgoingEdges()){let a=i.getTarget();n[a.internalId]=Math.max(n[a.internalId],n[e.internalId]+1),t[a.internalId]--,t[a.internalId]===0&&r.push(a)}}for(let e of this.nodes)for(let t of e.getOutgoingEdges())if(n[t.target.internalId]<=n[t.source.internalId])return!1;return!0}},ie=class e{graph;edges=[];treeEdges=/* @__PURE__ */ new Set;sources=[];edgeVisited=/* @__PURE__ */ new Uint8Array;postOrder=0;poID=[];lowestPoID=[];cutvalue=[];cutvalueLeafs=[];subtreeNodes=[];subtreeEdges=[];incidentCounts=[];topologicalRoots=[];spanIn=0;spanOut=0;previousLayeringNodeCounts=null;doBalance=!1;iterationLimit=2**53-1;constructor(){}static forGraph(t){let n=new e;return n.graph=t,n}prepare(e){return this.graph=e,this}withBalancing(e){return this.doBalance=e,this}withPreviousLayering(e){return this.previousLayeringNodeCounts=e,this}withIterationLimit(e){return this.iterationLimit=e,this}execute(){this.executeInternal(null)}executeWithMonitor(e){e.begin(`Network simplex`,1),this.executeInternal(e),e.done()}executeInternal(e){if(this.graph.nodes.length<1)return;for(let e of this.graph.nodes)e.layer=0;let t=this.graph.nodes.length>=40;t&&this.removeSubtrees(),this.initialize(),this.feasibleTree();let n=this.leaveEdge(),r=0;for(;n!==null&&r<this.iterationLimit;)this.exchange(n,this.enterEdge(n)),n=this.leaveEdge(),r++;t&&this.reattachSubtrees(),this.doBalance?this.balance(this.normalize()):this.normalize()}removeSubtrees(){this.subtreeNodes.length=0,this.subtreeEdges.length=0;let e=[];for(let t of this.graph.nodes)t.getConnectedEdges().length===1&&e.push(t);let t=0;for(;t<e.length;){let n=e[t++];if(n.getConnectedEdges().length===0)continue;let r=n.getConnectedEdges()[0],i=n.getOutgoingEdges().length>0,a=r.getOther(n);if(i){let e=a.getIncomingEdges().indexOf(r);e!==-1&&a.getIncomingEdges().splice(e,1)}else{let e=a.getOutgoingEdges().indexOf(r);e!==-1&&a.getOutgoingEdges().splice(e,1)}a.invalidateConnectedEdges(),a.getConnectedEdges().length===1&&e.push(a),this.subtreeNodes.push(n),this.subtreeEdges.push(r);let o=this.graph.nodes.indexOf(n);o!==-1&&this.graph.nodes.splice(o,1)}}reattachSubtrees(){for(;this.subtreeNodes.length>0;){let e=this.subtreeNodes.pop(),t=this.subtreeEdges.pop(),n=t.getOther(e);t.target===e?(n.getOutgoingEdges().push(t),e.layer=n.layer+t.delta):(n.getIncomingEdges().push(t),e.layer=n.layer-t.delta),n.invalidateConnectedEdges(),this.graph.nodes.push(e)}}initialize(){let e=this.graph.nodes.length;for(let e of this.graph.nodes)e.treeNode=!1;this.poID.length<e?this.poID=Array(e).fill(0):this.poID.fill(0),this.lowestPoID.length<e?this.lowestPoID=Array(e).fill(0):this.lowestPoID.fill(0),this.sources.length=0;let t=0;this.edges.length=0;for(let e of this.graph.nodes){e.internalId=t++,e.getIncomingEdges().length===0&&this.sources.push(e);let n=e.getOutgoingEdges();for(let e=0;e<n.length;e++)this.edges.push(n[e])}let n=0;for(let e of this.edges)e.internalId=n++,e.treeEdge=!1;let r=this.edges.length;this.cutvalue.length<r&&(this.cutvalue=Array(r).fill(0)),this.edgeVisited.length<r&&(this.edgeVisited=new Uint8Array(r)),this.edgeVisited.fill(0),this.treeEdges=/* @__PURE__ */ new Set,this.postOrder=1}feasibleTree(){if(this.layeringTopologicalNumbering(this.sources),this.edges.length>0){for(this.edgeVisited.fill(0);this.tightTreeDFS(this.graph.nodes[0])<this.graph.nodes.length;){let e=this.minimalSlack(),t=e.getTarget().layer-e.getSource().layer-e.delta;e.getTarget().treeNode&&(t=-t);for(let e of this.graph.nodes)e.treeNode&&(e.layer+=t);this.edgeVisited.fill(0)}this.edgeVisited.fill(0),this.postorderTraversal(this.graph.nodes[0]),this.cutvalues()}}layeringTopologicalNumbering(e){let t=this.graph.nodes.length;this.incidentCounts.length<t?this.incidentCounts=Array(t).fill(0):this.incidentCounts.fill(0);let n=this.incidentCounts;for(let e of this.graph.nodes)n[e.internalId]+=e.getIncomingEdges().length;this.topologicalRoots.length=0;let r=this.topologicalRoots;for(let t=0;t<e.length;t++)r.push(e[t]);let i=0;for(;i<r.length;){let e=r[i++];for(let t of e.getOutgoingEdges()){let i=t.getTarget();i.layer=Math.max(i.layer,e.layer+t.delta),n[i.internalId]--,n[i.internalId]===0&&r.push(i)}}}minimalSpan(e){let t=2**53-1,n=2**53-1,r,i=e.getIncomingEdges();for(let a=0;a<i.length;a++){let o=i[a];r=o.getTarget().layer-o.getSource().layer,o.getTarget()===e&&r<n?n=r:r<t&&(t=r)}let a=e.getOutgoingEdges();for(let i=0;i<a.length;i++){let o=a[i];r=o.getTarget().layer-o.getSource().layer,o.getTarget()===e&&r<n?n=r:r<t&&(t=r)}this.spanIn=n===2**53-1?-1:n,this.spanOut=t===2**53-1?-1:t}tightTreeDFS(e){let t=1;e.treeNode=!0;let n=e.getIncomingEdges();for(let r=0;r<n.length;r++){let i=n[r];if(!this.edgeVisited[i.internalId]){this.edgeVisited[i.internalId]=1;let n=i.getOther(e);i.treeEdge?t+=this.tightTreeDFS(n):!n.treeNode&&i.delta===i.getTarget().layer-i.getSource().layer&&(i.treeEdge=!0,this.treeEdges.add(i),t+=this.tightTreeDFS(n))}}let r=e.getOutgoingEdges();for(let n=0;n<r.length;n++){let i=r[n];if(!this.edgeVisited[i.internalId]){this.edgeVisited[i.internalId]=1;let n=i.getOther(e);i.treeEdge?t+=this.tightTreeDFS(n):!n.treeNode&&i.delta===i.getTarget().layer-i.getSource().layer&&(i.treeEdge=!0,this.treeEdges.add(i),t+=this.tightTreeDFS(n))}}return t}minimalSlack(){let e=2**53-1,t=null,n;for(let r of this.edges)r.getSource().treeNode!==r.getTarget().treeNode&&(n=r.getTarget().layer-r.getSource().layer-r.delta,n<e&&(e=n,t=r));return t}postorderTraversal(e){let t=2**53-1,n=e.getIncomingEdges();for(let r=0;r<n.length;r++){let i=n[r];if(i.treeEdge&&!this.edgeVisited[i.internalId]){this.edgeVisited[i.internalId]=1;let n=this.postorderTraversal(i.getOther(e));n<t&&(t=n)}}let r=e.getOutgoingEdges();for(let n=0;n<r.length;n++){let i=r[n];if(i.treeEdge&&!this.edgeVisited[i.internalId]){this.edgeVisited[i.internalId]=1;let n=this.postorderTraversal(i.getOther(e));n<t&&(t=n)}}this.poID[e.internalId]=this.postOrder;let i=this.postOrder;return this.lowestPoID[e.internalId]=t<i?t:i,this.postOrder=i+1,this.lowestPoID[e.internalId]}isInHead(e,t){let n=t.getSource(),r=t.getTarget();return this.lowestPoID[n.internalId]<=this.poID[e.internalId]&&this.poID[e.internalId]<=this.poID[n.internalId]&&this.lowestPoID[r.internalId]<=this.poID[e.internalId]&&this.poID[e.internalId]<=this.poID[r.internalId]?!(this.poID[n.internalId]<this.poID[r.internalId]):this.poID[n.internalId]<this.poID[r.internalId]}cutvalues(){let e=this.cutvalueLeafs;e.length=0;let t;for(let n of this.graph.nodes){t=0;let r=n.unknownCutvalues;r.length=0;let i=n.getIncomingEdges();for(let e=0;e<i.length;e++){let n=i[e];n.treeEdge&&(r.push(n),t++)}let a=n.getOutgoingEdges();for(let e=0;e<a.length;e++){let n=a[e];n.treeEdge&&(r.push(n),t++)}t===1&&e.push(n)}let n,r,i;for(let t=0;t<e.length;t++){let a=e[t];for(;a.unknownCutvalues.length===1;){n=a.unknownCutvalues[0],this.cutvalue[n.internalId]=n.weight,r=n.getSource(),i=n.getTarget();let e=a.getIncomingEdges(),t=a.getOutgoingEdges();for(let t=0;t<e.length;t++){let o=e[t];o!==n&&(o.treeEdge?r===o.getSource()||i===o.getTarget()?this.cutvalue[n.internalId]-=this.cutvalue[o.internalId]-o.weight:this.cutvalue[n.internalId]+=this.cutvalue[o.internalId]-o.weight:a===r?o.getSource()===a?this.cutvalue[n.internalId]+=o.weight:this.cutvalue[n.internalId]-=o.weight:o.getSource()===a?this.cutvalue[n.internalId]-=o.weight:this.cutvalue[n.internalId]+=o.weight)}for(let e=0;e<t.length;e++){let o=t[e];o!==n&&(o.treeEdge?r===o.getSource()||i===o.getTarget()?this.cutvalue[n.internalId]-=this.cutvalue[o.internalId]-o.weight:this.cutvalue[n.internalId]+=this.cutvalue[o.internalId]-o.weight:a===r?o.getSource()===a?this.cutvalue[n.internalId]+=o.weight:this.cutvalue[n.internalId]-=o.weight:o.getSource()===a?this.cutvalue[n.internalId]-=o.weight:this.cutvalue[n.internalId]+=o.weight)}let o=r.unknownCutvalues,s=o.indexOf(n);s!==-1&&(o[s]=o[o.length-1],o.pop());let c=i.unknownCutvalues,l=c.indexOf(n);l!==-1&&(c[l]=c[c.length-1],c.pop()),a=r===a?n.getTarget():n.getSource()}}}leaveEdge(){for(let e of this.treeEdges)if(e.treeEdge&&this.cutvalue[e.internalId]<-1e-10)return e;return null}enterEdge(e){if(!e.treeEdge)throw Error(`The input edge is not a tree edge.`);let t=null,n=2**53-1,r;for(let i of this.edges){let a=i.getSource(),o=i.getTarget();this.isInHead(a,e)&&!this.isInHead(o,e)&&(r=o.layer-a.layer-i.delta,r<n&&(n=r,t=i))}return t}exchange(e,t){if(!e.treeEdge)throw Error(`Given leave edge is no tree edge.`);if(t.treeEdge)throw Error(`Given enter edge is a tree edge already.`);e.treeEdge=!1,this.treeEdges.delete(e),t.treeEdge=!0,this.treeEdges.add(t);let n=t.getTarget().layer-t.getSource().layer-t.delta;this.isInHead(t.getTarget(),e)||(n=-n);for(let t of this.graph.nodes)this.isInHead(t,e)||(t.layer+=n);this.postOrder=1,this.edgeVisited.fill(0),this.postorderTraversal(this.graph.nodes[0]),this.cutvalues()}normalize(){let e=-(2**53-1),t=2**53-1;for(let n of this.graph.nodes)t=Math.min(t,n.layer),e=Math.max(e,n.layer);let n=Array(e-t+1).fill(0);for(let e of this.graph.nodes)e.layer-=t,n[e.layer]++;let r=0;if(this.previousLayeringNodeCounts!==null){for(let e of this.previousLayeringNodeCounts)if(n[r]+=e,r++,n.length===r)break}return n}balance(e){let t;for(let n of this.graph.nodes)if(n.getIncomingEdges().length===n.getOutgoingEdges().length){t=n.layer,this.minimalSpan(n);for(let r=n.layer-this.spanIn+1;r<n.layer+this.spanOut;r++)e[r]<e[t]&&(t=r);e[t]<e[n.layer]&&(e[n.layer]--,e[t]++,n.layer=t)}}},ae=class t{layeredGraph=null;componentNodes=[];nodeVisited=[];componentIndex=null;static ITER_LIMIT_FACTOR=4;process(n,r){r.begin(`Network simplex layering`,1),this.layeredGraph=n;let i=n.getProperty(e.mn)*t.ITER_LIMIT_FACTOR,a=n.getLayerlessNodes();if(a.length<1){r.done();return}let o=this.connectedComponents(a),s=null,c=null;for(let e of o){if(e.length===1&&e[0].getConnectedEdges().length===0){let t=n.getLayers();for(;t.length<=0;)t.push(new w(n));e[0].setLayer(t[0]);continue}let t=i*Math.floor(Math.sqrt(e.length)),a=this.initialize(e);c=c===null?ie.forGraph(a):c.prepare(a),c.withIterationLimit(t).withPreviousLayering(s).withBalancing(!0).executeWithMonitor(r);let l=n.getLayers();for(let e of a.nodes){for(;l.length<=e.layer;)l.push(new w(n));e.origin.setLayer(l[e.layer])}if(o.length>1){s=Array(n.getLayers().length).fill(0);let e=0;for(let t of n.getLayers())s[e++]=t.getNodes().length}}a.length=0,this.dispose(),r.done()}connectedComponents(e){let t=[];this.nodeVisited=Array(e.length).fill(!1),this.componentNodes=[];let n=/* @__PURE__ */ new Map;for(let t=0;t<e.length;t++)n.set(e[t],t);this.componentIndex=n;for(let n of e)this.componentNodes=[],this.connectedComponentsDFS(n),this.componentNodes.length>0&&(t.length===0||t[0].length<this.componentNodes.length?t.unshift(this.componentNodes):t.push(this.componentNodes));return t}connectedComponentsDFS(e){let t=this.componentIndex.get(e);if(!(t===void 0||this.nodeVisited[t])){this.nodeVisited[t]=!0,this.componentNodes.push(e);for(let t of e.getPorts()){for(let e of t.getIncomingEdges())this.connectedComponentsDFS(this.getOpposite(t,e).getNode());for(let e of t.getOutgoingEdges())this.connectedComponentsDFS(this.getOpposite(t,e).getNode())}}}initialize(t){let n=/* @__PURE__ */ new Map,r=new re;for(let e of t){let t=r.addNode(e);n.set(e,t)}for(let i of t)for(let t of i.getPorts())for(let i of t.getOutgoingEdges())i.isSelfLoop()||i.getSource()!==null&&i.getTarget()!==null&&r.addEdge(i,1*Math.max(1,i.getProperty(e.Wt)),1,n.get(i.getSource().getNode()),n.get(i.getTarget().getNode()));return r}dispose(){this.componentNodes=[],this.layeredGraph=null,this.nodeVisited=[],this.componentIndex=null}getOpposite(e,t){if(t.getSource()===e)return t.getTarget();if(t.getTarget()===e)return t.getSource();throw Error(`Input edge is not connected to the input port.`)}},oe=class{layeredGraph;nodeHeights=/* @__PURE__ */ new Map;process(e,t){t.begin(`Longest path layering`,1),this.layeredGraph=e;let n=e.getLayerlessNodes();this.nodeHeights=/* @__PURE__ */ new Map;for(let e of n)this.nodeHeights.set(e,-1);for(let e of n)this.visit(e);n.length=0,this.layeredGraph=null,this.nodeHeights=/* @__PURE__ */ new Map,t.done()}visit(e){let t=this.nodeHeights.get(e);if(t>=0)return t;let n=1;for(let t of e.getPorts())for(let r of t.getOutgoingEdges()){let t=r.getTarget().getNode();if(e!==t){let e=this.visit(t);n=Math.max(n,e+1)}}return this.putNode(e,n),n}putNode(e,t){let n=this.layeredGraph.getLayers();for(let e=n.length;e<t;e++)n.unshift(new w(this.layeredGraph));e.setLayer(n[n.length-t]),this.nodeHeights.set(e,t)}},se=class{layeredGraph;nodeHeights=/* @__PURE__ */ new Map;process(e,t){t.begin(`Longest path to source layering`,1),this.layeredGraph=e;let n=e.getLayerlessNodes();this.nodeHeights=/* @__PURE__ */ new Map;for(let e of n)this.nodeHeights.set(e,-1);for(let e of n)this.visit(e);n.length=0,this.layeredGraph=null,this.nodeHeights=/* @__PURE__ */ new Map,t.done()}visit(e){let t=this.nodeHeights.get(e);if(t!==void 0&&t>=0)return t;if(t===void 0)return 0;let n=1;for(let t of e.getPorts())for(let r of t.getIncomingEdges()){let t=r.getSource().getNode();if(e!==t){let e=this.visit(t);n=Math.max(n,e+1)}}return this.putNode(e,n),n}putNode(e,t){let n=this.layeredGraph.getLayers();for(let e=n.length;e<t;e++)n.push(new w(this.layeredGraph));e.setLayer(n[t-1]),this.nodeHeights.set(e,t)}};function ce(e){if(e.getLayers().length<=2)return;let t=e.getLayers();for(let n=0;n<t.length-1;n++){let r=t[n],i=t[n+1];for(let t of r.getNodes())for(let r of t.getPorts())for(let t of[...r.getOutgoingEdges()]){let r=t.getTarget().getNode().getLayer();r!==null&&r.getIndex()-n>1&&ue(t,le(e,i,t))}}}function le(t,n,r){let i=new f(t);return i.setType(`LONG_EDGE`),i.setProperty(e.lr,r),i.setProperty(e.Lt,`FIXED_POS`),i.setLayer(n),i}function ue(t,n){let r=t.getTarget(),i=t.getProperty(e.W);i<0&&(i=0,t.setProperty(e.W,i)),n.size.y=i;let a=Math.floor(i/2),o=new p;o.setSide(`WEST`),o.setNode(n),o.getPosition().y=a;let s=new p;s.setSide(`EAST`),s.setNode(n),s.getPosition().y=a,t.setTarget(o);let c=new m;return c.copyProperties(t),c.setProperty(e.nt,null),c.setSource(s),c.setTarget(r),de(n,t,c),fe(t,c),c}function de(t,n,r){let i=n.getSource().getNode(),a=r.getTarget().getNode();i.getType()===`LONG_EDGE`?(t.setProperty(e.rr,i.getProperty(e.rr)),t.setProperty(e.ir,i.getProperty(e.ir)),t.setProperty(e.nr,i.getProperty(e.nr))):i.getType()===`LABEL`?(t.setProperty(e.rr,i.getProperty(e.rr)),t.setProperty(e.ir,i.getProperty(e.ir)),t.setProperty(e.nr,!0)):a.getType()===`LABEL`?(t.setProperty(e.rr,a.getProperty(e.rr)),t.setProperty(e.ir,a.getProperty(e.ir)),t.setProperty(e.nr,!0)):(t.setProperty(e.rr,n.getSource()),t.setProperty(e.ir,r.getTarget()))}function fe(e,t){let n=[...e.getLabels()];for(let r of n)if(r.placement===`HEAD`){let n=e.getLabels().indexOf(r);n!==-1&&e.getLabels().splice(n,1),t.getLabels().push(r)}}function pe(e){return e.placement===void 0||e.placement===`CENTER`||e.placement===`UNDEFINED`}function me(t){let n=t.getProperty(e.tn),r=t.getProperty(e.an),i=t.getProperty(e.F)===`DOWN`||t.getProperty(e.F)===`UP`;for(let e of t.getLayerlessNodes())for(let a of[...e.getOutgoingEdges()]){if(!he(a))continue;let e=ge(a),o=[],s=_e(t,a,e,o).size,c=a.getLabels();for(let e=0;e<c.length;){let t=c[e];pe(t)?(i?(s.x+=t.size.x+r,s.y=Math.max(s.y,t.size.y)):(s.x=Math.max(s.x,t.size.x),s.y+=t.size.y+r),o.push(t),c.splice(e,1)):e++}i?(s.x-=r,s.y+=n+e):s.y+=n-r+e}}function he(e){return e.getSource().getNode()!==e.getTarget().getNode()&&e.getLabels().some(pe)}function ge(t){let n=t.getProperty(e.W);return n<0&&(n=0,t.setProperty(e.W,n)),n}function _e(t,n,r,i){let a=new f(t);return a.setType(`LABEL`),a.setProperty(e.lr,n),a.setProperty(e.xr,i),a.setProperty(e.Lt,`FIXED_POS`),a.setProperty(e.rr,n.getSource()),a.setProperty(e.ir,n.getTarget()),ue(n,a),a}const ve=[`MEDIAN_LAYER`,`TAIL_LAYER`,`HEAD_LAYER`,`SPACE_EFFICIENT_LAYER`,`WIDEST_LAYER`,`CENTER_LAYER`];function ye(e){return e===`WIDEST_LAYER`||e===`CENTER_LAYER`||e===`SPACE_EFFICIENT_LAYER`}function be(t){let n=t.getProperty(e.R);xe(t);let r=Se(t,n),i=Array(t.getLayers().length).fill(0);for(let e of ve)if(ye(e)&&r.get(e).length>0){i=Ce(t);break}for(let e of ve)ye(e)||Te(r.get(e),i);for(let e of ve)ye(e)&&Te(r.get(e),i)}function xe(e){let t=0;for(let n of e.getLayers())n.id=t,t++}function Se(e,t){let n=/* @__PURE__ */ new Map;for(let e of ve)n.set(e,[]);for(let r of e.getLayers())for(let e of r.getNodes())if(e.getType()===`LABEL`){let r=new Ve(e,t);n.get(r.placementStrategy).push(r)}return n}function Ce(e){let t=Array(e.getLayers().length).fill(0);for(let n of e.getLayers())t[n.id]=we(n);return t}function we(t){let n=t.getGraph();if(n!==null&&(n.getProperty(e.F)===`DOWN`||n.getProperty(e.F)===`UP`))return 0;let r=0;for(let e of t.getNodes())e.getType()===`NORMAL`&&(r=Math.max(r,e.getSize().x));return r}function Te(e,t){if(e.length!==0){if(e[0].placementStrategy===`SPACE_EFFICIENT_LAYER`)Ne(e,t);else for(let n of e){switch(n.placementStrategy){case`CENTER_LAYER`:Le(n,De(n,t),t);break;case`MEDIAN_LAYER`:Le(n,ke(n),t);break;case`WIDEST_LAYER`:Le(n,Ee(n,t),t);break;case`HEAD_LAYER`:je(n),Le(n,Ae(n,!0),t);break;case`TAIL_LAYER`:je(n),Le(n,Ae(n,!1),t)}ze(n)}}}function Ee(e,t){let n=e.leftmostLayerId;for(let r=n+1;r<=e.rightmostLayerId;r++)t[r]>t[n]&&(n=r);return n}function De(e,t){let n=Oe(e,t),r=n[n.length-1]/2;for(let t=0;t<n.length;t++)if(n[t]>=r)return e.leftmostLayerId+t;return e.leftmostLayerId+e.leftLongEdgeDummies.length}function Oe(t,n){let r=t.labelDummy.getGraph(),i=r.getProperty(e.rn)*2,a=r.getProperty(e.un),o=Math.max(i,a),s=Array(t.totalDummyCount()),c=-o,l=0;for(let e of t.leftLongEdgeDummies)c+=n[e.getLayer().id]+o,s[l++]=c;c+=n[t.labelDummy.getLayer().id]+o,s[l++]=c;for(let e of t.rightLongEdgeDummies)c+=n[e.getLayer().id]+o,s[l++]=c;return s}function ke(e){let t=e.totalDummyCount(),n=Math.floor((t-1)/2);return e.leftmostLayerId+n}function Ae(e,t){let n=Me(e);return t&&!n||!t&&n?e.rightmostLayerId:e.leftmostLayerId}function je(t){let n=t.placementStrategy===`HEAD_LAYER`,r=Me(t);n&&!r||!n&&r?t.labelDummy.setProperty(e.p,`RIGHT`):t.labelDummy.setProperty(e.p,`LEFT`)}function Me(t){let n=t.labelDummy.getIncomingEdges()[0],r=t.labelDummy.getOutgoingEdges()[0];return n.getProperty(e.Sr)||r.getProperty(e.Sr)}function Ne(e,t){let n=Pe(e,t);if(n.length===0)return;n.sort((e,t)=>t.labelDummy.getSize().x-e.labelDummy.getSize().x);let r=n.length;for(let e=0;e<r;e++)Le(n[e],Ie(n,e,t),t)}function Pe(e,t){let n=[];for(let r of e)r.leftmostLayerId===r.rightmostLayerId?Le(r,r.leftmostLayerId,t):Fe(r,t)||n.push(r);return n}function Fe(e,t){let n=e.labelDummy.getSize().x,r=e.labelDummy.getGraph().getLayers().slice(e.leftmostLayerId,e.rightmostLayerId+1);for(let i of r)if(i.getSize().x>=n)return Le(e,i.id,t),!0;return!1}function Ie(e,t,n){let r=e.length,i=e[t],a=i.labelDummy.getSize().x,o=i.leftmostLayerId,s=0;for(let c=i.leftmostLayerId;c<=i.rightmostLayerId;c++){if(a<=n[c])return c;let i=n[c],l=null;for(let n=t+1;n<r;n++){let t=e[n];t.leftmostLayerId<=c&&t.rightmostLayerId>=c&&(l=t)}l!==null&&(i=Math.max(i,l.labelDummy.getSize().x)),i>s&&(o=c,s=i)}return o}function Le(e,t,n){t!==e.leftmostLayerId+e.leftLongEdgeDummies.length&&Re(e.labelDummy,e.ithDummyNode(t-e.leftmostLayerId));let r=e.labelDummy.getLayer().id;n[r]=Math.max(n[r],e.labelDummy.getSize().x)}function Re(e,t){let n=e.getLayer(),r=t.getLayer(),i=n.getNodes().indexOf(e),a=r.getNodes().indexOf(t),o=e.getPorts(`INPUT`)[0],s=e.getPorts(`OUTPUT`)[0],c=t.getPorts(`INPUT`)[0],l=t.getPorts(`OUTPUT`)[0],u=[...o.getIncomingEdges()],d=[...s.getOutgoingEdges()],f=[...c.getIncomingEdges()],p=[...l.getOutgoingEdges()];e.setLayerAt(a,r);for(let e of f)e.setTarget(o);for(let e of p)e.setSource(s);t.setLayerAt(i,n);for(let e of u)e.setTarget(c);for(let e of d)e.setSource(l)}function ze(e){Be(e.labelDummy)}function Be(t){let n=t.getIncomingEdges()[0].getSource().getNode();for(;n.getType()===`LONG_EDGE`;)n.setProperty(e.tr,!0),n=n.getIncomingEdges()[0].getSource().getNode()}var Ve=class{labelDummy;placementStrategy;leftLongEdgeDummies=[];rightLongEdgeDummies=[];leftmostLayerId;rightmostLayerId;constructor(t,n){this.labelDummy=t,this.placementStrategy=n,this.gatherLeftLongEdgeDummies(),this.gatherRightLongEdgeDummies(),this.leftmostLayerId=this.leftLongEdgeDummies.length===0?t.getLayer().id:this.leftLongEdgeDummies[0].getLayer().id,this.rightmostLayerId=this.rightLongEdgeDummies.length===0?t.getLayer().id:this.rightLongEdgeDummies[this.rightLongEdgeDummies.length-1].getLayer().id;for(let n of t.getProperty(e.xr)){let e=n.centerLabelPlacementStrategy;if(e!=null){this.placementStrategy=e;break}}}gatherLeftLongEdgeDummies(){let e=this.labelDummy;do e=e.getIncomingEdges()[0].getSource().getNode(),e.getType()===`LONG_EDGE`&&this.leftLongEdgeDummies.push(e);while(e.getType()===`LONG_EDGE`);this.leftLongEdgeDummies.reverse()}gatherRightLongEdgeDummies(){let e=this.labelDummy;do e=e.getOutgoingEdges()[0].getTarget().getNode(),e.getType()===`LONG_EDGE`&&this.rightLongEdgeDummies.push(e);while(e.getType()===`LONG_EDGE`)}totalDummyCount(){return this.rightmostLayerId-this.leftmostLayerId+1}ithDummyNode(e){return e<this.leftLongEdgeDummies.length?this.leftLongEdgeDummies[e]:e===this.leftLongEdgeDummies.length?this.labelDummy:this.rightLongEdgeDummies[e-this.leftLongEdgeDummies.length-1]}};function He(t){let n=t.getProperty(e.hn);for(let e of t.getLayers()){let t=e.getNodes();for(let e=t.length-1;e>=0;e--){let r=t[e];r.getType()===`LONG_EDGE`&&(Ue(r,n),t.splice(e,1))}}}function Ue(t,n){let r=t.getPorts(`WEST`)[0],i=t.getPorts(`EAST`)[0],a=r.getIncomingEdges(),o=i.getOutgoingEdges(),s=a.length,c=t.getPorts()[0].getAbsoluteAnchor();for(;s-->0;){let t=a[0],r=o[0],i=r.getTarget().getIncomingEdges().indexOf(r);t.setTargetAndInsertAtIndex(r.getTarget(),i),r.setSource(null),r.setTarget(null);let s=t.getBendPoints();n&&s.push({...c});for(let e of r.getBendPoints())s.push({...e});for(let e of r.getLabels())t.getLabels().push(e);let l=t.getProperty(e.nt),u=r.getProperty(e.nt);u!=null&&(l==null?t.setProperty(e.nt,[...u]):l.push(...u))}}function We(t){let n=t.getProperty(e.tn),r=t.getProperty(e.an),i=t.getProperty(e.F),a=i===`DOWN`||i===`UP`;for(let o of t.getLayers())for(let t=o.getNodes().length-1;t>=0;t--){let s=o.getNodes()[t];if(s.getType()!==`LABEL`)continue;let c=s.getProperty(e.lr),l=c.getProperty(e.W),u=s.getProperty(e.er)===`BELOW`,d={...s.getPosition()};u&&(d.y+=l+n);let f={x:s.size.x,y:s.size.y-l-n},p=s.getProperty(e.xr);if(a)Ge(p,d,r,f,u,i);else{let e=d.y;for(let t of p)t.position.x=d.x+(f.x-t.size.x)/2,t.position.y=e,e+=t.size.y+r}c.getLabels().push(...p),Ue(s,!1),o.getNodes().splice(t,1)}}function Ge(e,t,n,r,i,a){let o=a===`UP`?[...e].reverse():e;for(let e of o)e.position.x=t.x,i?e.position.y=t.y:e.position.y=t.y+r.y-e.size.y,t.x+=e.size.x+n}var Ke=class{layerToNodes=/* @__PURE__ */ new Map;nodeToLayer=/* @__PURE__ */ new Map;put(e,t){let n=this.nodeToLayer.get(t);if(n!==void 0&&n!==e){let e=this.layerToNodes.get(n);if(e){let n=e.indexOf(t);n!==-1&&e.splice(n,1)}}this.nodeToLayer.set(t,e);let r=this.layerToNodes.get(e);r||(r=[],this.layerToNodes.set(e,r)),r.includes(t)||r.push(t)}putAll(e,t){for(let n of t)this.put(e,n)}getValues(e){return this.layerToNodes.get(e)??[]}getKey(e){return this.nodeToLayer.get(e)}keys(){return[...this.layerToNodes.keys()]}isMaximalKey(e){return e===Math.max(...this.keys())}isMinimalKey(e){return e===Math.min(...this.keys())}},qe=class{masterGraph;promotionStrategy=`NONE`;biLayerMap=new Ke;process(t,n){switch(n.begin(`Node promotion heuristic`,1),this.masterGraph=t,this.promotionStrategy=t.getProperty(e.ct),this.promotionStrategy){case`MODEL_ORDER_LEFT_TO_RIGHT`:this.precalculateAndSetInformationModelOrder(),this.modelOrderNodePromotion(!0);break;case`MODEL_ORDER_RIGHT_TO_LEFT`:this.precalculateAndSetInformationModelOrder(),this.modelOrderNodePromotion(!1)}(this.promotionStrategy===`MODEL_ORDER_LEFT_TO_RIGHT`||this.promotionStrategy===`MODEL_ORDER_RIGHT_TO_LEFT`)&&this.setNewLayeringModelOrder(t),n.done()}precalculateAndSetInformationModelOrder(){this.biLayerMap=new Ke;let t=0;for(let e of this.masterGraph.getLayers())e.id=t,t++;let n=this.promotionStrategy===`MODEL_ORDER_LEFT_TO_RIGHT`,r=(t,r)=>{if(!t.hasProperty(e.cr)||!r.hasProperty(e.cr))return 0;let i=t.getProperty(e.cr),a=r.getProperty(e.cr);return n?a-i:i-a};for(let e of this.masterGraph.getLayers())e.getNodes().sort(r),this.biLayerMap.putAll(e.id,e.getNodes())}modelOrderNodePromotion(t){let n;do{n=!1;let r=this.biLayerMap.keys();for(let i=t?r.length-2:1;t?i>=0:i<r.length;i+=t?-1:1){let r=this.biLayerMap.getValues(i);for(let a=0;a<r.length;a++){let o=r[a];if(!o.hasProperty(e.cr)||this.biLayerMap.isMaximalKey(i)&&t||this.biLayerMap.isMinimalKey(i)&&!t)continue;let s=!0;for(let n of r)if(n.hasProperty(e.cr)){let r=o.getProperty(e.cr),i=n.getProperty(e.cr);(t&&r<i||!t&&r>i)&&(s=!1)}if(!s)continue;let c=t?i+1:i-1,l=this.biLayerMap.getValues(c),u=!1,d=!0,f=!1;for(let n of l)if(n.hasProperty(e.cr)){if(n!==o){let r=o.getProperty(e.cr),i=n.getProperty(e.cr);u||=t?i<r:i>r,d=!1}}else if(!u&&d&&n.getType()===`LABEL`){f=!0;let e=t?n.getIncomingEdges()[0].getSource().getNode():n.getOutgoingEdges()[0].getTarget().getNode();if(e===o){let r=t?n.getOutgoingEdges()[0].getTarget().getNode():n.getIncomingEdges()[0].getSource().getNode();(t?this.biLayerMap.getKey(r)-this.biLayerMap.getKey(e):this.biLayerMap.getKey(e)-this.biLayerMap.getKey(r))<=2&&(d=!1)}}if(f&&d){let e=t?o.getOutgoingEdges()[0].getTarget().getNode():o.getIncomingEdges()[0].getSource().getNode();(t?this.biLayerMap.getKey(e)-this.biLayerMap.getKey(o):this.biLayerMap.getKey(o)-this.biLayerMap.getKey(e))<=2&&e.getType()===`NORMAL`&&(d=!1)}if(u||d){let e=this.promoteNodeByModelOrder(o,t),r=new Set(e);for(;r.size>0;){let e=r.values().next().value;r.delete(e);for(let n of this.promoteNodeByModelOrder(e,t))r.add(n)}a--,n=!0}}}}while(n)}promoteNodeByModelOrder(e,t){let n=this.biLayerMap.getKey(e);this.biLayerMap.put(t?n+1:n-1,e);let r=/* @__PURE__ */ new Set;for(let n of t?e.getOutgoingEdges():e.getIncomingEdges()){let i=t?n.getTarget().getNode():n.getSource().getNode();this.biLayerMap.getKey(i)===this.biLayerMap.getKey(e)&&r.add(i)}return r}setNewLayeringModelOrder(e){let t=[];e.getLayers().length=0;let n=this.biLayerMap.keys().sort((e,t)=>e-t);for(let r of n){let n=this.biLayerMap.getValues(r);if(n.length>0){let i=new w(e);t.push(i),i.id=r;for(let e of n)e.setLayer(i)}}e.getLayers().push(...t)}},Je=class{binarySums;numsPerIndex;count=0;maxNum;constructor(e){this.maxNum=e,this.binarySums=new Int32Array(e+1),this.numsPerIndex=new Int32Array(e)}add(e){if(!Number.isInteger(e)||e<0||e>=this.numsPerIndex.length)throw RangeError(`BinaryIndexedTree.add(${e})`);this.count++,this.numsPerIndex[e]++;let t=e+1;for(;t<this.binarySums.length;)this.binarySums[t]++,t+=t&-t}rank(e){let t=e,n=0;for(;t>0;)n+=this.binarySums[t],t-=t&-t;return n}size(){return this.count}removeAll(e){if(!Number.isInteger(e)||e<0||e>=this.numsPerIndex.length)throw RangeError(`BinaryIndexedTree.removeAll(${e})`);let t=this.numsPerIndex[e];if(t===0)return;this.numsPerIndex[e]=0,this.count-=t;let n=e+1;for(;n<this.binarySums.length;)this.binarySums[n]-=t,n+=n&-n}reset(e){e===this.maxNum?(this.binarySums.fill(0),this.numsPerIndex.fill(0)):(this.maxNum=e,this.binarySums=new Int32Array(e+1),this.numsPerIndex=new Int32Array(e)),this.count=0}clear(){this.binarySums.fill(0),this.numsPerIndex.fill(0),this.count=0}isEmpty(){return this.count===0}};function Ye(e,t){switch(t){case`EAST`:case`NORTH`:return e.getPortSideView(t);case`SOUTH`:case`WEST`:return[...e.getPortSideView(t)].reverse();default:return[]}}function Xe(e,t){return{first:e,second:t}}var Ze=class t{portPositions;indexTree=null;ends=[];nodeCardinalities=[];includedSet=/* @__PURE__ */ new Set;includedStamp=null;includedStampValue=0;scratchPortsCCW=[];scratchPortsInLayer=[];scratchPortsNS=[];scratchStackNS=[];nsTargets=[];nsDegrees=[];othersByPort=[];inLayerOthersByPort=[];betweenLayerDegreeByPort=[];static INDEXING_SIDE=`WEST`;static STACK_SIDE=`EAST`;constructor(e){this.portPositions=e}countCrossingsBetweenLayers(e,t){let n=this.initPortPositionsCounterClockwise(e,t);this.indexTree??=new Je(n.length),this.indexTree.reset(n.length);let r=this.includedSet;this.includedStamp??=new Uint32Array(this.portPositions.length);let i=++this.includedStampValue;i>=4294967296&&(this.includedStamp.fill(0),this.includedStampValue=1,i=1);for(let e of n)this.includedStamp[e.id]=i;return this.countCrossingsOnPorts(n,r)}countInLayerCrossingsOnSide(e,t){let n=this.initPortPositionsForInLayerCrossings(e,t);return this.countInLayerCrossingsOnPorts(n)}countNorthSouthPortCrossingsInLayer(e){let t=this.initPositionsForNorthSouthCounting(e);return this.indexTree??=new Je(t.length),this.indexTree.reset(t.length),this.countNorthSouthCrossingsOnPorts(t)}countCrossingsBetweenPortsInBothOrders(e,t){let n=this.connectedPortsSortedByPosition(e,t),r=this.countCrossingsOnPorts(n);this.indexTree.clear(),this.switchPorts(e,t),n.sort((e,t)=>this.positionOf(e)-this.positionOf(t));let i=this.countCrossingsOnPorts(n);return this.indexTree.clear(),this.switchPorts(t,e),Xe(r,i)}countInLayerCrossingsBetweenNodesInBothOrders(e,t,n){let r=this.connectedInLayerPortsSortedByPosition(e,t,n),i=this.countInLayerCrossingsOnPorts(r);this.switchNodes(e,t,n),this.indexTree.clear(),r.sort((e,t)=>this.positionOf(e)-this.positionOf(t));let a=this.countInLayerCrossingsOnPorts(r);return this.switchNodes(t,e,n),this.indexTree.clear(),Xe(i,a)}initForCountingBetween(e,t){let n=this.initPortPositionsCounterClockwise(e,t);this.indexTree??=new Je(n.length),this.indexTree.reset(n.length)}initPortPositionsForInLayerCrossings(e,t){let n=this.scratchPortsInLayer;return n.length=0,this.initPositions(e,n,t,!0,!0),this.indexTree??=new Je(n.length),this.indexTree.reset(n.length),n}switchPorts(e,t){let n=this.portPositions[e.id];this.portPositions[e.id]=this.portPositions[t.id],this.portPositions[t.id]=n}switchNodes(e,t,n){let r=Ye(e,n);for(let e of r)this.portPositions[e.id]=this.positionOf(e)+this.nodeCardinalities[t.id];r=Ye(t,n);for(let t of r)this.portPositions[t.id]=this.positionOf(t)-this.nodeCardinalities[e.id]}connectedPortsSortedByPosition(e,t){let n=/* @__PURE__ */ new Set;for(let r of[e,t]){n.add(r);for(let e of r.getIncomingEdges())this.isPortSelfLoop(e)||n.add(this.otherEndOf(e,r));for(let e of r.getOutgoingEdges())this.isPortSelfLoop(e)||n.add(this.otherEndOf(e,r))}return[...n].sort((e,t)=>this.positionOf(e)-this.positionOf(t))}connectedInLayerPortsSortedByPosition(e,t,n){let r=/* @__PURE__ */ new Set;for(let i of[e,t])for(let e of Ye(i,n)){for(let t of e.getIncomingEdges())t.isSelfLoop()||(r.add(e),this.isInLayer(t)&&r.add(this.otherEndOf(t,e)));for(let t of e.getOutgoingEdges())t.isSelfLoop()||(r.add(e),this.isInLayer(t)&&r.add(this.otherEndOf(t,e)))}return[...r].sort((e,t)=>this.positionOf(e)-this.positionOf(t))}getOthers(e){let t=this.othersByPort[e.id];if(t!==void 0)return t;let n=[],r=e.getIncomingEdges();for(let t=0;t<r.length;t++){let i=r[t];n.push(e===i.getSource()?i.getTarget():i.getSource())}let i=e.getOutgoingEdges();for(let t=0;t<i.length;t++){let r=i[t];n.push(e===r.getSource()?r.getTarget():r.getSource())}return this.othersByPort[e.id]=n,n}countCrossingsOnPorts(e,t){let n=0,r=this.indexTree,i=this.ends,a=this.portPositions,o=t===void 0?null:this.includedStamp,s=this.includedStampValue;for(let t of e){let e=a[t.id]??0;r.removeAll(e);let c=this.getOthers(t);for(let t=0;t<c.length;t++){let l=c[t];if(o!==null&&o[l.id]!==s)continue;let u=a[l.id]??0;u>e&&(n+=r.rank(u),i.push(u))}for(;i.length>0;)r.add(i.pop())}return n}getInLayerOthers(e){let t=this.inLayerOthersByPort[e.id];if(t!==void 0)return t;let n=[],r=0,i=e.getIncomingEdges();for(let t=0;t<i.length;t++){let a=i[t];a.getSource().getNode().getLayer()===a.getTarget().getNode().getLayer()?n.push(e===a.getSource()?a.getTarget():a.getSource()):r++}let a=e.getOutgoingEdges();for(let t=0;t<a.length;t++){let i=a[t];i.getSource().getNode().getLayer()===i.getTarget().getNode().getLayer()?n.push(e===i.getSource()?i.getTarget():i.getSource()):r++}return this.inLayerOthersByPort[e.id]=n,this.betweenLayerDegreeByPort[e.id]=r,n}countInLayerCrossingsOnPorts(e){let t=0,n=this.indexTree,r=this.ends,i=this.portPositions,a=n.numsPerIndex.length;for(let o of e){let e=i[o.id]??0;n.removeAll(e);let s=this.getInLayerOthers(o);for(let o=0;o<s.length;o++){let c=i[s[o].id]??0;c>e&&c<a&&(t+=n.rank(c),r.push(c))}for(t+=n.size()*this.betweenLayerDegreeByPort[o.id];r.length>0;)n.add(r.pop())}return t}countNorthSouthCrossingsOnPorts(t){let n=0,r=this.indexTree,i=this.ends,a=this.portPositions,o=this.nsTargets,s=this.nsDegrees;for(let c of t){let t=a[c.id]??0;switch(r.removeAll(t),o.length=0,s.length=0,c.getNode().getType()){case`NORMAL`:{let t=c.getProperty(e._r);if(t)for(let e of t.getPorts())o.push(e),s.push(e.getDegree());break}case`LONG_EDGE`:{let e=c.getNode().getPorts().find(e=>e!==c);e&&(o.push(e),s.push(e.getDegree()));break}case`NORTH_SOUTH_PORT`:{let t=c.getProperty(e.lr);t&&(o.push(t),s.push(c.getDegree()));break}}for(let e=0;e<o.length;e++){let c=a[o[e].id]??0;c>t&&(n+=r.rank(c)*s[e],i.push(c))}for(;i.length>0;)r.add(i.pop())}return n}initPositions(e,t,n,r,i){let a=t.length;i&&this.nodeCardinalities.length<e.length&&(this.nodeCardinalities=Array(e.length));let o=n===`EAST`?r:!r;if(r)for(let r=0;r<e.length;r++){let s=e[r],c=s.getPorts(),l=0;if(o)for(let e=0;e<c.length;e++){let r=c[e];r.getSide()===n&&(this.portPositions[r.id]=a++,t.push(r),l++)}else for(let e=c.length-1;e>=0;e--){let r=c[e];r.getSide()===n&&(this.portPositions[r.id]=a++,t.push(r),l++)}i&&(this.nodeCardinalities[s.id]=l)}else for(let r=e.length-1;r>=0;r--){let s=e[r],c=s.getPorts(),l=0;if(o)for(let e=0;e<c.length;e++){let r=c[e];r.getSide()===n&&(this.portPositions[r.id]=a++,t.push(r),l++)}else for(let e=c.length-1;e>=0;e--){let r=c[e];r.getSide()===n&&(this.portPositions[r.id]=a++,t.push(r),l++)}i&&(this.nodeCardinalities[s.id]=l)}}initPortPositionsCounterClockwise(e,t){let n=this.scratchPortsCCW;return n.length=0,this.initPositions(e,n,`EAST`,!0,!1),this.initPositions(t,n,`WEST`,!1,!1),n}initPositionsForNorthSouthCounting(n){let r=this.scratchPortsNS;r.length=0;let i=this.scratchStackNS;i.length=0;let a=null,o=0;for(let s=0;s<n.length;++s){let c=n[s];switch(this.isLayoutUnitChanged(a,c)&&(o=this.emptyStack(i,r,t.STACK_SIDE,o)),c.hasProperty(e.Zn)&&(a=c.getProperty(e.Zn)),c.getType()){case`NORMAL`:for(let t of c.getPorts())t.getSide()===`NORTH`&&t.hasProperty(e._r)&&(this.portPositions[t.id]=o++,r.push(t));o=this.emptyStack(i,r,t.STACK_SIDE,o);for(let t of c.getPorts())t.getSide()===`SOUTH`&&t.hasProperty(e._r)&&(this.portPositions[t.id]=o++,r.push(t));break;case`NORTH_SOUTH_PORT`:{let e=this.firstPortOnSide(c,t.INDEXING_SIDE);e!==null&&(this.portPositions[e.id]=o++,r.push(e)),this.countPortsOnSide(c,t.STACK_SIDE)>0&&i.push(c);break}case`LONG_EDGE`:for(let e of c.getPorts())e.getSide()===`WEST`&&(this.portPositions[e.id]=o++,r.push(e));for(let e=0,t=this.countPortsOnSide(c,`EAST`);e<t;e++)i.push(c)}}return this.emptyStack(i,r,t.STACK_SIDE,o),r}emptyStack(e,t,n,r){let i=r;for(;e.length>0;){let r=e.pop(),a=this.firstPortOnSide(r,n);this.portPositions[a.id]=i++,t.push(a)}return i}getPorts(e,t,n){return t===`EAST`?n?e.getPortSideView(t):[...e.getPortSideView(t)].reverse():n?[...e.getPortSideView(t)].reverse():e.getPortSideView(t)}firstPortOnSide(e,t){let n=e.getPorts();for(let e=0;e<n.length;e++)if(n[e].getSide()===t)return n[e];return null}countPortsOnSide(e,t){let n=e.getPorts(),r=0;for(let e=0;e<n.length;e++)n[e].getSide()===t&&r++;return r}start(e,t){return t?0:e.length-1}end(e,t,n){return t?e<n.length:e>=0}step(e){return e?1:-1}isInLayer(e){return e.getSource().getNode().getLayer()===e.getTarget().getNode().getLayer()}positionOf(e){return this.portPositions[e.id]??0}otherEndOf(e,t){return t===e.getSource()?e.getTarget():e.getSource()}isPortSelfLoop(e){return e.getSource()===e.getTarget()}isLayoutUnitChanged(t,n){return t===null||t===n||!n.hasProperty(e.Zn)?!1:n.getProperty(e.Zn)!==t}};function Qe(t,n){return t.getPortSideView(n).some(t=>t.hasProperty(e._r)||t.getConnectedEdges().length>0)}var $e=class{isCrossingMatrixFilled;crossingMatrix;inBetweenLayerCrossingCounter;direction;oneSided;constructor(e,t,n,r){this.direction=r,this.oneSided=e===1;let i=t[n];this.isCrossingMatrixFilled=Array.from({length:i.length},()=>Array(i.length).fill(!1)),this.crossingMatrix=Array.from({length:i.length},()=>Array(i.length).fill(0)),this.inBetweenLayerCrossingCounter=new tt(t,n)}getCrossingMatrixEntry(e,t){return this.isCrossingMatrixFilled[e.id][t.id]||(this.fillCrossingMatrix(e,t),this.isCrossingMatrixFilled[e.id][t.id]=!0,this.isCrossingMatrixFilled[t.id][e.id]=!0),this.crossingMatrix[e.id][t.id]}fillCrossingMatrix(e,t){this.oneSided?this.direction===1?this.inBetweenLayerCrossingCounter.countEasternEdgeCrossings(e,t):this.inBetweenLayerCrossingCounter.countWesternEdgeCrossings(e,t):this.inBetweenLayerCrossingCounter.countBothSideCrossings(e,t),this.crossingMatrix[e.id][t.id]=this.inBetweenLayerCrossingCounter.getUpperLowerCrossings(),this.crossingMatrix[t.id][e.id]=this.inBetweenLayerCrossingCounter.getLowerUpperCrossings()}},et=class{upperLowerCrossings=0;lowerUpperCrossings=0;portPositions=/* @__PURE__ */ new Map;layer;constructor(e){this.layer=e,this.initializePortPositions()}initializePortPositions(){for(let e of this.layer)this.setPortIdsOn(e,`SOUTH`),this.setPortIdsOn(e,`NORTH`)}setPortIdsOn(e,t){let n=0;for(let r of Ye(e,t))this.portPositions.set(r,n++)}countCrossings(e,t){this.upperLowerCrossings=0,this.lowerUpperCrossings=0,this.processIfTwoNorthSouthNodes(e,t),this.processIfNorthSouthLongEdgeDummyCrossing(e,t),this.processIfNormalNodeWithNSPortsAndLongEdgeDummy(e,t)}processIfTwoNorthSouthNodes(e,t){this.isNorthSouth(e)&&this.isNorthSouth(t)&&!this.haveDifferentOrigins(e,t)&&(this.isNorthOfNormalNode(e)?this.countCrossingsOfTwoNorthSouthDummies(e,t):this.countCrossingsOfTwoNorthSouthDummies(t,e))}countCrossingsOfTwoNorthSouthDummies(e,t){if(this.originPortPositionOf(e)>this.originPortPositionOf(t)){let n=t.getPortSideView(`EAST`);this.upperLowerCrossings=n.length===0?0:n[0].getDegree();let r=e.getPortSideView(`WEST`);this.lowerUpperCrossings=r.length===0?0:r[0].getDegree()}else{let n=t.getPortSideView(`WEST`);this.upperLowerCrossings=n.length===0?0:n[0].getDegree();let r=e.getPortSideView(`EAST`);this.lowerUpperCrossings=r.length===0?0:r[0].getDegree()}}processIfNorthSouthLongEdgeDummyCrossing(e,t){this.isNorthSouth(e)&&this.isLongEdgeDummy(t)?this.isNorthOfNormalNode(e)?this.upperLowerCrossings=1:this.lowerUpperCrossings=1:this.isNorthSouth(t)&&this.isLongEdgeDummy(e)&&(this.isNorthOfNormalNode(t)?this.lowerUpperCrossings=1:this.upperLowerCrossings=1)}processIfNormalNodeWithNSPortsAndLongEdgeDummy(e,t){this.isNormal(e)&&this.isLongEdgeDummy(t)&&(this.upperLowerCrossings=this.numberOfNorthSouthEdges(e,`SOUTH`),this.lowerUpperCrossings=this.numberOfNorthSouthEdges(e,`NORTH`)),this.isNormal(t)&&this.isLongEdgeDummy(e)&&(this.upperLowerCrossings=this.numberOfNorthSouthEdges(t,`NORTH`),this.lowerUpperCrossings=this.numberOfNorthSouthEdges(t,`SOUTH`))}numberOfNorthSouthEdges(e,t){let n=0;for(let r of e.getPortSideView(t))n+=+!!this.hasConnectedNorthSouthEdge(r);return n}hasConnectedNorthSouthEdge(t){return t.getProperty(e._r)!==null&&t.getProperty(e._r)!==void 0}haveDifferentOrigins(e,t){return this.originOf(e)!==this.originOf(t)}originPortPositionOf(e){return this.portPositions.get(this.originPortOf(e))}originPortOf(t){return t.getPorts()[0].getProperty(e.lr)}isNorthOfNormalNode(e){return this.originPortOf(e).getSide()===`NORTH`}originOf(t){return t.getProperty(e.lr)}isLongEdgeDummy(e){return e.getType()===`LONG_EDGE`}isNorthSouth(e){return e.getType()===`NORTH_SOUTH_PORT`}isNormal(e){return e.getType()===`NORMAL`}getUpperLowerCrossings(){return this.upperLowerCrossings}getLowerUpperCrossings(){return this.lowerUpperCrossings}},tt=class{currentNodeOrder;freeLayerIndex;upperLowerCrossings=0;lowerUpperCrossings=0;upperAdjacencies;lowerAdjacencies;portPositions=/* @__PURE__ */ new Map;easternAdjacencies=/* @__PURE__ */ new Map;westernAdjacencies=/* @__PURE__ */ new Map;constructor(e,t){this.currentNodeOrder=e,this.freeLayerIndex=t,this.setPortPositionsForNeighbouringLayers()}setPortPositionsForNeighbouringLayers(){this.freeLayerIndex>0&&this.setPortPositionsForLayer(this.freeLayerIndex-1,`EAST`),this.freeLayerIndex<this.currentNodeOrder.length-1&&this.setPortPositionsForLayer(this.freeLayerIndex+1,`WEST`)}setPortPositionsForLayer(e,t){let n=0;for(let r of this.currentNodeOrder[e])for(let e of Ye(r,t))this.portPositions.set(e,n++)}countEasternEdgeCrossings(e,t){this.resetCrossingCount(),e!==t&&this.addEasternCrossings(e,t)}countWesternEdgeCrossings(e,t){this.resetCrossingCount(),e!==t&&this.addWesternCrossings(e,t)}countBothSideCrossings(e,t){this.resetCrossingCount(),e!==t&&(this.addWesternCrossings(e,t),this.addEasternCrossings(e,t))}resetCrossingCount(){this.upperLowerCrossings=0,this.lowerUpperCrossings=0}addEasternCrossings(e,t){this.upperAdjacencies=this.getAdjacencyFor(e,`EAST`,this.easternAdjacencies),this.lowerAdjacencies=this.getAdjacencyFor(t,`EAST`,this.easternAdjacencies),this.upperAdjacencies.size()!==0&&this.lowerAdjacencies.size()!==0&&this.countCrossingsByMergingAdjacencyLists()}getAdjacencyFor(e,t,n){if(n.size===0)for(let e of this.currentNodeOrder[this.freeLayerIndex])n.set(e,new nt(e,t,this.portPositions));let r=n.get(e);return r.reset(),r}addWesternCrossings(e,t){this.upperAdjacencies=this.getAdjacencyFor(e,`WEST`,this.westernAdjacencies),this.lowerAdjacencies=this.getAdjacencyFor(t,`WEST`,this.westernAdjacencies),this.upperAdjacencies.size()!==0&&this.lowerAdjacencies.size()!==0&&this.countCrossingsByMergingAdjacencyLists()}countCrossingsByMergingAdjacencyLists(){for(;!this.upperAdjacencies.isEmpty()&&!this.lowerAdjacencies.isEmpty();)this.isBelow(this.upperAdjacencies.first(),this.lowerAdjacencies.first())?(this.upperLowerCrossings+=this.upperAdjacencies.size(),this.lowerAdjacencies.removeFirst()):this.isBelow(this.lowerAdjacencies.first(),this.upperAdjacencies.first())?(this.lowerUpperCrossings+=this.lowerAdjacencies.size(),this.upperAdjacencies.removeFirst()):(this.upperLowerCrossings+=this.upperAdjacencies.countAdjacenciesBelowNodeOfFirstPort(),this.lowerUpperCrossings+=this.lowerAdjacencies.countAdjacenciesBelowNodeOfFirstPort(),this.upperAdjacencies.removeFirst(),this.lowerAdjacencies.removeFirst())}isBelow(e,t){return e>t}getUpperLowerCrossings(){return this.upperLowerCrossings}getLowerUpperCrossings(){return this.lowerUpperCrossings}},nt=class{node;side;portPositions;adjacencyList=[];totalSize=0;currentSize=0;currentIndex=0;constructor(e,t,n){this.node=e,this.side=t,this.portPositions=n,this.getAdjacenciesSortedByPosition()}getAdjacenciesSortedByPosition(){this.iterateThroughEdgesCollectingAdjacencies(),this.adjacencyList.sort((e,t)=>e.position-t.position)}iterateThroughEdgesCollectingAdjacencies(){for(let e of Ye(this.node,this.side)){let t=this.side===`WEST`?e.getIncomingEdges():e.getOutgoingEdges();for(let e of t)!e.isSelfLoop()&&!this.isInLayer(e)&&(this.addAdjacencyOf(e),this.totalSize++,this.currentSize++)}}isInLayer(e){return e.getSource().getNode().getLayer()===e.getTarget().getNode().getLayer()}addAdjacencyOf(e){let t=this.side===`WEST`?e.getSource():e.getTarget(),n=this.portPositions.get(t),r=this.adjacencyList.length-1;this.adjacencyList.length>0&&this.adjacencyList[r].position===n?(this.adjacencyList[r].cardinality++,this.adjacencyList[r].currentCardinality++):this.adjacencyList.push(new rt(n))}reset(){this.currentIndex=0,this.currentSize=this.totalSize,this.isEmpty()||this.currentAdjacency().reset()}countAdjacenciesBelowNodeOfFirstPort(){return this.currentSize-this.currentAdjacency().currentCardinality}removeFirst(){if(this.isEmpty())return;let e=this.currentAdjacency();e.currentCardinality===1?this.incrementCurrentIndex():e.currentCardinality--,this.currentSize--}incrementCurrentIndex(){this.currentIndex++,this.currentIndex<this.adjacencyList.length&&this.currentAdjacency().reset()}isEmpty(){return this.currentSize===0}first(){return this.currentAdjacency().position}size(){return this.currentSize}currentAdjacency(){return this.adjacencyList[this.currentIndex]}},rt=class{position;cardinality=1;currentCardinality=1;constructor(e){this.position=e}reset(){this.currentCardinality=this.cardinality}},it=class{freeLayer;leftInLayerCounter;rightInLayerCounter;northSouthCounter;crossingMatrixFiller;graphData;parentCrossCounter=null;countCrossingsCausedByPortSwitch;constructor(e,t,n,r,i,a){if(this.crossingMatrixFiller=n,this.graphData=i,e>=t.length)throw Error(`Greedy SwitchDecider: Free layer not in graph.`);this.freeLayer=t[e],this.leftInLayerCounter=new Ze(r),this.leftInLayerCounter.initPortPositionsForInLayerCrossings(this.freeLayer,`WEST`),this.rightInLayerCounter=new Ze(r),this.rightInLayerCounter.initPortPositionsForInLayerCrossings(this.freeLayer,`EAST`),this.northSouthCounter=new et(this.freeLayer),this.countCrossingsCausedByPortSwitch=!a&&i.hasParent&&!i.dontSweepInto()&&this.freeLayer[0].getType()===`EXTERNAL_PORT`,this.countCrossingsCausedByPortSwitch&&this.initParentCrossingsCounters(e,t.length)}initParentCrossingsCounters(e,t){let n=this.graphData.parentGraphData,r=n.currentNodeOrder,i=n.portPositions;this.parentCrossCounter=new Ze(i);let a=this.graphData.parent.getLayer().id,o=a>0?r[a-1]:[],s=r[a],c=a<r.length-1?r[a+1]:[];e===t-1?this.parentCrossCounter.initForCountingBetween(s,c):this.parentCrossCounter.initForCountingBetween(o,s)}notifyOfSwitch(t,n){if(this.leftInLayerCounter.switchNodes(t,n,`WEST`),this.rightInLayerCounter.switchNodes(t,n,`EAST`),this.countCrossingsCausedByPortSwitch){let r=t.getProperty(e.lr),i=n.getProperty(e.lr);this.parentCrossCounter.switchPorts(r,i)}}doesSwitchReduceCrossings(t,n){if(this.constraintsPreventSwitch(t,n))return!1;let r=this.freeLayer[t],i=this.freeLayer[n],a=this.leftInLayerCounter.countInLayerCrossingsBetweenNodesInBothOrders(r,i,`WEST`),o=this.rightInLayerCounter.countInLayerCrossingsBetweenNodesInBothOrders(r,i,`EAST`);this.northSouthCounter.countCrossings(r,i);let s=this.crossingMatrixFiller.getCrossingMatrixEntry(r,i),c=this.crossingMatrixFiller.getCrossingMatrixEntry(i,r),l=s+a.first+o.first+this.northSouthCounter.getUpperLowerCrossings(),u=c+a.second+o.second+this.northSouthCounter.getLowerUpperCrossings();if(this.countCrossingsCausedByPortSwitch){let t=r.getProperty(e.lr),n=i.getProperty(e.lr),a=this.parentCrossCounter.countCrossingsBetweenPortsInBothOrders(t,n);l+=a.first,u+=a.second}return l>u}constraintsPreventSwitch(e,t){let n=this.freeLayer[e],r=this.freeLayer[t];return this.haveSuccessorConstraints(n,r)||this.haveLayoutUnitConstraints(n,r)||this.areNormalAndNorthSouthPortDummy(n,r)}haveSuccessorConstraints(t,n){let r=t.getProperty(e.Qn);return r!=null&&r.length!==0&&r.includes(n)}haveLayoutUnitConstraints(t,n){let r=t.getType()!==`LONG_EDGE`&&n.getType()!==`LONG_EDGE`,i=t.getProperty(e.Zn),a=n.getProperty(e.Zn),o=i!==a,s=this.partOfMultiNodeLayoutUnit(t,i)||this.partOfMultiNodeLayoutUnit(n,a),c=Qe(t,`NORTH`),l=Qe(n,`SOUTH`);return s=s||Qe(t,`SOUTH`)||Qe(n,`NORTH`),r&&(s&&o||c||l)}partOfMultiNodeLayoutUnit(e,t){return t!=null&&t!==e}areNormalAndNorthSouthPortDummy(e,t){return this.isNorthSouthPortNode(e)&&this.isNormalNode(t)||this.isNorthSouthPortNode(t)&&this.isNormalNode(e)}isNormalNode(e){return e.getType()===`NORMAL`}isNorthSouthPortNode(e){return e.getType()===`NORTH_SOUTH_PORT`}},at=class{greedySwitchType;graphData;currentNodeOrder;switchDecider;nPorts=0;portPositions=[];constructor(e,t){this.greedySwitchType=e,this.graphData=t}minimizeCrossings(e,t,n,r){return this.setUp(e,t,n),this.continueSwitchingUntilNoImprovementInLayer(t)}setFirstLayerOrder(e,t){let n=t?0:e.length-1;return this.setUp(e,n,t),this.sweepDownwardInLayer(n)}alwaysImproves(){return this.greedySwitchType!==1}isDeterministic(){return!0}initAtLayerLevel(){}initAtNodeLevel(e,t,n){n[e][t].id=t}initAtPortLevel(){this.nPorts++}initAtEdgeLevel(){}initAfterTraversal(){this.portPositions=Array(this.nPorts)}setUp(e,t,n){this.currentNodeOrder=e;let r=+!n,i=new $e(this.greedySwitchType,e,t,r);this.switchDecider=new it(t,e,i,this.portPositions,this.graphData,this.greedySwitchType===1)}continueSwitchingUntilNoImprovementInLayer(e){let t=!1,n;do n=this.sweepDownwardInLayer(e),t||=n;while(n);return t}sweepDownwardInLayer(e){let t=this.currentNodeOrder[e],n=!1;for(let e=0;e<t.length-1;e++){if(!this.switchDecider.doesSwitchReduceCrossings(e,e+1))continue;this.switchDecider.notifyOfSwitch(t[e],t[e+1]);let r=t[e];t[e]=t[e+1],t[e+1]=r,n=!0}return n}},ot=class{skipInitAtLayerLevel=!0;skipInitAtPortLevel=!0;skipInitAtEdgeLevel=!0;crossingsCounter;hierarchicalCrossingsCounter;nPorts=0;portPositions=[];distributePortsWhileSweeping(t,n,r){let i=r?`WEST`:`EAST`;r&&n>0?this.crossingsCounter.initForCountingBetween(t[n-1],t[n]):!r&&n<t.length-1?this.crossingsCounter.initForCountingBetween(t[n],t[n+1]):this.crossingsCounter.initPortPositionsForInLayerCrossings(t[n],i);let a=!1;for(let o of t[n]){let t=o.getProperty(e.Lt);if(e.Lr.isOrderFixed(t))continue;let n=o.getNestedGraph(),s=o.getPortSideView(i).length>0&&n!==null;if(s){let e=n.toNodeArray();this.hierarchicalCrossingsCounter=new tt(e,r?0:e.length-1)}a=this.distributePortsOnNode(o,i,s)||a}return a}initAtLayerLevel(){}initAtNodeLevel(e,t,n){this.nPorts+=n[e][t].getPorts().length}initAtPortLevel(){}initAtEdgeLevel(){}initAfterTraversal(){this.portPositions=Array(this.nPorts),this.crossingsCounter=new Ze(this.portPositions)}distributePortsOnNode(e,t,n){let r=e.getPortSideView(t);(t===`SOUTH`||t===`WEST`)&&(r=[...r].reverse());let i=!1,a;do{a=!1;for(let t=0;t<r.length-1;t++){let o=r[t],s=r[t+1];if(this.switchingDecreasesCrossings(o,s,n)){this.crossingsCounter.switchPorts(o,s),r[t]=s,r[t+1]=o;let n=e.getPorts(),c=n.indexOf(o),l=n.indexOf(s);c>=0&&l>=0&&(n[c]=s,n[l]=o),i=!0,a=!0}}}while(a);return i}switchingDecreasesCrossings(t,n,r){let i=this.crossingsCounter.countCrossingsBetweenPortsInBothOrders(t,n),a=i.first,o=i.second;if(r){let r=t.getProperty(e._r),i=n.getProperty(e._r);r!=null&&i!=null&&(this.hierarchicalCrossingsCounter.countBothSideCrossings(r,i),a+=this.hierarchicalCrossingsCounter.getUpperLowerCrossings(),o+=this.hierarchicalCrossingsCounter.getLowerUpperCrossings())}return a>o}};const st={NORTH:0,EAST:1,SOUTH:2,WEST:3};var ct=class{skipInitAtEdgeLevel=!0;portRanks;minBarycenter=0;maxBarycenter=0;nodePositions;portBarycenter;inLayerPorts=[];nPorts=0;nodeLayerIndex=/* @__PURE__ */ new WeakMap;scratchPorts=[];portHasIncoming=[];portHasOutgoing=[];portDegrees=[];debugSortPorts=!1;debugPortRanks=!1;constructor(e){this.nodePositions=Array(e)}getPortRanks(){return this.portRanks}distributePortsWhileSweeping(t,n,r){this.debugSortPorts=!1,this.updateNodePositions(t,n);let i=t[n],a=r?`WEST`:`EAST`;if(this.isNotFirstLayer(t.length,n,r)){let o=t[r?n-1:n+1];this.calculatePortRanksForLayer(o,this.portTypeFor(r));for(let e of i)this.distributePorts(e,a);this.calculatePortRanksForLayer(i,this.portTypeFor(!r));for(let t of o)this.hasNestedGraph(t)||this.distributePorts(t,e.Rr.opposed(a))}else for(let e of i)this.distributePorts(e,a);return!1}calculatePortRanksForLayer(e,t){this.debugPortRanks=!1;let n=0,r=e.length;for(let i=0;i<r;i++){let r=e[i];n+=this.calculatePortRanks(r,r.getPorts(),n,t)}}distributePorts(t,n){if(typeof n==`string`){let r=n;e.Lr.isOrderFixed(t.getProperty(e.Lt))||(this.distributePorts(t,this.collectPortsOnSide(t,r)),this.distributePorts(t,this.collectPortsOnSide(t,`SOUTH`)),this.distributePorts(t,this.collectPortsOnSide(t,`NORTH`)),this.sortPorts(t));return}let r=n;this.inLayerPorts.length=0,this.iteratePortsAndCollectInLayerPorts(t,r),this.inLayerPorts.length>0&&this.calculateInLayerPortsBarycenterValues(t)}collectPortsOnSide(e,t){this.scratchPorts.length=0;let n=e.getPorts();for(let e=0;e<n.length;e++)n[e].getSide()===t&&this.scratchPorts.push(n[e]);return this.scratchPorts}iteratePortsAndCollectInLayerPorts(t,n){this.minBarycenter=0,this.maxBarycenter=0;let r=t.getLayer(),i=2*r.getNodes().length+1;for(let t=0;t<n.length;t++){let a=n[t],o=a.getSide()===`NORTH`||a.getSide()===`SOUTH`,s=0;if(o){let t=a.getProperty(e._r);if(t==null)continue;s+=this.dealWithNorthSouthPorts(i,a,t)}else{for(let e of a.getOutgoingEdges()){let t=e.getTarget();t.getNode().getLayer()===r?this.inLayerPorts.push(a):s+=this.portRanks[t.id]}for(let e of a.getIncomingEdges()){let t=e.getSource();t.getNode().getLayer()===r?this.inLayerPorts.push(a):s-=this.portRanks[t.id]}}let c=this.portDegrees[a.id]??a.getDegree();c>0?(this.portBarycenter[a.id]=s/c,this.minBarycenter=Math.min(this.minBarycenter,this.portBarycenter[a.id]),this.maxBarycenter=Math.max(this.maxBarycenter,this.portBarycenter[a.id])):o&&(this.portBarycenter[a.id]=s)}}calculateInLayerPortsBarycenterValues(e){let t=this.positionOf(e)+1,n=e.getLayer(),r=n.getNodes().length+1;for(let e of this.inLayerPorts){let i=0,a=0;for(let t of e.getIncomingEdges()){let e=t.getSource();e.getNode().getLayer()===n&&(i+=this.positionOf(e.getNode())+1,a++)}for(let t of e.getOutgoingEdges()){let e=t.getTarget();e.getNode().getLayer()===n&&(i+=this.positionOf(e.getNode())+1,a++)}let o=i/a,s=e.getSide();s===`EAST`?this.portBarycenter[e.id]=o<t?this.minBarycenter-o:this.maxBarycenter+(r-o):s===`WEST`&&(this.portBarycenter[e.id]=o<t?this.maxBarycenter+o:this.minBarycenter-(r-o))}}dealWithNorthSouthPorts(t,n,r){let i=!1,a=!1;for(let t of r.getPorts())t.getProperty(e.lr)===n&&(t.getOutgoingEdges().length>0?a=!0:t.getIncomingEdges().length>0&&(i=!0));let o=0;return i&&!(i&&a)?o=n.getSide()===`NORTH`?-this.positionOf(r):t-this.positionOf(r):a&&!(i&&a)?o=this.positionOf(r)+1:i&&a&&(o=n.getSide()===`NORTH`?0:t/2),o}positionOf(e){return this.nodePositions[this.nodeLayerIndex.get(e)][e.id]}updateNodePositions(e,t){let n=e[t];if(n.length===0)return;let r=this.nodePositions[this.nodeLayerIndex.get(n[0])];for(let e=0;e<n.length;e++){let t=n[e];r[t.id]=e}}hasNestedGraph(e){return e.getNestedGraph()!==null}isNotFirstLayer(e,t,n){return n?t!==0:t!==e-1}portTypeFor(e){return e?`OUTPUT`:`INPUT`}sortPorts(e){if(this.debugSortPorts){let t=e.getPorts().map(e=>`${e.id}:${e.getSide()}(${this.portBarycenter[e.id]})`).join(` `);console.error(`GGN sortPorts L${e.getLayer().getIndex()} node=${e.id} before=[${t}]`)}e.getPorts().sort(this.portComparator),this.debugSortPorts&&console.error(`GGN sortPorts node=${e.id} after=[${e.getPorts().map(e=>e.id).join(` `)}]`)}portComparator=(e,t)=>{let n=st[e.getSide()]??0,r=st[t.getSide()]??0;if(n!==r)return n-r;let i=this.portBarycenter[e.id],a=this.portBarycenter[t.id];return i===0&&a===0?0:i===0?-1:a===0?1:i-a};initAtLayerLevel(e,t){this.nodePositions[e]=Array(t[e].length);let n=t[e];for(let t=0;t<n.length;t++)this.nodeLayerIndex.set(n[t],e)}initAtNodeLevel(e,t,n){let r=n[e][t];r.id=t,this.nodePositions[e][t]=t}initAtPortLevel(e,t,n,r){let i=r[e][t].getPorts()[n];i.id=this.nPorts++;let a=i.getIncomingEdges(),o=i.getOutgoingEdges();this.portHasIncoming[i.id]=+(a.length>0),this.portHasOutgoing[i.id]=+(o.length>0),this.portDegrees[i.id]=a.length+o.length}initAtEdgeLevel(){}initAfterTraversal(){this.portRanks=Array(this.nPorts).fill(0),this.portBarycenter=Array(this.nPorts).fill(0)}},lt=class extends ct{constructor(e){super(e)}calculatePortRanks(e,t,n,r){let i=this.portRanks;if(r===`INPUT`){let r=0,a=0;for(let e=0;e<t.length;e++){let n=t[e],i=this.portHasIncoming[n.id];(i===1||i===void 0&&n.getIncomingEdges().length>0)&&(r++,n.getSide()===`NORTH`&&a++)}let o=n+a,s=n+r;for(let n=0;n<t.length;n++){let r=t[n],a=this.portHasIncoming[r.id];if(!(a===0||a===void 0&&r.getIncomingEdges().length===0)&&(r.getSide()===`NORTH`?(i[r.id]=o,o--):(i[r.id]=s,s--),this.debugPortRanks)){let t=r.getIncomingEdges(),n=t.length>0?`<-${t[0].getSource().getNode().id}`:``;console.error(`GGN rank INPUT node=${e.id} L${e.getLayer().getIndex()} port=${r.id} rank=${i[r.id]} conn=${n}`)}}return r}if(r===`OUTPUT`){let e=0;for(let r=0;r<t.length;r++){let a=t[r],o=this.portHasOutgoing[a.id];o===0||o===void 0&&a.getOutgoingEdges().length===0||(e++,i[a.id]=n+e)}return e}throw Error(`IllegalArgumentException`)}},ut=class extends ct{constructor(e){super(e)}calculatePortRanks(e,t,n,r){let i=this.portRanks;if(r===`INPUT`){let e=0,r=0;for(let n=0;n<t.length;n++){let i=t[n],a=this.portHasIncoming[i.id];(a===1||a===void 0&&i.getIncomingEdges().length>0)&&(e++,i.getSide()===`NORTH`&&r++)}let a=1/(e+1),o=n+r*a,s=n+1-a;for(let e=0;e<t.length;e++){let n=t[e],r=this.portHasIncoming[n.id];r===0||r===void 0&&n.getIncomingEdges().length===0||(n.getSide()===`NORTH`?(i[n.id]=o,o-=a):(i[n.id]=s,s-=a))}}else if(r===`OUTPUT`){let e=0;for(let n=0;n<t.length;n++){let r=t[n],i=this.portHasOutgoing[r.id];(i===1||i===void 0&&r.getOutgoingEdges().length>0)&&e++}let r=1/(e+1),a=n+r;for(let e=0;e<t.length;e++){let n=t[e],o=this.portHasOutgoing[n.id];o===0||o===void 0&&n.getOutgoingEdges().length===0||(i[n.id]=a,a+=r)}}else throw Error(`Port type is undefined`);return 1}};function dt(e,t,n){return e===2?new ot:t.nextBoolean()?new ut(n.length):new lt(n.length)}var ft=class{portPos;inInterlayerCache=null;outInterlayerEdges=null;hyperedgeGroupsByLayer=/* @__PURE__ */ new WeakMap;bounds=/* @__PURE__ */ new Int32Array;constructor(e,t,n){this.portPos=n}getOutInterlayerEdges(e,t){let n=this.outInterlayerEdges??=[],r=n[e.id];if(r===void 0){r=[];let i=e.getOutgoingEdges();for(let e=0;e<i.length;e++){let n=i[e];t!==n.getTarget().getNode().getLayer()&&r.push(n)}n[e.id]=r}return r}getIncomingInterlayerFlag(e,t){let n=this.inInterlayerCache??=new Uint8Array(this.portPos.length).fill(2),r=n[e.id];if(r!==2)return r;r=0;let i=e.getIncomingEdges();for(let e=0;e<i.length;e++)if(t!==i[e].getSource().getNode().getLayer()){r=1;break}return n[e.id]=r,r}buildHyperedgeGroups(e){let t=/* @__PURE__ */ new Map,n=/* @__PURE__ */ new Map,r=e=>{let n=e;for(;t.get(n)!==n;)n=t.get(n);let r=e;for(;t.get(r)!==r;){let e=t.get(r);t.set(r,n),r=e}return n},i=(e,n)=>{let i=r(e),a=r(n);i!==a&&t.set(a,i)};for(let r=0;r<e.length;r++){let a=e[r],o=a.getLayer(),s=a.getPorts();for(let e=0;e<s.length;e++){let r=s[e],a=this.getOutInterlayerEdges(r,o);if(a.length!==0){t.has(r.id)||(t.set(r.id,r.id),n.set(r.id,r));for(let e=0;e<a.length;e++){let o=a[e].getTarget();t.has(o.id)||(t.set(o.id,o.id),n.set(o.id,o)),i(r.id,o.id)}}}}let a=/* @__PURE__ */ new Map;for(let[e]of t){let t=r(e),i=a.get(t);i===void 0&&(i=[],a.set(t,i)),i.push(n.get(e))}return[...a.values()]}getHyperedgeGroups(e){let t=e[0].getLayer(),n=this.hyperedgeGroupsByLayer.get(t);return n===void 0&&(n=this.buildHyperedgeGroups(e),this.hyperedgeGroupsByLayer.set(t,n)),n}countCrossings(e,t){let n=this.getHyperedgeGroups(e),r=0;for(let t=0;t<e.length;t++){let n=e[t],i=n.getLayer(),a=n.getPorts();for(let e=0;e<a.length;e++){let t=a[e];this.getOutInterlayerEdges(t,i).length>0&&(this.portPos[t.id]=r++)}}let i=0;for(let e=0;e<t.length;e++){let n=t[e],r=n.getLayer(),a=0,o=n.getPorts();for(let e=0;e<o.length;e++){let t=o[e];if(t.getSide()!==`NORTH`)break;this.getIncomingInterlayerFlag(t,r)===1&&a++}let s=0;for(let e=o.length-1;e>=0;e--){let t=o[e];this.getIncomingInterlayerFlag(t,r)===1&&(t.getSide()===`NORTH`?(this.portPos[t.id]=i,i++):(this.portPos[t.id]=i+a+s,s++))}i+=s}let a=n.length;this.bounds.length<a*4&&(this.bounds=new Int32Array(a*4));let o=this.bounds,s=e[0].getLayer(),c=t[0].getLayer();for(let e=0;e<a;e++){let t=n[e],a=r,l=0,u=i,d=0;for(let e=0;e<t.length;e++){let n=t[e],r=this.portPos[n.id],i=n.getNode().getLayer();i===s?(r<a&&(a=r),r>l&&(l=r)):i===c&&(r<u&&(u=r),r>d&&(d=r))}let f=e*4;o[f]=a,o[f+1]=l,o[f+2]=u,o[f+3]=d}let l=0;for(let e=0;e<a;e++){let t=e*4,n=o[t],r=o[t+1],i=o[t+2],s=o[t+3];for(let t=e+1;t<a;t++){let e=t*4,a=o[e],c=o[e+1],u=o[e+2],d=o[e+3];(n<a&&i>u||a<n&&u>i)&&l++,((n>a?n:a)<(r<c?r:c)||n===r&&a<n&&n<c||a===c&&n<a&&a<r)&&l++,((i>u?i:u)<(s<d?s:d)||i===s&&u<i&&i<d||u===d&&i<u&&u<s)&&l++}}return l}};function pt(e,t){let n=[],r=[],i=[],a=[],o=[];for(let t=0;t<e.length;t++){let s=e[t];s.skipInitAtLayerLevel!==!0&&n.push(s),s.skipInitAtNodeLevel!==!0&&r.push(s),s.skipInitAtPortLevel!==!0&&i.push(s),s.skipInitAtEdgeLevel!==!0&&a.push(s),s.skipInitAfterTraversal!==!0&&o.push(s)}for(let e=0;e<t.length;e++){for(let r=0;r<n.length;r++)n[r].initAtLayerLevel(e,t);for(let n=0;n<t[e].length;n++){for(let i=0;i<r.length;i++)r[i].initAtNodeLevel(e,n,t);let o=t[e][n].getPorts();for(let r=0;r<o.length;r++){for(let a=0;a<i.length;a++)i[a].initAtPortLevel(e,n,r,t);let s=o[r],c=0,l=s.getIncomingEdges();for(let i=0;i<l.length;i++){let o=l[i];for(let i=0;i<a.length;i++)a[i].initAtEdgeLevel(e,n,r,c++,o,t)}let u=s.getOutgoingEdges();for(let i=0;i<u.length;i++){let o=u[i];for(let i=0;i<a.length;i++)a[i].initAtEdgeLevel(e,n,r,c++,o,t)}}}}for(let e=0;e<o.length;e++)o[e].initAfterTraversal()}var mt=class{skipInitAtLayerLevel=!0;crossingCounter;hyperedgeCrossingsCounter;hasHyperEdgesEastOfIndex;inLayerEdgeCounts;hasNorthSouthPorts;nPorts=0;constructor(e){this.inLayerEdgeCounts=Array(e.length).fill(0),this.hasNorthSouthPorts=Array(e.length).fill(!1),this.hasHyperEdgesEastOfIndex=Array(e.length).fill(!1)}countAllCrossings(e){if(e.length===0)return 0;let t=this.crossingCounter.countInLayerCrossingsOnSide(e[0],`WEST`);t+=this.crossingCounter.countInLayerCrossingsOnSide(e[e.length-1],`EAST`);for(let n=0;n<e.length;n++)t+=this.countCrossingsAt(n,e);return t}countCrossingsAt(e,t){let n=0,r=t[e];if(e<t.length-1){let i=t[e+1];this.hasHyperEdgesEastOfIndex[e]?(n=this.hyperedgeCrossingsCounter.countCrossings(r,i),n+=this.crossingCounter.countInLayerCrossingsOnSide(r,`EAST`),n+=this.crossingCounter.countInLayerCrossingsOnSide(i,`WEST`)):n=this.crossingCounter.countCrossingsBetweenLayers(r,i)}return this.hasNorthSouthPorts[e]&&(n+=this.crossingCounter.countNorthSouthPortCrossingsInLayer(r)),n}initAtNodeLevel(e,t,n){let r=n[e][t];this.hasNorthSouthPorts[e]=this.hasNorthSouthPorts[e]||r.getType()===`NORTH_SOUTH_PORT`}initAtPortLevel(e,t,n,r){let i=r[e][t].getPorts()[n];i.id=this.nPorts++,i.getOutgoingEdges().length+i.getIncomingEdges().length>1&&(i.getSide()===`EAST`?this.hasHyperEdgesEastOfIndex[e]=!0:i.getSide()===`WEST`&&e>0&&(this.hasHyperEdgesEastOfIndex[e-1]=!0))}initAtEdgeLevel(e,t,n,r,i,a){let o=a[e][t].getPorts()[n];i.getSource()===o&&i.getSource().getNode().getLayer()===i.getTarget().getNode().getLayer()&&this.inLayerEdgeCounts[e]++}initAtLayerLevel(){}initAfterTraversal(){let e=Array(this.nPorts);this.hyperedgeCrossingsCounter=new ft(this.inLayerEdgeCounts,this.hasNorthSouthPorts,e),this.crossingCounter=new Ze(e)}};const ht=()=>({connectedEdges:0,hierarchicalInfluence:0,randomInfluence:0});function gt(e,t){e.hierarchicalInfluence+=t.hierarchicalInfluence,e.randomInfluence+=t.randomInfluence,e.connectedEdges+=t.connectedEdges}function _t(t){let n=t.lGraph.getProperty(e.Fn);if(xt(n)||!t.hasParent||yt(t)||bt(t))return!0;if(t.crossMinDeterministic)return!1;let r=t.currentNodeOrder.map(e=>e.map(()=>ht())),i=e=>r[e.getLayer().getIndex()][e.id],a=0,o=0,s=[];for(let n of t.currentNodeOrder){for(let t of n){if(t.getType()===`NORTH_SOUTH_PORT`){s.push(t);continue}let n=i(t);t.getType()===`EXTERNAL_PORT`?(n.hierarchicalInfluence=1,wt(t)&&(o+=n.connectedEdges)):Ct(t)?n.randomInfluence=1:St(t)&&(a+=n.connectedEdges);for(let e of t.getOutgoingEdges())a+=n.randomInfluence,o+=n.hierarchicalInfluence,vt(i,n,e);for(let r of[...t.getPortSideView(`NORTH`),...t.getPortSideView(`SOUTH`)]){let t=r.getProperty(e._r);if(t!=null){a+=n.randomInfluence,o+=n.hierarchicalInfluence;let e=i(t);gt(e,n),e.connectedEdges++}}}for(let e of s){let t=i(e);for(let n of e.getOutgoingEdges())a+=t.randomInfluence,o+=t.hierarchicalInfluence,vt(i,t,n)}s.length=0}let c=a+o;return(c===0?1/0:(a-o)/c)>=n}function vt(e,t,n){let r=e(n.getTarget().getNode());gt(r,t),r.connectedEdges++}function yt(t){return e.Lr.isOrderFixed(t.parent.getProperty(e.Lt))}function bt(e){return e.parent.getPortSideView(`EAST`).length<2&&e.parent.getPortSideView(`WEST`).length<2}function xt(e){return e<-1}function St(e){let t=e.getPortSideView(`EAST`);return t.length===0||!t.some(e=>e.getConnectedEdges().length>0)}function Ct(e){let t=e.getPortSideView(`WEST`);return t.length===0||!t.some(e=>e.getConnectedEdges().length>0)}function wt(t){return t.getProperty(e.lr).getSide()===`EAST`}const Tt=[];var Et=class{nodes;index=-1;barycenter=null;outgoing=null;incoming=null;incomingCount=0;summedWeight;degree;constructor(e,t){if(t!==void 0){let n=e,r=t;this.nodes=Array(n.nodes.length+r.nodes.length);let i=0;for(let e=0;e<n.nodes.length;e++)this.nodes[i++]=n.nodes[e];for(let e=0;e<r.nodes.length;e++)this.nodes[i++]=r.nodes[e];if(n.outgoing!==null){let e=[];for(let t=0;t<n.outgoing.length;t++){let i=n.outgoing[t];i!==r&&e.push(i)}if(r.outgoing!==null)for(let t=0;t<r.outgoing.length;t++){let i=r.outgoing[t];i!==n&&(e.includes(i)?i.incomingCount--:e.push(i))}this.outgoing=e}else if(r.outgoing!==null){let e=[];for(let t=0;t<r.outgoing.length;t++){let i=r.outgoing[t];i!==n&&e.push(i)}this.outgoing=e}this.summedWeight=n.summedWeight+r.summedWeight,this.degree=n.degree+r.degree}else this.nodes=[e],this.summedWeight=0,this.degree=0}getSummedWeight(){return this.summedWeight}getDegree(){return this.degree}getOutgoing(){return this.outgoing??=[],this.outgoing}getIncoming(){return this.incoming??=[],this.incoming}resetOutgoing(){this.outgoing=null}resetIncoming(){this.incoming=null}hasOutgoing(){return this.outgoing!==null&&this.outgoing.length>0}hasIncoming(){return this.incoming!==null&&this.incoming.length>0}getBarycenter(e){return e(this.nodes[0]).barycenter}},Dt=class{skipInitAtLayerLevel=!0;skipInitAtPortLevel=!0;skipInitAtEdgeLevel=!0;skipInitAfterTraversal=!0;barycenterStates;nodeState=/* @__PURE__ */ new WeakMap;groups=/* @__PURE__ */ new Map;layoutUnits=/* @__PURE__ */ new Map;constraintsBetweenNonDummies;scratchGroups=[];constructor(t){this.barycenterStates=t.map(e=>e.map(e=>{let t=new Ot(e);return this.nodeState.set(e,t),t})),this.constraintsBetweenNonDummies=t.length>0&&t[0].length>0&&t[0][0].getGraph().getProperty(e.$n)}getBarycenterStates(){return this.barycenterStates}registerNodeState(e,t){this.nodeState.set(e,t)}initAtLayerLevel(e,t){}initAtNodeLevel(e,t,n){this.initNode(n[e][t],!0)}initNode(t,n){if(this.groups.set(t,new Et(t)),n){let n=t.getProperty(e.Zn);if(n!==null){let e=this.layoutUnits.get(n);e===void 0?this.layoutUnits.set(n,[t]):e.push(t)}}}initAtPortLevel(){}initAtEdgeLevel(){}initAfterTraversal(){}stateOf(e){return this.nodeState.get(e)}processConstraints(e){if(this.constraintsBetweenNonDummies){this.processConstraintsStage(e,!0);for(let t of e)this.initNode(t,!1)}this.processConstraintsStage(e,!1)}processConstraintsStage(e,t){let n=this.scratchGroups;n.length=0;for(let t=0;t<e.length;t++)n.push(this.groups.get(e[t]));this.buildConstraintsGraph(n,t);let r=this.findViolatedConstraint(n);for(;r!==null;)this.handleViolatedConstraint(r[0],r[1],n),r=this.findViolatedConstraint(n);e.length=0;for(let t of n){let n=t.barycenter;for(let r of t.nodes)e.push(r),this.stateOf(r).barycenter=n}}buildConstraintsGraph(t,n){for(let e of t)e.resetOutgoing(),e.incomingCount=0;let r=null;for(let i of t){let t=i.nodes[0];if(!(n&&t.getType()!==`NORMAL`)){for(let r of t.getProperty(e.Qn)??Tt)if(!n||r.getType()===`NORMAL`){let e=this.groups.get(r);if(e===void 0){let e=r.getLayer(),n=t.getLayer();console.error(`GGN_FORSTER BUG: successor id=${r.id} label=${r.getLabels()[0]?.text??`?`} type=${r.getType()} layer=${e?.getIndex()??`UNDEF`} graphParent=${r.getGraph()?.getParentNode()?`nested`:`root`} | node id=${t.id} label=${t.getLabels()[0]?.text??`?`} type=${t.getType()} layer=${n?.getIndex()??`UNDEF`} graphParent=${t.getGraph()?.getParentNode()?`nested`:`root`} | graphNodeCount=${r.getGraph()?.getAllNodes().length}`);continue}i.getOutgoing().push(e),e.incomingCount++}if(!n&&t.getType()===`NORMAL`){if(r!==null){let e=this.layoutUnits.get(r)??Tt,n=this.layoutUnits.get(t)??Tt;for(let t of e)for(let e of n){let n=this.groups.get(t),r=this.groups.get(e);n.getOutgoing().push(r),r.incomingCount++}}r=t}}}}findViolatedConstraint(e){let t=e=>this.stateOf(e);for(let n=0;n<e.length;n++){let r=e[n];r.index=n,r.barycenter=t(r.nodes[0]).barycenter}let n=[];for(let t of e)t.resetIncoming(),t.hasOutgoing()&&t.incomingCount===0&&n.push(t);let r=0;for(;r<n.length;){let e=n[r++];if(e.hasIncoming()){let t=e.barycenter;for(let n of e.getIncoming()){let r=n.barycenter;if(r===t){if(n.index>e.index)return[n,e]}else if(r>t)return[n,e]}}for(let t of e.getOutgoing())t.getIncoming().unshift(e),t.incomingCount===t.getIncoming().length&&n.push(t)}return null}handleViolatedConstraint(e,t,n){let r=e=>this.stateOf(e),i=new Et(e,t),a=e.barycenter,o=t.barycenter,s=null,c=e.getSummedWeight()+t.getSummedWeight(),l=e.getDegree()+t.getDegree();if(l>0?s=c/l:a!==null&&o!==null?s=(a+o)/2:a===null?o!==null&&(s=o):s=a,s!==null)for(let e of i.nodes)this.stateOf(e).barycenter=s;i.barycenter=s;let u=!1;for(let a=0;a<n.length;a++){let o=n[a];if(o===e||o===t)n.splice(a,1),a--;else if(!u&&(o.getBarycenter(r)??0)>(i.getBarycenter(r)??0))n.splice(a,0,i),u=!0;else if(o.hasOutgoing()){let n=o.getOutgoing(),r=!0,a=!0,s=!1;for(let i=0;i<n.length;){let o=n[i];r&&o===e?(n.splice(i,1),r=!1,s=!0):a&&o===t?(n.splice(i,1),a=!1,s=!0):i++}s&&(n.push(i),i.incomingCount++)}}u||n.push(i)}},Ot=class{node;summedWeight=0;degree=0;barycenter=null;visited=!1;visitedGeneration=-1;forwardAdjacency=[];backwardAdjacency=[];constructor(e){this.node=e}};const kt=.07;function At(e){return e.getAllProperties().get(`org.eclipse.elk.hierarchyHandling`)===`SEPARATE_CHILDREN`}function jt(e){let t=e.getPorts();for(let e=0;e<t.length;e++){let n=t[e];if(n.getIncomingEdges().length>0||n.getOutgoingEdges().length>0)return!1}return!0}var Mt=class{skipInitAtPortLevel=!0;skipInitAtEdgeLevel=!0;portRanks;random;constraintResolver;barycenterState;portDistributor;barycenterSortStates=null;layerStates=/* @__PURE__ */ new WeakMap;debugBarycenter=!1;barycenterVisitGeneration=0;nextBarycenterScratch=[];barycenterAssociates=/* @__PURE__ */ new WeakMap;hasBarycenterAssociates=!1;separateBlackBoxes=/* @__PURE__ */ new WeakSet;hasSeparateBlackBoxes=!1;constructor(t,n,r,i){this.constraintResolver=t,this.random=n,this.portDistributor=r,this.barycenterState=t.getBarycenterStates();for(let t=0;t<i.length;t++){let n=i[t];for(let t=0;t<n.length;t++){let r=n[t],i=r.getProperty(e.On);i!=null&&i.length>0&&(this.barycenterAssociates.set(r,i),this.hasBarycenterAssociates=!0),At(r)&&(this.separateBlackBoxes.add(r),this.hasSeparateBlackBoxes=!0)}}}minimizeLayer(e,t,n,r){this.debugBarycenter=!1,n?this.randomizeBarycenters(e):(this.calculateBarycenters(e,r),this.fillInUnknownBarycenters(e,t)),e.length>1&&(this.barycenterSortStates=this.statesForLayer(e),e.sort(this.barycenterIndexStateComparator),this.barycenterSortStates=null,this.constraintResolver.processConstraints(e))}randomizeBarycenters(e){for(let t=0;t<e.length;t++){let n=e[t],r=this.hasSeparateBlackBoxes&&this.separateBlackBoxes.has(n)&&jt(n)?Number.MAX_VALUE:this.random.nextDouble(),i=this.stateOf(n);i.barycenter=r,i.summedWeight=r,i.degree=1}}fillInUnknownBarycenters(e,t){if(e.length===0)return;let n=this.statesForLayer(e);if(this.hasSeparateBlackBoxes)for(let t=0;t<e.length;t++){let r=e[t],i=n[r.id];i.barycenter===null&&this.separateBlackBoxes.has(r)&&jt(r)&&(i.barycenter=Number.MAX_VALUE,i.summedWeight=Number.MAX_VALUE,i.degree=1)}if(t){let t=this.nextBarycenterScratch;t.length=e.length;let r=null;for(let i=e.length-1;i>=0;i--){t[i]=r;let a=n[e[i].id].barycenter;a!==null&&(r=a)}let i=-1;for(let r=0;r<e.length;r++){let a=n[e[r].id],o=a.barycenter;if(o===null){let e=i+1,n=t[r];n!==null&&(e=n),o=(i+e)/2,a.barycenter=o,a.summedWeight=o,a.degree=1}i=o}}else{let t=0;for(let r=0;r<e.length;r++){let i=n[e[r].id].barycenter;i!==null&&(t=Math.max(t,i))}t+=2;for(let r=0;r<e.length;r++){let i=n[e[r].id];if(i.barycenter===null){let e=this.random.nextFloat()*t-1;i.barycenter=e,i.summedWeight=e,i.degree=1}}}}calculateBarycenters(e,t){if(e.length===0)return;let n=++this.barycenterVisitGeneration,r=this.statesForLayer(e);for(let i=0;i<e.length;i++)this.calculateBarycenter(e[i],t,n,r)}calculateBarycenter(e,t,n,r){let i=r[e.id];if(i.visitedGeneration===n)return;i.visitedGeneration=n,i.degree=0,i.summedWeight=0,i.barycenter=null;let a=e.getLayer(),o=t?i.forwardAdjacency:i.backwardAdjacency;for(let e=0;e<o.length;e++){let a=o[e];if(a>=0){let e=r[a].node,o=r[a];this.calculateBarycenter(e,t,n,r),i.degree+=o.degree,i.summedWeight+=o.summedWeight}else i.summedWeight+=this.portRanks[-a-1],i.degree++}if(this.hasBarycenterAssociates){let o=this.barycenterAssociates.get(e);if(o!==void 0)for(let e=0;e<o.length;e++){let s=o[e];if(s.getLayer()===a){let e=r[s.id];this.calculateBarycenter(s,t,n,r),i.degree+=e.degree,i.summedWeight+=e.summedWeight}}}if(i.degree>0){let t=this.random.nextFloat();if(i.summedWeight+=t*kt-kt/2,i.barycenter=i.summedWeight/i.degree,this.debugBarycenter){let t=e.getType().toString()===`NORMAL`?e.getLabels()[0]?.text??e.id:e.id,n=[];for(let t of e.getPorts()){for(let e of t.getSuccessorPorts()){let r=e.getNode(),i=r?.getType().toString()===`NORMAL`?r?.getLabels()[0]?.text??r?.id:r?.id;n.push(t.id+`->`+i+`:`+(this.portRanks[e.id]??`?`))}for(let e of t.getPredecessorPorts()){let r=e.getNode(),i=r?.getType().toString()===`NORMAL`?r?.getLabels()[0]?.text??r?.id:r?.id;n.push(i+`->`+t.id+`:`+(this.portRanks[e.id]??`?`))}}console.error(`GGN_BD ${t} L${e.getLayer()?.getIndex()} degree=${this.stateOf(e).degree} sw=${this.stateOf(e).summedWeight.toFixed(4)} bc=${this.stateOf(e).barycenter.toFixed(4)} [${n.join(` `)}]`)}}}statesForLayer(e){let t=e[0].getLayer();return this.layerStates.get(t)??this.barycenterState[t.getIndex()]}stateOf(e){return this.constraintResolver.stateOf(e)}barycenterIndexStateComparator=(e,t)=>{let n=this.barycenterSortStates,r=n[e.id],i=n[t.id];return r.barycenter!==null&&i.barycenter!==null?r.barycenter-i.barycenter:r.barycenter===null?i.barycenter===null?0:1:-1};barycenterStateComparator=(e,t)=>{let n=this.stateOf(e),r=this.stateOf(t);return n.barycenter!==null&&r.barycenter!==null?n.barycenter-r.barycenter:n.barycenter===null?r.barycenter===null?0:1:-1};minimizeCrossings(e,t,n,r){if(!this.isFirstLayer(e,t,n)){let r=e[t-this.changeIndex(n)];this.portDistributor.calculatePortRanksForLayer(r,this.portTypeFor(n))}let i=e[t][0],a=!r||this.isExternalPortDummy(i);return this.minimizeLayer(e[t],a,!1,n),!1}setFirstLayerOrder(e,t){let n=this.startIndex(t,e.length);return this.minimizeLayer(e[n],!1,!0,t),!1}isFirstLayer(e,t,n){return n?t===0:t===e.length-1}changeIndex(e){return e?1:-1}startIndex(e,t){return e?0:t-1}isExternalPortDummy(e){return e.getType()===`EXTERNAL_PORT`}portTypeFor(e){return e?`OUTPUT`:`INPUT`}alwaysImproves(){return!1}isDeterministic(){return!1}initAtLayerLevel(e,t){this.barycenterState[e]=Array(t[e].length)}initAtNodeLevel(e,t,n){let r=new Ot(n[e][t]);this.barycenterState[e][t]=r,this.constraintResolver.registerNodeState(n[e][t],r)}initAtPortLevel(){}initAtEdgeLevel(){}initAfterTraversal(){this.portRanks=this.portDistributor.getPortRanks();for(let e=0;e<this.barycenterState.length;e++){let t=this.barycenterState[e];if(t.length>0){let e=t[0].node.getLayer();e!==null&&this.layerStates.set(e,t)}}this.buildBarycenterAdjacency()}buildBarycenterAdjacency(){for(let e=0;e<this.barycenterState.length;e++){let t=this.barycenterState[e];for(let e=0;e<t.length;e++){let n=t[e].node,r=n.getLayer(),i=[],a=[],o=n.getPorts();for(let e=0;e<o.length;e++){let t=o[e];for(let e of t.getIncomingEdges()){let t=e.getSource();if(t===null)continue;let a=t.getNode();a.getLayer()===r?a!==n&&i.push(a.id):i.push(-(t.id+1))}for(let e of t.getOutgoingEdges()){let t=e.getTarget();if(t===null)continue;let i=t.getNode();i.getLayer()===r?i!==n&&a.push(i.id):a.push(-(t.id+1))}}t[e].forwardAdjacency=i,t[e].backwardAdjacency=a}}}};function O(t,n,r,i){let a=r.getProperty(e.S)===`ENFORCED`,o=r.getProperty(e.x);if(!t.hasProperty(e.cr))return-1;if(a){if(o.includes(t.getProperty(e.C))&&o.includes(n.getProperty(e.C)))return i*(t.getProperty(e.C)??0)+t.getProperty(e.cr)}else return t.getProperty(e.cr);return t.getProperty(e.cr)}const k=new e.ai(`medianHeuristic.weight`),Nt=Number.MIN_VALUE,Pt=Number.MAX_VALUE;function Ft(e){return e.getAllProperties().get(`org.eclipse.elk.hierarchyHandling`)===`SEPARATE_CHILDREN`}function It(e){return e.getIncomingEdges().length===0&&e.getOutgoingEdges().length===0}var Lt=class{skipInitAtLayerLevel=!0;skipInitAtNodeLevel=!0;skipInitAtPortLevel=!0;skipInitAtEdgeLevel=!0;skipInitAfterTraversal=!0;random;constructor(e){this.random=e}alwaysImproves(){return!1}isDeterministic(){return!0}setFirstLayerOrder(e,t){let n=t?0:Math.max(0,e.length-1),r=[...e[n]];for(let e of r)e.setProperty(k,Ft(e)&&It(e)?Pt:this.random.nextDouble());r.sort(this.weightComparator);let i=0;for(let t of r)e[n][i++]=t,t.setProperty(k,i);return!1}minimizeCrossings(e,t,n,r){let i=[...e[t]];this.calculateMedians(i,n?t-1:t+1),i.sort(this.weightComparator);let a=0;for(let n of i)e[t][a++]=n;return!1}calculateMedians(e,t){let n=Nt,r=Pt,i=[];for(let a of e){let e=[];for(let n of a.getIncomingEdges())this.addAdjacentNodeInReferenceLayer(n,t,e);for(let n of a.getOutgoingEdges())this.addAdjacentNodeInReferenceLayer(n,t,e);if(e.length===0)i.push(a);else{e.sort(this.weightComparator);let t=e[Math.floor(e.length/2)].getProperty(k);a.setProperty(k,t),n=Math.min(n,t),r=Math.max(r,t)}}let a=(r+n)/2;for(let e of i)e.setProperty(k,a)}addAdjacentNodeInReferenceLayer(e,t,n){let r=e.getTarget().getNode(),i=e.getSource().getNode();r.getLayer().getIndex()===t&&n.push(r),i.getLayer().getIndex()===t&&n.push(i)}weightComparator=(e,t)=>e.hasProperty(k)?t.hasProperty(k)?Rt(e.getProperty(k),t.getProperty(k)):-1:1;initAtLayerLevel(e,t){}initAtNodeLevel(e,t,n){}initAtPortLevel(e,t,n,r){}initAtEdgeLevel(e,t,n,r,i,a){}initAfterTraversal(){}};function Rt(e,t){return e<t?-1:e>t?1:e===t?e===0?Object.is(e,-0)===Object.is(t,-0)?0:Object.is(e,-0)?-1:1:0:Number.isNaN(e)?+!Number.isNaN(t):-1}var zt=class t extends Mt{biggerThan=/* @__PURE__ */ new Map;smallerThan=/* @__PURE__ */ new Map;constructor(t,n,r,i){super(t,n,r,i),this.barycenterStateComparator=(t,n)=>{if(t.getLayerConstraint()===`FIRST_SEPARATE`||t.getLayerConstraint()===`LAST_SEPARATE`||n.getLayerConstraint()===`FIRST_SEPARATE`||n.getLayerConstraint()===`LAST_SEPARATE`)return 0;let r=t.getGraph(),i=this.compareBasedOnTansitiveDependencies(t,n);if(i!==0)return i;if(t.hasProperty(e.cr)&&n.hasProperty(e.cr)){let i=Math.sign(O(t,n,r,r.getProperty(e.sr))-O(n,t,r,r.getProperty(e.sr)));if(r.getProperty(e.S)===`ONLY_WITHIN_GROUP`&&t.getProperty(e.C)!==n.getProperty(e.C)&&(i=0),i<0)return this.updateBiggerAndSmallerAssociations(n,t),i;if(i>0)return this.updateBiggerAndSmallerAssociations(t,n),i}return this.compareBasedOnBarycenter(t,n)}}minimizeLayer(n,r,i,a){if(i?this.randomizeBarycenters(n):(this.calculateBarycenters(n,a),this.fillInUnknownBarycenters(n,r)),n.length>1){let r=n[0].getGraph().getProperty(e.Pn);r?t.insertionSort(n,this.barycenterStateComparator,this):n.sort(this.barycenterStateComparator),r||this.constraintResolver.processConstraints(n)}}compareBasedOnTansitiveDependencies(e,t){if(!this.biggerThan.has(e))this.biggerThan.set(e,/* @__PURE__ */ new Set);else if(this.biggerThan.get(e).has(t))return 1;if(!this.biggerThan.has(t))this.biggerThan.set(t,/* @__PURE__ */ new Set);else if(this.biggerThan.get(t).has(e))return-1;if(!this.smallerThan.has(e))this.smallerThan.set(e,/* @__PURE__ */ new Set);else if(this.smallerThan.get(e).has(t))return-1;if(!this.smallerThan.has(t))this.smallerThan.set(t,/* @__PURE__ */ new Set);else if(this.smallerThan.get(t).has(e))return 1;return 0}compareBasedOnBarycenter(e,t){let n=this.stateOf(e),r=this.stateOf(t);if(n.barycenter!==null&&r.barycenter!==null){let i=Rt(n.barycenter,r.barycenter);return i<0?this.updateBiggerAndSmallerAssociations(t,e):i>0&&this.updateBiggerAndSmallerAssociations(e,t),i}return n.barycenter===null?r.barycenter===null?0:(this.updateBiggerAndSmallerAssociations(e,t),1):(this.updateBiggerAndSmallerAssociations(t,e),-1)}updateBiggerAndSmallerAssociations(e,t){let n=this.biggerThan.get(e),r=this.biggerThan.get(t),i=this.smallerThan.get(e),a=this.smallerThan.get(t);n.add(t),a.add(e);for(let t of r){n.add(t);let r=this.smallerThan.get(t);r.add(e);for(let e of i)r.add(e)}for(let e of i){a.add(e);let n=this.biggerThan.get(e);n.add(t);for(let e of r)n.add(e)}}static insertionSort(e,t,n){for(let n=1;n<e.length;n++){let r=e[n],i=n;for(;i>0&&t(e[i-1],r)>0;)e[i]=e[i-1],i--;e[i]=r}n.clearTransitiveOrdering()}clearTransitiveOrdering(){this.biggerThan=/* @__PURE__ */ new Map,this.smallerThan=/* @__PURE__ */ new Map}},Bt=class{skipInitAtLayerLevel=!0;skipInitAtEdgeLevel=!0;_lGraph;_currentNodeOrder;_currentlyBestNodeAndPortOrder=null;_bestNodeAndPortOrder=null;_portPositions=[];_useBottomUp=!1;_childGraphs=[];_hasExternalPorts=!1;_hasParent=!1;_parentGraphData=null;_parent=null;_crossMinimizer;_portDistributor;_crossingsCounter;_nPorts=0;constructor(t,n,r){this._lGraph=t,this._currentNodeOrder=t.toNodeArray(),this._parent=this._lGraph.getParentNode(),this._hasParent=this._parent!==null,this._parentGraphData=this._hasParent?r[this._parent.getGraph().id]:null;let i=this._lGraph.getProperty(e.Gn);this._hasExternalPorts=i.has(`EXTERNAL_PORTS`),this._crossingsCounter=new mt(this._currentNodeOrder);let a=this._lGraph.getProperty(e.br);this._portDistributor=dt(n,a,this._currentNodeOrder);let o=[this,this._crossingsCounter,this._portDistributor],s=t.getProperty(e.Pn);if(n===0&&!s){let e=new Dt(this._currentNodeOrder);o.push(e),this._crossMinimizer=new Mt(e,a,this._portDistributor,this._currentNodeOrder)}else if(n===0&&s){let e=new Dt(this._currentNodeOrder);o.push(e),this._crossMinimizer=new zt(e,a,this._portDistributor,this._currentNodeOrder)}else if(n===3)this._crossMinimizer=new Lt(a);else if(n===1||n===2)this._crossMinimizer=new at(n,this);else throw Error(`CrossMinType ${n} 未实现`);o.push(this._crossMinimizer),pt(o,this._currentNodeOrder),this._useBottomUp=_t(this)}dontSweepInto(){return this._useBottomUp}get lGraph(){return this._lGraph}get currentNodeOrder(){return this._currentNodeOrder}get currentlyBestNodeAndPortOrder(){return this._currentlyBestNodeAndPortOrder}setCurrentlyBestNodeAndPortOrder(e){this._currentlyBestNodeAndPortOrder=e}get bestNodeNPortOrder(){return this._bestNodeAndPortOrder}setBestNodeNPortOrder(e){this._bestNodeAndPortOrder=e}get crossCounter(){return this._crossingsCounter}get crossMinimizer(){return this._crossMinimizer}get portDistributor(){return this._portDistributor}get parent(){return this._parent}get hasParent(){return this._hasParent}get childGraphs(){return this._childGraphs}get hasExternalPorts(){return this._hasExternalPorts}get parentGraphData(){return this._parentGraphData}get crossMinDeterministic(){return this._crossMinimizer.isDeterministic()}get crossMinAlwaysImproves(){return this._crossMinimizer.alwaysImproves()}get getBestSweep(){return this._crossMinimizer.isDeterministic()?this._currentlyBestNodeAndPortOrder:this._bestNodeAndPortOrder}get portPositions(){return this._portPositions}initAtLayerLevel(){}initAtNodeLevel(e,t,n){let r=n[e][t].getNestedGraph();r!==null&&this._childGraphs.push(r)}initAtPortLevel(){this._nPorts++}initAtEdgeLevel(){}initAfterTraversal(){this._portPositions=Array(this._nPorts)}};function Vt(t,n){let r={NORTH:0,EAST:1,SOUTH:2,WEST:3},i=r[t.getSide()]??0,a=r[n.getSide()]??0;if(i!==a)return i-a;let o=t.getNode().getProperty(e.Lt);if(!e.Lr.isOrderFixed(o))return 0;if(o===`FIXED_ORDER`){let r=t.getProperty(e.Rt),i=n.getProperty(e.Rt);if(r!==null&&i!==null&&r-i!==0)return r-i}switch(t.getSide()){case`NORTH`:return t.getPosition().x-n.getPosition().x;case`EAST`:return t.getPosition().y-n.getPosition().y;case`SOUTH`:return n.getPosition().x-t.getPosition().x;case`WEST`:return n.getPosition().y-t.getPosition().y;default:return 0}}var Ht=class t{nodeOrder;portOrders;constructor(e){if(e instanceof t){let n=e;this.nodeOrder=t.deepCopy(n.nodeOrder),this.portOrders=[...n.portOrders]}else{this.nodeOrder=t.deepCopy(e);let n=Array(e.length);this.portOrders=n;for(let t=0;t<e.length;t++){let r=e[t],i=Array(r.length);n[t]=i;for(let e=0;e<r.length;e++)i[e]=r[e].getPorts().slice()}}}static deepCopy(e){if(e===null)return null;let t=Array(e.length);for(let n=0;n<e.length;n++)t[n]=e[n].slice();return t}nodes(){return this.nodeOrder}transferNodeAndPortOrdersToGraph(t,n){let r=[],i=/* @__PURE__ */ new Set,a=t.getLayers();for(let t=0;t<a.length;t++){let o=a[t].getNodes();r.length=0;for(let i=0;i<o.length;i++){let o=this.nodeOrder[t][i];if(o.id=i,o.getType()===`NORTH_SOUTH_PORT`&&r.push(o),a[t].getNodes()[i]=o,o.getPorts().length=0,o.getPorts().push(...this.portOrders[t][i]),n){let t=o.getProperty(e.Lt);e.Lr.isOrderFixed(t)||o.setProperty(e.Lt,`FIXED_ORDER`)}}for(let e of r){let t=this.assertCorrectPortSides(e);i.add(t),i.add(e)}}for(let e of i)e.getPorts().sort(Vt)}assertCorrectPortSides(t){let n=t.getProperty(e.Zn),r=t.getPorts()[0];for(let i of n.getPorts())if(i===r.getProperty(e.lr)){if(i.getSide()===`NORTH`&&t.id>n.id){if(i.setSide(`SOUTH`),i.isExplicitlySuppliedPortAnchor()){let e=i.getSize().y,t=i.getAnchor().y;i.getAnchor().y=e-t}}else if(i.getSide()===`SOUTH`&&n.id>t.id&&(i.setSide(`NORTH`),i.isExplicitlySuppliedPortAnchor())){let e=i.getSize().y,t=i.getAnchor().y;i.getAnchor().y=-(e-t)}break}return n}},Ut=class{graphInfoHolders=[];graphsWhoseNodeOrderChanged=/* @__PURE__ */ new Set;random;randomSeed=1;crossMinType;constructor(e){this.crossMinType=e}process(t,n){n.begin(`Minimize Crossings ${this.crossMinType}`,1);let r=t.getLayers().length===0||t.getLayers().every(e=>e.getNodes().length===0),i=t.getLayers().length===1&&t.getLayers()[0].getNodes().length===1,a=t.getProperty(e.q)===`INCLUDE_CHILDREN`;if(r||i&&!a){n.done();return}let o=this.initialize(t),s=this.chooseMinimizingMethod(o);for(let e of o)e.currentNodeOrder.length>0&&(s(e),e.hasParent&&this.setPortOrderOnParentGraph(e));this.transferNodeAndPortOrdersToGraph(),n.done()}chooseMinimizingMethod(e){if(e.length===0)return()=>{};let t=e[0];return t.crossMinDeterministic?t.crossMinAlwaysImproves?e=>this.minimizeCrossingsNoCounter(e):e=>this.minimizeCrossingsWithCounter(e):e=>this.compareDifferentRandomizedLayouts(e)}minimizeCrossingsNoCounter(e){let t=this.random.nextBoolean(),n=!0;for(;n;)n=!1,n=e.crossMinimizer.setFirstLayerOrder(e.currentNodeOrder,t),n=this.sweepReducingCrossings(e,t,!1)||n,t=!t;this.setCurrentlyBestNodeOrders()}compareDifferentRandomizedLayouts(t){this.random.setSeed(this.randomSeed),this.graphsWhoseNodeOrderChanged.clear();let n=2**53-1,r=t.lGraph.getProperty(e.mn);for(let e=0;e<r;e++){let e=this.minimizeCrossingsWithCounter(t);if(e<n&&(n=e,this.saveAllNodeOrdersOfChangedGraphs(),n===0))break}}minimizeCrossingsWithCounter(e){let t=this.random.nextBoolean();this.countCurrentNumberOfCrossings(e),e.crossMinimizer.setFirstLayerOrder(e.currentNodeOrder,t),this.sweepReducingCrossings(e,t,!0);let n=this.countCurrentNumberOfCrossings(e),r,i=2;do{if(i++,this.setCurrentlyBestNodeOrders(),n===0)return 0;t=!t,r=n,this.sweepReducingCrossings(e,t,!1),n=this.countCurrentNumberOfCrossings(e)}while(r>n);return r}countCurrentNumberOfCrossings(e){let t=0,n=[e];for(;n.length>0;){let e=n.pop();t+=e.crossCounter.countAllCrossings(e.currentNodeOrder);for(let n of e.childGraphs){let e=this.graphInfoHolders[n.id];e&&!e.dontSweepInto()&&(t+=this.countCurrentNumberOfCrossings(e))}}return t}sweepReducingCrossings(e,t,n){let r=e.currentNodeOrder,i=r.length,a=e.portDistributor.distributePortsWhileSweeping(r,this.firstIndex(t,i),t),o=r[this.firstIndex(t,i)];a=this.sweepInHierarchicalNodes(o,t,n)||a;for(let o=this.firstFree(t,i);this.isNotEnd(i,o,t);o+=this.next(t))a=e.crossMinimizer.minimizeCrossings(r,o,t,n)||a,a=e.portDistributor.distributePortsWhileSweeping(r,o,t)||a,a=this.sweepInHierarchicalNodes(r[o],t,n)||a;return this.graphsWhoseNodeOrderChanged.add(e),a}sweepInHierarchicalNodes(e,t,n){let r=!1;for(let i of e)this.hasNestedGraph(i)&&!this.graphInfoHolders[i.getNestedGraph().id].dontSweepInto()&&(r=this.sweepInHierarchicalNode(t,i,n)||r);return r}sweepInHierarchicalNode(e,t,n){let r=t.getNestedGraph(),i=this.graphInfoHolders[r.id],a=i.currentNodeOrder,o=this.firstIndex(e,a.length),s=a[o][0];this.isExternalPortDummy(s)?a[o]=this.sortPortDummiesByPortPositions(t,a[o],this.sideOpposedSweepDirection(e)):i.crossMinimizer.setFirstLayerOrder(a,e);let c=this.sweepReducingCrossings(i,e,n);return this.sortPortsByDummyPositionsInLastLayer(i.currentNodeOrder,i.parent,e),c}sortPortsByDummyPositionsInLastLayer(e,t,n){let r=e[this.endIndex(n,e.length)],i=this.firstIndex(n,r.length);if(!this.isExternalPortDummy(r[i]))return;let a=[];for(let e=0;e<r.length;e++){let t=r[e];if(this.isExternalPortDummy(t)){let e=this.originPort(t);e!=null&&typeof e.getSide==`function`&&a.push(t)}}let o=t.getPorts(),s=n?0:a.length-1,c=n?1:-1;for(let e=0;e<o.length;e++){let t=o[e];this.isOnEndOfSweepSide(t,n)&&this.isHierarchical(t)&&s>=0&&s<a.length&&(o[e]=this.originPort(a[s]),s+=c)}}sortPortDummiesByPortPositions(e,t,n){let r=e.getPortSideView(n),i=Array(t.length),a=0;if(n===`EAST`||n===`NORTH`)for(let e=0;e<r.length;e++){let t=r[e];this.isHierarchical(t)&&(i[a++]=this.dummyNodeFor(t))}else for(let e=r.length-1;e>=0;e--){let t=r[e];this.isHierarchical(t)&&(i[a++]=this.dummyNodeFor(t))}if(a<t.length)throw Error(`IllegalStateException: Expected ${t.length} hierarchical ports, but found only ${a}.`);return i}setPortOrderOnParentGraph(t){if(t.hasExternalPorts&&t.getBestSweep!==null){let n=t.getBestSweep;this.sortPortsByDummyPositionsInLastLayer(n.nodes(),t.parent,!0),this.sortPortsByDummyPositionsInLastLayer(n.nodes(),t.parent,!1),t.parent.setProperty(e.Lt,`FIXED_ORDER`)}}saveAllNodeOrdersOfChangedGraphs(){for(let e of this.graphsWhoseNodeOrderChanged)e.setBestNodeNPortOrder(new Ht(e.currentlyBestNodeAndPortOrder))}setCurrentlyBestNodeOrders(){for(let e of this.graphsWhoseNodeOrderChanged)e.setCurrentlyBestNodeAndPortOrder(new Ht(e.currentNodeOrder))}firstIndex(e,t){return e?0:t-1}endIndex(e,t){return e?t-1:0}firstFree(e,t){return e?1:t-2}next(e){return e?1:-1}isNotEnd(e,t,n){return n?t<e:t>=0}hasNestedGraph(e){return e.getNestedGraph()!==null}sideOpposedSweepDirection(e){return e?`WEST`:`EAST`}isExternalPortDummy(e){return e.getType()===`EXTERNAL_PORT`}originPort(t){return t.getProperty(e.lr)}isHierarchical(t){return t.getProperty(e.Xn)}dummyNodeFor(t){return t.getProperty(e._r)}isOnEndOfSweepSide(e,t){return t?e.getSide()===`EAST`:e.getSide()===`WEST`}initialize(t){this.graphInfoHolders=[];let n=t.getProperty(e.br);n===void 0&&(n=new i(t.getProperty(e.Kt)),t.setProperty(e.br,n)),this.random=n,this.randomSeed=this.random.nextLong();let r=[],a=[t],o=0;for(;o<a.length;){let t=a[o];t.id=o++,t.getProperty(e.br)===void 0&&t.setProperty(e.br,n);let i=new Bt(t,this.crossMinType,this.graphInfoHolders);a.push(...i.childGraphs),this.graphInfoHolders.push(i),i.dontSweepInto()&&r.unshift(i)}return this.graphsWhoseNodeOrderChanged=/* @__PURE__ */ new Set,r}transferNodeAndPortOrdersToGraph(){for(let e of this.graphInfoHolders){let t=e.getBestSweep;t!==null&&t.transferNodeAndPortOrdersToGraph(e.lGraph,!0)}}getGraphData(){return this.graphInfoHolders}},Wt=class{process(t){let n=0;for(let e of t.getLayers())e.id=n++;let r=t.toNodeArray(),i=new ut(r.length);pt([i],r);let a=0;n=0;for(let o of t.getLayers()){let t=0,s=0;for(let e of o.getNodes()){e.getPosition().x>0&&(t+=e.getPosition().x+e.getSize().x/2,s++);for(let t of e.getPorts())t.id=a++}s>0&&(t/=s);let c=Array(o.getNodes().length),l=0;for(let n of o.getNodes())n.id=l++,c[n.id]=Gt(n,t),n.getType()===`LONG_EDGE`&&n.setProperty(e.dr,c[n.id]);o.getNodes().sort((t,n)=>{let r=c[t.id]-c[n.id];if(r===0){let r=t.getProperty(e.Qn)??[],i=n.getProperty(e.Qn)??[];if(r.includes(n))return-1;if(i.includes(t))return 1}return r}),i.distributePortsWhileSweeping(r,n,!0),n++}}};function Gt(t,n){switch(t.getType()){case`LONG_EDGE`:{let r=t.getProperty(e.lr),i=(r?.getProperty(e.ur)??[]).slice();r?.getProperty(e.Sr)&&i.reverse();let a=t.getProperty(e.rr);if(a){let e=a.getAbsoluteAnchor();if(n<=e.x)return e.y;i.unshift(e)}let o=t.getProperty(e.ir);if(o){let e=o.getAbsoluteAnchor();if(e.x<=n)return e.y;i.push(e)}if(i.length>=2){let e=i[0],t=i[1],r=2;for(;t.x<n&&r<i.length;)e=t,t=i[r++];return e.y+(n-e.x)/(t.x-e.x)*(t.y-e.y)}break}case`NORTH_SOUTH_PORT`:{let n=t.getPorts()[0]?.getProperty(e.lr),r=n?.getNode();if(r&&n){if(n.getSide()===`NORTH`)return r.getPosition().y;if(n.getSide()===`SOUTH`)return r.getPosition().y+r.getSize().y}break}}return t.getGraph()?.getProperty(e.tt)===`TOP_LEFT`?t.getPosition().y:t.getPosition().y+t.getSize().y/2}function Kt(e,t){return{first:e,second:t}}var qt=class t{nodeCount=0;layerIndex=[];nodeIndex=[];leftNeighbors=[];rightNeighbors=[];static buildFor(e){let n=new t;n.nodeCount=0;for(let t of e.getLayers())n.nodeCount+=t.getNodes().length;let r=0,i=0;n.layerIndex=Array(e.getLayers().length);let a=0;n.nodeIndex=Array(n.nodeCount);for(let t of e.getLayers()){t.id=r++,n.layerIndex[t.id]=i++;let e=0;for(let r of t.getNodes())r.id=a++,n.nodeIndex[r.id]=e++}return n.leftNeighbors=[],t.determineAllLeftNeighbors(n,e),n.rightNeighbors=[],t.determineAllRightNeighbors(n,e),n}static determineAllLeftNeighbors(t,n){for(let r of n.getLayers())for(let n of r.getNodes()){let r=[],i=0;for(let t of n.getIncomingEdges()){if(t.isSelfLoop()||t.isInLayerEdge())continue;let n=t.getProperty(e.Gt);n>i&&(i=n,r.length=0),n===i&&r.push(Kt(t.getSource().getNode(),t))}r.sort((e,n)=>Math.sign(t.nodeIndex[e.first.id]-t.nodeIndex[n.first.id])),t.leftNeighbors[n.id]=r}}static determineAllRightNeighbors(t,n){for(let r of n.getLayers())for(let n of r.getNodes()){let r=[],i=0;for(let t of n.getOutgoingEdges()){if(t.isSelfLoop()||t.isInLayerEdge())continue;let n=t.getProperty(e.Gt);n>i&&(i=n,r.length=0),n===i&&r.push(Kt(t.getTarget().getNode(),t))}r.sort((e,n)=>Math.sign(t.nodeIndex[e.first.id]-t.nodeIndex[n.first.id])),t.rightNeighbors[n.id]=r}}cleanup(){this.leftNeighbors=[],this.rightNeighbors=[]}},Jt=class{root=[];blockSize=/* @__PURE__ */ new Float64Array;align=[];innerShift=/* @__PURE__ */ new Float64Array;sink=[];shift=/* @__PURE__ */ new Float64Array;y=/* @__PURE__ */ new Float64Array;vdir;hdir;su=/* @__PURE__ */ new Uint8Array;od=/* @__PURE__ */ new Uint8Array;layeredGraph;spacings;constructor(t,n,r,i){this.layeredGraph=t,this.spacings=t.getProperty(e.wr),this.root=Array(n),this.blockSize=new Float64Array(n),this.align=Array(n),this.innerShift=new Float64Array(n),this.sink=Array(n),this.shift=new Float64Array(n),this.y=new Float64Array(n),this.su=new Uint8Array(n),this.od=new Uint8Array(n),this.od.fill(1),this.vdir=r,this.hdir=i}cleanup(){this.root=[],this.blockSize=/* @__PURE__ */ new Float64Array,this.align=[],this.innerShift=/* @__PURE__ */ new Float64Array,this.sink=[],this.shift=/* @__PURE__ */ new Float64Array,this.y=/* @__PURE__ */ new Float64Array}layoutSize(){let e=1/0,t=-1/0;for(let n of this.layeredGraph.getLayers())for(let r of n.getNodes()){let n=this.y[r.id],i=n+this.blockSize[this.root[r.id].id];e=Math.min(e,n),t=Math.max(t,i)}return t-e}calculateDelta(e,t){let n=this.y[e.getNode().id]+this.innerShift[e.getNode().id]+e.getPosition().y+e.getAnchor().y;return this.y[t.getNode().id]+this.innerShift[t.getNode().id]+t.getPosition().y+t.getAnchor().y-n}shiftBlock(e,t){let n=e;do this.y[n.id]+=t,n=this.align[n.id];while(n!==e)}checkSpaceAbove(e,t,n){let r=t,i=e,a=i;do{a=this.align[a.id];let e=this.getMinY(a),t=this.getUpperNeighbor(a,n);if(t!==null){let n=this.getMaxY(t);r=Math.min(r,e-(n+this.spacings.getVerticalSpacing(a,t)))}}while(i!==a);return r}checkSpaceBelow(e,t,n){let r=t,i=e,a=i;do{a=this.align[a.id];let e=this.getMaxY(a),t=this.getLowerNeighbor(a,n);if(t!==null){let n=this.getMinY(t);r=Math.min(r,n-(e+this.spacings.getVerticalSpacing(a,t)))}}while(i!==a);return r}getMinY(e){let t=this.root[e.id];return this.y[t.id]+this.innerShift[e.id]-e.getMargin().top}getMaxY(e){let t=this.root[e.id];return this.y[t.id]+this.innerShift[e.id]+e.size.y+e.getMargin().bottom}getLowerNeighbor(e,t){let n=e.getLayer(),r=t.nodeIndex[e.id];return r<n.getNodes().length-1?n.getNodes()[r+1]:null}getUpperNeighbor(e,t){let n=e.getLayer(),r=t.nodeIndex[e.id];return r>0?n.getNodes()[r-1]:null}};const Yt=/* @__PURE__ */ new WeakMap;var Xt=class e{layeredGraph;ni;constructor(e,t){this.layeredGraph=e,this.ni=t}verticalAlignment(e,t){for(let t of this.layeredGraph.getLayers())for(let n of t.getNodes())e.root[n.id]=n,e.align[n.id]=n,e.innerShift[n.id]=0;let n=this.layeredGraph.getLayers(),r=n.length,i=e.hdir===1,a=e.vdir===1;for(let o=0;o<r;o++){let s=n[i?r-1-o:o],c=-1,l=s.getNodes(),u=l.length;a&&(c=2**53-1);for(let n=0;n<u;n++){let r=l[a?u-1-n:n],o=i?this.ni.rightNeighbors[r.id]:this.ni.leftNeighbors[r.id];if(o.length>0){let n=o.length,i=Math.floor((n+1)/2)-1,s=Math.ceil((n+1)/2)-1;if(a){for(let n=s;n>=i;n--)if(e.align[r.id]===r){let i=o[n].first;!t.has(o[n].second.id)&&c>this.ni.nodeIndex[i.id]&&(e.align[i.id]=r,e.root[r.id]=e.root[i.id],e.align[r.id]=e.root[r.id],e.od[e.root[r.id].id]=+(e.od[e.root[r.id].id]!==0&&r.getType()===`LONG_EDGE`),c=this.ni.nodeIndex[i.id])}}else for(let n=i;n<=s;n++)if(e.align[r.id]===r){let i=o[n].first;!t.has(o[n].second.id)&&c<this.ni.nodeIndex[i.id]&&(e.align[i.id]=r,e.root[r.id]=e.root[i.id],e.align[r.id]=e.root[r.id],e.od[e.root[r.id].id]=+(e.od[e.root[r.id].id]!==0&&r.getType()===`LONG_EDGE`),c=this.ni.nodeIndex[i.id])}}}}}insideBlockShift(e){for(let t of this.layeredGraph.getLayers())for(let n of t.getNodes())e.root[n.id]===n&&this.shiftBlock(e,n)}shiftBlock(e,t){let n=0,r=0;n=t.getMargin().top,r=t.size.y+t.getMargin().bottom,e.innerShift[t.id]=0;let i=t,a;for(;(a=e.align[i.id])!==t;){let t=this.getEdge(i,a),o=0;o=e.hdir===1?t.getTarget().getPosition().y+t.getTarget().getAnchor().y-t.getSource().getPosition().y-t.getSource().getAnchor().y:t.getSource().getPosition().y+t.getSource().getAnchor().y-t.getTarget().getPosition().y-t.getTarget().getAnchor().y;let s=e.innerShift[i.id]+o;e.innerShift[a.id]=s,n=Math.max(n,a.getMargin().top-s),r=Math.max(r,s+a.size.y+a.getMargin().bottom),i=a}i=t;do e.innerShift[i.id]=e.innerShift[i.id]+n,i=e.align[i.id];while(i!==t);e.blockSize[t.id]=n+r}getBlocks(e){let t=/* @__PURE__ */ new Map;for(let n of this.layeredGraph.getLayers())for(let r of n.getNodes()){let n=e.root[r.id],i=t.get(n);i||(i=[],t.set(n,i)),i.push(r)}return t}static getEdge(e,t){if(e===t){for(let n of e.getPorts()){for(let e of n.getIncomingEdges())if(e.getTarget().getNode()===t||e.getSource().getNode()===t)return e;for(let e of n.getOutgoingEdges())if(e.getTarget().getNode()===t||e.getSource().getNode()===t)return e}return null}let n=Yt.get(e);n===void 0&&(n=/* @__PURE__ */ new Map,Yt.set(e,n));let r=n.get(t);if(r!==void 0)return r;for(let r of e.getPorts()){for(let e of r.getIncomingEdges())if(e.getSource().getNode()===t)return n.set(t,e),e;for(let e of r.getOutgoingEdges())if(e.getTarget().getNode()===t)return n.set(t,e),e}return null}getEdge(t,n){return e.getEdge(t,n)}},Zt=class{static THRESHOLD=Number.MAX_VALUE;static EPSILON=1e-4;bal;ni;blockFinished=/* @__PURE__ */ new Set;postProcessablesQueue=[];postProcessablesStack=[];init(e,t){this.bal=e,this.ni=t,this.blockFinished.clear(),this.postProcessablesQueue=[],this.postProcessablesStack=[]}finishBlock(e){this.blockFinished.add(e)}getOther(e,t){if(e.getSource().getNode()===t)return e.getTarget().getNode();if(e.getTarget().getNode()===t)return e.getSource().getNode();throw Error(`Node neither source nor target of edge`)}},Qt=class extends Zt{calculateThreshold(e,t,n){return this.bal.vdir===1?1/0:-1/0}postProcess(){}},$t=class extends Zt{scratchPostprocessable=null;calculateThreshold(e,t,n){let r=t===n,i=this.bal.align[n.id]===t;if(!(r||i))return e;let a=e;return r&&(a=this.getBound(t,!0)),!Number.isFinite(a)&&i&&(a=this.getBound(n,!1)),a}pickEdge(e){let t=e.isRoot?this.bal.hdir===0?e.free.getIncomingEdges():e.free.getOutgoingEdges():this.bal.hdir===1?e.free.getIncomingEdges():e.free.getOutgoingEdges(),n=!1;for(let r of t)if((this.bal.od[this.bal.root[e.free.id].id]||!r.isInLayerEdge())&&!(this.bal.su[this.bal.root[e.free.id].id]||this.bal.su[this.bal.root[e.free.id].id])&&(n=!0,this.blockFinished.has(this.bal.root[this.getOther(r,e.free).id])))return e.hasEdges=!0,e.edge=r,e;return e.hasEdges=n,e.edge=null,e}getBound(e,t){let n=this.bal.vdir===1?1/0:-1/0,r=this.scratchPostprocessable;r===null?(r=new en(e,t),this.scratchPostprocessable=r):(r.free=e,r.isRoot=t,r.hasEdges=!1,r.edge=null);let i=this.pickEdge(r);if(i.edge===null&&i.hasEdges){let r=new en(e,t);return r.hasEdges=i.hasEdges,this.postProcessablesQueue.push(r),n}if(i.edge!==null){let e,n=i.edge.getSource(),r=i.edge.getTarget();if(t){let t=this.bal.hdir===0?r:n,i=this.bal.hdir===0?n:r,a=this.bal.root[i.getNode().id];e=this.bal.y[a.id]+this.bal.innerShift[i.getNode().id]+i.getPosition().y+i.getAnchor().y-this.bal.innerShift[t.getNode().id]-t.getPosition().y-t.getAnchor().y}else{let t=this.bal.hdir===1?r:n,i=this.bal.hdir===1?n:r;e=this.bal.y[this.bal.root[i.getNode().id].id]+this.bal.innerShift[i.getNode().id]+i.getPosition().y+i.getAnchor().y-this.bal.innerShift[t.getNode().id]-t.getPosition().y-t.getAnchor().y}return this.bal.su[this.bal.root[n.getNode().id].id]=1,this.bal.su[this.bal.root[r.getNode().id].id]=1,e}return n}postProcess(){for(;this.postProcessablesQueue.length>0;){let e=this.postProcessablesQueue.shift(),t=this.pickEdge(e);if(t.edge===null)continue;let n=t.edge;(this.bal.od[this.bal.root[e.free.id].id]||!n.isInLayerEdge())&&(this.process(e)||this.postProcessablesStack.push(e))}for(;this.postProcessablesStack.length>0;)this.process(this.postProcessablesStack.pop())}process(e){let t=e.edge,n,r;t.getSource().getNode()===e.free?(n=t.getTarget(),r=t.getSource()):(n=t.getSource(),r=t.getTarget());let i=this.bal.calculateDelta(n,r);if(i>0&&i<Zt.THRESHOLD){let e=this.bal.checkSpaceAbove(r.getNode(),i,this.ni);return this.bal.shiftBlock(r.getNode(),-e),e>0}if(i<0&&-i<Zt.THRESHOLD){let e=this.bal.checkSpaceBelow(r.getNode(),-i,this.ni);return this.bal.shiftBlock(r.getNode(),e),e>0}return!1}},en=class{free;isRoot;hasEdges=!1;edge=null;constructor(e,t){this.free=e,this.isRoot=t}},tn=class{classShift=null;node;outgoing=[];indegree=0},nn=class{separation=0;target},rn=class{layeredGraph;threshStrategy;ni;spacings;sinkNodes=/* @__PURE__ */ new Map;classNodePool=[];classEdgePool=[];constructor(t,n){this.layeredGraph=t,this.ni=n,this.spacings=t.getProperty(e.wr),this.threshStrategy=t.getProperty(e.vt)===`IMPROVE_STRAIGHTNESS`?new $t:new Qt}horizontalCompaction(e){for(let t of this.layeredGraph.getLayers())for(let n of t.getNodes())e.sink[n.id]=n,e.shift[n.id]=e.vdir===1?-1/0:1/0;for(let e of this.sinkNodes.values()){for(let t of e.outgoing)this.classEdgePool.push(t);e.outgoing.length=0,this.classNodePool.push(e)}this.sinkNodes.clear();let t=this.layeredGraph.getLayers(),n=t.length,r=e.hdir===1,i=e.vdir===1;this.threshStrategy.init(e,this.ni),e.y.fill(NaN);for(let a=0;a<n;a++){let o=t[r?n-1-a:a].getNodes(),s=o.length;for(let t=0;t<s;t++){let n=o[i?s-1-t:t];e.root[n.id]===n&&this.placeBlock(n,e)}}this.placeClasses(e);for(let i=0;i<n;i++){let a=t[r?n-1-i:i];for(let t of a.getNodes())if(e.y[t.id]=e.y[e.root[t.id].id],t===e.root[t.id]){let n=e.shift[e.sink[t.id].id];(e.vdir===1&&n>-1/0||e.vdir===0&&n<1/0)&&(e.y[t.id]=e.y[t.id]+n)}}this.threshStrategy.postProcess()}placeBlock(t,n){if(!Number.isNaN(n.y[t.id]))return;let r=!0;n.y[t.id]=0;let i=t,a=n.vdir===0?-1/0:1/0;do{let o=this.ni.nodeIndex[i.id],s=i.getLayer().getNodes().length;if(n.vdir===0&&o>0||n.vdir===1&&o<s-1){let s;s=n.vdir===1?i.getLayer().getNodes()[o+1]:i.getLayer().getNodes()[o-1];let c=n.root[s.id];if(this.placeBlock(c,n),a=this.threshStrategy.calculateThreshold(a,t,i),n.sink[t.id]===t&&(n.sink[t.id]=n.sink[c.id]),n.sink[t.id]===n.sink[c.id]){let e=this.spacings.getVerticalSpacing(i,s);if(n.vdir===1){let o=n.y[t.id],l=n.y[c.id]+n.innerShift[s.id]-s.getMargin().top-e-i.getMargin().bottom-i.size.y-n.innerShift[i.id];r?(r=!1,n.y[t.id]=Math.min(l,a)):n.y[t.id]=Math.min(o,Math.min(l,a))}else{let o=n.y[t.id],l=n.y[c.id]+n.innerShift[s.id]+s.size.y+s.getMargin().bottom+e+i.getMargin().top-n.innerShift[i.id];r?(r=!1,n.y[t.id]=Math.max(l,a)):n.y[t.id]=Math.max(o,Math.max(l,a))}}else{let r=this.layeredGraph.getProperty(e.ln),a=this.getOrCreateClassNode(n.sink[t.id],n),o=this.getOrCreateClassNode(n.sink[c.id],n);if(n.vdir===1){let e=n.y[t.id]+n.innerShift[i.id]+i.size.y+i.getMargin().bottom+r-(n.y[c.id]+n.innerShift[s.id]-s.getMargin().top);this.addClassEdge(a,o,e)}else{let e=n.y[t.id]+n.innerShift[i.id]-i.getMargin().top-n.y[c.id]-n.innerShift[s.id]-s.size.y-s.getMargin().bottom-r;this.addClassEdge(a,o,e)}}}else a=this.threshStrategy.calculateThreshold(a,t,i);i=n.align[i.id]}while(i!==t);this.threshStrategy.finishBlock(t)}placeClasses(e){let t=[];for(let e of this.sinkNodes.values())e.indegree===0&&t.push(e);for(;t.length>0;){let n=t.shift();n.classShift===null&&(n.classShift=0);for(let r of n.outgoing)r.target.classShift===null?r.target.classShift=n.classShift+r.separation:e.vdir===0?r.target.classShift=Math.min(r.target.classShift,n.classShift+r.separation):r.target.classShift=Math.max(r.target.classShift,n.classShift+r.separation),r.target.indegree--,r.target.indegree===0&&t.push(r.target)}for(let t of this.sinkNodes.values())e.shift[t.node.id]=t.classShift}addClassEdge(e,t,n){let r=this.classEdgePool.pop()??new nn;r.target=t,r.separation=n,t.indegree++,e.outgoing.push(r)}getOrCreateClassNode(e,t){let n=this.sinkNodes.get(e);return n===void 0&&(n=this.classNodePool.pop()??new tn,n.classShift=null,n.indegree=0,n.outgoing.length=0,n.node=e,this.sinkNodes.set(n.node,n)),n}},an=class t{lGraph;markedEdges=/* @__PURE__ */ new Set;ni;produceBalancedLayout=!1;static MIN_LAYERS_FOR_CONFLICTS=3;process(t){this.lGraph=t,this.ni=qt.buildFor(t);let n=t.getProperty(e.yt),r=t.getProperty(e.bt);this.produceBalancedLayout=n===`NONE`&&!r||n===`BALANCED`,this.markConflicts(t);let i=this.ni.nodeCount,a=[];switch(n){case`LEFTDOWN`:a.push([0,1]);break;case`LEFTUP`:a.push([1,1]);break;case`RIGHTDOWN`:a.push([0,0]);break;case`RIGHTUP`:a.push([1,0]);break;default:a.push([0,0],[1,0],[0,1],[1,1])}let o=a.length,s=new Float64Array(o*i),c=new Float64Array(o*i),l=Array(o),u=new Jt(t,i,null,null),d=new Xt(t,this.ni),f=new rn(t,this.ni),p=[];for(let e=0;e<o;e++)u.vdir=a[e][0],u.hdir=a[e][1],u.y=s.subarray(e*i,(e+1)*i),u.innerShift=c.subarray(e*i,(e+1)*i),u.su.fill(0),u.od.fill(1),d.verticalAlignment(u,this.markedEdges),d.insideBlockShift(u),f.horizontalCompaction(u),l[e]=u.layoutSize(),p.push({vdir:a[e][0],hdir:a[e][1],y:u.y,innerShift:u.innerShift,size:l[e]});let m=null,h=null,g=0,_=null;if(m===null&&this.produceBalancedLayout&&(_=this.createBalancedLayout(this.lGraph,i,p),this.checkOrderConstraint(t,_.y,_.innerShift)&&(m=_.y,h=_.innerShift,g=0)),m===null)for(let e of p)this.checkOrderConstraint(t,e.y,e.innerShift)&&(m===null||g>e.size+1e-6)&&(m=e.y,h=e.innerShift,g=e.size,`${e.vdir}${e.hdir}`);m===null&&(m=p[0].y,h=p[0].innerShift,g=p[0].size,`${p[0].vdir}${p[0].hdir}`);for(let e of t.getLayers())for(let t of e.getNodes())t.position.y=m[t.id]+h[t.id];u.cleanup(),this.ni.cleanup(),this.markedEdges.clear()}markConflicts(e){let n=e.getLayers().length;if(n<t.MIN_LAYERS_FOR_CONFLICTS)return;let r=e.getLayers().map(e=>e.getNodes().length);for(let t=1;t<n-1;t++){let n=e.getLayers()[t+1],i=0,a=0;for(let e=0;e<r[t+1];e++){let o=n.getNodes()[e],s=this.incidentToInnerSegment(o,t+1,t);if(e===r[t+1]-1||s){let c=r[t]-1;for(s&&(c=this.ni.nodeIndex[this.ni.leftNeighbors[o.id][0].first.id]);a<=e;){let e=n.getNodes()[a];if(!this.incidentToInnerSegment(e,t+1,t))for(let t of this.ni.leftNeighbors[e.id]){let e=this.ni.nodeIndex[t.first.id];(e<i||e>c)&&this.markedEdges.add(t.second.id)}a++}i=c}}}}incidentToInnerSegment(e,t,n){if(e.getType()===`LONG_EDGE`){for(let r of e.getPorts())for(let i of r.getIncomingEdges())if(i.getSource().getNode().getType()===`LONG_EDGE`&&this.ni.layerIndex[i.getSource().getNode().getLayer().getIndex()]===n&&this.ni.layerIndex[e.getLayer().getIndex()]===t)return!0}return!1}createBalancedLayout(e,t,n){let r=n.length,i=new Jt(e,t,null,null),a=Array(r),o=Array(r),s=Array(r),c=0;for(let e=0;e<r;e++)o[e]=2**53-1,s[e]=-(2**53-1);for(let t=0;t<r;t++){let r=n[t];a[t]=r.size,a[c]>a[t]&&(c=t);for(let n of e.getLayers())for(let e of n.getNodes()){let n=r.y[e.id]+r.innerShift[e.id];o[t]=Math.min(o[t],n),s[t]=Math.max(s[t],n+e.size.y)}}let l=Array(r);for(let e=0;e<r;e++)n[e].vdir===0?l[e]=o[c]-o[e]:l[e]=s[c]-s[e];let u=Array(r);for(let t of e.getLayers())for(let e of t.getNodes()){for(let t=0;t<r;t++){let r=n[t];u[t]=r.y[e.id]+r.innerShift[e.id]+l[t]}u.sort((e,t)=>e-t),i.y[e.id]=(u[1]+u[2])/2,i.innerShift[e.id]=0}return i}checkOrderConstraint(e,t,n){let r=!0;for(let i of e.getLayers()){let e=-1/0;for(let a of i.getNodes()){let i=t[a.id]+n[a.id]-a.getMargin().top,o=t[a.id]+n[a.id]+a.size.y+a.getMargin().bottom;if(i>e&&o>e)e=o;else{r=!1;break}}if(!r)break}return r}};function on(t){let n=t.getProperty(e.wr),r=0;for(let e of t.getLayers()){let t=e.getSize();t.y=0;let i=null;for(let r of e.getNodes())i!==null&&(t.y+=n.getVerticalSpacing(r,i)),t.y+=r.getMargin().top+r.getSize().y+r.getMargin().bottom,i=r;r=Math.max(r,t.y)}for(let e of t.getLayers()){let t=e.getSize(),i=(r-t.y)/2,a=null;for(let t of e.getNodes())a!==null&&(i+=n.getVerticalSpacing(t,a)),i+=t.getMargin().top,t.getPosition().y=i,i+=t.getSize().y+t.getMargin().bottom,a=t}}function sn(t){let n=t.getProperty(e.wr);for(let e of t.getLayers())cn(e,n)}function cn(t,n){let r=-1/0,i=`NORMAL`;for(let a of t.getNodes()){let t=a.getType();if(t!==`NORMAL`){let o=a.getProperty(e.dr);o==null?(r=Math.max(r,0),a.getPosition().y=r+n.getVerticalSpacingByType(t,i)):a.getPosition().y=o}let o=n.getVerticalSpacingByType(t,i);a.getPosition().y<r+o+a.getMargin().top&&(a.getPosition().y=r+o+a.getMargin().top),r=a.getPosition().y+a.getSize().y+a.getMargin().bottom,i=t}}const ln=Object.values(e.Ir);var un=class{graph;nodeTypeSpacingOptionsHorizontal;nodeTypeSpacingOptionsVertical;cachedDefaults=/* @__PURE__ */ new Map;constructor(e){this.graph=e,this.nodeTypeSpacingOptionsHorizontal=this.emptyTable(),this.nodeTypeSpacingOptionsVertical=this.emptyTable(),this.precalculateNodeTypeSpacings()}emptyTable(){let e={};for(let t of ln)e[t]={};return e}diagV(e,t){this.nodeTypeSpacingOptionsVertical[e][e]=t}diagVH(e,t,n){this.nodeTypeSpacingOptionsVertical[e][e]=t,this.nodeTypeSpacingOptionsHorizontal[e][e]=n}pairV(e,t,n){this.nodeTypeSpacingOptionsVertical[e][t]=n,this.nodeTypeSpacingOptionsVertical[t][e]=n}pairVH(e,t,n,r){this.nodeTypeSpacingOptionsVertical[e][t]=n,this.nodeTypeSpacingOptionsVertical[t][e]=n,this.nodeTypeSpacingOptionsHorizontal[e][t]=r,this.nodeTypeSpacingOptionsHorizontal[t][e]=r}precalculateNodeTypeSpacings(){let{NORMAL:t,LONG_EDGE:n,NORTH_SOUTH_PORT:r,EXTERNAL_PORT:i,LABEL:a,BREAKING_POINT:o}=e.Ir;this.diagVH(t,e.ln,e.un),this.pairVH(t,n,e.nn,e.rn),this.pairV(t,r,e.nn),this.pairV(t,i,e.nn),this.pairVH(t,a,e.ln,e.un),this.diagVH(n,e.$t,e.en),this.pairV(n,r,e.$t),this.pairV(n,i,e.$t),this.pairVH(n,a,e.nn,e.rn),this.diagV(r,e.$t),this.pairV(r,i,e.$t),this.pairV(r,a,e.on),this.diagV(i,e.pn),this.pairVH(i,a,e.cn,e.sn),this.diagVH(a,e.$t,e.$t),this.diagVH(o,e.$t,e.en),this.pairVH(o,t,e.nn,e.rn),this.pairVH(o,a,e.nn,e.rn),this.pairVH(o,n,e.nn,e.rn)}getVerticalSpacing(e,t){return this.getLocalSpacing(e,t,this.nodeTypeSpacingOptionsVertical)}getHorizontalSpacing(e,t){return this.getLocalSpacing(e,t,this.nodeTypeSpacingOptionsHorizontal)}getVerticalSpacingByType(e,t){return this.getTypeSpacing(e,t,this.nodeTypeSpacingOptionsVertical)}getHorizontalSpacingByType(e,t){return this.getTypeSpacing(e,t,this.nodeTypeSpacingOptionsHorizontal)}getLocalSpacing(e,t,n){let r=e.getType(),i=t.getType(),a=n[r]?.[i],o=this.getIndividualOrDefault(e,a),s=this.getIndividualOrDefault(t,a);return Math.max(o,s)}getTypeSpacing(t,n,r){let i=r[t]?.[n];return i===void 0?this.graph.getProperty(e.ln):this.graph.getProperty(i)}getIndividualOrDefault(t,n){if(n===void 0)return this.graph.getProperty(e.ln);if(!t.hasProperty(e.in)){let e=this.cachedDefaults.get(n);return e===void 0&&(e=this.graph.getProperty(n),this.cachedDefaults.set(n,e)),e}return dn(t,n)}};function dn(t,n){let r=null;if(t.hasProperty(e.in)){let i=t.getProperty(e.in);i&&i.hasProperty(n)&&(r=i.getProperty(n))}return r===null&&(r=t.getGraph()?.getProperty(n)??n.getDefault()),r}const fn=.1,pn=1e4;function mn(t){return t.hasProperty(e.xt)?t.getProperty(e.xt):t.getGraph().getProperty(e.St)}function hn(t){if(t.getType()!==`NORMAL`||t.getPorts().length<=1)return!1;let n=t.getProperty(`org.eclipse.elk.portConstraints`);if(e.Lr.isPosFixed(n))return!1;let r=mn(t);if(r===`NONE`)return!1;if(!gn(r)){let n=dn(t,e.pn),r=t.getProperty(e.fn),i=r.top,a=r.bottom,o=t.getPortSideView(`WEST`);if(i+a+(o.length-1)*n>t.getSize().y)return!1;let s=t.getPortSideView(`EAST`);if(i+a+(s.length-1)*n>t.getSize().y)return!1}return!0}function gn(e){return e===`NODE_SIZE_WHERE_SPACE_PERMITS`||e===`NODE_SIZE`}var _n=class{origin;head;tail;isFlexible;constructor(e,t,n,r){this.origin=e,this.isFlexible=t,this.head=n,this.tail=r}},vn=class{origin;left;right;constructor(e,t,n){this.origin=e,this.left=t,this.right=n}isStraight(){return this.notStraightBy()===0}notStraightBy(){return this.left.target.layer-this.left.delta-(this.right.target.layer-this.right.delta)}},yn=class extends Array{containsLongEdgeDummy(){return this.length===0?!1:this[0].getSource().getNode().getType()===`LONG_EDGE`||this.some(e=>e.getTarget().getNode().getType()===`LONG_EDGE`)}containsFlexibleNode(e){return this.length===0?!1:e(mn(this[0].getSource().getNode()))?!0:this.some(t=>e(mn(t.getTarget().getNode())))}orderTwoPath(){if(this.length!==2)throw Error(`Order only allowed for two paths.`);let e=this[0],t=this[1];e.getTarget().getNode()!==t.getSource().getNode()&&(this.length=0,this.push(t,e))}isTwoPathCenterNodeFlexible(){return hn(this[0].getTarget().getNode())}},bn=class t{lGraph;spacings;nGraph;nodeReps=[];edgeReps=[];portMap=/* @__PURE__ */ new Map;nodeCount=0;edgeCount=0;nodeState=[];crossing=[];twoPaths=[];flexibleWhereSpacePermitsEdges=[];process(t){this.lGraph=t,this.spacings=t.getProperty(e.wr),this.prepare(),this.buildInitialAuxiliaryGraph(),this.insertNorthSouthAuxiliaryEdges(),this.insertInLayerEdgeAuxiliaryEdges(),this.lGraph.getProperty(e.bt)&&this.preferStraightEdges(),this.nGraph.makeConnected();let n=t.getProperty(e.mn)*this.nGraph.nodes.length;if(ie.forGraph(this.nGraph).withIterationLimit(n).withBalancing(!1).execute(),this.flexibleWhereSpacePermitsEdges.length>0){this.insertFlexibleWhereSpaceAuxiliaryEdges();for(let e of this.flexibleWhereSpacePermitsEdges)e.weight=1;ie.forGraph(this.nGraph).withIterationLimit(n).withBalancing(!1).execute()}this.lGraph.getProperty(e.bt)&&this.postProcessTwoPaths(),this.applyPositions(),this.cleanup()}prepare(){this.nGraph=new re;let e=0,t=0;for(let n of this.lGraph.getLayers())for(let r of n.getNodes()){r.id=e++;for(let e of r.getOutgoingEdges())e.id=t++;let n=hn(r);for(let e of r.getPorts()){if(n){let t=e.getAnchor().y;if(t!==Math.floor(t)){let n=t-Math.round(t);e.getAnchor().y-=n}}let t=e.getPosition().y+e.getAnchor().y;if(t!==Math.floor(t)){let n=t-Math.round(t);e.getPosition().y-=n}}}this.nodeReps=Array(e),this.edgeReps=Array(t),this.nodeCount=e,this.edgeCount=t,this.flexibleWhereSpacePermitsEdges=[]}cleanup(){this.nodeReps=[],this.edgeReps=[],this.portMap.clear(),this.flexibleWhereSpacePermitsEdges=[]}buildInitialAuxiliaryGraph(){for(let e of this.lGraph.getLayers())this.transformLayer(e);this.transformEdges()}transformLayer(e){let t=null;for(let n of e.getNodes()){let e=hn(n)?this.transformFixedOrderNode(n):this.transformFixedPosNode(n);if(this.nodeReps[n.id]=e,t!==null){let r=t.origin.getMargin().bottom+this.spacings.getVerticalSpacing(t.origin,n)+n.getMargin().top;t.isFlexible||(r+=t.origin.getSize().y),D().delta(Math.ceil(r)).weight(0).source(t.tail).target(e.head).create()}t=e}}transformFixedPosNode(t){let n=T().origin(t).type(`non-flexible`).create(this.nGraph);for(let r of t.getPorts())e.Ur.includes(r.getSide())&&this.portMap.set(r,n);return new _n(t,!1,n,n)}transformFixedOrderNode(e){let t=T().origin(e).type(`flexible-head`).create(this.nGraph),n=T().origin(e).type(`flexible-tail`).create(this.nGraph),r=new _n(e,!0,t,n),i=e.getSize().y,a=mn(e),o=a===`NODE_SIZE`?1:pn,s=D().weight(o).delta(Math.ceil(i)).source(t).target(n).create();return a===`NODE_SIZE_WHERE_SPACE_PERMITS`&&this.flexibleWhereSpacePermitsEdges.push(s),this.transformPorts([...e.getPortSideView(`WEST`)].reverse(),r),this.transformPorts(e.getPortSideView(`EAST`),r),r}transformPorts(t,n){if(t.length===0)return;let r=dn(n.origin,e.pn),i=dn(n.origin,e.fn),a=n.head,o=null;for(let e of t){let t=0;t=o===null?i.top:r+o.getSize().y;let n=T().origin(e).type(`port`).create(this.nGraph);this.portMap.set(e,n),D().weight(0).delta(Math.ceil(t)).source(a).target(n).create(),o=e,a=n}D().weight(0).delta(Math.ceil(i.bottom+o.getSize().y)).source(a).target(n.tail).create()}transformEdges(){for(let e of this.lGraph.getLayers())for(let t of e.getNodes())for(let e of t.getOutgoingEdges())this.isHandledEdge(e)&&this.transformEdge(e)}transformEdge(e){let t=T().type(`edge`).create(this.nGraph),n=this.nodeReps[e.getSource().getNode().id],r=this.nodeReps[e.getTarget().getNode().id],i=e.getSource(),a=e.getTarget(),o=i.getAnchor().y,s=a.getAnchor().y;n.isFlexible||(o+=i.getPosition().y),r.isFlexible||(s+=a.getPosition().y);let c=Math.max(0,o-s),l=Math.max(0,s-o),u=this.getEdgeWeight(e),d=D().origin(e).weight(u).delta(l).source(t).target(this.portMap.get(i)).create(),f=D().origin(e).weight(u).delta(c).source(t).target(this.portMap.get(a)).create();this.edgeReps[e.id]=new vn(e,d,f)}insertInLayerEdgeAuxiliaryEdges(){for(let e of this.lGraph.getLayers())for(let t of e.getNodes())if(t.getType()===`NORMAL`)for(let e of t.getConnectedEdges()){if(!e.isInLayerEdge())continue;let t=e.getSource().getNode().getType()===`NORMAL`?e.getSource():e.getTarget(),n=e.getOther(t).getNode(),r=this.portMap.get(t),i=this.nodeReps[n.id].head,a=t.getNode().getIndex()<n.getIndex()?r:i,o=t.getNode().getIndex()<n.getIndex()?i:r;D().delta(0).weight(4).source(a).target(o).create()}}insertNorthSouthAuxiliaryEdges(){for(let t of this.lGraph.getLayers())for(let n of t.getNodes()){for(let t of n.getPortSideView(`SOUTH`)){let r=t.getProperty(e._r),i=r==null?void 0:this.nodeReps[r.id];r!=null&&i!==void 0&&this.nodeReps[n.id]!==void 0&&D().delta(0).weight(fn).source(this.nodeReps[n.id].tail).target(i.head).create()}for(let t of n.getPortSideView(`NORTH`)){let r=t.getProperty(e._r),i=r==null?void 0:this.nodeReps[r.id];r!=null&&i!==void 0&&this.nodeReps[n.id]!==void 0&&D().delta(0).weight(fn).source(i.tail).target(this.nodeReps[n.id].head).create()}}}static length(e){return Math.abs(e.source.layer-e.target.layer)-e.delta}getEdgeWeightByType(e,t){return e===`NORMAL`&&t===`NORMAL`?4:e===`NORMAL`||t===`NORMAL`?8:32}preferStraightEdges(){this.nodeState=Array(this.nodeCount),this.twoPaths=[];for(let e of this.lGraph.getLayers())for(let n of e.getNodes())this.nodeState[n.id]=t.getNodeState(n);this.markEdgeCrossings();let e=this.identifyPaths();for(let t of e){if(t.length<=1)continue;if(t.length===2){t.orderTwoPath(),t.isTwoPathCenterNodeFlexible()||this.twoPaths.push(t);continue}if(t.containsLongEdgeDummy()||t.containsFlexibleNode(e=>gn(e)))continue;let e=null;for(let n=0;n<t.length;n++){let r=t[n],i=this.edgeReps[r.id],a=(e===null||n===t.length-1?this.getEdgeWeightByType(`NORMAL`,`LONG_EDGE`):this.getEdgeWeightByType(`LONG_EDGE`,`LONG_EDGE`))*2,o=i.left.weight;i.left.weight=Math.max(o,o+(a-o));let s=i.right.weight;i.right.weight=Math.max(s,s+(a-s)),e=r}}}postProcessTwoPaths(){let e=[...this.twoPaths],t=[];for(;e.length>0;){let n=e.shift();this.improveTwoPath(n,!0)&&t.push(n)}for(;t.length>0;)this.improveTwoPath(t.pop(),!1)}improveTwoPath(e,n){let r=this.edgeReps[e[0].id],i=this.edgeReps[e[1].id];if(r.isStraight()&&i.isStraight())return!1;let a=r.right.target.origin;if(a===null||typeof a.getPorts!=`function`)return!1;let o=a,s=this.nodeReps[o.id],c=o.getIndex(),l=1/0;if(c>0){let e=o.getLayer().getNodes()[c-1],t=this.nodeReps[e.id],n=Math.ceil(this.spacings.getVerticalSpacing(e,o));l=s.head.layer-o.getMargin().top-(t.head.layer+e.getSize().y+e.getMargin().bottom)-n}let u=1/0;if(c<o.getLayer().getNodes().length-1){let e=o.getLayer().getNodes()[c+1],t=this.nodeReps[e.id],n=Math.ceil(this.spacings.getVerticalSpacing(e,o));u=t.head.layer-e.getMargin().top-(s.head.layer+o.getSize().y+o.getMargin().bottom)-n}if(n&&Math.abs(l-u)<=1e-5)return!0;let d=+t.length(r.left),f=-t.length(r.right),p=-t.length(i.left),m=+t.length(i.right),h=r.notStraightBy()>0&&i.notStraightBy()<0,g=r.notStraightBy()<0&&i.notStraightBy()>0,_=r.left.target.layer+r.right.delta<i.right.target.layer+i.left.delta,v=r.left.target.layer+r.right.delta>i.right.target.layer+i.left.delta,y=0;return!h&&!g&&(v?l+p>0?y=p:u-d>0&&(y=d):_&&(l+f>0?y=f:u-m>0&&(y=m))),s.head.layer+=y,s.isFlexible&&(s.tail.layer+=y),!1}identifyPaths(){let e=[];for(let t of this.lGraph.getLayers())for(let n of t.getNodes())if(this.nodeState[n.id]===2)for(let t of n.getConnectedEdges()){if(!this.isHandledEdge(t))continue;let r=this.follow(t,n,new yn);r.length>1&&e.push(r)}return e}follow(e,t,n){let r=e.getOtherNode(t);if(n.push(e),this.nodeState[r.id]===-1||this.nodeState[r.id]===2||this.crossing[e.id])return n;this.nodeState[r.id]=-1;for(let t of r.getConnectedEdges())if(this.isHandledEdge(t)&&t!==e)return this.follow(t,r,n);return n}static getNodeState(e){let t=0,n=0;for(let r of e.getPorts()){for(let e of r.getIncomingEdges())e.isSelfLoop()||t++;for(let e of r.getOutgoingEdges())e.isSelfLoop()||n++;if(t>1||n>1)return 2}return t+n===1?2:0}markEdgeCrossings(){this.crossing=Array(this.edgeCount).fill(!1);let e=this.lGraph.getLayers();for(let t=0;t+1<e.length;t++)this.markCrossingEdges(e[t],e[t+1])}markCrossingEdges(e,t){let n=[];for(let r of e.getNodes())for(let e of r.getPortSideView(`EAST`))for(let r of e.getOutgoingEdges())r.isInLayerEdge()||r.isSelfLoop()||r.getTarget().getNode().getLayer()!==t||n.push(r);for(let r=t.getNodes().length-1;r>=0;r--){let i=t.getNodes()[r];for(let t of i.getPortSideView(`WEST`))for(let r of t.getIncomingEdges())if(!(r.isInLayerEdge()||r.isSelfLoop()||r.getSource().getNode().getLayer()!==e)&&n.length>0){let e=n.length-1,t=n[e];for(;t!==r&&e>0;)this.crossing[t.id]=!0,this.crossing[r.id]=!0,e--,t=n[e];t===r&&e>0&&n.splice(e,1)}}}insertFlexibleWhereSpaceAuxiliaryEdges(){let e=1/0,t=-1/0;for(let n of this.nGraph.nodes)n.layer<e&&(e=n.layer),n.layer>t&&(t=n.layer);let n=t-e,r=T().create(this.nGraph),i=T().create(this.nGraph);D().weight(pn*2).delta(n).source(r).target(i).create();for(let t of this.nodeReps)t!==void 0&&t.origin.getType()===`NORMAL`&&(t.origin.getPorts().length<=1||(D().weight(0).delta(t.tail.layer-e).source(r).target(t.tail).create(),D().weight(0).delta(n-t.head.layer).source(t.head).target(i).create()))}applyPositions(){for(let t of this.lGraph.getLayers())for(let n of t.getNodes()){let t=this.nodeReps[n.id],r=t.head.layer,i=t.tail.layer;n.getPosition().y=r;let a=i-r-n.getSize().y,o=hn(n),s=mn(n);if(o&&gn(s)&&(n.getSize().y+=a),o&&(s===`PORT_POSITION`||gn(s))){for(let t of n.getPorts())if(e.Ur.includes(t.getSide())){let e=this.portMap.get(t);t.getPosition().y=e.layer-r}}}}getEdgeWeight(t){let n=Math.max(1,t.getProperty(e.Gt)),r=t.getSource().getNode().getType(),i=t.getTarget().getNode().getType(),a;return a=r===`NORMAL`&&i===`NORMAL`?4:r===`NORMAL`||i===`NORMAL`?8:32,n*a}isHandledEdge(e){return!e.isSelfLoop()&&!e.isInLayerEdge()}},xn=class{process(t){let n=1/0,r=-1/0,i=!1;for(let a of t.getLayers()){let o=a.getSize();if(o.x=0,o.y=0,a.getNodes().length===0)continue;i=!0;for(let e of a.getNodes())o.x=Math.max(o.x,e.size.x+e.getMargin().left+e.getMargin().right);let s=a.getNodes()[0],c=t.getProperty(e.fn),l=s.getPosition().y-s.getMargin().top;s.getType()===`EXTERNAL_PORT`&&(l-=c.top);let u=a.getNodes()[a.getNodes().length-1],d=u.getPosition().y+u.size.y+u.getMargin().bottom;u.getType()===`EXTERNAL_PORT`&&(d+=c.bottom),o.y=d-l,n=Math.min(n,l),r=Math.max(r,d)}i||(n=0,r=0),t.getSize().y=r-n,t.getOffset().y-=n}};function Sn(t,n){let r=0,i=0;for(let e of t.getNodes())r=Math.max(r,e.getMargin().left),i=Math.max(i,e.getMargin().right);for(let a of t.getNodes()){let o=a.getProperty(e.p),s;if(o===`LEFT`)s=0;else if(o===`RIGHT`)s=1;else if(o===`CENTER`)s=.5;else{let e=0,t=0;for(let n of a.getPorts())n.getIncomingEdges().length>0&&e++,n.getOutgoingEdges().length>0&&t++;s=e+t===0?.5:t/(e+t)}let c=t.getSize(),l=a.size.x,u=(c.x-l)*s;s>.5?u-=i*2*(s-.5):s<.5&&(u+=r*2*(.5-s));let d=a.getMargin().left;u<d&&(u=d);let f=a.getMargin().right;u>c.x-f-l&&(u=c.x-f-l),a.position.x=n+u}}var A=class e{static CRITICAL_DEPENDENCY_WEIGHT=1;type;source=null;target=null;weight;constructor(e,t,n,r){this.type=e,this.weight=r,this.setSource(t),this.setTarget(n)}static createAndAddRegular(t,n,r){return new e(0,t,n,r)}static createAndAddCritical(t,n){return new e(1,t,n,e.CRITICAL_DEPENDENCY_WEIGHT)}remove(){this.setSource(null),this.setTarget(null)}reverse(){let e=this.source,t=this.target;this.setSource(t),this.setTarget(e)}getType(){return this.type}getSource(){return this.source}getTarget(){return this.target}getWeight(){return this.weight}setSource(e){if(this.source!==null){let e=this.source.getOutgoingSegmentDependencies(),t=e.indexOf(this);t!==-1&&e.splice(t,1)}this.source=e,this.source!==null&&this.source.getOutgoingSegmentDependencies().push(this)}setTarget(e){if(this.target!==null){let e=this.target.getIncomingSegmentDependencies(),t=e.indexOf(this);t!==-1&&e.splice(t,1)}this.target=e,this.target!==null&&this.target.getIncomingSegmentDependencies().push(this)}},Cn=class{static detectCycles(e,t,n){let r=[],i=[],a=[];wn(e,i,a,t),Tn(e,i,a,t,n);for(let n of e)for(let e of n.getOutgoingSegmentDependencies())(!t||e.getType()===1)&&n.mark>e.getTarget().mark&&r.push(e);return r}};function wn(e,t,n,r){let i=-1;for(let a of e){a.mark=i--;let e=0;for(let t of a.getIncomingSegmentDependencies())t.getType()===1&&(e+=t.getWeight());let o=0;for(let e of a.getOutgoingSegmentDependencies())e.getType()===1&&(o+=e.getWeight());let s=e,c=o;if(!r){s=0;for(let e of a.getIncomingSegmentDependencies())s+=e.getWeight();c=0;for(let e of a.getOutgoingSegmentDependencies())c+=e.getWeight()}a.setInWeight(s),a.setCriticalInWeight(e),a.setOutWeight(c),a.setCriticalOutWeight(o),c===0?n.push(a):s===0&&t.push(a)}}function Tn(e,t,n,r,i){let a=[],o=[],s=e.length,c=s-1,l=s+1;for(;;){let s=0;for(;s<n.length;){let e=n[s++];e.mark=c--,En(e,t,n,r)}n.length=0;let u=0;for(;u<t.length;){let e=t[u++];e.mark=l++,En(e,t,n,r)}t.length=0,a.length=0;for(let t=e.length-1;t>=0;t--){let n=e[t];n.mark<0&&a.push(n)}if(a.length===0)break;let d=-(2**53-1);o.length=0;for(let e of a){if(!r&&e.getCriticalOutWeight()>0&&e.getCriticalInWeight()<=0){o.length=0,o.push(e);break}let t=e.getOutWeight()-e.getInWeight();t>=d&&(t>d&&(o.length=0,d=t),o.push(e))}if(o.length>0){let e=o[i.nextInt(o.length)];e.mark=l++,En(e,t,n,r)}}let u=e.length+1;for(let t of e)t.mark<s&&(t.mark+=u)}function En(e,t,n,r){for(let n of e.getOutgoingSegmentDependencies())if(!r||n.getType()===1){let e=n.getTarget();e.mark<0&&n.getWeight()>0&&(e.setInWeight(e.getInWeight()-n.getWeight()),n.getType()===1&&e.setCriticalInWeight(e.getCriticalInWeight()-n.getWeight()),e.getInWeight()<=0&&e.getOutWeight()>0&&t.push(e))}for(let t of e.getIncomingSegmentDependencies())if(!r||t.getType()===1){let e=t.getSource();e.mark<0&&t.getWeight()>0&&(e.setOutWeight(e.getOutWeight()-t.getWeight()),t.getType()===1&&e.setCriticalOutWeight(e.getCriticalOutWeight()-t.getWeight()),e.getOutWeight()<=0&&e.getInWeight()>0&&n.push(e))}}const Dn=`EAST`;function On(e){return e.getNode().position.y+e.getPosition().y+e.getAnchor().y}var kn=class e{mark=0;positionFn;srcSide;splitPartner=null;splitBy=null;constructor(e=On,t=Dn){this.positionFn=e,this.srcSide=t}routingSlot=0;ports=[];startPosition=NaN;endPosition=NaN;incomingConnectionCoordinates=[];outgoingConnectionCoordinates=[];incomingSegmentDependencies=[];outgoingSegmentDependencies=[];inWeight=0;outWeight=0;criticalInWeight=0;criticalOutWeight=0;addPortPositions(e,t,n=!0){t.set(e,this),this.ports.push(e);let r=this.positionFn(e);e.getSide()===this.srcSide?An(this.incomingConnectionCoordinates,r):An(this.outgoingConnectionCoordinates,r);let i=e.getIncomingEdges?.();if(i!==void 0){for(let n of i){let r=n.getSource()===e?n.getTarget():n.getSource();t.has(r)||this.addPortPositions(r,t,!1)}for(let n of e.getOutgoingEdges()){let r=n.getSource()===e?n.getTarget():n.getSource();t.has(r)||this.addPortPositions(r,t,!1)}}else for(let n of e.getConnectedPorts())t.has(n)||this.addPortPositions(n,t,!1);n&&this.recomputeExtent()}getPorts(){return this.ports}getSplitPartner(){return this.splitPartner}setSplitPartner(e){this.splitPartner=e}getSplitBy(){return this.splitBy}setSplitBy(e){this.splitBy=e}isDummy(){return this.splitPartner!==null&&this.splitBy===null}getLength(){return this.endPosition-this.startPosition}representsHyperedge(){return this.ports.length>2}getRoutingSlot(){return this.routingSlot}setRoutingSlot(e){this.routingSlot=e}getStartCoordinate(){return this.startPosition}getEndCoordinate(){return this.endPosition}getIncomingConnectionCoordinates(){return this.incomingConnectionCoordinates}getOutgoingConnectionCoordinates(){return this.outgoingConnectionCoordinates}getIncomingSegmentDependencies(){return this.incomingSegmentDependencies}getOutgoingSegmentDependencies(){return this.outgoingSegmentDependencies}getInWeight(){return this.inWeight}setInWeight(e){this.inWeight=e}getOutWeight(){return this.outWeight}setOutWeight(e){this.outWeight=e}getCriticalInWeight(){return this.criticalInWeight}setCriticalInWeight(e){this.criticalInWeight=e}getCriticalOutWeight(){return this.criticalOutWeight}setCriticalOutWeight(e){this.criticalOutWeight=e}splitAt(t){for(this.splitPartner=new e(this.positionFn,this.srcSide),this.splitPartner.setSplitPartner(this),this.splitPartner.outgoingConnectionCoordinates.push(...this.outgoingConnectionCoordinates),this.outgoingConnectionCoordinates.length=0,this.outgoingConnectionCoordinates.push(t),this.splitPartner.incomingConnectionCoordinates.push(t),this.recomputeExtent(),this.splitPartner.recomputeExtent();this.incomingSegmentDependencies.length>0;)this.incomingSegmentDependencies[0].remove();for(;this.outgoingSegmentDependencies.length>0;)this.outgoingSegmentDependencies[0].remove();return this.splitPartner}simulateSplit(){let t=new e(this.positionFn,this.srcSide),n=new e(this.positionFn,this.srcSide);return t.splitBy=this.splitBy,t.splitPartner=n,n.splitPartner=t,t.incomingConnectionCoordinates.push(...this.incomingConnectionCoordinates),t.recomputeExtent(),n.outgoingConnectionCoordinates.push(...this.outgoingConnectionCoordinates),n.recomputeExtent(),[t,n]}recomputeExtent(){this.startPosition=NaN,this.endPosition=NaN,this.recomputeExtentList(this.incomingConnectionCoordinates),this.recomputeExtentList(this.outgoingConnectionCoordinates)}recomputeExtentList(e){e.length!==0&&(this.startPosition=Number.isNaN(this.startPosition)?e[0]:Math.min(this.startPosition,e[0]),this.endPosition=Number.isNaN(this.endPosition)?e[e.length-1]:Math.max(this.endPosition,e[e.length-1]))}};function An(e,t){let n=0,r=e.length;for(;n<r;){let i=n+r>>1,a=e[i];if(a===t)return;a>t?r=i:n=i+1}e.splice(n,0,t)}var jn=class{startPosition;endPosition;size;constructor(e,t){this.startPosition=e,this.endPosition=t,this.size=t-e}},Mn=class{dependencies=0;crossings=0};function Nn(e,t){let n=[];for(let t of e)n.push(...t.getIncomingConnectionCoordinates(),...t.getOutgoingConnectionCoordinates());n.sort((e,t)=>e-t);let r=[];for(let e=1;e<n.length;e++)n[e]-n[e-1]>=2*t&&r.push(new jn(n[e-1]+t,n[e]-t));return r}function Pn(e){let t=/* @__PURE__ */ new Set;for(let n of e){let e=n.getSource(),r=n.getTarget();if(e===null||r===null||t.has(e)||t.has(r))continue;let i=e,a=r;e.representsHyperedge()&&!r.representsHyperedge()&&(i=r,a=e),t.add(i),i.setSplitBy(a)}return t}function Fn(e,t,n,r){let i=Rn(e,n,r);t.push(e.splitAt(i)),In(e,t)}function In(e,t){let n=e.getSplitBy(),r=e.getSplitPartner();if(n!==null&&r!==null){A.createAndAddCritical(e,n),A.createAndAddCritical(n,r);for(let i of t)i!==n&&i!==e&&i!==r&&(Ln(i,e),Ln(i,r))}}function Ln(e,t){if(Math.abs(e.getStartCoordinate()-e.getEndCoordinate())<.001||Math.abs(t.getStartCoordinate()-t.getEndCoordinate())<.001)return;let n=j(e.getOutgoingConnectionCoordinates(),t.getStartCoordinate(),t.getEndCoordinate())+j(t.getIncomingConnectionCoordinates(),e.getStartCoordinate(),e.getEndCoordinate()),r=j(t.getOutgoingConnectionCoordinates(),e.getStartCoordinate(),e.getEndCoordinate())+j(e.getIncomingConnectionCoordinates(),t.getStartCoordinate(),t.getEndCoordinate());(n>0||r>0)&&(n<=r?A.createAndAddCritical(e,t):A.createAndAddCritical(t,e))}function Rn(e,t,n){let r=-1,i=-1;for(let n=0;n<t.length;n++){let a=t[n];if(a.startPosition>e.getEndCoordinate())break;a.endPosition>=e.getStartCoordinate()&&(r<0&&(r=n),i=n)}let a=Kn(e);if(r>=0){let o=zn(e,t,r,i);a=qn(t[o]),Wn(t,o,n)}return a}function zn(e,t,n,r){let i=n;if(n<r){let[a,o]=e.simulateSplit(),s=t[i],c=Bn(e,a,o,s);for(let l=n+1;l<=r;l++){let n=t[l],r=Bn(e,a,o,n);Un(n,r,s,c)&&(s=n,c=r,i=l)}}return i}function Bn(e,t,n,r){let i=qn(r);t.getOutgoingConnectionCoordinates().length=0,t.getOutgoingConnectionCoordinates().push(i),n.getIncomingConnectionCoordinates().length=0,n.getIncomingConnectionCoordinates().push(i);let a=new Mn;for(let r of e.getIncomingSegmentDependencies()){let e=r.getSource();e!==null&&(Vn(a,t,e),Vn(a,n,e))}for(let r of e.getOutgoingSegmentDependencies()){let e=r.getTarget();e!==null&&(Vn(a,t,e),Vn(a,n,e))}a.dependencies+=2;let o=e.getSplitBy();return o!==null&&(a.crossings+=Hn(t,o),a.crossings+=Hn(o,n)),a}function Vn(e,t,n){let r=Hn(t,n),i=Hn(n,t);r===i?r>0&&(e.dependencies+=2,e.crossings+=r):(e.dependencies+=1,e.crossings+=Math.min(r,i))}function Hn(e,t){return j(e.getOutgoingConnectionCoordinates(),t.getStartCoordinate(),t.getEndCoordinate())+j(t.getIncomingConnectionCoordinates(),e.getStartCoordinate(),e.getEndCoordinate())}function Un(e,t,n,r){return t.crossings<r.crossings||t.crossings===r.crossings&&(t.dependencies<r.dependencies||t.dependencies===r.dependencies&&e.size>n.size)}function Wn(e,t,n){let r=e[t];if(e.splice(t,1),r.size/2>=n){let i=t,a=qn(r),o=a-n;r.startPosition<=o&&e.splice(i++,0,new jn(r.startPosition,o));let s=a+n;s<=r.endPosition&&e.splice(i,0,new jn(s,r.endPosition))}}function Gn(e,t){return(e+t)/2}function Kn(e){return Gn(e.getStartCoordinate(),e.getEndCoordinate())}function qn(e){return Gn(e.startPosition,e.endPosition)}function Jn(e,t,n){if(e.length===0)return;let r=Nn(t,n),i=[...Pn(e)].sort((e,t)=>e.getLength()-t.getLength());for(let e of i)Fn(e,t,r,n)}const Yn={sourceSide:`NORTH`,targetSide:`SOUTH`,positionFn:Zn},Xn={sourceSide:`SOUTH`,targetSide:`NORTH`,positionFn:Zn};function Zn(e){return e.getNode().position.x+e.getPosition().x+e.getAnchor().x}const Qn=.2;var $n=class{criticalConflictThreshold=0;edgeSpacing;conflictThreshold;constructor(e){this.edgeSpacing=e,this.conflictThreshold=.5*e}edgeSegmentsScratch=[];portToEdgeSegmentMapScratch=/* @__PURE__ */ new Map;incomingCoordsScratch=[];outgoingCoordsScratch=[];routeEdgesSlotCount(e,t,n){return this.routeEdgesInternal(e,t,n,NaN)}routeEdges(e,t,n,r){return this.routeEdgesInternal(e,t,r,n)}routeEdgesInternal(e,t,n,r){let i=this.edgeSegmentsScratch;i.length=0;let a=this.portToEdgeSegmentMapScratch;if(a.clear(),this.createHyperEdgeSegments(e,`EAST`,i,a),this.createHyperEdgeSegments(t,`WEST`,i,a),i.length===0)return 0;this.criticalConflictThreshold=Qn*this.minimumHorizontalSegmentDistance(i);let o=0,s=!1;for(let e=0;e<i.length-1;e++){let t=i[e];for(let n=e+1;n<i.length;n++)o+=this.createDependencyIfNecessary(t,i[n]),!s&&(t.getOutgoingSegmentDependencies().length>0||i[n].getOutgoingSegmentDependencies().length>0)&&(s=!0)}s&&(o>=2&&Jn(Cn.detectCycles(i,!0,n),i,this.criticalConflictThreshold),nr(i,n)),tr(i);let c=-1;for(let e of i)Math.abs(e.getStartCoordinate()-e.getEndCoordinate())<.001||(c=Math.max(c,e.getRoutingSlot()),Number.isNaN(r)||this.calculateBendPoints(e,r,this.edgeSpacing));return c+1}calculateBendPoints(e,t,n){if(e.isDummy())return;let r=t+e.getRoutingSlot()*n;for(let i of e.getPorts()){let a=i.getNode().position.y+i.getPosition().y+i.getAnchor().y;for(let o of i.getOutgoingEdges()){if(o.isSelfLoop())continue;let i=o.getTarget(),s=i.getNode().position.y+i.getPosition().y+i.getAnchor().y;if(Math.abs(a-s)>.001){let i=r;o.getBendPoints().push({x:i,y:a});let c=e.getSplitPartner();if(c!==null){let e=c.getIncomingConnectionCoordinates()[0];o.getBendPoints().push({x:i,y:e}),i=t+c.getRoutingSlot()*n,o.getBendPoints().push({x:i,y:e})}o.getBendPoints().push({x:i,y:s})}}}}createHyperEdgeSegments(e,t,n,r,i=On,a=Dn){if(e!=null)for(let o of e)for(let e of o.getPorts()){if(e.getSide()!==t||e.getOutgoingEdges().length===0)continue;let o=r.get(e);o===void 0&&(o=new kn(i,a),n.push(o),o.addPortPositions(e,r))}}routeEdgesForDirection(e,t,n,r,i,a,o=NaN){let s=this.edgeSegmentsScratch;s.length=0;let c=this.portToEdgeSegmentMapScratch;if(c.clear(),this.createHyperEdgeSegments(e??[],r,s,c,a,r),this.createHyperEdgeSegments(t??[],i,s,c,a,r),s.length===0)return 0;this.criticalConflictThreshold=Qn*this.minimumHorizontalSegmentDistance(s);let l=0,u=!1;for(let e=0;e<s.length-1;e++){let t=s[e];for(let n=e+1;n<s.length;n++)l+=this.createDependencyIfNecessary(t,s[n]),!u&&(t.getOutgoingSegmentDependencies().length>0||s[n].getOutgoingSegmentDependencies().length>0)&&(u=!0)}u&&(l>=2&&Jn(Cn.detectCycles(s,!0,n),s,this.criticalConflictThreshold),nr(s,n)),tr(s);let d=-1;for(let e of s)Math.abs(e.getStartCoordinate()-e.getEndCoordinate())<.001||(d=Math.max(d,e.getRoutingSlot()),Number.isNaN(o)||this.calculateBendPointsForDirection(e,o,this.edgeSpacing,r));return d+1}calculateBendPointsForDirection(e,t,n,r){if(e.isDummy())return;let i=r===`NORTH`,a=t+(i?-1:1)*e.getRoutingSlot()*n;for(let r of e.getPorts()){let o=Zn(r);for(let s of r.getOutgoingEdges()){if(s.isSelfLoop())continue;let r=s.getTarget();if(r==null)continue;let c=Zn(r);if(Math.abs(o-c)<=.001)continue;let l=a;s.getBendPoints().push({x:o,y:l});let u=e.getSplitPartner();if(u!==null){let e=u.getIncomingConnectionCoordinates()[0];e!==void 0&&(s.getBendPoints().push({x:e,y:l}),l=t+(i?-1:1)*u.getRoutingSlot()*n,s.getBendPoints().push({x:e,y:l}))}s.getBendPoints().push({x:c,y:l})}}}createDependencyIfNecessary(e,t){if(Math.abs(e.getStartCoordinate()-e.getEndCoordinate())<.001||Math.abs(t.getStartCoordinate()-t.getEndCoordinate())<.001)return 0;let n=this.countConflicts(e.getOutgoingConnectionCoordinates(),t.getIncomingConnectionCoordinates()),r=this.countConflicts(t.getOutgoingConnectionCoordinates(),e.getIncomingConnectionCoordinates());if(n===-1||r===-1){let i=0;return n===-1&&(A.createAndAddCritical(t,e),i++),r===-1&&(A.createAndAddCritical(e,t),i++),i}{let i=j(e.getOutgoingConnectionCoordinates(),t.getStartCoordinate(),t.getEndCoordinate())+j(t.getIncomingConnectionCoordinates(),e.getStartCoordinate(),e.getEndCoordinate()),a=j(t.getOutgoingConnectionCoordinates(),e.getStartCoordinate(),e.getEndCoordinate())+j(e.getIncomingConnectionCoordinates(),t.getStartCoordinate(),t.getEndCoordinate()),o=1*n+16*i,s=1*r+16*a;return o<s?A.createAndAddRegular(e,t,s-o):o>s?A.createAndAddRegular(t,e,o-s):o>0&&s>0&&(A.createAndAddRegular(e,t,0),A.createAndAddRegular(t,e,0)),0}}countConflicts(e,t){let n=0;if(e.length>0&&t.length>0){let r=0,i=0,a=e[0],o=t[0],s=!0;do{if(a>o-this.criticalConflictThreshold&&a<o+this.criticalConflictThreshold)return-1;a>o-this.conflictThreshold&&a<o+this.conflictThreshold&&n++,a<=o&&r+1<e.length?a=e[++r]:o<=a&&i+1<t.length?o=t[++i]:s=!1}while(s)}return n}minimumHorizontalSegmentDistance(e){let t=this.incomingCoordsScratch,n=this.outgoingCoordsScratch;t.length=0,n.length=0;for(let r of e)t.push(...r.getIncomingConnectionCoordinates()),n.push(...r.getOutgoingConnectionCoordinates());return Math.min(er(t),er(n))}};function er(e){e.sort((e,t)=>e-t);let t=Number.MAX_VALUE;if(e.length>=2)for(let n=1;n<e.length;n++)e[n]!==e[n-1]&&(t=Math.min(t,e[n]-e[n-1]));return t}function j(e,t,n){let r=0;for(let i=0;i<e.length;i++){let a=e[i];if(a>n)break;a>=t&&r++}return r}function tr(e){let t=[],n=[];for(let r of e)r.setInWeight(r.getIncomingSegmentDependencies().length),r.setOutWeight(r.getOutgoingSegmentDependencies().length),r.getInWeight()===0&&t.push(r),r.getOutWeight()===0&&r.getIncomingConnectionCoordinates().length===0&&n.push(r);let r=-1,i=0;for(;i<t.length;){let e=t[i++];r=Math.max(r,e.getRoutingSlot());for(let n of e.getOutgoingSegmentDependencies()){let i=n.getTarget();i.setRoutingSlot(Math.max(i.getRoutingSlot(),e.getRoutingSlot()+1)),r=Math.max(r,i.getRoutingSlot()),i.setInWeight(i.getInWeight()-1),i.getInWeight()===0&&t.push(i)}}if(r>-1){for(let e of n)e.setRoutingSlot(r);let e=0;for(;e<n.length;){let t=n[e++];for(let e of t.getIncomingSegmentDependencies()){let r=e.getSource();r.getIncomingConnectionCoordinates().length>0||(r.setRoutingSlot(Math.min(r.getRoutingSlot(),t.getRoutingSlot()-1)),r.setOutWeight(r.getOutWeight()-1),r.getOutWeight()===0&&n.push(r))}}}return r+1}function nr(e,t){let n=Cn.detectCycles(e,!1,t);for(let e of n)e.getWeight()===0?e.remove():e.reverse()}var rr=class{process(t){let n=t.getProperty(e.un),r=t.getProperty(e.en),i=t.getProperty(e.rn),a=new $n(r),o=0,s=t.getLayers(),c=t=>t.length>0&&t.every(t=>t.getType().toString()===`EXTERNAL_PORT`&&(t.getProperty(e.Un)===`WEST`||t.getProperty(e.Un)===`EAST`)),l=null;for(let u=0;u<=s.length;u++){let d=u<s.length?s[u].getNodes():null;l!==null&&(Sn(s[u-1],o),o+=s[u-1].getSize().x);let f=l===null?o:o+i,p=t.getProperty(e.br),m=a.routeEdges(l,d,f,p),h=l===null||c(l),g=d===null||c(d);if(m>0){let e=(m-1)*r;l!==null&&(e+=i),d!==null&&(e+=i),e<n&&!h&&!g&&(e=n),o+=e}else!h&&!g&&(o+=n);l=d}let u=o;for(let e of s)for(let t of e.getNodes())u=Math.max(u,t.position.x+t.size.x);t.getSize().x=u}},ir=class{startPos=-1/0;delta=0;deltaNormalized=0;cNodes;incomingConstraints;outDegree=0;reference=null;id=0;reposition=!0;constructor(...e){this.cNodes=/* @__PURE__ */ new Set,this.incomingConstraints=/* @__PURE__ */ new Set,this.outDegree=0;for(let t of e)this.reference===null&&(this.reference=t),this.addCNode(t)}addCNode(e){if(e.cGroup!==null)throw Error(`CNode belongs to another CGroup.`);this.cNodes.add(e),e.cGroup=this}removeCNode(e){let t=this.cNodes.delete(e);return t&&(e.cGroup=null),t}},ar=class{cNodes=[];cGroups=[];predefinedHorizontalConstraints=[];supportedDirections;constructor(e){this.supportedDirections=new Set(e)}supports(e){return this.supportedDirections.has(e)}};const or={getHorizontalSpacing(e,t){return Math.max(e.getHorizontalSpacing(),t.getHorizontalSpacing())},getVerticalSpacing(e,t){return Math.max(e.getVerticalSpacing(),t.getVerticalSpacing())}};function sr(e,t){return Math.abs(e-t)<=1e-4?0:e<t?-1:1}const cr={eq(e,t){return sr(e,t)===0},gt(e,t){return sr(e,t)>0},lt(e,t){return sr(e,t)<0},ge(e,t){return sr(e,t)>=0},le(e,t){return sr(e,t)<=0}};function lr(e,t,n){let r=[...e];r.sort(t);for(let e of r)n.handle(e)}var ur=class{compact(e){let t=1/0;for(let n of e.cGraph.cNodes)t=Math.min(t,n.cGroup.reference.hitbox.x+n.cGroupOffset.x);let n=[];for(let r of e.cGraph.cGroups)r.startPos=t,r.outDegree===0&&n.push(r);for(;n.length>0;){let t=n.shift(),r=t.reference.hitbox.x;for(let e of t.cNodes){let n=t.startPos+e.cGroupOffset.x;e.startPos=e.cGroup.reposition||e.getPosition()<n?n:e.hitbox.x}r-=t.reference.startPos,t.delta+=r,e.direction===`RIGHT`||e.direction===`DOWN`?t.deltaNormalized+=r:t.deltaNormalized-=r;for(let r of t.cNodes)for(let t of r.constraints){let i=e.direction===`LEFT`||e.direction===`RIGHT`?e.spacingsHandler.getHorizontalSpacing(r,t):e.spacingsHandler.getVerticalSpacing(r,t);t.cGroup.startPos=Math.max(t.cGroup.startPos,r.startPos+r.hitbox.width+i-t.cGroupOffset.x),t.reposition||(t.cGroup.startPos=Math.max(t.cGroup.startPos,t.getPosition()-t.cGroupOffset.x)),t.cGroup.outDegree--,t.cGroup.outDegree===0&&n.push(t.cGroup)}}for(let t of e.cGraph.cNodes)t.applyPosition()}},dr=class{calculateConstraints(e){for(let t of e.cGraph.cNodes)t.constraints.length=0;for(let t of e.cGraph.cNodes)for(let n of e.cGraph.cNodes){if(t===n||t.cGroup!==null&&t.cGroup===n.cGroup)continue;let r=e.direction===`LEFT`||e.direction===`RIGHT`?e.spacingsHandler.getVerticalSpacing(t,n):e.spacingsHandler.getHorizontalSpacing(t,n);t!==n.parentNode&&(n.hitbox.x>t.hitbox.x||t.hitbox.x===n.hitbox.x&&t.hitbox.width<n.hitbox.width)&&cr.gt(n.hitbox.y+n.hitbox.height+r,t.hitbox.y)&&cr.lt(n.hitbox.y,t.hitbox.y+t.hitbox.height+r)&&t.constraints.push(n)}}},M=class e{static EPSILON=.5;compactor;calculateConstraints(e){this.compactor=e,this.sweep(()=>!0,()=>0)}sweep(e,t){this.blowUpHitboxes(e,t);let n=[];for(let t of this.compactor.cGraph.cNodes)e(t)&&(n.push(new fr(t,!0)),n.push(new fr(t,!1)));let r=0;for(let t of this.compactor.cGraph.cNodes)e(t)&&(t.id=r++);this.handler.reset(this.compactor.cGraph.cNodes.length),lr(n,mr,this.handler),this.normalizeHitboxes(e,t)}blowUpHitboxes(t,n){for(let r of this.compactor.cGraph.cNodes){if(!t(r))continue;let i=n(r);i>0&&((this.compactor.direction===`LEFT`||this.compactor.direction===`RIGHT`?r.spacingIgnore.up:r.spacingIgnore.left)||(r.hitbox.y-=Math.max(0,i/2-e.EPSILON)),(this.compactor.direction===`LEFT`||this.compactor.direction===`RIGHT`?r.spacingIgnore.down:r.spacingIgnore.right)||(r.hitbox.height+=Math.max(0,i-2*e.EPSILON)))}}normalizeHitboxes(t,n){for(let r of this.compactor.cGraph.cNodes){if(!t(r))continue;let i=n(r);i>0&&((this.compactor.direction===`LEFT`||this.compactor.direction===`RIGHT`?r.spacingIgnore.up:r.spacingIgnore.left)||(r.hitbox.y+=Math.max(0,i/2-e.EPSILON)),(this.compactor.direction===`LEFT`||this.compactor.direction===`RIGHT`?r.spacingIgnore.down:r.spacingIgnore.right)||(r.hitbox.height-=i-2*e.EPSILON))}}handler=new hr},fr=class{node;low;constructor(e,t){this.node=e,this.low=t}};function pr(e){return e.low?e.node.hitbox.y:e.node.hitbox.y+e.node.hitbox.height}const mr=(e,t)=>{let n=pr(e)-pr(t);if(n===0){if(!e.low&&t.low)return-1;if(!t.low&&e.low)return 1}return n};var hr=class{intervals=[];cand=[];reset(e){this.intervals=[],this.cand=Array(e)}handle(e){e.low?this.insert(e):this.delete(e)}insert(e){this.intervals.push(e.node),this.intervals.sort((e,t)=>e.hitbox.x+e.hitbox.width/2-(t.hitbox.x+t.hitbox.width/2)),this.cand[e.node.id]=this.lower(e.node);let t=this.higher(e.node);t!==null&&(this.cand[t.id]=e.node)}delete(e){let t=this.lower(e.node);t!==null&&t===this.cand[e.node.id]&&t.cGroup!==null&&t.cGroup!==e.node.cGroup&&t.constraints.push(e.node);let n=this.higher(e.node);n!==null&&this.cand[n.id]===e.node&&n.cGroup!==null&&n.cGroup!==e.node.cGroup&&e.node.constraints.push(n),this.intervals.splice(this.intervals.indexOf(e.node),1)}lower(e){let t=e.hitbox.x+e.hitbox.width/2,n=null;for(let r of this.intervals){let i=r.hitbox.x+r.hitbox.width/2;if(i<t)n=r;else if((i!==t||r===e||n!==null)&&i>t)break}return n}higher(e){let t=e.hitbox.x+e.hitbox.width/2;for(let e of this.intervals)if(e.hitbox.x+e.hitbox.width/2>t)return e;return null}},gr=class e{static LONGEST_PATH_COMPACTION=new ur;static SCANLINE_CONSTRAINTS=new M;static QUADRATIC_CONSTRAINTS=new dr;compactionAlgorithm=e.LONGEST_PATH_COMPACTION;constraintAlgorithm=e.SCANLINE_CONSTRAINTS;cGraph;direction=`UNDEFINED`;lockingStrategy;finished=!1;spacingsHandler=or;constructor(e){this.cGraph=e,this.lockingStrategy=e=>e.first.cGroup.outDegree!==0,this.calculateGroupOffsets();for(let t of e.cNodes)if(t.cGroup===null){let n=new ir(t);e.cGroups.push(n)}}setSpacingsHandler(e){return this.spacingsHandler=e,this}setCompactionAlgorithm(e){return this.compactionAlgorithm=e,this}setConstraintAlgorithm(e){return this.constraintAlgorithm=e,this}compact(){if(this.finished)throw Error(`The OneDimensionalCompactor instance has been finished already.`);this.direction===`UNDEFINED`&&this.changeDirection(`LEFT`);for(let e of this.cGraph.cNodes)e.hitboxPreCompaction={...e.hitbox};for(let e of this.cGraph.cGroups)e.outDegree=0;for(let e of this.cGraph.cNodes){e.startPos=-1/0;for(let t of e.constraints)t.cGroup.outDegree++}this.compactionAlgorithm.compact(this);for(let e of this.cGraph.cNodes)e.reposition=!0;return this}finish(){return this.changeDirection(`LEFT`),this.finished=!0,this}changeDirection(e){if(this.finished)throw Error(`The OneDimensionalCompactor instance has been finished already.`);if(!this.cGraph.supports(e))throw Error(`The direction ${e} is not supported by the CGraph instance.`);if(e===this.direction)return this;let t=this.direction;switch(this.direction=e,t){case`UNDEFINED`:e===`LEFT`?this.calculateConstraints():e===`RIGHT`?(this.mirrorHitboxes(),this.calculateConstraints()):e===`UP`?(this.transposeHitboxes(),this.calculateConstraints()):e===`DOWN`&&(this.transposeHitboxes(),this.mirrorHitboxes(),this.calculateConstraints());break;case`LEFT`:e===`RIGHT`?(this.mirrorHitboxes(),this.reverseConstraints()):e===`UP`?(this.transposeHitboxes(),this.calculateConstraints()):e===`DOWN`&&(this.transposeHitboxes(),this.mirrorHitboxes(),this.calculateConstraints());break;case`RIGHT`:e===`LEFT`?(this.mirrorHitboxes(),this.reverseConstraints()):e===`UP`?(this.mirrorHitboxes(),this.transposeHitboxes(),this.calculateConstraints()):e===`DOWN`&&(this.mirrorHitboxes(),this.transposeHitboxes(),this.mirrorHitboxes(),this.calculateConstraints());break;case`UP`:e===`LEFT`?(this.transposeHitboxes(),this.calculateConstraints()):e===`RIGHT`?(this.transposeHitboxes(),this.mirrorHitboxes(),this.calculateConstraints()):e===`DOWN`&&(this.mirrorHitboxes(),this.reverseConstraints());break;case`DOWN`:e===`LEFT`?(this.mirrorHitboxes(),this.transposeHitboxes(),this.calculateConstraints()):e===`RIGHT`?(this.mirrorHitboxes(),this.transposeHitboxes(),this.mirrorHitboxes(),this.calculateConstraints()):e===`UP`&&(this.mirrorHitboxes(),this.reverseConstraints())}return this}setLockingStrategy(e){return this.lockingStrategy=e,this}applyLockingStrategy(e){let t=e??this.direction;for(let e of this.cGraph.cGroups)e.reposition=!0;for(let e of this.cGraph.cNodes)e.reposition=this.lockingStrategy({first:e,second:t}),e.cGroup.reposition=e.cGroup.reposition&&e.reposition;return this}forceConstraintsRecalculation(){return this.calculateConstraints(),this}calculateGroupOffsets(){for(let e of this.cGraph.cGroups){e.reference=null;for(let t of e.cNodes)t.cGroupOffset.x=0,t.cGroupOffset.y=0,(e.reference===null||t.hitbox.x<e.reference.hitbox.x)&&(e.reference=t);for(let t of e.cNodes)t.cGroupOffset.x=t.hitbox.x-e.reference.hitbox.x,t.cGroupOffset.y=t.hitbox.y-e.reference.hitbox.y}return this}mirrorHitboxes(){for(let e of this.cGraph.cNodes)e.hitbox.x=-e.hitbox.x-e.hitbox.width,e.parentNode!==null&&(e.cGroupOffset.x=-e.cGroupOffset.x+e.parentNode.hitbox.width);this.calculateGroupOffsets()}transposeHitboxes(){for(let e of this.cGraph.cNodes){let t=e.hitbox.x;e.hitbox.x=e.hitbox.y,e.hitbox.y=t,t=e.hitbox.width,e.hitbox.width=e.hitbox.height,e.hitbox.height=t,t=e.cGroupOffset.x,e.cGroupOffset.x=e.cGroupOffset.y,e.cGroupOffset.y=t}this.calculateGroupOffsets()}calculateConstraints(){for(let e of this.cGraph.cNodes)e.constraints.length=0;let e=this.cGraph.predefinedHorizontalConstraints;for(let[t,n]of e)this.direction===`LEFT`||this.direction===`UP`?t.constraints.push(n):n.constraints.push(t);this.constraintAlgorithm.calculateConstraints(this),this.calculateConstraintsForCGroups()}calculateConstraintsForCGroups(){for(let e of this.cGraph.cGroups)e.outDegree=0,e.incomingConstraints.clear();for(let e of this.cGraph.cGroups)for(let t of e.cNodes)for(let n of t.constraints)n.cGroup!==e&&(e.incomingConstraints.add(n),n.cGroup.outDegree++)}reverseConstraints(){let e=/* @__PURE__ */ new Map;for(let t of this.cGraph.cNodes)e.set(t,[]);for(let t of this.cGraph.cNodes){t.startPos=-1/0;for(let n of t.constraints)e.get(n).push(t)}for(let t of this.cGraph.cNodes)t.constraints=e.get(t);this.calculateConstraintsForCGroups()}},_r=class{left=!1;right=!1;up=!1;down=!1;constructor(e=!1,t=!1,n=!1,r=!1){this.set(e,t,n,r)}set(e,t,n,r){typeof t==`boolean`?(this.left=e,this.right=t,this.up=n??!1,this.down=r??!1):this.setDirection(e,t)}setDirection(e,t){switch(t){case`LEFT`:this.left=e;break;case`RIGHT`:this.right=e;break;case`UP`:this.up=e;break;case`DOWN`:this.down=e}}applyOr(e){this.left=this.left||e.left,this.right=this.right||e.right,this.up=this.up||e.up,this.down=this.down||e.down}get(e){switch(e){case`LEFT`:return this.left;case`RIGHT`:return this.right;case`UP`:return this.up;case`DOWN`:return this.down;default:return!1}}},vr=class{cGroup=null;parentNode=null;constraints=[];hitbox={x:0,y:0,width:0,height:0};hitboxPreCompaction=null;cGroupOffset=e.ti(0,0);startPos=-1/0;reposition=!0;lock=new _r;spacingIgnore=new _r;id=0;getPosition(){return this.hitbox.x}applyPosition(){this.hitbox.x=this.startPos}},N=class extends vr{lNode;constructor(e){super(),this.lNode=e;let t=e.getMargin(),n=e.getPosition(),r=e.getSize();this.hitbox={x:n.x-t.left,y:n.y-t.top,width:r.x+t.left+t.right,height:r.y+t.top+t.bottom}}getHorizontalSpacing(){return 0}getVerticalSpacing(){return 0}applyElementPosition(){this.lNode.getPosition().x=this.hitbox.x+this.lNode.getMargin().left}getElementPosition(){return this.hitbox.x}},P=class extends vr{vs;constructor(e){super(),this.vs=e,this.hitbox={...e.hitbox}}getHorizontalSpacing(){return 0}getVerticalSpacing(){return 0}applyElementPosition(){let e=this.hitboxPreCompaction,t=e===null?0:this.hitbox.x-e.x;for(let e of this.vs.affectedBends)e.x+=t;for(let e of this.vs.affectedBoundingBoxes)e.x+=t;for(let e of this.vs.junctionPoints)e.x+=t}getElementPosition(){return this.hitbox.x}};const yr=.01;var br=class extends M{graph;verticalEdgeEdgeSpacing;edgeRouting;constructor(t){super(),this.graph=t,this.verticalEdgeEdgeSpacing=t.getProperty(e.$t),this.edgeRouting=t.getProperty(e.B)}calculateConstraints(e){this.compactor=e,this.edgeRouting===`SPLINES`?this.calculateForSpline():this.calculateForOrthogonal()}alterHitbox(e,t,n){let r=t*n;if(e instanceof P){let t=e.vs;t.ignoreSpacing.up?t.ignoreSpacing.down||(e.hitbox.height+=r+yr):(e.hitbox.y-=r+yr,e.hitbox.height+=r+yr)}else e instanceof N&&(e.hitbox.y-=r,e.hitbox.height+=2*r)}alterGroupedHitboxOrthogonal(e,t,n){let r=null;for(let t of e.cNodes)if(t instanceof N){r=t;break}if(r===null&&(r=e.cNodes.values().next().value??null),r===null||(this.alterHitbox(r,t,n),e.cNodes.size===1))return;let i=t*n;for(let t of e.cNodes){if(t===r||!(t instanceof P))continue;let e=t.vs;e.ignoreSpacing.up?(t.hitbox.y+=i+yr,t.hitbox.height-=i+yr):e.ignoreSpacing.down&&(t.hitbox.height-=i+yr)}}calculateForSpline(){this.sweep(e=>e instanceof P,()=>0);let t=1/0;for(let n of this.compactor.cGraph.cNodes)if(!(n instanceof N&&n.lNode.getType()===`EXTERNAL_PORT`)){if(n instanceof P)t=Math.min(t,Math.max(0,this.verticalEdgeEdgeSpacing/2-M.EPSILON));else if(n instanceof N){let n=this.graph.getProperty(e.ln);t=Math.min(t,Math.max(0,n/2-M.EPSILON))}}Number.isFinite(t)||(t=0);let n=[];for(let e of this.compactor.cGraph.cNodes)e instanceof N&&(this.alterHitbox(e,t,1),n.push([e,t]));this.sweep(e=>!0,()=>0);for(let[e,t]of n)this.alterHitbox(e,t,-1)}calculateForOrthogonal(){let t=[];for(let e of this.compactor.cGraph.cNodes)if(e instanceof P){let n=Math.max(0,this.verticalEdgeEdgeSpacing/2-M.EPSILON);this.alterHitbox(e,n,1),t.push([e,n])}this.sweep(e=>e instanceof P,()=>0);for(let[e,n]of t)this.alterHitbox(e,n,-1);let n=[];for(let t of this.compactor.cGraph.cNodes)if(t instanceof N){let r=Math.max(0,this.graph.getProperty(e.$t)/2-M.EPSILON);this.alterHitbox(t,r,1),n.push([t,r])}this.sweep(e=>e instanceof N,()=>0);for(let[e,t]of n)this.alterHitbox(e,t,-1);let r=1/0;for(let t of this.compactor.cGraph.cNodes)t instanceof N&&t.lNode.getType()===`EXTERNAL_PORT`||(t instanceof P?r=Math.min(r,Math.max(0,this.verticalEdgeEdgeSpacing/2-M.EPSILON)):t instanceof N&&(r=Math.min(r,Math.max(0,this.graph.getProperty(e.ln)/2-M.EPSILON))));Number.isFinite(r)||(r=0);let i=[];for(let e of this.compactor.cGraph.cGroups)this.alterGroupedHitboxOrthogonal(e,r,1),i.push([e,r]);this.sweep(e=>!0,()=>0);for(let[e,t]of i)this.alterGroupedHitboxOrthogonal(e,t,-1)}},xr=class{potentialGroupParents=[];representedLEdges=[];affectedBends=[];affectedBoundingBoxes=[];hitbox={x:0,y:0,width:0,height:0};junctionPoints=[];ignoreSpacing=new _r;constraints=[];aPort=null;joined=[];constructor(e,t,n,r){this.affectedBends.push(e),this.affectedBends.push(t),this.hitbox.x=Math.min(e.x,t.x),this.hitbox.y=Math.min(e.y,t.y),this.hitbox.width=Math.abs(e.x-t.x),this.hitbox.height=Math.abs(e.y-t.y),n!==null&&this.potentialGroupParents.push(n),this.representedLEdges.push(r)}joinWith(e){this.representedLEdges.push(...e.representedLEdges),this.affectedBends.push(...e.affectedBends),this.affectedBoundingBoxes.push(...e.affectedBoundingBoxes),this.junctionPoints.push(...e.junctionPoints),this.constraints.push(...e.constraints),this.potentialGroupParents.push(...e.potentialGroupParents);let t=Math.min(this.hitbox.x,e.hitbox.x),n=Math.min(this.hitbox.y,e.hitbox.y),r=Math.max(this.hitbox.x+this.hitbox.width,e.hitbox.x+e.hitbox.width),i=Math.max(this.hitbox.y+this.hitbox.height,e.hitbox.y+e.hitbox.height);return this.hitbox={x:t,y:n,width:r-t,height:i-n},this.ignoreSpacing.applyOr(e.ignoreSpacing),this.aPort===null&&(this.aPort=e.aPort),this.joined.push(...e.joined),this.joined.push(e),this}intersects(e){return cr.eq(this.hitbox.x,e.hitbox.x)&&!(cr.lt(this.hitbox.y+this.hitbox.height,e.hitbox.y)||cr.lt(e.hitbox.y+e.hitbox.height,this.hitbox.y))}compareTo(e){let t=cr.eq(this.hitbox.x,e.hitbox.x)?0:this.hitbox.x<e.hitbox.x?-1:1;return t===0?this.hitbox.y-e.hitbox.y:t}},Sr=class{cGraph;layeredGraph;edgeRouting;nodesMap=/* @__PURE__ */ new Map;verticalSegmentsMap=/* @__PURE__ */ new Map;lockMap=/* @__PURE__ */ new Map;transform(t){return this.layeredGraph=t,this.edgeRouting=t.getProperty(e.B),this.cGraph=new ar([`LEFT`,`RIGHT`]),this.nodesMap=/* @__PURE__ */ new Map,this.verticalSegmentsMap=/* @__PURE__ */ new Map,this.lockMap=/* @__PURE__ */ new Map,this.transformNodes(),this.transformEdges(),this.cGraph}getLockMap(){return this.lockMap}transformNodes(){let e=0;for(let t of this.layeredGraph.getLayers())for(let n of t.getNodes()){let t=new N(n);t.id=e++,this.cGraph.cNodes.push(t);let r=new ir(t);this.cGraph.cGroups.push(r);let i=new _r;this.lockMap.set(t,i);let a=n.getIncomingEdges().length-n.getOutgoingEdges().length;a<0?i.set(!0,`LEFT`):a>0&&i.set(!0,`RIGHT`),n.getType()===`EXTERNAL_PORT`&&i.set(!1,!1,!1,!1),this.nodesMap.set(n,t)}}transformEdges(){let e;e=this.edgeRouting===`ORTHOGONAL`?this.collectVerticalSegmentsOrthogonal():this.edgeRouting===`SPLINES`?this.collectVerticalSegmentsSplines():[],this.mergeVerticalSegments(e);for(let[e,t]of this.verticalSegmentsMap)for(let n of e.constraints){let e=this.verticalSegmentsMap.get(n);e&&this.cGraph.predefinedHorizontalConstraints.push([t,e])}}collectVerticalSegmentsOrthogonal(){let e=[];for(let t of this.layeredGraph.getLayers())for(let n of t.getNodes()){let t=this.nodesMap.get(n);if(t){for(let r of n.getOutgoingEdges()){let n=r.getBendPoints();if(n.length===0)continue;let i=!0,a=null,o=n[0],s=null,c=r.getSource();if(c.getSide()===`NORTH`){let n=new xr(o,{x:o.x,y:t.hitbox.y},t,r);n.ignoreSpacing.down=!0,n.aPort=c,e.push(n)}if(c.getSide()===`SOUTH`){let n=new xr(o,{x:o.x,y:t.hitbox.y+t.hitbox.height},t,r);n.ignoreSpacing.up=!0,n.aPort=c,e.push(n)}for(let c=1;c<n.length;c++)s=n[c],cr.eq(o.y,s.y)||(a=new xr(o,s,null,r),e.push(a),i&&(i=!1,s.y<t.hitbox.y?a.ignoreSpacing.down=!0:s.y>t.hitbox.y+t.hitbox.height?a.ignoreSpacing.up=!0:(a.ignoreSpacing.up=!0,a.ignoreSpacing.down=!0))),c+1<n.length&&(o=s);if(a!==null){let e=this.nodesMap.get(r.getTarget().getNode());e&&(o.y<e.hitbox.y?a.ignoreSpacing.down=!0:o.y>e.hitbox.y+e.hitbox.height?a.ignoreSpacing.up=!0:(a.ignoreSpacing.up=!0,a.ignoreSpacing.down=!0))}}for(let r of n.getIncomingEdges()){let n=r.getBendPoints();if(n.length===0)continue;let i=n[n.length-1],a=r.getTarget();if(a.getSide()===`NORTH`){let n=new xr(i,{x:i.x,y:t.hitbox.y},t,r);n.ignoreSpacing.down=!0,n.aPort=a,e.push(n)}if(a.getSide()===`SOUTH`){let n=new xr(i,{x:i.x,y:t.hitbox.y+t.hitbox.height},t,r);n.ignoreSpacing.up=!0,n.aPort=a,e.push(n)}}}}return e}collectVerticalSegmentsSplines(){let t=[];this.cGraph.cNodes.length;for(let n of this.layeredGraph.getLayers())for(let r of n.getNodes())for(let n of r.getOutgoingEdges()){let r=n.getProperty(e.Dr);if(!r||r.length===0)continue;let i=null;for(let e of r){if(e.isStraight)continue;let n=new xr({x:e.boundingBox.x,y:e.boundingBox.y},{x:e.boundingBox.x+e.boundingBox.width,y:e.boundingBox.y+e.boundingBox.height},null,e.edges[0]);n.affectedBoundingBoxes.push(e.boundingBox),t.push(n),i!==null&&i.constraints.push(n),i=n}}return t}mergeVerticalSegments(e){if(e.length===0)return;e.sort((e,t)=>e.compareTo(t));let t=e[0];for(let n=1;n<e.length;n++){let r=e[n];t.intersects(r)?t.joinWith(r):(this.verticalSegmentToCNode(t),t=r)}this.verticalSegmentToCNode(t)}verticalSegmentToCNode(e){let t=new P(e);if(t.id=this.cGraph.cNodes.length,this.cGraph.cNodes.push(t),e.potentialGroupParents.length>0){let n=e.potentialGroupParents[0].cGroup;n&&n.addCNode(t)}else{let e=new ir(t);this.cGraph.cGroups.push(e)}let n=new _r;this.lockMap.set(t,n);let r=/* @__PURE__ */ new Set,i=/* @__PURE__ */ new Set;for(let t of e.representedLEdges)t.getSource()&&r.add(t.getSource().id),t.getTarget()&&i.add(t.getTarget().id);let a=r.size-i.size;a<0?(n.set(!0,`LEFT`),n.set(!1,`RIGHT`)):a>0&&(n.set(!1,`LEFT`),n.set(!0,`RIGHT`));for(let n of e.joined)this.verticalSegmentsMap.set(n,t);this.verticalSegmentsMap.set(e,t)}applyLayout(){for(let e of this.cGraph.cNodes)e instanceof N&&e.applyElementPosition();for(let e of this.cGraph.cNodes)e instanceof P&&e.applyElementPosition();if(this.edgeRouting===`SPLINES`){for(let e of this.layeredGraph.getLayers())for(let t of e.getNodes())for(let e of t.getOutgoingEdges()){if(!e.isSelfLoop())continue;let t=e.getSource().getNode(),n=this.nodesMap.get(t);if(n===void 0||n.hitboxPreCompaction===null)continue;let r=n.hitbox.x-n.hitboxPreCompaction.x;for(let t of e.getBendPoints())t.x+=r}for(let t of this.layeredGraph.getLayers())for(let n of t.getNodes())for(let t of n.getOutgoingEdges()){let n=t.getProperty(e.Dr);n!=null&&n.length>0&&this.adjustSplineControlPoints(n)}}let t=1/0,n=1/0,r=-1/0,i=-1/0;for(let e of this.cGraph.cNodes)t=Math.min(t,e.hitbox.x),n=Math.min(n,e.hitbox.y),r=Math.max(r,e.hitbox.x+e.hitbox.width),i=Math.max(i,e.hitbox.y+e.hitbox.height);Number.isFinite(t)&&(this.layeredGraph.getOffset().x=-t,this.layeredGraph.getOffset().y=-n,this.layeredGraph.getSize().x=r-t,this.layeredGraph.getSize().y=i-n)}adjustSplineControlPoints(e){if(e.length===0)return;let t=e[0];if(e.length===1){this.adjustControlPointBetweenSegments(t,t,1,0,e);return}let n=1;for(;n<e.length;)if(t.initialSegment||!t.isStraight){let r=this.firstNonStraightSegment(e,n);if(r!==null){let i=r.index,a=r.segment;this.adjustControlPointBetweenSegments(t,a,n,i,e),n=i+1,t=a}}}firstNonStraightSegment(e,t){if(t<0||t>=e.length)return null;for(let n=t;n<e.length;n++){let t=e[n];if(n===e.length-1||!t.isStraight)return{index:n,segment:t}}return null}adjustControlPointBetweenSegments(e,t,n,r,i){let a,o=n;if(e.initialSegment&&e.isStraight){let t=this.nodesMap.get(e.sourceNode);a=t.hitbox.x+t.hitbox.width,o--}else a=e.boundingBox.x+e.boundingBox.width;let s,c=r;t.lastSegment&&t.isStraight?(s=this.nodesMap.get(t.targetNode).hitbox.x,c++):s=t.boundingBox.x;let l=(s-a)/Math.max(2,c-o),u=a+l;for(let e=o;e<c;e++){let t=i[e],n=t.boundingBox.width;t.boundingBox.x=u-n/2,u+=l}}};function Cr(e){return e.getOutgoingEdges().length>0}function wr(e){return e.getIncomingEdges().length>0}function Tr(e){return e===`NORTH`||e===`SOUTH`}function Er(e){return e===`LEFT`||e===`RIGHT`}function Dr(e){return Math.trunc(Math.ceil(e))}var Or=class{compactor;networkSimplexGraph;nNodes=[];index=0;compact(e){this.compactor=e,this.networkSimplexGraph=new re,this.nNodes=Array(this.compactor.cGraph.cGroups.length),this.index=0;for(let e of this.compactor.cGraph.cGroups){e.id=this.index;let t=T().id(this.index).origin(e).create(this.networkSimplexGraph);this.nNodes[this.index]=t,this.index++}this.addSeparationConstraints(),this.addEdgeConstraints(),this.addArtificialSourceNode(),ie.forGraph(this.networkSimplexGraph).execute();for(let e of this.compactor.cGraph.cNodes)e.hitbox.x=this.nNodes[e.cGroup.id].layer+e.cGroupOffset.x}addSeparationConstraints(){for(let e of this.compactor.cGraph.cNodes)for(let t of e.constraints){if(e.cGroup===t.cGroup)continue;let n=Er(this.compactor.direction)?this.compactor.spacingsHandler.getHorizontalSpacing(e,t):this.compactor.spacingsHandler.getVerticalSpacing(e,t),r=e.cGroupOffset.x+e.hitbox.width+n-t.cGroupOffset.x;if(r=Math.ceil(r),r=Math.max(0,r),kr(e,t)){let n=T().create(this.networkSimplexGraph),r=Dr(t.cGroupOffset.x-e.cGroupOffset.x),i=r-(t.cGroupOffset.x-e.cGroupOffset.x),a=jr(e)?.aPort??null,o=e;a===null&&(a=jr(t)?.aPort??null,i=-i,o=t),a!==null&&(o.cGroupOffset.x-=i,a.getPosition().x-=i),D().delta(Math.max(0,r)).weight(1).source(n).target(this.nNodes[e.cGroup.id]).create(),D().delta(Math.max(0,-r)).weight(1).source(n).target(this.nNodes[t.cGroup.id]).create()}else{let n=1;(e instanceof P&&t instanceof N||t instanceof P&&e instanceof N)&&(n=2),D().delta(r).weight(n).source(this.nNodes[e.cGroup.id]).target(this.nNodes[t.cGroup.id]).create()}}}addEdgeConstraints(){let e=/* @__PURE__ */ new Map,t=/* @__PURE__ */ new Map;for(let n of this.compactor.cGraph.cNodes){let r=Ar(n);if(r!==null)e.set(r,n);else{let e=jr(n);if(e!==null)for(let r of e.representedLEdges){let e=t.get(r);e===void 0?t.set(r,[n]):e.push(n)}}}for(let n of this.compactor.cGraph.cNodes){let r=Ar(n);if(r!==null)for(let i of r.getOutgoingEdges()){if(i.isSelfLoop())continue;let r=i.getSource(),a=i.getTarget();if(r===null||a===null||Tr(r.getSide())&&Tr(a.getSide()))continue;let o=e.get(a.getNode());if(o!==void 0){if(D().delta(0).weight(100).source(this.nNodes[n.cGroup.id]).target(this.nNodes[o.cGroup.id]).create(),r.getSide()===`WEST`&&Cr(r)){for(let e of t.get(i)??[])if(e.hitbox.x<n.hitbox.x){let t=this.nNodes[e.cGroup.id],r=this.nNodes[n.cGroup.id];if(t===r)continue;D().delta(1).weight(100).source(t).target(r).create()}}if(a.getSide()===`EAST`&&wr(a)){for(let e of t.get(i)??[])if(e.hitbox.x>n.hitbox.x){let t=this.nNodes[n.cGroup.id],r=this.nNodes[e.cGroup.id];if(t===r)continue;D().delta(1).weight(100).source(t).target(r).create()}}}}}}addArtificialSourceNode(){let e=[];for(let t of this.networkSimplexGraph.nodes)t.getIncomingEdges().length===0&&e.push(t);if(e.length>1){let t=T().id(this.index++).create(this.networkSimplexGraph);for(let n of e)D().delta(1).weight(0).source(t).target(n).create()}}};function kr(e,t){let n=e instanceof P?e.vs:null,r=t instanceof P?t.vs:null;return n===null||r===null?!1:n.representedLEdges.some(e=>r.representedLEdges.includes(e))}function Ar(e){return e instanceof N?e.lNode:null}function jr(e){return e instanceof P?e.vs:null}var Mr=class{lGraph;process(t){let n=t.getProperty(e.v);if(n===`NONE`)return;this.lGraph=t;let r=new Sr,i=new gr(r.transform(t));switch(i.setSpacingsHandler(this.specialSpacingsHandler),t.getProperty(e._)===`SCANLINE`?i.setConstraintAlgorithm(new br(t)):i.setConstraintAlgorithm(gr.QUADRATIC_CONSTRAINTS),n){case`LEFT`:i.compact();break;case`RIGHT`:i.changeDirection(`RIGHT`).compact();break;case`LEFT_RIGHT_CONSTRAINT_LOCKING`:i.compact().changeDirection(`RIGHT`).setLockingStrategy(e=>e.first.cGroup.outDegree===0).applyLockingStrategy().compact();break;case`LEFT_RIGHT_CONNECTION_LOCKING`:i.compact().changeDirection(`RIGHT`).setLockingStrategy(e=>r.getLockMap().get(e.first)?.get(e.second)??!1).applyLockingStrategy().compact();break;case`EDGE_LENGTH`:i.setCompactionAlgorithm(new Or).compact()}i.finish(),r.applyLayout()}specialSpacingsHandler={getHorizontalSpacing:(t,n)=>{if(kr(t,n))return 0;let r=Ar(t),i=Ar(n);if(r!==null&&r.getType()===`EXTERNAL_PORT`||i!==null&&i.getType()===`EXTERNAL_PORT`)return 0;let a=this.lGraph.getProperty(e.wr);return a?a.getHorizontalSpacingByType(r===null?`LONG_EDGE`:r.getType(),i===null?`LONG_EDGE`:i.getType()):0},getVerticalSpacing:(t,n)=>{if(kr(t,n))return 1;let r=Ar(t),i=Ar(n),a=this.lGraph.getProperty(e.wr);return a?a.getVerticalSpacingByType(r===null?`LONG_EDGE`:r.getType(),i===null?`LONG_EDGE`:i.getType()):0}}};const Nr=.4;function Pr(e,t){return e.x===t.x&&e.y===t.y}var Fr=class{createdJunctionPoints=/* @__PURE__ */ new Set;process(t){let n=t.getProperty(e.V),r=t.getProperty(e.un),i=t.getProperty(e.en),a=Math.min(1,i/r),o=0,s=0,c=t.getLayers();if(c.length>0){let e=this.calculateWestInLayerEdgeYDiff(c[0]);o=Nr*a*e}for(let e=0;e<c.length;e++){let t=c[e],i=t.getNodes().length>0&&t.getNodes().every(e=>e.getType()===`EXTERNAL_PORT`),l=e+1<c.length;i&&o>0&&(o-=r),Ir(t,o);let u=0;for(let e of t.getNodes()){let r=0;for(let n of e.getOutgoingEdges()){let e=n.getSource(),i=n.getTarget();if(!e||!i)continue;let s=e.getAbsoluteAnchor().y,c=i.getAbsoluteAnchor().y;i.getNode()?.getLayer()===t&&!n.isSelfLoop()&&(this.processInLayerEdge(n,o,Nr*a*Math.abs(s-c)),e.getSide()===`WEST`&&(s=0,c=0)),r=Math.max(r,Math.abs(c-s))}switch(e.getType()){case`NORMAL`:case`LABEL`:case`LONG_EDGE`:case`NORTH_SOUTH_PORT`:case`BREAKING_POINT`:this.processNode(e,o,n)}u=Math.max(u,r)}if(l){let t=this.calculateWestInLayerEdgeYDiff(c[e+1]);u=Math.max(u,t)}s=Nr*a*u,!i&&l&&(s+=r),o+=t.getSize().x+s}this.createdJunctionPoints.clear(),t.getSize().x=o}processNode(t,n,r){let i=n+t.getLayer().getSize().x;for(let a of t.getPorts()){let o={...a.getAbsoluteAnchor()};if(t.getType()===`NORTH_SOUTH_PORT`){let n=a.getProperty(e.lr);n&&(o.x=n.getAbsoluteAnchor().x,t.getPosition().x=o.x)}let s={x:0,y:o.y};if(a.getSide()===`EAST`)s.x=i;else if(a.getSide()===`WEST`)s.x=n;else continue;if(Math.abs(o.x-s.x)<=r&&!this.isInLayerDummy(t))continue;let c=a.getOutgoingEdges().length+a.getIncomingEdges().length>1;for(let e of a.getConnectedEdges()){let t=e.getSource()===a?e.getTarget():e.getSource();Math.abs(t.getAbsoluteAnchor().y-s.y)>1&&this.addBendPoint(e,s,c,a)}}}processInLayerEdge(e,t,n){let r=e.getSource(),i=e.getTarget(),a=(r.getAbsoluteAnchor().y+i.getAbsoluteAnchor().y)/2,o=r.getSide()===`EAST`?{x:t+r.getNode().getLayer().getSize().x+n,y:a}:{x:t-n,y:a};e.getBendPoints().unshift(o)}addBendPoint(t,n,r,i){if((t.isInLayerEdge()||!Pr(i.getAbsoluteAnchor(),n))&&!t.isSelfLoop()){t.getSource()===i?t.getBendPoints().unshift({...n}):t.getBendPoints().push({...n});let a=`${n.x},${n.y}`;if(r&&!this.createdJunctionPoints.has(a)){let r=t.getProperty(e.nt);r??(r=[],t.setProperty(e.nt,r));let i={...n};r.push(i),this.createdJunctionPoints.add(a)}}}isInLayerDummy(e){if(e.getType()===`LONG_EDGE`){for(let t of e.getConnectedEdges())if(t.isInLayerEdge())return!0}return!1}calculateWestInLayerEdgeYDiff(e){let t=0;for(let n of e.getNodes())for(let r of n.getOutgoingEdges()){let n=r.getSource(),i=r.getTarget();if(n&&i&&i.getNode()?.getLayer()===e&&n.getSide()===`WEST`){let e=n.getAbsoluteAnchor().y,r=i.getAbsoluteAnchor().y;t=Math.max(t,Math.abs(r-e))}}return t}};function Ir(t,n){let r=0,i=0;for(let e of t.getNodes())r=Math.max(r,e.getMargin().left),i=Math.max(i,e.getMargin().right);for(let a of t.getNodes()){let o=a.getProperty(e.p),s;if(o===`LEFT`)s=0;else if(o===`RIGHT`)s=1;else if(o===`CENTER`)s=.5;else{let e=0,t=0;for(let n of a.getPorts())n.getIncomingEdges().length>0&&e++,n.getOutgoingEdges().length>0&&t++;s=e+t===0?.5:t/(e+t)}let c=t.getSize(),l=a.getSize().x,u=(c.x-l)*s;s>.5?u-=i*2*(s-.5):s<.5&&(u+=r*2*(.5-s));let d=a.getMargin().left;u<d&&(u=d);let f=a.getMargin().right;u>c.x-f-l&&(u=c.x-f-l),a.getPosition().x=n+u}}var Lr=class{source;target;weight;constructor(e,t,n){this.source=e,this.target=t,this.weight=n,e.outgoing.push(this),t.incoming.push(this)}};const Rr=.9,zr=.09999999999999998,Br=.5;var Vr=class e{mark=0;inweight=0;outweight=0;rank=0;outgoing=[];incoming=[];leftPorts=[];rightPorts=[];edges=[];boundingBox={x:0,y:0,width:0,height:0};xDelta=0;isWestOfInitialLayer=!1;isStraight=!1;centerControlPointY=0;hyperEdgeTopYPos=0;hyperEdgeBottomYPos=0;handled=!1;sourcePort=null;targetPort=null;initialSegment=!1;lastSegment=!1;sourceNode=null;targetNode=null;inverseOrder=!1;edgeInformation=/* @__PURE__ */ new Map;constructor(){}addEdge(t){this.edges.push(t);let n=t.getSource(),r=t.getTarget();this.edgeInformation.set(t,{startY:e.anchorY(n),endY:e.anchorY(r),normalSourceNode:Hr(n.getNode()),normalTargetNode:Hr(r.getNode()),invertedLeft:n.getSide()===`WEST`,invertedRight:r.getSide()===`EAST`})}isHyperEdge(){return this.edges.length>1}static anchorY(e){return e.getAbsoluteAnchor().y}static fromSingleEdge(t,n,r,i){let a=new e,o=t.getSource(),s=t.getTarget();n===`LEFT`?a.leftPorts.push(o):a.rightPorts.push(o),r===`LEFT`?a.leftPorts.push(s):a.rightPorts.push(s),a.addEdge(t);let c=e.anchorY(o),l=e.anchorY(s);return a.setRelevantPositions(c,l,l),a.isStraight=i(c,l),a}static fromHyperEdge(t,n,r){let i=new e;r===`LEFT`?i.leftPorts.push(t):i.rightPorts.push(t);let a=1/0,o=-1/0;for(let{side:r,edge:s}of n){let n=s.getSource(),c=s.getTarget(),l=n;l===t&&(l=c),r===`LEFT`?i.leftPorts.push(l):i.rightPorts.push(l);let u=e.anchorY(l);a=Math.min(a,u),o=Math.max(o,u)}let s=e.anchorY(t);i.setRelevantPositions(s,a,o);for(let{edge:e}of n)i.addEdge(e);return i.isStraight=!1,i}setRelevantPositions(e,t,n){this.boundingBox.y=Math.min(e,t),this.boundingBox.height=Math.max(e,n)-this.boundingBox.y,e<t?(this.centerControlPointY=Br*(e+t),this.hyperEdgeTopYPos=zr*this.centerControlPointY+Rr*e,this.hyperEdgeBottomYPos=zr*this.centerControlPointY+Rr*t):(this.centerControlPointY=Br*(e+n),this.hyperEdgeTopYPos=zr*this.centerControlPointY+Rr*n,this.hyperEdgeBottomYPos=zr*this.centerControlPointY+Rr*e)}};function Hr(e){let t=e.getType();return t===`NORMAL`||t===`BIG_NODE`||t===`BREAKING_POINT`}const Ur=Math.PI/2,Wr=1e-5;function Gr(e){switch(e){case`NORTH`:return 3*Ur;case`EAST`:return 0;case`SOUTH`:return Ur;case`WEST`:return Math.PI;default:return 0}}function Kr(e,t,n){return Math.abs(e-t)<=n}function qr(e,t,n){return e<t-n?-1:+(e>t+n)}function Jr(e,t){let n=e.x,r=e.x+e.width,i=e.y,a=e.y+e.height;return t.x>n&&t.x<r&&t.y>i&&t.y<a}function Yr(e,t,n){return Jr(e,t)&&Jr(e,n)}function Xr(e,t,n,r){let i=e,a={x:t.x-e.x,y:t.y-e.y},o=n,s={x:r.x-n.x,y:r.y-n.y},c=i.x,l=i.y,u=o.x,d=o.y,f=a.x,p=a.y,m=s.x,h=s.y,g=m*p-f*h;if(Kr(0,g,Wr))return!1;let _=1/g*((c-u)*p-(l-d)*f),v=1/g*-(-(c-u)*h+(l-d)*m);return qr(0,_,Wr)<0&&qr(_,1,Wr)<0&&qr(0,v,Wr)<0&&qr(v,1,Wr)<0}function Zr(e,t,n){if(Yr(e,t,n))return!1;let r={x:e.x,y:e.y},i={x:e.x+e.width,y:e.y},a={x:e.x+e.width,y:e.y+e.height},o={x:e.x,y:e.y+e.height};return Xr(r,i,t,n)||Xr(i,a,t,n)||Xr(a,o,t,n)||Xr(o,r,t,n)}function Qr(e,t){let n=t.length-1,r=0,i=0;for(let a=0;a<=n;a++){let o=t[a],s=$r(n,a)*(1-e)**(n-a)*e**+a;r+=o.x*s,i+=o.y*s}return{x:r,y:i}}function $r(e,t){if(t<0||t>e)return 0;let n=1;for(let r=1;r<=t;r++)n=n*(e-t+r)/r;return n}function ei(e,t){if(e<=0)return[];let n=[],r=1/e,i=0;for(let a=0;a<e;a++)i+=r,n.push(Qr(i,t));return n}const ti=1e-6;var ni=class e{cp;polarCoordinate;constructor(t,n,r){if(t instanceof e&&n instanceof e&&r!==void 0){let e=t.polarCoordinate[0],i=n.polarCoordinate[n.polarCoordinate.length-1],a={x:t.cp.x*(i-r),y:t.cp.y*(i-r)},o={x:n.cp.x*(r-e),y:n.cp.y*(r-e)},s={x:a.x+o.x,y:a.y+o.y},c=1/(i-e);this.cp={x:s.x*c,y:s.y*c},this.polarCoordinate=[];let l=!0;for(let e=1;e<t.polarCoordinate.length;e++){let n=t.polarCoordinate[e];l&&n-r>ti&&(this.polarCoordinate.push(r),l=!1),this.polarCoordinate.push(n)}l&&this.polarCoordinate.push(r)}else this.cp={x:t.x,y:t.y},this.polarCoordinate=[...n]}getCp(){return this.cp}},ri=class{knotVector=[];controlPoints=[];dimNUBS=0;isClamped=!1;isUniform=!1;isBezier=!1;minKnot=0;maxKnot=0;constructor(e,t,n){if(t<1)throw Error(`The dimension must be at least 1!`);for(;n.length<t+1;)n.unshift({...n[0]});this.dimNUBS=t,this.isClamped=e,this.isUniform=!0,this.isBezier=!1,this.createUniformKnotVector(e,n.length+this.dimNUBS-1);let r=[],i=0;for(let e=0;e<this.dimNUBS-1;e++)r.push(this.knotVector[i++]);for(let e of n)r.push(this.knotVector[i++]),this.controlPoints.push(new ni(e,r)),r.shift()}createUniformKnotVector(e,t){if(t<2*this.dimNUBS)throw Error(`The knot vector must have at least two time the dimension elements.`);let n;if(e){this.minKnot=0,this.maxKnot=1;for(let e=0;e<this.dimNUBS;e++)this.knotVector.push(0);n=t+1-2*this.dimNUBS}else{n=t+1;let e=this.dimNUBS;this.minKnot=e/(n+1),this.maxKnot=(n-e)/n}let r=n;for(let e=1;e<n;e++)this.knotVector.push(e/r);if(e)for(let e=0;e<this.dimNUBS;e++)this.knotVector.push(1)}getMultiplicity(e){let t=0;for(let n of this.knotVector)Math.abs(n-e)<ti&&t++;return t}insertKnotAtCurrentPosition(e,t,n,r){let i=this.getMultiplicity(t);for(let a=0;a<e;a++){r.add(t);let o=[],s=n.next();for(let e=i+a;e<this.dimNUBS;e++){let e=s;s=n.next(),o.push(new ni(e,s,t))}for(let e=i+a;e<this.dimNUBS;e++)n.previous(),e>i+a&&n.remove();for(let e of o)n.add(e);if(a<e-1)for(let e=i+a;e<this.dimNUBS;e++)n.previous()}}toBezier(){let e=new ii(this.knotVector),t=new ii(this.controlPoints);if(this.isClamped)for(let t=0;t<this.dimNUBS;t++)e.next();else for(let t=0;t<this.dimNUBS-1;t++)e.next(),e.remove();let n=e.next();for(;this.maxKnot-n>ti;){let r=n,i=0;for(;Math.abs(n-r)<ti;)i++,n=e.next(),t.next();i<this.dimNUBS&&(e.previous(),this.insertKnotAtCurrentPosition(this.dimNUBS-i,r,t,e),e.next()),t.previous()}if(!this.isClamped)for(let t=0;t<this.dimNUBS-1;t++)e.next(),e.remove();this.isClamped=!0,this.isBezier=!0}getControlPoints(){return this.controlPoints.map(e=>({x:e.getCp().x,y:e.getCp().y}))}getBezierCP(){this.isBezier||this.toBezier();let e=[];for(let t=1;t<this.controlPoints.length-1;t++)e.push({x:this.controlPoints[t].getCp().x,y:this.controlPoints[t].getCp().y});return e}},ii=class{items;cursor=0;lastRet=-1;constructor(e){this.items=e}next(){let e=this.items[this.cursor];return this.lastRet=this.cursor,this.cursor++,e}previous(){return this.cursor--,this.lastRet=this.cursor,this.items[this.cursor]}remove(){if(this.lastRet===-1)throw Error(`no last returned`);this.lastRet<this.cursor?(this.items.splice(this.lastRet,1),this.cursor--):this.items.splice(this.lastRet,1),this.lastRet=-1}add(e){this.items.splice(this.cursor,0,e),this.cursor++,this.lastRet=-1}};const ai=1.3,F=.5;function oi(e,t){return{x:e.x+t.x,y:e.y+t.y}}function si(e,t){return{x:e.x-t.x,y:e.y-t.y}}function ci(e,t){return{x:e.x*t,y:e.y*t}}function li(e){return Math.hypot(e.x,e.y)}function ui(e){return{x:Math.cos(e),y:Math.sin(e)}}function I(e){let t=e.getPosition(),n=e.getAnchor();return{x:t.x+n.x,y:t.y+n.y}}var di=class e extends ri{firstLabelPosition={x:0,y:0};constructor(e,t,n){typeof e==`boolean`?super(e,t,n):super(!0,e,t)}getFirstLabelPosition(){return this.firstLabelPosition}setFirstLabelPosition(e){this.firstLabelPosition=e}static createSideSelfLoop(t,n,r){let i=Gr(t.getSide()),a=I(t),o=I(n),s=oi(a,ci(ui(i),r)),c=oi(o,ci(ui(i),r)),l=ci(si(s,c),1/2),u=oi(oi(c,l),ci(ui(i),li(l)));return new e(3,[a,s,u,c,o])}static createCornerSelfLoop(t,n,r,i){let a=Gr(t.getSide()),o=Gr(n.getSide()),s=I(t),c=I(n),l=oi(s,ci(ui(a),ai*r)),u=oi(c,ci(ui(o),ai*i)),d=0,f=0;switch(t.getSide()){case`WEST`:d=2*(s.x-r)-F*(l.x+u.x);break;case`EAST`:d=2*(s.x+r)-F*(l.x+u.x);break;case`NORTH`:f=2*(s.y-r)-F*(l.y+u.y);break;case`SOUTH`:f=2*(s.y+r)-F*(l.y+u.y)}switch(n.getSide()){case`WEST`:d=2*(c.x-i)-F*(u.x+l.x);break;case`EAST`:d=2*(c.x+i)-F*(u.x+l.x);break;case`NORTH`:f=2*(c.y-i)-F*(u.y+l.y);break;case`SOUTH`:f=2*(c.y+i)-F*(u.y+l.y)}return new e(3,[s,l,{x:d,y:f},u,c])}static createAcrossSelfLoop(t,n,r,i,a){let o=I(t),s=I(n);if(i.length!==2)throw Error(`AssertionError: cornerBendPoints.size() == 2`);let c=i[0],l=i[1],u=ci(oi(l,c),F);return new e(3,[o,r,c,u,l,a,s])}static createThreeSideSelfLoop(t,n,r,i,a){let o=I(t),s=I(n);if(i.length!==3)throw Error(`AssertionError: cornerBendPoints.size() == 3`);let c=i[0],l=i[1],u=i[2];return new e(3,[o,r,c,l,u,a,s])}static createFourSideSelfLoop(t,n,r,i,a){let o=I(t),s=I(n);if(i.length!==4)throw Error(`AssertionError: cornerBendPoints.size() == 4`);let c=i[0],l=i[1],u=i[2],d=i[3];return new e(3,[o,r,c,l,u,d,a,s])}};const fi=1e-8;function pi(e,t,n){return Math.abs(t-e)<fi||Math.abs(n-e)<fi?!0:t-e>fi?e-n>fi:n-e>fi}function mi(e,t){return e!==t&&(e===`WEST`||e===`EAST`)!=(t===`WEST`||t===`EAST`)}function hi(t){return t.getType()===`EXTERNAL_PORT`&&(t.getProperty(e.Un)===`WEST`||t.getProperty(e.Un)===`EAST`)}var gi=class{edgesRemainingLayer=[];splineSegmentsLayer=[];leftPortsLayer=[];rightPortsLayer=[];selfLoopsLayer=/* @__PURE__ */ new Set;startEdges=[];allSplineSegments=[];edgeToSegmentMap=/* @__PURE__ */ new Map;successingEdge=/* @__PURE__ */ new Map;process(t){if(t.getLayers().length===0){t.getSize().x=0;return}let n=t.getProperty(e.un),r=t.getProperty(e.rn),i=t.getProperty(e.en),a=t.getProperty(e.H)===`SLOPPY`,o=t.getProperty(e.U);this.startEdges=[],this.allSplineSegments=[],this.successingEdge=/* @__PURE__ */ new Map;let s=t.getLayers(),c=s[0],l=s[s.length-1],u=c.getNodes().length>0&&c.getNodes().every(e=>hi(e)),d=l.getNodes().length>0&&l.getNodes().every(e=>hi(e)),f=0,p=null;for(let e=0;e<=s.length;e++){let m=e<s.length?s[e]:null;this.clearThenFillMappings(p,m),this.createSegmentsAndComputeRanking(t);let h=0;for(let e of this.splineSegmentsLayer)e.isStraight||(h=Math.max(h,e.rank+1));let g=0,_=f,v=p===null||u&&p===c,y=m===null||d&&m===l;if(h>0){let e=0;p!==null&&(e+=r),e+=(h-1)*i,m!==null&&(e+=r),a&&m!==null&&(e=Math.max(e,this.computeSloppySpacing(m,i,n,o))),e<n&&!v&&!y&&(g=(n-e)/2,e=n),_+=e}else!v&&!y&&(_+=n);m!==null&&Sn(m,_),this.routeSelfLoops(r);for(let e of this.splineSegmentsLayer)e.boundingBox.x=f,e.boundingBox.width=_-f,e.xDelta=g,e.isWestOfInitialLayer=p===null;this.allSplineSegments.push(...this.splineSegmentsLayer),f=_,m!==null&&(f+=m.getSize().x),p=m}t.getSize().x=f;for(let t of this.startEdges){let n=this.getEdgeChain(t);n.length>0&&t.setProperty(e.Tr,n);let r=this.getSplinePath(t);r.length>0&&t.setProperty(e.Dr,r)}}getEdgeChain(e){let t=[],n=e;for(;n!==null;)t.push(n),n=this.successingEdge.get(n)??null;return t}getSplinePath(e){let t=[],n=e;for(;n!==null;){let e=this.edgeToSegmentMap.get(n);if(!e)break;e.sourcePort=n.getSource(),e.targetPort=n.getTarget(),t.push(e),n=this.successingEdge.get(n)??null}if(t.length>0){let e=t[0];e.initialSegment=!0,e.sourceNode=e.edges[0].getSource().getNode();let n=t[t.length-1];n.lastSegment=!0,n.targetNode=n.edges[0].getTarget().getNode()}return t}clearThenFillMappings(e,t){if(this.leftPortsLayer=[],this.rightPortsLayer=[],this.edgesRemainingLayer=[],this.splineSegmentsLayer=[],this.selfLoopsLayer=/* @__PURE__ */ new Set,e!==null)for(let n of e.getNodes())for(let r of n.getPorts(`EAST`)){this.leftPortsLayer.push(r);for(let n of r.getOutgoingEdges()){if(n.isSelfLoop())continue;this.edgesRemainingLayer.push(n),this.findAndAddSuccessor(n),yi(n.getSource().getNode())&&this.startEdges.push(n);let r=n.getTarget(),i=r.getNode().getLayer();if(i===t)this.rightPortsLayer.push(r);else if(i===e)this.leftPortsLayer.push(r);else{let e=this.edgesRemainingLayer.indexOf(n);e!==-1&&this.edgesRemainingLayer.splice(e,1)}}}if(t!==null)for(let n of t.getNodes()){for(let e of n.getPorts())for(let t of e.getOutgoingEdges())t.isSelfLoop()&&this.selfLoopsLayer.add(t);for(let r of n.getPorts(`WEST`)){this.rightPortsLayer.push(r);for(let n of r.getOutgoingEdges()){if(n.isSelfLoop())continue;this.edgesRemainingLayer.push(n),this.findAndAddSuccessor(n),yi(n.getSource().getNode())&&this.startEdges.push(n);let r=n.getTarget(),i=r.getNode().getLayer();if(i===t)this.rightPortsLayer.push(r);else if(i===e)this.leftPortsLayer.push(r);else{let e=this.edgesRemainingLayer.indexOf(n);e!==-1&&this.edgesRemainingLayer.splice(e,1)}}}}}routeSelfLoops(e){if(this.selfLoopsLayer.size===0)return;let t=e>0?e:20;for(let e of this.selfLoopsLayer){let n=e.getSource(),r=e.getTarget();if(n===null||r===null||e.getBendPoints().length>0)continue;let i=n.getSide(),a=r.getSide();if(i===`UNDEFINED`||a===`UNDEFINED`)continue;let o=null;if(i===a?o=di.createSideSelfLoop(n,r,t):mi(i,a)&&(o=di.createCornerSelfLoop(n,r,t,t)),o===null)continue;let s=n.getNode(),c=s===null?{x:0,y:0}:s.getPosition();for(let t of o.getBezierCP())e.getBendPoints().push({x:t.x+c.x,y:t.y+c.y})}}createSegmentsAndComputeRanking(t){this.createSplineSegmentsForHyperEdges(`LEFT`,!0),this.createSplineSegmentsForHyperEdges(`LEFT`,!1),this.createSplineSegmentsForHyperEdges(`RIGHT`,!0),this.createSplineSegmentsForHyperEdges(`RIGHT`,!1),this.createSplineSegments();for(let e=0;e<this.splineSegmentsLayer.length;e++){let t=this.splineSegmentsLayer[e];for(let n=e+1;n<this.splineSegmentsLayer.length;n++)this.createDependency(t,this.splineSegmentsLayer[n])}this.breakCycles(this.splineSegmentsLayer,t.getProperty(e.br)),this.topologicalNumbering(this.splineSegmentsLayer)}createSplineSegments(){for(let e of this.edgesRemainingLayer){let t=e.getSource(),n;if(this.leftPortsLayer.includes(t))n=`LEFT`;else if(this.rightPortsLayer.includes(t))n=`RIGHT`;else throw Error(`Source port must be in one of the port sets.`);let r=e.getTarget(),i;if(this.leftPortsLayer.includes(r))i=`LEFT`;else if(this.rightPortsLayer.includes(r))i=`RIGHT`;else throw Error(`Target port must be in one of the port sets.`);let a=Vr.fromSingleEdge(e,n,i,(e,t)=>_i(e,t));this.edgeToSegmentMap.set(e,a),this.splineSegmentsLayer.push(a)}}createSplineSegmentsForHyperEdges(t,n){let r=t===`LEFT`?this.leftPortsLayer:this.rightPortsLayer;for(let i of r){let r=i.getAbsoluteAnchor().y,a=[],o=[];for(let t of i.getConnectedEdges())if(t.getProperty(e.Sr)===n&&this.edgesRemainingLayer.includes(t)){let e;e=t.getTarget()===i?t.getSource():t.getTarget();let n=e.getAbsoluteAnchor().y;if(_i(n,r))continue;n<r?a.push({side:this.leftPortsLayer.includes(e)?`LEFT`:`RIGHT`,edge:t}):o.push({side:this.leftPortsLayer.includes(e)?`LEFT`:`RIGHT`,edge:t})}if(a.length>1){let e=Vr.fromHyperEdge(i,a,t);for(let{edge:t}of a)this.edgeToSegmentMap.set(t,e);this.splineSegmentsLayer.push(e);for(let{edge:e}of a){let t=this.edgesRemainingLayer.indexOf(e);t!==-1&&this.edgesRemainingLayer.splice(t,1)}}if(o.length>1){let e=Vr.fromHyperEdge(i,o,t);for(let{edge:t}of o)this.edgeToSegmentMap.set(t,e);this.splineSegmentsLayer.push(e);for(let{edge:e}of o){let t=this.edgesRemainingLayer.indexOf(e);t!==-1&&this.edgesRemainingLayer.splice(t,1)}}}}createDependency(e,t){if(e.hyperEdgeTopYPos>t.hyperEdgeBottomYPos||t.hyperEdgeTopYPos>e.hyperEdgeBottomYPos)return;let n=0,r=0;for(let r of e.rightPorts)pi(r.getAbsoluteAnchor().y,t.hyperEdgeTopYPos,t.hyperEdgeBottomYPos)&&n++;for(let r of e.leftPorts)pi(r.getAbsoluteAnchor().y,t.hyperEdgeTopYPos,t.hyperEdgeBottomYPos)&&n--;for(let n of t.rightPorts)pi(n.getAbsoluteAnchor().y,e.hyperEdgeTopYPos,e.hyperEdgeBottomYPos)&&r++;for(let n of t.leftPorts)pi(n.getAbsoluteAnchor().y,e.hyperEdgeTopYPos,e.hyperEdgeBottomYPos)&&r--;n<r?new Lr(e,t,r-n):r<n?new Lr(t,e,n-r):(new Lr(t,e,0),new Lr(e,t,0))}breakCycles(e,t){let n=[],r=[],i=-1;for(let t of e){t.mark=i--;let e=0,a=0;for(let e of t.outgoing)a+=e.weight;for(let n of t.incoming)e+=n.weight;t.inweight=e,t.outweight=a,a===0?r.push(t):e===0&&n.push(t)}let a=new Set(e),o=e.length,s=o+1,c=o-1,l=[];for(;a.size>0;){for(;r.length>0;){let e=r.shift();a.delete(e),e.mark=c--,this.updateNeighbors(e,n,r)}for(;n.length>0;){let e=n.shift();a.delete(e),e.mark=s++,this.updateNeighbors(e,n,r)}let e=-(2**53-1);for(let t of a){let n=t.outweight-t.inweight;n>=e&&(n>e&&(l.length=0,e=n),l.push(t))}if(l.length>0){let e=t===void 0?l[0]:l[t.nextInt(l.length)];a.delete(e),e.mark=s++,this.updateNeighbors(e,n,r),l.length=0}}let u=e.length+1;for(let t of e)t.mark<o&&(t.mark+=u);for(let t of e){let e=t.outgoing;for(let n=e.length-1;n>=0;n--){let r=e[n],i=r.target;if(t.mark>i.mark){e.splice(n,1);let a=i.incoming.indexOf(r);a!==-1&&i.incoming.splice(a,1),r.weight>0&&(r.source=i,i.outgoing.push(r),r.target=t,t.incoming.push(r))}}}}updateNeighbors(e,t,n){for(let n of e.outgoing)n.target.mark<0&&n.weight>0&&(n.target.inweight-=n.weight,n.target.inweight<=0&&n.target.outweight>0&&t.push(n.target));for(let t of e.incoming)t.source.mark<0&&t.weight>0&&(t.source.outweight-=t.weight,t.source.outweight<=0&&t.source.inweight>0&&n.push(t.source))}topologicalNumbering(e){let t=[],n=[];for(let r of e)r.rank=0,r.inweight=r.incoming.length,r.outweight=r.outgoing.length,r.inweight===0&&t.push(r),r.outweight===0&&r.leftPorts.length===0&&n.push(r);let r=-1;for(;t.length>0;){let e=t.shift();for(let n of e.outgoing){let i=n.target;i.rank=Math.max(i.rank,e.rank+1),r=Math.max(r,i.rank),i.inweight--,i.inweight===0&&t.push(i)}}if(r>-1){for(let e of n)e.rank=r;for(;n.length>0;){let e=n.shift();for(let t of e.incoming){let r=t.source;r.leftPorts.length>0||(r.rank=Math.min(r.rank,e.rank-1),r.outweight--,r.outweight===0&&n.push(r))}}}}computeSloppySpacing(e,t,n,r){let i=0;for(let t of e.getNodes()){let e=0;for(let n of t.getIncomingEdges()){let t=n.getSource().getAbsoluteAnchor().y,r=n.getTarget().getAbsoluteAnchor().y;e=Math.max(e,Math.abs(r-t))}i=Math.max(i,e)}return r*Math.min(1,t/n)*i}findAndAddSuccessor(e){let t=e.getTarget().getNode();if(vi(t))return;let n=t.getOutgoingEdges();n.length>0&&this.successingEdge.set(e,n[0])}};function _i(e,t){return Math.abs(e-t)<.2}function vi(e){let t=e.getType();return t===`NORMAL`||t===`BREAKING_POINT`}function yi(e){let t=e.getType();return t===`NORMAL`||t===`NORTH_SOUTH_PORT`||t===`EXTERNAL_PORT`||t===`BREAKING_POINT`}function bi(t){let n=t.getProperty(e.en),r=t.getProperty(e.rn),i=t.getProperty(e.H),a=t.getProperty(e.v);for(let e of t.getLayers()){let t=0;for(let n of e.getNodes())n.id=t++}let o=[];for(let n of t.getLayers())for(let t of n.getNodes())for(let n of t.getPorts())for(let t of n.getOutgoingEdges())t.isSelfLoop()||t.hasProperty(e.Dr)&&o.push(t);for(let t of o){let o=t.getProperty(e.Dr);if(o!=null){for(let e of o)xi(e,n,r,i,a);t.setProperty(e.Dr,null)}}for(let t of o)Oi(t.getProperty(e.Tr)??[],t,i),t.setProperty(e.Tr,null)}function xi(e,t,n,r,i){if(!e.handled){e.handled=!0;for(let a of e.edges){if(e.isStraight&&!e.isHyperEdge()){Si(e);continue}let o=e.edgeInformation.get(a);o.invertedLeft||o.invertedRight?Ci(a,e,n,t):r===`SLOPPY`&&(o.normalSourceNode||o.normalTargetNode)&&ji(e,i)&&!e.isHyperEdge()?Ti(a,e):wi(a,e,n,t)}if(e.inverseOrder)for(let t of e.edges)t.getBendPoints().reverse()}}function Si(e){let t=e.boundingBox.x,n={x:t+(e.boundingBox.x+e.boundingBox.width-t)/2,y:e.centerControlPointY};e.edges[0].getBendPoints().push(n)}function Ci(e,t,n,r){let i=t.boundingBox.x,a=t.boundingBox.x+t.boundingBox.width,o=t.edgeInformation.get(e),s=o.startY,c=o.endY,l=o.invertedLeft?{x:a,y:s}:{x:i,y:s},u=o.invertedRight?{x:i,y:c}:{x:a,y:c},d=i;t.isWestOfInitialLayer||(d+=n),d+=t.xDelta+t.rank*r;let f={x:d,y:s},p={x:d,y:c};e.getBendPoints().push(l,f),t.edges.length>1&&e.getBendPoints().push({x:d,y:t.centerControlPointY}),e.getBendPoints().push(p,u)}function wi(e,t,n,r){let i=t.boundingBox.x,a=t.boundingBox.x+t.boundingBox.width,o=t.edgeInformation.get(e),s=o.startY,c=o.endY,l={x:i,y:s},u={x:a,y:c},d=i;t.isWestOfInitialLayer||(d+=n),d+=t.xDelta+t.rank*r;let f={x:d,y:s},p={x:d,y:c};e.getBendPoints().push(l,f),t.edges.length>1&&e.getBendPoints().push({x:d,y:t.centerControlPointY}),e.getBendPoints().push(p,u)}function Ti(e,t){let n=t.edgeInformation.get(e),r=t.boundingBox.x,i=t.boundingBox.x+t.boundingBox.width,a=n.startY,o=n.endY,s=a<o,c={x:r,y:a},l={x:i,y:o},u=(r+i)/2,d={x:u,y:a},f={x:u,y:o},p=Di(e,a,o),m=t.sourcePort.getAbsoluteAnchor(),h={x:u,y:p},g=t.targetPort.getAbsoluteAnchor(),_=ei(2,[m,h,g]),v=!1,y=t.sourcePort.getNode();if(y!==null&&y.getLayer()!==null&&n.normalSourceNode){let e=y.getLayer();if(!(s&&y.id<e.getNodes().length-1||!s&&y.id>0))v=!0;else{let t=s?y.id+1:y.id-1,n=e.getNodes()[t],r=Ei(n);v=!(Zr(r,m,_[0])||Yr(r,m,_[0]))}}let b=!1,x=t.targetPort.getNode();if(x!==null&&x.getLayer()!==null&&n.normalTargetNode){let e=x.getLayer();if(!(s&&x.id>0||!s&&x.id<e.getNodes().length-1))b=!0;else{let t=s?x.id-1:x.id+1,n=e.getNodes()[t],r=Ei(n);b=!(Zr(r,_[0],g)||Yr(r,_[0],g))}}v&&b&&e.getBendPoints().push(h),v||e.getBendPoints().push(c,d),b||e.getBendPoints().push(f,l)}function Ei(e){let t=e.getPosition(),n=e.getSize(),r=e.getMargin();return{x:t.x-r.left,y:t.y-r.top,width:n.x+r.left+r.right,height:n.y+r.top+r.bottom}}function Di(e,t,n){let r=0,i=0;if(e.getTarget()!==null)for(let t of e.getTarget().getNode().getPorts())r+=t.getIncomingEdges().length;else r=1;if(e.getSource()!==null)for(let t of e.getSource().getNode().getPorts())i+=t.getOutgoingEdges().length;else i=1;let a=Math.sign(i-r);return(n+t)/2+(n-t)*(.4*a)}function Oi(t,n,r){if(t.length===0)return;let i=n===null?t[0]:n,a=i.getSource();if(!yi(a.getNode()))throw Error(`The target node of the edge must be a normal node or a northSouthPort.`);let o=[a.getAbsoluteAnchor()];if(Ni(a.getSide())){let t=a.getProperty(e.Er);o.push({x:a.getAbsoluteAnchor().x,y:t??a.getAbsoluteAnchor().y})}let s=null,c=!1;for(let e of t){let t=e.getBendPoints();if(t.length>0){if(c){let e={x:(s.x+t[0].x)/2,y:(s.y+t[0].y)/2};o.push(e),c=!1}else c=!0;s={...t[t.length-1]},o.push(...t.map(e=>({x:e.x,y:e.y}))),t.length=0}}let l=i.getTarget();if(Ni(l.getSide())){let t=l.getProperty(e.Er);o.push({x:l.getAbsoluteAnchor().x,y:t??l.getAbsoluteAnchor().y})}o.push(l.getAbsoluteAnchor()),r===`CONSERVATIVE`&&ki(o,a,l);let u=new ri(!0,3,o).getBezierCP();i.getBendPoints().push(...u)}function ki(e,t,n){let r=e[0],i=e[1],a=Gr(t.getSide()),o={x:Math.cos(a)*5,y:Math.sin(a)*5},s={x:i.x-r.x,y:i.y-r.y},c={x:Ai(o.x,s.x),y:Ai(o.y,s.y)};c.x+=r.x,c.y+=r.y,e.splice(1,0,c);let l=e[e.length-1],u=e[e.length-2],d=Gr(n.getSide()),f={x:Math.cos(d)*5,y:Math.sin(d)*5},p={x:u.x-l.x,y:u.y-l.y},m={x:Ai(f.x,p.x),y:Ai(f.y,p.y)};m.x+=l.x,m.y+=l.y,e.splice(e.length-1,0,m)}function Ai(e,t){return Math.abs(e)<Math.abs(t)?e:t}function ji(e,t){if(t===`NONE`)return!0;let n=e.boundingBox.x,r=e.boundingBox.x+e.boundingBox.width;if(e.initialSegment&&e.sourceNode!==null){let t=e.sourceNode,r=Mi(t);if(n-(t.getPosition().x+t.getSize().x)>r)return!1}if(e.lastSegment&&e.targetNode!==null){let t=e.targetNode,n=Mi(t);if(t.getPosition().x-r>n)return!1}return!0}function Mi(e){return e.getLayer().getSize().x-e.getSize().x/2}function Ni(e){return e===`NORTH`||e===`SOUTH`}function Pi(e,t=!1){let n;switch(e){case`RIGHT`:n=`EAST`;break;case`LEFT`:n=`WEST`;break;case`DOWN`:n=`SOUTH`;break;case`UP`:n=`NORTH`;break;default:n=`EAST`}return t?Fi(n):n}function Fi(e){switch(e){case`NORTH`:return`SOUTH`;case`SOUTH`:return`NORTH`;case`EAST`:return`WEST`;case`WEST`:return`EAST`;default:return`UNDEFINED`}}function Ii(t){let n=t.getProperty(e.F);return n===`UNDEFINED`?t.getProperty(e.h)>=1?`RIGHT`:`DOWN`:n}function Li(e,t){let n=e.getGraph()?.getParentNode()??null;for(;n!==null;){if(n===t)return!0;n=n.getGraph()?.getParentNode()??null}return!1}function Ri(e,t){let n=e.getPosition().x+e.getAnchor().x,r=e.getPosition().y+e.getAnchor().y,i=e.getNode();for(;i!==null&&i!==t;)n+=i.position.x,r+=i.position.y,i=i.getGraph()?.getParentNode()??null;return{x:n,y:r}}function zi(e,t){let n=/* @__PURE__ */ new Set,r=e;for(;r!==null;)n.add(r),r=r.getGraph()?.getParentNode()??null;for(r=t;r!==null;){if(n.has(r))return r;r=r.getGraph()?.getParentNode()??null}return null}function Bi(t){let n=t.getSource(),r=t.getTarget(),i=n.getNode(),a=r.getNode(),o,s;if(i===a&&t.getProperty(e.$)){let t=i,a=t.getGraph(),c=!1;for(;a!==null;){if(a.getProperty(e.q)===`INCLUDE_CHILDREN`){c=!0;break}a=a.getParentNode()?.getGraph()??null}if(c)o=n.getAbsoluteAnchor(),s=r.getAbsoluteAnchor();else{let e=(e,n)=>{switch(e){case`WEST`:return{x:t.position.x+n.getPosition().x+n.getSize().x,y:t.position.y+n.getPosition().y+n.getSize().y/2};case`EAST`:return{x:t.position.x+n.getPosition().x,y:t.position.y+n.getPosition().y+n.getSize().y/2};case`NORTH`:return{x:t.position.x+n.getPosition().x+n.getSize().x/2,y:t.position.y+n.getPosition().y+n.getSize().y};case`SOUTH`:return{x:t.position.x+n.getPosition().x+n.getSize().x/2,y:t.position.y+n.getPosition().y};default:return n.getAbsoluteAnchor()}};o=e(n.getSide(),n),s=e(r.getSide(),r)}}else if(Li(a,i)){o={x:n.getPosition().x+n.getAnchor().x,y:n.getPosition().y+n.getAnchor().y};let i=r.getAbsoluteAnchor(),a=t.getProperty(e.Ar);s=a?{x:i.x+a.x,y:i.y+a.y}:i}else if(Li(i,a))o=Ri(n,a),s=Ri(r,a);else if(i===a){o=n.getAbsoluteAnchor();let i=r.getAbsoluteAnchor(),a=t.getProperty(e.Ar);s=a?{x:i.x+a.x,y:i.y+a.y}:i}else{let e=zi(i,a);o=Ri(n,e),s=Ri(r,e)}return{source:o,target:s}}function Vi(e,t,n){if(t===n)return e;let r=t,i=null;do{let t=r.getOffset();if(e.x+=t.x,e.y+=t.y,i=r.getParentNode(),i!==null){let t=r.getPadding();e.x+=t.left,e.y+=t.top,e.x+=i.getPosition().x,e.y+=i.getPosition().y,r=i.getGraph()}}while(i!==null);r=n;do{let t=r.getOffset();if(e.x-=t.x,e.y-=t.y,i=r.getParentNode(),i!==null){let t=r.getPadding();e.x-=t.left,e.y-=t.top,e.x-=i.getPosition().x,e.y-=i.getPosition().y,r=i.getGraph()}}while(i!==null);return e}function Hi(e,t){return Vi({x:0,y:0},e,t)}function Ui(t,n,r,i,a,o,s,c,l){let u=r,d=new f(l);d.setType(`EXTERNAL_PORT`),d.setProperty(e.Un,u),d.setProperty(e.Wn,s),d.setProperty(e.Lt,`FIXED_POS`);let m=t.getProperty(e.It);d.setProperty(e.It,m);let h=new p;if(h.setNode(d),e.Lr.isSideFixed(n)||(u=i>=0?Pi(c):Fi(Pi(c)),t.setProperty(e.Bt,u),t instanceof p&&t.setSide(u)),e.Lr.isRatioFixed(n)||e.Lr.isPosFixed(n)){let t=0;switch(u){case`WEST`:case`EAST`:t=o?.y??0,e.Lr.isRatioFixed(n)&&(t/=a?.y??1);break;case`NORTH`:case`SOUTH`:t=o?.x??0,e.Lr.isRatioFixed(n)&&(t/=a?.x??1)}d.setProperty(e.yr,t)}let g={x:s.x/2,y:s.y/2},_=!1;if(t.getProperty(e.Ft)!==void 0){let n=t.getProperty(e.Ft);n!=null&&(g.x=n.x,g.y=n.y,_=!0)}switch(u){case`WEST`:d.setLayerConstraint(`FIRST_SEPARATE`),d.setEdgeConstraint(`OUTGOING_ONLY`),d.size.y=s.y,m<0&&(d.size.x=-m),h.setSide(`EAST`),_||(g.x=s.x),g.x-=s.x;break;case`EAST`:d.setLayerConstraint(`LAST_SEPARATE`),d.setEdgeConstraint(`INCOMING_ONLY`),d.size.y=s.y,m<0&&(d.size.x=-m),h.setSide(`WEST`),_||(g.x=0);break;case`NORTH`:d.setInLayerConstraint(`TOP`),d.size.x=s.x,m<0&&(d.size.y=-m),h.setSide(`SOUTH`),_||(g.y=s.y),g.y-=s.y;break;case`SOUTH`:d.setInLayerConstraint(`BOTTOM`),d.size.x=s.x,m<0&&(d.size.y=-m),h.setSide(`NORTH`),_||(g.y=0)}return h.getPosition().x=g.x,h.getPosition().y=g.y,d.setProperty(e.Ft,{x:g.x,y:g.y}),o!=null&&(d.getPosition().x=o.x,d.getPosition().y=o.y),d.setProperty(e.Un,u),d}function Wi(e,t){let n=e.getNode(),r=n.size.x,i=n.size.y;if(r<=0&&i<=0)return`UNDEFINED`;let a=e.getPosition().x,o=e.getPosition().y,s=e.size.x,c=e.size.y;switch(t){case`LEFT`:case`RIGHT`:if(a<0)return`WEST`;if(a+s>r)return`EAST`;break;case`UP`:case`DOWN`:if(o<0)return`NORTH`;if(o+c>i)return`SOUTH`}let l=(a+s/2)/r,u=(o+c/2)/i;return l+u<=1&&l-u<=0?`WEST`:l+u>=1&&l-u>=0?`EAST`:u<.5?`NORTH`:`SOUTH`}function Gi(e,t){let n=e.getNode(),r=e.getPosition();switch(t){case`NORTH`:return-(r.y+e.size.y);case`EAST`:return r.x-(n?.size.x??0);case`SOUTH`:return r.y-(n?.size.y??0);case`WEST`:return-(r.x+e.size.x)}return 0}function Ki(t,n,r){let i=t.getSide(),a=e.Lr.isSideFixed(n);i===`UNDEFINED`&&a&&(i=Wi(t,r),t.setSideInferred(i),!t.hasProperty(e.It)&&i!==`UNDEFINED`&&(t.getPosition().x!==0||t.getPosition().y!==0)&&t.setProperty(e.It,Gi(t,i)));let o=t.size,s=t.getAnchor();if(i!==`UNDEFINED`)switch(i){case`NORTH`:s.x=o.x/2;break;case`EAST`:s.x=o.x,s.y=o.y/2;break;case`SOUTH`:s.x=o.x/2,s.y=o.y;break;case`WEST`:s.y=o.y/2}else s.x=o.x/2,s.y=o.y/2}function qi(t){let n=t.getProperty(e.G);for(let e of t.getLayerlessNodes())Ji(e,n);for(let e of t.getLayers())for(let t of e.getNodes())Ji(t,n)}function Ji(t,n){if(e.Lr.isSideFixed(t.getProperty(e.Lt)))for(let e of t.getPorts())e.getSide()===`UNDEFINED`&&Yi(e,n);else{for(let e of t.getPorts())Yi(e,n);t.setProperty(e.Lt,`FIXED_SIDE`)}}function Yi(t,n=!1,r=`RIGHT`){let i=t.getProperty(e._r);if(i!=null){t.setSideInferred(i.getProperty(e.Un));return}let a=0;if(n){for(let n of t.getIncomingEdges())a+=n.getProperty(e.Sr)?-1:1;for(let n of t.getOutgoingEdges())a-=n.getProperty(e.Sr)?-1:1}else a=t.getNetFlow();let o=Pi(r),s=a<0?o:Fi(o);t.setSideInferred(s)}const Xi={top:0,left:0,right:0,bottom:0};function Zi(t,n){let r=t.placement??n.getProperty(e._t);return Array.isArray(r)?r:String(r??``).split(/[\s,]+/).filter(Boolean)}function Qi(e){let t=e.includes(`H_LEFT`)||e.includes(`H_RIGHT`);return e.includes(`H_PRIORITY`)&&t||!e.includes(`H_PRIORITY`)&&e.includes(`V_CENTER`)&&t}function $i(e,t,n,r){let i=n.includes(`H_RIGHT`)?`right`:n.includes(`H_LEFT`)?`left`:`center`,a=n.includes(`V_BOTTOM`)?`bottom`:n.includes(`V_CENTER`)?`center`:`top`;Qi(n)?(e.position.x=i===`right`?t.x+r:-e.size.x-r,e.position.y=a===`bottom`?t.y-e.size.y:a===`center`?(t.y-e.size.y)/2:0):(e.position.y=a===`bottom`?t.y+r:-e.size.y-r,e.position.x=i===`right`?t.x-e.size.x:i===`center`?(t.x-e.size.x)/2:0)}function ea(e,t,n){if(Qi(t)){let r={...Xi};return t.includes(`H_LEFT`)&&(r.left=n+e.x),t.includes(`H_RIGHT`)&&(r.right=n+e.x),r}let r={...Xi};return t.includes(`V_TOP`)&&(r.top=n+e.y),t.includes(`V_BOTTOM`)&&(r.bottom=n+e.y),r}function ta(t){return t.hasProperty(e.on)?t.getProperty(e.on):t.getGraph()?.getProperty(e.on)??5}function na(e){let t=e.getLayers();for(let e of t)for(let t of e.getNodes())ra(t)}function ra(e){let t=e.getSize(),n=0,r=0,i=t.x,a=t.y;for(let t of e.getPorts()){let e=t.getPosition(),o=t.getSize();n=Math.min(n,e.x),r=Math.min(r,e.y),i=Math.max(i,e.x+o.x),a=Math.max(a,e.y+o.y);for(let o of t.getLabels()){let t=o.position,s=o.size;n=Math.min(n,e.x+t.x),r=Math.min(r,e.y+t.y),i=Math.max(i,e.x+t.x+s.x),a=Math.max(a,e.y+t.y+s.y)}}for(let o of e.getLabels()){let s=o.position,c=o.size;n=Math.min(n,s.x),r=Math.min(r,s.y),i=Math.max(i,s.x+c.x),a=Math.max(a,s.y+c.y);let l=Zi(o,e);if(l.includes(`OUTSIDE`)){let o=ea(c,l,ta(e));n=Math.min(n,-o.left),r=Math.min(r,-o.top),i=Math.max(i,t.x+o.right),a=Math.max(a,t.y+o.bottom)}}let o=e.getMargin();o.left=-n,o.top=-r,o.right=i-t.x,o.bottom=a-t.y}var ia=class{newEdge;graph;type;constructor(e,t,n){this.newEdge=e,this.graph=t,this.type=n}getNewEdge(){return this.newEdge}getGraph(){return this.graph}getType(){return this.type}getActualSource(){let t=this.newEdge.getSource();return t!==null&&t.getNode().getType().toString()===`EXTERNAL_PORT`?t.getNode().getProperty(e.lr):t}getActualTarget(){let t=this.newEdge.getTarget();return t!==null&&t.getNode().getType().toString()===`EXTERNAL_PORT`?t.getNode().getProperty(e.lr):t}};function aa(e,t){let n=0,r=e;for(;r!==t;){let e=r.getParentNode();if(e===null)break;let t=e.getGraph();if(t===null)break;r=t,n++}return n}function oa(e,t,n){let r=e.getType(),i=t.getType();return r===`OUTPUT`&&i===`INPUT`?-1:r===`INPUT`&&i===`OUTPUT`?1:r===`OUTPUT`?aa(t.getGraph(),n)-aa(e.getGraph(),n):aa(e.getGraph(),n)-aa(t.getGraph(),n)}var sa=class{origEdges=[];newEdge;dummyNode;dummyPort;type;exported;constructor(e,t,n,r,i,a){this.origEdges.push(e),this.newEdge=t,this.dummyNode=n,this.dummyPort=r,this.type=i,this.exported=a}},ca=class{crossHierarchyMap=/* @__PURE__ */ new Map;dummyNodeMap=/* @__PURE__ */ new Map;topGraph=null;process(t){this.crossHierarchyMap=/* @__PURE__ */ new Map,this.topGraph=t,t.getProperty(e.q)===`INCLUDE_CHILDREN`?(this.transformHierarchyEdges(t,null),this.removeOriginalEdges(),this.setSidesOfPortsToSidesOfDummyNodes(),t.setProperty(e.In,this.crossHierarchyMap),this.dummyNodeMap.clear()):(this.separateTransformHierarchyEdges(t),this.setContainerPortSidesByNetFlow(t),this.setSidesOfPortsToSidesOfDummyNodes(),this.removeOriginalEdges(),t.setProperty(e.In,this.crossHierarchyMap),this.dummyNodeMap.clear())}separateTransformHierarchyEdges(t){for(let n of t.getLayerlessNodes()){let t=n.getNestedGraph();t!==null&&(this.separateTransformHierarchyEdges(t),this.separateTransformNestedEdges(t,n),this.processInsideSelfLoops(t,n,n.getProperty(e.Lt),!0))}}separateTransformNestedEdges(t,n){let r=[],i=/* @__PURE__ */ new Set;for(let e of[...t.getLayerlessNodes()])if(e.getType()!==`EXTERNAL_PORT`)for(let a of e.getPorts()){for(let e of[...a.getOutgoingEdges()])if(!i.has(e)&&e.getTarget().getNode().getGraph()!==t){i.add(e);let o=this.introduceSeparateExternalPort(t,n,e,a,`OUTPUT`);o!==null&&r.push(o)}for(let e of[...a.getIncomingEdges()])if(!i.has(e)&&e.getSource().getNode().getGraph()!==t){i.add(e);let o=this.introduceSeparateExternalPort(t,n,e,a,`INPUT`);o!==null&&r.push(o)}}for(let e of r)t.getLayerlessNodes().includes(e.dummyNode)||t.getLayerlessNodes().push(e.dummyNode);r.length>0&&t.getProperty(e.Gn).add(`EXTERNAL_PORTS`)}introduceSeparateExternalPort(t,n,r,i,a){let o=a===`INPUT`?r.getSource():r.getTarget();if(o.getNode()!==n)return null;let s=o.getSide();if(s===`UNDEFINED`){let e=Ii(t);s=a===`INPUT`?Fi(Pi(e)):Pi(e)}let c=Ui(o,n.getProperty(e.Lt),s,this.calculateNetFlow(o),null,o.getPosition(),o.getSize(),Ii(t),t);c.setProperty(e.lr,o),this.dummyNodeMap.has(o)||this.dummyNodeMap.set(o,c);let l=this.createDummyEdge(t,r),u=c.getPorts()[0];a===`INPUT`?(l.setSource(u),l.setTarget(i)):(l.setSource(i),l.setTarget(u));let d=new sa(r,l,c,u,a,!0);return this.addToMap(r,new ia(l,t,a)),d}setContainerPortSidesByNetFlow(t){for(let n of t.getLayerlessNodes()){let t=n.getNestedGraph();if(t===null)continue;let r=n.getProperty(e.Lt);if(!e.Lr.isSideFixed(r))for(let e of n.getPorts()){if(e.getSide()!==`UNDEFINED`)continue;let n=Pi(Ii(t));e.setSideInferred(e.getNetFlow()>0?n:Fi(n))}this.setContainerPortSidesByNetFlow(t)}}removeOriginalEdges(){for(let e of[...this.crossHierarchyMap.keys()]){let t=this.crossHierarchyMap.get(e)??[];if(e.getLabels().length>0&&t.length>0){let n=[...t].sort((e,t)=>oa(e,t,this.topGraph));for(let t of[...e.getLabels()]){let r=-1;switch(t.placement===void 0?`CENTER`:t.placement){case`HEAD`:r=n.length-1;break;case`CENTER`:r=this.shallowestEdgeSegment(n);break;case`TAIL`:r=0}r!==-1&&(n[r].getNewEdge().getLabels().push(t),e.getLabels().splice(e.getLabels().indexOf(t),1))}}e.setSource(null),e.setTarget(null)}}shallowestEdgeSegment(e){let t=-1;for(let n=0;n<e.length;n++)if(e[n].getType()===`INPUT`){t=n===0?0:n-1;break}else n===e.length-1&&(t=n);return t}setSidesOfPortsToSidesOfDummyNodes(){for(let[t,n]of this.dummyNodeMap){n.setProperty(e.lr,t),t.setProperty(e._r,n),t.setProperty(e.Xn,!0);let r=n.getProperty(e.Un);t.setSide(r===`UNDEFINED`?`UNDEFINED`:r),t.getNode().setProperty(e.Lt,`FIXED_SIDE`),t.getNode().getGraph().getProperty(e.Gn).add(`NON_FREE_PORTS`)}}processInsideSelfLoops(t,n,r,i){if(n.getProperty(e.Q)){for(let i of n.getPorts())for(let a of[...i.getOutgoingEdges()]){if(!(a.getTarget().getNode()===n&&a.getProperty(e.$)))continue;let i=a.getSource(),o=this.dummyNodeMap.get(i);o===void 0&&(o=Ui(i,r,i.getSide(),-1,null,null,i.getSize(),Ii(t),t),o.setProperty(e.lr,i),this.dummyNodeMap.set(i,o),t.getLayerlessNodes().includes(o)||t.getLayerlessNodes().push(o));let s=a.getTarget(),c=this.dummyNodeMap.get(s);c===void 0&&(c=Ui(s,r,s.getSide(),1,null,null,s.getSize(),Ii(t),t),c.setProperty(e.lr,s),this.dummyNodeMap.set(s,c),t.getLayerlessNodes().includes(c)||t.getLayerlessNodes().push(c));let l=this.createDummyEdge(t,a);l.setSource(o.getPorts()[0]),l.setTarget(c.getPorts()[0]),this.addToMap(a,new ia(l,t,`OUTPUT`)),t.getProperty(e.Gn).add(`EXTERNAL_PORTS`)}if(i){let r=/* @__PURE__ */ new Map;n.getPorts().forEach((e,t)=>r.set(e,t));let i=t.getLayerlessNodes(),a=[...i].sort((t,n)=>{let i=t.getProperty(e.lr),a=n.getProperty(e.lr);if(i instanceof p&&a instanceof p){let e=r.get(i),t=r.get(a);if(e!==void 0&&t!==void 0)return e-t}return 0});a.some((e,t)=>e!==i[t])&&(i.length=0,i.push(...a))}}}calculateNetFlow(t){let n=t.getNode(),r=n.getProperty(e.Q),i=0,a=0;for(let o of t.getOutgoingEdges()){let t=o.isSelfLoop(),s=t&&r&&o.getProperty(e.$),c=o.getTarget().getNode();t&&s?a++:t&&!s?i++:c.getGraph().getParentNode()===n?a++:i++}for(let o of t.getIncomingEdges()){let t=o.isSelfLoop(),s=t&&r&&o.getProperty(e.$),c=o.getSource().getNode();t&&s?i++:t&&!s?a++:c.getGraph().getParentNode()===n?i++:a++}return i-a}transformHierarchyEdges(t,n){let r=[];for(let n of t.getLayerlessNodes()){let t=n.getNestedGraph();if(t!==null){let i=this.transformHierarchyEdges(t,n);if(r.push(...i),this.processInsideSelfLoops(t,n,`FREE`,!1),t.getProperty(e.Gn).has(`EXTERNAL_PORTS`)){let r=n.getProperty(e.Lt);for(let i of n.getPorts()){let a=this.dummyNodeMap.get(i);a===void 0&&(a=Ui(i,r,i.getSide(),-i.getNetFlow(),null,{x:0,y:0},i.getSize(),Ii(t),t),a.setProperty(e.lr,i),this.dummyNodeMap.set(i,a),t.getLayerlessNodes().includes(a)||t.getLayerlessNodes().push(a));let o=(n.getProperty(e.zt)??[]).includes(`INSIDE`),s=a.getPorts()[0],c=n.getProperty(e.zt)??[],l=!c.includes(`INSIDE`)&&!c.includes(`OUTSIDE`);for(let e of i.getLabels()){let t={text:``,position:{x:0,y:0},size:{x:e.size.x,y:e.size.y}};if(!o){let n=i.getSide(),r=0;if(l)switch(n){case`EAST`:r=Math.max(0,-e.position.x);break;case`WEST`:r=Math.max(0,e.size.x+e.position.x-i.getSize().x);break;case`NORTH`:r=Math.max(0,e.size.y+e.position.y-i.getSize().y);break;case`SOUTH`:r=Math.max(0,-e.position.y)}n===`EAST`||n===`WEST`?t.size.x=r:t.size.y=r}s.getLabels().push(t)}}}}}let i=[];return this.processInnerHierarchicalEdgeSegments(t,n,r,i),n!==null&&this.processOuterHierarchicalEdgeSegments(t,n,i),i}processInnerHierarchicalEdgeSegments(e,t,n,r){let i=[];for(let r of n){let a=null;if(r.type===`OUTPUT`)for(let o of[...r.origEdges]){let s=o.getTarget().getNode();if(s.getGraph()===e)this.connectChild(e,r,o,r.dummyPort,o.getTarget());else if(t===null||Li(s,t))this.connectSiblings(e,r,n,o);else{let n=this.introduceHierarchicalEdgeSegment(e,t,o,r.dummyPort,`OUTPUT`,a);n!==a&&i.push(n),n.exported&&(a=n)}}else for(let n of[...r.origEdges]){let o=n.getSource().getNode();if(o.getGraph()===e)this.connectChild(e,r,n,n.getSource(),r.dummyPort);else if(t===null||Li(o,t))continue;else{let o=this.introduceHierarchicalEdgeSegment(e,t,n,r.dummyPort,`INPUT`,a);o!==a&&i.push(o),o.exported&&(a=o)}}}for(let t of i)e.getLayerlessNodes().includes(t.dummyNode)||e.getLayerlessNodes().push(t.dummyNode),t.exported&&r.push(t)}processOuterHierarchicalEdgeSegments(e,t,n){let r=[];for(let n of e.getLayerlessNodes())for(let i of n.getPorts()){let n=null;for(let a of[...i.getOutgoingEdges()])if(!Li(a.getTarget().getNode(),t)){let i=this.introduceHierarchicalEdgeSegment(e,t,a,a.getSource(),`OUTPUT`,n);i!==n&&r.push(i),i.exported&&(n=i)}let a=null;for(let n of[...i.getIncomingEdges()])if(!Li(n.getSource().getNode(),t)){let i=this.introduceHierarchicalEdgeSegment(e,t,n,n.getTarget(),`INPUT`,a);i!==a&&r.push(i),i.exported&&(a=i)}}for(let t of r)e.getLayerlessNodes().includes(t.dummyNode)||e.getLayerlessNodes().push(t.dummyNode),t.exported&&n.push(t)}connectChild(e,t,n,r,i){let a=this.createDummyEdge(e,n);a.setSource(r),a.setTarget(i),this.addToMap(n,new ia(a,e,t.type))}connectSiblings(e,t,n,r){let i=null;for(let e of n)if(e!==t&&e.origEdges.includes(r)){i=e;break}if(i===null)return;let a=this.createDummyEdge(e,r);a.setSource(t.dummyPort),a.setTarget(i.dummyPort),this.addToMap(r,new ia(a,e,t.type))}introduceHierarchicalEdgeSegment(t,n,r,i,a,o){let s=t.getProperty(e.ht),c=null;a===`INPUT`&&r.getSource().getNode()===n?c=r.getSource():a===`OUTPUT`&&r.getTarget().getNode()===n&&(c=r.getTarget());let l=o;if(l===null||!s||c!==null){let o=`UNDEFINED`;c===null?n!==null&&e.Lr.isSideFixed(n.getProperty(e.Lt))&&(o=a===`INPUT`?`WEST`:`EAST`):o=c.getSide();let s=this.createExternalPortDummy(t,n,a,o,r),u=this.createDummyEdge(n.getGraph(),r);a===`INPUT`?(u.setSource(s.getPorts()[0]),u.setTarget(i)):(u.setSource(i),u.setTarget(s.getPorts()[0])),l=new sa(r,u,s,s.getProperty(e.lr),a,c===null)}else l.origEdges.push(r);return this.addToMap(r,new ia(l.newEdge,t,a)),l}createExternalPortDummy(t,n,r,i,a){let o=null,s=r===`INPUT`?a.getSource():a.getTarget(),c=Ii(t);if(s.getNode()===n)o=this.dummyNodeMap.get(s)??null,o===null&&(o=Ui(s,n.getProperty(e.Lt),i,this.calculateNetFlow(s),null,s.getPosition(),s.getSize(),c,t),o.setProperty(e.lr,s),this.dummyNodeMap.set(s,o));else{let a=t.getProperty(e.$t)/2;o=Ui({getProperty(t){if(t===e.It)return a},setProperty(){}},n.getProperty(e.Lt),i,r===`INPUT`?-1:1,null,{x:0,y:0},{x:0,y:0},c,t);let s=this.createPortForDummy(o,n,r);o.setProperty(e.lr,s),this.dummyNodeMap.set(s,o)}t.getProperty(e.Gn).add(`EXTERNAL_PORTS`);let l=t.getProperty(e.Lt);return e.Lr.isSideFixed(l)?t.setProperty(e.Lt,`FIXED_SIDE`):t.setProperty(e.Lt,`FREE`),o}createPortForDummy(t,n,r){let i=Ii(n.getGraph()),a=new p;return a.setNode(n),r===`INPUT`?a.setSide(Fi(Pi(i))):a.setSide(Pi(i)),a.setProperty(e.It,t.getProperty(e.It)),a}createDummyEdge(t,n){let r=new m;return r.copyProperties(n),r.setProperty(e.nt,null),r}addToMap(e,t){let n=this.crossHierarchyMap.get(e);n===void 0?this.crossHierarchyMap.set(e,[t]):n.push(t)}},la=class{moveGraphs(e,t,n,r){for(let i of t)this.moveGraph(e,i,n,r)}moveGraph(t,n,r,i){let a=r+n.getOffset().x,o=i+n.getOffset().y,s=/* @__PURE__ */ new Set;for(let r of n.getLayerlessNodes()){r.position.x+=a,r.position.y+=o;for(let t of r.getPorts())for(let n of t.getOutgoingEdges()){if(s.has(n))continue;s.add(n);for(let e of n.getBendPoints())e.x+=a,e.y+=o;let t=n.getProperty(e.nt);if(t!==null)for(let e of t)e.x+=a,e.y+=o;for(let e of n.getLabels())e.position.x+=a,e.position.y+=o}t.getLayerlessNodes().push(r),r.setGraph(t)}}offsetGraphs(e,t,n){for(let r of e)this.offsetGraph(r,t,n)}offsetGraph(t,n,r){let i=/* @__PURE__ */ new Set;for(let a of t.getLayerlessNodes()){a.position.x+=n,a.position.y+=r;for(let t of a.getPorts())for(let a of t.getOutgoingEdges()){if(i.has(a))continue;i.add(a);for(let e of a.getBendPoints())e.x+=n,e.y+=r;let t=a.getProperty(e.nt);if(t!==null)for(let e of t)e.x+=n,e.y+=r;for(let e of a.getLabels())e.position.x+=n,e.position.y+=r}}}};let ua=/* @__PURE__ */ function(e){return e.Q1=`Q1`,e.Q4=`Q4`,e.Q2=`Q2`,e.Q3=`Q3`,e}({});(function(e){function t(e){return e===`Q1`||e===`Q2`}e.isUpper=t;function n(e){return e===`Q1`||e===`Q4`}e.isLeft=n;function r(e,t){return e===`Q1`&&t===`Q4`||e===`Q4`&&t===`Q1`||e===`Q3`&&t===`Q2`||e===`Q2`&&t===`Q3`}e.isBothLeftOrBothRight=r;function i(e,t){return e===`Q1`&&(t===`Q2`||t===`Q3`)||e===`Q4`&&(t===`Q3`||t===`Q2`)}e.isOneLeftOneRight=i})(ua||={});var da=class{x;y;quadrant=null;convex=!0;constructor(e,t,n){this.x=e,this.y=t,n!==void 0&&(this.quadrant=n)}equals(e){return this.x===e.x&&this.y===e.y}};const fa=(e,t)=>e.x===t.x?e.y-t.y:e.x-t.x,pa=(e,t)=>e.x===t.x?t.y-e.y:e.x-t.x,ma=(e,t)=>e.x===t.x?e.y-t.y:t.x-e.x,ha=(e,t)=>e.x===t.x?t.y-e.y:t.x-e.x,ga=(e,t)=>{if(e.x===t.x){if(e.quadrant===t.quadrant||ua.isBothLeftOrBothRight(e.quadrant,t.quadrant)){let n=ua.isLeft(e.quadrant)?1:-1;if(e.convex&&!t.convex)return n;if(!e.convex&&t.convex)return-n}return _a[e.quadrant]-_a[t.quadrant]}return e.x-t.x},_a={Q1:0,Q4:1,Q2:2,Q3:3};var va=class{quadrant;points=[];maximalY;compare;constructor(e){this.quadrant=e,e===`Q1`||e===`Q2`?(this.compare=(e,t)=>t-e,this.maximalY=1/0):(this.compare=(e,t)=>e-t,this.maximalY=-1/0)}handle(e){this.compare(e.y,this.maximalY)>0&&(this.points.push(new da(e.x,e.y,this.quadrant)),this.maximalY=e.y)}},ya=class{rects=[];minY=null;maxY=null;lastX;queued=null;queuedPnt=null;constructor(e,t){this.lastX=Math.min(e?.x??0,t?.x??0)}handle(e){if(this.queued!==null&&(e.x!==this.queuedPnt.x||ua.isOneLeftOneRight(this.queuedPnt.quadrant,e.quadrant))&&(this.rects.push(this.queued),this.lastX=this.queued.x+this.queued.width,this.queued=null,this.queuedPnt=null),ua.isUpper(e.quadrant)?this.minY=e:this.maxY=e,(e.quadrant===`Q1`&&!e.convex||e.quadrant===`Q2`&&e.convex||e.quadrant===`Q3`&&e.convex||e.quadrant===`Q4`&&!e.convex)&&this.minY!==null&&this.maxY!==null){let t={x:this.lastX,y:this.minY.y,width:e.x-this.lastX,height:this.maxY.y-this.minY.y};this.queued=t,this.queuedPnt=e}}},ba=class e{hull=[];xMax1=null;xMax2=null;xMin1=null;xMin2=null;yMax1=null;yMax2=null;yMin1=null;yMin2=null;static of(t){let n=new e;for(let e of t)(n.xMax1===null||e.x>=n.xMax1.x)&&(n.xMax2=n.xMax1,n.xMax1=e),(n.xMin1===null||e.x<=n.xMin1.x)&&(n.xMin2=n.xMin1,n.xMin1=e),(n.yMax1===null||e.y>=n.yMax1.y)&&(n.yMax2=n.yMax1,n.yMax1=e),(n.yMin1===null||e.y<=n.yMin1.y)&&(n.yMin2=n.yMin1,n.yMin1=e);let r=new va(`Q1`);lr(t,fa,r);let i=new va(`Q4`);lr(t,pa,i);let a=new va(`Q2`);lr(t,ma,a);let o=new va(`Q3`);return lr(t,ha,o),xa(r.points,`Q1`),xa(a.points,`Q2`),xa(o.points,`Q3`),xa(i.points,`Q4`),n.hull.length=0,n.hull.push(...r.points,...[...a.points].reverse(),...o.points,...[...i.points].reverse()),n}getHull(){return this.hull}splitIntoRectangles(){let e=new ya(this.xMin1,this.xMin2);return lr(this.hull,ga,e),e.queued!==null&&e.rects.push(e.queued),e.rects}};function xa(e,t){let n=[],r=e[0];n.push(r);for(let i=1;i<e.length;i++){let a=e[i],o=new da(a.x,r.y,t);o.convex=!1,n.push(o,a),r=a}e.length=0,e.push(...n)}function Sa(e){return e===`LEFT`||e===`RIGHT`}function Ca(e){switch(e){case`LEFT`:return`RIGHT`;case`RIGHT`:return`LEFT`;case`UP`:return`DOWN`;case`DOWN`:return`UP`;default:return`UNDEFINED`}}const wa={getHorizontalSpacing(e,t){return Math.min(e.getHorizontalSpacing(),t.getHorizontalSpacing())},getVerticalSpacing(e,t){return Math.min(e.getVerticalSpacing(),t.getVerticalSpacing())}};function L(e,t){if(e.size!==t.size)return!1;for(let n of e)if(!t.has(n))return!1;return!0}const Ta=`NORTH`,Ea=`EAST`,Da=`SOUTH`,R=`WEST`,Oa=/* @__PURE__ */ new Set([Ta]),ka=/* @__PURE__ */ new Set([Ea]),Aa=/* @__PURE__ */ new Set([Da]),ja=/* @__PURE__ */ new Set([R]),Ma=/* @__PURE__ */ new Set([Ta,Ea]),Na=/* @__PURE__ */ new Set([Ea,Da]),Pa=/* @__PURE__ */ new Set([Da,R]),Fa=/* @__PURE__ */ new Set([Ta,R]),Ia=/* @__PURE__ */ new Set([Ta,Da]),La=/* @__PURE__ */ new Set([Ea,R]),Ra=/* @__PURE__ */ new Set([Ta,Ea,R]),za=/* @__PURE__ */ new Set([Ta,Da,R]),Ba=/* @__PURE__ */ new Set([Ea,Da,R]),Va=/* @__PURE__ */ new Set([Ta,Ea,Da,R]);var Ha=class{cGraph;spacing;oldPosition=/* @__PURE__ */ new Map;offsets=/* @__PURE__ */ new Map;globalOffset={x:0,y:0};graphSize={x:0,y:0};externalExtensions=/* @__PURE__ */ new Map;externalPlaceholder=/* @__PURE__ */ new Map;constructor(e){this.spacing=e,this.cGraph=new ar([])}getOffset(e){let t=this.oldPosition.get(e),n=this.offsets.get(e).rect;return{x:t.x-n.x,y:t.y-n.y}}getGlobalOffset(){return this.globalOffset}getGraphSize(){return this.graphSize}getExternalExtensions(){return this.externalExtensions}getExternalPlaceholder(){return this.externalPlaceholder}transform(e){this.cGraph=new ar([`LEFT`,`RIGHT`,`UP`,`DOWN`]);for(let t of e.getComponents()){let e=new ir;this.cGraph.cGroups.push(e);for(let n of t.getHull()){let r=new Ua(n,this.spacing);this.setLock(r,t.getExternalExtensionSides()),this.oldPosition.has(t)||(this.oldPosition.set(t,{x:n.x,y:n.y}),this.offsets.set(t,r)),this.cGraph.cNodes.push(r),e.addCNode(r)}for(let n of t.getExternalExtensions()){let r=new Ua(n.getRepresentor(),this.spacing);this.externalExtensions.set(n,{first:e,second:r}),this.setLock(r,t.getExternalExtensionSides());let i=n.getPlaceholder();if(i!==null){let r=new Ua(i,this.spacing,1);this.setLock(r,t.getExternalExtensionSides()),new ir().addCNode(r);let a=this.externalPlaceholder.get(n.getDirection())??[];a.push({first:e,second:r}),this.externalPlaceholder.set(n.getDirection(),a)}}}return this.cGraph}setLock(e,t){t.size===0&&e.lock.set(!0,!0,!0,!0),L(t,Oa)&&e.lock.set(!0,!0,!0,!1),L(t,ka)&&e.lock.set(!1,!0,!0,!0),L(t,Aa)&&e.lock.set(!0,!0,!1,!0),L(t,ja)&&e.lock.set(!0,!1,!0,!0),L(t,Ma)&&e.lock.set(!1,!0,!0,!1),L(t,Na)&&e.lock.set(!1,!0,!1,!0),L(t,Pa)&&e.lock.set(!0,!1,!1,!0),L(t,Fa)&&e.lock.set(!0,!1,!0,!1),L(t,Ia)&&e.lock.set(!0,!0,!0,!0),L(t,La)&&e.lock.set(!0,!0,!0,!0),L(t,Ba)&&e.lock.set(!0,!0,!0,!0),L(t,za)&&e.lock.set(!0,!0,!0,!0),L(t,Ra)&&e.lock.set(!0,!0,!0,!0),L(t,Va)&&e.lock.set(!0,!0,!0,!0)}applyLayout(){for(let e of this.cGraph.cNodes)e.applyElementPosition();let e={x:1/0,y:1/0},t={x:-1/0,y:-1/0};for(let n of this.cGraph.cNodes)e.x=Math.min(e.x,n.hitbox.x),e.y=Math.min(e.y,n.hitbox.y),t.x=Math.max(t.x,n.hitbox.x+n.hitbox.width),t.y=Math.max(t.y,n.hitbox.y+n.hitbox.height);for(let n of this.externalPlaceholder.values())for(let r of n){let n=r.second;e.x=Math.min(e.x,n.hitbox.x),e.y=Math.min(e.y,n.hitbox.y),t.x=Math.max(t.x,n.hitbox.x+n.hitbox.width),t.y=Math.max(t.y,n.hitbox.y+n.hitbox.height)}this.globalOffset={x:-e.x,y:-e.y},this.graphSize={x:t.x-e.x,y:t.y-e.y},this.cGraph.cGroups.length=0,this.cGraph.cNodes.length=0}},Ua=class extends vr{rect;spacing;individualSpacing;constructor(e,t,n=null){super(),this.rect=e,this.spacing=t,this.hitbox={x:e.x,y:e.y,width:e.width,height:e.height},this.individualSpacing=n}getHorizontalSpacing(){return this.individualSpacing??this.spacing}getVerticalSpacing(){return this.individualSpacing??this.spacing}applyElementPosition(){this.rect.x=this.hitbox.x,this.rect.y=this.hitbox.y}getElementPosition(){return this.rect.x}toString(){return``}};const Wa=/* @__PURE__ */ new Set([`LEFT`,`RIGHT`]),Ga=/* @__PURE__ */ new Set([`UP`,`DOWN`]);var Ka=class e{compactionGraph=new ar([]);transformer=new Ha(0);verticalExternalExtensions=[];horizontalExternalExtensions=[];compactor=null;topLeft={x:0,y:0};bottomRight={x:0,y:0};constructor(){}static init(t,n){let r=new e;return r.transformer=new Ha(n),r.compactionGraph=r.transformer.transform(t),r}compact(){let e=[];this.verticalExternalExtensions=[],this.horizontalExternalExtensions=[];for(let[t,n]of this.transformer.getExternalExtensions())e.push(n.second),Sa(t.getDirection())?this.horizontalExternalExtensions.push(n):this.verticalExternalExtensions.push(n);this.addExternalEdgeRepresentations(this.horizontalExternalExtensions),this.addExternalEdgeRepresentations(this.verticalExternalExtensions),this.compactor=new gr(this.compactionGraph),this.compactor.setSpacingsHandler(wa),this.removeExternalEdgeRepresentations(this.horizontalExternalExtensions),this.removeExternalEdgeRepresentations(this.verticalExternalExtensions),e.push(...this.compactor.cGraph.cNodes),this.topLeft={x:1/0,y:1/0},this.bottomRight={x:-1/0,y:-1/0};for(let t of e)this.topLeft.x=Math.min(this.topLeft.x,t.hitbox.x),this.topLeft.y=Math.min(this.topLeft.y,t.hitbox.y),this.bottomRight.x=Math.max(this.bottomRight.x,t.hitbox.x+t.hitbox.width),this.bottomRight.y=Math.max(this.bottomRight.y,t.hitbox.y+t.hitbox.height);this.compactor.setLockingStrategy(e=>e.first.cGroup.outDegree!==0);let t=0,n;do n=this.compactRun(t),t++;while((t<2||n>1e-4)&&t<10);this.compactor.setLockingStrategy(e=>e.first.lock.get(e.second)||e.first.cGroup.outDegree!==0&&e.first.lock.get(e.second)),this.compactRun(0),this.compactor.finish(),this.transformer.applyLayout()}getGraphSize(){return this.transformer.getGraphSize()}getOffset(e){let t=this.transformer.getOffset(e),n=this.transformer.getGlobalOffset();return{x:-t.x+n.x,y:-t.y+n.y}}compactRun(e){let t=0;for(let e of this.compactionGraph.cGroups)e.delta=0,e.deltaNormalized=0;this.addPlaceholders(`HORZ`),this.addExternalEdgeRepresentations(this.verticalExternalExtensions),this.compactor.calculateGroupOffsets(),this.compactor.forceConstraintsRecalculation();let n=`LEFT`;this.compactor.changeDirection(n).compact().changeDirection(Ca(n)).applyLockingStrategy().compact().changeDirection(n).applyLockingStrategy().compact(),this.compactor.changeDirection(`LEFT`),this.removeExternalEdgeRepresentations(this.verticalExternalExtensions),this.removePlaceholders(`HORZ`),this.updateExternalExtensionDimensions(`HORZ`),this.updatePlaceholders(`VERT`),this.addPlaceholders(`VERT`),this.addExternalEdgeRepresentations(this.horizontalExternalExtensions),this.compactor.calculateGroupOffsets();for(let e of this.compactionGraph.cGroups)t+=Math.abs(e.deltaNormalized);for(let e of this.compactionGraph.cGroups)e.delta=0,e.deltaNormalized=0;n=`UP`,this.compactor.changeDirection(n).forceConstraintsRecalculation().compact().changeDirection(Ca(n)).applyLockingStrategy().compact().changeDirection(n).applyLockingStrategy().compact(),this.compactor.changeDirection(`LEFT`),this.removeExternalEdgeRepresentations(this.horizontalExternalExtensions),this.removePlaceholders(`VERT`),this.updateExternalExtensionDimensions(`VERT`),this.updatePlaceholders(`HORZ`),this.compactor.forceConstraintsRecalculation();for(let e of this.compactionGraph.cGroups)t+=Math.abs(e.deltaNormalized);return t}addExternalEdgeRepresentations(e){for(let t of e)this.compactionGraph.cNodes.push(t.second),t.first.addCNode(t.second)}removeExternalEdgeRepresentations(e){for(let t of e){let e=this.compactionGraph.cNodes.indexOf(t.second);e!==-1&&this.compactionGraph.cNodes.splice(e,1),t.first.removeCNode(t.second)}}addPlaceholders(e){let t=e===`VERT`?Ga:Wa;for(let e of t)for(let t of this.transformer.getExternalPlaceholder().get(e)??[])this.compactionGraph.cNodes.push(t.second),this.compactionGraph.cGroups.push(t.second.cGroup)}removePlaceholders(e){let t=e===`VERT`?Ga:Wa;for(let e of t)for(let t of this.transformer.getExternalPlaceholder().get(e)??[]){let e=this.compactionGraph.cNodes.indexOf(t.second);e!==-1&&this.compactionGraph.cNodes.splice(e,1);let n=this.compactionGraph.cGroups.indexOf(t.second.cGroup);n!==-1&&this.compactionGraph.cGroups.splice(n,1)}}updatePlaceholders(e){let t=e===`VERT`?Ga:Wa;for(let e of t)for(let t of this.transformer.getExternalPlaceholder().get(e)??[]){let n=t.second,r=t.first.deltaNormalized;switch(e){case`LEFT`:case`RIGHT`:n.hitbox.y+=r;break;case`UP`:case`DOWN`:n.hitbox.x+=r}}}updateExternalExtensionDimensions(e){for(let[t,n]of this.transformer.getExternalExtensions()){if(e===`VERT`){if(t.getDirection()!==`UP`&&t.getDirection()!==`DOWN`)continue}else if(t.getDirection()!==`LEFT`&&t.getDirection()!==`RIGHT`)continue;let r=n.second,i=n.first.deltaNormalized;switch(t.getDirection()){case`LEFT`:r.hitbox.x=this.topLeft.x,r.hitbox.width=Math.max(1,r.hitbox.width+i);break;case`RIGHT`:r.hitbox.x=r.hitbox.x+i,r.hitbox.width=Math.max(1,r.hitbox.width-i);break;case`UP`:r.hitbox.y=this.topLeft.y,r.hitbox.height=Math.max(1,r.hitbox.height+i);break;case`DOWN`:r.hitbox.y=r.hitbox.y+i,r.hitbox.height=Math.max(1,r.hitbox.height-i)}}}};const qa=new e.ai(`org.eclipse.elk.layered.compaction.connectedComponents`,!1),Ja=1e-4;function Ya(e){switch(e){case`NORTH`:return`UP`;case`WEST`:return`LEFT`;case`EAST`:return`RIGHT`;case`SOUTH`:return`DOWN`;default:return`UNDEFINED`}}function Xa(e,t,n){return Math.abs(e-t)<=n}function z(e,t,n,r){return{x:e,y:t,width:n,height:r}}function Za(e){return{x:e.x+e.width,y:e.y}}function Qa(e){return{x:e.x+e.width,y:e.y+e.height}}function $a(e){return{x:e.x,y:e.y+e.height}}function eo(e){return{x:e.x,y:e.y}}var to=class{compactor=null;yetAnotherOffset={x:0,y:0};compactedGraphSize={x:0,y:0};graphTopLeft={x:0,y:0};graphBottomRight={x:0,y:0};compact(t,n,r){this.graphTopLeft={x:1/0,y:1/0},this.graphBottomRight={x:-1/0,y:-1/0};for(let e of t)for(let t of e.getLayerlessNodes())this.graphTopLeft.x=Math.min(this.graphTopLeft.x,t.position.x-t.getMargin().left),this.graphTopLeft.y=Math.min(this.graphTopLeft.y,t.position.y-t.getMargin().top),this.graphBottomRight.x=Math.max(this.graphBottomRight.x,t.position.x+t.size.x+t.getMargin().right),this.graphBottomRight.y=Math.max(this.graphBottomRight.y,t.position.y+t.size.y+t.getMargin().bottom);let i=new no;for(let e of t){let t=this.transformLGraph(e);i.getComponents().push(t),t.containsRegularNodes=t.containsRegularNodes||t.getExternalExtensionSides().size>0}this.compactor=Ka.init(i,r),this.compactor.compact(),this.yetAnotherOffset={x:0,y:0},this.compactedGraphSize=this.compactor.getGraphSize();for(let t of i.getComponents()){let n=this.compactor.getOffset(t);fo(t.graph,n.x,n.y);for(let n of t.getNodes())if(n.getType()===`EXTERNAL_PORT`){let t=this.getExternalPortPosition(n.getPosition(),n.getProperty(e.Un));n.position.x=t.x,n.position.y=t.y}}for(let e of i.getComponents())for(let t of e.getExternalEdges()){let e=[];e.push(t.getSource().getAbsoluteAnchor()),e.push(...t.getBendPoints()),e.push(t.getTarget().getAbsoluteAnchor());let n=null;for(let t of e)n===null||(Xa(n.x,t.x,Ja)?(this.yetAnotherOffset.x=Math.min(this.yetAnotherOffset.x,n.x),this.compactedGraphSize.x=Math.max(this.compactedGraphSize.x,n.x)):Xa(n.y,t.y,Ja)&&(this.yetAnotherOffset.y=Math.min(this.yetAnotherOffset.y,n.y),this.compactedGraphSize.y=Math.max(this.compactedGraphSize.y,n.y))),n=t}this.yetAnotherOffset.x=-this.yetAnotherOffset.x,this.yetAnotherOffset.y=-this.yetAnotherOffset.y,this.compactedGraphSize.x+=this.yetAnotherOffset.x,this.compactedGraphSize.y+=this.yetAnotherOffset.y}getOffset(){return this.yetAnotherOffset}getGraphSize(){return this.compactedGraphSize}transformLGraph(e){let t=new ro(e);t.containsRegularNodes||this.createDummyNode(e);let n=this.componentHullPoints(e),r=/* @__PURE__ */ new Map,i=new co;for(let t of e.getLayerlessNodes())for(let e of t.getOutgoingEdges())if(this.isExternalEdge(e)){let t=this.transformLEdge(e,n,i),a=r.get(t.getDirection())??[];a.push(t.edge),r.set(t.getDirection(),a)}let a=[];for(let e of t.getExternalExtensionSides()){let t=i.min[e],o=i.max[e],s=i.extent[e],c=null,l=null;switch(e){case`WEST`:c=z(this.graphTopLeft.x,t,n.topLeft.x-this.graphTopLeft.x,o-t),l=z(this.graphTopLeft.x,t,s,o-t),n.addVector(Za(c)),n.addVector(Qa(c));break;case`EAST`:c=z(n.bottomRight.x,t,this.graphBottomRight.x-n.bottomRight.x,o-t),l=z(this.graphBottomRight.x-s,t,s,o-t),n.addVector(eo(c)),n.addVector($a(c));break;case`NORTH`:c=z(t,this.graphTopLeft.y,o-t,n.topLeft.y-this.graphTopLeft.y),l=z(t,this.graphTopLeft.y,o-t,s),n.addVector($a(c)),n.addVector(Qa(c));break;case`SOUTH`:c=z(t,n.bottomRight.y,o-t,this.graphBottomRight.y-n.bottomRight.y),l=z(t,this.graphBottomRight.y-s,o-t,s),n.addVector(eo(c)),n.addVector(Za(c))}if(c!==null){let t=new io;t.side=e,t.extension=c,t.placeholder=l,t.edges=new Set(r.get(Ya(e))??[]),a.push(t)}}return t.externalExtensions=a,t.rectilinearConvexHull=ba.of(n.points).splitIntoRectangles(),t}createDummyNode(t){let n=t.getLayerlessNodes()[0],r=new f(t);switch(r.size.x=Math.max(1,n.size.x),r.size.y=Math.max(1,n.size.y),r.position.x=n.position.x,r.position.y=n.position.y,n.getProperty(e.Un)){case`WEST`:r.position.x+=2;break;case`NORTH`:r.position.y+=2;break;case`EAST`:r.position.x-=2;break;case`SOUTH`:r.position.y-=2}let i=new p;i.setNode(r);let a=new m,o=n.getPorts()[0];a.setSource(o),a.setTarget(i),i.position.x=o.position.x,i.position.y=o.position.y;let s=o.getAnchor(),c=i.getAnchor();c.x=s.x,c.y=s.y}componentHullPoints(e){let t=new oo;for(let n of e.getLayerlessNodes())if(n.getType()!==`EXTERNAL_PORT`){lo(t,n);for(let e of n.getOutgoingEdges())if(!this.isExternalEdge(e))for(let n of e.getBendPoints())t.add(new da(n.x,n.y))}return t}isExternalEdge(e){return e.getSource().getNode().getType()===`EXTERNAL_PORT`||e.getTarget().getNode().getType()===`EXTERNAL_PORT`}transformLEdge(t,n,r){let i=new ao(t),a=this.edgeToSegments(t,i),o=Math.max(t.getProperty(e.W),1);for(let e of a.innerSegments){let t=this.segmentToRectangle(e.first,e.second,o);n.addRect(t)}let s=i.externalPortSide,c=this.segmentToRectangle(a.outerSegment.first,a.outerSegment.second,o);s===`WEST`||s===`EAST`?(r.min[s]=Math.min(r.min[s],c.y),r.max[s]=Math.max(r.max[s],c.y+c.height)):(r.min[s]=Math.min(r.min[s],c.x),r.max[s]=Math.max(r.max[s],c.x+c.width));let l=-1/0,u=i.externalPort.getNode().getMargin();switch(s){case`WEST`:l=u.right;break;case`EAST`:l=u.left;break;case`NORTH`:l=u.bottom;break;case`SOUTH`:l=u.top}return r.extent[s]=Math.max(r.extent[s],l),i}segmentToRectangle(e,t,n){return z(Math.min(e.x,t.x)-n/2,Math.min(e.y,t.y)-n/2,Math.abs(e.x-t.x)+n,Math.abs(e.y-t.y)+n)}edgeToSegments(e,t){let n=t.externalPort,r=t.externalPortSide,i=e.getSource().getAbsoluteAnchor(),a=e.getTarget().getAbsoluteAnchor();n===e.getSource()?(i=this.getExternalPortPosition(i,r),a=uo(e.getTarget())):(i=uo(e.getSource()),a=this.getExternalPortPosition(a,r));let o=[];o.push(i),o.push(...e.getBendPoints()),o.push(a);let s=e.getSource()===n,c=new so;for(let e=0;e<o.length-1;++e){let t={first:o[e],second:o[e+1]};s&&e===0||!s&&e===o.length-2?c.outerSegment=t:c.innerSegments.push(t)}return c}getExternalPortPosition(e,t){switch(t){case`NORTH`:return{x:e.x,y:Math.min(this.graphTopLeft.y,e.y)};case`EAST`:return{x:Math.max(this.graphBottomRight.x,e.x),y:e.y};case`SOUTH`:return{x:e.x,y:Math.max(this.graphBottomRight.y,e.y)};case`WEST`:return{x:Math.min(e.x,this.graphTopLeft.x),y:e.y};default:return{x:e.x,y:e.y}}}},no=class{components=[];containsExternalPorts=!1;getComponents(){return this.components}isContainsExternalExtensions(){return this.containsExternalPorts}},ro=class{graph;containsRegularNodes;rectilinearConvexHull=[];externalExtensions=[];constructor(e){this.graph=e,this.containsRegularNodes=e.getLayerlessNodes().some(e=>e.getType()===`NORMAL`)}getExternalExtensionSides(){return this.graph.getProperty(e.Bn)??/* @__PURE__ */ new Set}getHull(){return this.rectilinearConvexHull}getExternalExtensions(){return this.externalExtensions}getNodes(){return this.graph.getLayerlessNodes()}getExternalEdges(){let e=[];for(let t of this.externalExtensions)e.push(...t.getRepresentative());return e}},io=class{edges=/* @__PURE__ */ new Set;side=`UNDEFINED`;extension=z(0,0,0,0);placeholder=z(0,0,0,0);getRepresentative(){return this.edges}getRepresentor(){return this.extension}getParent(){throw Error(`UnsupportedOperationException`)}getDirection(){return Ya(this.side)}getPlaceholder(){return this.placeholder}},ao=class{edge;externalPort;externalPortSide;constructor(t){if(this.edge=t,t.getSource().getNode().getType()===`EXTERNAL_PORT`)this.externalPort=t.getSource(),this.externalPortSide=t.getSource().getNode().getProperty(e.Un);else if(t.getTarget().getNode().getType()===`EXTERNAL_PORT`)this.externalPort=t.getTarget(),this.externalPortSide=t.getTarget().getNode().getProperty(e.Un);else throw Error(`Edge ${t} is not an external edge.`)}getDirection(){return Ya(this.externalPortSide)}getRepresentative(){return this.edge}},oo=class{points=[];topLeft={x:1/0,y:1/0};bottomRight={x:-1/0,y:-1/0};add(e){this.topLeft.x=Math.min(this.topLeft.x,e.x),this.topLeft.y=Math.min(this.topLeft.y,e.y),this.bottomRight.x=Math.max(this.bottomRight.x,e.x),this.bottomRight.y=Math.max(this.bottomRight.y,e.y),this.points.push(e)}addVector(e){this.add(new da(e.x,e.y))}addRect(e){this.addVector({x:e.x,y:e.y}),this.addVector({x:e.x+e.width,y:e.y}),this.addVector({x:e.x,y:e.y+e.height}),this.addVector({x:e.x+e.width,y:e.y+e.height})}},so=class{innerSegments=[];outerSegment=null},co=class{min;max;extent;constructor(){this.min={NORTH:1/0,EAST:1/0,SOUTH:1/0,WEST:1/0,UNDEFINED:1/0},this.max={NORTH:-1/0,EAST:-1/0,SOUTH:-1/0,WEST:-1/0,UNDEFINED:-1/0},this.extent={NORTH:-1/0,EAST:-1/0,SOUTH:-1/0,WEST:-1/0,UNDEFINED:-1/0}}};function lo(e,t){let n=t.getMargin();e.addVector({x:t.position.x-n.left,y:t.position.y-n.top}),e.addVector({x:t.position.x-n.left,y:t.position.y+t.size.y+n.bottom}),e.addVector({x:t.position.x+t.size.x+n.right,y:t.position.y-n.top}),e.addVector({x:t.position.x+t.size.x+n.right,y:t.position.y+t.size.y+n.bottom})}function uo(e){let t=e.getAbsoluteAnchor(),n=e.getNode().getMargin();switch(e.getSide()){case`NORTH`:t.y-=n.top;break;case`EAST`:t.x+=n.right;break;case`SOUTH`:t.y+=n.bottom;break;case`WEST`:t.x-=n.left}return t}function fo(e,t,n){let r=/* @__PURE__ */ new Set;for(let i of e.getLayerlessNodes()){i.position.x+=t,i.position.y+=n;for(let e of i.getPorts())for(let i of e.getOutgoingEdges())if(!r.has(i)){r.add(i);for(let e of i.getBendPoints())e.x+=t,e.y+=n}}}function po(t){return t.getProperty(e.Bn)??/* @__PURE__ */ new Set}var mo=class extends la{combine(t,n){if(t.length===1){let e=t[0];e!==n&&(n.getLayerlessNodes().length=0,this.moveGraph(n,e,0,0),n.copyProperties(e),n.getSize().x=e.getSize().x,n.getSize().y=e.getSize().y);return}if(t.length===0){n.getLayerlessNodes().length=0,n.getSize().x=0,n.getSize().y=0;return}this.sortComponents(t,n);let r=t[0];n.getLayerlessNodes().length=0,n.copyProperties(r);let i=0,a=0;for(let e of t){let t=e.getSize();i=Math.max(i,t.x),a+=t.x*t.y}i=Math.max(i,Math.sqrt(a)*n.getProperty(e.h));let o=n.getProperty(e.Qt);if(this.placeComponents(t,n,i,o),r.getProperty(qa)){let e=new to;e.compact(t,n.getSize(),o);for(let n of t){let t=n.getOffset();t.x=e.getOffset().x,t.y=e.getOffset().y}let r=n.getSize();r.x=e.getGraphSize().x,r.y=e.getGraphSize().y}this.moveGraphs(n,t,0,0)}sortComponents(e,t){}placeComponents(e,t,n,r){let i=0,a=0,o=0,s=r,c=null,l=0;for(let t of e){let e=t.getSize(),u=po(t);(i+e.x>n&&!u.has(`NORTH`)||c!==null&&po(c).has(`EAST`)||u.has(`WEST`))&&(i=l,a+=o+r,o=0);let d=t.getOffset();u.has(`NORTH`)&&(i=s+r),this.offsetGraph(t,i+d.x,a+d.y),s=Math.max(s,i+e.x),u.has(`SOUTH`)&&(l=Math.max(l,i+e.x+r)),d.x=0,d.y=0,o=Math.max(o,e.y),i+=e.x+r,c=t}t.getSize().x=s,t.getSize().y=a+o}};function ho(e){return[...e].sort().join(`,`)}const B={NONE:/* @__PURE__ */ new Set,WEST:/* @__PURE__ */ new Set([`WEST`]),EAST:/* @__PURE__ */ new Set([`EAST`]),NORTH:/* @__PURE__ */ new Set([`NORTH`]),SOUTH:/* @__PURE__ */ new Set([`SOUTH`]),NORTH_SOUTH:/* @__PURE__ */ new Set([`NORTH`,`SOUTH`]),EAST_WEST:/* @__PURE__ */ new Set([`EAST`,`WEST`]),NORTH_WEST:/* @__PURE__ */ new Set([`NORTH`,`WEST`]),NORTH_EAST:/* @__PURE__ */ new Set([`NORTH`,`EAST`]),SOUTH_WEST:/* @__PURE__ */ new Set([`SOUTH`,`WEST`]),EAST_SOUTH:/* @__PURE__ */ new Set([`EAST`,`SOUTH`]),NORTH_EAST_WEST:/* @__PURE__ */ new Set([`NORTH`,`EAST`,`WEST`]),NORTH_SOUTH_WEST:/* @__PURE__ */ new Set([`NORTH`,`SOUTH`,`WEST`]),EAST_SOUTH_WEST:/* @__PURE__ */ new Set([`EAST`,`SOUTH`,`WEST`]),NORTH_EAST_SOUTH:/* @__PURE__ */ new Set([`NORTH`,`EAST`,`SOUTH`]),NORTH_EAST_SOUTH_WEST:/* @__PURE__ */ new Set([`NORTH`,`EAST`,`SOUTH`,`WEST`])},go=/* @__PURE__ */ new Map;function V(e,...t){let n=ho(e),r=go.get(n);r===void 0&&(r=/* @__PURE__ */ new Set,go.set(n,r));for(let e of t)r.add(ho(e))}V(B.NONE,B.NORTH_EAST_SOUTH_WEST),V(B.WEST,B.NORTH_EAST_SOUTH_WEST,B.NORTH_SOUTH_WEST),V(B.EAST,B.NORTH_EAST_SOUTH,B.NORTH_EAST_SOUTH_WEST),V(B.NORTH,B.NORTH_EAST_SOUTH_WEST,B.NORTH_EAST_WEST),V(B.SOUTH,B.EAST_SOUTH_WEST,B.NORTH_EAST_SOUTH_WEST),V(B.NORTH_SOUTH,B.EAST_WEST,B.NORTH_EAST_SOUTH_WEST,B.NORTH_EAST_WEST,B.EAST_SOUTH_WEST),V(B.EAST_WEST,B.NORTH_SOUTH,B.NORTH_SOUTH_WEST,B.NORTH_EAST_SOUTH,B.NORTH_EAST_SOUTH_WEST),V(B.NORTH_WEST,B.NORTH_WEST,B.NORTH_EAST_WEST,B.NORTH_SOUTH_WEST),V(B.NORTH_EAST,B.NORTH_EAST,B.NORTH_EAST_WEST,B.NORTH_EAST_SOUTH),V(B.SOUTH_WEST,B.SOUTH_WEST,B.EAST_SOUTH_WEST,B.NORTH_SOUTH_WEST),V(B.EAST_SOUTH,B.EAST_SOUTH,B.EAST_SOUTH_WEST,B.NORTH_EAST_SOUTH),V(B.NORTH_EAST_WEST,B.NORTH,B.NORTH_SOUTH,B.NORTH_WEST,B.NORTH_EAST,B.NORTH_EAST_SOUTH_WEST,B.NORTH_EAST_WEST,B.NORTH_SOUTH_WEST,B.NORTH_EAST_SOUTH),V(B.EAST_SOUTH_WEST,B.SOUTH,B.NORTH_SOUTH,B.SOUTH_WEST,B.EAST_SOUTH,B.EAST_SOUTH_WEST,B.NORTH_SOUTH_WEST,B.NORTH_EAST_SOUTH,B.NORTH_EAST_SOUTH_WEST),V(B.NORTH_SOUTH_WEST,B.WEST,B.EAST_WEST,B.NORTH_WEST,B.SOUTH_WEST,B.NORTH_EAST_WEST,B.EAST_SOUTH_WEST,B.NORTH_SOUTH_WEST,B.NORTH_EAST_SOUTH_WEST),V(B.NORTH_EAST_SOUTH,B.EAST,B.EAST_WEST,B.NORTH_EAST,B.EAST_SOUTH,B.NORTH_EAST_WEST,B.EAST_SOUTH_WEST,B.NORTH_EAST_SOUTH,B.NORTH_EAST_SOUTH_WEST),V(B.NORTH_EAST_SOUTH_WEST,B.NONE,B.WEST,B.EAST,B.NORTH,B.SOUTH,B.NORTH_SOUTH,B.EAST_WEST,B.NORTH_EAST_WEST,B.EAST_SOUTH_WEST,B.NORTH_SOUTH_WEST,B.NORTH_EAST_SOUTH,B.NORTH_EAST_SOUTH_WEST);var _o=class{components=/* @__PURE__ */ new Map;constructor(e){e!==void 0&&this.add(e)}add(t){if(this.canAdd(t)){let n=ho(t.getProperty(e.Bn)??/* @__PURE__ */ new Set),r=this.components.get(n);return r===void 0?this.components.set(n,[t]):r.push(t),!0}return!1}canAdd(t){let n=t.getProperty(e.Bn)??/* @__PURE__ */ new Set,r=go.get(ho(n));if(r!==void 0)for(let e of r){let t=this.components.get(e);if(t!==void 0&&t.length>0)return!1}return!0}getPortSides(){return[...this.components.keys()]}getComponents(){return[...this.components.values()].flat()}getComponentsFor(e){return this.components.get(ho(e))??[]}},vo=class extends la{componentGroups=[];combine(t,n){if(this.componentGroups=[],n.getLayerlessNodes().length=0,t.length===0){n.getSize().x=0,n.getSize().y=0;return}let r=t[0];n.copyProperties(r);for(let e of t)this.addComponent(e);let i=0,a=0,o=r.getProperty(e.Qt);for(let e of this.componentGroups){let t=this.placeComponents(e,o);this.offsetGraphs(e.getComponents(),i,a),i+=t.x,a+=t.y}if(n.getSize().x=i-o,n.getSize().y=a-o,r.getProperty(qa)&&r.getProperty(e.B)===`ORTHOGONAL`){for(let e of t)this.offsetGraph(e,e.getOffset().x,e.getOffset().y);let e=new to;e.compact(t,n.getSize(),o);for(let n of t)n.getOffset().x=e.getOffset().x,n.getOffset().y=e.getOffset().y;n.getSize().x=e.getGraphSize().x,n.getSize().y=e.getGraphSize().y}for(let e of this.componentGroups)this.moveGraphs(n,e.getComponents(),0,0)}addComponent(e){for(let t of this.componentGroups)if(t.add(e))return;this.componentGroups.push(new _o(e))}placeComponents(e,t){let n=this.placeComponentsInRows(e.getComponentsFor(B.NONE),t),r=this.placeComponentsHorizontally(e.getComponentsFor(B.NORTH),t),i=this.placeComponentsHorizontally(e.getComponentsFor(B.SOUTH),t),a=this.placeComponentsVertically(e.getComponentsFor(B.WEST),t),o=this.placeComponentsVertically(e.getComponentsFor(B.EAST),t),s=this.placeComponentsHorizontally(e.getComponentsFor(B.NORTH_WEST),t),c=this.placeComponentsHorizontally(e.getComponentsFor(B.NORTH_EAST),t),l=this.placeComponentsHorizontally(e.getComponentsFor(B.SOUTH_WEST),t),u=this.placeComponentsHorizontally(e.getComponentsFor(B.EAST_SOUTH),t),d=this.placeComponentsVertically(e.getComponentsFor(B.EAST_WEST),t),f=this.placeComponentsHorizontally(e.getComponentsFor(B.NORTH_SOUTH),t),p=this.placeComponentsHorizontally(e.getComponentsFor(B.NORTH_EAST_WEST),t),m=this.placeComponentsHorizontally(e.getComponentsFor(B.EAST_SOUTH_WEST),t),h=this.placeComponentsVertically(e.getComponentsFor(B.NORTH_SOUTH_WEST),t),g=this.placeComponentsVertically(e.getComponentsFor(B.NORTH_EAST_SOUTH),t),_=this.placeComponentsHorizontally(e.getComponentsFor(B.NORTH_EAST_SOUTH_WEST),t),v=Math.max(s.x,a.x,l.x,h.x),y=Math.max(r.x,n.x,i.x,_.x),b=f.x,x=Math.max(c.x,o.x,u.x,g.x),S=Math.max(s.y,r.y,c.y,p.y),C=Math.max(a.y,n.y,o.y,_.y),w=d.y,ee=Math.max(l.y,i.y,u.y,m.y);this.offsetGraphs(e.getComponentsFor(B.NONE),v+b,S+w),this.offsetGraphs(e.getComponentsFor(B.NORTH_EAST_SOUTH_WEST),v+b,S+w),this.offsetGraphs(e.getComponentsFor(B.NORTH),v+b,0),this.offsetGraphs(e.getComponentsFor(B.SOUTH),v+b,S+w+C),this.offsetGraphs(e.getComponentsFor(B.WEST),0,S+w),this.offsetGraphs(e.getComponentsFor(B.EAST),v+b+y,S+w),this.offsetGraphs(e.getComponentsFor(B.NORTH_EAST),v+b+y,0),this.offsetGraphs(e.getComponentsFor(B.SOUTH_WEST),0,S+w+C),this.offsetGraphs(e.getComponentsFor(B.EAST_SOUTH),v+b+y,S+w+C),this.offsetGraphs(e.getComponentsFor(B.EAST_WEST),0,S),this.offsetGraphs(e.getComponentsFor(B.NORTH_SOUTH),v,0),this.offsetGraphs(e.getComponentsFor(B.EAST_SOUTH_WEST),0,S+w+C),this.offsetGraphs(e.getComponentsFor(B.NORTH_EAST_SOUTH),v+b+y,0);let te={x:0,y:0};return te.x=Math.max(v+y+b+x,d.x,p.x,m.x),te.y=Math.max(S+C+w+ee,f.y,h.y,g.y),te}placeComponentsHorizontally(e,t){let n={x:0,y:0};for(let r of e)this.offsetGraph(r,n.x,0),n.x+=r.getSize().x+t,n.y=Math.max(n.y,r.getSize().y);return n.y>0&&(n.y+=t),n}placeComponentsVertically(e,t){let n={x:0,y:0};for(let r of e)this.offsetGraph(r,0,n.y),n.y+=r.getSize().y+t,n.x=Math.max(n.x,r.getSize().x);return n.x>0&&(n.x+=t),n}placeComponentsInRows(e,t){if(e.length===0)return{x:0,y:0};let n=0,r=0;for(let t of e){let e=t.getSize();n=Math.max(n,e.x),r+=e.x*e.y}n=Math.max(n,Math.sqrt(r));let i=0,a=0,o=0,s=t;for(let r of e){let e=r.getSize();i+e.x>n&&(i=0,a+=o+t,o=0),this.offsetGraph(r,i,a),s=Math.max(s,i+e.x),o=Math.max(o,e.y),i+=e.x+t}return{x:s+t,y:a+o+t}}},yo=class{split(t){if(t.getProperty(e.q)===`INCLUDE_CHILDREN`)return[t];let n=t.getProperty(e.Yt)!==!1,r=t.getProperty(e.Gn).has(`EXTERNAL_PORTS`),i=t.getProperty(e.Lt),a=!e.Lr.isOrderFixed(i);if(!n||r&&!a)return[t];let o=this.splitInner(t);return t.getProperty(e.y)!==e.Dn.NONE&&o.sort((e,t)=>bo(e)-bo(t)),o}splitInner(e){let t=/* @__PURE__ */ new Set,n=[];for(let r of e.getLayerlessNodes()){if(t.has(r))continue;let i=[];if(this.dfs(r,i,t),i.length>0){let t=new c;t.copyProperties(e),t.getPadding().left=e.getPadding().left,t.getPadding().top=e.getPadding().top,t.getPadding().right=e.getPadding().right,t.getPadding().bottom=e.getPadding().bottom;for(let e of i)t.getLayerlessNodes().push(e),e.setGraph(t);n.push(t)}}return n.length>0?n:[e]}dfs(e,t,n){if(!n.has(e)){n.add(e),t.push(e);for(let r of e.getPorts())for(let e of r.getConnectedPorts()){let r=e.getNode();r!==null&&this.dfs(r,t,n)}}}combine(t,n){if(n.getProperty(e.Gn).has(`EXTERNAL_PORTS`)){let r=n.getProperty(e.y);if(r===e.Dn.MODEL_ORDER){new mo().combine(t,n);return}if(r!==e.Dn.GROUP_MODEL_ORDER){new vo().combine(t,n);return}}if(n.getLayerlessNodes().length=0,t.length===1){let e=t[0];e!==n&&this.moveGraph(n,e,0,0);return}if(t.length===0)return;let r=n.getProperty(e.Qt),i=n.getProperty(e.y)===e.Dn.NONE?[...t].sort((e,t)=>e.getSize().x*e.getSize().y-t.getSize().x*t.getSize().y):[...t],a=0,o=0;for(let e of i){let t=e.getSize();a=Math.max(a,t.x),o+=t.x*t.y}let s=n.getProperty(e.h);a=Math.max(a,Math.sqrt(o)*s);let c=0,l=0,u=0,d=r;for(let e of i){let t=e.getSize();c+t.x>a&&(c=0,l+=u+r,u=0);let n=e.getOffset();this.offsetGraph(e,c+n.x,l+n.y),n.x=0,n.y=0,d=Math.max(d,c+t.x),u=Math.max(u,t.y),c+=t.x+r}if(n.getSize().x=d,n.getSize().y=l+u,t[0].getProperty(qa)){let e=new to;e.compact(t,n.getSize(),r);for(let n of t){let t=n.getOffset();t.x=e.getOffset().x,t.y=e.getOffset().y}let i=n.getSize();i.x=e.getGraphSize().x,i.y=e.getGraphSize().y}for(let e of i)this.moveGraph(n,e,0,0)}moveGraph(e,t,n,r){let i=n+t.getOffset().x,a=r+t.getOffset().y,o=/* @__PURE__ */ new Set;for(let n of t.getLayerlessNodes()){n.position.x+=i,n.position.y+=a;for(let e of n.getPorts())for(let t of e.getConnectedEdges())if(!o.has(t)){o.add(t);for(let e of t.getBendPoints())e.x+=i,e.y+=a}e.getLayerlessNodes().push(n),n.setGraph(e)}t.getOffset().x=0,t.getOffset().y=0}offsetGraph(e,t,n){let r=/* @__PURE__ */ new Set;for(let i of e.getLayerlessNodes()){i.position.x+=t,i.position.y+=n;for(let e of i.getPorts())for(let i of e.getConnectedEdges())if(!r.has(i)){r.add(i);for(let e of i.getBendPoints())e.x+=t,e.y+=n}}}};function bo(t){let n=2**53-1;for(let r of t.getLayerlessNodes())r.hasProperty(e.cr)&&(n=Math.min(n,r.getProperty(e.cr)));return n}function xo(e){let t=1/0,n=1/0,r=-1/0,i=-1/0;for(let a of e.getLayerlessNodes()){let e=a.getMargin(),o=a.position.x-e.left,s=a.position.y-e.top,c=a.position.x+a.size.x+e.right,l=a.position.y+a.size.y+e.bottom;for(let e of a.getPorts()){let t=e.getPosition(),n=e.getSize();o=Math.min(o,a.position.x+t.x),s=Math.min(s,a.position.y+t.y),c=Math.max(c,a.position.x+t.x+n.x),l=Math.max(l,a.position.y+t.y+n.y)}t=Math.min(t,o),n=Math.min(n,s),r=Math.max(r,c),i=Math.max(i,l)}Number.isFinite(t)&&(e.getSize().x=Math.max(e.getSize().x,r-t),e.getSize().y=Math.max(e.getSize().y,i-n))}const So=.001;function Co(t){let n=t.getProperty(e.hn),r=t.getProperty(e.In);if(r==null)return;let i=/* @__PURE__ */ new Set;for(let[a,o]of r){let r=[...o].sort((e,n)=>oa(e,n,t));if(r.length===0)continue;let s=r[0].getActualSource(),c=r[r.length-1].getActualTarget();if(s===null||c===null)continue;let l=s.getNode(),u;u=l===c.getNode()?l.getGraph()?.getParentNode()??null:zi(l,c.getNode());let d;if(u!==null)d=u.getNestedGraph();else for(d=l.getGraph();d.getParentNode()!==null;)d=d.getParentNode().getGraph();let f=wo(a,r);a.getBendPoints().length=0;let p=null;for(let o of r){let r=o.getGraph().getAllNodes().some(e=>e.getType()===`NORMAL`)?To(o.getGraph(),d):Hi(o.getGraph(),d),s=o.getNewEdge(),l=s.getBendPoints().map(e=>({x:e.x+r.x,y:e.y+r.y})),u=o.getGraph(),m=To(u,d),h=Hi(u,d),g=s.getSource().getNode(),_=s.getTarget().getNode(),v=t.getProperty(e.q)===`INCLUDE_CHILDREN`,y=t.getProperty(e.F),b=t=>{if(t===null||t.getType()!==`EXTERNAL_PORT`)return!1;let n=t.getProperty(e.Un);return y===`DOWN`||y===`UP`?n===`NORTH`||n===`SOUTH`:n===`WEST`||n===`EAST`},x=e=>e!==null&&e.getType()===`EXTERNAL_PORT`?v&&b(e)?m:h:m,S=x(g),C=x(_),w=s.getSource().getAbsoluteAnchor(),ee=s.getTarget().getAbsoluteAnchor(),te={x:w.x+S.x,y:w.y+S.y},T={x:ee.x+C.x,y:ee.y+C.y};if(p!==null){let e=l.length>0?l[0]:T,t=Math.abs(p.x-e.x)>So,r=Math.abs(p.y-e.y)>So;(!n&&t&&r||n&&(t||r))&&a.getBendPoints().push({...te})}if(a.getBendPoints().push(...l),p=l.length>0?l[l.length-1]:te,f!==null){let t=s.getProperty(e.nt);if(t!=null)for(let e of t)f.push({x:e.x+r.x,y:e.y+r.y})}if(o.getActualTarget()===c){let t=c.getNode(),n=t.getGraph(),r=t.getType()===`EXTERNAL_PORT`?Hi(n,d):To(n,d);a.setProperty(e.Ar,r)}for(let e of[...s.getLabels()])e.position.x+=r.x,e.position.y+=r.y,a.getLabels().push(e);s.getLabels().length=0,i.add(s)}a.setSource(s),a.setTarget(c)}for(let e of i)e.setSource(null),e.setTarget(null)}function wo(t,n){let r=n.some(t=>{let n=t.getNewEdge().getProperty(e.nt);return n!=null&&n.length>0}),i=t.getProperty(e.nt);return r?i==null?(i=[],t.setProperty(e.nt,i)):i.length=0:i!=null&&(t.setProperty(e.nt,null),i=null),i}function To(e,t){let n={x:0,y:0},r=e;for(;r!==null&&r!==t;){let e=r.getParentNode();if(e===null)break;n.x+=e.position.x,n.y+=e.position.y,r=e.getGraph()}return n}const Eo=/* @__PURE__ */ new WeakMap;var Do=class{process(t){let n=[],r=[...t.getLayerlessNodes()];for(let e of r)if(this.isRelevantNode(e)){this.hide(e),n.push(e);let r=t.getLayerlessNodes().indexOf(e);r!==-1&&t.getLayerlessNodes().splice(r,1)}n.length>0&&t.setProperty(e.Jn,n)}isRelevantNode(e){let t=e.getLayerConstraint();return t===`FIRST_SEPARATE`||t===`LAST_SEPARATE`}hide(e){this.ensureNoInacceptableEdges(e);for(let t of[...e.getConnectedEdges()])this.hideEdge(e,t)}hideEdge(t,n){let r=n.getSource().getNode()===t,i=r?n.getTarget():n.getSource();r?n.setTarget(null):n.setSource(null),n.setProperty(e.pr,i),this.updateOppositeNodeLayerConstraints(t,i.getNode())}updateOppositeNodeLayerConstraints(e,t){if(t.getLayerConstraint()!==null)return;let n=Eo.get(t)??`NONE`,r=e.getLayerConstraint()??`NONE`,i=this.combine(n,r);if(Eo.set(t,i),!(t.getConnectedEdges().length>0))switch(i){case`FIRST_SEPARATE`:t.setLayerConstraint(`FIRST`);break;case`LAST_SEPARATE`:t.setLayerConstraint(`LAST`)}}combine(e,t){return e===`NONE`?t===`FIRST_SEPARATE`?`FIRST_SEPARATE`:`LAST_SEPARATE`:e===`FIRST_SEPARATE`?t===`FIRST_SEPARATE`?`FIRST_SEPARATE`:`BOTH`:e===`LAST_SEPARATE`?t===`FIRST_SEPARATE`?`BOTH`:`LAST_SEPARATE`:`BOTH`}ensureNoInacceptableEdges(e){let t=e.getLayerConstraint();if(t===`FIRST_SEPARATE`){for(let t of e.getIncomingEdges())if(!this.isAcceptableIncidentEdge(t))throw Error(`FIRST_SEPARATE node must not have incoming edges`)}else if(t===`LAST_SEPARATE`){for(let t of e.getOutgoingEdges())if(!this.isAcceptableIncidentEdge(t))throw Error(`LAST_SEPARATE node must not have outgoing edges`)}}isAcceptableIncidentEdge(e){let t=e.getSource().getNode(),n=e.getTarget().getNode();return t!==null&&n!==null&&t.getType()===`EXTERNAL_PORT`&&n.getType()===`EXTERNAL_PORT`}};function Oo(t){let n=t.getLayers();if(n.length>0){let e=n[0],r=n[n.length-1];ko(t,e,r)}let r=t.getProperty(e.Jn);if(r!==void 0&&r.length>0){let e=new w(t),i=new w(t);Ao(r,e,i),e.getNodes().length>0&&n.unshift(e),i.getNodes().length>0&&n.push(i)}for(let e=n.length-1;e>=0;e--)n[e].getNodes().length===0&&n.splice(e,1)}function ko(e,t,n){for(let r of[...e.getLayers()])for(let e of[...r.getNodes()]){let r=e.getLayerConstraint();r===`FIRST`?e.setLayer(t):r===`LAST`&&e.setLayer(n)}let r=e.getLayers();for(let e=r.length-1;e>=0;e--)r[e].getNodes().length===0&&r.splice(e,1)}function Ao(t,n,r){for(let i of t){let t=i.getLayerConstraint();t===`FIRST_SEPARATE`?i.setLayer(n):t===`LAST_SEPARATE`&&i.setLayer(r);for(let t of i.getConnectedEdges()){if(t.getSource()!==null&&t.getTarget()!==null)continue;let n=t.getTarget()===null,r=t.getProperty(e.pr);n?t.setTarget(r):t.setSource(r)}}}var jo=class{start=0;end=0;nodes=[]};function Mo(e,t){let n=[];for(let t of e.getLayerlessNodes()){let e=t.getPosition().x,r=Math.max(e+1,t.getPosition().x+t.size.x),i=null,a=0;for(;a<n.length;a++){let o=n[a];if(o.start>=r)break;o.end>e&&(i===null?(o.nodes.push(t),o.start=Math.min(o.start,e),o.end=Math.max(o.end,r),i=o):(i.nodes.push(...o.nodes),i.end=Math.max(i.end,o.end),n.splice(a,1),a--))}if(i===null){let i=new jo;i.start=e,i.end=r,i.nodes.push(t),n.splice(a,0,i)}}let r=e.getLayers(),i=0;for(let t of n){let n=new w(e);n.id=i++,r.push(n);for(let e of t.nodes)e.setLayer(n),e.id=0}for(let t of e.getLayerlessNodes()){if(t.id!==0)continue;let n=No(t,e);for(;n.size>0;){let t=n.values().next().value;n.delete(t);for(let r of No(t,e))n.add(r)}}for(let e=r.length-1;e>=0;e--)r[e].getNodes().length===0&&r.splice(e,1);e.getLayerlessNodes().length=0}function No(e,t){e.id=1;let n=e.getLayer(),r=/* @__PURE__ */ new Set;for(let i of e.getPorts(`OUTPUT`))for(let a of i.getOutgoingEdges()){let i=a.getTarget().getNode();if(i===e)continue;let o=i.getLayer();if(o!==null&&n!==null&&o.id<=n.id){let e=n.id+1,a;e===t.getLayers().length?(a=new w(t),a.id=e,t.getLayers().push(a)):a=t.getLayers()[e],i.setLayer(a),r.add(i)}}return r}var Po=class{sources=[];visited=[];active=[];edgesToBeReversed=[];process(t,n){n.begin(`Depth-first cycle removal`,1);let r=t.getLayerlessNodes(),i=r.length;this.sources=[],this.visited=Array(i).fill(!1),this.active=Array(i).fill(!1),this.edgesToBeReversed=[];let a=0;for(let e of r)e.id=a,e.getIncomingEdges().length===0&&this.sources.push(e),a++;for(let e of this.sources)this.dfs(e);for(let e=0;e<i;e++)this.visited[e]||this.dfs(r[e]);for(let n of this.edgesToBeReversed)n.reverse(t,!0),t.setProperty(e.Ln,!0);this.sources=[],this.visited=[],this.active=[],this.edgesToBeReversed=[],n.done()}dfs(e){if(!this.visited[e.id]){this.visited[e.id]=!0,this.active[e.id]=!0;for(let t of e.getOutgoingEdges()){if(t.isSelfLoop())continue;let e=t.getTarget().getNode();this.active[e.id]?this.edgesToBeReversed.push(t):this.dfs(e)}this.active[e.id]=!1}}},Fo=class{sources=/* @__PURE__ */ new Set;sinks=/* @__PURE__ */ new Set;visited=[];bfsQueue=[];edgesToBeReversed=[];graph=null;process(t,n){n.begin(`Breadth-first cycle removal`,1),this.graph=t;let r=t.getLayerlessNodes();this.bfsQueue=[],this.sources=/* @__PURE__ */ new Set,this.sinks=/* @__PURE__ */ new Set,this.visited=Array(r.length).fill(!1),this.edgesToBeReversed=[];let i=0;for(let e of r)e.id=i,e.getIncomingEdges().length===0&&this.sources.add(e),e.getOutgoingEdges().length===0&&this.sinks.add(e),i++;for(let e of this.sources)this.bfsQueue.push(e),this.bfsLoop();this.bfsLoop();let a=!0;for(;a;){a=!1;for(let e=0;e<r.length;e++)if(!this.visited[e]){this.bfsQueue.push(r[e]),a=!0;break}this.bfsLoop()}for(let n of this.edgesToBeReversed)n.reverse(t,!0),t.setProperty(e.Ln,!0);this.sources=/* @__PURE__ */ new Set,this.visited=[],this.bfsQueue=[],this.edgesToBeReversed=[],n.done()}bfsLoop(){for(;this.bfsQueue.length>0;)this.bfs(this.bfsQueue.shift())}bfs(t){if(this.visited[t.id])return;this.visited[t.id]=!0;let n=/* @__PURE__ */ new Map,r=this.graph.getProperty(e.b)===`ENFORCED`;for(let i of t.getOutgoingEdges()){let t=i.getTarget().getNode();if(!t.hasProperty(e.cr))n.set(2147483647-n.size,[i]);else{let a=0;a=r?this.graph.getProperty(e.sr)*t.getProperty(e.w)+t.getProperty(e.cr):t.getProperty(e.cr);let o=n.get(a);o===void 0?n.set(a,[i]):o.push(i)}}let i=[...n.keys()].sort((e,t)=>e-t);for(let e of i){let r=n.get(e),i=r[0];if(i.isSelfLoop())continue;let a=i.getTarget().getNode();this.visited[a.id]&&!this.sources.has(t)&&!this.sinks.has(a)?this.edgesToBeReversed.push(...r):this.bfsQueue.push(a)}}},Io=class{sources=[];visited=[];active=[];edgesToBeReversed=[];graph=null;process(t,n){n.begin(`Depth-first cycle removal`,1),this.graph=t;let r=t.getLayerlessNodes(),i=r.length;this.sources=[],this.visited=Array(i).fill(!1),this.active=Array(i).fill(!1),this.edgesToBeReversed=[];let a=0;for(let e of r)e.id=a,e.getIncomingEdges().length===0&&this.sources.push(e),a++;for(let e of this.sources)this.dfs(e);for(let e=0;e<i;e++)this.visited[e]||this.dfs(r[e]);for(let n of this.edgesToBeReversed)n.reverse(t,!0),t.setProperty(e.Ln,!0);this.sources=[],this.visited=[],this.active=[],this.edgesToBeReversed=[],n.done()}dfs(t){if(this.visited[t.id])return;this.visited[t.id]=!0,this.active[t.id]=!0;let n=/* @__PURE__ */ new Map,r=this.graph.getProperty(e.b)===`ENFORCED`;for(let i of t.getOutgoingEdges()){let t=i.getTarget().getNode();if(!t.hasProperty(e.cr))n.set(2147483647-n.size,[i]);else{let a=0;a=r?this.graph.getProperty(e.sr)*t.getProperty(e.w)+t.getProperty(e.cr):t.getProperty(e.cr);let o=n.get(a);o===void 0?n.set(a,[i]):o.push(i)}}let i=[...n.keys()].sort((e,t)=>e-t);for(let e of i){let t=n.get(e),r=t[0];if(r.isSelfLoop())continue;let i=r.getTarget().getNode();this.active[i.id]?this.edgesToBeReversed.push(...t):this.dfs(i)}this.active[t.id]=!1}},Lo=class{edgesToBeReversed;stronglyConnectedComponents;nodeToSCCID;index=0;stack=[];tarjanId=/* @__PURE__ */ new Map;tarjanLowlink=/* @__PURE__ */ new Map;tarjanOnStack=/* @__PURE__ */ new Map;constructor(e,t,n){this.edgesToBeReversed=e,this.stronglyConnectedComponents=t,this.nodeToSCCID=n}tarjan(e){this.index=0,this.stack=[];for(let t of e.getLayerlessNodes())(this.tarjanId.get(t)??-1)===-1&&(this.stronglyConnected(t),this.stack.length=0)}stronglyConnected(e){this.tarjanId.set(e,this.index),this.tarjanLowlink.set(e,this.index),this.index++,this.stack.push(e),this.tarjanOnStack.set(e,!0);for(let t of e.getConnectedEdges()){if(t.getSource().getNode()!==e&&!this.edgesToBeReversed.includes(t)||t.getSource().getNode()===e&&this.edgesToBeReversed.includes(t))continue;let n=t.getTarget().getNode()===e?t.getSource().getNode():t.getTarget().getNode();(this.tarjanId.get(n)??-1)===-1?(this.stronglyConnected(n),this.tarjanLowlink.set(e,Math.min(this.tarjanLowlink.get(e),this.tarjanLowlink.get(n)))):this.tarjanOnStack.get(n)&&this.tarjanLowlink.set(e,Math.min(this.tarjanLowlink.get(e),this.tarjanId.get(n)))}if(this.tarjanLowlink.get(e)===this.tarjanId.get(e)){let t=/* @__PURE__ */ new Set,n;do n=this.stack.pop(),this.tarjanOnStack.set(n,!1),t.add(n);while(e!==n);if(t.size>1){let e=this.stronglyConnectedComponents.length;this.stronglyConnectedComponents.push(t);for(let n of t)this.nodeToSCCID.set(n,e)}}}resetTarjan(e){for(let t of e.getLayerlessNodes())this.tarjanOnStack.set(t,!1),this.tarjanLowlink.set(t,-1),this.tarjanId.set(t,-1),this.stack.length=0}},Ro=class{stronglyConnectedComponents=[];nodeToSCCID=/* @__PURE__ */ new Map;revEdges=[];graph=null;process(t,n){if(n.begin(`Model order cycle breaking`,1),this.graph=t,this.revEdges=[],!t.hasProperty(e.sr))throw TypeError(`Cannot invoke "java.lang.Integer.intValue()" because the return value of "org.eclipse.elk.alg.layered.graph.LGraph.getProperty(org.eclipse.elk.graph.properties.IProperty)" is null`);let r=Math.max(t.getLayerlessNodes().length,t.getProperty(e.sr)),i=r*t.getProperty(e.jn);for(;;){let n=new Lo(this.revEdges,this.stronglyConnectedComponents,this.nodeToSCCID);if(n.resetTarjan(t),n.tarjan(t),this.stronglyConnectedComponents.length===0)break;this.findNodes(r,i);for(let n of this.revEdges)n.reverse(t,!1),t.setProperty(e.Ln,!0);this.stronglyConnectedComponents.length=0,this.nodeToSCCID.clear(),this.revEdges.length=0}n.done()}findNodes(t,n){for(let r=0;r<this.stronglyConnectedComponents.length;r++){let i=this.stronglyConnectedComponents[r],a=null,o=new y,s=-(2**53-1),c=this.graph.getProperty(e.b)===`ENFORCED`;for(let e of i)if(a===null)a=e,s=c?o.computeConstraintGroupModelOrder(e,n,t):o.computeConstraintModelOrder(e,t);else{let r=c?o.computeConstraintGroupModelOrder(e,n,t):o.computeConstraintModelOrder(e,t);s<r&&(a=e,s=r)}for(let e of a.getOutgoingEdges())i.has(e.getTarget().getNode())&&this.revEdges.push(e)}}},zo=class extends Ro{findNodes(t,n){for(let r=0;r<this.stronglyConnectedComponents.length;r++){let i=this.stronglyConnectedComponents[r];if(i.size<=1)continue;let a=null,o=null,s=2**53-1,c=-(2**53-1),l=this.graph.getProperty(e.b)===`ENFORCED`,u=new y;for(let e of i)if(a===null||o===null)a=e,s=l?u.computeConstraintGroupModelOrder(e,n,t):u.computeConstraintModelOrder(e,t),o=e,c=s;else{let r=l?u.computeConstraintGroupModelOrder(e,n,t):u.computeConstraintModelOrder(e,t);s>r&&(a=e,s=r),c<r&&(o=e,c=r)}let d=a.getIncomingEdges(),f=o.getOutgoingEdges();if(d.length>f.length)for(let e of d)i.has(e.getSource().getNode())&&this.revEdges.push(e);else for(let e of f)i.has(e.getTarget().getNode())&&this.revEdges.push(e)}}};const Bo=new e.ai(`org.eclipse.elk.layered.considerModelOrder.groupModelOrder.cbPreferredSourceId`,0),Vo=new e.ai(`org.eclipse.elk.layered.considerModelOrder.groupModelOrder.cbPreferredTargetId`,0);var Ho=class extends Ro{findNodes(t,n){for(let r=0;r<this.stronglyConnectedComponents.length;r++){let i=this.stronglyConnectedComponents[r];if(i.size<=1)continue;let a=null,o=null,s=2**53-1,c=-(2**53-1),l=this.graph.getProperty(e.b)===`ENFORCED`,u=new y;for(let e of i)if(a===null||o===null)a=e,s=l?u.computeConstraintGroupModelOrder(e,n,t):u.computeConstraintModelOrder(e,t),o=e,c=s;else{let r=l?u.computeConstraintGroupModelOrder(e,n,t):u.computeConstraintModelOrder(e,t);s>r&&(a=e,s=r),c<r&&(o=e,c=r)}let d=this.graph.getProperty(Bo),f=this.graph.getProperty(Vo);if(a.getProperty(e.w)===d)for(let e of a.getIncomingEdges())i.has(e.getSource().getNode())&&this.revEdges.push(e);else if(o.getProperty(e.w)===f)for(let e of o.getOutgoingEdges())i.has(e.getSource().getNode())&&this.revEdges.push(e);else{let e=a.getIncomingEdges(),t=o.getOutgoingEdges();if(e.length>t.length)for(let t of e)i.has(t.getSource().getNode())&&this.revEdges.push(t);else for(let e of t)i.has(e.getTarget().getNode())&&this.revEdges.push(e)}}}},Uo=class{compare;heap=[];constructor(e){this.compare=e}isEmpty(){return this.heap.length===0}push(e){this.heap.push(e),this.siftUp(this.heap.length-1)}poll(){if(this.heap.length===0)return;let e=this.heap[0],t=this.heap.pop();return this.heap.length>0&&(this.heap[0]=t,this.siftDown(0)),e}siftUp(e){let t=this.heap[e];for(;e>0;){let n=e-1>>1,r=this.heap[n];if(this.compare(t,r)>=0)break;this.heap[e]=r,e=n}this.heap[e]=t}siftDown(e){let t=this.heap.length,n=this.heap[e];for(;;){let r=2*e+1;if(r>=t)break;let i=this.heap[r],a=r+1;if(a<t){let e=this.heap[a];this.compare(i,e)>0&&(r=a,i=e)}if(this.compare(n,i)<=0)break;this.heap[e]=i,e=r}this.heap[e]=n}},Wo=class{nodeMark=[];edgeMark=[];inDeg=[];outDeg=[];topoOrd=[];inTopo=/* @__PURE__ */ new Map;process(t,n){if(n.begin(`Coffman-Graham Layering`,1),t.getLayerlessNodes().length===0){n.done();return}let r=t.getProperty(e.rt),i=0,a=0;for(let e of t.getLayerlessNodes()){e.id=i++;for(let t of e.getOutgoingEdges())t.id=a++}this.nodeMark=Array(i).fill(!1),this.edgeMark=Array(a).fill(!1),this.inDeg=Array(i).fill(0),this.outDeg=Array(i).fill(0),this.topoOrd=Array(i).fill(0),this.inTopo.clear(),this.transitiveReduction(t);let o=new Uo((e,t)=>this.compareNodesInTopo(e,t));for(let e of t.getLayerlessNodes()){for(let t of e.getIncomingEdges())this.edgeMark[t.id]||this.inDeg[e.id]++;this.inDeg[e.id]===0&&o.push(e)}let s=0;for(;!o.isEmpty();){let e=o.poll();this.topoOrd[e.id]=s++;for(let t of e.getOutgoingEdges()){if(this.edgeMark[t.id])continue;let n=t.getTarget().getNode();this.inDeg[n.id]--;let r=this.inTopo.get(n)??[];r.push(this.topoOrd[e.id]),this.inTopo.set(n,r),this.inDeg[n.id]===0&&o.push(n)}}let c=new Uo((e,t)=>{let n=this.topoOrd[e.id],r=this.topoOrd[t.id];return n>r?-1:+(n<r)});for(let e of t.getLayerlessNodes()){for(let t of e.getOutgoingEdges())this.edgeMark[t.id]||this.outDeg[e.id]++;this.outDeg[e.id]===0&&c.push(e)}let l=[],u=this.createLayer(t,l);for(;!c.isEmpty();){let e=c.poll();(this.isLayerFull(u,r)||!this.canAdd(e,u))&&(u=this.createLayer(t,l)),e.setLayer(u);for(let t of e.getIncomingEdges()){if(this.edgeMark[t.id])continue;let e=t.getSource().getNode();this.outDeg[e.id]--,this.outDeg[e.id]===0&&c.push(e)}}for(let e=l.length-1;e>=0;--e)t.getLayers().push(l[e]);t.getLayerlessNodes().length=0,n.done()}isLayerFull(e,t){return e.getNodes().length>=t}canAdd(e,t){for(let n of e.getOutgoingEdges())if(n.getTarget().getNode().getLayer()===t)return!1;return!0}createLayer(e,t){let n=new w(e);return t.push(n),n}compareNodesInTopo(e,t){let n=this.inTopo.get(e)??[],r=this.inTopo.get(t)??[],i=n.length-1,a=r.length-1;for(;i>=0&&a>=0;){let e=n[i],t=r[a];if(e!==t)return e<t?-1:1;i--,a--}return n.length===0&&r.length===0?e.id<t.id?-1:+(e.id>t.id):n.length===0?-1:1}transitiveReduction(e){for(let t of e.getLayerlessNodes()){this.nodeMark.fill(!1);for(let e of t.getOutgoingEdges())this.dfs(t,e.getTarget().getNode())}}dfs(e,t){if(!this.nodeMark[t.id]){for(let n of t.getOutgoingEdges()){let t=n.getTarget().getNode();for(let n of t.getIncomingEdges())n.getSource().getNode()===e&&(this.edgeMark[n.id]=!0);this.dfs(e,t)}this.nodeMark[t.id]=!0}}},Go=class{layeredGraph;process(t,n){n.begin(`Breadth first model order layering`,1),this.layeredGraph=t;let r=[];for(let e of this.layeredGraph.getLayerlessNodes())e.getType()===`NORMAL`&&r.push(e);r.sort((t,n)=>{if(t.hasProperty(e.cr)&&n.hasProperty(e.cr))return t.getProperty(e.cr)-n.getProperty(e.cr);throw Error(`The BF model order layer assigner requires all real nodes to have a model order.`)});let i=!0,a=new w(this.layeredGraph),o=null;this.layeredGraph.getLayers().push(a);for(let e of r)if(i)e.setLayer(a),i=!1;else{for(let t of e.getIncomingEdges())(t.getSource().getNode().getType()===`NORMAL`&&t.getSource().getNode().getLayer()===a||t.getSource().getNode().getType()===`LABEL`&&t.getSource().getNode().getIncomingEdges()[0].getSource().getNode().getLayer()===a)&&(o=new w(this.layeredGraph),this.layeredGraph.getLayers().push(o),a=new w(this.layeredGraph),this.layeredGraph.getLayers().push(a));for(let t of e.getIncomingEdges())t.getSource().getNode().getType()===`LABEL`&&t.getSource().getNode().getLayer()===null&&t.getSource().getNode().setLayer(o);e.setLayer(a)}this.layeredGraph.getLayerlessNodes().length=0;let s=[];for(let e of this.layeredGraph.getLayers())e.getNodes().length===0&&s.push(e);for(let e of s){let t=this.layeredGraph.getLayers().indexOf(e);t!==-1&&this.layeredGraph.getLayers().splice(t,1)}let c=0;for(let e of this.layeredGraph.getLayers())e.id=c,c++;n.done()}},Ko=class{layeredGraph;currentLayer;currentLayerId=0;currentDummyLayer=null;nodesToPlace=[];maxToPlace=0;process(t,n){n.begin(`Depth first model order layering`,1),this.layeredGraph=t;let r=[];for(let e of this.layeredGraph.getLayerlessNodes())e.getType()===`NORMAL`&&r.push(e);r.sort((t,n)=>{if(t.hasProperty(e.cr)&&n.hasProperty(e.cr))return t.getProperty(e.cr)-n.getProperty(e.cr);throw Error(`The DF model order layer assigner requires all real nodes to have a model order.`)});let i=!0;this.currentLayer=new w(this.layeredGraph),this.currentDummyLayer=null,this.layeredGraph.getLayers().push(this.currentLayer),this.currentLayer.id=0,this.currentLayerId=0,this.nodesToPlace=[];for(let e of r)if(i)e.setLayer(this.currentLayer),i=!1;else if(this.isConnectedToCurrentLayer(e)){let t=this.currentLayerId;t=this.getMaxConnectedLayer(t,e);let n=t+2,r=t-this.currentLayerId;if(this.nodesToPlace.length>0){if(r>0){for(let e of this.nodesToPlace)e.id+=t-this.maxToPlace;this.placeNodesToPlace(),this.nodesToPlace=[],this.addNodeToLayer(n,e)}else{this.nodesToPlace.push(e),e.id=n,this.maxToPlace=Math.max(this.maxToPlace,n);for(let t of e.getIncomingEdges())t.getSource().getNode().getLayer()===null&&t.getSource().getNode().getType()===`LABEL`&&(this.nodesToPlace.push(t.getSource().getNode()),t.getSource().getNode().id=n-1);this.currentLayerId=n}}else this.addNodeToLayer(n,e)}else{this.placeNodesToPlace(),this.nodesToPlace=[];let t=0;if(e.getIncomingEdges().length===0)this.nodesToPlace.push(e),e.id=0,this.maxToPlace=Math.max(this.maxToPlace,0),this.currentLayer=this.layeredGraph.getLayers()[0],this.currentLayerId=0;else{let n=0;n=this.getMaxConnectedLayer(n,e),t=n+2,this.addNodeToLayer(t,e)}}this.nodesToPlace.length>0&&this.placeNodesToPlace(),this.layeredGraph.getLayerlessNodes().length=0;let a=[];for(let e of this.layeredGraph.getLayers())e.getNodes().length===0&&a.push(e);for(let e of a){let t=this.layeredGraph.getLayers().indexOf(e);t!==-1&&this.layeredGraph.getLayers().splice(t,1)}let o=0;for(let e of this.layeredGraph.getLayers())e.id=o,o++;n.done()}isConnectedToCurrentLayer(e){for(let t of e.getIncomingEdges()){let e,n;if(this.nodesToPlace.length===0){if(e=t.getSource().getNode().getType()===`NORMAL`&&t.getSource().getNode().getLayer()!==null&&t.getSource().getNode().getLayer().id===this.currentLayerId,t.getSource().getNode().getIncomingEdges().length>0){let e=t.getSource().getNode().getIncomingEdges()[0].getSource().getNode().getLayer();n=t.getSource().getNode().getType()===`LABEL`&&e!==null&&e.id===this.currentLayerId}else n=!1}else e=t.getSource().getNode().getType()===`NORMAL`&&t.getSource().getNode().id===this.currentLayerId,n=t.getSource().getNode().getType()===`LABEL`&&t.getSource().getNode().getIncomingEdges()[0].getSource().getNode().id===this.currentLayerId;if(e||n)return!0}return!1}addNodeToLayer(e,t){e<this.layeredGraph.getLayers().length?(this.currentLayer=this.layeredGraph.getLayers()[e],this.currentDummyLayer=this.layeredGraph.getLayers()[e-1],this.currentLayerId=e):(this.currentDummyLayer=new w(this.layeredGraph),this.currentDummyLayer.id=e-1,this.layeredGraph.getLayers().push(this.currentDummyLayer),this.currentLayer=new w(this.layeredGraph),this.currentLayer.id=e,this.layeredGraph.getLayers().push(this.currentLayer),this.currentLayerId=e),t.setLayer(this.currentLayer);for(let e of t.getIncomingEdges())e.getSource().getNode().getLayer()===null&&e.getSource().getNode().getType()===`LABEL`&&e.getSource().getNode().setLayer(this.currentDummyLayer)}getMaxConnectedLayer(e,t){let n=e;for(let e of t.getIncomingEdges())e.getSource().getNode().getLayer()!==null&&(n=Math.max(n,e.getSource().getNode().getLayer().id));return n}placeNodesToPlace(){this.maxToPlace=0;for(let e of this.nodesToPlace){if(e.id>=this.layeredGraph.getLayers().length){let t=new w(this.layeredGraph);t.id=e.id-1,this.layeredGraph.getLayers().push(t);let n=new w(this.layeredGraph);n.id=e.id,this.layeredGraph.getLayers().push(n)}e.setLayer(this.layeredGraph.getLayers()[e.id])}}},qo=class t{static UPPERBOUND_ON_WIDTH_RANGE={lower:1,upper:4};static COMPENSATOR_RANGE={lower:1,upper:2};dummySize=0;minimumNodeSize=0;normSize=[];avgSize=0;inDegree=[];outDegree=[];lastMaxWidth=0;process(n,r){r.begin(`MinWidth layering`,1);let i=n.getLayers(),a=n.getLayerlessNodes(),o=n.getProperty(e.ot),s=n.getProperty(e.st);this.dummySize=n.getProperty(e.$t),this.minimumNodeSize=1/0;for(let e of a){if(e.getType()!==`NORMAL`)continue;let t=e.getSize().y;this.minimumNodeSize=Math.min(this.minimumNodeSize,t)}this.minimumNodeSize=Math.max(1,this.minimumNodeSize);let c=a.length;this.inDegree=Array(c).fill(0),this.outDegree=Array(c).fill(0),this.normSize=Array(c).fill(0);let l=0;this.avgSize=0;for(let e of a)e.id=l++,this.inDegree[e.id]=this.countEdgesExceptSelfLoops(e.getIncomingEdges()),this.outDegree[e.id]=this.countEdgesExceptSelfLoops(e.getOutgoingEdges()),this.normSize[e.id]=e.getSize().y/this.minimumNodeSize,this.avgSize+=this.normSize[e.id];this.dummySize/=this.minimumNodeSize,this.avgSize/=c;let u=this.precalcSuccessors(a);a.sort((e,t)=>{let n=this.outDegree[e.id],r=this.outDegree[t.id];return n<r?1:n===r?0:-1});let d=1/0,f=2**53-1,p=null,m=o,h=o,g=s,_=s;o<0&&(m=t.UPPERBOUND_ON_WIDTH_RANGE.lower,h=t.UPPERBOUND_ON_WIDTH_RANGE.upper),s<0&&(g=t.COMPENSATOR_RANGE.lower,_=t.COMPENSATOR_RANGE.upper);for(let e=m;e<=h;e++)for(let t=g;t<=_;t++){let n=this.computeMinWidthLayering(e,t,a,u),r=n.width,i=n.layers,o=i.length;(r<d||r===d&&o<f)&&(d=r,f=o,p=i)}for(let e of p){let t=new w(n);for(let n of e)n.setLayer(t);i.push(t)}this.lastMaxWidth=d,i.reverse(),a.length=0,r.done()}precalcSuccessors(e){let t=[];for(let n of e){let e=/* @__PURE__ */ new Set;for(let t of n.getOutgoingEdges())this.isSelfLoop(t)||e.add(t.getTarget().getNode());t.push(e)}return t}computeMinWidthLayering(e,t,n,r){let i=[],a=new Set(n),o=e*this.avgSize,s=0,c=0,l=/* @__PURE__ */ new Set,u=/* @__PURE__ */ new Set,d=[],f=0,p=0,m=0,h=0,g=0,_=0;for(;a.size>0;){let e=this.selectNode(a,r,u);if(e!==null&&(a.delete(e),d.push(e),l.add(e),c=this.outDegree[e.id],f+=this.normSize[e.id]-c*this.dummySize,s=this.inDegree[e.id],p+=s*this.dummySize,_+=c*this.dummySize,h+=this.normSize[e.id]),e===null||a.size===0||f>=o&&this.normSize[e.id]>c*this.dummySize||p>=t*o){i.push(d),d=[];for(let e of l)u.add(e);l.clear(),g-=_,m=Math.max(m,g*this.dummySize+h),g+=p,f=p,p=0,_=0,h=0}}return{width:m,layers:i}}selectNode(e,t,n){for(let r of e)if(this.containsAll(n,t[r.id]))return r;return null}containsAll(e,t){for(let n of t)if(!e.has(n))return!1;return!0}countEdgesExceptSelfLoops(e){let t=0;for(let n of e)this.isSelfLoop(n)||t++;return t}isSelfLoop(e){return e.getSource().getNode()===e.getTarget().getNode()}},Jo=class{widthCurrent=0;widthUp=0;maxWidth=0;currentGraph;upperLayerInfluence=0;sortedLayerlessNodes=[];alreadyPlacedNodes=/* @__PURE__ */ new Set;alreadyPlacedInOtherLayers=/* @__PURE__ */ new Set;tempLayerlessNodes=[];successors=[];outDegree=[];remainingOutGoing=[];inDegree=[];selectedNode=null;minimumNodeSize=0;maximumNodeSize=0;normSize=[];dummySize=0;process(t,n){if(n.begin(`StretchWidth layering`,1),t.getLayerlessNodes().length===0){n.done();return}this.currentGraph=t,this.widthCurrent=0,this.widthUp=0,this.minimumNodeSize=1/0,this.maximumNodeSize=-1/0,this.dummySize=t.getProperty(e.$t),this.computeSortedNodes(),this.computeSuccessors(),this.computeDegrees(),this.minMaxNodeSize(),this.computeNormalizedSize(),this.minimumNodeSize=Math.max(1,this.minimumNodeSize),this.maximumNodeSize=Math.max(1,this.maximumNodeSize),this.dummySize/=this.minimumNodeSize,this.maxWidth=this.maximumNodeSize/this.minimumNodeSize,this.upperLayerInfluence=this.getAverageOutDegree();let r=new w(this.currentGraph);for(this.currentGraph.getLayers().push(r),this.tempLayerlessNodes=[...this.sortedLayerlessNodes],this.remainingOutGoing=[...this.outDegree];this.tempLayerlessNodes.length>0;)if(this.selectedNode=this.selectNode(),this.selectedNode===null||this.conditionGoUp()&&this.alreadyPlacedNodes.size>0){this.updateOutGoing(r),r=new w(this.currentGraph),this.currentGraph.getLayers().push(r);for(let e of this.alreadyPlacedNodes)this.alreadyPlacedInOtherLayers.add(e);this.alreadyPlacedNodes.clear(),this.widthCurrent=this.widthUp,this.widthUp=0}else this.conditionGoUp()?(this.currentGraph.getLayers().length=0,r=new w(this.currentGraph),this.currentGraph.getLayers().push(r),this.widthCurrent=0,this.widthUp=0,this.alreadyPlacedNodes.clear(),this.alreadyPlacedInOtherLayers.clear(),this.maxWidth++,this.tempLayerlessNodes=[...this.sortedLayerlessNodes],this.remainingOutGoing=[...this.outDegree]):(this.selectedNode.setLayer(r),this.tempLayerlessNodes.splice(this.tempLayerlessNodes.indexOf(this.selectedNode),1),this.alreadyPlacedNodes.add(this.selectedNode),this.widthCurrent=this.widthCurrent-this.outDegree[this.selectedNode.id]*this.dummySize+this.normSize[this.selectedNode.id],this.widthUp+=this.inDegree[this.selectedNode.id]*this.dummySize);t.getLayerlessNodes().length=0,t.getLayers().reverse(),n.done()}conditionGoUp(){let e=this.widthCurrent-this.outDegree[this.selectedNode.id]*this.dummySize+this.normSize[this.selectedNode.id]>this.maxWidth,t=this.widthUp+this.inDegree[this.selectedNode.id]*this.dummySize>this.maxWidth*this.upperLayerInfluence*this.dummySize;return e||t}selectNode(){for(let e of this.tempLayerlessNodes)if(this.remainingOutGoing[e.id]<=0)return e;return null}computeSortedNodes(){let e=this.currentGraph.getLayerlessNodes();this.sortedLayerlessNodes=[...e];for(let t of e)t.id=this.getRank(t);this.sortedLayerlessNodes.sort((e,t)=>e.id<t.id?1:e.id>t.id?-1:0)}getRank(e){let t=e.getOutgoingEdges().length,n;for(let r of e.getIncomingEdges())n=r.getSource().getNode().getOutgoingEdges().length,t=Math.max(t,n);return t}computeSuccessors(){let e=0;this.successors=[];let t=/* @__PURE__ */ new Set;for(let n of this.sortedLayerlessNodes){n.id=e;for(let e of n.getOutgoingEdges())t.add(e.getTarget().getNode());t.delete(n),this.successors.push(new Set(t)),t.clear(),e++}}computeDegrees(){this.inDegree=Array(this.sortedLayerlessNodes.length).fill(0),this.outDegree=Array(this.sortedLayerlessNodes.length).fill(0);for(let e of this.sortedLayerlessNodes)this.inDegree[e.id]=e.getIncomingEdges().length,this.outDegree[e.id]=e.getOutgoingEdges().length}minMaxNodeSize(){for(let e of this.sortedLayerlessNodes){if(e.getType()!==`NORMAL`)continue;let t=e.getSize().y;this.minimumNodeSize=Math.min(this.minimumNodeSize,t),this.maximumNodeSize=Math.max(this.maximumNodeSize,t)}}avereageNodeSize(){let e=0;for(let t of this.sortedLayerlessNodes)e+=this.normSize[t.id];return e/this.sortedLayerlessNodes.length}computeNormalizedSize(){this.normSize=Array(this.sortedLayerlessNodes.length).fill(0);for(let e of this.sortedLayerlessNodes)this.normSize[e.id]=e.getSize().y/this.minimumNodeSize}getAverageOutDegree(){let e=0;for(let t of this.currentGraph.getLayerlessNodes())e+=t.getOutgoingEdges().length;return e/this.currentGraph.getLayerlessNodes().length}updateOutGoing(e){for(let t of e.getNodes())for(let e of t.getIncomingEdges()){let t=e.getSource().getNode().id;this.remainingOutGoing[t]=this.remainingOutGoing[t]-1}}};const Yo=new e.ai(`org.eclipse.elk.layered.nodePlacement.linearSegments.deflectionDampening`,.3);var Xo=class e{nodes=[];id;indexInLastLayer=-1;lastLayer=-1;deflection=0;weight=0;refSegment=null;nodeType=`NORMAL`;constructor(e){this.id=e}region(){let e=this;for(;e.refSegment!==null;)e=e.refSegment;return e}split(t,n,r){let i=this.nodes.indexOf(t),a=new e(n),o=this.nodes.splice(i);a.nodes.push(...o);for(let e of o)r.set(e,n);return a}};function Zo(t){let n=t.getProperty(e.wr),r=Qo(t),i=/* @__PURE__ */ new Map,a=$o(t,i);ns(t,a,n),rs(t,a,n,r,i),os(t,a,n)}function Qo(t){let n=/* @__PURE__ */ new Map;for(let r of t.getLayers())for(let t of r.getNodes()){let r=-(2**53-1),i=-(2**53-1);for(let n of t.getPorts()){for(let t of n.getIncomingEdges())r=Math.max(r,t.getProperty(e.Gt));for(let t of n.getOutgoingEdges())i=Math.max(i,t.getProperty(e.Gt))}n.set(t,{input:r,output:i})}return n}function $o(e,t){let n=[],r=0;for(let i of e.getLayers())for(let e of i.getNodes())if(!t.has(e)){let i=new Xo(r++);es(e,i,t),n.push(i)}let i=n.map(()=>[]),a=n.map(()=>0);ts(e,n,i,a,t);let o=[];for(let e=0;e<n.length;e++)a[e]===0&&o.push(n[e]);let s=Array(n.length),c=0;for(;o.length>0;){let e=o.shift();for(s[e.id]=c++;i[e.id].length>0;){let t=i[e.id].shift();a[t.id]--,a[t.id]===0&&o.push(t)}}let l=Array(n.length);for(let e=0;e<n.length;e++){let r=n[e],i=s[e];l[i]=r,r.id=i;for(let e of r.nodes)t.set(e,i)}return l}function es(e,t,n){let r=e.getType();if(n.has(e))return!1;if(n.set(e,t.id),t.nodes.push(e),t.nodeType=r,r===`LONG_EDGE`||r===`NORTH_SOUTH_PORT`)for(let r of e.getPorts())for(let i of r.getSuccessorPorts()){let r=i.getNode(),a=r.getType();if(e.getLayer()!==r.getLayer()&&(a===`LONG_EDGE`||a===`NORTH_SOUTH_PORT`)&&es(r,t,n))return!0}return!0}function ts(e,t,n,r,i){let a=t.length,o=0;for(let s of e.getLayers()){let e=s.getNodes();if(e.length===0)continue;let c=0,l=null,u=e[0],d=null;for(;u!==null;){if(d=t[i.get(u)],d.indexInLastLayer>=0){let o=null;for(let n=c+1;n<e.length;n++){let r=e[n],a=t[i.get(r)];if(a.lastLayer===d.lastLayer&&a.indexInLastLayer<d.indexInLastLayer){o=a;break}}if(o!==null){if(l!==null){let e=t[i.get(l)];r[d.id]--;let a=n[e.id],o=a.indexOf(d);o!==-1&&a.splice(o,1)}d=d.split(u,a++,i),t.push(d),n.push([]),l===null?r.push(0):(n[i.get(l)].push(d),r.push(1))}}let s=null;if(c+1<e.length){s=e[c+1];let a=t[i.get(s)];n[d.id].push(a),r[a.id]++}d.lastLayer=o,d.indexInLastLayer=c++,l=u,u=s}o++}}function ns(t,n,r){let i=t.getLayers().length,a=Array(i).fill(0),o=Array(i).fill(null);for(let i of n){let n=0;for(let s of i.nodes){let i=s.getLayer().getIndex();a[i]++;let c=t.getProperty(e.$t);a[i]>0&&o[i]!==null&&(c=r.getVerticalSpacing(o[i],s)),n=Math.max(n,s.getLayer().getSize().y+c)}for(let e of i.nodes){e.getPosition().y=n+e.getMargin().top;let t=e.getLayer();t.getSize().y=n+e.getMargin().top+e.getSize().y+e.getMargin().bottom,o[t.getIndex()]=e}}}function rs(t,n,r,i,a){let o=t.getProperty(Yo),s=t.getProperty(e.mn),c=4,l=3,u=20/s,d=!1,f=`FORW_PENDULUM`,p=2**53-1;do{let e=f!==`BACKW_PENDULUM`,m=f!==`FORW_PENDULUM`,h=0;for(let t of n)t.refSegment=null,is(t,n,e,m,o,i,a),h+=Math.abs(t.deflection);let g;do g=as(t,n,r,a);while(g);for(let e of n){let t=e.region().deflection;if(t!==0)for(let n of e.nodes)n.getPosition().y+=t}f===`FORW_PENDULUM`||f===`BACKW_PENDULUM`?(c--,c<=0&&(h<p||-c>s)?(f=`RUBBER`,p=2**53-1):f===`FORW_PENDULUM`?(f=`BACKW_PENDULUM`,p=h):(f=`FORW_PENDULUM`,p=h)):(d=h>=p||p-h<u,p=h,d&&l--)}while(!(d&&l<=0))}function is(t,n,r,i,a,o,s){let c=0,l=0;for(let a of t.nodes){let u=0,d=0,f=o.get(a),p=r?f.input:-(2**53-1),m=i?f.output:-(2**53-1),h=Math.max(p,m);for(let c of a.getPorts()){let l=a.getPosition().y+c.getPosition().y+c.getAnchor().y;if(i)for(let r of c.getOutgoingEdges()){let i=r.getTarget(),a=i.getNode();if(t!==n[s.get(a)]){let t=o.get(a),n=Math.max(t.input,t.output),s=r.getProperty(e.Gt);s>=h&&s>=n&&(u+=a.getPosition().y+i.getPosition().y+i.getAnchor().y-l,d++)}}if(r)for(let r of c.getIncomingEdges()){let i=r.getSource(),a=i.getNode();if(t!==n[s.get(a)]){let t=o.get(a),n=Math.max(t.input,t.output),s=r.getProperty(e.Gt);s>=h&&s>=n&&(u+=a.getPosition().y+i.getPosition().y+i.getAnchor().y-l,d++)}}}d>0&&(c+=u/d,l++)}l>0?(t.deflection=a*c/l,t.weight=l):(t.deflection=0,t.weight=0)}function as(t,n,r,i){let a=!1,o=1e-4*t.getProperty(e.ln);for(let e of t.getLayers()){let t=e.getNodes();if(t.length===0)continue;let s=t[0],c=n[i.get(s)].region();for(let e=1;e<t.length;e++){let l=t[e],u=n[i.get(l)].region();if(c!==u){let e=r.getVerticalSpacing(s,l);if(s.getPosition().y+s.getSize().y+s.getMargin().bottom+c.deflection+e>l.getPosition().y-l.getMargin().top+u.deflection+o){let e=c.weight+u.weight;e>0&&(u.deflection=(u.weight*u.deflection+c.weight*c.deflection)/e,u.weight=e,c.refSegment=u,a=!0)}}s=l,c=u}}return a}function os(e,t,n){for(let e of t){let t=2**53-1,r=2**53-1;for(let i of e.nodes){let e=i.getIndex(),a=i.getLayer().getNodes(),o,s;if(e>0){let t=a[e-1],r=n.getVerticalSpacing(i,t);o=i.getPosition().y-i.getMargin().top-(t.getPosition().y+t.getSize().y+t.getMargin().bottom+r)}else o=i.getPosition().y-i.getMargin().top;if(t=Math.min(o,t),e<a.length-1){let t=a[e+1],r=n.getVerticalSpacing(i,t);s=t.getPosition().y-t.getMargin().top-(i.getPosition().y+i.getSize().y+i.getMargin().bottom+r)}else s=2*i.getPosition().y;r=Math.min(s,r)}let i=2**53-1,a=!1,o=e.nodes[0];for(let e of o.getPorts()){let n=o.getPosition().y+e.getPosition().y+e.getAnchor().y;for(let o of e.getIncomingEdges()){let e=o.getSource(),s=e.getNode().getPosition().y+e.getPosition().y+e.getAnchor().y-n;Math.abs(s)<Math.abs(i)&&Math.abs(s)<(s<0?t:r)&&(i=s,a=!0)}}let s=e.nodes[e.nodes.length-1];for(let e of s.getPorts()){let n=s.getPosition().y+e.getPosition().y+e.getAnchor().y;for(let o of e.getOutgoingEdges()){let e=o.getTarget(),s=e.getNode().getPosition().y+e.getPosition().y+e.getAnchor().y-n;Math.abs(s)<Math.abs(i)&&Math.abs(s)<(s<0?t:r)&&(i=s,a=!0)}}if(a&&i!==0)for(let t of e.nodes)t.getPosition().y+=i}}function ss(t){let n=0;for(let r of t.getLayers()){let t=0,i=!1;for(let a of r.getNodes())a.getType()===`NORMAL`&&(i=!0,a.setProperty(e.at,n),a.setProperty(e.j,t),t++);i&&n++}}function cs(t){for(let n of t.getLayers())for(let r of n.getNodes()){if(!r.getProperty(e.Z)||r.getPorts().length>2)continue;let n=0,i=0,a=0,o=0;for(let e of r.getPorts())switch(e.getSide()){case`NORTH`:n++;break;case`EAST`:i++;break;case`SOUTH`:a++;break;case`WEST`:o++}n===0&&a===0&&ls(t,r,o<=i)}}function ls(t,n,r){let i=[],a=2**53-1,o=2**53-1,s=2**53-1;if(r){a=t.getSize().x;for(let e of n.getPorts())for(let t of e.getOutgoingEdges()){let e=t.getBendPoints();if(e.length===0)continue;let n=e[0];n.x<a&&(o=a-n.x,s=2**53-1,i.length=0,a=n.x),n.x<=a&&(i.push(t),e.length>1&&(s=Math.min(s,Math.abs(e[1].y-n.y))))}}else for(let e of n.getPorts())for(let t of e.getIncomingEdges()){let e=t.getBendPoints();if(e.length===0)continue;let n=e[e.length-1];n.x>a&&(o=n.x-a,s=2**53-1,i.length=0,a=n.x),n.x>=a&&(i.push(t),e.length>1&&(s=Math.min(s,Math.abs(e[e.length-2].y-n.y))))}if(i.length===0||o<=n.size.x/2||s<=n.size.y/2)return;let c=new p;c.setNode(n),c.setSide(`NORTH`),c.position.x=n.size.x/2;let l=new p;l.setNode(n),l.setSide(`SOUTH`),l.position.x=n.size.x/2,l.position.y=n.size.y;for(let t of i){let n,i;r?(n=t.getBendPoints().shift(),i=t.getBendPoints().length===0?t.getTarget().getAbsoluteAnchor():t.getBendPoints()[0],i.y>=n.y?t.setSource(l):t.setSource(c)):(n=t.getBendPoints().pop(),i=t.getBendPoints().length===0?t.getSource().getAbsoluteAnchor():t.getBendPoints()[t.getBendPoints().length-1],i.y>=n.y?t.setTarget(l):t.setTarget(c));let a=t.getProperty(e.nt);if(a!=null){let e=a.findIndex(e=>e.x===n.x&&e.y===n.y);e!==-1&&a.splice(e,1)}}n.position.x=a-n.size.x/2}const us={top:0,left:0,bottom:0,right:0},ds=e=>({...e}),fs=[`NORTH`,`SOUTH`,`EAST`,`WEST`];var ps=class{padding=ds(us);contributesMinWidth=!1;contributesMinHeight=!1;rect={x:0,y:0,width:0,height:0}},H=class extends ps{content={x:0,y:0};getMinimumWidth(){return this.content.x+this.padding.left+this.padding.right}getMinimumHeight(){return this.content.y+this.padding.top+this.padding.bottom}},ms=class extends ps{content={x:0,y:0};gap;labelRefs=[];hAlign=`CENTER`;vAlign=`CENTER`;constructor(e){super(),this.gap=e}addLabel(e,t,n){this.content.y>0&&(this.content.y+=this.gap),this.content.x=Math.max(this.content.x,e),this.content.y+=t,n&&this.labelRefs.push(n)}setHorizontalAlignment(e){this.hAlign=e}setVerticalAlignment(e){this.vAlign=e}getLabels(){return this.labelRefs}applyLabelLayout(){let e=this.rect,t=e.y;this.vAlign===`CENTER`?t+=(e.height-this.content.y)/2:this.vAlign===`BOTTOM`&&(t+=e.height-this.content.y);for(let n of this.labelRefs){let r=n.size.x;n.position.y=t,t+=n.size.y+this.gap,this.hAlign===`LEFT`?n.position.x=e.x+this.padding.left:this.hAlign===`CENTER`?n.position.x=e.x+this.padding.left+(e.width-r)/2:n.position.x=e.x+e.width-this.padding.right-r}}getMinimumWidth(){return this.content.x+this.padding.left+this.padding.right}getMinimumHeight(){return this.content.y+this.padding.top+this.padding.bottom}};function U(e,t){return e===null||t&&!e.contributesMinWidth||e instanceof H&&e.content.x===0?0:e.getMinimumWidth()}function hs(e){return e===null||e instanceof H&&e.content.x===0?0:e.getMinimumWidth()}function gs(e){return e===null||e instanceof H&&e.content.y===0?0:e.getMinimumHeight()}function _s(e,t){return e===null||t&&!e.contributesMinHeight||e instanceof H&&e.content.y===0?0:e.getMinimumHeight()}var vs=class extends ps{mode;symmetrical;gap;cells=[null,null,null];constructor(e,t,n){super(),this.mode=e,this.symmetrical=t,this.gap=n}getMinimumWidth(){let e;if(this.mode===`VERTICAL`)e=Math.max(0,U(this.cells[0],!0),U(this.cells[1],!0),U(this.cells[2],!0));else{let t=U(this.cells[0],!0),n=U(this.cells[1],!0),r=U(this.cells[2],!0);this.symmetrical&&(t=Math.max(t,r),r=t);let i=0,a=0;t>0&&(i+=t,a++),n>0&&(i+=n,a++),r>0&&(i+=r,a++),e=a>1?i+this.gap*(a-1):i}return e>0?e+this.padding.left+this.padding.right:0}getMinimumHeight(){let e;if(this.mode===`VERTICAL`){let t=_s(this.cells[0],!0),n=_s(this.cells[1],!0),r=_s(this.cells[2],!0);this.symmetrical&&(t=Math.max(t,r),r=t);let i=0,a=0;t>0&&(i+=t,a++),n>0&&(i+=n,a++),r>0&&(i+=r,a++),e=a>1?i+this.gap*(a-1):i}else e=Math.max(0,_s(this.cells[0],!0),_s(this.cells[1],!0),_s(this.cells[2],!0));return e>0?e+this.padding.top+this.padding.bottom:0}},ys=class extends ps{symmetrical;gap;cells=[[null,null,null],[null,null,null],[null,null,null]];constructor(e,t){super(),this.symmetrical=e,this.gap=t}minHeightOfRow(e,t){let n=0;for(let r=0;r<3;r++)n=Math.max(n,_s(this.cells[e][r],t));return n}minColumnWidthSum(e,t){let n=this.cells[e],r=U(n[0],t),i=U(n[1],t),a=U(n[2],t),o=0,s=0;return r>0&&(o+=r,s++),i>0&&(o+=i,s++),a>0&&(o+=a,s++),s>1?o+this.gap*(s-1):o}getMinimumWidth(){let e=Math.max(this.minColumnWidthSum(0,!0),this.minColumnWidthSum(1,!0),this.minColumnWidthSum(2,!0));return e>0?e+this.padding.left+this.padding.right:0}getMinimumHeight(){let e=this.minHeightOfRow(0,!0),t=this.minHeightOfRow(1,!0),n=this.minHeightOfRow(2,!0);this.symmetrical&&(e=Math.max(e,n),n=e);let r=0,i=0;e>0&&(r+=e,i++),t>0&&(r+=t,i++),n>0&&(r+=n,i++);let a=i>1?r+this.gap*(i-1):r;return a>0?a+this.padding.top+this.padding.bottom:0}};function bs(e,t,n,r){return e.hasProperty(n)?e.getProperty(n):t&&t.hasProperty(n)?t.getProperty(n):r}function xs(t,n){let r=n===`NORTH`?e.Mt:n===`SOUTH`?e.Nt:n===`EAST`?e.jt:e.Pt,i=t.node.hasProperty(r)?t.node.getProperty(r):void 0;return i&&i!==`DISTRIBUTED`?i:bs(t.node,t.graph,e.At,`DISTRIBUTED`)}function Ss(e){return!e.includes(`INSIDE`)&&!e.includes(`OUTSIDE`)}function Cs(e){let t=e.getLabels();if(t.length===0)return null;let n=1/0,r=1/0,i=-1/0,a=-1/0;for(let e of t)n=Math.min(n,e.position.x),r=Math.min(r,e.position.y),i=Math.max(i,e.position.x+e.size.x),a=Math.max(a,e.position.y+e.size.y);return{x:n,y:r,w:i-n,h:a-r}}function ws(e,t){for(let t of fs)e.portContexts.set(t,[]);let n=Ss(e.portLabelsPlacement),r=!n&&(!t||!e.portLabelsPlacement.includes(`INSIDE`)),i=e.portLabelsPlacement.includes(`NEXT_TO_PORT_IF_POSSIBLE`);for(let t of e.node.getPorts()){let a=t.getSide();if(a===`UNDEFINED`)continue;let o=!1;e.portLabelsPlacement.includes(`INSIDE`)?(o=!0,e.treatAsCompoundNode&&(o=i)):e.portLabelsPlacement.includes(`OUTSIDE`)&&(o=i&&t.getConnectedEdges().length===0);let s={port:t,margin:{left:0,right:0,top:0,bottom:0},labelsNextToPort:o,labelCell:null,fixedLabelBounds:n?Cs(t):null};if(r){let n=t.getLabels();if(n.length>0){let t=new ms(e.labelCellSpacing);for(let e of n)t.addLabel(e.size.x,e.size.y,e);s.labelCell=t,e.hasPortLabelCells=!0}}e.portContexts.get(a).push(s)}}function Ts(t){let n=t.insideGrid;n.padding=ds(t.nodeLabelsPadding);let r=t.outsideNodeLabelContainers,i=t.node.getProperty(e._t);for(let e of t.node.getLabels()){let a=Array.isArray(e.placement)?e.placement:String(e.placement??``).split(/[\s,]+/),o=[];for(let e of a){let t=e.replace(/^\[+|\]+$/g,``).trim();t&&o.push(t)}let s=o.length>0?o:i??[],c=s.includes(`INSIDE`),l=s.includes(`V_BOTTOM`)?`bottom`:s.includes(`V_CENTER`)?`center`:`top`,u=s.includes(`H_RIGHT`)?`right`:s.includes(`H_LEFT`)?`left`:`center`,d=l===`bottom`?2:+(l===`center`),f=u===`right`?2:u===`left`?0:1;if(c){let r=n.cells[d][f];r||(r=new ms(t.labelCellSpacing),n.cells[d][f]=r),r.addLabel(e.size.x,e.size.y)}else{let n;n=l===`bottom`?r.get(`SOUTH`):u===`left`&&(s.includes(`H_PRIORITY`)||l===`center`)?r.get(`WEST`):u===`right`&&(s.includes(`H_PRIORITY`)||l===`center`)?r.get(`EAST`):r.get(`NORTH`);let i=new ms(t.labelCellSpacing);i.addLabel(e.size.x,e.size.y),n.mode===`HORIZONTAL`?n.cells[f]=i:n.cells[1]=i}}}function Es(t){let n=t.nodeContainer.padding;for(let[r,i]of t.portContexts)for(let a of i){let i=a.port.getProperty(e.It)??0;if(i<0){let e=-i;r===`NORTH`?n.top=Math.max(n.top,e):r===`SOUTH`?n.bottom=Math.max(n.bottom,e):r===`EAST`?n.right=Math.max(n.right,e):n.left=Math.max(n.left,e)}if(Ss(t.portLabelsPlacement)&&a.fixedLabelBounds){let e=a.fixedLabelBounds,o=a.port.size,s=0;s=r===`NORTH`?Math.max(0,e.h+e.y-(o.y+i)):r===`SOUTH`?Math.max(0,-e.y-i):r===`EAST`?Math.max(0,-e.x-i):Math.max(0,e.w+e.x-(o.x+i));let c=t.symmetry;if(r===`NORTH`){let e=s>n.top;n.top=Math.max(n.top,s),c&&e&&(n.top=Math.max(n.top,n.bottom),n.bottom=n.top+i)}else if(r===`SOUTH`){let e=s>n.bottom;n.bottom=Math.max(n.bottom,s),c&&e&&(n.bottom=Math.max(n.bottom,n.top),n.top=n.bottom+i)}else if(r===`EAST`){let e=s>n.right;n.right=Math.max(n.right,s),c&&e&&(n.right=Math.max(n.left,n.right),n.left=n.right+i)}else{let e=s>n.left;n.left=Math.max(n.left,s),c&&e&&(n.left=Math.max(n.left,n.right),n.right=n.left+i)}}}}function Ds(e){let t=e.portConstraints;if(t===`FIXED_RATIO`||String(t)===`FIXED_RATIO`||t===`FIXED_POS`||String(t)===`FIXED_POSITION`)return;let n=e.insidePortLabelCells.get(`EAST`),r=e.insidePortLabelCells.get(`WEST`),i=e.insidePortLabelCells.get(`NORTH`),a=e.insidePortLabelCells.get(`SOUTH`),o=e.nodeContainer.padding.top+i.getMinimumHeight()+e.labelCellSpacing,s=e.nodeContainer.padding.bottom+a.getMinimumHeight()+e.labelCellSpacing,c=Math.max(0,n.padding.top-o,r.padding.top-o),l=Math.max(0,n.padding.bottom-s,r.padding.bottom-s);n.padding.top=c,r.padding.top=c,n.padding.bottom=l,r.padding.bottom=l}function Os(e){for(let t of fs){let n=e.insidePortLabelCells.get(t),r=e.portContexts.get(t);if(r.length===0){t===`NORTH`||t===`SOUTH`?(n.padding.left=0,n.padding.right=0,e.portLabelSpacingV>=0&&(t===`NORTH`?n.padding.top=e.portLabelSpacingV:n.padding.bottom=e.portLabelSpacingV)):(n.padding.top=0,n.padding.bottom=0);continue}t===`NORTH`||t===`SOUTH`?(n.padding.left=e.surrounding.left,n.padding.right=e.surrounding.right,e.portLabelSpacingV>=0&&(t===`NORTH`?n.padding.top=e.portLabelSpacingV:n.padding.bottom=e.portLabelSpacingV)):(n.padding.top=e.surrounding.top,n.padding.bottom=e.surrounding.bottom),e.constraints.includes(`PORT_LABELS`)&&ks(e,t);let i=t===`NORTH`||t===`SOUTH`,a=0;for(let t=0;t<r.length;t++){let n=r[t];a+=i?n.margin.left+n.port.size.x+n.margin.right:n.margin.top+n.port.size.y+n.margin.bottom,t<r.length-1&&(a+=e.portPort)}xs(e,t)===`DISTRIBUTED`&&(a+=2*e.portPort),i?n.content.x=a:n.content.y=a;let o=e.portConstraints!==`FIXED_POS`&&String(e.portConstraints)!==`FIXED_POSITION`;if(i&&e.portLabelsPlacement.includes(`INSIDE`)&&e.constraints.includes(`PORT_LABELS`)&&o){let e=0;for(let t of r)t.labelCell&&(e=Math.max(e,t.labelCell.getMinimumHeight()));e>0&&(n.content.y=e)}if(!i&&e.portLabelsPlacement.includes(`INSIDE`)){let i=0;for(let e of r)e.labelCell&&(i=Math.max(i,e.labelCell.getMinimumWidth()));i>0&&(n.content.x=i,t===`EAST`?n.padding.right=e.portLabelSpacingH:n.padding.left=e.portLabelSpacingH)}}}function ks(e,t){let n=e.portContexts.get(t),r=e.portLabelsPlacement.includes(`OUTSIDE`),i=e.sizeOptions.includes(`UNIFORM_PORT_SPACING`);for(let r of n){let n=r.labelCell?r.labelCell.getMinimumWidth():0,i=r.labelCell?r.labelCell.getMinimumHeight():0;if(r.labelCell){if(t===`NORTH`||t===`SOUTH`){if(r.labelsNextToPort){let e=r.port.size.x;if(n>e){let t=(n-e)/2;r.margin.left=t,r.margin.right=t}}else r.margin.right=e.portLabelSpacingH+n}else if(r.labelsNextToPort){let e=r.port.size.y;if(i>e){let t=(i-e)/2;r.margin.top=t,r.margin.bottom=t}}else r.margin.bottom=e.portLabelSpacingV+i}else if(Ss(e.portLabelsPlacement)&&r.fixedLabelBounds){let e=r.fixedLabelBounds;t===`NORTH`||t===`SOUTH`?(e.x<0&&(r.margin.left=-e.x),e.x+e.w>r.port.size.x&&(r.margin.right=e.x+e.w-r.port.size.x)):(e.y<0&&(r.margin.top=-e.y),e.y+e.h>r.port.size.y&&(r.margin.bottom=e.y+e.h-r.port.size.y))}}if(r){let e=n[0],r=n[n.length-1];t===`NORTH`||t===`SOUTH`?(e.margin.left=0,r.margin.right=0):(e.margin.top=0,r.margin.bottom=0)}if(i){let e=0,i=0,a=0,o=0;for(let t of n)t.margin.left>e&&(e=t.margin.left),t.margin.right>i&&(i=t.margin.right),t.margin.top>a&&(a=t.margin.top),t.margin.bottom>o&&(o=t.margin.bottom);for(let t of n)t.margin.left=e,t.margin.right=i,t.margin.top=a,t.margin.bottom=o;if(r){let e=n[0],r=n[n.length-1];t===`NORTH`||t===`SOUTH`?(e.margin.left=0,r.margin.right=0):(e.margin.top=0,r.margin.bottom=0)}}}function As(e){if(e.constraints.length===0)return;let t=e.insidePortLabelCells,n=e.portConstraints!==`FIXED_RATIO`&&e.portConstraints!==`FIXED_POS`&&String(e.portConstraints)!==`FIXED_RATIO`&&String(e.portConstraints)!==`FIXED_POSITION`;if(e.constraints.includes(`PORTS`)&&(t.get(`NORTH`).contributesMinWidth=!0,t.get(`SOUTH`).contributesMinWidth=!0,t.get(`EAST`).contributesMinHeight=n,t.get(`WEST`).contributesMinHeight=n,e.middleRow.contributesMinHeight=n,e.constraints.includes(`PORT_LABELS`)&&(t.get(`NORTH`).contributesMinHeight=!0,t.get(`SOUTH`).contributesMinHeight=!0,t.get(`EAST`).contributesMinWidth=!0,t.get(`WEST`).contributesMinWidth=!0,e.middleRow.contributesMinWidth=!0)),e.constraints.includes(`NODE_LABELS`)){e.insideGrid.contributesMinHeight=!0,e.insideGrid.contributesMinWidth=!0,e.middleRow.contributesMinHeight=!0,e.middleRow.contributesMinWidth=!0;let t=e.sizeOptions.includes(`OUTSIDE_NODE_LABELS_OVERHANG`);for(let t=0;t<3;t++)for(let n=0;n<3;n++){let r=e.insideGrid.cells[t][n];r&&(r.contributesMinHeight=!0,r.contributesMinWidth=!0)}for(let n of fs){let r=e.outsideNodeLabelContainers.get(n);r.contributesMinHeight=!t,r.contributesMinWidth=!t;for(let e of r.cells)e&&(e.contributesMinHeight=!t,e.contributesMinWidth=!t)}}e.constraints.includes(`MINIMUM_SIZE`)&&e.sizeOptions.includes(`MINIMUM_SIZE_ACCOUNTS_FOR_PADDING`)&&(e.middleRow.contributesMinHeight=!0,e.middleRow.contributesMinWidth=!0,e.insideGrid.contributesMinHeight||(e.insideGrid.contributesMinHeight=!0,e.insideGrid.contributesMinWidth=!0))}function js(t,n,r){let i=t.hasProperty(e.Tt)?t.getProperty(e.Tt):n?.getProperty(e.Tt)??[],a=i.length===0||i.length===1&&i[0]===`PORT_LABELS`,o=t.hasProperty(e.Dt)?t.getProperty(e.Dt):n&&n.hasProperty(e.Dt)?n.getProperty(e.Dt):[],s=String(t.getProperty(e.Lt)??`UNDEFINED`),c=t.hasProperty(e.zt)?t.getProperty(e.zt):[`OUTSIDE`],l=t.getProperty(`org.eclipse.elk.portLabels.treatAsGroup`)===!0,u=!o.includes(`ASYMMETRICAL`),d=bs(t,n,e.pn,10),f=bs(t,n,e.fn,ds(us)),p=bs(t,n,e.gt,{top:5,right:5,bottom:5,left:5}),m=bs(t,n,e.an,0),h=2*m,g=bs(t,n,e.on,5),_=bs(t,n,e.sn,1),v=bs(t,n,e.cn,1),y=new vs(`VERTICAL`,u,0),b=new vs(`HORIZONTAL`,u,0);y.cells[1]=b;let x=new ys(u,h);b.cells[1]=x;let S=/* @__PURE__ */ new Map,C=new H,w=new H,ee=new H,te=new H;S.set(`NORTH`,C),S.set(`SOUTH`,w),S.set(`WEST`,ee),S.set(`EAST`,te),y.cells[0]=C,y.cells[2]=w,b.cells[0]=ee,b.cells[2]=te;let T=/* @__PURE__ */ new Map;T.set(`NORTH`,new vs(`HORIZONTAL`,u,h)),T.set(`SOUTH`,new vs(`HORIZONTAL`,u,h)),T.set(`WEST`,new vs(`VERTICAL`,u,h)),T.set(`EAST`,new vs(`VERTICAL`,u,h)),T.get(`NORTH`).padding.bottom=g,T.get(`SOUTH`).padding.top=g,T.get(`WEST`).padding.right=g,T.get(`EAST`).padding.left=g;let E={node:t,graph:n,treatAsCompoundNode:t.getNestedGraph()!==null||t.getProperty(e.Q),sizeFixed:a,constraints:i,sizeOptions:o,portConstraints:s,portLabelsPlacement:c,portLabelsTreatAsGroup:l,symmetry:u,portPort:d,surrounding:f,nodeLabelsPadding:p,labelLabelSpacing:m,labelCellSpacing:h,nodeLabelSpacing:g,portLabelSpacingH:_,portLabelSpacingV:v,portContexts:/* @__PURE__ */ new Map,hasPortLabelCells:!1,nodeContainer:y,middleRow:b,insideGrid:x,insidePortLabelCells:S,outsideNodeLabelContainers:T};return ws(E,r),Ts(E),Es(E),Os(E),As(E),Ds(E),E}function Ms(e){if(e.sizeFixed)return null;let{nodeContainer:t}=e,n=e.constraints,r=e.sizeOptions,i=e.outsideNodeLabelContainers,a=t.getMinimumWidth(),o=t.getMinimumHeight();return n.includes(`NODE_LABELS`)&&!r.includes(`OUTSIDE_NODE_LABELS_OVERHANG`)&&(a=Math.max(a,i.get(`NORTH`).getMinimumWidth(),i.get(`SOUTH`).getMinimumWidth()),o=Math.max(o,i.get(`EAST`).getMinimumHeight(),i.get(`WEST`).getMinimumHeight())),{x:a,y:o}}function Ns(e,t,n=!1){return Ms(js(e,t,n))}function Ps(e,t){let n=gs(e.cells[0]),r=gs(e.cells[1]),i=gs(e.cells[2]);e.symmetrical&&(n=Math.max(n,i),i=n),e.cells[0]&&(e.cells[0].rect={x:t.x,y:t.y+e.padding.top,width:t.width,height:n}),e.cells[2]&&(e.cells[2].rect={x:t.x,y:t.y+t.height-e.padding.bottom-i,width:t.width,height:i});let a=t.height-e.padding.top-e.padding.bottom;n>0&&(a-=n),i>0&&(a-=i);let o=Math.max(r,a);e.cells[1]&&(e.cells[1].rect={x:t.x,y:t.y+e.padding.top+n,width:t.width,height:o})}function Fs(e,t){let n=hs(e.cells[0]),r=hs(e.cells[1]),i=hs(e.cells[2]);e.symmetrical&&(n=Math.max(n,i),i=n),e.cells[0]&&(e.cells[0].rect={x:t.x+e.padding.left,y:t.y,width:n,height:t.height}),e.cells[2]&&(e.cells[2].rect={x:t.x+t.width-e.padding.right-i,y:t.y,width:i,height:t.height});let a=t.width-e.padding.left-e.padding.right;n>0&&(a-=n+e.gap,n+=e.gap),i>0&&(a-=i+e.gap);let o=Math.max(r,a);e.cells[1]&&(e.cells[1].rect={x:t.x+e.padding.left+n-(o-a)/2,y:t.y,width:o,height:t.height})}function Is(e,t,n){return t===`DISTRIBUTED`?n-2*e.portPort:n}function Ls(t,n,r){let i={x:0,y:0,width:n,height:r};Ps(t.nodeContainer,i),Fs(t.middleRow,t.middleRow.rect);let a=t.sizeOptions.includes(`PORTS_OVERHANG`);for(let r of fs){let i=t.portContexts.get(r);if(i.length===0)continue;let o=t.insidePortLabelCells.get(r),s=o.rect,c=o.padding,l=r===`NORTH`||r===`SOUTH`,u=xs(t,r),d=l?o.content.x:o.content.y;(u===`DISTRIBUTED`||u===`JUSTIFIED`)&&i.length===1&&(d=Is(t,u,d),u=`CENTER`);let f=(l?s.width:s.height)-(l?c.left+c.right:c.top+c.bottom),p=l?s.x+c.left:s.y+c.top,m=t.portPort;if(f<d&&!a)u===`DISTRIBUTED`?(m+=(f-d)/(i.length+1),p+=m):m+=(f-d)/(i.length-1);else switch(f<d&&(d=Is(t,u,d),u=`CENTER`),u){case`BEGIN`:break;case`CENTER`:p+=(f-d)/2;break;case`END`:p+=f-d;break;case`DISTRIBUTED`:{let e=(f-d)/(i.length+1);m+=Math.max(0,e),p+=m;break}case`JUSTIFIED`:{let e=(f-d)/(i.length-1);m+=Math.max(0,e);break}}let h=r===`WEST`||r===`SOUTH`;for(let t=0;t<i.length;t++){let a=h?i[i.length-1-t]:i[t],o=a.port.getProperty(e.It)??0;l?(a.port.getPosition().x=p+a.margin.left,a.port.getPosition().y=r===`NORTH`?-a.port.size.y-o:o,p+=a.margin.left+a.port.size.x+a.margin.right+m):(a.port.getPosition().y=p+a.margin.top,a.port.getPosition().x=r===`EAST`?n+o:-a.port.size.x-o,p+=a.margin.top+a.port.size.y+a.margin.bottom+m)}}}function Rs(e,t){let n=e.nodeContainer.padding;switch(t){case`NORTH`:return n.top+e.portLabelSpacingV;case`SOUTH`:return n.bottom+e.portLabelSpacingV;case`EAST`:return n.right+e.portLabelSpacingH;case`WEST`:return n.left+e.portLabelSpacingH;default:return 0}}function zs(e,t){let n=e.portContexts.get(t);if(n.length>=2){let r=t===`SOUTH`||t===`WEST`?n[n.length-1]:n[0],i=e.portLabelsPlacement.includes(`ALWAYS_SAME_SIDE`),a=e.portLabelsPlacement.includes(`SPACE_EFFICIENT`);return!r.labelsNextToPort&&!i&&(n.length===2||a)}return!1}function Bs(t,n){let r=0,i=Rs(t,n),a=n===`NORTH`||n===`SOUTH`;for(let o of t.portContexts.get(n)){let s=o.labelCell;if(s===null||s.getLabels().length===0)continue;let c=o.port.size,l=o.port.getProperty(e.It)??0,u=s.rect;switch(u.width=s.getMinimumWidth(),u.height=s.getMinimumHeight(),n){case`NORTH`:u.x=o.labelsNextToPort?(c.x-u.width)/2:c.x+t.portLabelSpacingH,u.y=c.y+l+i,s.setHorizontalAlignment(`CENTER`),s.setVerticalAlignment(`TOP`);break;case`SOUTH`:u.x=o.labelsNextToPort?(c.x-u.width)/2:c.x+t.portLabelSpacingH,u.y=-l-i-u.height,s.setHorizontalAlignment(`CENTER`),s.setVerticalAlignment(`BOTTOM`);break;case`EAST`:if(u.x=-l-i-u.width,o.labelsNextToPort){let e=t.portLabelsTreatAsGroup?u.height:s.getLabels()[0].size.y;u.y=(c.y-e)/2}else u.y=c.y+t.portLabelSpacingV;s.setHorizontalAlignment(`RIGHT`),s.setVerticalAlignment(`CENTER`);break;case`WEST`:if(u.x=c.x+l+i,o.labelsNextToPort){let e=t.portLabelsTreatAsGroup?u.height:s.getLabels()[0].size.y;u.y=(c.y-e)/2}else u.y=c.y+t.portLabelSpacingV;s.setHorizontalAlignment(`LEFT`),s.setVerticalAlignment(`CENTER`)}a&&(r=Math.max(r,u.height))}r>0&&(t.insidePortLabelCells.get(n).content.y=r)}function Vs(e,t){let n=zs(e,t),r=e.portLabelsPlacement.includes(`ALWAYS_OTHER_SAME_SIDE`);for(let i of e.portContexts.get(t)){let a=i.labelCell;if(a===null||a.getLabels().length===0)continue;let o=i.port.size,s=a.rect;switch(s.width=a.getMinimumWidth(),s.height=a.getMinimumHeight(),t){case`NORTH`:i.labelsNextToPort?(s.x=(o.x-s.width)/2,a.setHorizontalAlignment(`CENTER`)):n||r?(s.x=-s.width-e.portLabelSpacingH,a.setHorizontalAlignment(`RIGHT`)):(s.x=o.x+e.portLabelSpacingH,a.setHorizontalAlignment(`LEFT`)),s.y=-s.height-e.portLabelSpacingV,a.setVerticalAlignment(`BOTTOM`);break;case`SOUTH`:i.labelsNextToPort?(s.x=(o.x-s.width)/2,a.setHorizontalAlignment(`CENTER`)):n||r?(s.x=-s.width-e.portLabelSpacingH,a.setHorizontalAlignment(`RIGHT`)):(s.x=o.x+e.portLabelSpacingH,a.setHorizontalAlignment(`LEFT`)),s.y=o.y+e.portLabelSpacingV,a.setVerticalAlignment(`TOP`);break;case`EAST`:if(i.labelsNextToPort){let t=e.portLabelsTreatAsGroup?s.height:a.getLabels()[0].size.y;s.y=(o.y-t)/2,a.setVerticalAlignment(`CENTER`)}else n||r?(s.y=-s.height-e.portLabelSpacingV,a.setVerticalAlignment(`BOTTOM`)):(s.y=o.y+e.portLabelSpacingV,a.setVerticalAlignment(`TOP`));s.x=o.x+e.portLabelSpacingH,a.setHorizontalAlignment(`LEFT`);break;case`WEST`:if(i.labelsNextToPort){let t=e.portLabelsTreatAsGroup?s.height:a.getLabels()[0].size.y;s.y=(o.y-t)/2,a.setVerticalAlignment(`CENTER`)}else n||r?(s.y=-s.height-e.portLabelSpacingV,a.setVerticalAlignment(`BOTTOM`)):(s.y=o.y+e.portLabelSpacingV,a.setVerticalAlignment(`TOP`));s.x=-s.width-e.portLabelSpacingH,a.setHorizontalAlignment(`RIGHT`)}n=!1}}function Hs(e){let t=e.portLabelsPlacement,n=t.includes(`INSIDE`),r=t.includes(`OUTSIDE`);if((n||r)&&e.hasPortLabelCells){for(let t of fs)n?Bs(e,t):Vs(e,t);for(let t of fs)for(let n of e.portContexts.get(t))n.labelCell&&n.labelCell.applyLabelLayout()}}function Us(e){return`JUSTIFIED`}function Ws(t,n,r){let i=t.getPorts(n);if(i.length===0)return;let a=t.size.y,o=i.find(e=>e.size.y>0)?.size.y??i[0].size.y,s=o+(a-i.reduce((e,t)=>e+t.size.y,0))/(i.length+1),c=n===`WEST`;for(let n=0;n<i.length;n++){let r=i[n],a=c?(i.length-n)*s-o:(n+1)*s-o,l=r.getProperty(e.It)??0;r.getPosition().x=c?-r.size.x-l:t.size.x+l,r.getPosition().y=a}}function Gs(t,n,r){let i=t.getPorts(n);if(i.length===0)return;let a=t.size.x,o=i.reduce((e,t)=>e+t.size.x,0),s=a,c=Us(t),l=0,u=c;(c===`DISTRIBUTED`||c===`JUSTIFIED`)&&i.length===1&&(u=`CENTER`);let d=r;switch(u===`JUSTIFIED`&&(d=(s-o)/(i.length+1),l=d),u){case`CENTER`:l=(s-o)/2;break;case`END`:l=s-o}let f=l,p=n===`SOUTH`?[...i].reverse():i;for(let r of p){let i=n===`NORTH`,a=r.getProperty(e.It);r.getPosition().y=i?-r.size.y-(a??0):t.size.y+(a??0),r.getPosition().x=f,f+=r.size.x+d}}function Ks(t){let n=t.getProperty(e.pn);for(let e of t.getLayers())for(let t of e.getNodes())t.getType()===`NORMAL`&&Js(t,n);qs(t)}function qs(t){let n=t.getProperty(e.zt)??[],r=n.includes(`NEXT_TO_PORT_IF_POSSIBLE`),i=t.getProperty(`org.eclipse.elk.portLabels.treatAsGroup`)===!0;for(let a of t.getLayers())for(let t of a.getNodes()){if(t.getType()!==`EXTERNAL_PORT`)continue;let a=t.getPorts()[0];if(!a||a.getLabels().length===0)continue;let o=dn(t,e.sn),s=dn(t,e.cn),c=dn(t,e.an),l=t.size,u=a.position,d=a.getLabels(),f=0,p=0;for(let e of d)f=Math.max(f,e.size.x),p+=e.size.y;p+=(d.length-1)*c;let m={x:0,y:0,width:f,height:p},h=t.getProperty(e.Un),g=e=>r?e?a.getIncomingEdges().length===0&&a.getOutgoingEdges().length===0:a.getConnectedEdges().length===0:!1;if(n.includes(`INSIDE`))switch(h){case`NORTH`:m.x=(l.x-m.width)/2-u.x,m.y=s;break;case`SOUTH`:m.x=(l.x-m.width)/2-u.x,m.y=-s-m.height;break;case`EAST`:case`WEST`:if(g(!0)){let e=i?m.height:d[0].size.y;m.y=(l.y-e)/2-u.y}else m.y=l.y+s-u.y;m.x=h===`EAST`?-o-m.width:o}else if(n.includes(`OUTSIDE`))switch(h){case`NORTH`:case`SOUTH`:m.x=u.x+o;break;case`EAST`:case`WEST`:if(g(!1)){let e=i?m.height:d[0].size.y;m.y=(l.y-e)/2-u.y}else m.y=u.y+s}let _=m.y;for(let e of d)e.position.x=m.x,e.position.y=_,_+=e.size.y+c}}function Js(t,n){let r=js(t,t.getGraph(),!1);Ys(t,r);let i=t.getProperty(e.Lt);if(i===`FIXED_POS`||i===`FIXED_RATIO`||String(i)===`FIXED_POSITION`||String(i)===`FIXED_RATIO`){for(let n of t.getPorts(`NORTH`))n.isExplicitSide()&&(n.getPosition().y=-n.size.y-(n.getProperty(e.It)??0));for(let n of t.getPorts(`SOUTH`))n.isExplicitSide()&&(n.getPosition().y=t.size.y+(n.getProperty(e.It)??0));for(let n of t.getPorts(`WEST`))n.isExplicitSide()&&(n.getPosition().x=-n.size.x-(n.getProperty(e.It)??0));for(let n of t.getPorts(`EAST`))n.isExplicitSide()&&(n.getPosition().x=t.size.x+(n.getProperty(e.It)??0));Hs(r)}else if(t.getNestedGraph()===null){Ls(r,t.size.x,t.size.y);let e=t.size.y;for(let n of t.getPorts(`SOUTH`))n.getPosition().y+=e;Hs(r)}else Ws(t,`WEST`,n),Ws(t,`EAST`,n),Gs(t,`NORTH`,n),Gs(t,`SOUTH`,n),Hs(r)}function Ys(t,n){let r=t.getLabels(),i=t.getGraph(),a=t.hasProperty(e.Tt)?t.getProperty(e.Tt):i?.getProperty(e.Tt)??[];if(a.includes(`MINIMUM_SIZE`)){let n=t.hasProperty(e.Et)?t.getProperty(e.Et):{x:0,y:0};t.size.x=Math.max(t.size.x,n.x),t.size.y=Math.max(t.size.y,n.y)}if(a.includes(`PORTS`)&&t.getNestedGraph()===null){let r=Ms(n);if(r){let n=r.x,i=r.y;if(a.includes(`MINIMUM_SIZE`)){let r=t.hasProperty(e.Et)?t.getProperty(e.Et):{x:0,y:0};n=Math.max(n,r.x>0?r.x:20),i=Math.max(i,r.y>0?r.y:20)}t.size.x=n,t.size.y=i}}if(r.length===0)return;let o=a.includes(`NODE_LABELS`),s=t.hasProperty(e.gt)?t.getProperty(e.gt):i?.getProperty(e.gt)??{top:5,right:5,bottom:5,left:5},c=0,l=0;for(let e of r)c=Math.max(c,e.size.x),l=Math.max(l,e.size.y);let u=a.includes(`PORTS`)||a.includes(`PORT_LABELS`),d=t.getProperty(e.q)===`SEPARATE_CHILDREN`;if(o&&!u&&t.getNestedGraph()===null&&!d){let n=c,r=l;if(a.includes(`MINIMUM_SIZE`)){let i=t.hasProperty(e.Et)?t.getProperty(e.Et):{x:0,y:0};n=Math.max(n,i.x>0?i.x:20),r=Math.max(r,i.y>0?i.y:20)}a.includes(`MINIMUM_SIZE`)?(t.size.x=n,t.size.y=r):(t.size.x=n+s.left+s.right,t.size.y=r+s.top+s.bottom)}Xs(t,r,s,i)}function Xs(t,n,r,i){if(n.length===0)return;let a=i?.getProperty(e.an)??0,o=ta(t),s=t.getProperty(e._t),c=e=>{let t=e.placement??s??``;return Array.isArray(t)?t:String(t).split(/[\s,]+/).filter(Boolean)},l=e=>e.includes(`V_BOTTOM`)?`bottom`:e.includes(`V_CENTER`)?`center`:`top`,u=e=>e.includes(`H_RIGHT`)?`right`:e.includes(`H_LEFT`)?`left`:`center`,d=Array(n.length);for(let e=0;e<n.length;e++)d[e]=c(n[e]);let f=[],p=[];for(let e=0;e<n.length;e++)d[e].includes(`OUTSIDE`)?f.push(n[e]):p.push(n[e]);if(f.length>0)for(let e of f)$i(e,t.size,Zi(e,t),o);if(p.length===0)return;let m={top:{},center:{},bottom:{}};for(let e=0;e<n.length;e++){let t=d[e];if(t.includes(`OUTSIDE`))continue;let r=l(t),i=u(t);(m[r][i]??=[]).push(n[e])}let h=e=>{let t=0;for(let n of Object.values(m[e])){let e=n.reduce((e,t)=>e+t.size.y+a,0)-(n.length>0?a:0);t=Math.max(t,e)}return t},g=h(`top`),_=h(`bottom`),v=h(`center`),y=(e,n)=>{if(e===`top`)return r.top;if(e===`bottom`)return t.size.y-r.bottom-(n.reduce((e,t)=>e+t.size.y+a,0)-(n.length>0?a:0));let i=r.top+g+a;return i+(t.size.y-r.bottom-_-a-i-v)/2};for(let e of[`top`,`center`,`bottom`])for(let t of Object.keys(m[e])){let n=m[e][t],r=y(e,n);for(let e of n)e.position.y=r,r+=e.size.y+a}for(let e=0;e<n.length;e++){if(d[e].includes(`OUTSIDE`))continue;let i=n[e],a=u(d[e]);a===`right`?i.position.x=t.size.x-i.size.x-r.right:a===`left`?i.position.x=r.left:i.position.x=r.left+(t.size.x-r.left-r.right-i.size.x)/2}}function Zs(t){let n=t.getProperty(e.Ct);if(n!=null){t.setProperty(e.St,null);for(let n of t.getLayers())for(let t of n.getNodes())t.setProperty(e.xt,null),t.setProperty(e.Tt,null),t.position.y=0;Ks(t),na(t),Qs(n,t)}}function Qs(e,t){switch(e){case`SIMPLE`:on(t);break;case`INTERACTIVE`:sn(t);break;case`NETWORK_SIMPLEX`:new bn().process(t);break;case`BRANDES_KOEPF`:new an().process(t);break;default:throw Error(`未支持的节点放置策略: ${e}`)}}function $s(t){if(!t.getProperty(e.Gn).has(`EXTERNAL_PORTS`))return;let n=1/0,r=-1/0,i=1/0,a=-1/0;for(let e of t.getLayerlessNodes()){if(e.getType()!==`NORMAL`)continue;let t=e.getMargin();n=Math.min(n,e.position.x-t.left),r=Math.max(r,e.position.x+e.size.x+t.right),i=Math.min(i,e.position.y-t.top),a=Math.max(a,e.position.y+e.size.y+t.bottom)}for(let e of t.getLayerlessNodes())if(e.getType()!==`NORMAL`)switch(e.getType()){case`EXTERNAL_PORT`:{let t=e.getLayerConstraint();if(t===`FIRST_SEPARATE`){e.position.x=n-10;let t=ec(e,e=>e.getTarget()?.getNode()??null);t!==null&&(e.position.y=t);break}if(t===`LAST_SEPARATE`){e.position.x=r+10;let t=ec(e,e=>e.getSource()?.getNode()??null);t!==null&&(e.position.y=t);break}let o=e.getInLayerConstraint();if(o===`TOP`){let t=tc(e);t!==null&&(e.position.x=t+10),e.position.y=i-10;break}if(o===`BOTTOM`){let t=tc(e);t!==null&&(e.position.x=t+10),e.position.y=a+10;break}break}default:throw Error(`节点类型 ${e.getType()} 不受 InteractiveExternalPortPositioner 支持`)}}function ec(e,t){for(let n of e.getConnectedEdges()){let e=t(n);if(e!==null)return e.position.y+e.size.y/2}return null}function tc(e){if(e.getPorts().length!==1)throw Error(`外部端口 dummy 必须恰好一个端口`);let t=e.getPorts()[0];if(t.getOutgoingEdges().length>0&&t.getIncomingEdges().length>0)throw Error(`交互式布局不支持同时有入边和出边的 NORTH/SOUTH 端口`);if(t.getOutgoingEdges().length>0){let e=1/0;for(let n of t.getOutgoingEdges()){let t=n.getTarget().getNode(),r=t.getMargin();e=Math.min(e,t.position.x-r.left)}return e}if(t.getIncomingEdges().length>0){let e=-1/0;for(let n of t.getIncomingEdges()){let t=n.getSource().getNode(),r=t.getMargin();e=Math.max(e,t.position.x+t.size.x+r.right)}return e}return null}var nc=class{start;end;nodeStartEdge;startEndEdge;originalEdge;startInLayerDummy=null;startInLayerEdge=null;endInLayerDummy=null;endInLayerEdge=null;prev=null;next=null;constructor(e,t,n,r,i){this.start=e,this.end=t,this.nodeStartEdge=n,this.startEndEdge=r,this.originalEdge=i}static isStart(t){let n=t.getProperty(e.An);return n!==null&&n.start===t}static isEnd(t){let n=t.getProperty(e.An);return n!==null&&n.end===t}},rc=class{graph;spacing=0;inLayerSpacing=0;dar;longestPath;maxWidth=null;maxHeight=null;sumWidth=null;widths=null;heights=null;cutsAllowed=null;constructor(t){this.graph=t;let n=t.getProperty(e.F),r=t.getProperty(e.h),i=t.getProperty(e._n);this.dar=n===`LEFT`||n===`RIGHT`||n===`UNDEFINED`?r*i:1/(r*i),this.spacing=t.getProperty(e.un),this.inLayerSpacing=t.getProperty(e.ln),this.longestPath=t.getLayers().length}getApproximateLayerWidth(e){return this.determineLayerWidth(e)}getApproximateLayeringWidth(){return this.getSumWidth()}getApproximateChunkBasedLayeringWidth(e){if(e.length===0)return this.getApproximateLayeringWidth();let t=0,n=0;for(let r of e)t=Math.max(t,this.determineChunkWidth(n,r)),n=r;return t=Math.max(t,this.determineChunkWidth(n,this.graph.getLayers().length)),t}getApproximateLayerHeight(e){return this.determineLayerHeight(e)}getApproximateLayeringHeight(){return this.getMaxHeight()}getApproximateChunkBasedLayeringHeight(e){if(e.length===0)return 0;let t=0,n=0;for(let r of e)t+=this.determineChunkHeight(n,r),n=r;return t+=this.determineChunkHeight(n,this.graph.getLayers().length),t}getMaxWidth(){return this.maxWidth===null&&(this.maxWidth=this.determineWidth((e,t)=>Math.max(e,t))),this.maxWidth}getSumWidth(){return this.sumWidth===null&&(this.sumWidth=this.determineWidth((e,t)=>e+t)),this.sumWidth}getWidths(){return this.widths===null&&this.initWidthsAndHeights(),this.widths}initWidthsAndHeights(){let e=this.longestPath,t=Array(e),n=Array(e);for(let r=0;r<e;r++){let e=this.graph.getLayers()[r];t[r]=this.determineLayerWidth(e),n[r]=this.determineLayerHeight(e)}this.widths=t,this.heights=n}determineWidth(e){let t=this.graph.getLayers(),n=this.determineLayerWidth(t[0]);for(let r=1;r<t.length;r++)n=e(n,this.determineLayerWidth(t[r]));return n}determineLayerWidth(e){let t=0;for(let n of e.getNodes()){let e=n.getSize().x+n.getMargin().right+n.getMargin().left+this.spacing;t=Math.max(t,e)}return t}determineChunkWidth(e,t){let n=0;for(let r=e;r<t;r++)n+=this.determineLayerWidth(this.graph.getLayers()[r]);return n}getMaxHeight(){return this.maxHeight===null&&(this.maxHeight=this.determineHeight((e,t)=>Math.max(e,t))),this.maxHeight}getHeights(){return this.heights===null&&this.initWidthsAndHeights(),this.heights}determineHeight(e){let t=this.graph.getLayers(),n=this.determineLayerHeight(t[0]);for(let r=1;r<t.length;r++)n=e(n,this.determineLayerHeight(t[r]));return n}determineLayerHeight(t){let n=0;for(let r of t.getNodes()){n+=r.getSize().y+r.getMargin().bottom+r.getMargin().top+this.inLayerSpacing;for(let t of r.getIncomingEdges())if(t.getSource().getNode().getType()===`NORTH_SOUTH_PORT`){let r=t.getSource().getNode().getProperty(e.lr);n+=r.getSize().y+r.getMargin().bottom+r.getMargin().top}}return n}determineChunkHeight(e,t){let n=0;for(let r=e;r<t;r++)n=Math.max(n,this.determineLayerHeight(this.graph.getLayers()[r]));return n}isCutAllowed(e){return this.cutsAllowed===null&&this.initCutAllowed(),this.cutsAllowed[e]}initCutAllowed(){if(this.cutsAllowed!==null)return;let t=Array(this.graph.getLayers().length);if(t[0]=!1,this.graph.hasProperty(e.Tn)){let n=this.graph.getProperty(e.Tn);if(n!==null)for(let e of n)e>0&&e<t.length&&(t[e]=!1)}else{let e=this.graph.getLayers();for(let n=1;n<e.length;n++)t[n]=this.isCutAllowedPerLayer(e[n])}this.cutsAllowed=t}getCutsAllowed(){return this.cutsAllowed===null&&this.initCutAllowed(),this.cutsAllowed}isCutAllowedPerLayer(e){let t=!0,n=null,r=null;check:for(let i of e.getNodes())for(let e of i.getIncomingEdges()){if(n!==null&&n!==i){t=!1;break check}n=i;let a=e.getSource().getNode();if(r!==null&&r!==a){t=!1;break check}r=a}return t}},ic=class{getCutIndexes(t,n){let r=t.getProperty(e.vn);return r===null?[]:r}guaranteeValid(){return!1}},ac=class e{getCutIndexes(t,n){let r=e.getChunkCount(n),i=[],a=n.longestPath/r;for(let e=1;e<r;++e)i.push(Math.round(e*a));return i}static getChunkCount(e){let t=Math.sqrt(e.getSumWidth()/(e.dar*e.getMaxHeight())),n=Math.round(t);return n=Math.min(n,e.longestPath),n}guaranteeValid(){return!1}},oc=class{guaranteeValid(){return!1}getCutIndexes(t,n){let r=n.getWidths(),i=n.getHeights(),a=Array(r.length);a[0]=r[0];let o=r[0];for(let e=1;e<r.length;e++)a[e]=a[e-1]+r[e],o+=r[e];let s=ac.getChunkCount(n)-1,c=t.getProperty(e.yn),l=-1/0,u=[];for(let e=Math.max(0,s-c);e<=Math.min(n.longestPath-1,s+c);e++){let t=o/(e+1),r=0,s=1,c=[],d=-1/0,f=0,p=0,m=i[0];if(e===0)d=o,p=n.getMaxHeight();else{for(;s<n.longestPath;)a[s-1]-r>=t&&(c.push(s),d=Math.max(d,a[s-1]-f),p+=m,r+=a[s-1]-r,f=a[s-1],m=i[s]),m=Math.max(m,i[s]),s++;p+=m}let h=Math.min(1/d,1/n.dar/p);h>l&&(l=h,u=c)}return u}};function sc(t,n,r){let i=t.getProperty(e.nn),a=t.getProperty(e.gn),o=new e.ii;o.setProperty(e.nn,i+a);let s=n,c=s.getTarget(),l=s.getSource().getNode(),u=s.getTarget().getNode(),d=l.getLayer().getIndex(),h=u.getLayer().getIndex(),g=[];for(let n=d;n<=h;n++){let i=new f(t);i.setType(`LONG_EDGE`),i.setProperty(e.lr,s),i.setProperty(e.Lt,`FIXED_POS`),i.setProperty(e.in,o);let a=t.getLayers()[n];n===d?i.setLayerAt(a.getNodes().length-r,a):i.setLayer(a);let l=s.getProperty(e.W);l<0&&(l=0,s.setProperty(e.W,l)),i.size.y=l;let u=Math.floor(l/2),h=new p;h.setSide(`WEST`),h.setNode(i),h.getPosition().y=u;let _=new p;_.setSide(`EAST`),_.setNode(i),_.getPosition().y=u,s.setTarget(h);let v=new m;v.copyProperties(s),v.setProperty(e.nt,null),v.setSource(_),v.setTarget(c),cc(i,s,v),g.push(v),s=v}return g}function cc(t,n,r){let i=n.getSource().getNode();i.getType()===`LONG_EDGE`?(t.setProperty(e.rr,i.getProperty(e.rr)),t.setProperty(e.ir,i.getProperty(e.ir))):(t.setProperty(e.rr,n.getSource()),t.setProperty(e.ir,r.getTarget()))}function lc(e,t){let n=[],r=0,i=0;for(;i<t.length;){let a=t[i]+r;for(;a<e.longestPath&&!e.isCutAllowed(a);)a++,r++;if(a>=e.longestPath)break;n.push(a),i++}return n}function uc(e,t){if(t.length===0)return[];let n=[-(2**53-1)];for(let t=1;t<e.longestPath;++t)e.isCutAllowed(t)&&n.push(t);return n.length===1?[]:(n.push(2**53-1),dc(t,n))}function dc(e,t){let n=[],r=0,i=0,a=0;for(;r<t.length-1&&i<e.length;){let o=e[i]+a;for(;t[r+1]<o;)r++;let s=0;for(o-t[r]>t[r+1]-o&&s++,n.push(t[r+s]),a+=t[r+s]-o,i++;i<e.length&&e[i]+a<=t[r+s];)i++;r+=1+s}return n}function fc(t){let n=new rc(t),r=pc(t),i=r.getCutIndexes(t,n);if(t.getProperty(e.Sn)&&(i=hc(t,i)),!r.guaranteeValid()&&t.hasProperty(e.En))switch(t.getProperty(e.En)){case`LOOK_BACK`:i=uc(n,i);break;case`GREEDY`:i=lc(n,i)}i.length!==0&&mc(t,i)}function pc(t){switch(t.getProperty(e.bn)){case`MANUAL`:return new ic;case`ARD`:return new ac;default:return new oc}}function mc(t,n){let r=t.getLayers(),i=0,a=0,o=n[0],s=0,c=/* @__PURE__ */ new Set,l=/* @__PURE__ */ new Set,u=0;for(;u<r.length;){let d=r[u];for(let e of d.getNodes()){for(let t of e.getOutgoingEdges())l.add(t);for(let t of e.getIncomingEdges())l.delete(t)}if(i+1===o){let i=new w(t);r.splice(u+1,0,i);let d=new w(t);r.splice(u+2,0,d);for(let n of l){c.has(n)||(s++,c.add(n));let r=new f(t);r.setProperty(e.Lt,`FIXED_SIDE`),r.setLayer(i),r.setType(`BREAKING_POINT`);let a=new p;a.setNode(r),a.setSide(`WEST`);let o=new p;o.setNode(r),o.setSide(`EAST`);let l=new f(t);l.setProperty(e.Lt,`FIXED_SIDE`),l.setLayer(d),l.setType(`BREAKING_POINT`);let u=new p;u.setNode(l),u.setSide(`WEST`);let h=new p;h.setNode(l),h.setSide(`EAST`);let g=new m;g.setSource(n.getSource()),g.setTarget(a),g.setProperty(e.cr,n.getProperty(e.cr));let _=new m;_.setSource(o),_.setTarget(u),_.setProperty(e.cr,n.getProperty(e.cr)),n.setSource(h);let v=new nc(r,l,g,_,n);r.setProperty(e.An,v),l.setProperty(e.An,v);let y=g.getSource().getNode();if(y.getType()===`BREAKING_POINT`){let t=y.getProperty(e.An);t.next=v,v.prev=t}}if(u+=2,a++,a<n.length)o=n[a];else break}i++,u++}return s}function hc(e,t){let n=[],r=[],i=null;for(let e of t){let t=new vc(e);r.push(t),i!==null&&(t.prev=i,i.suc=t),i=t}let a=_c(e);for(let t=0;t<r.length;++t){let t=null,i=r[0].selfOrNext(),o=null,s=1/0;for(let n=1;n<e.getLayers().length;++n){let r=i===null?Math.abs(n-t.index)+1:Math.abs(i.index-n),c=t===null?r+1:Math.abs(n-t.index),l,u;c<r?(l=t,u=c):(l=i,u=r);let d=gc(e,n,a[n],u);d<s&&(s=d,o=l,o.newIndex=n),i!==null&&n===i.index&&(t=i,i=i.next())}o!==null&&(n.push(o.newIndex),o.assigned=!0,o.offset())}return n.sort((e,t)=>e-t),n}function gc(t,n,r,i){return r+i**+t.getProperty(e.xn)}function _c(e){let t=Array(e.getLayers().length+1),n=/* @__PURE__ */ new Set,r=0;for(let i of e.getLayers()){t[r++]=n.size;for(let e of i.getNodes())for(let t of e.getOutgoingEdges())n.add(t);for(let e of i.getNodes())for(let t of e.getIncomingEdges())n.delete(t)}return t}var vc=class{index;newIndex=0;prev=null;suc=null;assigned=!1;constructor(e){this.index=e}selfOrNext(){return this.assigned?this.suc===null?null:this.suc.selfOrNext():this}next(){return this.suc===null?null:this.suc.selfOrNext()}offset(){if(!this.assigned)throw Error(`Cannot offset an unassigned cut.`);let e=this.newIndex-this.index;this.applyOffset(e),this.offsetPrev(e),this.offsetSuc(e)}applyOffset(e){this.index+=e}offsetPrev(e){this.prev!==null&&!this.prev.assigned&&(this.prev.applyOffset(e),this.prev.offsetPrev(e))}offsetSuc(e){this.suc!==null&&!this.suc.assigned&&(this.suc.applyOffset(e),this.suc.offsetSuc(e))}};function yc(t){if(bc(t),t.getProperty(e.Cn)){let e=/* @__PURE__ */ new Map;for(let n of t.getLayers()){let t=0;for(let r of n.getNodes())e.set(r,t++)}xc(t,e),Sc(t,e,!0),Sc(t,e,!1)}}function bc(t){let n=t.getLayers();n.unshift(new w(t));let r=!1,i=1,a=1;for(;a<n.length;){let o=n[a],s=n[i],c=[...o.getNodes()],l=c.length;for(let e of c)e.setLayer(s);if(r){for(let n of[...c].reverse())for(let r of[...n.getIncomingEdges()]){r.reverse(t,!0),t.setProperty(e.Ln,!0);let i=sc(t,r,l),a=n.getProperty(e.An),o=i[i.length-1];a.startInLayerDummy=o.getSource().getNode(),a.startInLayerEdge=o,a.endInLayerDummy=r.getTarget().getNode(),a.endInLayerEdge=r}r=!1}else c.length>0&&c[0].getType()===`BREAKING_POINT`&&(r=!0,i=-1);i++,a++}for(let e=n.length-1;e>=0;e--)n[e].getNodes().length===0&&n.splice(e,1)}function xc(t,n){for(let r of t.getLayers())for(let t of[...r.getNodes()])if(nc.isStart(t)){let r=t.getProperty(e.An);if(r.prev===null&&r.next!==null){let t=r,i=r.next;for(;i!==null;){Cc(n,i.start,i.startInLayerDummy,!1,!0),Dc(n,t.end),Dc(n,i.start),Dc(n,i.startInLayerDummy),Dc(n,i.endInLayerDummy),i.endInLayerEdge.setTarget(t.endInLayerEdge.getTarget()),t.endInLayerEdge.setTarget(null),t.end.setLayer(null),i.start.setLayer(null),i.startInLayerDummy.setLayer(null),i.endInLayerDummy.setLayer(null);let r=new nc(t.start,i.end,t.nodeStartEdge,i.startEndEdge,i.originalEdge);r.startInLayerDummy=t.startInLayerDummy,r.startInLayerEdge=t.startInLayerEdge,r.endInLayerDummy=t.endInLayerDummy,r.endInLayerEdge=i.endInLayerEdge,r.prev=t.prev,r.next=i.next,t.start.setProperty(e.An,r),i.end.setProperty(e.An,r),i=i.next,t=r}}}}function Sc(t,n,r){let i=r?nc.isEnd:nc.isStart,a=!1;do{a=!1;let o=r?[...t.getLayers()].reverse():t.getLayers();for(let t of o){let o=[...t.getNodes()];r||o.reverse();for(let t of o)if(i(t)){let i=t,o=t.getProperty(e.An);a=Cc(n,i,r?o.endInLayerDummy:o.startInLayerDummy,r,!1)}}}while(a)}function Cc(e,t,n,r,i){let a=Tc(t,r),o=Tc(n,r),s=!1;for(;a!==null&&o!==null&&(i||wc(e,a,o,r));){let i=Tc(a,r),c=Tc(o,r);Dc(e,n),Dc(e,t);let l=a.getLayer(),u=e.get(o),d=e.get(a);Ue(a,!1),Ue(o,!1),r?(n.setLayerAt(u,l),e.set(n,u),t.setLayerAt(d+1,l),e.set(t,d)):(t.setLayerAt(d,l),e.set(t,d),n.setLayerAt(u+1,l),e.set(n,u)),a.setLayer(null),o.setLayer(null),a=i,o=c,s=!0}return s}function wc(e,t,n,r){let i=t.getLayer(),a=r?n:t,o=r?t:n,s=e.get(a),c=e.get(o);for(let e=s+1;e<c;++e){let t=i.getNodes()[e];if(t.getType()!==`BREAKING_POINT`&&!Ec(t))return!1}return!0}function Tc(e,t){let n=t?e.getOutgoingEdges():e.getIncomingEdges();for(let t of n){let n=t.getOtherNode(e);if(n!==null&&n.getType()===`LONG_EDGE`&&n.getLayer()!==e.getLayer())return n}return null}function Ec(e){if(e.getType()===`LONG_EDGE`){for(let t of e.getConnectedEdges())if(!t.isSelfLoop()&&e.getLayer()===t.getOtherNode(e)?.getLayer())return!0}return!1}function Dc(e,t){let n=e.get(t),r=t.getLayer().getNodes();for(let t=n+1;t<r.length;++t){let n=r[t];e.set(n,e.get(n)-1)}}function Oc(t){let n=t.getProperty(e.B);for(let r of t.getLayers())for(let i of[...r.getNodes()])if(nc.isEnd(i)){let r=i.getProperty(e.An);r.next===null&&kc(t,r,n)}}function kc(t,n,r){let i=[];switch(r){case`SPLINES`:{let t=n.nodeStartEdge.getProperty(e.Dr)??[],r=n.startEndEdge.getProperty(e.Dr)??[],i=n.originalEdge.getProperty(e.Dr)??[],a=n.nodeStartEdge.getProperty(e.Tr)??[],o=n.startEndEdge.getProperty(e.Tr)??[],s=n.originalEdge.getProperty(e.Tr)??[],c=[];c.push(...t);for(let e of r)e.inverseOrder=!0;c.push(...[...r].reverse()),c.push(...i);let l=[];l.push(...a),l.push(...[...o].reverse()),l.push(...s),n.originalEdge.setProperty(e.Dr,c),n.originalEdge.setProperty(e.Tr,l),n.originalEdge.setProperty(e.Or,n.originalEdge),n.nodeStartEdge.setProperty(e.Dr,null),n.nodeStartEdge.setProperty(e.Tr,null),n.startEndEdge.setProperty(e.Dr,null),n.startEndEdge.setProperty(e.Tr,null);break}case`POLYLINE`:i.push(...n.nodeStartEdge.getBendPoints()),i.push(e.ti(n.start.getPosition().x,n.start.getPosition().y)),i.push(...[...n.startEndEdge.getBendPoints()].reverse()),i.push(e.ti(n.end.getPosition().x,n.end.getPosition().y)),i.push(...n.originalEdge.getBendPoints());break;default:i.push(...n.nodeStartEdge.getBendPoints()),i.push(...[...n.startEndEdge.getBendPoints()].reverse()),i.push(...n.originalEdge.getBendPoints())}let a=n.originalEdge.getBendPoints();a.splice(0,a.length,...i),n.originalEdge.setSource(n.nodeStartEdge.getSource());let o=n.nodeStartEdge.getProperty(e.nt),s=n.startEndEdge.getProperty(e.nt),c=n.originalEdge.getProperty(e.nt);if(o!==null||s!==null||c!==null){let t=[];Ac(t,c),Ac(t,s),Ac(t,o),n.originalEdge.setProperty(e.nt,t)}n.startEndEdge.setSource(null),n.startEndEdge.setTarget(null),n.nodeStartEdge.setSource(null),n.nodeStartEdge.setTarget(null),n.end.setLayer(null),n.start.setLayer(null),n.prev!==null&&kc(t,n.prev,r)}function Ac(e,t){t!=null&&e.push(...t)}function jc(t){for(let n of t.getLayers())for(let r of n.getNodes())for(let n of r.getPorts())for(let r of[...n.getOutgoingEdges()])r.getProperty(e.Sr)&&r.reverse(t,!1)}const W={NORTH:0,EAST:1,SOUTH:2,WEST:3,UNDEFINED:4},Mc=(e,t)=>W[e.getSide()]-W[t.getSide()],Nc=(t,n)=>{let r=t.getNode().getProperty(e.Lt);if(W[t.getSide()]-W[n.getSide()]!==0||!e.Lr.isOrderFixed(r))return 0;if(r===`FIXED_ORDER`){let r=t.getProperty(e.Rt),i=n.getProperty(e.Rt);if(r!==null&&i!==null&&r-i!==0)return r-i}switch(t.getSide()){case`NORTH`:return t.getPosition().x-n.getPosition().x;case`EAST`:return t.getPosition().y-n.getPosition().y;case`SOUTH`:return n.getPosition().x-t.getPosition().x;case`WEST`:return n.getPosition().y-t.getPosition().y;default:return 0}},Pc=(e,t)=>Mc(e,t)||Nc(e,t),Fc=(t,n)=>n(t).filter(t=>!t.getProperty(e.Sr)).length,Ic=(e,t)=>{if(W[e.getSide()]-W[t.getSide()]!==0)return 0;switch(e.getSide()){case`EAST`:return Fc(t,e=>e.getOutgoingEdges())-Fc(e,e=>e.getOutgoingEdges());case`WEST`:return Fc(e,e=>e.getIncomingEdges())-Fc(t,e=>e.getIncomingEdges());default:return 0}};function Lc(e,t,n){if(n-t<=2)return;let r=Math.floor((n-t)/2);for(let i=0;i<r;i++)[e[t+i],e[n-i-1]]=[e[n-i-1],e[t+i]]}function Rc(e,t){if(e.length===0)return[0,0];let n=W[t],r=n+1,i=0,a=W[e[0].getSide()];for(;i<e.length-1&&a<n;)i++,a=W[e[i].getSide()];let o=i;for(;o<e.length-1&&a<r;)o++,a=W[e[i].getSide()];return[i,o]}function zc(e){if(e.length<=1)return;let[t,n]=Rc(e,`SOUTH`);Lc(e,t,n);let[r,i]=Rc(e,`WEST`);Lc(e,r,i)}function Bc(t){let n=t.getProperty(e.Vt);for(let r of t.getLayers())for(let t of r.getNodes()){let r=t.getProperty(e.Lt),i=t.getPorts();e.Lr.isOrderFixed(r)?i.sort(Pc):e.Lr.isSideFixed(r)&&(i.sort(Mc),zc(i),n===`PORT_DEGREE`&&i.sort(Ic))}}function Vc(e){let t=e.getPorts(),n=t.length,r=0,i=n,a=2*n,o=/* @__PURE__ */ new Map;for(let e of t)switch(e.getSide()){case`EAST`:case`WEST`:o.set(e,-1);break;case`NORTH`:case`SOUTH`:{let t=e.getIncomingEdges().length,n=e.getOutgoingEdges().length;t>0&&n>0?o.set(e,i++):t>0?o.set(e,r++):n>0?o.set(e,a++):o.set(e,r++);break}default:o.set(e,-1)}t.sort((e,t)=>{let n=e.getSide(),r=t.getSide();if(n!==r)return Hc[n]-Hc[r];let i=o.get(e),a=o.get(t);return i===a?0:n===`NORTH`?i-a:a-i})}const Hc={UNDEFINED:0,NORTH:1,EAST:2,SOUTH:3,WEST:4};function Uc(t,n,r,i){let a=new f(t);a.setType(`NORTH_SOUTH_PORT`),a.setProperty(e.Lt,`FIXED_POS`);let o=0;if(n!==null){let t=new p;t.setProperty(e.lr,n),a.setProperty(e.lr,n.getNode()),t.setSide(`WEST`),t.setNode(a);for(let e of[...n.getIncomingEdges()])e.setTarget(t);n.setProperty(e._r,a),n.setProperty(e.vr,!1),o++}if(r!==null){let t=new p;a.setProperty(e.lr,r.getNode()),t.setProperty(e.lr,r),t.setSide(`EAST`),t.setNode(a);for(let e of[...r.getOutgoingEdges()])e.setSource(t);r.setProperty(e._r,a),r.setProperty(e.vr,!0),o++}return a.setProperty(e.Nn,o),i.push(a),a}function Wc(e,t,n,r){let[i,a,o]=t.reduce((e,t)=>{let n=t.getIncomingEdges().length>0,r=t.getOutgoingEdges().length>0;return n&&r?e[2].push(t):n?e[0].push(t):r&&e[1].push(t),e},[[],[],[]]);for(let t of i)r.push(Uc(e,t,null,n));for(let t of a)r.push(Uc(e,null,t,n));for(let t of o)r.push(Uc(e,t,t,n))}function Gc(t){for(let n of t.getLayers()){let r=-1;for(let i of[...n.getNodes()]){if(r++,!(i.getType()===`NORMAL`&&e.Lr.isSideFixed(i.getProperty(e.Lt))))continue;!e.Lr.isOrderFixed(i.getProperty(e.Lt))&&t.getProperty(e.O)===`NONE`&&Vc(i),i.setProperty(e.Zn,i);let a=[],o=[],s=[];Wc(t,i.getPorts(`NORTH`),a,s);let c=r,l=i;for(let t of a)t.setLayerAt(c,n),r++,t.setProperty(e.Zn,i),t.getPorts()[0].getProperty(e.lr)?.getProperty(e.m)||(t.hasProperty(e.Qn)||t.setProperty(e.Qn,[]),t.getProperty(e.Qn).push(l));Wc(t,[...i.getPorts(`SOUTH`)].reverse(),o,s);let u=i;for(let t of o)t.setLayerAt(++r,n),t.setProperty(e.Zn,i),t.getPorts()[0].getProperty(e.lr)?.getProperty(e.m)||(u.hasProperty(e.Qn)||u.setProperty(e.Qn,[]),u.getProperty(e.Qn).push(t));s.length>0&&i.setProperty(e.On,s)}}}const Kc={NORTH:0,EAST:1,SOUTH:2,WEST:3,UNDEFINED:4};function G(e){return Kc[e]}function qc(e){switch(e){case`NORTH`:return`EAST`;case`EAST`:return`SOUTH`;case`SOUTH`:return`WEST`;case`WEST`:return`NORTH`;default:return`UNDEFINED`}}function Jc(e){switch(e){case`NORTH`:return`WEST`;case`WEST`:return`SOUTH`;case`SOUTH`:return`EAST`;case`EAST`:return`NORTH`;default:return`UNDEFINED`}}var Yc=class{id=0;lLabels=[];size={x:0,y:0};position={x:0,y:0};layoutDirection;labelLabelSpacing;side=null;alignment=null;alignmentReferenceSLPort=null;constructor(t){let n=t.getSLHolder().getLNode();this.layoutDirection=n.getGraph().getProperty(e.F),this.labelLabelSpacing=n.getGraph().getProperty(e.an)}addLLabels(e){for(let t of e)this.lLabels.push(t),this.updateSize(t)}getLLabels(){return this.lLabels}getSize(){return this.size}getPosition(){return this.position}getSide(){return this.side}setSide(e){this.side=e}getAlignment(){return this.alignment}setAlignment(e){this.alignment=e}getAlignmentReferenceSLPort(){return this.alignmentReferenceSLPort}setAlignmentReferenceSLPort(e){this.alignmentReferenceSLPort=e}updateSize(e){let t=e.size;this.layoutDirection===`LEFT`||this.layoutDirection===`RIGHT`?(this.size.x=Math.max(this.size.x,t.x),this.size.y+=t.y,this.lLabels.length>1&&(this.size.y+=this.labelLabelSpacing)):(this.size.x+=t.x,this.size.y=Math.max(this.size.y,t.y),this.lLabels.length>1&&(this.size.x+=this.labelLabelSpacing))}applyPlacement(e){this.layoutDirection===`LEFT`||this.layoutDirection===`RIGHT`?this.applyPlacementForHorizontalLayout(e):this.applyPlacementForVerticalLayout(e)}applyPlacementForHorizontalLayout(e){let t=this.position.x,n=this.position.y;for(let r of this.lLabels){let i=r.position;i.x=this.alignment===`LEFT`||this.side===`EAST`?t:this.alignment===`RIGHT`||this.side===`WEST`?t+this.size.x-r.size.x:t+(this.size.x-r.size.x)/2,i.y=n,i.x+=e.x,i.y+=e.y,n+=r.size.y+this.labelLabelSpacing}}applyPlacementForVerticalLayout(e){let t=this.position.x,n=this.position.y;for(let r of this.lLabels){let i=r.position;i.x=t,i.y=this.side===`NORTH`?n+this.size.y-r.size.y:n,i.x+=e.x,i.y+=e.y,t+=r.size.x+this.labelLabelSpacing}}};function Xc(e){if(e.has(`UNDEFINED`))throw Error(`Port sides must not contain UNDEFINED`);switch(e.size){case 1:return`ONE_SIDE`;case 2:{let t=e.has(`EAST`)&&e.has(`WEST`),n=e.has(`NORTH`)&&e.has(`SOUTH`);return t||n?`TWO_SIDES_OPPOSING`:`TWO_SIDES_CORNER`}case 3:return`THREE_SIDES`;case 4:return`FOUR_SIDES`;default:return null}}var Zc=class{slHolder;slPorts=[];slEdges=/* @__PURE__ */ new Set;slLabels=null;selfLoopType=null;slPortsBySide=null;leftmostPort=null;rightmostPort=null;occupiedPortSides=/* @__PURE__ */ new Set;routingSlot=[,,,,,].fill(0);constructor(e){this.slHolder=e}getSLHolder(){return this.slHolder}addSelfLoopEdge(e){if(this.slEdges.has(e))return;this.slEdges.add(e),e.setSLHyperLoop(this);let t=e.getSLSource();this.slPorts.includes(t)||this.slPorts.push(t);let n=e.getSLTarget();this.slPorts.includes(n)||this.slPorts.push(n);let r=e.getLEdge().getLabels();r.length>0&&(this.slLabels===null&&(this.slLabels=new Yc(this)),this.slLabels.addLLabels(r))}computePortsPerSide(){this.slPortsBySide=/* @__PURE__ */ new Map;for(let e of this.slPorts){let t=e.getLPort().getSide(),n=this.slPortsBySide.get(t)??[];n.push(e),this.slPortsBySide.set(t,n)}this.selfLoopType=Xc(new Set(this.slPortsBySide.keys()))}getSLPorts(){return this.slPorts}getSLEdges(){return this.slEdges}getSLLabels(){return this.slLabels}getSelfLoopType(){return this.selfLoopType}getSLPortsBySideMap(){return this.slPortsBySide}getSLPortsBySide(e){return this.slPortsBySide.get(e)??[]}hasSLPortsOnSide(e){return this.slPortsBySide.has(e)}getLeftmostPort(){return this.leftmostPort}setLeftmostPort(e){this.leftmostPort=e}getRightmostPort(){return this.rightmostPort}setRightmostPort(e){this.rightmostPort=e}getOccupiedPortSides(){return this.occupiedPortSides}getRoutingSlot(e){return this.routingSlot[G(e)]}setRoutingSlot(e,t){this.routingSlot[G(e)]=t;let n=this.slHolder.getRoutingSlotCount(),r=G(e);n[r]=Math.max(n[r],t+1)}},Qc=class{lEdge;slHyperLoop=null;slSource;slTarget;constructor(e,t,n){this.lEdge=e,this.slSource=t,this.slTarget=n,t.getOutgoingSLEdges().push(this),n.getIncomingSLEdges().push(this)}getLEdge(){return this.lEdge}getSLHyperLoop(){return this.slHyperLoop}setSLHyperLoop(e){this.slHyperLoop=e}getSLSource(){return this.slSource}getSLTarget(){return this.slTarget}getLabelSide(){return this.slHyperLoop.getSLLabels().getSide()}},$c=class{lPort;onlySelfLoops;incomingSLEdges=[];outgoingSLEdges=[];hidden=!1;constructor(e){this.lPort=e,this.onlySelfLoops=e.getConnectedEdges().length>0&&e.getConnectedEdges().every(e=>e.isSelfLoop())}getLPort(){return this.lPort}hadOnlySelfLoops(){return this.onlySelfLoops}isHidden(){return this.hidden}setHidden(e){this.hidden=e}getIncomingSLEdges(){return this.incomingSLEdges}getOutgoingSLEdges(){return this.outgoingSLEdges}getSLNetFlow(){return this.incomingSLEdges.length-this.outgoingSLEdges.length}},el=class t{lNode;slHyperLoops=[];slPorts=/* @__PURE__ */ new Map;arePortsHidden=!1;routingSlotCount=[,,,,,].fill(0);constructor(e){this.lNode=e}static needsSelfLoopProcessing(e){return e.getType()===`NORMAL`&&e.getOutgoingEdges().some(e=>e.isSelfLoop())}static install(n){if(!t.needsSelfLoopProcessing(n))throw Error(`AssertionError: needsSelfLoopProcessing`);let r=new t(n);return n.setProperty(e.Cr,r),r.initialize(),r}getLNode(){return this.lNode}getSLHyperLoops(){return this.slHyperLoops}getSLPortMap(){return this.slPorts}arePortsHiddenFlag(){return this.arePortsHidden}setPortsHidden(e){this.arePortsHidden=e}getRoutingSlotCount(){return this.routingSlotCount}initialize(){let e=[];for(let t of this.lNode.getOutgoingEdges())t.isSelfLoop()&&e.push(new Qc(t,this.selfLoopPortFor(t.getSource()),this.selfLoopPortFor(t.getTarget())));for(let e of this.slPorts.values())e.getLPort().id=0;for(let e of this.slPorts.values())e.getLPort().id===0&&this.slHyperLoops.push(this.initializeHyperLoop(e))}selfLoopPortFor(e){let t=this.slPorts.get(e);return t===void 0&&(t=new $c(e),this.slPorts.set(e,t)),t}initializeHyperLoop(e){let t=new Zc(this),n=[e];for(;n.length>0;){let e=n.shift();e.getLPort().id=1;for(let r of e.getOutgoingSLEdges()){t.addSelfLoopEdge(r);let e=r.getSLTarget();e.getLPort().id===0&&n.push(e)}for(let r of e.getIncomingSLEdges()){t.addSelfLoopEdge(r);let e=r.getSLSource();e.getLPort().id===0&&n.push(e)}}return t}};function tl(e){for(let t of e.getLayerlessNodes())if(el.needsSelfLoopProcessing(t)){let e=el.install(t);nl(e),il(e)}}function nl(e){for(let t of e.getSLHyperLoops())for(let e of t.getSLEdges())rl(e.getLEdge())}function rl(e){e.setSource(null),e.setTarget(null)}function il(t){let n=t.getLNode(),r=n.getNestedGraph(),i=e.Lr.isOrderFixed(n.getProperty(e.Lt)),a=r!==null&&r.getProperty(e.Gn).has(`EXTERNAL_PORTS`);if(!(i||a))for(let e of t.getSLPortMap().values())e.hadOnlySelfLoops()&&(e.getLPort().setNode(null),e.setHidden(!0),t.setPortsHidden(!0))}function al(t){let n=t.getProperty(e.en)*2;for(let e of t.getLayers()){let{north:t,south:r}=ol(e);sl(t,!0,n),sl(r,!1,n)}}function ol(t){let n=[],r=[];for(let i of t.getNodes()){if(i.getType()!==`EXTERNAL_PORT`)continue;let t=i.getProperty(e.Un);t===`NORTH`?n.push(i):t===`SOUTH`&&r.push(i)}return{north:n,south:r}}function sl(t,n,r){let i=n?0:r*(t.length-1),a=n?r:-r;for(let n of t){n.setProperty(e.p,`CENTER`),n.size.x=i;for(let e of n.getPorts(`EAST`))e.getPosition().x=i;i+=a}}var cl=class{process(e){this.processEasternAndWesternPortDummies(e),this.processNorthernAndSouthernPortDummies(e)}processEasternAndWesternPortDummies(t){if(!e.Lr.isOrderFixed(t.getProperty(e.Lt)))return;let n=t.getLayers();n.length!==0&&(this.processEW(n[0]),this.processEW(n[n.length-1]))}processEW(t){let n=[...t.getNodes()];n.sort((t,n)=>{let r=t.getType(),i=n.getType(),a=t.getProperty(e.yr),o=n.getProperty(e.yr);return i===`EXTERNAL_PORT`?r===`EXTERNAL_PORT`?a===o?0:a<o?-1:1:1:-1});let r=null;for(let t of n){if(t.getType()!==`EXTERNAL_PORT`)break;let n=t.getProperty(e.Un);if(n===`WEST`||n===`EAST`){if(r!==null){let n=r.getProperty(e.Qn);n??(n=[],r.setProperty(e.Qn,n)),n.push(t)}r=t}}}processNorthernAndSouthernPortDummies(t){if(!e.Lr.isSideFixed(t.getProperty(e.Lt)))return;let n=t.getLayers(),r=n.length,i=[/* @__PURE__ */ new Map,/* @__PURE__ */ new Map],a=[[],[]],o=[];for(let s=0;s<r;s++){let r=n[s],c=i[s],l=/* @__PURE__ */ new Map;i.push(l);let u=a[s],d=[];a.push(d);for(let n of r.getNodes())if(this.isNorthernOrSouthernDummy(n))o.push(n);else{for(let r of n.getIncomingEdges()){let n=r.getSource()?.getNode();if(n==null||!this.isNorthernOrSouthernDummy(n))continue;let i=n.getProperty(e.Hn)??n,a=c.get(i)??null;a===null&&(a=this.createDummy(t,n),c.set(i,a),u.push(a)),r.setSource(a.getPorts()[1])}for(let r of n.getOutgoingEdges()){let n=r.getTarget()?.getNode();if(n==null||!this.isNorthernOrSouthernDummy(n))continue;let i=n.getProperty(e.Hn)??n,a=l.get(i)??null;a===null&&(a=this.createDummy(t,n),l.set(i,a),d.push(a)),r.setTarget(a.getPorts()[0])}}}for(let e=0;e<a.length;e++){let r=a[e];if(r.length===0)continue;let o;e===0?(o=new w(t),n.unshift(o)):e===i.length-1?(o=new w(t),n.push(o)):o=n[e-1];for(let e of r)e.setLayer(o)}for(let e of o)e.setLayer(null);t.setProperty(e.Vn,o)}isNorthernOrSouthernDummy(t){if(t.getType()!==`EXTERNAL_PORT`)return!1;let n=t.getProperty(e.Un);return n===`NORTH`||n===`SOUTH`}createDummy(t,n){let r=new f(t);r.copyProperties(n),r.setInLayerConstraint(n.getInLayerConstraint()),r.setProperty(e.Hn,n),r.setProperty(e.Lt,`FIXED_POS`),r.setProperty(e.p,`CENTER`),r.setType(`EXTERNAL_PORT`);let i=new p;i.setNode(r),i.setSide(`WEST`);let a=new p;return a.setNode(r),a.setSide(`EAST`),r}};function ll(e){let t=e.getLayers();t.length>0&&ul(t[0],e),t.length>1&&ul(t[t.length-1],e)}function ul(t,n){let r=n.getProperty(e.Lt);if(!(e.Lr.isRatioFixed(r)||e.Lr.isPosFixed(r)))return;let i=n.getActualSize().y;for(let a of t.getNodes()){if(a.getType()!==`EXTERNAL_PORT`)continue;let t=a.getProperty(e.Un);if(t!==`EAST`&&t!==`WEST`)continue;let o=a.getProperty(e.yr);r===`FIXED_RATIO`&&(o*=i),a.getPosition().y=o-(a.getProperty(e.Ft)?.y??0),a.position.y-=n.getPadding().top+n.getOffset().y}}function dl(e){let t=fl(e);hl(e,t),Sl(e,t),Tl(e),Cl(e),El(e)}function fl(t){let n=t.getProperty(e.Vn);if(n==null||n.length===0)return[];let r=[];for(let e of n)pl(e),r.push(e);for(let n of t.getLayers())for(let t of n.getNodes()){if(t.getType()!==`EXTERNAL_PORT`)continue;let n=t.getProperty(e.Hn);n!=null&&ml(t,n)}let i=t.getLayers();for(let e of r)e.setLayer(i[i.length-1]);return r}function pl(t){let n=t.getProperty(e.Un),r=t.getPorts()[0];n===`NORTH`?r.setSide(`SOUTH`):n===`SOUTH`&&r.setSide(`NORTH`)}function ml(t,n){let r=new p;r.setNode(t),r.setSide(t.getProperty(e.Un));let i=n.getPorts()[0],a=new m;a.setSource(r),a.setTarget(i)}function hl(t,n){let r=t.getProperty(e.Lt),i=t.getSize(),a=t.getPadding(),o=i.x+a.left+a.right,s=0-t.getOffset().y,c=i.y+a.top+a.bottom-t.getOffset().y,l=[],u=[];for(let t of n){switch(r){case`FREE`:case`FIXED_SIDE`:case`FIXED_ORDER`:gl(t);break;case`FIXED_RATIO`:_l(t,o);break;case`FIXED_POS`:vl(t),i.x=Math.max(i.x,t.getPosition().x+t.getSize().x/2)}switch(t.getProperty(e.Un)){case`NORTH`:t.getPosition().y=s,l.push(t);break;case`SOUTH`:t.getPosition().y=c,u.push(t)}}r===`FREE`||r===`FIXED_SIDE`?(yl(l,t),yl(u,t)):r===`FIXED_ORDER`&&(bl(l,t),bl(u,t))}function gl(t){let n=t.getPorts()[0];if(n.getDegree()===0){t.getPosition().x=0;return}let r=0;for(let e of n.getConnectedPorts())r+=e.getNode().getPosition().x+e.getPosition().x+e.getAnchor().x;let i=t.getProperty(e.Ft),a=i==null?0:i.x;t.getPosition().x=r/n.getDegree()-a}function _l(t,n){let r=t.getProperty(e.Ft),i=r==null?0:r.x;t.getPosition().x=n*t.getProperty(e.yr)-i}function vl(t){let n=t.getProperty(e.Ft),r=n==null?0:n.x;t.getPosition().x=t.getProperty(e.yr)-r}function yl(e,t){e.length!==0&&(e.sort((e,t)=>e.getPosition().x-t.getPosition().x),xl(e,t))}function bl(t,n){t.length!==0&&(t.sort((t,n)=>t.getProperty(e.yr)-n.getProperty(e.yr)),xl(t,n))}function xl(t,n){let r=n.getProperty(e.pn),i=t[0].getPosition().x+t[0].getSize().x+t[0].getMargin().right+r;for(let e=1;e<t.length;e++){let a=t[e].getPosition(),o=t[e].getSize(),s=t[e].getMargin(),c=a.x-s.left-i;c<0&&(a.x-=c);let l=n.getSize();l.x=Math.max(l.x,a.x+o.x),i=a.x+o.x+s.right+r}}function Sl(t,n){let r=n.filter(t=>t.getProperty(e.Un)===`NORTH`),i=n.filter(t=>t.getProperty(e.Un)===`SOUTH`),a=t.getProperty(e.br),o=t.getProperty(e.ln),s=t.getProperty(e.$t),c=new $n(s),l=e=>{let t=/* @__PURE__ */ new Set;for(let n of e){let e=n.getPorts()[0];if(e!=null)for(let n of e.getIncomingEdges()){let e=n.getSource()?.getNode();e!=null&&t.add(e)}}return[...t]};if(r.length>0){let e=c.routeEdgesForDirection(l(r),r,a,Yn.sourceSide,Yn.targetSide,Yn.positionFn,-o-t.getOffset().y);if(e>0){let n=o+(e-1)*s;t.getOffset().y+=n,t.getSize().y+=n}}if(i.length>0){let e=c.routeEdgesForDirection(l(i),i,a,Xn.sourceSide,Xn.targetSide,Xn.positionFn,t.getSize().y+o-t.getOffset().y);e>0&&(t.getSize().y+=o+(e-1)*s)}}function Cl(e){let t=e.getLayers();t.length!==0&&(wl(t[0],e),wl(t[t.length-1],e))}function wl(t,n){let r=n.getProperty(e.Lt),i=n.getPadding(),a=n.getOffset(),o=n.getSize(),s=o.y+i.top+i.bottom,c=s;for(let n of t.getNodes()){if(n.getType()!==`EXTERNAL_PORT`)continue;let t=n.getProperty(e.Un),s=n.getPosition(),l=n.getProperty(e.Wn);if(l==null){let t=n.getProperty(e.lr);l=t instanceof p?t.getSize():{x:0,y:0}}switch(t){case`EAST`:s.x=o.x+i.right-a.x;break;case`WEST`:s.x=-a.x-i.left}let u=0;if(t===`EAST`||t===`WEST`){let t=n.getProperty(e.Ft),c=t==null?0:t.y;if(r===`FIXED_RATIO`){let t=n.getProperty(e.yr)??0;s.y=o.y*t-c,u=s.y+l.y,s.y-=i.top+a.y}else r===`FIXED_POS`&&(s.y=(n.getProperty(e.yr)??0)-c,u=s.y+l.y,s.y-=i.top+a.y)}c=Math.max(c,u)}o.y+=c-s;for(let n of t.getNodes()){if(n.getType()!==`EXTERNAL_PORT`)continue;let t=n.getProperty(e.Un),r=n.getPosition();switch(t){case`NORTH`:r.y=-a.y;break;case`SOUTH`:r.y=o.y+i.top+i.bottom-a.y}}}function Tl(t){let n=[];for(let r of t.getLayers())for(let t of r.getNodes()){if(t.getType()!==`EXTERNAL_PORT`||!t.hasProperty(e.Hn))continue;let r=null,i=null,a=null;for(let e of t.getPorts())switch(e.getSide()){case`WEST`:r=e;break;case`EAST`:i=e;break;default:a=e}if(r===null||i===null||a===null)continue;let o=a.getOutgoingEdges()[0];if(o===void 0)continue;let s=o.getBendPoints().map(e=>({...e})),c={x:a.getPosition().x+t.getPosition().x,y:a.getPosition().y+t.getPosition().y};s.unshift(c);let l=[...o.getBendPoints()].reverse().map(e=>({...e}));l.push({...c});let u=t.getProperty(e.Hn).getPorts()[0];for(let e of[...r.getIncomingEdges()])e.setTarget(u),e.getBendPoints().push(...s.map(e=>({...e})));for(let e of[...i.getOutgoingEdges()])e.setSource(u),e.getBendPoints().unshift(...l.map(e=>({...e})));o.setSource(null),o.setTarget(null),n.push(t)}for(let e of n){e.setLayer(null);let n=t.getLayerlessNodes().indexOf(e);n!==-1&&t.getLayerlessNodes().splice(n,1)}}function El(e){let t=e.getLayers();t.length!==0&&(Dl(t[0]),Dl(t[t.length-1]))}function Dl(t){for(let n of t.getNodes()){if(n.getType()!==`EXTERNAL_PORT`)continue;let t=n.getProperty(e.Un);if(t===`EAST`||t===`WEST`)for(let e of n.getPorts())for(let t of e.getConnectedEdges()){let e=t.getBendPoints();if(e.length===0)continue;let r=t.getSource();r!==null&&r.getNode()===n&&(e[0].y=r.getAbsoluteAnchor().y);let i=t.getTarget();i!==null&&i.getNode()===n&&(e[e.length-1].y=i.getAbsoluteAnchor().y)}}}function Ol(e){for(let t of e.getLayers()){let e=-1,n=[];for(let[r,i]of[...t.getNodes()].entries()){let a=i.getInLayerConstraint();e===-1?a!==`TOP`&&(e=r):a===`TOP`&&(i.setLayer(null),i.setLayerAt(e++,t)),a===`BOTTOM`&&n.push(i)}for(let e of n)e.setLayer(null),e.setLayer(t)}}function kl(t){for(let n of t.getLayers())for(let t of n.getNodes()){if(t.getType()!==`NORMAL`)continue;let n=t.getProperty(e.Cr);n!=null&&Al(t,n)}}function Al(e,t){for(let n of t.getSLHyperLoops())for(let t of n.getSLEdges())jl(e,t);for(let n of t.getSLHyperLoops())n.getSLLabels()!==null&&n.getSLLabels().applyPlacement(e.position)}function jl(e,t){let n=t.getLEdge();n.setSource(t.getSLSource().getLPort()),n.setTarget(t.getSLTarget().getLPort());for(let t of n.getBendPoints())t.x+=e.position.x,t.y+=e.position.y}var Ml=class t{slLoopsByType=/* @__PURE__ */ new Map;targetAreas=/* @__PURE__ */ new Map;restorePorts(t){this.initTargetAreas(),this.slLoopsByType=this.gatherSelfLoopsByType(t);let n=t.getLNode().hasProperty(e.Jt)?t.getLNode().getProperty(e.Jt):t.getLNode().getGraph().getProperty(e.Jt);this.processOneSideLoops(n),this.processTwoSideCornerLoops(),this.processThreeSideLoops(),this.processFourSideLoops(),this.processTwoSideOpposingLoops(),this.restorePortList(t);for(let e of this.targetAreas.values())for(let t of e)t.setHidden(!1);t.setPortsHidden(!1),this.slLoopsByType=/* @__PURE__ */ new Map}initTargetAreas(){this.targetAreas=/* @__PURE__ */ new Map;for(let e of Nl)for(let t of[0,1,2])this.targetAreas.set(K(e,t),[])}gatherSelfLoopsByType(e){let t=/* @__PURE__ */ new Map;for(let n of e.getSLHyperLoops()){let e=t.get(n.getSelfLoopType())??[];e.push(n),t.set(n.getSelfLoopType(),e)}return t}processOneSideLoops(e){let t=this.slLoopsByType.get(`ONE_SIDE`)??[];e===`REVERSE_STACKED`&&t.reverse();for(let n of t){let t=n.getSLPorts()[0].getLPort().getSide(),r=[...n.getSLPorts()];switch(r.sort((e,t)=>e.getSLNetFlow()-t.getSLNetFlow()),e){case`SEQUENCED`:this.addToTargetAreaPorts(r,t,1,1);break;case`REVERSE_STACKED`:case`STACKED`:{let e=this.computePortListSplitIndex(r);this.addToTargetAreaPorts(r.slice(0,e),t,1,0),this.addToTargetAreaPorts(r.slice(e),t,1,1);break}default:throw Error(`Unexpected ordering: ${e}`)}}}computePortListSplitIndex(e){let t=0;for(;t<e.length&&!(e[t].getSLNetFlow()>0);t++);if(t>0&&t<e.length-1)return t;let n=0;for(;n<e.length&&!(e[n].getSLNetFlow()>0);n++);return n>0&&t<e.length-1?n:Math.floor(e.length/2)}processTwoSideCornerLoops(){for(let e of this.slLoopsByType.get(`TWO_SIDES_CORNER`)??[]){let n=t.sortedTwoSideLoopPortSides(e);this.addToTargetArea(e,n[0],2,0),this.addToTargetArea(e,n[1],0,1)}}processTwoSideOpposingLoops(){for(let e of this.slLoopsByType.get(`TWO_SIDES_OPPOSING`)??[]){let n=t.sortedTwoSideLoopPortSides(e);this.addToTargetArea(e,n[0],2,0),this.addToTargetArea(e,n[1],0,1)}}static sortedTwoSideLoopPortSides(e){let t=[...e.getSLPortsBySideMap().keys()];return t.sort((e,t)=>Pl(e)-Pl(t)),t[0]===`NORTH`&&t[1]===`WEST`&&(t[0]=`WEST`,t[1]=`NORTH`),t}static NES=[`NORTH`,`EAST`,`SOUTH`];static ESW=[`EAST`,`SOUTH`,`WEST`];static SWN=[`SOUTH`,`WEST`,`NORTH`];static WNE=[`WEST`,`NORTH`,`EAST`];processThreeSideLoops(){for(let e of this.slLoopsByType.get(`THREE_SIDES`)??[]){let t=this.determineLoopConstellation(e);this.addToTargetArea(e,t[0],2,0),this.addToTargetArea(e,t[1],1,1),this.addToTargetArea(e,t[2],0,1)}}determineLoopConstellation(e){let n=e.getSLPortsBySideMap();if(!n.has(`NORTH`))return t.ESW;if(!n.has(`EAST`))return t.SWN;if(!n.has(`SOUTH`))return t.WNE;if(!n.has(`WEST`))return t.NES;throw Error(`Impossible`)}processFourSideLoops(){for(let e of this.slLoopsByType.get(`FOUR_SIDES`)??[])for(let t of e.getSLPortsBySideMap().keys())this.addToTargetArea(e,t,1,1)}addToTargetArea(e,t,n,r){this.addToTargetAreaPorts(e.getSLPortsBySide(t),t,n,r)}addToTargetAreaPorts(e,t,n,r){let i=e.filter(e=>e.isHidden());i.reverse();let a=this.targetAreas.get(K(t,n));r===0?a.unshift(...i):a.push(...i)}restorePortList(e){let t=e.getLNode(),n=[...t.getPorts()],r=0,i=t.getPorts();i.length=0,this.addAll(this.targetAreas.get(K(`NORTH`,0)),t),r=this.addAllThat(n,r,e=>e.getSide()===`NORTH`&&this.isNorthSouthPortWithWestOrWestEastConnections(e),i),this.addAll(this.targetAreas.get(K(`NORTH`,1)),t),r=this.addAllThat(n,r,e=>e.getSide()===`NORTH`,i),this.addAll(this.targetAreas.get(K(`NORTH`,2)),t),this.addAll(this.targetAreas.get(K(`EAST`,0)),t),this.addAll(this.targetAreas.get(K(`EAST`,1)),t),r=this.addAllThat(n,r,e=>e.getSide()===`EAST`,i),this.addAll(this.targetAreas.get(K(`EAST`,2)),t),this.addAll(this.targetAreas.get(K(`SOUTH`,0)),t),r=this.addAllThat(n,r,e=>e.getSide()===`SOUTH`&&this.isNorthSouthPortWithEastConnections(e),i),this.addAll(this.targetAreas.get(K(`SOUTH`,1)),t),r=this.addAllThat(n,r,e=>e.getSide()===`SOUTH`,i),this.addAll(this.targetAreas.get(K(`SOUTH`,2)),t),this.addAll(this.targetAreas.get(K(`WEST`,0)),t),r=this.addAllThat(n,r,e=>e.getSide()===`WEST`,i),this.addAll(this.targetAreas.get(K(`WEST`,1)),t),this.addAll(this.targetAreas.get(K(`WEST`,2)),t)}addAll(e,t){for(let n of e)n.getLPort().setNode(t)}addAllThat(e,t,n,r){for(let i=t;i<e.length;i++){let t=e[i];if(n(t))r.push(t);else return i}return e.length}isNorthSouthPortWithWestOrWestEastConnections(e){return this.northSouthPortConnectionSides(e).has(`WEST`)}isNorthSouthPortWithEastConnections(e){return this.northSouthPortConnectionSides(e).has(`EAST`)}northSouthPortConnectionSides(t){let n=/* @__PURE__ */ new Set,r=t.getProperty(e._r);if(r!=null)for(let i of r.getPorts())i.getProperty(e.lr)===t&&i.getConnectedEdges().length>0&&n.add(i.getSide());return n}};const Nl=[`NORTH`,`EAST`,`SOUTH`,`WEST`];function K(e,t){return`${e}-${t}`}function Pl(e){switch(e){case`NORTH`:return 0;case`EAST`:return 1;case`SOUTH`:return 2;case`WEST`:return 3;default:return 4}}const Fl=[{name:`NORTH`,firstSide:`NORTH`,secondSide:`NORTH`},{name:`SOUTH`,firstSide:`SOUTH`,secondSide:`SOUTH`},{name:`EAST`,firstSide:`EAST`,secondSide:`EAST`},{name:`WEST`,firstSide:`WEST`,secondSide:`WEST`},{name:`NORTH_WEST_CORNER`,firstSide:`WEST`,secondSide:`NORTH`},{name:`NORTH_EAST_CORNER`,firstSide:`NORTH`,secondSide:`EAST`},{name:`SOUTH_WEST_CORNER`,firstSide:`SOUTH`,secondSide:`WEST`},{name:`SOUTH_EAST_CORNER`,firstSide:`EAST`,secondSide:`SOUTH`}],Il=e=>e.firstSide!==e.secondSide;var Ll=class{assignPortSides(t){let n=t.getLNode().hasProperty(e.qt)?t.getLNode().getProperty(e.qt):t.getLNode().getGraph().getProperty(e.qt);switch(n){case`NORTH`:this.assignToNorthSide(t);break;case`NORTH_SOUTH`:this.assignToNorthOrSouthSide(t);break;case`EQUALLY`:this.assignToAllSides(t);break;default:throw Error(`Unexpected distribution: ${String(n)}`)}}assignToNorthSide(e){for(let t of e.getSLHyperLoops())for(let e of this.hiddenSelfLoopPortStream(t))e.getLPort().setSide(`NORTH`)}assignToNorthOrSouthSide(e){let t=0,n=0;for(let r of e.getSLHyperLoops()){let e=this.hiddenSelfLoopPortStream(r),i;t<=n?(i=`NORTH`,t+=e.length):(i=`SOUTH`,n+=e.length);for(let t of e)t.getLPort().setSide(i)}}assignToAllSides(e){let t=[...e.getSLHyperLoops()];t.sort((e,t)=>t.getSLPorts().length-e.getSLPorts().length);let n=0;for(let e of t){let t=Fl[n%Fl.length];this.assignToTarget(e,t),n++}}assignToTarget(e,t){let n=e.getSLPorts();Il(t)&&n.sort((e,t)=>e.getLPort().getNetFlow()-t.getLPort().getNetFlow());let r=Math.floor(n.length/2);for(let e=0;e<r;e++){let r=n[e];r.isHidden()&&r.getLPort().setSide(t.firstSide)}for(let e=r;e<n.length;e++){let r=n[e];r.isHidden()&&r.getLPort().setSide(t.secondSide)}}hiddenSelfLoopPortStream(e){return e.getSLPorts().filter(e=>e.isHidden())}},Rl=class{portSideAssigner=new Ll;portRestorer=new Ml;process(t){for(let n of t.getLayers())for(let t of n.getNodes()){if(t.getType()!==`NORMAL`)continue;let n=t.getProperty(e.Cr);n!=null&&this.processNode(n)}}processNode(t){if(t.arePortsHiddenFlag())switch(t.getLNode().getProperty(e.mr)){case`UNDEFINED`:case`FREE`:this.portSideAssigner.assignPortSides(t);case`FIXED_SIDE`:this.computeSelfLoopTypes(t),this.portRestorer.restorePorts(t);break;default:throw Error(`Unexpected port constraints`)}else this.computeSelfLoopTypes(t)}computeSelfLoopTypes(e){for(let t of e.getSLHyperLoops())t.computePortsPerSide()}};function zl(e){Bl(e);for(let t of e.getSLHyperLoops())t.getSLLabels()!==null&&Kl(t)}function Bl(t){let n=null,r=null,i=t.getLNode().hasProperty(e.Jt)?t.getLNode().getProperty(e.Jt):t.getLNode().getGraph().getProperty(e.Jt);i===`SEQUENCED`&&(n=[],r=[]);for(let e of t.getSLHyperLoops())if(e.getSLLabels()!==null)switch(e.getSelfLoopType()){case`ONE_SIDE`:{let t=e.getOccupiedPortSides().values().next().value;i===`SEQUENCED`&&t===`NORTH`?n.push(e):i===`SEQUENCED`&&t===`SOUTH`?r.push(e):Vl(e,t);break}case`TWO_SIDES_CORNER`:Ul(e);break;case`TWO_SIDES_OPPOSING`:case`THREE_SIDES`:Wl(e);break;case`FOUR_SIDES`:Gl(e);break;default:throw Error(`Unexpected self loop type`)}n!==null&&(n.length>0&&Hl(n,`NORTH`),r.length>0&&Hl(r,`SOUTH`))}function Vl(e,t){switch(t){case`EAST`:case`WEST`:{let n=e.getLeftmostPort();e.getRightmostPort().getLPort().getPosition().y<n.getLPort().getPosition().y&&(n=e.getRightmostPort()),q(e,t,`TOP`,n);break}case`NORTH`:case`SOUTH`:q(e,t,`CENTER`,null);break;default:throw Error(`Impossible`)}}function Hl(e,t){let n=0;for(let t of e[0].getSLHolder().getLNode().getPorts())t.id=n++;t===`NORTH`?e.sort((e,t)=>e.getLeftmostPort().getLPort().id-t.getLeftmostPort().getLPort().id):e.sort((e,t)=>t.getLeftmostPort().getLPort().id-e.getLeftmostPort().getLPort().id);let r=0,i=e.length-1;for(;r<i;){let n=e[r],a=e[i],o=t===`NORTH`?n.getRightmostPort():n.getLeftmostPort(),s=t===`NORTH`?a.getLeftmostPort():a.getRightmostPort();q(n,t,`RIGHT`,o),q(a,t,`LEFT`,s),r++,i--}r===i&&q(e[r],t,`CENTER`,null)}function Ul(e){let t=e.getLeftmostPort().getLPort().getSide(),n=e.getRightmostPort().getLPort().getSide();if(t===`NORTH`)q(e,`NORTH`,`LEFT`,e.getLeftmostPort());else if(n===`NORTH`)q(e,`NORTH`,`RIGHT`,e.getRightmostPort());else if(t===`SOUTH`)q(e,`SOUTH`,`RIGHT`,e.getLeftmostPort());else if(n===`SOUTH`)q(e,`SOUTH`,`LEFT`,e.getRightmostPort());else throw Error(`Impossible`)}function Wl(e){let t=e.getOccupiedPortSides();if(!t.has(`NORTH`))q(e,`SOUTH`,`CENTER`,null);else if(!t.has(`SOUTH`))q(e,`NORTH`,`CENTER`,null);else if(!t.has(`WEST`))q(e,`NORTH`,`LEFT`,e.getLeftmostPort());else if(!t.has(`EAST`))q(e,`NORTH`,`RIGHT`,e.getRightmostPort());else throw Error(`Impossible`)}function Gl(e){let t=e.getLeftmostPort().getLPort().getSide(),n=e.getLeftmostPort().getLPort().getSide();t===`NORTH`||n===`NORTH`?q(e,`SOUTH`,`CENTER`,null):q(e,`NORTH`,`CENTER`,null)}function q(e,t,n,r){let i=e.getSLLabels();i.setSide(t),i.setAlignment(n),i.setAlignmentReferenceSLPort(r)}function Kl(e){let t=e.getSLLabels(),n=t.getAlignmentReferenceSLPort(),r=t.getSize(),i=t.getPosition();switch(t.getAlignment()){case`CENTER`:i.x=(e.getSLHolder().getLNode().size.x-r.x)/2;break;case`LEFT`:i.x=n.getLPort().getPosition().x+n.getLPort().getAnchor().x;break;case`RIGHT`:i.x=n.getLPort().getPosition().x+n.getLPort().getAnchor().x-r.x;break;case`TOP`:i.y=n.getLPort().getPosition().y+n.getLPort().getAnchor().y;break;default:throw Error(`Impossible`)}}var ql=class{routeSelfLoops(t){let n=t.getLNode(),r=n.size,i=n.getMargin(),a=n.getGraph().getProperty(e.$t),o=n.getGraph().getProperty(e.tn),s=n.getGraph().getProperty(e.dn),c={...i},l=this.computeRoutingSlotPositions(t,a,o,s);for(let e of t.getSLHyperLoops()){for(let t of e.getSLEdges()){let e=t.getLEdge(),n=this.computeEdgeRoutingDirection(t),i=this.computeOrthogonalBendPoints(t,n,l),a=this.modifyBendPoints(t,n,i);e.getBendPoints().length=0;for(let t of a)e.getBendPoints().push(t);for(let e of a)this.updateNewNodeMargins(r,c,e)}let t=e.getSLLabels();t!==null&&(this.placeLabels(e,t,l,o),this.updateNewNodeMarginsForLabels(r,c,t))}i.left=c.left,i.top=c.top,i.right=c.right,i.bottom=c.bottom}computeEdgeRoutingDirection(e){let t=e.getSLSource().getLPort(),n=t.getSide(),r=e.getSLTarget().getLPort(),i=r.getSide();return n===i?t.id<r.id?0:1:qc(n)===i?0:Jc(n)===i?1:+!e.getSLHyperLoop().getOccupiedPortSides().has(qc(n))}placeLabels(e,t,n,r){let i=t.getSide(),a=n[G(i)][e.getRoutingSlot(i)];switch(i){case`NORTH`:a-=r+t.getSize().y,t.getPosition().y=a;break;case`SOUTH`:a+=r,t.getPosition().y=a;break;case`WEST`:a-=r+t.getSize().x,t.getPosition().x=a;break;case`EAST`:a+=r,t.getPosition().x=a}}updateNewNodeMargins(e,t,n){t.left=Math.max(t.left,-n.x),t.right=Math.max(t.right,n.x-e.x),t.top=Math.max(t.top,-n.y),t.bottom=Math.max(t.bottom,n.y-e.y)}updateNewNodeMarginsForLabels(e,t,n){let r={...n.getPosition()};this.updateNewNodeMargins(e,t,r),r.x+=n.getSize().x,r.y+=n.getSize().y,this.updateNewNodeMargins(e,t,r)}computeRoutingSlotPositions(e,t,n,r){let i=[];for(let t of[`NORTH`,`EAST`,`SOUTH`,`WEST`])i[G(t)]=Array(e.getRoutingSlotCount()[G(t)]).fill(0);return this.initializeWithMaxLabelHeight(i,e,`NORTH`),this.initializeWithMaxLabelHeight(i,e,`SOUTH`),this.computePositions(i,e,`NORTH`,t,n,r),this.computePositions(i,e,`EAST`,t,n,r),this.computePositions(i,e,`SOUTH`,t,n,r),this.computePositions(i,e,`WEST`,t,n,r),i}initializeWithMaxLabelHeight(e,t,n){let r=e[G(n)];for(let e of t.getSLHyperLoops()){let t=e.getSLLabels();if(t!==null&&t.getSide()===n){let i=e.getRoutingSlot(n);r[i]=Math.max(r[i],t.getSize().y)}}}computePositions(e,t,n,r,i,a){let o=this.computeBaselinePosition(t,n,a),s=n===`NORTH`||n===`WEST`?-1:1,c=e[G(n)];for(let e=0;e<c.length;e++){let t=c[e];t>0&&(t+=i),c[e]=o,o+=s*(t+r)}}computeBaselinePosition(e,t,n){let r=e.getLNode(),i=r.getMargin();switch(t){case`NORTH`:return-i.top-n;case`EAST`:return r.size.x+i.right+n;case`SOUTH`:return r.size.y+i.bottom+n;case`WEST`:return-i.left-n;default:throw Error(`Impossible`)}}computeOrthogonalBendPoints(e,t,n){let r=[];return this.addOuterBendPoint(e,e.getSLSource(),n,r),this.addCornerBendPoints(e,t,n,r),this.addOuterBendPoint(e,e.getSLTarget(),n,r),r}modifyBendPoints(e,t,n){return n}addOuterBendPoint(e,t,n,r){let i=e.getSLHyperLoop(),a=t.getLPort(),o=a.getSide(),s=this.getBaseVector(o,i.getRoutingSlot(o),n),c={x:a.getPosition().x+a.getAnchor().x,y:a.getPosition().y+a.getAnchor().y};switch(a.getSide()){case`NORTH`:s.x+=c.x;break;case`SOUTH`:s.x+=c.x;break;case`EAST`:s.y+=c.y;break;case`WEST`:s.y+=c.y}r.push(s)}addCornerBendPoints(e,t,n,r){let i=e.getSLSource().getLPort(),a=e.getSLTarget().getLPort();if(i.getSide()===a.getSide())return;let o=e.getSLHyperLoop(),s=i.getSide();for(;s!==a.getSide();){let e=t===0?qc(s):Jc(s),i=this.getBaseVector(s,o.getRoutingSlot(s),n),a=this.getBaseVector(e,o.getRoutingSlot(e),n);r.push({x:i.x+a.x,y:i.y+a.y}),s=e}}getBaseVector(e,t,n){let r=n[G(e)][t];switch(e){case`NORTH`:case`SOUTH`:return{x:0,y:r};case`EAST`:case`WEST`:return{x:r,y:0};default:throw Error(`Impossible`)}}};const Jl=.01;function Yl(e){return{x:e.x>=-.01&&e.x<=Jl?0:e.x,y:e.y>=-.01&&e.y<=Jl?0:e.y}}var Xl=class extends ql{modifyBendPoints(e,t,n){let r=e.getSLSource().getLPort();n.unshift({x:r.getPosition().x+r.getAnchor().x,y:r.getPosition().y+r.getAnchor().y});let i=e.getSLTarget().getLPort();return n.push({x:i.getPosition().x+i.getAnchor().x,y:i.getPosition().y+i.getAnchor().y}),this.cutCorners(n,10)}cutCorners(e,t){if(e.length<=2)throw Error(`AssertionError: bendPoints.size() > 2`);let n=[],r=null,i=e[0],a=e[1];for(let o=2;o<e.length;o++){r=i,i=a,a=e[o];let s=Yl({x:r.x-i.x,y:r.y-i.y}),c=Yl({x:a.x-i.x,y:a.y-i.y}),l=t;l=Math.min(l,Math.abs(s.x+s.y)/2),l=Math.min(l,Math.abs(c.x+c.y)/2),s.x=Math.sign(s.x)*l,s.y=Math.sign(s.y)*l,c.x=Math.sign(c.x)*l,c.y=Math.sign(c.y)*l,n.push({x:s.x+i.x,y:s.y+i.y}),n.push({x:c.x+i.x,y:c.y+i.y})}return n}};const Zl=[`WEST`,`NORTH`,`SOUTH`,`EAST`],Ql=(e,t)=>e.getLPort().id-t.getLPort().id;var $l=class{portPenalties=null;determineLoopRoutes(e){this.assignPortIds(e.getLNode().getPorts()),this.sortHyperLoopPortLists(e);for(let t of e.getSLHyperLoops()){switch(t.getSelfLoopType()){case`ONE_SIDE`:this.determineOneSideLoopRoutes(t);break;case`TWO_SIDES_CORNER`:this.determineTwoSideCornerLoopRoutes(t);break;case`TWO_SIDES_OPPOSING`:this.determineTwoSideOpposingLoopRoutes(t);break;case`THREE_SIDES`:this.determineThreeSideLoopRoutes(t);break;case`FOUR_SIDES`:this.determineFourSideLoopRoutes(t);break;default:throw Error(`Unexpected self loop type`)}this.computeOccupiedPortSides(t)}this.portPenalties=null}assignPortIds(e){for(let t=0;t<e.length;t++)e[t].id=t}sortHyperLoopPortLists(e){for(let t of e.getSLHyperLoops())t.getSLPorts().sort(Ql)}computeOccupiedPortSides(e){let t=e.getLeftmostPort().getLPort().getSide(),n=e.getRightmostPort().getLPort().getSide();for(;t!==n;)e.getOccupiedPortSides().add(t),t=qc(t);e.getOccupiedPortSides().add(t)}determineOneSideLoopRoutes(e){let t=e.getSLPorts()[0].getLPort().getSide();this.assignLeftmostRightmostPorts(e,t,t)}determineTwoSideCornerLoopRoutes(e){let t=Ml.sortedTwoSideLoopPortSides(e);this.assignLeftmostRightmostPorts(e,t[0],t[1])}determineTwoSideOpposingLoopRoutes(e){let t=[...e.getSLPortsBySideMap().keys()].sort((e,t)=>Zl.indexOf(e)-Zl.indexOf(t)),n=e.getSLHolder(),r=this.lowestPortOnSide(e,t[0]),i=this.highestPortOnSide(e,t[1]),a=this.computeEdgePenalty(n,r,i),o=this.lowestPortOnSide(e,t[1]),s=this.highestPortOnSide(e,t[0]);a<=this.computeEdgePenalty(n,o,s)?(e.setLeftmostPort(r),e.setRightmostPort(i)):(e.setLeftmostPort(o),e.setRightmostPort(s))}determineThreeSideLoopRoutes(e){let t,n;switch(this.computeMissingPortSide(e)){case`NORTH`:t=`EAST`,n=`WEST`;break;case`EAST`:t=`SOUTH`,n=`NORTH`;break;case`SOUTH`:t=`WEST`,n=`EAST`;break;default:t=`NORTH`,n=`SOUTH`}this.assignLeftmostRightmostPorts(e,t,n)}computeMissingPortSide(e){let t=e.getSLPortsBySideMap();for(let e of[`NORTH`,`EAST`,`SOUTH`,`WEST`])if(!t.has(e))return e;throw Error(`Cannot happen`)}determineFourSideLoopRoutes(e){let t=e.getSLPorts(),n=e.getSLHolder(),r=t[t.length-1],i=t[0],a=this.computeEdgePenalty(n,r,i);for(let e=1;e<t.length;e++){let o=t[e-1],s=t[e],c=this.computeEdgePenalty(n,o,s);c>a&&(r=o,i=s,a=c)}e.setLeftmostPort(i),e.setRightmostPort(r)}assignLeftmostRightmostPorts(e,t,n){e.setLeftmostPort(this.lowestPortOnSide(e,t)),e.setRightmostPort(this.highestPortOnSide(e,n))}lowestPortOnSide(e,t){let n=e.getSLPortsBySide(t),r=n[0];for(let e of n)Ql(e,r)<0&&(r=e);return r}highestPortOnSide(e,t){let n=e.getSLPortsBySide(t),r=n[0];for(let e of n)Ql(e,r)>0&&(r=e);return r}computeEdgePenalty(e,t,n){this.portPenalties===null&&this.computePenalties(e);let r=e.getLNode().getPorts().length,i=t.getLPort().id,a=n.getLPort().id-1;a<0&&(a=r-1);let o=this.portPenalties;return i<=a?o[a]-o[i]:o[r-1]-o[i]+o[a]}computePenalties(e){let t=e.getLNode().getPorts();this.portPenalties=Array(t.length);let n=0;for(let e=0;e<t.length;e++){let r=t[e];r.getIncomingEdges().length===0&&r.getOutgoingEdges().length===0?n+=1:n+=3,this.portPenalties[e]=n}}};const eu=1e-6;var tu=class{list;cursor=0;lastReturned=-1;constructor(e){this.list=e}next(){if(this.cursor>=this.list.length)throw Error(`NoSuchElementException`);this.lastReturned=this.cursor;let e=this.list[this.cursor];return this.cursor++,e}hasNext(){return this.cursor<this.list.length}previous(){if(this.cursor<=0)throw Error(`NoSuchElementException`);return this.cursor--,this.lastReturned=this.cursor,this.list[this.cursor]}add(e){this.list.splice(this.cursor,0,e),this.cursor++,this.lastReturned=-1}remove(){if(this.lastReturned<0)throw Error(`IllegalStateException`);this.list.splice(this.lastReturned,1),this.cursor>this.lastReturned&&this.cursor--,this.lastReturned=-1}},nu=class e{cp;polarCoordinate;constructor(t,n,r){if(t instanceof e&&n instanceof e&&r!==void 0){let e=t.polarCoordinate[0],i=n.polarCoordinate[n.polarCoordinate.length-1],a={x:t.cp.x*(i-r),y:t.cp.y*(i-r)},o={x:n.cp.x*(r-e),y:n.cp.y*(r-e)};this.cp={x:(a.x+o.x)/(i-e),y:(a.y+o.y)/(i-e)},this.polarCoordinate=[];let s=!0;for(let e=1;e<t.polarCoordinate.length;e++){let n=t.polarCoordinate[e];s&&n-r>eu&&(this.polarCoordinate.push(r),s=!1),this.polarCoordinate.push(n)}s&&this.polarCoordinate.push(r)}else this.cp={x:t.x,y:t.y},this.polarCoordinate=[...n]}getCp(){return this.cp}},ru=class{knotVector=[];controlPoints=[];dim;isClamped;isBezier=!1;minKnot=0;maxKnot=0;constructor(e,t,n){if(t<1)throw Error(`The dimension must be at least 1!`);for(;n.length<=t;)n.unshift({...n[0]});if(n.length<t+1)throw Error(`At (least dimension + 1) control points are necessary!`);this.dim=t,this.isClamped=e,this.isBezier=!1,this.createUniformKnotVector(e,n.length+t-1);let r=[],i=new tu(this.knotVector);for(let e=0;e<t-1;e++)r.push(i.next());for(let e of n)r.push(i.next()),this.controlPoints.push(new nu(e,r)),r.shift()}createUniformKnotVector(e,t){if(t<2*this.dim)throw Error(`The knot vector must have at least two time the dimension elements.`);let n;if(e){this.minKnot=0,this.maxKnot=1;for(let e=0;e<this.dim;e++)this.knotVector.push(0);n=t+1-2*this.dim}else{n=t+1;let e=this.dim;this.minKnot=e/(n+1),this.maxKnot=(n-e)/n}let r=n;for(let e=1;e<n;e++)this.knotVector.push(e/r);if(this.isClamped)for(let e=0;e<this.dim;e++)this.knotVector.push(1)}getMultiplicity(e){let t=0;for(let n of this.knotVector){let r=n-e;if(r>eu)return t;r>-1e-6&&t++}return t}insertKnotAtCurrentPosition(e,t,n,r){let i=this.getMultiplicity(t);for(let a=0;a<e;a++){r.add(t);let o=[],s=n.next();for(let e=i+a;e<this.dim;e++){let e=s;s=n.next(),o.push(new nu(e,s,t))}for(let e=i+a;e<this.dim;e++)n.previous(),e>i+a&&n.remove();for(let e of o)n.add(e);if(a<e-1)for(let e=i+a;e<this.dim;e++)n.previous()}}toBezier(){let e=new tu(this.knotVector),t=new tu(this.controlPoints);if(this.isClamped)for(let t=0;t<this.dim;t++)e.next();else for(let t=0;t<this.dim-1;t++)e.next(),e.remove();let n=e.next();for(;this.maxKnot-n>eu;){let r=n,i=0;for(;Math.abs(n-r)<eu;)i++,n=e.next(),t.next();i<this.dim&&(e.previous(),this.insertKnotAtCurrentPosition(this.dim-i,r,t,e),e.next()),t.previous()}if(!this.isClamped)for(let t=0;t<this.dim-1;t++)e.next(),e.remove();this.isClamped=!0,this.isBezier=!0}getBezierCP(e=!1,t=!1){this.isBezier||this.toBezier();let n=[],r=this.controlPoints[Symbol.iterator]();e||r.next();let i=r.next();for(;!i.done;)n.push(i.value.getCp()),i=r.next();return t||n.pop(),n}};function iu(e){switch(e){case`NORTH`:return Math.PI*1.5;case`EAST`:return 0;case`SOUTH`:return Math.PI*.5;case`WEST`:return Math.PI;default:return 0}}function au(e){return{x:Math.cos(e),y:Math.sin(e)}}var ou=class extends ql{modifyBendPoints(t,n,r){let i=t.getSLHyperLoop().getSLHolder().getLNode().getGraph().getProperty(e.tn),a=[this.relativePortAnchor(t.getSLSource())];return this.addSplineControlPoints(t,n,r,a,i),a.push(this.relativePortAnchor(t.getSLTarget())),new ru(!0,3,a).getBezierCP()}relativePortAnchor(e){let t=e.getLPort();return{x:t.getPosition().x+t.getAnchor().x,y:t.getPosition().y+t.getAnchor().y}}addSplineControlPoints(e,t,n,r,i){if(n.length<2)throw Error(`AssertionError: orthoBendPoints.size() >= 2`);let a=e.getSLSource().getLPort().getSide(),o=n[0];for(let e=1;e<n.length;e++){let s=n[e];r.push(o);let c={x:(o.x+s.x)*.5,y:(o.y+s.y)*.5},l=au(iu(a));c.x+=l.x*i,c.y+=l.y*i,r.push(c),o=s,a=t===0?qc(a):Jc(a)}r.push(n[n.length-1])}},su=class{hyperEdgeSegments=[];slLoopToSegmentMap=/* @__PURE__ */ new Map;slLoopActivityOverPorts=/* @__PURE__ */ new Map;assignRoutingSlots(t){let n=this.computeLabelCrossingMatrix(t);this.createCrossingGraph(t,n);let r=t.getLNode().getGraph().getProperty(e.br);lu(this.hyperEdgeSegments,r),this.doAssignRoutingSlots(t,n),this.hyperEdgeSegments=[],this.slLoopToSegmentMap=/* @__PURE__ */ new Map,this.slLoopActivityOverPorts=/* @__PURE__ */ new Map}computeLabelCrossingMatrix(e){let t=0;for(let n of e.getSLHyperLoops())n.getSLLabels()!==null&&(n.getSLLabels().id=t++);let n=Array.from({length:t},()=>Array(t).fill(!1)),r=e.getSLHyperLoops();for(let e=0;e<r.length;e++){let t=r[e];if(t.getSLLabels()!==null)for(let i=e+1;i<r.length;i++){let e=r[i];if(e.getSLLabels()!==null){let r=cu(t,e);n[t.getSLLabels().id][e.getSLLabels().id]=r,n[e.getSLLabels().id][t.getSLLabels().id]=r}}}return n}createCrossingGraph(e,t){let n=e.getSLHyperLoops();this.hyperEdgeSegments=Array(n.length),this.slLoopToSegmentMap=/* @__PURE__ */ new Map;for(let e=0;e<n.length;e++){let t=new kn;this.hyperEdgeSegments[e]=t,this.slLoopToSegmentMap.set(n[e],t)}this.slLoopActivityOverPorts=/* @__PURE__ */ new Map,this.computeLoopActivity(e);for(let e=0;e<n.length-1;e++){let r=n[e];for(let i=e+1;i<n.length;i++)this.createDependencies(r,n[i],t)}}computeLoopActivity(e){let t=e.getSLHyperLoops(),n=e.getLNode().getPorts();for(let e of t){let t=Array(n.length).fill(!1);this.slLoopActivityOverPorts.set(e,t);let r=e.getLeftmostPort().getLPort().id-1,i=e.getRightmostPort().getLPort().id;for(;r!==i;)r=(r+1)%n.length,t[r]=!0}}createDependencies(e,t,n){let r=this.countCrossings(e,t),i=this.countCrossings(t,e),a=this.slLoopToSegmentMap.get(e),o=this.slLoopToSegmentMap.get(t);r<i?A.createAndAddRegular(a,o,i-r):i<r?A.createAndAddRegular(o,a,r-i):(r!==0||this.labelsOverlapWithMatrix(e,t,n))&&(A.createAndAddRegular(a,o,0),A.createAndAddRegular(o,a,0))}countCrossings(e,t){let n=this.slLoopActivityOverPorts.get(t),r=0;for(let t of e.getSLPorts())n[t.getLPort().id]&&r++;return r}labelsOverlapWithMatrix(e,t,n){return e.getSLLabels()===null||t.getSLLabels()===null?!1:n[e.getSLLabels().id][t.getSLLabels().id]}doAssignRoutingSlots(e,t){this.assignRawRoutingSlotsToSegments(),this.assignRawRoutingSlotsToLoops(e),this.shiftTowardsNode(e,t)}assignRawRoutingSlotsToSegments(){let e=[];for(let t of this.hyperEdgeSegments)t.setInWeight(t.getIncomingSegmentDependencies().length),t.setOutWeight(t.getOutgoingSegmentDependencies().length),t.getOutWeight()===0&&(t.setRoutingSlot(0),e.push(t));for(;e.length>0;){let t=e.shift(),n=t.getRoutingSlot()+1;for(let r of t.getIncomingSegmentDependencies()){let t=r.getSource();t.setRoutingSlot(Math.max(t.getRoutingSlot(),n)),t.setOutWeight(t.getOutWeight()-1),t.getOutWeight()===0&&e.push(t)}}}assignRawRoutingSlotsToLoops(e){for(let t of e.getSLHyperLoops()){let e=this.slLoopToSegmentMap.get(t);for(let n of t.getOccupiedPortSides())t.setRoutingSlot(n,e.getRoutingSlot())}}shiftTowardsNode(e,t){let n=Array(e.getLNode().getPorts().length).fill(0);this.shiftTowardsNodeOnSide(e,`NORTH`,n,t),this.shiftTowardsNodeOnSide(e,`EAST`,n,t),this.shiftTowardsNodeOnSide(e,`SOUTH`,n,t),this.shiftTowardsNodeOnSide(e,`WEST`,n,t)}shiftTowardsNodeOnSide(e,t,n,r){let i=e.getSLHyperLoops().filter(e=>e.getOccupiedPortSides().has(t)).sort((e,n)=>e.getRoutingSlot(t)-n.getRoutingSlot(t)),a=e.getLNode(),o=2**53-1,s=-(2**53-1);for(let e of a.getPorts())e.getSide()===t&&(o=Math.min(o,e.id),s=Math.max(s,e.id));if(o===2**53-1)for(let e=0;e<i.length;e++)i[e].setRoutingSlot(t,e);else{let e=Array(r.length).fill(-1);for(let a of i){let i=this.slLoopActivityOverPorts.get(a),c=0;for(let e=o;e<=s;e++)i[e]&&(c=Math.max(c,n[e]));if(a.getSLLabels()!==null){let t=a.getSLLabels().id,n=/* @__PURE__ */ new Set;for(let i=0;i<r.length;i++)r[t][i]&&n.add(e[i]);for(;n.has(c);)c++}a.setRoutingSlot(t,c);for(let e=o;e<=s;e++)i[e]&&(n[e]=c+1);a.getSLLabels()!==null&&(e[a.getSLLabels().id]=c)}}}};function cu(e,t){let n=e.getSLLabels(),r=t.getSLLabels();if(n===null||r===null||n.getSide()!==r.getSide()||n.getSide()===`EAST`||n.getSide()===`WEST`)return!1;let i=n.getPosition().x,a=i+n.getSize().x,o=r.getPosition().x;return i<=o+r.getSize().x&&a>=o}function lu(e,t){let n=Cn.detectCycles(e,!1,t);for(let e of n)e.getWeight()===0?e.remove():e.reverse()}function uu(t){switch(t.getProperty(e.B)){case`POLYLINE`:return new Xl;case`SPLINES`:return new ou;default:return new ql}}function du(t){let n=new $l,r=new su,i=uu(t);for(let a of t.getLayers())for(let t of a.getNodes()){if(t.getType()!==`NORMAL`)continue;let a=t.getProperty(e.Cr);a!=null&&fu(a,i,n,r)}}function fu(e,t,n,r){n.determineLoopRoutes(e),zl(e),r.assignRoutingSlots(e),t.routeSelfLoops(e)}function pu(e){for(let t of e.getLayers()){let n=[];for(let r of t.getNodes())for(let t of r.getPorts()){let r=[...t.getOutgoingEdges()];for(let t of r){if(t.getSource().getNode()!==t.getTarget().getNode())continue;let r=t.getSource(),i=t.getTarget(),a=r.getSide(),o=i.getSide();((a===`NORTH`||a===`SOUTH`)&&o===`WEST`||a===`SOUTH`&&o===`NORTH`||a===`EAST`&&o!==`EAST`)&&t.reverse(e,!1);let s=t.getSource().getSide(),c=t.getTarget().getSide();s===`EAST`&&c===`WEST`?n.push(mu(e,t,t.getTarget(),t.getSource())):s===`WEST`&&c===`EAST`&&n.push(mu(e,t,t.getSource(),t.getTarget()))}}for(let e of n)e.setLayer(t)}}function mu(t,n,r,i){let a=new f(t);a.setType(`LONG_EDGE`),a.setProperty(e.lr,n),a.setProperty(e.Lt,`FIXED_POS`),a.setProperty(e.rr,r),a.setProperty(e.ir,i);let o=new p;o.setSide(`WEST`),o.setNode(a);let s=new p;s.setSide(`EAST`),s.setNode(a),n.setTarget(o);let c=new m;return c.copyProperties(n),c.setProperty(e.nt,null),c.setSource(s),c.setTarget(i),a}function hu(t,n,r){for(let i of t){let t=i.getProperty(e.lr),a=t.getAbsoluteAnchor().x,o=i.getNode().getPosition().y,s=n?[...i.getIncomingEdges()]:[...i.getOutgoingEdges()];for(let i of s)if(n?(i.setTarget(t),i.getBendPoints().push({x:a,y:o})):(i.setSource(t),i.getBendPoints().unshift({x:a,y:o})),r){let t=i.getProperty(e.nt);t??(t=[],i.setProperty(e.nt,t)),t.push({x:a,y:o})}}}function gu(t){let n=t.getProperty(e.lr),r=t.getPorts(`WEST`)[0],i=t.getPorts(`EAST`)[0],a=r.getProperty(e.lr),o=i.getProperty(e.lr);n.setSource(o),n.setTarget(a);let s={...i.getNode().getPosition()};s.x=o.getAbsoluteAnchor().x,n.getBendPoints().push(s);let c={...r.getNode().getPosition()};c.x=a.getAbsoluteAnchor().x,n.getBendPoints().push(c)}function _u(t){let n=t.getProperty(e.B);for(let r of t.getLayers())for(let t of[...r.getNodes()])if(t.getType()===`NORTH_SOUTH_PORT`){if(n===`SPLINES`)for(let n of t.getPorts()){let r=n.getProperty(e.lr);if(r.setProperty(e.Er,t.getPosition().y),n.getIncomingEdges().length>0)for(let e of[...n.getIncomingEdges()])e.setTarget(r);if(n.getOutgoingEdges().length>0)for(let e of[...n.getOutgoingEdges()])e.setSource(r)}else if(t.getProperty(e.lr)instanceof m)gu(t);else{let n=t.getPorts(),r=n.length>=2;for(let t=1;t<n.length;t++)if(n[t].getProperty(e.lr)!==n[t-1].getProperty(e.lr)){r=!1;break}n.length<2&&(r=!1);for(let e of n)e.getIncomingEdges().length>0&&hu([e],!0,r),e.getOutgoingEdges().length>0&&hu([e],!1,r)}t.setLayer(null)}}function vu(t,n,r,i,a){if((a?r.getSource().getNode():r.getTarget().getNode())===n.getNode())return;let o=new f(t);o.setType(`LONG_EDGE`),o.setProperty(e.lr,r),o.setProperty(e.Lt,`FIXED_POS`),i.push(o);let s=new p;s.setNode(o),s.setSide(`WEST`);let c=new p;if(c.setNode(o),c.setSide(`EAST`),a){r.setTarget(s);let t=new m;t.copyProperties(r),t.setProperty(e.nt,null),t.setSource(c),t.setTarget(n),bu(o,s,c,n),yu(r,t)}else{let t=r.getTarget();r.setTarget(s);let i=new m;i.copyProperties(r),i.setProperty(e.nt,null),i.setSource(c),i.setTarget(t),bu(o,s,c,n),yu(r,i)}}function yu(e,t){let n=e.getLabels();for(let e=n.length-1;e>=0;e--)if(n[e].placement===`HEAD`){let[r]=n.splice(e,1);t.getLabels().push(r)}}function bu(t,n,r,i){let a=n.getIncomingEdges()[0].getSource(),o=a.getNode();t.setProperty(e.rr,o.getType()===`LONG_EDGE`?o.getProperty(e.rr):a);let s=r.getOutgoingEdges()[0].getTarget(),c=s.getNode();t.setProperty(e.ir,c.getType()===`LONG_EDGE`?c.getProperty(e.ir):s)}function xu(t){let n=t.getLayers(),r=[],i=0;for(let a of n){if(i>0){for(let e of r)e.setLayer(n[i-1]);r.length=0}for(let n of a.getNodes())if(n.getType()===`NORMAL`&&e.Lr.isSideFixed(n.getProperty(e.Lt))){for(let e of n.getPorts(`INPUT`).filter(e=>e.getSide()===`EAST`))for(let n of[...e.getIncomingEdges()])vu(t,e,n,r,!0);for(let e of n.getPorts(`OUTPUT`).filter(e=>e.getSide()===`WEST`))for(let n of[...e.getOutgoingEdges()])vu(t,e,n,r,!1)}i++}for(let e of r)e.setLayer(n[n.length-1])}function Su(t){return t.getLayerlessNodes().some(t=>t.getProperty(e.g))}function Cu(t){for(let n of[...t.getLayerlessNodes()]){if(!n.getProperty(e.g))continue;let r=0,i=null,a=null;for(let e of n.getPorts())r+=e.getDegree(),e.getIncomingEdges().length===1&&(i=e.getIncomingEdges()[0],a=i.getSource()),e.getOutgoingEdges().length===1&&(i=e.getOutgoingEdges()[0],a=i.getTarget());if(r===1&&a!==null&&a.getDegree()===1&&!a.getNode().getProperty(e.g)){wu(n,i,a,a.getNode());let e=t.getLayerlessNodes().indexOf(n);e!==-1&&t.getLayerlessNodes().splice(e,1)}else{let e=[];for(let t of n.getPorts()){for(let n of t.getOutgoingEdges())n.getTarget().getNode().getOutgoingEdges().length>0&&e.push(n);for(let n of t.getIncomingEdges())n.getSource().getNode().getIncomingEdges().length>0&&e.push(n)}for(let n of e)n.reverse(t,!0)}}}function wu(t,n,r,i){let a=!1,o=!1,s=!1,c=i.getProperty(`org.eclipse.elk.portConstraints`);if(c!=null&&String(c).includes(`FIXED`)){let t=!1,n=!1;for(let r of i.getPorts())for(let i of r.getConnectedPorts())if(!i.getNode().getProperty(e.g)){if(r.getSide()===`NORTH`){t=!0;break}if(r.getSide()===`SOUTH`){n=!0;break}}o=n&&!t,s=t&&!n}if(!o&&!s&&i.getLabels().length>0){let e=0;for(let t of i.getLabels())e+=t.position.y+t.size.y/2;e/=i.getLabels().length,a=e>=i.size.y/2}else a=!s;let l=null;if(a){let t=i.getProperty(e.jr);if(t==null)l=[],i.setProperty(e.jr,l);else if(o)l=t;else{let n=i.getProperty(e.kn);n==null?(l=[],i.setProperty(e.kn,l)):l=t.length<=n.length?t:n}}else{let t=i.getProperty(e.kn);if(t==null)l=[],i.setProperty(e.kn,l);else if(s)l=t;else{let n=i.getProperty(e.jr);n==null?(l=[],i.setProperty(e.jr,l)):l=t.length<=n.length?t:n}}l.push(t),t.setProperty(e.Mn,r),n.getTarget()===r?(n.setTarget(null),r.getDegree()===0&&r.setNode(null),Tu(r)):(n.setSource(null),r.getDegree()===0&&r.setNode(null)),n.getBendPoints().length=0}function Tu(t){let n=t.getProperty(e._r);if(n!=null){let e=n.getLayer();if(e!==null){let t=e.getNodes(),r=t.indexOf(n);if(r!==-1&&t.splice(r,1),t.length===0){let t=n.getGraph().getLayers(),r=t.indexOf(e);r!==-1&&t.splice(r,1)}}}}function Eu(e){for(let t of e.getLayers())for(let e of t.getNodes())Ou(e)}function Du(e){Ou(e)}function Ou(t){let n=t.getMargin(),r=t.getProperty(e.jr),i=t.getProperty(e.kn);if(r==null&&i==null)return;let a=t.getGraph()?.getProperty(e.Xt)??10,o=t.getGraph()?.getProperty(e.Zt)??10,s=0;if(r!=null){let e=0;for(let t of r)e=Math.max(e,t.size.y),s+=t.size.x;s+=a*(r.length-1),n.top+=e+o}let c=0;if(i!=null){let e=0;for(let t of i)e=Math.max(e,t.size.y),c+=t.size.x;c+=a*(i.length-1),n.bottom+=e+o}let l=Math.max(s,c);if(l>t.size.x){let e=(l-t.size.x)/2;n.left=Math.max(n.left,e),n.right=Math.max(n.right,e)}}function ku(t){for(let n of t.getLayers()){let t=[];for(let r of n.getNodes()){let n=r.getProperty(e.jr),i=r.getProperty(e.kn);(n!=null||i!=null)&&(Au(r,n??null,i??null),n!=null&&t.push(...n),i!=null&&t.push(...i))}for(let e of t)n.getNodes().includes(e)||n.getNodes().push(e)}}function Au(t,n,r){let i=t.position,a=t.size,o=t.getMargin(),s=t.getGraph()?.getProperty(e.Xt)??10;if(n!=null){let r=s*(n.length-1),c=0;for(let e of n)r+=e.size.x,c=Math.max(c,e.size.y);let l=i.x-(r-a.x)/2,u=i.y-o.top+c,d=a.x/(n.length+1),f=d;for(let r of n){r.position.x=l,r.position.y=u-r.size.y,l+=r.size.x+s;let n=ju(r);n!==null&&(n.getPosition().x=r.size.x/2-n.getAnchor().x,n.getPosition().y=r.size.y);let i=r.getProperty(e.Mn);i!=null&&i.getDegree()===1&&(i.getPosition().x=f-i.getAnchor().x,i.getPosition().y=0,i.setNode(t)),f+=d}}if(r!=null){let n=s*(r.length-1),c=0;for(let e of r)n+=e.size.x,c=Math.max(c,e.size.y);let l=i.x-(n-a.x)/2,u=i.y+a.y+o.bottom-c,d=a.x/(r.length+1),f=d;for(let n of r){n.position.x=l,n.position.y=u,l+=n.size.x+s;let r=ju(n);r!==null&&(r.getPosition().x=n.size.x/2-r.getAnchor().x,r.getPosition().y=0);let i=n.getProperty(e.Mn);i!=null&&i.getDegree()===1&&(i.getPosition().x=f-i.getAnchor().x,i.getPosition().y=a.y,i.setNode(t)),f+=d}}}function ju(t){let n=t.getProperty(e.Mn);for(let e of t.getPorts()){for(let t of e.getOutgoingEdges())return n!=null&&t.setTarget(n),e;for(let t of e.getIncomingEdges())return n!=null&&t.setSource(n),e}return null}function J(e){let t=e.x;e.x=e.y,e.y=t}function Y(e,t){e.x=t-e.x}function X(e,t){e.y=t-e.y}function Mu(e){let t=e.top,n=e.bottom,r=e.left,i=e.right;e.top=r,e.bottom=i,e.left=t,e.right=n}function Nu(e){let t=e.left;e.left=e.right,e.right=t}function Pu(e){let t=e.top;e.top=e.bottom,e.bottom=t}function Fu(e){return e===`EAST`?`WEST`:e===`WEST`?`EAST`:e}function Iu(e){return e===`NORTH`?`SOUTH`:e===`SOUTH`?`NORTH`:e}function Lu(e){switch(e){case`NORTH`:return`WEST`;case`WEST`:return`NORTH`;case`SOUTH`:return`EAST`;case`EAST`:return`SOUTH`;default:return`UNDEFINED`}}function Ru(t){let n=t.getProperty(e.Rt);n!=null&&t.setProperty(e.Rt,-n)}function zu(e){switch(e.getLayerConstraint()){case`FIRST`:e.setLayerConstraint(`LAST`);break;case`FIRST_SEPARATE`:e.setLayerConstraint(`LAST_SEPARATE`);break;case`LAST`:e.setLayerConstraint(`FIRST`);break;case`LAST_SEPARATE`:e.setLayerConstraint(`FIRST_SEPARATE`)}}function Bu(e){switch(e.getInLayerConstraint()){case`TOP`:e.setInLayerConstraint(`BOTTOM`);break;case`BOTTOM`:e.setInLayerConstraint(`TOP`)}}function Vu(e){let t=e.getLayerConstraint(),n=e.getInLayerConstraint();t===`FIRST_SEPARATE`?(e.setLayerConstraint(`NONE`),e.setInLayerConstraint(`TOP`)):t===`LAST_SEPARATE`?(e.setLayerConstraint(`NONE`),e.setInLayerConstraint(`BOTTOM`)):n===`TOP`?(e.setLayerConstraint(`FIRST_SEPARATE`),e.setInLayerConstraint(`NONE`)):n===`BOTTOM`&&(e.setLayerConstraint(`LAST_SEPARATE`),e.setInLayerConstraint(`NONE`))}function Hu(e){return Array.isArray(e)?[...e]:String(e??``).replace(/[\[\]]/g,``).split(/[\s,]+/).filter(Boolean)}function Uu(e){let t=[...e],n=t.indexOf(`H_LEFT`),r=t.indexOf(`H_RIGHT`);return n>=0?t[n]=`H_RIGHT`:r>=0&&(t[r]=`H_LEFT`),t}function Wu(e){let t=[...e],n=t.indexOf(`V_TOP`),r=t.indexOf(`V_BOTTOM`);return n>=0?t[n]=`V_BOTTOM`:r>=0&&(t[r]=`V_TOP`),t}function Gu(e){if(e.length===0)return e;let t=[];return e.includes(`INSIDE`)?t.push(`INSIDE`):t.push(`OUTSIDE`),e.includes(`H_PRIORITY`)||t.push(`H_PRIORITY`),e.includes(`H_LEFT`)?t.push(`V_TOP`):e.includes(`H_CENTER`)?t.push(`V_CENTER`):e.includes(`H_RIGHT`)&&t.push(`V_BOTTOM`),e.includes(`V_TOP`)?t.push(`H_LEFT`):e.includes(`V_CENTER`)?t.push(`H_CENTER`):e.includes(`V_BOTTOM`)&&t.push(`H_RIGHT`),t}function Ku(e){return e.join(`, `)}var qu=class{mode;constructor(e){this.mode=e}process(t){let n=[...t.getLayerlessNodes()];for(let e of t.getLayers())n.push(...e.getNodes());let r=t.getProperty(e.F),i=t.getProperty(e.I)===`READING_DIRECTION`,a=this.mode===`TO_INPUT_DIRECTION`;if(i)switch(r){case`LEFT`:this.mirrorAllX(t,n);break;case`DOWN`:this.transposeAll(t,n);break;case`UP`:a?(this.mirrorAllY(t,n),this.transposeAll(t,n)):(this.transposeAll(t,n),this.mirrorAllY(t,n))}else if(a)switch(r){case`LEFT`:this.mirrorAllX(t,n),this.mirrorAllY(t,n);break;case`DOWN`:this.mirrorAllX(t,n),this.transposeAll(t,n);break;case`UP`:this.transposeAll(t,n),this.mirrorAllX(t,n)}else switch(r){case`LEFT`:this.mirrorAllX(t,n),this.mirrorAllY(t,n);break;case`DOWN`:this.transposeAll(t,n),this.mirrorAllX(t,n);break;case`UP`:this.mirrorAllX(t,n),this.transposeAll(t,n)}}mirrorAllX(t,n){t.hasProperty(e.gt)&&Nu(t.getProperty(e.gt));let r=0;if(t.getSize().x===0)for(let e of n)r=Math.max(r,e.position.x+e.size.x+e.getMargin().right);else r=t.getSize().x-t.getOffset().x;r-=t.getOffset().x;for(let t of n){Y(t.position,r-t.size.x),Nu(t.getPadding()),this.mirrorLabelPlacementX(t),this.mirrorPositionX(t,r),this.mirrorAlignmentX(t);let n=t.size;for(let i of t.getPorts()){Y(i.getPosition(),n.x-i.getSize().x),Y(i.getAnchor(),i.getSize().x),i.setSideInferred(Fu(i.getSide())),Ru(i);for(let t of i.getOutgoingEdges()){for(let e of t.getBendPoints())Y(e,r);let n=t.getProperty(e.nt);if(n!=null)for(let e of n)Y(e,r);for(let e of t.getLabels())Y(e.position,r-e.size.x)}for(let e of i.getLabels())Y(e.position,i.getSize().x-e.size.x)}t.getType()===`EXTERNAL_PORT`&&(t.setProperty(e.Un,Fu(t.getProperty(e.Un))),zu(t));for(let e of t.getLabels())this.mirrorLabelPlacementXOn(e),Y(e.position,n.x-e.size.x)}}mirrorAllY(t,n){t.hasProperty(e.gt)&&Pu(t.getProperty(e.gt));let r=0;if(t.getSize().y===0)for(let e of n)r=Math.max(r,e.position.y+e.size.y+e.getMargin().bottom);else r=t.getSize().y-t.getOffset().y;r-=t.getOffset().y;for(let t of n){X(t.position,r-t.size.y),Pu(t.getPadding()),this.mirrorLabelPlacementY(t),this.mirrorPositionY(t,r),this.mirrorAlignmentY(t);let n=t.size;for(let i of t.getPorts()){X(i.getPosition(),n.y-i.getSize().y),X(i.getAnchor(),i.getSize().y),i.setSideInferred(Iu(i.getSide())),Ru(i);for(let t of i.getOutgoingEdges()){for(let e of t.getBendPoints())X(e,r);let n=t.getProperty(e.nt);if(n!=null)for(let e of n)X(e,r);for(let e of t.getLabels())X(e.position,r-e.size.y)}for(let e of i.getLabels())X(e.position,i.getSize().y-e.size.y)}t.getType()===`EXTERNAL_PORT`&&(t.setProperty(e.Un,Iu(t.getProperty(e.Un))),Bu(t));for(let e of t.getLabels())this.mirrorLabelPlacementYOn(e),X(e.position,n.y-e.size.y)}}transposeAll(t,n){J(t.getOffset()),J(t.getSize()),Mu(t.getPadding()),t.hasProperty(e.gt)&&Mu(t.getProperty(e.gt));for(let t of n){J(t.position),J(t.size),Mu(t.getPadding()),this.transposeLabelPlacement(t),this.transposeProperties(t);for(let n of t.getPorts()){J(n.getPosition()),J(n.getAnchor()),J(n.getSize()),n.setSideInferred(Lu(n.getSide())),Ru(n);for(let t of n.getOutgoingEdges()){for(let e of t.getBendPoints())J(e);let n=t.getProperty(e.nt);if(n!=null)for(let e of n)J(e);for(let e of t.getLabels())J(e.position),J(e.size)}for(let e of n.getLabels())J(e.position),J(e.size)}t.getType()===`EXTERNAL_PORT`&&(t.setProperty(e.Un,Lu(t.getProperty(e.Un))),Vu(t));for(let e of t.getLabels())this.transposeLabelPlacementOn(e),J(e.size),J(e.position)}}mirrorLabelPlacementX(t){if(!t.hasProperty(e._t))return;let n=Hu(t.getProperty(e._t));n.length!==0&&t.setProperty(e._t,Uu(n))}mirrorLabelPlacementY(t){if(!t.hasProperty(e._t))return;let n=Hu(t.getProperty(e._t));n.length!==0&&t.setProperty(e._t,Wu(n))}transposeLabelPlacement(t){if(!t.hasProperty(e._t))return;let n=Hu(t.getProperty(e._t));t.setProperty(e._t,Gu(n))}mirrorLabelPlacementXOn(e){if(e.placement===void 0||e.placement===``)return;let t=Hu(e.placement);t.length!==0&&(e.placement=Ku(Uu(t)))}mirrorLabelPlacementYOn(e){if(e.placement===void 0||e.placement===``)return;let t=Hu(e.placement);t.length!==0&&(e.placement=Ku(Wu(t)))}transposeLabelPlacementOn(e){if(e.placement===void 0||e.placement===``)return;let t=Hu(e.placement);t.length!==0&&(e.placement=Ku(Gu(t)))}mirrorPositionX(t,n){if(!t.hasProperty(e.Ht))return;let r=t.getProperty(e.Ht);r&&Y(r,n-t.size.x)}mirrorPositionY(t,n){if(!t.hasProperty(e.Ht))return;let r=t.getProperty(e.Ht);r&&X(r,n-t.size.y)}mirrorAlignmentX(t){switch(t.getProperty(e.p)){case`LEFT`:t.setProperty(e.p,`RIGHT`);break;case`RIGHT`:t.setProperty(e.p,`LEFT`)}}mirrorAlignmentY(t){switch(t.getProperty(e.p)){case`TOP`:t.setProperty(e.p,`BOTTOM`);break;case`BOTTOM`:t.setProperty(e.p,`TOP`)}}transposeProperties(t){let n=t.getProperty(e.Et);t.setProperty(e.Et,{x:n.y,y:n.x});let r=t.getProperty(`org.eclipse.elk.contentAlignment`)??[];if(r.length>0){let e=r.map(e=>e===`H_CENTER`?`V_CENTER`:e===`V_CENTER`?`H_CENTER`:e===`H_LEFT`?`V_TOP`:e===`H_RIGHT`?`V_BOTTOM`:e===`V_TOP`?`H_LEFT`:e===`V_BOTTOM`?`H_RIGHT`:e);t.setProperty(`org.eclipse.elk.contentAlignment`,e)}switch(t.getProperty(e.p)){case`LEFT`:t.setProperty(e.p,`TOP`);break;case`RIGHT`:t.setProperty(e.p,`BOTTOM`);break;case`TOP`:t.setProperty(e.p,`LEFT`);break;case`BOTTOM`:t.setProperty(e.p,`RIGHT`)}if(t.hasProperty(e.Ht)){let n=t.getProperty(e.Ht);if(n){let e=n.x;n.x=n.y,n.y=e}}}transposeEdgeLabelPlacement(t){switch(t.getProperty(e.z)){case`ALWAYS_UP`:t.setProperty(e.z,`ALWAYS_DOWN`);break;case`ALWAYS_DOWN`:t.setProperty(e.z,`ALWAYS_UP`);break;case`DIRECTION_UP`:t.setProperty(e.z,`DIRECTION_DOWN`);break;case`DIRECTION_DOWN`:t.setProperty(e.z,`DIRECTION_UP`);break;case`SMART_UP`:t.setProperty(e.z,`SMART_DOWN`);break;case`SMART_DOWN`:t.setProperty(e.z,`SMART_UP`)}}},Ju=class{horizontalLayoutMode;gap;horizontalAlignment=`CENTER`;verticalAlignment=`CENTER`;entries=[];minimumContentAreaSize={x:0,y:0};cellRectangle={x:0,y:0,width:0,height:0};constructor(e,t){this.gap=e,this.horizontalLayoutMode=t}getHorizontalAlignment(){return this.horizontalAlignment}setHorizontalAlignment(e){return this.horizontalAlignment=e,this}getVerticalAlignment(){return this.verticalAlignment}setVerticalAlignment(e){return this.verticalAlignment=e,this}getEntries(){return this.entries}hasLabels(){return this.entries.length>0}addLabel(e,t){this.entries.push({label:e,edge:t});let n=e.size;this.horizontalLayoutMode?(this.minimumContentAreaSize.x=Math.max(this.minimumContentAreaSize.x,n.x),this.minimumContentAreaSize.y+=n.y,this.entries.length>1&&(this.minimumContentAreaSize.y+=this.gap)):(this.minimumContentAreaSize.x+=n.x,this.minimumContentAreaSize.y=Math.max(this.minimumContentAreaSize.y,n.y),this.entries.length>1&&(this.minimumContentAreaSize.x+=this.gap))}getMinimumWidth(){return this.minimumContentAreaSize.x}getMinimumHeight(){return this.minimumContentAreaSize.y}applyLabelLayout(){this.horizontalLayoutMode?this.applyHorizontalModeLabelLayout():this.applyVerticalModeLabelLayout()}applyHorizontalModeLabelLayout(){let e=this.cellRectangle,t=e.y;this.verticalAlignment===`CENTER`?t+=(e.height-this.minimumContentAreaSize.y)/2:this.verticalAlignment===`BOTTOM`&&(t+=e.height-this.minimumContentAreaSize.y);for(let n of this.entries){let r=n.label.size;switch(n.label.position.y=t,t+=r.y+this.gap,this.horizontalAlignment){case`LEFT`:n.label.position.x=e.x;break;case`CENTER`:n.label.position.x=e.x+(e.width-r.x)/2;break;case`RIGHT`:n.label.position.x=e.x+e.width-r.x}}}applyVerticalModeLabelLayout(){let e=this.cellRectangle,t=e.x;this.horizontalAlignment===`CENTER`?t+=(e.width-this.minimumContentAreaSize.x)/2:this.horizontalAlignment===`RIGHT`&&(t+=e.width-this.minimumContentAreaSize.x);for(let n of this.entries){let r=n.label.size;switch(n.label.position.x=t,t+=r.x+this.gap,this.verticalAlignment){case`TOP`:n.label.position.y=e.y;break;case`CENTER`:n.label.position.y=e.y+(e.height-r.y)/2;break;case`BOTTOM`:n.label.position.y=e.y+e.height-r.y}}}},Yu=class e{static DEFAULT_GAP=5;overlapRemovalDirection;gapVertical=e.DEFAULT_GAP;gapHorizontal=e.DEFAULT_GAP;startCoordinate=0;rectangleNodes=[];constructor(e){this.overlapRemovalDirection=e}static createForDirection(t){return new e(t)}withGap(e,t){return this.gapHorizontal=e,this.gapVertical=t,this}withStartCoordinate(e){return this.startCoordinate=e,this}getVerticalGap(){return this.gapVertical}getRectangleNodes(){return this.rectangleNodes}addRectangle(e){return this.rectangleNodes.push({originalRectangle:e,rectangle:this.importRectangle(e),overlappingNodes:[]}),this}importRectangle(e){switch(this.overlapRemovalDirection){case`UP`:case`DOWN`:return e;case`LEFT`:case`RIGHT`:return{x:e.y,y:0,width:e.height,height:e.width};default:throw Error(`unsupported direction`)}}exportRectangle(e){let t=e.rectangle,n=e.originalRectangle;switch(this.overlapRemovalDirection){case`UP`:n.y=this.startCoordinate-t.height-t.y;break;case`DOWN`:n.y+=this.startCoordinate;break;case`LEFT`:n.x=this.startCoordinate-t.height-t.y;break;case`RIGHT`:n.x=this.startCoordinate+t.y}}removeOverlaps(){this.rectangleNodes.sort((e,t)=>e.rectangle.x-t.rectangle.x),this.computeOverlaps();let e=this.greedyRemoveOverlaps();for(let e of this.rectangleNodes)this.exportRectangle(e);return e}computeOverlaps(){let e=[];for(let t of this.rectangleNodes){let n=t.rectangle.x;for(;e.length>0;){let t=e[0];if(t.rectangle.x+t.rectangle.width<n)e.shift();else break}for(let n of e)n.overlappingNodes.push(t),t.overlappingNodes.push(n);let r=t.rectangle.x+t.rectangle.width,i=e.findIndex(e=>e.rectangle.x+e.rectangle.width>r);i===-1&&(i=e.length),e.splice(i,0,t)}}greedyRemoveOverlaps(){let e=this.gapVertical,t=/* @__PURE__ */ new Set,n=0;for(let r of this.rectangleNodes){let i=0;r.overlappingNodes.sort((e,t)=>e.rectangle.y-t.rectangle.y);for(let n of r.overlappingNodes)if(t.has(n)){let t=r.rectangle,a=n.rectangle;i<a.y+a.height+e&&i+t.height+e>a.y&&(i=a.y+a.height+e)}r.rectangle.y=i,t.add(r),n=Math.max(n,r.rectangle.y+r.rectangle.height)}return n}};function Xu(t){let n=t.getProperty(e.tn),r=t.getProperty(e.an),i=t.getProperty(e.F),a=i===`DOWN`||i===`UP`;for(let e of t.getLayers())for(let t of e.getNodes())Zu(t,n,r,a)}function Zu(t,n,r,i){let a=t.getPorts().length,o=Array(a);for(let e=0;e<a;e++){let n=t.getPorts()[e];n.id=e,o[e]=Qu($u(n),r,i)}td(t,o,r,n,i);let s=/* @__PURE__ */ new Map;for(let e=0;e<o.length;e++){let n=o[e];n!==null&&s.set(t.getPorts()[e],n)}s.size>0&&(t.setProperty(e.Rn,s),ad(t,o))}function Qu(e,t,n){if(e===null||e.length===0)return null;let r=new Ju(t,!n);for(let t of e)r.addLabel(t.label,t.edge);return r.cellRectangle.height=r.getMinimumHeight(),r.cellRectangle.width=r.getMinimumWidth(),r}function $u(t){let n=[],r=ed(t,n),i=t.getProperty(e._r);if(i!=null)for(let a of i.getPorts())a.getProperty(e.lr)===t&&(r=Math.max(r,ed(a,n)));return n.length>0&&t.setProperty(e.or,r),r===-1?null:n}function ed(t,n){let r=-1,i=[];for(let a of t.getConnectedEdges()){if(r=Math.max(r,a.getProperty(e.W)),a.getSource()===t)for(let e of a.getLabels())e.placement===`TAIL`&&i.push({label:e,edge:a});else for(let e of a.getLabels())e.placement===`HEAD`&&i.push({label:e,edge:a});n.push(...i),i.length=0}return r}function td(e,t,n,r,i){for(let n of e.getPorts()){let e=t[n.id];e!==null&&nd(n,e,r)}i?(rd(e,t,`EAST`,2*n,r),rd(e,t,`WEST`,2*n,r)):(rd(e,t,`NORTH`,2*n,r),rd(e,t,`SOUTH`,2*n,r))}function nd(e,t,n){let r=t.cellRectangle,i=e.getNode().getSize(),a=e.getNode().getMargin(),o=e.getPosition(),s={x:o.x+e.getAnchor().x,y:o.y+e.getAnchor().y};switch(e.getSide()){case`NORTH`:t.setVerticalAlignment(`BOTTOM`),r.y=-a.top-n-r.height,sd(t)===`ABOVE`?(t.setHorizontalAlignment(`RIGHT`),r.x=s.x-ld(e)-n-r.width):(t.setHorizontalAlignment(`LEFT`),r.x=s.x+ld(e)+n);break;case`EAST`:t.setHorizontalAlignment(`LEFT`),r.x=i.x+a.right+n,sd(t)===`ABOVE`?(t.setVerticalAlignment(`BOTTOM`),r.y=s.y-ld(e)-n-r.height):(t.setVerticalAlignment(`TOP`),r.y=s.y+ld(e)+n);break;case`SOUTH`:t.setVerticalAlignment(`TOP`),r.y=i.y+a.bottom+n,sd(t)===`ABOVE`?(t.setHorizontalAlignment(`RIGHT`),r.x=s.x-ld(e)-n-r.width):(t.setHorizontalAlignment(`LEFT`),r.x=s.x+ld(e)+n);break;case`WEST`:t.setHorizontalAlignment(`RIGHT`),r.x=-a.left-n-r.width,sd(t)===`ABOVE`?(t.setVerticalAlignment(`BOTTOM`),r.y=s.y-ld(e)-n-r.height):(t.setVerticalAlignment(`TOP`),r.y=s.y+ld(e)+n)}}function rd(e,t,n,r,i){let a=Yu.createForDirection(cd(n)).withGap(r,r).withStartCoordinate(id(e,n,i));for(let r of e.getPorts(n)){let e=t[r.id];e!==null&&a.addRectangle(e.cellRectangle)}a.removeOverlaps()}function id(e,t,n){let r=e.getSize(),i=e.getMargin();switch(t){case`NORTH`:return-i.top-n;case`SOUTH`:return r.y+i.bottom+n;case`EAST`:return r.x+i.right+n;case`WEST`:return-i.left-n;default:return 0}}function ad(e,t){let n=e.getMargin(),r=e.getSize(),i={x:-n.left,y:-n.top,width:n.left+r.x+n.right,height:n.top+r.y+n.bottom};for(let e of t)e!==null&&(i=od(i,e.cellRectangle));n.left=-i.x,n.top=-i.y,n.right=i.width-n.left-r.x,n.bottom=i.height-n.top-r.y}function od(e,t){let n=Math.min(e.x,t.x),r=Math.min(e.y,t.y),i=Math.max(e.x+e.width,t.x+t.width),a=Math.max(e.y+e.height,t.y+t.height);return{x:n,y:r,width:i-n,height:a-r}}function sd(e){return`BELOW`}function cd(e){switch(e){case`NORTH`:return`UP`;case`SOUTH`:return`DOWN`;case`EAST`:return`RIGHT`;case`WEST`:return`LEFT`;default:return`UP`}}function ld(t){return t.getProperty(e.or)}function ud(t){switch(t.getProperty(e.z)){case`ALWAYS_UP`:fd(t,`ABOVE`);break;case`ALWAYS_DOWN`:fd(t,`BELOW`);break;case`DIRECTION_UP`:pd(t,`ABOVE`);break;case`DIRECTION_DOWN`:pd(t,`BELOW`);break;case`SMART_UP`:md(t,`ABOVE`),dd(t,`ABOVE`);break;case`SMART_DOWN`:md(t,`BELOW`),dd(t,`BELOW`)}}function dd(e,t){let n=e=>{for(let n of e.getOutgoingEdges())for(let e of n.getLabels()){let n=e;(n.side===void 0||n.side===``)&&(n.side=t)}};for(let t of e.getLayers())for(let e of t.getNodes())n(e);for(let t of e.getLayerlessNodes())n(t)}function fd(e,t){for(let n of e.getLayers())for(let e of n.getNodes()){e.getType()===`LABEL`&&Z(e,t);for(let n of e.getOutgoingEdges())Sd(n,t)}}function pd(e,t){let n=t===`ABOVE`?`BELOW`:`ABOVE`;for(let r of e.getLayers())for(let e of r.getNodes()){e.getType()===`LABEL`&&Z(e,Cd(e)?t:n);for(let r of e.getOutgoingEdges())Sd(r,Cd(r)?t:n)}}function md(e,t){let n=[];for(let r of e.getLayers()){let e=!0,i=0;for(let a of r.getNodes())switch(a.getType()){case`LABEL`:i++,n.push(a);break;case`LONG_EDGE`:n.push(a);break;case`NORMAL`:hd(a,t),n.length>0&&vd(n,i,e,!1,t),e=!1,i=0;break;default:n.length>0&&vd(n,i,e,!1,t),e=!1,i=0}n.length>0&&vd(n,i,e,!0,t)}}function hd(e,t){let n=[],r=null;for(let i of e.getPorts()){i.getSide()!==r&&(n.length>0&&gd(n,r,t),n.length=0,r=i.getSide());let e=$u(i);e!==null&&n.push(e)}n.length>0&&gd(n,r,t)}function gd(e,t,n){if(e.length===2)t===`NORTH`||t===`EAST`?(_d(e[0],`ABOVE`),_d(e[1],`BELOW`)):(_d(e[0],`BELOW`),_d(e[1],`ABOVE`));else for(let t of e)_d(t,n)}function _d(e,t){for(let n of e)n.label.side=t}function vd(e,t,n,r,i){n&&(!r||e.length>1)&&t===1&&e[0].getType()===`LABEL`?Z(e[0],`ABOVE`):r&&(!n||e.length>1)&&t===1&&e[e.length-1].getType()===`LABEL`?Z(e[e.length-1],`BELOW`):e.length===2?(Z(e[0],`ABOVE`),Z(e[1],`BELOW`)):yd(e,t,i),e.length=0}function yd(e,t,n){let r=[],i=null,a=null;for(let t of e){let e=xd(t,!0),o=xd(t,!1);(i!==e||a!==o)&&(bd(r,n),i=e,a=o),r.push(t)}bd(r,n)}function bd(e,t){if(e.length!==0){if(e.length===2)Z(e[0],`ABOVE`),Z(e[1],`BELOW`);else for(let n of e)Z(n,t);e.length=0}}function xd(t,n){let r=t.getProperty(n?e.rr:e.ir);return r==null?null:r.getNode()}function Z(t,n){if(t.getType()!==`LABEL`)return;let r=n;if(t.setProperty(e.er,r),r!==`BELOW`){let n=t.getProperty(e.lr)?.getProperty(e.W)??0,i=0;if(r===`ABOVE`)i=t.size.y-Math.ceil(n/2);else if(r===`INLINE`){let r=t.getGraph()?.getProperty(e.tn)??0;i=Math.ceil(t.size.y-r-n)/2,t.size.y-=r,t.size.y-=n}for(let e of t.getPorts())e.getPosition().y=i}}function Sd(e,t){for(let n of e.getLabels())n.side=t}function Cd(t){if(t instanceof f){let e=t.getIncomingEdges()[0],n=t.getOutgoingEdges()[0];return!!(e&&Cd(e)||n&&Cd(n))}return!t.getProperty(e.Sr)}function wd(e){for(let t of e.getLayers())for(let e of t.getNodes())e.getType()===`NORMAL`&&Td(e)}function Td(t){let n=!1,r=t.getProperty(e.Rn);if(r==null||!(r instanceof Map))return;let i=r;for(let e of t.getPorts())Ed(e)&&(n||=(Dd(t.getGraph()),!0),Od(e,i.get(e)))}function Ed(e){let t=0;for(let n of e.getIncomingEdges())n.getLabels().some(e=>e.placement===`HEAD`)&&t++;for(let n of e.getOutgoingEdges())n.getLabels().some(e=>e.placement===`TAIL`)&&t++;return t>=2}function Dd(e){if(e===null)return;let t=0;for(let n of e.getLayers())for(let e of n.getNodes()){e.id=t++;for(let n of e.getPorts())n.id=t++}}function Od(e,t){if(t===void 0)return;let n=kd(t);n.sort(jd);let r=t.getEntries();r.length=0;for(let e of n)r.push(...e.entries)}function kd(e){let t=/* @__PURE__ */ new Map;for(let n of e.getEntries()){let e=n.edge,r=t.get(e);r===void 0&&(r=new Ad(e),t.set(e,r)),r.entries.push(n)}return[...t.values()]}var Ad=class{edge;entries=[];constructor(e){this.edge=e}};const jd=(e,t)=>{let n=e.edge,r=t.edge;if(n===null||r===null)return 0;let i=n.getSource(),a=r.getSource();if(i!==null&&a!==null){let e=i.id-a.id;if(e!==0)return e}let o=n.getTarget(),s=r.getTarget();if(o!==null&&s!==null){let e=o.getNode(),t=s.getNode(),n=(e?.id??0)-(t?.id??0);return n===0?s.id-o.id:n}return 0};function Md(t){for(let n of t.getLayers())for(let t of n.getNodes())(t.getType()===`NORMAL`||t.getType()===`EXTERNAL_PORT`)&&t.hasProperty(e.Rn)&&Nd(t)}function Nd(t){let n=t.getProperty(e.Rn);if(n==null)return;let r=t.getPosition();for(let e of n.values()){let t=e,n=t.cellRectangle;n.x+=r.x,n.y+=r.y,t.applyLabelLayout()}t.setProperty(e.Rn,null)}var Pd=class{targetNodeModelOrder;portModelOrder;previousLayer;graph;strategy;biggerThan=/* @__PURE__ */ new Map;smallerThan=/* @__PURE__ */ new Map;constructor(e,t,n,r,i){this.graph=e,this.previousLayer=t,this.strategy=n,this.targetNodeModelOrder=r,this.portModelOrder=i}compare(t,n){let r=t,i=n;if(!this.biggerThan.has(r))this.biggerThan.set(r,/* @__PURE__ */ new Set);else if(this.biggerThan.get(r).has(i))return 1;if(!this.biggerThan.has(i))this.biggerThan.set(i,/* @__PURE__ */ new Set);else if(this.biggerThan.get(i).has(r))return-1;if(!this.smallerThan.has(r))this.smallerThan.set(r,/* @__PURE__ */ new Set);else if(this.smallerThan.get(r).has(i))return-1;if(!this.smallerThan.has(i))this.smallerThan.set(i,/* @__PURE__ */ new Set);else if(this.biggerThan.get(i).has(r))return 1;if(r.getSide()!==i.getSide()){let e=Ld(r.getSide())-Ld(i.getSide());return e>0?this.updateBiggerAndSmallerAssociations(r,i,1):this.updateBiggerAndSmallerAssociations(i,r,1),e}let a=1;if(r.getIncomingEdges().length>0&&i.getIncomingEdges().length>0){(r.getSide()===`WEST`&&i.getSide()===`WEST`||r.getSide()===`NORTH`&&i.getSide()===`NORTH`||r.getSide()===`SOUTH`&&i.getSide()===`SOUTH`)&&(a=-a);let e=r.getIncomingEdges()[0].getSource(),t=i.getIncomingEdges()[0].getSource(),n=e.getNode(),o=t.getNode();if(n===o)for(let o of n.getPorts()){if(e===o)return this.updateBiggerAndSmallerAssociations(i,r,a),-a;if(t===o)return this.updateBiggerAndSmallerAssociations(r,i,a),a}if(n.getType()===`LONG_EDGE`&&o.getType()===`LONG_EDGE`&&n.getLayer().id===o.getLayer().id&&n.getLayer().id===r.getNode().getLayer().id){let e=this.checkReferenceLayer(n.getLayer().getNodes(),n,o);if(e!==0)return r.getSide()===`EAST`&&i.getSide()===`EAST`&&(a=-a),e>0?(this.updateBiggerAndSmallerAssociations(r,i,a),a):(this.updateBiggerAndSmallerAssociations(i,r,a),-a)}let s=this.checkReferenceLayer(this.previousLayer,n,o);if(s!==0)return s>0?(this.updateBiggerAndSmallerAssociations(r,i,a),a):(this.updateBiggerAndSmallerAssociations(i,r,a),-a);if(this.portModelOrder){let e=this.checkPortModelOrder(r,i);if(e!==0)return e>0?(this.updateBiggerAndSmallerAssociations(r,i,a),a):(this.updateBiggerAndSmallerAssociations(i,r,a),-a)}}if(r.getOutgoingEdges().length>0&&i.getOutgoingEdges().length>0){(r.getSide()===`WEST`&&i.getSide()===`WEST`||r.getSide()===`SOUTH`&&i.getSide()===`SOUTH`)&&(a=-a);let t=r.getProperty(e.ar),n=i.getProperty(e.ar);if(this.strategy===`PREFER_NODES`&&t!=null&&n!=null&&t.hasProperty(e.cr)&&n.hasProperty(e.cr))return O(t,n,this.graph,this.graph.getProperty(`org.eclipse.elk.layered.internal.maxModelOrderNodes`))>O(n,t,this.graph,this.graph.getProperty(`org.eclipse.elk.layered.internal.maxModelOrderNodes`))?(this.updateBiggerAndSmallerAssociations(r,i,a),a):(this.updateBiggerAndSmallerAssociations(i,r,a),-a);if(this.portModelOrder){let e=this.checkPortModelOrder(r,i);if(e!==0)return e>0?(this.updateBiggerAndSmallerAssociations(r,i,a),a):(this.updateBiggerAndSmallerAssociations(i,r,a),-a)}let o=0,s=0;return r.getOutgoingEdges()[0].hasProperty(e.cr)&&(o=O(r.getOutgoingEdges()[0],i.getOutgoingEdges()[0],this.graph,r.getOutgoingEdges().length+r.getIncomingEdges().length)),i.getOutgoingEdges()[0].hasProperty(e.cr)&&(s=O(i.getOutgoingEdges()[0],r.getOutgoingEdges()[0],this.graph,i.getOutgoingEdges().length+i.getIncomingEdges().length)),t!=null&&t===n||this.targetNodeModelOrder!=null&&(this.targetNodeModelOrder.has(t)&&(o=this.targetNodeModelOrder.get(t)),this.targetNodeModelOrder.has(n)&&(s=this.targetNodeModelOrder.get(n))),o>s?(this.updateBiggerAndSmallerAssociations(r,i,a),a):(this.updateBiggerAndSmallerAssociations(i,r,a),-a)}if(r.getIncomingEdges().length>0&&i.getOutgoingEdges().length>0)return this.updateBiggerAndSmallerAssociations(r,i,a),1;if(r.getOutgoingEdges().length>0&&i.getIncomingEdges().length>0)return this.updateBiggerAndSmallerAssociations(i,r,a),-1;if(r.hasProperty(e.cr)&&i.hasProperty(e.cr)){let e=r.getNode().getPorts().length,t=O(r,i,this.graph,e),n=O(i,r,this.graph,e);return(r.getSide()===`WEST`&&i.getSide()===`WEST`||r.getSide()===`SOUTH`&&i.getSide()===`SOUTH`)&&(a=-a),t>n?(this.updateBiggerAndSmallerAssociations(r,i,a),a):(this.updateBiggerAndSmallerAssociations(i,r,a),-a)}return this.updateBiggerAndSmallerAssociations(i,r,a),-a}checkPortModelOrder(t,n){let r=t.getNode().getPorts().length;return t.hasProperty(e.cr)&&n.hasProperty(e.cr)?O(t,n,this.graph,r)-O(n,t,this.graph,r):0}updateBiggerAndSmallerAssociations(e,t,n){let r=e,i=t;n<0&&(r=t,i=e);let a=this.biggerThan.get(r),o=this.biggerThan.get(i),s=this.smallerThan.get(r),c=this.smallerThan.get(i);a.add(i),c.add(r);for(let e of o){a.add(e),this.smallerThan.get(e).add(r);for(let t of s)this.smallerThan.get(e).add(t)}for(let e of s){c.add(e),this.biggerThan.get(e).add(i);for(let t of o)this.biggerThan.get(e).add(t)}}checkReferenceLayer(e,t,n){for(let r of e){if(r===t)return-1;if(r===n)return 1}return 0}clearTransitiveOrdering(){this.biggerThan=/* @__PURE__ */ new Map,this.smallerThan=/* @__PURE__ */ new Map}},Fd=class{previousLayer;graph;orderingStrategy;groupOrderStrategy;biggerThan=/* @__PURE__ */ new Map;smallerThan=/* @__PURE__ */ new Map;longEdgeNodeOrder;beforePorts;constructor(e,t,n,r,i,a){this.graph=e,this.previousLayer=t,this.orderingStrategy=n,this.groupOrderStrategy=i,this.longEdgeNodeOrder=r,this.beforePorts=a}compare(t,n){if(!this.biggerThan.has(t))this.biggerThan.set(t,/* @__PURE__ */ new Set);else if(this.biggerThan.get(t).has(n))return 1;if(!this.biggerThan.has(n))this.biggerThan.set(n,/* @__PURE__ */ new Set);else if(this.biggerThan.get(n).has(t))return-1;if(!this.smallerThan.has(t))this.smallerThan.set(t,/* @__PURE__ */ new Set);else if(this.smallerThan.get(t).has(n))return-1;if(!this.smallerThan.has(n))this.smallerThan.set(n,/* @__PURE__ */ new Set);else if(this.biggerThan.get(n).has(t))return 1;if(this.orderingStrategy===`PREFER_EDGES`||!t.hasProperty(e.cr)||!n.hasProperty(e.cr)){let r=null;for(let e of t.getPorts())if(e.getIncomingEdges().length>0&&e.getIncomingEdges()[0].getSource().getNode().getLayer().id===t.getLayer().id-1){r=e.getIncomingEdges()[0].getSource();break}let i=null;for(let e of n.getPorts())if(e.getIncomingEdges()[0]?.getSource()?.getNode(),e.getIncomingEdges().length>0&&e.getIncomingEdges()[0].getSource().getNode().getLayer().id===n.getLayer().id-1){i=e.getIncomingEdges()[0].getSource();break}if(r!==null&&i!==null){let e=r.getNode(),a=i.getNode();if(e===a){for(let a of e.getPorts()){if(a===r)return this.updateBiggerAndSmallerAssociations(n,t),-1;if(a===i)return this.updateBiggerAndSmallerAssociations(t,n),1}return this.getModelOrderFromConnectedEdges(t)>this.getModelOrderFromConnectedEdges(n)?(this.updateBiggerAndSmallerAssociations(t,n),1):(this.updateBiggerAndSmallerAssociations(n,t),-1)}for(let r of this.previousLayer){if(r===e)return this.updateBiggerAndSmallerAssociations(n,t),-1;if(r===a)return this.updateBiggerAndSmallerAssociations(t,n),1}}if(r!==null&&i===null||r===null&&i!==null){let r=this.handleHelperDummyNodes(t,n);if(r!==0)return r>0?this.updateBiggerAndSmallerAssociations(t,n):this.updateBiggerAndSmallerAssociations(n,t),r;if(!t.hasProperty(e.cr)||!n.hasProperty(e.cr))return this.getModelOrderFromConnectedEdges(t)>this.getModelOrderFromConnectedEdges(n)?(this.updateBiggerAndSmallerAssociations(t,n),1):(this.updateBiggerAndSmallerAssociations(n,t),-1)}if(r===null&&i===null){let e=this.handleHelperDummyNodes(t,n);if(e!==0)return e>0?this.updateBiggerAndSmallerAssociations(t,n):this.updateBiggerAndSmallerAssociations(n,t),e}}return t.hasProperty(e.cr)&&n.hasProperty(e.cr)&&O(t,n,this.graph,this.graph.getProperty(e.sr))>O(n,t,this.graph,this.graph.getProperty(e.sr))?(this.updateBiggerAndSmallerAssociations(t,n),1):(this.updateBiggerAndSmallerAssociations(n,t),-1)}getModelOrderFromConnectedEdges(t){let n=t.getPorts().find(e=>e.getIncomingEdges().length>0);if(n!==void 0){let t=n.getIncomingEdges()[0];if(t!==void 0)return t.getProperty(e.cr)}return Id(this.longEdgeNodeOrder)}updateBiggerAndSmallerAssociations(e,t){let n=this.biggerThan.get(e),r=this.biggerThan.get(t),i=this.smallerThan.get(e),a=this.smallerThan.get(t);n.add(t),a.add(e);for(let t of r){n.add(t),this.smallerThan.get(t).add(e);for(let e of i)this.smallerThan.get(t).add(e)}for(let e of i){a.add(e),this.biggerThan.get(e).add(t);for(let t of r)this.biggerThan.get(e).add(t)}}handleHelperDummyNodes(e,t){if(e.getType()===`LONG_EDGE`&&t.getType()===`NORMAL`){let n=this.getFirstIncomingSourcePortOfNode(e).getNode(),r=this.getFirstOutgoingTargetPortOfNode(e).getNode(),i=e.getLayer().id;return n.getLayer().id!==i&&r.getLayer().id!==i?0:n===t||r===t?(this.updateBiggerAndSmallerAssociations(e,t),1):this.compare(n,t)}if(e.getType()===`NORMAL`&&t.getType()===`LONG_EDGE`){let n=this.getFirstIncomingSourcePortOfNode(t).getNode(),r=this.getFirstOutgoingTargetPortOfNode(t).getNode(),i=e.getLayer().id;return n.getLayer().id!==i&&r.getLayer().id!==i?0:n===e||r===e?(this.updateBiggerAndSmallerAssociations(t,e),-1):this.compare(e,n)}if(e.getType()===`LONG_EDGE`&&t.getType()===`LONG_EDGE`){let n=this.getFirstIncomingSourcePortOfNode(e),r=this.getFirstOutgoingTargetPortOfNode(e),i=n.getNode(),a=r.getNode(),o=e.getLayer().id,s=!1,c=!1,l=this.getFirstIncomingSourcePortOfNode(t),u=this.getFirstOutgoingTargetPortOfNode(t),d=l.getNode(),f=u.getNode(),p=t.getLayer().id,m=!1,h=!1,g=e,_=t;if(i.getLayer().id===o?(s=!0,g=i):a.getLayer().id===o&&(c=!0,g=a),d.getLayer().id===p?(m=!0,_=d):f.getLayer().id===p&&(h=!0,_=f),g===_){if(this.beforePorts){if(s&&m)return new Pd(this.graph,this.previousLayer,this.orderingStrategy,null,h).compare(n,l)>0?(this.updateBiggerAndSmallerAssociations(t,e),1):(this.updateBiggerAndSmallerAssociations(e,t),-1);if(s&&h)return this.updateBiggerAndSmallerAssociations(t,e),1;if(c&&m)return this.updateBiggerAndSmallerAssociations(e,t),-1;if(c&&h)return 0}else for(let r of g.getPorts()){if(n===r)return this.updateBiggerAndSmallerAssociations(t,e),-1;if(l===r)return this.updateBiggerAndSmallerAssociations(e,t),1}}return this.compare(g,_)}return 0}getFirstIncomingPortOfNode(e){return e.getPorts().find(e=>e.getIncomingEdges().length>0)}getFirstIncomingSourcePortOfNode(e){return this.getFirstIncomingPortOfNode(e).getIncomingEdges()[0].getSource()}getFirstOutgoingPortOfNode(e){return e.getPorts().find(e=>e.getOutgoingEdges().length>0)}getFirstOutgoingTargetPortOfNode(e){return this.getFirstOutgoingPortOfNode(e).getOutgoingEdges()[0].getTarget()}clearTransitiveOrdering(){this.biggerThan=/* @__PURE__ */ new Map,this.smallerThan=/* @__PURE__ */ new Map}};function Id(e){switch(e){case`DUMMY_NODE_OVER`:return 2**53-1;case`DUMMY_NODE_UNDER`:return-(2**53-1);default:return 0}}function Ld(e){switch(e){case`UNDEFINED`:return 0;case`NORTH`:return 1;case`EAST`:return 2;case`SOUTH`:return 3;case`WEST`:return 4}}function Rd(t){let n=0;for(let r of t.getLayers()){r.id=n;let i=n===0?0:n-1,a=t.getLayers()[i].getNodes(),o=new Fd(t,a,t.getProperty(e.O),t.getProperty(e.T),t.getProperty(e.S),!0);Vd(r.getNodes(),o);for(let n of r.getNodes()){let r=n.getProperty(e.Lt);if(r!==`FIXED_ORDER`&&r!==`FIXED_POS`){let r=new Pd(t,a,t.getProperty(e.O),zd(n),t.getProperty(e.D));n.getPorts().sort((e,t)=>r.compare(e,t))}}o=new Fd(t,a,t.getProperty(e.O),t.getProperty(e.T),t.getProperty(e.S),!1),Vd(r.getNodes(),o),n++}}function zd(t){let n=/* @__PURE__ */ new Map;if(t.hasProperty(e.kr))return t.getProperty(e.kr);for(let r of t.getPorts()){if(r.getOutgoingEdges().length===0)continue;let t=Bd(r);if(r.setProperty(e.ar,t),t!==null){let i=2**53-1;n.has(t)&&(i=n.get(t));let a=r.getOutgoingEdges()[0];a.getProperty(e.Sr)||n.set(t,Math.min(a.getProperty(e.cr),i))}}return t.setProperty(e.kr,n),n}function Bd(t){let n=null,r=t.getOutgoingEdges()[0];for(;;){if(n=r.getTarget().getNode(),n.hasProperty(e.ir))return n.getProperty(e.ir).getNode();if(n.getType()!==`NORMAL`&&n.getOutgoingEdges().length>0)r=n.getOutgoingEdges()[0];else if(n.getType()!==`NORMAL`)return null;if(n.getType()===`NORMAL`)break}return n}function Vd(e,t){for(let n=1;n<e.length;n++){let r=e[n],i=n;for(;i>0&&t.compare(e[i-1],r)>0;)e[i]=e[i-1],i--;e[i]=r}t.clearTransitiveOrdering()}function Hd(t){let n=!1;for(let r of t.getLayers()){let t=r.getNodes().filter(e=>e.getType()===`NORMAL`).filter(t=>t.hasProperty(e.Ht)&&t.getProperty(e.Ht)!==null).sort((t,n)=>{let r=t.getProperty(e.Ht),i=n.getProperty(e.Ht);return(r?.y??0)-(i?.y??0)});for(let r=0;r+1<t.length;r++){let i=t[r].getProperty(e.Qn)??[];i.push(t[r+1]),t[r].setProperty(e.Qn,i),n=!0}}n&&t.setProperty(e.$n,!0)}function Ud(t){let n=t.getLayerlessNodes().filter(t=>t.hasProperty(e.kt)),r=[];for(let i of t.getLayerlessNodes())if(i.hasProperty(e.kt))for(let e of i.getOutgoingEdges())Wd(e,n)&&r.push(e);for(let n of r){n.reverse(t,!0);let r=1e3;n.hasProperty(e.Ut)&&(r+=n.getProperty(e.Ut)),n.setProperty(e.Ut,r)}}function Wd(t,n){let r=t.getSource()?.getNode(),i=t.getTarget()?.getNode();if(!r||!i)return!1;let a=r.getProperty(e.kt);if(i.hasProperty(e.kt))return a>i.getProperty(e.kt);let o=n.filter(t=>t.getProperty(e.kt)<a),s=[r],c=/* @__PURE__ */ new Set([r]);for(;s.length>0;){let e=s.shift();if(o.includes(e))return!0;for(let t of e.getOutgoingEdges()){let e=t.getTarget()?.getNode();e&&!c.has(e)&&(c.add(e),s.push(e))}}return!1}function Gd(t){let n=/* @__PURE__ */ new Map;for(let r of t.getLayerlessNodes())if(r.hasProperty(e.kt)){let t=r.getProperty(e.kt);n.has(t)||n.set(t,[]),n.get(t).push(r)}if(n.size===0)return;let r=[...n.keys()].sort((e,t)=>e-t);for(let e=0;e+1<r.length;e++)Kd(n.get(r[e]),n.get(r[e+1]))}function Kd(t,n){for(let r of t){let t=new p;t.setNode(r),t.setSide(`EAST`),t.setProperty(e.gr,!0);for(let r of n){let n=new p;n.setNode(r),n.setSide(`WEST`),n.setProperty(e.gr,!0);let i=new m;i.setProperty(e.gr,!0),i.setSource(t),i.setTarget(n)}}}function qd(t){for(let n of t.getLayers())for(let t of n.getNodes())t.setPorts(t.getPorts().filter(t=>!t.getProperty(e.gr)))}function Jd(t){t.getProperty(e.Ot)&&t.getProperty(e.Gn).add(`PARTITIONS`)}function Yd(t){let n=t.getProperty(e.J),r=t.getProperty(e.X);r===0&&(r=2**53-1);let i=t.getLayers(),a=0;for(;a<i.length;){let e=i[a],o=[],s=-1,c=-1;for(let t of[...e.getNodes()])if($d(t)>=n){let e=Xd(t,n,r);s=Math.max(s,e.incMax),c=Math.max(c,e.outMax),o.push([t,e])}let l=[];for(let e=0;e<s;e++){let e=new w(t);i.splice(a,0,e),l.unshift(e)}l.reverse();for(let[,e]of o)if(e.incRoots!==null)for(let t of e.incRoots)Qd(t,e=>e.getIncomingEdges(),l);let u=a+Math.max(0,s),d=[];for(let e=0;e<c;e++){let n=new w(t);i.splice(u+1+e,0,n),d.push(n)}for(let[,e]of o)if(e.outRoots!==null)for(let t of e.outRoots)Qd(t,e=>e.getOutgoingEdges(),d);a+=Math.max(0,s)+1+Math.max(0,c)}for(let e=i.length-1;e>=0;e--)i[e].getNodes().length===0&&i.splice(e,1)}function Xd(e,t,n){let r={incMax:-1,incRoots:null,outMax:-1,outRoots:null};for(let i of e.getIncomingEdges()){if(i.isSelfLoop())continue;let e=i.getSource().getNode();if(ef(e,e=>e.getOutgoingEdges())){let i=Zd(e,e=>e.getOutgoingEdges(),e=>e.getIncomingEdges(),t,n);if(i===-1)continue;r.incMax=Math.max(r.incMax,i),r.incRoots===null&&(r.incRoots=[]),r.incRoots.push(e)}}for(let i of e.getOutgoingEdges()){if(i.isSelfLoop())continue;let e=i.getTarget().getNode();if(ef(e,e=>e.getIncomingEdges())){let i=Zd(e,e=>e.getIncomingEdges(),e=>e.getOutgoingEdges(),t,n);if(i===-1)continue;r.outMax=Math.max(r.outMax,i),r.outRoots===null&&(r.outRoots=[]),r.outRoots.push(e)}}return r}function Zd(e,t,n,r,i){if($d(e)>=r||!ef(e,t))return-1;let a=n(e);if(a.length===0)return 1;let o=0;for(let s of a){let a=Zd(tf(s,e),t,n,r,i);if(a===-1||(o=Math.max(o,a),o>i-1))return-1}return o+1}function Qd(e,t,n){e.setLayer(n[0]);let r=n.slice(1);for(let n of t(e))Qd(tf(n,e),t,r)}function $d(e){return e.getConnectedEdges().length}function ef(e,t){let n=null;for(let r of t(e)){let t=tf(r,e);if(n===null)n=t;else if(t!==n)return!1}return!0}function tf(e,t){let n=e.getSource()?.getNode(),r=e.getTarget()?.getNode();return n===t?r:n}function nf(t){let n=1,r=[];for(let i=0;i<t.getLayers().length;i++){let a=t.getLayers()[i],o=rf(a),s=af(a);if(of(a)){let n=0,r=0;for(let e of a.getNodes())n=Math.max(n,e.size.x),r+=e.size.y;if(r/=a.getNodes().length,n+=Math.max(2*t.getProperty(e.rn),Math.max(a.getNodes().length*t.getProperty(e.en),t.getProperty(e.un))),r+=Math.max(t.getProperty(e.ln),t.getProperty(e.nn)),n/r>=a.getNodes().length/4)continue}if(a.getNodes().length>=o){let e=[a];for(let a=0;a<o-1;a++){let o=new w(t);r.push({layer:o,index:i+a+n}),e.push(o)}n+=o-1;let c=e[0].getNodes().length;for(let n=0,r=0,i=0;n<c;n++,r++,i++){let a=e[0].getNodes()[r];a.getType()===`NONSHIFTING_PLACEHOLDER`?(--n,--i):r+=sf(t,e,i%o,r),s&&a.getType()===`LONG_EDGE`&&(i=-1)}}}for(let e of r)t.getLayers().splice(e.index,0,e.layer);for(let e of t.getLayers()){let t=e.getNodes();for(let e=t.length-1;e>=0;e--){let n=t[e];(n.getType()===`PLACEHOLDER`||n.getType()===`NONSHIFTING_PLACEHOLDER`)&&t.splice(e,1)}}}function rf(t){let n=2**53-1,r=!0;for(let i=0;i<t.getNodes().length;i++){let a=t.getNodes()[i];if(a.hasProperty(e.ut)){r=!1;let t=a.getProperty(e.ut);n=n<t?n:t}}return r&&(n=e.ut.getDefault()),n}function af(t){for(let n=0;n<t.getNodes().length;n++){let r=t.getNodes()[n];if(r.hasProperty(e.ft)&&!r.getProperty(e.ft))return!1}return!0}function of(t){for(let n=0;n<t.getNodes().length;n++){let r=t.getNodes()[n];if(r.hasProperty(e.dt)&&r.getProperty(e.dt))return!0}return!1}function sf(e,t,n,r){let i=t[0].getNodes()[r];n>0&&i.setLayer(t[n]);let a=0,o=!0,s=[...i.getIncomingEdges()].reverse();for(let i of s){o=!1;let s=i;for(let i=0;i<n;i++){let n=cf(e,s);r+a>t[i].getNodes().length?n.setLayer(t[i]):n.setLayerAt(r+a,t[i]),s=ue(s,n)}n>0&&(a+=1)}if(o){for(let i=0;i<n;i++){let n=new f(e);n.setType(`PLACEHOLDER`),r+a>t[i].getNodes().length?n.setLayer(t[i]):n.setLayerAt(r+a,t[i])}n>0&&(a+=1)}let c=!1;for(let o of i.getOutgoingEdges()){let i=o;for(let r=n+1;r<t.length;r++){let n=cf(e,i);n.setLayer(t[r]),i=ue(i,n)}for(let i=0;i<=n;i++)if(c){let n=new f(e);n.setType(`NONSHIFTING_PLACEHOLDER`),r+1>t[i].getNodes().length?n.setLayer(t[i]):n.setLayerAt(r+1,t[i])}c&&(a+=1),c=!0}return a>0?a-1:0}function cf(t,n){let r=new f(t);return r.setType(`LONG_EDGE`),r.setProperty(e.lr,n),r.setProperty(e.Lt,`FIXED_POS`),r}function lf(t){let n=t.getProperty(e.P),r=n===`MODEL_ORDER`||n===`GREEDY_MODEL_ORDER`||n===`BFS_NODE_ORDER`||n===`DFS_NODE_ORDER`||n===`SCC_CONNECTIVITY`||n===`SCC_NODE_TYPE`,i=t.getProperty(e.lt),a=i===`BF_MODEL_ORDER`||i===`DF_MODEL_ORDER`||t.getProperty(e.ct)===`MODEL_ORDER_LEFT_TO_RIGHT`||t.getProperty(e.ct)===`MODEL_ORDER_RIGHT_TO_LEFT`,o=t.getProperty(e.O)!==`NONE`||t.getProperty(e.Pn)||t.getProperty(e.y)!==e.Dn.NONE;return r||a||o}function uf(e){let t=[],n=[e];for(;n.length>0;){let e=n.pop();t.push(e);for(let t of e.getLayerlessNodes()){let e=t.getNestedGraph();e!==null&&n.push(e)}}return t}function df(t){if(!lf(t))return;let n=0,r=/* @__PURE__ */ new Set;for(let i of t.getLayerlessNodes())i.getProperty(e.E)||(i.setProperty(e.cr,n++),i.hasProperty(e.w)&&r.add(i.getProperty(e.w)));t.setProperty(e.sr,n),t.setProperty(e.jn,r.size);let i=0;for(let n of t.getLayerlessNodes())for(let t of n.getPorts())for(let n of t.getOutgoingEdges())n.setProperty(e.cr,i++)}function ff(e){for(let t of uf(e))df(t)}function pf(t){let n=[t];for(;n.length>0;){let t=n.pop();for(let r of t.getLayerlessNodes()){let t=r.getOutgoingEdges().some(t=>t.isSelfLoop()&&t.getProperty(e.$));if(r.getProperty(e.Q)&&t&&r.getNestedGraph()===null){let t=new c;r.setNestedGraph(t),t.setParentNode(r),t.setProperty(e.F,`RIGHT`)}let i=r.getNestedGraph();i!==null&&n.push(i)}}}var mf=class{begin(){}done(){}};function hf(e){let t=[],n=[e];for(;n.length>0;){let e=n.pop();for(let t of e.getLayerlessNodes()){let e=t.getNestedGraph();e!==null&&n.push(e)}t.push(e)}return t.reverse()}function gf(t,n,r,i){let a={x:n.position.x+n.size.x/2,y:n.position.y+n.size.y/2},o=n.getProperty(e.It),s=t.getSize(),c=t.getPadding(),l=t.getOffset();switch(n.getProperty(e.lr),n.getProperty(e.Un)){case`NORTH`:a.x+=c.left+l.x-r/2,a.y=-i-o,n.position.y=-(c.top+o+l.y);break;case`EAST`:a.x=s.x+c.left+c.right+o,a.y+=c.top+l.y-i/2,n.position.x=s.x+c.right+o-l.x;break;case`SOUTH`:a.x+=c.left+l.x-r/2,a.y=s.y+c.top+c.bottom+o,n.position.y=s.y+c.bottom+o-l.y;break;case`WEST`:a.x=-r-o,a.y+=c.top+l.y-i/2,n.position.x=-(c.left+o+l.x)}return a}function _f(t,n){let r=t.getNestedGraph();if(r===null)return;let i=r.getAllNodes();if(i.length===0)return;let a=t=>{let r=t.getType();if(r===`NORMAL`||r===`LONG_EDGE`)return!0;if(r===`EXTERNAL_PORT`){if(!n&&o)return!1;let r=t.getProperty(e.Un);return r===`WEST`||r===`EAST`||t.getPorts().some(e=>e.getConnectedEdges().length>0)}return!1},o=i.some(e=>e.getType()===`NORMAL`||e.getType()===`LONG_EDGE`),s=i.filter(a);if(s.length===0)return;let c=1/0,l=1/0,u=-1/0,d=-1/0,f=1/0,m=1/0;for(let e of s){let t=e.getMargin();if(c=Math.min(c,e.position.x-t.left),l=Math.min(l,e.position.y-t.top),u=Math.max(u,e.position.x+e.size.x+t.right),d=Math.max(d,e.position.y+e.size.y+t.bottom),e.getType()===`EXTERNAL_PORT`){let n=e.position.x;if(n<0||n>r.getSize().x){m=Math.min(m,e.position.y-t.top);continue}}f=Math.min(f,e.position.x-t.left),m=Math.min(m,e.position.y-t.top)}let h=r.getPadding(),g=t.size.x,_=t.size.y,v=r.getSize().x+h.left+h.right,y=r.getSize().y+h.top+h.bottom,b=r.getProperty(e.Et);b&&(v=Math.max(v,b.x),y=Math.max(y,b.y)),Pf&&r.getProperty(e.Vn)?.length>0&&(v=r.getSize().x+h.left+h.right,y=r.getSize().y+h.top+h.bottom,b&&(v=Math.max(v,b.x),y=Math.max(y,b.y)));{let e=r.getSize().x+h.left+h.right,n=r.getSize().y+h.top+h.bottom,i=t.getProperty(`org.eclipse.elk.contentAlignment`)??[];if(v>e||y>n){let t=r.getOffset();v>e&&(i.includes(`H_CENTER`)?t.x+=(v-e)/2:i.includes(`H_RIGHT`)&&(t.x+=v-e)),y>n&&(i.includes(`V_CENTER`)?t.y+=(y-n)/2:i.includes(`V_BOTTOM`)&&(t.y+=y-n))}}f=-r.getOffset().x,m=-r.getOffset().y;let x=h.left-f,S=h.top-m;if(n&&(x!==0||S!==0)){for(let e of i)e.getType()===`NORMAL`&&(e.position.x+=x,e.position.y+=S);let e=/* @__PURE__ */ new Set;for(let t of i)for(let n of t.getPorts())for(let t of n.getConnectedEdges())if(!e.has(t)){e.add(t);for(let e of t.getBendPoints())e.x+=x,e.y+=S;for(let e of t.getLabels())e.position.x+=x,e.position.y+=S}}if(r.getProperty(e.Gn).has(`EXTERNAL_PORTS`)){t.setProperty(e.Lt,`FIXED_POS`),t.getGraph().getProperty(e.Gn).add(`NON_FREE_PORTS`);for(let t of r.getAllNodes()){let n=t.getProperty(e.lr);if(n instanceof p){let i=n,a=gf(r,t,i.getSize().x,i.getSize().y);i.getPosition().x=a.x,i.getPosition().y=a.y,i.setSide(t.getProperty(e.Un))}}if(n&&S!==0&&i.some(e=>e.getType()===`NORMAL`))for(let t of r.getAllNodes()){if(t.getType()!==`EXTERNAL_PORT`)continue;let n=t.getProperty(e.Un);if(n===`WEST`||n===`EAST`){t.position.y+=S;for(let e of t.getPorts())for(let t of e.getLabels())t.position.y-=S}}t.size.x=v,t.size.y=y,r.getSize().x=v,r.getSize().y=y}else{if(g>0&&_>0){let e=v/g,n=y/_,r=v-g,i=y-_;for(let a of t.getPorts())switch(a.getSide()){case`NORTH`:a.getPosition().x*=e;break;case`EAST`:a.getPosition().x+=r,a.getPosition().y*=n;break;case`SOUTH`:a.getPosition().x*=e,a.getPosition().y+=i;break;case`WEST`:a.getPosition().y*=n}}t.size.x=v,t.size.y=y,r.getSize().x=v,r.getSize().y=y}}function vf(t,n,r){let i=t.getProperty(e.F)===`UNDEFINED`?`RIGHT`:t.getProperty(e.F);for(let n of t.getAllNodes()){let t=n.getProperty(e.Lt);if(e.Lr.isSideFixed(t))for(let e of n.getPorts())Ki(e,t,i)}let a=t.getProperty(e.Gn),o=t.getProperty(e.F),s=o===`UNDEFINED`?`RIGHT`:o;for(let n of t.getLayerlessNodes()){let r=n.getProperty(e.Lt);r!==`FREE`&&r!==`UNDEFINED`&&a.add(`NON_FREE_PORTS`),n.getProperty(e.Z)&&(a.add(`HYPERNODES`),a.add(`HYPEREDGES`),n.setProperty(e.Lt,`FREE`)),Jd(t);for(let e of n.getPorts()){let t=e.getSide();(s===`RIGHT`||s===`LEFT`?t===`NORTH`||t===`SOUTH`:t===`EAST`||t===`WEST`)&&a.add(`NORTH_SOUTH_PORTS`),e.getIncomingEdges().length+e.getOutgoingEdges().length>1&&a.add(`HYPEREDGES`);for(let t of e.getOutgoingEdges()){t.getTarget()!==null&&t.getTarget().getNode()===n&&a.add(`SELF_LOOPS`);for(let e of t.getLabels())e.placement===`HEAD`||e.placement===`TAIL`?a.add(`END_LABELS`):a.add(`CENTER_LABELS`)}}}Q(`GraphTransformer(in)`,r,t,()=>new qu(`TO_INPUT_DIRECTION`).process(t));for(let n of t.getAllNodes())n.hasProperty(e.mr)||n.setProperty(e.mr,n.getProperty(e.Lt));(t.getProperty(e.bt)===null||t.getProperty(e.bt)===void 0)&&t.setProperty(e.bt,t.getProperty(e.B)===`ORTHOGONAL`),t.getProperty(e.Gn).has(`COMMENTS`)&&Q(`CommentPreprocessor`,r,t,()=>Cu(t)),t.getProperty(e.lt)!==`INTERACTIVE`&&Q(`EdgeAndLayerConstraintEdgeReverser`,r,t,()=>new S().process(t));let c=t.getProperty(e.Gn).has(`SELF_LOOPS`);c&&Q(`SelfLoopPreprocessor`,r,t,()=>tl(t)),t.getProperty(e.Gn).has(`PARTITIONS`)&&Q(`PartitionPreprocessor`,r,t,()=>Ud(t)),(t.getProperty(e.P)===`INTERACTIVE`||t.getProperty(e.lt)===`INTERACTIVE`)&&Q(`InteractiveExternalPortPositioner`,r,t,()=>$s(t));let l=t.getProperty(e.P);l===`MODEL_ORDER`?Q(`ModelOrderCycleBreaker`,r,t,()=>b(t,n)):l===`GREEDY_MODEL_ORDER`?Q(`GreedyModelOrderCycleBreaker`,r,t,()=>new x().process(t,n)):l===`DEPTH_FIRST`?Q(`DepthFirstCycleBreaker`,r,t,()=>new Po().process(t,n)):l===`SCC_CONNECTIVITY`?Q(`SCConnectivity`,r,t,()=>new zo().process(t,n)):l===`SCC_NODE_TYPE`?Q(`SCCNodeTypeCycleBreaker`,r,t,()=>new Ho().process(t,n)):l===`DFS_NODE_ORDER`?Q(`DFSNodeOrderCycleBreaker`,r,t,()=>new Io().process(t,n)):l===`BFS_NODE_ORDER`?Q(`BFSNodeOrderCycleBreaker`,r,t,()=>new Fo().process(t,n)):l===`INTERACTIVE`?Q(`InteractiveCycleBreaker`,r,t,()=>_(t)):Q(`GreedyCycleBreaker`,r,t,()=>new h().process(t,n)),r?.afterPhase?.(`P1`,t),Q(`LabelDummyInserter`,r,t,()=>me(t)),Q(`LayerConstraintPreprocessor`,r,t,()=>new Do().process(t)),t.getProperty(e.Gn).has(`PARTITIONS`)&&Q(`PartitionMidprocessor`,r,t,()=>Gd(t));let u=t.getProperty(e.lt);u===`INTERACTIVE`?Q(`InteractiveLayerer`,r,t,()=>Mo(t,n)):u===`LONGEST_PATH_SOURCE`?Q(`LongestPathSourceLayerer`,r,t,()=>new se().process(t,n)):u===`LONGEST_PATH`||u===`LONGEST_PATH_SINK`?Q(`LongestPathLayerer`,r,t,()=>new oe().process(t,n)):u===`COFFMAN_GRAHAM`?Q(`CoffmanGrahamLayerer`,r,t,()=>new Wo().process(t,n)):u===`BF_MODEL_ORDER`?Q(`BreadthFirstModelOrderLayerer`,r,t,()=>new Go().process(t,n)):u===`DF_MODEL_ORDER`?Q(`DepthFirstModelOrderLayerer`,r,t,()=>new Ko().process(t,n)):u===`MIN_WIDTH`?Q(`MinWidthLayerer`,r,t,()=>new qo().process(t,n)):u===`STRETCH_WIDTH`?Q(`StretchWidthLayerer`,r,t,()=>new Jo().process(t,n)):Q(`NetworkSimplexLayerer`,r,t,()=>new ae().process(t,n)),r?.afterPhase?.(`P2`,t),t.getProperty(e.Y)&&Q(`HighDegreeNodeLayeringProcessor`,r,t,()=>Yd(t)),t.getProperty(e.ct)!==`NONE`&&Q(`NodePromotion`,r,t,()=>new qe().process(t,n)),Q(`LayerConstraintPostprocessor`,r,t,()=>Oo(t)),t.getProperty(e.Gn).has(`PARTITIONS`)&&Q(`PartitionPostprocessor`,r,t,()=>qd(t)),Pf&&t.getProperty(e.Gn).has(`EXTERNAL_PORTS`)&&Q(`HierarchicalPortConstraintProcessor`,r,t,()=>new cl().process(t)),t.getProperty(e.wn)===`MULTI_EDGE`&&Q(`BreakingPointInserter`,r,t,()=>fc(t)),Q(`LongEdgeSplitter`,r,t,()=>ce(t)),Q(`PortSideProcessor`,r,t,()=>qi(t));let d=t.getProperty(e.B);(d===`POLYLINE`||d===`SPLINES`||d===`ORTHOGONAL`&&(t.getProperty(e.Gn).has(`NON_FREE_PORTS`)||t.getProperty(e.G)||t.getProperty(e.Gn).has(`HYPEREDGES`)))&&Q(`InvertedPortProcessor`,r,t,()=>xu(t)),c&&Q(`DummySelfLoopProcessor`,r,t,()=>pu(t)),t.getProperty(e.O)!==`NONE`&&Q(`SortByInputModel`,r,t,()=>Rd(t)),Q(`PortListSorter`,r,t,()=>Bc(t)),t.getProperty(e.Gn).has(`EXTERNAL_PORTS`)&&!Pf&&Q(`HierarchicalPortConstraintProcessor`,r,t,()=>new cl().process(t)),t.getProperty(e.M)&&Q(`SemiInteractiveCrossMinProcessor`,r,t,()=>Hd(t)),t.getProperty(e.Gn).has(`NON_FREE_PORTS`)&&t.getProperty(e.Gn).has(`NORTH_SOUTH_PORTS`)&&Q(`NorthSouthPortPreprocessor`,r,t,()=>Gc(t))}function yf(t,n,r,i=!1){let a=t.getProperty(e.Gn).has(`SELF_LOOPS`);t.setProperty(e.wr,new un(t)),a&&Q(`SelfLoopPortRestorer`,r,t,()=>new Rl().process(t)),Q(`InLayerConstraintProcessor`,r,t,()=>Ol(t)),Q(`LabelAndNodeSizeProcessor`,r,t,()=>Ks(t)),Q(`NodeMarginCalculator`,r,t,()=>na(t)),t.getProperty(e.Gn).has(`COMMENTS`)&&Q(`CommentNodeMarginCalculator`,r,t,()=>Eu(t)),t.getProperty(e.Gn).has(`END_LABELS`)&&Q(`EndLabelPreprocessor`,r,t,()=>Xu(t)),t.getProperty(e.Gn).has(`CENTER_LABELS`)&&Q(`LabelDummySwitcher`,r,t,()=>be(t)),(t.getProperty(e.Gn).has(`END_LABELS`)||t.getProperty(e.Gn).has(`CENTER_LABELS`))&&Q(`LabelSideSelector`,r,t,()=>ud(t)),t.getProperty(e.Gn).has(`HYPEREDGES`)&&t.getProperty(e.B)!==`SPLINES`&&Q(`HyperedgeDummyMerger`,r,t,()=>new C().process(t)),Q(`HierarchicalPortDummySizeProcessor`,r,t,()=>al(t)),a&&Q(`SelfLoopRouter`,r,t,()=>du(t)),t.getProperty(e.wn)===`MULTI_EDGE`&&Q(`BreakingPointProcessor`,r,t,()=>yc(t));let o=t.getProperty(e.wt);o===`SIMPLE`?Q(`SimpleNodePlacer`,r,t,()=>on(t)):o===`INTERACTIVE`?Q(`InteractiveNodePlacer`,r,t,()=>sn(t)):o===`NETWORK_SIMPLEX`?Q(`NetworkSimplexPlacer`,r,t,()=>new bn().process(t)):o===`LINEAR_SEGMENTS`?Q(`LinearSegmentsNodePlacer`,r,t,()=>Zo(t)):(o!==`BRANDES_KOEPF`&&Mf(`nodePlacement.strategy`,String(o),`BRANDES_KOEPF`),Q(`BKNodePlacer`,r,t,()=>new an().process(t))),r?.afterPhase?.(`BK`,t),t.getLayerlessNodes().length>0&&t.hasProperty(e.Ct)&&Q(`NodePlacementRepeater`,r,t,()=>Zs(t)),Q(`LayerSizeAndGraphHeightCalculator`,r,t,()=>new xn().process(t)),t.getProperty(e.Gn).has(`EXTERNAL_PORTS`)&&Q(`HierarchicalPortPositionProcessor`,r,t,()=>ll(t));let s=t.getProperty(e.B);if(s===`POLYLINE`?Q(`PolylineEdgeRouter`,r,t,()=>new Fr().process(t)):s===`SPLINES`?Q(`SplineEdgeRouter`,r,t,()=>new gi().process(t)):(s!==`ORTHOGONAL`&&s!=null&&Mf(`edgeRouting`,String(s),`ORTHOGONAL`),Q(`OrthogonalEdgeRouter`,r,t,()=>new rr().process(t))),r?.afterPhase?.(`P5`,t),(t.getProperty(e.et)||t.getProperty(e.K))&&Q(`ConstraintsPostprocessor`,r,t,()=>ss(t)),t.getProperty(e.Gn).has(`HYPERNODES`)&&Q(`HypernodesProcessor`,r,t,()=>cs(t)),Q(`LongEdgeJoiner`,r,t,()=>He(t)),a&&Q(`SelfLoopPostprocessor`,r,t,()=>kl(t)),t.getProperty(e.wn)===`MULTI_EDGE`&&Q(`BreakingPointRemover`,r,t,()=>Oc(t)),t.getProperty(e.Gn).has(`NON_FREE_PORTS`)&&t.getProperty(e.Gn).has(`NORTH_SOUTH_PORTS`)&&Q(`NorthSouthPortPostprocessor`,r,t,()=>_u(t)),t.getProperty(e.v)!==`NONE`&&t.getProperty(e.B)!==`POLYLINE`&&Q(`HorizontalGraphCompactor`,r,t,()=>new Mr().process(t)),Q(`LabelDummyRemover`,r,t,()=>We(t)),s===`SPLINES`&&Q(`FinalSplineBendpointsCalculator`,r,t,()=>bi(t)),t.getProperty(e.Gn).has(`COMMENTS`)&&Q(`CommentPostprocessor`,r,t,()=>ku(t)),Q(`EndLabelSorter`,r,t,()=>wd(t)),Q(`ReversedEdgeRestorer`,r,t,()=>jc(t)),t.getProperty(e.Gn).has(`EXTERNAL_PORTS`)&&Q(`HierarchicalPortOrthogonalEdgeRouter`,r,t,()=>dl(t)),t.getProperty(e.Gn).has(`END_LABELS`)&&Q(`EndLabelPostprocessor`,r,t,()=>Md(t)),!i){Q(`GraphTransformer(out)`,r,t,()=>new qu(`TO_INTERNAL_LTR`).process(t));for(let n of t.getLayers())for(let r of n.getNodes())ra(r),t.getProperty(e.Gn).has(`COMMENTS`)&&Du(r)}}function bf(t){let n=t.getParentNode();if(n===null)return;let r=t.getProperty(e.F);if(r!==`DOWN`&&r!==`UP`)return;let i=n.getGraph()?.getProperty(e.F);if(i!==`RIGHT`&&i!==`UNDEFINED`)return;let a=n.size.x;n.size.x=n.size.y,n.size.y=a;let o=n.getPadding(),s=o.left;o.left=o.top,o.top=s;let c=o.right;o.right=o.bottom,o.bottom=c}function xf(t){let n=t.getParentNode();return n!==null&&n.getProperty(e.q)===`SEPARATE_CHILDREN`}function Sf(t,n,r){let a=hf(t);Df(t,a);for(let t of a)if(t.getProperty(e.br)===void 0){let n=t.getProperty(e.Kt);t.setProperty(e.br,n===0?new i:new i(n))}for(let e of a)If(e)||vf(e,n,r);let o=a[a.length-1],s=o.getProperty(e.N);s===`INTERACTIVE`?(Q(`InteractiveCrossingMinimizer`,r,o,()=>new Wt().process(o)),r?.afterPhase?.(`P3`,o)):s===`MEDIAN_LAYER_SWEEP`?(Q(`LayerSweepCrossingMinimizer`,r,o,()=>new Ut(3).process(o,n)),r?.afterPhase?.(`P3`,o)):(Q(`LayerSweepCrossingMinimizer`,r,o,()=>new Ut(0).process(o,n)),r?.afterPhase?.(`P3`,o));let c=/* @__PURE__ */ new Set;for(let e of a){if(If(e))continue;yf(e,n,r,!0);let t=e.getParentNode();if(t!==null&&_f(t,!0),xf(e)){Q(`GraphTransformer(out)`,r,e,()=>new qu(`TO_INTERNAL_LTR`).process(e)),bf(e);for(let t of e.getLayers())for(let e of t.getNodes())ra(e);c.add(e)}}for(let e of a)if(!c.has(e)){Q(`GraphTransformer(out)`,r,e,()=>new qu(`TO_INTERNAL_LTR`).process(e)),bf(e);for(let t of e.getLayers())for(let e of t.getNodes())ra(e)}let l=t.getOffset(),u=t.getPadding();for(let e of t.getAllNodes())e.position.x+=l.x+u.left,e.position.y+=l.y+u.top;let d=l.x+u.left,f=l.y+u.top;if(d!==0||f!==0){let e=/* @__PURE__ */ new Set;for(let n of t.getAllNodes())for(let t of n.getPorts())for(let n of t.getConnectedEdges())if(!e.has(n)){e.add(n);for(let e of n.getBendPoints())e.x+=d,e.y+=f}}r?.afterPhase?.(`done`,t)}function Cf(t){let n=t.getProperty(e.F);for(let r of t.getLayerlessNodes()){let t=r.getNestedGraph();if(t!==null){if(t.getProperty(e.F)===`UNDEFINED`){let i=r.getProperty(`org.eclipse.elk.hierarchyHandling`),a=r.getProperty(`org.eclipse.elk.direction`);i===`SEPARATE_CHILDREN`&&a!==void 0&&a!==`UNDEFINED`?t.setProperty(e.F,a):n!==`UNDEFINED`&&t.setProperty(e.F,n)}Cf(t)}}}function wf(t){for(let n of t.getLayerlessNodes()){let t=n.getNestedGraph();if(t!==null){if(t.getProperty(e.Lt)===`UNDEFINED`){let r=n.getProperty(e.Lt);r!==`UNDEFINED`&&t.setProperty(e.Lt,r)}wf(t)}}}const Tf=[e.N,e.P,e.lt,e.M,e.et,e.Vt,e.B,e.I,e.Kt,e.A,e.k,e._t,e.ln,e.un,e.$t,e.en,e.nn,e.rn,e.pn,e.fn,e.zt];function Ef(e){for(let t of e.getLayerlessNodes()){let e=t.getNestedGraph();if(e!==null){for(let n of Tf)t.hasProperty(n)&&e.setProperty(n,t.getProperty(n));Ef(e)}}}function Df(t,n){let r=t.getProperty(e.N);for(let i of n){if(i===t)continue;let n=i.getProperty(e.N);if(n!==r){let e=i.getParentNode()?.id??`G-unlayered`;throw Error(`UnsupportedGraphException: The hierarchy aware processor `+n+` in child node `+e+` is only allowed if the root node specifies the same hierarchical processor.`)}}}function Of(t){let n=[t];for(;n.length>0;){let t=n.pop(),r=t.getProperty(e.F)===`UNDEFINED`?`RIGHT`:t.getProperty(e.F);for(let n of t.getAllNodes()){let t=n.getProperty(e.Lt);if(e.Lr.isSideFixed(t))for(let e of n.getPorts())Ki(e,t,r)}for(let e of t.getLayerlessNodes()){let t=e.getNestedGraph();t!==null&&n.push(t)}}}function kf(t,n,r){if(Cf(t),Ef(t),Pf&&wf(t),Of(t),Q(`CompoundGraphPreprocessor`,r,t,()=>new ca().process(t)),t.getProperty(e.q)===`INCLUDE_CHILDREN`){Sf(t,n,r),Q(`CompoundGraphPostprocessor`,r,t,()=>Co(t));return}let i=hf(t);for(let t of i)if(!If(t)&&(t.getLayers().length===0||t.getLayerlessNodes().length>0)){Af(t,n,r);let i=t.getParentNode();if(i!==null&&t.getProperty(e.Gn).has(`EXTERNAL_PORTS`)&&t.getSize().x===0&&t.getAllNodes().some(e=>e.getType()===`EXTERNAL_PORT`)){let n=[],r=/* @__PURE__ */ new Set;for(let e of t.getAllNodes())r.has(e)||(r.add(e),n.push(e));let a=/* @__PURE__ */ new Set,o=e=>{let t=[e];for(;t.length>0;){let e=t.pop();if(!a.has(e)){a.add(e);for(let n of e.getPorts())for(let e of n.getConnectedPorts()){let n=e.getNode();n!==null&&!a.has(n)&&t.push(n)}}}},s=0;for(let e of n)a.has(e)||(o(e),s++);let c=/* @__PURE__ */ new Set;for(let t of n){let n=t.getProperty(e.lr);n instanceof p&&c.add(n)}for(let e of i.getPorts())c.has(e)||s++;t.getSize().x=s>1?t.getProperty(e.Qt):-t.getProperty(e.Qt)}i!==null&&Pf&&t.getProperty(e.Gn).has(`EXTERNAL_PORTS`)&&dl(t),i!==null&&(_f(i,!1),bf(t))}Q(`CompoundGraphPostprocessor`,r,t,()=>Co(t))}function Q(e,t,n,r){t?.beforeModule?.(e,n),r(),t?.afterModule?.(e,n)}function Af(t,n,r){if(t.getProperty(e.br)===void 0){let n=t.getProperty(e.Kt);t.setProperty(e.br,n===0?new i:new i(n))}let a=t.getProperty(e.M)||t.getProperty(e.N)===`INTERACTIVE`,o=t.getProperty(e.A),s=t.getProperty(e.k),c=t.getLayerlessNodes().length,l=!a&&o!==`OFF`&&(s===0||s>c);t.setProperty(e.Kn,l);let u=new yo().split(t);if(u.length===1)Nf(t,n,r);else{for(let e of u){Nf(e,n,r,!1);for(let t of e.getLayers()){for(let n of[...t.getNodes()])e.getLayerlessNodes().includes(n)||e.getLayerlessNodes().push(n),n.setLayer(null);t.getNodes().length=0}e.getLayers().length=0,xo(e)}new yo().combine(u,t),r?.afterPhase?.(`combine`,t);let e=t.getOffset(),i=t.getPadding(),a=e.x+i.left,o=e.y+i.top,s=/* @__PURE__ */ new Set;for(let e of t.getLayerlessNodes()){e.position.x+=a,e.position.y+=o;for(let t of e.getPorts())for(let e of t.getConnectedEdges())if(!s.has(e)){s.add(e);for(let t of e.getBendPoints())t.x+=a,t.y+=o}}}}const jf=/* @__PURE__ */ new Set;function Mf(e,t,n){let r=`${e}=${t}`;jf.has(r)||(jf.add(r),console.warn(`[ggn] 未实现策略 ${e}=${t},降级为 ${n}(与 ELK 不一致,待移植/显式降级)`))}function Nf(t,n,r,i=!0){let a=t.getProperty(e.F)===`UNDEFINED`?`RIGHT`:t.getProperty(e.F);for(let n of t.getAllNodes()){let t=n.getProperty(e.Lt);if(e.Lr.isSideFixed(t))for(let e of n.getPorts())Ki(e,t,a)}let o=t.getProperty(e.Gn),s=t.getProperty(e.F),c=s===`UNDEFINED`?`RIGHT`:s;for(let n of t.getLayerlessNodes()){let r=n.getProperty(e.Lt);r!==`FREE`&&r!==`UNDEFINED`&&o.add(`NON_FREE_PORTS`),n.getProperty(e.Z)&&(o.add(`HYPERNODES`),o.add(`HYPEREDGES`),n.setProperty(e.Lt,`FREE`)),Jd(t);for(let e of n.getPorts()){let t=e.getSide();(c===`RIGHT`||c===`LEFT`?t===`NORTH`||t===`SOUTH`:t===`EAST`||t===`WEST`)&&o.add(`NORTH_SOUTH_PORTS`),e.getIncomingEdges().length+e.getOutgoingEdges().length>1&&o.add(`HYPEREDGES`);for(let t of e.getOutgoingEdges()){t.getTarget()!==null&&t.getTarget().getNode()===n&&o.add(`SELF_LOOPS`);for(let e of t.getLabels())e.placement===`HEAD`||e.placement===`TAIL`?o.add(`END_LABELS`):o.add(`CENTER_LABELS`)}}}Q(`GraphTransformer(in)`,r,t,()=>new qu(`TO_INPUT_DIRECTION`).process(t));for(let n of t.getAllNodes())n.hasProperty(e.mr)||n.setProperty(e.mr,n.getProperty(e.Lt));(t.getProperty(e.bt)===null||t.getProperty(e.bt)===void 0)&&t.setProperty(e.bt,t.getProperty(e.B)===`ORTHOGONAL`),t.getProperty(e.Gn).has(`COMMENTS`)&&Q(`CommentPreprocessor`,r,t,()=>Cu(t)),t.getProperty(e.lt)!==`INTERACTIVE`&&Q(`EdgeAndLayerConstraintEdgeReverser`,r,t,()=>new S().process(t));let l=t.getProperty(e.Gn).has(`SELF_LOOPS`);l&&Q(`SelfLoopPreprocessor`,r,t,()=>tl(t)),t.getProperty(e.Gn).has(`PARTITIONS`)&&Q(`PartitionPreprocessor`,r,t,()=>Ud(t)),(t.getProperty(e.P)===`INTERACTIVE`||t.getProperty(e.lt)===`INTERACTIVE`)&&Q(`InteractiveExternalPortPositioner`,r,t,()=>$s(t));let u=t.getProperty(e.P);u===`MODEL_ORDER`?Q(`ModelOrderCycleBreaker`,r,t,()=>b(t,n)):u===`GREEDY_MODEL_ORDER`?Q(`GreedyModelOrderCycleBreaker`,r,t,()=>new x().process(t,n)):u===`DEPTH_FIRST`?Q(`DepthFirstCycleBreaker`,r,t,()=>new Po().process(t,n)):u===`SCC_CONNECTIVITY`?Q(`SCConnectivity`,r,t,()=>new zo().process(t,n)):u===`SCC_NODE_TYPE`?Q(`SCCNodeTypeCycleBreaker`,r,t,()=>new Ho().process(t,n)):u===`DFS_NODE_ORDER`?Q(`DFSNodeOrderCycleBreaker`,r,t,()=>new Io().process(t,n)):u===`BFS_NODE_ORDER`?Q(`BFSNodeOrderCycleBreaker`,r,t,()=>new Fo().process(t,n)):u===`INTERACTIVE`?Q(`InteractiveCycleBreaker`,r,t,()=>_(t)):Q(`GreedyCycleBreaker`,r,t,()=>new h().process(t,n)),r?.afterPhase?.(`P1`,t),Q(`LabelDummyInserter`,r,t,()=>me(t)),Q(`LayerConstraintPreprocessor`,r,t,()=>new Do().process(t)),t.getProperty(e.Gn).has(`PARTITIONS`)&&Q(`PartitionMidprocessor`,r,t,()=>Gd(t));let d=t.getProperty(e.lt);d===`INTERACTIVE`?Q(`InteractiveLayerer`,r,t,()=>Mo(t,n)):d===`LONGEST_PATH_SOURCE`?Q(`LongestPathSourceLayerer`,r,t,()=>new se().process(t,n)):d===`LONGEST_PATH`||d===`LONGEST_PATH_SINK`?Q(`LongestPathLayerer`,r,t,()=>new oe().process(t,n)):d===`COFFMAN_GRAHAM`?Q(`CoffmanGrahamLayerer`,r,t,()=>new Wo().process(t,n)):d===`BF_MODEL_ORDER`?Q(`BreadthFirstModelOrderLayerer`,r,t,()=>new Go().process(t,n)):d===`DF_MODEL_ORDER`?Q(`DepthFirstModelOrderLayerer`,r,t,()=>new Ko().process(t,n)):d===`MIN_WIDTH`?Q(`MinWidthLayerer`,r,t,()=>new qo().process(t,n)):d===`STRETCH_WIDTH`?Q(`StretchWidthLayerer`,r,t,()=>new Jo().process(t,n)):Q(`NetworkSimplexLayerer`,r,t,()=>new ae().process(t,n)),r?.afterPhase?.(`P2`,t),t.getProperty(e.Y)&&Q(`HighDegreeNodeLayeringProcessor`,r,t,()=>Yd(t)),t.getProperty(e.ct)!==`NONE`&&Q(`NodePromotion`,r,t,()=>new qe().process(t,n)),Q(`LayerConstraintPostprocessor`,r,t,()=>Oo(t)),t.getProperty(e.Gn).has(`PARTITIONS`)&&Q(`PartitionPostprocessor`,r,t,()=>qd(t)),t.getProperty(e.wn)===`MULTI_EDGE`&&Q(`BreakingPointInserter`,r,t,()=>fc(t)),Q(`LongEdgeSplitter`,r,t,()=>ce(t)),Q(`PortSideProcessor`,r,t,()=>qi(t));let f=t.getProperty(e.B);(f===`POLYLINE`||f===`SPLINES`||f===`ORTHOGONAL`&&(t.getProperty(e.Gn).has(`NON_FREE_PORTS`)||t.getProperty(e.G)||t.getProperty(e.Gn).has(`HYPEREDGES`)))&&Q(`InvertedPortProcessor`,r,t,()=>xu(t)),l&&Q(`DummySelfLoopProcessor`,r,t,()=>pu(t)),Q(`PortListSorter`,r,t,()=>Bc(t)),t.getProperty(e.Gn).has(`EXTERNAL_PORTS`)&&Q(`HierarchicalPortConstraintProcessor`,r,t,()=>new cl().process(t)),t.getProperty(e.M)&&Q(`SemiInteractiveCrossMinProcessor`,r,t,()=>Hd(t)),t.getProperty(e.O)!==`NONE`&&Q(`SortByInputModel`,r,t,()=>Rd(t)),t.getProperty(e.Gn).has(`NON_FREE_PORTS`)&&t.getProperty(e.Gn).has(`NORTH_SOUTH_PORTS`)&&Q(`NorthSouthPortPreprocessor`,r,t,()=>Gc(t));let p=t.getProperty(e.N),m=t.getProperty(e.Kn);p===`INTERACTIVE`?(Q(`InteractiveCrossingMinimizer`,r,t,()=>new Wt().process(t)),r?.afterPhase?.(`P3`,t)):p===`MEDIAN_LAYER_SWEEP`?(Q(`LayerSweepCrossingMinimizer`,r,t,()=>new Ut(3).process(t,n)),r?.afterPhase?.(`P3`,t)):p!==`NONE`&&(Q(`LayerSweepCrossingMinimizer`,r,t,()=>new Ut(0).process(t,n)),r?.afterPhase?.(`P3`,t)),t.getProperty(e.wn)===`MULTI_EDGE`&&Q(`BreakingPointProcessor`,r,t,()=>yc(t)),m&&(Q(`GreedySwitchHeuristic`,r,t,()=>new Ut(2).process(t,n)),r?.afterPhase?.(`GreedySwitch`,t)),t.setProperty(e.wr,new un(t)),l&&Q(`SelfLoopPortRestorer`,r,t,()=>new Rl().process(t)),Q(`InLayerConstraintProcessor`,r,t,()=>Ol(t)),Q(`LabelAndNodeSizeProcessor`,r,t,()=>Ks(t)),Q(`NodeMarginCalculator`,r,t,()=>na(t)),t.getProperty(e.Gn).has(`COMMENTS`)&&Q(`CommentNodeMarginCalculator`,r,t,()=>Eu(t)),t.getProperty(e.Gn).has(`END_LABELS`)&&Q(`EndLabelPreprocessor`,r,t,()=>Xu(t)),t.getProperty(e.Gn).has(`CENTER_LABELS`)&&Q(`LabelDummySwitcher`,r,t,()=>be(t)),(t.getProperty(e.Gn).has(`END_LABELS`)||t.getProperty(e.Gn).has(`CENTER_LABELS`))&&Q(`LabelSideSelector`,r,t,()=>ud(t)),t.getProperty(e.Gn).has(`HYPEREDGES`)&&t.getProperty(e.B)!==`SPLINES`&&Q(`HyperedgeDummyMerger`,r,t,()=>new C().process(t)),Q(`HierarchicalPortDummySizeProcessor`,r,t,()=>al(t)),l&&Q(`SelfLoopRouter`,r,t,()=>du(t)),t.getProperty(e.pt)===`ALTERNATING`&&Q(`AlternatingLayerUnzipper`,r,t,()=>nf(t));let g=t.getProperty(e.wt);g===`SIMPLE`?Q(`SimpleNodePlacer`,r,t,()=>on(t)):g===`INTERACTIVE`?Q(`InteractiveNodePlacer`,r,t,()=>sn(t)):g===`NETWORK_SIMPLEX`?Q(`NetworkSimplexPlacer`,r,t,()=>new bn().process(t)):g===`LINEAR_SEGMENTS`?Q(`LinearSegmentsNodePlacer`,r,t,()=>Zo(t)):(g!==`BRANDES_KOEPF`&&Mf(`nodePlacement.strategy`,String(g),`BRANDES_KOEPF`),Q(`BKNodePlacer`,r,t,()=>new an().process(t))),r?.afterPhase?.(`BK`,t),t.getLayerlessNodes().length>0&&t.hasProperty(e.Ct)&&Q(`NodePlacementRepeater`,r,t,()=>Zs(t)),Q(`LayerSizeAndGraphHeightCalculator`,r,t,()=>new xn().process(t)),t.getProperty(e.Gn).has(`EXTERNAL_PORTS`)&&Q(`HierarchicalPortPositionProcessor`,r,t,()=>ll(t));let v=t.getProperty(e.B);v===`POLYLINE`?Q(`PolylineEdgeRouter`,r,t,()=>new Fr().process(t)):v===`SPLINES`?Q(`SplineEdgeRouter`,r,t,()=>new gi().process(t)):(v!==`ORTHOGONAL`&&v!=null&&Mf(`edgeRouting`,String(v),`ORTHOGONAL`),Q(`OrthogonalEdgeRouter`,r,t,()=>new rr().process(t))),r?.afterPhase?.(`P5`,t),(t.getProperty(e.et)||t.getProperty(e.K))&&Q(`ConstraintsPostprocessor`,r,t,()=>ss(t)),t.getProperty(e.Gn).has(`HYPERNODES`)&&Q(`HypernodesProcessor`,r,t,()=>cs(t)),Q(`LongEdgeJoiner`,r,t,()=>He(t)),l&&Q(`SelfLoopPostprocessor`,r,t,()=>kl(t)),t.getProperty(e.wn)===`MULTI_EDGE`&&Q(`BreakingPointRemover`,r,t,()=>Oc(t)),t.getProperty(e.Gn).has(`NON_FREE_PORTS`)&&t.getProperty(e.Gn).has(`NORTH_SOUTH_PORTS`)&&Q(`NorthSouthPortPostprocessor`,r,t,()=>_u(t)),t.getProperty(e.v)!==`NONE`&&t.getProperty(e.B)!==`POLYLINE`&&Q(`HorizontalGraphCompactor`,r,t,()=>new Mr().process(t)),Q(`LabelDummyRemover`,r,t,()=>We(t)),v===`SPLINES`&&Q(`FinalSplineBendpointsCalculator`,r,t,()=>bi(t)),t.getProperty(e.Gn).has(`COMMENTS`)&&Q(`CommentPostprocessor`,r,t,()=>ku(t)),Q(`EndLabelSorter`,r,t,()=>wd(t)),Q(`ReversedEdgeRestorer`,r,t,()=>jc(t)),t.getProperty(e.Gn).has(`END_LABELS`)&&Q(`EndLabelPostprocessor`,r,t,()=>Md(t)),Q(`GraphTransformer(out)`,r,t,()=>new qu(`TO_INTERNAL_LTR`).process(t));let y=t.getProperty(e.F);if(y!==`RIGHT`&&y!==`UNDEFINED`)for(let n of t.getLayers())for(let r of n.getNodes())ra(r),t.getProperty(e.Gn).has(`COMMENTS`)&&Du(r);if(i){let e=t.getOffset(),n=t.getPadding(),r=e.x+n.left,i=e.y+n.top,a=/* @__PURE__ */ new Set;for(let e of t.getAllNodes())if(e.getType()!==`EXTERNAL_PORT`){e.position.x+=r,e.position.y+=i;for(let t of e.getPorts())for(let e of t.getConnectedEdges())if(!a.has(e)){a.add(e);for(let t of e.getBendPoints())t.x+=r,t.y+=i}}}r?.afterPhase?.(`done`,t)}const Pf=!0;function Ff(t){for(let n of hf(t))for(let t of n.getLayerlessNodes()){let r=t.getNestedGraph();if(r===null)continue;let i=t.getProperty(e.Tt);if(!i||i.length===0)continue;let a=t.getProperty(e.Lt);if(!e.Lr.isSideFixed(a)){let r=n.getProperty(e.F)===`UNDEFINED`?`RIGHT`:n.getProperty(e.F);for(let e of t.getPorts())e.getSide()===`UNDEFINED`&&Yi(e,!1,r)}let o=Ns(t,n,!0)??{x:t.size.x,y:t.size.y},s=r.getProperty(e.Et)??{x:0,y:0},c=t.getProperty(e.Et)??{x:0,y:0},l={x:Math.max(s.x,c.x),y:Math.max(s.y,c.y)};r.setProperty(e.Et,{x:Math.max(l.x,o.x),y:Math.max(l.y,o.y)});let u=r.getProperty(e.Tt);u.includes(`MINIMUM_SIZE`)||r.setProperty(e.Tt,[...u,`MINIMUM_SIZE`])}}function If(e){let t=e.getParentNode();return t!==null&&t.getProperty(`org.eclipse.elk.algorithm`)===`fixed`}function Lf(e){let t=/* @__PURE__ */ new Set,n=e=>{let r=e.getProperty(`org.eclipse.elk.algorithm`);if(r&&t.has(r))throw Error(`Layout algorithm '${r}' not found`);let i=e.getNestedGraph();if(i!==null)for(let e of i.getLayerlessNodes())n(e)};for(let t of e.getLayerlessNodes())n(t)}var Rf=class{hooks;setHooks(e){this.hooks=e}layout(t,n){let r=n??new mf;Lf(t),ff(t),pf(t),Cf(t),Of(t),Ff(t),Su(t)&&t.getProperty(e.Gn).add(`COMMENTS`),t.getLayerlessNodes().filter(e=>e.getNestedGraph()!==null).length>0?kf(t,r,this.hooks):Af(t,r,this.hooks),Bf(t),zf(t)}};function zf(t){for(let n of t.getAllNodes()){n.getNestedGraph()!==null&&zf(n.getNestedGraph());let t=n.hasProperty(e.Tt)?n.getProperty(e.Tt):n.getGraph()?.getProperty(e.Tt)??[];if(!t.includes(`NODE_LABELS`)||t.includes(`PORTS`)||t.includes(`PORT_LABELS`)||t.includes(`MINIMUM_SIZE`)||n.getNestedGraph()!==null)continue;let r=n.getLabels();if(r.length===0)continue;let i=0,a=0;for(let e of r)i=Math.max(i,e.size.x),a=Math.max(a,e.size.y);if(i>0||a>0||n.size.x===0&&n.size.y===0)continue;let o={x:n.size.x,y:n.size.y};n.size.x=0,n.size.y=0,n.position.x+=o.x/2,n.position.y+=o.y/2;for(let e of r)e.position.x=0,e.position.y=0}}function Bf(t){for(let n of t.getAllNodes()){n.getNestedGraph()!==null&&Bf(n.getNestedGraph());let t=n.hasProperty(e.gt)?n.getProperty(e.gt):n.getGraph()?.getProperty(e.gt)??{left:0,right:0,top:0,bottom:0},r=t.left??0,i=t.right??0,a=ta(n);for(let t of n.getLabels()){let o=t.placement??n.getProperty(e._t)??``,s=Array.isArray(o)?o:String(o).split(/[\s,]+/).filter(Boolean);if(s.includes(`OUTSIDE`)){let e=s.includes(`H_PRIORITY`),r=s.includes(`H_LEFT`)||s.includes(`H_RIGHT`);e&&r||!e&&s.includes(`V_CENTER`)&&r?(s.includes(`H_RIGHT`)?t.position.x=n.size.x+a:t.position.x=-t.size.x-a,s.includes(`V_BOTTOM`)?t.position.y=n.size.y-t.size.y:s.includes(`V_CENTER`)?t.position.y=(n.size.y-t.size.y)/2:t.position.y=0):(s.includes(`V_BOTTOM`)?t.position.y=n.size.y+a:t.position.y=-t.size.y-a,s.includes(`H_RIGHT`)?t.position.x=n.size.x-t.size.x:s.includes(`H_LEFT`)?t.position.x=0:t.position.x=(n.size.x-t.size.x)/2)}else s.includes(`H_LEFT`)?t.position.x=r:s.includes(`H_RIGHT`)?t.position.x=n.size.x-t.size.x-i:t.position.x=r+(n.size.x-r-i-t.size.x)/2}}}function Vf(e,t,n){switch(n){case`WEST`:e.x=0,e.y=t.y/2;break;case`EAST`:e.x=t.x,e.y=t.y/2;break;case`NORTH`:e.x=t.x/2,e.y=0;break;case`SOUTH`:e.x=t.x/2,e.y=t.y;break;default:e.x=t.x/2,e.y=t.y/2}}function Hf(t,n,r){let i=n===`INPUT`?e.Yn:e.hr;for(let e of t.getPorts())if(e.getProperty(i)===!0)return e;let a=new p;return a.setProperty(i,!0),a.setNode(t),a.setSide(r),Vf(a.getPosition(),t.getSize(),r),a}function Uf(e,t,n,r,i){if(r&&!i)return Hf(e,t,t===`OUTPUT`?n:Wf(n));let a=new p;return a.setNode(e),a.setSide(t===`OUTPUT`?n:Wf(n)),a}function Wf(e){switch(e){case`NORTH`:return`SOUTH`;case`SOUTH`:return`NORTH`;case`EAST`:return`WEST`;case`WEST`:return`EAST`;default:return`UNDEFINED`}}const Gf={direction:{ggn:`org.eclipse.elk.direction`,elkjs:`elk.direction`,type:`str`},position:{ggn:`org.eclipse.elk.position`,elkjs:`elk.position`,type:`str`},edgeRouting:{ggn:`org.eclipse.elk.edgeRouting`,elkjs:`elk.edgeRouting`,type:`str`},"spacing.nodeNode":{ggn:`org.eclipse.elk.spacing.nodeNode`,elkjs:`elk.spacing.nodeNode`,type:`num`},"spacing.edgeEdge":{ggn:`org.eclipse.elk.spacing.edgeEdge`,elkjs:`elk.spacing.edgeEdge`,type:`num`},"spacing.nodeSelfLoop":{ggn:`org.eclipse.elk.spacing.nodeSelfLoop`,elkjs:`elk.spacing.nodeSelfLoop`,type:`num`},"spacing.portPort":{ggn:`org.eclipse.elk.spacing.portPort`,elkjs:`elk.spacing.portPort`,type:`num`},"spacing.edgeNode":{ggn:`org.eclipse.elk.spacing.edgeNode`,elkjs:`elk.spacing.edgeNode`,type:`num`},"spacing.edgeLabel":{ggn:`org.eclipse.elk.spacing.edgeLabel`,elkjs:`elk.spacing.edgeLabel`,type:`num`},"spacing.labelLabel":{ggn:`org.eclipse.elk.spacing.labelLabel`,elkjs:`elk.spacing.labelLabel`,type:`num`},"spacing.labelNode":{ggn:`org.eclipse.elk.spacing.labelNode`,elkjs:`elk.spacing.labelNode`,type:`num`},"spacing.edgeEdgeBetweenLayers":{ggn:`org.eclipse.elk.layered.spacing.edgeEdgeBetweenLayers`,elkjs:`elk.layered.spacing.edgeEdgeBetweenLayers`,type:`num`},"spacing.nodeNodeBetweenLayers":{ggn:`org.eclipse.elk.layered.spacing.nodeNodeBetweenLayers`,elkjs:`elk.layered.spacing.nodeNodeBetweenLayers`,type:`num`},"spacing.edgeNodeBetweenLayers":{ggn:`org.eclipse.elk.layered.spacing.edgeNodeBetweenLayers`,elkjs:`elk.layered.spacing.edgeNodeBetweenLayers`,type:`num`},"crossingMinimization.strategy":{ggn:`org.eclipse.elk.layered.crossingMinimization.strategy`,elkjs:`elk.layered.crossingMinimization.strategy`,type:`str`},"crossingMinimization.greedySwitch.type":{ggn:`org.eclipse.elk.layered.crossingMinimization.greedySwitch.type`,elkjs:`elk.layered.crossingMinimization.greedySwitch.type`,type:`str`},"cycleBreaking.strategy":{ggn:`org.eclipse.elk.layered.cycleBreaking.strategy`,elkjs:`elk.layered.cycleBreaking.strategy`,type:`str`},"layering.strategy":{ggn:`org.eclipse.elk.layered.layering.strategy`,elkjs:`elk.layered.layering.strategy`,type:`str`},"nodePlacement.strategy":{ggn:`org.eclipse.elk.layered.nodePlacement.strategy`,elkjs:`elk.layered.nodePlacement.strategy`,type:`str`},"considerModelOrder.strategy":{ggn:`org.eclipse.elk.layered.considerModelOrder.strategy`,elkjs:`elk.layered.considerModelOrder.strategy`,type:`str`},mergeEdges:{ggn:`org.eclipse.elk.layered.mergeEdges`,elkjs:`elk.layered.mergeEdges`,type:`bool`},mergeHierarchyEdges:{ggn:`org.eclipse.elk.layered.mergeHierarchyEdges`,elkjs:`elk.layered.mergeHierarchyEdges`,type:`bool`},feedbackEdges:{ggn:`org.eclipse.elk.layered.feedbackEdges`,elkjs:`elk.layered.feedbackEdges`,type:`bool`},thoroughness:{ggn:`org.eclipse.elk.layered.thoroughness`,elkjs:`elk.layered.thoroughness`,type:`num`},randomSeed:{ggn:`org.eclipse.elk.randomSeed`,elkjs:`elk.randomSeed`,type:`num`},separateConnectedComponents:{ggn:`org.eclipse.elk.separateConnectedComponents`,elkjs:`elk.separateConnectedComponents`,type:`bool`},hierarchyHandling:{ggn:`org.eclipse.elk.hierarchyHandling`,elkjs:`elk.hierarchyHandling`,type:`str`},portConstraints:{ggn:`org.eclipse.elk.portConstraints`,elkjs:`elk.portConstraints`,type:`str`},"insideSelfLoops.activate":{ggn:`org.eclipse.elk.insideSelfLoops.activate`,elkjs:`elk.insideSelfLoops.activate`,type:`bool`},generatePositionAndLayerIds:{ggn:`org.eclipse.elk.layered.generatePositionAndLayerIds`,elkjs:`elk.layered.generatePositionAndLayerIds`,type:`bool`},"nodeLabels.placement":{ggn:`org.eclipse.elk.nodeLabels.placement`,elkjs:`elk.nodeLabels.placement`,type:`enumset`,values:[`H_LEFT`,`H_CENTER`,`H_RIGHT`,`V_TOP`,`V_CENTER`,`V_BOTTOM`,`INSIDE`,`OUTSIDE`,`H_PRIORITY`]},"portLabels.placement":{ggn:`org.eclipse.elk.portLabels.placement`,elkjs:`elk.portLabels.placement`,type:`enumset`,values:[`OUTSIDE`,`INSIDE`,`NEXT_TO_PORT_IF_POSSIBLE`,`ALWAYS_SAME_SIDE`,`ALWAYS_OTHER_SAME_SIDE`,`SPACE_EFFICIENT`]},allowNonFlowPortsToSwitchSides:{ggn:`org.eclipse.elk.layered.allowNonFlowPortsToSwitchSides`,elkjs:`elk.layered.allowNonFlowPortsToSwitchSides`,type:`bool`},directionCongruency:{ggn:`org.eclipse.elk.layered.directionCongruency`,elkjs:`elk.layered.directionCongruency`,type:`str`},portSortingStrategy:{ggn:`org.eclipse.elk.layered.portSortingStrategy`,elkjs:`elk.portSortingStrategy`,type:`str`},aspectRatio:{ggn:`org.eclipse.elk.aspectRatio`,elkjs:`elk.aspectRatio`,type:`num`},"edgeRouting.selfLoopDistribution":{ggn:`org.eclipse.elk.layered.edgeRouting.selfLoopDistribution`,elkjs:`elk.layered.edgeRouting.selfLoopDistribution`,type:`str`},"edgeRouting.selfLoopOrdering":{ggn:`org.eclipse.elk.layered.edgeRouting.selfLoopOrdering`,elkjs:`elk.layered.edgeRouting.selfLoopOrdering`,type:`str`},"nodePlacement.bk.fixedAlignment":{ggn:`org.eclipse.elk.layered.nodePlacement.bk.fixedAlignment`,elkjs:`elk.layered.nodePlacement.bk.fixedAlignment`,type:`str`},"nodePlacement.bk.edgeStraightening":{ggn:`org.eclipse.elk.layered.nodePlacement.bk.edgeStraightening`,elkjs:`elk.layered.nodePlacement.bk.edgeStraightening`,type:`str`},"layering.nodePromotion.strategy":{ggn:`org.eclipse.elk.layered.layering.nodePromotion.strategy`,elkjs:`elk.layered.layering.nodePromotion.strategy`,type:`str`},"considerModelOrder.portModelOrder":{ggn:`org.eclipse.elk.layered.considerModelOrder.portModelOrder`,elkjs:`elk.layered.considerModelOrder.portModelOrder`,type:`bool`},"edgeLabels.placement":{ggn:`org.eclipse.elk.edgeLabels.placement`,elkjs:`elk.edgeLabels.placement`,type:`str`},"spacing.labelPort":{ggn:`org.eclipse.elk.spacing.labelPortHorizontal`,elkjs:`elk.spacing.labelPortHorizontal`,type:`num`},"insideSelfLoops.yo":{ggn:`org.eclipse.elk.insideSelfLoops.yo`,elkjs:`elk.insideSelfLoops.yo`,type:`bool`},"nodeSize.constraints":{ggn:`org.eclipse.elk.nodeSize.constraints`,elkjs:`elk.nodeSize.constraints`,type:`enumset`,values:[`PORTS`,`PORT_LABELS`,`NODE_LABELS`,`MINIMUM_SIZE`]},"nodeSize.minimum":{ggn:`org.eclipse.elk.nodeSize.minimum`,elkjs:`elk.nodeSize.minimum`,type:`str`},"nodeSize.options":{ggn:`org.eclipse.elk.nodeSize.options`,elkjs:`elk.nodeSize.options`,type:`str`},"nodeLabels.padding":{ggn:`org.eclipse.elk.nodeLabels.padding`,elkjs:`elk.nodeLabels.padding`,type:`object`},"nodeLabels.spacing":{ggn:`org.eclipse.elk.nodeLabels.spacing`,elkjs:`elk.nodeLabels.spacing`,type:`num`},layerConstraint:{ggn:`org.eclipse.elk.layered.layering.layerConstraint`,elkjs:`elk.layered.layering.layerConstraint`,type:`str`},"layering.layerConstraint":{ggn:`org.eclipse.elk.layered.layering.layerConstraint`,elkjs:`elk.layered.layering.layerConstraint`,type:`str`},"layering.layerChoiceConstraint":{ggn:`org.eclipse.elk.layered.layering.layerChoiceConstraint`,elkjs:`elk.layered.layering.layerChoiceConstraint`,type:`num`},"crossingMinimization.positionChoiceConstraint":{ggn:`org.eclipse.elk.layered.crossingMinimization.positionChoiceConstraint`,elkjs:`elk.layered.crossingMinimization.positionChoiceConstraint`,type:`num`},"crossingMinimization.semiInteractive":{ggn:`org.eclipse.elk.layered.crossingMinimization.semiInteractive`,elkjs:`elk.layered.crossingMinimization.semiInteractive`,type:`bool`},algorithm:{ggn:`org.eclipse.elk.algorithm`,elkjs:`elk.algorithm`,type:`str`},"partitioning.partition":{ggn:`org.eclipse.elk.partitioning.partition`,elkjs:`elk.partitioning.partition`,type:`num`},"spacing.portNode":{ggn:`org.eclipse.elk.spacing.portNode`,elkjs:`elk.spacing.portNode`,type:`num`},"portAlignment.default":{ggn:`org.eclipse.elk.portAlignment.default`,elkjs:`elk.portAlignment.default`,type:`str`},"portAlignment.west":{ggn:`org.eclipse.elk.portAlignment.west`,elkjs:`elk.portAlignment.west`,type:`str`},"portAlignment.east":{ggn:`org.eclipse.elk.portAlignment.east`,elkjs:`elk.portAlignment.east`,type:`str`},"portAlignment.north":{ggn:`org.eclipse.elk.portAlignment.north`,elkjs:`elk.portAlignment.north`,type:`str`},"portAlignment.south":{ggn:`org.eclipse.elk.portAlignment.south`,elkjs:`elk.portAlignment.south`,type:`str`},commentBox:{ggn:`org.eclipse.elk.commentBox`,elkjs:`elk.commentBox`,type:`bool`},desiredPosition:{ggn:`org.eclipse.elk.desiredPosition`,elkjs:`elk.desiredPosition`,type:`str`},interactiveLayout:{ggn:`org.eclipse.elk.interactiveLayout`,elkjs:`elk.interactiveLayout`,type:`bool`},padding:{ggn:`org.eclipse.elk.padding`,elkjs:`elk.padding`,type:`object`},noLayout:{ggn:`org.eclipse.elk.noLayout`,elkjs:`elk.noLayout`,type:`bool`},expandNodes:{ggn:`org.eclipse.elk.expandNodes`,elkjs:`elk.expandNodes`,type:`bool`},debugMode:{ggn:`org.eclipse.elk.debugMode`,elkjs:`elk.debugMode`,type:`bool`},alignment:{ggn:`org.eclipse.elk.alignment`,elkjs:`elk.alignment`,type:`str`},contentAlignment:{ggn:`org.eclipse.elk.contentAlignment`,elkjs:`elk.contentAlignment`,type:`enumset`,values:[`V_TOP`,`V_CENTER`,`V_BOTTOM`,`H_LEFT`,`H_CENTER`,`H_RIGHT`]},"spacing.portsSurrounding":{ggn:`org.eclipse.elk.spacing.portsSurrounding`,elkjs:`elk.spacing.portsSurrounding`,type:`object`},"spacing.individual":{ggn:`org.eclipse.elk.spacing.individual`,elkjs:`elk.spacing.individual`,type:`str`},"spacing.commentComment":{ggn:`org.eclipse.elk.spacing.commentComment`,elkjs:`elk.spacing.commentComment`,type:`num`},"spacing.commentNode":{ggn:`org.eclipse.elk.spacing.commentNode`,elkjs:`elk.spacing.commentNode`,type:`num`},"spacing.componentComponent":{ggn:`org.eclipse.elk.spacing.componentComponent`,elkjs:`elk.spacing.componentComponent`,type:`num`},"portLabels.treatAsGroup":{ggn:`org.eclipse.elk.portLabels.treatAsGroup`,elkjs:`elk.portLabels.treatAsGroup`,type:`bool`},"partitioning.activate":{ggn:`org.eclipse.elk.partitioning.activate`,elkjs:`elk.partitioning.activate`,type:`bool`},fixedAlignment:{ggn:`org.eclipse.elk.layered.nodePlacement.bk.fixedAlignment`,elkjs:`elk.layered.nodePlacement.bk.fixedAlignment`,type:`str`},edgeStraightening:{ggn:`org.eclipse.elk.layered.nodePlacement.bk.edgeStraightening`,elkjs:`elk.layered.nodePlacement.bk.edgeStraightening`,type:`str`},mode:{ggn:`org.eclipse.elk.layered.edgeRouting.splines.mode`,elkjs:`elk.layered.edgeRouting.splines.mode`,type:`str`},"postCompaction.strategy":{ggn:`org.eclipse.elk.layered.compaction.postCompaction.strategy`,elkjs:`elk.layered.compaction.postCompaction.strategy`,type:`str`},"compaction.connectedComponents":{ggn:`org.eclipse.elk.layered.compaction.connectedComponents`,elkjs:`elk.layered.compaction.connectedComponents`,type:`bool`},"edgeLabels.sideSelection":{ggn:`org.eclipse.elk.layered.edgeLabels.sideSelection`,elkjs:`elk.layered.edgeLabels.sideSelection`,type:`str`},"edgeLabels.centerLabelPlacementStrategy":{ggn:`org.eclipse.elk.layered.edgeLabels.centerLabelPlacementStrategy`,elkjs:`elk.layered.edgeLabels.centerLabelPlacementStrategy`,type:`str`},"highDegreeNodes.threshold":{ggn:`org.eclipse.elk.layered.highDegreeNodes.threshold`,elkjs:`elk.layered.highDegreeNodes.threshold`,type:`num`},"highDegreeNodes.treatment":{ggn:`org.eclipse.elk.layered.highDegreeNodes.treatment`,elkjs:`elk.layered.highDegreeNodes.treatment`,type:`bool`},"highDegreeNodes.treeHeight":{ggn:`org.eclipse.elk.layered.highDegreeNodes.treeHeight`,elkjs:`elk.layered.highDegreeNodes.treeHeight`,type:`num`},"considerModelOrder.components":{ggn:`org.eclipse.elk.layered.considerModelOrder.components`,elkjs:`elk.layered.considerModelOrder.components`,type:`str`},"considerModelOrder.longEdgeStrategy":{ggn:`org.eclipse.elk.layered.considerModelOrder.longEdgeStrategy`,elkjs:`elk.layered.considerModelOrder.longEdgeStrategy`,type:`str`},"considerModelOrder.crossingCounterNodeInfluence":{ggn:`org.eclipse.elk.layered.considerModelOrder.crossingCounterNodeInfluence`,elkjs:`elk.layered.considerModelOrder.crossingCounterNodeInfluence`,type:`num`},"crossingMinimization.greedySwitchHierarchical.type":{ggn:`org.eclipse.elk.layered.crossingMinimization.greedySwitchHierarchical.type`,elkjs:`elk.layered.crossingMinimization.greedySwitchHierarchical.type`,type:`str`},"crossingMinimization.forceNodeModelOrder":{ggn:`org.eclipse.elk.layered.crossingMinimization.forceNodeModelOrder`,elkjs:`elk.layered.crossingMinimization.forceNodeModelOrder`,type:`bool`},nodeFlexibility:{ggn:`org.eclipse.elk.layered.nodePlacement.networkSimplex.nodeFlexibility`,elkjs:`elk.layered.nodePlacement.networkSimplex.nodeFlexibility`,type:`str`},"nodeFlexibility.default":{ggn:`org.eclipse.elk.layered.nodePlacement.networkSimplex.nodeFlexibility.default`,elkjs:`elk.layered.nodePlacement.networkSimplex.nodeFlexibility.default`,type:`str`},portPort:{ggn:`org.eclipse.elk.spacing.portPort`,elkjs:`elk.spacing.portPort`,type:`num`},nodeNode:{ggn:`org.eclipse.elk.spacing.nodeNode`,elkjs:`elk.spacing.nodeNode`,type:`num`},minimum:{ggn:`org.eclipse.elk.nodeSize.minimum`,elkjs:`elk.nodeSize.minimum`,type:`str`},"greedySwitch.type":{ggn:`org.eclipse.elk.layered.crossingMinimization.greedySwitch.type`,elkjs:`elk.layered.crossingMinimization.greedySwitch.type`,type:`str`},positionChoiceConstraint:{ggn:`org.eclipse.elk.layered.crossingMinimization.positionChoiceConstraint`,elkjs:`elk.layered.crossingMinimization.positionChoiceConstraint`,type:`num`},sideSelection:{ggn:`org.eclipse.elk.layered.edgeLabels.sideSelection`,elkjs:`elk.layered.edgeLabels.sideSelection`,type:`str`},"nodeSize.fixedGraphSize":{ggn:`org.eclipse.elk.nodeSize.fixedGraphSize`,elkjs:`elk.nodeSize.fixedGraphSize`,type:`bool`},"topdown.hierarchicalNodeWidth":{ggn:`org.eclipse.elk.topdown.hierarchicalNodeWidth`,elkjs:`elk.topdown.hierarchicalNodeWidth`,type:`num`},"topdown.hierarchicalNodeAspectRatio":{ggn:`org.eclipse.elk.topdown.hierarchicalNodeAspectRatio`,elkjs:`elk.topdown.hierarchicalNodeAspectRatio`,type:`num`},"topdownpacking.nodeArrangement.strategy":{ggn:`org.eclipse.elk.topdownpacking.nodeArrangement.strategy`,elkjs:`elk.topdownpacking.nodeArrangement.strategy`,type:`str`},"topdownpacking.whitespaceElimination.strategy":{ggn:`org.eclipse.elk.topdownpacking.whitespaceElimination.strategy`,elkjs:`elk.topdownpacking.whitespaceElimination.strategy`,type:`str`},"vertiflex.verticalConstraint":{ggn:`org.eclipse.elk.vertiflex.verticalConstraint`,elkjs:`elk.vertiflex.verticalConstraint`,type:`num`},"vertiflex.layoutStrategy":{ggn:`org.eclipse.elk.vertiflex.layoutStrategy`,elkjs:`elk.vertiflex.layoutStrategy`,type:`str`},"vertiflex.layerDistance":{ggn:`org.eclipse.elk.vertiflex.layerDistance`,elkjs:`elk.vertiflex.layerDistance`,type:`num`},"vertiflex.considerNodeModelOrder":{ggn:`org.eclipse.elk.vertiflex.considerNodeModelOrder`,elkjs:`elk.vertiflex.considerNodeModelOrder`,type:`bool`},"overlapRemoval.maxIterations":{ggn:`org.eclipse.elk.overlapRemoval.maxIterations`,elkjs:`elk.overlapRemoval.maxIterations`,type:`num`},"overlapRemoval.runScanline":{ggn:`org.eclipse.elk.overlapRemoval.runScanline`,elkjs:`elk.overlapRemoval.runScanline`,type:`bool`},"processingOrder.treeConstruction":{ggn:`org.eclipse.elk.processingOrder.treeConstruction`,elkjs:`elk.processingOrder.treeConstruction`,type:`str`},"processingOrder.spanningTreeCostFunction":{ggn:`org.eclipse.elk.processingOrder.spanningTreeCostFunction`,elkjs:`elk.processingOrder.spanningTreeCostFunction`,type:`str`},"processingOrder.rootSelection":{ggn:`org.eclipse.elk.processingOrder.rootSelection`,elkjs:`elk.processingOrder.rootSelection`,type:`str`},"processingOrder.preferredRoot":{ggn:`org.eclipse.elk.processingOrder.preferredRoot`,elkjs:`elk.processingOrder.preferredRoot`,type:`str`},"compaction.compactionStrategy":{ggn:`org.eclipse.elk.compaction.compactionStrategy`,elkjs:`elk.compaction.compactionStrategy`,type:`str`},"compaction.orthogonal":{ggn:`org.eclipse.elk.compaction.orthogonal`,elkjs:`elk.compaction.orthogonal`,type:`bool`},"structure.structureExtractionStrategy":{ggn:`org.eclipse.elk.structure.structureExtractionStrategy`,elkjs:`elk.structure.structureExtractionStrategy`,type:`str`},underlyingLayoutAlgorithm:{ggn:`org.eclipse.elk.underlyingLayoutAlgorithm`,elkjs:`elk.underlyingLayoutAlgorithm`,type:`str`},interactiveReferencePoint:{ggn:`org.eclipse.elk.layered.interactiveReferencePoint`,elkjs:`elk.layered.interactiveReferencePoint`,type:`str`},considerModelOrder:{ggn:`org.eclipse.elk.layered.considerModelOrder.strategy`,elkjs:`elk.layered.considerModelOrder.strategy`,type:`str`},portAlignment:{ggn:`org.eclipse.elk.portAlignment.default`,elkjs:`elk.portAlignment.default`,type:`str`}};function Kf(e){return e.replace(/\\(['"\\])/g,(e,t)=>t)}function qf(e,t){let n=t.trim();if((n.startsWith(`"`)&&n.endsWith(`"`)||n.startsWith(`'`)&&n.endsWith(`'`))&&(n=n.slice(1,-1)),e.type===`num`){let e=Number(n);return Number.isFinite(e)?e:void 0}if(e.type===`bool`)return n.toLowerCase()===`true`;if(e.type===`enumset`){let t=n.match(/^\[([^\]]*)\]$/),r=(t?t[1]:n).split(/[\s,]+/).map(e=>e.trim()).filter(Boolean);if(e.values){for(let t of r)if(!e.values.includes(t))return}return r}if(e.type===`object`){let e=n.match(/^\[([^\]]*)\]$/);if(e){let t={};for(let n of e[1].split(/[,;]/)){let e=n.split(`=`);if(e.length===2){let n=Number(e[1].trim());if(!Number.isFinite(n))return;t[e[0].trim()]=n}}return t}let t=n.match(/^\(([\d.]+)\s*,\s*([\d.]+)\)$/);return t?{x:Number(t[1]),y:Number(t[2])}:void 0}return Kf(n)}function Jf(e,t){let n={},r=t instanceof Map?t.entries():Object.entries(t);for(let[t,i]of r){let r=e[t];if(r===void 0)continue;let a=[];for(let t of i){let n=e[t];n!==void 0&&a.push(n)}n[r]=a}return n}function Yf(t,n,r=null,i=null,a=`EAST`,o=!1,s=!1){let c=(t,n,r)=>{if(r&&t.getProperty(e.Lt)!==`FIXED_SIDE`)return Uf(t,n===`OUTPUT`?`OUTPUT`:`INPUT`,(n===`OUTPUT`?a:Xf[a]??`WEST`)??`EAST`,!0,!1);let i=new p;return i.setNode(t),i.setSide(n===`OUTPUT`?a:Xf[a]??`WEST`),i},l=r!==null&&r<t.getPorts().length?t.getPorts()[r]:c(t,`OUTPUT`,o),u=i!==null&&i<n.getPorts().length?n.getPorts()[i]:c(n,`INPUT`,s),d=new m;return d.setSource(l),d.setTarget(u),d}const Xf={NORTH:`SOUTH`,SOUTH:`NORTH`,EAST:`WEST`,WEST:`EAST`};function Zf(e,t){let n=e.split(`.`),r=t.split(`.`),i=0;for(;i<n.length&&i<r.length&&n[i]===r[i];)i++;return i===0?null:n.slice(0,i).join(`.`)}function Qf(e){return String(e).trim().toLowerCase().replace(/^org\.eclipse\.elk\./,``).replace(/^elk\./,``)}function $f(e,t,n,r){let i=n(e),a=n(t);if(i===null&&a===null)return;let o=Zf(e,t);if(o===null||!r(o)&&n(o)===null)throw Error(`UnsupportedGraphException: The source or the target of edge could not be found. This usually happens when an edge connects a node laid out by ELK Layered to a node in another level of hierarchy laid out by either another instance of ELK Layered or another layout algorithm alltogether. The former can be solved by setting the hierarchyHandling option to INCLUDE_CHILDREN.`)}function ep(e,t){for(let[n,r]of Object.entries(t)){let t=Gf[n];if(!t)continue;let i=typeof r==`object`&&r&&!Array.isArray(r)?r:qf(t,String(r));if(i!==void 0){if(t.ggn===`org.eclipse.elk.nodeSize.minimum`&&typeof i==`string`){let[e,t]=String(i).replace(/[()]/g,``).split(`,`).map(Number);i={x:e,y:t}}if(t.ggn===`org.eclipse.elk.padding`){let t=i;if(typeof t!=`object`||!t||t.top===void 0&&t.left===void 0&&t.right===void 0&&t.bottom===void 0)continue;e.setPadding({top:t.top??0,left:t.left??0,right:t.right??0,bottom:t.bottom??0})}else e.setProperty(t.ggn,i)}}}function tp(t,n=`graph`){let{nodes:r,edges:i,hierarchy:a,graphProps:o,nodeProps:s}=t,l=r.length,u=Object.create(null);for(let e=0;e<l;e++){let t=r[e];u[t]===void 0&&(u[t]=e)}let d=Jf(u,a),m=String(o.direction??`RIGHT`).toUpperCase(),h=new c,g=/* @__PURE__ */ new Map,_=/* @__PURE__ */ new Map,v=new Int32Array(l);v.fill(-1);for(let e of Object.keys(d)){let t=Number(e);_.set(t,new c);for(let e of d[t])v[e]===-1&&(v[e]=t)}for(let t=0;t<l;t++){let n=r[t],i=s.get(n)??{},o=v[t],c=new f(o===-1?h:_.get(o));c.size={x:i.width??60,y:i.height??30},i.x!==void 0&&(c.position.x=i.x),i.y!==void 0&&(c.position.y=i.y),i.portConstraints&&c.setProperty(e.Lt,i.portConstraints),(i[`insideSelfLoops.activate`]===`true`||i[`insideSelfLoops.activate`]===!0)&&c.setProperty(e.Q,!0);for(let[e,t]of Object.entries(i)){if(e.startsWith(`_`)||e===`ports`||e===`children`||e===`labels`||e===`width`||e===`height`||e===`portConstraints`||e===`insideSelfLoops.activate`)continue;let n=Gf[e];if(!n)continue;let r=typeof t==`object`&&t&&!Array.isArray(t)?t:qf(n,String(t));if(r!==void 0){if(n.ggn===`org.eclipse.elk.nodeSize.minimum`&&typeof r==`string`){let[e,t]=String(r).replace(/[()]/g,``).split(`,`).map(Number);r={x:e,y:t}}if(n.ggn===`org.eclipse.elk.position`&&typeof r==`string`){let[e,t]=String(r).replace(/[()]/g,``).split(`,`).map(Number);r={x:e,y:t}}c.setProperty(n.ggn,r)}}for(let t of i.ports??[]){let n=t.side??null,r=new p;r.setNode(c),r.getPosition().x=t.x??0,r.getPosition().y=t.y??0,r.size={x:t.w??8,y:t.h??8},t.borderOffset!==void 0&&t.borderOffset!==null&&r.setProperty(e.It,t.borderOffset),n&&r.setSide(n),t.index!==null&&t.index!==void 0&&r.setProperty(e.Rt,t.index),(t.labels??[]).length>0&&r.setLabels((t.labels??[]).map(e=>({text:e.text??``,position:{x:e.x??0,y:e.y??0},size:{x:e.width??0,y:e.height??0}})))}if((i.labels??[]).length>0&&c.setLabels((i.labels??[]).map(e=>({text:e.text??``,position:{x:e.x??0,y:e.y??0},size:{x:e.width??0,y:e.height??0},placement:e.placement??void 0}))),(a.get(n)??[]).length>0){let e=_.get(t);if(e){let t=typeof i.padding==`object`?i.padding:i.padding?qf(Gf.padding,String(i.padding)):null,n=t===null||!(e=>e!==null&&(e.top!==void 0||e.left!==void 0||e.right!==void 0||e.bottom!==void 0))(t)?{top:12,left:12,right:12,bottom:12}:{top:t.top??0,left:t.left??0,right:t.right??0,bottom:t.bottom??0},r=i[`nodeLabels.placement`],a=0,o=0,s=0,c=0;for(let e of i.labels??[]){let t=e.placement??r??``;if(!t)continue;let n=String(t).replace(/[\[\]]/g,``).split(/[\s,]+/).filter(Boolean);n.includes(`INSIDE`)&&(n.includes(`V_TOP`)?a=Math.max(a,e.height??0):n.includes(`V_BOTTOM`)?o=Math.max(o,e.height??0):(n.includes(`H_LEFT`)&&(s=Math.max(s,e.width??0)),n.includes(`H_RIGHT`)&&(c=Math.max(c,e.width??0))))}let l=i[`nodeLabels.padding`]??{top:5,right:5,bottom:5,left:5},u=Number(i[`spacing.labelLabel`]??0),d=typeof l==`object`?l.top??5:5,f=typeof l==`object`?l.bottom??5:5,p=typeof l==`object`?l.left??5:5,m=typeof l==`object`?l.right??5:5,h=(e,t)=>e>0?e+t+2*u:0;e.setPadding({top:n.top+h(a,d),bottom:n.bottom+h(o,f),left:n.left+h(s,p),right:n.right+h(c,m)})}}g.set(t,c)}for(let t of Object.keys(d).map(Number)){let n=g.get(t),i=_.get(t);n.setNestedGraph(i),i.setParentNode(n);let a=(s.get(r[t])??{}).mergeEdges;(a===!0||a===`true`)&&i.setProperty(e.mt,!0)}(o.mergeEdges===!0||o.mergeEdges===`true`)&&h.setProperty(e.mt,!0);let y=/* @__PURE__ */ new Map;for(let[e,t]of Object.entries(d)){let n=Number(e);for(let e of t)y.set(e,n)}let b=(e,t)=>{let n=/* @__PURE__ */ new Set,r=e;for(;r!==void 0;)n.add(r),r=y.get(r);let i=t;for(;i!==void 0&&!n.has(i);)i=y.get(i);if(i===void 0)return h;let a=y.get(i);return a===void 0?h:_.get(a)??h},x=e=>{let t=s.get(e);return t!==void 0&&t.algorithm!==void 0&&Qf(t.algorithm)!==`layered`},S=e=>{let t=e.lastIndexOf(`.`);for(;t!==-1;){let n=e.slice(0,t);if(x(n))return n;t=n.lastIndexOf(`.`)}return null};for(let[t,n,r,a,o,c,l]of i){$f(t,r,S,x);let i=u[t],d=u[r];if(i===void 0||d===void 0)continue;let f=n===null?-1:(s.get(t)?.ports??[]).findIndex(e=>e.id===n),p=a===null?-1:(s.get(r)?.ports??[]).findIndex(e=>e.id===a),h={RIGHT:`EAST`,LEFT:`WEST`,DOWN:`SOUTH`,UP:`NORTH`}[m]??`EAST`,_=(f<0||f>=g.get(i).getPorts().length)&&b(i,d).getProperty(e.mt)===!0,v=(p<0||p>=g.get(d).getPorts().length)&&g.get(d).getGraph()?.getProperty(e.mt)===!0,y=Yf(g.get(i),g.get(d),f>=0?f:null,p>=0?p:null,h,_,v);if(o===!0&&y.setProperty(e.$,!0),l!=null&&y.setProperty(e.W,l),c!=null&&c.length>0)for(let e of c)y.getLabels().push({text:e.text??``,position:{x:0,y:0},size:{x:e.width??0,y:e.height??0},placement:e.placement??void 0})}return Object.keys(d).length>0&&h.setProperty(e.q,`INCLUDE_CHILDREN`),h.setProperty(e.F,m),ep(h,o),h.hasProperty(e.Kt)||h.setProperty(e.Kt,1),{graph:h,nodeOf:g,nodeCount:l,edgeCount:i.length,hasHierarchy:Object.keys(d).length>0,name:n}}function np(e={}){let t={};for(let[n,r]of Object.entries(e)){let e=null;for(let[t,r]of Object.entries(Gf))if(r.ggn===n||r.elkjs===n){e=t;break}t[e??n.replace(/^org\.eclipse\.elk\./,``).replace(/^layered\./,``)]=r}return t}function rp(e,t={}){let n=t.stripNPrefix!==!1,r=t.blackBoxIds instanceof Set?t.blackBoxIds:/* @__PURE__ */ new Set,i=[],a=/* @__PURE__ */ new Set;for(let e of r)a.add(n?String(e).replace(/^N/,``):String(e));let o=/* @__PURE__ */ new Map;if(a.size>0){let t=(e,r)=>{let i=n?String(e.id).replace(/^N/,``):String(e.id),s=a.has(i)?i:r;for(let r of e.children??[]){let e=n?String(r.id).replace(/^N/,``):String(r.id);s!==null&&o.set(e,s),t(r,s)}};t(e,null)}let s=[],c=/* @__PURE__ */ new Map,l={},u=/* @__PURE__ */ new Map,d=/* @__PURE__ */ new Set,f=(e,t)=>{let a=n?e.id.replace(/^N/,``):e.id;if(d.has(a)||(d.add(a),i.push(a)),t!=null){let e=c.get(t)??[];e.includes(a)||e.push(a),c.set(t,e)}let o={width:e.width??60,height:e.height??30,x:e.x,y:e.y},s=(n?`N`+a:a)+`.`,l=e.ports??[];o.ports=l.map(e=>{let t=np(e.properties??{}),n={id:e.id&&e.id.startsWith(s)?e.id.slice(s.length):e.id,w:0,h:0};e.x!==void 0&&(n.x=e.x),e.y!==void 0&&(n.y=e.y),n.w=e.width??0,n.h=e.height??0,t[`port.side`]!==void 0&&(n.side=t[`port.side`]===`UNDEFINED`?null:t[`port.side`]),t[`port.index`]!==void 0&&(n.index=Number(t[`port.index`])),t[`port.borderOffset`]!==void 0&&(n.borderOffset=Number(t[`port.borderOffset`]));let r=e.labels??[];return r.length>0&&(n.labels=r.map(e=>{let t={text:e.text??``,width:e.width??0,height:e.height??0};return e.x!==void 0&&(t.x=e.x,t.y=e.y),t})),n}),l.length===0&&delete o.ports;let p=e.labels??[];if(o.labels=p.map(e=>{let t=np(e.layoutOptions??{}),n={text:e.text??``,width:e.width??0,height:e.height??0};return e.x!==void 0&&(n.x=e.x),e.y!==void 0&&(n.y=e.y),t[`nodeLabels.placement`]!==void 0&&(n.placement=t[`nodeLabels.placement`]),n}),p.length===0&&delete o.labels,Object.assign(o,np(e.layoutOptions??{})),u.set(a,o),!(r.has(e.id)||r.has(a)))for(let t of e.children??[])f(t,a)};for(let t of e.children??[])f(t,null);Object.assign(l,np(e.layoutOptions??{}));let p=e=>{let t=n?String(e??``).replace(/^N/,``):String(e??``);if(d.has(t))return[t,null];let r=t.lastIndexOf(`.`);return r!==-1&&d.has(t.slice(0,r))?[t.slice(0,r),t.slice(r+1)]:[t,null]},m=e=>{if(!(r.has(e.id)||r.has(n?String(e.id).replace(/^N/,``):e.id))){for(let t of e.edges??[]){if(a.size>0){let e=t.sources?.[0]??t.source,r=t.targets?.[0]??t.target;if(e!==void 0&&r!==void 0){let t=e=>n?String(e).replace(/^N/,``):String(e);$f(t(e),t(r),e=>{if(o.has(e))return o.get(e);let t=e.lastIndexOf(`.`);return t!==-1&&o.has(e.slice(0,t))?o.get(e.slice(0,t)):null},e=>a.has(e))}}let[e,r]=p(t.sources?.[0]??t.source),[i,c]=p(t.targets?.[0]??t.target),l=np(t.properties??{}),u=l[`insideSelfLoops.yo`]===`true`,d=l[`edge.thickness`]===void 0?null:Number(l[`edge.thickness`]),f=(t.labels??[]).map(e=>{let t=np(e.layoutOptions??{})[`edgeLabels.placement`]??e.placement??null;return{text:e.text??``,width:e.width??0,height:e.height??0,placement:t}});s.push([e,r,i,c,u,f,d])}for(let t of e.children??[])m(t)}};return m(e),{nodes:i,edges:s,hierarchy:c,graphProps:l,nodeProps:u}}let ip=/* @__PURE__ */ function(e){return e.INVALID_INPUT=`INVALID_INPUT`,e.MISSING_ID=`MISSING_ID`,e.DUPLICATE_ID=`DUPLICATE_ID`,e.NEGATIVE_SIZE=`NEGATIVE_SIZE`,e.NON_FINITE_SIZE=`NON_FINITE_SIZE`,e.EMPTY_ENDPOINTS=`EMPTY_ENDPOINTS`,e.DANGLING_ENDPOINT=`DANGLING_ENDPOINT`,e.MULTI_ENDPOINTS=`MULTI_ENDPOINTS`,e.UNSUPPORTED_ALGORITHM=`UNSUPPORTED_ALGORITHM`,e.CYCLIC_REFERENCE=`CYCLIC_REFERENCE`,e.INTERNAL_ERROR=`INTERNAL_ERROR`,e.ABORTED=`ABORTED`,e}({});var ap=class extends Error{code;path;retryable;phase;details;constructor(e,t,n,r={}){super(`${e} at ${t||`root`}: ${n}`,r.cause===void 0?void 0:{cause:r.cause}),this.name=`LayoutError`,this.code=e,this.path=t,this.retryable=!1,this.phase=r.phase,this.details=r.details,Object.setPrototypeOf(this,new.target.prototype)}toJSON(){let e={name:this.name,code:this.code,path:this.path,message:this.message,retryable:this.retryable};return this.phase!==void 0&&(e.phase=this.phase),this.details!==void 0&&(e.details=this.details),e}};function op(e){if(typeof e!=`object`||!e||Array.isArray(e))return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function sp(e,t){return e?`${e}.${t}`:t}function cp(e,t,n){return`${e?`${e}.`:``}${t}[${n}]`}function $(e,t,n,r){e.push({code:t,path:n,message:`${t} at ${n||`root`}: ${r}`,retryable:!1})}function lp(e,t,n){typeof e!=`number`||!Number.isFinite(e)?$(n,`NON_FINITE_SIZE`,t,`size must be a finite number`):e<0&&$(n,`NEGATIVE_SIZE`,t,`size must be greater than or equal to zero`)}function up(e,t,n){for(let r of[`width`,`height`])r in e&&lp(e[r],sp(t,r),n)}function dp(t,n,r,i){let a=t.layoutOptions;if(op(a))for(let t of[`org.eclipse.elk.algorithm`,`elk.algorithm`]){if(!(t in a))continue;let o=a[t];(typeof o!=`string`||o.trim()!==``)&&(e.d(o)||$(i,`UNSUPPORTED_ALGORITHM`,sp(n,`layoutOptions.${t}`),`algorithm ${JSON.stringify(o)} on node ${JSON.stringify(r??`root`)} is not supported`))}}function fp(e,t,n,r,i,a){if(!op(e)){$(n,a?`INVALID_INPUT`:`MISSING_ID`,t||`root`,a?`root input must be a plain object`:`child node must be a plain object with a non-empty string id`);return}if(i.has(e)){$(n,`CYCLIC_REFERENCE`,t||`root`,`object is referenced more than once in the input tree (cycle or shared reference)`);return}i.add(e);let o=e.id,s=typeof o==`string`&&o.trim().length>0;s?r.nodeIds.has(o)?$(n,`DUPLICATE_ID`,t||`root`,`node id ${JSON.stringify(o)} is duplicated`):r.nodeIds.add(o):$(n,a?`INVALID_INPUT`:`MISSING_ID`,a?`root`:t,a?`root input must have a non-empty string id`:`child node must have a non-empty string id`),up(e,t,n),dp(e,t,s?o:void 0,n);let c=s?o:void 0,l=e.ports;if(Array.isArray(l))for(let e=0;e<l.length;e+=1){let i=l[e],a=cp(t,`ports`,e);if(!op(i))continue;up(i,a,n);let o=i.id;c!==void 0&&typeof o==`string`&&o.trim().length>0&&(r.portRefs.add(`${c}.${o}`),r.portRefs.add(o))}let u=e.children;if(Array.isArray(u))for(let e=0;e<u.length;e+=1)fp(u[e],cp(t,`children`,e),n,r,i,!1)}function pp(e,t){if(t.nodeIds.has(e))return!0;let n=e.lastIndexOf(`.`);return n!==-1&&t.nodeIds.has(e.slice(0,n))}function mp(e,t,n,r){if(!op(e))return;let i=e.edges;if(!Array.isArray(i))return;for(let e=0;e<i.length;e+=1){let a=i[e],o=cp(t,`edges`,e);if(!op(a))$(n,`EMPTY_ENDPOINTS`,o,`edge must contain non-empty sources and targets arrays`);else for(let e of[`sources`,`targets`]){let t=a[e],i=sp(o,e);if(!Array.isArray(t)||t.length===0||t.some(e=>typeof e!=`string`)){$(n,`EMPTY_ENDPOINTS`,i,`${e} must be a non-empty string array`);continue}if(t.length>1){$(n,`MULTI_ENDPOINTS`,i,`${e} must contain exactly one endpoint (hyperedge not supported in P0)`);continue}let s=t[0];pp(s,r)||$(n,`DANGLING_ENDPOINT`,`${i}[0]`,`endpoint reference ${JSON.stringify(s)} does not resolve to a node or port`)}}let a=e.children;if(Array.isArray(a))for(let e=0;e<a.length;e+=1)mp(a[e],cp(t,`children`,e),n,r)}function hp(e){let t=[];if(!op(e))return $(t,`INVALID_INPUT`,`root`,`root input must be a plain object`),t;let n={nodeIds:/* @__PURE__ */ new Set,portRefs:/* @__PURE__ */ new Set};return fp(e,``,t,n,/* @__PURE__ */ new WeakSet,!0),mp(e,``,t,n),t}function gp(e){let t=hp(e),n=t[0];if(n!==void 0)throw new ap(n.code,n.path,n.message,{phase:`validate`,details:{issues:t}})}function _p(e,t){if(Array.isArray(e)){let n=[];t&&t.set(e,n);for(let r of e)n.push(_p(r,t));return n}if(typeof e==`object`&&e){let n=t?.get(e);if(n!==void 0)return n;let r={};t&&t.set(e,r);for(let[n,i]of Object.entries(e))Object.defineProperty(r,n,{value:_p(i,t),enumerable:!0,writable:!0,configurable:!0});return r}return e}function vp(e,t,n,r){if(e?.signal?.aborted)throw new ap(`ABORTED`,`root`,`布局在 ${t} 阶段被取消`,{phase:t});if(e?.onProgress?.({phase:t,completed:n,...r===void 0?{}:{graphId:r}}),e?.signal?.aborted)throw new ap(`ABORTED`,`root`,`布局在 ${t} 阶段回调后被取消`,{phase:t})}function yp(t,n,r){let i={...n?.layoutOptions??{},...t.layoutOptions??{}},a=rp(t,{stripNPrefix:!1,blackBoxIds:r});if(Object.assign(a.graphProps,np(n?.layoutOptions??{})),n?.direction&&(a.graphProps.direction=n.direction),n?.randomSeed!==void 0&&(a.graphProps.randomSeed=String(n.randomSeed)),n?.hierarchyHandling&&(a.graphProps.hierarchyHandling=n.hierarchyHandling),a.graphProps.direction===void 0&&(a.graphProps.direction=i[`org.eclipse.elk.direction`]??i[`elk.direction`]??`RIGHT`),a.graphProps.randomSeed===void 0&&(a.graphProps.randomSeed=`1`),a.graphProps.hierarchyHandling===void 0){let e=(t.children??[]).some(e=>(e.children?.length??0)>0);a.graphProps.hierarchyHandling=e?`INCLUDE_CHILDREN`:`OFF`}let o=tp(a,t.id),s=/* @__PURE__ */ new Map,c=/* @__PURE__ */ new Map;for(let[t,n]of o.nodeOf){let i=a.nodes[t];s.set(n,i),c.set(i,n),r?.has(i)&&n.setProperty(e.q,`SEPARATE_CHILDREN`)}let l=/* @__PURE__ */ new Map,u=/* @__PURE__ */ new Map;for(let[e,t]of o.nodeOf){let n=a.nodes[e],r=a.nodeProps.get(n)?.ports??[],i=t.getPorts();for(let e=0;e<r.length&&e<i.length;e++){let t=`${n}.${r[e].id}`;l.set(t,i[e]),u.set(i[e],t)}}let d=/* @__PURE__ */ new Map;d.set(o.graph,t.id);let f=e=>{for(let t of e.getAllNodes()){let e=t.getNestedGraph();if(e){let n=s.get(t);n!==void 0&&d.set(e,n),f(e)}}};f(o.graph);let p=/* @__PURE__ */ new Set,m=e=>{for(let t of e.getAllNodes()){for(let e of t.getPorts())for(let t of e.getOutgoingEdges())p.add(t);let e=t.getNestedGraph();e&&m(e)}};return m(o.graph),{graph:o.graph,nodeOf:c,portOf:l,nodeRef:s,portRef:u,edgeSet:p,graphToNodeId:d,root:t}}function bp(e){let t=e.getSource()?.getNode(),n=e.getTarget()?.getNode();if(!t||!n)return null;if(t===n)return t.getGraph()?.getParentNode()??null;let r=/* @__PURE__ */ new Set,i=t;for(;i;)r.add(i),i=i.getGraph()?.getParentNode()??null;for(i=n;i;){if(r.has(i))return i;i=i.getGraph()?.getParentNode()??null}return null}function xp(e,t){let n={...t.root};delete n.children,delete n.edges;let r=/* @__PURE__ */ new Map,i=/* @__PURE__ */ new Map,a=/* @__PURE__ */ new Map,o=/* @__PURE__ */ new Map,s=(e,t,n)=>JSON.stringify([e,t,n]),c=e=>{if(i.has(e))return e;let t=e.lastIndexOf(`.`),n=t===-1?e:e.slice(0,t);return i.has(n)?n:null},l=(e,t)=>{let r=c(String(e[0]??``)),i=c(String(t[0]??``));if(r===null||i===null||r===i)return r===null?n.id:a.get(r)??n.id;let o=/* @__PURE__ */ new Set,s=r;for(;s!==null;)o.add(s),s=a.get(s)??null;for(s=i;s!==null&&!o.has(s);)s=a.get(s)??null;return s??n.id},u=(e,t)=>{i.set(e.id,e),a.set(e.id,t);for(let t of e.children??[])u(t,e.id)},d=e=>{for(let t of e.edges??[]){let n={edge:t,consumed:!1},r=e=>{let r=s(e,String(t.sources?.[0]??``),String(t.targets?.[0]??``)),i=o.get(r)??[];i.includes(n)||i.push(n),o.set(r,i)};r(e.id);let i=l(t.sources??[],t.targets??[]);i!==e.id&&r(i)}for(let t of e.children??[])d(t)};u(t.root,null),d(t.root);let f=(e,t,n)=>{let r=o.get(s(e,String(t[0]??``),String(n[0]??``)));for(;r&&r.length>0;){let e=r.shift();if(!e.consumed)return e.consumed=!0,e.edge}};function p(e,n){let a=[];n.children=a;for(let n of e.getAllNodes()){let e=t.nodeRef.get(n);if(e===void 0)continue;let o=i.get(e),s=o?{...o,x:n.position.x,y:n.position.y,width:n.size.x,height:n.size.y}:{id:e,x:n.position.x,y:n.position.y,width:n.size.x,height:n.size.y};delete s.children,delete s.edges,r.set(s.id,s),a.push(s);let c=n.getNestedGraph();c&&p(c,s)}}p(e,n);let m=/* @__PURE__ */ new Set,h=/* @__PURE__ */ new Map;function g(e){for(let r of e.getAllNodes()){for(let e of r.getPorts())for(let r of e.getOutgoingEdges()){if(m.has(r)||!t.edgeSet.has(r))continue;m.add(r);let e=bp(r),i=h.get(e)??[];h.set(e,i);let{source:a,target:o}=Bi(r),s=[Sp(r.getSource(),t)],c=[Sp(r.getTarget(),t)],l=r.getBendPoints().map(e=>({x:e.x,y:e.y})),u={startPoint:a,endPoint:o};l.length>0&&(u.bendPoints=l);let d=e===null?n.id:t.nodeRef.get(e)??n.id,p=f(d,s,c);i.push(p?{...p,sources:s,targets:c,sections:[u],container:d}:{sources:s,targets:c,sections:[u],container:d})}let e=r.getNestedGraph();e&&g(e)}}g(e);let _=h.get(null);_&&_.length>0&&(n.edges=_);for(let[e,n]of h){if(e===null)continue;let i=t.nodeRef.get(e);if(i===void 0)continue;let a=r.get(i);a&&(a.edges=n)}return n}function Sp(e,t){return t.portRef.get(e)??(e.getNode()?t.nodeRef.get(e.getNode())??String(e.getNode().id):`?`)}function Cp(t,n,r=/* @__PURE__ */ new Map,i=!0){let a=n?.layoutOptions?.[`org.eclipse.elk.algorithm`]??n?.layoutOptions?.[`elk.algorithm`]??t.layoutOptions?.[`org.eclipse.elk.algorithm`]??t.layoutOptions?.[`elk.algorithm`];a!==void 0&&String(a).trim()!==``&&r.set(t.id,e.f(String(a)));for(let e of t.children??[])Cp(e,void 0,r,!1);return r}function wp(t,n,r){let i=/* @__PURE__ */ new Map,a=e=>{i.set(e.id,e);for(let t of e.children??[])a(t)};a(t);let o=/* @__PURE__ */ new Map,c=(e,t)=>{o.set(e.id,t);for(let n of e.children??[])c(n,t+1)};c(t,0);let l=[...n.entries()].filter(([,t])=>e.t.has(t)||e.r.has(t)||e.s.has(t)||e.l.has(t)||e.c.has(t)||e.o.has(t)||e.u.has(t)||e.n.has(t)||e.a.has(t)).sort((e,t)=>(o.get(t[0])??0)-(o.get(e[0])??0));for(let[e,t]of l){let n=i.get(e);if(n===void 0||(n.children?.length??0)===0)continue;let a=s(t);if(a===void 0)throw Error(`[layout] 布局算法 '${t}' 未注册 (本入口未包含该算法; 非 layered 算法请用完整入口 src/index.ts)`);a(n),r?.(n)===!0&&a(n)}}function Tp(e,t){if(t.size===0)return;let n=(e,t)=>e.id===t?e:(e.children??[]).map(e=>n(e,t)).find(Boolean)??null,r=[],i=e=>{for(let t of e.edges??[])r.push({e:t,holder:e});for(let t of e.children??[])i(t)};i(e);let a=/* @__PURE__ */ new Map;for(let r of t){let t=n(e,r);if(t===null)continue;let i=/* @__PURE__ */ new Set,o=e=>{i.add(e.id);for(let t of e.children??[])o(t)};o(t),a.set(r,i)}let o=[...a.entries()].sort((e,t)=>t[0].length-e[0].length),s=e=>{if(c.has(e))return e;let t=e.lastIndexOf(`.`);return t!==-1&&c.has(e.slice(0,t))?e.slice(0,t):null},c=/* @__PURE__ */ new Set;for(let e of a.values())for(let t of e)c.add(t);for(let{e:t,holder:i}of r){let r=String(t.sources?.[0]??``),a=String(t.targets?.[0]??``),c=s(r),l=s(a);if(c!==null&&l!==null)for(let[r,a]of o){if(!a.has(c)||!a.has(l))continue;let o=n(e,r);if(o!==null){o.edges??=[],o.edges.push(t);let e=(i.edges??[]).indexOf(t);e!==-1&&i.edges.splice(e,1)}break}}}function Ep(e,t){let n=e=>e.id===t?e:(e.children??[]).map(n).find(Boolean)??null;return(n(e)?.children?.length??0)>0}function Dp(t,n){let r=n?.control,i=typeof t?.id==`string`?t.id:void 0;vp(r,`validate`,1,i),gp(t),vp(r,`clone`,2,i);let a=_p(t);vp(r,`dispatch`,3,i);let o=Cp(a,n);for(let[t,n]of o)if(!e.t.has(n)&&!e.i.has(n)&&!e.r.has(n)&&!e.s.has(n)&&!e.l.has(n)&&!e.c.has(n)&&!e.o.has(n)&&!e.u.has(n)&&!e.n.has(n)&&!e.a.has(n))throw new ap(`UNSUPPORTED_ALGORITHM`,`nodes.${t}`,`布局算法 '${n}' 尚未移植 (节点 ${t}); 移植清单见 docs/NON-LAYERED-PORTING.md`,{phase:`dispatch`});let s=new Set([...o.entries()].filter(([,t])=>e.t.has(t)||e.r.has(t)||e.s.has(t)||e.l.has(t)||e.c.has(t)||e.o.has(t)||e.u.has(t)||e.n.has(t)||e.a.has(t)).map(([e])=>e).filter(e=>Ep(a,e)));s.size>0&&(Tp(a,s),wp(a,o,n?.onBlackBoxLaidOut));let c=o.get(a.id);if(c!==void 0&&!e.i.has(c)){let e=new Set([...s].filter(e=>e!==a.id));return e.size>0&&(Tp(a,e),wp(a,new Map([...o.entries()].filter(([e])=>e!==a.id)),n?.onBlackBoxLaidOut)),wp(a,/* @__PURE__ */ new Map([[a.id,c]]),n?.onBlackBoxLaidOut),Fp(a,Pp(a,n),a),Op(a),vp(r,`extract`,4,i),vp(r,`format`,5,i),kp(a,n)}let l=yp(a,n,s);new Rf().layout(l.graph),vp(r,`extract`,4,i);let u=xp(l.graph,l);return Op(u,l.graph),s.size>0&&Ip(u,a,s),Fp(u,Pp(a,n),a),vp(r,`format`,5,i),kp(u,n)}function Op(e,t){e.x??=0,e.y??=0,e.width===void 0&&(e.width=t?.getActualSize().x??0),e.height===void 0&&(e.height=t?.getActualSize().y??0)}function kp(e,t){let n=t?.responseFormat??`full`;return n===`summary`?Mp(e):n===`concise`?Ap(e):t?.pick===void 0?e:jp(e,t.pick)}function Ap(e){let t={id:e.id,x:e.x,y:e.y,width:e.width,height:e.height};return e.children!==void 0&&(t.children=e.children.map(Ap)),e.edges!==void 0&&(t.edges=e.edges.flatMap(e=>{let t=e.sections?.[0],n={...e.id===void 0?{}:{id:e.id},sources:[...e.sources],targets:[...e.targets]};return t!==void 0&&(n.sections=[{startPoint:{...t.startPoint},endPoint:{...t.endPoint}}]),[n]})),t}function jp(e,t){let n={id:e.id,x:e.x,y:e.y,width:e.width,height:e.height};for(let r of t)r in e&&r!==`children`&&r!==`edges`&&r!==`id`&&r!==`x`&&r!==`y`&&r!==`width`&&r!==`height`&&(n[r]=e[r]);return e.children!==void 0&&(n.children=e.children.map(e=>jp(e,t))),e.edges!==void 0&&(n.edges=e.edges),n}function Mp(e){let t=[],n=[],r=(e,i)=>{i&&t.push({id:e.id,x:e.x,y:e.y,width:e.width,height:e.height});for(let t of e.edges??[]){let e=t.sections?.[0],r=t.sources[0],i=t.targets[0];e!==void 0&&r!==void 0&&i!==void 0&&n.push({...t.id===void 0?{}:{id:t.id},sources:[r],targets:[i],startPoint:{...e.startPoint},endPoint:{...e.endPoint}})}for(let t of e.children??[])r(t,!0)};r(e,!1);let i={nodes:t,edges:n};return typeof e.width==`number`&&(i.width=e.width),typeof e.height==`number`&&(i.height=e.height),i}function Np(e){return e===`shapeCoords`||e.endsWith(`json.shapeCoords`)?`org.eclipse.elk.json.shapeCoords`:e===`edgeCoords`||e.endsWith(`json.edgeCoords`)?`org.eclipse.elk.json.edgeCoords`:e.startsWith(`org.eclipse.elk.`)?e:e.replace(/^elk\./,`org.eclipse.elk.`)}function Pp(e,t){let n=e=>{let t={};for(let[n,r]of Object.entries(e??{}))t[Np(n)]=r;return t},r=n(e.layoutOptions);for(let[e,i]of Object.entries(n(t?.layoutOptions)))r[e]=i;let i=e=>{let t=n(e)[`org.eclipse.elk.json.shapeCoords`];return t===`ROOT`||t===`PARENT`||t===`INHERIT`?t:void 0},a=e=>{let t=n(e)[`org.eclipse.elk.json.edgeCoords`];return t===`ROOT`||t===`PARENT`||t===`CONTAINER`||t===`INHERIT`?t:void 0},o=r[`org.eclipse.elk.json.shapeCoords`],s=r[`org.eclipse.elk.json.edgeCoords`],c=o===`ROOT`||o===`PARENT`?o:`PARENT`,l=s===`ROOT`||s===`PARENT`||s===`CONTAINER`?s:`CONTAINER`,u=/* @__PURE__ */ new Map,d=/* @__PURE__ */ new Map,f=(e,t,n,r)=>{let o=i(e.layoutOptions),s=a(e.layoutOptions),c=o===void 0||o===`INHERIT`?t:o,l=s===void 0||s===`INHERIT`?n:s;r||(u.set(e.id,c),d.set(e.id,l));for(let t of e.children??[])f(t,c,l,!1)};return f(e,c,l,!0),{rootShape:c,rootEdge:l,nodeShape:u,nodeEdge:d}}function Fp(e,t,n){let r=/* @__PURE__ */ new Map,i=(e,t,n)=>{let a=t+(e.x??0),o=n+(e.y??0);r.set(e.id,{x:a,y:o});for(let t of e.children??[])i(t,a,o)};i(e,0,0);let a=n=>n.id===e.id?t.rootShape:t.nodeShape.get(n.id)??`PARENT`,o=(t,n)=>{if(t.id!==e.id&&n===`ROOT`){let e=r.get(t.id);e&&(t.x=e.x,t.y=e.y)}let i=a(t);for(let e of t.children??[])o(e,i)};o(e,t.rootShape);let s=/* @__PURE__ */ new Map,c=(e,t)=>{for(let n of e.edges??[]){let e=`${String(n.sources?.[0]??``)}|${String(n.targets?.[0]??``)}`;s.has(e)||s.set(e,t)}for(let t of e.children??[])c(t,t.id)};c(n,null);let l=e=>{let n=s.get(e);return n===null?t.rootEdge:n===void 0?`CONTAINER`:t.nodeEdge.get(n)??`CONTAINER`},u=(e,t)=>{e&&(e.x+=t.x,e.y+=t.y)},d=t=>t.id===e.id?{x:0,y:0}:r.get(t.id)??{x:0,y:0},f=e=>{let t=d(e);for(let n of e.edges??[]){let e=`${String(n.sources?.[0]??``)}|${String(n.targets?.[0]??``)}`,i=l(e),a=null;if(i===`ROOT`)a=t;else if(i===`PARENT`){let n=s.get(e),i=n==null?{x:0,y:0}:r.get(n)??{x:0,y:0};a={x:t.x-i.x,y:t.y-i.y}}if(a!==null){for(let e of n.sections??[]){u(e.startPoint,a),u(e.endPoint,a);for(let t of e.bendPoints??[])u(t,a)}delete n.container}}for(let t of e.children??[])f(t)};f(e)}function Ip(e,t,n){let r=(e,t)=>{if(e.id===t)return e;for(let n of e.children??[]){let e=r(n,t);if(e!==null)return e}return null},i=e=>{if(n.has(e.id)){let n=r(t,e.id);if(n!==null){e.children=n.children,e.edges=n.edges;for(let t of e.edges??[])t.container=e.id;for(let t of e.children??[])i(t);return}}for(let t of e.children??[])i(t)};i(e)}Object.defineProperty(exports,"C",{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,"S",{enumerable:!0,get:function(){return d}}),Object.defineProperty(exports,"T",{enumerable:!0,get:function(){return i}}),Object.defineProperty(exports,"_",{enumerable:!0,get:function(){return w}}),Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return hp}}),Object.defineProperty(exports,"b",{enumerable:!0,get:function(){return f}}),Object.defineProperty(exports,"c",{enumerable:!0,get:function(){return Uf}}),Object.defineProperty(exports,"d",{enumerable:!0,get:function(){return mf}}),Object.defineProperty(exports,"f",{enumerable:!0,get:function(){return kf}}),Object.defineProperty(exports,"g",{enumerable:!0,get:function(){return Bi}}),Object.defineProperty(exports,"h",{enumerable:!0,get:function(){return xo}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return gp}}),Object.defineProperty(exports,"l",{enumerable:!0,get:function(){return Hf}}),Object.defineProperty(exports,"m",{enumerable:!0,get:function(){return yo}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return xp}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return ap}}),Object.defineProperty(exports,"p",{enumerable:!0,get:function(){return Af}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return Dp}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return ip}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return yp}}),Object.defineProperty(exports,"u",{enumerable:!0,get:function(){return Rf}}),Object.defineProperty(exports,"v",{enumerable:!0,get:function(){return m}}),Object.defineProperty(exports,"w",{enumerable:!0,get:function(){return o}}),Object.defineProperty(exports,"x",{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,"y",{enumerable:!0,get:function(){return p}});
1
+ /**
2
+ * ggn-layout — TypeScript port of the Eclipse Layout Kernel (ELK) layered layout algorithms.
3
+ *
4
+ * Copyright (c) 2026 GGN contributors.
5
+ * Portions derived from ELK (https://github.com/eclipse/elk), Copyright (c) Kiel University
6
+ * and others, are licensed under the Eclipse Public License 2.0 (EPL-2.0);
7
+ * GGN-original portions are licensed under MIT.
8
+ * See LICENSES/EPL-2.0.txt, LICENSE and THIRD_PARTY_NOTICES.md.
9
+ *
10
+ * SPDX-License-Identifier: (MIT AND EPL-2.0)
11
+ */
12
+ const e=require("./algorithms-X6GKNYEw.cjs"),t=25214903917n,n=(1n<<48n)-1n,r=15525485;var i=class{seed;constructor(e){this.seed=Number(e==null?(BigInt(Date.now()^Math.random()*4294967295)^t)&n:(BigInt(e)^t)&n)}next(e){let t=this.seed,n=t&16777215,i=Math.floor(t/16777216),a=n*r+11,o=Math.floor(a/16777216),s=i*r+n*1502+o;return this.seed=(s&16777215)*16777216+(a&16777215),Math.floor(this.seed/2**(48-e))}nextInt(e){if((e&-e)===e)return Math.floor(e*this.next(31)/2147483648);let t,n;do t=this.next(31),n=t%e;while(t-n+(e-1)<0);return n}nextBoolean(){return this.next(1)!==0}nextFloat(){return this.next(24)/16777216}nextLong(){let e=this.next(32),t=this.next(32),n=t>=2147483648?1n:0n,r=(BigInt(e)-n<<32n)+BigInt(t);return Number(r&281474976710655n)}nextDouble(){return(this.next(26)*134217728+this.next(27))/9007199254740992}setSeed(e){this.seed=Number((BigInt(e)^t)&n)}next31(){return this.next(31)}};const a=/* @__PURE__ */ new Map;function o(e,t){a.set(e,t)}function s(e){return a.get(e)}var c=class extends e.ii{constructor(){super(),this.setProperty(e.Gn,/* @__PURE__ */ new Set)}id=0;size={x:0,y:0};padding={left:12,top:12,right:12,bottom:12};offset={x:0,y:0};layerlessNodes=[];layers=[];parentNode=null;direction=`UNDEFINED`;getSize(){return this.size}getPadding(){return this.padding}setPadding(e){this.padding={...this.padding,...e}}getActualSize(){return{x:this.size.x+this.padding.left+this.padding.right,y:this.size.y+this.padding.top+this.padding.bottom}}getOffset(){return this.offset}getLayerlessNodes(){return this.layerlessNodes}getLayers(){return this.layers}getParentNode(){return this.parentNode}setParentNode(e){this.parentNode=e}getDirection(){return this.direction}setDirection(e){this.direction=e}toNodeArray(){return this.layers.map(e=>[...e.getNodes()])}getAllNodes(){let e=this.layerlessNodes.length;for(let t of this.layers)e+=t.getNodes().length;let t=Array(e),n=0;for(let e of this.layers)for(let r of e.getNodes())t[n++]=r;for(let e of this.layerlessNodes)t[n++]=e;return t}};let l=0;var u=class extends e.ii{id=l++;getId(){return this.id}},d=class extends u{position={x:0,y:0};size={x:0,y:0};getPosition(){return this.position}getSize(){return this.size}},f=class extends d{graph=null;layer=null;type=`NORMAL`;ports=[];labels=[];nestedGraph=null;margin={left:0,top:0,right:0,bottom:0};padding={left:0,top:0,right:0,bottom:0};layerConstraint=null;inLayerConstraint=null;edgeConstraint=null;portConstraints=null;constructor(e=null){super(),this.graph=e,e&&e.getLayerlessNodes().push(this)}getGraph(){return this.graph===null&&this.layer!==null?this.layer.getGraph():this.graph}setGraph(e){this.graph=e}getLayer(){return this.layer}setLayer(e){if(this.layer!==null){let e=this.layer.getNodes(),t=e.indexOf(this);t!==-1&&e.splice(t,1)}this.layer=e,this.layer!==null&&this.layer.getNodes().push(this)}setLayerAt(e,t){if(this.layer!==null){let e=this.layer.getNodes(),t=e.indexOf(this);t!==-1&&e.splice(t,1)}this.layer=t,t.getNodes().splice(e,0,this)}getType(){return this.type}setType(e){this.type=e}getPorts(e){if(e===void 0)return this.ports;if(typeof e==`string`&&(e===`NORTH`||e===`EAST`||e===`SOUTH`||e===`WEST`))return this.ports.filter(t=>t.getSide()===e);let t=e;return t===`INPUT`?this.ports.filter(e=>e.getIncomingEdges().length>0):t===`OUTPUT`?this.ports.filter(e=>e.getOutgoingEdges().length>0):[]}getPortSideView(e){return this.ports.filter(t=>t.getSide()===e)}setPorts(e){this.ports=e}getLabels(){return this.labels}setLabels(e){this.labels=e}getNestedGraph(){return this.nestedGraph}setNestedGraph(e){this.nestedGraph=e}getMargin(){return this.margin}getPadding(){return this.padding}getLayerConstraint(){if(this.layerConstraint!==null)return this.layerConstraint;let t=this.getProperty(`org.eclipse.elk.layered.layering.layerConstraint`);if(typeof t==`string`){let n=e.Fr[t];if(n!==void 0)return n}return null}setLayerConstraint(e){this.layerConstraint=e,this.setProperty(`org.eclipse.elk.layered.layering.layerConstraint`,e)}getInLayerConstraint(){return this.inLayerConstraint}setInLayerConstraint(e){this.inLayerConstraint=e}getEdgeConstraint(){return this.edgeConstraint}setEdgeConstraint(e){this.edgeConstraint=e}getPortConstraints(){return this.portConstraints}setPortConstraints(e){this.portConstraints=e}getIndex(){return this.layer===null?-1:this.layer.getNodes().indexOf(this)}getOutgoingEdges(){let e=0;for(let t of this.ports)e+=t.getOutgoingEdges().length;let t=Array(e),n=0;for(let e of this.ports)for(let r of e.getOutgoingEdges())t[n++]=r;return t}getIncomingEdges(){let e=0;for(let t of this.ports)e+=t.getIncomingEdges().length;let t=Array(e),n=0;for(let e of this.ports)for(let r of e.getIncomingEdges())t[n++]=r;return t}getConnectedEdges(){let e=[];for(let t of this.ports)e.push(...t.getIncomingEdges(),...t.getOutgoingEdges());return e}},p=class extends d{owner=null;side=`UNDEFINED`;explicitSide=!1;anchor={x:0,y:0};explicitlySuppliedPortAnchor=!1;incomingEdges=[];outgoingEdges=[];margin={left:0,top:0,right:0,bottom:0};labels=[];getNode(){return this.owner}setNode(e){if(this.owner!==null){let e=this.owner.getPorts(),t=e.indexOf(this);t!==-1&&e.splice(t,1)}this.owner=e,this.owner!==null&&this.owner.getPorts().push(this)}getSide(){return this.side}setSide(e){this.applySideAndAnchor(e),this.explicitSide=!0}setSideInferred(e){this.applySideAndAnchor(e)}isExplicitSide(){return this.explicitSide}applySideAndAnchor(e){if(this.side=e,!this.explicitlySuppliedPortAnchor)switch(this.side){case`NORTH`:this.anchor.x=this.size.x/2,this.anchor.y=0;break;case`EAST`:this.anchor.x=this.size.x,this.anchor.y=this.size.y/2;break;case`SOUTH`:this.anchor.x=this.size.x/2,this.anchor.y=this.size.y;break;case`WEST`:this.anchor.x=0,this.anchor.y=this.size.y/2}}getAnchor(){return this.anchor}setAnchor(e){this.anchor.x=e.x,this.anchor.y=e.y}isExplicitlySuppliedPortAnchor(){return this.explicitlySuppliedPortAnchor}setExplicitlySuppliedPortAnchor(e){this.explicitlySuppliedPortAnchor=e}getAbsoluteAnchor(){let e=this.owner;return{x:e.position.x+this.position.x+this.anchor.x,y:e.position.y+this.position.y+this.anchor.y}}getIncomingEdges(){return this.incomingEdges}getOutgoingEdges(){return this.outgoingEdges}getConnectedEdges(){return[...this.incomingEdges,...this.outgoingEdges]}getConnectedPorts(){let e=[];for(let t of this.getConnectedEdges())e.push(this.otherEnd(t));return e}getPredecessorPorts(){return this.incomingEdges.map(e=>e.getSource()).filter(Boolean)}getSuccessorPorts(){return this.outgoingEdges.map(e=>e.getTarget()).filter(Boolean)}otherEnd(e){return e.getSource()===this?e.getTarget():e.getSource()}getDegree(){return this.incomingEdges.length+this.outgoingEdges.length}getNetFlow(){return this.incomingEdges.length-this.outgoingEdges.length}getMargin(){return this.margin}getLabels(){return this.labels}setLabels(e){this.labels=e}getIndex(){return this.owner===null?-1:this.owner.getPorts().indexOf(this)}},m=class extends u{source=null;target=null;bendPoints=[];labels=[];getSource(){return this.source}setSource(e){if(this.source!==null){let e=this.source.getOutgoingEdges(),t=e.indexOf(this);t!==-1&&e.splice(t,1)}this.source=e,this.source!==null&&this.source.getOutgoingEdges().push(this)}getTarget(){return this.target}setTarget(e){if(this.target!==null){let e=this.target.getIncomingEdges(),t=e.indexOf(this);t!==-1&&e.splice(t,1)}this.target=e,this.target!==null&&this.target.getIncomingEdges().push(this)}setTargetAndInsertAtIndex(e,t){if(this.target!==null){let e=this.target.getIncomingEdges(),t=e.indexOf(this);t!==-1&&e.splice(t,1)}this.target=e,this.target!==null&&this.target.getIncomingEdges().splice(t,0,this)}getBendPoints(){return this.bendPoints}getLabels(){return this.labels}isSelfLoop(){return this.source!==null&&this.target!==null&&this.source.getNode()!==null&&this.source.getNode()===this.target.getNode()}isInLayerEdge(){return this.source!==null&&this.target!==null&&!this.isSelfLoop()&&this.source.getNode().getLayer()===this.target.getNode().getLayer()}getOther(e){return this.source===e?this.target:this.target===e?this.source:null}getOtherNode(e){return this.source!==null&&this.source.getNode()===e?this.target?.getNode()??null:this.target!==null&&this.target.getNode()===e?this.source?.getNode()??null:null}reverse(t,n){this.setProperty(e.Sr,!this.getProperty(e.Sr));let r=this.source,i=this.target;this.setSource(i),this.setTarget(r),this.bendPoints.reverse();for(let e of this.labels)e.placement===`HEAD`?e.placement=`TAIL`:e.placement===`TAIL`&&(e.placement=`HEAD`)}},h=class{indeg=[];outdeg=[];mark=[];sources=[];sinks=[];random=null;process(t,n){n.begin(`Greedy cycle removal`,1);let r=t.getLayerlessNodes(),i=r.length;this.indeg=Array(i).fill(0),this.outdeg=Array(i).fill(0),this.mark=Array(i).fill(0);let a=0;for(let n of r){n.setGraph(t),n.id=a;for(let t of n.getPorts()){for(let r of t.getIncomingEdges()){if(r.getSource()!==null&&r.getSource().getNode()===n)continue;let t=r.getProperty(e.Ut);this.indeg[a]+=t>0?t+1:1}for(let r of t.getOutgoingEdges()){if(r.getTarget()!==null&&r.getTarget().getNode()===n)continue;let t=r.getProperty(e.Ut);this.outdeg[a]+=t>0?t+1:1}}this.outdeg[a]===0?this.sinks.push(n):this.indeg[a]===0&&this.sources.push(n),a++}let o=-1,s=1,c=[];for(this.random=t.getProperty(e.br);i>0;){for(;this.sinks.length>0;){let e=this.sinks.shift();this.mark[r.indexOf(e)]=o--,this.updateNeighbors(e,r),i--}for(;this.sources.length>0;){let e=this.sources.shift();this.mark[r.indexOf(e)]=s++,this.updateNeighbors(e,r),i--}if(i>0){let e=-(2**53-1);for(let t=0;t<r.length;t++)if(this.mark[t]===0){let n=this.outdeg[t]-this.indeg[t];n>=e&&(n>e&&(c.length=0,e=n),c.push(r[t]))}let t=this.chooseNodeWithMaxOutflow(c);this.mark[r.indexOf(t)]=s++,this.updateNeighbors(t,r),i--}}let l=r.length+1;for(let e=0;e<r.length;e++)this.mark[e]<0&&(this.mark[e]+=l);for(let n of r)for(let i of[...n.getPorts()])for(let a of[...i.getOutgoingEdges()]){let i=r.indexOf(a.getTarget().getNode());this.mark[r.indexOf(n)]>this.mark[i]&&(a.reverse(t,!0),t.setProperty(e.Ln,!0))}this.dispose(),n.done()}chooseNodeWithMaxOutflow(e){return e[this.random.nextInt(e.length)]}updateNeighbors(t,n){for(let r of t.getPorts())for(let i of r.getConnectedEdges()){let a=i.getSource()===r?i.getTarget():i.getSource();if(a===null)continue;let o=a.getNode();if(o===null||t===o)continue;let s=i.getProperty(e.Ut),c=s<0?0:s,l=n.indexOf(o);this.mark[l]===0&&(i.getTarget()===a?(this.indeg[l]-=c+1,this.indeg[l]<=0&&this.outdeg[l]>0&&this.sources.push(o)):(this.outdeg[l]-=c+1,this.outdeg[l]<=0&&this.indeg[l]>0&&this.sinks.push(o)))}}dispose(){this.indeg=[],this.outdeg=[],this.mark=[],this.sources=[],this.sinks=[]}};function g(t){let n=t.getGraph()?.getProperty(e.tt),r=t.getPosition();return n===`TOP_LEFT`?{x:r.x,y:r.y}:{x:r.x+t.getSize().x/2,y:r.y+t.getSize().y/2}}function _(e){let t=[];for(let n of e.getLayerlessNodes()){n.id=1;let e=g(n).x;for(let r of n.getPorts(`OUTPUT`))for(let i of r.getOutgoingEdges()){let r=i.getTarget()?.getNode();r!=null&&r!==n&&g(r).x<e&&t.push(i)}}for(let n of t)n.reverse(e,!0);t.length=0;for(let n of e.getLayerlessNodes())n.id>0&&v(n,t,e);for(let n of t)n.reverse(e,!0)}function v(e,t,n){e.id=-1;for(let r of e.getPorts(`OUTPUT`))for(let i of r.getOutgoingEdges()){let r=i.getTarget()?.getNode();r!=null&&e!==r&&(r.id<0?t.push(i):r.id>0&&v(r,t,n))}e.id=0}var y=class{firstSeparateNodes=0;lastSeparateNodes=0;computeConstraintModelOrder(t,n){let r=0;switch(t.getProperty(e.it)){case`FIRST_SEPARATE`:r=2*-n+this.firstSeparateNodes,this.firstSeparateNodes++;break;case`FIRST`:r=-n;break;case`LAST`:r=n;break;case`LAST_SEPARATE`:r=2*n+this.lastSeparateNodes,this.lastSeparateNodes++}return t.hasProperty(e.cr)&&(r+=t.getProperty(e.cr)),r}computeConstraintGroupModelOrder(t,n,r){let i=0;switch(t.getProperty(e.it)){case`FIRST_SEPARATE`:i=2*-n+this.firstSeparateNodes,this.firstSeparateNodes++;break;case`FIRST`:i=-n;break;case`LAST`:i=n;break;case`LAST_SEPARATE`:i=2*n+this.lastSeparateNodes,this.lastSeparateNodes++}if(t.hasProperty(e.cr)){let n=t.getProperty(e.w);if(n==null)throw TypeError(`Cannot invoke "java.lang.Integer.intValue()" because the return value of "org.eclipse.elk.alg.layered.graph.LGraph.getProperty(org.eclipse.elk.graph.properties.IProperty)" is null`);i+=n*r+t.getProperty(e.cr)}return i}resetInternalCounters(){this.firstSeparateNodes=0,this.lastSeparateNodes=0}};function b(t,n){n.begin(`Model order cycle breaking`,1);let r=[];if(!t.hasProperty(e.sr))throw TypeError(`NullPointerException: Cannot invoke "java.lang.Integer.intValue()" because the return value of "org.eclipse.elk.alg.layered.graph.LGraph.getProperty(org.eclipse.elk.graph.properties.IProperty)" is null`);let i=Math.max(t.getLayerlessNodes().length,t.getProperty(e.sr)),a=i*t.getProperty(e.jn),o=t.getProperty(e.b)===`ENFORCED`;for(let e of t.getLayerlessNodes()){let t=new y,n=o?t.computeConstraintGroupModelOrder(e,a,i):t.computeConstraintModelOrder(e,i);for(let s of e.getPorts(`OUTPUT`))for(let e of s.getOutgoingEdges()){let s=e.getTarget().getNode();(o?t.computeConstraintGroupModelOrder(s,a,i):t.computeConstraintModelOrder(s,i))<n&&r.push(e)}}for(let n of r)n.reverse(t,!0),t.setProperty(e.Ln,!0);n.done()}var x=class extends h{layeredGraph;process(e,t){this.layeredGraph=e,super.process(e,t)}chooseNodeWithMaxOutflow(t){let n=null,r=2**53-1,i=Math.max(this.layeredGraph.getLayerlessNodes().length,this.layeredGraph.getProperty(e.sr)),a=i*this.layeredGraph.getProperty(e.jn),o=new y,s=this.layeredGraph.getProperty(e.b)===`ENFORCED`;for(let c of t)if(c.hasProperty(e.cr)){let e=s?o.computeConstraintGroupModelOrder(c,a,i):o.computeConstraintModelOrder(c,i);r>e&&(r=e,n=c)}return n===null?t[this.layeredGraph.getProperty(e.br).nextInt(t.length)]:n}},S=class{process(e){let t=this.handleOuterNodes(e);this.handleInnerNodes(e,t)}handleOuterNodes(e){let t=[];for(let n of e.getLayerlessNodes())this.handleLayerConstraintNode(e,n)||t.push(n);return t}handleInnerNodes(t,n){for(let r of n)if(this.handleLayerConstraintNode(t,r),e.Lr.isSideFixed(r.getProperty(e.Lt))&&r.getPorts().length>0){let e=!0;for(let t of r.getPorts()){let n=t.getSide(),r=t.getNetFlow();if(!(n===`EAST`&&r>0||n===`WEST`&&r<0)){e=!1;break}for(let n of t.getOutgoingEdges()){let t=n.getTarget()?.getNode()?.getLayerConstraint();if(t===`LAST`||t===`LAST_SEPARATE`){e=!1;break}}if(!e)break;for(let n of t.getIncomingEdges()){let t=n.getSource()?.getNode()?.getLayerConstraint();if(t===`FIRST`||t===`FIRST_SEPARATE`){e=!1;break}}if(!e)break}e&&this.reverseEdges(t,r,`NONE`,`UNDEFINED`)}}handleLayerConstraintNode(t,n){let r=n.getLayerConstraint(),i=null;switch(r){case`FIRST`:case`FIRST_SEPARATE`:i=`OUTGOING_ONLY`;break;case`LAST`:case`LAST_SEPARATE`:i=`INCOMING_ONLY`}return i!==null&&(n.setProperty(e.L,`OUTGOING_ONLY`),i===`INCOMING_ONLY`?this.reverseEdges(t,n,r,`INPUT`):this.reverseEdges(t,n,r,`OUTPUT`),!0)}reverseEdges(e,t,n,r){for(let i of[...t.getPorts()]){if(r===`INPUT`||r===`UNDEFINED`)for(let t of[...i.getOutgoingEdges()])this.canReverseOutgoingEdge(n,t)&&t.reverse(e,!0);if(r===`OUTPUT`||r===`UNDEFINED`)for(let t of[...i.getIncomingEdges()])this.canReverseIncomingEdge(n,t)&&t.reverse(e,!0)}}canReverseOutgoingEdge(t,n){if(n.getProperty(e.Sr))return!1;let r=n.getTarget()?.getNode();return!(r==null||t===`LAST`&&r.getType()===`LABEL`||r.getLayerConstraint()===`LAST_SEPARATE`)}canReverseIncomingEdge(t,n){if(n.getProperty(e.Sr))return!1;let r=n.getSource()?.getNode();return!(r==null||t===`FIRST`&&r.getType()===`LABEL`||r.getLayerConstraint()===`FIRST_SEPARATE`)}},C=class{process(e){this.identifyHyperedges(e);for(let t of e.getLayers()){let e=t.getNodes();if(e.length===0)continue;let n=null,r=null;for(let t=0;t<e.length;t++){let i=e[t],a=i.getType();if(a===`LONG_EDGE`&&r===`LONG_EDGE`&&n!==null){let r=this.checkMergeAllowed(i,n);if(r.allowMerge){this.mergeNodes(i,n,r.sameSource,r.sameTarget),e.splice(t,1),t--;continue}}n=i,r=a}}}checkMergeAllowed(t,n){let r=t.getProperty(e.nr),i=n.getProperty(e.nr),a=t.getProperty(e.rr),o=n.getProperty(e.rr),s=t.getProperty(e.ir),c=n.getProperty(e.ir),l=a!=null&&a===o,u=s!=null&&s===c;if(!r&&!i)return{allowMerge:t.getPorts()[0]?.id===n.getPorts()[0]?.id,sameSource:l,sameTarget:u};let d=(!r||t.getProperty(e.tr))&&(!i||n.getProperty(e.tr)),f=(!r||!t.getProperty(e.tr))&&(!i||!n.getProperty(e.tr));return{allowMerge:l&&d||u&&f,sameSource:l,sameTarget:u}}mergeNodes(t,n,r,i){let a=n.getPorts(`WEST`)[0],o=n.getPorts(`EAST`)[0];for(let e of t.getPorts()){for(;e.getIncomingEdges().length>0;)e.getIncomingEdges()[0].setTarget(a);for(;e.getOutgoingEdges().length>0;)e.getOutgoingEdges()[0].setSource(o)}r||n.setProperty(e.rr,null),i||n.setProperty(e.ir,null)}identifyHyperedges(e){let t=[];for(let n of e.getLayers())for(let e of n.getNodes())t.push(...e.getPorts());for(let e of t)e.id=-1;let n=0;for(let e of t)e.id===-1&&this.dfs(e,n++)}dfs(e,t){e.id=t;for(let n of e.getConnectedPorts())n.id===-1&&this.dfs(n,t);if(e.getNode().getType()===`LONG_EDGE`)for(let n of e.getNode().getPorts())n!==e&&n.id===-1&&this.dfs(n,t)}},w=class{id=0;owner=null;size={x:0,y:0};nodes=[];constructor(e=null){this.owner=e}getGraph(){return this.owner}getSize(){return this.size}getNodes(){return this.nodes}getIndex(){return this.owner===null?-1:this.owner.getLayers().indexOf(this)}},ee=class{id=0;internalId=0;origin=null;type=``;layer=0;outgoingEdges=[];incomingEdges=[];allEdgesCache=null;treeNode=!1;unknownCutvalues=[];getOutgoingEdges(){return this.outgoingEdges}getIncomingEdges(){return this.incomingEdges}getConnectedEdges(){return this.allEdgesCache===null&&(this.allEdgesCache=[...this.incomingEdges,...this.outgoingEdges]),this.allEdgesCache}invalidateConnectedEdges(){this.allEdgesCache=null}},te=class{node;constructor(){this.node=new ee}id(e){return this.node.id=e,this}origin(e){return this.node.origin=e,this}type(e){return this.node.type=e,this}create(e){return e.nodes.push(this.node),this.node}};function T(){return new te}var E=class{id=0;internalId=0;origin=null;source;target;weight=0;delta=1;treeEdge=!1;getSource(){return this.source}getTarget(){return this.target}getOther(e){if(e===this.source)return this.target;if(e===this.target)return this.source;throw Error(`Node not part of edge`)}reverse(){let e=this.source;this.source=this.target,this.target=e;let t=this.target.getOutgoingEdges(),n=t.indexOf(this);n!==-1&&t.splice(n,1),this.target.getIncomingEdges().push(this);let r=this.source.getIncomingEdges(),i=r.indexOf(this);return i!==-1&&r.splice(i,1),this.source.getOutgoingEdges().push(this),this.source.invalidateConnectedEdges(),this.target.invalidateConnectedEdges(),this}},ne=class{edge;constructor(){this.edge=new E}id(e){return this.edge.id=e,this}origin(e){return this.edge.origin=e,this}weight(e){return this.edge.weight=e,this}delta(e){return this.edge.delta=e,this}source(e){return this.edge.source=e,this}target(e){return this.edge.target=e,this}create(){if(this.edge.source===void 0||this.edge.target===void 0)throw Error(`NEdge must have a source and target NNode specified.`);if(this.edge.source===this.edge.target)throw Error(`Network simplex does not support self-loops`);return this.edge.source.getOutgoingEdges().push(this.edge),this.edge.target.getIncomingEdges().push(this.edge),this.edge.source.invalidateConnectedEdges(),this.edge.target.invalidateConnectedEdges(),this.edge}};function D(){return new ne}var re=class{nodes=[];addNode(e){let t=new ee;return t.origin=e,this.nodes.push(t),t}addEdge(e,t,n,r,i){if(r===i)throw Error(`Network simplex does not support self-loops`);let a=new E;return a.origin=e,a.weight=t,a.delta=n,a.source=r,a.target=i,a.source.getOutgoingEdges().push(a),a.target.getIncomingEdges().push(a),a.source.invalidateConnectedEdges(),a.target.invalidateConnectedEdges(),a}createArtificialRootAndConnect(e){let t=T().create(this);for(let n of e)D().delta(0).weight(0).source(t).target(n).create();return t}findConCompRepresentatives(){let e=[],t=Array(this.nodes.length).fill(!1);for(let n of this.nodes)t[n.internalId]||(e.push(n),this.dfs(n,t));return e}dfs(e,t){if(!t[e.internalId]){t[e.internalId]=!0;for(let n of e.getConnectedEdges())this.dfs(n.getOther(e),t)}}makeConnected(){let e=0;for(let t of this.nodes)t.internalId=e++;let t=this.findConCompRepresentatives(),n=null;return t.length>1&&(n=this.createArtificialRootAndConnect(t)),n}isAcyclic(){let e=0;for(let t of this.nodes)t.internalId=e++;let t=Array(this.nodes.length).fill(0),n=Array(this.nodes.length).fill(0);for(let e of this.nodes)t[e.internalId]+=e.getIncomingEdges().length;let r=[];for(let e of this.nodes)e.getIncomingEdges().length===0&&r.push(e);if(r.length===0&&this.nodes.length>0)return!1;for(;r.length>0;){let e=r.shift();for(let i of e.getOutgoingEdges()){let a=i.getTarget();n[a.internalId]=Math.max(n[a.internalId],n[e.internalId]+1),t[a.internalId]--,t[a.internalId]===0&&r.push(a)}}for(let e of this.nodes)for(let t of e.getOutgoingEdges())if(n[t.target.internalId]<=n[t.source.internalId])return!1;return!0}},ie=class e{graph;edges=[];treeEdges=/* @__PURE__ */ new Set;sources=[];edgeVisited=/* @__PURE__ */ new Uint8Array;postOrder=0;poID=[];lowestPoID=[];cutvalue=[];cutvalueLeafs=[];subtreeNodes=[];subtreeEdges=[];incidentCounts=[];topologicalRoots=[];spanIn=0;spanOut=0;previousLayeringNodeCounts=null;doBalance=!1;iterationLimit=2**53-1;constructor(){}static forGraph(t){let n=new e;return n.graph=t,n}prepare(e){return this.graph=e,this}withBalancing(e){return this.doBalance=e,this}withPreviousLayering(e){return this.previousLayeringNodeCounts=e,this}withIterationLimit(e){return this.iterationLimit=e,this}execute(){this.executeInternal(null)}executeWithMonitor(e){e.begin(`Network simplex`,1),this.executeInternal(e),e.done()}executeInternal(e){if(this.graph.nodes.length<1)return;for(let e of this.graph.nodes)e.layer=0;let t=this.graph.nodes.length>=40;t&&this.removeSubtrees(),this.initialize(),this.feasibleTree();let n=this.leaveEdge(),r=0;for(;n!==null&&r<this.iterationLimit;)this.exchange(n,this.enterEdge(n)),n=this.leaveEdge(),r++;t&&this.reattachSubtrees(),this.doBalance?this.balance(this.normalize()):this.normalize()}removeSubtrees(){this.subtreeNodes.length=0,this.subtreeEdges.length=0;let e=[];for(let t of this.graph.nodes)t.getConnectedEdges().length===1&&e.push(t);let t=0;for(;t<e.length;){let n=e[t++];if(n.getConnectedEdges().length===0)continue;let r=n.getConnectedEdges()[0],i=n.getOutgoingEdges().length>0,a=r.getOther(n);if(i){let e=a.getIncomingEdges().indexOf(r);e!==-1&&a.getIncomingEdges().splice(e,1)}else{let e=a.getOutgoingEdges().indexOf(r);e!==-1&&a.getOutgoingEdges().splice(e,1)}a.invalidateConnectedEdges(),a.getConnectedEdges().length===1&&e.push(a),this.subtreeNodes.push(n),this.subtreeEdges.push(r);let o=this.graph.nodes.indexOf(n);o!==-1&&this.graph.nodes.splice(o,1)}}reattachSubtrees(){for(;this.subtreeNodes.length>0;){let e=this.subtreeNodes.pop(),t=this.subtreeEdges.pop(),n=t.getOther(e);t.target===e?(n.getOutgoingEdges().push(t),e.layer=n.layer+t.delta):(n.getIncomingEdges().push(t),e.layer=n.layer-t.delta),n.invalidateConnectedEdges(),this.graph.nodes.push(e)}}initialize(){let e=this.graph.nodes.length;for(let e of this.graph.nodes)e.treeNode=!1;this.poID.length<e?this.poID=Array(e).fill(0):this.poID.fill(0),this.lowestPoID.length<e?this.lowestPoID=Array(e).fill(0):this.lowestPoID.fill(0),this.sources.length=0;let t=0;this.edges.length=0;for(let e of this.graph.nodes){e.internalId=t++,e.getIncomingEdges().length===0&&this.sources.push(e);let n=e.getOutgoingEdges();for(let e=0;e<n.length;e++)this.edges.push(n[e])}let n=0;for(let e of this.edges)e.internalId=n++,e.treeEdge=!1;let r=this.edges.length;this.cutvalue.length<r&&(this.cutvalue=Array(r).fill(0)),this.edgeVisited.length<r&&(this.edgeVisited=new Uint8Array(r)),this.edgeVisited.fill(0),this.treeEdges=/* @__PURE__ */ new Set,this.postOrder=1}feasibleTree(){if(this.layeringTopologicalNumbering(this.sources),this.edges.length>0){for(this.edgeVisited.fill(0);this.tightTreeDFS(this.graph.nodes[0])<this.graph.nodes.length;){let e=this.minimalSlack(),t=e.getTarget().layer-e.getSource().layer-e.delta;e.getTarget().treeNode&&(t=-t);for(let e of this.graph.nodes)e.treeNode&&(e.layer+=t);this.edgeVisited.fill(0)}this.edgeVisited.fill(0),this.postorderTraversal(this.graph.nodes[0]),this.cutvalues()}}layeringTopologicalNumbering(e){let t=this.graph.nodes.length;this.incidentCounts.length<t?this.incidentCounts=Array(t).fill(0):this.incidentCounts.fill(0);let n=this.incidentCounts;for(let e of this.graph.nodes)n[e.internalId]+=e.getIncomingEdges().length;this.topologicalRoots.length=0;let r=this.topologicalRoots;for(let t=0;t<e.length;t++)r.push(e[t]);let i=0;for(;i<r.length;){let e=r[i++];for(let t of e.getOutgoingEdges()){let i=t.getTarget();i.layer=Math.max(i.layer,e.layer+t.delta),n[i.internalId]--,n[i.internalId]===0&&r.push(i)}}}minimalSpan(e){let t=2**53-1,n=2**53-1,r,i=e.getIncomingEdges();for(let a=0;a<i.length;a++){let o=i[a];r=o.getTarget().layer-o.getSource().layer,o.getTarget()===e&&r<n?n=r:r<t&&(t=r)}let a=e.getOutgoingEdges();for(let i=0;i<a.length;i++){let o=a[i];r=o.getTarget().layer-o.getSource().layer,o.getTarget()===e&&r<n?n=r:r<t&&(t=r)}this.spanIn=n===2**53-1?-1:n,this.spanOut=t===2**53-1?-1:t}tightTreeDFS(e){let t=1;e.treeNode=!0;let n=e.getIncomingEdges();for(let r=0;r<n.length;r++){let i=n[r];if(!this.edgeVisited[i.internalId]){this.edgeVisited[i.internalId]=1;let n=i.getOther(e);i.treeEdge?t+=this.tightTreeDFS(n):!n.treeNode&&i.delta===i.getTarget().layer-i.getSource().layer&&(i.treeEdge=!0,this.treeEdges.add(i),t+=this.tightTreeDFS(n))}}let r=e.getOutgoingEdges();for(let n=0;n<r.length;n++){let i=r[n];if(!this.edgeVisited[i.internalId]){this.edgeVisited[i.internalId]=1;let n=i.getOther(e);i.treeEdge?t+=this.tightTreeDFS(n):!n.treeNode&&i.delta===i.getTarget().layer-i.getSource().layer&&(i.treeEdge=!0,this.treeEdges.add(i),t+=this.tightTreeDFS(n))}}return t}minimalSlack(){let e=2**53-1,t=null,n;for(let r of this.edges)r.getSource().treeNode!==r.getTarget().treeNode&&(n=r.getTarget().layer-r.getSource().layer-r.delta,n<e&&(e=n,t=r));return t}postorderTraversal(e){let t=2**53-1,n=e.getIncomingEdges();for(let r=0;r<n.length;r++){let i=n[r];if(i.treeEdge&&!this.edgeVisited[i.internalId]){this.edgeVisited[i.internalId]=1;let n=this.postorderTraversal(i.getOther(e));n<t&&(t=n)}}let r=e.getOutgoingEdges();for(let n=0;n<r.length;n++){let i=r[n];if(i.treeEdge&&!this.edgeVisited[i.internalId]){this.edgeVisited[i.internalId]=1;let n=this.postorderTraversal(i.getOther(e));n<t&&(t=n)}}this.poID[e.internalId]=this.postOrder;let i=this.postOrder;return this.lowestPoID[e.internalId]=t<i?t:i,this.postOrder=i+1,this.lowestPoID[e.internalId]}isInHead(e,t){let n=t.getSource(),r=t.getTarget();return this.lowestPoID[n.internalId]<=this.poID[e.internalId]&&this.poID[e.internalId]<=this.poID[n.internalId]&&this.lowestPoID[r.internalId]<=this.poID[e.internalId]&&this.poID[e.internalId]<=this.poID[r.internalId]?!(this.poID[n.internalId]<this.poID[r.internalId]):this.poID[n.internalId]<this.poID[r.internalId]}cutvalues(){let e=this.cutvalueLeafs;e.length=0;let t;for(let n of this.graph.nodes){t=0;let r=n.unknownCutvalues;r.length=0;let i=n.getIncomingEdges();for(let e=0;e<i.length;e++){let n=i[e];n.treeEdge&&(r.push(n),t++)}let a=n.getOutgoingEdges();for(let e=0;e<a.length;e++){let n=a[e];n.treeEdge&&(r.push(n),t++)}t===1&&e.push(n)}let n,r,i;for(let t=0;t<e.length;t++){let a=e[t];for(;a.unknownCutvalues.length===1;){n=a.unknownCutvalues[0],this.cutvalue[n.internalId]=n.weight,r=n.getSource(),i=n.getTarget();let e=a.getIncomingEdges(),t=a.getOutgoingEdges();for(let t=0;t<e.length;t++){let o=e[t];o!==n&&(o.treeEdge?r===o.getSource()||i===o.getTarget()?this.cutvalue[n.internalId]-=this.cutvalue[o.internalId]-o.weight:this.cutvalue[n.internalId]+=this.cutvalue[o.internalId]-o.weight:a===r?o.getSource()===a?this.cutvalue[n.internalId]+=o.weight:this.cutvalue[n.internalId]-=o.weight:o.getSource()===a?this.cutvalue[n.internalId]-=o.weight:this.cutvalue[n.internalId]+=o.weight)}for(let e=0;e<t.length;e++){let o=t[e];o!==n&&(o.treeEdge?r===o.getSource()||i===o.getTarget()?this.cutvalue[n.internalId]-=this.cutvalue[o.internalId]-o.weight:this.cutvalue[n.internalId]+=this.cutvalue[o.internalId]-o.weight:a===r?o.getSource()===a?this.cutvalue[n.internalId]+=o.weight:this.cutvalue[n.internalId]-=o.weight:o.getSource()===a?this.cutvalue[n.internalId]-=o.weight:this.cutvalue[n.internalId]+=o.weight)}let o=r.unknownCutvalues,s=o.indexOf(n);s!==-1&&(o[s]=o[o.length-1],o.pop());let c=i.unknownCutvalues,l=c.indexOf(n);l!==-1&&(c[l]=c[c.length-1],c.pop()),a=r===a?n.getTarget():n.getSource()}}}leaveEdge(){for(let e of this.treeEdges)if(e.treeEdge&&this.cutvalue[e.internalId]<-1e-10)return e;return null}enterEdge(e){if(!e.treeEdge)throw Error(`The input edge is not a tree edge.`);let t=null,n=2**53-1,r;for(let i of this.edges){let a=i.getSource(),o=i.getTarget();this.isInHead(a,e)&&!this.isInHead(o,e)&&(r=o.layer-a.layer-i.delta,r<n&&(n=r,t=i))}return t}exchange(e,t){if(!e.treeEdge)throw Error(`Given leave edge is no tree edge.`);if(t.treeEdge)throw Error(`Given enter edge is a tree edge already.`);e.treeEdge=!1,this.treeEdges.delete(e),t.treeEdge=!0,this.treeEdges.add(t);let n=t.getTarget().layer-t.getSource().layer-t.delta;this.isInHead(t.getTarget(),e)||(n=-n);for(let t of this.graph.nodes)this.isInHead(t,e)||(t.layer+=n);this.postOrder=1,this.edgeVisited.fill(0),this.postorderTraversal(this.graph.nodes[0]),this.cutvalues()}normalize(){let e=-(2**53-1),t=2**53-1;for(let n of this.graph.nodes)t=Math.min(t,n.layer),e=Math.max(e,n.layer);let n=Array(e-t+1).fill(0);for(let e of this.graph.nodes)e.layer-=t,n[e.layer]++;let r=0;if(this.previousLayeringNodeCounts!==null){for(let e of this.previousLayeringNodeCounts)if(n[r]+=e,r++,n.length===r)break}return n}balance(e){let t;for(let n of this.graph.nodes)if(n.getIncomingEdges().length===n.getOutgoingEdges().length){t=n.layer,this.minimalSpan(n);for(let r=n.layer-this.spanIn+1;r<n.layer+this.spanOut;r++)e[r]<e[t]&&(t=r);e[t]<e[n.layer]&&(e[n.layer]--,e[t]++,n.layer=t)}}},ae=class t{layeredGraph=null;componentNodes=[];nodeVisited=[];componentIndex=null;static ITER_LIMIT_FACTOR=4;process(n,r){r.begin(`Network simplex layering`,1),this.layeredGraph=n;let i=n.getProperty(e.mn)*t.ITER_LIMIT_FACTOR,a=n.getLayerlessNodes();if(a.length<1){r.done();return}let o=this.connectedComponents(a),s=null,c=null;for(let e of o){if(e.length===1&&e[0].getConnectedEdges().length===0){let t=n.getLayers();for(;t.length<=0;)t.push(new w(n));e[0].setLayer(t[0]);continue}let t=i*Math.floor(Math.sqrt(e.length)),a=this.initialize(e);c=c===null?ie.forGraph(a):c.prepare(a),c.withIterationLimit(t).withPreviousLayering(s).withBalancing(!0).executeWithMonitor(r);let l=n.getLayers();for(let e of a.nodes){for(;l.length<=e.layer;)l.push(new w(n));e.origin.setLayer(l[e.layer])}if(o.length>1){s=Array(n.getLayers().length).fill(0);let e=0;for(let t of n.getLayers())s[e++]=t.getNodes().length}}a.length=0,this.dispose(),r.done()}connectedComponents(e){let t=[];this.nodeVisited=Array(e.length).fill(!1),this.componentNodes=[];let n=/* @__PURE__ */ new Map;for(let t=0;t<e.length;t++)n.set(e[t],t);this.componentIndex=n;for(let n of e)this.componentNodes=[],this.connectedComponentsDFS(n),this.componentNodes.length>0&&(t.length===0||t[0].length<this.componentNodes.length?t.unshift(this.componentNodes):t.push(this.componentNodes));return t}connectedComponentsDFS(e){let t=this.componentIndex.get(e);if(!(t===void 0||this.nodeVisited[t])){this.nodeVisited[t]=!0,this.componentNodes.push(e);for(let t of e.getPorts()){for(let e of t.getIncomingEdges())this.connectedComponentsDFS(this.getOpposite(t,e).getNode());for(let e of t.getOutgoingEdges())this.connectedComponentsDFS(this.getOpposite(t,e).getNode())}}}initialize(t){let n=/* @__PURE__ */ new Map,r=new re;for(let e of t){let t=r.addNode(e);n.set(e,t)}for(let i of t)for(let t of i.getPorts())for(let i of t.getOutgoingEdges())i.isSelfLoop()||i.getSource()!==null&&i.getTarget()!==null&&r.addEdge(i,1*Math.max(1,i.getProperty(e.Wt)),1,n.get(i.getSource().getNode()),n.get(i.getTarget().getNode()));return r}dispose(){this.componentNodes=[],this.layeredGraph=null,this.nodeVisited=[],this.componentIndex=null}getOpposite(e,t){if(t.getSource()===e)return t.getTarget();if(t.getTarget()===e)return t.getSource();throw Error(`Input edge is not connected to the input port.`)}},oe=class{layeredGraph;nodeHeights=/* @__PURE__ */ new Map;process(e,t){t.begin(`Longest path layering`,1),this.layeredGraph=e;let n=e.getLayerlessNodes();this.nodeHeights=/* @__PURE__ */ new Map;for(let e of n)this.nodeHeights.set(e,-1);for(let e of n)this.visit(e);n.length=0,this.layeredGraph=null,this.nodeHeights=/* @__PURE__ */ new Map,t.done()}visit(e){let t=this.nodeHeights.get(e);if(t>=0)return t;let n=1;for(let t of e.getPorts())for(let r of t.getOutgoingEdges()){let t=r.getTarget().getNode();if(e!==t){let e=this.visit(t);n=Math.max(n,e+1)}}return this.putNode(e,n),n}putNode(e,t){let n=this.layeredGraph.getLayers();for(let e=n.length;e<t;e++)n.unshift(new w(this.layeredGraph));e.setLayer(n[n.length-t]),this.nodeHeights.set(e,t)}},se=class{layeredGraph;nodeHeights=/* @__PURE__ */ new Map;process(e,t){t.begin(`Longest path to source layering`,1),this.layeredGraph=e;let n=e.getLayerlessNodes();this.nodeHeights=/* @__PURE__ */ new Map;for(let e of n)this.nodeHeights.set(e,-1);for(let e of n)this.visit(e);n.length=0,this.layeredGraph=null,this.nodeHeights=/* @__PURE__ */ new Map,t.done()}visit(e){let t=this.nodeHeights.get(e);if(t!==void 0&&t>=0)return t;if(t===void 0)return 0;let n=1;for(let t of e.getPorts())for(let r of t.getIncomingEdges()){let t=r.getSource().getNode();if(e!==t){let e=this.visit(t);n=Math.max(n,e+1)}}return this.putNode(e,n),n}putNode(e,t){let n=this.layeredGraph.getLayers();for(let e=n.length;e<t;e++)n.push(new w(this.layeredGraph));e.setLayer(n[t-1]),this.nodeHeights.set(e,t)}};function ce(e){if(e.getLayers().length<=2)return;let t=e.getLayers();for(let n=0;n<t.length-1;n++){let r=t[n],i=t[n+1];for(let t of r.getNodes())for(let r of t.getPorts())for(let t of[...r.getOutgoingEdges()]){let r=t.getTarget().getNode().getLayer();r!==null&&r.getIndex()-n>1&&ue(t,le(e,i,t))}}}function le(t,n,r){let i=new f(t);return i.setType(`LONG_EDGE`),i.setProperty(e.lr,r),i.setProperty(e.Lt,`FIXED_POS`),i.setLayer(n),i}function ue(t,n){let r=t.getTarget(),i=t.getProperty(e.W);i<0&&(i=0,t.setProperty(e.W,i)),n.size.y=i;let a=Math.floor(i/2),o=new p;o.setSide(`WEST`),o.setNode(n),o.getPosition().y=a;let s=new p;s.setSide(`EAST`),s.setNode(n),s.getPosition().y=a,t.setTarget(o);let c=new m;return c.copyProperties(t),c.setProperty(e.nt,null),c.setSource(s),c.setTarget(r),de(n,t,c),fe(t,c),c}function de(t,n,r){let i=n.getSource().getNode(),a=r.getTarget().getNode();i.getType()===`LONG_EDGE`?(t.setProperty(e.rr,i.getProperty(e.rr)),t.setProperty(e.ir,i.getProperty(e.ir)),t.setProperty(e.nr,i.getProperty(e.nr))):i.getType()===`LABEL`?(t.setProperty(e.rr,i.getProperty(e.rr)),t.setProperty(e.ir,i.getProperty(e.ir)),t.setProperty(e.nr,!0)):a.getType()===`LABEL`?(t.setProperty(e.rr,a.getProperty(e.rr)),t.setProperty(e.ir,a.getProperty(e.ir)),t.setProperty(e.nr,!0)):(t.setProperty(e.rr,n.getSource()),t.setProperty(e.ir,r.getTarget()))}function fe(e,t){let n=[...e.getLabels()];for(let r of n)if(r.placement===`HEAD`){let n=e.getLabels().indexOf(r);n!==-1&&e.getLabels().splice(n,1),t.getLabels().push(r)}}function pe(e){return e.placement===void 0||e.placement===`CENTER`||e.placement===`UNDEFINED`}function me(t){let n=t.getProperty(e.tn),r=t.getProperty(e.an),i=t.getProperty(e.F)===`DOWN`||t.getProperty(e.F)===`UP`;for(let e of t.getLayerlessNodes())for(let a of[...e.getOutgoingEdges()]){if(!he(a))continue;let e=ge(a),o=[],s=_e(t,a,e,o).size,c=a.getLabels();for(let e=0;e<c.length;){let t=c[e];pe(t)?(i?(s.x+=t.size.x+r,s.y=Math.max(s.y,t.size.y)):(s.x=Math.max(s.x,t.size.x),s.y+=t.size.y+r),o.push(t),c.splice(e,1)):e++}i?(s.x-=r,s.y+=n+e):s.y+=n-r+e}}function he(e){return e.getSource().getNode()!==e.getTarget().getNode()&&e.getLabels().some(pe)}function ge(t){let n=t.getProperty(e.W);return n<0&&(n=0,t.setProperty(e.W,n)),n}function _e(t,n,r,i){let a=new f(t);return a.setType(`LABEL`),a.setProperty(e.lr,n),a.setProperty(e.xr,i),a.setProperty(e.Lt,`FIXED_POS`),a.setProperty(e.rr,n.getSource()),a.setProperty(e.ir,n.getTarget()),ue(n,a),a}const ve=[`MEDIAN_LAYER`,`TAIL_LAYER`,`HEAD_LAYER`,`SPACE_EFFICIENT_LAYER`,`WIDEST_LAYER`,`CENTER_LAYER`];function ye(e){return e===`WIDEST_LAYER`||e===`CENTER_LAYER`||e===`SPACE_EFFICIENT_LAYER`}function be(t){let n=t.getProperty(e.R);xe(t);let r=Se(t,n),i=Array(t.getLayers().length).fill(0);for(let e of ve)if(ye(e)&&r.get(e).length>0){i=Ce(t);break}for(let e of ve)ye(e)||Te(r.get(e),i);for(let e of ve)ye(e)&&Te(r.get(e),i)}function xe(e){let t=0;for(let n of e.getLayers())n.id=t,t++}function Se(e,t){let n=/* @__PURE__ */ new Map;for(let e of ve)n.set(e,[]);for(let r of e.getLayers())for(let e of r.getNodes())if(e.getType()===`LABEL`){let r=new Ve(e,t);n.get(r.placementStrategy).push(r)}return n}function Ce(e){let t=Array(e.getLayers().length).fill(0);for(let n of e.getLayers())t[n.id]=we(n);return t}function we(t){let n=t.getGraph();if(n!==null&&(n.getProperty(e.F)===`DOWN`||n.getProperty(e.F)===`UP`))return 0;let r=0;for(let e of t.getNodes())e.getType()===`NORMAL`&&(r=Math.max(r,e.getSize().x));return r}function Te(e,t){if(e.length!==0){if(e[0].placementStrategy===`SPACE_EFFICIENT_LAYER`)Ne(e,t);else for(let n of e){switch(n.placementStrategy){case`CENTER_LAYER`:Le(n,De(n,t),t);break;case`MEDIAN_LAYER`:Le(n,ke(n),t);break;case`WIDEST_LAYER`:Le(n,Ee(n,t),t);break;case`HEAD_LAYER`:je(n),Le(n,Ae(n,!0),t);break;case`TAIL_LAYER`:je(n),Le(n,Ae(n,!1),t)}ze(n)}}}function Ee(e,t){let n=e.leftmostLayerId;for(let r=n+1;r<=e.rightmostLayerId;r++)t[r]>t[n]&&(n=r);return n}function De(e,t){let n=Oe(e,t),r=n[n.length-1]/2;for(let t=0;t<n.length;t++)if(n[t]>=r)return e.leftmostLayerId+t;return e.leftmostLayerId+e.leftLongEdgeDummies.length}function Oe(t,n){let r=t.labelDummy.getGraph(),i=r.getProperty(e.rn)*2,a=r.getProperty(e.un),o=Math.max(i,a),s=Array(t.totalDummyCount()),c=-o,l=0;for(let e of t.leftLongEdgeDummies)c+=n[e.getLayer().id]+o,s[l++]=c;c+=n[t.labelDummy.getLayer().id]+o,s[l++]=c;for(let e of t.rightLongEdgeDummies)c+=n[e.getLayer().id]+o,s[l++]=c;return s}function ke(e){let t=e.totalDummyCount(),n=Math.floor((t-1)/2);return e.leftmostLayerId+n}function Ae(e,t){let n=Me(e);return t&&!n||!t&&n?e.rightmostLayerId:e.leftmostLayerId}function je(t){let n=t.placementStrategy===`HEAD_LAYER`,r=Me(t);n&&!r||!n&&r?t.labelDummy.setProperty(e.p,`RIGHT`):t.labelDummy.setProperty(e.p,`LEFT`)}function Me(t){let n=t.labelDummy.getIncomingEdges()[0],r=t.labelDummy.getOutgoingEdges()[0];return n.getProperty(e.Sr)||r.getProperty(e.Sr)}function Ne(e,t){let n=Pe(e,t);if(n.length===0)return;n.sort((e,t)=>t.labelDummy.getSize().x-e.labelDummy.getSize().x);let r=n.length;for(let e=0;e<r;e++)Le(n[e],Ie(n,e,t),t)}function Pe(e,t){let n=[];for(let r of e)r.leftmostLayerId===r.rightmostLayerId?Le(r,r.leftmostLayerId,t):Fe(r,t)||n.push(r);return n}function Fe(e,t){let n=e.labelDummy.getSize().x,r=e.labelDummy.getGraph().getLayers().slice(e.leftmostLayerId,e.rightmostLayerId+1);for(let i of r)if(i.getSize().x>=n)return Le(e,i.id,t),!0;return!1}function Ie(e,t,n){let r=e.length,i=e[t],a=i.labelDummy.getSize().x,o=i.leftmostLayerId,s=0;for(let c=i.leftmostLayerId;c<=i.rightmostLayerId;c++){if(a<=n[c])return c;let i=n[c],l=null;for(let n=t+1;n<r;n++){let t=e[n];t.leftmostLayerId<=c&&t.rightmostLayerId>=c&&(l=t)}l!==null&&(i=Math.max(i,l.labelDummy.getSize().x)),i>s&&(o=c,s=i)}return o}function Le(e,t,n){t!==e.leftmostLayerId+e.leftLongEdgeDummies.length&&Re(e.labelDummy,e.ithDummyNode(t-e.leftmostLayerId));let r=e.labelDummy.getLayer().id;n[r]=Math.max(n[r],e.labelDummy.getSize().x)}function Re(e,t){let n=e.getLayer(),r=t.getLayer(),i=n.getNodes().indexOf(e),a=r.getNodes().indexOf(t),o=e.getPorts(`INPUT`)[0],s=e.getPorts(`OUTPUT`)[0],c=t.getPorts(`INPUT`)[0],l=t.getPorts(`OUTPUT`)[0],u=[...o.getIncomingEdges()],d=[...s.getOutgoingEdges()],f=[...c.getIncomingEdges()],p=[...l.getOutgoingEdges()];e.setLayerAt(a,r);for(let e of f)e.setTarget(o);for(let e of p)e.setSource(s);t.setLayerAt(i,n);for(let e of u)e.setTarget(c);for(let e of d)e.setSource(l)}function ze(e){Be(e.labelDummy)}function Be(t){let n=t.getIncomingEdges()[0].getSource().getNode();for(;n.getType()===`LONG_EDGE`;)n.setProperty(e.tr,!0),n=n.getIncomingEdges()[0].getSource().getNode()}var Ve=class{labelDummy;placementStrategy;leftLongEdgeDummies=[];rightLongEdgeDummies=[];leftmostLayerId;rightmostLayerId;constructor(t,n){this.labelDummy=t,this.placementStrategy=n,this.gatherLeftLongEdgeDummies(),this.gatherRightLongEdgeDummies(),this.leftmostLayerId=this.leftLongEdgeDummies.length===0?t.getLayer().id:this.leftLongEdgeDummies[0].getLayer().id,this.rightmostLayerId=this.rightLongEdgeDummies.length===0?t.getLayer().id:this.rightLongEdgeDummies[this.rightLongEdgeDummies.length-1].getLayer().id;for(let n of t.getProperty(e.xr)){let e=n.centerLabelPlacementStrategy;if(e!=null){this.placementStrategy=e;break}}}gatherLeftLongEdgeDummies(){let e=this.labelDummy;do e=e.getIncomingEdges()[0].getSource().getNode(),e.getType()===`LONG_EDGE`&&this.leftLongEdgeDummies.push(e);while(e.getType()===`LONG_EDGE`);this.leftLongEdgeDummies.reverse()}gatherRightLongEdgeDummies(){let e=this.labelDummy;do e=e.getOutgoingEdges()[0].getTarget().getNode(),e.getType()===`LONG_EDGE`&&this.rightLongEdgeDummies.push(e);while(e.getType()===`LONG_EDGE`)}totalDummyCount(){return this.rightmostLayerId-this.leftmostLayerId+1}ithDummyNode(e){return e<this.leftLongEdgeDummies.length?this.leftLongEdgeDummies[e]:e===this.leftLongEdgeDummies.length?this.labelDummy:this.rightLongEdgeDummies[e-this.leftLongEdgeDummies.length-1]}};function He(t){let n=t.getProperty(e.hn);for(let e of t.getLayers()){let t=e.getNodes();for(let e=t.length-1;e>=0;e--){let r=t[e];r.getType()===`LONG_EDGE`&&(Ue(r,n),t.splice(e,1))}}}function Ue(t,n){let r=t.getPorts(`WEST`)[0],i=t.getPorts(`EAST`)[0],a=r.getIncomingEdges(),o=i.getOutgoingEdges(),s=a.length,c=t.getPorts()[0].getAbsoluteAnchor();for(;s-->0;){let t=a[0],r=o[0],i=r.getTarget().getIncomingEdges().indexOf(r);t.setTargetAndInsertAtIndex(r.getTarget(),i),r.setSource(null),r.setTarget(null);let s=t.getBendPoints();n&&s.push({...c});for(let e of r.getBendPoints())s.push({...e});for(let e of r.getLabels())t.getLabels().push(e);let l=t.getProperty(e.nt),u=r.getProperty(e.nt);u!=null&&(l==null?t.setProperty(e.nt,[...u]):l.push(...u))}}function We(t){let n=t.getProperty(e.tn),r=t.getProperty(e.an),i=t.getProperty(e.F),a=i===`DOWN`||i===`UP`;for(let o of t.getLayers())for(let t=o.getNodes().length-1;t>=0;t--){let s=o.getNodes()[t];if(s.getType()!==`LABEL`)continue;let c=s.getProperty(e.lr),l=c.getProperty(e.W),u=s.getProperty(e.er)===`BELOW`,d={...s.getPosition()};u&&(d.y+=l+n);let f={x:s.size.x,y:s.size.y-l-n},p=s.getProperty(e.xr);if(a)Ge(p,d,r,f,u,i);else{let e=d.y;for(let t of p)t.position.x=d.x+(f.x-t.size.x)/2,t.position.y=e,e+=t.size.y+r}c.getLabels().push(...p),Ue(s,!1),o.getNodes().splice(t,1)}}function Ge(e,t,n,r,i,a){let o=a===`UP`?[...e].reverse():e;for(let e of o)e.position.x=t.x,i?e.position.y=t.y:e.position.y=t.y+r.y-e.size.y,t.x+=e.size.x+n}var Ke=class{layerToNodes=/* @__PURE__ */ new Map;nodeToLayer=/* @__PURE__ */ new Map;put(e,t){let n=this.nodeToLayer.get(t);if(n!==void 0&&n!==e){let e=this.layerToNodes.get(n);if(e){let n=e.indexOf(t);n!==-1&&e.splice(n,1)}}this.nodeToLayer.set(t,e);let r=this.layerToNodes.get(e);r||(r=[],this.layerToNodes.set(e,r)),r.includes(t)||r.push(t)}putAll(e,t){for(let n of t)this.put(e,n)}getValues(e){return this.layerToNodes.get(e)??[]}getKey(e){return this.nodeToLayer.get(e)}keys(){return[...this.layerToNodes.keys()]}isMaximalKey(e){return e===Math.max(...this.keys())}isMinimalKey(e){return e===Math.min(...this.keys())}},qe=class{masterGraph;promotionStrategy=`NONE`;biLayerMap=new Ke;process(t,n){switch(n.begin(`Node promotion heuristic`,1),this.masterGraph=t,this.promotionStrategy=t.getProperty(e.ct),this.promotionStrategy){case`MODEL_ORDER_LEFT_TO_RIGHT`:this.precalculateAndSetInformationModelOrder(),this.modelOrderNodePromotion(!0);break;case`MODEL_ORDER_RIGHT_TO_LEFT`:this.precalculateAndSetInformationModelOrder(),this.modelOrderNodePromotion(!1)}(this.promotionStrategy===`MODEL_ORDER_LEFT_TO_RIGHT`||this.promotionStrategy===`MODEL_ORDER_RIGHT_TO_LEFT`)&&this.setNewLayeringModelOrder(t),n.done()}precalculateAndSetInformationModelOrder(){this.biLayerMap=new Ke;let t=0;for(let e of this.masterGraph.getLayers())e.id=t,t++;let n=this.promotionStrategy===`MODEL_ORDER_LEFT_TO_RIGHT`,r=(t,r)=>{if(!t.hasProperty(e.cr)||!r.hasProperty(e.cr))return 0;let i=t.getProperty(e.cr),a=r.getProperty(e.cr);return n?a-i:i-a};for(let e of this.masterGraph.getLayers())e.getNodes().sort(r),this.biLayerMap.putAll(e.id,e.getNodes())}modelOrderNodePromotion(t){let n;do{n=!1;let r=this.biLayerMap.keys();for(let i=t?r.length-2:1;t?i>=0:i<r.length;i+=t?-1:1){let r=this.biLayerMap.getValues(i);for(let a=0;a<r.length;a++){let o=r[a];if(!o.hasProperty(e.cr)||this.biLayerMap.isMaximalKey(i)&&t||this.biLayerMap.isMinimalKey(i)&&!t)continue;let s=!0;for(let n of r)if(n.hasProperty(e.cr)){let r=o.getProperty(e.cr),i=n.getProperty(e.cr);(t&&r<i||!t&&r>i)&&(s=!1)}if(!s)continue;let c=t?i+1:i-1,l=this.biLayerMap.getValues(c),u=!1,d=!0,f=!1;for(let n of l)if(n.hasProperty(e.cr)){if(n!==o){let r=o.getProperty(e.cr),i=n.getProperty(e.cr);u||=t?i<r:i>r,d=!1}}else if(!u&&d&&n.getType()===`LABEL`){f=!0;let e=t?n.getIncomingEdges()[0].getSource().getNode():n.getOutgoingEdges()[0].getTarget().getNode();if(e===o){let r=t?n.getOutgoingEdges()[0].getTarget().getNode():n.getIncomingEdges()[0].getSource().getNode();(t?this.biLayerMap.getKey(r)-this.biLayerMap.getKey(e):this.biLayerMap.getKey(e)-this.biLayerMap.getKey(r))<=2&&(d=!1)}}if(f&&d){let e=t?o.getOutgoingEdges()[0].getTarget().getNode():o.getIncomingEdges()[0].getSource().getNode();(t?this.biLayerMap.getKey(e)-this.biLayerMap.getKey(o):this.biLayerMap.getKey(o)-this.biLayerMap.getKey(e))<=2&&e.getType()===`NORMAL`&&(d=!1)}if(u||d){let e=this.promoteNodeByModelOrder(o,t),r=new Set(e);for(;r.size>0;){let e=r.values().next().value;r.delete(e);for(let n of this.promoteNodeByModelOrder(e,t))r.add(n)}a--,n=!0}}}}while(n)}promoteNodeByModelOrder(e,t){let n=this.biLayerMap.getKey(e);this.biLayerMap.put(t?n+1:n-1,e);let r=/* @__PURE__ */ new Set;for(let n of t?e.getOutgoingEdges():e.getIncomingEdges()){let i=t?n.getTarget().getNode():n.getSource().getNode();this.biLayerMap.getKey(i)===this.biLayerMap.getKey(e)&&r.add(i)}return r}setNewLayeringModelOrder(e){let t=[];e.getLayers().length=0;let n=this.biLayerMap.keys().sort((e,t)=>e-t);for(let r of n){let n=this.biLayerMap.getValues(r);if(n.length>0){let i=new w(e);t.push(i),i.id=r;for(let e of n)e.setLayer(i)}}e.getLayers().push(...t)}},Je=class{binarySums;numsPerIndex;count=0;maxNum;constructor(e){this.maxNum=e,this.binarySums=new Int32Array(e+1),this.numsPerIndex=new Int32Array(e)}add(e){if(!Number.isInteger(e)||e<0||e>=this.numsPerIndex.length)throw RangeError(`BinaryIndexedTree.add(${e})`);this.count++,this.numsPerIndex[e]++;let t=e+1;for(;t<this.binarySums.length;)this.binarySums[t]++,t+=t&-t}rank(e){let t=e,n=0;for(;t>0;)n+=this.binarySums[t],t-=t&-t;return n}size(){return this.count}removeAll(e){if(!Number.isInteger(e)||e<0||e>=this.numsPerIndex.length)throw RangeError(`BinaryIndexedTree.removeAll(${e})`);let t=this.numsPerIndex[e];if(t===0)return;this.numsPerIndex[e]=0,this.count-=t;let n=e+1;for(;n<this.binarySums.length;)this.binarySums[n]-=t,n+=n&-n}reset(e){e===this.maxNum?(this.binarySums.fill(0),this.numsPerIndex.fill(0)):(this.maxNum=e,this.binarySums=new Int32Array(e+1),this.numsPerIndex=new Int32Array(e)),this.count=0}clear(){this.binarySums.fill(0),this.numsPerIndex.fill(0),this.count=0}isEmpty(){return this.count===0}};function Ye(e,t){switch(t){case`EAST`:case`NORTH`:return e.getPortSideView(t);case`SOUTH`:case`WEST`:return[...e.getPortSideView(t)].reverse();default:return[]}}function Xe(e,t){return{first:e,second:t}}var Ze=class t{portPositions;indexTree=null;ends=[];nodeCardinalities=[];includedSet=/* @__PURE__ */ new Set;includedStamp=null;includedStampValue=0;scratchPortsCCW=[];scratchPortsInLayer=[];scratchPortsNS=[];scratchStackNS=[];nsTargets=[];nsDegrees=[];othersByPort=[];inLayerOthersByPort=[];betweenLayerDegreeByPort=[];static INDEXING_SIDE=`WEST`;static STACK_SIDE=`EAST`;constructor(e){this.portPositions=e}countCrossingsBetweenLayers(e,t){let n=this.initPortPositionsCounterClockwise(e,t);this.indexTree??=new Je(n.length),this.indexTree.reset(n.length);let r=this.includedSet;this.includedStamp??=new Uint32Array(this.portPositions.length);let i=++this.includedStampValue;i>=4294967296&&(this.includedStamp.fill(0),this.includedStampValue=1,i=1);for(let e of n)this.includedStamp[e.id]=i;return this.countCrossingsOnPorts(n,r)}countInLayerCrossingsOnSide(e,t){let n=this.initPortPositionsForInLayerCrossings(e,t);return this.countInLayerCrossingsOnPorts(n)}countNorthSouthPortCrossingsInLayer(e){let t=this.initPositionsForNorthSouthCounting(e);return this.indexTree??=new Je(t.length),this.indexTree.reset(t.length),this.countNorthSouthCrossingsOnPorts(t)}countCrossingsBetweenPortsInBothOrders(e,t){let n=this.connectedPortsSortedByPosition(e,t),r=this.countCrossingsOnPorts(n);this.indexTree.clear(),this.switchPorts(e,t),n.sort((e,t)=>this.positionOf(e)-this.positionOf(t));let i=this.countCrossingsOnPorts(n);return this.indexTree.clear(),this.switchPorts(t,e),Xe(r,i)}countInLayerCrossingsBetweenNodesInBothOrders(e,t,n){let r=this.connectedInLayerPortsSortedByPosition(e,t,n),i=this.countInLayerCrossingsOnPorts(r);this.switchNodes(e,t,n),this.indexTree.clear(),r.sort((e,t)=>this.positionOf(e)-this.positionOf(t));let a=this.countInLayerCrossingsOnPorts(r);return this.switchNodes(t,e,n),this.indexTree.clear(),Xe(i,a)}initForCountingBetween(e,t){let n=this.initPortPositionsCounterClockwise(e,t);this.indexTree??=new Je(n.length),this.indexTree.reset(n.length)}initPortPositionsForInLayerCrossings(e,t){let n=this.scratchPortsInLayer;return n.length=0,this.initPositions(e,n,t,!0,!0),this.indexTree??=new Je(n.length),this.indexTree.reset(n.length),n}switchPorts(e,t){let n=this.portPositions[e.id];this.portPositions[e.id]=this.portPositions[t.id],this.portPositions[t.id]=n}switchNodes(e,t,n){let r=Ye(e,n);for(let e of r)this.portPositions[e.id]=this.positionOf(e)+this.nodeCardinalities[t.id];r=Ye(t,n);for(let t of r)this.portPositions[t.id]=this.positionOf(t)-this.nodeCardinalities[e.id]}connectedPortsSortedByPosition(e,t){let n=/* @__PURE__ */ new Set;for(let r of[e,t]){n.add(r);for(let e of r.getIncomingEdges())this.isPortSelfLoop(e)||n.add(this.otherEndOf(e,r));for(let e of r.getOutgoingEdges())this.isPortSelfLoop(e)||n.add(this.otherEndOf(e,r))}return[...n].sort((e,t)=>this.positionOf(e)-this.positionOf(t))}connectedInLayerPortsSortedByPosition(e,t,n){let r=/* @__PURE__ */ new Set;for(let i of[e,t])for(let e of Ye(i,n)){for(let t of e.getIncomingEdges())t.isSelfLoop()||(r.add(e),this.isInLayer(t)&&r.add(this.otherEndOf(t,e)));for(let t of e.getOutgoingEdges())t.isSelfLoop()||(r.add(e),this.isInLayer(t)&&r.add(this.otherEndOf(t,e)))}return[...r].sort((e,t)=>this.positionOf(e)-this.positionOf(t))}getOthers(e){let t=this.othersByPort[e.id];if(t!==void 0)return t;let n=[],r=e.getIncomingEdges();for(let t=0;t<r.length;t++){let i=r[t];n.push(e===i.getSource()?i.getTarget():i.getSource())}let i=e.getOutgoingEdges();for(let t=0;t<i.length;t++){let r=i[t];n.push(e===r.getSource()?r.getTarget():r.getSource())}return this.othersByPort[e.id]=n,n}countCrossingsOnPorts(e,t){let n=0,r=this.indexTree,i=this.ends,a=this.portPositions,o=t===void 0?null:this.includedStamp,s=this.includedStampValue;for(let t of e){let e=a[t.id]??0;r.removeAll(e);let c=this.getOthers(t);for(let t=0;t<c.length;t++){let l=c[t];if(o!==null&&o[l.id]!==s)continue;let u=a[l.id]??0;u>e&&(n+=r.rank(u),i.push(u))}for(;i.length>0;)r.add(i.pop())}return n}getInLayerOthers(e){let t=this.inLayerOthersByPort[e.id];if(t!==void 0)return t;let n=[],r=0,i=e.getIncomingEdges();for(let t=0;t<i.length;t++){let a=i[t];a.getSource().getNode().getLayer()===a.getTarget().getNode().getLayer()?n.push(e===a.getSource()?a.getTarget():a.getSource()):r++}let a=e.getOutgoingEdges();for(let t=0;t<a.length;t++){let i=a[t];i.getSource().getNode().getLayer()===i.getTarget().getNode().getLayer()?n.push(e===i.getSource()?i.getTarget():i.getSource()):r++}return this.inLayerOthersByPort[e.id]=n,this.betweenLayerDegreeByPort[e.id]=r,n}countInLayerCrossingsOnPorts(e){let t=0,n=this.indexTree,r=this.ends,i=this.portPositions,a=n.numsPerIndex.length;for(let o of e){let e=i[o.id]??0;n.removeAll(e);let s=this.getInLayerOthers(o);for(let o=0;o<s.length;o++){let c=i[s[o].id]??0;c>e&&c<a&&(t+=n.rank(c),r.push(c))}for(t+=n.size()*this.betweenLayerDegreeByPort[o.id];r.length>0;)n.add(r.pop())}return t}countNorthSouthCrossingsOnPorts(t){let n=0,r=this.indexTree,i=this.ends,a=this.portPositions,o=this.nsTargets,s=this.nsDegrees;for(let c of t){let t=a[c.id]??0;switch(r.removeAll(t),o.length=0,s.length=0,c.getNode().getType()){case`NORMAL`:{let t=c.getProperty(e._r);if(t)for(let e of t.getPorts())o.push(e),s.push(e.getDegree());break}case`LONG_EDGE`:{let e=c.getNode().getPorts().find(e=>e!==c);e&&(o.push(e),s.push(e.getDegree()));break}case`NORTH_SOUTH_PORT`:{let t=c.getProperty(e.lr);t&&(o.push(t),s.push(c.getDegree()));break}}for(let e=0;e<o.length;e++){let c=a[o[e].id]??0;c>t&&(n+=r.rank(c)*s[e],i.push(c))}for(;i.length>0;)r.add(i.pop())}return n}initPositions(e,t,n,r,i){let a=t.length;i&&this.nodeCardinalities.length<e.length&&(this.nodeCardinalities=Array(e.length));let o=n===`EAST`?r:!r;if(r)for(let r=0;r<e.length;r++){let s=e[r],c=s.getPorts(),l=0;if(o)for(let e=0;e<c.length;e++){let r=c[e];r.getSide()===n&&(this.portPositions[r.id]=a++,t.push(r),l++)}else for(let e=c.length-1;e>=0;e--){let r=c[e];r.getSide()===n&&(this.portPositions[r.id]=a++,t.push(r),l++)}i&&(this.nodeCardinalities[s.id]=l)}else for(let r=e.length-1;r>=0;r--){let s=e[r],c=s.getPorts(),l=0;if(o)for(let e=0;e<c.length;e++){let r=c[e];r.getSide()===n&&(this.portPositions[r.id]=a++,t.push(r),l++)}else for(let e=c.length-1;e>=0;e--){let r=c[e];r.getSide()===n&&(this.portPositions[r.id]=a++,t.push(r),l++)}i&&(this.nodeCardinalities[s.id]=l)}}initPortPositionsCounterClockwise(e,t){let n=this.scratchPortsCCW;return n.length=0,this.initPositions(e,n,`EAST`,!0,!1),this.initPositions(t,n,`WEST`,!1,!1),n}initPositionsForNorthSouthCounting(n){let r=this.scratchPortsNS;r.length=0;let i=this.scratchStackNS;i.length=0;let a=null,o=0;for(let s=0;s<n.length;++s){let c=n[s];switch(this.isLayoutUnitChanged(a,c)&&(o=this.emptyStack(i,r,t.STACK_SIDE,o)),c.hasProperty(e.Zn)&&(a=c.getProperty(e.Zn)),c.getType()){case`NORMAL`:for(let t of c.getPorts())t.getSide()===`NORTH`&&t.hasProperty(e._r)&&(this.portPositions[t.id]=o++,r.push(t));o=this.emptyStack(i,r,t.STACK_SIDE,o);for(let t of c.getPorts())t.getSide()===`SOUTH`&&t.hasProperty(e._r)&&(this.portPositions[t.id]=o++,r.push(t));break;case`NORTH_SOUTH_PORT`:{let e=this.firstPortOnSide(c,t.INDEXING_SIDE);e!==null&&(this.portPositions[e.id]=o++,r.push(e)),this.countPortsOnSide(c,t.STACK_SIDE)>0&&i.push(c);break}case`LONG_EDGE`:for(let e of c.getPorts())e.getSide()===`WEST`&&(this.portPositions[e.id]=o++,r.push(e));for(let e=0,t=this.countPortsOnSide(c,`EAST`);e<t;e++)i.push(c)}}return this.emptyStack(i,r,t.STACK_SIDE,o),r}emptyStack(e,t,n,r){let i=r;for(;e.length>0;){let r=e.pop(),a=this.firstPortOnSide(r,n);this.portPositions[a.id]=i++,t.push(a)}return i}getPorts(e,t,n){return t===`EAST`?n?e.getPortSideView(t):[...e.getPortSideView(t)].reverse():n?[...e.getPortSideView(t)].reverse():e.getPortSideView(t)}firstPortOnSide(e,t){let n=e.getPorts();for(let e=0;e<n.length;e++)if(n[e].getSide()===t)return n[e];return null}countPortsOnSide(e,t){let n=e.getPorts(),r=0;for(let e=0;e<n.length;e++)n[e].getSide()===t&&r++;return r}start(e,t){return t?0:e.length-1}end(e,t,n){return t?e<n.length:e>=0}step(e){return e?1:-1}isInLayer(e){return e.getSource().getNode().getLayer()===e.getTarget().getNode().getLayer()}positionOf(e){return this.portPositions[e.id]??0}otherEndOf(e,t){return t===e.getSource()?e.getTarget():e.getSource()}isPortSelfLoop(e){return e.getSource()===e.getTarget()}isLayoutUnitChanged(t,n){return t===null||t===n||!n.hasProperty(e.Zn)?!1:n.getProperty(e.Zn)!==t}};function Qe(t,n){return t.getPortSideView(n).some(t=>t.hasProperty(e._r)||t.getConnectedEdges().length>0)}var $e=class{isCrossingMatrixFilled;crossingMatrix;inBetweenLayerCrossingCounter;direction;oneSided;constructor(e,t,n,r){this.direction=r,this.oneSided=e===1;let i=t[n];this.isCrossingMatrixFilled=Array.from({length:i.length},()=>Array(i.length).fill(!1)),this.crossingMatrix=Array.from({length:i.length},()=>Array(i.length).fill(0)),this.inBetweenLayerCrossingCounter=new tt(t,n)}getCrossingMatrixEntry(e,t){return this.isCrossingMatrixFilled[e.id][t.id]||(this.fillCrossingMatrix(e,t),this.isCrossingMatrixFilled[e.id][t.id]=!0,this.isCrossingMatrixFilled[t.id][e.id]=!0),this.crossingMatrix[e.id][t.id]}fillCrossingMatrix(e,t){this.oneSided?this.direction===1?this.inBetweenLayerCrossingCounter.countEasternEdgeCrossings(e,t):this.inBetweenLayerCrossingCounter.countWesternEdgeCrossings(e,t):this.inBetweenLayerCrossingCounter.countBothSideCrossings(e,t),this.crossingMatrix[e.id][t.id]=this.inBetweenLayerCrossingCounter.getUpperLowerCrossings(),this.crossingMatrix[t.id][e.id]=this.inBetweenLayerCrossingCounter.getLowerUpperCrossings()}},et=class{upperLowerCrossings=0;lowerUpperCrossings=0;portPositions=/* @__PURE__ */ new Map;layer;constructor(e){this.layer=e,this.initializePortPositions()}initializePortPositions(){for(let e of this.layer)this.setPortIdsOn(e,`SOUTH`),this.setPortIdsOn(e,`NORTH`)}setPortIdsOn(e,t){let n=0;for(let r of Ye(e,t))this.portPositions.set(r,n++)}countCrossings(e,t){this.upperLowerCrossings=0,this.lowerUpperCrossings=0,this.processIfTwoNorthSouthNodes(e,t),this.processIfNorthSouthLongEdgeDummyCrossing(e,t),this.processIfNormalNodeWithNSPortsAndLongEdgeDummy(e,t)}processIfTwoNorthSouthNodes(e,t){this.isNorthSouth(e)&&this.isNorthSouth(t)&&!this.haveDifferentOrigins(e,t)&&(this.isNorthOfNormalNode(e)?this.countCrossingsOfTwoNorthSouthDummies(e,t):this.countCrossingsOfTwoNorthSouthDummies(t,e))}countCrossingsOfTwoNorthSouthDummies(e,t){if(this.originPortPositionOf(e)>this.originPortPositionOf(t)){let n=t.getPortSideView(`EAST`);this.upperLowerCrossings=n.length===0?0:n[0].getDegree();let r=e.getPortSideView(`WEST`);this.lowerUpperCrossings=r.length===0?0:r[0].getDegree()}else{let n=t.getPortSideView(`WEST`);this.upperLowerCrossings=n.length===0?0:n[0].getDegree();let r=e.getPortSideView(`EAST`);this.lowerUpperCrossings=r.length===0?0:r[0].getDegree()}}processIfNorthSouthLongEdgeDummyCrossing(e,t){this.isNorthSouth(e)&&this.isLongEdgeDummy(t)?this.isNorthOfNormalNode(e)?this.upperLowerCrossings=1:this.lowerUpperCrossings=1:this.isNorthSouth(t)&&this.isLongEdgeDummy(e)&&(this.isNorthOfNormalNode(t)?this.lowerUpperCrossings=1:this.upperLowerCrossings=1)}processIfNormalNodeWithNSPortsAndLongEdgeDummy(e,t){this.isNormal(e)&&this.isLongEdgeDummy(t)&&(this.upperLowerCrossings=this.numberOfNorthSouthEdges(e,`SOUTH`),this.lowerUpperCrossings=this.numberOfNorthSouthEdges(e,`NORTH`)),this.isNormal(t)&&this.isLongEdgeDummy(e)&&(this.upperLowerCrossings=this.numberOfNorthSouthEdges(t,`NORTH`),this.lowerUpperCrossings=this.numberOfNorthSouthEdges(t,`SOUTH`))}numberOfNorthSouthEdges(e,t){let n=0;for(let r of e.getPortSideView(t))n+=+!!this.hasConnectedNorthSouthEdge(r);return n}hasConnectedNorthSouthEdge(t){return t.getProperty(e._r)!==null&&t.getProperty(e._r)!==void 0}haveDifferentOrigins(e,t){return this.originOf(e)!==this.originOf(t)}originPortPositionOf(e){return this.portPositions.get(this.originPortOf(e))}originPortOf(t){return t.getPorts()[0].getProperty(e.lr)}isNorthOfNormalNode(e){return this.originPortOf(e).getSide()===`NORTH`}originOf(t){return t.getProperty(e.lr)}isLongEdgeDummy(e){return e.getType()===`LONG_EDGE`}isNorthSouth(e){return e.getType()===`NORTH_SOUTH_PORT`}isNormal(e){return e.getType()===`NORMAL`}getUpperLowerCrossings(){return this.upperLowerCrossings}getLowerUpperCrossings(){return this.lowerUpperCrossings}},tt=class{currentNodeOrder;freeLayerIndex;upperLowerCrossings=0;lowerUpperCrossings=0;upperAdjacencies;lowerAdjacencies;portPositions=/* @__PURE__ */ new Map;easternAdjacencies=/* @__PURE__ */ new Map;westernAdjacencies=/* @__PURE__ */ new Map;constructor(e,t){this.currentNodeOrder=e,this.freeLayerIndex=t,this.setPortPositionsForNeighbouringLayers()}setPortPositionsForNeighbouringLayers(){this.freeLayerIndex>0&&this.setPortPositionsForLayer(this.freeLayerIndex-1,`EAST`),this.freeLayerIndex<this.currentNodeOrder.length-1&&this.setPortPositionsForLayer(this.freeLayerIndex+1,`WEST`)}setPortPositionsForLayer(e,t){let n=0;for(let r of this.currentNodeOrder[e])for(let e of Ye(r,t))this.portPositions.set(e,n++)}countEasternEdgeCrossings(e,t){this.resetCrossingCount(),e!==t&&this.addEasternCrossings(e,t)}countWesternEdgeCrossings(e,t){this.resetCrossingCount(),e!==t&&this.addWesternCrossings(e,t)}countBothSideCrossings(e,t){this.resetCrossingCount(),e!==t&&(this.addWesternCrossings(e,t),this.addEasternCrossings(e,t))}resetCrossingCount(){this.upperLowerCrossings=0,this.lowerUpperCrossings=0}addEasternCrossings(e,t){this.upperAdjacencies=this.getAdjacencyFor(e,`EAST`,this.easternAdjacencies),this.lowerAdjacencies=this.getAdjacencyFor(t,`EAST`,this.easternAdjacencies),this.upperAdjacencies.size()!==0&&this.lowerAdjacencies.size()!==0&&this.countCrossingsByMergingAdjacencyLists()}getAdjacencyFor(e,t,n){if(n.size===0)for(let e of this.currentNodeOrder[this.freeLayerIndex])n.set(e,new nt(e,t,this.portPositions));let r=n.get(e);return r.reset(),r}addWesternCrossings(e,t){this.upperAdjacencies=this.getAdjacencyFor(e,`WEST`,this.westernAdjacencies),this.lowerAdjacencies=this.getAdjacencyFor(t,`WEST`,this.westernAdjacencies),this.upperAdjacencies.size()!==0&&this.lowerAdjacencies.size()!==0&&this.countCrossingsByMergingAdjacencyLists()}countCrossingsByMergingAdjacencyLists(){for(;!this.upperAdjacencies.isEmpty()&&!this.lowerAdjacencies.isEmpty();)this.isBelow(this.upperAdjacencies.first(),this.lowerAdjacencies.first())?(this.upperLowerCrossings+=this.upperAdjacencies.size(),this.lowerAdjacencies.removeFirst()):this.isBelow(this.lowerAdjacencies.first(),this.upperAdjacencies.first())?(this.lowerUpperCrossings+=this.lowerAdjacencies.size(),this.upperAdjacencies.removeFirst()):(this.upperLowerCrossings+=this.upperAdjacencies.countAdjacenciesBelowNodeOfFirstPort(),this.lowerUpperCrossings+=this.lowerAdjacencies.countAdjacenciesBelowNodeOfFirstPort(),this.upperAdjacencies.removeFirst(),this.lowerAdjacencies.removeFirst())}isBelow(e,t){return e>t}getUpperLowerCrossings(){return this.upperLowerCrossings}getLowerUpperCrossings(){return this.lowerUpperCrossings}},nt=class{node;side;portPositions;adjacencyList=[];totalSize=0;currentSize=0;currentIndex=0;constructor(e,t,n){this.node=e,this.side=t,this.portPositions=n,this.getAdjacenciesSortedByPosition()}getAdjacenciesSortedByPosition(){this.iterateThroughEdgesCollectingAdjacencies(),this.adjacencyList.sort((e,t)=>e.position-t.position)}iterateThroughEdgesCollectingAdjacencies(){for(let e of Ye(this.node,this.side)){let t=this.side===`WEST`?e.getIncomingEdges():e.getOutgoingEdges();for(let e of t)!e.isSelfLoop()&&!this.isInLayer(e)&&(this.addAdjacencyOf(e),this.totalSize++,this.currentSize++)}}isInLayer(e){return e.getSource().getNode().getLayer()===e.getTarget().getNode().getLayer()}addAdjacencyOf(e){let t=this.side===`WEST`?e.getSource():e.getTarget(),n=this.portPositions.get(t),r=this.adjacencyList.length-1;this.adjacencyList.length>0&&this.adjacencyList[r].position===n?(this.adjacencyList[r].cardinality++,this.adjacencyList[r].currentCardinality++):this.adjacencyList.push(new rt(n))}reset(){this.currentIndex=0,this.currentSize=this.totalSize,this.isEmpty()||this.currentAdjacency().reset()}countAdjacenciesBelowNodeOfFirstPort(){return this.currentSize-this.currentAdjacency().currentCardinality}removeFirst(){if(this.isEmpty())return;let e=this.currentAdjacency();e.currentCardinality===1?this.incrementCurrentIndex():e.currentCardinality--,this.currentSize--}incrementCurrentIndex(){this.currentIndex++,this.currentIndex<this.adjacencyList.length&&this.currentAdjacency().reset()}isEmpty(){return this.currentSize===0}first(){return this.currentAdjacency().position}size(){return this.currentSize}currentAdjacency(){return this.adjacencyList[this.currentIndex]}},rt=class{position;cardinality=1;currentCardinality=1;constructor(e){this.position=e}reset(){this.currentCardinality=this.cardinality}},it=class{freeLayer;leftInLayerCounter;rightInLayerCounter;northSouthCounter;crossingMatrixFiller;graphData;parentCrossCounter=null;countCrossingsCausedByPortSwitch;constructor(e,t,n,r,i,a){if(this.crossingMatrixFiller=n,this.graphData=i,e>=t.length)throw Error(`Greedy SwitchDecider: Free layer not in graph.`);this.freeLayer=t[e],this.leftInLayerCounter=new Ze(r),this.leftInLayerCounter.initPortPositionsForInLayerCrossings(this.freeLayer,`WEST`),this.rightInLayerCounter=new Ze(r),this.rightInLayerCounter.initPortPositionsForInLayerCrossings(this.freeLayer,`EAST`),this.northSouthCounter=new et(this.freeLayer),this.countCrossingsCausedByPortSwitch=!a&&i.hasParent&&!i.dontSweepInto()&&this.freeLayer[0].getType()===`EXTERNAL_PORT`,this.countCrossingsCausedByPortSwitch&&this.initParentCrossingsCounters(e,t.length)}initParentCrossingsCounters(e,t){let n=this.graphData.parentGraphData,r=n.currentNodeOrder,i=n.portPositions;this.parentCrossCounter=new Ze(i);let a=this.graphData.parent.getLayer().id,o=a>0?r[a-1]:[],s=r[a],c=a<r.length-1?r[a+1]:[];e===t-1?this.parentCrossCounter.initForCountingBetween(s,c):this.parentCrossCounter.initForCountingBetween(o,s)}notifyOfSwitch(t,n){if(this.leftInLayerCounter.switchNodes(t,n,`WEST`),this.rightInLayerCounter.switchNodes(t,n,`EAST`),this.countCrossingsCausedByPortSwitch){let r=t.getProperty(e.lr),i=n.getProperty(e.lr);this.parentCrossCounter.switchPorts(r,i)}}doesSwitchReduceCrossings(t,n){if(this.constraintsPreventSwitch(t,n))return!1;let r=this.freeLayer[t],i=this.freeLayer[n],a=this.leftInLayerCounter.countInLayerCrossingsBetweenNodesInBothOrders(r,i,`WEST`),o=this.rightInLayerCounter.countInLayerCrossingsBetweenNodesInBothOrders(r,i,`EAST`);this.northSouthCounter.countCrossings(r,i);let s=this.crossingMatrixFiller.getCrossingMatrixEntry(r,i),c=this.crossingMatrixFiller.getCrossingMatrixEntry(i,r),l=s+a.first+o.first+this.northSouthCounter.getUpperLowerCrossings(),u=c+a.second+o.second+this.northSouthCounter.getLowerUpperCrossings();if(this.countCrossingsCausedByPortSwitch){let t=r.getProperty(e.lr),n=i.getProperty(e.lr),a=this.parentCrossCounter.countCrossingsBetweenPortsInBothOrders(t,n);l+=a.first,u+=a.second}return l>u}constraintsPreventSwitch(e,t){let n=this.freeLayer[e],r=this.freeLayer[t];return this.haveSuccessorConstraints(n,r)||this.haveLayoutUnitConstraints(n,r)||this.areNormalAndNorthSouthPortDummy(n,r)}haveSuccessorConstraints(t,n){let r=t.getProperty(e.Qn);return r!=null&&r.length!==0&&r.includes(n)}haveLayoutUnitConstraints(t,n){let r=t.getType()!==`LONG_EDGE`&&n.getType()!==`LONG_EDGE`,i=t.getProperty(e.Zn),a=n.getProperty(e.Zn),o=i!==a,s=this.partOfMultiNodeLayoutUnit(t,i)||this.partOfMultiNodeLayoutUnit(n,a),c=Qe(t,`NORTH`),l=Qe(n,`SOUTH`);return s=s||Qe(t,`SOUTH`)||Qe(n,`NORTH`),r&&(s&&o||c||l)}partOfMultiNodeLayoutUnit(e,t){return t!=null&&t!==e}areNormalAndNorthSouthPortDummy(e,t){return this.isNorthSouthPortNode(e)&&this.isNormalNode(t)||this.isNorthSouthPortNode(t)&&this.isNormalNode(e)}isNormalNode(e){return e.getType()===`NORMAL`}isNorthSouthPortNode(e){return e.getType()===`NORTH_SOUTH_PORT`}},at=class{greedySwitchType;graphData;currentNodeOrder;switchDecider;nPorts=0;portPositions=[];constructor(e,t){this.greedySwitchType=e,this.graphData=t}minimizeCrossings(e,t,n,r){return this.setUp(e,t,n),this.continueSwitchingUntilNoImprovementInLayer(t)}setFirstLayerOrder(e,t){let n=t?0:e.length-1;return this.setUp(e,n,t),this.sweepDownwardInLayer(n)}alwaysImproves(){return this.greedySwitchType!==1}isDeterministic(){return!0}initAtLayerLevel(){}initAtNodeLevel(e,t,n){n[e][t].id=t}initAtPortLevel(){this.nPorts++}initAtEdgeLevel(){}initAfterTraversal(){this.portPositions=Array(this.nPorts)}setUp(e,t,n){this.currentNodeOrder=e;let r=+!n,i=new $e(this.greedySwitchType,e,t,r);this.switchDecider=new it(t,e,i,this.portPositions,this.graphData,this.greedySwitchType===1)}continueSwitchingUntilNoImprovementInLayer(e){let t=!1,n;do n=this.sweepDownwardInLayer(e),t||=n;while(n);return t}sweepDownwardInLayer(e){let t=this.currentNodeOrder[e],n=!1;for(let e=0;e<t.length-1;e++){if(!this.switchDecider.doesSwitchReduceCrossings(e,e+1))continue;this.switchDecider.notifyOfSwitch(t[e],t[e+1]);let r=t[e];t[e]=t[e+1],t[e+1]=r,n=!0}return n}},ot=class{skipInitAtLayerLevel=!0;skipInitAtPortLevel=!0;skipInitAtEdgeLevel=!0;crossingsCounter;hierarchicalCrossingsCounter;nPorts=0;portPositions=[];distributePortsWhileSweeping(t,n,r){let i=r?`WEST`:`EAST`;r&&n>0?this.crossingsCounter.initForCountingBetween(t[n-1],t[n]):!r&&n<t.length-1?this.crossingsCounter.initForCountingBetween(t[n],t[n+1]):this.crossingsCounter.initPortPositionsForInLayerCrossings(t[n],i);let a=!1;for(let o of t[n]){let t=o.getProperty(e.Lt);if(e.Lr.isOrderFixed(t))continue;let n=o.getNestedGraph(),s=o.getPortSideView(i).length>0&&n!==null;if(s){let e=n.toNodeArray();this.hierarchicalCrossingsCounter=new tt(e,r?0:e.length-1)}a=this.distributePortsOnNode(o,i,s)||a}return a}initAtLayerLevel(){}initAtNodeLevel(e,t,n){this.nPorts+=n[e][t].getPorts().length}initAtPortLevel(){}initAtEdgeLevel(){}initAfterTraversal(){this.portPositions=Array(this.nPorts),this.crossingsCounter=new Ze(this.portPositions)}distributePortsOnNode(e,t,n){let r=e.getPortSideView(t);(t===`SOUTH`||t===`WEST`)&&(r=[...r].reverse());let i=!1,a;do{a=!1;for(let t=0;t<r.length-1;t++){let o=r[t],s=r[t+1];if(this.switchingDecreasesCrossings(o,s,n)){this.crossingsCounter.switchPorts(o,s),r[t]=s,r[t+1]=o;let n=e.getPorts(),c=n.indexOf(o),l=n.indexOf(s);c>=0&&l>=0&&(n[c]=s,n[l]=o),i=!0,a=!0}}}while(a);return i}switchingDecreasesCrossings(t,n,r){let i=this.crossingsCounter.countCrossingsBetweenPortsInBothOrders(t,n),a=i.first,o=i.second;if(r){let r=t.getProperty(e._r),i=n.getProperty(e._r);r!=null&&i!=null&&(this.hierarchicalCrossingsCounter.countBothSideCrossings(r,i),a+=this.hierarchicalCrossingsCounter.getUpperLowerCrossings(),o+=this.hierarchicalCrossingsCounter.getLowerUpperCrossings())}return a>o}};const st={NORTH:0,EAST:1,SOUTH:2,WEST:3};var ct=class{skipInitAtEdgeLevel=!0;portRanks;minBarycenter=0;maxBarycenter=0;nodePositions;portBarycenter;inLayerPorts=[];nPorts=0;nodeLayerIndex=/* @__PURE__ */ new WeakMap;scratchPorts=[];portHasIncoming=[];portHasOutgoing=[];portDegrees=[];debugSortPorts=!1;debugPortRanks=!1;constructor(e){this.nodePositions=Array(e)}getPortRanks(){return this.portRanks}distributePortsWhileSweeping(t,n,r){this.debugSortPorts=!1,this.updateNodePositions(t,n);let i=t[n],a=r?`WEST`:`EAST`;if(this.isNotFirstLayer(t.length,n,r)){let o=t[r?n-1:n+1];this.calculatePortRanksForLayer(o,this.portTypeFor(r));for(let e of i)this.distributePorts(e,a);this.calculatePortRanksForLayer(i,this.portTypeFor(!r));for(let t of o)this.hasNestedGraph(t)||this.distributePorts(t,e.Rr.opposed(a))}else for(let e of i)this.distributePorts(e,a);return!1}calculatePortRanksForLayer(e,t){this.debugPortRanks=!1;let n=0,r=e.length;for(let i=0;i<r;i++){let r=e[i];n+=this.calculatePortRanks(r,r.getPorts(),n,t)}}distributePorts(t,n){if(typeof n==`string`){let r=n;e.Lr.isOrderFixed(t.getProperty(e.Lt))||(this.distributePorts(t,this.collectPortsOnSide(t,r)),this.distributePorts(t,this.collectPortsOnSide(t,`SOUTH`)),this.distributePorts(t,this.collectPortsOnSide(t,`NORTH`)),this.sortPorts(t));return}let r=n;this.inLayerPorts.length=0,this.iteratePortsAndCollectInLayerPorts(t,r),this.inLayerPorts.length>0&&this.calculateInLayerPortsBarycenterValues(t)}collectPortsOnSide(e,t){this.scratchPorts.length=0;let n=e.getPorts();for(let e=0;e<n.length;e++)n[e].getSide()===t&&this.scratchPorts.push(n[e]);return this.scratchPorts}iteratePortsAndCollectInLayerPorts(t,n){this.minBarycenter=0,this.maxBarycenter=0;let r=t.getLayer(),i=2*r.getNodes().length+1;for(let t=0;t<n.length;t++){let a=n[t],o=a.getSide()===`NORTH`||a.getSide()===`SOUTH`,s=0;if(o){let t=a.getProperty(e._r);if(t==null)continue;s+=this.dealWithNorthSouthPorts(i,a,t)}else{for(let e of a.getOutgoingEdges()){let t=e.getTarget();t.getNode().getLayer()===r?this.inLayerPorts.push(a):s+=this.portRanks[t.id]}for(let e of a.getIncomingEdges()){let t=e.getSource();t.getNode().getLayer()===r?this.inLayerPorts.push(a):s-=this.portRanks[t.id]}}let c=this.portDegrees[a.id]??a.getDegree();c>0?(this.portBarycenter[a.id]=s/c,this.minBarycenter=Math.min(this.minBarycenter,this.portBarycenter[a.id]),this.maxBarycenter=Math.max(this.maxBarycenter,this.portBarycenter[a.id])):o&&(this.portBarycenter[a.id]=s)}}calculateInLayerPortsBarycenterValues(e){let t=this.positionOf(e)+1,n=e.getLayer(),r=n.getNodes().length+1;for(let e of this.inLayerPorts){let i=0,a=0;for(let t of e.getIncomingEdges()){let e=t.getSource();e.getNode().getLayer()===n&&(i+=this.positionOf(e.getNode())+1,a++)}for(let t of e.getOutgoingEdges()){let e=t.getTarget();e.getNode().getLayer()===n&&(i+=this.positionOf(e.getNode())+1,a++)}let o=i/a,s=e.getSide();s===`EAST`?this.portBarycenter[e.id]=o<t?this.minBarycenter-o:this.maxBarycenter+(r-o):s===`WEST`&&(this.portBarycenter[e.id]=o<t?this.maxBarycenter+o:this.minBarycenter-(r-o))}}dealWithNorthSouthPorts(t,n,r){let i=!1,a=!1;for(let t of r.getPorts())t.getProperty(e.lr)===n&&(t.getOutgoingEdges().length>0?a=!0:t.getIncomingEdges().length>0&&(i=!0));let o=0;return i&&!(i&&a)?o=n.getSide()===`NORTH`?-this.positionOf(r):t-this.positionOf(r):a&&!(i&&a)?o=this.positionOf(r)+1:i&&a&&(o=n.getSide()===`NORTH`?0:t/2),o}positionOf(e){return this.nodePositions[this.nodeLayerIndex.get(e)][e.id]}updateNodePositions(e,t){let n=e[t];if(n.length===0)return;let r=this.nodePositions[this.nodeLayerIndex.get(n[0])];for(let e=0;e<n.length;e++){let t=n[e];r[t.id]=e}}hasNestedGraph(e){return e.getNestedGraph()!==null}isNotFirstLayer(e,t,n){return n?t!==0:t!==e-1}portTypeFor(e){return e?`OUTPUT`:`INPUT`}sortPorts(e){if(this.debugSortPorts){let t=e.getPorts().map(e=>`${e.id}:${e.getSide()}(${this.portBarycenter[e.id]})`).join(` `);console.error(`GGN sortPorts L${e.getLayer().getIndex()} node=${e.id} before=[${t}]`)}e.getPorts().sort(this.portComparator),this.debugSortPorts&&console.error(`GGN sortPorts node=${e.id} after=[${e.getPorts().map(e=>e.id).join(` `)}]`)}portComparator=(e,t)=>{let n=st[e.getSide()]??0,r=st[t.getSide()]??0;if(n!==r)return n-r;let i=this.portBarycenter[e.id],a=this.portBarycenter[t.id];return i===0&&a===0?0:i===0?-1:a===0?1:i-a};initAtLayerLevel(e,t){this.nodePositions[e]=Array(t[e].length);let n=t[e];for(let t=0;t<n.length;t++)this.nodeLayerIndex.set(n[t],e)}initAtNodeLevel(e,t,n){let r=n[e][t];r.id=t,this.nodePositions[e][t]=t}initAtPortLevel(e,t,n,r){let i=r[e][t].getPorts()[n];i.id=this.nPorts++;let a=i.getIncomingEdges(),o=i.getOutgoingEdges();this.portHasIncoming[i.id]=+(a.length>0),this.portHasOutgoing[i.id]=+(o.length>0),this.portDegrees[i.id]=a.length+o.length}initAtEdgeLevel(){}initAfterTraversal(){this.portRanks=Array(this.nPorts).fill(0),this.portBarycenter=Array(this.nPorts).fill(0)}},lt=class extends ct{constructor(e){super(e)}calculatePortRanks(e,t,n,r){let i=this.portRanks;if(r===`INPUT`){let r=0,a=0;for(let e=0;e<t.length;e++){let n=t[e],i=this.portHasIncoming[n.id];(i===1||i===void 0&&n.getIncomingEdges().length>0)&&(r++,n.getSide()===`NORTH`&&a++)}let o=n+a,s=n+r;for(let n=0;n<t.length;n++){let r=t[n],a=this.portHasIncoming[r.id];if(!(a===0||a===void 0&&r.getIncomingEdges().length===0)&&(r.getSide()===`NORTH`?(i[r.id]=o,o--):(i[r.id]=s,s--),this.debugPortRanks)){let t=r.getIncomingEdges(),n=t.length>0?`<-${t[0].getSource().getNode().id}`:``;console.error(`GGN rank INPUT node=${e.id} L${e.getLayer().getIndex()} port=${r.id} rank=${i[r.id]} conn=${n}`)}}return r}if(r===`OUTPUT`){let e=0;for(let r=0;r<t.length;r++){let a=t[r],o=this.portHasOutgoing[a.id];o===0||o===void 0&&a.getOutgoingEdges().length===0||(e++,i[a.id]=n+e)}return e}throw Error(`IllegalArgumentException`)}},ut=class extends ct{constructor(e){super(e)}calculatePortRanks(e,t,n,r){let i=this.portRanks;if(r===`INPUT`){let e=0,r=0;for(let n=0;n<t.length;n++){let i=t[n],a=this.portHasIncoming[i.id];(a===1||a===void 0&&i.getIncomingEdges().length>0)&&(e++,i.getSide()===`NORTH`&&r++)}let a=1/(e+1),o=n+r*a,s=n+1-a;for(let e=0;e<t.length;e++){let n=t[e],r=this.portHasIncoming[n.id];r===0||r===void 0&&n.getIncomingEdges().length===0||(n.getSide()===`NORTH`?(i[n.id]=o,o-=a):(i[n.id]=s,s-=a))}}else if(r===`OUTPUT`){let e=0;for(let n=0;n<t.length;n++){let r=t[n],i=this.portHasOutgoing[r.id];(i===1||i===void 0&&r.getOutgoingEdges().length>0)&&e++}let r=1/(e+1),a=n+r;for(let e=0;e<t.length;e++){let n=t[e],o=this.portHasOutgoing[n.id];o===0||o===void 0&&n.getOutgoingEdges().length===0||(i[n.id]=a,a+=r)}}else throw Error(`Port type is undefined`);return 1}};function dt(e,t,n){return e===2?new ot:t.nextBoolean()?new ut(n.length):new lt(n.length)}var ft=class{portPos;inInterlayerCache=null;outInterlayerEdges=null;hyperedgeGroupsByLayer=/* @__PURE__ */ new WeakMap;bounds=/* @__PURE__ */ new Int32Array;constructor(e,t,n){this.portPos=n}getOutInterlayerEdges(e,t){let n=this.outInterlayerEdges??=[],r=n[e.id];if(r===void 0){r=[];let i=e.getOutgoingEdges();for(let e=0;e<i.length;e++){let n=i[e];t!==n.getTarget().getNode().getLayer()&&r.push(n)}n[e.id]=r}return r}getIncomingInterlayerFlag(e,t){let n=this.inInterlayerCache??=new Uint8Array(this.portPos.length).fill(2),r=n[e.id];if(r!==2)return r;r=0;let i=e.getIncomingEdges();for(let e=0;e<i.length;e++)if(t!==i[e].getSource().getNode().getLayer()){r=1;break}return n[e.id]=r,r}buildHyperedgeGroups(e){let t=/* @__PURE__ */ new Map,n=/* @__PURE__ */ new Map,r=e=>{let n=e;for(;t.get(n)!==n;)n=t.get(n);let r=e;for(;t.get(r)!==r;){let e=t.get(r);t.set(r,n),r=e}return n},i=(e,n)=>{let i=r(e),a=r(n);i!==a&&t.set(a,i)};for(let r=0;r<e.length;r++){let a=e[r],o=a.getLayer(),s=a.getPorts();for(let e=0;e<s.length;e++){let r=s[e],a=this.getOutInterlayerEdges(r,o);if(a.length!==0){t.has(r.id)||(t.set(r.id,r.id),n.set(r.id,r));for(let e=0;e<a.length;e++){let o=a[e].getTarget();t.has(o.id)||(t.set(o.id,o.id),n.set(o.id,o)),i(r.id,o.id)}}}}let a=/* @__PURE__ */ new Map;for(let[e]of t){let t=r(e),i=a.get(t);i===void 0&&(i=[],a.set(t,i)),i.push(n.get(e))}return[...a.values()]}getHyperedgeGroups(e){let t=e[0].getLayer(),n=this.hyperedgeGroupsByLayer.get(t);return n===void 0&&(n=this.buildHyperedgeGroups(e),this.hyperedgeGroupsByLayer.set(t,n)),n}countCrossings(e,t){let n=this.getHyperedgeGroups(e),r=0;for(let t=0;t<e.length;t++){let n=e[t],i=n.getLayer(),a=n.getPorts();for(let e=0;e<a.length;e++){let t=a[e];this.getOutInterlayerEdges(t,i).length>0&&(this.portPos[t.id]=r++)}}let i=0;for(let e=0;e<t.length;e++){let n=t[e],r=n.getLayer(),a=0,o=n.getPorts();for(let e=0;e<o.length;e++){let t=o[e];if(t.getSide()!==`NORTH`)break;this.getIncomingInterlayerFlag(t,r)===1&&a++}let s=0;for(let e=o.length-1;e>=0;e--){let t=o[e];this.getIncomingInterlayerFlag(t,r)===1&&(t.getSide()===`NORTH`?(this.portPos[t.id]=i,i++):(this.portPos[t.id]=i+a+s,s++))}i+=s}let a=n.length;this.bounds.length<a*4&&(this.bounds=new Int32Array(a*4));let o=this.bounds,s=e[0].getLayer(),c=t[0].getLayer();for(let e=0;e<a;e++){let t=n[e],a=r,l=0,u=i,d=0;for(let e=0;e<t.length;e++){let n=t[e],r=this.portPos[n.id],i=n.getNode().getLayer();i===s?(r<a&&(a=r),r>l&&(l=r)):i===c&&(r<u&&(u=r),r>d&&(d=r))}let f=e*4;o[f]=a,o[f+1]=l,o[f+2]=u,o[f+3]=d}let l=0;for(let e=0;e<a;e++){let t=e*4,n=o[t],r=o[t+1],i=o[t+2],s=o[t+3];for(let t=e+1;t<a;t++){let e=t*4,a=o[e],c=o[e+1],u=o[e+2],d=o[e+3];(n<a&&i>u||a<n&&u>i)&&l++,((n>a?n:a)<(r<c?r:c)||n===r&&a<n&&n<c||a===c&&n<a&&a<r)&&l++,((i>u?i:u)<(s<d?s:d)||i===s&&u<i&&i<d||u===d&&i<u&&u<s)&&l++}}return l}};function pt(e,t){let n=[],r=[],i=[],a=[],o=[];for(let t=0;t<e.length;t++){let s=e[t];s.skipInitAtLayerLevel!==!0&&n.push(s),s.skipInitAtNodeLevel!==!0&&r.push(s),s.skipInitAtPortLevel!==!0&&i.push(s),s.skipInitAtEdgeLevel!==!0&&a.push(s),s.skipInitAfterTraversal!==!0&&o.push(s)}for(let e=0;e<t.length;e++){for(let r=0;r<n.length;r++)n[r].initAtLayerLevel(e,t);for(let n=0;n<t[e].length;n++){for(let i=0;i<r.length;i++)r[i].initAtNodeLevel(e,n,t);let o=t[e][n].getPorts();for(let r=0;r<o.length;r++){for(let a=0;a<i.length;a++)i[a].initAtPortLevel(e,n,r,t);let s=o[r],c=0,l=s.getIncomingEdges();for(let i=0;i<l.length;i++){let o=l[i];for(let i=0;i<a.length;i++)a[i].initAtEdgeLevel(e,n,r,c++,o,t)}let u=s.getOutgoingEdges();for(let i=0;i<u.length;i++){let o=u[i];for(let i=0;i<a.length;i++)a[i].initAtEdgeLevel(e,n,r,c++,o,t)}}}}for(let e=0;e<o.length;e++)o[e].initAfterTraversal()}var mt=class{skipInitAtLayerLevel=!0;crossingCounter;hyperedgeCrossingsCounter;hasHyperEdgesEastOfIndex;inLayerEdgeCounts;hasNorthSouthPorts;nPorts=0;constructor(e){this.inLayerEdgeCounts=Array(e.length).fill(0),this.hasNorthSouthPorts=Array(e.length).fill(!1),this.hasHyperEdgesEastOfIndex=Array(e.length).fill(!1)}countAllCrossings(e){if(e.length===0)return 0;let t=this.crossingCounter.countInLayerCrossingsOnSide(e[0],`WEST`);t+=this.crossingCounter.countInLayerCrossingsOnSide(e[e.length-1],`EAST`);for(let n=0;n<e.length;n++)t+=this.countCrossingsAt(n,e);return t}countCrossingsAt(e,t){let n=0,r=t[e];if(e<t.length-1){let i=t[e+1];this.hasHyperEdgesEastOfIndex[e]?(n=this.hyperedgeCrossingsCounter.countCrossings(r,i),n+=this.crossingCounter.countInLayerCrossingsOnSide(r,`EAST`),n+=this.crossingCounter.countInLayerCrossingsOnSide(i,`WEST`)):n=this.crossingCounter.countCrossingsBetweenLayers(r,i)}return this.hasNorthSouthPorts[e]&&(n+=this.crossingCounter.countNorthSouthPortCrossingsInLayer(r)),n}initAtNodeLevel(e,t,n){let r=n[e][t];this.hasNorthSouthPorts[e]=this.hasNorthSouthPorts[e]||r.getType()===`NORTH_SOUTH_PORT`}initAtPortLevel(e,t,n,r){let i=r[e][t].getPorts()[n];i.id=this.nPorts++,i.getOutgoingEdges().length+i.getIncomingEdges().length>1&&(i.getSide()===`EAST`?this.hasHyperEdgesEastOfIndex[e]=!0:i.getSide()===`WEST`&&e>0&&(this.hasHyperEdgesEastOfIndex[e-1]=!0))}initAtEdgeLevel(e,t,n,r,i,a){let o=a[e][t].getPorts()[n];i.getSource()===o&&i.getSource().getNode().getLayer()===i.getTarget().getNode().getLayer()&&this.inLayerEdgeCounts[e]++}initAtLayerLevel(){}initAfterTraversal(){let e=Array(this.nPorts);this.hyperedgeCrossingsCounter=new ft(this.inLayerEdgeCounts,this.hasNorthSouthPorts,e),this.crossingCounter=new Ze(e)}};const ht=()=>({connectedEdges:0,hierarchicalInfluence:0,randomInfluence:0});function gt(e,t){e.hierarchicalInfluence+=t.hierarchicalInfluence,e.randomInfluence+=t.randomInfluence,e.connectedEdges+=t.connectedEdges}function _t(t){let n=t.lGraph.getProperty(e.Fn);if(xt(n)||!t.hasParent||yt(t)||bt(t))return!0;if(t.crossMinDeterministic)return!1;let r=t.currentNodeOrder.map(e=>e.map(()=>ht())),i=e=>r[e.getLayer().getIndex()][e.id],a=0,o=0,s=[];for(let n of t.currentNodeOrder){for(let t of n){if(t.getType()===`NORTH_SOUTH_PORT`){s.push(t);continue}let n=i(t);t.getType()===`EXTERNAL_PORT`?(n.hierarchicalInfluence=1,wt(t)&&(o+=n.connectedEdges)):Ct(t)?n.randomInfluence=1:St(t)&&(a+=n.connectedEdges);for(let e of t.getOutgoingEdges())a+=n.randomInfluence,o+=n.hierarchicalInfluence,vt(i,n,e);for(let r of[...t.getPortSideView(`NORTH`),...t.getPortSideView(`SOUTH`)]){let t=r.getProperty(e._r);if(t!=null){a+=n.randomInfluence,o+=n.hierarchicalInfluence;let e=i(t);gt(e,n),e.connectedEdges++}}}for(let e of s){let t=i(e);for(let n of e.getOutgoingEdges())a+=t.randomInfluence,o+=t.hierarchicalInfluence,vt(i,t,n)}s.length=0}let c=a+o;return(c===0?1/0:(a-o)/c)>=n}function vt(e,t,n){let r=e(n.getTarget().getNode());gt(r,t),r.connectedEdges++}function yt(t){return e.Lr.isOrderFixed(t.parent.getProperty(e.Lt))}function bt(e){return e.parent.getPortSideView(`EAST`).length<2&&e.parent.getPortSideView(`WEST`).length<2}function xt(e){return e<-1}function St(e){let t=e.getPortSideView(`EAST`);return t.length===0||!t.some(e=>e.getConnectedEdges().length>0)}function Ct(e){let t=e.getPortSideView(`WEST`);return t.length===0||!t.some(e=>e.getConnectedEdges().length>0)}function wt(t){return t.getProperty(e.lr).getSide()===`EAST`}const Tt=[];var Et=class{nodes;index=-1;barycenter=null;outgoing=null;incoming=null;incomingCount=0;summedWeight;degree;constructor(e,t){if(t!==void 0){let n=e,r=t;this.nodes=Array(n.nodes.length+r.nodes.length);let i=0;for(let e=0;e<n.nodes.length;e++)this.nodes[i++]=n.nodes[e];for(let e=0;e<r.nodes.length;e++)this.nodes[i++]=r.nodes[e];if(n.outgoing!==null){let e=[];for(let t=0;t<n.outgoing.length;t++){let i=n.outgoing[t];i!==r&&e.push(i)}if(r.outgoing!==null)for(let t=0;t<r.outgoing.length;t++){let i=r.outgoing[t];i!==n&&(e.includes(i)?i.incomingCount--:e.push(i))}this.outgoing=e}else if(r.outgoing!==null){let e=[];for(let t=0;t<r.outgoing.length;t++){let i=r.outgoing[t];i!==n&&e.push(i)}this.outgoing=e}this.summedWeight=n.summedWeight+r.summedWeight,this.degree=n.degree+r.degree}else this.nodes=[e],this.summedWeight=0,this.degree=0}getSummedWeight(){return this.summedWeight}getDegree(){return this.degree}getOutgoing(){return this.outgoing??=[],this.outgoing}getIncoming(){return this.incoming??=[],this.incoming}resetOutgoing(){this.outgoing=null}resetIncoming(){this.incoming=null}hasOutgoing(){return this.outgoing!==null&&this.outgoing.length>0}hasIncoming(){return this.incoming!==null&&this.incoming.length>0}getBarycenter(e){return e(this.nodes[0]).barycenter}},Dt=class{skipInitAtLayerLevel=!0;skipInitAtPortLevel=!0;skipInitAtEdgeLevel=!0;skipInitAfterTraversal=!0;barycenterStates;nodeState=/* @__PURE__ */ new WeakMap;groups=/* @__PURE__ */ new Map;layoutUnits=/* @__PURE__ */ new Map;constraintsBetweenNonDummies;scratchGroups=[];constructor(t){this.barycenterStates=t.map(e=>e.map(e=>{let t=new Ot(e);return this.nodeState.set(e,t),t})),this.constraintsBetweenNonDummies=t.length>0&&t[0].length>0&&t[0][0].getGraph().getProperty(e.$n)}getBarycenterStates(){return this.barycenterStates}registerNodeState(e,t){this.nodeState.set(e,t)}initAtLayerLevel(e,t){}initAtNodeLevel(e,t,n){this.initNode(n[e][t],!0)}initNode(t,n){if(this.groups.set(t,new Et(t)),n){let n=t.getProperty(e.Zn);if(n!==null){let e=this.layoutUnits.get(n);e===void 0?this.layoutUnits.set(n,[t]):e.push(t)}}}initAtPortLevel(){}initAtEdgeLevel(){}initAfterTraversal(){}stateOf(e){return this.nodeState.get(e)}processConstraints(e){if(this.constraintsBetweenNonDummies){this.processConstraintsStage(e,!0);for(let t of e)this.initNode(t,!1)}this.processConstraintsStage(e,!1)}processConstraintsStage(e,t){let n=this.scratchGroups;n.length=0;for(let t=0;t<e.length;t++)n.push(this.groups.get(e[t]));this.buildConstraintsGraph(n,t);let r=this.findViolatedConstraint(n);for(;r!==null;)this.handleViolatedConstraint(r[0],r[1],n),r=this.findViolatedConstraint(n);e.length=0;for(let t of n){let n=t.barycenter;for(let r of t.nodes)e.push(r),this.stateOf(r).barycenter=n}}buildConstraintsGraph(t,n){for(let e of t)e.resetOutgoing(),e.incomingCount=0;let r=null;for(let i of t){let t=i.nodes[0];if(!(n&&t.getType()!==`NORMAL`)){for(let r of t.getProperty(e.Qn)??Tt)if(!n||r.getType()===`NORMAL`){let e=this.groups.get(r);if(e===void 0){let e=r.getLayer(),n=t.getLayer();console.error(`GGN_FORSTER BUG: successor id=${r.id} label=${r.getLabels()[0]?.text??`?`} type=${r.getType()} layer=${e?.getIndex()??`UNDEF`} graphParent=${r.getGraph()?.getParentNode()?`nested`:`root`} | node id=${t.id} label=${t.getLabels()[0]?.text??`?`} type=${t.getType()} layer=${n?.getIndex()??`UNDEF`} graphParent=${t.getGraph()?.getParentNode()?`nested`:`root`} | graphNodeCount=${r.getGraph()?.getAllNodes().length}`);continue}i.getOutgoing().push(e),e.incomingCount++}if(!n&&t.getType()===`NORMAL`){if(r!==null){let e=this.layoutUnits.get(r)??Tt,n=this.layoutUnits.get(t)??Tt;for(let t of e)for(let e of n){let n=this.groups.get(t),r=this.groups.get(e);n.getOutgoing().push(r),r.incomingCount++}}r=t}}}}findViolatedConstraint(e){let t=e=>this.stateOf(e);for(let n=0;n<e.length;n++){let r=e[n];r.index=n,r.barycenter=t(r.nodes[0]).barycenter}let n=[];for(let t of e)t.resetIncoming(),t.hasOutgoing()&&t.incomingCount===0&&n.push(t);let r=0;for(;r<n.length;){let e=n[r++];if(e.hasIncoming()){let t=e.barycenter;for(let n of e.getIncoming()){let r=n.barycenter;if(r===t){if(n.index>e.index)return[n,e]}else if(r>t)return[n,e]}}for(let t of e.getOutgoing())t.getIncoming().unshift(e),t.incomingCount===t.getIncoming().length&&n.push(t)}return null}handleViolatedConstraint(e,t,n){let r=e=>this.stateOf(e),i=new Et(e,t),a=e.barycenter,o=t.barycenter,s=null,c=e.getSummedWeight()+t.getSummedWeight(),l=e.getDegree()+t.getDegree();if(l>0?s=c/l:a!==null&&o!==null?s=(a+o)/2:a===null?o!==null&&(s=o):s=a,s!==null)for(let e of i.nodes)this.stateOf(e).barycenter=s;i.barycenter=s;let u=!1;for(let a=0;a<n.length;a++){let o=n[a];if(o===e||o===t)n.splice(a,1),a--;else if(!u&&(o.getBarycenter(r)??0)>(i.getBarycenter(r)??0))n.splice(a,0,i),u=!0;else if(o.hasOutgoing()){let n=o.getOutgoing(),r=!0,a=!0,s=!1;for(let i=0;i<n.length;){let o=n[i];r&&o===e?(n.splice(i,1),r=!1,s=!0):a&&o===t?(n.splice(i,1),a=!1,s=!0):i++}s&&(n.push(i),i.incomingCount++)}}u||n.push(i)}},Ot=class{node;summedWeight=0;degree=0;barycenter=null;visited=!1;visitedGeneration=-1;forwardAdjacency=[];backwardAdjacency=[];constructor(e){this.node=e}};const kt=.07;function At(e){return e.getAllProperties().get(`org.eclipse.elk.hierarchyHandling`)===`SEPARATE_CHILDREN`}function jt(e){let t=e.getPorts();for(let e=0;e<t.length;e++){let n=t[e];if(n.getIncomingEdges().length>0||n.getOutgoingEdges().length>0)return!1}return!0}var Mt=class{skipInitAtPortLevel=!0;skipInitAtEdgeLevel=!0;portRanks;random;constraintResolver;barycenterState;portDistributor;barycenterSortStates=null;layerStates=/* @__PURE__ */ new WeakMap;debugBarycenter=!1;barycenterVisitGeneration=0;nextBarycenterScratch=[];barycenterAssociates=/* @__PURE__ */ new WeakMap;hasBarycenterAssociates=!1;separateBlackBoxes=/* @__PURE__ */ new WeakSet;hasSeparateBlackBoxes=!1;constructor(t,n,r,i){this.constraintResolver=t,this.random=n,this.portDistributor=r,this.barycenterState=t.getBarycenterStates();for(let t=0;t<i.length;t++){let n=i[t];for(let t=0;t<n.length;t++){let r=n[t],i=r.getProperty(e.On);i!=null&&i.length>0&&(this.barycenterAssociates.set(r,i),this.hasBarycenterAssociates=!0),At(r)&&(this.separateBlackBoxes.add(r),this.hasSeparateBlackBoxes=!0)}}}minimizeLayer(e,t,n,r){this.debugBarycenter=!1,n?this.randomizeBarycenters(e):(this.calculateBarycenters(e,r),this.fillInUnknownBarycenters(e,t)),e.length>1&&(this.barycenterSortStates=this.statesForLayer(e),e.sort(this.barycenterIndexStateComparator),this.barycenterSortStates=null,this.constraintResolver.processConstraints(e))}randomizeBarycenters(e){for(let t=0;t<e.length;t++){let n=e[t],r=this.hasSeparateBlackBoxes&&this.separateBlackBoxes.has(n)&&jt(n)?Number.MAX_VALUE:this.random.nextDouble(),i=this.stateOf(n);i.barycenter=r,i.summedWeight=r,i.degree=1}}fillInUnknownBarycenters(e,t){if(e.length===0)return;let n=this.statesForLayer(e);if(this.hasSeparateBlackBoxes)for(let t=0;t<e.length;t++){let r=e[t],i=n[r.id];i.barycenter===null&&this.separateBlackBoxes.has(r)&&jt(r)&&(i.barycenter=Number.MAX_VALUE,i.summedWeight=Number.MAX_VALUE,i.degree=1)}if(t){let t=this.nextBarycenterScratch;t.length=e.length;let r=null;for(let i=e.length-1;i>=0;i--){t[i]=r;let a=n[e[i].id].barycenter;a!==null&&(r=a)}let i=-1;for(let r=0;r<e.length;r++){let a=n[e[r].id],o=a.barycenter;if(o===null){let e=i+1,n=t[r];n!==null&&(e=n),o=(i+e)/2,a.barycenter=o,a.summedWeight=o,a.degree=1}i=o}}else{let t=0;for(let r=0;r<e.length;r++){let i=n[e[r].id].barycenter;i!==null&&(t=Math.max(t,i))}t+=2;for(let r=0;r<e.length;r++){let i=n[e[r].id];if(i.barycenter===null){let e=this.random.nextFloat()*t-1;i.barycenter=e,i.summedWeight=e,i.degree=1}}}}calculateBarycenters(e,t){if(e.length===0)return;let n=++this.barycenterVisitGeneration,r=this.statesForLayer(e);for(let i=0;i<e.length;i++)this.calculateBarycenter(e[i],t,n,r)}calculateBarycenter(e,t,n,r){let i=r[e.id];if(i.visitedGeneration===n)return;i.visitedGeneration=n,i.degree=0,i.summedWeight=0,i.barycenter=null;let a=e.getLayer(),o=t?i.forwardAdjacency:i.backwardAdjacency;for(let e=0;e<o.length;e++){let a=o[e];if(a>=0){let e=r[a].node,o=r[a];this.calculateBarycenter(e,t,n,r),i.degree+=o.degree,i.summedWeight+=o.summedWeight}else i.summedWeight+=this.portRanks[-a-1],i.degree++}if(this.hasBarycenterAssociates){let o=this.barycenterAssociates.get(e);if(o!==void 0)for(let e=0;e<o.length;e++){let s=o[e];if(s.getLayer()===a){let e=r[s.id];this.calculateBarycenter(s,t,n,r),i.degree+=e.degree,i.summedWeight+=e.summedWeight}}}if(i.degree>0){let t=this.random.nextFloat();if(i.summedWeight+=t*kt-kt/2,i.barycenter=i.summedWeight/i.degree,this.debugBarycenter){let t=e.getType().toString()===`NORMAL`?e.getLabels()[0]?.text??e.id:e.id,n=[];for(let t of e.getPorts()){for(let e of t.getSuccessorPorts()){let r=e.getNode(),i=r?.getType().toString()===`NORMAL`?r?.getLabels()[0]?.text??r?.id:r?.id;n.push(t.id+`->`+i+`:`+(this.portRanks[e.id]??`?`))}for(let e of t.getPredecessorPorts()){let r=e.getNode(),i=r?.getType().toString()===`NORMAL`?r?.getLabels()[0]?.text??r?.id:r?.id;n.push(i+`->`+t.id+`:`+(this.portRanks[e.id]??`?`))}}console.error(`GGN_BD ${t} L${e.getLayer()?.getIndex()} degree=${this.stateOf(e).degree} sw=${this.stateOf(e).summedWeight.toFixed(4)} bc=${this.stateOf(e).barycenter.toFixed(4)} [${n.join(` `)}]`)}}}statesForLayer(e){let t=e[0].getLayer();return this.layerStates.get(t)??this.barycenterState[t.getIndex()]}stateOf(e){return this.constraintResolver.stateOf(e)}barycenterIndexStateComparator=(e,t)=>{let n=this.barycenterSortStates,r=n[e.id],i=n[t.id];return r.barycenter!==null&&i.barycenter!==null?r.barycenter-i.barycenter:r.barycenter===null?i.barycenter===null?0:1:-1};barycenterStateComparator=(e,t)=>{let n=this.stateOf(e),r=this.stateOf(t);return n.barycenter!==null&&r.barycenter!==null?n.barycenter-r.barycenter:n.barycenter===null?r.barycenter===null?0:1:-1};minimizeCrossings(e,t,n,r){if(!this.isFirstLayer(e,t,n)){let r=e[t-this.changeIndex(n)];this.portDistributor.calculatePortRanksForLayer(r,this.portTypeFor(n))}let i=e[t][0],a=!r||this.isExternalPortDummy(i);return this.minimizeLayer(e[t],a,!1,n),!1}setFirstLayerOrder(e,t){let n=this.startIndex(t,e.length);return this.minimizeLayer(e[n],!1,!0,t),!1}isFirstLayer(e,t,n){return n?t===0:t===e.length-1}changeIndex(e){return e?1:-1}startIndex(e,t){return e?0:t-1}isExternalPortDummy(e){return e.getType()===`EXTERNAL_PORT`}portTypeFor(e){return e?`OUTPUT`:`INPUT`}alwaysImproves(){return!1}isDeterministic(){return!1}initAtLayerLevel(e,t){this.barycenterState[e]=Array(t[e].length)}initAtNodeLevel(e,t,n){let r=new Ot(n[e][t]);this.barycenterState[e][t]=r,this.constraintResolver.registerNodeState(n[e][t],r)}initAtPortLevel(){}initAtEdgeLevel(){}initAfterTraversal(){this.portRanks=this.portDistributor.getPortRanks();for(let e=0;e<this.barycenterState.length;e++){let t=this.barycenterState[e];if(t.length>0){let e=t[0].node.getLayer();e!==null&&this.layerStates.set(e,t)}}this.buildBarycenterAdjacency()}buildBarycenterAdjacency(){for(let e=0;e<this.barycenterState.length;e++){let t=this.barycenterState[e];for(let e=0;e<t.length;e++){let n=t[e].node,r=n.getLayer(),i=[],a=[],o=n.getPorts();for(let e=0;e<o.length;e++){let t=o[e];for(let e of t.getIncomingEdges()){let t=e.getSource();if(t===null)continue;let a=t.getNode();a.getLayer()===r?a!==n&&i.push(a.id):i.push(-(t.id+1))}for(let e of t.getOutgoingEdges()){let t=e.getTarget();if(t===null)continue;let i=t.getNode();i.getLayer()===r?i!==n&&a.push(i.id):a.push(-(t.id+1))}}t[e].forwardAdjacency=i,t[e].backwardAdjacency=a}}}};function O(t,n,r,i){let a=r.getProperty(e.S)===`ENFORCED`,o=r.getProperty(e.x);if(!t.hasProperty(e.cr))return-1;if(a){if(o.includes(t.getProperty(e.C))&&o.includes(n.getProperty(e.C)))return i*(t.getProperty(e.C)??0)+t.getProperty(e.cr)}else return t.getProperty(e.cr);return t.getProperty(e.cr)}const k=new e.ai(`medianHeuristic.weight`),Nt=Number.MIN_VALUE,Pt=Number.MAX_VALUE;function Ft(e){return e.getAllProperties().get(`org.eclipse.elk.hierarchyHandling`)===`SEPARATE_CHILDREN`}function It(e){return e.getIncomingEdges().length===0&&e.getOutgoingEdges().length===0}var Lt=class{skipInitAtLayerLevel=!0;skipInitAtNodeLevel=!0;skipInitAtPortLevel=!0;skipInitAtEdgeLevel=!0;skipInitAfterTraversal=!0;random;constructor(e){this.random=e}alwaysImproves(){return!1}isDeterministic(){return!0}setFirstLayerOrder(e,t){let n=t?0:Math.max(0,e.length-1),r=[...e[n]];for(let e of r)e.setProperty(k,Ft(e)&&It(e)?Pt:this.random.nextDouble());r.sort(this.weightComparator);let i=0;for(let t of r)e[n][i++]=t,t.setProperty(k,i);return!1}minimizeCrossings(e,t,n,r){let i=[...e[t]];this.calculateMedians(i,n?t-1:t+1),i.sort(this.weightComparator);let a=0;for(let n of i)e[t][a++]=n;return!1}calculateMedians(e,t){let n=Nt,r=Pt,i=[];for(let a of e){let e=[];for(let n of a.getIncomingEdges())this.addAdjacentNodeInReferenceLayer(n,t,e);for(let n of a.getOutgoingEdges())this.addAdjacentNodeInReferenceLayer(n,t,e);if(e.length===0)i.push(a);else{e.sort(this.weightComparator);let t=e[Math.floor(e.length/2)].getProperty(k);a.setProperty(k,t),n=Math.min(n,t),r=Math.max(r,t)}}let a=(r+n)/2;for(let e of i)e.setProperty(k,a)}addAdjacentNodeInReferenceLayer(e,t,n){let r=e.getTarget().getNode(),i=e.getSource().getNode();r.getLayer().getIndex()===t&&n.push(r),i.getLayer().getIndex()===t&&n.push(i)}weightComparator=(e,t)=>e.hasProperty(k)?t.hasProperty(k)?Rt(e.getProperty(k),t.getProperty(k)):-1:1;initAtLayerLevel(e,t){}initAtNodeLevel(e,t,n){}initAtPortLevel(e,t,n,r){}initAtEdgeLevel(e,t,n,r,i,a){}initAfterTraversal(){}};function Rt(e,t){return e<t?-1:e>t?1:e===t?e===0?Object.is(e,-0)===Object.is(t,-0)?0:Object.is(e,-0)?-1:1:0:Number.isNaN(e)?+!Number.isNaN(t):-1}var zt=class t extends Mt{biggerThan=/* @__PURE__ */ new Map;smallerThan=/* @__PURE__ */ new Map;constructor(t,n,r,i){super(t,n,r,i),this.barycenterStateComparator=(t,n)=>{if(t.getLayerConstraint()===`FIRST_SEPARATE`||t.getLayerConstraint()===`LAST_SEPARATE`||n.getLayerConstraint()===`FIRST_SEPARATE`||n.getLayerConstraint()===`LAST_SEPARATE`)return 0;let r=t.getGraph(),i=this.compareBasedOnTansitiveDependencies(t,n);if(i!==0)return i;if(t.hasProperty(e.cr)&&n.hasProperty(e.cr)){let i=Math.sign(O(t,n,r,r.getProperty(e.sr))-O(n,t,r,r.getProperty(e.sr)));if(r.getProperty(e.S)===`ONLY_WITHIN_GROUP`&&t.getProperty(e.C)!==n.getProperty(e.C)&&(i=0),i<0)return this.updateBiggerAndSmallerAssociations(n,t),i;if(i>0)return this.updateBiggerAndSmallerAssociations(t,n),i}return this.compareBasedOnBarycenter(t,n)}}minimizeLayer(n,r,i,a){if(i?this.randomizeBarycenters(n):(this.calculateBarycenters(n,a),this.fillInUnknownBarycenters(n,r)),n.length>1){let r=n[0].getGraph().getProperty(e.Pn);r?t.insertionSort(n,this.barycenterStateComparator,this):n.sort(this.barycenterStateComparator),r||this.constraintResolver.processConstraints(n)}}compareBasedOnTansitiveDependencies(e,t){if(!this.biggerThan.has(e))this.biggerThan.set(e,/* @__PURE__ */ new Set);else if(this.biggerThan.get(e).has(t))return 1;if(!this.biggerThan.has(t))this.biggerThan.set(t,/* @__PURE__ */ new Set);else if(this.biggerThan.get(t).has(e))return-1;if(!this.smallerThan.has(e))this.smallerThan.set(e,/* @__PURE__ */ new Set);else if(this.smallerThan.get(e).has(t))return-1;if(!this.smallerThan.has(t))this.smallerThan.set(t,/* @__PURE__ */ new Set);else if(this.smallerThan.get(t).has(e))return 1;return 0}compareBasedOnBarycenter(e,t){let n=this.stateOf(e),r=this.stateOf(t);if(n.barycenter!==null&&r.barycenter!==null){let i=Rt(n.barycenter,r.barycenter);return i<0?this.updateBiggerAndSmallerAssociations(t,e):i>0&&this.updateBiggerAndSmallerAssociations(e,t),i}return n.barycenter===null?r.barycenter===null?0:(this.updateBiggerAndSmallerAssociations(e,t),1):(this.updateBiggerAndSmallerAssociations(t,e),-1)}updateBiggerAndSmallerAssociations(e,t){let n=this.biggerThan.get(e),r=this.biggerThan.get(t),i=this.smallerThan.get(e),a=this.smallerThan.get(t);n.add(t),a.add(e);for(let t of r){n.add(t);let r=this.smallerThan.get(t);r.add(e);for(let e of i)r.add(e)}for(let e of i){a.add(e);let n=this.biggerThan.get(e);n.add(t);for(let e of r)n.add(e)}}static insertionSort(e,t,n){for(let n=1;n<e.length;n++){let r=e[n],i=n;for(;i>0&&t(e[i-1],r)>0;)e[i]=e[i-1],i--;e[i]=r}n.clearTransitiveOrdering()}clearTransitiveOrdering(){this.biggerThan=/* @__PURE__ */ new Map,this.smallerThan=/* @__PURE__ */ new Map}},Bt=class{skipInitAtLayerLevel=!0;skipInitAtEdgeLevel=!0;_lGraph;_currentNodeOrder;_currentlyBestNodeAndPortOrder=null;_bestNodeAndPortOrder=null;_portPositions=[];_useBottomUp=!1;_childGraphs=[];_hasExternalPorts=!1;_hasParent=!1;_parentGraphData=null;_parent=null;_crossMinimizer;_portDistributor;_crossingsCounter;_nPorts=0;constructor(t,n,r){this._lGraph=t,this._currentNodeOrder=t.toNodeArray(),this._parent=this._lGraph.getParentNode(),this._hasParent=this._parent!==null,this._parentGraphData=this._hasParent?r[this._parent.getGraph().id]:null;let i=this._lGraph.getProperty(e.Gn);this._hasExternalPorts=i.has(`EXTERNAL_PORTS`),this._crossingsCounter=new mt(this._currentNodeOrder);let a=this._lGraph.getProperty(e.br);this._portDistributor=dt(n,a,this._currentNodeOrder);let o=[this,this._crossingsCounter,this._portDistributor],s=t.getProperty(e.Pn);if(n===0&&!s){let e=new Dt(this._currentNodeOrder);o.push(e),this._crossMinimizer=new Mt(e,a,this._portDistributor,this._currentNodeOrder)}else if(n===0&&s){let e=new Dt(this._currentNodeOrder);o.push(e),this._crossMinimizer=new zt(e,a,this._portDistributor,this._currentNodeOrder)}else if(n===3)this._crossMinimizer=new Lt(a);else if(n===1||n===2)this._crossMinimizer=new at(n,this);else throw Error(`CrossMinType ${n} 未实现`);o.push(this._crossMinimizer),pt(o,this._currentNodeOrder),this._useBottomUp=_t(this)}dontSweepInto(){return this._useBottomUp}get lGraph(){return this._lGraph}get currentNodeOrder(){return this._currentNodeOrder}get currentlyBestNodeAndPortOrder(){return this._currentlyBestNodeAndPortOrder}setCurrentlyBestNodeAndPortOrder(e){this._currentlyBestNodeAndPortOrder=e}get bestNodeNPortOrder(){return this._bestNodeAndPortOrder}setBestNodeNPortOrder(e){this._bestNodeAndPortOrder=e}get crossCounter(){return this._crossingsCounter}get crossMinimizer(){return this._crossMinimizer}get portDistributor(){return this._portDistributor}get parent(){return this._parent}get hasParent(){return this._hasParent}get childGraphs(){return this._childGraphs}get hasExternalPorts(){return this._hasExternalPorts}get parentGraphData(){return this._parentGraphData}get crossMinDeterministic(){return this._crossMinimizer.isDeterministic()}get crossMinAlwaysImproves(){return this._crossMinimizer.alwaysImproves()}get getBestSweep(){return this._crossMinimizer.isDeterministic()?this._currentlyBestNodeAndPortOrder:this._bestNodeAndPortOrder}get portPositions(){return this._portPositions}initAtLayerLevel(){}initAtNodeLevel(e,t,n){let r=n[e][t].getNestedGraph();r!==null&&this._childGraphs.push(r)}initAtPortLevel(){this._nPorts++}initAtEdgeLevel(){}initAfterTraversal(){this._portPositions=Array(this._nPorts)}};function Vt(t,n){let r={NORTH:0,EAST:1,SOUTH:2,WEST:3},i=r[t.getSide()]??0,a=r[n.getSide()]??0;if(i!==a)return i-a;let o=t.getNode().getProperty(e.Lt);if(!e.Lr.isOrderFixed(o))return 0;if(o===`FIXED_ORDER`){let r=t.getProperty(e.Rt),i=n.getProperty(e.Rt);if(r!==null&&i!==null&&r-i!==0)return r-i}switch(t.getSide()){case`NORTH`:return t.getPosition().x-n.getPosition().x;case`EAST`:return t.getPosition().y-n.getPosition().y;case`SOUTH`:return n.getPosition().x-t.getPosition().x;case`WEST`:return n.getPosition().y-t.getPosition().y;default:return 0}}var Ht=class t{nodeOrder;portOrders;constructor(e){if(e instanceof t){let n=e;this.nodeOrder=t.deepCopy(n.nodeOrder),this.portOrders=[...n.portOrders]}else{this.nodeOrder=t.deepCopy(e);let n=Array(e.length);this.portOrders=n;for(let t=0;t<e.length;t++){let r=e[t],i=Array(r.length);n[t]=i;for(let e=0;e<r.length;e++)i[e]=r[e].getPorts().slice()}}}static deepCopy(e){if(e===null)return null;let t=Array(e.length);for(let n=0;n<e.length;n++)t[n]=e[n].slice();return t}nodes(){return this.nodeOrder}transferNodeAndPortOrdersToGraph(t,n){let r=[],i=/* @__PURE__ */ new Set,a=t.getLayers();for(let t=0;t<a.length;t++){let o=a[t].getNodes();r.length=0;for(let i=0;i<o.length;i++){let o=this.nodeOrder[t][i];if(o.id=i,o.getType()===`NORTH_SOUTH_PORT`&&r.push(o),a[t].getNodes()[i]=o,o.getPorts().length=0,o.getPorts().push(...this.portOrders[t][i]),n){let t=o.getProperty(e.Lt);e.Lr.isOrderFixed(t)||o.setProperty(e.Lt,`FIXED_ORDER`)}}for(let e of r){let t=this.assertCorrectPortSides(e);i.add(t),i.add(e)}}for(let e of i)e.getPorts().sort(Vt)}assertCorrectPortSides(t){let n=t.getProperty(e.Zn),r=t.getPorts()[0];for(let i of n.getPorts())if(i===r.getProperty(e.lr)){if(i.getSide()===`NORTH`&&t.id>n.id){if(i.setSide(`SOUTH`),i.isExplicitlySuppliedPortAnchor()){let e=i.getSize().y,t=i.getAnchor().y;i.getAnchor().y=e-t}}else if(i.getSide()===`SOUTH`&&n.id>t.id&&(i.setSide(`NORTH`),i.isExplicitlySuppliedPortAnchor())){let e=i.getSize().y,t=i.getAnchor().y;i.getAnchor().y=-(e-t)}break}return n}},Ut=class{graphInfoHolders=[];graphsWhoseNodeOrderChanged=/* @__PURE__ */ new Set;random;randomSeed=1;crossMinType;constructor(e){this.crossMinType=e}process(t,n){n.begin(`Minimize Crossings ${this.crossMinType}`,1);let r=t.getLayers().length===0||t.getLayers().every(e=>e.getNodes().length===0),i=t.getLayers().length===1&&t.getLayers()[0].getNodes().length===1,a=t.getProperty(e.q)===`INCLUDE_CHILDREN`;if(r||i&&!a){n.done();return}let o=this.initialize(t),s=this.chooseMinimizingMethod(o);for(let e of o)e.currentNodeOrder.length>0&&(s(e),e.hasParent&&this.setPortOrderOnParentGraph(e));this.transferNodeAndPortOrdersToGraph(),n.done()}chooseMinimizingMethod(e){if(e.length===0)return()=>{};let t=e[0];return t.crossMinDeterministic?t.crossMinAlwaysImproves?e=>this.minimizeCrossingsNoCounter(e):e=>this.minimizeCrossingsWithCounter(e):e=>this.compareDifferentRandomizedLayouts(e)}minimizeCrossingsNoCounter(e){let t=this.random.nextBoolean(),n=!0;for(;n;)n=!1,n=e.crossMinimizer.setFirstLayerOrder(e.currentNodeOrder,t),n=this.sweepReducingCrossings(e,t,!1)||n,t=!t;this.setCurrentlyBestNodeOrders()}compareDifferentRandomizedLayouts(t){this.random.setSeed(this.randomSeed),this.graphsWhoseNodeOrderChanged.clear();let n=2**53-1,r=t.lGraph.getProperty(e.mn);for(let e=0;e<r;e++){let e=this.minimizeCrossingsWithCounter(t);if(e<n&&(n=e,this.saveAllNodeOrdersOfChangedGraphs(),n===0))break}}minimizeCrossingsWithCounter(e){let t=this.random.nextBoolean();this.countCurrentNumberOfCrossings(e),e.crossMinimizer.setFirstLayerOrder(e.currentNodeOrder,t),this.sweepReducingCrossings(e,t,!0);let n=this.countCurrentNumberOfCrossings(e),r,i=2;do{if(i++,this.setCurrentlyBestNodeOrders(),n===0)return 0;t=!t,r=n,this.sweepReducingCrossings(e,t,!1),n=this.countCurrentNumberOfCrossings(e)}while(r>n);return r}countCurrentNumberOfCrossings(e){let t=0,n=[e];for(;n.length>0;){let e=n.pop();t+=e.crossCounter.countAllCrossings(e.currentNodeOrder);for(let n of e.childGraphs){let e=this.graphInfoHolders[n.id];e&&!e.dontSweepInto()&&(t+=this.countCurrentNumberOfCrossings(e))}}return t}sweepReducingCrossings(e,t,n){let r=e.currentNodeOrder,i=r.length,a=e.portDistributor.distributePortsWhileSweeping(r,this.firstIndex(t,i),t),o=r[this.firstIndex(t,i)];a=this.sweepInHierarchicalNodes(o,t,n)||a;for(let o=this.firstFree(t,i);this.isNotEnd(i,o,t);o+=this.next(t))a=e.crossMinimizer.minimizeCrossings(r,o,t,n)||a,a=e.portDistributor.distributePortsWhileSweeping(r,o,t)||a,a=this.sweepInHierarchicalNodes(r[o],t,n)||a;return this.graphsWhoseNodeOrderChanged.add(e),a}sweepInHierarchicalNodes(e,t,n){let r=!1;for(let i of e)this.hasNestedGraph(i)&&!this.graphInfoHolders[i.getNestedGraph().id].dontSweepInto()&&(r=this.sweepInHierarchicalNode(t,i,n)||r);return r}sweepInHierarchicalNode(e,t,n){let r=t.getNestedGraph(),i=this.graphInfoHolders[r.id],a=i.currentNodeOrder,o=this.firstIndex(e,a.length),s=a[o][0];this.isExternalPortDummy(s)?a[o]=this.sortPortDummiesByPortPositions(t,a[o],this.sideOpposedSweepDirection(e)):i.crossMinimizer.setFirstLayerOrder(a,e);let c=this.sweepReducingCrossings(i,e,n);return this.sortPortsByDummyPositionsInLastLayer(i.currentNodeOrder,i.parent,e),c}sortPortsByDummyPositionsInLastLayer(e,t,n){let r=e[this.endIndex(n,e.length)],i=this.firstIndex(n,r.length);if(!this.isExternalPortDummy(r[i]))return;let a=[];for(let e=0;e<r.length;e++){let t=r[e];if(this.isExternalPortDummy(t)){let e=this.originPort(t);e!=null&&typeof e.getSide==`function`&&a.push(t)}}let o=t.getPorts(),s=n?0:a.length-1,c=n?1:-1;for(let e=0;e<o.length;e++){let t=o[e];this.isOnEndOfSweepSide(t,n)&&this.isHierarchical(t)&&s>=0&&s<a.length&&(o[e]=this.originPort(a[s]),s+=c)}}sortPortDummiesByPortPositions(e,t,n){let r=e.getPortSideView(n),i=Array(t.length),a=0;if(n===`EAST`||n===`NORTH`)for(let e=0;e<r.length;e++){let t=r[e];this.isHierarchical(t)&&(i[a++]=this.dummyNodeFor(t))}else for(let e=r.length-1;e>=0;e--){let t=r[e];this.isHierarchical(t)&&(i[a++]=this.dummyNodeFor(t))}if(a<t.length)throw Error(`IllegalStateException: Expected ${t.length} hierarchical ports, but found only ${a}.`);return i}setPortOrderOnParentGraph(t){if(t.hasExternalPorts&&t.getBestSweep!==null){let n=t.getBestSweep;this.sortPortsByDummyPositionsInLastLayer(n.nodes(),t.parent,!0),this.sortPortsByDummyPositionsInLastLayer(n.nodes(),t.parent,!1),t.parent.setProperty(e.Lt,`FIXED_ORDER`)}}saveAllNodeOrdersOfChangedGraphs(){for(let e of this.graphsWhoseNodeOrderChanged)e.setBestNodeNPortOrder(new Ht(e.currentlyBestNodeAndPortOrder))}setCurrentlyBestNodeOrders(){for(let e of this.graphsWhoseNodeOrderChanged)e.setCurrentlyBestNodeAndPortOrder(new Ht(e.currentNodeOrder))}firstIndex(e,t){return e?0:t-1}endIndex(e,t){return e?t-1:0}firstFree(e,t){return e?1:t-2}next(e){return e?1:-1}isNotEnd(e,t,n){return n?t<e:t>=0}hasNestedGraph(e){return e.getNestedGraph()!==null}sideOpposedSweepDirection(e){return e?`WEST`:`EAST`}isExternalPortDummy(e){return e.getType()===`EXTERNAL_PORT`}originPort(t){return t.getProperty(e.lr)}isHierarchical(t){return t.getProperty(e.Xn)}dummyNodeFor(t){return t.getProperty(e._r)}isOnEndOfSweepSide(e,t){return t?e.getSide()===`EAST`:e.getSide()===`WEST`}initialize(t){this.graphInfoHolders=[];let n=t.getProperty(e.br);n===void 0&&(n=new i(t.getProperty(e.Kt)),t.setProperty(e.br,n)),this.random=n,this.randomSeed=this.random.nextLong();let r=[],a=[t],o=0;for(;o<a.length;){let t=a[o];t.id=o++,t.getProperty(e.br)===void 0&&t.setProperty(e.br,n);let i=new Bt(t,this.crossMinType,this.graphInfoHolders);a.push(...i.childGraphs),this.graphInfoHolders.push(i),i.dontSweepInto()&&r.unshift(i)}return this.graphsWhoseNodeOrderChanged=/* @__PURE__ */ new Set,r}transferNodeAndPortOrdersToGraph(){for(let e of this.graphInfoHolders){let t=e.getBestSweep;t!==null&&t.transferNodeAndPortOrdersToGraph(e.lGraph,!0)}}getGraphData(){return this.graphInfoHolders}},Wt=class{process(t){let n=0;for(let e of t.getLayers())e.id=n++;let r=t.toNodeArray(),i=new ut(r.length);pt([i],r);let a=0;n=0;for(let o of t.getLayers()){let t=0,s=0;for(let e of o.getNodes()){e.getPosition().x>0&&(t+=e.getPosition().x+e.getSize().x/2,s++);for(let t of e.getPorts())t.id=a++}s>0&&(t/=s);let c=Array(o.getNodes().length),l=0;for(let n of o.getNodes())n.id=l++,c[n.id]=Gt(n,t),n.getType()===`LONG_EDGE`&&n.setProperty(e.dr,c[n.id]);o.getNodes().sort((t,n)=>{let r=c[t.id]-c[n.id];if(r===0){let r=t.getProperty(e.Qn)??[],i=n.getProperty(e.Qn)??[];if(r.includes(n))return-1;if(i.includes(t))return 1}return r}),i.distributePortsWhileSweeping(r,n,!0),n++}}};function Gt(t,n){switch(t.getType()){case`LONG_EDGE`:{let r=t.getProperty(e.lr),i=(r?.getProperty(e.ur)??[]).slice();r?.getProperty(e.Sr)&&i.reverse();let a=t.getProperty(e.rr);if(a){let e=a.getAbsoluteAnchor();if(n<=e.x)return e.y;i.unshift(e)}let o=t.getProperty(e.ir);if(o){let e=o.getAbsoluteAnchor();if(e.x<=n)return e.y;i.push(e)}if(i.length>=2){let e=i[0],t=i[1],r=2;for(;t.x<n&&r<i.length;)e=t,t=i[r++];return e.y+(n-e.x)/(t.x-e.x)*(t.y-e.y)}break}case`NORTH_SOUTH_PORT`:{let n=t.getPorts()[0]?.getProperty(e.lr),r=n?.getNode();if(r&&n){if(n.getSide()===`NORTH`)return r.getPosition().y;if(n.getSide()===`SOUTH`)return r.getPosition().y+r.getSize().y}break}}return t.getGraph()?.getProperty(e.tt)===`TOP_LEFT`?t.getPosition().y:t.getPosition().y+t.getSize().y/2}function Kt(e,t){return{first:e,second:t}}var qt=class t{nodeCount=0;layerIndex=[];nodeIndex=[];leftNeighbors=[];rightNeighbors=[];static buildFor(e){let n=new t;n.nodeCount=0;for(let t of e.getLayers())n.nodeCount+=t.getNodes().length;let r=0,i=0;n.layerIndex=Array(e.getLayers().length);let a=0;n.nodeIndex=Array(n.nodeCount);for(let t of e.getLayers()){t.id=r++,n.layerIndex[t.id]=i++;let e=0;for(let r of t.getNodes())r.id=a++,n.nodeIndex[r.id]=e++}return n.leftNeighbors=[],t.determineAllLeftNeighbors(n,e),n.rightNeighbors=[],t.determineAllRightNeighbors(n,e),n}static determineAllLeftNeighbors(t,n){for(let r of n.getLayers())for(let n of r.getNodes()){let r=[],i=0;for(let t of n.getIncomingEdges()){if(t.isSelfLoop()||t.isInLayerEdge())continue;let n=t.getProperty(e.Gt);n>i&&(i=n,r.length=0),n===i&&r.push(Kt(t.getSource().getNode(),t))}r.sort((e,n)=>Math.sign(t.nodeIndex[e.first.id]-t.nodeIndex[n.first.id])),t.leftNeighbors[n.id]=r}}static determineAllRightNeighbors(t,n){for(let r of n.getLayers())for(let n of r.getNodes()){let r=[],i=0;for(let t of n.getOutgoingEdges()){if(t.isSelfLoop()||t.isInLayerEdge())continue;let n=t.getProperty(e.Gt);n>i&&(i=n,r.length=0),n===i&&r.push(Kt(t.getTarget().getNode(),t))}r.sort((e,n)=>Math.sign(t.nodeIndex[e.first.id]-t.nodeIndex[n.first.id])),t.rightNeighbors[n.id]=r}}cleanup(){this.leftNeighbors=[],this.rightNeighbors=[]}},Jt=class{root=[];blockSize=/* @__PURE__ */ new Float64Array;align=[];innerShift=/* @__PURE__ */ new Float64Array;sink=[];shift=/* @__PURE__ */ new Float64Array;y=/* @__PURE__ */ new Float64Array;vdir;hdir;su=/* @__PURE__ */ new Uint8Array;od=/* @__PURE__ */ new Uint8Array;layeredGraph;spacings;constructor(t,n,r,i){this.layeredGraph=t,this.spacings=t.getProperty(e.wr),this.root=Array(n),this.blockSize=new Float64Array(n),this.align=Array(n),this.innerShift=new Float64Array(n),this.sink=Array(n),this.shift=new Float64Array(n),this.y=new Float64Array(n),this.su=new Uint8Array(n),this.od=new Uint8Array(n),this.od.fill(1),this.vdir=r,this.hdir=i}cleanup(){this.root=[],this.blockSize=/* @__PURE__ */ new Float64Array,this.align=[],this.innerShift=/* @__PURE__ */ new Float64Array,this.sink=[],this.shift=/* @__PURE__ */ new Float64Array,this.y=/* @__PURE__ */ new Float64Array}layoutSize(){let e=1/0,t=-1/0;for(let n of this.layeredGraph.getLayers())for(let r of n.getNodes()){let n=this.y[r.id],i=n+this.blockSize[this.root[r.id].id];e=Math.min(e,n),t=Math.max(t,i)}return t-e}calculateDelta(e,t){let n=this.y[e.getNode().id]+this.innerShift[e.getNode().id]+e.getPosition().y+e.getAnchor().y;return this.y[t.getNode().id]+this.innerShift[t.getNode().id]+t.getPosition().y+t.getAnchor().y-n}shiftBlock(e,t){let n=e;do this.y[n.id]+=t,n=this.align[n.id];while(n!==e)}checkSpaceAbove(e,t,n){let r=t,i=e,a=i;do{a=this.align[a.id];let e=this.getMinY(a),t=this.getUpperNeighbor(a,n);if(t!==null){let n=this.getMaxY(t);r=Math.min(r,e-(n+this.spacings.getVerticalSpacing(a,t)))}}while(i!==a);return r}checkSpaceBelow(e,t,n){let r=t,i=e,a=i;do{a=this.align[a.id];let e=this.getMaxY(a),t=this.getLowerNeighbor(a,n);if(t!==null){let n=this.getMinY(t);r=Math.min(r,n-(e+this.spacings.getVerticalSpacing(a,t)))}}while(i!==a);return r}getMinY(e){let t=this.root[e.id];return this.y[t.id]+this.innerShift[e.id]-e.getMargin().top}getMaxY(e){let t=this.root[e.id];return this.y[t.id]+this.innerShift[e.id]+e.size.y+e.getMargin().bottom}getLowerNeighbor(e,t){let n=e.getLayer(),r=t.nodeIndex[e.id];return r<n.getNodes().length-1?n.getNodes()[r+1]:null}getUpperNeighbor(e,t){let n=e.getLayer(),r=t.nodeIndex[e.id];return r>0?n.getNodes()[r-1]:null}};const Yt=/* @__PURE__ */ new WeakMap;var Xt=class e{layeredGraph;ni;constructor(e,t){this.layeredGraph=e,this.ni=t}verticalAlignment(e,t){for(let t of this.layeredGraph.getLayers())for(let n of t.getNodes())e.root[n.id]=n,e.align[n.id]=n,e.innerShift[n.id]=0;let n=this.layeredGraph.getLayers(),r=n.length,i=e.hdir===1,a=e.vdir===1;for(let o=0;o<r;o++){let s=n[i?r-1-o:o],c=-1,l=s.getNodes(),u=l.length;a&&(c=2**53-1);for(let n=0;n<u;n++){let r=l[a?u-1-n:n],o=i?this.ni.rightNeighbors[r.id]:this.ni.leftNeighbors[r.id];if(o.length>0){let n=o.length,i=Math.floor((n+1)/2)-1,s=Math.ceil((n+1)/2)-1;if(a){for(let n=s;n>=i;n--)if(e.align[r.id]===r){let i=o[n].first;!t.has(o[n].second.id)&&c>this.ni.nodeIndex[i.id]&&(e.align[i.id]=r,e.root[r.id]=e.root[i.id],e.align[r.id]=e.root[r.id],e.od[e.root[r.id].id]=+(e.od[e.root[r.id].id]!==0&&r.getType()===`LONG_EDGE`),c=this.ni.nodeIndex[i.id])}}else for(let n=i;n<=s;n++)if(e.align[r.id]===r){let i=o[n].first;!t.has(o[n].second.id)&&c<this.ni.nodeIndex[i.id]&&(e.align[i.id]=r,e.root[r.id]=e.root[i.id],e.align[r.id]=e.root[r.id],e.od[e.root[r.id].id]=+(e.od[e.root[r.id].id]!==0&&r.getType()===`LONG_EDGE`),c=this.ni.nodeIndex[i.id])}}}}}insideBlockShift(e){for(let t of this.layeredGraph.getLayers())for(let n of t.getNodes())e.root[n.id]===n&&this.shiftBlock(e,n)}shiftBlock(e,t){let n=0,r=0;n=t.getMargin().top,r=t.size.y+t.getMargin().bottom,e.innerShift[t.id]=0;let i=t,a;for(;(a=e.align[i.id])!==t;){let t=this.getEdge(i,a),o=0;o=e.hdir===1?t.getTarget().getPosition().y+t.getTarget().getAnchor().y-t.getSource().getPosition().y-t.getSource().getAnchor().y:t.getSource().getPosition().y+t.getSource().getAnchor().y-t.getTarget().getPosition().y-t.getTarget().getAnchor().y;let s=e.innerShift[i.id]+o;e.innerShift[a.id]=s,n=Math.max(n,a.getMargin().top-s),r=Math.max(r,s+a.size.y+a.getMargin().bottom),i=a}i=t;do e.innerShift[i.id]=e.innerShift[i.id]+n,i=e.align[i.id];while(i!==t);e.blockSize[t.id]=n+r}getBlocks(e){let t=/* @__PURE__ */ new Map;for(let n of this.layeredGraph.getLayers())for(let r of n.getNodes()){let n=e.root[r.id],i=t.get(n);i||(i=[],t.set(n,i)),i.push(r)}return t}static getEdge(e,t){if(e===t){for(let n of e.getPorts()){for(let e of n.getIncomingEdges())if(e.getTarget().getNode()===t||e.getSource().getNode()===t)return e;for(let e of n.getOutgoingEdges())if(e.getTarget().getNode()===t||e.getSource().getNode()===t)return e}return null}let n=Yt.get(e);n===void 0&&(n=/* @__PURE__ */ new Map,Yt.set(e,n));let r=n.get(t);if(r!==void 0)return r;for(let r of e.getPorts()){for(let e of r.getIncomingEdges())if(e.getSource().getNode()===t)return n.set(t,e),e;for(let e of r.getOutgoingEdges())if(e.getTarget().getNode()===t)return n.set(t,e),e}return null}getEdge(t,n){return e.getEdge(t,n)}},Zt=class{static THRESHOLD=Number.MAX_VALUE;static EPSILON=1e-4;bal;ni;blockFinished=/* @__PURE__ */ new Set;postProcessablesQueue=[];postProcessablesStack=[];init(e,t){this.bal=e,this.ni=t,this.blockFinished.clear(),this.postProcessablesQueue=[],this.postProcessablesStack=[]}finishBlock(e){this.blockFinished.add(e)}getOther(e,t){if(e.getSource().getNode()===t)return e.getTarget().getNode();if(e.getTarget().getNode()===t)return e.getSource().getNode();throw Error(`Node neither source nor target of edge`)}},Qt=class extends Zt{calculateThreshold(e,t,n){return this.bal.vdir===1?1/0:-1/0}postProcess(){}},$t=class extends Zt{scratchPostprocessable=null;calculateThreshold(e,t,n){let r=t===n,i=this.bal.align[n.id]===t;if(!(r||i))return e;let a=e;return r&&(a=this.getBound(t,!0)),!Number.isFinite(a)&&i&&(a=this.getBound(n,!1)),a}pickEdge(e){let t=e.isRoot?this.bal.hdir===0?e.free.getIncomingEdges():e.free.getOutgoingEdges():this.bal.hdir===1?e.free.getIncomingEdges():e.free.getOutgoingEdges(),n=!1;for(let r of t)if((this.bal.od[this.bal.root[e.free.id].id]||!r.isInLayerEdge())&&!(this.bal.su[this.bal.root[e.free.id].id]||this.bal.su[this.bal.root[e.free.id].id])&&(n=!0,this.blockFinished.has(this.bal.root[this.getOther(r,e.free).id])))return e.hasEdges=!0,e.edge=r,e;return e.hasEdges=n,e.edge=null,e}getBound(e,t){let n=this.bal.vdir===1?1/0:-1/0,r=this.scratchPostprocessable;r===null?(r=new en(e,t),this.scratchPostprocessable=r):(r.free=e,r.isRoot=t,r.hasEdges=!1,r.edge=null);let i=this.pickEdge(r);if(i.edge===null&&i.hasEdges){let r=new en(e,t);return r.hasEdges=i.hasEdges,this.postProcessablesQueue.push(r),n}if(i.edge!==null){let e,n=i.edge.getSource(),r=i.edge.getTarget();if(t){let t=this.bal.hdir===0?r:n,i=this.bal.hdir===0?n:r,a=this.bal.root[i.getNode().id];e=this.bal.y[a.id]+this.bal.innerShift[i.getNode().id]+i.getPosition().y+i.getAnchor().y-this.bal.innerShift[t.getNode().id]-t.getPosition().y-t.getAnchor().y}else{let t=this.bal.hdir===1?r:n,i=this.bal.hdir===1?n:r;e=this.bal.y[this.bal.root[i.getNode().id].id]+this.bal.innerShift[i.getNode().id]+i.getPosition().y+i.getAnchor().y-this.bal.innerShift[t.getNode().id]-t.getPosition().y-t.getAnchor().y}return this.bal.su[this.bal.root[n.getNode().id].id]=1,this.bal.su[this.bal.root[r.getNode().id].id]=1,e}return n}postProcess(){for(;this.postProcessablesQueue.length>0;){let e=this.postProcessablesQueue.shift(),t=this.pickEdge(e);if(t.edge===null)continue;let n=t.edge;(this.bal.od[this.bal.root[e.free.id].id]||!n.isInLayerEdge())&&(this.process(e)||this.postProcessablesStack.push(e))}for(;this.postProcessablesStack.length>0;)this.process(this.postProcessablesStack.pop())}process(e){let t=e.edge,n,r;t.getSource().getNode()===e.free?(n=t.getTarget(),r=t.getSource()):(n=t.getSource(),r=t.getTarget());let i=this.bal.calculateDelta(n,r);if(i>0&&i<Zt.THRESHOLD){let e=this.bal.checkSpaceAbove(r.getNode(),i,this.ni);return this.bal.shiftBlock(r.getNode(),-e),e>0}if(i<0&&-i<Zt.THRESHOLD){let e=this.bal.checkSpaceBelow(r.getNode(),-i,this.ni);return this.bal.shiftBlock(r.getNode(),e),e>0}return!1}},en=class{free;isRoot;hasEdges=!1;edge=null;constructor(e,t){this.free=e,this.isRoot=t}},tn=class{classShift=null;node;outgoing=[];indegree=0},nn=class{separation=0;target},rn=class{layeredGraph;threshStrategy;ni;spacings;sinkNodes=/* @__PURE__ */ new Map;classNodePool=[];classEdgePool=[];constructor(t,n){this.layeredGraph=t,this.ni=n,this.spacings=t.getProperty(e.wr),this.threshStrategy=t.getProperty(e.vt)===`IMPROVE_STRAIGHTNESS`?new $t:new Qt}horizontalCompaction(e){for(let t of this.layeredGraph.getLayers())for(let n of t.getNodes())e.sink[n.id]=n,e.shift[n.id]=e.vdir===1?-1/0:1/0;for(let e of this.sinkNodes.values()){for(let t of e.outgoing)this.classEdgePool.push(t);e.outgoing.length=0,this.classNodePool.push(e)}this.sinkNodes.clear();let t=this.layeredGraph.getLayers(),n=t.length,r=e.hdir===1,i=e.vdir===1;this.threshStrategy.init(e,this.ni),e.y.fill(NaN);for(let a=0;a<n;a++){let o=t[r?n-1-a:a].getNodes(),s=o.length;for(let t=0;t<s;t++){let n=o[i?s-1-t:t];e.root[n.id]===n&&this.placeBlock(n,e)}}this.placeClasses(e);for(let i=0;i<n;i++){let a=t[r?n-1-i:i];for(let t of a.getNodes())if(e.y[t.id]=e.y[e.root[t.id].id],t===e.root[t.id]){let n=e.shift[e.sink[t.id].id];(e.vdir===1&&n>-1/0||e.vdir===0&&n<1/0)&&(e.y[t.id]=e.y[t.id]+n)}}this.threshStrategy.postProcess()}placeBlock(t,n){if(!Number.isNaN(n.y[t.id]))return;let r=!0;n.y[t.id]=0;let i=t,a=n.vdir===0?-1/0:1/0;do{let o=this.ni.nodeIndex[i.id],s=i.getLayer().getNodes().length;if(n.vdir===0&&o>0||n.vdir===1&&o<s-1){let s;s=n.vdir===1?i.getLayer().getNodes()[o+1]:i.getLayer().getNodes()[o-1];let c=n.root[s.id];if(this.placeBlock(c,n),a=this.threshStrategy.calculateThreshold(a,t,i),n.sink[t.id]===t&&(n.sink[t.id]=n.sink[c.id]),n.sink[t.id]===n.sink[c.id]){let e=this.spacings.getVerticalSpacing(i,s);if(n.vdir===1){let o=n.y[t.id],l=n.y[c.id]+n.innerShift[s.id]-s.getMargin().top-e-i.getMargin().bottom-i.size.y-n.innerShift[i.id];r?(r=!1,n.y[t.id]=Math.min(l,a)):n.y[t.id]=Math.min(o,Math.min(l,a))}else{let o=n.y[t.id],l=n.y[c.id]+n.innerShift[s.id]+s.size.y+s.getMargin().bottom+e+i.getMargin().top-n.innerShift[i.id];r?(r=!1,n.y[t.id]=Math.max(l,a)):n.y[t.id]=Math.max(o,Math.max(l,a))}}else{let r=this.layeredGraph.getProperty(e.ln),a=this.getOrCreateClassNode(n.sink[t.id],n),o=this.getOrCreateClassNode(n.sink[c.id],n);if(n.vdir===1){let e=n.y[t.id]+n.innerShift[i.id]+i.size.y+i.getMargin().bottom+r-(n.y[c.id]+n.innerShift[s.id]-s.getMargin().top);this.addClassEdge(a,o,e)}else{let e=n.y[t.id]+n.innerShift[i.id]-i.getMargin().top-n.y[c.id]-n.innerShift[s.id]-s.size.y-s.getMargin().bottom-r;this.addClassEdge(a,o,e)}}}else a=this.threshStrategy.calculateThreshold(a,t,i);i=n.align[i.id]}while(i!==t);this.threshStrategy.finishBlock(t)}placeClasses(e){let t=[];for(let e of this.sinkNodes.values())e.indegree===0&&t.push(e);for(;t.length>0;){let n=t.shift();n.classShift===null&&(n.classShift=0);for(let r of n.outgoing)r.target.classShift===null?r.target.classShift=n.classShift+r.separation:e.vdir===0?r.target.classShift=Math.min(r.target.classShift,n.classShift+r.separation):r.target.classShift=Math.max(r.target.classShift,n.classShift+r.separation),r.target.indegree--,r.target.indegree===0&&t.push(r.target)}for(let t of this.sinkNodes.values())e.shift[t.node.id]=t.classShift}addClassEdge(e,t,n){let r=this.classEdgePool.pop()??new nn;r.target=t,r.separation=n,t.indegree++,e.outgoing.push(r)}getOrCreateClassNode(e,t){let n=this.sinkNodes.get(e);return n===void 0&&(n=this.classNodePool.pop()??new tn,n.classShift=null,n.indegree=0,n.outgoing.length=0,n.node=e,this.sinkNodes.set(n.node,n)),n}},an=class t{lGraph;markedEdges=/* @__PURE__ */ new Set;ni;produceBalancedLayout=!1;static MIN_LAYERS_FOR_CONFLICTS=3;process(t){this.lGraph=t,this.ni=qt.buildFor(t);let n=t.getProperty(e.yt),r=t.getProperty(e.bt);this.produceBalancedLayout=n===`NONE`&&!r||n===`BALANCED`,this.markConflicts(t);let i=this.ni.nodeCount,a=[];switch(n){case`LEFTDOWN`:a.push([0,1]);break;case`LEFTUP`:a.push([1,1]);break;case`RIGHTDOWN`:a.push([0,0]);break;case`RIGHTUP`:a.push([1,0]);break;default:a.push([0,0],[1,0],[0,1],[1,1])}let o=a.length,s=new Float64Array(o*i),c=new Float64Array(o*i),l=Array(o),u=new Jt(t,i,null,null),d=new Xt(t,this.ni),f=new rn(t,this.ni),p=[];for(let e=0;e<o;e++)u.vdir=a[e][0],u.hdir=a[e][1],u.y=s.subarray(e*i,(e+1)*i),u.innerShift=c.subarray(e*i,(e+1)*i),u.su.fill(0),u.od.fill(1),d.verticalAlignment(u,this.markedEdges),d.insideBlockShift(u),f.horizontalCompaction(u),l[e]=u.layoutSize(),p.push({vdir:a[e][0],hdir:a[e][1],y:u.y,innerShift:u.innerShift,size:l[e]});let m=null,h=null,g=0,_=null;if(m===null&&this.produceBalancedLayout&&(_=this.createBalancedLayout(this.lGraph,i,p),this.checkOrderConstraint(t,_.y,_.innerShift)&&(m=_.y,h=_.innerShift,g=0)),m===null)for(let e of p)this.checkOrderConstraint(t,e.y,e.innerShift)&&(m===null||g>e.size+1e-6)&&(m=e.y,h=e.innerShift,g=e.size,`${e.vdir}${e.hdir}`);m===null&&(m=p[0].y,h=p[0].innerShift,g=p[0].size,`${p[0].vdir}${p[0].hdir}`);for(let e of t.getLayers())for(let t of e.getNodes())t.position.y=m[t.id]+h[t.id];u.cleanup(),this.ni.cleanup(),this.markedEdges.clear()}markConflicts(e){let n=e.getLayers().length;if(n<t.MIN_LAYERS_FOR_CONFLICTS)return;let r=e.getLayers().map(e=>e.getNodes().length);for(let t=1;t<n-1;t++){let n=e.getLayers()[t+1],i=0,a=0;for(let e=0;e<r[t+1];e++){let o=n.getNodes()[e],s=this.incidentToInnerSegment(o,t+1,t);if(e===r[t+1]-1||s){let c=r[t]-1;for(s&&(c=this.ni.nodeIndex[this.ni.leftNeighbors[o.id][0].first.id]);a<=e;){let e=n.getNodes()[a];if(!this.incidentToInnerSegment(e,t+1,t))for(let t of this.ni.leftNeighbors[e.id]){let e=this.ni.nodeIndex[t.first.id];(e<i||e>c)&&this.markedEdges.add(t.second.id)}a++}i=c}}}}incidentToInnerSegment(e,t,n){if(e.getType()===`LONG_EDGE`){for(let r of e.getPorts())for(let i of r.getIncomingEdges())if(i.getSource().getNode().getType()===`LONG_EDGE`&&this.ni.layerIndex[i.getSource().getNode().getLayer().getIndex()]===n&&this.ni.layerIndex[e.getLayer().getIndex()]===t)return!0}return!1}createBalancedLayout(e,t,n){let r=n.length,i=new Jt(e,t,null,null),a=Array(r),o=Array(r),s=Array(r),c=0;for(let e=0;e<r;e++)o[e]=2**53-1,s[e]=-(2**53-1);for(let t=0;t<r;t++){let r=n[t];a[t]=r.size,a[c]>a[t]&&(c=t);for(let n of e.getLayers())for(let e of n.getNodes()){let n=r.y[e.id]+r.innerShift[e.id];o[t]=Math.min(o[t],n),s[t]=Math.max(s[t],n+e.size.y)}}let l=Array(r);for(let e=0;e<r;e++)n[e].vdir===0?l[e]=o[c]-o[e]:l[e]=s[c]-s[e];let u=Array(r);for(let t of e.getLayers())for(let e of t.getNodes()){for(let t=0;t<r;t++){let r=n[t];u[t]=r.y[e.id]+r.innerShift[e.id]+l[t]}u.sort((e,t)=>e-t),i.y[e.id]=(u[1]+u[2])/2,i.innerShift[e.id]=0}return i}checkOrderConstraint(e,t,n){let r=!0;for(let i of e.getLayers()){let e=-1/0;for(let a of i.getNodes()){let i=t[a.id]+n[a.id]-a.getMargin().top,o=t[a.id]+n[a.id]+a.size.y+a.getMargin().bottom;if(i>e&&o>e)e=o;else{r=!1;break}}if(!r)break}return r}};function on(t){let n=t.getProperty(e.wr),r=0;for(let e of t.getLayers()){let t=e.getSize();t.y=0;let i=null;for(let r of e.getNodes())i!==null&&(t.y+=n.getVerticalSpacing(r,i)),t.y+=r.getMargin().top+r.getSize().y+r.getMargin().bottom,i=r;r=Math.max(r,t.y)}for(let e of t.getLayers()){let t=e.getSize(),i=(r-t.y)/2,a=null;for(let t of e.getNodes())a!==null&&(i+=n.getVerticalSpacing(t,a)),i+=t.getMargin().top,t.getPosition().y=i,i+=t.getSize().y+t.getMargin().bottom,a=t}}function sn(t){let n=t.getProperty(e.wr);for(let e of t.getLayers())cn(e,n)}function cn(t,n){let r=-1/0,i=`NORMAL`;for(let a of t.getNodes()){let t=a.getType();if(t!==`NORMAL`){let o=a.getProperty(e.dr);o==null?(r=Math.max(r,0),a.getPosition().y=r+n.getVerticalSpacingByType(t,i)):a.getPosition().y=o}let o=n.getVerticalSpacingByType(t,i);a.getPosition().y<r+o+a.getMargin().top&&(a.getPosition().y=r+o+a.getMargin().top),r=a.getPosition().y+a.getSize().y+a.getMargin().bottom,i=t}}const ln=Object.values(e.Ir);var un=class{graph;nodeTypeSpacingOptionsHorizontal;nodeTypeSpacingOptionsVertical;cachedDefaults=/* @__PURE__ */ new Map;constructor(e){this.graph=e,this.nodeTypeSpacingOptionsHorizontal=this.emptyTable(),this.nodeTypeSpacingOptionsVertical=this.emptyTable(),this.precalculateNodeTypeSpacings()}emptyTable(){let e={};for(let t of ln)e[t]={};return e}diagV(e,t){this.nodeTypeSpacingOptionsVertical[e][e]=t}diagVH(e,t,n){this.nodeTypeSpacingOptionsVertical[e][e]=t,this.nodeTypeSpacingOptionsHorizontal[e][e]=n}pairV(e,t,n){this.nodeTypeSpacingOptionsVertical[e][t]=n,this.nodeTypeSpacingOptionsVertical[t][e]=n}pairVH(e,t,n,r){this.nodeTypeSpacingOptionsVertical[e][t]=n,this.nodeTypeSpacingOptionsVertical[t][e]=n,this.nodeTypeSpacingOptionsHorizontal[e][t]=r,this.nodeTypeSpacingOptionsHorizontal[t][e]=r}precalculateNodeTypeSpacings(){let{NORMAL:t,LONG_EDGE:n,NORTH_SOUTH_PORT:r,EXTERNAL_PORT:i,LABEL:a,BREAKING_POINT:o}=e.Ir;this.diagVH(t,e.ln,e.un),this.pairVH(t,n,e.nn,e.rn),this.pairV(t,r,e.nn),this.pairV(t,i,e.nn),this.pairVH(t,a,e.ln,e.un),this.diagVH(n,e.$t,e.en),this.pairV(n,r,e.$t),this.pairV(n,i,e.$t),this.pairVH(n,a,e.nn,e.rn),this.diagV(r,e.$t),this.pairV(r,i,e.$t),this.pairV(r,a,e.on),this.diagV(i,e.pn),this.pairVH(i,a,e.cn,e.sn),this.diagVH(a,e.$t,e.$t),this.diagVH(o,e.$t,e.en),this.pairVH(o,t,e.nn,e.rn),this.pairVH(o,a,e.nn,e.rn),this.pairVH(o,n,e.nn,e.rn)}getVerticalSpacing(e,t){return this.getLocalSpacing(e,t,this.nodeTypeSpacingOptionsVertical)}getHorizontalSpacing(e,t){return this.getLocalSpacing(e,t,this.nodeTypeSpacingOptionsHorizontal)}getVerticalSpacingByType(e,t){return this.getTypeSpacing(e,t,this.nodeTypeSpacingOptionsVertical)}getHorizontalSpacingByType(e,t){return this.getTypeSpacing(e,t,this.nodeTypeSpacingOptionsHorizontal)}getLocalSpacing(e,t,n){let r=e.getType(),i=t.getType(),a=n[r]?.[i],o=this.getIndividualOrDefault(e,a),s=this.getIndividualOrDefault(t,a);return Math.max(o,s)}getTypeSpacing(t,n,r){let i=r[t]?.[n];return i===void 0?this.graph.getProperty(e.ln):this.graph.getProperty(i)}getIndividualOrDefault(t,n){if(n===void 0)return this.graph.getProperty(e.ln);if(!t.hasProperty(e.in)){let e=this.cachedDefaults.get(n);return e===void 0&&(e=this.graph.getProperty(n),this.cachedDefaults.set(n,e)),e}return dn(t,n)}};function dn(t,n){let r=null;if(t.hasProperty(e.in)){let i=t.getProperty(e.in);i&&i.hasProperty(n)&&(r=i.getProperty(n))}return r===null&&(r=t.getGraph()?.getProperty(n)??n.getDefault()),r}const fn=.1,pn=1e4;function mn(t){return t.hasProperty(e.xt)?t.getProperty(e.xt):t.getGraph().getProperty(e.St)}function hn(t){if(t.getType()!==`NORMAL`||t.getPorts().length<=1)return!1;let n=t.getProperty(`org.eclipse.elk.portConstraints`);if(e.Lr.isPosFixed(n))return!1;let r=mn(t);if(r===`NONE`)return!1;if(!gn(r)){let n=dn(t,e.pn),r=t.getProperty(e.fn),i=r.top,a=r.bottom,o=t.getPortSideView(`WEST`);if(i+a+(o.length-1)*n>t.getSize().y)return!1;let s=t.getPortSideView(`EAST`);if(i+a+(s.length-1)*n>t.getSize().y)return!1}return!0}function gn(e){return e===`NODE_SIZE_WHERE_SPACE_PERMITS`||e===`NODE_SIZE`}var _n=class{origin;head;tail;isFlexible;constructor(e,t,n,r){this.origin=e,this.isFlexible=t,this.head=n,this.tail=r}},vn=class{origin;left;right;constructor(e,t,n){this.origin=e,this.left=t,this.right=n}isStraight(){return this.notStraightBy()===0}notStraightBy(){return this.left.target.layer-this.left.delta-(this.right.target.layer-this.right.delta)}},yn=class extends Array{containsLongEdgeDummy(){return this.length===0?!1:this[0].getSource().getNode().getType()===`LONG_EDGE`||this.some(e=>e.getTarget().getNode().getType()===`LONG_EDGE`)}containsFlexibleNode(e){return this.length===0?!1:e(mn(this[0].getSource().getNode()))?!0:this.some(t=>e(mn(t.getTarget().getNode())))}orderTwoPath(){if(this.length!==2)throw Error(`Order only allowed for two paths.`);let e=this[0],t=this[1];e.getTarget().getNode()!==t.getSource().getNode()&&(this.length=0,this.push(t,e))}isTwoPathCenterNodeFlexible(){return hn(this[0].getTarget().getNode())}},bn=class t{lGraph;spacings;nGraph;nodeReps=[];edgeReps=[];portMap=/* @__PURE__ */ new Map;nodeCount=0;edgeCount=0;nodeState=[];crossing=[];twoPaths=[];flexibleWhereSpacePermitsEdges=[];process(t){this.lGraph=t,this.spacings=t.getProperty(e.wr),this.prepare(),this.buildInitialAuxiliaryGraph(),this.insertNorthSouthAuxiliaryEdges(),this.insertInLayerEdgeAuxiliaryEdges(),this.lGraph.getProperty(e.bt)&&this.preferStraightEdges(),this.nGraph.makeConnected();let n=t.getProperty(e.mn)*this.nGraph.nodes.length;if(ie.forGraph(this.nGraph).withIterationLimit(n).withBalancing(!1).execute(),this.flexibleWhereSpacePermitsEdges.length>0){this.insertFlexibleWhereSpaceAuxiliaryEdges();for(let e of this.flexibleWhereSpacePermitsEdges)e.weight=1;ie.forGraph(this.nGraph).withIterationLimit(n).withBalancing(!1).execute()}this.lGraph.getProperty(e.bt)&&this.postProcessTwoPaths(),this.applyPositions(),this.cleanup()}prepare(){this.nGraph=new re;let e=0,t=0;for(let n of this.lGraph.getLayers())for(let r of n.getNodes()){r.id=e++;for(let e of r.getOutgoingEdges())e.id=t++;let n=hn(r);for(let e of r.getPorts()){if(n){let t=e.getAnchor().y;if(t!==Math.floor(t)){let n=t-Math.round(t);e.getAnchor().y-=n}}let t=e.getPosition().y+e.getAnchor().y;if(t!==Math.floor(t)){let n=t-Math.round(t);e.getPosition().y-=n}}}this.nodeReps=Array(e),this.edgeReps=Array(t),this.nodeCount=e,this.edgeCount=t,this.flexibleWhereSpacePermitsEdges=[]}cleanup(){this.nodeReps=[],this.edgeReps=[],this.portMap.clear(),this.flexibleWhereSpacePermitsEdges=[]}buildInitialAuxiliaryGraph(){for(let e of this.lGraph.getLayers())this.transformLayer(e);this.transformEdges()}transformLayer(e){let t=null;for(let n of e.getNodes()){let e=hn(n)?this.transformFixedOrderNode(n):this.transformFixedPosNode(n);if(this.nodeReps[n.id]=e,t!==null){let r=t.origin.getMargin().bottom+this.spacings.getVerticalSpacing(t.origin,n)+n.getMargin().top;t.isFlexible||(r+=t.origin.getSize().y),D().delta(Math.ceil(r)).weight(0).source(t.tail).target(e.head).create()}t=e}}transformFixedPosNode(t){let n=T().origin(t).type(`non-flexible`).create(this.nGraph);for(let r of t.getPorts())e.Ur.includes(r.getSide())&&this.portMap.set(r,n);return new _n(t,!1,n,n)}transformFixedOrderNode(e){let t=T().origin(e).type(`flexible-head`).create(this.nGraph),n=T().origin(e).type(`flexible-tail`).create(this.nGraph),r=new _n(e,!0,t,n),i=e.getSize().y,a=mn(e),o=a===`NODE_SIZE`?1:pn,s=D().weight(o).delta(Math.ceil(i)).source(t).target(n).create();return a===`NODE_SIZE_WHERE_SPACE_PERMITS`&&this.flexibleWhereSpacePermitsEdges.push(s),this.transformPorts([...e.getPortSideView(`WEST`)].reverse(),r),this.transformPorts(e.getPortSideView(`EAST`),r),r}transformPorts(t,n){if(t.length===0)return;let r=dn(n.origin,e.pn),i=dn(n.origin,e.fn),a=n.head,o=null;for(let e of t){let t=0;t=o===null?i.top:r+o.getSize().y;let n=T().origin(e).type(`port`).create(this.nGraph);this.portMap.set(e,n),D().weight(0).delta(Math.ceil(t)).source(a).target(n).create(),o=e,a=n}D().weight(0).delta(Math.ceil(i.bottom+o.getSize().y)).source(a).target(n.tail).create()}transformEdges(){for(let e of this.lGraph.getLayers())for(let t of e.getNodes())for(let e of t.getOutgoingEdges())this.isHandledEdge(e)&&this.transformEdge(e)}transformEdge(e){let t=T().type(`edge`).create(this.nGraph),n=this.nodeReps[e.getSource().getNode().id],r=this.nodeReps[e.getTarget().getNode().id],i=e.getSource(),a=e.getTarget(),o=i.getAnchor().y,s=a.getAnchor().y;n.isFlexible||(o+=i.getPosition().y),r.isFlexible||(s+=a.getPosition().y);let c=Math.max(0,o-s),l=Math.max(0,s-o),u=this.getEdgeWeight(e),d=D().origin(e).weight(u).delta(l).source(t).target(this.portMap.get(i)).create(),f=D().origin(e).weight(u).delta(c).source(t).target(this.portMap.get(a)).create();this.edgeReps[e.id]=new vn(e,d,f)}insertInLayerEdgeAuxiliaryEdges(){for(let e of this.lGraph.getLayers())for(let t of e.getNodes())if(t.getType()===`NORMAL`)for(let e of t.getConnectedEdges()){if(!e.isInLayerEdge())continue;let t=e.getSource().getNode().getType()===`NORMAL`?e.getSource():e.getTarget(),n=e.getOther(t).getNode(),r=this.portMap.get(t),i=this.nodeReps[n.id].head,a=t.getNode().getIndex()<n.getIndex()?r:i,o=t.getNode().getIndex()<n.getIndex()?i:r;D().delta(0).weight(4).source(a).target(o).create()}}insertNorthSouthAuxiliaryEdges(){for(let t of this.lGraph.getLayers())for(let n of t.getNodes()){for(let t of n.getPortSideView(`SOUTH`)){let r=t.getProperty(e._r),i=r==null?void 0:this.nodeReps[r.id];r!=null&&i!==void 0&&this.nodeReps[n.id]!==void 0&&D().delta(0).weight(fn).source(this.nodeReps[n.id].tail).target(i.head).create()}for(let t of n.getPortSideView(`NORTH`)){let r=t.getProperty(e._r),i=r==null?void 0:this.nodeReps[r.id];r!=null&&i!==void 0&&this.nodeReps[n.id]!==void 0&&D().delta(0).weight(fn).source(i.tail).target(this.nodeReps[n.id].head).create()}}}static length(e){return Math.abs(e.source.layer-e.target.layer)-e.delta}getEdgeWeightByType(e,t){return e===`NORMAL`&&t===`NORMAL`?4:e===`NORMAL`||t===`NORMAL`?8:32}preferStraightEdges(){this.nodeState=Array(this.nodeCount),this.twoPaths=[];for(let e of this.lGraph.getLayers())for(let n of e.getNodes())this.nodeState[n.id]=t.getNodeState(n);this.markEdgeCrossings();let e=this.identifyPaths();for(let t of e){if(t.length<=1)continue;if(t.length===2){t.orderTwoPath(),t.isTwoPathCenterNodeFlexible()||this.twoPaths.push(t);continue}if(t.containsLongEdgeDummy()||t.containsFlexibleNode(e=>gn(e)))continue;let e=null;for(let n=0;n<t.length;n++){let r=t[n],i=this.edgeReps[r.id],a=(e===null||n===t.length-1?this.getEdgeWeightByType(`NORMAL`,`LONG_EDGE`):this.getEdgeWeightByType(`LONG_EDGE`,`LONG_EDGE`))*2,o=i.left.weight;i.left.weight=Math.max(o,o+(a-o));let s=i.right.weight;i.right.weight=Math.max(s,s+(a-s)),e=r}}}postProcessTwoPaths(){let e=[...this.twoPaths],t=[];for(;e.length>0;){let n=e.shift();this.improveTwoPath(n,!0)&&t.push(n)}for(;t.length>0;)this.improveTwoPath(t.pop(),!1)}improveTwoPath(e,n){let r=this.edgeReps[e[0].id],i=this.edgeReps[e[1].id];if(r.isStraight()&&i.isStraight())return!1;let a=r.right.target.origin;if(a===null||typeof a.getPorts!=`function`)return!1;let o=a,s=this.nodeReps[o.id],c=o.getIndex(),l=1/0;if(c>0){let e=o.getLayer().getNodes()[c-1],t=this.nodeReps[e.id],n=Math.ceil(this.spacings.getVerticalSpacing(e,o));l=s.head.layer-o.getMargin().top-(t.head.layer+e.getSize().y+e.getMargin().bottom)-n}let u=1/0;if(c<o.getLayer().getNodes().length-1){let e=o.getLayer().getNodes()[c+1],t=this.nodeReps[e.id],n=Math.ceil(this.spacings.getVerticalSpacing(e,o));u=t.head.layer-e.getMargin().top-(s.head.layer+o.getSize().y+o.getMargin().bottom)-n}if(n&&Math.abs(l-u)<=1e-5)return!0;let d=+t.length(r.left),f=-t.length(r.right),p=-t.length(i.left),m=+t.length(i.right),h=r.notStraightBy()>0&&i.notStraightBy()<0,g=r.notStraightBy()<0&&i.notStraightBy()>0,_=r.left.target.layer+r.right.delta<i.right.target.layer+i.left.delta,v=r.left.target.layer+r.right.delta>i.right.target.layer+i.left.delta,y=0;return!h&&!g&&(v?l+p>0?y=p:u-d>0&&(y=d):_&&(l+f>0?y=f:u-m>0&&(y=m))),s.head.layer+=y,s.isFlexible&&(s.tail.layer+=y),!1}identifyPaths(){let e=[];for(let t of this.lGraph.getLayers())for(let n of t.getNodes())if(this.nodeState[n.id]===2)for(let t of n.getConnectedEdges()){if(!this.isHandledEdge(t))continue;let r=this.follow(t,n,new yn);r.length>1&&e.push(r)}return e}follow(e,t,n){let r=e.getOtherNode(t);if(n.push(e),this.nodeState[r.id]===-1||this.nodeState[r.id]===2||this.crossing[e.id])return n;this.nodeState[r.id]=-1;for(let t of r.getConnectedEdges())if(this.isHandledEdge(t)&&t!==e)return this.follow(t,r,n);return n}static getNodeState(e){let t=0,n=0;for(let r of e.getPorts()){for(let e of r.getIncomingEdges())e.isSelfLoop()||t++;for(let e of r.getOutgoingEdges())e.isSelfLoop()||n++;if(t>1||n>1)return 2}return t+n===1?2:0}markEdgeCrossings(){this.crossing=Array(this.edgeCount).fill(!1);let e=this.lGraph.getLayers();for(let t=0;t+1<e.length;t++)this.markCrossingEdges(e[t],e[t+1])}markCrossingEdges(e,t){let n=[];for(let r of e.getNodes())for(let e of r.getPortSideView(`EAST`))for(let r of e.getOutgoingEdges())r.isInLayerEdge()||r.isSelfLoop()||r.getTarget().getNode().getLayer()!==t||n.push(r);for(let r=t.getNodes().length-1;r>=0;r--){let i=t.getNodes()[r];for(let t of i.getPortSideView(`WEST`))for(let r of t.getIncomingEdges())if(!(r.isInLayerEdge()||r.isSelfLoop()||r.getSource().getNode().getLayer()!==e)&&n.length>0){let e=n.length-1,t=n[e];for(;t!==r&&e>0;)this.crossing[t.id]=!0,this.crossing[r.id]=!0,e--,t=n[e];t===r&&e>0&&n.splice(e,1)}}}insertFlexibleWhereSpaceAuxiliaryEdges(){let e=1/0,t=-1/0;for(let n of this.nGraph.nodes)n.layer<e&&(e=n.layer),n.layer>t&&(t=n.layer);let n=t-e,r=T().create(this.nGraph),i=T().create(this.nGraph);D().weight(pn*2).delta(n).source(r).target(i).create();for(let t of this.nodeReps)t!==void 0&&t.origin.getType()===`NORMAL`&&(t.origin.getPorts().length<=1||(D().weight(0).delta(t.tail.layer-e).source(r).target(t.tail).create(),D().weight(0).delta(n-t.head.layer).source(t.head).target(i).create()))}applyPositions(){for(let t of this.lGraph.getLayers())for(let n of t.getNodes()){let t=this.nodeReps[n.id],r=t.head.layer,i=t.tail.layer;n.getPosition().y=r;let a=i-r-n.getSize().y,o=hn(n),s=mn(n);if(o&&gn(s)&&(n.getSize().y+=a),o&&(s===`PORT_POSITION`||gn(s))){for(let t of n.getPorts())if(e.Ur.includes(t.getSide())){let e=this.portMap.get(t);t.getPosition().y=e.layer-r}}}}getEdgeWeight(t){let n=Math.max(1,t.getProperty(e.Gt)),r=t.getSource().getNode().getType(),i=t.getTarget().getNode().getType(),a;return a=r===`NORMAL`&&i===`NORMAL`?4:r===`NORMAL`||i===`NORMAL`?8:32,n*a}isHandledEdge(e){return!e.isSelfLoop()&&!e.isInLayerEdge()}},xn=class{process(t){let n=1/0,r=-1/0,i=!1;for(let a of t.getLayers()){let o=a.getSize();if(o.x=0,o.y=0,a.getNodes().length===0)continue;i=!0;for(let e of a.getNodes())o.x=Math.max(o.x,e.size.x+e.getMargin().left+e.getMargin().right);let s=a.getNodes()[0],c=t.getProperty(e.fn),l=s.getPosition().y-s.getMargin().top;s.getType()===`EXTERNAL_PORT`&&(l-=c.top);let u=a.getNodes()[a.getNodes().length-1],d=u.getPosition().y+u.size.y+u.getMargin().bottom;u.getType()===`EXTERNAL_PORT`&&(d+=c.bottom),o.y=d-l,n=Math.min(n,l),r=Math.max(r,d)}i||(n=0,r=0),t.getSize().y=r-n,t.getOffset().y-=n}};function Sn(t,n){let r=0,i=0;for(let e of t.getNodes())r=Math.max(r,e.getMargin().left),i=Math.max(i,e.getMargin().right);for(let a of t.getNodes()){let o=a.getProperty(e.p),s;if(o===`LEFT`)s=0;else if(o===`RIGHT`)s=1;else if(o===`CENTER`)s=.5;else{let e=0,t=0;for(let n of a.getPorts())n.getIncomingEdges().length>0&&e++,n.getOutgoingEdges().length>0&&t++;s=e+t===0?.5:t/(e+t)}let c=t.getSize(),l=a.size.x,u=(c.x-l)*s;s>.5?u-=i*2*(s-.5):s<.5&&(u+=r*2*(.5-s));let d=a.getMargin().left;u<d&&(u=d);let f=a.getMargin().right;u>c.x-f-l&&(u=c.x-f-l),a.position.x=n+u}}var A=class e{static CRITICAL_DEPENDENCY_WEIGHT=1;type;source=null;target=null;weight;constructor(e,t,n,r){this.type=e,this.weight=r,this.setSource(t),this.setTarget(n)}static createAndAddRegular(t,n,r){return new e(0,t,n,r)}static createAndAddCritical(t,n){return new e(1,t,n,e.CRITICAL_DEPENDENCY_WEIGHT)}remove(){this.setSource(null),this.setTarget(null)}reverse(){let e=this.source,t=this.target;this.setSource(t),this.setTarget(e)}getType(){return this.type}getSource(){return this.source}getTarget(){return this.target}getWeight(){return this.weight}setSource(e){if(this.source!==null){let e=this.source.getOutgoingSegmentDependencies(),t=e.indexOf(this);t!==-1&&e.splice(t,1)}this.source=e,this.source!==null&&this.source.getOutgoingSegmentDependencies().push(this)}setTarget(e){if(this.target!==null){let e=this.target.getIncomingSegmentDependencies(),t=e.indexOf(this);t!==-1&&e.splice(t,1)}this.target=e,this.target!==null&&this.target.getIncomingSegmentDependencies().push(this)}},Cn=class{static detectCycles(e,t,n){let r=[],i=[],a=[];wn(e,i,a,t),Tn(e,i,a,t,n);for(let n of e)for(let e of n.getOutgoingSegmentDependencies())(!t||e.getType()===1)&&n.mark>e.getTarget().mark&&r.push(e);return r}};function wn(e,t,n,r){let i=-1;for(let a of e){a.mark=i--;let e=0;for(let t of a.getIncomingSegmentDependencies())t.getType()===1&&(e+=t.getWeight());let o=0;for(let e of a.getOutgoingSegmentDependencies())e.getType()===1&&(o+=e.getWeight());let s=e,c=o;if(!r){s=0;for(let e of a.getIncomingSegmentDependencies())s+=e.getWeight();c=0;for(let e of a.getOutgoingSegmentDependencies())c+=e.getWeight()}a.setInWeight(s),a.setCriticalInWeight(e),a.setOutWeight(c),a.setCriticalOutWeight(o),c===0?n.push(a):s===0&&t.push(a)}}function Tn(e,t,n,r,i){let a=[],o=[],s=e.length,c=s-1,l=s+1;for(;;){let s=0;for(;s<n.length;){let e=n[s++];e.mark=c--,En(e,t,n,r)}n.length=0;let u=0;for(;u<t.length;){let e=t[u++];e.mark=l++,En(e,t,n,r)}t.length=0,a.length=0;for(let t=e.length-1;t>=0;t--){let n=e[t];n.mark<0&&a.push(n)}if(a.length===0)break;let d=-(2**53-1);o.length=0;for(let e of a){if(!r&&e.getCriticalOutWeight()>0&&e.getCriticalInWeight()<=0){o.length=0,o.push(e);break}let t=e.getOutWeight()-e.getInWeight();t>=d&&(t>d&&(o.length=0,d=t),o.push(e))}if(o.length>0){let e=o[i.nextInt(o.length)];e.mark=l++,En(e,t,n,r)}}let u=e.length+1;for(let t of e)t.mark<s&&(t.mark+=u)}function En(e,t,n,r){for(let n of e.getOutgoingSegmentDependencies())if(!r||n.getType()===1){let e=n.getTarget();e.mark<0&&n.getWeight()>0&&(e.setInWeight(e.getInWeight()-n.getWeight()),n.getType()===1&&e.setCriticalInWeight(e.getCriticalInWeight()-n.getWeight()),e.getInWeight()<=0&&e.getOutWeight()>0&&t.push(e))}for(let t of e.getIncomingSegmentDependencies())if(!r||t.getType()===1){let e=t.getSource();e.mark<0&&t.getWeight()>0&&(e.setOutWeight(e.getOutWeight()-t.getWeight()),t.getType()===1&&e.setCriticalOutWeight(e.getCriticalOutWeight()-t.getWeight()),e.getOutWeight()<=0&&e.getInWeight()>0&&n.push(e))}}const Dn=`EAST`;function On(e){return e.getNode().position.y+e.getPosition().y+e.getAnchor().y}var kn=class e{mark=0;positionFn;srcSide;splitPartner=null;splitBy=null;constructor(e=On,t=Dn){this.positionFn=e,this.srcSide=t}routingSlot=0;ports=[];startPosition=NaN;endPosition=NaN;incomingConnectionCoordinates=[];outgoingConnectionCoordinates=[];incomingSegmentDependencies=[];outgoingSegmentDependencies=[];inWeight=0;outWeight=0;criticalInWeight=0;criticalOutWeight=0;addPortPositions(e,t,n=!0){t.set(e,this),this.ports.push(e);let r=this.positionFn(e);e.getSide()===this.srcSide?An(this.incomingConnectionCoordinates,r):An(this.outgoingConnectionCoordinates,r);let i=e.getIncomingEdges?.();if(i!==void 0){for(let n of i){let r=n.getSource()===e?n.getTarget():n.getSource();t.has(r)||this.addPortPositions(r,t,!1)}for(let n of e.getOutgoingEdges()){let r=n.getSource()===e?n.getTarget():n.getSource();t.has(r)||this.addPortPositions(r,t,!1)}}else for(let n of e.getConnectedPorts())t.has(n)||this.addPortPositions(n,t,!1);n&&this.recomputeExtent()}getPorts(){return this.ports}getSplitPartner(){return this.splitPartner}setSplitPartner(e){this.splitPartner=e}getSplitBy(){return this.splitBy}setSplitBy(e){this.splitBy=e}isDummy(){return this.splitPartner!==null&&this.splitBy===null}getLength(){return this.endPosition-this.startPosition}representsHyperedge(){return this.ports.length>2}getRoutingSlot(){return this.routingSlot}setRoutingSlot(e){this.routingSlot=e}getStartCoordinate(){return this.startPosition}getEndCoordinate(){return this.endPosition}getIncomingConnectionCoordinates(){return this.incomingConnectionCoordinates}getOutgoingConnectionCoordinates(){return this.outgoingConnectionCoordinates}getIncomingSegmentDependencies(){return this.incomingSegmentDependencies}getOutgoingSegmentDependencies(){return this.outgoingSegmentDependencies}getInWeight(){return this.inWeight}setInWeight(e){this.inWeight=e}getOutWeight(){return this.outWeight}setOutWeight(e){this.outWeight=e}getCriticalInWeight(){return this.criticalInWeight}setCriticalInWeight(e){this.criticalInWeight=e}getCriticalOutWeight(){return this.criticalOutWeight}setCriticalOutWeight(e){this.criticalOutWeight=e}splitAt(t){for(this.splitPartner=new e(this.positionFn,this.srcSide),this.splitPartner.setSplitPartner(this),this.splitPartner.outgoingConnectionCoordinates.push(...this.outgoingConnectionCoordinates),this.outgoingConnectionCoordinates.length=0,this.outgoingConnectionCoordinates.push(t),this.splitPartner.incomingConnectionCoordinates.push(t),this.recomputeExtent(),this.splitPartner.recomputeExtent();this.incomingSegmentDependencies.length>0;)this.incomingSegmentDependencies[0].remove();for(;this.outgoingSegmentDependencies.length>0;)this.outgoingSegmentDependencies[0].remove();return this.splitPartner}simulateSplit(){let t=new e(this.positionFn,this.srcSide),n=new e(this.positionFn,this.srcSide);return t.splitBy=this.splitBy,t.splitPartner=n,n.splitPartner=t,t.incomingConnectionCoordinates.push(...this.incomingConnectionCoordinates),t.recomputeExtent(),n.outgoingConnectionCoordinates.push(...this.outgoingConnectionCoordinates),n.recomputeExtent(),[t,n]}recomputeExtent(){this.startPosition=NaN,this.endPosition=NaN,this.recomputeExtentList(this.incomingConnectionCoordinates),this.recomputeExtentList(this.outgoingConnectionCoordinates)}recomputeExtentList(e){e.length!==0&&(this.startPosition=Number.isNaN(this.startPosition)?e[0]:Math.min(this.startPosition,e[0]),this.endPosition=Number.isNaN(this.endPosition)?e[e.length-1]:Math.max(this.endPosition,e[e.length-1]))}};function An(e,t){let n=0,r=e.length;for(;n<r;){let i=n+r>>1,a=e[i];if(a===t)return;a>t?r=i:n=i+1}e.splice(n,0,t)}var jn=class{startPosition;endPosition;size;constructor(e,t){this.startPosition=e,this.endPosition=t,this.size=t-e}},Mn=class{dependencies=0;crossings=0};function Nn(e,t){let n=[];for(let t of e)n.push(...t.getIncomingConnectionCoordinates(),...t.getOutgoingConnectionCoordinates());n.sort((e,t)=>e-t);let r=[];for(let e=1;e<n.length;e++)n[e]-n[e-1]>=2*t&&r.push(new jn(n[e-1]+t,n[e]-t));return r}function Pn(e){let t=/* @__PURE__ */ new Set;for(let n of e){let e=n.getSource(),r=n.getTarget();if(e===null||r===null||t.has(e)||t.has(r))continue;let i=e,a=r;e.representsHyperedge()&&!r.representsHyperedge()&&(i=r,a=e),t.add(i),i.setSplitBy(a)}return t}function Fn(e,t,n,r){let i=Rn(e,n,r);t.push(e.splitAt(i)),In(e,t)}function In(e,t){let n=e.getSplitBy(),r=e.getSplitPartner();if(n!==null&&r!==null){A.createAndAddCritical(e,n),A.createAndAddCritical(n,r);for(let i of t)i!==n&&i!==e&&i!==r&&(Ln(i,e),Ln(i,r))}}function Ln(e,t){if(Math.abs(e.getStartCoordinate()-e.getEndCoordinate())<.001||Math.abs(t.getStartCoordinate()-t.getEndCoordinate())<.001)return;let n=j(e.getOutgoingConnectionCoordinates(),t.getStartCoordinate(),t.getEndCoordinate())+j(t.getIncomingConnectionCoordinates(),e.getStartCoordinate(),e.getEndCoordinate()),r=j(t.getOutgoingConnectionCoordinates(),e.getStartCoordinate(),e.getEndCoordinate())+j(e.getIncomingConnectionCoordinates(),t.getStartCoordinate(),t.getEndCoordinate());(n>0||r>0)&&(n<=r?A.createAndAddCritical(e,t):A.createAndAddCritical(t,e))}function Rn(e,t,n){let r=-1,i=-1;for(let n=0;n<t.length;n++){let a=t[n];if(a.startPosition>e.getEndCoordinate())break;a.endPosition>=e.getStartCoordinate()&&(r<0&&(r=n),i=n)}let a=Kn(e);if(r>=0){let o=zn(e,t,r,i);a=qn(t[o]),Wn(t,o,n)}return a}function zn(e,t,n,r){let i=n;if(n<r){let[a,o]=e.simulateSplit(),s=t[i],c=Bn(e,a,o,s);for(let l=n+1;l<=r;l++){let n=t[l],r=Bn(e,a,o,n);Un(n,r,s,c)&&(s=n,c=r,i=l)}}return i}function Bn(e,t,n,r){let i=qn(r);t.getOutgoingConnectionCoordinates().length=0,t.getOutgoingConnectionCoordinates().push(i),n.getIncomingConnectionCoordinates().length=0,n.getIncomingConnectionCoordinates().push(i);let a=new Mn;for(let r of e.getIncomingSegmentDependencies()){let e=r.getSource();e!==null&&(Vn(a,t,e),Vn(a,n,e))}for(let r of e.getOutgoingSegmentDependencies()){let e=r.getTarget();e!==null&&(Vn(a,t,e),Vn(a,n,e))}a.dependencies+=2;let o=e.getSplitBy();return o!==null&&(a.crossings+=Hn(t,o),a.crossings+=Hn(o,n)),a}function Vn(e,t,n){let r=Hn(t,n),i=Hn(n,t);r===i?r>0&&(e.dependencies+=2,e.crossings+=r):(e.dependencies+=1,e.crossings+=Math.min(r,i))}function Hn(e,t){return j(e.getOutgoingConnectionCoordinates(),t.getStartCoordinate(),t.getEndCoordinate())+j(t.getIncomingConnectionCoordinates(),e.getStartCoordinate(),e.getEndCoordinate())}function Un(e,t,n,r){return t.crossings<r.crossings||t.crossings===r.crossings&&(t.dependencies<r.dependencies||t.dependencies===r.dependencies&&e.size>n.size)}function Wn(e,t,n){let r=e[t];if(e.splice(t,1),r.size/2>=n){let i=t,a=qn(r),o=a-n;r.startPosition<=o&&e.splice(i++,0,new jn(r.startPosition,o));let s=a+n;s<=r.endPosition&&e.splice(i,0,new jn(s,r.endPosition))}}function Gn(e,t){return(e+t)/2}function Kn(e){return Gn(e.getStartCoordinate(),e.getEndCoordinate())}function qn(e){return Gn(e.startPosition,e.endPosition)}function Jn(e,t,n){if(e.length===0)return;let r=Nn(t,n),i=[...Pn(e)].sort((e,t)=>e.getLength()-t.getLength());for(let e of i)Fn(e,t,r,n)}const Yn={sourceSide:`NORTH`,targetSide:`SOUTH`,positionFn:Zn},Xn={sourceSide:`SOUTH`,targetSide:`NORTH`,positionFn:Zn};function Zn(e){return e.getNode().position.x+e.getPosition().x+e.getAnchor().x}const Qn=.2;var $n=class{criticalConflictThreshold=0;edgeSpacing;conflictThreshold;constructor(e){this.edgeSpacing=e,this.conflictThreshold=.5*e}edgeSegmentsScratch=[];portToEdgeSegmentMapScratch=/* @__PURE__ */ new Map;incomingCoordsScratch=[];outgoingCoordsScratch=[];routeEdgesSlotCount(e,t,n){return this.routeEdgesInternal(e,t,n,NaN)}routeEdges(e,t,n,r){return this.routeEdgesInternal(e,t,r,n)}routeEdgesInternal(e,t,n,r){let i=this.edgeSegmentsScratch;i.length=0;let a=this.portToEdgeSegmentMapScratch;if(a.clear(),this.createHyperEdgeSegments(e,`EAST`,i,a),this.createHyperEdgeSegments(t,`WEST`,i,a),i.length===0)return 0;this.criticalConflictThreshold=Qn*this.minimumHorizontalSegmentDistance(i);let o=0,s=!1;for(let e=0;e<i.length-1;e++){let t=i[e];for(let n=e+1;n<i.length;n++)o+=this.createDependencyIfNecessary(t,i[n]),!s&&(t.getOutgoingSegmentDependencies().length>0||i[n].getOutgoingSegmentDependencies().length>0)&&(s=!0)}s&&(o>=2&&Jn(Cn.detectCycles(i,!0,n),i,this.criticalConflictThreshold),nr(i,n)),tr(i);let c=-1;for(let e of i)Math.abs(e.getStartCoordinate()-e.getEndCoordinate())<.001||(c=Math.max(c,e.getRoutingSlot()),Number.isNaN(r)||this.calculateBendPoints(e,r,this.edgeSpacing));return c+1}calculateBendPoints(e,t,n){if(e.isDummy())return;let r=t+e.getRoutingSlot()*n;for(let i of e.getPorts()){let a=i.getNode().position.y+i.getPosition().y+i.getAnchor().y;for(let o of i.getOutgoingEdges()){if(o.isSelfLoop())continue;let i=o.getTarget(),s=i.getNode().position.y+i.getPosition().y+i.getAnchor().y;if(Math.abs(a-s)>.001){let i=r;o.getBendPoints().push({x:i,y:a});let c=e.getSplitPartner();if(c!==null){let e=c.getIncomingConnectionCoordinates()[0];o.getBendPoints().push({x:i,y:e}),i=t+c.getRoutingSlot()*n,o.getBendPoints().push({x:i,y:e})}o.getBendPoints().push({x:i,y:s})}}}}createHyperEdgeSegments(e,t,n,r,i=On,a=Dn){if(e!=null)for(let o of e)for(let e of o.getPorts()){if(e.getSide()!==t||e.getOutgoingEdges().length===0)continue;let o=r.get(e);o===void 0&&(o=new kn(i,a),n.push(o),o.addPortPositions(e,r))}}routeEdgesForDirection(e,t,n,r,i,a,o=NaN){let s=this.edgeSegmentsScratch;s.length=0;let c=this.portToEdgeSegmentMapScratch;if(c.clear(),this.createHyperEdgeSegments(e??[],r,s,c,a,r),this.createHyperEdgeSegments(t??[],i,s,c,a,r),s.length===0)return 0;this.criticalConflictThreshold=Qn*this.minimumHorizontalSegmentDistance(s);let l=0,u=!1;for(let e=0;e<s.length-1;e++){let t=s[e];for(let n=e+1;n<s.length;n++)l+=this.createDependencyIfNecessary(t,s[n]),!u&&(t.getOutgoingSegmentDependencies().length>0||s[n].getOutgoingSegmentDependencies().length>0)&&(u=!0)}u&&(l>=2&&Jn(Cn.detectCycles(s,!0,n),s,this.criticalConflictThreshold),nr(s,n)),tr(s);let d=-1;for(let e of s)Math.abs(e.getStartCoordinate()-e.getEndCoordinate())<.001||(d=Math.max(d,e.getRoutingSlot()),Number.isNaN(o)||this.calculateBendPointsForDirection(e,o,this.edgeSpacing,r));return d+1}calculateBendPointsForDirection(e,t,n,r){if(e.isDummy())return;let i=r===`NORTH`,a=t+(i?-1:1)*e.getRoutingSlot()*n;for(let r of e.getPorts()){let o=Zn(r);for(let s of r.getOutgoingEdges()){if(s.isSelfLoop())continue;let r=s.getTarget();if(r==null)continue;let c=Zn(r);if(Math.abs(o-c)<=.001)continue;let l=a;s.getBendPoints().push({x:o,y:l});let u=e.getSplitPartner();if(u!==null){let e=u.getIncomingConnectionCoordinates()[0];e!==void 0&&(s.getBendPoints().push({x:e,y:l}),l=t+(i?-1:1)*u.getRoutingSlot()*n,s.getBendPoints().push({x:e,y:l}))}s.getBendPoints().push({x:c,y:l})}}}createDependencyIfNecessary(e,t){if(Math.abs(e.getStartCoordinate()-e.getEndCoordinate())<.001||Math.abs(t.getStartCoordinate()-t.getEndCoordinate())<.001)return 0;let n=this.countConflicts(e.getOutgoingConnectionCoordinates(),t.getIncomingConnectionCoordinates()),r=this.countConflicts(t.getOutgoingConnectionCoordinates(),e.getIncomingConnectionCoordinates());if(n===-1||r===-1){let i=0;return n===-1&&(A.createAndAddCritical(t,e),i++),r===-1&&(A.createAndAddCritical(e,t),i++),i}{let i=j(e.getOutgoingConnectionCoordinates(),t.getStartCoordinate(),t.getEndCoordinate())+j(t.getIncomingConnectionCoordinates(),e.getStartCoordinate(),e.getEndCoordinate()),a=j(t.getOutgoingConnectionCoordinates(),e.getStartCoordinate(),e.getEndCoordinate())+j(e.getIncomingConnectionCoordinates(),t.getStartCoordinate(),t.getEndCoordinate()),o=1*n+16*i,s=1*r+16*a;return o<s?A.createAndAddRegular(e,t,s-o):o>s?A.createAndAddRegular(t,e,o-s):o>0&&s>0&&(A.createAndAddRegular(e,t,0),A.createAndAddRegular(t,e,0)),0}}countConflicts(e,t){let n=0;if(e.length>0&&t.length>0){let r=0,i=0,a=e[0],o=t[0],s=!0;do{if(a>o-this.criticalConflictThreshold&&a<o+this.criticalConflictThreshold)return-1;a>o-this.conflictThreshold&&a<o+this.conflictThreshold&&n++,a<=o&&r+1<e.length?a=e[++r]:o<=a&&i+1<t.length?o=t[++i]:s=!1}while(s)}return n}minimumHorizontalSegmentDistance(e){let t=this.incomingCoordsScratch,n=this.outgoingCoordsScratch;t.length=0,n.length=0;for(let r of e)t.push(...r.getIncomingConnectionCoordinates()),n.push(...r.getOutgoingConnectionCoordinates());return Math.min(er(t),er(n))}};function er(e){e.sort((e,t)=>e-t);let t=Number.MAX_VALUE;if(e.length>=2)for(let n=1;n<e.length;n++)e[n]!==e[n-1]&&(t=Math.min(t,e[n]-e[n-1]));return t}function j(e,t,n){let r=0;for(let i=0;i<e.length;i++){let a=e[i];if(a>n)break;a>=t&&r++}return r}function tr(e){let t=[],n=[];for(let r of e)r.setInWeight(r.getIncomingSegmentDependencies().length),r.setOutWeight(r.getOutgoingSegmentDependencies().length),r.getInWeight()===0&&t.push(r),r.getOutWeight()===0&&r.getIncomingConnectionCoordinates().length===0&&n.push(r);let r=-1,i=0;for(;i<t.length;){let e=t[i++];r=Math.max(r,e.getRoutingSlot());for(let n of e.getOutgoingSegmentDependencies()){let i=n.getTarget();i.setRoutingSlot(Math.max(i.getRoutingSlot(),e.getRoutingSlot()+1)),r=Math.max(r,i.getRoutingSlot()),i.setInWeight(i.getInWeight()-1),i.getInWeight()===0&&t.push(i)}}if(r>-1){for(let e of n)e.setRoutingSlot(r);let e=0;for(;e<n.length;){let t=n[e++];for(let e of t.getIncomingSegmentDependencies()){let r=e.getSource();r.getIncomingConnectionCoordinates().length>0||(r.setRoutingSlot(Math.min(r.getRoutingSlot(),t.getRoutingSlot()-1)),r.setOutWeight(r.getOutWeight()-1),r.getOutWeight()===0&&n.push(r))}}}return r+1}function nr(e,t){let n=Cn.detectCycles(e,!1,t);for(let e of n)e.getWeight()===0?e.remove():e.reverse()}var rr=class{process(t){let n=t.getProperty(e.un),r=t.getProperty(e.en),i=t.getProperty(e.rn),a=new $n(r),o=0,s=t.getLayers(),c=t=>t.length>0&&t.every(t=>t.getType().toString()===`EXTERNAL_PORT`&&(t.getProperty(e.Un)===`WEST`||t.getProperty(e.Un)===`EAST`)),l=null;for(let u=0;u<=s.length;u++){let d=u<s.length?s[u].getNodes():null;l!==null&&(Sn(s[u-1],o),o+=s[u-1].getSize().x);let f=l===null?o:o+i,p=t.getProperty(e.br),m=a.routeEdges(l,d,f,p),h=l===null||c(l),g=d===null||c(d);if(m>0){let e=(m-1)*r;l!==null&&(e+=i),d!==null&&(e+=i),e<n&&!h&&!g&&(e=n),o+=e}else!h&&!g&&(o+=n);l=d}let u=o;for(let e of s)for(let t of e.getNodes())u=Math.max(u,t.position.x+t.size.x);t.getSize().x=u}},ir=class{startPos=-1/0;delta=0;deltaNormalized=0;cNodes;incomingConstraints;outDegree=0;reference=null;id=0;reposition=!0;constructor(...e){this.cNodes=/* @__PURE__ */ new Set,this.incomingConstraints=/* @__PURE__ */ new Set,this.outDegree=0;for(let t of e)this.reference===null&&(this.reference=t),this.addCNode(t)}addCNode(e){if(e.cGroup!==null)throw Error(`CNode belongs to another CGroup.`);this.cNodes.add(e),e.cGroup=this}removeCNode(e){let t=this.cNodes.delete(e);return t&&(e.cGroup=null),t}},ar=class{cNodes=[];cGroups=[];predefinedHorizontalConstraints=[];supportedDirections;constructor(e){this.supportedDirections=new Set(e)}supports(e){return this.supportedDirections.has(e)}};const or={getHorizontalSpacing(e,t){return Math.max(e.getHorizontalSpacing(),t.getHorizontalSpacing())},getVerticalSpacing(e,t){return Math.max(e.getVerticalSpacing(),t.getVerticalSpacing())}};function sr(e,t){return Math.abs(e-t)<=1e-4?0:e<t?-1:1}const cr={eq(e,t){return sr(e,t)===0},gt(e,t){return sr(e,t)>0},lt(e,t){return sr(e,t)<0},ge(e,t){return sr(e,t)>=0},le(e,t){return sr(e,t)<=0}};function lr(e,t,n){let r=[...e];r.sort(t);for(let e of r)n.handle(e)}var ur=class{compact(e){let t=1/0;for(let n of e.cGraph.cNodes)t=Math.min(t,n.cGroup.reference.hitbox.x+n.cGroupOffset.x);let n=[];for(let r of e.cGraph.cGroups)r.startPos=t,r.outDegree===0&&n.push(r);for(;n.length>0;){let t=n.shift(),r=t.reference.hitbox.x;for(let e of t.cNodes){let n=t.startPos+e.cGroupOffset.x;e.startPos=e.cGroup.reposition||e.getPosition()<n?n:e.hitbox.x}r-=t.reference.startPos,t.delta+=r,e.direction===`RIGHT`||e.direction===`DOWN`?t.deltaNormalized+=r:t.deltaNormalized-=r;for(let r of t.cNodes)for(let t of r.constraints){let i=e.direction===`LEFT`||e.direction===`RIGHT`?e.spacingsHandler.getHorizontalSpacing(r,t):e.spacingsHandler.getVerticalSpacing(r,t);t.cGroup.startPos=Math.max(t.cGroup.startPos,r.startPos+r.hitbox.width+i-t.cGroupOffset.x),t.reposition||(t.cGroup.startPos=Math.max(t.cGroup.startPos,t.getPosition()-t.cGroupOffset.x)),t.cGroup.outDegree--,t.cGroup.outDegree===0&&n.push(t.cGroup)}}for(let t of e.cGraph.cNodes)t.applyPosition()}},dr=class{calculateConstraints(e){for(let t of e.cGraph.cNodes)t.constraints.length=0;for(let t of e.cGraph.cNodes)for(let n of e.cGraph.cNodes){if(t===n||t.cGroup!==null&&t.cGroup===n.cGroup)continue;let r=e.direction===`LEFT`||e.direction===`RIGHT`?e.spacingsHandler.getVerticalSpacing(t,n):e.spacingsHandler.getHorizontalSpacing(t,n);t!==n.parentNode&&(n.hitbox.x>t.hitbox.x||t.hitbox.x===n.hitbox.x&&t.hitbox.width<n.hitbox.width)&&cr.gt(n.hitbox.y+n.hitbox.height+r,t.hitbox.y)&&cr.lt(n.hitbox.y,t.hitbox.y+t.hitbox.height+r)&&t.constraints.push(n)}}},M=class e{static EPSILON=.5;compactor;calculateConstraints(e){this.compactor=e,this.sweep(()=>!0,()=>0)}sweep(e,t){this.blowUpHitboxes(e,t);let n=[];for(let t of this.compactor.cGraph.cNodes)e(t)&&(n.push(new fr(t,!0)),n.push(new fr(t,!1)));let r=0;for(let t of this.compactor.cGraph.cNodes)e(t)&&(t.id=r++);this.handler.reset(this.compactor.cGraph.cNodes.length),lr(n,mr,this.handler),this.normalizeHitboxes(e,t)}blowUpHitboxes(t,n){for(let r of this.compactor.cGraph.cNodes){if(!t(r))continue;let i=n(r);i>0&&((this.compactor.direction===`LEFT`||this.compactor.direction===`RIGHT`?r.spacingIgnore.up:r.spacingIgnore.left)||(r.hitbox.y-=Math.max(0,i/2-e.EPSILON)),(this.compactor.direction===`LEFT`||this.compactor.direction===`RIGHT`?r.spacingIgnore.down:r.spacingIgnore.right)||(r.hitbox.height+=Math.max(0,i-2*e.EPSILON)))}}normalizeHitboxes(t,n){for(let r of this.compactor.cGraph.cNodes){if(!t(r))continue;let i=n(r);i>0&&((this.compactor.direction===`LEFT`||this.compactor.direction===`RIGHT`?r.spacingIgnore.up:r.spacingIgnore.left)||(r.hitbox.y+=Math.max(0,i/2-e.EPSILON)),(this.compactor.direction===`LEFT`||this.compactor.direction===`RIGHT`?r.spacingIgnore.down:r.spacingIgnore.right)||(r.hitbox.height-=i-2*e.EPSILON))}}handler=new hr},fr=class{node;low;constructor(e,t){this.node=e,this.low=t}};function pr(e){return e.low?e.node.hitbox.y:e.node.hitbox.y+e.node.hitbox.height}const mr=(e,t)=>{let n=pr(e)-pr(t);if(n===0){if(!e.low&&t.low)return-1;if(!t.low&&e.low)return 1}return n};var hr=class{intervals=[];cand=[];reset(e){this.intervals=[],this.cand=Array(e)}handle(e){e.low?this.insert(e):this.delete(e)}insert(e){this.intervals.push(e.node),this.intervals.sort((e,t)=>e.hitbox.x+e.hitbox.width/2-(t.hitbox.x+t.hitbox.width/2)),this.cand[e.node.id]=this.lower(e.node);let t=this.higher(e.node);t!==null&&(this.cand[t.id]=e.node)}delete(e){let t=this.lower(e.node);t!==null&&t===this.cand[e.node.id]&&t.cGroup!==null&&t.cGroup!==e.node.cGroup&&t.constraints.push(e.node);let n=this.higher(e.node);n!==null&&this.cand[n.id]===e.node&&n.cGroup!==null&&n.cGroup!==e.node.cGroup&&e.node.constraints.push(n),this.intervals.splice(this.intervals.indexOf(e.node),1)}lower(e){let t=e.hitbox.x+e.hitbox.width/2,n=null;for(let r of this.intervals){let i=r.hitbox.x+r.hitbox.width/2;if(i<t)n=r;else if((i!==t||r===e||n!==null)&&i>t)break}return n}higher(e){let t=e.hitbox.x+e.hitbox.width/2;for(let e of this.intervals)if(e.hitbox.x+e.hitbox.width/2>t)return e;return null}},gr=class e{static LONGEST_PATH_COMPACTION=new ur;static SCANLINE_CONSTRAINTS=new M;static QUADRATIC_CONSTRAINTS=new dr;compactionAlgorithm=e.LONGEST_PATH_COMPACTION;constraintAlgorithm=e.SCANLINE_CONSTRAINTS;cGraph;direction=`UNDEFINED`;lockingStrategy;finished=!1;spacingsHandler=or;constructor(e){this.cGraph=e,this.lockingStrategy=e=>e.first.cGroup.outDegree!==0,this.calculateGroupOffsets();for(let t of e.cNodes)if(t.cGroup===null){let n=new ir(t);e.cGroups.push(n)}}setSpacingsHandler(e){return this.spacingsHandler=e,this}setCompactionAlgorithm(e){return this.compactionAlgorithm=e,this}setConstraintAlgorithm(e){return this.constraintAlgorithm=e,this}compact(){if(this.finished)throw Error(`The OneDimensionalCompactor instance has been finished already.`);this.direction===`UNDEFINED`&&this.changeDirection(`LEFT`);for(let e of this.cGraph.cNodes)e.hitboxPreCompaction={...e.hitbox};for(let e of this.cGraph.cGroups)e.outDegree=0;for(let e of this.cGraph.cNodes){e.startPos=-1/0;for(let t of e.constraints)t.cGroup.outDegree++}this.compactionAlgorithm.compact(this);for(let e of this.cGraph.cNodes)e.reposition=!0;return this}finish(){return this.changeDirection(`LEFT`),this.finished=!0,this}changeDirection(e){if(this.finished)throw Error(`The OneDimensionalCompactor instance has been finished already.`);if(!this.cGraph.supports(e))throw Error(`The direction ${e} is not supported by the CGraph instance.`);if(e===this.direction)return this;let t=this.direction;switch(this.direction=e,t){case`UNDEFINED`:e===`LEFT`?this.calculateConstraints():e===`RIGHT`?(this.mirrorHitboxes(),this.calculateConstraints()):e===`UP`?(this.transposeHitboxes(),this.calculateConstraints()):e===`DOWN`&&(this.transposeHitboxes(),this.mirrorHitboxes(),this.calculateConstraints());break;case`LEFT`:e===`RIGHT`?(this.mirrorHitboxes(),this.reverseConstraints()):e===`UP`?(this.transposeHitboxes(),this.calculateConstraints()):e===`DOWN`&&(this.transposeHitboxes(),this.mirrorHitboxes(),this.calculateConstraints());break;case`RIGHT`:e===`LEFT`?(this.mirrorHitboxes(),this.reverseConstraints()):e===`UP`?(this.mirrorHitboxes(),this.transposeHitboxes(),this.calculateConstraints()):e===`DOWN`&&(this.mirrorHitboxes(),this.transposeHitboxes(),this.mirrorHitboxes(),this.calculateConstraints());break;case`UP`:e===`LEFT`?(this.transposeHitboxes(),this.calculateConstraints()):e===`RIGHT`?(this.transposeHitboxes(),this.mirrorHitboxes(),this.calculateConstraints()):e===`DOWN`&&(this.mirrorHitboxes(),this.reverseConstraints());break;case`DOWN`:e===`LEFT`?(this.mirrorHitboxes(),this.transposeHitboxes(),this.calculateConstraints()):e===`RIGHT`?(this.mirrorHitboxes(),this.transposeHitboxes(),this.mirrorHitboxes(),this.calculateConstraints()):e===`UP`&&(this.mirrorHitboxes(),this.reverseConstraints())}return this}setLockingStrategy(e){return this.lockingStrategy=e,this}applyLockingStrategy(e){let t=e??this.direction;for(let e of this.cGraph.cGroups)e.reposition=!0;for(let e of this.cGraph.cNodes)e.reposition=this.lockingStrategy({first:e,second:t}),e.cGroup.reposition=e.cGroup.reposition&&e.reposition;return this}forceConstraintsRecalculation(){return this.calculateConstraints(),this}calculateGroupOffsets(){for(let e of this.cGraph.cGroups){e.reference=null;for(let t of e.cNodes)t.cGroupOffset.x=0,t.cGroupOffset.y=0,(e.reference===null||t.hitbox.x<e.reference.hitbox.x)&&(e.reference=t);for(let t of e.cNodes)t.cGroupOffset.x=t.hitbox.x-e.reference.hitbox.x,t.cGroupOffset.y=t.hitbox.y-e.reference.hitbox.y}return this}mirrorHitboxes(){for(let e of this.cGraph.cNodes)e.hitbox.x=-e.hitbox.x-e.hitbox.width,e.parentNode!==null&&(e.cGroupOffset.x=-e.cGroupOffset.x+e.parentNode.hitbox.width);this.calculateGroupOffsets()}transposeHitboxes(){for(let e of this.cGraph.cNodes){let t=e.hitbox.x;e.hitbox.x=e.hitbox.y,e.hitbox.y=t,t=e.hitbox.width,e.hitbox.width=e.hitbox.height,e.hitbox.height=t,t=e.cGroupOffset.x,e.cGroupOffset.x=e.cGroupOffset.y,e.cGroupOffset.y=t}this.calculateGroupOffsets()}calculateConstraints(){for(let e of this.cGraph.cNodes)e.constraints.length=0;let e=this.cGraph.predefinedHorizontalConstraints;for(let[t,n]of e)this.direction===`LEFT`||this.direction===`UP`?t.constraints.push(n):n.constraints.push(t);this.constraintAlgorithm.calculateConstraints(this),this.calculateConstraintsForCGroups()}calculateConstraintsForCGroups(){for(let e of this.cGraph.cGroups)e.outDegree=0,e.incomingConstraints.clear();for(let e of this.cGraph.cGroups)for(let t of e.cNodes)for(let n of t.constraints)n.cGroup!==e&&(e.incomingConstraints.add(n),n.cGroup.outDegree++)}reverseConstraints(){let e=/* @__PURE__ */ new Map;for(let t of this.cGraph.cNodes)e.set(t,[]);for(let t of this.cGraph.cNodes){t.startPos=-1/0;for(let n of t.constraints)e.get(n).push(t)}for(let t of this.cGraph.cNodes)t.constraints=e.get(t);this.calculateConstraintsForCGroups()}},_r=class{left=!1;right=!1;up=!1;down=!1;constructor(e=!1,t=!1,n=!1,r=!1){this.set(e,t,n,r)}set(e,t,n,r){typeof t==`boolean`?(this.left=e,this.right=t,this.up=n??!1,this.down=r??!1):this.setDirection(e,t)}setDirection(e,t){switch(t){case`LEFT`:this.left=e;break;case`RIGHT`:this.right=e;break;case`UP`:this.up=e;break;case`DOWN`:this.down=e}}applyOr(e){this.left=this.left||e.left,this.right=this.right||e.right,this.up=this.up||e.up,this.down=this.down||e.down}get(e){switch(e){case`LEFT`:return this.left;case`RIGHT`:return this.right;case`UP`:return this.up;case`DOWN`:return this.down;default:return!1}}},vr=class{cGroup=null;parentNode=null;constraints=[];hitbox={x:0,y:0,width:0,height:0};hitboxPreCompaction=null;cGroupOffset=e.ti(0,0);startPos=-1/0;reposition=!0;lock=new _r;spacingIgnore=new _r;id=0;getPosition(){return this.hitbox.x}applyPosition(){this.hitbox.x=this.startPos}},N=class extends vr{lNode;constructor(e){super(),this.lNode=e;let t=e.getMargin(),n=e.getPosition(),r=e.getSize();this.hitbox={x:n.x-t.left,y:n.y-t.top,width:r.x+t.left+t.right,height:r.y+t.top+t.bottom}}getHorizontalSpacing(){return 0}getVerticalSpacing(){return 0}applyElementPosition(){this.lNode.getPosition().x=this.hitbox.x+this.lNode.getMargin().left}getElementPosition(){return this.hitbox.x}},P=class extends vr{vs;constructor(e){super(),this.vs=e,this.hitbox={...e.hitbox}}getHorizontalSpacing(){return 0}getVerticalSpacing(){return 0}applyElementPosition(){let e=this.hitboxPreCompaction,t=e===null?0:this.hitbox.x-e.x;for(let e of this.vs.affectedBends)e.x+=t;for(let e of this.vs.affectedBoundingBoxes)e.x+=t;for(let e of this.vs.junctionPoints)e.x+=t}getElementPosition(){return this.hitbox.x}};const yr=.01;var br=class extends M{graph;verticalEdgeEdgeSpacing;edgeRouting;constructor(t){super(),this.graph=t,this.verticalEdgeEdgeSpacing=t.getProperty(e.$t),this.edgeRouting=t.getProperty(e.B)}calculateConstraints(e){this.compactor=e,this.edgeRouting===`SPLINES`?this.calculateForSpline():this.calculateForOrthogonal()}alterHitbox(e,t,n){let r=t*n;if(e instanceof P){let t=e.vs;t.ignoreSpacing.up?t.ignoreSpacing.down||(e.hitbox.height+=r+yr):(e.hitbox.y-=r+yr,e.hitbox.height+=r+yr)}else e instanceof N&&(e.hitbox.y-=r,e.hitbox.height+=2*r)}alterGroupedHitboxOrthogonal(e,t,n){let r=null;for(let t of e.cNodes)if(t instanceof N){r=t;break}if(r===null&&(r=e.cNodes.values().next().value??null),r===null||(this.alterHitbox(r,t,n),e.cNodes.size===1))return;let i=t*n;for(let t of e.cNodes){if(t===r||!(t instanceof P))continue;let e=t.vs;e.ignoreSpacing.up?(t.hitbox.y+=i+yr,t.hitbox.height-=i+yr):e.ignoreSpacing.down&&(t.hitbox.height-=i+yr)}}calculateForSpline(){this.sweep(e=>e instanceof P,()=>0);let t=1/0;for(let n of this.compactor.cGraph.cNodes)if(!(n instanceof N&&n.lNode.getType()===`EXTERNAL_PORT`)){if(n instanceof P)t=Math.min(t,Math.max(0,this.verticalEdgeEdgeSpacing/2-M.EPSILON));else if(n instanceof N){let n=this.graph.getProperty(e.ln);t=Math.min(t,Math.max(0,n/2-M.EPSILON))}}Number.isFinite(t)||(t=0);let n=[];for(let e of this.compactor.cGraph.cNodes)e instanceof N&&(this.alterHitbox(e,t,1),n.push([e,t]));this.sweep(e=>!0,()=>0);for(let[e,t]of n)this.alterHitbox(e,t,-1)}calculateForOrthogonal(){let t=[];for(let e of this.compactor.cGraph.cNodes)if(e instanceof P){let n=Math.max(0,this.verticalEdgeEdgeSpacing/2-M.EPSILON);this.alterHitbox(e,n,1),t.push([e,n])}this.sweep(e=>e instanceof P,()=>0);for(let[e,n]of t)this.alterHitbox(e,n,-1);let n=[];for(let t of this.compactor.cGraph.cNodes)if(t instanceof N){let r=Math.max(0,this.graph.getProperty(e.$t)/2-M.EPSILON);this.alterHitbox(t,r,1),n.push([t,r])}this.sweep(e=>e instanceof N,()=>0);for(let[e,t]of n)this.alterHitbox(e,t,-1);let r=1/0;for(let t of this.compactor.cGraph.cNodes)t instanceof N&&t.lNode.getType()===`EXTERNAL_PORT`||(t instanceof P?r=Math.min(r,Math.max(0,this.verticalEdgeEdgeSpacing/2-M.EPSILON)):t instanceof N&&(r=Math.min(r,Math.max(0,this.graph.getProperty(e.ln)/2-M.EPSILON))));Number.isFinite(r)||(r=0);let i=[];for(let e of this.compactor.cGraph.cGroups)this.alterGroupedHitboxOrthogonal(e,r,1),i.push([e,r]);this.sweep(e=>!0,()=>0);for(let[e,t]of i)this.alterGroupedHitboxOrthogonal(e,t,-1)}},xr=class{potentialGroupParents=[];representedLEdges=[];affectedBends=[];affectedBoundingBoxes=[];hitbox={x:0,y:0,width:0,height:0};junctionPoints=[];ignoreSpacing=new _r;constraints=[];aPort=null;joined=[];constructor(e,t,n,r){this.affectedBends.push(e),this.affectedBends.push(t),this.hitbox.x=Math.min(e.x,t.x),this.hitbox.y=Math.min(e.y,t.y),this.hitbox.width=Math.abs(e.x-t.x),this.hitbox.height=Math.abs(e.y-t.y),n!==null&&this.potentialGroupParents.push(n),this.representedLEdges.push(r)}joinWith(e){this.representedLEdges.push(...e.representedLEdges),this.affectedBends.push(...e.affectedBends),this.affectedBoundingBoxes.push(...e.affectedBoundingBoxes),this.junctionPoints.push(...e.junctionPoints),this.constraints.push(...e.constraints),this.potentialGroupParents.push(...e.potentialGroupParents);let t=Math.min(this.hitbox.x,e.hitbox.x),n=Math.min(this.hitbox.y,e.hitbox.y),r=Math.max(this.hitbox.x+this.hitbox.width,e.hitbox.x+e.hitbox.width),i=Math.max(this.hitbox.y+this.hitbox.height,e.hitbox.y+e.hitbox.height);return this.hitbox={x:t,y:n,width:r-t,height:i-n},this.ignoreSpacing.applyOr(e.ignoreSpacing),this.aPort===null&&(this.aPort=e.aPort),this.joined.push(...e.joined),this.joined.push(e),this}intersects(e){return cr.eq(this.hitbox.x,e.hitbox.x)&&!(cr.lt(this.hitbox.y+this.hitbox.height,e.hitbox.y)||cr.lt(e.hitbox.y+e.hitbox.height,this.hitbox.y))}compareTo(e){let t=cr.eq(this.hitbox.x,e.hitbox.x)?0:this.hitbox.x<e.hitbox.x?-1:1;return t===0?this.hitbox.y-e.hitbox.y:t}},Sr=class{cGraph;layeredGraph;edgeRouting;nodesMap=/* @__PURE__ */ new Map;verticalSegmentsMap=/* @__PURE__ */ new Map;lockMap=/* @__PURE__ */ new Map;transform(t){return this.layeredGraph=t,this.edgeRouting=t.getProperty(e.B),this.cGraph=new ar([`LEFT`,`RIGHT`]),this.nodesMap=/* @__PURE__ */ new Map,this.verticalSegmentsMap=/* @__PURE__ */ new Map,this.lockMap=/* @__PURE__ */ new Map,this.transformNodes(),this.transformEdges(),this.cGraph}getLockMap(){return this.lockMap}transformNodes(){let e=0;for(let t of this.layeredGraph.getLayers())for(let n of t.getNodes()){let t=new N(n);t.id=e++,this.cGraph.cNodes.push(t);let r=new ir(t);this.cGraph.cGroups.push(r);let i=new _r;this.lockMap.set(t,i);let a=n.getIncomingEdges().length-n.getOutgoingEdges().length;a<0?i.set(!0,`LEFT`):a>0&&i.set(!0,`RIGHT`),n.getType()===`EXTERNAL_PORT`&&i.set(!1,!1,!1,!1),this.nodesMap.set(n,t)}}transformEdges(){let e;e=this.edgeRouting===`ORTHOGONAL`?this.collectVerticalSegmentsOrthogonal():this.edgeRouting===`SPLINES`?this.collectVerticalSegmentsSplines():[],this.mergeVerticalSegments(e);for(let[e,t]of this.verticalSegmentsMap)for(let n of e.constraints){let e=this.verticalSegmentsMap.get(n);e&&this.cGraph.predefinedHorizontalConstraints.push([t,e])}}collectVerticalSegmentsOrthogonal(){let e=[];for(let t of this.layeredGraph.getLayers())for(let n of t.getNodes()){let t=this.nodesMap.get(n);if(t){for(let r of n.getOutgoingEdges()){let n=r.getBendPoints();if(n.length===0)continue;let i=!0,a=null,o=n[0],s=null,c=r.getSource();if(c.getSide()===`NORTH`){let n=new xr(o,{x:o.x,y:t.hitbox.y},t,r);n.ignoreSpacing.down=!0,n.aPort=c,e.push(n)}if(c.getSide()===`SOUTH`){let n=new xr(o,{x:o.x,y:t.hitbox.y+t.hitbox.height},t,r);n.ignoreSpacing.up=!0,n.aPort=c,e.push(n)}for(let c=1;c<n.length;c++)s=n[c],cr.eq(o.y,s.y)||(a=new xr(o,s,null,r),e.push(a),i&&(i=!1,s.y<t.hitbox.y?a.ignoreSpacing.down=!0:s.y>t.hitbox.y+t.hitbox.height?a.ignoreSpacing.up=!0:(a.ignoreSpacing.up=!0,a.ignoreSpacing.down=!0))),c+1<n.length&&(o=s);if(a!==null){let e=this.nodesMap.get(r.getTarget().getNode());e&&(o.y<e.hitbox.y?a.ignoreSpacing.down=!0:o.y>e.hitbox.y+e.hitbox.height?a.ignoreSpacing.up=!0:(a.ignoreSpacing.up=!0,a.ignoreSpacing.down=!0))}}for(let r of n.getIncomingEdges()){let n=r.getBendPoints();if(n.length===0)continue;let i=n[n.length-1],a=r.getTarget();if(a.getSide()===`NORTH`){let n=new xr(i,{x:i.x,y:t.hitbox.y},t,r);n.ignoreSpacing.down=!0,n.aPort=a,e.push(n)}if(a.getSide()===`SOUTH`){let n=new xr(i,{x:i.x,y:t.hitbox.y+t.hitbox.height},t,r);n.ignoreSpacing.up=!0,n.aPort=a,e.push(n)}}}}return e}collectVerticalSegmentsSplines(){let t=[];this.cGraph.cNodes.length;for(let n of this.layeredGraph.getLayers())for(let r of n.getNodes())for(let n of r.getOutgoingEdges()){let r=n.getProperty(e.Dr);if(!r||r.length===0)continue;let i=null;for(let e of r){if(e.isStraight)continue;let n=new xr({x:e.boundingBox.x,y:e.boundingBox.y},{x:e.boundingBox.x+e.boundingBox.width,y:e.boundingBox.y+e.boundingBox.height},null,e.edges[0]);n.affectedBoundingBoxes.push(e.boundingBox),t.push(n),i!==null&&i.constraints.push(n),i=n}}return t}mergeVerticalSegments(e){if(e.length===0)return;e.sort((e,t)=>e.compareTo(t));let t=e[0];for(let n=1;n<e.length;n++){let r=e[n];t.intersects(r)?t.joinWith(r):(this.verticalSegmentToCNode(t),t=r)}this.verticalSegmentToCNode(t)}verticalSegmentToCNode(e){let t=new P(e);if(t.id=this.cGraph.cNodes.length,this.cGraph.cNodes.push(t),e.potentialGroupParents.length>0){let n=e.potentialGroupParents[0].cGroup;n&&n.addCNode(t)}else{let e=new ir(t);this.cGraph.cGroups.push(e)}let n=new _r;this.lockMap.set(t,n);let r=/* @__PURE__ */ new Set,i=/* @__PURE__ */ new Set;for(let t of e.representedLEdges)t.getSource()&&r.add(t.getSource().id),t.getTarget()&&i.add(t.getTarget().id);let a=r.size-i.size;a<0?(n.set(!0,`LEFT`),n.set(!1,`RIGHT`)):a>0&&(n.set(!1,`LEFT`),n.set(!0,`RIGHT`));for(let n of e.joined)this.verticalSegmentsMap.set(n,t);this.verticalSegmentsMap.set(e,t)}applyLayout(){for(let e of this.cGraph.cNodes)e instanceof N&&e.applyElementPosition();for(let e of this.cGraph.cNodes)e instanceof P&&e.applyElementPosition();if(this.edgeRouting===`SPLINES`){for(let e of this.layeredGraph.getLayers())for(let t of e.getNodes())for(let e of t.getOutgoingEdges()){if(!e.isSelfLoop())continue;let t=e.getSource().getNode(),n=this.nodesMap.get(t);if(n===void 0||n.hitboxPreCompaction===null)continue;let r=n.hitbox.x-n.hitboxPreCompaction.x;for(let t of e.getBendPoints())t.x+=r}for(let t of this.layeredGraph.getLayers())for(let n of t.getNodes())for(let t of n.getOutgoingEdges()){let n=t.getProperty(e.Dr);n!=null&&n.length>0&&this.adjustSplineControlPoints(n)}}let t=1/0,n=1/0,r=-1/0,i=-1/0;for(let e of this.cGraph.cNodes)t=Math.min(t,e.hitbox.x),n=Math.min(n,e.hitbox.y),r=Math.max(r,e.hitbox.x+e.hitbox.width),i=Math.max(i,e.hitbox.y+e.hitbox.height);Number.isFinite(t)&&(this.layeredGraph.getOffset().x=-t,this.layeredGraph.getOffset().y=-n,this.layeredGraph.getSize().x=r-t,this.layeredGraph.getSize().y=i-n)}adjustSplineControlPoints(e){if(e.length===0)return;let t=e[0];if(e.length===1){this.adjustControlPointBetweenSegments(t,t,1,0,e);return}let n=1;for(;n<e.length;)if(t.initialSegment||!t.isStraight){let r=this.firstNonStraightSegment(e,n);if(r!==null){let i=r.index,a=r.segment;this.adjustControlPointBetweenSegments(t,a,n,i,e),n=i+1,t=a}}}firstNonStraightSegment(e,t){if(t<0||t>=e.length)return null;for(let n=t;n<e.length;n++){let t=e[n];if(n===e.length-1||!t.isStraight)return{index:n,segment:t}}return null}adjustControlPointBetweenSegments(e,t,n,r,i){let a,o=n;if(e.initialSegment&&e.isStraight){let t=this.nodesMap.get(e.sourceNode);a=t.hitbox.x+t.hitbox.width,o--}else a=e.boundingBox.x+e.boundingBox.width;let s,c=r;t.lastSegment&&t.isStraight?(s=this.nodesMap.get(t.targetNode).hitbox.x,c++):s=t.boundingBox.x;let l=(s-a)/Math.max(2,c-o),u=a+l;for(let e=o;e<c;e++){let t=i[e],n=t.boundingBox.width;t.boundingBox.x=u-n/2,u+=l}}};function Cr(e){return e.getOutgoingEdges().length>0}function wr(e){return e.getIncomingEdges().length>0}function Tr(e){return e===`NORTH`||e===`SOUTH`}function Er(e){return e===`LEFT`||e===`RIGHT`}function Dr(e){return Math.trunc(Math.ceil(e))}var Or=class{compactor;networkSimplexGraph;nNodes=[];index=0;compact(e){this.compactor=e,this.networkSimplexGraph=new re,this.nNodes=Array(this.compactor.cGraph.cGroups.length),this.index=0;for(let e of this.compactor.cGraph.cGroups){e.id=this.index;let t=T().id(this.index).origin(e).create(this.networkSimplexGraph);this.nNodes[this.index]=t,this.index++}this.addSeparationConstraints(),this.addEdgeConstraints(),this.addArtificialSourceNode(),ie.forGraph(this.networkSimplexGraph).execute();for(let e of this.compactor.cGraph.cNodes)e.hitbox.x=this.nNodes[e.cGroup.id].layer+e.cGroupOffset.x}addSeparationConstraints(){for(let e of this.compactor.cGraph.cNodes)for(let t of e.constraints){if(e.cGroup===t.cGroup)continue;let n=Er(this.compactor.direction)?this.compactor.spacingsHandler.getHorizontalSpacing(e,t):this.compactor.spacingsHandler.getVerticalSpacing(e,t),r=e.cGroupOffset.x+e.hitbox.width+n-t.cGroupOffset.x;if(r=Math.ceil(r),r=Math.max(0,r),kr(e,t)){let n=T().create(this.networkSimplexGraph),r=Dr(t.cGroupOffset.x-e.cGroupOffset.x),i=r-(t.cGroupOffset.x-e.cGroupOffset.x),a=jr(e)?.aPort??null,o=e;a===null&&(a=jr(t)?.aPort??null,i=-i,o=t),a!==null&&(o.cGroupOffset.x-=i,a.getPosition().x-=i),D().delta(Math.max(0,r)).weight(1).source(n).target(this.nNodes[e.cGroup.id]).create(),D().delta(Math.max(0,-r)).weight(1).source(n).target(this.nNodes[t.cGroup.id]).create()}else{let n=1;(e instanceof P&&t instanceof N||t instanceof P&&e instanceof N)&&(n=2),D().delta(r).weight(n).source(this.nNodes[e.cGroup.id]).target(this.nNodes[t.cGroup.id]).create()}}}addEdgeConstraints(){let e=/* @__PURE__ */ new Map,t=/* @__PURE__ */ new Map;for(let n of this.compactor.cGraph.cNodes){let r=Ar(n);if(r!==null)e.set(r,n);else{let e=jr(n);if(e!==null)for(let r of e.representedLEdges){let e=t.get(r);e===void 0?t.set(r,[n]):e.push(n)}}}for(let n of this.compactor.cGraph.cNodes){let r=Ar(n);if(r!==null)for(let i of r.getOutgoingEdges()){if(i.isSelfLoop())continue;let r=i.getSource(),a=i.getTarget();if(r===null||a===null||Tr(r.getSide())&&Tr(a.getSide()))continue;let o=e.get(a.getNode());if(o!==void 0){if(D().delta(0).weight(100).source(this.nNodes[n.cGroup.id]).target(this.nNodes[o.cGroup.id]).create(),r.getSide()===`WEST`&&Cr(r)){for(let e of t.get(i)??[])if(e.hitbox.x<n.hitbox.x){let t=this.nNodes[e.cGroup.id],r=this.nNodes[n.cGroup.id];if(t===r)continue;D().delta(1).weight(100).source(t).target(r).create()}}if(a.getSide()===`EAST`&&wr(a)){for(let e of t.get(i)??[])if(e.hitbox.x>n.hitbox.x){let t=this.nNodes[n.cGroup.id],r=this.nNodes[e.cGroup.id];if(t===r)continue;D().delta(1).weight(100).source(t).target(r).create()}}}}}}addArtificialSourceNode(){let e=[];for(let t of this.networkSimplexGraph.nodes)t.getIncomingEdges().length===0&&e.push(t);if(e.length>1){let t=T().id(this.index++).create(this.networkSimplexGraph);for(let n of e)D().delta(1).weight(0).source(t).target(n).create()}}};function kr(e,t){let n=e instanceof P?e.vs:null,r=t instanceof P?t.vs:null;return n===null||r===null?!1:n.representedLEdges.some(e=>r.representedLEdges.includes(e))}function Ar(e){return e instanceof N?e.lNode:null}function jr(e){return e instanceof P?e.vs:null}var Mr=class{lGraph;process(t){let n=t.getProperty(e.v);if(n===`NONE`)return;this.lGraph=t;let r=new Sr,i=new gr(r.transform(t));switch(i.setSpacingsHandler(this.specialSpacingsHandler),t.getProperty(e._)===`SCANLINE`?i.setConstraintAlgorithm(new br(t)):i.setConstraintAlgorithm(gr.QUADRATIC_CONSTRAINTS),n){case`LEFT`:i.compact();break;case`RIGHT`:i.changeDirection(`RIGHT`).compact();break;case`LEFT_RIGHT_CONSTRAINT_LOCKING`:i.compact().changeDirection(`RIGHT`).setLockingStrategy(e=>e.first.cGroup.outDegree===0).applyLockingStrategy().compact();break;case`LEFT_RIGHT_CONNECTION_LOCKING`:i.compact().changeDirection(`RIGHT`).setLockingStrategy(e=>r.getLockMap().get(e.first)?.get(e.second)??!1).applyLockingStrategy().compact();break;case`EDGE_LENGTH`:i.setCompactionAlgorithm(new Or).compact()}i.finish(),r.applyLayout()}specialSpacingsHandler={getHorizontalSpacing:(t,n)=>{if(kr(t,n))return 0;let r=Ar(t),i=Ar(n);if(r!==null&&r.getType()===`EXTERNAL_PORT`||i!==null&&i.getType()===`EXTERNAL_PORT`)return 0;let a=this.lGraph.getProperty(e.wr);return a?a.getHorizontalSpacingByType(r===null?`LONG_EDGE`:r.getType(),i===null?`LONG_EDGE`:i.getType()):0},getVerticalSpacing:(t,n)=>{if(kr(t,n))return 1;let r=Ar(t),i=Ar(n),a=this.lGraph.getProperty(e.wr);return a?a.getVerticalSpacingByType(r===null?`LONG_EDGE`:r.getType(),i===null?`LONG_EDGE`:i.getType()):0}}};const Nr=.4;function Pr(e,t){return e.x===t.x&&e.y===t.y}var Fr=class{createdJunctionPoints=/* @__PURE__ */ new Set;process(t){let n=t.getProperty(e.V),r=t.getProperty(e.un),i=t.getProperty(e.en),a=Math.min(1,i/r),o=0,s=0,c=t.getLayers();if(c.length>0){let e=this.calculateWestInLayerEdgeYDiff(c[0]);o=Nr*a*e}for(let e=0;e<c.length;e++){let t=c[e],i=t.getNodes().length>0&&t.getNodes().every(e=>e.getType()===`EXTERNAL_PORT`),l=e+1<c.length;i&&o>0&&(o-=r),Ir(t,o);let u=0;for(let e of t.getNodes()){let r=0;for(let n of e.getOutgoingEdges()){let e=n.getSource(),i=n.getTarget();if(!e||!i)continue;let s=e.getAbsoluteAnchor().y,c=i.getAbsoluteAnchor().y;i.getNode()?.getLayer()===t&&!n.isSelfLoop()&&(this.processInLayerEdge(n,o,Nr*a*Math.abs(s-c)),e.getSide()===`WEST`&&(s=0,c=0)),r=Math.max(r,Math.abs(c-s))}switch(e.getType()){case`NORMAL`:case`LABEL`:case`LONG_EDGE`:case`NORTH_SOUTH_PORT`:case`BREAKING_POINT`:this.processNode(e,o,n)}u=Math.max(u,r)}if(l){let t=this.calculateWestInLayerEdgeYDiff(c[e+1]);u=Math.max(u,t)}s=Nr*a*u,!i&&l&&(s+=r),o+=t.getSize().x+s}this.createdJunctionPoints.clear(),t.getSize().x=o}processNode(t,n,r){let i=n+t.getLayer().getSize().x;for(let a of t.getPorts()){let o={...a.getAbsoluteAnchor()};if(t.getType()===`NORTH_SOUTH_PORT`){let n=a.getProperty(e.lr);n&&(o.x=n.getAbsoluteAnchor().x,t.getPosition().x=o.x)}let s={x:0,y:o.y};if(a.getSide()===`EAST`)s.x=i;else if(a.getSide()===`WEST`)s.x=n;else continue;if(Math.abs(o.x-s.x)<=r&&!this.isInLayerDummy(t))continue;let c=a.getOutgoingEdges().length+a.getIncomingEdges().length>1;for(let e of a.getConnectedEdges()){let t=e.getSource()===a?e.getTarget():e.getSource();Math.abs(t.getAbsoluteAnchor().y-s.y)>1&&this.addBendPoint(e,s,c,a)}}}processInLayerEdge(e,t,n){let r=e.getSource(),i=e.getTarget(),a=(r.getAbsoluteAnchor().y+i.getAbsoluteAnchor().y)/2,o=r.getSide()===`EAST`?{x:t+r.getNode().getLayer().getSize().x+n,y:a}:{x:t-n,y:a};e.getBendPoints().unshift(o)}addBendPoint(t,n,r,i){if((t.isInLayerEdge()||!Pr(i.getAbsoluteAnchor(),n))&&!t.isSelfLoop()){t.getSource()===i?t.getBendPoints().unshift({...n}):t.getBendPoints().push({...n});let a=`${n.x},${n.y}`;if(r&&!this.createdJunctionPoints.has(a)){let r=t.getProperty(e.nt);r??(r=[],t.setProperty(e.nt,r));let i={...n};r.push(i),this.createdJunctionPoints.add(a)}}}isInLayerDummy(e){if(e.getType()===`LONG_EDGE`){for(let t of e.getConnectedEdges())if(t.isInLayerEdge())return!0}return!1}calculateWestInLayerEdgeYDiff(e){let t=0;for(let n of e.getNodes())for(let r of n.getOutgoingEdges()){let n=r.getSource(),i=r.getTarget();if(n&&i&&i.getNode()?.getLayer()===e&&n.getSide()===`WEST`){let e=n.getAbsoluteAnchor().y,r=i.getAbsoluteAnchor().y;t=Math.max(t,Math.abs(r-e))}}return t}};function Ir(t,n){let r=0,i=0;for(let e of t.getNodes())r=Math.max(r,e.getMargin().left),i=Math.max(i,e.getMargin().right);for(let a of t.getNodes()){let o=a.getProperty(e.p),s;if(o===`LEFT`)s=0;else if(o===`RIGHT`)s=1;else if(o===`CENTER`)s=.5;else{let e=0,t=0;for(let n of a.getPorts())n.getIncomingEdges().length>0&&e++,n.getOutgoingEdges().length>0&&t++;s=e+t===0?.5:t/(e+t)}let c=t.getSize(),l=a.getSize().x,u=(c.x-l)*s;s>.5?u-=i*2*(s-.5):s<.5&&(u+=r*2*(.5-s));let d=a.getMargin().left;u<d&&(u=d);let f=a.getMargin().right;u>c.x-f-l&&(u=c.x-f-l),a.getPosition().x=n+u}}var Lr=class{source;target;weight;constructor(e,t,n){this.source=e,this.target=t,this.weight=n,e.outgoing.push(this),t.incoming.push(this)}};const Rr=.9,zr=.09999999999999998,Br=.5;var Vr=class e{mark=0;inweight=0;outweight=0;rank=0;outgoing=[];incoming=[];leftPorts=[];rightPorts=[];edges=[];boundingBox={x:0,y:0,width:0,height:0};xDelta=0;isWestOfInitialLayer=!1;isStraight=!1;centerControlPointY=0;hyperEdgeTopYPos=0;hyperEdgeBottomYPos=0;handled=!1;sourcePort=null;targetPort=null;initialSegment=!1;lastSegment=!1;sourceNode=null;targetNode=null;inverseOrder=!1;edgeInformation=/* @__PURE__ */ new Map;constructor(){}addEdge(t){this.edges.push(t);let n=t.getSource(),r=t.getTarget();this.edgeInformation.set(t,{startY:e.anchorY(n),endY:e.anchorY(r),normalSourceNode:Hr(n.getNode()),normalTargetNode:Hr(r.getNode()),invertedLeft:n.getSide()===`WEST`,invertedRight:r.getSide()===`EAST`})}isHyperEdge(){return this.edges.length>1}static anchorY(e){return e.getAbsoluteAnchor().y}static fromSingleEdge(t,n,r,i){let a=new e,o=t.getSource(),s=t.getTarget();n===`LEFT`?a.leftPorts.push(o):a.rightPorts.push(o),r===`LEFT`?a.leftPorts.push(s):a.rightPorts.push(s),a.addEdge(t);let c=e.anchorY(o),l=e.anchorY(s);return a.setRelevantPositions(c,l,l),a.isStraight=i(c,l),a}static fromHyperEdge(t,n,r){let i=new e;r===`LEFT`?i.leftPorts.push(t):i.rightPorts.push(t);let a=1/0,o=-1/0;for(let{side:r,edge:s}of n){let n=s.getSource(),c=s.getTarget(),l=n;l===t&&(l=c),r===`LEFT`?i.leftPorts.push(l):i.rightPorts.push(l);let u=e.anchorY(l);a=Math.min(a,u),o=Math.max(o,u)}let s=e.anchorY(t);i.setRelevantPositions(s,a,o);for(let{edge:e}of n)i.addEdge(e);return i.isStraight=!1,i}setRelevantPositions(e,t,n){this.boundingBox.y=Math.min(e,t),this.boundingBox.height=Math.max(e,n)-this.boundingBox.y,e<t?(this.centerControlPointY=Br*(e+t),this.hyperEdgeTopYPos=zr*this.centerControlPointY+Rr*e,this.hyperEdgeBottomYPos=zr*this.centerControlPointY+Rr*t):(this.centerControlPointY=Br*(e+n),this.hyperEdgeTopYPos=zr*this.centerControlPointY+Rr*n,this.hyperEdgeBottomYPos=zr*this.centerControlPointY+Rr*e)}};function Hr(e){let t=e.getType();return t===`NORMAL`||t===`BIG_NODE`||t===`BREAKING_POINT`}const Ur=Math.PI/2,Wr=1e-5;function Gr(e){switch(e){case`NORTH`:return 3*Ur;case`EAST`:return 0;case`SOUTH`:return Ur;case`WEST`:return Math.PI;default:return 0}}function Kr(e,t,n){return Math.abs(e-t)<=n}function qr(e,t,n){return e<t-n?-1:+(e>t+n)}function Jr(e,t){let n=e.x,r=e.x+e.width,i=e.y,a=e.y+e.height;return t.x>n&&t.x<r&&t.y>i&&t.y<a}function Yr(e,t,n){return Jr(e,t)&&Jr(e,n)}function Xr(e,t,n,r){let i=e,a={x:t.x-e.x,y:t.y-e.y},o=n,s={x:r.x-n.x,y:r.y-n.y},c=i.x,l=i.y,u=o.x,d=o.y,f=a.x,p=a.y,m=s.x,h=s.y,g=m*p-f*h;if(Kr(0,g,Wr))return!1;let _=1/g*((c-u)*p-(l-d)*f),v=1/g*-(-(c-u)*h+(l-d)*m);return qr(0,_,Wr)<0&&qr(_,1,Wr)<0&&qr(0,v,Wr)<0&&qr(v,1,Wr)<0}function Zr(e,t,n){if(Yr(e,t,n))return!1;let r={x:e.x,y:e.y},i={x:e.x+e.width,y:e.y},a={x:e.x+e.width,y:e.y+e.height},o={x:e.x,y:e.y+e.height};return Xr(r,i,t,n)||Xr(i,a,t,n)||Xr(a,o,t,n)||Xr(o,r,t,n)}function Qr(e,t){let n=t.length-1,r=0,i=0;for(let a=0;a<=n;a++){let o=t[a],s=$r(n,a)*(1-e)**(n-a)*e**+a;r+=o.x*s,i+=o.y*s}return{x:r,y:i}}function $r(e,t){if(t<0||t>e)return 0;let n=1;for(let r=1;r<=t;r++)n=n*(e-t+r)/r;return n}function ei(e,t){if(e<=0)return[];let n=[],r=1/e,i=0;for(let a=0;a<e;a++)i+=r,n.push(Qr(i,t));return n}const ti=1e-6;var ni=class e{cp;polarCoordinate;constructor(t,n,r){if(t instanceof e&&n instanceof e&&r!==void 0){let e=t.polarCoordinate[0],i=n.polarCoordinate[n.polarCoordinate.length-1],a={x:t.cp.x*(i-r),y:t.cp.y*(i-r)},o={x:n.cp.x*(r-e),y:n.cp.y*(r-e)},s={x:a.x+o.x,y:a.y+o.y},c=1/(i-e);this.cp={x:s.x*c,y:s.y*c},this.polarCoordinate=[];let l=!0;for(let e=1;e<t.polarCoordinate.length;e++){let n=t.polarCoordinate[e];l&&n-r>ti&&(this.polarCoordinate.push(r),l=!1),this.polarCoordinate.push(n)}l&&this.polarCoordinate.push(r)}else this.cp={x:t.x,y:t.y},this.polarCoordinate=[...n]}getCp(){return this.cp}},ri=class{knotVector=[];controlPoints=[];dimNUBS=0;isClamped=!1;isUniform=!1;isBezier=!1;minKnot=0;maxKnot=0;constructor(e,t,n){if(t<1)throw Error(`The dimension must be at least 1!`);for(;n.length<t+1;)n.unshift({...n[0]});this.dimNUBS=t,this.isClamped=e,this.isUniform=!0,this.isBezier=!1,this.createUniformKnotVector(e,n.length+this.dimNUBS-1);let r=[],i=0;for(let e=0;e<this.dimNUBS-1;e++)r.push(this.knotVector[i++]);for(let e of n)r.push(this.knotVector[i++]),this.controlPoints.push(new ni(e,r)),r.shift()}createUniformKnotVector(e,t){if(t<2*this.dimNUBS)throw Error(`The knot vector must have at least two time the dimension elements.`);let n;if(e){this.minKnot=0,this.maxKnot=1;for(let e=0;e<this.dimNUBS;e++)this.knotVector.push(0);n=t+1-2*this.dimNUBS}else{n=t+1;let e=this.dimNUBS;this.minKnot=e/(n+1),this.maxKnot=(n-e)/n}let r=n;for(let e=1;e<n;e++)this.knotVector.push(e/r);if(e)for(let e=0;e<this.dimNUBS;e++)this.knotVector.push(1)}getMultiplicity(e){let t=0;for(let n of this.knotVector)Math.abs(n-e)<ti&&t++;return t}insertKnotAtCurrentPosition(e,t,n,r){let i=this.getMultiplicity(t);for(let a=0;a<e;a++){r.add(t);let o=[],s=n.next();for(let e=i+a;e<this.dimNUBS;e++){let e=s;s=n.next(),o.push(new ni(e,s,t))}for(let e=i+a;e<this.dimNUBS;e++)n.previous(),e>i+a&&n.remove();for(let e of o)n.add(e);if(a<e-1)for(let e=i+a;e<this.dimNUBS;e++)n.previous()}}toBezier(){let e=new ii(this.knotVector),t=new ii(this.controlPoints);if(this.isClamped)for(let t=0;t<this.dimNUBS;t++)e.next();else for(let t=0;t<this.dimNUBS-1;t++)e.next(),e.remove();let n=e.next();for(;this.maxKnot-n>ti;){let r=n,i=0;for(;Math.abs(n-r)<ti;)i++,n=e.next(),t.next();i<this.dimNUBS&&(e.previous(),this.insertKnotAtCurrentPosition(this.dimNUBS-i,r,t,e),e.next()),t.previous()}if(!this.isClamped)for(let t=0;t<this.dimNUBS-1;t++)e.next(),e.remove();this.isClamped=!0,this.isBezier=!0}getControlPoints(){return this.controlPoints.map(e=>({x:e.getCp().x,y:e.getCp().y}))}getBezierCP(){this.isBezier||this.toBezier();let e=[];for(let t=1;t<this.controlPoints.length-1;t++)e.push({x:this.controlPoints[t].getCp().x,y:this.controlPoints[t].getCp().y});return e}},ii=class{items;cursor=0;lastRet=-1;constructor(e){this.items=e}next(){let e=this.items[this.cursor];return this.lastRet=this.cursor,this.cursor++,e}previous(){return this.cursor--,this.lastRet=this.cursor,this.items[this.cursor]}remove(){if(this.lastRet===-1)throw Error(`no last returned`);this.lastRet<this.cursor?(this.items.splice(this.lastRet,1),this.cursor--):this.items.splice(this.lastRet,1),this.lastRet=-1}add(e){this.items.splice(this.cursor,0,e),this.cursor++,this.lastRet=-1}};const ai=1.3,F=.5;function oi(e,t){return{x:e.x+t.x,y:e.y+t.y}}function si(e,t){return{x:e.x-t.x,y:e.y-t.y}}function ci(e,t){return{x:e.x*t,y:e.y*t}}function li(e){return Math.hypot(e.x,e.y)}function ui(e){return{x:Math.cos(e),y:Math.sin(e)}}function I(e){let t=e.getPosition(),n=e.getAnchor();return{x:t.x+n.x,y:t.y+n.y}}var di=class e extends ri{firstLabelPosition={x:0,y:0};constructor(e,t,n){typeof e==`boolean`?super(e,t,n):super(!0,e,t)}getFirstLabelPosition(){return this.firstLabelPosition}setFirstLabelPosition(e){this.firstLabelPosition=e}static createSideSelfLoop(t,n,r){let i=Gr(t.getSide()),a=I(t),o=I(n),s=oi(a,ci(ui(i),r)),c=oi(o,ci(ui(i),r)),l=ci(si(s,c),1/2),u=oi(oi(c,l),ci(ui(i),li(l)));return new e(3,[a,s,u,c,o])}static createCornerSelfLoop(t,n,r,i){let a=Gr(t.getSide()),o=Gr(n.getSide()),s=I(t),c=I(n),l=oi(s,ci(ui(a),ai*r)),u=oi(c,ci(ui(o),ai*i)),d=0,f=0;switch(t.getSide()){case`WEST`:d=2*(s.x-r)-F*(l.x+u.x);break;case`EAST`:d=2*(s.x+r)-F*(l.x+u.x);break;case`NORTH`:f=2*(s.y-r)-F*(l.y+u.y);break;case`SOUTH`:f=2*(s.y+r)-F*(l.y+u.y)}switch(n.getSide()){case`WEST`:d=2*(c.x-i)-F*(u.x+l.x);break;case`EAST`:d=2*(c.x+i)-F*(u.x+l.x);break;case`NORTH`:f=2*(c.y-i)-F*(u.y+l.y);break;case`SOUTH`:f=2*(c.y+i)-F*(u.y+l.y)}return new e(3,[s,l,{x:d,y:f},u,c])}static createAcrossSelfLoop(t,n,r,i,a){let o=I(t),s=I(n);if(i.length!==2)throw Error(`AssertionError: cornerBendPoints.size() == 2`);let c=i[0],l=i[1],u=ci(oi(l,c),F);return new e(3,[o,r,c,u,l,a,s])}static createThreeSideSelfLoop(t,n,r,i,a){let o=I(t),s=I(n);if(i.length!==3)throw Error(`AssertionError: cornerBendPoints.size() == 3`);let c=i[0],l=i[1],u=i[2];return new e(3,[o,r,c,l,u,a,s])}static createFourSideSelfLoop(t,n,r,i,a){let o=I(t),s=I(n);if(i.length!==4)throw Error(`AssertionError: cornerBendPoints.size() == 4`);let c=i[0],l=i[1],u=i[2],d=i[3];return new e(3,[o,r,c,l,u,d,a,s])}};const fi=1e-8;function pi(e,t,n){return Math.abs(t-e)<fi||Math.abs(n-e)<fi?!0:t-e>fi?e-n>fi:n-e>fi}function mi(e,t){return e!==t&&(e===`WEST`||e===`EAST`)!=(t===`WEST`||t===`EAST`)}function hi(t){return t.getType()===`EXTERNAL_PORT`&&(t.getProperty(e.Un)===`WEST`||t.getProperty(e.Un)===`EAST`)}var gi=class{edgesRemainingLayer=[];splineSegmentsLayer=[];leftPortsLayer=[];rightPortsLayer=[];selfLoopsLayer=/* @__PURE__ */ new Set;startEdges=[];allSplineSegments=[];edgeToSegmentMap=/* @__PURE__ */ new Map;successingEdge=/* @__PURE__ */ new Map;process(t){if(t.getLayers().length===0){t.getSize().x=0;return}let n=t.getProperty(e.un),r=t.getProperty(e.rn),i=t.getProperty(e.en),a=t.getProperty(e.H)===`SLOPPY`,o=t.getProperty(e.U);this.startEdges=[],this.allSplineSegments=[],this.successingEdge=/* @__PURE__ */ new Map;let s=t.getLayers(),c=s[0],l=s[s.length-1],u=c.getNodes().length>0&&c.getNodes().every(e=>hi(e)),d=l.getNodes().length>0&&l.getNodes().every(e=>hi(e)),f=0,p=null;for(let e=0;e<=s.length;e++){let m=e<s.length?s[e]:null;this.clearThenFillMappings(p,m),this.createSegmentsAndComputeRanking(t);let h=0;for(let e of this.splineSegmentsLayer)e.isStraight||(h=Math.max(h,e.rank+1));let g=0,_=f,v=p===null||u&&p===c,y=m===null||d&&m===l;if(h>0){let e=0;p!==null&&(e+=r),e+=(h-1)*i,m!==null&&(e+=r),a&&m!==null&&(e=Math.max(e,this.computeSloppySpacing(m,i,n,o))),e<n&&!v&&!y&&(g=(n-e)/2,e=n),_+=e}else!v&&!y&&(_+=n);m!==null&&Sn(m,_),this.routeSelfLoops(r);for(let e of this.splineSegmentsLayer)e.boundingBox.x=f,e.boundingBox.width=_-f,e.xDelta=g,e.isWestOfInitialLayer=p===null;this.allSplineSegments.push(...this.splineSegmentsLayer),f=_,m!==null&&(f+=m.getSize().x),p=m}t.getSize().x=f;for(let t of this.startEdges){let n=this.getEdgeChain(t);n.length>0&&t.setProperty(e.Tr,n);let r=this.getSplinePath(t);r.length>0&&t.setProperty(e.Dr,r)}}getEdgeChain(e){let t=[],n=e;for(;n!==null;)t.push(n),n=this.successingEdge.get(n)??null;return t}getSplinePath(e){let t=[],n=e;for(;n!==null;){let e=this.edgeToSegmentMap.get(n);if(!e)break;e.sourcePort=n.getSource(),e.targetPort=n.getTarget(),t.push(e),n=this.successingEdge.get(n)??null}if(t.length>0){let e=t[0];e.initialSegment=!0,e.sourceNode=e.edges[0].getSource().getNode();let n=t[t.length-1];n.lastSegment=!0,n.targetNode=n.edges[0].getTarget().getNode()}return t}clearThenFillMappings(e,t){if(this.leftPortsLayer=[],this.rightPortsLayer=[],this.edgesRemainingLayer=[],this.splineSegmentsLayer=[],this.selfLoopsLayer=/* @__PURE__ */ new Set,e!==null)for(let n of e.getNodes())for(let r of n.getPorts(`EAST`)){this.leftPortsLayer.push(r);for(let n of r.getOutgoingEdges()){if(n.isSelfLoop())continue;this.edgesRemainingLayer.push(n),this.findAndAddSuccessor(n),yi(n.getSource().getNode())&&this.startEdges.push(n);let r=n.getTarget(),i=r.getNode().getLayer();if(i===t)this.rightPortsLayer.push(r);else if(i===e)this.leftPortsLayer.push(r);else{let e=this.edgesRemainingLayer.indexOf(n);e!==-1&&this.edgesRemainingLayer.splice(e,1)}}}if(t!==null)for(let n of t.getNodes()){for(let e of n.getPorts())for(let t of e.getOutgoingEdges())t.isSelfLoop()&&this.selfLoopsLayer.add(t);for(let r of n.getPorts(`WEST`)){this.rightPortsLayer.push(r);for(let n of r.getOutgoingEdges()){if(n.isSelfLoop())continue;this.edgesRemainingLayer.push(n),this.findAndAddSuccessor(n),yi(n.getSource().getNode())&&this.startEdges.push(n);let r=n.getTarget(),i=r.getNode().getLayer();if(i===t)this.rightPortsLayer.push(r);else if(i===e)this.leftPortsLayer.push(r);else{let e=this.edgesRemainingLayer.indexOf(n);e!==-1&&this.edgesRemainingLayer.splice(e,1)}}}}}routeSelfLoops(e){if(this.selfLoopsLayer.size===0)return;let t=e>0?e:20;for(let e of this.selfLoopsLayer){let n=e.getSource(),r=e.getTarget();if(n===null||r===null||e.getBendPoints().length>0)continue;let i=n.getSide(),a=r.getSide();if(i===`UNDEFINED`||a===`UNDEFINED`)continue;let o=null;if(i===a?o=di.createSideSelfLoop(n,r,t):mi(i,a)&&(o=di.createCornerSelfLoop(n,r,t,t)),o===null)continue;let s=n.getNode(),c=s===null?{x:0,y:0}:s.getPosition();for(let t of o.getBezierCP())e.getBendPoints().push({x:t.x+c.x,y:t.y+c.y})}}createSegmentsAndComputeRanking(t){this.createSplineSegmentsForHyperEdges(`LEFT`,!0),this.createSplineSegmentsForHyperEdges(`LEFT`,!1),this.createSplineSegmentsForHyperEdges(`RIGHT`,!0),this.createSplineSegmentsForHyperEdges(`RIGHT`,!1),this.createSplineSegments();for(let e=0;e<this.splineSegmentsLayer.length;e++){let t=this.splineSegmentsLayer[e];for(let n=e+1;n<this.splineSegmentsLayer.length;n++)this.createDependency(t,this.splineSegmentsLayer[n])}this.breakCycles(this.splineSegmentsLayer,t.getProperty(e.br)),this.topologicalNumbering(this.splineSegmentsLayer)}createSplineSegments(){for(let e of this.edgesRemainingLayer){let t=e.getSource(),n;if(this.leftPortsLayer.includes(t))n=`LEFT`;else if(this.rightPortsLayer.includes(t))n=`RIGHT`;else throw Error(`Source port must be in one of the port sets.`);let r=e.getTarget(),i;if(this.leftPortsLayer.includes(r))i=`LEFT`;else if(this.rightPortsLayer.includes(r))i=`RIGHT`;else throw Error(`Target port must be in one of the port sets.`);let a=Vr.fromSingleEdge(e,n,i,(e,t)=>_i(e,t));this.edgeToSegmentMap.set(e,a),this.splineSegmentsLayer.push(a)}}createSplineSegmentsForHyperEdges(t,n){let r=t===`LEFT`?this.leftPortsLayer:this.rightPortsLayer;for(let i of r){let r=i.getAbsoluteAnchor().y,a=[],o=[];for(let t of i.getConnectedEdges())if(t.getProperty(e.Sr)===n&&this.edgesRemainingLayer.includes(t)){let e;e=t.getTarget()===i?t.getSource():t.getTarget();let n=e.getAbsoluteAnchor().y;if(_i(n,r))continue;n<r?a.push({side:this.leftPortsLayer.includes(e)?`LEFT`:`RIGHT`,edge:t}):o.push({side:this.leftPortsLayer.includes(e)?`LEFT`:`RIGHT`,edge:t})}if(a.length>1){let e=Vr.fromHyperEdge(i,a,t);for(let{edge:t}of a)this.edgeToSegmentMap.set(t,e);this.splineSegmentsLayer.push(e);for(let{edge:e}of a){let t=this.edgesRemainingLayer.indexOf(e);t!==-1&&this.edgesRemainingLayer.splice(t,1)}}if(o.length>1){let e=Vr.fromHyperEdge(i,o,t);for(let{edge:t}of o)this.edgeToSegmentMap.set(t,e);this.splineSegmentsLayer.push(e);for(let{edge:e}of o){let t=this.edgesRemainingLayer.indexOf(e);t!==-1&&this.edgesRemainingLayer.splice(t,1)}}}}createDependency(e,t){if(e.hyperEdgeTopYPos>t.hyperEdgeBottomYPos||t.hyperEdgeTopYPos>e.hyperEdgeBottomYPos)return;let n=0,r=0;for(let r of e.rightPorts)pi(r.getAbsoluteAnchor().y,t.hyperEdgeTopYPos,t.hyperEdgeBottomYPos)&&n++;for(let r of e.leftPorts)pi(r.getAbsoluteAnchor().y,t.hyperEdgeTopYPos,t.hyperEdgeBottomYPos)&&n--;for(let n of t.rightPorts)pi(n.getAbsoluteAnchor().y,e.hyperEdgeTopYPos,e.hyperEdgeBottomYPos)&&r++;for(let n of t.leftPorts)pi(n.getAbsoluteAnchor().y,e.hyperEdgeTopYPos,e.hyperEdgeBottomYPos)&&r--;n<r?new Lr(e,t,r-n):r<n?new Lr(t,e,n-r):(new Lr(t,e,0),new Lr(e,t,0))}breakCycles(e,t){let n=[],r=[],i=-1;for(let t of e){t.mark=i--;let e=0,a=0;for(let e of t.outgoing)a+=e.weight;for(let n of t.incoming)e+=n.weight;t.inweight=e,t.outweight=a,a===0?r.push(t):e===0&&n.push(t)}let a=new Set(e),o=e.length,s=o+1,c=o-1,l=[];for(;a.size>0;){for(;r.length>0;){let e=r.shift();a.delete(e),e.mark=c--,this.updateNeighbors(e,n,r)}for(;n.length>0;){let e=n.shift();a.delete(e),e.mark=s++,this.updateNeighbors(e,n,r)}let e=-(2**53-1);for(let t of a){let n=t.outweight-t.inweight;n>=e&&(n>e&&(l.length=0,e=n),l.push(t))}if(l.length>0){let e=t===void 0?l[0]:l[t.nextInt(l.length)];a.delete(e),e.mark=s++,this.updateNeighbors(e,n,r),l.length=0}}let u=e.length+1;for(let t of e)t.mark<o&&(t.mark+=u);for(let t of e){let e=t.outgoing;for(let n=e.length-1;n>=0;n--){let r=e[n],i=r.target;if(t.mark>i.mark){e.splice(n,1);let a=i.incoming.indexOf(r);a!==-1&&i.incoming.splice(a,1),r.weight>0&&(r.source=i,i.outgoing.push(r),r.target=t,t.incoming.push(r))}}}}updateNeighbors(e,t,n){for(let n of e.outgoing)n.target.mark<0&&n.weight>0&&(n.target.inweight-=n.weight,n.target.inweight<=0&&n.target.outweight>0&&t.push(n.target));for(let t of e.incoming)t.source.mark<0&&t.weight>0&&(t.source.outweight-=t.weight,t.source.outweight<=0&&t.source.inweight>0&&n.push(t.source))}topologicalNumbering(e){let t=[],n=[];for(let r of e)r.rank=0,r.inweight=r.incoming.length,r.outweight=r.outgoing.length,r.inweight===0&&t.push(r),r.outweight===0&&r.leftPorts.length===0&&n.push(r);let r=-1;for(;t.length>0;){let e=t.shift();for(let n of e.outgoing){let i=n.target;i.rank=Math.max(i.rank,e.rank+1),r=Math.max(r,i.rank),i.inweight--,i.inweight===0&&t.push(i)}}if(r>-1){for(let e of n)e.rank=r;for(;n.length>0;){let e=n.shift();for(let t of e.incoming){let r=t.source;r.leftPorts.length>0||(r.rank=Math.min(r.rank,e.rank-1),r.outweight--,r.outweight===0&&n.push(r))}}}}computeSloppySpacing(e,t,n,r){let i=0;for(let t of e.getNodes()){let e=0;for(let n of t.getIncomingEdges()){let t=n.getSource().getAbsoluteAnchor().y,r=n.getTarget().getAbsoluteAnchor().y;e=Math.max(e,Math.abs(r-t))}i=Math.max(i,e)}return r*Math.min(1,t/n)*i}findAndAddSuccessor(e){let t=e.getTarget().getNode();if(vi(t))return;let n=t.getOutgoingEdges();n.length>0&&this.successingEdge.set(e,n[0])}};function _i(e,t){return Math.abs(e-t)<.2}function vi(e){let t=e.getType();return t===`NORMAL`||t===`BREAKING_POINT`}function yi(e){let t=e.getType();return t===`NORMAL`||t===`NORTH_SOUTH_PORT`||t===`EXTERNAL_PORT`||t===`BREAKING_POINT`}function bi(t){let n=t.getProperty(e.en),r=t.getProperty(e.rn),i=t.getProperty(e.H),a=t.getProperty(e.v);for(let e of t.getLayers()){let t=0;for(let n of e.getNodes())n.id=t++}let o=[];for(let n of t.getLayers())for(let t of n.getNodes())for(let n of t.getPorts())for(let t of n.getOutgoingEdges())t.isSelfLoop()||t.hasProperty(e.Dr)&&o.push(t);for(let t of o){let o=t.getProperty(e.Dr);if(o!=null){for(let e of o)xi(e,n,r,i,a);t.setProperty(e.Dr,null)}}for(let t of o)Oi(t.getProperty(e.Tr)??[],t,i),t.setProperty(e.Tr,null)}function xi(e,t,n,r,i){if(!e.handled){e.handled=!0;for(let a of e.edges){if(e.isStraight&&!e.isHyperEdge()){Si(e);continue}let o=e.edgeInformation.get(a);o.invertedLeft||o.invertedRight?Ci(a,e,n,t):r===`SLOPPY`&&(o.normalSourceNode||o.normalTargetNode)&&ji(e,i)&&!e.isHyperEdge()?Ti(a,e):wi(a,e,n,t)}if(e.inverseOrder)for(let t of e.edges)t.getBendPoints().reverse()}}function Si(e){let t=e.boundingBox.x,n={x:t+(e.boundingBox.x+e.boundingBox.width-t)/2,y:e.centerControlPointY};e.edges[0].getBendPoints().push(n)}function Ci(e,t,n,r){let i=t.boundingBox.x,a=t.boundingBox.x+t.boundingBox.width,o=t.edgeInformation.get(e),s=o.startY,c=o.endY,l=o.invertedLeft?{x:a,y:s}:{x:i,y:s},u=o.invertedRight?{x:i,y:c}:{x:a,y:c},d=i;t.isWestOfInitialLayer||(d+=n),d+=t.xDelta+t.rank*r;let f={x:d,y:s},p={x:d,y:c};e.getBendPoints().push(l,f),t.edges.length>1&&e.getBendPoints().push({x:d,y:t.centerControlPointY}),e.getBendPoints().push(p,u)}function wi(e,t,n,r){let i=t.boundingBox.x,a=t.boundingBox.x+t.boundingBox.width,o=t.edgeInformation.get(e),s=o.startY,c=o.endY,l={x:i,y:s},u={x:a,y:c},d=i;t.isWestOfInitialLayer||(d+=n),d+=t.xDelta+t.rank*r;let f={x:d,y:s},p={x:d,y:c};e.getBendPoints().push(l,f),t.edges.length>1&&e.getBendPoints().push({x:d,y:t.centerControlPointY}),e.getBendPoints().push(p,u)}function Ti(e,t){let n=t.edgeInformation.get(e),r=t.boundingBox.x,i=t.boundingBox.x+t.boundingBox.width,a=n.startY,o=n.endY,s=a<o,c={x:r,y:a},l={x:i,y:o},u=(r+i)/2,d={x:u,y:a},f={x:u,y:o},p=Di(e,a,o),m=t.sourcePort.getAbsoluteAnchor(),h={x:u,y:p},g=t.targetPort.getAbsoluteAnchor(),_=ei(2,[m,h,g]),v=!1,y=t.sourcePort.getNode();if(y!==null&&y.getLayer()!==null&&n.normalSourceNode){let e=y.getLayer();if(!(s&&y.id<e.getNodes().length-1||!s&&y.id>0))v=!0;else{let t=s?y.id+1:y.id-1,n=e.getNodes()[t],r=Ei(n);v=!(Zr(r,m,_[0])||Yr(r,m,_[0]))}}let b=!1,x=t.targetPort.getNode();if(x!==null&&x.getLayer()!==null&&n.normalTargetNode){let e=x.getLayer();if(!(s&&x.id>0||!s&&x.id<e.getNodes().length-1))b=!0;else{let t=s?x.id-1:x.id+1,n=e.getNodes()[t],r=Ei(n);b=!(Zr(r,_[0],g)||Yr(r,_[0],g))}}v&&b&&e.getBendPoints().push(h),v||e.getBendPoints().push(c,d),b||e.getBendPoints().push(f,l)}function Ei(e){let t=e.getPosition(),n=e.getSize(),r=e.getMargin();return{x:t.x-r.left,y:t.y-r.top,width:n.x+r.left+r.right,height:n.y+r.top+r.bottom}}function Di(e,t,n){let r=0,i=0;if(e.getTarget()!==null)for(let t of e.getTarget().getNode().getPorts())r+=t.getIncomingEdges().length;else r=1;if(e.getSource()!==null)for(let t of e.getSource().getNode().getPorts())i+=t.getOutgoingEdges().length;else i=1;let a=Math.sign(i-r);return(n+t)/2+(n-t)*(.4*a)}function Oi(t,n,r){if(t.length===0)return;let i=n===null?t[0]:n,a=i.getSource();if(!yi(a.getNode()))throw Error(`The target node of the edge must be a normal node or a northSouthPort.`);let o=[a.getAbsoluteAnchor()];if(Ni(a.getSide())){let t=a.getProperty(e.Er);o.push({x:a.getAbsoluteAnchor().x,y:t??a.getAbsoluteAnchor().y})}let s=null,c=!1;for(let e of t){let t=e.getBendPoints();if(t.length>0){if(c){let e={x:(s.x+t[0].x)/2,y:(s.y+t[0].y)/2};o.push(e),c=!1}else c=!0;s={...t[t.length-1]},o.push(...t.map(e=>({x:e.x,y:e.y}))),t.length=0}}let l=i.getTarget();if(Ni(l.getSide())){let t=l.getProperty(e.Er);o.push({x:l.getAbsoluteAnchor().x,y:t??l.getAbsoluteAnchor().y})}o.push(l.getAbsoluteAnchor()),r===`CONSERVATIVE`&&ki(o,a,l);let u=new ri(!0,3,o).getBezierCP();i.getBendPoints().push(...u)}function ki(e,t,n){let r=e[0],i=e[1],a=Gr(t.getSide()),o={x:Math.cos(a)*5,y:Math.sin(a)*5},s={x:i.x-r.x,y:i.y-r.y},c={x:Ai(o.x,s.x),y:Ai(o.y,s.y)};c.x+=r.x,c.y+=r.y,e.splice(1,0,c);let l=e[e.length-1],u=e[e.length-2],d=Gr(n.getSide()),f={x:Math.cos(d)*5,y:Math.sin(d)*5},p={x:u.x-l.x,y:u.y-l.y},m={x:Ai(f.x,p.x),y:Ai(f.y,p.y)};m.x+=l.x,m.y+=l.y,e.splice(e.length-1,0,m)}function Ai(e,t){return Math.abs(e)<Math.abs(t)?e:t}function ji(e,t){if(t===`NONE`)return!0;let n=e.boundingBox.x,r=e.boundingBox.x+e.boundingBox.width;if(e.initialSegment&&e.sourceNode!==null){let t=e.sourceNode,r=Mi(t);if(n-(t.getPosition().x+t.getSize().x)>r)return!1}if(e.lastSegment&&e.targetNode!==null){let t=e.targetNode,n=Mi(t);if(t.getPosition().x-r>n)return!1}return!0}function Mi(e){return e.getLayer().getSize().x-e.getSize().x/2}function Ni(e){return e===`NORTH`||e===`SOUTH`}function Pi(e,t=!1){let n;switch(e){case`RIGHT`:n=`EAST`;break;case`LEFT`:n=`WEST`;break;case`DOWN`:n=`SOUTH`;break;case`UP`:n=`NORTH`;break;default:n=`EAST`}return t?Fi(n):n}function Fi(e){switch(e){case`NORTH`:return`SOUTH`;case`SOUTH`:return`NORTH`;case`EAST`:return`WEST`;case`WEST`:return`EAST`;default:return`UNDEFINED`}}function Ii(t){let n=t.getProperty(e.F);return n===`UNDEFINED`?t.getProperty(e.h)>=1?`RIGHT`:`DOWN`:n}function Li(e,t){let n=e.getGraph()?.getParentNode()??null;for(;n!==null;){if(n===t)return!0;n=n.getGraph()?.getParentNode()??null}return!1}function Ri(e,t){let n=e.getPosition().x+e.getAnchor().x,r=e.getPosition().y+e.getAnchor().y,i=e.getNode();for(;i!==null&&i!==t;)n+=i.position.x,r+=i.position.y,i=i.getGraph()?.getParentNode()??null;return{x:n,y:r}}function zi(e,t){let n=/* @__PURE__ */ new Set,r=e;for(;r!==null;)n.add(r),r=r.getGraph()?.getParentNode()??null;for(r=t;r!==null;){if(n.has(r))return r;r=r.getGraph()?.getParentNode()??null}return null}function Bi(t){let n=t.getSource(),r=t.getTarget(),i=n.getNode(),a=r.getNode(),o,s;if(i===a&&t.getProperty(e.$)){let t=i,a=t.getGraph(),c=!1;for(;a!==null;){if(a.getProperty(e.q)===`INCLUDE_CHILDREN`){c=!0;break}a=a.getParentNode()?.getGraph()??null}if(c)o=n.getAbsoluteAnchor(),s=r.getAbsoluteAnchor();else{let e=(e,n)=>{switch(e){case`WEST`:return{x:t.position.x+n.getPosition().x+n.getSize().x,y:t.position.y+n.getPosition().y+n.getSize().y/2};case`EAST`:return{x:t.position.x+n.getPosition().x,y:t.position.y+n.getPosition().y+n.getSize().y/2};case`NORTH`:return{x:t.position.x+n.getPosition().x+n.getSize().x/2,y:t.position.y+n.getPosition().y+n.getSize().y};case`SOUTH`:return{x:t.position.x+n.getPosition().x+n.getSize().x/2,y:t.position.y+n.getPosition().y};default:return n.getAbsoluteAnchor()}};o=e(n.getSide(),n),s=e(r.getSide(),r)}}else if(Li(a,i)){o={x:n.getPosition().x+n.getAnchor().x,y:n.getPosition().y+n.getAnchor().y};let i=r.getAbsoluteAnchor(),a=t.getProperty(e.Ar);s=a?{x:i.x+a.x,y:i.y+a.y}:i}else if(Li(i,a))o=Ri(n,a),s=Ri(r,a);else if(i===a){o=n.getAbsoluteAnchor();let i=r.getAbsoluteAnchor(),a=t.getProperty(e.Ar);s=a?{x:i.x+a.x,y:i.y+a.y}:i}else{let e=zi(i,a);o=Ri(n,e),s=Ri(r,e)}return{source:o,target:s}}function Vi(e,t,n){if(t===n)return e;let r=t,i=null;do{let t=r.getOffset();if(e.x+=t.x,e.y+=t.y,i=r.getParentNode(),i!==null){let t=r.getPadding();e.x+=t.left,e.y+=t.top,e.x+=i.getPosition().x,e.y+=i.getPosition().y,r=i.getGraph()}}while(i!==null);r=n;do{let t=r.getOffset();if(e.x-=t.x,e.y-=t.y,i=r.getParentNode(),i!==null){let t=r.getPadding();e.x-=t.left,e.y-=t.top,e.x-=i.getPosition().x,e.y-=i.getPosition().y,r=i.getGraph()}}while(i!==null);return e}function Hi(e,t){return Vi({x:0,y:0},e,t)}function Ui(t,n,r,i,a,o,s,c,l){let u=r,d=new f(l);d.setType(`EXTERNAL_PORT`),d.setProperty(e.Un,u),d.setProperty(e.Wn,s),d.setProperty(e.Lt,`FIXED_POS`);let m=t.getProperty(e.It);d.setProperty(e.It,m);let h=new p;if(h.setNode(d),e.Lr.isSideFixed(n)||(u=i>=0?Pi(c):Fi(Pi(c)),t.setProperty(e.Bt,u),t instanceof p&&t.setSide(u)),e.Lr.isRatioFixed(n)||e.Lr.isPosFixed(n)){let t=0;switch(u){case`WEST`:case`EAST`:t=o?.y??0,e.Lr.isRatioFixed(n)&&(t/=a?.y??1);break;case`NORTH`:case`SOUTH`:t=o?.x??0,e.Lr.isRatioFixed(n)&&(t/=a?.x??1)}d.setProperty(e.yr,t)}let g={x:s.x/2,y:s.y/2},_=!1;if(t.getProperty(e.Ft)!==void 0){let n=t.getProperty(e.Ft);n!=null&&(g.x=n.x,g.y=n.y,_=!0)}switch(u){case`WEST`:d.setLayerConstraint(`FIRST_SEPARATE`),d.setEdgeConstraint(`OUTGOING_ONLY`),d.size.y=s.y,m<0&&(d.size.x=-m),h.setSide(`EAST`),_||(g.x=s.x),g.x-=s.x;break;case`EAST`:d.setLayerConstraint(`LAST_SEPARATE`),d.setEdgeConstraint(`INCOMING_ONLY`),d.size.y=s.y,m<0&&(d.size.x=-m),h.setSide(`WEST`),_||(g.x=0);break;case`NORTH`:d.setInLayerConstraint(`TOP`),d.size.x=s.x,m<0&&(d.size.y=-m),h.setSide(`SOUTH`),_||(g.y=s.y),g.y-=s.y;break;case`SOUTH`:d.setInLayerConstraint(`BOTTOM`),d.size.x=s.x,m<0&&(d.size.y=-m),h.setSide(`NORTH`),_||(g.y=0)}return h.getPosition().x=g.x,h.getPosition().y=g.y,d.setProperty(e.Ft,{x:g.x,y:g.y}),o!=null&&(d.getPosition().x=o.x,d.getPosition().y=o.y),d.setProperty(e.Un,u),d}function Wi(e,t){let n=e.getNode(),r=n.size.x,i=n.size.y;if(r<=0&&i<=0)return`UNDEFINED`;let a=e.getPosition().x,o=e.getPosition().y,s=e.size.x,c=e.size.y;switch(t){case`LEFT`:case`RIGHT`:if(a<0)return`WEST`;if(a+s>r)return`EAST`;break;case`UP`:case`DOWN`:if(o<0)return`NORTH`;if(o+c>i)return`SOUTH`}let l=(a+s/2)/r,u=(o+c/2)/i;return l+u<=1&&l-u<=0?`WEST`:l+u>=1&&l-u>=0?`EAST`:u<.5?`NORTH`:`SOUTH`}function Gi(e,t){let n=e.getNode(),r=e.getPosition();switch(t){case`NORTH`:return-(r.y+e.size.y);case`EAST`:return r.x-(n?.size.x??0);case`SOUTH`:return r.y-(n?.size.y??0);case`WEST`:return-(r.x+e.size.x)}return 0}function Ki(t,n,r){let i=t.getSide(),a=e.Lr.isSideFixed(n);i===`UNDEFINED`&&a&&(i=Wi(t,r),t.setSideInferred(i),!t.hasProperty(e.It)&&i!==`UNDEFINED`&&(t.getPosition().x!==0||t.getPosition().y!==0)&&t.setProperty(e.It,Gi(t,i)));let o=t.size,s=t.getAnchor();if(i!==`UNDEFINED`)switch(i){case`NORTH`:s.x=o.x/2;break;case`EAST`:s.x=o.x,s.y=o.y/2;break;case`SOUTH`:s.x=o.x/2,s.y=o.y;break;case`WEST`:s.y=o.y/2}else s.x=o.x/2,s.y=o.y/2}function qi(t){let n=t.getProperty(e.G);for(let e of t.getLayerlessNodes())Ji(e,n);for(let e of t.getLayers())for(let t of e.getNodes())Ji(t,n)}function Ji(t,n){if(e.Lr.isSideFixed(t.getProperty(e.Lt)))for(let e of t.getPorts())e.getSide()===`UNDEFINED`&&Yi(e,n);else{for(let e of t.getPorts())Yi(e,n);t.setProperty(e.Lt,`FIXED_SIDE`)}}function Yi(t,n=!1,r=`RIGHT`){let i=t.getProperty(e._r);if(i!=null){t.setSideInferred(i.getProperty(e.Un));return}let a=0;if(n){for(let n of t.getIncomingEdges())a+=n.getProperty(e.Sr)?-1:1;for(let n of t.getOutgoingEdges())a-=n.getProperty(e.Sr)?-1:1}else a=t.getNetFlow();let o=Pi(r),s=a<0?o:Fi(o);t.setSideInferred(s)}const Xi={top:0,left:0,right:0,bottom:0};function Zi(t,n){let r=t.placement??n.getProperty(e._t);return Array.isArray(r)?r:String(r??``).split(/[\s,]+/).filter(Boolean)}function Qi(e){let t=e.includes(`H_LEFT`)||e.includes(`H_RIGHT`);return e.includes(`H_PRIORITY`)&&t||!e.includes(`H_PRIORITY`)&&e.includes(`V_CENTER`)&&t}function $i(e,t,n,r){let i=n.includes(`H_RIGHT`)?`right`:n.includes(`H_LEFT`)?`left`:`center`,a=n.includes(`V_BOTTOM`)?`bottom`:n.includes(`V_CENTER`)?`center`:`top`;Qi(n)?(e.position.x=i===`right`?t.x+r:-e.size.x-r,e.position.y=a===`bottom`?t.y-e.size.y:a===`center`?(t.y-e.size.y)/2:0):(e.position.y=a===`bottom`?t.y+r:-e.size.y-r,e.position.x=i===`right`?t.x-e.size.x:i===`center`?(t.x-e.size.x)/2:0)}function ea(e,t,n){if(Qi(t)){let r={...Xi};return t.includes(`H_LEFT`)&&(r.left=n+e.x),t.includes(`H_RIGHT`)&&(r.right=n+e.x),r}let r={...Xi};return t.includes(`V_TOP`)&&(r.top=n+e.y),t.includes(`V_BOTTOM`)&&(r.bottom=n+e.y),r}function ta(t){return t.hasProperty(e.on)?t.getProperty(e.on):t.getGraph()?.getProperty(e.on)??5}function na(e){let t=e.getLayers();for(let e of t)for(let t of e.getNodes())ra(t)}function ra(e){let t=e.getSize(),n=0,r=0,i=t.x,a=t.y;for(let t of e.getPorts()){let e=t.getPosition(),o=t.getSize();n=Math.min(n,e.x),r=Math.min(r,e.y),i=Math.max(i,e.x+o.x),a=Math.max(a,e.y+o.y);for(let o of t.getLabels()){let t=o.position,s=o.size;n=Math.min(n,e.x+t.x),r=Math.min(r,e.y+t.y),i=Math.max(i,e.x+t.x+s.x),a=Math.max(a,e.y+t.y+s.y)}}for(let o of e.getLabels()){let s=o.position,c=o.size;n=Math.min(n,s.x),r=Math.min(r,s.y),i=Math.max(i,s.x+c.x),a=Math.max(a,s.y+c.y);let l=Zi(o,e);if(l.includes(`OUTSIDE`)){let o=ea(c,l,ta(e));n=Math.min(n,-o.left),r=Math.min(r,-o.top),i=Math.max(i,t.x+o.right),a=Math.max(a,t.y+o.bottom)}}let o=e.getMargin();o.left=-n,o.top=-r,o.right=i-t.x,o.bottom=a-t.y}var ia=class{newEdge;graph;type;constructor(e,t,n){this.newEdge=e,this.graph=t,this.type=n}getNewEdge(){return this.newEdge}getGraph(){return this.graph}getType(){return this.type}getActualSource(){let t=this.newEdge.getSource();return t!==null&&t.getNode().getType().toString()===`EXTERNAL_PORT`?t.getNode().getProperty(e.lr):t}getActualTarget(){let t=this.newEdge.getTarget();return t!==null&&t.getNode().getType().toString()===`EXTERNAL_PORT`?t.getNode().getProperty(e.lr):t}};function aa(e,t){let n=0,r=e;for(;r!==t;){let e=r.getParentNode();if(e===null)break;let t=e.getGraph();if(t===null)break;r=t,n++}return n}function oa(e,t,n){let r=e.getType(),i=t.getType();return r===`OUTPUT`&&i===`INPUT`?-1:r===`INPUT`&&i===`OUTPUT`?1:r===`OUTPUT`?aa(t.getGraph(),n)-aa(e.getGraph(),n):aa(e.getGraph(),n)-aa(t.getGraph(),n)}var sa=class{origEdges=[];newEdge;dummyNode;dummyPort;type;exported;constructor(e,t,n,r,i,a){this.origEdges.push(e),this.newEdge=t,this.dummyNode=n,this.dummyPort=r,this.type=i,this.exported=a}},ca=class{crossHierarchyMap=/* @__PURE__ */ new Map;dummyNodeMap=/* @__PURE__ */ new Map;topGraph=null;process(t){this.crossHierarchyMap=/* @__PURE__ */ new Map,this.topGraph=t,t.getProperty(e.q)===`INCLUDE_CHILDREN`?(this.transformHierarchyEdges(t,null),this.removeOriginalEdges(),this.setSidesOfPortsToSidesOfDummyNodes(),t.setProperty(e.In,this.crossHierarchyMap),this.dummyNodeMap.clear()):(this.separateTransformHierarchyEdges(t),this.setContainerPortSidesByNetFlow(t),this.setSidesOfPortsToSidesOfDummyNodes(),this.removeOriginalEdges(),t.setProperty(e.In,this.crossHierarchyMap),this.dummyNodeMap.clear())}separateTransformHierarchyEdges(t){for(let n of t.getLayerlessNodes()){let t=n.getNestedGraph();t!==null&&(this.separateTransformHierarchyEdges(t),this.separateTransformNestedEdges(t,n),this.processInsideSelfLoops(t,n,n.getProperty(e.Lt),!0))}}separateTransformNestedEdges(t,n){let r=[],i=/* @__PURE__ */ new Set;for(let e of[...t.getLayerlessNodes()])if(e.getType()!==`EXTERNAL_PORT`)for(let a of e.getPorts()){for(let e of[...a.getOutgoingEdges()])if(!i.has(e)&&e.getTarget().getNode().getGraph()!==t){i.add(e);let o=this.introduceSeparateExternalPort(t,n,e,a,`OUTPUT`);o!==null&&r.push(o)}for(let e of[...a.getIncomingEdges()])if(!i.has(e)&&e.getSource().getNode().getGraph()!==t){i.add(e);let o=this.introduceSeparateExternalPort(t,n,e,a,`INPUT`);o!==null&&r.push(o)}}for(let e of r)t.getLayerlessNodes().includes(e.dummyNode)||t.getLayerlessNodes().push(e.dummyNode);r.length>0&&t.getProperty(e.Gn).add(`EXTERNAL_PORTS`)}introduceSeparateExternalPort(t,n,r,i,a){let o=a===`INPUT`?r.getSource():r.getTarget();if(o.getNode()!==n)return null;let s=o.getSide();if(s===`UNDEFINED`){let e=Ii(t);s=a===`INPUT`?Fi(Pi(e)):Pi(e)}let c=Ui(o,n.getProperty(e.Lt),s,this.calculateNetFlow(o),null,o.getPosition(),o.getSize(),Ii(t),t);c.setProperty(e.lr,o),this.dummyNodeMap.has(o)||this.dummyNodeMap.set(o,c);let l=this.createDummyEdge(t,r),u=c.getPorts()[0];a===`INPUT`?(l.setSource(u),l.setTarget(i)):(l.setSource(i),l.setTarget(u));let d=new sa(r,l,c,u,a,!0);return this.addToMap(r,new ia(l,t,a)),d}setContainerPortSidesByNetFlow(t){for(let n of t.getLayerlessNodes()){let t=n.getNestedGraph();if(t===null)continue;let r=n.getProperty(e.Lt);if(!e.Lr.isSideFixed(r))for(let e of n.getPorts()){if(e.getSide()!==`UNDEFINED`)continue;let n=Pi(Ii(t));e.setSideInferred(e.getNetFlow()>0?n:Fi(n))}this.setContainerPortSidesByNetFlow(t)}}removeOriginalEdges(){for(let e of[...this.crossHierarchyMap.keys()]){let t=this.crossHierarchyMap.get(e)??[];if(e.getLabels().length>0&&t.length>0){let n=[...t].sort((e,t)=>oa(e,t,this.topGraph));for(let t of[...e.getLabels()]){let r=-1;switch(t.placement===void 0?`CENTER`:t.placement){case`HEAD`:r=n.length-1;break;case`CENTER`:r=this.shallowestEdgeSegment(n);break;case`TAIL`:r=0}r!==-1&&(n[r].getNewEdge().getLabels().push(t),e.getLabels().splice(e.getLabels().indexOf(t),1))}}e.setSource(null),e.setTarget(null)}}shallowestEdgeSegment(e){let t=-1;for(let n=0;n<e.length;n++)if(e[n].getType()===`INPUT`){t=n===0?0:n-1;break}else n===e.length-1&&(t=n);return t}setSidesOfPortsToSidesOfDummyNodes(){for(let[t,n]of this.dummyNodeMap){n.setProperty(e.lr,t),t.setProperty(e._r,n),t.setProperty(e.Xn,!0);let r=n.getProperty(e.Un);t.setSide(r===`UNDEFINED`?`UNDEFINED`:r),t.getNode().setProperty(e.Lt,`FIXED_SIDE`),t.getNode().getGraph().getProperty(e.Gn).add(`NON_FREE_PORTS`)}}processInsideSelfLoops(t,n,r,i){if(n.getProperty(e.Q)){for(let i of n.getPorts())for(let a of[...i.getOutgoingEdges()]){if(!(a.getTarget().getNode()===n&&a.getProperty(e.$)))continue;let i=a.getSource(),o=this.dummyNodeMap.get(i);o===void 0&&(o=Ui(i,r,i.getSide(),-1,null,null,i.getSize(),Ii(t),t),o.setProperty(e.lr,i),this.dummyNodeMap.set(i,o),t.getLayerlessNodes().includes(o)||t.getLayerlessNodes().push(o));let s=a.getTarget(),c=this.dummyNodeMap.get(s);c===void 0&&(c=Ui(s,r,s.getSide(),1,null,null,s.getSize(),Ii(t),t),c.setProperty(e.lr,s),this.dummyNodeMap.set(s,c),t.getLayerlessNodes().includes(c)||t.getLayerlessNodes().push(c));let l=this.createDummyEdge(t,a);l.setSource(o.getPorts()[0]),l.setTarget(c.getPorts()[0]),this.addToMap(a,new ia(l,t,`OUTPUT`)),t.getProperty(e.Gn).add(`EXTERNAL_PORTS`)}if(i){let r=/* @__PURE__ */ new Map;n.getPorts().forEach((e,t)=>r.set(e,t));let i=t.getLayerlessNodes(),a=[...i].sort((t,n)=>{let i=t.getProperty(e.lr),a=n.getProperty(e.lr);if(i instanceof p&&a instanceof p){let e=r.get(i),t=r.get(a);if(e!==void 0&&t!==void 0)return e-t}return 0});a.some((e,t)=>e!==i[t])&&(i.length=0,i.push(...a))}}}calculateNetFlow(t){let n=t.getNode(),r=n.getProperty(e.Q),i=0,a=0;for(let o of t.getOutgoingEdges()){let t=o.isSelfLoop(),s=t&&r&&o.getProperty(e.$),c=o.getTarget().getNode();t&&s?a++:t&&!s?i++:c.getGraph().getParentNode()===n?a++:i++}for(let o of t.getIncomingEdges()){let t=o.isSelfLoop(),s=t&&r&&o.getProperty(e.$),c=o.getSource().getNode();t&&s?i++:t&&!s?a++:c.getGraph().getParentNode()===n?i++:a++}return i-a}transformHierarchyEdges(t,n){let r=[];for(let n of t.getLayerlessNodes()){let t=n.getNestedGraph();if(t!==null){let i=this.transformHierarchyEdges(t,n);if(r.push(...i),this.processInsideSelfLoops(t,n,`FREE`,!1),t.getProperty(e.Gn).has(`EXTERNAL_PORTS`)){let r=n.getProperty(e.Lt);for(let i of n.getPorts()){let a=this.dummyNodeMap.get(i);a===void 0&&(a=Ui(i,r,i.getSide(),-i.getNetFlow(),null,{x:0,y:0},i.getSize(),Ii(t),t),a.setProperty(e.lr,i),this.dummyNodeMap.set(i,a),t.getLayerlessNodes().includes(a)||t.getLayerlessNodes().push(a));let o=(n.getProperty(e.zt)??[]).includes(`INSIDE`),s=a.getPorts()[0],c=n.getProperty(e.zt)??[],l=!c.includes(`INSIDE`)&&!c.includes(`OUTSIDE`);for(let e of i.getLabels()){let t={text:``,position:{x:0,y:0},size:{x:e.size.x,y:e.size.y}};if(!o){let n=i.getSide(),r=0;if(l)switch(n){case`EAST`:r=Math.max(0,-e.position.x);break;case`WEST`:r=Math.max(0,e.size.x+e.position.x-i.getSize().x);break;case`NORTH`:r=Math.max(0,e.size.y+e.position.y-i.getSize().y);break;case`SOUTH`:r=Math.max(0,-e.position.y)}n===`EAST`||n===`WEST`?t.size.x=r:t.size.y=r}s.getLabels().push(t)}}}}}let i=[];return this.processInnerHierarchicalEdgeSegments(t,n,r,i),n!==null&&this.processOuterHierarchicalEdgeSegments(t,n,i),i}processInnerHierarchicalEdgeSegments(e,t,n,r){let i=[];for(let r of n){let a=null;if(r.type===`OUTPUT`)for(let o of[...r.origEdges]){let s=o.getTarget().getNode();if(s.getGraph()===e)this.connectChild(e,r,o,r.dummyPort,o.getTarget());else if(t===null||Li(s,t))this.connectSiblings(e,r,n,o);else{let n=this.introduceHierarchicalEdgeSegment(e,t,o,r.dummyPort,`OUTPUT`,a);n!==a&&i.push(n),n.exported&&(a=n)}}else for(let n of[...r.origEdges]){let o=n.getSource().getNode();if(o.getGraph()===e)this.connectChild(e,r,n,n.getSource(),r.dummyPort);else if(t===null||Li(o,t))continue;else{let o=this.introduceHierarchicalEdgeSegment(e,t,n,r.dummyPort,`INPUT`,a);o!==a&&i.push(o),o.exported&&(a=o)}}}for(let t of i)e.getLayerlessNodes().includes(t.dummyNode)||e.getLayerlessNodes().push(t.dummyNode),t.exported&&r.push(t)}processOuterHierarchicalEdgeSegments(e,t,n){let r=[];for(let n of e.getLayerlessNodes())for(let i of n.getPorts()){let n=null;for(let a of[...i.getOutgoingEdges()])if(!Li(a.getTarget().getNode(),t)){let i=this.introduceHierarchicalEdgeSegment(e,t,a,a.getSource(),`OUTPUT`,n);i!==n&&r.push(i),i.exported&&(n=i)}let a=null;for(let n of[...i.getIncomingEdges()])if(!Li(n.getSource().getNode(),t)){let i=this.introduceHierarchicalEdgeSegment(e,t,n,n.getTarget(),`INPUT`,a);i!==a&&r.push(i),i.exported&&(a=i)}}for(let t of r)e.getLayerlessNodes().includes(t.dummyNode)||e.getLayerlessNodes().push(t.dummyNode),t.exported&&n.push(t)}connectChild(e,t,n,r,i){let a=this.createDummyEdge(e,n);a.setSource(r),a.setTarget(i),this.addToMap(n,new ia(a,e,t.type))}connectSiblings(e,t,n,r){let i=null;for(let e of n)if(e!==t&&e.origEdges.includes(r)){i=e;break}if(i===null)return;let a=this.createDummyEdge(e,r);a.setSource(t.dummyPort),a.setTarget(i.dummyPort),this.addToMap(r,new ia(a,e,t.type))}introduceHierarchicalEdgeSegment(t,n,r,i,a,o){let s=t.getProperty(e.ht),c=null;a===`INPUT`&&r.getSource().getNode()===n?c=r.getSource():a===`OUTPUT`&&r.getTarget().getNode()===n&&(c=r.getTarget());let l=o;if(l===null||!s||c!==null){let o=`UNDEFINED`;c===null?n!==null&&e.Lr.isSideFixed(n.getProperty(e.Lt))&&(o=a===`INPUT`?`WEST`:`EAST`):o=c.getSide();let s=this.createExternalPortDummy(t,n,a,o,r),u=this.createDummyEdge(n.getGraph(),r);a===`INPUT`?(u.setSource(s.getPorts()[0]),u.setTarget(i)):(u.setSource(i),u.setTarget(s.getPorts()[0])),l=new sa(r,u,s,s.getProperty(e.lr),a,c===null)}else l.origEdges.push(r);return this.addToMap(r,new ia(l.newEdge,t,a)),l}createExternalPortDummy(t,n,r,i,a){let o=null,s=r===`INPUT`?a.getSource():a.getTarget(),c=Ii(t);if(s.getNode()===n)o=this.dummyNodeMap.get(s)??null,o===null&&(o=Ui(s,n.getProperty(e.Lt),i,this.calculateNetFlow(s),null,s.getPosition(),s.getSize(),c,t),o.setProperty(e.lr,s),this.dummyNodeMap.set(s,o));else{let a=t.getProperty(e.$t)/2;o=Ui({getProperty(t){if(t===e.It)return a},setProperty(){}},n.getProperty(e.Lt),i,r===`INPUT`?-1:1,null,{x:0,y:0},{x:0,y:0},c,t);let s=this.createPortForDummy(o,n,r);o.setProperty(e.lr,s),this.dummyNodeMap.set(s,o)}t.getProperty(e.Gn).add(`EXTERNAL_PORTS`);let l=t.getProperty(e.Lt);return e.Lr.isSideFixed(l)?t.setProperty(e.Lt,`FIXED_SIDE`):t.setProperty(e.Lt,`FREE`),o}createPortForDummy(t,n,r){let i=Ii(n.getGraph()),a=new p;return a.setNode(n),r===`INPUT`?a.setSide(Fi(Pi(i))):a.setSide(Pi(i)),a.setProperty(e.It,t.getProperty(e.It)),a}createDummyEdge(t,n){let r=new m;return r.copyProperties(n),r.setProperty(e.nt,null),r}addToMap(e,t){let n=this.crossHierarchyMap.get(e);n===void 0?this.crossHierarchyMap.set(e,[t]):n.push(t)}},la=class{moveGraphs(e,t,n,r){for(let i of t)this.moveGraph(e,i,n,r)}moveGraph(t,n,r,i){let a=r+n.getOffset().x,o=i+n.getOffset().y,s=/* @__PURE__ */ new Set;for(let r of n.getLayerlessNodes()){r.position.x+=a,r.position.y+=o;for(let t of r.getPorts())for(let n of t.getOutgoingEdges()){if(s.has(n))continue;s.add(n);for(let e of n.getBendPoints())e.x+=a,e.y+=o;let t=n.getProperty(e.nt);if(t!==null)for(let e of t)e.x+=a,e.y+=o;for(let e of n.getLabels())e.position.x+=a,e.position.y+=o}t.getLayerlessNodes().push(r),r.setGraph(t)}}offsetGraphs(e,t,n){for(let r of e)this.offsetGraph(r,t,n)}offsetGraph(t,n,r){let i=/* @__PURE__ */ new Set;for(let a of t.getLayerlessNodes()){a.position.x+=n,a.position.y+=r;for(let t of a.getPorts())for(let a of t.getOutgoingEdges()){if(i.has(a))continue;i.add(a);for(let e of a.getBendPoints())e.x+=n,e.y+=r;let t=a.getProperty(e.nt);if(t!==null)for(let e of t)e.x+=n,e.y+=r;for(let e of a.getLabels())e.position.x+=n,e.position.y+=r}}}};let ua=/* @__PURE__ */ function(e){return e.Q1=`Q1`,e.Q4=`Q4`,e.Q2=`Q2`,e.Q3=`Q3`,e}({});(function(e){function t(e){return e===`Q1`||e===`Q2`}e.isUpper=t;function n(e){return e===`Q1`||e===`Q4`}e.isLeft=n;function r(e,t){return e===`Q1`&&t===`Q4`||e===`Q4`&&t===`Q1`||e===`Q3`&&t===`Q2`||e===`Q2`&&t===`Q3`}e.isBothLeftOrBothRight=r;function i(e,t){return e===`Q1`&&(t===`Q2`||t===`Q3`)||e===`Q4`&&(t===`Q3`||t===`Q2`)}e.isOneLeftOneRight=i})(ua||={});var da=class{x;y;quadrant=null;convex=!0;constructor(e,t,n){this.x=e,this.y=t,n!==void 0&&(this.quadrant=n)}equals(e){return this.x===e.x&&this.y===e.y}};const fa=(e,t)=>e.x===t.x?e.y-t.y:e.x-t.x,pa=(e,t)=>e.x===t.x?t.y-e.y:e.x-t.x,ma=(e,t)=>e.x===t.x?e.y-t.y:t.x-e.x,ha=(e,t)=>e.x===t.x?t.y-e.y:t.x-e.x,ga=(e,t)=>{if(e.x===t.x){if(e.quadrant===t.quadrant||ua.isBothLeftOrBothRight(e.quadrant,t.quadrant)){let n=ua.isLeft(e.quadrant)?1:-1;if(e.convex&&!t.convex)return n;if(!e.convex&&t.convex)return-n}return _a[e.quadrant]-_a[t.quadrant]}return e.x-t.x},_a={Q1:0,Q4:1,Q2:2,Q3:3};var va=class{quadrant;points=[];maximalY;compare;constructor(e){this.quadrant=e,e===`Q1`||e===`Q2`?(this.compare=(e,t)=>t-e,this.maximalY=1/0):(this.compare=(e,t)=>e-t,this.maximalY=-1/0)}handle(e){this.compare(e.y,this.maximalY)>0&&(this.points.push(new da(e.x,e.y,this.quadrant)),this.maximalY=e.y)}},ya=class{rects=[];minY=null;maxY=null;lastX;queued=null;queuedPnt=null;constructor(e,t){this.lastX=Math.min(e?.x??0,t?.x??0)}handle(e){if(this.queued!==null&&(e.x!==this.queuedPnt.x||ua.isOneLeftOneRight(this.queuedPnt.quadrant,e.quadrant))&&(this.rects.push(this.queued),this.lastX=this.queued.x+this.queued.width,this.queued=null,this.queuedPnt=null),ua.isUpper(e.quadrant)?this.minY=e:this.maxY=e,(e.quadrant===`Q1`&&!e.convex||e.quadrant===`Q2`&&e.convex||e.quadrant===`Q3`&&e.convex||e.quadrant===`Q4`&&!e.convex)&&this.minY!==null&&this.maxY!==null){let t={x:this.lastX,y:this.minY.y,width:e.x-this.lastX,height:this.maxY.y-this.minY.y};this.queued=t,this.queuedPnt=e}}},ba=class e{hull=[];xMax1=null;xMax2=null;xMin1=null;xMin2=null;yMax1=null;yMax2=null;yMin1=null;yMin2=null;static of(t){let n=new e;for(let e of t)(n.xMax1===null||e.x>=n.xMax1.x)&&(n.xMax2=n.xMax1,n.xMax1=e),(n.xMin1===null||e.x<=n.xMin1.x)&&(n.xMin2=n.xMin1,n.xMin1=e),(n.yMax1===null||e.y>=n.yMax1.y)&&(n.yMax2=n.yMax1,n.yMax1=e),(n.yMin1===null||e.y<=n.yMin1.y)&&(n.yMin2=n.yMin1,n.yMin1=e);let r=new va(`Q1`);lr(t,fa,r);let i=new va(`Q4`);lr(t,pa,i);let a=new va(`Q2`);lr(t,ma,a);let o=new va(`Q3`);return lr(t,ha,o),xa(r.points,`Q1`),xa(a.points,`Q2`),xa(o.points,`Q3`),xa(i.points,`Q4`),n.hull.length=0,n.hull.push(...r.points,...[...a.points].reverse(),...o.points,...[...i.points].reverse()),n}getHull(){return this.hull}splitIntoRectangles(){let e=new ya(this.xMin1,this.xMin2);return lr(this.hull,ga,e),e.queued!==null&&e.rects.push(e.queued),e.rects}};function xa(e,t){let n=[],r=e[0];n.push(r);for(let i=1;i<e.length;i++){let a=e[i],o=new da(a.x,r.y,t);o.convex=!1,n.push(o,a),r=a}e.length=0,e.push(...n)}function Sa(e){return e===`LEFT`||e===`RIGHT`}function Ca(e){switch(e){case`LEFT`:return`RIGHT`;case`RIGHT`:return`LEFT`;case`UP`:return`DOWN`;case`DOWN`:return`UP`;default:return`UNDEFINED`}}const wa={getHorizontalSpacing(e,t){return Math.min(e.getHorizontalSpacing(),t.getHorizontalSpacing())},getVerticalSpacing(e,t){return Math.min(e.getVerticalSpacing(),t.getVerticalSpacing())}};function L(e,t){if(e.size!==t.size)return!1;for(let n of e)if(!t.has(n))return!1;return!0}const Ta=`NORTH`,Ea=`EAST`,Da=`SOUTH`,R=`WEST`,Oa=/* @__PURE__ */ new Set([Ta]),ka=/* @__PURE__ */ new Set([Ea]),Aa=/* @__PURE__ */ new Set([Da]),ja=/* @__PURE__ */ new Set([R]),Ma=/* @__PURE__ */ new Set([Ta,Ea]),Na=/* @__PURE__ */ new Set([Ea,Da]),Pa=/* @__PURE__ */ new Set([Da,R]),Fa=/* @__PURE__ */ new Set([Ta,R]),Ia=/* @__PURE__ */ new Set([Ta,Da]),La=/* @__PURE__ */ new Set([Ea,R]),Ra=/* @__PURE__ */ new Set([Ta,Ea,R]),za=/* @__PURE__ */ new Set([Ta,Da,R]),Ba=/* @__PURE__ */ new Set([Ea,Da,R]),Va=/* @__PURE__ */ new Set([Ta,Ea,Da,R]);var Ha=class{cGraph;spacing;oldPosition=/* @__PURE__ */ new Map;offsets=/* @__PURE__ */ new Map;globalOffset={x:0,y:0};graphSize={x:0,y:0};externalExtensions=/* @__PURE__ */ new Map;externalPlaceholder=/* @__PURE__ */ new Map;constructor(e){this.spacing=e,this.cGraph=new ar([])}getOffset(e){let t=this.oldPosition.get(e),n=this.offsets.get(e).rect;return{x:t.x-n.x,y:t.y-n.y}}getGlobalOffset(){return this.globalOffset}getGraphSize(){return this.graphSize}getExternalExtensions(){return this.externalExtensions}getExternalPlaceholder(){return this.externalPlaceholder}transform(e){this.cGraph=new ar([`LEFT`,`RIGHT`,`UP`,`DOWN`]);for(let t of e.getComponents()){let e=new ir;this.cGraph.cGroups.push(e);for(let n of t.getHull()){let r=new Ua(n,this.spacing);this.setLock(r,t.getExternalExtensionSides()),this.oldPosition.has(t)||(this.oldPosition.set(t,{x:n.x,y:n.y}),this.offsets.set(t,r)),this.cGraph.cNodes.push(r),e.addCNode(r)}for(let n of t.getExternalExtensions()){let r=new Ua(n.getRepresentor(),this.spacing);this.externalExtensions.set(n,{first:e,second:r}),this.setLock(r,t.getExternalExtensionSides());let i=n.getPlaceholder();if(i!==null){let r=new Ua(i,this.spacing,1);this.setLock(r,t.getExternalExtensionSides()),new ir().addCNode(r);let a=this.externalPlaceholder.get(n.getDirection())??[];a.push({first:e,second:r}),this.externalPlaceholder.set(n.getDirection(),a)}}}return this.cGraph}setLock(e,t){t.size===0&&e.lock.set(!0,!0,!0,!0),L(t,Oa)&&e.lock.set(!0,!0,!0,!1),L(t,ka)&&e.lock.set(!1,!0,!0,!0),L(t,Aa)&&e.lock.set(!0,!0,!1,!0),L(t,ja)&&e.lock.set(!0,!1,!0,!0),L(t,Ma)&&e.lock.set(!1,!0,!0,!1),L(t,Na)&&e.lock.set(!1,!0,!1,!0),L(t,Pa)&&e.lock.set(!0,!1,!1,!0),L(t,Fa)&&e.lock.set(!0,!1,!0,!1),L(t,Ia)&&e.lock.set(!0,!0,!0,!0),L(t,La)&&e.lock.set(!0,!0,!0,!0),L(t,Ba)&&e.lock.set(!0,!0,!0,!0),L(t,za)&&e.lock.set(!0,!0,!0,!0),L(t,Ra)&&e.lock.set(!0,!0,!0,!0),L(t,Va)&&e.lock.set(!0,!0,!0,!0)}applyLayout(){for(let e of this.cGraph.cNodes)e.applyElementPosition();let e={x:1/0,y:1/0},t={x:-1/0,y:-1/0};for(let n of this.cGraph.cNodes)e.x=Math.min(e.x,n.hitbox.x),e.y=Math.min(e.y,n.hitbox.y),t.x=Math.max(t.x,n.hitbox.x+n.hitbox.width),t.y=Math.max(t.y,n.hitbox.y+n.hitbox.height);for(let n of this.externalPlaceholder.values())for(let r of n){let n=r.second;e.x=Math.min(e.x,n.hitbox.x),e.y=Math.min(e.y,n.hitbox.y),t.x=Math.max(t.x,n.hitbox.x+n.hitbox.width),t.y=Math.max(t.y,n.hitbox.y+n.hitbox.height)}this.globalOffset={x:-e.x,y:-e.y},this.graphSize={x:t.x-e.x,y:t.y-e.y},this.cGraph.cGroups.length=0,this.cGraph.cNodes.length=0}},Ua=class extends vr{rect;spacing;individualSpacing;constructor(e,t,n=null){super(),this.rect=e,this.spacing=t,this.hitbox={x:e.x,y:e.y,width:e.width,height:e.height},this.individualSpacing=n}getHorizontalSpacing(){return this.individualSpacing??this.spacing}getVerticalSpacing(){return this.individualSpacing??this.spacing}applyElementPosition(){this.rect.x=this.hitbox.x,this.rect.y=this.hitbox.y}getElementPosition(){return this.rect.x}toString(){return``}};const Wa=/* @__PURE__ */ new Set([`LEFT`,`RIGHT`]),Ga=/* @__PURE__ */ new Set([`UP`,`DOWN`]);var Ka=class e{compactionGraph=new ar([]);transformer=new Ha(0);verticalExternalExtensions=[];horizontalExternalExtensions=[];compactor=null;topLeft={x:0,y:0};bottomRight={x:0,y:0};constructor(){}static init(t,n){let r=new e;return r.transformer=new Ha(n),r.compactionGraph=r.transformer.transform(t),r}compact(){let e=[];this.verticalExternalExtensions=[],this.horizontalExternalExtensions=[];for(let[t,n]of this.transformer.getExternalExtensions())e.push(n.second),Sa(t.getDirection())?this.horizontalExternalExtensions.push(n):this.verticalExternalExtensions.push(n);this.addExternalEdgeRepresentations(this.horizontalExternalExtensions),this.addExternalEdgeRepresentations(this.verticalExternalExtensions),this.compactor=new gr(this.compactionGraph),this.compactor.setSpacingsHandler(wa),this.removeExternalEdgeRepresentations(this.horizontalExternalExtensions),this.removeExternalEdgeRepresentations(this.verticalExternalExtensions),e.push(...this.compactor.cGraph.cNodes),this.topLeft={x:1/0,y:1/0},this.bottomRight={x:-1/0,y:-1/0};for(let t of e)this.topLeft.x=Math.min(this.topLeft.x,t.hitbox.x),this.topLeft.y=Math.min(this.topLeft.y,t.hitbox.y),this.bottomRight.x=Math.max(this.bottomRight.x,t.hitbox.x+t.hitbox.width),this.bottomRight.y=Math.max(this.bottomRight.y,t.hitbox.y+t.hitbox.height);this.compactor.setLockingStrategy(e=>e.first.cGroup.outDegree!==0);let t=0,n;do n=this.compactRun(t),t++;while((t<2||n>1e-4)&&t<10);this.compactor.setLockingStrategy(e=>e.first.lock.get(e.second)||e.first.cGroup.outDegree!==0&&e.first.lock.get(e.second)),this.compactRun(0),this.compactor.finish(),this.transformer.applyLayout()}getGraphSize(){return this.transformer.getGraphSize()}getOffset(e){let t=this.transformer.getOffset(e),n=this.transformer.getGlobalOffset();return{x:-t.x+n.x,y:-t.y+n.y}}compactRun(e){let t=0;for(let e of this.compactionGraph.cGroups)e.delta=0,e.deltaNormalized=0;this.addPlaceholders(`HORZ`),this.addExternalEdgeRepresentations(this.verticalExternalExtensions),this.compactor.calculateGroupOffsets(),this.compactor.forceConstraintsRecalculation();let n=`LEFT`;this.compactor.changeDirection(n).compact().changeDirection(Ca(n)).applyLockingStrategy().compact().changeDirection(n).applyLockingStrategy().compact(),this.compactor.changeDirection(`LEFT`),this.removeExternalEdgeRepresentations(this.verticalExternalExtensions),this.removePlaceholders(`HORZ`),this.updateExternalExtensionDimensions(`HORZ`),this.updatePlaceholders(`VERT`),this.addPlaceholders(`VERT`),this.addExternalEdgeRepresentations(this.horizontalExternalExtensions),this.compactor.calculateGroupOffsets();for(let e of this.compactionGraph.cGroups)t+=Math.abs(e.deltaNormalized);for(let e of this.compactionGraph.cGroups)e.delta=0,e.deltaNormalized=0;n=`UP`,this.compactor.changeDirection(n).forceConstraintsRecalculation().compact().changeDirection(Ca(n)).applyLockingStrategy().compact().changeDirection(n).applyLockingStrategy().compact(),this.compactor.changeDirection(`LEFT`),this.removeExternalEdgeRepresentations(this.horizontalExternalExtensions),this.removePlaceholders(`VERT`),this.updateExternalExtensionDimensions(`VERT`),this.updatePlaceholders(`HORZ`),this.compactor.forceConstraintsRecalculation();for(let e of this.compactionGraph.cGroups)t+=Math.abs(e.deltaNormalized);return t}addExternalEdgeRepresentations(e){for(let t of e)this.compactionGraph.cNodes.push(t.second),t.first.addCNode(t.second)}removeExternalEdgeRepresentations(e){for(let t of e){let e=this.compactionGraph.cNodes.indexOf(t.second);e!==-1&&this.compactionGraph.cNodes.splice(e,1),t.first.removeCNode(t.second)}}addPlaceholders(e){let t=e===`VERT`?Ga:Wa;for(let e of t)for(let t of this.transformer.getExternalPlaceholder().get(e)??[])this.compactionGraph.cNodes.push(t.second),this.compactionGraph.cGroups.push(t.second.cGroup)}removePlaceholders(e){let t=e===`VERT`?Ga:Wa;for(let e of t)for(let t of this.transformer.getExternalPlaceholder().get(e)??[]){let e=this.compactionGraph.cNodes.indexOf(t.second);e!==-1&&this.compactionGraph.cNodes.splice(e,1);let n=this.compactionGraph.cGroups.indexOf(t.second.cGroup);n!==-1&&this.compactionGraph.cGroups.splice(n,1)}}updatePlaceholders(e){let t=e===`VERT`?Ga:Wa;for(let e of t)for(let t of this.transformer.getExternalPlaceholder().get(e)??[]){let n=t.second,r=t.first.deltaNormalized;switch(e){case`LEFT`:case`RIGHT`:n.hitbox.y+=r;break;case`UP`:case`DOWN`:n.hitbox.x+=r}}}updateExternalExtensionDimensions(e){for(let[t,n]of this.transformer.getExternalExtensions()){if(e===`VERT`){if(t.getDirection()!==`UP`&&t.getDirection()!==`DOWN`)continue}else if(t.getDirection()!==`LEFT`&&t.getDirection()!==`RIGHT`)continue;let r=n.second,i=n.first.deltaNormalized;switch(t.getDirection()){case`LEFT`:r.hitbox.x=this.topLeft.x,r.hitbox.width=Math.max(1,r.hitbox.width+i);break;case`RIGHT`:r.hitbox.x=r.hitbox.x+i,r.hitbox.width=Math.max(1,r.hitbox.width-i);break;case`UP`:r.hitbox.y=this.topLeft.y,r.hitbox.height=Math.max(1,r.hitbox.height+i);break;case`DOWN`:r.hitbox.y=r.hitbox.y+i,r.hitbox.height=Math.max(1,r.hitbox.height-i)}}}};const qa=new e.ai(`org.eclipse.elk.layered.compaction.connectedComponents`,!1),Ja=1e-4;function Ya(e){switch(e){case`NORTH`:return`UP`;case`WEST`:return`LEFT`;case`EAST`:return`RIGHT`;case`SOUTH`:return`DOWN`;default:return`UNDEFINED`}}function Xa(e,t,n){return Math.abs(e-t)<=n}function z(e,t,n,r){return{x:e,y:t,width:n,height:r}}function Za(e){return{x:e.x+e.width,y:e.y}}function Qa(e){return{x:e.x+e.width,y:e.y+e.height}}function $a(e){return{x:e.x,y:e.y+e.height}}function eo(e){return{x:e.x,y:e.y}}var to=class{compactor=null;yetAnotherOffset={x:0,y:0};compactedGraphSize={x:0,y:0};graphTopLeft={x:0,y:0};graphBottomRight={x:0,y:0};compact(t,n,r){this.graphTopLeft={x:1/0,y:1/0},this.graphBottomRight={x:-1/0,y:-1/0};for(let e of t)for(let t of e.getLayerlessNodes())this.graphTopLeft.x=Math.min(this.graphTopLeft.x,t.position.x-t.getMargin().left),this.graphTopLeft.y=Math.min(this.graphTopLeft.y,t.position.y-t.getMargin().top),this.graphBottomRight.x=Math.max(this.graphBottomRight.x,t.position.x+t.size.x+t.getMargin().right),this.graphBottomRight.y=Math.max(this.graphBottomRight.y,t.position.y+t.size.y+t.getMargin().bottom);let i=new no;for(let e of t){let t=this.transformLGraph(e);i.getComponents().push(t),t.containsRegularNodes=t.containsRegularNodes||t.getExternalExtensionSides().size>0}this.compactor=Ka.init(i,r),this.compactor.compact(),this.yetAnotherOffset={x:0,y:0},this.compactedGraphSize=this.compactor.getGraphSize();for(let t of i.getComponents()){let n=this.compactor.getOffset(t);fo(t.graph,n.x,n.y);for(let n of t.getNodes())if(n.getType()===`EXTERNAL_PORT`){let t=this.getExternalPortPosition(n.getPosition(),n.getProperty(e.Un));n.position.x=t.x,n.position.y=t.y}}for(let e of i.getComponents())for(let t of e.getExternalEdges()){let e=[];e.push(t.getSource().getAbsoluteAnchor()),e.push(...t.getBendPoints()),e.push(t.getTarget().getAbsoluteAnchor());let n=null;for(let t of e)n===null||(Xa(n.x,t.x,Ja)?(this.yetAnotherOffset.x=Math.min(this.yetAnotherOffset.x,n.x),this.compactedGraphSize.x=Math.max(this.compactedGraphSize.x,n.x)):Xa(n.y,t.y,Ja)&&(this.yetAnotherOffset.y=Math.min(this.yetAnotherOffset.y,n.y),this.compactedGraphSize.y=Math.max(this.compactedGraphSize.y,n.y))),n=t}this.yetAnotherOffset.x=-this.yetAnotherOffset.x,this.yetAnotherOffset.y=-this.yetAnotherOffset.y,this.compactedGraphSize.x+=this.yetAnotherOffset.x,this.compactedGraphSize.y+=this.yetAnotherOffset.y}getOffset(){return this.yetAnotherOffset}getGraphSize(){return this.compactedGraphSize}transformLGraph(e){let t=new ro(e);t.containsRegularNodes||this.createDummyNode(e);let n=this.componentHullPoints(e),r=/* @__PURE__ */ new Map,i=new co;for(let t of e.getLayerlessNodes())for(let e of t.getOutgoingEdges())if(this.isExternalEdge(e)){let t=this.transformLEdge(e,n,i),a=r.get(t.getDirection())??[];a.push(t.edge),r.set(t.getDirection(),a)}let a=[];for(let e of t.getExternalExtensionSides()){let t=i.min[e],o=i.max[e],s=i.extent[e],c=null,l=null;switch(e){case`WEST`:c=z(this.graphTopLeft.x,t,n.topLeft.x-this.graphTopLeft.x,o-t),l=z(this.graphTopLeft.x,t,s,o-t),n.addVector(Za(c)),n.addVector(Qa(c));break;case`EAST`:c=z(n.bottomRight.x,t,this.graphBottomRight.x-n.bottomRight.x,o-t),l=z(this.graphBottomRight.x-s,t,s,o-t),n.addVector(eo(c)),n.addVector($a(c));break;case`NORTH`:c=z(t,this.graphTopLeft.y,o-t,n.topLeft.y-this.graphTopLeft.y),l=z(t,this.graphTopLeft.y,o-t,s),n.addVector($a(c)),n.addVector(Qa(c));break;case`SOUTH`:c=z(t,n.bottomRight.y,o-t,this.graphBottomRight.y-n.bottomRight.y),l=z(t,this.graphBottomRight.y-s,o-t,s),n.addVector(eo(c)),n.addVector(Za(c))}if(c!==null){let t=new io;t.side=e,t.extension=c,t.placeholder=l,t.edges=new Set(r.get(Ya(e))??[]),a.push(t)}}return t.externalExtensions=a,t.rectilinearConvexHull=ba.of(n.points).splitIntoRectangles(),t}createDummyNode(t){let n=t.getLayerlessNodes()[0],r=new f(t);switch(r.size.x=Math.max(1,n.size.x),r.size.y=Math.max(1,n.size.y),r.position.x=n.position.x,r.position.y=n.position.y,n.getProperty(e.Un)){case`WEST`:r.position.x+=2;break;case`NORTH`:r.position.y+=2;break;case`EAST`:r.position.x-=2;break;case`SOUTH`:r.position.y-=2}let i=new p;i.setNode(r);let a=new m,o=n.getPorts()[0];a.setSource(o),a.setTarget(i),i.position.x=o.position.x,i.position.y=o.position.y;let s=o.getAnchor(),c=i.getAnchor();c.x=s.x,c.y=s.y}componentHullPoints(e){let t=new oo;for(let n of e.getLayerlessNodes())if(n.getType()!==`EXTERNAL_PORT`){lo(t,n);for(let e of n.getOutgoingEdges())if(!this.isExternalEdge(e))for(let n of e.getBendPoints())t.add(new da(n.x,n.y))}return t}isExternalEdge(e){return e.getSource().getNode().getType()===`EXTERNAL_PORT`||e.getTarget().getNode().getType()===`EXTERNAL_PORT`}transformLEdge(t,n,r){let i=new ao(t),a=this.edgeToSegments(t,i),o=Math.max(t.getProperty(e.W),1);for(let e of a.innerSegments){let t=this.segmentToRectangle(e.first,e.second,o);n.addRect(t)}let s=i.externalPortSide,c=this.segmentToRectangle(a.outerSegment.first,a.outerSegment.second,o);s===`WEST`||s===`EAST`?(r.min[s]=Math.min(r.min[s],c.y),r.max[s]=Math.max(r.max[s],c.y+c.height)):(r.min[s]=Math.min(r.min[s],c.x),r.max[s]=Math.max(r.max[s],c.x+c.width));let l=-1/0,u=i.externalPort.getNode().getMargin();switch(s){case`WEST`:l=u.right;break;case`EAST`:l=u.left;break;case`NORTH`:l=u.bottom;break;case`SOUTH`:l=u.top}return r.extent[s]=Math.max(r.extent[s],l),i}segmentToRectangle(e,t,n){return z(Math.min(e.x,t.x)-n/2,Math.min(e.y,t.y)-n/2,Math.abs(e.x-t.x)+n,Math.abs(e.y-t.y)+n)}edgeToSegments(e,t){let n=t.externalPort,r=t.externalPortSide,i=e.getSource().getAbsoluteAnchor(),a=e.getTarget().getAbsoluteAnchor();n===e.getSource()?(i=this.getExternalPortPosition(i,r),a=uo(e.getTarget())):(i=uo(e.getSource()),a=this.getExternalPortPosition(a,r));let o=[];o.push(i),o.push(...e.getBendPoints()),o.push(a);let s=e.getSource()===n,c=new so;for(let e=0;e<o.length-1;++e){let t={first:o[e],second:o[e+1]};s&&e===0||!s&&e===o.length-2?c.outerSegment=t:c.innerSegments.push(t)}return c}getExternalPortPosition(e,t){switch(t){case`NORTH`:return{x:e.x,y:Math.min(this.graphTopLeft.y,e.y)};case`EAST`:return{x:Math.max(this.graphBottomRight.x,e.x),y:e.y};case`SOUTH`:return{x:e.x,y:Math.max(this.graphBottomRight.y,e.y)};case`WEST`:return{x:Math.min(e.x,this.graphTopLeft.x),y:e.y};default:return{x:e.x,y:e.y}}}},no=class{components=[];containsExternalPorts=!1;getComponents(){return this.components}isContainsExternalExtensions(){return this.containsExternalPorts}},ro=class{graph;containsRegularNodes;rectilinearConvexHull=[];externalExtensions=[];constructor(e){this.graph=e,this.containsRegularNodes=e.getLayerlessNodes().some(e=>e.getType()===`NORMAL`)}getExternalExtensionSides(){return this.graph.getProperty(e.Bn)??/* @__PURE__ */ new Set}getHull(){return this.rectilinearConvexHull}getExternalExtensions(){return this.externalExtensions}getNodes(){return this.graph.getLayerlessNodes()}getExternalEdges(){let e=[];for(let t of this.externalExtensions)e.push(...t.getRepresentative());return e}},io=class{edges=/* @__PURE__ */ new Set;side=`UNDEFINED`;extension=z(0,0,0,0);placeholder=z(0,0,0,0);getRepresentative(){return this.edges}getRepresentor(){return this.extension}getParent(){throw Error(`UnsupportedOperationException`)}getDirection(){return Ya(this.side)}getPlaceholder(){return this.placeholder}},ao=class{edge;externalPort;externalPortSide;constructor(t){if(this.edge=t,t.getSource().getNode().getType()===`EXTERNAL_PORT`)this.externalPort=t.getSource(),this.externalPortSide=t.getSource().getNode().getProperty(e.Un);else if(t.getTarget().getNode().getType()===`EXTERNAL_PORT`)this.externalPort=t.getTarget(),this.externalPortSide=t.getTarget().getNode().getProperty(e.Un);else throw Error(`Edge ${t} is not an external edge.`)}getDirection(){return Ya(this.externalPortSide)}getRepresentative(){return this.edge}},oo=class{points=[];topLeft={x:1/0,y:1/0};bottomRight={x:-1/0,y:-1/0};add(e){this.topLeft.x=Math.min(this.topLeft.x,e.x),this.topLeft.y=Math.min(this.topLeft.y,e.y),this.bottomRight.x=Math.max(this.bottomRight.x,e.x),this.bottomRight.y=Math.max(this.bottomRight.y,e.y),this.points.push(e)}addVector(e){this.add(new da(e.x,e.y))}addRect(e){this.addVector({x:e.x,y:e.y}),this.addVector({x:e.x+e.width,y:e.y}),this.addVector({x:e.x,y:e.y+e.height}),this.addVector({x:e.x+e.width,y:e.y+e.height})}},so=class{innerSegments=[];outerSegment=null},co=class{min;max;extent;constructor(){this.min={NORTH:1/0,EAST:1/0,SOUTH:1/0,WEST:1/0,UNDEFINED:1/0},this.max={NORTH:-1/0,EAST:-1/0,SOUTH:-1/0,WEST:-1/0,UNDEFINED:-1/0},this.extent={NORTH:-1/0,EAST:-1/0,SOUTH:-1/0,WEST:-1/0,UNDEFINED:-1/0}}};function lo(e,t){let n=t.getMargin();e.addVector({x:t.position.x-n.left,y:t.position.y-n.top}),e.addVector({x:t.position.x-n.left,y:t.position.y+t.size.y+n.bottom}),e.addVector({x:t.position.x+t.size.x+n.right,y:t.position.y-n.top}),e.addVector({x:t.position.x+t.size.x+n.right,y:t.position.y+t.size.y+n.bottom})}function uo(e){let t=e.getAbsoluteAnchor(),n=e.getNode().getMargin();switch(e.getSide()){case`NORTH`:t.y-=n.top;break;case`EAST`:t.x+=n.right;break;case`SOUTH`:t.y+=n.bottom;break;case`WEST`:t.x-=n.left}return t}function fo(e,t,n){let r=/* @__PURE__ */ new Set;for(let i of e.getLayerlessNodes()){i.position.x+=t,i.position.y+=n;for(let e of i.getPorts())for(let i of e.getOutgoingEdges())if(!r.has(i)){r.add(i);for(let e of i.getBendPoints())e.x+=t,e.y+=n}}}function po(t){return t.getProperty(e.Bn)??/* @__PURE__ */ new Set}var mo=class extends la{combine(t,n){if(t.length===1){let e=t[0];e!==n&&(n.getLayerlessNodes().length=0,this.moveGraph(n,e,0,0),n.copyProperties(e),n.getSize().x=e.getSize().x,n.getSize().y=e.getSize().y);return}if(t.length===0){n.getLayerlessNodes().length=0,n.getSize().x=0,n.getSize().y=0;return}this.sortComponents(t,n);let r=t[0];n.getLayerlessNodes().length=0,n.copyProperties(r);let i=0,a=0;for(let e of t){let t=e.getSize();i=Math.max(i,t.x),a+=t.x*t.y}i=Math.max(i,Math.sqrt(a)*n.getProperty(e.h));let o=n.getProperty(e.Qt);if(this.placeComponents(t,n,i,o),r.getProperty(qa)){let e=new to;e.compact(t,n.getSize(),o);for(let n of t){let t=n.getOffset();t.x=e.getOffset().x,t.y=e.getOffset().y}let r=n.getSize();r.x=e.getGraphSize().x,r.y=e.getGraphSize().y}this.moveGraphs(n,t,0,0)}sortComponents(e,t){}placeComponents(e,t,n,r){let i=0,a=0,o=0,s=r,c=null,l=0;for(let t of e){let e=t.getSize(),u=po(t);(i+e.x>n&&!u.has(`NORTH`)||c!==null&&po(c).has(`EAST`)||u.has(`WEST`))&&(i=l,a+=o+r,o=0);let d=t.getOffset();u.has(`NORTH`)&&(i=s+r),this.offsetGraph(t,i+d.x,a+d.y),s=Math.max(s,i+e.x),u.has(`SOUTH`)&&(l=Math.max(l,i+e.x+r)),d.x=0,d.y=0,o=Math.max(o,e.y),i+=e.x+r,c=t}t.getSize().x=s,t.getSize().y=a+o}};function ho(e){return[...e].sort().join(`,`)}const B={NONE:/* @__PURE__ */ new Set,WEST:/* @__PURE__ */ new Set([`WEST`]),EAST:/* @__PURE__ */ new Set([`EAST`]),NORTH:/* @__PURE__ */ new Set([`NORTH`]),SOUTH:/* @__PURE__ */ new Set([`SOUTH`]),NORTH_SOUTH:/* @__PURE__ */ new Set([`NORTH`,`SOUTH`]),EAST_WEST:/* @__PURE__ */ new Set([`EAST`,`WEST`]),NORTH_WEST:/* @__PURE__ */ new Set([`NORTH`,`WEST`]),NORTH_EAST:/* @__PURE__ */ new Set([`NORTH`,`EAST`]),SOUTH_WEST:/* @__PURE__ */ new Set([`SOUTH`,`WEST`]),EAST_SOUTH:/* @__PURE__ */ new Set([`EAST`,`SOUTH`]),NORTH_EAST_WEST:/* @__PURE__ */ new Set([`NORTH`,`EAST`,`WEST`]),NORTH_SOUTH_WEST:/* @__PURE__ */ new Set([`NORTH`,`SOUTH`,`WEST`]),EAST_SOUTH_WEST:/* @__PURE__ */ new Set([`EAST`,`SOUTH`,`WEST`]),NORTH_EAST_SOUTH:/* @__PURE__ */ new Set([`NORTH`,`EAST`,`SOUTH`]),NORTH_EAST_SOUTH_WEST:/* @__PURE__ */ new Set([`NORTH`,`EAST`,`SOUTH`,`WEST`])},go=/* @__PURE__ */ new Map;function V(e,...t){let n=ho(e),r=go.get(n);r===void 0&&(r=/* @__PURE__ */ new Set,go.set(n,r));for(let e of t)r.add(ho(e))}V(B.NONE,B.NORTH_EAST_SOUTH_WEST),V(B.WEST,B.NORTH_EAST_SOUTH_WEST,B.NORTH_SOUTH_WEST),V(B.EAST,B.NORTH_EAST_SOUTH,B.NORTH_EAST_SOUTH_WEST),V(B.NORTH,B.NORTH_EAST_SOUTH_WEST,B.NORTH_EAST_WEST),V(B.SOUTH,B.EAST_SOUTH_WEST,B.NORTH_EAST_SOUTH_WEST),V(B.NORTH_SOUTH,B.EAST_WEST,B.NORTH_EAST_SOUTH_WEST,B.NORTH_EAST_WEST,B.EAST_SOUTH_WEST),V(B.EAST_WEST,B.NORTH_SOUTH,B.NORTH_SOUTH_WEST,B.NORTH_EAST_SOUTH,B.NORTH_EAST_SOUTH_WEST),V(B.NORTH_WEST,B.NORTH_WEST,B.NORTH_EAST_WEST,B.NORTH_SOUTH_WEST),V(B.NORTH_EAST,B.NORTH_EAST,B.NORTH_EAST_WEST,B.NORTH_EAST_SOUTH),V(B.SOUTH_WEST,B.SOUTH_WEST,B.EAST_SOUTH_WEST,B.NORTH_SOUTH_WEST),V(B.EAST_SOUTH,B.EAST_SOUTH,B.EAST_SOUTH_WEST,B.NORTH_EAST_SOUTH),V(B.NORTH_EAST_WEST,B.NORTH,B.NORTH_SOUTH,B.NORTH_WEST,B.NORTH_EAST,B.NORTH_EAST_SOUTH_WEST,B.NORTH_EAST_WEST,B.NORTH_SOUTH_WEST,B.NORTH_EAST_SOUTH),V(B.EAST_SOUTH_WEST,B.SOUTH,B.NORTH_SOUTH,B.SOUTH_WEST,B.EAST_SOUTH,B.EAST_SOUTH_WEST,B.NORTH_SOUTH_WEST,B.NORTH_EAST_SOUTH,B.NORTH_EAST_SOUTH_WEST),V(B.NORTH_SOUTH_WEST,B.WEST,B.EAST_WEST,B.NORTH_WEST,B.SOUTH_WEST,B.NORTH_EAST_WEST,B.EAST_SOUTH_WEST,B.NORTH_SOUTH_WEST,B.NORTH_EAST_SOUTH_WEST),V(B.NORTH_EAST_SOUTH,B.EAST,B.EAST_WEST,B.NORTH_EAST,B.EAST_SOUTH,B.NORTH_EAST_WEST,B.EAST_SOUTH_WEST,B.NORTH_EAST_SOUTH,B.NORTH_EAST_SOUTH_WEST),V(B.NORTH_EAST_SOUTH_WEST,B.NONE,B.WEST,B.EAST,B.NORTH,B.SOUTH,B.NORTH_SOUTH,B.EAST_WEST,B.NORTH_EAST_WEST,B.EAST_SOUTH_WEST,B.NORTH_SOUTH_WEST,B.NORTH_EAST_SOUTH,B.NORTH_EAST_SOUTH_WEST);var _o=class{components=/* @__PURE__ */ new Map;constructor(e){e!==void 0&&this.add(e)}add(t){if(this.canAdd(t)){let n=ho(t.getProperty(e.Bn)??/* @__PURE__ */ new Set),r=this.components.get(n);return r===void 0?this.components.set(n,[t]):r.push(t),!0}return!1}canAdd(t){let n=t.getProperty(e.Bn)??/* @__PURE__ */ new Set,r=go.get(ho(n));if(r!==void 0)for(let e of r){let t=this.components.get(e);if(t!==void 0&&t.length>0)return!1}return!0}getPortSides(){return[...this.components.keys()]}getComponents(){return[...this.components.values()].flat()}getComponentsFor(e){return this.components.get(ho(e))??[]}},vo=class extends la{componentGroups=[];combine(t,n){if(this.componentGroups=[],n.getLayerlessNodes().length=0,t.length===0){n.getSize().x=0,n.getSize().y=0;return}let r=t[0];n.copyProperties(r);for(let e of t)this.addComponent(e);let i=0,a=0,o=r.getProperty(e.Qt);for(let e of this.componentGroups){let t=this.placeComponents(e,o);this.offsetGraphs(e.getComponents(),i,a),i+=t.x,a+=t.y}if(n.getSize().x=i-o,n.getSize().y=a-o,r.getProperty(qa)&&r.getProperty(e.B)===`ORTHOGONAL`){for(let e of t)this.offsetGraph(e,e.getOffset().x,e.getOffset().y);let e=new to;e.compact(t,n.getSize(),o);for(let n of t)n.getOffset().x=e.getOffset().x,n.getOffset().y=e.getOffset().y;n.getSize().x=e.getGraphSize().x,n.getSize().y=e.getGraphSize().y}for(let e of this.componentGroups)this.moveGraphs(n,e.getComponents(),0,0)}addComponent(e){for(let t of this.componentGroups)if(t.add(e))return;this.componentGroups.push(new _o(e))}placeComponents(e,t){let n=this.placeComponentsInRows(e.getComponentsFor(B.NONE),t),r=this.placeComponentsHorizontally(e.getComponentsFor(B.NORTH),t),i=this.placeComponentsHorizontally(e.getComponentsFor(B.SOUTH),t),a=this.placeComponentsVertically(e.getComponentsFor(B.WEST),t),o=this.placeComponentsVertically(e.getComponentsFor(B.EAST),t),s=this.placeComponentsHorizontally(e.getComponentsFor(B.NORTH_WEST),t),c=this.placeComponentsHorizontally(e.getComponentsFor(B.NORTH_EAST),t),l=this.placeComponentsHorizontally(e.getComponentsFor(B.SOUTH_WEST),t),u=this.placeComponentsHorizontally(e.getComponentsFor(B.EAST_SOUTH),t),d=this.placeComponentsVertically(e.getComponentsFor(B.EAST_WEST),t),f=this.placeComponentsHorizontally(e.getComponentsFor(B.NORTH_SOUTH),t),p=this.placeComponentsHorizontally(e.getComponentsFor(B.NORTH_EAST_WEST),t),m=this.placeComponentsHorizontally(e.getComponentsFor(B.EAST_SOUTH_WEST),t),h=this.placeComponentsVertically(e.getComponentsFor(B.NORTH_SOUTH_WEST),t),g=this.placeComponentsVertically(e.getComponentsFor(B.NORTH_EAST_SOUTH),t),_=this.placeComponentsHorizontally(e.getComponentsFor(B.NORTH_EAST_SOUTH_WEST),t),v=Math.max(s.x,a.x,l.x,h.x),y=Math.max(r.x,n.x,i.x,_.x),b=f.x,x=Math.max(c.x,o.x,u.x,g.x),S=Math.max(s.y,r.y,c.y,p.y),C=Math.max(a.y,n.y,o.y,_.y),w=d.y,ee=Math.max(l.y,i.y,u.y,m.y);this.offsetGraphs(e.getComponentsFor(B.NONE),v+b,S+w),this.offsetGraphs(e.getComponentsFor(B.NORTH_EAST_SOUTH_WEST),v+b,S+w),this.offsetGraphs(e.getComponentsFor(B.NORTH),v+b,0),this.offsetGraphs(e.getComponentsFor(B.SOUTH),v+b,S+w+C),this.offsetGraphs(e.getComponentsFor(B.WEST),0,S+w),this.offsetGraphs(e.getComponentsFor(B.EAST),v+b+y,S+w),this.offsetGraphs(e.getComponentsFor(B.NORTH_EAST),v+b+y,0),this.offsetGraphs(e.getComponentsFor(B.SOUTH_WEST),0,S+w+C),this.offsetGraphs(e.getComponentsFor(B.EAST_SOUTH),v+b+y,S+w+C),this.offsetGraphs(e.getComponentsFor(B.EAST_WEST),0,S),this.offsetGraphs(e.getComponentsFor(B.NORTH_SOUTH),v,0),this.offsetGraphs(e.getComponentsFor(B.EAST_SOUTH_WEST),0,S+w+C),this.offsetGraphs(e.getComponentsFor(B.NORTH_EAST_SOUTH),v+b+y,0);let te={x:0,y:0};return te.x=Math.max(v+y+b+x,d.x,p.x,m.x),te.y=Math.max(S+C+w+ee,f.y,h.y,g.y),te}placeComponentsHorizontally(e,t){let n={x:0,y:0};for(let r of e)this.offsetGraph(r,n.x,0),n.x+=r.getSize().x+t,n.y=Math.max(n.y,r.getSize().y);return n.y>0&&(n.y+=t),n}placeComponentsVertically(e,t){let n={x:0,y:0};for(let r of e)this.offsetGraph(r,0,n.y),n.y+=r.getSize().y+t,n.x=Math.max(n.x,r.getSize().x);return n.x>0&&(n.x+=t),n}placeComponentsInRows(e,t){if(e.length===0)return{x:0,y:0};let n=0,r=0;for(let t of e){let e=t.getSize();n=Math.max(n,e.x),r+=e.x*e.y}n=Math.max(n,Math.sqrt(r));let i=0,a=0,o=0,s=t;for(let r of e){let e=r.getSize();i+e.x>n&&(i=0,a+=o+t,o=0),this.offsetGraph(r,i,a),s=Math.max(s,i+e.x),o=Math.max(o,e.y),i+=e.x+t}return{x:s+t,y:a+o+t}}},yo=class{split(t){if(t.getProperty(e.q)===`INCLUDE_CHILDREN`)return[t];let n=t.getProperty(e.Yt)!==!1,r=t.getProperty(e.Gn).has(`EXTERNAL_PORTS`),i=t.getProperty(e.Lt),a=!e.Lr.isOrderFixed(i);if(!n||r&&!a)return[t];let o=this.splitInner(t);return t.getProperty(e.y)!==e.Dn.NONE&&o.sort((e,t)=>bo(e)-bo(t)),o}splitInner(e){let t=/* @__PURE__ */ new Set,n=[];for(let r of e.getLayerlessNodes()){if(t.has(r))continue;let i=[];if(this.dfs(r,i,t),i.length>0){let t=new c;t.copyProperties(e),t.getPadding().left=e.getPadding().left,t.getPadding().top=e.getPadding().top,t.getPadding().right=e.getPadding().right,t.getPadding().bottom=e.getPadding().bottom;for(let e of i)t.getLayerlessNodes().push(e),e.setGraph(t);n.push(t)}}return n.length>0?n:[e]}dfs(e,t,n){if(!n.has(e)){n.add(e),t.push(e);for(let r of e.getPorts())for(let e of r.getConnectedPorts()){let r=e.getNode();r!==null&&this.dfs(r,t,n)}}}combine(t,n){if(n.getProperty(e.Gn).has(`EXTERNAL_PORTS`)){let r=n.getProperty(e.y);if(r===e.Dn.MODEL_ORDER){new mo().combine(t,n);return}if(r!==e.Dn.GROUP_MODEL_ORDER){new vo().combine(t,n);return}}if(n.getLayerlessNodes().length=0,t.length===1){let e=t[0];e!==n&&this.moveGraph(n,e,0,0);return}if(t.length===0)return;let r=n.getProperty(e.Qt),i=n.getProperty(e.y)===e.Dn.NONE?[...t].sort((e,t)=>e.getSize().x*e.getSize().y-t.getSize().x*t.getSize().y):[...t],a=0,o=0;for(let e of i){let t=e.getSize();a=Math.max(a,t.x),o+=t.x*t.y}let s=n.getProperty(e.h);a=Math.max(a,Math.sqrt(o)*s);let c=0,l=0,u=0,d=r;for(let e of i){let t=e.getSize();c+t.x>a&&(c=0,l+=u+r,u=0);let n=e.getOffset();this.offsetGraph(e,c+n.x,l+n.y),n.x=0,n.y=0,d=Math.max(d,c+t.x),u=Math.max(u,t.y),c+=t.x+r}if(n.getSize().x=d,n.getSize().y=l+u,t[0].getProperty(qa)){let e=new to;e.compact(t,n.getSize(),r);for(let n of t){let t=n.getOffset();t.x=e.getOffset().x,t.y=e.getOffset().y}let i=n.getSize();i.x=e.getGraphSize().x,i.y=e.getGraphSize().y}for(let e of i)this.moveGraph(n,e,0,0)}moveGraph(e,t,n,r){let i=n+t.getOffset().x,a=r+t.getOffset().y,o=/* @__PURE__ */ new Set;for(let n of t.getLayerlessNodes()){n.position.x+=i,n.position.y+=a;for(let e of n.getPorts())for(let t of e.getConnectedEdges())if(!o.has(t)){o.add(t);for(let e of t.getBendPoints())e.x+=i,e.y+=a}e.getLayerlessNodes().push(n),n.setGraph(e)}t.getOffset().x=0,t.getOffset().y=0}offsetGraph(e,t,n){let r=/* @__PURE__ */ new Set;for(let i of e.getLayerlessNodes()){i.position.x+=t,i.position.y+=n;for(let e of i.getPorts())for(let i of e.getConnectedEdges())if(!r.has(i)){r.add(i);for(let e of i.getBendPoints())e.x+=t,e.y+=n}}}};function bo(t){let n=2**53-1;for(let r of t.getLayerlessNodes())r.hasProperty(e.cr)&&(n=Math.min(n,r.getProperty(e.cr)));return n}function xo(e){let t=1/0,n=1/0,r=-1/0,i=-1/0;for(let a of e.getLayerlessNodes()){let e=a.getMargin(),o=a.position.x-e.left,s=a.position.y-e.top,c=a.position.x+a.size.x+e.right,l=a.position.y+a.size.y+e.bottom;for(let e of a.getPorts()){let t=e.getPosition(),n=e.getSize();o=Math.min(o,a.position.x+t.x),s=Math.min(s,a.position.y+t.y),c=Math.max(c,a.position.x+t.x+n.x),l=Math.max(l,a.position.y+t.y+n.y)}t=Math.min(t,o),n=Math.min(n,s),r=Math.max(r,c),i=Math.max(i,l)}Number.isFinite(t)&&(e.getSize().x=Math.max(e.getSize().x,r-t),e.getSize().y=Math.max(e.getSize().y,i-n))}const So=.001;function Co(t){let n=t.getProperty(e.hn),r=t.getProperty(e.In);if(r==null)return;let i=/* @__PURE__ */ new Set;for(let[a,o]of r){let r=[...o].sort((e,n)=>oa(e,n,t));if(r.length===0)continue;let s=r[0].getActualSource(),c=r[r.length-1].getActualTarget();if(s===null||c===null)continue;let l=s.getNode(),u;u=l===c.getNode()?l.getGraph()?.getParentNode()??null:zi(l,c.getNode());let d;if(u!==null)d=u.getNestedGraph();else for(d=l.getGraph();d.getParentNode()!==null;)d=d.getParentNode().getGraph();let f=wo(a,r);a.getBendPoints().length=0;let p=null;for(let o of r){let r=o.getGraph().getAllNodes().some(e=>e.getType()===`NORMAL`)?To(o.getGraph(),d):Hi(o.getGraph(),d),s=o.getNewEdge(),l=s.getBendPoints().map(e=>({x:e.x+r.x,y:e.y+r.y})),u=o.getGraph(),m=To(u,d),h=Hi(u,d),g=s.getSource().getNode(),_=s.getTarget().getNode(),v=t.getProperty(e.q)===`INCLUDE_CHILDREN`,y=t.getProperty(e.F),b=t=>{if(t===null||t.getType()!==`EXTERNAL_PORT`)return!1;let n=t.getProperty(e.Un);return y===`DOWN`||y===`UP`?n===`NORTH`||n===`SOUTH`:n===`WEST`||n===`EAST`},x=e=>e!==null&&e.getType()===`EXTERNAL_PORT`?v&&b(e)?m:h:m,S=x(g),C=x(_),w=s.getSource().getAbsoluteAnchor(),ee=s.getTarget().getAbsoluteAnchor(),te={x:w.x+S.x,y:w.y+S.y},T={x:ee.x+C.x,y:ee.y+C.y};if(p!==null){let e=l.length>0?l[0]:T,t=Math.abs(p.x-e.x)>So,r=Math.abs(p.y-e.y)>So;(!n&&t&&r||n&&(t||r))&&a.getBendPoints().push({...te})}if(a.getBendPoints().push(...l),p=l.length>0?l[l.length-1]:te,f!==null){let t=s.getProperty(e.nt);if(t!=null)for(let e of t)f.push({x:e.x+r.x,y:e.y+r.y})}if(o.getActualTarget()===c){let t=c.getNode(),n=t.getGraph(),r=t.getType()===`EXTERNAL_PORT`?Hi(n,d):To(n,d);a.setProperty(e.Ar,r)}for(let e of[...s.getLabels()])e.position.x+=r.x,e.position.y+=r.y,a.getLabels().push(e);s.getLabels().length=0,i.add(s)}a.setSource(s),a.setTarget(c)}for(let e of i)e.setSource(null),e.setTarget(null)}function wo(t,n){let r=n.some(t=>{let n=t.getNewEdge().getProperty(e.nt);return n!=null&&n.length>0}),i=t.getProperty(e.nt);return r?i==null?(i=[],t.setProperty(e.nt,i)):i.length=0:i!=null&&(t.setProperty(e.nt,null),i=null),i}function To(e,t){let n={x:0,y:0},r=e;for(;r!==null&&r!==t;){let e=r.getParentNode();if(e===null)break;n.x+=e.position.x,n.y+=e.position.y,r=e.getGraph()}return n}const Eo=/* @__PURE__ */ new WeakMap;var Do=class{process(t){let n=[],r=[...t.getLayerlessNodes()];for(let e of r)if(this.isRelevantNode(e)){this.hide(e),n.push(e);let r=t.getLayerlessNodes().indexOf(e);r!==-1&&t.getLayerlessNodes().splice(r,1)}n.length>0&&t.setProperty(e.Jn,n)}isRelevantNode(e){let t=e.getLayerConstraint();return t===`FIRST_SEPARATE`||t===`LAST_SEPARATE`}hide(e){this.ensureNoInacceptableEdges(e);for(let t of[...e.getConnectedEdges()])this.hideEdge(e,t)}hideEdge(t,n){let r=n.getSource().getNode()===t,i=r?n.getTarget():n.getSource();r?n.setTarget(null):n.setSource(null),n.setProperty(e.pr,i),this.updateOppositeNodeLayerConstraints(t,i.getNode())}updateOppositeNodeLayerConstraints(e,t){if(t.getLayerConstraint()!==null)return;let n=Eo.get(t)??`NONE`,r=e.getLayerConstraint()??`NONE`,i=this.combine(n,r);if(Eo.set(t,i),!(t.getConnectedEdges().length>0))switch(i){case`FIRST_SEPARATE`:t.setLayerConstraint(`FIRST`);break;case`LAST_SEPARATE`:t.setLayerConstraint(`LAST`)}}combine(e,t){return e===`NONE`?t===`FIRST_SEPARATE`?`FIRST_SEPARATE`:`LAST_SEPARATE`:e===`FIRST_SEPARATE`?t===`FIRST_SEPARATE`?`FIRST_SEPARATE`:`BOTH`:e===`LAST_SEPARATE`?t===`FIRST_SEPARATE`?`BOTH`:`LAST_SEPARATE`:`BOTH`}ensureNoInacceptableEdges(e){let t=e.getLayerConstraint();if(t===`FIRST_SEPARATE`){for(let t of e.getIncomingEdges())if(!this.isAcceptableIncidentEdge(t))throw Error(`FIRST_SEPARATE node must not have incoming edges`)}else if(t===`LAST_SEPARATE`){for(let t of e.getOutgoingEdges())if(!this.isAcceptableIncidentEdge(t))throw Error(`LAST_SEPARATE node must not have outgoing edges`)}}isAcceptableIncidentEdge(e){let t=e.getSource().getNode(),n=e.getTarget().getNode();return t!==null&&n!==null&&t.getType()===`EXTERNAL_PORT`&&n.getType()===`EXTERNAL_PORT`}};function Oo(t){let n=t.getLayers();if(n.length>0){let e=n[0],r=n[n.length-1];ko(t,e,r)}let r=t.getProperty(e.Jn);if(r!==void 0&&r.length>0){let e=new w(t),i=new w(t);Ao(r,e,i),e.getNodes().length>0&&n.unshift(e),i.getNodes().length>0&&n.push(i)}for(let e=n.length-1;e>=0;e--)n[e].getNodes().length===0&&n.splice(e,1)}function ko(e,t,n){for(let r of[...e.getLayers()])for(let e of[...r.getNodes()]){let r=e.getLayerConstraint();r===`FIRST`?e.setLayer(t):r===`LAST`&&e.setLayer(n)}let r=e.getLayers();for(let e=r.length-1;e>=0;e--)r[e].getNodes().length===0&&r.splice(e,1)}function Ao(t,n,r){for(let i of t){let t=i.getLayerConstraint();t===`FIRST_SEPARATE`?i.setLayer(n):t===`LAST_SEPARATE`&&i.setLayer(r);for(let t of i.getConnectedEdges()){if(t.getSource()!==null&&t.getTarget()!==null)continue;let n=t.getTarget()===null,r=t.getProperty(e.pr);n?t.setTarget(r):t.setSource(r)}}}var jo=class{start=0;end=0;nodes=[]};function Mo(e,t){let n=[];for(let t of e.getLayerlessNodes()){let e=t.getPosition().x,r=Math.max(e+1,t.getPosition().x+t.size.x),i=null,a=0;for(;a<n.length;a++){let o=n[a];if(o.start>=r)break;o.end>e&&(i===null?(o.nodes.push(t),o.start=Math.min(o.start,e),o.end=Math.max(o.end,r),i=o):(i.nodes.push(...o.nodes),i.end=Math.max(i.end,o.end),n.splice(a,1),a--))}if(i===null){let i=new jo;i.start=e,i.end=r,i.nodes.push(t),n.splice(a,0,i)}}let r=e.getLayers(),i=0;for(let t of n){let n=new w(e);n.id=i++,r.push(n);for(let e of t.nodes)e.setLayer(n),e.id=0}for(let t of e.getLayerlessNodes()){if(t.id!==0)continue;let n=No(t,e);for(;n.size>0;){let t=n.values().next().value;n.delete(t);for(let r of No(t,e))n.add(r)}}for(let e=r.length-1;e>=0;e--)r[e].getNodes().length===0&&r.splice(e,1);e.getLayerlessNodes().length=0}function No(e,t){e.id=1;let n=e.getLayer(),r=/* @__PURE__ */ new Set;for(let i of e.getPorts(`OUTPUT`))for(let a of i.getOutgoingEdges()){let i=a.getTarget().getNode();if(i===e)continue;let o=i.getLayer();if(o!==null&&n!==null&&o.id<=n.id){let e=n.id+1,a;e===t.getLayers().length?(a=new w(t),a.id=e,t.getLayers().push(a)):a=t.getLayers()[e],i.setLayer(a),r.add(i)}}return r}var Po=class{sources=[];visited=[];active=[];edgesToBeReversed=[];process(t,n){n.begin(`Depth-first cycle removal`,1);let r=t.getLayerlessNodes(),i=r.length;this.sources=[],this.visited=Array(i).fill(!1),this.active=Array(i).fill(!1),this.edgesToBeReversed=[];let a=0;for(let e of r)e.id=a,e.getIncomingEdges().length===0&&this.sources.push(e),a++;for(let e of this.sources)this.dfs(e);for(let e=0;e<i;e++)this.visited[e]||this.dfs(r[e]);for(let n of this.edgesToBeReversed)n.reverse(t,!0),t.setProperty(e.Ln,!0);this.sources=[],this.visited=[],this.active=[],this.edgesToBeReversed=[],n.done()}dfs(e){if(!this.visited[e.id]){this.visited[e.id]=!0,this.active[e.id]=!0;for(let t of e.getOutgoingEdges()){if(t.isSelfLoop())continue;let e=t.getTarget().getNode();this.active[e.id]?this.edgesToBeReversed.push(t):this.dfs(e)}this.active[e.id]=!1}}},Fo=class{sources=/* @__PURE__ */ new Set;sinks=/* @__PURE__ */ new Set;visited=[];bfsQueue=[];edgesToBeReversed=[];graph=null;process(t,n){n.begin(`Breadth-first cycle removal`,1),this.graph=t;let r=t.getLayerlessNodes();this.bfsQueue=[],this.sources=/* @__PURE__ */ new Set,this.sinks=/* @__PURE__ */ new Set,this.visited=Array(r.length).fill(!1),this.edgesToBeReversed=[];let i=0;for(let e of r)e.id=i,e.getIncomingEdges().length===0&&this.sources.add(e),e.getOutgoingEdges().length===0&&this.sinks.add(e),i++;for(let e of this.sources)this.bfsQueue.push(e),this.bfsLoop();this.bfsLoop();let a=!0;for(;a;){a=!1;for(let e=0;e<r.length;e++)if(!this.visited[e]){this.bfsQueue.push(r[e]),a=!0;break}this.bfsLoop()}for(let n of this.edgesToBeReversed)n.reverse(t,!0),t.setProperty(e.Ln,!0);this.sources=/* @__PURE__ */ new Set,this.visited=[],this.bfsQueue=[],this.edgesToBeReversed=[],n.done()}bfsLoop(){for(;this.bfsQueue.length>0;)this.bfs(this.bfsQueue.shift())}bfs(t){if(this.visited[t.id])return;this.visited[t.id]=!0;let n=/* @__PURE__ */ new Map,r=this.graph.getProperty(e.b)===`ENFORCED`;for(let i of t.getOutgoingEdges()){let t=i.getTarget().getNode();if(!t.hasProperty(e.cr))n.set(2147483647-n.size,[i]);else{let a=0;a=r?this.graph.getProperty(e.sr)*t.getProperty(e.w)+t.getProperty(e.cr):t.getProperty(e.cr);let o=n.get(a);o===void 0?n.set(a,[i]):o.push(i)}}let i=[...n.keys()].sort((e,t)=>e-t);for(let e of i){let r=n.get(e),i=r[0];if(i.isSelfLoop())continue;let a=i.getTarget().getNode();this.visited[a.id]&&!this.sources.has(t)&&!this.sinks.has(a)?this.edgesToBeReversed.push(...r):this.bfsQueue.push(a)}}},Io=class{sources=[];visited=[];active=[];edgesToBeReversed=[];graph=null;process(t,n){n.begin(`Depth-first cycle removal`,1),this.graph=t;let r=t.getLayerlessNodes(),i=r.length;this.sources=[],this.visited=Array(i).fill(!1),this.active=Array(i).fill(!1),this.edgesToBeReversed=[];let a=0;for(let e of r)e.id=a,e.getIncomingEdges().length===0&&this.sources.push(e),a++;for(let e of this.sources)this.dfs(e);for(let e=0;e<i;e++)this.visited[e]||this.dfs(r[e]);for(let n of this.edgesToBeReversed)n.reverse(t,!0),t.setProperty(e.Ln,!0);this.sources=[],this.visited=[],this.active=[],this.edgesToBeReversed=[],n.done()}dfs(t){if(this.visited[t.id])return;this.visited[t.id]=!0,this.active[t.id]=!0;let n=/* @__PURE__ */ new Map,r=this.graph.getProperty(e.b)===`ENFORCED`;for(let i of t.getOutgoingEdges()){let t=i.getTarget().getNode();if(!t.hasProperty(e.cr))n.set(2147483647-n.size,[i]);else{let a=0;a=r?this.graph.getProperty(e.sr)*t.getProperty(e.w)+t.getProperty(e.cr):t.getProperty(e.cr);let o=n.get(a);o===void 0?n.set(a,[i]):o.push(i)}}let i=[...n.keys()].sort((e,t)=>e-t);for(let e of i){let t=n.get(e),r=t[0];if(r.isSelfLoop())continue;let i=r.getTarget().getNode();this.active[i.id]?this.edgesToBeReversed.push(...t):this.dfs(i)}this.active[t.id]=!1}},Lo=class{edgesToBeReversed;stronglyConnectedComponents;nodeToSCCID;index=0;stack=[];tarjanId=/* @__PURE__ */ new Map;tarjanLowlink=/* @__PURE__ */ new Map;tarjanOnStack=/* @__PURE__ */ new Map;constructor(e,t,n){this.edgesToBeReversed=e,this.stronglyConnectedComponents=t,this.nodeToSCCID=n}tarjan(e){this.index=0,this.stack=[];for(let t of e.getLayerlessNodes())(this.tarjanId.get(t)??-1)===-1&&(this.stronglyConnected(t),this.stack.length=0)}stronglyConnected(e){this.tarjanId.set(e,this.index),this.tarjanLowlink.set(e,this.index),this.index++,this.stack.push(e),this.tarjanOnStack.set(e,!0);for(let t of e.getConnectedEdges()){if(t.getSource().getNode()!==e&&!this.edgesToBeReversed.includes(t)||t.getSource().getNode()===e&&this.edgesToBeReversed.includes(t))continue;let n=t.getTarget().getNode()===e?t.getSource().getNode():t.getTarget().getNode();(this.tarjanId.get(n)??-1)===-1?(this.stronglyConnected(n),this.tarjanLowlink.set(e,Math.min(this.tarjanLowlink.get(e),this.tarjanLowlink.get(n)))):this.tarjanOnStack.get(n)&&this.tarjanLowlink.set(e,Math.min(this.tarjanLowlink.get(e),this.tarjanId.get(n)))}if(this.tarjanLowlink.get(e)===this.tarjanId.get(e)){let t=/* @__PURE__ */ new Set,n;do n=this.stack.pop(),this.tarjanOnStack.set(n,!1),t.add(n);while(e!==n);if(t.size>1){let e=this.stronglyConnectedComponents.length;this.stronglyConnectedComponents.push(t);for(let n of t)this.nodeToSCCID.set(n,e)}}}resetTarjan(e){for(let t of e.getLayerlessNodes())this.tarjanOnStack.set(t,!1),this.tarjanLowlink.set(t,-1),this.tarjanId.set(t,-1),this.stack.length=0}},Ro=class{stronglyConnectedComponents=[];nodeToSCCID=/* @__PURE__ */ new Map;revEdges=[];graph=null;process(t,n){if(n.begin(`Model order cycle breaking`,1),this.graph=t,this.revEdges=[],!t.hasProperty(e.sr))throw TypeError(`Cannot invoke "java.lang.Integer.intValue()" because the return value of "org.eclipse.elk.alg.layered.graph.LGraph.getProperty(org.eclipse.elk.graph.properties.IProperty)" is null`);let r=Math.max(t.getLayerlessNodes().length,t.getProperty(e.sr)),i=r*t.getProperty(e.jn);for(;;){let n=new Lo(this.revEdges,this.stronglyConnectedComponents,this.nodeToSCCID);if(n.resetTarjan(t),n.tarjan(t),this.stronglyConnectedComponents.length===0)break;this.findNodes(r,i);for(let n of this.revEdges)n.reverse(t,!1),t.setProperty(e.Ln,!0);this.stronglyConnectedComponents.length=0,this.nodeToSCCID.clear(),this.revEdges.length=0}n.done()}findNodes(t,n){for(let r=0;r<this.stronglyConnectedComponents.length;r++){let i=this.stronglyConnectedComponents[r],a=null,o=new y,s=-(2**53-1),c=this.graph.getProperty(e.b)===`ENFORCED`;for(let e of i)if(a===null)a=e,s=c?o.computeConstraintGroupModelOrder(e,n,t):o.computeConstraintModelOrder(e,t);else{let r=c?o.computeConstraintGroupModelOrder(e,n,t):o.computeConstraintModelOrder(e,t);s<r&&(a=e,s=r)}for(let e of a.getOutgoingEdges())i.has(e.getTarget().getNode())&&this.revEdges.push(e)}}},zo=class extends Ro{findNodes(t,n){for(let r=0;r<this.stronglyConnectedComponents.length;r++){let i=this.stronglyConnectedComponents[r];if(i.size<=1)continue;let a=null,o=null,s=2**53-1,c=-(2**53-1),l=this.graph.getProperty(e.b)===`ENFORCED`,u=new y;for(let e of i)if(a===null||o===null)a=e,s=l?u.computeConstraintGroupModelOrder(e,n,t):u.computeConstraintModelOrder(e,t),o=e,c=s;else{let r=l?u.computeConstraintGroupModelOrder(e,n,t):u.computeConstraintModelOrder(e,t);s>r&&(a=e,s=r),c<r&&(o=e,c=r)}let d=a.getIncomingEdges(),f=o.getOutgoingEdges();if(d.length>f.length)for(let e of d)i.has(e.getSource().getNode())&&this.revEdges.push(e);else for(let e of f)i.has(e.getTarget().getNode())&&this.revEdges.push(e)}}};const Bo=new e.ai(`org.eclipse.elk.layered.considerModelOrder.groupModelOrder.cbPreferredSourceId`,0),Vo=new e.ai(`org.eclipse.elk.layered.considerModelOrder.groupModelOrder.cbPreferredTargetId`,0);var Ho=class extends Ro{findNodes(t,n){for(let r=0;r<this.stronglyConnectedComponents.length;r++){let i=this.stronglyConnectedComponents[r];if(i.size<=1)continue;let a=null,o=null,s=2**53-1,c=-(2**53-1),l=this.graph.getProperty(e.b)===`ENFORCED`,u=new y;for(let e of i)if(a===null||o===null)a=e,s=l?u.computeConstraintGroupModelOrder(e,n,t):u.computeConstraintModelOrder(e,t),o=e,c=s;else{let r=l?u.computeConstraintGroupModelOrder(e,n,t):u.computeConstraintModelOrder(e,t);s>r&&(a=e,s=r),c<r&&(o=e,c=r)}let d=this.graph.getProperty(Bo),f=this.graph.getProperty(Vo);if(a.getProperty(e.w)===d)for(let e of a.getIncomingEdges())i.has(e.getSource().getNode())&&this.revEdges.push(e);else if(o.getProperty(e.w)===f)for(let e of o.getOutgoingEdges())i.has(e.getSource().getNode())&&this.revEdges.push(e);else{let e=a.getIncomingEdges(),t=o.getOutgoingEdges();if(e.length>t.length)for(let t of e)i.has(t.getSource().getNode())&&this.revEdges.push(t);else for(let e of t)i.has(e.getTarget().getNode())&&this.revEdges.push(e)}}}},Uo=class{compare;heap=[];constructor(e){this.compare=e}isEmpty(){return this.heap.length===0}push(e){this.heap.push(e),this.siftUp(this.heap.length-1)}poll(){if(this.heap.length===0)return;let e=this.heap[0],t=this.heap.pop();return this.heap.length>0&&(this.heap[0]=t,this.siftDown(0)),e}siftUp(e){let t=this.heap[e];for(;e>0;){let n=e-1>>1,r=this.heap[n];if(this.compare(t,r)>=0)break;this.heap[e]=r,e=n}this.heap[e]=t}siftDown(e){let t=this.heap.length,n=this.heap[e];for(;;){let r=2*e+1;if(r>=t)break;let i=this.heap[r],a=r+1;if(a<t){let e=this.heap[a];this.compare(i,e)>0&&(r=a,i=e)}if(this.compare(n,i)<=0)break;this.heap[e]=i,e=r}this.heap[e]=n}},Wo=class{nodeMark=[];edgeMark=[];inDeg=[];outDeg=[];topoOrd=[];inTopo=/* @__PURE__ */ new Map;process(t,n){if(n.begin(`Coffman-Graham Layering`,1),t.getLayerlessNodes().length===0){n.done();return}let r=t.getProperty(e.rt),i=0,a=0;for(let e of t.getLayerlessNodes()){e.id=i++;for(let t of e.getOutgoingEdges())t.id=a++}this.nodeMark=Array(i).fill(!1),this.edgeMark=Array(a).fill(!1),this.inDeg=Array(i).fill(0),this.outDeg=Array(i).fill(0),this.topoOrd=Array(i).fill(0),this.inTopo.clear(),this.transitiveReduction(t);let o=new Uo((e,t)=>this.compareNodesInTopo(e,t));for(let e of t.getLayerlessNodes()){for(let t of e.getIncomingEdges())this.edgeMark[t.id]||this.inDeg[e.id]++;this.inDeg[e.id]===0&&o.push(e)}let s=0;for(;!o.isEmpty();){let e=o.poll();this.topoOrd[e.id]=s++;for(let t of e.getOutgoingEdges()){if(this.edgeMark[t.id])continue;let n=t.getTarget().getNode();this.inDeg[n.id]--;let r=this.inTopo.get(n)??[];r.push(this.topoOrd[e.id]),this.inTopo.set(n,r),this.inDeg[n.id]===0&&o.push(n)}}let c=new Uo((e,t)=>{let n=this.topoOrd[e.id],r=this.topoOrd[t.id];return n>r?-1:+(n<r)});for(let e of t.getLayerlessNodes()){for(let t of e.getOutgoingEdges())this.edgeMark[t.id]||this.outDeg[e.id]++;this.outDeg[e.id]===0&&c.push(e)}let l=[],u=this.createLayer(t,l);for(;!c.isEmpty();){let e=c.poll();(this.isLayerFull(u,r)||!this.canAdd(e,u))&&(u=this.createLayer(t,l)),e.setLayer(u);for(let t of e.getIncomingEdges()){if(this.edgeMark[t.id])continue;let e=t.getSource().getNode();this.outDeg[e.id]--,this.outDeg[e.id]===0&&c.push(e)}}for(let e=l.length-1;e>=0;--e)t.getLayers().push(l[e]);t.getLayerlessNodes().length=0,n.done()}isLayerFull(e,t){return e.getNodes().length>=t}canAdd(e,t){for(let n of e.getOutgoingEdges())if(n.getTarget().getNode().getLayer()===t)return!1;return!0}createLayer(e,t){let n=new w(e);return t.push(n),n}compareNodesInTopo(e,t){let n=this.inTopo.get(e)??[],r=this.inTopo.get(t)??[],i=n.length-1,a=r.length-1;for(;i>=0&&a>=0;){let e=n[i],t=r[a];if(e!==t)return e<t?-1:1;i--,a--}return n.length===0&&r.length===0?e.id<t.id?-1:+(e.id>t.id):n.length===0?-1:1}transitiveReduction(e){for(let t of e.getLayerlessNodes()){this.nodeMark.fill(!1);for(let e of t.getOutgoingEdges())this.dfs(t,e.getTarget().getNode())}}dfs(e,t){if(!this.nodeMark[t.id]){for(let n of t.getOutgoingEdges()){let t=n.getTarget().getNode();for(let n of t.getIncomingEdges())n.getSource().getNode()===e&&(this.edgeMark[n.id]=!0);this.dfs(e,t)}this.nodeMark[t.id]=!0}}},Go=class{layeredGraph;process(t,n){n.begin(`Breadth first model order layering`,1),this.layeredGraph=t;let r=[];for(let e of this.layeredGraph.getLayerlessNodes())e.getType()===`NORMAL`&&r.push(e);r.sort((t,n)=>{if(t.hasProperty(e.cr)&&n.hasProperty(e.cr))return t.getProperty(e.cr)-n.getProperty(e.cr);throw Error(`The BF model order layer assigner requires all real nodes to have a model order.`)});let i=!0,a=new w(this.layeredGraph),o=null;this.layeredGraph.getLayers().push(a);for(let e of r)if(i)e.setLayer(a),i=!1;else{for(let t of e.getIncomingEdges())(t.getSource().getNode().getType()===`NORMAL`&&t.getSource().getNode().getLayer()===a||t.getSource().getNode().getType()===`LABEL`&&t.getSource().getNode().getIncomingEdges()[0].getSource().getNode().getLayer()===a)&&(o=new w(this.layeredGraph),this.layeredGraph.getLayers().push(o),a=new w(this.layeredGraph),this.layeredGraph.getLayers().push(a));for(let t of e.getIncomingEdges())t.getSource().getNode().getType()===`LABEL`&&t.getSource().getNode().getLayer()===null&&t.getSource().getNode().setLayer(o);e.setLayer(a)}this.layeredGraph.getLayerlessNodes().length=0;let s=[];for(let e of this.layeredGraph.getLayers())e.getNodes().length===0&&s.push(e);for(let e of s){let t=this.layeredGraph.getLayers().indexOf(e);t!==-1&&this.layeredGraph.getLayers().splice(t,1)}let c=0;for(let e of this.layeredGraph.getLayers())e.id=c,c++;n.done()}},Ko=class{layeredGraph;currentLayer;currentLayerId=0;currentDummyLayer=null;nodesToPlace=[];maxToPlace=0;process(t,n){n.begin(`Depth first model order layering`,1),this.layeredGraph=t;let r=[];for(let e of this.layeredGraph.getLayerlessNodes())e.getType()===`NORMAL`&&r.push(e);r.sort((t,n)=>{if(t.hasProperty(e.cr)&&n.hasProperty(e.cr))return t.getProperty(e.cr)-n.getProperty(e.cr);throw Error(`The DF model order layer assigner requires all real nodes to have a model order.`)});let i=!0;this.currentLayer=new w(this.layeredGraph),this.currentDummyLayer=null,this.layeredGraph.getLayers().push(this.currentLayer),this.currentLayer.id=0,this.currentLayerId=0,this.nodesToPlace=[];for(let e of r)if(i)e.setLayer(this.currentLayer),i=!1;else if(this.isConnectedToCurrentLayer(e)){let t=this.currentLayerId;t=this.getMaxConnectedLayer(t,e);let n=t+2,r=t-this.currentLayerId;if(this.nodesToPlace.length>0){if(r>0){for(let e of this.nodesToPlace)e.id+=t-this.maxToPlace;this.placeNodesToPlace(),this.nodesToPlace=[],this.addNodeToLayer(n,e)}else{this.nodesToPlace.push(e),e.id=n,this.maxToPlace=Math.max(this.maxToPlace,n);for(let t of e.getIncomingEdges())t.getSource().getNode().getLayer()===null&&t.getSource().getNode().getType()===`LABEL`&&(this.nodesToPlace.push(t.getSource().getNode()),t.getSource().getNode().id=n-1);this.currentLayerId=n}}else this.addNodeToLayer(n,e)}else{this.placeNodesToPlace(),this.nodesToPlace=[];let t=0;if(e.getIncomingEdges().length===0)this.nodesToPlace.push(e),e.id=0,this.maxToPlace=Math.max(this.maxToPlace,0),this.currentLayer=this.layeredGraph.getLayers()[0],this.currentLayerId=0;else{let n=0;n=this.getMaxConnectedLayer(n,e),t=n+2,this.addNodeToLayer(t,e)}}this.nodesToPlace.length>0&&this.placeNodesToPlace(),this.layeredGraph.getLayerlessNodes().length=0;let a=[];for(let e of this.layeredGraph.getLayers())e.getNodes().length===0&&a.push(e);for(let e of a){let t=this.layeredGraph.getLayers().indexOf(e);t!==-1&&this.layeredGraph.getLayers().splice(t,1)}let o=0;for(let e of this.layeredGraph.getLayers())e.id=o,o++;n.done()}isConnectedToCurrentLayer(e){for(let t of e.getIncomingEdges()){let e,n;if(this.nodesToPlace.length===0){if(e=t.getSource().getNode().getType()===`NORMAL`&&t.getSource().getNode().getLayer()!==null&&t.getSource().getNode().getLayer().id===this.currentLayerId,t.getSource().getNode().getIncomingEdges().length>0){let e=t.getSource().getNode().getIncomingEdges()[0].getSource().getNode().getLayer();n=t.getSource().getNode().getType()===`LABEL`&&e!==null&&e.id===this.currentLayerId}else n=!1}else e=t.getSource().getNode().getType()===`NORMAL`&&t.getSource().getNode().id===this.currentLayerId,n=t.getSource().getNode().getType()===`LABEL`&&t.getSource().getNode().getIncomingEdges()[0].getSource().getNode().id===this.currentLayerId;if(e||n)return!0}return!1}addNodeToLayer(e,t){e<this.layeredGraph.getLayers().length?(this.currentLayer=this.layeredGraph.getLayers()[e],this.currentDummyLayer=this.layeredGraph.getLayers()[e-1],this.currentLayerId=e):(this.currentDummyLayer=new w(this.layeredGraph),this.currentDummyLayer.id=e-1,this.layeredGraph.getLayers().push(this.currentDummyLayer),this.currentLayer=new w(this.layeredGraph),this.currentLayer.id=e,this.layeredGraph.getLayers().push(this.currentLayer),this.currentLayerId=e),t.setLayer(this.currentLayer);for(let e of t.getIncomingEdges())e.getSource().getNode().getLayer()===null&&e.getSource().getNode().getType()===`LABEL`&&e.getSource().getNode().setLayer(this.currentDummyLayer)}getMaxConnectedLayer(e,t){let n=e;for(let e of t.getIncomingEdges())e.getSource().getNode().getLayer()!==null&&(n=Math.max(n,e.getSource().getNode().getLayer().id));return n}placeNodesToPlace(){this.maxToPlace=0;for(let e of this.nodesToPlace){if(e.id>=this.layeredGraph.getLayers().length){let t=new w(this.layeredGraph);t.id=e.id-1,this.layeredGraph.getLayers().push(t);let n=new w(this.layeredGraph);n.id=e.id,this.layeredGraph.getLayers().push(n)}e.setLayer(this.layeredGraph.getLayers()[e.id])}}},qo=class t{static UPPERBOUND_ON_WIDTH_RANGE={lower:1,upper:4};static COMPENSATOR_RANGE={lower:1,upper:2};dummySize=0;minimumNodeSize=0;normSize=[];avgSize=0;inDegree=[];outDegree=[];lastMaxWidth=0;process(n,r){r.begin(`MinWidth layering`,1);let i=n.getLayers(),a=n.getLayerlessNodes(),o=n.getProperty(e.ot),s=n.getProperty(e.st);this.dummySize=n.getProperty(e.$t),this.minimumNodeSize=1/0;for(let e of a){if(e.getType()!==`NORMAL`)continue;let t=e.getSize().y;this.minimumNodeSize=Math.min(this.minimumNodeSize,t)}this.minimumNodeSize=Math.max(1,this.minimumNodeSize);let c=a.length;this.inDegree=Array(c).fill(0),this.outDegree=Array(c).fill(0),this.normSize=Array(c).fill(0);let l=0;this.avgSize=0;for(let e of a)e.id=l++,this.inDegree[e.id]=this.countEdgesExceptSelfLoops(e.getIncomingEdges()),this.outDegree[e.id]=this.countEdgesExceptSelfLoops(e.getOutgoingEdges()),this.normSize[e.id]=e.getSize().y/this.minimumNodeSize,this.avgSize+=this.normSize[e.id];this.dummySize/=this.minimumNodeSize,this.avgSize/=c;let u=this.precalcSuccessors(a);a.sort((e,t)=>{let n=this.outDegree[e.id],r=this.outDegree[t.id];return n<r?1:n===r?0:-1});let d=1/0,f=2**53-1,p=null,m=o,h=o,g=s,_=s;o<0&&(m=t.UPPERBOUND_ON_WIDTH_RANGE.lower,h=t.UPPERBOUND_ON_WIDTH_RANGE.upper),s<0&&(g=t.COMPENSATOR_RANGE.lower,_=t.COMPENSATOR_RANGE.upper);for(let e=m;e<=h;e++)for(let t=g;t<=_;t++){let n=this.computeMinWidthLayering(e,t,a,u),r=n.width,i=n.layers,o=i.length;(r<d||r===d&&o<f)&&(d=r,f=o,p=i)}for(let e of p){let t=new w(n);for(let n of e)n.setLayer(t);i.push(t)}this.lastMaxWidth=d,i.reverse(),a.length=0,r.done()}precalcSuccessors(e){let t=[];for(let n of e){let e=/* @__PURE__ */ new Set;for(let t of n.getOutgoingEdges())this.isSelfLoop(t)||e.add(t.getTarget().getNode());t.push(e)}return t}computeMinWidthLayering(e,t,n,r){let i=[],a=new Set(n),o=e*this.avgSize,s=0,c=0,l=/* @__PURE__ */ new Set,u=/* @__PURE__ */ new Set,d=[],f=0,p=0,m=0,h=0,g=0,_=0;for(;a.size>0;){let e=this.selectNode(a,r,u);if(e!==null&&(a.delete(e),d.push(e),l.add(e),c=this.outDegree[e.id],f+=this.normSize[e.id]-c*this.dummySize,s=this.inDegree[e.id],p+=s*this.dummySize,_+=c*this.dummySize,h+=this.normSize[e.id]),e===null||a.size===0||f>=o&&this.normSize[e.id]>c*this.dummySize||p>=t*o){i.push(d),d=[];for(let e of l)u.add(e);l.clear(),g-=_,m=Math.max(m,g*this.dummySize+h),g+=p,f=p,p=0,_=0,h=0}}return{width:m,layers:i}}selectNode(e,t,n){for(let r of e)if(this.containsAll(n,t[r.id]))return r;return null}containsAll(e,t){for(let n of t)if(!e.has(n))return!1;return!0}countEdgesExceptSelfLoops(e){let t=0;for(let n of e)this.isSelfLoop(n)||t++;return t}isSelfLoop(e){return e.getSource().getNode()===e.getTarget().getNode()}},Jo=class{widthCurrent=0;widthUp=0;maxWidth=0;currentGraph;upperLayerInfluence=0;sortedLayerlessNodes=[];alreadyPlacedNodes=/* @__PURE__ */ new Set;alreadyPlacedInOtherLayers=/* @__PURE__ */ new Set;tempLayerlessNodes=[];successors=[];outDegree=[];remainingOutGoing=[];inDegree=[];selectedNode=null;minimumNodeSize=0;maximumNodeSize=0;normSize=[];dummySize=0;process(t,n){if(n.begin(`StretchWidth layering`,1),t.getLayerlessNodes().length===0){n.done();return}this.currentGraph=t,this.widthCurrent=0,this.widthUp=0,this.minimumNodeSize=1/0,this.maximumNodeSize=-1/0,this.dummySize=t.getProperty(e.$t),this.computeSortedNodes(),this.computeSuccessors(),this.computeDegrees(),this.minMaxNodeSize(),this.computeNormalizedSize(),this.minimumNodeSize=Math.max(1,this.minimumNodeSize),this.maximumNodeSize=Math.max(1,this.maximumNodeSize),this.dummySize/=this.minimumNodeSize,this.maxWidth=this.maximumNodeSize/this.minimumNodeSize,this.upperLayerInfluence=this.getAverageOutDegree();let r=new w(this.currentGraph);for(this.currentGraph.getLayers().push(r),this.tempLayerlessNodes=[...this.sortedLayerlessNodes],this.remainingOutGoing=[...this.outDegree];this.tempLayerlessNodes.length>0;)if(this.selectedNode=this.selectNode(),this.selectedNode===null||this.conditionGoUp()&&this.alreadyPlacedNodes.size>0){this.updateOutGoing(r),r=new w(this.currentGraph),this.currentGraph.getLayers().push(r);for(let e of this.alreadyPlacedNodes)this.alreadyPlacedInOtherLayers.add(e);this.alreadyPlacedNodes.clear(),this.widthCurrent=this.widthUp,this.widthUp=0}else this.conditionGoUp()?(this.currentGraph.getLayers().length=0,r=new w(this.currentGraph),this.currentGraph.getLayers().push(r),this.widthCurrent=0,this.widthUp=0,this.alreadyPlacedNodes.clear(),this.alreadyPlacedInOtherLayers.clear(),this.maxWidth++,this.tempLayerlessNodes=[...this.sortedLayerlessNodes],this.remainingOutGoing=[...this.outDegree]):(this.selectedNode.setLayer(r),this.tempLayerlessNodes.splice(this.tempLayerlessNodes.indexOf(this.selectedNode),1),this.alreadyPlacedNodes.add(this.selectedNode),this.widthCurrent=this.widthCurrent-this.outDegree[this.selectedNode.id]*this.dummySize+this.normSize[this.selectedNode.id],this.widthUp+=this.inDegree[this.selectedNode.id]*this.dummySize);t.getLayerlessNodes().length=0,t.getLayers().reverse(),n.done()}conditionGoUp(){let e=this.widthCurrent-this.outDegree[this.selectedNode.id]*this.dummySize+this.normSize[this.selectedNode.id]>this.maxWidth,t=this.widthUp+this.inDegree[this.selectedNode.id]*this.dummySize>this.maxWidth*this.upperLayerInfluence*this.dummySize;return e||t}selectNode(){for(let e of this.tempLayerlessNodes)if(this.remainingOutGoing[e.id]<=0)return e;return null}computeSortedNodes(){let e=this.currentGraph.getLayerlessNodes();this.sortedLayerlessNodes=[...e];for(let t of e)t.id=this.getRank(t);this.sortedLayerlessNodes.sort((e,t)=>e.id<t.id?1:e.id>t.id?-1:0)}getRank(e){let t=e.getOutgoingEdges().length,n;for(let r of e.getIncomingEdges())n=r.getSource().getNode().getOutgoingEdges().length,t=Math.max(t,n);return t}computeSuccessors(){let e=0;this.successors=[];let t=/* @__PURE__ */ new Set;for(let n of this.sortedLayerlessNodes){n.id=e;for(let e of n.getOutgoingEdges())t.add(e.getTarget().getNode());t.delete(n),this.successors.push(new Set(t)),t.clear(),e++}}computeDegrees(){this.inDegree=Array(this.sortedLayerlessNodes.length).fill(0),this.outDegree=Array(this.sortedLayerlessNodes.length).fill(0);for(let e of this.sortedLayerlessNodes)this.inDegree[e.id]=e.getIncomingEdges().length,this.outDegree[e.id]=e.getOutgoingEdges().length}minMaxNodeSize(){for(let e of this.sortedLayerlessNodes){if(e.getType()!==`NORMAL`)continue;let t=e.getSize().y;this.minimumNodeSize=Math.min(this.minimumNodeSize,t),this.maximumNodeSize=Math.max(this.maximumNodeSize,t)}}avereageNodeSize(){let e=0;for(let t of this.sortedLayerlessNodes)e+=this.normSize[t.id];return e/this.sortedLayerlessNodes.length}computeNormalizedSize(){this.normSize=Array(this.sortedLayerlessNodes.length).fill(0);for(let e of this.sortedLayerlessNodes)this.normSize[e.id]=e.getSize().y/this.minimumNodeSize}getAverageOutDegree(){let e=0;for(let t of this.currentGraph.getLayerlessNodes())e+=t.getOutgoingEdges().length;return e/this.currentGraph.getLayerlessNodes().length}updateOutGoing(e){for(let t of e.getNodes())for(let e of t.getIncomingEdges()){let t=e.getSource().getNode().id;this.remainingOutGoing[t]=this.remainingOutGoing[t]-1}}};const Yo=new e.ai(`org.eclipse.elk.layered.nodePlacement.linearSegments.deflectionDampening`,.3);var Xo=class e{nodes=[];id;indexInLastLayer=-1;lastLayer=-1;deflection=0;weight=0;refSegment=null;nodeType=`NORMAL`;constructor(e){this.id=e}region(){let e=this;for(;e.refSegment!==null;)e=e.refSegment;return e}split(t,n,r){let i=this.nodes.indexOf(t),a=new e(n),o=this.nodes.splice(i);a.nodes.push(...o);for(let e of o)r.set(e,n);return a}};function Zo(t){let n=t.getProperty(e.wr),r=Qo(t),i=/* @__PURE__ */ new Map,a=$o(t,i);ns(t,a,n),rs(t,a,n,r,i),os(t,a,n)}function Qo(t){let n=/* @__PURE__ */ new Map;for(let r of t.getLayers())for(let t of r.getNodes()){let r=-(2**53-1),i=-(2**53-1);for(let n of t.getPorts()){for(let t of n.getIncomingEdges())r=Math.max(r,t.getProperty(e.Gt));for(let t of n.getOutgoingEdges())i=Math.max(i,t.getProperty(e.Gt))}n.set(t,{input:r,output:i})}return n}function $o(e,t){let n=[],r=0;for(let i of e.getLayers())for(let e of i.getNodes())if(!t.has(e)){let i=new Xo(r++);es(e,i,t),n.push(i)}let i=n.map(()=>[]),a=n.map(()=>0);ts(e,n,i,a,t);let o=[];for(let e=0;e<n.length;e++)a[e]===0&&o.push(n[e]);let s=Array(n.length),c=0;for(;o.length>0;){let e=o.shift();for(s[e.id]=c++;i[e.id].length>0;){let t=i[e.id].shift();a[t.id]--,a[t.id]===0&&o.push(t)}}let l=Array(n.length);for(let e=0;e<n.length;e++){let r=n[e],i=s[e];l[i]=r,r.id=i;for(let e of r.nodes)t.set(e,i)}return l}function es(e,t,n){let r=e.getType();if(n.has(e))return!1;if(n.set(e,t.id),t.nodes.push(e),t.nodeType=r,r===`LONG_EDGE`||r===`NORTH_SOUTH_PORT`)for(let r of e.getPorts())for(let i of r.getSuccessorPorts()){let r=i.getNode(),a=r.getType();if(e.getLayer()!==r.getLayer()&&(a===`LONG_EDGE`||a===`NORTH_SOUTH_PORT`)&&es(r,t,n))return!0}return!0}function ts(e,t,n,r,i){let a=t.length,o=0;for(let s of e.getLayers()){let e=s.getNodes();if(e.length===0)continue;let c=0,l=null,u=e[0],d=null;for(;u!==null;){if(d=t[i.get(u)],d.indexInLastLayer>=0){let o=null;for(let n=c+1;n<e.length;n++){let r=e[n],a=t[i.get(r)];if(a.lastLayer===d.lastLayer&&a.indexInLastLayer<d.indexInLastLayer){o=a;break}}if(o!==null){if(l!==null){let e=t[i.get(l)];r[d.id]--;let a=n[e.id],o=a.indexOf(d);o!==-1&&a.splice(o,1)}d=d.split(u,a++,i),t.push(d),n.push([]),l===null?r.push(0):(n[i.get(l)].push(d),r.push(1))}}let s=null;if(c+1<e.length){s=e[c+1];let a=t[i.get(s)];n[d.id].push(a),r[a.id]++}d.lastLayer=o,d.indexInLastLayer=c++,l=u,u=s}o++}}function ns(t,n,r){let i=t.getLayers().length,a=Array(i).fill(0),o=Array(i).fill(null);for(let i of n){let n=0;for(let s of i.nodes){let i=s.getLayer().getIndex();a[i]++;let c=t.getProperty(e.$t);a[i]>0&&o[i]!==null&&(c=r.getVerticalSpacing(o[i],s)),n=Math.max(n,s.getLayer().getSize().y+c)}for(let e of i.nodes){e.getPosition().y=n+e.getMargin().top;let t=e.getLayer();t.getSize().y=n+e.getMargin().top+e.getSize().y+e.getMargin().bottom,o[t.getIndex()]=e}}}function rs(t,n,r,i,a){let o=t.getProperty(Yo),s=t.getProperty(e.mn),c=4,l=3,u=20/s,d=!1,f=`FORW_PENDULUM`,p=2**53-1;do{let e=f!==`BACKW_PENDULUM`,m=f!==`FORW_PENDULUM`,h=0;for(let t of n)t.refSegment=null,is(t,n,e,m,o,i,a),h+=Math.abs(t.deflection);let g;do g=as(t,n,r,a);while(g);for(let e of n){let t=e.region().deflection;if(t!==0)for(let n of e.nodes)n.getPosition().y+=t}f===`FORW_PENDULUM`||f===`BACKW_PENDULUM`?(c--,c<=0&&(h<p||-c>s)?(f=`RUBBER`,p=2**53-1):f===`FORW_PENDULUM`?(f=`BACKW_PENDULUM`,p=h):(f=`FORW_PENDULUM`,p=h)):(d=h>=p||p-h<u,p=h,d&&l--)}while(!(d&&l<=0))}function is(t,n,r,i,a,o,s){let c=0,l=0;for(let a of t.nodes){let u=0,d=0,f=o.get(a),p=r?f.input:-(2**53-1),m=i?f.output:-(2**53-1),h=Math.max(p,m);for(let c of a.getPorts()){let l=a.getPosition().y+c.getPosition().y+c.getAnchor().y;if(i)for(let r of c.getOutgoingEdges()){let i=r.getTarget(),a=i.getNode();if(t!==n[s.get(a)]){let t=o.get(a),n=Math.max(t.input,t.output),s=r.getProperty(e.Gt);s>=h&&s>=n&&(u+=a.getPosition().y+i.getPosition().y+i.getAnchor().y-l,d++)}}if(r)for(let r of c.getIncomingEdges()){let i=r.getSource(),a=i.getNode();if(t!==n[s.get(a)]){let t=o.get(a),n=Math.max(t.input,t.output),s=r.getProperty(e.Gt);s>=h&&s>=n&&(u+=a.getPosition().y+i.getPosition().y+i.getAnchor().y-l,d++)}}}d>0&&(c+=u/d,l++)}l>0?(t.deflection=a*c/l,t.weight=l):(t.deflection=0,t.weight=0)}function as(t,n,r,i){let a=!1,o=1e-4*t.getProperty(e.ln);for(let e of t.getLayers()){let t=e.getNodes();if(t.length===0)continue;let s=t[0],c=n[i.get(s)].region();for(let e=1;e<t.length;e++){let l=t[e],u=n[i.get(l)].region();if(c!==u){let e=r.getVerticalSpacing(s,l);if(s.getPosition().y+s.getSize().y+s.getMargin().bottom+c.deflection+e>l.getPosition().y-l.getMargin().top+u.deflection+o){let e=c.weight+u.weight;e>0&&(u.deflection=(u.weight*u.deflection+c.weight*c.deflection)/e,u.weight=e,c.refSegment=u,a=!0)}}s=l,c=u}}return a}function os(e,t,n){for(let e of t){let t=2**53-1,r=2**53-1;for(let i of e.nodes){let e=i.getIndex(),a=i.getLayer().getNodes(),o,s;if(e>0){let t=a[e-1],r=n.getVerticalSpacing(i,t);o=i.getPosition().y-i.getMargin().top-(t.getPosition().y+t.getSize().y+t.getMargin().bottom+r)}else o=i.getPosition().y-i.getMargin().top;if(t=Math.min(o,t),e<a.length-1){let t=a[e+1],r=n.getVerticalSpacing(i,t);s=t.getPosition().y-t.getMargin().top-(i.getPosition().y+i.getSize().y+i.getMargin().bottom+r)}else s=2*i.getPosition().y;r=Math.min(s,r)}let i=2**53-1,a=!1,o=e.nodes[0];for(let e of o.getPorts()){let n=o.getPosition().y+e.getPosition().y+e.getAnchor().y;for(let o of e.getIncomingEdges()){let e=o.getSource(),s=e.getNode().getPosition().y+e.getPosition().y+e.getAnchor().y-n;Math.abs(s)<Math.abs(i)&&Math.abs(s)<(s<0?t:r)&&(i=s,a=!0)}}let s=e.nodes[e.nodes.length-1];for(let e of s.getPorts()){let n=s.getPosition().y+e.getPosition().y+e.getAnchor().y;for(let o of e.getOutgoingEdges()){let e=o.getTarget(),s=e.getNode().getPosition().y+e.getPosition().y+e.getAnchor().y-n;Math.abs(s)<Math.abs(i)&&Math.abs(s)<(s<0?t:r)&&(i=s,a=!0)}}if(a&&i!==0)for(let t of e.nodes)t.getPosition().y+=i}}function ss(t){let n=0;for(let r of t.getLayers()){let t=0,i=!1;for(let a of r.getNodes())a.getType()===`NORMAL`&&(i=!0,a.setProperty(e.at,n),a.setProperty(e.j,t),t++);i&&n++}}function cs(t){for(let n of t.getLayers())for(let r of n.getNodes()){if(!r.getProperty(e.Z)||r.getPorts().length>2)continue;let n=0,i=0,a=0,o=0;for(let e of r.getPorts())switch(e.getSide()){case`NORTH`:n++;break;case`EAST`:i++;break;case`SOUTH`:a++;break;case`WEST`:o++}n===0&&a===0&&ls(t,r,o<=i)}}function ls(t,n,r){let i=[],a=2**53-1,o=2**53-1,s=2**53-1;if(r){a=t.getSize().x;for(let e of n.getPorts())for(let t of e.getOutgoingEdges()){let e=t.getBendPoints();if(e.length===0)continue;let n=e[0];n.x<a&&(o=a-n.x,s=2**53-1,i.length=0,a=n.x),n.x<=a&&(i.push(t),e.length>1&&(s=Math.min(s,Math.abs(e[1].y-n.y))))}}else for(let e of n.getPorts())for(let t of e.getIncomingEdges()){let e=t.getBendPoints();if(e.length===0)continue;let n=e[e.length-1];n.x>a&&(o=n.x-a,s=2**53-1,i.length=0,a=n.x),n.x>=a&&(i.push(t),e.length>1&&(s=Math.min(s,Math.abs(e[e.length-2].y-n.y))))}if(i.length===0||o<=n.size.x/2||s<=n.size.y/2)return;let c=new p;c.setNode(n),c.setSide(`NORTH`),c.position.x=n.size.x/2;let l=new p;l.setNode(n),l.setSide(`SOUTH`),l.position.x=n.size.x/2,l.position.y=n.size.y;for(let t of i){let n,i;r?(n=t.getBendPoints().shift(),i=t.getBendPoints().length===0?t.getTarget().getAbsoluteAnchor():t.getBendPoints()[0],i.y>=n.y?t.setSource(l):t.setSource(c)):(n=t.getBendPoints().pop(),i=t.getBendPoints().length===0?t.getSource().getAbsoluteAnchor():t.getBendPoints()[t.getBendPoints().length-1],i.y>=n.y?t.setTarget(l):t.setTarget(c));let a=t.getProperty(e.nt);if(a!=null){let e=a.findIndex(e=>e.x===n.x&&e.y===n.y);e!==-1&&a.splice(e,1)}}n.position.x=a-n.size.x/2}const us={top:0,left:0,bottom:0,right:0},ds=e=>({...e}),fs=[`NORTH`,`SOUTH`,`EAST`,`WEST`];var ps=class{padding=ds(us);contributesMinWidth=!1;contributesMinHeight=!1;rect={x:0,y:0,width:0,height:0}},H=class extends ps{content={x:0,y:0};getMinimumWidth(){return this.content.x+this.padding.left+this.padding.right}getMinimumHeight(){return this.content.y+this.padding.top+this.padding.bottom}},ms=class extends ps{content={x:0,y:0};gap;labelRefs=[];hAlign=`CENTER`;vAlign=`CENTER`;constructor(e){super(),this.gap=e}addLabel(e,t,n){this.content.y>0&&(this.content.y+=this.gap),this.content.x=Math.max(this.content.x,e),this.content.y+=t,n&&this.labelRefs.push(n)}setHorizontalAlignment(e){this.hAlign=e}setVerticalAlignment(e){this.vAlign=e}getLabels(){return this.labelRefs}applyLabelLayout(){let e=this.rect,t=e.y;this.vAlign===`CENTER`?t+=(e.height-this.content.y)/2:this.vAlign===`BOTTOM`&&(t+=e.height-this.content.y);for(let n of this.labelRefs){let r=n.size.x;n.position.y=t,t+=n.size.y+this.gap,this.hAlign===`LEFT`?n.position.x=e.x+this.padding.left:this.hAlign===`CENTER`?n.position.x=e.x+this.padding.left+(e.width-r)/2:n.position.x=e.x+e.width-this.padding.right-r}}getMinimumWidth(){return this.content.x+this.padding.left+this.padding.right}getMinimumHeight(){return this.content.y+this.padding.top+this.padding.bottom}};function U(e,t){return e===null||t&&!e.contributesMinWidth||e instanceof H&&e.content.x===0?0:e.getMinimumWidth()}function hs(e){return e===null||e instanceof H&&e.content.x===0?0:e.getMinimumWidth()}function gs(e){return e===null||e instanceof H&&e.content.y===0?0:e.getMinimumHeight()}function _s(e,t){return e===null||t&&!e.contributesMinHeight||e instanceof H&&e.content.y===0?0:e.getMinimumHeight()}var vs=class extends ps{mode;symmetrical;gap;cells=[null,null,null];constructor(e,t,n){super(),this.mode=e,this.symmetrical=t,this.gap=n}getMinimumWidth(){let e;if(this.mode===`VERTICAL`)e=Math.max(0,U(this.cells[0],!0),U(this.cells[1],!0),U(this.cells[2],!0));else{let t=U(this.cells[0],!0),n=U(this.cells[1],!0),r=U(this.cells[2],!0);this.symmetrical&&(t=Math.max(t,r),r=t);let i=0,a=0;t>0&&(i+=t,a++),n>0&&(i+=n,a++),r>0&&(i+=r,a++),e=a>1?i+this.gap*(a-1):i}return e>0?e+this.padding.left+this.padding.right:0}getMinimumHeight(){let e;if(this.mode===`VERTICAL`){let t=_s(this.cells[0],!0),n=_s(this.cells[1],!0),r=_s(this.cells[2],!0);this.symmetrical&&(t=Math.max(t,r),r=t);let i=0,a=0;t>0&&(i+=t,a++),n>0&&(i+=n,a++),r>0&&(i+=r,a++),e=a>1?i+this.gap*(a-1):i}else e=Math.max(0,_s(this.cells[0],!0),_s(this.cells[1],!0),_s(this.cells[2],!0));return e>0?e+this.padding.top+this.padding.bottom:0}},ys=class extends ps{symmetrical;gap;cells=[[null,null,null],[null,null,null],[null,null,null]];constructor(e,t){super(),this.symmetrical=e,this.gap=t}minHeightOfRow(e,t){let n=0;for(let r=0;r<3;r++)n=Math.max(n,_s(this.cells[e][r],t));return n}minColumnWidthSum(e,t){let n=this.cells[e],r=U(n[0],t),i=U(n[1],t),a=U(n[2],t),o=0,s=0;return r>0&&(o+=r,s++),i>0&&(o+=i,s++),a>0&&(o+=a,s++),s>1?o+this.gap*(s-1):o}getMinimumWidth(){let e=Math.max(this.minColumnWidthSum(0,!0),this.minColumnWidthSum(1,!0),this.minColumnWidthSum(2,!0));return e>0?e+this.padding.left+this.padding.right:0}getMinimumHeight(){let e=this.minHeightOfRow(0,!0),t=this.minHeightOfRow(1,!0),n=this.minHeightOfRow(2,!0);this.symmetrical&&(e=Math.max(e,n),n=e);let r=0,i=0;e>0&&(r+=e,i++),t>0&&(r+=t,i++),n>0&&(r+=n,i++);let a=i>1?r+this.gap*(i-1):r;return a>0?a+this.padding.top+this.padding.bottom:0}};function bs(e,t,n,r){return e.hasProperty(n)?e.getProperty(n):t&&t.hasProperty(n)?t.getProperty(n):r}function xs(t,n){let r=n===`NORTH`?e.Mt:n===`SOUTH`?e.Nt:n===`EAST`?e.jt:e.Pt,i=t.node.hasProperty(r)?t.node.getProperty(r):void 0;return i&&i!==`DISTRIBUTED`?i:bs(t.node,t.graph,e.At,`DISTRIBUTED`)}function Ss(e){return!e.includes(`INSIDE`)&&!e.includes(`OUTSIDE`)}function Cs(e){let t=e.getLabels();if(t.length===0)return null;let n=1/0,r=1/0,i=-1/0,a=-1/0;for(let e of t)n=Math.min(n,e.position.x),r=Math.min(r,e.position.y),i=Math.max(i,e.position.x+e.size.x),a=Math.max(a,e.position.y+e.size.y);return{x:n,y:r,w:i-n,h:a-r}}function ws(e,t){for(let t of fs)e.portContexts.set(t,[]);let n=Ss(e.portLabelsPlacement),r=!n&&(!t||!e.portLabelsPlacement.includes(`INSIDE`)),i=e.portLabelsPlacement.includes(`NEXT_TO_PORT_IF_POSSIBLE`);for(let t of e.node.getPorts()){let a=t.getSide();if(a===`UNDEFINED`)continue;let o=!1;e.portLabelsPlacement.includes(`INSIDE`)?(o=!0,e.treatAsCompoundNode&&(o=i)):e.portLabelsPlacement.includes(`OUTSIDE`)&&(o=i&&t.getConnectedEdges().length===0);let s={port:t,margin:{left:0,right:0,top:0,bottom:0},labelsNextToPort:o,labelCell:null,fixedLabelBounds:n?Cs(t):null};if(r){let n=t.getLabels();if(n.length>0){let t=new ms(e.labelCellSpacing);for(let e of n)t.addLabel(e.size.x,e.size.y,e);s.labelCell=t,e.hasPortLabelCells=!0}}e.portContexts.get(a).push(s)}}function Ts(t){let n=t.insideGrid;n.padding=ds(t.nodeLabelsPadding);let r=t.outsideNodeLabelContainers,i=t.node.getProperty(e._t);for(let e of t.node.getLabels()){let a=Array.isArray(e.placement)?e.placement:String(e.placement??``).split(/[\s,]+/),o=[];for(let e of a){let t=e.replace(/^\[+|\]+$/g,``).trim();t&&o.push(t)}let s=o.length>0?o:i??[],c=s.includes(`INSIDE`),l=s.includes(`V_BOTTOM`)?`bottom`:s.includes(`V_CENTER`)?`center`:`top`,u=s.includes(`H_RIGHT`)?`right`:s.includes(`H_LEFT`)?`left`:`center`,d=l===`bottom`?2:+(l===`center`),f=u===`right`?2:u===`left`?0:1;if(c){let r=n.cells[d][f];r||(r=new ms(t.labelCellSpacing),n.cells[d][f]=r),r.addLabel(e.size.x,e.size.y)}else{let n;n=l===`bottom`?r.get(`SOUTH`):u===`left`&&(s.includes(`H_PRIORITY`)||l===`center`)?r.get(`WEST`):u===`right`&&(s.includes(`H_PRIORITY`)||l===`center`)?r.get(`EAST`):r.get(`NORTH`);let i=new ms(t.labelCellSpacing);i.addLabel(e.size.x,e.size.y),n.mode===`HORIZONTAL`?n.cells[f]=i:n.cells[1]=i}}}function Es(t){let n=t.nodeContainer.padding;for(let[r,i]of t.portContexts)for(let a of i){let i=a.port.getProperty(e.It)??0;if(i<0){let e=-i;r===`NORTH`?n.top=Math.max(n.top,e):r===`SOUTH`?n.bottom=Math.max(n.bottom,e):r===`EAST`?n.right=Math.max(n.right,e):n.left=Math.max(n.left,e)}if(Ss(t.portLabelsPlacement)&&a.fixedLabelBounds){let e=a.fixedLabelBounds,o=a.port.size,s=0;s=r===`NORTH`?Math.max(0,e.h+e.y-(o.y+i)):r===`SOUTH`?Math.max(0,-e.y-i):r===`EAST`?Math.max(0,-e.x-i):Math.max(0,e.w+e.x-(o.x+i));let c=t.symmetry;if(r===`NORTH`){let e=s>n.top;n.top=Math.max(n.top,s),c&&e&&(n.top=Math.max(n.top,n.bottom),n.bottom=n.top+i)}else if(r===`SOUTH`){let e=s>n.bottom;n.bottom=Math.max(n.bottom,s),c&&e&&(n.bottom=Math.max(n.bottom,n.top),n.top=n.bottom+i)}else if(r===`EAST`){let e=s>n.right;n.right=Math.max(n.right,s),c&&e&&(n.right=Math.max(n.left,n.right),n.left=n.right+i)}else{let e=s>n.left;n.left=Math.max(n.left,s),c&&e&&(n.left=Math.max(n.left,n.right),n.right=n.left+i)}}}}function Ds(e){let t=e.portConstraints;if(t===`FIXED_RATIO`||String(t)===`FIXED_RATIO`||t===`FIXED_POS`||String(t)===`FIXED_POSITION`)return;let n=e.insidePortLabelCells.get(`EAST`),r=e.insidePortLabelCells.get(`WEST`),i=e.insidePortLabelCells.get(`NORTH`),a=e.insidePortLabelCells.get(`SOUTH`),o=e.nodeContainer.padding.top+i.getMinimumHeight()+e.labelCellSpacing,s=e.nodeContainer.padding.bottom+a.getMinimumHeight()+e.labelCellSpacing,c=Math.max(0,n.padding.top-o,r.padding.top-o),l=Math.max(0,n.padding.bottom-s,r.padding.bottom-s);n.padding.top=c,r.padding.top=c,n.padding.bottom=l,r.padding.bottom=l}function Os(e){for(let t of fs){let n=e.insidePortLabelCells.get(t),r=e.portContexts.get(t);if(r.length===0){t===`NORTH`||t===`SOUTH`?(n.padding.left=0,n.padding.right=0,e.portLabelSpacingV>=0&&(t===`NORTH`?n.padding.top=e.portLabelSpacingV:n.padding.bottom=e.portLabelSpacingV)):(n.padding.top=0,n.padding.bottom=0);continue}t===`NORTH`||t===`SOUTH`?(n.padding.left=e.surrounding.left,n.padding.right=e.surrounding.right,e.portLabelSpacingV>=0&&(t===`NORTH`?n.padding.top=e.portLabelSpacingV:n.padding.bottom=e.portLabelSpacingV)):(n.padding.top=e.surrounding.top,n.padding.bottom=e.surrounding.bottom),e.constraints.includes(`PORT_LABELS`)&&ks(e,t);let i=t===`NORTH`||t===`SOUTH`,a=0;for(let t=0;t<r.length;t++){let n=r[t];a+=i?n.margin.left+n.port.size.x+n.margin.right:n.margin.top+n.port.size.y+n.margin.bottom,t<r.length-1&&(a+=e.portPort)}xs(e,t)===`DISTRIBUTED`&&(a+=2*e.portPort),i?n.content.x=a:n.content.y=a;let o=e.portConstraints!==`FIXED_POS`&&String(e.portConstraints)!==`FIXED_POSITION`;if(i&&e.portLabelsPlacement.includes(`INSIDE`)&&e.constraints.includes(`PORT_LABELS`)&&o){let e=0;for(let t of r)t.labelCell&&(e=Math.max(e,t.labelCell.getMinimumHeight()));e>0&&(n.content.y=e)}if(!i&&e.portLabelsPlacement.includes(`INSIDE`)){let i=0;for(let e of r)e.labelCell&&(i=Math.max(i,e.labelCell.getMinimumWidth()));i>0&&(n.content.x=i,t===`EAST`?n.padding.right=e.portLabelSpacingH:n.padding.left=e.portLabelSpacingH)}}}function ks(e,t){let n=e.portContexts.get(t),r=e.portLabelsPlacement.includes(`OUTSIDE`),i=e.sizeOptions.includes(`UNIFORM_PORT_SPACING`);for(let r of n){let n=r.labelCell?r.labelCell.getMinimumWidth():0,i=r.labelCell?r.labelCell.getMinimumHeight():0;if(r.labelCell){if(t===`NORTH`||t===`SOUTH`){if(r.labelsNextToPort){let e=r.port.size.x;if(n>e){let t=(n-e)/2;r.margin.left=t,r.margin.right=t}}else r.margin.right=e.portLabelSpacingH+n}else if(r.labelsNextToPort){let e=r.port.size.y;if(i>e){let t=(i-e)/2;r.margin.top=t,r.margin.bottom=t}}else r.margin.bottom=e.portLabelSpacingV+i}else if(Ss(e.portLabelsPlacement)&&r.fixedLabelBounds){let e=r.fixedLabelBounds;t===`NORTH`||t===`SOUTH`?(e.x<0&&(r.margin.left=-e.x),e.x+e.w>r.port.size.x&&(r.margin.right=e.x+e.w-r.port.size.x)):(e.y<0&&(r.margin.top=-e.y),e.y+e.h>r.port.size.y&&(r.margin.bottom=e.y+e.h-r.port.size.y))}}if(r){let e=n[0],r=n[n.length-1];t===`NORTH`||t===`SOUTH`?(e.margin.left=0,r.margin.right=0):(e.margin.top=0,r.margin.bottom=0)}if(i){let e=0,i=0,a=0,o=0;for(let t of n)t.margin.left>e&&(e=t.margin.left),t.margin.right>i&&(i=t.margin.right),t.margin.top>a&&(a=t.margin.top),t.margin.bottom>o&&(o=t.margin.bottom);for(let t of n)t.margin.left=e,t.margin.right=i,t.margin.top=a,t.margin.bottom=o;if(r){let e=n[0],r=n[n.length-1];t===`NORTH`||t===`SOUTH`?(e.margin.left=0,r.margin.right=0):(e.margin.top=0,r.margin.bottom=0)}}}function As(e){if(e.constraints.length===0)return;let t=e.insidePortLabelCells,n=e.portConstraints!==`FIXED_RATIO`&&e.portConstraints!==`FIXED_POS`&&String(e.portConstraints)!==`FIXED_RATIO`&&String(e.portConstraints)!==`FIXED_POSITION`;if(e.constraints.includes(`PORTS`)&&(t.get(`NORTH`).contributesMinWidth=!0,t.get(`SOUTH`).contributesMinWidth=!0,t.get(`EAST`).contributesMinHeight=n,t.get(`WEST`).contributesMinHeight=n,e.middleRow.contributesMinHeight=n,e.constraints.includes(`PORT_LABELS`)&&(t.get(`NORTH`).contributesMinHeight=!0,t.get(`SOUTH`).contributesMinHeight=!0,t.get(`EAST`).contributesMinWidth=!0,t.get(`WEST`).contributesMinWidth=!0,e.middleRow.contributesMinWidth=!0)),e.constraints.includes(`NODE_LABELS`)){e.insideGrid.contributesMinHeight=!0,e.insideGrid.contributesMinWidth=!0,e.middleRow.contributesMinHeight=!0,e.middleRow.contributesMinWidth=!0;let t=e.sizeOptions.includes(`OUTSIDE_NODE_LABELS_OVERHANG`);for(let t=0;t<3;t++)for(let n=0;n<3;n++){let r=e.insideGrid.cells[t][n];r&&(r.contributesMinHeight=!0,r.contributesMinWidth=!0)}for(let n of fs){let r=e.outsideNodeLabelContainers.get(n);r.contributesMinHeight=!t,r.contributesMinWidth=!t;for(let e of r.cells)e&&(e.contributesMinHeight=!t,e.contributesMinWidth=!t)}}e.constraints.includes(`MINIMUM_SIZE`)&&e.sizeOptions.includes(`MINIMUM_SIZE_ACCOUNTS_FOR_PADDING`)&&(e.middleRow.contributesMinHeight=!0,e.middleRow.contributesMinWidth=!0,e.insideGrid.contributesMinHeight||(e.insideGrid.contributesMinHeight=!0,e.insideGrid.contributesMinWidth=!0))}function js(t,n,r){let i=t.hasProperty(e.Tt)?t.getProperty(e.Tt):n?.getProperty(e.Tt)??[],a=i.length===0||i.length===1&&i[0]===`PORT_LABELS`,o=t.hasProperty(e.Dt)?t.getProperty(e.Dt):n&&n.hasProperty(e.Dt)?n.getProperty(e.Dt):[],s=String(t.getProperty(e.Lt)??`UNDEFINED`),c=t.hasProperty(e.zt)?t.getProperty(e.zt):[`OUTSIDE`],l=t.getProperty(`org.eclipse.elk.portLabels.treatAsGroup`)===!0,u=!o.includes(`ASYMMETRICAL`),d=bs(t,n,e.pn,10),f=bs(t,n,e.fn,ds(us)),p=bs(t,n,e.gt,{top:5,right:5,bottom:5,left:5}),m=bs(t,n,e.an,0),h=2*m,g=bs(t,n,e.on,5),_=bs(t,n,e.sn,1),v=bs(t,n,e.cn,1),y=new vs(`VERTICAL`,u,0),b=new vs(`HORIZONTAL`,u,0);y.cells[1]=b;let x=new ys(u,h);b.cells[1]=x;let S=/* @__PURE__ */ new Map,C=new H,w=new H,ee=new H,te=new H;S.set(`NORTH`,C),S.set(`SOUTH`,w),S.set(`WEST`,ee),S.set(`EAST`,te),y.cells[0]=C,y.cells[2]=w,b.cells[0]=ee,b.cells[2]=te;let T=/* @__PURE__ */ new Map;T.set(`NORTH`,new vs(`HORIZONTAL`,u,h)),T.set(`SOUTH`,new vs(`HORIZONTAL`,u,h)),T.set(`WEST`,new vs(`VERTICAL`,u,h)),T.set(`EAST`,new vs(`VERTICAL`,u,h)),T.get(`NORTH`).padding.bottom=g,T.get(`SOUTH`).padding.top=g,T.get(`WEST`).padding.right=g,T.get(`EAST`).padding.left=g;let E={node:t,graph:n,treatAsCompoundNode:t.getNestedGraph()!==null||t.getProperty(e.Q),sizeFixed:a,constraints:i,sizeOptions:o,portConstraints:s,portLabelsPlacement:c,portLabelsTreatAsGroup:l,symmetry:u,portPort:d,surrounding:f,nodeLabelsPadding:p,labelLabelSpacing:m,labelCellSpacing:h,nodeLabelSpacing:g,portLabelSpacingH:_,portLabelSpacingV:v,portContexts:/* @__PURE__ */ new Map,hasPortLabelCells:!1,nodeContainer:y,middleRow:b,insideGrid:x,insidePortLabelCells:S,outsideNodeLabelContainers:T};return ws(E,r),Ts(E),Es(E),Os(E),As(E),Ds(E),E}function Ms(e){if(e.sizeFixed)return null;let{nodeContainer:t}=e,n=e.constraints,r=e.sizeOptions,i=e.outsideNodeLabelContainers,a=t.getMinimumWidth(),o=t.getMinimumHeight();return n.includes(`NODE_LABELS`)&&!r.includes(`OUTSIDE_NODE_LABELS_OVERHANG`)&&(a=Math.max(a,i.get(`NORTH`).getMinimumWidth(),i.get(`SOUTH`).getMinimumWidth()),o=Math.max(o,i.get(`EAST`).getMinimumHeight(),i.get(`WEST`).getMinimumHeight())),{x:a,y:o}}function Ns(e,t,n=!1){return Ms(js(e,t,n))}function Ps(e,t){let n=gs(e.cells[0]),r=gs(e.cells[1]),i=gs(e.cells[2]);e.symmetrical&&(n=Math.max(n,i),i=n),e.cells[0]&&(e.cells[0].rect={x:t.x,y:t.y+e.padding.top,width:t.width,height:n}),e.cells[2]&&(e.cells[2].rect={x:t.x,y:t.y+t.height-e.padding.bottom-i,width:t.width,height:i});let a=t.height-e.padding.top-e.padding.bottom;n>0&&(a-=n),i>0&&(a-=i);let o=Math.max(r,a);e.cells[1]&&(e.cells[1].rect={x:t.x,y:t.y+e.padding.top+n,width:t.width,height:o})}function Fs(e,t){let n=hs(e.cells[0]),r=hs(e.cells[1]),i=hs(e.cells[2]);e.symmetrical&&(n=Math.max(n,i),i=n),e.cells[0]&&(e.cells[0].rect={x:t.x+e.padding.left,y:t.y,width:n,height:t.height}),e.cells[2]&&(e.cells[2].rect={x:t.x+t.width-e.padding.right-i,y:t.y,width:i,height:t.height});let a=t.width-e.padding.left-e.padding.right;n>0&&(a-=n+e.gap,n+=e.gap),i>0&&(a-=i+e.gap);let o=Math.max(r,a);e.cells[1]&&(e.cells[1].rect={x:t.x+e.padding.left+n-(o-a)/2,y:t.y,width:o,height:t.height})}function Is(e,t,n){return t===`DISTRIBUTED`?n-2*e.portPort:n}function Ls(t,n,r){let i={x:0,y:0,width:n,height:r};Ps(t.nodeContainer,i),Fs(t.middleRow,t.middleRow.rect);let a=t.sizeOptions.includes(`PORTS_OVERHANG`);for(let r of fs){let i=t.portContexts.get(r);if(i.length===0)continue;let o=t.insidePortLabelCells.get(r),s=o.rect,c=o.padding,l=r===`NORTH`||r===`SOUTH`,u=xs(t,r),d=l?o.content.x:o.content.y;(u===`DISTRIBUTED`||u===`JUSTIFIED`)&&i.length===1&&(d=Is(t,u,d),u=`CENTER`);let f=(l?s.width:s.height)-(l?c.left+c.right:c.top+c.bottom),p=l?s.x+c.left:s.y+c.top,m=t.portPort;if(f<d&&!a)u===`DISTRIBUTED`?(m+=(f-d)/(i.length+1),p+=m):m+=(f-d)/(i.length-1);else switch(f<d&&(d=Is(t,u,d),u=`CENTER`),u){case`BEGIN`:break;case`CENTER`:p+=(f-d)/2;break;case`END`:p+=f-d;break;case`DISTRIBUTED`:{let e=(f-d)/(i.length+1);m+=Math.max(0,e),p+=m;break}case`JUSTIFIED`:{let e=(f-d)/(i.length-1);m+=Math.max(0,e);break}}let h=r===`WEST`||r===`SOUTH`;for(let t=0;t<i.length;t++){let a=h?i[i.length-1-t]:i[t],o=a.port.getProperty(e.It)??0;l?(a.port.getPosition().x=p+a.margin.left,a.port.getPosition().y=r===`NORTH`?-a.port.size.y-o:o,p+=a.margin.left+a.port.size.x+a.margin.right+m):(a.port.getPosition().y=p+a.margin.top,a.port.getPosition().x=r===`EAST`?n+o:-a.port.size.x-o,p+=a.margin.top+a.port.size.y+a.margin.bottom+m)}}}function Rs(e,t){let n=e.nodeContainer.padding;switch(t){case`NORTH`:return n.top+e.portLabelSpacingV;case`SOUTH`:return n.bottom+e.portLabelSpacingV;case`EAST`:return n.right+e.portLabelSpacingH;case`WEST`:return n.left+e.portLabelSpacingH;default:return 0}}function zs(e,t){let n=e.portContexts.get(t);if(n.length>=2){let r=t===`SOUTH`||t===`WEST`?n[n.length-1]:n[0],i=e.portLabelsPlacement.includes(`ALWAYS_SAME_SIDE`),a=e.portLabelsPlacement.includes(`SPACE_EFFICIENT`);return!r.labelsNextToPort&&!i&&(n.length===2||a)}return!1}function Bs(t,n){let r=0,i=Rs(t,n),a=n===`NORTH`||n===`SOUTH`;for(let o of t.portContexts.get(n)){let s=o.labelCell;if(s===null||s.getLabels().length===0)continue;let c=o.port.size,l=o.port.getProperty(e.It)??0,u=s.rect;switch(u.width=s.getMinimumWidth(),u.height=s.getMinimumHeight(),n){case`NORTH`:u.x=o.labelsNextToPort?(c.x-u.width)/2:c.x+t.portLabelSpacingH,u.y=c.y+l+i,s.setHorizontalAlignment(`CENTER`),s.setVerticalAlignment(`TOP`);break;case`SOUTH`:u.x=o.labelsNextToPort?(c.x-u.width)/2:c.x+t.portLabelSpacingH,u.y=-l-i-u.height,s.setHorizontalAlignment(`CENTER`),s.setVerticalAlignment(`BOTTOM`);break;case`EAST`:if(u.x=-l-i-u.width,o.labelsNextToPort){let e=t.portLabelsTreatAsGroup?u.height:s.getLabels()[0].size.y;u.y=(c.y-e)/2}else u.y=c.y+t.portLabelSpacingV;s.setHorizontalAlignment(`RIGHT`),s.setVerticalAlignment(`CENTER`);break;case`WEST`:if(u.x=c.x+l+i,o.labelsNextToPort){let e=t.portLabelsTreatAsGroup?u.height:s.getLabels()[0].size.y;u.y=(c.y-e)/2}else u.y=c.y+t.portLabelSpacingV;s.setHorizontalAlignment(`LEFT`),s.setVerticalAlignment(`CENTER`)}a&&(r=Math.max(r,u.height))}r>0&&(t.insidePortLabelCells.get(n).content.y=r)}function Vs(e,t){let n=zs(e,t),r=e.portLabelsPlacement.includes(`ALWAYS_OTHER_SAME_SIDE`);for(let i of e.portContexts.get(t)){let a=i.labelCell;if(a===null||a.getLabels().length===0)continue;let o=i.port.size,s=a.rect;switch(s.width=a.getMinimumWidth(),s.height=a.getMinimumHeight(),t){case`NORTH`:i.labelsNextToPort?(s.x=(o.x-s.width)/2,a.setHorizontalAlignment(`CENTER`)):n||r?(s.x=-s.width-e.portLabelSpacingH,a.setHorizontalAlignment(`RIGHT`)):(s.x=o.x+e.portLabelSpacingH,a.setHorizontalAlignment(`LEFT`)),s.y=-s.height-e.portLabelSpacingV,a.setVerticalAlignment(`BOTTOM`);break;case`SOUTH`:i.labelsNextToPort?(s.x=(o.x-s.width)/2,a.setHorizontalAlignment(`CENTER`)):n||r?(s.x=-s.width-e.portLabelSpacingH,a.setHorizontalAlignment(`RIGHT`)):(s.x=o.x+e.portLabelSpacingH,a.setHorizontalAlignment(`LEFT`)),s.y=o.y+e.portLabelSpacingV,a.setVerticalAlignment(`TOP`);break;case`EAST`:if(i.labelsNextToPort){let t=e.portLabelsTreatAsGroup?s.height:a.getLabels()[0].size.y;s.y=(o.y-t)/2,a.setVerticalAlignment(`CENTER`)}else n||r?(s.y=-s.height-e.portLabelSpacingV,a.setVerticalAlignment(`BOTTOM`)):(s.y=o.y+e.portLabelSpacingV,a.setVerticalAlignment(`TOP`));s.x=o.x+e.portLabelSpacingH,a.setHorizontalAlignment(`LEFT`);break;case`WEST`:if(i.labelsNextToPort){let t=e.portLabelsTreatAsGroup?s.height:a.getLabels()[0].size.y;s.y=(o.y-t)/2,a.setVerticalAlignment(`CENTER`)}else n||r?(s.y=-s.height-e.portLabelSpacingV,a.setVerticalAlignment(`BOTTOM`)):(s.y=o.y+e.portLabelSpacingV,a.setVerticalAlignment(`TOP`));s.x=-s.width-e.portLabelSpacingH,a.setHorizontalAlignment(`RIGHT`)}n=!1}}function Hs(e){let t=e.portLabelsPlacement,n=t.includes(`INSIDE`),r=t.includes(`OUTSIDE`);if((n||r)&&e.hasPortLabelCells){for(let t of fs)n?Bs(e,t):Vs(e,t);for(let t of fs)for(let n of e.portContexts.get(t))n.labelCell&&n.labelCell.applyLabelLayout()}}function Us(e){return`JUSTIFIED`}function Ws(t,n,r){let i=t.getPorts(n);if(i.length===0)return;let a=t.size.y,o=i.find(e=>e.size.y>0)?.size.y??i[0].size.y,s=o+(a-i.reduce((e,t)=>e+t.size.y,0))/(i.length+1),c=n===`WEST`;for(let n=0;n<i.length;n++){let r=i[n],a=c?(i.length-n)*s-o:(n+1)*s-o,l=r.getProperty(e.It)??0;r.getPosition().x=c?-r.size.x-l:t.size.x+l,r.getPosition().y=a}}function Gs(t,n,r){let i=t.getPorts(n);if(i.length===0)return;let a=t.size.x,o=i.reduce((e,t)=>e+t.size.x,0),s=a,c=Us(t),l=0,u=c;(c===`DISTRIBUTED`||c===`JUSTIFIED`)&&i.length===1&&(u=`CENTER`);let d=r;switch(u===`JUSTIFIED`&&(d=(s-o)/(i.length+1),l=d),u){case`CENTER`:l=(s-o)/2;break;case`END`:l=s-o}let f=l,p=n===`SOUTH`?[...i].reverse():i;for(let r of p){let i=n===`NORTH`,a=r.getProperty(e.It);r.getPosition().y=i?-r.size.y-(a??0):t.size.y+(a??0),r.getPosition().x=f,f+=r.size.x+d}}function Ks(t){let n=t.getProperty(e.pn);for(let e of t.getLayers())for(let t of e.getNodes())t.getType()===`NORMAL`&&Js(t,n);qs(t)}function qs(t){let n=t.getProperty(e.zt)??[],r=n.includes(`NEXT_TO_PORT_IF_POSSIBLE`),i=t.getProperty(`org.eclipse.elk.portLabels.treatAsGroup`)===!0;for(let a of t.getLayers())for(let t of a.getNodes()){if(t.getType()!==`EXTERNAL_PORT`)continue;let a=t.getPorts()[0];if(!a||a.getLabels().length===0)continue;let o=dn(t,e.sn),s=dn(t,e.cn),c=dn(t,e.an),l=t.size,u=a.position,d=a.getLabels(),f=0,p=0;for(let e of d)f=Math.max(f,e.size.x),p+=e.size.y;p+=(d.length-1)*c;let m={x:0,y:0,width:f,height:p},h=t.getProperty(e.Un),g=e=>r?e?a.getIncomingEdges().length===0&&a.getOutgoingEdges().length===0:a.getConnectedEdges().length===0:!1;if(n.includes(`INSIDE`))switch(h){case`NORTH`:m.x=(l.x-m.width)/2-u.x,m.y=s;break;case`SOUTH`:m.x=(l.x-m.width)/2-u.x,m.y=-s-m.height;break;case`EAST`:case`WEST`:if(g(!0)){let e=i?m.height:d[0].size.y;m.y=(l.y-e)/2-u.y}else m.y=l.y+s-u.y;m.x=h===`EAST`?-o-m.width:o}else if(n.includes(`OUTSIDE`))switch(h){case`NORTH`:case`SOUTH`:m.x=u.x+o;break;case`EAST`:case`WEST`:if(g(!1)){let e=i?m.height:d[0].size.y;m.y=(l.y-e)/2-u.y}else m.y=u.y+s}let _=m.y;for(let e of d)e.position.x=m.x,e.position.y=_,_+=e.size.y+c}}function Js(t,n){let r=js(t,t.getGraph(),!1);Ys(t,r);let i=t.getProperty(e.Lt);if(i===`FIXED_POS`||i===`FIXED_RATIO`||String(i)===`FIXED_POSITION`||String(i)===`FIXED_RATIO`){for(let n of t.getPorts(`NORTH`))n.isExplicitSide()&&(n.getPosition().y=-n.size.y-(n.getProperty(e.It)??0));for(let n of t.getPorts(`SOUTH`))n.isExplicitSide()&&(n.getPosition().y=t.size.y+(n.getProperty(e.It)??0));for(let n of t.getPorts(`WEST`))n.isExplicitSide()&&(n.getPosition().x=-n.size.x-(n.getProperty(e.It)??0));for(let n of t.getPorts(`EAST`))n.isExplicitSide()&&(n.getPosition().x=t.size.x+(n.getProperty(e.It)??0));Hs(r)}else if(t.getNestedGraph()===null){Ls(r,t.size.x,t.size.y);let e=t.size.y;for(let n of t.getPorts(`SOUTH`))n.getPosition().y+=e;Hs(r)}else Ws(t,`WEST`,n),Ws(t,`EAST`,n),Gs(t,`NORTH`,n),Gs(t,`SOUTH`,n),Hs(r)}function Ys(t,n){let r=t.getLabels(),i=t.getGraph(),a=t.hasProperty(e.Tt)?t.getProperty(e.Tt):i?.getProperty(e.Tt)??[];if(a.includes(`MINIMUM_SIZE`)){let n=t.hasProperty(e.Et)?t.getProperty(e.Et):{x:0,y:0};t.size.x=Math.max(t.size.x,n.x),t.size.y=Math.max(t.size.y,n.y)}if(a.includes(`PORTS`)&&t.getNestedGraph()===null){let r=Ms(n);if(r){let n=r.x,i=r.y;if(a.includes(`MINIMUM_SIZE`)){let r=t.hasProperty(e.Et)?t.getProperty(e.Et):{x:0,y:0};n=Math.max(n,r.x>0?r.x:20),i=Math.max(i,r.y>0?r.y:20)}t.size.x=n,t.size.y=i}}if(r.length===0)return;let o=a.includes(`NODE_LABELS`),s=t.hasProperty(e.gt)?t.getProperty(e.gt):i?.getProperty(e.gt)??{top:5,right:5,bottom:5,left:5},c=0,l=0;for(let e of r)c=Math.max(c,e.size.x),l=Math.max(l,e.size.y);let u=a.includes(`PORTS`)||a.includes(`PORT_LABELS`),d=t.getProperty(e.q)===`SEPARATE_CHILDREN`;if(o&&!u&&t.getNestedGraph()===null&&!d){let n=c,r=l;if(a.includes(`MINIMUM_SIZE`)){let i=t.hasProperty(e.Et)?t.getProperty(e.Et):{x:0,y:0};n=Math.max(n,i.x>0?i.x:20),r=Math.max(r,i.y>0?i.y:20)}a.includes(`MINIMUM_SIZE`)?(t.size.x=n,t.size.y=r):(t.size.x=n+s.left+s.right,t.size.y=r+s.top+s.bottom)}Xs(t,r,s,i)}function Xs(t,n,r,i){if(n.length===0)return;let a=i?.getProperty(e.an)??0,o=ta(t),s=t.getProperty(e._t),c=e=>{let t=e.placement??s??``;return Array.isArray(t)?t:String(t).split(/[\s,]+/).filter(Boolean)},l=e=>e.includes(`V_BOTTOM`)?`bottom`:e.includes(`V_CENTER`)?`center`:`top`,u=e=>e.includes(`H_RIGHT`)?`right`:e.includes(`H_LEFT`)?`left`:`center`,d=Array(n.length);for(let e=0;e<n.length;e++)d[e]=c(n[e]);let f=[],p=[];for(let e=0;e<n.length;e++)d[e].includes(`OUTSIDE`)?f.push(n[e]):p.push(n[e]);if(f.length>0)for(let e of f)$i(e,t.size,Zi(e,t),o);if(p.length===0)return;let m={top:{},center:{},bottom:{}};for(let e=0;e<n.length;e++){let t=d[e];if(t.includes(`OUTSIDE`))continue;let r=l(t),i=u(t);(m[r][i]??=[]).push(n[e])}let h=e=>{let t=0;for(let n of Object.values(m[e])){let e=n.reduce((e,t)=>e+t.size.y+a,0)-(n.length>0?a:0);t=Math.max(t,e)}return t},g=h(`top`),_=h(`bottom`),v=h(`center`),y=(e,n)=>{if(e===`top`)return r.top;if(e===`bottom`)return t.size.y-r.bottom-(n.reduce((e,t)=>e+t.size.y+a,0)-(n.length>0?a:0));let i=r.top+g+a;return i+(t.size.y-r.bottom-_-a-i-v)/2};for(let e of[`top`,`center`,`bottom`])for(let t of Object.keys(m[e])){let n=m[e][t],r=y(e,n);for(let e of n)e.position.y=r,r+=e.size.y+a}for(let e=0;e<n.length;e++){if(d[e].includes(`OUTSIDE`))continue;let i=n[e],a=u(d[e]);a===`right`?i.position.x=t.size.x-i.size.x-r.right:a===`left`?i.position.x=r.left:i.position.x=r.left+(t.size.x-r.left-r.right-i.size.x)/2}}function Zs(t){let n=t.getProperty(e.Ct);if(n!=null){t.setProperty(e.St,null);for(let n of t.getLayers())for(let t of n.getNodes())t.setProperty(e.xt,null),t.setProperty(e.Tt,null),t.position.y=0;Ks(t),na(t),Qs(n,t)}}function Qs(e,t){switch(e){case`SIMPLE`:on(t);break;case`INTERACTIVE`:sn(t);break;case`NETWORK_SIMPLEX`:new bn().process(t);break;case`BRANDES_KOEPF`:new an().process(t);break;default:throw Error(`未支持的节点放置策略: ${e}`)}}function $s(t){if(!t.getProperty(e.Gn).has(`EXTERNAL_PORTS`))return;let n=1/0,r=-1/0,i=1/0,a=-1/0;for(let e of t.getLayerlessNodes()){if(e.getType()!==`NORMAL`)continue;let t=e.getMargin();n=Math.min(n,e.position.x-t.left),r=Math.max(r,e.position.x+e.size.x+t.right),i=Math.min(i,e.position.y-t.top),a=Math.max(a,e.position.y+e.size.y+t.bottom)}for(let e of t.getLayerlessNodes())if(e.getType()!==`NORMAL`)switch(e.getType()){case`EXTERNAL_PORT`:{let t=e.getLayerConstraint();if(t===`FIRST_SEPARATE`){e.position.x=n-10;let t=ec(e,e=>e.getTarget()?.getNode()??null);t!==null&&(e.position.y=t);break}if(t===`LAST_SEPARATE`){e.position.x=r+10;let t=ec(e,e=>e.getSource()?.getNode()??null);t!==null&&(e.position.y=t);break}let o=e.getInLayerConstraint();if(o===`TOP`){let t=tc(e);t!==null&&(e.position.x=t+10),e.position.y=i-10;break}if(o===`BOTTOM`){let t=tc(e);t!==null&&(e.position.x=t+10),e.position.y=a+10;break}break}default:throw Error(`节点类型 ${e.getType()} 不受 InteractiveExternalPortPositioner 支持`)}}function ec(e,t){for(let n of e.getConnectedEdges()){let e=t(n);if(e!==null)return e.position.y+e.size.y/2}return null}function tc(e){if(e.getPorts().length!==1)throw Error(`外部端口 dummy 必须恰好一个端口`);let t=e.getPorts()[0];if(t.getOutgoingEdges().length>0&&t.getIncomingEdges().length>0)throw Error(`交互式布局不支持同时有入边和出边的 NORTH/SOUTH 端口`);if(t.getOutgoingEdges().length>0){let e=1/0;for(let n of t.getOutgoingEdges()){let t=n.getTarget().getNode(),r=t.getMargin();e=Math.min(e,t.position.x-r.left)}return e}if(t.getIncomingEdges().length>0){let e=-1/0;for(let n of t.getIncomingEdges()){let t=n.getSource().getNode(),r=t.getMargin();e=Math.max(e,t.position.x+t.size.x+r.right)}return e}return null}var nc=class{start;end;nodeStartEdge;startEndEdge;originalEdge;startInLayerDummy=null;startInLayerEdge=null;endInLayerDummy=null;endInLayerEdge=null;prev=null;next=null;constructor(e,t,n,r,i){this.start=e,this.end=t,this.nodeStartEdge=n,this.startEndEdge=r,this.originalEdge=i}static isStart(t){let n=t.getProperty(e.An);return n!==null&&n.start===t}static isEnd(t){let n=t.getProperty(e.An);return n!==null&&n.end===t}},rc=class{graph;spacing=0;inLayerSpacing=0;dar;longestPath;maxWidth=null;maxHeight=null;sumWidth=null;widths=null;heights=null;cutsAllowed=null;constructor(t){this.graph=t;let n=t.getProperty(e.F),r=t.getProperty(e.h),i=t.getProperty(e._n);this.dar=n===`LEFT`||n===`RIGHT`||n===`UNDEFINED`?r*i:1/(r*i),this.spacing=t.getProperty(e.un),this.inLayerSpacing=t.getProperty(e.ln),this.longestPath=t.getLayers().length}getApproximateLayerWidth(e){return this.determineLayerWidth(e)}getApproximateLayeringWidth(){return this.getSumWidth()}getApproximateChunkBasedLayeringWidth(e){if(e.length===0)return this.getApproximateLayeringWidth();let t=0,n=0;for(let r of e)t=Math.max(t,this.determineChunkWidth(n,r)),n=r;return t=Math.max(t,this.determineChunkWidth(n,this.graph.getLayers().length)),t}getApproximateLayerHeight(e){return this.determineLayerHeight(e)}getApproximateLayeringHeight(){return this.getMaxHeight()}getApproximateChunkBasedLayeringHeight(e){if(e.length===0)return 0;let t=0,n=0;for(let r of e)t+=this.determineChunkHeight(n,r),n=r;return t+=this.determineChunkHeight(n,this.graph.getLayers().length),t}getMaxWidth(){return this.maxWidth===null&&(this.maxWidth=this.determineWidth((e,t)=>Math.max(e,t))),this.maxWidth}getSumWidth(){return this.sumWidth===null&&(this.sumWidth=this.determineWidth((e,t)=>e+t)),this.sumWidth}getWidths(){return this.widths===null&&this.initWidthsAndHeights(),this.widths}initWidthsAndHeights(){let e=this.longestPath,t=Array(e),n=Array(e);for(let r=0;r<e;r++){let e=this.graph.getLayers()[r];t[r]=this.determineLayerWidth(e),n[r]=this.determineLayerHeight(e)}this.widths=t,this.heights=n}determineWidth(e){let t=this.graph.getLayers(),n=this.determineLayerWidth(t[0]);for(let r=1;r<t.length;r++)n=e(n,this.determineLayerWidth(t[r]));return n}determineLayerWidth(e){let t=0;for(let n of e.getNodes()){let e=n.getSize().x+n.getMargin().right+n.getMargin().left+this.spacing;t=Math.max(t,e)}return t}determineChunkWidth(e,t){let n=0;for(let r=e;r<t;r++)n+=this.determineLayerWidth(this.graph.getLayers()[r]);return n}getMaxHeight(){return this.maxHeight===null&&(this.maxHeight=this.determineHeight((e,t)=>Math.max(e,t))),this.maxHeight}getHeights(){return this.heights===null&&this.initWidthsAndHeights(),this.heights}determineHeight(e){let t=this.graph.getLayers(),n=this.determineLayerHeight(t[0]);for(let r=1;r<t.length;r++)n=e(n,this.determineLayerHeight(t[r]));return n}determineLayerHeight(t){let n=0;for(let r of t.getNodes()){n+=r.getSize().y+r.getMargin().bottom+r.getMargin().top+this.inLayerSpacing;for(let t of r.getIncomingEdges())if(t.getSource().getNode().getType()===`NORTH_SOUTH_PORT`){let r=t.getSource().getNode().getProperty(e.lr);n+=r.getSize().y+r.getMargin().bottom+r.getMargin().top}}return n}determineChunkHeight(e,t){let n=0;for(let r=e;r<t;r++)n=Math.max(n,this.determineLayerHeight(this.graph.getLayers()[r]));return n}isCutAllowed(e){return this.cutsAllowed===null&&this.initCutAllowed(),this.cutsAllowed[e]}initCutAllowed(){if(this.cutsAllowed!==null)return;let t=Array(this.graph.getLayers().length);if(t[0]=!1,this.graph.hasProperty(e.Tn)){let n=this.graph.getProperty(e.Tn);if(n!==null)for(let e of n)e>0&&e<t.length&&(t[e]=!1)}else{let e=this.graph.getLayers();for(let n=1;n<e.length;n++)t[n]=this.isCutAllowedPerLayer(e[n])}this.cutsAllowed=t}getCutsAllowed(){return this.cutsAllowed===null&&this.initCutAllowed(),this.cutsAllowed}isCutAllowedPerLayer(e){let t=!0,n=null,r=null;check:for(let i of e.getNodes())for(let e of i.getIncomingEdges()){if(n!==null&&n!==i){t=!1;break check}n=i;let a=e.getSource().getNode();if(r!==null&&r!==a){t=!1;break check}r=a}return t}},ic=class{getCutIndexes(t,n){let r=t.getProperty(e.vn);return r===null?[]:r}guaranteeValid(){return!1}},ac=class e{getCutIndexes(t,n){let r=e.getChunkCount(n),i=[],a=n.longestPath/r;for(let e=1;e<r;++e)i.push(Math.round(e*a));return i}static getChunkCount(e){let t=Math.sqrt(e.getSumWidth()/(e.dar*e.getMaxHeight())),n=Math.round(t);return n=Math.min(n,e.longestPath),n}guaranteeValid(){return!1}},oc=class{guaranteeValid(){return!1}getCutIndexes(t,n){let r=n.getWidths(),i=n.getHeights(),a=Array(r.length);a[0]=r[0];let o=r[0];for(let e=1;e<r.length;e++)a[e]=a[e-1]+r[e],o+=r[e];let s=ac.getChunkCount(n)-1,c=t.getProperty(e.yn),l=-1/0,u=[];for(let e=Math.max(0,s-c);e<=Math.min(n.longestPath-1,s+c);e++){let t=o/(e+1),r=0,s=1,c=[],d=-1/0,f=0,p=0,m=i[0];if(e===0)d=o,p=n.getMaxHeight();else{for(;s<n.longestPath;)a[s-1]-r>=t&&(c.push(s),d=Math.max(d,a[s-1]-f),p+=m,r+=a[s-1]-r,f=a[s-1],m=i[s]),m=Math.max(m,i[s]),s++;p+=m}let h=Math.min(1/d,1/n.dar/p);h>l&&(l=h,u=c)}return u}};function sc(t,n,r){let i=t.getProperty(e.nn),a=t.getProperty(e.gn),o=new e.ii;o.setProperty(e.nn,i+a);let s=n,c=s.getTarget(),l=s.getSource().getNode(),u=s.getTarget().getNode(),d=l.getLayer().getIndex(),h=u.getLayer().getIndex(),g=[];for(let n=d;n<=h;n++){let i=new f(t);i.setType(`LONG_EDGE`),i.setProperty(e.lr,s),i.setProperty(e.Lt,`FIXED_POS`),i.setProperty(e.in,o);let a=t.getLayers()[n];n===d?i.setLayerAt(a.getNodes().length-r,a):i.setLayer(a);let l=s.getProperty(e.W);l<0&&(l=0,s.setProperty(e.W,l)),i.size.y=l;let u=Math.floor(l/2),h=new p;h.setSide(`WEST`),h.setNode(i),h.getPosition().y=u;let _=new p;_.setSide(`EAST`),_.setNode(i),_.getPosition().y=u,s.setTarget(h);let v=new m;v.copyProperties(s),v.setProperty(e.nt,null),v.setSource(_),v.setTarget(c),cc(i,s,v),g.push(v),s=v}return g}function cc(t,n,r){let i=n.getSource().getNode();i.getType()===`LONG_EDGE`?(t.setProperty(e.rr,i.getProperty(e.rr)),t.setProperty(e.ir,i.getProperty(e.ir))):(t.setProperty(e.rr,n.getSource()),t.setProperty(e.ir,r.getTarget()))}function lc(e,t){let n=[],r=0,i=0;for(;i<t.length;){let a=t[i]+r;for(;a<e.longestPath&&!e.isCutAllowed(a);)a++,r++;if(a>=e.longestPath)break;n.push(a),i++}return n}function uc(e,t){if(t.length===0)return[];let n=[-(2**53-1)];for(let t=1;t<e.longestPath;++t)e.isCutAllowed(t)&&n.push(t);return n.length===1?[]:(n.push(2**53-1),dc(t,n))}function dc(e,t){let n=[],r=0,i=0,a=0;for(;r<t.length-1&&i<e.length;){let o=e[i]+a;for(;t[r+1]<o;)r++;let s=0;for(o-t[r]>t[r+1]-o&&s++,n.push(t[r+s]),a+=t[r+s]-o,i++;i<e.length&&e[i]+a<=t[r+s];)i++;r+=1+s}return n}function fc(t){let n=new rc(t),r=pc(t),i=r.getCutIndexes(t,n);if(t.getProperty(e.Sn)&&(i=hc(t,i)),!r.guaranteeValid()&&t.hasProperty(e.En))switch(t.getProperty(e.En)){case`LOOK_BACK`:i=uc(n,i);break;case`GREEDY`:i=lc(n,i)}i.length!==0&&mc(t,i)}function pc(t){switch(t.getProperty(e.bn)){case`MANUAL`:return new ic;case`ARD`:return new ac;default:return new oc}}function mc(t,n){let r=t.getLayers(),i=0,a=0,o=n[0],s=0,c=/* @__PURE__ */ new Set,l=/* @__PURE__ */ new Set,u=0;for(;u<r.length;){let d=r[u];for(let e of d.getNodes()){for(let t of e.getOutgoingEdges())l.add(t);for(let t of e.getIncomingEdges())l.delete(t)}if(i+1===o){let i=new w(t);r.splice(u+1,0,i);let d=new w(t);r.splice(u+2,0,d);for(let n of l){c.has(n)||(s++,c.add(n));let r=new f(t);r.setProperty(e.Lt,`FIXED_SIDE`),r.setLayer(i),r.setType(`BREAKING_POINT`);let a=new p;a.setNode(r),a.setSide(`WEST`);let o=new p;o.setNode(r),o.setSide(`EAST`);let l=new f(t);l.setProperty(e.Lt,`FIXED_SIDE`),l.setLayer(d),l.setType(`BREAKING_POINT`);let u=new p;u.setNode(l),u.setSide(`WEST`);let h=new p;h.setNode(l),h.setSide(`EAST`);let g=new m;g.setSource(n.getSource()),g.setTarget(a),g.setProperty(e.cr,n.getProperty(e.cr));let _=new m;_.setSource(o),_.setTarget(u),_.setProperty(e.cr,n.getProperty(e.cr)),n.setSource(h);let v=new nc(r,l,g,_,n);r.setProperty(e.An,v),l.setProperty(e.An,v);let y=g.getSource().getNode();if(y.getType()===`BREAKING_POINT`){let t=y.getProperty(e.An);t.next=v,v.prev=t}}if(u+=2,a++,a<n.length)o=n[a];else break}i++,u++}return s}function hc(e,t){let n=[],r=[],i=null;for(let e of t){let t=new vc(e);r.push(t),i!==null&&(t.prev=i,i.suc=t),i=t}let a=_c(e);for(let t=0;t<r.length;++t){let t=null,i=r[0].selfOrNext(),o=null,s=1/0;for(let n=1;n<e.getLayers().length;++n){let r=i===null?Math.abs(n-t.index)+1:Math.abs(i.index-n),c=t===null?r+1:Math.abs(n-t.index),l,u;c<r?(l=t,u=c):(l=i,u=r);let d=gc(e,n,a[n],u);d<s&&(s=d,o=l,o.newIndex=n),i!==null&&n===i.index&&(t=i,i=i.next())}o!==null&&(n.push(o.newIndex),o.assigned=!0,o.offset())}return n.sort((e,t)=>e-t),n}function gc(t,n,r,i){return r+i**+t.getProperty(e.xn)}function _c(e){let t=Array(e.getLayers().length+1),n=/* @__PURE__ */ new Set,r=0;for(let i of e.getLayers()){t[r++]=n.size;for(let e of i.getNodes())for(let t of e.getOutgoingEdges())n.add(t);for(let e of i.getNodes())for(let t of e.getIncomingEdges())n.delete(t)}return t}var vc=class{index;newIndex=0;prev=null;suc=null;assigned=!1;constructor(e){this.index=e}selfOrNext(){return this.assigned?this.suc===null?null:this.suc.selfOrNext():this}next(){return this.suc===null?null:this.suc.selfOrNext()}offset(){if(!this.assigned)throw Error(`Cannot offset an unassigned cut.`);let e=this.newIndex-this.index;this.applyOffset(e),this.offsetPrev(e),this.offsetSuc(e)}applyOffset(e){this.index+=e}offsetPrev(e){this.prev!==null&&!this.prev.assigned&&(this.prev.applyOffset(e),this.prev.offsetPrev(e))}offsetSuc(e){this.suc!==null&&!this.suc.assigned&&(this.suc.applyOffset(e),this.suc.offsetSuc(e))}};function yc(t){if(bc(t),t.getProperty(e.Cn)){let e=/* @__PURE__ */ new Map;for(let n of t.getLayers()){let t=0;for(let r of n.getNodes())e.set(r,t++)}xc(t,e),Sc(t,e,!0),Sc(t,e,!1)}}function bc(t){let n=t.getLayers();n.unshift(new w(t));let r=!1,i=1,a=1;for(;a<n.length;){let o=n[a],s=n[i],c=[...o.getNodes()],l=c.length;for(let e of c)e.setLayer(s);if(r){for(let n of[...c].reverse())for(let r of[...n.getIncomingEdges()]){r.reverse(t,!0),t.setProperty(e.Ln,!0);let i=sc(t,r,l),a=n.getProperty(e.An),o=i[i.length-1];a.startInLayerDummy=o.getSource().getNode(),a.startInLayerEdge=o,a.endInLayerDummy=r.getTarget().getNode(),a.endInLayerEdge=r}r=!1}else c.length>0&&c[0].getType()===`BREAKING_POINT`&&(r=!0,i=-1);i++,a++}for(let e=n.length-1;e>=0;e--)n[e].getNodes().length===0&&n.splice(e,1)}function xc(t,n){for(let r of t.getLayers())for(let t of[...r.getNodes()])if(nc.isStart(t)){let r=t.getProperty(e.An);if(r.prev===null&&r.next!==null){let t=r,i=r.next;for(;i!==null;){Cc(n,i.start,i.startInLayerDummy,!1,!0),Dc(n,t.end),Dc(n,i.start),Dc(n,i.startInLayerDummy),Dc(n,i.endInLayerDummy),i.endInLayerEdge.setTarget(t.endInLayerEdge.getTarget()),t.endInLayerEdge.setTarget(null),t.end.setLayer(null),i.start.setLayer(null),i.startInLayerDummy.setLayer(null),i.endInLayerDummy.setLayer(null);let r=new nc(t.start,i.end,t.nodeStartEdge,i.startEndEdge,i.originalEdge);r.startInLayerDummy=t.startInLayerDummy,r.startInLayerEdge=t.startInLayerEdge,r.endInLayerDummy=t.endInLayerDummy,r.endInLayerEdge=i.endInLayerEdge,r.prev=t.prev,r.next=i.next,t.start.setProperty(e.An,r),i.end.setProperty(e.An,r),i=i.next,t=r}}}}function Sc(t,n,r){let i=r?nc.isEnd:nc.isStart,a=!1;do{a=!1;let o=r?[...t.getLayers()].reverse():t.getLayers();for(let t of o){let o=[...t.getNodes()];r||o.reverse();for(let t of o)if(i(t)){let i=t,o=t.getProperty(e.An);a=Cc(n,i,r?o.endInLayerDummy:o.startInLayerDummy,r,!1)}}}while(a)}function Cc(e,t,n,r,i){let a=Tc(t,r),o=Tc(n,r),s=!1;for(;a!==null&&o!==null&&(i||wc(e,a,o,r));){let i=Tc(a,r),c=Tc(o,r);Dc(e,n),Dc(e,t);let l=a.getLayer(),u=e.get(o),d=e.get(a);Ue(a,!1),Ue(o,!1),r?(n.setLayerAt(u,l),e.set(n,u),t.setLayerAt(d+1,l),e.set(t,d)):(t.setLayerAt(d,l),e.set(t,d),n.setLayerAt(u+1,l),e.set(n,u)),a.setLayer(null),o.setLayer(null),a=i,o=c,s=!0}return s}function wc(e,t,n,r){let i=t.getLayer(),a=r?n:t,o=r?t:n,s=e.get(a),c=e.get(o);for(let e=s+1;e<c;++e){let t=i.getNodes()[e];if(t.getType()!==`BREAKING_POINT`&&!Ec(t))return!1}return!0}function Tc(e,t){let n=t?e.getOutgoingEdges():e.getIncomingEdges();for(let t of n){let n=t.getOtherNode(e);if(n!==null&&n.getType()===`LONG_EDGE`&&n.getLayer()!==e.getLayer())return n}return null}function Ec(e){if(e.getType()===`LONG_EDGE`){for(let t of e.getConnectedEdges())if(!t.isSelfLoop()&&e.getLayer()===t.getOtherNode(e)?.getLayer())return!0}return!1}function Dc(e,t){let n=e.get(t),r=t.getLayer().getNodes();for(let t=n+1;t<r.length;++t){let n=r[t];e.set(n,e.get(n)-1)}}function Oc(t){let n=t.getProperty(e.B);for(let r of t.getLayers())for(let i of[...r.getNodes()])if(nc.isEnd(i)){let r=i.getProperty(e.An);r.next===null&&kc(t,r,n)}}function kc(t,n,r){let i=[];switch(r){case`SPLINES`:{let t=n.nodeStartEdge.getProperty(e.Dr)??[],r=n.startEndEdge.getProperty(e.Dr)??[],i=n.originalEdge.getProperty(e.Dr)??[],a=n.nodeStartEdge.getProperty(e.Tr)??[],o=n.startEndEdge.getProperty(e.Tr)??[],s=n.originalEdge.getProperty(e.Tr)??[],c=[];c.push(...t);for(let e of r)e.inverseOrder=!0;c.push(...[...r].reverse()),c.push(...i);let l=[];l.push(...a),l.push(...[...o].reverse()),l.push(...s),n.originalEdge.setProperty(e.Dr,c),n.originalEdge.setProperty(e.Tr,l),n.originalEdge.setProperty(e.Or,n.originalEdge),n.nodeStartEdge.setProperty(e.Dr,null),n.nodeStartEdge.setProperty(e.Tr,null),n.startEndEdge.setProperty(e.Dr,null),n.startEndEdge.setProperty(e.Tr,null);break}case`POLYLINE`:i.push(...n.nodeStartEdge.getBendPoints()),i.push(e.ti(n.start.getPosition().x,n.start.getPosition().y)),i.push(...[...n.startEndEdge.getBendPoints()].reverse()),i.push(e.ti(n.end.getPosition().x,n.end.getPosition().y)),i.push(...n.originalEdge.getBendPoints());break;default:i.push(...n.nodeStartEdge.getBendPoints()),i.push(...[...n.startEndEdge.getBendPoints()].reverse()),i.push(...n.originalEdge.getBendPoints())}let a=n.originalEdge.getBendPoints();a.splice(0,a.length,...i),n.originalEdge.setSource(n.nodeStartEdge.getSource());let o=n.nodeStartEdge.getProperty(e.nt),s=n.startEndEdge.getProperty(e.nt),c=n.originalEdge.getProperty(e.nt);if(o!==null||s!==null||c!==null){let t=[];Ac(t,c),Ac(t,s),Ac(t,o),n.originalEdge.setProperty(e.nt,t)}n.startEndEdge.setSource(null),n.startEndEdge.setTarget(null),n.nodeStartEdge.setSource(null),n.nodeStartEdge.setTarget(null),n.end.setLayer(null),n.start.setLayer(null),n.prev!==null&&kc(t,n.prev,r)}function Ac(e,t){t!=null&&e.push(...t)}function jc(t){for(let n of t.getLayers())for(let r of n.getNodes())for(let n of r.getPorts())for(let r of[...n.getOutgoingEdges()])r.getProperty(e.Sr)&&r.reverse(t,!1)}const W={NORTH:0,EAST:1,SOUTH:2,WEST:3,UNDEFINED:4},Mc=(e,t)=>W[e.getSide()]-W[t.getSide()],Nc=(t,n)=>{let r=t.getNode().getProperty(e.Lt);if(W[t.getSide()]-W[n.getSide()]!==0||!e.Lr.isOrderFixed(r))return 0;if(r===`FIXED_ORDER`){let r=t.getProperty(e.Rt),i=n.getProperty(e.Rt);if(r!==null&&i!==null&&r-i!==0)return r-i}switch(t.getSide()){case`NORTH`:return t.getPosition().x-n.getPosition().x;case`EAST`:return t.getPosition().y-n.getPosition().y;case`SOUTH`:return n.getPosition().x-t.getPosition().x;case`WEST`:return n.getPosition().y-t.getPosition().y;default:return 0}},Pc=(e,t)=>Mc(e,t)||Nc(e,t),Fc=(t,n)=>n(t).filter(t=>!t.getProperty(e.Sr)).length,Ic=(e,t)=>{if(W[e.getSide()]-W[t.getSide()]!==0)return 0;switch(e.getSide()){case`EAST`:return Fc(t,e=>e.getOutgoingEdges())-Fc(e,e=>e.getOutgoingEdges());case`WEST`:return Fc(e,e=>e.getIncomingEdges())-Fc(t,e=>e.getIncomingEdges());default:return 0}};function Lc(e,t,n){if(n-t<=2)return;let r=Math.floor((n-t)/2);for(let i=0;i<r;i++)[e[t+i],e[n-i-1]]=[e[n-i-1],e[t+i]]}function Rc(e,t){if(e.length===0)return[0,0];let n=W[t],r=n+1,i=0,a=W[e[0].getSide()];for(;i<e.length-1&&a<n;)i++,a=W[e[i].getSide()];let o=i;for(;o<e.length-1&&a<r;)o++,a=W[e[i].getSide()];return[i,o]}function zc(e){if(e.length<=1)return;let[t,n]=Rc(e,`SOUTH`);Lc(e,t,n);let[r,i]=Rc(e,`WEST`);Lc(e,r,i)}function Bc(t){let n=t.getProperty(e.Vt);for(let r of t.getLayers())for(let t of r.getNodes()){let r=t.getProperty(e.Lt),i=t.getPorts();e.Lr.isOrderFixed(r)?i.sort(Pc):e.Lr.isSideFixed(r)&&(i.sort(Mc),zc(i),n===`PORT_DEGREE`&&i.sort(Ic))}}function Vc(e){let t=e.getPorts(),n=t.length,r=0,i=n,a=2*n,o=/* @__PURE__ */ new Map;for(let e of t)switch(e.getSide()){case`EAST`:case`WEST`:o.set(e,-1);break;case`NORTH`:case`SOUTH`:{let t=e.getIncomingEdges().length,n=e.getOutgoingEdges().length;t>0&&n>0?o.set(e,i++):t>0?o.set(e,r++):n>0?o.set(e,a++):o.set(e,r++);break}default:o.set(e,-1)}t.sort((e,t)=>{let n=e.getSide(),r=t.getSide();if(n!==r)return Hc[n]-Hc[r];let i=o.get(e),a=o.get(t);return i===a?0:n===`NORTH`?i-a:a-i})}const Hc={UNDEFINED:0,NORTH:1,EAST:2,SOUTH:3,WEST:4};function Uc(t,n,r,i){let a=new f(t);a.setType(`NORTH_SOUTH_PORT`),a.setProperty(e.Lt,`FIXED_POS`);let o=0;if(n!==null){let t=new p;t.setProperty(e.lr,n),a.setProperty(e.lr,n.getNode()),t.setSide(`WEST`),t.setNode(a);for(let e of[...n.getIncomingEdges()])e.setTarget(t);n.setProperty(e._r,a),n.setProperty(e.vr,!1),o++}if(r!==null){let t=new p;a.setProperty(e.lr,r.getNode()),t.setProperty(e.lr,r),t.setSide(`EAST`),t.setNode(a);for(let e of[...r.getOutgoingEdges()])e.setSource(t);r.setProperty(e._r,a),r.setProperty(e.vr,!0),o++}return a.setProperty(e.Nn,o),i.push(a),a}function Wc(e,t,n,r){let[i,a,o]=t.reduce((e,t)=>{let n=t.getIncomingEdges().length>0,r=t.getOutgoingEdges().length>0;return n&&r?e[2].push(t):n?e[0].push(t):r&&e[1].push(t),e},[[],[],[]]);for(let t of i)r.push(Uc(e,t,null,n));for(let t of a)r.push(Uc(e,null,t,n));for(let t of o)r.push(Uc(e,t,t,n))}function Gc(t){for(let n of t.getLayers()){let r=-1;for(let i of[...n.getNodes()]){if(r++,!(i.getType()===`NORMAL`&&e.Lr.isSideFixed(i.getProperty(e.Lt))))continue;!e.Lr.isOrderFixed(i.getProperty(e.Lt))&&t.getProperty(e.O)===`NONE`&&Vc(i),i.setProperty(e.Zn,i);let a=[],o=[],s=[];Wc(t,i.getPorts(`NORTH`),a,s);let c=r,l=i;for(let t of a)t.setLayerAt(c,n),r++,t.setProperty(e.Zn,i),t.getPorts()[0].getProperty(e.lr)?.getProperty(e.m)||(t.hasProperty(e.Qn)||t.setProperty(e.Qn,[]),t.getProperty(e.Qn).push(l));Wc(t,[...i.getPorts(`SOUTH`)].reverse(),o,s);let u=i;for(let t of o)t.setLayerAt(++r,n),t.setProperty(e.Zn,i),t.getPorts()[0].getProperty(e.lr)?.getProperty(e.m)||(u.hasProperty(e.Qn)||u.setProperty(e.Qn,[]),u.getProperty(e.Qn).push(t));s.length>0&&i.setProperty(e.On,s)}}}const Kc={NORTH:0,EAST:1,SOUTH:2,WEST:3,UNDEFINED:4};function G(e){return Kc[e]}function qc(e){switch(e){case`NORTH`:return`EAST`;case`EAST`:return`SOUTH`;case`SOUTH`:return`WEST`;case`WEST`:return`NORTH`;default:return`UNDEFINED`}}function Jc(e){switch(e){case`NORTH`:return`WEST`;case`WEST`:return`SOUTH`;case`SOUTH`:return`EAST`;case`EAST`:return`NORTH`;default:return`UNDEFINED`}}var Yc=class{id=0;lLabels=[];size={x:0,y:0};position={x:0,y:0};layoutDirection;labelLabelSpacing;side=null;alignment=null;alignmentReferenceSLPort=null;constructor(t){let n=t.getSLHolder().getLNode();this.layoutDirection=n.getGraph().getProperty(e.F),this.labelLabelSpacing=n.getGraph().getProperty(e.an)}addLLabels(e){for(let t of e)this.lLabels.push(t),this.updateSize(t)}getLLabels(){return this.lLabels}getSize(){return this.size}getPosition(){return this.position}getSide(){return this.side}setSide(e){this.side=e}getAlignment(){return this.alignment}setAlignment(e){this.alignment=e}getAlignmentReferenceSLPort(){return this.alignmentReferenceSLPort}setAlignmentReferenceSLPort(e){this.alignmentReferenceSLPort=e}updateSize(e){let t=e.size;this.layoutDirection===`LEFT`||this.layoutDirection===`RIGHT`?(this.size.x=Math.max(this.size.x,t.x),this.size.y+=t.y,this.lLabels.length>1&&(this.size.y+=this.labelLabelSpacing)):(this.size.x+=t.x,this.size.y=Math.max(this.size.y,t.y),this.lLabels.length>1&&(this.size.x+=this.labelLabelSpacing))}applyPlacement(e){this.layoutDirection===`LEFT`||this.layoutDirection===`RIGHT`?this.applyPlacementForHorizontalLayout(e):this.applyPlacementForVerticalLayout(e)}applyPlacementForHorizontalLayout(e){let t=this.position.x,n=this.position.y;for(let r of this.lLabels){let i=r.position;i.x=this.alignment===`LEFT`||this.side===`EAST`?t:this.alignment===`RIGHT`||this.side===`WEST`?t+this.size.x-r.size.x:t+(this.size.x-r.size.x)/2,i.y=n,i.x+=e.x,i.y+=e.y,n+=r.size.y+this.labelLabelSpacing}}applyPlacementForVerticalLayout(e){let t=this.position.x,n=this.position.y;for(let r of this.lLabels){let i=r.position;i.x=t,i.y=this.side===`NORTH`?n+this.size.y-r.size.y:n,i.x+=e.x,i.y+=e.y,t+=r.size.x+this.labelLabelSpacing}}};function Xc(e){if(e.has(`UNDEFINED`))throw Error(`Port sides must not contain UNDEFINED`);switch(e.size){case 1:return`ONE_SIDE`;case 2:{let t=e.has(`EAST`)&&e.has(`WEST`),n=e.has(`NORTH`)&&e.has(`SOUTH`);return t||n?`TWO_SIDES_OPPOSING`:`TWO_SIDES_CORNER`}case 3:return`THREE_SIDES`;case 4:return`FOUR_SIDES`;default:return null}}var Zc=class{slHolder;slPorts=[];slEdges=/* @__PURE__ */ new Set;slLabels=null;selfLoopType=null;slPortsBySide=null;leftmostPort=null;rightmostPort=null;occupiedPortSides=/* @__PURE__ */ new Set;routingSlot=[,,,,,].fill(0);constructor(e){this.slHolder=e}getSLHolder(){return this.slHolder}addSelfLoopEdge(e){if(this.slEdges.has(e))return;this.slEdges.add(e),e.setSLHyperLoop(this);let t=e.getSLSource();this.slPorts.includes(t)||this.slPorts.push(t);let n=e.getSLTarget();this.slPorts.includes(n)||this.slPorts.push(n);let r=e.getLEdge().getLabels();r.length>0&&(this.slLabels===null&&(this.slLabels=new Yc(this)),this.slLabels.addLLabels(r))}computePortsPerSide(){this.slPortsBySide=/* @__PURE__ */ new Map;for(let e of this.slPorts){let t=e.getLPort().getSide(),n=this.slPortsBySide.get(t)??[];n.push(e),this.slPortsBySide.set(t,n)}this.selfLoopType=Xc(new Set(this.slPortsBySide.keys()))}getSLPorts(){return this.slPorts}getSLEdges(){return this.slEdges}getSLLabels(){return this.slLabels}getSelfLoopType(){return this.selfLoopType}getSLPortsBySideMap(){return this.slPortsBySide}getSLPortsBySide(e){return this.slPortsBySide.get(e)??[]}hasSLPortsOnSide(e){return this.slPortsBySide.has(e)}getLeftmostPort(){return this.leftmostPort}setLeftmostPort(e){this.leftmostPort=e}getRightmostPort(){return this.rightmostPort}setRightmostPort(e){this.rightmostPort=e}getOccupiedPortSides(){return this.occupiedPortSides}getRoutingSlot(e){return this.routingSlot[G(e)]}setRoutingSlot(e,t){this.routingSlot[G(e)]=t;let n=this.slHolder.getRoutingSlotCount(),r=G(e);n[r]=Math.max(n[r],t+1)}},Qc=class{lEdge;slHyperLoop=null;slSource;slTarget;constructor(e,t,n){this.lEdge=e,this.slSource=t,this.slTarget=n,t.getOutgoingSLEdges().push(this),n.getIncomingSLEdges().push(this)}getLEdge(){return this.lEdge}getSLHyperLoop(){return this.slHyperLoop}setSLHyperLoop(e){this.slHyperLoop=e}getSLSource(){return this.slSource}getSLTarget(){return this.slTarget}getLabelSide(){return this.slHyperLoop.getSLLabels().getSide()}},$c=class{lPort;onlySelfLoops;incomingSLEdges=[];outgoingSLEdges=[];hidden=!1;constructor(e){this.lPort=e,this.onlySelfLoops=e.getConnectedEdges().length>0&&e.getConnectedEdges().every(e=>e.isSelfLoop())}getLPort(){return this.lPort}hadOnlySelfLoops(){return this.onlySelfLoops}isHidden(){return this.hidden}setHidden(e){this.hidden=e}getIncomingSLEdges(){return this.incomingSLEdges}getOutgoingSLEdges(){return this.outgoingSLEdges}getSLNetFlow(){return this.incomingSLEdges.length-this.outgoingSLEdges.length}},el=class t{lNode;slHyperLoops=[];slPorts=/* @__PURE__ */ new Map;arePortsHidden=!1;routingSlotCount=[,,,,,].fill(0);constructor(e){this.lNode=e}static needsSelfLoopProcessing(e){return e.getType()===`NORMAL`&&e.getOutgoingEdges().some(e=>e.isSelfLoop())}static install(n){if(!t.needsSelfLoopProcessing(n))throw Error(`AssertionError: needsSelfLoopProcessing`);let r=new t(n);return n.setProperty(e.Cr,r),r.initialize(),r}getLNode(){return this.lNode}getSLHyperLoops(){return this.slHyperLoops}getSLPortMap(){return this.slPorts}arePortsHiddenFlag(){return this.arePortsHidden}setPortsHidden(e){this.arePortsHidden=e}getRoutingSlotCount(){return this.routingSlotCount}initialize(){let e=[];for(let t of this.lNode.getOutgoingEdges())t.isSelfLoop()&&e.push(new Qc(t,this.selfLoopPortFor(t.getSource()),this.selfLoopPortFor(t.getTarget())));for(let e of this.slPorts.values())e.getLPort().id=0;for(let e of this.slPorts.values())e.getLPort().id===0&&this.slHyperLoops.push(this.initializeHyperLoop(e))}selfLoopPortFor(e){let t=this.slPorts.get(e);return t===void 0&&(t=new $c(e),this.slPorts.set(e,t)),t}initializeHyperLoop(e){let t=new Zc(this),n=[e];for(;n.length>0;){let e=n.shift();e.getLPort().id=1;for(let r of e.getOutgoingSLEdges()){t.addSelfLoopEdge(r);let e=r.getSLTarget();e.getLPort().id===0&&n.push(e)}for(let r of e.getIncomingSLEdges()){t.addSelfLoopEdge(r);let e=r.getSLSource();e.getLPort().id===0&&n.push(e)}}return t}};function tl(e){for(let t of e.getLayerlessNodes())if(el.needsSelfLoopProcessing(t)){let e=el.install(t);nl(e),il(e)}}function nl(e){for(let t of e.getSLHyperLoops())for(let e of t.getSLEdges())rl(e.getLEdge())}function rl(e){e.setSource(null),e.setTarget(null)}function il(t){let n=t.getLNode(),r=n.getNestedGraph(),i=e.Lr.isOrderFixed(n.getProperty(e.Lt)),a=r!==null&&r.getProperty(e.Gn).has(`EXTERNAL_PORTS`);if(!(i||a))for(let e of t.getSLPortMap().values())e.hadOnlySelfLoops()&&(e.getLPort().setNode(null),e.setHidden(!0),t.setPortsHidden(!0))}function al(t){let n=t.getProperty(e.en)*2;for(let e of t.getLayers()){let{north:t,south:r}=ol(e);sl(t,!0,n),sl(r,!1,n)}}function ol(t){let n=[],r=[];for(let i of t.getNodes()){if(i.getType()!==`EXTERNAL_PORT`)continue;let t=i.getProperty(e.Un);t===`NORTH`?n.push(i):t===`SOUTH`&&r.push(i)}return{north:n,south:r}}function sl(t,n,r){let i=n?0:r*(t.length-1),a=n?r:-r;for(let n of t){n.setProperty(e.p,`CENTER`),n.size.x=i;for(let e of n.getPorts(`EAST`))e.getPosition().x=i;i+=a}}var cl=class{process(e){this.processEasternAndWesternPortDummies(e),this.processNorthernAndSouthernPortDummies(e)}processEasternAndWesternPortDummies(t){if(!e.Lr.isOrderFixed(t.getProperty(e.Lt)))return;let n=t.getLayers();n.length!==0&&(this.processEW(n[0]),this.processEW(n[n.length-1]))}processEW(t){let n=[...t.getNodes()];n.sort((t,n)=>{let r=t.getType(),i=n.getType(),a=t.getProperty(e.yr),o=n.getProperty(e.yr);return i===`EXTERNAL_PORT`?r===`EXTERNAL_PORT`?a===o?0:a<o?-1:1:1:-1});let r=null;for(let t of n){if(t.getType()!==`EXTERNAL_PORT`)break;let n=t.getProperty(e.Un);if(n===`WEST`||n===`EAST`){if(r!==null){let n=r.getProperty(e.Qn);n??(n=[],r.setProperty(e.Qn,n)),n.push(t)}r=t}}}processNorthernAndSouthernPortDummies(t){if(!e.Lr.isSideFixed(t.getProperty(e.Lt)))return;let n=t.getLayers(),r=n.length,i=[/* @__PURE__ */ new Map,/* @__PURE__ */ new Map],a=[[],[]],o=[];for(let s=0;s<r;s++){let r=n[s],c=i[s],l=/* @__PURE__ */ new Map;i.push(l);let u=a[s],d=[];a.push(d);for(let n of r.getNodes())if(this.isNorthernOrSouthernDummy(n))o.push(n);else{for(let r of n.getIncomingEdges()){let n=r.getSource()?.getNode();if(n==null||!this.isNorthernOrSouthernDummy(n))continue;let i=n.getProperty(e.Hn)??n,a=c.get(i)??null;a===null&&(a=this.createDummy(t,n),c.set(i,a),u.push(a)),r.setSource(a.getPorts()[1])}for(let r of n.getOutgoingEdges()){let n=r.getTarget()?.getNode();if(n==null||!this.isNorthernOrSouthernDummy(n))continue;let i=n.getProperty(e.Hn)??n,a=l.get(i)??null;a===null&&(a=this.createDummy(t,n),l.set(i,a),d.push(a)),r.setTarget(a.getPorts()[0])}}}for(let e=0;e<a.length;e++){let r=a[e];if(r.length===0)continue;let o;e===0?(o=new w(t),n.unshift(o)):e===i.length-1?(o=new w(t),n.push(o)):o=n[e-1];for(let e of r)e.setLayer(o)}for(let e of o)e.setLayer(null);t.setProperty(e.Vn,o)}isNorthernOrSouthernDummy(t){if(t.getType()!==`EXTERNAL_PORT`)return!1;let n=t.getProperty(e.Un);return n===`NORTH`||n===`SOUTH`}createDummy(t,n){let r=new f(t);r.copyProperties(n),r.setInLayerConstraint(n.getInLayerConstraint()),r.setProperty(e.Hn,n),r.setProperty(e.Lt,`FIXED_POS`),r.setProperty(e.p,`CENTER`),r.setType(`EXTERNAL_PORT`);let i=new p;i.setNode(r),i.setSide(`WEST`);let a=new p;return a.setNode(r),a.setSide(`EAST`),r}};function ll(e){let t=e.getLayers();t.length>0&&ul(t[0],e),t.length>1&&ul(t[t.length-1],e)}function ul(t,n){let r=n.getProperty(e.Lt);if(!(e.Lr.isRatioFixed(r)||e.Lr.isPosFixed(r)))return;let i=n.getActualSize().y;for(let a of t.getNodes()){if(a.getType()!==`EXTERNAL_PORT`)continue;let t=a.getProperty(e.Un);if(t!==`EAST`&&t!==`WEST`)continue;let o=a.getProperty(e.yr);r===`FIXED_RATIO`&&(o*=i),a.getPosition().y=o-(a.getProperty(e.Ft)?.y??0),a.position.y-=n.getPadding().top+n.getOffset().y}}function dl(e){let t=fl(e);hl(e,t),Sl(e,t),Tl(e),Cl(e),El(e)}function fl(t){let n=t.getProperty(e.Vn);if(n==null||n.length===0)return[];let r=[];for(let e of n)pl(e),r.push(e);for(let n of t.getLayers())for(let t of n.getNodes()){if(t.getType()!==`EXTERNAL_PORT`)continue;let n=t.getProperty(e.Hn);n!=null&&ml(t,n)}let i=t.getLayers();for(let e of r)e.setLayer(i[i.length-1]);return r}function pl(t){let n=t.getProperty(e.Un),r=t.getPorts()[0];n===`NORTH`?r.setSide(`SOUTH`):n===`SOUTH`&&r.setSide(`NORTH`)}function ml(t,n){let r=new p;r.setNode(t),r.setSide(t.getProperty(e.Un));let i=n.getPorts()[0],a=new m;a.setSource(r),a.setTarget(i)}function hl(t,n){let r=t.getProperty(e.Lt),i=t.getSize(),a=t.getPadding(),o=i.x+a.left+a.right,s=0-t.getOffset().y,c=i.y+a.top+a.bottom-t.getOffset().y,l=[],u=[];for(let t of n){switch(r){case`FREE`:case`FIXED_SIDE`:case`FIXED_ORDER`:gl(t);break;case`FIXED_RATIO`:_l(t,o);break;case`FIXED_POS`:vl(t),i.x=Math.max(i.x,t.getPosition().x+t.getSize().x/2)}switch(t.getProperty(e.Un)){case`NORTH`:t.getPosition().y=s,l.push(t);break;case`SOUTH`:t.getPosition().y=c,u.push(t)}}r===`FREE`||r===`FIXED_SIDE`?(yl(l,t),yl(u,t)):r===`FIXED_ORDER`&&(bl(l,t),bl(u,t))}function gl(t){let n=t.getPorts()[0];if(n.getDegree()===0){t.getPosition().x=0;return}let r=0;for(let e of n.getConnectedPorts())r+=e.getNode().getPosition().x+e.getPosition().x+e.getAnchor().x;let i=t.getProperty(e.Ft),a=i==null?0:i.x;t.getPosition().x=r/n.getDegree()-a}function _l(t,n){let r=t.getProperty(e.Ft),i=r==null?0:r.x;t.getPosition().x=n*t.getProperty(e.yr)-i}function vl(t){let n=t.getProperty(e.Ft),r=n==null?0:n.x;t.getPosition().x=t.getProperty(e.yr)-r}function yl(e,t){e.length!==0&&(e.sort((e,t)=>e.getPosition().x-t.getPosition().x),xl(e,t))}function bl(t,n){t.length!==0&&(t.sort((t,n)=>t.getProperty(e.yr)-n.getProperty(e.yr)),xl(t,n))}function xl(t,n){let r=n.getProperty(e.pn),i=t[0].getPosition().x+t[0].getSize().x+t[0].getMargin().right+r;for(let e=1;e<t.length;e++){let a=t[e].getPosition(),o=t[e].getSize(),s=t[e].getMargin(),c=a.x-s.left-i;c<0&&(a.x-=c);let l=n.getSize();l.x=Math.max(l.x,a.x+o.x),i=a.x+o.x+s.right+r}}function Sl(t,n){let r=n.filter(t=>t.getProperty(e.Un)===`NORTH`),i=n.filter(t=>t.getProperty(e.Un)===`SOUTH`),a=t.getProperty(e.br),o=t.getProperty(e.ln),s=t.getProperty(e.$t),c=new $n(s),l=e=>{let t=/* @__PURE__ */ new Set;for(let n of e){let e=n.getPorts()[0];if(e!=null)for(let n of e.getIncomingEdges()){let e=n.getSource()?.getNode();e!=null&&t.add(e)}}return[...t]};if(r.length>0){let e=c.routeEdgesForDirection(l(r),r,a,Yn.sourceSide,Yn.targetSide,Yn.positionFn,-o-t.getOffset().y);if(e>0){let n=o+(e-1)*s;t.getOffset().y+=n,t.getSize().y+=n}}if(i.length>0){let e=c.routeEdgesForDirection(l(i),i,a,Xn.sourceSide,Xn.targetSide,Xn.positionFn,t.getSize().y+o-t.getOffset().y);e>0&&(t.getSize().y+=o+(e-1)*s)}}function Cl(e){let t=e.getLayers();t.length!==0&&(wl(t[0],e),wl(t[t.length-1],e))}function wl(t,n){let r=n.getProperty(e.Lt),i=n.getPadding(),a=n.getOffset(),o=n.getSize(),s=o.y+i.top+i.bottom,c=s;for(let n of t.getNodes()){if(n.getType()!==`EXTERNAL_PORT`)continue;let t=n.getProperty(e.Un),s=n.getPosition(),l=n.getProperty(e.Wn);if(l==null){let t=n.getProperty(e.lr);l=t instanceof p?t.getSize():{x:0,y:0}}switch(t){case`EAST`:s.x=o.x+i.right-a.x;break;case`WEST`:s.x=-a.x-i.left}let u=0;if(t===`EAST`||t===`WEST`){let t=n.getProperty(e.Ft),c=t==null?0:t.y;if(r===`FIXED_RATIO`){let t=n.getProperty(e.yr)??0;s.y=o.y*t-c,u=s.y+l.y,s.y-=i.top+a.y}else r===`FIXED_POS`&&(s.y=(n.getProperty(e.yr)??0)-c,u=s.y+l.y,s.y-=i.top+a.y)}c=Math.max(c,u)}o.y+=c-s;for(let n of t.getNodes()){if(n.getType()!==`EXTERNAL_PORT`)continue;let t=n.getProperty(e.Un),r=n.getPosition();switch(t){case`NORTH`:r.y=-a.y;break;case`SOUTH`:r.y=o.y+i.top+i.bottom-a.y}}}function Tl(t){let n=[];for(let r of t.getLayers())for(let t of r.getNodes()){if(t.getType()!==`EXTERNAL_PORT`||!t.hasProperty(e.Hn))continue;let r=null,i=null,a=null;for(let e of t.getPorts())switch(e.getSide()){case`WEST`:r=e;break;case`EAST`:i=e;break;default:a=e}if(r===null||i===null||a===null)continue;let o=a.getOutgoingEdges()[0];if(o===void 0)continue;let s=o.getBendPoints().map(e=>({...e})),c={x:a.getPosition().x+t.getPosition().x,y:a.getPosition().y+t.getPosition().y};s.unshift(c);let l=[...o.getBendPoints()].reverse().map(e=>({...e}));l.push({...c});let u=t.getProperty(e.Hn).getPorts()[0];for(let e of[...r.getIncomingEdges()])e.setTarget(u),e.getBendPoints().push(...s.map(e=>({...e})));for(let e of[...i.getOutgoingEdges()])e.setSource(u),e.getBendPoints().unshift(...l.map(e=>({...e})));o.setSource(null),o.setTarget(null),n.push(t)}for(let e of n){e.setLayer(null);let n=t.getLayerlessNodes().indexOf(e);n!==-1&&t.getLayerlessNodes().splice(n,1)}}function El(e){let t=e.getLayers();t.length!==0&&(Dl(t[0]),Dl(t[t.length-1]))}function Dl(t){for(let n of t.getNodes()){if(n.getType()!==`EXTERNAL_PORT`)continue;let t=n.getProperty(e.Un);if(t===`EAST`||t===`WEST`)for(let e of n.getPorts())for(let t of e.getConnectedEdges()){let e=t.getBendPoints();if(e.length===0)continue;let r=t.getSource();r!==null&&r.getNode()===n&&(e[0].y=r.getAbsoluteAnchor().y);let i=t.getTarget();i!==null&&i.getNode()===n&&(e[e.length-1].y=i.getAbsoluteAnchor().y)}}}function Ol(e){for(let t of e.getLayers()){let e=-1,n=[];for(let[r,i]of[...t.getNodes()].entries()){let a=i.getInLayerConstraint();e===-1?a!==`TOP`&&(e=r):a===`TOP`&&(i.setLayer(null),i.setLayerAt(e++,t)),a===`BOTTOM`&&n.push(i)}for(let e of n)e.setLayer(null),e.setLayer(t)}}function kl(t){for(let n of t.getLayers())for(let t of n.getNodes()){if(t.getType()!==`NORMAL`)continue;let n=t.getProperty(e.Cr);n!=null&&Al(t,n)}}function Al(e,t){for(let n of t.getSLHyperLoops())for(let t of n.getSLEdges())jl(e,t);for(let n of t.getSLHyperLoops())n.getSLLabels()!==null&&n.getSLLabels().applyPlacement(e.position)}function jl(e,t){let n=t.getLEdge();n.setSource(t.getSLSource().getLPort()),n.setTarget(t.getSLTarget().getLPort());for(let t of n.getBendPoints())t.x+=e.position.x,t.y+=e.position.y}var Ml=class t{slLoopsByType=/* @__PURE__ */ new Map;targetAreas=/* @__PURE__ */ new Map;restorePorts(t){this.initTargetAreas(),this.slLoopsByType=this.gatherSelfLoopsByType(t);let n=t.getLNode().hasProperty(e.Jt)?t.getLNode().getProperty(e.Jt):t.getLNode().getGraph().getProperty(e.Jt);this.processOneSideLoops(n),this.processTwoSideCornerLoops(),this.processThreeSideLoops(),this.processFourSideLoops(),this.processTwoSideOpposingLoops(),this.restorePortList(t);for(let e of this.targetAreas.values())for(let t of e)t.setHidden(!1);t.setPortsHidden(!1),this.slLoopsByType=/* @__PURE__ */ new Map}initTargetAreas(){this.targetAreas=/* @__PURE__ */ new Map;for(let e of Nl)for(let t of[0,1,2])this.targetAreas.set(K(e,t),[])}gatherSelfLoopsByType(e){let t=/* @__PURE__ */ new Map;for(let n of e.getSLHyperLoops()){let e=t.get(n.getSelfLoopType())??[];e.push(n),t.set(n.getSelfLoopType(),e)}return t}processOneSideLoops(e){let t=this.slLoopsByType.get(`ONE_SIDE`)??[];e===`REVERSE_STACKED`&&t.reverse();for(let n of t){let t=n.getSLPorts()[0].getLPort().getSide(),r=[...n.getSLPorts()];switch(r.sort((e,t)=>e.getSLNetFlow()-t.getSLNetFlow()),e){case`SEQUENCED`:this.addToTargetAreaPorts(r,t,1,1);break;case`REVERSE_STACKED`:case`STACKED`:{let e=this.computePortListSplitIndex(r);this.addToTargetAreaPorts(r.slice(0,e),t,1,0),this.addToTargetAreaPorts(r.slice(e),t,1,1);break}default:throw Error(`Unexpected ordering: ${e}`)}}}computePortListSplitIndex(e){let t=0;for(;t<e.length&&!(e[t].getSLNetFlow()>0);t++);if(t>0&&t<e.length-1)return t;let n=0;for(;n<e.length&&!(e[n].getSLNetFlow()>0);n++);return n>0&&t<e.length-1?n:Math.floor(e.length/2)}processTwoSideCornerLoops(){for(let e of this.slLoopsByType.get(`TWO_SIDES_CORNER`)??[]){let n=t.sortedTwoSideLoopPortSides(e);this.addToTargetArea(e,n[0],2,0),this.addToTargetArea(e,n[1],0,1)}}processTwoSideOpposingLoops(){for(let e of this.slLoopsByType.get(`TWO_SIDES_OPPOSING`)??[]){let n=t.sortedTwoSideLoopPortSides(e);this.addToTargetArea(e,n[0],2,0),this.addToTargetArea(e,n[1],0,1)}}static sortedTwoSideLoopPortSides(e){let t=[...e.getSLPortsBySideMap().keys()];return t.sort((e,t)=>Pl(e)-Pl(t)),t[0]===`NORTH`&&t[1]===`WEST`&&(t[0]=`WEST`,t[1]=`NORTH`),t}static NES=[`NORTH`,`EAST`,`SOUTH`];static ESW=[`EAST`,`SOUTH`,`WEST`];static SWN=[`SOUTH`,`WEST`,`NORTH`];static WNE=[`WEST`,`NORTH`,`EAST`];processThreeSideLoops(){for(let e of this.slLoopsByType.get(`THREE_SIDES`)??[]){let t=this.determineLoopConstellation(e);this.addToTargetArea(e,t[0],2,0),this.addToTargetArea(e,t[1],1,1),this.addToTargetArea(e,t[2],0,1)}}determineLoopConstellation(e){let n=e.getSLPortsBySideMap();if(!n.has(`NORTH`))return t.ESW;if(!n.has(`EAST`))return t.SWN;if(!n.has(`SOUTH`))return t.WNE;if(!n.has(`WEST`))return t.NES;throw Error(`Impossible`)}processFourSideLoops(){for(let e of this.slLoopsByType.get(`FOUR_SIDES`)??[])for(let t of e.getSLPortsBySideMap().keys())this.addToTargetArea(e,t,1,1)}addToTargetArea(e,t,n,r){this.addToTargetAreaPorts(e.getSLPortsBySide(t),t,n,r)}addToTargetAreaPorts(e,t,n,r){let i=e.filter(e=>e.isHidden());i.reverse();let a=this.targetAreas.get(K(t,n));r===0?a.unshift(...i):a.push(...i)}restorePortList(e){let t=e.getLNode(),n=[...t.getPorts()],r=0,i=t.getPorts();i.length=0,this.addAll(this.targetAreas.get(K(`NORTH`,0)),t),r=this.addAllThat(n,r,e=>e.getSide()===`NORTH`&&this.isNorthSouthPortWithWestOrWestEastConnections(e),i),this.addAll(this.targetAreas.get(K(`NORTH`,1)),t),r=this.addAllThat(n,r,e=>e.getSide()===`NORTH`,i),this.addAll(this.targetAreas.get(K(`NORTH`,2)),t),this.addAll(this.targetAreas.get(K(`EAST`,0)),t),this.addAll(this.targetAreas.get(K(`EAST`,1)),t),r=this.addAllThat(n,r,e=>e.getSide()===`EAST`,i),this.addAll(this.targetAreas.get(K(`EAST`,2)),t),this.addAll(this.targetAreas.get(K(`SOUTH`,0)),t),r=this.addAllThat(n,r,e=>e.getSide()===`SOUTH`&&this.isNorthSouthPortWithEastConnections(e),i),this.addAll(this.targetAreas.get(K(`SOUTH`,1)),t),r=this.addAllThat(n,r,e=>e.getSide()===`SOUTH`,i),this.addAll(this.targetAreas.get(K(`SOUTH`,2)),t),this.addAll(this.targetAreas.get(K(`WEST`,0)),t),r=this.addAllThat(n,r,e=>e.getSide()===`WEST`,i),this.addAll(this.targetAreas.get(K(`WEST`,1)),t),this.addAll(this.targetAreas.get(K(`WEST`,2)),t)}addAll(e,t){for(let n of e)n.getLPort().setNode(t)}addAllThat(e,t,n,r){for(let i=t;i<e.length;i++){let t=e[i];if(n(t))r.push(t);else return i}return e.length}isNorthSouthPortWithWestOrWestEastConnections(e){return this.northSouthPortConnectionSides(e).has(`WEST`)}isNorthSouthPortWithEastConnections(e){return this.northSouthPortConnectionSides(e).has(`EAST`)}northSouthPortConnectionSides(t){let n=/* @__PURE__ */ new Set,r=t.getProperty(e._r);if(r!=null)for(let i of r.getPorts())i.getProperty(e.lr)===t&&i.getConnectedEdges().length>0&&n.add(i.getSide());return n}};const Nl=[`NORTH`,`EAST`,`SOUTH`,`WEST`];function K(e,t){return`${e}-${t}`}function Pl(e){switch(e){case`NORTH`:return 0;case`EAST`:return 1;case`SOUTH`:return 2;case`WEST`:return 3;default:return 4}}const Fl=[{name:`NORTH`,firstSide:`NORTH`,secondSide:`NORTH`},{name:`SOUTH`,firstSide:`SOUTH`,secondSide:`SOUTH`},{name:`EAST`,firstSide:`EAST`,secondSide:`EAST`},{name:`WEST`,firstSide:`WEST`,secondSide:`WEST`},{name:`NORTH_WEST_CORNER`,firstSide:`WEST`,secondSide:`NORTH`},{name:`NORTH_EAST_CORNER`,firstSide:`NORTH`,secondSide:`EAST`},{name:`SOUTH_WEST_CORNER`,firstSide:`SOUTH`,secondSide:`WEST`},{name:`SOUTH_EAST_CORNER`,firstSide:`EAST`,secondSide:`SOUTH`}],Il=e=>e.firstSide!==e.secondSide;var Ll=class{assignPortSides(t){let n=t.getLNode().hasProperty(e.qt)?t.getLNode().getProperty(e.qt):t.getLNode().getGraph().getProperty(e.qt);switch(n){case`NORTH`:this.assignToNorthSide(t);break;case`NORTH_SOUTH`:this.assignToNorthOrSouthSide(t);break;case`EQUALLY`:this.assignToAllSides(t);break;default:throw Error(`Unexpected distribution: ${String(n)}`)}}assignToNorthSide(e){for(let t of e.getSLHyperLoops())for(let e of this.hiddenSelfLoopPortStream(t))e.getLPort().setSide(`NORTH`)}assignToNorthOrSouthSide(e){let t=0,n=0;for(let r of e.getSLHyperLoops()){let e=this.hiddenSelfLoopPortStream(r),i;t<=n?(i=`NORTH`,t+=e.length):(i=`SOUTH`,n+=e.length);for(let t of e)t.getLPort().setSide(i)}}assignToAllSides(e){let t=[...e.getSLHyperLoops()];t.sort((e,t)=>t.getSLPorts().length-e.getSLPorts().length);let n=0;for(let e of t){let t=Fl[n%Fl.length];this.assignToTarget(e,t),n++}}assignToTarget(e,t){let n=e.getSLPorts();Il(t)&&n.sort((e,t)=>e.getLPort().getNetFlow()-t.getLPort().getNetFlow());let r=Math.floor(n.length/2);for(let e=0;e<r;e++){let r=n[e];r.isHidden()&&r.getLPort().setSide(t.firstSide)}for(let e=r;e<n.length;e++){let r=n[e];r.isHidden()&&r.getLPort().setSide(t.secondSide)}}hiddenSelfLoopPortStream(e){return e.getSLPorts().filter(e=>e.isHidden())}},Rl=class{portSideAssigner=new Ll;portRestorer=new Ml;process(t){for(let n of t.getLayers())for(let t of n.getNodes()){if(t.getType()!==`NORMAL`)continue;let n=t.getProperty(e.Cr);n!=null&&this.processNode(n)}}processNode(t){if(t.arePortsHiddenFlag())switch(t.getLNode().getProperty(e.mr)){case`UNDEFINED`:case`FREE`:this.portSideAssigner.assignPortSides(t);case`FIXED_SIDE`:this.computeSelfLoopTypes(t),this.portRestorer.restorePorts(t);break;default:throw Error(`Unexpected port constraints`)}else this.computeSelfLoopTypes(t)}computeSelfLoopTypes(e){for(let t of e.getSLHyperLoops())t.computePortsPerSide()}};function zl(e){Bl(e);for(let t of e.getSLHyperLoops())t.getSLLabels()!==null&&Kl(t)}function Bl(t){let n=null,r=null,i=t.getLNode().hasProperty(e.Jt)?t.getLNode().getProperty(e.Jt):t.getLNode().getGraph().getProperty(e.Jt);i===`SEQUENCED`&&(n=[],r=[]);for(let e of t.getSLHyperLoops())if(e.getSLLabels()!==null)switch(e.getSelfLoopType()){case`ONE_SIDE`:{let t=e.getOccupiedPortSides().values().next().value;i===`SEQUENCED`&&t===`NORTH`?n.push(e):i===`SEQUENCED`&&t===`SOUTH`?r.push(e):Vl(e,t);break}case`TWO_SIDES_CORNER`:Ul(e);break;case`TWO_SIDES_OPPOSING`:case`THREE_SIDES`:Wl(e);break;case`FOUR_SIDES`:Gl(e);break;default:throw Error(`Unexpected self loop type`)}n!==null&&(n.length>0&&Hl(n,`NORTH`),r.length>0&&Hl(r,`SOUTH`))}function Vl(e,t){switch(t){case`EAST`:case`WEST`:{let n=e.getLeftmostPort();e.getRightmostPort().getLPort().getPosition().y<n.getLPort().getPosition().y&&(n=e.getRightmostPort()),q(e,t,`TOP`,n);break}case`NORTH`:case`SOUTH`:q(e,t,`CENTER`,null);break;default:throw Error(`Impossible`)}}function Hl(e,t){let n=0;for(let t of e[0].getSLHolder().getLNode().getPorts())t.id=n++;t===`NORTH`?e.sort((e,t)=>e.getLeftmostPort().getLPort().id-t.getLeftmostPort().getLPort().id):e.sort((e,t)=>t.getLeftmostPort().getLPort().id-e.getLeftmostPort().getLPort().id);let r=0,i=e.length-1;for(;r<i;){let n=e[r],a=e[i],o=t===`NORTH`?n.getRightmostPort():n.getLeftmostPort(),s=t===`NORTH`?a.getLeftmostPort():a.getRightmostPort();q(n,t,`RIGHT`,o),q(a,t,`LEFT`,s),r++,i--}r===i&&q(e[r],t,`CENTER`,null)}function Ul(e){let t=e.getLeftmostPort().getLPort().getSide(),n=e.getRightmostPort().getLPort().getSide();if(t===`NORTH`)q(e,`NORTH`,`LEFT`,e.getLeftmostPort());else if(n===`NORTH`)q(e,`NORTH`,`RIGHT`,e.getRightmostPort());else if(t===`SOUTH`)q(e,`SOUTH`,`RIGHT`,e.getLeftmostPort());else if(n===`SOUTH`)q(e,`SOUTH`,`LEFT`,e.getRightmostPort());else throw Error(`Impossible`)}function Wl(e){let t=e.getOccupiedPortSides();if(!t.has(`NORTH`))q(e,`SOUTH`,`CENTER`,null);else if(!t.has(`SOUTH`))q(e,`NORTH`,`CENTER`,null);else if(!t.has(`WEST`))q(e,`NORTH`,`LEFT`,e.getLeftmostPort());else if(!t.has(`EAST`))q(e,`NORTH`,`RIGHT`,e.getRightmostPort());else throw Error(`Impossible`)}function Gl(e){let t=e.getLeftmostPort().getLPort().getSide(),n=e.getLeftmostPort().getLPort().getSide();t===`NORTH`||n===`NORTH`?q(e,`SOUTH`,`CENTER`,null):q(e,`NORTH`,`CENTER`,null)}function q(e,t,n,r){let i=e.getSLLabels();i.setSide(t),i.setAlignment(n),i.setAlignmentReferenceSLPort(r)}function Kl(e){let t=e.getSLLabels(),n=t.getAlignmentReferenceSLPort(),r=t.getSize(),i=t.getPosition();switch(t.getAlignment()){case`CENTER`:i.x=(e.getSLHolder().getLNode().size.x-r.x)/2;break;case`LEFT`:i.x=n.getLPort().getPosition().x+n.getLPort().getAnchor().x;break;case`RIGHT`:i.x=n.getLPort().getPosition().x+n.getLPort().getAnchor().x-r.x;break;case`TOP`:i.y=n.getLPort().getPosition().y+n.getLPort().getAnchor().y;break;default:throw Error(`Impossible`)}}var ql=class{routeSelfLoops(t){let n=t.getLNode(),r=n.size,i=n.getMargin(),a=n.getGraph().getProperty(e.$t),o=n.getGraph().getProperty(e.tn),s=n.getGraph().getProperty(e.dn),c={...i},l=this.computeRoutingSlotPositions(t,a,o,s);for(let e of t.getSLHyperLoops()){for(let t of e.getSLEdges()){let e=t.getLEdge(),n=this.computeEdgeRoutingDirection(t),i=this.computeOrthogonalBendPoints(t,n,l),a=this.modifyBendPoints(t,n,i);e.getBendPoints().length=0;for(let t of a)e.getBendPoints().push(t);for(let e of a)this.updateNewNodeMargins(r,c,e)}let t=e.getSLLabels();t!==null&&(this.placeLabels(e,t,l,o),this.updateNewNodeMarginsForLabels(r,c,t))}i.left=c.left,i.top=c.top,i.right=c.right,i.bottom=c.bottom}computeEdgeRoutingDirection(e){let t=e.getSLSource().getLPort(),n=t.getSide(),r=e.getSLTarget().getLPort(),i=r.getSide();return n===i?t.id<r.id?0:1:qc(n)===i?0:Jc(n)===i?1:+!e.getSLHyperLoop().getOccupiedPortSides().has(qc(n))}placeLabels(e,t,n,r){let i=t.getSide(),a=n[G(i)][e.getRoutingSlot(i)];switch(i){case`NORTH`:a-=r+t.getSize().y,t.getPosition().y=a;break;case`SOUTH`:a+=r,t.getPosition().y=a;break;case`WEST`:a-=r+t.getSize().x,t.getPosition().x=a;break;case`EAST`:a+=r,t.getPosition().x=a}}updateNewNodeMargins(e,t,n){t.left=Math.max(t.left,-n.x),t.right=Math.max(t.right,n.x-e.x),t.top=Math.max(t.top,-n.y),t.bottom=Math.max(t.bottom,n.y-e.y)}updateNewNodeMarginsForLabels(e,t,n){let r={...n.getPosition()};this.updateNewNodeMargins(e,t,r),r.x+=n.getSize().x,r.y+=n.getSize().y,this.updateNewNodeMargins(e,t,r)}computeRoutingSlotPositions(e,t,n,r){let i=[];for(let t of[`NORTH`,`EAST`,`SOUTH`,`WEST`])i[G(t)]=Array(e.getRoutingSlotCount()[G(t)]).fill(0);return this.initializeWithMaxLabelHeight(i,e,`NORTH`),this.initializeWithMaxLabelHeight(i,e,`SOUTH`),this.computePositions(i,e,`NORTH`,t,n,r),this.computePositions(i,e,`EAST`,t,n,r),this.computePositions(i,e,`SOUTH`,t,n,r),this.computePositions(i,e,`WEST`,t,n,r),i}initializeWithMaxLabelHeight(e,t,n){let r=e[G(n)];for(let e of t.getSLHyperLoops()){let t=e.getSLLabels();if(t!==null&&t.getSide()===n){let i=e.getRoutingSlot(n);r[i]=Math.max(r[i],t.getSize().y)}}}computePositions(e,t,n,r,i,a){let o=this.computeBaselinePosition(t,n,a),s=n===`NORTH`||n===`WEST`?-1:1,c=e[G(n)];for(let e=0;e<c.length;e++){let t=c[e];t>0&&(t+=i),c[e]=o,o+=s*(t+r)}}computeBaselinePosition(e,t,n){let r=e.getLNode(),i=r.getMargin();switch(t){case`NORTH`:return-i.top-n;case`EAST`:return r.size.x+i.right+n;case`SOUTH`:return r.size.y+i.bottom+n;case`WEST`:return-i.left-n;default:throw Error(`Impossible`)}}computeOrthogonalBendPoints(e,t,n){let r=[];return this.addOuterBendPoint(e,e.getSLSource(),n,r),this.addCornerBendPoints(e,t,n,r),this.addOuterBendPoint(e,e.getSLTarget(),n,r),r}modifyBendPoints(e,t,n){return n}addOuterBendPoint(e,t,n,r){let i=e.getSLHyperLoop(),a=t.getLPort(),o=a.getSide(),s=this.getBaseVector(o,i.getRoutingSlot(o),n),c={x:a.getPosition().x+a.getAnchor().x,y:a.getPosition().y+a.getAnchor().y};switch(a.getSide()){case`NORTH`:s.x+=c.x;break;case`SOUTH`:s.x+=c.x;break;case`EAST`:s.y+=c.y;break;case`WEST`:s.y+=c.y}r.push(s)}addCornerBendPoints(e,t,n,r){let i=e.getSLSource().getLPort(),a=e.getSLTarget().getLPort();if(i.getSide()===a.getSide())return;let o=e.getSLHyperLoop(),s=i.getSide();for(;s!==a.getSide();){let e=t===0?qc(s):Jc(s),i=this.getBaseVector(s,o.getRoutingSlot(s),n),a=this.getBaseVector(e,o.getRoutingSlot(e),n);r.push({x:i.x+a.x,y:i.y+a.y}),s=e}}getBaseVector(e,t,n){let r=n[G(e)][t];switch(e){case`NORTH`:case`SOUTH`:return{x:0,y:r};case`EAST`:case`WEST`:return{x:r,y:0};default:throw Error(`Impossible`)}}};const Jl=.01;function Yl(e){return{x:e.x>=-.01&&e.x<=Jl?0:e.x,y:e.y>=-.01&&e.y<=Jl?0:e.y}}var Xl=class extends ql{modifyBendPoints(e,t,n){let r=e.getSLSource().getLPort();n.unshift({x:r.getPosition().x+r.getAnchor().x,y:r.getPosition().y+r.getAnchor().y});let i=e.getSLTarget().getLPort();return n.push({x:i.getPosition().x+i.getAnchor().x,y:i.getPosition().y+i.getAnchor().y}),this.cutCorners(n,10)}cutCorners(e,t){if(e.length<=2)throw Error(`AssertionError: bendPoints.size() > 2`);let n=[],r=null,i=e[0],a=e[1];for(let o=2;o<e.length;o++){r=i,i=a,a=e[o];let s=Yl({x:r.x-i.x,y:r.y-i.y}),c=Yl({x:a.x-i.x,y:a.y-i.y}),l=t;l=Math.min(l,Math.abs(s.x+s.y)/2),l=Math.min(l,Math.abs(c.x+c.y)/2),s.x=Math.sign(s.x)*l,s.y=Math.sign(s.y)*l,c.x=Math.sign(c.x)*l,c.y=Math.sign(c.y)*l,n.push({x:s.x+i.x,y:s.y+i.y}),n.push({x:c.x+i.x,y:c.y+i.y})}return n}};const Zl=[`WEST`,`NORTH`,`SOUTH`,`EAST`],Ql=(e,t)=>e.getLPort().id-t.getLPort().id;var $l=class{portPenalties=null;determineLoopRoutes(e){this.assignPortIds(e.getLNode().getPorts()),this.sortHyperLoopPortLists(e);for(let t of e.getSLHyperLoops()){switch(t.getSelfLoopType()){case`ONE_SIDE`:this.determineOneSideLoopRoutes(t);break;case`TWO_SIDES_CORNER`:this.determineTwoSideCornerLoopRoutes(t);break;case`TWO_SIDES_OPPOSING`:this.determineTwoSideOpposingLoopRoutes(t);break;case`THREE_SIDES`:this.determineThreeSideLoopRoutes(t);break;case`FOUR_SIDES`:this.determineFourSideLoopRoutes(t);break;default:throw Error(`Unexpected self loop type`)}this.computeOccupiedPortSides(t)}this.portPenalties=null}assignPortIds(e){for(let t=0;t<e.length;t++)e[t].id=t}sortHyperLoopPortLists(e){for(let t of e.getSLHyperLoops())t.getSLPorts().sort(Ql)}computeOccupiedPortSides(e){let t=e.getLeftmostPort().getLPort().getSide(),n=e.getRightmostPort().getLPort().getSide();for(;t!==n;)e.getOccupiedPortSides().add(t),t=qc(t);e.getOccupiedPortSides().add(t)}determineOneSideLoopRoutes(e){let t=e.getSLPorts()[0].getLPort().getSide();this.assignLeftmostRightmostPorts(e,t,t)}determineTwoSideCornerLoopRoutes(e){let t=Ml.sortedTwoSideLoopPortSides(e);this.assignLeftmostRightmostPorts(e,t[0],t[1])}determineTwoSideOpposingLoopRoutes(e){let t=[...e.getSLPortsBySideMap().keys()].sort((e,t)=>Zl.indexOf(e)-Zl.indexOf(t)),n=e.getSLHolder(),r=this.lowestPortOnSide(e,t[0]),i=this.highestPortOnSide(e,t[1]),a=this.computeEdgePenalty(n,r,i),o=this.lowestPortOnSide(e,t[1]),s=this.highestPortOnSide(e,t[0]);a<=this.computeEdgePenalty(n,o,s)?(e.setLeftmostPort(r),e.setRightmostPort(i)):(e.setLeftmostPort(o),e.setRightmostPort(s))}determineThreeSideLoopRoutes(e){let t,n;switch(this.computeMissingPortSide(e)){case`NORTH`:t=`EAST`,n=`WEST`;break;case`EAST`:t=`SOUTH`,n=`NORTH`;break;case`SOUTH`:t=`WEST`,n=`EAST`;break;default:t=`NORTH`,n=`SOUTH`}this.assignLeftmostRightmostPorts(e,t,n)}computeMissingPortSide(e){let t=e.getSLPortsBySideMap();for(let e of[`NORTH`,`EAST`,`SOUTH`,`WEST`])if(!t.has(e))return e;throw Error(`Cannot happen`)}determineFourSideLoopRoutes(e){let t=e.getSLPorts(),n=e.getSLHolder(),r=t[t.length-1],i=t[0],a=this.computeEdgePenalty(n,r,i);for(let e=1;e<t.length;e++){let o=t[e-1],s=t[e],c=this.computeEdgePenalty(n,o,s);c>a&&(r=o,i=s,a=c)}e.setLeftmostPort(i),e.setRightmostPort(r)}assignLeftmostRightmostPorts(e,t,n){e.setLeftmostPort(this.lowestPortOnSide(e,t)),e.setRightmostPort(this.highestPortOnSide(e,n))}lowestPortOnSide(e,t){let n=e.getSLPortsBySide(t),r=n[0];for(let e of n)Ql(e,r)<0&&(r=e);return r}highestPortOnSide(e,t){let n=e.getSLPortsBySide(t),r=n[0];for(let e of n)Ql(e,r)>0&&(r=e);return r}computeEdgePenalty(e,t,n){this.portPenalties===null&&this.computePenalties(e);let r=e.getLNode().getPorts().length,i=t.getLPort().id,a=n.getLPort().id-1;a<0&&(a=r-1);let o=this.portPenalties;return i<=a?o[a]-o[i]:o[r-1]-o[i]+o[a]}computePenalties(e){let t=e.getLNode().getPorts();this.portPenalties=Array(t.length);let n=0;for(let e=0;e<t.length;e++){let r=t[e];r.getIncomingEdges().length===0&&r.getOutgoingEdges().length===0?n+=1:n+=3,this.portPenalties[e]=n}}};const eu=1e-6;var tu=class{list;cursor=0;lastReturned=-1;constructor(e){this.list=e}next(){if(this.cursor>=this.list.length)throw Error(`NoSuchElementException`);this.lastReturned=this.cursor;let e=this.list[this.cursor];return this.cursor++,e}hasNext(){return this.cursor<this.list.length}previous(){if(this.cursor<=0)throw Error(`NoSuchElementException`);return this.cursor--,this.lastReturned=this.cursor,this.list[this.cursor]}add(e){this.list.splice(this.cursor,0,e),this.cursor++,this.lastReturned=-1}remove(){if(this.lastReturned<0)throw Error(`IllegalStateException`);this.list.splice(this.lastReturned,1),this.cursor>this.lastReturned&&this.cursor--,this.lastReturned=-1}},nu=class e{cp;polarCoordinate;constructor(t,n,r){if(t instanceof e&&n instanceof e&&r!==void 0){let e=t.polarCoordinate[0],i=n.polarCoordinate[n.polarCoordinate.length-1],a={x:t.cp.x*(i-r),y:t.cp.y*(i-r)},o={x:n.cp.x*(r-e),y:n.cp.y*(r-e)};this.cp={x:(a.x+o.x)/(i-e),y:(a.y+o.y)/(i-e)},this.polarCoordinate=[];let s=!0;for(let e=1;e<t.polarCoordinate.length;e++){let n=t.polarCoordinate[e];s&&n-r>eu&&(this.polarCoordinate.push(r),s=!1),this.polarCoordinate.push(n)}s&&this.polarCoordinate.push(r)}else this.cp={x:t.x,y:t.y},this.polarCoordinate=[...n]}getCp(){return this.cp}},ru=class{knotVector=[];controlPoints=[];dim;isClamped;isBezier=!1;minKnot=0;maxKnot=0;constructor(e,t,n){if(t<1)throw Error(`The dimension must be at least 1!`);for(;n.length<=t;)n.unshift({...n[0]});if(n.length<t+1)throw Error(`At (least dimension + 1) control points are necessary!`);this.dim=t,this.isClamped=e,this.isBezier=!1,this.createUniformKnotVector(e,n.length+t-1);let r=[],i=new tu(this.knotVector);for(let e=0;e<t-1;e++)r.push(i.next());for(let e of n)r.push(i.next()),this.controlPoints.push(new nu(e,r)),r.shift()}createUniformKnotVector(e,t){if(t<2*this.dim)throw Error(`The knot vector must have at least two time the dimension elements.`);let n;if(e){this.minKnot=0,this.maxKnot=1;for(let e=0;e<this.dim;e++)this.knotVector.push(0);n=t+1-2*this.dim}else{n=t+1;let e=this.dim;this.minKnot=e/(n+1),this.maxKnot=(n-e)/n}let r=n;for(let e=1;e<n;e++)this.knotVector.push(e/r);if(this.isClamped)for(let e=0;e<this.dim;e++)this.knotVector.push(1)}getMultiplicity(e){let t=0;for(let n of this.knotVector){let r=n-e;if(r>eu)return t;r>-1e-6&&t++}return t}insertKnotAtCurrentPosition(e,t,n,r){let i=this.getMultiplicity(t);for(let a=0;a<e;a++){r.add(t);let o=[],s=n.next();for(let e=i+a;e<this.dim;e++){let e=s;s=n.next(),o.push(new nu(e,s,t))}for(let e=i+a;e<this.dim;e++)n.previous(),e>i+a&&n.remove();for(let e of o)n.add(e);if(a<e-1)for(let e=i+a;e<this.dim;e++)n.previous()}}toBezier(){let e=new tu(this.knotVector),t=new tu(this.controlPoints);if(this.isClamped)for(let t=0;t<this.dim;t++)e.next();else for(let t=0;t<this.dim-1;t++)e.next(),e.remove();let n=e.next();for(;this.maxKnot-n>eu;){let r=n,i=0;for(;Math.abs(n-r)<eu;)i++,n=e.next(),t.next();i<this.dim&&(e.previous(),this.insertKnotAtCurrentPosition(this.dim-i,r,t,e),e.next()),t.previous()}if(!this.isClamped)for(let t=0;t<this.dim-1;t++)e.next(),e.remove();this.isClamped=!0,this.isBezier=!0}getBezierCP(e=!1,t=!1){this.isBezier||this.toBezier();let n=[],r=this.controlPoints[Symbol.iterator]();e||r.next();let i=r.next();for(;!i.done;)n.push(i.value.getCp()),i=r.next();return t||n.pop(),n}};function iu(e){switch(e){case`NORTH`:return Math.PI*1.5;case`EAST`:return 0;case`SOUTH`:return Math.PI*.5;case`WEST`:return Math.PI;default:return 0}}function au(e){return{x:Math.cos(e),y:Math.sin(e)}}var ou=class extends ql{modifyBendPoints(t,n,r){let i=t.getSLHyperLoop().getSLHolder().getLNode().getGraph().getProperty(e.tn),a=[this.relativePortAnchor(t.getSLSource())];return this.addSplineControlPoints(t,n,r,a,i),a.push(this.relativePortAnchor(t.getSLTarget())),new ru(!0,3,a).getBezierCP()}relativePortAnchor(e){let t=e.getLPort();return{x:t.getPosition().x+t.getAnchor().x,y:t.getPosition().y+t.getAnchor().y}}addSplineControlPoints(e,t,n,r,i){if(n.length<2)throw Error(`AssertionError: orthoBendPoints.size() >= 2`);let a=e.getSLSource().getLPort().getSide(),o=n[0];for(let e=1;e<n.length;e++){let s=n[e];r.push(o);let c={x:(o.x+s.x)*.5,y:(o.y+s.y)*.5},l=au(iu(a));c.x+=l.x*i,c.y+=l.y*i,r.push(c),o=s,a=t===0?qc(a):Jc(a)}r.push(n[n.length-1])}},su=class{hyperEdgeSegments=[];slLoopToSegmentMap=/* @__PURE__ */ new Map;slLoopActivityOverPorts=/* @__PURE__ */ new Map;assignRoutingSlots(t){let n=this.computeLabelCrossingMatrix(t);this.createCrossingGraph(t,n);let r=t.getLNode().getGraph().getProperty(e.br);lu(this.hyperEdgeSegments,r),this.doAssignRoutingSlots(t,n),this.hyperEdgeSegments=[],this.slLoopToSegmentMap=/* @__PURE__ */ new Map,this.slLoopActivityOverPorts=/* @__PURE__ */ new Map}computeLabelCrossingMatrix(e){let t=0;for(let n of e.getSLHyperLoops())n.getSLLabels()!==null&&(n.getSLLabels().id=t++);let n=Array.from({length:t},()=>Array(t).fill(!1)),r=e.getSLHyperLoops();for(let e=0;e<r.length;e++){let t=r[e];if(t.getSLLabels()!==null)for(let i=e+1;i<r.length;i++){let e=r[i];if(e.getSLLabels()!==null){let r=cu(t,e);n[t.getSLLabels().id][e.getSLLabels().id]=r,n[e.getSLLabels().id][t.getSLLabels().id]=r}}}return n}createCrossingGraph(e,t){let n=e.getSLHyperLoops();this.hyperEdgeSegments=Array(n.length),this.slLoopToSegmentMap=/* @__PURE__ */ new Map;for(let e=0;e<n.length;e++){let t=new kn;this.hyperEdgeSegments[e]=t,this.slLoopToSegmentMap.set(n[e],t)}this.slLoopActivityOverPorts=/* @__PURE__ */ new Map,this.computeLoopActivity(e);for(let e=0;e<n.length-1;e++){let r=n[e];for(let i=e+1;i<n.length;i++)this.createDependencies(r,n[i],t)}}computeLoopActivity(e){let t=e.getSLHyperLoops(),n=e.getLNode().getPorts();for(let e of t){let t=Array(n.length).fill(!1);this.slLoopActivityOverPorts.set(e,t);let r=e.getLeftmostPort().getLPort().id-1,i=e.getRightmostPort().getLPort().id;for(;r!==i;)r=(r+1)%n.length,t[r]=!0}}createDependencies(e,t,n){let r=this.countCrossings(e,t),i=this.countCrossings(t,e),a=this.slLoopToSegmentMap.get(e),o=this.slLoopToSegmentMap.get(t);r<i?A.createAndAddRegular(a,o,i-r):i<r?A.createAndAddRegular(o,a,r-i):(r!==0||this.labelsOverlapWithMatrix(e,t,n))&&(A.createAndAddRegular(a,o,0),A.createAndAddRegular(o,a,0))}countCrossings(e,t){let n=this.slLoopActivityOverPorts.get(t),r=0;for(let t of e.getSLPorts())n[t.getLPort().id]&&r++;return r}labelsOverlapWithMatrix(e,t,n){return e.getSLLabels()===null||t.getSLLabels()===null?!1:n[e.getSLLabels().id][t.getSLLabels().id]}doAssignRoutingSlots(e,t){this.assignRawRoutingSlotsToSegments(),this.assignRawRoutingSlotsToLoops(e),this.shiftTowardsNode(e,t)}assignRawRoutingSlotsToSegments(){let e=[];for(let t of this.hyperEdgeSegments)t.setInWeight(t.getIncomingSegmentDependencies().length),t.setOutWeight(t.getOutgoingSegmentDependencies().length),t.getOutWeight()===0&&(t.setRoutingSlot(0),e.push(t));for(;e.length>0;){let t=e.shift(),n=t.getRoutingSlot()+1;for(let r of t.getIncomingSegmentDependencies()){let t=r.getSource();t.setRoutingSlot(Math.max(t.getRoutingSlot(),n)),t.setOutWeight(t.getOutWeight()-1),t.getOutWeight()===0&&e.push(t)}}}assignRawRoutingSlotsToLoops(e){for(let t of e.getSLHyperLoops()){let e=this.slLoopToSegmentMap.get(t);for(let n of t.getOccupiedPortSides())t.setRoutingSlot(n,e.getRoutingSlot())}}shiftTowardsNode(e,t){let n=Array(e.getLNode().getPorts().length).fill(0);this.shiftTowardsNodeOnSide(e,`NORTH`,n,t),this.shiftTowardsNodeOnSide(e,`EAST`,n,t),this.shiftTowardsNodeOnSide(e,`SOUTH`,n,t),this.shiftTowardsNodeOnSide(e,`WEST`,n,t)}shiftTowardsNodeOnSide(e,t,n,r){let i=e.getSLHyperLoops().filter(e=>e.getOccupiedPortSides().has(t)).sort((e,n)=>e.getRoutingSlot(t)-n.getRoutingSlot(t)),a=e.getLNode(),o=2**53-1,s=-(2**53-1);for(let e of a.getPorts())e.getSide()===t&&(o=Math.min(o,e.id),s=Math.max(s,e.id));if(o===2**53-1)for(let e=0;e<i.length;e++)i[e].setRoutingSlot(t,e);else{let e=Array(r.length).fill(-1);for(let a of i){let i=this.slLoopActivityOverPorts.get(a),c=0;for(let e=o;e<=s;e++)i[e]&&(c=Math.max(c,n[e]));if(a.getSLLabels()!==null){let t=a.getSLLabels().id,n=/* @__PURE__ */ new Set;for(let i=0;i<r.length;i++)r[t][i]&&n.add(e[i]);for(;n.has(c);)c++}a.setRoutingSlot(t,c);for(let e=o;e<=s;e++)i[e]&&(n[e]=c+1);a.getSLLabels()!==null&&(e[a.getSLLabels().id]=c)}}}};function cu(e,t){let n=e.getSLLabels(),r=t.getSLLabels();if(n===null||r===null||n.getSide()!==r.getSide()||n.getSide()===`EAST`||n.getSide()===`WEST`)return!1;let i=n.getPosition().x,a=i+n.getSize().x,o=r.getPosition().x;return i<=o+r.getSize().x&&a>=o}function lu(e,t){let n=Cn.detectCycles(e,!1,t);for(let e of n)e.getWeight()===0?e.remove():e.reverse()}function uu(t){switch(t.getProperty(e.B)){case`POLYLINE`:return new Xl;case`SPLINES`:return new ou;default:return new ql}}function du(t){let n=new $l,r=new su,i=uu(t);for(let a of t.getLayers())for(let t of a.getNodes()){if(t.getType()!==`NORMAL`)continue;let a=t.getProperty(e.Cr);a!=null&&fu(a,i,n,r)}}function fu(e,t,n,r){n.determineLoopRoutes(e),zl(e),r.assignRoutingSlots(e),t.routeSelfLoops(e)}function pu(e){for(let t of e.getLayers()){let n=[];for(let r of t.getNodes())for(let t of r.getPorts()){let r=[...t.getOutgoingEdges()];for(let t of r){if(t.getSource().getNode()!==t.getTarget().getNode())continue;let r=t.getSource(),i=t.getTarget(),a=r.getSide(),o=i.getSide();((a===`NORTH`||a===`SOUTH`)&&o===`WEST`||a===`SOUTH`&&o===`NORTH`||a===`EAST`&&o!==`EAST`)&&t.reverse(e,!1);let s=t.getSource().getSide(),c=t.getTarget().getSide();s===`EAST`&&c===`WEST`?n.push(mu(e,t,t.getTarget(),t.getSource())):s===`WEST`&&c===`EAST`&&n.push(mu(e,t,t.getSource(),t.getTarget()))}}for(let e of n)e.setLayer(t)}}function mu(t,n,r,i){let a=new f(t);a.setType(`LONG_EDGE`),a.setProperty(e.lr,n),a.setProperty(e.Lt,`FIXED_POS`),a.setProperty(e.rr,r),a.setProperty(e.ir,i);let o=new p;o.setSide(`WEST`),o.setNode(a);let s=new p;s.setSide(`EAST`),s.setNode(a),n.setTarget(o);let c=new m;return c.copyProperties(n),c.setProperty(e.nt,null),c.setSource(s),c.setTarget(i),a}function hu(t,n,r){for(let i of t){let t=i.getProperty(e.lr),a=t.getAbsoluteAnchor().x,o=i.getNode().getPosition().y,s=n?[...i.getIncomingEdges()]:[...i.getOutgoingEdges()];for(let i of s)if(n?(i.setTarget(t),i.getBendPoints().push({x:a,y:o})):(i.setSource(t),i.getBendPoints().unshift({x:a,y:o})),r){let t=i.getProperty(e.nt);t??(t=[],i.setProperty(e.nt,t)),t.push({x:a,y:o})}}}function gu(t){let n=t.getProperty(e.lr),r=t.getPorts(`WEST`)[0],i=t.getPorts(`EAST`)[0],a=r.getProperty(e.lr),o=i.getProperty(e.lr);n.setSource(o),n.setTarget(a);let s={...i.getNode().getPosition()};s.x=o.getAbsoluteAnchor().x,n.getBendPoints().push(s);let c={...r.getNode().getPosition()};c.x=a.getAbsoluteAnchor().x,n.getBendPoints().push(c)}function _u(t){let n=t.getProperty(e.B);for(let r of t.getLayers())for(let t of[...r.getNodes()])if(t.getType()===`NORTH_SOUTH_PORT`){if(n===`SPLINES`)for(let n of t.getPorts()){let r=n.getProperty(e.lr);if(r.setProperty(e.Er,t.getPosition().y),n.getIncomingEdges().length>0)for(let e of[...n.getIncomingEdges()])e.setTarget(r);if(n.getOutgoingEdges().length>0)for(let e of[...n.getOutgoingEdges()])e.setSource(r)}else if(t.getProperty(e.lr)instanceof m)gu(t);else{let n=t.getPorts(),r=n.length>=2;for(let t=1;t<n.length;t++)if(n[t].getProperty(e.lr)!==n[t-1].getProperty(e.lr)){r=!1;break}n.length<2&&(r=!1);for(let e of n)e.getIncomingEdges().length>0&&hu([e],!0,r),e.getOutgoingEdges().length>0&&hu([e],!1,r)}t.setLayer(null)}}function vu(t,n,r,i,a){if((a?r.getSource().getNode():r.getTarget().getNode())===n.getNode())return;let o=new f(t);o.setType(`LONG_EDGE`),o.setProperty(e.lr,r),o.setProperty(e.Lt,`FIXED_POS`),i.push(o);let s=new p;s.setNode(o),s.setSide(`WEST`);let c=new p;if(c.setNode(o),c.setSide(`EAST`),a){r.setTarget(s);let t=new m;t.copyProperties(r),t.setProperty(e.nt,null),t.setSource(c),t.setTarget(n),bu(o,s,c,n),yu(r,t)}else{let t=r.getTarget();r.setTarget(s);let i=new m;i.copyProperties(r),i.setProperty(e.nt,null),i.setSource(c),i.setTarget(t),bu(o,s,c,n),yu(r,i)}}function yu(e,t){let n=e.getLabels();for(let e=n.length-1;e>=0;e--)if(n[e].placement===`HEAD`){let[r]=n.splice(e,1);t.getLabels().push(r)}}function bu(t,n,r,i){let a=n.getIncomingEdges()[0].getSource(),o=a.getNode();t.setProperty(e.rr,o.getType()===`LONG_EDGE`?o.getProperty(e.rr):a);let s=r.getOutgoingEdges()[0].getTarget(),c=s.getNode();t.setProperty(e.ir,c.getType()===`LONG_EDGE`?c.getProperty(e.ir):s)}function xu(t){let n=t.getLayers(),r=[],i=0;for(let a of n){if(i>0){for(let e of r)e.setLayer(n[i-1]);r.length=0}for(let n of a.getNodes())if(n.getType()===`NORMAL`&&e.Lr.isSideFixed(n.getProperty(e.Lt))){for(let e of n.getPorts(`INPUT`).filter(e=>e.getSide()===`EAST`))for(let n of[...e.getIncomingEdges()])vu(t,e,n,r,!0);for(let e of n.getPorts(`OUTPUT`).filter(e=>e.getSide()===`WEST`))for(let n of[...e.getOutgoingEdges()])vu(t,e,n,r,!1)}i++}for(let e of r)e.setLayer(n[n.length-1])}function Su(t){return t.getLayerlessNodes().some(t=>t.getProperty(e.g))}function Cu(t){for(let n of[...t.getLayerlessNodes()]){if(!n.getProperty(e.g))continue;let r=0,i=null,a=null;for(let e of n.getPorts())r+=e.getDegree(),e.getIncomingEdges().length===1&&(i=e.getIncomingEdges()[0],a=i.getSource()),e.getOutgoingEdges().length===1&&(i=e.getOutgoingEdges()[0],a=i.getTarget());if(r===1&&a!==null&&a.getDegree()===1&&!a.getNode().getProperty(e.g)){wu(n,i,a,a.getNode());let e=t.getLayerlessNodes().indexOf(n);e!==-1&&t.getLayerlessNodes().splice(e,1)}else{let e=[];for(let t of n.getPorts()){for(let n of t.getOutgoingEdges())n.getTarget().getNode().getOutgoingEdges().length>0&&e.push(n);for(let n of t.getIncomingEdges())n.getSource().getNode().getIncomingEdges().length>0&&e.push(n)}for(let n of e)n.reverse(t,!0)}}}function wu(t,n,r,i){let a=!1,o=!1,s=!1,c=i.getProperty(`org.eclipse.elk.portConstraints`);if(c!=null&&String(c).includes(`FIXED`)){let t=!1,n=!1;for(let r of i.getPorts())for(let i of r.getConnectedPorts())if(!i.getNode().getProperty(e.g)){if(r.getSide()===`NORTH`){t=!0;break}if(r.getSide()===`SOUTH`){n=!0;break}}o=n&&!t,s=t&&!n}if(!o&&!s&&i.getLabels().length>0){let e=0;for(let t of i.getLabels())e+=t.position.y+t.size.y/2;e/=i.getLabels().length,a=e>=i.size.y/2}else a=!s;let l=null;if(a){let t=i.getProperty(e.jr);if(t==null)l=[],i.setProperty(e.jr,l);else if(o)l=t;else{let n=i.getProperty(e.kn);n==null?(l=[],i.setProperty(e.kn,l)):l=t.length<=n.length?t:n}}else{let t=i.getProperty(e.kn);if(t==null)l=[],i.setProperty(e.kn,l);else if(s)l=t;else{let n=i.getProperty(e.jr);n==null?(l=[],i.setProperty(e.jr,l)):l=t.length<=n.length?t:n}}l.push(t),t.setProperty(e.Mn,r),n.getTarget()===r?(n.setTarget(null),r.getDegree()===0&&r.setNode(null),Tu(r)):(n.setSource(null),r.getDegree()===0&&r.setNode(null)),n.getBendPoints().length=0}function Tu(t){let n=t.getProperty(e._r);if(n!=null){let e=n.getLayer();if(e!==null){let t=e.getNodes(),r=t.indexOf(n);if(r!==-1&&t.splice(r,1),t.length===0){let t=n.getGraph().getLayers(),r=t.indexOf(e);r!==-1&&t.splice(r,1)}}}}function Eu(e){for(let t of e.getLayers())for(let e of t.getNodes())Ou(e)}function Du(e){Ou(e)}function Ou(t){let n=t.getMargin(),r=t.getProperty(e.jr),i=t.getProperty(e.kn);if(r==null&&i==null)return;let a=t.getGraph()?.getProperty(e.Xt)??10,o=t.getGraph()?.getProperty(e.Zt)??10,s=0;if(r!=null){let e=0;for(let t of r)e=Math.max(e,t.size.y),s+=t.size.x;s+=a*(r.length-1),n.top+=e+o}let c=0;if(i!=null){let e=0;for(let t of i)e=Math.max(e,t.size.y),c+=t.size.x;c+=a*(i.length-1),n.bottom+=e+o}let l=Math.max(s,c);if(l>t.size.x){let e=(l-t.size.x)/2;n.left=Math.max(n.left,e),n.right=Math.max(n.right,e)}}function ku(t){for(let n of t.getLayers()){let t=[];for(let r of n.getNodes()){let n=r.getProperty(e.jr),i=r.getProperty(e.kn);(n!=null||i!=null)&&(Au(r,n??null,i??null),n!=null&&t.push(...n),i!=null&&t.push(...i))}for(let e of t)n.getNodes().includes(e)||n.getNodes().push(e)}}function Au(t,n,r){let i=t.position,a=t.size,o=t.getMargin(),s=t.getGraph()?.getProperty(e.Xt)??10;if(n!=null){let r=s*(n.length-1),c=0;for(let e of n)r+=e.size.x,c=Math.max(c,e.size.y);let l=i.x-(r-a.x)/2,u=i.y-o.top+c,d=a.x/(n.length+1),f=d;for(let r of n){r.position.x=l,r.position.y=u-r.size.y,l+=r.size.x+s;let n=ju(r);n!==null&&(n.getPosition().x=r.size.x/2-n.getAnchor().x,n.getPosition().y=r.size.y);let i=r.getProperty(e.Mn);i!=null&&i.getDegree()===1&&(i.getPosition().x=f-i.getAnchor().x,i.getPosition().y=0,i.setNode(t)),f+=d}}if(r!=null){let n=s*(r.length-1),c=0;for(let e of r)n+=e.size.x,c=Math.max(c,e.size.y);let l=i.x-(n-a.x)/2,u=i.y+a.y+o.bottom-c,d=a.x/(r.length+1),f=d;for(let n of r){n.position.x=l,n.position.y=u,l+=n.size.x+s;let r=ju(n);r!==null&&(r.getPosition().x=n.size.x/2-r.getAnchor().x,r.getPosition().y=0);let i=n.getProperty(e.Mn);i!=null&&i.getDegree()===1&&(i.getPosition().x=f-i.getAnchor().x,i.getPosition().y=a.y,i.setNode(t)),f+=d}}}function ju(t){let n=t.getProperty(e.Mn);for(let e of t.getPorts()){for(let t of e.getOutgoingEdges())return n!=null&&t.setTarget(n),e;for(let t of e.getIncomingEdges())return n!=null&&t.setSource(n),e}return null}function J(e){let t=e.x;e.x=e.y,e.y=t}function Y(e,t){e.x=t-e.x}function X(e,t){e.y=t-e.y}function Mu(e){let t=e.top,n=e.bottom,r=e.left,i=e.right;e.top=r,e.bottom=i,e.left=t,e.right=n}function Nu(e){let t=e.left;e.left=e.right,e.right=t}function Pu(e){let t=e.top;e.top=e.bottom,e.bottom=t}function Fu(e){return e===`EAST`?`WEST`:e===`WEST`?`EAST`:e}function Iu(e){return e===`NORTH`?`SOUTH`:e===`SOUTH`?`NORTH`:e}function Lu(e){switch(e){case`NORTH`:return`WEST`;case`WEST`:return`NORTH`;case`SOUTH`:return`EAST`;case`EAST`:return`SOUTH`;default:return`UNDEFINED`}}function Ru(t){let n=t.getProperty(e.Rt);n!=null&&t.setProperty(e.Rt,-n)}function zu(e){switch(e.getLayerConstraint()){case`FIRST`:e.setLayerConstraint(`LAST`);break;case`FIRST_SEPARATE`:e.setLayerConstraint(`LAST_SEPARATE`);break;case`LAST`:e.setLayerConstraint(`FIRST`);break;case`LAST_SEPARATE`:e.setLayerConstraint(`FIRST_SEPARATE`)}}function Bu(e){switch(e.getInLayerConstraint()){case`TOP`:e.setInLayerConstraint(`BOTTOM`);break;case`BOTTOM`:e.setInLayerConstraint(`TOP`)}}function Vu(e){let t=e.getLayerConstraint(),n=e.getInLayerConstraint();t===`FIRST_SEPARATE`?(e.setLayerConstraint(`NONE`),e.setInLayerConstraint(`TOP`)):t===`LAST_SEPARATE`?(e.setLayerConstraint(`NONE`),e.setInLayerConstraint(`BOTTOM`)):n===`TOP`?(e.setLayerConstraint(`FIRST_SEPARATE`),e.setInLayerConstraint(`NONE`)):n===`BOTTOM`&&(e.setLayerConstraint(`LAST_SEPARATE`),e.setInLayerConstraint(`NONE`))}function Hu(e){return Array.isArray(e)?[...e]:String(e??``).replace(/[\[\]]/g,``).split(/[\s,]+/).filter(Boolean)}function Uu(e){let t=[...e],n=t.indexOf(`H_LEFT`),r=t.indexOf(`H_RIGHT`);return n>=0?t[n]=`H_RIGHT`:r>=0&&(t[r]=`H_LEFT`),t}function Wu(e){let t=[...e],n=t.indexOf(`V_TOP`),r=t.indexOf(`V_BOTTOM`);return n>=0?t[n]=`V_BOTTOM`:r>=0&&(t[r]=`V_TOP`),t}function Gu(e){if(e.length===0)return e;let t=[];return e.includes(`INSIDE`)?t.push(`INSIDE`):t.push(`OUTSIDE`),e.includes(`H_PRIORITY`)||t.push(`H_PRIORITY`),e.includes(`H_LEFT`)?t.push(`V_TOP`):e.includes(`H_CENTER`)?t.push(`V_CENTER`):e.includes(`H_RIGHT`)&&t.push(`V_BOTTOM`),e.includes(`V_TOP`)?t.push(`H_LEFT`):e.includes(`V_CENTER`)?t.push(`H_CENTER`):e.includes(`V_BOTTOM`)&&t.push(`H_RIGHT`),t}function Ku(e){return e.join(`, `)}var qu=class{mode;constructor(e){this.mode=e}process(t){let n=[...t.getLayerlessNodes()];for(let e of t.getLayers())n.push(...e.getNodes());let r=t.getProperty(e.F),i=t.getProperty(e.I)===`READING_DIRECTION`,a=this.mode===`TO_INPUT_DIRECTION`;if(i)switch(r){case`LEFT`:this.mirrorAllX(t,n);break;case`DOWN`:this.transposeAll(t,n);break;case`UP`:a?(this.mirrorAllY(t,n),this.transposeAll(t,n)):(this.transposeAll(t,n),this.mirrorAllY(t,n))}else if(a)switch(r){case`LEFT`:this.mirrorAllX(t,n),this.mirrorAllY(t,n);break;case`DOWN`:this.mirrorAllX(t,n),this.transposeAll(t,n);break;case`UP`:this.transposeAll(t,n),this.mirrorAllX(t,n)}else switch(r){case`LEFT`:this.mirrorAllX(t,n),this.mirrorAllY(t,n);break;case`DOWN`:this.transposeAll(t,n),this.mirrorAllX(t,n);break;case`UP`:this.mirrorAllX(t,n),this.transposeAll(t,n)}}mirrorAllX(t,n){t.hasProperty(e.gt)&&Nu(t.getProperty(e.gt));let r=0;if(t.getSize().x===0)for(let e of n)r=Math.max(r,e.position.x+e.size.x+e.getMargin().right);else r=t.getSize().x-t.getOffset().x;r-=t.getOffset().x;for(let t of n){Y(t.position,r-t.size.x),Nu(t.getPadding()),this.mirrorLabelPlacementX(t),this.mirrorPositionX(t,r),this.mirrorAlignmentX(t);let n=t.size;for(let i of t.getPorts()){Y(i.getPosition(),n.x-i.getSize().x),Y(i.getAnchor(),i.getSize().x),i.setSideInferred(Fu(i.getSide())),Ru(i);for(let t of i.getOutgoingEdges()){for(let e of t.getBendPoints())Y(e,r);let n=t.getProperty(e.nt);if(n!=null)for(let e of n)Y(e,r);for(let e of t.getLabels())Y(e.position,r-e.size.x)}for(let e of i.getLabels())Y(e.position,i.getSize().x-e.size.x)}t.getType()===`EXTERNAL_PORT`&&(t.setProperty(e.Un,Fu(t.getProperty(e.Un))),zu(t));for(let e of t.getLabels())this.mirrorLabelPlacementXOn(e),Y(e.position,n.x-e.size.x)}}mirrorAllY(t,n){t.hasProperty(e.gt)&&Pu(t.getProperty(e.gt));let r=0;if(t.getSize().y===0)for(let e of n)r=Math.max(r,e.position.y+e.size.y+e.getMargin().bottom);else r=t.getSize().y-t.getOffset().y;r-=t.getOffset().y;for(let t of n){X(t.position,r-t.size.y),Pu(t.getPadding()),this.mirrorLabelPlacementY(t),this.mirrorPositionY(t,r),this.mirrorAlignmentY(t);let n=t.size;for(let i of t.getPorts()){X(i.getPosition(),n.y-i.getSize().y),X(i.getAnchor(),i.getSize().y),i.setSideInferred(Iu(i.getSide())),Ru(i);for(let t of i.getOutgoingEdges()){for(let e of t.getBendPoints())X(e,r);let n=t.getProperty(e.nt);if(n!=null)for(let e of n)X(e,r);for(let e of t.getLabels())X(e.position,r-e.size.y)}for(let e of i.getLabels())X(e.position,i.getSize().y-e.size.y)}t.getType()===`EXTERNAL_PORT`&&(t.setProperty(e.Un,Iu(t.getProperty(e.Un))),Bu(t));for(let e of t.getLabels())this.mirrorLabelPlacementYOn(e),X(e.position,n.y-e.size.y)}}transposeAll(t,n){J(t.getOffset()),J(t.getSize()),Mu(t.getPadding()),t.hasProperty(e.gt)&&Mu(t.getProperty(e.gt));for(let t of n){J(t.position),J(t.size),Mu(t.getPadding()),this.transposeLabelPlacement(t),this.transposeProperties(t);for(let n of t.getPorts()){J(n.getPosition()),J(n.getAnchor()),J(n.getSize()),n.setSideInferred(Lu(n.getSide())),Ru(n);for(let t of n.getOutgoingEdges()){for(let e of t.getBendPoints())J(e);let n=t.getProperty(e.nt);if(n!=null)for(let e of n)J(e);for(let e of t.getLabels())J(e.position),J(e.size)}for(let e of n.getLabels())J(e.position),J(e.size)}t.getType()===`EXTERNAL_PORT`&&(t.setProperty(e.Un,Lu(t.getProperty(e.Un))),Vu(t));for(let e of t.getLabels())this.transposeLabelPlacementOn(e),J(e.size),J(e.position)}}mirrorLabelPlacementX(t){if(!t.hasProperty(e._t))return;let n=Hu(t.getProperty(e._t));n.length!==0&&t.setProperty(e._t,Uu(n))}mirrorLabelPlacementY(t){if(!t.hasProperty(e._t))return;let n=Hu(t.getProperty(e._t));n.length!==0&&t.setProperty(e._t,Wu(n))}transposeLabelPlacement(t){if(!t.hasProperty(e._t))return;let n=Hu(t.getProperty(e._t));t.setProperty(e._t,Gu(n))}mirrorLabelPlacementXOn(e){if(e.placement===void 0||e.placement===``)return;let t=Hu(e.placement);t.length!==0&&(e.placement=Ku(Uu(t)))}mirrorLabelPlacementYOn(e){if(e.placement===void 0||e.placement===``)return;let t=Hu(e.placement);t.length!==0&&(e.placement=Ku(Wu(t)))}transposeLabelPlacementOn(e){if(e.placement===void 0||e.placement===``)return;let t=Hu(e.placement);t.length!==0&&(e.placement=Ku(Gu(t)))}mirrorPositionX(t,n){if(!t.hasProperty(e.Ht))return;let r=t.getProperty(e.Ht);r&&Y(r,n-t.size.x)}mirrorPositionY(t,n){if(!t.hasProperty(e.Ht))return;let r=t.getProperty(e.Ht);r&&X(r,n-t.size.y)}mirrorAlignmentX(t){switch(t.getProperty(e.p)){case`LEFT`:t.setProperty(e.p,`RIGHT`);break;case`RIGHT`:t.setProperty(e.p,`LEFT`)}}mirrorAlignmentY(t){switch(t.getProperty(e.p)){case`TOP`:t.setProperty(e.p,`BOTTOM`);break;case`BOTTOM`:t.setProperty(e.p,`TOP`)}}transposeProperties(t){let n=t.getProperty(e.Et);t.setProperty(e.Et,{x:n.y,y:n.x});let r=t.getProperty(`org.eclipse.elk.contentAlignment`)??[];if(r.length>0){let e=r.map(e=>e===`H_CENTER`?`V_CENTER`:e===`V_CENTER`?`H_CENTER`:e===`H_LEFT`?`V_TOP`:e===`H_RIGHT`?`V_BOTTOM`:e===`V_TOP`?`H_LEFT`:e===`V_BOTTOM`?`H_RIGHT`:e);t.setProperty(`org.eclipse.elk.contentAlignment`,e)}switch(t.getProperty(e.p)){case`LEFT`:t.setProperty(e.p,`TOP`);break;case`RIGHT`:t.setProperty(e.p,`BOTTOM`);break;case`TOP`:t.setProperty(e.p,`LEFT`);break;case`BOTTOM`:t.setProperty(e.p,`RIGHT`)}if(t.hasProperty(e.Ht)){let n=t.getProperty(e.Ht);if(n){let e=n.x;n.x=n.y,n.y=e}}}transposeEdgeLabelPlacement(t){switch(t.getProperty(e.z)){case`ALWAYS_UP`:t.setProperty(e.z,`ALWAYS_DOWN`);break;case`ALWAYS_DOWN`:t.setProperty(e.z,`ALWAYS_UP`);break;case`DIRECTION_UP`:t.setProperty(e.z,`DIRECTION_DOWN`);break;case`DIRECTION_DOWN`:t.setProperty(e.z,`DIRECTION_UP`);break;case`SMART_UP`:t.setProperty(e.z,`SMART_DOWN`);break;case`SMART_DOWN`:t.setProperty(e.z,`SMART_UP`)}}},Ju=class{horizontalLayoutMode;gap;horizontalAlignment=`CENTER`;verticalAlignment=`CENTER`;entries=[];minimumContentAreaSize={x:0,y:0};cellRectangle={x:0,y:0,width:0,height:0};constructor(e,t){this.gap=e,this.horizontalLayoutMode=t}getHorizontalAlignment(){return this.horizontalAlignment}setHorizontalAlignment(e){return this.horizontalAlignment=e,this}getVerticalAlignment(){return this.verticalAlignment}setVerticalAlignment(e){return this.verticalAlignment=e,this}getEntries(){return this.entries}hasLabels(){return this.entries.length>0}addLabel(e,t){this.entries.push({label:e,edge:t});let n=e.size;this.horizontalLayoutMode?(this.minimumContentAreaSize.x=Math.max(this.minimumContentAreaSize.x,n.x),this.minimumContentAreaSize.y+=n.y,this.entries.length>1&&(this.minimumContentAreaSize.y+=this.gap)):(this.minimumContentAreaSize.x+=n.x,this.minimumContentAreaSize.y=Math.max(this.minimumContentAreaSize.y,n.y),this.entries.length>1&&(this.minimumContentAreaSize.x+=this.gap))}getMinimumWidth(){return this.minimumContentAreaSize.x}getMinimumHeight(){return this.minimumContentAreaSize.y}applyLabelLayout(){this.horizontalLayoutMode?this.applyHorizontalModeLabelLayout():this.applyVerticalModeLabelLayout()}applyHorizontalModeLabelLayout(){let e=this.cellRectangle,t=e.y;this.verticalAlignment===`CENTER`?t+=(e.height-this.minimumContentAreaSize.y)/2:this.verticalAlignment===`BOTTOM`&&(t+=e.height-this.minimumContentAreaSize.y);for(let n of this.entries){let r=n.label.size;switch(n.label.position.y=t,t+=r.y+this.gap,this.horizontalAlignment){case`LEFT`:n.label.position.x=e.x;break;case`CENTER`:n.label.position.x=e.x+(e.width-r.x)/2;break;case`RIGHT`:n.label.position.x=e.x+e.width-r.x}}}applyVerticalModeLabelLayout(){let e=this.cellRectangle,t=e.x;this.horizontalAlignment===`CENTER`?t+=(e.width-this.minimumContentAreaSize.x)/2:this.horizontalAlignment===`RIGHT`&&(t+=e.width-this.minimumContentAreaSize.x);for(let n of this.entries){let r=n.label.size;switch(n.label.position.x=t,t+=r.x+this.gap,this.verticalAlignment){case`TOP`:n.label.position.y=e.y;break;case`CENTER`:n.label.position.y=e.y+(e.height-r.y)/2;break;case`BOTTOM`:n.label.position.y=e.y+e.height-r.y}}}},Yu=class e{static DEFAULT_GAP=5;overlapRemovalDirection;gapVertical=e.DEFAULT_GAP;gapHorizontal=e.DEFAULT_GAP;startCoordinate=0;rectangleNodes=[];constructor(e){this.overlapRemovalDirection=e}static createForDirection(t){return new e(t)}withGap(e,t){return this.gapHorizontal=e,this.gapVertical=t,this}withStartCoordinate(e){return this.startCoordinate=e,this}getVerticalGap(){return this.gapVertical}getRectangleNodes(){return this.rectangleNodes}addRectangle(e){return this.rectangleNodes.push({originalRectangle:e,rectangle:this.importRectangle(e),overlappingNodes:[]}),this}importRectangle(e){switch(this.overlapRemovalDirection){case`UP`:case`DOWN`:return e;case`LEFT`:case`RIGHT`:return{x:e.y,y:0,width:e.height,height:e.width};default:throw Error(`unsupported direction`)}}exportRectangle(e){let t=e.rectangle,n=e.originalRectangle;switch(this.overlapRemovalDirection){case`UP`:n.y=this.startCoordinate-t.height-t.y;break;case`DOWN`:n.y+=this.startCoordinate;break;case`LEFT`:n.x=this.startCoordinate-t.height-t.y;break;case`RIGHT`:n.x=this.startCoordinate+t.y}}removeOverlaps(){this.rectangleNodes.sort((e,t)=>e.rectangle.x-t.rectangle.x),this.computeOverlaps();let e=this.greedyRemoveOverlaps();for(let e of this.rectangleNodes)this.exportRectangle(e);return e}computeOverlaps(){let e=[];for(let t of this.rectangleNodes){let n=t.rectangle.x;for(;e.length>0;){let t=e[0];if(t.rectangle.x+t.rectangle.width<n)e.shift();else break}for(let n of e)n.overlappingNodes.push(t),t.overlappingNodes.push(n);let r=t.rectangle.x+t.rectangle.width,i=e.findIndex(e=>e.rectangle.x+e.rectangle.width>r);i===-1&&(i=e.length),e.splice(i,0,t)}}greedyRemoveOverlaps(){let e=this.gapVertical,t=/* @__PURE__ */ new Set,n=0;for(let r of this.rectangleNodes){let i=0;r.overlappingNodes.sort((e,t)=>e.rectangle.y-t.rectangle.y);for(let n of r.overlappingNodes)if(t.has(n)){let t=r.rectangle,a=n.rectangle;i<a.y+a.height+e&&i+t.height+e>a.y&&(i=a.y+a.height+e)}r.rectangle.y=i,t.add(r),n=Math.max(n,r.rectangle.y+r.rectangle.height)}return n}};function Xu(t){let n=t.getProperty(e.tn),r=t.getProperty(e.an),i=t.getProperty(e.F),a=i===`DOWN`||i===`UP`;for(let e of t.getLayers())for(let t of e.getNodes())Zu(t,n,r,a)}function Zu(t,n,r,i){let a=t.getPorts().length,o=Array(a);for(let e=0;e<a;e++){let n=t.getPorts()[e];n.id=e,o[e]=Qu($u(n),r,i)}td(t,o,r,n,i);let s=/* @__PURE__ */ new Map;for(let e=0;e<o.length;e++){let n=o[e];n!==null&&s.set(t.getPorts()[e],n)}s.size>0&&(t.setProperty(e.Rn,s),ad(t,o))}function Qu(e,t,n){if(e===null||e.length===0)return null;let r=new Ju(t,!n);for(let t of e)r.addLabel(t.label,t.edge);return r.cellRectangle.height=r.getMinimumHeight(),r.cellRectangle.width=r.getMinimumWidth(),r}function $u(t){let n=[],r=ed(t,n),i=t.getProperty(e._r);if(i!=null)for(let a of i.getPorts())a.getProperty(e.lr)===t&&(r=Math.max(r,ed(a,n)));return n.length>0&&t.setProperty(e.or,r),r===-1?null:n}function ed(t,n){let r=-1,i=[];for(let a of t.getConnectedEdges()){if(r=Math.max(r,a.getProperty(e.W)),a.getSource()===t)for(let e of a.getLabels())e.placement===`TAIL`&&i.push({label:e,edge:a});else for(let e of a.getLabels())e.placement===`HEAD`&&i.push({label:e,edge:a});n.push(...i),i.length=0}return r}function td(e,t,n,r,i){for(let n of e.getPorts()){let e=t[n.id];e!==null&&nd(n,e,r)}i?(rd(e,t,`EAST`,2*n,r),rd(e,t,`WEST`,2*n,r)):(rd(e,t,`NORTH`,2*n,r),rd(e,t,`SOUTH`,2*n,r))}function nd(e,t,n){let r=t.cellRectangle,i=e.getNode().getSize(),a=e.getNode().getMargin(),o=e.getPosition(),s={x:o.x+e.getAnchor().x,y:o.y+e.getAnchor().y};switch(e.getSide()){case`NORTH`:t.setVerticalAlignment(`BOTTOM`),r.y=-a.top-n-r.height,sd(t)===`ABOVE`?(t.setHorizontalAlignment(`RIGHT`),r.x=s.x-ld(e)-n-r.width):(t.setHorizontalAlignment(`LEFT`),r.x=s.x+ld(e)+n);break;case`EAST`:t.setHorizontalAlignment(`LEFT`),r.x=i.x+a.right+n,sd(t)===`ABOVE`?(t.setVerticalAlignment(`BOTTOM`),r.y=s.y-ld(e)-n-r.height):(t.setVerticalAlignment(`TOP`),r.y=s.y+ld(e)+n);break;case`SOUTH`:t.setVerticalAlignment(`TOP`),r.y=i.y+a.bottom+n,sd(t)===`ABOVE`?(t.setHorizontalAlignment(`RIGHT`),r.x=s.x-ld(e)-n-r.width):(t.setHorizontalAlignment(`LEFT`),r.x=s.x+ld(e)+n);break;case`WEST`:t.setHorizontalAlignment(`RIGHT`),r.x=-a.left-n-r.width,sd(t)===`ABOVE`?(t.setVerticalAlignment(`BOTTOM`),r.y=s.y-ld(e)-n-r.height):(t.setVerticalAlignment(`TOP`),r.y=s.y+ld(e)+n)}}function rd(e,t,n,r,i){let a=Yu.createForDirection(cd(n)).withGap(r,r).withStartCoordinate(id(e,n,i));for(let r of e.getPorts(n)){let e=t[r.id];e!==null&&a.addRectangle(e.cellRectangle)}a.removeOverlaps()}function id(e,t,n){let r=e.getSize(),i=e.getMargin();switch(t){case`NORTH`:return-i.top-n;case`SOUTH`:return r.y+i.bottom+n;case`EAST`:return r.x+i.right+n;case`WEST`:return-i.left-n;default:return 0}}function ad(e,t){let n=e.getMargin(),r=e.getSize(),i={x:-n.left,y:-n.top,width:n.left+r.x+n.right,height:n.top+r.y+n.bottom};for(let e of t)e!==null&&(i=od(i,e.cellRectangle));n.left=-i.x,n.top=-i.y,n.right=i.width-n.left-r.x,n.bottom=i.height-n.top-r.y}function od(e,t){let n=Math.min(e.x,t.x),r=Math.min(e.y,t.y),i=Math.max(e.x+e.width,t.x+t.width),a=Math.max(e.y+e.height,t.y+t.height);return{x:n,y:r,width:i-n,height:a-r}}function sd(e){return`BELOW`}function cd(e){switch(e){case`NORTH`:return`UP`;case`SOUTH`:return`DOWN`;case`EAST`:return`RIGHT`;case`WEST`:return`LEFT`;default:return`UP`}}function ld(t){return t.getProperty(e.or)}function ud(t){switch(t.getProperty(e.z)){case`ALWAYS_UP`:fd(t,`ABOVE`);break;case`ALWAYS_DOWN`:fd(t,`BELOW`);break;case`DIRECTION_UP`:pd(t,`ABOVE`);break;case`DIRECTION_DOWN`:pd(t,`BELOW`);break;case`SMART_UP`:md(t,`ABOVE`),dd(t,`ABOVE`);break;case`SMART_DOWN`:md(t,`BELOW`),dd(t,`BELOW`)}}function dd(e,t){let n=e=>{for(let n of e.getOutgoingEdges())for(let e of n.getLabels()){let n=e;(n.side===void 0||n.side===``)&&(n.side=t)}};for(let t of e.getLayers())for(let e of t.getNodes())n(e);for(let t of e.getLayerlessNodes())n(t)}function fd(e,t){for(let n of e.getLayers())for(let e of n.getNodes()){e.getType()===`LABEL`&&Z(e,t);for(let n of e.getOutgoingEdges())Sd(n,t)}}function pd(e,t){let n=t===`ABOVE`?`BELOW`:`ABOVE`;for(let r of e.getLayers())for(let e of r.getNodes()){e.getType()===`LABEL`&&Z(e,Cd(e)?t:n);for(let r of e.getOutgoingEdges())Sd(r,Cd(r)?t:n)}}function md(e,t){let n=[];for(let r of e.getLayers()){let e=!0,i=0;for(let a of r.getNodes())switch(a.getType()){case`LABEL`:i++,n.push(a);break;case`LONG_EDGE`:n.push(a);break;case`NORMAL`:hd(a,t),n.length>0&&vd(n,i,e,!1,t),e=!1,i=0;break;default:n.length>0&&vd(n,i,e,!1,t),e=!1,i=0}n.length>0&&vd(n,i,e,!0,t)}}function hd(e,t){let n=[],r=null;for(let i of e.getPorts()){i.getSide()!==r&&(n.length>0&&gd(n,r,t),n.length=0,r=i.getSide());let e=$u(i);e!==null&&n.push(e)}n.length>0&&gd(n,r,t)}function gd(e,t,n){if(e.length===2)t===`NORTH`||t===`EAST`?(_d(e[0],`ABOVE`),_d(e[1],`BELOW`)):(_d(e[0],`BELOW`),_d(e[1],`ABOVE`));else for(let t of e)_d(t,n)}function _d(e,t){for(let n of e)n.label.side=t}function vd(e,t,n,r,i){n&&(!r||e.length>1)&&t===1&&e[0].getType()===`LABEL`?Z(e[0],`ABOVE`):r&&(!n||e.length>1)&&t===1&&e[e.length-1].getType()===`LABEL`?Z(e[e.length-1],`BELOW`):e.length===2?(Z(e[0],`ABOVE`),Z(e[1],`BELOW`)):yd(e,t,i),e.length=0}function yd(e,t,n){let r=[],i=null,a=null;for(let t of e){let e=xd(t,!0),o=xd(t,!1);(i!==e||a!==o)&&(bd(r,n),i=e,a=o),r.push(t)}bd(r,n)}function bd(e,t){if(e.length!==0){if(e.length===2)Z(e[0],`ABOVE`),Z(e[1],`BELOW`);else for(let n of e)Z(n,t);e.length=0}}function xd(t,n){let r=t.getProperty(n?e.rr:e.ir);return r==null?null:r.getNode()}function Z(t,n){if(t.getType()!==`LABEL`)return;let r=n;if(t.setProperty(e.er,r),r!==`BELOW`){let n=t.getProperty(e.lr)?.getProperty(e.W)??0,i=0;if(r===`ABOVE`)i=t.size.y-Math.ceil(n/2);else if(r===`INLINE`){let r=t.getGraph()?.getProperty(e.tn)??0;i=Math.ceil(t.size.y-r-n)/2,t.size.y-=r,t.size.y-=n}for(let e of t.getPorts())e.getPosition().y=i}}function Sd(e,t){for(let n of e.getLabels())n.side=t}function Cd(t){if(t instanceof f){let e=t.getIncomingEdges()[0],n=t.getOutgoingEdges()[0];return!!(e&&Cd(e)||n&&Cd(n))}return!t.getProperty(e.Sr)}function wd(e){for(let t of e.getLayers())for(let e of t.getNodes())e.getType()===`NORMAL`&&Td(e)}function Td(t){let n=!1,r=t.getProperty(e.Rn);if(r==null||!(r instanceof Map))return;let i=r;for(let e of t.getPorts())Ed(e)&&(n||=(Dd(t.getGraph()),!0),Od(e,i.get(e)))}function Ed(e){let t=0;for(let n of e.getIncomingEdges())n.getLabels().some(e=>e.placement===`HEAD`)&&t++;for(let n of e.getOutgoingEdges())n.getLabels().some(e=>e.placement===`TAIL`)&&t++;return t>=2}function Dd(e){if(e===null)return;let t=0;for(let n of e.getLayers())for(let e of n.getNodes()){e.id=t++;for(let n of e.getPorts())n.id=t++}}function Od(e,t){if(t===void 0)return;let n=kd(t);n.sort(jd);let r=t.getEntries();r.length=0;for(let e of n)r.push(...e.entries)}function kd(e){let t=/* @__PURE__ */ new Map;for(let n of e.getEntries()){let e=n.edge,r=t.get(e);r===void 0&&(r=new Ad(e),t.set(e,r)),r.entries.push(n)}return[...t.values()]}var Ad=class{edge;entries=[];constructor(e){this.edge=e}};const jd=(e,t)=>{let n=e.edge,r=t.edge;if(n===null||r===null)return 0;let i=n.getSource(),a=r.getSource();if(i!==null&&a!==null){let e=i.id-a.id;if(e!==0)return e}let o=n.getTarget(),s=r.getTarget();if(o!==null&&s!==null){let e=o.getNode(),t=s.getNode(),n=(e?.id??0)-(t?.id??0);return n===0?s.id-o.id:n}return 0};function Md(t){for(let n of t.getLayers())for(let t of n.getNodes())(t.getType()===`NORMAL`||t.getType()===`EXTERNAL_PORT`)&&t.hasProperty(e.Rn)&&Nd(t)}function Nd(t){let n=t.getProperty(e.Rn);if(n==null)return;let r=t.getPosition();for(let e of n.values()){let t=e,n=t.cellRectangle;n.x+=r.x,n.y+=r.y,t.applyLabelLayout()}t.setProperty(e.Rn,null)}var Pd=class{targetNodeModelOrder;portModelOrder;previousLayer;graph;strategy;biggerThan=/* @__PURE__ */ new Map;smallerThan=/* @__PURE__ */ new Map;constructor(e,t,n,r,i){this.graph=e,this.previousLayer=t,this.strategy=n,this.targetNodeModelOrder=r,this.portModelOrder=i}compare(t,n){let r=t,i=n;if(!this.biggerThan.has(r))this.biggerThan.set(r,/* @__PURE__ */ new Set);else if(this.biggerThan.get(r).has(i))return 1;if(!this.biggerThan.has(i))this.biggerThan.set(i,/* @__PURE__ */ new Set);else if(this.biggerThan.get(i).has(r))return-1;if(!this.smallerThan.has(r))this.smallerThan.set(r,/* @__PURE__ */ new Set);else if(this.smallerThan.get(r).has(i))return-1;if(!this.smallerThan.has(i))this.smallerThan.set(i,/* @__PURE__ */ new Set);else if(this.biggerThan.get(i).has(r))return 1;if(r.getSide()!==i.getSide()){let e=Ld(r.getSide())-Ld(i.getSide());return e>0?this.updateBiggerAndSmallerAssociations(r,i,1):this.updateBiggerAndSmallerAssociations(i,r,1),e}let a=1;if(r.getIncomingEdges().length>0&&i.getIncomingEdges().length>0){(r.getSide()===`WEST`&&i.getSide()===`WEST`||r.getSide()===`NORTH`&&i.getSide()===`NORTH`||r.getSide()===`SOUTH`&&i.getSide()===`SOUTH`)&&(a=-a);let e=r.getIncomingEdges()[0].getSource(),t=i.getIncomingEdges()[0].getSource(),n=e.getNode(),o=t.getNode();if(n===o)for(let o of n.getPorts()){if(e===o)return this.updateBiggerAndSmallerAssociations(i,r,a),-a;if(t===o)return this.updateBiggerAndSmallerAssociations(r,i,a),a}if(n.getType()===`LONG_EDGE`&&o.getType()===`LONG_EDGE`&&n.getLayer().id===o.getLayer().id&&n.getLayer().id===r.getNode().getLayer().id){let e=this.checkReferenceLayer(n.getLayer().getNodes(),n,o);if(e!==0)return r.getSide()===`EAST`&&i.getSide()===`EAST`&&(a=-a),e>0?(this.updateBiggerAndSmallerAssociations(r,i,a),a):(this.updateBiggerAndSmallerAssociations(i,r,a),-a)}let s=this.checkReferenceLayer(this.previousLayer,n,o);if(s!==0)return s>0?(this.updateBiggerAndSmallerAssociations(r,i,a),a):(this.updateBiggerAndSmallerAssociations(i,r,a),-a);if(this.portModelOrder){let e=this.checkPortModelOrder(r,i);if(e!==0)return e>0?(this.updateBiggerAndSmallerAssociations(r,i,a),a):(this.updateBiggerAndSmallerAssociations(i,r,a),-a)}}if(r.getOutgoingEdges().length>0&&i.getOutgoingEdges().length>0){(r.getSide()===`WEST`&&i.getSide()===`WEST`||r.getSide()===`SOUTH`&&i.getSide()===`SOUTH`)&&(a=-a);let t=r.getProperty(e.ar),n=i.getProperty(e.ar);if(this.strategy===`PREFER_NODES`&&t!=null&&n!=null&&t.hasProperty(e.cr)&&n.hasProperty(e.cr))return O(t,n,this.graph,this.graph.getProperty(`org.eclipse.elk.layered.internal.maxModelOrderNodes`))>O(n,t,this.graph,this.graph.getProperty(`org.eclipse.elk.layered.internal.maxModelOrderNodes`))?(this.updateBiggerAndSmallerAssociations(r,i,a),a):(this.updateBiggerAndSmallerAssociations(i,r,a),-a);if(this.portModelOrder){let e=this.checkPortModelOrder(r,i);if(e!==0)return e>0?(this.updateBiggerAndSmallerAssociations(r,i,a),a):(this.updateBiggerAndSmallerAssociations(i,r,a),-a)}let o=0,s=0;return r.getOutgoingEdges()[0].hasProperty(e.cr)&&(o=O(r.getOutgoingEdges()[0],i.getOutgoingEdges()[0],this.graph,r.getOutgoingEdges().length+r.getIncomingEdges().length)),i.getOutgoingEdges()[0].hasProperty(e.cr)&&(s=O(i.getOutgoingEdges()[0],r.getOutgoingEdges()[0],this.graph,i.getOutgoingEdges().length+i.getIncomingEdges().length)),t!=null&&t===n||this.targetNodeModelOrder!=null&&(this.targetNodeModelOrder.has(t)&&(o=this.targetNodeModelOrder.get(t)),this.targetNodeModelOrder.has(n)&&(s=this.targetNodeModelOrder.get(n))),o>s?(this.updateBiggerAndSmallerAssociations(r,i,a),a):(this.updateBiggerAndSmallerAssociations(i,r,a),-a)}if(r.getIncomingEdges().length>0&&i.getOutgoingEdges().length>0)return this.updateBiggerAndSmallerAssociations(r,i,a),1;if(r.getOutgoingEdges().length>0&&i.getIncomingEdges().length>0)return this.updateBiggerAndSmallerAssociations(i,r,a),-1;if(r.hasProperty(e.cr)&&i.hasProperty(e.cr)){let e=r.getNode().getPorts().length,t=O(r,i,this.graph,e),n=O(i,r,this.graph,e);return(r.getSide()===`WEST`&&i.getSide()===`WEST`||r.getSide()===`SOUTH`&&i.getSide()===`SOUTH`)&&(a=-a),t>n?(this.updateBiggerAndSmallerAssociations(r,i,a),a):(this.updateBiggerAndSmallerAssociations(i,r,a),-a)}return this.updateBiggerAndSmallerAssociations(i,r,a),-a}checkPortModelOrder(t,n){let r=t.getNode().getPorts().length;return t.hasProperty(e.cr)&&n.hasProperty(e.cr)?O(t,n,this.graph,r)-O(n,t,this.graph,r):0}updateBiggerAndSmallerAssociations(e,t,n){let r=e,i=t;n<0&&(r=t,i=e);let a=this.biggerThan.get(r),o=this.biggerThan.get(i),s=this.smallerThan.get(r),c=this.smallerThan.get(i);a.add(i),c.add(r);for(let e of o){a.add(e),this.smallerThan.get(e).add(r);for(let t of s)this.smallerThan.get(e).add(t)}for(let e of s){c.add(e),this.biggerThan.get(e).add(i);for(let t of o)this.biggerThan.get(e).add(t)}}checkReferenceLayer(e,t,n){for(let r of e){if(r===t)return-1;if(r===n)return 1}return 0}clearTransitiveOrdering(){this.biggerThan=/* @__PURE__ */ new Map,this.smallerThan=/* @__PURE__ */ new Map}},Fd=class{previousLayer;graph;orderingStrategy;groupOrderStrategy;biggerThan=/* @__PURE__ */ new Map;smallerThan=/* @__PURE__ */ new Map;longEdgeNodeOrder;beforePorts;constructor(e,t,n,r,i,a){this.graph=e,this.previousLayer=t,this.orderingStrategy=n,this.groupOrderStrategy=i,this.longEdgeNodeOrder=r,this.beforePorts=a}compare(t,n){if(!this.biggerThan.has(t))this.biggerThan.set(t,/* @__PURE__ */ new Set);else if(this.biggerThan.get(t).has(n))return 1;if(!this.biggerThan.has(n))this.biggerThan.set(n,/* @__PURE__ */ new Set);else if(this.biggerThan.get(n).has(t))return-1;if(!this.smallerThan.has(t))this.smallerThan.set(t,/* @__PURE__ */ new Set);else if(this.smallerThan.get(t).has(n))return-1;if(!this.smallerThan.has(n))this.smallerThan.set(n,/* @__PURE__ */ new Set);else if(this.biggerThan.get(n).has(t))return 1;if(this.orderingStrategy===`PREFER_EDGES`||!t.hasProperty(e.cr)||!n.hasProperty(e.cr)){let r=null;for(let e of t.getPorts())if(e.getIncomingEdges().length>0&&e.getIncomingEdges()[0].getSource().getNode().getLayer().id===t.getLayer().id-1){r=e.getIncomingEdges()[0].getSource();break}let i=null;for(let e of n.getPorts())if(e.getIncomingEdges()[0]?.getSource()?.getNode(),e.getIncomingEdges().length>0&&e.getIncomingEdges()[0].getSource().getNode().getLayer().id===n.getLayer().id-1){i=e.getIncomingEdges()[0].getSource();break}if(r!==null&&i!==null){let e=r.getNode(),a=i.getNode();if(e===a){for(let a of e.getPorts()){if(a===r)return this.updateBiggerAndSmallerAssociations(n,t),-1;if(a===i)return this.updateBiggerAndSmallerAssociations(t,n),1}return this.getModelOrderFromConnectedEdges(t)>this.getModelOrderFromConnectedEdges(n)?(this.updateBiggerAndSmallerAssociations(t,n),1):(this.updateBiggerAndSmallerAssociations(n,t),-1)}for(let r of this.previousLayer){if(r===e)return this.updateBiggerAndSmallerAssociations(n,t),-1;if(r===a)return this.updateBiggerAndSmallerAssociations(t,n),1}}if(r!==null&&i===null||r===null&&i!==null){let r=this.handleHelperDummyNodes(t,n);if(r!==0)return r>0?this.updateBiggerAndSmallerAssociations(t,n):this.updateBiggerAndSmallerAssociations(n,t),r;if(!t.hasProperty(e.cr)||!n.hasProperty(e.cr))return this.getModelOrderFromConnectedEdges(t)>this.getModelOrderFromConnectedEdges(n)?(this.updateBiggerAndSmallerAssociations(t,n),1):(this.updateBiggerAndSmallerAssociations(n,t),-1)}if(r===null&&i===null){let e=this.handleHelperDummyNodes(t,n);if(e!==0)return e>0?this.updateBiggerAndSmallerAssociations(t,n):this.updateBiggerAndSmallerAssociations(n,t),e}}return t.hasProperty(e.cr)&&n.hasProperty(e.cr)&&O(t,n,this.graph,this.graph.getProperty(e.sr))>O(n,t,this.graph,this.graph.getProperty(e.sr))?(this.updateBiggerAndSmallerAssociations(t,n),1):(this.updateBiggerAndSmallerAssociations(n,t),-1)}getModelOrderFromConnectedEdges(t){let n=t.getPorts().find(e=>e.getIncomingEdges().length>0);if(n!==void 0){let t=n.getIncomingEdges()[0];if(t!==void 0)return t.getProperty(e.cr)}return Id(this.longEdgeNodeOrder)}updateBiggerAndSmallerAssociations(e,t){let n=this.biggerThan.get(e),r=this.biggerThan.get(t),i=this.smallerThan.get(e),a=this.smallerThan.get(t);n.add(t),a.add(e);for(let t of r){n.add(t),this.smallerThan.get(t).add(e);for(let e of i)this.smallerThan.get(t).add(e)}for(let e of i){a.add(e),this.biggerThan.get(e).add(t);for(let t of r)this.biggerThan.get(e).add(t)}}handleHelperDummyNodes(e,t){if(e.getType()===`LONG_EDGE`&&t.getType()===`NORMAL`){let n=this.getFirstIncomingSourcePortOfNode(e).getNode(),r=this.getFirstOutgoingTargetPortOfNode(e).getNode(),i=e.getLayer().id;return n.getLayer().id!==i&&r.getLayer().id!==i?0:n===t||r===t?(this.updateBiggerAndSmallerAssociations(e,t),1):this.compare(n,t)}if(e.getType()===`NORMAL`&&t.getType()===`LONG_EDGE`){let n=this.getFirstIncomingSourcePortOfNode(t).getNode(),r=this.getFirstOutgoingTargetPortOfNode(t).getNode(),i=e.getLayer().id;return n.getLayer().id!==i&&r.getLayer().id!==i?0:n===e||r===e?(this.updateBiggerAndSmallerAssociations(t,e),-1):this.compare(e,n)}if(e.getType()===`LONG_EDGE`&&t.getType()===`LONG_EDGE`){let n=this.getFirstIncomingSourcePortOfNode(e),r=this.getFirstOutgoingTargetPortOfNode(e),i=n.getNode(),a=r.getNode(),o=e.getLayer().id,s=!1,c=!1,l=this.getFirstIncomingSourcePortOfNode(t),u=this.getFirstOutgoingTargetPortOfNode(t),d=l.getNode(),f=u.getNode(),p=t.getLayer().id,m=!1,h=!1,g=e,_=t;if(i.getLayer().id===o?(s=!0,g=i):a.getLayer().id===o&&(c=!0,g=a),d.getLayer().id===p?(m=!0,_=d):f.getLayer().id===p&&(h=!0,_=f),g===_){if(this.beforePorts){if(s&&m)return new Pd(this.graph,this.previousLayer,this.orderingStrategy,null,h).compare(n,l)>0?(this.updateBiggerAndSmallerAssociations(t,e),1):(this.updateBiggerAndSmallerAssociations(e,t),-1);if(s&&h)return this.updateBiggerAndSmallerAssociations(t,e),1;if(c&&m)return this.updateBiggerAndSmallerAssociations(e,t),-1;if(c&&h)return 0}else for(let r of g.getPorts()){if(n===r)return this.updateBiggerAndSmallerAssociations(t,e),-1;if(l===r)return this.updateBiggerAndSmallerAssociations(e,t),1}}return this.compare(g,_)}return 0}getFirstIncomingPortOfNode(e){return e.getPorts().find(e=>e.getIncomingEdges().length>0)}getFirstIncomingSourcePortOfNode(e){return this.getFirstIncomingPortOfNode(e).getIncomingEdges()[0].getSource()}getFirstOutgoingPortOfNode(e){return e.getPorts().find(e=>e.getOutgoingEdges().length>0)}getFirstOutgoingTargetPortOfNode(e){return this.getFirstOutgoingPortOfNode(e).getOutgoingEdges()[0].getTarget()}clearTransitiveOrdering(){this.biggerThan=/* @__PURE__ */ new Map,this.smallerThan=/* @__PURE__ */ new Map}};function Id(e){switch(e){case`DUMMY_NODE_OVER`:return 2**53-1;case`DUMMY_NODE_UNDER`:return-(2**53-1);default:return 0}}function Ld(e){switch(e){case`UNDEFINED`:return 0;case`NORTH`:return 1;case`EAST`:return 2;case`SOUTH`:return 3;case`WEST`:return 4}}function Rd(t){let n=0;for(let r of t.getLayers()){r.id=n;let i=n===0?0:n-1,a=t.getLayers()[i].getNodes(),o=new Fd(t,a,t.getProperty(e.O),t.getProperty(e.T),t.getProperty(e.S),!0);Vd(r.getNodes(),o);for(let n of r.getNodes()){let r=n.getProperty(e.Lt);if(r!==`FIXED_ORDER`&&r!==`FIXED_POS`){let r=new Pd(t,a,t.getProperty(e.O),zd(n),t.getProperty(e.D));n.getPorts().sort((e,t)=>r.compare(e,t))}}o=new Fd(t,a,t.getProperty(e.O),t.getProperty(e.T),t.getProperty(e.S),!1),Vd(r.getNodes(),o),n++}}function zd(t){let n=/* @__PURE__ */ new Map;if(t.hasProperty(e.kr))return t.getProperty(e.kr);for(let r of t.getPorts()){if(r.getOutgoingEdges().length===0)continue;let t=Bd(r);if(r.setProperty(e.ar,t),t!==null){let i=2**53-1;n.has(t)&&(i=n.get(t));let a=r.getOutgoingEdges()[0];a.getProperty(e.Sr)||n.set(t,Math.min(a.getProperty(e.cr),i))}}return t.setProperty(e.kr,n),n}function Bd(t){let n=null,r=t.getOutgoingEdges()[0];for(;;){if(n=r.getTarget().getNode(),n.hasProperty(e.ir))return n.getProperty(e.ir).getNode();if(n.getType()!==`NORMAL`&&n.getOutgoingEdges().length>0)r=n.getOutgoingEdges()[0];else if(n.getType()!==`NORMAL`)return null;if(n.getType()===`NORMAL`)break}return n}function Vd(e,t){for(let n=1;n<e.length;n++){let r=e[n],i=n;for(;i>0&&t.compare(e[i-1],r)>0;)e[i]=e[i-1],i--;e[i]=r}t.clearTransitiveOrdering()}function Hd(t){let n=!1;for(let r of t.getLayers()){let t=r.getNodes().filter(e=>e.getType()===`NORMAL`).filter(t=>t.hasProperty(e.Ht)&&t.getProperty(e.Ht)!==null).sort((t,n)=>{let r=t.getProperty(e.Ht),i=n.getProperty(e.Ht);return(r?.y??0)-(i?.y??0)});for(let r=0;r+1<t.length;r++){let i=t[r].getProperty(e.Qn)??[];i.push(t[r+1]),t[r].setProperty(e.Qn,i),n=!0}}n&&t.setProperty(e.$n,!0)}function Ud(t){let n=t.getLayerlessNodes().filter(t=>t.hasProperty(e.kt)),r=[];for(let i of t.getLayerlessNodes())if(i.hasProperty(e.kt))for(let e of i.getOutgoingEdges())Wd(e,n)&&r.push(e);for(let n of r){n.reverse(t,!0);let r=1e3;n.hasProperty(e.Ut)&&(r+=n.getProperty(e.Ut)),n.setProperty(e.Ut,r)}}function Wd(t,n){let r=t.getSource()?.getNode(),i=t.getTarget()?.getNode();if(!r||!i)return!1;let a=r.getProperty(e.kt);if(i.hasProperty(e.kt))return a>i.getProperty(e.kt);let o=n.filter(t=>t.getProperty(e.kt)<a),s=[r],c=/* @__PURE__ */ new Set([r]);for(;s.length>0;){let e=s.shift();if(o.includes(e))return!0;for(let t of e.getOutgoingEdges()){let e=t.getTarget()?.getNode();e&&!c.has(e)&&(c.add(e),s.push(e))}}return!1}function Gd(t){let n=/* @__PURE__ */ new Map;for(let r of t.getLayerlessNodes())if(r.hasProperty(e.kt)){let t=r.getProperty(e.kt);n.has(t)||n.set(t,[]),n.get(t).push(r)}if(n.size===0)return;let r=[...n.keys()].sort((e,t)=>e-t);for(let e=0;e+1<r.length;e++)Kd(n.get(r[e]),n.get(r[e+1]))}function Kd(t,n){for(let r of t){let t=new p;t.setNode(r),t.setSide(`EAST`),t.setProperty(e.gr,!0);for(let r of n){let n=new p;n.setNode(r),n.setSide(`WEST`),n.setProperty(e.gr,!0);let i=new m;i.setProperty(e.gr,!0),i.setSource(t),i.setTarget(n)}}}function qd(t){for(let n of t.getLayers())for(let t of n.getNodes())t.setPorts(t.getPorts().filter(t=>!t.getProperty(e.gr)))}function Jd(t){t.getProperty(e.Ot)&&t.getProperty(e.Gn).add(`PARTITIONS`)}function Yd(t){let n=t.getProperty(e.J),r=t.getProperty(e.X);r===0&&(r=2**53-1);let i=t.getLayers(),a=0;for(;a<i.length;){let e=i[a],o=[],s=-1,c=-1;for(let t of[...e.getNodes()])if($d(t)>=n){let e=Xd(t,n,r);s=Math.max(s,e.incMax),c=Math.max(c,e.outMax),o.push([t,e])}let l=[];for(let e=0;e<s;e++){let e=new w(t);i.splice(a,0,e),l.unshift(e)}l.reverse();for(let[,e]of o)if(e.incRoots!==null)for(let t of e.incRoots)Qd(t,e=>e.getIncomingEdges(),l);let u=a+Math.max(0,s),d=[];for(let e=0;e<c;e++){let n=new w(t);i.splice(u+1+e,0,n),d.push(n)}for(let[,e]of o)if(e.outRoots!==null)for(let t of e.outRoots)Qd(t,e=>e.getOutgoingEdges(),d);a+=Math.max(0,s)+1+Math.max(0,c)}for(let e=i.length-1;e>=0;e--)i[e].getNodes().length===0&&i.splice(e,1)}function Xd(e,t,n){let r={incMax:-1,incRoots:null,outMax:-1,outRoots:null};for(let i of e.getIncomingEdges()){if(i.isSelfLoop())continue;let e=i.getSource().getNode();if(ef(e,e=>e.getOutgoingEdges())){let i=Zd(e,e=>e.getOutgoingEdges(),e=>e.getIncomingEdges(),t,n);if(i===-1)continue;r.incMax=Math.max(r.incMax,i),r.incRoots===null&&(r.incRoots=[]),r.incRoots.push(e)}}for(let i of e.getOutgoingEdges()){if(i.isSelfLoop())continue;let e=i.getTarget().getNode();if(ef(e,e=>e.getIncomingEdges())){let i=Zd(e,e=>e.getIncomingEdges(),e=>e.getOutgoingEdges(),t,n);if(i===-1)continue;r.outMax=Math.max(r.outMax,i),r.outRoots===null&&(r.outRoots=[]),r.outRoots.push(e)}}return r}function Zd(e,t,n,r,i){if($d(e)>=r||!ef(e,t))return-1;let a=n(e);if(a.length===0)return 1;let o=0;for(let s of a){let a=Zd(tf(s,e),t,n,r,i);if(a===-1||(o=Math.max(o,a),o>i-1))return-1}return o+1}function Qd(e,t,n){e.setLayer(n[0]);let r=n.slice(1);for(let n of t(e))Qd(tf(n,e),t,r)}function $d(e){return e.getConnectedEdges().length}function ef(e,t){let n=null;for(let r of t(e)){let t=tf(r,e);if(n===null)n=t;else if(t!==n)return!1}return!0}function tf(e,t){let n=e.getSource()?.getNode(),r=e.getTarget()?.getNode();return n===t?r:n}function nf(t){let n=1,r=[];for(let i=0;i<t.getLayers().length;i++){let a=t.getLayers()[i],o=rf(a),s=af(a);if(of(a)){let n=0,r=0;for(let e of a.getNodes())n=Math.max(n,e.size.x),r+=e.size.y;if(r/=a.getNodes().length,n+=Math.max(2*t.getProperty(e.rn),Math.max(a.getNodes().length*t.getProperty(e.en),t.getProperty(e.un))),r+=Math.max(t.getProperty(e.ln),t.getProperty(e.nn)),n/r>=a.getNodes().length/4)continue}if(a.getNodes().length>=o){let e=[a];for(let a=0;a<o-1;a++){let o=new w(t);r.push({layer:o,index:i+a+n}),e.push(o)}n+=o-1;let c=e[0].getNodes().length;for(let n=0,r=0,i=0;n<c;n++,r++,i++){let a=e[0].getNodes()[r];a.getType()===`NONSHIFTING_PLACEHOLDER`?(--n,--i):r+=sf(t,e,i%o,r),s&&a.getType()===`LONG_EDGE`&&(i=-1)}}}for(let e of r)t.getLayers().splice(e.index,0,e.layer);for(let e of t.getLayers()){let t=e.getNodes();for(let e=t.length-1;e>=0;e--){let n=t[e];(n.getType()===`PLACEHOLDER`||n.getType()===`NONSHIFTING_PLACEHOLDER`)&&t.splice(e,1)}}}function rf(t){let n=2**53-1,r=!0;for(let i=0;i<t.getNodes().length;i++){let a=t.getNodes()[i];if(a.hasProperty(e.ut)){r=!1;let t=a.getProperty(e.ut);n=n<t?n:t}}return r&&(n=e.ut.getDefault()),n}function af(t){for(let n=0;n<t.getNodes().length;n++){let r=t.getNodes()[n];if(r.hasProperty(e.ft)&&!r.getProperty(e.ft))return!1}return!0}function of(t){for(let n=0;n<t.getNodes().length;n++){let r=t.getNodes()[n];if(r.hasProperty(e.dt)&&r.getProperty(e.dt))return!0}return!1}function sf(e,t,n,r){let i=t[0].getNodes()[r];n>0&&i.setLayer(t[n]);let a=0,o=!0,s=[...i.getIncomingEdges()].reverse();for(let i of s){o=!1;let s=i;for(let i=0;i<n;i++){let n=cf(e,s);r+a>t[i].getNodes().length?n.setLayer(t[i]):n.setLayerAt(r+a,t[i]),s=ue(s,n)}n>0&&(a+=1)}if(o){for(let i=0;i<n;i++){let n=new f(e);n.setType(`PLACEHOLDER`),r+a>t[i].getNodes().length?n.setLayer(t[i]):n.setLayerAt(r+a,t[i])}n>0&&(a+=1)}let c=!1;for(let o of i.getOutgoingEdges()){let i=o;for(let r=n+1;r<t.length;r++){let n=cf(e,i);n.setLayer(t[r]),i=ue(i,n)}for(let i=0;i<=n;i++)if(c){let n=new f(e);n.setType(`NONSHIFTING_PLACEHOLDER`),r+1>t[i].getNodes().length?n.setLayer(t[i]):n.setLayerAt(r+1,t[i])}c&&(a+=1),c=!0}return a>0?a-1:0}function cf(t,n){let r=new f(t);return r.setType(`LONG_EDGE`),r.setProperty(e.lr,n),r.setProperty(e.Lt,`FIXED_POS`),r}function lf(t){let n=t.getProperty(e.P),r=n===`MODEL_ORDER`||n===`GREEDY_MODEL_ORDER`||n===`BFS_NODE_ORDER`||n===`DFS_NODE_ORDER`||n===`SCC_CONNECTIVITY`||n===`SCC_NODE_TYPE`,i=t.getProperty(e.lt),a=i===`BF_MODEL_ORDER`||i===`DF_MODEL_ORDER`||t.getProperty(e.ct)===`MODEL_ORDER_LEFT_TO_RIGHT`||t.getProperty(e.ct)===`MODEL_ORDER_RIGHT_TO_LEFT`,o=t.getProperty(e.O)!==`NONE`||t.getProperty(e.Pn)||t.getProperty(e.y)!==e.Dn.NONE;return r||a||o}function uf(e){let t=[],n=[e];for(;n.length>0;){let e=n.pop();t.push(e);for(let t of e.getLayerlessNodes()){let e=t.getNestedGraph();e!==null&&n.push(e)}}return t}function df(t){if(!lf(t))return;let n=0,r=/* @__PURE__ */ new Set;for(let i of t.getLayerlessNodes())i.getProperty(e.E)||(i.setProperty(e.cr,n++),i.hasProperty(e.w)&&r.add(i.getProperty(e.w)));t.setProperty(e.sr,n),t.setProperty(e.jn,r.size);let i=0;for(let n of t.getLayerlessNodes())for(let t of n.getPorts())for(let n of t.getOutgoingEdges())n.setProperty(e.cr,i++)}function ff(e){for(let t of uf(e))df(t)}function pf(t){let n=[t];for(;n.length>0;){let t=n.pop();for(let r of t.getLayerlessNodes()){let t=r.getOutgoingEdges().some(t=>t.isSelfLoop()&&t.getProperty(e.$));if(r.getProperty(e.Q)&&t&&r.getNestedGraph()===null){let t=new c;r.setNestedGraph(t),t.setParentNode(r),t.setProperty(e.F,`RIGHT`)}let i=r.getNestedGraph();i!==null&&n.push(i)}}}var mf=class{begin(){}done(){}};function hf(e){let t=[],n=[e];for(;n.length>0;){let e=n.pop();for(let t of e.getLayerlessNodes()){let e=t.getNestedGraph();e!==null&&n.push(e)}t.push(e)}return t.reverse()}function gf(t,n,r,i){let a={x:n.position.x+n.size.x/2,y:n.position.y+n.size.y/2},o=n.getProperty(e.It),s=t.getSize(),c=t.getPadding(),l=t.getOffset();switch(n.getProperty(e.lr),n.getProperty(e.Un)){case`NORTH`:a.x+=c.left+l.x-r/2,a.y=-i-o,n.position.y=-(c.top+o+l.y);break;case`EAST`:a.x=s.x+c.left+c.right+o,a.y+=c.top+l.y-i/2,n.position.x=s.x+c.right+o-l.x;break;case`SOUTH`:a.x+=c.left+l.x-r/2,a.y=s.y+c.top+c.bottom+o,n.position.y=s.y+c.bottom+o-l.y;break;case`WEST`:a.x=-r-o,a.y+=c.top+l.y-i/2,n.position.x=-(c.left+o+l.x)}return a}function _f(t,n){let r=t.getNestedGraph();if(r===null)return;let i=r.getAllNodes();if(i.length===0)return;let a=t=>{let r=t.getType();if(r===`NORMAL`||r===`LONG_EDGE`)return!0;if(r===`EXTERNAL_PORT`){if(!n&&o)return!1;let r=t.getProperty(e.Un);return r===`WEST`||r===`EAST`||t.getPorts().some(e=>e.getConnectedEdges().length>0)}return!1},o=i.some(e=>e.getType()===`NORMAL`||e.getType()===`LONG_EDGE`),s=i.filter(a);if(s.length===0)return;let c=1/0,l=1/0,u=-1/0,d=-1/0,f=1/0,m=1/0;for(let e of s){let t=e.getMargin();if(c=Math.min(c,e.position.x-t.left),l=Math.min(l,e.position.y-t.top),u=Math.max(u,e.position.x+e.size.x+t.right),d=Math.max(d,e.position.y+e.size.y+t.bottom),e.getType()===`EXTERNAL_PORT`){let n=e.position.x;if(n<0||n>r.getSize().x){m=Math.min(m,e.position.y-t.top);continue}}f=Math.min(f,e.position.x-t.left),m=Math.min(m,e.position.y-t.top)}let h=r.getPadding(),g=t.size.x,_=t.size.y,v=r.getSize().x+h.left+h.right,y=r.getSize().y+h.top+h.bottom,b=r.getProperty(e.Et);b&&(v=Math.max(v,b.x),y=Math.max(y,b.y)),Pf&&r.getProperty(e.Vn)?.length>0&&(v=r.getSize().x+h.left+h.right,y=r.getSize().y+h.top+h.bottom,b&&(v=Math.max(v,b.x),y=Math.max(y,b.y)));{let e=r.getSize().x+h.left+h.right,n=r.getSize().y+h.top+h.bottom,i=t.getProperty(`org.eclipse.elk.contentAlignment`)??[];if(v>e||y>n){let t=r.getOffset();v>e&&(i.includes(`H_CENTER`)?t.x+=(v-e)/2:i.includes(`H_RIGHT`)&&(t.x+=v-e)),y>n&&(i.includes(`V_CENTER`)?t.y+=(y-n)/2:i.includes(`V_BOTTOM`)&&(t.y+=y-n))}}f=-r.getOffset().x,m=-r.getOffset().y;let x=h.left-f,S=h.top-m;if(n&&(x!==0||S!==0)){for(let e of i)e.getType()===`NORMAL`&&(e.position.x+=x,e.position.y+=S);let e=/* @__PURE__ */ new Set;for(let t of i)for(let n of t.getPorts())for(let t of n.getConnectedEdges())if(!e.has(t)){e.add(t);for(let e of t.getBendPoints())e.x+=x,e.y+=S;for(let e of t.getLabels())e.position.x+=x,e.position.y+=S}}if(r.getProperty(e.Gn).has(`EXTERNAL_PORTS`)){t.setProperty(e.Lt,`FIXED_POS`),t.getGraph().getProperty(e.Gn).add(`NON_FREE_PORTS`);for(let t of r.getAllNodes()){let n=t.getProperty(e.lr);if(n instanceof p){let i=n,a=gf(r,t,i.getSize().x,i.getSize().y);i.getPosition().x=a.x,i.getPosition().y=a.y,i.setSide(t.getProperty(e.Un))}}if(n&&S!==0&&i.some(e=>e.getType()===`NORMAL`))for(let t of r.getAllNodes()){if(t.getType()!==`EXTERNAL_PORT`)continue;let n=t.getProperty(e.Un);if(n===`WEST`||n===`EAST`){t.position.y+=S;for(let e of t.getPorts())for(let t of e.getLabels())t.position.y-=S}}t.size.x=v,t.size.y=y,r.getSize().x=v,r.getSize().y=y}else{if(g>0&&_>0){let e=v/g,n=y/_,r=v-g,i=y-_;for(let a of t.getPorts())switch(a.getSide()){case`NORTH`:a.getPosition().x*=e;break;case`EAST`:a.getPosition().x+=r,a.getPosition().y*=n;break;case`SOUTH`:a.getPosition().x*=e,a.getPosition().y+=i;break;case`WEST`:a.getPosition().y*=n}}t.size.x=v,t.size.y=y,r.getSize().x=v,r.getSize().y=y}}function vf(t,n,r){let i=t.getProperty(e.F)===`UNDEFINED`?`RIGHT`:t.getProperty(e.F);for(let n of t.getAllNodes()){let t=n.getProperty(e.Lt);if(e.Lr.isSideFixed(t))for(let e of n.getPorts())Ki(e,t,i)}let a=t.getProperty(e.Gn),o=t.getProperty(e.F),s=o===`UNDEFINED`?`RIGHT`:o;for(let n of t.getLayerlessNodes()){let r=n.getProperty(e.Lt);r!==`FREE`&&r!==`UNDEFINED`&&a.add(`NON_FREE_PORTS`),n.getProperty(e.Z)&&(a.add(`HYPERNODES`),a.add(`HYPEREDGES`),n.setProperty(e.Lt,`FREE`)),Jd(t);for(let e of n.getPorts()){let t=e.getSide();(s===`RIGHT`||s===`LEFT`?t===`NORTH`||t===`SOUTH`:t===`EAST`||t===`WEST`)&&a.add(`NORTH_SOUTH_PORTS`),e.getIncomingEdges().length+e.getOutgoingEdges().length>1&&a.add(`HYPEREDGES`);for(let t of e.getOutgoingEdges()){t.getTarget()!==null&&t.getTarget().getNode()===n&&a.add(`SELF_LOOPS`);for(let e of t.getLabels())e.placement===`HEAD`||e.placement===`TAIL`?a.add(`END_LABELS`):a.add(`CENTER_LABELS`)}}}Q(`GraphTransformer(in)`,r,t,()=>new qu(`TO_INPUT_DIRECTION`).process(t));for(let n of t.getAllNodes())n.hasProperty(e.mr)||n.setProperty(e.mr,n.getProperty(e.Lt));(t.getProperty(e.bt)===null||t.getProperty(e.bt)===void 0)&&t.setProperty(e.bt,t.getProperty(e.B)===`ORTHOGONAL`),t.getProperty(e.Gn).has(`COMMENTS`)&&Q(`CommentPreprocessor`,r,t,()=>Cu(t)),t.getProperty(e.lt)!==`INTERACTIVE`&&Q(`EdgeAndLayerConstraintEdgeReverser`,r,t,()=>new S().process(t));let c=t.getProperty(e.Gn).has(`SELF_LOOPS`);c&&Q(`SelfLoopPreprocessor`,r,t,()=>tl(t)),t.getProperty(e.Gn).has(`PARTITIONS`)&&Q(`PartitionPreprocessor`,r,t,()=>Ud(t)),(t.getProperty(e.P)===`INTERACTIVE`||t.getProperty(e.lt)===`INTERACTIVE`)&&Q(`InteractiveExternalPortPositioner`,r,t,()=>$s(t));let l=t.getProperty(e.P);l===`MODEL_ORDER`?Q(`ModelOrderCycleBreaker`,r,t,()=>b(t,n)):l===`GREEDY_MODEL_ORDER`?Q(`GreedyModelOrderCycleBreaker`,r,t,()=>new x().process(t,n)):l===`DEPTH_FIRST`?Q(`DepthFirstCycleBreaker`,r,t,()=>new Po().process(t,n)):l===`SCC_CONNECTIVITY`?Q(`SCConnectivity`,r,t,()=>new zo().process(t,n)):l===`SCC_NODE_TYPE`?Q(`SCCNodeTypeCycleBreaker`,r,t,()=>new Ho().process(t,n)):l===`DFS_NODE_ORDER`?Q(`DFSNodeOrderCycleBreaker`,r,t,()=>new Io().process(t,n)):l===`BFS_NODE_ORDER`?Q(`BFSNodeOrderCycleBreaker`,r,t,()=>new Fo().process(t,n)):l===`INTERACTIVE`?Q(`InteractiveCycleBreaker`,r,t,()=>_(t)):Q(`GreedyCycleBreaker`,r,t,()=>new h().process(t,n)),r?.afterPhase?.(`P1`,t),Q(`LabelDummyInserter`,r,t,()=>me(t)),Q(`LayerConstraintPreprocessor`,r,t,()=>new Do().process(t)),t.getProperty(e.Gn).has(`PARTITIONS`)&&Q(`PartitionMidprocessor`,r,t,()=>Gd(t));let u=t.getProperty(e.lt);u===`INTERACTIVE`?Q(`InteractiveLayerer`,r,t,()=>Mo(t,n)):u===`LONGEST_PATH_SOURCE`?Q(`LongestPathSourceLayerer`,r,t,()=>new se().process(t,n)):u===`LONGEST_PATH`||u===`LONGEST_PATH_SINK`?Q(`LongestPathLayerer`,r,t,()=>new oe().process(t,n)):u===`COFFMAN_GRAHAM`?Q(`CoffmanGrahamLayerer`,r,t,()=>new Wo().process(t,n)):u===`BF_MODEL_ORDER`?Q(`BreadthFirstModelOrderLayerer`,r,t,()=>new Go().process(t,n)):u===`DF_MODEL_ORDER`?Q(`DepthFirstModelOrderLayerer`,r,t,()=>new Ko().process(t,n)):u===`MIN_WIDTH`?Q(`MinWidthLayerer`,r,t,()=>new qo().process(t,n)):u===`STRETCH_WIDTH`?Q(`StretchWidthLayerer`,r,t,()=>new Jo().process(t,n)):Q(`NetworkSimplexLayerer`,r,t,()=>new ae().process(t,n)),r?.afterPhase?.(`P2`,t),t.getProperty(e.Y)&&Q(`HighDegreeNodeLayeringProcessor`,r,t,()=>Yd(t)),t.getProperty(e.ct)!==`NONE`&&Q(`NodePromotion`,r,t,()=>new qe().process(t,n)),Q(`LayerConstraintPostprocessor`,r,t,()=>Oo(t)),t.getProperty(e.Gn).has(`PARTITIONS`)&&Q(`PartitionPostprocessor`,r,t,()=>qd(t)),Pf&&t.getProperty(e.Gn).has(`EXTERNAL_PORTS`)&&Q(`HierarchicalPortConstraintProcessor`,r,t,()=>new cl().process(t)),t.getProperty(e.wn)===`MULTI_EDGE`&&Q(`BreakingPointInserter`,r,t,()=>fc(t)),Q(`LongEdgeSplitter`,r,t,()=>ce(t)),Q(`PortSideProcessor`,r,t,()=>qi(t));let d=t.getProperty(e.B);(d===`POLYLINE`||d===`SPLINES`||d===`ORTHOGONAL`&&(t.getProperty(e.Gn).has(`NON_FREE_PORTS`)||t.getProperty(e.G)||t.getProperty(e.Gn).has(`HYPEREDGES`)))&&Q(`InvertedPortProcessor`,r,t,()=>xu(t)),c&&Q(`DummySelfLoopProcessor`,r,t,()=>pu(t)),t.getProperty(e.O)!==`NONE`&&Q(`SortByInputModel`,r,t,()=>Rd(t)),Q(`PortListSorter`,r,t,()=>Bc(t)),t.getProperty(e.Gn).has(`EXTERNAL_PORTS`)&&!Pf&&Q(`HierarchicalPortConstraintProcessor`,r,t,()=>new cl().process(t)),t.getProperty(e.M)&&Q(`SemiInteractiveCrossMinProcessor`,r,t,()=>Hd(t)),t.getProperty(e.Gn).has(`NON_FREE_PORTS`)&&t.getProperty(e.Gn).has(`NORTH_SOUTH_PORTS`)&&Q(`NorthSouthPortPreprocessor`,r,t,()=>Gc(t))}function yf(t,n,r,i=!1){let a=t.getProperty(e.Gn).has(`SELF_LOOPS`);t.setProperty(e.wr,new un(t)),a&&Q(`SelfLoopPortRestorer`,r,t,()=>new Rl().process(t)),Q(`InLayerConstraintProcessor`,r,t,()=>Ol(t)),Q(`LabelAndNodeSizeProcessor`,r,t,()=>Ks(t)),Q(`NodeMarginCalculator`,r,t,()=>na(t)),t.getProperty(e.Gn).has(`COMMENTS`)&&Q(`CommentNodeMarginCalculator`,r,t,()=>Eu(t)),t.getProperty(e.Gn).has(`END_LABELS`)&&Q(`EndLabelPreprocessor`,r,t,()=>Xu(t)),t.getProperty(e.Gn).has(`CENTER_LABELS`)&&Q(`LabelDummySwitcher`,r,t,()=>be(t)),(t.getProperty(e.Gn).has(`END_LABELS`)||t.getProperty(e.Gn).has(`CENTER_LABELS`))&&Q(`LabelSideSelector`,r,t,()=>ud(t)),t.getProperty(e.Gn).has(`HYPEREDGES`)&&t.getProperty(e.B)!==`SPLINES`&&Q(`HyperedgeDummyMerger`,r,t,()=>new C().process(t)),Q(`HierarchicalPortDummySizeProcessor`,r,t,()=>al(t)),a&&Q(`SelfLoopRouter`,r,t,()=>du(t)),t.getProperty(e.wn)===`MULTI_EDGE`&&Q(`BreakingPointProcessor`,r,t,()=>yc(t));let o=t.getProperty(e.wt);o===`SIMPLE`?Q(`SimpleNodePlacer`,r,t,()=>on(t)):o===`INTERACTIVE`?Q(`InteractiveNodePlacer`,r,t,()=>sn(t)):o===`NETWORK_SIMPLEX`?Q(`NetworkSimplexPlacer`,r,t,()=>new bn().process(t)):o===`LINEAR_SEGMENTS`?Q(`LinearSegmentsNodePlacer`,r,t,()=>Zo(t)):(o!==`BRANDES_KOEPF`&&Mf(`nodePlacement.strategy`,String(o),`BRANDES_KOEPF`),Q(`BKNodePlacer`,r,t,()=>new an().process(t))),r?.afterPhase?.(`BK`,t),t.getLayerlessNodes().length>0&&t.hasProperty(e.Ct)&&Q(`NodePlacementRepeater`,r,t,()=>Zs(t)),Q(`LayerSizeAndGraphHeightCalculator`,r,t,()=>new xn().process(t)),t.getProperty(e.Gn).has(`EXTERNAL_PORTS`)&&Q(`HierarchicalPortPositionProcessor`,r,t,()=>ll(t));let s=t.getProperty(e.B);if(s===`POLYLINE`?Q(`PolylineEdgeRouter`,r,t,()=>new Fr().process(t)):s===`SPLINES`?Q(`SplineEdgeRouter`,r,t,()=>new gi().process(t)):(s!==`ORTHOGONAL`&&s!=null&&Mf(`edgeRouting`,String(s),`ORTHOGONAL`),Q(`OrthogonalEdgeRouter`,r,t,()=>new rr().process(t))),r?.afterPhase?.(`P5`,t),(t.getProperty(e.et)||t.getProperty(e.K))&&Q(`ConstraintsPostprocessor`,r,t,()=>ss(t)),t.getProperty(e.Gn).has(`HYPERNODES`)&&Q(`HypernodesProcessor`,r,t,()=>cs(t)),Q(`LongEdgeJoiner`,r,t,()=>He(t)),a&&Q(`SelfLoopPostprocessor`,r,t,()=>kl(t)),t.getProperty(e.wn)===`MULTI_EDGE`&&Q(`BreakingPointRemover`,r,t,()=>Oc(t)),t.getProperty(e.Gn).has(`NON_FREE_PORTS`)&&t.getProperty(e.Gn).has(`NORTH_SOUTH_PORTS`)&&Q(`NorthSouthPortPostprocessor`,r,t,()=>_u(t)),t.getProperty(e.v)!==`NONE`&&t.getProperty(e.B)!==`POLYLINE`&&Q(`HorizontalGraphCompactor`,r,t,()=>new Mr().process(t)),Q(`LabelDummyRemover`,r,t,()=>We(t)),s===`SPLINES`&&Q(`FinalSplineBendpointsCalculator`,r,t,()=>bi(t)),t.getProperty(e.Gn).has(`COMMENTS`)&&Q(`CommentPostprocessor`,r,t,()=>ku(t)),Q(`EndLabelSorter`,r,t,()=>wd(t)),Q(`ReversedEdgeRestorer`,r,t,()=>jc(t)),t.getProperty(e.Gn).has(`EXTERNAL_PORTS`)&&Q(`HierarchicalPortOrthogonalEdgeRouter`,r,t,()=>dl(t)),t.getProperty(e.Gn).has(`END_LABELS`)&&Q(`EndLabelPostprocessor`,r,t,()=>Md(t)),!i){Q(`GraphTransformer(out)`,r,t,()=>new qu(`TO_INTERNAL_LTR`).process(t));for(let n of t.getLayers())for(let r of n.getNodes())ra(r),t.getProperty(e.Gn).has(`COMMENTS`)&&Du(r)}}function bf(t){let n=t.getParentNode();if(n===null)return;let r=t.getProperty(e.F);if(r!==`DOWN`&&r!==`UP`)return;let i=n.getGraph()?.getProperty(e.F);if(i!==`RIGHT`&&i!==`UNDEFINED`)return;let a=n.size.x;n.size.x=n.size.y,n.size.y=a;let o=n.getPadding(),s=o.left;o.left=o.top,o.top=s;let c=o.right;o.right=o.bottom,o.bottom=c}function xf(t){let n=t.getParentNode();return n!==null&&n.getProperty(e.q)===`SEPARATE_CHILDREN`}function Sf(t,n,r){let a=hf(t);Df(t,a);for(let t of a)if(t.getProperty(e.br)===void 0){let n=t.getProperty(e.Kt);t.setProperty(e.br,n===0?new i:new i(n))}for(let e of a)If(e)||vf(e,n,r);let o=a[a.length-1],s=o.getProperty(e.N);s===`INTERACTIVE`?(Q(`InteractiveCrossingMinimizer`,r,o,()=>new Wt().process(o)),r?.afterPhase?.(`P3`,o)):s===`MEDIAN_LAYER_SWEEP`?(Q(`LayerSweepCrossingMinimizer`,r,o,()=>new Ut(3).process(o,n)),r?.afterPhase?.(`P3`,o)):(Q(`LayerSweepCrossingMinimizer`,r,o,()=>new Ut(0).process(o,n)),r?.afterPhase?.(`P3`,o));let c=/* @__PURE__ */ new Set;for(let e of a){if(If(e))continue;yf(e,n,r,!0);let t=e.getParentNode();if(t!==null&&_f(t,!0),xf(e)){Q(`GraphTransformer(out)`,r,e,()=>new qu(`TO_INTERNAL_LTR`).process(e)),bf(e);for(let t of e.getLayers())for(let e of t.getNodes())ra(e);c.add(e)}}for(let e of a)if(!c.has(e)){Q(`GraphTransformer(out)`,r,e,()=>new qu(`TO_INTERNAL_LTR`).process(e)),bf(e);for(let t of e.getLayers())for(let e of t.getNodes())ra(e)}let l=t.getOffset(),u=t.getPadding();for(let e of t.getAllNodes())e.position.x+=l.x+u.left,e.position.y+=l.y+u.top;let d=l.x+u.left,f=l.y+u.top;if(d!==0||f!==0){let e=/* @__PURE__ */ new Set;for(let n of t.getAllNodes())for(let t of n.getPorts())for(let n of t.getConnectedEdges())if(!e.has(n)){e.add(n);for(let e of n.getBendPoints())e.x+=d,e.y+=f}}r?.afterPhase?.(`done`,t)}function Cf(t){let n=t.getProperty(e.F);for(let r of t.getLayerlessNodes()){let t=r.getNestedGraph();if(t!==null){if(t.getProperty(e.F)===`UNDEFINED`){let i=r.getProperty(`org.eclipse.elk.hierarchyHandling`),a=r.getProperty(`org.eclipse.elk.direction`);i===`SEPARATE_CHILDREN`&&a!==void 0&&a!==`UNDEFINED`?t.setProperty(e.F,a):n!==`UNDEFINED`&&t.setProperty(e.F,n)}Cf(t)}}}function wf(t){for(let n of t.getLayerlessNodes()){let t=n.getNestedGraph();if(t!==null){if(t.getProperty(e.Lt)===`UNDEFINED`){let r=n.getProperty(e.Lt);r!==`UNDEFINED`&&t.setProperty(e.Lt,r)}wf(t)}}}const Tf=[e.N,e.P,e.lt,e.M,e.et,e.Vt,e.B,e.I,e.Kt,e.A,e.k,e._t,e.ln,e.un,e.$t,e.en,e.nn,e.rn,e.pn,e.fn,e.zt];function Ef(e){for(let t of e.getLayerlessNodes()){let e=t.getNestedGraph();if(e!==null){for(let n of Tf)t.hasProperty(n)&&e.setProperty(n,t.getProperty(n));Ef(e)}}}function Df(t,n){let r=t.getProperty(e.N);for(let i of n){if(i===t)continue;let n=i.getProperty(e.N);if(n!==r){let e=i.getParentNode()?.id??`G-unlayered`;throw Error(`UnsupportedGraphException: The hierarchy aware processor `+n+` in child node `+e+` is only allowed if the root node specifies the same hierarchical processor.`)}}}function Of(t){let n=[t];for(;n.length>0;){let t=n.pop(),r=t.getProperty(e.F)===`UNDEFINED`?`RIGHT`:t.getProperty(e.F);for(let n of t.getAllNodes()){let t=n.getProperty(e.Lt);if(e.Lr.isSideFixed(t))for(let e of n.getPorts())Ki(e,t,r)}for(let e of t.getLayerlessNodes()){let t=e.getNestedGraph();t!==null&&n.push(t)}}}function kf(t,n,r){if(Cf(t),Ef(t),Pf&&wf(t),Of(t),Q(`CompoundGraphPreprocessor`,r,t,()=>new ca().process(t)),t.getProperty(e.q)===`INCLUDE_CHILDREN`){Sf(t,n,r),Q(`CompoundGraphPostprocessor`,r,t,()=>Co(t));return}let i=hf(t);for(let t of i)if(!If(t)&&(t.getLayers().length===0||t.getLayerlessNodes().length>0)){Af(t,n,r);let i=t.getParentNode();if(i!==null&&t.getProperty(e.Gn).has(`EXTERNAL_PORTS`)&&t.getSize().x===0&&t.getAllNodes().some(e=>e.getType()===`EXTERNAL_PORT`)){let n=[],r=/* @__PURE__ */ new Set;for(let e of t.getAllNodes())r.has(e)||(r.add(e),n.push(e));let a=/* @__PURE__ */ new Set,o=e=>{let t=[e];for(;t.length>0;){let e=t.pop();if(!a.has(e)){a.add(e);for(let n of e.getPorts())for(let e of n.getConnectedPorts()){let n=e.getNode();n!==null&&!a.has(n)&&t.push(n)}}}},s=0;for(let e of n)a.has(e)||(o(e),s++);let c=/* @__PURE__ */ new Set;for(let t of n){let n=t.getProperty(e.lr);n instanceof p&&c.add(n)}for(let e of i.getPorts())c.has(e)||s++;t.getSize().x=s>1?t.getProperty(e.Qt):-t.getProperty(e.Qt)}i!==null&&Pf&&t.getProperty(e.Gn).has(`EXTERNAL_PORTS`)&&dl(t),i!==null&&(_f(i,!1),bf(t))}Q(`CompoundGraphPostprocessor`,r,t,()=>Co(t))}function Q(e,t,n,r){t?.beforeModule?.(e,n),r(),t?.afterModule?.(e,n)}function Af(t,n,r){if(t.getProperty(e.br)===void 0){let n=t.getProperty(e.Kt);t.setProperty(e.br,n===0?new i:new i(n))}let a=t.getProperty(e.M)||t.getProperty(e.N)===`INTERACTIVE`,o=t.getProperty(e.A),s=t.getProperty(e.k),c=t.getLayerlessNodes().length,l=!a&&o!==`OFF`&&(s===0||s>c);t.setProperty(e.Kn,l);let u=new yo().split(t);if(u.length===1)Nf(t,n,r);else{for(let e of u){Nf(e,n,r,!1);for(let t of e.getLayers()){for(let n of[...t.getNodes()])e.getLayerlessNodes().includes(n)||e.getLayerlessNodes().push(n),n.setLayer(null);t.getNodes().length=0}e.getLayers().length=0,xo(e)}new yo().combine(u,t),r?.afterPhase?.(`combine`,t);let e=t.getOffset(),i=t.getPadding(),a=e.x+i.left,o=e.y+i.top,s=/* @__PURE__ */ new Set;for(let e of t.getLayerlessNodes()){e.position.x+=a,e.position.y+=o;for(let t of e.getPorts())for(let e of t.getConnectedEdges())if(!s.has(e)){s.add(e);for(let t of e.getBendPoints())t.x+=a,t.y+=o}}}}const jf=/* @__PURE__ */ new Set;function Mf(e,t,n){let r=`${e}=${t}`;jf.has(r)||(jf.add(r),console.warn(`[ggn] 未实现策略 ${e}=${t},降级为 ${n}(与 ELK 不一致,待移植/显式降级)`))}function Nf(t,n,r,i=!0){let a=t.getProperty(e.F)===`UNDEFINED`?`RIGHT`:t.getProperty(e.F);for(let n of t.getAllNodes()){let t=n.getProperty(e.Lt);if(e.Lr.isSideFixed(t))for(let e of n.getPorts())Ki(e,t,a)}let o=t.getProperty(e.Gn),s=t.getProperty(e.F),c=s===`UNDEFINED`?`RIGHT`:s;for(let n of t.getLayerlessNodes()){let r=n.getProperty(e.Lt);r!==`FREE`&&r!==`UNDEFINED`&&o.add(`NON_FREE_PORTS`),n.getProperty(e.Z)&&(o.add(`HYPERNODES`),o.add(`HYPEREDGES`),n.setProperty(e.Lt,`FREE`)),Jd(t);for(let e of n.getPorts()){let t=e.getSide();(c===`RIGHT`||c===`LEFT`?t===`NORTH`||t===`SOUTH`:t===`EAST`||t===`WEST`)&&o.add(`NORTH_SOUTH_PORTS`),e.getIncomingEdges().length+e.getOutgoingEdges().length>1&&o.add(`HYPEREDGES`);for(let t of e.getOutgoingEdges()){t.getTarget()!==null&&t.getTarget().getNode()===n&&o.add(`SELF_LOOPS`);for(let e of t.getLabels())e.placement===`HEAD`||e.placement===`TAIL`?o.add(`END_LABELS`):o.add(`CENTER_LABELS`)}}}Q(`GraphTransformer(in)`,r,t,()=>new qu(`TO_INPUT_DIRECTION`).process(t));for(let n of t.getAllNodes())n.hasProperty(e.mr)||n.setProperty(e.mr,n.getProperty(e.Lt));(t.getProperty(e.bt)===null||t.getProperty(e.bt)===void 0)&&t.setProperty(e.bt,t.getProperty(e.B)===`ORTHOGONAL`),t.getProperty(e.Gn).has(`COMMENTS`)&&Q(`CommentPreprocessor`,r,t,()=>Cu(t)),t.getProperty(e.lt)!==`INTERACTIVE`&&Q(`EdgeAndLayerConstraintEdgeReverser`,r,t,()=>new S().process(t));let l=t.getProperty(e.Gn).has(`SELF_LOOPS`);l&&Q(`SelfLoopPreprocessor`,r,t,()=>tl(t)),t.getProperty(e.Gn).has(`PARTITIONS`)&&Q(`PartitionPreprocessor`,r,t,()=>Ud(t)),(t.getProperty(e.P)===`INTERACTIVE`||t.getProperty(e.lt)===`INTERACTIVE`)&&Q(`InteractiveExternalPortPositioner`,r,t,()=>$s(t));let u=t.getProperty(e.P);u===`MODEL_ORDER`?Q(`ModelOrderCycleBreaker`,r,t,()=>b(t,n)):u===`GREEDY_MODEL_ORDER`?Q(`GreedyModelOrderCycleBreaker`,r,t,()=>new x().process(t,n)):u===`DEPTH_FIRST`?Q(`DepthFirstCycleBreaker`,r,t,()=>new Po().process(t,n)):u===`SCC_CONNECTIVITY`?Q(`SCConnectivity`,r,t,()=>new zo().process(t,n)):u===`SCC_NODE_TYPE`?Q(`SCCNodeTypeCycleBreaker`,r,t,()=>new Ho().process(t,n)):u===`DFS_NODE_ORDER`?Q(`DFSNodeOrderCycleBreaker`,r,t,()=>new Io().process(t,n)):u===`BFS_NODE_ORDER`?Q(`BFSNodeOrderCycleBreaker`,r,t,()=>new Fo().process(t,n)):u===`INTERACTIVE`?Q(`InteractiveCycleBreaker`,r,t,()=>_(t)):Q(`GreedyCycleBreaker`,r,t,()=>new h().process(t,n)),r?.afterPhase?.(`P1`,t),Q(`LabelDummyInserter`,r,t,()=>me(t)),Q(`LayerConstraintPreprocessor`,r,t,()=>new Do().process(t)),t.getProperty(e.Gn).has(`PARTITIONS`)&&Q(`PartitionMidprocessor`,r,t,()=>Gd(t));let d=t.getProperty(e.lt);d===`INTERACTIVE`?Q(`InteractiveLayerer`,r,t,()=>Mo(t,n)):d===`LONGEST_PATH_SOURCE`?Q(`LongestPathSourceLayerer`,r,t,()=>new se().process(t,n)):d===`LONGEST_PATH`||d===`LONGEST_PATH_SINK`?Q(`LongestPathLayerer`,r,t,()=>new oe().process(t,n)):d===`COFFMAN_GRAHAM`?Q(`CoffmanGrahamLayerer`,r,t,()=>new Wo().process(t,n)):d===`BF_MODEL_ORDER`?Q(`BreadthFirstModelOrderLayerer`,r,t,()=>new Go().process(t,n)):d===`DF_MODEL_ORDER`?Q(`DepthFirstModelOrderLayerer`,r,t,()=>new Ko().process(t,n)):d===`MIN_WIDTH`?Q(`MinWidthLayerer`,r,t,()=>new qo().process(t,n)):d===`STRETCH_WIDTH`?Q(`StretchWidthLayerer`,r,t,()=>new Jo().process(t,n)):Q(`NetworkSimplexLayerer`,r,t,()=>new ae().process(t,n)),r?.afterPhase?.(`P2`,t),t.getProperty(e.Y)&&Q(`HighDegreeNodeLayeringProcessor`,r,t,()=>Yd(t)),t.getProperty(e.ct)!==`NONE`&&Q(`NodePromotion`,r,t,()=>new qe().process(t,n)),Q(`LayerConstraintPostprocessor`,r,t,()=>Oo(t)),t.getProperty(e.Gn).has(`PARTITIONS`)&&Q(`PartitionPostprocessor`,r,t,()=>qd(t)),t.getProperty(e.wn)===`MULTI_EDGE`&&Q(`BreakingPointInserter`,r,t,()=>fc(t)),Q(`LongEdgeSplitter`,r,t,()=>ce(t)),Q(`PortSideProcessor`,r,t,()=>qi(t));let f=t.getProperty(e.B);(f===`POLYLINE`||f===`SPLINES`||f===`ORTHOGONAL`&&(t.getProperty(e.Gn).has(`NON_FREE_PORTS`)||t.getProperty(e.G)||t.getProperty(e.Gn).has(`HYPEREDGES`)))&&Q(`InvertedPortProcessor`,r,t,()=>xu(t)),l&&Q(`DummySelfLoopProcessor`,r,t,()=>pu(t)),Q(`PortListSorter`,r,t,()=>Bc(t)),t.getProperty(e.Gn).has(`EXTERNAL_PORTS`)&&Q(`HierarchicalPortConstraintProcessor`,r,t,()=>new cl().process(t)),t.getProperty(e.M)&&Q(`SemiInteractiveCrossMinProcessor`,r,t,()=>Hd(t)),t.getProperty(e.O)!==`NONE`&&Q(`SortByInputModel`,r,t,()=>Rd(t)),t.getProperty(e.Gn).has(`NON_FREE_PORTS`)&&t.getProperty(e.Gn).has(`NORTH_SOUTH_PORTS`)&&Q(`NorthSouthPortPreprocessor`,r,t,()=>Gc(t));let p=t.getProperty(e.N),m=t.getProperty(e.Kn);p===`INTERACTIVE`?(Q(`InteractiveCrossingMinimizer`,r,t,()=>new Wt().process(t)),r?.afterPhase?.(`P3`,t)):p===`MEDIAN_LAYER_SWEEP`?(Q(`LayerSweepCrossingMinimizer`,r,t,()=>new Ut(3).process(t,n)),r?.afterPhase?.(`P3`,t)):p!==`NONE`&&(Q(`LayerSweepCrossingMinimizer`,r,t,()=>new Ut(0).process(t,n)),r?.afterPhase?.(`P3`,t)),t.getProperty(e.wn)===`MULTI_EDGE`&&Q(`BreakingPointProcessor`,r,t,()=>yc(t)),m&&(Q(`GreedySwitchHeuristic`,r,t,()=>new Ut(2).process(t,n)),r?.afterPhase?.(`GreedySwitch`,t)),t.setProperty(e.wr,new un(t)),l&&Q(`SelfLoopPortRestorer`,r,t,()=>new Rl().process(t)),Q(`InLayerConstraintProcessor`,r,t,()=>Ol(t)),Q(`LabelAndNodeSizeProcessor`,r,t,()=>Ks(t)),Q(`NodeMarginCalculator`,r,t,()=>na(t)),t.getProperty(e.Gn).has(`COMMENTS`)&&Q(`CommentNodeMarginCalculator`,r,t,()=>Eu(t)),t.getProperty(e.Gn).has(`END_LABELS`)&&Q(`EndLabelPreprocessor`,r,t,()=>Xu(t)),t.getProperty(e.Gn).has(`CENTER_LABELS`)&&Q(`LabelDummySwitcher`,r,t,()=>be(t)),(t.getProperty(e.Gn).has(`END_LABELS`)||t.getProperty(e.Gn).has(`CENTER_LABELS`))&&Q(`LabelSideSelector`,r,t,()=>ud(t)),t.getProperty(e.Gn).has(`HYPEREDGES`)&&t.getProperty(e.B)!==`SPLINES`&&Q(`HyperedgeDummyMerger`,r,t,()=>new C().process(t)),Q(`HierarchicalPortDummySizeProcessor`,r,t,()=>al(t)),l&&Q(`SelfLoopRouter`,r,t,()=>du(t)),t.getProperty(e.pt)===`ALTERNATING`&&Q(`AlternatingLayerUnzipper`,r,t,()=>nf(t));let g=t.getProperty(e.wt);g===`SIMPLE`?Q(`SimpleNodePlacer`,r,t,()=>on(t)):g===`INTERACTIVE`?Q(`InteractiveNodePlacer`,r,t,()=>sn(t)):g===`NETWORK_SIMPLEX`?Q(`NetworkSimplexPlacer`,r,t,()=>new bn().process(t)):g===`LINEAR_SEGMENTS`?Q(`LinearSegmentsNodePlacer`,r,t,()=>Zo(t)):(g!==`BRANDES_KOEPF`&&Mf(`nodePlacement.strategy`,String(g),`BRANDES_KOEPF`),Q(`BKNodePlacer`,r,t,()=>new an().process(t))),r?.afterPhase?.(`BK`,t),t.getLayerlessNodes().length>0&&t.hasProperty(e.Ct)&&Q(`NodePlacementRepeater`,r,t,()=>Zs(t)),Q(`LayerSizeAndGraphHeightCalculator`,r,t,()=>new xn().process(t)),t.getProperty(e.Gn).has(`EXTERNAL_PORTS`)&&Q(`HierarchicalPortPositionProcessor`,r,t,()=>ll(t));let v=t.getProperty(e.B);v===`POLYLINE`?Q(`PolylineEdgeRouter`,r,t,()=>new Fr().process(t)):v===`SPLINES`?Q(`SplineEdgeRouter`,r,t,()=>new gi().process(t)):(v!==`ORTHOGONAL`&&v!=null&&Mf(`edgeRouting`,String(v),`ORTHOGONAL`),Q(`OrthogonalEdgeRouter`,r,t,()=>new rr().process(t))),r?.afterPhase?.(`P5`,t),(t.getProperty(e.et)||t.getProperty(e.K))&&Q(`ConstraintsPostprocessor`,r,t,()=>ss(t)),t.getProperty(e.Gn).has(`HYPERNODES`)&&Q(`HypernodesProcessor`,r,t,()=>cs(t)),Q(`LongEdgeJoiner`,r,t,()=>He(t)),l&&Q(`SelfLoopPostprocessor`,r,t,()=>kl(t)),t.getProperty(e.wn)===`MULTI_EDGE`&&Q(`BreakingPointRemover`,r,t,()=>Oc(t)),t.getProperty(e.Gn).has(`NON_FREE_PORTS`)&&t.getProperty(e.Gn).has(`NORTH_SOUTH_PORTS`)&&Q(`NorthSouthPortPostprocessor`,r,t,()=>_u(t)),t.getProperty(e.v)!==`NONE`&&t.getProperty(e.B)!==`POLYLINE`&&Q(`HorizontalGraphCompactor`,r,t,()=>new Mr().process(t)),Q(`LabelDummyRemover`,r,t,()=>We(t)),v===`SPLINES`&&Q(`FinalSplineBendpointsCalculator`,r,t,()=>bi(t)),t.getProperty(e.Gn).has(`COMMENTS`)&&Q(`CommentPostprocessor`,r,t,()=>ku(t)),Q(`EndLabelSorter`,r,t,()=>wd(t)),Q(`ReversedEdgeRestorer`,r,t,()=>jc(t)),t.getProperty(e.Gn).has(`END_LABELS`)&&Q(`EndLabelPostprocessor`,r,t,()=>Md(t)),Q(`GraphTransformer(out)`,r,t,()=>new qu(`TO_INTERNAL_LTR`).process(t));let y=t.getProperty(e.F);if(y!==`RIGHT`&&y!==`UNDEFINED`)for(let n of t.getLayers())for(let r of n.getNodes())ra(r),t.getProperty(e.Gn).has(`COMMENTS`)&&Du(r);if(i){let e=t.getOffset(),n=t.getPadding(),r=e.x+n.left,i=e.y+n.top,a=/* @__PURE__ */ new Set;for(let e of t.getAllNodes())if(e.getType()!==`EXTERNAL_PORT`){e.position.x+=r,e.position.y+=i;for(let t of e.getPorts())for(let e of t.getConnectedEdges())if(!a.has(e)){a.add(e);for(let t of e.getBendPoints())t.x+=r,t.y+=i}}}r?.afterPhase?.(`done`,t)}const Pf=!0;function Ff(t){for(let n of hf(t))for(let t of n.getLayerlessNodes()){let r=t.getNestedGraph();if(r===null)continue;let i=t.getProperty(e.Tt);if(!i||i.length===0)continue;let a=t.getProperty(e.Lt);if(!e.Lr.isSideFixed(a)){let r=n.getProperty(e.F)===`UNDEFINED`?`RIGHT`:n.getProperty(e.F);for(let e of t.getPorts())e.getSide()===`UNDEFINED`&&Yi(e,!1,r)}let o=Ns(t,n,!0)??{x:t.size.x,y:t.size.y},s=r.getProperty(e.Et)??{x:0,y:0},c=t.getProperty(e.Et)??{x:0,y:0},l={x:Math.max(s.x,c.x),y:Math.max(s.y,c.y)};r.setProperty(e.Et,{x:Math.max(l.x,o.x),y:Math.max(l.y,o.y)});let u=r.getProperty(e.Tt);u.includes(`MINIMUM_SIZE`)||r.setProperty(e.Tt,[...u,`MINIMUM_SIZE`])}}function If(e){let t=e.getParentNode();return t!==null&&t.getProperty(`org.eclipse.elk.algorithm`)===`fixed`}function Lf(e){let t=/* @__PURE__ */ new Set,n=e=>{let r=e.getProperty(`org.eclipse.elk.algorithm`);if(r&&t.has(r))throw Error(`Layout algorithm '${r}' not found`);let i=e.getNestedGraph();if(i!==null)for(let e of i.getLayerlessNodes())n(e)};for(let t of e.getLayerlessNodes())n(t)}var Rf=class{hooks;setHooks(e){this.hooks=e}layout(t,n){let r=n??new mf;Lf(t),ff(t),pf(t),Cf(t),Of(t),Ff(t),Su(t)&&t.getProperty(e.Gn).add(`COMMENTS`),t.getLayerlessNodes().filter(e=>e.getNestedGraph()!==null).length>0?kf(t,r,this.hooks):Af(t,r,this.hooks),Bf(t),zf(t)}};function zf(t){for(let n of t.getAllNodes()){n.getNestedGraph()!==null&&zf(n.getNestedGraph());let t=n.hasProperty(e.Tt)?n.getProperty(e.Tt):n.getGraph()?.getProperty(e.Tt)??[];if(!t.includes(`NODE_LABELS`)||t.includes(`PORTS`)||t.includes(`PORT_LABELS`)||t.includes(`MINIMUM_SIZE`)||n.getNestedGraph()!==null)continue;let r=n.getLabels();if(r.length===0)continue;let i=0,a=0;for(let e of r)i=Math.max(i,e.size.x),a=Math.max(a,e.size.y);if(i>0||a>0||n.size.x===0&&n.size.y===0)continue;let o={x:n.size.x,y:n.size.y};n.size.x=0,n.size.y=0,n.position.x+=o.x/2,n.position.y+=o.y/2;for(let e of r)e.position.x=0,e.position.y=0}}function Bf(t){for(let n of t.getAllNodes()){n.getNestedGraph()!==null&&Bf(n.getNestedGraph());let t=n.hasProperty(e.gt)?n.getProperty(e.gt):n.getGraph()?.getProperty(e.gt)??{left:0,right:0,top:0,bottom:0},r=t.left??0,i=t.right??0,a=ta(n);for(let t of n.getLabels()){let o=t.placement??n.getProperty(e._t)??``,s=Array.isArray(o)?o:String(o).split(/[\s,]+/).filter(Boolean);if(s.includes(`OUTSIDE`)){let e=s.includes(`H_PRIORITY`),r=s.includes(`H_LEFT`)||s.includes(`H_RIGHT`);e&&r||!e&&s.includes(`V_CENTER`)&&r?(s.includes(`H_RIGHT`)?t.position.x=n.size.x+a:t.position.x=-t.size.x-a,s.includes(`V_BOTTOM`)?t.position.y=n.size.y-t.size.y:s.includes(`V_CENTER`)?t.position.y=(n.size.y-t.size.y)/2:t.position.y=0):(s.includes(`V_BOTTOM`)?t.position.y=n.size.y+a:t.position.y=-t.size.y-a,s.includes(`H_RIGHT`)?t.position.x=n.size.x-t.size.x:s.includes(`H_LEFT`)?t.position.x=0:t.position.x=(n.size.x-t.size.x)/2)}else s.includes(`H_LEFT`)?t.position.x=r:s.includes(`H_RIGHT`)?t.position.x=n.size.x-t.size.x-i:t.position.x=r+(n.size.x-r-i-t.size.x)/2}}}function Vf(e,t,n){switch(n){case`WEST`:e.x=0,e.y=t.y/2;break;case`EAST`:e.x=t.x,e.y=t.y/2;break;case`NORTH`:e.x=t.x/2,e.y=0;break;case`SOUTH`:e.x=t.x/2,e.y=t.y;break;default:e.x=t.x/2,e.y=t.y/2}}function Hf(t,n,r){let i=n===`INPUT`?e.Yn:e.hr;for(let e of t.getPorts())if(e.getProperty(i)===!0)return e;let a=new p;return a.setProperty(i,!0),a.setNode(t),a.setSide(r),Vf(a.getPosition(),t.getSize(),r),a}function Uf(e,t,n,r,i){if(r&&!i)return Hf(e,t,t===`OUTPUT`?n:Wf(n));let a=new p;return a.setNode(e),a.setSide(t===`OUTPUT`?n:Wf(n)),a}function Wf(e){switch(e){case`NORTH`:return`SOUTH`;case`SOUTH`:return`NORTH`;case`EAST`:return`WEST`;case`WEST`:return`EAST`;default:return`UNDEFINED`}}const Gf={direction:{ggn:`org.eclipse.elk.direction`,elkjs:`elk.direction`,type:`str`},position:{ggn:`org.eclipse.elk.position`,elkjs:`elk.position`,type:`str`},edgeRouting:{ggn:`org.eclipse.elk.edgeRouting`,elkjs:`elk.edgeRouting`,type:`str`},"spacing.nodeNode":{ggn:`org.eclipse.elk.spacing.nodeNode`,elkjs:`elk.spacing.nodeNode`,type:`num`},"spacing.edgeEdge":{ggn:`org.eclipse.elk.spacing.edgeEdge`,elkjs:`elk.spacing.edgeEdge`,type:`num`},"spacing.nodeSelfLoop":{ggn:`org.eclipse.elk.spacing.nodeSelfLoop`,elkjs:`elk.spacing.nodeSelfLoop`,type:`num`},"spacing.portPort":{ggn:`org.eclipse.elk.spacing.portPort`,elkjs:`elk.spacing.portPort`,type:`num`},"spacing.edgeNode":{ggn:`org.eclipse.elk.spacing.edgeNode`,elkjs:`elk.spacing.edgeNode`,type:`num`},"spacing.edgeLabel":{ggn:`org.eclipse.elk.spacing.edgeLabel`,elkjs:`elk.spacing.edgeLabel`,type:`num`},"spacing.labelLabel":{ggn:`org.eclipse.elk.spacing.labelLabel`,elkjs:`elk.spacing.labelLabel`,type:`num`},"spacing.labelNode":{ggn:`org.eclipse.elk.spacing.labelNode`,elkjs:`elk.spacing.labelNode`,type:`num`},"spacing.edgeEdgeBetweenLayers":{ggn:`org.eclipse.elk.layered.spacing.edgeEdgeBetweenLayers`,elkjs:`elk.layered.spacing.edgeEdgeBetweenLayers`,type:`num`},"spacing.nodeNodeBetweenLayers":{ggn:`org.eclipse.elk.layered.spacing.nodeNodeBetweenLayers`,elkjs:`elk.layered.spacing.nodeNodeBetweenLayers`,type:`num`},"spacing.edgeNodeBetweenLayers":{ggn:`org.eclipse.elk.layered.spacing.edgeNodeBetweenLayers`,elkjs:`elk.layered.spacing.edgeNodeBetweenLayers`,type:`num`},"crossingMinimization.strategy":{ggn:`org.eclipse.elk.layered.crossingMinimization.strategy`,elkjs:`elk.layered.crossingMinimization.strategy`,type:`str`},"crossingMinimization.greedySwitch.type":{ggn:`org.eclipse.elk.layered.crossingMinimization.greedySwitch.type`,elkjs:`elk.layered.crossingMinimization.greedySwitch.type`,type:`str`},"cycleBreaking.strategy":{ggn:`org.eclipse.elk.layered.cycleBreaking.strategy`,elkjs:`elk.layered.cycleBreaking.strategy`,type:`str`},"layering.strategy":{ggn:`org.eclipse.elk.layered.layering.strategy`,elkjs:`elk.layered.layering.strategy`,type:`str`},"nodePlacement.strategy":{ggn:`org.eclipse.elk.layered.nodePlacement.strategy`,elkjs:`elk.layered.nodePlacement.strategy`,type:`str`},"considerModelOrder.strategy":{ggn:`org.eclipse.elk.layered.considerModelOrder.strategy`,elkjs:`elk.layered.considerModelOrder.strategy`,type:`str`},mergeEdges:{ggn:`org.eclipse.elk.layered.mergeEdges`,elkjs:`elk.layered.mergeEdges`,type:`bool`},mergeHierarchyEdges:{ggn:`org.eclipse.elk.layered.mergeHierarchyEdges`,elkjs:`elk.layered.mergeHierarchyEdges`,type:`bool`},feedbackEdges:{ggn:`org.eclipse.elk.layered.feedbackEdges`,elkjs:`elk.layered.feedbackEdges`,type:`bool`},thoroughness:{ggn:`org.eclipse.elk.layered.thoroughness`,elkjs:`elk.layered.thoroughness`,type:`num`},randomSeed:{ggn:`org.eclipse.elk.randomSeed`,elkjs:`elk.randomSeed`,type:`num`},separateConnectedComponents:{ggn:`org.eclipse.elk.separateConnectedComponents`,elkjs:`elk.separateConnectedComponents`,type:`bool`},hierarchyHandling:{ggn:`org.eclipse.elk.hierarchyHandling`,elkjs:`elk.hierarchyHandling`,type:`str`},portConstraints:{ggn:`org.eclipse.elk.portConstraints`,elkjs:`elk.portConstraints`,type:`str`},"insideSelfLoops.activate":{ggn:`org.eclipse.elk.insideSelfLoops.activate`,elkjs:`elk.insideSelfLoops.activate`,type:`bool`},generatePositionAndLayerIds:{ggn:`org.eclipse.elk.layered.generatePositionAndLayerIds`,elkjs:`elk.layered.generatePositionAndLayerIds`,type:`bool`},"nodeLabels.placement":{ggn:`org.eclipse.elk.nodeLabels.placement`,elkjs:`elk.nodeLabels.placement`,type:`enumset`,values:[`H_LEFT`,`H_CENTER`,`H_RIGHT`,`V_TOP`,`V_CENTER`,`V_BOTTOM`,`INSIDE`,`OUTSIDE`,`H_PRIORITY`]},"portLabels.placement":{ggn:`org.eclipse.elk.portLabels.placement`,elkjs:`elk.portLabels.placement`,type:`enumset`,values:[`OUTSIDE`,`INSIDE`,`NEXT_TO_PORT_IF_POSSIBLE`,`ALWAYS_SAME_SIDE`,`ALWAYS_OTHER_SAME_SIDE`,`SPACE_EFFICIENT`]},allowNonFlowPortsToSwitchSides:{ggn:`org.eclipse.elk.layered.allowNonFlowPortsToSwitchSides`,elkjs:`elk.layered.allowNonFlowPortsToSwitchSides`,type:`bool`},directionCongruency:{ggn:`org.eclipse.elk.layered.directionCongruency`,elkjs:`elk.layered.directionCongruency`,type:`str`},portSortingStrategy:{ggn:`org.eclipse.elk.layered.portSortingStrategy`,elkjs:`elk.portSortingStrategy`,type:`str`},aspectRatio:{ggn:`org.eclipse.elk.aspectRatio`,elkjs:`elk.aspectRatio`,type:`num`},"edgeRouting.selfLoopDistribution":{ggn:`org.eclipse.elk.layered.edgeRouting.selfLoopDistribution`,elkjs:`elk.layered.edgeRouting.selfLoopDistribution`,type:`str`},"edgeRouting.selfLoopOrdering":{ggn:`org.eclipse.elk.layered.edgeRouting.selfLoopOrdering`,elkjs:`elk.layered.edgeRouting.selfLoopOrdering`,type:`str`},"nodePlacement.bk.fixedAlignment":{ggn:`org.eclipse.elk.layered.nodePlacement.bk.fixedAlignment`,elkjs:`elk.layered.nodePlacement.bk.fixedAlignment`,type:`str`},"nodePlacement.bk.edgeStraightening":{ggn:`org.eclipse.elk.layered.nodePlacement.bk.edgeStraightening`,elkjs:`elk.layered.nodePlacement.bk.edgeStraightening`,type:`str`},"layering.nodePromotion.strategy":{ggn:`org.eclipse.elk.layered.layering.nodePromotion.strategy`,elkjs:`elk.layered.layering.nodePromotion.strategy`,type:`str`},"considerModelOrder.portModelOrder":{ggn:`org.eclipse.elk.layered.considerModelOrder.portModelOrder`,elkjs:`elk.layered.considerModelOrder.portModelOrder`,type:`bool`},"edgeLabels.placement":{ggn:`org.eclipse.elk.edgeLabels.placement`,elkjs:`elk.edgeLabels.placement`,type:`str`},"spacing.labelPort":{ggn:`org.eclipse.elk.spacing.labelPortHorizontal`,elkjs:`elk.spacing.labelPortHorizontal`,type:`num`},"insideSelfLoops.yo":{ggn:`org.eclipse.elk.insideSelfLoops.yo`,elkjs:`elk.insideSelfLoops.yo`,type:`bool`},"nodeSize.constraints":{ggn:`org.eclipse.elk.nodeSize.constraints`,elkjs:`elk.nodeSize.constraints`,type:`enumset`,values:[`PORTS`,`PORT_LABELS`,`NODE_LABELS`,`MINIMUM_SIZE`]},"nodeSize.minimum":{ggn:`org.eclipse.elk.nodeSize.minimum`,elkjs:`elk.nodeSize.minimum`,type:`str`},"nodeSize.options":{ggn:`org.eclipse.elk.nodeSize.options`,elkjs:`elk.nodeSize.options`,type:`str`},"nodeLabels.padding":{ggn:`org.eclipse.elk.nodeLabels.padding`,elkjs:`elk.nodeLabels.padding`,type:`object`},"nodeLabels.spacing":{ggn:`org.eclipse.elk.nodeLabels.spacing`,elkjs:`elk.nodeLabels.spacing`,type:`num`},layerConstraint:{ggn:`org.eclipse.elk.layered.layering.layerConstraint`,elkjs:`elk.layered.layering.layerConstraint`,type:`str`},"layering.layerConstraint":{ggn:`org.eclipse.elk.layered.layering.layerConstraint`,elkjs:`elk.layered.layering.layerConstraint`,type:`str`},"layering.layerChoiceConstraint":{ggn:`org.eclipse.elk.layered.layering.layerChoiceConstraint`,elkjs:`elk.layered.layering.layerChoiceConstraint`,type:`num`},"crossingMinimization.positionChoiceConstraint":{ggn:`org.eclipse.elk.layered.crossingMinimization.positionChoiceConstraint`,elkjs:`elk.layered.crossingMinimization.positionChoiceConstraint`,type:`num`},"crossingMinimization.semiInteractive":{ggn:`org.eclipse.elk.layered.crossingMinimization.semiInteractive`,elkjs:`elk.layered.crossingMinimization.semiInteractive`,type:`bool`},algorithm:{ggn:`org.eclipse.elk.algorithm`,elkjs:`elk.algorithm`,type:`str`},"partitioning.partition":{ggn:`org.eclipse.elk.partitioning.partition`,elkjs:`elk.partitioning.partition`,type:`num`},"spacing.portNode":{ggn:`org.eclipse.elk.spacing.portNode`,elkjs:`elk.spacing.portNode`,type:`num`},"portAlignment.default":{ggn:`org.eclipse.elk.portAlignment.default`,elkjs:`elk.portAlignment.default`,type:`str`},"portAlignment.west":{ggn:`org.eclipse.elk.portAlignment.west`,elkjs:`elk.portAlignment.west`,type:`str`},"portAlignment.east":{ggn:`org.eclipse.elk.portAlignment.east`,elkjs:`elk.portAlignment.east`,type:`str`},"portAlignment.north":{ggn:`org.eclipse.elk.portAlignment.north`,elkjs:`elk.portAlignment.north`,type:`str`},"portAlignment.south":{ggn:`org.eclipse.elk.portAlignment.south`,elkjs:`elk.portAlignment.south`,type:`str`},commentBox:{ggn:`org.eclipse.elk.commentBox`,elkjs:`elk.commentBox`,type:`bool`},desiredPosition:{ggn:`org.eclipse.elk.desiredPosition`,elkjs:`elk.desiredPosition`,type:`str`},interactiveLayout:{ggn:`org.eclipse.elk.interactiveLayout`,elkjs:`elk.interactiveLayout`,type:`bool`},padding:{ggn:`org.eclipse.elk.padding`,elkjs:`elk.padding`,type:`object`},noLayout:{ggn:`org.eclipse.elk.noLayout`,elkjs:`elk.noLayout`,type:`bool`},expandNodes:{ggn:`org.eclipse.elk.expandNodes`,elkjs:`elk.expandNodes`,type:`bool`},debugMode:{ggn:`org.eclipse.elk.debugMode`,elkjs:`elk.debugMode`,type:`bool`},alignment:{ggn:`org.eclipse.elk.alignment`,elkjs:`elk.alignment`,type:`str`},contentAlignment:{ggn:`org.eclipse.elk.contentAlignment`,elkjs:`elk.contentAlignment`,type:`enumset`,values:[`V_TOP`,`V_CENTER`,`V_BOTTOM`,`H_LEFT`,`H_CENTER`,`H_RIGHT`]},"spacing.portsSurrounding":{ggn:`org.eclipse.elk.spacing.portsSurrounding`,elkjs:`elk.spacing.portsSurrounding`,type:`object`},"spacing.individual":{ggn:`org.eclipse.elk.spacing.individual`,elkjs:`elk.spacing.individual`,type:`str`},"spacing.commentComment":{ggn:`org.eclipse.elk.spacing.commentComment`,elkjs:`elk.spacing.commentComment`,type:`num`},"spacing.commentNode":{ggn:`org.eclipse.elk.spacing.commentNode`,elkjs:`elk.spacing.commentNode`,type:`num`},"spacing.componentComponent":{ggn:`org.eclipse.elk.spacing.componentComponent`,elkjs:`elk.spacing.componentComponent`,type:`num`},"portLabels.treatAsGroup":{ggn:`org.eclipse.elk.portLabels.treatAsGroup`,elkjs:`elk.portLabels.treatAsGroup`,type:`bool`},"partitioning.activate":{ggn:`org.eclipse.elk.partitioning.activate`,elkjs:`elk.partitioning.activate`,type:`bool`},fixedAlignment:{ggn:`org.eclipse.elk.layered.nodePlacement.bk.fixedAlignment`,elkjs:`elk.layered.nodePlacement.bk.fixedAlignment`,type:`str`},edgeStraightening:{ggn:`org.eclipse.elk.layered.nodePlacement.bk.edgeStraightening`,elkjs:`elk.layered.nodePlacement.bk.edgeStraightening`,type:`str`},mode:{ggn:`org.eclipse.elk.layered.edgeRouting.splines.mode`,elkjs:`elk.layered.edgeRouting.splines.mode`,type:`str`},"postCompaction.strategy":{ggn:`org.eclipse.elk.layered.compaction.postCompaction.strategy`,elkjs:`elk.layered.compaction.postCompaction.strategy`,type:`str`},"compaction.connectedComponents":{ggn:`org.eclipse.elk.layered.compaction.connectedComponents`,elkjs:`elk.layered.compaction.connectedComponents`,type:`bool`},"edgeLabels.sideSelection":{ggn:`org.eclipse.elk.layered.edgeLabels.sideSelection`,elkjs:`elk.layered.edgeLabels.sideSelection`,type:`str`},"edgeLabels.centerLabelPlacementStrategy":{ggn:`org.eclipse.elk.layered.edgeLabels.centerLabelPlacementStrategy`,elkjs:`elk.layered.edgeLabels.centerLabelPlacementStrategy`,type:`str`},"highDegreeNodes.threshold":{ggn:`org.eclipse.elk.layered.highDegreeNodes.threshold`,elkjs:`elk.layered.highDegreeNodes.threshold`,type:`num`},"highDegreeNodes.treatment":{ggn:`org.eclipse.elk.layered.highDegreeNodes.treatment`,elkjs:`elk.layered.highDegreeNodes.treatment`,type:`bool`},"highDegreeNodes.treeHeight":{ggn:`org.eclipse.elk.layered.highDegreeNodes.treeHeight`,elkjs:`elk.layered.highDegreeNodes.treeHeight`,type:`num`},"considerModelOrder.components":{ggn:`org.eclipse.elk.layered.considerModelOrder.components`,elkjs:`elk.layered.considerModelOrder.components`,type:`str`},"considerModelOrder.longEdgeStrategy":{ggn:`org.eclipse.elk.layered.considerModelOrder.longEdgeStrategy`,elkjs:`elk.layered.considerModelOrder.longEdgeStrategy`,type:`str`},"considerModelOrder.crossingCounterNodeInfluence":{ggn:`org.eclipse.elk.layered.considerModelOrder.crossingCounterNodeInfluence`,elkjs:`elk.layered.considerModelOrder.crossingCounterNodeInfluence`,type:`num`},"crossingMinimization.greedySwitchHierarchical.type":{ggn:`org.eclipse.elk.layered.crossingMinimization.greedySwitchHierarchical.type`,elkjs:`elk.layered.crossingMinimization.greedySwitchHierarchical.type`,type:`str`},"crossingMinimization.forceNodeModelOrder":{ggn:`org.eclipse.elk.layered.crossingMinimization.forceNodeModelOrder`,elkjs:`elk.layered.crossingMinimization.forceNodeModelOrder`,type:`bool`},nodeFlexibility:{ggn:`org.eclipse.elk.layered.nodePlacement.networkSimplex.nodeFlexibility`,elkjs:`elk.layered.nodePlacement.networkSimplex.nodeFlexibility`,type:`str`},"nodeFlexibility.default":{ggn:`org.eclipse.elk.layered.nodePlacement.networkSimplex.nodeFlexibility.default`,elkjs:`elk.layered.nodePlacement.networkSimplex.nodeFlexibility.default`,type:`str`},portPort:{ggn:`org.eclipse.elk.spacing.portPort`,elkjs:`elk.spacing.portPort`,type:`num`},nodeNode:{ggn:`org.eclipse.elk.spacing.nodeNode`,elkjs:`elk.spacing.nodeNode`,type:`num`},minimum:{ggn:`org.eclipse.elk.nodeSize.minimum`,elkjs:`elk.nodeSize.minimum`,type:`str`},"greedySwitch.type":{ggn:`org.eclipse.elk.layered.crossingMinimization.greedySwitch.type`,elkjs:`elk.layered.crossingMinimization.greedySwitch.type`,type:`str`},positionChoiceConstraint:{ggn:`org.eclipse.elk.layered.crossingMinimization.positionChoiceConstraint`,elkjs:`elk.layered.crossingMinimization.positionChoiceConstraint`,type:`num`},sideSelection:{ggn:`org.eclipse.elk.layered.edgeLabels.sideSelection`,elkjs:`elk.layered.edgeLabels.sideSelection`,type:`str`},"nodeSize.fixedGraphSize":{ggn:`org.eclipse.elk.nodeSize.fixedGraphSize`,elkjs:`elk.nodeSize.fixedGraphSize`,type:`bool`},"topdown.hierarchicalNodeWidth":{ggn:`org.eclipse.elk.topdown.hierarchicalNodeWidth`,elkjs:`elk.topdown.hierarchicalNodeWidth`,type:`num`},"topdown.hierarchicalNodeAspectRatio":{ggn:`org.eclipse.elk.topdown.hierarchicalNodeAspectRatio`,elkjs:`elk.topdown.hierarchicalNodeAspectRatio`,type:`num`},"topdownpacking.nodeArrangement.strategy":{ggn:`org.eclipse.elk.topdownpacking.nodeArrangement.strategy`,elkjs:`elk.topdownpacking.nodeArrangement.strategy`,type:`str`},"topdownpacking.whitespaceElimination.strategy":{ggn:`org.eclipse.elk.topdownpacking.whitespaceElimination.strategy`,elkjs:`elk.topdownpacking.whitespaceElimination.strategy`,type:`str`},"vertiflex.verticalConstraint":{ggn:`org.eclipse.elk.vertiflex.verticalConstraint`,elkjs:`elk.vertiflex.verticalConstraint`,type:`num`},"vertiflex.layoutStrategy":{ggn:`org.eclipse.elk.vertiflex.layoutStrategy`,elkjs:`elk.vertiflex.layoutStrategy`,type:`str`},"vertiflex.layerDistance":{ggn:`org.eclipse.elk.vertiflex.layerDistance`,elkjs:`elk.vertiflex.layerDistance`,type:`num`},"vertiflex.considerNodeModelOrder":{ggn:`org.eclipse.elk.vertiflex.considerNodeModelOrder`,elkjs:`elk.vertiflex.considerNodeModelOrder`,type:`bool`},"overlapRemoval.maxIterations":{ggn:`org.eclipse.elk.overlapRemoval.maxIterations`,elkjs:`elk.overlapRemoval.maxIterations`,type:`num`},"overlapRemoval.runScanline":{ggn:`org.eclipse.elk.overlapRemoval.runScanline`,elkjs:`elk.overlapRemoval.runScanline`,type:`bool`},"processingOrder.treeConstruction":{ggn:`org.eclipse.elk.processingOrder.treeConstruction`,elkjs:`elk.processingOrder.treeConstruction`,type:`str`},"processingOrder.spanningTreeCostFunction":{ggn:`org.eclipse.elk.processingOrder.spanningTreeCostFunction`,elkjs:`elk.processingOrder.spanningTreeCostFunction`,type:`str`},"processingOrder.rootSelection":{ggn:`org.eclipse.elk.processingOrder.rootSelection`,elkjs:`elk.processingOrder.rootSelection`,type:`str`},"processingOrder.preferredRoot":{ggn:`org.eclipse.elk.processingOrder.preferredRoot`,elkjs:`elk.processingOrder.preferredRoot`,type:`str`},"compaction.compactionStrategy":{ggn:`org.eclipse.elk.compaction.compactionStrategy`,elkjs:`elk.compaction.compactionStrategy`,type:`str`},"compaction.orthogonal":{ggn:`org.eclipse.elk.compaction.orthogonal`,elkjs:`elk.compaction.orthogonal`,type:`bool`},"structure.structureExtractionStrategy":{ggn:`org.eclipse.elk.structure.structureExtractionStrategy`,elkjs:`elk.structure.structureExtractionStrategy`,type:`str`},underlyingLayoutAlgorithm:{ggn:`org.eclipse.elk.underlyingLayoutAlgorithm`,elkjs:`elk.underlyingLayoutAlgorithm`,type:`str`},interactiveReferencePoint:{ggn:`org.eclipse.elk.layered.interactiveReferencePoint`,elkjs:`elk.layered.interactiveReferencePoint`,type:`str`},considerModelOrder:{ggn:`org.eclipse.elk.layered.considerModelOrder.strategy`,elkjs:`elk.layered.considerModelOrder.strategy`,type:`str`},portAlignment:{ggn:`org.eclipse.elk.portAlignment.default`,elkjs:`elk.portAlignment.default`,type:`str`}};function Kf(e){return e.replace(/\\(['"\\])/g,(e,t)=>t)}function qf(e,t){let n=t.trim();if((n.startsWith(`"`)&&n.endsWith(`"`)||n.startsWith(`'`)&&n.endsWith(`'`))&&(n=n.slice(1,-1)),e.type===`num`){let e=Number(n);return Number.isFinite(e)?e:void 0}if(e.type===`bool`)return n.toLowerCase()===`true`;if(e.type===`enumset`){let t=n.match(/^\[([^\]]*)\]$/),r=(t?t[1]:n).split(/[\s,]+/).map(e=>e.trim()).filter(Boolean);if(e.values){for(let t of r)if(!e.values.includes(t))return}return r}if(e.type===`object`){let e=n.match(/^\[([^\]]*)\]$/);if(e){let t={};for(let n of e[1].split(/[,;]/)){let e=n.split(`=`);if(e.length===2){let n=Number(e[1].trim());if(!Number.isFinite(n))return;t[e[0].trim()]=n}}return t}let t=n.match(/^\(([\d.]+)\s*,\s*([\d.]+)\)$/);return t?{x:Number(t[1]),y:Number(t[2])}:void 0}return Kf(n)}function Jf(e,t){let n={},r=t instanceof Map?t.entries():Object.entries(t);for(let[t,i]of r){let r=e[t];if(r===void 0)continue;let a=[];for(let t of i){let n=e[t];n!==void 0&&a.push(n)}n[r]=a}return n}function Yf(t,n,r=null,i=null,a=`EAST`,o=!1,s=!1){let c=(t,n,r)=>{if(r&&t.getProperty(e.Lt)!==`FIXED_SIDE`)return Uf(t,n===`OUTPUT`?`OUTPUT`:`INPUT`,(n===`OUTPUT`?a:Xf[a]??`WEST`)??`EAST`,!0,!1);let i=new p;return i.setNode(t),i.setSide(n===`OUTPUT`?a:Xf[a]??`WEST`),i},l=r!==null&&r<t.getPorts().length?t.getPorts()[r]:c(t,`OUTPUT`,o),u=i!==null&&i<n.getPorts().length?n.getPorts()[i]:c(n,`INPUT`,s),d=new m;return d.setSource(l),d.setTarget(u),d}const Xf={NORTH:`SOUTH`,SOUTH:`NORTH`,EAST:`WEST`,WEST:`EAST`};function Zf(e,t){let n=e.split(`.`),r=t.split(`.`),i=0;for(;i<n.length&&i<r.length&&n[i]===r[i];)i++;return i===0?null:n.slice(0,i).join(`.`)}function Qf(e){return String(e).trim().toLowerCase().replace(/^org\.eclipse\.elk\./,``).replace(/^elk\./,``)}function $f(e,t,n,r){let i=n(e),a=n(t);if(i===null&&a===null)return;let o=Zf(e,t);if(o===null||!r(o)&&n(o)===null)throw Error(`UnsupportedGraphException: The source or the target of edge could not be found. This usually happens when an edge connects a node laid out by ELK Layered to a node in another level of hierarchy laid out by either another instance of ELK Layered or another layout algorithm alltogether. The former can be solved by setting the hierarchyHandling option to INCLUDE_CHILDREN.`)}function ep(e,t){for(let[n,r]of Object.entries(t)){let t=Gf[n];if(!t)continue;let i=typeof r==`object`&&r&&!Array.isArray(r)?r:qf(t,String(r));if(i!==void 0){if(t.ggn===`org.eclipse.elk.nodeSize.minimum`&&typeof i==`string`){let[e,t]=String(i).replace(/[()]/g,``).split(`,`).map(Number);i={x:e,y:t}}if(t.ggn===`org.eclipse.elk.padding`){let t=i;if(typeof t!=`object`||!t||t.top===void 0&&t.left===void 0&&t.right===void 0&&t.bottom===void 0)continue;e.setPadding({top:t.top??0,left:t.left??0,right:t.right??0,bottom:t.bottom??0})}else e.setProperty(t.ggn,i)}}}function tp(t,n=`graph`){let{nodes:r,edges:i,hierarchy:a,graphProps:o,nodeProps:s}=t,l=r.length,u=Object.create(null);for(let e=0;e<l;e++){let t=r[e];u[t]===void 0&&(u[t]=e)}let d=Jf(u,a),m=String(o.direction??`RIGHT`).toUpperCase(),h=new c,g=/* @__PURE__ */ new Map,_=/* @__PURE__ */ new Map,v=new Int32Array(l);v.fill(-1);for(let e of Object.keys(d)){let t=Number(e);_.set(t,new c);for(let e of d[t])v[e]===-1&&(v[e]=t)}for(let t=0;t<l;t++){let n=r[t],i=s.get(n)??{},o=v[t],c=new f(o===-1?h:_.get(o));c.size={x:i.width??60,y:i.height??30},i.x!==void 0&&(c.position.x=i.x),i.y!==void 0&&(c.position.y=i.y),i.portConstraints&&c.setProperty(e.Lt,i.portConstraints),(i[`insideSelfLoops.activate`]===`true`||i[`insideSelfLoops.activate`]===!0)&&c.setProperty(e.Q,!0);for(let[e,t]of Object.entries(i)){if(e.startsWith(`_`)||e===`ports`||e===`children`||e===`labels`||e===`width`||e===`height`||e===`portConstraints`||e===`insideSelfLoops.activate`)continue;let n=Gf[e];if(!n)continue;let r=typeof t==`object`&&t&&!Array.isArray(t)?t:qf(n,String(t));if(r!==void 0){if(n.ggn===`org.eclipse.elk.nodeSize.minimum`&&typeof r==`string`){let[e,t]=String(r).replace(/[()]/g,``).split(`,`).map(Number);r={x:e,y:t}}if(n.ggn===`org.eclipse.elk.position`&&typeof r==`string`){let[e,t]=String(r).replace(/[()]/g,``).split(`,`).map(Number);r={x:e,y:t}}c.setProperty(n.ggn,r)}}for(let t of i.ports??[]){let n=t.side??null,r=new p;r.setNode(c),r.getPosition().x=t.x??0,r.getPosition().y=t.y??0,r.size={x:t.w??8,y:t.h??8},t.borderOffset!==void 0&&t.borderOffset!==null&&r.setProperty(e.It,t.borderOffset),n&&r.setSide(n),t.index!==null&&t.index!==void 0&&r.setProperty(e.Rt,t.index),(t.labels??[]).length>0&&r.setLabels((t.labels??[]).map(e=>({text:e.text??``,position:{x:e.x??0,y:e.y??0},size:{x:e.width??0,y:e.height??0}})))}if((i.labels??[]).length>0&&c.setLabels((i.labels??[]).map(e=>({text:e.text??``,position:{x:e.x??0,y:e.y??0},size:{x:e.width??0,y:e.height??0},placement:e.placement??void 0}))),(a.get(n)??[]).length>0){let e=_.get(t);if(e){let t=typeof i.padding==`object`?i.padding:i.padding?qf(Gf.padding,String(i.padding)):null,n=t===null||!(e=>e!==null&&(e.top!==void 0||e.left!==void 0||e.right!==void 0||e.bottom!==void 0))(t)?{top:12,left:12,right:12,bottom:12}:{top:t.top??0,left:t.left??0,right:t.right??0,bottom:t.bottom??0},r=i[`nodeLabels.placement`],a=0,o=0,s=0,c=0;for(let e of i.labels??[]){let t=e.placement??r??``;if(!t)continue;let n=String(t).replace(/[\[\]]/g,``).split(/[\s,]+/).filter(Boolean);n.includes(`INSIDE`)&&(n.includes(`V_TOP`)?a=Math.max(a,e.height??0):n.includes(`V_BOTTOM`)?o=Math.max(o,e.height??0):(n.includes(`H_LEFT`)&&(s=Math.max(s,e.width??0)),n.includes(`H_RIGHT`)&&(c=Math.max(c,e.width??0))))}let l=i[`nodeLabels.padding`]??{top:5,right:5,bottom:5,left:5},u=Number(i[`spacing.labelLabel`]??0),d=typeof l==`object`?l.top??5:5,f=typeof l==`object`?l.bottom??5:5,p=typeof l==`object`?l.left??5:5,m=typeof l==`object`?l.right??5:5,h=(e,t)=>e>0?e+t+2*u:0;e.setPadding({top:n.top+h(a,d),bottom:n.bottom+h(o,f),left:n.left+h(s,p),right:n.right+h(c,m)})}}g.set(t,c)}for(let t of Object.keys(d).map(Number)){let n=g.get(t),i=_.get(t);n.setNestedGraph(i),i.setParentNode(n);let a=(s.get(r[t])??{}).mergeEdges;(a===!0||a===`true`)&&i.setProperty(e.mt,!0)}(o.mergeEdges===!0||o.mergeEdges===`true`)&&h.setProperty(e.mt,!0);let y=/* @__PURE__ */ new Map;for(let[e,t]of Object.entries(d)){let n=Number(e);for(let e of t)y.set(e,n)}let b=(e,t)=>{let n=/* @__PURE__ */ new Set,r=e;for(;r!==void 0;)n.add(r),r=y.get(r);let i=t;for(;i!==void 0&&!n.has(i);)i=y.get(i);if(i===void 0)return h;let a=y.get(i);return a===void 0?h:_.get(a)??h},x=e=>{let t=s.get(e);return t!==void 0&&t.algorithm!==void 0&&Qf(t.algorithm)!==`layered`},S=e=>{let t=e.lastIndexOf(`.`);for(;t!==-1;){let n=e.slice(0,t);if(x(n))return n;t=n.lastIndexOf(`.`)}return null};for(let[t,n,r,a,o,c,l]of i){$f(t,r,S,x);let i=u[t],d=u[r];if(i===void 0||d===void 0)continue;let f=n===null?-1:(s.get(t)?.ports??[]).findIndex(e=>e.id===n),p=a===null?-1:(s.get(r)?.ports??[]).findIndex(e=>e.id===a),h={RIGHT:`EAST`,LEFT:`WEST`,DOWN:`SOUTH`,UP:`NORTH`}[m]??`EAST`,_=(f<0||f>=g.get(i).getPorts().length)&&b(i,d).getProperty(e.mt)===!0,v=(p<0||p>=g.get(d).getPorts().length)&&g.get(d).getGraph()?.getProperty(e.mt)===!0,y=Yf(g.get(i),g.get(d),f>=0?f:null,p>=0?p:null,h,_,v);if(o===!0&&y.setProperty(e.$,!0),l!=null&&y.setProperty(e.W,l),c!=null&&c.length>0)for(let e of c)y.getLabels().push({text:e.text??``,position:{x:0,y:0},size:{x:e.width??0,y:e.height??0},placement:e.placement??void 0})}return Object.keys(d).length>0&&h.setProperty(e.q,`INCLUDE_CHILDREN`),h.setProperty(e.F,m),ep(h,o),h.hasProperty(e.Kt)||h.setProperty(e.Kt,1),{graph:h,nodeOf:g,nodeCount:l,edgeCount:i.length,hasHierarchy:Object.keys(d).length>0,name:n}}function np(e={}){let t={};for(let[n,r]of Object.entries(e)){let e=null;for(let[t,r]of Object.entries(Gf))if(r.ggn===n||r.elkjs===n){e=t;break}t[e??n.replace(/^org\.eclipse\.elk\./,``).replace(/^layered\./,``)]=r}return t}function rp(e,t={}){let n=t.stripNPrefix!==!1,r=t.blackBoxIds instanceof Set?t.blackBoxIds:/* @__PURE__ */ new Set,i=[],a=/* @__PURE__ */ new Set;for(let e of r)a.add(n?String(e).replace(/^N/,``):String(e));let o=/* @__PURE__ */ new Map;if(a.size>0){let t=(e,r)=>{let i=n?String(e.id).replace(/^N/,``):String(e.id),s=a.has(i)?i:r;for(let r of e.children??[]){let e=n?String(r.id).replace(/^N/,``):String(r.id);s!==null&&o.set(e,s),t(r,s)}};t(e,null)}let s=[],c=/* @__PURE__ */ new Map,l={},u=/* @__PURE__ */ new Map,d=/* @__PURE__ */ new Set,f=(e,t)=>{let a=n?e.id.replace(/^N/,``):e.id;if(d.has(a)||(d.add(a),i.push(a)),t!=null){let e=c.get(t)??[];e.includes(a)||e.push(a),c.set(t,e)}let o={width:e.width??60,height:e.height??30,x:e.x,y:e.y},s=(n?`N`+a:a)+`.`,l=e.ports??[];o.ports=l.map(e=>{let t=np(e.properties??{}),n={id:e.id&&e.id.startsWith(s)?e.id.slice(s.length):e.id,w:0,h:0};e.x!==void 0&&(n.x=e.x),e.y!==void 0&&(n.y=e.y),n.w=e.width??0,n.h=e.height??0,t[`port.side`]!==void 0&&(n.side=t[`port.side`]===`UNDEFINED`?null:t[`port.side`]),t[`port.index`]!==void 0&&(n.index=Number(t[`port.index`])),t[`port.borderOffset`]!==void 0&&(n.borderOffset=Number(t[`port.borderOffset`]));let r=e.labels??[];return r.length>0&&(n.labels=r.map(e=>{let t={text:e.text??``,width:e.width??0,height:e.height??0};return e.x!==void 0&&(t.x=e.x,t.y=e.y),t})),n}),l.length===0&&delete o.ports;let p=e.labels??[];if(o.labels=p.map(e=>{let t=np(e.layoutOptions??{}),n={text:e.text??``,width:e.width??0,height:e.height??0};return e.x!==void 0&&(n.x=e.x),e.y!==void 0&&(n.y=e.y),t[`nodeLabels.placement`]!==void 0&&(n.placement=t[`nodeLabels.placement`]),n}),p.length===0&&delete o.labels,Object.assign(o,np(e.layoutOptions??{})),u.set(a,o),!(r.has(e.id)||r.has(a)))for(let t of e.children??[])f(t,a)};for(let t of e.children??[])f(t,null);Object.assign(l,np(e.layoutOptions??{}));let p=e=>{let t=n?String(e??``).replace(/^N/,``):String(e??``);if(d.has(t))return[t,null];let r=t.lastIndexOf(`.`);return r!==-1&&d.has(t.slice(0,r))?[t.slice(0,r),t.slice(r+1)]:[t,null]},m=e=>{if(!(r.has(e.id)||r.has(n?String(e.id).replace(/^N/,``):e.id))){for(let t of e.edges??[]){if(a.size>0){let e=t.sources?.[0]??t.source,r=t.targets?.[0]??t.target;if(e!==void 0&&r!==void 0){let t=e=>n?String(e).replace(/^N/,``):String(e);$f(t(e),t(r),e=>{if(o.has(e))return o.get(e);let t=e.lastIndexOf(`.`);return t!==-1&&o.has(e.slice(0,t))?o.get(e.slice(0,t)):null},e=>a.has(e))}}let[e,r]=p(t.sources?.[0]??t.source),[i,c]=p(t.targets?.[0]??t.target),l=np(t.properties??{}),u=l[`insideSelfLoops.yo`]===`true`,d=l[`edge.thickness`]===void 0?null:Number(l[`edge.thickness`]),f=(t.labels??[]).map(e=>{let t=np(e.layoutOptions??{})[`edgeLabels.placement`]??e.placement??null;return{text:e.text??``,width:e.width??0,height:e.height??0,placement:t}});s.push([e,r,i,c,u,f,d])}for(let t of e.children??[])m(t)}};return m(e),{nodes:i,edges:s,hierarchy:c,graphProps:l,nodeProps:u}}let ip=/* @__PURE__ */ function(e){return e.INVALID_INPUT=`INVALID_INPUT`,e.MISSING_ID=`MISSING_ID`,e.DUPLICATE_ID=`DUPLICATE_ID`,e.NEGATIVE_SIZE=`NEGATIVE_SIZE`,e.NON_FINITE_SIZE=`NON_FINITE_SIZE`,e.EMPTY_ENDPOINTS=`EMPTY_ENDPOINTS`,e.DANGLING_ENDPOINT=`DANGLING_ENDPOINT`,e.MULTI_ENDPOINTS=`MULTI_ENDPOINTS`,e.UNSUPPORTED_ALGORITHM=`UNSUPPORTED_ALGORITHM`,e.CYCLIC_REFERENCE=`CYCLIC_REFERENCE`,e.INTERNAL_ERROR=`INTERNAL_ERROR`,e.ABORTED=`ABORTED`,e}({});var ap=class extends Error{code;path;retryable;phase;details;constructor(e,t,n,r={}){super(`${e} at ${t||`root`}: ${n}`,r.cause===void 0?void 0:{cause:r.cause}),this.name=`LayoutError`,this.code=e,this.path=t,this.retryable=!1,this.phase=r.phase,this.details=r.details,Object.setPrototypeOf(this,new.target.prototype)}toJSON(){let e={name:this.name,code:this.code,path:this.path,message:this.message,retryable:this.retryable};return this.phase!==void 0&&(e.phase=this.phase),this.details!==void 0&&(e.details=this.details),e}};function op(e){if(typeof e!=`object`||!e||Array.isArray(e))return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function sp(e,t){return e?`${e}.${t}`:t}function cp(e,t,n){return`${e?`${e}.`:``}${t}[${n}]`}function $(e,t,n,r){e.push({code:t,path:n,message:`${t} at ${n||`root`}: ${r}`,retryable:!1})}function lp(e,t,n){typeof e!=`number`||!Number.isFinite(e)?$(n,`NON_FINITE_SIZE`,t,`size must be a finite number`):e<0&&$(n,`NEGATIVE_SIZE`,t,`size must be greater than or equal to zero`)}function up(e,t,n){for(let r of[`width`,`height`])r in e&&lp(e[r],sp(t,r),n)}function dp(t,n,r,i){let a=t.layoutOptions;if(op(a))for(let t of[`org.eclipse.elk.algorithm`,`elk.algorithm`]){if(!(t in a))continue;let o=a[t];(typeof o!=`string`||o.trim()!==``)&&(e.d(o)||$(i,`UNSUPPORTED_ALGORITHM`,sp(n,`layoutOptions.${t}`),`algorithm ${JSON.stringify(o)} on node ${JSON.stringify(r??`root`)} is not supported`))}}function fp(e,t,n,r,i,a){if(!op(e)){$(n,a?`INVALID_INPUT`:`MISSING_ID`,t||`root`,a?`root input must be a plain object`:`child node must be a plain object with a non-empty string id`);return}if(i.has(e)){$(n,`CYCLIC_REFERENCE`,t||`root`,`object is referenced more than once in the input tree (cycle or shared reference)`);return}i.add(e);let o=e.id,s=typeof o==`string`&&o.trim().length>0;s?r.nodeIds.has(o)?$(n,`DUPLICATE_ID`,t||`root`,`node id ${JSON.stringify(o)} is duplicated`):r.nodeIds.add(o):$(n,a?`INVALID_INPUT`:`MISSING_ID`,a?`root`:t,a?`root input must have a non-empty string id`:`child node must have a non-empty string id`),up(e,t,n),dp(e,t,s?o:void 0,n);let c=s?o:void 0,l=e.ports;if(Array.isArray(l))for(let e=0;e<l.length;e+=1){let i=l[e],a=cp(t,`ports`,e);if(!op(i))continue;up(i,a,n);let o=i.id;c!==void 0&&typeof o==`string`&&o.trim().length>0&&(r.portRefs.add(`${c}.${o}`),r.portRefs.add(o))}let u=e.children;if(Array.isArray(u))for(let e=0;e<u.length;e+=1)fp(u[e],cp(t,`children`,e),n,r,i,!1)}function pp(e,t){if(t.nodeIds.has(e))return!0;let n=e.lastIndexOf(`.`);return n!==-1&&t.nodeIds.has(e.slice(0,n))}function mp(e,t,n,r){if(!op(e))return;let i=e.edges;if(!Array.isArray(i))return;for(let e=0;e<i.length;e+=1){let a=i[e],o=cp(t,`edges`,e);if(!op(a))$(n,`EMPTY_ENDPOINTS`,o,`edge must contain non-empty sources and targets arrays`);else for(let e of[`sources`,`targets`]){let t=a[e],i=sp(o,e);if(!Array.isArray(t)||t.length===0||t.some(e=>typeof e!=`string`)){$(n,`EMPTY_ENDPOINTS`,i,`${e} must be a non-empty string array`);continue}if(t.length>1){$(n,`MULTI_ENDPOINTS`,i,`${e} must contain exactly one endpoint (hyperedge not supported in P0)`);continue}let s=t[0];pp(s,r)||$(n,`DANGLING_ENDPOINT`,`${i}[0]`,`endpoint reference ${JSON.stringify(s)} does not resolve to a node or port`)}}let a=e.children;if(Array.isArray(a))for(let e=0;e<a.length;e+=1)mp(a[e],cp(t,`children`,e),n,r)}function hp(e){let t=[];if(!op(e))return $(t,`INVALID_INPUT`,`root`,`root input must be a plain object`),t;let n={nodeIds:/* @__PURE__ */ new Set,portRefs:/* @__PURE__ */ new Set};return fp(e,``,t,n,/* @__PURE__ */ new WeakSet,!0),mp(e,``,t,n),t}function gp(e){let t=hp(e),n=t[0];if(n!==void 0)throw new ap(n.code,n.path,n.message,{phase:`validate`,details:{issues:t}})}function _p(e,t){if(Array.isArray(e)){let n=[];t&&t.set(e,n);for(let r of e)n.push(_p(r,t));return n}if(typeof e==`object`&&e){let n=t?.get(e);if(n!==void 0)return n;let r={};t&&t.set(e,r);for(let[n,i]of Object.entries(e))Object.defineProperty(r,n,{value:_p(i,t),enumerable:!0,writable:!0,configurable:!0});return r}return e}function vp(e,t,n,r){if(e?.signal?.aborted)throw new ap(`ABORTED`,`root`,`布局在 ${t} 阶段被取消`,{phase:t});if(e?.onProgress?.({phase:t,completed:n,...r===void 0?{}:{graphId:r}}),e?.signal?.aborted)throw new ap(`ABORTED`,`root`,`布局在 ${t} 阶段回调后被取消`,{phase:t})}function yp(t,n,r){let i={...n?.layoutOptions??{},...t.layoutOptions??{}},a=rp(t,{stripNPrefix:!1,blackBoxIds:r});if(Object.assign(a.graphProps,np(n?.layoutOptions??{})),n?.direction&&(a.graphProps.direction=n.direction),n?.randomSeed!==void 0&&(a.graphProps.randomSeed=String(n.randomSeed)),n?.hierarchyHandling&&(a.graphProps.hierarchyHandling=n.hierarchyHandling),a.graphProps.direction===void 0&&(a.graphProps.direction=i[`org.eclipse.elk.direction`]??i[`elk.direction`]??`RIGHT`),a.graphProps.randomSeed===void 0&&(a.graphProps.randomSeed=`1`),a.graphProps.hierarchyHandling===void 0){let e=(t.children??[]).some(e=>(e.children?.length??0)>0);a.graphProps.hierarchyHandling=e?`INCLUDE_CHILDREN`:`OFF`}let o=tp(a,t.id),s=/* @__PURE__ */ new Map,c=/* @__PURE__ */ new Map;for(let[t,n]of o.nodeOf){let i=a.nodes[t];s.set(n,i),c.set(i,n),r?.has(i)&&n.setProperty(e.q,`SEPARATE_CHILDREN`)}let l=/* @__PURE__ */ new Map,u=/* @__PURE__ */ new Map;for(let[e,t]of o.nodeOf){let n=a.nodes[e],r=a.nodeProps.get(n)?.ports??[],i=t.getPorts();for(let e=0;e<r.length&&e<i.length;e++){let t=`${n}.${r[e].id}`;l.set(t,i[e]),u.set(i[e],t)}}let d=/* @__PURE__ */ new Map;d.set(o.graph,t.id);let f=e=>{for(let t of e.getAllNodes()){let e=t.getNestedGraph();if(e){let n=s.get(t);n!==void 0&&d.set(e,n),f(e)}}};f(o.graph);let p=/* @__PURE__ */ new Set,m=e=>{for(let t of e.getAllNodes()){for(let e of t.getPorts())for(let t of e.getOutgoingEdges())p.add(t);let e=t.getNestedGraph();e&&m(e)}};return m(o.graph),{graph:o.graph,nodeOf:c,portOf:l,nodeRef:s,portRef:u,edgeSet:p,graphToNodeId:d,root:t}}function bp(e){let t=e.getSource()?.getNode(),n=e.getTarget()?.getNode();if(!t||!n)return null;if(t===n)return t.getGraph()?.getParentNode()??null;let r=/* @__PURE__ */ new Set,i=t;for(;i;)r.add(i),i=i.getGraph()?.getParentNode()??null;for(i=n;i;){if(r.has(i))return i;i=i.getGraph()?.getParentNode()??null}return null}function xp(e,t){let n={...t.root};delete n.children,delete n.edges;let r=/* @__PURE__ */ new Map,i=/* @__PURE__ */ new Map,a=/* @__PURE__ */ new Map,o=/* @__PURE__ */ new Map,s=(e,t,n)=>JSON.stringify([e,t,n]),c=e=>{if(i.has(e))return e;let t=e.lastIndexOf(`.`),n=t===-1?e:e.slice(0,t);return i.has(n)?n:null},l=(e,t)=>{let r=c(String(e[0]??``)),i=c(String(t[0]??``));if(r===null||i===null||r===i)return r===null?n.id:a.get(r)??n.id;let o=/* @__PURE__ */ new Set,s=r;for(;s!==null;)o.add(s),s=a.get(s)??null;for(s=i;s!==null&&!o.has(s);)s=a.get(s)??null;return s??n.id},u=(e,t)=>{i.set(e.id,e),a.set(e.id,t);for(let t of e.children??[])u(t,e.id)},d=e=>{for(let t of e.edges??[]){let n={edge:t,consumed:!1},r=e=>{let r=s(e,String(t.sources?.[0]??``),String(t.targets?.[0]??``)),i=o.get(r)??[];i.includes(n)||i.push(n),o.set(r,i)};r(e.id);let i=l(t.sources??[],t.targets??[]);i!==e.id&&r(i)}for(let t of e.children??[])d(t)};u(t.root,null),d(t.root);let f=(e,t,n)=>{let r=o.get(s(e,String(t[0]??``),String(n[0]??``)));for(;r&&r.length>0;){let e=r.shift();if(!e.consumed)return e.consumed=!0,e.edge}};function p(e,n){let a=[];n.children=a;for(let n of e.getAllNodes()){let e=t.nodeRef.get(n);if(e===void 0)continue;let o=i.get(e),s=o?{...o,x:n.position.x,y:n.position.y,width:n.size.x,height:n.size.y}:{id:e,x:n.position.x,y:n.position.y,width:n.size.x,height:n.size.y};delete s.children,delete s.edges,r.set(s.id,s),a.push(s);let c=n.getNestedGraph();c&&p(c,s)}}p(e,n);let m=/* @__PURE__ */ new Set,h=/* @__PURE__ */ new Map;function g(e){for(let r of e.getAllNodes()){for(let e of r.getPorts())for(let r of e.getOutgoingEdges()){if(m.has(r)||!t.edgeSet.has(r))continue;m.add(r);let e=bp(r),i=h.get(e)??[];h.set(e,i);let{source:a,target:o}=Bi(r),s=[Sp(r.getSource(),t)],c=[Sp(r.getTarget(),t)],l=r.getBendPoints().map(e=>({x:e.x,y:e.y})),u={startPoint:a,endPoint:o};l.length>0&&(u.bendPoints=l);let d=e===null?n.id:t.nodeRef.get(e)??n.id,p=f(d,s,c);i.push(p?{...p,sources:s,targets:c,sections:[u],container:d}:{sources:s,targets:c,sections:[u],container:d})}let e=r.getNestedGraph();e&&g(e)}}g(e);let _=h.get(null);_&&_.length>0&&(n.edges=_);for(let[e,n]of h){if(e===null)continue;let i=t.nodeRef.get(e);if(i===void 0)continue;let a=r.get(i);a&&(a.edges=n)}return n}function Sp(e,t){return t.portRef.get(e)??(e.getNode()?t.nodeRef.get(e.getNode())??String(e.getNode().id):`?`)}function Cp(t,n,r=/* @__PURE__ */ new Map,i=!0){let a=n?.layoutOptions?.[`org.eclipse.elk.algorithm`]??n?.layoutOptions?.[`elk.algorithm`]??t.layoutOptions?.[`org.eclipse.elk.algorithm`]??t.layoutOptions?.[`elk.algorithm`];a!==void 0&&String(a).trim()!==``&&r.set(t.id,e.f(String(a)));for(let e of t.children??[])Cp(e,void 0,r,!1);return r}function wp(t,n,r){let i=/* @__PURE__ */ new Map,a=e=>{i.set(e.id,e);for(let t of e.children??[])a(t)};a(t);let o=/* @__PURE__ */ new Map,c=(e,t)=>{o.set(e.id,t);for(let n of e.children??[])c(n,t+1)};c(t,0);let l=[...n.entries()].filter(([,t])=>e.t.has(t)||e.r.has(t)||e.s.has(t)||e.l.has(t)||e.c.has(t)||e.o.has(t)||e.u.has(t)||e.n.has(t)||e.a.has(t)).sort((e,t)=>(o.get(t[0])??0)-(o.get(e[0])??0));for(let[e,t]of l){let n=i.get(e);if(n===void 0||(n.children?.length??0)===0)continue;let a=s(t);if(a===void 0)throw Error(`[layout] 布局算法 '${t}' 未注册 (本入口未包含该算法; 非 layered 算法请用完整入口 src/index.ts)`);a(n),r?.(n)===!0&&a(n)}}function Tp(e,t){if(t.size===0)return;let n=(e,t)=>e.id===t?e:(e.children??[]).map(e=>n(e,t)).find(Boolean)??null,r=[],i=e=>{for(let t of e.edges??[])r.push({e:t,holder:e});for(let t of e.children??[])i(t)};i(e);let a=/* @__PURE__ */ new Map;for(let r of t){let t=n(e,r);if(t===null)continue;let i=/* @__PURE__ */ new Set,o=e=>{i.add(e.id);for(let t of e.children??[])o(t)};o(t),a.set(r,i)}let o=[...a.entries()].sort((e,t)=>t[0].length-e[0].length),s=e=>{if(c.has(e))return e;let t=e.lastIndexOf(`.`);return t!==-1&&c.has(e.slice(0,t))?e.slice(0,t):null},c=/* @__PURE__ */ new Set;for(let e of a.values())for(let t of e)c.add(t);for(let{e:t,holder:i}of r){let r=String(t.sources?.[0]??``),a=String(t.targets?.[0]??``),c=s(r),l=s(a);if(c!==null&&l!==null)for(let[r,a]of o){if(!a.has(c)||!a.has(l))continue;let o=n(e,r);if(o!==null){o.edges??=[],o.edges.push(t);let e=(i.edges??[]).indexOf(t);e!==-1&&i.edges.splice(e,1)}break}}}function Ep(e,t){let n=e=>e.id===t?e:(e.children??[]).map(n).find(Boolean)??null;return(n(e)?.children?.length??0)>0}function Dp(t,n){let r=n?.control,i=typeof t?.id==`string`?t.id:void 0;vp(r,`validate`,1,i),gp(t),vp(r,`clone`,2,i);let a=_p(t);vp(r,`dispatch`,3,i);let o=Cp(a,n);for(let[t,n]of o)if(!e.t.has(n)&&!e.i.has(n)&&!e.r.has(n)&&!e.s.has(n)&&!e.l.has(n)&&!e.c.has(n)&&!e.o.has(n)&&!e.u.has(n)&&!e.n.has(n)&&!e.a.has(n))throw new ap(`UNSUPPORTED_ALGORITHM`,`nodes.${t}`,`布局算法 '${n}' 尚未移植 (节点 ${t}); 移植清单见 docs/NON-LAYERED-PORTING.md`,{phase:`dispatch`});let s=new Set([...o.entries()].filter(([,t])=>e.t.has(t)||e.r.has(t)||e.s.has(t)||e.l.has(t)||e.c.has(t)||e.o.has(t)||e.u.has(t)||e.n.has(t)||e.a.has(t)).map(([e])=>e).filter(e=>Ep(a,e)));s.size>0&&(Tp(a,s),wp(a,o,n?.onBlackBoxLaidOut));let c=o.get(a.id);if(c!==void 0&&!e.i.has(c)){let e=new Set([...s].filter(e=>e!==a.id));return e.size>0&&(Tp(a,e),wp(a,new Map([...o.entries()].filter(([e])=>e!==a.id)),n?.onBlackBoxLaidOut)),wp(a,/* @__PURE__ */ new Map([[a.id,c]]),n?.onBlackBoxLaidOut),Fp(a,Pp(a,n),a),Op(a),vp(r,`extract`,4,i),vp(r,`format`,5,i),kp(a,n)}let l=yp(a,n,s);new Rf().layout(l.graph),vp(r,`extract`,4,i);let u=xp(l.graph,l);return Op(u,l.graph),s.size>0&&Ip(u,a,s),Fp(u,Pp(a,n),a),vp(r,`format`,5,i),kp(u,n)}function Op(e,t){e.x??=0,e.y??=0,e.width===void 0&&(e.width=t?.getActualSize().x??0),e.height===void 0&&(e.height=t?.getActualSize().y??0)}function kp(e,t){let n=t?.responseFormat??`full`;return n===`summary`?Mp(e):n===`concise`?Ap(e):t?.pick===void 0?e:jp(e,t.pick)}function Ap(e){let t={id:e.id,x:e.x,y:e.y,width:e.width,height:e.height};return e.children!==void 0&&(t.children=e.children.map(Ap)),e.edges!==void 0&&(t.edges=e.edges.flatMap(e=>{let t=e.sections?.[0],n={...e.id===void 0?{}:{id:e.id},sources:[...e.sources],targets:[...e.targets]};return t!==void 0&&(n.sections=[{startPoint:{...t.startPoint},endPoint:{...t.endPoint}}]),[n]})),t}function jp(e,t){let n={id:e.id,x:e.x,y:e.y,width:e.width,height:e.height};for(let r of t)r in e&&r!==`children`&&r!==`edges`&&r!==`id`&&r!==`x`&&r!==`y`&&r!==`width`&&r!==`height`&&(n[r]=e[r]);return e.children!==void 0&&(n.children=e.children.map(e=>jp(e,t))),e.edges!==void 0&&(n.edges=e.edges),n}function Mp(e){let t=[],n=[],r=(e,i)=>{i&&t.push({id:e.id,x:e.x,y:e.y,width:e.width,height:e.height});for(let t of e.edges??[]){let e=t.sections?.[0],r=t.sources[0],i=t.targets[0];e!==void 0&&r!==void 0&&i!==void 0&&n.push({...t.id===void 0?{}:{id:t.id},sources:[r],targets:[i],startPoint:{...e.startPoint},endPoint:{...e.endPoint}})}for(let t of e.children??[])r(t,!0)};r(e,!1);let i={nodes:t,edges:n};return typeof e.width==`number`&&(i.width=e.width),typeof e.height==`number`&&(i.height=e.height),i}function Np(e){return e===`shapeCoords`||e.endsWith(`json.shapeCoords`)?`org.eclipse.elk.json.shapeCoords`:e===`edgeCoords`||e.endsWith(`json.edgeCoords`)?`org.eclipse.elk.json.edgeCoords`:e.startsWith(`org.eclipse.elk.`)?e:e.replace(/^elk\./,`org.eclipse.elk.`)}function Pp(e,t){let n=e=>{let t={};for(let[n,r]of Object.entries(e??{}))t[Np(n)]=r;return t},r=n(e.layoutOptions);for(let[e,i]of Object.entries(n(t?.layoutOptions)))r[e]=i;let i=e=>{let t=n(e)[`org.eclipse.elk.json.shapeCoords`];return t===`ROOT`||t===`PARENT`||t===`INHERIT`?t:void 0},a=e=>{let t=n(e)[`org.eclipse.elk.json.edgeCoords`];return t===`ROOT`||t===`PARENT`||t===`CONTAINER`||t===`INHERIT`?t:void 0},o=r[`org.eclipse.elk.json.shapeCoords`],s=r[`org.eclipse.elk.json.edgeCoords`],c=o===`ROOT`||o===`PARENT`?o:`PARENT`,l=s===`ROOT`||s===`PARENT`||s===`CONTAINER`?s:`CONTAINER`,u=/* @__PURE__ */ new Map,d=/* @__PURE__ */ new Map,f=(e,t,n,r)=>{let o=i(e.layoutOptions),s=a(e.layoutOptions),c=o===void 0||o===`INHERIT`?t:o,l=s===void 0||s===`INHERIT`?n:s;r||(u.set(e.id,c),d.set(e.id,l));for(let t of e.children??[])f(t,c,l,!1)};return f(e,c,l,!0),{rootShape:c,rootEdge:l,nodeShape:u,nodeEdge:d}}function Fp(e,t,n){let r=/* @__PURE__ */ new Map,i=(e,t,n)=>{let a=t+(e.x??0),o=n+(e.y??0);r.set(e.id,{x:a,y:o});for(let t of e.children??[])i(t,a,o)};i(e,0,0);let a=n=>n.id===e.id?t.rootShape:t.nodeShape.get(n.id)??`PARENT`,o=(t,n)=>{if(t.id!==e.id&&n===`ROOT`){let e=r.get(t.id);e&&(t.x=e.x,t.y=e.y)}let i=a(t);for(let e of t.children??[])o(e,i)};o(e,t.rootShape);let s=/* @__PURE__ */ new Map,c=(e,t)=>{for(let n of e.edges??[]){let e=`${String(n.sources?.[0]??``)}|${String(n.targets?.[0]??``)}`;s.has(e)||s.set(e,t)}for(let t of e.children??[])c(t,t.id)};c(n,null);let l=e=>{let n=s.get(e);return n===null?t.rootEdge:n===void 0?`CONTAINER`:t.nodeEdge.get(n)??`CONTAINER`},u=(e,t)=>{e&&(e.x+=t.x,e.y+=t.y)},d=t=>t.id===e.id?{x:0,y:0}:r.get(t.id)??{x:0,y:0},f=e=>{let t=d(e);for(let n of e.edges??[]){let e=`${String(n.sources?.[0]??``)}|${String(n.targets?.[0]??``)}`,i=l(e),a=null;if(i===`ROOT`)a=t;else if(i===`PARENT`){let n=s.get(e),i=n==null?{x:0,y:0}:r.get(n)??{x:0,y:0};a={x:t.x-i.x,y:t.y-i.y}}if(a!==null){for(let e of n.sections??[]){u(e.startPoint,a),u(e.endPoint,a);for(let t of e.bendPoints??[])u(t,a)}delete n.container}}for(let t of e.children??[])f(t)};f(e)}function Ip(e,t,n){let r=(e,t)=>{if(e.id===t)return e;for(let n of e.children??[]){let e=r(n,t);if(e!==null)return e}return null},i=e=>{if(n.has(e.id)){let n=r(t,e.id);if(n!==null){e.children=n.children,e.edges=n.edges;for(let t of e.edges??[])t.container=e.id;for(let t of e.children??[])i(t);return}}for(let t of e.children??[])i(t)};i(e)}Object.defineProperty(exports,"C",{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,"S",{enumerable:!0,get:function(){return d}}),Object.defineProperty(exports,"T",{enumerable:!0,get:function(){return i}}),Object.defineProperty(exports,"_",{enumerable:!0,get:function(){return w}}),Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return hp}}),Object.defineProperty(exports,"b",{enumerable:!0,get:function(){return f}}),Object.defineProperty(exports,"c",{enumerable:!0,get:function(){return Uf}}),Object.defineProperty(exports,"d",{enumerable:!0,get:function(){return mf}}),Object.defineProperty(exports,"f",{enumerable:!0,get:function(){return kf}}),Object.defineProperty(exports,"g",{enumerable:!0,get:function(){return Bi}}),Object.defineProperty(exports,"h",{enumerable:!0,get:function(){return xo}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return gp}}),Object.defineProperty(exports,"l",{enumerable:!0,get:function(){return Hf}}),Object.defineProperty(exports,"m",{enumerable:!0,get:function(){return yo}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return xp}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return ap}}),Object.defineProperty(exports,"p",{enumerable:!0,get:function(){return Af}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return Dp}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return ip}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return yp}}),Object.defineProperty(exports,"u",{enumerable:!0,get:function(){return Rf}}),Object.defineProperty(exports,"v",{enumerable:!0,get:function(){return m}}),Object.defineProperty(exports,"w",{enumerable:!0,get:function(){return o}}),Object.defineProperty(exports,"x",{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,"y",{enumerable:!0,get:function(){return p}});