@codexhost/cli-win32-x64 0.32.1 → 0.34.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (159) hide show
  1. package/README.md +2 -1
  2. package/app/codexhost-distribution.json +1 -1
  3. package/app/console-server.mjs +559 -15
  4. package/app/console-web.js +1361 -192
  5. package/app/desktop-controller.mjs +620 -16
  6. package/app/desktop-mcp-client.mjs +619 -0
  7. package/app/host-runtime.mjs +10370 -5625
  8. package/app/plugins/antigravity/plugin.mjs +888 -73
  9. package/app/plugins/claude-code/assets/icon.svg +1 -1
  10. package/app/plugins/claude-code/manifest.json +1 -1
  11. package/app/plugins/claude-code/plugin.mjs +1280 -198
  12. package/app/plugins/codebuddy/plugin.mjs +643 -35
  13. package/app/plugins/codex-usage/plugin.mjs +544 -12
  14. package/app/plugins/copilot/assets/icon.svg +1 -1
  15. package/app/plugins/copilot/manifest.json +1 -1
  16. package/app/plugins/copilot/plugin.mjs +546 -14
  17. package/app/plugins/cursor-cli/plugin.mjs +544 -12
  18. package/app/plugins/deepseek-harness/assets/icon.svg +1 -1
  19. package/app/plugins/deepseek-harness/manifest.json +1 -1
  20. package/app/plugins/deepseek-harness/plugin.mjs +983 -153
  21. package/app/plugins/devin/assets/icon.svg +1 -1
  22. package/app/plugins/devin/manifest.json +1 -1
  23. package/app/plugins/devin/plugin.mjs +546 -13
  24. package/app/plugins/enabled.json +1 -0
  25. package/app/plugins/grok/plugin.mjs +544 -12
  26. package/app/plugins/hermes/plugin.mjs +544 -12
  27. package/app/plugins/kimi-code/plugin.mjs +544 -12
  28. package/app/plugins/kiro-cli/plugin.mjs +544 -12
  29. package/app/plugins/omp/assets/icon.svg +1 -1
  30. package/app/plugins/omp/plugin.mjs +1381 -243
  31. package/app/plugins/opencode/plugin.mjs +548 -13
  32. package/app/plugins/pi/assets/icon.svg +1 -1
  33. package/app/plugins/pi/manifest.json +1 -1
  34. package/app/plugins/pi/plugin.mjs +572 -14
  35. package/app/plugins/qoder/assets/icon.svg +1 -1
  36. package/app/plugins/qoder/plugin.mjs +570 -12
  37. package/app/plugins/qoder-cn/assets/icon.svg +1 -1
  38. package/app/plugins/qoder-cn/plugin.mjs +570 -12
  39. package/app/plugins/qwen-code/assets/icon.svg +1 -1
  40. package/app/plugins/qwen-code/plugin.mjs +573 -12
  41. package/app/plugins/workbuddy/plugin.mjs +1263 -472
  42. package/app/plugins/workbuddy-cn/assets/icon.svg +27 -0
  43. package/app/plugins/workbuddy-cn/manifest.json +32 -0
  44. package/app/plugins/workbuddy-cn/plugin.mjs +36211 -0
  45. package/app/plugins/zcode/plugin.mjs +564 -19
  46. package/app/renderer-extension.js +2932 -262
  47. package/app/web/assets/{abnfDiagram-XWFEHMT6-7XITZmBH.js → abnfDiagram-XWFEHMT6-Cg-E7mc4.js} +1 -1
  48. package/app/web/assets/{architectureDiagram-CSQXQB3N-C8Usdzd8.js → architectureDiagram-CSQXQB3N-B__CwXjW.js} +1 -1
  49. package/app/web/assets/{blockDiagram-BEDRHYPZ-CyN9yE_Q.js → blockDiagram-BEDRHYPZ-Bk2gCIVM.js} +1 -1
  50. package/app/web/assets/{c4Diagram-M2UUVUY5-CjhY1l3g.js → c4Diagram-M2UUVUY5-DU_TpjJ3.js} +1 -1
  51. package/app/web/assets/{chunk-2Q5K7J3B-o24_rh4_.js → chunk-2Q5K7J3B-DnJEi6e4.js} +1 -1
  52. package/app/web/assets/{chunk-3GCGMST5-D7bw3E1a.js → chunk-3GCGMST5-Dia9jGkf.js} +1 -1
  53. package/app/web/assets/{chunk-5VM5RSS4-D0v4acf7.js → chunk-5VM5RSS4-2PGDiDvK.js} +1 -1
  54. package/app/web/assets/{chunk-7U7NFRK5-CYJxP4rV.js → chunk-7U7NFRK5-BLPm3d5H.js} +1 -1
  55. package/app/web/assets/{chunk-CNRTWJTD-DTgCtcCl.js → chunk-CNRTWJTD-GH_nAEXs.js} +1 -1
  56. package/app/web/assets/{chunk-D5HYT7QG-qRNelehW.js → chunk-D5HYT7QG-DnIm-Ely.js} +1 -1
  57. package/app/web/assets/{chunk-EBZ3SEQC-BgJPPYdu.js → chunk-EBZ3SEQC-C6N5qLCR.js} +2 -2
  58. package/app/web/assets/{chunk-JWPE2WC7-C50ZnSQQ.js → chunk-JWPE2WC7-D_kMgdmr.js} +1 -1
  59. package/app/web/assets/{chunk-KTR4FSNJ-Cifh4XHc.js → chunk-KTR4FSNJ-BRb9femQ.js} +1 -1
  60. package/app/web/assets/{chunk-XXDRQBXY-D23WAHPW.js → chunk-XXDRQBXY-BFaK95zq.js} +1 -1
  61. package/app/web/assets/{classDiagram-v2-KXABOMEV-B3cezFGj.js → classDiagram-v2-KXABOMEV--_hR_XrU.js} +1 -1
  62. package/app/web/assets/{cose-bilkent-JH36ORCC-VSMi4La2.js → cose-bilkent-JH36ORCC-C7ghEB3_.js} +1 -1
  63. package/app/web/assets/{cynefin-EF2NZ3EQ-qQnfHq16.js → cynefin-EF2NZ3EQ-Ce1lURwZ.js} +1 -1
  64. package/app/web/assets/{cynefinDiagram-NJNITYFG-BJELApXD.js → cynefinDiagram-NJNITYFG-Cgr5aSTS.js} +1 -1
  65. package/app/web/assets/{dagre-KIHZ2IZ3-C8B5ZMVs.js → dagre-KIHZ2IZ3-BBFKmRP1.js} +1 -1
  66. package/app/web/assets/{diagram-7YQZDPLS-HIWoNpzV.js → diagram-7YQZDPLS-CJQih32K.js} +1 -1
  67. package/app/web/assets/{diagram-QBROCOUO-3_vS1jbp.js → diagram-QBROCOUO-Cl3S7IUT.js} +1 -1
  68. package/app/web/assets/{diagram-RJJCUUZO-C_Kndn_e.js → diagram-RJJCUUZO-B6C8N2cV.js} +1 -1
  69. package/app/web/assets/{diagram-WERXNKYE-BLWdOwya.js → diagram-WERXNKYE-NkciBSQl.js} +1 -1
  70. package/app/web/assets/{diagram-YHHI257C-DJeOs6eS.js → diagram-YHHI257C-DlEvljeY.js} +1 -1
  71. package/app/web/assets/{diagram-YR4HJLHV-BKNULu-g.js → diagram-YR4HJLHV-e4_Gzbt6.js} +1 -1
  72. package/app/web/assets/{ebnfDiagram-N527522P-Bu8aReoF.js → ebnfDiagram-N527522P-WvQEFmPi.js} +1 -1
  73. package/app/web/assets/{elk-O5DQBFGD-CIp7Z0ER.js → elk-O5DQBFGD-CkyJsjzf.js} +1 -1
  74. package/app/web/assets/{erDiagram-K3K3BIDK-BTsor1Lp.js → erDiagram-K3K3BIDK-B93gK3X0.js} +1 -1
  75. package/app/web/assets/{flowDiagram-Z6JWZHQI-p_h5PKQr.js → flowDiagram-Z6JWZHQI-NFaGX6B4.js} +1 -1
  76. package/app/web/assets/{ganttDiagram-3PRQTZWP-DKjfPPJ1.js → ganttDiagram-3PRQTZWP-Czh68CQm.js} +1 -1
  77. package/app/web/assets/{gitGraphDiagram-VXDFKS5L-RnPOf2fj.js → gitGraphDiagram-VXDFKS5L-t95UHKja.js} +1 -1
  78. package/app/web/assets/{grid-E2QIVN74-C96GnBO1.js → grid-E2QIVN74-C87DucDN.js} +1 -1
  79. package/app/web/assets/index-CGI50Nfg.css +1 -0
  80. package/app/web/assets/index-Dr6wHi0A.js +208 -0
  81. package/app/web/assets/{infoDiagram-EZ3ZOAHP-B68eZHsb.js → infoDiagram-EZ3ZOAHP-CxFlfQbY.js} +1 -1
  82. package/app/web/assets/{ishikawaDiagram-S3EKX5GW-BLj7PFLt.js → ishikawaDiagram-S3EKX5GW-D4IwQJde.js} +1 -1
  83. package/app/web/assets/{journeyDiagram-POQNLL5X-Bo-_In0d.js → journeyDiagram-POQNLL5X-C0Bf5W4T.js} +1 -1
  84. package/app/web/assets/{kanban-definition-BH5XI6FM-BpHvxprW.js → kanban-definition-BH5XI6FM-Cda7r2yr.js} +1 -1
  85. package/app/web/assets/langs/{graphql-D6Z3qcRW.js → graphql-2R4AZ1iu.js} +1 -1
  86. package/app/web/assets/langs/{http-XiU9G9In.js → http-q2Qm0vBh.js} +1 -1
  87. package/app/web/assets/langs/{php-DL3xwS-7.js → php-Cz2gDBnd.js} +1 -1
  88. package/app/web/assets/langs/{rst-DudRVJ9g.js → rst-_9muvx-X.js} +1 -1
  89. package/app/web/assets/langs/{ruby-_FqsfqJi.js → ruby-cn7REk4H.js} +1 -1
  90. package/app/web/assets/langs/{svelte-ClsVJoBT.js → svelte-CPnL2mcy.js} +1 -1
  91. package/app/web/assets/langs/{vue-BiKMXCyK.js → vue-DO0YwyVz.js} +1 -1
  92. package/app/web/assets/{mermaid.core-COb9i2Gl.js → mermaid.core-f4LJm6AC.js} +5 -5
  93. package/app/web/assets/{mindmap-definition-WVAN44T4-DG15AlXd.js → mindmap-definition-WVAN44T4-DKapinG7.js} +1 -1
  94. package/app/web/assets/{pegDiagram-D4NLKWP3-GMBk8RM6.js → pegDiagram-D4NLKWP3-D7iEZGN2.js} +1 -1
  95. package/app/web/assets/{pieDiagram-36ENHN4W-BzeJgVnn.js → pieDiagram-36ENHN4W-CopXZ5qt.js} +1 -1
  96. package/app/web/assets/{quadrantDiagram-ZQUDMS73-C--Kif6a.js → quadrantDiagram-ZQUDMS73-mmkKPDGK.js} +1 -1
  97. package/app/web/assets/{railroadDiagram-JIZHGYPL-NPLVu_R7.js → railroadDiagram-JIZHGYPL-BAGwIIkV.js} +1 -1
  98. package/app/web/assets/{render-VIF2ZAQL-DdpQ8E0J.js → render-VIF2ZAQL-dXxGa09y.js} +2 -2
  99. package/app/web/assets/{requirementDiagram-AXW2TVFA-WWRwRbkA.js → requirementDiagram-AXW2TVFA-C35tmLFs.js} +1 -1
  100. package/app/web/assets/{sankeyDiagram-FBCJTAIF-hBr6pZ0V.js → sankeyDiagram-FBCJTAIF-BbSo5yeK.js} +1 -1
  101. package/app/web/assets/{sequenceDiagram-3LA2ROMG-DvzZWy5J.js → sequenceDiagram-3LA2ROMG-Cgm2unNy.js} +1 -1
  102. package/app/web/assets/{sizeCapture-2Q2CQKSF-C2B86W70.js → sizeCapture-2Q2CQKSF-DCXFjl2x.js} +1 -1
  103. package/app/web/assets/{stateDiagram-v2-ATKHQDJO-Jwj3XqMx.js → stateDiagram-v2-ATKHQDJO-B349iAao.js} +1 -1
  104. package/app/web/assets/{swimlanes-YQL5WMAO-DxI0hC09.js → swimlanes-YQL5WMAO-6OvL1sEz.js} +1 -1
  105. package/app/web/assets/swimlanesDiagram-UCCPES4V-CIKaQUvP.js +8 -0
  106. package/app/web/assets/{timeline-definition-7Z437IG3-m8Ew8iuN.js → timeline-definition-7Z437IG3-Bh1E3mhW.js} +1 -1
  107. package/app/web/assets/{usecaseDiagram-RDK6N6HP-BsiPSzIT.js → usecaseDiagram-RDK6N6HP-Dr5A05lL.js} +1 -1
  108. package/app/web/assets/{vendor-BKfNgqAm.js → vendor-BMCjWFMy.js} +20 -20
  109. package/app/web/assets/{vennDiagram-SHRQU5PJ-yYfXhiGp.js → vennDiagram-SHRQU5PJ-CQPPBa27.js} +1 -1
  110. package/app/web/assets/{wardleyDiagram-F3OXNVQS-DHLEfnsg.js → wardleyDiagram-F3OXNVQS-BHin00q8.js} +1 -1
  111. package/app/web/assets/{xychartDiagram-GDYJKCDI-Drn_UxYt.js → xychartDiagram-GDYJKCDI-D4BAWlQZ.js} +1 -1
  112. package/app/web/codex-agent.png +0 -0
  113. package/app/web/codex.png +0 -0
  114. package/app/web/codexhost-settings.js +337 -137
  115. package/app/web/index.html +3 -3
  116. package/app/web/plugins/deepseek-ai__dsh-api-remotes/client.js +65 -65
  117. package/app/web/plugins/deepseek-ai__dsh-api-session-controller/client.js +69 -69
  118. package/app/web/plugins/deepseek-ai__dsh-client-ui-chat/client.js +75 -75
  119. package/app/web/plugins/deepseek-ai__dsh-client-ui-codexhost/client.js +162 -74
  120. package/app/web/plugins/deepseek-ai__dsh-client-ui-conversation/client.js +104 -100
  121. package/app/web/plugins/deepseek-ai__dsh-client-ui-input-trigger/client.js +1 -1
  122. package/app/web/plugins/deepseek-ai__dsh-client-ui-model-selection/client.js +114 -2
  123. package/app/web/plugins/deepseek-ai__dsh-client-ui-settings-general/client.js +5 -5
  124. package/app/web/plugins/deepseek-ai__dsh-client-ui-sidebar-documentpreview/client.js +6 -6
  125. package/app/web/plugins/deepseek-ai__dsh-client-ui-tool/client.js +80 -80
  126. package/app/web/plugins/deepseek-ai__dsh-client-ui-user-questions/client.js +1 -1
  127. package/app/web/plugins/deepseek-ai__dsh-client-ui-workspace/client.js +69 -69
  128. package/app/web/role-avatars/builtin/advisor-otter.webp +0 -0
  129. package/app/web/role-avatars/builtin/architect-otter.webp +0 -0
  130. package/app/web/role-avatars/builtin/audio-otter.webp +0 -0
  131. package/app/web/role-avatars/builtin/backend-otter.webp +0 -0
  132. package/app/web/role-avatars/builtin/builder-otter.webp +0 -0
  133. package/app/web/role-avatars/builtin/classic-otter.webp +0 -0
  134. package/app/web/role-avatars/builtin/data-otter.webp +0 -0
  135. package/app/web/role-avatars/builtin/debugger-otter.webp +0 -0
  136. package/app/web/role-avatars/builtin/frontend-otter.webp +0 -0
  137. package/app/web/role-avatars/builtin/idea-otter.webp +0 -0
  138. package/app/web/role-avatars/builtin/ops-otter.webp +0 -0
  139. package/app/web/role-avatars/builtin/pm-otter.webp +0 -0
  140. package/app/web/role-avatars/builtin/researcher-otter.webp +0 -0
  141. package/app/web/role-avatars/builtin/reviewer-otter.webp +0 -0
  142. package/app/web/role-avatars/builtin/sailor-otter.webp +0 -0
  143. package/app/web/role-avatars/builtin/scholar-otter.webp +0 -0
  144. package/app/web/role-avatars/builtin/security-otter.webp +0 -0
  145. package/app/web/role-avatars/builtin/tester-otter.webp +0 -0
  146. package/app/web/role-avatars/builtin/wizard-otter.webp +0 -0
  147. package/app/web/role-avatars/builtin/writer-otter.webp +0 -0
  148. package/app/web-modules/node_modules/@deepseek-ai/dsh-host-webserver/index.js +7 -1
  149. package/app/web-modules/server.mjs +6951 -2390
  150. package/bin/codexhost.exe +0 -0
  151. package/libexec/codexhost-node-repl.exe +0 -0
  152. package/libexec/codexhost-screenshot.exe +0 -0
  153. package/libexec/codexhost-shell.exe +0 -0
  154. package/libexec/codexhost-shim.exe +0 -0
  155. package/libexec/codexhost-updater.exe +0 -0
  156. package/package.json +1 -1
  157. package/app/web/assets/index-CDRWzs-u.js +0 -205
  158. package/app/web/assets/index-Dwdnvinl.css +0 -1
  159. package/app/web/assets/swimlanesDiagram-UCCPES4V-CR0nv8kJ.js +0 -8
@@ -1 +1 @@
1
- import{n as Nr,a as Fr}from"./chunk-3GCGMST5-D7bw3E1a.js";import{c as Dr}from"./chunk-EBZ3SEQC-BgJPPYdu.js";import{ak as kr,ay as Io,az as Mo,l as te,_ as u,aA as fo}from"./mermaid.core-COb9i2Gl.js";import"./index-CDRWzs-u.js";import"./vendor-BKfNgqAm.js";import"./graph-D8UmR1vK.js";var nt=1;function Co(t,e,o=nt){const n=Math.abs(e.x-t.x),i=Math.abs(e.y-t.y);return n<=o&&i<=o?"Z":i<=o?"H":"V"}u(Co,"segmentOrientation");function So(t,e=nt){const o=[];for(let n=0;n<t.length-1;n++){const i=t[n],r=t[n+1];o.push({a:i,b:r,orientation:Co(i,r,e)})}return o}u(So,"segmentsFromPoints");function Eo(t,e=nt){if(t.length===0)return[];const o=[];let n={...t[0]};for(let i=1;i<t.length;i++){const r=t[i];if(r.orientation!=="Z"){if(n.orientation==="Z"){n={...r};continue}if(n.orientation===r.orientation){if(n.orientation==="H"&&Math.abs(n.b.y-r.a.y)<=e&&Math.abs(n.a.y-r.a.y)<=e){n.b=r.b;continue}if(n.orientation==="V"&&Math.abs(n.b.x-r.a.x)<=e&&Math.abs(n.a.x-r.a.x)<=e){n.b=r.b;continue}}n.orientation!=="Z"&&o.push(n),n={...r}}}return n.orientation!=="Z"&&o.push(n),o}u(Eo,"mergeCollinear");function z(t,e=nt){if(t.length<2)return{points:[...t],segments:[],bends:0};const o=So(t,e).filter(s=>s.orientation!=="Z"),n=Eo(o,e),i=[];for(const[s,a]of n.entries())s===0&&i.push(a.a),i.push(a.b);let r=0;for(let s=1;s<n.length;s++)n[s-1].orientation!==n[s].orientation&&r++;return{points:i.length>0?i:[...t],segments:n,bends:r}}u(z,"normalizePolyline");function Bn(t,e){if(t.orientation==="Z"||e.orientation==="Z"||t.orientation===e.orientation)return!1;const o=t.orientation==="H"?t:e,n=t.orientation==="V"?t:e,i=o.a.y,r=Math.min(o.a.x,o.b.x),s=Math.max(o.a.x,o.b.x),a=n.a.x,c=Math.min(n.a.y,n.b.y),d=Math.max(n.a.y,n.b.y);if(a>=r&&a<=s&&i>=c&&i<=d){const h=a,f=i,m=Math.abs(h-o.a.x)<1e-6&&Math.abs(f-o.a.y)<1e-6||Math.abs(h-o.b.x)<1e-6&&Math.abs(f-o.b.y)<1e-6,p=Math.abs(h-n.a.x)<1e-6&&Math.abs(f-n.a.y)<1e-6||Math.abs(h-n.b.x)<1e-6&&Math.abs(f-n.b.y)<1e-6;return!(m&&p)}return!1}u(Bn,"segmentsCross");function U(t,e){return t<e?-1:t>e?1:0}u(U,"compareCodeUnits");function k(t){const e=t.x??0,o=t.y??0,n=t.width??40,i=t.height??40;return{cx:e,cy:o,left:e-n/2,right:e+n/2,top:o-i/2,bottom:o+i/2}}u(k,"rectForNode");function Ro(t,e,o,n,i=0){if(t.length<2)return null;const r=e==="end"?t[t.length-1]:t[0],s=e==="end"?t[t.length-2]:t[1],a=s.x-r.x,c=s.y-r.y;if(Math.abs(a)<=i&&Math.abs(c)<=i)return null;if(Math.abs(c)<=i){const d=r.x+Math.sign(a)*o,l=Math.min(r.x,d),h=Math.max(r.x,d);return{cx:(l+h)/2,cy:r.y,left:l,right:h,top:r.y-n,bottom:r.y+n}}if(Math.abs(a)<=i){const d=r.y+Math.sign(c)*o,l=Math.min(r.y,d),h=Math.max(r.y,d);return{cx:r.x,cy:(l+h)/2,left:r.x-n,right:r.x+n,top:l,bottom:h}}return null}u(Ro,"terminalMarkerClearanceRect");function Ao(t,e){const o=e==="start"?t.arrowTypeStart:t.arrowTypeEnd;if(typeof o=="string"){const n=o.trim();if(n.length>0)return n!=="none"&&n!=="arrow_open"}return typeof t.type!="string"?!1:e==="start"&&t.type.startsWith("double_")?!0:e==="end"&&/arrow_(point|cross|circle|barb)|double_arrow/.test(t.type)}u(Ao,"hasTerminalMarker");function Vt(t,e,o=1e-6){return Math.abs(t-e)<=o}u(Vt,"approxEqual");function Oo(t,e,o=1e-6){for(let n=1;n<t.length;n++){const i=t[n-1],r=t[n];if(Vt(i.y,r.y,o)&&!Vt(i.x,r.x,o)){if(Vt(e.y,i.y,o)&&e.x>=Math.min(i.x,r.x)-o&&e.x<=Math.max(i.x,r.x)+o)return!0}else if(Vt(i.x,r.x,o)&&!Vt(i.y,r.y,o)&&Vt(e.x,i.x,o)&&e.y>=Math.min(i.y,r.y)-o&&e.y<=Math.max(i.y,r.y)+o)return!0}return!1}u(Oo,"orthogonalPolylineContainsPoint");function ee(t){let e=0;for(let o=1;o<t.length;o++){const n=t[o-1],i=t[o];e+=Math.abs(i.x-n.x)+Math.abs(i.y-n.y)}return e}u(ee,"manhattanLength");function Ft(t,e,o){if(t.x===e.x&&t.y===e.y)return!1;if(t.y===e.y){const n=t.y,i=Math.min(t.x,e.x),r=Math.max(t.x,e.x),s=n>=o.top&&n<=o.bottom,a=Math.max(i,o.left)<Math.min(r,o.right);return s&&a}if(t.x===e.x){const n=t.x,i=Math.min(t.y,e.y),r=Math.max(t.y,e.y),s=n>=o.left&&n<=o.right,a=Math.max(i,o.top)<Math.min(r,o.bottom);return s&&a}return!1}u(Ft,"segmentIntersectsRectInterior");function bt(t,e){for(let o=1;o<t.length;o++)if(Ft(t[o-1],t[o],e))return!0;return!1}u(bt,"polylineIntersectsRect");function Bt(t,e,o){return Math.max(e,Math.min(o,t))}u(Bt,"clamp");var j="__grid_root__",zr="edge-label-";function H(t,e,o){const n=new Error(`${t}: ${e}`);return n.code=t,n.details=o,n}u(H,"gridError");var xt={columns:0,rowGap:50,columnGap:50,cellGap:20,containerPadding:20,titleGap:8,horizontalAlign:"center",verticalAlign:"center",curve:"rounded"};function pt(t){return!!t.isEdgeLabel}u(pt,"isEdgeLabelNode");function Z(t){return typeof t=="number"&&Number.isFinite(t)&&t>0}u(Z,"isFinitePositiveNumber");var $t=6,Ze=12,Bo=2;function Ln(t,e){if(!Z(t.width)||!Z(t.height))return null;const o=e==="H"?t.width:t.height,n=e==="H"?t.height:t.width,i=Math.max($t,Ze),r=Math.max($t,Ze);return{along:o,cross:n,startInset:i,endInset:r,requiredAlongSpan:o+i+r+Bo}}u(Ln,"gridLabelSpanRequirement");function Lo(t,e){const o=e==="H"?t.width:t.height;return Z(o)?o+$t*2:0}u(Lo,"gridLabelRequiredSegmentLength");var ut=$t,it=14,Hr=18,Vr=16,Po=128,$r=64,go=2e6,Pn=Ze,tt=1e-6,Kr=7,jr=8,dt=u(t=>z(t,tt),"normalizePolyline");function Je(t,e,o,n){const i=Math.max(Math.min(t,e),Math.min(o,n)),r=Math.min(Math.max(t,e),Math.max(o,n));return Math.max(0,r-i)}u(Je,"rangeOverlapLength");function _n(t){const e=dt([...t]).segments;for(let o=0;o<e.length;o++){const n=e[o];for(let i=o+2;i<e.length;i++){const r=e[i];if(Bn(n,r))return!0;if(n.orientation!==r.orientation||n.orientation==="Z")continue;const s=n.orientation==="H"?Math.abs(n.a.y-r.a.y)<=tt:Math.abs(n.a.x-r.a.x)<=tt,a=n.orientation==="H"?Je(n.a.x,n.b.x,r.a.x,r.b.x):Je(n.a.y,n.b.y,r.a.y,r.b.y);if(s&&a>tt)return!0;const c=n.orientation==="H"?Math.abs(n.a.y-r.a.y):Math.abs(n.a.x-r.a.x);if(!s&&c<Kr&&a>=jr)return!0}}return!1}u(_n,"polylineHasSelfConflict");var po=class extends Error{constructor(t){super(`Could not place label for edge "${t.edgeId}"`),this.details=t,this.name="LabelPlacementSearchExhaustedError"}static{u(this,"LabelPlacementSearchExhaustedError")}},_o=class extends Error{static{u(this,"LabelIndexWorkLimitError")}constructor(){super("Grid label index work cap exceeded"),this.name="LabelIndexWorkLimitError"}},Ur=class{constructor(t,e){this.limit=t,this.metrics=e,this.used=0}static{u(this,"LabelIndexWorkBudget")}charge(t){if(!(t<=0)){if(this.used+t>this.limit)throw new _o;this.used+=t,K(this.metrics,"indexWorkUnits",t)}}},Ee=class{constructor(t,e){this.workBudget=t,this.metrics=e,this.entriesById=new Map,this.sortedByLeft=[],this.dirty=!1}static{u(this,"CompressedBoundsIndex")}upsert(t){const e=!this.entriesById.has(t.id);this.entriesById.set(t.id,t),this.dirty=!0,e&&this.metrics&&(this.metrics.indexCoordinateCount+=4)}remove(t){this.entriesById.delete(t)&&(this.dirty=!0)}query(t){if(this.dirty){const o=this.entriesById.size;this.workBudget.charge(o*Math.max(1,Math.ceil(Math.log2(o+1)))),this.sortedByLeft=[...this.entriesById.values()].sort((n,i)=>n.bounds.left-i.bounds.left||U(n.id,i.id)),this.dirty=!1}const e=[];for(const o of this.sortedByLeft){if(this.workBudget.charge(1),o.bounds.left>t.right)break;Gn(o.bounds,t)&&e.push(o)}return e}};function tn(t,e){return t.left<e.right&&t.right>e.left&&t.top<e.bottom&&t.bottom>e.top}u(tn,"rectOverlap");function se(t,e){const o=t.width??0,n=t.height??0;return{cx:e.x,cy:e.y,left:e.x-o/2,right:e.x+o/2,top:e.y-n/2,bottom:e.y+n/2}}u(se,"labelRectAt");function Go(t){const e=t.groupTitleRect;return e?{cx:(e.left+e.right)/2,cy:(e.top+e.bottom)/2,left:e.left,right:e.right,top:e.top,bottom:e.bottom}:null}u(Go,"groupTitleRect");function K(t,e,o=1){t&&(t[e]+=o)}u(K,"incrementMetric");function pe(t){return{...t}}u(pe,"clonePoint");function Tt(t){return{left:t.left,right:t.right,top:t.top,bottom:t.bottom}}u(Tt,"boundsForRect");function Fe(t){return{left:Math.min(t.a.x,t.b.x),right:Math.max(t.a.x,t.b.x),top:Math.min(t.a.y,t.b.y),bottom:Math.max(t.a.y,t.b.y)}}u(Fe,"boundsForSegment");function To(t){if(t.length===0)return null;let e=t[0].x,o=t[0].x,n=t[0].y,i=t[0].y;for(const r of t.slice(1))e=Math.min(e,r.x),o=Math.max(o,r.x),n=Math.min(n,r.y),i=Math.max(i,r.y);return{left:e,right:o,top:n,bottom:i}}u(To,"boundsForPoints");function No(t,e){return{left:Math.min(t.left,e.left),right:Math.max(t.right,e.right),top:Math.min(t.top,e.top),bottom:Math.max(t.bottom,e.bottom)}}u(No,"mergeBounds");function Fo(t,e){return{left:t.left-e,right:t.right+e,top:t.top-e,bottom:t.bottom+e}}u(Fo,"expandBounds");function Gn(t,e){return t.left<=e.right&&t.right>=e.left&&t.top<=e.bottom&&t.bottom>=e.top}u(Gn,"boundsOverlap");function Tn(t){return(t.length<=2?t.map((o,n)=>n):[...t.slice(1,-1).map((o,n)=>n+1),0,t.length-1]).map((o,n)=>({segment:t[o],segmentIndex:o,order:n}))}u(Tn,"candidateSegmentsFromSegments");function Nn(t,e){return["start","end"].filter(n=>Ao(t,n)).map(n=>Ro(e,n,Pn,7,tt)).filter(n=>n!==null)}u(Nn,"markerClearanceRectsFromPoints");function De(t,e){const o=dt(e);return{points:o.points,segments:o.segments,candidateSegments:Tn(o.segments),markerRects:Nn(t,o.points)}}u(De,"buildEdgeGeometry");function Kt(t){return t.orientation==="H"?Math.abs(t.b.x-t.a.x):Math.abs(t.b.y-t.a.y)}u(Kt,"segmentLength");function Do(t,e){const o=[{x:e.left,y:e.top},{x:e.right,y:e.top},{x:e.right,y:e.bottom},{x:e.left,y:e.bottom}];for(let n=0;n<o.length;n++)if(Ft(o[n],o[(n+1)%o.length],t))return!0;return!1}u(Do,"borderCutsRect");function Fn(t){return Number.isFinite(t.x)&&Number.isFinite(t.y)}u(Fn,"hasFinitePosition");function St(t,e,o){const n=e?.get(t.id);if(n)return dt(n).points;const i=o?.edgeGeometryById.get(t.id);return i?i.points:dt(t.points??[]).points}u(St,"pointsForEdge");function ke(t,e,o){if(!e?.has(t.id)){const n=o?.edgeGeometryById.get(t.id);if(n)return n.markerRects}return Nn(t,St(t,e,o))}u(ke,"markerClearanceRectsForEdge");function ge(t,e,o,n){return Math.max(Math.min(t,e),Math.min(o,n))<Math.min(Math.max(t,e),Math.max(o,n))-tt}u(ge,"rangeOverlaps");function ko(t,e,o){const n=Bt(Math.min(t.start,t.end),e,o),i=Bt(Math.max(t.start,t.end),e,o);return i-n>tt?{start:n,end:i}:null}u(ko,"clampInterval");function zo(t,e,o){const n=t.map(r=>ko(r,e,o)).filter(r=>r!==null).sort((r,s)=>r.start-s.start||r.end-s.end);if(n.length===0)return[];const i=[n[0]];for(let r=1;r<n.length;r++){const s=n[r],a=i[i.length-1];s.start<=a.end+tt?a.end=Math.max(a.end,s.end):i.push(s)}return i}u(zo,"mergeBlockedLabelIntervals");function ze(t,e,o,n){if(e-t<=tt)return[];const i=[];let r=t;for(const d of zo(o,t,e))d.start-r>tt&&i.push({start:r,end:d.start}),r=Math.max(r,d.end);e-r>tt&&i.push({start:r,end:e});const s=i.map(d=>({value:Bt(n,d.start,d.end),start:d.start,end:d.end}));s.sort((d,l)=>{const h=Math.abs(d.value-n)-Math.abs(l.value-n);if(Math.abs(h)>tt)return h;const f=l.end-l.start-(d.end-d.start);return Math.abs(f)>tt?f:d.value-l.value});const a=new Set,c=[];for(const d of s){const l=Math.round(d.value*1e6)/1e6;a.has(l)||(a.add(l),c.push(d.value))}return c}u(ze,"centerCandidatesFromIntervals");function Ho(t){return t.isGroup||pt(t)&&!Fn(t)?null:k(t)}u(Ho,"obstacleRectForNode");function Vo(t,e){const o=e?.edgeGeometryById.get(t.id);return o?o.candidateSegments:Tn(dt(t.points??[]).segments)}u(Vo,"candidateSegments");function Dn(t,e,o){const n=t.edgeGeometryById.get(e);n&&n.segments.forEach((i,r)=>t.segmentIndex.remove(`${e}:${r}`)),t.edgeGeometryById.set(e,o),o.segments.forEach((i,r)=>{t.segmentIndex.upsert({id:`${e}:${r}`,edgeId:e,segment:i,bounds:Fe(i)})})}u(Dn,"storeEdgeGeometry");function Nt(t,e,o){const n=De(e,o);e.points=n.points.map(pe),Dn(t,e.id,n)}u(Nt,"setEdgePoints");function $o(t,e){t.placedLabelIndex.upsert({id:`label:${e.nodeId}`,nodeId:e.nodeId,rect:e.rect,bounds:Tt(e.rect)})}u($o,"upsertPlacedLabelObstacle");function Ko(t,e,o){const n={edgeById:new Map,edgeGeometryById:new Map,obstacleIndex:new Ee(e,o),placedLabelIndex:new Ee(e,o),groupBorderIndex:new Ee(e,o),segmentIndex:new Ee(e,o),searchBounds:{left:0,right:0,top:0,bottom:0},metrics:o};let i=null;const r=u(s=>{i=i?No(i,s):{...s}},"rememberBounds");for(const s of t.nodes){if(s.isGroup){const d=k(s),l=Tt(d);n.groupBorderIndex.upsert({id:`border:${s.id}`,rect:d,bounds:l}),r(l);const h=Go(s);if(h){const f=Tt(h);n.obstacleIndex.upsert({id:`title:${s.id}`,rect:h,bounds:f}),r(f)}continue}const a=Ho(s);if(!a)continue;const c={id:`${pt(s)?"label":"node"}:${s.id}`,rect:a,bounds:Tt(a),nodeId:s.id};pt(s)?n.placedLabelIndex.upsert(c):n.obstacleIndex.upsert(c),r(c.bounds)}for(const s of t.edges){n.edgeById.set(s.id,s);const a=De(s,s.points??[]);Dn(n,s.id,a);const c=To(a.points);c&&r(c)}return n.searchBounds=Fo(i??{left:0,right:0,top:0,bottom:0},128),n}u(Ko,"createEdgeLabelContext");function Xt(t,e,o,n={}){K(t.metrics,o);const i=[],r=u(s=>{for(const a of s)a.nodeId&&(a.nodeId===n.excludeNodeId||n.skipNodeIds?.has(a.nodeId))||i.push(a)},"appendEntries");return r(t.obstacleIndex.query(e)),r(t.placedLabelIndex.query(e)),K(t.metrics,"obstacleCandidatesVisited",i.length),i}u(Xt,"queryObstacleEntries");function He(t,e,o,n,i){K(t.metrics,i);const r=n?new Set(n.keys()):void 0,s=[],a=t.segmentIndex.query(e);for(const d of a)d.edgeId===o||r?.has(d.edgeId)||s.push(d);let c=a.length;if(n)for(const[d,l]of n){if(d===o)continue;const h=t.edgeById.get(d);if(!h)continue;De(h,l).segments.forEach((m,p)=>{const x=Fe(m);Gn(x,e)&&(c+=1,s.push({id:`override:${d}:${p}`,edgeId:d,segment:m,bounds:x}))})}return K(t.metrics,"segmentCandidatesVisited",c),s}u(He,"queryForeignSegments");function Ve(t,e,o,n){K(t.metrics,"foreignEdgeLookups");const i=new Set;for(const r of He(t,Tt(e),o,n,"segmentRectQueries"))Ft(r.segment.a,r.segment.b,e)&&i.add(r.edgeId);return[...i].sort(U)}u(Ve,"foreignEdgeIdsIntersectingRect");function kn(t,e){return!Z(e.width)||!Z(e.height)?null:t.orientation==="H"?{left:Math.min(t.a.x,t.b.x)-e.width/2,right:Math.max(t.a.x,t.b.x)+e.width/2,top:t.a.y-e.height/2,bottom:t.a.y+e.height/2}:{left:t.a.x-e.width/2,right:t.a.x+e.width/2,top:Math.min(t.a.y,t.b.y)-e.height/2,bottom:Math.max(t.a.y,t.b.y)+e.height/2}}u(kn,"obstacleBandQueryBounds");function jo(t,e,o){if(t.orientation==="H"){const i=(e.width??0)+ut*2+it;return{left:Math.min(t.a.x,t.b.x)-i,right:Math.max(t.a.x,t.b.x)+i,top:o.top,bottom:o.bottom}}const n=(e.height??0)+ut*2+it;return{left:o.left,right:o.right,top:Math.min(t.a.y,t.b.y)-n,bottom:Math.max(t.a.y,t.b.y)+n}}u(jo,"detourLineQueryBounds");function Uo(t,e){return t.orientation==="H"?{left:Math.min(t.a.x,t.b.x)-ut,right:Math.max(t.a.x,t.b.x)+ut,top:e.top,bottom:e.bottom}:{left:e.left,right:e.right,top:Math.min(t.a.y,t.b.y)-ut,bottom:Math.max(t.a.y,t.b.y)+ut}}u(Uo,"rerouteLineQueryBounds");function ae(t,e,o,n,i,r){for(const s of Xt(n,Tt(t),"obstacleRectQueries",{excludeNodeId:o}))if(tn(t,s.rect))return!1;for(const s of n.groupBorderIndex.query(Tt(t)))if(Do(t,s.rect))return!1;for(const s of ke(e,i,n))if(tn(t,s))return!1;for(const s of He(n,Tt(t),e.id,i,"segmentRectQueries"))if(!r?.has(s.edgeId)&&Ft(s.segment.a,s.segment.b,t))return!1;return!0}u(ae,"rectSafeForLabel");function Xo(t,e){return e.orientation==="Z"?0:Lo(t,e.orientation)}u(Xo,"requiredSegmentLength");function $e(t,e,o,n,i,r){if(!Z(e.width)||!Z(e.height))return null;const s=e.width,a=e.height,c=o.orientation==="H"?s/2+ut:a/2+ut,d=o.orientation==="H"?Math.min(o.a.x,o.b.x)+c:Math.min(o.a.y,o.b.y)+c,l=o.orientation==="H"?Math.max(o.a.x,o.b.x)-c:Math.max(o.a.y,o.b.y)-c;if(l-d<=tt)return null;const h=[],f=kn(o,e);if(!f)return null;const m=u(p=>{if(o.orientation==="H"){const y=o.a.y-a/2,b=o.a.y+a/2;ge(y,b,p.top,p.bottom)&&h.push({start:p.left-s/2,end:p.right+s/2});return}const x=o.a.x-s/2,g=o.a.x+s/2;ge(x,g,p.left,p.right)&&h.push({start:p.top-a/2,end:p.bottom+a/2})},"addRect");for(const p of Xt(n,f,"obstacleBandQueries",{excludeNodeId:e.id}))m(p.rect);for(const p of ke(t,i,n))m(p);if(r)for(const p of He(n,f,t.id,i,"segmentBandQueries")){const x=p.segment;if(o.orientation==="H"){const b=o.a.y-e.height/2,I=o.a.y+e.height/2;x.orientation==="H"?b<x.a.y&&I>x.a.y&&h.push({start:Math.min(x.a.x,x.b.x)-e.width/2,end:Math.max(x.a.x,x.b.x)+e.width/2}):ge(b,I,Math.min(x.a.y,x.b.y),Math.max(x.a.y,x.b.y))&&h.push({start:x.a.x-e.width/2,end:x.a.x+e.width/2});continue}const g=o.a.x-e.width/2,y=o.a.x+e.width/2;x.orientation==="V"?g<x.a.x&&y>x.a.x&&h.push({start:Math.min(x.a.y,x.b.y)-e.height/2,end:Math.max(x.a.y,x.b.y)+e.height/2}):ge(g,y,Math.min(x.a.x,x.b.x),Math.max(x.a.x,x.b.x))&&h.push({start:x.a.y-e.height/2,end:x.a.y+e.height/2})}return{low:d,high:l,blocked:h}}u($e,"blockedCenterIntervals");function Wo(t,e,o,n){if(Kt(o)<Xo(e,o))return null;const i=$e(t,e,o,n,void 0,!0);if(!i)return null;const r=o.orientation==="H"?(Math.min(o.a.x,o.b.x)+Math.max(o.a.x,o.b.x))/2:(Math.min(o.a.y,o.b.y)+Math.max(o.a.y,o.b.y))/2,s=ze(i.low,i.high,i.blocked,r);for(const a of s){const c=o.orientation==="H"?{x:a,y:o.a.y}:{x:o.a.x,y:a},d=se(e,c);if(ae(d,t,e.id,n))return c}return null}u(Wo,"placementOnExistingSegment");function Yo(t,e,o,n,i){const r=$e(t,e,o,n,void 0,!1);if(!r)return null;const s=o.orientation==="H"?(Math.min(o.a.x,o.b.x)+Math.max(o.a.x,o.b.x))/2:(Math.min(o.a.y,o.b.y)+Math.max(o.a.y,o.b.y))/2,a=ze(r.low,r.high,r.blocked,s);for(const c of a){const d=o.orientation==="H"?{x:c,y:o.a.y}:{x:o.a.x,y:c},l=se(e,d),h=new Map,f=Ve(n,l,t.id).map(p=>n.edgeById.get(p)).filter(p=>p!==void 0);let m=!0;for(const p of f){const x=ce(p,l,n,i,h);if(!x){m=!1;break}h.set(p.id,x)}if(m&&ae(l,t,e.id,n,h)){for(const[p,x]of h){const g=n.edgeById.get(p);g&&Nt(n,g,x)}return d}}return null}u(Yo,"placementOnExistingSegmentWithReroutes");function ye(t,e,o){for(const n of dt(t).segments)for(const i of Xt(e,Fe(n),"obstaclePolylineQueries",{skipNodeIds:o}))if(Ft(n.a,n.b,i.rect))return!0;return!1}u(ye,"polylineHitsProtectedObstacles");function Yt(t,e,o){const n=o.get(t);return!n||Oo(e,n.center,tt)}u(Yt,"labelStillAnchored");function zn(t){const e=[];for(let o=0;o<Vr;o++){const n=t+it+o*Hr;e.push(-n,n)}return e}u(zn,"detourOffsets");function Ce(t,e){const o=new Map;for(const n of t){const i=Math.round(n*1e6)/1e6;o.has(i)||o.set(i,n)}return[...o.values()].sort((n,i)=>{const r=Math.abs(n-e)-Math.abs(i-e);return Math.abs(r)>tt?r:n-i})}u(Ce,"uniqueSortedCandidates");function Hn(t,e,o,n){if(!Z(e.width)||!Z(e.height))return[];const i=e.width,r=e.height,s=o.orientation==="H"?o.a.y:o.a.x,a=o.orientation==="H"?r/2:i/2,c=zn(a).map(l=>s+l),d=u(l=>{if(o.orientation==="H"){c.push(l.top-a-it),c.push(l.bottom+a+it);return}c.push(l.left-a-it),c.push(l.right+a+it)},"addRect");for(const l of Xt(n,jo(o,e,n.searchBounds),"obstacleBandQueries",{excludeNodeId:e.id}))d(l.rect);for(const l of ke(t,void 0,n))d(l);return Ce(c,s).slice(0,Po)}u(Hn,"detourLineCandidates");function en(t,e,o,n,i){const r=t.orientation==="H"?t.a.y:t.a.x,s=[];for(const l of zn(0))t.orientation==="H"?s.push(l<0?e.top+l:e.bottom+l):s.push(l<0?e.left+l:e.right+l);const a=u(l=>{if(t.orientation==="H"){s.push(l.top-it),s.push(l.bottom+it);return}s.push(l.left-it),s.push(l.right+it)},"addRect");for(const l of Xt(o,Uo(t,o.searchBounds),"obstacleBandQueries",{skipNodeIds:n}))a(l.rect);const c=Ce(s,r);return(i?.orientation===t.orientation?c.filter(l=>i.side==="top"?l<e.top:i.side==="bottom"?l>e.bottom:i.side==="left"?l<e.left:l>e.right):c).slice(0,Po)}u(en,"rerouteLineCandidates");function qo(t,e,o,n,i){if(!Z(e.width)||!Z(e.height))return[];const r=e.width,s=e.height,a=o.orientation==="H"?{orientation:"H",a:{x:o.a.x,y:n},b:{x:o.b.x,y:n}}:{orientation:"V",a:{x:n,y:o.a.y},b:{x:n,y:o.b.y}},c=$e(t,e,a,i,void 0,!1);if(!c){const l=o.orientation==="H"?(Math.min(o.a.x,o.b.x)+Math.max(o.a.x,o.b.x))/2:(Math.min(o.a.y,o.b.y)+Math.max(o.a.y,o.b.y))/2,h=[l],f=kn(a,e),m=u(p=>{if(o.orientation==="H"){h.push(p.left-it-r/2),h.push(p.right+it+r/2);return}h.push(p.top-it-s/2),h.push(p.bottom+it+s/2)},"addRect");if(f)for(const p of Xt(i,f,"obstacleBandQueries",{excludeNodeId:e.id}))m(p.rect);return Ce(h,l).slice(0,$r)}const d=o.orientation==="H"?(Math.min(o.a.x,o.b.x)+Math.max(o.a.x,o.b.x))/2:(Math.min(o.a.y,o.b.y)+Math.max(o.a.y,o.b.y))/2;return ze(c.low,c.high,c.blocked,d)}u(qo,"detourCenterCandidates");function Vn(t,e,o){const n=e>=t?1:-1;return e+n*(o+ut)}u(Vn,"detourReturnCoordinate");var Xr={along:u(t=>t.x,"along"),cross:u(t=>t.y,"cross"),point:u((t,e)=>({x:t,y:e}),"point"),labelAlongSize:u(t=>t.width??0,"labelAlongSize"),labelCrossSize:u(t=>t.height??0,"labelCrossSize")},Wr={along:u(t=>t.y,"along"),cross:u(t=>t.x,"cross"),point:u((t,e)=>({x:e,y:t}),"point"),labelAlongSize:u(t=>t.height??0,"labelAlongSize"),labelCrossSize:u(t=>t.width??0,"labelCrossSize")};function $n(t){return t.orientation==="H"?Xr:Wr}u($n,"detourAxis");function Qo(t,e,o,n,i,r){if(!Z(n.width)||!Z(n.height))return null;const s=t[e],a=t[e+1],c=$n(o),d=c.cross(o.a),l=c.along(s),h=c.along(a),f=c.labelAlongSize(n)+ut*2,m=i-f/2,p=i+f/2,x=m<Math.min(l,h)-tt,g=p>Math.max(l,h)+tt,y=h>=l?1:-1,b=Math.max(0,Math.min(Pn,Math.abs(h-l)/2-tt)),I=l+y*b,C=h-y*b;if(!x&&!g)return dt([...t.slice(0,e),s,c.point(m,d),c.point(m,r),c.point(p,r),c.point(p,d),a,...t.slice(e+2)]).points;const S=Vn(d,r,c.labelCrossSize(n)/2),v=[...t.slice(0,e),s];return x?v.push(c.point(I,d),c.point(I,S),c.point(m,S),c.point(m,r)):v.push(c.point(m,d),c.point(m,r)),v.push(c.point(p,r)),g?v.push(c.point(p,S),c.point(C,S),c.point(C,d)):v.push(c.point(p,d)),v.push(a,...t.slice(e+2)),dt(v).points}u(Qo,"buildLabelDetourPoints");function Zo(t,e,o,n,i,r,s){if(!Z(n.width)||!Z(n.height))return null;const a=t[e],c=t[e+1],d=s?4:2,l=$n(o),h=l.cross(o.a),f=l.along(a),m=l.along(c),p=l.labelAlongSize(n)+ut*2,x=i-p/2,g=i+p/2,y=m>=f?1:-1,b=Math.max(0,Math.min(Pn,Math.abs(m-f)/d-tt)),I=f+y*b,C=m-y*b,S=Vn(h,r,l.labelCrossSize(n)/2);return dt([...t.slice(0,e),a,l.point(I,h),l.point(I,r),l.point(x,r),l.point(g,r),l.point(g,S),l.point(C,S),l.point(C,h),c,...t.slice(e+2)]).points}u(Zo,"buildExtendedLabelDetourPoints");function Jo(t,e){if(!Z(e.width)||!Z(e.height))return[];if(t.orientation==="H"){const i=Math.min(t.a.x,t.b.x),r=Math.max(t.a.x,t.b.x);return[i-e.width/2-it,r+e.width/2+it]}const o=Math.min(t.a.y,t.b.y),n=Math.max(t.a.y,t.b.y);return[o-e.height/2-it,n+e.height/2+it]}u(Jo,"externalDetourCenterCandidates");function Kn(t,e){let o=0,n=0;for(const i of dt([...t]).segments)Ft(i.a,i.b,e)&&(o++,i.orientation==="H"?n+=Math.max(0,Math.min(Math.max(i.a.x,i.b.x),e.right)-Math.max(Math.min(i.a.x,i.b.x),e.left)):i.orientation==="V"&&(n+=Math.max(0,Math.min(Math.max(i.a.y,i.b.y),e.bottom)-Math.max(Math.min(i.a.y,i.b.y),e.top))));return{count:o,length:n}}u(Kn,"blockedIntersectionScore");function nn(t,e,o){const n=Kn(t,e);return n.count<o.count||n.count===o.count&&n.length<o.length-tt}u(nn,"reducesBlockedIntersections");function ti(t,e,o){const n=dt([...t]).segments.find(s=>Ft(s.a,s.b,e));if(!n||n.orientation==="Z")return null;const i=n.orientation==="H"?Math.abs(n.a.y-e.top)<=Math.abs(e.bottom-n.a.y)?"top":"bottom":Math.abs(n.a.x-e.left)<=Math.abs(e.right-n.a.x)?"left":"right",r=o.map(s=>s.edgeId).sort(U);return{key:JSON.stringify([r,n.orientation,i]),orientation:n.orientation,side:i}}u(ti,"rerouteLane");function ei(t,e,o,n,i,r,s){const a=dt(e),c=Kn(a.points,n),d=a.segments[o];if(!d||d.orientation==="Z")return null;const l=a.points[o],h=a.points[o+1],f=r.get(t.id)?.nodeId,m=new Set;if(f&&m.add(f),d.orientation==="H"){const b=Math.min(l.x,h.x),I=Math.max(l.x,h.x),C=Math.max(b,n.left-ut),S=Math.min(I,n.right+ut);if(S-C<=tt)return K(i.metrics,"rerouteRejectedDegenerateSpan"),null;for(const v of en(d,n,i,m,s)){K(i.metrics,"rerouteCandidatesEvaluated");const w=dt([...a.points.slice(0,o),l,{x:C,y:d.a.y},{x:C,y:v},{x:S,y:v},{x:S,y:d.a.y},h,...a.points.slice(o+2)]).points;if(bt(w,n)&&!nn(w,n,c)){K(i.metrics,"rerouteRejectedBlockedRect");continue}if(bt(w,n)&&K(i.metrics,"reroutePartialProgressCandidates"),ye(w,i,m)){K(i.metrics,"rerouteRejectedProtectedObstacle");continue}if(!Yt(t.id,w,r)){K(i.metrics,"rerouteRejectedLabelAnchor");continue}return w}return null}const p=Math.min(l.y,h.y),x=Math.max(l.y,h.y),g=Math.max(p,n.top-ut),y=Math.min(x,n.bottom+ut);if(y-g<=tt)return K(i.metrics,"rerouteRejectedDegenerateSpan"),null;for(const b of en(d,n,i,m,s)){K(i.metrics,"rerouteCandidatesEvaluated");const I=dt([...a.points.slice(0,o),l,{x:d.a.x,y:g},{x:b,y:g},{x:b,y},{x:d.a.x,y},h,...a.points.slice(o+2)]).points;if(bt(I,n)&&!nn(I,n,c)){K(i.metrics,"rerouteRejectedBlockedRect");continue}if(bt(I,n)&&K(i.metrics,"reroutePartialProgressCandidates"),ye(I,i,m)){K(i.metrics,"rerouteRejectedProtectedObstacle");continue}if(!Yt(t.id,I,r)){K(i.metrics,"rerouteRejectedLabelAnchor");continue}return I}return null}u(ei,"rerouteSegmentAroundRect");function ce(t,e,o,n,i,r){let s=St(t,i,o);for(let a=0;a<8;a++){if(!bt(s,e))return s;const c=dt(s),d=c.points.findIndex((h,f)=>f===c.points.length-1?!1:Ft(h,c.points[f+1],e));if(d<0)return s;const l=ei(t,c.points,d,e,o,n,r);if(!l)return null;s=l}return bt(s,e)?null:s}u(ce,"rerouteForeignEdgeAroundRect");function ni(t,e,o,n,i){const r=St(t,i,o);let s=r;for(let a=0;a<2;a++){let c=!1;for(const d of e){if(!bt(s,d.rect))continue;K(o.metrics,"individualLabelRerouteAttempts"),i.set(t.id,s);const l=ce(t,d.rect,o,n,i);if(!l)return i.set(t.id,r),null;K(o.metrics,"individualLabelRerouteSuccesses"),s=l,c=!0}if(e.every(d=>!bt(s,d.rect)))return s;if(!c)break}return i.set(t.id,r),null}u(ni,"rerouteForeignEdgeAroundLabels");function oi(t,e,o,n,i){if(!Z(e.width)||!Z(e.height))return null;const r=St(t,void 0,n),s=o.segment;for(const a of Hn(t,e,s,n)){const c=Ce(Jo(s,e),s.orientation==="H"?(Math.min(s.a.x,s.b.x)+Math.max(s.a.x,s.b.x))/2:(Math.min(s.a.y,s.b.y)+Math.max(s.a.y,s.b.y))/2);for(const d of c){const l=Zo(r,o.segmentIndex,s,e,d,a,t.start===t.end);if(!l||t.start===t.end&&_n(l)||ye(l,n,new Set([e.id])))continue;const h=s.orientation==="H"?{x:d,y:a}:{x:a,y:d},f=se(e,h),m=new Map([[t.id,l]]),p=Ve(n,f,t.id,m).map(g=>n.edgeById.get(g)).filter(g=>g!==void 0);let x=!0;for(const g of p){const y=ce(g,f,n,i,m);if(!y){x=!1;break}m.set(g.id,y)}if(x&&ae(f,t,e.id,n,m)){Nt(n,t,l);for(const[g,y]of m){if(g===t.id)continue;const b=n.edgeById.get(g);b&&Nt(n,b,y)}return h}}}return null}u(oi,"labelPlacementWithExtendedDetour");function ii(t,e,o,n,i){if(!Z(e.width)||!Z(e.height))return null;const r=St(t,void 0,n),s=o.segment;for(const a of Hn(t,e,s,n)){const c=qo(t,e,s,a,n);for(const d of c){const l=Qo(r,o.segmentIndex,s,e,d,a);if(!l||t.start===t.end&&_n(l)||ye(l,n,new Set([e.id])))continue;const h=s.orientation==="H"?{x:d,y:a}:{x:a,y:d},f=se(e,h),m=new Map([[t.id,l]]),p=Ve(n,f,t.id,m).map(g=>n.edgeById.get(g)).filter(g=>g!==void 0);let x=!0;for(const g of p){const y=ce(g,f,n,i,m);if(!y){x=!1;break}m.set(g.id,y)}if(x&&ae(f,t,e.id,n,m)){Nt(n,t,l);for(const[g,y]of m){if(g===t.id)continue;const b=n.edgeById.get(g);b&&Nt(n,b,y)}return h}}}return null}u(ii,"labelPlacementWithDetour");function ri(t){return!!(t&&pt(t))}u(ri,"isPreparedLabelNode");function jn(t,e,o){const n=t.points?.find(a=>Number.isFinite(a.x)&&Number.isFinite(a.y)),i=t.start?o.get(t.start):void 0,r=t.end?o.get(t.end):void 0,s=n??(i&&Fn(i)?i:void 0)??r;if(s&&Number.isFinite(s.x)&&Number.isFinite(s.y)){e.x=s.x,e.y=s.y;return}delete e.x,delete e.y}u(jn,"parkDegenerateLabel");function si(t,e,o){let n;for(const i of dt(t.points??[]).segments)i.orientation!=="Z"&&(!n||Kt(i)>Kt(n))&&(n=i);if(!n){jn(t,e,o);return}e.x=(n.a.x+n.b.x)/2,e.y=(n.a.y+n.b.y)/2}u(si,"placeLabelAtRouteMidpoint");function ai(t){return`${zr}${t.start??""}-${t.end??""}-${t.id}`}u(ai,"preferredGridLabelNodeId");function ci(t,e){const o=t.labelNodeId??ai(t);let n=o,i=1;for(;;){if(!e.has(n))return n;n=`${o}-${i}`,i+=1}}u(ci,"ensureUniqueGridLabelNodeId");function di(t){const e=new Map;for(const n of t.nodes)e.set(n.id,n);const o=[];for(const n of t.edges){if(!n.label||n.label.length===0)continue;const i=n.start?e.get(n.start):void 0,r=n.labelNodeId?e.get(n.labelNodeId):void 0;if(ri(r)){r.label=n.label,r.labelStyle=Array.isArray(n.labelStyle)?n.labelStyle[0]:n.labelStyle??"",r.edgeStart=n.start??"",r.edgeEnd=n.end??"",i?.dir&&(r.dir=i.dir),n.label=void 0,n.text=void 0;continue}const s=ci(n,e),a={id:s,label:n.label,edgeStart:n.start??"",edgeEnd:n.end??"",shape:"labelRect",width:0,height:0,isEdgeLabel:!0,isDummy:!0,isGroup:!1,parentId:void 0,labelStyle:Array.isArray(n.labelStyle)?n.labelStyle[0]:n.labelStyle??"",...i?.dir?{dir:i.dir}:{}};o.push(a),e.set(s,a),n.labelNodeId=s,n.label=void 0,n.text=void 0}t.nodes.push(...o)}u(di,"prepareGridLayout");function li(t,e,o,n={}){const i=new Map;for(const y of t.nodes)i.set(y.id,y);const r=t.nodes.filter(pt),s=new Map(r.map(y=>[y.id,{x:y.x,y:y.y}]));for(const y of r)delete y.x,delete y.y;const a=t.edges.map((y,b)=>{if(!y.labelNodeId)return null;const I=i.get(y.labelNodeId);return I?!Z(I.width)||!Z(I.height)?(K(e,"unmeasuredLabelsSkipped"),null):{edge:y,labelNode:I,sourceIndex:b}:null}).filter(y=>y!==null);if(a.length===0)return;const c=new Map(t.edges.map(y=>[y.id,y.points?.map(b=>({...b}))])),d=u(()=>{for(const y of t.edges){const b=c.get(y.id);b?y.points=b.map(I=>({...I})):delete y.points}},"restoreBaseEdgePoints"),l=u(()=>{d();for(const y of r){const b=s.get(y.id);b&&Number.isFinite(b.x)&&Number.isFinite(b.y)?(y.x=b.x,y.y=b.y):(delete y.x,delete y.y)}},"restoreBaseState"),h=a.filter(({edge:y,labelNode:b})=>dt(y.points??[]).segments.length>0?!0:(jn(y,b,i),K(e,"degenerateLabelRoutesSkipped"),!1)).sort((y,b)=>y.sourceIndex-b.sourceIndex||U(y.edge.id,b.edge.id));if(h.length===0)return;const f=u(()=>{d();for(const{edge:y,labelNode:b}of h)si(y,b,i)},"placeLabelsAtRouteMidpoints"),m=n.maxIndexWork??go,p=Number.isFinite(m)&&m>=0?Math.floor(m):go,x=new Ur(p,e),g=[];for(let y=1;y<=2;y++){K(e,"labelPasses");const b=Ko(t,x,e),I=new Map,C=new Map,S=new Map(t.edges.map(w=>[w.id,St(w,void 0,b).map(pe)])),v=new Map;try{for(const{edge:M,labelNode:A}of h){const L=[...Vo(M,b)].sort((G,X)=>{const W=Kt(X.segment)-Kt(G.segment);return Math.abs(W)>tt?W:G.order-X.order});let B=null;for(const G of L)if(B=Wo(M,A,G.segment,b),B)break;if(!B){for(const G of L)if(B=Yo(M,A,G.segment,b,I),B)break}if(y===2&&!B){for(const G of L)if(B=ii(M,A,G,b,I),B)break}if(y===2&&!B){for(const G of L)if(B=oi(M,A,G,b,I),B)break}if(!B)throw new po({edgeId:M.id,labelNodeId:A.id,labelWidth:A.width,labelHeight:A.height,pointCount:M.points?.length??0,points:M.points?.map(G=>({...G}))??[],segments:L.map(({segment:G})=>({orientation:G.orientation,length:Kt(G),a:{...G.a},b:{...G.b}}))});A.x=B.x,A.y=B.y;const T={edgeId:M.id,nodeId:A.id,center:B,rect:se(A,B)};I.set(M.id,T),$o(b,T)}const w=[...I.values()];K(e,"frozenReservations",w.length),o&&(o.labelOverlayBuilds++,o.labelOverlayVertices+=w.length*4);for(const M of t.edges){const A=S.get(M.id)??[],L=St(M,void 0,b);JSON.stringify(L)!==JSON.stringify(A)&&v.set(M.id,L.map(pe)),Nt(b,M,A.map(pe))}for(const[M,A]of v){if(!I.has(M))continue;const L=b.edgeById.get(M);L&&Nt(b,L,A)}const E=new Set(v.keys());for(const M of t.edges){const A=I.get(M.id),L=St(M,void 0,b);for(const B of w)B.edgeId!==M.id&&bt(L,B.rect)&&E.add(M.id);A&&!Yt(M.id,L,I)&&E.add(M.id)}const R=new Map;for(const M of t.edges){if(!E.has(M.id))continue;let A=St(M,void 0,b);const L=new Map([[M.id,A]]),B=w.filter(T=>T.edgeId!==M.id&&bt(A,T.rect));if(B.length>0){const T=B.slice(1).reduce((et,D)=>({cx:(Math.min(et.left,D.rect.left)+Math.max(et.right,D.rect.right))/2,cy:(Math.min(et.top,D.rect.top)+Math.max(et.bottom,D.rect.bottom))/2,left:Math.min(et.left,D.rect.left),right:Math.max(et.right,D.rect.right),top:Math.min(et.top,D.rect.top),bottom:Math.max(et.bottom,D.rect.bottom)}),{...B[0].rect}),G=ti(A,T,B),X=G?R.get(G.key)??0:0,W=(X+2)*12,F={cx:T.cx,cy:T.cy,left:T.left-W,right:T.right+W,top:T.top-W,bottom:T.bottom+W};let Y=ce(M,F,b,I,L,G??void 0);const wt=Y!==null;if(Y??=ni(M,B,b,I,L),Y)A=Y,L.set(M.id,A),G&&wt&&R.set(G.key,X+1);else{K(e,"labelOverlapFallbacks");for(const et of B){if(!bt(A,et.rect))continue;const D=C.get(et.edgeId)??new Set;D.has(M.id)||K(e,"labelOverlapReservations"),D.add(M.id),C.set(et.edgeId,D)}}}if(!Yt(M.id,A,I))throw H("GRID_ROUTE_NOT_FOUND",`Label anchor was lost for edge "${M.id}"`,{edgeId:M.id,pass:y});I.has(M.id)&&K(e,"preservedAnchors"),Nt(b,M,A),K(e,"impactedEdgeReroutes")}for(const{edge:M,labelNode:A}of h){const L=I.get(M.id);if(!L||!Yt(M.id,St(M,void 0,b),I)||!ae(L.rect,M,A.id,b,void 0,C.get(M.id)))throw H("GRID_ROUTE_NOT_FOUND",`Label pass ${y} did not validate`,{edgeId:M.id,pass:y})}return}catch(w){if(w instanceof _o){f(),K(e,"indexWorkLimitFallbacks"),o&&(o.resourceLimitFallbacks++,o.fallbackReasons.label_index_work_cap++);return}if(!(w instanceof po))throw l(),K(e,"rollbacks"),w;g.push(w),d();for(const{labelNode:E}of h)delete E.x,delete E.y}}f(),K(e,"placementSearchFallbacks"),o&&o.fallbackReasons.label_placement_exhausted++,te.warn("[grid]","Label placement search exhausted; using route midpoints. Labels may overlap.",{reason:"label_placement_exhausted",edgeIds:h.map(({edge:y})=>y.id),failures:g.map(({details:y})=>y)})}u(li,"positionGridEdgeLabels");function Ae(t){return t.isGroup?t:void 0}u(Ae,"asGroup");function ui(t){const e=new Map,o=new Map,n=new Set;for(const d of t){if(d.id===j)throw H("GRID_INVALID_CONTAINMENT",`Node id "${j}" is reserved for the grid layout root`,{traversedIds:[d.id]});if(e.has(d.id))throw H("GRID_INVALID_CONTAINMENT",`Duplicate node id "${d.id}"`,{traversedIds:[d.id]});if(e.set(d.id,d),pt(d)){n.add(d.id);continue}const l=Ae(d);l&&o.set(l.id,l)}const i=new Map;i.set(j,[]);for(const d of t){if(n.has(d.id))continue;const l=d.parentId??j;if(l!==j&&!o.get(l))throw H("GRID_INVALID_CONTAINMENT",`Missing parent "${l}" for "${d.id}"`,{traversedIds:[d.id,l]});i.has(l)||i.set(l,[]),i.get(l).push(d)}const r=new Map,s=[],a=u(d=>(i.get(d)??[]).map(l=>Ae(l)).filter(l=>l!==void 0),"directChildGroups"),c=u(d=>{const l=r.get(d)??0;if(l===1)throw H("GRID_INVALID_CONTAINMENT",`Containment cycle at "${d}"`,{traversedIds:[d]});if(l===2)return;r.set(d,1);const h=[{groupId:d,childGroups:a(d),nextChildIndex:0}];for(;h.length>0;){const f=h[h.length-1],m=f.childGroups[f.nextChildIndex];if(m){f.nextChildIndex+=1;const x=r.get(m.id)??0;if(x===1)throw H("GRID_INVALID_CONTAINMENT",`Containment cycle at "${m.id}"`,{traversedIds:[...h.map(g=>g.groupId),m.id]});if(x===2)continue;r.set(m.id,1),h.push({groupId:m.id,childGroups:a(m.id),nextChildIndex:0});continue}h.pop(),r.set(f.groupId,2);const p=o.get(f.groupId);p&&s.push(p)}},"visit");for(const d of i.get(j)??[]){const l=Ae(d);l&&c(l.id)}for(const d of o.keys())(r.get(d)??0)===0&&c(d);return{nodeById:e,groupById:o,childrenByParent:i,rootChildren:i.get(j)??[],postOrderGroups:s,helperNodeIds:n}}u(ui,"buildGridForest");function kt(t,e,o){let n=e;const i=new Set;for(;n?.parentId;){if(n.parentId===t)return!0;if(i.has(n.parentId))return!1;i.add(n.parentId),n=o.get(n.parentId)}return!1}u(kt,"isAncestorGroup");function hi(t,e,o){const n=new Map,i=new Map;for(const r of t.edges){if(!r.start||!r.end||!r.labelNodeId)continue;o&&o.labelSpacingEdgesExamined++;const s=e.nodeById.get(r.labelNodeId),a=e.nodeById.get(r.start),c=e.nodeById.get(r.end);if(!s||!a||!c)continue;if(r.start===r.end){const f=Ln(s,"H");f&&i.set(r.id,f);continue}const d=a.parentId??j,l=c.parentId??j;if(d!==l)continue;const h=n.get(d);h?h.push({edge:r,labelNode:s}):n.set(d,[{edge:r,labelNode:s}])}return{byContainer:n,selfLoops:i}}u(hi,"buildGridLabelRequirements");function fi(t,e,o){const n=new Map;let i=0;for(const r of t)n.set(r,i),i+=(e.get(r)??0)+o;return n}u(fi,"trackOrigins");function on(t,e,o,n,i){const r=fi(o,n,i),s=r.get(t),a=n.get(t);if(s===void 0||a===void 0)return!1;const c=s+a/2,d=c-e/2,l=c+e/2;return o.every(h=>{if(h===t)return!0;const f=r.get(h),m=f+(n.get(h)??0);return l<=f||d>=m})}u(on,"crossAxisFits");function gi(t){const e=new Map;for(const o of t.values())for(const n of o.items)e.set(n.item.id,n);return e}u(gi,"placementByNodeId");function rn(t,e,o){const n=Math.min(t,e),i=Math.max(t,e),r=o.indexOf(n);return r>=0&&o[r+1]===i}u(rn,"areConsecutive");function sn(t,e,o){t.set(e,Math.max(t.get(e)??0,o))}u(sn,"addGapRequirement");function pi(t,e,o,n,i,r,s,a,c){const d=new Map,l=new Map,h=gi(e),f=u((m,p)=>Ln(m.labelNode,p),"requirementFor");for(const m of t){const p=m.edge.start?h.get(m.edge.start):void 0,x=m.edge.end?h.get(m.edge.end):void 0;if(!(!p||!x)){if(p.row===x.row&&rn(p.column,x.column,r)){const g=f(m,"H");g&&on(p.row,g.cross,i,o,s)&&(c&&c.labelSpacingEligibleEdges++,sn(l,Math.min(p.column,x.column),g.requiredAlongSpan));continue}if(p.column===x.column&&rn(p.row,x.row,i)){const g=f(m,"V");g&&on(p.column,g.cross,r,n,a)&&(c&&c.labelSpacingEligibleEdges++,sn(d,Math.min(p.row,x.row),g.requiredAlongSpan))}}}return{rowGapAfter:d,columnGapAfter:l}}u(pi,"deriveGridContainerLabelGaps");var an="[grid]",Yr=new Set(["basis","bumpX","bumpY","cardinal","catmullRom","linear","monotoneX","monotoneY","natural","step","stepAfter","stepBefore","rounded"]);function Be(t){return t!==null&&typeof t=="object"&&!Array.isArray(t)}u(Be,"isObjectRecord");function Un(t){if(!Be(t))return{};const e={};return Object.hasOwn(t,"row")&&(e.row=t.row),Object.hasOwn(t,"column")&&(e.column=t.column),Mo(t.horizontalAlign)&&(e.horizontalAlign=t.horizontalAlign),Io(t.verticalAlign)&&(e.verticalAlign=t.verticalAlign),e}u(Un,"ownPlacementFrom");function mi(t){const e=new Map;let o=0;for(const n of t)e.has(n.id)||e.set(n.id,o++);return e}u(mi,"buildGridSourceOrder");function yi(t){const e=Be(t.config?.grid)?t.config.grid:{},o=Be(e.placements)?e.placements:{},n=new Map;for(const i of Object.keys(o)){const r=o[i],s=Array.isArray(r)?r:[r];n.set(i,s.map(a=>Un(a)))}return{placements:n,columns:typeof e.columns=="number"&&Number.isFinite(e.columns)&&e.columns>=0?Math.trunc(e.columns):xt.columns,rowGap:typeof e.rowGap=="number"&&Number.isFinite(e.rowGap)&&e.rowGap>=0?e.rowGap:xt.rowGap,columnGap:typeof e.columnGap=="number"&&Number.isFinite(e.columnGap)&&e.columnGap>=0?e.columnGap:xt.columnGap,cellGap:typeof e.cellGap=="number"&&Number.isFinite(e.cellGap)&&e.cellGap>=0?e.cellGap:xt.cellGap,containerPadding:typeof e.containerPadding=="number"&&Number.isFinite(e.containerPadding)&&e.containerPadding>=0?e.containerPadding:xt.containerPadding,titleGap:typeof e.titleGap=="number"&&Number.isFinite(e.titleGap)&&e.titleGap>=0?e.titleGap:xt.titleGap,horizontalAlign:Mo(e.horizontalAlign)?e.horizontalAlign:xt.horizontalAlign,verticalAlign:Io(e.verticalAlign)?e.verticalAlign:xt.verticalAlign,curve:typeof e.curve=="string"&&Yr.has(e.curve)?e.curve:xt.curve,edgeCornerRadius:kr(e.edgeCornerRadius)}}u(yi,"readGridConfig");function xi(t,e){const o=new Map;for(const n of t){const i=n.placementId??n.id;o.set(i,(o.get(i)??0)+1)}for(const[n,i]of e.placements){const r=o.get(n)??0;if(r===0){te.warn(an,`Ignoring grid placement for unknown target "${n}"`);continue}i.length>r&&te.warn(an,`Ignoring ${i.length-r} extra grid placement occurrence(s) for target "${n}"; found ${r} matching node(s)`)}}u(xi,"validateGridPlacementMap");function bi(t){return(e,o)=>{const n=t.get(e.id)??Number.MAX_SAFE_INTEGER,i=t.get(o.id)??Number.MAX_SAFE_INTEGER;return n!==i?n-i:U(e.id,o.id)}}u(bi,"itemComparator");function wi(t,e,o,n){const i=t.placementId??t.id,r=o.placements.get(i)?.[n]??{},s=Un(t.metadata);for(const d of["row","column","horizontalAlign","verticalAlign"])Object.hasOwn(r,d)&&Object.hasOwn(s,d)&&r[d]!==s[d]&&te.debug(an,"metadata overrides placement map",{nodeId:t.id,field:d,metadata:s[d],config:r[d]});const a=Object.hasOwn(s,"row")?s.row:r.row,c=Object.hasOwn(s,"column")?s.column:r.column;return fo(i,"row",a,t.id),fo(i,"column",c,t.id),{item:t,row:a??0,column:c??0,horizontalAlign:s.horizontalAlign??r.horizontalAlign??o.horizontalAlign,verticalAlign:s.verticalAlign??r.verticalAlign??o.verticalAlign,sourceOrder:e.get(t.id)??Number.MAX_SAFE_INTEGER,explicitRow:a!==void 0,explicitColumn:c!==void 0,explicitCell:a!==void 0&&c!==void 0}}u(wi,"resolveItemPlacement");function vi(t,e,o){let n=o;for(;e.has(`${t}:${n}`);)n++;return n}u(vi,"nextFreeColumn");function Ii(t,e,o){let n=o;for(;e.has(`${n}:${t}`);)n++;return n}u(Ii,"nextFreeRow");function Mi(t,e,o){let n=o;for(;;){const i=Math.floor(n/e)+1,r=n%e+1;if(n++,!t.has(`${i}:${r}`))return{row:i,column:r,nextIndex:n}}}u(Mi,"nextAutoCell");function Ci(t,e,o){const n=[...t].sort(bi(e)),i=new Map,r=n.map(f=>{const m=f.placementId??f.id,p=i.get(m)??0;return i.set(m,p+1),wi(f,e,o,p)}),s=new Map,a=new Set;for(const f of r){if(!f.explicitCell)continue;const m=`${f.row}:${f.column}`;a.add(m);const p=s.get(m);if(p){if(p.verticalAlign!==f.verticalAlign)throw H("GRID_CELL_ALIGNMENT_CONFLICT",`Conflicting vertical alignment in cell (${f.row}, ${f.column})`,{containerId:f.item.parentId??"root",row:f.row,column:f.column,itemIds:[...p.items.map(x=>x.item.id),f.item.id],values:[...p.items.map(x=>x.verticalAlign),f.verticalAlign]});p.items.push(f)}else s.set(m,{row:f.row,column:f.column,items:[f],width:0,height:0,verticalAlign:f.verticalAlign})}const c=o.columns>0?o.columns:Math.max(1,Math.ceil(Math.sqrt(n.length)));let d=0;const l=new Map,h=new Map;for(const f of r){if(f.explicitCell)continue;if(f.explicitRow){const p=vi(f.row,a,l.get(f.row)??1);f.column=p,l.set(f.row,p+1)}else if(f.explicitColumn){const p=Ii(f.column,a,h.get(f.column)??1);f.row=p,h.set(f.column,p+1)}else{const p=Mi(a,c,d);f.row=p.row,f.column=p.column,d=p.nextIndex}const m=`${f.row}:${f.column}`;a.add(m),s.set(m,{row:f.row,column:f.column,items:[f],width:0,height:0,verticalAlign:f.verticalAlign})}return{placements:r,cells:s}}u(Ci,"resolveGridPlacements");var Lt=class extends Error{constructor(t,e,o){super(e),this.reason=t,this.searchStateScope=o,this.name="GridRoutingResourceLimitError"}static{u(this,"GridRoutingResourceLimitError")}},V=6,qt=24,qr=5e4,Qr=4,zt=64*1024*1024,Zr=class{constructor(t,e){this.bands=t,this.strictBoundaryIntervals=e,this.byLow=new Map,this.byHigh=new Map,this.coordinateCount=new Set(t.flatMap(({low:n,high:i})=>[n,i])).size;let o=t.reduce((n,i)=>n+i.intervals.length,0);for(const n of e.values())o+=n.length;this.intervalCount=o;for(const n of t)this.byLow.set(n.low,n),this.byHigh.set(n.high,n);Object.freeze(this.bands),Object.freeze(this)}static{u(this,"CompressedIntervalIndex")}containingBand(t){let e=0,o=this.bands.length-1;for(;e<=o;){const n=e+o>>>1,i=this.bands[n];if(t<=i.low)o=n-1;else if(t>=i.high)e=n+1;else return i}}overlaps(t,e,o){let n=0,i=t.length;for(;n<i;){const r=n+i>>>1;t[r][1]<=e?n=r+1:i=r}return n<t.length&&t[n][0]<o}intersects(t,e,o){const n=Math.min(e,o),i=Math.max(e,o),r=this.byHigh.get(t),s=this.byLow.get(t),a=r||s?void 0:this.containingBand(t);if(a)return this.overlaps(a.intervals,n,i);if(!r||!s)return!1;let c=0,d=0;for(;c<r.intervals.length&&d<s.intervals.length;){const l=Math.max(n,r.intervals[c][0],s.intervals[d][0]),h=Math.min(i,r.intervals[c][1],s.intervals[d][1]);if(l<h)return!0;r.intervals[c][1]<s.intervals[d][1]?c++:d++}return!1}contains(t,e){const o=this.strictBoundaryIntervals.get(t)??this.containingBand(t)?.intervals;if(!o)return!1;let n=0,i=o.length;for(;n<i;){const r=n+i>>>1;o[r][0]<e?n=r+1:i=r}return n>0&&e<o[n-1][1]}nearestBoundary(t,e,o){const n=this.strictBoundaryIntervals.get(t)??this.containingBand(t)?.intervals;if(!n)return;if(o<0){let s=0,a=n.length;for(;s<a;){const c=s+a>>>1;n[c][1]<=e?s=c+1:a=c}return s>0?n[s-1][1]:void 0}let i=0,r=n.length;for(;i<r;){const s=i+r>>>1;n[s][0]<e?i=s+1:r=s}return i<n.length?n[i][0]:void 0}},mo,Ke=class{constructor(t){this.backing=t,this[mo]="ImmutableMap",Object.freeze(this)}static{u(this,"ImmutableMap")}get size(){return this.backing.size}entries(){return this.backing.entries()}forEach(t,e){for(const[o,n]of this.backing)t.call(e,n,o,this)}get(t){return this.backing.get(t)}has(t){return this.backing.has(t)}keys(){return this.backing.keys()}values(){return this.backing.values()}[(mo=Symbol.toStringTag,Symbol.iterator)](){return this.entries()}},yo,xo=class{constructor(t,e){this.base=t,this.overrides=e,this[yo]="OverlayMap"}static{u(this,"OverlayMap")}get size(){let t=0;for(const e of this.overrides.keys())this.base.has(e)||t++;return this.base.size+t}materialize(){return new Map([...this.base,...this.overrides])}entries(){return this.materialize().entries()}forEach(t,e){for(const[o,n]of this)t.call(e,n,o,this)}get(t){return this.overrides.get(t)??this.base.get(t)}has(t){return this.overrides.has(t)||this.base.has(t)}keys(){return this.materialize().keys()}values(){return this.materialize().values()}[(yo=Symbol.toStringTag,Symbol.iterator)](){return this.entries()}};function Si(t,e){return new Proxy([],{get(o,n){if(n==="length")return t.length+e.length;if(n===Symbol.iterator)return function*(){yield*t,yield*e};if(typeof n=="string"&&/^\d+$/.test(n)){const i=Number(n);return i<t.length?t[i]:e[i-t.length]}return Reflect.get(Array.prototype,n)}})}u(Si,"overlayArray");function cn(t,e,o){return new Proxy([],{get(n,i){if(i==="length")return o;if(i===Symbol.iterator)return function*(){for(let r=0;r<o;r++)yield e.get(r)??t[r]};if(typeof i=="string"&&/^\d+$/.test(i)){const r=Number(i);return e.get(r)??t[r]}return Reflect.get(Array.prototype,i)}})}u(cn,"overrideArray");var Ei=class{constructor(t){this.base=t,this.addedVertices=[],this.adjacencyOverrides=new Map,this.searchAdjacencyOverrides=new Map,this.pointOverrides=new Map,this.undoLog=[],this.resetCount=0}static{u(this,"EndpointOverlayScratch")}reset(t){if(t!==this.base)throw new Error("Endpoint overlay scratch cannot be shared across base topologies");for(const e of this.undoLog)this.adjacencyOverrides.delete(e),this.searchAdjacencyOverrides.delete(e);this.undoLog.length=0,this.addedVertices.length=0,this.pointOverrides.clear(),this.resetCount++}setArcs(t,e){this.adjacencyOverrides.has(t)||this.undoLog.push(t),this.adjacencyOverrides.set(t,e),this.searchAdjacencyOverrides.set(t,Yn(e))}};function _t(t){return Object.is(t,-0)?0:t}u(_t,"normalizeCoordinate");function xe(t){if(![t.left,t.right,t.top,t.bottom].every(Number.isFinite))throw new Error("Grid routing geometry must contain only finite coordinates");const o=_t(Math.min(t.left,t.right)),n=_t(Math.max(t.left,t.right)),i=_t(Math.min(t.top,t.bottom)),r=_t(Math.max(t.top,t.bottom));if(o===n||i===r)throw new Error("Grid routing rectangles must have positive area");return{left:o,right:n,top:i,bottom:r}}u(xe,"normalizeRect");function Ri(t,e){const o=xe(t.bounds),n={id:t.id,left:Math.max(e.left,o.left-V),right:Math.min(e.right,o.right+V),top:Math.max(e.top,o.top-V),bottom:Math.min(e.bottom,o.bottom+V)};return n.left<n.right&&n.top<n.bottom?n:void 0}u(Ri,"inflateAndClip");function Xn(t){const e=[...t].sort((n,i)=>n.low-i.low||n.high-i.high||U(n.id,i.id)),o=[];for(const n of e){const i=o.at(-1);if(!i||n.low>i.high){o.push({...n});continue}i.high=Math.max(i.high,n.high),U(n.id,i.id)<0&&(i.id=n.id)}return o}u(Xn,"mergeObstacleIntervals");function Ai(t){const e=new Map;for(const s of t){const a=e.get(s.left)??{starts:[],ends:[]};a.starts.push(s),e.set(s.left,a);const c=e.get(s.right)??{starts:[],ends:[]};c.ends.push(s),e.set(s.right,c)}const o=[...e.keys()].sort((s,a)=>s-a),n=new Set,i=[];let r=new Map;for(let s=0;s<o.length-1;s++){const a=o[s],c=o[s+1],d=e.get(a);for(const h of d.ends)n.delete(h);for(const h of d.starts)n.add(h);const l=new Map;for(const h of Xn([...n].map(f=>({low:f.top,high:f.bottom,id:f.id})))){const f=`${h.low}:${h.high}`,m=r.get(f);if(m)m.right=c,U(h.id,m.id)<0&&(m.id=h.id);else{const p={id:h.id,left:a,right:c,top:h.low,bottom:h.high};i.push(p),l.set(f,p);continue}l.set(f,m)}r=l}return i.sort((s,a)=>s.top-a.top||s.left-a.left||s.bottom-a.bottom||s.right-a.right||U(s.id,a.id))}u(Ai,"unionObstacles");function gt(t){return`${_t(t.x)}:${_t(t.y)}`}u(gt,"routingPointKey");function be(t){return t==="left"?0:t==="right"?1:t==="top"?2:t==="bottom"?3:4}u(be,"topologySideOrdinal");function je(t,e){return U(t.kind,e.kind)||be(t.side)-be(e.side)||t.point.x-e.point.x||t.point.y-e.point.y||U(t.ownerId??"",e.ownerId??"")}u(je,"vertexRecordOrder");function Ue(t){const e=new Map;for(const o of[...t].sort(je)){const n={...o,point:{x:_t(o.point.x),y:_t(o.point.y)}},i=gt(n.point);e.has(i)||e.set(i,n)}return[...e.values()]}u(Ue,"canonicalRecords");function dn(t,e,o="corner"){return[{point:{x:t.left,y:t.top},kind:o,ownerId:e},{point:{x:t.right,y:t.top},kind:o,ownerId:e},{point:{x:t.left,y:t.bottom},kind:o,ownerId:e},{point:{x:t.right,y:t.bottom},kind:o,ownerId:e}]}u(dn,"cornerRecords");function Oi(t,e){const o=t.coordinate??(t.side==="left"?e.left:t.side==="right"?e.right:t.side==="top"?e.top:e.bottom);return(t.side==="left"||t.side==="right"?[{x:o,y:t.low},{x:o,y:t.high}]:[{x:t.low,y:o},{x:t.high,y:o}]).map(i=>({point:i,kind:"portal",ownerId:t.ownerId,side:t.side}))}u(Oi,"portalRecords");function Wn(t,e,o,n,i){if(e==="left"||e==="right")return{x:n.nearestBoundary(t.y,t.x,e==="left"?-1:1)??(e==="left"?o.left:o.right),y:t.y};const r=i.nearestBoundary(t.x,t.y,e==="top"?-1:1)??(e==="top"?o.top:o.bottom);return{x:t.x,y:r}}u(Wn,"rayHit");function ln(t,e,o){const n=[...new Set(t.flatMap(h=>e==="H"?[h.top,h.bottom]:[h.left,h.right]))].sort((h,f)=>h-f),i=[],r=new Map,s=new Map,a=new Map;for(const h of t){const f=e==="H"?h.top:h.left,m=e==="H"?h.bottom:h.right,p=s.get(f)??[];p.push(h),s.set(f,p);const x=a.get(m)??[];x.push(h),a.set(m,x)}const c=new Set,d=u(()=>Xn([...c].map(h=>e==="H"?{low:h.left,high:h.right,id:h.id}:{low:h.top,high:h.bottom,id:h.id})),"activeIntervals"),l=u(h=>{const f=o.intervalCount+h.length;return Ht(Le(0,0,t.length,f),o.maxEstimatedBytes,"estimated_memory_cap"),o.intervalCount=f,Object.freeze(h.map(m=>Object.freeze([m.low,m.high])))},"freezeIntervals");for(let h=0;h<n.length;h++){const f=n[h];for(const x of a.get(f)??[])c.delete(x);r.set(f,l(d()));for(const x of s.get(f)??[])c.add(x);const m=n[h+1];if(m===void 0)continue;const p=d();p.length>0&&i.push({low:f,high:m,intervals:l(p)})}return new Zr(Object.freeze(i),new Ke(r))}u(ln,"createIntervalIndex");function Le(t,e,o,n){return t*64+e*56+o*48+n*24}u(Le,"estimatedTopologyBytes");function Ht(t,e,o){if(t>e)throw new Lt(o,`Grid routing ${o} exceeded: ${t} > ${e}`)}u(Ht,"enforceCap");function un(t,e){const o=new Map;for(const n of t){const i=e==="H"?n.point.y:n.point.x,r=o.get(i)??[];r.push(n),o.set(i,r)}for(const n of o.values())n.sort((i,r)=>e==="H"?i.point.x-r.point.x||i.id-r.id:i.point.y-r.point.y||i.id-r.id),Object.freeze(n);return new Ke(o)}u(un,"indexVertexLines");function Yn(t){return Object.freeze(t.map(e=>Object.freeze({to:e.to,orientationOrdinal:e.orientation==="H"?1:2,length:e.length,boundaryTransitions:e.kind==="portal"?1:0})))}u(Yn,"searchArcs");function Bi(t,e,o,n){const i=Ue(t).sort(je),r=n.maxVertices??qr;Ht(i.length,r,"vertex_cap");const s=i.map((f,m)=>Object.freeze({id:m,...f,point:Object.freeze({...f.point})})),a=new Map(s.map(f=>[f.id,[]])),c=u((f,m,p)=>{const x=Math.abs(f.point.x-m.point.x)+Math.abs(f.point.y-m.point.y);if(x===0)return;const g=p==="H"?Math.min(f.point.x,m.point.x):Math.min(f.point.y,m.point.y),y=g+x;for(const[b,I]of[[f,m],[m,f]])a.get(b.id).push({from:b.id,to:I.id,orientation:p,length:x,kind:"visibility",intervalStart:g,intervalEnd:y})},"addArcPair");for(const f of["H","V"]){const m=new Map;for(const p of s){const x=f==="H"?p.point.y:p.point.x,g=m.get(x)??[];g.push(p),m.set(x,g)}for(const[p,x]of m){x.sort((g,y)=>f==="H"?g.point.x-y.point.x||g.id-y.id:g.point.y-y.point.y||g.id-y.id);for(let g=1;g<x.length;g++){const y=x[g-1],b=x[g],I=f==="H"?y.point.x:y.point.y,C=f==="H"?b.point.x:b.point.y;(f==="H"?e:o).intersects(p,I,C)||c(y,b,f)}}}const d={visibility:0,terminal:1,portal:2,lane:3};let l=0;const h=new Map;for(const f of s){const m=a.get(f.id);m.sort((x,g)=>d[x.kind]-d[g.kind]||U(x.orientation,g.orientation)||s[x.to].point.x-s[g.to].point.x||s[x.to].point.y-s[g.to].point.y||x.to-g.to);const p=m.filter((x,g)=>g===0||x.to!==m[g-1].to||x.orientation!==m[g-1].orientation||x.kind!==m[g-1].kind);l+=p.length,h.set(f.id,Object.freeze(p.map(x=>Object.freeze(x))))}return Ht(l,n.maxAdjacencyEntries??r*Qr,"adjacency_cap"),{vertices:Object.freeze(s),adjacency:new Ke(h),adjacencyEntries:l}}u(Bi,"buildVisibilityGraph");function ne(t,e,o){const n=xe(e),i=o?xe(o):void 0,r=Math.max(n.top+V,(i?.bottom??-1/0)+V),s=n.bottom-V,a=n.left+V,c=n.right-V,d=[];return r<=s&&d.push({ownerId:t,side:"left",low:r,high:s},{ownerId:t,side:"right",low:r,high:s}),a<=c&&(d.push({ownerId:t,side:"bottom",low:a,high:c}),(!i||i.bottom+V<=n.top)&&d.push({ownerId:t,side:"top",low:a,high:c})),d}u(ne,"derivePortalRanges");function hn(t,e,o,n,i){const r=ne(t,e,o).find(h=>h.side===n);if(!r||i<r.low||i>r.high)throw new Error(`Illegal ${n} portal for "${t}" at ${i}`);const s=n==="left"?e.left:n==="right"?e.right:n==="top"?e.top:e.bottom,a=n==="left"||n==="top"?s+V:s-V,c=n==="left"||n==="top"?s-V:s+V,d=n==="left"||n==="right"?{x:a,y:i}:{x:i,y:a},l=n==="left"||n==="right"?{x:c,y:i}:{x:i,y:c};return{ownerId:t,side:n,tangentialCoordinate:i,interior:d,exterior:l,transition:{from:d,to:l,orientation:n==="left"||n==="right"?"H":"V",length:V*2,kind:"portal"}}}u(hn,"buildPairedPortal");function Li(t,e={}){const o=xe(t.bounds),n=[...t.obstacles,...t.titleExclusions??[]].map(g=>Ri(g,o)).filter(g=>!!g),i=Ai(n),r=[...t.portalRanges??[]].sort((g,y)=>be(g.side)-be(y.side)||g.low-y.low||g.high-y.high||U(g.ownerId,y.ownerId)),s=Ue([...dn(o,t.containerId),...i.flatMap(g=>dn(g,g.id)),...r.flatMap(g=>Oi(g,o))]),a={intervalCount:0,maxEstimatedBytes:e.caps?.maxEstimatedBytes??zt};Ht(Le(0,0,i.length,0),a.maxEstimatedBytes,"estimated_memory_cap");const c=ln(i,"H",a),d=ln(i,"V",a),l=[],h=["left","right","top","bottom"];for(const g of s)for(const y of h){const b=Wn(g.point,y,o,c,d);(b.x!==g.point.x||b.y!==g.point.y)&&l.push({point:b,kind:"projection",side:y})}const{vertices:f,adjacency:m,adjacencyEntries:p}=Bi([...s,...l],c,d,e.caps??{}),x=Le(f.length,p,i.length,c.intervalCount+d.intervalCount);return Ht(x,e.caps?.maxEstimatedBytes??zt,"estimated_memory_cap"),e.metrics&&(e.metrics.containersBuilt++,e.metrics.baseTopologyBuilds++,e.metrics.baseVertices+=f.length,e.metrics.baseAdjacencyEntries+=p,e.metrics.buildSweepEvents+=s.length*4+i.length*4,e.metrics.estimatedBytes+=x),Object.freeze({containerId:t.containerId,bounds:Object.freeze(o),obstacles:Object.freeze(i.map(g=>Object.freeze(g))),vertices:Object.freeze(f),pointVertexIds:new Ke(new Map(f.map(({id:g,point:y})=>[gt(y),g]))),horizontalVertexLines:un(f,"H"),verticalVertexLines:un(f,"V"),adjacency:m,adjacencyByVertex:Object.freeze(f.map(({id:g})=>m.get(g)??[])),searchAdjacencyByVertex:Object.freeze(f.map(({id:g})=>Yn(m.get(g)??[]))),adjacencyEntries:p,horizontalIntervals:c,verticalIntervals:d,portalRanges:Object.freeze(r.map(g=>Object.freeze(g))),seedCount:s.length,estimatedBytes:x})}u(Li,"buildContainerRoutingTopology");function fn(t,e){return e.contains(t.y,t.x)}u(fn,"pointInsideObstacle");function Xe(t,e,o,n,i,r=[]){const s=i??new Ei(t);s.reset(t);const a=[{point:e,kind:"endpoint",ownerId:"source"},{point:o,kind:"endpoint",ownerId:"target"},...r.filter(v=>!fn(v,t.horizontalIntervals)).map(v=>({point:v,kind:"lane"}))];for(const v of[{x:e.x,y:o.y},{x:o.x,y:e.y}])fn(v,t.horizontalIntervals)||a.push({point:v,kind:"projection"});for(const v of a.slice(0,2))for(const w of["left","right","top","bottom"]){const E=Wn(v.point,w,t.bounds,t.horizontalIntervals,t.verticalIntervals);(E.x!==v.point.x||E.y!==v.point.y)&&a.push({point:E,kind:"projection",side:w})}const c=Ue(a).filter(({point:v})=>!t.pointVertexIds.has(gt(v))).sort(je);Ht(c.length,32,"vertex_cap"),s.addedVertices.push(...c.map((v,w)=>Object.freeze({id:t.vertices.length+w,...v,point:Object.freeze({...v.point})})));const d=Si(t.vertices,s.addedVertices),l=u(v=>v<t.vertices.length?t.vertices[v]:s.addedVertices[v-t.vertices.length],"vertexAt"),h=new Map,f=u(v=>{let w=h.get(v);return w||(w=[...t.adjacency.get(v)??[]],h.set(v,w)),w},"mutableArcs");for(const v of s.addedVertices)h.set(v.id,[]);const m=new Set(s.addedVertices.map(({id:v})=>v)),p=new Set,x=u((v,w,E)=>{const R=Math.abs(v.point.x-w.point.x)+Math.abs(v.point.y-w.point.y);if(R===0)return;const M=E==="H"?Math.min(v.point.x,w.point.x):Math.min(v.point.y,w.point.y),A=M+R;for(const[L,B]of[[v,w],[w,v]]){const T=`${L.id}:${B.id}:${E}:visibility`;p.has(T)||(t.adjacency.get(L.id)??[]).some(G=>G.to===B.id&&G.orientation===E&&G.kind==="visibility")||(p.add(T),f(L.id).push({from:L.id,to:B.id,orientation:E,length:R,kind:"visibility",intervalStart:M,intervalEnd:A}))}},"connect");for(const v of["H","V"]){const w=v==="H"?t.horizontalVertexLines:t.verticalVertexLines,E=new Set(s.addedVertices.map(({point:R})=>v==="H"?R.y:R.x));for(const R of E){const M=[...w.get(R)??[],...s.addedVertices.filter(({point:A})=>(v==="H"?A.y:A.x)===R)];M.sort((A,L)=>v==="H"?A.point.x-L.point.x||A.id-L.id:A.point.y-L.point.y||A.id-L.id);for(let A=1;A<M.length;A++){const L=M[A-1],B=M[A];if(!m.has(L.id)&&!m.has(B.id))continue;const T=v==="H"?L.point.x:L.point.y,G=v==="H"?B.point.x:B.point.y;(v==="H"?t.horizontalIntervals:t.verticalIntervals).intersects(R,T,G)||x(L,B,v)}}}for(const[v,w]of h){w.sort((R,M)=>U(R.kind,M.kind)||U(R.orientation,M.orientation)||l(R.to).point.x-l(M.to).point.x||l(R.to).point.y-l(M.to).point.y||R.to-M.to);const E=Object.freeze(w.map(R=>Object.freeze(R)));s.setArcs(v,E)}const g=t.adjacencyEntries+p.size;Ht(g,t.adjacencyEntries+64,"adjacency_cap");const y=c.length,b=t.estimatedBytes+y*64+(g-t.adjacencyEntries)*56;n&&(n.endpointOverlayBuilds++,n.endpointOverlayVertices+=y,n.estimatedBytes=Math.max(n.estimatedBytes,b));const I=t.vertices.length+s.addedVertices.length,C=cn(t.adjacencyByVertex,s.adjacencyOverrides,I),S=cn(t.searchAdjacencyByVertex,s.searchAdjacencyOverrides,I);for(const v of s.addedVertices)s.pointOverrides.set(gt(v.point),v.id);return Object.freeze({...t,vertices:d,pointVertexIds:new xo(t.pointVertexIds,s.pointOverrides),adjacency:new xo(t.adjacency,s.adjacencyOverrides),adjacencyByVertex:C,searchAdjacencyByVertex:S,adjacencyEntries:g,estimatedBytes:b,vertexCount:I,getVertex:l,getSearchArcs:u(v=>s.searchAdjacencyOverrides.get(v)??t.searchAdjacencyByVertex[v]??[],"getSearchArcs")})}u(Xe,"buildEndpointRoutingOverlay");var we=4,q=20,Pe=8;function We(t){return!!t.groupTitleRect}u(We,"ownerGroupTitle");function oe(t,e){return JSON.stringify([t,e])}u(oe,"ownerSideKey");function Ye(t,e){const o=k(t),n=e.x-o.cx,i=e.y-o.cy,r=t.isGroup&&We(t);return Math.abs(n)>=Math.abs(i)?n>=0?"right":"left":i>=0?"bottom":r?n>=0?"right":"left":"top"}u(Ye,"preferredSide");function _e(t,e){const o=[];let n=t.parentId??j;const i=new Set;for(;o.push(n),!(n===j||i.has(n));)i.add(n),n=e.get(n)?.parentId??j;return o}u(_e,"containerChain");function Pi(t,e,o){if(t.isGroup&&kt(t.id,e,o))return t.parentId??j;if(e.isGroup&&kt(e.id,t,o))return e.parentId??j;const n=new Set(_e(e,o));for(const i of _e(t,o))if(n.has(i))return i;return j}u(Pi,"commonContainerId");function Ge(t,e){return e==="left"||e==="right"?t.cy:t.cx}u(Ge,"oppositeCoordFor");function ie(t,e){return e==="left"||e==="right"?{x:e==="left"?t.left:t.right,y:t.cy}:{x:t.cx,y:e==="top"?t.top:t.bottom}}u(ie,"sideMidpoint");function Te(t,e){return e==="left"||e==="right"?t.y:t.x}u(Te,"tangentialCoordinate");function gn(t,e,o,n,i,r){const s=[],a=k(t),c=k(e),d={x:e.x??0,y:e.y??0};let l=t;for(;;){const h=l.parentId??j,f=n.get(h),m={x:l.x??0,y:l.y??0},p=d.x-m.x,x=d.y-m.y,g=x<0&&Math.abs(p)<=nt&&!!((l.isGroup?l.groupTitleRect:void 0)??f?.groupTitleRect),y=[];Math.abs(Math.abs(p)-Math.abs(x))<=nt&&Math.abs(p)>nt&&y.push(p>=0?"right":"left",x>=0?"bottom":"top");const b=!!((l.isGroup?l.groupTitleRect:void 0)??f?.groupTitleRect),I=(g?["left","right"]:y).filter(S=>S!=="top"||!b);let C=Ye(l,d);if(C==="top"&&f?.groupTitleRect&&(C=p>=0?"right":"left"),s.push({ownerId:l.id,side:C,demandKey:JSON.stringify([i,r,l.id,C]),oppositeCoord:Ge(c,C),preferredCoord:Ge(a,C),compactPortal:l.id!==t.id,ambiguousSides:I.length>1?I:void 0,inner:s.length?{demandKey:s[s.length-1].demandKey,side:s[s.length-1].side}:void 0}),l.isGroup&&l.id===o&&kt(l.id,e,n))return{chain:s,finalKind:"boundary"};if(h===o)return{chain:s,finalKind:"item"};if(!f?.isGroup)throw H("GRID_INVALID_CONTAINMENT",`Missing parent group "${h}"`,{traversedIds:s.map(S=>S.ownerId)});l=f}}u(gn,"buildEndpointPlan");function _i(t){const e=new Map;for(const n of t){if(!n.start||!n.end)continue;const i=n.start<n.end?`${n.start}|${n.end}`:`${n.end}|${n.start}`;e.has(i)||e.set(i,[]),e.get(i).push(n)}const o=new Map;for(const[n,i]of e)i.sort((r,s)=>U(`${r.start}|${r.end}`,`${s.start}|${s.end}`)||U(r.id,s.id)),i.forEach((r,s)=>o.set(r.id,{index:s,size:i.length,offset:(s-(i.length-1)/2)*Pe,pairKey:n}));return o}u(_i,"buildPairLanes");function Gi(t,e){const o=new Map,n=u((s,a)=>oe(s,a),"reservationKey");for(const s of t)for(const a of[...s.source.chain,...s.target.chain])if(!a.ambiguousSides){const c=n(a.ownerId,a.side);o.set(c,(o.get(c)??0)+1)}const i=u((s,a,c)=>{const d=a.chain.filter(({ambiguousSides:f})=>f);if(d.length===0)return;const h=["right","bottom","left","top"].filter(f=>d.every(m=>m.ambiguousSides?.includes(f))&&d.every(m=>{const p=e.forest.nodeById.get(m.ownerId);return p!==void 0&&Rt(p,f)!==void 0})).sort((f,m)=>d.reduce((p,x)=>p+(o.get(n(x.ownerId,f))??0),0)-d.reduce((p,x)=>p+(o.get(n(x.ownerId,m))??0),0)||+(f!==d[0].side)-+(m!==d[0].side))[0];if(h){for(const f of d){f.side=h;const m=n(f.ownerId,h);o.set(m,(o.get(m)??0)+1);const p=e.forest.nodeById.get(f.ownerId);p&&(f.preferredCoord=Ge(k(p),h))}for(const[f,m]of a.chain.entries())m.demandKey=JSON.stringify([s.edge.id,c,m.ownerId,m.side]),m.inner=f>0?{demandKey:a.chain[f-1].demandKey,side:a.chain[f-1].side}:void 0}},"resolveEndpoint"),r=t.flatMap(s=>[{plan:s,endpoint:s.source,role:"source"},{plan:s,endpoint:s.target,role:"target"}]).sort((s,a)=>U(`${s.plan.edge.start??""}|${s.plan.edge.end??""}|${s.plan.edge.id}|${s.role}`,`${a.plan.edge.start??""}|${a.plan.edge.end??""}|${a.plan.edge.id}|${a.role}`));for(const{plan:s,endpoint:a,role:c}of r)i(s,a,c);for(const s of t){const a=s.source.chain.at(-1),c=s.target.chain.at(-1),d=a?e.forest.nodeById.get(a.ownerId):void 0,l=c?e.forest.nodeById.get(c.ownerId):void 0;if(!a||!c||!d||!l)continue;const h=ie(k(d),a.side),f=ie(k(l),c.side);for(const m of s.source.chain)m.oppositeCoord=Te(f,m.side);for(const m of s.target.chain)m.oppositeCoord=Te(h,m.side)}}u(Gi,"resolveAmbiguousEndpointSides");function Ti(t,e){const o=e.forest.nodeById,n=_i(t.edges),i=t.edges.map(r=>{const s=r.start?o.get(r.start):void 0,a=r.end?o.get(r.end):void 0;if(!s||!a)throw H("GRID_MISSING_ENDPOINT",`Missing endpoint for edge "${r.id}"`,{edgeId:r.id,start:r.start,end:r.end});const c=Pi(s,a,o),d=n.get(r.id)??{index:0,size:1,offset:0,pairKey:Ot(r)};return{edge:r,lcaContainerId:c,source:gn(s,a,c,o,r.id,"source"),target:gn(a,s,c,o,r.id,"target"),laneIndex:d.index,laneOffset:d.offset,bundleSize:d.size,pairKey:d.pairKey}});return Gi(i,e),i}u(Ti,"collectRoutePlans");function qn(t,e,o){const n=[];for(const[d,l]of t.entries())n.push(d===0?l:Math.max(l,n[d-1]+we));for(let d=n.length-1;d>=0;d--)n[d]=Math.min(n[d],d===n.length-1?o:n[d+1]-we);const i=t.reduce((d,l)=>d+l,0)/t.length,r=n.reduce((d,l)=>d+l,0)/n.length,s=e-n[0],a=o-n[n.length-1],c=Bt(i-r,s,a);return n.map(d=>d+c)}u(qn,"assignCompactPortalCoordinates");function Ni(t,e,o){const n=e.forest.nodeById,i=new Map(t.map(l=>[l.edge.id,l])),r=new Map;for(const l of t)if(l.edge.start!==l.edge.end)for(const h of[...l.source.chain,...l.target.chain])r.has(h.demandKey)||r.set(h.demandKey,{ownerId:h.ownerId,side:h.side,edgeId:l.edge.id,demandKey:h.demandKey,oppositeCoord:h.oppositeCoord,preferredCoord:h.preferredCoord,compactPortal:h.compactPortal,inner:h.inner});const s=new Map;for(const l of r.values()){const h=oe(l.ownerId,l.side),f=s.get(h)??{ownerId:l.ownerId,side:l.side,demands:[]};f.demands.push(l),s.set(h,f)}const a=u(l=>{const h=n.get(l);return h?_e(h,n).length:0},"depthOf"),c=[...s.values()].sort((l,h)=>Number(l.demands.every(f=>f.compactPortal))-Number(h.demands.every(f=>f.compactPortal))||a(h.ownerId)-a(l.ownerId)),d=new Map;for(const{ownerId:l,side:h,demands:f}of c){const m=n.get(l);if(!m)continue;const p=k(m);let x=h==="left"||h==="right"?p.top+V:p.left+V;const g=h==="left"||h==="right"?p.bottom-V:p.right-V;(h==="left"||h==="right")&&m.groupTitleRect&&(x=Math.max(x,m.groupTitleRect.bottom+V));const y=Math.max(0,g-x);f.sort((v,w)=>v.oppositeCoord-w.oppositeCoord||U(v.edgeId,w.edgeId));const b=f.map(v=>i.get(v.edgeId)),I=new Set(b.map(v=>v?.pairKey)),C=m.isGroup&&f.every(({compactPortal:v})=>v);if(!(C&&f.length===1)&&I.size===1&&b.every(v=>v&&v.bundleSize===f.length&&o.get(v.edge.start)===v.bundleSize&&o.get(v.edge.end)===v.bundleSize)){const v=(x+g)/2,w=b.map(E=>v+E.laneOffset);if(w.every(E=>E>=x&&E<=g)){f.forEach((E,R)=>d.set(E.demandKey,w[R]));continue}}if(C){const v=e.containers.get(m.id),w=h==="left"||h==="right"?v?.horizontalCorridors:v?.verticalCorridors,E=u(M=>{const A=M.inner?r.get(M.inner.demandKey):void 0,L=A?n.get(A.ownerId):void 0,B=A?d.get(A.demandKey):void 0;if(!A||!L||B===void 0)return M.preferredCoord;const T=ie(k(L),A.side);return A.side==="left"||A.side==="right"?T.y=B:T.x=B,Te(T,h)},"innerCoordinate"),R=u(M=>{const A=M.inner?d.get(M.inner.demandKey):void 0,L=M.inner!==void 0&&A!==void 0&&(M.inner.side==="left"||M.inner.side==="right")==(h==="left"||h==="right"),B=Bt(L?A:M.preferredCoord,x,g),T=w?.reduce((G,X)=>Math.abs(X-B)<Math.abs(G-B)?X:G,w[0]);return T!==void 0&&Math.abs(T-B)<=nt?T:B},"preferredCoordinate");if(f.length===1){d.set(f[0].demandKey,R(f[0]));continue}if(y>=we*(f.length-1)){f.sort((L,B)=>E(L)-E(B)||L.oppositeCoord-B.oppositeCoord||U(L.edgeId,B.edgeId));const M=f.map(R),A=qn(M,x,g);f.forEach((L,B)=>d.set(L.demandKey,A[B]));continue}}if(f.length===1||y<=0){d.set(f[0].demandKey,(x+g)/2);continue}const S=y/(f.length-1);f.forEach((v,w)=>{d.set(v.demandKey,x+S*w)})}for(const l of t){if(l.bundleSize!==1)continue;const h=l.source.chain.at(-1),f=l.target.chain.at(-1);if(!h||!f)continue;const m=u(b=>b==="left"||b==="right","verticalSide");if(m(h.side)!==m(f.side))continue;const p=d.get(h.demandKey),x=d.get(f.demandKey);if(p===void 0||x===void 0||Math.abs(p-x)>nt)continue;const g=[...l.source.chain,...l.target.chain];if(g.some(b=>m(b.side)!==m(h.side)))continue;const y=[p,x].find(b=>g.every(I=>{const C=n.get(I.ownerId),S=C?Rt(C,I.side):void 0;return S!==void 0&&b>=S.low-nt&&b<=S.high+nt}));y!==void 0&&g.forEach(b=>d.set(b.demandKey,y))}return d}u(Ni,"assignDemandCoordinates");function Gt(t){return t==="right"?0:t==="bottom"?1:t==="left"?2:3}u(Gt,"sideOrder");function Rt(t,e){const o=k(t);if(e==="top"&&t.groupTitleRect)return;let n=e==="left"||e==="right"?o.top+V:o.left+V;const i=e==="left"||e==="right"?o.bottom-V:o.right-V;return(e==="left"||e==="right")&&t.groupTitleRect&&(n=Math.max(n,t.groupTitleRect.bottom+V)),n<=i?{low:n,high:i}:void 0}u(Rt,"sideInterval");function Ot(t){const e=t.start??"",o=t.end??"";return e<o?`${e}|${o}`:`${o}|${e}`}u(Ot,"endpointPairKey");function Qn(t,e,o){const n=k(t.opposite),i=k(e.opposite),r=o==="left"||o==="right"?n.cy:n.cx,s=o==="left"||o==="right"?i.cy:i.cx;return r-s||U(Ot(t.plan.edge),Ot(e.plan.edge))||U(`${t.plan.edge.start}|${t.plan.edge.end}`,`${e.plan.edge.start}|${e.plan.edge.end}`)||U(t.plan.edge.id,e.plan.edge.id)||U(t.role,e.role)}u(Qn,"compareEndpointDemands");function Fi(t){return`${t.plan.edge.id}:${t.role}`}u(Fi,"endpointDemandKey");function Di(t,e){return U(Ot(t.plan.edge),Ot(e.plan.edge))||U(`${t.plan.edge.start}|${t.plan.edge.end}`,`${e.plan.edge.start}|${e.plan.edge.end}`)||U(t.plan.edge.id,e.plan.edge.id)||U(t.role,e.role)}u(Di,"compareEndpointDemandIdentity");function Ne(t,e,o){const n=Rt(t,e);if(!n||o.length===0)return new Map;const i=[...o].sort((a,c)=>Qn(a,c,e));if(i.length===1){const a=k(t),c=e==="left"||e==="right"?a.cy:a.cx;return new Map([[i[0],Bt(c,n.low,n.high)]])}if((n.high-n.low)/(i.length-1)<we)return new Map(i.map((a,c)=>[a,n.low+c*(n.high-n.low)/(i.length-1)]));const r=i.map(({opposite:a})=>{const c=k(a),d=e==="left"||e==="right"?c.cy:c.cx;return Bt(d,n.low,n.high)}),s=qn(r,n.low,n.high);return new Map(i.map((a,c)=>[a,s[c]]))}u(Ne,"preferredEndpointCoordinates");function Zn(t,e){const o=Rt(t,e);return o?1+Math.floor((o.high-o.low)/we):0}u(Zn,"endpointSideCapacity");function pn(t,e){const o=k(e.opposite),n=Ye(t,{x:o.cx,y:o.cy});return["right","bottom","left","top"].filter(i=>Zn(t,i)>0).sort((i,r)=>{if(i===n)return-1;if(r===n)return 1;const s=k(t),a=ie(s,i),c=ie(s,r),d=Math.abs(a.x-o.cx)+Math.abs(a.y-o.cy),l=Math.abs(c.x-o.cx)+Math.abs(c.y-o.cy);return d-l||Gt(i)-Gt(r)})}u(pn,"endpointSidePreferences");function Qt(t,e){const o=k(t),n=k(e.opposite);return Math.abs(o.cx-n.cx)<=nt||Math.abs(o.cy-n.cy)<=nt}u(Qt,"isAxisAlignedDemand");function ki(t,e,o,n){const i=Rt(t,e);if(!i)return;const r=[...o],s=new Map;for(const a of n){const c=k(a.opposite),d=Bt(e==="left"||e==="right"?c.cy:c.cx,i.low,i.high),l=[d,i.low,i.high,...r.flatMap(h=>[h-qt,h+qt])].filter(h=>h>=i.low-nt&&h<=i.high+nt&&r.every(f=>Math.abs(h-f)>=qt-nt)).sort((h,f)=>Math.abs(h-d)-Math.abs(f-d)||h-f);if(l.length===0)return;s.set(a,l[0]),r.push(l[0])}return s}u(ki,"placePortsBesideFixed");function zi(t,e){const o=new Map,n=new Map(["right","bottom","left","top"].map(g=>[g,Zn(t,g)])),i=[...e].sort(Di),r=i.filter(g=>Qt(t,g)),s=i.filter(g=>!Qt(t,g)),a=new Set,c=new Map,d=new Map,l=u(g=>(o.get(g)?.length??0)<(n.get(g)??0),"hasCapacity"),h=u((g,y)=>{const b=o.get(y)??[];b.push(g),o.set(y,b)},"record"),f=u(g=>{const y=pn(t,g).find(l);y&&(h(g,y),a.add(y))},"assignAligned"),m=u((g,y)=>{const b=d.get(y)??new Map,I=ki(t,y,[...c.get(y)??[],...b.values()],[g]);return I?(b.set(g,I.get(g)),d.set(y,b),h(g,y),!0):!1},"tryShareReservedSide"),p=u(g=>{const y=pn(t,g).filter(l),b=y.find(S=>!a.has(S));if(y.find(S=>(b===void 0||y.indexOf(S)<y.indexOf(b))&&a.has(S)&&m(g,S)))return;const C=b??y[0];C&&h(g,C)},"assignUnaligned");for(const g of r)f(g);for(const[g,y]of o)c.set(g,[...Ne(t,g,y).values()]);for(const g of s)p(g);const x=new Map;for(const[g,y]of o){const b=Rt(t,g);if(!b)continue;const I=d.get(g),C=I?y.filter(w=>!I.has(w)):y,S=new Map([...Ne(t,g,C),...I??[]]),v=[...y].sort((w,E)=>Qn(w,E,g));for(const[w,E]of v.entries()){const R=S.get(E)??(v.length===1?(b.low+b.high)/2:b.low+w*(b.high-b.low)/(v.length-1));x.set(Fi(E),{side:g,coordinate:R})}}return x}u(zi,"allocateEndpointSlots");function mn(t,e,o,n,i,r){const s=e==="source"?t.edge.start:t.edge.end,a=e==="source"?t.edge.end:t.edge.start,c=r.forest.nodeById.get(s),d=r.forest.nodeById.get(a);if(!c||!d)throw H("GRID_MISSING_ENDPOINT",`Missing endpoint for edge "${t.edge.id}"`);const l=k(d),h=[],f=new Set,m=n.get(s)?.get(`${t.edge.id}:${e}`),p=i.has(s)&&m!==void 0,x=u((y,b,I)=>{const C=Rt(c,y);if(!C||b<C.low||b>C.high)return;const S=k(c),v=y==="left"||y==="right"?{x:y==="left"?S.left:S.right,y:b}:{x:b,y:y==="top"?S.top:S.bottom},w=`${y}:${gt(v)}`;f.has(w)||(f.add(w),h.push({ownerId:s,side:y,port:v,connect:{x:v.x+(y==="left"?-q:y==="right"?q:0),y:v.y+(y==="top"?-q:y==="bottom"?q:0)},rank:I,onAssignedSide:p?y===m.side:void 0}))},"addCandidate");if(m&&t.bundleSize===1&&x(m.side,m.coordinate,-2),t.bundleSize>1){const y=Ye(c,{x:l.cx,y:l.cy}),b=k(c),I=y==="left"||y==="right"?b.cy:b.cx;x(y,I+t.laneOffset,-1)}const g=[...o.get(s)??[]];for(const y of["right","bottom","left","top"]){if(!Rt(c,y))continue;const I=Ne(c,y,g),C=g.find(R=>R.plan===t&&R.role===e),S=C?I.get(C):void 0;if(S===void 0)continue;const v=k(c),w=y==="left"||y==="right"?{x:y==="left"?v.left:v.right,y:S}:{x:S,y:y==="top"?v.top:v.bottom},E=Math.abs(w.x-l.cx)+Math.abs(w.y-l.cy);x(y,S,E)}return h.sort((y,b)=>y.rank-b.rank||Gt(y.side)-Gt(b.side)),h.forEach((y,b)=>{y.rank=b}),h}u(mn,"endpointCandidates");function Hi(t,e){const o=Ti(t,e),n=new Map,i=new Map;for(const p of o){const x=Ot(p.edge);n.set(x,(n.get(x)??0)+1),p.edge.start&&i.set(p.edge.start,(i.get(p.edge.start)??0)+1),p.edge.end&&p.edge.end!==p.edge.start&&i.set(p.edge.end,(i.get(p.edge.end)??0)+1)}const r=o.filter(p=>p.edge.start!==p.edge.end&&p.source.chain.length===1&&p.target.chain.length===1&&p.source.finalKind==="item"&&p.target.finalKind==="item"),s=new Map;for(const p of r){const x=e.forest.nodeById.get(p.edge.start),g=e.forest.nodeById.get(p.edge.end);if(!x||!g)continue;const y=s.get(x.id)??[];y.push({plan:p,role:"source",opposite:g}),s.set(x.id,y);const b=s.get(g.id)??[];b.push({plan:p,role:"target",opposite:x}),s.set(g.id,b)}const a=new Map([...s].map(([p,x])=>{const g=e.forest.nodeById.get(p);return[p,g?zi(g,x):new Map]})),c=new Set,d=new Set;for(const[p,x]of s){const g=e.forest.nodeById.get(p);if(!g)continue;const y=x.some(I=>Qt(g,I)),b=x.some(I=>!Qt(g,I));if(y&&b){d.add(p);for(const I of x)Qt(g,I)||c.add(I.plan.edge.id)}}const l=new Map(r.map(p=>[p.edge.id,{sources:mn(p,"source",s,a,d,e),targets:mn(p,"target",s,a,d,e)}])),h=new Map([...l].map(([p,x])=>[p,x.sources.length*x.targets.length])),f=u(p=>{const x=e.forest.nodeById.get(p.edge.start),g=e.forest.nodeById.get(p.edge.end);return p.edge.start===p.edge.end?0:x?.isGroup&&g&&kt(x.id,g,e.forest.nodeById)||g?.isGroup&&x&&kt(g.id,x,e.forest.nodeById)?1:(x?.parentId??j)!==(g?.parentId??j)?2:n.get(Ot(p.edge))>1?3:4},"routeClass"),m=[...o].sort((p,x)=>{const g=Ot(p.edge),y=Ot(x.edge),b=`${p.edge.start??""}|${p.edge.end??""}`,I=`${x.edge.start??""}|${x.edge.end??""}`,C=p.source.chain.length+p.target.chain.length-2,S=x.source.chain.length+x.target.chain.length-2;return f(p)-f(x)||S-C||(h.get(p.edge.id)??0)-(h.get(x.edge.id)??0)||U(g,y)||U(b,I)||U(p.edge.id,x.edge.id)});return{plans:o,eligiblePlans:r,eligibleIds:new Set(r.map(({edge:p})=>p.id)),orderedPlans:m,demandCoords:Ni(m,e,i),endpointCandidatesByEdge:l,endpointIncidentCounts:i,coordinatedEndpointIds:c}}u(Hi,"prepareEdgeRoutes");function Vi(t){if(!(t instanceof Error)||!("details"in t))return!1;const e=t.details;return typeof e=="object"&&e!==null&&"reason"in e&&e.reason==="pair-separation"}u(Vi,"isPairSeparationError");function Pt(t){const e=k(t);return{left:e.left,right:e.right,top:e.top,bottom:e.bottom}}u(Pt,"routerRect");function Jn(t){if(t.length<2||t.some(({x:i,y:r})=>!Number.isFinite(i)||!Number.isFinite(r)))return;const e=[{...t[0]}];for(let i=1;i<t.length;i++){const r=t[i],s=e.at(-1);if(!(Math.abs(r.x-s.x)<=nt&&Math.abs(r.y-s.y)<=nt)){e.push({...r});continue}if(i===t.length-1){for(;e.length>1;){const c=e.at(-2);if(Math.abs(r.x-c.x)>nt||Math.abs(r.y-c.y)>nt)break;e.pop()}if(e.length===1)return;e[e.length-1]={...r}}}if(e.length<2)return;const o=[];for(let i=0;i<e.length-1;i++){const r=e[i],s=e[i+1],a=Math.abs(s.x-r.x);if(Math.abs(s.y-r.y)<=nt)o.push("H");else if(a<=nt)o.push("V");else return}const n=e.map(i=>({...i}));for(let i=0;i<o.length;){const r=o[i];let s=i+1;for(;s<o.length&&o[s]===r;)s++;const a=r==="H"?"y":"x";if(i===0&&s===e.length-1&&e[i][a]!==e[s][a])return;const c=s===e.length-1?e[s][a]:e[i][a];for(let d=i;d<=s;d++){if(Math.abs(e[d][a]-c)>nt)return;n[d][a]=c}i=s}return n}u(Jn,"canonicalizeOrthogonalPolyline");function ve(t,e,o){return t.y===e.y?t.y>o.top&&t.y<o.bottom&&Math.max(t.x,e.x)>o.left&&Math.min(t.x,e.x)<o.right:t.x===e.x?t.x>o.left&&t.x<o.right&&Math.max(t.y,e.y)>o.top&&Math.min(t.y,e.y)<o.bottom:!0}u(ve,"segmentEntersRect");function to(t){const e=Pt(t);return{left:e.left-V,right:e.right+V,top:e.top-V,bottom:e.bottom+V}}u(to,"inflatedRect");function Et(t,e,o,n,i){const r=Jn(t);if(!r)return!1;const s=z(r);if(s.points.length<2||s.segments.length>1&&(Math.abs(s.segments[0].a.x-s.segments[0].b.x)+Math.abs(s.segments[0].a.y-s.segments[0].b.y)<q||Math.abs(s.segments.at(-1).a.x-s.segments.at(-1).b.x)+Math.abs(s.segments.at(-1).a.y-s.segments.at(-1).b.y)<q))return!1;const a=(i.forest.childrenByParent.get(n)??[]).filter(c=>!pt(c));for(const c of a){const d=to(c);for(let l=0;l<s.points.length-1;l++){if(c.id===e.id&&l===0||c.id===o.id&&l===s.points.length-2){if(ve(s.points[l],s.points[l+1],Pt(c)))return!1;continue}if(ve(s.points[l],s.points[l+1],d))return!1}}return!0}u(Et,"validateSameContainerRoute");function Dt(t,e,o,n,i){const r=Jn(t);if(!r)return!1;const s=z(r);if(s.points.length<2)return!1;const a=(i.forest.childrenByParent.get(n)??[]).filter(c=>!pt(c));for(const c of a){const d=to(c);for(let l=0;l<s.points.length-1;l++){if(c.id===e&&l===0||c.id===o&&l===s.points.length-2){if(ve(s.points[l],s.points[l+1],Pt(c)))return!1;continue}if(ve(s.points[l],s.points[l+1],d))return!1}}return!0}u(Dt,"validateContainerSegment");function yn(t){return t.orientation==="H"?{low:Math.min(t.a.x,t.b.x),high:Math.max(t.a.x,t.b.x)}:{low:Math.min(t.a.y,t.b.y),high:Math.max(t.a.y,t.b.y)}}u(yn,"segmentSpan");function re(t){const e=z([...t]).segments.filter(n=>n.orientation!=="Z").map(n=>({a:{...n.a},b:{...n.b},orientation:n.orientation}));if(e.length===0)return[];if(e.length===1&&Math.abs(e[0].a.x-e[0].b.x)+Math.abs(e[0].a.y-e[0].b.y)<=q*2)return[];const o=u((n,i)=>{if(n.orientation==="H"){const r=Math.sign(n.b.x-n.a.x);i?n.a.x+=r*q:n.b.x-=r*q}else{const r=Math.sign(n.b.y-n.a.y);i?n.a.y+=r*q:n.b.y-=r*q}},"trim");return o(e[0],!0),o(e[e.length-1],!1),e.filter(({a:n,b:i})=>n.x!==i.x||n.y!==i.y)}u(re,"nonterminalSegments");function eo(t,e){if(t.orientation!==e.orientation)return!1;const o=yn(t),n=yn(e),i=Math.max(0,Math.min(o.high,n.high)-Math.max(o.low,n.low));if(i<=0)return!1;const r=t.orientation==="H"?Math.abs(t.a.y-e.a.y):Math.abs(t.a.x-e.a.x);return r===0&&i>=Pe||r>0&&r<Pe}u(eo,"pairSegmentsConflict");function ft(t,e){const o=z([...t]).points,n=[o[0],o.at(-1)],i=re(o);return e.every(r=>{const s=z([...r]).points,a=[s[0],s.at(-1)];return n.some(c=>a.some(d=>c.x===d.x&&c.y===d.y))?!1:i.every(c=>re(s).every(d=>!eo(c,d)))})}u(ft,"routeSatisfiesPairConstraints");function no(t,e){const o=z([...t]).points,n=[o[0],o.at(-1)];return e.every(i=>{const r=z([...i]).points,s=[r[0],r.at(-1)];return!n.some(a=>s.some(c=>a.x===c.x&&a.y===c.y))})}u(no,"routeHasDistinctPairPorts");function qe(t,e,o){const n=t.y===e.y?"H":"V",i={a:t,b:e,orientation:n};return o.every(r=>re(r).every(s=>!eo(i,s)))}u(qe,"pairArcAllowed");function $i(t,e){const o=t.side==="left"||t.side==="right"?"H":"V",n=e.side==="left"||e.side==="right"?"H":"V",i=Math.abs(t.connect.x-e.connect.x),r=Math.abs(t.connect.y-e.connect.y);let s;if(i===0&&r===0)s=+(o!==n);else if(i===0||r===0){const a=i===0?"V":"H";s=+(o!==a)+ +(n!==a)}else s=Math.min(+(o!=="H")+1+ +(n!=="V"),+(o!=="V")+1+ +(n!=="H"));return[q*2+i+r,s]}u($i,"endpointPairLowerBound");function Ki(t,e){if(t.orientation!==e.orientation)return!1;const o=t.orientation==="H",n=u(a=>o?Math.min(a.a.x,a.b.x):Math.min(a.a.y,a.b.y),"lowOf"),i=u(a=>o?Math.max(a.a.x,a.b.x):Math.max(a.a.y,a.b.y),"highOf"),r=Math.min(i(t),i(e))-Math.max(n(t),n(e)),s=Math.abs(o?t.a.y-e.a.y:t.a.x-e.a.x);return r>0&&s<qt}u(Ki,"segmentsTooClose");var xn=class{constructor(){this.lines={H:new Map,V:new Map},this.sortedCoordinates={H:void 0,V:void 0},this.log=[]}static{u(this,"RouteOccupancyIndex")}get size(){return this.log.length}add(t,e){for(const o of re(t)){const n=o.orientation,i=n==="H"?o.a.y:o.a.x,r=this.lines[n].get(i);r?r.push({segment:o,pairKey:e}):(this.lines[n].set(i,[{segment:o,pairKey:e}]),this.sortedCoordinates[n]=void 0),this.log.push({orientation:n,coordinate:i})}}truncate(t){for(;this.log.length>t;){const{orientation:e,coordinate:o}=this.log.pop();this.lines[e].get(o)?.pop()}}conflictsWithRoute(t,e){return re(t).some(o=>this.conflicts(o,e))}conflictsWithArc(t,e,o){const n=t.y===e.y?"H":"V";return this.conflicts({a:t,b:e,orientation:n},o)}conflicts(t,e){const o=t.orientation;if(o!=="H"&&o!=="V")return!1;const n=o==="H"?t.a.y:t.a.x,i=this.coordinatesFor(o);let r=0,s=i.length;for(;r<s;){const a=r+s>>1;i[a]<=n-qt?r=a+1:s=a}for(let a=r;a<i.length;a++){const c=i[a];if(c>=n+qt)break;for(const d of this.lines[o].get(c))if(d.pairKey!==e&&Ki(t,d.segment))return!0}return!1}coordinatesFor(t){return this.sortedCoordinates[t]??=[...this.lines[t].keys()].sort((e,o)=>e-o)}},It=24,ht=18,Ct=14,bo=4,ji=18,oo=4,Jr=64,ts=4;function Ui(t,e,o,n){if(!e.conflictsWithRoute(t,o))return[...t];const i=z([...t]).points;for(let r=1;r<=ts;r++)for(const s of[1,-1]){const a=s*r*Pe;for(let c=1;c<i.length-2;c++){const d=i[c].x===i[c+1].x,l=i.map((h,f)=>f===c||f===c+1?d?{x:h.x+a,y:h.y}:{x:h.x,y:h.y+a}:h);if(!e.conflictsWithRoute(l,o)&&n(l))return l}}}u(Ui,"separateRouteFromOccupied");function Xi(t){const e=u((o,n)=>Math.abs(o.x-n.x)+Math.abs(o.y-n.y),"stub");return e(t[0],t[1])>=q&&e(t.at(-1),t.at(-2))>=q}u(Xi,"terminalStubsAreLongEnough");function Wi(t,e,o,n,i=3){const r=[...n.filter(c=>c>=e&&c<=o).sort((c,d)=>Math.abs(c-t)-Math.abs(d-t)||c-d),(e+o)/2,e,o],s=new Set([t]),a=[];for(const c of r)if(!s.has(c)&&(s.add(c),a.push(c),a.length===i))break;return a}u(Wi,"boundedAlternativePortalCoordinates");function Zt(t,e){return Math.abs(t.x-e.x)<=1e-6&&Math.abs(t.y-e.y)<=1e-6}u(Zt,"equalPoint");function Yi(t,e){return t.x===e.x||t.y===e.y}u(Yi,"areExactlyAxisAligned");function Oe(t,e,o,n){const i=[...t].sort((r,s)=>Math.abs(r-e)+Math.abs(r-o)-(Math.abs(s-e)+Math.abs(s-o))||r-s);return i[Math.min(n,Math.max(0,i.length-1))]??(e+o)/2}u(Oe,"chooseIntermediateCoordinate");function qi(t){const e=[];for(const o of t)(e.length===0||!Zt(e[e.length-1],o))&&e.push(o);return e}u(qi,"dedupeConsecutive");function jt(t,e,o,n,i){const r=e.containers.get(t);if(!r)throw H("GRID_ROUTE_NOT_FOUND",`Missing container layout "${t}"`);const s=[o.port,o.connect];if(o.orientation==="V"&&n.orientation==="V"){if(!Zt(o.connect,n.connect)&&Math.abs(o.connect.x-n.connect.x)>1e-6){const a=Oe(r.horizontalCorridors,o.connect.y,n.connect.y,i);s.push({x:o.connect.x,y:a},{x:n.connect.x,y:a})}else if(!Zt(o.connect,n.connect)&&Math.abs(o.connect.y-n.connect.y)>1e-6&&i>0){const a=r.verticalCorridors.filter(d=>Math.abs(d-o.connect.x)>1e-6),c=Oe(a.length>0?a:r.verticalCorridors,o.connect.x,n.connect.x,i-1);s.push({x:c,y:o.connect.y},{x:c,y:n.connect.y})}}else if(o.orientation==="H"&&n.orientation==="H"){if(!Zt(o.connect,n.connect)&&Math.abs(o.connect.y-n.connect.y)>1e-6){const a=Oe(r.verticalCorridors,o.connect.x,n.connect.x,i);s.push({x:a,y:o.connect.y},{x:a,y:n.connect.y})}}else o.orientation==="V"&&n.orientation==="H"?s.push({x:o.connect.x,y:n.connect.y}):s.push({x:n.connect.x,y:o.connect.y});return s.push(n.connect,n.port),z(qi(s)).points}u(jt,"routeWithinContainer");function Ie(t,e,o,n,i,r,s){const a=i.forest.nodeById.get(t),c=i.itemMeta.get(t);if(!a||!c||c.containerId!==n)throw H("GRID_ROUTE_NOT_FOUND",`Missing item metadata for "${t}" in "${n}"`);const d=k(a),l=s??r.get(o)??(e==="left"||e==="right"?d.cy:d.cx);switch(e){case"left":return{port:{x:d.left,y:l},connect:{x:c.leftCorridorX,y:l},orientation:"V",side:e};case"right":return{port:{x:d.right,y:l},connect:{x:c.rightCorridorX,y:l},orientation:"V",side:e};case"top":return{port:{x:l,y:d.top},connect:{x:l,y:c.topCorridorY},orientation:"H",side:e};case"bottom":return{port:{x:l,y:d.bottom},connect:{x:l,y:c.bottomCorridorY},orientation:"H",side:e}}}u(Ie,"itemAttachment");function io(t,e,o,n,i){const r=n.forest.nodeById.get(t),s=n.containers.get(t);if(!r||!s)throw H("GRID_ROUTE_NOT_FOUND",`Missing boundary metadata for "${t}"`);const a=k(r),c=i.get(o)??(e==="left"||e==="right"?a.cy:a.cx);switch(e){case"left":return{port:{x:a.left,y:c},connect:{x:s.verticalCorridors[0],y:c},orientation:"V",side:e};case"right":return{port:{x:a.right,y:c},connect:{x:s.verticalCorridors[s.verticalCorridors.length-1],y:c},orientation:"V",side:e};case"top":return{port:{x:c,y:a.top},connect:{x:c,y:s.horizontalCorridors[0]},orientation:"H",side:e};case"bottom":return{port:{x:c,y:a.bottom},connect:{x:c,y:s.horizontalCorridors[s.horizontalCorridors.length-1]},orientation:"H",side:e}}}u(io,"boundaryAttachment");function Qi(t){return{x:(t.interior.x+t.exterior.x)/2,y:(t.interior.y+t.exterior.y)/2}}u(Qi,"portalBoundaryPoint");function Wt(t,e){return{ownerId:t.ownerId,port:Qi(t),connect:e?t.interior:t.exterior,orientation:t.side==="left"||t.side==="right"?"V":"H",side:t.side}}u(Wt,"portalAttachment");function bn(t,e,o,n,i){const r=n.forest.nodeById.get(t);if(!r?.isGroup)throw H("GRID_ROUTE_NOT_FOUND",`Missing group endpoint "${t}"`);const s=k(r),a=i.get(o)??(e==="left"||e==="right"?s.cy:s.cx),c=e==="left"||e==="right"?{x:e==="left"?s.left:s.right,y:a}:{x:a,y:e==="top"?s.top:s.bottom};return{ownerId:t,port:c,connect:{x:c.x+(e==="left"?q:e==="right"?-q:0),y:c.y+(e==="top"?q:e==="bottom"?-q:0)},orientation:e==="left"||e==="right"?"V":"H",side:e}}u(bn,"groupBoundaryEndpointAttachment");function Zi(t){return[...t].reverse()}u(Zi,"reversePoints");function Ji(t){const e=[];for(const o of t)for(const n of o)(e.length===0||!Zt(e[e.length-1],n))&&e.push(n);return z(e).points}u(Ji,"combinePointChains");function tr(t,e,o,n){const i=k(t),r=Ct+(o+1)*ji,s=o*oo;switch(e){case"right":{const a=n-ht/2-s,c=n+ht/2+s;return z([{x:i.right,y:a},{x:i.right+Ct,y:a},{x:i.right+r,y:a},{x:i.right+r,y:c},{x:i.right+Ct,y:c},{x:i.right,y:c}]).points}case"left":{const a=n-ht/2-s,c=n+ht/2+s;return z([{x:i.left,y:a},{x:i.left-Ct,y:a},{x:i.left-r,y:a},{x:i.left-r,y:c},{x:i.left-Ct,y:c},{x:i.left,y:c}]).points}case"top":{const a=n-ht/2-s,c=n+ht/2+s;return z([{x:a,y:i.top},{x:a,y:i.top-Ct},{x:a,y:i.top-r},{x:c,y:i.top-r},{x:c,y:i.top-Ct},{x:c,y:i.top}]).points}case"bottom":{const a=n-ht/2-s,c=n+ht/2+s;return z([{x:a,y:i.bottom},{x:a,y:i.bottom+Ct},{x:a,y:i.bottom+r},{x:c,y:i.bottom+r},{x:c,y:i.bottom+Ct},{x:c,y:i.bottom}]).points}}}u(tr,"routeSelfLoop");function ro(t,e,o,n,i){const r=k(t),s=Ct+(o+1)*ji,a=o*oo,c=ht+a*2,d=e==="left"||e==="right",l=Math.max(c,(d?i.cross:i.along)+$t*2+Bo),h=Math.max(s,(d?i.along:i.cross)/2+$t),f=d?[r.top,r.bottom]:[r.left,r.right],m=n-l/2,p=n+l/2;if(m-f[0]>=bo&&f[1]-p>=bo)switch(e){case"right":return[z([{x:r.right,y:m},{x:r.right+h,y:m},{x:r.right+h,y:p},{x:r.right,y:p}]).points];case"left":return[z([{x:r.left,y:m},{x:r.left-h,y:m},{x:r.left-h,y:p},{x:r.left,y:p}]).points];case"top":return[z([{x:m,y:r.top},{x:m,y:r.top-h},{x:p,y:r.top-h},{x:p,y:r.top}]).points];case"bottom":return[z([{x:m,y:r.bottom},{x:m,y:r.bottom+h},{x:p,y:r.bottom+h},{x:p,y:r.bottom}]).points]}const x=n-ht/2-a,g=n+ht/2+a;if(x<f[0]||g>f[1])return[];const y=n-l/2,b=n+l/2,I=Math.max(Ct,q),C=Math.max(h,I+(d?i.along:i.cross)/2+$t);switch(e){case"right":return[z([{x:r.right,y:x},{x:r.right+I,y:x},{x:r.right+I,y},{x:r.right+C,y},{x:r.right+C,y:b},{x:r.right+I,y:b},{x:r.right+I,y:g},{x:r.right,y:g}]).points];case"left":return[z([{x:r.left,y:x},{x:r.left-I,y:x},{x:r.left-I,y},{x:r.left-C,y},{x:r.left-C,y:b},{x:r.left-I,y:b},{x:r.left-I,y:g},{x:r.left,y:g}]).points];case"top":return[z([{x,y:r.top},{x,y:r.top-I},{x:y,y:r.top-I},{x:y,y:r.top-C},{x:b,y:r.top-C},{x:b,y:r.top-I},{x:g,y:r.top-I},{x:g,y:r.top}]).points];case"bottom":return[z([{x,y:r.bottom},{x,y:r.bottom+I},{x:y,y:r.bottom+I},{x:y,y:r.bottom+C},{x:b,y:r.bottom+C},{x:b,y:r.bottom+I},{x:g,y:r.bottom+I},{x:g,y:r.bottom}]).points]}}u(ro,"labelAwareSelfLoopCandidates");function so(t,e,o){return(t.isGroup&&We(t)?["left","right","bottom"]:["left","right","top","bottom"]).sort((i,r)=>{const s=(e.get(oe(t.id,i))??0)+(o.get(`${t.id}:${i}`)??0),a=(e.get(oe(t.id,r))??0)+(o.get(`${t.id}:${r}`)??0);return s-a})}u(so,"orderedSelfLoopSides");function er(t,e){const o=[];for(const n of e.forest.nodeById.values())if(n.id!==t.id&&!n.isGroup&&n.x!==void 0&&n.y!==void 0&&o.push(k(n)),n.id!==t.id&&n.groupTitleRect){const{left:i,right:r,top:s,bottom:a}=n.groupTitleRect;o.push({cx:(i+r)/2,cy:(s+a)/2,left:i,right:r,top:s,bottom:a})}return o}u(er,"selfLoopObstacles");function nr(t,e,o,n,i,r){const s=k(t),a=er(t,n);for(const c of so(t,e,o)){const d=`${t.id}:${c}`,l=o.get(d)??0,h=c==="left"||c==="right"?s.cy:s.cx,f=i?ro(t,c,l,h,i):[tr(t,c,l,h)];i&&r&&(r.labelAwareSelfLoopCandidates+=f.length);for(const m of f)if(!a.some(p=>bt(m,p)))return{points:m,side:c,index:l}}throw H("GRID_ROUTE_NOT_FOUND",`No obstacle-clear self-loop route for "${t.id}"`,{nodeId:t.id})}u(nr,"routeObstacleClearSelfLoop");function or(t){if(t.containers.has(j))return;let e=0,o=0,n=0,i=0,r=!0;for(const c of t.itemMeta.values())c.containerId===j&&(r?(e=c.cellLeft,o=c.cellLeft+c.cellWidth,n=c.cellTop,i=c.cellTop+c.cellHeight,r=!1):(e=Math.min(e,c.cellLeft),o=Math.max(o,c.cellLeft+c.cellWidth),n=Math.min(n,c.cellTop),i=Math.max(i,c.cellTop+c.cellHeight)));const s=new Set([n-It,i+It]),a=new Set([e-It,o+It]);for(const c of t.itemMeta.values())c.containerId===j&&(s.add(c.topCorridorY),s.add(c.bottomCorridorY),a.add(c.leftCorridorX),a.add(c.rightCorridorX));t.containers.set(j,{id:j,left:e-It,top:n-It,width:o-e+It*2,height:i-n+It*2,contentLeft:e,contentTop:n,contentRight:o,contentBottom:i,verticalCorridors:[...a].sort((c,d)=>c-d),horizontalCorridors:[...s].sort((c,d)=>c-d)})}u(or,"rootContainerMeta");function ir(t,e){const o=e.containers.get(t);if(!o)throw H("GRID_ROUTE_NOT_FOUND",`Missing container layout "${t}"`);if(t===j){const r=[...e.itemMeta.values()].filter(({containerId:s})=>s===j);return r.length>0?{left:Math.min(...r.map(({cellLeft:s})=>s))-It,right:Math.max(...r.map(({cellLeft:s,cellWidth:a})=>s+a))+It,top:Math.min(...r.map(({cellTop:s})=>s))-It,bottom:Math.max(...r.map(({cellTop:s,cellHeight:a})=>s+a))+It}:{left:o.left,right:o.left+o.width,top:o.top,bottom:o.top+o.height}}const n=e.forest.nodeById.get(t);if(!n)throw H("GRID_ROUTE_NOT_FOUND",`Missing container owner "${t}"`);const i=Pt(n);return{left:i.left+V,right:i.right-V,top:i.top+V,bottom:i.bottom-V}}u(ir,"containerBounds");function wn(t,e,o){return(e==="left"?t.left:e==="right"?t.right:e==="top"?t.top:t.bottom)+(e==="left"||e==="top"?1:-1)*V*(o?1:-1)}u(wn,"portalCoordinate");function rr(t,e){const o=[];if(t!==j){const n=e.forest.nodeById.get(t);if(n){const i=Pt(n);o.push(...ne(t,i,n.groupTitleRect).map(r=>({...r,coordinate:wn(i,r.side,!0)})))}}for(const n of e.forest.childrenByParent.get(t)??[]){if(!n.isGroup)continue;const i=Pt(n);o.push(...ne(n.id,i,n.groupTitleRect).map(r=>({...r,coordinate:wn(i,r.side,!1)})))}return o}u(rr,"containerPortalRanges");function sr(t,e,o,n){const i={topologies:new Map,fallbackContainers:new Map,searchBudget:{expandedStates:0},searchBudgetWarningEmitted:!1,baseEstimatedBytes:0,metrics:o};let r=0;for(const s of[...new Set(t)].sort()){const a=(e.forest.childrenByParent.get(s)??[]).filter(d=>!pt(d)),c=e.forest.nodeById.get(s)?.groupTitleRect;try{const d=Li({containerId:s,bounds:ir(s,e),obstacles:a.map(h=>({id:h.id,bounds:Pt(h)})),titleExclusions:c?[{id:`${s}:title`,bounds:{...c}}]:void 0,portalRanges:rr(s,e)},{caps:n.topologyCaps}),l=n.topologyCaps?.maxEstimatedBytes??zt;if(r+d.estimatedBytes>l){i.fallbackContainers.set(s,"estimated_memory_cap");continue}r+=d.estimatedBytes,i.baseEstimatedBytes=r,i.topologies.set(s,d),o&&(o.containersBuilt++,o.baseTopologyBuilds++,o.baseVertices+=d.vertices.length,o.baseAdjacencyEntries+=d.adjacencyEntries,o.buildSweepEvents+=d.seedCount*4+d.obstacles.length*4,o.estimatedBytes=r)}catch(d){if(!(d instanceof Lt))throw d;i.fallbackContainers.set(s,d.reason)}}return i}u(sr,"buildRoutingContext");function vn(t,e,o,n,i,r,s){const a=i();if(s&&s.compatibilitySegments++,Dt(a,o.ownerId,n.ownerId,e,r))return a;throw s&&(s.compatibilityValidationFailures++,s.routesImpossible++),H("GRID_ROUTE_NOT_FOUND",`Invalid compatibility route for "${t}"`,{edgeId:t,containerId:e})}u(vn,"validatedCompatibilitySegment");function Me(t,e,o){const n=t.source.chain.at(-1),i=t.target.chain.at(-1),r=u((s,a)=>({ownerId:a.ownerId,...s.finalKind==="boundary"?io(t.lcaContainerId,a.side,a.demandKey,e,o):Ie(a.ownerId,a.side,a.demandKey,t.lcaContainerId,e,o)}),"finalAttachment");return{start:r(t.source,n),end:r(t.target,i)}}u(Me,"compatibilityLcaAttachments");function ao(t,e,o){return t.chain.slice(0,-1).map((n,i)=>{const r=t.chain[i+1];return{containerId:r.ownerId,start:{ownerId:n.ownerId,...Ie(n.ownerId,n.side,n.demandKey,r.ownerId,e,o)},end:{ownerId:r.ownerId,...io(r.ownerId,r.side,r.demandKey,e,o)}}})}u(ao,"compatibilityHierarchyAttachments");function ar(t,e,o){const n=u((r,s,a)=>Dt(jt(r,e,s,a,t.laneIndex),s.ownerId,a.ownerId,r,e),"segmentIsValid");for(const r of[t.source,t.target])for(const{containerId:s,start:a,end:c}of ao(r,e,o))if(!n(s,a,c))return!1;const i=Me(t,e,o);return n(t.lcaContainerId,i.start,i.end)}u(ar,"compatibilityPlanIsValid");function cr(t,e,o,n){const{plans:i,eligiblePlans:r,eligibleIds:s,demandCoords:a,endpointCandidatesByEdge:c,endpointIncidentCounts:d,coordinatedEndpointIds:l}=t,h=u(w=>(d.get(w.edge.start)??0)===w.bundleSize&&(d.get(w.edge.end)??0)===w.bundleSize,"hasIsolatedEndpoints"),f=u(w=>{const E=e.forest.nodeById.get(w.edge.start),R=e.forest.nodeById.get(w.edge.end);return!!(E&&R&&(E.isGroup&&kt(E.id,R,e.forest.nodeById)||R.isGroup&&kt(R.id,E,e.forest.nodeById)))},"hasAncestorEndpoint"),m=new Map,p=new Map,x=i.length<=Jr,g=n.topologyCaps===void 0&&n.searchCaps===void 0&&n.onDualRouteComparison===void 0;for(const w of g?r:[]){if(l.has(w.edge.id))continue;const E=c.get(w.edge.id);if(w.bundleSize!==1||!E?.sources.length||!E.targets.length)continue;const R=e.forest.nodeById.get(w.edge.start),M=e.forest.nodeById.get(w.edge.end);if(!R||!M)continue;const A=Me(w,e,a),L=jt(w.lcaContainerId,e,A.start,A.end,w.laneIndex),B=z(L),T=B.points[0],G=B.points.at(-1);if(!T||!G)continue;const X=E.sources.find(({port:Q})=>Q.x===T.x&&Q.y===T.y),W=E.targets.find(({port:Q})=>Q.x===G.x&&Q.y===G.y);if(!X||!W)continue;o&&o.compatibilityFastPathAttempts++;const F=Math.abs(T.x-G.x)+Math.abs(T.y-G.y);if(!Et(L,R,M,w.lcaContainerId,e)){o&&o.compatibilityFastPathValidationFailures++;continue}if(ee(B.points)!==F){o&&o.compatibilityFastPathNonMinimalRoutes++;continue}let Y=p.get(w.lcaContainerId);if(Y||(Y=new xn,p.set(w.lcaContainerId,Y)),Y.conflictsWithRoute(B.points,w.pairKey)&&x)continue;const D=Ui(B.points,Y,w.pairKey,Q=>Xi(Q)&&ee(Q)===F&&Et(Q,R,M,w.lcaContainerId,e))??L;Y.add(D,w.pairKey),m.set(w.edge.id,D)}const y=u(w=>!s.has(w.edge.id)&&w.edge.start!==w.edge.end&&(w.bundleSize>1||h(w)||!ar(w,e,a)),"sparseCandidate"),b=new Map,I=new Set;if(x)for(const w of t.orderedPlans){if(s.has(w.edge.id)||w.edge.start===w.edge.end||f(w)||y(w))continue;const E=Me(w,e,a),R=jt(w.lcaContainerId,e,E.start,E.end,w.laneIndex);let M=b.get(w.lcaContainerId);M||(M=new xn,b.set(w.lcaContainerId,M)),M.conflictsWithRoute(R,w.pairKey)?I.add(w.edge.id):M.add(R,w.pairKey)}const C=new Set([...i.filter(y).map(({edge:w})=>w.id),...I]),S=new Set([...C,...i.filter(f).map(({edge:w})=>w.id)]),v=i.filter(w=>s.has(w.edge.id)&&!m.has(w.edge.id)||S.has(w.edge.id)||w.edge.start===w.edge.end).flatMap(w=>[w.lcaContainerId,...w.source.chain.slice(1).map(({ownerId:E})=>E),...w.target.chain.slice(1).map(({ownerId:E})=>E)]);return{overlapAvoidanceEnabled:x,compatibilityFastRoutes:m,sparseHierarchyIds:C,sparseLcaIds:S,routedContainerIds:v,routeOccupancy:p}}u(cr,"prepareRoutingModes");var wo={containersBuilt:"cumulative",baseTopologyBuilds:"cumulative",baseVertices:"cumulative",baseAdjacencyEntries:"cumulative",buildSweepEvents:"cumulative",endpointOverlayBuilds:"cumulative",endpointOverlayVertices:"cumulative",hierarchyPortalPairs:"transactional",hierarchyPortalTransitionLength:"transactional",hierarchyPortalAlternativeAttempts:"cumulative",hierarchyPortalAlternativeSelections:"transactional",hierarchyBoundaryTransitions:"transactional",labelOverlayBuilds:"cumulative",labelOverlayVertices:"cumulative",labelSpacingEdgesExamined:"cumulative",labelSpacingEligibleEdges:"cumulative",labelSpacingBoundariesExpanded:"cumulative",labelSpacingPixelsAdded:"cumulative",labelAwareSelfLoopCandidates:"cumulative",labelAwareSelfLoopsCommitted:"transactional",labelAwareSelfLoopFallbacks:"cumulative",searches:"cumulative",expandedStates:"cumulative",maxOpenSet:"cumulative",routesFound:"transactional",routesImpossible:"transactional",resourceLimitFallbacks:"cumulative",fallbackReasons:"cumulative",fallbackValidationFailures:"cumulative",compatibilitySegments:"transactional",compatibilityFastPathAttempts:"cumulative",compatibilityFastPaths:"cumulative",compatibilityFastPathValidationFailures:"cumulative",compatibilityFastPathNonMinimalRoutes:"cumulative",compatibilityRecoveries:"transactional",compatibilityValidationFailures:"cumulative",bundleSeparationRelaxations:"transactional",routeLength:"transactional",bendCount:"transactional",crossingCount:"transactional",sharedLength:"transactional",estimatedBytes:"cumulative",searchWorkspaceBytes:"cumulative",routeOrder:"transactional",routes:"transactional"},es=Object.keys(wo).filter(t=>wo[t]==="transactional"&&t!=="routeOrder"&&t!=="routes");function dr(t){return{routeOrderLength:t.routeOrder.length,routesLength:t.routes.length,values:Object.fromEntries(es.map(e=>[e,t[e]]))}}u(dr,"createGridRoutingInstrumentationCheckpoint");function lr(t,e){t.routeOrder.length=e.routeOrderLength,t.routes.length=e.routesLength,Object.assign(t,e.values)}u(lr,"restoreGridRoutingInstrumentationCheckpoint");function In(t,e,o,n){return Math.max(0,Math.min(Math.max(t,e),Math.max(o,n))-Math.max(Math.min(t,e),Math.min(o,n)))}u(In,"intervalOverlap");function ur(t,e){const o=z(t).segments,n=z(e).segments;let i=0;for(const r of o)for(const s of n)r.orientation===s.orientation&&(r.orientation==="H"&&r.a.y===s.a.y?i+=In(r.a.x,r.b.x,s.a.x,s.b.x):r.orientation==="V"&&r.a.x===s.a.x&&(i+=In(r.a.y,r.b.y,s.a.y,s.b.y)));return i}u(ur,"sharedSegmentLength");function Mn(t,e,o,n,i=0,r=0){const s=z(o);let a=0,c=0;for(const l of n){const h=z(l).segments;for(const f of s.segments)for(const m of h)Bn(f,m)&&a++;c+=ur(s.points,l)}const d={edgeId:e,routeOrder:t.routes.length,laneOffset:r,routeLength:ee(s.points),bendCount:s.bends,crossingCount:a,sharedLength:c,boundaryTransitionCount:i,routeSignature:JSON.stringify(s.points)};t.routeOrder.push(e),t.routes.push(d),t.routesFound++,t.routeLength+=d.routeLength,t.bendCount+=d.bendCount,t.crossingCount+=d.crossingCount,t.sharedLength+=d.sharedLength,t.hierarchyBoundaryTransitions+=i}u(Mn,"recordGridRoute");var hr=1e5,fr=2e6,gr=class{constructor(){this.stateVertices=new Int32Array(256),this.orientations=new Uint8Array(256),this.gLengths=new Float64Array(256),this.gBends=new Float64Array(256),this.gBoundaryTransitions=new Float64Array(256),this.fLengths=new Float64Array(256),this.fBends=new Float64Array(256),this.predecessors=new Int32Array(256),this.depths=new Int32Array(256),this.ancestor4=new Int32Array(256),this.best=new Int32Array(256),this.heapChildren=new Int32Array(256),this.heapSiblings=new Int32Array(256),this.heapPairs=[],this.touchedBestIndices=[],this.best.fill(-1)}static{u(this,"RouterSearchWorkspace")}reset(t){const e=t*3;if(this.best.length<e)this.best=new Int32Array(e),this.best.fill(-1);else for(const o of this.touchedBestIndices)this.best[o]=-1;this.touchedBestIndices.length=0,this.heapPairs.length=0}setBest(t,e){this.best[t]<0&&this.touchedBestIndices.push(t),this.best[t]=e}ensureStateCapacity(t){if(this.stateVertices.length>=t)return;const e=Math.max(t,this.stateVertices.length*2);this.stateVertices=yt(this.stateVertices,e),this.orientations=yt(this.orientations,e),this.gLengths=yt(this.gLengths,e),this.gBends=yt(this.gBends,e),this.gBoundaryTransitions=yt(this.gBoundaryTransitions,e),this.fLengths=yt(this.fLengths,e),this.fBends=yt(this.fBends,e),this.predecessors=yt(this.predecessors,e),this.depths=yt(this.depths,e),this.ancestor4=yt(this.ancestor4,e),this.heapChildren=yt(this.heapChildren,e),this.heapSiblings=yt(this.heapSiblings,e)}estimatedBytes(){return this.stateVertices.byteLength+this.orientations.byteLength+this.gLengths.byteLength+this.gBends.byteLength+this.gBoundaryTransitions.byteLength+this.fLengths.byteLength+this.fBends.byteLength+this.predecessors.byteLength+this.depths.byteLength+this.ancestor4.byteLength+this.best.byteLength+this.heapChildren.byteLength+this.heapSiblings.byteLength+(this.heapPairs.length+this.touchedBestIndices.length)*8}};function Se(t){const e=t.caps?.maxExpandedStates??hr,o=t.caps?.maxInvocationExpandedStates??fr,n=t.budget?.expandedStates??t.metrics?.expandedStates??0;if(!(e>0&&n<o))throw new Lt("search_state_cap","Grid routing search-state cap exceeded",n>=o?"invocation":"edge")}u(Se,"assertSearchBudgetAvailable");function yt(t,e){const o=new t.constructor(e);return o.set(t),o}u(yt,"growTypedArray");function Jt(t,e){for(let o=0;o<4;o++){if(t[o]<e[o])return-1;if(t[o]>e[o])return 1}return 0}u(Jt,"compareTupleCost");function Cn(t,e,o,n){return t===0&&e===0?o&&n?+(o!==n):0:t===0?(o?+(o!=="V"):0)+(n?+(n!=="V"):0):e===0?(o?+(o!=="H"):0)+(n?+(n!=="H"):0):Math.min((o?+(o!=="H"):0)+1+(n?+(n!=="V"):0),(o?+(o!=="V"):0)+1+(n?+(n!=="H"):0))}u(Cn,"minimumBends");function me(t){return t===void 0?0:t==="H"?1:2}u(me,"orientationOrdinal");function Sn(t,e,o){return o==="left"?t.y===e.y&&e.x>t.x:o==="right"?t.y===e.y&&e.x<t.x:o==="top"?t.x===e.x&&e.y>t.y:t.x===e.x&&e.y<t.y}u(Sn,"movesTowardOwner");function pr(t,e){return t*3+me(e)}u(pr,"stateIndex");function mr(t){const e=[];for(const o of t){const n=e.at(-1);if(n&&n.x===o.x&&n.y===o.y)continue;const i=e.at(-2);i&&n&&(i.x===n.x&&n.x===o.x||i.y===n.y&&n.y===o.y)?e[e.length-1]={...o}:e.push({...o})}return e}u(mr,"normalizePoints");function En(t,e,o,n,i){const r=[];let s=t;for(;s>=0;)r.push(e[s]),s=o[s];return r.reverse(),{points:mr(r.map(a=>i(a).point)),vertexIds:r,cost:n}}u(En,"reconstruct");function yr(t){for(const e of t.vertices){if(e.id<0||t.vertices[e.id]!==e||!Number.isFinite(e.point.x)||!Number.isFinite(e.point.y))throw new Error("Malformed grid routing vertex");for(const o of t.adjacency.get(e.id)??[]){const n=t.vertices[o.to],i=n&&(o.orientation==="H"?e.point.y===n.point.y:e.point.x===n.point.x),r=n?Math.abs(e.point.x-n.point.x)+Math.abs(e.point.y-n.point.y):Number.NaN;if(o.from!==e.id||!i||!Number.isFinite(o.length)||o.length<=0||o.length!==r)throw new Error("Malformed grid routing arc")}}}u(yr,"validateSearchTopology");function xr(t,e,o,n){const i=u(P=>{const _=t.getVertex?.(P)??t.vertices[P];if(!_)throw new Error(`Missing grid routing vertex ${P}`);return _},"vertexAt"),r=i(e),s=i(o);n.topologyValidated||yr(t);const a=n.metrics;a&&a.searches++,Se(n);const c=n.workspace??new gr;c.reset(t.vertexCount??t.vertices.length);let d=c.stateVertices,l=c.orientations,h=c.gLengths,f=c.gBends,m=c.gBoundaryTransitions,p=c.fLengths,x=c.fBends,g=c.predecessors,y=c.depths,b=c.ancestor4,I=c.heapChildren,C=c.heapSiblings;const S=c.best,v=c.heapPairs;let w=1;const E=n.endpointCandidateRank??0,R=n.heuristic!=="zero";function M(P,_){return d[P]-d[_]||l[P]-l[_]||g[P]-g[_]||P-_}u(M,"nonCostOrder");function A(P,_){return p[P]-p[_]||x[P]-x[_]||m[P]-m[_]||(n.queueOrder==="reverse"?-M(P,_):M(P,_))}u(A,"compareStates");function L(P,_){if(P===_)return 0;if(P<0)return-1;if(_<0)return 1;const at=y[P],ct=y[_];let J=P,$=_;for(;y[J]>y[$];)J=g[J];for(;y[$]>y[J];)$=g[$];if(J===$)return at-ct;for(;b[J]>=0&&b[$]>=0&&b[J]!==b[$];)J=b[J],$=b[$];for(;g[J]!==g[$];)J=g[J],$=g[$];return d[J]-d[$]||l[J]-l[$]}u(L,"compareChains");let B=-1,T=0;function G(P,_){return P<0?_:_<0?P:A(P,_)<=0?(C[_]=I[P],I[P]=_,P):(C[P]=I[_],I[_]=P,_)}u(G,"heapMeld");const X=u(P=>{I[P]=-1,C[P]=-1,B=G(B,P),T++},"heapPush"),W=u(()=>{if(B<0)return;const P=B;v.length=0;let _=I[P];for(;_>=0;){const ct=C[_];C[_]=-1,v.push(_),_=ct}for(let ct=0;ct+1<v.length;ct+=2)v[ct>>>1]=G(v[ct],v[ct+1]);let at=Math.ceil(v.length/2);for(v.length%2!==0&&(v[at-1]=v[v.length-1]),B=-1;at>0;)B=G(v[--at],B);return T--,P},"heapPop");let F=0;const Y=n.caps?.maxExpandedStates??hr,wt=n.caps?.maxInvocationExpandedStates??fr,et=n.budget?.expandedStates??a?.expandedStates??0,D=u(()=>{const P=c.estimatedBytes(),_=(n.estimatedBytesBase??0)+P;if(a&&(a.searchWorkspaceBytes=Math.max(a.searchWorkspaceBytes,P),a.estimatedBytes=Math.max(a.estimatedBytes,_)),_>(n.caps?.maxEstimatedBytes??Number.POSITIVE_INFINITY))throw new Lt("estimated_memory_cap","Grid routing search workspace memory cap exceeded")},"recordWorkspaceBytes");D();const Q=u(()=>{n.budget&&(n.budget.expandedStates+=F),a&&(a.expandedStates+=F)},"commitExpandedStates"),rt=n.initialLength??0;d[0]=e,l[0]=me(n.initialOrientation),h[0]=rt,f[0]=0,m[0]=0;const lt=Math.abs(r.point.x-s.point.x),ot=Math.abs(r.point.y-s.point.y);p[0]=rt+(R?lt+ot:0),x[0]=R?Cn(lt,ot,n.initialOrientation,n.targetOrientation):0,g[0]=-1,y[0]=1,b[0]=-1,c.setBest(pr(e,n.initialOrientation),0),X(0),a&&(a.maxOpenSet=Math.max(a.maxOpenSet,T));let mt=-1,O;const N=u(P=>{const _=[h[P]+(n.targetLength??0),f[P]+(n.targetOrientation!==void 0&&l[P]!==0&&me(n.targetOrientation)!==l[P]?1:0),m[P],E];(!O||Jt(_,O)<0||Jt(_,O)===0&&L(P,mt)<0)&&(mt=P,O=_)},"considerGoal"),st=u((P,_,at,ct,J,$)=>{const Mt=i(at).point;if(n.arcAllowed&&!n.arcAllowed(_,Mt)||n.initialSide&&g[P]<0&&Sn(_,Mt,n.initialSide)||n.targetSide&&at===o&&Sn(s.point,_,n.targetSide))return;const de=at*3+ct,At=S[de],le=h[P]+J,ue=f[P]+(l[P]!==0&&l[P]!==ct?1:0),he=m[P]+$,fe=At>=0?le-h[At]||ue-f[At]||he-m[At]:-1;if(At>=0&&(fe>0||fe===0&&L(P,g[At])>=0))return;const vt=w++;w>d.length&&(c.ensureStateCapacity(w),d=c.stateVertices,l=c.orientations,h=c.gLengths,f=c.gBends,m=c.gBoundaryTransitions,p=c.fLengths,x=c.fBends,g=c.predecessors,y=c.depths,b=c.ancestor4,I=c.heapChildren,C=c.heapSiblings,D()),d[vt]=at,l[vt]=ct,h[vt]=le,f[vt]=ue,m[vt]=he;const co=Math.abs(Mt.x-s.point.x),lo=Math.abs(Mt.y-s.point.y);p[vt]=le+(R?co+lo:0),x[vt]=ue+(R?Cn(co,lo,ct===1?"H":"V",n.targetOrientation):0),g[vt]=P,y[vt]=y[P]+1;const uo=g[P],ho=uo>=0?g[uo]:-1;b[vt]=ho>=0?g[ho]:-1,c.setBest(de,vt),X(vt)},"relaxArc");for(;T>0;){const P=B;if(O&&(p[P]-O[0]||x[P]-O[1]||m[P]-O[2]||E-O[3])>0)break;const _=W();if(S[d[_]*3+l[_]]!==_)continue;if(F>=Y||et+F>=wt){if(mt>=0&&O)return a&&n.recordOutcome!==!1&&a.routesFound++,Q(),En(mt,d,g,O,i);Q();const $=et+F>=wt?"invocation":"edge";throw new Lt("search_state_cap","Grid routing search-state cap exceeded",$)}if(F++,d[_]===o){N(_);continue}const at=d[_],ct=i(at).point,J=t.getSearchArcs?.(at)??t.searchAdjacencyByVertex?.[at];if(J)for(const $ of J)st(_,ct,$.to,$.orientationOrdinal,$.length,$.boundaryTransitions);else for(const $ of t.adjacencyByVertex?.[at]??t.adjacency.get(at)??[])st(_,ct,$.to,me($.orientation),$.length,$.kind==="portal"?1:0);a&&(a.maxOpenSet=Math.max(a.maxOpenSet,T))}if(mt<0||!O){Q(),a&&n.recordOutcome!==!1&&a.routesImpossible++;return}return a&&n.recordOutcome!==!1&&a.routesFound++,Q(),En(mt,d,g,O,i)}u(xr,"search");function Qe(t,e,o,n={}){return xr(t,e,o,n)}u(Qe,"findShortestRoute");var vo="grid-router";function br(t,e,o,n,i){t.metrics&&(t.metrics.resourceLimitFallbacks++,t.metrics.fallbackReasons[e]++),te.debug(vo,"GRID_ROUTING_RESOURCE_FALLBACK",{edgeId:o,containerId:n,reason:e}),e==="search_state_cap"&&i==="invocation"&&!t.searchBudgetWarningEmitted&&(t.searchBudgetWarningEmitted=!0,te.warn(vo,"GRID_ROUTING_INVOCATION_SEARCH_BUDGET_EXHAUSTED",{edgeId:o,containerId:n,expandedStates:t.searchBudget.expandedStates}))}u(br,"recordFallback");function Ut({context:t,reason:e,edgeId:o,containerId:n,searchStateScope:i,route:r,isValid:s,includeContainerIdInError:a}){const c=r();if(br(t,e,o,n,i),s(c))return c;throw t.metrics&&t.metrics.fallbackValidationFailures++,H("GRID_ROUTE_NOT_FOUND",`Invalid legacy fallback for "${o}"`,{edgeId:o,...a?{containerId:n}:{},reason:e})}u(Ut,"runValidatedFallback");function wr(t,e,o,n,i,r,s,a,c,d,l,h,f){const m=a.fallbackContainers.get(t.lcaContainerId);if(m)return Ut({context:a,reason:m,edgeId:t.edge.id,containerId:t.lcaContainerId,route:r,isValid:u(C=>Et(C,n,i,t.lcaContainerId,s)&&(t.bundleSize<=1||ft(C,h)),"isValid")});const p=a.topologies.get(t.lcaContainerId);if(!p)throw H("GRID_ROUTE_NOT_FOUND",`Missing routing topology "${t.lcaContainerId}"`);if(e.length===0||o.length===0)throw a.metrics&&a.metrics.routesImpossible++,H("GRID_ROUTE_NOT_FOUND",t.bundleSize>1?`No distinct lane route for "${t.edge.id}"`:`No legal endpoint candidates for "${t.edge.id}"`,{edgeId:t.edge.id});let x,g;const y=e.flatMap(C=>o.map(S=>{const v=C.rank*o.length+S.rank,[w,E]=$i(C,S);return{sourceCandidate:C,targetCandidate:S,pairRank:v,lowerCost:[w,E,0,v]}})).sort((C,S)=>Jt(C.lowerCost,S.lowerCost)||Gt(C.sourceCandidate.side)-Gt(S.sourceCandidate.side)||Gt(C.targetCandidate.side)-Gt(S.targetCandidate.side)),b=u((C,S="all")=>{const v=t.bundleSize>1||C?(w,E)=>(t.bundleSize<=1||qe(w,E,h))&&!(C&&f.index.conflictsWithArc(w,E,f.pairKey)):void 0;for(const{sourceCandidate:w,targetCandidate:E,pairRank:R,lowerCost:M}of y)if(!(S==="preferred"&&R!==0)&&!(S==="assigned-side"&&(w.onAssignedSide===!1||E.onAssignedSide===!1))){if(x&&Jt(x.result.cost,M)<=0)break;try{Se({metrics:a.metrics,caps:l.searchCaps,budget:a.searchBudget});const A=Xe(p,w.connect,E.connect,a.metrics,d,t.bundleSize>1&&(w.connect.x===E.connect.x||w.connect.y===E.connect.y)?[{x:(w.connect.x+E.connect.x)/2,y:(w.connect.y+E.connect.y)/2}]:[]),L=a.baseEstimatedBytes+A.estimatedBytes-p.estimatedBytes;if(L>(l.topologyCaps?.maxEstimatedBytes??zt))throw new Lt("estimated_memory_cap","Grid routing estimated_memory_cap exceeded");a.metrics&&(a.metrics.estimatedBytes=Math.max(a.metrics.estimatedBytes,L));const B=A.pointVertexIds.get(gt(w.connect)),T=A.pointVertexIds.get(gt(E.connect));if(B===void 0||T===void 0)throw H("GRID_ROUTE_NOT_FOUND",`Endpoint projection is missing from the routing overlay for "${t.edge.id}"`,{edgeId:t.edge.id,containerId:t.lcaContainerId,source:w.connect,target:E.connect});const G=w.side==="left"||w.side==="right"?"H":"V",X=E.side==="left"||E.side==="right"?"H":"V",W=Qe(A,B,T,{metrics:a.metrics,caps:{...l.searchCaps,maxEstimatedBytes:l.searchCaps?.maxEstimatedBytes??l.topologyCaps?.maxEstimatedBytes??zt},endpointCandidateRank:R,recordOutcome:!1,budget:a.searchBudget,initialOrientation:G,initialLength:q,targetOrientation:X,targetLength:q,topologyValidated:!0,workspace:c,estimatedBytesBase:L,arcAllowed:v});if(!W)continue;const F=z([w.port,...W.points,E.port]).points;if(!Et(F,n,i,t.lcaContainerId,s)||t.bundleSize>1&&!ft(F,h)||C&&f.index.conflictsWithRoute(F,f.pairKey))continue;(!x||Jt(W.cost,x.result.cost)<0)&&(x={result:W,points:F},g=void 0)}catch(A){if(!(A instanceof Lt))throw A;if(x)break;g=A;break}}},"searchPairs"),I=f!==void 0&&f.index.size>0;if(f?.prioritizeEndpointCandidates&&(b(I,"preferred"),b(I,"assigned-side")),x||b(I),!x&&!g&&f!==void 0&&f.index.size>0&&b(!1),g)return Ut({context:a,reason:g.reason,edgeId:t.edge.id,containerId:t.lcaContainerId,searchStateScope:g.searchStateScope,route:r,isValid:u(C=>Et(C,n,i,t.lcaContainerId,s)&&(t.bundleSize<=1||ft(C,h)),"isValid")});if(!x)throw a.metrics&&a.metrics.routesImpossible++,H("GRID_ROUTE_NOT_FOUND",t.bundleSize>1?`No distinct lane route for "${t.edge.id}"`:`No cell-aware route for "${t.edge.id}"`,{edgeId:t.edge.id});if(l.onDualRouteComparison){const C=r(),S=z(x.points),v=z(C);l.onDualRouteComparison({edgeId:t.edge.id,sparse:{valid:!0,length:ee(S.points),bends:S.bends},legacy:{valid:Et(C,n,i,t.lcaContainerId,s),length:ee(v.points),bends:v.bends}})}return x.points}u(wr,"sparseSameContainerRoute");function vr(t,e,o){const n=Rt(t,e);if(!n||n.high-n.low<ht)return;const i=k(t),r=(n.low+n.high)/2,s=o*oo,a=[r-ht/2-s,r+ht/2+s];if(a[0]<n.low||a[1]>n.high)return;const c=u(d=>{const l=e==="left"||e==="right"?{x:e==="left"?i.left:i.right,y:d}:{x:d,y:e==="top"?i.top:i.bottom};return{ownerId:t.id,side:e,port:l,connect:{x:l.x+(e==="left"?-q:e==="right"?q:0),y:l.y+(e==="top"?-q:e==="bottom"?q:0)},rank:0}},"candidate");return{start:c(a[0]),target:c(a[1])}}u(vr,"selfLoopAttachments");function Ir(t,e,o,n,i,r,s,a,c,d){const l=e.parentId??j,h=o.labelRequirements.selfLoops.get(t.edge.id),f=n.fallbackContainers.get(l),m=u(()=>nr(e,s,a,o,h,n.metrics),"legacyRoute");if(f){const g=Ut({context:n,reason:f,edgeId:t.edge.id,containerId:l,route:m,isValid:u(y=>Et(y.points,e,e,l,o)&&ft(y.points,c),"isValid")});return h&&n.metrics&&n.metrics.labelAwareSelfLoopsCommitted++,g}const p=n.topologies.get(l);if(!p||!r)throw H("GRID_ROUTE_NOT_FOUND",`Missing routing topology "${l}"`);const x=so(e,s,a);if(h){for(const g of x){const y=a.get(`${e.id}:${g}`)??0,b=k(e),I=g==="left"||g==="right"?b.cy:b.cx,C=ro(e,g,y,I,h);n.metrics&&(n.metrics.labelAwareSelfLoopCandidates+=C.length);for(const S of C)if(Et(S,e,e,l,o)&&ft(S,c))return n.metrics&&n.metrics.labelAwareSelfLoopsCommitted++,{points:S,side:g,index:y}}n.metrics&&n.metrics.labelAwareSelfLoopFallbacks++}for(const g of x){const y=a.get(`${e.id}:${g}`)??0,b=vr(e,g,y);if(!b)continue;const{start:I,target:C}=b;try{Se({metrics:n.metrics,caps:d.searchCaps,budget:n.searchBudget});const S=Xe(p,I.connect,C.connect,n.metrics,r,[{x:(I.connect.x+C.connect.x)/2,y:(I.connect.y+C.connect.y)/2}]),v=S.pointVertexIds.get(gt(I.connect)),w=S.pointVertexIds.get(gt(C.connect));if(v===void 0||w===void 0)throw H("GRID_ROUTE_NOT_FOUND",`Self-loop endpoint projection is missing from the routing overlay for "${t.edge.id}"`,{edgeId:t.edge.id,containerId:l,source:I.connect,target:C.connect,side:g});const E=g==="left"||g==="right"?"H":"V",R=Qe(S,v,w,{metrics:n.metrics,caps:{...d.searchCaps,maxEstimatedBytes:d.searchCaps?.maxEstimatedBytes??d.topologyCaps?.maxEstimatedBytes??zt},recordOutcome:!1,budget:n.searchBudget,initialOrientation:E,initialSide:g,initialLength:q,targetOrientation:E,targetSide:g,targetLength:q,topologyValidated:!0,workspace:i,estimatedBytesBase:n.baseEstimatedBytes+S.estimatedBytes-p.estimatedBytes,arcAllowed:u((A,L)=>qe(A,L,c),"arcAllowed")});if(!R)continue;const M=z([I.port,...R.points,C.port]).points;if(Et(M,e,e,l,o)&&ft(M,c))return{points:M,side:g,index:y}}catch(S){if(!(S instanceof Lt))throw S;const v=Ut({context:n,reason:S.reason,edgeId:t.edge.id,containerId:l,searchStateScope:S.searchStateScope,route:m,isValid:u(w=>Et(w.points,e,e,l,o)&&ft(w.points,c),"isValid")});return h&&n.metrics&&n.metrics.labelAwareSelfLoopsCommitted++,v}}throw n.metrics&&n.metrics.routesImpossible++,H("GRID_ROUTE_NOT_FOUND",`No distinct self-loop route for "${t.edge.id}"`,{edgeId:t.edge.id,nodeId:e.id})}u(Ir,"sparseSelfLoopRoute");function Rn(t,e,o,n,i,r,s,a,c,d,l=[],h=()=>[],f=()=>[],m=!1,p){const x=s.fallbackContainers.get(e);if(x)return Ut({context:s,reason:x,edgeId:t,containerId:e,route:i,isValid:u(v=>Dt(v,o.ownerId,n.ownerId,e,r)&&ft(v,l),"isValid"),includeContainerIdInError:!0});const g=s.topologies.get(e);if(!g||!c)throw H("GRID_ROUTE_NOT_FOUND",`Missing routing topology "${e}"`);const y=[{start:o,end:n,select:[]}];let b=!1;const I=u(()=>{if(b)return;b=!0;const v=f(),w=h();y.push(...w.map(E=>({start:o,end:E.attachment,select:[E.select]})),...v.map(E=>({start:E.attachment,end:n,select:[E.select]})),...v.flatMap(E=>w.map(R=>({start:E.attachment,end:R.attachment,select:[E.select,R.select]}))))},"appendAlternatives"),C=p!==void 0&&p.index.size>0?[!0,!1]:[!1];try{for(const v of C)for(const[w,E]of y.entries()){const R=E.start,M=E.end;if(w>0&&s.metrics&&s.metrics.hierarchyPortalAlternativeAttempts++,Yi(R.connect,M.connect)){const F=z([R.port,R.connect,M.connect,M.port]).points;if(Dt(F,R.ownerId,M.ownerId,e,r)&&ft(F,l)&&!(v&&p.index.conflictsWithRoute(F,p.pairKey))){for(const Y of E.select)Y();return w>0&&s.metrics&&s.metrics.hierarchyPortalAlternativeSelections++,F}}Se({metrics:s.metrics,caps:d.searchCaps,budget:s.searchBudget});const L=Xe(g,R.connect,M.connect,s.metrics,c),B=s.baseEstimatedBytes+L.estimatedBytes-g.estimatedBytes;if(B>(d.topologyCaps?.maxEstimatedBytes??zt))throw new Lt("estimated_memory_cap","Grid routing estimated_memory_cap exceeded");const T=L.pointVertexIds.get(gt(R.connect)),G=L.pointVertexIds.get(gt(M.connect));if(T===void 0||G===void 0){w===0&&I();continue}const X=Qe(L,T,G,{metrics:s.metrics,caps:{...d.searchCaps,maxEstimatedBytes:d.searchCaps?.maxEstimatedBytes??d.topologyCaps?.maxEstimatedBytes??zt},recordOutcome:!1,budget:s.searchBudget,initialOrientation:R.side==="left"||R.side==="right"?"H":"V",initialSide:R.side,initialLength:Math.abs(R.port.x-R.connect.x)+Math.abs(R.port.y-R.connect.y),targetOrientation:M.side==="left"||M.side==="right"?"H":"V",targetSide:M.side,targetLength:Math.abs(M.port.x-M.connect.x)+Math.abs(M.port.y-M.connect.y),topologyValidated:!0,workspace:a,estimatedBytesBase:B,arcAllowed:l.length>0||v?(F,Y)=>(l.length===0||qe(F,Y,l))&&!(v&&p.index.conflictsWithArc(F,Y,p.pairKey)):void 0});if(!X){w===0&&I();continue}const W=z([R.port,...X.points,M.port]).points;if(!Dt(W,R.ownerId,M.ownerId,e,r)||!ft(W,l)||v&&p.index.conflictsWithRoute(W,p.pairKey)){w===0&&I();continue}for(const F of E.select)F();return w>0&&s.metrics&&s.metrics.hierarchyPortalAlternativeSelections++,W}}catch(v){if(!(v instanceof Lt))throw v;return Ut({context:s,reason:v.reason,edgeId:t,containerId:e,searchStateScope:v.searchStateScope,route:i,isValid:u(w=>Dt(w,o.ownerId,n.ownerId,e,r)&&ft(w,l),"isValid"),includeContainerIdInError:!0})}const S=i();if(Dt(S,o.ownerId,n.ownerId,e,r)&&(ft(S,l)||m&&no(S,l)))return s.metrics&&(s.metrics.compatibilitySegments++,s.metrics.compatibilityRecoveries++),S;throw H("GRID_ROUTE_NOT_FOUND",`No hierarchy route for "${t}" in "${e}" from ${gt(o.connect)} to ${gt(n.connect)}`,{edgeId:t,containerId:e})}u(Rn,"sparseContainerSegment");function Mr(t,e,o,n,i,r,s){const a=t[0].pairKey,c=e.get(a),d=[...new Set(t.flatMap(m=>[...m.source.chain,...m.target.chain].map(({demandKey:p})=>p)))],l=new Map,h=new Map;for(const m of d){const p=o.get(m);p&&l.set(m,p);const x=n.get(m);x!==void 0&&h.set(m,x)}const f=s.get(t[0].lcaContainerId);return{pairKey:a,occupancy:f?{index:f,size:f.size}:void 0,pairRoutes:c?[...c]:void 0,demandKeys:d,pairedPortals:l,demandCoords:h,edges:t.map(({edge:m})=>({edge:m,points:m.points,curve:m.curve,cornerRadius:m.cornerRadius})),instrumentedRoutesLength:i?.length,metrics:r?dr(r):void 0}}u(Mr,"createBundleCheckpoint");function Cr(t,e,o,n,i,r){t.occupancy?.index.truncate(t.occupancy.size),t.pairRoutes?e.set(t.pairKey,[...t.pairRoutes]):e.delete(t.pairKey);for(const s of t.demandKeys){const a=t.pairedPortals.get(s);a?o.set(s,a):o.delete(s);const c=t.demandCoords.get(s);c!==void 0?n.set(s,c):n.delete(s)}for(const s of t.edges)s.edge.points=s.points,s.edge.curve=s.curve,s.edge.cornerRadius=s.cornerRadius;i&&t.instrumentedRoutesLength!==void 0&&(i.length=t.instrumentedRoutesLength),r&&t.metrics&&lr(r,t.metrics)}u(Cr,"restoreBundleCheckpoint");var ns=class{constructor(t,e,o,n){this.layout=t,this.result=e,this.metrics=o,this.options=n,this.searchWorkspace=new gr,this.pairedPortals=new Map,this.ownerSideCounts=new Map,this.selfLoopCounts=new Map,this.pairRoutes=new Map,this.routed=!1}static{u(this,"GridEdgeRoutingSession")}route(){if(this.routed)throw new Error("Grid edge routing session can only be run once");this.routed=!0,this.prepare();const t=new Map;for(const e of this.prepared.orderedPlans){const o=t.get(e.pairKey)??[];o.push(e),t.set(e.pairKey,o)}for(const e of t.values())this.routeBundle(e)}prepare(){or(this.result),this.prepared=Hi(this.layout,this.result),this.modes=cr(this.prepared,this.result,this.metrics,this.options),this.routingContext=sr(this.modes.routedContainerIds,this.result,this.metrics,this.options),this.endpointOverlayScratch=new Map([...this.routingContext.topologies].map(([e,o])=>[e,new Ei(o)])),this.instrumentedRoutes=this.metrics?[]:void 0;const t=new Set;for(const e of this.prepared.orderedPlans)if(e.edge.start!==e.edge.end)for(const o of[...e.source.chain,...e.target.chain]){if(t.has(o.demandKey))continue;t.add(o.demandKey);const n=oe(o.ownerId,o.side);this.ownerSideCounts.set(n,(this.ownerSideCounts.get(n)??0)+1)}}pairedPortal(t){const e=this.pairedPortals.get(t.demandKey);if(e)return e;const o=this.result.forest.nodeById.get(t.ownerId);if(!o?.isGroup)throw H("GRID_ROUTE_NOT_FOUND",`Missing portal owner "${t.ownerId}"`);const n=Pt(o),i=this.prepared.demandCoords.get(t.demandKey)??(t.side==="left"||t.side==="right"?(n.top+n.bottom)/2:(n.left+n.right)/2),r=ne(t.ownerId,n,o.groupTitleRect).find(({side:a})=>a===t.side);if(!r)throw H("GRID_ROUTE_NOT_FOUND",`No legal ${t.side} portal for "${t.ownerId}"`);const s=hn(t.ownerId,n,o.groupTitleRect?{...o.groupTitleRect}:void 0,t.side,Bt(i,r.low,r.high));return this.pairedPortals.set(t.demandKey,s),this.metrics&&(this.metrics.hierarchyPortalPairs++,this.metrics.hierarchyPortalTransitionLength+=s.transition.length),s}alternativePairedPortals(t,e=!0){const o=this.pairedPortal(t),n=this.result.forest.nodeById.get(t.ownerId);if(!n?.isGroup)return[];const i=Pt(n),r=ne(t.ownerId,i,n.groupTitleRect).find(({side:c})=>c===t.side);if(!r)return[];const s=this.result.containers.get(n.id),a=t.side==="left"||t.side==="right"?s?.horizontalCorridors:s?.verticalCorridors;return Wi(o.tangentialCoordinate,r.low,r.high,a??[]).map(c=>{const d=hn(t.ownerId,i,n.groupTitleRect?{...n.groupTitleRect}:void 0,t.side,c);return{attachment:Wt(d,e),select:u(()=>{this.pairedPortals.set(t.demandKey,d),this.prepared.demandCoords.set(t.demandKey,c)},"select")}})}itemSegmentAttachment(t,e){return{ownerId:t.ownerId,...Ie(t.ownerId,t.side,t.demandKey,e,this.result,this.prepared.demandCoords)}}alternativeItemAttachments(t,e,o){const n=this.itemSegmentAttachment(e,o),i=this.result.forest.nodeById.get(e.ownerId);return i?["right","bottom","left","top"].filter(r=>r!==n.side&&!(r==="top"&&We(i))).map(r=>{const s=Rt(i,r);if(!s)return;const a=k(i),c=r==="left"||r==="right"?a.cy:a.cx,d=Math.max(s.low,Math.min(s.high,c+t.laneOffset));return{ownerId:e.ownerId,...Ie(e.ownerId,r,e.demandKey,o,this.result,this.prepared.demandCoords,d)}}).filter(r=>r!==void 0).slice(0,3).map(r=>({attachment:r,select:u(()=>{},"select")})):[]}routePlan(t,e=!0){const o=this.result,n=this.routingContext,i=this.searchWorkspace,r=this.endpointOverlayScratch,s=this.prepared.demandCoords,a=this.ownerSideCounts,c=this.selfLoopCounts,d=this.pairRoutes,l=this.instrumentedRoutes,h=this.metrics,f=this.options,m=this.prepared.eligibleIds,p=this.prepared.endpointCandidatesByEdge,x=this.modes.compatibilityFastRoutes,g=this.modes.sparseHierarchyIds,y=this.modes.sparseLcaIds,b=t.edge,I=b.start?o.forest.nodeById.get(b.start):void 0,C=b.end?o.forest.nodeById.get(b.end):void 0;if(!I||!C)throw H("GRID_MISSING_ENDPOINT",`Missing endpoint for edge "${b.id}"`,{edgeId:b.id});if(I.id===C.id){const D=d.get(t.pairKey)??[],{points:Q,side:rt,index:lt}=Ir(t,I,o,n,i,r.get(I.parentId??j),a,c,D,f),ot=`${I.id}:${rt}`;c.set(ot,lt+1),b.points=Q,b.curve=o.config.curve,b.cornerRadius=o.config.edgeCornerRadius,D.push(Q),d.set(t.pairKey,D),h&&l&&(Mn(h,b.id,Q,l,0,t.laneOffset),l.push(Q));return}const S=t.source.chain[t.source.chain.length-1],v=t.target.chain[t.target.chain.length-1],w=y.has(b.id),E=w?void 0:Me(t,o,s),R=E?E.start:t.source.finalKind==="boundary"?bn(S.ownerId,S.side,S.demandKey,o,s):t.source.chain.length>1?Wt(this.pairedPortal(S),!1):this.itemSegmentAttachment(S,t.lcaContainerId),M=E?E.end:t.target.finalKind==="boundary"?bn(v.ownerId,v.side,v.demandKey,o,s):t.target.chain.length>1?Wt(this.pairedPortal(v),!1):this.itemSegmentAttachment(v,t.lcaContainerId);let A;const L=u(()=>A??=jt(t.lcaContainerId,o,R,M,t.laneIndex),"legacyRoute"),B=x.get(b.id),T=B?(h&&h.compatibilityFastPaths++,B):m.has(b.id)?wr(t,p.get(b.id).sources,p.get(b.id).targets,I,C,L,o,n,i,r.get(t.lcaContainerId),f,d.get(t.pairKey)??[],{index:this.occupancyFor(t.lcaContainerId),pairKey:t.pairKey,prioritizeEndpointCandidates:this.prepared.coordinatedEndpointIds.has(b.id)}):w?Rn(b.id,t.lcaContainerId,R,M,L,o,n,i,r.get(t.lcaContainerId),f,d.get(t.pairKey)??[],()=>t.target.finalKind==="item"&&t.target.chain.length>1?this.alternativePairedPortals(v,!1):[],()=>t.source.finalKind==="item"&&t.source.chain.length>1?this.alternativePairedPortals(S,!1):[],t.bundleSize>1,this.modes.overlapAvoidanceEnabled?{index:this.occupancyFor(t.lcaContainerId),pairKey:t.pairKey}:void 0):vn(b.id,t.lcaContainerId,R,M,L,o,h),G=u((D,Q)=>{if(!g.has(b.id)){for(const{containerId:rt,start:lt,end:ot}of ao(D,o,s))Q.push(vn(b.id,rt,lt,ot,()=>jt(rt,o,lt,ot,t.laneIndex),o,h));return}for(let rt=0;rt<D.chain.length-1;rt++){const lt=D.chain[rt],ot=D.chain[rt+1],mt=rt===0?this.itemSegmentAttachment(lt,ot.ownerId):Wt(this.pairedPortal(lt),!1),O=Wt(this.pairedPortal(ot),!0);Q.push(Rn(b.id,ot.ownerId,mt,O,()=>jt(ot.ownerId,o,mt,O,t.laneIndex),o,n,i,r.get(ot.ownerId),f,d.get(t.pairKey)??[],()=>this.alternativePairedPortals(ot),()=>rt===0?this.alternativeItemAttachments(t,lt,ot.ownerId):[],t.bundleSize>1))}},"routeHierarchyChain"),X=[],W=[];G(t.source,X),G(t.target,W);const F=Ji([...X,T,...W.reverse().map(D=>Zi(D))]),Y=d.get(t.pairKey)??[],wt=ft(F,Y),et=!wt&&t.bundleSize>1&&t.source.chain.length+t.target.chain.length>2&&no(F,Y);if(t.bundleSize>1&&!wt&&(!et||!e))throw h&&h.routesImpossible++,H("GRID_ROUTE_NOT_FOUND",`No distinct lane route for "${b.id}"`,{edgeId:b.id,reason:et?"pair-separation":"no-distinct-route"});if(et&&h&&h.bundleSeparationRelaxations++,b.points=F,b.curve=o.config.curve,b.cornerRadius=o.config.edgeCornerRadius,Y.push(F),d.set(t.pairKey,Y),B||this.occupancyFor(t.lcaContainerId).add(T,t.pairKey),h&&l){const D=t.source.chain.length+t.target.chain.length-2;Mn(h,b.id,F,l,D,t.laneOffset),l.push(F)}}occupancyFor(t){let e=this.modes.routeOccupancy.get(t);return e||(e=new xn,this.modes.routeOccupancy.set(t,e)),e}createBundleCheckpoint(t){return this.occupancyFor(t[0].lcaContainerId),Mr(t,this.pairRoutes,this.pairedPortals,this.prepared.demandCoords,this.instrumentedRoutes,this.metrics,this.modes.routeOccupancy)}restoreBundleCheckpoint(t){Cr(t,this.pairRoutes,this.pairedPortals,this.prepared.demandCoords,this.instrumentedRoutes,this.metrics)}routeBundle(t){if(!(t.length>1&&t.length<=8&&t.every(({edge:i})=>i.start!==i.end))){for(const i of t)this.routePlan(i);return}const o=this.createBundleCheckpoint(t);let n;try{for(const i of t)this.routePlan(i,!1);return}catch(i){n=i,this.restoreBundleCheckpoint(o)}if(!Vi(n))throw n;for(const i of t)this.routePlan(i)}};function Sr(t,e,o,n={}){new ns(t,e,o,n).route()}u(Sr,"routeGridEdges");var os=24,Re=20;function Er(t,e){return!t.label||!t.labelBBox||!(t.labelBBox.height>0)?0:t.labelBBox.height+e}u(Er,"titleBandFor");function Rr(t){if(!Z(t.width)||!Z(t.height))throw H("GRID_MISSING_MEASUREMENT",`Node "${t.id}" must have width and height greater than 0 (width: ${t.width}, height: ${t.height})`,{nodeId:t.id,width:t.width,height:t.height})}u(Rr,"ensureMeasuredNode");function An(t){return Rr(t),{width:t.width,height:t.height}}u(An,"measureChild");function On(t,e,o,n,i){const{forest:r,config:s,sourceOrder:a}=e,c=t===j?void 0:r.groupById.get(t),d=c?Math.max(c.padding??0,s.containerPadding):0,l=c?Er(c,s.titleGap):0,h=c?os:0,f=c?d+l+h:0,m=(r.childrenByParent.get(t)??[]).filter(O=>!pt(O)),{cells:p}=Ci(m,a,s),x=[...p.values()].sort((O,N)=>O.row-N.row||O.column-N.column),g=new Map,y=new Map,b=new Set,I=new Set;for(const O of x){let N=0,st=0;for(const P of O.items){const _=An(P.item);N=Math.max(N,_.width),st+=_.height}O.items.length>1&&(st+=s.cellGap*(O.items.length-1)),O.width=N,O.height=st,b.add(O.row),I.add(O.column),g.set(O.column,Math.max(g.get(O.column)??0,N)),y.set(O.row,Math.max(y.get(O.row)??0,st))}const C=[...b].sort((O,N)=>O-N),S=[...I].sort((O,N)=>O-N),v=pi(e.labelRequirements.byContainer.get(t)??[],p,y,g,C,S,s.rowGap,s.columnGap,i),w=u(O=>Math.max(s.rowGap,v.rowGapAfter.get(O)??0),"rowGapAfter"),E=u(O=>Math.max(s.columnGap,v.columnGapAfter.get(O)??0),"columnGapAfter");if(i){for(const O of v.rowGapAfter.values())O>s.rowGap&&(i.labelSpacingBoundariesExpanded++,i.labelSpacingPixelsAdded+=O-s.rowGap);for(const O of v.columnGapAfter.values())O>s.columnGap&&(i.labelSpacingBoundariesExpanded++,i.labelSpacingPixelsAdded+=O-s.columnGap)}const R=S.reduce((O,N,st)=>O+(g.get(N)??0)+(st<S.length-1?E(N):0),0),M=c?Math.max(R+(d+h)*2,(c.labelBBox?.width??0)+d*2):R,A=c?(M-R)/2:0,L=new Map;let B=A;for(const[O,N]of S.entries())L.set(N,B),B+=(g.get(N)??0)+(O<S.length-1?E(N):0);const T=new Map;let G=f;for(const[O,N]of C.entries())T.set(N,G),G+=(y.get(N)??0)+(O<C.length-1?w(N):0);const X=C.length?G-f:0,W=c?A-Re:-Math.max(s.columnGap/2,xt.containerPadding),F=c?A+R+Re:A+R+Math.max(s.columnGap/2,xt.containerPadding),Y=c?f-Re:-Math.max(s.rowGap/2,xt.containerPadding),wt=c?f+X+Re:f+X+Math.max(s.rowGap/2,xt.containerPadding),et=new Set([W,F]),D=new Set([Y,wt]),Q=new Map,rt=new Map,lt=new Map,ot=new Map;S.length>0&&(Q.set(S[0],W),rt.set(S.at(-1),F));for(let O=0;O<S.length-1;O++){const N=S[O],st=S[O+1],P=(L.get(N)+(g.get(N)??0)+L.get(st))/2;et.add(P),rt.set(N,P),Q.set(st,P)}C.length>0&&(lt.set(C[0],Y),ot.set(C.at(-1),wt));for(let O=0;O<C.length-1;O++){const N=C[O],st=C[O+1],P=(T.get(N)+(y.get(N)??0)+T.get(st))/2;D.add(P),ot.set(N,P),lt.set(st,P)}for(const O of x){const N=L.get(O.column)??A,st=T.get(O.row)??f,P=g.get(O.column)??O.width,_=y.get(O.row)??O.height,at=O.verticalAlign==="top"?0:O.verticalAlign==="bottom"?1:.5;let J=st+(_-O.height)*at;for(const[$,Mt]of O.items.entries()){const{width:de,height:At}=An(Mt.item),le=Mt.horizontalAlign==="left"?0:Mt.horizontalAlign==="right"?1:.5,ue=N+(P-de)*le;Mt.item.x=ue+de/2,Mt.item.y=J+At/2;const he=$>0?J-s.cellGap/2:lt.get(O.row)??Y,fe=$<O.items.length-1?J+At+s.cellGap/2:ot.get(O.row)??wt;$>0&&D.add(he),$<O.items.length-1&&D.add(fe),n.set(Mt.item.id,{containerId:t,row:O.row,column:O.column,cellLeft:N,cellTop:st,cellWidth:P,cellHeight:_,leftCorridorX:Q.get(O.column)??W,rightCorridorX:rt.get(O.column)??F,topCorridorY:he,bottomCorridorY:fe}),J+=At+s.cellGap}}const mt=c?X+l+(d+h)*2:X;o.set(t,{id:t,left:0,top:0,width:M,height:mt,contentLeft:A,contentTop:f,contentRight:c?A+R:R,contentBottom:c?f+X:X,verticalCorridors:[...et].sort((O,N)=>O-N),horizontalCorridors:[...D].sort((O,N)=>O-N)}),c&&(c.width=M,c.height=mt,c.x=M/2,c.y=mt/2,l>0?c.groupTitleRect={left:0,right:M,top:0,bottom:d+l}:delete c.groupTitleRect)}u(On,"layoutContainer");function Ar(t,e,o){return{left:t.left+e,right:t.right+e,top:t.top+o,bottom:t.bottom+o}}u(Ar,"translateRect");function Or(t){const{forest:e,containers:o,itemMeta:n}=t,i=[{containerId:j,offsetX:0,offsetY:0,children:e.childrenByParent.get(j)??[],nextChildIndex:0,entered:!1}];for(;i.length>0;){const r=i[i.length-1];if(!r.entered){r.entered=!0;const c=o.get(r.containerId);c&&(c.left+=r.offsetX,c.top+=r.offsetY,c.contentLeft+=r.offsetX,c.contentRight+=r.offsetX,c.contentTop+=r.offsetY,c.contentBottom+=r.offsetY,c.verticalCorridors=c.verticalCorridors.map(d=>d+r.offsetX),c.horizontalCorridors=c.horizontalCorridors.map(d=>d+r.offsetY))}const s=r.children[r.nextChildIndex];if(!s){i.pop();continue}if(r.nextChildIndex+=1,pt(s))continue;const a=n.get(s.id);a&&(a.cellLeft+=r.offsetX,a.cellTop+=r.offsetY,a.leftCorridorX+=r.offsetX,a.rightCorridorX+=r.offsetX,a.topCorridorY+=r.offsetY,a.bottomCorridorY+=r.offsetY),s.x=(s.x??0)+r.offsetX,s.y=(s.y??0)+r.offsetY,s.isGroup&&(s.groupTitleRect&&(s.groupTitleRect=Ar(s.groupTitleRect,s.x-(s.width??0)/2,s.y-(s.height??0)/2)),i.push({containerId:s.id,offsetX:s.x-(s.width??0)/2,offsetY:s.y-(s.height??0)/2,children:e.childrenByParent.get(s.id)??[],nextChildIndex:0,entered:!1}))}}u(Or,"materializeAbsoluteGeometry");function Br(t,e){const o=new Map(t.nodes.map(i=>[i.id,i]));for(const i of e.nodes){const r=o.get(i.id);r&&(i.x=r.x,i.y=r.y,i.width=r.width,i.height=r.height,r.groupTitleRect?i.groupTitleRect={...r.groupTitleRect}:delete i.groupTitleRect)}const n=new Map(t.edges.map(i=>[i.id,i]));for(const i of e.edges){const r=n.get(i.id);r&&(i.points=r.points?.map(s=>({...s})),i.curve=r.curve,i.cornerRadius=r.cornerRadius,i.portClipping="outline-orthogonal",i.skipCornerFix=r.curve==="linear")}}u(Br,"commitGridGeometry");function Lr(t){return{...t,nodes:t.nodes.map(e=>({...e,labelBBox:e.labelBBox?{...e.labelBBox}:e.labelBBox,groupTitleRect:e.groupTitleRect?{...e.groupTitleRect}:e.groupTitleRect})),edges:t.edges.map(e=>({...e,points:e.points?.map(o=>({...o}))}))}}u(Lr,"cloneGridLayoutData");function Pr(t,e){const o=new Map(e.map(r=>[r.id,r])),n=u(r=>{const s=o.get(r.id);if(!s)throw new Error(`Missing committed grid node "${r.id}"`);return s},"originalNode"),i=u(r=>{const s=n(r);if(!s.isGroup)throw new Error(`Committed grid node "${r.id}" is no longer a group`);return s},"originalGroup");return{nodeById:o,groupById:new Map([...t.groupById].map(([r,s])=>[r,i(s)])),childrenByParent:new Map([...t.childrenByParent].map(([r,s])=>[r,s.map(n)])),rootChildren:t.rootChildren.map(n),postOrderGroups:t.postOrderGroups.map(i),helperNodeIds:new Set(t.helperNodeIds)}}u(Pr,"rebindGridForest");function _r(t,e){const o=ui(t.nodes),n=yi(t),i=mi(t.nodes.filter(s=>!pt(s)));xi(t.nodes.filter(s=>!pt(s)),n);const r={forest:o,config:n,containers:new Map,itemMeta:new Map,sourceOrder:i,labelRequirements:hi(t,o,e.metrics)};for(const s of o.postOrderGroups)On(s.id,r,r.containers,r.itemMeta,e.metrics);return On(j,r,r.containers,r.itemMeta,e.metrics),Or(r),Sr(t,r,e.metrics,e.routing),li(t,void 0,e.metrics),r}u(_r,"runGridLayoutCoreInPlace");function Gr(t,e={}){const o=t,n=Lr(o),i=_r(n,e);return Br(n,o),{...i,forest:Pr(i.forest,o.nodes)}}u(Gr,"runGridLayoutCore");function Tr(t,{measure:e}){const o=Nr(t.config.grid?.lineHops);if(o===!1)return;const n=t.edges.filter(i=>Array.isArray(i.points)&&i.points.length>=2).map(i=>({id:i.id,points:i.points,curve:i.curve,cornerRadius:i.cornerRadius,arrowTypeStart:i.arrowTypeStart,arrowTypeEnd:i.arrowTypeEnd}));Fr(e.groups.edgePaths,n,{enabled:!0,jumpRadius:6,jumpStyle:o})}u(Tr,"applyGridLineJumps");var ls=Dr({prepareLayout:di,runLayoutCore:u(t=>Gr(t),"runLayoutCore"),afterPaint:Tr});export{di as prepareGridLayout,ls as render,Gr as runGridLayoutCore};
1
+ import{n as Nr,a as Fr}from"./chunk-3GCGMST5-Dia9jGkf.js";import{c as Dr}from"./chunk-EBZ3SEQC-C6N5qLCR.js";import{ak as kr,ay as Io,az as Mo,l as te,_ as u,aA as fo}from"./mermaid.core-f4LJm6AC.js";import"./index-Dr6wHi0A.js";import"./vendor-BMCjWFMy.js";import"./graph-D8UmR1vK.js";var nt=1;function Co(t,e,o=nt){const n=Math.abs(e.x-t.x),i=Math.abs(e.y-t.y);return n<=o&&i<=o?"Z":i<=o?"H":"V"}u(Co,"segmentOrientation");function So(t,e=nt){const o=[];for(let n=0;n<t.length-1;n++){const i=t[n],r=t[n+1];o.push({a:i,b:r,orientation:Co(i,r,e)})}return o}u(So,"segmentsFromPoints");function Eo(t,e=nt){if(t.length===0)return[];const o=[];let n={...t[0]};for(let i=1;i<t.length;i++){const r=t[i];if(r.orientation!=="Z"){if(n.orientation==="Z"){n={...r};continue}if(n.orientation===r.orientation){if(n.orientation==="H"&&Math.abs(n.b.y-r.a.y)<=e&&Math.abs(n.a.y-r.a.y)<=e){n.b=r.b;continue}if(n.orientation==="V"&&Math.abs(n.b.x-r.a.x)<=e&&Math.abs(n.a.x-r.a.x)<=e){n.b=r.b;continue}}n.orientation!=="Z"&&o.push(n),n={...r}}}return n.orientation!=="Z"&&o.push(n),o}u(Eo,"mergeCollinear");function z(t,e=nt){if(t.length<2)return{points:[...t],segments:[],bends:0};const o=So(t,e).filter(s=>s.orientation!=="Z"),n=Eo(o,e),i=[];for(const[s,a]of n.entries())s===0&&i.push(a.a),i.push(a.b);let r=0;for(let s=1;s<n.length;s++)n[s-1].orientation!==n[s].orientation&&r++;return{points:i.length>0?i:[...t],segments:n,bends:r}}u(z,"normalizePolyline");function Bn(t,e){if(t.orientation==="Z"||e.orientation==="Z"||t.orientation===e.orientation)return!1;const o=t.orientation==="H"?t:e,n=t.orientation==="V"?t:e,i=o.a.y,r=Math.min(o.a.x,o.b.x),s=Math.max(o.a.x,o.b.x),a=n.a.x,c=Math.min(n.a.y,n.b.y),d=Math.max(n.a.y,n.b.y);if(a>=r&&a<=s&&i>=c&&i<=d){const h=a,f=i,m=Math.abs(h-o.a.x)<1e-6&&Math.abs(f-o.a.y)<1e-6||Math.abs(h-o.b.x)<1e-6&&Math.abs(f-o.b.y)<1e-6,p=Math.abs(h-n.a.x)<1e-6&&Math.abs(f-n.a.y)<1e-6||Math.abs(h-n.b.x)<1e-6&&Math.abs(f-n.b.y)<1e-6;return!(m&&p)}return!1}u(Bn,"segmentsCross");function U(t,e){return t<e?-1:t>e?1:0}u(U,"compareCodeUnits");function k(t){const e=t.x??0,o=t.y??0,n=t.width??40,i=t.height??40;return{cx:e,cy:o,left:e-n/2,right:e+n/2,top:o-i/2,bottom:o+i/2}}u(k,"rectForNode");function Ro(t,e,o,n,i=0){if(t.length<2)return null;const r=e==="end"?t[t.length-1]:t[0],s=e==="end"?t[t.length-2]:t[1],a=s.x-r.x,c=s.y-r.y;if(Math.abs(a)<=i&&Math.abs(c)<=i)return null;if(Math.abs(c)<=i){const d=r.x+Math.sign(a)*o,l=Math.min(r.x,d),h=Math.max(r.x,d);return{cx:(l+h)/2,cy:r.y,left:l,right:h,top:r.y-n,bottom:r.y+n}}if(Math.abs(a)<=i){const d=r.y+Math.sign(c)*o,l=Math.min(r.y,d),h=Math.max(r.y,d);return{cx:r.x,cy:(l+h)/2,left:r.x-n,right:r.x+n,top:l,bottom:h}}return null}u(Ro,"terminalMarkerClearanceRect");function Ao(t,e){const o=e==="start"?t.arrowTypeStart:t.arrowTypeEnd;if(typeof o=="string"){const n=o.trim();if(n.length>0)return n!=="none"&&n!=="arrow_open"}return typeof t.type!="string"?!1:e==="start"&&t.type.startsWith("double_")?!0:e==="end"&&/arrow_(point|cross|circle|barb)|double_arrow/.test(t.type)}u(Ao,"hasTerminalMarker");function Vt(t,e,o=1e-6){return Math.abs(t-e)<=o}u(Vt,"approxEqual");function Oo(t,e,o=1e-6){for(let n=1;n<t.length;n++){const i=t[n-1],r=t[n];if(Vt(i.y,r.y,o)&&!Vt(i.x,r.x,o)){if(Vt(e.y,i.y,o)&&e.x>=Math.min(i.x,r.x)-o&&e.x<=Math.max(i.x,r.x)+o)return!0}else if(Vt(i.x,r.x,o)&&!Vt(i.y,r.y,o)&&Vt(e.x,i.x,o)&&e.y>=Math.min(i.y,r.y)-o&&e.y<=Math.max(i.y,r.y)+o)return!0}return!1}u(Oo,"orthogonalPolylineContainsPoint");function ee(t){let e=0;for(let o=1;o<t.length;o++){const n=t[o-1],i=t[o];e+=Math.abs(i.x-n.x)+Math.abs(i.y-n.y)}return e}u(ee,"manhattanLength");function Ft(t,e,o){if(t.x===e.x&&t.y===e.y)return!1;if(t.y===e.y){const n=t.y,i=Math.min(t.x,e.x),r=Math.max(t.x,e.x),s=n>=o.top&&n<=o.bottom,a=Math.max(i,o.left)<Math.min(r,o.right);return s&&a}if(t.x===e.x){const n=t.x,i=Math.min(t.y,e.y),r=Math.max(t.y,e.y),s=n>=o.left&&n<=o.right,a=Math.max(i,o.top)<Math.min(r,o.bottom);return s&&a}return!1}u(Ft,"segmentIntersectsRectInterior");function bt(t,e){for(let o=1;o<t.length;o++)if(Ft(t[o-1],t[o],e))return!0;return!1}u(bt,"polylineIntersectsRect");function Bt(t,e,o){return Math.max(e,Math.min(o,t))}u(Bt,"clamp");var j="__grid_root__",zr="edge-label-";function H(t,e,o){const n=new Error(`${t}: ${e}`);return n.code=t,n.details=o,n}u(H,"gridError");var xt={columns:0,rowGap:50,columnGap:50,cellGap:20,containerPadding:20,titleGap:8,horizontalAlign:"center",verticalAlign:"center",curve:"rounded"};function pt(t){return!!t.isEdgeLabel}u(pt,"isEdgeLabelNode");function Z(t){return typeof t=="number"&&Number.isFinite(t)&&t>0}u(Z,"isFinitePositiveNumber");var $t=6,Ze=12,Bo=2;function Ln(t,e){if(!Z(t.width)||!Z(t.height))return null;const o=e==="H"?t.width:t.height,n=e==="H"?t.height:t.width,i=Math.max($t,Ze),r=Math.max($t,Ze);return{along:o,cross:n,startInset:i,endInset:r,requiredAlongSpan:o+i+r+Bo}}u(Ln,"gridLabelSpanRequirement");function Lo(t,e){const o=e==="H"?t.width:t.height;return Z(o)?o+$t*2:0}u(Lo,"gridLabelRequiredSegmentLength");var ut=$t,it=14,Hr=18,Vr=16,Po=128,$r=64,go=2e6,Pn=Ze,tt=1e-6,Kr=7,jr=8,dt=u(t=>z(t,tt),"normalizePolyline");function Je(t,e,o,n){const i=Math.max(Math.min(t,e),Math.min(o,n)),r=Math.min(Math.max(t,e),Math.max(o,n));return Math.max(0,r-i)}u(Je,"rangeOverlapLength");function _n(t){const e=dt([...t]).segments;for(let o=0;o<e.length;o++){const n=e[o];for(let i=o+2;i<e.length;i++){const r=e[i];if(Bn(n,r))return!0;if(n.orientation!==r.orientation||n.orientation==="Z")continue;const s=n.orientation==="H"?Math.abs(n.a.y-r.a.y)<=tt:Math.abs(n.a.x-r.a.x)<=tt,a=n.orientation==="H"?Je(n.a.x,n.b.x,r.a.x,r.b.x):Je(n.a.y,n.b.y,r.a.y,r.b.y);if(s&&a>tt)return!0;const c=n.orientation==="H"?Math.abs(n.a.y-r.a.y):Math.abs(n.a.x-r.a.x);if(!s&&c<Kr&&a>=jr)return!0}}return!1}u(_n,"polylineHasSelfConflict");var po=class extends Error{constructor(t){super(`Could not place label for edge "${t.edgeId}"`),this.details=t,this.name="LabelPlacementSearchExhaustedError"}static{u(this,"LabelPlacementSearchExhaustedError")}},_o=class extends Error{static{u(this,"LabelIndexWorkLimitError")}constructor(){super("Grid label index work cap exceeded"),this.name="LabelIndexWorkLimitError"}},Ur=class{constructor(t,e){this.limit=t,this.metrics=e,this.used=0}static{u(this,"LabelIndexWorkBudget")}charge(t){if(!(t<=0)){if(this.used+t>this.limit)throw new _o;this.used+=t,K(this.metrics,"indexWorkUnits",t)}}},Ee=class{constructor(t,e){this.workBudget=t,this.metrics=e,this.entriesById=new Map,this.sortedByLeft=[],this.dirty=!1}static{u(this,"CompressedBoundsIndex")}upsert(t){const e=!this.entriesById.has(t.id);this.entriesById.set(t.id,t),this.dirty=!0,e&&this.metrics&&(this.metrics.indexCoordinateCount+=4)}remove(t){this.entriesById.delete(t)&&(this.dirty=!0)}query(t){if(this.dirty){const o=this.entriesById.size;this.workBudget.charge(o*Math.max(1,Math.ceil(Math.log2(o+1)))),this.sortedByLeft=[...this.entriesById.values()].sort((n,i)=>n.bounds.left-i.bounds.left||U(n.id,i.id)),this.dirty=!1}const e=[];for(const o of this.sortedByLeft){if(this.workBudget.charge(1),o.bounds.left>t.right)break;Gn(o.bounds,t)&&e.push(o)}return e}};function tn(t,e){return t.left<e.right&&t.right>e.left&&t.top<e.bottom&&t.bottom>e.top}u(tn,"rectOverlap");function se(t,e){const o=t.width??0,n=t.height??0;return{cx:e.x,cy:e.y,left:e.x-o/2,right:e.x+o/2,top:e.y-n/2,bottom:e.y+n/2}}u(se,"labelRectAt");function Go(t){const e=t.groupTitleRect;return e?{cx:(e.left+e.right)/2,cy:(e.top+e.bottom)/2,left:e.left,right:e.right,top:e.top,bottom:e.bottom}:null}u(Go,"groupTitleRect");function K(t,e,o=1){t&&(t[e]+=o)}u(K,"incrementMetric");function pe(t){return{...t}}u(pe,"clonePoint");function Tt(t){return{left:t.left,right:t.right,top:t.top,bottom:t.bottom}}u(Tt,"boundsForRect");function Fe(t){return{left:Math.min(t.a.x,t.b.x),right:Math.max(t.a.x,t.b.x),top:Math.min(t.a.y,t.b.y),bottom:Math.max(t.a.y,t.b.y)}}u(Fe,"boundsForSegment");function To(t){if(t.length===0)return null;let e=t[0].x,o=t[0].x,n=t[0].y,i=t[0].y;for(const r of t.slice(1))e=Math.min(e,r.x),o=Math.max(o,r.x),n=Math.min(n,r.y),i=Math.max(i,r.y);return{left:e,right:o,top:n,bottom:i}}u(To,"boundsForPoints");function No(t,e){return{left:Math.min(t.left,e.left),right:Math.max(t.right,e.right),top:Math.min(t.top,e.top),bottom:Math.max(t.bottom,e.bottom)}}u(No,"mergeBounds");function Fo(t,e){return{left:t.left-e,right:t.right+e,top:t.top-e,bottom:t.bottom+e}}u(Fo,"expandBounds");function Gn(t,e){return t.left<=e.right&&t.right>=e.left&&t.top<=e.bottom&&t.bottom>=e.top}u(Gn,"boundsOverlap");function Tn(t){return(t.length<=2?t.map((o,n)=>n):[...t.slice(1,-1).map((o,n)=>n+1),0,t.length-1]).map((o,n)=>({segment:t[o],segmentIndex:o,order:n}))}u(Tn,"candidateSegmentsFromSegments");function Nn(t,e){return["start","end"].filter(n=>Ao(t,n)).map(n=>Ro(e,n,Pn,7,tt)).filter(n=>n!==null)}u(Nn,"markerClearanceRectsFromPoints");function De(t,e){const o=dt(e);return{points:o.points,segments:o.segments,candidateSegments:Tn(o.segments),markerRects:Nn(t,o.points)}}u(De,"buildEdgeGeometry");function Kt(t){return t.orientation==="H"?Math.abs(t.b.x-t.a.x):Math.abs(t.b.y-t.a.y)}u(Kt,"segmentLength");function Do(t,e){const o=[{x:e.left,y:e.top},{x:e.right,y:e.top},{x:e.right,y:e.bottom},{x:e.left,y:e.bottom}];for(let n=0;n<o.length;n++)if(Ft(o[n],o[(n+1)%o.length],t))return!0;return!1}u(Do,"borderCutsRect");function Fn(t){return Number.isFinite(t.x)&&Number.isFinite(t.y)}u(Fn,"hasFinitePosition");function St(t,e,o){const n=e?.get(t.id);if(n)return dt(n).points;const i=o?.edgeGeometryById.get(t.id);return i?i.points:dt(t.points??[]).points}u(St,"pointsForEdge");function ke(t,e,o){if(!e?.has(t.id)){const n=o?.edgeGeometryById.get(t.id);if(n)return n.markerRects}return Nn(t,St(t,e,o))}u(ke,"markerClearanceRectsForEdge");function ge(t,e,o,n){return Math.max(Math.min(t,e),Math.min(o,n))<Math.min(Math.max(t,e),Math.max(o,n))-tt}u(ge,"rangeOverlaps");function ko(t,e,o){const n=Bt(Math.min(t.start,t.end),e,o),i=Bt(Math.max(t.start,t.end),e,o);return i-n>tt?{start:n,end:i}:null}u(ko,"clampInterval");function zo(t,e,o){const n=t.map(r=>ko(r,e,o)).filter(r=>r!==null).sort((r,s)=>r.start-s.start||r.end-s.end);if(n.length===0)return[];const i=[n[0]];for(let r=1;r<n.length;r++){const s=n[r],a=i[i.length-1];s.start<=a.end+tt?a.end=Math.max(a.end,s.end):i.push(s)}return i}u(zo,"mergeBlockedLabelIntervals");function ze(t,e,o,n){if(e-t<=tt)return[];const i=[];let r=t;for(const d of zo(o,t,e))d.start-r>tt&&i.push({start:r,end:d.start}),r=Math.max(r,d.end);e-r>tt&&i.push({start:r,end:e});const s=i.map(d=>({value:Bt(n,d.start,d.end),start:d.start,end:d.end}));s.sort((d,l)=>{const h=Math.abs(d.value-n)-Math.abs(l.value-n);if(Math.abs(h)>tt)return h;const f=l.end-l.start-(d.end-d.start);return Math.abs(f)>tt?f:d.value-l.value});const a=new Set,c=[];for(const d of s){const l=Math.round(d.value*1e6)/1e6;a.has(l)||(a.add(l),c.push(d.value))}return c}u(ze,"centerCandidatesFromIntervals");function Ho(t){return t.isGroup||pt(t)&&!Fn(t)?null:k(t)}u(Ho,"obstacleRectForNode");function Vo(t,e){const o=e?.edgeGeometryById.get(t.id);return o?o.candidateSegments:Tn(dt(t.points??[]).segments)}u(Vo,"candidateSegments");function Dn(t,e,o){const n=t.edgeGeometryById.get(e);n&&n.segments.forEach((i,r)=>t.segmentIndex.remove(`${e}:${r}`)),t.edgeGeometryById.set(e,o),o.segments.forEach((i,r)=>{t.segmentIndex.upsert({id:`${e}:${r}`,edgeId:e,segment:i,bounds:Fe(i)})})}u(Dn,"storeEdgeGeometry");function Nt(t,e,o){const n=De(e,o);e.points=n.points.map(pe),Dn(t,e.id,n)}u(Nt,"setEdgePoints");function $o(t,e){t.placedLabelIndex.upsert({id:`label:${e.nodeId}`,nodeId:e.nodeId,rect:e.rect,bounds:Tt(e.rect)})}u($o,"upsertPlacedLabelObstacle");function Ko(t,e,o){const n={edgeById:new Map,edgeGeometryById:new Map,obstacleIndex:new Ee(e,o),placedLabelIndex:new Ee(e,o),groupBorderIndex:new Ee(e,o),segmentIndex:new Ee(e,o),searchBounds:{left:0,right:0,top:0,bottom:0},metrics:o};let i=null;const r=u(s=>{i=i?No(i,s):{...s}},"rememberBounds");for(const s of t.nodes){if(s.isGroup){const d=k(s),l=Tt(d);n.groupBorderIndex.upsert({id:`border:${s.id}`,rect:d,bounds:l}),r(l);const h=Go(s);if(h){const f=Tt(h);n.obstacleIndex.upsert({id:`title:${s.id}`,rect:h,bounds:f}),r(f)}continue}const a=Ho(s);if(!a)continue;const c={id:`${pt(s)?"label":"node"}:${s.id}`,rect:a,bounds:Tt(a),nodeId:s.id};pt(s)?n.placedLabelIndex.upsert(c):n.obstacleIndex.upsert(c),r(c.bounds)}for(const s of t.edges){n.edgeById.set(s.id,s);const a=De(s,s.points??[]);Dn(n,s.id,a);const c=To(a.points);c&&r(c)}return n.searchBounds=Fo(i??{left:0,right:0,top:0,bottom:0},128),n}u(Ko,"createEdgeLabelContext");function Xt(t,e,o,n={}){K(t.metrics,o);const i=[],r=u(s=>{for(const a of s)a.nodeId&&(a.nodeId===n.excludeNodeId||n.skipNodeIds?.has(a.nodeId))||i.push(a)},"appendEntries");return r(t.obstacleIndex.query(e)),r(t.placedLabelIndex.query(e)),K(t.metrics,"obstacleCandidatesVisited",i.length),i}u(Xt,"queryObstacleEntries");function He(t,e,o,n,i){K(t.metrics,i);const r=n?new Set(n.keys()):void 0,s=[],a=t.segmentIndex.query(e);for(const d of a)d.edgeId===o||r?.has(d.edgeId)||s.push(d);let c=a.length;if(n)for(const[d,l]of n){if(d===o)continue;const h=t.edgeById.get(d);if(!h)continue;De(h,l).segments.forEach((m,p)=>{const x=Fe(m);Gn(x,e)&&(c+=1,s.push({id:`override:${d}:${p}`,edgeId:d,segment:m,bounds:x}))})}return K(t.metrics,"segmentCandidatesVisited",c),s}u(He,"queryForeignSegments");function Ve(t,e,o,n){K(t.metrics,"foreignEdgeLookups");const i=new Set;for(const r of He(t,Tt(e),o,n,"segmentRectQueries"))Ft(r.segment.a,r.segment.b,e)&&i.add(r.edgeId);return[...i].sort(U)}u(Ve,"foreignEdgeIdsIntersectingRect");function kn(t,e){return!Z(e.width)||!Z(e.height)?null:t.orientation==="H"?{left:Math.min(t.a.x,t.b.x)-e.width/2,right:Math.max(t.a.x,t.b.x)+e.width/2,top:t.a.y-e.height/2,bottom:t.a.y+e.height/2}:{left:t.a.x-e.width/2,right:t.a.x+e.width/2,top:Math.min(t.a.y,t.b.y)-e.height/2,bottom:Math.max(t.a.y,t.b.y)+e.height/2}}u(kn,"obstacleBandQueryBounds");function jo(t,e,o){if(t.orientation==="H"){const i=(e.width??0)+ut*2+it;return{left:Math.min(t.a.x,t.b.x)-i,right:Math.max(t.a.x,t.b.x)+i,top:o.top,bottom:o.bottom}}const n=(e.height??0)+ut*2+it;return{left:o.left,right:o.right,top:Math.min(t.a.y,t.b.y)-n,bottom:Math.max(t.a.y,t.b.y)+n}}u(jo,"detourLineQueryBounds");function Uo(t,e){return t.orientation==="H"?{left:Math.min(t.a.x,t.b.x)-ut,right:Math.max(t.a.x,t.b.x)+ut,top:e.top,bottom:e.bottom}:{left:e.left,right:e.right,top:Math.min(t.a.y,t.b.y)-ut,bottom:Math.max(t.a.y,t.b.y)+ut}}u(Uo,"rerouteLineQueryBounds");function ae(t,e,o,n,i,r){for(const s of Xt(n,Tt(t),"obstacleRectQueries",{excludeNodeId:o}))if(tn(t,s.rect))return!1;for(const s of n.groupBorderIndex.query(Tt(t)))if(Do(t,s.rect))return!1;for(const s of ke(e,i,n))if(tn(t,s))return!1;for(const s of He(n,Tt(t),e.id,i,"segmentRectQueries"))if(!r?.has(s.edgeId)&&Ft(s.segment.a,s.segment.b,t))return!1;return!0}u(ae,"rectSafeForLabel");function Xo(t,e){return e.orientation==="Z"?0:Lo(t,e.orientation)}u(Xo,"requiredSegmentLength");function $e(t,e,o,n,i,r){if(!Z(e.width)||!Z(e.height))return null;const s=e.width,a=e.height,c=o.orientation==="H"?s/2+ut:a/2+ut,d=o.orientation==="H"?Math.min(o.a.x,o.b.x)+c:Math.min(o.a.y,o.b.y)+c,l=o.orientation==="H"?Math.max(o.a.x,o.b.x)-c:Math.max(o.a.y,o.b.y)-c;if(l-d<=tt)return null;const h=[],f=kn(o,e);if(!f)return null;const m=u(p=>{if(o.orientation==="H"){const y=o.a.y-a/2,b=o.a.y+a/2;ge(y,b,p.top,p.bottom)&&h.push({start:p.left-s/2,end:p.right+s/2});return}const x=o.a.x-s/2,g=o.a.x+s/2;ge(x,g,p.left,p.right)&&h.push({start:p.top-a/2,end:p.bottom+a/2})},"addRect");for(const p of Xt(n,f,"obstacleBandQueries",{excludeNodeId:e.id}))m(p.rect);for(const p of ke(t,i,n))m(p);if(r)for(const p of He(n,f,t.id,i,"segmentBandQueries")){const x=p.segment;if(o.orientation==="H"){const b=o.a.y-e.height/2,I=o.a.y+e.height/2;x.orientation==="H"?b<x.a.y&&I>x.a.y&&h.push({start:Math.min(x.a.x,x.b.x)-e.width/2,end:Math.max(x.a.x,x.b.x)+e.width/2}):ge(b,I,Math.min(x.a.y,x.b.y),Math.max(x.a.y,x.b.y))&&h.push({start:x.a.x-e.width/2,end:x.a.x+e.width/2});continue}const g=o.a.x-e.width/2,y=o.a.x+e.width/2;x.orientation==="V"?g<x.a.x&&y>x.a.x&&h.push({start:Math.min(x.a.y,x.b.y)-e.height/2,end:Math.max(x.a.y,x.b.y)+e.height/2}):ge(g,y,Math.min(x.a.x,x.b.x),Math.max(x.a.x,x.b.x))&&h.push({start:x.a.y-e.height/2,end:x.a.y+e.height/2})}return{low:d,high:l,blocked:h}}u($e,"blockedCenterIntervals");function Wo(t,e,o,n){if(Kt(o)<Xo(e,o))return null;const i=$e(t,e,o,n,void 0,!0);if(!i)return null;const r=o.orientation==="H"?(Math.min(o.a.x,o.b.x)+Math.max(o.a.x,o.b.x))/2:(Math.min(o.a.y,o.b.y)+Math.max(o.a.y,o.b.y))/2,s=ze(i.low,i.high,i.blocked,r);for(const a of s){const c=o.orientation==="H"?{x:a,y:o.a.y}:{x:o.a.x,y:a},d=se(e,c);if(ae(d,t,e.id,n))return c}return null}u(Wo,"placementOnExistingSegment");function Yo(t,e,o,n,i){const r=$e(t,e,o,n,void 0,!1);if(!r)return null;const s=o.orientation==="H"?(Math.min(o.a.x,o.b.x)+Math.max(o.a.x,o.b.x))/2:(Math.min(o.a.y,o.b.y)+Math.max(o.a.y,o.b.y))/2,a=ze(r.low,r.high,r.blocked,s);for(const c of a){const d=o.orientation==="H"?{x:c,y:o.a.y}:{x:o.a.x,y:c},l=se(e,d),h=new Map,f=Ve(n,l,t.id).map(p=>n.edgeById.get(p)).filter(p=>p!==void 0);let m=!0;for(const p of f){const x=ce(p,l,n,i,h);if(!x){m=!1;break}h.set(p.id,x)}if(m&&ae(l,t,e.id,n,h)){for(const[p,x]of h){const g=n.edgeById.get(p);g&&Nt(n,g,x)}return d}}return null}u(Yo,"placementOnExistingSegmentWithReroutes");function ye(t,e,o){for(const n of dt(t).segments)for(const i of Xt(e,Fe(n),"obstaclePolylineQueries",{skipNodeIds:o}))if(Ft(n.a,n.b,i.rect))return!0;return!1}u(ye,"polylineHitsProtectedObstacles");function Yt(t,e,o){const n=o.get(t);return!n||Oo(e,n.center,tt)}u(Yt,"labelStillAnchored");function zn(t){const e=[];for(let o=0;o<Vr;o++){const n=t+it+o*Hr;e.push(-n,n)}return e}u(zn,"detourOffsets");function Ce(t,e){const o=new Map;for(const n of t){const i=Math.round(n*1e6)/1e6;o.has(i)||o.set(i,n)}return[...o.values()].sort((n,i)=>{const r=Math.abs(n-e)-Math.abs(i-e);return Math.abs(r)>tt?r:n-i})}u(Ce,"uniqueSortedCandidates");function Hn(t,e,o,n){if(!Z(e.width)||!Z(e.height))return[];const i=e.width,r=e.height,s=o.orientation==="H"?o.a.y:o.a.x,a=o.orientation==="H"?r/2:i/2,c=zn(a).map(l=>s+l),d=u(l=>{if(o.orientation==="H"){c.push(l.top-a-it),c.push(l.bottom+a+it);return}c.push(l.left-a-it),c.push(l.right+a+it)},"addRect");for(const l of Xt(n,jo(o,e,n.searchBounds),"obstacleBandQueries",{excludeNodeId:e.id}))d(l.rect);for(const l of ke(t,void 0,n))d(l);return Ce(c,s).slice(0,Po)}u(Hn,"detourLineCandidates");function en(t,e,o,n,i){const r=t.orientation==="H"?t.a.y:t.a.x,s=[];for(const l of zn(0))t.orientation==="H"?s.push(l<0?e.top+l:e.bottom+l):s.push(l<0?e.left+l:e.right+l);const a=u(l=>{if(t.orientation==="H"){s.push(l.top-it),s.push(l.bottom+it);return}s.push(l.left-it),s.push(l.right+it)},"addRect");for(const l of Xt(o,Uo(t,o.searchBounds),"obstacleBandQueries",{skipNodeIds:n}))a(l.rect);const c=Ce(s,r);return(i?.orientation===t.orientation?c.filter(l=>i.side==="top"?l<e.top:i.side==="bottom"?l>e.bottom:i.side==="left"?l<e.left:l>e.right):c).slice(0,Po)}u(en,"rerouteLineCandidates");function qo(t,e,o,n,i){if(!Z(e.width)||!Z(e.height))return[];const r=e.width,s=e.height,a=o.orientation==="H"?{orientation:"H",a:{x:o.a.x,y:n},b:{x:o.b.x,y:n}}:{orientation:"V",a:{x:n,y:o.a.y},b:{x:n,y:o.b.y}},c=$e(t,e,a,i,void 0,!1);if(!c){const l=o.orientation==="H"?(Math.min(o.a.x,o.b.x)+Math.max(o.a.x,o.b.x))/2:(Math.min(o.a.y,o.b.y)+Math.max(o.a.y,o.b.y))/2,h=[l],f=kn(a,e),m=u(p=>{if(o.orientation==="H"){h.push(p.left-it-r/2),h.push(p.right+it+r/2);return}h.push(p.top-it-s/2),h.push(p.bottom+it+s/2)},"addRect");if(f)for(const p of Xt(i,f,"obstacleBandQueries",{excludeNodeId:e.id}))m(p.rect);return Ce(h,l).slice(0,$r)}const d=o.orientation==="H"?(Math.min(o.a.x,o.b.x)+Math.max(o.a.x,o.b.x))/2:(Math.min(o.a.y,o.b.y)+Math.max(o.a.y,o.b.y))/2;return ze(c.low,c.high,c.blocked,d)}u(qo,"detourCenterCandidates");function Vn(t,e,o){const n=e>=t?1:-1;return e+n*(o+ut)}u(Vn,"detourReturnCoordinate");var Xr={along:u(t=>t.x,"along"),cross:u(t=>t.y,"cross"),point:u((t,e)=>({x:t,y:e}),"point"),labelAlongSize:u(t=>t.width??0,"labelAlongSize"),labelCrossSize:u(t=>t.height??0,"labelCrossSize")},Wr={along:u(t=>t.y,"along"),cross:u(t=>t.x,"cross"),point:u((t,e)=>({x:e,y:t}),"point"),labelAlongSize:u(t=>t.height??0,"labelAlongSize"),labelCrossSize:u(t=>t.width??0,"labelCrossSize")};function $n(t){return t.orientation==="H"?Xr:Wr}u($n,"detourAxis");function Qo(t,e,o,n,i,r){if(!Z(n.width)||!Z(n.height))return null;const s=t[e],a=t[e+1],c=$n(o),d=c.cross(o.a),l=c.along(s),h=c.along(a),f=c.labelAlongSize(n)+ut*2,m=i-f/2,p=i+f/2,x=m<Math.min(l,h)-tt,g=p>Math.max(l,h)+tt,y=h>=l?1:-1,b=Math.max(0,Math.min(Pn,Math.abs(h-l)/2-tt)),I=l+y*b,C=h-y*b;if(!x&&!g)return dt([...t.slice(0,e),s,c.point(m,d),c.point(m,r),c.point(p,r),c.point(p,d),a,...t.slice(e+2)]).points;const S=Vn(d,r,c.labelCrossSize(n)/2),v=[...t.slice(0,e),s];return x?v.push(c.point(I,d),c.point(I,S),c.point(m,S),c.point(m,r)):v.push(c.point(m,d),c.point(m,r)),v.push(c.point(p,r)),g?v.push(c.point(p,S),c.point(C,S),c.point(C,d)):v.push(c.point(p,d)),v.push(a,...t.slice(e+2)),dt(v).points}u(Qo,"buildLabelDetourPoints");function Zo(t,e,o,n,i,r,s){if(!Z(n.width)||!Z(n.height))return null;const a=t[e],c=t[e+1],d=s?4:2,l=$n(o),h=l.cross(o.a),f=l.along(a),m=l.along(c),p=l.labelAlongSize(n)+ut*2,x=i-p/2,g=i+p/2,y=m>=f?1:-1,b=Math.max(0,Math.min(Pn,Math.abs(m-f)/d-tt)),I=f+y*b,C=m-y*b,S=Vn(h,r,l.labelCrossSize(n)/2);return dt([...t.slice(0,e),a,l.point(I,h),l.point(I,r),l.point(x,r),l.point(g,r),l.point(g,S),l.point(C,S),l.point(C,h),c,...t.slice(e+2)]).points}u(Zo,"buildExtendedLabelDetourPoints");function Jo(t,e){if(!Z(e.width)||!Z(e.height))return[];if(t.orientation==="H"){const i=Math.min(t.a.x,t.b.x),r=Math.max(t.a.x,t.b.x);return[i-e.width/2-it,r+e.width/2+it]}const o=Math.min(t.a.y,t.b.y),n=Math.max(t.a.y,t.b.y);return[o-e.height/2-it,n+e.height/2+it]}u(Jo,"externalDetourCenterCandidates");function Kn(t,e){let o=0,n=0;for(const i of dt([...t]).segments)Ft(i.a,i.b,e)&&(o++,i.orientation==="H"?n+=Math.max(0,Math.min(Math.max(i.a.x,i.b.x),e.right)-Math.max(Math.min(i.a.x,i.b.x),e.left)):i.orientation==="V"&&(n+=Math.max(0,Math.min(Math.max(i.a.y,i.b.y),e.bottom)-Math.max(Math.min(i.a.y,i.b.y),e.top))));return{count:o,length:n}}u(Kn,"blockedIntersectionScore");function nn(t,e,o){const n=Kn(t,e);return n.count<o.count||n.count===o.count&&n.length<o.length-tt}u(nn,"reducesBlockedIntersections");function ti(t,e,o){const n=dt([...t]).segments.find(s=>Ft(s.a,s.b,e));if(!n||n.orientation==="Z")return null;const i=n.orientation==="H"?Math.abs(n.a.y-e.top)<=Math.abs(e.bottom-n.a.y)?"top":"bottom":Math.abs(n.a.x-e.left)<=Math.abs(e.right-n.a.x)?"left":"right",r=o.map(s=>s.edgeId).sort(U);return{key:JSON.stringify([r,n.orientation,i]),orientation:n.orientation,side:i}}u(ti,"rerouteLane");function ei(t,e,o,n,i,r,s){const a=dt(e),c=Kn(a.points,n),d=a.segments[o];if(!d||d.orientation==="Z")return null;const l=a.points[o],h=a.points[o+1],f=r.get(t.id)?.nodeId,m=new Set;if(f&&m.add(f),d.orientation==="H"){const b=Math.min(l.x,h.x),I=Math.max(l.x,h.x),C=Math.max(b,n.left-ut),S=Math.min(I,n.right+ut);if(S-C<=tt)return K(i.metrics,"rerouteRejectedDegenerateSpan"),null;for(const v of en(d,n,i,m,s)){K(i.metrics,"rerouteCandidatesEvaluated");const w=dt([...a.points.slice(0,o),l,{x:C,y:d.a.y},{x:C,y:v},{x:S,y:v},{x:S,y:d.a.y},h,...a.points.slice(o+2)]).points;if(bt(w,n)&&!nn(w,n,c)){K(i.metrics,"rerouteRejectedBlockedRect");continue}if(bt(w,n)&&K(i.metrics,"reroutePartialProgressCandidates"),ye(w,i,m)){K(i.metrics,"rerouteRejectedProtectedObstacle");continue}if(!Yt(t.id,w,r)){K(i.metrics,"rerouteRejectedLabelAnchor");continue}return w}return null}const p=Math.min(l.y,h.y),x=Math.max(l.y,h.y),g=Math.max(p,n.top-ut),y=Math.min(x,n.bottom+ut);if(y-g<=tt)return K(i.metrics,"rerouteRejectedDegenerateSpan"),null;for(const b of en(d,n,i,m,s)){K(i.metrics,"rerouteCandidatesEvaluated");const I=dt([...a.points.slice(0,o),l,{x:d.a.x,y:g},{x:b,y:g},{x:b,y},{x:d.a.x,y},h,...a.points.slice(o+2)]).points;if(bt(I,n)&&!nn(I,n,c)){K(i.metrics,"rerouteRejectedBlockedRect");continue}if(bt(I,n)&&K(i.metrics,"reroutePartialProgressCandidates"),ye(I,i,m)){K(i.metrics,"rerouteRejectedProtectedObstacle");continue}if(!Yt(t.id,I,r)){K(i.metrics,"rerouteRejectedLabelAnchor");continue}return I}return null}u(ei,"rerouteSegmentAroundRect");function ce(t,e,o,n,i,r){let s=St(t,i,o);for(let a=0;a<8;a++){if(!bt(s,e))return s;const c=dt(s),d=c.points.findIndex((h,f)=>f===c.points.length-1?!1:Ft(h,c.points[f+1],e));if(d<0)return s;const l=ei(t,c.points,d,e,o,n,r);if(!l)return null;s=l}return bt(s,e)?null:s}u(ce,"rerouteForeignEdgeAroundRect");function ni(t,e,o,n,i){const r=St(t,i,o);let s=r;for(let a=0;a<2;a++){let c=!1;for(const d of e){if(!bt(s,d.rect))continue;K(o.metrics,"individualLabelRerouteAttempts"),i.set(t.id,s);const l=ce(t,d.rect,o,n,i);if(!l)return i.set(t.id,r),null;K(o.metrics,"individualLabelRerouteSuccesses"),s=l,c=!0}if(e.every(d=>!bt(s,d.rect)))return s;if(!c)break}return i.set(t.id,r),null}u(ni,"rerouteForeignEdgeAroundLabels");function oi(t,e,o,n,i){if(!Z(e.width)||!Z(e.height))return null;const r=St(t,void 0,n),s=o.segment;for(const a of Hn(t,e,s,n)){const c=Ce(Jo(s,e),s.orientation==="H"?(Math.min(s.a.x,s.b.x)+Math.max(s.a.x,s.b.x))/2:(Math.min(s.a.y,s.b.y)+Math.max(s.a.y,s.b.y))/2);for(const d of c){const l=Zo(r,o.segmentIndex,s,e,d,a,t.start===t.end);if(!l||t.start===t.end&&_n(l)||ye(l,n,new Set([e.id])))continue;const h=s.orientation==="H"?{x:d,y:a}:{x:a,y:d},f=se(e,h),m=new Map([[t.id,l]]),p=Ve(n,f,t.id,m).map(g=>n.edgeById.get(g)).filter(g=>g!==void 0);let x=!0;for(const g of p){const y=ce(g,f,n,i,m);if(!y){x=!1;break}m.set(g.id,y)}if(x&&ae(f,t,e.id,n,m)){Nt(n,t,l);for(const[g,y]of m){if(g===t.id)continue;const b=n.edgeById.get(g);b&&Nt(n,b,y)}return h}}}return null}u(oi,"labelPlacementWithExtendedDetour");function ii(t,e,o,n,i){if(!Z(e.width)||!Z(e.height))return null;const r=St(t,void 0,n),s=o.segment;for(const a of Hn(t,e,s,n)){const c=qo(t,e,s,a,n);for(const d of c){const l=Qo(r,o.segmentIndex,s,e,d,a);if(!l||t.start===t.end&&_n(l)||ye(l,n,new Set([e.id])))continue;const h=s.orientation==="H"?{x:d,y:a}:{x:a,y:d},f=se(e,h),m=new Map([[t.id,l]]),p=Ve(n,f,t.id,m).map(g=>n.edgeById.get(g)).filter(g=>g!==void 0);let x=!0;for(const g of p){const y=ce(g,f,n,i,m);if(!y){x=!1;break}m.set(g.id,y)}if(x&&ae(f,t,e.id,n,m)){Nt(n,t,l);for(const[g,y]of m){if(g===t.id)continue;const b=n.edgeById.get(g);b&&Nt(n,b,y)}return h}}}return null}u(ii,"labelPlacementWithDetour");function ri(t){return!!(t&&pt(t))}u(ri,"isPreparedLabelNode");function jn(t,e,o){const n=t.points?.find(a=>Number.isFinite(a.x)&&Number.isFinite(a.y)),i=t.start?o.get(t.start):void 0,r=t.end?o.get(t.end):void 0,s=n??(i&&Fn(i)?i:void 0)??r;if(s&&Number.isFinite(s.x)&&Number.isFinite(s.y)){e.x=s.x,e.y=s.y;return}delete e.x,delete e.y}u(jn,"parkDegenerateLabel");function si(t,e,o){let n;for(const i of dt(t.points??[]).segments)i.orientation!=="Z"&&(!n||Kt(i)>Kt(n))&&(n=i);if(!n){jn(t,e,o);return}e.x=(n.a.x+n.b.x)/2,e.y=(n.a.y+n.b.y)/2}u(si,"placeLabelAtRouteMidpoint");function ai(t){return`${zr}${t.start??""}-${t.end??""}-${t.id}`}u(ai,"preferredGridLabelNodeId");function ci(t,e){const o=t.labelNodeId??ai(t);let n=o,i=1;for(;;){if(!e.has(n))return n;n=`${o}-${i}`,i+=1}}u(ci,"ensureUniqueGridLabelNodeId");function di(t){const e=new Map;for(const n of t.nodes)e.set(n.id,n);const o=[];for(const n of t.edges){if(!n.label||n.label.length===0)continue;const i=n.start?e.get(n.start):void 0,r=n.labelNodeId?e.get(n.labelNodeId):void 0;if(ri(r)){r.label=n.label,r.labelStyle=Array.isArray(n.labelStyle)?n.labelStyle[0]:n.labelStyle??"",r.edgeStart=n.start??"",r.edgeEnd=n.end??"",i?.dir&&(r.dir=i.dir),n.label=void 0,n.text=void 0;continue}const s=ci(n,e),a={id:s,label:n.label,edgeStart:n.start??"",edgeEnd:n.end??"",shape:"labelRect",width:0,height:0,isEdgeLabel:!0,isDummy:!0,isGroup:!1,parentId:void 0,labelStyle:Array.isArray(n.labelStyle)?n.labelStyle[0]:n.labelStyle??"",...i?.dir?{dir:i.dir}:{}};o.push(a),e.set(s,a),n.labelNodeId=s,n.label=void 0,n.text=void 0}t.nodes.push(...o)}u(di,"prepareGridLayout");function li(t,e,o,n={}){const i=new Map;for(const y of t.nodes)i.set(y.id,y);const r=t.nodes.filter(pt),s=new Map(r.map(y=>[y.id,{x:y.x,y:y.y}]));for(const y of r)delete y.x,delete y.y;const a=t.edges.map((y,b)=>{if(!y.labelNodeId)return null;const I=i.get(y.labelNodeId);return I?!Z(I.width)||!Z(I.height)?(K(e,"unmeasuredLabelsSkipped"),null):{edge:y,labelNode:I,sourceIndex:b}:null}).filter(y=>y!==null);if(a.length===0)return;const c=new Map(t.edges.map(y=>[y.id,y.points?.map(b=>({...b}))])),d=u(()=>{for(const y of t.edges){const b=c.get(y.id);b?y.points=b.map(I=>({...I})):delete y.points}},"restoreBaseEdgePoints"),l=u(()=>{d();for(const y of r){const b=s.get(y.id);b&&Number.isFinite(b.x)&&Number.isFinite(b.y)?(y.x=b.x,y.y=b.y):(delete y.x,delete y.y)}},"restoreBaseState"),h=a.filter(({edge:y,labelNode:b})=>dt(y.points??[]).segments.length>0?!0:(jn(y,b,i),K(e,"degenerateLabelRoutesSkipped"),!1)).sort((y,b)=>y.sourceIndex-b.sourceIndex||U(y.edge.id,b.edge.id));if(h.length===0)return;const f=u(()=>{d();for(const{edge:y,labelNode:b}of h)si(y,b,i)},"placeLabelsAtRouteMidpoints"),m=n.maxIndexWork??go,p=Number.isFinite(m)&&m>=0?Math.floor(m):go,x=new Ur(p,e),g=[];for(let y=1;y<=2;y++){K(e,"labelPasses");const b=Ko(t,x,e),I=new Map,C=new Map,S=new Map(t.edges.map(w=>[w.id,St(w,void 0,b).map(pe)])),v=new Map;try{for(const{edge:M,labelNode:A}of h){const L=[...Vo(M,b)].sort((G,X)=>{const W=Kt(X.segment)-Kt(G.segment);return Math.abs(W)>tt?W:G.order-X.order});let B=null;for(const G of L)if(B=Wo(M,A,G.segment,b),B)break;if(!B){for(const G of L)if(B=Yo(M,A,G.segment,b,I),B)break}if(y===2&&!B){for(const G of L)if(B=ii(M,A,G,b,I),B)break}if(y===2&&!B){for(const G of L)if(B=oi(M,A,G,b,I),B)break}if(!B)throw new po({edgeId:M.id,labelNodeId:A.id,labelWidth:A.width,labelHeight:A.height,pointCount:M.points?.length??0,points:M.points?.map(G=>({...G}))??[],segments:L.map(({segment:G})=>({orientation:G.orientation,length:Kt(G),a:{...G.a},b:{...G.b}}))});A.x=B.x,A.y=B.y;const T={edgeId:M.id,nodeId:A.id,center:B,rect:se(A,B)};I.set(M.id,T),$o(b,T)}const w=[...I.values()];K(e,"frozenReservations",w.length),o&&(o.labelOverlayBuilds++,o.labelOverlayVertices+=w.length*4);for(const M of t.edges){const A=S.get(M.id)??[],L=St(M,void 0,b);JSON.stringify(L)!==JSON.stringify(A)&&v.set(M.id,L.map(pe)),Nt(b,M,A.map(pe))}for(const[M,A]of v){if(!I.has(M))continue;const L=b.edgeById.get(M);L&&Nt(b,L,A)}const E=new Set(v.keys());for(const M of t.edges){const A=I.get(M.id),L=St(M,void 0,b);for(const B of w)B.edgeId!==M.id&&bt(L,B.rect)&&E.add(M.id);A&&!Yt(M.id,L,I)&&E.add(M.id)}const R=new Map;for(const M of t.edges){if(!E.has(M.id))continue;let A=St(M,void 0,b);const L=new Map([[M.id,A]]),B=w.filter(T=>T.edgeId!==M.id&&bt(A,T.rect));if(B.length>0){const T=B.slice(1).reduce((et,D)=>({cx:(Math.min(et.left,D.rect.left)+Math.max(et.right,D.rect.right))/2,cy:(Math.min(et.top,D.rect.top)+Math.max(et.bottom,D.rect.bottom))/2,left:Math.min(et.left,D.rect.left),right:Math.max(et.right,D.rect.right),top:Math.min(et.top,D.rect.top),bottom:Math.max(et.bottom,D.rect.bottom)}),{...B[0].rect}),G=ti(A,T,B),X=G?R.get(G.key)??0:0,W=(X+2)*12,F={cx:T.cx,cy:T.cy,left:T.left-W,right:T.right+W,top:T.top-W,bottom:T.bottom+W};let Y=ce(M,F,b,I,L,G??void 0);const wt=Y!==null;if(Y??=ni(M,B,b,I,L),Y)A=Y,L.set(M.id,A),G&&wt&&R.set(G.key,X+1);else{K(e,"labelOverlapFallbacks");for(const et of B){if(!bt(A,et.rect))continue;const D=C.get(et.edgeId)??new Set;D.has(M.id)||K(e,"labelOverlapReservations"),D.add(M.id),C.set(et.edgeId,D)}}}if(!Yt(M.id,A,I))throw H("GRID_ROUTE_NOT_FOUND",`Label anchor was lost for edge "${M.id}"`,{edgeId:M.id,pass:y});I.has(M.id)&&K(e,"preservedAnchors"),Nt(b,M,A),K(e,"impactedEdgeReroutes")}for(const{edge:M,labelNode:A}of h){const L=I.get(M.id);if(!L||!Yt(M.id,St(M,void 0,b),I)||!ae(L.rect,M,A.id,b,void 0,C.get(M.id)))throw H("GRID_ROUTE_NOT_FOUND",`Label pass ${y} did not validate`,{edgeId:M.id,pass:y})}return}catch(w){if(w instanceof _o){f(),K(e,"indexWorkLimitFallbacks"),o&&(o.resourceLimitFallbacks++,o.fallbackReasons.label_index_work_cap++);return}if(!(w instanceof po))throw l(),K(e,"rollbacks"),w;g.push(w),d();for(const{labelNode:E}of h)delete E.x,delete E.y}}f(),K(e,"placementSearchFallbacks"),o&&o.fallbackReasons.label_placement_exhausted++,te.warn("[grid]","Label placement search exhausted; using route midpoints. Labels may overlap.",{reason:"label_placement_exhausted",edgeIds:h.map(({edge:y})=>y.id),failures:g.map(({details:y})=>y)})}u(li,"positionGridEdgeLabels");function Ae(t){return t.isGroup?t:void 0}u(Ae,"asGroup");function ui(t){const e=new Map,o=new Map,n=new Set;for(const d of t){if(d.id===j)throw H("GRID_INVALID_CONTAINMENT",`Node id "${j}" is reserved for the grid layout root`,{traversedIds:[d.id]});if(e.has(d.id))throw H("GRID_INVALID_CONTAINMENT",`Duplicate node id "${d.id}"`,{traversedIds:[d.id]});if(e.set(d.id,d),pt(d)){n.add(d.id);continue}const l=Ae(d);l&&o.set(l.id,l)}const i=new Map;i.set(j,[]);for(const d of t){if(n.has(d.id))continue;const l=d.parentId??j;if(l!==j&&!o.get(l))throw H("GRID_INVALID_CONTAINMENT",`Missing parent "${l}" for "${d.id}"`,{traversedIds:[d.id,l]});i.has(l)||i.set(l,[]),i.get(l).push(d)}const r=new Map,s=[],a=u(d=>(i.get(d)??[]).map(l=>Ae(l)).filter(l=>l!==void 0),"directChildGroups"),c=u(d=>{const l=r.get(d)??0;if(l===1)throw H("GRID_INVALID_CONTAINMENT",`Containment cycle at "${d}"`,{traversedIds:[d]});if(l===2)return;r.set(d,1);const h=[{groupId:d,childGroups:a(d),nextChildIndex:0}];for(;h.length>0;){const f=h[h.length-1],m=f.childGroups[f.nextChildIndex];if(m){f.nextChildIndex+=1;const x=r.get(m.id)??0;if(x===1)throw H("GRID_INVALID_CONTAINMENT",`Containment cycle at "${m.id}"`,{traversedIds:[...h.map(g=>g.groupId),m.id]});if(x===2)continue;r.set(m.id,1),h.push({groupId:m.id,childGroups:a(m.id),nextChildIndex:0});continue}h.pop(),r.set(f.groupId,2);const p=o.get(f.groupId);p&&s.push(p)}},"visit");for(const d of i.get(j)??[]){const l=Ae(d);l&&c(l.id)}for(const d of o.keys())(r.get(d)??0)===0&&c(d);return{nodeById:e,groupById:o,childrenByParent:i,rootChildren:i.get(j)??[],postOrderGroups:s,helperNodeIds:n}}u(ui,"buildGridForest");function kt(t,e,o){let n=e;const i=new Set;for(;n?.parentId;){if(n.parentId===t)return!0;if(i.has(n.parentId))return!1;i.add(n.parentId),n=o.get(n.parentId)}return!1}u(kt,"isAncestorGroup");function hi(t,e,o){const n=new Map,i=new Map;for(const r of t.edges){if(!r.start||!r.end||!r.labelNodeId)continue;o&&o.labelSpacingEdgesExamined++;const s=e.nodeById.get(r.labelNodeId),a=e.nodeById.get(r.start),c=e.nodeById.get(r.end);if(!s||!a||!c)continue;if(r.start===r.end){const f=Ln(s,"H");f&&i.set(r.id,f);continue}const d=a.parentId??j,l=c.parentId??j;if(d!==l)continue;const h=n.get(d);h?h.push({edge:r,labelNode:s}):n.set(d,[{edge:r,labelNode:s}])}return{byContainer:n,selfLoops:i}}u(hi,"buildGridLabelRequirements");function fi(t,e,o){const n=new Map;let i=0;for(const r of t)n.set(r,i),i+=(e.get(r)??0)+o;return n}u(fi,"trackOrigins");function on(t,e,o,n,i){const r=fi(o,n,i),s=r.get(t),a=n.get(t);if(s===void 0||a===void 0)return!1;const c=s+a/2,d=c-e/2,l=c+e/2;return o.every(h=>{if(h===t)return!0;const f=r.get(h),m=f+(n.get(h)??0);return l<=f||d>=m})}u(on,"crossAxisFits");function gi(t){const e=new Map;for(const o of t.values())for(const n of o.items)e.set(n.item.id,n);return e}u(gi,"placementByNodeId");function rn(t,e,o){const n=Math.min(t,e),i=Math.max(t,e),r=o.indexOf(n);return r>=0&&o[r+1]===i}u(rn,"areConsecutive");function sn(t,e,o){t.set(e,Math.max(t.get(e)??0,o))}u(sn,"addGapRequirement");function pi(t,e,o,n,i,r,s,a,c){const d=new Map,l=new Map,h=gi(e),f=u((m,p)=>Ln(m.labelNode,p),"requirementFor");for(const m of t){const p=m.edge.start?h.get(m.edge.start):void 0,x=m.edge.end?h.get(m.edge.end):void 0;if(!(!p||!x)){if(p.row===x.row&&rn(p.column,x.column,r)){const g=f(m,"H");g&&on(p.row,g.cross,i,o,s)&&(c&&c.labelSpacingEligibleEdges++,sn(l,Math.min(p.column,x.column),g.requiredAlongSpan));continue}if(p.column===x.column&&rn(p.row,x.row,i)){const g=f(m,"V");g&&on(p.column,g.cross,r,n,a)&&(c&&c.labelSpacingEligibleEdges++,sn(d,Math.min(p.row,x.row),g.requiredAlongSpan))}}}return{rowGapAfter:d,columnGapAfter:l}}u(pi,"deriveGridContainerLabelGaps");var an="[grid]",Yr=new Set(["basis","bumpX","bumpY","cardinal","catmullRom","linear","monotoneX","monotoneY","natural","step","stepAfter","stepBefore","rounded"]);function Be(t){return t!==null&&typeof t=="object"&&!Array.isArray(t)}u(Be,"isObjectRecord");function Un(t){if(!Be(t))return{};const e={};return Object.hasOwn(t,"row")&&(e.row=t.row),Object.hasOwn(t,"column")&&(e.column=t.column),Mo(t.horizontalAlign)&&(e.horizontalAlign=t.horizontalAlign),Io(t.verticalAlign)&&(e.verticalAlign=t.verticalAlign),e}u(Un,"ownPlacementFrom");function mi(t){const e=new Map;let o=0;for(const n of t)e.has(n.id)||e.set(n.id,o++);return e}u(mi,"buildGridSourceOrder");function yi(t){const e=Be(t.config?.grid)?t.config.grid:{},o=Be(e.placements)?e.placements:{},n=new Map;for(const i of Object.keys(o)){const r=o[i],s=Array.isArray(r)?r:[r];n.set(i,s.map(a=>Un(a)))}return{placements:n,columns:typeof e.columns=="number"&&Number.isFinite(e.columns)&&e.columns>=0?Math.trunc(e.columns):xt.columns,rowGap:typeof e.rowGap=="number"&&Number.isFinite(e.rowGap)&&e.rowGap>=0?e.rowGap:xt.rowGap,columnGap:typeof e.columnGap=="number"&&Number.isFinite(e.columnGap)&&e.columnGap>=0?e.columnGap:xt.columnGap,cellGap:typeof e.cellGap=="number"&&Number.isFinite(e.cellGap)&&e.cellGap>=0?e.cellGap:xt.cellGap,containerPadding:typeof e.containerPadding=="number"&&Number.isFinite(e.containerPadding)&&e.containerPadding>=0?e.containerPadding:xt.containerPadding,titleGap:typeof e.titleGap=="number"&&Number.isFinite(e.titleGap)&&e.titleGap>=0?e.titleGap:xt.titleGap,horizontalAlign:Mo(e.horizontalAlign)?e.horizontalAlign:xt.horizontalAlign,verticalAlign:Io(e.verticalAlign)?e.verticalAlign:xt.verticalAlign,curve:typeof e.curve=="string"&&Yr.has(e.curve)?e.curve:xt.curve,edgeCornerRadius:kr(e.edgeCornerRadius)}}u(yi,"readGridConfig");function xi(t,e){const o=new Map;for(const n of t){const i=n.placementId??n.id;o.set(i,(o.get(i)??0)+1)}for(const[n,i]of e.placements){const r=o.get(n)??0;if(r===0){te.warn(an,`Ignoring grid placement for unknown target "${n}"`);continue}i.length>r&&te.warn(an,`Ignoring ${i.length-r} extra grid placement occurrence(s) for target "${n}"; found ${r} matching node(s)`)}}u(xi,"validateGridPlacementMap");function bi(t){return(e,o)=>{const n=t.get(e.id)??Number.MAX_SAFE_INTEGER,i=t.get(o.id)??Number.MAX_SAFE_INTEGER;return n!==i?n-i:U(e.id,o.id)}}u(bi,"itemComparator");function wi(t,e,o,n){const i=t.placementId??t.id,r=o.placements.get(i)?.[n]??{},s=Un(t.metadata);for(const d of["row","column","horizontalAlign","verticalAlign"])Object.hasOwn(r,d)&&Object.hasOwn(s,d)&&r[d]!==s[d]&&te.debug(an,"metadata overrides placement map",{nodeId:t.id,field:d,metadata:s[d],config:r[d]});const a=Object.hasOwn(s,"row")?s.row:r.row,c=Object.hasOwn(s,"column")?s.column:r.column;return fo(i,"row",a,t.id),fo(i,"column",c,t.id),{item:t,row:a??0,column:c??0,horizontalAlign:s.horizontalAlign??r.horizontalAlign??o.horizontalAlign,verticalAlign:s.verticalAlign??r.verticalAlign??o.verticalAlign,sourceOrder:e.get(t.id)??Number.MAX_SAFE_INTEGER,explicitRow:a!==void 0,explicitColumn:c!==void 0,explicitCell:a!==void 0&&c!==void 0}}u(wi,"resolveItemPlacement");function vi(t,e,o){let n=o;for(;e.has(`${t}:${n}`);)n++;return n}u(vi,"nextFreeColumn");function Ii(t,e,o){let n=o;for(;e.has(`${n}:${t}`);)n++;return n}u(Ii,"nextFreeRow");function Mi(t,e,o){let n=o;for(;;){const i=Math.floor(n/e)+1,r=n%e+1;if(n++,!t.has(`${i}:${r}`))return{row:i,column:r,nextIndex:n}}}u(Mi,"nextAutoCell");function Ci(t,e,o){const n=[...t].sort(bi(e)),i=new Map,r=n.map(f=>{const m=f.placementId??f.id,p=i.get(m)??0;return i.set(m,p+1),wi(f,e,o,p)}),s=new Map,a=new Set;for(const f of r){if(!f.explicitCell)continue;const m=`${f.row}:${f.column}`;a.add(m);const p=s.get(m);if(p){if(p.verticalAlign!==f.verticalAlign)throw H("GRID_CELL_ALIGNMENT_CONFLICT",`Conflicting vertical alignment in cell (${f.row}, ${f.column})`,{containerId:f.item.parentId??"root",row:f.row,column:f.column,itemIds:[...p.items.map(x=>x.item.id),f.item.id],values:[...p.items.map(x=>x.verticalAlign),f.verticalAlign]});p.items.push(f)}else s.set(m,{row:f.row,column:f.column,items:[f],width:0,height:0,verticalAlign:f.verticalAlign})}const c=o.columns>0?o.columns:Math.max(1,Math.ceil(Math.sqrt(n.length)));let d=0;const l=new Map,h=new Map;for(const f of r){if(f.explicitCell)continue;if(f.explicitRow){const p=vi(f.row,a,l.get(f.row)??1);f.column=p,l.set(f.row,p+1)}else if(f.explicitColumn){const p=Ii(f.column,a,h.get(f.column)??1);f.row=p,h.set(f.column,p+1)}else{const p=Mi(a,c,d);f.row=p.row,f.column=p.column,d=p.nextIndex}const m=`${f.row}:${f.column}`;a.add(m),s.set(m,{row:f.row,column:f.column,items:[f],width:0,height:0,verticalAlign:f.verticalAlign})}return{placements:r,cells:s}}u(Ci,"resolveGridPlacements");var Lt=class extends Error{constructor(t,e,o){super(e),this.reason=t,this.searchStateScope=o,this.name="GridRoutingResourceLimitError"}static{u(this,"GridRoutingResourceLimitError")}},V=6,qt=24,qr=5e4,Qr=4,zt=64*1024*1024,Zr=class{constructor(t,e){this.bands=t,this.strictBoundaryIntervals=e,this.byLow=new Map,this.byHigh=new Map,this.coordinateCount=new Set(t.flatMap(({low:n,high:i})=>[n,i])).size;let o=t.reduce((n,i)=>n+i.intervals.length,0);for(const n of e.values())o+=n.length;this.intervalCount=o;for(const n of t)this.byLow.set(n.low,n),this.byHigh.set(n.high,n);Object.freeze(this.bands),Object.freeze(this)}static{u(this,"CompressedIntervalIndex")}containingBand(t){let e=0,o=this.bands.length-1;for(;e<=o;){const n=e+o>>>1,i=this.bands[n];if(t<=i.low)o=n-1;else if(t>=i.high)e=n+1;else return i}}overlaps(t,e,o){let n=0,i=t.length;for(;n<i;){const r=n+i>>>1;t[r][1]<=e?n=r+1:i=r}return n<t.length&&t[n][0]<o}intersects(t,e,o){const n=Math.min(e,o),i=Math.max(e,o),r=this.byHigh.get(t),s=this.byLow.get(t),a=r||s?void 0:this.containingBand(t);if(a)return this.overlaps(a.intervals,n,i);if(!r||!s)return!1;let c=0,d=0;for(;c<r.intervals.length&&d<s.intervals.length;){const l=Math.max(n,r.intervals[c][0],s.intervals[d][0]),h=Math.min(i,r.intervals[c][1],s.intervals[d][1]);if(l<h)return!0;r.intervals[c][1]<s.intervals[d][1]?c++:d++}return!1}contains(t,e){const o=this.strictBoundaryIntervals.get(t)??this.containingBand(t)?.intervals;if(!o)return!1;let n=0,i=o.length;for(;n<i;){const r=n+i>>>1;o[r][0]<e?n=r+1:i=r}return n>0&&e<o[n-1][1]}nearestBoundary(t,e,o){const n=this.strictBoundaryIntervals.get(t)??this.containingBand(t)?.intervals;if(!n)return;if(o<0){let s=0,a=n.length;for(;s<a;){const c=s+a>>>1;n[c][1]<=e?s=c+1:a=c}return s>0?n[s-1][1]:void 0}let i=0,r=n.length;for(;i<r;){const s=i+r>>>1;n[s][0]<e?i=s+1:r=s}return i<n.length?n[i][0]:void 0}},mo,Ke=class{constructor(t){this.backing=t,this[mo]="ImmutableMap",Object.freeze(this)}static{u(this,"ImmutableMap")}get size(){return this.backing.size}entries(){return this.backing.entries()}forEach(t,e){for(const[o,n]of this.backing)t.call(e,n,o,this)}get(t){return this.backing.get(t)}has(t){return this.backing.has(t)}keys(){return this.backing.keys()}values(){return this.backing.values()}[(mo=Symbol.toStringTag,Symbol.iterator)](){return this.entries()}},yo,xo=class{constructor(t,e){this.base=t,this.overrides=e,this[yo]="OverlayMap"}static{u(this,"OverlayMap")}get size(){let t=0;for(const e of this.overrides.keys())this.base.has(e)||t++;return this.base.size+t}materialize(){return new Map([...this.base,...this.overrides])}entries(){return this.materialize().entries()}forEach(t,e){for(const[o,n]of this)t.call(e,n,o,this)}get(t){return this.overrides.get(t)??this.base.get(t)}has(t){return this.overrides.has(t)||this.base.has(t)}keys(){return this.materialize().keys()}values(){return this.materialize().values()}[(yo=Symbol.toStringTag,Symbol.iterator)](){return this.entries()}};function Si(t,e){return new Proxy([],{get(o,n){if(n==="length")return t.length+e.length;if(n===Symbol.iterator)return function*(){yield*t,yield*e};if(typeof n=="string"&&/^\d+$/.test(n)){const i=Number(n);return i<t.length?t[i]:e[i-t.length]}return Reflect.get(Array.prototype,n)}})}u(Si,"overlayArray");function cn(t,e,o){return new Proxy([],{get(n,i){if(i==="length")return o;if(i===Symbol.iterator)return function*(){for(let r=0;r<o;r++)yield e.get(r)??t[r]};if(typeof i=="string"&&/^\d+$/.test(i)){const r=Number(i);return e.get(r)??t[r]}return Reflect.get(Array.prototype,i)}})}u(cn,"overrideArray");var Ei=class{constructor(t){this.base=t,this.addedVertices=[],this.adjacencyOverrides=new Map,this.searchAdjacencyOverrides=new Map,this.pointOverrides=new Map,this.undoLog=[],this.resetCount=0}static{u(this,"EndpointOverlayScratch")}reset(t){if(t!==this.base)throw new Error("Endpoint overlay scratch cannot be shared across base topologies");for(const e of this.undoLog)this.adjacencyOverrides.delete(e),this.searchAdjacencyOverrides.delete(e);this.undoLog.length=0,this.addedVertices.length=0,this.pointOverrides.clear(),this.resetCount++}setArcs(t,e){this.adjacencyOverrides.has(t)||this.undoLog.push(t),this.adjacencyOverrides.set(t,e),this.searchAdjacencyOverrides.set(t,Yn(e))}};function _t(t){return Object.is(t,-0)?0:t}u(_t,"normalizeCoordinate");function xe(t){if(![t.left,t.right,t.top,t.bottom].every(Number.isFinite))throw new Error("Grid routing geometry must contain only finite coordinates");const o=_t(Math.min(t.left,t.right)),n=_t(Math.max(t.left,t.right)),i=_t(Math.min(t.top,t.bottom)),r=_t(Math.max(t.top,t.bottom));if(o===n||i===r)throw new Error("Grid routing rectangles must have positive area");return{left:o,right:n,top:i,bottom:r}}u(xe,"normalizeRect");function Ri(t,e){const o=xe(t.bounds),n={id:t.id,left:Math.max(e.left,o.left-V),right:Math.min(e.right,o.right+V),top:Math.max(e.top,o.top-V),bottom:Math.min(e.bottom,o.bottom+V)};return n.left<n.right&&n.top<n.bottom?n:void 0}u(Ri,"inflateAndClip");function Xn(t){const e=[...t].sort((n,i)=>n.low-i.low||n.high-i.high||U(n.id,i.id)),o=[];for(const n of e){const i=o.at(-1);if(!i||n.low>i.high){o.push({...n});continue}i.high=Math.max(i.high,n.high),U(n.id,i.id)<0&&(i.id=n.id)}return o}u(Xn,"mergeObstacleIntervals");function Ai(t){const e=new Map;for(const s of t){const a=e.get(s.left)??{starts:[],ends:[]};a.starts.push(s),e.set(s.left,a);const c=e.get(s.right)??{starts:[],ends:[]};c.ends.push(s),e.set(s.right,c)}const o=[...e.keys()].sort((s,a)=>s-a),n=new Set,i=[];let r=new Map;for(let s=0;s<o.length-1;s++){const a=o[s],c=o[s+1],d=e.get(a);for(const h of d.ends)n.delete(h);for(const h of d.starts)n.add(h);const l=new Map;for(const h of Xn([...n].map(f=>({low:f.top,high:f.bottom,id:f.id})))){const f=`${h.low}:${h.high}`,m=r.get(f);if(m)m.right=c,U(h.id,m.id)<0&&(m.id=h.id);else{const p={id:h.id,left:a,right:c,top:h.low,bottom:h.high};i.push(p),l.set(f,p);continue}l.set(f,m)}r=l}return i.sort((s,a)=>s.top-a.top||s.left-a.left||s.bottom-a.bottom||s.right-a.right||U(s.id,a.id))}u(Ai,"unionObstacles");function gt(t){return`${_t(t.x)}:${_t(t.y)}`}u(gt,"routingPointKey");function be(t){return t==="left"?0:t==="right"?1:t==="top"?2:t==="bottom"?3:4}u(be,"topologySideOrdinal");function je(t,e){return U(t.kind,e.kind)||be(t.side)-be(e.side)||t.point.x-e.point.x||t.point.y-e.point.y||U(t.ownerId??"",e.ownerId??"")}u(je,"vertexRecordOrder");function Ue(t){const e=new Map;for(const o of[...t].sort(je)){const n={...o,point:{x:_t(o.point.x),y:_t(o.point.y)}},i=gt(n.point);e.has(i)||e.set(i,n)}return[...e.values()]}u(Ue,"canonicalRecords");function dn(t,e,o="corner"){return[{point:{x:t.left,y:t.top},kind:o,ownerId:e},{point:{x:t.right,y:t.top},kind:o,ownerId:e},{point:{x:t.left,y:t.bottom},kind:o,ownerId:e},{point:{x:t.right,y:t.bottom},kind:o,ownerId:e}]}u(dn,"cornerRecords");function Oi(t,e){const o=t.coordinate??(t.side==="left"?e.left:t.side==="right"?e.right:t.side==="top"?e.top:e.bottom);return(t.side==="left"||t.side==="right"?[{x:o,y:t.low},{x:o,y:t.high}]:[{x:t.low,y:o},{x:t.high,y:o}]).map(i=>({point:i,kind:"portal",ownerId:t.ownerId,side:t.side}))}u(Oi,"portalRecords");function Wn(t,e,o,n,i){if(e==="left"||e==="right")return{x:n.nearestBoundary(t.y,t.x,e==="left"?-1:1)??(e==="left"?o.left:o.right),y:t.y};const r=i.nearestBoundary(t.x,t.y,e==="top"?-1:1)??(e==="top"?o.top:o.bottom);return{x:t.x,y:r}}u(Wn,"rayHit");function ln(t,e,o){const n=[...new Set(t.flatMap(h=>e==="H"?[h.top,h.bottom]:[h.left,h.right]))].sort((h,f)=>h-f),i=[],r=new Map,s=new Map,a=new Map;for(const h of t){const f=e==="H"?h.top:h.left,m=e==="H"?h.bottom:h.right,p=s.get(f)??[];p.push(h),s.set(f,p);const x=a.get(m)??[];x.push(h),a.set(m,x)}const c=new Set,d=u(()=>Xn([...c].map(h=>e==="H"?{low:h.left,high:h.right,id:h.id}:{low:h.top,high:h.bottom,id:h.id})),"activeIntervals"),l=u(h=>{const f=o.intervalCount+h.length;return Ht(Le(0,0,t.length,f),o.maxEstimatedBytes,"estimated_memory_cap"),o.intervalCount=f,Object.freeze(h.map(m=>Object.freeze([m.low,m.high])))},"freezeIntervals");for(let h=0;h<n.length;h++){const f=n[h];for(const x of a.get(f)??[])c.delete(x);r.set(f,l(d()));for(const x of s.get(f)??[])c.add(x);const m=n[h+1];if(m===void 0)continue;const p=d();p.length>0&&i.push({low:f,high:m,intervals:l(p)})}return new Zr(Object.freeze(i),new Ke(r))}u(ln,"createIntervalIndex");function Le(t,e,o,n){return t*64+e*56+o*48+n*24}u(Le,"estimatedTopologyBytes");function Ht(t,e,o){if(t>e)throw new Lt(o,`Grid routing ${o} exceeded: ${t} > ${e}`)}u(Ht,"enforceCap");function un(t,e){const o=new Map;for(const n of t){const i=e==="H"?n.point.y:n.point.x,r=o.get(i)??[];r.push(n),o.set(i,r)}for(const n of o.values())n.sort((i,r)=>e==="H"?i.point.x-r.point.x||i.id-r.id:i.point.y-r.point.y||i.id-r.id),Object.freeze(n);return new Ke(o)}u(un,"indexVertexLines");function Yn(t){return Object.freeze(t.map(e=>Object.freeze({to:e.to,orientationOrdinal:e.orientation==="H"?1:2,length:e.length,boundaryTransitions:e.kind==="portal"?1:0})))}u(Yn,"searchArcs");function Bi(t,e,o,n){const i=Ue(t).sort(je),r=n.maxVertices??qr;Ht(i.length,r,"vertex_cap");const s=i.map((f,m)=>Object.freeze({id:m,...f,point:Object.freeze({...f.point})})),a=new Map(s.map(f=>[f.id,[]])),c=u((f,m,p)=>{const x=Math.abs(f.point.x-m.point.x)+Math.abs(f.point.y-m.point.y);if(x===0)return;const g=p==="H"?Math.min(f.point.x,m.point.x):Math.min(f.point.y,m.point.y),y=g+x;for(const[b,I]of[[f,m],[m,f]])a.get(b.id).push({from:b.id,to:I.id,orientation:p,length:x,kind:"visibility",intervalStart:g,intervalEnd:y})},"addArcPair");for(const f of["H","V"]){const m=new Map;for(const p of s){const x=f==="H"?p.point.y:p.point.x,g=m.get(x)??[];g.push(p),m.set(x,g)}for(const[p,x]of m){x.sort((g,y)=>f==="H"?g.point.x-y.point.x||g.id-y.id:g.point.y-y.point.y||g.id-y.id);for(let g=1;g<x.length;g++){const y=x[g-1],b=x[g],I=f==="H"?y.point.x:y.point.y,C=f==="H"?b.point.x:b.point.y;(f==="H"?e:o).intersects(p,I,C)||c(y,b,f)}}}const d={visibility:0,terminal:1,portal:2,lane:3};let l=0;const h=new Map;for(const f of s){const m=a.get(f.id);m.sort((x,g)=>d[x.kind]-d[g.kind]||U(x.orientation,g.orientation)||s[x.to].point.x-s[g.to].point.x||s[x.to].point.y-s[g.to].point.y||x.to-g.to);const p=m.filter((x,g)=>g===0||x.to!==m[g-1].to||x.orientation!==m[g-1].orientation||x.kind!==m[g-1].kind);l+=p.length,h.set(f.id,Object.freeze(p.map(x=>Object.freeze(x))))}return Ht(l,n.maxAdjacencyEntries??r*Qr,"adjacency_cap"),{vertices:Object.freeze(s),adjacency:new Ke(h),adjacencyEntries:l}}u(Bi,"buildVisibilityGraph");function ne(t,e,o){const n=xe(e),i=o?xe(o):void 0,r=Math.max(n.top+V,(i?.bottom??-1/0)+V),s=n.bottom-V,a=n.left+V,c=n.right-V,d=[];return r<=s&&d.push({ownerId:t,side:"left",low:r,high:s},{ownerId:t,side:"right",low:r,high:s}),a<=c&&(d.push({ownerId:t,side:"bottom",low:a,high:c}),(!i||i.bottom+V<=n.top)&&d.push({ownerId:t,side:"top",low:a,high:c})),d}u(ne,"derivePortalRanges");function hn(t,e,o,n,i){const r=ne(t,e,o).find(h=>h.side===n);if(!r||i<r.low||i>r.high)throw new Error(`Illegal ${n} portal for "${t}" at ${i}`);const s=n==="left"?e.left:n==="right"?e.right:n==="top"?e.top:e.bottom,a=n==="left"||n==="top"?s+V:s-V,c=n==="left"||n==="top"?s-V:s+V,d=n==="left"||n==="right"?{x:a,y:i}:{x:i,y:a},l=n==="left"||n==="right"?{x:c,y:i}:{x:i,y:c};return{ownerId:t,side:n,tangentialCoordinate:i,interior:d,exterior:l,transition:{from:d,to:l,orientation:n==="left"||n==="right"?"H":"V",length:V*2,kind:"portal"}}}u(hn,"buildPairedPortal");function Li(t,e={}){const o=xe(t.bounds),n=[...t.obstacles,...t.titleExclusions??[]].map(g=>Ri(g,o)).filter(g=>!!g),i=Ai(n),r=[...t.portalRanges??[]].sort((g,y)=>be(g.side)-be(y.side)||g.low-y.low||g.high-y.high||U(g.ownerId,y.ownerId)),s=Ue([...dn(o,t.containerId),...i.flatMap(g=>dn(g,g.id)),...r.flatMap(g=>Oi(g,o))]),a={intervalCount:0,maxEstimatedBytes:e.caps?.maxEstimatedBytes??zt};Ht(Le(0,0,i.length,0),a.maxEstimatedBytes,"estimated_memory_cap");const c=ln(i,"H",a),d=ln(i,"V",a),l=[],h=["left","right","top","bottom"];for(const g of s)for(const y of h){const b=Wn(g.point,y,o,c,d);(b.x!==g.point.x||b.y!==g.point.y)&&l.push({point:b,kind:"projection",side:y})}const{vertices:f,adjacency:m,adjacencyEntries:p}=Bi([...s,...l],c,d,e.caps??{}),x=Le(f.length,p,i.length,c.intervalCount+d.intervalCount);return Ht(x,e.caps?.maxEstimatedBytes??zt,"estimated_memory_cap"),e.metrics&&(e.metrics.containersBuilt++,e.metrics.baseTopologyBuilds++,e.metrics.baseVertices+=f.length,e.metrics.baseAdjacencyEntries+=p,e.metrics.buildSweepEvents+=s.length*4+i.length*4,e.metrics.estimatedBytes+=x),Object.freeze({containerId:t.containerId,bounds:Object.freeze(o),obstacles:Object.freeze(i.map(g=>Object.freeze(g))),vertices:Object.freeze(f),pointVertexIds:new Ke(new Map(f.map(({id:g,point:y})=>[gt(y),g]))),horizontalVertexLines:un(f,"H"),verticalVertexLines:un(f,"V"),adjacency:m,adjacencyByVertex:Object.freeze(f.map(({id:g})=>m.get(g)??[])),searchAdjacencyByVertex:Object.freeze(f.map(({id:g})=>Yn(m.get(g)??[]))),adjacencyEntries:p,horizontalIntervals:c,verticalIntervals:d,portalRanges:Object.freeze(r.map(g=>Object.freeze(g))),seedCount:s.length,estimatedBytes:x})}u(Li,"buildContainerRoutingTopology");function fn(t,e){return e.contains(t.y,t.x)}u(fn,"pointInsideObstacle");function Xe(t,e,o,n,i,r=[]){const s=i??new Ei(t);s.reset(t);const a=[{point:e,kind:"endpoint",ownerId:"source"},{point:o,kind:"endpoint",ownerId:"target"},...r.filter(v=>!fn(v,t.horizontalIntervals)).map(v=>({point:v,kind:"lane"}))];for(const v of[{x:e.x,y:o.y},{x:o.x,y:e.y}])fn(v,t.horizontalIntervals)||a.push({point:v,kind:"projection"});for(const v of a.slice(0,2))for(const w of["left","right","top","bottom"]){const E=Wn(v.point,w,t.bounds,t.horizontalIntervals,t.verticalIntervals);(E.x!==v.point.x||E.y!==v.point.y)&&a.push({point:E,kind:"projection",side:w})}const c=Ue(a).filter(({point:v})=>!t.pointVertexIds.has(gt(v))).sort(je);Ht(c.length,32,"vertex_cap"),s.addedVertices.push(...c.map((v,w)=>Object.freeze({id:t.vertices.length+w,...v,point:Object.freeze({...v.point})})));const d=Si(t.vertices,s.addedVertices),l=u(v=>v<t.vertices.length?t.vertices[v]:s.addedVertices[v-t.vertices.length],"vertexAt"),h=new Map,f=u(v=>{let w=h.get(v);return w||(w=[...t.adjacency.get(v)??[]],h.set(v,w)),w},"mutableArcs");for(const v of s.addedVertices)h.set(v.id,[]);const m=new Set(s.addedVertices.map(({id:v})=>v)),p=new Set,x=u((v,w,E)=>{const R=Math.abs(v.point.x-w.point.x)+Math.abs(v.point.y-w.point.y);if(R===0)return;const M=E==="H"?Math.min(v.point.x,w.point.x):Math.min(v.point.y,w.point.y),A=M+R;for(const[L,B]of[[v,w],[w,v]]){const T=`${L.id}:${B.id}:${E}:visibility`;p.has(T)||(t.adjacency.get(L.id)??[]).some(G=>G.to===B.id&&G.orientation===E&&G.kind==="visibility")||(p.add(T),f(L.id).push({from:L.id,to:B.id,orientation:E,length:R,kind:"visibility",intervalStart:M,intervalEnd:A}))}},"connect");for(const v of["H","V"]){const w=v==="H"?t.horizontalVertexLines:t.verticalVertexLines,E=new Set(s.addedVertices.map(({point:R})=>v==="H"?R.y:R.x));for(const R of E){const M=[...w.get(R)??[],...s.addedVertices.filter(({point:A})=>(v==="H"?A.y:A.x)===R)];M.sort((A,L)=>v==="H"?A.point.x-L.point.x||A.id-L.id:A.point.y-L.point.y||A.id-L.id);for(let A=1;A<M.length;A++){const L=M[A-1],B=M[A];if(!m.has(L.id)&&!m.has(B.id))continue;const T=v==="H"?L.point.x:L.point.y,G=v==="H"?B.point.x:B.point.y;(v==="H"?t.horizontalIntervals:t.verticalIntervals).intersects(R,T,G)||x(L,B,v)}}}for(const[v,w]of h){w.sort((R,M)=>U(R.kind,M.kind)||U(R.orientation,M.orientation)||l(R.to).point.x-l(M.to).point.x||l(R.to).point.y-l(M.to).point.y||R.to-M.to);const E=Object.freeze(w.map(R=>Object.freeze(R)));s.setArcs(v,E)}const g=t.adjacencyEntries+p.size;Ht(g,t.adjacencyEntries+64,"adjacency_cap");const y=c.length,b=t.estimatedBytes+y*64+(g-t.adjacencyEntries)*56;n&&(n.endpointOverlayBuilds++,n.endpointOverlayVertices+=y,n.estimatedBytes=Math.max(n.estimatedBytes,b));const I=t.vertices.length+s.addedVertices.length,C=cn(t.adjacencyByVertex,s.adjacencyOverrides,I),S=cn(t.searchAdjacencyByVertex,s.searchAdjacencyOverrides,I);for(const v of s.addedVertices)s.pointOverrides.set(gt(v.point),v.id);return Object.freeze({...t,vertices:d,pointVertexIds:new xo(t.pointVertexIds,s.pointOverrides),adjacency:new xo(t.adjacency,s.adjacencyOverrides),adjacencyByVertex:C,searchAdjacencyByVertex:S,adjacencyEntries:g,estimatedBytes:b,vertexCount:I,getVertex:l,getSearchArcs:u(v=>s.searchAdjacencyOverrides.get(v)??t.searchAdjacencyByVertex[v]??[],"getSearchArcs")})}u(Xe,"buildEndpointRoutingOverlay");var we=4,q=20,Pe=8;function We(t){return!!t.groupTitleRect}u(We,"ownerGroupTitle");function oe(t,e){return JSON.stringify([t,e])}u(oe,"ownerSideKey");function Ye(t,e){const o=k(t),n=e.x-o.cx,i=e.y-o.cy,r=t.isGroup&&We(t);return Math.abs(n)>=Math.abs(i)?n>=0?"right":"left":i>=0?"bottom":r?n>=0?"right":"left":"top"}u(Ye,"preferredSide");function _e(t,e){const o=[];let n=t.parentId??j;const i=new Set;for(;o.push(n),!(n===j||i.has(n));)i.add(n),n=e.get(n)?.parentId??j;return o}u(_e,"containerChain");function Pi(t,e,o){if(t.isGroup&&kt(t.id,e,o))return t.parentId??j;if(e.isGroup&&kt(e.id,t,o))return e.parentId??j;const n=new Set(_e(e,o));for(const i of _e(t,o))if(n.has(i))return i;return j}u(Pi,"commonContainerId");function Ge(t,e){return e==="left"||e==="right"?t.cy:t.cx}u(Ge,"oppositeCoordFor");function ie(t,e){return e==="left"||e==="right"?{x:e==="left"?t.left:t.right,y:t.cy}:{x:t.cx,y:e==="top"?t.top:t.bottom}}u(ie,"sideMidpoint");function Te(t,e){return e==="left"||e==="right"?t.y:t.x}u(Te,"tangentialCoordinate");function gn(t,e,o,n,i,r){const s=[],a=k(t),c=k(e),d={x:e.x??0,y:e.y??0};let l=t;for(;;){const h=l.parentId??j,f=n.get(h),m={x:l.x??0,y:l.y??0},p=d.x-m.x,x=d.y-m.y,g=x<0&&Math.abs(p)<=nt&&!!((l.isGroup?l.groupTitleRect:void 0)??f?.groupTitleRect),y=[];Math.abs(Math.abs(p)-Math.abs(x))<=nt&&Math.abs(p)>nt&&y.push(p>=0?"right":"left",x>=0?"bottom":"top");const b=!!((l.isGroup?l.groupTitleRect:void 0)??f?.groupTitleRect),I=(g?["left","right"]:y).filter(S=>S!=="top"||!b);let C=Ye(l,d);if(C==="top"&&f?.groupTitleRect&&(C=p>=0?"right":"left"),s.push({ownerId:l.id,side:C,demandKey:JSON.stringify([i,r,l.id,C]),oppositeCoord:Ge(c,C),preferredCoord:Ge(a,C),compactPortal:l.id!==t.id,ambiguousSides:I.length>1?I:void 0,inner:s.length?{demandKey:s[s.length-1].demandKey,side:s[s.length-1].side}:void 0}),l.isGroup&&l.id===o&&kt(l.id,e,n))return{chain:s,finalKind:"boundary"};if(h===o)return{chain:s,finalKind:"item"};if(!f?.isGroup)throw H("GRID_INVALID_CONTAINMENT",`Missing parent group "${h}"`,{traversedIds:s.map(S=>S.ownerId)});l=f}}u(gn,"buildEndpointPlan");function _i(t){const e=new Map;for(const n of t){if(!n.start||!n.end)continue;const i=n.start<n.end?`${n.start}|${n.end}`:`${n.end}|${n.start}`;e.has(i)||e.set(i,[]),e.get(i).push(n)}const o=new Map;for(const[n,i]of e)i.sort((r,s)=>U(`${r.start}|${r.end}`,`${s.start}|${s.end}`)||U(r.id,s.id)),i.forEach((r,s)=>o.set(r.id,{index:s,size:i.length,offset:(s-(i.length-1)/2)*Pe,pairKey:n}));return o}u(_i,"buildPairLanes");function Gi(t,e){const o=new Map,n=u((s,a)=>oe(s,a),"reservationKey");for(const s of t)for(const a of[...s.source.chain,...s.target.chain])if(!a.ambiguousSides){const c=n(a.ownerId,a.side);o.set(c,(o.get(c)??0)+1)}const i=u((s,a,c)=>{const d=a.chain.filter(({ambiguousSides:f})=>f);if(d.length===0)return;const h=["right","bottom","left","top"].filter(f=>d.every(m=>m.ambiguousSides?.includes(f))&&d.every(m=>{const p=e.forest.nodeById.get(m.ownerId);return p!==void 0&&Rt(p,f)!==void 0})).sort((f,m)=>d.reduce((p,x)=>p+(o.get(n(x.ownerId,f))??0),0)-d.reduce((p,x)=>p+(o.get(n(x.ownerId,m))??0),0)||+(f!==d[0].side)-+(m!==d[0].side))[0];if(h){for(const f of d){f.side=h;const m=n(f.ownerId,h);o.set(m,(o.get(m)??0)+1);const p=e.forest.nodeById.get(f.ownerId);p&&(f.preferredCoord=Ge(k(p),h))}for(const[f,m]of a.chain.entries())m.demandKey=JSON.stringify([s.edge.id,c,m.ownerId,m.side]),m.inner=f>0?{demandKey:a.chain[f-1].demandKey,side:a.chain[f-1].side}:void 0}},"resolveEndpoint"),r=t.flatMap(s=>[{plan:s,endpoint:s.source,role:"source"},{plan:s,endpoint:s.target,role:"target"}]).sort((s,a)=>U(`${s.plan.edge.start??""}|${s.plan.edge.end??""}|${s.plan.edge.id}|${s.role}`,`${a.plan.edge.start??""}|${a.plan.edge.end??""}|${a.plan.edge.id}|${a.role}`));for(const{plan:s,endpoint:a,role:c}of r)i(s,a,c);for(const s of t){const a=s.source.chain.at(-1),c=s.target.chain.at(-1),d=a?e.forest.nodeById.get(a.ownerId):void 0,l=c?e.forest.nodeById.get(c.ownerId):void 0;if(!a||!c||!d||!l)continue;const h=ie(k(d),a.side),f=ie(k(l),c.side);for(const m of s.source.chain)m.oppositeCoord=Te(f,m.side);for(const m of s.target.chain)m.oppositeCoord=Te(h,m.side)}}u(Gi,"resolveAmbiguousEndpointSides");function Ti(t,e){const o=e.forest.nodeById,n=_i(t.edges),i=t.edges.map(r=>{const s=r.start?o.get(r.start):void 0,a=r.end?o.get(r.end):void 0;if(!s||!a)throw H("GRID_MISSING_ENDPOINT",`Missing endpoint for edge "${r.id}"`,{edgeId:r.id,start:r.start,end:r.end});const c=Pi(s,a,o),d=n.get(r.id)??{index:0,size:1,offset:0,pairKey:Ot(r)};return{edge:r,lcaContainerId:c,source:gn(s,a,c,o,r.id,"source"),target:gn(a,s,c,o,r.id,"target"),laneIndex:d.index,laneOffset:d.offset,bundleSize:d.size,pairKey:d.pairKey}});return Gi(i,e),i}u(Ti,"collectRoutePlans");function qn(t,e,o){const n=[];for(const[d,l]of t.entries())n.push(d===0?l:Math.max(l,n[d-1]+we));for(let d=n.length-1;d>=0;d--)n[d]=Math.min(n[d],d===n.length-1?o:n[d+1]-we);const i=t.reduce((d,l)=>d+l,0)/t.length,r=n.reduce((d,l)=>d+l,0)/n.length,s=e-n[0],a=o-n[n.length-1],c=Bt(i-r,s,a);return n.map(d=>d+c)}u(qn,"assignCompactPortalCoordinates");function Ni(t,e,o){const n=e.forest.nodeById,i=new Map(t.map(l=>[l.edge.id,l])),r=new Map;for(const l of t)if(l.edge.start!==l.edge.end)for(const h of[...l.source.chain,...l.target.chain])r.has(h.demandKey)||r.set(h.demandKey,{ownerId:h.ownerId,side:h.side,edgeId:l.edge.id,demandKey:h.demandKey,oppositeCoord:h.oppositeCoord,preferredCoord:h.preferredCoord,compactPortal:h.compactPortal,inner:h.inner});const s=new Map;for(const l of r.values()){const h=oe(l.ownerId,l.side),f=s.get(h)??{ownerId:l.ownerId,side:l.side,demands:[]};f.demands.push(l),s.set(h,f)}const a=u(l=>{const h=n.get(l);return h?_e(h,n).length:0},"depthOf"),c=[...s.values()].sort((l,h)=>Number(l.demands.every(f=>f.compactPortal))-Number(h.demands.every(f=>f.compactPortal))||a(h.ownerId)-a(l.ownerId)),d=new Map;for(const{ownerId:l,side:h,demands:f}of c){const m=n.get(l);if(!m)continue;const p=k(m);let x=h==="left"||h==="right"?p.top+V:p.left+V;const g=h==="left"||h==="right"?p.bottom-V:p.right-V;(h==="left"||h==="right")&&m.groupTitleRect&&(x=Math.max(x,m.groupTitleRect.bottom+V));const y=Math.max(0,g-x);f.sort((v,w)=>v.oppositeCoord-w.oppositeCoord||U(v.edgeId,w.edgeId));const b=f.map(v=>i.get(v.edgeId)),I=new Set(b.map(v=>v?.pairKey)),C=m.isGroup&&f.every(({compactPortal:v})=>v);if(!(C&&f.length===1)&&I.size===1&&b.every(v=>v&&v.bundleSize===f.length&&o.get(v.edge.start)===v.bundleSize&&o.get(v.edge.end)===v.bundleSize)){const v=(x+g)/2,w=b.map(E=>v+E.laneOffset);if(w.every(E=>E>=x&&E<=g)){f.forEach((E,R)=>d.set(E.demandKey,w[R]));continue}}if(C){const v=e.containers.get(m.id),w=h==="left"||h==="right"?v?.horizontalCorridors:v?.verticalCorridors,E=u(M=>{const A=M.inner?r.get(M.inner.demandKey):void 0,L=A?n.get(A.ownerId):void 0,B=A?d.get(A.demandKey):void 0;if(!A||!L||B===void 0)return M.preferredCoord;const T=ie(k(L),A.side);return A.side==="left"||A.side==="right"?T.y=B:T.x=B,Te(T,h)},"innerCoordinate"),R=u(M=>{const A=M.inner?d.get(M.inner.demandKey):void 0,L=M.inner!==void 0&&A!==void 0&&(M.inner.side==="left"||M.inner.side==="right")==(h==="left"||h==="right"),B=Bt(L?A:M.preferredCoord,x,g),T=w?.reduce((G,X)=>Math.abs(X-B)<Math.abs(G-B)?X:G,w[0]);return T!==void 0&&Math.abs(T-B)<=nt?T:B},"preferredCoordinate");if(f.length===1){d.set(f[0].demandKey,R(f[0]));continue}if(y>=we*(f.length-1)){f.sort((L,B)=>E(L)-E(B)||L.oppositeCoord-B.oppositeCoord||U(L.edgeId,B.edgeId));const M=f.map(R),A=qn(M,x,g);f.forEach((L,B)=>d.set(L.demandKey,A[B]));continue}}if(f.length===1||y<=0){d.set(f[0].demandKey,(x+g)/2);continue}const S=y/(f.length-1);f.forEach((v,w)=>{d.set(v.demandKey,x+S*w)})}for(const l of t){if(l.bundleSize!==1)continue;const h=l.source.chain.at(-1),f=l.target.chain.at(-1);if(!h||!f)continue;const m=u(b=>b==="left"||b==="right","verticalSide");if(m(h.side)!==m(f.side))continue;const p=d.get(h.demandKey),x=d.get(f.demandKey);if(p===void 0||x===void 0||Math.abs(p-x)>nt)continue;const g=[...l.source.chain,...l.target.chain];if(g.some(b=>m(b.side)!==m(h.side)))continue;const y=[p,x].find(b=>g.every(I=>{const C=n.get(I.ownerId),S=C?Rt(C,I.side):void 0;return S!==void 0&&b>=S.low-nt&&b<=S.high+nt}));y!==void 0&&g.forEach(b=>d.set(b.demandKey,y))}return d}u(Ni,"assignDemandCoordinates");function Gt(t){return t==="right"?0:t==="bottom"?1:t==="left"?2:3}u(Gt,"sideOrder");function Rt(t,e){const o=k(t);if(e==="top"&&t.groupTitleRect)return;let n=e==="left"||e==="right"?o.top+V:o.left+V;const i=e==="left"||e==="right"?o.bottom-V:o.right-V;return(e==="left"||e==="right")&&t.groupTitleRect&&(n=Math.max(n,t.groupTitleRect.bottom+V)),n<=i?{low:n,high:i}:void 0}u(Rt,"sideInterval");function Ot(t){const e=t.start??"",o=t.end??"";return e<o?`${e}|${o}`:`${o}|${e}`}u(Ot,"endpointPairKey");function Qn(t,e,o){const n=k(t.opposite),i=k(e.opposite),r=o==="left"||o==="right"?n.cy:n.cx,s=o==="left"||o==="right"?i.cy:i.cx;return r-s||U(Ot(t.plan.edge),Ot(e.plan.edge))||U(`${t.plan.edge.start}|${t.plan.edge.end}`,`${e.plan.edge.start}|${e.plan.edge.end}`)||U(t.plan.edge.id,e.plan.edge.id)||U(t.role,e.role)}u(Qn,"compareEndpointDemands");function Fi(t){return`${t.plan.edge.id}:${t.role}`}u(Fi,"endpointDemandKey");function Di(t,e){return U(Ot(t.plan.edge),Ot(e.plan.edge))||U(`${t.plan.edge.start}|${t.plan.edge.end}`,`${e.plan.edge.start}|${e.plan.edge.end}`)||U(t.plan.edge.id,e.plan.edge.id)||U(t.role,e.role)}u(Di,"compareEndpointDemandIdentity");function Ne(t,e,o){const n=Rt(t,e);if(!n||o.length===0)return new Map;const i=[...o].sort((a,c)=>Qn(a,c,e));if(i.length===1){const a=k(t),c=e==="left"||e==="right"?a.cy:a.cx;return new Map([[i[0],Bt(c,n.low,n.high)]])}if((n.high-n.low)/(i.length-1)<we)return new Map(i.map((a,c)=>[a,n.low+c*(n.high-n.low)/(i.length-1)]));const r=i.map(({opposite:a})=>{const c=k(a),d=e==="left"||e==="right"?c.cy:c.cx;return Bt(d,n.low,n.high)}),s=qn(r,n.low,n.high);return new Map(i.map((a,c)=>[a,s[c]]))}u(Ne,"preferredEndpointCoordinates");function Zn(t,e){const o=Rt(t,e);return o?1+Math.floor((o.high-o.low)/we):0}u(Zn,"endpointSideCapacity");function pn(t,e){const o=k(e.opposite),n=Ye(t,{x:o.cx,y:o.cy});return["right","bottom","left","top"].filter(i=>Zn(t,i)>0).sort((i,r)=>{if(i===n)return-1;if(r===n)return 1;const s=k(t),a=ie(s,i),c=ie(s,r),d=Math.abs(a.x-o.cx)+Math.abs(a.y-o.cy),l=Math.abs(c.x-o.cx)+Math.abs(c.y-o.cy);return d-l||Gt(i)-Gt(r)})}u(pn,"endpointSidePreferences");function Qt(t,e){const o=k(t),n=k(e.opposite);return Math.abs(o.cx-n.cx)<=nt||Math.abs(o.cy-n.cy)<=nt}u(Qt,"isAxisAlignedDemand");function ki(t,e,o,n){const i=Rt(t,e);if(!i)return;const r=[...o],s=new Map;for(const a of n){const c=k(a.opposite),d=Bt(e==="left"||e==="right"?c.cy:c.cx,i.low,i.high),l=[d,i.low,i.high,...r.flatMap(h=>[h-qt,h+qt])].filter(h=>h>=i.low-nt&&h<=i.high+nt&&r.every(f=>Math.abs(h-f)>=qt-nt)).sort((h,f)=>Math.abs(h-d)-Math.abs(f-d)||h-f);if(l.length===0)return;s.set(a,l[0]),r.push(l[0])}return s}u(ki,"placePortsBesideFixed");function zi(t,e){const o=new Map,n=new Map(["right","bottom","left","top"].map(g=>[g,Zn(t,g)])),i=[...e].sort(Di),r=i.filter(g=>Qt(t,g)),s=i.filter(g=>!Qt(t,g)),a=new Set,c=new Map,d=new Map,l=u(g=>(o.get(g)?.length??0)<(n.get(g)??0),"hasCapacity"),h=u((g,y)=>{const b=o.get(y)??[];b.push(g),o.set(y,b)},"record"),f=u(g=>{const y=pn(t,g).find(l);y&&(h(g,y),a.add(y))},"assignAligned"),m=u((g,y)=>{const b=d.get(y)??new Map,I=ki(t,y,[...c.get(y)??[],...b.values()],[g]);return I?(b.set(g,I.get(g)),d.set(y,b),h(g,y),!0):!1},"tryShareReservedSide"),p=u(g=>{const y=pn(t,g).filter(l),b=y.find(S=>!a.has(S));if(y.find(S=>(b===void 0||y.indexOf(S)<y.indexOf(b))&&a.has(S)&&m(g,S)))return;const C=b??y[0];C&&h(g,C)},"assignUnaligned");for(const g of r)f(g);for(const[g,y]of o)c.set(g,[...Ne(t,g,y).values()]);for(const g of s)p(g);const x=new Map;for(const[g,y]of o){const b=Rt(t,g);if(!b)continue;const I=d.get(g),C=I?y.filter(w=>!I.has(w)):y,S=new Map([...Ne(t,g,C),...I??[]]),v=[...y].sort((w,E)=>Qn(w,E,g));for(const[w,E]of v.entries()){const R=S.get(E)??(v.length===1?(b.low+b.high)/2:b.low+w*(b.high-b.low)/(v.length-1));x.set(Fi(E),{side:g,coordinate:R})}}return x}u(zi,"allocateEndpointSlots");function mn(t,e,o,n,i,r){const s=e==="source"?t.edge.start:t.edge.end,a=e==="source"?t.edge.end:t.edge.start,c=r.forest.nodeById.get(s),d=r.forest.nodeById.get(a);if(!c||!d)throw H("GRID_MISSING_ENDPOINT",`Missing endpoint for edge "${t.edge.id}"`);const l=k(d),h=[],f=new Set,m=n.get(s)?.get(`${t.edge.id}:${e}`),p=i.has(s)&&m!==void 0,x=u((y,b,I)=>{const C=Rt(c,y);if(!C||b<C.low||b>C.high)return;const S=k(c),v=y==="left"||y==="right"?{x:y==="left"?S.left:S.right,y:b}:{x:b,y:y==="top"?S.top:S.bottom},w=`${y}:${gt(v)}`;f.has(w)||(f.add(w),h.push({ownerId:s,side:y,port:v,connect:{x:v.x+(y==="left"?-q:y==="right"?q:0),y:v.y+(y==="top"?-q:y==="bottom"?q:0)},rank:I,onAssignedSide:p?y===m.side:void 0}))},"addCandidate");if(m&&t.bundleSize===1&&x(m.side,m.coordinate,-2),t.bundleSize>1){const y=Ye(c,{x:l.cx,y:l.cy}),b=k(c),I=y==="left"||y==="right"?b.cy:b.cx;x(y,I+t.laneOffset,-1)}const g=[...o.get(s)??[]];for(const y of["right","bottom","left","top"]){if(!Rt(c,y))continue;const I=Ne(c,y,g),C=g.find(R=>R.plan===t&&R.role===e),S=C?I.get(C):void 0;if(S===void 0)continue;const v=k(c),w=y==="left"||y==="right"?{x:y==="left"?v.left:v.right,y:S}:{x:S,y:y==="top"?v.top:v.bottom},E=Math.abs(w.x-l.cx)+Math.abs(w.y-l.cy);x(y,S,E)}return h.sort((y,b)=>y.rank-b.rank||Gt(y.side)-Gt(b.side)),h.forEach((y,b)=>{y.rank=b}),h}u(mn,"endpointCandidates");function Hi(t,e){const o=Ti(t,e),n=new Map,i=new Map;for(const p of o){const x=Ot(p.edge);n.set(x,(n.get(x)??0)+1),p.edge.start&&i.set(p.edge.start,(i.get(p.edge.start)??0)+1),p.edge.end&&p.edge.end!==p.edge.start&&i.set(p.edge.end,(i.get(p.edge.end)??0)+1)}const r=o.filter(p=>p.edge.start!==p.edge.end&&p.source.chain.length===1&&p.target.chain.length===1&&p.source.finalKind==="item"&&p.target.finalKind==="item"),s=new Map;for(const p of r){const x=e.forest.nodeById.get(p.edge.start),g=e.forest.nodeById.get(p.edge.end);if(!x||!g)continue;const y=s.get(x.id)??[];y.push({plan:p,role:"source",opposite:g}),s.set(x.id,y);const b=s.get(g.id)??[];b.push({plan:p,role:"target",opposite:x}),s.set(g.id,b)}const a=new Map([...s].map(([p,x])=>{const g=e.forest.nodeById.get(p);return[p,g?zi(g,x):new Map]})),c=new Set,d=new Set;for(const[p,x]of s){const g=e.forest.nodeById.get(p);if(!g)continue;const y=x.some(I=>Qt(g,I)),b=x.some(I=>!Qt(g,I));if(y&&b){d.add(p);for(const I of x)Qt(g,I)||c.add(I.plan.edge.id)}}const l=new Map(r.map(p=>[p.edge.id,{sources:mn(p,"source",s,a,d,e),targets:mn(p,"target",s,a,d,e)}])),h=new Map([...l].map(([p,x])=>[p,x.sources.length*x.targets.length])),f=u(p=>{const x=e.forest.nodeById.get(p.edge.start),g=e.forest.nodeById.get(p.edge.end);return p.edge.start===p.edge.end?0:x?.isGroup&&g&&kt(x.id,g,e.forest.nodeById)||g?.isGroup&&x&&kt(g.id,x,e.forest.nodeById)?1:(x?.parentId??j)!==(g?.parentId??j)?2:n.get(Ot(p.edge))>1?3:4},"routeClass"),m=[...o].sort((p,x)=>{const g=Ot(p.edge),y=Ot(x.edge),b=`${p.edge.start??""}|${p.edge.end??""}`,I=`${x.edge.start??""}|${x.edge.end??""}`,C=p.source.chain.length+p.target.chain.length-2,S=x.source.chain.length+x.target.chain.length-2;return f(p)-f(x)||S-C||(h.get(p.edge.id)??0)-(h.get(x.edge.id)??0)||U(g,y)||U(b,I)||U(p.edge.id,x.edge.id)});return{plans:o,eligiblePlans:r,eligibleIds:new Set(r.map(({edge:p})=>p.id)),orderedPlans:m,demandCoords:Ni(m,e,i),endpointCandidatesByEdge:l,endpointIncidentCounts:i,coordinatedEndpointIds:c}}u(Hi,"prepareEdgeRoutes");function Vi(t){if(!(t instanceof Error)||!("details"in t))return!1;const e=t.details;return typeof e=="object"&&e!==null&&"reason"in e&&e.reason==="pair-separation"}u(Vi,"isPairSeparationError");function Pt(t){const e=k(t);return{left:e.left,right:e.right,top:e.top,bottom:e.bottom}}u(Pt,"routerRect");function Jn(t){if(t.length<2||t.some(({x:i,y:r})=>!Number.isFinite(i)||!Number.isFinite(r)))return;const e=[{...t[0]}];for(let i=1;i<t.length;i++){const r=t[i],s=e.at(-1);if(!(Math.abs(r.x-s.x)<=nt&&Math.abs(r.y-s.y)<=nt)){e.push({...r});continue}if(i===t.length-1){for(;e.length>1;){const c=e.at(-2);if(Math.abs(r.x-c.x)>nt||Math.abs(r.y-c.y)>nt)break;e.pop()}if(e.length===1)return;e[e.length-1]={...r}}}if(e.length<2)return;const o=[];for(let i=0;i<e.length-1;i++){const r=e[i],s=e[i+1],a=Math.abs(s.x-r.x);if(Math.abs(s.y-r.y)<=nt)o.push("H");else if(a<=nt)o.push("V");else return}const n=e.map(i=>({...i}));for(let i=0;i<o.length;){const r=o[i];let s=i+1;for(;s<o.length&&o[s]===r;)s++;const a=r==="H"?"y":"x";if(i===0&&s===e.length-1&&e[i][a]!==e[s][a])return;const c=s===e.length-1?e[s][a]:e[i][a];for(let d=i;d<=s;d++){if(Math.abs(e[d][a]-c)>nt)return;n[d][a]=c}i=s}return n}u(Jn,"canonicalizeOrthogonalPolyline");function ve(t,e,o){return t.y===e.y?t.y>o.top&&t.y<o.bottom&&Math.max(t.x,e.x)>o.left&&Math.min(t.x,e.x)<o.right:t.x===e.x?t.x>o.left&&t.x<o.right&&Math.max(t.y,e.y)>o.top&&Math.min(t.y,e.y)<o.bottom:!0}u(ve,"segmentEntersRect");function to(t){const e=Pt(t);return{left:e.left-V,right:e.right+V,top:e.top-V,bottom:e.bottom+V}}u(to,"inflatedRect");function Et(t,e,o,n,i){const r=Jn(t);if(!r)return!1;const s=z(r);if(s.points.length<2||s.segments.length>1&&(Math.abs(s.segments[0].a.x-s.segments[0].b.x)+Math.abs(s.segments[0].a.y-s.segments[0].b.y)<q||Math.abs(s.segments.at(-1).a.x-s.segments.at(-1).b.x)+Math.abs(s.segments.at(-1).a.y-s.segments.at(-1).b.y)<q))return!1;const a=(i.forest.childrenByParent.get(n)??[]).filter(c=>!pt(c));for(const c of a){const d=to(c);for(let l=0;l<s.points.length-1;l++){if(c.id===e.id&&l===0||c.id===o.id&&l===s.points.length-2){if(ve(s.points[l],s.points[l+1],Pt(c)))return!1;continue}if(ve(s.points[l],s.points[l+1],d))return!1}}return!0}u(Et,"validateSameContainerRoute");function Dt(t,e,o,n,i){const r=Jn(t);if(!r)return!1;const s=z(r);if(s.points.length<2)return!1;const a=(i.forest.childrenByParent.get(n)??[]).filter(c=>!pt(c));for(const c of a){const d=to(c);for(let l=0;l<s.points.length-1;l++){if(c.id===e&&l===0||c.id===o&&l===s.points.length-2){if(ve(s.points[l],s.points[l+1],Pt(c)))return!1;continue}if(ve(s.points[l],s.points[l+1],d))return!1}}return!0}u(Dt,"validateContainerSegment");function yn(t){return t.orientation==="H"?{low:Math.min(t.a.x,t.b.x),high:Math.max(t.a.x,t.b.x)}:{low:Math.min(t.a.y,t.b.y),high:Math.max(t.a.y,t.b.y)}}u(yn,"segmentSpan");function re(t){const e=z([...t]).segments.filter(n=>n.orientation!=="Z").map(n=>({a:{...n.a},b:{...n.b},orientation:n.orientation}));if(e.length===0)return[];if(e.length===1&&Math.abs(e[0].a.x-e[0].b.x)+Math.abs(e[0].a.y-e[0].b.y)<=q*2)return[];const o=u((n,i)=>{if(n.orientation==="H"){const r=Math.sign(n.b.x-n.a.x);i?n.a.x+=r*q:n.b.x-=r*q}else{const r=Math.sign(n.b.y-n.a.y);i?n.a.y+=r*q:n.b.y-=r*q}},"trim");return o(e[0],!0),o(e[e.length-1],!1),e.filter(({a:n,b:i})=>n.x!==i.x||n.y!==i.y)}u(re,"nonterminalSegments");function eo(t,e){if(t.orientation!==e.orientation)return!1;const o=yn(t),n=yn(e),i=Math.max(0,Math.min(o.high,n.high)-Math.max(o.low,n.low));if(i<=0)return!1;const r=t.orientation==="H"?Math.abs(t.a.y-e.a.y):Math.abs(t.a.x-e.a.x);return r===0&&i>=Pe||r>0&&r<Pe}u(eo,"pairSegmentsConflict");function ft(t,e){const o=z([...t]).points,n=[o[0],o.at(-1)],i=re(o);return e.every(r=>{const s=z([...r]).points,a=[s[0],s.at(-1)];return n.some(c=>a.some(d=>c.x===d.x&&c.y===d.y))?!1:i.every(c=>re(s).every(d=>!eo(c,d)))})}u(ft,"routeSatisfiesPairConstraints");function no(t,e){const o=z([...t]).points,n=[o[0],o.at(-1)];return e.every(i=>{const r=z([...i]).points,s=[r[0],r.at(-1)];return!n.some(a=>s.some(c=>a.x===c.x&&a.y===c.y))})}u(no,"routeHasDistinctPairPorts");function qe(t,e,o){const n=t.y===e.y?"H":"V",i={a:t,b:e,orientation:n};return o.every(r=>re(r).every(s=>!eo(i,s)))}u(qe,"pairArcAllowed");function $i(t,e){const o=t.side==="left"||t.side==="right"?"H":"V",n=e.side==="left"||e.side==="right"?"H":"V",i=Math.abs(t.connect.x-e.connect.x),r=Math.abs(t.connect.y-e.connect.y);let s;if(i===0&&r===0)s=+(o!==n);else if(i===0||r===0){const a=i===0?"V":"H";s=+(o!==a)+ +(n!==a)}else s=Math.min(+(o!=="H")+1+ +(n!=="V"),+(o!=="V")+1+ +(n!=="H"));return[q*2+i+r,s]}u($i,"endpointPairLowerBound");function Ki(t,e){if(t.orientation!==e.orientation)return!1;const o=t.orientation==="H",n=u(a=>o?Math.min(a.a.x,a.b.x):Math.min(a.a.y,a.b.y),"lowOf"),i=u(a=>o?Math.max(a.a.x,a.b.x):Math.max(a.a.y,a.b.y),"highOf"),r=Math.min(i(t),i(e))-Math.max(n(t),n(e)),s=Math.abs(o?t.a.y-e.a.y:t.a.x-e.a.x);return r>0&&s<qt}u(Ki,"segmentsTooClose");var xn=class{constructor(){this.lines={H:new Map,V:new Map},this.sortedCoordinates={H:void 0,V:void 0},this.log=[]}static{u(this,"RouteOccupancyIndex")}get size(){return this.log.length}add(t,e){for(const o of re(t)){const n=o.orientation,i=n==="H"?o.a.y:o.a.x,r=this.lines[n].get(i);r?r.push({segment:o,pairKey:e}):(this.lines[n].set(i,[{segment:o,pairKey:e}]),this.sortedCoordinates[n]=void 0),this.log.push({orientation:n,coordinate:i})}}truncate(t){for(;this.log.length>t;){const{orientation:e,coordinate:o}=this.log.pop();this.lines[e].get(o)?.pop()}}conflictsWithRoute(t,e){return re(t).some(o=>this.conflicts(o,e))}conflictsWithArc(t,e,o){const n=t.y===e.y?"H":"V";return this.conflicts({a:t,b:e,orientation:n},o)}conflicts(t,e){const o=t.orientation;if(o!=="H"&&o!=="V")return!1;const n=o==="H"?t.a.y:t.a.x,i=this.coordinatesFor(o);let r=0,s=i.length;for(;r<s;){const a=r+s>>1;i[a]<=n-qt?r=a+1:s=a}for(let a=r;a<i.length;a++){const c=i[a];if(c>=n+qt)break;for(const d of this.lines[o].get(c))if(d.pairKey!==e&&Ki(t,d.segment))return!0}return!1}coordinatesFor(t){return this.sortedCoordinates[t]??=[...this.lines[t].keys()].sort((e,o)=>e-o)}},It=24,ht=18,Ct=14,bo=4,ji=18,oo=4,Jr=64,ts=4;function Ui(t,e,o,n){if(!e.conflictsWithRoute(t,o))return[...t];const i=z([...t]).points;for(let r=1;r<=ts;r++)for(const s of[1,-1]){const a=s*r*Pe;for(let c=1;c<i.length-2;c++){const d=i[c].x===i[c+1].x,l=i.map((h,f)=>f===c||f===c+1?d?{x:h.x+a,y:h.y}:{x:h.x,y:h.y+a}:h);if(!e.conflictsWithRoute(l,o)&&n(l))return l}}}u(Ui,"separateRouteFromOccupied");function Xi(t){const e=u((o,n)=>Math.abs(o.x-n.x)+Math.abs(o.y-n.y),"stub");return e(t[0],t[1])>=q&&e(t.at(-1),t.at(-2))>=q}u(Xi,"terminalStubsAreLongEnough");function Wi(t,e,o,n,i=3){const r=[...n.filter(c=>c>=e&&c<=o).sort((c,d)=>Math.abs(c-t)-Math.abs(d-t)||c-d),(e+o)/2,e,o],s=new Set([t]),a=[];for(const c of r)if(!s.has(c)&&(s.add(c),a.push(c),a.length===i))break;return a}u(Wi,"boundedAlternativePortalCoordinates");function Zt(t,e){return Math.abs(t.x-e.x)<=1e-6&&Math.abs(t.y-e.y)<=1e-6}u(Zt,"equalPoint");function Yi(t,e){return t.x===e.x||t.y===e.y}u(Yi,"areExactlyAxisAligned");function Oe(t,e,o,n){const i=[...t].sort((r,s)=>Math.abs(r-e)+Math.abs(r-o)-(Math.abs(s-e)+Math.abs(s-o))||r-s);return i[Math.min(n,Math.max(0,i.length-1))]??(e+o)/2}u(Oe,"chooseIntermediateCoordinate");function qi(t){const e=[];for(const o of t)(e.length===0||!Zt(e[e.length-1],o))&&e.push(o);return e}u(qi,"dedupeConsecutive");function jt(t,e,o,n,i){const r=e.containers.get(t);if(!r)throw H("GRID_ROUTE_NOT_FOUND",`Missing container layout "${t}"`);const s=[o.port,o.connect];if(o.orientation==="V"&&n.orientation==="V"){if(!Zt(o.connect,n.connect)&&Math.abs(o.connect.x-n.connect.x)>1e-6){const a=Oe(r.horizontalCorridors,o.connect.y,n.connect.y,i);s.push({x:o.connect.x,y:a},{x:n.connect.x,y:a})}else if(!Zt(o.connect,n.connect)&&Math.abs(o.connect.y-n.connect.y)>1e-6&&i>0){const a=r.verticalCorridors.filter(d=>Math.abs(d-o.connect.x)>1e-6),c=Oe(a.length>0?a:r.verticalCorridors,o.connect.x,n.connect.x,i-1);s.push({x:c,y:o.connect.y},{x:c,y:n.connect.y})}}else if(o.orientation==="H"&&n.orientation==="H"){if(!Zt(o.connect,n.connect)&&Math.abs(o.connect.y-n.connect.y)>1e-6){const a=Oe(r.verticalCorridors,o.connect.x,n.connect.x,i);s.push({x:a,y:o.connect.y},{x:a,y:n.connect.y})}}else o.orientation==="V"&&n.orientation==="H"?s.push({x:o.connect.x,y:n.connect.y}):s.push({x:n.connect.x,y:o.connect.y});return s.push(n.connect,n.port),z(qi(s)).points}u(jt,"routeWithinContainer");function Ie(t,e,o,n,i,r,s){const a=i.forest.nodeById.get(t),c=i.itemMeta.get(t);if(!a||!c||c.containerId!==n)throw H("GRID_ROUTE_NOT_FOUND",`Missing item metadata for "${t}" in "${n}"`);const d=k(a),l=s??r.get(o)??(e==="left"||e==="right"?d.cy:d.cx);switch(e){case"left":return{port:{x:d.left,y:l},connect:{x:c.leftCorridorX,y:l},orientation:"V",side:e};case"right":return{port:{x:d.right,y:l},connect:{x:c.rightCorridorX,y:l},orientation:"V",side:e};case"top":return{port:{x:l,y:d.top},connect:{x:l,y:c.topCorridorY},orientation:"H",side:e};case"bottom":return{port:{x:l,y:d.bottom},connect:{x:l,y:c.bottomCorridorY},orientation:"H",side:e}}}u(Ie,"itemAttachment");function io(t,e,o,n,i){const r=n.forest.nodeById.get(t),s=n.containers.get(t);if(!r||!s)throw H("GRID_ROUTE_NOT_FOUND",`Missing boundary metadata for "${t}"`);const a=k(r),c=i.get(o)??(e==="left"||e==="right"?a.cy:a.cx);switch(e){case"left":return{port:{x:a.left,y:c},connect:{x:s.verticalCorridors[0],y:c},orientation:"V",side:e};case"right":return{port:{x:a.right,y:c},connect:{x:s.verticalCorridors[s.verticalCorridors.length-1],y:c},orientation:"V",side:e};case"top":return{port:{x:c,y:a.top},connect:{x:c,y:s.horizontalCorridors[0]},orientation:"H",side:e};case"bottom":return{port:{x:c,y:a.bottom},connect:{x:c,y:s.horizontalCorridors[s.horizontalCorridors.length-1]},orientation:"H",side:e}}}u(io,"boundaryAttachment");function Qi(t){return{x:(t.interior.x+t.exterior.x)/2,y:(t.interior.y+t.exterior.y)/2}}u(Qi,"portalBoundaryPoint");function Wt(t,e){return{ownerId:t.ownerId,port:Qi(t),connect:e?t.interior:t.exterior,orientation:t.side==="left"||t.side==="right"?"V":"H",side:t.side}}u(Wt,"portalAttachment");function bn(t,e,o,n,i){const r=n.forest.nodeById.get(t);if(!r?.isGroup)throw H("GRID_ROUTE_NOT_FOUND",`Missing group endpoint "${t}"`);const s=k(r),a=i.get(o)??(e==="left"||e==="right"?s.cy:s.cx),c=e==="left"||e==="right"?{x:e==="left"?s.left:s.right,y:a}:{x:a,y:e==="top"?s.top:s.bottom};return{ownerId:t,port:c,connect:{x:c.x+(e==="left"?q:e==="right"?-q:0),y:c.y+(e==="top"?q:e==="bottom"?-q:0)},orientation:e==="left"||e==="right"?"V":"H",side:e}}u(bn,"groupBoundaryEndpointAttachment");function Zi(t){return[...t].reverse()}u(Zi,"reversePoints");function Ji(t){const e=[];for(const o of t)for(const n of o)(e.length===0||!Zt(e[e.length-1],n))&&e.push(n);return z(e).points}u(Ji,"combinePointChains");function tr(t,e,o,n){const i=k(t),r=Ct+(o+1)*ji,s=o*oo;switch(e){case"right":{const a=n-ht/2-s,c=n+ht/2+s;return z([{x:i.right,y:a},{x:i.right+Ct,y:a},{x:i.right+r,y:a},{x:i.right+r,y:c},{x:i.right+Ct,y:c},{x:i.right,y:c}]).points}case"left":{const a=n-ht/2-s,c=n+ht/2+s;return z([{x:i.left,y:a},{x:i.left-Ct,y:a},{x:i.left-r,y:a},{x:i.left-r,y:c},{x:i.left-Ct,y:c},{x:i.left,y:c}]).points}case"top":{const a=n-ht/2-s,c=n+ht/2+s;return z([{x:a,y:i.top},{x:a,y:i.top-Ct},{x:a,y:i.top-r},{x:c,y:i.top-r},{x:c,y:i.top-Ct},{x:c,y:i.top}]).points}case"bottom":{const a=n-ht/2-s,c=n+ht/2+s;return z([{x:a,y:i.bottom},{x:a,y:i.bottom+Ct},{x:a,y:i.bottom+r},{x:c,y:i.bottom+r},{x:c,y:i.bottom+Ct},{x:c,y:i.bottom}]).points}}}u(tr,"routeSelfLoop");function ro(t,e,o,n,i){const r=k(t),s=Ct+(o+1)*ji,a=o*oo,c=ht+a*2,d=e==="left"||e==="right",l=Math.max(c,(d?i.cross:i.along)+$t*2+Bo),h=Math.max(s,(d?i.along:i.cross)/2+$t),f=d?[r.top,r.bottom]:[r.left,r.right],m=n-l/2,p=n+l/2;if(m-f[0]>=bo&&f[1]-p>=bo)switch(e){case"right":return[z([{x:r.right,y:m},{x:r.right+h,y:m},{x:r.right+h,y:p},{x:r.right,y:p}]).points];case"left":return[z([{x:r.left,y:m},{x:r.left-h,y:m},{x:r.left-h,y:p},{x:r.left,y:p}]).points];case"top":return[z([{x:m,y:r.top},{x:m,y:r.top-h},{x:p,y:r.top-h},{x:p,y:r.top}]).points];case"bottom":return[z([{x:m,y:r.bottom},{x:m,y:r.bottom+h},{x:p,y:r.bottom+h},{x:p,y:r.bottom}]).points]}const x=n-ht/2-a,g=n+ht/2+a;if(x<f[0]||g>f[1])return[];const y=n-l/2,b=n+l/2,I=Math.max(Ct,q),C=Math.max(h,I+(d?i.along:i.cross)/2+$t);switch(e){case"right":return[z([{x:r.right,y:x},{x:r.right+I,y:x},{x:r.right+I,y},{x:r.right+C,y},{x:r.right+C,y:b},{x:r.right+I,y:b},{x:r.right+I,y:g},{x:r.right,y:g}]).points];case"left":return[z([{x:r.left,y:x},{x:r.left-I,y:x},{x:r.left-I,y},{x:r.left-C,y},{x:r.left-C,y:b},{x:r.left-I,y:b},{x:r.left-I,y:g},{x:r.left,y:g}]).points];case"top":return[z([{x,y:r.top},{x,y:r.top-I},{x:y,y:r.top-I},{x:y,y:r.top-C},{x:b,y:r.top-C},{x:b,y:r.top-I},{x:g,y:r.top-I},{x:g,y:r.top}]).points];case"bottom":return[z([{x,y:r.bottom},{x,y:r.bottom+I},{x:y,y:r.bottom+I},{x:y,y:r.bottom+C},{x:b,y:r.bottom+C},{x:b,y:r.bottom+I},{x:g,y:r.bottom+I},{x:g,y:r.bottom}]).points]}}u(ro,"labelAwareSelfLoopCandidates");function so(t,e,o){return(t.isGroup&&We(t)?["left","right","bottom"]:["left","right","top","bottom"]).sort((i,r)=>{const s=(e.get(oe(t.id,i))??0)+(o.get(`${t.id}:${i}`)??0),a=(e.get(oe(t.id,r))??0)+(o.get(`${t.id}:${r}`)??0);return s-a})}u(so,"orderedSelfLoopSides");function er(t,e){const o=[];for(const n of e.forest.nodeById.values())if(n.id!==t.id&&!n.isGroup&&n.x!==void 0&&n.y!==void 0&&o.push(k(n)),n.id!==t.id&&n.groupTitleRect){const{left:i,right:r,top:s,bottom:a}=n.groupTitleRect;o.push({cx:(i+r)/2,cy:(s+a)/2,left:i,right:r,top:s,bottom:a})}return o}u(er,"selfLoopObstacles");function nr(t,e,o,n,i,r){const s=k(t),a=er(t,n);for(const c of so(t,e,o)){const d=`${t.id}:${c}`,l=o.get(d)??0,h=c==="left"||c==="right"?s.cy:s.cx,f=i?ro(t,c,l,h,i):[tr(t,c,l,h)];i&&r&&(r.labelAwareSelfLoopCandidates+=f.length);for(const m of f)if(!a.some(p=>bt(m,p)))return{points:m,side:c,index:l}}throw H("GRID_ROUTE_NOT_FOUND",`No obstacle-clear self-loop route for "${t.id}"`,{nodeId:t.id})}u(nr,"routeObstacleClearSelfLoop");function or(t){if(t.containers.has(j))return;let e=0,o=0,n=0,i=0,r=!0;for(const c of t.itemMeta.values())c.containerId===j&&(r?(e=c.cellLeft,o=c.cellLeft+c.cellWidth,n=c.cellTop,i=c.cellTop+c.cellHeight,r=!1):(e=Math.min(e,c.cellLeft),o=Math.max(o,c.cellLeft+c.cellWidth),n=Math.min(n,c.cellTop),i=Math.max(i,c.cellTop+c.cellHeight)));const s=new Set([n-It,i+It]),a=new Set([e-It,o+It]);for(const c of t.itemMeta.values())c.containerId===j&&(s.add(c.topCorridorY),s.add(c.bottomCorridorY),a.add(c.leftCorridorX),a.add(c.rightCorridorX));t.containers.set(j,{id:j,left:e-It,top:n-It,width:o-e+It*2,height:i-n+It*2,contentLeft:e,contentTop:n,contentRight:o,contentBottom:i,verticalCorridors:[...a].sort((c,d)=>c-d),horizontalCorridors:[...s].sort((c,d)=>c-d)})}u(or,"rootContainerMeta");function ir(t,e){const o=e.containers.get(t);if(!o)throw H("GRID_ROUTE_NOT_FOUND",`Missing container layout "${t}"`);if(t===j){const r=[...e.itemMeta.values()].filter(({containerId:s})=>s===j);return r.length>0?{left:Math.min(...r.map(({cellLeft:s})=>s))-It,right:Math.max(...r.map(({cellLeft:s,cellWidth:a})=>s+a))+It,top:Math.min(...r.map(({cellTop:s})=>s))-It,bottom:Math.max(...r.map(({cellTop:s,cellHeight:a})=>s+a))+It}:{left:o.left,right:o.left+o.width,top:o.top,bottom:o.top+o.height}}const n=e.forest.nodeById.get(t);if(!n)throw H("GRID_ROUTE_NOT_FOUND",`Missing container owner "${t}"`);const i=Pt(n);return{left:i.left+V,right:i.right-V,top:i.top+V,bottom:i.bottom-V}}u(ir,"containerBounds");function wn(t,e,o){return(e==="left"?t.left:e==="right"?t.right:e==="top"?t.top:t.bottom)+(e==="left"||e==="top"?1:-1)*V*(o?1:-1)}u(wn,"portalCoordinate");function rr(t,e){const o=[];if(t!==j){const n=e.forest.nodeById.get(t);if(n){const i=Pt(n);o.push(...ne(t,i,n.groupTitleRect).map(r=>({...r,coordinate:wn(i,r.side,!0)})))}}for(const n of e.forest.childrenByParent.get(t)??[]){if(!n.isGroup)continue;const i=Pt(n);o.push(...ne(n.id,i,n.groupTitleRect).map(r=>({...r,coordinate:wn(i,r.side,!1)})))}return o}u(rr,"containerPortalRanges");function sr(t,e,o,n){const i={topologies:new Map,fallbackContainers:new Map,searchBudget:{expandedStates:0},searchBudgetWarningEmitted:!1,baseEstimatedBytes:0,metrics:o};let r=0;for(const s of[...new Set(t)].sort()){const a=(e.forest.childrenByParent.get(s)??[]).filter(d=>!pt(d)),c=e.forest.nodeById.get(s)?.groupTitleRect;try{const d=Li({containerId:s,bounds:ir(s,e),obstacles:a.map(h=>({id:h.id,bounds:Pt(h)})),titleExclusions:c?[{id:`${s}:title`,bounds:{...c}}]:void 0,portalRanges:rr(s,e)},{caps:n.topologyCaps}),l=n.topologyCaps?.maxEstimatedBytes??zt;if(r+d.estimatedBytes>l){i.fallbackContainers.set(s,"estimated_memory_cap");continue}r+=d.estimatedBytes,i.baseEstimatedBytes=r,i.topologies.set(s,d),o&&(o.containersBuilt++,o.baseTopologyBuilds++,o.baseVertices+=d.vertices.length,o.baseAdjacencyEntries+=d.adjacencyEntries,o.buildSweepEvents+=d.seedCount*4+d.obstacles.length*4,o.estimatedBytes=r)}catch(d){if(!(d instanceof Lt))throw d;i.fallbackContainers.set(s,d.reason)}}return i}u(sr,"buildRoutingContext");function vn(t,e,o,n,i,r,s){const a=i();if(s&&s.compatibilitySegments++,Dt(a,o.ownerId,n.ownerId,e,r))return a;throw s&&(s.compatibilityValidationFailures++,s.routesImpossible++),H("GRID_ROUTE_NOT_FOUND",`Invalid compatibility route for "${t}"`,{edgeId:t,containerId:e})}u(vn,"validatedCompatibilitySegment");function Me(t,e,o){const n=t.source.chain.at(-1),i=t.target.chain.at(-1),r=u((s,a)=>({ownerId:a.ownerId,...s.finalKind==="boundary"?io(t.lcaContainerId,a.side,a.demandKey,e,o):Ie(a.ownerId,a.side,a.demandKey,t.lcaContainerId,e,o)}),"finalAttachment");return{start:r(t.source,n),end:r(t.target,i)}}u(Me,"compatibilityLcaAttachments");function ao(t,e,o){return t.chain.slice(0,-1).map((n,i)=>{const r=t.chain[i+1];return{containerId:r.ownerId,start:{ownerId:n.ownerId,...Ie(n.ownerId,n.side,n.demandKey,r.ownerId,e,o)},end:{ownerId:r.ownerId,...io(r.ownerId,r.side,r.demandKey,e,o)}}})}u(ao,"compatibilityHierarchyAttachments");function ar(t,e,o){const n=u((r,s,a)=>Dt(jt(r,e,s,a,t.laneIndex),s.ownerId,a.ownerId,r,e),"segmentIsValid");for(const r of[t.source,t.target])for(const{containerId:s,start:a,end:c}of ao(r,e,o))if(!n(s,a,c))return!1;const i=Me(t,e,o);return n(t.lcaContainerId,i.start,i.end)}u(ar,"compatibilityPlanIsValid");function cr(t,e,o,n){const{plans:i,eligiblePlans:r,eligibleIds:s,demandCoords:a,endpointCandidatesByEdge:c,endpointIncidentCounts:d,coordinatedEndpointIds:l}=t,h=u(w=>(d.get(w.edge.start)??0)===w.bundleSize&&(d.get(w.edge.end)??0)===w.bundleSize,"hasIsolatedEndpoints"),f=u(w=>{const E=e.forest.nodeById.get(w.edge.start),R=e.forest.nodeById.get(w.edge.end);return!!(E&&R&&(E.isGroup&&kt(E.id,R,e.forest.nodeById)||R.isGroup&&kt(R.id,E,e.forest.nodeById)))},"hasAncestorEndpoint"),m=new Map,p=new Map,x=i.length<=Jr,g=n.topologyCaps===void 0&&n.searchCaps===void 0&&n.onDualRouteComparison===void 0;for(const w of g?r:[]){if(l.has(w.edge.id))continue;const E=c.get(w.edge.id);if(w.bundleSize!==1||!E?.sources.length||!E.targets.length)continue;const R=e.forest.nodeById.get(w.edge.start),M=e.forest.nodeById.get(w.edge.end);if(!R||!M)continue;const A=Me(w,e,a),L=jt(w.lcaContainerId,e,A.start,A.end,w.laneIndex),B=z(L),T=B.points[0],G=B.points.at(-1);if(!T||!G)continue;const X=E.sources.find(({port:Q})=>Q.x===T.x&&Q.y===T.y),W=E.targets.find(({port:Q})=>Q.x===G.x&&Q.y===G.y);if(!X||!W)continue;o&&o.compatibilityFastPathAttempts++;const F=Math.abs(T.x-G.x)+Math.abs(T.y-G.y);if(!Et(L,R,M,w.lcaContainerId,e)){o&&o.compatibilityFastPathValidationFailures++;continue}if(ee(B.points)!==F){o&&o.compatibilityFastPathNonMinimalRoutes++;continue}let Y=p.get(w.lcaContainerId);if(Y||(Y=new xn,p.set(w.lcaContainerId,Y)),Y.conflictsWithRoute(B.points,w.pairKey)&&x)continue;const D=Ui(B.points,Y,w.pairKey,Q=>Xi(Q)&&ee(Q)===F&&Et(Q,R,M,w.lcaContainerId,e))??L;Y.add(D,w.pairKey),m.set(w.edge.id,D)}const y=u(w=>!s.has(w.edge.id)&&w.edge.start!==w.edge.end&&(w.bundleSize>1||h(w)||!ar(w,e,a)),"sparseCandidate"),b=new Map,I=new Set;if(x)for(const w of t.orderedPlans){if(s.has(w.edge.id)||w.edge.start===w.edge.end||f(w)||y(w))continue;const E=Me(w,e,a),R=jt(w.lcaContainerId,e,E.start,E.end,w.laneIndex);let M=b.get(w.lcaContainerId);M||(M=new xn,b.set(w.lcaContainerId,M)),M.conflictsWithRoute(R,w.pairKey)?I.add(w.edge.id):M.add(R,w.pairKey)}const C=new Set([...i.filter(y).map(({edge:w})=>w.id),...I]),S=new Set([...C,...i.filter(f).map(({edge:w})=>w.id)]),v=i.filter(w=>s.has(w.edge.id)&&!m.has(w.edge.id)||S.has(w.edge.id)||w.edge.start===w.edge.end).flatMap(w=>[w.lcaContainerId,...w.source.chain.slice(1).map(({ownerId:E})=>E),...w.target.chain.slice(1).map(({ownerId:E})=>E)]);return{overlapAvoidanceEnabled:x,compatibilityFastRoutes:m,sparseHierarchyIds:C,sparseLcaIds:S,routedContainerIds:v,routeOccupancy:p}}u(cr,"prepareRoutingModes");var wo={containersBuilt:"cumulative",baseTopologyBuilds:"cumulative",baseVertices:"cumulative",baseAdjacencyEntries:"cumulative",buildSweepEvents:"cumulative",endpointOverlayBuilds:"cumulative",endpointOverlayVertices:"cumulative",hierarchyPortalPairs:"transactional",hierarchyPortalTransitionLength:"transactional",hierarchyPortalAlternativeAttempts:"cumulative",hierarchyPortalAlternativeSelections:"transactional",hierarchyBoundaryTransitions:"transactional",labelOverlayBuilds:"cumulative",labelOverlayVertices:"cumulative",labelSpacingEdgesExamined:"cumulative",labelSpacingEligibleEdges:"cumulative",labelSpacingBoundariesExpanded:"cumulative",labelSpacingPixelsAdded:"cumulative",labelAwareSelfLoopCandidates:"cumulative",labelAwareSelfLoopsCommitted:"transactional",labelAwareSelfLoopFallbacks:"cumulative",searches:"cumulative",expandedStates:"cumulative",maxOpenSet:"cumulative",routesFound:"transactional",routesImpossible:"transactional",resourceLimitFallbacks:"cumulative",fallbackReasons:"cumulative",fallbackValidationFailures:"cumulative",compatibilitySegments:"transactional",compatibilityFastPathAttempts:"cumulative",compatibilityFastPaths:"cumulative",compatibilityFastPathValidationFailures:"cumulative",compatibilityFastPathNonMinimalRoutes:"cumulative",compatibilityRecoveries:"transactional",compatibilityValidationFailures:"cumulative",bundleSeparationRelaxations:"transactional",routeLength:"transactional",bendCount:"transactional",crossingCount:"transactional",sharedLength:"transactional",estimatedBytes:"cumulative",searchWorkspaceBytes:"cumulative",routeOrder:"transactional",routes:"transactional"},es=Object.keys(wo).filter(t=>wo[t]==="transactional"&&t!=="routeOrder"&&t!=="routes");function dr(t){return{routeOrderLength:t.routeOrder.length,routesLength:t.routes.length,values:Object.fromEntries(es.map(e=>[e,t[e]]))}}u(dr,"createGridRoutingInstrumentationCheckpoint");function lr(t,e){t.routeOrder.length=e.routeOrderLength,t.routes.length=e.routesLength,Object.assign(t,e.values)}u(lr,"restoreGridRoutingInstrumentationCheckpoint");function In(t,e,o,n){return Math.max(0,Math.min(Math.max(t,e),Math.max(o,n))-Math.max(Math.min(t,e),Math.min(o,n)))}u(In,"intervalOverlap");function ur(t,e){const o=z(t).segments,n=z(e).segments;let i=0;for(const r of o)for(const s of n)r.orientation===s.orientation&&(r.orientation==="H"&&r.a.y===s.a.y?i+=In(r.a.x,r.b.x,s.a.x,s.b.x):r.orientation==="V"&&r.a.x===s.a.x&&(i+=In(r.a.y,r.b.y,s.a.y,s.b.y)));return i}u(ur,"sharedSegmentLength");function Mn(t,e,o,n,i=0,r=0){const s=z(o);let a=0,c=0;for(const l of n){const h=z(l).segments;for(const f of s.segments)for(const m of h)Bn(f,m)&&a++;c+=ur(s.points,l)}const d={edgeId:e,routeOrder:t.routes.length,laneOffset:r,routeLength:ee(s.points),bendCount:s.bends,crossingCount:a,sharedLength:c,boundaryTransitionCount:i,routeSignature:JSON.stringify(s.points)};t.routeOrder.push(e),t.routes.push(d),t.routesFound++,t.routeLength+=d.routeLength,t.bendCount+=d.bendCount,t.crossingCount+=d.crossingCount,t.sharedLength+=d.sharedLength,t.hierarchyBoundaryTransitions+=i}u(Mn,"recordGridRoute");var hr=1e5,fr=2e6,gr=class{constructor(){this.stateVertices=new Int32Array(256),this.orientations=new Uint8Array(256),this.gLengths=new Float64Array(256),this.gBends=new Float64Array(256),this.gBoundaryTransitions=new Float64Array(256),this.fLengths=new Float64Array(256),this.fBends=new Float64Array(256),this.predecessors=new Int32Array(256),this.depths=new Int32Array(256),this.ancestor4=new Int32Array(256),this.best=new Int32Array(256),this.heapChildren=new Int32Array(256),this.heapSiblings=new Int32Array(256),this.heapPairs=[],this.touchedBestIndices=[],this.best.fill(-1)}static{u(this,"RouterSearchWorkspace")}reset(t){const e=t*3;if(this.best.length<e)this.best=new Int32Array(e),this.best.fill(-1);else for(const o of this.touchedBestIndices)this.best[o]=-1;this.touchedBestIndices.length=0,this.heapPairs.length=0}setBest(t,e){this.best[t]<0&&this.touchedBestIndices.push(t),this.best[t]=e}ensureStateCapacity(t){if(this.stateVertices.length>=t)return;const e=Math.max(t,this.stateVertices.length*2);this.stateVertices=yt(this.stateVertices,e),this.orientations=yt(this.orientations,e),this.gLengths=yt(this.gLengths,e),this.gBends=yt(this.gBends,e),this.gBoundaryTransitions=yt(this.gBoundaryTransitions,e),this.fLengths=yt(this.fLengths,e),this.fBends=yt(this.fBends,e),this.predecessors=yt(this.predecessors,e),this.depths=yt(this.depths,e),this.ancestor4=yt(this.ancestor4,e),this.heapChildren=yt(this.heapChildren,e),this.heapSiblings=yt(this.heapSiblings,e)}estimatedBytes(){return this.stateVertices.byteLength+this.orientations.byteLength+this.gLengths.byteLength+this.gBends.byteLength+this.gBoundaryTransitions.byteLength+this.fLengths.byteLength+this.fBends.byteLength+this.predecessors.byteLength+this.depths.byteLength+this.ancestor4.byteLength+this.best.byteLength+this.heapChildren.byteLength+this.heapSiblings.byteLength+(this.heapPairs.length+this.touchedBestIndices.length)*8}};function Se(t){const e=t.caps?.maxExpandedStates??hr,o=t.caps?.maxInvocationExpandedStates??fr,n=t.budget?.expandedStates??t.metrics?.expandedStates??0;if(!(e>0&&n<o))throw new Lt("search_state_cap","Grid routing search-state cap exceeded",n>=o?"invocation":"edge")}u(Se,"assertSearchBudgetAvailable");function yt(t,e){const o=new t.constructor(e);return o.set(t),o}u(yt,"growTypedArray");function Jt(t,e){for(let o=0;o<4;o++){if(t[o]<e[o])return-1;if(t[o]>e[o])return 1}return 0}u(Jt,"compareTupleCost");function Cn(t,e,o,n){return t===0&&e===0?o&&n?+(o!==n):0:t===0?(o?+(o!=="V"):0)+(n?+(n!=="V"):0):e===0?(o?+(o!=="H"):0)+(n?+(n!=="H"):0):Math.min((o?+(o!=="H"):0)+1+(n?+(n!=="V"):0),(o?+(o!=="V"):0)+1+(n?+(n!=="H"):0))}u(Cn,"minimumBends");function me(t){return t===void 0?0:t==="H"?1:2}u(me,"orientationOrdinal");function Sn(t,e,o){return o==="left"?t.y===e.y&&e.x>t.x:o==="right"?t.y===e.y&&e.x<t.x:o==="top"?t.x===e.x&&e.y>t.y:t.x===e.x&&e.y<t.y}u(Sn,"movesTowardOwner");function pr(t,e){return t*3+me(e)}u(pr,"stateIndex");function mr(t){const e=[];for(const o of t){const n=e.at(-1);if(n&&n.x===o.x&&n.y===o.y)continue;const i=e.at(-2);i&&n&&(i.x===n.x&&n.x===o.x||i.y===n.y&&n.y===o.y)?e[e.length-1]={...o}:e.push({...o})}return e}u(mr,"normalizePoints");function En(t,e,o,n,i){const r=[];let s=t;for(;s>=0;)r.push(e[s]),s=o[s];return r.reverse(),{points:mr(r.map(a=>i(a).point)),vertexIds:r,cost:n}}u(En,"reconstruct");function yr(t){for(const e of t.vertices){if(e.id<0||t.vertices[e.id]!==e||!Number.isFinite(e.point.x)||!Number.isFinite(e.point.y))throw new Error("Malformed grid routing vertex");for(const o of t.adjacency.get(e.id)??[]){const n=t.vertices[o.to],i=n&&(o.orientation==="H"?e.point.y===n.point.y:e.point.x===n.point.x),r=n?Math.abs(e.point.x-n.point.x)+Math.abs(e.point.y-n.point.y):Number.NaN;if(o.from!==e.id||!i||!Number.isFinite(o.length)||o.length<=0||o.length!==r)throw new Error("Malformed grid routing arc")}}}u(yr,"validateSearchTopology");function xr(t,e,o,n){const i=u(P=>{const _=t.getVertex?.(P)??t.vertices[P];if(!_)throw new Error(`Missing grid routing vertex ${P}`);return _},"vertexAt"),r=i(e),s=i(o);n.topologyValidated||yr(t);const a=n.metrics;a&&a.searches++,Se(n);const c=n.workspace??new gr;c.reset(t.vertexCount??t.vertices.length);let d=c.stateVertices,l=c.orientations,h=c.gLengths,f=c.gBends,m=c.gBoundaryTransitions,p=c.fLengths,x=c.fBends,g=c.predecessors,y=c.depths,b=c.ancestor4,I=c.heapChildren,C=c.heapSiblings;const S=c.best,v=c.heapPairs;let w=1;const E=n.endpointCandidateRank??0,R=n.heuristic!=="zero";function M(P,_){return d[P]-d[_]||l[P]-l[_]||g[P]-g[_]||P-_}u(M,"nonCostOrder");function A(P,_){return p[P]-p[_]||x[P]-x[_]||m[P]-m[_]||(n.queueOrder==="reverse"?-M(P,_):M(P,_))}u(A,"compareStates");function L(P,_){if(P===_)return 0;if(P<0)return-1;if(_<0)return 1;const at=y[P],ct=y[_];let J=P,$=_;for(;y[J]>y[$];)J=g[J];for(;y[$]>y[J];)$=g[$];if(J===$)return at-ct;for(;b[J]>=0&&b[$]>=0&&b[J]!==b[$];)J=b[J],$=b[$];for(;g[J]!==g[$];)J=g[J],$=g[$];return d[J]-d[$]||l[J]-l[$]}u(L,"compareChains");let B=-1,T=0;function G(P,_){return P<0?_:_<0?P:A(P,_)<=0?(C[_]=I[P],I[P]=_,P):(C[P]=I[_],I[_]=P,_)}u(G,"heapMeld");const X=u(P=>{I[P]=-1,C[P]=-1,B=G(B,P),T++},"heapPush"),W=u(()=>{if(B<0)return;const P=B;v.length=0;let _=I[P];for(;_>=0;){const ct=C[_];C[_]=-1,v.push(_),_=ct}for(let ct=0;ct+1<v.length;ct+=2)v[ct>>>1]=G(v[ct],v[ct+1]);let at=Math.ceil(v.length/2);for(v.length%2!==0&&(v[at-1]=v[v.length-1]),B=-1;at>0;)B=G(v[--at],B);return T--,P},"heapPop");let F=0;const Y=n.caps?.maxExpandedStates??hr,wt=n.caps?.maxInvocationExpandedStates??fr,et=n.budget?.expandedStates??a?.expandedStates??0,D=u(()=>{const P=c.estimatedBytes(),_=(n.estimatedBytesBase??0)+P;if(a&&(a.searchWorkspaceBytes=Math.max(a.searchWorkspaceBytes,P),a.estimatedBytes=Math.max(a.estimatedBytes,_)),_>(n.caps?.maxEstimatedBytes??Number.POSITIVE_INFINITY))throw new Lt("estimated_memory_cap","Grid routing search workspace memory cap exceeded")},"recordWorkspaceBytes");D();const Q=u(()=>{n.budget&&(n.budget.expandedStates+=F),a&&(a.expandedStates+=F)},"commitExpandedStates"),rt=n.initialLength??0;d[0]=e,l[0]=me(n.initialOrientation),h[0]=rt,f[0]=0,m[0]=0;const lt=Math.abs(r.point.x-s.point.x),ot=Math.abs(r.point.y-s.point.y);p[0]=rt+(R?lt+ot:0),x[0]=R?Cn(lt,ot,n.initialOrientation,n.targetOrientation):0,g[0]=-1,y[0]=1,b[0]=-1,c.setBest(pr(e,n.initialOrientation),0),X(0),a&&(a.maxOpenSet=Math.max(a.maxOpenSet,T));let mt=-1,O;const N=u(P=>{const _=[h[P]+(n.targetLength??0),f[P]+(n.targetOrientation!==void 0&&l[P]!==0&&me(n.targetOrientation)!==l[P]?1:0),m[P],E];(!O||Jt(_,O)<0||Jt(_,O)===0&&L(P,mt)<0)&&(mt=P,O=_)},"considerGoal"),st=u((P,_,at,ct,J,$)=>{const Mt=i(at).point;if(n.arcAllowed&&!n.arcAllowed(_,Mt)||n.initialSide&&g[P]<0&&Sn(_,Mt,n.initialSide)||n.targetSide&&at===o&&Sn(s.point,_,n.targetSide))return;const de=at*3+ct,At=S[de],le=h[P]+J,ue=f[P]+(l[P]!==0&&l[P]!==ct?1:0),he=m[P]+$,fe=At>=0?le-h[At]||ue-f[At]||he-m[At]:-1;if(At>=0&&(fe>0||fe===0&&L(P,g[At])>=0))return;const vt=w++;w>d.length&&(c.ensureStateCapacity(w),d=c.stateVertices,l=c.orientations,h=c.gLengths,f=c.gBends,m=c.gBoundaryTransitions,p=c.fLengths,x=c.fBends,g=c.predecessors,y=c.depths,b=c.ancestor4,I=c.heapChildren,C=c.heapSiblings,D()),d[vt]=at,l[vt]=ct,h[vt]=le,f[vt]=ue,m[vt]=he;const co=Math.abs(Mt.x-s.point.x),lo=Math.abs(Mt.y-s.point.y);p[vt]=le+(R?co+lo:0),x[vt]=ue+(R?Cn(co,lo,ct===1?"H":"V",n.targetOrientation):0),g[vt]=P,y[vt]=y[P]+1;const uo=g[P],ho=uo>=0?g[uo]:-1;b[vt]=ho>=0?g[ho]:-1,c.setBest(de,vt),X(vt)},"relaxArc");for(;T>0;){const P=B;if(O&&(p[P]-O[0]||x[P]-O[1]||m[P]-O[2]||E-O[3])>0)break;const _=W();if(S[d[_]*3+l[_]]!==_)continue;if(F>=Y||et+F>=wt){if(mt>=0&&O)return a&&n.recordOutcome!==!1&&a.routesFound++,Q(),En(mt,d,g,O,i);Q();const $=et+F>=wt?"invocation":"edge";throw new Lt("search_state_cap","Grid routing search-state cap exceeded",$)}if(F++,d[_]===o){N(_);continue}const at=d[_],ct=i(at).point,J=t.getSearchArcs?.(at)??t.searchAdjacencyByVertex?.[at];if(J)for(const $ of J)st(_,ct,$.to,$.orientationOrdinal,$.length,$.boundaryTransitions);else for(const $ of t.adjacencyByVertex?.[at]??t.adjacency.get(at)??[])st(_,ct,$.to,me($.orientation),$.length,$.kind==="portal"?1:0);a&&(a.maxOpenSet=Math.max(a.maxOpenSet,T))}if(mt<0||!O){Q(),a&&n.recordOutcome!==!1&&a.routesImpossible++;return}return a&&n.recordOutcome!==!1&&a.routesFound++,Q(),En(mt,d,g,O,i)}u(xr,"search");function Qe(t,e,o,n={}){return xr(t,e,o,n)}u(Qe,"findShortestRoute");var vo="grid-router";function br(t,e,o,n,i){t.metrics&&(t.metrics.resourceLimitFallbacks++,t.metrics.fallbackReasons[e]++),te.debug(vo,"GRID_ROUTING_RESOURCE_FALLBACK",{edgeId:o,containerId:n,reason:e}),e==="search_state_cap"&&i==="invocation"&&!t.searchBudgetWarningEmitted&&(t.searchBudgetWarningEmitted=!0,te.warn(vo,"GRID_ROUTING_INVOCATION_SEARCH_BUDGET_EXHAUSTED",{edgeId:o,containerId:n,expandedStates:t.searchBudget.expandedStates}))}u(br,"recordFallback");function Ut({context:t,reason:e,edgeId:o,containerId:n,searchStateScope:i,route:r,isValid:s,includeContainerIdInError:a}){const c=r();if(br(t,e,o,n,i),s(c))return c;throw t.metrics&&t.metrics.fallbackValidationFailures++,H("GRID_ROUTE_NOT_FOUND",`Invalid legacy fallback for "${o}"`,{edgeId:o,...a?{containerId:n}:{},reason:e})}u(Ut,"runValidatedFallback");function wr(t,e,o,n,i,r,s,a,c,d,l,h,f){const m=a.fallbackContainers.get(t.lcaContainerId);if(m)return Ut({context:a,reason:m,edgeId:t.edge.id,containerId:t.lcaContainerId,route:r,isValid:u(C=>Et(C,n,i,t.lcaContainerId,s)&&(t.bundleSize<=1||ft(C,h)),"isValid")});const p=a.topologies.get(t.lcaContainerId);if(!p)throw H("GRID_ROUTE_NOT_FOUND",`Missing routing topology "${t.lcaContainerId}"`);if(e.length===0||o.length===0)throw a.metrics&&a.metrics.routesImpossible++,H("GRID_ROUTE_NOT_FOUND",t.bundleSize>1?`No distinct lane route for "${t.edge.id}"`:`No legal endpoint candidates for "${t.edge.id}"`,{edgeId:t.edge.id});let x,g;const y=e.flatMap(C=>o.map(S=>{const v=C.rank*o.length+S.rank,[w,E]=$i(C,S);return{sourceCandidate:C,targetCandidate:S,pairRank:v,lowerCost:[w,E,0,v]}})).sort((C,S)=>Jt(C.lowerCost,S.lowerCost)||Gt(C.sourceCandidate.side)-Gt(S.sourceCandidate.side)||Gt(C.targetCandidate.side)-Gt(S.targetCandidate.side)),b=u((C,S="all")=>{const v=t.bundleSize>1||C?(w,E)=>(t.bundleSize<=1||qe(w,E,h))&&!(C&&f.index.conflictsWithArc(w,E,f.pairKey)):void 0;for(const{sourceCandidate:w,targetCandidate:E,pairRank:R,lowerCost:M}of y)if(!(S==="preferred"&&R!==0)&&!(S==="assigned-side"&&(w.onAssignedSide===!1||E.onAssignedSide===!1))){if(x&&Jt(x.result.cost,M)<=0)break;try{Se({metrics:a.metrics,caps:l.searchCaps,budget:a.searchBudget});const A=Xe(p,w.connect,E.connect,a.metrics,d,t.bundleSize>1&&(w.connect.x===E.connect.x||w.connect.y===E.connect.y)?[{x:(w.connect.x+E.connect.x)/2,y:(w.connect.y+E.connect.y)/2}]:[]),L=a.baseEstimatedBytes+A.estimatedBytes-p.estimatedBytes;if(L>(l.topologyCaps?.maxEstimatedBytes??zt))throw new Lt("estimated_memory_cap","Grid routing estimated_memory_cap exceeded");a.metrics&&(a.metrics.estimatedBytes=Math.max(a.metrics.estimatedBytes,L));const B=A.pointVertexIds.get(gt(w.connect)),T=A.pointVertexIds.get(gt(E.connect));if(B===void 0||T===void 0)throw H("GRID_ROUTE_NOT_FOUND",`Endpoint projection is missing from the routing overlay for "${t.edge.id}"`,{edgeId:t.edge.id,containerId:t.lcaContainerId,source:w.connect,target:E.connect});const G=w.side==="left"||w.side==="right"?"H":"V",X=E.side==="left"||E.side==="right"?"H":"V",W=Qe(A,B,T,{metrics:a.metrics,caps:{...l.searchCaps,maxEstimatedBytes:l.searchCaps?.maxEstimatedBytes??l.topologyCaps?.maxEstimatedBytes??zt},endpointCandidateRank:R,recordOutcome:!1,budget:a.searchBudget,initialOrientation:G,initialLength:q,targetOrientation:X,targetLength:q,topologyValidated:!0,workspace:c,estimatedBytesBase:L,arcAllowed:v});if(!W)continue;const F=z([w.port,...W.points,E.port]).points;if(!Et(F,n,i,t.lcaContainerId,s)||t.bundleSize>1&&!ft(F,h)||C&&f.index.conflictsWithRoute(F,f.pairKey))continue;(!x||Jt(W.cost,x.result.cost)<0)&&(x={result:W,points:F},g=void 0)}catch(A){if(!(A instanceof Lt))throw A;if(x)break;g=A;break}}},"searchPairs"),I=f!==void 0&&f.index.size>0;if(f?.prioritizeEndpointCandidates&&(b(I,"preferred"),b(I,"assigned-side")),x||b(I),!x&&!g&&f!==void 0&&f.index.size>0&&b(!1),g)return Ut({context:a,reason:g.reason,edgeId:t.edge.id,containerId:t.lcaContainerId,searchStateScope:g.searchStateScope,route:r,isValid:u(C=>Et(C,n,i,t.lcaContainerId,s)&&(t.bundleSize<=1||ft(C,h)),"isValid")});if(!x)throw a.metrics&&a.metrics.routesImpossible++,H("GRID_ROUTE_NOT_FOUND",t.bundleSize>1?`No distinct lane route for "${t.edge.id}"`:`No cell-aware route for "${t.edge.id}"`,{edgeId:t.edge.id});if(l.onDualRouteComparison){const C=r(),S=z(x.points),v=z(C);l.onDualRouteComparison({edgeId:t.edge.id,sparse:{valid:!0,length:ee(S.points),bends:S.bends},legacy:{valid:Et(C,n,i,t.lcaContainerId,s),length:ee(v.points),bends:v.bends}})}return x.points}u(wr,"sparseSameContainerRoute");function vr(t,e,o){const n=Rt(t,e);if(!n||n.high-n.low<ht)return;const i=k(t),r=(n.low+n.high)/2,s=o*oo,a=[r-ht/2-s,r+ht/2+s];if(a[0]<n.low||a[1]>n.high)return;const c=u(d=>{const l=e==="left"||e==="right"?{x:e==="left"?i.left:i.right,y:d}:{x:d,y:e==="top"?i.top:i.bottom};return{ownerId:t.id,side:e,port:l,connect:{x:l.x+(e==="left"?-q:e==="right"?q:0),y:l.y+(e==="top"?-q:e==="bottom"?q:0)},rank:0}},"candidate");return{start:c(a[0]),target:c(a[1])}}u(vr,"selfLoopAttachments");function Ir(t,e,o,n,i,r,s,a,c,d){const l=e.parentId??j,h=o.labelRequirements.selfLoops.get(t.edge.id),f=n.fallbackContainers.get(l),m=u(()=>nr(e,s,a,o,h,n.metrics),"legacyRoute");if(f){const g=Ut({context:n,reason:f,edgeId:t.edge.id,containerId:l,route:m,isValid:u(y=>Et(y.points,e,e,l,o)&&ft(y.points,c),"isValid")});return h&&n.metrics&&n.metrics.labelAwareSelfLoopsCommitted++,g}const p=n.topologies.get(l);if(!p||!r)throw H("GRID_ROUTE_NOT_FOUND",`Missing routing topology "${l}"`);const x=so(e,s,a);if(h){for(const g of x){const y=a.get(`${e.id}:${g}`)??0,b=k(e),I=g==="left"||g==="right"?b.cy:b.cx,C=ro(e,g,y,I,h);n.metrics&&(n.metrics.labelAwareSelfLoopCandidates+=C.length);for(const S of C)if(Et(S,e,e,l,o)&&ft(S,c))return n.metrics&&n.metrics.labelAwareSelfLoopsCommitted++,{points:S,side:g,index:y}}n.metrics&&n.metrics.labelAwareSelfLoopFallbacks++}for(const g of x){const y=a.get(`${e.id}:${g}`)??0,b=vr(e,g,y);if(!b)continue;const{start:I,target:C}=b;try{Se({metrics:n.metrics,caps:d.searchCaps,budget:n.searchBudget});const S=Xe(p,I.connect,C.connect,n.metrics,r,[{x:(I.connect.x+C.connect.x)/2,y:(I.connect.y+C.connect.y)/2}]),v=S.pointVertexIds.get(gt(I.connect)),w=S.pointVertexIds.get(gt(C.connect));if(v===void 0||w===void 0)throw H("GRID_ROUTE_NOT_FOUND",`Self-loop endpoint projection is missing from the routing overlay for "${t.edge.id}"`,{edgeId:t.edge.id,containerId:l,source:I.connect,target:C.connect,side:g});const E=g==="left"||g==="right"?"H":"V",R=Qe(S,v,w,{metrics:n.metrics,caps:{...d.searchCaps,maxEstimatedBytes:d.searchCaps?.maxEstimatedBytes??d.topologyCaps?.maxEstimatedBytes??zt},recordOutcome:!1,budget:n.searchBudget,initialOrientation:E,initialSide:g,initialLength:q,targetOrientation:E,targetSide:g,targetLength:q,topologyValidated:!0,workspace:i,estimatedBytesBase:n.baseEstimatedBytes+S.estimatedBytes-p.estimatedBytes,arcAllowed:u((A,L)=>qe(A,L,c),"arcAllowed")});if(!R)continue;const M=z([I.port,...R.points,C.port]).points;if(Et(M,e,e,l,o)&&ft(M,c))return{points:M,side:g,index:y}}catch(S){if(!(S instanceof Lt))throw S;const v=Ut({context:n,reason:S.reason,edgeId:t.edge.id,containerId:l,searchStateScope:S.searchStateScope,route:m,isValid:u(w=>Et(w.points,e,e,l,o)&&ft(w.points,c),"isValid")});return h&&n.metrics&&n.metrics.labelAwareSelfLoopsCommitted++,v}}throw n.metrics&&n.metrics.routesImpossible++,H("GRID_ROUTE_NOT_FOUND",`No distinct self-loop route for "${t.edge.id}"`,{edgeId:t.edge.id,nodeId:e.id})}u(Ir,"sparseSelfLoopRoute");function Rn(t,e,o,n,i,r,s,a,c,d,l=[],h=()=>[],f=()=>[],m=!1,p){const x=s.fallbackContainers.get(e);if(x)return Ut({context:s,reason:x,edgeId:t,containerId:e,route:i,isValid:u(v=>Dt(v,o.ownerId,n.ownerId,e,r)&&ft(v,l),"isValid"),includeContainerIdInError:!0});const g=s.topologies.get(e);if(!g||!c)throw H("GRID_ROUTE_NOT_FOUND",`Missing routing topology "${e}"`);const y=[{start:o,end:n,select:[]}];let b=!1;const I=u(()=>{if(b)return;b=!0;const v=f(),w=h();y.push(...w.map(E=>({start:o,end:E.attachment,select:[E.select]})),...v.map(E=>({start:E.attachment,end:n,select:[E.select]})),...v.flatMap(E=>w.map(R=>({start:E.attachment,end:R.attachment,select:[E.select,R.select]}))))},"appendAlternatives"),C=p!==void 0&&p.index.size>0?[!0,!1]:[!1];try{for(const v of C)for(const[w,E]of y.entries()){const R=E.start,M=E.end;if(w>0&&s.metrics&&s.metrics.hierarchyPortalAlternativeAttempts++,Yi(R.connect,M.connect)){const F=z([R.port,R.connect,M.connect,M.port]).points;if(Dt(F,R.ownerId,M.ownerId,e,r)&&ft(F,l)&&!(v&&p.index.conflictsWithRoute(F,p.pairKey))){for(const Y of E.select)Y();return w>0&&s.metrics&&s.metrics.hierarchyPortalAlternativeSelections++,F}}Se({metrics:s.metrics,caps:d.searchCaps,budget:s.searchBudget});const L=Xe(g,R.connect,M.connect,s.metrics,c),B=s.baseEstimatedBytes+L.estimatedBytes-g.estimatedBytes;if(B>(d.topologyCaps?.maxEstimatedBytes??zt))throw new Lt("estimated_memory_cap","Grid routing estimated_memory_cap exceeded");const T=L.pointVertexIds.get(gt(R.connect)),G=L.pointVertexIds.get(gt(M.connect));if(T===void 0||G===void 0){w===0&&I();continue}const X=Qe(L,T,G,{metrics:s.metrics,caps:{...d.searchCaps,maxEstimatedBytes:d.searchCaps?.maxEstimatedBytes??d.topologyCaps?.maxEstimatedBytes??zt},recordOutcome:!1,budget:s.searchBudget,initialOrientation:R.side==="left"||R.side==="right"?"H":"V",initialSide:R.side,initialLength:Math.abs(R.port.x-R.connect.x)+Math.abs(R.port.y-R.connect.y),targetOrientation:M.side==="left"||M.side==="right"?"H":"V",targetSide:M.side,targetLength:Math.abs(M.port.x-M.connect.x)+Math.abs(M.port.y-M.connect.y),topologyValidated:!0,workspace:a,estimatedBytesBase:B,arcAllowed:l.length>0||v?(F,Y)=>(l.length===0||qe(F,Y,l))&&!(v&&p.index.conflictsWithArc(F,Y,p.pairKey)):void 0});if(!X){w===0&&I();continue}const W=z([R.port,...X.points,M.port]).points;if(!Dt(W,R.ownerId,M.ownerId,e,r)||!ft(W,l)||v&&p.index.conflictsWithRoute(W,p.pairKey)){w===0&&I();continue}for(const F of E.select)F();return w>0&&s.metrics&&s.metrics.hierarchyPortalAlternativeSelections++,W}}catch(v){if(!(v instanceof Lt))throw v;return Ut({context:s,reason:v.reason,edgeId:t,containerId:e,searchStateScope:v.searchStateScope,route:i,isValid:u(w=>Dt(w,o.ownerId,n.ownerId,e,r)&&ft(w,l),"isValid"),includeContainerIdInError:!0})}const S=i();if(Dt(S,o.ownerId,n.ownerId,e,r)&&(ft(S,l)||m&&no(S,l)))return s.metrics&&(s.metrics.compatibilitySegments++,s.metrics.compatibilityRecoveries++),S;throw H("GRID_ROUTE_NOT_FOUND",`No hierarchy route for "${t}" in "${e}" from ${gt(o.connect)} to ${gt(n.connect)}`,{edgeId:t,containerId:e})}u(Rn,"sparseContainerSegment");function Mr(t,e,o,n,i,r,s){const a=t[0].pairKey,c=e.get(a),d=[...new Set(t.flatMap(m=>[...m.source.chain,...m.target.chain].map(({demandKey:p})=>p)))],l=new Map,h=new Map;for(const m of d){const p=o.get(m);p&&l.set(m,p);const x=n.get(m);x!==void 0&&h.set(m,x)}const f=s.get(t[0].lcaContainerId);return{pairKey:a,occupancy:f?{index:f,size:f.size}:void 0,pairRoutes:c?[...c]:void 0,demandKeys:d,pairedPortals:l,demandCoords:h,edges:t.map(({edge:m})=>({edge:m,points:m.points,curve:m.curve,cornerRadius:m.cornerRadius})),instrumentedRoutesLength:i?.length,metrics:r?dr(r):void 0}}u(Mr,"createBundleCheckpoint");function Cr(t,e,o,n,i,r){t.occupancy?.index.truncate(t.occupancy.size),t.pairRoutes?e.set(t.pairKey,[...t.pairRoutes]):e.delete(t.pairKey);for(const s of t.demandKeys){const a=t.pairedPortals.get(s);a?o.set(s,a):o.delete(s);const c=t.demandCoords.get(s);c!==void 0?n.set(s,c):n.delete(s)}for(const s of t.edges)s.edge.points=s.points,s.edge.curve=s.curve,s.edge.cornerRadius=s.cornerRadius;i&&t.instrumentedRoutesLength!==void 0&&(i.length=t.instrumentedRoutesLength),r&&t.metrics&&lr(r,t.metrics)}u(Cr,"restoreBundleCheckpoint");var ns=class{constructor(t,e,o,n){this.layout=t,this.result=e,this.metrics=o,this.options=n,this.searchWorkspace=new gr,this.pairedPortals=new Map,this.ownerSideCounts=new Map,this.selfLoopCounts=new Map,this.pairRoutes=new Map,this.routed=!1}static{u(this,"GridEdgeRoutingSession")}route(){if(this.routed)throw new Error("Grid edge routing session can only be run once");this.routed=!0,this.prepare();const t=new Map;for(const e of this.prepared.orderedPlans){const o=t.get(e.pairKey)??[];o.push(e),t.set(e.pairKey,o)}for(const e of t.values())this.routeBundle(e)}prepare(){or(this.result),this.prepared=Hi(this.layout,this.result),this.modes=cr(this.prepared,this.result,this.metrics,this.options),this.routingContext=sr(this.modes.routedContainerIds,this.result,this.metrics,this.options),this.endpointOverlayScratch=new Map([...this.routingContext.topologies].map(([e,o])=>[e,new Ei(o)])),this.instrumentedRoutes=this.metrics?[]:void 0;const t=new Set;for(const e of this.prepared.orderedPlans)if(e.edge.start!==e.edge.end)for(const o of[...e.source.chain,...e.target.chain]){if(t.has(o.demandKey))continue;t.add(o.demandKey);const n=oe(o.ownerId,o.side);this.ownerSideCounts.set(n,(this.ownerSideCounts.get(n)??0)+1)}}pairedPortal(t){const e=this.pairedPortals.get(t.demandKey);if(e)return e;const o=this.result.forest.nodeById.get(t.ownerId);if(!o?.isGroup)throw H("GRID_ROUTE_NOT_FOUND",`Missing portal owner "${t.ownerId}"`);const n=Pt(o),i=this.prepared.demandCoords.get(t.demandKey)??(t.side==="left"||t.side==="right"?(n.top+n.bottom)/2:(n.left+n.right)/2),r=ne(t.ownerId,n,o.groupTitleRect).find(({side:a})=>a===t.side);if(!r)throw H("GRID_ROUTE_NOT_FOUND",`No legal ${t.side} portal for "${t.ownerId}"`);const s=hn(t.ownerId,n,o.groupTitleRect?{...o.groupTitleRect}:void 0,t.side,Bt(i,r.low,r.high));return this.pairedPortals.set(t.demandKey,s),this.metrics&&(this.metrics.hierarchyPortalPairs++,this.metrics.hierarchyPortalTransitionLength+=s.transition.length),s}alternativePairedPortals(t,e=!0){const o=this.pairedPortal(t),n=this.result.forest.nodeById.get(t.ownerId);if(!n?.isGroup)return[];const i=Pt(n),r=ne(t.ownerId,i,n.groupTitleRect).find(({side:c})=>c===t.side);if(!r)return[];const s=this.result.containers.get(n.id),a=t.side==="left"||t.side==="right"?s?.horizontalCorridors:s?.verticalCorridors;return Wi(o.tangentialCoordinate,r.low,r.high,a??[]).map(c=>{const d=hn(t.ownerId,i,n.groupTitleRect?{...n.groupTitleRect}:void 0,t.side,c);return{attachment:Wt(d,e),select:u(()=>{this.pairedPortals.set(t.demandKey,d),this.prepared.demandCoords.set(t.demandKey,c)},"select")}})}itemSegmentAttachment(t,e){return{ownerId:t.ownerId,...Ie(t.ownerId,t.side,t.demandKey,e,this.result,this.prepared.demandCoords)}}alternativeItemAttachments(t,e,o){const n=this.itemSegmentAttachment(e,o),i=this.result.forest.nodeById.get(e.ownerId);return i?["right","bottom","left","top"].filter(r=>r!==n.side&&!(r==="top"&&We(i))).map(r=>{const s=Rt(i,r);if(!s)return;const a=k(i),c=r==="left"||r==="right"?a.cy:a.cx,d=Math.max(s.low,Math.min(s.high,c+t.laneOffset));return{ownerId:e.ownerId,...Ie(e.ownerId,r,e.demandKey,o,this.result,this.prepared.demandCoords,d)}}).filter(r=>r!==void 0).slice(0,3).map(r=>({attachment:r,select:u(()=>{},"select")})):[]}routePlan(t,e=!0){const o=this.result,n=this.routingContext,i=this.searchWorkspace,r=this.endpointOverlayScratch,s=this.prepared.demandCoords,a=this.ownerSideCounts,c=this.selfLoopCounts,d=this.pairRoutes,l=this.instrumentedRoutes,h=this.metrics,f=this.options,m=this.prepared.eligibleIds,p=this.prepared.endpointCandidatesByEdge,x=this.modes.compatibilityFastRoutes,g=this.modes.sparseHierarchyIds,y=this.modes.sparseLcaIds,b=t.edge,I=b.start?o.forest.nodeById.get(b.start):void 0,C=b.end?o.forest.nodeById.get(b.end):void 0;if(!I||!C)throw H("GRID_MISSING_ENDPOINT",`Missing endpoint for edge "${b.id}"`,{edgeId:b.id});if(I.id===C.id){const D=d.get(t.pairKey)??[],{points:Q,side:rt,index:lt}=Ir(t,I,o,n,i,r.get(I.parentId??j),a,c,D,f),ot=`${I.id}:${rt}`;c.set(ot,lt+1),b.points=Q,b.curve=o.config.curve,b.cornerRadius=o.config.edgeCornerRadius,D.push(Q),d.set(t.pairKey,D),h&&l&&(Mn(h,b.id,Q,l,0,t.laneOffset),l.push(Q));return}const S=t.source.chain[t.source.chain.length-1],v=t.target.chain[t.target.chain.length-1],w=y.has(b.id),E=w?void 0:Me(t,o,s),R=E?E.start:t.source.finalKind==="boundary"?bn(S.ownerId,S.side,S.demandKey,o,s):t.source.chain.length>1?Wt(this.pairedPortal(S),!1):this.itemSegmentAttachment(S,t.lcaContainerId),M=E?E.end:t.target.finalKind==="boundary"?bn(v.ownerId,v.side,v.demandKey,o,s):t.target.chain.length>1?Wt(this.pairedPortal(v),!1):this.itemSegmentAttachment(v,t.lcaContainerId);let A;const L=u(()=>A??=jt(t.lcaContainerId,o,R,M,t.laneIndex),"legacyRoute"),B=x.get(b.id),T=B?(h&&h.compatibilityFastPaths++,B):m.has(b.id)?wr(t,p.get(b.id).sources,p.get(b.id).targets,I,C,L,o,n,i,r.get(t.lcaContainerId),f,d.get(t.pairKey)??[],{index:this.occupancyFor(t.lcaContainerId),pairKey:t.pairKey,prioritizeEndpointCandidates:this.prepared.coordinatedEndpointIds.has(b.id)}):w?Rn(b.id,t.lcaContainerId,R,M,L,o,n,i,r.get(t.lcaContainerId),f,d.get(t.pairKey)??[],()=>t.target.finalKind==="item"&&t.target.chain.length>1?this.alternativePairedPortals(v,!1):[],()=>t.source.finalKind==="item"&&t.source.chain.length>1?this.alternativePairedPortals(S,!1):[],t.bundleSize>1,this.modes.overlapAvoidanceEnabled?{index:this.occupancyFor(t.lcaContainerId),pairKey:t.pairKey}:void 0):vn(b.id,t.lcaContainerId,R,M,L,o,h),G=u((D,Q)=>{if(!g.has(b.id)){for(const{containerId:rt,start:lt,end:ot}of ao(D,o,s))Q.push(vn(b.id,rt,lt,ot,()=>jt(rt,o,lt,ot,t.laneIndex),o,h));return}for(let rt=0;rt<D.chain.length-1;rt++){const lt=D.chain[rt],ot=D.chain[rt+1],mt=rt===0?this.itemSegmentAttachment(lt,ot.ownerId):Wt(this.pairedPortal(lt),!1),O=Wt(this.pairedPortal(ot),!0);Q.push(Rn(b.id,ot.ownerId,mt,O,()=>jt(ot.ownerId,o,mt,O,t.laneIndex),o,n,i,r.get(ot.ownerId),f,d.get(t.pairKey)??[],()=>this.alternativePairedPortals(ot),()=>rt===0?this.alternativeItemAttachments(t,lt,ot.ownerId):[],t.bundleSize>1))}},"routeHierarchyChain"),X=[],W=[];G(t.source,X),G(t.target,W);const F=Ji([...X,T,...W.reverse().map(D=>Zi(D))]),Y=d.get(t.pairKey)??[],wt=ft(F,Y),et=!wt&&t.bundleSize>1&&t.source.chain.length+t.target.chain.length>2&&no(F,Y);if(t.bundleSize>1&&!wt&&(!et||!e))throw h&&h.routesImpossible++,H("GRID_ROUTE_NOT_FOUND",`No distinct lane route for "${b.id}"`,{edgeId:b.id,reason:et?"pair-separation":"no-distinct-route"});if(et&&h&&h.bundleSeparationRelaxations++,b.points=F,b.curve=o.config.curve,b.cornerRadius=o.config.edgeCornerRadius,Y.push(F),d.set(t.pairKey,Y),B||this.occupancyFor(t.lcaContainerId).add(T,t.pairKey),h&&l){const D=t.source.chain.length+t.target.chain.length-2;Mn(h,b.id,F,l,D,t.laneOffset),l.push(F)}}occupancyFor(t){let e=this.modes.routeOccupancy.get(t);return e||(e=new xn,this.modes.routeOccupancy.set(t,e)),e}createBundleCheckpoint(t){return this.occupancyFor(t[0].lcaContainerId),Mr(t,this.pairRoutes,this.pairedPortals,this.prepared.demandCoords,this.instrumentedRoutes,this.metrics,this.modes.routeOccupancy)}restoreBundleCheckpoint(t){Cr(t,this.pairRoutes,this.pairedPortals,this.prepared.demandCoords,this.instrumentedRoutes,this.metrics)}routeBundle(t){if(!(t.length>1&&t.length<=8&&t.every(({edge:i})=>i.start!==i.end))){for(const i of t)this.routePlan(i);return}const o=this.createBundleCheckpoint(t);let n;try{for(const i of t)this.routePlan(i,!1);return}catch(i){n=i,this.restoreBundleCheckpoint(o)}if(!Vi(n))throw n;for(const i of t)this.routePlan(i)}};function Sr(t,e,o,n={}){new ns(t,e,o,n).route()}u(Sr,"routeGridEdges");var os=24,Re=20;function Er(t,e){return!t.label||!t.labelBBox||!(t.labelBBox.height>0)?0:t.labelBBox.height+e}u(Er,"titleBandFor");function Rr(t){if(!Z(t.width)||!Z(t.height))throw H("GRID_MISSING_MEASUREMENT",`Node "${t.id}" must have width and height greater than 0 (width: ${t.width}, height: ${t.height})`,{nodeId:t.id,width:t.width,height:t.height})}u(Rr,"ensureMeasuredNode");function An(t){return Rr(t),{width:t.width,height:t.height}}u(An,"measureChild");function On(t,e,o,n,i){const{forest:r,config:s,sourceOrder:a}=e,c=t===j?void 0:r.groupById.get(t),d=c?Math.max(c.padding??0,s.containerPadding):0,l=c?Er(c,s.titleGap):0,h=c?os:0,f=c?d+l+h:0,m=(r.childrenByParent.get(t)??[]).filter(O=>!pt(O)),{cells:p}=Ci(m,a,s),x=[...p.values()].sort((O,N)=>O.row-N.row||O.column-N.column),g=new Map,y=new Map,b=new Set,I=new Set;for(const O of x){let N=0,st=0;for(const P of O.items){const _=An(P.item);N=Math.max(N,_.width),st+=_.height}O.items.length>1&&(st+=s.cellGap*(O.items.length-1)),O.width=N,O.height=st,b.add(O.row),I.add(O.column),g.set(O.column,Math.max(g.get(O.column)??0,N)),y.set(O.row,Math.max(y.get(O.row)??0,st))}const C=[...b].sort((O,N)=>O-N),S=[...I].sort((O,N)=>O-N),v=pi(e.labelRequirements.byContainer.get(t)??[],p,y,g,C,S,s.rowGap,s.columnGap,i),w=u(O=>Math.max(s.rowGap,v.rowGapAfter.get(O)??0),"rowGapAfter"),E=u(O=>Math.max(s.columnGap,v.columnGapAfter.get(O)??0),"columnGapAfter");if(i){for(const O of v.rowGapAfter.values())O>s.rowGap&&(i.labelSpacingBoundariesExpanded++,i.labelSpacingPixelsAdded+=O-s.rowGap);for(const O of v.columnGapAfter.values())O>s.columnGap&&(i.labelSpacingBoundariesExpanded++,i.labelSpacingPixelsAdded+=O-s.columnGap)}const R=S.reduce((O,N,st)=>O+(g.get(N)??0)+(st<S.length-1?E(N):0),0),M=c?Math.max(R+(d+h)*2,(c.labelBBox?.width??0)+d*2):R,A=c?(M-R)/2:0,L=new Map;let B=A;for(const[O,N]of S.entries())L.set(N,B),B+=(g.get(N)??0)+(O<S.length-1?E(N):0);const T=new Map;let G=f;for(const[O,N]of C.entries())T.set(N,G),G+=(y.get(N)??0)+(O<C.length-1?w(N):0);const X=C.length?G-f:0,W=c?A-Re:-Math.max(s.columnGap/2,xt.containerPadding),F=c?A+R+Re:A+R+Math.max(s.columnGap/2,xt.containerPadding),Y=c?f-Re:-Math.max(s.rowGap/2,xt.containerPadding),wt=c?f+X+Re:f+X+Math.max(s.rowGap/2,xt.containerPadding),et=new Set([W,F]),D=new Set([Y,wt]),Q=new Map,rt=new Map,lt=new Map,ot=new Map;S.length>0&&(Q.set(S[0],W),rt.set(S.at(-1),F));for(let O=0;O<S.length-1;O++){const N=S[O],st=S[O+1],P=(L.get(N)+(g.get(N)??0)+L.get(st))/2;et.add(P),rt.set(N,P),Q.set(st,P)}C.length>0&&(lt.set(C[0],Y),ot.set(C.at(-1),wt));for(let O=0;O<C.length-1;O++){const N=C[O],st=C[O+1],P=(T.get(N)+(y.get(N)??0)+T.get(st))/2;D.add(P),ot.set(N,P),lt.set(st,P)}for(const O of x){const N=L.get(O.column)??A,st=T.get(O.row)??f,P=g.get(O.column)??O.width,_=y.get(O.row)??O.height,at=O.verticalAlign==="top"?0:O.verticalAlign==="bottom"?1:.5;let J=st+(_-O.height)*at;for(const[$,Mt]of O.items.entries()){const{width:de,height:At}=An(Mt.item),le=Mt.horizontalAlign==="left"?0:Mt.horizontalAlign==="right"?1:.5,ue=N+(P-de)*le;Mt.item.x=ue+de/2,Mt.item.y=J+At/2;const he=$>0?J-s.cellGap/2:lt.get(O.row)??Y,fe=$<O.items.length-1?J+At+s.cellGap/2:ot.get(O.row)??wt;$>0&&D.add(he),$<O.items.length-1&&D.add(fe),n.set(Mt.item.id,{containerId:t,row:O.row,column:O.column,cellLeft:N,cellTop:st,cellWidth:P,cellHeight:_,leftCorridorX:Q.get(O.column)??W,rightCorridorX:rt.get(O.column)??F,topCorridorY:he,bottomCorridorY:fe}),J+=At+s.cellGap}}const mt=c?X+l+(d+h)*2:X;o.set(t,{id:t,left:0,top:0,width:M,height:mt,contentLeft:A,contentTop:f,contentRight:c?A+R:R,contentBottom:c?f+X:X,verticalCorridors:[...et].sort((O,N)=>O-N),horizontalCorridors:[...D].sort((O,N)=>O-N)}),c&&(c.width=M,c.height=mt,c.x=M/2,c.y=mt/2,l>0?c.groupTitleRect={left:0,right:M,top:0,bottom:d+l}:delete c.groupTitleRect)}u(On,"layoutContainer");function Ar(t,e,o){return{left:t.left+e,right:t.right+e,top:t.top+o,bottom:t.bottom+o}}u(Ar,"translateRect");function Or(t){const{forest:e,containers:o,itemMeta:n}=t,i=[{containerId:j,offsetX:0,offsetY:0,children:e.childrenByParent.get(j)??[],nextChildIndex:0,entered:!1}];for(;i.length>0;){const r=i[i.length-1];if(!r.entered){r.entered=!0;const c=o.get(r.containerId);c&&(c.left+=r.offsetX,c.top+=r.offsetY,c.contentLeft+=r.offsetX,c.contentRight+=r.offsetX,c.contentTop+=r.offsetY,c.contentBottom+=r.offsetY,c.verticalCorridors=c.verticalCorridors.map(d=>d+r.offsetX),c.horizontalCorridors=c.horizontalCorridors.map(d=>d+r.offsetY))}const s=r.children[r.nextChildIndex];if(!s){i.pop();continue}if(r.nextChildIndex+=1,pt(s))continue;const a=n.get(s.id);a&&(a.cellLeft+=r.offsetX,a.cellTop+=r.offsetY,a.leftCorridorX+=r.offsetX,a.rightCorridorX+=r.offsetX,a.topCorridorY+=r.offsetY,a.bottomCorridorY+=r.offsetY),s.x=(s.x??0)+r.offsetX,s.y=(s.y??0)+r.offsetY,s.isGroup&&(s.groupTitleRect&&(s.groupTitleRect=Ar(s.groupTitleRect,s.x-(s.width??0)/2,s.y-(s.height??0)/2)),i.push({containerId:s.id,offsetX:s.x-(s.width??0)/2,offsetY:s.y-(s.height??0)/2,children:e.childrenByParent.get(s.id)??[],nextChildIndex:0,entered:!1}))}}u(Or,"materializeAbsoluteGeometry");function Br(t,e){const o=new Map(t.nodes.map(i=>[i.id,i]));for(const i of e.nodes){const r=o.get(i.id);r&&(i.x=r.x,i.y=r.y,i.width=r.width,i.height=r.height,r.groupTitleRect?i.groupTitleRect={...r.groupTitleRect}:delete i.groupTitleRect)}const n=new Map(t.edges.map(i=>[i.id,i]));for(const i of e.edges){const r=n.get(i.id);r&&(i.points=r.points?.map(s=>({...s})),i.curve=r.curve,i.cornerRadius=r.cornerRadius,i.portClipping="outline-orthogonal",i.skipCornerFix=r.curve==="linear")}}u(Br,"commitGridGeometry");function Lr(t){return{...t,nodes:t.nodes.map(e=>({...e,labelBBox:e.labelBBox?{...e.labelBBox}:e.labelBBox,groupTitleRect:e.groupTitleRect?{...e.groupTitleRect}:e.groupTitleRect})),edges:t.edges.map(e=>({...e,points:e.points?.map(o=>({...o}))}))}}u(Lr,"cloneGridLayoutData");function Pr(t,e){const o=new Map(e.map(r=>[r.id,r])),n=u(r=>{const s=o.get(r.id);if(!s)throw new Error(`Missing committed grid node "${r.id}"`);return s},"originalNode"),i=u(r=>{const s=n(r);if(!s.isGroup)throw new Error(`Committed grid node "${r.id}" is no longer a group`);return s},"originalGroup");return{nodeById:o,groupById:new Map([...t.groupById].map(([r,s])=>[r,i(s)])),childrenByParent:new Map([...t.childrenByParent].map(([r,s])=>[r,s.map(n)])),rootChildren:t.rootChildren.map(n),postOrderGroups:t.postOrderGroups.map(i),helperNodeIds:new Set(t.helperNodeIds)}}u(Pr,"rebindGridForest");function _r(t,e){const o=ui(t.nodes),n=yi(t),i=mi(t.nodes.filter(s=>!pt(s)));xi(t.nodes.filter(s=>!pt(s)),n);const r={forest:o,config:n,containers:new Map,itemMeta:new Map,sourceOrder:i,labelRequirements:hi(t,o,e.metrics)};for(const s of o.postOrderGroups)On(s.id,r,r.containers,r.itemMeta,e.metrics);return On(j,r,r.containers,r.itemMeta,e.metrics),Or(r),Sr(t,r,e.metrics,e.routing),li(t,void 0,e.metrics),r}u(_r,"runGridLayoutCoreInPlace");function Gr(t,e={}){const o=t,n=Lr(o),i=_r(n,e);return Br(n,o),{...i,forest:Pr(i.forest,o.nodes)}}u(Gr,"runGridLayoutCore");function Tr(t,{measure:e}){const o=Nr(t.config.grid?.lineHops);if(o===!1)return;const n=t.edges.filter(i=>Array.isArray(i.points)&&i.points.length>=2).map(i=>({id:i.id,points:i.points,curve:i.curve,cornerRadius:i.cornerRadius,arrowTypeStart:i.arrowTypeStart,arrowTypeEnd:i.arrowTypeEnd}));Fr(e.groups.edgePaths,n,{enabled:!0,jumpRadius:6,jumpStyle:o})}u(Tr,"applyGridLineJumps");var ls=Dr({prepareLayout:di,runLayoutCore:u(t=>Gr(t),"runLayoutCore"),afterPaint:Tr});export{di as prepareGridLayout,ls as render,Gr as runGridLayoutCore};