@softistx/pulsarix-widget 0.8.3 → 0.8.5

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 (112) hide show
  1. package/dist/chunks/{abnfDiagram-XWFEHMT6.9eyf87ze.js → abnfDiagram-XWFEHMT6.b9yk4x5x.js} +1 -1
  2. package/dist/chunks/architecture-WOLXFQ4H.aft3rkrr.js +1 -0
  3. package/dist/chunks/{architectureDiagram-CSQXQB3N.cy6247c8.js → architectureDiagram-CSQXQB3N.qz18rz0g.js} +1 -1
  4. package/dist/chunks/{blockDiagram-BEDRHYPZ.an5w7tk4.js → blockDiagram-BEDRHYPZ.bb08b9nt.js} +1 -1
  5. package/dist/chunks/{c4Diagram-M2UUVUY5.512525r3.js → c4Diagram-M2UUVUY5.px0epccd.js} +2 -2
  6. package/dist/chunks/{chat-markdown-COFhHMpe.fm39gs4e.js → chat-markdown-CrbWbK1O.k4nmgyey.js} +5 -5
  7. package/dist/chunks/{classDiagram-v2-KXABOMEV.5gw6azyv.js → classDiagram-v2-KXABOMEV.f02387t9.js} +2 -2
  8. package/dist/chunks/{cose-bilkent-JH36ORCC.9t42zmky.js → cose-bilkent-JH36ORCC.azq9k24r.js} +1 -1
  9. package/dist/chunks/cynefin-EF2NZ3EQ.dk039jny.js +1 -0
  10. package/dist/chunks/{cynefinDiagram-NJNITYFG.dta2tfnh.js → cynefinDiagram-NJNITYFG.zt7gprt1.js} +1 -1
  11. package/dist/chunks/{dagre-KIHZ2IZ3.k7b2vmwy.js → dagre-KIHZ2IZ3.702bqbr9.js} +1 -1
  12. package/dist/chunks/{diagram-7YQZDPLS.cd2t0saz.js → diagram-7YQZDPLS.m7vf21j6.js} +1 -1
  13. package/dist/chunks/{diagram-QBROCOUO.1x4d8w7m.js → diagram-QBROCOUO.33e5hv7x.js} +3 -3
  14. package/dist/chunks/{diagram-RJJCUUZO.jk65d82z.js → diagram-RJJCUUZO.94k74bz7.js} +2 -2
  15. package/dist/chunks/{diagram-WERXNKYE.85c3en4j.js → diagram-WERXNKYE.7fe849z6.js} +1 -1
  16. package/dist/chunks/{diagram-YHHI257C.y494n4nm.js → diagram-YHHI257C.qjjjfq7w.js} +2 -2
  17. package/dist/chunks/{diagram-YR4HJLHV.z2n88j9s.js → diagram-YR4HJLHV.310x2we2.js} +1 -1
  18. package/dist/chunks/{ebnfDiagram-N527522P.cgfkzbkp.js → ebnfDiagram-N527522P.a4crteq1.js} +1 -1
  19. package/dist/chunks/{editor-shortcuts-dialog-Ch8GFC-h.n66q7eep.js → editor-shortcuts-dialog-B0ppoiza.x3p4h07t.js} +1 -1
  20. package/dist/chunks/editor.arg3zy29.js +4 -0
  21. package/dist/chunks/{elk-O5DQBFGD.188pnf8b.js → elk-O5DQBFGD.dx61etan.js} +1 -1
  22. package/dist/chunks/{emoji-picker-Cv6ZOgpd.cmp5h45n.js → emoji-picker-CbvQZ2ZL.nst616hd.js} +2 -2
  23. package/dist/chunks/{erDiagram-K3K3BIDK.abxf5cgs.js → erDiagram-K3K3BIDK.qzqv67zm.js} +5 -5
  24. package/dist/chunks/eventmodeling-K75KTNOO.gmm1bcak.js +1 -0
  25. package/dist/chunks/{flow-diagram-B6X1M34-.awp18a9v.js → flow-diagram-AiM6FiIm.73jr19pb.js} +1 -1
  26. package/dist/chunks/flowDiagram-Z6JWZHQI.fzwqg115.js +1 -0
  27. package/dist/chunks/{ganttDiagram-3PRQTZWP.p72ak8vx.js → ganttDiagram-3PRQTZWP.xngzb32h.js} +2 -2
  28. package/dist/chunks/gitGraph-VSP46ZUC.0m8jykgw.js +1 -0
  29. package/dist/chunks/{gitGraphDiagram-VXDFKS5L.vtq378bg.js → gitGraphDiagram-VXDFKS5L.1sm36z2q.js} +1 -1
  30. package/dist/chunks/{grid-E2QIVN74.8xqrr45y.js → grid-E2QIVN74.76pgtn2n.js} +1 -1
  31. package/dist/chunks/illustration-BOW28wq5.bkz28k1x.js +1 -0
  32. package/dist/chunks/{index.pb5tn7q8.js → index.0e4s8r4m.js} +1 -1
  33. package/dist/chunks/{index.8hmrz817.js → index.0k4tbjhp.js} +1 -1
  34. package/dist/chunks/{index.je7pqrtm.js → index.1d7qpsyx.js} +2 -2
  35. package/dist/chunks/{index.x22rwqsz.js → index.32jxrb9b.js} +2 -2
  36. package/dist/chunks/{index.yd3167gn.js → index.7gxz6d1f.js} +2 -2
  37. package/dist/chunks/{index.r8wc9n4q.js → index.7k5v3p25.js} +1 -1
  38. package/dist/chunks/{index.nphh2dtn.js → index.8f3x951p.js} +1 -1
  39. package/dist/chunks/{index.ybmxf4mt.js → index.9bf5qrah.js} +1 -1
  40. package/dist/chunks/{index.mjfjqm0b.js → index.a1bxkgd3.js} +10 -10
  41. package/dist/chunks/{index.cf9nd6xy.js → index.a6rz456z.js} +2 -2
  42. package/dist/chunks/{index.b0pypc3w.js → index.dnnzjw18.js} +1 -1
  43. package/dist/chunks/index.e35b4yh5.js +44 -0
  44. package/dist/chunks/{index.jgvp2nkv.js → index.fbeztcp3.js} +1 -1
  45. package/dist/chunks/{index.2jsv3483.js → index.hvdnkr5m.js} +2 -2
  46. package/dist/chunks/{index.3k4gyba0.js → index.nsckd1vt.js} +2 -2
  47. package/dist/chunks/{index.btq862bx.js → index.r0p3fm9f.js} +1 -1
  48. package/dist/chunks/{index.psaka010.js → index.rfyzb2yv.js} +1 -1
  49. package/dist/chunks/{index.vm7ezzet.js → index.t34t6kpe.js} +2 -2
  50. package/dist/chunks/{index.6tc2v7mk.js → index.wrjdgn4c.js} +2 -2
  51. package/dist/chunks/{index.qy1pndre.js → index.zm5x44tn.js} +1 -1
  52. package/dist/chunks/info-OHQRW6UA.e0a85drn.js +1 -0
  53. package/dist/chunks/{infoDiagram-EZ3ZOAHP.q0047zjz.js → infoDiagram-EZ3ZOAHP.pfd0fjwn.js} +1 -1
  54. package/dist/chunks/{ishikawaDiagram-S3EKX5GW.41wwb1jp.js → ishikawaDiagram-S3EKX5GW.h5kjez1x.js} +2 -2
  55. package/dist/chunks/{journeyDiagram-POQNLL5X.2c9swtn6.js → journeyDiagram-POQNLL5X.55cqc9p0.js} +2 -2
  56. package/dist/chunks/{kanban-definition-BH5XI6FM.xznh9d30.js → kanban-definition-BH5XI6FM.pkdvda4y.js} +1 -1
  57. package/dist/chunks/{markup-color-chrome-ykGNUl8y.955bjndb.js → markup-color-chrome-ykGNUl8y.0ds56d6x.js} +1 -1
  58. package/dist/chunks/{markup-custom-color-Dou38qUi.w8c65wn1.js → markup-custom-color-Dgm2hHI7.7darvajx.js} +1 -1
  59. package/dist/chunks/{mention-list-D4eNNVs0.2k5cdtgy.js → mention-list-CkAUzPBG.mtjgmmzb.js} +1 -1
  60. package/dist/chunks/{mermaid.core.d680cq0m.js → mermaid.core.j7s05j63.js} +4 -4
  61. package/dist/chunks/{mindmap-definition-WVAN44T4.k41b9d4r.js → mindmap-definition-WVAN44T4.x3jbxvft.js} +1 -1
  62. package/dist/chunks/packet-JDAUHWVQ.52409p3r.js +1 -0
  63. package/dist/chunks/{panel.yh0jnkha.js → panel.9tp7gr60.js} +1 -1
  64. package/dist/chunks/{pegDiagram-D4NLKWP3.x25624w6.js → pegDiagram-D4NLKWP3.xq15gqy9.js} +1 -1
  65. package/dist/chunks/pie-XZMESJXO.q5kre8cx.js +1 -0
  66. package/dist/chunks/{pieDiagram-36ENHN4W.j4fq9134.js → pieDiagram-36ENHN4W.8h0wam54.js} +2 -2
  67. package/dist/chunks/{plated-illustration-0ro04oJt.0ebg0x7r.js → plated-illustration-COZYWJ81.xy7ba5mq.js} +1 -1
  68. package/dist/chunks/{quadrantDiagram-ZQUDMS73.1vgwgk90.js → quadrantDiagram-ZQUDMS73.k28g8jpn.js} +2 -2
  69. package/dist/chunks/radar-ABXABTNO.yk872k2n.js +1 -0
  70. package/dist/chunks/railroad-I3PHUGI6.9wfa6vs3.js +1 -0
  71. package/dist/chunks/railroad-abnf-LNEFI6M7.70zznk3b.js +1 -0
  72. package/dist/chunks/railroad-ebnf-DWYD2UWJ.4pvdng0p.js +1 -0
  73. package/dist/chunks/railroad-peg-JR7BVNR7.ev15ebp6.js +1 -0
  74. package/dist/chunks/{railroadDiagram-JIZHGYPL.pbv1rqfp.js → railroadDiagram-JIZHGYPL.e7p2vqgg.js} +1 -1
  75. package/dist/chunks/{render-VIF2ZAQL.2kz294jj.js → render-VIF2ZAQL.w5ytncsg.js} +1 -1
  76. package/dist/chunks/{requirementDiagram-AXW2TVFA.qnxmvqx8.js → requirementDiagram-AXW2TVFA.arekdz02.js} +2 -2
  77. package/dist/chunks/{sankeyDiagram-FBCJTAIF.whv6dy60.js → sankeyDiagram-FBCJTAIF.1d04xcmb.js} +2 -2
  78. package/dist/chunks/{sequenceDiagram-3LA2ROMG.w52darq5.js → sequenceDiagram-3LA2ROMG.j4xywwp1.js} +2 -2
  79. package/dist/chunks/{sizeCapture-2Q2CQKSF.zgscrz2v.js → sizeCapture-2Q2CQKSF.862bnf6p.js} +1 -1
  80. package/dist/chunks/{stateDiagram-v2-ATKHQDJO.zk8w1ht1.js → stateDiagram-v2-ATKHQDJO.xvvtr0y2.js} +2 -2
  81. package/dist/chunks/{swimlanes-YQL5WMAO.cn1pz0jc.js → swimlanes-YQL5WMAO.dtnjb4xt.js} +1 -1
  82. package/dist/chunks/swimlanesDiagram-UCCPES4V.0q8kd5qn.js +8 -0
  83. package/dist/chunks/{timeline-definition-7Z437IG3.atpqnb0j.js → timeline-definition-7Z437IG3.zfhqzc4r.js} +1 -1
  84. package/dist/chunks/treeView-D4JQ5SDB.3fzswdjp.js +1 -0
  85. package/dist/chunks/treemap-SAJKECNS.cgh74bhn.js +1 -0
  86. package/dist/chunks/{usecaseDiagram-RDK6N6HP.ase4sfgd.js → usecaseDiagram-RDK6N6HP.ewxnyz4c.js} +2 -2
  87. package/dist/chunks/{vennDiagram-SHRQU5PJ.as8z3hh5.js → vennDiagram-SHRQU5PJ.wkzf1f00.js} +2 -2
  88. package/dist/chunks/wardley-7MLQ67FV.6q5tgt0s.js +1 -0
  89. package/dist/chunks/{wardleyDiagram-F3OXNVQS.8pf1xb65.js → wardleyDiagram-F3OXNVQS.srjfm4nb.js} +1 -1
  90. package/dist/chunks/{xychartDiagram-GDYJKCDI.z35xw169.js → xychartDiagram-GDYJKCDI.xfa2vexk.js} +2 -2
  91. package/dist/index.js +22 -15
  92. package/package.json +2 -2
  93. package/dist/chunks/architecture-WOLXFQ4H.230b0n6c.js +0 -1
  94. package/dist/chunks/cynefin-EF2NZ3EQ.e9ycn4jb.js +0 -1
  95. package/dist/chunks/editor.yc8q5dd1.js +0 -4
  96. package/dist/chunks/eventmodeling-K75KTNOO.q3y4xbmj.js +0 -1
  97. package/dist/chunks/flowDiagram-Z6JWZHQI.af312t1k.js +0 -1
  98. package/dist/chunks/gitGraph-VSP46ZUC.e4envgw8.js +0 -1
  99. package/dist/chunks/illustration-BpmMAKpO.brt46gkr.js +0 -1
  100. package/dist/chunks/index.5vcex75v.js +0 -44
  101. package/dist/chunks/info-OHQRW6UA.yhwzx56w.js +0 -1
  102. package/dist/chunks/packet-JDAUHWVQ.gp9cmm94.js +0 -1
  103. package/dist/chunks/pie-XZMESJXO.fx385qqa.js +0 -1
  104. package/dist/chunks/radar-ABXABTNO.d58r1mqp.js +0 -1
  105. package/dist/chunks/railroad-I3PHUGI6.cwq84f31.js +0 -1
  106. package/dist/chunks/railroad-abnf-LNEFI6M7.7z7d547m.js +0 -1
  107. package/dist/chunks/railroad-ebnf-DWYD2UWJ.geje0ygg.js +0 -1
  108. package/dist/chunks/railroad-peg-JR7BVNR7.f8xnzs1y.js +0 -1
  109. package/dist/chunks/swimlanesDiagram-UCCPES4V.cy9ywqbn.js +0 -8
  110. package/dist/chunks/treeView-D4JQ5SDB.fj76b06b.js +0 -1
  111. package/dist/chunks/treemap-SAJKECNS.yk7967y9.js +0 -1
  112. package/dist/chunks/wardley-7MLQ67FV.r3k2k1ra.js +0 -1
@@ -1 +1 @@
1
- import{e,n,Ea,Aa,Lr,Es,Qr}from"./index.mjfjqm0b.js";import{Mt,Nt}from"./index.jgvp2nkv.js";import"./index.6tc2v7mk.js";import{ot}from"./index.2jsv3483.js";var rt=1;function So(t,o,r=rt){let i=Math.abs(o.x-t.x),s=Math.abs(o.y-t.y);if(i<=r&&s<=r)return"Z";if(s<=r)return"H";return"V"}e(So,"segmentOrientation");function Eo(t,o=rt){let r=[];for(let i=0;i<t.length-1;i++){let s=t[i],a=t[i+1];r.push({a:s,b:a,orientation:So(s,a,o)})}return r}e(Eo,"segmentsFromPoints");function Ro(t,o=rt){if(t.length===0)return[];let r=[],i={...t[0]};for(let s=1;s<t.length;s++){let a=t[s];if(a.orientation==="Z")continue;if(i.orientation==="Z"){i={...a};continue}if(i.orientation===a.orientation){if(i.orientation==="H"&&Math.abs(i.b.y-a.a.y)<=o&&Math.abs(i.a.y-a.a.y)<=o){i.b=a.b;continue}if(i.orientation==="V"&&Math.abs(i.b.x-a.a.x)<=o&&Math.abs(i.a.x-a.a.x)<=o){i.b=a.b;continue}}if(i.orientation!=="Z")r.push(i);i={...a}}if(i.orientation!=="Z")r.push(i);return r}e(Ro,"mergeCollinear");function H(t,o=rt){if(t.length<2)return{points:[...t],segments:[],bends:0};let r=Eo(t,o).filter((c)=>c.orientation!=="Z"),i=Ro(r,o),s=[];for(let[c,d]of i.entries()){if(c===0)s.push(d.a);s.push(d.b)}let a=0;for(let c=1;c<i.length;c++)if(i[c-1].orientation!==i[c].orientation)a++;return{points:s.length>0?s:[...t],segments:i,bends:a}}e(H,"normalizePolyline");function Gn(t,o){if(t.orientation==="Z"||o.orientation==="Z")return!1;if(t.orientation===o.orientation)return!1;let r=t.orientation==="H"?t:o,i=t.orientation==="V"?t:o,s=r.a.y,a=Math.min(r.a.x,r.b.x),c=Math.max(r.a.x,r.b.x),d=i.a.x,l=Math.min(i.a.y,i.b.y),u=Math.max(i.a.y,i.b.y);if(d>=a&&d<=c&&s>=l&&s<=u){let f=d,p=s,y=Math.abs(f-r.a.x)<0.000001&&Math.abs(p-r.a.y)<0.000001||Math.abs(f-r.b.x)<0.000001&&Math.abs(p-r.b.y)<0.000001,m=Math.abs(f-i.a.x)<0.000001&&Math.abs(p-i.a.y)<0.000001||Math.abs(f-i.b.x)<0.000001&&Math.abs(p-i.b.y)<0.000001;if(y&&m)return!1;return!0}return!1}e(Gn,"segmentsCross");function W(t,o){return t<o?-1:t>o?1:0}e(W,"compareCodeUnits");function z(t){let o=t.x??0,r=t.y??0,i=t.width??40,s=t.height??40;return{cx:o,cy:r,left:o-i/2,right:o+i/2,top:r-s/2,bottom:r+s/2}}e(z,"rectForNode");function Ao(t,o,r,i,s=0){if(t.length<2)return null;let a=o==="end"?t[t.length-1]:t[0],c=o==="end"?t[t.length-2]:t[1],d=c.x-a.x,l=c.y-a.y;if(Math.abs(d)<=s&&Math.abs(l)<=s)return null;if(Math.abs(l)<=s){let u=a.x+Math.sign(d)*r,h=Math.min(a.x,u),f=Math.max(a.x,u);return{cx:(h+f)/2,cy:a.y,left:h,right:f,top:a.y-i,bottom:a.y+i}}if(Math.abs(d)<=s){let u=a.y+Math.sign(l)*r,h=Math.min(a.y,u),f=Math.max(a.y,u);return{cx:a.x,cy:(h+f)/2,left:a.x-i,right:a.x+i,top:h,bottom:f}}return null}e(Ao,"terminalMarkerClearanceRect");function Oo(t,o){let r=o==="start"?t.arrowTypeStart:t.arrowTypeEnd;if(typeof r==="string"){let i=r.trim();if(i.length>0)return i!=="none"&&i!=="arrow_open"}if(typeof t.type!=="string")return!1;if(o==="start"&&t.type.startsWith("double_"))return!0;return o==="end"&&/arrow_(point|cross|circle|barb)|double_arrow/.test(t.type)}e(Oo,"hasTerminalMarker");function Xt(t,o,r=0.000001){return Math.abs(t-o)<=r}e(Xt,"approxEqual");function Bo(t,o,r=0.000001){for(let i=1;i<t.length;i++){let s=t[i-1],a=t[i];if(Xt(s.y,a.y,r)&&!Xt(s.x,a.x,r)){if(Xt(o.y,s.y,r)&&o.x>=Math.min(s.x,a.x)-r&&o.x<=Math.max(s.x,a.x)+r)return!0}else if(Xt(s.x,a.x,r)&&!Xt(s.y,a.y,r)){if(Xt(o.x,s.x,r)&&o.y>=Math.min(s.y,a.y)-r&&o.y<=Math.max(s.y,a.y)+r)return!0}}return!1}e(Bo,"orthogonalPolylineContainsPoint");function re(t){let o=0;for(let r=1;r<t.length;r++){let i=t[r-1],s=t[r];o+=Math.abs(s.x-i.x)+Math.abs(s.y-i.y)}return o}e(re,"manhattanLength");function Vt(t,o,r){if(t.x===o.x&&t.y===o.y)return!1;if(t.y===o.y){let i=t.y,s=Math.min(t.x,o.x),a=Math.max(t.x,o.x),c=i>=r.top&&i<=r.bottom,d=Math.max(s,r.left)<Math.min(a,r.right);return c&&d}if(t.x===o.x){let i=t.x,s=Math.min(t.y,o.y),a=Math.max(t.y,o.y),c=i>=r.left&&i<=r.right,d=Math.max(s,r.top)<Math.min(a,r.bottom);return c&&d}return!1}e(Vt,"segmentIntersectsRectInterior");function It(t,o){for(let r=1;r<t.length;r++)if(Vt(t[r-1],t[r],o))return!0;return!1}e(It,"polylineIntersectsRect");function Gt(t,o,r){return Math.max(o,Math.min(r,t))}e(Gt,"clamp");var X="__grid_root__",Dr="edge-label-";function V(t,o,r){let i=Error(`${t}: ${o}`);return i.code=t,i.details=r,i}e(V,"gridError");var vt={columns:0,rowGap:50,columnGap:50,cellGap:20,containerPadding:20,titleGap:8,horizontalAlign:"center",verticalAlign:"center",curve:"rounded",edgeCornerRadius:Es};function xt(t){return Boolean(t.isEdgeLabel)}e(xt,"isEdgeLabelNode");function tt(t){return typeof t==="number"&&Number.isFinite(t)&&t>0}e(tt,"isFinitePositiveNumber");var Wt=6,nn=12,Lo=2;function Tn(t,o){if(!tt(t.width)||!tt(t.height))return null;let r=o==="H"?t.width:t.height,i=o==="H"?t.height:t.width,s=Math.max(Wt,nn),a=Math.max(Wt,nn);return{along:r,cross:i,startInset:s,endInset:a,requiredAlongSpan:r+s+a+Lo}}e(Tn,"gridLabelSpanRequirement");function Po(t,o){let r=o==="H"?t.width:t.height;return tt(r)?r+Wt*2:0}e(Po,"gridLabelRequiredSegmentLength");var pt=Wt,at=14,kr=18,zr=16,_o=128,Hr=64,yo=2000000,Nn=nn,nt=0.000001,Vr=7,$r=8,ht=e((t)=>H(t,nt),"normalizePolyline");function on(t,o,r,i){let s=Math.max(Math.min(t,o),Math.min(r,i)),a=Math.min(Math.max(t,o),Math.max(r,i));return Math.max(0,a-s)}e(on,"rangeOverlapLength");function Fn(t){let o=ht([...t]).segments;for(let r=0;r<o.length;r++){let i=o[r];for(let s=r+2;s<o.length;s++){let a=o[s];if(Gn(i,a))return!0;if(i.orientation!==a.orientation||i.orientation==="Z")continue;let c=i.orientation==="H"?Math.abs(i.a.y-a.a.y)<=nt:Math.abs(i.a.x-a.a.x)<=nt,d=i.orientation==="H"?on(i.a.x,i.b.x,a.a.x,a.b.x):on(i.a.y,i.b.y,a.a.y,a.b.y);if(c&&d>nt)return!0;let l=i.orientation==="H"?Math.abs(i.a.y-a.a.y):Math.abs(i.a.x-a.a.x);if(!c&&l<Vr&&d>=$r)return!0}}return!1}e(Fn,"polylineHasSelfConflict");var xo=class extends Error{constructor(t){super(`Could not place label for edge "${t.edgeId}"`);this.details=t,this.name="LabelPlacementSearchExhaustedError"}static{e(this,"LabelPlacementSearchExhaustedError")}},Go=class extends Error{static{e(this,"LabelIndexWorkLimitError")}constructor(){super("Grid label index work cap exceeded");this.name="LabelIndexWorkLimitError"}},Kr=class{constructor(t,o){this.limit=t,this.metrics=o,this.used=0}static{e(this,"LabelIndexWorkBudget")}charge(t){if(t<=0)return;if(this.used+t>this.limit)throw new Go;this.used+=t,U(this.metrics,"indexWorkUnits",t)}},Be=class{constructor(t,o){this.workBudget=t,this.metrics=o,this.entriesById=new Map,this.sortedByLeft=[],this.dirty=!1}static{e(this,"CompressedBoundsIndex")}upsert(t){let o=!this.entriesById.has(t.id);if(this.entriesById.set(t.id,t),this.dirty=!0,o&&this.metrics)this.metrics.indexCoordinateCount+=4}remove(t){if(this.entriesById.delete(t))this.dirty=!0}query(t){if(this.dirty){let r=this.entriesById.size;this.workBudget.charge(r*Math.max(1,Math.ceil(Math.log2(r+1)))),this.sortedByLeft=[...this.entriesById.values()].sort((i,s)=>i.bounds.left-s.bounds.left||W(i.id,s.id)),this.dirty=!1}let o=[];for(let r of this.sortedByLeft){if(this.workBudget.charge(1),r.bounds.left>t.right)break;if(Dn(r.bounds,t))o.push(r)}return o}};function rn(t,o){return t.left<o.right&&t.right>o.left&&t.top<o.bottom&&t.bottom>o.top}e(rn,"rectOverlap");function le(t,o){let r=t.width??0,i=t.height??0;return{cx:o.x,cy:o.y,left:o.x-r/2,right:o.x+r/2,top:o.y-i/2,bottom:o.y+i/2}}e(le,"labelRectAt");function To(t){let o=t.groupTitleRect;if(!o)return null;return{cx:(o.left+o.right)/2,cy:(o.top+o.bottom)/2,left:o.left,right:o.right,top:o.top,bottom:o.bottom}}e(To,"groupTitleRect");function U(t,o,r=1){if(t)t[o]+=r}e(U,"incrementMetric");function be(t){return{...t}}e(be,"clonePoint");function zt(t){return{left:t.left,right:t.right,top:t.top,bottom:t.bottom}}e(zt,"boundsForRect");function He(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)}}e(He,"boundsForSegment");function No(t){if(t.length===0)return null;let o=t[0].x,r=t[0].x,i=t[0].y,s=t[0].y;for(let a of t.slice(1))o=Math.min(o,a.x),r=Math.max(r,a.x),i=Math.min(i,a.y),s=Math.max(s,a.y);return{left:o,right:r,top:i,bottom:s}}e(No,"boundsForPoints");function Fo(t,o){return{left:Math.min(t.left,o.left),right:Math.max(t.right,o.right),top:Math.min(t.top,o.top),bottom:Math.max(t.bottom,o.bottom)}}e(Fo,"mergeBounds");function Do(t,o){return{left:t.left-o,right:t.right+o,top:t.top-o,bottom:t.bottom+o}}e(Do,"expandBounds");function Dn(t,o){return t.left<=o.right&&t.right>=o.left&&t.top<=o.bottom&&t.bottom>=o.top}e(Dn,"boundsOverlap");function kn(t){return(t.length<=2?t.map((r,i)=>i):[...t.slice(1,-1).map((r,i)=>i+1),0,t.length-1]).map((r,i)=>({segment:t[r],segmentIndex:r,order:i}))}e(kn,"candidateSegmentsFromSegments");function zn(t,o){return["start","end"].filter((i)=>Oo(t,i)).map((i)=>Ao(o,i,Nn,7,nt)).filter((i)=>i!==null)}e(zn,"markerClearanceRectsFromPoints");function Ve(t,o){let r=ht(o);return{points:r.points,segments:r.segments,candidateSegments:kn(r.segments),markerRects:zn(t,r.points)}}e(Ve,"buildEdgeGeometry");function Yt(t){return t.orientation==="H"?Math.abs(t.b.x-t.a.x):Math.abs(t.b.y-t.a.y)}e(Yt,"segmentLength");function ko(t,o){let r=[{x:o.left,y:o.top},{x:o.right,y:o.top},{x:o.right,y:o.bottom},{x:o.left,y:o.bottom}];for(let i=0;i<r.length;i++)if(Vt(r[i],r[(i+1)%r.length],t))return!0;return!1}e(ko,"borderCutsRect");function Hn(t){return Number.isFinite(t.x)&&Number.isFinite(t.y)}e(Hn,"hasFinitePosition");function Ot(t,o,r){let i=o?.get(t.id);if(i)return ht(i).points;let s=r?.edgeGeometryById.get(t.id);if(s)return s.points;return ht(t.points??[]).points}e(Ot,"pointsForEdge");function $e(t,o,r){if(!o?.has(t.id)){let i=r?.edgeGeometryById.get(t.id);if(i)return i.markerRects}return zn(t,Ot(t,o,r))}e($e,"markerClearanceRectsForEdge");function xe(t,o,r,i){return Math.max(Math.min(t,o),Math.min(r,i))<Math.min(Math.max(t,o),Math.max(r,i))-nt}e(xe,"rangeOverlaps");function zo(t,o,r){let i=Gt(Math.min(t.start,t.end),o,r),s=Gt(Math.max(t.start,t.end),o,r);return s-i>nt?{start:i,end:s}:null}e(zo,"clampInterval");function Ho(t,o,r){let i=t.map((a)=>zo(a,o,r)).filter((a)=>a!==null).sort((a,c)=>a.start-c.start||a.end-c.end);if(i.length===0)return[];let s=[i[0]];for(let a=1;a<i.length;a++){let c=i[a],d=s[s.length-1];if(c.start<=d.end+nt)d.end=Math.max(d.end,c.end);else s.push(c)}return s}e(Ho,"mergeBlockedLabelIntervals");function Ke(t,o,r,i){if(o-t<=nt)return[];let s=[],a=t;for(let u of Ho(r,t,o)){if(u.start-a>nt)s.push({start:a,end:u.start});a=Math.max(a,u.end)}if(o-a>nt)s.push({start:a,end:o});let c=s.map((u)=>({value:Gt(i,u.start,u.end),start:u.start,end:u.end}));c.sort((u,h)=>{let f=Math.abs(u.value-i)-Math.abs(h.value-i);if(Math.abs(f)>nt)return f;let p=h.end-h.start-(u.end-u.start);if(Math.abs(p)>nt)return p;return u.value-h.value});let d=new Set,l=[];for(let u of c){let h=Math.round(u.value*1e6)/1e6;if(d.has(h))continue;d.add(h),l.push(u.value)}return l}e(Ke,"centerCandidatesFromIntervals");function Vo(t){if(t.isGroup)return null;if(xt(t)&&!Hn(t))return null;return z(t)}e(Vo,"obstacleRectForNode");function $o(t,o){let r=o?.edgeGeometryById.get(t.id);if(r)return r.candidateSegments;return kn(ht(t.points??[]).segments)}e($o,"candidateSegments");function Vn(t,o,r){let i=t.edgeGeometryById.get(o);if(i)i.segments.forEach((s,a)=>t.segmentIndex.remove(`${o}:${a}`));t.edgeGeometryById.set(o,r),r.segments.forEach((s,a)=>{t.segmentIndex.upsert({id:`${o}:${a}`,edgeId:o,segment:s,bounds:He(s)})})}e(Vn,"storeEdgeGeometry");function Ht(t,o,r){let i=Ve(o,r);o.points=i.points.map(be),Vn(t,o.id,i)}e(Ht,"setEdgePoints");function Ko(t,o){t.placedLabelIndex.upsert({id:`label:${o.nodeId}`,nodeId:o.nodeId,rect:o.rect,bounds:zt(o.rect)})}e(Ko,"upsertPlacedLabelObstacle");function jo(t,o,r){let i={edgeById:new Map,edgeGeometryById:new Map,obstacleIndex:new Be(o,r),placedLabelIndex:new Be(o,r),groupBorderIndex:new Be(o,r),segmentIndex:new Be(o,r),searchBounds:{left:0,right:0,top:0,bottom:0},metrics:r},s=null,a=e((c)=>{s=s?Fo(s,c):{...c}},"rememberBounds");for(let c of t.nodes){if(c.isGroup){let u=z(c),h=zt(u);i.groupBorderIndex.upsert({id:`border:${c.id}`,rect:u,bounds:h}),a(h);let f=To(c);if(f){let p=zt(f);i.obstacleIndex.upsert({id:`title:${c.id}`,rect:f,bounds:p}),a(p)}continue}let d=Vo(c);if(!d)continue;let l={id:`${xt(c)?"label":"node"}:${c.id}`,rect:d,bounds:zt(d),nodeId:c.id};if(xt(c))i.placedLabelIndex.upsert(l);else i.obstacleIndex.upsert(l);a(l.bounds)}for(let c of t.edges){i.edgeById.set(c.id,c);let d=Ve(c,c.points??[]);Vn(i,c.id,d);let l=No(d.points);if(l)a(l)}return i.searchBounds=Do(s??{left:0,right:0,top:0,bottom:0},128),i}e(jo,"createEdgeLabelContext");function Zt(t,o,r,i={}){U(t.metrics,r);let s=[],a=e((c)=>{for(let d of c){if(d.nodeId&&(d.nodeId===i.excludeNodeId||i.skipNodeIds?.has(d.nodeId)))continue;s.push(d)}},"appendEntries");return a(t.obstacleIndex.query(o)),a(t.placedLabelIndex.query(o)),U(t.metrics,"obstacleCandidatesVisited",s.length),s}e(Zt,"queryObstacleEntries");function je(t,o,r,i,s){U(t.metrics,s);let a=i?new Set(i.keys()):void 0,c=[],d=t.segmentIndex.query(o);for(let u of d){if(u.edgeId===r||a?.has(u.edgeId))continue;c.push(u)}let l=d.length;if(i)for(let[u,h]of i){if(u===r)continue;let f=t.edgeById.get(u);if(!f)continue;Ve(f,h).segments.forEach((y,m)=>{let b=He(y);if(!Dn(b,o))return;l+=1,c.push({id:`override:${u}:${m}`,edgeId:u,segment:y,bounds:b})})}return U(t.metrics,"segmentCandidatesVisited",l),c}e(je,"queryForeignSegments");function Ue(t,o,r,i){U(t.metrics,"foreignEdgeLookups");let s=new Set;for(let a of je(t,zt(o),r,i,"segmentRectQueries"))if(Vt(a.segment.a,a.segment.b,o))s.add(a.edgeId);return[...s].sort(W)}e(Ue,"foreignEdgeIdsIntersectingRect");function $n(t,o){if(!tt(o.width)||!tt(o.height))return null;if(t.orientation==="H")return{left:Math.min(t.a.x,t.b.x)-o.width/2,right:Math.max(t.a.x,t.b.x)+o.width/2,top:t.a.y-o.height/2,bottom:t.a.y+o.height/2};return{left:t.a.x-o.width/2,right:t.a.x+o.width/2,top:Math.min(t.a.y,t.b.y)-o.height/2,bottom:Math.max(t.a.y,t.b.y)+o.height/2}}e($n,"obstacleBandQueryBounds");function Uo(t,o,r){if(t.orientation==="H"){let s=(o.width??0)+pt*2+at;return{left:Math.min(t.a.x,t.b.x)-s,right:Math.max(t.a.x,t.b.x)+s,top:r.top,bottom:r.bottom}}let i=(o.height??0)+pt*2+at;return{left:r.left,right:r.right,top:Math.min(t.a.y,t.b.y)-i,bottom:Math.max(t.a.y,t.b.y)+i}}e(Uo,"detourLineQueryBounds");function Xo(t,o){if(t.orientation==="H")return{left:Math.min(t.a.x,t.b.x)-pt,right:Math.max(t.a.x,t.b.x)+pt,top:o.top,bottom:o.bottom};return{left:o.left,right:o.right,top:Math.min(t.a.y,t.b.y)-pt,bottom:Math.max(t.a.y,t.b.y)+pt}}e(Xo,"rerouteLineQueryBounds");function ue(t,o,r,i,s,a){for(let c of Zt(i,zt(t),"obstacleRectQueries",{excludeNodeId:r}))if(rn(t,c.rect))return!1;for(let c of i.groupBorderIndex.query(zt(t)))if(ko(t,c.rect))return!1;for(let c of $e(o,s,i))if(rn(t,c))return!1;for(let c of je(i,zt(t),o.id,s,"segmentRectQueries")){if(a?.has(c.edgeId))continue;if(Vt(c.segment.a,c.segment.b,t))return!1}return!0}e(ue,"rectSafeForLabel");function Wo(t,o){return o.orientation==="Z"?0:Po(t,o.orientation)}e(Wo,"requiredSegmentLength");function Xe(t,o,r,i,s,a){if(!tt(o.width)||!tt(o.height))return null;let{width:c,height:d}=o,l=r.orientation==="H"?c/2+pt:d/2+pt,u=r.orientation==="H"?Math.min(r.a.x,r.b.x)+l:Math.min(r.a.y,r.b.y)+l,h=r.orientation==="H"?Math.max(r.a.x,r.b.x)-l:Math.max(r.a.y,r.b.y)-l;if(h-u<=nt)return null;let f=[],p=$n(r,o);if(!p)return null;let y=e((m)=>{if(r.orientation==="H"){let x=r.a.y-d/2,w=r.a.y+d/2;if(xe(x,w,m.top,m.bottom))f.push({start:m.left-c/2,end:m.right+c/2});return}let b=r.a.x-c/2,g=r.a.x+c/2;if(xe(b,g,m.left,m.right))f.push({start:m.top-d/2,end:m.bottom+d/2})},"addRect");for(let m of Zt(i,p,"obstacleBandQueries",{excludeNodeId:o.id}))y(m.rect);for(let m of $e(t,s,i))y(m);if(a)for(let m of je(i,p,t.id,s,"segmentBandQueries")){let b=m.segment;if(r.orientation==="H"){let w=r.a.y-o.height/2,M=r.a.y+o.height/2;if(b.orientation==="H"){if(w<b.a.y&&M>b.a.y)f.push({start:Math.min(b.a.x,b.b.x)-o.width/2,end:Math.max(b.a.x,b.b.x)+o.width/2})}else if(xe(w,M,Math.min(b.a.y,b.b.y),Math.max(b.a.y,b.b.y)))f.push({start:b.a.x-o.width/2,end:b.a.x+o.width/2});continue}let g=r.a.x-o.width/2,x=r.a.x+o.width/2;if(b.orientation==="V"){if(g<b.a.x&&x>b.a.x)f.push({start:Math.min(b.a.y,b.b.y)-o.height/2,end:Math.max(b.a.y,b.b.y)+o.height/2})}else if(xe(g,x,Math.min(b.a.x,b.b.x),Math.max(b.a.x,b.b.x)))f.push({start:b.a.y-o.height/2,end:b.a.y+o.height/2})}return{low:u,high:h,blocked:f}}e(Xe,"blockedCenterIntervals");function Yo(t,o,r,i){if(Yt(r)<Wo(o,r))return null;let s=Xe(t,o,r,i,void 0,!0);if(!s)return null;let a=r.orientation==="H"?(Math.min(r.a.x,r.b.x)+Math.max(r.a.x,r.b.x))/2:(Math.min(r.a.y,r.b.y)+Math.max(r.a.y,r.b.y))/2,c=Ke(s.low,s.high,s.blocked,a);for(let d of c){let l=r.orientation==="H"?{x:d,y:r.a.y}:{x:r.a.x,y:d},u=le(o,l);if(ue(u,t,o.id,i))return l}return null}e(Yo,"placementOnExistingSegment");function qo(t,o,r,i,s){let a=Xe(t,o,r,i,void 0,!1);if(!a)return null;let c=r.orientation==="H"?(Math.min(r.a.x,r.b.x)+Math.max(r.a.x,r.b.x))/2:(Math.min(r.a.y,r.b.y)+Math.max(r.a.y,r.b.y))/2,d=Ke(a.low,a.high,a.blocked,c);for(let l of d){let u=r.orientation==="H"?{x:l,y:r.a.y}:{x:r.a.x,y:l},h=le(o,u),f=new Map,p=Ue(i,h,t.id).map((m)=>i.edgeById.get(m)).filter((m)=>m!==void 0),y=!0;for(let m of p){let b=he(m,h,i,s,f);if(!b){y=!1;break}f.set(m.id,b)}if(!y)continue;if(!ue(h,t,o.id,i,f))continue;for(let[m,b]of f){let g=i.edgeById.get(m);if(g)Ht(i,g,b)}return u}return null}e(qo,"placementOnExistingSegmentWithReroutes");function ve(t,o,r){for(let i of ht(t).segments)for(let s of Zt(o,He(i),"obstaclePolylineQueries",{skipNodeIds:r}))if(Vt(i.a,i.b,s.rect))return!0;return!1}e(ve,"polylineHitsProtectedObstacles");function te(t,o,r){let i=r.get(t);return!i||Bo(o,i.center,nt)}e(te,"labelStillAnchored");function Kn(t){let o=[];for(let r=0;r<zr;r++){let i=t+at+r*kr;o.push(-i,i)}return o}e(Kn,"detourOffsets");function Ae(t,o){let r=new Map;for(let i of t){let s=Math.round(i*1e6)/1e6;if(!r.has(s))r.set(s,i)}return[...r.values()].sort((i,s)=>{let a=Math.abs(i-o)-Math.abs(s-o);if(Math.abs(a)>nt)return a;return i-s})}e(Ae,"uniqueSortedCandidates");function jn(t,o,r,i){if(!tt(o.width)||!tt(o.height))return[];let{width:s,height:a}=o,c=r.orientation==="H"?r.a.y:r.a.x,d=r.orientation==="H"?a/2:s/2,l=Kn(d).map((h)=>c+h),u=e((h)=>{if(r.orientation==="H"){l.push(h.top-d-at),l.push(h.bottom+d+at);return}l.push(h.left-d-at),l.push(h.right+d+at)},"addRect");for(let h of Zt(i,Uo(r,o,i.searchBounds),"obstacleBandQueries",{excludeNodeId:o.id}))u(h.rect);for(let h of $e(t,void 0,i))u(h);return Ae(l,c).slice(0,_o)}e(jn,"detourLineCandidates");function sn(t,o,r,i,s){let a=t.orientation==="H"?t.a.y:t.a.x,c=[];for(let h of Kn(0))if(t.orientation==="H")c.push(h<0?o.top+h:o.bottom+h);else c.push(h<0?o.left+h:o.right+h);let d=e((h)=>{if(t.orientation==="H"){c.push(h.top-at),c.push(h.bottom+at);return}c.push(h.left-at),c.push(h.right+at)},"addRect");for(let h of Zt(r,Xo(t,r.searchBounds),"obstacleBandQueries",{skipNodeIds:i}))d(h.rect);let l=Ae(c,a);return(s?.orientation===t.orientation?l.filter((h)=>{if(s.side==="top")return h<o.top;if(s.side==="bottom")return h>o.bottom;if(s.side==="left")return h<o.left;return h>o.right}):l).slice(0,_o)}e(sn,"rerouteLineCandidates");function Qo(t,o,r,i,s){if(!tt(o.width)||!tt(o.height))return[];let{width:a,height:c}=o,d=r.orientation==="H"?{orientation:"H",a:{x:r.a.x,y:i},b:{x:r.b.x,y:i}}:{orientation:"V",a:{x:i,y:r.a.y},b:{x:i,y:r.b.y}},l=Xe(t,o,d,s,void 0,!1);if(!l){let h=r.orientation==="H"?(Math.min(r.a.x,r.b.x)+Math.max(r.a.x,r.b.x))/2:(Math.min(r.a.y,r.b.y)+Math.max(r.a.y,r.b.y))/2,f=[h],p=$n(d,o),y=e((m)=>{if(r.orientation==="H"){f.push(m.left-at-a/2),f.push(m.right+at+a/2);return}f.push(m.top-at-c/2),f.push(m.bottom+at+c/2)},"addRect");if(p)for(let m of Zt(s,p,"obstacleBandQueries",{excludeNodeId:o.id}))y(m.rect);return Ae(f,h).slice(0,Hr)}let u=r.orientation==="H"?(Math.min(r.a.x,r.b.x)+Math.max(r.a.x,r.b.x))/2:(Math.min(r.a.y,r.b.y)+Math.max(r.a.y,r.b.y))/2;return Ke(l.low,l.high,l.blocked,u)}e(Qo,"detourCenterCandidates");function Un(t,o,r){let i=o>=t?1:-1;return o+i*(r+pt)}e(Un,"detourReturnCoordinate");var jr={along:e((t)=>t.x,"along"),cross:e((t)=>t.y,"cross"),point:e((t,o)=>({x:t,y:o}),"point"),labelAlongSize:e((t)=>t.width??0,"labelAlongSize"),labelCrossSize:e((t)=>t.height??0,"labelCrossSize")},Ur={along:e((t)=>t.y,"along"),cross:e((t)=>t.x,"cross"),point:e((t,o)=>({x:o,y:t}),"point"),labelAlongSize:e((t)=>t.height??0,"labelAlongSize"),labelCrossSize:e((t)=>t.width??0,"labelCrossSize")};function Xn(t){return t.orientation==="H"?jr:Ur}e(Xn,"detourAxis");function Zo(t,o,r,i,s,a){if(!tt(i.width)||!tt(i.height))return null;let c=t[o],d=t[o+1],l=Xn(r),u=l.cross(r.a),h=l.along(c),f=l.along(d),p=l.labelAlongSize(i)+pt*2,y=s-p/2,m=s+p/2,b=y<Math.min(h,f)-nt,g=m>Math.max(h,f)+nt,x=f>=h?1:-1,w=Math.max(0,Math.min(Nn,Math.abs(f-h)/2-nt)),M=h+x*w,S=f-x*w;if(!b&&!g)return ht([...t.slice(0,o),c,l.point(y,u),l.point(y,a),l.point(m,a),l.point(m,u),d,...t.slice(o+2)]).points;let E=Un(u,a,l.labelCrossSize(i)/2),I=[...t.slice(0,o),c];if(b)I.push(l.point(M,u),l.point(M,E),l.point(y,E),l.point(y,a));else I.push(l.point(y,u),l.point(y,a));if(I.push(l.point(m,a)),g)I.push(l.point(m,E),l.point(S,E),l.point(S,u));else I.push(l.point(m,u));return I.push(d,...t.slice(o+2)),ht(I).points}e(Zo,"buildLabelDetourPoints");function Jo(t,o,r,i,s,a,c){if(!tt(i.width)||!tt(i.height))return null;let d=t[o],l=t[o+1],u=c?4:2,h=Xn(r),f=h.cross(r.a),p=h.along(d),y=h.along(l),m=h.labelAlongSize(i)+pt*2,b=s-m/2,g=s+m/2,x=y>=p?1:-1,w=Math.max(0,Math.min(Nn,Math.abs(y-p)/u-nt)),M=p+x*w,S=y-x*w,E=Un(f,a,h.labelCrossSize(i)/2);return ht([...t.slice(0,o),d,h.point(M,f),h.point(M,a),h.point(b,a),h.point(g,a),h.point(g,E),h.point(S,E),h.point(S,f),l,...t.slice(o+2)]).points}e(Jo,"buildExtendedLabelDetourPoints");function ti(t,o){if(!tt(o.width)||!tt(o.height))return[];if(t.orientation==="H"){let s=Math.min(t.a.x,t.b.x),a=Math.max(t.a.x,t.b.x);return[s-o.width/2-at,a+o.width/2+at]}let r=Math.min(t.a.y,t.b.y),i=Math.max(t.a.y,t.b.y);return[r-o.height/2-at,i+o.height/2+at]}e(ti,"externalDetourCenterCandidates");function Wn(t,o){let r=0,i=0;for(let s of ht([...t]).segments){if(!Vt(s.a,s.b,o))continue;if(r++,s.orientation==="H")i+=Math.max(0,Math.min(Math.max(s.a.x,s.b.x),o.right)-Math.max(Math.min(s.a.x,s.b.x),o.left));else if(s.orientation==="V")i+=Math.max(0,Math.min(Math.max(s.a.y,s.b.y),o.bottom)-Math.max(Math.min(s.a.y,s.b.y),o.top))}return{count:r,length:i}}e(Wn,"blockedIntersectionScore");function an(t,o,r){let i=Wn(t,o);return i.count<r.count||i.count===r.count&&i.length<r.length-nt}e(an,"reducesBlockedIntersections");function ei(t,o,r){let i=ht([...t]).segments.find((c)=>Vt(c.a,c.b,o));if(!i||i.orientation==="Z")return null;let s=i.orientation==="H"?Math.abs(i.a.y-o.top)<=Math.abs(o.bottom-i.a.y)?"top":"bottom":Math.abs(i.a.x-o.left)<=Math.abs(o.right-i.a.x)?"left":"right",a=r.map((c)=>c.edgeId).sort(W);return{key:JSON.stringify([a,i.orientation,s]),orientation:i.orientation,side:s}}e(ei,"rerouteLane");function ni(t,o,r,i,s,a,c){let d=ht(o),l=Wn(d.points,i),u=d.segments[r];if(!u||u.orientation==="Z")return null;let h=d.points[r],f=d.points[r+1],p=a.get(t.id)?.nodeId,y=new Set;if(p)y.add(p);if(u.orientation==="H"){let w=Math.min(h.x,f.x),M=Math.max(h.x,f.x),S=Math.max(w,i.left-pt),E=Math.min(M,i.right+pt);if(E-S<=nt)return U(s.metrics,"rerouteRejectedDegenerateSpan"),null;for(let I of sn(u,i,s,y,c)){U(s.metrics,"rerouteCandidatesEvaluated");let v=ht([...d.points.slice(0,r),h,{x:S,y:u.a.y},{x:S,y:I},{x:E,y:I},{x:E,y:u.a.y},f,...d.points.slice(r+2)]).points;if(It(v,i)&&!an(v,i,l)){U(s.metrics,"rerouteRejectedBlockedRect");continue}if(It(v,i))U(s.metrics,"reroutePartialProgressCandidates");if(ve(v,s,y)){U(s.metrics,"rerouteRejectedProtectedObstacle");continue}if(!te(t.id,v,a)){U(s.metrics,"rerouteRejectedLabelAnchor");continue}return v}return null}let m=Math.min(h.y,f.y),b=Math.max(h.y,f.y),g=Math.max(m,i.top-pt),x=Math.min(b,i.bottom+pt);if(x-g<=nt)return U(s.metrics,"rerouteRejectedDegenerateSpan"),null;for(let w of sn(u,i,s,y,c)){U(s.metrics,"rerouteCandidatesEvaluated");let M=ht([...d.points.slice(0,r),h,{x:u.a.x,y:g},{x:w,y:g},{x:w,y:x},{x:u.a.x,y:x},f,...d.points.slice(r+2)]).points;if(It(M,i)&&!an(M,i,l)){U(s.metrics,"rerouteRejectedBlockedRect");continue}if(It(M,i))U(s.metrics,"reroutePartialProgressCandidates");if(ve(M,s,y)){U(s.metrics,"rerouteRejectedProtectedObstacle");continue}if(!te(t.id,M,a)){U(s.metrics,"rerouteRejectedLabelAnchor");continue}return M}return null}e(ni,"rerouteSegmentAroundRect");function he(t,o,r,i,s,a){let c=Ot(t,s,r);for(let d=0;d<8;d++){if(!It(c,o))return c;let l=ht(c),u=l.points.findIndex((f,p)=>{if(p===l.points.length-1)return!1;return Vt(f,l.points[p+1],o)});if(u<0)return c;let h=ni(t,l.points,u,o,r,i,a);if(!h)return null;c=h}return It(c,o)?null:c}e(he,"rerouteForeignEdgeAroundRect");function oi(t,o,r,i,s){let a=Ot(t,s,r),c=a;for(let d=0;d<2;d++){let l=!1;for(let u of o){if(!It(c,u.rect))continue;U(r.metrics,"individualLabelRerouteAttempts"),s.set(t.id,c);let h=he(t,u.rect,r,i,s);if(!h)return s.set(t.id,a),null;U(r.metrics,"individualLabelRerouteSuccesses"),c=h,l=!0}if(o.every((u)=>!It(c,u.rect)))return c;if(!l)break}return s.set(t.id,a),null}e(oi,"rerouteForeignEdgeAroundLabels");function ii(t,o,r,i,s){if(!tt(o.width)||!tt(o.height))return null;let a=Ot(t,void 0,i),c=r.segment;for(let d of jn(t,o,c,i)){let l=Ae(ti(c,o),c.orientation==="H"?(Math.min(c.a.x,c.b.x)+Math.max(c.a.x,c.b.x))/2:(Math.min(c.a.y,c.b.y)+Math.max(c.a.y,c.b.y))/2);for(let u of l){let h=Jo(a,r.segmentIndex,c,o,u,d,t.start===t.end);if(!h)continue;if(t.start===t.end&&Fn(h))continue;if(ve(h,i,new Set([o.id])))continue;let f=c.orientation==="H"?{x:u,y:d}:{x:d,y:u},p=le(o,f),y=new Map([[t.id,h]]),m=Ue(i,p,t.id,y).map((g)=>i.edgeById.get(g)).filter((g)=>g!==void 0),b=!0;for(let g of m){let x=he(g,p,i,s,y);if(!x){b=!1;break}y.set(g.id,x)}if(!b)continue;if(!ue(p,t,o.id,i,y))continue;Ht(i,t,h);for(let[g,x]of y){if(g===t.id)continue;let w=i.edgeById.get(g);if(w)Ht(i,w,x)}return f}}return null}e(ii,"labelPlacementWithExtendedDetour");function ri(t,o,r,i,s){if(!tt(o.width)||!tt(o.height))return null;let a=Ot(t,void 0,i),c=r.segment;for(let d of jn(t,o,c,i)){let l=Qo(t,o,c,d,i);for(let u of l){let h=Zo(a,r.segmentIndex,c,o,u,d);if(!h)continue;if(t.start===t.end&&Fn(h))continue;if(ve(h,i,new Set([o.id])))continue;let f=c.orientation==="H"?{x:u,y:d}:{x:d,y:u},p=le(o,f),y=new Map([[t.id,h]]),m=Ue(i,p,t.id,y).map((g)=>i.edgeById.get(g)).filter((g)=>g!==void 0),b=!0;for(let g of m){let x=he(g,p,i,s,y);if(!x){b=!1;break}y.set(g.id,x)}if(!b)continue;if(!ue(p,t,o.id,i,y))continue;Ht(i,t,h);for(let[g,x]of y){if(g===t.id)continue;let w=i.edgeById.get(g);if(w)Ht(i,w,x)}return f}}return null}e(ri,"labelPlacementWithDetour");function si(t){return Boolean(t&&xt(t))}e(si,"isPreparedLabelNode");function Yn(t,o,r){let i=t.points?.find((d)=>Number.isFinite(d.x)&&Number.isFinite(d.y)),s=t.start?r.get(t.start):void 0,a=t.end?r.get(t.end):void 0,c=i??(s&&Hn(s)?s:void 0)??a;if(c&&Number.isFinite(c.x)&&Number.isFinite(c.y)){o.x=c.x,o.y=c.y;return}delete o.x,delete o.y}e(Yn,"parkDegenerateLabel");function ai(t,o,r){let i;for(let s of ht(t.points??[]).segments){if(s.orientation==="Z")continue;if(!i||Yt(s)>Yt(i))i=s}if(!i){Yn(t,o,r);return}o.x=(i.a.x+i.b.x)/2,o.y=(i.a.y+i.b.y)/2}e(ai,"placeLabelAtRouteMidpoint");function ci(t){return`${Dr}${t.start??""}-${t.end??""}-${t.id}`}e(ci,"preferredGridLabelNodeId");function di(t,o){let r=t.labelNodeId??ci(t),i=r,s=1;while(!0){if(!o.has(i))return i;i=`${r}-${s}`,s+=1}}e(di,"ensureUniqueGridLabelNodeId");function li(t){let o=new Map;for(let i of t.nodes)o.set(i.id,i);let r=[];for(let i of t.edges){if(!i.label||i.label.length===0)continue;let s=i.start?o.get(i.start):void 0,a=i.labelNodeId?o.get(i.labelNodeId):void 0;if(si(a)){if(a.label=i.label,a.labelStyle=Array.isArray(i.labelStyle)?i.labelStyle[0]:i.labelStyle??"",a.edgeStart=i.start??"",a.edgeEnd=i.end??"",s?.dir)a.dir=s.dir;i.label=void 0,i.text=void 0;continue}let c=di(i,o),d={id:c,label:i.label,edgeStart:i.start??"",edgeEnd:i.end??"",shape:"labelRect",width:0,height:0,isEdgeLabel:!0,isDummy:!0,isGroup:!1,parentId:void 0,labelStyle:Array.isArray(i.labelStyle)?i.labelStyle[0]:i.labelStyle??"",...s?.dir?{dir:s.dir}:{}};r.push(d),o.set(c,d),i.labelNodeId=c,i.label=void 0,i.text=void 0}t.nodes.push(...r)}e(li,"prepareGridLayout");function ui(t,o,r,i={}){let s=new Map;for(let x of t.nodes)s.set(x.id,x);let a=t.nodes.filter(xt),c=new Map(a.map((x)=>[x.id,{x:x.x,y:x.y}]));for(let x of a)delete x.x,delete x.y;let d=t.edges.map((x,w)=>{if(!x.labelNodeId)return null;let M=s.get(x.labelNodeId);if(!M)return null;if(!tt(M.width)||!tt(M.height))return U(o,"unmeasuredLabelsSkipped"),null;return{edge:x,labelNode:M,sourceIndex:w}}).filter((x)=>x!==null);if(d.length===0)return;let l=new Map(t.edges.map((x)=>[x.id,x.points?.map((w)=>({...w}))])),u=e(()=>{for(let x of t.edges){let w=l.get(x.id);if(w)x.points=w.map((M)=>({...M}));else delete x.points}},"restoreBaseEdgePoints"),h=e(()=>{u();for(let x of a){let w=c.get(x.id);if(w&&Number.isFinite(w.x)&&Number.isFinite(w.y))x.x=w.x,x.y=w.y;else delete x.x,delete x.y}},"restoreBaseState"),f=d.filter(({edge:x,labelNode:w})=>{if(ht(x.points??[]).segments.length>0)return!0;return Yn(x,w,s),U(o,"degenerateLabelRoutesSkipped"),!1}).sort((x,w)=>x.sourceIndex-w.sourceIndex||W(x.edge.id,w.edge.id));if(f.length===0)return;let p=e(()=>{u();for(let{edge:x,labelNode:w}of f)ai(x,w,s)},"placeLabelsAtRouteMidpoints"),y=i.maxIndexWork??yo,m=Number.isFinite(y)&&y>=0?Math.floor(y):yo,b=new Kr(m,o),g=[];for(let x=1;x<=2;x++){U(o,"labelPasses");let w=jo(t,b,o),M=new Map,S=new Map,E=new Map(t.edges.map((v)=>[v.id,Ot(v,void 0,w).map(be)])),I=new Map;try{for(let{edge:C,labelNode:O}of f){let P=[...$o(C,w)].sort((T,Y)=>{let q=Yt(Y.segment)-Yt(T.segment);if(Math.abs(q)>nt)return q;return T.order-Y.order}),L=null;for(let T of P)if(L=Yo(C,O,T.segment,w),L)break;if(!L){for(let T of P)if(L=qo(C,O,T.segment,w,M),L)break}if(x===2&&!L){for(let T of P)if(L=ri(C,O,T,w,M),L)break}if(x===2&&!L){for(let T of P)if(L=ii(C,O,T,w,M),L)break}if(!L)throw new xo({edgeId:C.id,labelNodeId:O.id,labelWidth:O.width,labelHeight:O.height,pointCount:C.points?.length??0,points:C.points?.map((T)=>({...T}))??[],segments:P.map(({segment:T})=>({orientation:T.orientation,length:Yt(T),a:{...T.a},b:{...T.b}}))});O.x=L.x,O.y=L.y;let N={edgeId:C.id,nodeId:O.id,center:L,rect:le(O,L)};M.set(C.id,N),Ko(w,N)}let v=[...M.values()];if(U(o,"frozenReservations",v.length),r)r.labelOverlayBuilds++,r.labelOverlayVertices+=v.length*4;for(let C of t.edges){let O=E.get(C.id)??[],P=Ot(C,void 0,w);if(JSON.stringify(P)!==JSON.stringify(O))I.set(C.id,P.map(be));Ht(w,C,O.map(be))}for(let[C,O]of I){if(!M.has(C))continue;let P=w.edgeById.get(C);if(P)Ht(w,P,O)}let R=new Set(I.keys());for(let C of t.edges){let O=M.get(C.id),P=Ot(C,void 0,w);for(let L of v)if(L.edgeId!==C.id&&It(P,L.rect))R.add(C.id);if(O&&!te(C.id,P,M))R.add(C.id)}let A=new Map;for(let C of t.edges){if(!R.has(C.id))continue;let O=Ot(C,void 0,w),P=new Map([[C.id,O]]),L=v.filter((N)=>N.edgeId!==C.id&&It(O,N.rect));if(L.length>0){let N=L.slice(1).reduce((it,k)=>({cx:(Math.min(it.left,k.rect.left)+Math.max(it.right,k.rect.right))/2,cy:(Math.min(it.top,k.rect.top)+Math.max(it.bottom,k.rect.bottom))/2,left:Math.min(it.left,k.rect.left),right:Math.max(it.right,k.rect.right),top:Math.min(it.top,k.rect.top),bottom:Math.max(it.bottom,k.rect.bottom)}),{...L[0].rect}),T=ei(O,N,L),Y=T?A.get(T.key)??0:0,q=(Y+2)*12,D={cx:N.cx,cy:N.cy,left:N.left-q,right:N.right+q,top:N.top-q,bottom:N.bottom+q},Q=he(C,D,w,M,P,T??void 0),Ct=Q!==null;if(Q??=oi(C,L,w,M,P),Q){if(O=Q,P.set(C.id,O),T&&Ct)A.set(T.key,Y+1)}else{U(o,"labelOverlapFallbacks");for(let it of L){if(!It(O,it.rect))continue;let k=S.get(it.edgeId)??new Set;if(!k.has(C.id))U(o,"labelOverlapReservations");k.add(C.id),S.set(it.edgeId,k)}}}if(!te(C.id,O,M))throw V("GRID_ROUTE_NOT_FOUND",`Label anchor was lost for edge "${C.id}"`,{edgeId:C.id,pass:x});if(M.has(C.id))U(o,"preservedAnchors");Ht(w,C,O),U(o,"impactedEdgeReroutes")}for(let{edge:C,labelNode:O}of f){let P=M.get(C.id);if(!P||!te(C.id,Ot(C,void 0,w),M)||!ue(P.rect,C,O.id,w,void 0,S.get(C.id)))throw V("GRID_ROUTE_NOT_FOUND",`Label pass ${x} did not validate`,{edgeId:C.id,pass:x})}return}catch(v){if(v instanceof Go){if(p(),U(o,"indexWorkLimitFallbacks"),r)r.resourceLimitFallbacks++,r.fallbackReasons.label_index_work_cap++;return}if(!(v instanceof xo))throw h(),U(o,"rollbacks"),v;g.push(v),u();for(let{labelNode:R}of f)delete R.x,delete R.y}}if(p(),U(o,"placementSearchFallbacks"),r)r.fallbackReasons.label_placement_exhausted++;n.warn("[grid]","Label placement search exhausted; using route midpoints. Labels may overlap.",{reason:"label_placement_exhausted",edgeIds:f.map(({edge:x})=>x.id),failures:g.map(({details:x})=>x)})}e(ui,"positionGridEdgeLabels");function Pe(t){return t.isGroup?t:void 0}e(Pe,"asGroup");function hi(t){let o=new Map,r=new Map,i=new Set;for(let u of t){if(u.id===X)throw V("GRID_INVALID_CONTAINMENT",`Node id "${X}" is reserved for the grid layout root`,{traversedIds:[u.id]});if(o.has(u.id))throw V("GRID_INVALID_CONTAINMENT",`Duplicate node id "${u.id}"`,{traversedIds:[u.id]});if(o.set(u.id,u),xt(u)){i.add(u.id);continue}let h=Pe(u);if(h)r.set(h.id,h)}let s=new Map;s.set(X,[]);for(let u of t){if(i.has(u.id))continue;let h=u.parentId??X;if(h!==X){if(!r.get(h))throw V("GRID_INVALID_CONTAINMENT",`Missing parent "${h}" for "${u.id}"`,{traversedIds:[u.id,h]})}if(!s.has(h))s.set(h,[]);s.get(h).push(u)}let a=new Map,c=[],d=e((u)=>(s.get(u)??[]).map((h)=>Pe(h)).filter((h)=>h!==void 0),"directChildGroups"),l=e((u)=>{let h=a.get(u)??0;if(h===1)throw V("GRID_INVALID_CONTAINMENT",`Containment cycle at "${u}"`,{traversedIds:[u]});if(h===2)return;a.set(u,1);let f=[{groupId:u,childGroups:d(u),nextChildIndex:0}];while(f.length>0){let p=f[f.length-1],y=p.childGroups[p.nextChildIndex];if(y){p.nextChildIndex+=1;let b=a.get(y.id)??0;if(b===1)throw V("GRID_INVALID_CONTAINMENT",`Containment cycle at "${y.id}"`,{traversedIds:[...f.map((g)=>g.groupId),y.id]});if(b===2)continue;a.set(y.id,1),f.push({groupId:y.id,childGroups:d(y.id),nextChildIndex:0});continue}f.pop(),a.set(p.groupId,2);let m=r.get(p.groupId);if(m)c.push(m)}},"visit");for(let u of s.get(X)??[]){let h=Pe(u);if(h)l(h.id)}for(let u of r.keys())if((a.get(u)??0)===0)l(u);return{nodeById:o,groupById:r,childrenByParent:s,rootChildren:s.get(X)??[],postOrderGroups:c,helperNodeIds:i}}e(hi,"buildGridForest");function Kt(t,o,r){let i=o,s=new Set;while(i?.parentId){if(i.parentId===t)return!0;if(s.has(i.parentId))return!1;s.add(i.parentId),i=r.get(i.parentId)}return!1}e(Kt,"isAncestorGroup");function fi(t,o,r){let i=new Map,s=new Map;for(let a of t.edges){if(!a.start||!a.end||!a.labelNodeId)continue;if(r)r.labelSpacingEdgesExamined++;let c=o.nodeById.get(a.labelNodeId),d=o.nodeById.get(a.start),l=o.nodeById.get(a.end);if(!c||!d||!l)continue;if(a.start===a.end){let p=Tn(c,"H");if(p)s.set(a.id,p);continue}let u=d.parentId??X,h=l.parentId??X;if(u!==h)continue;let f=i.get(u);if(f)f.push({edge:a,labelNode:c});else i.set(u,[{edge:a,labelNode:c}])}return{byContainer:i,selfLoops:s}}e(fi,"buildGridLabelRequirements");function pi(t,o,r){let i=new Map,s=0;for(let a of t)i.set(a,s),s+=(o.get(a)??0)+r;return i}e(pi,"trackOrigins");function cn(t,o,r,i,s){let a=pi(r,i,s),c=a.get(t),d=i.get(t);if(c===void 0||d===void 0)return!1;let l=c+d/2,u=l-o/2,h=l+o/2;return r.every((f)=>{if(f===t)return!0;let p=a.get(f),y=p+(i.get(f)??0);return h<=p||u>=y})}e(cn,"crossAxisFits");function gi(t){let o=new Map;for(let r of t.values())for(let i of r.items)o.set(i.item.id,i);return o}e(gi,"placementByNodeId");function dn(t,o,r){let i=Math.min(t,o),s=Math.max(t,o),a=r.indexOf(i);return a>=0&&r[a+1]===s}e(dn,"areConsecutive");function ln(t,o,r){t.set(o,Math.max(t.get(o)??0,r))}e(ln,"addGapRequirement");function mi(t,o,r,i,s,a,c,d,l){let u=new Map,h=new Map,f=gi(o),p=e((y,m)=>Tn(y.labelNode,m),"requirementFor");for(let y of t){let m=y.edge.start?f.get(y.edge.start):void 0,b=y.edge.end?f.get(y.edge.end):void 0;if(!m||!b)continue;if(m.row===b.row&&dn(m.column,b.column,a)){let g=p(y,"H");if(g&&cn(m.row,g.cross,s,r,c)){if(l)l.labelSpacingEligibleEdges++;ln(h,Math.min(m.column,b.column),g.requiredAlongSpan)}continue}if(m.column===b.column&&dn(m.row,b.row,s)){let g=p(y,"V");if(g&&cn(m.column,g.cross,a,i,d)){if(l)l.labelSpacingEligibleEdges++;ln(u,Math.min(m.row,b.row),g.requiredAlongSpan)}}}return{rowGapAfter:u,columnGapAfter:h}}e(mi,"deriveGridContainerLabelGaps");var un="[grid]",Xr=new Set(["basis","bumpX","bumpY","cardinal","catmullRom","linear","monotoneX","monotoneY","natural","step","stepAfter","stepBefore","rounded"]);function Ge(t){return t!==null&&typeof t==="object"&&!Array.isArray(t)}e(Ge,"isObjectRecord");function qn(t){if(!Ge(t))return{};let o={};if(Object.hasOwn(t,"row"))o.row=t.row;if(Object.hasOwn(t,"column"))o.column=t.column;if(Ea(t.horizontalAlign))o.horizontalAlign=t.horizontalAlign;if(Aa(t.verticalAlign))o.verticalAlign=t.verticalAlign;return o}e(qn,"ownPlacementFrom");function yi(t){let o=new Map,r=0;for(let i of t)if(!o.has(i.id))o.set(i.id,r++);return o}e(yi,"buildGridSourceOrder");function xi(t){let o=Ge(t.config?.grid)?t.config.grid:{},r=Ge(o.placements)?o.placements:{},i=new Map;for(let s of Object.keys(r)){let a=r[s],c=Array.isArray(a)?a:[a];i.set(s,c.map((d)=>qn(d)))}return{placements:i,columns:typeof o.columns==="number"&&Number.isFinite(o.columns)&&o.columns>=0?Math.trunc(o.columns):vt.columns,rowGap:typeof o.rowGap==="number"&&Number.isFinite(o.rowGap)&&o.rowGap>=0?o.rowGap:vt.rowGap,columnGap:typeof o.columnGap==="number"&&Number.isFinite(o.columnGap)&&o.columnGap>=0?o.columnGap:vt.columnGap,cellGap:typeof o.cellGap==="number"&&Number.isFinite(o.cellGap)&&o.cellGap>=0?o.cellGap:vt.cellGap,containerPadding:typeof o.containerPadding==="number"&&Number.isFinite(o.containerPadding)&&o.containerPadding>=0?o.containerPadding:vt.containerPadding,titleGap:typeof o.titleGap==="number"&&Number.isFinite(o.titleGap)&&o.titleGap>=0?o.titleGap:vt.titleGap,horizontalAlign:Ea(o.horizontalAlign)?o.horizontalAlign:vt.horizontalAlign,verticalAlign:Aa(o.verticalAlign)?o.verticalAlign:vt.verticalAlign,curve:typeof o.curve==="string"&&Xr.has(o.curve)?o.curve:vt.curve,edgeCornerRadius:Qr(o.edgeCornerRadius)}}e(xi,"readGridConfig");function bi(t,o){let r=new Map;for(let i of t){let s=i.placementId??i.id;r.set(s,(r.get(s)??0)+1)}for(let[i,s]of o.placements){let a=r.get(i)??0;if(a===0){n.warn(un,`Ignoring grid placement for unknown target "${i}"`);continue}if(s.length>a)n.warn(un,`Ignoring ${s.length-a} extra grid placement occurrence(s) for target "${i}"; found ${a} matching node(s)`)}}e(bi,"validateGridPlacementMap");function wi(t){return(o,r)=>{let i=t.get(o.id)??Number.MAX_SAFE_INTEGER,s=t.get(r.id)??Number.MAX_SAFE_INTEGER;if(i!==s)return i-s;return W(o.id,r.id)}}e(wi,"itemComparator");function vi(t,o,r,i){let s=t.placementId??t.id,a=r.placements.get(s)?.[i]??{},c=qn(t.metadata);for(let u of["row","column","horizontalAlign","verticalAlign"])if(Object.hasOwn(a,u)&&Object.hasOwn(c,u)&&a[u]!==c[u])n.debug(un,"metadata overrides placement map",{nodeId:t.id,field:u,metadata:c[u],config:a[u]});let d=Object.hasOwn(c,"row")?c.row:a.row,l=Object.hasOwn(c,"column")?c.column:a.column;return Lr(s,"row",d,t.id),Lr(s,"column",l,t.id),{item:t,row:d??0,column:l??0,horizontalAlign:c.horizontalAlign??a.horizontalAlign??r.horizontalAlign,verticalAlign:c.verticalAlign??a.verticalAlign??r.verticalAlign,sourceOrder:o.get(t.id)??Number.MAX_SAFE_INTEGER,explicitRow:d!==void 0,explicitColumn:l!==void 0,explicitCell:d!==void 0&&l!==void 0}}e(vi,"resolveItemPlacement");function Ii(t,o,r){let i=r;while(o.has(`${t}:${i}`))i++;return i}e(Ii,"nextFreeColumn");function Mi(t,o,r){let i=r;while(o.has(`${i}:${t}`))i++;return i}e(Mi,"nextFreeRow");function Ci(t,o,r){let i=r;for(;;){let s=Math.floor(i/o)+1,a=i%o+1;if(i++,!t.has(`${s}:${a}`))return{row:s,column:a,nextIndex:i}}}e(Ci,"nextAutoCell");function Si(t,o,r){let i=[...t].sort(wi(o)),s=new Map,a=i.map((p)=>{let y=p.placementId??p.id,m=s.get(y)??0;return s.set(y,m+1),vi(p,o,r,m)}),c=new Map,d=new Set;for(let p of a){if(!p.explicitCell)continue;let y=`${p.row}:${p.column}`;d.add(y);let m=c.get(y);if(m){if(m.verticalAlign!==p.verticalAlign)throw V("GRID_CELL_ALIGNMENT_CONFLICT",`Conflicting vertical alignment in cell (${p.row}, ${p.column})`,{containerId:p.item.parentId??"root",row:p.row,column:p.column,itemIds:[...m.items.map((b)=>b.item.id),p.item.id],values:[...m.items.map((b)=>b.verticalAlign),p.verticalAlign]});m.items.push(p)}else c.set(y,{row:p.row,column:p.column,items:[p],width:0,height:0,verticalAlign:p.verticalAlign})}let l=r.columns>0?r.columns:Math.max(1,Math.ceil(Math.sqrt(i.length))),u=0,h=new Map,f=new Map;for(let p of a){if(p.explicitCell)continue;if(p.explicitRow){let m=Ii(p.row,d,h.get(p.row)??1);p.column=m,h.set(p.row,m+1)}else if(p.explicitColumn){let m=Mi(p.column,d,f.get(p.column)??1);p.row=m,f.set(p.column,m+1)}else{let m=Ci(d,l,u);p.row=m.row,p.column=m.column,u=m.nextIndex}let y=`${p.row}:${p.column}`;d.add(y),c.set(y,{row:p.row,column:p.column,items:[p],width:0,height:0,verticalAlign:p.verticalAlign})}return{placements:a,cells:c}}e(Si,"resolveGridPlacements");var Tt=class extends Error{constructor(t,o,r){super(o);this.reason=t,this.searchStateScope=r,this.name="GridRoutingResourceLimitError"}static{e(this,"GridRoutingResourceLimitError")}},K=6,ee=24,Wr=50000,Yr=4,jt=67108864,qr=class{constructor(t,o){this.bands=t,this.strictBoundaryIntervals=o,this.byLow=new Map,this.byHigh=new Map,this.coordinateCount=new Set(t.flatMap(({low:i,high:s})=>[i,s])).size;let r=t.reduce((i,s)=>i+s.intervals.length,0);for(let i of o.values())r+=i.length;this.intervalCount=r;for(let i of t)this.byLow.set(i.low,i),this.byHigh.set(i.high,i);Object.freeze(this.bands),Object.freeze(this)}static{e(this,"CompressedIntervalIndex")}containingBand(t){let o=0,r=this.bands.length-1;while(o<=r){let i=o+r>>>1,s=this.bands[i];if(t<=s.low)r=i-1;else if(t>=s.high)o=i+1;else return s}return}overlaps(t,o,r){let i=0,s=t.length;while(i<s){let a=i+s>>>1;if(t[a][1]<=o)i=a+1;else s=a}return i<t.length&&t[i][0]<r}intersects(t,o,r){let i=Math.min(o,r),s=Math.max(o,r),a=this.byHigh.get(t),c=this.byLow.get(t),d=a||c?void 0:this.containingBand(t);if(d)return this.overlaps(d.intervals,i,s);if(!a||!c)return!1;let l=0,u=0;while(l<a.intervals.length&&u<c.intervals.length){let h=Math.max(i,a.intervals[l][0],c.intervals[u][0]),f=Math.min(s,a.intervals[l][1],c.intervals[u][1]);if(h<f)return!0;if(a.intervals[l][1]<c.intervals[u][1])l++;else u++}return!1}contains(t,o){let r=this.strictBoundaryIntervals.get(t)??this.containingBand(t)?.intervals;if(!r)return!1;let i=0,s=r.length;while(i<s){let a=i+s>>>1;if(r[a][0]<o)i=a+1;else s=a}return i>0&&o<r[i-1][1]}nearestBoundary(t,o,r){let i=this.strictBoundaryIntervals.get(t)??this.containingBand(t)?.intervals;if(!i)return;if(r<0){let c=0,d=i.length;while(c<d){let l=c+d>>>1;if(i[l][1]<=o)c=l+1;else d=l}return c>0?i[c-1][1]:void 0}let s=0,a=i.length;while(s<a){let c=s+a>>>1;if(i[c][0]<o)s=c+1;else a=c}return s<i.length?i[s][0]:void 0}},bo,We=class{constructor(t){this.backing=t,this[bo]="ImmutableMap",Object.freeze(this)}static{e(this,"ImmutableMap")}get size(){return this.backing.size}entries(){return this.backing.entries()}forEach(t,o){for(let[r,i]of this.backing)t.call(o,i,r,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()}[(bo=Symbol.toStringTag,Symbol.iterator)](){return this.entries()}},wo,vo=class{constructor(t,o){this.base=t,this.overrides=o,this[wo]="OverlayMap"}static{e(this,"OverlayMap")}get size(){let t=0;for(let o of this.overrides.keys())if(!this.base.has(o))t++;return this.base.size+t}materialize(){return new Map([...this.base,...this.overrides])}entries(){return this.materialize().entries()}forEach(t,o){for(let[r,i]of this)t.call(o,i,r,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()}[(wo=Symbol.toStringTag,Symbol.iterator)](){return this.entries()}};function Ei(t,o){return new Proxy([],{get(r,i){if(i==="length")return t.length+o.length;if(i===Symbol.iterator)return function*(){yield*t,yield*o};if(typeof i==="string"&&/^\d+$/.test(i)){let s=Number(i);return s<t.length?t[s]:o[s-t.length]}return Reflect.get(Array.prototype,i)}})}e(Ei,"overlayArray");function hn(t,o,r){return new Proxy([],{get(i,s){if(s==="length")return r;if(s===Symbol.iterator)return function*(){for(let a=0;a<r;a++)yield o.get(a)??t[a]};if(typeof s==="string"&&/^\d+$/.test(s)){let a=Number(s);return o.get(a)??t[a]}return Reflect.get(Array.prototype,s)}})}e(hn,"overrideArray");var Ri=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{e(this,"EndpointOverlayScratch")}reset(t){if(t!==this.base)throw Error("Endpoint overlay scratch cannot be shared across base topologies");for(let o of this.undoLog)this.adjacencyOverrides.delete(o),this.searchAdjacencyOverrides.delete(o);this.undoLog.length=0,this.addedVertices.length=0,this.pointOverrides.clear(),this.resetCount++}setArcs(t,o){if(!this.adjacencyOverrides.has(t))this.undoLog.push(t);this.adjacencyOverrides.set(t,o),this.searchAdjacencyOverrides.set(t,Jn(o))}};function Dt(t){return Object.is(t,-0)?0:t}e(Dt,"normalizeCoordinate");function Ie(t){if(![t.left,t.right,t.top,t.bottom].every(Number.isFinite))throw Error("Grid routing geometry must contain only finite coordinates");let r=Dt(Math.min(t.left,t.right)),i=Dt(Math.max(t.left,t.right)),s=Dt(Math.min(t.top,t.bottom)),a=Dt(Math.max(t.top,t.bottom));if(r===i||s===a)throw Error("Grid routing rectangles must have positive area");return{left:r,right:i,top:s,bottom:a}}e(Ie,"normalizeRect");function Ai(t,o){let r=Ie(t.bounds),i={id:t.id,left:Math.max(o.left,r.left-K),right:Math.min(o.right,r.right+K),top:Math.max(o.top,r.top-K),bottom:Math.min(o.bottom,r.bottom+K)};return i.left<i.right&&i.top<i.bottom?i:void 0}e(Ai,"inflateAndClip");function Qn(t){let o=[...t].sort((i,s)=>i.low-s.low||i.high-s.high||W(i.id,s.id)),r=[];for(let i of o){let s=r.at(-1);if(!s||i.low>s.high){r.push({...i});continue}if(s.high=Math.max(s.high,i.high),W(i.id,s.id)<0)s.id=i.id}return r}e(Qn,"mergeObstacleIntervals");function Oi(t){let o=new Map;for(let c of t){let d=o.get(c.left)??{starts:[],ends:[]};d.starts.push(c),o.set(c.left,d);let l=o.get(c.right)??{starts:[],ends:[]};l.ends.push(c),o.set(c.right,l)}let r=[...o.keys()].sort((c,d)=>c-d),i=new Set,s=[],a=new Map;for(let c=0;c<r.length-1;c++){let d=r[c],l=r[c+1],u=o.get(d);for(let f of u.ends)i.delete(f);for(let f of u.starts)i.add(f);let h=new Map;for(let f of Qn([...i].map((p)=>({low:p.top,high:p.bottom,id:p.id})))){let p=`${f.low}:${f.high}`,y=a.get(p);if(y){if(y.right=l,W(f.id,y.id)<0)y.id=f.id}else{let m={id:f.id,left:d,right:l,top:f.low,bottom:f.high};s.push(m),h.set(p,m);continue}h.set(p,y)}a=h}return s.sort((c,d)=>c.top-d.top||c.left-d.left||c.bottom-d.bottom||c.right-d.right||W(c.id,d.id))}e(Oi,"unionObstacles");function yt(t){return`${Dt(t.x)}:${Dt(t.y)}`}e(yt,"routingPointKey");function Me(t){return t==="left"?0:t==="right"?1:t==="top"?2:t==="bottom"?3:4}e(Me,"topologySideOrdinal");function Ye(t,o){return W(t.kind,o.kind)||Me(t.side)-Me(o.side)||t.point.x-o.point.x||t.point.y-o.point.y||W(t.ownerId??"",o.ownerId??"")}e(Ye,"vertexRecordOrder");function qe(t){let o=new Map;for(let r of[...t].sort(Ye)){let i={...r,point:{x:Dt(r.point.x),y:Dt(r.point.y)}},s=yt(i.point);if(!o.has(s))o.set(s,i)}return[...o.values()]}e(qe,"canonicalRecords");function fn(t,o,r="corner"){return[{point:{x:t.left,y:t.top},kind:r,ownerId:o},{point:{x:t.right,y:t.top},kind:r,ownerId:o},{point:{x:t.left,y:t.bottom},kind:r,ownerId:o},{point:{x:t.right,y:t.bottom},kind:r,ownerId:o}]}e(fn,"cornerRecords");function Bi(t,o){let r=t.coordinate??(t.side==="left"?o.left:t.side==="right"?o.right:t.side==="top"?o.top:o.bottom);return(t.side==="left"||t.side==="right"?[{x:r,y:t.low},{x:r,y:t.high}]:[{x:t.low,y:r},{x:t.high,y:r}]).map((s)=>({point:s,kind:"portal",ownerId:t.ownerId,side:t.side}))}e(Bi,"portalRecords");function Zn(t,o,r,i,s){if(o==="left"||o==="right")return{x:i.nearestBoundary(t.y,t.x,o==="left"?-1:1)??(o==="left"?r.left:r.right),y:t.y};let a=s.nearestBoundary(t.x,t.y,o==="top"?-1:1)??(o==="top"?r.top:r.bottom);return{x:t.x,y:a}}e(Zn,"rayHit");function pn(t,o,r){let i=[...new Set(t.flatMap((f)=>o==="H"?[f.top,f.bottom]:[f.left,f.right]))].sort((f,p)=>f-p),s=[],a=new Map,c=new Map,d=new Map;for(let f of t){let p=o==="H"?f.top:f.left,y=o==="H"?f.bottom:f.right,m=c.get(p)??[];m.push(f),c.set(p,m);let b=d.get(y)??[];b.push(f),d.set(y,b)}let l=new Set,u=e(()=>Qn([...l].map((f)=>o==="H"?{low:f.left,high:f.right,id:f.id}:{low:f.top,high:f.bottom,id:f.id})),"activeIntervals"),h=e((f)=>{let p=r.intervalCount+f.length;return Ut(Te(0,0,t.length,p),r.maxEstimatedBytes,"estimated_memory_cap"),r.intervalCount=p,Object.freeze(f.map((y)=>Object.freeze([y.low,y.high])))},"freezeIntervals");for(let f=0;f<i.length;f++){let p=i[f];for(let b of d.get(p)??[])l.delete(b);a.set(p,h(u()));for(let b of c.get(p)??[])l.add(b);let y=i[f+1];if(y===void 0)continue;let m=u();if(m.length>0)s.push({low:p,high:y,intervals:h(m)})}return new qr(Object.freeze(s),new We(a))}e(pn,"createIntervalIndex");function Te(t,o,r,i){return t*64+o*56+r*48+i*24}e(Te,"estimatedTopologyBytes");function Ut(t,o,r){if(t>o)throw new Tt(r,`Grid routing ${r} exceeded: ${t} > ${o}`)}e(Ut,"enforceCap");function gn(t,o){let r=new Map;for(let i of t){let s=o==="H"?i.point.y:i.point.x,a=r.get(s)??[];a.push(i),r.set(s,a)}for(let i of r.values())i.sort((s,a)=>o==="H"?s.point.x-a.point.x||s.id-a.id:s.point.y-a.point.y||s.id-a.id),Object.freeze(i);return new We(r)}e(gn,"indexVertexLines");function Jn(t){return Object.freeze(t.map((o)=>Object.freeze({to:o.to,orientationOrdinal:o.orientation==="H"?1:2,length:o.length,boundaryTransitions:o.kind==="portal"?1:0})))}e(Jn,"searchArcs");function Li(t,o,r,i){let s=qe(t).sort(Ye),a=i.maxVertices??Wr;Ut(s.length,a,"vertex_cap");let c=s.map((p,y)=>Object.freeze({id:y,...p,point:Object.freeze({...p.point})})),d=new Map(c.map((p)=>[p.id,[]])),l=e((p,y,m)=>{let b=Math.abs(p.point.x-y.point.x)+Math.abs(p.point.y-y.point.y);if(b===0)return;let g=m==="H"?Math.min(p.point.x,y.point.x):Math.min(p.point.y,y.point.y),x=g+b;for(let[w,M]of[[p,y],[y,p]])d.get(w.id).push({from:w.id,to:M.id,orientation:m,length:b,kind:"visibility",intervalStart:g,intervalEnd:x})},"addArcPair");for(let p of["H","V"]){let y=new Map;for(let m of c){let b=p==="H"?m.point.y:m.point.x,g=y.get(b)??[];g.push(m),y.set(b,g)}for(let[m,b]of y){b.sort((g,x)=>p==="H"?g.point.x-x.point.x||g.id-x.id:g.point.y-x.point.y||g.id-x.id);for(let g=1;g<b.length;g++){let x=b[g-1],w=b[g],M=p==="H"?x.point.x:x.point.y,S=p==="H"?w.point.x:w.point.y;if(!(p==="H"?o:r).intersects(m,M,S))l(x,w,p)}}}let u={visibility:0,terminal:1,portal:2,lane:3},h=0,f=new Map;for(let p of c){let y=d.get(p.id);y.sort((b,g)=>u[b.kind]-u[g.kind]||W(b.orientation,g.orientation)||c[b.to].point.x-c[g.to].point.x||c[b.to].point.y-c[g.to].point.y||b.to-g.to);let m=y.filter((b,g)=>g===0||b.to!==y[g-1].to||b.orientation!==y[g-1].orientation||b.kind!==y[g-1].kind);h+=m.length,f.set(p.id,Object.freeze(m.map((b)=>Object.freeze(b))))}return Ut(h,i.maxAdjacencyEntries??a*Yr,"adjacency_cap"),{vertices:Object.freeze(c),adjacency:new We(f),adjacencyEntries:h}}e(Li,"buildVisibilityGraph");function se(t,o,r){let i=Ie(o),s=r?Ie(r):void 0,a=Math.max(i.top+K,(s?.bottom??-1/0)+K),c=i.bottom-K,d=i.left+K,l=i.right-K,u=[];if(a<=c)u.push({ownerId:t,side:"left",low:a,high:c},{ownerId:t,side:"right",low:a,high:c});if(d<=l){if(u.push({ownerId:t,side:"bottom",low:d,high:l}),!s||s.bottom+K<=i.top)u.push({ownerId:t,side:"top",low:d,high:l})}return u}e(se,"derivePortalRanges");function mn(t,o,r,i,s){let a=se(t,o,r).find((f)=>f.side===i);if(!a||s<a.low||s>a.high)throw Error(`Illegal ${i} portal for "${t}" at ${s}`);let c=i==="left"?o.left:i==="right"?o.right:i==="top"?o.top:o.bottom,d=i==="left"||i==="top"?c+K:c-K,l=i==="left"||i==="top"?c-K:c+K,u=i==="left"||i==="right"?{x:d,y:s}:{x:s,y:d},h=i==="left"||i==="right"?{x:l,y:s}:{x:s,y:l};return{ownerId:t,side:i,tangentialCoordinate:s,interior:u,exterior:h,transition:{from:u,to:h,orientation:i==="left"||i==="right"?"H":"V",length:K*2,kind:"portal"}}}e(mn,"buildPairedPortal");function Pi(t,o={}){let r=Ie(t.bounds),i=[...t.obstacles,...t.titleExclusions??[]].map((g)=>Ai(g,r)).filter((g)=>Boolean(g)),s=Oi(i),a=[...t.portalRanges??[]].sort((g,x)=>Me(g.side)-Me(x.side)||g.low-x.low||g.high-x.high||W(g.ownerId,x.ownerId)),c=qe([...fn(r,t.containerId),...s.flatMap((g)=>fn(g,g.id)),...a.flatMap((g)=>Bi(g,r))]),d={intervalCount:0,maxEstimatedBytes:o.caps?.maxEstimatedBytes??jt};Ut(Te(0,0,s.length,0),d.maxEstimatedBytes,"estimated_memory_cap");let l=pn(s,"H",d),u=pn(s,"V",d),h=[],f=["left","right","top","bottom"];for(let g of c)for(let x of f){let w=Zn(g.point,x,r,l,u);if(w.x!==g.point.x||w.y!==g.point.y)h.push({point:w,kind:"projection",side:x})}let{vertices:p,adjacency:y,adjacencyEntries:m}=Li([...c,...h],l,u,o.caps??{}),b=Te(p.length,m,s.length,l.intervalCount+u.intervalCount);if(Ut(b,o.caps?.maxEstimatedBytes??jt,"estimated_memory_cap"),o.metrics)o.metrics.containersBuilt++,o.metrics.baseTopologyBuilds++,o.metrics.baseVertices+=p.length,o.metrics.baseAdjacencyEntries+=m,o.metrics.buildSweepEvents+=c.length*4+s.length*4,o.metrics.estimatedBytes+=b;return Object.freeze({containerId:t.containerId,bounds:Object.freeze(r),obstacles:Object.freeze(s.map((g)=>Object.freeze(g))),vertices:Object.freeze(p),pointVertexIds:new We(new Map(p.map(({id:g,point:x})=>[yt(x),g]))),horizontalVertexLines:gn(p,"H"),verticalVertexLines:gn(p,"V"),adjacency:y,adjacencyByVertex:Object.freeze(p.map(({id:g})=>y.get(g)??[])),searchAdjacencyByVertex:Object.freeze(p.map(({id:g})=>Jn(y.get(g)??[]))),adjacencyEntries:m,horizontalIntervals:l,verticalIntervals:u,portalRanges:Object.freeze(a.map((g)=>Object.freeze(g))),seedCount:c.length,estimatedBytes:b})}e(Pi,"buildContainerRoutingTopology");function yn(t,o){return o.contains(t.y,t.x)}e(yn,"pointInsideObstacle");function Qe(t,o,r,i,s,a=[]){let c=s??new Ri(t);c.reset(t);let d=[{point:o,kind:"endpoint",ownerId:"source"},{point:r,kind:"endpoint",ownerId:"target"},...a.filter((I)=>!yn(I,t.horizontalIntervals)).map((I)=>({point:I,kind:"lane"}))];for(let I of[{x:o.x,y:r.y},{x:r.x,y:o.y}])if(!yn(I,t.horizontalIntervals))d.push({point:I,kind:"projection"});for(let I of d.slice(0,2))for(let v of["left","right","top","bottom"]){let R=Zn(I.point,v,t.bounds,t.horizontalIntervals,t.verticalIntervals);if(R.x!==I.point.x||R.y!==I.point.y)d.push({point:R,kind:"projection",side:v})}let l=qe(d).filter(({point:I})=>!t.pointVertexIds.has(yt(I))).sort(Ye);Ut(l.length,32,"vertex_cap"),c.addedVertices.push(...l.map((I,v)=>Object.freeze({id:t.vertices.length+v,...I,point:Object.freeze({...I.point})})));let u=Ei(t.vertices,c.addedVertices),h=e((I)=>I<t.vertices.length?t.vertices[I]:c.addedVertices[I-t.vertices.length],"vertexAt"),f=new Map,p=e((I)=>{let v=f.get(I);if(!v)v=[...t.adjacency.get(I)??[]],f.set(I,v);return v},"mutableArcs");for(let I of c.addedVertices)f.set(I.id,[]);let y=new Set(c.addedVertices.map(({id:I})=>I)),m=new Set,b=e((I,v,R)=>{let A=Math.abs(I.point.x-v.point.x)+Math.abs(I.point.y-v.point.y);if(A===0)return;let C=R==="H"?Math.min(I.point.x,v.point.x):Math.min(I.point.y,v.point.y),O=C+A;for(let[P,L]of[[I,v],[v,I]]){let N=`${P.id}:${L.id}:${R}:visibility`;if(m.has(N)||(t.adjacency.get(P.id)??[]).some((T)=>T.to===L.id&&T.orientation===R&&T.kind==="visibility"))continue;m.add(N),p(P.id).push({from:P.id,to:L.id,orientation:R,length:A,kind:"visibility",intervalStart:C,intervalEnd:O})}},"connect");for(let I of["H","V"]){let v=I==="H"?t.horizontalVertexLines:t.verticalVertexLines,R=new Set(c.addedVertices.map(({point:A})=>I==="H"?A.y:A.x));for(let A of R){let C=[...v.get(A)??[],...c.addedVertices.filter(({point:O})=>(I==="H"?O.y:O.x)===A)];C.sort((O,P)=>I==="H"?O.point.x-P.point.x||O.id-P.id:O.point.y-P.point.y||O.id-P.id);for(let O=1;O<C.length;O++){let P=C[O-1],L=C[O];if(!y.has(P.id)&&!y.has(L.id))continue;let N=I==="H"?P.point.x:P.point.y,T=I==="H"?L.point.x:L.point.y;if(!(I==="H"?t.horizontalIntervals:t.verticalIntervals).intersects(A,N,T))b(P,L,I)}}}for(let[I,v]of f){v.sort((A,C)=>W(A.kind,C.kind)||W(A.orientation,C.orientation)||h(A.to).point.x-h(C.to).point.x||h(A.to).point.y-h(C.to).point.y||A.to-C.to);let R=Object.freeze(v.map((A)=>Object.freeze(A)));c.setArcs(I,R)}let g=t.adjacencyEntries+m.size;Ut(g,t.adjacencyEntries+64,"adjacency_cap");let x=l.length,w=t.estimatedBytes+x*64+(g-t.adjacencyEntries)*56;if(i)i.endpointOverlayBuilds++,i.endpointOverlayVertices+=x,i.estimatedBytes=Math.max(i.estimatedBytes,w);let M=t.vertices.length+c.addedVertices.length,S=hn(t.adjacencyByVertex,c.adjacencyOverrides,M),E=hn(t.searchAdjacencyByVertex,c.searchAdjacencyOverrides,M);for(let I of c.addedVertices)c.pointOverrides.set(yt(I.point),I.id);return Object.freeze({...t,vertices:u,pointVertexIds:new vo(t.pointVertexIds,c.pointOverrides),adjacency:new vo(t.adjacency,c.adjacencyOverrides),adjacencyByVertex:S,searchAdjacencyByVertex:E,adjacencyEntries:g,estimatedBytes:w,vertexCount:M,getVertex:h,getSearchArcs:e((I)=>c.searchAdjacencyOverrides.get(I)??t.searchAdjacencyByVertex[I]??[],"getSearchArcs")})}e(Qe,"buildEndpointRoutingOverlay");var Ce=4,Z=20,Ne=8;function Ze(t){return Boolean(t.groupTitleRect)}e(Ze,"ownerGroupTitle");function ae(t,o){return JSON.stringify([t,o])}e(ae,"ownerSideKey");function Je(t,o){let r=z(t),i=o.x-r.cx,s=o.y-r.cy,a=t.isGroup&&Ze(t);if(Math.abs(i)>=Math.abs(s))return i>=0?"right":"left";if(s>=0)return"bottom";if(a)return i>=0?"right":"left";return"top"}e(Je,"preferredSide");function Fe(t,o){let r=[],i=t.parentId??X,s=new Set;while(!0){if(r.push(i),i===X)break;if(s.has(i))break;s.add(i),i=o.get(i)?.parentId??X}return r}e(Fe,"containerChain");function _i(t,o,r){if(t.isGroup&&Kt(t.id,o,r))return t.parentId??X;if(o.isGroup&&Kt(o.id,t,r))return o.parentId??X;let i=new Set(Fe(o,r));for(let s of Fe(t,r))if(i.has(s))return s;return X}e(_i,"commonContainerId");function De(t,o){return o==="left"||o==="right"?t.cy:t.cx}e(De,"oppositeCoordFor");function ce(t,o){return o==="left"||o==="right"?{x:o==="left"?t.left:t.right,y:t.cy}:{x:t.cx,y:o==="top"?t.top:t.bottom}}e(ce,"sideMidpoint");function ke(t,o){return o==="left"||o==="right"?t.y:t.x}e(ke,"tangentialCoordinate");function xn(t,o,r,i,s,a){let c=[],d=z(t),l=z(o),u={x:o.x??0,y:o.y??0},h=t;for(;;){let f=h.parentId??X,p=i.get(f),y={x:h.x??0,y:h.y??0},m=u.x-y.x,b=u.y-y.y,g=b<0&&Math.abs(m)<=rt&&Boolean((h.isGroup?h.groupTitleRect:void 0)??p?.groupTitleRect),x=[];if(Math.abs(Math.abs(m)-Math.abs(b))<=rt&&Math.abs(m)>rt)x.push(m>=0?"right":"left",b>=0?"bottom":"top");let w=Boolean((h.isGroup?h.groupTitleRect:void 0)??p?.groupTitleRect),M=(g?["left","right"]:x).filter((E)=>E!=="top"||!w),S=Je(h,u);if(S==="top"&&p?.groupTitleRect)S=m>=0?"right":"left";if(c.push({ownerId:h.id,side:S,demandKey:JSON.stringify([s,a,h.id,S]),oppositeCoord:De(l,S),preferredCoord:De(d,S),compactPortal:h.id!==t.id,ambiguousSides:M.length>1?M:void 0,inner:c.length?{demandKey:c[c.length-1].demandKey,side:c[c.length-1].side}:void 0}),h.isGroup&&h.id===r&&Kt(h.id,o,i))return{chain:c,finalKind:"boundary"};if(f===r)return{chain:c,finalKind:"item"};if(!p?.isGroup)throw V("GRID_INVALID_CONTAINMENT",`Missing parent group "${f}"`,{traversedIds:c.map((E)=>E.ownerId)});h=p}}e(xn,"buildEndpointPlan");function Gi(t){let o=new Map;for(let i of t){if(!i.start||!i.end)continue;let s=i.start<i.end?`${i.start}|${i.end}`:`${i.end}|${i.start}`;if(!o.has(s))o.set(s,[]);o.get(s).push(i)}let r=new Map;for(let[i,s]of o)s.sort((a,c)=>W(`${a.start}|${a.end}`,`${c.start}|${c.end}`)||W(a.id,c.id)),s.forEach((a,c)=>r.set(a.id,{index:c,size:s.length,offset:(c-(s.length-1)/2)*Ne,pairKey:i}));return r}e(Gi,"buildPairLanes");function Ti(t,o){let r=new Map,i=e((c,d)=>ae(c,d),"reservationKey");for(let c of t)for(let d of[...c.source.chain,...c.target.chain])if(!d.ambiguousSides){let l=i(d.ownerId,d.side);r.set(l,(r.get(l)??0)+1)}let s=e((c,d,l)=>{let u=d.chain.filter(({ambiguousSides:p})=>p);if(u.length===0)return;let f=["right","bottom","left","top"].filter((p)=>u.every((y)=>y.ambiguousSides?.includes(p))&&u.every((y)=>{let m=o.forest.nodeById.get(y.ownerId);return m!==void 0&&Lt(m,p)!==void 0})).sort((p,y)=>u.reduce((m,b)=>m+(r.get(i(b.ownerId,p))??0),0)-u.reduce((m,b)=>m+(r.get(i(b.ownerId,y))??0),0)||Number(p!==u[0].side)-Number(y!==u[0].side))[0];if(!f)return;for(let p of u){p.side=f;let y=i(p.ownerId,f);r.set(y,(r.get(y)??0)+1);let m=o.forest.nodeById.get(p.ownerId);if(m)p.preferredCoord=De(z(m),f)}for(let[p,y]of d.chain.entries())y.demandKey=JSON.stringify([c.edge.id,l,y.ownerId,y.side]),y.inner=p>0?{demandKey:d.chain[p-1].demandKey,side:d.chain[p-1].side}:void 0},"resolveEndpoint"),a=t.flatMap((c)=>[{plan:c,endpoint:c.source,role:"source"},{plan:c,endpoint:c.target,role:"target"}]).sort((c,d)=>W(`${c.plan.edge.start??""}|${c.plan.edge.end??""}|${c.plan.edge.id}|${c.role}`,`${d.plan.edge.start??""}|${d.plan.edge.end??""}|${d.plan.edge.id}|${d.role}`));for(let{plan:c,endpoint:d,role:l}of a)s(c,d,l);for(let c of t){let d=c.source.chain.at(-1),l=c.target.chain.at(-1),u=d?o.forest.nodeById.get(d.ownerId):void 0,h=l?o.forest.nodeById.get(l.ownerId):void 0;if(!d||!l||!u||!h)continue;let f=ce(z(u),d.side),p=ce(z(h),l.side);for(let y of c.source.chain)y.oppositeCoord=ke(p,y.side);for(let y of c.target.chain)y.oppositeCoord=ke(f,y.side)}}e(Ti,"resolveAmbiguousEndpointSides");function Ni(t,o){let r=o.forest.nodeById,i=Gi(t.edges),s=t.edges.map((a)=>{let c=a.start?r.get(a.start):void 0,d=a.end?r.get(a.end):void 0;if(!c||!d)throw V("GRID_MISSING_ENDPOINT",`Missing endpoint for edge "${a.id}"`,{edgeId:a.id,start:a.start,end:a.end});let l=_i(c,d,r),u=i.get(a.id)??{index:0,size:1,offset:0,pairKey:_t(a)};return{edge:a,lcaContainerId:l,source:xn(c,d,l,r,a.id,"source"),target:xn(d,c,l,r,a.id,"target"),laneIndex:u.index,laneOffset:u.offset,bundleSize:u.size,pairKey:u.pairKey}});return Ti(s,o),s}e(Ni,"collectRoutePlans");function to(t,o,r){let i=[];for(let[u,h]of t.entries())i.push(u===0?h:Math.max(h,i[u-1]+Ce));for(let u=i.length-1;u>=0;u--)i[u]=Math.min(i[u],u===i.length-1?r:i[u+1]-Ce);let s=t.reduce((u,h)=>u+h,0)/t.length,a=i.reduce((u,h)=>u+h,0)/i.length,c=o-i[0],d=r-i[i.length-1],l=Gt(s-a,c,d);return i.map((u)=>u+l)}e(to,"assignCompactPortalCoordinates");function Fi(t,o,r){let i=o.forest.nodeById,s=new Map(t.map((h)=>[h.edge.id,h])),a=new Map;for(let h of t){if(h.edge.start===h.edge.end)continue;for(let f of[...h.source.chain,...h.target.chain])if(!a.has(f.demandKey))a.set(f.demandKey,{ownerId:f.ownerId,side:f.side,edgeId:h.edge.id,demandKey:f.demandKey,oppositeCoord:f.oppositeCoord,preferredCoord:f.preferredCoord,compactPortal:f.compactPortal,inner:f.inner})}let c=new Map;for(let h of a.values()){let f=ae(h.ownerId,h.side),p=c.get(f)??{ownerId:h.ownerId,side:h.side,demands:[]};p.demands.push(h),c.set(f,p)}let d=e((h)=>{let f=i.get(h);return f?Fe(f,i).length:0},"depthOf"),l=[...c.values()].sort((h,f)=>Number(h.demands.every((p)=>p.compactPortal))-Number(f.demands.every((p)=>p.compactPortal))||d(f.ownerId)-d(h.ownerId)),u=new Map;for(let{ownerId:h,side:f,demands:p}of l){let y=i.get(h);if(!y)continue;let m=z(y),b=f==="left"||f==="right"?m.top+K:m.left+K,g=f==="left"||f==="right"?m.bottom-K:m.right-K;if((f==="left"||f==="right")&&y.groupTitleRect)b=Math.max(b,y.groupTitleRect.bottom+K);let x=Math.max(0,g-b);p.sort((I,v)=>I.oppositeCoord-v.oppositeCoord||W(I.edgeId,v.edgeId));let w=p.map((I)=>s.get(I.edgeId)),M=new Set(w.map((I)=>I?.pairKey)),S=y.isGroup&&p.every(({compactPortal:I})=>I);if(!(S&&p.length===1)&&M.size===1&&w.every((I)=>I&&I.bundleSize===p.length&&r.get(I.edge.start)===I.bundleSize&&r.get(I.edge.end)===I.bundleSize)){let I=(b+g)/2,v=w.map((R)=>I+R.laneOffset);if(v.every((R)=>R>=b&&R<=g)){p.forEach((R,A)=>u.set(R.demandKey,v[A]));continue}}if(S){let I=o.containers.get(y.id),v=f==="left"||f==="right"?I?.horizontalCorridors:I?.verticalCorridors,R=e((C)=>{let O=C.inner?a.get(C.inner.demandKey):void 0,P=O?i.get(O.ownerId):void 0,L=O?u.get(O.demandKey):void 0;if(!O||!P||L===void 0)return C.preferredCoord;let N=ce(z(P),O.side);if(O.side==="left"||O.side==="right")N.y=L;else N.x=L;return ke(N,f)},"innerCoordinate"),A=e((C)=>{let O=C.inner?u.get(C.inner.demandKey):void 0,P=C.inner!==void 0&&O!==void 0&&(C.inner.side==="left"||C.inner.side==="right")===(f==="left"||f==="right"),L=Gt(P?O:C.preferredCoord,b,g),N=v?.reduce((T,Y)=>Math.abs(Y-L)<Math.abs(T-L)?Y:T,v[0]);return N!==void 0&&Math.abs(N-L)<=rt?N:L},"preferredCoordinate");if(p.length===1){u.set(p[0].demandKey,A(p[0]));continue}if(x>=Ce*(p.length-1)){p.sort((P,L)=>R(P)-R(L)||P.oppositeCoord-L.oppositeCoord||W(P.edgeId,L.edgeId));let C=p.map(A),O=to(C,b,g);p.forEach((P,L)=>u.set(P.demandKey,O[L]));continue}}if(p.length===1||x<=0){u.set(p[0].demandKey,(b+g)/2);continue}let E=x/(p.length-1);p.forEach((I,v)=>{u.set(I.demandKey,b+E*v)})}for(let h of t){if(h.bundleSize!==1)continue;let f=h.source.chain.at(-1),p=h.target.chain.at(-1);if(!f||!p)continue;let y=e((w)=>w==="left"||w==="right","verticalSide");if(y(f.side)!==y(p.side))continue;let m=u.get(f.demandKey),b=u.get(p.demandKey);if(m===void 0||b===void 0||Math.abs(m-b)>rt)continue;let g=[...h.source.chain,...h.target.chain];if(g.some((w)=>y(w.side)!==y(f.side)))continue;let x=[m,b].find((w)=>g.every((M)=>{let S=i.get(M.ownerId),E=S?Lt(S,M.side):void 0;return E!==void 0&&w>=E.low-rt&&w<=E.high+rt}));if(x!==void 0)g.forEach((w)=>u.set(w.demandKey,x))}return u}e(Fi,"assignDemandCoordinates");function kt(t){return t==="right"?0:t==="bottom"?1:t==="left"?2:3}e(kt,"sideOrder");function Lt(t,o){let r=z(t);if(o==="top"&&t.groupTitleRect)return;let i=o==="left"||o==="right"?r.top+K:r.left+K,s=o==="left"||o==="right"?r.bottom-K:r.right-K;if((o==="left"||o==="right")&&t.groupTitleRect)i=Math.max(i,t.groupTitleRect.bottom+K);return i<=s?{low:i,high:s}:void 0}e(Lt,"sideInterval");function _t(t){let o=t.start??"",r=t.end??"";return o<r?`${o}|${r}`:`${r}|${o}`}e(_t,"endpointPairKey");function eo(t,o,r){let i=z(t.opposite),s=z(o.opposite),a=r==="left"||r==="right"?i.cy:i.cx,c=r==="left"||r==="right"?s.cy:s.cx;return a-c||W(_t(t.plan.edge),_t(o.plan.edge))||W(`${t.plan.edge.start}|${t.plan.edge.end}`,`${o.plan.edge.start}|${o.plan.edge.end}`)||W(t.plan.edge.id,o.plan.edge.id)||W(t.role,o.role)}e(eo,"compareEndpointDemands");function Di(t){return`${t.plan.edge.id}:${t.role}`}e(Di,"endpointDemandKey");function ki(t,o){return W(_t(t.plan.edge),_t(o.plan.edge))||W(`${t.plan.edge.start}|${t.plan.edge.end}`,`${o.plan.edge.start}|${o.plan.edge.end}`)||W(t.plan.edge.id,o.plan.edge.id)||W(t.role,o.role)}e(ki,"compareEndpointDemandIdentity");function ze(t,o,r){let i=Lt(t,o);if(!i||r.length===0)return new Map;let s=[...r].sort((d,l)=>eo(d,l,o));if(s.length===1){let d=z(t),l=o==="left"||o==="right"?d.cy:d.cx;return new Map([[s[0],Gt(l,i.low,i.high)]])}if((i.high-i.low)/(s.length-1)<Ce)return new Map(s.map((d,l)=>[d,i.low+l*(i.high-i.low)/(s.length-1)]));let a=s.map(({opposite:d})=>{let l=z(d),u=o==="left"||o==="right"?l.cy:l.cx;return Gt(u,i.low,i.high)}),c=to(a,i.low,i.high);return new Map(s.map((d,l)=>[d,c[l]]))}e(ze,"preferredEndpointCoordinates");function no(t,o){let r=Lt(t,o);if(!r)return 0;return 1+Math.floor((r.high-r.low)/Ce)}e(no,"endpointSideCapacity");function bn(t,o){let r=z(o.opposite),i=Je(t,{x:r.cx,y:r.cy});return["right","bottom","left","top"].filter((s)=>no(t,s)>0).sort((s,a)=>{if(s===i)return-1;if(a===i)return 1;let c=z(t),d=ce(c,s),l=ce(c,a),u=Math.abs(d.x-r.cx)+Math.abs(d.y-r.cy),h=Math.abs(l.x-r.cx)+Math.abs(l.y-r.cy);return u-h||kt(s)-kt(a)})}e(bn,"endpointSidePreferences");function ne(t,o){let r=z(t),i=z(o.opposite);return Math.abs(r.cx-i.cx)<=rt||Math.abs(r.cy-i.cy)<=rt}e(ne,"isAxisAlignedDemand");function zi(t,o,r,i){let s=Lt(t,o);if(!s)return;let a=[...r],c=new Map;for(let d of i){let l=z(d.opposite),u=Gt(o==="left"||o==="right"?l.cy:l.cx,s.low,s.high),h=[u,s.low,s.high,...a.flatMap((f)=>[f-ee,f+ee])].filter((f)=>f>=s.low-rt&&f<=s.high+rt&&a.every((p)=>Math.abs(f-p)>=ee-rt)).sort((f,p)=>Math.abs(f-u)-Math.abs(p-u)||f-p);if(h.length===0)return;c.set(d,h[0]),a.push(h[0])}return c}e(zi,"placePortsBesideFixed");function Hi(t,o){let r=new Map,i=new Map(["right","bottom","left","top"].map((g)=>[g,no(t,g)])),s=[...o].sort(ki),a=s.filter((g)=>ne(t,g)),c=s.filter((g)=>!ne(t,g)),d=new Set,l=new Map,u=new Map,h=e((g)=>(r.get(g)?.length??0)<(i.get(g)??0),"hasCapacity"),f=e((g,x)=>{let w=r.get(x)??[];w.push(g),r.set(x,w)},"record"),p=e((g)=>{let x=bn(t,g).find(h);if(x)f(g,x),d.add(x)},"assignAligned"),y=e((g,x)=>{let w=u.get(x)??new Map,M=zi(t,x,[...l.get(x)??[],...w.values()],[g]);if(!M)return!1;return w.set(g,M.get(g)),u.set(x,w),f(g,x),!0},"tryShareReservedSide"),m=e((g)=>{let x=bn(t,g).filter(h),w=x.find((E)=>!d.has(E));if(x.find((E)=>(w===void 0||x.indexOf(E)<x.indexOf(w))&&d.has(E)&&y(g,E)))return;let S=w??x[0];if(S)f(g,S)},"assignUnaligned");for(let g of a)p(g);for(let[g,x]of r)l.set(g,[...ze(t,g,x).values()]);for(let g of c)m(g);let b=new Map;for(let[g,x]of r){let w=Lt(t,g);if(!w)continue;let M=u.get(g),S=M?x.filter((v)=>!M.has(v)):x,E=new Map([...ze(t,g,S),...M??[]]),I=[...x].sort((v,R)=>eo(v,R,g));for(let[v,R]of I.entries()){let A=E.get(R)??(I.length===1?(w.low+w.high)/2:w.low+v*(w.high-w.low)/(I.length-1));b.set(Di(R),{side:g,coordinate:A})}}return b}e(Hi,"allocateEndpointSlots");function wn(t,o,r,i,s,a){let c=o==="source"?t.edge.start:t.edge.end,d=o==="source"?t.edge.end:t.edge.start,l=a.forest.nodeById.get(c),u=a.forest.nodeById.get(d);if(!l||!u)throw V("GRID_MISSING_ENDPOINT",`Missing endpoint for edge "${t.edge.id}"`);let h=z(u),f=[],p=new Set,y=i.get(c)?.get(`${t.edge.id}:${o}`),m=s.has(c)&&y!==void 0,b=e((x,w,M)=>{let S=Lt(l,x);if(!S||w<S.low||w>S.high)return;let E=z(l),I=x==="left"||x==="right"?{x:x==="left"?E.left:E.right,y:w}:{x:w,y:x==="top"?E.top:E.bottom},v=`${x}:${yt(I)}`;if(p.has(v))return;p.add(v),f.push({ownerId:c,side:x,port:I,connect:{x:I.x+(x==="left"?-Z:x==="right"?Z:0),y:I.y+(x==="top"?-Z:x==="bottom"?Z:0)},rank:M,onAssignedSide:m?x===y.side:void 0})},"addCandidate");if(y&&t.bundleSize===1)b(y.side,y.coordinate,-2);if(t.bundleSize>1){let x=Je(l,{x:h.cx,y:h.cy}),w=z(l),M=x==="left"||x==="right"?w.cy:w.cx;b(x,M+t.laneOffset,-1)}let g=[...r.get(c)??[]];for(let x of["right","bottom","left","top"]){if(!Lt(l,x))continue;let M=ze(l,x,g),S=g.find((A)=>A.plan===t&&A.role===o),E=S?M.get(S):void 0;if(E===void 0)continue;let I=z(l),v=x==="left"||x==="right"?{x:x==="left"?I.left:I.right,y:E}:{x:E,y:x==="top"?I.top:I.bottom},R=Math.abs(v.x-h.cx)+Math.abs(v.y-h.cy);b(x,E,R)}return f.sort((x,w)=>x.rank-w.rank||kt(x.side)-kt(w.side)),f.forEach((x,w)=>{x.rank=w}),f}e(wn,"endpointCandidates");function Vi(t,o){let r=Ni(t,o),i=new Map,s=new Map;for(let m of r){let b=_t(m.edge);if(i.set(b,(i.get(b)??0)+1),m.edge.start)s.set(m.edge.start,(s.get(m.edge.start)??0)+1);if(m.edge.end&&m.edge.end!==m.edge.start)s.set(m.edge.end,(s.get(m.edge.end)??0)+1)}let a=r.filter((m)=>m.edge.start!==m.edge.end&&m.source.chain.length===1&&m.target.chain.length===1&&m.source.finalKind==="item"&&m.target.finalKind==="item"),c=new Map;for(let m of a){let b=o.forest.nodeById.get(m.edge.start),g=o.forest.nodeById.get(m.edge.end);if(!b||!g)continue;let x=c.get(b.id)??[];x.push({plan:m,role:"source",opposite:g}),c.set(b.id,x);let w=c.get(g.id)??[];w.push({plan:m,role:"target",opposite:b}),c.set(g.id,w)}let d=new Map([...c].map(([m,b])=>{let g=o.forest.nodeById.get(m);return[m,g?Hi(g,b):new Map]})),l=new Set,u=new Set;for(let[m,b]of c){let g=o.forest.nodeById.get(m);if(!g)continue;let x=b.some((M)=>ne(g,M)),w=b.some((M)=>!ne(g,M));if(x&&w){u.add(m);for(let M of b)if(!ne(g,M))l.add(M.plan.edge.id)}}let h=new Map(a.map((m)=>[m.edge.id,{sources:wn(m,"source",c,d,u,o),targets:wn(m,"target",c,d,u,o)}])),f=new Map([...h].map(([m,b])=>[m,b.sources.length*b.targets.length])),p=e((m)=>{let b=o.forest.nodeById.get(m.edge.start),g=o.forest.nodeById.get(m.edge.end);if(m.edge.start===m.edge.end)return 0;if(b?.isGroup&&g&&Kt(b.id,g,o.forest.nodeById)||g?.isGroup&&b&&Kt(g.id,b,o.forest.nodeById))return 1;if((b?.parentId??X)!==(g?.parentId??X))return 2;return i.get(_t(m.edge))>1?3:4},"routeClass"),y=[...r].sort((m,b)=>{let g=_t(m.edge),x=_t(b.edge),w=`${m.edge.start??""}|${m.edge.end??""}`,M=`${b.edge.start??""}|${b.edge.end??""}`,S=m.source.chain.length+m.target.chain.length-2,E=b.source.chain.length+b.target.chain.length-2;return p(m)-p(b)||E-S||(f.get(m.edge.id)??0)-(f.get(b.edge.id)??0)||W(g,x)||W(w,M)||W(m.edge.id,b.edge.id)});return{plans:r,eligiblePlans:a,eligibleIds:new Set(a.map(({edge:m})=>m.id)),orderedPlans:y,demandCoords:Fi(y,o,s),endpointCandidatesByEdge:h,endpointIncidentCounts:s,coordinatedEndpointIds:l}}e(Vi,"prepareEdgeRoutes");function $i(t){if(!(t instanceof Error)||!("details"in t))return!1;let o=t.details;return typeof o==="object"&&o!==null&&"reason"in o&&o.reason==="pair-separation"}e($i,"isPairSeparationError");function Ft(t){let o=z(t);return{left:o.left,right:o.right,top:o.top,bottom:o.bottom}}e(Ft,"routerRect");function oo(t){if(t.length<2||t.some(({x:s,y:a})=>!Number.isFinite(s)||!Number.isFinite(a)))return;let o=[{...t[0]}];for(let s=1;s<t.length;s++){let a=t[s],c=o.at(-1);if(!(Math.abs(a.x-c.x)<=rt&&Math.abs(a.y-c.y)<=rt)){o.push({...a});continue}if(s!==t.length-1)continue;while(o.length>1){let l=o.at(-2);if(Math.abs(a.x-l.x)>rt||Math.abs(a.y-l.y)>rt)break;o.pop()}if(o.length===1)return;o[o.length-1]={...a}}if(o.length<2)return;let r=[];for(let s=0;s<o.length-1;s++){let a=o[s],c=o[s+1],d=Math.abs(c.x-a.x);if(Math.abs(c.y-a.y)<=rt)r.push("H");else if(d<=rt)r.push("V");else return}let i=o.map((s)=>({...s}));for(let s=0;s<r.length;){let a=r[s],c=s+1;while(c<r.length&&r[c]===a)c++;let d=a==="H"?"y":"x";if(s===0&&c===o.length-1&&o[s][d]!==o[c][d])return;let l=c===o.length-1?o[c][d]:o[s][d];for(let u=s;u<=c;u++){if(Math.abs(o[u][d]-l)>rt)return;i[u][d]=l}s=c}return i}e(oo,"canonicalizeOrthogonalPolyline");function Se(t,o,r){if(t.y===o.y)return t.y>r.top&&t.y<r.bottom&&Math.max(t.x,o.x)>r.left&&Math.min(t.x,o.x)<r.right;if(t.x===o.x)return t.x>r.left&&t.x<r.right&&Math.max(t.y,o.y)>r.top&&Math.min(t.y,o.y)<r.bottom;return!0}e(Se,"segmentEntersRect");function io(t){let o=Ft(t);return{left:o.left-K,right:o.right+K,top:o.top-K,bottom:o.bottom+K}}e(io,"inflatedRect");function Bt(t,o,r,i,s){let a=oo(t);if(!a)return!1;let c=H(a);if(c.points.length<2)return!1;if(c.segments.length>1&&(Math.abs(c.segments[0].a.x-c.segments[0].b.x)+Math.abs(c.segments[0].a.y-c.segments[0].b.y)<Z||Math.abs(c.segments.at(-1).a.x-c.segments.at(-1).b.x)+Math.abs(c.segments.at(-1).a.y-c.segments.at(-1).b.y)<Z))return!1;let d=(s.forest.childrenByParent.get(i)??[]).filter((l)=>!xt(l));for(let l of d){let u=io(l);for(let h=0;h<c.points.length-1;h++){if(l.id===o.id&&h===0||l.id===r.id&&h===c.points.length-2){if(Se(c.points[h],c.points[h+1],Ft(l)))return!1;continue}if(Se(c.points[h],c.points[h+1],u))return!1}}return!0}e(Bt,"validateSameContainerRoute");function $t(t,o,r,i,s){let a=oo(t);if(!a)return!1;let c=H(a);if(c.points.length<2)return!1;let d=(s.forest.childrenByParent.get(i)??[]).filter((l)=>!xt(l));for(let l of d){let u=io(l);for(let h=0;h<c.points.length-1;h++){if(l.id===o&&h===0||l.id===r&&h===c.points.length-2){if(Se(c.points[h],c.points[h+1],Ft(l)))return!1;continue}if(Se(c.points[h],c.points[h+1],u))return!1}}return!0}e($t,"validateContainerSegment");function vn(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)}}e(vn,"segmentSpan");function de(t){let o=H([...t]).segments.filter((i)=>i.orientation!=="Z").map((i)=>({a:{...i.a},b:{...i.b},orientation:i.orientation}));if(o.length===0)return[];if(o.length===1&&Math.abs(o[0].a.x-o[0].b.x)+Math.abs(o[0].a.y-o[0].b.y)<=Z*2)return[];let r=e((i,s)=>{if(i.orientation==="H"){let a=Math.sign(i.b.x-i.a.x);if(s)i.a.x+=a*Z;else i.b.x-=a*Z}else{let a=Math.sign(i.b.y-i.a.y);if(s)i.a.y+=a*Z;else i.b.y-=a*Z}},"trim");return r(o[0],!0),r(o[o.length-1],!1),o.filter(({a:i,b:s})=>i.x!==s.x||i.y!==s.y)}e(de,"nonterminalSegments");function ro(t,o){if(t.orientation!==o.orientation)return!1;let r=vn(t),i=vn(o),s=Math.max(0,Math.min(r.high,i.high)-Math.max(r.low,i.low));if(s<=0)return!1;let a=t.orientation==="H"?Math.abs(t.a.y-o.a.y):Math.abs(t.a.x-o.a.x);return a===0&&s>=Ne||a>0&&a<Ne}e(ro,"pairSegmentsConflict");function mt(t,o){let r=H([...t]).points,i=[r[0],r.at(-1)],s=de(r);return o.every((a)=>{let c=H([...a]).points,d=[c[0],c.at(-1)];if(i.some((l)=>d.some((u)=>l.x===u.x&&l.y===u.y)))return!1;return s.every((l)=>de(c).every((u)=>!ro(l,u)))})}e(mt,"routeSatisfiesPairConstraints");function so(t,o){let r=H([...t]).points,i=[r[0],r.at(-1)];return o.every((s)=>{let a=H([...s]).points,c=[a[0],a.at(-1)];return!i.some((d)=>c.some((l)=>d.x===l.x&&d.y===l.y))})}e(so,"routeHasDistinctPairPorts");function tn(t,o,r){let i=t.y===o.y?"H":"V",s={a:t,b:o,orientation:i};return r.every((a)=>de(a).every((c)=>!ro(s,c)))}e(tn,"pairArcAllowed");function Ki(t,o){let r=t.side==="left"||t.side==="right"?"H":"V",i=o.side==="left"||o.side==="right"?"H":"V",s=Math.abs(t.connect.x-o.connect.x),a=Math.abs(t.connect.y-o.connect.y),c;if(s===0&&a===0)c=Number(r!==i);else if(s===0||a===0){let d=s===0?"V":"H";c=Number(r!==d)+Number(i!==d)}else c=Math.min(Number(r!=="H")+1+Number(i!=="V"),Number(r!=="V")+1+Number(i!=="H"));return[Z*2+s+a,c]}e(Ki,"endpointPairLowerBound");function ji(t,o){if(t.orientation!==o.orientation)return!1;let r=t.orientation==="H",i=e((d)=>r?Math.min(d.a.x,d.b.x):Math.min(d.a.y,d.b.y),"lowOf"),s=e((d)=>r?Math.max(d.a.x,d.b.x):Math.max(d.a.y,d.b.y),"highOf"),a=Math.min(s(t),s(o))-Math.max(i(t),i(o)),c=r?Math.abs(t.a.y-o.a.y):Math.abs(t.a.x-o.a.x);return a>0&&c<ee}e(ji,"segmentsTooClose");var In=class{constructor(){this.lines={H:new Map,V:new Map},this.sortedCoordinates={H:void 0,V:void 0},this.log=[]}static{e(this,"RouteOccupancyIndex")}get size(){return this.log.length}add(t,o){for(let r of de(t)){let i=r.orientation,s=i==="H"?r.a.y:r.a.x,a=this.lines[i].get(s);if(a)a.push({segment:r,pairKey:o});else this.lines[i].set(s,[{segment:r,pairKey:o}]),this.sortedCoordinates[i]=void 0;this.log.push({orientation:i,coordinate:s})}}truncate(t){while(this.log.length>t){let{orientation:o,coordinate:r}=this.log.pop();this.lines[o].get(r)?.pop()}}conflictsWithRoute(t,o){return de(t).some((r)=>this.conflicts(r,o))}conflictsWithArc(t,o,r){let i=t.y===o.y?"H":"V";return this.conflicts({a:t,b:o,orientation:i},r)}conflicts(t,o){let r=t.orientation;if(r!=="H"&&r!=="V")return!1;let i=r==="H"?t.a.y:t.a.x,s=this.coordinatesFor(r),a=0,c=s.length;while(a<c){let d=a+c>>1;if(s[d]<=i-ee)a=d+1;else c=d}for(let d=a;d<s.length;d++){let l=s[d];if(l>=i+ee)break;for(let u of this.lines[r].get(l))if(u.pairKey!==o&&ji(t,u.segment))return!0}return!1}coordinatesFor(t){return this.sortedCoordinates[t]??=[...this.lines[t].keys()].sort((o,r)=>o-r)}},Et=24,gt=18,At=14,Io=4,Ui=18,ao=4,Zr=64,Jr=4;function Xi(t,o,r,i){if(!o.conflictsWithRoute(t,r))return[...t];let s=H([...t]).points;for(let a=1;a<=Jr;a++)for(let c of[1,-1]){let d=c*a*Ne;for(let l=1;l<s.length-2;l++){let u=s[l].x===s[l+1].x,h=s.map((f,p)=>p===l||p===l+1?u?{x:f.x+d,y:f.y}:{x:f.x,y:f.y+d}:f);if(!o.conflictsWithRoute(h,r)&&i(h))return h}}return}e(Xi,"separateRouteFromOccupied");function Wi(t){let o=e((r,i)=>Math.abs(r.x-i.x)+Math.abs(r.y-i.y),"stub");return o(t[0],t[1])>=Z&&o(t.at(-1),t.at(-2))>=Z}e(Wi,"terminalStubsAreLongEnough");function Yi(t,o,r,i,s=3){let a=[...i.filter((l)=>l>=o&&l<=r).sort((l,u)=>Math.abs(l-t)-Math.abs(u-t)||l-u),(o+r)/2,o,r],c=new Set([t]),d=[];for(let l of a){if(c.has(l))continue;if(c.add(l),d.push(l),d.length===s)break}return d}e(Yi,"boundedAlternativePortalCoordinates");function oe(t,o){return Math.abs(t.x-o.x)<=0.000001&&Math.abs(t.y-o.y)<=0.000001}e(oe,"equalPoint");function qi(t,o){return t.x===o.x||t.y===o.y}e(qi,"areExactlyAxisAligned");function _e(t,o,r,i){let s=[...t].sort((a,c)=>Math.abs(a-o)+Math.abs(a-r)-(Math.abs(c-o)+Math.abs(c-r))||a-c);return s[Math.min(i,Math.max(0,s.length-1))]??(o+r)/2}e(_e,"chooseIntermediateCoordinate");function Qi(t){let o=[];for(let r of t)if(o.length===0||!oe(o[o.length-1],r))o.push(r);return o}e(Qi,"dedupeConsecutive");function qt(t,o,r,i,s){let a=o.containers.get(t);if(!a)throw V("GRID_ROUTE_NOT_FOUND",`Missing container layout "${t}"`);let c=[r.port,r.connect];if(r.orientation==="V"&&i.orientation==="V"){if(!oe(r.connect,i.connect)&&Math.abs(r.connect.x-i.connect.x)>0.000001){let d=_e(a.horizontalCorridors,r.connect.y,i.connect.y,s);c.push({x:r.connect.x,y:d},{x:i.connect.x,y:d})}else if(!oe(r.connect,i.connect)&&Math.abs(r.connect.y-i.connect.y)>0.000001&&s>0){let d=a.verticalCorridors.filter((u)=>Math.abs(u-r.connect.x)>0.000001),l=_e(d.length>0?d:a.verticalCorridors,r.connect.x,i.connect.x,s-1);c.push({x:l,y:r.connect.y},{x:l,y:i.connect.y})}}else if(r.orientation==="H"&&i.orientation==="H"){if(!oe(r.connect,i.connect)&&Math.abs(r.connect.y-i.connect.y)>0.000001){let d=_e(a.verticalCorridors,r.connect.x,i.connect.x,s);c.push({x:d,y:r.connect.y},{x:d,y:i.connect.y})}}else if(r.orientation==="V"&&i.orientation==="H")c.push({x:r.connect.x,y:i.connect.y});else c.push({x:i.connect.x,y:r.connect.y});return c.push(i.connect,i.port),H(Qi(c)).points}e(qt,"routeWithinContainer");function Ee(t,o,r,i,s,a,c){let d=s.forest.nodeById.get(t),l=s.itemMeta.get(t);if(!d||!l||l.containerId!==i)throw V("GRID_ROUTE_NOT_FOUND",`Missing item metadata for "${t}" in "${i}"`);let u=z(d),h=c??a.get(r)??(o==="left"||o==="right"?u.cy:u.cx);switch(o){case"left":return{port:{x:u.left,y:h},connect:{x:l.leftCorridorX,y:h},orientation:"V",side:o};case"right":return{port:{x:u.right,y:h},connect:{x:l.rightCorridorX,y:h},orientation:"V",side:o};case"top":return{port:{x:h,y:u.top},connect:{x:h,y:l.topCorridorY},orientation:"H",side:o};case"bottom":return{port:{x:h,y:u.bottom},connect:{x:h,y:l.bottomCorridorY},orientation:"H",side:o}}}e(Ee,"itemAttachment");function co(t,o,r,i,s){let a=i.forest.nodeById.get(t),c=i.containers.get(t);if(!a||!c)throw V("GRID_ROUTE_NOT_FOUND",`Missing boundary metadata for "${t}"`);let d=z(a),l=s.get(r)??(o==="left"||o==="right"?d.cy:d.cx);switch(o){case"left":return{port:{x:d.left,y:l},connect:{x:c.verticalCorridors[0],y:l},orientation:"V",side:o};case"right":return{port:{x:d.right,y:l},connect:{x:c.verticalCorridors[c.verticalCorridors.length-1],y:l},orientation:"V",side:o};case"top":return{port:{x:l,y:d.top},connect:{x:l,y:c.horizontalCorridors[0]},orientation:"H",side:o};case"bottom":return{port:{x:l,y:d.bottom},connect:{x:l,y:c.horizontalCorridors[c.horizontalCorridors.length-1]},orientation:"H",side:o}}}e(co,"boundaryAttachment");function Zi(t){return{x:(t.interior.x+t.exterior.x)/2,y:(t.interior.y+t.exterior.y)/2}}e(Zi,"portalBoundaryPoint");function Jt(t,o){return{ownerId:t.ownerId,port:Zi(t),connect:o?t.interior:t.exterior,orientation:t.side==="left"||t.side==="right"?"V":"H",side:t.side}}e(Jt,"portalAttachment");function Mn(t,o,r,i,s){let a=i.forest.nodeById.get(t);if(!a?.isGroup)throw V("GRID_ROUTE_NOT_FOUND",`Missing group endpoint "${t}"`);let c=z(a),d=s.get(r)??(o==="left"||o==="right"?c.cy:c.cx),l=o==="left"||o==="right"?{x:o==="left"?c.left:c.right,y:d}:{x:d,y:o==="top"?c.top:c.bottom};return{ownerId:t,port:l,connect:{x:l.x+(o==="left"?Z:o==="right"?-Z:0),y:l.y+(o==="top"?Z:o==="bottom"?-Z:0)},orientation:o==="left"||o==="right"?"V":"H",side:o}}e(Mn,"groupBoundaryEndpointAttachment");function Ji(t){return[...t].reverse()}e(Ji,"reversePoints");function tr(t){let o=[];for(let r of t)for(let i of r)if(o.length===0||!oe(o[o.length-1],i))o.push(i);return H(o).points}e(tr,"combinePointChains");function er(t,o,r,i){let s=z(t),a=At+(r+1)*Ui,c=r*ao;switch(o){case"right":{let d=i-gt/2-c,l=i+gt/2+c;return H([{x:s.right,y:d},{x:s.right+At,y:d},{x:s.right+a,y:d},{x:s.right+a,y:l},{x:s.right+At,y:l},{x:s.right,y:l}]).points}case"left":{let d=i-gt/2-c,l=i+gt/2+c;return H([{x:s.left,y:d},{x:s.left-At,y:d},{x:s.left-a,y:d},{x:s.left-a,y:l},{x:s.left-At,y:l},{x:s.left,y:l}]).points}case"top":{let d=i-gt/2-c,l=i+gt/2+c;return H([{x:d,y:s.top},{x:d,y:s.top-At},{x:d,y:s.top-a},{x:l,y:s.top-a},{x:l,y:s.top-At},{x:l,y:s.top}]).points}case"bottom":{let d=i-gt/2-c,l=i+gt/2+c;return H([{x:d,y:s.bottom},{x:d,y:s.bottom+At},{x:d,y:s.bottom+a},{x:l,y:s.bottom+a},{x:l,y:s.bottom+At},{x:l,y:s.bottom}]).points}}}e(er,"routeSelfLoop");function lo(t,o,r,i,s){let a=z(t),c=At+(r+1)*Ui,d=r*ao,l=gt+d*2,u=o==="left"||o==="right",h=Math.max(l,(u?s.cross:s.along)+Wt*2+Lo),f=Math.max(c,(u?s.along:s.cross)/2+Wt),p=u?[a.top,a.bottom]:[a.left,a.right],y=i-h/2,m=i+h/2;if(y-p[0]>=Io&&p[1]-m>=Io)switch(o){case"right":return[H([{x:a.right,y},{x:a.right+f,y},{x:a.right+f,y:m},{x:a.right,y:m}]).points];case"left":return[H([{x:a.left,y},{x:a.left-f,y},{x:a.left-f,y:m},{x:a.left,y:m}]).points];case"top":return[H([{x:y,y:a.top},{x:y,y:a.top-f},{x:m,y:a.top-f},{x:m,y:a.top}]).points];case"bottom":return[H([{x:y,y:a.bottom},{x:y,y:a.bottom+f},{x:m,y:a.bottom+f},{x:m,y:a.bottom}]).points]}let b=i-gt/2-d,g=i+gt/2+d;if(b<p[0]||g>p[1])return[];let x=i-h/2,w=i+h/2,M=Math.max(At,Z),S=Math.max(f,M+(u?s.along:s.cross)/2+Wt);switch(o){case"right":return[H([{x:a.right,y:b},{x:a.right+M,y:b},{x:a.right+M,y:x},{x:a.right+S,y:x},{x:a.right+S,y:w},{x:a.right+M,y:w},{x:a.right+M,y:g},{x:a.right,y:g}]).points];case"left":return[H([{x:a.left,y:b},{x:a.left-M,y:b},{x:a.left-M,y:x},{x:a.left-S,y:x},{x:a.left-S,y:w},{x:a.left-M,y:w},{x:a.left-M,y:g},{x:a.left,y:g}]).points];case"top":return[H([{x:b,y:a.top},{x:b,y:a.top-M},{x,y:a.top-M},{x,y:a.top-S},{x:w,y:a.top-S},{x:w,y:a.top-M},{x:g,y:a.top-M},{x:g,y:a.top}]).points];case"bottom":return[H([{x:b,y:a.bottom},{x:b,y:a.bottom+M},{x,y:a.bottom+M},{x,y:a.bottom+S},{x:w,y:a.bottom+S},{x:w,y:a.bottom+M},{x:g,y:a.bottom+M},{x:g,y:a.bottom}]).points]}}e(lo,"labelAwareSelfLoopCandidates");function uo(t,o,r){return(t.isGroup&&Ze(t)?["left","right","bottom"]:["left","right","top","bottom"]).sort((s,a)=>{let c=(o.get(ae(t.id,s))??0)+(r.get(`${t.id}:${s}`)??0),d=(o.get(ae(t.id,a))??0)+(r.get(`${t.id}:${a}`)??0);return c-d})}e(uo,"orderedSelfLoopSides");function nr(t,o){let r=[];for(let i of o.forest.nodeById.values()){if(i.id!==t.id&&!i.isGroup&&i.x!==void 0&&i.y!==void 0)r.push(z(i));if(i.id!==t.id&&i.groupTitleRect){let{left:s,right:a,top:c,bottom:d}=i.groupTitleRect;r.push({cx:(s+a)/2,cy:(c+d)/2,left:s,right:a,top:c,bottom:d})}}return r}e(nr,"selfLoopObstacles");function or(t,o,r,i,s,a){let c=z(t),d=nr(t,i);for(let l of uo(t,o,r)){let u=`${t.id}:${l}`,h=r.get(u)??0,f=l==="left"||l==="right"?c.cy:c.cx,p=s?lo(t,l,h,f,s):[er(t,l,h,f)];if(s&&a)a.labelAwareSelfLoopCandidates+=p.length;for(let y of p)if(!d.some((m)=>It(y,m)))return{points:y,side:l,index:h}}throw V("GRID_ROUTE_NOT_FOUND",`No obstacle-clear self-loop route for "${t.id}"`,{nodeId:t.id})}e(or,"routeObstacleClearSelfLoop");function ir(t){if(t.containers.has(X))return;let o=0,r=0,i=0,s=0,a=!0;for(let l of t.itemMeta.values()){if(l.containerId!==X)continue;if(a)o=l.cellLeft,r=l.cellLeft+l.cellWidth,i=l.cellTop,s=l.cellTop+l.cellHeight,a=!1;else o=Math.min(o,l.cellLeft),r=Math.max(r,l.cellLeft+l.cellWidth),i=Math.min(i,l.cellTop),s=Math.max(s,l.cellTop+l.cellHeight)}let c=new Set([i-Et,s+Et]),d=new Set([o-Et,r+Et]);for(let l of t.itemMeta.values()){if(l.containerId!==X)continue;c.add(l.topCorridorY),c.add(l.bottomCorridorY),d.add(l.leftCorridorX),d.add(l.rightCorridorX)}t.containers.set(X,{id:X,left:o-Et,top:i-Et,width:r-o+Et*2,height:s-i+Et*2,contentLeft:o,contentTop:i,contentRight:r,contentBottom:s,verticalCorridors:[...d].sort((l,u)=>l-u),horizontalCorridors:[...c].sort((l,u)=>l-u)})}e(ir,"rootContainerMeta");function rr(t,o){let r=o.containers.get(t);if(!r)throw V("GRID_ROUTE_NOT_FOUND",`Missing container layout "${t}"`);if(t===X){let a=[...o.itemMeta.values()].filter(({containerId:c})=>c===X);if(a.length>0)return{left:Math.min(...a.map(({cellLeft:c})=>c))-Et,right:Math.max(...a.map(({cellLeft:c,cellWidth:d})=>c+d))+Et,top:Math.min(...a.map(({cellTop:c})=>c))-Et,bottom:Math.max(...a.map(({cellTop:c,cellHeight:d})=>c+d))+Et};return{left:r.left,right:r.left+r.width,top:r.top,bottom:r.top+r.height}}let i=o.forest.nodeById.get(t);if(!i)throw V("GRID_ROUTE_NOT_FOUND",`Missing container owner "${t}"`);let s=Ft(i);return{left:s.left+K,right:s.right-K,top:s.top+K,bottom:s.bottom-K}}e(rr,"containerBounds");function Cn(t,o,r){return(o==="left"?t.left:o==="right"?t.right:o==="top"?t.top:t.bottom)+(o==="left"||o==="top"?1:-1)*K*(r?1:-1)}e(Cn,"portalCoordinate");function sr(t,o){let r=[];if(t!==X){let i=o.forest.nodeById.get(t);if(i){let s=Ft(i);r.push(...se(t,s,i.groupTitleRect).map((a)=>({...a,coordinate:Cn(s,a.side,!0)})))}}for(let i of o.forest.childrenByParent.get(t)??[]){if(!i.isGroup)continue;let s=Ft(i);r.push(...se(i.id,s,i.groupTitleRect).map((a)=>({...a,coordinate:Cn(s,a.side,!1)})))}return r}e(sr,"containerPortalRanges");function ar(t,o,r,i){let s={topologies:new Map,fallbackContainers:new Map,searchBudget:{expandedStates:0},searchBudgetWarningEmitted:!1,baseEstimatedBytes:0,metrics:r},a=0;for(let c of[...new Set(t)].sort()){let d=(o.forest.childrenByParent.get(c)??[]).filter((u)=>!xt(u)),l=o.forest.nodeById.get(c)?.groupTitleRect;try{let u=Pi({containerId:c,bounds:rr(c,o),obstacles:d.map((f)=>({id:f.id,bounds:Ft(f)})),titleExclusions:l?[{id:`${c}:title`,bounds:{...l}}]:void 0,portalRanges:sr(c,o)},{caps:i.topologyCaps}),h=i.topologyCaps?.maxEstimatedBytes??jt;if(a+u.estimatedBytes>h){s.fallbackContainers.set(c,"estimated_memory_cap");continue}if(a+=u.estimatedBytes,s.baseEstimatedBytes=a,s.topologies.set(c,u),r)r.containersBuilt++,r.baseTopologyBuilds++,r.baseVertices+=u.vertices.length,r.baseAdjacencyEntries+=u.adjacencyEntries,r.buildSweepEvents+=u.seedCount*4+u.obstacles.length*4,r.estimatedBytes=a}catch(u){if(!(u instanceof Tt))throw u;s.fallbackContainers.set(c,u.reason)}}return s}e(ar,"buildRoutingContext");function Sn(t,o,r,i,s,a,c){let d=s();if(c)c.compatibilitySegments++;if($t(d,r.ownerId,i.ownerId,o,a))return d;if(c)c.compatibilityValidationFailures++,c.routesImpossible++;throw V("GRID_ROUTE_NOT_FOUND",`Invalid compatibility route for "${t}"`,{edgeId:t,containerId:o})}e(Sn,"validatedCompatibilitySegment");function Re(t,o,r){let i=t.source.chain.at(-1),s=t.target.chain.at(-1),a=e((c,d)=>({ownerId:d.ownerId,...c.finalKind==="boundary"?co(t.lcaContainerId,d.side,d.demandKey,o,r):Ee(d.ownerId,d.side,d.demandKey,t.lcaContainerId,o,r)}),"finalAttachment");return{start:a(t.source,i),end:a(t.target,s)}}e(Re,"compatibilityLcaAttachments");function ho(t,o,r){return t.chain.slice(0,-1).map((i,s)=>{let a=t.chain[s+1];return{containerId:a.ownerId,start:{ownerId:i.ownerId,...Ee(i.ownerId,i.side,i.demandKey,a.ownerId,o,r)},end:{ownerId:a.ownerId,...co(a.ownerId,a.side,a.demandKey,o,r)}}})}e(ho,"compatibilityHierarchyAttachments");function cr(t,o,r){let i=e((a,c,d)=>$t(qt(a,o,c,d,t.laneIndex),c.ownerId,d.ownerId,a,o),"segmentIsValid");for(let a of[t.source,t.target])for(let{containerId:c,start:d,end:l}of ho(a,o,r))if(!i(c,d,l))return!1;let s=Re(t,o,r);return i(t.lcaContainerId,s.start,s.end)}e(cr,"compatibilityPlanIsValid");function dr(t,o,r,i){let{plans:s,eligiblePlans:a,eligibleIds:c,demandCoords:d,endpointCandidatesByEdge:l,endpointIncidentCounts:u,coordinatedEndpointIds:h}=t,f=e((v)=>(u.get(v.edge.start)??0)===v.bundleSize&&(u.get(v.edge.end)??0)===v.bundleSize,"hasIsolatedEndpoints"),p=e((v)=>{let R=o.forest.nodeById.get(v.edge.start),A=o.forest.nodeById.get(v.edge.end);return Boolean(R&&A&&(R.isGroup&&Kt(R.id,A,o.forest.nodeById)||A.isGroup&&Kt(A.id,R,o.forest.nodeById)))},"hasAncestorEndpoint"),y=new Map,m=new Map,b=s.length<=Zr,g=i.topologyCaps===void 0&&i.searchCaps===void 0&&i.onDualRouteComparison===void 0;for(let v of g?a:[]){if(h.has(v.edge.id))continue;let R=l.get(v.edge.id);if(v.bundleSize!==1||!R?.sources.length||!R.targets.length)continue;let A=o.forest.nodeById.get(v.edge.start),C=o.forest.nodeById.get(v.edge.end);if(!A||!C)continue;let O=Re(v,o,d),P=qt(v.lcaContainerId,o,O.start,O.end,v.laneIndex),L=H(P),N=L.points[0],T=L.points.at(-1);if(!N||!T)continue;let Y=R.sources.find(({port:J})=>J.x===N.x&&J.y===N.y),q=R.targets.find(({port:J})=>J.x===T.x&&J.y===T.y);if(!Y||!q)continue;if(r)r.compatibilityFastPathAttempts++;let D=Math.abs(N.x-T.x)+Math.abs(N.y-T.y);if(!Bt(P,A,C,v.lcaContainerId,o)){if(r)r.compatibilityFastPathValidationFailures++;continue}if(re(L.points)!==D){if(r)r.compatibilityFastPathNonMinimalRoutes++;continue}let Q=m.get(v.lcaContainerId);if(!Q)Q=new In,m.set(v.lcaContainerId,Q);if(Q.conflictsWithRoute(L.points,v.pairKey)&&b)continue;let k=Xi(L.points,Q,v.pairKey,(J)=>Wi(J)&&re(J)===D&&Bt(J,A,C,v.lcaContainerId,o))??P;Q.add(k,v.pairKey),y.set(v.edge.id,k)}let x=e((v)=>!c.has(v.edge.id)&&v.edge.start!==v.edge.end&&(v.bundleSize>1||f(v)||!cr(v,o,d)),"sparseCandidate"),w=new Map,M=new Set;if(b)for(let v of t.orderedPlans){if(c.has(v.edge.id)||v.edge.start===v.edge.end||p(v)||x(v))continue;let R=Re(v,o,d),A=qt(v.lcaContainerId,o,R.start,R.end,v.laneIndex),C=w.get(v.lcaContainerId);if(!C)C=new In,w.set(v.lcaContainerId,C);if(C.conflictsWithRoute(A,v.pairKey))M.add(v.edge.id);else C.add(A,v.pairKey)}let S=new Set([...s.filter(x).map(({edge:v})=>v.id),...M]),E=new Set([...S,...s.filter(p).map(({edge:v})=>v.id)]),I=s.filter((v)=>c.has(v.edge.id)&&!y.has(v.edge.id)||E.has(v.edge.id)||v.edge.start===v.edge.end).flatMap((v)=>[v.lcaContainerId,...v.source.chain.slice(1).map(({ownerId:R})=>R),...v.target.chain.slice(1).map(({ownerId:R})=>R)]);return{overlapAvoidanceEnabled:b,compatibilityFastRoutes:y,sparseHierarchyIds:S,sparseLcaIds:E,routedContainerIds:I,routeOccupancy:m}}e(dr,"prepareRoutingModes");var Mo={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"},ts=Object.keys(Mo).filter((t)=>Mo[t]==="transactional"&&t!=="routeOrder"&&t!=="routes");function lr(t){return{routeOrderLength:t.routeOrder.length,routesLength:t.routes.length,values:Object.fromEntries(ts.map((o)=>[o,t[o]]))}}e(lr,"createGridRoutingInstrumentationCheckpoint");function ur(t,o){t.routeOrder.length=o.routeOrderLength,t.routes.length=o.routesLength,Object.assign(t,o.values)}e(ur,"restoreGridRoutingInstrumentationCheckpoint");function En(t,o,r,i){return Math.max(0,Math.min(Math.max(t,o),Math.max(r,i))-Math.max(Math.min(t,o),Math.min(r,i)))}e(En,"intervalOverlap");function hr(t,o){let r=H(t).segments,i=H(o).segments,s=0;for(let a of r)for(let c of i){if(a.orientation!==c.orientation)continue;if(a.orientation==="H"&&a.a.y===c.a.y)s+=En(a.a.x,a.b.x,c.a.x,c.b.x);else if(a.orientation==="V"&&a.a.x===c.a.x)s+=En(a.a.y,a.b.y,c.a.y,c.b.y)}return s}e(hr,"sharedSegmentLength");function Rn(t,o,r,i,s=0,a=0){let c=H(r),d=0,l=0;for(let h of i){let f=H(h).segments;for(let p of c.segments)for(let y of f)if(Gn(p,y))d++;l+=hr(c.points,h)}let u={edgeId:o,routeOrder:t.routes.length,laneOffset:a,routeLength:re(c.points),bendCount:c.bends,crossingCount:d,sharedLength:l,boundaryTransitionCount:s,routeSignature:JSON.stringify(c.points)};t.routeOrder.push(o),t.routes.push(u),t.routesFound++,t.routeLength+=u.routeLength,t.bendCount+=u.bendCount,t.crossingCount+=u.crossingCount,t.sharedLength+=u.sharedLength,t.hierarchyBoundaryTransitions+=s}e(Rn,"recordGridRoute");var fr=1e5,pr=2000000,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{e(this,"RouterSearchWorkspace")}reset(t){let o=t*3;if(this.best.length<o)this.best=new Int32Array(o),this.best.fill(-1);else for(let r of this.touchedBestIndices)this.best[r]=-1;this.touchedBestIndices.length=0,this.heapPairs.length=0}setBest(t,o){if(this.best[t]<0)this.touchedBestIndices.push(t);this.best[t]=o}ensureStateCapacity(t){if(this.stateVertices.length>=t)return;let o=Math.max(t,this.stateVertices.length*2);this.stateVertices=wt(this.stateVertices,o),this.orientations=wt(this.orientations,o),this.gLengths=wt(this.gLengths,o),this.gBends=wt(this.gBends,o),this.gBoundaryTransitions=wt(this.gBoundaryTransitions,o),this.fLengths=wt(this.fLengths,o),this.fBends=wt(this.fBends,o),this.predecessors=wt(this.predecessors,o),this.depths=wt(this.depths,o),this.ancestor4=wt(this.ancestor4,o),this.heapChildren=wt(this.heapChildren,o),this.heapSiblings=wt(this.heapSiblings,o)}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 Oe(t){let o=t.caps?.maxExpandedStates??fr,r=t.caps?.maxInvocationExpandedStates??pr,i=t.budget?.expandedStates??t.metrics?.expandedStates??0;if(o>0&&i<r)return;throw new Tt("search_state_cap","Grid routing search-state cap exceeded",i>=r?"invocation":"edge")}e(Oe,"assertSearchBudgetAvailable");function wt(t,o){let r=new t.constructor(o);return r.set(t),r}e(wt,"growTypedArray");function ie(t,o){for(let r=0;r<4;r++){if(t[r]<o[r])return-1;if(t[r]>o[r])return 1}return 0}e(ie,"compareTupleCost");function An(t,o,r,i){if(t===0&&o===0)return r&&i?Number(r!==i):0;if(t===0)return(r?Number(r!=="V"):0)+(i?Number(i!=="V"):0);if(o===0)return(r?Number(r!=="H"):0)+(i?Number(i!=="H"):0);return Math.min((r?Number(r!=="H"):0)+1+(i?Number(i!=="V"):0),(r?Number(r!=="V"):0)+1+(i?Number(i!=="H"):0))}e(An,"minimumBends");function we(t){return t===void 0?0:t==="H"?1:2}e(we,"orientationOrdinal");function On(t,o,r){return r==="left"?t.y===o.y&&o.x>t.x:r==="right"?t.y===o.y&&o.x<t.x:r==="top"?t.x===o.x&&o.y>t.y:t.x===o.x&&o.y<t.y}e(On,"movesTowardOwner");function mr(t,o){return t*3+we(o)}e(mr,"stateIndex");function yr(t){let o=[];for(let r of t){let i=o.at(-1);if(i&&i.x===r.x&&i.y===r.y)continue;let s=o.at(-2);if(s&&i&&(s.x===i.x&&i.x===r.x||s.y===i.y&&i.y===r.y))o[o.length-1]={...r};else o.push({...r})}return o}e(yr,"normalizePoints");function Bn(t,o,r,i,s){let a=[],c=t;while(c>=0)a.push(o[c]),c=r[c];return a.reverse(),{points:yr(a.map((d)=>s(d).point)),vertexIds:a,cost:i}}e(Bn,"reconstruct");function xr(t){for(let o of t.vertices){if(o.id<0||t.vertices[o.id]!==o||!Number.isFinite(o.point.x)||!Number.isFinite(o.point.y))throw Error("Malformed grid routing vertex");for(let r of t.adjacency.get(o.id)??[]){let i=t.vertices[r.to],s=i&&(r.orientation==="H"?o.point.y===i.point.y:o.point.x===i.point.x),a=i?Math.abs(o.point.x-i.point.x)+Math.abs(o.point.y-i.point.y):Number.NaN;if(r.from!==o.id||!s||!Number.isFinite(r.length)||r.length<=0||r.length!==a)throw Error("Malformed grid routing arc")}}}e(xr,"validateSearchTopology");function br(t,o,r,i){let s=e((_)=>{let G=t.getVertex?.(_)??t.vertices[_];if(!G)throw Error(`Missing grid routing vertex ${_}`);return G},"vertexAt"),a=s(o),c=s(r);if(!i.topologyValidated)xr(t);let d=i.metrics;if(d)d.searches++;Oe(i);let l=i.workspace??new gr;l.reset(t.vertexCount??t.vertices.length);let{stateVertices:u,orientations:h,gLengths:f,gBends:p,gBoundaryTransitions:y,fLengths:m,fBends:b,predecessors:g,depths:x,ancestor4:w,heapChildren:M,heapSiblings:S,best:E,heapPairs:I}=l,v=1,R=i.endpointCandidateRank??0,A=i.heuristic!=="zero";function C(_,G){return u[_]-u[G]||h[_]-h[G]||g[_]-g[G]||_-G}e(C,"nonCostOrder");function O(_,G){return m[_]-m[G]||b[_]-b[G]||y[_]-y[G]||(i.queueOrder==="reverse"?-C(_,G):C(_,G))}e(O,"compareStates");function P(_,G){if(_===G)return 0;if(_<0)return-1;if(G<0)return 1;let lt=x[_],ut=x[G],et=_,j=G;while(x[et]>x[j])et=g[et];while(x[j]>x[et])j=g[j];if(et===j)return lt-ut;while(w[et]>=0&&w[j]>=0&&w[et]!==w[j])et=w[et],j=w[j];while(g[et]!==g[j])et=g[et],j=g[j];return u[et]-u[j]||h[et]-h[j]}e(P,"compareChains");let L=-1,N=0;function T(_,G){if(_<0)return G;if(G<0)return _;if(O(_,G)<=0)return S[G]=M[_],M[_]=G,_;return S[_]=M[G],M[G]=_,G}e(T,"heapMeld");let Y=e((_)=>{M[_]=-1,S[_]=-1,L=T(L,_),N++},"heapPush"),q=e(()=>{if(L<0)return;let _=L;I.length=0;let G=M[_];while(G>=0){let ut=S[G];S[G]=-1,I.push(G),G=ut}for(let ut=0;ut+1<I.length;ut+=2)I[ut>>>1]=T(I[ut],I[ut+1]);let lt=Math.ceil(I.length/2);if(I.length%2!==0)I[lt-1]=I[I.length-1];L=-1;while(lt>0)L=T(I[--lt],L);return N--,_},"heapPop"),D=0,Q=i.caps?.maxExpandedStates??fr,Ct=i.caps?.maxInvocationExpandedStates??pr,it=i.budget?.expandedStates??d?.expandedStates??0,k=e(()=>{let _=l.estimatedBytes(),G=(i.estimatedBytesBase??0)+_;if(d)d.searchWorkspaceBytes=Math.max(d.searchWorkspaceBytes,_),d.estimatedBytes=Math.max(d.estimatedBytes,G);if(G>(i.caps?.maxEstimatedBytes??Number.POSITIVE_INFINITY))throw new Tt("estimated_memory_cap","Grid routing search workspace memory cap exceeded")},"recordWorkspaceBytes");k();let J=e(()=>{if(i.budget)i.budget.expandedStates+=D;if(d)d.expandedStates+=D},"commitExpandedStates"),ct=i.initialLength??0;u[0]=o,h[0]=we(i.initialOrientation),f[0]=ct,p[0]=0,y[0]=0;let ft=Math.abs(a.point.x-c.point.x),st=Math.abs(a.point.y-c.point.y);if(m[0]=ct+(A?ft+st:0),b[0]=A?An(ft,st,i.initialOrientation,i.targetOrientation):0,g[0]=-1,x[0]=1,w[0]=-1,l.setBest(mr(o,i.initialOrientation),0),Y(0),d)d.maxOpenSet=Math.max(d.maxOpenSet,N);let bt=-1,B,F=e((_)=>{let G=[f[_]+(i.targetLength??0),p[_]+(i.targetOrientation!==void 0&&h[_]!==0&&we(i.targetOrientation)!==h[_]?1:0),y[_],R];if(!B||ie(G,B)<0||ie(G,B)===0&&P(_,bt)<0)bt=_,B=G},"considerGoal"),dt=e((_,G,lt,ut,et,j)=>{let Rt=s(lt).point;if(i.arcAllowed&&!i.arcAllowed(G,Rt))return;if(i.initialSide&&g[_]<0&&On(G,Rt,i.initialSide))return;if(i.targetSide&&lt===r&&On(c.point,G,i.targetSide))return;let fe=lt*3+ut,Pt=E[fe],pe=f[_]+et,ge=p[_]+(h[_]!==0&&h[_]!==ut?1:0),me=y[_]+j,ye=Pt>=0?pe-f[Pt]||ge-p[Pt]||me-y[Pt]:-1;if(Pt>=0&&(ye>0||ye===0&&P(_,g[Pt])>=0))return;let St=v++;if(v>u.length)l.ensureStateCapacity(v),u=l.stateVertices,h=l.orientations,f=l.gLengths,p=l.gBends,y=l.gBoundaryTransitions,m=l.fLengths,b=l.fBends,g=l.predecessors,x=l.depths,w=l.ancestor4,M=l.heapChildren,S=l.heapSiblings,k();u[St]=lt,h[St]=ut,f[St]=pe,p[St]=ge,y[St]=me;let fo=Math.abs(Rt.x-c.point.x),po=Math.abs(Rt.y-c.point.y);m[St]=pe+(A?fo+po:0),b[St]=ge+(A?An(fo,po,ut===1?"H":"V",i.targetOrientation):0),g[St]=_,x[St]=x[_]+1;let go=g[_],mo=go>=0?g[go]:-1;w[St]=mo>=0?g[mo]:-1,l.setBest(fe,St),Y(St)},"relaxArc");while(N>0){let _=L;if(B&&(m[_]-B[0]||b[_]-B[1]||y[_]-B[2]||R-B[3])>0)break;let G=q();if(E[u[G]*3+h[G]]!==G)continue;if(D>=Q||it+D>=Ct){if(bt>=0&&B){if(d&&i.recordOutcome!==!1)d.routesFound++;return J(),Bn(bt,u,g,B,s)}J();let j=it+D>=Ct?"invocation":"edge";throw new Tt("search_state_cap","Grid routing search-state cap exceeded",j)}if(D++,u[G]===r){F(G);continue}let lt=u[G],ut=s(lt).point,et=t.getSearchArcs?.(lt)??t.searchAdjacencyByVertex?.[lt];if(et)for(let j of et)dt(G,ut,j.to,j.orientationOrdinal,j.length,j.boundaryTransitions);else for(let j of t.adjacencyByVertex?.[lt]??t.adjacency.get(lt)??[])dt(G,ut,j.to,we(j.orientation),j.length,j.kind==="portal"?1:0);if(d)d.maxOpenSet=Math.max(d.maxOpenSet,N)}if(bt<0||!B){if(J(),d&&i.recordOutcome!==!1)d.routesImpossible++;return}if(d&&i.recordOutcome!==!1)d.routesFound++;return J(),Bn(bt,u,g,B,s)}e(br,"search");function en(t,o,r,i={}){return br(t,o,r,i)}e(en,"findShortestRoute");var Co="grid-router";function wr(t,o,r,i,s){if(t.metrics)t.metrics.resourceLimitFallbacks++,t.metrics.fallbackReasons[o]++;if(n.debug(Co,"GRID_ROUTING_RESOURCE_FALLBACK",{edgeId:r,containerId:i,reason:o}),o==="search_state_cap"&&s==="invocation"&&!t.searchBudgetWarningEmitted)t.searchBudgetWarningEmitted=!0,n.warn(Co,"GRID_ROUTING_INVOCATION_SEARCH_BUDGET_EXHAUSTED",{edgeId:r,containerId:i,expandedStates:t.searchBudget.expandedStates})}e(wr,"recordFallback");function Qt({context:t,reason:o,edgeId:r,containerId:i,searchStateScope:s,route:a,isValid:c,includeContainerIdInError:d}){let l=a();if(wr(t,o,r,i,s),c(l))return l;if(t.metrics)t.metrics.fallbackValidationFailures++;throw V("GRID_ROUTE_NOT_FOUND",`Invalid legacy fallback for "${r}"`,{edgeId:r,...d?{containerId:i}:{},reason:o})}e(Qt,"runValidatedFallback");function vr(t,o,r,i,s,a,c,d,l,u,h,f,p){let y=d.fallbackContainers.get(t.lcaContainerId);if(y)return Qt({context:d,reason:y,edgeId:t.edge.id,containerId:t.lcaContainerId,route:a,isValid:e((S)=>Bt(S,i,s,t.lcaContainerId,c)&&(t.bundleSize<=1||mt(S,f)),"isValid")});let m=d.topologies.get(t.lcaContainerId);if(!m)throw V("GRID_ROUTE_NOT_FOUND",`Missing routing topology "${t.lcaContainerId}"`);if(o.length===0||r.length===0){if(d.metrics)d.metrics.routesImpossible++;throw V("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 b,g,x=o.flatMap((S)=>r.map((E)=>{let I=S.rank*r.length+E.rank,[v,R]=Ki(S,E);return{sourceCandidate:S,targetCandidate:E,pairRank:I,lowerCost:[v,R,0,I]}})).sort((S,E)=>ie(S.lowerCost,E.lowerCost)||kt(S.sourceCandidate.side)-kt(E.sourceCandidate.side)||kt(S.targetCandidate.side)-kt(E.targetCandidate.side)),w=e((S,E="all")=>{let I=t.bundleSize>1||S?(v,R)=>(t.bundleSize<=1||tn(v,R,f))&&!(S&&p.index.conflictsWithArc(v,R,p.pairKey)):void 0;for(let{sourceCandidate:v,targetCandidate:R,pairRank:A,lowerCost:C}of x){if(E==="preferred"&&A!==0)continue;if(E==="assigned-side"&&(v.onAssignedSide===!1||R.onAssignedSide===!1))continue;if(b&&ie(b.result.cost,C)<=0)break;try{Oe({metrics:d.metrics,caps:h.searchCaps,budget:d.searchBudget});let O=Qe(m,v.connect,R.connect,d.metrics,u,t.bundleSize>1&&(v.connect.x===R.connect.x||v.connect.y===R.connect.y)?[{x:(v.connect.x+R.connect.x)/2,y:(v.connect.y+R.connect.y)/2}]:[]),P=d.baseEstimatedBytes+O.estimatedBytes-m.estimatedBytes;if(P>(h.topologyCaps?.maxEstimatedBytes??jt))throw new Tt("estimated_memory_cap","Grid routing estimated_memory_cap exceeded");if(d.metrics)d.metrics.estimatedBytes=Math.max(d.metrics.estimatedBytes,P);let L=O.pointVertexIds.get(yt(v.connect)),N=O.pointVertexIds.get(yt(R.connect));if(L===void 0||N===void 0)throw V("GRID_ROUTE_NOT_FOUND",`Endpoint projection is missing from the routing overlay for "${t.edge.id}"`,{edgeId:t.edge.id,containerId:t.lcaContainerId,source:v.connect,target:R.connect});let T=v.side==="left"||v.side==="right"?"H":"V",Y=R.side==="left"||R.side==="right"?"H":"V",q=en(O,L,N,{metrics:d.metrics,caps:{...h.searchCaps,maxEstimatedBytes:h.searchCaps?.maxEstimatedBytes??h.topologyCaps?.maxEstimatedBytes??jt},endpointCandidateRank:A,recordOutcome:!1,budget:d.searchBudget,initialOrientation:T,initialLength:Z,targetOrientation:Y,targetLength:Z,topologyValidated:!0,workspace:l,estimatedBytesBase:P,arcAllowed:I});if(!q)continue;let D=H([v.port,...q.points,R.port]).points;if(!Bt(D,i,s,t.lcaContainerId,c))continue;if(t.bundleSize>1&&!mt(D,f))continue;if(S&&p.index.conflictsWithRoute(D,p.pairKey))continue;if(!b||ie(q.cost,b.result.cost)<0)b={result:q,points:D},g=void 0}catch(O){if(!(O instanceof Tt))throw O;if(b)break;g=O;break}}},"searchPairs"),M=p!==void 0&&p.index.size>0;if(p?.prioritizeEndpointCandidates)w(M,"preferred"),w(M,"assigned-side");if(!b)w(M);if(!b&&!g&&p!==void 0&&p.index.size>0)w(!1);if(g)return Qt({context:d,reason:g.reason,edgeId:t.edge.id,containerId:t.lcaContainerId,searchStateScope:g.searchStateScope,route:a,isValid:e((S)=>Bt(S,i,s,t.lcaContainerId,c)&&(t.bundleSize<=1||mt(S,f)),"isValid")});if(!b){if(d.metrics)d.metrics.routesImpossible++;throw V("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(h.onDualRouteComparison){let S=a(),E=H(b.points),I=H(S);h.onDualRouteComparison({edgeId:t.edge.id,sparse:{valid:!0,length:re(E.points),bends:E.bends},legacy:{valid:Bt(S,i,s,t.lcaContainerId,c),length:re(I.points),bends:I.bends}})}return b.points}e(vr,"sparseSameContainerRoute");function Ir(t,o,r){let i=Lt(t,o);if(!i||i.high-i.low<gt)return;let s=z(t),a=(i.low+i.high)/2,c=r*ao,d=[a-gt/2-c,a+gt/2+c];if(d[0]<i.low||d[1]>i.high)return;let l=e((u)=>{let h=o==="left"||o==="right"?{x:o==="left"?s.left:s.right,y:u}:{x:u,y:o==="top"?s.top:s.bottom};return{ownerId:t.id,side:o,port:h,connect:{x:h.x+(o==="left"?-Z:o==="right"?Z:0),y:h.y+(o==="top"?-Z:o==="bottom"?Z:0)},rank:0}},"candidate");return{start:l(d[0]),target:l(d[1])}}e(Ir,"selfLoopAttachments");function Mr(t,o,r,i,s,a,c,d,l,u){let h=o.parentId??X,f=r.labelRequirements.selfLoops.get(t.edge.id),p=i.fallbackContainers.get(h),y=e(()=>or(o,c,d,r,f,i.metrics),"legacyRoute");if(p){let g=Qt({context:i,reason:p,edgeId:t.edge.id,containerId:h,route:y,isValid:e((x)=>Bt(x.points,o,o,h,r)&&mt(x.points,l),"isValid")});if(f&&i.metrics)i.metrics.labelAwareSelfLoopsCommitted++;return g}let m=i.topologies.get(h);if(!m||!a)throw V("GRID_ROUTE_NOT_FOUND",`Missing routing topology "${h}"`);let b=uo(o,c,d);if(f){for(let g of b){let x=d.get(`${o.id}:${g}`)??0,w=z(o),M=g==="left"||g==="right"?w.cy:w.cx,S=lo(o,g,x,M,f);if(i.metrics)i.metrics.labelAwareSelfLoopCandidates+=S.length;for(let E of S)if(Bt(E,o,o,h,r)&&mt(E,l)){if(i.metrics)i.metrics.labelAwareSelfLoopsCommitted++;return{points:E,side:g,index:x}}}if(i.metrics)i.metrics.labelAwareSelfLoopFallbacks++}for(let g of b){let x=d.get(`${o.id}:${g}`)??0,w=Ir(o,g,x);if(!w)continue;let{start:M,target:S}=w;try{Oe({metrics:i.metrics,caps:u.searchCaps,budget:i.searchBudget});let E=Qe(m,M.connect,S.connect,i.metrics,a,[{x:(M.connect.x+S.connect.x)/2,y:(M.connect.y+S.connect.y)/2}]),I=E.pointVertexIds.get(yt(M.connect)),v=E.pointVertexIds.get(yt(S.connect));if(I===void 0||v===void 0)throw V("GRID_ROUTE_NOT_FOUND",`Self-loop endpoint projection is missing from the routing overlay for "${t.edge.id}"`,{edgeId:t.edge.id,containerId:h,source:M.connect,target:S.connect,side:g});let R=g==="left"||g==="right"?"H":"V",A=en(E,I,v,{metrics:i.metrics,caps:{...u.searchCaps,maxEstimatedBytes:u.searchCaps?.maxEstimatedBytes??u.topologyCaps?.maxEstimatedBytes??jt},recordOutcome:!1,budget:i.searchBudget,initialOrientation:R,initialSide:g,initialLength:Z,targetOrientation:R,targetSide:g,targetLength:Z,topologyValidated:!0,workspace:s,estimatedBytesBase:i.baseEstimatedBytes+E.estimatedBytes-m.estimatedBytes,arcAllowed:e((O,P)=>tn(O,P,l),"arcAllowed")});if(!A)continue;let C=H([M.port,...A.points,S.port]).points;if(Bt(C,o,o,h,r)&&mt(C,l))return{points:C,side:g,index:x}}catch(E){if(!(E instanceof Tt))throw E;let I=Qt({context:i,reason:E.reason,edgeId:t.edge.id,containerId:h,searchStateScope:E.searchStateScope,route:y,isValid:e((v)=>Bt(v.points,o,o,h,r)&&mt(v.points,l),"isValid")});if(f&&i.metrics)i.metrics.labelAwareSelfLoopsCommitted++;return I}}if(i.metrics)i.metrics.routesImpossible++;throw V("GRID_ROUTE_NOT_FOUND",`No distinct self-loop route for "${t.edge.id}"`,{edgeId:t.edge.id,nodeId:o.id})}e(Mr,"sparseSelfLoopRoute");function Ln(t,o,r,i,s,a,c,d,l,u,h=[],f=()=>[],p=()=>[],y=!1,m){let b=c.fallbackContainers.get(o);if(b)return Qt({context:c,reason:b,edgeId:t,containerId:o,route:s,isValid:e((I)=>$t(I,r.ownerId,i.ownerId,o,a)&&mt(I,h),"isValid"),includeContainerIdInError:!0});let g=c.topologies.get(o);if(!g||!l)throw V("GRID_ROUTE_NOT_FOUND",`Missing routing topology "${o}"`);let x=[{start:r,end:i,select:[]}],w=!1,M=e(()=>{if(w)return;w=!0;let I=p(),v=f();x.push(...v.map((R)=>({start:r,end:R.attachment,select:[R.select]})),...I.map((R)=>({start:R.attachment,end:i,select:[R.select]})),...I.flatMap((R)=>v.map((A)=>({start:R.attachment,end:A.attachment,select:[R.select,A.select]}))))},"appendAlternatives"),S=m!==void 0&&m.index.size>0?[!0,!1]:[!1];try{for(let I of S)for(let[v,R]of x.entries()){let{start:A,end:C}=R;if(v>0&&c.metrics)c.metrics.hierarchyPortalAlternativeAttempts++;if(qi(A.connect,C.connect)){let D=H([A.port,A.connect,C.connect,C.port]).points;if($t(D,A.ownerId,C.ownerId,o,a)&&mt(D,h)&&!(I&&m.index.conflictsWithRoute(D,m.pairKey))){for(let Q of R.select)Q();if(v>0&&c.metrics)c.metrics.hierarchyPortalAlternativeSelections++;return D}}Oe({metrics:c.metrics,caps:u.searchCaps,budget:c.searchBudget});let P=Qe(g,A.connect,C.connect,c.metrics,l),L=c.baseEstimatedBytes+P.estimatedBytes-g.estimatedBytes;if(L>(u.topologyCaps?.maxEstimatedBytes??jt))throw new Tt("estimated_memory_cap","Grid routing estimated_memory_cap exceeded");let N=P.pointVertexIds.get(yt(A.connect)),T=P.pointVertexIds.get(yt(C.connect));if(N===void 0||T===void 0){if(v===0)M();continue}let Y=en(P,N,T,{metrics:c.metrics,caps:{...u.searchCaps,maxEstimatedBytes:u.searchCaps?.maxEstimatedBytes??u.topologyCaps?.maxEstimatedBytes??jt},recordOutcome:!1,budget:c.searchBudget,initialOrientation:A.side==="left"||A.side==="right"?"H":"V",initialSide:A.side,initialLength:Math.abs(A.port.x-A.connect.x)+Math.abs(A.port.y-A.connect.y),targetOrientation:C.side==="left"||C.side==="right"?"H":"V",targetSide:C.side,targetLength:Math.abs(C.port.x-C.connect.x)+Math.abs(C.port.y-C.connect.y),topologyValidated:!0,workspace:d,estimatedBytesBase:L,arcAllowed:h.length>0||I?(D,Q)=>(h.length===0||tn(D,Q,h))&&!(I&&m.index.conflictsWithArc(D,Q,m.pairKey)):void 0});if(!Y){if(v===0)M();continue}let q=H([A.port,...Y.points,C.port]).points;if(!$t(q,A.ownerId,C.ownerId,o,a)||!mt(q,h)||I&&m.index.conflictsWithRoute(q,m.pairKey)){if(v===0)M();continue}for(let D of R.select)D();if(v>0&&c.metrics)c.metrics.hierarchyPortalAlternativeSelections++;return q}}catch(I){if(!(I instanceof Tt))throw I;return Qt({context:c,reason:I.reason,edgeId:t,containerId:o,searchStateScope:I.searchStateScope,route:s,isValid:e((v)=>$t(v,r.ownerId,i.ownerId,o,a)&&mt(v,h),"isValid"),includeContainerIdInError:!0})}let E=s();if($t(E,r.ownerId,i.ownerId,o,a)&&(mt(E,h)||y&&so(E,h))){if(c.metrics)c.metrics.compatibilitySegments++,c.metrics.compatibilityRecoveries++;return E}throw V("GRID_ROUTE_NOT_FOUND",`No hierarchy route for "${t}" in "${o}" from ${yt(r.connect)} to ${yt(i.connect)}`,{edgeId:t,containerId:o})}e(Ln,"sparseContainerSegment");function Cr(t,o,r,i,s,a,c){let d=t[0].pairKey,l=o.get(d),u=[...new Set(t.flatMap((y)=>[...y.source.chain,...y.target.chain].map(({demandKey:m})=>m)))],h=new Map,f=new Map;for(let y of u){let m=r.get(y);if(m)h.set(y,m);let b=i.get(y);if(b!==void 0)f.set(y,b)}let p=c.get(t[0].lcaContainerId);return{pairKey:d,occupancy:p?{index:p,size:p.size}:void 0,pairRoutes:l?[...l]:void 0,demandKeys:u,pairedPortals:h,demandCoords:f,edges:t.map(({edge:y})=>({edge:y,points:y.points,curve:y.curve,cornerRadius:y.cornerRadius})),instrumentedRoutesLength:s?.length,metrics:a?lr(a):void 0}}e(Cr,"createBundleCheckpoint");function Sr(t,o,r,i,s,a){if(t.occupancy?.index.truncate(t.occupancy.size),t.pairRoutes)o.set(t.pairKey,[...t.pairRoutes]);else o.delete(t.pairKey);for(let c of t.demandKeys){let d=t.pairedPortals.get(c);if(d)r.set(c,d);else r.delete(c);let l=t.demandCoords.get(c);if(l!==void 0)i.set(c,l);else i.delete(c)}for(let c of t.edges)c.edge.points=c.points,c.edge.curve=c.curve,c.edge.cornerRadius=c.cornerRadius;if(s&&t.instrumentedRoutesLength!==void 0)s.length=t.instrumentedRoutesLength;if(a&&t.metrics)ur(a,t.metrics)}e(Sr,"restoreBundleCheckpoint");var es=class{constructor(t,o,r,i){this.layout=t,this.result=o,this.metrics=r,this.options=i,this.searchWorkspace=new gr,this.pairedPortals=new Map,this.ownerSideCounts=new Map,this.selfLoopCounts=new Map,this.pairRoutes=new Map,this.routed=!1}static{e(this,"GridEdgeRoutingSession")}route(){if(this.routed)throw Error("Grid edge routing session can only be run once");this.routed=!0,this.prepare();let t=new Map;for(let o of this.prepared.orderedPlans){let r=t.get(o.pairKey)??[];r.push(o),t.set(o.pairKey,r)}for(let o of t.values())this.routeBundle(o)}prepare(){ir(this.result),this.prepared=Vi(this.layout,this.result),this.modes=dr(this.prepared,this.result,this.metrics,this.options),this.routingContext=ar(this.modes.routedContainerIds,this.result,this.metrics,this.options),this.endpointOverlayScratch=new Map([...this.routingContext.topologies].map(([o,r])=>[o,new Ri(r)])),this.instrumentedRoutes=this.metrics?[]:void 0;let t=new Set;for(let o of this.prepared.orderedPlans){if(o.edge.start===o.edge.end)continue;for(let r of[...o.source.chain,...o.target.chain]){if(t.has(r.demandKey))continue;t.add(r.demandKey);let i=ae(r.ownerId,r.side);this.ownerSideCounts.set(i,(this.ownerSideCounts.get(i)??0)+1)}}}pairedPortal(t){let o=this.pairedPortals.get(t.demandKey);if(o)return o;let r=this.result.forest.nodeById.get(t.ownerId);if(!r?.isGroup)throw V("GRID_ROUTE_NOT_FOUND",`Missing portal owner "${t.ownerId}"`);let i=Ft(r),s=this.prepared.demandCoords.get(t.demandKey)??(t.side==="left"||t.side==="right"?(i.top+i.bottom)/2:(i.left+i.right)/2),a=se(t.ownerId,i,r.groupTitleRect).find(({side:d})=>d===t.side);if(!a)throw V("GRID_ROUTE_NOT_FOUND",`No legal ${t.side} portal for "${t.ownerId}"`);let c=mn(t.ownerId,i,r.groupTitleRect?{...r.groupTitleRect}:void 0,t.side,Gt(s,a.low,a.high));if(this.pairedPortals.set(t.demandKey,c),this.metrics)this.metrics.hierarchyPortalPairs++,this.metrics.hierarchyPortalTransitionLength+=c.transition.length;return c}alternativePairedPortals(t,o=!0){let r=this.pairedPortal(t),i=this.result.forest.nodeById.get(t.ownerId);if(!i?.isGroup)return[];let s=Ft(i),a=se(t.ownerId,s,i.groupTitleRect).find(({side:l})=>l===t.side);if(!a)return[];let c=this.result.containers.get(i.id),d=t.side==="left"||t.side==="right"?c?.horizontalCorridors:c?.verticalCorridors;return Yi(r.tangentialCoordinate,a.low,a.high,d??[]).map((l)=>{let u=mn(t.ownerId,s,i.groupTitleRect?{...i.groupTitleRect}:void 0,t.side,l);return{attachment:Jt(u,o),select:e(()=>{this.pairedPortals.set(t.demandKey,u),this.prepared.demandCoords.set(t.demandKey,l)},"select")}})}itemSegmentAttachment(t,o){return{ownerId:t.ownerId,...Ee(t.ownerId,t.side,t.demandKey,o,this.result,this.prepared.demandCoords)}}alternativeItemAttachments(t,o,r){let i=this.itemSegmentAttachment(o,r),s=this.result.forest.nodeById.get(o.ownerId);if(!s)return[];return["right","bottom","left","top"].filter((a)=>a!==i.side&&!(a==="top"&&Ze(s))).map((a)=>{let c=Lt(s,a);if(!c)return;let d=z(s),l=a==="left"||a==="right"?d.cy:d.cx,u=Math.max(c.low,Math.min(c.high,l+t.laneOffset));return{ownerId:o.ownerId,...Ee(o.ownerId,a,o.demandKey,r,this.result,this.prepared.demandCoords,u)}}).filter((a)=>a!==void 0).slice(0,3).map((a)=>({attachment:a,select:e(()=>{return},"select")}))}routePlan(t,o=!0){let r=this.result,i=this.routingContext,s=this.searchWorkspace,a=this.endpointOverlayScratch,c=this.prepared.demandCoords,d=this.ownerSideCounts,l=this.selfLoopCounts,u=this.pairRoutes,h=this.instrumentedRoutes,f=this.metrics,p=this.options,y=this.prepared.eligibleIds,m=this.prepared.endpointCandidatesByEdge,b=this.modes.compatibilityFastRoutes,g=this.modes.sparseHierarchyIds,x=this.modes.sparseLcaIds,w=t.edge,M=w.start?r.forest.nodeById.get(w.start):void 0,S=w.end?r.forest.nodeById.get(w.end):void 0;if(!M||!S)throw V("GRID_MISSING_ENDPOINT",`Missing endpoint for edge "${w.id}"`,{edgeId:w.id});if(M.id===S.id){let k=u.get(t.pairKey)??[],{points:J,side:ct,index:ft}=Mr(t,M,r,i,s,a.get(M.parentId??X),d,l,k,p),st=`${M.id}:${ct}`;if(l.set(st,ft+1),w.points=J,w.curve=r.config.curve,w.cornerRadius=r.config.edgeCornerRadius,k.push(J),u.set(t.pairKey,k),f&&h)Rn(f,w.id,J,h,0,t.laneOffset),h.push(J);return}let E=t.source.chain[t.source.chain.length-1],I=t.target.chain[t.target.chain.length-1],v=x.has(w.id),R=v?void 0:Re(t,r,c),A=R?R.start:t.source.finalKind==="boundary"?Mn(E.ownerId,E.side,E.demandKey,r,c):t.source.chain.length>1?Jt(this.pairedPortal(E),!1):this.itemSegmentAttachment(E,t.lcaContainerId),C=R?R.end:t.target.finalKind==="boundary"?Mn(I.ownerId,I.side,I.demandKey,r,c):t.target.chain.length>1?Jt(this.pairedPortal(I),!1):this.itemSegmentAttachment(I,t.lcaContainerId),O,P=e(()=>O??=qt(t.lcaContainerId,r,A,C,t.laneIndex),"legacyRoute"),L=b.get(w.id),N=L?(()=>{if(f)f.compatibilityFastPaths++;return L})():y.has(w.id)?vr(t,m.get(w.id).sources,m.get(w.id).targets,M,S,P,r,i,s,a.get(t.lcaContainerId),p,u.get(t.pairKey)??[],{index:this.occupancyFor(t.lcaContainerId),pairKey:t.pairKey,prioritizeEndpointCandidates:this.prepared.coordinatedEndpointIds.has(w.id)}):v?Ln(w.id,t.lcaContainerId,A,C,P,r,i,s,a.get(t.lcaContainerId),p,u.get(t.pairKey)??[],()=>t.target.finalKind==="item"&&t.target.chain.length>1?this.alternativePairedPortals(I,!1):[],()=>t.source.finalKind==="item"&&t.source.chain.length>1?this.alternativePairedPortals(E,!1):[],t.bundleSize>1,this.modes.overlapAvoidanceEnabled?{index:this.occupancyFor(t.lcaContainerId),pairKey:t.pairKey}:void 0):Sn(w.id,t.lcaContainerId,A,C,P,r,f),T=e((k,J)=>{if(!g.has(w.id)){for(let{containerId:ct,start:ft,end:st}of ho(k,r,c))J.push(Sn(w.id,ct,ft,st,()=>qt(ct,r,ft,st,t.laneIndex),r,f));return}for(let ct=0;ct<k.chain.length-1;ct++){let ft=k.chain[ct],st=k.chain[ct+1],bt=ct===0?this.itemSegmentAttachment(ft,st.ownerId):Jt(this.pairedPortal(ft),!1),B=Jt(this.pairedPortal(st),!0);J.push(Ln(w.id,st.ownerId,bt,B,()=>qt(st.ownerId,r,bt,B,t.laneIndex),r,i,s,a.get(st.ownerId),p,u.get(t.pairKey)??[],()=>this.alternativePairedPortals(st),()=>ct===0?this.alternativeItemAttachments(t,ft,st.ownerId):[],t.bundleSize>1))}},"routeHierarchyChain"),Y=[],q=[];T(t.source,Y),T(t.target,q);let D=tr([...Y,N,...q.reverse().map((k)=>Ji(k))]),Q=u.get(t.pairKey)??[],Ct=mt(D,Q),it=!Ct&&t.bundleSize>1&&t.source.chain.length+t.target.chain.length>2&&so(D,Q);if(t.bundleSize>1&&!Ct&&(!it||!o)){if(f)f.routesImpossible++;throw V("GRID_ROUTE_NOT_FOUND",`No distinct lane route for "${w.id}"`,{edgeId:w.id,reason:it?"pair-separation":"no-distinct-route"})}if(it&&f)f.bundleSeparationRelaxations++;if(w.points=D,w.curve=r.config.curve,w.cornerRadius=r.config.edgeCornerRadius,Q.push(D),u.set(t.pairKey,Q),!L)this.occupancyFor(t.lcaContainerId).add(N,t.pairKey);if(f&&h){let k=t.source.chain.length+t.target.chain.length-2;Rn(f,w.id,D,h,k,t.laneOffset),h.push(D)}}occupancyFor(t){let o=this.modes.routeOccupancy.get(t);if(!o)o=new In,this.modes.routeOccupancy.set(t,o);return o}createBundleCheckpoint(t){return this.occupancyFor(t[0].lcaContainerId),Cr(t,this.pairRoutes,this.pairedPortals,this.prepared.demandCoords,this.instrumentedRoutes,this.metrics,this.modes.routeOccupancy)}restoreBundleCheckpoint(t){Sr(t,this.pairRoutes,this.pairedPortals,this.prepared.demandCoords,this.instrumentedRoutes,this.metrics)}routeBundle(t){if(!(t.length>1&&t.length<=8&&t.every(({edge:s})=>s.start!==s.end))){for(let s of t)this.routePlan(s);return}let r=this.createBundleCheckpoint(t),i;try{for(let s of t)this.routePlan(s,!1);return}catch(s){i=s,this.restoreBundleCheckpoint(r)}if(!$i(i))throw i;for(let s of t)this.routePlan(s)}};function Er(t,o,r,i={}){new es(t,o,r,i).route()}e(Er,"routeGridEdges");var ns=24,Le=20;function Rr(t,o){if(!t.label||!t.labelBBox||!(t.labelBBox.height>0))return 0;return t.labelBBox.height+o}e(Rr,"titleBandFor");function Ar(t){if(!tt(t.width)||!tt(t.height))throw V("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})}e(Ar,"ensureMeasuredNode");function Pn(t){return Ar(t),{width:t.width,height:t.height}}e(Pn,"measureChild");function _n(t,o,r,i,s){let{forest:a,config:c,sourceOrder:d}=o,l=t===X?void 0:a.groupById.get(t),u=l?Math.max(l.padding??0,c.containerPadding):0,h=l?Rr(l,c.titleGap):0,f=l?ns:0,p=l?u+h+f:0,y=(a.childrenByParent.get(t)??[]).filter((B)=>!xt(B)),{cells:m}=Si(y,d,c),b=[...m.values()].sort((B,F)=>B.row-F.row||B.column-F.column),g=new Map,x=new Map,w=new Set,M=new Set;for(let B of b){let F=0,dt=0;for(let _ of B.items){let G=Pn(_.item);F=Math.max(F,G.width),dt+=G.height}if(B.items.length>1)dt+=c.cellGap*(B.items.length-1);B.width=F,B.height=dt,w.add(B.row),M.add(B.column),g.set(B.column,Math.max(g.get(B.column)??0,F)),x.set(B.row,Math.max(x.get(B.row)??0,dt))}let S=[...w].sort((B,F)=>B-F),E=[...M].sort((B,F)=>B-F),I=mi(o.labelRequirements.byContainer.get(t)??[],m,x,g,S,E,c.rowGap,c.columnGap,s),v=e((B)=>Math.max(c.rowGap,I.rowGapAfter.get(B)??0),"rowGapAfter"),R=e((B)=>Math.max(c.columnGap,I.columnGapAfter.get(B)??0),"columnGapAfter");if(s){for(let B of I.rowGapAfter.values())if(B>c.rowGap)s.labelSpacingBoundariesExpanded++,s.labelSpacingPixelsAdded+=B-c.rowGap;for(let B of I.columnGapAfter.values())if(B>c.columnGap)s.labelSpacingBoundariesExpanded++,s.labelSpacingPixelsAdded+=B-c.columnGap}let A=E.reduce((B,F,dt)=>B+(g.get(F)??0)+(dt<E.length-1?R(F):0),0),C=l?Math.max(A+(u+f)*2,(l.labelBBox?.width??0)+u*2):A,O=l?(C-A)/2:0,P=new Map,L=O;for(let[B,F]of E.entries())P.set(F,L),L+=(g.get(F)??0)+(B<E.length-1?R(F):0);let N=new Map,T=p;for(let[B,F]of S.entries())N.set(F,T),T+=(x.get(F)??0)+(B<S.length-1?v(F):0);let Y=S.length?T-p:0,q=l?O-Le:-Math.max(c.columnGap/2,vt.containerPadding),D=l?O+A+Le:O+A+Math.max(c.columnGap/2,vt.containerPadding),Q=l?p-Le:-Math.max(c.rowGap/2,vt.containerPadding),Ct=l?p+Y+Le:p+Y+Math.max(c.rowGap/2,vt.containerPadding),it=new Set([q,D]),k=new Set([Q,Ct]),J=new Map,ct=new Map,ft=new Map,st=new Map;if(E.length>0)J.set(E[0],q),ct.set(E.at(-1),D);for(let B=0;B<E.length-1;B++){let F=E[B],dt=E[B+1],_=(P.get(F)+(g.get(F)??0)+P.get(dt))/2;it.add(_),ct.set(F,_),J.set(dt,_)}if(S.length>0)ft.set(S[0],Q),st.set(S.at(-1),Ct);for(let B=0;B<S.length-1;B++){let F=S[B],dt=S[B+1],_=(N.get(F)+(x.get(F)??0)+N.get(dt))/2;k.add(_),st.set(F,_),ft.set(dt,_)}for(let B of b){let F=P.get(B.column)??O,dt=N.get(B.row)??p,_=g.get(B.column)??B.width,G=x.get(B.row)??B.height,lt=B.verticalAlign==="top"?0:B.verticalAlign==="bottom"?1:0.5,et=dt+(G-B.height)*lt;for(let[j,Rt]of B.items.entries()){let{width:fe,height:Pt}=Pn(Rt.item),pe=Rt.horizontalAlign==="left"?0:Rt.horizontalAlign==="right"?1:0.5,ge=F+(_-fe)*pe;Rt.item.x=ge+fe/2,Rt.item.y=et+Pt/2;let me=j>0?et-c.cellGap/2:ft.get(B.row)??Q,ye=j<B.items.length-1?et+Pt+c.cellGap/2:st.get(B.row)??Ct;if(j>0)k.add(me);if(j<B.items.length-1)k.add(ye);i.set(Rt.item.id,{containerId:t,row:B.row,column:B.column,cellLeft:F,cellTop:dt,cellWidth:_,cellHeight:G,leftCorridorX:J.get(B.column)??q,rightCorridorX:ct.get(B.column)??D,topCorridorY:me,bottomCorridorY:ye}),et+=Pt+c.cellGap}}let bt=l?Y+h+(u+f)*2:Y;if(r.set(t,{id:t,left:0,top:0,width:C,height:bt,contentLeft:O,contentTop:p,contentRight:l?O+A:A,contentBottom:l?p+Y:Y,verticalCorridors:[...it].sort((B,F)=>B-F),horizontalCorridors:[...k].sort((B,F)=>B-F)}),l)if(l.width=C,l.height=bt,l.x=C/2,l.y=bt/2,h>0)l.groupTitleRect={left:0,right:C,top:0,bottom:u+h};else delete l.groupTitleRect}e(_n,"layoutContainer");function Or(t,o,r){return{left:t.left+o,right:t.right+o,top:t.top+r,bottom:t.bottom+r}}e(Or,"translateRect");function Br(t){let{forest:o,containers:r,itemMeta:i}=t,s=[{containerId:X,offsetX:0,offsetY:0,children:o.childrenByParent.get(X)??[],nextChildIndex:0,entered:!1}];while(s.length>0){let a=s[s.length-1];if(!a.entered){a.entered=!0;let l=r.get(a.containerId);if(l)l.left+=a.offsetX,l.top+=a.offsetY,l.contentLeft+=a.offsetX,l.contentRight+=a.offsetX,l.contentTop+=a.offsetY,l.contentBottom+=a.offsetY,l.verticalCorridors=l.verticalCorridors.map((u)=>u+a.offsetX),l.horizontalCorridors=l.horizontalCorridors.map((u)=>u+a.offsetY)}let c=a.children[a.nextChildIndex];if(!c){s.pop();continue}if(a.nextChildIndex+=1,xt(c))continue;let d=i.get(c.id);if(d)d.cellLeft+=a.offsetX,d.cellTop+=a.offsetY,d.leftCorridorX+=a.offsetX,d.rightCorridorX+=a.offsetX,d.topCorridorY+=a.offsetY,d.bottomCorridorY+=a.offsetY;if(c.x=(c.x??0)+a.offsetX,c.y=(c.y??0)+a.offsetY,!c.isGroup)continue;if(c.groupTitleRect)c.groupTitleRect=Or(c.groupTitleRect,c.x-(c.width??0)/2,c.y-(c.height??0)/2);s.push({containerId:c.id,offsetX:c.x-(c.width??0)/2,offsetY:c.y-(c.height??0)/2,children:o.childrenByParent.get(c.id)??[],nextChildIndex:0,entered:!1})}}e(Br,"materializeAbsoluteGeometry");function Pr(t,o){let r=new Map(t.nodes.map((s)=>[s.id,s]));for(let s of o.nodes){let a=r.get(s.id);if(!a)continue;if(s.x=a.x,s.y=a.y,s.width=a.width,s.height=a.height,a.groupTitleRect)s.groupTitleRect={...a.groupTitleRect};else delete s.groupTitleRect}let i=new Map(t.edges.map((s)=>[s.id,s]));for(let s of o.edges){let a=i.get(s.id);if(!a)continue;s.points=a.points?.map((c)=>({...c})),s.curve=a.curve,s.cornerRadius=a.cornerRadius,s.portClipping="outline-orthogonal",s.skipCornerFix=a.curve==="linear"}}e(Pr,"commitGridGeometry");function _r(t){return{...t,nodes:t.nodes.map((o)=>({...o,labelBBox:o.labelBBox?{...o.labelBBox}:o.labelBBox,groupTitleRect:o.groupTitleRect?{...o.groupTitleRect}:o.groupTitleRect})),edges:t.edges.map((o)=>({...o,points:o.points?.map((r)=>({...r}))}))}}e(_r,"cloneGridLayoutData");function Gr(t,o){let r=new Map(o.map((a)=>[a.id,a])),i=e((a)=>{let c=r.get(a.id);if(!c)throw Error(`Missing committed grid node "${a.id}"`);return c},"originalNode"),s=e((a)=>{let c=i(a);if(!c.isGroup)throw Error(`Committed grid node "${a.id}" is no longer a group`);return c},"originalGroup");return{nodeById:r,groupById:new Map([...t.groupById].map(([a,c])=>[a,s(c)])),childrenByParent:new Map([...t.childrenByParent].map(([a,c])=>[a,c.map(i)])),rootChildren:t.rootChildren.map(i),postOrderGroups:t.postOrderGroups.map(s),helperNodeIds:new Set(t.helperNodeIds)}}e(Gr,"rebindGridForest");function Tr(t,o){let r=hi(t.nodes),i=xi(t),s=yi(t.nodes.filter((c)=>!xt(c)));bi(t.nodes.filter((c)=>!xt(c)),i);let a={forest:r,config:i,containers:new Map,itemMeta:new Map,sourceOrder:s,labelRequirements:fi(t,r,o.metrics)};for(let c of r.postOrderGroups)_n(c.id,a,a.containers,a.itemMeta,o.metrics);return _n(X,a,a.containers,a.itemMeta,o.metrics),Br(a),Er(t,a,o.metrics,o.routing),ui(t,void 0,o.metrics),a}e(Tr,"runGridLayoutCoreInPlace");function Nr(t,o={}){let r=t,i=_r(r),s=Tr(i,o);return Pr(i,r),{...s,forest:Gr(s.forest,r.nodes)}}e(Nr,"runGridLayoutCore");function Fr(t,{measure:o}){let r=Mt(t.config.grid?.lineHops);if(r===!1)return;let i=t.edges.filter((s)=>Array.isArray(s.points)&&s.points.length>=2).map((s)=>({id:s.id,points:s.points,curve:s.curve,cornerRadius:s.cornerRadius,arrowTypeStart:s.arrowTypeStart,arrowTypeEnd:s.arrowTypeEnd}));Nt(o.groups.edgePaths,i,{enabled:!0,jumpRadius:6,jumpStyle:r})}e(Fr,"applyGridLineJumps");var ys=ot({prepareLayout:li,runLayoutCore:e((t)=>Nr(t),"runLayoutCore"),afterPaint:Fr});export{li as prepareGridLayout,ys as render,Nr as runGridLayoutCore};
1
+ import{e,n,Ea,Aa,Lr,Es,Qr}from"./index.a1bxkgd3.js";import{Mt,Nt}from"./index.fbeztcp3.js";import"./index.wrjdgn4c.js";import{ot}from"./index.hvdnkr5m.js";var rt=1;function So(t,o,r=rt){let i=Math.abs(o.x-t.x),s=Math.abs(o.y-t.y);if(i<=r&&s<=r)return"Z";if(s<=r)return"H";return"V"}e(So,"segmentOrientation");function Eo(t,o=rt){let r=[];for(let i=0;i<t.length-1;i++){let s=t[i],a=t[i+1];r.push({a:s,b:a,orientation:So(s,a,o)})}return r}e(Eo,"segmentsFromPoints");function Ro(t,o=rt){if(t.length===0)return[];let r=[],i={...t[0]};for(let s=1;s<t.length;s++){let a=t[s];if(a.orientation==="Z")continue;if(i.orientation==="Z"){i={...a};continue}if(i.orientation===a.orientation){if(i.orientation==="H"&&Math.abs(i.b.y-a.a.y)<=o&&Math.abs(i.a.y-a.a.y)<=o){i.b=a.b;continue}if(i.orientation==="V"&&Math.abs(i.b.x-a.a.x)<=o&&Math.abs(i.a.x-a.a.x)<=o){i.b=a.b;continue}}if(i.orientation!=="Z")r.push(i);i={...a}}if(i.orientation!=="Z")r.push(i);return r}e(Ro,"mergeCollinear");function H(t,o=rt){if(t.length<2)return{points:[...t],segments:[],bends:0};let r=Eo(t,o).filter((c)=>c.orientation!=="Z"),i=Ro(r,o),s=[];for(let[c,d]of i.entries()){if(c===0)s.push(d.a);s.push(d.b)}let a=0;for(let c=1;c<i.length;c++)if(i[c-1].orientation!==i[c].orientation)a++;return{points:s.length>0?s:[...t],segments:i,bends:a}}e(H,"normalizePolyline");function Gn(t,o){if(t.orientation==="Z"||o.orientation==="Z")return!1;if(t.orientation===o.orientation)return!1;let r=t.orientation==="H"?t:o,i=t.orientation==="V"?t:o,s=r.a.y,a=Math.min(r.a.x,r.b.x),c=Math.max(r.a.x,r.b.x),d=i.a.x,l=Math.min(i.a.y,i.b.y),u=Math.max(i.a.y,i.b.y);if(d>=a&&d<=c&&s>=l&&s<=u){let f=d,p=s,y=Math.abs(f-r.a.x)<0.000001&&Math.abs(p-r.a.y)<0.000001||Math.abs(f-r.b.x)<0.000001&&Math.abs(p-r.b.y)<0.000001,m=Math.abs(f-i.a.x)<0.000001&&Math.abs(p-i.a.y)<0.000001||Math.abs(f-i.b.x)<0.000001&&Math.abs(p-i.b.y)<0.000001;if(y&&m)return!1;return!0}return!1}e(Gn,"segmentsCross");function W(t,o){return t<o?-1:t>o?1:0}e(W,"compareCodeUnits");function z(t){let o=t.x??0,r=t.y??0,i=t.width??40,s=t.height??40;return{cx:o,cy:r,left:o-i/2,right:o+i/2,top:r-s/2,bottom:r+s/2}}e(z,"rectForNode");function Ao(t,o,r,i,s=0){if(t.length<2)return null;let a=o==="end"?t[t.length-1]:t[0],c=o==="end"?t[t.length-2]:t[1],d=c.x-a.x,l=c.y-a.y;if(Math.abs(d)<=s&&Math.abs(l)<=s)return null;if(Math.abs(l)<=s){let u=a.x+Math.sign(d)*r,h=Math.min(a.x,u),f=Math.max(a.x,u);return{cx:(h+f)/2,cy:a.y,left:h,right:f,top:a.y-i,bottom:a.y+i}}if(Math.abs(d)<=s){let u=a.y+Math.sign(l)*r,h=Math.min(a.y,u),f=Math.max(a.y,u);return{cx:a.x,cy:(h+f)/2,left:a.x-i,right:a.x+i,top:h,bottom:f}}return null}e(Ao,"terminalMarkerClearanceRect");function Oo(t,o){let r=o==="start"?t.arrowTypeStart:t.arrowTypeEnd;if(typeof r==="string"){let i=r.trim();if(i.length>0)return i!=="none"&&i!=="arrow_open"}if(typeof t.type!=="string")return!1;if(o==="start"&&t.type.startsWith("double_"))return!0;return o==="end"&&/arrow_(point|cross|circle|barb)|double_arrow/.test(t.type)}e(Oo,"hasTerminalMarker");function Xt(t,o,r=0.000001){return Math.abs(t-o)<=r}e(Xt,"approxEqual");function Bo(t,o,r=0.000001){for(let i=1;i<t.length;i++){let s=t[i-1],a=t[i];if(Xt(s.y,a.y,r)&&!Xt(s.x,a.x,r)){if(Xt(o.y,s.y,r)&&o.x>=Math.min(s.x,a.x)-r&&o.x<=Math.max(s.x,a.x)+r)return!0}else if(Xt(s.x,a.x,r)&&!Xt(s.y,a.y,r)){if(Xt(o.x,s.x,r)&&o.y>=Math.min(s.y,a.y)-r&&o.y<=Math.max(s.y,a.y)+r)return!0}}return!1}e(Bo,"orthogonalPolylineContainsPoint");function re(t){let o=0;for(let r=1;r<t.length;r++){let i=t[r-1],s=t[r];o+=Math.abs(s.x-i.x)+Math.abs(s.y-i.y)}return o}e(re,"manhattanLength");function Vt(t,o,r){if(t.x===o.x&&t.y===o.y)return!1;if(t.y===o.y){let i=t.y,s=Math.min(t.x,o.x),a=Math.max(t.x,o.x),c=i>=r.top&&i<=r.bottom,d=Math.max(s,r.left)<Math.min(a,r.right);return c&&d}if(t.x===o.x){let i=t.x,s=Math.min(t.y,o.y),a=Math.max(t.y,o.y),c=i>=r.left&&i<=r.right,d=Math.max(s,r.top)<Math.min(a,r.bottom);return c&&d}return!1}e(Vt,"segmentIntersectsRectInterior");function It(t,o){for(let r=1;r<t.length;r++)if(Vt(t[r-1],t[r],o))return!0;return!1}e(It,"polylineIntersectsRect");function Gt(t,o,r){return Math.max(o,Math.min(r,t))}e(Gt,"clamp");var X="__grid_root__",Dr="edge-label-";function V(t,o,r){let i=Error(`${t}: ${o}`);return i.code=t,i.details=r,i}e(V,"gridError");var vt={columns:0,rowGap:50,columnGap:50,cellGap:20,containerPadding:20,titleGap:8,horizontalAlign:"center",verticalAlign:"center",curve:"rounded",edgeCornerRadius:Es};function xt(t){return Boolean(t.isEdgeLabel)}e(xt,"isEdgeLabelNode");function tt(t){return typeof t==="number"&&Number.isFinite(t)&&t>0}e(tt,"isFinitePositiveNumber");var Wt=6,nn=12,Lo=2;function Tn(t,o){if(!tt(t.width)||!tt(t.height))return null;let r=o==="H"?t.width:t.height,i=o==="H"?t.height:t.width,s=Math.max(Wt,nn),a=Math.max(Wt,nn);return{along:r,cross:i,startInset:s,endInset:a,requiredAlongSpan:r+s+a+Lo}}e(Tn,"gridLabelSpanRequirement");function Po(t,o){let r=o==="H"?t.width:t.height;return tt(r)?r+Wt*2:0}e(Po,"gridLabelRequiredSegmentLength");var pt=Wt,at=14,kr=18,zr=16,_o=128,Hr=64,yo=2000000,Nn=nn,nt=0.000001,Vr=7,$r=8,ht=e((t)=>H(t,nt),"normalizePolyline");function on(t,o,r,i){let s=Math.max(Math.min(t,o),Math.min(r,i)),a=Math.min(Math.max(t,o),Math.max(r,i));return Math.max(0,a-s)}e(on,"rangeOverlapLength");function Fn(t){let o=ht([...t]).segments;for(let r=0;r<o.length;r++){let i=o[r];for(let s=r+2;s<o.length;s++){let a=o[s];if(Gn(i,a))return!0;if(i.orientation!==a.orientation||i.orientation==="Z")continue;let c=i.orientation==="H"?Math.abs(i.a.y-a.a.y)<=nt:Math.abs(i.a.x-a.a.x)<=nt,d=i.orientation==="H"?on(i.a.x,i.b.x,a.a.x,a.b.x):on(i.a.y,i.b.y,a.a.y,a.b.y);if(c&&d>nt)return!0;let l=i.orientation==="H"?Math.abs(i.a.y-a.a.y):Math.abs(i.a.x-a.a.x);if(!c&&l<Vr&&d>=$r)return!0}}return!1}e(Fn,"polylineHasSelfConflict");var xo=class extends Error{constructor(t){super(`Could not place label for edge "${t.edgeId}"`);this.details=t,this.name="LabelPlacementSearchExhaustedError"}static{e(this,"LabelPlacementSearchExhaustedError")}},Go=class extends Error{static{e(this,"LabelIndexWorkLimitError")}constructor(){super("Grid label index work cap exceeded");this.name="LabelIndexWorkLimitError"}},Kr=class{constructor(t,o){this.limit=t,this.metrics=o,this.used=0}static{e(this,"LabelIndexWorkBudget")}charge(t){if(t<=0)return;if(this.used+t>this.limit)throw new Go;this.used+=t,U(this.metrics,"indexWorkUnits",t)}},Be=class{constructor(t,o){this.workBudget=t,this.metrics=o,this.entriesById=new Map,this.sortedByLeft=[],this.dirty=!1}static{e(this,"CompressedBoundsIndex")}upsert(t){let o=!this.entriesById.has(t.id);if(this.entriesById.set(t.id,t),this.dirty=!0,o&&this.metrics)this.metrics.indexCoordinateCount+=4}remove(t){if(this.entriesById.delete(t))this.dirty=!0}query(t){if(this.dirty){let r=this.entriesById.size;this.workBudget.charge(r*Math.max(1,Math.ceil(Math.log2(r+1)))),this.sortedByLeft=[...this.entriesById.values()].sort((i,s)=>i.bounds.left-s.bounds.left||W(i.id,s.id)),this.dirty=!1}let o=[];for(let r of this.sortedByLeft){if(this.workBudget.charge(1),r.bounds.left>t.right)break;if(Dn(r.bounds,t))o.push(r)}return o}};function rn(t,o){return t.left<o.right&&t.right>o.left&&t.top<o.bottom&&t.bottom>o.top}e(rn,"rectOverlap");function le(t,o){let r=t.width??0,i=t.height??0;return{cx:o.x,cy:o.y,left:o.x-r/2,right:o.x+r/2,top:o.y-i/2,bottom:o.y+i/2}}e(le,"labelRectAt");function To(t){let o=t.groupTitleRect;if(!o)return null;return{cx:(o.left+o.right)/2,cy:(o.top+o.bottom)/2,left:o.left,right:o.right,top:o.top,bottom:o.bottom}}e(To,"groupTitleRect");function U(t,o,r=1){if(t)t[o]+=r}e(U,"incrementMetric");function be(t){return{...t}}e(be,"clonePoint");function zt(t){return{left:t.left,right:t.right,top:t.top,bottom:t.bottom}}e(zt,"boundsForRect");function He(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)}}e(He,"boundsForSegment");function No(t){if(t.length===0)return null;let o=t[0].x,r=t[0].x,i=t[0].y,s=t[0].y;for(let a of t.slice(1))o=Math.min(o,a.x),r=Math.max(r,a.x),i=Math.min(i,a.y),s=Math.max(s,a.y);return{left:o,right:r,top:i,bottom:s}}e(No,"boundsForPoints");function Fo(t,o){return{left:Math.min(t.left,o.left),right:Math.max(t.right,o.right),top:Math.min(t.top,o.top),bottom:Math.max(t.bottom,o.bottom)}}e(Fo,"mergeBounds");function Do(t,o){return{left:t.left-o,right:t.right+o,top:t.top-o,bottom:t.bottom+o}}e(Do,"expandBounds");function Dn(t,o){return t.left<=o.right&&t.right>=o.left&&t.top<=o.bottom&&t.bottom>=o.top}e(Dn,"boundsOverlap");function kn(t){return(t.length<=2?t.map((r,i)=>i):[...t.slice(1,-1).map((r,i)=>i+1),0,t.length-1]).map((r,i)=>({segment:t[r],segmentIndex:r,order:i}))}e(kn,"candidateSegmentsFromSegments");function zn(t,o){return["start","end"].filter((i)=>Oo(t,i)).map((i)=>Ao(o,i,Nn,7,nt)).filter((i)=>i!==null)}e(zn,"markerClearanceRectsFromPoints");function Ve(t,o){let r=ht(o);return{points:r.points,segments:r.segments,candidateSegments:kn(r.segments),markerRects:zn(t,r.points)}}e(Ve,"buildEdgeGeometry");function Yt(t){return t.orientation==="H"?Math.abs(t.b.x-t.a.x):Math.abs(t.b.y-t.a.y)}e(Yt,"segmentLength");function ko(t,o){let r=[{x:o.left,y:o.top},{x:o.right,y:o.top},{x:o.right,y:o.bottom},{x:o.left,y:o.bottom}];for(let i=0;i<r.length;i++)if(Vt(r[i],r[(i+1)%r.length],t))return!0;return!1}e(ko,"borderCutsRect");function Hn(t){return Number.isFinite(t.x)&&Number.isFinite(t.y)}e(Hn,"hasFinitePosition");function Ot(t,o,r){let i=o?.get(t.id);if(i)return ht(i).points;let s=r?.edgeGeometryById.get(t.id);if(s)return s.points;return ht(t.points??[]).points}e(Ot,"pointsForEdge");function $e(t,o,r){if(!o?.has(t.id)){let i=r?.edgeGeometryById.get(t.id);if(i)return i.markerRects}return zn(t,Ot(t,o,r))}e($e,"markerClearanceRectsForEdge");function xe(t,o,r,i){return Math.max(Math.min(t,o),Math.min(r,i))<Math.min(Math.max(t,o),Math.max(r,i))-nt}e(xe,"rangeOverlaps");function zo(t,o,r){let i=Gt(Math.min(t.start,t.end),o,r),s=Gt(Math.max(t.start,t.end),o,r);return s-i>nt?{start:i,end:s}:null}e(zo,"clampInterval");function Ho(t,o,r){let i=t.map((a)=>zo(a,o,r)).filter((a)=>a!==null).sort((a,c)=>a.start-c.start||a.end-c.end);if(i.length===0)return[];let s=[i[0]];for(let a=1;a<i.length;a++){let c=i[a],d=s[s.length-1];if(c.start<=d.end+nt)d.end=Math.max(d.end,c.end);else s.push(c)}return s}e(Ho,"mergeBlockedLabelIntervals");function Ke(t,o,r,i){if(o-t<=nt)return[];let s=[],a=t;for(let u of Ho(r,t,o)){if(u.start-a>nt)s.push({start:a,end:u.start});a=Math.max(a,u.end)}if(o-a>nt)s.push({start:a,end:o});let c=s.map((u)=>({value:Gt(i,u.start,u.end),start:u.start,end:u.end}));c.sort((u,h)=>{let f=Math.abs(u.value-i)-Math.abs(h.value-i);if(Math.abs(f)>nt)return f;let p=h.end-h.start-(u.end-u.start);if(Math.abs(p)>nt)return p;return u.value-h.value});let d=new Set,l=[];for(let u of c){let h=Math.round(u.value*1e6)/1e6;if(d.has(h))continue;d.add(h),l.push(u.value)}return l}e(Ke,"centerCandidatesFromIntervals");function Vo(t){if(t.isGroup)return null;if(xt(t)&&!Hn(t))return null;return z(t)}e(Vo,"obstacleRectForNode");function $o(t,o){let r=o?.edgeGeometryById.get(t.id);if(r)return r.candidateSegments;return kn(ht(t.points??[]).segments)}e($o,"candidateSegments");function Vn(t,o,r){let i=t.edgeGeometryById.get(o);if(i)i.segments.forEach((s,a)=>t.segmentIndex.remove(`${o}:${a}`));t.edgeGeometryById.set(o,r),r.segments.forEach((s,a)=>{t.segmentIndex.upsert({id:`${o}:${a}`,edgeId:o,segment:s,bounds:He(s)})})}e(Vn,"storeEdgeGeometry");function Ht(t,o,r){let i=Ve(o,r);o.points=i.points.map(be),Vn(t,o.id,i)}e(Ht,"setEdgePoints");function Ko(t,o){t.placedLabelIndex.upsert({id:`label:${o.nodeId}`,nodeId:o.nodeId,rect:o.rect,bounds:zt(o.rect)})}e(Ko,"upsertPlacedLabelObstacle");function jo(t,o,r){let i={edgeById:new Map,edgeGeometryById:new Map,obstacleIndex:new Be(o,r),placedLabelIndex:new Be(o,r),groupBorderIndex:new Be(o,r),segmentIndex:new Be(o,r),searchBounds:{left:0,right:0,top:0,bottom:0},metrics:r},s=null,a=e((c)=>{s=s?Fo(s,c):{...c}},"rememberBounds");for(let c of t.nodes){if(c.isGroup){let u=z(c),h=zt(u);i.groupBorderIndex.upsert({id:`border:${c.id}`,rect:u,bounds:h}),a(h);let f=To(c);if(f){let p=zt(f);i.obstacleIndex.upsert({id:`title:${c.id}`,rect:f,bounds:p}),a(p)}continue}let d=Vo(c);if(!d)continue;let l={id:`${xt(c)?"label":"node"}:${c.id}`,rect:d,bounds:zt(d),nodeId:c.id};if(xt(c))i.placedLabelIndex.upsert(l);else i.obstacleIndex.upsert(l);a(l.bounds)}for(let c of t.edges){i.edgeById.set(c.id,c);let d=Ve(c,c.points??[]);Vn(i,c.id,d);let l=No(d.points);if(l)a(l)}return i.searchBounds=Do(s??{left:0,right:0,top:0,bottom:0},128),i}e(jo,"createEdgeLabelContext");function Zt(t,o,r,i={}){U(t.metrics,r);let s=[],a=e((c)=>{for(let d of c){if(d.nodeId&&(d.nodeId===i.excludeNodeId||i.skipNodeIds?.has(d.nodeId)))continue;s.push(d)}},"appendEntries");return a(t.obstacleIndex.query(o)),a(t.placedLabelIndex.query(o)),U(t.metrics,"obstacleCandidatesVisited",s.length),s}e(Zt,"queryObstacleEntries");function je(t,o,r,i,s){U(t.metrics,s);let a=i?new Set(i.keys()):void 0,c=[],d=t.segmentIndex.query(o);for(let u of d){if(u.edgeId===r||a?.has(u.edgeId))continue;c.push(u)}let l=d.length;if(i)for(let[u,h]of i){if(u===r)continue;let f=t.edgeById.get(u);if(!f)continue;Ve(f,h).segments.forEach((y,m)=>{let b=He(y);if(!Dn(b,o))return;l+=1,c.push({id:`override:${u}:${m}`,edgeId:u,segment:y,bounds:b})})}return U(t.metrics,"segmentCandidatesVisited",l),c}e(je,"queryForeignSegments");function Ue(t,o,r,i){U(t.metrics,"foreignEdgeLookups");let s=new Set;for(let a of je(t,zt(o),r,i,"segmentRectQueries"))if(Vt(a.segment.a,a.segment.b,o))s.add(a.edgeId);return[...s].sort(W)}e(Ue,"foreignEdgeIdsIntersectingRect");function $n(t,o){if(!tt(o.width)||!tt(o.height))return null;if(t.orientation==="H")return{left:Math.min(t.a.x,t.b.x)-o.width/2,right:Math.max(t.a.x,t.b.x)+o.width/2,top:t.a.y-o.height/2,bottom:t.a.y+o.height/2};return{left:t.a.x-o.width/2,right:t.a.x+o.width/2,top:Math.min(t.a.y,t.b.y)-o.height/2,bottom:Math.max(t.a.y,t.b.y)+o.height/2}}e($n,"obstacleBandQueryBounds");function Uo(t,o,r){if(t.orientation==="H"){let s=(o.width??0)+pt*2+at;return{left:Math.min(t.a.x,t.b.x)-s,right:Math.max(t.a.x,t.b.x)+s,top:r.top,bottom:r.bottom}}let i=(o.height??0)+pt*2+at;return{left:r.left,right:r.right,top:Math.min(t.a.y,t.b.y)-i,bottom:Math.max(t.a.y,t.b.y)+i}}e(Uo,"detourLineQueryBounds");function Xo(t,o){if(t.orientation==="H")return{left:Math.min(t.a.x,t.b.x)-pt,right:Math.max(t.a.x,t.b.x)+pt,top:o.top,bottom:o.bottom};return{left:o.left,right:o.right,top:Math.min(t.a.y,t.b.y)-pt,bottom:Math.max(t.a.y,t.b.y)+pt}}e(Xo,"rerouteLineQueryBounds");function ue(t,o,r,i,s,a){for(let c of Zt(i,zt(t),"obstacleRectQueries",{excludeNodeId:r}))if(rn(t,c.rect))return!1;for(let c of i.groupBorderIndex.query(zt(t)))if(ko(t,c.rect))return!1;for(let c of $e(o,s,i))if(rn(t,c))return!1;for(let c of je(i,zt(t),o.id,s,"segmentRectQueries")){if(a?.has(c.edgeId))continue;if(Vt(c.segment.a,c.segment.b,t))return!1}return!0}e(ue,"rectSafeForLabel");function Wo(t,o){return o.orientation==="Z"?0:Po(t,o.orientation)}e(Wo,"requiredSegmentLength");function Xe(t,o,r,i,s,a){if(!tt(o.width)||!tt(o.height))return null;let{width:c,height:d}=o,l=r.orientation==="H"?c/2+pt:d/2+pt,u=r.orientation==="H"?Math.min(r.a.x,r.b.x)+l:Math.min(r.a.y,r.b.y)+l,h=r.orientation==="H"?Math.max(r.a.x,r.b.x)-l:Math.max(r.a.y,r.b.y)-l;if(h-u<=nt)return null;let f=[],p=$n(r,o);if(!p)return null;let y=e((m)=>{if(r.orientation==="H"){let x=r.a.y-d/2,w=r.a.y+d/2;if(xe(x,w,m.top,m.bottom))f.push({start:m.left-c/2,end:m.right+c/2});return}let b=r.a.x-c/2,g=r.a.x+c/2;if(xe(b,g,m.left,m.right))f.push({start:m.top-d/2,end:m.bottom+d/2})},"addRect");for(let m of Zt(i,p,"obstacleBandQueries",{excludeNodeId:o.id}))y(m.rect);for(let m of $e(t,s,i))y(m);if(a)for(let m of je(i,p,t.id,s,"segmentBandQueries")){let b=m.segment;if(r.orientation==="H"){let w=r.a.y-o.height/2,M=r.a.y+o.height/2;if(b.orientation==="H"){if(w<b.a.y&&M>b.a.y)f.push({start:Math.min(b.a.x,b.b.x)-o.width/2,end:Math.max(b.a.x,b.b.x)+o.width/2})}else if(xe(w,M,Math.min(b.a.y,b.b.y),Math.max(b.a.y,b.b.y)))f.push({start:b.a.x-o.width/2,end:b.a.x+o.width/2});continue}let g=r.a.x-o.width/2,x=r.a.x+o.width/2;if(b.orientation==="V"){if(g<b.a.x&&x>b.a.x)f.push({start:Math.min(b.a.y,b.b.y)-o.height/2,end:Math.max(b.a.y,b.b.y)+o.height/2})}else if(xe(g,x,Math.min(b.a.x,b.b.x),Math.max(b.a.x,b.b.x)))f.push({start:b.a.y-o.height/2,end:b.a.y+o.height/2})}return{low:u,high:h,blocked:f}}e(Xe,"blockedCenterIntervals");function Yo(t,o,r,i){if(Yt(r)<Wo(o,r))return null;let s=Xe(t,o,r,i,void 0,!0);if(!s)return null;let a=r.orientation==="H"?(Math.min(r.a.x,r.b.x)+Math.max(r.a.x,r.b.x))/2:(Math.min(r.a.y,r.b.y)+Math.max(r.a.y,r.b.y))/2,c=Ke(s.low,s.high,s.blocked,a);for(let d of c){let l=r.orientation==="H"?{x:d,y:r.a.y}:{x:r.a.x,y:d},u=le(o,l);if(ue(u,t,o.id,i))return l}return null}e(Yo,"placementOnExistingSegment");function qo(t,o,r,i,s){let a=Xe(t,o,r,i,void 0,!1);if(!a)return null;let c=r.orientation==="H"?(Math.min(r.a.x,r.b.x)+Math.max(r.a.x,r.b.x))/2:(Math.min(r.a.y,r.b.y)+Math.max(r.a.y,r.b.y))/2,d=Ke(a.low,a.high,a.blocked,c);for(let l of d){let u=r.orientation==="H"?{x:l,y:r.a.y}:{x:r.a.x,y:l},h=le(o,u),f=new Map,p=Ue(i,h,t.id).map((m)=>i.edgeById.get(m)).filter((m)=>m!==void 0),y=!0;for(let m of p){let b=he(m,h,i,s,f);if(!b){y=!1;break}f.set(m.id,b)}if(!y)continue;if(!ue(h,t,o.id,i,f))continue;for(let[m,b]of f){let g=i.edgeById.get(m);if(g)Ht(i,g,b)}return u}return null}e(qo,"placementOnExistingSegmentWithReroutes");function ve(t,o,r){for(let i of ht(t).segments)for(let s of Zt(o,He(i),"obstaclePolylineQueries",{skipNodeIds:r}))if(Vt(i.a,i.b,s.rect))return!0;return!1}e(ve,"polylineHitsProtectedObstacles");function te(t,o,r){let i=r.get(t);return!i||Bo(o,i.center,nt)}e(te,"labelStillAnchored");function Kn(t){let o=[];for(let r=0;r<zr;r++){let i=t+at+r*kr;o.push(-i,i)}return o}e(Kn,"detourOffsets");function Ae(t,o){let r=new Map;for(let i of t){let s=Math.round(i*1e6)/1e6;if(!r.has(s))r.set(s,i)}return[...r.values()].sort((i,s)=>{let a=Math.abs(i-o)-Math.abs(s-o);if(Math.abs(a)>nt)return a;return i-s})}e(Ae,"uniqueSortedCandidates");function jn(t,o,r,i){if(!tt(o.width)||!tt(o.height))return[];let{width:s,height:a}=o,c=r.orientation==="H"?r.a.y:r.a.x,d=r.orientation==="H"?a/2:s/2,l=Kn(d).map((h)=>c+h),u=e((h)=>{if(r.orientation==="H"){l.push(h.top-d-at),l.push(h.bottom+d+at);return}l.push(h.left-d-at),l.push(h.right+d+at)},"addRect");for(let h of Zt(i,Uo(r,o,i.searchBounds),"obstacleBandQueries",{excludeNodeId:o.id}))u(h.rect);for(let h of $e(t,void 0,i))u(h);return Ae(l,c).slice(0,_o)}e(jn,"detourLineCandidates");function sn(t,o,r,i,s){let a=t.orientation==="H"?t.a.y:t.a.x,c=[];for(let h of Kn(0))if(t.orientation==="H")c.push(h<0?o.top+h:o.bottom+h);else c.push(h<0?o.left+h:o.right+h);let d=e((h)=>{if(t.orientation==="H"){c.push(h.top-at),c.push(h.bottom+at);return}c.push(h.left-at),c.push(h.right+at)},"addRect");for(let h of Zt(r,Xo(t,r.searchBounds),"obstacleBandQueries",{skipNodeIds:i}))d(h.rect);let l=Ae(c,a);return(s?.orientation===t.orientation?l.filter((h)=>{if(s.side==="top")return h<o.top;if(s.side==="bottom")return h>o.bottom;if(s.side==="left")return h<o.left;return h>o.right}):l).slice(0,_o)}e(sn,"rerouteLineCandidates");function Qo(t,o,r,i,s){if(!tt(o.width)||!tt(o.height))return[];let{width:a,height:c}=o,d=r.orientation==="H"?{orientation:"H",a:{x:r.a.x,y:i},b:{x:r.b.x,y:i}}:{orientation:"V",a:{x:i,y:r.a.y},b:{x:i,y:r.b.y}},l=Xe(t,o,d,s,void 0,!1);if(!l){let h=r.orientation==="H"?(Math.min(r.a.x,r.b.x)+Math.max(r.a.x,r.b.x))/2:(Math.min(r.a.y,r.b.y)+Math.max(r.a.y,r.b.y))/2,f=[h],p=$n(d,o),y=e((m)=>{if(r.orientation==="H"){f.push(m.left-at-a/2),f.push(m.right+at+a/2);return}f.push(m.top-at-c/2),f.push(m.bottom+at+c/2)},"addRect");if(p)for(let m of Zt(s,p,"obstacleBandQueries",{excludeNodeId:o.id}))y(m.rect);return Ae(f,h).slice(0,Hr)}let u=r.orientation==="H"?(Math.min(r.a.x,r.b.x)+Math.max(r.a.x,r.b.x))/2:(Math.min(r.a.y,r.b.y)+Math.max(r.a.y,r.b.y))/2;return Ke(l.low,l.high,l.blocked,u)}e(Qo,"detourCenterCandidates");function Un(t,o,r){let i=o>=t?1:-1;return o+i*(r+pt)}e(Un,"detourReturnCoordinate");var jr={along:e((t)=>t.x,"along"),cross:e((t)=>t.y,"cross"),point:e((t,o)=>({x:t,y:o}),"point"),labelAlongSize:e((t)=>t.width??0,"labelAlongSize"),labelCrossSize:e((t)=>t.height??0,"labelCrossSize")},Ur={along:e((t)=>t.y,"along"),cross:e((t)=>t.x,"cross"),point:e((t,o)=>({x:o,y:t}),"point"),labelAlongSize:e((t)=>t.height??0,"labelAlongSize"),labelCrossSize:e((t)=>t.width??0,"labelCrossSize")};function Xn(t){return t.orientation==="H"?jr:Ur}e(Xn,"detourAxis");function Zo(t,o,r,i,s,a){if(!tt(i.width)||!tt(i.height))return null;let c=t[o],d=t[o+1],l=Xn(r),u=l.cross(r.a),h=l.along(c),f=l.along(d),p=l.labelAlongSize(i)+pt*2,y=s-p/2,m=s+p/2,b=y<Math.min(h,f)-nt,g=m>Math.max(h,f)+nt,x=f>=h?1:-1,w=Math.max(0,Math.min(Nn,Math.abs(f-h)/2-nt)),M=h+x*w,S=f-x*w;if(!b&&!g)return ht([...t.slice(0,o),c,l.point(y,u),l.point(y,a),l.point(m,a),l.point(m,u),d,...t.slice(o+2)]).points;let E=Un(u,a,l.labelCrossSize(i)/2),I=[...t.slice(0,o),c];if(b)I.push(l.point(M,u),l.point(M,E),l.point(y,E),l.point(y,a));else I.push(l.point(y,u),l.point(y,a));if(I.push(l.point(m,a)),g)I.push(l.point(m,E),l.point(S,E),l.point(S,u));else I.push(l.point(m,u));return I.push(d,...t.slice(o+2)),ht(I).points}e(Zo,"buildLabelDetourPoints");function Jo(t,o,r,i,s,a,c){if(!tt(i.width)||!tt(i.height))return null;let d=t[o],l=t[o+1],u=c?4:2,h=Xn(r),f=h.cross(r.a),p=h.along(d),y=h.along(l),m=h.labelAlongSize(i)+pt*2,b=s-m/2,g=s+m/2,x=y>=p?1:-1,w=Math.max(0,Math.min(Nn,Math.abs(y-p)/u-nt)),M=p+x*w,S=y-x*w,E=Un(f,a,h.labelCrossSize(i)/2);return ht([...t.slice(0,o),d,h.point(M,f),h.point(M,a),h.point(b,a),h.point(g,a),h.point(g,E),h.point(S,E),h.point(S,f),l,...t.slice(o+2)]).points}e(Jo,"buildExtendedLabelDetourPoints");function ti(t,o){if(!tt(o.width)||!tt(o.height))return[];if(t.orientation==="H"){let s=Math.min(t.a.x,t.b.x),a=Math.max(t.a.x,t.b.x);return[s-o.width/2-at,a+o.width/2+at]}let r=Math.min(t.a.y,t.b.y),i=Math.max(t.a.y,t.b.y);return[r-o.height/2-at,i+o.height/2+at]}e(ti,"externalDetourCenterCandidates");function Wn(t,o){let r=0,i=0;for(let s of ht([...t]).segments){if(!Vt(s.a,s.b,o))continue;if(r++,s.orientation==="H")i+=Math.max(0,Math.min(Math.max(s.a.x,s.b.x),o.right)-Math.max(Math.min(s.a.x,s.b.x),o.left));else if(s.orientation==="V")i+=Math.max(0,Math.min(Math.max(s.a.y,s.b.y),o.bottom)-Math.max(Math.min(s.a.y,s.b.y),o.top))}return{count:r,length:i}}e(Wn,"blockedIntersectionScore");function an(t,o,r){let i=Wn(t,o);return i.count<r.count||i.count===r.count&&i.length<r.length-nt}e(an,"reducesBlockedIntersections");function ei(t,o,r){let i=ht([...t]).segments.find((c)=>Vt(c.a,c.b,o));if(!i||i.orientation==="Z")return null;let s=i.orientation==="H"?Math.abs(i.a.y-o.top)<=Math.abs(o.bottom-i.a.y)?"top":"bottom":Math.abs(i.a.x-o.left)<=Math.abs(o.right-i.a.x)?"left":"right",a=r.map((c)=>c.edgeId).sort(W);return{key:JSON.stringify([a,i.orientation,s]),orientation:i.orientation,side:s}}e(ei,"rerouteLane");function ni(t,o,r,i,s,a,c){let d=ht(o),l=Wn(d.points,i),u=d.segments[r];if(!u||u.orientation==="Z")return null;let h=d.points[r],f=d.points[r+1],p=a.get(t.id)?.nodeId,y=new Set;if(p)y.add(p);if(u.orientation==="H"){let w=Math.min(h.x,f.x),M=Math.max(h.x,f.x),S=Math.max(w,i.left-pt),E=Math.min(M,i.right+pt);if(E-S<=nt)return U(s.metrics,"rerouteRejectedDegenerateSpan"),null;for(let I of sn(u,i,s,y,c)){U(s.metrics,"rerouteCandidatesEvaluated");let v=ht([...d.points.slice(0,r),h,{x:S,y:u.a.y},{x:S,y:I},{x:E,y:I},{x:E,y:u.a.y},f,...d.points.slice(r+2)]).points;if(It(v,i)&&!an(v,i,l)){U(s.metrics,"rerouteRejectedBlockedRect");continue}if(It(v,i))U(s.metrics,"reroutePartialProgressCandidates");if(ve(v,s,y)){U(s.metrics,"rerouteRejectedProtectedObstacle");continue}if(!te(t.id,v,a)){U(s.metrics,"rerouteRejectedLabelAnchor");continue}return v}return null}let m=Math.min(h.y,f.y),b=Math.max(h.y,f.y),g=Math.max(m,i.top-pt),x=Math.min(b,i.bottom+pt);if(x-g<=nt)return U(s.metrics,"rerouteRejectedDegenerateSpan"),null;for(let w of sn(u,i,s,y,c)){U(s.metrics,"rerouteCandidatesEvaluated");let M=ht([...d.points.slice(0,r),h,{x:u.a.x,y:g},{x:w,y:g},{x:w,y:x},{x:u.a.x,y:x},f,...d.points.slice(r+2)]).points;if(It(M,i)&&!an(M,i,l)){U(s.metrics,"rerouteRejectedBlockedRect");continue}if(It(M,i))U(s.metrics,"reroutePartialProgressCandidates");if(ve(M,s,y)){U(s.metrics,"rerouteRejectedProtectedObstacle");continue}if(!te(t.id,M,a)){U(s.metrics,"rerouteRejectedLabelAnchor");continue}return M}return null}e(ni,"rerouteSegmentAroundRect");function he(t,o,r,i,s,a){let c=Ot(t,s,r);for(let d=0;d<8;d++){if(!It(c,o))return c;let l=ht(c),u=l.points.findIndex((f,p)=>{if(p===l.points.length-1)return!1;return Vt(f,l.points[p+1],o)});if(u<0)return c;let h=ni(t,l.points,u,o,r,i,a);if(!h)return null;c=h}return It(c,o)?null:c}e(he,"rerouteForeignEdgeAroundRect");function oi(t,o,r,i,s){let a=Ot(t,s,r),c=a;for(let d=0;d<2;d++){let l=!1;for(let u of o){if(!It(c,u.rect))continue;U(r.metrics,"individualLabelRerouteAttempts"),s.set(t.id,c);let h=he(t,u.rect,r,i,s);if(!h)return s.set(t.id,a),null;U(r.metrics,"individualLabelRerouteSuccesses"),c=h,l=!0}if(o.every((u)=>!It(c,u.rect)))return c;if(!l)break}return s.set(t.id,a),null}e(oi,"rerouteForeignEdgeAroundLabels");function ii(t,o,r,i,s){if(!tt(o.width)||!tt(o.height))return null;let a=Ot(t,void 0,i),c=r.segment;for(let d of jn(t,o,c,i)){let l=Ae(ti(c,o),c.orientation==="H"?(Math.min(c.a.x,c.b.x)+Math.max(c.a.x,c.b.x))/2:(Math.min(c.a.y,c.b.y)+Math.max(c.a.y,c.b.y))/2);for(let u of l){let h=Jo(a,r.segmentIndex,c,o,u,d,t.start===t.end);if(!h)continue;if(t.start===t.end&&Fn(h))continue;if(ve(h,i,new Set([o.id])))continue;let f=c.orientation==="H"?{x:u,y:d}:{x:d,y:u},p=le(o,f),y=new Map([[t.id,h]]),m=Ue(i,p,t.id,y).map((g)=>i.edgeById.get(g)).filter((g)=>g!==void 0),b=!0;for(let g of m){let x=he(g,p,i,s,y);if(!x){b=!1;break}y.set(g.id,x)}if(!b)continue;if(!ue(p,t,o.id,i,y))continue;Ht(i,t,h);for(let[g,x]of y){if(g===t.id)continue;let w=i.edgeById.get(g);if(w)Ht(i,w,x)}return f}}return null}e(ii,"labelPlacementWithExtendedDetour");function ri(t,o,r,i,s){if(!tt(o.width)||!tt(o.height))return null;let a=Ot(t,void 0,i),c=r.segment;for(let d of jn(t,o,c,i)){let l=Qo(t,o,c,d,i);for(let u of l){let h=Zo(a,r.segmentIndex,c,o,u,d);if(!h)continue;if(t.start===t.end&&Fn(h))continue;if(ve(h,i,new Set([o.id])))continue;let f=c.orientation==="H"?{x:u,y:d}:{x:d,y:u},p=le(o,f),y=new Map([[t.id,h]]),m=Ue(i,p,t.id,y).map((g)=>i.edgeById.get(g)).filter((g)=>g!==void 0),b=!0;for(let g of m){let x=he(g,p,i,s,y);if(!x){b=!1;break}y.set(g.id,x)}if(!b)continue;if(!ue(p,t,o.id,i,y))continue;Ht(i,t,h);for(let[g,x]of y){if(g===t.id)continue;let w=i.edgeById.get(g);if(w)Ht(i,w,x)}return f}}return null}e(ri,"labelPlacementWithDetour");function si(t){return Boolean(t&&xt(t))}e(si,"isPreparedLabelNode");function Yn(t,o,r){let i=t.points?.find((d)=>Number.isFinite(d.x)&&Number.isFinite(d.y)),s=t.start?r.get(t.start):void 0,a=t.end?r.get(t.end):void 0,c=i??(s&&Hn(s)?s:void 0)??a;if(c&&Number.isFinite(c.x)&&Number.isFinite(c.y)){o.x=c.x,o.y=c.y;return}delete o.x,delete o.y}e(Yn,"parkDegenerateLabel");function ai(t,o,r){let i;for(let s of ht(t.points??[]).segments){if(s.orientation==="Z")continue;if(!i||Yt(s)>Yt(i))i=s}if(!i){Yn(t,o,r);return}o.x=(i.a.x+i.b.x)/2,o.y=(i.a.y+i.b.y)/2}e(ai,"placeLabelAtRouteMidpoint");function ci(t){return`${Dr}${t.start??""}-${t.end??""}-${t.id}`}e(ci,"preferredGridLabelNodeId");function di(t,o){let r=t.labelNodeId??ci(t),i=r,s=1;while(!0){if(!o.has(i))return i;i=`${r}-${s}`,s+=1}}e(di,"ensureUniqueGridLabelNodeId");function li(t){let o=new Map;for(let i of t.nodes)o.set(i.id,i);let r=[];for(let i of t.edges){if(!i.label||i.label.length===0)continue;let s=i.start?o.get(i.start):void 0,a=i.labelNodeId?o.get(i.labelNodeId):void 0;if(si(a)){if(a.label=i.label,a.labelStyle=Array.isArray(i.labelStyle)?i.labelStyle[0]:i.labelStyle??"",a.edgeStart=i.start??"",a.edgeEnd=i.end??"",s?.dir)a.dir=s.dir;i.label=void 0,i.text=void 0;continue}let c=di(i,o),d={id:c,label:i.label,edgeStart:i.start??"",edgeEnd:i.end??"",shape:"labelRect",width:0,height:0,isEdgeLabel:!0,isDummy:!0,isGroup:!1,parentId:void 0,labelStyle:Array.isArray(i.labelStyle)?i.labelStyle[0]:i.labelStyle??"",...s?.dir?{dir:s.dir}:{}};r.push(d),o.set(c,d),i.labelNodeId=c,i.label=void 0,i.text=void 0}t.nodes.push(...r)}e(li,"prepareGridLayout");function ui(t,o,r,i={}){let s=new Map;for(let x of t.nodes)s.set(x.id,x);let a=t.nodes.filter(xt),c=new Map(a.map((x)=>[x.id,{x:x.x,y:x.y}]));for(let x of a)delete x.x,delete x.y;let d=t.edges.map((x,w)=>{if(!x.labelNodeId)return null;let M=s.get(x.labelNodeId);if(!M)return null;if(!tt(M.width)||!tt(M.height))return U(o,"unmeasuredLabelsSkipped"),null;return{edge:x,labelNode:M,sourceIndex:w}}).filter((x)=>x!==null);if(d.length===0)return;let l=new Map(t.edges.map((x)=>[x.id,x.points?.map((w)=>({...w}))])),u=e(()=>{for(let x of t.edges){let w=l.get(x.id);if(w)x.points=w.map((M)=>({...M}));else delete x.points}},"restoreBaseEdgePoints"),h=e(()=>{u();for(let x of a){let w=c.get(x.id);if(w&&Number.isFinite(w.x)&&Number.isFinite(w.y))x.x=w.x,x.y=w.y;else delete x.x,delete x.y}},"restoreBaseState"),f=d.filter(({edge:x,labelNode:w})=>{if(ht(x.points??[]).segments.length>0)return!0;return Yn(x,w,s),U(o,"degenerateLabelRoutesSkipped"),!1}).sort((x,w)=>x.sourceIndex-w.sourceIndex||W(x.edge.id,w.edge.id));if(f.length===0)return;let p=e(()=>{u();for(let{edge:x,labelNode:w}of f)ai(x,w,s)},"placeLabelsAtRouteMidpoints"),y=i.maxIndexWork??yo,m=Number.isFinite(y)&&y>=0?Math.floor(y):yo,b=new Kr(m,o),g=[];for(let x=1;x<=2;x++){U(o,"labelPasses");let w=jo(t,b,o),M=new Map,S=new Map,E=new Map(t.edges.map((v)=>[v.id,Ot(v,void 0,w).map(be)])),I=new Map;try{for(let{edge:C,labelNode:O}of f){let P=[...$o(C,w)].sort((T,Y)=>{let q=Yt(Y.segment)-Yt(T.segment);if(Math.abs(q)>nt)return q;return T.order-Y.order}),L=null;for(let T of P)if(L=Yo(C,O,T.segment,w),L)break;if(!L){for(let T of P)if(L=qo(C,O,T.segment,w,M),L)break}if(x===2&&!L){for(let T of P)if(L=ri(C,O,T,w,M),L)break}if(x===2&&!L){for(let T of P)if(L=ii(C,O,T,w,M),L)break}if(!L)throw new xo({edgeId:C.id,labelNodeId:O.id,labelWidth:O.width,labelHeight:O.height,pointCount:C.points?.length??0,points:C.points?.map((T)=>({...T}))??[],segments:P.map(({segment:T})=>({orientation:T.orientation,length:Yt(T),a:{...T.a},b:{...T.b}}))});O.x=L.x,O.y=L.y;let N={edgeId:C.id,nodeId:O.id,center:L,rect:le(O,L)};M.set(C.id,N),Ko(w,N)}let v=[...M.values()];if(U(o,"frozenReservations",v.length),r)r.labelOverlayBuilds++,r.labelOverlayVertices+=v.length*4;for(let C of t.edges){let O=E.get(C.id)??[],P=Ot(C,void 0,w);if(JSON.stringify(P)!==JSON.stringify(O))I.set(C.id,P.map(be));Ht(w,C,O.map(be))}for(let[C,O]of I){if(!M.has(C))continue;let P=w.edgeById.get(C);if(P)Ht(w,P,O)}let R=new Set(I.keys());for(let C of t.edges){let O=M.get(C.id),P=Ot(C,void 0,w);for(let L of v)if(L.edgeId!==C.id&&It(P,L.rect))R.add(C.id);if(O&&!te(C.id,P,M))R.add(C.id)}let A=new Map;for(let C of t.edges){if(!R.has(C.id))continue;let O=Ot(C,void 0,w),P=new Map([[C.id,O]]),L=v.filter((N)=>N.edgeId!==C.id&&It(O,N.rect));if(L.length>0){let N=L.slice(1).reduce((it,k)=>({cx:(Math.min(it.left,k.rect.left)+Math.max(it.right,k.rect.right))/2,cy:(Math.min(it.top,k.rect.top)+Math.max(it.bottom,k.rect.bottom))/2,left:Math.min(it.left,k.rect.left),right:Math.max(it.right,k.rect.right),top:Math.min(it.top,k.rect.top),bottom:Math.max(it.bottom,k.rect.bottom)}),{...L[0].rect}),T=ei(O,N,L),Y=T?A.get(T.key)??0:0,q=(Y+2)*12,D={cx:N.cx,cy:N.cy,left:N.left-q,right:N.right+q,top:N.top-q,bottom:N.bottom+q},Q=he(C,D,w,M,P,T??void 0),Ct=Q!==null;if(Q??=oi(C,L,w,M,P),Q){if(O=Q,P.set(C.id,O),T&&Ct)A.set(T.key,Y+1)}else{U(o,"labelOverlapFallbacks");for(let it of L){if(!It(O,it.rect))continue;let k=S.get(it.edgeId)??new Set;if(!k.has(C.id))U(o,"labelOverlapReservations");k.add(C.id),S.set(it.edgeId,k)}}}if(!te(C.id,O,M))throw V("GRID_ROUTE_NOT_FOUND",`Label anchor was lost for edge "${C.id}"`,{edgeId:C.id,pass:x});if(M.has(C.id))U(o,"preservedAnchors");Ht(w,C,O),U(o,"impactedEdgeReroutes")}for(let{edge:C,labelNode:O}of f){let P=M.get(C.id);if(!P||!te(C.id,Ot(C,void 0,w),M)||!ue(P.rect,C,O.id,w,void 0,S.get(C.id)))throw V("GRID_ROUTE_NOT_FOUND",`Label pass ${x} did not validate`,{edgeId:C.id,pass:x})}return}catch(v){if(v instanceof Go){if(p(),U(o,"indexWorkLimitFallbacks"),r)r.resourceLimitFallbacks++,r.fallbackReasons.label_index_work_cap++;return}if(!(v instanceof xo))throw h(),U(o,"rollbacks"),v;g.push(v),u();for(let{labelNode:R}of f)delete R.x,delete R.y}}if(p(),U(o,"placementSearchFallbacks"),r)r.fallbackReasons.label_placement_exhausted++;n.warn("[grid]","Label placement search exhausted; using route midpoints. Labels may overlap.",{reason:"label_placement_exhausted",edgeIds:f.map(({edge:x})=>x.id),failures:g.map(({details:x})=>x)})}e(ui,"positionGridEdgeLabels");function Pe(t){return t.isGroup?t:void 0}e(Pe,"asGroup");function hi(t){let o=new Map,r=new Map,i=new Set;for(let u of t){if(u.id===X)throw V("GRID_INVALID_CONTAINMENT",`Node id "${X}" is reserved for the grid layout root`,{traversedIds:[u.id]});if(o.has(u.id))throw V("GRID_INVALID_CONTAINMENT",`Duplicate node id "${u.id}"`,{traversedIds:[u.id]});if(o.set(u.id,u),xt(u)){i.add(u.id);continue}let h=Pe(u);if(h)r.set(h.id,h)}let s=new Map;s.set(X,[]);for(let u of t){if(i.has(u.id))continue;let h=u.parentId??X;if(h!==X){if(!r.get(h))throw V("GRID_INVALID_CONTAINMENT",`Missing parent "${h}" for "${u.id}"`,{traversedIds:[u.id,h]})}if(!s.has(h))s.set(h,[]);s.get(h).push(u)}let a=new Map,c=[],d=e((u)=>(s.get(u)??[]).map((h)=>Pe(h)).filter((h)=>h!==void 0),"directChildGroups"),l=e((u)=>{let h=a.get(u)??0;if(h===1)throw V("GRID_INVALID_CONTAINMENT",`Containment cycle at "${u}"`,{traversedIds:[u]});if(h===2)return;a.set(u,1);let f=[{groupId:u,childGroups:d(u),nextChildIndex:0}];while(f.length>0){let p=f[f.length-1],y=p.childGroups[p.nextChildIndex];if(y){p.nextChildIndex+=1;let b=a.get(y.id)??0;if(b===1)throw V("GRID_INVALID_CONTAINMENT",`Containment cycle at "${y.id}"`,{traversedIds:[...f.map((g)=>g.groupId),y.id]});if(b===2)continue;a.set(y.id,1),f.push({groupId:y.id,childGroups:d(y.id),nextChildIndex:0});continue}f.pop(),a.set(p.groupId,2);let m=r.get(p.groupId);if(m)c.push(m)}},"visit");for(let u of s.get(X)??[]){let h=Pe(u);if(h)l(h.id)}for(let u of r.keys())if((a.get(u)??0)===0)l(u);return{nodeById:o,groupById:r,childrenByParent:s,rootChildren:s.get(X)??[],postOrderGroups:c,helperNodeIds:i}}e(hi,"buildGridForest");function Kt(t,o,r){let i=o,s=new Set;while(i?.parentId){if(i.parentId===t)return!0;if(s.has(i.parentId))return!1;s.add(i.parentId),i=r.get(i.parentId)}return!1}e(Kt,"isAncestorGroup");function fi(t,o,r){let i=new Map,s=new Map;for(let a of t.edges){if(!a.start||!a.end||!a.labelNodeId)continue;if(r)r.labelSpacingEdgesExamined++;let c=o.nodeById.get(a.labelNodeId),d=o.nodeById.get(a.start),l=o.nodeById.get(a.end);if(!c||!d||!l)continue;if(a.start===a.end){let p=Tn(c,"H");if(p)s.set(a.id,p);continue}let u=d.parentId??X,h=l.parentId??X;if(u!==h)continue;let f=i.get(u);if(f)f.push({edge:a,labelNode:c});else i.set(u,[{edge:a,labelNode:c}])}return{byContainer:i,selfLoops:s}}e(fi,"buildGridLabelRequirements");function pi(t,o,r){let i=new Map,s=0;for(let a of t)i.set(a,s),s+=(o.get(a)??0)+r;return i}e(pi,"trackOrigins");function cn(t,o,r,i,s){let a=pi(r,i,s),c=a.get(t),d=i.get(t);if(c===void 0||d===void 0)return!1;let l=c+d/2,u=l-o/2,h=l+o/2;return r.every((f)=>{if(f===t)return!0;let p=a.get(f),y=p+(i.get(f)??0);return h<=p||u>=y})}e(cn,"crossAxisFits");function gi(t){let o=new Map;for(let r of t.values())for(let i of r.items)o.set(i.item.id,i);return o}e(gi,"placementByNodeId");function dn(t,o,r){let i=Math.min(t,o),s=Math.max(t,o),a=r.indexOf(i);return a>=0&&r[a+1]===s}e(dn,"areConsecutive");function ln(t,o,r){t.set(o,Math.max(t.get(o)??0,r))}e(ln,"addGapRequirement");function mi(t,o,r,i,s,a,c,d,l){let u=new Map,h=new Map,f=gi(o),p=e((y,m)=>Tn(y.labelNode,m),"requirementFor");for(let y of t){let m=y.edge.start?f.get(y.edge.start):void 0,b=y.edge.end?f.get(y.edge.end):void 0;if(!m||!b)continue;if(m.row===b.row&&dn(m.column,b.column,a)){let g=p(y,"H");if(g&&cn(m.row,g.cross,s,r,c)){if(l)l.labelSpacingEligibleEdges++;ln(h,Math.min(m.column,b.column),g.requiredAlongSpan)}continue}if(m.column===b.column&&dn(m.row,b.row,s)){let g=p(y,"V");if(g&&cn(m.column,g.cross,a,i,d)){if(l)l.labelSpacingEligibleEdges++;ln(u,Math.min(m.row,b.row),g.requiredAlongSpan)}}}return{rowGapAfter:u,columnGapAfter:h}}e(mi,"deriveGridContainerLabelGaps");var un="[grid]",Xr=new Set(["basis","bumpX","bumpY","cardinal","catmullRom","linear","monotoneX","monotoneY","natural","step","stepAfter","stepBefore","rounded"]);function Ge(t){return t!==null&&typeof t==="object"&&!Array.isArray(t)}e(Ge,"isObjectRecord");function qn(t){if(!Ge(t))return{};let o={};if(Object.hasOwn(t,"row"))o.row=t.row;if(Object.hasOwn(t,"column"))o.column=t.column;if(Ea(t.horizontalAlign))o.horizontalAlign=t.horizontalAlign;if(Aa(t.verticalAlign))o.verticalAlign=t.verticalAlign;return o}e(qn,"ownPlacementFrom");function yi(t){let o=new Map,r=0;for(let i of t)if(!o.has(i.id))o.set(i.id,r++);return o}e(yi,"buildGridSourceOrder");function xi(t){let o=Ge(t.config?.grid)?t.config.grid:{},r=Ge(o.placements)?o.placements:{},i=new Map;for(let s of Object.keys(r)){let a=r[s],c=Array.isArray(a)?a:[a];i.set(s,c.map((d)=>qn(d)))}return{placements:i,columns:typeof o.columns==="number"&&Number.isFinite(o.columns)&&o.columns>=0?Math.trunc(o.columns):vt.columns,rowGap:typeof o.rowGap==="number"&&Number.isFinite(o.rowGap)&&o.rowGap>=0?o.rowGap:vt.rowGap,columnGap:typeof o.columnGap==="number"&&Number.isFinite(o.columnGap)&&o.columnGap>=0?o.columnGap:vt.columnGap,cellGap:typeof o.cellGap==="number"&&Number.isFinite(o.cellGap)&&o.cellGap>=0?o.cellGap:vt.cellGap,containerPadding:typeof o.containerPadding==="number"&&Number.isFinite(o.containerPadding)&&o.containerPadding>=0?o.containerPadding:vt.containerPadding,titleGap:typeof o.titleGap==="number"&&Number.isFinite(o.titleGap)&&o.titleGap>=0?o.titleGap:vt.titleGap,horizontalAlign:Ea(o.horizontalAlign)?o.horizontalAlign:vt.horizontalAlign,verticalAlign:Aa(o.verticalAlign)?o.verticalAlign:vt.verticalAlign,curve:typeof o.curve==="string"&&Xr.has(o.curve)?o.curve:vt.curve,edgeCornerRadius:Qr(o.edgeCornerRadius)}}e(xi,"readGridConfig");function bi(t,o){let r=new Map;for(let i of t){let s=i.placementId??i.id;r.set(s,(r.get(s)??0)+1)}for(let[i,s]of o.placements){let a=r.get(i)??0;if(a===0){n.warn(un,`Ignoring grid placement for unknown target "${i}"`);continue}if(s.length>a)n.warn(un,`Ignoring ${s.length-a} extra grid placement occurrence(s) for target "${i}"; found ${a} matching node(s)`)}}e(bi,"validateGridPlacementMap");function wi(t){return(o,r)=>{let i=t.get(o.id)??Number.MAX_SAFE_INTEGER,s=t.get(r.id)??Number.MAX_SAFE_INTEGER;if(i!==s)return i-s;return W(o.id,r.id)}}e(wi,"itemComparator");function vi(t,o,r,i){let s=t.placementId??t.id,a=r.placements.get(s)?.[i]??{},c=qn(t.metadata);for(let u of["row","column","horizontalAlign","verticalAlign"])if(Object.hasOwn(a,u)&&Object.hasOwn(c,u)&&a[u]!==c[u])n.debug(un,"metadata overrides placement map",{nodeId:t.id,field:u,metadata:c[u],config:a[u]});let d=Object.hasOwn(c,"row")?c.row:a.row,l=Object.hasOwn(c,"column")?c.column:a.column;return Lr(s,"row",d,t.id),Lr(s,"column",l,t.id),{item:t,row:d??0,column:l??0,horizontalAlign:c.horizontalAlign??a.horizontalAlign??r.horizontalAlign,verticalAlign:c.verticalAlign??a.verticalAlign??r.verticalAlign,sourceOrder:o.get(t.id)??Number.MAX_SAFE_INTEGER,explicitRow:d!==void 0,explicitColumn:l!==void 0,explicitCell:d!==void 0&&l!==void 0}}e(vi,"resolveItemPlacement");function Ii(t,o,r){let i=r;while(o.has(`${t}:${i}`))i++;return i}e(Ii,"nextFreeColumn");function Mi(t,o,r){let i=r;while(o.has(`${i}:${t}`))i++;return i}e(Mi,"nextFreeRow");function Ci(t,o,r){let i=r;for(;;){let s=Math.floor(i/o)+1,a=i%o+1;if(i++,!t.has(`${s}:${a}`))return{row:s,column:a,nextIndex:i}}}e(Ci,"nextAutoCell");function Si(t,o,r){let i=[...t].sort(wi(o)),s=new Map,a=i.map((p)=>{let y=p.placementId??p.id,m=s.get(y)??0;return s.set(y,m+1),vi(p,o,r,m)}),c=new Map,d=new Set;for(let p of a){if(!p.explicitCell)continue;let y=`${p.row}:${p.column}`;d.add(y);let m=c.get(y);if(m){if(m.verticalAlign!==p.verticalAlign)throw V("GRID_CELL_ALIGNMENT_CONFLICT",`Conflicting vertical alignment in cell (${p.row}, ${p.column})`,{containerId:p.item.parentId??"root",row:p.row,column:p.column,itemIds:[...m.items.map((b)=>b.item.id),p.item.id],values:[...m.items.map((b)=>b.verticalAlign),p.verticalAlign]});m.items.push(p)}else c.set(y,{row:p.row,column:p.column,items:[p],width:0,height:0,verticalAlign:p.verticalAlign})}let l=r.columns>0?r.columns:Math.max(1,Math.ceil(Math.sqrt(i.length))),u=0,h=new Map,f=new Map;for(let p of a){if(p.explicitCell)continue;if(p.explicitRow){let m=Ii(p.row,d,h.get(p.row)??1);p.column=m,h.set(p.row,m+1)}else if(p.explicitColumn){let m=Mi(p.column,d,f.get(p.column)??1);p.row=m,f.set(p.column,m+1)}else{let m=Ci(d,l,u);p.row=m.row,p.column=m.column,u=m.nextIndex}let y=`${p.row}:${p.column}`;d.add(y),c.set(y,{row:p.row,column:p.column,items:[p],width:0,height:0,verticalAlign:p.verticalAlign})}return{placements:a,cells:c}}e(Si,"resolveGridPlacements");var Tt=class extends Error{constructor(t,o,r){super(o);this.reason=t,this.searchStateScope=r,this.name="GridRoutingResourceLimitError"}static{e(this,"GridRoutingResourceLimitError")}},K=6,ee=24,Wr=50000,Yr=4,jt=67108864,qr=class{constructor(t,o){this.bands=t,this.strictBoundaryIntervals=o,this.byLow=new Map,this.byHigh=new Map,this.coordinateCount=new Set(t.flatMap(({low:i,high:s})=>[i,s])).size;let r=t.reduce((i,s)=>i+s.intervals.length,0);for(let i of o.values())r+=i.length;this.intervalCount=r;for(let i of t)this.byLow.set(i.low,i),this.byHigh.set(i.high,i);Object.freeze(this.bands),Object.freeze(this)}static{e(this,"CompressedIntervalIndex")}containingBand(t){let o=0,r=this.bands.length-1;while(o<=r){let i=o+r>>>1,s=this.bands[i];if(t<=s.low)r=i-1;else if(t>=s.high)o=i+1;else return s}return}overlaps(t,o,r){let i=0,s=t.length;while(i<s){let a=i+s>>>1;if(t[a][1]<=o)i=a+1;else s=a}return i<t.length&&t[i][0]<r}intersects(t,o,r){let i=Math.min(o,r),s=Math.max(o,r),a=this.byHigh.get(t),c=this.byLow.get(t),d=a||c?void 0:this.containingBand(t);if(d)return this.overlaps(d.intervals,i,s);if(!a||!c)return!1;let l=0,u=0;while(l<a.intervals.length&&u<c.intervals.length){let h=Math.max(i,a.intervals[l][0],c.intervals[u][0]),f=Math.min(s,a.intervals[l][1],c.intervals[u][1]);if(h<f)return!0;if(a.intervals[l][1]<c.intervals[u][1])l++;else u++}return!1}contains(t,o){let r=this.strictBoundaryIntervals.get(t)??this.containingBand(t)?.intervals;if(!r)return!1;let i=0,s=r.length;while(i<s){let a=i+s>>>1;if(r[a][0]<o)i=a+1;else s=a}return i>0&&o<r[i-1][1]}nearestBoundary(t,o,r){let i=this.strictBoundaryIntervals.get(t)??this.containingBand(t)?.intervals;if(!i)return;if(r<0){let c=0,d=i.length;while(c<d){let l=c+d>>>1;if(i[l][1]<=o)c=l+1;else d=l}return c>0?i[c-1][1]:void 0}let s=0,a=i.length;while(s<a){let c=s+a>>>1;if(i[c][0]<o)s=c+1;else a=c}return s<i.length?i[s][0]:void 0}},bo,We=class{constructor(t){this.backing=t,this[bo]="ImmutableMap",Object.freeze(this)}static{e(this,"ImmutableMap")}get size(){return this.backing.size}entries(){return this.backing.entries()}forEach(t,o){for(let[r,i]of this.backing)t.call(o,i,r,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()}[(bo=Symbol.toStringTag,Symbol.iterator)](){return this.entries()}},wo,vo=class{constructor(t,o){this.base=t,this.overrides=o,this[wo]="OverlayMap"}static{e(this,"OverlayMap")}get size(){let t=0;for(let o of this.overrides.keys())if(!this.base.has(o))t++;return this.base.size+t}materialize(){return new Map([...this.base,...this.overrides])}entries(){return this.materialize().entries()}forEach(t,o){for(let[r,i]of this)t.call(o,i,r,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()}[(wo=Symbol.toStringTag,Symbol.iterator)](){return this.entries()}};function Ei(t,o){return new Proxy([],{get(r,i){if(i==="length")return t.length+o.length;if(i===Symbol.iterator)return function*(){yield*t,yield*o};if(typeof i==="string"&&/^\d+$/.test(i)){let s=Number(i);return s<t.length?t[s]:o[s-t.length]}return Reflect.get(Array.prototype,i)}})}e(Ei,"overlayArray");function hn(t,o,r){return new Proxy([],{get(i,s){if(s==="length")return r;if(s===Symbol.iterator)return function*(){for(let a=0;a<r;a++)yield o.get(a)??t[a]};if(typeof s==="string"&&/^\d+$/.test(s)){let a=Number(s);return o.get(a)??t[a]}return Reflect.get(Array.prototype,s)}})}e(hn,"overrideArray");var Ri=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{e(this,"EndpointOverlayScratch")}reset(t){if(t!==this.base)throw Error("Endpoint overlay scratch cannot be shared across base topologies");for(let o of this.undoLog)this.adjacencyOverrides.delete(o),this.searchAdjacencyOverrides.delete(o);this.undoLog.length=0,this.addedVertices.length=0,this.pointOverrides.clear(),this.resetCount++}setArcs(t,o){if(!this.adjacencyOverrides.has(t))this.undoLog.push(t);this.adjacencyOverrides.set(t,o),this.searchAdjacencyOverrides.set(t,Jn(o))}};function Dt(t){return Object.is(t,-0)?0:t}e(Dt,"normalizeCoordinate");function Ie(t){if(![t.left,t.right,t.top,t.bottom].every(Number.isFinite))throw Error("Grid routing geometry must contain only finite coordinates");let r=Dt(Math.min(t.left,t.right)),i=Dt(Math.max(t.left,t.right)),s=Dt(Math.min(t.top,t.bottom)),a=Dt(Math.max(t.top,t.bottom));if(r===i||s===a)throw Error("Grid routing rectangles must have positive area");return{left:r,right:i,top:s,bottom:a}}e(Ie,"normalizeRect");function Ai(t,o){let r=Ie(t.bounds),i={id:t.id,left:Math.max(o.left,r.left-K),right:Math.min(o.right,r.right+K),top:Math.max(o.top,r.top-K),bottom:Math.min(o.bottom,r.bottom+K)};return i.left<i.right&&i.top<i.bottom?i:void 0}e(Ai,"inflateAndClip");function Qn(t){let o=[...t].sort((i,s)=>i.low-s.low||i.high-s.high||W(i.id,s.id)),r=[];for(let i of o){let s=r.at(-1);if(!s||i.low>s.high){r.push({...i});continue}if(s.high=Math.max(s.high,i.high),W(i.id,s.id)<0)s.id=i.id}return r}e(Qn,"mergeObstacleIntervals");function Oi(t){let o=new Map;for(let c of t){let d=o.get(c.left)??{starts:[],ends:[]};d.starts.push(c),o.set(c.left,d);let l=o.get(c.right)??{starts:[],ends:[]};l.ends.push(c),o.set(c.right,l)}let r=[...o.keys()].sort((c,d)=>c-d),i=new Set,s=[],a=new Map;for(let c=0;c<r.length-1;c++){let d=r[c],l=r[c+1],u=o.get(d);for(let f of u.ends)i.delete(f);for(let f of u.starts)i.add(f);let h=new Map;for(let f of Qn([...i].map((p)=>({low:p.top,high:p.bottom,id:p.id})))){let p=`${f.low}:${f.high}`,y=a.get(p);if(y){if(y.right=l,W(f.id,y.id)<0)y.id=f.id}else{let m={id:f.id,left:d,right:l,top:f.low,bottom:f.high};s.push(m),h.set(p,m);continue}h.set(p,y)}a=h}return s.sort((c,d)=>c.top-d.top||c.left-d.left||c.bottom-d.bottom||c.right-d.right||W(c.id,d.id))}e(Oi,"unionObstacles");function yt(t){return`${Dt(t.x)}:${Dt(t.y)}`}e(yt,"routingPointKey");function Me(t){return t==="left"?0:t==="right"?1:t==="top"?2:t==="bottom"?3:4}e(Me,"topologySideOrdinal");function Ye(t,o){return W(t.kind,o.kind)||Me(t.side)-Me(o.side)||t.point.x-o.point.x||t.point.y-o.point.y||W(t.ownerId??"",o.ownerId??"")}e(Ye,"vertexRecordOrder");function qe(t){let o=new Map;for(let r of[...t].sort(Ye)){let i={...r,point:{x:Dt(r.point.x),y:Dt(r.point.y)}},s=yt(i.point);if(!o.has(s))o.set(s,i)}return[...o.values()]}e(qe,"canonicalRecords");function fn(t,o,r="corner"){return[{point:{x:t.left,y:t.top},kind:r,ownerId:o},{point:{x:t.right,y:t.top},kind:r,ownerId:o},{point:{x:t.left,y:t.bottom},kind:r,ownerId:o},{point:{x:t.right,y:t.bottom},kind:r,ownerId:o}]}e(fn,"cornerRecords");function Bi(t,o){let r=t.coordinate??(t.side==="left"?o.left:t.side==="right"?o.right:t.side==="top"?o.top:o.bottom);return(t.side==="left"||t.side==="right"?[{x:r,y:t.low},{x:r,y:t.high}]:[{x:t.low,y:r},{x:t.high,y:r}]).map((s)=>({point:s,kind:"portal",ownerId:t.ownerId,side:t.side}))}e(Bi,"portalRecords");function Zn(t,o,r,i,s){if(o==="left"||o==="right")return{x:i.nearestBoundary(t.y,t.x,o==="left"?-1:1)??(o==="left"?r.left:r.right),y:t.y};let a=s.nearestBoundary(t.x,t.y,o==="top"?-1:1)??(o==="top"?r.top:r.bottom);return{x:t.x,y:a}}e(Zn,"rayHit");function pn(t,o,r){let i=[...new Set(t.flatMap((f)=>o==="H"?[f.top,f.bottom]:[f.left,f.right]))].sort((f,p)=>f-p),s=[],a=new Map,c=new Map,d=new Map;for(let f of t){let p=o==="H"?f.top:f.left,y=o==="H"?f.bottom:f.right,m=c.get(p)??[];m.push(f),c.set(p,m);let b=d.get(y)??[];b.push(f),d.set(y,b)}let l=new Set,u=e(()=>Qn([...l].map((f)=>o==="H"?{low:f.left,high:f.right,id:f.id}:{low:f.top,high:f.bottom,id:f.id})),"activeIntervals"),h=e((f)=>{let p=r.intervalCount+f.length;return Ut(Te(0,0,t.length,p),r.maxEstimatedBytes,"estimated_memory_cap"),r.intervalCount=p,Object.freeze(f.map((y)=>Object.freeze([y.low,y.high])))},"freezeIntervals");for(let f=0;f<i.length;f++){let p=i[f];for(let b of d.get(p)??[])l.delete(b);a.set(p,h(u()));for(let b of c.get(p)??[])l.add(b);let y=i[f+1];if(y===void 0)continue;let m=u();if(m.length>0)s.push({low:p,high:y,intervals:h(m)})}return new qr(Object.freeze(s),new We(a))}e(pn,"createIntervalIndex");function Te(t,o,r,i){return t*64+o*56+r*48+i*24}e(Te,"estimatedTopologyBytes");function Ut(t,o,r){if(t>o)throw new Tt(r,`Grid routing ${r} exceeded: ${t} > ${o}`)}e(Ut,"enforceCap");function gn(t,o){let r=new Map;for(let i of t){let s=o==="H"?i.point.y:i.point.x,a=r.get(s)??[];a.push(i),r.set(s,a)}for(let i of r.values())i.sort((s,a)=>o==="H"?s.point.x-a.point.x||s.id-a.id:s.point.y-a.point.y||s.id-a.id),Object.freeze(i);return new We(r)}e(gn,"indexVertexLines");function Jn(t){return Object.freeze(t.map((o)=>Object.freeze({to:o.to,orientationOrdinal:o.orientation==="H"?1:2,length:o.length,boundaryTransitions:o.kind==="portal"?1:0})))}e(Jn,"searchArcs");function Li(t,o,r,i){let s=qe(t).sort(Ye),a=i.maxVertices??Wr;Ut(s.length,a,"vertex_cap");let c=s.map((p,y)=>Object.freeze({id:y,...p,point:Object.freeze({...p.point})})),d=new Map(c.map((p)=>[p.id,[]])),l=e((p,y,m)=>{let b=Math.abs(p.point.x-y.point.x)+Math.abs(p.point.y-y.point.y);if(b===0)return;let g=m==="H"?Math.min(p.point.x,y.point.x):Math.min(p.point.y,y.point.y),x=g+b;for(let[w,M]of[[p,y],[y,p]])d.get(w.id).push({from:w.id,to:M.id,orientation:m,length:b,kind:"visibility",intervalStart:g,intervalEnd:x})},"addArcPair");for(let p of["H","V"]){let y=new Map;for(let m of c){let b=p==="H"?m.point.y:m.point.x,g=y.get(b)??[];g.push(m),y.set(b,g)}for(let[m,b]of y){b.sort((g,x)=>p==="H"?g.point.x-x.point.x||g.id-x.id:g.point.y-x.point.y||g.id-x.id);for(let g=1;g<b.length;g++){let x=b[g-1],w=b[g],M=p==="H"?x.point.x:x.point.y,S=p==="H"?w.point.x:w.point.y;if(!(p==="H"?o:r).intersects(m,M,S))l(x,w,p)}}}let u={visibility:0,terminal:1,portal:2,lane:3},h=0,f=new Map;for(let p of c){let y=d.get(p.id);y.sort((b,g)=>u[b.kind]-u[g.kind]||W(b.orientation,g.orientation)||c[b.to].point.x-c[g.to].point.x||c[b.to].point.y-c[g.to].point.y||b.to-g.to);let m=y.filter((b,g)=>g===0||b.to!==y[g-1].to||b.orientation!==y[g-1].orientation||b.kind!==y[g-1].kind);h+=m.length,f.set(p.id,Object.freeze(m.map((b)=>Object.freeze(b))))}return Ut(h,i.maxAdjacencyEntries??a*Yr,"adjacency_cap"),{vertices:Object.freeze(c),adjacency:new We(f),adjacencyEntries:h}}e(Li,"buildVisibilityGraph");function se(t,o,r){let i=Ie(o),s=r?Ie(r):void 0,a=Math.max(i.top+K,(s?.bottom??-1/0)+K),c=i.bottom-K,d=i.left+K,l=i.right-K,u=[];if(a<=c)u.push({ownerId:t,side:"left",low:a,high:c},{ownerId:t,side:"right",low:a,high:c});if(d<=l){if(u.push({ownerId:t,side:"bottom",low:d,high:l}),!s||s.bottom+K<=i.top)u.push({ownerId:t,side:"top",low:d,high:l})}return u}e(se,"derivePortalRanges");function mn(t,o,r,i,s){let a=se(t,o,r).find((f)=>f.side===i);if(!a||s<a.low||s>a.high)throw Error(`Illegal ${i} portal for "${t}" at ${s}`);let c=i==="left"?o.left:i==="right"?o.right:i==="top"?o.top:o.bottom,d=i==="left"||i==="top"?c+K:c-K,l=i==="left"||i==="top"?c-K:c+K,u=i==="left"||i==="right"?{x:d,y:s}:{x:s,y:d},h=i==="left"||i==="right"?{x:l,y:s}:{x:s,y:l};return{ownerId:t,side:i,tangentialCoordinate:s,interior:u,exterior:h,transition:{from:u,to:h,orientation:i==="left"||i==="right"?"H":"V",length:K*2,kind:"portal"}}}e(mn,"buildPairedPortal");function Pi(t,o={}){let r=Ie(t.bounds),i=[...t.obstacles,...t.titleExclusions??[]].map((g)=>Ai(g,r)).filter((g)=>Boolean(g)),s=Oi(i),a=[...t.portalRanges??[]].sort((g,x)=>Me(g.side)-Me(x.side)||g.low-x.low||g.high-x.high||W(g.ownerId,x.ownerId)),c=qe([...fn(r,t.containerId),...s.flatMap((g)=>fn(g,g.id)),...a.flatMap((g)=>Bi(g,r))]),d={intervalCount:0,maxEstimatedBytes:o.caps?.maxEstimatedBytes??jt};Ut(Te(0,0,s.length,0),d.maxEstimatedBytes,"estimated_memory_cap");let l=pn(s,"H",d),u=pn(s,"V",d),h=[],f=["left","right","top","bottom"];for(let g of c)for(let x of f){let w=Zn(g.point,x,r,l,u);if(w.x!==g.point.x||w.y!==g.point.y)h.push({point:w,kind:"projection",side:x})}let{vertices:p,adjacency:y,adjacencyEntries:m}=Li([...c,...h],l,u,o.caps??{}),b=Te(p.length,m,s.length,l.intervalCount+u.intervalCount);if(Ut(b,o.caps?.maxEstimatedBytes??jt,"estimated_memory_cap"),o.metrics)o.metrics.containersBuilt++,o.metrics.baseTopologyBuilds++,o.metrics.baseVertices+=p.length,o.metrics.baseAdjacencyEntries+=m,o.metrics.buildSweepEvents+=c.length*4+s.length*4,o.metrics.estimatedBytes+=b;return Object.freeze({containerId:t.containerId,bounds:Object.freeze(r),obstacles:Object.freeze(s.map((g)=>Object.freeze(g))),vertices:Object.freeze(p),pointVertexIds:new We(new Map(p.map(({id:g,point:x})=>[yt(x),g]))),horizontalVertexLines:gn(p,"H"),verticalVertexLines:gn(p,"V"),adjacency:y,adjacencyByVertex:Object.freeze(p.map(({id:g})=>y.get(g)??[])),searchAdjacencyByVertex:Object.freeze(p.map(({id:g})=>Jn(y.get(g)??[]))),adjacencyEntries:m,horizontalIntervals:l,verticalIntervals:u,portalRanges:Object.freeze(a.map((g)=>Object.freeze(g))),seedCount:c.length,estimatedBytes:b})}e(Pi,"buildContainerRoutingTopology");function yn(t,o){return o.contains(t.y,t.x)}e(yn,"pointInsideObstacle");function Qe(t,o,r,i,s,a=[]){let c=s??new Ri(t);c.reset(t);let d=[{point:o,kind:"endpoint",ownerId:"source"},{point:r,kind:"endpoint",ownerId:"target"},...a.filter((I)=>!yn(I,t.horizontalIntervals)).map((I)=>({point:I,kind:"lane"}))];for(let I of[{x:o.x,y:r.y},{x:r.x,y:o.y}])if(!yn(I,t.horizontalIntervals))d.push({point:I,kind:"projection"});for(let I of d.slice(0,2))for(let v of["left","right","top","bottom"]){let R=Zn(I.point,v,t.bounds,t.horizontalIntervals,t.verticalIntervals);if(R.x!==I.point.x||R.y!==I.point.y)d.push({point:R,kind:"projection",side:v})}let l=qe(d).filter(({point:I})=>!t.pointVertexIds.has(yt(I))).sort(Ye);Ut(l.length,32,"vertex_cap"),c.addedVertices.push(...l.map((I,v)=>Object.freeze({id:t.vertices.length+v,...I,point:Object.freeze({...I.point})})));let u=Ei(t.vertices,c.addedVertices),h=e((I)=>I<t.vertices.length?t.vertices[I]:c.addedVertices[I-t.vertices.length],"vertexAt"),f=new Map,p=e((I)=>{let v=f.get(I);if(!v)v=[...t.adjacency.get(I)??[]],f.set(I,v);return v},"mutableArcs");for(let I of c.addedVertices)f.set(I.id,[]);let y=new Set(c.addedVertices.map(({id:I})=>I)),m=new Set,b=e((I,v,R)=>{let A=Math.abs(I.point.x-v.point.x)+Math.abs(I.point.y-v.point.y);if(A===0)return;let C=R==="H"?Math.min(I.point.x,v.point.x):Math.min(I.point.y,v.point.y),O=C+A;for(let[P,L]of[[I,v],[v,I]]){let N=`${P.id}:${L.id}:${R}:visibility`;if(m.has(N)||(t.adjacency.get(P.id)??[]).some((T)=>T.to===L.id&&T.orientation===R&&T.kind==="visibility"))continue;m.add(N),p(P.id).push({from:P.id,to:L.id,orientation:R,length:A,kind:"visibility",intervalStart:C,intervalEnd:O})}},"connect");for(let I of["H","V"]){let v=I==="H"?t.horizontalVertexLines:t.verticalVertexLines,R=new Set(c.addedVertices.map(({point:A})=>I==="H"?A.y:A.x));for(let A of R){let C=[...v.get(A)??[],...c.addedVertices.filter(({point:O})=>(I==="H"?O.y:O.x)===A)];C.sort((O,P)=>I==="H"?O.point.x-P.point.x||O.id-P.id:O.point.y-P.point.y||O.id-P.id);for(let O=1;O<C.length;O++){let P=C[O-1],L=C[O];if(!y.has(P.id)&&!y.has(L.id))continue;let N=I==="H"?P.point.x:P.point.y,T=I==="H"?L.point.x:L.point.y;if(!(I==="H"?t.horizontalIntervals:t.verticalIntervals).intersects(A,N,T))b(P,L,I)}}}for(let[I,v]of f){v.sort((A,C)=>W(A.kind,C.kind)||W(A.orientation,C.orientation)||h(A.to).point.x-h(C.to).point.x||h(A.to).point.y-h(C.to).point.y||A.to-C.to);let R=Object.freeze(v.map((A)=>Object.freeze(A)));c.setArcs(I,R)}let g=t.adjacencyEntries+m.size;Ut(g,t.adjacencyEntries+64,"adjacency_cap");let x=l.length,w=t.estimatedBytes+x*64+(g-t.adjacencyEntries)*56;if(i)i.endpointOverlayBuilds++,i.endpointOverlayVertices+=x,i.estimatedBytes=Math.max(i.estimatedBytes,w);let M=t.vertices.length+c.addedVertices.length,S=hn(t.adjacencyByVertex,c.adjacencyOverrides,M),E=hn(t.searchAdjacencyByVertex,c.searchAdjacencyOverrides,M);for(let I of c.addedVertices)c.pointOverrides.set(yt(I.point),I.id);return Object.freeze({...t,vertices:u,pointVertexIds:new vo(t.pointVertexIds,c.pointOverrides),adjacency:new vo(t.adjacency,c.adjacencyOverrides),adjacencyByVertex:S,searchAdjacencyByVertex:E,adjacencyEntries:g,estimatedBytes:w,vertexCount:M,getVertex:h,getSearchArcs:e((I)=>c.searchAdjacencyOverrides.get(I)??t.searchAdjacencyByVertex[I]??[],"getSearchArcs")})}e(Qe,"buildEndpointRoutingOverlay");var Ce=4,Z=20,Ne=8;function Ze(t){return Boolean(t.groupTitleRect)}e(Ze,"ownerGroupTitle");function ae(t,o){return JSON.stringify([t,o])}e(ae,"ownerSideKey");function Je(t,o){let r=z(t),i=o.x-r.cx,s=o.y-r.cy,a=t.isGroup&&Ze(t);if(Math.abs(i)>=Math.abs(s))return i>=0?"right":"left";if(s>=0)return"bottom";if(a)return i>=0?"right":"left";return"top"}e(Je,"preferredSide");function Fe(t,o){let r=[],i=t.parentId??X,s=new Set;while(!0){if(r.push(i),i===X)break;if(s.has(i))break;s.add(i),i=o.get(i)?.parentId??X}return r}e(Fe,"containerChain");function _i(t,o,r){if(t.isGroup&&Kt(t.id,o,r))return t.parentId??X;if(o.isGroup&&Kt(o.id,t,r))return o.parentId??X;let i=new Set(Fe(o,r));for(let s of Fe(t,r))if(i.has(s))return s;return X}e(_i,"commonContainerId");function De(t,o){return o==="left"||o==="right"?t.cy:t.cx}e(De,"oppositeCoordFor");function ce(t,o){return o==="left"||o==="right"?{x:o==="left"?t.left:t.right,y:t.cy}:{x:t.cx,y:o==="top"?t.top:t.bottom}}e(ce,"sideMidpoint");function ke(t,o){return o==="left"||o==="right"?t.y:t.x}e(ke,"tangentialCoordinate");function xn(t,o,r,i,s,a){let c=[],d=z(t),l=z(o),u={x:o.x??0,y:o.y??0},h=t;for(;;){let f=h.parentId??X,p=i.get(f),y={x:h.x??0,y:h.y??0},m=u.x-y.x,b=u.y-y.y,g=b<0&&Math.abs(m)<=rt&&Boolean((h.isGroup?h.groupTitleRect:void 0)??p?.groupTitleRect),x=[];if(Math.abs(Math.abs(m)-Math.abs(b))<=rt&&Math.abs(m)>rt)x.push(m>=0?"right":"left",b>=0?"bottom":"top");let w=Boolean((h.isGroup?h.groupTitleRect:void 0)??p?.groupTitleRect),M=(g?["left","right"]:x).filter((E)=>E!=="top"||!w),S=Je(h,u);if(S==="top"&&p?.groupTitleRect)S=m>=0?"right":"left";if(c.push({ownerId:h.id,side:S,demandKey:JSON.stringify([s,a,h.id,S]),oppositeCoord:De(l,S),preferredCoord:De(d,S),compactPortal:h.id!==t.id,ambiguousSides:M.length>1?M:void 0,inner:c.length?{demandKey:c[c.length-1].demandKey,side:c[c.length-1].side}:void 0}),h.isGroup&&h.id===r&&Kt(h.id,o,i))return{chain:c,finalKind:"boundary"};if(f===r)return{chain:c,finalKind:"item"};if(!p?.isGroup)throw V("GRID_INVALID_CONTAINMENT",`Missing parent group "${f}"`,{traversedIds:c.map((E)=>E.ownerId)});h=p}}e(xn,"buildEndpointPlan");function Gi(t){let o=new Map;for(let i of t){if(!i.start||!i.end)continue;let s=i.start<i.end?`${i.start}|${i.end}`:`${i.end}|${i.start}`;if(!o.has(s))o.set(s,[]);o.get(s).push(i)}let r=new Map;for(let[i,s]of o)s.sort((a,c)=>W(`${a.start}|${a.end}`,`${c.start}|${c.end}`)||W(a.id,c.id)),s.forEach((a,c)=>r.set(a.id,{index:c,size:s.length,offset:(c-(s.length-1)/2)*Ne,pairKey:i}));return r}e(Gi,"buildPairLanes");function Ti(t,o){let r=new Map,i=e((c,d)=>ae(c,d),"reservationKey");for(let c of t)for(let d of[...c.source.chain,...c.target.chain])if(!d.ambiguousSides){let l=i(d.ownerId,d.side);r.set(l,(r.get(l)??0)+1)}let s=e((c,d,l)=>{let u=d.chain.filter(({ambiguousSides:p})=>p);if(u.length===0)return;let f=["right","bottom","left","top"].filter((p)=>u.every((y)=>y.ambiguousSides?.includes(p))&&u.every((y)=>{let m=o.forest.nodeById.get(y.ownerId);return m!==void 0&&Lt(m,p)!==void 0})).sort((p,y)=>u.reduce((m,b)=>m+(r.get(i(b.ownerId,p))??0),0)-u.reduce((m,b)=>m+(r.get(i(b.ownerId,y))??0),0)||Number(p!==u[0].side)-Number(y!==u[0].side))[0];if(!f)return;for(let p of u){p.side=f;let y=i(p.ownerId,f);r.set(y,(r.get(y)??0)+1);let m=o.forest.nodeById.get(p.ownerId);if(m)p.preferredCoord=De(z(m),f)}for(let[p,y]of d.chain.entries())y.demandKey=JSON.stringify([c.edge.id,l,y.ownerId,y.side]),y.inner=p>0?{demandKey:d.chain[p-1].demandKey,side:d.chain[p-1].side}:void 0},"resolveEndpoint"),a=t.flatMap((c)=>[{plan:c,endpoint:c.source,role:"source"},{plan:c,endpoint:c.target,role:"target"}]).sort((c,d)=>W(`${c.plan.edge.start??""}|${c.plan.edge.end??""}|${c.plan.edge.id}|${c.role}`,`${d.plan.edge.start??""}|${d.plan.edge.end??""}|${d.plan.edge.id}|${d.role}`));for(let{plan:c,endpoint:d,role:l}of a)s(c,d,l);for(let c of t){let d=c.source.chain.at(-1),l=c.target.chain.at(-1),u=d?o.forest.nodeById.get(d.ownerId):void 0,h=l?o.forest.nodeById.get(l.ownerId):void 0;if(!d||!l||!u||!h)continue;let f=ce(z(u),d.side),p=ce(z(h),l.side);for(let y of c.source.chain)y.oppositeCoord=ke(p,y.side);for(let y of c.target.chain)y.oppositeCoord=ke(f,y.side)}}e(Ti,"resolveAmbiguousEndpointSides");function Ni(t,o){let r=o.forest.nodeById,i=Gi(t.edges),s=t.edges.map((a)=>{let c=a.start?r.get(a.start):void 0,d=a.end?r.get(a.end):void 0;if(!c||!d)throw V("GRID_MISSING_ENDPOINT",`Missing endpoint for edge "${a.id}"`,{edgeId:a.id,start:a.start,end:a.end});let l=_i(c,d,r),u=i.get(a.id)??{index:0,size:1,offset:0,pairKey:_t(a)};return{edge:a,lcaContainerId:l,source:xn(c,d,l,r,a.id,"source"),target:xn(d,c,l,r,a.id,"target"),laneIndex:u.index,laneOffset:u.offset,bundleSize:u.size,pairKey:u.pairKey}});return Ti(s,o),s}e(Ni,"collectRoutePlans");function to(t,o,r){let i=[];for(let[u,h]of t.entries())i.push(u===0?h:Math.max(h,i[u-1]+Ce));for(let u=i.length-1;u>=0;u--)i[u]=Math.min(i[u],u===i.length-1?r:i[u+1]-Ce);let s=t.reduce((u,h)=>u+h,0)/t.length,a=i.reduce((u,h)=>u+h,0)/i.length,c=o-i[0],d=r-i[i.length-1],l=Gt(s-a,c,d);return i.map((u)=>u+l)}e(to,"assignCompactPortalCoordinates");function Fi(t,o,r){let i=o.forest.nodeById,s=new Map(t.map((h)=>[h.edge.id,h])),a=new Map;for(let h of t){if(h.edge.start===h.edge.end)continue;for(let f of[...h.source.chain,...h.target.chain])if(!a.has(f.demandKey))a.set(f.demandKey,{ownerId:f.ownerId,side:f.side,edgeId:h.edge.id,demandKey:f.demandKey,oppositeCoord:f.oppositeCoord,preferredCoord:f.preferredCoord,compactPortal:f.compactPortal,inner:f.inner})}let c=new Map;for(let h of a.values()){let f=ae(h.ownerId,h.side),p=c.get(f)??{ownerId:h.ownerId,side:h.side,demands:[]};p.demands.push(h),c.set(f,p)}let d=e((h)=>{let f=i.get(h);return f?Fe(f,i).length:0},"depthOf"),l=[...c.values()].sort((h,f)=>Number(h.demands.every((p)=>p.compactPortal))-Number(f.demands.every((p)=>p.compactPortal))||d(f.ownerId)-d(h.ownerId)),u=new Map;for(let{ownerId:h,side:f,demands:p}of l){let y=i.get(h);if(!y)continue;let m=z(y),b=f==="left"||f==="right"?m.top+K:m.left+K,g=f==="left"||f==="right"?m.bottom-K:m.right-K;if((f==="left"||f==="right")&&y.groupTitleRect)b=Math.max(b,y.groupTitleRect.bottom+K);let x=Math.max(0,g-b);p.sort((I,v)=>I.oppositeCoord-v.oppositeCoord||W(I.edgeId,v.edgeId));let w=p.map((I)=>s.get(I.edgeId)),M=new Set(w.map((I)=>I?.pairKey)),S=y.isGroup&&p.every(({compactPortal:I})=>I);if(!(S&&p.length===1)&&M.size===1&&w.every((I)=>I&&I.bundleSize===p.length&&r.get(I.edge.start)===I.bundleSize&&r.get(I.edge.end)===I.bundleSize)){let I=(b+g)/2,v=w.map((R)=>I+R.laneOffset);if(v.every((R)=>R>=b&&R<=g)){p.forEach((R,A)=>u.set(R.demandKey,v[A]));continue}}if(S){let I=o.containers.get(y.id),v=f==="left"||f==="right"?I?.horizontalCorridors:I?.verticalCorridors,R=e((C)=>{let O=C.inner?a.get(C.inner.demandKey):void 0,P=O?i.get(O.ownerId):void 0,L=O?u.get(O.demandKey):void 0;if(!O||!P||L===void 0)return C.preferredCoord;let N=ce(z(P),O.side);if(O.side==="left"||O.side==="right")N.y=L;else N.x=L;return ke(N,f)},"innerCoordinate"),A=e((C)=>{let O=C.inner?u.get(C.inner.demandKey):void 0,P=C.inner!==void 0&&O!==void 0&&(C.inner.side==="left"||C.inner.side==="right")===(f==="left"||f==="right"),L=Gt(P?O:C.preferredCoord,b,g),N=v?.reduce((T,Y)=>Math.abs(Y-L)<Math.abs(T-L)?Y:T,v[0]);return N!==void 0&&Math.abs(N-L)<=rt?N:L},"preferredCoordinate");if(p.length===1){u.set(p[0].demandKey,A(p[0]));continue}if(x>=Ce*(p.length-1)){p.sort((P,L)=>R(P)-R(L)||P.oppositeCoord-L.oppositeCoord||W(P.edgeId,L.edgeId));let C=p.map(A),O=to(C,b,g);p.forEach((P,L)=>u.set(P.demandKey,O[L]));continue}}if(p.length===1||x<=0){u.set(p[0].demandKey,(b+g)/2);continue}let E=x/(p.length-1);p.forEach((I,v)=>{u.set(I.demandKey,b+E*v)})}for(let h of t){if(h.bundleSize!==1)continue;let f=h.source.chain.at(-1),p=h.target.chain.at(-1);if(!f||!p)continue;let y=e((w)=>w==="left"||w==="right","verticalSide");if(y(f.side)!==y(p.side))continue;let m=u.get(f.demandKey),b=u.get(p.demandKey);if(m===void 0||b===void 0||Math.abs(m-b)>rt)continue;let g=[...h.source.chain,...h.target.chain];if(g.some((w)=>y(w.side)!==y(f.side)))continue;let x=[m,b].find((w)=>g.every((M)=>{let S=i.get(M.ownerId),E=S?Lt(S,M.side):void 0;return E!==void 0&&w>=E.low-rt&&w<=E.high+rt}));if(x!==void 0)g.forEach((w)=>u.set(w.demandKey,x))}return u}e(Fi,"assignDemandCoordinates");function kt(t){return t==="right"?0:t==="bottom"?1:t==="left"?2:3}e(kt,"sideOrder");function Lt(t,o){let r=z(t);if(o==="top"&&t.groupTitleRect)return;let i=o==="left"||o==="right"?r.top+K:r.left+K,s=o==="left"||o==="right"?r.bottom-K:r.right-K;if((o==="left"||o==="right")&&t.groupTitleRect)i=Math.max(i,t.groupTitleRect.bottom+K);return i<=s?{low:i,high:s}:void 0}e(Lt,"sideInterval");function _t(t){let o=t.start??"",r=t.end??"";return o<r?`${o}|${r}`:`${r}|${o}`}e(_t,"endpointPairKey");function eo(t,o,r){let i=z(t.opposite),s=z(o.opposite),a=r==="left"||r==="right"?i.cy:i.cx,c=r==="left"||r==="right"?s.cy:s.cx;return a-c||W(_t(t.plan.edge),_t(o.plan.edge))||W(`${t.plan.edge.start}|${t.plan.edge.end}`,`${o.plan.edge.start}|${o.plan.edge.end}`)||W(t.plan.edge.id,o.plan.edge.id)||W(t.role,o.role)}e(eo,"compareEndpointDemands");function Di(t){return`${t.plan.edge.id}:${t.role}`}e(Di,"endpointDemandKey");function ki(t,o){return W(_t(t.plan.edge),_t(o.plan.edge))||W(`${t.plan.edge.start}|${t.plan.edge.end}`,`${o.plan.edge.start}|${o.plan.edge.end}`)||W(t.plan.edge.id,o.plan.edge.id)||W(t.role,o.role)}e(ki,"compareEndpointDemandIdentity");function ze(t,o,r){let i=Lt(t,o);if(!i||r.length===0)return new Map;let s=[...r].sort((d,l)=>eo(d,l,o));if(s.length===1){let d=z(t),l=o==="left"||o==="right"?d.cy:d.cx;return new Map([[s[0],Gt(l,i.low,i.high)]])}if((i.high-i.low)/(s.length-1)<Ce)return new Map(s.map((d,l)=>[d,i.low+l*(i.high-i.low)/(s.length-1)]));let a=s.map(({opposite:d})=>{let l=z(d),u=o==="left"||o==="right"?l.cy:l.cx;return Gt(u,i.low,i.high)}),c=to(a,i.low,i.high);return new Map(s.map((d,l)=>[d,c[l]]))}e(ze,"preferredEndpointCoordinates");function no(t,o){let r=Lt(t,o);if(!r)return 0;return 1+Math.floor((r.high-r.low)/Ce)}e(no,"endpointSideCapacity");function bn(t,o){let r=z(o.opposite),i=Je(t,{x:r.cx,y:r.cy});return["right","bottom","left","top"].filter((s)=>no(t,s)>0).sort((s,a)=>{if(s===i)return-1;if(a===i)return 1;let c=z(t),d=ce(c,s),l=ce(c,a),u=Math.abs(d.x-r.cx)+Math.abs(d.y-r.cy),h=Math.abs(l.x-r.cx)+Math.abs(l.y-r.cy);return u-h||kt(s)-kt(a)})}e(bn,"endpointSidePreferences");function ne(t,o){let r=z(t),i=z(o.opposite);return Math.abs(r.cx-i.cx)<=rt||Math.abs(r.cy-i.cy)<=rt}e(ne,"isAxisAlignedDemand");function zi(t,o,r,i){let s=Lt(t,o);if(!s)return;let a=[...r],c=new Map;for(let d of i){let l=z(d.opposite),u=Gt(o==="left"||o==="right"?l.cy:l.cx,s.low,s.high),h=[u,s.low,s.high,...a.flatMap((f)=>[f-ee,f+ee])].filter((f)=>f>=s.low-rt&&f<=s.high+rt&&a.every((p)=>Math.abs(f-p)>=ee-rt)).sort((f,p)=>Math.abs(f-u)-Math.abs(p-u)||f-p);if(h.length===0)return;c.set(d,h[0]),a.push(h[0])}return c}e(zi,"placePortsBesideFixed");function Hi(t,o){let r=new Map,i=new Map(["right","bottom","left","top"].map((g)=>[g,no(t,g)])),s=[...o].sort(ki),a=s.filter((g)=>ne(t,g)),c=s.filter((g)=>!ne(t,g)),d=new Set,l=new Map,u=new Map,h=e((g)=>(r.get(g)?.length??0)<(i.get(g)??0),"hasCapacity"),f=e((g,x)=>{let w=r.get(x)??[];w.push(g),r.set(x,w)},"record"),p=e((g)=>{let x=bn(t,g).find(h);if(x)f(g,x),d.add(x)},"assignAligned"),y=e((g,x)=>{let w=u.get(x)??new Map,M=zi(t,x,[...l.get(x)??[],...w.values()],[g]);if(!M)return!1;return w.set(g,M.get(g)),u.set(x,w),f(g,x),!0},"tryShareReservedSide"),m=e((g)=>{let x=bn(t,g).filter(h),w=x.find((E)=>!d.has(E));if(x.find((E)=>(w===void 0||x.indexOf(E)<x.indexOf(w))&&d.has(E)&&y(g,E)))return;let S=w??x[0];if(S)f(g,S)},"assignUnaligned");for(let g of a)p(g);for(let[g,x]of r)l.set(g,[...ze(t,g,x).values()]);for(let g of c)m(g);let b=new Map;for(let[g,x]of r){let w=Lt(t,g);if(!w)continue;let M=u.get(g),S=M?x.filter((v)=>!M.has(v)):x,E=new Map([...ze(t,g,S),...M??[]]),I=[...x].sort((v,R)=>eo(v,R,g));for(let[v,R]of I.entries()){let A=E.get(R)??(I.length===1?(w.low+w.high)/2:w.low+v*(w.high-w.low)/(I.length-1));b.set(Di(R),{side:g,coordinate:A})}}return b}e(Hi,"allocateEndpointSlots");function wn(t,o,r,i,s,a){let c=o==="source"?t.edge.start:t.edge.end,d=o==="source"?t.edge.end:t.edge.start,l=a.forest.nodeById.get(c),u=a.forest.nodeById.get(d);if(!l||!u)throw V("GRID_MISSING_ENDPOINT",`Missing endpoint for edge "${t.edge.id}"`);let h=z(u),f=[],p=new Set,y=i.get(c)?.get(`${t.edge.id}:${o}`),m=s.has(c)&&y!==void 0,b=e((x,w,M)=>{let S=Lt(l,x);if(!S||w<S.low||w>S.high)return;let E=z(l),I=x==="left"||x==="right"?{x:x==="left"?E.left:E.right,y:w}:{x:w,y:x==="top"?E.top:E.bottom},v=`${x}:${yt(I)}`;if(p.has(v))return;p.add(v),f.push({ownerId:c,side:x,port:I,connect:{x:I.x+(x==="left"?-Z:x==="right"?Z:0),y:I.y+(x==="top"?-Z:x==="bottom"?Z:0)},rank:M,onAssignedSide:m?x===y.side:void 0})},"addCandidate");if(y&&t.bundleSize===1)b(y.side,y.coordinate,-2);if(t.bundleSize>1){let x=Je(l,{x:h.cx,y:h.cy}),w=z(l),M=x==="left"||x==="right"?w.cy:w.cx;b(x,M+t.laneOffset,-1)}let g=[...r.get(c)??[]];for(let x of["right","bottom","left","top"]){if(!Lt(l,x))continue;let M=ze(l,x,g),S=g.find((A)=>A.plan===t&&A.role===o),E=S?M.get(S):void 0;if(E===void 0)continue;let I=z(l),v=x==="left"||x==="right"?{x:x==="left"?I.left:I.right,y:E}:{x:E,y:x==="top"?I.top:I.bottom},R=Math.abs(v.x-h.cx)+Math.abs(v.y-h.cy);b(x,E,R)}return f.sort((x,w)=>x.rank-w.rank||kt(x.side)-kt(w.side)),f.forEach((x,w)=>{x.rank=w}),f}e(wn,"endpointCandidates");function Vi(t,o){let r=Ni(t,o),i=new Map,s=new Map;for(let m of r){let b=_t(m.edge);if(i.set(b,(i.get(b)??0)+1),m.edge.start)s.set(m.edge.start,(s.get(m.edge.start)??0)+1);if(m.edge.end&&m.edge.end!==m.edge.start)s.set(m.edge.end,(s.get(m.edge.end)??0)+1)}let a=r.filter((m)=>m.edge.start!==m.edge.end&&m.source.chain.length===1&&m.target.chain.length===1&&m.source.finalKind==="item"&&m.target.finalKind==="item"),c=new Map;for(let m of a){let b=o.forest.nodeById.get(m.edge.start),g=o.forest.nodeById.get(m.edge.end);if(!b||!g)continue;let x=c.get(b.id)??[];x.push({plan:m,role:"source",opposite:g}),c.set(b.id,x);let w=c.get(g.id)??[];w.push({plan:m,role:"target",opposite:b}),c.set(g.id,w)}let d=new Map([...c].map(([m,b])=>{let g=o.forest.nodeById.get(m);return[m,g?Hi(g,b):new Map]})),l=new Set,u=new Set;for(let[m,b]of c){let g=o.forest.nodeById.get(m);if(!g)continue;let x=b.some((M)=>ne(g,M)),w=b.some((M)=>!ne(g,M));if(x&&w){u.add(m);for(let M of b)if(!ne(g,M))l.add(M.plan.edge.id)}}let h=new Map(a.map((m)=>[m.edge.id,{sources:wn(m,"source",c,d,u,o),targets:wn(m,"target",c,d,u,o)}])),f=new Map([...h].map(([m,b])=>[m,b.sources.length*b.targets.length])),p=e((m)=>{let b=o.forest.nodeById.get(m.edge.start),g=o.forest.nodeById.get(m.edge.end);if(m.edge.start===m.edge.end)return 0;if(b?.isGroup&&g&&Kt(b.id,g,o.forest.nodeById)||g?.isGroup&&b&&Kt(g.id,b,o.forest.nodeById))return 1;if((b?.parentId??X)!==(g?.parentId??X))return 2;return i.get(_t(m.edge))>1?3:4},"routeClass"),y=[...r].sort((m,b)=>{let g=_t(m.edge),x=_t(b.edge),w=`${m.edge.start??""}|${m.edge.end??""}`,M=`${b.edge.start??""}|${b.edge.end??""}`,S=m.source.chain.length+m.target.chain.length-2,E=b.source.chain.length+b.target.chain.length-2;return p(m)-p(b)||E-S||(f.get(m.edge.id)??0)-(f.get(b.edge.id)??0)||W(g,x)||W(w,M)||W(m.edge.id,b.edge.id)});return{plans:r,eligiblePlans:a,eligibleIds:new Set(a.map(({edge:m})=>m.id)),orderedPlans:y,demandCoords:Fi(y,o,s),endpointCandidatesByEdge:h,endpointIncidentCounts:s,coordinatedEndpointIds:l}}e(Vi,"prepareEdgeRoutes");function $i(t){if(!(t instanceof Error)||!("details"in t))return!1;let o=t.details;return typeof o==="object"&&o!==null&&"reason"in o&&o.reason==="pair-separation"}e($i,"isPairSeparationError");function Ft(t){let o=z(t);return{left:o.left,right:o.right,top:o.top,bottom:o.bottom}}e(Ft,"routerRect");function oo(t){if(t.length<2||t.some(({x:s,y:a})=>!Number.isFinite(s)||!Number.isFinite(a)))return;let o=[{...t[0]}];for(let s=1;s<t.length;s++){let a=t[s],c=o.at(-1);if(!(Math.abs(a.x-c.x)<=rt&&Math.abs(a.y-c.y)<=rt)){o.push({...a});continue}if(s!==t.length-1)continue;while(o.length>1){let l=o.at(-2);if(Math.abs(a.x-l.x)>rt||Math.abs(a.y-l.y)>rt)break;o.pop()}if(o.length===1)return;o[o.length-1]={...a}}if(o.length<2)return;let r=[];for(let s=0;s<o.length-1;s++){let a=o[s],c=o[s+1],d=Math.abs(c.x-a.x);if(Math.abs(c.y-a.y)<=rt)r.push("H");else if(d<=rt)r.push("V");else return}let i=o.map((s)=>({...s}));for(let s=0;s<r.length;){let a=r[s],c=s+1;while(c<r.length&&r[c]===a)c++;let d=a==="H"?"y":"x";if(s===0&&c===o.length-1&&o[s][d]!==o[c][d])return;let l=c===o.length-1?o[c][d]:o[s][d];for(let u=s;u<=c;u++){if(Math.abs(o[u][d]-l)>rt)return;i[u][d]=l}s=c}return i}e(oo,"canonicalizeOrthogonalPolyline");function Se(t,o,r){if(t.y===o.y)return t.y>r.top&&t.y<r.bottom&&Math.max(t.x,o.x)>r.left&&Math.min(t.x,o.x)<r.right;if(t.x===o.x)return t.x>r.left&&t.x<r.right&&Math.max(t.y,o.y)>r.top&&Math.min(t.y,o.y)<r.bottom;return!0}e(Se,"segmentEntersRect");function io(t){let o=Ft(t);return{left:o.left-K,right:o.right+K,top:o.top-K,bottom:o.bottom+K}}e(io,"inflatedRect");function Bt(t,o,r,i,s){let a=oo(t);if(!a)return!1;let c=H(a);if(c.points.length<2)return!1;if(c.segments.length>1&&(Math.abs(c.segments[0].a.x-c.segments[0].b.x)+Math.abs(c.segments[0].a.y-c.segments[0].b.y)<Z||Math.abs(c.segments.at(-1).a.x-c.segments.at(-1).b.x)+Math.abs(c.segments.at(-1).a.y-c.segments.at(-1).b.y)<Z))return!1;let d=(s.forest.childrenByParent.get(i)??[]).filter((l)=>!xt(l));for(let l of d){let u=io(l);for(let h=0;h<c.points.length-1;h++){if(l.id===o.id&&h===0||l.id===r.id&&h===c.points.length-2){if(Se(c.points[h],c.points[h+1],Ft(l)))return!1;continue}if(Se(c.points[h],c.points[h+1],u))return!1}}return!0}e(Bt,"validateSameContainerRoute");function $t(t,o,r,i,s){let a=oo(t);if(!a)return!1;let c=H(a);if(c.points.length<2)return!1;let d=(s.forest.childrenByParent.get(i)??[]).filter((l)=>!xt(l));for(let l of d){let u=io(l);for(let h=0;h<c.points.length-1;h++){if(l.id===o&&h===0||l.id===r&&h===c.points.length-2){if(Se(c.points[h],c.points[h+1],Ft(l)))return!1;continue}if(Se(c.points[h],c.points[h+1],u))return!1}}return!0}e($t,"validateContainerSegment");function vn(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)}}e(vn,"segmentSpan");function de(t){let o=H([...t]).segments.filter((i)=>i.orientation!=="Z").map((i)=>({a:{...i.a},b:{...i.b},orientation:i.orientation}));if(o.length===0)return[];if(o.length===1&&Math.abs(o[0].a.x-o[0].b.x)+Math.abs(o[0].a.y-o[0].b.y)<=Z*2)return[];let r=e((i,s)=>{if(i.orientation==="H"){let a=Math.sign(i.b.x-i.a.x);if(s)i.a.x+=a*Z;else i.b.x-=a*Z}else{let a=Math.sign(i.b.y-i.a.y);if(s)i.a.y+=a*Z;else i.b.y-=a*Z}},"trim");return r(o[0],!0),r(o[o.length-1],!1),o.filter(({a:i,b:s})=>i.x!==s.x||i.y!==s.y)}e(de,"nonterminalSegments");function ro(t,o){if(t.orientation!==o.orientation)return!1;let r=vn(t),i=vn(o),s=Math.max(0,Math.min(r.high,i.high)-Math.max(r.low,i.low));if(s<=0)return!1;let a=t.orientation==="H"?Math.abs(t.a.y-o.a.y):Math.abs(t.a.x-o.a.x);return a===0&&s>=Ne||a>0&&a<Ne}e(ro,"pairSegmentsConflict");function mt(t,o){let r=H([...t]).points,i=[r[0],r.at(-1)],s=de(r);return o.every((a)=>{let c=H([...a]).points,d=[c[0],c.at(-1)];if(i.some((l)=>d.some((u)=>l.x===u.x&&l.y===u.y)))return!1;return s.every((l)=>de(c).every((u)=>!ro(l,u)))})}e(mt,"routeSatisfiesPairConstraints");function so(t,o){let r=H([...t]).points,i=[r[0],r.at(-1)];return o.every((s)=>{let a=H([...s]).points,c=[a[0],a.at(-1)];return!i.some((d)=>c.some((l)=>d.x===l.x&&d.y===l.y))})}e(so,"routeHasDistinctPairPorts");function tn(t,o,r){let i=t.y===o.y?"H":"V",s={a:t,b:o,orientation:i};return r.every((a)=>de(a).every((c)=>!ro(s,c)))}e(tn,"pairArcAllowed");function Ki(t,o){let r=t.side==="left"||t.side==="right"?"H":"V",i=o.side==="left"||o.side==="right"?"H":"V",s=Math.abs(t.connect.x-o.connect.x),a=Math.abs(t.connect.y-o.connect.y),c;if(s===0&&a===0)c=Number(r!==i);else if(s===0||a===0){let d=s===0?"V":"H";c=Number(r!==d)+Number(i!==d)}else c=Math.min(Number(r!=="H")+1+Number(i!=="V"),Number(r!=="V")+1+Number(i!=="H"));return[Z*2+s+a,c]}e(Ki,"endpointPairLowerBound");function ji(t,o){if(t.orientation!==o.orientation)return!1;let r=t.orientation==="H",i=e((d)=>r?Math.min(d.a.x,d.b.x):Math.min(d.a.y,d.b.y),"lowOf"),s=e((d)=>r?Math.max(d.a.x,d.b.x):Math.max(d.a.y,d.b.y),"highOf"),a=Math.min(s(t),s(o))-Math.max(i(t),i(o)),c=r?Math.abs(t.a.y-o.a.y):Math.abs(t.a.x-o.a.x);return a>0&&c<ee}e(ji,"segmentsTooClose");var In=class{constructor(){this.lines={H:new Map,V:new Map},this.sortedCoordinates={H:void 0,V:void 0},this.log=[]}static{e(this,"RouteOccupancyIndex")}get size(){return this.log.length}add(t,o){for(let r of de(t)){let i=r.orientation,s=i==="H"?r.a.y:r.a.x,a=this.lines[i].get(s);if(a)a.push({segment:r,pairKey:o});else this.lines[i].set(s,[{segment:r,pairKey:o}]),this.sortedCoordinates[i]=void 0;this.log.push({orientation:i,coordinate:s})}}truncate(t){while(this.log.length>t){let{orientation:o,coordinate:r}=this.log.pop();this.lines[o].get(r)?.pop()}}conflictsWithRoute(t,o){return de(t).some((r)=>this.conflicts(r,o))}conflictsWithArc(t,o,r){let i=t.y===o.y?"H":"V";return this.conflicts({a:t,b:o,orientation:i},r)}conflicts(t,o){let r=t.orientation;if(r!=="H"&&r!=="V")return!1;let i=r==="H"?t.a.y:t.a.x,s=this.coordinatesFor(r),a=0,c=s.length;while(a<c){let d=a+c>>1;if(s[d]<=i-ee)a=d+1;else c=d}for(let d=a;d<s.length;d++){let l=s[d];if(l>=i+ee)break;for(let u of this.lines[r].get(l))if(u.pairKey!==o&&ji(t,u.segment))return!0}return!1}coordinatesFor(t){return this.sortedCoordinates[t]??=[...this.lines[t].keys()].sort((o,r)=>o-r)}},Et=24,gt=18,At=14,Io=4,Ui=18,ao=4,Zr=64,Jr=4;function Xi(t,o,r,i){if(!o.conflictsWithRoute(t,r))return[...t];let s=H([...t]).points;for(let a=1;a<=Jr;a++)for(let c of[1,-1]){let d=c*a*Ne;for(let l=1;l<s.length-2;l++){let u=s[l].x===s[l+1].x,h=s.map((f,p)=>p===l||p===l+1?u?{x:f.x+d,y:f.y}:{x:f.x,y:f.y+d}:f);if(!o.conflictsWithRoute(h,r)&&i(h))return h}}return}e(Xi,"separateRouteFromOccupied");function Wi(t){let o=e((r,i)=>Math.abs(r.x-i.x)+Math.abs(r.y-i.y),"stub");return o(t[0],t[1])>=Z&&o(t.at(-1),t.at(-2))>=Z}e(Wi,"terminalStubsAreLongEnough");function Yi(t,o,r,i,s=3){let a=[...i.filter((l)=>l>=o&&l<=r).sort((l,u)=>Math.abs(l-t)-Math.abs(u-t)||l-u),(o+r)/2,o,r],c=new Set([t]),d=[];for(let l of a){if(c.has(l))continue;if(c.add(l),d.push(l),d.length===s)break}return d}e(Yi,"boundedAlternativePortalCoordinates");function oe(t,o){return Math.abs(t.x-o.x)<=0.000001&&Math.abs(t.y-o.y)<=0.000001}e(oe,"equalPoint");function qi(t,o){return t.x===o.x||t.y===o.y}e(qi,"areExactlyAxisAligned");function _e(t,o,r,i){let s=[...t].sort((a,c)=>Math.abs(a-o)+Math.abs(a-r)-(Math.abs(c-o)+Math.abs(c-r))||a-c);return s[Math.min(i,Math.max(0,s.length-1))]??(o+r)/2}e(_e,"chooseIntermediateCoordinate");function Qi(t){let o=[];for(let r of t)if(o.length===0||!oe(o[o.length-1],r))o.push(r);return o}e(Qi,"dedupeConsecutive");function qt(t,o,r,i,s){let a=o.containers.get(t);if(!a)throw V("GRID_ROUTE_NOT_FOUND",`Missing container layout "${t}"`);let c=[r.port,r.connect];if(r.orientation==="V"&&i.orientation==="V"){if(!oe(r.connect,i.connect)&&Math.abs(r.connect.x-i.connect.x)>0.000001){let d=_e(a.horizontalCorridors,r.connect.y,i.connect.y,s);c.push({x:r.connect.x,y:d},{x:i.connect.x,y:d})}else if(!oe(r.connect,i.connect)&&Math.abs(r.connect.y-i.connect.y)>0.000001&&s>0){let d=a.verticalCorridors.filter((u)=>Math.abs(u-r.connect.x)>0.000001),l=_e(d.length>0?d:a.verticalCorridors,r.connect.x,i.connect.x,s-1);c.push({x:l,y:r.connect.y},{x:l,y:i.connect.y})}}else if(r.orientation==="H"&&i.orientation==="H"){if(!oe(r.connect,i.connect)&&Math.abs(r.connect.y-i.connect.y)>0.000001){let d=_e(a.verticalCorridors,r.connect.x,i.connect.x,s);c.push({x:d,y:r.connect.y},{x:d,y:i.connect.y})}}else if(r.orientation==="V"&&i.orientation==="H")c.push({x:r.connect.x,y:i.connect.y});else c.push({x:i.connect.x,y:r.connect.y});return c.push(i.connect,i.port),H(Qi(c)).points}e(qt,"routeWithinContainer");function Ee(t,o,r,i,s,a,c){let d=s.forest.nodeById.get(t),l=s.itemMeta.get(t);if(!d||!l||l.containerId!==i)throw V("GRID_ROUTE_NOT_FOUND",`Missing item metadata for "${t}" in "${i}"`);let u=z(d),h=c??a.get(r)??(o==="left"||o==="right"?u.cy:u.cx);switch(o){case"left":return{port:{x:u.left,y:h},connect:{x:l.leftCorridorX,y:h},orientation:"V",side:o};case"right":return{port:{x:u.right,y:h},connect:{x:l.rightCorridorX,y:h},orientation:"V",side:o};case"top":return{port:{x:h,y:u.top},connect:{x:h,y:l.topCorridorY},orientation:"H",side:o};case"bottom":return{port:{x:h,y:u.bottom},connect:{x:h,y:l.bottomCorridorY},orientation:"H",side:o}}}e(Ee,"itemAttachment");function co(t,o,r,i,s){let a=i.forest.nodeById.get(t),c=i.containers.get(t);if(!a||!c)throw V("GRID_ROUTE_NOT_FOUND",`Missing boundary metadata for "${t}"`);let d=z(a),l=s.get(r)??(o==="left"||o==="right"?d.cy:d.cx);switch(o){case"left":return{port:{x:d.left,y:l},connect:{x:c.verticalCorridors[0],y:l},orientation:"V",side:o};case"right":return{port:{x:d.right,y:l},connect:{x:c.verticalCorridors[c.verticalCorridors.length-1],y:l},orientation:"V",side:o};case"top":return{port:{x:l,y:d.top},connect:{x:l,y:c.horizontalCorridors[0]},orientation:"H",side:o};case"bottom":return{port:{x:l,y:d.bottom},connect:{x:l,y:c.horizontalCorridors[c.horizontalCorridors.length-1]},orientation:"H",side:o}}}e(co,"boundaryAttachment");function Zi(t){return{x:(t.interior.x+t.exterior.x)/2,y:(t.interior.y+t.exterior.y)/2}}e(Zi,"portalBoundaryPoint");function Jt(t,o){return{ownerId:t.ownerId,port:Zi(t),connect:o?t.interior:t.exterior,orientation:t.side==="left"||t.side==="right"?"V":"H",side:t.side}}e(Jt,"portalAttachment");function Mn(t,o,r,i,s){let a=i.forest.nodeById.get(t);if(!a?.isGroup)throw V("GRID_ROUTE_NOT_FOUND",`Missing group endpoint "${t}"`);let c=z(a),d=s.get(r)??(o==="left"||o==="right"?c.cy:c.cx),l=o==="left"||o==="right"?{x:o==="left"?c.left:c.right,y:d}:{x:d,y:o==="top"?c.top:c.bottom};return{ownerId:t,port:l,connect:{x:l.x+(o==="left"?Z:o==="right"?-Z:0),y:l.y+(o==="top"?Z:o==="bottom"?-Z:0)},orientation:o==="left"||o==="right"?"V":"H",side:o}}e(Mn,"groupBoundaryEndpointAttachment");function Ji(t){return[...t].reverse()}e(Ji,"reversePoints");function tr(t){let o=[];for(let r of t)for(let i of r)if(o.length===0||!oe(o[o.length-1],i))o.push(i);return H(o).points}e(tr,"combinePointChains");function er(t,o,r,i){let s=z(t),a=At+(r+1)*Ui,c=r*ao;switch(o){case"right":{let d=i-gt/2-c,l=i+gt/2+c;return H([{x:s.right,y:d},{x:s.right+At,y:d},{x:s.right+a,y:d},{x:s.right+a,y:l},{x:s.right+At,y:l},{x:s.right,y:l}]).points}case"left":{let d=i-gt/2-c,l=i+gt/2+c;return H([{x:s.left,y:d},{x:s.left-At,y:d},{x:s.left-a,y:d},{x:s.left-a,y:l},{x:s.left-At,y:l},{x:s.left,y:l}]).points}case"top":{let d=i-gt/2-c,l=i+gt/2+c;return H([{x:d,y:s.top},{x:d,y:s.top-At},{x:d,y:s.top-a},{x:l,y:s.top-a},{x:l,y:s.top-At},{x:l,y:s.top}]).points}case"bottom":{let d=i-gt/2-c,l=i+gt/2+c;return H([{x:d,y:s.bottom},{x:d,y:s.bottom+At},{x:d,y:s.bottom+a},{x:l,y:s.bottom+a},{x:l,y:s.bottom+At},{x:l,y:s.bottom}]).points}}}e(er,"routeSelfLoop");function lo(t,o,r,i,s){let a=z(t),c=At+(r+1)*Ui,d=r*ao,l=gt+d*2,u=o==="left"||o==="right",h=Math.max(l,(u?s.cross:s.along)+Wt*2+Lo),f=Math.max(c,(u?s.along:s.cross)/2+Wt),p=u?[a.top,a.bottom]:[a.left,a.right],y=i-h/2,m=i+h/2;if(y-p[0]>=Io&&p[1]-m>=Io)switch(o){case"right":return[H([{x:a.right,y},{x:a.right+f,y},{x:a.right+f,y:m},{x:a.right,y:m}]).points];case"left":return[H([{x:a.left,y},{x:a.left-f,y},{x:a.left-f,y:m},{x:a.left,y:m}]).points];case"top":return[H([{x:y,y:a.top},{x:y,y:a.top-f},{x:m,y:a.top-f},{x:m,y:a.top}]).points];case"bottom":return[H([{x:y,y:a.bottom},{x:y,y:a.bottom+f},{x:m,y:a.bottom+f},{x:m,y:a.bottom}]).points]}let b=i-gt/2-d,g=i+gt/2+d;if(b<p[0]||g>p[1])return[];let x=i-h/2,w=i+h/2,M=Math.max(At,Z),S=Math.max(f,M+(u?s.along:s.cross)/2+Wt);switch(o){case"right":return[H([{x:a.right,y:b},{x:a.right+M,y:b},{x:a.right+M,y:x},{x:a.right+S,y:x},{x:a.right+S,y:w},{x:a.right+M,y:w},{x:a.right+M,y:g},{x:a.right,y:g}]).points];case"left":return[H([{x:a.left,y:b},{x:a.left-M,y:b},{x:a.left-M,y:x},{x:a.left-S,y:x},{x:a.left-S,y:w},{x:a.left-M,y:w},{x:a.left-M,y:g},{x:a.left,y:g}]).points];case"top":return[H([{x:b,y:a.top},{x:b,y:a.top-M},{x,y:a.top-M},{x,y:a.top-S},{x:w,y:a.top-S},{x:w,y:a.top-M},{x:g,y:a.top-M},{x:g,y:a.top}]).points];case"bottom":return[H([{x:b,y:a.bottom},{x:b,y:a.bottom+M},{x,y:a.bottom+M},{x,y:a.bottom+S},{x:w,y:a.bottom+S},{x:w,y:a.bottom+M},{x:g,y:a.bottom+M},{x:g,y:a.bottom}]).points]}}e(lo,"labelAwareSelfLoopCandidates");function uo(t,o,r){return(t.isGroup&&Ze(t)?["left","right","bottom"]:["left","right","top","bottom"]).sort((s,a)=>{let c=(o.get(ae(t.id,s))??0)+(r.get(`${t.id}:${s}`)??0),d=(o.get(ae(t.id,a))??0)+(r.get(`${t.id}:${a}`)??0);return c-d})}e(uo,"orderedSelfLoopSides");function nr(t,o){let r=[];for(let i of o.forest.nodeById.values()){if(i.id!==t.id&&!i.isGroup&&i.x!==void 0&&i.y!==void 0)r.push(z(i));if(i.id!==t.id&&i.groupTitleRect){let{left:s,right:a,top:c,bottom:d}=i.groupTitleRect;r.push({cx:(s+a)/2,cy:(c+d)/2,left:s,right:a,top:c,bottom:d})}}return r}e(nr,"selfLoopObstacles");function or(t,o,r,i,s,a){let c=z(t),d=nr(t,i);for(let l of uo(t,o,r)){let u=`${t.id}:${l}`,h=r.get(u)??0,f=l==="left"||l==="right"?c.cy:c.cx,p=s?lo(t,l,h,f,s):[er(t,l,h,f)];if(s&&a)a.labelAwareSelfLoopCandidates+=p.length;for(let y of p)if(!d.some((m)=>It(y,m)))return{points:y,side:l,index:h}}throw V("GRID_ROUTE_NOT_FOUND",`No obstacle-clear self-loop route for "${t.id}"`,{nodeId:t.id})}e(or,"routeObstacleClearSelfLoop");function ir(t){if(t.containers.has(X))return;let o=0,r=0,i=0,s=0,a=!0;for(let l of t.itemMeta.values()){if(l.containerId!==X)continue;if(a)o=l.cellLeft,r=l.cellLeft+l.cellWidth,i=l.cellTop,s=l.cellTop+l.cellHeight,a=!1;else o=Math.min(o,l.cellLeft),r=Math.max(r,l.cellLeft+l.cellWidth),i=Math.min(i,l.cellTop),s=Math.max(s,l.cellTop+l.cellHeight)}let c=new Set([i-Et,s+Et]),d=new Set([o-Et,r+Et]);for(let l of t.itemMeta.values()){if(l.containerId!==X)continue;c.add(l.topCorridorY),c.add(l.bottomCorridorY),d.add(l.leftCorridorX),d.add(l.rightCorridorX)}t.containers.set(X,{id:X,left:o-Et,top:i-Et,width:r-o+Et*2,height:s-i+Et*2,contentLeft:o,contentTop:i,contentRight:r,contentBottom:s,verticalCorridors:[...d].sort((l,u)=>l-u),horizontalCorridors:[...c].sort((l,u)=>l-u)})}e(ir,"rootContainerMeta");function rr(t,o){let r=o.containers.get(t);if(!r)throw V("GRID_ROUTE_NOT_FOUND",`Missing container layout "${t}"`);if(t===X){let a=[...o.itemMeta.values()].filter(({containerId:c})=>c===X);if(a.length>0)return{left:Math.min(...a.map(({cellLeft:c})=>c))-Et,right:Math.max(...a.map(({cellLeft:c,cellWidth:d})=>c+d))+Et,top:Math.min(...a.map(({cellTop:c})=>c))-Et,bottom:Math.max(...a.map(({cellTop:c,cellHeight:d})=>c+d))+Et};return{left:r.left,right:r.left+r.width,top:r.top,bottom:r.top+r.height}}let i=o.forest.nodeById.get(t);if(!i)throw V("GRID_ROUTE_NOT_FOUND",`Missing container owner "${t}"`);let s=Ft(i);return{left:s.left+K,right:s.right-K,top:s.top+K,bottom:s.bottom-K}}e(rr,"containerBounds");function Cn(t,o,r){return(o==="left"?t.left:o==="right"?t.right:o==="top"?t.top:t.bottom)+(o==="left"||o==="top"?1:-1)*K*(r?1:-1)}e(Cn,"portalCoordinate");function sr(t,o){let r=[];if(t!==X){let i=o.forest.nodeById.get(t);if(i){let s=Ft(i);r.push(...se(t,s,i.groupTitleRect).map((a)=>({...a,coordinate:Cn(s,a.side,!0)})))}}for(let i of o.forest.childrenByParent.get(t)??[]){if(!i.isGroup)continue;let s=Ft(i);r.push(...se(i.id,s,i.groupTitleRect).map((a)=>({...a,coordinate:Cn(s,a.side,!1)})))}return r}e(sr,"containerPortalRanges");function ar(t,o,r,i){let s={topologies:new Map,fallbackContainers:new Map,searchBudget:{expandedStates:0},searchBudgetWarningEmitted:!1,baseEstimatedBytes:0,metrics:r},a=0;for(let c of[...new Set(t)].sort()){let d=(o.forest.childrenByParent.get(c)??[]).filter((u)=>!xt(u)),l=o.forest.nodeById.get(c)?.groupTitleRect;try{let u=Pi({containerId:c,bounds:rr(c,o),obstacles:d.map((f)=>({id:f.id,bounds:Ft(f)})),titleExclusions:l?[{id:`${c}:title`,bounds:{...l}}]:void 0,portalRanges:sr(c,o)},{caps:i.topologyCaps}),h=i.topologyCaps?.maxEstimatedBytes??jt;if(a+u.estimatedBytes>h){s.fallbackContainers.set(c,"estimated_memory_cap");continue}if(a+=u.estimatedBytes,s.baseEstimatedBytes=a,s.topologies.set(c,u),r)r.containersBuilt++,r.baseTopologyBuilds++,r.baseVertices+=u.vertices.length,r.baseAdjacencyEntries+=u.adjacencyEntries,r.buildSweepEvents+=u.seedCount*4+u.obstacles.length*4,r.estimatedBytes=a}catch(u){if(!(u instanceof Tt))throw u;s.fallbackContainers.set(c,u.reason)}}return s}e(ar,"buildRoutingContext");function Sn(t,o,r,i,s,a,c){let d=s();if(c)c.compatibilitySegments++;if($t(d,r.ownerId,i.ownerId,o,a))return d;if(c)c.compatibilityValidationFailures++,c.routesImpossible++;throw V("GRID_ROUTE_NOT_FOUND",`Invalid compatibility route for "${t}"`,{edgeId:t,containerId:o})}e(Sn,"validatedCompatibilitySegment");function Re(t,o,r){let i=t.source.chain.at(-1),s=t.target.chain.at(-1),a=e((c,d)=>({ownerId:d.ownerId,...c.finalKind==="boundary"?co(t.lcaContainerId,d.side,d.demandKey,o,r):Ee(d.ownerId,d.side,d.demandKey,t.lcaContainerId,o,r)}),"finalAttachment");return{start:a(t.source,i),end:a(t.target,s)}}e(Re,"compatibilityLcaAttachments");function ho(t,o,r){return t.chain.slice(0,-1).map((i,s)=>{let a=t.chain[s+1];return{containerId:a.ownerId,start:{ownerId:i.ownerId,...Ee(i.ownerId,i.side,i.demandKey,a.ownerId,o,r)},end:{ownerId:a.ownerId,...co(a.ownerId,a.side,a.demandKey,o,r)}}})}e(ho,"compatibilityHierarchyAttachments");function cr(t,o,r){let i=e((a,c,d)=>$t(qt(a,o,c,d,t.laneIndex),c.ownerId,d.ownerId,a,o),"segmentIsValid");for(let a of[t.source,t.target])for(let{containerId:c,start:d,end:l}of ho(a,o,r))if(!i(c,d,l))return!1;let s=Re(t,o,r);return i(t.lcaContainerId,s.start,s.end)}e(cr,"compatibilityPlanIsValid");function dr(t,o,r,i){let{plans:s,eligiblePlans:a,eligibleIds:c,demandCoords:d,endpointCandidatesByEdge:l,endpointIncidentCounts:u,coordinatedEndpointIds:h}=t,f=e((v)=>(u.get(v.edge.start)??0)===v.bundleSize&&(u.get(v.edge.end)??0)===v.bundleSize,"hasIsolatedEndpoints"),p=e((v)=>{let R=o.forest.nodeById.get(v.edge.start),A=o.forest.nodeById.get(v.edge.end);return Boolean(R&&A&&(R.isGroup&&Kt(R.id,A,o.forest.nodeById)||A.isGroup&&Kt(A.id,R,o.forest.nodeById)))},"hasAncestorEndpoint"),y=new Map,m=new Map,b=s.length<=Zr,g=i.topologyCaps===void 0&&i.searchCaps===void 0&&i.onDualRouteComparison===void 0;for(let v of g?a:[]){if(h.has(v.edge.id))continue;let R=l.get(v.edge.id);if(v.bundleSize!==1||!R?.sources.length||!R.targets.length)continue;let A=o.forest.nodeById.get(v.edge.start),C=o.forest.nodeById.get(v.edge.end);if(!A||!C)continue;let O=Re(v,o,d),P=qt(v.lcaContainerId,o,O.start,O.end,v.laneIndex),L=H(P),N=L.points[0],T=L.points.at(-1);if(!N||!T)continue;let Y=R.sources.find(({port:J})=>J.x===N.x&&J.y===N.y),q=R.targets.find(({port:J})=>J.x===T.x&&J.y===T.y);if(!Y||!q)continue;if(r)r.compatibilityFastPathAttempts++;let D=Math.abs(N.x-T.x)+Math.abs(N.y-T.y);if(!Bt(P,A,C,v.lcaContainerId,o)){if(r)r.compatibilityFastPathValidationFailures++;continue}if(re(L.points)!==D){if(r)r.compatibilityFastPathNonMinimalRoutes++;continue}let Q=m.get(v.lcaContainerId);if(!Q)Q=new In,m.set(v.lcaContainerId,Q);if(Q.conflictsWithRoute(L.points,v.pairKey)&&b)continue;let k=Xi(L.points,Q,v.pairKey,(J)=>Wi(J)&&re(J)===D&&Bt(J,A,C,v.lcaContainerId,o))??P;Q.add(k,v.pairKey),y.set(v.edge.id,k)}let x=e((v)=>!c.has(v.edge.id)&&v.edge.start!==v.edge.end&&(v.bundleSize>1||f(v)||!cr(v,o,d)),"sparseCandidate"),w=new Map,M=new Set;if(b)for(let v of t.orderedPlans){if(c.has(v.edge.id)||v.edge.start===v.edge.end||p(v)||x(v))continue;let R=Re(v,o,d),A=qt(v.lcaContainerId,o,R.start,R.end,v.laneIndex),C=w.get(v.lcaContainerId);if(!C)C=new In,w.set(v.lcaContainerId,C);if(C.conflictsWithRoute(A,v.pairKey))M.add(v.edge.id);else C.add(A,v.pairKey)}let S=new Set([...s.filter(x).map(({edge:v})=>v.id),...M]),E=new Set([...S,...s.filter(p).map(({edge:v})=>v.id)]),I=s.filter((v)=>c.has(v.edge.id)&&!y.has(v.edge.id)||E.has(v.edge.id)||v.edge.start===v.edge.end).flatMap((v)=>[v.lcaContainerId,...v.source.chain.slice(1).map(({ownerId:R})=>R),...v.target.chain.slice(1).map(({ownerId:R})=>R)]);return{overlapAvoidanceEnabled:b,compatibilityFastRoutes:y,sparseHierarchyIds:S,sparseLcaIds:E,routedContainerIds:I,routeOccupancy:m}}e(dr,"prepareRoutingModes");var Mo={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"},ts=Object.keys(Mo).filter((t)=>Mo[t]==="transactional"&&t!=="routeOrder"&&t!=="routes");function lr(t){return{routeOrderLength:t.routeOrder.length,routesLength:t.routes.length,values:Object.fromEntries(ts.map((o)=>[o,t[o]]))}}e(lr,"createGridRoutingInstrumentationCheckpoint");function ur(t,o){t.routeOrder.length=o.routeOrderLength,t.routes.length=o.routesLength,Object.assign(t,o.values)}e(ur,"restoreGridRoutingInstrumentationCheckpoint");function En(t,o,r,i){return Math.max(0,Math.min(Math.max(t,o),Math.max(r,i))-Math.max(Math.min(t,o),Math.min(r,i)))}e(En,"intervalOverlap");function hr(t,o){let r=H(t).segments,i=H(o).segments,s=0;for(let a of r)for(let c of i){if(a.orientation!==c.orientation)continue;if(a.orientation==="H"&&a.a.y===c.a.y)s+=En(a.a.x,a.b.x,c.a.x,c.b.x);else if(a.orientation==="V"&&a.a.x===c.a.x)s+=En(a.a.y,a.b.y,c.a.y,c.b.y)}return s}e(hr,"sharedSegmentLength");function Rn(t,o,r,i,s=0,a=0){let c=H(r),d=0,l=0;for(let h of i){let f=H(h).segments;for(let p of c.segments)for(let y of f)if(Gn(p,y))d++;l+=hr(c.points,h)}let u={edgeId:o,routeOrder:t.routes.length,laneOffset:a,routeLength:re(c.points),bendCount:c.bends,crossingCount:d,sharedLength:l,boundaryTransitionCount:s,routeSignature:JSON.stringify(c.points)};t.routeOrder.push(o),t.routes.push(u),t.routesFound++,t.routeLength+=u.routeLength,t.bendCount+=u.bendCount,t.crossingCount+=u.crossingCount,t.sharedLength+=u.sharedLength,t.hierarchyBoundaryTransitions+=s}e(Rn,"recordGridRoute");var fr=1e5,pr=2000000,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{e(this,"RouterSearchWorkspace")}reset(t){let o=t*3;if(this.best.length<o)this.best=new Int32Array(o),this.best.fill(-1);else for(let r of this.touchedBestIndices)this.best[r]=-1;this.touchedBestIndices.length=0,this.heapPairs.length=0}setBest(t,o){if(this.best[t]<0)this.touchedBestIndices.push(t);this.best[t]=o}ensureStateCapacity(t){if(this.stateVertices.length>=t)return;let o=Math.max(t,this.stateVertices.length*2);this.stateVertices=wt(this.stateVertices,o),this.orientations=wt(this.orientations,o),this.gLengths=wt(this.gLengths,o),this.gBends=wt(this.gBends,o),this.gBoundaryTransitions=wt(this.gBoundaryTransitions,o),this.fLengths=wt(this.fLengths,o),this.fBends=wt(this.fBends,o),this.predecessors=wt(this.predecessors,o),this.depths=wt(this.depths,o),this.ancestor4=wt(this.ancestor4,o),this.heapChildren=wt(this.heapChildren,o),this.heapSiblings=wt(this.heapSiblings,o)}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 Oe(t){let o=t.caps?.maxExpandedStates??fr,r=t.caps?.maxInvocationExpandedStates??pr,i=t.budget?.expandedStates??t.metrics?.expandedStates??0;if(o>0&&i<r)return;throw new Tt("search_state_cap","Grid routing search-state cap exceeded",i>=r?"invocation":"edge")}e(Oe,"assertSearchBudgetAvailable");function wt(t,o){let r=new t.constructor(o);return r.set(t),r}e(wt,"growTypedArray");function ie(t,o){for(let r=0;r<4;r++){if(t[r]<o[r])return-1;if(t[r]>o[r])return 1}return 0}e(ie,"compareTupleCost");function An(t,o,r,i){if(t===0&&o===0)return r&&i?Number(r!==i):0;if(t===0)return(r?Number(r!=="V"):0)+(i?Number(i!=="V"):0);if(o===0)return(r?Number(r!=="H"):0)+(i?Number(i!=="H"):0);return Math.min((r?Number(r!=="H"):0)+1+(i?Number(i!=="V"):0),(r?Number(r!=="V"):0)+1+(i?Number(i!=="H"):0))}e(An,"minimumBends");function we(t){return t===void 0?0:t==="H"?1:2}e(we,"orientationOrdinal");function On(t,o,r){return r==="left"?t.y===o.y&&o.x>t.x:r==="right"?t.y===o.y&&o.x<t.x:r==="top"?t.x===o.x&&o.y>t.y:t.x===o.x&&o.y<t.y}e(On,"movesTowardOwner");function mr(t,o){return t*3+we(o)}e(mr,"stateIndex");function yr(t){let o=[];for(let r of t){let i=o.at(-1);if(i&&i.x===r.x&&i.y===r.y)continue;let s=o.at(-2);if(s&&i&&(s.x===i.x&&i.x===r.x||s.y===i.y&&i.y===r.y))o[o.length-1]={...r};else o.push({...r})}return o}e(yr,"normalizePoints");function Bn(t,o,r,i,s){let a=[],c=t;while(c>=0)a.push(o[c]),c=r[c];return a.reverse(),{points:yr(a.map((d)=>s(d).point)),vertexIds:a,cost:i}}e(Bn,"reconstruct");function xr(t){for(let o of t.vertices){if(o.id<0||t.vertices[o.id]!==o||!Number.isFinite(o.point.x)||!Number.isFinite(o.point.y))throw Error("Malformed grid routing vertex");for(let r of t.adjacency.get(o.id)??[]){let i=t.vertices[r.to],s=i&&(r.orientation==="H"?o.point.y===i.point.y:o.point.x===i.point.x),a=i?Math.abs(o.point.x-i.point.x)+Math.abs(o.point.y-i.point.y):Number.NaN;if(r.from!==o.id||!s||!Number.isFinite(r.length)||r.length<=0||r.length!==a)throw Error("Malformed grid routing arc")}}}e(xr,"validateSearchTopology");function br(t,o,r,i){let s=e((_)=>{let G=t.getVertex?.(_)??t.vertices[_];if(!G)throw Error(`Missing grid routing vertex ${_}`);return G},"vertexAt"),a=s(o),c=s(r);if(!i.topologyValidated)xr(t);let d=i.metrics;if(d)d.searches++;Oe(i);let l=i.workspace??new gr;l.reset(t.vertexCount??t.vertices.length);let{stateVertices:u,orientations:h,gLengths:f,gBends:p,gBoundaryTransitions:y,fLengths:m,fBends:b,predecessors:g,depths:x,ancestor4:w,heapChildren:M,heapSiblings:S,best:E,heapPairs:I}=l,v=1,R=i.endpointCandidateRank??0,A=i.heuristic!=="zero";function C(_,G){return u[_]-u[G]||h[_]-h[G]||g[_]-g[G]||_-G}e(C,"nonCostOrder");function O(_,G){return m[_]-m[G]||b[_]-b[G]||y[_]-y[G]||(i.queueOrder==="reverse"?-C(_,G):C(_,G))}e(O,"compareStates");function P(_,G){if(_===G)return 0;if(_<0)return-1;if(G<0)return 1;let lt=x[_],ut=x[G],et=_,j=G;while(x[et]>x[j])et=g[et];while(x[j]>x[et])j=g[j];if(et===j)return lt-ut;while(w[et]>=0&&w[j]>=0&&w[et]!==w[j])et=w[et],j=w[j];while(g[et]!==g[j])et=g[et],j=g[j];return u[et]-u[j]||h[et]-h[j]}e(P,"compareChains");let L=-1,N=0;function T(_,G){if(_<0)return G;if(G<0)return _;if(O(_,G)<=0)return S[G]=M[_],M[_]=G,_;return S[_]=M[G],M[G]=_,G}e(T,"heapMeld");let Y=e((_)=>{M[_]=-1,S[_]=-1,L=T(L,_),N++},"heapPush"),q=e(()=>{if(L<0)return;let _=L;I.length=0;let G=M[_];while(G>=0){let ut=S[G];S[G]=-1,I.push(G),G=ut}for(let ut=0;ut+1<I.length;ut+=2)I[ut>>>1]=T(I[ut],I[ut+1]);let lt=Math.ceil(I.length/2);if(I.length%2!==0)I[lt-1]=I[I.length-1];L=-1;while(lt>0)L=T(I[--lt],L);return N--,_},"heapPop"),D=0,Q=i.caps?.maxExpandedStates??fr,Ct=i.caps?.maxInvocationExpandedStates??pr,it=i.budget?.expandedStates??d?.expandedStates??0,k=e(()=>{let _=l.estimatedBytes(),G=(i.estimatedBytesBase??0)+_;if(d)d.searchWorkspaceBytes=Math.max(d.searchWorkspaceBytes,_),d.estimatedBytes=Math.max(d.estimatedBytes,G);if(G>(i.caps?.maxEstimatedBytes??Number.POSITIVE_INFINITY))throw new Tt("estimated_memory_cap","Grid routing search workspace memory cap exceeded")},"recordWorkspaceBytes");k();let J=e(()=>{if(i.budget)i.budget.expandedStates+=D;if(d)d.expandedStates+=D},"commitExpandedStates"),ct=i.initialLength??0;u[0]=o,h[0]=we(i.initialOrientation),f[0]=ct,p[0]=0,y[0]=0;let ft=Math.abs(a.point.x-c.point.x),st=Math.abs(a.point.y-c.point.y);if(m[0]=ct+(A?ft+st:0),b[0]=A?An(ft,st,i.initialOrientation,i.targetOrientation):0,g[0]=-1,x[0]=1,w[0]=-1,l.setBest(mr(o,i.initialOrientation),0),Y(0),d)d.maxOpenSet=Math.max(d.maxOpenSet,N);let bt=-1,B,F=e((_)=>{let G=[f[_]+(i.targetLength??0),p[_]+(i.targetOrientation!==void 0&&h[_]!==0&&we(i.targetOrientation)!==h[_]?1:0),y[_],R];if(!B||ie(G,B)<0||ie(G,B)===0&&P(_,bt)<0)bt=_,B=G},"considerGoal"),dt=e((_,G,lt,ut,et,j)=>{let Rt=s(lt).point;if(i.arcAllowed&&!i.arcAllowed(G,Rt))return;if(i.initialSide&&g[_]<0&&On(G,Rt,i.initialSide))return;if(i.targetSide&&lt===r&&On(c.point,G,i.targetSide))return;let fe=lt*3+ut,Pt=E[fe],pe=f[_]+et,ge=p[_]+(h[_]!==0&&h[_]!==ut?1:0),me=y[_]+j,ye=Pt>=0?pe-f[Pt]||ge-p[Pt]||me-y[Pt]:-1;if(Pt>=0&&(ye>0||ye===0&&P(_,g[Pt])>=0))return;let St=v++;if(v>u.length)l.ensureStateCapacity(v),u=l.stateVertices,h=l.orientations,f=l.gLengths,p=l.gBends,y=l.gBoundaryTransitions,m=l.fLengths,b=l.fBends,g=l.predecessors,x=l.depths,w=l.ancestor4,M=l.heapChildren,S=l.heapSiblings,k();u[St]=lt,h[St]=ut,f[St]=pe,p[St]=ge,y[St]=me;let fo=Math.abs(Rt.x-c.point.x),po=Math.abs(Rt.y-c.point.y);m[St]=pe+(A?fo+po:0),b[St]=ge+(A?An(fo,po,ut===1?"H":"V",i.targetOrientation):0),g[St]=_,x[St]=x[_]+1;let go=g[_],mo=go>=0?g[go]:-1;w[St]=mo>=0?g[mo]:-1,l.setBest(fe,St),Y(St)},"relaxArc");while(N>0){let _=L;if(B&&(m[_]-B[0]||b[_]-B[1]||y[_]-B[2]||R-B[3])>0)break;let G=q();if(E[u[G]*3+h[G]]!==G)continue;if(D>=Q||it+D>=Ct){if(bt>=0&&B){if(d&&i.recordOutcome!==!1)d.routesFound++;return J(),Bn(bt,u,g,B,s)}J();let j=it+D>=Ct?"invocation":"edge";throw new Tt("search_state_cap","Grid routing search-state cap exceeded",j)}if(D++,u[G]===r){F(G);continue}let lt=u[G],ut=s(lt).point,et=t.getSearchArcs?.(lt)??t.searchAdjacencyByVertex?.[lt];if(et)for(let j of et)dt(G,ut,j.to,j.orientationOrdinal,j.length,j.boundaryTransitions);else for(let j of t.adjacencyByVertex?.[lt]??t.adjacency.get(lt)??[])dt(G,ut,j.to,we(j.orientation),j.length,j.kind==="portal"?1:0);if(d)d.maxOpenSet=Math.max(d.maxOpenSet,N)}if(bt<0||!B){if(J(),d&&i.recordOutcome!==!1)d.routesImpossible++;return}if(d&&i.recordOutcome!==!1)d.routesFound++;return J(),Bn(bt,u,g,B,s)}e(br,"search");function en(t,o,r,i={}){return br(t,o,r,i)}e(en,"findShortestRoute");var Co="grid-router";function wr(t,o,r,i,s){if(t.metrics)t.metrics.resourceLimitFallbacks++,t.metrics.fallbackReasons[o]++;if(n.debug(Co,"GRID_ROUTING_RESOURCE_FALLBACK",{edgeId:r,containerId:i,reason:o}),o==="search_state_cap"&&s==="invocation"&&!t.searchBudgetWarningEmitted)t.searchBudgetWarningEmitted=!0,n.warn(Co,"GRID_ROUTING_INVOCATION_SEARCH_BUDGET_EXHAUSTED",{edgeId:r,containerId:i,expandedStates:t.searchBudget.expandedStates})}e(wr,"recordFallback");function Qt({context:t,reason:o,edgeId:r,containerId:i,searchStateScope:s,route:a,isValid:c,includeContainerIdInError:d}){let l=a();if(wr(t,o,r,i,s),c(l))return l;if(t.metrics)t.metrics.fallbackValidationFailures++;throw V("GRID_ROUTE_NOT_FOUND",`Invalid legacy fallback for "${r}"`,{edgeId:r,...d?{containerId:i}:{},reason:o})}e(Qt,"runValidatedFallback");function vr(t,o,r,i,s,a,c,d,l,u,h,f,p){let y=d.fallbackContainers.get(t.lcaContainerId);if(y)return Qt({context:d,reason:y,edgeId:t.edge.id,containerId:t.lcaContainerId,route:a,isValid:e((S)=>Bt(S,i,s,t.lcaContainerId,c)&&(t.bundleSize<=1||mt(S,f)),"isValid")});let m=d.topologies.get(t.lcaContainerId);if(!m)throw V("GRID_ROUTE_NOT_FOUND",`Missing routing topology "${t.lcaContainerId}"`);if(o.length===0||r.length===0){if(d.metrics)d.metrics.routesImpossible++;throw V("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 b,g,x=o.flatMap((S)=>r.map((E)=>{let I=S.rank*r.length+E.rank,[v,R]=Ki(S,E);return{sourceCandidate:S,targetCandidate:E,pairRank:I,lowerCost:[v,R,0,I]}})).sort((S,E)=>ie(S.lowerCost,E.lowerCost)||kt(S.sourceCandidate.side)-kt(E.sourceCandidate.side)||kt(S.targetCandidate.side)-kt(E.targetCandidate.side)),w=e((S,E="all")=>{let I=t.bundleSize>1||S?(v,R)=>(t.bundleSize<=1||tn(v,R,f))&&!(S&&p.index.conflictsWithArc(v,R,p.pairKey)):void 0;for(let{sourceCandidate:v,targetCandidate:R,pairRank:A,lowerCost:C}of x){if(E==="preferred"&&A!==0)continue;if(E==="assigned-side"&&(v.onAssignedSide===!1||R.onAssignedSide===!1))continue;if(b&&ie(b.result.cost,C)<=0)break;try{Oe({metrics:d.metrics,caps:h.searchCaps,budget:d.searchBudget});let O=Qe(m,v.connect,R.connect,d.metrics,u,t.bundleSize>1&&(v.connect.x===R.connect.x||v.connect.y===R.connect.y)?[{x:(v.connect.x+R.connect.x)/2,y:(v.connect.y+R.connect.y)/2}]:[]),P=d.baseEstimatedBytes+O.estimatedBytes-m.estimatedBytes;if(P>(h.topologyCaps?.maxEstimatedBytes??jt))throw new Tt("estimated_memory_cap","Grid routing estimated_memory_cap exceeded");if(d.metrics)d.metrics.estimatedBytes=Math.max(d.metrics.estimatedBytes,P);let L=O.pointVertexIds.get(yt(v.connect)),N=O.pointVertexIds.get(yt(R.connect));if(L===void 0||N===void 0)throw V("GRID_ROUTE_NOT_FOUND",`Endpoint projection is missing from the routing overlay for "${t.edge.id}"`,{edgeId:t.edge.id,containerId:t.lcaContainerId,source:v.connect,target:R.connect});let T=v.side==="left"||v.side==="right"?"H":"V",Y=R.side==="left"||R.side==="right"?"H":"V",q=en(O,L,N,{metrics:d.metrics,caps:{...h.searchCaps,maxEstimatedBytes:h.searchCaps?.maxEstimatedBytes??h.topologyCaps?.maxEstimatedBytes??jt},endpointCandidateRank:A,recordOutcome:!1,budget:d.searchBudget,initialOrientation:T,initialLength:Z,targetOrientation:Y,targetLength:Z,topologyValidated:!0,workspace:l,estimatedBytesBase:P,arcAllowed:I});if(!q)continue;let D=H([v.port,...q.points,R.port]).points;if(!Bt(D,i,s,t.lcaContainerId,c))continue;if(t.bundleSize>1&&!mt(D,f))continue;if(S&&p.index.conflictsWithRoute(D,p.pairKey))continue;if(!b||ie(q.cost,b.result.cost)<0)b={result:q,points:D},g=void 0}catch(O){if(!(O instanceof Tt))throw O;if(b)break;g=O;break}}},"searchPairs"),M=p!==void 0&&p.index.size>0;if(p?.prioritizeEndpointCandidates)w(M,"preferred"),w(M,"assigned-side");if(!b)w(M);if(!b&&!g&&p!==void 0&&p.index.size>0)w(!1);if(g)return Qt({context:d,reason:g.reason,edgeId:t.edge.id,containerId:t.lcaContainerId,searchStateScope:g.searchStateScope,route:a,isValid:e((S)=>Bt(S,i,s,t.lcaContainerId,c)&&(t.bundleSize<=1||mt(S,f)),"isValid")});if(!b){if(d.metrics)d.metrics.routesImpossible++;throw V("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(h.onDualRouteComparison){let S=a(),E=H(b.points),I=H(S);h.onDualRouteComparison({edgeId:t.edge.id,sparse:{valid:!0,length:re(E.points),bends:E.bends},legacy:{valid:Bt(S,i,s,t.lcaContainerId,c),length:re(I.points),bends:I.bends}})}return b.points}e(vr,"sparseSameContainerRoute");function Ir(t,o,r){let i=Lt(t,o);if(!i||i.high-i.low<gt)return;let s=z(t),a=(i.low+i.high)/2,c=r*ao,d=[a-gt/2-c,a+gt/2+c];if(d[0]<i.low||d[1]>i.high)return;let l=e((u)=>{let h=o==="left"||o==="right"?{x:o==="left"?s.left:s.right,y:u}:{x:u,y:o==="top"?s.top:s.bottom};return{ownerId:t.id,side:o,port:h,connect:{x:h.x+(o==="left"?-Z:o==="right"?Z:0),y:h.y+(o==="top"?-Z:o==="bottom"?Z:0)},rank:0}},"candidate");return{start:l(d[0]),target:l(d[1])}}e(Ir,"selfLoopAttachments");function Mr(t,o,r,i,s,a,c,d,l,u){let h=o.parentId??X,f=r.labelRequirements.selfLoops.get(t.edge.id),p=i.fallbackContainers.get(h),y=e(()=>or(o,c,d,r,f,i.metrics),"legacyRoute");if(p){let g=Qt({context:i,reason:p,edgeId:t.edge.id,containerId:h,route:y,isValid:e((x)=>Bt(x.points,o,o,h,r)&&mt(x.points,l),"isValid")});if(f&&i.metrics)i.metrics.labelAwareSelfLoopsCommitted++;return g}let m=i.topologies.get(h);if(!m||!a)throw V("GRID_ROUTE_NOT_FOUND",`Missing routing topology "${h}"`);let b=uo(o,c,d);if(f){for(let g of b){let x=d.get(`${o.id}:${g}`)??0,w=z(o),M=g==="left"||g==="right"?w.cy:w.cx,S=lo(o,g,x,M,f);if(i.metrics)i.metrics.labelAwareSelfLoopCandidates+=S.length;for(let E of S)if(Bt(E,o,o,h,r)&&mt(E,l)){if(i.metrics)i.metrics.labelAwareSelfLoopsCommitted++;return{points:E,side:g,index:x}}}if(i.metrics)i.metrics.labelAwareSelfLoopFallbacks++}for(let g of b){let x=d.get(`${o.id}:${g}`)??0,w=Ir(o,g,x);if(!w)continue;let{start:M,target:S}=w;try{Oe({metrics:i.metrics,caps:u.searchCaps,budget:i.searchBudget});let E=Qe(m,M.connect,S.connect,i.metrics,a,[{x:(M.connect.x+S.connect.x)/2,y:(M.connect.y+S.connect.y)/2}]),I=E.pointVertexIds.get(yt(M.connect)),v=E.pointVertexIds.get(yt(S.connect));if(I===void 0||v===void 0)throw V("GRID_ROUTE_NOT_FOUND",`Self-loop endpoint projection is missing from the routing overlay for "${t.edge.id}"`,{edgeId:t.edge.id,containerId:h,source:M.connect,target:S.connect,side:g});let R=g==="left"||g==="right"?"H":"V",A=en(E,I,v,{metrics:i.metrics,caps:{...u.searchCaps,maxEstimatedBytes:u.searchCaps?.maxEstimatedBytes??u.topologyCaps?.maxEstimatedBytes??jt},recordOutcome:!1,budget:i.searchBudget,initialOrientation:R,initialSide:g,initialLength:Z,targetOrientation:R,targetSide:g,targetLength:Z,topologyValidated:!0,workspace:s,estimatedBytesBase:i.baseEstimatedBytes+E.estimatedBytes-m.estimatedBytes,arcAllowed:e((O,P)=>tn(O,P,l),"arcAllowed")});if(!A)continue;let C=H([M.port,...A.points,S.port]).points;if(Bt(C,o,o,h,r)&&mt(C,l))return{points:C,side:g,index:x}}catch(E){if(!(E instanceof Tt))throw E;let I=Qt({context:i,reason:E.reason,edgeId:t.edge.id,containerId:h,searchStateScope:E.searchStateScope,route:y,isValid:e((v)=>Bt(v.points,o,o,h,r)&&mt(v.points,l),"isValid")});if(f&&i.metrics)i.metrics.labelAwareSelfLoopsCommitted++;return I}}if(i.metrics)i.metrics.routesImpossible++;throw V("GRID_ROUTE_NOT_FOUND",`No distinct self-loop route for "${t.edge.id}"`,{edgeId:t.edge.id,nodeId:o.id})}e(Mr,"sparseSelfLoopRoute");function Ln(t,o,r,i,s,a,c,d,l,u,h=[],f=()=>[],p=()=>[],y=!1,m){let b=c.fallbackContainers.get(o);if(b)return Qt({context:c,reason:b,edgeId:t,containerId:o,route:s,isValid:e((I)=>$t(I,r.ownerId,i.ownerId,o,a)&&mt(I,h),"isValid"),includeContainerIdInError:!0});let g=c.topologies.get(o);if(!g||!l)throw V("GRID_ROUTE_NOT_FOUND",`Missing routing topology "${o}"`);let x=[{start:r,end:i,select:[]}],w=!1,M=e(()=>{if(w)return;w=!0;let I=p(),v=f();x.push(...v.map((R)=>({start:r,end:R.attachment,select:[R.select]})),...I.map((R)=>({start:R.attachment,end:i,select:[R.select]})),...I.flatMap((R)=>v.map((A)=>({start:R.attachment,end:A.attachment,select:[R.select,A.select]}))))},"appendAlternatives"),S=m!==void 0&&m.index.size>0?[!0,!1]:[!1];try{for(let I of S)for(let[v,R]of x.entries()){let{start:A,end:C}=R;if(v>0&&c.metrics)c.metrics.hierarchyPortalAlternativeAttempts++;if(qi(A.connect,C.connect)){let D=H([A.port,A.connect,C.connect,C.port]).points;if($t(D,A.ownerId,C.ownerId,o,a)&&mt(D,h)&&!(I&&m.index.conflictsWithRoute(D,m.pairKey))){for(let Q of R.select)Q();if(v>0&&c.metrics)c.metrics.hierarchyPortalAlternativeSelections++;return D}}Oe({metrics:c.metrics,caps:u.searchCaps,budget:c.searchBudget});let P=Qe(g,A.connect,C.connect,c.metrics,l),L=c.baseEstimatedBytes+P.estimatedBytes-g.estimatedBytes;if(L>(u.topologyCaps?.maxEstimatedBytes??jt))throw new Tt("estimated_memory_cap","Grid routing estimated_memory_cap exceeded");let N=P.pointVertexIds.get(yt(A.connect)),T=P.pointVertexIds.get(yt(C.connect));if(N===void 0||T===void 0){if(v===0)M();continue}let Y=en(P,N,T,{metrics:c.metrics,caps:{...u.searchCaps,maxEstimatedBytes:u.searchCaps?.maxEstimatedBytes??u.topologyCaps?.maxEstimatedBytes??jt},recordOutcome:!1,budget:c.searchBudget,initialOrientation:A.side==="left"||A.side==="right"?"H":"V",initialSide:A.side,initialLength:Math.abs(A.port.x-A.connect.x)+Math.abs(A.port.y-A.connect.y),targetOrientation:C.side==="left"||C.side==="right"?"H":"V",targetSide:C.side,targetLength:Math.abs(C.port.x-C.connect.x)+Math.abs(C.port.y-C.connect.y),topologyValidated:!0,workspace:d,estimatedBytesBase:L,arcAllowed:h.length>0||I?(D,Q)=>(h.length===0||tn(D,Q,h))&&!(I&&m.index.conflictsWithArc(D,Q,m.pairKey)):void 0});if(!Y){if(v===0)M();continue}let q=H([A.port,...Y.points,C.port]).points;if(!$t(q,A.ownerId,C.ownerId,o,a)||!mt(q,h)||I&&m.index.conflictsWithRoute(q,m.pairKey)){if(v===0)M();continue}for(let D of R.select)D();if(v>0&&c.metrics)c.metrics.hierarchyPortalAlternativeSelections++;return q}}catch(I){if(!(I instanceof Tt))throw I;return Qt({context:c,reason:I.reason,edgeId:t,containerId:o,searchStateScope:I.searchStateScope,route:s,isValid:e((v)=>$t(v,r.ownerId,i.ownerId,o,a)&&mt(v,h),"isValid"),includeContainerIdInError:!0})}let E=s();if($t(E,r.ownerId,i.ownerId,o,a)&&(mt(E,h)||y&&so(E,h))){if(c.metrics)c.metrics.compatibilitySegments++,c.metrics.compatibilityRecoveries++;return E}throw V("GRID_ROUTE_NOT_FOUND",`No hierarchy route for "${t}" in "${o}" from ${yt(r.connect)} to ${yt(i.connect)}`,{edgeId:t,containerId:o})}e(Ln,"sparseContainerSegment");function Cr(t,o,r,i,s,a,c){let d=t[0].pairKey,l=o.get(d),u=[...new Set(t.flatMap((y)=>[...y.source.chain,...y.target.chain].map(({demandKey:m})=>m)))],h=new Map,f=new Map;for(let y of u){let m=r.get(y);if(m)h.set(y,m);let b=i.get(y);if(b!==void 0)f.set(y,b)}let p=c.get(t[0].lcaContainerId);return{pairKey:d,occupancy:p?{index:p,size:p.size}:void 0,pairRoutes:l?[...l]:void 0,demandKeys:u,pairedPortals:h,demandCoords:f,edges:t.map(({edge:y})=>({edge:y,points:y.points,curve:y.curve,cornerRadius:y.cornerRadius})),instrumentedRoutesLength:s?.length,metrics:a?lr(a):void 0}}e(Cr,"createBundleCheckpoint");function Sr(t,o,r,i,s,a){if(t.occupancy?.index.truncate(t.occupancy.size),t.pairRoutes)o.set(t.pairKey,[...t.pairRoutes]);else o.delete(t.pairKey);for(let c of t.demandKeys){let d=t.pairedPortals.get(c);if(d)r.set(c,d);else r.delete(c);let l=t.demandCoords.get(c);if(l!==void 0)i.set(c,l);else i.delete(c)}for(let c of t.edges)c.edge.points=c.points,c.edge.curve=c.curve,c.edge.cornerRadius=c.cornerRadius;if(s&&t.instrumentedRoutesLength!==void 0)s.length=t.instrumentedRoutesLength;if(a&&t.metrics)ur(a,t.metrics)}e(Sr,"restoreBundleCheckpoint");var es=class{constructor(t,o,r,i){this.layout=t,this.result=o,this.metrics=r,this.options=i,this.searchWorkspace=new gr,this.pairedPortals=new Map,this.ownerSideCounts=new Map,this.selfLoopCounts=new Map,this.pairRoutes=new Map,this.routed=!1}static{e(this,"GridEdgeRoutingSession")}route(){if(this.routed)throw Error("Grid edge routing session can only be run once");this.routed=!0,this.prepare();let t=new Map;for(let o of this.prepared.orderedPlans){let r=t.get(o.pairKey)??[];r.push(o),t.set(o.pairKey,r)}for(let o of t.values())this.routeBundle(o)}prepare(){ir(this.result),this.prepared=Vi(this.layout,this.result),this.modes=dr(this.prepared,this.result,this.metrics,this.options),this.routingContext=ar(this.modes.routedContainerIds,this.result,this.metrics,this.options),this.endpointOverlayScratch=new Map([...this.routingContext.topologies].map(([o,r])=>[o,new Ri(r)])),this.instrumentedRoutes=this.metrics?[]:void 0;let t=new Set;for(let o of this.prepared.orderedPlans){if(o.edge.start===o.edge.end)continue;for(let r of[...o.source.chain,...o.target.chain]){if(t.has(r.demandKey))continue;t.add(r.demandKey);let i=ae(r.ownerId,r.side);this.ownerSideCounts.set(i,(this.ownerSideCounts.get(i)??0)+1)}}}pairedPortal(t){let o=this.pairedPortals.get(t.demandKey);if(o)return o;let r=this.result.forest.nodeById.get(t.ownerId);if(!r?.isGroup)throw V("GRID_ROUTE_NOT_FOUND",`Missing portal owner "${t.ownerId}"`);let i=Ft(r),s=this.prepared.demandCoords.get(t.demandKey)??(t.side==="left"||t.side==="right"?(i.top+i.bottom)/2:(i.left+i.right)/2),a=se(t.ownerId,i,r.groupTitleRect).find(({side:d})=>d===t.side);if(!a)throw V("GRID_ROUTE_NOT_FOUND",`No legal ${t.side} portal for "${t.ownerId}"`);let c=mn(t.ownerId,i,r.groupTitleRect?{...r.groupTitleRect}:void 0,t.side,Gt(s,a.low,a.high));if(this.pairedPortals.set(t.demandKey,c),this.metrics)this.metrics.hierarchyPortalPairs++,this.metrics.hierarchyPortalTransitionLength+=c.transition.length;return c}alternativePairedPortals(t,o=!0){let r=this.pairedPortal(t),i=this.result.forest.nodeById.get(t.ownerId);if(!i?.isGroup)return[];let s=Ft(i),a=se(t.ownerId,s,i.groupTitleRect).find(({side:l})=>l===t.side);if(!a)return[];let c=this.result.containers.get(i.id),d=t.side==="left"||t.side==="right"?c?.horizontalCorridors:c?.verticalCorridors;return Yi(r.tangentialCoordinate,a.low,a.high,d??[]).map((l)=>{let u=mn(t.ownerId,s,i.groupTitleRect?{...i.groupTitleRect}:void 0,t.side,l);return{attachment:Jt(u,o),select:e(()=>{this.pairedPortals.set(t.demandKey,u),this.prepared.demandCoords.set(t.demandKey,l)},"select")}})}itemSegmentAttachment(t,o){return{ownerId:t.ownerId,...Ee(t.ownerId,t.side,t.demandKey,o,this.result,this.prepared.demandCoords)}}alternativeItemAttachments(t,o,r){let i=this.itemSegmentAttachment(o,r),s=this.result.forest.nodeById.get(o.ownerId);if(!s)return[];return["right","bottom","left","top"].filter((a)=>a!==i.side&&!(a==="top"&&Ze(s))).map((a)=>{let c=Lt(s,a);if(!c)return;let d=z(s),l=a==="left"||a==="right"?d.cy:d.cx,u=Math.max(c.low,Math.min(c.high,l+t.laneOffset));return{ownerId:o.ownerId,...Ee(o.ownerId,a,o.demandKey,r,this.result,this.prepared.demandCoords,u)}}).filter((a)=>a!==void 0).slice(0,3).map((a)=>({attachment:a,select:e(()=>{return},"select")}))}routePlan(t,o=!0){let r=this.result,i=this.routingContext,s=this.searchWorkspace,a=this.endpointOverlayScratch,c=this.prepared.demandCoords,d=this.ownerSideCounts,l=this.selfLoopCounts,u=this.pairRoutes,h=this.instrumentedRoutes,f=this.metrics,p=this.options,y=this.prepared.eligibleIds,m=this.prepared.endpointCandidatesByEdge,b=this.modes.compatibilityFastRoutes,g=this.modes.sparseHierarchyIds,x=this.modes.sparseLcaIds,w=t.edge,M=w.start?r.forest.nodeById.get(w.start):void 0,S=w.end?r.forest.nodeById.get(w.end):void 0;if(!M||!S)throw V("GRID_MISSING_ENDPOINT",`Missing endpoint for edge "${w.id}"`,{edgeId:w.id});if(M.id===S.id){let k=u.get(t.pairKey)??[],{points:J,side:ct,index:ft}=Mr(t,M,r,i,s,a.get(M.parentId??X),d,l,k,p),st=`${M.id}:${ct}`;if(l.set(st,ft+1),w.points=J,w.curve=r.config.curve,w.cornerRadius=r.config.edgeCornerRadius,k.push(J),u.set(t.pairKey,k),f&&h)Rn(f,w.id,J,h,0,t.laneOffset),h.push(J);return}let E=t.source.chain[t.source.chain.length-1],I=t.target.chain[t.target.chain.length-1],v=x.has(w.id),R=v?void 0:Re(t,r,c),A=R?R.start:t.source.finalKind==="boundary"?Mn(E.ownerId,E.side,E.demandKey,r,c):t.source.chain.length>1?Jt(this.pairedPortal(E),!1):this.itemSegmentAttachment(E,t.lcaContainerId),C=R?R.end:t.target.finalKind==="boundary"?Mn(I.ownerId,I.side,I.demandKey,r,c):t.target.chain.length>1?Jt(this.pairedPortal(I),!1):this.itemSegmentAttachment(I,t.lcaContainerId),O,P=e(()=>O??=qt(t.lcaContainerId,r,A,C,t.laneIndex),"legacyRoute"),L=b.get(w.id),N=L?(()=>{if(f)f.compatibilityFastPaths++;return L})():y.has(w.id)?vr(t,m.get(w.id).sources,m.get(w.id).targets,M,S,P,r,i,s,a.get(t.lcaContainerId),p,u.get(t.pairKey)??[],{index:this.occupancyFor(t.lcaContainerId),pairKey:t.pairKey,prioritizeEndpointCandidates:this.prepared.coordinatedEndpointIds.has(w.id)}):v?Ln(w.id,t.lcaContainerId,A,C,P,r,i,s,a.get(t.lcaContainerId),p,u.get(t.pairKey)??[],()=>t.target.finalKind==="item"&&t.target.chain.length>1?this.alternativePairedPortals(I,!1):[],()=>t.source.finalKind==="item"&&t.source.chain.length>1?this.alternativePairedPortals(E,!1):[],t.bundleSize>1,this.modes.overlapAvoidanceEnabled?{index:this.occupancyFor(t.lcaContainerId),pairKey:t.pairKey}:void 0):Sn(w.id,t.lcaContainerId,A,C,P,r,f),T=e((k,J)=>{if(!g.has(w.id)){for(let{containerId:ct,start:ft,end:st}of ho(k,r,c))J.push(Sn(w.id,ct,ft,st,()=>qt(ct,r,ft,st,t.laneIndex),r,f));return}for(let ct=0;ct<k.chain.length-1;ct++){let ft=k.chain[ct],st=k.chain[ct+1],bt=ct===0?this.itemSegmentAttachment(ft,st.ownerId):Jt(this.pairedPortal(ft),!1),B=Jt(this.pairedPortal(st),!0);J.push(Ln(w.id,st.ownerId,bt,B,()=>qt(st.ownerId,r,bt,B,t.laneIndex),r,i,s,a.get(st.ownerId),p,u.get(t.pairKey)??[],()=>this.alternativePairedPortals(st),()=>ct===0?this.alternativeItemAttachments(t,ft,st.ownerId):[],t.bundleSize>1))}},"routeHierarchyChain"),Y=[],q=[];T(t.source,Y),T(t.target,q);let D=tr([...Y,N,...q.reverse().map((k)=>Ji(k))]),Q=u.get(t.pairKey)??[],Ct=mt(D,Q),it=!Ct&&t.bundleSize>1&&t.source.chain.length+t.target.chain.length>2&&so(D,Q);if(t.bundleSize>1&&!Ct&&(!it||!o)){if(f)f.routesImpossible++;throw V("GRID_ROUTE_NOT_FOUND",`No distinct lane route for "${w.id}"`,{edgeId:w.id,reason:it?"pair-separation":"no-distinct-route"})}if(it&&f)f.bundleSeparationRelaxations++;if(w.points=D,w.curve=r.config.curve,w.cornerRadius=r.config.edgeCornerRadius,Q.push(D),u.set(t.pairKey,Q),!L)this.occupancyFor(t.lcaContainerId).add(N,t.pairKey);if(f&&h){let k=t.source.chain.length+t.target.chain.length-2;Rn(f,w.id,D,h,k,t.laneOffset),h.push(D)}}occupancyFor(t){let o=this.modes.routeOccupancy.get(t);if(!o)o=new In,this.modes.routeOccupancy.set(t,o);return o}createBundleCheckpoint(t){return this.occupancyFor(t[0].lcaContainerId),Cr(t,this.pairRoutes,this.pairedPortals,this.prepared.demandCoords,this.instrumentedRoutes,this.metrics,this.modes.routeOccupancy)}restoreBundleCheckpoint(t){Sr(t,this.pairRoutes,this.pairedPortals,this.prepared.demandCoords,this.instrumentedRoutes,this.metrics)}routeBundle(t){if(!(t.length>1&&t.length<=8&&t.every(({edge:s})=>s.start!==s.end))){for(let s of t)this.routePlan(s);return}let r=this.createBundleCheckpoint(t),i;try{for(let s of t)this.routePlan(s,!1);return}catch(s){i=s,this.restoreBundleCheckpoint(r)}if(!$i(i))throw i;for(let s of t)this.routePlan(s)}};function Er(t,o,r,i={}){new es(t,o,r,i).route()}e(Er,"routeGridEdges");var ns=24,Le=20;function Rr(t,o){if(!t.label||!t.labelBBox||!(t.labelBBox.height>0))return 0;return t.labelBBox.height+o}e(Rr,"titleBandFor");function Ar(t){if(!tt(t.width)||!tt(t.height))throw V("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})}e(Ar,"ensureMeasuredNode");function Pn(t){return Ar(t),{width:t.width,height:t.height}}e(Pn,"measureChild");function _n(t,o,r,i,s){let{forest:a,config:c,sourceOrder:d}=o,l=t===X?void 0:a.groupById.get(t),u=l?Math.max(l.padding??0,c.containerPadding):0,h=l?Rr(l,c.titleGap):0,f=l?ns:0,p=l?u+h+f:0,y=(a.childrenByParent.get(t)??[]).filter((B)=>!xt(B)),{cells:m}=Si(y,d,c),b=[...m.values()].sort((B,F)=>B.row-F.row||B.column-F.column),g=new Map,x=new Map,w=new Set,M=new Set;for(let B of b){let F=0,dt=0;for(let _ of B.items){let G=Pn(_.item);F=Math.max(F,G.width),dt+=G.height}if(B.items.length>1)dt+=c.cellGap*(B.items.length-1);B.width=F,B.height=dt,w.add(B.row),M.add(B.column),g.set(B.column,Math.max(g.get(B.column)??0,F)),x.set(B.row,Math.max(x.get(B.row)??0,dt))}let S=[...w].sort((B,F)=>B-F),E=[...M].sort((B,F)=>B-F),I=mi(o.labelRequirements.byContainer.get(t)??[],m,x,g,S,E,c.rowGap,c.columnGap,s),v=e((B)=>Math.max(c.rowGap,I.rowGapAfter.get(B)??0),"rowGapAfter"),R=e((B)=>Math.max(c.columnGap,I.columnGapAfter.get(B)??0),"columnGapAfter");if(s){for(let B of I.rowGapAfter.values())if(B>c.rowGap)s.labelSpacingBoundariesExpanded++,s.labelSpacingPixelsAdded+=B-c.rowGap;for(let B of I.columnGapAfter.values())if(B>c.columnGap)s.labelSpacingBoundariesExpanded++,s.labelSpacingPixelsAdded+=B-c.columnGap}let A=E.reduce((B,F,dt)=>B+(g.get(F)??0)+(dt<E.length-1?R(F):0),0),C=l?Math.max(A+(u+f)*2,(l.labelBBox?.width??0)+u*2):A,O=l?(C-A)/2:0,P=new Map,L=O;for(let[B,F]of E.entries())P.set(F,L),L+=(g.get(F)??0)+(B<E.length-1?R(F):0);let N=new Map,T=p;for(let[B,F]of S.entries())N.set(F,T),T+=(x.get(F)??0)+(B<S.length-1?v(F):0);let Y=S.length?T-p:0,q=l?O-Le:-Math.max(c.columnGap/2,vt.containerPadding),D=l?O+A+Le:O+A+Math.max(c.columnGap/2,vt.containerPadding),Q=l?p-Le:-Math.max(c.rowGap/2,vt.containerPadding),Ct=l?p+Y+Le:p+Y+Math.max(c.rowGap/2,vt.containerPadding),it=new Set([q,D]),k=new Set([Q,Ct]),J=new Map,ct=new Map,ft=new Map,st=new Map;if(E.length>0)J.set(E[0],q),ct.set(E.at(-1),D);for(let B=0;B<E.length-1;B++){let F=E[B],dt=E[B+1],_=(P.get(F)+(g.get(F)??0)+P.get(dt))/2;it.add(_),ct.set(F,_),J.set(dt,_)}if(S.length>0)ft.set(S[0],Q),st.set(S.at(-1),Ct);for(let B=0;B<S.length-1;B++){let F=S[B],dt=S[B+1],_=(N.get(F)+(x.get(F)??0)+N.get(dt))/2;k.add(_),st.set(F,_),ft.set(dt,_)}for(let B of b){let F=P.get(B.column)??O,dt=N.get(B.row)??p,_=g.get(B.column)??B.width,G=x.get(B.row)??B.height,lt=B.verticalAlign==="top"?0:B.verticalAlign==="bottom"?1:0.5,et=dt+(G-B.height)*lt;for(let[j,Rt]of B.items.entries()){let{width:fe,height:Pt}=Pn(Rt.item),pe=Rt.horizontalAlign==="left"?0:Rt.horizontalAlign==="right"?1:0.5,ge=F+(_-fe)*pe;Rt.item.x=ge+fe/2,Rt.item.y=et+Pt/2;let me=j>0?et-c.cellGap/2:ft.get(B.row)??Q,ye=j<B.items.length-1?et+Pt+c.cellGap/2:st.get(B.row)??Ct;if(j>0)k.add(me);if(j<B.items.length-1)k.add(ye);i.set(Rt.item.id,{containerId:t,row:B.row,column:B.column,cellLeft:F,cellTop:dt,cellWidth:_,cellHeight:G,leftCorridorX:J.get(B.column)??q,rightCorridorX:ct.get(B.column)??D,topCorridorY:me,bottomCorridorY:ye}),et+=Pt+c.cellGap}}let bt=l?Y+h+(u+f)*2:Y;if(r.set(t,{id:t,left:0,top:0,width:C,height:bt,contentLeft:O,contentTop:p,contentRight:l?O+A:A,contentBottom:l?p+Y:Y,verticalCorridors:[...it].sort((B,F)=>B-F),horizontalCorridors:[...k].sort((B,F)=>B-F)}),l)if(l.width=C,l.height=bt,l.x=C/2,l.y=bt/2,h>0)l.groupTitleRect={left:0,right:C,top:0,bottom:u+h};else delete l.groupTitleRect}e(_n,"layoutContainer");function Or(t,o,r){return{left:t.left+o,right:t.right+o,top:t.top+r,bottom:t.bottom+r}}e(Or,"translateRect");function Br(t){let{forest:o,containers:r,itemMeta:i}=t,s=[{containerId:X,offsetX:0,offsetY:0,children:o.childrenByParent.get(X)??[],nextChildIndex:0,entered:!1}];while(s.length>0){let a=s[s.length-1];if(!a.entered){a.entered=!0;let l=r.get(a.containerId);if(l)l.left+=a.offsetX,l.top+=a.offsetY,l.contentLeft+=a.offsetX,l.contentRight+=a.offsetX,l.contentTop+=a.offsetY,l.contentBottom+=a.offsetY,l.verticalCorridors=l.verticalCorridors.map((u)=>u+a.offsetX),l.horizontalCorridors=l.horizontalCorridors.map((u)=>u+a.offsetY)}let c=a.children[a.nextChildIndex];if(!c){s.pop();continue}if(a.nextChildIndex+=1,xt(c))continue;let d=i.get(c.id);if(d)d.cellLeft+=a.offsetX,d.cellTop+=a.offsetY,d.leftCorridorX+=a.offsetX,d.rightCorridorX+=a.offsetX,d.topCorridorY+=a.offsetY,d.bottomCorridorY+=a.offsetY;if(c.x=(c.x??0)+a.offsetX,c.y=(c.y??0)+a.offsetY,!c.isGroup)continue;if(c.groupTitleRect)c.groupTitleRect=Or(c.groupTitleRect,c.x-(c.width??0)/2,c.y-(c.height??0)/2);s.push({containerId:c.id,offsetX:c.x-(c.width??0)/2,offsetY:c.y-(c.height??0)/2,children:o.childrenByParent.get(c.id)??[],nextChildIndex:0,entered:!1})}}e(Br,"materializeAbsoluteGeometry");function Pr(t,o){let r=new Map(t.nodes.map((s)=>[s.id,s]));for(let s of o.nodes){let a=r.get(s.id);if(!a)continue;if(s.x=a.x,s.y=a.y,s.width=a.width,s.height=a.height,a.groupTitleRect)s.groupTitleRect={...a.groupTitleRect};else delete s.groupTitleRect}let i=new Map(t.edges.map((s)=>[s.id,s]));for(let s of o.edges){let a=i.get(s.id);if(!a)continue;s.points=a.points?.map((c)=>({...c})),s.curve=a.curve,s.cornerRadius=a.cornerRadius,s.portClipping="outline-orthogonal",s.skipCornerFix=a.curve==="linear"}}e(Pr,"commitGridGeometry");function _r(t){return{...t,nodes:t.nodes.map((o)=>({...o,labelBBox:o.labelBBox?{...o.labelBBox}:o.labelBBox,groupTitleRect:o.groupTitleRect?{...o.groupTitleRect}:o.groupTitleRect})),edges:t.edges.map((o)=>({...o,points:o.points?.map((r)=>({...r}))}))}}e(_r,"cloneGridLayoutData");function Gr(t,o){let r=new Map(o.map((a)=>[a.id,a])),i=e((a)=>{let c=r.get(a.id);if(!c)throw Error(`Missing committed grid node "${a.id}"`);return c},"originalNode"),s=e((a)=>{let c=i(a);if(!c.isGroup)throw Error(`Committed grid node "${a.id}" is no longer a group`);return c},"originalGroup");return{nodeById:r,groupById:new Map([...t.groupById].map(([a,c])=>[a,s(c)])),childrenByParent:new Map([...t.childrenByParent].map(([a,c])=>[a,c.map(i)])),rootChildren:t.rootChildren.map(i),postOrderGroups:t.postOrderGroups.map(s),helperNodeIds:new Set(t.helperNodeIds)}}e(Gr,"rebindGridForest");function Tr(t,o){let r=hi(t.nodes),i=xi(t),s=yi(t.nodes.filter((c)=>!xt(c)));bi(t.nodes.filter((c)=>!xt(c)),i);let a={forest:r,config:i,containers:new Map,itemMeta:new Map,sourceOrder:s,labelRequirements:fi(t,r,o.metrics)};for(let c of r.postOrderGroups)_n(c.id,a,a.containers,a.itemMeta,o.metrics);return _n(X,a,a.containers,a.itemMeta,o.metrics),Br(a),Er(t,a,o.metrics,o.routing),ui(t,void 0,o.metrics),a}e(Tr,"runGridLayoutCoreInPlace");function Nr(t,o={}){let r=t,i=_r(r),s=Tr(i,o);return Pr(i,r),{...s,forest:Gr(s.forest,r.nodes)}}e(Nr,"runGridLayoutCore");function Fr(t,{measure:o}){let r=Mt(t.config.grid?.lineHops);if(r===!1)return;let i=t.edges.filter((s)=>Array.isArray(s.points)&&s.points.length>=2).map((s)=>({id:s.id,points:s.points,curve:s.curve,cornerRadius:s.cornerRadius,arrowTypeStart:s.arrowTypeStart,arrowTypeEnd:s.arrowTypeEnd}));Nt(o.groups.edgePaths,i,{enabled:!0,jumpRadius:6,jumpStyle:r})}e(Fr,"applyGridLineJumps");var ys=ot({prepareLayout:li,runLayoutCore:e((t)=>Nr(t),"runLayoutCore"),afterPaint:Fr});export{li as prepareGridLayout,ys as render,Nr as runGridLayoutCore};