@kern0x1b/penstock-cli 26.10.0 → 26.10.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 (135) hide show
  1. package/THIRD-PARTY-NOTICES.md +1647 -0
  2. package/dist/grammars/tree-sitter-c-sharp.wasm +0 -0
  3. package/dist/grammars/tree-sitter-go.wasm +0 -0
  4. package/dist/grammars/tree-sitter-groovy.wasm +0 -0
  5. package/dist/grammars/tree-sitter-java.wasm +0 -0
  6. package/dist/grammars/tree-sitter-javascript.wasm +0 -0
  7. package/dist/grammars/tree-sitter-kotlin.wasm +0 -0
  8. package/dist/grammars/tree-sitter-python.wasm +0 -0
  9. package/dist/grammars/tree-sitter-scala.wasm +0 -0
  10. package/dist/grammars/tree-sitter-typescript.wasm +0 -0
  11. package/dist/grammars/web-tree-sitter.wasm +0 -0
  12. package/dist/penstock.js +1077 -419
  13. package/dist/syntax-worker.js +5 -0
  14. package/dist/web/assets/AgentSettings-Iy9ZaTGR.js +1 -0
  15. package/dist/web/assets/AgentsDialog-Dt09_TEw.js +1 -0
  16. package/dist/web/assets/BpmnCanvas-CCRBnGIV.js +1905 -0
  17. package/dist/web/assets/BpmnDocument-D2lXXcnN.js +24 -0
  18. package/dist/web/assets/ConflictDialog-CaBNoJST.js +1 -0
  19. package/dist/web/assets/DiffDocument-BjLzoDLL.js +1 -0
  20. package/dist/web/assets/DmnDocument-BSGTyR3r.js +41 -0
  21. package/dist/web/assets/DmnDocument-DdjhA8he.css +1 -0
  22. package/dist/web/assets/FormDocument-BdCKvI-7.js +32 -0
  23. package/dist/web/assets/FormDocument-URLcKn84.css +1 -0
  24. package/dist/web/assets/FormStepView-BEDXMPef.js +1 -0
  25. package/dist/web/assets/GraphAwareLayoutService-CZCVRb9X.js +21 -0
  26. package/dist/web/assets/NewFileDialog-D9nTKDOT.js +34 -0
  27. package/dist/web/assets/QuickOpen-D3AkwBdF.js +1 -0
  28. package/dist/web/assets/ScriptPane-4TG-1RyI.js +2 -0
  29. package/dist/web/assets/ScriptRunDialog-C2n9cLcf.js +1 -0
  30. package/dist/web/assets/SettingsDialog-BUft2ulJ.js +1 -0
  31. package/dist/web/assets/ShortcutsDialog-Naoea994.js +1 -0
  32. package/dist/web/assets/SourceDocument-PMA1dm6T.js +1 -0
  33. package/dist/web/assets/TextDocument-D4fl42FV.js +1 -0
  34. package/dist/web/assets/UnreadableFileLayer-DuWtY1bx.js +1 -0
  35. package/dist/web/assets/UploadDialog-CEnwtJ3T.js +1 -0
  36. package/dist/web/assets/Viewer-CZiVl0t6.js +4 -0
  37. package/dist/web/assets/apply-DwO6xN9h.js +1 -0
  38. package/dist/web/assets/array-move-Bc4mVEdq.js +1 -0
  39. package/dist/web/assets/bpmn-0HrGCizt.svg +228 -0
  40. package/dist/web/assets/bpmn-Cyvp-fAH.eot +0 -0
  41. package/dist/web/assets/bpmnTheme-iB2hl29R.js +1687 -0
  42. package/dist/web/assets/bridgeInstance-CJkr34d9.js +600 -0
  43. package/dist/web/assets/clike-DaHM3zHz.js +1 -0
  44. package/dist/web/assets/colors-dark-C7vOziWz.css +1 -0
  45. package/dist/web/assets/colors-dracula-CXhMcc1Z.css +1 -0
  46. package/dist/web/assets/colors-light-CyT40N4M.css +1 -0
  47. package/dist/web/assets/commands-BMjdyegc.js +1 -0
  48. package/dist/web/assets/de-BDwOyJ4E.js +1 -0
  49. package/dist/web/assets/dialog-wo7dFa5A.js +1 -0
  50. package/dist/web/assets/diff-BmEImmS0.js +1 -0
  51. package/dist/web/assets/dist--PmHUHDp.js +1 -0
  52. package/dist/web/assets/dist-B163CX7G.js +57 -0
  53. package/dist/web/assets/dist-BBuLDp9u.js +2 -0
  54. package/dist/web/assets/dist-B_V0lTcO.js +1 -0
  55. package/dist/web/assets/dist-BaEGn3tp.js +6 -0
  56. package/dist/web/assets/dist-BqwyxNP3.js +1 -0
  57. package/dist/web/assets/dist-CAxViutc.js +5 -0
  58. package/dist/web/assets/dist-CBRIhX1e.js +1 -0
  59. package/dist/web/assets/dist-CHluRwHI.js +2 -0
  60. package/dist/web/assets/dist-COW2iVt-.js +1 -0
  61. package/dist/web/assets/dist-CRJyslwo.js +1 -0
  62. package/dist/web/assets/dist-CnDXCEJ_.js +23 -0
  63. package/dist/web/assets/dist-CsBP6QjA.js +13 -0
  64. package/dist/web/assets/dist-CxyFqsL2.js +6 -0
  65. package/dist/web/assets/dist-D6gjpLLN.js +1 -0
  66. package/dist/web/assets/dist-DUkRqvKl.js +1 -0
  67. package/dist/web/assets/dist-DgvQWhKm.js +6 -0
  68. package/dist/web/assets/dist-DvFyMwGd.js +1 -0
  69. package/dist/web/assets/dist-Gx7P7Pk_.js +1 -0
  70. package/dist/web/assets/dist-Km3QNqlU.js +2 -0
  71. package/dist/web/assets/dist-TNwbKIWT.js +1 -0
  72. package/dist/web/assets/dist-sl8LIbwu.js +1 -0
  73. package/dist/web/assets/dmn-2EwrEScy.eot +0 -0
  74. package/dist/web/assets/dmn-eH1_eUsy.svg +90 -0
  75. package/dist/web/assets/dockLayout-CxOMo-Nl.js +1 -0
  76. package/dist/web/assets/documentBridge-uW6vNrY3.js +240 -0
  77. package/dist/web/assets/documents-BwU2MdUd.js +1 -0
  78. package/dist/web/assets/duplicate-rWDlHiZr.js +342 -0
  79. package/dist/web/assets/ed25519-DTYhEcYX.js +1 -0
  80. package/dist/web/assets/engine-BPUfS3r2.js +1 -0
  81. package/dist/web/assets/engines-C3gTrVWJ.js +5 -0
  82. package/dist/web/assets/es-B4wrlqk9.js +1 -0
  83. package/dist/web/assets/files-Chpd_QD0.js +1 -0
  84. package/dist/web/assets/formChecks-DXIRZuhX.js +1 -0
  85. package/dist/web/assets/fr-BqtYruiB.js +1 -0
  86. package/dist/web/assets/frontend-By89859W.js +1 -0
  87. package/dist/web/assets/go-C1TRUqzB.js +1 -0
  88. package/dist/web/assets/groovy-DASguM_i.js +1 -0
  89. package/dist/web/assets/html2canvas-BNKOpkjM.js +5 -0
  90. package/dist/web/assets/httpHost-_QDw41Ka.js +1 -0
  91. package/dist/web/assets/index.es-CVOua_f9.js +4 -0
  92. package/dist/web/assets/index.es-DHW5-gbr.js +78 -0
  93. package/dist/web/assets/index.esm-CTLpq4ik.js +3 -0
  94. package/dist/web/assets/intelligence-BnJILPl7.js +3 -0
  95. package/dist/web/assets/ja-B6eG6Wld.js +1 -0
  96. package/dist/web/assets/jspdf.es.min-Yw43YJzU.js +79 -0
  97. package/dist/web/assets/ko-Le3hTKqP.js +1 -0
  98. package/dist/web/assets/lib-D6xZQFAF.js +1 -0
  99. package/dist/web/assets/libavoid-BRQRZjmQ.wasm +0 -0
  100. package/dist/web/assets/libavoid.wasm +0 -0
  101. package/dist/web/assets/platform-PXoldsjF.js +2 -0
  102. package/dist/web/assets/preferences-C7SSy7Wf.js +1 -0
  103. package/dist/web/assets/preload-helper-VRuDKI9K.js +1 -0
  104. package/dist/web/assets/properties-C3HzGRE2.js +1 -0
  105. package/dist/web/assets/pt-BR-aDlgSu84.js +1 -0
  106. package/dist/web/assets/purify.es-DBLk-NVl.js +3 -0
  107. package/dist/web/assets/python-CvnBFxgv.js +1 -0
  108. package/dist/web/assets/resource/ArchitectsDaughter-OFL.txt +93 -0
  109. package/dist/web/assets/resource/ArchitectsDaughter-Regular.ttf +0 -0
  110. package/dist/web/assets/resource/JetBrainsMono-Italic.woff2 +0 -0
  111. package/dist/web/assets/resource/JetBrainsMono-Medium.woff2 +0 -0
  112. package/dist/web/assets/resource/JetBrainsMono-OFL.txt +52 -0
  113. package/dist/web/assets/resource/JetBrainsMono-Regular.woff2 +0 -0
  114. package/dist/web/assets/resource/JetBrainsMono-SemiBold.woff2 +0 -0
  115. package/dist/web/assets/rolldown-runtime-B8BYMn-z.js +1 -0
  116. package/dist/web/assets/ru-DJl9EFpu.js +1 -0
  117. package/dist/web/assets/run-Dd_PjDF8.js +1 -0
  118. package/dist/web/assets/samples-DfOV2cQu.js +1 -0
  119. package/dist/web/assets/shortcut-DONH578b.js +1 -0
  120. package/dist/web/assets/source-frame-q4WXS_Md.js +2 -0
  121. package/dist/web/assets/stackblur-es-Djj-lnDR.js +2 -0
  122. package/dist/web/assets/syntax-DBcQvmbn.js +6 -0
  123. package/dist/web/assets/testCaseRuns-6x2pl8U_.js +1 -0
  124. package/dist/web/assets/translator-CTBxdhz9.js +1 -0
  125. package/dist/web/assets/typing-CXvbBSPr.js +1 -0
  126. package/dist/web/assets/ui-B2q39Bca.js +1 -0
  127. package/dist/web/assets/useTrace-BbcYW5PF.js +1 -0
  128. package/dist/web/assets/vendor-NJP34MHU.js +1 -0
  129. package/dist/web/assets/web-BTVzb1W6.css +1 -0
  130. package/dist/web/assets/web-D7xTiPek.js +148 -0
  131. package/dist/web/assets/zh-CaEk-YOk.js +1 -0
  132. package/dist/web/icon.svg +9 -0
  133. package/dist/web/index.html +64 -0
  134. package/dist/web/manifest.webmanifest +14 -0
  135. package/package.json +13 -8
@@ -0,0 +1,21 @@
1
+ import{i as c,t as u}from"./rolldown-runtime-B8BYMn-z.js";import{i as m}from"./translator-CTBxdhz9.js";import{A as h,C as g,D as v,E as y,O as S,S as w,T,_ as E,a as D,b as k,c as j,d as M,f as N,g as P,h as I,i as L,j as z,k as B,l as V,m as H,n as U,o as W,p as ee,r as G,s as K,t as Z,u as Q,v as te,w as ne,x as $,y as re}from"./BpmnDocument-D2lXXcnN.js";var Bt=c=>({avoidLib:void 0,async load(u=void 0){if(this.avoidLib)console.log(`Avoid library is already initialized`);else{let ce=function(c,m){return u!==void 0&&c.endsWith(`.wasm`)?u:m+c};this.avoidLib=await c({locateFile:ce})}},getInstance(){if(!this.avoidLib)throw Error(`Avoid library should be initialized before using`);return this.avoidLib}}),ae=Bt((()=>{var c=import.meta.url;return async function(u={}){var m,h=u,g,v,y=new Promise((c,u)=>{g=c,v=u}),S=`./this.program`,w=``,Ye;if(typeof document<`u`&&document.currentScript&&(w=document.currentScript.src),c&&(w=c),w=w.startsWith(`blob:`)?``:w.slice(0,w.replace(/[?#].*/,``).lastIndexOf(`/`)+1),typeof window!=`object`&&typeof WorkerGlobalScope>`u`)throw Error(`not compiled for this environment (did you build to HTML and try to run it not on the web, or set ENVIRONMENT to something - like node - and run it someplace else - like on the web?)`);Ye=async c=>{if(d(!Ze(c),`readAsync does not work with file:// URLs`),c=await fetch(c,{credentials:`same-origin`}),c.ok)return c.arrayBuffer();throw Error(c.status+` : `+c.url)};var T=console.log.bind(console),E=console.error.bind(console);d(!0,"worker environment detected but not enabled at build time. Add `worker` to `-sENVIRONMENT` to enable."),d(!0,"node environment detected but not enabled at build time. Add `node` to `-sENVIRONMENT` to enable."),d(!0,"shell environment detected but not enabled at build time. Add `shell` to `-sENVIRONMENT` to enable.");var D;typeof WebAssembly!=`object`&&E(`no native wasm support detected`);var k,j=!1,M;function d(c,u){c||A(`Assertion failed`+(u?`: `+u:``))}var N,P,I,L,z,B,V,H,U,W,ee=!1,G=!1,Ze=c=>c.startsWith(`file://`);function Ht(){var c=Ot();d(!(c&3)),c==0&&(c+=4),B[c>>2]=34821223,B[c+4>>2]=2310721022,B[0]=1668509029}function ie(){if(!j){var c=Ot();c==0&&(c+=4);var u=B[c>>2],m=B[c+4>>2];u==34821223&&m==2310721022||A(`Stack overflow! Stack cookie has been overwritten at ${J(c)}, expected hex dwords 0x89BACDFE and 0x2135467, but received ${J(m)} ${J(u)}`),B[0]!=1668509029&&A(`Runtime error: The application has corrupted its heap memory area (address zero)!`)}}var K=new Int16Array(1),Z=new Int8Array(K.buffer);if(K[0]=25459,Z[0]!==115||Z[1]!==99)throw`Runtime error: expected the system to be little-endian! (Run with -sSUPPORT_BIG_ENDIAN to bypass)`;function he(c){Object.getOwnPropertyDescriptor(h,c)||Object.defineProperty(h,c,{configurable:!0,set(){A(`Attempt to set \`Module.${c}\` after it has already been processed. This can happen, for example, when code is injected via '--post-js' rather than '--pre-js'`)}})}function rt(c){return c===`FS_createPath`||c===`FS_createDataFile`||c===`FS_createPreloadedFile`||c===`FS_unlink`||c===`addRunDependency`||c===`FS_createLazyFile`||c===`FS_createDevice`||c===`removeRunDependency`}function nt(c,u){typeof globalThis>`u`||Object.getOwnPropertyDescriptor(globalThis,c)||Object.defineProperty(globalThis,c,{configurable:!0,get(){u()}})}function it(c,u){nt(c,()=>{O(`\`${c}\` is not longer defined by emscripten. ${u}`)})}it(`buffer`,`Please use HEAP8.buffer or wasmMemory.buffer`),it(`asm`,`Please use wasmExports instead`);function ot(c){Object.getOwnPropertyDescriptor(h,c)||Object.defineProperty(h,c,{configurable:!0,get(){var u=`'${c}' was not exported. add it to EXPORTED_RUNTIME_METHODS (see the Emscripten FAQ)`;rt(c)&&(u+=`. Alternatively, forcing filesystem support (-sFORCE_FILESYSTEM) can export this for you`),A(u)}})}function at(){var c=k.buffer;N=new Int8Array(c),I=new Int16Array(c),P=new Uint8Array(c),L=new Uint16Array(c),z=new Int32Array(c),B=new Uint32Array(c),V=new Float32Array(c),W=new Float64Array(c),H=new BigInt64Array(c),U=new BigUint64Array(c)}d(typeof Int32Array<`u`&&typeof Float64Array<`u`&&Int32Array.prototype.subarray!=null&&Int32Array.prototype.set!=null,`JS engine does not provide full typed array support`);var Q=0,te=null,ne={},$=null;function zt(){Q++,h.monitorRunDependencies?.(Q),d(!ne[`wasm-instantiate`]),ne[`wasm-instantiate`]=1,$===null&&typeof setInterval<`u`&&($=setInterval(()=>{if(j)clearInterval($),$=null;else{var c=!1,u;for(u in ne)c||(c=!0,E(`still waiting on run dependencies:`)),E(`dependency: ${u}`);c&&E(`(end of list)`)}},1e4))}function A(c){throw h.onAbort?.(c),c=`Aborted(`+c+`)`,E(c),j=!0,ee&&Nt(),c=new WebAssembly.RuntimeError(c),v(c),c}function st(){A(`Filesystem support (FS) was not included. The problem is that you are using files from JS, but files were not used from C/C++, so filesystem support was not auto-included. You can force-include filesystem support with -sFORCE_FILESYSTEM`)}function F(c,u){return(...m)=>{d(ee,`native function \`${c}\` called before runtime initialization`),d(!G,`native function \`${c}\` called after runtime exit (use NO_EXIT_RUNTIME to keep it alive after main() exits)`);var h=gt[c];return d(h,`exported native function \`${c}\` not found`),d(m.length<=u,`native function \`${c}\` called with ${m.length} args but expects ${u}`),h(...m)}}var re=0;function ut(c){return(...u)=>{if(j)throw`program has already aborted!`;re++;try{return c(...u)}catch(c){if(j||1<re||c===`unwind`)throw c;A(`unhandled exception: `+[c,c.stack])}finally{re--}}}function Jt(){var c=de.get,u={};de.get=m=>{var h=c.call(de,m),g=u[m];return g&&g.S===h||(g=u[m]={S:h,ca:ut(h)}),g.ca}}var ae;async function Yt(c){if(!D)try{var u=await Ye(c);return new Uint8Array(u)}catch{}if(c==ae&&D)c=new Uint8Array(D);else throw`both async and sync fetching of the wasm failed`;return c}async function Kt(c,u){try{var m=await Yt(c);return await WebAssembly.instantiate(m,u)}catch(c){E(`failed to asynchronously prepare wasm: ${c}`),Ze(ae)&&E(`warning: Loading from a file URI (${ae}) is not supported in most browsers. See https://emscripten.org/docs/getting_started/FAQ.html#how-do-i-run-a-local-webserver-for-testing-why-does-my-program-stall-in-downloading-or-preparing`),A(c)}}async function qt(c){var u=ae;if(!D&&typeof WebAssembly.instantiateStreaming==`function`)try{var m=fetch(u,{credentials:`same-origin`});return await WebAssembly.instantiateStreaming(m,c)}catch(c){E(`wasm streaming compile failed: ${c}`),E(`falling back to ArrayBuffer instantiation`)}return Kt(u,c)}class lt{name=`ExitStatus`;constructor(c){this.message=`Program terminated with exit(${c})`,this.status=c}}var ct=c=>{for(;0<c.length;)c.shift()(h)},oe=[],se=[],Xt=()=>{var c=h.preRun.shift();se.push(c)},le=!1,J=c=>(d(typeof c==`number`),`0x`+(c>>>0).toString(16).padStart(8,`0`)),O=c=>{O.M||={},O.M[c]||(O.M[c]=1,E(c))},de,fe=typeof TextDecoder<`u`?new TextDecoder:void 0,pt=(c,u=0,m=NaN)=>{var h=u+m;for(m=u;c[m]&&!(m>=h);)++m;if(16<m-u&&c.buffer&&fe)return fe.decode(c.subarray(u,m));for(h=``;u<m;){var g=c[u++];if(g&128){var v=c[u++]&63;if((g&224)==192)h+=String.fromCharCode((g&31)<<6|v);else{var y=c[u++]&63;(g&240)==224?g=(g&15)<<12|v<<6|y:((g&248)!=240&&O(`Invalid UTF-8 leading byte `+J(g)+` encountered when deserializing a UTF-8 string in wasm memory to a JS string!`),g=(g&7)<<18|v<<12|y<<6|c[u++]&63),65536>g?h+=String.fromCharCode(g):(g-=65536,h+=String.fromCharCode(55296|g>>10,56320|g&1023))}}else h+=String.fromCharCode(g)}return h},Y=(c,u)=>(d(typeof c==`number`,`UTF8ToString expects a number (got ${typeof c})`),c?pt(P,c,u):``),be=c=>(c=c.getArg(gt.__cpp_exception,0),en(c)),ht=c=>{var u=be(c);c=Ut();var m=Vt(4),h=Vt(4);if(tn(u,m,h),u=B[m>>2],h=B[h>>2],m=Y(u),xt(u),h){var g=Y(h);xt(h)}return Lt(c),[m,g]},x=c=>{if(c===null)return`null`;var u=typeof c;return u===`object`||u===`array`||u===`function`?c.toString():``+c},pe,_=c=>{for(var u=``;P[c];)u+=pe[P[c++]];return u},me={},ge={},ye={},De=h.BindingError=class extends Error{constructor(c){super(c),this.name=`BindingError`}},Qt=c=>{throw new De(c)};function Zt(c,u,m={}){var h=u.name;if(!c)throw new De(`type "${h}" must have a positive integer typeid pointer`);if(ge.hasOwnProperty(c)){if(m.V)return;throw new De(`Cannot register type '${h}' twice`)}ge[c]=u,delete ye[c],me.hasOwnProperty(c)&&(u=me[c],delete me[c],u.forEach(c=>c()))}function C(c,u,m={}){if(u.o===void 0)throw TypeError(`registerType registeredInstance requires argPackAdvance`);return Zt(c,u,m)}var yt=(c,u,m)=>{switch(u){case 1:return m?c=>N[c]:c=>P[c];case 2:return m?c=>I[c>>1]:c=>L[c>>1];case 4:return m?c=>z[c>>2]:c=>B[c>>2];case 8:return m?c=>H[c>>3]:c=>U[c>>3];default:throw TypeError(`invalid integer width (${u}): ${c}`)}},Re=c=>{throw new De(c.g.j.h.name+` instance already deleted`)},je=!1,vt=()=>{},wt=(c,u,m)=>u===m?c:m.m===void 0?null:(c=wt(c,u,m.m),c===null?null:m.R(c)),Me={},Pe={},tr=(c,u)=>{if(u===void 0)throw new De(`ptr should not be undefined`);for(;c.m;)u=c.H(u),c=c.m;return Pe[u]},Fe=h.InternalError=class extends Error{constructor(c){super(c),this.name=`InternalError`}},ve=(c,u)=>{if(!u.j||!u.i)throw new Fe(`makeClassHandle requires ptr and ptrType`);if(!!u.v!=!!u.l)throw new Fe(`Both smartPtrType and smartPtr must be specified`);return u.count={value:1},ue(Object.create(c,{g:{value:u,writable:!0}}))};function Tt(c){function t(){return this.K?ve(this.h.A,{j:this.Y,i:u,v:this,l:c}):ve(this.h.A,{j:this,i:c})}var u=this.U(c);if(!u)return this.N(c),null;var m=tr(this.h,u);if(m!==void 0)return m.g.count.value===0?(m.g.i=u,m.g.l=c,m.clone()):(m=m.clone(),this.N(c),m);if(m=this.h.T(u),m=Me[m],!m)return t.call(this);m=this.J?m.P:m.pointerType;var h=wt(u,this.h,m.h);return h===null?t.call(this):this.K?ve(m.h.A,{j:m,i:h,v:this,l:c}):ve(m.h.A,{j:m,i:h})}var ue=c=>typeof FinalizationRegistry>`u`?(ue=c=>c,c):(je=new FinalizationRegistry(c=>{console.warn(c.X),c=c.g,--c.count.value,c.count.value===0&&(c.l?c.v.B(c.l):c.j.h.B(c.i))}),ue=c=>{var u=c.g;if(u.l){var m={g:u};u=Error(`Embind found a leaked C++ instance ${u.j.h.name} <${J(u.i)}>.
2
+ We'll free it automatically in this case, but this functionality is not reliable across various environments.
3
+ Make sure to invoke .delete() manually once you're done with the instance instead.
4
+ Originally allocated`),`captureStackTrace`in Error&&Error.captureStackTrace(u,Tt),m.X=u.stack.replace(/^Error: /,``),je.register(c,m,c)}return c},vt=c=>{je.unregister(c)},ue(c)),Ie=[];function we(){}var _e=(c,u)=>Object.defineProperty(u,"name",{value:c}),Et=(c,u,m)=>{if(c[u].u===void 0){var h=c[u];c[u]=function(...h){if(!c[u].u.hasOwnProperty(h.length))throw new De(`Function '${m}' called with an invalid number of arguments (${h.length}) - expects one of (${c[u].u})!`);return c[u].u[h.length].apply(this,h)},c[u].u=[],c[u].u[h.C]=h}},At=(c,u)=>{if(h.hasOwnProperty(c))throw new De(`Cannot register public name '${c}' twice`);h[c]=u,h[c].C=void 0},nr=c=>{d(typeof c==`string`),c=c.replace(/[^a-zA-Z0-9_]/g,`$`);var u=c.charCodeAt(0);return 48<=u&&57>=u?`_${c}`:c};function ir(c,u,m,h,g,v,y,S){this.name=c,this.constructor=u,this.A=m,this.B=h,this.m=g,this.T=v,this.H=y,this.R=S,this.Z=[]}var Te=(c,u,m)=>{for(;u!==m;){if(!u.H)throw new De(`Expected null or instance of ${m.name}, got an instance of ${u.name}`);c=u.H(c),u=u.m}return c};function or(c,u){if(u===null){if(this.L)throw new De(`null is not a valid ${this.name}`);return 0}if(!u.g)throw new De(`Cannot pass "${x(u)}" as a ${this.name}`);if(!u.g.i)throw new De(`Cannot pass deleted object as a pointer of type ${this.name}`);return Te(u.g.i,u.g.j.h,this.h)}function ar(c,u){if(u===null){if(this.L)throw new De(`null is not a valid ${this.name}`);if(this.K){var m=this.$();return c!==null&&c.push(this.B,m),m}return 0}if(!u||!u.g)throw new De(`Cannot pass "${x(u)}" as a ${this.name}`);if(!u.g.i)throw new De(`Cannot pass deleted object as a pointer of type ${this.name}`);if(!this.J&&u.g.j.J)throw new De(`Cannot convert argument of type ${u.g.v?u.g.v.name:u.g.j.name} to parameter type ${this.name}`);if(m=Te(u.g.i,u.g.j.h,this.h),this.K){if(u.g.l===void 0)throw new De(`Passing raw pointer to smart pointer is illegal`);switch(this.ba){case 0:if(u.g.v===this)m=u.g.l;else throw new De(`Cannot convert argument of type ${u.g.v?u.g.v.name:u.g.j.name} to parameter type ${this.name}`);break;case 1:m=u.g.l;break;case 2:if(u.g.v===this)m=u.g.l;else{var h=u.clone();m=this.aa(m,Se(()=>h.delete())),c!==null&&c.push(this.B,m)}break;default:throw new De(`Unsupporting sharing policy`)}}return m}function sr(c,u){if(u===null){if(this.L)throw new De(`null is not a valid ${this.name}`);return 0}if(!u.g)throw new De(`Cannot pass "${x(u)}" as a ${this.name}`);if(!u.g.i)throw new De(`Cannot pass deleted object as a pointer of type ${this.name}`);if(u.g.j.J)throw new De(`Cannot convert argument of type ${u.g.j.name} to parameter type ${this.name}`);return Te(u.g.i,u.g.j.h,this.h)}function Ee(c){return this.fromWireType(B[c>>2])}function Ae(c,u,m,h,g,v,y,S,w,T,E){this.name=c,this.h=u,this.L=m,this.J=h,this.K=g,this.Y=v,this.ba=y,this.O=S,this.$=w,this.aa=T,this.B=E,g||u.m!==void 0?this.toWireType=ar:(this.toWireType=h?or:sr,this.s=null)}var ur=(c,u)=>{if(!h.hasOwnProperty(c))throw new Fe(`Replacing nonexistent public symbol`);h[c]=u,h[c].C=void 0},Le=[],b=(c,u,m=!1)=>{if(d(!m,`Async bindings are only supported with JSPI.`),c=_(c),(m=Le[u])||(Le[u]=m=de.get(u)),d(de.get(u)==m,`JavaScript-side Wasm function table mirror is out of date!`),typeof m!=`function`)throw new De(`unknown function pointer with signature ${c}: ${u}`);return m};class lr extends Error{}var Ct=c=>{c=_t(c);var u=_(c);return xt(c),u},q=(c,u)=>{function r(c){h[c]||ge[c]||(ye[c]?ye[c].forEach(r):(m.push(c),h[c]=!0))}var m=[],h={};throw u.forEach(r),new lr(`${c}: `+m.map(Ct).join([`, `]))},R=(c,u,m)=>{function n(u){if(u=m(u),u.length!==c.length)throw new Fe(`Mismatched type converter count`);for(var h=0;h<c.length;++h)C(c[h],u[h])}c.forEach(c=>ye[c]=u);var h=Array(u.length),g=[],v=0;u.forEach((c,u)=>{ge.hasOwnProperty(c)?h[u]=ge[c]:(g.push(c),me.hasOwnProperty(c)||(me[c]=[]),me[c].push(()=>{h[u]=ge[c],++v,v===g.length&&n(h)}))}),g.length===0&&n(h)},ke=c=>{for(;c.length;){var u=c.pop();c.pop()(u)}};function $t(c){for(var u=1;u<c.length;++u)if(c[u]!==null&&c[u].s===void 0)return!0;return!1}function cr(c,u,m,h,g){(c<u||c>m)&&g(`function ${h} called with ${c} arguments, expected ${u==m?u:`${u} to ${m}`}`)}function Oe(c,u,m,h,g,v){var y=u.length;if(2>y)throw new De(`argTypes array size mismatch! Must at least get return value and 'this' types!`);d(!v,`Async bindings are only supported with JSPI.`);var S=u[1]!==null&&m!==null,w=$t(u);m=u[0].name!==`void`;for(var T=y-2,E=u.length-2,D=u.length-1;2<=D&&u[D].optional;--D)E--;for(h=[c,Qt,h,g,ke,u[0],u[1]],g=0;g<y-2;++g)h.push(u[g+2]);if(!w)for(g=S?1:2;g<u.length;++g)u[g].s!==null&&h.push(u[g].s);for(h.push(cr,E,T),w=$t(u),T=u.length-2,E=[],g=[`fn`],S&&g.push(`thisWired`),y=0;y<T;++y)E.push(`arg${y}`),g.push(`arg${y}Wired`);E=E.join(`,`),g=g.join(`,`),E=`return function (${E}) {
5
+ checkArgCount(arguments.length, minArgs, maxArgs, humanName, throwBindingError);
6
+ `,w&&(E+=`var destructors = [];
7
+ `);var k=w?`destructors`:`null`;for(D=`humanName throwBindingError invoker fn runDestructors retType classParam`.split(` `),S&&(E+=`var thisWired = classParam['toWireType'](${k}, this);
8
+ `),y=0;y<T;++y)E+=`var arg${y}Wired = argType${y}['toWireType'](${k}, arg${y});
9
+ `,D.push(`argType${y}`);if(E+=(m||v?`var rv = `:``)+`invoker(${g});
10
+ `,w)E+=`runDestructors(destructors);
11
+ `;else for(y=S?1:2;y<u.length;++y)v=y===1?`thisWired`:`arg`+(y-2)+`Wired`,u[y].s!==null&&(E+=`${v}_dtor(${v});
12
+ `,D.push(`${v}_dtor`));m&&(E+=`var ret = retType['fromWireType'](rv);
13
+ return ret;
14
+ `),E+=`}
15
+ `,D.push(`checkArgCount`,`minArgs`,`maxArgs`),E=`if (arguments.length !== ${D.length}){ throw new Error(humanName + "Expected ${D.length} closure arguments " + arguments.length + " given."); }
16
+ ${E}`;let[j,M]=[D,E];return u=Function(...j,M)(...h),_e(c,u)}for(var xe=(c,u)=>{for(var m=[],h=0;h<c;h++)m.push(B[u+4*h>>2]);return m},It=c=>{c=c.trim();let u=c.indexOf(`(`);return u===-1?c:(d(c.endsWith(`)`),`Parentheses for argument names should match.`),c.slice(0,u))},Ft=(c,u,m)=>{if(!(c instanceof Object))throw new De(`${m} with invalid "this": ${c}`);if(!(c instanceof u.h.constructor))throw new De(`${m} incompatible with "this" of type ${c.constructor.name}`);if(!c.g.i)throw new De(`cannot call emscripten binding method ${m} on deleted object`);return Te(c.g.i,c.g.j.h,u.h)},ze=[],Be=[],We=c=>{9<c&&--Be[c+1]===0&&(d(Be[c]!==void 0,`Decref for unallocated handle.`),Be[c]=void 0,ze.push(c))},Ue=c=>{if(!c)throw new De(`Cannot use deleted val. handle = ${c}`);return d(c===2||Be[c]!==void 0&&c%2==0,`invalid handle: ${c}`),Be[c]},Se=c=>{switch(c){case void 0:return 2;case null:return 4;case!0:return 6;case!1:return 8;default:let u=ze.pop()||Be.length;return Be[u]=c,Be[u+1]=1,u}},Ge={name:`emscripten::val`,fromWireType:c=>{var u=Ue(c);return We(c),u},toWireType:(c,u)=>Se(u),o:8,readValueFromPointer:Ee,s:null},dr=(c,u,m)=>{switch(u){case 1:return m?function(c){return this.fromWireType(N[c])}:function(c){return this.fromWireType(P[c])};case 2:return m?function(c){return this.fromWireType(I[c>>1])}:function(c){return this.fromWireType(L[c>>1])};case 4:return m?function(c){return this.fromWireType(z[c>>2])}:function(c){return this.fromWireType(B[c>>2])};default:throw TypeError(`invalid integer width (${u}): ${c}`)}},Ne=(c,u)=>{var m=ge[c];if(m===void 0)throw c=`${u} has unknown type ${Ct(c)}`,new De(c);return m},fr=(c,u)=>{switch(u){case 4:return function(c){return this.fromWireType(V[c>>2])};case 8:return function(c){return this.fromWireType(W[c>>3])};default:throw TypeError(`invalid float width (${u}): ${c}`)}},Ke=Object.assign({optional:!0},Ge),X=(c,u,m)=>{d(typeof m==`number`,`stringToUTF8(str, outPtr, maxBytesToWrite) is missing the third parameter that specifies the length of the output buffer!`);var h=P;if(d(typeof c==`string`,`stringToUTF8Array expects a string (got ${typeof c})`),0<m){var g=u;m=u+m-1;for(var v=0;v<c.length;++v){var y=c.charCodeAt(v);if(55296<=y&&57343>=y){var S=c.charCodeAt(++v);y=65536+((y&1023)<<10)|S&1023}if(127>=y){if(u>=m)break;h[u++]=y}else{if(2047>=y){if(u+1>=m)break;h[u++]=192|y>>6}else{if(65535>=y){if(u+2>=m)break;h[u++]=224|y>>12}else{if(u+3>=m)break;1114111<y&&O(`Invalid Unicode code point `+J(y)+` encountered when serializing a JS string to a UTF-8 string in wasm memory! (Valid unicode code points should be in range 0-0x10FFFF).`),h[u++]=240|y>>18,h[u++]=128|y>>12&63}h[u++]=128|y>>6&63}h[u++]=128|y&63}}h[u]=0,c=u-g}else c=0;return c},Ce=c=>{for(var u=0,m=0;m<c.length;++m){var h=c.charCodeAt(m);127>=h?u++:2047>=h?u+=2:55296<=h&&57343>=h?(u+=4,++m):u+=3}return u},qe=typeof TextDecoder<`u`?new TextDecoder(`utf-16le`):void 0,pr=(c,u)=>{d(c%2==0,`Pointer passed to UTF16ToString must be aligned to two bytes!`);for(var m=c>>1,h=m+u/2;!(m>=h)&&L[m];)++m;if(m<<=1,32<m-c&&qe)return qe.decode(P.subarray(c,m));for(m=``,h=0;!(h>=u/2);++h){var g=I[c+2*h>>1];if(g==0)break;m+=String.fromCharCode(g)}return m},hr=(c,u,m)=>{if(d(u%2==0,`Pointer passed to stringToUTF16 must be aligned to two bytes!`),d(typeof m==`number`,`stringToUTF16(str, outPtr, maxBytesToWrite) is missing the third parameter that specifies the length of the output buffer!`),m??=2147483647,2>m)return 0;m-=2;var h=u;m=m<2*c.length?m/2:c.length;for(var g=0;g<m;++g)I[u>>1]=c.charCodeAt(g),u+=2;return I[u>>1]=0,u-h},gr=c=>2*c.length,yr=(c,u)=>{d(c%4==0,`Pointer passed to UTF32ToString must be aligned to four bytes!`);for(var m=0,h=``;!(m>=u/4);){var g=z[c+4*m>>2];if(g==0)break;++m,65536<=g?(g-=65536,h+=String.fromCharCode(55296|g>>10,56320|g&1023)):h+=String.fromCharCode(g)}return h},vr=(c,u,m)=>{if(d(u%4==0,`Pointer passed to stringToUTF32 must be aligned to four bytes!`),d(typeof m==`number`,`stringToUTF32(str, outPtr, maxBytesToWrite) is missing the third parameter that specifies the length of the output buffer!`),m??=2147483647,4>m)return 0;var h=u;m=h+m-4;for(var g=0;g<c.length;++g){var v=c.charCodeAt(g);if(55296<=v&&57343>=v){var y=c.charCodeAt(++g);v=65536+((v&1023)<<10)|y&1023}if(z[u>>2]=v,u+=4,u+4>m)break}return z[u>>2]=0,u-h},wr=c=>{for(var u=0,m=0;m<c.length;++m){var h=c.charCodeAt(m);55296<=h&&57343>=h&&++m,u+=4}return u},Je=0,Xe=[],_r=c=>{var u=Xe.length;return Xe.push(c),u},Tr=(c,u)=>{for(var m=Array(c),h=0;h<c;++h)m[h]=Ne(B[u+4*h>>2],`parameter ${h}`);return m},Er=(c,u,m)=>{var h=[];return c=c.toWireType(h,m),h.length&&(B[u>>2]=Se(h)),c},Qe={},Rt=c=>{if(!(c instanceof lt||c==`unwind`))throw ie(),c instanceof WebAssembly.RuntimeError&&0>=Ut()&&E(`Stack overflow detected. You can try increasing -sSTACK_SIZE (currently set to 65536)`),c},Mt=c=>{throw M=c,le||0<Je||(h.onExit?.(c),j=!0),new lt(c)},Ar=c=>{if(G||j)E(`user callback triggered after runtime exited or application aborted. Ignoring.`);else try{if(c(),!(G||le||0<Je))try{if(M=c=M,le||0<Je||(d(!G),ie(),Dt(),St(0),tt[1].length&&Ve(1,10),tt[2].length&&Ve(2,10),G=!0),le||0<Je){var u=`program exited (with status: ${c}), but keepRuntimeAlive() is set (counter=${Je}) due to an async operation, so halting execution but not exiting the runtime or preventing further async execution (you can use emscripten_force_exit, if you want to force a true shutdown)`;v(u),E(u)}Mt(c)}catch(c){Rt(c)}}catch(c){Rt(c)}},$e={},kt=()=>{if(!et){var c={USER:`web_user`,LOGNAME:`web_user`,PATH:`/`,PWD:`/`,HOME:`/home/web_user`,LANG:(typeof navigator==`object`&&navigator.languages&&navigator.languages[0]||`C`).replace(`-`,`_`)+`.UTF-8`,_:S||`./this.program`},u;for(u in $e)$e[u]===void 0?delete c[u]:c[u]=$e[u];var m=[];for(u in c)m.push(`${u}=${c[u]}`);et=m}return et},et,tt=[null,[],[]],Ve=(c,u)=>{var m=tt[c];d(m),u===0||u===10?((c===1?T:E)(pt(m)),m.length=0):m.push(u)},dt=Array(256),ft=0;256>ft;++ft)dt[ft]=String.fromCharCode(ft);pe=dt,(()=>{let c=we.prototype;Object.assign(c,{isAliasOf:function(c){if(!(this instanceof we&&c instanceof we))return!1;var u=this.g.j.h,m=this.g.i;c.g=c.g;var h=c.g.j.h;for(c=c.g.i;u.m;)m=u.H(m),u=u.m;for(;h.m;)c=h.H(c),h=h.m;return u===h&&m===c},clone:function(){if(this.g.i||Re(this),this.g.G)return this.g.count.value+=1,this;var c=ue,u=Object,m=u.create,h=Object.getPrototypeOf(this),g=this.g;return c=c(m.call(u,h,{g:{value:{count:g.count,F:g.F,G:g.G,i:g.i,j:g.j,l:g.l,v:g.v}}})),c.g.count.value+=1,c.g.F=!1,c},delete(){if(this.g.i||Re(this),this.g.F&&!this.g.G)throw new De(`Object already scheduled for deletion`);vt(this);var c=this.g;--c.count.value,c.count.value===0&&(c.l?c.v.B(c.l):c.j.h.B(c.i)),this.g.G||(this.g.l=void 0,this.g.i=void 0)},isDeleted:function(){return!this.g.i},deleteLater:function(){if(this.g.i||Re(this),this.g.F&&!this.g.G)throw new De(`Object already scheduled for deletion`);return Ie.push(this),this.g.F=!0,this}});let u=Symbol.dispose;u&&(c[u]=c.delete)})(),Object.assign(Ae.prototype,{U(c){return this.O&&(c=this.O(c)),c},N(c){this.B?.(c)},o:8,readValueFromPointer:Ee,fromWireType:Tt}),Be.push(0,1,void 0,1,null,1,!0,1,!1,1),d(Be.length===10),h.count_emval_handles=()=>Be.length/2-5-ze.length,h.noExitRuntime&&(le=h.noExitRuntime),h.print&&(T=h.print),h.printErr&&(E=h.printErr),h.wasmBinary&&(D=h.wasmBinary),h.FS_createDataFile=function(){st()},h.FS_createPreloadedFile=function(){st()},Object.getOwnPropertyDescriptor(h,`fetchSettings`)&&A("`Module.fetchSettings` was supplied but `fetchSettings` not included in INCOMING_MODULE_JS_API"),h.thisProgram&&(S=h.thisProgram),d(typeof h.memoryInitializerPrefixURL>`u`,`Module.memoryInitializerPrefixURL option was removed, use Module.locateFile instead`),d(typeof h.pthreadMainPrefixURL>`u`,`Module.pthreadMainPrefixURL option was removed, use Module.locateFile instead`),d(typeof h.cdInitializerPrefixURL>`u`,`Module.cdInitializerPrefixURL option was removed, use Module.locateFile instead`),d(typeof h.filePackagePrefixURL>`u`,`Module.filePackagePrefixURL option was removed, use Module.locateFile instead`),d(typeof h.read>`u`,`Module.read option was removed`),d(typeof h.readAsync>`u`,`Module.readAsync option was removed (modify readAsync in JS)`),d(typeof h.readBinary>`u`,`Module.readBinary option was removed (modify readBinary in JS)`),d(typeof h.setWindowTitle>`u`,`Module.setWindowTitle option was removed (modify emscripten_set_window_title in JS)`),d(typeof h.TOTAL_MEMORY>`u`,`Module.TOTAL_MEMORY has been renamed Module.INITIAL_MEMORY`),d(typeof h.ENVIRONMENT>`u`,`Module.ENVIRONMENT has been deprecated. To force the environment, use the ENVIRONMENT compile-time option (for example, -sENVIRONMENT=web or -sENVIRONMENT=node)`),d(typeof h.STACK_SIZE>`u`,`STACK_SIZE can no longer be set at runtime. Use -sSTACK_SIZE at link time`),d(typeof h.wasmMemory>`u`,"Use of `wasmMemory` detected. Use -sIMPORTED_MEMORY to define wasmMemory externally"),d(typeof h.INITIAL_MEMORY>`u`,`Detected runtime INITIAL_MEMORY setting. Use -sIMPORTED_MEMORY to define wasmMemory dynamically`),`writeI53ToI64 writeI53ToI64Clamped writeI53ToI64Signaling writeI53ToU64Clamped writeI53ToU64Signaling readI53FromI64 readI53FromU64 convertI32PairToI53 convertI32PairToI53Checked convertU32PairToI53 getTempRet0 setTempRet0 zeroMemory strError inetPton4 inetNtop4 inetPton6 inetNtop6 readSockaddr writeSockaddr emscriptenLog readEmAsmArgs jstoi_q listenOnce autoResumeAudioContext getDynCaller dynCall runtimeKeepalivePush runtimeKeepalivePop asmjsMangle asyncLoad mmapAlloc HandleAllocator getNativeTypeSize addOnInit addOnPostCtor addOnPreMain addOnExit STACK_SIZE STACK_ALIGN POINTER_SIZE ASSERTIONS getCFunc ccall cwrap uleb128Encode sigToWasmTypes generateFuncType convertJsFunctionToWasm getEmptyTableSlot updateTableMap getFunctionAddress addFunction removeFunction reallyNegative unSign strLen reSign formatString intArrayFromString intArrayToString AsciiToString stringToAscii stringToNewUTF8 stringToUTF8OnStack writeArrayToMemory registerKeyEventCallback maybeCStringToJsString findEventTarget getBoundingClientRect fillMouseEventData registerMouseEventCallback registerWheelEventCallback registerUiEventCallback registerFocusEventCallback fillDeviceOrientationEventData registerDeviceOrientationEventCallback fillDeviceMotionEventData registerDeviceMotionEventCallback screenOrientation fillOrientationChangeEventData registerOrientationChangeEventCallback fillFullscreenChangeEventData registerFullscreenChangeEventCallback JSEvents_requestFullscreen JSEvents_resizeCanvasForFullscreen registerRestoreOldStyle hideEverythingExceptGivenElement restoreHiddenElements setLetterbox softFullscreenResizeWebGLRenderTarget doRequestFullscreen fillPointerlockChangeEventData registerPointerlockChangeEventCallback registerPointerlockErrorEventCallback requestPointerLock fillVisibilityChangeEventData registerVisibilityChangeEventCallback registerTouchEventCallback fillGamepadEventData registerGamepadEventCallback registerBeforeUnloadEventCallback fillBatteryEventData battery registerBatteryEventCallback setCanvasElementSize getCanvasElementSize jsStackTrace getCallstack convertPCtoSourceLocation wasiRightsToMuslOFlags wasiOFlagsToMuslOFlags initRandomFill randomFill safeSetTimeout setImmediateWrapped safeRequestAnimationFrame clearImmediateWrapped registerPostMainLoop registerPreMainLoop getPromise makePromise idsToPromises makePromiseCallback Browser_asyncPrepareDataCounter isLeapYear ydayFromDate arraySum addDays getSocketFromFD getSocketAddress heapObjectForWebGLType toTypedArrayIndex webgl_enable_ANGLE_instanced_arrays webgl_enable_OES_vertex_array_object webgl_enable_WEBGL_draw_buffers webgl_enable_WEBGL_multi_draw webgl_enable_EXT_polygon_offset_clamp webgl_enable_EXT_clip_control webgl_enable_WEBGL_polygon_mode emscriptenWebGLGet computeUnpackAlignedImageSize colorChannelsInGlTextureFormat emscriptenWebGLGetTexPixelData emscriptenWebGLGetUniform webglGetUniformLocation webglPrepareUniformLocationsBeforeFirstUse webglGetLeftBracePos emscriptenWebGLGetVertexAttrib __glGetActiveAttribOrUniform writeGLArray registerWebGlEventCallback runAndAbortIfError ALLOC_NORMAL ALLOC_STACK allocate writeStringToMemory writeAsciiToMemory demangle stackTrace getFunctionArgsName createJsInvokerSignature PureVirtualError registerInheritedInstance unregisterInheritedInstance getInheritedInstanceCount getLiveInheritedInstances setDelayFunction getStringOrSymbol emval_get_global`.split(` `).forEach(function(c){nt(c,()=>{var u=`\`${c}\` is a library symbol and not included by default; add it to your library.js __deps or to DEFAULT_LIBRARY_FUNCS_TO_INCLUDE on the command line`,m=c;m.startsWith(`_`)||(m=`$`+c),u+=` (e.g. -sDEFAULT_LIBRARY_FUNCS_TO_INCLUDE='${m}')`,rt(c)&&(u+=`. Alternatively, forcing filesystem support (-sFORCE_FILESYSTEM) can export this for you`),O(u)}),ot(c)}),`run addRunDependency removeRunDependency out err callMain abort wasmMemory wasmExports HEAPF32 HEAPF64 HEAP8 HEAPU8 HEAP16 HEAPU16 HEAP32 HEAPU32 HEAP64 HEAPU64 writeStackCookie checkStackCookie INT53_MAX INT53_MIN bigintToI53Checked stackSave stackRestore stackAlloc ptrToString exitJS getHeapMax growMemory ENV ERRNO_CODES DNS Protocols Sockets timers warnOnce readEmAsmArgsArray jstoi_s getExecutableName handleException keepRuntimeAlive callUserCallback maybeExit alignMemory wasmTable noExitRuntime addOnPreRun addOnPostRun freeTableIndexes functionsInTableMap setValue getValue PATH PATH_FS UTF8Decoder UTF8ArrayToString UTF8ToString stringToUTF8Array stringToUTF8 lengthBytesUTF8 UTF16Decoder UTF16ToString stringToUTF16 lengthBytesUTF16 UTF32ToString stringToUTF32 lengthBytesUTF32 JSEvents specialHTMLTargets findCanvasEventTarget currentFullscreenStrategy restoreOldWindowedStyle UNWIND_CACHE ExitStatus getEnvStrings checkWasiClock flush_NO_FILESYSTEM emSetImmediate emClearImmediate_deps emClearImmediate promiseMap getExceptionMessageCommon getCppExceptionTag getCppExceptionThrownObjectFromWebAssemblyException Browser getPreloadedImageData__data wget MONTH_DAYS_REGULAR MONTH_DAYS_LEAP MONTH_DAYS_REGULAR_CUMULATIVE MONTH_DAYS_LEAP_CUMULATIVE SYSCALLS tempFixedLengthArray miniTempWebGLFloatBuffers miniTempWebGLIntBuffers GL AL GLUT EGL GLEW IDBStore SDL SDL_gfx allocateUTF8 allocateUTF8OnStack print printErr InternalError BindingError throwInternalError throwBindingError registeredTypes awaitingDependencies typeDependencies tupleRegistrations structRegistrations sharedRegisterType whenDependentTypesAreResolved embind_charCodes embind_init_charCodes readLatin1String getTypeName getFunctionName heap32VectorToArray requireRegisteredType usesDestructorStack checkArgCount getRequiredArgCount createJsInvoker UnboundTypeError GenericWireTypeSize EmValType EmValOptionalType throwUnboundTypeError ensureOverloadTable exposePublicSymbol replacePublicSymbol createNamedFunction embindRepr registeredInstances getBasestPointer getInheritedInstance registeredPointers registerType integerReadValueFromPointer enumReadValueFromPointer floatReadValueFromPointer readPointer runDestructors craftInvokerFunction embind__requireFunction genericPointerToWireType constNoSmartPtrRawPointerToWireType nonConstNoSmartPtrRawPointerToWireType init_RegisteredPointer RegisteredPointer RegisteredPointer_fromWireType runDestructor releaseClassHandle finalizationRegistry detachFinalizer_deps detachFinalizer attachFinalizer makeClassHandle init_ClassHandle ClassHandle throwInstanceAlreadyDeleted deletionQueue flushPendingDeletes delayFunction RegisteredClass shallowCopyInternalPointer downcastPointer upcastPointer validateThis char_0 char_9 makeLegalFunctionName emval_freelist emval_handles emval_symbols init_emval count_emval_handles Emval emval_returnValue emval_lookupTypes emval_methodCallers emval_addMethodCaller reflectConstruct`.split(` `).forEach(ot),h.getExceptionMessage=ht,h.incrementExceptionRefcount=c=>{c=be(c),Gt(c)},h.decrementExceptionRefcount=c=>{c=be(c),Wt(c)};var mt={__assert_fail:(c,u,m,h)=>A(`Assertion failed: ${Y(c)}, at: `+[u?Y(u):`unknown filename`,m,h?Y(h):`unknown function`]),__throw_exception_with_stack_trace:c=>{throw c=new WebAssembly.Exception(gt.__cpp_exception,[c],{traceStack:!0}),c.message=ht(c),c},_abort_js:()=>A(`native code called abort()`),_embind_register_bigint:(c,u,m,h,g)=>{u=_(u);var v=u.indexOf(`u`)!=-1;v&&(g=(1n<<64n)-1n),C(c,{name:u,fromWireType:c=>c,toWireType:function(c,m){if(typeof m!=`bigint`&&typeof m!=`number`)throw TypeError(`Cannot convert "${x(m)}" to ${this.name}`);if(typeof m==`number`&&(m=BigInt(m)),m<h||m>g)throw TypeError(`Passing a number "${x(m)}" from JS side to C/C++ side to an argument of type "${u}", which is outside the valid range [${h}, ${g}]!`);return m},o:8,readValueFromPointer:yt(u,m,!v),s:null})},_embind_register_bool:(c,u,m,h)=>{u=_(u),C(c,{name:u,fromWireType:function(c){return!!c},toWireType:function(c,u){return u?m:h},o:8,readValueFromPointer:function(c){return this.fromWireType(P[c])},s:null})},_embind_register_class:(c,u,m,h,g,v,y,S,w,T,E,D,k)=>{E=_(E),v=b(g,v),S&&=b(y,S),T&&=b(w,T),k=b(D,k);var j=nr(E);At(j,function(){q(`Cannot construct ${E} due to unbound types`,[h])}),R([c,u,m],h?[h]:[],u=>{if(u=u[0],h)var m=u.h,g=m.A;else g=we.prototype;u=_e(E,function(...c){if(Object.getPrototypeOf(this)!==y)throw new De(`Use 'new' to construct ${E}`);if(w.D===void 0)throw new De(`${E} has no accessible constructor`);var u=w.D[c.length];if(u===void 0)throw new De(`Tried to invoke ctor of ${E} with invalid number of parameters (${c.length}) - expected (${Object.keys(w.D).toString()}) parameters instead!`);return u.apply(this,c)});var y=Object.create(g,{constructor:{value:u}});u.prototype=y;var w=new ir(E,u,y,k,m,v,S,T);if(w.m){var D;(D=w.m).I??(D.I=[]),w.m.I.push(w)}return m=new Ae(E,w,!0,!1,!1),D=new Ae(E+`*`,w,!1,!1,!1),g=new Ae(E+` const*`,w,!1,!0,!1),Me[c]={pointerType:D,P:g},ur(j,u),[m,D,g]})},_embind_register_class_class_function:(c,u,m,h,g,v,y,S)=>{var w=xe(m,h);u=_(u),u=It(u),v=b(g,v,S),R([],[c],c=>{function l(){q(`Cannot call ${h} due to unbound types`,w)}c=c[0];var h=`${c.name}.${u}`;u.startsWith(`@@`)&&(u=Symbol[u.substring(2)]);var g=c.h.constructor;return g[u]===void 0?(l.C=m-1,g[u]=l):(Et(g,u,h),g[u].u[m-1]=l),R([],w,w=>{if(w=Oe(h,[w[0],null].concat(w.slice(1)),null,v,y,S),g[u].u===void 0?(w.C=m-1,g[u]=w):g[u].u[m-1]=w,c.h.I)for(let m of c.h.I)m.constructor.hasOwnProperty(u)||(m.constructor[u]=w);return[]}),[]})},_embind_register_class_constructor:(c,u,m,h,g,v)=>{d(0<u);var y=xe(u,m);g=b(h,g),R([],[c],c=>{c=c[0];var m=`constructor ${c.name}`;if(c.h.D===void 0&&(c.h.D=[]),c.h.D[u-1]!==void 0)throw new De(`Cannot register multiple constructors with identical number of parameters (${u-1}) for class '${c.name}'! Overload resolution is currently only performed using the parameter count, not actual type info!`);return c.h.D[u-1]=()=>{q(`Cannot construct ${c.name} due to unbound types`,y)},R([],y,h=>(h.splice(1,0,null),c.h.D[u-1]=Oe(m,h,null,g,v),[])),[]})},_embind_register_class_function:(c,u,m,h,g,v,y,S,w)=>{var T=xe(m,h);u=_(u),u=It(u),v=b(g,v,w),R([],[c],c=>{function p(){q(`Cannot call ${h} due to unbound types`,T)}c=c[0];var h=`${c.name}.${u}`;u.startsWith(`@@`)&&(u=Symbol[u.substring(2)]),S&&c.h.Z.push(u);var g=c.h.A,E=g[u];return E===void 0||E.u===void 0&&E.className!==c.name&&E.C===m-2?(p.C=m-2,p.className=c.name,g[u]=p):(Et(g,u,h),g[u].u[m-2]=p),R([],T,S=>(S=Oe(h,S,c,v,y,w),g[u].u===void 0?(S.C=m-2,g[u]=S):g[u].u[m-2]=S,[])),[]})},_embind_register_class_property:(c,u,m,h,g,v,y,S,w,T)=>{u=_(u),g=b(h,g),R([],[c],c=>{c=c[0];var h=`${c.name}.${u}`,E={get(){q(`Cannot access ${h} due to unbound types`,[m,y])},enumerable:!0,configurable:!0};return E.set=w?()=>q(`Cannot access ${h} due to unbound types`,[m,y]):()=>{throw new De(h+` is a read-only property`)},Object.defineProperty(c.h.A,u,E),R([],w?[m,y]:[m],m=>{var y=m[0],E={get(){var u=Ft(this,c,h+` getter`);return y.fromWireType(g(v,u))},enumerable:!0};if(w){w=b(S,w);var D=m[1];E.set=function(u){var m=Ft(this,c,h+` setter`),g=[];w(T,m,D.toWireType(g,u)),ke(g)}}return Object.defineProperty(c.h.A,u,E),[]}),[]})},_embind_register_emval:c=>C(c,Ge),_embind_register_enum:(c,u,m,h)=>{function i(){}u=_(u),i.values={},C(c,{name:u,constructor:i,fromWireType:function(c){return this.constructor.values[c]},toWireType:(c,u)=>u.value,o:8,readValueFromPointer:dr(u,m,h),s:null}),At(u,i)},_embind_register_enum_value:(c,u,m)=>{var h=Ne(c,`enum`);u=_(u),c=h.constructor,h=Object.create(h.constructor.prototype,{value:{value:m},constructor:{value:_e(`${h.name}_${u}`,function(){})}}),c.values[m]=h,c[u]=h},_embind_register_float:(c,u,m)=>{u=_(u),C(c,{name:u,fromWireType:c=>c,toWireType:(c,u)=>{if(typeof u!=`number`&&typeof u!=`boolean`)throw TypeError(`Cannot convert ${x(u)} to ${this.name}`);return u},o:8,readValueFromPointer:fr(u,m),s:null})},_embind_register_integer:(c,u,m,h,g)=>{u=_(u),g===-1&&(g=4294967295);var o=c=>c;if(h===0){var v=32-8*m;o=c=>c<<v>>>v}var s=(c,m)=>{if(typeof c!=`number`&&typeof c!=`boolean`)throw TypeError(`Cannot convert "${x(c)}" to ${m}`);if(c<h||c>g)throw TypeError(`Passing a number "${x(c)}" from JS side to C/C++ side to an argument of type "${u}", which is outside the valid range [${h}, ${g}]!`)},y=u.includes(`unsigned`)?function(c,u){return s(u,this.name),u>>>0}:function(c,u){return s(u,this.name),u};C(c,{name:u,fromWireType:o,toWireType:y,o:8,readValueFromPointer:yt(u,m,h!==0),s:null})},_embind_register_memory_view:(c,u,m)=>{function n(c){return new h(N.buffer,B[c+4>>2],B[c>>2])}var h=[Int8Array,Uint8Array,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array,BigInt64Array,BigUint64Array][u];m=_(m),C(c,{name:m,fromWireType:n,o:8,readValueFromPointer:n},{V:!0})},_embind_register_optional:c=>{C(c,Ke)},_embind_register_std_string:(c,u)=>{u=_(u),C(c,{name:u,fromWireType:function(c){for(var u=B[c>>2],m=c+4,h,g=m,v=0;v<=u;++v){var y=m+v;(v==u||P[y]==0)&&(g=Y(g,y-g),h===void 0?h=g:(h+=`\0`,h+=g),g=y+1)}return xt(c),h},toWireType:function(c,u){u instanceof ArrayBuffer&&(u=new Uint8Array(u));var m=typeof u==`string`;if(!(m||ArrayBuffer.isView(u)&&u.BYTES_PER_ELEMENT==1))throw new De(`Cannot pass non-string to std::string`);var h=m?Ce(u):u.length,g=bt(4+h+1),v=g+4;return B[g>>2]=h,m?X(u,v,h+1):P.set(u,v),c!==null&&c.push(xt,g),g},o:8,readValueFromPointer:Ee,s(c){xt(c)}})},_embind_register_std_wstring:(c,u,m)=>{if(m=_(m),u===2)var h=pr,g=hr,v=gr,a=c=>L[c>>1];else u===4&&(h=yr,g=vr,v=wr,a=c=>B[c>>2]);C(c,{name:m,fromWireType:c=>{for(var m=B[c>>2],g,v=c+4,y=0;y<=m;++y){var S=c+4+y*u;(y==m||a(S)==0)&&(v=h(v,S-v),g===void 0?g=v:(g+=`\0`,g+=v),v=S+u)}return xt(c),g},toWireType:(c,h)=>{if(typeof h!=`string`)throw new De(`Cannot pass non-string to C++ string type ${m}`);var y=v(h),S=bt(4+y+u);return B[S>>2]=y/u,g(h,S+4,y+u),c!==null&&c.push(xt,S),S},o:8,readValueFromPointer:Ee,s(c){xt(c)}})},_embind_register_void:(c,u)=>{u=_(u),C(c,{W:!0,name:u,o:0,fromWireType:()=>{},toWireType:()=>{}})},_emscripten_runtime_keepalive_clear:()=>{le=!1,Je=0},_emval_call:(c,u,m,h)=>(c=Xe[c],u=Ue(u),c(null,u,m,h)),_emval_decref:We,_emval_get_method_caller:(c,u,m)=>{u=Tr(c,u);var h=u.shift();c--;var g=`return function (obj, func, destructorsRef, args) {
17
+ `,v=0,y=[];m===0&&y.push(`obj`);for(var S=[`retType`],w=[h],T=0;T<c;++T)y.push(`arg${T}`),S.push(`argType${T}`),w.push(u[T]),g+=` var arg${T} = argType${T}.readValueFromPointer(args${v?`+`+v:``});
18
+ `,v+=u[T].o;return g+=` var rv = ${m===1?`new func`:`func.call`}(${y.join(`, `)});
19
+ `,h.W||(S.push(`emval_returnValue`),w.push(Er),g+=` return emval_returnValue(retType, destructorsRef, rv);
20
+ `),c=Function(...S,g+`};
21
+ `)(...w),m=`methodCaller<(${u.map(c=>c.name).join(`, `)}) => ${h.name}>`,_r(_e(m,c))},_emval_incref:c=>{9<c&&(Be[c+1]+=1)},_emval_run_destructors:c=>{ke(Ue(c)),We(c)},_emval_take_value:(c,u)=>(c=Ne(c,`_emval_take_value`),c=c.readValueFromPointer(u),Se(c)),_setitimer_js:(c,u)=>(Qe[c]&&(clearTimeout(Qe[c].id),delete Qe[c]),u&&(Qe[c]={id:setTimeout(()=>{d(c in Qe),delete Qe[c],Ar(()=>jt(c,performance.now()))},u),da:u}),0),_tzset_js:(c,t,u,m)=>{var h=new Date().getFullYear(),g=new Date(h,0,1).getTimezoneOffset();h=new Date(h,6,1).getTimezoneOffset(),B[c>>2]=60*Math.max(g,h),z[t>>2]=+(g!=h),t=c=>{var u=Math.abs(c);return`UTC${0<=c?`-`:`+`}${String(Math.floor(u/60)).padStart(2,`0`)}${String(u%60).padStart(2,`0`)}`},c=t(g),t=t(h),d(c),d(t),d(16>=Ce(c),`timezone name truncated to fit in TZNAME_MAX (${c})`),d(16>=Ce(t),`timezone name truncated to fit in TZNAME_MAX (${t})`),h<g?(X(c,u,17),X(t,m,17)):(X(c,m,17),X(t,u,17))},clock_time_get:function(c,u,m){return 0<=c&&3>=c?(H[m>>3]=BigInt(Math.round(1e6*(c===0?Date.now():performance.now()))),0):28},emscripten_resize_heap:c=>{var u=P.length;if(c>>>=0,d(c>u),2147483648<c)return E(`Cannot enlarge memory, requested ${c} bytes, but the limit is 2147483648 bytes!`),!1;for(var m=1;4>=m;m*=2){var h=u*(1+.2/m);h=Math.min(h,c+100663296);var g=Math,v=g.min;h=Math.max(c,h),d(65536,`alignment argument is required`),g=v.call(g,2147483648,65536*Math.ceil(h/65536));e:{v=g,h=k.buffer;var y=(v-h.byteLength+65535)/65536|0;try{k.grow(y),at();var S=1;break e}catch(c){E(`growMemory: Attempted to grow heap from ${h.byteLength} bytes to ${v} bytes, but got error: ${c}`)}S=void 0}if(S)return!0}return E(`Failed to grow the heap from ${u} bytes to ${g} bytes, not enough memory!`),!1},environ_get:(c,u)=>{var m=0,h=0,g;for(g of kt()){var v=u+m;B[c+h>>2]=v,m+=X(g,v,1/0)+1,h+=4}return 0},environ_sizes_get:(c,u)=>{var m=kt();B[c>>2]=m.length,c=0;for(var h of m)c+=Ce(h)+1;return B[u>>2]=c,0},fd_close:()=>{A(`fd_close called without SYSCALLS_REQUIRE_FILESYSTEM`)},fd_seek:function(){return 70},fd_write:(c,u,m,h)=>{for(var g=0,v=0;v<m;v++){var y=B[u>>2],S=B[u+4>>2];u+=8;for(var w=0;w<S;w++)Ve(c,P[y+w]);g+=S}return B[h>>2]=g,0},proc_exit:Mt},gt=await async function(){function e(c){c=gt=c.exports;var u={};for(g in c){var m=c[g];u[g]=typeof m==`function`?ut(m):m}if(gt=u,k=gt.memory,d(k,`memory not found in wasm exports`),at(),de=gt.__indirect_function_table,d(de,`table not found in wasm exports`),Jt(),Q--,h.monitorRunDependencies?.(Q),d(ne[`wasm-instantiate`]),delete ne[`wasm-instantiate`],Q==0&&($!==null&&(clearInterval($),$=null),te)){var g=te;te=null,g()}return gt}function t(u){return d(h===c,`the Module object should not be replaced during async compilation - perhaps the order of HTML elements is wrong?`),c=null,e(u.instance)}zt();var c=h,u={env:mt,wasi_snapshot_preview1:mt};if(h.instantiateWasm)return new Promise((c,m)=>{try{h.instantiateWasm(u,(u,m)=>{c(e(u,m))})}catch(c){E(`Module.instantiateWasm callback failed with error: ${c}`),m(c)}});ae??=h.locateFile?h.locateFile?h.locateFile(`libavoid.wasm`,w):w+`libavoid.wasm`:new URL(new URL(`libavoid-BRQRZjmQ.wasm`,import.meta.url).href,``+import.meta.url).href;try{return t(await qt(u))}catch(c){return v(c),Promise.reject(c)}}(),_t=F(`__getTypeName`,1),bt=F(`malloc`,1),xt=F(`free`,1),St=F(`fflush`,1),Dt=F(`__funcs_on_exit`,0),Ot=gt.emscripten_stack_get_end,jt=F(`_emscripten_timeout`,2),Nt=gt.__trap,Pt=gt.emscripten_stack_init,Lt=gt._emscripten_stack_restore,Vt=gt._emscripten_stack_alloc,Ut=gt.emscripten_stack_get_current,Wt=F(`__cxa_decrement_exception_refcount`,1),Gt=F(`__cxa_increment_exception_refcount`,1),en=F(`__thrown_object_from_unwind_exception`,1),tn=F(`__get_exception_message`,3),nn;function He(){function e(){if(d(!nn),nn=!0,h.calledRun=!0,!j){if(d(!ee),ee=!0,ie(),gt.__wasm_call_ctors(),g(h),h.onRuntimeInitialized?.(),he(`onRuntimeInitialized`),d(!h._main,`compiled without a main, but one is present. if you added it from JS, use Module["onRuntimeInitialized"]`),ie(),h.postRun)for(typeof h.postRun==`function`&&(h.postRun=[h.postRun]);h.postRun.length;){var c=h.postRun.shift();oe.push(c)}he(`postRun`),ct(oe)}}if(0<Q)te=He;else{if(Pt(),Ht(),h.preRun)for(typeof h.preRun==`function`&&(h.preRun=[h.preRun]);h.preRun.length;)Xt();he(`preRun`),ct(se),0<Q?te=He:(h.setStatus?(h.setStatus(`Running...`),setTimeout(()=>{setTimeout(()=>h.setStatus(``),1),e()},1)):e(),ie())}}if(h.preInit)for(typeof h.preInit==`function`&&(h.preInit=[h.preInit]);0<h.preInit.length;)h.preInit.shift()();he(`preInit`),He(),m=y;for(let c of Object.keys(h))c in u||Object.defineProperty(u,c,{configurable:!0,get(){A(`Access to module property ('${c}') is no longer possible via the module constructor argument; Instead, use the result of the module constructor.`)}});return m}})());function freeWasm(c){c.delete()}var oe=1,se=2,le=4,de=8,fe=15;function portSideToConnDir(c){switch(c){case`NORTH`:return oe;case`SOUTH`:return se;case`EAST`:return de;case`WEST`:return le;default:return fe}}function applyRoutingParameters(c,u,m){let h=u.RoutingParameter,g=[[`segmentPenalty`,h.segmentPenalty],[`anglePenalty`,h.anglePenalty],[`crossingPenalty`,h.crossingPenalty],[`clusterCrossingPenalty`,h.clusterCrossingPenalty],[`fixedSharedPathPenalty`,h.fixedSharedPathPenalty],[`portDirectionPenalty`,h.portDirectionPenalty],[`shapeBufferDistance`,h.shapeBufferDistance],[`idealNudgingDistance`,h.idealNudgingDistance],[`reverseDirectionPenalty`,h.reverseDirectionPenalty]];for(let[u,h]of g){let g=m[u];typeof g==`number`&&c.setRoutingParameter(h,g)}let v=u.RoutingOption,y=[[`nudgeOrthogonalSegmentsConnectedToShapes`,v.nudgeOrthogonalSegmentsConnectedToShapes],[`nudgeOrthogonalTouchingColinearSegments`,v.nudgeOrthogonalTouchingColinearSegments],[`performUnifyingNudgingPreprocessingStep`,v.performUnifyingNudgingPreprocessingStep],[`nudgeSharedPathsWithCommonEndPoint`,v.nudgeSharedPathsWithCommonEndPoint]];for(let[u,h]of y){let g=m[u];typeof g==`boolean`&&c.setRoutingOption(h,g)}}function registerNodeShapes(c,u,m,h,g){let v=new Map,y=new Map,S=new Map;for(let[w,T]of c.nodes){if(T.parentId===null||T.hasChildren&&!g.has(w))continue;let c=new u.Point(T.x,T.y),E=new u.Point(T.x+T.width,T.y+T.height),D=new u.Rectangle(c,E),k=new u.ShapeRef(m,D);freeWasm(c),freeWasm(E),freeWasm(D),v.set(w,{node:T,shapeRef:k}),h.has(w)&&registerAutoPins(k,u),registerPortPins(T.ports,T,k,u,y,S)}return{portPinClassIds:S,shapes:v}}var pe=[.2,.4,.6,.8];function registerAutoPins(c,u){for(let m of pe)for(let[h,g,v]of[[0,m,le],[1,m,de],[m,0,oe],[m,1,se]])new u.ShapeConnectionPin(c,1,h,g,!0,0,v).setExclusive(!1)}function registerPortPins(c,u,m,h,g,v){for(let y of c){let c=g.get(u.id)??2;g.set(u.id,c+1),v.set(y.id,c);let S=Math.max(0,Math.min(1,(y.x+y.width/2-u.x)/u.width)),w=Math.max(0,Math.min(1,(y.y+y.height/2-u.y)/u.height)),T=portSideToConnDir(y.side);new h.ShapeConnectionPin(m,c,S,w,!0,0,T).setExclusive(!1)}}function registerEdgeConnectors(c,u,m,h,g){let v=new Map;for(let y of c.edges){let c=h.get(y.sourceNodeId),S=h.get(y.targetNodeId);if(!c)throw Error(`Edge "${y.id}": source node "${y.sourceNodeId}" has no corresponding shape`);if(!S)throw Error(`Edge "${y.id}": target node "${y.targetNodeId}" has no corresponding shape`);let w=y.sourcePortId?g.get(y.sourcePortId):1,T=y.targetPortId?g.get(y.targetPortId):1;if(w===void 0)throw Error(`Edge "${y.id}": source port "${y.sourcePortId}" has no pin class`);if(T===void 0)throw Error(`Edge "${y.id}": target port "${y.targetPortId}" has no pin class`);let E=new u.ConnEnd(c.shapeRef,w),D=new u.ConnEnd(S.shapeRef,T),k=new u.ConnRef(m,E,D);freeWasm(E),freeWasm(D),v.set(y.id,{connRef:k,edge:y})}return v}function createLibavoidSession(c,u,m={}){let h=(m.routingType??`orthogonal`)===`polyline`?u.RouterFlag.PolyLineRouting.value:u.RouterFlag.OrthogonalRouting.value,g=new u.Router(h);try{applyRoutingParameters(g,u,m);let h=new Set,v=new Set;for(let u of c.edges)v.add(u.sourceNodeId),v.add(u.targetNodeId),u.sourcePortId||h.add(u.sourceNodeId),u.targetPortId||h.add(u.targetNodeId);let{shapes:y,portPinClassIds:S}=registerNodeShapes(c,u,g,h,v);return{avoid:u,connectors:registerEdgeConnectors(c,u,g,y,S),edgeEndpointNodes:v,nodes:c.nodes,portPinClassIds:S,router:g,shapes:y}}catch(c){throw g.delete(),c}}function extractRoutes(c){let u=new Map;for(let[m,{connRef:h}]of c.connectors){let c=h.displayRoute();try{let h=[];for(let u=0;u<c.size();u++){let m=c.at(u);try{h.push({x:m.x,y:m.y})}finally{freeWasm(m)}}u.set(m,h)}finally{freeWasm(c)}}return u}function destroySession(c){c.router.delete(),c.shapes.clear(),c.connectors.clear()}var me={EAST:`EAST`,NORTH:`NORTH`,SOUTH:`SOUTH`,WEST:`WEST`};function inferPortSide(c,u,m){let h=c.properties?.[`port.side`]??c.properties?.[`elk.port.side`];if(typeof h==`string`){let c=me[h.toUpperCase()];if(c)return c}let g=c.x??0,v=c.y??0,y=c.width??0,S=c.height??0,w=g+y/2,T=v+S/2,E=w,D=u-w,k=T,j=m-T,M=Math.min(E,D,k,j);return M===D?`EAST`:M===E?`WEST`:M===k?`NORTH`:`SOUTH`}function resolveEdgeEndpoint(c,u,m,h,g,v,y){if(c&&c.length>0){if(c.length>1)throw Error(`Edge "${v}": multiple ${y}s are not supported (got ${c.length})`);let u=c[0],m=g.get(u);if(m)return{nodeId:m.nodeId,portId:u};if(h.has(u))return{nodeId:u,portId:void 0};throw Error(`Edge "${v}": ${y} reference "${u}" not found as node or port`)}if(u){if(!h.has(u))throw Error(`Edge "${v}": ${y} node "${u}" not found`);if(m&&!g.has(m))throw Error(`Edge "${v}": ${y} port "${m}" not found`);return{nodeId:u,portId:m}}throw Error(`Edge "${v}": no ${y} specified (need source/target or sources/targets)`)}function validateNode(c,u){let{width:m,height:h}=c;if(u===null)return{height:h??0,width:m??0};if(m===void 0||h===void 0)throw Error(`Node "${c.id}" is missing width or height. All nodes must have dimensions.`);if(m<=0||h<=0)throw Error(`Node "${c.id}" has invalid dimensions (${m}x${h}). Width and height must be positive.`);if(c.x===void 0||c.y===void 0)throw Error(`Node "${c.id}" is missing x or y position. All non-root nodes must be positioned.`);return{height:h,width:m}}function resolvePorts(c,u,m,h,g,v){let y=[];if(!c.ports)return y;for(let S of c.ports){let w=S.x??0,T=S.y??0,E=S.width??0,D=S.height??0,k=inferPortSide(S,h,g),j={height:D,id:S.id,nodeId:c.id,side:k,width:E,x:u+w,y:m+T};if(y.push(j),v.has(S.id))throw Error(`Duplicate port ID "${S.id}" found in graph`);v.set(S.id,j)}return y}function resolvePadding(c){return{bottom:c.padding?.bottom??0,left:c.padding?.left??0,right:c.padding?.right??0,top:c.padding?.top??0}}function resolveEdges(c,u,m,h,g){if(c.edges)for(let v of c.edges){if(g.has(v.id))throw Error(`Duplicate edge ID "${v.id}" found in graph`);g.add(v.id);let y=resolveEdgeEndpoint(v.sources,v.source,v.sourcePort,u,m,v.id,`source`),S=resolveEdgeEndpoint(v.targets,v.target,v.targetPort,u,m,v.id,`target`);if(u.get(y.nodeId)?.parentId===null)throw Error(`Edge "${v.id}": source node "${y.nodeId}" is the root node and cannot be an edge endpoint`);if(u.get(S.nodeId)?.parentId===null)throw Error(`Edge "${v.id}": target node "${S.nodeId}" is the root node and cannot be an edge endpoint`);h.push({elkEdgeRef:v,id:v.id,ownerNodeId:c.id,sourceNodeId:y.nodeId,sourcePortId:y.portId,targetNodeId:S.nodeId,targetPortId:S.portId})}}function parseElkGraph(c){let u=new Map,m=new Map,h=[],g=new Set;function visitNode(c,v,y,S){let w=v+(c.x??0),T=y+(c.y??0),{width:E,height:D}=validateNode(c,S),k=resolvePorts(c,w,T,E,D,m),j=resolvePadding(c);if(u.has(c.id))throw Error(`Duplicate node ID "${c.id}" found in graph`);if(u.set(c.id,{hasChildren:(c.children?.length??0)>0,height:D,id:c.id,padding:j,parentId:S,ports:k,width:E,x:w,y:T}),c.children){let u=w+(c.padding?.left??0),m=T+(c.padding?.top??0);for(let h of c.children)visitNode(h,u,m,c.id)}resolveEdges(c,u,m,h,g)}return visitNode(c,0,0,null),{edges:h,nodes:u,ports:m}}function inferSide(c,u,m){let h=u.x-c.x,g=u.y-c.y;return h===0&&g===0?m?`west`:`east`:Math.abs(h)>=Math.abs(g)?h>0==!m?`east`:`west`:g>0==!m?`south`:`north`}function buildRouteResults(c){let u=new Map;for(let[m,h]of c){if(h.length<2)continue;let c=inferSide(h[0],h[1],!1),g=inferSide(h[h.length-2],h[h.length-1],!0);u.set(m,{bendPoints:h.length>2?h.slice(1,-1):[],sourcePoint:h[0],sourceSide:c,targetPoint:h[h.length-1],targetSide:g})}return u}var ge=null,ye;async function init(c){return ge?c!==void 0&&c!==ye&&console.warn(`elkjs-libavoid: init() already called with a different wasmPath ("${ye}"). The new path ("${c}") will be ignored.`):(ye=c,ge=ae.load(c).catch(u=>{throw ge=null,ye=void 0,isBrowserEnvironment()&&!c?wrapBrowserWasmError(u):u})),ge}function isBrowserEnvironment(){return typeof globalThis<`u`&&`document`in globalThis}function wrapBrowserWasmError(c){let u=c instanceof Error?c.message:String(c);return u.includes(`file://`)||u.includes(`locateFile`)||u.includes(`fetch`)?Error(`In browser environments, you must call init('/path/to/libavoid.wasm') with a URL that serves the WASM file. Copy libavoid.wasm from node_modules/libavoid-js/dist/libavoid.wasm to your public directory.`):c instanceof Error?c:Error(String(c))}function generateSelfLoopRoute(c,u,m,h,g){let v=c+m,y=u+h*.4,S=u+h*.6,w=v+g*3,T=u-g*2;return{points:[{x:v,y},{x:w,y},{x:w,y:T},{x:v,y:T},{x:v,y:S}],sourceSide:`east`,targetSide:`east`}}function partitionEdges(c,u){let m;if(u){let h=new Set(u);m=c.filter(c=>h.has(c.id))}else m=c;let h=[],g=[];for(let c of m)c.sourceNodeId===c.targetNodeId?g.push(c):h.push(c);return{normalEdges:h,selfLoopEdges:g}}function buildSelfLoopResults(c,u,m){let h=new Map;for(let g of c){let c=u.nodes.get(g.sourceNodeId);if(!c)continue;let v=generateSelfLoopRoute(c.x,c.y,c.width,c.height,m);h.set(g.id,{bendPoints:v.points.slice(1,-1),sourcePoint:v.points[0],sourceSide:v.sourceSide,targetPoint:v.points[v.points.length-1],targetSide:v.targetSide})}return h}function validateGraph(c){if(!c||typeof c!=`object`)throw Error(`Invalid graph: expected an ELK JSON graph object, got ${typeof c}`);if(!(`id`in c)||typeof c.id!=`string`)throw Error(`Invalid graph: missing required "id" property of type string`)}async function executeRouting(c,u){validateGraph(c),await init();let m=ae.getInstance(),h=parseElkGraph(c);if(h.edges.length===0)return{parsed:h,rawRoutes:new Map,selfLoopEdges:[]};let{normalEdges:g,selfLoopEdges:v}=partitionEdges(h.edges,u?.edgeIds),y=new Map;if(g.length>0){let c=createLibavoidSession({...h,edges:g},m,u);try{c.router.processTransaction(),y=extractRoutes(c)}finally{destroySession(c)}}return{parsed:h,rawRoutes:y,selfLoopEdges:v}}async function routeEdges(c,u){let{parsed:m,rawRoutes:h,selfLoopEdges:g}=await executeRouting(c,u),v=buildRouteResults(h);if((u?.selfLoopHandling??`skip`)===`fallback`){let c=buildSelfLoopResults(g,m,u?.shapeBufferDistance??4);for(let[u,m]of c)v.set(u,m)}return v}var De=/^[a-z][a-z0-9+.-]*:/i;function buildBase(){return`./`}function assetUrl(c,u=buildBase()){return De.test(c)?c:`${u.endsWith(`/`)?u:`${u}/`}${c.replace(/^\/+/,``)}`}var je=class LayoutDeadlineError extends Error{limitMs;constructor(c){super(m(`app.editor.layoutTooSlow`,{seconds:String(Math.round(c/1e3))})),this.name=LayoutDeadlineError.name,this.limitMs=c}},Me=.4;function createBudget(c={}){let u=c.limitMs??15e3,m=c.now??(()=>performance.now()),h=m(),elapsed=()=>m()-h;return{limitMs:u,elapsed,remaining:()=>u-elapsed(),spare:()=>elapsed()<u*Me,check(){if(elapsed()>=u)throw new je(u)}}}var Pe=null;function activeBudget(){return Pe}var Fe=Promise.resolve();function withBudget(c,u){let m=Fe.then(async()=>{let m=createBudget(c);Pe=m;try{return await u(m)}finally{Pe=null}});return Fe=m.catch(()=>void 0),m}function checkBudget(){Pe?.check()}function hasSpare(){return!Pe||Pe.spare()}function yieldToHost(){return new Promise(c=>setTimeout(c,0))}var Ie=1500;function routingLoad(c){let u=new Map;for(let m of c)u.set(m.source,(u.get(m.source)??0)+1),u.set(m.target,(u.get(m.target)??0)+1);let m=Math.max(0,...u.values());if(c.length>Ie)return{edges:c.length,crossings:1/0,hub:m};let h=0;for(let u=0;u<c.length;u++)for(let m=u+1;m<c.length;m++)P(c[u].from,c[u].to,c[m].from,c[m].to)&&h++;return{edges:c.length,crossings:h,hub:m}}function estimateRouteMs(c,u,m){let h=.006*(c.edges+u)**2.4+.02*c.edges*c.crossings+1.5*c.edges*c.hub;return m?h*(1+c.crossings/3):h}var RouteTooCostly=class extends Error{},Le=u((c=>{Object.defineProperty(c,"__esModule",{value:!0});var u=function(){function PowerEdge(c,u,m){this.source=c,this.target=u,this.type=m}return PowerEdge}();c.PowerEdge=u;var m=function(){function Configuration(c,u,m,v){var y=this;if(this.linkAccessor=m,this.modules=Array(c),this.roots=[],v)this.initModulesFromGroup(v);else{this.roots.push(new g);for(var S=0;S<c;++S)this.roots[0].add(this.modules[S]=new h(S))}this.R=u.length,u.forEach(function(c){var u=y.modules[m.getSourceIndex(c)],h=y.modules[m.getTargetIndex(c)],g=m.getType(c);u.outgoing.add(g,h),h.incoming.add(g,u)})}return Configuration.prototype.initModulesFromGroup=function(c){var u=new g;this.roots.push(u);for(var m=0;m<c.leaves.length;++m){var y=c.leaves[m],S=new h(y.id);this.modules[y.id]=S,u.add(S)}if(c.groups)for(var w=0;w<c.groups.length;++w){var T=c.groups[w],E={};for(var D in T)D!==`leaves`&&D!==`groups`&&T.hasOwnProperty(D)&&(E[D]=T[D]);u.add(new h(-1-w,new v,new v,this.initModulesFromGroup(T),E))}return u},Configuration.prototype.merge=function(c,u,m){m===void 0&&(m=0);var v=c.incoming.intersection(u.incoming),y=c.outgoing.intersection(u.outgoing),S=new g;S.add(c),S.add(u);var w=new h(this.modules.length,y,v,S);this.modules.push(w);var update=function(m,h,g){m.forAll(function(m,v){m.forAll(function(m){var y=m[h];y.add(v,w),y.remove(v,c),y.remove(v,u),c[g].remove(v,m),u[g].remove(v,m)})})};return update(y,`incoming`,`outgoing`),update(v,`outgoing`,`incoming`),this.R-=v.count()+y.count(),this.roots[m].remove(c),this.roots[m].remove(u),this.roots[m].add(w),w},Configuration.prototype.rootMerges=function(c){c===void 0&&(c=0);for(var u=this.roots[c].modules(),m=u.length,h=Array(m*(m-1)),g=0,v=0,y=m-1;v<y;++v)for(var S=v+1;S<m;++S){var w=u[v],T=u[S];h[g]={id:g,nEdges:this.nEdges(w,T),a:w,b:T},g++}return h},Configuration.prototype.greedyMerge=function(){for(var c=0;c<this.roots.length;++c)if(!(this.roots[c].modules().length<2)){var u=this.rootMerges(c).sort(function(c,u){return c.nEdges==u.nEdges?c.id-u.id:c.nEdges-u.nEdges})[0];if(!(u.nEdges>=this.R))return this.merge(u.a,u.b,c),!0}},Configuration.prototype.nEdges=function(c,u){var m=c.incoming.intersection(u.incoming),h=c.outgoing.intersection(u.outgoing);return this.R-m.count()-h.count()},Configuration.prototype.getGroupHierarchy=function(c){var m=this,h=[];return toGroups(this.roots[0],{},h),this.allEdges().forEach(function(g){var v=m.modules[g.source],y=m.modules[g.target];c.push(new u(v.gid===void 0?g.source:h[v.gid],y.gid===void 0?g.target:h[y.gid],g.type))}),h},Configuration.prototype.allEdges=function(){var c=[];return Configuration.getEdges(this.roots[0],c),c},Configuration.getEdges=function(c,u){c.forAll(function(c){c.getEdges(u),Configuration.getEdges(c.children,u)})},Configuration}();c.Configuration=m;function toGroups(c,u,m){c.forAll(function(c){if(c.isLeaf())u.leaves||=[],u.leaves.push(c.id);else{var h=u;if(c.gid=m.length,!c.isIsland()||c.isPredefined()){if(h={id:c.gid},c.isPredefined())for(var g in c.definition)h[g]=c.definition[g];u.groups||=[],u.groups.push(c.gid),m.push(h)}toGroups(c.children,h,m)}})}var h=function(){function Module(c,u,m,h,y){u===void 0&&(u=new v),m===void 0&&(m=new v),h===void 0&&(h=new g),this.id=c,this.outgoing=u,this.incoming=m,this.children=h,this.definition=y}return Module.prototype.getEdges=function(c){var m=this;this.outgoing.forAll(function(h,g){h.forAll(function(h){c.push(new u(m.id,h.id,g))})})},Module.prototype.isLeaf=function(){return this.children.count()===0},Module.prototype.isIsland=function(){return this.outgoing.count()===0&&this.incoming.count()===0},Module.prototype.isPredefined=function(){return this.definition!==void 0},Module}();c.Module=h;function intersection(c,u){var m={};for(var h in c)h in u&&(m[h]=c[h]);return m}var g=function(){function ModuleSet(){this.table={}}return ModuleSet.prototype.count=function(){return Object.keys(this.table).length},ModuleSet.prototype.intersection=function(c){var u=new ModuleSet;return u.table=intersection(this.table,c.table),u},ModuleSet.prototype.intersectionCount=function(c){return this.intersection(c).count()},ModuleSet.prototype.contains=function(c){return c in this.table},ModuleSet.prototype.add=function(c){this.table[c.id]=c},ModuleSet.prototype.remove=function(c){delete this.table[c.id]},ModuleSet.prototype.forAll=function(c){for(var u in this.table)c(this.table[u])},ModuleSet.prototype.modules=function(){var c=[];return this.forAll(function(u){u.isPredefined()||c.push(u)}),c},ModuleSet}();c.ModuleSet=g;var v=function(){function LinkSets(){this.sets={},this.n=0}return LinkSets.prototype.count=function(){return this.n},LinkSets.prototype.contains=function(c){var u=!1;return this.forAllModules(function(m){!u&&m.id==c&&(u=!0)}),u},LinkSets.prototype.add=function(c,u){(c in this.sets?this.sets[c]:this.sets[c]=new g).add(u),++this.n},LinkSets.prototype.remove=function(c,u){var m=this.sets[c];m.remove(u),m.count()===0&&delete this.sets[c],--this.n},LinkSets.prototype.forAll=function(c){for(var u in this.sets)c(this.sets[u],Number(u))},LinkSets.prototype.forAllModules=function(c){this.forAll(function(u,m){return u.forAll(c)})},LinkSets.prototype.intersection=function(c){var u=new LinkSets;return this.forAll(function(m,h){if(h in c.sets){var g=m.intersection(c.sets[h]),v=g.count();v>0&&(u.sets[h]=g,u.n+=v)}}),u},LinkSets}();c.LinkSets=v;function getGroups(c,u,h,g){for(var v=c.length,y=new m(v,u,h,g);y.greedyMerge(););var S=[],w=y.getGroupHierarchy(S);return S.forEach(function(u){var f=function(m){var h=u[m];typeof h==`number`&&(u[m]=c[h])};f(`source`),f(`target`)}),{groups:w,powerEdges:S}}c.getGroups=getGroups})),ze=u((c=>{Object.defineProperty(c,"__esModule",{value:!0});function unionCount(c,u){var m={};for(var h in c)m[h]={};for(var h in u)m[h]={};return Object.keys(m).length}function intersectionCount(c,u){var m=0;for(var h in c)u[h]!==void 0&&++m;return m}function getNeighbours(c,u){var m={},addNeighbours=function(c,u){m[c]===void 0&&(m[c]={}),m[c][u]={}};return c.forEach(function(c){var m=u.getSourceIndex(c),h=u.getTargetIndex(c);addNeighbours(m,h),addNeighbours(h,m)}),m}function computeLinkLengths(c,u,m,h){var g=getNeighbours(c,h);c.forEach(function(c){var v=g[h.getSourceIndex(c)],y=g[h.getTargetIndex(c)];h.setLength(c,1+u*m(v,y))})}function symmetricDiffLinkLengths(c,u,m){m===void 0&&(m=1),computeLinkLengths(c,m,function(c,u){return Math.sqrt(unionCount(c,u)-intersectionCount(c,u))},u)}c.symmetricDiffLinkLengths=symmetricDiffLinkLengths;function jaccardLinkLengths(c,u,m){m===void 0&&(m=1),computeLinkLengths(c,m,function(c,u){return Math.min(Object.keys(c).length,Object.keys(u).length)<1.1?0:intersectionCount(c,u)/unionCount(c,u)},u)}c.jaccardLinkLengths=jaccardLinkLengths;function generateDirectedEdgeConstraints(c,u,m,h){var g=stronglyConnectedComponents(c,u,h),v={};g.forEach(function(c,u){return c.forEach(function(c){return v[c]=u})});var y=[];return u.forEach(function(c){var u=h.getSourceIndex(c),g=h.getTargetIndex(c);v[u]!==v[g]&&y.push({axis:m,left:u,right:g,gap:h.getMinSeparation(c)})}),y}c.generateDirectedEdgeConstraints=generateDirectedEdgeConstraints;function stronglyConnectedComponents(c,u,m){var h=[],g=0,v=[],y=[];function strongConnect(c){c.index=c.lowlink=g++,v.push(c),c.onStack=!0;for(var u=0,m=c.out;u<m.length;u++){var h=m[u];h.index===void 0?(strongConnect(h),c.lowlink=Math.min(c.lowlink,h.lowlink)):h.onStack&&(c.lowlink=Math.min(c.lowlink,h.index))}if(c.lowlink===c.index){for(var S=[];v.length&&(h=v.pop(),h.onStack=!1,S.push(h),h!==c););y.push(S.map(function(c){return c.id}))}}for(var S=0;S<c;S++)h.push({id:S,out:[]});for(var w=0,T=u;w<T.length;w++){var E=T[w],D=h[m.getSourceIndex(E)],k=h[m.getTargetIndex(E)];D.out.push(k)}for(var j=0,M=h;j<M.length;j++){var N=M[j];N.index===void 0&&strongConnect(N)}return y}c.stronglyConnectedComponents=stronglyConnectedComponents})),Be=u((c=>{Object.defineProperty(c,"__esModule",{value:!0});var u=function(){function Locks(){this.locks={}}return Locks.prototype.add=function(c,u){this.locks[c]=u},Locks.prototype.clear=function(){this.locks={}},Locks.prototype.isEmpty=function(){for(var c in this.locks)return!1;return!0},Locks.prototype.apply=function(c){for(var u in this.locks)c(Number(u),this.locks[u])},Locks}();c.Locks=u,c.Descent=function(){function Descent(c,h,g){g===void 0&&(g=null),this.D=h,this.G=g,this.threshold=1e-4,this.numGridSnapNodes=0,this.snapGridSize=100,this.snapStrength=1e3,this.scaleSnapByMaxH=!1,this.random=new m,this.project=null,this.x=c,this.k=c.length;var v=this.n=c[0].length;this.H=Array(this.k),this.g=Array(this.k),this.Hd=Array(this.k),this.a=Array(this.k),this.b=Array(this.k),this.c=Array(this.k),this.d=Array(this.k),this.e=Array(this.k),this.ia=Array(this.k),this.ib=Array(this.k),this.xtmp=Array(this.k),this.locks=new u,this.minD=Number.MAX_VALUE;for(var y=v,S;y--;)for(S=v;--S>y;){var w=h[y][S];w>0&&w<this.minD&&(this.minD=w)}for(this.minD===Number.MAX_VALUE&&(this.minD=1),y=this.k;y--;){for(this.g[y]=Array(v),this.H[y]=Array(v),S=v;S--;)this.H[y][S]=Array(v);this.Hd[y]=Array(v),this.a[y]=Array(v),this.b[y]=Array(v),this.c[y]=Array(v),this.d[y]=Array(v),this.e[y]=Array(v),this.ia[y]=Array(v),this.ib[y]=Array(v),this.xtmp[y]=Array(v)}}return Descent.createSquareMatrix=function(c,u){for(var m=Array(c),h=0;h<c;++h){m[h]=Array(c);for(var g=0;g<c;++g)m[h][g]=u(h,g)}return m},Descent.prototype.offsetDir=function(){for(var c=this,u=Array(this.k),m=0,h=0;h<this.k;++h){var g=u[h]=this.random.getNextBetween(.01,1)-.5;m+=g*g}return m=Math.sqrt(m),u.map(function(u){return u*=c.minD/m})},Descent.prototype.computeDerivatives=function(c){var u=this,m=this.n;if(!(m<1)){for(var h,g=Array(this.k),v=Array(this.k),y=Array(this.k),S=0,w=0;w<m;++w){for(h=0;h<this.k;++h)y[h]=this.g[h][w]=0;for(var T=0;T<m;++T)if(w!==T){for(var E=m;E--;){var D=0;for(h=0;h<this.k;++h){var k=g[h]=c[h][w]-c[h][T];D+=v[h]=k*k}if(D>1e-9)break;var j=this.offsetDir();for(h=0;h<this.k;++h)c[h][T]+=j[h]}var M=Math.sqrt(D),N=this.D[w][T],P=this.G==null?1:this.G[w][T];if(P>1&&M>N||!isFinite(N))for(h=0;h<this.k;++h)this.H[h][w][T]=0;else{P>1&&(P=1);var I=N*N,L=2*P*(M-N)/(I*M),z=M*M*M,B=2*-P/(I*z);for(isFinite(L)||console.log(L),h=0;h<this.k;++h)this.g[h][w]+=g[h]*L,y[h]-=this.H[h][w][T]=B*(z+N*(v[h]-D)+M*D)}}for(h=0;h<this.k;++h)S=Math.max(S,this.H[h][w][w]=y[h])}for(var V=this.snapGridSize/2,H=this.snapGridSize,U=this.snapStrength/(V*V),W=this.numGridSnapNodes,w=0;w<W;++w)for(h=0;h<this.k;++h){var ee=this.x[h][w],G=ee/H,K=G%1,Z=G-K,k=Math.abs(K)<=.5?ee-Z*H:ee>0?ee-(Z+1)*H:ee-(Z-1)*H;-V<k&&k<=V&&(this.scaleSnapByMaxH?(this.g[h][w]+=S*U*k,this.H[h][w][w]+=S*U):(this.g[h][w]+=U*k,this.H[h][w][w]+=U))}this.locks.isEmpty()||this.locks.apply(function(m,g){for(h=0;h<u.k;++h)u.H[h][m][m]+=S,u.g[h][m]-=S*(g[h]-c[h][m])})}},Descent.dotProd=function(c,u){for(var m=0,h=c.length;h--;)m+=c[h]*u[h];return m},Descent.rightMultiply=function(c,u,m){for(var h=c.length;h--;)m[h]=Descent.dotProd(c[h],u)},Descent.prototype.computeStepSize=function(c){for(var u=0,m=0,h=0;h<this.k;++h)u+=Descent.dotProd(this.g[h],c[h]),Descent.rightMultiply(this.H[h],c[h],this.Hd[h]),m+=Descent.dotProd(c[h],this.Hd[h]);return m===0||!isFinite(m)?0:1*u/m},Descent.prototype.reduceStress=function(){this.computeDerivatives(this.x);for(var c=this.computeStepSize(this.g),u=0;u<this.k;++u)this.takeDescentStep(this.x[u],this.g[u],c);return this.computeStress()},Descent.copy=function(c,u){for(var m=c.length,h=u[0].length,g=0;g<m;++g)for(var v=0;v<h;++v)u[g][v]=c[g][v]},Descent.prototype.stepAndProject=function(c,u,m,h){Descent.copy(c,u),this.takeDescentStep(u[0],m[0],h),this.project&&this.project[0](c[0],c[1],u[0]),this.takeDescentStep(u[1],m[1],h),this.project&&this.project[1](u[0],c[1],u[1]);for(var g=2;g<this.k;g++)this.takeDescentStep(u[g],m[g],h)},Descent.mApply=function(c,u,m){for(var h=c;h-->0;)for(var g=u;g-->0;)m(h,g)},Descent.prototype.matrixApply=function(c){Descent.mApply(this.k,this.n,c)},Descent.prototype.computeNextPosition=function(c,u){var m=this;this.computeDerivatives(c);var h=this.computeStepSize(this.g);if(this.stepAndProject(c,u,this.g,h),this.project){this.matrixApply(function(h,g){return m.e[h][g]=c[h][g]-u[h][g]});var g=this.computeStepSize(this.e);g=Math.max(.2,Math.min(g,1)),this.stepAndProject(c,u,this.e,g)}},Descent.prototype.run=function(c){for(var u=Number.MAX_VALUE,m=!1;!m&&c-->0;){var h=this.rungeKutta();m=Math.abs(u/h-1)<this.threshold,u=h}return u},Descent.prototype.rungeKutta=function(){var c=this;this.computeNextPosition(this.x,this.a),Descent.mid(this.x,this.a,this.ia),this.computeNextPosition(this.ia,this.b),Descent.mid(this.x,this.b,this.ib),this.computeNextPosition(this.ib,this.c),this.computeNextPosition(this.c,this.d);var u=0;return this.matrixApply(function(m,h){var g=(c.a[m][h]+2*c.b[m][h]+2*c.c[m][h]+c.d[m][h])/6,v=c.x[m][h]-g;u+=v*v,c.x[m][h]=g}),u},Descent.mid=function(c,u,m){Descent.mApply(c.length,c[0].length,function(h,g){return m[h][g]=c[h][g]+(u[h][g]-c[h][g])/2})},Descent.prototype.takeDescentStep=function(c,u,m){for(var h=0;h<this.n;++h)c[h]=c[h]-m*u[h]},Descent.prototype.computeStress=function(){for(var c=0,u=0,m=this.n-1;u<m;++u)for(var h=u+1,g=this.n;h<g;++h){for(var v=0,y=0;y<this.k;++y){var S=this.x[y][u]-this.x[y][h];v+=S*S}v=Math.sqrt(v);var w=this.D[u][h];if(isFinite(w)){var T=w-v,E=w*w;c+=T*T/E}}return c},Descent.zeroDistance=1e-10,Descent}();var m=function(){function PseudoRandom(c){c===void 0&&(c=1),this.seed=c,this.a=214013,this.c=2531011,this.m=2147483648,this.range=32767}return PseudoRandom.prototype.getNext=function(){return this.seed=(this.seed*this.a+this.c)%this.m,(this.seed>>16)/this.range},PseudoRandom.prototype.getNextBetween=function(c,u){return c+this.getNext()*(u-c)},PseudoRandom}();c.PseudoRandom=m})),Ge=u((c=>{Object.defineProperty(c,"__esModule",{value:!0});var u=function(){function PositionStats(c){this.scale=c,this.AB=0,this.AD=0,this.A2=0}return PositionStats.prototype.addVariable=function(c){var u=this.scale/c.scale,m=c.offset/c.scale,h=c.weight;this.AB+=h*u*m,this.AD+=h*u*c.desiredPosition,this.A2+=h*u*u},PositionStats.prototype.getPosn=function(){return(this.AD-this.AB)/this.A2},PositionStats}();c.PositionStats=u;var m=function(){function Constraint(c,u,m,h){h===void 0&&(h=!1),this.left=c,this.right=u,this.gap=m,this.equality=h,this.active=!1,this.unsatisfiable=!1,this.left=c,this.right=u,this.gap=m,this.equality=h}return Constraint.prototype.slack=function(){return this.unsatisfiable?Number.MAX_VALUE:this.right.scale*this.right.position()-this.gap-this.left.scale*this.left.position()},Constraint}();c.Constraint=m;var h=function(){function Variable(c,u,m){u===void 0&&(u=1),m===void 0&&(m=1),this.desiredPosition=c,this.weight=u,this.scale=m,this.offset=0}return Variable.prototype.dfdv=function(){return 2*this.weight*(this.position()-this.desiredPosition)},Variable.prototype.position=function(){return(this.block.ps.scale*this.block.posn+this.offset)/this.scale},Variable.prototype.visitNeighbours=function(c,u){var ff=function(m,h){return m.active&&c!==h&&u(m,h)};this.cOut.forEach(function(c){return ff(c,c.right)}),this.cIn.forEach(function(c){return ff(c,c.left)})},Variable}();c.Variable=h;var g=function(){function Block(c){this.vars=[],c.offset=0,this.ps=new u(c.scale),this.addVariable(c)}return Block.prototype.addVariable=function(c){c.block=this,this.vars.push(c),this.ps.addVariable(c),this.posn=this.ps.getPosn()},Block.prototype.updateWeightedPosition=function(){this.ps.AB=this.ps.AD=this.ps.A2=0;for(var c=0,u=this.vars.length;c<u;++c)this.ps.addVariable(this.vars[c]);this.posn=this.ps.getPosn()},Block.prototype.compute_lm=function(c,u,m){var h=this,g=c.dfdv();return c.visitNeighbours(u,function(u,v){var y=h.compute_lm(v,c,m);v===u.right?(g+=y*u.left.scale,u.lm=y):(g+=y*u.right.scale,u.lm=-y),m(u)}),g/c.scale},Block.prototype.populateSplitBlock=function(c,u){var m=this;c.visitNeighbours(u,function(u,h){h.offset=c.offset+(h===u.right?u.gap:-u.gap),m.addVariable(h),m.populateSplitBlock(h,c)})},Block.prototype.traverse=function(c,u,m,h){var g=this;m===void 0&&(m=this.vars[0]),h===void 0&&(h=null),m.visitNeighbours(h,function(h,v){u.push(c(h)),g.traverse(c,u,v,m)})},Block.prototype.findMinLM=function(){var c=null;return this.compute_lm(this.vars[0],null,function(u){!u.equality&&(c===null||u.lm<c.lm)&&(c=u)}),c},Block.prototype.findMinLMBetween=function(c,u){this.compute_lm(c,null,function(){});var m=null;return this.findPath(c,null,u,function(c,u){!c.equality&&c.right===u&&(m===null||c.lm<m.lm)&&(m=c)}),m},Block.prototype.findPath=function(c,u,m,h){var g=this,v=!1;return c.visitNeighbours(u,function(u,y){!v&&(y===m||g.findPath(y,c,m,h))&&(v=!0,h(u,y))}),v},Block.prototype.isActiveDirectedPathBetween=function(c,u){if(c===u)return!0;for(var m=c.cOut.length;m--;){var h=c.cOut[m];if(h.active&&this.isActiveDirectedPathBetween(h.right,u))return!0}return!1},Block.split=function(c){return c.active=!1,[Block.createSplitBlock(c.left),Block.createSplitBlock(c.right)]},Block.createSplitBlock=function(c){var u=new Block(c);return u.populateSplitBlock(c,null),u},Block.prototype.splitBetween=function(c,u){var m=this.findMinLMBetween(c,u);if(m!==null){var h=Block.split(m);return{constraint:m,lb:h[0],rb:h[1]}}return null},Block.prototype.mergeAcross=function(c,u,m){u.active=!0;for(var h=0,g=c.vars.length;h<g;++h){var v=c.vars[h];v.offset+=m,this.addVariable(v)}this.posn=this.ps.getPosn()},Block.prototype.cost=function(){for(var c=0,u=this.vars.length;u--;){var m=this.vars[u],h=m.position()-m.desiredPosition;c+=h*h*m.weight}return c},Block}();c.Block=g;var v=function(){function Blocks(c){this.vs=c;var u=c.length;for(this.list=Array(u);u--;){var m=new g(c[u]);this.list[u]=m,m.blockInd=u}}return Blocks.prototype.cost=function(){for(var c=0,u=this.list.length;u--;)c+=this.list[u].cost();return c},Blocks.prototype.insert=function(c){c.blockInd=this.list.length,this.list.push(c)},Blocks.prototype.remove=function(c){var u=this.list.length-1,m=this.list[u];this.list.length=u,c!==m&&(this.list[c.blockInd]=m,m.blockInd=c.blockInd)},Blocks.prototype.merge=function(c){var u=c.left.block,m=c.right.block,h=c.right.offset-c.left.offset-c.gap;u.vars.length<m.vars.length?(m.mergeAcross(u,c,h),this.remove(u)):(u.mergeAcross(m,c,-h),this.remove(m))},Blocks.prototype.forEach=function(c){this.list.forEach(c)},Blocks.prototype.updateBlockPositions=function(){this.list.forEach(function(c){return c.updateWeightedPosition()})},Blocks.prototype.split=function(c){var u=this;this.updateBlockPositions(),this.list.forEach(function(m){var h=m.findMinLM();h!==null&&h.lm<y.LAGRANGIAN_TOLERANCE&&(m=h.left.block,g.split(h).forEach(function(c){return u.insert(c)}),u.remove(m),c.push(h))})},Blocks}();c.Blocks=v;var y=function(){function Solver(c,u){this.vs=c,this.cs=u,this.vs=c,c.forEach(function(c){c.cIn=[],c.cOut=[]}),this.cs=u,u.forEach(function(c){c.left.cOut.push(c),c.right.cIn.push(c)}),this.inactive=u.map(function(c){return c.active=!1,c}),this.bs=null}return Solver.prototype.cost=function(){return this.bs.cost()},Solver.prototype.setStartingPositions=function(c){this.inactive=this.cs.map(function(c){return c.active=!1,c}),this.bs=new v(this.vs),this.bs.forEach(function(u,m){return u.posn=c[m]})},Solver.prototype.setDesiredPositions=function(c){this.vs.forEach(function(u,m){return u.desiredPosition=c[m]})},Solver.prototype.mostViolated=function(){for(var c=Number.MAX_VALUE,u=null,m=this.inactive,h=m.length,g=h,v=0;v<h;++v){var y=m[v];if(!y.unsatisfiable){var S=y.slack();if((y.equality||S<c)&&(c=S,u=y,g=v,y.equality))break}}return g!==h&&(c<Solver.ZERO_UPPERBOUND&&!u.active||u.equality)&&(m[g]=m[h-1],m.length=h-1),u},Solver.prototype.satisfy=function(){this.bs??=new v(this.vs),this.bs.split(this.inactive);for(var c=null;(c=this.mostViolated())&&(c.equality||c.slack()<Solver.ZERO_UPPERBOUND&&!c.active);){var u=c.left.block;if(u!==c.right.block)this.bs.merge(c);else{if(u.isActiveDirectedPathBetween(c.right,c.left)){c.unsatisfiable=!0;continue}var m=u.splitBetween(c.left,c.right);if(m!==null)this.bs.insert(m.lb),this.bs.insert(m.rb),this.bs.remove(u),this.inactive.push(m.constraint);else{c.unsatisfiable=!0;continue}c.slack()>=0?this.inactive.push(c):this.bs.merge(c)}}},Solver.prototype.solve=function(){this.satisfy();for(var c=Number.MAX_VALUE,u=this.bs.cost();Math.abs(c-u)>1e-4;)this.satisfy(),c=u,u=this.bs.cost();return u},Solver.LAGRANGIAN_TOLERANCE=-1e-4,Solver.ZERO_UPPERBOUND=-1e-10,Solver}();c.Solver=y;function removeOverlapInOneDimension(c,u,g){for(var v=c.map(function(c){return new h(c.desiredCenter)}),S=[],w=c.length,T=0;T<w-1;T++){var E=c[T],D=c[T+1];S.push(new m(v[T],v[T+1],(E.size+D.size)/2))}var k=v[0],j=v[w-1],M=c[0].size/2,N=c[w-1].size/2,P=null,I=null;return u&&(P=new h(u,k.weight*1e3),v.push(P),S.push(new m(P,k,M))),g&&(I=new h(g,j.weight*1e3),v.push(I),S.push(new m(j,I,N))),new y(v,S).solve(),{newCenters:v.slice(0,c.length).map(function(c){return c.position()}),lowerBound:P?P.position():k.position()-M,upperBound:I?I.position():j.position()+N}}c.removeOverlapInOneDimension=removeOverlapInOneDimension})),Ke=u(((c,u,m)=>{var h=m&&m.__extends||(function(){var extendStatics=function(c,u){return extendStatics=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(c,u){c.__proto__=u}||function(c,u){for(var m in u)u.hasOwnProperty(m)&&(c[m]=u[m])},extendStatics(c,u)};return function(c,u){extendStatics(c,u);function __(){this.constructor=c}c.prototype=u===null?Object.create(u):(__.prototype=u.prototype,new __)}})();Object.defineProperty(c,"__esModule",{value:!0});var g=function(){function TreeBase(){this.findIter=function(c){for(var u=this._root,m=this.iterator();u!==null;){var h=this._comparator(c,u.data);if(h===0)return m._cursor=u,m;m._ancestors.push(u),u=u.get_child(h>0)}return null}}return TreeBase.prototype.clear=function(){this._root=null,this.size=0},TreeBase.prototype.find=function(c){for(var u=this._root;u!==null;){var m=this._comparator(c,u.data);if(m===0)return u.data;u=u.get_child(m>0)}return null},TreeBase.prototype.lowerBound=function(c){return this._bound(c,this._comparator)},TreeBase.prototype.upperBound=function(c){var u=this._comparator;function reverse_cmp(c,m){return u(m,c)}return this._bound(c,reverse_cmp)},TreeBase.prototype.min=function(){var c=this._root;if(c===null)return null;for(;c.left!==null;)c=c.left;return c.data},TreeBase.prototype.max=function(){var c=this._root;if(c===null)return null;for(;c.right!==null;)c=c.right;return c.data},TreeBase.prototype.iterator=function(){return new v(this)},TreeBase.prototype.each=function(c){for(var u=this.iterator(),m;(m=u.next())!==null;)c(m)},TreeBase.prototype.reach=function(c){for(var u=this.iterator(),m;(m=u.prev())!==null;)c(m)},TreeBase.prototype._bound=function(c,u){for(var m=this._root,h=this.iterator();m!==null;){var g=this._comparator(c,m.data);if(g===0)return h._cursor=m,h;h._ancestors.push(m),m=m.get_child(g>0)}for(var v=h._ancestors.length-1;v>=0;--v)if(m=h._ancestors[v],u(c,m.data)>0)return h._cursor=m,h._ancestors.length=v,h;return h._ancestors.length=0,h},TreeBase}();c.TreeBase=g;var v=function(){function Iterator(c){this._tree=c,this._ancestors=[],this._cursor=null}return Iterator.prototype.data=function(){return this._cursor===null?null:this._cursor.data},Iterator.prototype.next=function(){if(this._cursor===null){var c=this._tree._root;c!==null&&this._minNode(c)}else if(this._cursor.right===null){var u;do if(u=this._cursor,this._ancestors.length)this._cursor=this._ancestors.pop();else{this._cursor=null;break}while(this._cursor.right===u)}else this._ancestors.push(this._cursor),this._minNode(this._cursor.right);return this._cursor===null?null:this._cursor.data},Iterator.prototype.prev=function(){if(this._cursor===null){var c=this._tree._root;c!==null&&this._maxNode(c)}else if(this._cursor.left===null){var u;do if(u=this._cursor,this._ancestors.length)this._cursor=this._ancestors.pop();else{this._cursor=null;break}while(this._cursor.left===u)}else this._ancestors.push(this._cursor),this._maxNode(this._cursor.left);return this._cursor===null?null:this._cursor.data},Iterator.prototype._minNode=function(c){for(;c.left!==null;)this._ancestors.push(c),c=c.left;this._cursor=c},Iterator.prototype._maxNode=function(c){for(;c.right!==null;)this._ancestors.push(c),c=c.right;this._cursor=c},Iterator}();c.Iterator=v;var y=function(){function Node(c){this.data=c,this.left=null,this.right=null,this.red=!0}return Node.prototype.get_child=function(c){return c?this.right:this.left},Node.prototype.set_child=function(c,u){c?this.right=u:this.left=u},Node}();c.RBTree=function(c){h(RBTree,c);function RBTree(u){var m=c.call(this)||this;return m._root=null,m._comparator=u,m.size=0,m}return RBTree.prototype.insert=function(c){var u=!1;if(this._root===null)this._root=new y(c),u=!0,this.size++;else{var m=new y(void 0),h=!1,g=!1,v=null,S=m,w=null,T=this._root;for(S.right=this._root;;){if(T===null?(T=new y(c),w.set_child(h,T),u=!0,this.size++):RBTree.is_red(T.left)&&RBTree.is_red(T.right)&&(T.red=!0,T.left.red=!1,T.right.red=!1),RBTree.is_red(T)&&RBTree.is_red(w)){var E=S.right===v;T===w.get_child(g)?S.set_child(E,RBTree.single_rotate(v,!g)):S.set_child(E,RBTree.double_rotate(v,!g))}var D=this._comparator(T.data,c);if(D===0)break;g=h,h=D<0,v!==null&&(S=v),v=w,w=T,T=T.get_child(h)}this._root=m.right}return this._root.red=!1,u},RBTree.prototype.remove=function(c){if(this._root===null)return!1;var u=new y(void 0),m=u;m.right=this._root;for(var h=null,g=null,v=null,S=!0;m.get_child(S)!==null;){var w=S;g=h,h=m,m=m.get_child(S);var T=this._comparator(c,m.data);if(S=T>0,T===0&&(v=m),!RBTree.is_red(m)&&!RBTree.is_red(m.get_child(S))){if(RBTree.is_red(m.get_child(!S))){var E=RBTree.single_rotate(m,S);h.set_child(w,E),h=E}else if(!RBTree.is_red(m.get_child(!S))){var D=h.get_child(!w);if(D!==null){if(!RBTree.is_red(D.get_child(!w))&&!RBTree.is_red(D.get_child(w)))h.red=!1,D.red=!0,m.red=!0;else{var k=g.right===h;RBTree.is_red(D.get_child(w))?g.set_child(k,RBTree.double_rotate(h,w)):RBTree.is_red(D.get_child(!w))&&g.set_child(k,RBTree.single_rotate(h,w));var j=g.get_child(k);j.red=!0,m.red=!0,j.left.red=!1,j.right.red=!1}}}}}return v!==null&&(v.data=m.data,h.set_child(h.right===m,m.get_child(m.left===null)),this.size--),this._root=u.right,this._root!==null&&(this._root.red=!1),v!==null},RBTree.is_red=function(c){return c!==null&&c.red},RBTree.single_rotate=function(c,u){var m=c.get_child(!u);return c.set_child(!u,m.get_child(u)),m.set_child(u,c),c.red=!0,m.red=!1,m},RBTree.double_rotate=function(c,u){return c.set_child(!u,RBTree.single_rotate(c.get_child(!u),!u)),RBTree.single_rotate(c,u)},RBTree}(g)})),qe=u(((c,u,m)=>{var h=m&&m.__extends||(function(){var extendStatics=function(c,u){return extendStatics=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(c,u){c.__proto__=u}||function(c,u){for(var m in u)u.hasOwnProperty(m)&&(c[m]=u[m])},extendStatics(c,u)};return function(c,u){extendStatics(c,u);function __(){this.constructor=c}c.prototype=u===null?Object.create(u):(__.prototype=u.prototype,new __)}})();Object.defineProperty(c,"__esModule",{value:!0});var g=Ge(),v=Ke();function computeGroupBounds(c){return c.bounds=c.leaves===void 0?y.empty():c.leaves.reduce(function(c,u){return u.bounds.union(c)},y.empty()),c.groups!==void 0&&(c.bounds=c.groups.reduce(function(c,u){return computeGroupBounds(u).union(c)},c.bounds)),c.bounds=c.bounds.inflate(c.padding),c.bounds}c.computeGroupBounds=computeGroupBounds;var y=function(){function Rectangle(c,u,m,h){this.x=c,this.X=u,this.y=m,this.Y=h}return Rectangle.empty=function(){return new Rectangle(1/0,-1/0,1/0,-1/0)},Rectangle.prototype.cx=function(){return(this.x+this.X)/2},Rectangle.prototype.cy=function(){return(this.y+this.Y)/2},Rectangle.prototype.overlapX=function(c){var u=this.cx(),m=c.cx();return u<=m&&c.x<this.X?this.X-c.x:m<=u&&this.x<c.X?c.X-this.x:0},Rectangle.prototype.overlapY=function(c){var u=this.cy(),m=c.cy();return u<=m&&c.y<this.Y?this.Y-c.y:m<=u&&this.y<c.Y?c.Y-this.y:0},Rectangle.prototype.setXCentre=function(c){var u=c-this.cx();this.x+=u,this.X+=u},Rectangle.prototype.setYCentre=function(c){var u=c-this.cy();this.y+=u,this.Y+=u},Rectangle.prototype.width=function(){return this.X-this.x},Rectangle.prototype.height=function(){return this.Y-this.y},Rectangle.prototype.union=function(c){return new Rectangle(Math.min(this.x,c.x),Math.max(this.X,c.X),Math.min(this.y,c.y),Math.max(this.Y,c.Y))},Rectangle.prototype.lineIntersections=function(c,u,m,h){for(var g=[[this.x,this.y,this.X,this.y],[this.X,this.y,this.X,this.Y],[this.X,this.Y,this.x,this.Y],[this.x,this.Y,this.x,this.y]],v=[],y=0;y<4;++y){var S=Rectangle.lineIntersection(c,u,m,h,g[y][0],g[y][1],g[y][2],g[y][3]);S!==null&&v.push({x:S.x,y:S.y})}return v},Rectangle.prototype.rayIntersection=function(c,u){var m=this.lineIntersections(this.cx(),this.cy(),c,u);return m.length>0?m[0]:null},Rectangle.prototype.vertices=function(){return[{x:this.x,y:this.y},{x:this.X,y:this.y},{x:this.X,y:this.Y},{x:this.x,y:this.Y}]},Rectangle.lineIntersection=function(c,u,m,h,g,v,y,S){var w=m-c,T=y-g,E=h-u,D=S-v,k=D*w-T*E;if(k==0)return null;var j=c-g,M=u-v,N=(T*M-D*j)/k,P=(w*M-E*j)/k;return N>=0&&N<=1&&P>=0&&P<=1?{x:c+N*w,y:u+N*E}:null},Rectangle.prototype.inflate=function(c){return new Rectangle(this.x-c,this.X+c,this.y-c,this.Y+c)},Rectangle}();c.Rectangle=y;function makeEdgeBetween(c,u,m){var h=c.rayIntersection(u.cx(),u.cy())||{x:c.cx(),y:c.cy()},g=u.rayIntersection(c.cx(),c.cy())||{x:u.cx(),y:u.cy()},v=g.x-h.x,y=g.y-h.y,S=Math.sqrt(v*v+y*y),w=S-m;return{sourceIntersection:h,targetIntersection:g,arrowStart:{x:h.x+w*v/S,y:h.y+w*y/S}}}c.makeEdgeBetween=makeEdgeBetween;function makeEdgeTo(c,u,m){var h=u.rayIntersection(c.x,c.y);h||={x:u.cx(),y:u.cy()};var g=h.x-c.x,v=h.y-c.y,y=Math.sqrt(g*g+v*v);return{x:h.x-m*g/y,y:h.y-m*v/y}}c.makeEdgeTo=makeEdgeTo;var S=function(){function Node(c,u,m){this.v=c,this.r=u,this.pos=m,this.prev=makeRBTree(),this.next=makeRBTree()}return Node}(),w=function(){function Event(c,u,m){this.isOpen=c,this.v=u,this.pos=m}return Event}();function compareEvents(c,u){return c.pos>u.pos?1:c.pos<u.pos||c.isOpen?-1:+!!u.isOpen}function makeRBTree(){return new v.RBTree(function(c,u){return c.pos-u.pos})}var T={getCentre:function(c){return c.cx()},getOpen:function(c){return c.y},getClose:function(c){return c.Y},getSize:function(c){return c.width()},makeRect:function(c,u,m,h){return new y(m-h/2,m+h/2,c,u)},findNeighbours:findXNeighbours},E={getCentre:function(c){return c.cy()},getOpen:function(c){return c.x},getClose:function(c){return c.X},getSize:function(c){return c.height()},makeRect:function(c,u,m,h){return new y(c,u,m-h/2,m+h/2)},findNeighbours:findYNeighbours};function generateGroupConstraints(c,u,m,h){h===void 0&&(h=!1);var g=c.padding,v=c.groups===void 0?0:c.groups.length,y=c.leaves===void 0?0:c.leaves.length,S=v?c.groups.reduce(function(c,h){return c.concat(generateGroupConstraints(h,u,m,!0))},[]):[],w=(h?2:0)+y+v,T=Array(w),E=Array(w),D=0,add=function(c,u){E[D]=c,T[D++]=u};if(h){var k=c.bounds,j=u.getCentre(k),M=u.getSize(k)/2,N=u.getOpen(k),P=u.getClose(k),I=j-M+g/2,L=j+M-g/2;c.minVar.desiredPosition=I,add(u.makeRect(N,P,I,g),c.minVar),c.maxVar.desiredPosition=L,add(u.makeRect(N,P,L,g),c.maxVar)}y&&c.leaves.forEach(function(c){return add(c.bounds,c.variable)}),v&&c.groups.forEach(function(c){var m=c.bounds;add(u.makeRect(u.getOpen(m),u.getClose(m),u.getCentre(m),u.getSize(m)),c.minVar)});var z=generateConstraints(E,T,u,m);return v&&(T.forEach(function(c){c.cOut=[],c.cIn=[]}),z.forEach(function(c){c.left.cOut.push(c),c.right.cIn.push(c)}),c.groups.forEach(function(c){var m=(c.padding-u.getSize(c.bounds))/2;c.minVar.cIn.forEach(function(c){return c.gap+=m}),c.minVar.cOut.forEach(function(u){u.left=c.maxVar,u.gap+=m})})),S.concat(z)}function generateConstraints(c,u,m,h){var v,y=c.length,T=2*y;console.assert(u.length>=y);var E=Array(T);for(v=0;v<y;++v){var D=c[v],k=new S(u[v],D,m.getCentre(D));E[v]=new w(!0,k,m.getOpen(D)),E[v+y]=new w(!1,k,m.getClose(D))}E.sort(compareEvents);var j=[],M=makeRBTree();for(v=0;v<T;++v){var N=E[v],k=N.v;if(N.isOpen)M.insert(k),m.findNeighbours(k,M);else{M.remove(k);var makeConstraint=function(c,u){var v=(m.getSize(c.r)+m.getSize(u.r))/2+h;j.push(new g.Constraint(c.v,u.v,v))},visitNeighbours=function(c,u,m){for(var h,g=k[c].iterator();(h=g[c]())!==null;)m(h,k),h[u].remove(k)};visitNeighbours(`prev`,`next`,function(c,u){return makeConstraint(c,u)}),visitNeighbours(`next`,`prev`,function(c,u){return makeConstraint(u,c)})}}return console.assert(M.size===0),j}function findXNeighbours(c,u){var f=function(m,h){for(var g=u.findIter(c),v;(v=g[m]())!==null;){var y=v.r.overlapX(c.r);if((y<=0||y<=v.r.overlapY(c.r))&&(c[m].insert(v),v[h].insert(c)),y<=0)break}};f(`next`,`prev`),f(`prev`,`next`)}function findYNeighbours(c,u){var f=function(m,h){var g=u.findIter(c)[m]();g!==null&&g.r.overlapX(c.r)>0&&(c[m].insert(g),g[h].insert(c))};f(`next`,`prev`),f(`prev`,`next`)}function generateXConstraints(c,u){return generateConstraints(c,u,T,1e-6)}c.generateXConstraints=generateXConstraints;function generateYConstraints(c,u){return generateConstraints(c,u,E,1e-6)}c.generateYConstraints=generateYConstraints;function generateXGroupConstraints(c){return generateGroupConstraints(c,T,1e-6)}c.generateXGroupConstraints=generateXGroupConstraints;function generateYGroupConstraints(c){return generateGroupConstraints(c,E,1e-6)}c.generateYGroupConstraints=generateYGroupConstraints;function removeOverlaps(c){var u=c.map(function(c){return new g.Variable(c.cx())}),m=generateXConstraints(c,u),h=new g.Solver(u,m);h.solve(),u.forEach(function(u,m){return c[m].setXCentre(u.position())}),u=c.map(function(c){return new g.Variable(c.cy())}),m=generateYConstraints(c,u),h=new g.Solver(u,m),h.solve(),u.forEach(function(u,m){return c[m].setYCentre(u.position())})}c.removeOverlaps=removeOverlaps;var D=function(c){h(IndexedVariable,c);function IndexedVariable(u,m){var h=c.call(this,0,m)||this;return h.index=u,h}return IndexedVariable}(g.Variable);c.IndexedVariable=D,c.Projection=function(){function Projection(c,u,m,h,g){var v=this;if(m===void 0&&(m=null),h===void 0&&(h=null),g===void 0&&(g=!1),this.nodes=c,this.groups=u,this.rootGroup=m,this.avoidOverlaps=g,this.variables=c.map(function(c,u){return c.variable=new D(u,1)}),h&&this.createConstraints(h),g&&m&&m.groups!==void 0){c.forEach(function(c){if(!c.width||!c.height)c.bounds=new y(c.x,c.x,c.y,c.y);else{var u=c.width/2,m=c.height/2;c.bounds=new y(c.x-u,c.x+u,c.y-m,c.y+m)}}),computeGroupBounds(m);var S=c.length;u.forEach(function(c){v.variables[S]=c.minVar=new D(S++,c.stiffness===void 0?.01:c.stiffness),v.variables[S]=c.maxVar=new D(S++,c.stiffness===void 0?.01:c.stiffness)})}}return Projection.prototype.createSeparation=function(c){return new g.Constraint(this.nodes[c.left].variable,this.nodes[c.right].variable,c.gap,c.equality!==void 0&&c.equality)},Projection.prototype.makeFeasible=function(c){var u=this;if(this.avoidOverlaps){var m=`x`,h=`width`;c.axis===`x`&&(m=`y`,h=`height`);var g=c.offsets.map(function(c){return u.nodes[c.node]}).sort(function(c,u){return c[m]-u[m]}),v=null;g.forEach(function(c){if(v){var u=v[m]+v[h];u>c[m]&&(c[m]=u)}v=c})}},Projection.prototype.createAlignment=function(c){var u=this,m=this.nodes[c.offsets[0].node].variable;this.makeFeasible(c);var h=c.axis===`x`?this.xConstraints:this.yConstraints;c.offsets.slice(1).forEach(function(c){var v=u.nodes[c.node].variable;h.push(new g.Constraint(m,v,c.offset,!0))})},Projection.prototype.createConstraints=function(c){var u=this,isSep=function(c){return c.type===void 0||c.type===`separation`};this.xConstraints=c.filter(function(c){return c.axis===`x`&&isSep(c)}).map(function(c){return u.createSeparation(c)}),this.yConstraints=c.filter(function(c){return c.axis===`y`&&isSep(c)}).map(function(c){return u.createSeparation(c)}),c.filter(function(c){return c.type===`alignment`}).forEach(function(c){return u.createAlignment(c)})},Projection.prototype.setupVariablesAndBounds=function(c,u,m,h){this.nodes.forEach(function(g,v){g.fixed?(g.variable.weight=g.fixedWeight?g.fixedWeight:1e3,m[v]=h(g)):g.variable.weight=1;var S=(g.width||0)/2,w=(g.height||0)/2,T=c[v],E=u[v];g.bounds=new y(T-S,T+S,E-w,E+w)})},Projection.prototype.xProject=function(c,u,m){(this.rootGroup||this.avoidOverlaps||this.xConstraints)&&this.project(c,u,c,m,function(c){return c.px},this.xConstraints,generateXGroupConstraints,function(c){return c.bounds.setXCentre(m[c.variable.index]=c.variable.position())},function(c){var u=m[c.minVar.index]=c.minVar.position(),h=m[c.maxVar.index]=c.maxVar.position(),g=c.padding/2;c.bounds.x=u-g,c.bounds.X=h+g})},Projection.prototype.yProject=function(c,u,m){(this.rootGroup||this.yConstraints)&&this.project(c,u,u,m,function(c){return c.py},this.yConstraints,generateYGroupConstraints,function(c){return c.bounds.setYCentre(m[c.variable.index]=c.variable.position())},function(c){var u=m[c.minVar.index]=c.minVar.position(),h=m[c.maxVar.index]=c.maxVar.position(),g=c.padding/2;c.bounds.y=u-g,c.bounds.Y=h+g})},Projection.prototype.projectFunctions=function(){var c=this;return[function(u,m,h){return c.xProject(u,m,h)},function(u,m,h){return c.yProject(u,m,h)}]},Projection.prototype.project=function(c,u,m,h,g,v,y,S,w){this.setupVariablesAndBounds(c,u,h,g),this.rootGroup&&this.avoidOverlaps&&(computeGroupBounds(this.rootGroup),v=v.concat(y(this.rootGroup))),this.solve(this.variables,v,m,h),this.nodes.forEach(S),this.rootGroup&&this.avoidOverlaps&&(this.groups.forEach(w),computeGroupBounds(this.rootGroup))},Projection.prototype.solve=function(c,u,m,h){var v=new g.Solver(c,u);v.setStartingPositions(m),v.setDesiredPositions(h),v.solve()},Projection}()})),Je=u((c=>{Object.defineProperty(c,"__esModule",{value:!0});var u=function(){function PairingHeap(c){this.elem=c,this.subheaps=[]}return PairingHeap.prototype.toString=function(c){for(var u=``,m=!1,h=0;h<this.subheaps.length;++h){var g=this.subheaps[h];g.elem?(m&&(u+=`,`),u+=g.toString(c),m=!0):m=!1}return u!==``&&(u=`(`+u+`)`),(this.elem?c(this.elem):``)+u},PairingHeap.prototype.forEach=function(c){this.empty()||(c(this.elem,this),this.subheaps.forEach(function(u){return u.forEach(c)}))},PairingHeap.prototype.count=function(){return this.empty()?0:1+this.subheaps.reduce(function(c,u){return c+u.count()},0)},PairingHeap.prototype.min=function(){return this.elem},PairingHeap.prototype.empty=function(){return this.elem==null},PairingHeap.prototype.contains=function(c){if(this===c)return!0;for(var u=0;u<this.subheaps.length;u++)if(this.subheaps[u].contains(c))return!0;return!1},PairingHeap.prototype.isHeap=function(c){var u=this;return this.subheaps.every(function(m){return c(u.elem,m.elem)&&m.isHeap(c)})},PairingHeap.prototype.insert=function(c,u){return this.merge(new PairingHeap(c),u)},PairingHeap.prototype.merge=function(c,u){return this.empty()?c:c.empty()?this:u(this.elem,c.elem)?(this.subheaps.push(c),this):(c.subheaps.push(this),c)},PairingHeap.prototype.removeMin=function(c){return this.empty()?null:this.mergePairs(c)},PairingHeap.prototype.mergePairs=function(c){if(this.subheaps.length==0)return new PairingHeap(null);if(this.subheaps.length==1)return this.subheaps[0];var u=this.subheaps.pop().merge(this.subheaps.pop(),c),m=this.mergePairs(c);return u.merge(m,c)},PairingHeap.prototype.decreaseKey=function(c,u,m,h){var g=c.removeMin(h);c.elem=g.elem,c.subheaps=g.subheaps,m!==null&&g.elem!==null&&m(c.elem,c);var v=new PairingHeap(u);return m!==null&&m(u,v),this.merge(v,h)},PairingHeap}();c.PairingHeap=u,c.PriorityQueue=function(){function PriorityQueue(c){this.lessThan=c}return PriorityQueue.prototype.top=function(){return this.empty()?null:this.root.elem},PriorityQueue.prototype.push=function(){for(var c=[...arguments],m,h=0,g;g=c[h];++h)m=new u(g),this.root=this.empty()?m:this.root.merge(m,this.lessThan);return m},PriorityQueue.prototype.empty=function(){return!this.root||!this.root.elem},PriorityQueue.prototype.isHeap=function(){return this.root.isHeap(this.lessThan)},PriorityQueue.prototype.forEach=function(c){this.root.forEach(c)},PriorityQueue.prototype.pop=function(){if(this.empty())return null;var c=this.root.min();return this.root=this.root.removeMin(this.lessThan),c},PriorityQueue.prototype.reduceKey=function(c,u,m){m===void 0&&(m=null),this.root=this.root.decreaseKey(c,u,m,this.lessThan)},PriorityQueue.prototype.toString=function(c){return this.root.toString(c)},PriorityQueue.prototype.count=function(){return this.root.count()},PriorityQueue}()})),Xe=u((c=>{Object.defineProperty(c,"__esModule",{value:!0});var u=Je(),m=function(){function Neighbour(c,u){this.id=c,this.distance=u}return Neighbour}(),h=function(){function Node(c){this.id=c,this.neighbours=[]}return Node}(),g=function(){function QueueEntry(c,u,m){this.node=c,this.prev=u,this.d=m}return QueueEntry}();c.Calculator=function(){function Calculator(c,u,g,v,y){this.n=c,this.es=u,this.neighbours=Array(this.n);for(var S=this.n;S--;)this.neighbours[S]=new h(S);for(S=this.es.length;S--;){var w=this.es[S],T=g(w),E=v(w),D=y(w);this.neighbours[T].neighbours.push(new m(E,D)),this.neighbours[E].neighbours.push(new m(T,D))}}return Calculator.prototype.DistanceMatrix=function(){for(var c=Array(this.n),u=0;u<this.n;++u)c[u]=this.dijkstraNeighbours(u);return c},Calculator.prototype.DistancesFromNode=function(c){return this.dijkstraNeighbours(c)},Calculator.prototype.PathFromNodeToNode=function(c,u){return this.dijkstraNeighbours(c,u)},Calculator.prototype.PathFromNodeToNodeWithPrevCost=function(c,m,h){var v=new u.PriorityQueue(function(c,u){return c.d<=u.d}),y=this.neighbours[c],S=new g(y,null,0),w={};for(v.push(S);!v.empty()&&(S=v.pop(),y=S.node,y.id!==m);)for(var T=y.neighbours.length;T--;){var E=y.neighbours[T],D=this.neighbours[E.id];if(!(S.prev&&D.id===S.prev.node.id)){var k=D.id+`,`+y.id;if(!(k in w&&w[k]<=S.d)){var j=S.prev?h(S.prev.node.id,y.id,D.id):0,M=S.d+E.distance+j;w[k]=M,v.push(new g(D,S,M))}}}for(var N=[];S.prev;)S=S.prev,N.push(S.node.id);return N},Calculator.prototype.dijkstraNeighbours=function(c,m){m===void 0&&(m=-1);for(var h=new u.PriorityQueue(function(c,u){return c.d<=u.d}),g=this.neighbours.length,v=Array(g);g--;){var y=this.neighbours[g];y.d=g===c?0:1/0,y.q=h.push(y)}for(;!h.empty();){var S=h.pop();if(v[S.id]=S.d,S.id===m){for(var w=[],T=S;T.prev!==void 0;)w.push(T.prev.id),T=T.prev;return w}for(g=S.neighbours.length;g--;){var E=S.neighbours[g],T=this.neighbours[E.id],D=S.d+E.distance;S.d!==Number.MAX_VALUE&&T.d>D&&(T.d=D,T.prev=S,h.reduceKey(T.q,T,function(c,u){return c.q=u}))}}return v},Calculator}()})),Qe=u(((c,u,m)=>{var h=m&&m.__extends||(function(){var extendStatics=function(c,u){return extendStatics=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(c,u){c.__proto__=u}||function(c,u){for(var m in u)u.hasOwnProperty(m)&&(c[m]=u[m])},extendStatics(c,u)};return function(c,u){extendStatics(c,u);function __(){this.constructor=c}c.prototype=u===null?Object.create(u):(__.prototype=u.prototype,new __)}})();Object.defineProperty(c,"__esModule",{value:!0});var g=qe(),v=function(){function Point(){}return Point}();c.Point=v;var y=function(){function LineSegment(c,u,m,h){this.x1=c,this.y1=u,this.x2=m,this.y2=h}return LineSegment}();c.LineSegment=y,c.PolyPoint=function(c){h(PolyPoint,c);function PolyPoint(){return c!==null&&c.apply(this,arguments)||this}return PolyPoint}(v);function isLeft(c,u,m){return(u.x-c.x)*(m.y-c.y)-(m.x-c.x)*(u.y-c.y)}c.isLeft=isLeft;function above(c,u,m){return isLeft(c,u,m)>0}function below(c,u,m){return isLeft(c,u,m)<0}function ConvexHull(c){var u=c.slice(0).sort(function(c,u){return c.x===u.x?u.y-c.y:u.x-c.x}),m=c.length,h,g=0,v=u[0].x;for(h=1;h<m&&u[h].x===v;++h);var y=h-1,S=[];if(S.push(u[g]),y===m-1)u[y].y!==u[g].y&&S.push(u[y]);else{var w,T=m-1,E=u[m-1].x;for(h=m-2;h>=0&&u[h].x===E;h--);for(w=h+1,h=y;++h<=w;)if(!(isLeft(u[g],u[w],u[h])>=0&&h<w)){for(;S.length>1&&!(isLeft(S[S.length-2],S[S.length-1],u[h])>0);)--S.length;h!=g&&S.push(u[h])}T!=w&&S.push(u[T]);var D=S.length;for(h=w;--h>=y;)if(!(isLeft(u[T],u[y],u[h])>=0&&h>y)){for(;S.length>D&&!(isLeft(S[S.length-2],S[S.length-1],u[h])>0);)--S.length;h!=g&&S.push(u[h])}}return S}c.ConvexHull=ConvexHull;function clockwiseRadialSweep(c,u,m){u.slice(0).sort(function(u,m){return Math.atan2(u.y-c.y,u.x-c.x)-Math.atan2(m.y-c.y,m.x-c.x)}).forEach(m)}c.clockwiseRadialSweep=clockwiseRadialSweep;function tangent_PointPolyC(c,u){var m=u.slice(0);return m.push(u[0]),{rtan:Rtangent_PointPolyC(c,m),ltan:Ltangent_PointPolyC(c,m)}}function Rtangent_PointPolyC(c,u){var m=u.length-1,h,g,v,y,S;if(below(c,u[1],u[0])&&!above(c,u[m-1],u[0]))return 0;for(h=0,g=m;;){if(g-h===1)return above(c,u[h],u[g])?h:g;if(v=Math.floor((h+g)/2),S=below(c,u[v+1],u[v]),S&&!above(c,u[v-1],u[v]))return v;y=above(c,u[h+1],u[h]),y?S||above(c,u[h],u[v])?g=v:h=v:S&&below(c,u[h],u[v])?g=v:h=v}}function Ltangent_PointPolyC(c,u){var m=u.length-1,h,g,v,y,S;if(above(c,u[m-1],u[0])&&!below(c,u[1],u[0]))return 0;for(h=0,g=m;;){if(g-h===1)return below(c,u[h],u[g])?h:g;if(v=Math.floor((h+g)/2),S=below(c,u[v+1],u[v]),above(c,u[v-1],u[v])&&!S)return v;y=below(c,u[h+1],u[h]),y?S?below(c,u[h],u[v])?g=v:h=v:g=v:S?h=v:above(c,u[h],u[v])?g=v:h=v}}function tangent_PolyPolyC(c,u,m,h,g,v){for(var y=m(u[0],c),S=h(c[y],u),w=!1;!w;){for(w=!0;y===c.length-1&&(y=0),!g(u[S],c[y],c[y+1]);)++y;for(;S===0&&(S=u.length-1),!v(c[y],u[S],u[S-1]);)--S,w=!1}return{t1:y,t2:S}}c.tangent_PolyPolyC=tangent_PolyPolyC;function LRtangent_PolyPolyC(c,u){var m=RLtangent_PolyPolyC(u,c);return{t1:m.t2,t2:m.t1}}c.LRtangent_PolyPolyC=LRtangent_PolyPolyC;function RLtangent_PolyPolyC(c,u){return tangent_PolyPolyC(c,u,Rtangent_PointPolyC,Ltangent_PointPolyC,above,below)}c.RLtangent_PolyPolyC=RLtangent_PolyPolyC;function LLtangent_PolyPolyC(c,u){return tangent_PolyPolyC(c,u,Ltangent_PointPolyC,Ltangent_PointPolyC,below,below)}c.LLtangent_PolyPolyC=LLtangent_PolyPolyC;function RRtangent_PolyPolyC(c,u){return tangent_PolyPolyC(c,u,Rtangent_PointPolyC,Rtangent_PointPolyC,above,above)}c.RRtangent_PolyPolyC=RRtangent_PolyPolyC;var S=function(){function BiTangent(c,u){this.t1=c,this.t2=u}return BiTangent}();c.BiTangent=S;var w=function(){function BiTangents(){}return BiTangents}();c.BiTangents=w,c.TVGPoint=function(c){h(TVGPoint,c);function TVGPoint(){return c!==null&&c.apply(this,arguments)||this}return TVGPoint}(v);var T=function(){function VisibilityVertex(c,u,m,h){this.id=c,this.polyid=u,this.polyvertid=m,this.p=h,h.vv=this}return VisibilityVertex}();c.VisibilityVertex=T;var E=function(){function VisibilityEdge(c,u){this.source=c,this.target=u}return VisibilityEdge.prototype.length=function(){var c=this.source.p.x-this.target.p.x,u=this.source.p.y-this.target.p.y;return Math.sqrt(c*c+u*u)},VisibilityEdge}();c.VisibilityEdge=E,c.TangentVisibilityGraph=function(){function TangentVisibilityGraph(c,u){if(this.P=c,this.V=[],this.E=[],u)this.V=u.V.slice(0),this.E=u.E.slice(0);else{for(var m=c.length,h=0;h<m;h++){for(var g=c[h],v=0;v<g.length;++v){var y=g[v],S=new T(this.V.length,h,v,y);this.V.push(S),v>0&&this.E.push(new E(g[v-1].vv,S))}g.length>1&&this.E.push(new E(g[0].vv,g[g.length-1].vv))}for(var h=0;h<m-1;h++)for(var w=c[h],v=h+1;v<m;v++){var D=c[v],k=tangents(w,D);for(var j in k){var M=k[j],N=w[M.t1],P=D[M.t2];this.addEdgeIfVisible(N,P,h,v)}}}}return TangentVisibilityGraph.prototype.addEdgeIfVisible=function(c,u,m,h){this.intersectsPolys(new y(c.x,c.y,u.x,u.y),m,h)||this.E.push(new E(c.vv,u.vv))},TangentVisibilityGraph.prototype.addPoint=function(c,u){var m=this.P.length;this.V.push(new T(this.V.length,m,0,c));for(var h=0;h<m;++h)if(h!==u){var g=this.P[h],v=tangent_PointPolyC(c,g);this.addEdgeIfVisible(c,g[v.ltan],u,h),this.addEdgeIfVisible(c,g[v.rtan],u,h)}return c.vv},TangentVisibilityGraph.prototype.intersectsPolys=function(c,u,m){for(var h=0,g=this.P.length;h<g;++h)if(h!=u&&h!=m&&intersects(c,this.P[h]).length>0)return!0;return!1},TangentVisibilityGraph}();function intersects(c,u){for(var m=[],h=1,v=u.length;h<v;++h){var y=g.Rectangle.lineIntersection(c.x1,c.y1,c.x2,c.y2,u[h-1].x,u[h-1].y,u[h].x,u[h].y);y&&m.push(y)}return m}function tangents(c,u){for(var m=c.length-1,h=u.length-1,g=new w,v=0;v<m;++v)for(var y=0;y<h;++y){var T=c[v==0?m-1:v-1],E=c[v],D=c[v+1],k=u[y==0?h-1:y-1],j=u[y],M=u[y+1],N=isLeft(T,E,j),P=isLeft(E,k,j),I=isLeft(E,j,M),L=isLeft(k,j,E),z=isLeft(j,T,E),B=isLeft(j,E,D);N>=0&&P>=0&&I<0&&L>=0&&z>=0&&B<0?g.ll=new S(v,y):N<=0&&P<=0&&I>0&&L<=0&&z<=0&&B>0?g.rr=new S(v,y):N<=0&&P>0&&I<=0&&L>=0&&z<0&&B>=0?g.rl=new S(v,y):N>=0&&P<0&&I>=0&&L<=0&&z>0&&B<=0&&(g.lr=new S(v,y))}return g}c.tangents=tangents;function isPointInsidePoly(c,u){for(var m=1,h=u.length;m<h;++m)if(below(u[m-1],u[m],c))return!1;return!0}function isAnyPInQ(c,u){return!c.every(function(c){return!isPointInsidePoly(c,u)})}function polysOverlap(c,u){if(isAnyPInQ(c,u)||isAnyPInQ(u,c))return!0;for(var m=1,h=c.length;m<h;++m){var g=c[m],v=c[m-1];if(intersects(new y(v.x,v.y,g.x,g.y),u).length>0)return!0}return!1}c.polysOverlap=polysOverlap})),$e=u((c=>{Object.defineProperty(c,"__esModule",{value:!0});var u={PADDING:10,GOLDEN_SECTION:(1+Math.sqrt(5))/2,FLOAT_EPSILON:1e-4,MAX_INERATIONS:100};function applyPacking(c,m,h,g,v,y){v===void 0&&(v=1),y===void 0&&(y=!0);var S=0,w=0,T=m,E=h,v=v===void 0?1:v,g=g===void 0?0:g,D=0,k=0,j=0,M=0,N=[];if(c.length==0)return;calculate_bb(c),apply(c,v),y&&put_nodes_to_right_positions(c);function calculate_bb(c){c.forEach(function(c){calculate_single_bb(c)});function calculate_single_bb(c){var u=Number.MAX_VALUE,m=Number.MAX_VALUE,h=0,v=0;c.array.forEach(function(c){var y=c.width===void 0?g:c.width,S=c.height===void 0?g:c.height;y/=2,S/=2,h=Math.max(c.x+y,h),u=Math.min(c.x-y,u),v=Math.max(c.y+S,v),m=Math.min(c.y-S,m)}),c.width=h-u,c.height=v-m}}function put_nodes_to_right_positions(c){c.forEach(function(c){var u={x:0,y:0};c.array.forEach(function(c){u.x+=c.x,u.y+=c.y}),u.x/=c.array.length,u.y/=c.array.length;var m={x:u.x-c.width/2,y:u.y-c.height/2},h={x:c.x-m.x+T/2-D/2,y:c.y-m.y+E/2-k/2};c.array.forEach(function(c){c.x+=h.x,c.y+=h.y})})}function apply(c,m){var h=1/0,g=0;c.sort(function(c,u){return u.height-c.height}),j=c.reduce(function(c,u){return c.width<u.width?c.width:u.width});for(var v=M=j,y=N=get_entire_width(c),S=0,w=Number.MAX_VALUE,T=Number.MAX_VALUE,E=-1,D=Number.MAX_VALUE,k=Number.MAX_VALUE;D>j||k>u.FLOAT_EPSILON;){if(E!=1)var M=y-(y-v)/u.GOLDEN_SECTION,w=step(c,M);if(E!=0)var N=v+(y-v)/u.GOLDEN_SECTION,T=step(c,N);if(D=Math.abs(M-N),k=Math.abs(w-T),w<h&&(h=w,g=M),T<h&&(h=T,g=N),w>T?(v=M,M=N,w=T,E=1):(y=N,N=M,T=w,E=0),S++>100)break}step(c,g)}function step(c,u){N=[],D=0,k=0,M=w;for(var m=0;m<c.length;m++){var h=c[m];put_rect(h,u)}return Math.abs(get_real_ratio()-v)}function put_rect(c,m){for(var h=void 0,g=0;g<N.length;g++)if(N[g].space_left>=c.height&&N[g].x+N[g].width+c.width+u.PADDING-m<=u.FLOAT_EPSILON){h=N[g];break}N.push(c),h===void 0?(c.y=M,M+=c.height+u.PADDING,c.x=S,c.bottom=c.y,c.space_left=c.height):(c.x=h.x+h.width+u.PADDING,c.y=h.bottom,c.space_left=c.height,c.bottom=c.y,h.space_left-=c.height+u.PADDING,h.bottom+=c.height+u.PADDING),c.y+c.height-k>-u.FLOAT_EPSILON&&(k=c.y+c.height-w),c.x+c.width-D>-u.FLOAT_EPSILON&&(D=c.x+c.width-S)}function get_entire_width(c){var m=0;return c.forEach(function(c){return m+=c.width+u.PADDING}),m}function get_real_ratio(){return D/k}}c.applyPacking=applyPacking;function separateGraphs(c,u){for(var m={},h={},g=[],v=0,y=0;y<u.length;y++){var S=u[y],w=S.source,T=S.target;h[w.index]?h[w.index].push(T):h[w.index]=[T],h[T.index]?h[T.index].push(w):h[T.index]=[w]}for(var y=0;y<c.length;y++){var E=c[y];m[E.index]||explore_node(E,!0)}function explore_node(c,u){if(m[c.index]===void 0){u&&(v++,g.push({array:[]})),m[c.index]=v,g[v-1].array.push(c);var y=h[c.index];if(y)for(var S=0;S<y.length;S++)explore_node(y[S],!1)}}return g}c.separateGraphs=separateGraphs})),et=u((c=>{Object.defineProperty(c,"__esModule",{value:!0});var u=Le(),m=ze(),h=Be(),g=qe(),v=Xe(),y=Qe(),S=$e(),w;(function(c){c[c.start=0]=`start`,c[c.tick=1]=`tick`,c[c.end=2]=`end`})(w=c.EventType||={});function isGroup(c){return c.leaves!==void 0||c.groups!==void 0}c.Layout=function(){function Layout(){var c=this;this._canvasSize=[1,1],this._linkDistance=20,this._defaultNodeSize=10,this._linkLengthCalculator=null,this._linkType=null,this._avoidOverlaps=!1,this._handleDisconnected=!0,this._running=!1,this._nodes=[],this._groups=[],this._rootGroup=null,this._links=[],this._constraints=[],this._distanceMatrix=null,this._descent=null,this._directedLinkConstraints=null,this._threshold=.01,this._visibilityGraph=null,this._groupCompactness=1e-6,this.event=null,this.linkAccessor={getSourceIndex:Layout.getSourceIndex,getTargetIndex:Layout.getTargetIndex,setLength:Layout.setLinkLength,getType:function(u){return typeof c._linkType==`function`?c._linkType(u):0}}}return Layout.prototype.on=function(c,u){return this.event||={},typeof c==`string`?this.event[w[c]]=u:this.event[c]=u,this},Layout.prototype.trigger=function(c){this.event&&this.event[c.type]!==void 0&&this.event[c.type](c)},Layout.prototype.kick=function(){for(;!this.tick(););},Layout.prototype.tick=function(){if(this._alpha<this._threshold)return this._running=!1,this.trigger({type:w.end,alpha:this._alpha=0,stress:this._lastStress}),!0;var c=this._nodes.length;this._links.length;var u,m;for(this._descent.locks.clear(),m=0;m<c;++m)if(u=this._nodes[m],u.fixed){(u.px===void 0||u.py===void 0)&&(u.px=u.x,u.py=u.y);var h=[u.px,u.py];this._descent.locks.add(m,h)}var g=this._descent.rungeKutta();return g===0?this._alpha=0:this._lastStress!==void 0&&(this._alpha=g),this._lastStress=g,this.updateNodePositions(),this.trigger({type:w.tick,alpha:this._alpha,stress:this._lastStress}),!1},Layout.prototype.updateNodePositions=function(){for(var c=this._descent.x[0],u=this._descent.x[1],m,h=this._nodes.length;h--;)m=this._nodes[h],m.x=c[h],m.y=u[h]},Layout.prototype.nodes=function(c){if(!c){if(this._nodes.length===0&&this._links.length>0){var u=0;this._links.forEach(function(c){u=Math.max(u,c.source,c.target)}),this._nodes=Array(++u);for(var m=0;m<u;++m)this._nodes[m]={}}return this._nodes}return this._nodes=c,this},Layout.prototype.groups=function(c){var u=this;return c?(this._groups=c,this._rootGroup={},this._groups.forEach(function(c){c.padding===void 0&&(c.padding=1),c.leaves!==void 0&&c.leaves.forEach(function(m,h){typeof m==`number`&&((c.leaves[h]=u._nodes[m]).parent=c)}),c.groups!==void 0&&c.groups.forEach(function(m,h){typeof m==`number`&&((c.groups[h]=u._groups[m]).parent=c)})}),this._rootGroup.leaves=this._nodes.filter(function(c){return c.parent===void 0}),this._rootGroup.groups=this._groups.filter(function(c){return c.parent===void 0}),this):this._groups},Layout.prototype.powerGraphGroups=function(c){var m=u.getGroups(this._nodes,this._links,this.linkAccessor,this._rootGroup);return this.groups(m.groups),c(m),this},Layout.prototype.avoidOverlaps=function(c){return arguments.length?(this._avoidOverlaps=c,this):this._avoidOverlaps},Layout.prototype.handleDisconnected=function(c){return arguments.length?(this._handleDisconnected=c,this):this._handleDisconnected},Layout.prototype.flowLayout=function(c,u){return arguments.length||(c=`y`),this._directedLinkConstraints={axis:c,getMinSeparation:typeof u==`number`?function(){return u}:u},this},Layout.prototype.links=function(c){return arguments.length?(this._links=c,this):this._links},Layout.prototype.constraints=function(c){return arguments.length?(this._constraints=c,this):this._constraints},Layout.prototype.distanceMatrix=function(c){return arguments.length?(this._distanceMatrix=c,this):this._distanceMatrix},Layout.prototype.size=function(c){return c?(this._canvasSize=c,this):this._canvasSize},Layout.prototype.defaultNodeSize=function(c){return c?(this._defaultNodeSize=c,this):this._defaultNodeSize},Layout.prototype.groupCompactness=function(c){return c?(this._groupCompactness=c,this):this._groupCompactness},Layout.prototype.linkDistance=function(c){return c?(this._linkDistance=typeof c==`function`?c:+c,this._linkLengthCalculator=null,this):this._linkDistance},Layout.prototype.linkType=function(c){return this._linkType=c,this},Layout.prototype.convergenceThreshold=function(c){return c?(this._threshold=typeof c==`function`?c:+c,this):this._threshold},Layout.prototype.alpha=function(c){return arguments.length?(c=+c,this._alpha?this._alpha=c>0?c:0:c>0&&(this._running||(this._running=!0,this.trigger({type:w.start,alpha:this._alpha=c}),this.kick())),this):this._alpha},Layout.prototype.getLinkLength=function(c){return typeof this._linkDistance==`function`?+this._linkDistance(c):this._linkDistance},Layout.setLinkLength=function(c,u){c.length=u},Layout.prototype.getLinkType=function(c){return typeof this._linkType==`function`?this._linkType(c):0},Layout.prototype.symmetricDiffLinkLengths=function(c,u){var h=this;return u===void 0&&(u=1),this.linkDistance(function(u){return c*u.length}),this._linkLengthCalculator=function(){return m.symmetricDiffLinkLengths(h._links,h.linkAccessor,u)},this},Layout.prototype.jaccardLinkLengths=function(c,u){var h=this;return u===void 0&&(u=1),this.linkDistance(function(u){return c*u.length}),this._linkLengthCalculator=function(){return m.jaccardLinkLengths(h._links,h.linkAccessor,u)},this},Layout.prototype.start=function(c,u,y,S,w,T){var E=this;c===void 0&&(c=0),u===void 0&&(u=0),y===void 0&&(y=0),S===void 0&&(S=0),w===void 0&&(w=!0),T===void 0&&(T=!0);var D,k=this.nodes().length,j=k+2*this._groups.length;this._links.length;var M=this._canvasSize[0],N=this._canvasSize[1],P=Array(j),I=Array(j),L=null,z=this._avoidOverlaps;this._nodes.forEach(function(c,u){c.index=u,c.x===void 0&&(c.x=M/2,c.y=N/2),P[u]=c.x,I[u]=c.y}),this._linkLengthCalculator&&this._linkLengthCalculator();var B;this._distanceMatrix?B=this._distanceMatrix:(B=new v.Calculator(j,this._links,Layout.getSourceIndex,Layout.getTargetIndex,function(c){return E.getLinkLength(c)}).DistanceMatrix(),L=h.Descent.createSquareMatrix(j,function(){return 2}),this._links.forEach(function(c){typeof c.source==`number`&&(c.source=E._nodes[c.source]),typeof c.target==`number`&&(c.target=E._nodes[c.target])}),this._links.forEach(function(c){var u=Layout.getSourceIndex(c),m=Layout.getTargetIndex(c);L[u][m]=L[m][u]=c.weight||1}));var V=h.Descent.createSquareMatrix(j,function(c,u){return B[c][u]});if(this._rootGroup&&this._rootGroup.groups!==void 0){var D=k,addAttraction=function(c,u,m,h){L[c][u]=L[u][c]=m,V[c][u]=V[u][c]=h};this._groups.forEach(function(c){addAttraction(D,D+1,E._groupCompactness,.1),P[D]=0,I[D++]=0,P[D]=0,I[D++]=0})}else this._rootGroup={leaves:this._nodes,groups:[]};var H=this._constraints||[];this._directedLinkConstraints&&(this.linkAccessor.getMinSeparation=this._directedLinkConstraints.getMinSeparation,H=H.concat(m.generateDirectedEdgeConstraints(k,this._links,this._directedLinkConstraints.axis,this.linkAccessor))),this.avoidOverlaps(!1),this._descent=new h.Descent([P,I],V),this._descent.locks.clear();for(var D=0;D<k;++D){var U=this._nodes[D];if(U.fixed){U.px=U.x,U.py=U.y;var W=[U.x,U.y];this._descent.locks.add(D,W)}}if(this._descent.threshold=this._threshold,this.initialLayout(c,P,I),H.length>0&&(this._descent.project=new g.Projection(this._nodes,this._groups,this._rootGroup,H).projectFunctions()),this._descent.run(u),this.separateOverlappingComponents(M,N,T),this.avoidOverlaps(z),z&&(this._nodes.forEach(function(c,u){c.x=P[u],c.y=I[u]}),this._descent.project=new g.Projection(this._nodes,this._groups,this._rootGroup,H,!0).projectFunctions(),this._nodes.forEach(function(c,u){P[u]=c.x,I[u]=c.y})),this._descent.G=L,this._descent.run(y),S){this._descent.snapStrength=1e3,this._descent.snapGridSize=this._nodes[0].width,this._descent.numGridSnapNodes=k,this._descent.scaleSnapByMaxH=k!=j;var ee=h.Descent.createSquareMatrix(j,function(c,u){return c>=k||u>=k?L[c][u]:0});this._descent.G=ee,this._descent.run(S)}return this.updateNodePositions(),this.separateOverlappingComponents(M,N,T),w?this.resume():this},Layout.prototype.initialLayout=function(c,u,m){if(this._groups.length>0&&c>0){var h=this._nodes.length,g=this._links.map(function(c){return{source:c.source.index,target:c.target.index}}),v=this._nodes.map(function(c){return{index:c.index}});this._groups.forEach(function(c,u){v.push({index:c.index=h+u})}),this._groups.forEach(function(c,u){c.leaves!==void 0&&c.leaves.forEach(function(u){return g.push({source:c.index,target:u.index})}),c.groups!==void 0&&c.groups.forEach(function(u){return g.push({source:c.index,target:u.index})})}),new Layout().size(this.size()).nodes(v).links(g).avoidOverlaps(!1).linkDistance(this.linkDistance()).symmetricDiffLinkLengths(5).convergenceThreshold(1e-4).start(c,0,0,0,!1),this._nodes.forEach(function(c){u[c.index]=v[c.index].x,m[c.index]=v[c.index].y})}else this._descent.run(c)},Layout.prototype.separateOverlappingComponents=function(c,u,m){var h=this;if(m===void 0&&(m=!0),!this._distanceMatrix&&this._handleDisconnected){var g=this._descent.x[0],v=this._descent.x[1];this._nodes.forEach(function(c,u){c.x=g[u],c.y=v[u]});var y=S.separateGraphs(this._nodes,this._links);S.applyPacking(y,c,u,this._defaultNodeSize,1,m),this._nodes.forEach(function(c,u){h._descent.x[0][u]=c.x,h._descent.x[1][u]=c.y,c.bounds&&(c.bounds.setXCentre(c.x),c.bounds.setYCentre(c.y))})}},Layout.prototype.resume=function(){return this.alpha(.1)},Layout.prototype.stop=function(){return this.alpha(0)},Layout.prototype.prepareEdgeRouting=function(c){c===void 0&&(c=0),this._visibilityGraph=new y.TangentVisibilityGraph(this._nodes.map(function(u){return u.bounds.inflate(-c).vertices()}))},Layout.prototype.routeEdge=function(c,u,m){u===void 0&&(u=5);var h=[],S=new y.TangentVisibilityGraph(this._visibilityGraph.P,{V:this._visibilityGraph.V,E:this._visibilityGraph.E}),w={x:c.source.x,y:c.source.y},T={x:c.target.x,y:c.target.y},E=S.addPoint(w,c.source.index),D=S.addPoint(T,c.target.index);S.addEdgeIfVisible(w,T,c.source.index,c.target.index),m!==void 0&&m(S);var sourceInd=function(c){return c.source.id},targetInd=function(c){return c.target.id},length=function(c){return c.length()},k=new v.Calculator(S.V.length,S.E,sourceInd,targetInd,length).PathFromNodeToNode(E.id,D.id);if(k.length===1||k.length===S.V.length){var j=g.makeEdgeBetween(c.source.innerBounds,c.target.innerBounds,u);h=[j.sourceIntersection,j.arrowStart]}else{for(var M=k.length-2,N=S.V[k[M]].p,P=S.V[k[0]].p,h=[c.source.innerBounds.rayIntersection(N.x,N.y)],I=M;I>=0;--I)h.push(S.V[k[I]].p);h.push(g.makeEdgeTo(P,c.target.innerBounds,u))}return h},Layout.getSourceIndex=function(c){return typeof c.source==`number`?c.source:c.source.index},Layout.getTargetIndex=function(c){return typeof c.target==`number`?c.target:c.target.index},Layout.linkId=function(c){return Layout.getSourceIndex(c)+`-`+Layout.getTargetIndex(c)},Layout.dragStart=function(c){isGroup(c)?Layout.storeOffset(c,Layout.dragOrigin(c)):(Layout.stopNode(c),c.fixed|=2)},Layout.stopNode=function(c){c.px=c.x,c.py=c.y},Layout.storeOffset=function(c,u){c.leaves!==void 0&&c.leaves.forEach(function(c){c.fixed|=2,Layout.stopNode(c),c._dragGroupOffsetX=c.x-u.x,c._dragGroupOffsetY=c.y-u.y}),c.groups!==void 0&&c.groups.forEach(function(c){return Layout.storeOffset(c,u)})},Layout.dragOrigin=function(c){return isGroup(c)?{x:c.bounds.cx(),y:c.bounds.cy()}:c},Layout.drag=function(c,u){isGroup(c)?(c.leaves!==void 0&&c.leaves.forEach(function(m){c.bounds.setXCentre(u.x),c.bounds.setYCentre(u.y),m.px=m._dragGroupOffsetX+u.x,m.py=m._dragGroupOffsetY+u.y}),c.groups!==void 0&&c.groups.forEach(function(c){return Layout.drag(c,u)})):(c.px=u.x,c.py=u.y)},Layout.dragEnd=function(c){isGroup(c)?(c.leaves!==void 0&&c.leaves.forEach(function(c){Layout.dragEnd(c),delete c._dragGroupOffsetX,delete c._dragGroupOffsetY}),c.groups!==void 0&&c.groups.forEach(Layout.dragEnd)):c.fixed&=-7},Layout.mouseOver=function(c){c.fixed|=4,c.px=c.x,c.py=c.y},Layout.mouseOut=function(c){c.fixed&=-5},Layout}()})),tt=u(((c,u,m)=>{var h=m&&m.__extends||(function(){var extendStatics=function(c,u){return extendStatics=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(c,u){c.__proto__=u}||function(c,u){for(var m in u)u.hasOwnProperty(m)&&(c[m]=u[m])},extendStatics(c,u)};return function(c,u){extendStatics(c,u);function __(){this.constructor=c}c.prototype=u===null?Object.create(u):(__.prototype=u.prototype,new __)}})();Object.defineProperty(c,"__esModule",{value:!0});var g=et(),v=function(c){h(LayoutAdaptor,c);function LayoutAdaptor(u){var m=c.call(this)||this,h=u;return h.trigger&&(m.trigger=h.trigger),h.kick&&(m.kick=h.kick),h.drag&&(m.drag=h.drag),h.on&&(m.on=h.on),m.dragstart=m.dragStart=g.Layout.dragStart,m.dragend=m.dragEnd=g.Layout.dragEnd,m}return LayoutAdaptor.prototype.trigger=function(c){},LayoutAdaptor.prototype.kick=function(){},LayoutAdaptor.prototype.drag=function(){},LayoutAdaptor.prototype.on=function(c,u){return this},LayoutAdaptor}(g.Layout);c.LayoutAdaptor=v;function adaptor(c){return new v(c)}c.adaptor=adaptor})),dt=u(((c,u,m)=>{var h=m&&m.__extends||(function(){var extendStatics=function(c,u){return extendStatics=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(c,u){c.__proto__=u}||function(c,u){for(var m in u)u.hasOwnProperty(m)&&(c[m]=u[m])},extendStatics(c,u)};return function(c,u){extendStatics(c,u);function __(){this.constructor=c}c.prototype=u===null?Object.create(u):(__.prototype=u.prototype,new __)}})();Object.defineProperty(c,"__esModule",{value:!0});var g=et(),v=function(c){h(D3StyleLayoutAdaptor,c);function D3StyleLayoutAdaptor(){var u=c.call(this)||this;u.event=d3.dispatch(g.EventType[g.EventType.start],g.EventType[g.EventType.tick],g.EventType[g.EventType.end]);var m=u;return u.drag=function(){if(!c)var c=d3.behavior.drag().origin(g.Layout.dragOrigin).on(`dragstart.d3adaptor`,g.Layout.dragStart).on(`drag.d3adaptor`,function(c){g.Layout.drag(c,d3.event),m.resume()}).on(`dragend.d3adaptor`,g.Layout.dragEnd);if(!arguments.length)return c;this.call(c)},u}return D3StyleLayoutAdaptor.prototype.trigger=function(c){var u={type:g.EventType[c.type],alpha:c.alpha,stress:c.stress};this.event[u.type](u)},D3StyleLayoutAdaptor.prototype.kick=function(){var u=this;d3.timer(function(){return c.prototype.tick.call(u)})},D3StyleLayoutAdaptor.prototype.on=function(c,u){return typeof c==`string`?this.event.on(c,u):this.event.on(g.EventType[c],u),this},D3StyleLayoutAdaptor}(g.Layout);c.D3StyleLayoutAdaptor=v;function d3adaptor(){return new v}c.d3adaptor=d3adaptor})),ft=u(((c,u,m)=>{var h=m&&m.__extends||(function(){var extendStatics=function(c,u){return extendStatics=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(c,u){c.__proto__=u}||function(c,u){for(var m in u)u.hasOwnProperty(m)&&(c[m]=u[m])},extendStatics(c,u)};return function(c,u){extendStatics(c,u);function __(){this.constructor=c}c.prototype=u===null?Object.create(u):(__.prototype=u.prototype,new __)}})();Object.defineProperty(c,"__esModule",{value:!0});var g=et();c.D3StyleLayoutAdaptor=function(c){h(D3StyleLayoutAdaptor,c);function D3StyleLayoutAdaptor(u){var m=c.call(this)||this;m.d3Context=u,m.event=u.dispatch(g.EventType[g.EventType.start],g.EventType[g.EventType.tick],g.EventType[g.EventType.end]);var h=m;return m.drag=function(){if(!c)var c=u.drag().subject(g.Layout.dragOrigin).on(`start.d3adaptor`,g.Layout.dragStart).on(`drag.d3adaptor`,function(c){g.Layout.drag(c,u.event),h.resume()}).on(`end.d3adaptor`,g.Layout.dragEnd);if(!arguments.length)return c;arguments[0].call(c)},m}return D3StyleLayoutAdaptor.prototype.trigger=function(c){var u={type:g.EventType[c.type],alpha:c.alpha,stress:c.stress};this.event.call(u.type,u)},D3StyleLayoutAdaptor.prototype.kick=function(){var u=this,m=this.d3Context.timer(function(){return c.prototype.tick.call(u)&&m.stop()})},D3StyleLayoutAdaptor.prototype.on=function(c,u){return typeof c==`string`?this.event.on(c,u):this.event.on(g.EventType[c],u),this},D3StyleLayoutAdaptor}(g.Layout)})),mt=u((c=>{Object.defineProperty(c,"__esModule",{value:!0});var u=dt(),m=ft();function d3adaptor(c){return!c||isD3V3(c)?new u.D3StyleLayoutAdaptor:new m.D3StyleLayoutAdaptor(c)}c.d3adaptor=d3adaptor;function isD3V3(c){return c.version&&c.version.match(/^3\./)!==null}})),gt=u((c=>{Object.defineProperty(c,"__esModule",{value:!0});var u=qe(),m=Ge(),h=Xe(),g=function(){function NodeWrapper(c,u,m){this.id=c,this.rect=u,this.children=m,this.leaf=m===void 0||m.length===0}return NodeWrapper}();c.NodeWrapper=g;var v=function(){function Vert(c,u,m,h,g){h===void 0&&(h=null),g===void 0&&(g=null),this.id=c,this.x=u,this.y=m,this.node=h,this.line=g}return Vert}();c.Vert=v;var y=function(){function LongestCommonSubsequence(c,u){this.s=c,this.t=u;var m=LongestCommonSubsequence.findMatch(c,u),h=u.slice(0).reverse(),g=LongestCommonSubsequence.findMatch(c,h);m.length>=g.length?(this.length=m.length,this.si=m.si,this.ti=m.ti,this.reversed=!1):(this.length=g.length,this.si=g.si,this.ti=u.length-g.ti-g.length,this.reversed=!0)}return LongestCommonSubsequence.findMatch=function(c,u){for(var m=c.length,h=u.length,g={length:0,si:-1,ti:-1},v=Array(m),y=0;y<m;y++){v[y]=Array(h);for(var S=0;S<h;S++)if(c[y]===u[S]){var w=v[y][S]=y===0||S===0?1:v[y-1][S-1]+1;w>g.length&&(g.length=w,g.si=y-w+1,g.ti=S-w+1)}else v[y][S]=0}return g},LongestCommonSubsequence.prototype.getSequence=function(){return this.length>=0?this.s.slice(this.si,this.si+this.length):[]},LongestCommonSubsequence}();c.LongestCommonSubsequence=y,c.GridRouter=function(){function GridRouter(c,m,h){var y=this;h===void 0&&(h=12),this.originalnodes=c,this.groupPadding=h,this.leaves=null,this.nodes=c.map(function(c,u){return new g(u,m.getBounds(c),m.getChildren(c))}),this.leaves=this.nodes.filter(function(c){return c.leaf}),this.groups=this.nodes.filter(function(c){return!c.leaf}),this.cols=this.getGridLines(`x`),this.rows=this.getGridLines(`y`),this.groups.forEach(function(c){return c.children.forEach(function(u){return y.nodes[u].parent=c})}),this.root={children:[]},this.nodes.forEach(function(c){c.parent===void 0&&(c.parent=y.root,y.root.children.push(c.id)),c.ports=[]}),this.backToFront=this.nodes.slice(0),this.backToFront.sort(function(c,u){return y.getDepth(c)-y.getDepth(u)}),this.backToFront.slice(0).reverse().filter(function(c){return!c.leaf}).forEach(function(c){var m=u.Rectangle.empty();c.children.forEach(function(c){return m=m.union(y.nodes[c].rect)}),c.rect=m.inflate(y.groupPadding)});var S=this.midPoints(this.cols.map(function(c){return c.pos})),w=this.midPoints(this.rows.map(function(c){return c.pos})),T=S[0],E=S[S.length-1],D=w[0],k=w[w.length-1],j=this.rows.map(function(c){return{x1:T,x2:E,y1:c.pos,y2:c.pos}}).concat(w.map(function(c){return{x1:T,x2:E,y1:c,y2:c}})),M=this.cols.map(function(c){return{x1:c.pos,x2:c.pos,y1:D,y2:k}}).concat(S.map(function(c){return{x1:c,x2:c,y1:D,y2:k}})),N=j.concat(M);N.forEach(function(c){return c.verts=[]}),this.verts=[],this.edges=[],j.forEach(function(c){return M.forEach(function(u){var m=new v(y.verts.length,u.x1,c.y1);c.verts.push(m),u.verts.push(m),y.verts.push(m);for(var h=y.backToFront.length;h-->0;){var g=y.backToFront[h],S=g.rect,w=Math.abs(m.x-S.cx()),T=Math.abs(m.y-S.cy());if(w<S.width()/2&&T<S.height()/2){m.node=g;break}}})}),N.forEach(function(c,u){y.nodes.forEach(function(u,m){u.rect.lineIntersections(c.x1,c.y1,c.x2,c.y2).forEach(function(m,h){var g=new v(y.verts.length,m.x,m.y,u,c);y.verts.push(g),c.verts.push(g),u.ports.push(g)})});var m=Math.abs(c.y1-c.y2)<.1,delta=function(c,u){return m?u.x-c.x:u.y-c.y};c.verts.sort(delta);for(var h=1;h<c.verts.length;h++){var g=c.verts[h-1],S=c.verts[h];g.node&&g.node===S.node&&g.node.leaf||y.edges.push({source:g.id,target:S.id,length:Math.abs(delta(g,S))})}})}return GridRouter.prototype.avg=function(c){return c.reduce(function(c,u){return c+u})/c.length},GridRouter.prototype.getGridLines=function(c){for(var u=[],m=this.leaves.slice(0,this.leaves.length);m.length>0;){var h=m.filter(function(u){return u.rect[`overlap`+c.toUpperCase()](m[0].rect)}),g={nodes:h,pos:this.avg(h.map(function(u){return u.rect[`c`+c]()}))};u.push(g),g.nodes.forEach(function(c){return m.splice(m.indexOf(c),1)})}return u.sort(function(c,u){return c.pos-u.pos}),u},GridRouter.prototype.getDepth=function(c){for(var u=0;c.parent!==this.root;)u++,c=c.parent;return u},GridRouter.prototype.midPoints=function(c){for(var u=c[1]-c[0],m=[c[0]-u/2],h=1;h<c.length;h++)m.push((c[h]+c[h-1])/2);return m.push(c[c.length-1]+u/2),m},GridRouter.prototype.findLineage=function(c){var u=[c];do c=c.parent,u.push(c);while(c!==this.root);return u.reverse()},GridRouter.prototype.findAncestorPathBetween=function(c,u){for(var m=this.findLineage(c),h=this.findLineage(u),g=0;m[g]===h[g];)g++;return{commonAncestor:m[g-1],lineages:m.slice(g).concat(h.slice(g))}},GridRouter.prototype.siblingObstacles=function(c,u){var m=this,h=this.findAncestorPathBetween(c,u),g={};h.lineages.forEach(function(c){return g[c.id]={}});var v=h.commonAncestor.children.filter(function(c){return!(c in g)});return h.lineages.filter(function(c){return c.parent!==h.commonAncestor}).forEach(function(c){return v=v.concat(c.parent.children.filter(function(u){return u!==c.id}))}),v.map(function(c){return m.nodes[c]})},GridRouter.getSegmentSets=function(c,u,m){for(var h=[],g=0;g<c.length;g++)for(var v=c[g],y=0;y<v.length;y++){var S=v[y];S.edgeid=g,S.i=y;var w=S[1][u]-S[0][u];Math.abs(w)<.1&&h.push(S)}h.sort(function(c,m){return c[0][u]-m[0][u]});for(var T=[],E=null,D=0;D<h.length;D++){var S=h[D];(!E||Math.abs(S[0][u]-E.pos)>.1)&&(E={pos:S[0][u],segments:[]},T.push(E)),E.segments.push(S)}return T},GridRouter.nudgeSegs=function(c,u,h,g,v,y){var S=g.length;if(!(S<=1)){for(var w=g.map(function(u){return new m.Variable(u[0][c])}),T=[],E=0;E<S;E++)for(var D=0;D<S;D++)if(E!==D){var k=g[E],j=g[D],M=k.edgeid,N=j.edgeid,P=-1,I=-1;c==`x`?v(M,N)&&(k[0][u]<k[1][u]?(P=D,I=E):(P=E,I=D)):v(M,N)&&(k[0][u]<k[1][u]?(P=E,I=D):(P=D,I=E)),P>=0&&T.push(new m.Constraint(w[P],w[I],y))}new m.Solver(w,T).solve(),w.forEach(function(u,m){var v=g[m],y=u.position();v[0][c]=v[1][c]=y;var S=h[v.edgeid];v.i>0&&(S[v.i-1][1][c]=y),v.i<S.length-1&&(S[v.i+1][0][c]=y)})}},GridRouter.nudgeSegments=function(c,u,m,h,g){for(var v=GridRouter.getSegmentSets(c,u,m),y=0;y<v.length;y++){for(var S=v[y],w=[],T=0;T<S.segments.length;T++){var E=S.segments[T];w.push({type:0,s:E,pos:Math.min(E[0][m],E[1][m])}),w.push({type:1,s:E,pos:Math.max(E[0][m],E[1][m])})}w.sort(function(c,u){return c.pos-u.pos+c.type-u.type});var D=[],k=0;w.forEach(function(v){v.type===0?(D.push(v.s),k++):k--,k==0&&(GridRouter.nudgeSegs(u,m,c,D,h,g),D=[])})}},GridRouter.prototype.routeEdges=function(c,u,m,h){var g=this,v=c.map(function(c){return g.route(m(c),h(c))}),y=GridRouter.orderEdges(v),S=v.map(function(c){return GridRouter.makeSegments(c)});return GridRouter.nudgeSegments(S,`x`,`y`,y,u),GridRouter.nudgeSegments(S,`y`,`x`,y,u),GridRouter.unreverseEdges(S,v),S},GridRouter.unreverseEdges=function(c,u){c.forEach(function(c,m){u[m].reversed&&(c.reverse(),c.forEach(function(c){c.reverse()}))})},GridRouter.angleBetween2Lines=function(c,u){var m=Math.atan2(c[0].y-c[1].y,c[0].x-c[1].x),h=Math.atan2(u[0].y-u[1].y,u[0].x-u[1].x),g=m-h;return(g>Math.PI||g<-Math.PI)&&(g=h-m),g},GridRouter.isLeft=function(c,u,m){return(u.x-c.x)*(m.y-c.y)-(u.y-c.y)*(m.x-c.x)<=0},GridRouter.getOrder=function(c){for(var u={},m=0;m<c.length;m++){var h=c[m];u[h.l]===void 0&&(u[h.l]={}),u[h.l][h.r]=!0}return function(c,m){return u[c]!==void 0&&u[c][m]}},GridRouter.orderEdges=function(c){for(var u=[],m=0;m<c.length-1;m++)for(var h=m+1;h<c.length;h++){var g=c[m],v=c[h],S=new y(g,v),w,T,E;S.length!==0&&(S.reversed&&(v.reverse(),v.reversed=!0,S=new y(g,v)),(S.si<=0||S.ti<=0)&&(S.si+S.length>=g.length||S.ti+S.length>=v.length)?u.push({l:m,r:h}):(S.si+S.length>=g.length||S.ti+S.length>=v.length?(w=g[S.si+1],E=g[S.si-1],T=v[S.ti-1]):(w=g[S.si+S.length-2],T=g[S.si+S.length],E=v[S.ti+S.length]),GridRouter.isLeft(w,T,E)?u.push({l:h,r:m}):u.push({l:m,r:h})))}return GridRouter.getOrder(u)},GridRouter.makeSegments=function(c){function copyPoint(c){return{x:c.x,y:c.y}}for(var isStraight=function(c,u,m){return Math.abs((u.x-c.x)*(m.y-c.y)-(u.y-c.y)*(m.x-c.x))<.001},u=[],m=copyPoint(c[0]),h=1;h<c.length;h++){var g=copyPoint(c[h]),v=h<c.length-1?c[h+1]:null;v&&isStraight(m,g,v)||(u.push([m,g]),m=g)}return u},GridRouter.prototype.route=function(c,u){var m=this,g=this.nodes[c],v=this.nodes[u];this.obstacles=this.siblingObstacles(g,v);var y={};this.obstacles.forEach(function(c){return y[c.id]=c}),this.passableEdges=this.edges.filter(function(c){var u=m.verts[c.source],h=m.verts[c.target];return!(u.node&&u.node.id in y||h.node&&h.node.id in y)});for(var S=1;S<g.ports.length;S++){var w=g.ports[0].id,T=g.ports[S].id;this.passableEdges.push({source:w,target:T,length:0})}for(var S=1;S<v.ports.length;S++){var w=v.ports[0].id,T=v.ports[S].id;this.passableEdges.push({source:w,target:T,length:0})}var getSource=function(c){return c.source},getTarget=function(c){return c.target},getLength=function(c){return c.length},E=new h.Calculator(this.verts.length,this.passableEdges,getSource,getTarget,getLength),bendPenalty=function(c,u,h){var y=m.verts[c],S=m.verts[u],w=m.verts[h],T=Math.abs(w.x-y.x),E=Math.abs(w.y-y.y);return y.node===g&&y.node===S.node||S.node===v&&S.node===w.node?0:T>1&&E>1?1e3:0},D=E.PathFromNodeToNodeWithPrevCost(g.ports[0].id,v.ports[0].id,bendPenalty).reverse().map(function(c){return m.verts[c]});return D.push(this.nodes[v.id].ports[0]),D.filter(function(c,u){return!(u<D.length-1&&D[u+1].node===g&&c.node===g||u>0&&c.node===v&&D[u-1].node===v)})},GridRouter.getRoutePath=function(c,u,m,h){var g={routepath:`M `+c[0][0].x+` `+c[0][0].y+` `,arrowpath:``};if(c.length>1)for(var v=0;v<c.length;v++){var y=c[v],S=y[1].x,w=y[1].y,T=S-y[0].x,E=w-y[0].y;if(v<c.length-1){Math.abs(T)>0?S-=T/Math.abs(T)*u:w-=E/Math.abs(E)*u,g.routepath+=`L `+S+` `+w+` `;var D=c[v+1],k=D[0].x,j=D[0].y,M=D[1].x,N=D[1].y;T=M-k,E=N-j;var P=+(GridRouter.angleBetween2Lines(y,D)<0),I,L;Math.abs(T)>0?(I=k+T/Math.abs(T)*u,L=j):(I=k,L=j+E/Math.abs(E)*u);var z=Math.abs(I-S),B=Math.abs(L-w);g.routepath+=`A `+z+` `+B+` 0 0 `+P+` `+I+` `+L+` `}else{var V=[S,w],H,U;Math.abs(T)>0?(S-=T/Math.abs(T)*h,H=[S,w+m],U=[S,w-m]):(w-=E/Math.abs(E)*h,H=[S+m,w],U=[S-m,w]),g.routepath+=`L `+S+` `+w+` `,h>0&&(g.arrowpath=`M `+V[0]+` `+V[1]+` L `+H[0]+` `+H[1]+` L `+U[0]+` `+U[1])}}else{var y=c[0],S=y[1].x,w=y[1].y,T=S-y[0].x,E=w-y[0].y,V=[S,w],H,U;Math.abs(T)>0?(S-=T/Math.abs(T)*h,H=[S,w+m],U=[S,w-m]):(w-=E/Math.abs(E)*h,H=[S+m,w],U=[S-m,w]),g.routepath+=`L `+S+` `+w+` `,h>0&&(g.arrowpath=`M `+V[0]+` `+V[1]+` L `+H[0]+` `+H[1]+` L `+U[0]+` `+U[1])}return g},GridRouter}()})),_t=u((c=>{Object.defineProperty(c,"__esModule",{value:!0});var u=Xe(),m=Be(),h=qe(),g=ze();c.Link3D=function(){function Link3D(c,u){this.source=c,this.target=u}return Link3D.prototype.actualLength=function(c){var u=this;return Math.sqrt(c.reduce(function(c,m){var h=m[u.target]-m[u.source];return c+h*h},0))},Link3D}(),c.Node3D=function(){function Node3D(c,u,m){c===void 0&&(c=0),u===void 0&&(u=0),m===void 0&&(m=0),this.x=c,this.y=u,this.z=m}return Node3D}(),c.Layout3D=function(){function Layout3D(c,u,m){var h=this;m===void 0&&(m=1),this.nodes=c,this.links=u,this.idealLinkLength=m,this.constraints=null,this.useJaccardLinkLengths=!0,this.result=Array(Layout3D.k);for(var g=0;g<Layout3D.k;++g)this.result[g]=Array(c.length);c.forEach(function(c,u){for(var m=0,g=Layout3D.dims;m<g.length;m++){var v=g[m];c[v]===void 0&&(c[v]=Math.random())}h.result[0][u]=c.x,h.result[1][u]=c.y,h.result[2][u]=c.z})}return Layout3D.prototype.linkLength=function(c){return c.actualLength(this.result)},Layout3D.prototype.start=function(c){var y=this;c===void 0&&(c=100);var S=this.nodes.length,w=new v;this.useJaccardLinkLengths&&g.jaccardLinkLengths(this.links,w,1.5),this.links.forEach(function(c){return c.length*=y.idealLinkLength});var T=new u.Calculator(S,this.links,function(c){return c.source},function(c){return c.target},function(c){return c.length}).DistanceMatrix(),E=m.Descent.createSquareMatrix(S,function(c,u){return T[c][u]}),D=m.Descent.createSquareMatrix(S,function(){return 2});this.links.forEach(function(c){var u=c.source,m=c.target;return D[u][m]=D[m][u]=1}),this.descent=new m.Descent(this.result,E),this.descent.threshold=.001,this.descent.G=D,this.constraints&&(this.descent.project=new h.Projection(this.nodes,null,null,this.constraints).projectFunctions());for(var k=0;k<this.nodes.length;k++){var j=this.nodes[k];j.fixed&&this.descent.locks.add(k,[j.x,j.y,j.z])}return this.descent.run(c),this},Layout3D.prototype.tick=function(){this.descent.locks.clear();for(var c=0;c<this.nodes.length;c++){var u=this.nodes[c];u.fixed&&this.descent.locks.add(c,[u.x,u.y,u.z])}return this.descent.rungeKutta()},Layout3D.dims=[`x`,`y`,`z`],Layout3D.k=Layout3D.dims.length,Layout3D}();var v=function(){function LinkAccessor(){}return LinkAccessor.prototype.getSourceIndex=function(c){return c.source},LinkAccessor.prototype.getTargetIndex=function(c){return c.target},LinkAccessor.prototype.getLength=function(c){return c.length},LinkAccessor.prototype.setLength=function(c,u){c.length=u},LinkAccessor}()})),bt=u((c=>{Object.defineProperty(c,"__esModule",{value:!0});var u=et(),m=gt();function gridify(c,u,m,h){return c.cola.start(0,0,0,10,!1),route(c.cola.nodes(),c.cola.groups(),m,h).routeEdges(c.powerGraph.powerEdges,u,function(c){return c.source.routerNode.id},function(c){return c.target.routerNode.id})}c.gridify=gridify;function route(c,u,h,g){c.forEach(function(c){c.routerNode={name:c.name,bounds:c.bounds.inflate(-h)}}),u.forEach(function(u){u.routerNode={bounds:u.bounds.inflate(-g),children:(u.groups===void 0?[]:u.groups.map(function(u){return c.length+u.id})).concat(u.leaves===void 0?[]:u.leaves.map(function(c){return c.index}))}});var v=c.concat(u).map(function(c,u){return c.routerNode.id=u,c.routerNode});return new m.GridRouter(v,{getChildren:function(c){return c.children},getBounds:function(c){return c.bounds}},h-g)}function powerGraphGridLayout(c,m,h){var g;c.nodes.forEach(function(c,u){return c.index=u}),new u.Layout().avoidOverlaps(!1).nodes(c.nodes).links(c.links).powerGraphGroups(function(c){g=c,g.groups.forEach(function(c){return c.padding=h})});var v=c.nodes.length,y=[],S=c.nodes.slice(0);return S.forEach(function(c,u){return c.index=u}),g.groups.forEach(function(c){var u=c.index=c.id+v;S.push(c),c.leaves!==void 0&&c.leaves.forEach(function(c){return y.push({source:u,target:c.index})}),c.groups!==void 0&&c.groups.forEach(function(c){return y.push({source:u,target:c.id+v})})}),g.powerEdges.forEach(function(c){y.push({source:c.source.index,target:c.target.index})}),new u.Layout().size(m).nodes(S).links(y).avoidOverlaps(!1).linkDistance(30).symmetricDiffLinkLengths(5).convergenceThreshold(1e-4).start(100,0,0,0,!1),{cola:new u.Layout().convergenceThreshold(.001).size(m).avoidOverlaps(!0).nodes(c.nodes).links(c.links).groupCompactness(1e-4).linkDistance(30).symmetricDiffLinkLengths(5).powerGraphGroups(function(c){g=c,g.groups.forEach(function(c){c.padding=h})}).start(50,0,100,0,!1),powerGraph:g}}c.powerGraphGridLayout=powerGraphGridLayout})),xt=u((c=>{function __export(u){for(var m in u)c.hasOwnProperty(m)||(c[m]=u[m])}Object.defineProperty(c,"__esModule",{value:!0}),__export(tt()),__export(mt()),__export(Be()),__export(Qe()),__export(gt()),__export($e()),__export(et()),__export(_t()),__export(ze()),__export(Le()),__export(Je()),__export(Ke()),__export(qe()),__export(Xe()),__export(Ge()),__export(bt())}))(),St=20,Dt=10,widthOf=c=>c.width||100,heightOf=c=>c.height||80;function rigidGroupExtent(c,u){let m=u?.positions.get(c.id)??{x:c.x,y:c.y},h=u?.sizes.get(c.id)??{width:widthOf(c),height:heightOf(c)},g=u?.padding?.get(c.id)??{top:0,right:0,bottom:0,left:0};return{left:m.x-g.left,top:m.y-g.top,right:m.x+h.width+g.right,bottom:m.y+h.height+g.bottom}}function alignmentGroups(c,u){let m=c.map((c,u)=>({index:u,centre:c})).sort((c,u)=>c.centre-u.centre),h=[],g=[],flush=()=>{g.length>1&&h.push(g.map(c=>c.index)),g=[]};for(let c of m){let m=g.length?c.centre-g[g.length-1].centre:0,h=g.length?c.centre-g[0].centre:0;g.length&&(m>u||h>u)&&flush(),g.push(c)}return flush(),h}function breakContainment(c){let inside=(c,u)=>c.x>=u.x&&c.X<=u.X&&c.y>=u.y&&c.Y<=u.Y;for(let u=0;u<c.length;u++)for(let m=0;m<c.length;m++){if(u===m)continue;let h=c[u],g=c[m];if(!inside(h,g))continue;let v=g.X-h.x+1,y=h.X-g.x+1,S=g.Y-h.y+1,w=h.Y-g.y+1,T=Math.min(v,y,S,w);T===v?(h.x+=v,h.X+=v):T===y?(h.x-=y,h.X-=y):T===S?(h.y+=S,h.Y+=S):(h.y-=w,h.Y-=w)}}function overlapping(c){for(let u=0;u<c.length;u++)for(let m=u+1;m<c.length;m++){let h=c[u],g=c[m];if(h.x<g.X&&g.x<h.X&&h.y<g.Y&&g.y<h.Y)return!0}return!1}function solveAxis$1(c,u,m,h,g,v){let y=c.map(c=>new xt.Variable(u(c))),S=new Map(y.map((c,u)=>[c,u])),w=g(c,y),T=new Set;for(let c of w){let u=S.get(c.left),m=S.get(c.right);u!==void 0&&m!==void 0&&T.add(u<m?`${u}:${m}`:`${m}:${u}`)}for(let m of v){let h=u(c[m.follower])-u(c[m.owner]);w.push(new xt.Constraint(y[m.owner],y[m.follower],h,!0)),T.add(m.owner<m.follower?`${m.owner}:${m.follower}`:`${m.follower}:${m.owner}`)}for(let m of alignmentGroups(c.map(u),St))for(let c=1;c<m.length;c++){let u=m[c-1],h=m[c],g=u<h?`${u}:${h}`:`${h}:${u}`;T.has(g)||w.push(new xt.Constraint(y[u],y[h],0,!0))}new xt.Solver(y,w).solve(),c.forEach((c,u)=>{let g=y[u].position();if(!Number.isFinite(g))return;let v=m(c)/2;h(c,g-v,g+v)})}c(solveAxis$1,`solveAxis`);function indexByValue$1(c){let u=[...new Set(c.values())].sort((c,u)=>c-u),m=new Map(u.map((c,u)=>[c,u]));return new Map([...c].map(([c,u])=>[c,m.get(u)]))}c(indexByValue$1,`indexByValue`);function placeWithConstraints(c,u,m,h){let g=c.filter(c=>c.width>0&&c.height>0).filter(c=>!m.has(c.type??``)),v=g;if(v.length<1||!h&&(g.length<2||g.every(c=>c.x===0&&c.y===0)))return null;let y=Math.min(8,Math.max(2,u.nodesep/8)),S=g.map(c=>h?.positions.get(c.id)??{x:c.x,y:c.y}),w=g.map(c=>rigidGroupExtent(c,h)),T=[],E=w.map(c=>new xt.Rectangle(c.left-y/2,c.right+y/2,c.top-y/2,c.bottom+y/2));for(let c=0;c<Dt&&overlapping(E);c++)breakContainment(E),solveAxis$1(E,c=>c.cx(),c=>c.width(),(c,u,m)=>{c.x=u,c.X=m},xt.generateXConstraints,T),solveAxis$1(E,c=>c.cy(),c=>c.height(),(c,u,m)=>{c.y=u,c.Y=m},xt.generateYConstraints,T);let D=new Map,k=new Map,j=new Map;g.forEach((c,u)=>{let m=E[u].x+y/2,h=E[u].y+y/2,g=Math.round(m-w[u].left),v=Math.round(h-w[u].top),T=Number.isFinite(g)?S[u].x+g:S[u].x,M=Number.isFinite(v)?S[u].y+v:S[u].y;D.set(c.id,{x:T,y:M}),k.set(c.id,T+widthOf(c)/2),j.set(c.id,M+heightOf(c)/2)}),c.forEach(c=>{if(D.has(c.id))return;let u=h?.positions.get(c.id)??{x:c.x,y:c.y};D.set(c.id,u),k.set(c.id,u.x+widthOf(c)/2),j.set(c.id,u.y+heightOf(c)/2)});let originOf=c=>h?.positions.get(c.id)??{x:c.x,y:c.y},M=Math.max(...v.map(c=>originOf(c).x+widthOf(c)))-Math.min(...v.map(c=>originOf(c).x)),N=Math.max(...v.map(c=>originOf(c).y+heightOf(c)))-Math.min(...v.map(c=>originOf(c).y))>M;return{positions:D,ranks:indexByValue$1(N?j:k),rows:indexByValue$1(N?k:j),authored:!0}}function layoutChildren(c){return(c.children||[]).filter(c=>!!c.width&&!!c.height&&c.type!==`bpmn:Lane`&&!c.waypoints)}function applyPlacement(c,u,m,h,g={x:0,y:0}){let v=new Map,y=new Set,S=0,w=0,T=1/0,E=1/0;return c.forEach(c=>{let D=u.get(c.id)??{x:c.x,y:c.y},k=(Number.isFinite(D.x)?D.x:c.x)+g.x,j=(Number.isFinite(D.y)?D.y:c.y)+g.y,M=k-c.x,N=j-c.y;(M!==0||N!==0)&&(m.moves.push({elements:h(c),dx:M,dy:N}),y.add(c.id)),v.set(c.id,{x:k,y:j,width:c.width,height:c.height}),T=Math.min(T,k),E=Math.min(E,j),S=Math.max(S,k+c.width),w=Math.max(w,j+c.height)}),{positions:u,rects:v,size:{width:Number.isFinite(T)?S-T:0,height:Number.isFinite(E)?w-E:0},movedIds:y}}function fitContainer(c,u,m,h,g,v={x:c.x,y:c.y,width:c.width,height:c.height},y=!1){if(!(v.width>0&&v.height>0))return;let S=[...u.entries()].filter(([c])=>m.has(c)).map(([,c])=>c);if(S.length===0)return;let w=h.marginY,T=Math.min(...S.map(c=>c.x))-w,E=Math.min(...S.map(c=>c.y))-w,D=Math.max(...S.map(c=>c.x+c.width))+w,k=Math.max(...S.map(c=>c.y+c.height))+w,j=y?T:Math.min(v.x,T),M=y?E:Math.min(v.y,E),N=(y?D:Math.max(v.x+v.width,D))-j,P=(y?k:Math.max(v.y+v.height,k))-M;(j!==v.x||M!==v.y||N!==v.width||P!==v.height)&&g.resizes.push({element:c,x:j,y:M,width:N,height:P})}var Ot=1e9,jt=12e3,Nt=1500,Pt=1500,Lt=150,Vt=.005;function settledRects(c,u){let m=new Map;u.moves.forEach(c=>c.elements.forEach(u=>{let h=m.get(u.id)??{x:0,y:0};m.set(u.id,{x:h.x+c.dx,y:h.y+c.dy})}));let h=new Map(u.resizes.map(c=>[c.element.id,c])),g=[],v=1/0,y=1/0,S=-1/0,w=-1/0,walk=(c,u)=>{let T=h.get(c.id),E=m.get(c.id)??{x:0,y:0},D=T?{x:T.x,y:T.y,width:T.width,height:T.height}:{x:c.x+E.x,y:c.y+E.y,width:c.width,height:c.height};!W(c)&&!K(c)&&(v=Math.min(v,D.x),y=Math.min(y,D.y),S=Math.max(S,D.x+D.width),w=Math.max(w,D.y+D.height),u&&g.push(D));let k=(c.children||[]).filter(c=>!W(c)&&!K(c));k.forEach(c=>walk(c,u&&k.length>0))};return(c.children||[]).forEach(c=>walk(c,!D(c)&&!Z.has(c.type??``)&&c.type!==`bpmn:Lane`)),{boxes:g,frame:v===1/0?{x:0,y:0,width:0,height:0}:{x:v,y,width:S-v,height:w-y}}}function scoreLayout(c,u){let{boxes:m,frame:h}=settledRects(c,u),g=m.filter(c=>!m.some(u=>u!==c&&T(u,c))),v=0;for(let c=0;c<g.length;c++)for(let u=c+1;u<g.length;u++)S(g[c],g[u])&&(v+=1);let y=u.routes.map(c=>c.waypoints).filter(c=>c.length>1),E=0,D=0;for(let c=0;c<y.length;c++)for(let u=c+1;u<y.length;u++)$(y[c],y[u])>0&&(E+=1),N(y[c],y[u])&&(D+=1);let k=y.reduce((c,u)=>c+M(u),0),j=0,P=0;y.forEach(c=>{j+=c.length-2,P+=w(c)});let I=h.width*h.height,L=Ot*v+jt*E+Nt*D+Pt*k+Lt*j+P+Vt*I;return{overlaps:v,crossings:E,merges:D,jogs:k,bends:j,length:P,area:I,energy:L}}function settledElements(c,u){let m=[],h=new Set,keep=c=>{h.has(c.id)||(h.add(c.id),m.push(c))},walk=c=>{keep(c),(c.attachers||[]).forEach(keep),(c.children||[]).forEach(walk)};(c.children||[]).forEach(walk);let g=new Map;u.moves.forEach(c=>c.elements.forEach(u=>{let m=g.get(u.id)??{x:0,y:0};g.set(u.id,{x:m.x+c.dx,y:m.y+c.dy})}));let v=new Map(u.resizes.map(c=>[c.element.id,c])),rectOf=c=>{let u=v.get(c.id);if(u)return{x:u.x,y:u.y,width:u.width,height:u.height};let m=g.get(c.id)??{x:0,y:0};return{x:c.x+m.x,y:c.y+m.y,width:c.width,height:c.height}};return{every:m,rectOf}}function ancestorIds(c){let u=new Set,m=c?.parent;for(;m;)u.add(m.id),m=m.parent;return u}function onShapeOrLine(c,u,m,h){if(W(u)){let h=m.get(u.id)??u.waypoints??[];for(let u=0;u+1<h.length;u++){let m=g(c,h[u],h[u+1]);if(Math.abs(m.x-c.x)<=2&&Math.abs(m.y-c.y)<=2)return!0}return!1}return z(c,h(u),2)}var Ut=new Set([`bpmn:TextAnnotation`,`bpmn:Group`]);function countAlongShape(c,u,m){let{every:h,rectOf:g}=settledElements(c,u),v=h.filter(c=>!W(c)&&!K(c)&&!D(c)&&c.type!==`bpmn:Lane`),y=0;return u.routes.forEach(c=>{let u=c.waypoints||[],h=c.connection,S=new Set([h.source?.id,h.target?.id,...ancestorIds(h.source),...ancestorIds(h.target)]);for(let h=0;h+1<u.length;h++){let w=H(u[h],u[h+1]);if(!w)continue;let T=v.find(c=>S.has(c.id)||Ut.has(c.type??``)?!1:re(w,g(c)));T&&(y+=1,m?.(c,T))}}),y}var Wt=2,Gt=40;function countDetours(c,u,m){let{rectOf:h}=settledElements(c,u),g=new Set,v=new Set;u.routes.forEach(c=>{let u=c.connection;if(!u.source||!u.target)return;let m=`${u.type}:${u.source.id}:${u.target.id}`;g.has(m)?v.add(u.id):g.add(m)});let y=0;return u.routes.forEach(c=>{let u=c.waypoints??[],g=c.connection;if(v.has(g.id)||u.length<2||!g.source||!g.target||g.type!==`bpmn:MessageFlow`&&g.type!==`bpmn:SequenceFlow`)return;let S=w(u),T=h(g.source),E=h(g.target),D=Math.abs(T.x+T.width/2-(E.x+E.width/2))+Math.abs(T.y+T.height/2-(E.y+E.height/2));D<Gt||S<=D*Wt||(y+=1,m?.(c))}),y}var en=300;function countAdriftNotes(c){let u=0;return c.routes.forEach(c=>{let m=c.connection;if(m.type!==`bpmn:Association`&&m.type!==`bpmn:DataInputAssociation`&&m.type!==`bpmn:DataOutputAssociation`)return;let h=c.waypoints??[];h.length<2||w(h)<=en||(u+=1)}),u}function checkPlanCorrectness(c,u){let{every:m,rectOf:h}=settledElements(c,u),g=m.filter(c=>!W(c)&&!K(c)&&!D(c)&&c.type!==`bpmn:Lane`),v=g.filter(c=>c.type===`bpmn:Participant`||c.type===`bpmn:SubProcess`),y=new Map(u.routes.map(c=>[c.connection.id,c.waypoints])),S=new Set([`bpmn:Participant`,`bpmn:Lane`,`bpmn:SubProcess`]),w=new Set([`bpmn:TextAnnotation`,`bpmn:DataObjectReference`,`bpmn:DataStoreReference`]),E=[...m.filter(c=>!W(c)&&!K(c)&&!D(c)&&c.type!==`bpmn:Lane`),...m.filter(D)],k=0;for(let c=0;c<E.length;c++)for(let u=c+1;u<E.length;u++){let m=E[c],g=E[u];if(m.host?.id===g.id||g.host?.id===m.id||ancestorIds(m).has(g.id)||ancestorIds(g).has(m.id)||m.type===`bpmn:Group`||g.type===`bpmn:Group`||Ut.has(m.type??``)&&S.has(g.type??``)||Ut.has(g.type??``)&&S.has(m.type??``))continue;let v=m.type===`bpmn:Participant`&&g.type===`bpmn:Participant`,y=w.has(m.type??``)||w.has(g.type??``);if(!v&&!y&&m.parent!==g.parent&&m.type!==`bpmn:Participant`&&g.type!==`bpmn:Participant`)continue;let T=h(m),D=h(g);T.x<D.x+D.width&&D.x<T.x+T.width&&T.y<D.y+D.height&&D.y<T.y+T.height&&(k+=1)}let j=0,M=0;u.routes.forEach(c=>{let u=c.waypoints,m=c.connection;if(!u||u.length<2)return;let g=!m.source||onShapeOrLine(u[0],m.source,y,h),v=!m.target||onShapeOrLine(u[u.length-1],m.target,y,h);g&&v||(j+=1);for(let c=0;c+1<u.length;c++)if(Math.abs(u[c].x-u[c+1].x)>.5&&Math.abs(u[c].y-u[c+1].y)>.5){M+=1;break}});let N=0;u.routes.forEach(c=>{let u=c.waypoints,m=c.connection;if(!u||u.length<2)return;let v=ancestorIds(m.source),y=ancestorIds(m.target);g.forEach(c=>{if(c.id===m.source?.id||c.id===m.target?.id||v.has(c.id)||y.has(c.id)||Ut.has(c.type??``))return;let g=h(c);for(let c=0;c+1<u.length;c++)B(u[c],u[c+1],g,2)&&(N+=1)})});let P=0;m.forEach(c=>{if(c.type===`bpmn:Participant`||c.type===`bpmn:Lane`||c.type===`bpmn:Group`||W(c)||K(c))return;let u=h(c),m=ancestorIds(c);v.forEach(g=>{if(g.id===c.id||c.host?.id===g.id||ancestorIds(g).has(c.id))return;let v=h(g),y=T(v,u),S=ne(u,v);(c.type===`bpmn:TextAnnotation`?!y&&!S:m.has(g.id)?!y:!S)&&(P+=1)})});let I=0;return m.filter(D).forEach(c=>{let u=c.host;if(!u)return;let m=h(c),g=h(u),v=m.x+m.width/2,y=m.y+m.height/2,S=Math.abs(v-g.x)<=2||Math.abs(v-(g.x+g.width))<=2,w=Math.abs(y-g.y)<=2||Math.abs(y-(g.y+g.height))<=2,T=v>=g.x-2&&v<=g.x+g.width+2,E=y>=g.y-2&&y<=g.y+g.height+2;S&&E||w&&T||(I+=1)}),{ok:k===0&&j===0&&N===0&&P===0&&I===0&&M===0,overlaps:k,detachedEdges:j,edgeThroughNode:N,containment:P,boundaryOffHost:I,diagonalEdges:M}}function computeAnnotationWaypoints(c,u,m=.5){let h=c.x+c.width*m,g=c.y+c.height*m,v=u.x+u.width/2,y=u.y+u.height/2;if(u.y>=c.y+c.height){let m={x:h,y:c.y+c.height},g={x:v,y:u.y};return m.x===g.x?[m,g]:[m,{x:m.x,y:g.y},g]}if(u.y+u.height<=c.y){let m={x:h,y:c.y},g={x:v,y:u.y+u.height};return m.x===g.x?[m,g]:[m,{x:m.x,y:g.y},g]}if(u.x>=c.x+c.width){let m={x:c.x+c.width,y:g},h={x:u.x,y};return m.y===h.y?[m,h]:[m,{x:h.x,y:m.y},h]}let S={x:c.x,y:g},w={x:u.x+u.width,y};return S.y===w.y?[S,w]:[S,{x:w.x,y:S.y},w]}var tn=20,nn=14;function exactArrangement(c,u,m){let h=c.length,g=new Map(c.map((c,m)=>[u(c),m])),v=Array.from({length:h},()=>Array(h).fill(0));m.forEach((c,u)=>{let[m,h]=u.split(`|`),y=g.get(m),S=g.get(h);y!==void 0&&S!==void 0&&y!==S&&(v[y][S]+=c,v[S][y]+=c)});let y=v.map(c=>c.reduce((c,u)=>c+u,0)),S=1<<h,w=new Float64Array(S);for(let c=1;c<S;c++){let u=c&-c,m=31-Math.clz32(u),g=c^u,S=0;for(let c=0;c<h;c++)g&1<<c&&(S+=v[m][c]);w[c]=w[g]+y[m]-2*S}let T=new Float64Array(S).fill(1/0),E=new Int32Array(S).fill(-1);T[0]=0;for(let c=1;c<S;c++){for(let u=0;u<h;u++){if(!(c&1<<u))continue;let m=T[c^1<<u];m<T[c]&&(T[c]=m,E[c]=u)}T[c]+=w[c]}let D=[];for(let u=S-1;u>0;){let m=E[u];D.push(c[m]),u^=1<<m}return D.reverse()}function trafficKey(c,u){return c<u?`${c}|${u}`:`${u}|${c}`}function orderByTraffic(c,u,m,h=!1){let g=[...c].sort((c,u)=>c.y-u.y||(c.id<u.id?-1:1));if(c.length<3||m.size===0)return g;if(h&&c.length<=nn)return exactArrangement(g,u,m);let cost=c=>{let h=new Map(c.map((c,m)=>[u(c),m])),g=0;return m.forEach((c,u)=>{let[m,v]=u.split(`|`),y=h.get(m),S=h.get(v);y!==void 0&&S!==void 0&&(g+=c*Math.abs(y-S))}),g},v=g,y=cost(v);for(let c=0;c<tn;c++){let c=new Map(v.map((c,m)=>[u(c),m])),h=[...v.map(h=>{let g=u(h),v=0,y=0;return m.forEach((u,m)=>{let[h,S]=m.split(`|`),w=h===g?S:S===g?h:null;if(w===null)return;let T=c.get(w);T!==void 0&&(v+=u,y+=u*T)}),{item:h,place:v?y/v:c.get(g)}})].sort((c,u)=>c.place-u.place||(c.item.id<u.item.id?-1:1)).map(c=>c.item),g=cost(h);if(g>=y)break;v=h,y=g}return v}function poolTraffic(c){let subtree=c=>[c,...(c.children||[]).flatMap(subtree)],u=new Map;c.forEach(c=>subtree(c).forEach(m=>u.set(m.id,c.id)));let m=new Map;return c.flatMap(subtree).forEach(c=>(c.outgoing||[]).forEach(c=>{let h=c;if(!j(h))return;let g=u.get(h.source?.id??``),v=u.get(h.target?.id??``);if(!g||!v||g===v)return;let y=trafficKey(g,v);m.set(y,(m.get(y)??0)+1)})),m}function poolRanking(c,u=!1){let m=poolTraffic(c);return new Map(orderByTraffic(c,c=>c.id,m,u).map((c,u)=>[c.id,u]))}function snapRoundAnchor(c,u,m,h,g){if(!m||c.length<2)return c;let v=h?0:c.length-1,y=h?1:c.length-2,S=c[v],w=c[y],T=u.x+u.width/2,E=u.y+u.height/2,D=Math.abs(S.x-u.x)<.5,k=Math.abs(S.x-(u.x+u.width))<.5,j=Math.abs(S.y-u.y)<.5,M=Math.abs(S.y-(u.y+u.height))<.5,N=y===0||y===c.length-1,P=[...c],place=(c,u)=>{P[v]=c,N?Math.abs(u.x-w.x)<.5&&Math.abs(u.y-w.y)<.5||P.splice(h?1:P.length-1,0,u):P[y]=u};(D||k)&&Math.abs(S.y-E)>.5?Math.abs(w.y-S.y)<.5&&place({x:S.x,y:E},{x:w.x,y:E}):(j||M)&&Math.abs(S.x-T)>.5&&Math.abs(w.x-S.x)<.5&&place({x:T,y:S.y},{x:T,y:w.y});for(let u=0;u+1<P.length;u++)if(segmentHitsAnyRect(P[u],P[u+1],g))return c;return P}function segmentHitsAnyRect(c,u,m){return m.some(m=>{if(c.x===u.x){let h=c.x;return h>m.x+.01&&h<m.x+m.width-.01&&Math.min(c.y,u.y)<m.y+m.height&&Math.max(c.y,u.y)>m.y}if(c.y===u.y){let h=c.y;return h>m.y+.01&&h<m.y+m.height-.01&&Math.min(c.x,u.x)<m.x+m.width&&Math.max(c.x,u.x)>m.x}return!1})}function onShape(c,u){return z(c,u,.5)}function anchorEndpoints(c,u,m,h){let g=c;return u&&!onShape(g[0],u)&&(g=snapRoundAnchor(g,u,!0,!0,h)),m&&!onShape(g[g.length-1],m)&&(g=snapRoundAnchor(g,m,!0,!1,h)),g}var rn=90,an=60,on=400,sn=4,Frontier=class{items=[];push(c){this.items.push(c);let u=this.items.length-1;for(;u>0;){let c=u-1>>1;if(this.items[c].guess<=this.items[u].guess)break;[this.items[c],this.items[u]]=[this.items[u],this.items[c]],u=c}}pop(){let c=this.items[0],u=this.items.pop();if(u===void 0||this.items.length===0)return c;this.items[0]=u;let m=0;for(;;){let u=m*2+1,h=u+1,g=m;if(u<this.items.length&&this.items[u].guess<this.items[g].guess&&(g=u),h<this.items.length&&this.items[h].guess<this.items[g].guess&&(g=h),g===m)return c;[this.items[m],this.items[g]]=[this.items[g],this.items[m]],m=g}}};function blocked(c,u,m){let h=Math.min(c.x,u.x),g=Math.max(c.x,u.x),v=Math.min(c.y,u.y),y=Math.max(c.y,u.y);return m.some(c=>g>c.x+sn&&h<c.x+c.width-sn&&y>c.y+sn&&v<c.y+c.height-sn)}function axisValues(c,u,m,h){let g=Math.min(u,m)-h*2,v=Math.max(u,m)+h*2,y=new Set([u,m]);return c.forEach(c=>{c>=g&&c<=v&&y.add(c)}),[...y].sort((c,u)=>c-u)}function routeByVisibility(c,u,m,h,g,v,y=2,S=rn){let w=m.flatMap(c=>[c.x-g,c.x+c.width+g]),T=m.flatMap(c=>[c.y-g,c.y+c.height+g]),E=axisValues(w,c.x,u.x,g).filter(c=>!v||c>=v.x-g&&c<=v.x+v.width+g),D=axisValues(T,c.y,u.y,g);if(E.length*D.length>S*S)return null;let k=new Map(E.map((c,u)=>[c,u])),j=new Map(D.map((c,u)=>[c,u])),M=k.get(c.x),N=j.get(c.y),I=k.get(u.x),L=j.get(u.y);if(M===void 0||N===void 0||I===void 0||L===void 0)return null;let z=E.length,key=(c,u,m)=>(u*z+c)*3+m,B=new Map,V=new Map,H=new Frontier,push=(c,m,h,g)=>{let v=key(c,m,h),y=B.get(v);return y!==void 0&&y<=g?!1:(B.set(v,g),H.push({ix:c,iy:m,dir:h,cost:g,guess:g+Math.abs(E[c]-u.x)+Math.abs(D[m]-u.y)}),!0)};push(M,N,y,0);let U=[];h.forEach(c=>{for(let u=0;u+1<c.length;u++){let m=c[u],h=c[u+1];U.push({a:m,b:h,left:Math.min(m.x,h.x),right:Math.max(m.x,h.x),top:Math.min(m.y,h.y),bottom:Math.max(m.y,h.y)})}});let W=new Map,crossCost=(c,u,m,h)=>{let g=m*z*D.length+h,v=W.get(g);if(v!==void 0)return v;let y=Math.min(c.x,u.x),S=Math.max(c.x,u.x),w=Math.min(c.y,u.y),T=Math.max(c.y,u.y),E=0;for(let m of U)m.right<y||m.left>S||m.bottom<w||m.top>T||P(c,u,m.a,m.b)&&E++;let k=E*on;return W.set(g,k),k},ee=-1,G=0;for(;;){G++%512==0&&checkBudget();let c=H.pop();if(!c)break;if(B.get(key(c.ix,c.iy,c.dir))!==c.cost)continue;if(c.ix===I&&c.iy===L&&(y===2||c.dir===y)){ee=key(c.ix,c.iy,c.dir);break}let u=[[c.ix+1,c.iy,0],[c.ix-1,c.iy,0],[c.ix,c.iy+1,1],[c.ix,c.iy-1,1]],h=c.ix===M&&c.iy===N;u.forEach(([u,g,v])=>{if(u<0||g<0||u>=E.length||g>=D.length||y!==2&&h&&v!==y)return;let S={x:E[c.ix],y:D[c.iy]},w={x:E[u],y:D[g]};if(blocked(S,w,m))return;let T=c.dir===2||c.dir===v?0:an,k=c.cost+Math.abs(w.x-S.x)+Math.abs(w.y-S.y)+T+crossCost(S,w,c.iy*z+c.ix,g*z+u);push(u,g,v,k)&&V.set(key(u,g,v),key(c.ix,c.iy,c.dir))})}if(ee<0)return null;let K=[],Z=ee;for(;Z!==void 0;){let c=Math.floor(Z/3);K.push({x:E[c%z],y:D[Math.floor(c/z)]}),Z=V.get(Z)}K.reverse();let Q=[];return K.forEach((c,u)=>{let m=Q[Q.length-1];if(m&&m.x===c.x&&m.y===c.y)return;let h=K[u+1];m&&h&&(m.x===c.x&&h.x===c.x||m.y===c.y&&h.y===c.y)||Q.push(c)}),Q}var cn=16,ln=24;function colourLanes(c,u,m){let h=new Map,g=[];return[...c].sort((c,h)=>m(c)-m(h)||u(c).from-u(h).from).forEach(c=>{let m=u(c),v=g.findIndex(c=>c<=m.from);v<0&&(v=g.length),g[v]=m.to,h.set(c,v)}),h}function planFlows(c,u){let m=new Map(c.map((c,u)=>[c,u]));return u.map((u,h)=>{let g=m.get(u.from)??0,v=m.get(u.to)??0,y=Math.min(g,v),S=Math.max(g,v),gapAt=u=>`${c[u]}|${c[u+1]}`;return S-y<=1?{id:u.id,fromPool:u.from,toPool:u.to,gaps:[gapAt(y)],strip:null}:{id:u.id,fromPool:u.from,toPool:u.to,gaps:[gapAt(g<v?g:g-1),gapAt(v<g?v:v-1)],strip:h%2==0?`right`:`left`}})}function freeColumn(c,u,m,g,v){let clear=c=>h({x:c,y:u},{x:c,y:m},g)===0&&v.every(u=>Math.abs(u-c)>=cn);if(clear(c))return c;for(let u=1;u<=ln;u++)for(let m of[1,-1]){let h=c+m*u*cn;if(clear(h))return h}return c}function routeThroughChannels(c,u,m){let h=new Map;c.forEach(c=>[...new Set(c.plan.gaps)].forEach(u=>{h.has(u)||h.set(u,[]),h.get(u).push(c)}));let reach=c=>({from:Math.min(c.source.x+c.source.width/2,c.target.x+c.target.width/2),to:Math.max(c.source.x+c.source.width/2,c.target.x+c.target.width/2)}),g=new Map;h.forEach((c,u)=>{let m=colourLanes(c,reach,c=>reach(c).from);g.set(u,new Map([...m].map(([c,u])=>[c.connection.id,u])))});let v=c.filter(c=>c.plan.strip!==null),y=new Map,reachDown=c=>({from:Math.min(c.sourcePool.y,c.targetPool.y),to:Math.max(c.sourcePool.y+c.sourcePool.height,c.targetPool.y+c.targetPool.height)});[`left`,`right`].forEach(c=>{colourLanes(v.filter(u=>u.plan.strip===c),reachDown,c=>reachDown(c).from).forEach((c,u)=>y.set(u.connection.id,c))});let S=[],w=new Map;return c.forEach(c=>{let h=c.source.x+c.source.width/2,v=c.target.x+c.target.width/2,T=c.sourcePool.y<c.targetPool.y,E=T?c.source.y+c.source.height:c.source.y,D=T?c.target.y:c.target.y+c.target.height,lanesIn=m=>{let h=u.gapOf(m),v=g.get(m)?.get(c.connection.id)??0;if(!h)return E;let y=Math.max(1,h.high-h.low),S=Math.max(1,g.get(m)?.size??1),w=Math.min(20,y/(S+1));return h.low+y/2+(v-(S-1)/2)*w},k=lanesIn(c.plan.gaps[0]),j=lanesIn(c.plan.gaps[c.plan.gaps.length-1]),M=freeColumn(h,Math.min(E,k),Math.max(E,k),m,S);S.push(M);let N=freeColumn(v,Math.min(D,j),Math.max(D,j),m,S);if(S.push(N),c.plan.strip===null){w.set(c.connection.id,[{x:M,y:E},{x:M,y:k},{x:N,y:k},{x:N,y:D}]);return}let P=y.get(c.connection.id)??0,I=c.plan.strip===`right`?u.rightAt+(P+1)*20:u.leftAt-(P+1)*20;w.set(c.connection.id,[{x:M,y:E},{x:M,y:k},{x:I,y:k},{x:I,y:j},{x:N,y:j},{x:N,y:D}])}),w}var un=10,dn=.5,fn=[`channel`,`target`,`source`,`third`,`far`],pn=16,mn=.01,hn=4,gn=16e3,_n=100;function poolGroups(c,u){let m=new Map(c.map(c=>[c.id,c.id])),find=c=>{let u=c;for(;m.get(u)!==u;)u=m.get(u);return u};return u.forEach(c=>{let u=V(c.source),h=V(c.target);if(!u||!h||!m.has(u.id)||!m.has(h.id))return;let g=find(u.id),v=find(h.id);g!==v&&m.set(g,v)}),new Map(c.map(c=>[c.id,find(c.id)]))}function channelKey(c){let u=V(c.source),m=V(c.target);return!u||!m?c.source.id:u.y<=m.y?`${u.id}|${m.id}`:`${m.id}|${u.id}`}function assignChannelLanes(c){let reach=c=>{let u=c.source,m=c.target,h=u.x+u.width/2,g=m.x+m.width/2;return{from:Math.min(h,g),to:Math.max(h,g)}},u=new Map;c.forEach(c=>{let m=channelKey(c);u.has(m)||u.set(m,[]),u.get(m).push(c)});let m=new Map,h=new Map;return u.forEach((c,u)=>{let g=[];[...c].sort((c,u)=>reach(c).from-reach(u).from||(c.id<u.id?-1:1)).forEach(c=>{let u=reach(c),h=g.findIndex(c=>c<=u.from);h<0&&(h=g.length),g[h]=u.to+20,m.set(c.id,h)}),h.set(u,g.length)}),{lane:m,width:h}}function channelDemand(c){let walk=c=>[c,...(c.children||[]).flatMap(walk)],u=new Map;return walk(c).forEach(c=>(c.outgoing||[]).forEach(c=>{let m=c;j(m)&&m.source&&m.target&&u.set(m.id,m)})),assignChannelLanes([...u.values()]).width}function corridorsBetween(c,u,m,h){let g=Math.min(c.y,u.y),v=Math.max(c.y+c.height,u.y+u.height),y=m.filter(c=>c.y>=g-1&&c.y+c.height<=v+1).sort((c,u)=>c.y-u.y),S=[];for(let c=1;c<y.length;c++){let u=y[c-1],m=y[c];S.push((u.y+u.height+m.y)/2)}return h?S:S.reverse()}function staircase(c,u,m,h,g,v,y,S){if(g.length===0)return null;let priceOf=c=>I(c,v)*U+y.reduce((u,m)=>u+$(c,m),0),w=c.x+c.width/2,T=[{x:w,y:u}],E=m.x+m.width/2;if(g.forEach((c,u)=>{let m=u+1<g.length?g[u+1]:h,y=new Set([w,E]);v.forEach(u=>{u.y>Math.max(c,m)||u.y+u.height<Math.min(c,m)||(y.add(u.x-10),y.add(u.x+u.width+10))});let D={x:w,price:1/0};[...y].filter(c=>!S||c>=S.x&&c<=S.x+S.width).sort((c,u)=>Math.abs(c-E)-Math.abs(u-E)).forEach(u=>{let h=priceOf([{x:w,y:c},{x:u,y:c},{x:u,y:m}])+Math.abs(u-w)*mn;h<D.price&&(D={x:u,price:h})}),T.push({x:w,y:c}),D.x!==w&&T.push({x:D.x,y:c}),w=D.x}),w===E)return T.push({x:w,y:h}),te(T);let D=T[T.length-1],k=h+Math.sign(D.y-h)*20;return T.push({x:w,y:k}),T.push({x:E,y:k}),T.push({x:E,y:h}),te(T)}function escapeColumn(c,u,m,h,g=[],v){let y=c.x+c.width/2,priceOf=c=>I(c,h)*U+g.reduce((u,m)=>u+$(c,m),0),along=c=>[{x:c,y:u},{x:c,y:m}],S=Math.max(0,c.width/2-10),w=[y];for(let c=1;c*un<=S;c++)w.push(y+c*un,y-c*un);let seatCost=c=>priceOf(along(c))*U+g.filter(u=>N(along(c),u)).length,T=w.reduce((c,u)=>seatCost(u)<seatCost(c)?u:c,y),E=Math.abs(u-c.y)<=Math.abs(u-(c.y+c.height))?-1:1,stubbed=c=>{let h=u+E*Math.min(20,Math.abs(m-u));return h===u?[{x:c,y:u}]:[{x:c,y:u},{x:c,y:h}]};if(seatCost(T)===0)return stubbed(T);let D=priceOf(along(y));if(D===0)return stubbed(y);let k=u+E*20,inside=c=>!v||c>=v.x&&c<=v.x+v.width,j={price:D,x:y};for(let c=1;c<=80&&j.price>0;c++)for(let h of[1,-1]){let g=y+h*c*un;if(!inside(g))continue;let v=priceOf([{x:y,y:u},{x:y,y:k},{x:g,y:k},{x:g,y:m}]);v<j.price&&(j={price:v,x:g})}return j.x===y?stubbed(y):[{x:y,y:u},{x:y,y:k},{x:j.x,y:k},{x:j.x,y:m}]}function computeMessageFlowWaypoints(c,u,m=[],h=0,g=[],v=[],y=new Map,S=new Map,w=!0,T=0,D=1,k=!1){let j={x:c.x,y:c.y,width:c.width,height:c.height},M={x:u.x,y:u.y,width:u.width,height:u.height},P=V(c),L=V(u),z=[P,L].filter(c=>!!c),B=m.filter(c=>(c.x!==j.x||c.y!==j.y)&&(c.x!==M.x||c.y!==M.y)&&!z.some(u=>c.x===u.x&&c.y===u.y)),faultsOf=c=>I(c,B)*U+v.reduce((u,m)=>u+$(c,m),0),spanOf=c=>c.reduce((u,m,h)=>h===0?0:u+Math.abs(m.x-c[h-1].x)+Math.abs(m.y-c[h-1].y),0),priceOf=c=>w?faultsOf(c)*gn+spanOf(c):faultsOf(c),H=P?S.get(y.get(P.id)??``):void 0,routeLeaving=(m,S)=>{let E=m?c.y:c.y+c.height,k=m?u.y+u.height:u.y,I=P&&L&&P!==L?m?{low:L.y+L.height,high:P.y}:{low:P.y+P.height,high:L.y}:{low:Math.min(E,k),high:Math.max(E,k)},z=Math.max(0,I.high-I.low),V=Math.min(20,z/(D+1)),U=(I.low+I.high)/2+(T-(D-1)/2)*V,W=Math.max(0,(T-(D-1)/2)*pn+(D-1)*pn/2),ee=m?k+20+W:k-20-W,G=m?E-20:E+20,K=I.high-I.low,Z={channel:U,target:ee,source:G,third:I.low+K/3,far:I.low+K*2/3}[S],Q={from:Math.max(j.x,M.x)+10,to:Math.min(j.x+j.width,M.x+M.width)-10};if(Q.to>=Q.from){let c=(Q.from+Q.to)/2,u=[c];for(let m=1;m*un<=(Q.to-Q.from)/2;m++)u.push(c+m*un,c-m*un);let m=u.map(c=>[{x:c,y:E},{x:c,y:k}]).find(c=>faultsOf(c)===0&&!v.some(u=>N(c,u)));if(m)return m}let ne=joinAtChannel(escapeColumn(j,E,Z,B,v,H),escapeColumn(M,k,Z,B,v,H).reverse(),Z);if(!P||!L||P===L)return ne;let $=Math.min(P.y,L.y),re=Math.max(P.y+P.height,L.y+L.height);if(!g.some(c=>c!==P&&c!==L&&c.y>$&&c.y+c.height<re)&&faultsOf(ne)===0)return ne;let ae=(T-(D-1)/2)*V,oe=(m?P.y-30:P.y+P.height+30)+ae,se=(m?L.y+L.height+30:L.y-30)+ae,le={left:Math.min(P.x,L.x),right:Math.max(P.x+P.width,L.x+L.width)},de=g.filter(c=>c.y+c.height>Math.min(P.y,L.y)&&c.y<Math.max(P.y+P.height,L.y+L.height)&&c.x+c.width>le.left&&c.x<le.right&&(y.size===0||y.get(c.id)===y.get(P.id))),fe=60+h%hn*20,pe=Math.max(...de.map(c=>c.x+c.width),P.x+P.width,L.x+L.width)+fe,me=Math.min(...de.map(c=>c.x),P.x,L.x)-fe,ge=H?Math.min(pe,H.x+H.width-20):pe,ye=H?Math.max(me,H.x+20):me,De=escapeColumn(j,E,oe,B,v,H),je=escapeColumn(M,k,se,B,v,H).reverse(),around=c=>te([...De,{x:De[De.length-1].x,y:oe},{x:c,y:oe},{x:c,y:se},{x:je[0].x,y:se},...je]),Me=staircase(j,E,M,k,corridorsBetween(P,L,de,!m),B,v,H),Pe=routeByVisibility({x:j.x+j.width/2,y:E},{x:M.x+M.width/2,y:k},B,v,20,void 0,1),Fe=h%2==0?[around(ge),around(ye)]:[around(ye),around(ge)];return(w?[ne,...Pe?[Pe]:[],...Me?[Me]:[],...Fe]:[...Fe,ne,...Me?[Me]:[],...Pe?[Pe]:[]]).reduce((c,u)=>priceOf(u)<priceOf(c)?u:c)},glueOf=c=>v.filter(u=>N(c,u)).length,worthOf=c=>priceOf(c)+glueOf(c)*dn,W=k?`target`:`channel`,ee=routeLeaving(c.y>u.y,W);if(!P||!L||P===L)return E(ee);let G=routeLeaving(c.y<=u.y,W),K=worthOf(G)<worthOf(ee)?G:ee;if(glueOf(K)===0)return E(K);let Z=fn.filter(c=>c!==W).flatMap(m=>[routeLeaving(c.y>u.y,m),routeLeaving(c.y<=u.y,m)]);return E(Z.reduce((c,u)=>worthOf(u)<worthOf(c)?u:c,K))}function joinAtChannel(c,u,m){let h=[...c];return h[h.length-1].y!==m&&h.push({x:h[h.length-1].x,y:m}),u[0].x!==h[h.length-1].x&&h.push({x:u[0].x,y:m}),u.forEach(c=>h.push(c)),te(h)}function routeByChannels(c,u,m){if(u.length<2||c.length===0)return null;let h=poolGroups(u,c),g=new Map,v=new Map;return u.forEach(c=>{let u=h.get(c.id)??c.id;v.has(u)||v.set(u,[]),v.get(u).push(c)}),v.forEach((u,v)=>{let y=[...u].sort((c,u)=>c.y-u.y);if(y.length<2)return;let S=y.map(c=>c.id),w=c.filter(c=>{let u=V(c.source),m=V(c.target);return!!u&&!!m&&u.id!==m.id&&h.get(u.id)===v&&h.get(m.id)===v});if(w.length===0)return;let T=new Map(planFlows(S,w.map(c=>({id:c.id,from:V(c.source).id,to:V(c.target).id}))).map(c=>[c.id,c])),E=new Map;for(let c=0;c+1<y.length;c++)E.set(`${y[c].id}|${y[c+1].id}`,{low:y[c].y+y[c].height,high:y[c+1].y});let D={gapOf:c=>E.get(c),leftAt:Math.min(...y.map(c=>c.x)),rightAt:Math.max(...y.map(c=>c.x+c.width))},rectOf=c=>({x:c.x,y:c.y,width:c.width,height:c.height}),k=w.map(c=>({connection:c,plan:T.get(c.id),source:rectOf(c.source),target:rectOf(c.target),sourcePool:rectOf(V(c.source)),targetPool:rectOf(V(c.target))}));routeThroughChannels(k,D,m.filter(c=>!k.some(u=>u.source.x===c.x&&u.source.y===c.y||u.target.x===c.x&&u.target.y===c.y))).forEach((c,u)=>g.set(u,c))}),c.every(c=>g.has(c.id))?g:null}function computeMessageFlowRoutes(c,u=[],m=[],h=!0,g=!1,y=!1){let S=u.filter(c=>c.type!==`bpmn:Lane`&&c.type!==`bpmn:Participant`&&!G.has(c.type??``)&&c.width>0&&c.height>0).map(c=>({x:c.x,y:c.y,width:c.width,height:c.height})),w=u.filter(c=>c.type===`bpmn:Participant`),T=c.filter(c=>j(c)&&c.source&&c.target),spanOf=c=>{let u=V(c.source),m=V(c.target);if(!u||!m)return{low:0,high:0};let h=u.y+u.height/2,g=m.y+m.height/2;return{low:Math.min(h,g),high:Math.max(h,g)}},E=new Map([...T].sort((c,u)=>{let m=spanOf(c),h=spanOf(u);return h.high-h.low-(m.high-m.low)||m.low-h.low||(c.id<u.id?-1:1)}).map((c,u)=>[c.id,T.length-u])),{lane:D,width:k}=assignChannelLanes(T),M=poolGroups(w,T),N=new Map;w.forEach(c=>{let u=M.get(c.id);if(!u)return;let m=N.get(u),h={x:c.x-_n,y:c.y,width:c.width+_n*2,height:c.height};N.set(u,m?v(m,h):h)});let P=g?routeByChannels(T,w,S):null;if(P)return T.map(c=>({connection:c,waypoints:P.get(c.id)}));let I=[...m];return T.map(c=>{let u=computeMessageFlowWaypoints(c.source,c.target,S,E.get(c.id)??0,w,I,M,N,h,D.get(c.id)??0,k.get(channelKey(c))??1,y);return I.push(u),{connection:c,waypoints:u}})}var vn=1e6;function runsOfRoute(c){let u=c.waypoints,m=[];for(let h=0;h+1<u.length;h++){let g=u[h],v=u[h+1],y=h===0||h+2===u.length;g.y===v.y&&g.x!==v.x?m.push({route:c,index:h,axis:`y`,at:g.y,from:Math.min(g.x,v.x),to:Math.max(g.x,v.x),anchored:y}):g.x===v.x&&g.y!==v.y&&m.push({route:c,index:h,axis:`x`,at:g.x,from:Math.min(g.y,v.y),to:Math.max(g.y,v.y),anchored:y})}return m}function solveAxis(c,u){let m=new Map;c.forEach(c=>m.set(c,new xt.Variable(c.at,c.anchored?vn:1)));let h=[],g=[...c].sort((c,u)=>c.at-u.at||c.from-u.from);for(let c=0;c<g.length;c++)for(let v=c+1;v<g.length;v++){let y=g[c],S=g[v];if(S.at-y.at>u)break;y.route!==S.route&&(Math.min(y.to,S.to)-Math.max(y.from,S.from)<=0||h.push(new xt.Constraint(m.get(y),m.get(S),u)))}if(h.length===0)return new Map;new xt.Solver(c.map(c=>m.get(c)),h).solve();let v=new Map;return c.forEach(c=>{let u=m.get(c).position();Math.abs(u-c.at)>=.5&&v.set(c,u)}),v}function separateRuns(c,u=16){let m=c.flatMap(runsOfRoute),h=[];return[`x`,`y`].forEach(c=>{let g=m.filter(u=>u.axis===c);g.length<2||solveAxis(g,u).forEach((u,m)=>h.push({route:m.route,index:m.index,axis:c,at:u,step:Math.abs(u-m.at)}))}),h.sort((c,u)=>c.step-u.step)}function endsOf(c){let u=c.route.waypoints,m=c.axis===`y`?`y`:`x`,h=u[c.index-1],g=u[c.index+2],v=h?h[m]:u[c.index][m],y=g?g[m]:u[c.index+1][m];return u[c.index].x<=u[c.index+1].x&&u[c.index].y<=u[c.index+1].y?{head:v,foot:y}:{head:y,foot:v}}var yn={comparisons:0};function sharedLines(c){let u=c.map((c,u)=>u),find=c=>{let m=c;for(;u[m]!==m;)m=u[m];return m},axisRank=c=>c===`x`?0:1,m=c.map((c,u)=>u).sort((u,m)=>axisRank(c[u].axis)-axisRank(c[m].axis)||c[u].at-c[m].at||c[u].from-c[m].from);for(let h=0;h<m.length;h++){let g=m[h],v=c[g];for(let y=h+1;y<m.length;y++){let h=m[y],S=c[h];if(yn.comparisons+=1,v.axis!==S.axis||S.at-v.at>12)break;if(v.route===S.route||Math.min(v.to,S.to)-Math.max(v.from,S.from)<40)continue;let w=find(g),T=find(h);w!==T&&(u[w]=T)}}let h=new Map;return c.forEach((c,u)=>{let m=find(u);h.has(m)||h.set(m,[]),h.get(m).push(c)}),[...h.values()].filter(c=>c.length>1)}function orderedShifts(c,u=16){let m=c.flatMap(runsOfRoute),h=[];return sharedLines(m).forEach(c=>{let m=c.reduce((c,u)=>c+u.at,0)/c.length;[...c].sort((c,u)=>{let m=endsOf(c),h=endsOf(u);return m.head-h.head||m.foot-h.foot||c.at-u.at||c.index-u.index}).forEach((g,v)=>{let y=m+(v-(c.length-1)/2)*u;Math.abs(y-g.at)<.5||h.push({route:g.route,index:g.index,axis:g.axis,at:y,step:Math.abs(y-g.at)})})}),h.sort((c,u)=>c.step-u.step)}function borderShifts(c,u){let m=[];return c.forEach(c=>{let h=u(c);runsOfRoute(c).forEach(u=>{let g=u.axis===`y`,v;h.forEach(c=>{let m=g?c.x:c.y,h=g?c.x+c.width:c.y+c.height;Math.min(u.to,h)-Math.max(u.from,m)<40||(g?[c.y,c.y+c.height]:[c.x,c.x+c.width]).forEach((c,m)=>{if(Math.abs(c-u.at)>6)return;let h=m===0?c-12:c+12;(v===void 0||Math.abs(h-u.at)<Math.abs(v-u.at))&&(v=h)})}),v!==void 0&&m.push({route:c,index:u.index,axis:u.axis,at:v,step:Math.abs(v-u.at)})})}),m.sort((c,u)=>c.step-u.step)}function latticeShifts(c,u){let m=[];return c.forEach(c=>{let h=u(c);runsOfRoute(c).forEach(u=>{if(u.anchored)return;let g=u.axis===`y`,v=h.filter(c=>{let m=g?c.x:c.y,h=g?c.x+c.width:c.y+c.height;return Math.min(u.to,h)-Math.max(u.from,m)>=40});if(!v.some(c=>(g?[c.y,c.y+c.height]:[c.x,c.x+c.width]).some(c=>Math.abs(c-u.at)<=6)))return;let y=v.map(c=>g?[c.y,c.y+c.height]:[c.x,c.x+c.width]).sort((c,u)=>c[0]-u[0]),S=[];y.forEach(c=>{let u=S[S.length-1];u&&c[0]<=u[1]?u[1]=Math.max(u[1],c[1]):S.push([c[0],c[1]])});let w=[];for(let c=0;c+1<S.length;c++)w.push([S[c][1],S[c+1][0]]);let T=w.filter(c=>c[1]-c[0]>=24).map(c=>(c[0]+c[1])/2).reduce((c,m)=>c===void 0||Math.abs(m-u.at)<Math.abs(c-u.at)?m:c,void 0);T===void 0||Math.abs(T-u.at)<.5||m.push({route:c,index:u.index,axis:u.axis,at:T,step:Math.abs(T-u.at)})})}),m.sort((c,u)=>c.step-u.step)}var bn=12,xn=40,Sn=16,Cn=12,wn=4,Tn=2,En=[.5,.34,.66,.42,.58],Dn=20,On=20,kn=10,An=5,jn=8,Mn=4,Nn=9,Pn=40,Fn=800,In=3e3,Ln=80,Rn=200;function reanchorRoutes(c){let u=new Map,rectOf=c=>{let m=u.get(c.id);if(m)return m;let h={x:c.x,y:c.y,width:c.width,height:c.height};return u.set(c.id,h),h};c.moves.forEach(({elements:c,dx:u,dy:m})=>c.forEach(c=>{let h=rectOf(c);h.x+=u,h.y+=m})),c.resizes.forEach(({element:c,x:m,y:h,width:g,height:v})=>{u.set(c.id,{x:m,y:h,width:g,height:v})});let snap=c=>{let u=Math.round(c/40)*40;return Math.abs(u-c)<=4?u:c};c.routes.forEach(c=>{let u=c.connection.source?rectOf(c.connection.source):void 0,m=c.connection.target?rectOf(c.connection.target):void 0,h=anchorEndpoints(c.waypoints,u,m,[]),g=h.map(c=>({x:snap(c.x),y:snap(c.y)}));c.waypoints=k(g)&&Q(g)<=Q(h)&&(!u||onShape(g[0],u))&&(!m||onShape(g[g.length-1],m))?g:h})}function settledGeometry(c,u){let m=[],h=new Set,keep=c=>{h.has(c.id)||(h.add(c.id),m.push(c))},walk=c=>{keep(c),(c.attachers||[]).forEach(keep),(c.children||[]).forEach(walk)};(c.children||[]).forEach(walk);let g=new Map,v=new Map(u.resizes.map(c=>[c.element.id,c])),refresh=()=>{g.clear(),u.moves.forEach(c=>c.elements.forEach(u=>{let m=g.get(u.id)??{x:0,y:0};g.set(u.id,{x:m.x+c.dx,y:m.y+c.dy})})),v=new Map(u.resizes.map(c=>[c.element.id,c]))};refresh();let driftOf=c=>{let u=g.get(c.id);if(u)return u;let m=v.get(c.id);return m?{x:m.x-c.x,y:m.y-c.y}:{x:0,y:0}},rectOf=c=>{let u=v.get(c.id);if(u)return{x:u.x,y:u.y,width:u.width,height:u.height};let m=g.get(c.id)??{x:0,y:0};return{x:c.x+m.x,y:c.y+m.y,width:c.width,height:c.height}},movedBy=c=>g.get(c.id);return{every:m,rectOf,driftOf,movedBy,refresh}}function stackPools(c,u,m,h=!1){let g=(c.children||[]).filter(c=>c.type===`bpmn:Participant`);if(g.length<2)return;let v=new Map;u.moves.forEach(c=>c.elements.forEach(u=>{let m=v.get(u.id)??{x:0,y:0};v.set(u.id,{x:m.x+c.dx,y:m.y+c.dy})}));let y=new Map(u.resizes.map(c=>[c.element.id,c])),rectOf=c=>{let u=y.get(c.id);if(u)return{x:u.x,y:u.y,width:u.width,height:u.height};let m=v.get(c.id)??{x:0,y:0};return{x:c.x+m.x,y:c.y+m.y,width:c.width,height:c.height}},subtree=c=>[c,...(c.children||[]).flatMap(subtree)],S=(c.children||[]).filter(c=>Z.has(c.type??``)),w=new Map;S.forEach(c=>{let u=[...c.outgoing||[],...c.incoming||[]].map(u=>{let m=u;return m.source?.id===c.id?m.target:m.source}).filter(c=>!!c).map(c=>g.find(u=>subtree(u).some(u=>u.id===c.id))).find(Boolean);u&&w.set(c.id,u.id)});let T=channelDemand(c),E=poolRanking(g,h),D=[...g].sort((c,u)=>(E.get(c.id)??0)-(E.get(u.id)??0)),k=poolTraffic(g),j=talkingGroups(D,k).map(c=>{let u=arrangeGroup(c,k,rectOf,m,T);return c.length>1&&u.forEach((c,m)=>u.set(m,{x:c.x+_n,y:c.y})),{group:c,inside:u,width:Math.max(...c.map(c=>u.get(c.id).x+rectOf(c).width))+(c.length>1?_n:0),height:Math.max(...c.map(c=>u.get(c.id).y+rectOf(c).height))}}),M=new Map,N=Math.max(...j.map(c=>c.height)),P=[];j.slice().sort((c,u)=>u.height-c.height||u.width-c.width).forEach(c=>{let u=P.find(u=>u.used+c.height<=N+1);if(!u){let c=P[P.length-1];u={left:c?c.left+c.width+60:m.marginX,used:0,width:0},P.push(u)}let h=m.marginY+u.used;c.group.forEach(m=>{let g=c.inside.get(m.id);M.set(m.id,{x:u.left+g.x,y:h+g.y})}),u.used+=c.height+60,u.width=Math.max(u.width,c.width)}),D.forEach(c=>{let m=rectOf(c),h=M.get(c.id),g=h.x-m.x,v=h.y-m.y;if(Math.abs(g)<.5&&Math.abs(v)<.5)return;let T=[...subtree(c),...S.filter(u=>w.get(u.id)===c.id)],E=new Set(T.map(c=>c.id));T.forEach(c=>{let m=y.get(c.id);m?(m.x+=g,m.y+=v):W(c)||u.moves.push({elements:[c],dx:g,dy:v})}),u.routes.forEach(c=>{E.has(c.connection.source?.id??``)&&E.has(c.connection.target?.id??``)&&(c.waypoints=c.waypoints.map(c=>({x:c.x+g,y:c.y+v})))})})}function alignPools(c,u){let m=(c.children||[]).filter(c=>c.type===`bpmn:Participant`);if(m.length<2)return;let h=new Map;u.moves.forEach(c=>c.elements.forEach(u=>{let m=h.get(u.id)??{x:0,y:0};h.set(u.id,{x:m.x+c.dx,y:m.y+c.dy})}));let g=new Map(u.resizes.map(c=>[c.element.id,c])),rectOf=c=>{let u=g.get(c.id);if(u)return{x:u.x,y:u.y,width:u.width,height:u.height};let m=h.get(c.id)??{x:0,y:0};return{x:c.x+m.x,y:c.y+m.y,width:c.width,height:c.height}},subtree=c=>[c,...(c.children||[]).flatMap(subtree)],v=new Map;m.forEach(c=>subtree(c).forEach(u=>v.set(u.id,c.id)));let y=[];if(m.flatMap(subtree).forEach(c=>(c.outgoing||[]).forEach(c=>{let u=c;if(!j(u)||!u.source||!u.target)return;let m=v.get(u.source.id),h=v.get(u.target.id);if(!m||!h||m===h)return;let g=rectOf(u.source),S=rectOf(u.target);y.push({from:m,to:h,gap:S.x+S.width/2-(g.x+g.width/2)})})),y.length===0)return;let S=new Map(m.map(c=>[c.id,0])),w=[...m].sort((c,u)=>c.id<u.id?-1:1);for(let c=0;c<Cn;c++){let c=!1;if(w.forEach(u=>{let m=[];if(y.forEach(({from:c,to:h,gap:g})=>{c===u.id?m.push(S.get(h)+g):h===u.id&&m.push(S.get(c)-g)}),m.length===0)return;m.sort((c,u)=>c-u);let h=Math.round(m[Math.floor((m.length-1)/2)]);h!==S.get(u.id)&&(S.set(u.id,h),c=!0)}),!c)break}let T=new Map(m.map(c=>[c.id,c.id])),find=c=>{let u=c;for(;T.get(u)!==u;)u=T.get(u);return u};y.forEach(({from:c,to:u})=>{let m=find(c),h=find(u);m!==h&&T.set(m,h)});let E=new Map;m.forEach(c=>{let u=find(c.id),m=E.get(u),h=S.get(c.id);(m===void 0||h<m)&&E.set(u,h)}),m.forEach(c=>{let m=S.get(c.id)-(E.get(find(c.id))??0);if(m<1)return;let h=subtree(c).filter(u=>u.id!==c.id),v=new Set(h.map(c=>c.id)),y=(c.children||[]).filter(c=>c.type===`bpmn:Lane`),w=y.length===1?y[0].id:void 0;h.forEach(c=>{let h=g.get(c.id);h?c.id===w?h.width+=m:h.x+=m:W(c)||u.moves.push({elements:[c],dx:m,dy:0})}),u.routes.forEach(c=>{v.has(c.connection.source?.id??``)&&v.has(c.connection.target?.id??``)&&(c.waypoints=c.waypoints.map(c=>({x:c.x+m,y:c.y})))});let T=g.get(c.id);T&&(T.width+=m)})}function arrangeGroup(c,u,m,h,g){let v=new Map;if(c.length===1)return v.set(c[0].id,{x:0,y:0}),v;let y=new Map;c.forEach(c=>y.set(c.id,[])),u.forEach((c,u)=>{let[m,h]=u.split(`|`);y.has(m)&&y.has(h)&&(y.get(m).push(h),y.get(h).push(m))});let S=new Map,w=new Set,T=0;c.forEach(c=>{if(w.has(c.id))return;let u=[c.id];for(w.add(c.id);u.length>0;){let c=u.shift();S.set(c,T),T+=1,(y.get(c)??[]).forEach(c=>{w.has(c)||(w.add(c),u.push(c))})}});let E=0,D=c.slice().sort((c,u)=>(S.get(c.id)??0)-(S.get(u.id)??0));return D.forEach((c,u)=>{v.set(c.id,{x:0,y:E});let h=D[u+1],y=h?g.get(`${c.id}|${h.id}`)??g.get(`${h.id}|${c.id}`)??0:0;E+=m(c).height+Math.max(60,(y+1)*20)}),v}function talkingGroups(c,u){let m=new Map(c.map(c=>[c.id,c.id])),find=c=>{let u=c;for(;m.get(u)!==u;)u=m.get(u);return u};u.forEach((c,u)=>{let[h,g]=u.split(`|`);if(!m.has(h)||!m.has(g))return;let v=find(h),y=find(g);v!==y&&m.set(v,y)});let h=new Map;return c.forEach(c=>{let u=find(c.id);h.has(u)||h.set(u,[]),h.get(u).push(c)}),[...h.values()]}function bestAssociation(c,u,m,h=[]){let g={x:c.x+c.width/2,y:c.y+c.height/2},v={x:u.x+u.width/2,y:u.y+u.height/2},dockX=(c,u)=>u>c.x+c.width/2?c.x+c.width:c.x,dockY=(c,u)=>u>c.y+c.height/2?c.y+c.height:c.y,y=[];En.forEach(m=>{let h=g.y+(v.y-g.y)*m,S=g.x+(v.x-g.x)*m;y.push({path:[{x:g.x,y:dockY(c,v.y)},{x:g.x,y:h},{x:v.x,y:h},{x:v.x,y:dockY(u,g.y)}],sideways:0}),y.push({path:[{x:dockX(c,v.x),y:g.y},{x:S,y:g.y},{x:S,y:v.y},{x:dockX(u,g.x),y:v.y}],sideways:1})}),y.push({path:[{x:g.x,y:dockY(c,v.y)},{x:g.x,y:v.y},{x:dockX(u,g.x),y:v.y}],sideways:0}),y.push({path:[{x:dockX(c,v.x),y:g.y},{x:v.x,y:g.y},{x:v.x,y:dockY(u,g.y)}],sideways:1}),Math.abs(g.y-v.y)<1&&y.push({path:[{x:dockX(c,v.x),y:g.y},{x:dockX(u,g.x),y:v.y}],sideways:0}),Math.abs(g.x-v.x)<1&&y.push({path:[{x:g.x,y:dockY(c,v.y)},{x:v.x,y:dockY(u,g.y)}],sideways:0});let insideOwn=(c,u)=>u.x>c.x+.5&&u.x<c.x+c.width-.5&&u.y>c.y+.5&&u.y<c.y+c.height-.5,S=te(y[y.length-2].path),w=1/0;return y.forEach(({path:g,sideways:v})=>{let y=te(g),T=h.reduce((c,u)=>c+$(y,u),0),E=h.filter(c=>N(y,c)).length,D=(y.length>1&&insideOwn(c,y[1])?1:0)+(y.length>1&&insideOwn(u,y[y.length-2])?1:0),k=(I(y,m)+D)*kn+T*An+E*Dn+v+y.length/100;k<w&&(w=k,S=y)}),S}function parkComments(c,u,m){let{every:h,rectOf:g}=settledGeometry(c,u),v=h.filter(c=>Z.has(c.type??``)&&c.type!==`bpmn:Group`);new Set(v.map(c=>c.id)),parkLoose(v.filter(c=>c.type===`bpmn:TextAnnotation`&&[...c.outgoing||[],...c.incoming||[]].length===0),h,g,u,m)}function parkLoose(c,u,m,h,g){if(c.length===0)return;let v=u.filter(u=>!c.includes(u)&&u.type!==`bpmn:Lane`&&u.width>0&&u.height>0);if(v.length===0)return;let y=v.map(m),S=Math.min(...y.map(c=>c.x)),w=Math.max(...y.map(c=>c.x+c.width)),T=Math.min(...y.map(c=>c.y)),E=Math.max(...y.map(c=>c.y+c.height)),D=c.map(m),k={width:Math.max(...D.map(c=>c.width)),height:D.reduce((c,u)=>c+u.height,0)+g.nodesep*(c.length-1)},j={width:D.reduce((c,u)=>c+u.width,0)+g.marginX*(c.length-1),height:Math.max(...D.map(c=>c.height))},costOf=(c,u)=>c*u,M=costOf(w-S+g.marginX*2+k.width,E-T)<=costOf(Math.max(w-S,j.width),E-T+g.marginY*2+j.height),N=M?T:S;[...c].sort((c,u)=>m(c).y-m(u).y||m(c).x-m(u).x).forEach(c=>{let u=m(c),v=M?{x:w+g.marginX*2,y:N}:{x:N,y:E+g.marginY*2};N+=M?u.height+g.nodesep:u.width+g.marginX;let y=v.x-u.x,S=v.y-u.y;Math.abs(y)<.5&&Math.abs(S)<.5||h.moves.push({elements:[c],dx:y,dy:S})})}function settleArtifacts(c,u,m,h=!1,g=!0){let{every:w,rectOf:E}=settledGeometry(c,u),D=w.filter(c=>Z.has(c.type??``)&&c.type!==`bpmn:Group`);if(D.length===0)return;new Set(D.map(c=>c.id));let k=D.filter(c=>c.type===`bpmn:TextAnnotation`&&[...c.outgoing||[],...c.incoming||[]].length===0),j=D.filter(c=>!k.includes(c));if(j.length===0)return;let M=new Set(j.map(c=>c.id)),N=w.filter(c=>!M.has(c.id)&&c.type!==`bpmn:Lane`&&c.width>0&&c.height>0),ancestors=c=>{let u=new Set,m=c?.parent;for(;m;)u.add(m.id),m=m.parent;return u},P=new Map(u.routes.map(c=>[c.connection.id,c.waypoints])),boxOf=(c,u)=>{if(!c.source||!c.target)return E(c);let m=P.get(c.id)??c.waypoints??[];return m.length<2?E(c):bestSeatOn(m,u,!1,[],[]).at},ownedByEdge=c=>[...c.outgoing||[],...c.incoming||[]].some(u=>{let m=u,h=m.source?.id===c.id?m.target:m.source;return!!h?.source&&!!h?.target}),L=N.map(E),z=[],B=[],V=new Map,H=new Map,footprintOf=c=>c.label?v(E(c),E(c.label)):E(c);j.filter(c=>!h||ownedByEdge(c)).forEach(c=>{let g=E(c),v=footprintOf(c),D=g.x-v.x,k=g.y-v.y,spread=c=>({x:c.x-D,y:c.y-k,width:v.width,height:v.height}),j=ancestors(c),U=N.filter(c=>!j.has(c.id)&&c.type!==`bpmn:Participant`&&c.type!==`bpmn:Lane`&&c.type!==`bpmn:SubProcess`).map(E),W=[...(c.outgoing||[]).map(c=>c.target),...(c.incoming||[]).map(c=>c.source)].filter(c=>!!c&&!M.has(c.id)),container=c=>c.type===`bpmn:Participant`||c.type===`bpmn:Lane`||c.type===`bpmn:SubProcess`,ee=W.filter(c=>!container(c)),G=ee.length?boxOf(ee[0],g):W.length?boxOf(W[0],g):g,K=m.nodesep,Z=c.parent;for(;Z&&Z.type!==`bpmn:Participant`&&Z.type!==`bpmn:SubProcess`;)Z=Z.parent;let Q=Z?V.get(Z.id)??E(Z):void 0,te=w.filter(c=>(c.type===`bpmn:Participant`||c.type===`bpmn:SubProcess`)&&!j.has(c.id)&&c.id!==Z?.id).map(E),re=w.filter(c=>c.type===`bpmn:Lane`&&c.id!==Z?.id).map(E),growthFor=c=>{if(!Q||T(Q,c))return Q??c;let u=Math.max(Q.x+Q.width,c.x+c.width+m.marginX),h=Math.max(Q.y+Q.height,c.y+c.height+m.marginY),g=Math.min(Q.x,c.x-m.marginX),v=Math.min(Q.y,c.y-m.marginY);return{x:g,y:v,width:u-g,height:h-v}},growthCrossesForeign=c=>{if(!Q)return!1;let u=growthFor(c);if(u===Q)return!1;let m=[];return u.x<Q.x&&m.push({x:u.x,y:u.y,width:Q.x-u.x,height:u.height}),u.x+u.width>Q.x+Q.width&&m.push({x:Q.x+Q.width,y:u.y,width:u.x+u.width-(Q.x+Q.width),height:u.height}),u.y<Q.y&&m.push({x:u.x,y:u.y,width:u.width,height:Q.y-u.y}),u.y+u.height>Q.y+Q.height&&m.push({x:u.x,y:Q.y+Q.height,width:u.width,height:u.y+u.height-(Q.y+Q.height)}),m.some(c=>te.some(u=>S(c,u)))},ae=m.nodesep*6,growExceedsCap=c=>{if(!Q)return!1;let u=Math.max(0,Q.x-c.x),m=Math.max(0,c.x+c.width-(Q.x+Q.width)),h=Math.max(0,Q.y-c.y),g=Math.max(0,c.y+c.height-(Q.y+Q.height));return u>ae||m>ae||h>ae||g>ae},clear=c=>re.some(u=>y(c,u))||te.some(u=>!ne(c,u))?!1:ee.length>1||te.length>5?!Q||T(Q,c):!growExceedsCap(c)&&!growthCrossesForeign(c),fits=c=>(!Q||T(Q,c))&&clear(c),oe=ee.length>1?U:[...U,...te],crossedBy=c=>u.routes.reduce((u,m)=>u+I(m.waypoints,[c]),0),score=(m,h=1/0)=>{if(!clear(m)||U.some(c=>S(m,c))||z.some(c=>S(m,c)))return 1/0;let g=spread(m),v=+!clear(g)+U.filter(c=>S(g,c)).length+B.filter(c=>S(g,c)).length,y=Math.abs(m.x+m.width/2-(G.x+G.width/2))+Math.abs(m.y+m.height/2-(G.y+G.height/2)),w=v*Fn+y*Ln;if(w>=h)return w;if(!ee.length)return crossedBy(m)*In+w;let T=u.routes.filter(u=>u.connection.source?.id!==c.id&&u.connection.target?.id!==c.id).map(c=>c.waypoints);return ee.reduce((c,u)=>{let h=P.get(u.id)??u.waypoints,g=u.source&&u.target&&h&&h.length>=2?bestSeatOn(h,m,!1,oe,T).waypoints:bestAssociation(E(u),m,oe,T);return c+I(g,oe)+T.reduce((c,u)=>c+$(g,u),0)},0)*In+crossedBy(m)*In+w},se=g,le=score(g);for(let c=1;c<=100&&le>0;c++){let u=G.y+G.height+K*c,m=G.y-K*c-g.height,h=G.x+G.width+K*c,v=G.x-K*c-g.width,y=G.x+G.width/2-g.width/2,S=G.y+G.height/2-g.height/2;for(let c of[{x:y,y:u,aside:0},{x:y,y:m,aside:0},{x:h,y:S,aside:1},{x:v,y:S,aside:1},{x:h,y:u,aside:1},{x:v,y:u,aside:1},{x:h,y:m,aside:1},{x:v,y:m,aside:1}]){let u={x:c.x,y:c.y,width:g.width,height:g.height},m=score(u,le)+c.aside*Rn;m<le&&(le=m,se=u)}}if(le===1/0){let c=G.y+G.height+K;for(let u=0;u<200;u++){let u={x:G.x+G.width/2-g.width/2,y:c,width:g.width,height:g.height};if(score(u)<1/0){se=u;break}c+=K}}if(se!==g&&u.moves.push({elements:[c],dx:se.x-g.x,dy:se.y-g.y}),[...c.outgoing||[],...c.incoming||[]].forEach(m=>{let h=m,g=h.source?.id===c.id?h.target:h.source;if(!g)return;let v=boxOf(g,se),y=h.source?.id===c.id,S=u.routes.filter(c=>c.connection.id!==h.id).map(c=>c.waypoints),w=bestAssociation(y?se:v,y?v:se,oe,S),T=u.routes.find(c=>c.connection.id===h.id);T?T.waypoints=w:u.routes.push({connection:h,waypoints:w})}),L.push(se),z.push(se),B.push(spread(se)),Z&&!h&&!fits(se)){H.has(Z.id)||H.set(Z.id,{...E(Z)});let c=V.get(Z.id)??{...E(Z)},u=Math.max(c.x+c.width,se.x+se.width+m.marginX),h=Math.max(c.y+c.height,se.y+se.height+m.marginY);c.x=Math.min(c.x,se.x-m.marginX),c.y=Math.min(c.y,se.y-m.marginY),c.width=u-c.x,c.height=h-c.y,V.set(Z.id,c)}});let U=new Map(u.resizes.map(c=>[c.element.id,c])),applyResize=(c,m)=>{let h=U.get(c.id);h?(h.x=m.x,h.y=m.y,h.width=m.width,h.height=m.height):u.resizes.push({element:c,x:m.x,y:m.y,width:m.width,height:m.height})};V.forEach((c,u)=>{let m=w.find(c=>c.id===u);if(!m)return;applyResize(m,c);let h=H.get(u);if(!h)return;let v=h.x-c.x,y=h.y-c.y,S=c.x+c.width-(h.x+h.width),T=c.y+c.height-(h.y+h.height);if(v<=0&&y<=0&&S<=0&&T<=0)return;let D=w.filter(c=>c.type===`bpmn:Lane`&&c.parent?.id===u);g&&D.length===1&&D.forEach(c=>{let u=U.get(c.id)??E(c);applyResize(c,{x:u.x-v,y:u.y-y,width:u.width+v+S,height:u.height+y+T})})})}function fitGroups(c,u,m){let{every:h,rectOf:g}=settledGeometry(c,u),v=h.filter(c=>c.type===`bpmn:Group`&&c.width>0&&c.height>0);if(v.length===0)return;let y=h.filter(c=>c.type!==`bpmn:Group`&&!W(c)&&!K(c)&&c.width>0&&c.height>0),S=new Map(u.resizes.map(c=>[c.element.id,c])),w=m.nodesep/2;v.forEach(c=>{let m=y.filter(u=>u.x>=c.x&&u.y>=c.y&&u.x+u.width<=c.x+c.width&&u.y+u.height<=c.y+c.height);if(m.length===0)return;let h=m.map(g),v=Math.min(...h.map(c=>c.x))-w,T=Math.min(...h.map(c=>c.y))-w,E=Math.max(...h.map(c=>c.x+c.width))+w,D=Math.max(...h.map(c=>c.y+c.height))+w,k=g(c);c.label&&u.moves.push({elements:[c.label],dx:v-k.x,dy:T-k.y});let j=S.get(c.id);j?(j.x=v,j.y=T,j.width=E-v,j.height=D-T):u.resizes.push({element:c,x:v,y:T,width:E-v,height:D-T})})}function settleLabels(c,u,m){let{every:h,rectOf:v,driftOf:y,movedBy:w}=settledGeometry(c,u),T=[...h.filter(c=>c.label&&c.type!==`bpmn:Lane`&&c.type!==`bpmn:Participant`),...u.routes.map(c=>c.connection).filter(c=>c.label)];if(T.sort((c,m)=>{let h=!!u.routes.find(u=>u.connection.id===c.id);return h===!!u.routes.find(c=>c.connection.id===m.id)?0:h?-1:1}),T.length===0)return;let E=h.filter(c=>c.type!==`bpmn:Lane`&&c.width>0&&c.height>0),homeOf=c=>{let u=new Set,m=c?.parent;for(;m;)u.add(m.id),m=m.parent;return u},k=[],anchorOf=c=>{let m=u.routes.find(u=>u.connection.id===c.id)?.waypoints??c.waypoints;if(m&&m.length>1){let c={from:m[0],to:m[1],span:-1};for(let u=0;u+1<m.length;u++){let h=Math.abs(m[u+1].x-m[u].x)+Math.abs(m[u+1].y-m[u].y);h>c.span&&(c={from:m[u],to:m[u+1],span:h})}return{x:(c.from.x+c.to.x)/2,y:(c.from.y+c.to.y)/2,width:0,height:0}}if(c.source&&c.target){let u=v(c.source),m=v(c.target);return{x:(u.x+u.width/2+m.x+m.width/2)/2,y:(u.y+u.height/2+m.y+m.height/2)/2,width:0,height:0}}return v(c)},j=m.nodesep/2;T.forEach(c=>{let m=c.label,h=w(m)??y(c),T={x:m.x+h.x,y:m.y+h.y,width:m.width,height:m.height},M=u.routes.some(u=>u.connection.id===c.id);if(!M){let u=v(c);if(T.x>=u.x-1&&T.y>=u.y-1&&T.x+T.width<=u.x+u.width+1&&T.y+T.height<=u.y+u.height+1)return}let N=new Set([c.id,...homeOf(c),...homeOf(c.source),...homeOf(c.target)]);D(c)&&c.host&&N.delete(c.host.id);let P=E.filter(c=>!N.has(c.id)).map(v),busy=c=>P.some(u=>S(c,u))||k.some(u=>S(c,u)),crossed=m=>u.routes.some(u=>u.connection.id!==c.id&&I(u.waypoints,[m])>0),strayed=m=>{let h=u.routes.find(u=>u.connection.id===c.id)?.waypoints??c.waypoints??[];if(h.length<2)return!1;let v=m.x+m.width/2,y=m.y+m.height/2,S=1/0;for(let c=0;c+1<h.length;c++){let u=g({x:v,y},h[c],h[c+1]);S=Math.min(S,Math.abs(v-u.x)+Math.abs(y-u.y))}return S>Pn};if(!busy(T)&&!crossed(T)&&!(M&&strayed(T))){k.push(T);return}if(M){let h=u.routes.find(u=>u.connection.id===c.id)?.waypoints??c.waypoints??[],g=[];for(let c=0;c+1<h.length;c++){let u=h[c],m=h[c+1];if(Math.abs(m.x-u.x)+Math.abs(m.y-u.y)<T.width/2)continue;let v=u.y===m.y;for(let c=1;c<=Nn;c++){let h=c/10,y={x:u.x+(m.x-u.x)*h,y:u.y+(m.y-u.y)*h};[1,2,3].flatMap(c=>v?[{x:y.x-T.width/2,y:y.y-T.height-Mn*c},{x:y.x-T.width/2,y:y.y+Mn*c}]:[{x:y.x+Mn*c,y:y.y-T.height/2},{x:y.x-T.width-Mn*c,y:y.y-T.height/2}]).forEach(c=>g.push({x:Math.round(c.x),y:Math.round(c.y),width:T.width,height:T.height}))}}let v=g.find(c=>!busy(c)&&!crossed(c))??g.find(c=>!busy(c));if(v){u.moves.push({elements:[m],dx:v.x-T.x,dy:v.y-T.y}),k.push(v);return}}let L=anchorOf(c),z=L.x+L.width/2-T.width/2,B=L.y+L.height/2-T.height/2,V=T,H;outer:for(let c=1;c<=jn;c++){let u=L.y+L.height+j*c,m=L.y-j*c-T.height,h=L.x+L.width+j*c,g=L.x-j*c-T.width;for(let c of[{x:z,y:u},{x:z,y:m},{x:h,y:B},{x:g,y:B},{x:h,y:u},{x:g,y:u},{x:h,y:m},{x:g,y:m}]){let u={x:c.x,y:c.y,width:T.width,height:T.height};if(!busy(u)){if(!crossed(u)){V=u;break outer}H||=u}}}V===T&&H&&(V=H),V!==T&&u.moves.push({elements:[m],dx:V.x-T.x,dy:V.y-T.y}),k.push(V)})}function repairRoutes(c,u,m,g=!1){let{every:v,rectOf:y}=settledGeometry(c,u),S=v.filter(c=>c.type!==`bpmn:Lane`&&!G.has(c.type??``)&&c.width>0&&c.height>0),homeOf=c=>{let u=new Set,m=c?.parent;for(;m;)u.add(m.id),m=m.parent;return u},w=new Set;u.routes.forEach(c=>{let u=c.connection,T=new Set([u.source?.id??``,u.target?.id??``,...homeOf(u.source),...homeOf(u.target)]),E=((u.type??``).includes(`Association`)?v.filter(c=>c.type!==`bpmn:Lane`&&c.width>0&&c.height>0):S).filter(c=>!T.has(c.id)).map(y),D=I(c.waypoints,E);if(D===0)return;let j=c.waypoints[0],M=c.waypoints[c.waypoints.length-1],N=E.filter(u=>c.waypoints.some((m,g)=>g+1<c.waypoints.length&&h(m,c.waypoints[g+1],[u])>0));if(N.length===0)return;let P=m.nodesep/2,L=P;if(g)for(let c=0;c<3;c++){let u=Math.round(Math.min(...N.map(c=>c.y),j.y,M.y)-L),m=Math.round(Math.max(...N.map(c=>c.y+c.height),j.y,M.y)+L);if(!w.has(u)&&!w.has(m))break;L=P+(c+1)*2}let z=Math.round(Math.min(...N.map(c=>c.y),j.y,M.y)-L),B=Math.round(Math.max(...N.map(c=>c.y+c.height),j.y,M.y)+L);g&&(w.add(z),w.add(B));let V=v.filter(c=>c.type===`bpmn:Participant`).flatMap(c=>{let u=y(c);return[u.y-L,u.y+u.height+L]}),H=[Math.min(...E.map(c=>c.x))-L,Math.max(...E.map(c=>c.x+c.width))+L],U=[...[z,B,...V].map(c=>[j,{x:j.x,y:c},{x:M.x,y:c},M]),...H.flatMap(c=>[z,B,...V].map(u=>[j,{x:j.x,y:u},{x:c,y:u},{x:c,y:M.y},M])),...routeVariants(c.waypoints)],W=c.waypoints,ee=D,G=Q(c.waypoints);U.forEach(c=>{let u=te(c);if(!k(u)||Q(u)>G)return;let m=I(u,E);m<ee&&(ee=m,W=u)}),c.waypoints=W})}function slidePositions(c){let u=[];for(let m=1;m+2<c;m++)u.push(m);if(u.length<=Sn)return u;let m=(u.length-1)/15;return Array.from({length:Sn},(c,h)=>u[Math.round(h*m)])}function routeVariants(c,u=!1){if(c.length<2)return[c];let m=c[0],h=c[c.length-1],g=Math.abs(c[1].x-m.x)<.5,v=Math.abs(h.x-c[c.length-2].x)<.5,y=[],S=!u;if(S&&g&&v)for(let c=1;c<=7;c++){let u=m.y+(h.y-m.y)*c/8;y.push([m,{x:m.x,y:u},{x:h.x,y:u},h])}else if(S&&!g&&!v)for(let c=1;c<=7;c++){let u=m.x+(h.x-m.x)*c/8;y.push([m,{x:u,y:m.y},{x:u,y:h.y},h])}else S&&g?y.push([m,{x:m.x,y:h.y},h]):S&&y.push([m,{x:h.x,y:m.y},h]);if(S)for(let u of slidePositions(c.length)){let m=Math.abs(c[u].x-c[u+1].x)<.5;for(let h=1;h<=xn;h++)for(let g of[1,-1]){let v=g*h*20,slide=(c,h)=>h!==u&&h!==u+1?c:m?{x:c.x+v,y:c.y}:{x:c.x,y:c.y+v};if(y.push(c.map(slide)),u+3<c.length){let m=Math.abs(c[u+2].x-c[u+3].x)<.5;y.push(c.map((c,h)=>{let g=slide(c,h);return h!==u+2&&h!==u+3?g:m?{x:g.x+v,y:g.y}:{x:g.x,y:g.y+v}}))}}}for(let m=0;u&&m+3<c.length;m++){let[u,h,g,v]=[c[m],c[m+1],c[m+2],c[m+3]],S=Math.abs(u.x-h.x)<.5&&Math.abs(g.x-v.x)<.5,w=Math.abs(u.y-h.y)<.5&&Math.abs(g.y-v.y)<.5;if(!(S?(h.y-u.y)*(v.y-g.y)<0:w&&(h.x-u.x)*(v.x-g.x)<0))continue;let T=S?{x:v.x,y:u.y}:{x:u.x,y:v.y};y.push([...c.slice(0,m+1),T,...c.slice(m+3)])}return y.map(te).filter(c=>c.length>=2)}function cutSet(c,u){return new Set(u.filter(u=>I(c,[u.rect])>0).map(c=>c.id))}function addsCut(c,u,m){let h=cutSet(u,m);return[...cutSet(c,m)].some(c=>!h.has(c))}function untangleRoutes(c,u){let{every:m,rectOf:h}=settledGeometry(c,u),homeOf=c=>{let u=new Set,m=c?.parent;for(;m;)u.add(m.id),m=m.parent;return u},g=m.filter(c=>c.type!==`bpmn:Lane`&&!G.has(c.type??``)&&c.width>0&&c.height>0),share=(c,u)=>new Set([c.connection.source?.id,c.connection.target?.id,u.connection.source?.id,u.connection.target?.id].filter(Boolean)).size<4;for(let c=0;c<30;c++){let c=!1;if(u.routes.forEach(m=>{let v=u.routes.filter(c=>c!==m&&!share(m,c)),tally=c=>v.reduce((u,m)=>u+$(c,m.waypoints),0)*1e6+c.length*200+w(c),y=tally(m.waypoints);if(y<1e6)return;let S=new Set([m.connection.source?.id??``,m.connection.target?.id??``,...homeOf(m.connection.source),...homeOf(m.connection.target)]),T=g.filter(c=>!S.has(c.id)).map(c=>({id:c.id,rect:h(c)})),E=T.map(c=>c.rect),D=I(m.waypoints,E),k=m.waypoints,j=y,M=m.waypoints[0],N=m.waypoints[m.waypoints.length-1];routeVariants(m.waypoints).forEach(c=>{let u=c[0],h=c[c.length-1];if(u.x!==M.x||u.y!==M.y||h.x!==N.x||h.y!==N.y||!c.every((u,m)=>m===0||Math.abs(u.x-c[m-1].x)<.5||Math.abs(u.y-c[m-1].y)<.5)||I(c,E)>D||addsCut(c,m.waypoints,T)||Q(c)>Q(m.waypoints))return;let g=tally(c);g<j&&(j=g,k=c)}),k!==m.waypoints&&(m.waypoints=k,c=!0)}),!c)break}}function planMessageFlows(c,u,m=!0,h=!1,g=!1){let v=[],walk=c=>{v.push(c),(c.attachers||[]).forEach(c=>v.push(c)),(c.children||[]).forEach(walk)};(c.children||[]).forEach(walk);let y=new Map;u.moves.forEach(c=>c.elements.forEach(u=>{let m=y.get(u.id)??{x:0,y:0};y.set(u.id,{x:m.x+c.dx,y:m.y+c.dy})}));let S=new Map(u.resizes.map(c=>[c.element.id,c])),w=v.map(c=>{let u=S.get(c.id);if(u)return{...c,x:u.x,y:u.y,width:u.width,height:u.height};let m=y.get(c.id)??{x:0,y:0};return{...c,x:c.x+m.x,y:c.y+m.y}}),T=new Map(w.map(c=>[c.id,c]));w.forEach(c=>{c.parent=c.parent?T.get(c.parent.id)??c.parent:c.parent});let E=new Map;v.forEach(c=>(c.outgoing||[]).forEach(c=>{let u=c;j(u)&&E.set(u.id,u)})),E.size!==0&&computeMessageFlowRoutes([...E.values()].map(c=>({...c,source:c.source?T.get(c.source.id)??c.source:c.source,target:c.target?T.get(c.target.id)??c.target:c.target})),w,u.routes.filter(c=>!j(c.connection)).map(c=>c.waypoints),m,h,g).forEach(({connection:c,waypoints:m})=>{let h=E.get(c.id);if(!h)return;let g=u.routes.find(u=>u.connection.id===c.id);g?g.waypoints=m:u.routes.push({connection:h,waypoints:m})})}var zn=16,Bn=4e3,Vn=8,Hn=600,Un=1200,Wn=260;function seatsAlong(c){if(c.length===0)return[];let u=[],m=w(c);if(m===0)return[c[0]];let h=m/zn,g=0,v=0;for(let m=0;m+1<c.length;m++){let y=c[m],S=c[m+1],w=Math.abs(S.x-y.x)+Math.abs(S.y-y.y);for(;w>0&&v<=g+w;){let c=(v-g)/w;u.push({x:y.x+(S.x-y.x)*c,y:y.y+(S.y-y.y)*c}),v+=h}g+=w}return u.push(c[c.length-1]),u}function bestSeatOn(c,u,m,h,g){let v={x:u.x+u.width/2,y:u.y+u.height/2},y;return seatsAlong(c).forEach(c=>{let S={x:c.x,y:c.y,width:0,height:0},w={x:Math.max(u.x,Math.min(c.x,u.x+u.width)),y:Math.max(u.y,Math.min(c.y,u.y+u.height))},T=m?[w,c]:[c,w],E=bestAssociation(m?u:S,m?S:u,h,g),D=(Math.abs(w.x-c.x)<.5||Math.abs(w.y-c.y)<.5)&&I(T,h)===0&&g.reduce((c,u)=>c+$(T,u),0)<=g.reduce((c,u)=>c+$(E,u),0)?T:E,k=I(D,h),j=k>0?routeByVisibility({x:u.x+u.width/2,y:u.y+u.height/2},c,h,g,20):null,M=j&&I(j,h)<k?m?j:[...j].reverse():D,P=Math.abs(c.x-v.x)+Math.abs(c.y-v.y),L=I(M,h)*Bn+g.reduce((c,u)=>c+$(M,u),0)*Hn+g.filter(c=>N(M,c)).length*Un+P;(!y||L<y.price)&&(y={at:S,waypoints:M,price:L})}),y?{at:y.at,waypoints:y.waypoints}:{at:u,waypoints:[]}}function withoutElement(c,u){return c.flatMap(c=>{if(!c.elements.some(c=>c.id===u))return[c];let m=c.elements.filter(c=>c.id!==u);return m.length===0?[]:[{...c,elements:m}]})}function anchorEdgeNotes(c,u){let{every:m,rectOf:h,refresh:g}=settledGeometry(c,u),v=new Map(u.routes.map(c=>[c.connection.id,c.waypoints])),y=m.filter(c=>!Z.has(c.type??``)&&!c.source&&!c.target&&c.width>0&&c.height>0),w=m.filter(c=>c.type===`bpmn:TextAnnotation`&&!c.source&&!c.target&&c.width>0&&c.height>0),E=[],lineage=c=>{let u=new Set,m=c?.parent;for(;m;)u.add(m.id),m=m.parent;return u},container=c=>c.type===`bpmn:Lane`||c.type===`bpmn:Participant`||c.type===`bpmn:SubProcess`,D=new Map;u.routes.forEach(c=>{let u=c.connection;if(u.type!==`bpmn:Association`)return;let m=[u.source,u.target].filter(c=>!!c),h=m.find(c=>!!c.source&&!!c.target),g=m.find(c=>c!==h);h&&g&&v.get(h.id)&&(D.has(g.id)||D.set(g.id,{note:g,links:[]}),D.get(g.id).links.push({op:c,owner:h}))}),D.forEach(({note:c,links:D})=>{let k=h(c),j=lineage(c),M=m.find(c=>container(c)&&j.has(c.id)),N=new Set([c.id,...j,...D.flatMap(({owner:c})=>[c.id,...lineage(c)])]),P=y.filter(c=>!N.has(c.id)).map(h),L=y.filter(c=>!N.has(c.id)&&!container(c)).flatMap(c=>c.label?[h(c),h(c.label)]:[h(c)]).concat(w.filter(u=>u.id!==c.id).map(h)).concat(E),z=m.filter(c=>container(c)&&!j.has(c.id)).map(h),B=u.routes.filter(c=>!D.some(({op:u})=>u.connection.id===c.connection.id)).map(c=>c.waypoints),drawFrom=u=>D.map(({op:m,owner:h})=>({op:m,line:bestSeatOn(v.get(h.id),u,m.connection.source?.id===c.id,P,B)})),cutsIn=c=>c.reduce((c,{line:u})=>c+I(u.waypoints,P),0),runOf=c=>c.reduce((c,{line:u})=>c+u.waypoints.reduce((c,m,h)=>h===0?0:c+Math.abs(m.x-u.waypoints[h-1].x)+Math.abs(m.y-u.waypoints[h-1].y),0),0),badly=c=>cutsIn(c)>0||runOf(c)>Wn*D.length,V=u.moves.filter(u=>u.elements.some(u=>u.id===c.id)),H={x:k.x-V.reduce((c,u)=>c+u.dx,0),y:k.y-V.reduce((c,u)=>c+u.dy,0),width:k.width,height:k.height},U=k,W=drawFrom(k);if(badly(W)){let c=W[0].line.at;for(let u=1;u<=Vn&&badly(W);u++){let m=On*u;[{x:c.x-k.width/2,y:c.y+m},{x:c.x-k.width/2,y:c.y-m-k.height},{x:c.x+m,y:c.y-k.height/2},{x:c.x-m-k.width,y:c.y-k.height/2}].map(c=>({x:c.x,y:c.y,width:k.width,height:k.height})).forEach(c=>{if(!badly(W)||L.some(u=>S(c,u))||z.some(u=>S(c,u))||M&&!T(h(M),c))return;let u=drawFrom(c);cutsIn(u)>0||runOf(u)>=runOf(W)||(U=c,W=u)})}}if(cutsIn(W)>0){let m=drawFrom(H);cutsIn(m)<cutsIn(W)&&(u.moves=withoutElement(u.moves,c.id),g(),W=m,U=k)}U!==k&&(u.moves.push({elements:[c],dx:U.x-k.x,dy:U.y-k.y}),E.push(U)),W.forEach(({op:c,line:u})=>{c.waypoints=u.waypoints})})}function straightenAssociations(c,u){let{every:m,rectOf:h}=settledGeometry(c,u),g=m.filter(c=>c.type!==`bpmn:Participant`&&c.type!==`bpmn:Lane`&&c.type!==`bpmn:SubProcess`&&c.width>0&&c.height>0).map(h);u.routes.forEach(c=>{if(!(c.connection.type??``).includes(`Association`))return;let v=c.connection.source,y=c.connection.target;if(!v||!y)return;let S=new Set([v.id,y.id]),w=m.filter(c=>!S.has(c.id)&&g.length>0).filter(c=>c.type!==`bpmn:Participant`&&c.type!==`bpmn:Lane`&&c.type!==`bpmn:SubProcess`&&c.width>0&&c.height>0).map(h),T=u.routes.filter(u=>u!==c).map(c=>c.waypoints);c.waypoints=bestAssociation(h(v),h(y),w,T)})}function routeSignature(c){return c.routes.map(c=>`${c.connection.id}:${c.waypoints.map(c=>`${Math.round(c.x)},${Math.round(c.y)}`).join(` `)}`).join(`|`)}function settleRoutes(c,u,m,h=bn){for(let g=1;g<=h;g++){let h=routeSignature(u);if(repairRoutes(c,u,m),untangleRoutes(c,u),routeSignature(u)===h)return g}return h}function recordWidened(c,u){if(c.length===0)return;let m=new Map;u.moves.forEach(c=>c.elements.forEach(u=>{let h=m.get(u.id)??{x:0,y:0};m.set(u.id,{x:h.x+c.dx,y:h.y+c.dy})}));let h=new Map(u.resizes.map(c=>[c.element.id,c]));c.forEach(c=>{if(h.has(c.id))return;let g=m.get(c.id)??{x:0,y:0};u.resizes.push({element:c,x:c.x+g.x,y:c.y+g.y,width:c.width,height:c.height})})}function grazeCount(c,u){let m=0;for(let h=0;h+1<c.length;h++){let g=H(c[h],c[h+1]);g&&u.some(c=>re(g,c))&&(m+=1)}return m}function grazingBoxes(c,u){let m=new Set;for(let h=0;h+1<c.length;h++){let g=H(c[h],c[h+1]);g&&u.forEach((c,u)=>{re(g,c)&&m.add(u)})}return m}function introducesNewGraze(c,u){for(let m of u)if(!c.has(m))return!0;return!1}var Gn=[8,-8,16,-16,24,-24,32,-32,40,-40,60,-60,80,-80,100,-100,120,-120,160,-160,200,-200,300,-300,400,-400];function nudgeMergedRuns(c,u){let{every:m,rectOf:h}=settledGeometry(c,u),lineage=c=>{let u=new Set,m=c?.parent;for(;m;)u.add(m.id),m=m.parent;return u},wallsOf=c=>{let u=new Set([c.connection.source?.id,c.connection.target?.id,...lineage(c.connection.source),...lineage(c.connection.target)]);return m.filter(c=>!W(c)&&!K(c)&&!G.has(c.type??``)&&c.width>0&&c.height>0&&!u.has(c.id)).map(c=>({id:c.id,rect:h(c)}))},tally=()=>{let c=0;for(let m=0;m<u.routes.length;m++)for(let h=m+1;h<u.routes.length;h++)$(u.routes[m].waypoints,u.routes[h].waypoints)>0&&(c+=1);return c},g=tally(),v=u.routes.map(c=>c.waypoints);u.routes.forEach(c=>{let m=u.routes.filter(u=>u!==c).map(c=>c.waypoints),g=wallsOf(c),v=g.map(c=>c.rect),jogClear=(c,u)=>!segmentHitsAnyRect(c,u,v),y=c.connection.source?h(c.connection.source):void 0,S=c.connection.target?h(c.connection.target):void 0;for(let u=0;u+1<c.waypoints.length;u++){let h=c.waypoints,w=h[u],T=h[u+1],E=Math.abs(w.y-T.y)<.5,D=Math.abs(w.x-T.x)<.5;if(!E&&!D)continue;let j=u===0,P=u+1===h.length-1,L=u+1;if(j)for(;L+1<h.length&&(E?Math.abs(h[L+1].y-w.y)<.5:Math.abs(h[L+1].x-w.x)<.5);)L+=1;let z=u;if(P)for(;z-1>=0&&(E?Math.abs(h[z-1].y-T.y)<.5:Math.abs(h[z-1].x-T.x)<.5);)--z;let B=m.filter(c=>N(h,c)).length,V=grazeCount(h,v);if(B===0&&V===0)continue;let H=m.filter(c=>$(h,c)>0).length,U=I(h,v),W=Q(h),ee=M(h,jogClear);for(let u of Gn){let w=h.map(c=>({...c}));for(let c=z;c<=L;c++)E?w[c].y+=u:w[c].x+=u;let T=te(w);if(!k(T)||y&&!onShape(T[0],y)||S&&!onShape(T[T.length-1],S)||I(T,v)>U||addsCut(T,h,g)||m.filter(c=>$(T,c)>0).length>H||Q(T)>W||M(T,jogClear)>ee)continue;let D=m.filter(c=>N(T,c)).length,j=grazeCount(T,v);if(!(D>B||j>V)&&!(D>=B&&j>=V)){c.waypoints=T;break}}}let w=m.filter(u=>N(c.waypoints,u)).length,T=grazeCount(c.waypoints,v);if(w===0&&T===0)return;let E=c.waypoints[0],D=c.waypoints[c.waypoints.length-1],j=m.filter(u=>$(c.waypoints,u)>0).length,P=Q(c.waypoints),L=I(c.waypoints,v),z=c.waypoints,B=w,V=T;routeVariants(c.waypoints).forEach(u=>{let h=u[0],y=u[u.length-1];if(h.x!==E.x||h.y!==E.y||y.x!==D.x||y.y!==D.y||!k(u)||I(u,v)>L||addsCut(u,c.waypoints,g)||m.filter(c=>$(u,c)>0).length>j||Q(u)>P)return;let S=m.filter(c=>N(u,c)).length,w=grazeCount(u,v);S>B||w>V||S>=B&&w>=V||(z=u,B=S,V=w)}),c.waypoints=z}),tally()>g&&u.routes.forEach((c,u)=>{c.waypoints=v[u]})}function isRoundLike(c){return!!c&&((c.type??``).includes(`Gateway`)||(c.type??``).includes(`Event`))}var Kn=4,qn=Gn[0];function centerRoundAnchors(c,u){let{every:m,rectOf:h}=settledGeometry(c,u),lineage=c=>{let u=new Set,m=c?.parent;for(;m;)u.add(m.id),m=m.parent;return u},wallsOf=c=>{let u=new Set([c.connection.source?.id,c.connection.target?.id,...lineage(c.connection.source),...lineage(c.connection.target)]);return m.filter(c=>!W(c)&&c.type!==`bpmn:Lane`&&!K(c)&&!G.has(c.type??``)&&c.width>0&&c.height>0&&!u.has(c.id)).map(c=>h(c))},sideOf=(c,u,m)=>{let g=h(c),v=Math.abs(u.y-m.y)<.5&&Math.abs(u.x-m.x)>=.5;if(Math.abs(u.x-m.x)<.5&&Math.abs(u.y-m.y)>=.5)return u.y<=g.y+g.height/2?`n`:`s`;if(v)return u.x<=g.x+g.width/2?`w`:`e`},g=new Set,v=new Map;{let c=new Set;u.routes.forEach(u=>{let m=u.waypoints;if(m.length<2)return;[u.connection.source,u.connection.target].forEach(u=>{u&&isRoundLike(u)&&(c.has(u.id)?g.add(u.id):c.add(u.id))});let h=u.connection.source;if(h&&isRoundLike(h)){let c=sideOf(h,m[0],m[1]),g=`${h.id}:${c}`;c&&v.set(g,[...v.get(g)??[],`${u.connection.id}:s`])}let y=u.connection.target;if(y&&isRoundLike(y)){let c=sideOf(y,m[m.length-1],m[m.length-2]),h=`${y.id}:${c}`;c&&v.set(h,[...v.get(h)??[],`${u.connection.id}:t`])}}),v.forEach(c=>c.sort())}u.routes.forEach(c=>{if(c.waypoints.length<2||!(c.connection.source&&g.has(c.connection.source.id)||c.connection.target&&g.has(c.connection.target.id)))return;let m=u.routes.filter(u=>u!==c).map(c=>c.waypoints),y=wallsOf(c),tryCenter=u=>{let g=c.waypoints;if(g.length<2)return;let S=u?c.connection.source:c.connection.target;if(!isRoundLike(S)||!S)return;let w=u?0:g.length-1,T=u?1:g.length-2,E=g[w],D=g[T],j=Math.abs(E.y-D.y)<.5&&Math.abs(E.x-D.x)>=.5,M=Math.abs(E.x-D.x)<.5&&Math.abs(E.y-D.y)>=.5;if(!j&&!M)return;let P=sideOf(S,E,D),L=`${c.connection.id}:${u?`s`:`t`}`,z=P?v.get(`${S.id}:${P}`)??[L]:[L],B=Math.max(0,z.indexOf(L)),V=h(S),H=j?V.width:V.height,U=Math.min(H/2-Kn,Math.max(10,H*.4)),W=Math.ceil(B/2),ee=B===0?0:W*U*(B%2==1?1:-1),G=j?{x:E.x,y:V.y+V.height/2+ee}:{x:V.x+V.width/2+ee,y:E.y};if(Math.abs(G.x-E.x)<Kn&&Math.abs(G.y-E.y)<Kn)return;let K=j?Math.sign(D.x-E.x)||1:Math.sign(D.y-E.y)||1,Z=j?{x:G.x+K*qn,y:G.y}:{x:G.x,y:G.y+K*qn},ne=j?{x:Z.x,y:E.y}:{x:E.x,y:Z.y},re=u?[G,Z,ne,...g.slice(1).map(c=>({...c}))]:[...g.slice(0,-1).map(c=>({...c})),ne,Z,G],ae=u?g[2]:g[g.length-3],oe=j?{x:D.x,y:G.y}:{x:G.x,y:D.y},se=ae&&(u?[G,oe,...g.slice(2).map(c=>({...c}))]:[...g.slice(0,-2).map(c=>({...c})),oe,G]),le=m.filter(c=>N(g,c)).length,de=grazingBoxes(g,y),fe=m.filter(c=>$(g,c)>0).length,pe=I(g,y),me=Q(g);for(let u of[se,re]){if(!u)continue;let h=te(u);if(k(h)&&!(I(h,y)>pe)&&!(Q(h)>me)&&!(m.filter(c=>$(h,c)>0).length>fe)&&!(m.filter(c=>N(h,c)).length>le)&&!introducesNewGraze(de,grazingBoxes(h,y))){c.waypoints=h;return}}};tryCenter(!0),tryCenter(!1)})}var Jn=30,Yn=60;function airOutSharedNodeRuns(c,u){let{every:m,rectOf:h}=settledGeometry(c,u),lineage=c=>{let u=new Set,m=c?.parent;for(;m;)u.add(m.id),m=m.parent;return u},wallsOf=c=>{let u=new Set([c.connection.source?.id,c.connection.target?.id,...lineage(c.connection.source),...lineage(c.connection.target)]);return m.filter(c=>!W(c)&&c.type!==`bpmn:Lane`&&!K(c)&&!G.has(c.type??``)&&c.width>0&&c.height>0&&!u.has(c.id)).map(c=>h(c))},endpointIds=c=>[c.connection.source?.id,c.connection.target?.id].filter(c=>!!c);u.routes.forEach(c=>{let m=u.routes.filter(u=>u!==c&&endpointIds(u).some(u=>endpointIds(c).includes(u)));if(m.length===0)return;let g=u.routes.filter(u=>u!==c).map(c=>c.waypoints),v=wallsOf(c);for(let u=0;u+1<c.waypoints.length;u++){let y=c.waypoints,S=y[u],w=y[u+1],T=Math.abs(S.y-w.y)<.5&&Math.abs(S.x-w.x)>=.5,E=Math.abs(S.x-w.x)<.5&&Math.abs(S.y-w.y)>=.5;if(!T&&!E)continue;let D=T?`y`:`x`,j=T?S.y:S.x,M=Math.min(T?S.x:S.y,T?w.x:w.y),P=Math.max(T?S.x:S.y,T?w.x:w.y);if(!m.some(c=>ee(c.waypoints).some(c=>c.axis!==D||Math.abs(c.at-j)>=Jn?!1:Math.min(P,c.to)-Math.max(M,c.from)>=Yn)))continue;let L=m.flatMap(c=>ee(c.waypoints).map(c=>c)).filter(c=>c.axis!==D||Math.abs(c.at-j)>=Jn?!1:Math.min(P,c.to)-Math.max(M,c.from)>=Yn),z=g.filter(c=>N(y,c)).length,B=grazingBoxes(y,v),V=g.filter(c=>$(y,c)>0).length,H=I(y,v),U=Q(y),isRoundLike=c=>!!c&&((c.type??``).includes(`Gateway`)||(c.type??``).includes(`Event`)),W=u===0&&isRoundLike(c.connection.source),G=u+1===y.length-1&&isRoundLike(c.connection.target),K=(W||G)&&!(W&&G),Z=Gn[0],centerOf=(c,u)=>T?{x:u.x,y:c.y+c.height/2}:{x:c.x+c.width/2,y:u.y},ne=W&&c.connection.source?centerOf(h(c.connection.source),y[0]):y[0],re=G&&c.connection.target?centerOf(h(c.connection.target),y[y.length-1]):y[y.length-1],buildCandidate=c=>{if(!K){let m=y.map(c=>({...c}));return T?(m[u].y+=c,m[u+1].y+=c):(m[u].x+=c,m[u+1].x+=c),m}if(W){let u={...ne},m=y[1],h=T?{x:u.x+(Math.sign(m.x-u.x)||1)*Z,y:u.y}:{x:u.x,y:u.y+(Math.sign(m.y-u.y)||1)*Z};return[u,h,T?{x:h.x,y:m.y+c}:{x:m.x+c,y:h.y},T?{x:m.x,y:m.y+c}:{x:m.x+c,y:m.y},...y.slice(2).map(c=>({...c}))]}let m=y.length,h={...re},g=y[m-2],v=T?{x:h.x+(Math.sign(g.x-h.x)||1)*Z,y:h.y}:{x:h.x,y:h.y+(Math.sign(g.y-h.y)||1)*Z},S=T?{x:v.x,y:g.y+c}:{x:g.x+c,y:v.y},w=T?{x:g.x,y:g.y+c}:{x:g.x+c,y:g.y};return[...y.slice(0,m-2).map(c=>({...c})),w,S,v,h]},ae=!1;for(let m of[!0,!1]){if(ae)break;for(let S of Gn){let w=buildCandidate(S),E=te(w);if(!k(E))continue;if(W){if(E[0].x!==ne.x||E[0].y!==ne.y)continue}else if(E[0].x!==y[0].x||E[0].y!==y[0].y){if(u!==0)continue;let m=c.connection.source?h(c.connection.source):void 0;if(!m||!onShape(E[0],m))continue}if(G){if(E[E.length-1].x!==re.x||E[E.length-1].y!==re.y)continue}else if(E[E.length-1].x!==y[y.length-1].x||E[E.length-1].y!==y[y.length-1].y){if(u+1!==y.length-1)continue;let m=c.connection.target?h(c.connection.target):void 0;if(!m||!onShape(E[E.length-1],m))continue}if(I(E,v)>H||Q(E)>U||g.filter(c=>$(E,c)>0).length>V||g.filter(c=>N(E,c)).length>z||introducesNewGraze(B,grazingBoxes(E,v)))continue;let D=T?W?w[2].y:G?w[w.length-3].y:w[u].y:W?w[2].x:G?w[w.length-3].x:w[u].x;if(m){if(L.some(c=>Math.abs(c.at-D)<Jn))continue}else if(L.some(c=>Math.abs(c.at-D)<Math.abs(c.at-j)))continue;c.waypoints=E,ae=!0;break}}}})}var Xn=2,Zn=20,Qn=20,$n=150;function clearEdgeTouchingRuns(c,u){let{every:m,rectOf:h}=settledGeometry(c,u),lineage=c=>{let u=new Set,m=c?.parent;for(;m;)u.add(m.id),m=m.parent;return u},wallsOf=c=>{let u=new Set([c.connection.source?.id,c.connection.target?.id,...lineage(c.connection.source),...lineage(c.connection.target)]);return m.filter(c=>!W(c)&&c.type!==`bpmn:Lane`&&!K(c)&&!G.has(c.type??``)&&c.width>0&&c.height>0&&!u.has(c.id)).map(c=>h(c))};u.routes.forEach(c=>{let m=u.routes.filter(u=>u!==c).map(c=>c.waypoints),g=wallsOf(c);for(let u=0;u+1<c.waypoints.length;u++){let v=c.waypoints,y=v[u],S=v[u+1],w=Math.abs(y.y-S.y)<.5&&Math.abs(y.x-S.x)>=.5,T=Math.abs(y.x-S.x)<.5&&Math.abs(y.y-S.y)>=.5;if(!w&&!T)continue;let E=w?`y`:`x`,D=w?y.y:y.x,j=Math.min(w?y.x:y.y,w?S.x:S.y),M=Math.max(w?y.x:y.y,w?S.x:S.y);if(M-j<$n)continue;let P=g.filter(c=>{if(!(E===`x`?[c.x,c.x+c.width]:[c.y,c.y+c.height]).some(c=>Math.abs(c-D)<=Xn))return!1;let u=E===`x`?c.y:c.x,m=E===`x`?c.y+c.height:c.x+c.width;return Math.min(M,m)-Math.max(j,u)>=Qn});if(P.length===0)continue;let L=m.filter(c=>N(v,c)).length,z=grazingBoxes(v,g),B=m.filter(c=>$(v,c)>0).length,V=I(v,g),H=Q(v);for(let y of Gn){let S=v.map(c=>({...c}));w?(S[u].y+=y,S[u+1].y+=y):(S[u].x+=y,S[u+1].x+=y);let T=te(S);if(!k(T))continue;if(u===0){let u=c.connection.source?h(c.connection.source):void 0;if(!u||!onShape(T[0],u))continue}else if(T[0].x!==v[0].x||T[0].y!==v[0].y)continue;if(u+1===v.length-1){let u=c.connection.target?h(c.connection.target):void 0;if(!u||!onShape(T[T.length-1],u))continue}else if(T[T.length-1].x!==v[v.length-1].x||T[T.length-1].y!==v[v.length-1].y)continue;if(I(T,g)>V||Q(T)>H||m.filter(c=>$(T,c)>0).length>B||m.filter(c=>N(T,c)).length>L||introducesNewGraze(z,grazingBoxes(T,g)))continue;let D=w?S[u].y:S[u].x;if(!P.some(c=>(E===`x`?[c.x,c.x+c.width]:[c.y,c.y+c.height]).some(c=>Math.abs(c-D)<Zn))){c.waypoints=T;break}}}})}var er=2,rr=40;function shortenDetouredRoutes(c,u){let{every:m,rectOf:h}=settledGeometry(c,u),g=m.filter(c=>!W(c)&&!K(c)&&c.type!==`bpmn:Lane`&&!G.has(c.type??``)&&c.width>0&&c.height>0),lineage=c=>{let u=new Set,m=c?.parent;for(;m;)u.add(m.id),m=m.parent;return u},tally=()=>{let c=0;for(let m=0;m<u.routes.length;m++)for(let h=m+1;h<u.routes.length;h++)$(u.routes[m].waypoints,u.routes[h].waypoints)>0&&(c+=1);return c},v=tally(),y=u.routes.map(c=>c.waypoints);u.routes.forEach(c=>{let m=c.connection;if(!j(m)||!m.source||!m.target)return;let v=c.waypoints;if(v.length<2)return;let y=w(v),S=h(m.source),T=h(m.target),E=Math.abs(S.x+S.width/2-(T.x+T.width/2))+Math.abs(S.y+S.height/2-(T.y+T.height/2));if(E<rr||y<=E*er)return;let D=new Set([m.source.id,m.target.id,...lineage(m.source),...lineage(m.target)]),M=g.filter(c=>!D.has(c.id)).map(h),P=u.routes.filter(u=>u!==c).map(c=>c.waypoints),L=P.reduce((c,u)=>c+ +($(v,u)>0),0),z=P.filter(c=>N(v,c)).length,B=Q(v),V=bestAssociation(S,T,M,P),H=I(V,M)===0,U=H?[V]:routeVariants(v),W=v[0],ee=v[v.length-1],G,K=y;U.forEach(c=>{if(!H){let u=c[0],m=c[c.length-1];if(Math.abs(u.x-W.x)>2||Math.abs(u.y-W.y)>2||Math.abs(m.x-ee.x)>2||Math.abs(m.y-ee.y)>2)return}if(I(c,M)>0||!k(c)||Q(c)>B)return;let u=w(c);u>=K||P.reduce((u,m)=>u+ +($(c,m)>0),0)>L||P.filter(u=>N(c,u)).length>z||(K=u,G=c)}),G&&(c.waypoints=G)}),tally()>v&&u.routes.forEach((c,u)=>{c.waypoints=y[u]})}function redockRoundShapeSides(c,u){let{every:m,rectOf:h}=settledGeometry(c,u),g=m.filter(c=>!W(c)&&!K(c)&&c.type!==`bpmn:Lane`&&!G.has(c.type??``)&&c.width>0&&c.height>0),lineage=c=>{let u=new Set,m=c?.parent;for(;m;)u.add(m.id),m=m.parent;return u},tally=()=>{let c=0;for(let m=0;m<u.routes.length;m++)for(let h=m+1;h<u.routes.length;h++)$(u.routes[m].waypoints,u.routes[h].waypoints)>0&&(c+=1);return c},v=tally(),y=u.routes.map(c=>c.waypoints);u.routes.forEach(c=>{let m=c.connection;if(!m.source||!m.target||!isRoundLike(m.source)&&!isRoundLike(m.target))return;let v=c.waypoints;if(v.length<2)return;let y=w(v),S=h(m.source),T=h(m.target),E=new Set([m.source.id,m.target.id,...lineage(m.source),...lineage(m.target)]),D=g.filter(c=>!E.has(c.id)).map(h),j=u.routes.filter(u=>u!==c).map(c=>c.waypoints),M=j.reduce((c,u)=>c+ +($(v,u)>0),0),P=j.filter(c=>N(v,c)).length,L=Q(v),z=bestAssociation(S,T,D,j);I(z,D)>0||k(z)&&(Q(z)>L||w(z)>=y||j.reduce((c,u)=>c+ +($(z,u)>0),0)>M||j.filter(c=>N(z,c)).length>P||(c.waypoints=z))}),tally()>v&&u.routes.forEach((c,u)=>{c.waypoints=y[u]})}function tidyRoutes(c){c.routes.forEach(c=>{c.waypoints=E(c.waypoints)})}function spreadRuns(c,u,m,g=`vpsc`){let{every:v,rectOf:y}=settledGeometry(c,u),S=v.filter(c=>!W(c)&&!K(c)&&c.type!==`bpmn:Lane`&&!G.has(c.type??``)).map(y),crossingsOf=(c,m)=>u.routes.reduce((u,h)=>h===m?u:u+$(c,h.waypoints),0),tally=()=>{let c=0;for(let m=0;m<u.routes.length;m++)for(let h=m+1;h<u.routes.length;h++)$(u.routes[m].waypoints,u.routes[h].waypoints)>0&&(c+=1);return c},w=tally(),T=u.routes.map(c=>c.waypoints),lineage=c=>{let u=new Set,m=c?.parent;for(;m;)u.add(m.id),m=m.parent;return u},wallsOf=c=>{let u=new Set([c.connection.source?.id,c.connection.target?.id,...lineage(c.connection.source),...lineage(c.connection.target)]);return v.filter(c=>!W(c)&&!K(c)&&!G.has(c.type??``)&&c.width>0&&c.height>0&&!u.has(c.id)).map(c=>({id:c.id,rect:y(c)}))},wallsFor=c=>wallsOf(c).map(c=>c.rect);(g===`lattice`?latticeShifts(u.routes,wallsFor):g===`border`?borderShifts(u.routes,wallsFor):g===`ordered`?orderedShifts(u.routes,m):separateRuns(u.routes,m)).forEach(({route:c,index:u,axis:m,at:g})=>{let v=c.waypoints;if(u+1>=v.length)return;let w=v.map(c=>({...c})),T=m===`y`?{y:g}:{x:g};w[u]={...w[u],...T},w[u+1]={...w[u+1],...T};let E=k(w),D=c.connection.source?y(c.connection.source):void 0,j=c.connection.target?y(c.connection.target):void 0,M=(!D||onShape(w[0],D))&&(!j||onShape(w[w.length-1],j));if(!E||!M)return;let N=wallsOf(c),P=N.map(c=>c.rect);h(w[u],w[u+1],P)>h(v[u],v[u+1],P)||addsCut(w,v,N)||I(w,S)>I(v,S)||crossingsOf(w,c)>crossingsOf(v,c)||Q(w)>Q(v)||(c.waypoints=w)}),tally()>w?u.routes.forEach((c,u)=>{c.waypoints=T[u]}):u.routes.forEach(c=>{c.waypoints=te(c.waypoints)})}function flattenJogs(c,u){let{every:m,rectOf:h}=settledGeometry(c,u),g=m.filter(c=>!W(c)&&!K(c)&&c.type!==`bpmn:Lane`&&!G.has(c.type??``)).map(c=>({id:c.id,rect:h(c)})),v=g.map(c=>c.rect),y=m.filter(c=>!W(c)&&!K(c)&&c.type!==`bpmn:Lane`&&!G.has(c.type??``)&&(c.children||[]).filter(c=>!W(c)&&!K(c)).length===0).map(h),crossingsOf=(c,m)=>u.routes.reduce((u,h)=>h===m?u:u+$(c,h.waypoints),0),mergesOf=(c,m)=>u.routes.filter(u=>u!==m&&N(c,u.waypoints)).length;u.routes.forEach(c=>{for(let u=0;u<Tn;u++){let u=c.waypoints,m=!0;for(let S=0;S+3<u.length;S++){let[w,T,E,D]=[u[S],u[S+1],u[S+2],u[S+3]],j=w.x===T.x&&E.x===D.x&&T.y===E.y,M=w.y===T.y&&E.y===D.y&&T.x===E.x,N=j?Math.abs(T.x-E.x):M?Math.abs(T.y-E.y):0;if(!j&&!M||N<.5||N>=40)continue;let P=c.connection.source?h(c.connection.source):void 0,L=c.connection.target?h(c.connection.target):void 0,z=j?[w.x,D.x]:[w.y,D.y];for(let h of z){let w=u.map(c=>({...c}));for(let c=0;c<=3;c++)j?w[S+c].x=h:w[S+c].y=h;let T=te(w),E=k(T),D=(!P||onShape(T[0],P))&&(!L||onShape(T[T.length-1],L));if(E&&D&&!(I(T,v)>I(u,v))&&!(I(T,y)>I(u,y))&&!addsCut(T,u,g)&&!(crossingsOf(T,c)>crossingsOf(u,c))&&!(mergesOf(T,c)>mergesOf(u,c))&&!(Q(T)>Q(u))){c.waypoints=T,m=!1;break}}if(!m)break}if(m)break}})}function straightenRoutes(c,u){let{every:m,rectOf:h}=settledGeometry(c,u),g=m.filter(c=>c.type!==`bpmn:Lane`&&!G.has(c.type??``)&&c.width>0&&c.height>0),homeOf=c=>{let u=new Set,m=c?.parent;for(;m;)u.add(m.id),m=m.parent;return u},hugsBorder=(c,u,m)=>{let g=h(c);if(Math.abs(u.y-m.y)<.5){let c=u.y;if(Math.abs(c-g.y)<.5||Math.abs(c-(g.y+g.height))<.5){let c=Math.min(u.x,m.x);return Math.max(u.x,m.x)>g.x&&c<g.x+g.width}}if(Math.abs(u.x-m.x)<.5){let c=u.x;if(Math.abs(c-g.x)<.5||Math.abs(c-(g.x+g.width))<.5){let c=Math.min(u.y,m.y);return Math.max(u.y,m.y)>g.y&&c<g.y+g.height}}return!1};for(let c=0;c<Tn;c++){let c=!1;if(u.routes.forEach(m=>{if(m.waypoints.length<=wn)return;let v=m.connection,y=new Set([v.source?.id??``,v.target?.id??``,...homeOf(v.source),...homeOf(v.target)]),S=g.filter(c=>!y.has(c.id)).map(h),T=u.routes.filter(c=>c!==m).map(c=>c.waypoints),tally=c=>I(c,S)*1e6+T.reduce((u,m)=>u+$(c,m),0)*1e4+c.length*200+w(c),E=tally(m.waypoints),D=!!v.source&&hugsBorder(v.source,m.waypoints[0],m.waypoints[1]),k=!!v.target&&hugsBorder(v.target,m.waypoints[m.waypoints.length-1],m.waypoints[m.waypoints.length-2]),j=m.waypoints,M=E;routeVariants(m.waypoints,!0).forEach(c=>{if(!D&&v.source&&hugsBorder(v.source,c[0],c[1])||!k&&v.target&&hugsBorder(v.target,c[c.length-1],c[c.length-2]))return;let u=tally(c);u<M&&(M=u,j=c)}),j!==m.waypoints&&(m.waypoints=j,c=!0)}),!c)break}}var mr=[20,60,120,300],br=150,xr=[6,3,1];function thickenPath(c,u){let m=[];for(let h=0;h+1<c.length;h++){let g=c[h],v=c[h+1];m.push({x:Math.min(g.x,v.x)-u,y:Math.min(g.y,v.y)-u,width:Math.abs(v.x-g.x)+u*2,height:Math.abs(v.y-g.y)+u*2})}return m}function axisCrossingOnPath(c,u,m,h){let g,v=1/0;for(let y=0;y+1<c.length;y++){let S=c[y],w=c[y+1],T;if(u===`x`&&S.y===w.y){let c=Math.min(S.x,w.x),u=Math.max(S.x,w.x);m>=c&&m<=u&&(T={x:m,y:S.y})}else if(u===`y`&&S.x===w.x){let c=Math.min(S.y,w.y),u=Math.max(S.y,w.y);m>=c&&m<=u&&(T={x:S.x,y:m})}if(!T)continue;let E=Math.abs(T.x-h.x)+Math.abs(T.y-h.y);E<v&&(v=E,g=T)}return g}function nearestPointOnPath(c,u){let m=c[0],h=1/0;for(let g=0;g+1<c.length;g++){let v=c[g],y=c[g+1],S=y.x-v.x,w=y.y-v.y,T=S*S+w*w,E=T===0?0:Math.max(0,Math.min(1,((u.x-v.x)*S+(u.y-v.y)*w)/T)),D={x:v.x+E*S,y:v.y+E*w},k=Math.abs(D.x-u.x)+Math.abs(D.y-u.y);k<h&&(h=k,m=D)}return m}function elbowOptions(c,u){return[[c,{x:u.x,y:c.y},u],[c,{x:c.x,y:u.y},u]]}function reprojectDependents(c,u,m,h,g){let v=[];for(let{route:y,end:S}of c){if(y.waypoints.length<2)return;let c=S===`first`?y.waypoints[0]:y.waypoints[y.waypoints.length-1],w=S===`first`?y.waypoints[1]:y.waypoints[y.waypoints.length-2],T=y.connection.source?h(y.connection.source):void 0,E=y.connection.target?h(y.connection.target):void 0,D=new Set([y.connection.source?.id,y.connection.target?.id,...g(y.connection.source),...g(y.connection.target)]),j=m.filter(c=>!D.has(c.id)).map(h),M=I(y.waypoints,j),N=S===`first`?E:T,P;if(w.x===c.x||w.y===c.y){let m=w.x===c.x?`x`:`y`,h=axisCrossingOnPath(u,m,m===`x`?w.x:w.y,c);if(h){let c=y.waypoints.map(c=>({...c}));S===`first`?c[0]=h:c[c.length-1]=h,k(c)&&I(c,j)<=M&&(P=c)}}if(!P){let m=nearestPointOnPath(u,c),h=S===`first`?y.waypoints.slice(2):y.waypoints.slice(0,-2);for(let c of elbowOptions(w,m)){let u=te(S===`first`?[...c.slice().reverse(),...h]:[...h,...c]);if(k(u)&&!(I(u,j)>M)&&!(Q(u)>0)){P=u;break}}}if(!P)return;let L=S===`first`?P[P.length-1]:P[0];if(N&&!onShape(L,N))return;v.push({dep:y,movedPath:P})}return v}function eliminateMerges(c,u){let{every:m,rectOf:h}=settledGeometry(c,u),g=m.filter(c=>!W(c)&&!K(c)&&c.type!==`bpmn:Lane`&&!G.has(c.type??``)&&c.width>0&&c.height>0),lineage=c=>{let u=new Set,m=c?.parent;for(;m;)u.add(m.id),m=m.parent;return u},dependentsOf=c=>u.routes.filter(u=>u!==c).flatMap(u=>{let{source:m,target:h}=u.connection,g=m?.id===c.connection.id;return g===(h?.id===c.connection.id)?[]:[{route:u,end:g?`first`:`last`}]}),v=[...new Map(u.routes.map(c=>[c,u.routes.filter(u=>u!==c&&N(c.waypoints,u.waypoints)).length])).entries()].sort((c,u)=>u[1]-c[1]).map(([c])=>c),tryClearBystander=(c,u,m,h)=>{let g=c.waypoints,v=Q(g),y=h.reduce((c,u)=>c+ +($(g,u)>0),0);for(let c=1;c+2<g.length;c++){let S=g[c],w=g[c+1],T=Math.abs(S.y-w.y)<.5,E=Math.abs(S.x-w.x)<.5;if(T||E)for(let S of Gn){let w=g.map(c=>({...c}));T?(w[c].y+=S,w[c+1].y+=S):(w[c].x+=S,w[c+1].x+=S);let E=te(w);if(k(E)&&!(I(E,m)>0)&&!N(E,u)&&!h.some(c=>N(E,c))&&!(Q(E)>v)&&!(h.reduce((c,u)=>c+ +($(E,u)>0),0)>y))return E}}};v.forEach(c=>{let m=c.connection;if(!m.source||!m.target)return;let v=u.routes.filter(u=>u!==c),y=v.filter(u=>N(c.waypoints,u.waypoints));if(y.length===0)return;let S=new Set([m.source.id,m.target.id,...lineage(m.source),...lineage(m.target)]),w=g.filter(c=>!S.has(c.id)).map(h),T=v.map(c=>c.waypoints),jogClear=(c,u)=>!segmentHitsAnyRect(c,u,w),E=M(c.waypoints,jogClear),D=c.waypoints[0],j=c.waypoints[c.waypoints.length-1],P=null,L=1/0,z;for(let m of mr){for(let S of xr){let B=y.flatMap(c=>thickenPath(c.waypoints,S)),V=routeByVisibility(D,j,[...w,...B],T,m,void 0,2,br);if(!V||V.length<2||!k(V)||I(V,w)>0)continue;let H=T.reduce((c,u)=>c+ +($(V,u)>0),0);if(P&&H>=L)continue;let U=v.filter(c=>N(V,c.waypoints));if(U.length>1)continue;let W;if(U.length===1){let m=U[0],v=u.routes.filter(c=>c!==m&&N(m.waypoints,c.waypoints)).length,y=v===1&&N(m.waypoints,c.waypoints);if(v>0&&!y||dependentsOf(m).length>0)continue;let S=m.connection,w=new Set([S.source?.id,S.target?.id,...lineage(S.source),...lineage(S.target)]),T=g.filter(c=>!w.has(c.id)).map(h),E=u.routes.filter(u=>u!==c&&u!==m).map(c=>c.waypoints),D=tryClearBystander(m,V,T,E);if(!D)continue;W={bystander:m,waypoints:D}}if(!(M(V,jogClear)>E)&&(P=V,L=H,z=W,L===0))break}if(P&&L===0)break}if(!P)return;let B=reprojectDependents(dependentsOf(c),P,g,h,lineage);B&&(c.waypoints=P,B.forEach(({dep:c,movedPath:u})=>{c.waypoints=u}),z&&(z.bystander.waypoints=z.waypoints))}),resolveMergeClusters(u,g,h,lineage,dependentsOf)}var Sr=4,Cr=4e3;function resolveMergeClusters(c,u,m,h,g){let v=c.routes.filter(u=>c.routes.some(c=>c!==u&&N(u.waypoints,c.waypoints)));if(v.length===0)return;let y=new Set,S=[];v.forEach(c=>{if(y.has(c))return;let u=[],m=[c];for(y.add(c);m.length>0;){let c=m.shift();u.push(c),v.forEach(u=>{y.has(u)||u===c||N(c.waypoints,u.waypoints)&&(y.add(u),m.push(u))})}S.push(u)});let trySolve=v=>{let y=c.routes.filter(c=>!v.includes(c)),S=new Map,w=v.map(c=>{let g=c.connection,v=new Set([g.source?.id,g.target?.id,...h(g.source),...h(g.target)]),S=u.filter(c=>!v.has(c.id)).map(m),w=y.map(c=>c.waypoints),jogClear=(c,u)=>!segmentHitsAnyRect(c,u,S),T=M(c.waypoints,jogClear),E=c.waypoints[0],D=c.waypoints[c.waypoints.length-1],j=new Set,P=[],add=c=>{let u=JSON.stringify(c);j.has(u)||(j.add(u),P.push(c))};add(c.waypoints);for(let u of mr){for(let m of xr){let h=y.flatMap(u=>N(c.waypoints,u.waypoints)?thickenPath(u.waypoints,m):[]),g=routeByVisibility(E,D,[...S,...h],w,u,void 0,2,br);if(!(!g||g.length<2)&&k(g)&&!(I(g,S)>0)&&!(M(g,jogClear)>T)&&(add(g),P.length>=6))break}if(P.length>=6)break}return P});if(w.some(c=>c.length===0)||w.reduce((c,u)=>c*u.length,1)>Cr)return{solved:void 0,blockers:S};let T=y.map(c=>c.waypoints),crossCountOf=c=>T.reduce((u,m)=>u+ +($(c,m)>0),0),E=v.map(c=>g(c)),D=w.map(()=>0),j,P,L=1/0;outer:for(;;){let c=D.map((c,u)=>w[u][c]),g=!0;for(let u=0;u<c.length&&g;u++){for(let m=u+1;m<c.length&&g;m++)N(c[u],c[m])&&(g=!1);if(g){let m=y.find(m=>N(c[u],m.waypoints));m&&(g=!1,S.set(m,(S.get(m)??0)+1))}}let v;if(g){let g=c.reduce((c,u)=>c+crossCountOf(u),0);if(g<L){v=[];for(let g=0;g<c.length&&v;g++){let y=reprojectDependents(E[g],c[g],u,m,h);y?v.push(y):v=void 0}if(v&&(j=c,P=v,L=g,g===0))break outer}}let T=D.length-1;for(;;){if(T<0)break outer;if(D[T]++,D[T]<w[T].length)break;D[T]=0,T--}}return j&&P?{solved:j,solvedDeps:P,blockers:S}:{solved:void 0,blockers:S}};S.forEach(c=>{if(c.length<2||c.length>Sr)return;let u=c,m=trySolve(u);if(!m.solved&&u.length<Sr){let c=[...m.blockers.entries()].sort((c,u)=>u[1]-c[1])[0];c&&(u=[...u,c[0]],m=trySolve(u))}m.solved&&u.forEach((c,u)=>{c.waypoints=m.solved[u],m.solvedDeps[u].forEach(({dep:c,movedPath:u})=>{c.waypoints=u})})})}var LayoutInputError=class extends Error{element;constructor(c,u){super(u),this.element=c}},Dr=1e7,usable=c=>typeof c==`number`&&Number.isFinite(c)&&Math.abs(c)<=Dr;function problemOf(c,u){let h=c.waypoints!==void 0||c.source!==void 0||c.target!==void 0;for(let[u,m]of[[`x`,c.x],[`y`,c.y]])if(!usable(m))return`${u} is ${String(m)}`;for(let[m,g]of[[`width`,c.width],[`height`,c.height]])if(!usable(g)||g<=0&&!h&&!u&&c.type!==`root`&&c.type!==`bpmn:Process`&&c.type!==`label`)return`${m} is ${String(g)}`;for(let u of c.waypoints??[])if(!usable(u?.x)||!usable(u?.y))return m(`app.editor.layoutBadWaypoint`,{x:String(u?.x),y:String(u?.y)});return null}function assertLayoutable(c){let u=new Set,h=[c];for(let g=h.pop();g;g=h.pop()){if(u.has(g))continue;u.add(g);let v=problemOf(g,g===c);if(v)throw new LayoutInputError(g.id,m(`app.editor.layoutBadShape`,{element:g.id||m(`app.editor.layoutAnElement`),problem:v}));h.push(...g.children??[],...g.attachers??[],...g.outgoing??[],...g.incoming??[]),g.label&&h.push(g.label)}}var Or={nodesep:40,ranksep:80,marginX:40,marginY:40},kr={}.BPMN_LAYOUT_ENGINE!==`legacy`,jr=6,Mr=6;function attacherSlot(c){return Math.max(c.width||36,c.label?.width??0)}function attacherSpan(c){return c.reduce((c,u,m)=>c+attacherSlot(u)+(m>0?jr:0),0)}function attacherWidth(c){let u=0;for(let m=0;m<Mr;m++){let{south:m,north:h}=splitAttachers({...c,width:u}),g=Math.max(attacherSpan(m),attacherSpan(h));if(g<=u)break;u=g}return u}function widenForAttachers(c){let u=[],walk=c=>{if((c.attachers||[]).length>0&&layoutChildren(c).length===0){let m=Math.max(c.width,attacherWidth(c));m>c.width&&(c.width=m,u.push(c))}(c.children||[]).forEach(walk)};return(c.children||[]).forEach(walk),u}function attacherOffsets(c,u){let m=new Map,{south:h,north:g}=splitAttachers(c);return[h,g].forEach(c=>{if(c.length===0)return;let h=(u-attacherSpan(c))/2;c.forEach(c=>{m.set(c.id,h+attacherSlot(c)/2),h+=attacherSlot(c)+jr})}),m}function escapesUpward(c){return(c.businessObject?.eventDefinitions||[]).some(c=>c.$type===`bpmn:EscalationEventDefinition`)}function splitAttachers(c){let u=c.attachers||[],m=[],h=u.filter(escapesUpward),g=0;return u.filter(c=>!escapesUpward(c)).forEach(u=>{let v=attacherSlot(u),y=g+(m.length>0?jr:0)+v;m.length===0||y<=c.width?(m.push(u),g=y):h.push(u)}),{south:m,north:h}}function boundaryOverhang(c,u=`SOUTH`){let{south:m,north:h}=splitAttachers(c),g=u===`SOUTH`?m:h;return g.length===0?0:Math.max(...g.map(c=>c.height||36))/2}function collectContainers(c){let u=(c.children||[]).filter(c=>c.type===`bpmn:Participant`);return u.length>0?u:[c]}function collectMoveGroup(c,u=[]){return u.push(c),(c.attachers||[]).forEach(c=>{u.push(c)}),(c.children||[]).forEach(c=>{!W(c)&&!K(c)&&collectMoveGroup(c,u)}),u}function virtualOutgoing(c,u){let m=[];return Z.has(c.type??``)?m:((c.outgoing||[]).forEach(c=>{c.target&&u.has(c.target.id)&&(Z.has(c.target.type??``)||m.push({target:c.target,conn:c,fromBoundary:!1}))}),(c.attachers||[]).forEach(c=>{(c.outgoing||[]).forEach(h=>{h.target&&u.has(h.target.id)&&m.push({target:h.target,conn:h,fromBoundary:!0,sourceAttacherId:c.id})})}),m.map((c,u)=>({edge:c,index:u})).sort((c,u)=>c.edge.target.y+c.edge.target.height/2-(u.edge.target.y+u.edge.target.height/2)||c.index-u.index).map(c=>c.edge))}function computeBoundaryLeafIds(c,u){let m=new Map,h=new Map;c.forEach(c=>{virtualOutgoing(c,u).forEach(c=>{m.set(c.target.id,(m.get(c.target.id)??0)+1),c.fromBoundary&&h.set(c.target.id,(h.get(c.target.id)??0)+1)})});let g=new Set;return c.forEach(c=>{let v=m.get(c.id)??0,y=h.get(c.id)??0,S=virtualOutgoing(c,u).length===0;v>0&&v===y&&S&&g.add(c.id)}),g}function computeAnnotationSources(c,u){let m=new Map;return c.forEach(c=>{(c.outgoing||[]).forEach(h=>{if(!h.target||!u.has(h.target.id))return;let g=Z.has(c.type??``),v=Z.has(h.target.type??``);v&&!g&&!m.has(h.target.id)&&m.set(h.target.id,c),g&&!v&&!m.has(c.id)&&m.set(c.id,h.target)})}),m}function computeBoundaryLeafHosts(c,u){let m=new Map;return c.forEach(c=>{(c.attachers||[]).forEach(h=>{(h.outgoing||[]).forEach(h=>{h.target&&u.has(h.target.id)&&m.set(h.target.id,c)})})}),m}var Nr=20,Pr=2;function clusterCenters(c){let u=new Map,m=[...c].sort((c,u)=>c.center-u.center||(c.id<u.id?-1:1)),h=[],flush=()=>{if(h.length===0)return;let c=[...h.map(c=>c.center)].sort((c,u)=>c-u),m=c[Math.floor(c.length/2)];h.forEach(c=>u.set(c.id,m)),h=[]};return m.forEach(c=>{h.length>0&&c.center-h[0].center>Nr&&flush(),h.push(c)}),flush(),u}function indexByValue(c){let u=[...new Set(c.values())].sort((c,u)=>c-u),m=new Map(u.map((c,u)=>[c,u]));return new Map([...c.entries()].map(([c,u])=>[c,m.get(u)]))}function hasAuthoredLayout(c){let u=c.filter(c=>(c.x??0)!==0||(c.y??0)!==0);if(u.length<2)return!1;let m=new Set(u.map(c=>Math.round(c.x))),h=new Set(u.map(c=>Math.round(c.y)));return m.size>1||h.size>1}function formatAuthoredLayout(c,u,m){let h=c.filter(c=>!Z.has(c.type??``));if(!hasAuthoredLayout(h))return null;let g=clusterCenters(h.map(c=>({id:c.id,center:c.x+(c.width||100)/2}))),v=clusterCenters(h.map(c=>({id:c.id,center:c.y+(c.height||80)/2}))),y=new Map;c.forEach(c=>{let u=g.get(c.id),m=v.get(c.id);y.set(c.id,{x:u===void 0?c.x:u-(c.width||100)/2,y:m===void 0?c.y:m-(c.height||80)/2})});let S=new Map(c.map(c=>[c.id,{x:c.x,y:c.y}])),w=new Map([...y].map(([c,u])=>[c,{...u}]));compactLayout(c,y,u,m??{x:u.marginX,y:u.marginY});let T=new Map([...S].map(([c,u])=>[c,{...u}]));separateOverlaps(c,T,u);let E=new Map([...w].map(([c,u])=>[c,{...u}]));separateOverlaps(c,E,u);let D=new Map([...S].map(([c,u])=>[c,{...u}]));straightenChains(c,D,u,isVerticalFlow(c)),separateOverlaps(c,D,u);let k=[S,w,T,E,D,y].reduce((u,m)=>layoutScore(c,m)<layoutScore(c,u)?m:u);k!==y&&k.forEach((c,u)=>y.set(u,c));let j=isVerticalFlow(h);return{positions:y,ranks:indexByValue(j?v:g),rows:indexByValue(j?g:v),authored:!0}}function compactAxis(c,u,m){let h=new Map,g=new Map;[...c].sort((c,u)=>c.center-u.center||(c.id<u.id?-1:1)).forEach(c=>{let u=[...h.keys()].find(u=>{let m=h.get(u);return Math.abs(m[0].center-c.center)>Nr?!1:!m.some(u=>u.otherStart<c.otherEnd&&u.otherEnd>c.otherStart)})??c.id;h.has(u)||h.set(u,[]),h.get(u).push(c),g.set(c.id,u)});let v=[...h.keys()].sort((c,u)=>Math.min(...h.get(c).map(c=>c.center))-Math.min(...h.get(u).map(c=>c.center))||(c<u?-1:1)),overlapsOther=(c,u)=>c.otherStart<u.otherEnd&&c.otherEnd>u.otherStart,y=new Map;v.forEach((c,g)=>{let S=h.get(c),w=m+Math.max(...S.map(c=>c.half));for(let c=0;c<g;c++){let m=v[c],g=y.get(m),T=h.get(m),E=g;T.forEach(c=>{S.forEach(m=>{overlapsOther(c,m)&&(E=Math.max(E,g+c.half+m.half+u))})}),w=Math.max(w,E)}y.set(c,w)});let S=new Map;return c.forEach(c=>S.set(c.id,y.get(g.get(c.id)))),S}function isVerticalFlow(c){let u=new Map(c.map(c=>[c.id,c])),m=0,h=0;return c.forEach(c=>{(c.outgoing||[]).forEach(g=>{let v=g.target,y=v?u.get(v.id):void 0;y&&(m+=Math.abs(y.x+(y.width||100)/2-(c.x+(c.width||100)/2)),h+=Math.abs(y.y+(y.height||80)/2-(c.y+(c.height||80)/2)))})}),h>m}function segmentsIntersect(c,u,m,h){let cross=(c,u,m)=>(u.x-c.x)*(m.y-c.y)-(u.y-c.y)*(m.x-c.x);return cross(m,h,c)>0!=cross(m,h,u)>0&&cross(c,u,m)>0!=cross(c,u,h)>0}function countCrossings(c,u){let m=new Map(c.map(c=>[c.id,c])),centerOf=c=>{let m=u.get(c.id)??{x:c.x,y:c.y};return{x:m.x+(c.width||100)/2,y:m.y+(c.height||80)/2}},h=[];c.forEach(c=>{Z.has(c.type??``)||[c,...c.attachers||[]].forEach(u=>{(u.outgoing||[]).forEach(g=>{let v=g.target,y=v?m.get(v.id):void 0;y&&!Z.has(y.type??``)&&h.push({a:m.get(u.id)??c,b:y})})})});let g=0;for(let c=0;c<h.length;c++)for(let u=c+1;u<h.length;u++){let m=h[c],v=h[u];m.a!==v.a&&m.a!==v.b&&m.b!==v.a&&m.b!==v.b&&segmentsIntersect(centerOf(m.a),centerOf(m.b),centerOf(v.a),centerOf(v.b))&&g++}return g}function layoutScore(c,u,m=0){let h=new Map(c.map(c=>[c.id,c])),centerOf=c=>{let m=u.get(c.id)??{x:c.x,y:c.y};return{x:m.x+(c.width||100)/2,y:m.y+(c.height||80)/2}},rectOf=c=>{let m=u.get(c.id)??{x:c.x,y:c.y};return{x:m.x,y:m.y,width:c.width||100,height:c.height||80}},g=[];c.forEach(c=>{Z.has(c.type??``)||(c.outgoing||[]).forEach(u=>{let m=u.target,v=m?h.get(m.id):void 0;v&&!Z.has(v.type??``)&&g.push({a:c,b:v})})});let v=0;for(let c=0;c<g.length;c++)for(let u=c+1;u<g.length;u++){let m=g[c],h=g[u];m.a!==h.a&&m.a!==h.b&&m.b!==h.a&&m.b!==h.b&&segmentsIntersect(centerOf(m.a),centerOf(m.b),centerOf(h.a),centerOf(h.b))&&v++}let y=0;g.forEach(({a:u,b:m})=>{let h=centerOf(u),g=centerOf(m);c.forEach(c=>{if(c===u||c===m||Z.has(c.type??``))return;let v=rectOf(c),S=Math.min(h.x,g.x),w=Math.max(h.x,g.x),T=Math.min(h.y,g.y),E=Math.max(h.y,g.y);S<v.x+v.width&&w>v.x&&T<v.y+v.height&&E>v.y&&y++})});let S=c.filter(c=>!Z.has(c.type??``)&&!D(c)),w=0;for(let c=0;c<S.length;c++)for(let u=c+1;u<S.length;u++){let m=rectOf(S[c]),h=rectOf(S[u]);m.x<h.x+h.width&&m.x+m.width>h.x&&m.y<h.y+h.height&&m.y+m.height>h.y&&w++}let T=c.map(c=>rectOf(c)),E=Math.max(...T.map(c=>c.x+c.width))-Math.min(...T.map(c=>c.x)),k=Math.max(...T.map(c=>c.y+c.height))-Math.min(...T.map(c=>c.y)),j=[];c.forEach(c=>{let m=u.get(c.id);m&&j.push({x:m.x-c.x,y:m.y-c.y})});let median=c=>{if(c.length===0)return 0;let u=[...c].sort((c,u)=>c-u);return u[Math.floor(u.length/2)]},M=median(j.map(c=>c.x)),N=median(j.map(c=>c.y)),P=j.length>0?j.reduce((c,u)=>c+Math.abs(u.x-M)+Math.abs(u.y-N),0)/j.length:0,I=0,L=[];g.forEach(({a:c,b:u})=>{let m=rectOf(c),h=rectOf(u),g=h.x+h.width/2-(m.x+m.width/2),v=h.y+h.height/2-(m.y+m.height/2);Math.abs(g)>=Math.abs(v)?(Math.abs(v)>2&&I++,L.push(g>0?h.x-(m.x+m.width):m.x-(h.x+h.width))):(Math.abs(g)>2&&I++,L.push(v>0?h.y-(m.y+m.height):m.y-(h.y+h.height)))});let z=L.filter(c=>c>0),B=z.reduce((c,u)=>c+u,0)/(z.length||1),V=z.reduce((c,u)=>c+Math.abs(u-B),0)/(z.length||1);return w*1e5+v*1e3+y*m+E*k/2e3+P*1+I*1e3+V*10}function separateOverlaps(c,u,m){let h=c.filter(c=>!Z.has(c.type??``)&&!D(c)&&u.has(c.id)),rectOf=c=>{let m=u.get(c.id);return{x:m.x,y:m.y,width:c.width||100,height:c.height||80}};for(let c=0;c<12;c++){let c=!1;for(let g=0;g<h.length;g++)for(let v=g+1;v<h.length;v++){let y=rectOf(h[g]),S=rectOf(h[v]);if(!(y.x<S.x+S.width&&y.x+y.width>S.x&&y.y<S.y+S.height&&y.y+y.height>S.y))continue;let w=Math.min(y.y+y.height,S.y+S.height)-Math.max(y.y,S.y)+m.nodesep,T=Math.min(y.x+y.width,S.x+S.width)-Math.max(y.x,S.x)+m.nodesep,E=u.get(h[v].id);w<=T?u.set(h[v].id,{x:E.x,y:E.y+(S.y>=y.y?w:-w)}):u.set(h[v].id,{x:E.x+(S.x>=y.x?T:-T),y:E.y}),c=!0}if(!c)return}}function straightenChains(c,u,m,h){let g=new Map(c.map(c=>[c.id,c])),v=new Map,y=new Map;c.forEach(c=>{Z.has(c.type??``)||(c.outgoing||[]).forEach(u=>{let m=u.target,h=m?g.get(m.id):void 0;h&&!Z.has(h.type??``)&&(v.has(h.id)||v.set(h.id,[]),v.get(h.id).push(c),y.has(c.id)||y.set(c.id,[]),y.get(c.id).push(h))})});let sizeOf=c=>h?c.width||100:c.height||80,spanOf=c=>h?c.height||80:c.width||100,crossOf=c=>h?c.x:c.y,flowOf=c=>h?c.y:c.x,make=(c,u)=>h?{x:c,y:u}:{x:u,y:c};[...c].filter(c=>!Z.has(c.type??``)&&u.has(c.id)).sort((c,m)=>flowOf(u.get(c.id))-flowOf(u.get(m.id))).forEach(c=>{let h=(v.get(c.id)??[]).filter(c=>u.has(c.id));if(h.length!==1)return;let g=h[0];if((y.get(g.id)??[]).length!==1)return;let S=u.get(g.id),w=u.get(c.id),T=crossOf(S)+sizeOf(g)/2,E=flowOf(S)+spanOf(g)+m.ranksep;flowOf(w)<flowOf(S)||u.set(c.id,make(T-sizeOf(c)/2,E))})}function compactLayout(c,u,m,h){let g=c.filter(c=>!Z.has(c.type??``)&&u.has(c.id));if(g.length===0)return;let v=isVerticalFlow(g);for(let c=0;c<3;c++)compactPass(g,u,m,v,h)}function compactPass(c,u,m,h,g){let rectOf=c=>{let m=u.get(c.id);return{x:m.x,y:m.y,w:c.width||100,h:c.height||80}},v=c.map(c=>{let u=rectOf(c);return{id:c.id,center:u.x+u.w/2,half:u.w/2,otherStart:u.y,otherEnd:u.y+u.h}});if(!h){let h=compactAxis(v,m.ranksep,g.x);c.forEach(c=>{let m=u.get(c.id);u.set(c.id,{x:h.get(c.id)-(c.width||100)/2,y:m.y})})}let y=c.map(c=>{let u=rectOf(c);return{id:c.id,center:u.y+u.h/2,half:u.h/2,otherStart:u.x,otherEnd:u.x+u.w}});if(h){let h=compactAxis(y,m.ranksep,g.y);c.forEach(c=>{let m=u.get(c.id);u.set(c.id,{x:m.x,y:h.get(c.id)-(c.height||80)/2})})}}function computeRanks(c,u){let m=new Map,h=[...c].sort((c,u)=>c.id<u.id?-1:+(c.id>u.id)),g=new Set,v=[],y=new Set,S=new Set;function markBackEdges(c){S.has(c.id)||y.has(c.id)||(y.add(c.id),v.push(c.id),virtualOutgoing(c,u).forEach(u=>{y.has(u.target.id)?v.length-v.indexOf(u.target.id)<=5&&g.add(`${c.id}->${u.target.id}`):markBackEdges(u.target)}),v.pop(),y.delete(c.id),S.add(c.id))}h.forEach(markBackEdges);let w=new Set;function computeRank(c){let v=m.get(c.id);if(v!==void 0)return v;if(w.has(c.id))return 0;w.add(c.id);let y=h.filter(m=>virtualOutgoing(m,u).some(u=>u.target.id===c.id)&&!g.has(`${m.id}->${c.id}`)),S=y.length===0?0:Math.max(...y.map(computeRank))+1;return m.set(c.id,S),w.delete(c.id),S}return h.forEach(computeRank),m}function applyBranchOrder(c,u,m){let h=m?.get(u);if(!h)return c;let g=new Map(c.map(c=>[c.target.id,c])),v=h.map(c=>g.get(c)).filter(c=>!!c);return v.length===c.length?v:c}function computeTopGroups(c,u,m,h){let g=new Map,v=new Map,y=new Map;return[...c].sort((c,u)=>(m.get(c.id)??0)-(m.get(u.id)??0)||(c.id<u.id?-1:+(c.id>u.id))).forEach(c=>{let m=v.get(c.id),S=new Set(m??[]),w=!m||m.length===0?null:S.size===1?[...S][0]:null;g.set(c.id,w);let T=virtualOutgoing(c,u),E=applyBranchOrder(T.filter(c=>!c.fromBoundary),c.id,h),D=T.filter(c=>c.fromBoundary),propose=(c,u)=>{v.has(c.id)||v.set(c.id,[]),v.get(c.id).push(u)};if(E.length>1&&w===null){let c=branchOffsets(E.length);E.forEach((u,m)=>{propose(u.target,u.target.id),y.has(u.target.id)||y.set(u.target.id,c[m])})}else E.forEach(c=>propose(c.target,w));D.forEach(c=>propose(c.target,w))}),{groups:g,groupOrder:y}}function computeLocalCenters(c,u,m,h,g){let v=new Map,y=new Map;c.forEach(c=>{let m=u.get(c.id),h=(c.height||80)/2;v.set(m,Math.max(v.get(m)??0,h+boundaryOverhang(c,`NORTH`))),y.set(m,Math.max(y.get(m)??0,h+boundaryOverhang(c,`SOUTH`)))});let S=[...v.keys()].sort((c,u)=>c-u),w=S.includes(h)?h:S[0]??h,T=S.indexOf(w),E=new Map;E.set(w,0);let D=new Map;c.forEach(c=>{let m=u.get(c.id);D.has(m)||D.set(m,[]),D.get(m).push(c)});let requiredGap=(c,u)=>{if(!g)return y.get(c)+m+v.get(u);let h=m;return(D.get(c)??[]).forEach(c=>{(D.get(u)??[]).forEach(u=>{if(g.get(c.id)!==g.get(u.id))return;let v=(c.height||80)/2+boundaryOverhang(c,`SOUTH`)+m+(u.height||80)/2+boundaryOverhang(u,`NORTH`);h=Math.max(h,v)})}),h};for(let c=T+1;c<S.length;c++){let u=S[c-1],m=S[c];E.set(m,E.get(u)+requiredGap(u,m))}for(let c=T-1;c>=0;c--){let u=S[c+1],m=S[c];E.set(m,E.get(u)-requiredGap(m,u))}let k=1/0,j=-1/0;return S.forEach(c=>{k=Math.min(k,E.get(c)-v.get(c)),j=Math.max(j,E.get(c)+y.get(c))}),{centers:E,minY:k,maxY:j,topExtent:v,bottomExtent:y}}function computeAllRowCenters(c,u,m,h,g,v){let y=new Map,S=c.filter(c=>!h.get(c.id)),w=S.map(c=>m.get(c.id)),T=computeLocalCenters(S,m,v,w.length>0?w.reduce((c,u)=>Math.abs(u)<Math.abs(c)?u:c):0,u);S.forEach(c=>y.set(c.id,T.centers.get(m.get(c.id))));let E=new Map;c.forEach(c=>{let u=h.get(c.id);u&&(E.has(u)||E.set(u,[]),E.get(u).push(c))});let D=new Map,k=new Map;E.forEach((c,h)=>{let g=c.map(c=>m.get(c.id)).reduce((c,u)=>Math.abs(u)<Math.abs(c)?u:c);k.set(h,g),D.set(h,computeLocalCenters(c,m,v,g,u))});let j=[...E.keys()].filter(c=>(g.get(c)??0)<0),M=[...E.keys()].filter(c=>(g.get(c)??0)>=0),packSide=(c,h)=>{let minRankOf=c=>Math.min(...E.get(c).map(c=>u.get(c.id)??0)),w=[...c].sort((c,u)=>{let m=minRankOf(c)-minRankOf(u);if(m!==0)return m;let v=g.get(c)??0,y=g.get(u)??0,S=h===-1?y-v:v-y;return S===0?c<u?-1:+(c>u):S}),spineEdgeFor=c=>{let g=E.get(c),v=new Set(g.map(c=>u.get(c.id)??0)),y=S.filter(c=>[...v].some(m=>Math.abs(m-(u.get(c.id)??0))<=1));return y.length===0?h===-1?T.minY:T.maxY:h===-1?Math.min(...y.map(c=>T.centers.get(m.get(c.id))-(c.height||80)/2-boundaryOverhang(c,`NORTH`))):Math.max(...y.map(c=>T.centers.get(m.get(c.id))+(c.height||80)/2+boundaryOverhang(c,`SOUTH`)))},j=[];w.forEach(c=>{let w=E.get(c),M=Math.min(...w.map(c=>u.get(c.id)??0)),N=Math.max(...w.map(c=>u.get(c.id)??0)),P=D.get(c),I=spineEdgeFor(c),L=j.find(c=>c.occupiedUntilRank<M);L||(L={edge:I,occupiedUntilRank:-1/0},j.push(L));let z=j.filter(c=>c!==L&&c.occupiedUntilRank>=M).reduce((c,u)=>h===-1?Math.min(c,u.edge):Math.max(c,u.edge),I);L.edge=z;let B=(g.get(c)??0)===0,V=k.get(c)??0,H=P.centers.get(V),U=[...T.centers.keys()].sort((c,u)=>c-u).reduce((c,u)=>c===void 0||Math.abs(u-V)<Math.abs(c-V)?u:c,void 0),W=(()=>{if(H===void 0||U===void 0)return;let c=T.centers.get(U),h=V-U;if(h===0)return c;let g=h>0,y=new Set(w.filter(c=>m.get(c.id)===V).map(c=>u.get(c.id)??0)),nearRank=c=>[...y].some(u=>Math.abs(u-c)<=1),E=S.filter(c=>m.get(c.id)===U&&nearRank(u.get(c.id)??0)),D=E.length?Math.max(...E.map(c=>(c.height||80)/2+boundaryOverhang(c,g?`SOUTH`:`NORTH`))):0,k=w.filter(c=>m.get(c.id)===V),j=k.length?Math.max(...k.map(c=>(c.height||80)/2+boundaryOverhang(c,g?`NORTH`:`SOUTH`))):0,M=D+v+j;return g?c+M:c-M})(),ee=W!==void 0&&H!==void 0?W-H:0,G=B&&L.edge===I?ee:h===-1?L.edge-v-P.maxY:L.edge+v-P.minY;w.forEach(c=>y.set(c.id,P.centers.get(m.get(c.id))+G)),L.occupiedUntilRank=N,L.edge=h===-1?P.minY+G:P.maxY+G})};return packSide(j,-1),packSide(M,1),y.forEach((c,u)=>{Number.isFinite(c)||y.set(u,T.centers.get(m.get(u)??0)??0)}),y}function branchOffsets(c,u=!1){let m=[];if(c===2&&!u)return[0,1];if(c%2==1){let u=(c-1)/2;for(let h=0;h<c;h++)m.push(h-u)}else{let u=c/2;for(let h=0;h<c;h++)m.push(h<u?h-u:h-u+1)}return m}function computeRows(c,u,m,h,g){let v=new Map,y=new Map,S=new Map,w=new Set,T=new Map,E=new Map(c.map(c=>[c.id,c])),computeReachable=c=>{let m=T.get(c);if(m)return m;let h=new Set,g=[c];for(;g.length>0;){let c=g.pop(),m=E.get(c);m&&virtualOutgoing(m,u).forEach(c=>{h.has(c.target.id)||(h.add(c.target.id),g.push(c.target.id))})}return T.set(c,h),h},closesCycle=(c,u)=>computeReachable(u).has(c),D=new Map;return c.forEach(c=>{let u=m.get(c.id)??0;D.has(u)||D.set(u,[]),D.get(u).push(c)}),[...D.keys()].sort((c,u)=>c-u).forEach(c=>{let m=D.get(c),T=new Map(m.map(c=>{let u=y.get(c.id);if(!u||u.length===0)return[c.id,0];let m=u.filter(c=>!c.cyclic),h=m.length>0?m:u,g=h.reduce((c,u)=>c+u.row,0)/h.length;return[c.id,g]})),priority=c=>{let u=y.get(c)?.length??0,m=S.get(c)??0;return u>0&&m===u?3:u>1?2:+!w.has(c)};m.sort((c,u)=>priority(c.id)-priority(u.id)||T.get(c.id)-T.get(u.id)||(c.y??0)-(u.y??0)||(c.id<u.id?-1:+(c.id>u.id)));let E=new Map;m.forEach(c=>{let m=h.get(c.id)??``;E.has(m)||E.set(m,new Set);let D=E.get(m),k=Math.round(T.get(c.id)),j=k,M=0;for(;D.has(j);)M=M>0?-M:-M+1,j=k+M;D.add(j),v.set(c.id,j);let N=virtualOutgoing(c,u),P=applyBranchOrder(N.filter(c=>!c.fromBoundary),c.id,g),I=N.filter(c=>c.fromBoundary),propose=(u,m,h)=>{y.has(u.id)||y.set(u.id,[]);let g=closesCycle(c.id,u.id);y.get(u.id).push({row:j+m,cyclic:g}),m===0&&!h&&w.add(u.id),h&&S.set(u.id,(S.get(u.id)??0)+1)},L=P.map(u=>closesCycle(c.id,u.target.id)),z=L.some(Boolean)&&L.filter(c=>!c).length>1,B=0,V=z?L.map(c=>{if(!c)return 0;let u=B++;return u%2==0?Math.floor(u/2)+1:-(Math.floor(u/2)+1)}):branchOffsets(P.length,(c.type??``).includes(`Gateway`));P.forEach((c,u)=>propose(c.target,V[u],!1));let H=new Set(splitAttachers(c).south.map(c=>c.id)),U=I.filter(c=>H.has(c.sourceAttacherId??``)),W=I.filter(c=>!H.has(c.sourceAttacherId??``));U.forEach((c,u)=>propose(c.target,U.length-u,!0)),W.forEach((c,u)=>propose(c.target,-(W.length-u),!0))})}),v}function computeChainX(c,u,m,h){let g=new Map(c.map(c=>[c.id,c])),v=new Map;c.forEach(c=>{Z.has(c.type??``)||[c,...c.attachers||[]].forEach(h=>{(h.outgoing||[]).forEach(h=>{let g=h.target;g&&u.has(g.id)&&(Z.has(g.type??``)||(m.get(g.id)??0)<=(m.get(c.id)??0)||(v.has(g.id)||v.set(g.id,[]),v.get(g.id).push(c.id)))})})});let y=new Map;return[...c].filter(c=>!Z.has(c.type??``)).sort((c,u)=>(m.get(c.id)??0)-(m.get(u.id)??0)).forEach(c=>{let u=(v.get(c.id)??[]).reduce((c,u)=>{let m=g.get(u),v=y.get(u);return!m||v===void 0?c:Math.max(c,v+(m.width||100)+h.ranksep)},h.marginX);y.set(c.id,u)}),y}function computeRankX(c,u,m){let h=c.reduce((c,m)=>Math.max(c,u.get(m.id)??0),0),g=new Map;c.forEach(c=>{if(Z.has(c.type??``))return;let m=u.get(c.id)??0;g.set(m,Math.max(g.get(m)??0,c.width||100))});let v=new Map,y=m.marginX;for(let c=0;c<=h;c++)v.set(c,y),y+=(g.get(c)??100)+m.ranksep;return{rankX:v,rankWidth:g}}function reduceRowCrossings(c,u,m,h,g,v){let y=c.filter(c=>!v.has(c.id)),S=new Map;y.forEach(c=>S.set(c.id,[])),c.forEach(c=>{virtualOutgoing(c,u).forEach(u=>{S.has(c.id)&&S.get(c.id).push(u.target.id),S.has(u.target.id)&&S.get(u.target.id).push(c.id)})});let w=new Map;y.forEach(c=>{let u=`${m.get(c.id)??0}:${h.get(c.id)??``}`;w.has(u)||w.set(u,[]),w.get(u).push(c.id)});for(let c=0;c<4;c++){let c=!1;if(w.forEach(u=>{if(u.length<2)return;let m=u.map(c=>g.get(c)).sort((c,u)=>c-u),barycenter=c=>{let u=(S.get(c)??[]).map(c=>g.get(c)).filter(c=>c!==void 0);return u.length===0?g.get(c):u.reduce((c,u)=>c+u,0)/u.length};[...u].sort((c,u)=>barycenter(c)-barycenter(u)||g.get(c)-g.get(u)).forEach((u,h)=>{g.get(u)!==m[h]&&(c=!0),g.set(u,m[h])})}),!c)break}}function computeBranchOrder(c,u,m,h){let g=new Map,v=new Map;c.forEach(c=>{let u=m.get(c.id);u&&(v.has(u)||v.set(u,[]),v.get(u).push(c))});let barycenterOf=c=>{let u=v.get(c);return!u||u.length===0?h.get(c)??0:u.reduce((c,u)=>c+(h.get(u.id)??0),0)/u.length},y=new Map(c.map(c=>[c.id,c])),S=new Map,reachOf=c=>{let m=S.get(c);if(m!==void 0)return m;let h=[],g=new Set,enter=c=>{g.add(c);let m=y.get(c),v=m?virtualOutgoing(m,u).filter(c=>!c.fromBoundary).map(c=>c.target.id):[];h.push({id:c,next:v,at:0,deepest:0})};enter(c);let v=0;for(;h.length>0;){let c=h[h.length-1];if(c.at<c.next.length){let u=c.next[c.at++],m=S.get(u);m===void 0?g.has(u)||enter(u):c.deepest=Math.max(c.deepest,m);continue}h.pop(),g.delete(c.id),v=y.get(c.id)?1+c.deepest:0,S.set(c.id,v);let u=h[h.length-1];u&&(u.deepest=Math.max(u.deepest,v))}return v};return c.forEach(c=>{let m=virtualOutgoing(c,u).filter(c=>!c.fromBoundary);if(m.length<=1)return;let h=m.map(c=>c.target.id);if(new Set(h).size!==h.length)return;let v=h.length===2?[...h].sort((c,u)=>reachOf(u)-reachOf(c)||barycenterOf(c)-barycenterOf(u)||(c<u?-1:1)):[...h].sort((c,u)=>barycenterOf(c)-barycenterOf(u)||(c<u?-1:+(c>u)));g.set(c.id,v)}),g}function rebuildPositions(c,u,m){let h=new Set;c.forEach(c=>{[c,...c.attachers||[]].forEach(m=>{(m.outgoing||[]).forEach(m=>{let g=m.target;g&&u.has(g.id)&&(h.add(c.id),h.add(g.id))})}),(c.incoming||[]).forEach(m=>{let g=m.source;g&&u.has(g.id)&&(h.add(c.id),h.add(g.id))})});let g=c.filter(c=>!h.has(c.id)&&!Z.has(c.type??``)&&(c.x!==0||c.y!==0)),v=new Set(g.map(c=>c.id)),y=g.length>0?c.filter(c=>!v.has(c.id)):c,S=g.length>0?new Set(y.map(c=>c.id)):u,w=computeTopologicalPositions(y,S,m),T=[w.positions],withCentering=c=>{let u=new Map([...c].map(([c,u])=>[c,{...u}]));return centerGateways(y,S,u),u},E=new Map([...w.positions].map(([c,u])=>[c,{...u}]));compactRows(y,E,w.rows,m),T.push(withCentering(w.positions),E,withCentering(E));let D=T.map(c=>countCrossings(y,c)),k=Math.min(...D);if(T.filter((c,u)=>D[u]===k).reduce((c,u)=>layoutScore(y,u)<layoutScore(y,c)?u:c).forEach((c,u)=>w.positions.set(u,c)),g.length>0){let c=y.filter(c=>w.positions.has(c.id)),u=c.reduce((c,u)=>{let m=w.positions.get(u.id);return Math.max(c,m.y+(u.height||80))},m.marginY),h=c.reduce((c,u)=>Math.min(c,w.positions.get(u.id).x),m.marginX),v=u+m.ranksep;[...g].sort((c,u)=>c.x-u.x||c.y-u.y).forEach(c=>{w.positions.set(c.id,{x:h,y:v}),h+=(c.width||100)+m.nodesep})}return w}function computeNodePositions(c,u,m){if(kr){let u=placeWithConstraints(c,m,Z);if(u)return u}let h=rebuildPositions(c,u,m),g=formatAuthoredLayout(c,m);if(g){let m=authoredDefects(c,u);if(layoutScore(c,g.positions)+m.crossings*1e3+m.through*1e3<=layoutScore(c,h.positions))return g}return h}function authoredDefects(c,u){let m=[],h=new Set;c.forEach(c=>{[c,...c.attachers||[]].forEach(g=>{(g.outgoing||[]).forEach(g=>{let v=g,y=v.target;if(!y||!u.has(y.id)||h.has(v.id)||Z.has(c.type??``)||Z.has(y.type??``))return;h.add(v.id);let S=v.waypoints??[];S.slice(1).forEach((c,u)=>m.push({id:v.id,a:S[u],b:c}))})})});let g=0;for(let c=0;c<m.length;c++)for(let u=c+1;u<m.length;u++)m[c].id!==m[u].id&&segmentsIntersect(m[c].a,m[c].b,m[u].a,m[u].b)&&g++;let v=0;return m.forEach(({a:u,b:m})=>{c.forEach(c=>{if(Z.has(c.type??``)||D(c))return;let h=Math.min(u.x,m.x),g=Math.max(u.x,m.x),y=Math.min(u.y,m.y),S=Math.max(u.y,m.y);h<c.x+c.width-2&&g>c.x+2&&y<c.y+c.height-2&&S>c.y+2&&v++})}),{crossings:g,through:v}}function compactRows(c,u,m,h){let g=c.filter(c=>!Z.has(c.type??``)&&u.has(c.id));if(g.length===0)return;let v=new Map;g.forEach(c=>{let h=m.get(c.id);if(h===void 0)return;let g=u.get(c.id),y=g.y-boundaryOverhang(c,`NORTH`),S=g.y+(c.height||80)+boundaryOverhang(c,`SOUTH`),w=v.get(h);w?(w.top=Math.min(w.top,y),w.bottom=Math.max(w.bottom,S),w.members.push(c)):v.set(h,{top:y,bottom:S,members:[c]})});let y=h.marginY;[...v.keys()].sort((c,u)=>c-u).forEach(c=>{let m=v.get(c),g=y-m.top;m.members.forEach(c=>{let m=u.get(c.id);u.set(c.id,{x:m.x,y:m.y+g})}),y+=m.bottom-m.top+h.nodesep})}function centerGateways(c,u,m){let h=new Map(c.map(c=>[c.id,c])),g=c.filter(c=>(c.type??``).includes(`Gateway`)&&m.has(c.id));if(g.length===0)return;let rectOf=c=>{let u=m.get(c.id);return{x:u.x,y:u.y,width:c.width||100,height:c.height||80}};g.forEach(g=>{let v=[];if((g.outgoing||[]).forEach(c=>{let m=c.target,g=m?h.get(m.id):void 0;g&&u.has(g.id)&&v.push(g)}),c.forEach(c=>{(c.outgoing||[]).forEach(u=>{u.target?.id===g.id&&v.push(c)})}),v.length<2)return;let y=v.map(c=>rectOf(c).y+(c.height||80)/2),w=(Math.min(...y)+Math.max(...y))/2-(g.height||50)/2,T=m.get(g.id);if(Math.abs(w-T.y)<1)return;let E={x:T.x,y:w},D={x:E.x,y:E.y,width:g.width||50,height:g.height||50};c.some(c=>c.id!==g.id&&!Z.has(c.type??``)&&m.has(c.id)&&S(D,rectOf(c)))||m.set(g.id,E)})}function computeTopologicalPositions(c,u,m){let h=computeRanks(c,u),g=computeTopGroups(c,u,h),v=computeRows(c,u,h,g.groups),y=computeBranchOrder(c,u,g.groups,v),{groups:S,groupOrder:w}=computeTopGroups(c,u,h,y),T=computeRows(c,u,h,S,y),E=computeBoundaryLeafIds(c,u),D=computeBoundaryLeafHosts(c,E),k=computeAnnotationSources(c,u);reduceRowCrossings(c,u,h,S,T,new Set([...E,...k.keys()]));let j=c.filter(c=>!E.has(c.id)&&!k.has(c.id)),M=computeAllRowCenters(j,h,T,S,w,m.nodesep),{rankX:N,rankWidth:P}=computeRankX(c,h,m),I=computeChainX(c,u,h,m),centeredX=(c,u)=>(N.get(c)??0)+((P.get(c)??u)-u)/2,nodeXOf=(c,u,m)=>I.get(c)??centeredX(u,m),L=new Map;j.forEach(c=>{let u=M.get(c.id);L.set(c.id,u-c.height/2)});let z=new Map;c.forEach(c=>{if(!E.has(c.id))return;let u=D.get(c.id);u&&(z.has(u.id)||z.set(u.id,[]),z.get(u.id).push(c))}),z.forEach((u,h)=>{let g=c.find(c=>c.id===h),v=L.get(h)+g.height/2,y=T.get(h)??0,S=u.filter(c=>T.get(c.id)>=y),w=u.filter(c=>T.get(c.id)<y);[{list:S,edge:v+g.height/2,dir:1},{list:w,edge:v-g.height/2,dir:-1}].forEach(({list:c,edge:u,dir:h})=>{if(c.length===0)return;let g=c.map(c=>T.get(c.id)).reduce((c,u)=>Math.abs(u-y)<Math.abs(c-y)?u:c),v=computeLocalCenters(c,T,m.nodesep,g),S=c.filter(c=>T.get(c.id)===g),w=Math.max(...S.map(c=>(c.height||80)/2+boundaryOverhang(c,h===1?`NORTH`:`SOUTH`))),E=h===1?u+m.nodesep+w:u-m.nodesep-w;c.forEach(c=>L.set(c.id,E+v.centers.get(T.get(c.id))-c.height/2))})});let B=[...L.keys()].map(u=>{let g=c.find(c=>c.id===u),v=h.get(u)??0,y=g.width<=m.ranksep-10;return{x:E.has(u)&&v>0&&y?N.get(v)-m.ranksep/2-g.width/2:nodeXOf(u,v,g.width),y:L.get(u),w:g.width,h:g.height}}),overlapsAny=(c,u,m,h)=>B.some(g=>c<g.x+g.w&&c+m>g.x&&u<g.y+g.h&&u+h>g.y),V=new Map,H=new Map;k.forEach((u,m)=>{H.has(u.id)||H.set(u.id,[]),H.get(u.id).push(c.find(c=>c.id===m))}),H.forEach((u,g)=>{let v=c.find(c=>c.id===g),y={x:N.get(h.get(g)??0)??0,y:L.get(g),w:v.width,h:v.height},S=m.nodesep,clearOverlapsAny=(c,u,m,h)=>overlapsAny(c-S/2,u-S/2,m+S,h+S),slide=(c,u,m,h)=>{for(let g=0;g<=6;g++)for(let v of g===0?[1]:[1,-1]){let y=h===`x`?c.x+v*g*20:c.x,S=h===`y`?c.y+v*g*20:c.y;if(!clearOverlapsAny(y,S,u,m))return{x:y,y:S}}return null},corridorTraffic=(c,u)=>B.filter(m=>m.x<y.x+y.w+200&&m.x+m.w>y.x-200&&m.y<u&&m.y+m.h>c).length,w=corridorTraffic(y.y-400,y.y)<=corridorTraffic(y.y+y.h,y.y+y.h+400);u.forEach(c=>{let u={base:{x:y.x+y.w/2-c.width/2,y:y.y-S-c.height},axis:`x`},m={base:{x:y.x+y.w/2-c.width/2,y:y.y+y.h+S},axis:`x`},h=[...w?[u,m]:[m,u],{base:{x:y.x+y.w+S,y:y.y+y.h/2-c.height/2},axis:`y`},{base:{x:y.x-S-c.width,y:y.y+y.h/2-c.height/2},axis:`y`}],g=null;for(let{base:u,axis:m}of h)if(g=slide(u,c.width,c.height,m),g)break;let{x:v,y:T}=g??h[0].base;L.set(c.id,T),V.set(c.id,v),B.push({x:v,y:T,w:c.width,h:c.height})})});let U=Math.min(0,...c.map(c=>L.get(c.id))),W=m.marginY-U,ee=new Map;return c.forEach(c=>{if(k.has(c.id))return;let u=h.get(c.id)??0,g=c.width<=m.ranksep-10,v=E.has(c.id)&&u>0&&g?N.get(u)-m.ranksep/2-c.width/2:nodeXOf(c.id,u,c.width);ee.set(c.id,{x:v,y:L.get(c.id)+W})}),k.forEach((c,u)=>{ee.set(u,{x:V.get(u),y:L.get(u)+W})}),{positions:ee,rows:T,ranks:h}}var Fr=1e6;function computeLanedNodePositions(c,u,m,h){if(kr){let u=placeWithConstraints(c,h,Z);if(u)return{...u,laneBands:null}}let g=new Map;m.forEach((c,u)=>g.set(c.businessObject?.id??c.id,u));let v=new Map;c.forEach(c=>{(c.outgoing||[]).forEach(u=>{if(!u.target)return;let m=Z.has(c.type??``),h=Z.has(u.target.type??``);h&&!m&&!v.has(u.target.id)&&v.set(u.target.id,c.id),m&&!h&&!v.has(c.id)&&v.set(c.id,u.target.id)})});let y=new Map(c.map(c=>[c.id,c])),laneIndexOf=c=>{let u=c.businessObject?.lanes?.[0]?.id;if(u)return g.get(u)??0;let m=v.get(c.id),h=m?y.get(m):void 0;return h?laneIndexOf(h):0},S=new Map;if(c.forEach(c=>{let u=laneIndexOf(c);S.has(u)||S.set(u,[]),S.get(u).push(c)}),hasAuthoredLayout(c.filter(c=>!Z.has(c.type??``)))){let u=new Map;m.forEach((c,m)=>{let g=S.get(m)??[];if(g.length===0)return;let v=formatAuthoredLayout(g,h,{x:c.x+h.marginX,y:c.y+h.marginY});v?g.forEach(m=>{let h=v.positions.get(m.id)??{x:m.x,y:m.y};u.set(m.id,{x:Math.min(Math.max(h.x,c.x),Math.max(c.x,c.x+c.width-m.width)),y:Math.min(Math.max(h.y,c.y),Math.max(c.y,c.y+c.height-m.height))})}):g.forEach(c=>u.set(c.id,{x:c.x,y:c.y}))}),c.forEach(c=>{u.has(c.id)||u.set(c.id,{x:c.x,y:c.y})});let g=new Map(c.map(c=>[c.id,{x:c.x,y:c.y}]));layoutScore(c,g)<layoutScore(c,u)&&g.forEach((c,m)=>u.set(m,c));let v=new Map([...u].map(([c,u])=>[c,u.x])),y=new Map([...u].map(([c,u])=>[c,u.y])),w=isVerticalFlow(c);return{positions:u,ranks:indexByValue(w?y:v),rows:indexByValue(w?v:y),laneBands:null,authored:!0}}let w=computeRanks(c,u),{rankX:T,rankWidth:E}=computeRankX(c,w,h),globalCenteredX=(c,u)=>(T.get(c)??0)+((E.get(c)??u)-u)/2,D=new Map,k=new Map,j=[],M=0;m.forEach((c,u)=>{let m=S.get(u)??[];if(m.length===0){let c=h.marginY*2;j.push({y:M,height:c}),M+=c;return}let g=computeNodePositions(m,new Set(m.map(c=>c.id)),h),y=0;m.forEach(c=>{let u=g.positions.get(c.id);y=Math.max(y,u.y+c.height)});let T=y+h.marginY,isAnnotation=c=>Z.has(c.type??``);m.forEach(c=>{if(isAnnotation(c))return;let m=g.positions.get(c.id),h=w.get(c.id)??0;D.set(c.id,{x:globalCenteredX(h,c.width),y:M+m.y}),k.set(c.id,u*Fr+(g.rows.get(c.id)??0))}),m.forEach(c=>{if(!isAnnotation(c))return;let m=g.positions.get(c.id),h=v.get(c.id),y=h?g.positions.get(h):void 0,S=h?D.get(h):void 0,w=y&&S?S.x+(m.x-y.x):m.x;D.set(c.id,{x:w,y:M+m.y}),k.set(c.id,u*Fr+(g.rows.get(c.id)??0))}),j.push({y:M,height:T}),M+=T});let N=c.filter(c=>!Z.has(c.type??``)).map(c=>{let u=D.get(c.id);return{x:u.x,y:u.y,w:c.width,h:c.height}}),finalOverlaps=(c,u,m,h)=>N.some(g=>c<g.x+g.w&&c+m>g.x&&u<g.y+g.h&&u+h>g.y);return c.filter(c=>Z.has(c.type??``)).forEach(c=>{let u=D.get(c.id),m=u;if(finalOverlaps(u.x,u.y,c.width,c.height))outer:for(let h=1;h<=15;h++)for(let g of[1,-1]){let v=u.x+g*h*20;if(!finalOverlaps(v,u.y,c.width,c.height)){m={x:v,y:u.y};break outer}}D.set(c.id,m),N.push({x:m.x,y:m.y,w:c.width,h:c.height})}),{positions:D,rows:k,ranks:w,laneBands:j}}function isBackEdge(c,u,m){let h=m.get(c),g=m.get(u);return h===void 0||g===void 0?!1:g<=h}function collectRawEdges(c,u,m,h=!1,g){let v=[],wanted=(c,u)=>!g||g.has(c)||g.has(u),y=0;return c.forEach(c=>{Z.has(c.type??``)||((c.outgoing||[]).forEach(g=>{let S=g.target;S&&u.has(S.id)&&!Z.has(S.type??``)&&(h||!isBackEdge(c.id,S.id,m))&&wanted(c.id,S.id)&&v.push({id:`le${y++}`,sourceId:c.id,targetId:S.id,conn:g})}),(c.attachers||[]).forEach(c=>{(c.outgoing||[]).forEach(g=>{let S=g.target;S&&u.has(S.id)&&(h||!isBackEdge(c.id,S.id,m))&&wanted(c.id,S.id)&&v.push({id:`le${y++}`,sourceId:c.id,targetId:S.id,conn:g})})}))}),v}function buildGraphChildren(c,u,m){let h=[],g=new Set,pushChild=c=>{if(g.has(c.id))return;g.add(c.id);let v=u.get(c.id);if(!v||v.width<=0||v.height<=0)return;let y=m?.get(c.id);h.push({id:c.id,x:v.x,y:v.y,width:v.width,height:v.height,...y?{ports:y}:{}})};return c.forEach(c=>{pushChild(c),(c.attachers||[]).forEach(c=>pushChild(c))}),h}function sidePoint(c,u,m=.5){switch(u){case`EAST`:return{x:c.width,y:c.height*m};case`WEST`:return{x:0,y:c.height*m};case`NORTH`:return{x:c.width*m,y:0};case`SOUTH`:return{x:c.width*m,y:c.height}}}function relativeSides(c,u){let m=u.x-(c.x+c.width),h=c.x-(u.x+u.width),g=u.y-(c.y+c.height),v=c.y-(u.y+u.height),y=Math.max(m,h);return y>=0||y>=Math.max(g,v)?m>=h?{from:`EAST`,to:`WEST`}:{from:`WEST`,to:`EAST`}:g>=v?{from:`SOUTH`,to:`NORTH`}:{from:`NORTH`,to:`SOUTH`}}function computeEdgeSidesByRank(c,u,m,h,g){let v=new Map,y=new Map;c.forEach(c=>{v.set(c.sourceId,(v.get(c.sourceId)??0)+1),y.set(c.targetId,(y.get(c.targetId)??0)+1)});let S=new Set(m.flatMap(c=>(c.attachers||[]).map(c=>c.id))),w=new Map;m.forEach(c=>{let{south:u,north:m}=splitAttachers(c);u.forEach(c=>w.set(c.id,`SOUTH`)),m.forEach(c=>w.set(c.id,`NORTH`))});let T=new Map,E=new Map;c.forEach(c=>{let m=u.get(c.sourceId),h=u.get(c.targetId),D=(v.get(c.sourceId)??0)>1,k=(y.get(c.targetId)??0)>1;if(S.has(c.sourceId)?T.set(c.id,w.get(c.sourceId)??`SOUTH`):D?m!==void 0&&h!==void 0&&T.set(c.id,h<m?`NORTH`:h>m?`SOUTH`:`EAST`):T.set(c.id,`EAST`),k)m!==void 0&&h!==void 0&&E.set(c.id,m<h?`NORTH`:m>h?`SOUTH`:`WEST`);else{let u=g.get(c.sourceId),m=g.get(c.targetId),h=u&&m?u.x+u.width/2-(m.x+m.width/2):0,v=u&&m?u.y+u.height/2-(m.y+m.height/2):0;u&&m&&Math.abs(v)>Math.abs(h)*3?E.set(c.id,v>0?`SOUTH`:`NORTH`):E.set(c.id,`WEST`)}});let rowGap=c=>Math.abs((u.get(c.targetId)??0)-(u.get(c.sourceId)??0)),D=new Map;return c.forEach(c=>{if(!h.has(c.sourceId))return;let u=T.get(c.id);if(u!==`NORTH`&&u!==`SOUTH`)return;let m=`${c.sourceId}:${u}`;D.has(m)||D.set(m,[]),D.get(m).push(c)}),D.forEach(c=>{c.length<=1||[...c].sort((c,u)=>rowGap(u)-rowGap(c)).slice(1).forEach(c=>T.set(c.id,`EAST`))}),{sourceSideByEdge:T,targetSideByEdge:E}}function computeEdgeSidesGeometric(c,u,m){let h=new Set(u.flatMap(c=>(c.attachers||[]).map(c=>c.id))),g=new Map;u.forEach(c=>{let{south:u,north:m}=splitAttachers(c);u.forEach(c=>g.set(c.id,`SOUTH`)),m.forEach(c=>g.set(c.id,`NORTH`))});let v=new Map,y=new Map,S=new Map,w=new Map;return c.forEach(c=>{S.set(c.sourceId,(S.get(c.sourceId)??0)+1),w.set(c.targetId,(w.get(c.targetId)??0)+1)}),c.forEach(c=>{let u=m.get(c.sourceId),T=m.get(c.targetId);if(!u||!T)return;let{from:E,to:D}=relativeSides(u,T),k=E;if((S.get(c.sourceId)??0)>1){let c=T.y+T.height/2-(u.y+u.height/2);Math.abs(c)>u.height/2&&(k=c>0?`SOUTH`:`NORTH`)}let j=D;if((w.get(c.targetId)??0)>1){let c=u.y+u.height/2-(T.y+T.height/2);Math.abs(c)>T.height/2&&(j=c>0?`SOUTH`:`NORTH`)}v.set(c.id,h.has(c.sourceId)?g.get(c.sourceId)??k:k),y.set(c.id,j)}),{sourceSideByEdge:v,targetSideByEdge:y}}function grazeRuns(c,u){let m=0;for(let h=0;h+1<c.length;h++){let g=H(c[h],c[h+1]);g&&u.some(c=>re(g,c))&&(m+=1)}return m}var Ir=[{nudgeOrthogonalSegmentsConnectedToShapes:!1,performUnifyingNudgingPreprocessingStep:!1},{nudgeOrthogonalSegmentsConnectedToShapes:!0,performUnifyingNudgingPreprocessingStep:!1},{nudgeOrthogonalSegmentsConnectedToShapes:!1,performUnifyingNudgingPreprocessingStep:!0},{nudgeOrthogonalSegmentsConnectedToShapes:!0,performUnifyingNudgingPreprocessingStep:!0}];async function routeBestContainerEdges(c,u,m,h,g,v){let y=null,S=1/0;for(let[w,T]of Ir.entries()){if(checkBudget(),w>0&&!hasSpare())break;await yieldToHost();let E;try{E=await routeContainerEdges(c,u,m,h,{crossingPenalty:700,idealNudgingDistance:16,nudgeSharedPathsWithCommonEndPoint:!0,nudgeOrthogonalTouchingColinearSegments:!0,...T},g,v,w===0)}catch(c){if(!(c instanceof RouteTooCostly))throw c;if(w===0)throw new je(activeBudget()?.limitMs??0);break}let D=[...E.routes.values()].map(c=>[c.sourcePoint,...c.bendPoints,c.targetPoint]),k=0,j=0;for(let c=0;c<D.length;c++)for(let u=c+1;u<D.length;u++)$(D[c],D[u])>0&&(k+=1),N(D[c],D[u])&&(j+=1);let M=[...u.values()],P=D.reduce((c,u)=>c+grazeRuns(u,M),0),I=k*3e3+j*1500+P*6e3;I<S&&(S=I,y=E)}return y}async function routeContainerEdges(c,u,m,h,g,v=!1,y,S=!0){let w=collectRawEdges(c,new Set(c.map(c=>c.id)),h,v,y),T=new Map(w.map(c=>[c.id,{connection:c.conn}])),E=new Set(c.filter(c=>(c.type??``).includes(`Gateway`)).map(c=>c.id)),D=new Set(c.filter(c=>(c.type??``).includes(`Gateway`)||(c.type??``).includes(`Event`)).map(c=>c.id)),{sourceSideByEdge:k,targetSideByEdge:j}=v?computeEdgeSidesGeometric(w,c,u):computeEdgeSidesByRank(w,m,c,D,u),M=new Map;w.forEach(c=>{let u=k.get(c.id),m=j.get(c.id);if(u){let m=`${c.sourceId}:${u}:source`;M.has(m)||M.set(m,[]),M.get(m).push(`${c.id}:source`)}if(m){let u=`${c.targetId}:${m}:target`;M.has(u)||M.set(u,[]),M.get(u).push(`${c.id}:target`)}});let N=new Set;M.forEach((c,u)=>{let[m,h,g]=u.split(`:`),v=g===`source`?`target`:`source`;M.has(`${m}:${h}:${v}`)&&N.add(`${m}:${h}`)});let P=new Map,I=new Map,addPort=(c,u,m,h)=>{P.has(c)||P.set(c,[]);let g=P.get(c),v=g.find(c=>c.id===u);if(v)return v.id;let y={...m};for(;g.some(c=>Math.abs(c.x-y.x)<.5&&Math.abs(c.y-y.y)<.5);)h===`NORTH`||h===`SOUTH`?y.x+=.5:y.y+=.5;return g.push({id:u,...y,properties:{"port.side":h}}),u};M.forEach((c,m)=>{let[h,g,v]=m.split(`:`),y=u.get(h);if(!y)return;let S=!E.has(h)&&N.has(`${h}:${g}`),w=c.length>1,T=S?v===`target`?[0,.5]:[.5,1]:[0,1],proportionOf=u=>w?T[0]+(T[1]-T[0])*(u+1)/(c.length+1):S?v===`target`?.4:.6:.5;c.forEach((c,u)=>{let m=w?`${h}__${g}__${v}__${u}`:`${h}__${g}__${v}`,S=addPort(h,m,sidePoint(y,g,proportionOf(u)),g);I.set(c,S)})});let L={id:`root`,children:buildGraphChildren(c,u,P),edges:w.map(c=>({id:c.id,sources:[I.get(`${c.id}:source`)??c.sourceId],targets:[I.get(`${c.id}:target`)??c.targetId]}))},centre=c=>{let m=u.get(c);return m?{x:m.x+m.width/2,y:m.y+m.height/2}:{x:0,y:0}},z=routingLoad(w.map(c=>({from:centre(c.sourceId),to:centre(c.targetId),source:c.sourceId,target:c.targetId}))),B=g.performUnifyingNudgingPreprocessingStep===!0;if(estimateRouteMs(z,c.length,B)>(activeBudget()?.remaining()??1/0)*(S?1:.5))throw new RouteTooCostly;let V=await routeEdges(L,g),isDiagonal=c=>{if(!c)return!1;let u=[c.sourcePoint,...c.bendPoints,c.targetPoint];return u.some((c,m)=>m>0&&Math.abs(c.x-u[m-1].x)>1&&Math.abs(c.y-u[m-1].y)>1)},H=new Set(w.filter(c=>isDiagonal(V.get(c.id))).map(c=>c.id));if(H.size>0){let m=await routeEdges({id:`root`,children:buildGraphChildren(c,u,P),edges:w.map(c=>({id:c.id,sources:[H.has(c.id)?c.sourceId:I.get(`${c.id}:source`)??c.sourceId],targets:[H.has(c.id)?c.targetId:I.get(`${c.id}:target`)??c.targetId]}))},g);H.forEach(c=>{let u=m.get(c);u&&V.set(c,u)})}return{routes:V,edgeMeta:T}}function fixPortApproach(c,u,m){if(c.length<3)return c;let h=c.length,g=c[h-1],v=c[h-2],y=c[h-3],S=Math.abs(g.x-u.x)<.5||Math.abs(g.x-(u.x+u.width))<.5,w=Math.abs(g.y-u.y)<.5||Math.abs(g.y-(u.y+u.height))<.5,T=Math.abs(g.x-v.x)<.5&&Math.abs(g.y-v.y)>.5,E=Math.abs(g.y-v.y)<.5&&Math.abs(g.x-v.x)>.5,D=Math.abs(v.y-y.y)<.5&&Math.abs(v.x-y.x)>.5,k=Math.abs(v.x-y.x)<.5&&Math.abs(v.y-y.y)>.5;if(S&&T&&D){let u={x:y.x,y:g.y};if(!segmentHitsAnyRect(y,u,m)&&!segmentHitsAnyRect(u,g,m)){let m=[...c];return m[h-2]=u,m}}if(w&&E&&k){let u={x:g.x,y:y.y};if(!segmentHitsAnyRect(y,u,m)&&!segmentHitsAnyRect(u,g,m)){let m=[...c];return m[h-2]=u,m}}return c}function isRoundShape(c){return(c.type??``).includes(`Gateway`)||(c.type??``).includes(`Event`)}function portSide(c,u){let m=Math.abs(c.x-u.x)<.5||Math.abs(c.x-(u.x+u.width))<.5,h=Math.abs(c.y-u.y)<.5||Math.abs(c.y-(u.y+u.height))<.5;return m&&!h?`horizontal`:h&&!m?`vertical`:null}function segmentsCross(c,u,m,h){let g=c.y===u.y;if(g===(m.y===h.y))return!1;let v=g?{y:c.y,x1:Math.min(c.x,u.x),x2:Math.max(c.x,u.x)}:{y:m.y,x1:Math.min(m.x,h.x),x2:Math.max(m.x,h.x)},y=g?{x:m.x,y1:Math.min(m.y,h.y),y2:Math.max(m.y,h.y)}:{x:c.x,y1:Math.min(c.y,u.y),y2:Math.max(c.y,u.y)};return y.x>v.x1&&y.x<v.x2&&v.y>y.y1&&v.y<y.y2}function pathCrossesAny(c,u){for(let m=0;m+1<c.length;m++)for(let h of u)for(let u=0;u+1<h.length;u++)if(segmentsCross(c[m],c[m+1],h[u],h[u+1]))return!0;return!1}function isPathSafe(c,u,m){for(let m=0;m+1<c.length;m++)if(segmentHitsAnyRect(c[m],c[m+1],u))return!1;return!pathCrossesAny(c,m)}function fixSingleBendConflict(c,u,m,h,g){if(c.length!==3)return null;let v=c[0],y=c[2],S=portSide(v,u),w=portSide(y,m);if(S===`horizontal`&&w===`horizontal`&&Math.abs(v.y-y.y)>.5){let c=(v.x+y.x)/2,u=[v,{x:c,y:v.y},{x:c,y:y.y},y];return isPathSafe(u,h,g)?u:null}if(S===`vertical`&&w===`vertical`&&Math.abs(v.x-y.x)>.5){let c=(v.y+y.y)/2,u=[v,{x:v.x,y:c},{x:y.x,y:c},y];return isPathSafe(u,h,g)?u:null}return null}function fixPortApproaches(c,u,m,h,g,v,y){let S=c;if(m&&(S=snapRoundAnchor(S,m,y,!1,h)),u&&(S=snapRoundAnchor(S,u,v,!0,h)),u&&m){let c=fixSingleBendConflict(S,u,m,h,g);if(c)return c}return m&&(S=fixPortApproach(S,m,h)),u&&(S=[...fixPortApproach([...S].reverse(),u,h)].reverse()),S}function normaliseStubs(c,u,m,h){if(!u||!m||c.length<2)return c;let g=c[0],v=c[c.length-1],y=Math.abs(g.x-(u.x+u.width))<.5,S=Math.abs(v.x-m.x)<.5;if(!y||!S||m.x<=u.x+u.width)return c;if(Math.abs(g.y-v.y)<.5)return[g,v];let w=Math.round((u.x+u.width+m.x)/2),T=[g,{x:w,y:g.y},{x:w,y:v.y},v];for(let u=0;u+1<T.length;u++)if(segmentHitsAnyRect(T[u],T[u+1],h))return c;return T}function moveConnectionLabel(c,u,m){let h=c.label,g=c.waypoints??[];if(!h||g.length<2||u.length<2)return;let midpoint=c=>{let u=Math.floor(c.length/2);if(c.length%2==1)return c[u];let m=c[u-1],h=c[u];return{x:(m.x+h.x)/2,y:(m.y+h.y)/2}},v=midpoint(g),y=midpoint(u),S=y.x-v.x,w=y.y-v.y;Math.abs(S)<1&&Math.abs(w)<1||m.moves.push({elements:[h],dx:S,dy:w})}function bendCount(c){let u=0;for(let m=1;m<c.length-1;m++){let h=c[m-1],g=c[m],v=c[m+1];Math.abs((g.x-h.x)*(v.y-g.y)-(g.y-h.y)*(v.x-g.x))>1&&u++}return u}function reduceBends(c,u,m,h){if(!u||!m||bendCount(c)<2)return c;let g={x:u.x+u.width/2,y:u.y+u.height/2},v={x:m.x+m.width/2,y:m.y+m.height/2},y=v.x>=g.x?u.x+u.width:u.x,S=v.y>=g.y?u.y+u.height:u.y,w=g.x>=v.x?m.x+m.width:m.x,T=g.y>=v.y?m.y+m.height:m.y,E=Math.abs(g.y-v.y)<=1,D=Math.abs(g.x-v.x)<=1,k=[];E&&k.push([{x:y,y:g.y},{x:w,y:g.y}]),D&&k.push([{x:g.x,y:S},{x:g.x,y:T}]),k.push([{x:y,y:g.y},{x:v.x,y:g.y},{x:v.x,y:T}]),k.push([{x:g.x,y:S},{x:g.x,y:v.y},{x:w,y:v.y}]);let clear=c=>c.slice(1).every((g,v)=>{let y=c[v],S=Math.min(y.x,g.x),w=Math.max(y.x,g.x),T=Math.min(y.y,g.y),E=Math.max(y.y,g.y);return h.every(c=>c===u||c===m||!(S<c.x+c.width-2&&w>c.x+2&&T<c.y+c.height-2&&E>c.y+2))}),attachedSide=(c,u)=>Math.abs(c.x-u.x)<.5?`W`:Math.abs(c.x-(u.x+u.width))<.5?`E`:Math.abs(c.y-u.y)<.5?`N`:Math.abs(c.y-(u.y+u.height))<.5?`S`:`?`,j=attachedSide(c[0],u),M=attachedSide(c[c.length-1],m),keepsSides=c=>attachedSide(c[0],u)===j&&attachedSide(c[c.length-1],m)===M;return k.find(u=>bendCount(u)<bendCount(c)&&keepsSides(u)&&clear(u))??c}function simplifyJogs(c,u){let m=[...c],h=0;for(;h+3<m.length;){let[c,g,v,y]=[m[h],m[h+1],m[h+2],m[h+3]],S=Math.abs(g.x-v.x),w=Math.abs(g.y-v.y),T=c.x===g.x&&v.x===y.x&&g.y===v.y&&S>.5&&S<40,E=c.y===g.y&&v.y===y.y&&g.x===v.x&&w>.5&&w<40;if(T){let g={x:y.x,y:c.y};if(!segmentHitsAnyRect(c,g,u)&&!segmentHitsAnyRect(g,y,u)){m.splice(h,4,g,y);continue}}if(E){let g={x:c.x,y:y.y};if(!segmentHitsAnyRect(c,g,u)&&!segmentHitsAnyRect(g,y,u)){m.splice(h,4,g,y);continue}}h++}return m.filter((c,u)=>u===0||c.x!==m[u-1].x||c.y!==m[u-1].y)}var Lr=30,Rr=36,zr=1.6;function laneChildren(c){return(c.children||[]).filter(c=>c.type===`bpmn:Lane`).sort((c,u)=>c.y-u.y||(c.id<u.id?-1:1))}function orderLanes(c,u,m,h){let g=new Map;return u.forEach(c=>virtualOutgoing(c,m).forEach(u=>{let m=h(c),v=h(u.target);if(!m||!v||m===v)return;let y=trafficKey(m,v);g.set(y,(g.get(y)??0)+1)})),orderByTraffic(c,c=>c.businessObject?.id??c.id,g)}function stackLanes(c,u,m,h,g,v){if(u.length===0)return;let y=new Map;m.forEach(c=>{let u=c.businessObject?.lanes?.[0]?.id;u&&y.set(c.id,u)});let idOf=c=>c.businessObject?.id??c.id,nodesIn=c=>{let u=laneChildren(c);if(u.length)return u.flatMap(nodesIn);let g=idOf(c);return m.filter(c=>y.get(c.id)===g&&h.has(c.id))},shift=(c,u)=>{let m=h.get(c.id);!m||Math.abs(u)<.5||(v.moves.push({elements:[c],dx:0,dy:u}),h.set(c.id,{...m,y:m.y+u}),(c.attachers||[]).forEach(c=>{let m=h.get(c.id);m&&(v.moves.push({elements:[c],dx:0,dy:u}),h.set(c.id,{...m,y:m.y+u}))}))},place=(c,u,y,S)=>{let w=S;return c.forEach(c=>{let S=orderLanes(laneChildren(c),m,new Set(m.map(c=>c.id)),u=>{let m=u.businessObject?.lanes?.[0]?.id;return laneChildren(c).some(c=>(c.businessObject?.id??c.id)===m)?m:void 0}),T=y-Lr,E;if(S.length)E=place(S,u+Lr,T,w)-w;else{let u=nodesIn(c);if(u.length){u.map(c=>h.get(c.id));let c=u.map(c=>{let u=h.get(c.id),m=(c.attachers||[]).map(c=>h.get(c.id)).filter(c=>!!c);return{top:Math.min(u.y,...m.map(c=>c.y)),bottom:Math.max(u.y+u.height,...m.map(c=>c.y+c.height))}}),m=Math.min(...c.map(c=>c.top));E=Math.max(...c.map(c=>c.bottom))-m+g.nodesep*2;let v=w+g.nodesep-m;u.forEach(c=>shift(c,v))}else E=g.nodesep*2+40}v.resizes.push({element:c,x:u,y:w,width:y,height:E}),h.set(c.id,{x:u,y:w,width:y,height:E}),w+=E}),w},laneIdOf=c=>{let m=c.businessObject?.lanes?.[0]?.id;if(!m)return;let h=u.find(c=>(c.businessObject?.id??c.id)===m);for(;h&&h.parent&&h.parent.type===`bpmn:Lane`&&!u.includes(h);)h=h.parent;return h?h.businessObject?.id??h.id:m},S=orderLanes(u,m,new Set(m.map(c=>c.id)),laneIdOf),w=m.filter(c=>!Z.has(c.type??``)&&h.get(c.id)),T=w.length>0?w:m.filter(c=>h.get(c.id)),E=Math.min(...T.map(c=>h.get(c.id).x))-g.marginX,D=Math.max(...T.map(c=>h.get(c.id).x+h.get(c.id).width))+g.marginX-E,k=Math.min(...T.map(c=>h.get(c.id).y))-g.marginY,j=place(S,E,D,k);v.resizes.push({element:c,x:E-Lr,y:k,width:D+Lr,height:j-k})}function planAnnotationRoutes(c,u,m,h,g,v,y,S){let w=[];c.forEach(c=>{(c.outgoing||[]).forEach(u=>{let m=u.target;if(!m)return;let h=Z.has(c.type??``);h!==Z.has(m.type??``)&&w.push({real:h?m:c,annotation:h?c:m,conn:u,elIsAnn:h})})});let annotationSideOf=(c,u)=>u.y>=c.y+c.height?`SOUTH`:u.y+u.height<=c.y?`NORTH`:u.x>=c.x+c.width?`EAST`:`WEST`,T=new Map;w.forEach(c=>{let u=m.get(c.real.id),h=m.get(c.annotation.id);if(!u||!h)return;let g=`${c.real.id}:${annotationSideOf(u,h)}`;T.has(g)||T.set(g,[]),T.get(g).push(c)}),w.forEach(c=>{let u=m.get(c.real.id),h=m.get(c.annotation.id);if(!u||!h)return;let g=annotationSideOf(u,h),v=T.get(`${c.real.id}:${g}`)??[c],S=.5;if(v.length>1&&!isRoundShape(c.real)){let u=[...v].sort((c,u)=>{let h=m.get(c.annotation.id),v=m.get(u.annotation.id);return(g===`NORTH`||g===`SOUTH`?h.x+h.width/2:h.y+h.height/2)-(g===`NORTH`||g===`SOUTH`?v.x+v.width/2:v.y+v.height/2)||(c.annotation.id<u.annotation.id?-1:1)});S=(u.findIndex(u=>u.annotation.id===c.annotation.id)+1)/(u.length+1)}let w=computeAnnotationWaypoints(u,h,S),E=c.elIsAnn?[...w].reverse():w;y.routes.push({connection:c.conn,waypoints:E})});let E=0,D=0,routeIfBackEdge=(c,w)=>{let T=w.target;if(!T||!u.has(T.id)||Z.has(T.type??``)||g||!isBackEdge(c,T.id,h))return;let k=m.get(c),j=m.get(T.id);if(!k||!j)return;let M=k.x+k.width/2,N=j.x+j.width/2,P=v+S.nodesep+E*S.nodesep;D=Math.max(D,P),y.routes.push({connection:w,waypoints:[{x:M,y:k.y+k.height},{x:M,y:P},{x:N,y:P},{x:N,y:j.y+j.height}]}),E+=1};return c.forEach(c=>{Z.has(c.type??``)||((c.outgoing||[]).forEach(u=>routeIfBackEdge(c.id,u)),(c.attachers||[]).forEach(c=>(c.outgoing||[]).forEach(u=>routeIfBackEdge(c.id,u))))}),D}async function solveContainerPlacement(c,u,m,h,g,v,y,S,w){let T=w,E=T?{positions:new Map(u.filter(c=>T.positions.has(c.id)).map(c=>[c.id,T.positions.get(c.id)])),sizes:T.sizes,padding:T.padding}:void 0,k=E&&E.positions.size===u.length?E:void 0,j=placeWithConstraints(u,v,Z,k);if(j){let T=applyPlacement(u,j.positions,y,c=>[c],S);for(let c of u){if((c.children||[]).filter(c=>!W(c)&&!K(c)&&!D(c)&&c.type!==`bpmn:Lane`).length===0)continue;let u=j.positions.get(c.id)??{x:c.x,y:c.y},m=k?.positions.get(c.id)??{x:c.x,y:c.y},h=T.rects.get(c.id);await layoutContainer(c,v,h?{x:h.x,y:h.y}:null,y,[],{x:S.x+u.x-m.x,y:S.y+u.y-m.y},w)}let E=new Map(y.resizes.map(c=>[c.element.id,c]));u.forEach(c=>{let u=E.get(c.id);u&&T.rects.set(c.id,{x:u.x,y:u.y,width:u.width,height:u.height})}),u.forEach(c=>{let u=T.rects.get(c.id);if(!u)return;let{south:m,north:h}=splitAttachers(c),spread=(m,h)=>{if(m.length===0)return;let g=attacherOffsets(c,u.width);m.forEach(c=>{let m=c.width||36,v=c.height||36,S=Math.round(u.x+g.get(c.id)-m/2),w=Math.round(h-v/2);(S!==c.x||w!==c.y)&&y.moves.push({elements:[c],dx:S-c.x,dy:w-c.y}),T.rects.set(c.id,{x:S,y:w,width:m,height:v})})};spread(m,u.y+u.height),spread(h,u.y)}),g&&stackLanes(c,m,u,T.rects,v,y);let{routes:M,edgeMeta:N}=await routeBestContainerEdges(u,T.rects,j.rows,j.ranks,!0,k?void 0:T.movedIds),P=[...T.rects.values()],sideKey=(c,u,m)=>u?Math.abs(c.x-u.x)<.5?`${m}:W`:Math.abs(c.x-(u.x+u.width))<.5?`${m}:E`:Math.abs(c.y-u.y)<.5?`${m}:N`:`${m}:S`:``,I=new Map;M.forEach((c,u)=>{let m=N.get(u);if(!m)return;let h=m.connection.source,g=m.connection.target;[sideKey(c.sourcePoint,h?T.rects.get(h.id):void 0,h?.id??``),sideKey(c.targetPoint,g?T.rects.get(g.id):void 0,g?.id??``)].forEach(c=>{c&&I.set(c,(I.get(c)??0)+1)})});let alone=(c,u,m)=>(I.get(sideKey(c,u,m))??0)<=1,L=new Map([...M.entries()].map(([c,u])=>[c,[u.sourcePoint,...u.bendPoints,u.targetPoint]])),z=new Set([...N.values()].map(c=>c.connection.id));formatAuthoredRoutes(u,T.rects,y,z),M.forEach((c,u)=>{let m=N.get(u);if(!m)return;let h=m.connection.source?T.rects.get(m.connection.source.id):void 0,g=m.connection.target?T.rects.get(m.connection.target.id):void 0,v=[...L.entries()].filter(([c])=>c!==u).map(([,c])=>c),S=simplifyJogs(L.get(u),P),w=anchorEndpoints(normaliseStubs(reduceBends(fixPortApproaches(S,h,g,P,v,m.connection.source?isRoundShape(m.connection.source)&&alone(S[0],h,m.connection.source.id):!1,m.connection.target?isRoundShape(m.connection.target)&&alone(S[S.length-1],g,m.connection.target.id):!1),h,g,P),h,g,P),h,g,P),cutsOf=c=>{let u=0;for(let m=0;m+1<c.length;m++)segmentHitsAnyRect(c[m],c[m+1],P)&&u++;return u},E=cutsOf(w)>cutsOf(S)?S:w;moveConnectionLabel(m.connection,E,y),y.routes.push({connection:m.connection,waypoints:E})});let frameOf=c=>({x:c.x+S.x,y:c.y+S.y,width:c.width,height:c.height});return g||fitContainer(c,T.rects,h,v,y,frameOf(c),!!k),{size:T.size,flowNodes:u,laned:g,authored:!0}}return null}async function layoutContainer(c,u,m,h,g=[],v={x:0,y:0},y=null){let idOrder=(c,u)=>c.id<u.id?-1:+(c.id>u.id),S=(c.children||[]).filter(c=>c.type===`bpmn:Lane`),w=(c.children||[]).filter(c=>!W(c)&&!K(c)&&!D(c)&&c.type!==`bpmn:Lane`),T=[...w,...g].sort(idOrder);if(T.length===0)return null;let E=new Set(T.map(c=>c.id)),k=new Set(w.filter(c=>!Z.has(c.type??``)).map(c=>c.id)),j=S.length>0;if(kr){let m=await solveContainerPlacement(c,T,S,k,j,u,h,v,y);if(m)return m}let{positions:M,rows:N,ranks:P,laneBands:I,authored:L}=j?computeLanedNodePositions(T,E,S,u):{...computeNodePositions(T,E,u),laneBands:null};if(L&&c.width>0&&c.height>0){let m=c.x+v.x,g=c.y+v.y,y=u.marginY/2,S=0,w=0;T.forEach(u=>{let h=M.get(u.id);if(!h)return;let T=m+y-v.x,E=g+y-v.y,D={x:Math.max(h.x,T),y:Math.max(h.y,E)};M.set(u.id,D),S=Math.max(S,D.x+v.x+u.width+y-(m+c.width)),w=Math.max(w,D.y+v.y+u.height+y-(g+c.height))}),(S>0||w>0)&&h.resizes.push({element:c,x:m,y:g,width:c.width+Math.max(0,S),height:c.height+Math.max(0,w)})}T.forEach(c=>{let u=M.get(c.id);u&&(Number.isFinite(u.x)&&Number.isFinite(u.y)||M.set(c.id,{x:Number.isFinite(u.x)?u.x:c.x,y:Number.isFinite(u.y)?u.y:c.y}))});let z=new Map,B=0,V=0,H=0;T.forEach(c=>{let u=M.get(c.id);if(c.label){let m=u.x+(c.label.x-c.x);H=Math.max(H,-m)}}),T.forEach(c=>{let u=M.get(c.id),g=L?u.x:u.x+(m?.x??0)+H,y=L?u.y:u.y+(m?.y??0),S=g-c.x,w=y-c.y;if((S!==0||w!==0)&&h.moves.push({elements:collectMoveGroup(c),dx:S,dy:w}),z.set(c.id,{x:g+v.x,y:y+v.y,width:c.width,height:c.height}),L){(c.attachers||[]).forEach(c=>{z.set(c.id,{x:c.x+S+v.x,y:c.y+w+v.y,width:c.width,height:c.height})}),B=Math.max(B,g+c.width),V=Math.max(V,y+c.height+boundaryOverhang(c,`SOUTH`)),c.label&&(B=Math.max(B,g+(c.label.x+c.label.width-c.x)),V=Math.max(V,y+(c.label.y+c.label.height-c.y)));return}let{south:T,north:E}=splitAttachers(c);[{list:T,y:y+c.height},{list:E,y}].forEach(({list:u,y:m})=>{let v=jr,y=u.reduce((c,u)=>c+u.width,0)+v*Math.max(0,u.length-1),T=g+c.width/2-y/2;u.forEach(c=>{let u=T,g=m-c.height/2;z.set(c.id,{x:u,y:g,width:c.width,height:c.height});let y=u-(c.x+S),E=g-(c.y+w);(y!==0||E!==0)&&h.moves.push({elements:[c],dx:y,dy:E}),T+=c.width+v})}),B=Math.max(B,g+c.width),V=Math.max(V,y+c.height+boundaryOverhang(c,`SOUTH`)),c.label&&(B=Math.max(B,g+(c.label.x+c.label.width-c.x)),V=Math.max(V,y+(c.label.y+c.label.height-c.y)))});let U=planAnnotationRoutes(T,E,z,P,!!L,V,h,u);V=Math.max(V,U);for(let c of T){if((c.children||[]).filter(c=>!W(c)&&!K(c)&&!D(c)&&c.type!==`bpmn:Lane`).length===0)continue;let m=z.get(c.id);if(!m)continue;let g=h.resizes.length;await layoutContainer(c,u,{x:m.x,y:m.y},h,[],{x:m.x-c.x,y:m.y-c.y},y);let v=h.resizes.slice(g).find(u=>u.element===c);v&&(z.set(c.id,{x:v.x,y:v.y,width:v.width,height:v.height}),B=Math.max(B,v.x+v.width),V=Math.max(V,v.y+v.height))}let ee=new Set(T.filter(c=>{let u=z.get(c.id);return!!u&&(Math.abs(u.x-c.x)>1||Math.abs(u.y-c.y)>1)}).map(c=>c.id));if(L){let c=T.filter(c=>!Z.has(c.type??``)).map(c=>({id:c.id,rect:z.get(c.id)})).filter(c=>!!c.rect);T.forEach(u=>{[u,...u.attachers||[]].forEach(m=>{(m.outgoing||[]).forEach(h=>{let g=h,v=g.target;if(!v||Z.has(v.type??``)||Z.has(u.type??``))return;let y=g.waypoints??[];y.slice(1).some((u,h)=>{let g=y[h],S=Math.min(g.x,u.x),w=Math.max(g.x,u.x),T=Math.min(g.y,u.y),E=Math.max(g.y,u.y);return c.some(({id:c,rect:u})=>c===m.id||c===v.id?!1:S<u.x+u.width-2&&w>u.x+2&&T<u.y+u.height-2&&E>u.y+2)})&&(ee.add(m.id),ee.add(v.id))})})})}let{routes:G,edgeMeta:Q}=await routeBestContainerEdges(T,z,N,P,L===!0,L===!0?ee:void 0),te=[...z.values()],ne=new Map([...G.entries()].map(([c,u])=>[c,[u.sourcePoint,...u.bendPoints,u.targetPoint]])),$=new Set([...Q.values()].map(c=>c.connection.id));L&&formatAuthoredRoutes(T,z,h,$),G.forEach((c,u)=>{let m=Q.get(u);if(!m)return;let g=m.connection.source?z.get(m.connection.source.id):void 0,v=m.connection.target?z.get(m.connection.target.id):void 0,y=[...ne.entries()].filter(([c])=>c!==u).map(([,c])=>c),S=simplifyJogs(ne.get(u),te),w=m.connection.source?isRoundShape(m.connection.source):!1,T=m.connection.target?isRoundShape(m.connection.target):!1,E=reduceBends(fixPortApproaches(S,g,v,te,y,w,T),g,v,te);moveConnectionLabel(m.connection,E,h),h.routes.push({connection:m.connection,waypoints:E})});let re=m?.x??0,ae=m?.y??0;if(I){let g=m?ae-40:0,v=B+40,y=I.reduce((c,u)=>c+u.height,0),w=Math.max(y,U+u.nodesep-g),T=w-y;T>0&&(I[I.length-1].height+=T);let E=w;V=Math.max(V,g+E),h.resizes.push({element:c,x:0,y:g,width:v,height:E}),S.forEach((c,u)=>{let m=I[u];h.resizes.push({element:c,x:0,y:g+m.y,width:v,height:m.height})})}return{size:{width:B-re,height:V-ae},flowNodes:T,laned:j,authored:L===!0}}function formatAuthoredRoutes(c,u,m,h){let deltaOf=c=>{let m=c?u.get(c.id):void 0;return!c||!m?{x:0,y:0}:{x:m.x-c.x,y:m.y-c.y}},g=new Set;c.forEach(c=>{[c,...c.attachers||[]].forEach(c=>{(c.outgoing||[]).forEach(u=>{let v=u;if(g.has(v.id)||(g.add(v.id),h?.has(v.id)))return;let y=v.waypoints??[];if(y.length<2)return;let S=deltaOf(v.source??c),w=deltaOf(v.target),T=y.length-1,E=y.map((c,u)=>{let m=T===0?0:u/T;return{x:c.x+S.x+(w.x-S.x)*m,y:c.y+S.y+(w.y-S.y)*m}});for(let c=1;c<E.length;c++){let u=c===E.length-1?Pr:Nr;Math.abs(E[c].x-E[c-1].x)<=u?E[c].x=E[c-1].x:Math.abs(E[c].y-E[c-1].y)<=u&&(E[c].y=E[c-1].y)}moveConnectionLabel(v,E,m),m.routes.push({connection:v,waypoints:E})})})})}function annotationLinkedNodeIds(c){let u=[];return(c.outgoing||[]).forEach(c=>{c.target&&!Z.has(c.target.type??``)&&u.push(c.target.id)}),(c.incoming||[]).forEach(c=>{c.source&&!Z.has(c.source.type??``)&&u.push(c.source.id)}),u}function computeHandlerPaths(c,u){let m=new Map(c.map(c=>[c.id,c])),h=new Map,g=[];c.forEach(c=>virtualOutgoing(c,u).forEach(u=>{u.fromBoundary?g.push(u.target.id):(h.has(u.target.id)||h.set(u.target.id,new Set),h.get(u.target.id).add(c.id))}));let v=new Set,y=[];return[...new Set(g)].forEach(c=>{let g=new Set,S=[c];for(;S.length;){let c=S.shift();if(g.has(c)||v.has(c))continue;g.add(c);let h=m.get(c);h&&virtualOutgoing(h,u).filter(c=>!c.fromBoundary).forEach(c=>S.push(c.target.id))}for(let u=!1;!u;)u=!0,[...g].forEach(m=>{if(m===c)return;let v=h.get(m);v&&![...v].every(c=>g.has(c))&&(g.delete(m),u=!1)});g.size!==0&&(g.forEach(c=>v.add(c)),y.push([...g]))}),y.sort((c,u)=>u.length-c.length)}var Br=200,Vr=.5;function solveBandCentres(c,u,m,h,g,v,y,S,w){let T=Math.max(...c.map(g))+w.nodesep,stepOf=({source:c,target:u,escape:h})=>h||Math.sign(m(u)-m(c)),E=new Map(c.map(c=>[c.id,c.id])),bandOf=c=>{let u=c;for(;E.get(u)!==u;)u=E.get(u);let m=c;for(;E.get(m)!==u;){let c=E.get(m);E.set(m,u),m=c}return u};u.forEach(c=>{stepOf(c)===0&&E.set(bandOf(c.source.id),bandOf(c.target.id))});let D=new Map,connect=(c,u,m)=>{D.has(c)||D.set(c,[]),D.get(c).push({other:u,delta:m})};u.forEach(c=>{let u=stepOf(c);if(u===0)return;let{source:m,target:h,escape:v,port:E}=c,D=u*((v?w.nodesep+E:T)+(v||(S.get(m.id)??0)>1?g(m)/2:0)+((y.get(h.id)??0)>1?g(h)/2:0));connect(bandOf(m.id),bandOf(h.id),D),connect(bandOf(h.id),bandOf(m.id),-D)});let k=new Map,j=[...c].sort((c,u)=>m(c)-m(u)||h(c)-h(u));j.forEach(c=>{if(k.has(bandOf(c.id)))return;k.set(bandOf(c.id),m(c)*T);let u=[bandOf(c.id)];for(;u.length;){let c=u.shift();(D.get(c)??[]).forEach(({other:m,delta:h})=>{k.has(m)||(k.set(m,k.get(c)+h),u.push(m))})}});let centreOf=c=>k.get(bandOf(c.id)),M=[...new Set(c.map(h))].sort((c,u)=>c-u),N=[...new Set(j.map(c=>bandOf(c.id)))];for(let u=0;u<Br;u++){let u=0;if(N.forEach(c=>{let m=D.get(c)??[];if(!m.length)return;let h=m.reduce((c,{other:u,delta:m})=>c+k.get(u)-m,0)/m.length;u=Math.max(u,Math.abs(h-k.get(c))),k.set(c,h)}),M.forEach(y=>{let S=c.filter(c=>h(c)===y).sort((c,u)=>centreOf(c)-centreOf(u)||m(c)-m(u));for(let c=1;c<S.length;c++){let m=S[c-1],h=S[c],y=g(m)/2+v(m)+w.nodesep+g(h)/2-(centreOf(h)-centreOf(m));y>0&&(k.set(bandOf(h.id),centreOf(h)+y),u=Math.max(u,y))}}),u<Vr)break}let P=w.marginY-Math.min(...c.map(c=>centreOf(c)-g(c)/2));return[...k.keys()].forEach(c=>k.set(c,k.get(c)+P)),centreOf}function placeLevel(c,u,m){let decoration=c=>Z.has(c.type??``),h=c.filter(c=>!decoration(c));if(h.length===0)return new Map(c.map(c=>[c.id,{x:c.x,y:c.y}]));let g=h.filter(c=>c.type===`bpmn:Participant`);if(g.length===h.length){let u=new Map,h=m.marginY;return[...g].sort((c,u)=>c.y-u.y||(c.id<u.id?-1:1)).forEach(c=>{u.set(c.id,{x:m.marginX,y:h}),h+=(c.height||200)+m.nodesep}),placeDecorations(c.filter(decoration),g,u,m,c=>c.width||100,c=>c.height||80)}let v=computeRanks(h,u),y=computeHandlerPaths(h,u),S=new Set(y.flat()),w=computeTopGroups(h,u,v),T=computeRows(h,u,v,w.groups),E=computeBranchOrder(h,u,w.groups,T),{groups:D}=computeTopGroups(h,u,v,E),k=computeRows(h,u,v,D,E);reduceRowCrossings(h,u,v,D,k,new Set);let j=new Map;h.forEach(c=>{let m=attacherOffsets(c,c.width||100),h=new Set(splitAttachers(c).north.map(c=>c.id));virtualOutgoing(c,u).forEach(u=>{u.fromBoundary&&S.has(u.target.id)&&j.set(u.target.id,{row:k.get(c.id)??0,port:m.get(u.sourceAttacherId??``)??0,away:h.has(u.sourceAttacherId??``)?-1:1})})});let M=y.map(c=>({path:c,entry:j.get(c.find(c=>j.has(c))??``)})).filter(c=>!!c.entry).sort((c,u)=>c.entry.row-u.entry.row||u.entry.port-c.entry.port);M.forEach(({path:c,entry:u},m)=>{let h=(m+1)/(M.length+1);c.forEach(c=>k.set(c,u.row+u.away*h))});let N=[...new Set([...k.values()])].sort((c,u)=>c-u),P=new Map(N.map((c,u)=>[c,u]));k.forEach((c,u)=>k.set(u,P.get(c)));let widthOf=c=>c.width||100,heightOf=c=>c.height||80,captionOf=c=>c.label&&c.label.y>=c.y+heightOf(c)?c.label.y+c.label.height-(c.y+heightOf(c)):0,rowOf=c=>k.get(c.id)??0,rankOf=c=>v.get(c.id)??0,I=new Map,L=new Map,z=[];h.forEach(c=>{let m=new Set(splitAttachers(c).north.map(c=>c.id));virtualOutgoing(c,u).forEach(u=>{if(u.fromBoundary){let h=(c.attachers||[]).find(c=>c.id===u.sourceAttacherId);z.push({source:c,target:u.target,escape:m.has(u.sourceAttacherId??``)?-1:1,port:(h?.height||36)/2})}else I.set(c.id,(I.get(c.id)??0)+1),L.set(u.target.id,(L.get(u.target.id)??0)+1),z.push({source:c,target:u.target,escape:0,port:0})})});let B=solveBandCentres(h,z,rowOf,rankOf,heightOf,captionOf,L,I,m),middleY=c=>B(c),topOf=c=>middleY(c)-heightOf(c)/2,V=[...new Set(h.map(rankOf))].sort((c,u)=>c-u),H=new Map;V.forEach(c=>{let u=h.filter(u=>rankOf(u)===c&&!S.has(u.id));H.set(c,u.length?Math.max(...u.map(widthOf)):0)});let U=new Map;z.forEach(({source:c,target:u,escape:h})=>{if(S.has(u.id))return;let g=rankOf(c),v=rankOf(u);if(v<=g)return;let y=Math.abs(middleY(u)-middleY(c)),w=h!==0||(I.get(c.id)??0)>1&&y>heightOf(c)/2,T=(L.get(u.id)??0)>1&&y>heightOf(u)/2,E=w||T||y<1?1:2,D=H.get(g)/2+(w?0:widthOf(c)/2)+E*(h?m.nodesep:m.ranksep)+(T?0:widthOf(u)/2)-H.get(v)/2;U.has(v)||U.set(v,[]),U.get(v).push({from:g,reach:D})});let W=new Map;V.forEach((c,u)=>{if(u===0){W.set(c,m.marginX);return}let h=V[u-1],g=W.get(h)+H.get(h)+m.ranksep;(U.get(c)??[]).forEach(({from:c,reach:u})=>{W.has(c)&&(g=Math.max(g,W.get(c)+u))}),W.set(c,Math.round(g))});let ee=new Map;h.forEach(c=>virtualOutgoing(c,u).forEach(u=>{u.fromBoundary&&S.has(u.target.id)&&ee.set(u.target.id,c)}));let columnLeft=c=>W.get(rankOf(c))+(H.get(rankOf(c))-widthOf(c))/2,G=new Map;y.forEach(c=>{let g=c.find(c=>ee.has(c));if(g===void 0)return;let v=ee.get(g),y=columnLeft(v)+widthOf(v)+m.nodesep,w=[g],T=new Set;for(;w.length;){let c=w.shift();if(T.has(c))continue;T.add(c);let g=h.find(u=>u.id===c);g&&(G.set(c,y),y+=widthOf(g)+m.nodesep,virtualOutgoing(g,u).filter(c=>!c.fromBoundary&&S.has(c.target.id)).forEach(c=>w.push(c.target.id)))}});let K=new Map;h.forEach(c=>{let u=G.get(c.id)??columnLeft(c);K.set(c.id,{x:Math.round(u),y:Math.round(topOf(c))})});let Q=packComponents(h,z,K,m,widthOf,heightOf,captionOf);return placeDecorations(c.filter(decoration),h,Q,m,widthOf,heightOf)}var Hr=12;function placeDecorations(c,u,m,h,g,v){if(c.length===0)return m;let y=new Map(u.map(c=>[c.id,c])),w=u.filter(c=>m.has(c.id)).map(c=>({...m.get(c.id),width:g(c),height:v(c)})),clear=c=>!w.some(u=>S(c,u)),atThisLevel=c=>{let u=c;for(;u;){let c=y.get(u.id);if(c&&m.has(c.id))return c;u=u.parent}},ownersOf=c=>{let u=[...(c.outgoing||[]).map(c=>c.target),...(c.incoming||[]).map(c=>c.source)].map(atThisLevel).filter(u=>!!u&&!c.id.startsWith(u.id));return[...new Map(u.map(c=>[c.id,c])).values()]},T=h.nodesep;return[...c].map((c,u)=>({decoration:c,index:u,owners:ownersOf(c)})).sort((c,u)=>u.owners.length-c.owners.length||g(u.decoration)*v(u.decoration)-g(c.decoration)*v(c.decoration)||c.index-u.index).forEach(({decoration:c,owners:u})=>{let y=g(c),S=v(c),beside=()=>{let c=w.length?Math.max(...w.map(c=>c.x+c.width)):h.marginX,u=w.length?Math.min(...w.map(c=>c.y)):h.marginY;for(;!clear({x:c+T,y:u,width:y,height:S});)u+=S+T;return{x:c+T,y:u,width:y,height:S}};if(u.length===0){let u=beside();m.set(c.id,{x:Math.round(u.x),y:Math.round(u.y)}),w.push(u);return}let E={x:u.reduce((c,u)=>c+m.get(u.id).x+g(u)/2,0)/u.length,y:u.reduce((c,u)=>c+m.get(u.id).y+v(u)/2,0)/u.length},D={top:Math.min(...u.map(c=>m.get(c.id).y)),bottom:Math.max(...u.map(c=>m.get(c.id).y+v(c))),left:Math.min(...u.map(c=>m.get(c.id).x)),right:Math.max(...u.map(c=>m.get(c.id).x+g(c)))},k=[{x:E.x-y/2,y:D.bottom+T,slide:`x`},{x:E.x-y/2,y:D.top-T-S,slide:`x`},{x:D.right+T,y:E.y-S/2,slide:`y`},{x:D.left-T-y,y:E.y-S/2,slide:`y`}],j=null;for(let c of k){for(let u=0;u<=8&&!j;u++)for(let m of u===0?[1]:[1,-1]){let h=m*u*(T+Math.min(y,S)),g={x:c.x+(c.slide===`x`?h:0),y:c.y+(c.slide===`y`?h:0),width:y,height:S};if(clear(g)){j=g;break}}if(j)break}let nearby=()=>{let c=T+Math.min(y,S)/2,u=[];for(let m=1;m<=Hr;m++)for(let h=-m;h<=m;h++)for(let g of[-m,m])u.push({x:E.x-y/2+h*c,y:E.y-S/2+g*c,width:y,height:S}),u.push({x:E.x-y/2+g*c,y:E.y-S/2+h*c,width:y,height:S});return u.filter(clear).sort((c,u)=>Math.abs(c.x-E.x)+Math.abs(c.y-E.y)-(Math.abs(u.x-E.x)+Math.abs(u.y-E.y)))[0]??null},M=j??nearby()??beside();m.set(c.id,{x:Math.round(M.x),y:Math.round(M.y)}),w.push(M)}),m}function packComponents(c,u,m,h,g,v,y){let S=new Map(c.map(c=>[c.id,c.id])),rootOf=c=>{let u=c;for(;S.get(u)!==u;)u=S.get(u);let m=c;for(;S.get(m)!==u;){let c=S.get(m);S.set(m,u),m=c}return u};u.forEach(({source:c,target:u})=>S.set(rootOf(c.id),rootOf(u.id)));let w=new Map;if(c.forEach(c=>{let u=rootOf(c.id);w.has(u)||w.set(u,[]),w.get(u).push(c)}),w.size<2)return m;let T=h.nodesep,E=[...w.values()].map(c=>{let u=Math.min(...c.map(c=>m.get(c.id).x))-T,h=Math.min(...c.map(c=>m.get(c.id).y))-T;return{group:c,left:u,top:h,width:Math.max(...c.map(c=>m.get(c.id).x+g(c)))+T-u,height:Math.max(...c.map(c=>m.get(c.id).y+v(c)+y(c)))+T-h}}).map(c=>({box:c,shapes:c.group.map(c=>{let u=m.get(c.id);return{x:u.x,y:u.y,width:g(c),height:v(c)+y(c)}})})),D=E.reduce((c,{box:u})=>c+u.width+u.height,0),k=E.reduce((c,{box:u})=>c+u.width*u.height,0),j=Math.max(1,Rr*E.length-1),M=Math.max(h.nodesep,(D+Math.sqrt(D*D+4*j*k))/(2*j)),shapeOf=({box:c,shapes:u})=>{let m=new Set;return u.forEach(u=>{let h=Math.floor((u.x-c.left)/M),g=Math.floor((u.y-c.top)/M),v=Math.floor((u.x+u.width-c.left)/M),y=Math.floor((u.y+u.height-c.top)/M);for(let c=h;c<=v;c++)for(let u=g;u<=y;u++)m.add(`${c}:${u}`)}),[...m].map(c=>{let[u,m]=c.split(`:`).map(Number);return{column:u,row:m}})},N=E.map(c=>({...c,tiles:shapeOf(c)})).sort((c,u)=>u.box.width+u.box.height-(c.box.width+c.box.height)),P=new Set,I=Math.ceil(Math.sqrt(N.reduce((c,u)=>c+u.tiles.length,0)))+4,L=[];for(let c=0;c<=I;c++)for(let u=-c;u<=c;u++)for(let m=-c;m<=c;m++)Math.max(Math.abs(u),Math.abs(m*zr))===c&&L.push({x:u,y:m});let z=new Map;N.forEach(c=>{let u=L.find(u=>c.tiles.every(c=>!P.has(`${u.x+c.column}:${u.y+c.row}`)))??L[L.length-1];c.tiles.forEach(c=>P.add(`${u.x+c.column}:${u.y+c.row}`)),c.box.group.forEach(h=>{let g=m.get(h.id);z.set(h.id,{x:g.x-c.box.left+u.x*M,y:g.y-c.box.top+u.y*M})})});let B=Math.min(...[...z.values()].map(c=>c.x)),V=Math.min(...[...z.values()].map(c=>c.y));return z.forEach((c,u)=>z.set(u,{x:c.x-B+h.marginX,y:c.y-V+h.marginY})),z}function layeredSeed(c,u,m){let h=new Map,g=new Map,v=new Map,y=new Map,layoutLevel=c=>{let v=(c.children||[]).filter(m);v.forEach(c=>y.set(c.id,c));let S=v.map(c=>{if(layoutChildren(c).length===0)return c;let u=layoutLevel(c),m={width:Math.max(u.width,attacherWidth(c)),height:u.height};return g.set(c.id,m),{...c,width:m.width,height:m.height}}),w=placeLevel(S,new Set(S.map(c=>c.id)),u),T=0,E=0,D=new Set;return S.forEach(c=>{let m={...w.get(c.id)??{x:c.x,y:c.y}};for(;D.has(`${Math.round(m.x)}:${Math.round(m.y)}`);)m.y+=c.height+u.nodesep;D.add(`${Math.round(m.x)}:${Math.round(m.y)}`),h.set(c.id,m),T=Math.max(T,m.x+c.width),E=Math.max(E,m.y+c.height)}),{width:T+u.marginX,height:E+u.marginY}};layoutLevel(c);let S=new Map,place=(c,u)=>{(c.children||[]).filter(m).forEach(c=>{let m=h.get(c.id);if(!m)return;let v={x:u.x+m.x,y:u.y+m.y};S.set(c.id,v),g.has(c.id)&&place(c,v)})};return place(c,{x:0,y:0}),S.forEach((c,u)=>{let m=y.get(u);if(!m||(m.attachers??[]).length===0)return;let h=g.get(u)?.width??m.width,{south:S,north:w}=splitAttachers(m),spanOf=c=>c.reduce((c,u,m)=>c+(u.width||36)+(m>0?jr:0),0),T=Math.max(0,(Math.max(spanOf(S),spanOf(w))-h)/2),tallest=c=>c.reduce((c,u)=>Math.max(c,(u.height||36)/2),0);v.set(u,{top:tallest(w),bottom:tallest(S),left:T,right:T})}),{positions:S,sizes:g,padding:v}}async function buildPlan(c,u,m,h=0){let isMovable=c=>!W(c)&&!K(c)&&!D(c)&&c.type!==`bpmn:Lane`,g={moves:[],resizes:[],routes:[]},v=kr?layeredSeed(c,u,isMovable):null,y=collectContainers(c),S=y.length>1,w=(c.children||[]).some(c=>c.type===`bpmn:Participant`)?(c.children||[]).filter(c=>Z.has(c.type??``)):[],T=0;for(let c of y){checkBudget(),await yieldToHost();let y=S?{x:40,y:T+40}:null,E=new Set((c.children||[]).filter(c=>!W(c)&&!K(c)&&!D(c)&&c.type!==`bpmn:Lane`).map(c=>c.id)),k=w.filter(c=>annotationLinkedNodeIds(c).some(c=>E.has(c))),j=await layoutContainer(c,m?.has(c.id)?{...u,nodesep:u.nodesep+h}:u,y,g,k,{x:0,y:0},v);if(j&&S){let u=[...g.resizes].reverse().find(u=>u.element.id===c.id);if(u){T=u.y+u.height+60;continue}let m=j.size.height+80;g.resizes.push({element:c,x:0,y:T,width:j.size.width+80,height:m}),T+=m+60}}return g}function clonePlan(c){return{moves:c.moves.map(c=>({...c,elements:[...c.elements]})),resizes:c.resizes.map(c=>({...c})),routes:c.routes.map(c=>({...c,waypoints:c.waypoints.map(c=>({...c}))}))}}function finishPlan(c,u,m,h,g,v,y,S,w,T=!1,E=!0){let D=clonePlan(u);stackPools(c,D,m,h),settleArtifacts(c,D,m,!1,E),stackPools(c,D,m,h),settleArtifacts(c,D,m,!1,E),v&&alignPools(c,D),checkBudget(),parkComments(c,D,m),repairRoutes(c,D,m,T),checkBudget(),planMessageFlows(c,D,g,y,S),reanchorRoutes(D),settleRoutes(c,D,m),reanchorRoutes(D),settleRoutes(c,D,m),checkBudget(),fitGroups(c,D,m),straightenAssociations(c,D),settleRoutes(c,D,m),straightenRoutes(c,D),shortenDetouredRoutes(c,D),redockRoundShapeSides(c,D),checkBudget(),tidyRoutes(D);for(let u=0;u<Wr;u++)Gr.forEach(u=>spreadRuns(c,D,u,`ordered`)),spreadRuns(c,D),spreadRuns(c,D,void 0,`border`),checkBudget();checkBudget(),flattenJogs(c,D);for(let u=0;u<2;u++)nudgeMergedRuns(c,D);flattenJogs(c,D),centerRoundAnchors(c,D);for(let u=0;u<2;u++)airOutSharedNodeRuns(c,D);return flattenJogs(c,D),checkBudget(),clearEdgeTouchingRuns(c,D),recordWidened(w,D),anchorEdgeNotes(c,D),settleLabels(c,D,m),spreadRuns(c,D,void 0,`lattice`),D}function talkingPools(c){if((c.children||[]).filter(c=>c.type===`bpmn:Participant`&&(c.children||[]).some(c=>!W(c))).length<2)return 0;let walk=c=>[c,...(c.children||[]).flatMap(walk)],u=new Set;return walk(c).forEach(c=>(c.outgoing||[]).forEach(c=>{let m=c;if(!j(m)||!m.source||!m.target)return;let h=V(m.source),g=V(m.target);h&&g&&h.id!==g.id&&(u.add(h.id),u.add(g.id))})),u.size}var Ur=[{exactOrder:!1,shortRoutes:!1,slidePools:!1,byChannel:!1,hugTarget:!0},{exactOrder:!1,shortRoutes:!1,slidePools:!1,byChannel:!1,hugTarget:!1},{exactOrder:!1,shortRoutes:!1,slidePools:!0,byChannel:!1,hugTarget:!0},{exactOrder:!1,shortRoutes:!0,slidePools:!1,byChannel:!1,hugTarget:!0},{exactOrder:!1,shortRoutes:!1,slidePools:!0,byChannel:!1,hugTarget:!1},{exactOrder:!1,shortRoutes:!0,slidePools:!0,byChannel:!1,hugTarget:!0},{exactOrder:!0,shortRoutes:!1,slidePools:!1,byChannel:!1,hugTarget:!0},{exactOrder:!0,shortRoutes:!1,slidePools:!0,byChannel:!1,hugTarget:!0},{exactOrder:!1,shortRoutes:!1,slidePools:!1,byChannel:!0,hugTarget:!1},{exactOrder:!0,shortRoutes:!0,slidePools:!1,byChannel:!1,hugTarget:!0},{exactOrder:!0,shortRoutes:!0,slidePools:!0,byChannel:!1,hugTarget:!0}],Wr=4,Gr=[36,20],Kr=[12,24,36,48],qr=4,Jr=[{upTo:60,plans:11},{upTo:120,plans:6},{upTo:1/0,plans:4}];function countShapes(c){let walk=c=>(W(c)||K(c)?0:1)+(c.children||[]).reduce((c,u)=>c+walk(u),0);return(c.children||[]).reduce((c,u)=>c+walk(u),0)}async function computeLayoutPlan(c,u,m={}){return assertLayoutable(c),withBudget(m,()=>planWithinBudget(c,u))}async function planWithinBudget(c,u){let m=widenForAttachers(c),h=await buildPlan(c,u),g=talkingPools(c),v=Jr.find(u=>countShapes(c)<=u.upTo).plans,y=Ur.filter(c=>(g>=2||!c.shortRoutes&&!c.slidePools&&!c.byChannel&&!c.hugTarget)&&(g>=3||!c.exactOrder)).slice(0,v),S=y[0],w=1/0,T=0;for(let[g,v]of y.entries()){if(g>0&&!hasSpare())break;checkBudget(),await yieldToHost();let{exactOrder:y,shortRoutes:E,slidePools:D,byChannel:k,hugTarget:j}=v,M=scoreLayout(c,finishPlan(c,h,u,y,E,D,k,j,m)).energy;T++,M<w&&(w=M,S=v)}let E=finishPlan(c,h,u,S.exactOrder,S.shortRoutes,S.slidePools,S.byChannel,S.hugTarget,m);if(checkPlanCorrectness(c,E).containment>0){let g=finishPlan(c,h,u,S.exactOrder,S.shortRoutes,S.slidePools,S.byChannel,S.hugTarget,m,!1,!1);checkPlanCorrectness(c,g).containment===0&&(E=g)}let D=scoreLayout(c,E),k=countAlongShape(c,E),j=countDetours(c,E),M=countAdriftNotes(E);if((D.merges>0||k>0||j>0)&&hasSpare()){let containerOf=u=>{let m=u;for(;m?.parent;)m=m.parent;return m??c},g=new Map,bump=c=>g.set(c,(g.get(c)??0)+1),v=E.routes.map(c=>c.waypoints);E.routes.forEach((c,u)=>{v.some((m,h)=>h!==u&&N(c.waypoints,m))&&(bump(containerOf(c.connection.source).id),bump(containerOf(c.connection.target).id))}),countAlongShape(c,E,(c,u)=>{bump(containerOf(c.connection.source).id),bump(containerOf(c.connection.target).id),bump(containerOf(u).id)}),countDetours(c,E,c=>{bump(containerOf(c.connection.source).id),bump(containerOf(c.connection.target).id)});let y=[...g.entries()].sort((c,u)=>u[1]-c[1]).slice(0,qr).map(([c])=>c),w,P=D.merges,I=k,L=j;for(let h of y)for(let g of Kr){if(!hasSpare())break;checkBudget(),await yieldToHost();let v=finishPlan(c,await buildPlan(c,u,new Set([h]),g),u,S.exactOrder,S.shortRoutes,S.slidePools,S.byChannel,S.hugTarget,m);if(!checkPlanCorrectness(c,v).ok)continue;let y=scoreLayout(c,v),T=countAlongShape(c,v),E=countDetours(c,v),N=countAdriftNotes(v);if(!(y.merges<=D.merges&&T<=k&&E<=j&&N<=M&&y.crossings<=D.crossings))continue;let z=y.merges<P||T<I||E<L,B=y.merges<=P&&T<=I&&E<=L;if(z&&B&&(w=v,P=y.merges,I=T,L=E),y.merges<D.merges||T<k||E<j)break}let z=finishPlan(c,h,u,S.exactOrder,S.shortRoutes,S.slidePools,S.byChannel,S.hugTarget,m,!0);if(checkPlanCorrectness(c,z).ok){let u=scoreLayout(c,z),m=countAlongShape(c,z),h=countDetours(c,z),g=countAdriftNotes(z),v=u.merges<=D.merges&&m<=k&&h<=j&&g<=M&&u.crossings<=D.crossings+1,y=u.merges<P||m<I||h<L,S=u.merges<=P&&m<=I&&h<=L;v&&y&&S&&(w=z,P=u.merges,I=m,L=h)}if(w)return eliminateMerges(c,w),nudgeMergedRuns(c,w),withSearch(c,w,T)}return eliminateMerges(c,E),nudgeMergedRuns(c,E),withSearch(c,E,T)}function withSearch(c,u,m){return{...u,search:{candidates:m,energy:scoreLayout(c,u).energy}}}function innermostLane(c){if(c&&c.length!==0)return[{id:(c.find(c=>!(c.childLaneSet?.lanes?.length>0))??c[c.length-1]).id}]}function labelOf(c,u){let m=c.label;if(!m||m===c)return;let h={id:m.id,type:`label`,x:m.x,y:m.y,width:m.width,height:m.height};return u.set(h,m),h}function layoutModel(c){let u=new Map,m=new Map;if(!c)return{root:{id:``,type:``,x:0,y:0,width:0,height:0,children:[]},editorOf:u};let h={id:c.id,type:c.type,x:0,y:0,width:0,height:0,children:[]};m.set(c,h);let g=[],v=[],walk=c=>{(c?.children||[]).forEach(c=>{c.type===`label`||c.labelTarget||(c.waypoints?v.push(c):(g.push(c),walk(c)))})};walk(c),g.forEach(c=>{let h=c.businessObject??{},g={id:c.id,type:c.type,x:c.x,y:c.y,width:c.width,height:c.height,children:[],attachers:[],outgoing:[],incoming:[],businessObject:c.type===`bpmn:Lane`?{id:h.id}:{id:h.id,eventDefinitions:h.eventDefinitions,lanes:innermostLane(h.lanes)}},v=labelOf(c,u);v&&(g.label=v),m.set(c,g),u.set(g,c)}),g.forEach(c=>{let u=m.get(c);u.parent=m.get(c.parent)??h,u.parent.children.push(u),c.host&&m.has(c.host)&&(u.host=m.get(c.host),u.host.attachers.push(u))});let isAssociation=c=>c.type===`bpmn:Association`;return[...v.filter(c=>!isAssociation(c)),...v.filter(isAssociation)].forEach(c=>{let h=m.get(c.source),g=m.get(c.target);if(!h||!g)return;let v={id:c.id,type:c.type,x:0,y:0,width:0,height:0,source:h,target:g,waypoints:(c.waypoints||[]).map(c=>({x:c.x,y:c.y})),businessObject:{id:c.businessObject?.id}},y=labelOf(c,u);y&&(v.label=y),h.outgoing=[...h.outgoing||[],v],g.incoming=[...g.incoming||[],v],m.set(c,v),u.set(v,c)}),{root:h,editorOf:u}}function editorPlan(c,u){let editor=c=>u?.get?.(c)??c;return{moves:(c?.moves??[]).map(c=>({...c,elements:(c.elements??[]).map(editor)})),resizes:(c?.resizes??[]).map(c=>({...c,element:editor(c.element)})),routes:(c?.routes??[]).map(c=>({...c,connection:editor(c.connection)}))}}var Yr=`bpmnEditor.autoLayout`,AutoLayoutCommandHandler=class{modeling;elementRegistry;static $inject=[`modeling`,`elementRegistry`];constructor(c,u){this.modeling=c,this.elementRegistry=u}canvasRoot(){return this.elementRegistry.getAll().find(c=>!c.parent)}preExecute(c){let{plan:u}=c,m=this.elementRegistry.getAll().filter(c=>c.parent&&!c.waypoints),h=new Map(m.map(c=>[c,{x:c.x,y:c.y}])),shift=(c,u,m)=>{let g=h.get(c);g&&h.set(c,{x:g.x+u,y:g.y+m})};u.moves.forEach(({elements:c,dx:u,dy:m})=>c.forEach(c=>{shift(c,u,m),c.label&&shift(c.label,u,m)})),u.resizes.forEach(({element:c,x:u,y:m})=>{h.has(c)&&h.set(c,{x:u,y:m})});let isLabel=c=>c.type===`label`||c.labelTarget!==void 0,depth=c=>{let u=c.host?.5:0;for(let m=c.parent;m;m=m.parent)u+=1;return u},place=c=>{let u=h.get(c),m=u.x-c.x,g=u.y-c.y;if(!(Math.abs(m)<.5&&Math.abs(g)<.5))try{this.modeling.moveShape(c,{x:m,y:g},c.parent??this.canvasRoot(),void 0,{recurse:!1})}catch(u){console.warn(`Auto layout could not move`,c.id,u)}},g=m.filter(c=>!isLabel(c)).sort((c,u)=>depth(c)-depth(u));g.forEach(place),u.resizes.forEach(({element:c,x:u,y:m,width:h,height:g})=>{this.modeling.resizeShape(c,{x:u,y:m,width:h,height:g})}),g.forEach(place),u.routes.forEach(({connection:c,waypoints:u})=>{try{this.modeling.updateWaypoints(c,u)}catch(u){console.warn(`Auto layout could not route`,c.id,u)}}),m.filter(isLabel).forEach(place)}execute(){return[]}revert(){return[]}},Xr=new WeakSet;function ensureCommandRegistered(c){Xr.has(c)||(c.registerHandler(Yr,AutoLayoutCommandHandler),Xr.add(c))}async function planLayout(c,u){let{root:m,editorOf:h}=layoutModel(c);return editorPlan(await computeLayoutPlan(m,Or,u),h)}function applyLayoutPlan(c,u){if(!c||!u)return;let m=c.get?.(`commandStack`);m&&(ensureCommandRegistered(m),m.execute(Yr,{plan:u}))}var GraphAwareLayoutService=class{budget;constructor(c){this.budget=c}async applyToModeler(c){await init(assetUrl(`/assets/libavoid.wasm`));let u=c.get(`elementRegistry`),m=c.get(`canvas`).getRootElement(),h=L(u.getAll().filter(W)),g=!1;if(h.length>0)try{c.get(`modeling`).removeElements(h),g=!0}catch(c){console.warn(`Auto layout could not remove duplicate connections`,c)}let v;try{v=await planLayout(m,this.budget)}catch(u){throw g&&c.get(`commandStack`).undo(),u}applyLayoutPlan(c,v);let{xml:y}=await c.saveXML({format:!0});return y}async applyLayout(c){try{return{success:!0,xml:await this.applyToModeler(c)}}catch(c){return{success:!1,error:c}}}},Zr=new GraphAwareLayoutService;export{Zr as graphAwareLayoutService};