for-humanity 0.12.0 → 0.13.1

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 (226) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/README.md +16 -9
  3. package/dist/browser.js +14 -16
  4. package/dist/cli.css +2 -968
  5. package/dist/cli.js +92 -2318
  6. package/dist/config.js +1 -0
  7. package/dist/constant/copy.d.ts +100 -0
  8. package/dist/constant/site.d.ts +20 -0
  9. package/dist/constant/status.d.ts +19 -0
  10. package/dist/copy-C1uzvEnr.js +103 -0
  11. package/dist/group-path-XAThmzvC.js +10 -0
  12. package/dist/load-site-B-u5-jv0.js +2343 -0
  13. package/dist/logger-Dv1i9xSV.js +9 -0
  14. package/dist/mermaid/THIRD-PARTY-NOTICES.txt +3134 -0
  15. package/dist/mermaid/chunk--TN-qHgG.js +2 -0
  16. package/dist/mermaid/chunk-0kM1Lv4D.js +2 -0
  17. package/dist/mermaid/chunk-3FHei3pH.js +2001 -0
  18. package/dist/mermaid/chunk-3_2p2GqN.js +2 -0
  19. package/dist/mermaid/chunk-6HLei9i0.js +84 -0
  20. package/dist/mermaid/chunk-7Sz3kAwl.js +2214 -0
  21. package/dist/mermaid/chunk-7Tarqbpa.js +18047 -0
  22. package/dist/mermaid/chunk-9kkt8lzL.js +10 -0
  23. package/dist/mermaid/chunk-B--pNBQF.js +884 -0
  24. package/dist/mermaid/chunk-B4F-pysn.js +4241 -0
  25. package/dist/mermaid/chunk-B58sEIY_.js +14 -0
  26. package/dist/mermaid/chunk-B9_UWzSH.js +1517 -0
  27. package/dist/mermaid/chunk-BB8uZHwY.js +75 -0
  28. package/dist/mermaid/chunk-BFfk0LEc.js +717 -0
  29. package/dist/mermaid/chunk-BKri0qr7.js +89 -0
  30. package/dist/mermaid/chunk-BL404pH5.js +26 -0
  31. package/dist/mermaid/chunk-BLeiQSWo.js +354 -0
  32. package/dist/mermaid/chunk-BOmH_UFd.js +2 -0
  33. package/dist/mermaid/chunk-BSej9Nhy.js +1361 -0
  34. package/dist/mermaid/chunk-BYzrzvCI.js +12 -0
  35. package/dist/mermaid/chunk-BariMtWr.js +3020 -0
  36. package/dist/mermaid/chunk-BcrBoMwH.js +2352 -0
  37. package/dist/mermaid/chunk-Bok8z-Yo.js +67 -0
  38. package/dist/mermaid/chunk-BpTHLKQM.js +1970 -0
  39. package/dist/mermaid/chunk-BqjuxRsC.js +733 -0
  40. package/dist/mermaid/chunk-BuvPd-s5.js +1073 -0
  41. package/dist/mermaid/chunk-BvVehae3.js +5069 -0
  42. package/dist/mermaid/chunk-C-JABYpd.js +3075 -0
  43. package/dist/mermaid/chunk-C9XlTm4w.js +2 -0
  44. package/dist/mermaid/chunk-CApNbSU9.js +6 -0
  45. package/dist/mermaid/chunk-CCM2AH-C.js +9 -0
  46. package/dist/mermaid/chunk-CD1E0F_N.js +2 -0
  47. package/dist/mermaid/chunk-CDWvKG7D.js +2 -0
  48. package/dist/mermaid/chunk-CEVPpC1F.js +34 -0
  49. package/dist/mermaid/chunk-CLDr12lf.js +47504 -0
  50. package/dist/mermaid/chunk-CLVYqOBI.js +61 -0
  51. package/dist/mermaid/chunk-CLeOkFb5.js +15 -0
  52. package/dist/mermaid/chunk-CLgRAtOz.js +37 -0
  53. package/dist/mermaid/chunk-CMqFNUBl.js +134 -0
  54. package/dist/mermaid/chunk-CTPaBJXB.js +2 -0
  55. package/dist/mermaid/chunk-CVi6IGBL.js +2 -0
  56. package/dist/mermaid/chunk-CWV_EN-4.js +4745 -0
  57. package/dist/mermaid/chunk-CZ0dAs3g.js +2 -0
  58. package/dist/mermaid/chunk-C_YGy4Fn.js +236 -0
  59. package/dist/mermaid/chunk-CcVH22Yt.js +100 -0
  60. package/dist/mermaid/chunk-CgG6CD9_.js +7175 -0
  61. package/dist/mermaid/chunk-CgOP6IDB.js +3397 -0
  62. package/dist/mermaid/chunk-Cgg2UTSf.js +13 -0
  63. package/dist/mermaid/chunk-ChJfJJ1A.js +214 -0
  64. package/dist/mermaid/chunk-Ck5XRA46.js +447 -0
  65. package/dist/mermaid/chunk-Ckuw16cl.js +203 -0
  66. package/dist/mermaid/chunk-CpAbRCbF.js +1880 -0
  67. package/dist/mermaid/chunk-CuYekbSv.js +2 -0
  68. package/dist/mermaid/chunk-CwS4wZ5a.js +2 -0
  69. package/dist/mermaid/chunk-D-bcrBO3.js +82 -0
  70. package/dist/mermaid/chunk-D3IEAkCW.js +76 -0
  71. package/dist/mermaid/chunk-D8XfBJ_K.js +645 -0
  72. package/dist/mermaid/chunk-D9Ddd9y4.js +2228 -0
  73. package/dist/mermaid/chunk-DBh1mIbK.js +12 -0
  74. package/dist/mermaid/chunk-DD6Df6Ic.js +5 -0
  75. package/dist/mermaid/chunk-DGVDaXjx.js +8 -0
  76. package/dist/mermaid/chunk-DK9KqIXj.js +632 -0
  77. package/dist/mermaid/chunk-DORnIAsy.js +4487 -0
  78. package/dist/mermaid/chunk-DU69_VcF.js +363 -0
  79. package/dist/mermaid/chunk-DVNvSFoz.js +2144 -0
  80. package/dist/mermaid/chunk-DZe-4kde.js +20 -0
  81. package/dist/mermaid/chunk-D_a06Rz4.js +287 -0
  82. package/dist/mermaid/chunk-DfyFJJi2.js +972 -0
  83. package/dist/mermaid/chunk-DhKYPp1Z.js +2 -0
  84. package/dist/mermaid/chunk-DjFqgNTG.js +94 -0
  85. package/dist/mermaid/chunk-DmbDDrr-.js +65 -0
  86. package/dist/mermaid/chunk-DpuxlyL_.js +696 -0
  87. package/dist/mermaid/chunk-DqGhppWe.js +2 -0
  88. package/dist/mermaid/chunk-DqPZxHXa.js +5 -0
  89. package/dist/mermaid/chunk-Dt_1Jyif.js +293 -0
  90. package/dist/mermaid/chunk-DyQBE_NW.js +1935 -0
  91. package/dist/mermaid/chunk-JckyC4mW.js +1009 -0
  92. package/dist/mermaid/chunk-K7Myuj2-.js +1334 -0
  93. package/dist/mermaid/chunk-KuPYb48V.js +275 -0
  94. package/dist/mermaid/chunk-MFVRUoO0.js +4020 -0
  95. package/dist/mermaid/chunk-MbInCS_6.js +28 -0
  96. package/dist/mermaid/chunk-MexOLyKV.js +355 -0
  97. package/dist/mermaid/chunk-NnbDtJzg.js +21856 -0
  98. package/dist/mermaid/chunk-SGpOYZbI.js +2139 -0
  99. package/dist/mermaid/chunk-TbxLDlcU.js +198 -0
  100. package/dist/mermaid/chunk-TftHqGLg.js +490 -0
  101. package/dist/mermaid/chunk-UjQ8vA_Z.js +4138 -0
  102. package/dist/mermaid/chunk-YgmVTKqc.js +16 -0
  103. package/dist/mermaid/chunk-_a9EZE1v.js +1798 -0
  104. package/dist/mermaid/chunk-dTb8jqeP.js +2 -0
  105. package/dist/mermaid/chunk-fFdMfF8S.js +2240 -0
  106. package/dist/mermaid/chunk-feYbMzBj.js +1267 -0
  107. package/dist/mermaid/chunk-g3Pn8DkW.js +46 -0
  108. package/dist/mermaid/chunk-hM77LvCb.js +19832 -0
  109. package/dist/mermaid/chunk-hUDb-eAW.js +527 -0
  110. package/dist/mermaid/chunk-tpABtZ-3.js +4252 -0
  111. package/dist/mermaid/chunk-xIbz3oFK.js +59 -0
  112. package/dist/mermaid/chunk-yBz-vst0.js +976 -0
  113. package/dist/mermaid/mermaid-BhtR3wyB.js +1145 -0
  114. package/dist/run-site-command-cqCjpIlc.js +129 -0
  115. package/dist/site-config-bllORGpm.js +90 -0
  116. package/dist/site.js +1 -0
  117. package/dist/start-dev-server-x7Ja5uwv.js +184 -0
  118. package/dist/to-change-queue-DbEnZGNK.js +34 -0
  119. package/dist/to-error-message-pF6_7wGK.js +16 -0
  120. package/dist/type/group-path.d.ts +7 -0
  121. package/dist/type/site-config.d.ts +57 -0
  122. package/package.json +34 -17
  123. package/src/component/widget/cursor-face/_constant/cursor-face.ts +0 -14
  124. package/src/component/widget/cursor-face/wg-cursor-face.css +0 -15
  125. package/src/component/widget/cursor-face/wg-cursor-face.tsx +0 -153
  126. package/src/component/widget/navigation/_constant/locale.ts +0 -9
  127. package/src/component/widget/navigation/_constant/navigation-data-schema.ts +0 -33
  128. package/src/component/widget/navigation/_constant/navigation.ts +0 -9
  129. package/src/component/widget/navigation/_constant/reading-line.ts +0 -4
  130. package/src/component/widget/navigation/_function/restore-navigation-scroll.ts +0 -59
  131. package/src/component/widget/navigation/_function/to-doc-groups/_to-doc-branches.ts +0 -15
  132. package/src/component/widget/navigation/_function/to-doc-groups/_to-doc-group-branches.ts +0 -70
  133. package/src/component/widget/navigation/_function/to-doc-groups/to-doc-groups.ts +0 -15
  134. package/src/component/widget/navigation/_function/to-navigation-data/_to-navigation-document.ts +0 -13
  135. package/src/component/widget/navigation/_function/to-navigation-data/_to-navigation-group.ts +0 -13
  136. package/src/component/widget/navigation/_function/to-navigation-data/to-navigation-data.ts +0 -18
  137. package/src/component/widget/navigation/_function/to-navigation-json.ts +0 -8
  138. package/src/component/widget/navigation/_function/to-toc-groups.ts +0 -38
  139. package/src/component/widget/navigation/_type/doc-branch.ts +0 -11
  140. package/src/component/widget/navigation/_type/doc-group.ts +0 -24
  141. package/src/component/widget/navigation/_type/navigation-data.ts +0 -75
  142. package/src/component/widget/navigation/_type/navigation-focus-snapshot.ts +0 -17
  143. package/src/component/widget/navigation/_type/toc-group.ts +0 -39
  144. package/src/component/widget/navigation/_wg-navigation-nav-list.css +0 -48
  145. package/src/component/widget/navigation/_wg-navigation-nav-list.tsx +0 -61
  146. package/src/component/widget/navigation/_wg-navigation-nav.css +0 -21
  147. package/src/component/widget/navigation/_wg-navigation-nav.tsx +0 -33
  148. package/src/component/widget/navigation/_wg-navigation-scroll.tsx +0 -117
  149. package/src/component/widget/navigation/_wg-navigation-toc.css +0 -91
  150. package/src/component/widget/navigation/_wg-navigation-toc.tsx +0 -114
  151. package/src/component/widget/navigation/wg-navigation.css +0 -282
  152. package/src/component/widget/navigation/wg-navigation.tsx +0 -420
  153. package/src/component/widget/prose/_constant/heading-highlight.ts +0 -4
  154. package/src/component/widget/prose/_constant/section.ts +0 -7
  155. package/src/component/widget/prose/_constant/status.ts +0 -9
  156. package/src/component/widget/prose/_function/has-block-content.ts +0 -30
  157. package/src/component/widget/prose/_function/rehype-head.ts +0 -31
  158. package/src/component/widget/prose/_function/rehype-sections/_to-section-headings.ts +0 -20
  159. package/src/component/widget/prose/_function/rehype-sections/rehype-sections.ts +0 -21
  160. package/src/component/widget/prose/_function/rehype-tables.ts +0 -22
  161. package/src/component/widget/prose/_function/remark-blocks.ts +0 -112
  162. package/src/component/widget/prose/_function/remark-flow.ts +0 -26
  163. package/src/component/widget/prose/_function/remark-links.ts +0 -33
  164. package/src/component/widget/prose/_function/remark-parts.ts +0 -26
  165. package/src/component/widget/prose/_function/remark-status.ts +0 -59
  166. package/src/component/widget/prose/_function/remark-swatch.ts +0 -16
  167. package/src/component/widget/prose/_function/remark-unknown-directives.ts +0 -25
  168. package/src/component/widget/prose/wg-prose.css +0 -484
  169. package/src/component/widget/prose/wg-prose.tsx +0 -43
  170. package/src/component/widget/shell/wg-shell.css +0 -63
  171. package/src/component/widget/shell/wg-shell.tsx +0 -88
  172. package/src/component/widget/shell-controls/wg-shell-controls.css +0 -4
  173. package/src/component/widget/shell-controls/wg-shell-controls.tsx +0 -170
  174. package/src/constant/asset.ts +0 -63
  175. package/src/constant/copy.ts +0 -133
  176. package/src/constant/doc.ts +0 -13
  177. package/src/constant/font.ts +0 -34
  178. package/src/constant/site.ts +0 -24
  179. package/src/constant/status.ts +0 -15
  180. package/src/entry/browser/browser.tsx +0 -22
  181. package/src/entry/cli/_constant/cli.ts +0 -19
  182. package/src/entry/cli/_constant/crawling.ts +0 -14
  183. package/src/entry/cli/_constant/snippet.ts +0 -21
  184. package/src/entry/cli/_function/create-app.tsx +0 -57
  185. package/src/entry/cli/_function/create-dev-app.ts +0 -87
  186. package/src/entry/cli/_function/create-processor/_rehype-assets.ts +0 -70
  187. package/src/entry/cli/_function/create-processor/_rehype-heading-ids.ts +0 -34
  188. package/src/entry/cli/_function/create-processor/_remark-report.ts +0 -15
  189. package/src/entry/cli/_function/create-processor/_remark-snippets.ts +0 -117
  190. package/src/entry/cli/_function/create-processor/_shiki-transformers.ts +0 -91
  191. package/src/entry/cli/_function/create-processor/create-processor.ts +0 -64
  192. package/src/entry/cli/_function/read-docs.ts +0 -128
  193. package/src/entry/cli/_function/read-home.ts +0 -32
  194. package/src/entry/cli/_function/to-crawling-app.ts +0 -42
  195. package/src/entry/cli/cli.test.ts +0 -804
  196. package/src/entry/cli/cli.ts +0 -206
  197. package/src/env.d.ts +0 -6
  198. package/src/page/doc/pg-doc.tsx +0 -35
  199. package/src/page/home/pg-home.tsx +0 -40
  200. package/src/store/navigation/create-navigation-stores.test.ts +0 -74
  201. package/src/store/navigation/create-navigation-stores.ts +0 -59
  202. package/src/store/navigation/navigation-state.ts +0 -36
  203. package/src/store/navigation/navigation-storage.ts +0 -9
  204. package/src/store/navigation/to-navigation-scroll-state.ts +0 -42
  205. package/src/style/base.css +0 -28
  206. package/src/style/token.css +0 -188
  207. package/src/type/doc-content.ts +0 -15
  208. package/src/type/doc-data.ts +0 -38
  209. package/src/type/doc-file-data.ts +0 -21
  210. package/src/type/doc-heading.ts +0 -17
  211. package/src/type/doc-outline.ts +0 -16
  212. package/src/type/doc-section.ts +0 -9
  213. package/src/type/doc.ts +0 -20
  214. package/src/type/group-path.ts +0 -7
  215. package/src/type/site-assets.ts +0 -25
  216. package/src/type/site-config.ts +0 -73
  217. package/src/type/vfile-data.d.ts +0 -10
  218. package/src/util/async/to-change-queue.test.ts +0 -58
  219. package/src/util/async/to-change-queue.ts +0 -43
  220. package/src/util/dom/find-hash-target.ts +0 -18
  221. package/src/util/dom/reveal-hash-target.ts +0 -15
  222. package/src/util/error/to-error-message.ts +0 -10
  223. package/src/util/file/to-asset-path.ts +0 -26
  224. package/src/util/font/to-font-css.test.ts +0 -41
  225. package/src/util/font/to-font-css.ts +0 -28
  226. package/src/util/mermaid/render-flow.js +0 -321
@@ -0,0 +1,4745 @@
1
+ import { m as e } from "./chunk-DVNvSFoz.js";
2
+ import { n as t } from "./chunk-BYzrzvCI.js";
3
+ import "./chunk-MFVRUoO0.js";
4
+ import "./chunk-K7Myuj2-.js";
5
+ import "./chunk-Bok8z-Yo.js";
6
+ import "./chunk-KuPYb48V.js";
7
+ import "./chunk-_a9EZE1v.js";
8
+ import "./chunk-DORnIAsy.js";
9
+ import "./chunk-CLgRAtOz.js";
10
+ import "./chunk-DU69_VcF.js";
11
+ import "./chunk-DpuxlyL_.js";
12
+ import { r as n } from "./chunk-BLeiQSWo.js";
13
+ import { t as r } from "./chunk-C_YGy4Fn.js";
14
+ //#region node_modules/.pnpm/mermaid@12.2.0/node_modules/mermaid/dist/chunks/mermaid.core/swimlanes-B3ENRKFQ.mjs
15
+ function i(e, { measure: t }) {
16
+ let n = e.config?.swimlane?.lineHops;
17
+ if (n === !1) return;
18
+ let i = n === "gap" ? "gap" : "arc", a = e.edges.filter((e) => Array.isArray(e.points) && e.points.length >= 2).map((e) => ({
19
+ id: e.id,
20
+ points: e.points,
21
+ curve: e.curve,
22
+ arrowTypeStart: e.arrowTypeStart,
23
+ arrowTypeEnd: e.arrowTypeEnd
24
+ }));
25
+ r(t.groups.edgePaths, a, {
26
+ enabled: !0,
27
+ jumpRadius: 6,
28
+ jumpStyle: i
29
+ });
30
+ }
31
+ t(i, "applySwimlaneLineJumps");
32
+ var a = "__swimlane_default__", o = 21, s = 20;
33
+ function c(e) {
34
+ return Math.max(e.padding ?? s, s);
35
+ }
36
+ t(c, "topLaneHorizontalPadding");
37
+ function l(e) {
38
+ let { x: t, y: n, width: r, height: i } = e, a = e.swimlaneContentTop;
39
+ if (typeof t != "number" || typeof n != "number" || typeof r != "number" || typeof i != "number" || typeof a != "number" || !Number.isFinite(t) || !Number.isFinite(n) || !Number.isFinite(r) || !Number.isFinite(i) || !Number.isFinite(a) || r <= 0 || i <= 0) {
40
+ delete e.groupTitleRect;
41
+ return;
42
+ }
43
+ let s = n - i / 2, c = Math.min(a, n + i / 2), l = s + Math.min(o, Math.max(0, c - s));
44
+ l <= s ? delete e.groupTitleRect : e.groupTitleRect = {
45
+ left: t - r / 2,
46
+ right: t + r / 2,
47
+ top: s,
48
+ bottom: l
49
+ };
50
+ }
51
+ t(l, "assignTopLaneTitleRect");
52
+ function u(e) {
53
+ let t = e.direction, n = e.nodes ??= [];
54
+ for (let n of e.nodes ?? []) n.isGroup && !n.parentId && (n.shape = "swimlane", t && (n.direction = t));
55
+ let r = n.filter((e) => !e.isGroup && !e.parentId);
56
+ if (r.length === 0) return;
57
+ let i = n.find((e) => e.id === a);
58
+ i ? i.isGroup && (i.shape = "swimlane", t && (i.direction = t)) : (i = {
59
+ id: a,
60
+ label: "",
61
+ isGroup: !0,
62
+ shape: "swimlane",
63
+ padding: 20,
64
+ look: e.config?.look,
65
+ colorIndex: n.reduce((e, t) => Math.max(e, t.colorIndex ?? -1), -1) + 1,
66
+ ...t ? { direction: t } : {}
67
+ }, n.push(i));
68
+ for (let e of r) e.parentId = a;
69
+ }
70
+ t(u, "prepareLayoutForSwimlanes");
71
+ function d(e) {
72
+ let t = /* @__PURE__ */ new Map();
73
+ for (let n of e.nodes ?? []) t.set(n.id, n);
74
+ let n = [];
75
+ for (let t of e.edges ?? []) {
76
+ let e = typeof t.start == "string" ? t.start : void 0, r = typeof t.end == "string" ? t.end : void 0;
77
+ e && r && (t.labelNodeId || n.push({
78
+ id: t.id,
79
+ src: e,
80
+ dst: r,
81
+ ref: t
82
+ }));
83
+ }
84
+ let r = e.nodes ?? [], i = r.filter((e) => e.isGroup), a = r.filter((e) => !e.isGroup);
85
+ return {
86
+ nodes: [...[...i].reverse(), ...a].map((e) => e.id),
87
+ edges: n,
88
+ layout: e,
89
+ nodeById: t
90
+ };
91
+ }
92
+ t(d, "toGraphView");
93
+ function f(e, t, n, r) {
94
+ let { layout: i } = e, a = e.nodeById, o = r?.layerGap ?? 100, s = r?.nodeGap ?? 40, u = 0;
95
+ for (let e of t.layers) {
96
+ let t = 0;
97
+ for (let r of e) {
98
+ let e = a.get(r);
99
+ if (!e) {
100
+ t++;
101
+ continue;
102
+ }
103
+ e.layer = u, e.order = t;
104
+ let i = n.x[r] ?? t * s, c = n.y[r] ?? u * o;
105
+ e.x = i, e.y = c, t++;
106
+ }
107
+ u++;
108
+ }
109
+ let d = i.nodes ?? [], f = /* @__PURE__ */ new Map(), p = [];
110
+ for (let e of d) {
111
+ if (!e?.isGroup) continue;
112
+ e.parentId || p.push(e);
113
+ let t = d.filter((t) => t.parentId === e.id), r = Infinity, i = -Infinity, a = Infinity, o = -Infinity;
114
+ for (let e of t) {
115
+ let t = e.x ?? n.x[e.id], s = e.y ?? n.y[e.id], c = e.width ?? 0, l = e.height ?? 0;
116
+ t != null && s != null && (r = Math.min(r, t - c / 2), i = Math.max(i, t + c / 2), a = Math.min(a, s - l / 2), o = Math.max(o, s + l / 2));
117
+ }
118
+ if (r === Infinity || a === Infinity) e.x = e.x ?? 0, e.y = e.y ?? 0, e.width = e.width ?? 0, e.height = e.height ?? 0;
119
+ else {
120
+ let t = e.padding ?? 20, n = e.parentId ? t : 2 * c(e), s = t, l = Math.max(0, i - r) + n, u = Math.max(0, o - a) + s, d = (r + i) / 2, p = (a + o) / 2;
121
+ e.x = d, e.y = p, e.width = l, e.height = u, f.set(e.id, {
122
+ minX: r,
123
+ maxX: i,
124
+ minY: a,
125
+ maxY: o
126
+ });
127
+ }
128
+ }
129
+ if (p.length > 0 && f.size > 0) {
130
+ let e = Infinity, t = -Infinity, n = 0;
131
+ for (let r of p) {
132
+ let i = r.padding ?? 20;
133
+ i > n && (n = i);
134
+ let a = f.get(r.id);
135
+ a && (e = Math.min(e, a.minY), t = Math.max(t, a.maxY));
136
+ }
137
+ if (e !== Infinity && t !== -Infinity) {
138
+ let r = Math.max(0, t - e) + 2 * Math.max(n, 36), i = (e + t) / 2;
139
+ for (let t of p) t.y = i, t.height = r, t.swimlaneContentTop = e;
140
+ let a = [...p].sort((e, t) => (e.x ?? 0) - (t.x ?? 0)), o = [], s = [], u = [];
141
+ for (let e of a) {
142
+ let t = f.get(e.id);
143
+ if (!t) continue;
144
+ let n = Math.max(0, t.maxX - t.minX) + 2 * c(e), r = (t.minX + t.maxX) / 2;
145
+ o.push(e.id), s.push(r), u.push(n);
146
+ }
147
+ let d = o.length;
148
+ if (d > 0) {
149
+ let e = /* @__PURE__ */ new Map();
150
+ if (d === 1) e.set(o[0], u[0]);
151
+ else {
152
+ let t = [];
153
+ for (let e = 0; e < d - 1; e++) t.push(s[e + 1] - s[e]);
154
+ let n = Array(d);
155
+ n[0] = 0;
156
+ for (let e = 0; e < d - 1; e++) n[e + 1] = 2 * t[e] - n[e];
157
+ let r = 0, i = Infinity;
158
+ for (let e = 0; e < d; e++) {
159
+ let t = u[e];
160
+ e % 2 == 0 ? r = Math.max(r, t - n[e]) : i = Math.min(i, n[e] - t);
161
+ }
162
+ let a = r;
163
+ a = r <= i ? (r + i) / 2 : r;
164
+ for (let t = 0; t < d; t++) {
165
+ let r = n[t] + (t % 2 == 0 ? a : -a), i = Math.max(u[t], r);
166
+ e.set(o[t], i);
167
+ }
168
+ }
169
+ for (let t of p) {
170
+ let n = e.get(t.id);
171
+ n != null && (t.width = n), l(t);
172
+ }
173
+ }
174
+ }
175
+ }
176
+ }
177
+ t(f, "writeBackToLayoutData");
178
+ var p = "[EdgeLabelNodes]";
179
+ function m(t) {
180
+ let n = [], r = [], i = /* @__PURE__ */ new Map();
181
+ for (let e of t.nodes) i.set(e.id, e);
182
+ for (let a of t.edges) {
183
+ if (!a.label || a.label.length === 0 || a.isLayoutOnly || a.labelNodeId) continue;
184
+ let t = a.start ? i.get(a.start) : void 0, o = a.end ? i.get(a.end) : void 0;
185
+ if (!t || !o) {
186
+ e.warn(p, `Edge ${a.id} has missing source or target node`);
187
+ continue;
188
+ }
189
+ let s = `edge-label-${a.start}-${a.end}-${a.id}`, c = t.parentId === o.parentId ? t.parentId : o.parentId, l = {
190
+ id: s,
191
+ label: a.label,
192
+ edgeStart: a.start ?? "",
193
+ edgeEnd: a.end ?? "",
194
+ shape: "labelRect",
195
+ width: 0,
196
+ height: 0,
197
+ isEdgeLabel: !0,
198
+ isDummy: !0,
199
+ parentId: c,
200
+ isGroup: !1,
201
+ labelStyle: Array.isArray(a.labelStyle) ? a.labelStyle[0] : a.labelStyle ?? "",
202
+ ...t.dir ? { dir: t.dir } : {}
203
+ };
204
+ n.push(l), a.labelNodeId = s, a.label = void 0, a.text = void 0;
205
+ let u = {
206
+ id: `${a.id}-to-label`,
207
+ start: a.start,
208
+ end: s,
209
+ type: "normal",
210
+ isLayoutOnly: !0
211
+ }, d = {
212
+ id: `${a.id}-from-label`,
213
+ start: s,
214
+ end: a.end,
215
+ type: "normal",
216
+ isLayoutOnly: !0
217
+ };
218
+ r.push(u, d);
219
+ }
220
+ let a = [...t.nodes, ...n], o = [...t.edges, ...r];
221
+ return {
222
+ ...t,
223
+ nodes: a,
224
+ edges: o
225
+ };
226
+ }
227
+ t(m, "createEdgeLabelNodes");
228
+ var h = .001;
229
+ function g(e) {
230
+ let t = e.x ?? 0, n = e.y ?? 0, r = e.width ?? 0, i = e.height ?? 0;
231
+ return r > 0 && i > 0 ? {
232
+ cx: t,
233
+ cy: n,
234
+ rect: P(t, n, r, i)
235
+ } : void 0;
236
+ }
237
+ t(g, "measuredNodeRect");
238
+ function _(e) {
239
+ if (e.isGroup) return;
240
+ let t = g(e);
241
+ if (t) return {
242
+ id: String(e.id ?? ""),
243
+ cx: t.cx,
244
+ cy: t.cy,
245
+ rect: t.rect
246
+ };
247
+ }
248
+ t(_, "nodeBoundsInfoFor");
249
+ function v(e, t, n = h) {
250
+ return Math.abs(e.x - t.x) < n && Math.abs(e.y - t.y) < n;
251
+ }
252
+ t(v, "samePoint");
253
+ function y(e, t, n = h) {
254
+ return Math.abs(e.x - t.x) < n;
255
+ }
256
+ t(y, "sameX");
257
+ function b(e, t, n = h) {
258
+ return Math.abs(e.y - t.y) < n;
259
+ }
260
+ t(b, "sameY");
261
+ function x(e, t, n = h) {
262
+ return b(e, t, n) && Math.abs(e.x - t.x) > n;
263
+ }
264
+ t(x, "isHorizontalSegment");
265
+ function S(e, t, n = h) {
266
+ return y(e, t, n) && Math.abs(e.y - t.y) > n;
267
+ }
268
+ t(S, "isVerticalSegment");
269
+ function C(e, t, n, r) {
270
+ return Math.max(0, Math.min(Math.max(e, t), Math.max(n, r)) - Math.max(Math.min(e, t), Math.min(n, r)));
271
+ }
272
+ t(C, "overlapLength");
273
+ function w(e, t, n = h) {
274
+ return e.horizontal && t.horizontal && b(e.a, t.a, n) ? C(e.a.x, e.b.x, t.a.x, t.b.x) : e.vertical && t.vertical && y(e.a, t.a, n) ? C(e.a.y, e.b.y, t.a.y, t.b.y) : 0;
275
+ }
276
+ t(w, "sameAxisSegmentOverlapLength");
277
+ function T(e, t = h) {
278
+ let n = [];
279
+ for (let r = 0; r < e.length - 1; r++) {
280
+ let i = e[r], a = e[r + 1], o = x(i, a, t), s = S(i, a, t);
281
+ (o || s) && n.push({
282
+ index: r,
283
+ a: i,
284
+ b: a,
285
+ horizontal: o,
286
+ vertical: s
287
+ });
288
+ }
289
+ return n;
290
+ }
291
+ t(T, "orthogonalSegmentsForPoints");
292
+ function E(e, t = h) {
293
+ let n = T(e, t), r = 0;
294
+ for (let e = 1; e < n.length; e++) n[e - 1].horizontal !== n[e].horizontal && r++;
295
+ return r;
296
+ }
297
+ t(E, "countOrthogonalBends");
298
+ function D(e, t = h) {
299
+ let n = [];
300
+ for (let r of e) {
301
+ let e = n.length > 0 ? n[n.length - 1] : void 0;
302
+ (!e || !v(e, r, t)) && n.push({
303
+ x: r.x,
304
+ y: r.y
305
+ });
306
+ }
307
+ return n;
308
+ }
309
+ t(D, "dedupeConsecutivePoints");
310
+ function O(e, t = h) {
311
+ if (!e || e.length !== 4) return;
312
+ let [n, r, i, a] = e;
313
+ return x(n, r, t) && S(r, i, t) && x(i, a, t) ? {
314
+ kind: "HVH",
315
+ p0: n,
316
+ p1: r,
317
+ p2: i,
318
+ p3: a
319
+ } : S(n, r, t) && x(r, i, t) && S(i, a, t) ? {
320
+ kind: "VHV",
321
+ p0: n,
322
+ p1: r,
323
+ p2: i,
324
+ p3: a
325
+ } : void 0;
326
+ }
327
+ t(O, "classifyThreeSegmentRoute");
328
+ function k(e, t, n, r = 0) {
329
+ let i = Math.min(e.x, t.x), a = Math.max(e.x, t.x), o = Math.min(e.y, t.y), s = Math.max(e.y, t.y);
330
+ return a > n.left - r && i < n.right + r && s > n.top - r && o < n.bottom + r;
331
+ }
332
+ t(k, "segmentBoundsOverlapRect");
333
+ function A(e, t, n = 0) {
334
+ return e.x > t.left + n && e.x < t.right - n && e.y > t.top + n && e.y < t.bottom - n;
335
+ }
336
+ t(A, "pointInsideRect");
337
+ function j(e, t) {
338
+ return e.left <= t.left && e.right >= t.right && e.top <= t.top && e.bottom >= t.bottom;
339
+ }
340
+ t(j, "rectContainsRect");
341
+ function M(e, t) {
342
+ return e.left < t.right && e.right > t.left && e.top < t.bottom && e.bottom > t.top;
343
+ }
344
+ t(M, "rectsOverlap");
345
+ function N(e, t) {
346
+ return {
347
+ left: e.left - t,
348
+ right: e.right + t,
349
+ top: e.top - t,
350
+ bottom: e.bottom + t
351
+ };
352
+ }
353
+ t(N, "inflateRect");
354
+ function P(e, t, n, r) {
355
+ return {
356
+ left: e - n / 2,
357
+ right: e + n / 2,
358
+ top: t - r / 2,
359
+ bottom: t + r / 2
360
+ };
361
+ }
362
+ t(P, "rectFromCenterSize");
363
+ function F(e) {
364
+ return g(e)?.rect;
365
+ }
366
+ t(F, "rectOfNodeBounds");
367
+ function I(e, t) {
368
+ switch (t) {
369
+ case "top": return {
370
+ x: e.cx,
371
+ y: e.rect.top
372
+ };
373
+ case "bottom": return {
374
+ x: e.cx,
375
+ y: e.rect.bottom
376
+ };
377
+ case "left": return {
378
+ x: e.rect.left,
379
+ y: e.cy
380
+ };
381
+ case "right": return {
382
+ x: e.rect.right,
383
+ y: e.cy
384
+ };
385
+ }
386
+ }
387
+ t(I, "portForRectSide");
388
+ function ee(e, t, n, r, i, a = h) {
389
+ let o = t === "left" || t === "right", s = r === "left" || r === "right";
390
+ if (o && s) {
391
+ if (t === "right" && r === "left" && e.x < n.x || t === "left" && r === "right" && e.x > n.x) {
392
+ if (b(e, n, a)) return [e, n];
393
+ let t = (e.x + n.x) / 2;
394
+ return [
395
+ e,
396
+ {
397
+ x: t,
398
+ y: e.y
399
+ },
400
+ {
401
+ x: t,
402
+ y: n.y
403
+ },
404
+ n
405
+ ];
406
+ }
407
+ if (t === r) {
408
+ if (b(e, n, a)) return;
409
+ let r = t === "left" ? Math.min(e.x, n.x) - i : Math.max(e.x, n.x) + i;
410
+ return [
411
+ e,
412
+ {
413
+ x: r,
414
+ y: e.y
415
+ },
416
+ {
417
+ x: r,
418
+ y: n.y
419
+ },
420
+ n
421
+ ];
422
+ }
423
+ return;
424
+ }
425
+ if (!o && !s) {
426
+ if (t === r) {
427
+ if (y(e, n, a)) return;
428
+ let r = t === "top" ? Math.min(e.y, n.y) - i : Math.max(e.y, n.y) + i;
429
+ return [
430
+ e,
431
+ {
432
+ x: e.x,
433
+ y: r
434
+ },
435
+ {
436
+ x: n.x,
437
+ y: r
438
+ },
439
+ n
440
+ ];
441
+ }
442
+ if (!(t === "bottom" && r === "top" && e.y < n.y || t === "top" && r === "bottom" && e.y > n.y)) return;
443
+ if (y(e, n, a)) return [e, n];
444
+ let o = (e.y + n.y) / 2;
445
+ return [
446
+ e,
447
+ {
448
+ x: e.x,
449
+ y: o
450
+ },
451
+ {
452
+ x: n.x,
453
+ y: o
454
+ },
455
+ n
456
+ ];
457
+ }
458
+ if (o && !s) {
459
+ let i = t === "right" && n.x > e.x || t === "left" && n.x < e.x, a = r === "top" && e.y < n.y || r === "bottom" && e.y > n.y;
460
+ return i && a ? [
461
+ e,
462
+ {
463
+ x: n.x,
464
+ y: e.y
465
+ },
466
+ n
467
+ ] : void 0;
468
+ }
469
+ let c = t === "bottom" && n.y > e.y || t === "top" && n.y < e.y, l = r === "left" && e.x < n.x || r === "right" && e.x > n.x;
470
+ return c && l ? [
471
+ e,
472
+ {
473
+ x: e.x,
474
+ y: n.y
475
+ },
476
+ n
477
+ ] : void 0;
478
+ }
479
+ t(ee, "buildOrthogonalPortPath");
480
+ function L(e, t, n, r) {
481
+ return t === "left" || t === "right" ? [
482
+ e,
483
+ {
484
+ x: r,
485
+ y: e.y
486
+ },
487
+ {
488
+ x: r,
489
+ y: n.y
490
+ },
491
+ n
492
+ ] : [
493
+ e,
494
+ {
495
+ x: e.x,
496
+ y: r
497
+ },
498
+ {
499
+ x: n.x,
500
+ y: r
501
+ },
502
+ n
503
+ ];
504
+ }
505
+ t(L, "buildSameSideTrackPath");
506
+ function R(e) {
507
+ let t = /* @__PURE__ */ new Map(), n = [];
508
+ for (let r of e) {
509
+ if (r.isEdgeLabel) continue;
510
+ let e = _(r);
511
+ e && (t.set(e.id, e), n.push({
512
+ id: e.id,
513
+ rect: e.rect
514
+ }));
515
+ }
516
+ return {
517
+ nodeInfoById: t,
518
+ realNodeRects: n
519
+ };
520
+ }
521
+ t(R, "collectRealNodeBounds");
522
+ function z(e) {
523
+ let t = [], n = [];
524
+ for (let r of e) {
525
+ let e = _(r);
526
+ if (!e) continue;
527
+ let i = {
528
+ id: e.id,
529
+ rect: e.rect
530
+ };
531
+ r.isEdgeLabel ? n.push(i) : t.push(i);
532
+ }
533
+ return {
534
+ realNodeRects: t,
535
+ labelNodeRects: n
536
+ };
537
+ }
538
+ t(z, "collectNodeRectEntries");
539
+ function te(e, { includeEdgeLabels: t = !0 } = {}) {
540
+ let n = [];
541
+ for (let r of e) {
542
+ if (r.isGroup || !t && r.isEdgeLabel) continue;
543
+ let e = r.x ?? 0, i = r.y ?? 0, a = r.width ?? 0, o = r.height ?? 0;
544
+ n.push({
545
+ nodeId: r.id,
546
+ ...P(e, i, a, o)
547
+ });
548
+ }
549
+ return n;
550
+ }
551
+ t(te, "collectLayoutNodeRects");
552
+ function ne(e, t, n = h) {
553
+ let r = e.start, i = e.end;
554
+ if (!r || !i) return;
555
+ let a = t.get(r), o = t.get(i);
556
+ if (a && o) return {
557
+ srcId: r,
558
+ dstId: i,
559
+ srcInfo: a,
560
+ dstInfo: o,
561
+ collinearX: Math.abs(a.cx - o.cx) < n,
562
+ collinearY: Math.abs(a.cy - o.cy) < n
563
+ };
564
+ }
565
+ t(ne, "getNodePairGeometry");
566
+ function B(e, t, n, r = [], i = 0) {
567
+ for (let a of n) if (!r.includes(a.id) && k(e, t, a.rect, -i)) return !0;
568
+ return !1;
569
+ }
570
+ t(B, "segmentHitsAnyRect");
571
+ function re(e, t, n, r, i = h, a = 1e-6) {
572
+ let o = b(e, t, i), s = y(e, t, i), c = b(n, r, i), l = y(n, r, i);
573
+ if (o && c || s && l || !(o || s) || !(c || l)) return !1;
574
+ let u = o ? {
575
+ a: e,
576
+ b: t
577
+ } : {
578
+ a: n,
579
+ b: r
580
+ }, d = s ? {
581
+ a: e,
582
+ b: t
583
+ } : {
584
+ a: n,
585
+ b: r
586
+ }, f = u.a.y, p = Math.min(u.a.x, u.b.x), m = Math.max(u.a.x, u.b.x), g = d.a.x, _ = Math.min(d.a.y, d.b.y), v = Math.max(d.a.y, d.b.y);
587
+ if (g < p || g > m || f < _ || f > v) return !1;
588
+ let x = Math.abs(g - u.a.x) < a && Math.abs(f - u.a.y) < a || Math.abs(g - u.b.x) < a && Math.abs(f - u.b.y) < a, S = Math.abs(g - d.a.x) < a && Math.abs(f - d.a.y) < a || Math.abs(g - d.b.x) < a && Math.abs(f - d.b.y) < a;
589
+ return !(x && S);
590
+ }
591
+ t(re, "orthogonalSegmentsCross");
592
+ function ie(e, t, n, r, i = h) {
593
+ let a = b(e, t, i), o = y(e, t, i), s = b(n, r, i), c = y(n, r, i);
594
+ return o && c && y(e, n, i) ? C(e.y, t.y, n.y, r.y) > i : a && s && b(e, n, i) ? C(e.x, t.x, n.x, r.x) > i : !1;
595
+ }
596
+ t(ie, "sameAxisSegmentsOverlap");
597
+ function ae(e, t, n, r, { epsilon: i = h, skipDegenerateOther: a = !1 } = {}) {
598
+ for (let o of n) {
599
+ if (o === r || o.isLayoutOnly) continue;
600
+ let n = o.points;
601
+ if (!(!n || n.length < 2)) for (let r = 0; r < n.length - 1; r++) {
602
+ let o = n[r], s = n[r + 1];
603
+ if (!(a && v(o, s, i)) && (re(e, t, o, s, i) || ie(e, t, o, s, i))) return !0;
604
+ }
605
+ }
606
+ return !1;
607
+ }
608
+ t(ae, "segmentConflictsWithAnyEdge");
609
+ function V(e, t, n, r, i = h) {
610
+ let a = b(e, t, i), o = y(e, t, i), s = b(n, r, i), c = y(n, r, i);
611
+ if (!(a && c || o && s)) return !1;
612
+ let l = a ? {
613
+ a: e,
614
+ b: t
615
+ } : {
616
+ a: n,
617
+ b: r
618
+ }, u = a ? {
619
+ a: n,
620
+ b: r
621
+ } : {
622
+ a: e,
623
+ b: t
624
+ }, d = l.a.y, f = Math.min(l.a.x, l.b.x), p = Math.max(l.a.x, l.b.x), m = u.a.x, g = Math.min(u.a.y, u.b.y), _ = Math.max(u.a.y, u.b.y);
625
+ return m > f + i && m < p - i && d > g + i && d < _ - i;
626
+ }
627
+ t(V, "orthogonalSegmentsStrictlyCross");
628
+ function oe(e, t, n) {
629
+ let r = Math.min(t, n), i = Math.max(t, n);
630
+ return e > r + h && e < i - h;
631
+ }
632
+ t(oe, "strictlyBetween");
633
+ function H(e, t, n) {
634
+ return y(e, t) && y(t, n) ? oe(t.y, e.y, n.y) : b(e, t) && b(t, n) ? oe(t.x, e.x, n.x) : !1;
635
+ }
636
+ t(H, "isCollinearIntermediate");
637
+ function U(e) {
638
+ let t = !1, n = [];
639
+ for (let r = 0; r < e.length; r++) {
640
+ let i = n[n.length - 1], a = e[r], o = r + 1 < e.length ? e[r + 1] : void 0;
641
+ if (i && o) {
642
+ if (v(i, o)) {
643
+ r++, t = !0;
644
+ continue;
645
+ }
646
+ if (H(i, a, o)) {
647
+ t = !0;
648
+ continue;
649
+ }
650
+ }
651
+ n.push(a);
652
+ }
653
+ return {
654
+ points: n,
655
+ changed: t
656
+ };
657
+ }
658
+ t(U, "simplifyPolylineOnce");
659
+ function W(e) {
660
+ let t = [e[0]];
661
+ for (let n = 1; n < e.length; n++) {
662
+ let r = t[t.length - 1], i = e[n];
663
+ if (!y(r, i) && !b(r, i)) {
664
+ let e = t.length >= 2 ? t[t.length - 2] : void 0, n = e && y(e, r) ? {
665
+ x: r.x,
666
+ y: i.y
667
+ } : {
668
+ x: i.x,
669
+ y: r.y
670
+ };
671
+ t.push(n);
672
+ }
673
+ t.push(i);
674
+ }
675
+ let n = [];
676
+ for (let e of t) {
677
+ let t = n[n.length - 1];
678
+ (!t || !v(t, e)) && n.push(e);
679
+ }
680
+ return n;
681
+ }
682
+ t(W, "orthogonalizePolyline");
683
+ function G(e) {
684
+ if (e.length < 3) return e;
685
+ let t = [...e];
686
+ for (let e = 0; e < 32; e++) {
687
+ let e = U(t);
688
+ if (t = e.points, !e.changed) break;
689
+ }
690
+ return t;
691
+ }
692
+ t(G, "simplifyPolyline");
693
+ var K = .001, se = .5, ce = 4;
694
+ function le(e, t, n) {
695
+ let r = e;
696
+ if (r.isLayoutOnly || !r.points || r.points.length < n) return;
697
+ let i = r.start ? t.get(r.start) : void 0, a = r.end ? t.get(r.end) : void 0;
698
+ return {
699
+ edge: r,
700
+ points: r.points,
701
+ srcRect: i ? F(i) : void 0,
702
+ dstRect: a ? F(a) : void 0
703
+ };
704
+ }
705
+ t(le, "endpointContextFor");
706
+ function ue(e, t, n) {
707
+ if (b(e, t, K)) return {
708
+ x: e.x < n.left ? n.left : n.right,
709
+ y: e.y
710
+ };
711
+ if (y(e, t, K)) {
712
+ let t = e.y < n.top ? n.top : n.bottom;
713
+ return {
714
+ x: e.x,
715
+ y: t
716
+ };
717
+ }
718
+ return {
719
+ x: Math.min(n.right, Math.max(n.left, e.x)),
720
+ y: Math.min(n.bottom, Math.max(n.top, e.y))
721
+ };
722
+ }
723
+ t(ue, "segmentEnterPoint");
724
+ function de(e, t, n) {
725
+ let r = n ? 1 : -1, i = n ? 0 : e.length - 1;
726
+ for (; i >= 0 && i < e.length && A(e[i], t, se);) i += r;
727
+ if (i < 0 || i >= e.length) return e;
728
+ let a = i - r;
729
+ if (a < 0 || a >= e.length) return e;
730
+ let o = ue(e[i], e[a], t);
731
+ return n ? [o, ...e.slice(i)] : [...e.slice(0, i + 1), o];
732
+ }
733
+ t(de, "clipEndpoint");
734
+ function q(e, t) {
735
+ for (let n of e) {
736
+ let e = le(n, t, 2);
737
+ if (!e) continue;
738
+ let r = [...e.points];
739
+ e.srcRect && (r = de(r, e.srcRect, !0)), e.dstRect && (r = de(r, e.dstRect, !1)), r = G(W(r)), r = xe(r, e.srcRect, e.dstRect), e.edge.points = G(W(r));
740
+ }
741
+ }
742
+ t(q, "clipEdgeEndpointsToNodeBoundaries");
743
+ function J(e, t, n, r = !1) {
744
+ if (b(e, t, K)) {
745
+ if (t.y < n.top - K || t.y > n.bottom + K) return t;
746
+ if (r) {
747
+ if (e.x < n.left - K) return {
748
+ x: n.left,
749
+ y: e.y
750
+ };
751
+ if (e.x > n.right + K) return {
752
+ x: n.right,
753
+ y: e.y
754
+ };
755
+ }
756
+ return {
757
+ x: Math.abs(t.x - n.left) <= Math.abs(t.x - n.right) ? n.left : n.right,
758
+ y: e.y
759
+ };
760
+ }
761
+ if (y(e, t, K)) {
762
+ if (t.x < n.left - K || t.x > n.right + K) return t;
763
+ if (r) {
764
+ if (e.y < n.top - K) return {
765
+ x: e.x,
766
+ y: n.top
767
+ };
768
+ if (e.y > n.bottom + K) return {
769
+ x: e.x,
770
+ y: n.bottom
771
+ };
772
+ }
773
+ let i = Math.abs(t.y - n.top) <= Math.abs(t.y - n.bottom);
774
+ return {
775
+ x: e.x,
776
+ y: i ? n.top : n.bottom
777
+ };
778
+ }
779
+ return t;
780
+ }
781
+ t(J, "snapEndpointToBoundary");
782
+ function fe(e, t, n) {
783
+ let r = e[t];
784
+ for (let i = t + n; i >= 0 && i < e.length; i += n) {
785
+ let t = e[i];
786
+ if (!v(t, r, K)) return t;
787
+ }
788
+ return e[t + n];
789
+ }
790
+ t(fe, "firstDistinctAdjacent");
791
+ function pe(e, t) {
792
+ let n = e + ce, r = t - ce;
793
+ return n <= r ? {
794
+ lo: n,
795
+ hi: r
796
+ } : {
797
+ lo: (e + t) / 2,
798
+ hi: (e + t) / 2
799
+ };
800
+ }
801
+ t(pe, "cornerClearanceRange");
802
+ function me(e, t, n) {
803
+ let { lo: r, hi: i } = pe(t, n);
804
+ return Math.min(i, Math.max(r, e));
805
+ }
806
+ t(me, "clampToCornerClearance");
807
+ function he(e) {
808
+ let t = Math.max(...e.map((e) => e.lo)), n = Math.min(...e.map((e) => e.hi));
809
+ if (!(t > n)) return {
810
+ lo: t,
811
+ hi: n
812
+ };
813
+ }
814
+ t(he, "intersectRanges");
815
+ function ge(e, t) {
816
+ return t === "left" || t === "right" ? pe(e.top, e.bottom) : pe(e.left, e.right);
817
+ }
818
+ t(ge, "clearanceRangeForSide");
819
+ function _e(e, t, n) {
820
+ let r = e.y >= n.top - K && e.y <= n.bottom + K, i = e.x >= n.left - K && e.x <= n.right + K;
821
+ if (b(e, t, K) && r) {
822
+ if (Math.abs(e.x - n.left) < K) return "left";
823
+ if (Math.abs(e.x - n.right) < K) return "right";
824
+ }
825
+ if (y(e, t, K) && i) {
826
+ if (Math.abs(e.y - n.top) < K) return "top";
827
+ if (Math.abs(e.y - n.bottom) < K) return "bottom";
828
+ }
829
+ }
830
+ t(_e, "terminalSideForSegment");
831
+ function ve(e) {
832
+ return e === "left" || e === "right";
833
+ }
834
+ t(ve, "isHorizontalSide");
835
+ function ye(e, t, n, r, i) {
836
+ let a = [], o = n ? _e(e, t, n) : void 0, s = r ? _e(t, e, r) : void 0;
837
+ return n && o && ve(o) === i && a.push(ge(n, o)), r && s && ve(s) === i && a.push(ge(r, s)), a.length > 0 ? he(a) : void 0;
838
+ }
839
+ t(ye, "straightClearanceRange");
840
+ function be(e, t, n, r, i) {
841
+ let a = ye(e, t, n, r, i);
842
+ if (!a) return;
843
+ let o = i ? e.y : e.x, s = Math.min(a.hi, Math.max(a.lo, o));
844
+ if (!(Math.abs(s - o) < K)) return i ? [{
845
+ x: e.x,
846
+ y: s
847
+ }, {
848
+ x: t.x,
849
+ y: s
850
+ }] : [{
851
+ x: s,
852
+ y: e.y
853
+ }, {
854
+ x: s,
855
+ y: t.y
856
+ }];
857
+ }
858
+ t(be, "clearStraightEndpointCornerAxis");
859
+ function xe(e, t, n) {
860
+ if (e.length !== 2) return e;
861
+ let [r, i] = e;
862
+ return b(r, i, K) ? be(r, i, t, n, !0) ?? e : y(r, i, K) ? be(r, i, t, n, !1) ?? e : e;
863
+ }
864
+ t(xe, "clearStraightEndpointCornerConnections");
865
+ function Se(e, t, n) {
866
+ return ve(n) ? {
867
+ x: e.x,
868
+ y: me(e.y, t.top, t.bottom)
869
+ } : {
870
+ x: me(e.x, t.left, t.right),
871
+ y: e.y
872
+ };
873
+ }
874
+ t(Se, "cornerClearedEndpoint");
875
+ function Ce(e, t, n, r, i, a) {
876
+ let o = e.map((e) => ({ ...e }));
877
+ for (let s = t; s >= 0 && s < e.length; s += n) {
878
+ let t = e[s];
879
+ if (a && !b(t, r, K) || !a && !y(t, r, K)) break;
880
+ a ? o[s].y = i.y : o[s].x = i.x;
881
+ }
882
+ return o;
883
+ }
884
+ t(Ce, "moveCollinearEndpointRun");
885
+ function we(e, t, n) {
886
+ if (e.length < 2) return e;
887
+ let r = n ? 0 : e.length - 1, i = n ? 1 : -1, a = e[r], o = fe(e, r, i);
888
+ if (!o) return e;
889
+ let s = _e(a, o, t);
890
+ if (!s) return e;
891
+ let c = ve(s), l = Se(a, t, s);
892
+ return v(a, l, K) ? e : Ce(e, r, i, a, l, c);
893
+ }
894
+ t(we, "clearEndpointCornerConnection");
895
+ function Te(e, t, n) {
896
+ let r = Math.min(e.x, t.x) >= n.left - K && Math.max(e.x, t.x) <= n.right + K, i = Math.min(e.y, t.y) >= n.top - K && Math.max(e.y, t.y) <= n.bottom + K;
897
+ if (Math.abs(e.y - n.top) < K && Math.abs(t.y - n.top) < K && r) return "top";
898
+ if (Math.abs(e.y - n.bottom) < K && Math.abs(t.y - n.bottom) < K && r) return "bottom";
899
+ if (Math.abs(e.x - n.left) < K && Math.abs(t.x - n.left) < K && i) return "left";
900
+ if (Math.abs(e.x - n.right) < K && Math.abs(t.x - n.right) < K && i) return "right";
901
+ }
902
+ t(Te, "borderSideForSegment");
903
+ function Ee(e, t, n, r) {
904
+ switch (e) {
905
+ case "top": return y(t, n, K) && n.y < r.top - K;
906
+ case "bottom": return y(t, n, K) && n.y > r.bottom + K;
907
+ case "left": return b(t, n, K) && n.x < r.left - K;
908
+ case "right": return b(t, n, K) && n.x > r.right + K;
909
+ }
910
+ }
911
+ t(Ee, "leavesOutward");
912
+ function De(e, t, n) {
913
+ if (e.length < 3) return e;
914
+ if (n) {
915
+ let n = Te(e[0], e[1], t);
916
+ return n && Ee(n, e[1], e[2], t) ? e.slice(1) : e;
917
+ }
918
+ let r = e.length - 1, i = Te(e[r - 1], e[r], t);
919
+ return i && Ee(i, e[r - 1], e[r - 2], t) ? e.slice(0, r) : e;
920
+ }
921
+ t(De, "collapseOwnBorderStub");
922
+ function Oe(e, t, n) {
923
+ let r = e;
924
+ if (t) {
925
+ let e = fe(r, 0, 1);
926
+ if (e) {
927
+ let n = J(e, r[0], t);
928
+ n !== r[0] && (r = [n, ...r.slice(1)]);
929
+ }
930
+ r = De(r, t, !0);
931
+ }
932
+ if (n) {
933
+ let e = r.length - 1, t = fe(r, e, -1);
934
+ if (t) {
935
+ let i = J(t, r[e], n, !0);
936
+ i !== r[e] && (r = [...r.slice(0, e), i]);
937
+ }
938
+ r = De(r, n, !1);
939
+ }
940
+ let i = xe(r, t, n);
941
+ return i !== r || r.length === 2 ? i : (t && (r = we(r, t, !0)), n && (r = we(r, n, !1)), r);
942
+ }
943
+ t(Oe, "snapAndCollapseEndpoints");
944
+ function ke(e, t) {
945
+ for (let n of e) {
946
+ let e = le(n, t, 2);
947
+ if (!e) continue;
948
+ let r = Oe(D(e.points, K), e.srcRect, e.dstRect);
949
+ if (r.length < 3) {
950
+ e.edge.points = r;
951
+ continue;
952
+ }
953
+ let i = [
954
+ r[0],
955
+ { ...r[0] },
956
+ ...r.slice(1, -1),
957
+ r[r.length - 1],
958
+ { ...r[r.length - 1] }
959
+ ];
960
+ e.edge.points = i;
961
+ }
962
+ }
963
+ t(ke, "prepareEdgeEndpointsForRenderer");
964
+ function Ae(e) {
965
+ return new Map(e.map((e) => [e.id, e]));
966
+ }
967
+ t(Ae, "buildNodeMap");
968
+ function je(e, t) {
969
+ let n = e.parentId, r = null;
970
+ for (; n;) {
971
+ let e = t.get(n);
972
+ if (!e?.isGroup) break;
973
+ r = e.id, n = e.parentId;
974
+ }
975
+ return r;
976
+ }
977
+ t(je, "resolveTopLevelGroupId");
978
+ function Me(e, t) {
979
+ let n = 0, r = e.parentId;
980
+ for (; r;) {
981
+ let e = t.get(r);
982
+ if (!e?.isGroup) break;
983
+ n++, r = e.parentId;
984
+ }
985
+ return n;
986
+ }
987
+ t(Me, "groupDepth");
988
+ function Ne(e) {
989
+ let t = Infinity, n = -Infinity, r = Infinity, i = -Infinity;
990
+ for (let a of e) {
991
+ let e = a.x, o = a.y;
992
+ if (typeof e != "number" || typeof o != "number") continue;
993
+ let s = a.width ?? 0, c = a.height ?? 0;
994
+ t = Math.min(t, e - s / 2), n = Math.max(n, e + s / 2), r = Math.min(r, o - c / 2), i = Math.max(i, o + c / 2);
995
+ }
996
+ return t === Infinity || r === Infinity ? null : {
997
+ minX: t,
998
+ maxX: n,
999
+ minY: r,
1000
+ maxY: i
1001
+ };
1002
+ }
1003
+ t(Ne, "boundsForChildren");
1004
+ function Pe(e, t) {
1005
+ let n = e.padding ?? 20;
1006
+ e.x = (t.minX + t.maxX) / 2, e.y = (t.minY + t.maxY) / 2, e.width = Math.max(0, t.maxX - t.minX) + n, e.height = Math.max(0, t.maxY - t.minY) + n;
1007
+ }
1008
+ t(Pe, "applyGroupBounds");
1009
+ function Fe(e) {
1010
+ let t = Ae(e), n = e.filter((e) => e.isGroup && e.parentId).sort((e, n) => Me(n, t) - Me(e, t));
1011
+ for (let t of n) {
1012
+ let n = Ne(e.filter((e) => e.parentId === t.id));
1013
+ n && Pe(t, n);
1014
+ }
1015
+ }
1016
+ t(Fe, "recomputeNestedGroupBounds");
1017
+ function Ie(e, n) {
1018
+ let r = e.nodes ?? [], i = e.edges ?? [], a = r.filter((e) => !e.isGroup), o = Infinity, s = -Infinity;
1019
+ for (let e of a) {
1020
+ let t = e[n];
1021
+ typeof t == "number" && (o = Math.min(o, t), s = Math.max(s, t));
1022
+ }
1023
+ if (!Number.isFinite(o) || !Number.isFinite(s)) return !1;
1024
+ let c = /* @__PURE__ */ t((e) => o + s - e, "mirror");
1025
+ for (let e of r) {
1026
+ let t = e[n];
1027
+ typeof t == "number" && (e[n] = c(t));
1028
+ let r = e.groupTitleRect;
1029
+ r && (e.groupTitleRect = n === "x" ? {
1030
+ ...r,
1031
+ left: c(r.right),
1032
+ right: c(r.left)
1033
+ } : {
1034
+ ...r,
1035
+ top: c(r.bottom),
1036
+ bottom: c(r.top)
1037
+ });
1038
+ }
1039
+ for (let e of i) for (let t of e.points ?? []) t[n] = c(t[n]);
1040
+ return !0;
1041
+ }
1042
+ t(Ie, "mirrorAxis");
1043
+ function Le(e) {
1044
+ return !(e.nodes ?? []).some((e) => !e.isGroup) || Ie(e, "y");
1045
+ }
1046
+ t(Le, "applyBtDirectionTransform");
1047
+ function Re(e, t = "LR") {
1048
+ let n = e.nodes ?? [], r = e.edges ?? [], i = n.filter((e) => !e.isGroup), a = Infinity, o = Infinity;
1049
+ for (let e of i) {
1050
+ let t = e.x ?? 0, n = e.y ?? 0;
1051
+ t < a && (a = t), n < o && (o = n);
1052
+ }
1053
+ if (!Number.isFinite(a) || !Number.isFinite(o)) return !1;
1054
+ let s = 0, c = 0;
1055
+ for (let e of i) s += e.width ?? 0, c += e.height ?? 0;
1056
+ let l = s / i.length, u = c / i.length, d = u > 0 ? Math.max(1, l / u) : 1;
1057
+ for (let e of i) {
1058
+ let t = e.x ?? 0, n = ((e.y ?? 0) - o) * d + 36, r = t - a;
1059
+ e.x = n, e.y = r;
1060
+ }
1061
+ for (let e of r) if (e.points) for (let t of e.points) {
1062
+ let e = t.x, n = (t.y - o) * d + 36, r = e - a;
1063
+ t.x = n, t.y = r;
1064
+ }
1065
+ Fe(n);
1066
+ let f = n.filter((e) => e.isGroup && !e.parentId);
1067
+ if (f.length === 0) return t === "RL" && Ie(e, "x"), !0;
1068
+ let p = Ae(n), m = /* @__PURE__ */ new Map();
1069
+ for (let e of n) {
1070
+ if (e.isGroup) continue;
1071
+ let t = je(e, p);
1072
+ if (!t) continue;
1073
+ let n = m.get(t) ?? [];
1074
+ n.push(e), m.set(t, n);
1075
+ }
1076
+ let h = 0;
1077
+ for (let e of f) {
1078
+ let t = e.padding ?? 0;
1079
+ t > h && (h = t);
1080
+ }
1081
+ let g = [], _ = Infinity, v = -Infinity;
1082
+ for (let e of f) {
1083
+ let t = Ne(m.get(e.id) ?? []);
1084
+ t && (_ = Math.min(_, t.minX), v = Math.max(v, t.maxX), g.push({
1085
+ lane: e,
1086
+ contentTop: t.minY,
1087
+ contentBottom: t.maxY,
1088
+ centerY: (t.minY + t.maxY) / 2
1089
+ }));
1090
+ }
1091
+ if (_ === Infinity || v === -Infinity) return !0;
1092
+ let y = Math.max(0, v - _) + 2 * Math.max(h, 10), b = 36 + y, x = (_ + v) / 2 - y / 2 - 36, S = x + b / 2, C = Math.max(h, 36);
1093
+ g.sort((e, t) => e.centerY - t.centerY);
1094
+ for (let e = 0; e < g.length; e++) {
1095
+ let t = g[e], n, r;
1096
+ if (n = e === 0 ? t.contentTop - C : (g[e - 1].contentBottom + t.contentTop) / 2, e === g.length - 1) r = t.contentBottom + C;
1097
+ else {
1098
+ let n = g[e + 1];
1099
+ r = (t.contentBottom + n.contentTop) / 2;
1100
+ }
1101
+ let i = Math.max(0, r - n), a = (n + r) / 2;
1102
+ t.lane.x = S, t.lane.y = a, t.lane.width = b, t.lane.height = i, t.lane.swimlaneContentTop = t.contentTop, t.lane.groupTitleRect = {
1103
+ left: x,
1104
+ right: x + 36,
1105
+ top: n,
1106
+ bottom: r
1107
+ };
1108
+ }
1109
+ return t === "RL" && Ie(e, "x"), !0;
1110
+ }
1111
+ t(Re, "applyLrDirectionTransform");
1112
+ var ze = 1e-6, Be = 8, Ve = [
1113
+ 0,
1114
+ Be,
1115
+ -Be,
1116
+ 2 * Be,
1117
+ -2 * Be
1118
+ ];
1119
+ function He(e, t) {
1120
+ let { nodeInfoById: n, realNodeRects: r } = R(t);
1121
+ for (let t of e) {
1122
+ if (t.isLayoutOnly) continue;
1123
+ let i = t.points;
1124
+ if (!i || i.length < 4) continue;
1125
+ let a = O(D(i, ze), ze);
1126
+ if (!a) continue;
1127
+ let { p3: o } = a, s = a.kind === "HVH", c = ne(t, n, ze);
1128
+ if (!c) continue;
1129
+ let { srcId: l, dstId: u, srcInfo: d, dstInfo: f, collinearX: p, collinearY: m } = c;
1130
+ if (p || m) continue;
1131
+ let h, g = d.rect;
1132
+ for (let n of Ve) {
1133
+ let i, a, c;
1134
+ if (s) {
1135
+ let e = f.cy > d.cy ? g.bottom : g.top, t = d.cx + n;
1136
+ if (t <= g.left + ze || t >= g.right - ze) continue;
1137
+ i = {
1138
+ x: t,
1139
+ y: e
1140
+ }, a = {
1141
+ x: t,
1142
+ y: o.y
1143
+ }, c = {
1144
+ x: o.x,
1145
+ y: o.y
1146
+ };
1147
+ } else {
1148
+ let e = f.cx > d.cx ? g.right : g.left, t = d.cy + n;
1149
+ if (t <= g.top + ze || t >= g.bottom - ze) continue;
1150
+ i = {
1151
+ x: e,
1152
+ y: t
1153
+ }, a = {
1154
+ x: o.x,
1155
+ y: t
1156
+ }, c = {
1157
+ x: o.x,
1158
+ y: o.y
1159
+ };
1160
+ }
1161
+ let p = v(i, a, ze), m = v(a, c, ze);
1162
+ if (p && m || !p && B(i, a, r, [l], 1) || !m && B(a, c, r, [u], 1)) continue;
1163
+ let _ = !p && ae(i, a, e, t, {
1164
+ epsilon: ze,
1165
+ skipDegenerateOther: !0
1166
+ }), y = !m && ae(a, c, e, t, {
1167
+ epsilon: ze,
1168
+ skipDegenerateOther: !0
1169
+ });
1170
+ if (!(_ || y)) {
1171
+ h = p ? [a, c] : m ? [i, a] : [
1172
+ i,
1173
+ a,
1174
+ c
1175
+ ];
1176
+ break;
1177
+ }
1178
+ }
1179
+ h && (t.points = h);
1180
+ }
1181
+ }
1182
+ t(He, "portSwapToLShape");
1183
+ function Ue(e, n) {
1184
+ let r = .001, { realNodeRects: i, labelNodeRects: a } = z(n.values());
1185
+ for (let o of e) {
1186
+ if (o.isLayoutOnly) continue;
1187
+ let s = o.points;
1188
+ if (!s || s.length < 4) continue;
1189
+ let c = D(s, r);
1190
+ if (c.length < 4) continue;
1191
+ let l = c.length - 1, u = c[l], d = c[l - 1], f = c[l - 2], p = u.x - d.x, m = u.y - d.y, h = Math.hypot(p, m);
1192
+ if (h >= 10 || h < r) continue;
1193
+ let g = d.x - f.x, _ = d.y - f.y;
1194
+ if (Math.hypot(g, _) < r) continue;
1195
+ let v = x(d, u, r), C = S(d, u, r), w = x(f, d, r), T = S(f, d, r);
1196
+ if (!(v && T || C && w)) continue;
1197
+ let E = o.end, O = o.start, k = E ? n.get(E) : void 0;
1198
+ if (!k) continue;
1199
+ let j = k.x ?? 0, M = k.y ?? 0, N = F(k);
1200
+ if (!N) continue;
1201
+ let P, I;
1202
+ if (T) {
1203
+ let e = _ < 0;
1204
+ P = {
1205
+ x: j,
1206
+ y: f.y
1207
+ }, I = {
1208
+ x: j,
1209
+ y: e ? N.bottom : N.top
1210
+ };
1211
+ } else {
1212
+ let e = g > 0;
1213
+ P = {
1214
+ x: f.x,
1215
+ y: M
1216
+ }, I = {
1217
+ x: e ? N.right : N.left,
1218
+ y: M
1219
+ };
1220
+ }
1221
+ if (B(P, I, i, E ? [E] : [], -2) || B(P, I, a, [], -2)) continue;
1222
+ if (O) {
1223
+ let e = n.get(O), t = e ? F(e) : void 0;
1224
+ if (t && A(P, t, 2)) continue;
1225
+ }
1226
+ let ee = /* @__PURE__ */ t((e, t) => `${e.x.toFixed(3)},${e.y.toFixed(3)}|${t.x.toFixed(3)},${t.y.toFixed(3)}`, "ownSegmentKey"), L = /* @__PURE__ */ new Set();
1227
+ for (let e = 0; e < c.length - 1; e++) L.add(ee(c[e], c[e + 1]));
1228
+ let R = /* @__PURE__ */ t((t, n) => {
1229
+ for (let i of e) {
1230
+ if (i === o || i.isLayoutOnly) continue;
1231
+ let e = i.points;
1232
+ if (!(!e || e.length < 2)) for (let i = 0; i < e.length - 1; i++) {
1233
+ let a = e[i], o = e[i + 1];
1234
+ if (!L.has(ee(a, o)) && V(t, n, a, o, r)) return !0;
1235
+ }
1236
+ }
1237
+ return !1;
1238
+ }, "segmentCrossesOtherEdge");
1239
+ if (R(P, I)) continue;
1240
+ if (l - 3 >= 0) {
1241
+ let e = c[l - 3], t = [O, E].filter((e) => !!e);
1242
+ if (B(e, P, i, t, -2) || R(e, P)) continue;
1243
+ }
1244
+ let z = [
1245
+ ...c.slice(0, l - 2),
1246
+ P,
1247
+ I
1248
+ ];
1249
+ o.points = z;
1250
+ let te = o.labelNodeId;
1251
+ if (te) {
1252
+ let e = n.get(te);
1253
+ if (e) {
1254
+ let t = e.width ?? 0, n = e.height ?? 0;
1255
+ if (t > 0 && n > 0) {
1256
+ let i, a, o = -1;
1257
+ for (let e = 0; e < z.length - 1; e++) {
1258
+ let s = z[e], c = z[e + 1], l = Math.hypot(c.x - s.x, c.y - s.y), u = b(s, c, r), d = y(s, c, r);
1259
+ (u && l >= t + 2 || d && l >= n + 2) && l > o && (o = l, i = (s.x + c.x) / 2, a = (s.y + c.y) / 2);
1260
+ }
1261
+ i !== void 0 && a !== void 0 && (e.x = i, e.y = a);
1262
+ }
1263
+ }
1264
+ }
1265
+ }
1266
+ }
1267
+ t(Ue, "collapseShortTerminalStub");
1268
+ var Y = .001, X = 8, We = /* @__PURE__ */ t((e) => typeof e == "string" ? e.toUpperCase() : "", "upperCaseDirection"), Z = T, Ge = /* @__PURE__ */ t((e, t) => y(e, t, Y) || b(e, t, Y), "orthogonallyAligned");
1269
+ function Ke(e, n) {
1270
+ let r = /* @__PURE__ */ t((e, t) => {
1271
+ let n = e.x ?? 0, r = e.y ?? 0, i = t.x - n, a = t.y - r, o = (e.width ?? 0) / 2, s = (e.height ?? 0) / 2;
1272
+ return Math.abs(a) * o > Math.abs(i) * s ? (a < 0 && (s = -s), {
1273
+ x: n + (a === 0 ? 0 : s * i / a),
1274
+ y: r + s
1275
+ }) : (i < 0 && (o = -o), {
1276
+ x: n + o,
1277
+ y: r + (i === 0 ? 0 : o * a / i)
1278
+ });
1279
+ }, "rectIntersect"), i = /* @__PURE__ */ t((e, t) => {
1280
+ let i = D(e.points ?? []);
1281
+ if (i.length < 2) return;
1282
+ let a = t ? e.start : e.end, o = a ? n.get(a) : void 0, s = o ? F(o) : void 0;
1283
+ if (!o || !a || !s) return;
1284
+ let c = t ? i[0] : i[i.length - 1], l = t ? i[1] : i[i.length - 2], u = r(o, c), d = c;
1285
+ if (Ge(l, u) && (d = l), y(u, d, Y)) return {
1286
+ edge: e,
1287
+ edgeId: String(e.id ?? ""),
1288
+ nodeId: a,
1289
+ atStart: t,
1290
+ orientation: "V",
1291
+ coord: u.x,
1292
+ min: Math.min(u.y, d.y),
1293
+ max: Math.max(u.y, d.y),
1294
+ boundary: u,
1295
+ railEnd: d,
1296
+ rect: s
1297
+ };
1298
+ if (b(u, d, Y)) return {
1299
+ edge: e,
1300
+ edgeId: String(e.id ?? ""),
1301
+ nodeId: a,
1302
+ atStart: t,
1303
+ orientation: "H",
1304
+ coord: u.y,
1305
+ min: Math.min(u.x, d.x),
1306
+ max: Math.max(u.x, d.x),
1307
+ boundary: u,
1308
+ railEnd: d,
1309
+ rect: s
1310
+ };
1311
+ }, "terminalLaneFor"), a = /* @__PURE__ */ t((e, t) => Math.max(0, Math.min(e.max, t.max) - Math.max(e.min, t.min)), "projectedOverlapLength"), o = /* @__PURE__ */ t((e, t) => e.nodeId !== t.nodeId || e.orientation !== t.orientation ? !1 : e.orientation === "H" ? (Math.abs(e.boundary.x - e.rect.left) < 1 || Math.abs(e.boundary.x - e.rect.right) < 1) && y(e.boundary, t.boundary, 1) : (Math.abs(e.boundary.y - e.rect.top) < 1 || Math.abs(e.boundary.y - e.rect.bottom) < 1) && b(e.boundary, t.boundary, 1), "sameTerminalFace"), s = /* @__PURE__ */ t((e, t) => e.nodeId !== t.nodeId || e.orientation !== t.orientation ? !1 : a(e, t) >= X && Math.abs(e.coord - t.coord) < .5, "exactTerminalLaneConflict"), c = /* @__PURE__ */ t((e, t) => {
1312
+ if (e.nodeId !== t.nodeId || e.orientation !== t.orientation || e.orientation !== "H" || e.atStart === t.atStart) return !1;
1313
+ let n = a(e, t);
1314
+ if (n < X) return !1;
1315
+ let r = e.rect.bottom - e.rect.top;
1316
+ return n < r || n > 2 * r ? !1 : o(e, t) && Math.abs(e.coord - t.coord) < 16;
1317
+ }, "nearTerminalLaneConflict"), l = /* @__PURE__ */ t((e, n) => {
1318
+ let r = D(e.edge.points ?? []);
1319
+ if (r.length < 2) return;
1320
+ let i = e.orientation === "V" ? {
1321
+ x: e.boundary.x + n,
1322
+ y: e.boundary.y
1323
+ } : {
1324
+ x: e.boundary.x,
1325
+ y: e.boundary.y + n
1326
+ }, a = e.orientation === "V" ? {
1327
+ x: e.railEnd.x + n,
1328
+ y: e.railEnd.y
1329
+ } : {
1330
+ x: e.railEnd.x,
1331
+ y: e.railEnd.y + n
1332
+ };
1333
+ if (!(/* @__PURE__ */ t(() => Math.abs(e.boundary.y - e.rect.top) < 1 || Math.abs(e.boundary.y - e.rect.bottom) < 1 ? b(i, e.boundary, Y) && i.x >= e.rect.left + 1 && i.x <= e.rect.right - 1 : Math.abs(e.boundary.x - e.rect.left) < 1 || Math.abs(e.boundary.x - e.rect.right) < 1 ? y(i, e.boundary, Y) && i.y >= e.rect.top + 1 && i.y <= e.rect.bottom - 1 : !1, "boundaryStaysOnSameFace"))()) return;
1334
+ if (e.atStart) {
1335
+ let t = r.length > 1 && v(r[1], e.railEnd, Y), n = r.slice(t ? 2 : 1), o = n[0];
1336
+ return o && !Ge(o, a) ? void 0 : [
1337
+ i,
1338
+ a,
1339
+ ...n
1340
+ ];
1341
+ }
1342
+ let o = r.length > 1 && v(r[r.length - 2], e.railEnd, Y), s = r.slice(0, o ? -2 : -1), c = s[s.length - 1];
1343
+ if (!c || Ge(c, a)) return [
1344
+ ...s,
1345
+ a,
1346
+ i
1347
+ ];
1348
+ }, "shiftedCandidate"), u = /* @__PURE__ */ t((e) => {
1349
+ let t = e.edge, r = D(t.points ?? []);
1350
+ if (r.length !== 2) return !1;
1351
+ let i = t.start, a = t.end, o = i ? n.get(i) : void 0, s = a ? n.get(a) : void 0;
1352
+ if (!o || !s) return !1;
1353
+ let c = o.x ?? 0, l = o.y ?? 0, u = s.x ?? 0, d = s.y ?? 0, [f, p] = r;
1354
+ return b(f, p, Y) && Math.abs(l - d) < 1 && Math.abs(c - u) > 1 || y(f, p, Y) && Math.abs(c - u) < 1 && Math.abs(l - d) > 1;
1355
+ }, "laneIsStraightCollinearConnector"), d = [
1356
+ -7,
1357
+ 7,
1358
+ -14,
1359
+ 14,
1360
+ -21,
1361
+ 21
1362
+ ];
1363
+ for (let t = 0; t < 8; t++) {
1364
+ let t = e.filter((e) => !e.isLayoutOnly).flatMap((e) => [i(e, !0), i(e, !1)]).filter((e) => !!e), n = !1;
1365
+ for (let e = 0; e < t.length && !n; e++) for (let r = e + 1; r < t.length && !n; r++) {
1366
+ let a = t[e], o = t[r];
1367
+ if (a.edge === o.edge || !(s(a, o) || c(a, o))) continue;
1368
+ let f = !s(a, o), p = [a, o].sort((e, t) => {
1369
+ let n = u(e), r = u(t);
1370
+ return n === r ? Number(!t.atStart) - Number(!e.atStart) : Number(n) - Number(r);
1371
+ });
1372
+ for (let e of p) {
1373
+ for (let r of d) {
1374
+ let a = l(e, r);
1375
+ if (!a) continue;
1376
+ let o = i({
1377
+ ...e.edge,
1378
+ points: a
1379
+ }, e.atStart);
1380
+ if (o && !t.some((t) => t.edge !== e.edge && (s(o, t) || f && c(o, t)))) {
1381
+ e.edge.points = a, n = !0;
1382
+ break;
1383
+ }
1384
+ }
1385
+ if (n) break;
1386
+ }
1387
+ }
1388
+ if (!n) return;
1389
+ }
1390
+ }
1391
+ t(Ke, "separateSharedRenderedTerminalLanes");
1392
+ function qe(e, n) {
1393
+ let { realNodeRects: r, labelNodeRects: i } = z(n.values()), a = /* @__PURE__ */ t((t, n) => {
1394
+ let a = t.start, o = t.end, s = Z(n);
1395
+ if (s.length !== n.length - 1) return !1;
1396
+ let c = [a, o].filter((e) => !!e);
1397
+ for (let e of s) if (B(e.a, e.b, r, c, -2) || B(e.a, e.b, i, [], -2)) return !1;
1398
+ for (let n of e) {
1399
+ if (n === t || n.isLayoutOnly) continue;
1400
+ let e = n.points;
1401
+ if (!(!e || e.length < 2)) {
1402
+ for (let t of s) for (let n of Z(D(e))) if (w(t, n, .5) >= X || V(t.a, t.b, n.a, n.b, Y)) return !1;
1403
+ }
1404
+ }
1405
+ return !0;
1406
+ }, "candidateIsSafe"), o = /* @__PURE__ */ t((e, t) => {
1407
+ if (t + 4 >= e.length) return;
1408
+ let n = e[t], r = e[t + 1], i = e[t + 2], a = e[t + 3], o = e[t + 4], s = x(n, r) && S(r, i) && x(i, a) && S(a, o) && y(n, a, Y) && y(n, o, Y) && y(r, i, Y) && (r.x - n.x) * (a.x - i.x) < 0, c = S(n, r) && x(r, i) && S(i, a) && x(a, o) && b(n, a, Y) && b(n, o, Y) && b(r, i, Y) && (r.y - n.y) * (a.y - i.y) < 0;
1409
+ if (s || c) return D([
1410
+ ...e.slice(0, t + 1),
1411
+ o,
1412
+ ...e.slice(t + 5)
1413
+ ]);
1414
+ if (t + 5 >= e.length) return;
1415
+ let l = e[t + 5], u = S(n, r) && x(r, i) && S(i, a) && x(a, o) && S(o, l) && y(n, o, Y) && y(n, l, Y) && y(i, a, Y) && (i.x - r.x) * (o.x - a.x) < 0, d = x(n, r) && S(r, i) && x(i, a) && S(a, o) && x(o, l) && b(n, o, Y) && b(n, l, Y) && b(i, a, Y) && (i.y - r.y) * (o.y - a.y) < 0;
1416
+ if (u || d) return D([
1417
+ ...e.slice(0, t + 1),
1418
+ l,
1419
+ ...e.slice(t + 6)
1420
+ ]);
1421
+ }, "withoutDogleg");
1422
+ for (let t = 0; t < 8; t++) {
1423
+ let t = !1;
1424
+ for (let n of e) {
1425
+ if (n.isLayoutOnly) continue;
1426
+ let e = D(n.points ?? []);
1427
+ for (let r = 0; r <= e.length - 5; r++) {
1428
+ let i = o(e, r);
1429
+ if (i && a(n, i)) {
1430
+ n.points = i, t = !0;
1431
+ break;
1432
+ }
1433
+ }
1434
+ if (t) break;
1435
+ }
1436
+ if (!t) return;
1437
+ }
1438
+ }
1439
+ t(qe, "collapseRedundantRectangularDoglegs");
1440
+ function Je(e, n) {
1441
+ let { realNodeRects: r, labelNodeRects: i } = z(n.values()), a = e.filter((e) => !e.isLayoutOnly), o = /* @__PURE__ */ t((e, t, n) => D(e === t ? n ?? [] : e.points ?? []), "pointsFor"), s = /* @__PURE__ */ t((e, t) => {
1442
+ let n = 0;
1443
+ for (let r = 0; r < a.length; r++) {
1444
+ let i = Z(o(a[r], e, t));
1445
+ for (let s = r + 1; s < a.length; s++) {
1446
+ let r = Z(o(a[s], e, t));
1447
+ for (let e of i) for (let t of r) V(e.a, e.b, t.a, t.b, Y) && n++;
1448
+ }
1449
+ }
1450
+ return n;
1451
+ }, "strictCrossingCount"), c = /* @__PURE__ */ t((e) => {
1452
+ let t = Z(e);
1453
+ if (t.length !== 3) return;
1454
+ let n = t[1];
1455
+ if (t[0].horizontal !== n.horizontal && t[2].horizontal !== n.horizontal) return {
1456
+ index: n.index,
1457
+ horizontal: n.horizontal,
1458
+ vertical: n.vertical,
1459
+ segment: n
1460
+ };
1461
+ }, "middleRail"), l = /* @__PURE__ */ t((e, t) => {
1462
+ let n = [e.start, e.end].filter((e) => !!e);
1463
+ return r.filter((e) => {
1464
+ if (n.includes(e.id)) return !1;
1465
+ let r = e.rect;
1466
+ return t.horizontal ? C(t.a.x, t.b.x, r.left, r.right) >= X && t.a.y >= r.top - 2 && t.a.y <= r.bottom + 2 : C(t.a.y, t.b.y, r.top, r.bottom) >= X && t.a.x >= r.left - 2 && t.a.x <= r.right + 2;
1467
+ });
1468
+ }, "blockingRectsFor"), u = /* @__PURE__ */ t((e, t, n) => {
1469
+ let r = e.map((e) => ({ ...e }));
1470
+ if (t.horizontal) r[t.index].y = n, r[t.index + 1].y = n;
1471
+ else if (t.vertical) r[t.index].x = n, r[t.index + 1].x = n;
1472
+ else return;
1473
+ let i = G(D(r));
1474
+ return Z(i).length === i.length - 1 ? i : void 0;
1475
+ }, "candidateByMovingRail"), d = /* @__PURE__ */ t((e, t, n) => {
1476
+ let c = [e.start, e.end].filter((e) => !!e), l = Z(t);
1477
+ if (l.length !== t.length - 1) return !1;
1478
+ for (let e of l) if (B(e.a, e.b, r, c, -2) || B(e.a, e.b, i, [], -2)) return !1;
1479
+ for (let t of a) if (t !== e) {
1480
+ for (let e of l) for (let n of Z(o(t))) if (w(e, n, .5) >= X) return !1;
1481
+ }
1482
+ return s(e, t) <= n;
1483
+ }, "candidateIsSafe");
1484
+ for (let e = 0; e < 8; e++) {
1485
+ let e = s(), t = !1;
1486
+ for (let n of a) {
1487
+ let r = o(n), i = c(r);
1488
+ if (!i) continue;
1489
+ let a = l(n, i.segment);
1490
+ if (a.length === 0) continue;
1491
+ let s = i.horizontal ? [Math.min(...a.map((e) => e.rect.top)) - 20, Math.max(...a.map((e) => e.rect.bottom)) + 20] : [Math.min(...a.map((e) => e.rect.left)) - 20, Math.max(...a.map((e) => e.rect.right)) + 20];
1492
+ for (let a of s) {
1493
+ let o = u(r, i.segment, a);
1494
+ if (o && d(n, o, e)) {
1495
+ n.points = o, t = !0;
1496
+ break;
1497
+ }
1498
+ }
1499
+ if (t) break;
1500
+ }
1501
+ if (!t) return;
1502
+ }
1503
+ }
1504
+ t(Je, "liftObstacleHuggingSameSideRails");
1505
+ function Ye(e, n, r) {
1506
+ let i = /* @__PURE__ */ t((e) => {
1507
+ let t = e.groupTitleRect;
1508
+ if (!(!t || typeof t.left != "number" || typeof t.right != "number" || typeof t.top != "number" || typeof t.bottom != "number" || !Number.isFinite(t.left) || !Number.isFinite(t.right) || !Number.isFinite(t.top) || !Number.isFinite(t.bottom) || t.right <= t.left || t.bottom <= t.top)) return {
1509
+ left: t.left,
1510
+ right: t.right,
1511
+ top: t.top,
1512
+ bottom: t.bottom
1513
+ };
1514
+ }, "validTitleRect"), a = /* @__PURE__ */ t((e) => {
1515
+ if (!e.isGroup || e.parentId) return;
1516
+ let t = We(e.direction ?? r);
1517
+ if (t === "LR" || t === "RL" || t === "BT") return;
1518
+ let n = i(e), a = e.y, o = e.height;
1519
+ if (!n || typeof a != "number" || typeof o != "number" || !Number.isFinite(a) || !Number.isFinite(o) || o <= 0) return;
1520
+ let s = n.right - n.left, c = n.bottom - n.top;
1521
+ if (!(c <= 0 || s < c)) return {
1522
+ node: e,
1523
+ rect: n
1524
+ };
1525
+ }, "topLaneTitleFor"), o = /* @__PURE__ */ t((e, t) => {
1526
+ if (!e.horizontal) return !1;
1527
+ let n = e.a.y;
1528
+ return n < t.top - Y || n > t.bottom + Y ? !1 : C(e.a.x, e.b.x, t.left, t.right) >= X;
1529
+ }, "horizontalSegmentIntersectsTitle"), s = [...n.values()].map(a).filter((e) => !!e);
1530
+ if (s.length === 0) return;
1531
+ let c = 0;
1532
+ for (let t of e) {
1533
+ if (t.isLayoutOnly) continue;
1534
+ let e = D(t.points ?? []);
1535
+ for (let t of Z(e)) for (let e of s) o(t, e.rect) && (c = Math.max(c, e.rect.bottom - t.a.y + 4));
1536
+ }
1537
+ if (!(c <= Y)) for (let e of s) {
1538
+ let t = e.node.y, n = e.node.height;
1539
+ typeof t != "number" || typeof n != "number" || !Number.isFinite(t) || !Number.isFinite(n) || n <= 0 || (e.node.y = t - c / 2, e.node.height = n + c, e.node.groupTitleRect = {
1540
+ ...e.rect,
1541
+ top: e.rect.top - c,
1542
+ bottom: e.rect.bottom - c
1543
+ });
1544
+ }
1545
+ }
1546
+ t(Ye, "liftTopLaneTitleBandsAboveRails");
1547
+ function Xe(e, n, r) {
1548
+ let i = /* @__PURE__ */ t((e) => {
1549
+ let t = e.groupTitleRect;
1550
+ if (!(!t || typeof t.left != "number" || typeof t.right != "number" || typeof t.top != "number" || typeof t.bottom != "number" || !Number.isFinite(t.left) || !Number.isFinite(t.right) || !Number.isFinite(t.top) || !Number.isFinite(t.bottom) || t.right <= t.left || t.bottom <= t.top)) return {
1551
+ left: t.left,
1552
+ right: t.right,
1553
+ top: t.top,
1554
+ bottom: t.bottom
1555
+ };
1556
+ }, "validTitleRect"), a = /* @__PURE__ */ t((e) => {
1557
+ if (!e.isGroup || e.parentId || We(e.direction ?? r) !== "LR") return;
1558
+ let t = i(e), n = e.x, a = e.width;
1559
+ if (!t || typeof n != "number" || typeof a != "number" || !Number.isFinite(n) || !Number.isFinite(a) || a <= 0) return;
1560
+ let o = t.right - t.left, s = t.bottom - t.top;
1561
+ if (!(o <= 0 || s < o)) return {
1562
+ node: e,
1563
+ rect: t
1564
+ };
1565
+ }, "leftLaneTitleFor"), o = /* @__PURE__ */ t((e, t) => {
1566
+ if (!e.vertical) return !1;
1567
+ let n = e.a.x;
1568
+ return n < t.left - Y || n > t.right + Y ? !1 : C(e.a.y, e.b.y, t.top, t.bottom) >= X;
1569
+ }, "verticalSegmentIntersectsTitle"), s = /* @__PURE__ */ t((e, t) => {
1570
+ if (!e.horizontal) return !1;
1571
+ let n = e.a.y;
1572
+ return n < t.top - Y || n > t.bottom + Y ? !1 : C(e.a.x, e.b.x, t.left, t.right) >= X;
1573
+ }, "horizontalSegmentIntersectsTitle"), c = [...n.values()].map(a).filter((e) => !!e);
1574
+ if (c.length === 0) return;
1575
+ let l = 0;
1576
+ for (let t of e) {
1577
+ if (t.isLayoutOnly) continue;
1578
+ let e = D(t.points ?? []);
1579
+ for (let t of Z(e)) for (let e of c) if (o(t, e.rect)) l = Math.max(l, e.rect.right - t.a.x + 4);
1580
+ else if (s(t, e.rect)) {
1581
+ let n = Math.min(t.a.x, t.b.x);
1582
+ l = Math.max(l, e.rect.right - n + 4);
1583
+ }
1584
+ }
1585
+ if (!(l <= Y)) for (let e of c) {
1586
+ let t = e.node.x, n = e.node.width;
1587
+ typeof t != "number" || typeof n != "number" || !Number.isFinite(t) || !Number.isFinite(n) || n <= 0 || (e.node.x = t - l / 2, e.node.width = n + l, e.node.groupTitleRect = {
1588
+ ...e.rect,
1589
+ left: e.rect.left - l,
1590
+ right: e.rect.right - l
1591
+ });
1592
+ }
1593
+ }
1594
+ t(Xe, "shiftLeftLaneTitleBandsLeftOfRails");
1595
+ function Ze(e, n) {
1596
+ let { realNodeRects: r } = z(n.values()), i = e.filter((e) => !e.isLayoutOnly), a = /* @__PURE__ */ t((e, t = /* @__PURE__ */ new Map()) => D(t.get(e) ?? e.points ?? []), "replacementPointsFor"), o = /* @__PURE__ */ t((e = /* @__PURE__ */ new Map()) => {
1597
+ let t = 0;
1598
+ for (let n = 0; n < i.length; n++) {
1599
+ let r = Z(a(i[n], e));
1600
+ for (let o = n + 1; o < i.length; o++) {
1601
+ let n = Z(a(i[o], e));
1602
+ for (let e of r) for (let r of n) V(e.a, e.b, r.a, r.b, Y) && t++;
1603
+ }
1604
+ }
1605
+ return t;
1606
+ }, "crossingCount"), s = /* @__PURE__ */ t((e = /* @__PURE__ */ new Map()) => i.reduce((t, n) => t + E(a(n, e)), 0), "totalBends"), c = /* @__PURE__ */ t((e) => {
1607
+ let t = a(e);
1608
+ if (t.length < 4) return;
1609
+ let n = t[t.length - 2], r = t[t.length - 1];
1610
+ if (x(n, r, Y) || S(n, r, Y)) return {
1611
+ tailStart: n,
1612
+ terminal: r
1613
+ };
1614
+ }, "terminalTailFor"), l = /* @__PURE__ */ t((e, t) => {
1615
+ let n = a(e);
1616
+ if (n.length < 3) return;
1617
+ let r = n[0], i = n[1], o;
1618
+ if (x(r, i, Y)) o = {
1619
+ x: i.x,
1620
+ y: t.tailStart.y
1621
+ };
1622
+ else if (S(r, i, Y)) o = {
1623
+ x: t.tailStart.x,
1624
+ y: i.y
1625
+ };
1626
+ else return;
1627
+ let s = G(D([
1628
+ r,
1629
+ i,
1630
+ o,
1631
+ t.tailStart,
1632
+ t.terminal
1633
+ ]));
1634
+ return Z(s).length === s.length - 1 ? s : void 0;
1635
+ }, "candidateWithDestinationTail"), u = /* @__PURE__ */ t((e, t) => {
1636
+ let n = [e.start, e.end].filter((e) => !!e);
1637
+ for (let e of Z(t)) if (B(e.a, e.b, r, n, -2)) return !0;
1638
+ return !1;
1639
+ }, "pathHasNodeHit"), d = /* @__PURE__ */ t((e, t, n) => {
1640
+ for (let r of i) if (r !== e) {
1641
+ for (let e of Z(t)) for (let t of Z(a(r, n))) if (w(e, t, .5) >= X) return !0;
1642
+ }
1643
+ return !1;
1644
+ }, "pathHasSharedTrack"), f = /* @__PURE__ */ t((e, t, n) => !u(e, t) && !d(e, t, n), "candidateIsSafe"), p = /* @__PURE__ */ t(() => {
1645
+ let e = /* @__PURE__ */ new Map();
1646
+ for (let t of i) {
1647
+ let r = t.end;
1648
+ if (!r || !n.has(r) || a(t).length < 4) continue;
1649
+ let i = e.get(r) ?? [];
1650
+ i.push(t), e.set(r, i);
1651
+ }
1652
+ return e;
1653
+ }, "edgesByDestination");
1654
+ for (let e = 0; e < 4; e++) {
1655
+ let e = o();
1656
+ if (e === 0) return;
1657
+ let t = s(), n, r = e, i = t;
1658
+ for (let t of p().values()) for (let a = 0; a < t.length; a++) for (let u = a + 1; u < t.length; u++) {
1659
+ let d = t[a], p = t[u], m = c(d), h = c(p);
1660
+ if (!m || !h) continue;
1661
+ let g = l(d, h), _ = l(p, m);
1662
+ if (!g || !_) continue;
1663
+ let v = /* @__PURE__ */ new Map([[d, g], [p, _]]);
1664
+ if (!f(d, g, v) || !f(p, _, v)) continue;
1665
+ let y = o(v), b = s(v);
1666
+ y >= e || y > r || y === r && b >= i || (n = v, r = y, i = b);
1667
+ }
1668
+ if (!n) return;
1669
+ for (let [e, t] of n) e.points = t;
1670
+ }
1671
+ }
1672
+ t(Ze, "swapDestinationTerminalTailsToReduceCrossings");
1673
+ function Qe(e, n) {
1674
+ let { realNodeRects: r, labelNodeRects: i } = z(n.values()), a = e.filter((e) => !e.isLayoutOnly), o = /* @__PURE__ */ t((e, t = /* @__PURE__ */ new Map()) => D(t.get(e) ?? e.points ?? []), "replacementPointsFor"), s = /* @__PURE__ */ t((e = /* @__PURE__ */ new Map()) => {
1675
+ let t = 0;
1676
+ for (let n = 0; n < a.length; n++) {
1677
+ let r = Z(o(a[n], e));
1678
+ for (let i = n + 1; i < a.length; i++) {
1679
+ let n = Z(o(a[i], e));
1680
+ for (let e of r) for (let r of n) V(e.a, e.b, r.a, r.b, Y) && t++;
1681
+ }
1682
+ }
1683
+ return t;
1684
+ }, "strictCrossingCount"), c = /* @__PURE__ */ t((e = /* @__PURE__ */ new Map()) => a.reduce((t, n) => t + E(o(n, e)), 0), "totalBends"), l = /* @__PURE__ */ t((e) => {
1685
+ let t = e.start, r = e.end, i = t ? n.get(t) : void 0, a = r ? n.get(r) : void 0, o = i ? F(i) : void 0, s = a ? F(a) : void 0;
1686
+ return o && s ? {
1687
+ src: o,
1688
+ dst: s
1689
+ } : void 0;
1690
+ }, "endpointRectsFor"), u = /* @__PURE__ */ t((e, t, n) => {
1691
+ if (n.index <= 0 || n.index + 1 >= t.length - 1) return;
1692
+ let r = l(e);
1693
+ if (r) {
1694
+ if (n.vertical) {
1695
+ let i = n.a.x, a = Math.min(r.src.left, r.dst.left), o = Math.max(r.src.right, r.dst.right), s = i < a - Y ? "left" : i > o + Y ? "right" : void 0;
1696
+ return s ? {
1697
+ edge: e,
1698
+ points: t,
1699
+ segmentIndex: n.index,
1700
+ axis: "vertical",
1701
+ side: s,
1702
+ coord: i,
1703
+ min: Math.min(n.a.y, n.b.y),
1704
+ max: Math.max(n.a.y, n.b.y)
1705
+ } : void 0;
1706
+ }
1707
+ if (n.horizontal) {
1708
+ let i = n.a.y, a = Math.min(r.src.top, r.dst.top), o = Math.max(r.src.bottom, r.dst.bottom), s = i < a - Y ? "top" : i > o + Y ? "bottom" : void 0;
1709
+ return s ? {
1710
+ edge: e,
1711
+ points: t,
1712
+ segmentIndex: n.index,
1713
+ axis: "horizontal",
1714
+ side: s,
1715
+ coord: i,
1716
+ min: Math.min(n.a.x, n.b.x),
1717
+ max: Math.max(n.a.x, n.b.x)
1718
+ } : void 0;
1719
+ }
1720
+ }
1721
+ }, "externalRailForSegment"), d = /* @__PURE__ */ t(() => {
1722
+ let e = [];
1723
+ for (let t of a) {
1724
+ let n = o(t);
1725
+ for (let r of Z(n)) {
1726
+ let i = u(t, n, r);
1727
+ i && e.push(i);
1728
+ }
1729
+ }
1730
+ return e;
1731
+ }, "collectExternalRails"), f = /* @__PURE__ */ t((e, t) => e.edge !== t.edge && e.axis === t.axis && e.side === t.side && C(e.min, e.max, t.min, t.max) >= X, "railsInteract"), p = /* @__PURE__ */ t((e) => {
1732
+ let t = [], n = /* @__PURE__ */ new Set();
1733
+ for (let r of e) {
1734
+ if (n.has(r)) continue;
1735
+ let i = [r], a = [];
1736
+ for (n.add(r); i.length > 0;) {
1737
+ let t = i.pop();
1738
+ a.push(t);
1739
+ for (let r of e) !n.has(r) && f(t, r) && (n.add(r), i.push(r));
1740
+ }
1741
+ a.length > 1 && t.push(a);
1742
+ }
1743
+ return t;
1744
+ }, "connectedComponents"), m = /* @__PURE__ */ t((e) => {
1745
+ let t = [];
1746
+ for (let n of e) t.some((e) => Math.abs(e - n.coord) < Y) || t.push(n.coord);
1747
+ for (; t.length < e.length;) {
1748
+ let n = Math.min(...t), r = Math.max(...t), i = e[0].side;
1749
+ t.push(i === "left" || i === "top" ? n - 12 * (e.length - t.length) : r + 12 * (e.length - t.length));
1750
+ }
1751
+ return t;
1752
+ }, "uniqueCoordsFor"), h = /* @__PURE__ */ t((e) => {
1753
+ let n = e.map((e) => e.coord), r = m(e), i = [];
1754
+ if (e.length <= 6) {
1755
+ let a = Array(r.length).fill(!1), o = [], s = /* @__PURE__ */ t(() => {
1756
+ if (o.length === e.length) o.some((e, t) => Math.abs(e - n[t]) >= Y) && i.push([...o]);
1757
+ else for (let [e, t] of r.entries()) a[e] || (a[e] = !0, o.push(t), s(), o.pop(), a[e] = !1);
1758
+ }, "visit");
1759
+ return s(), i;
1760
+ }
1761
+ for (let e = 0; e < n.length; e++) for (let t = e + 1; t < n.length; t++) {
1762
+ let r = [...n];
1763
+ [r[e], r[t]] = [r[t], r[e]], i.push(r);
1764
+ }
1765
+ return i;
1766
+ }, "coordinateAssignmentsFor"), g = /* @__PURE__ */ t((e, t) => {
1767
+ let n = /* @__PURE__ */ new Map();
1768
+ for (let [r, i] of e.entries()) {
1769
+ let e = t[r], a = n.get(i.edge) ?? i.points.map((e) => ({
1770
+ x: e.x,
1771
+ y: e.y
1772
+ }));
1773
+ i.axis === "vertical" ? (a[i.segmentIndex].x = e, a[i.segmentIndex + 1].x = e) : (a[i.segmentIndex].y = e, a[i.segmentIndex + 1].y = e), n.set(i.edge, a);
1774
+ }
1775
+ let r = /* @__PURE__ */ new Map();
1776
+ for (let [e, t] of n) {
1777
+ let n = G(D(t));
1778
+ if (Z(n).length !== n.length - 1) return;
1779
+ r.set(e, n);
1780
+ }
1781
+ return r;
1782
+ }, "replacementsForAssignment"), _ = /* @__PURE__ */ t((e) => {
1783
+ for (let [t, n] of e) {
1784
+ let e = [t.start, t.end].filter((e) => !!e);
1785
+ for (let t of Z(n)) if (B(t.a, t.b, r, e, -2) || B(t.a, t.b, i, [], -2)) return !1;
1786
+ }
1787
+ for (let t = 0; t < a.length; t++) {
1788
+ let n = a[t], r = e.has(n), i = Z(o(n, e));
1789
+ for (let n = t + 1; n < a.length; n++) {
1790
+ let t = a[n];
1791
+ if (!r && !e.has(t)) continue;
1792
+ let s = Z(o(t, e));
1793
+ for (let e of i) for (let t of s) if (w(e, t, .5) >= X) return !1;
1794
+ }
1795
+ }
1796
+ return !0;
1797
+ }, "candidateIsSafe");
1798
+ for (let e = 0; e < 4; e++) {
1799
+ let e = s();
1800
+ if (e === 0) return;
1801
+ let t, n = e, r = c(), i = Infinity;
1802
+ for (let a of p(d())) for (let o of h(a)) {
1803
+ let l = g(a, o);
1804
+ if (!l || !_(l)) continue;
1805
+ let u = s(l);
1806
+ if (u >= e) continue;
1807
+ let d = c(l), f = a.reduce((e, t, n) => e + Math.abs(o[n] - t.coord), 0);
1808
+ u > n || u === n && (d > r || d === r && f >= i) || (t = l, n = u, r = d, i = f);
1809
+ }
1810
+ if (!t) return;
1811
+ for (let [e, n] of t) e.points = n;
1812
+ }
1813
+ }
1814
+ t(Qe, "reassignCrossingExternalRailChannels");
1815
+ function $e(e, n) {
1816
+ let { realNodeRects: r, labelNodeRects: i } = z(n.values()), a = e.filter((e) => !e.isLayoutOnly), o = /* @__PURE__ */ t((e, t, n) => D(e === t ? n ?? [] : e.points ?? []), "pointsFor"), s = /* @__PURE__ */ t((e) => Z(e).reduce((e, t) => {
1817
+ let n = t.a.x - t.b.x, r = t.a.y - t.b.y;
1818
+ return e + Math.hypot(n, r);
1819
+ }, 0), "pathLength"), c = /* @__PURE__ */ t((e, t) => {
1820
+ let n = 0;
1821
+ for (let r = 0; r < a.length; r++) {
1822
+ let i = Z(o(a[r], e, t));
1823
+ for (let s = r + 1; s < a.length; s++) {
1824
+ let r = Z(o(a[s], e, t));
1825
+ for (let e of i) for (let t of r) V(e.a, e.b, t.a, t.b, Y) && n++;
1826
+ }
1827
+ }
1828
+ return n;
1829
+ }, "strictCrossingCount"), l = /* @__PURE__ */ t((e, t) => {
1830
+ if (e.horizontal) {
1831
+ let n = e.a.y;
1832
+ return (Math.abs(n - t.top) < 1 || Math.abs(n - t.bottom) < 1) && C(e.a.x, e.b.x, t.left, t.right) >= X;
1833
+ }
1834
+ if (e.vertical) {
1835
+ let n = e.a.x;
1836
+ return (Math.abs(n - t.left) < 1 || Math.abs(n - t.right) < 1) && C(e.a.y, e.b.y, t.top, t.bottom) >= X;
1837
+ }
1838
+ return !1;
1839
+ }, "segmentRunsAlongRectBorder"), u = /* @__PURE__ */ t((e) => {
1840
+ let t = [e.start, e.end].filter((e) => !!e), r = [];
1841
+ for (let e of t) {
1842
+ let t = n.get(e), i = t ? F(t) : void 0;
1843
+ i && r.push(i);
1844
+ }
1845
+ return r;
1846
+ }, "endpointRectsFor"), d = /* @__PURE__ */ t((e, t) => {
1847
+ if (t + 3 >= e.length) return [];
1848
+ let n = e[t], r = e[t + 1], i = e[t + 2], a = e[t + 3], o = x(n, r, Y) && S(r, i, Y) && x(i, a, Y), s = S(n, r, Y) && x(r, i, Y) && S(i, a, Y);
1849
+ if (!o && !s || !(o ? Math.sign(r.x - n.x) !== Math.sign(a.x - i.x) : Math.sign(r.y - n.y) !== Math.sign(a.y - i.y))) return [];
1850
+ let c = y(n, a, Y) || b(n, a, Y) ? [] : [{
1851
+ x: n.x,
1852
+ y: a.y
1853
+ }, {
1854
+ x: a.x,
1855
+ y: n.y
1856
+ }], l = c.length === 0 ? [[...e.slice(0, t + 1), ...e.slice(t + 3)]] : c.map((n) => [
1857
+ ...e.slice(0, t + 1),
1858
+ n,
1859
+ ...e.slice(t + 3)
1860
+ ]), u = /* @__PURE__ */ new Set();
1861
+ return l.map((e) => G(D(e))).filter((e) => {
1862
+ if (Z(e).length !== e.length - 1 || !e.some((e) => v(e, a, Y))) return !1;
1863
+ let t = e.map((e) => `${e.x.toFixed(3)},${e.y.toFixed(3)}`).join("|");
1864
+ return !u.has(t) && (u.add(t), !0);
1865
+ });
1866
+ }, "shortcutCandidatesAt"), f = /* @__PURE__ */ t((e, t, n) => {
1867
+ let s = [e.start, e.end].filter((e) => !!e), d = u(e);
1868
+ for (let e of Z(t)) if (B(e.a, e.b, r, s, -2) || B(e.a, e.b, i, [], -2) || d.some((t) => l(e, t))) return !1;
1869
+ for (let n of a) if (n !== e) {
1870
+ for (let e of Z(t)) for (let t of Z(o(n))) if (w(e, t, .5) >= X) return !1;
1871
+ }
1872
+ return c(e, t) <= n;
1873
+ }, "candidateIsSafe");
1874
+ for (let e = 0; e < 8; e++) {
1875
+ let e = c(), t, n, r = e, i = Infinity, l = Infinity;
1876
+ for (let u of a) {
1877
+ let a = o(u), p = E(a, Y), m = s(a);
1878
+ for (let o = 0; o <= a.length - 4; o++) for (let h of d(a, o)) {
1879
+ let a = E(h, Y), o = s(h);
1880
+ if (!(a < p || a === p && o < m - Y) || !f(u, h, e)) continue;
1881
+ let d = c(u, h);
1882
+ d > r || d === r && (a > i || a === i && o >= l) || (t = u, n = h, r = d, i = a, l = o);
1883
+ }
1884
+ }
1885
+ if (!t || !n) return;
1886
+ t.points = n;
1887
+ }
1888
+ }
1889
+ t($e, "shortcutRedundantOrthogonalJogs");
1890
+ function et(e, n) {
1891
+ let r = [];
1892
+ for (let e of n.values()) {
1893
+ if (e.isGroup || e.isEdgeLabel) continue;
1894
+ let t = e.x ?? 0, n = e.y ?? 0, i = F(e);
1895
+ i && r.push({
1896
+ id: String(e.id ?? ""),
1897
+ cx: t,
1898
+ cy: n,
1899
+ rect: i
1900
+ });
1901
+ }
1902
+ if (r.length === 0) return;
1903
+ let i = new Map(r.map((e) => [e.id, e])), a = r.map((e) => ({
1904
+ id: e.id,
1905
+ rect: e.rect
1906
+ })), o = [
1907
+ "top",
1908
+ "bottom",
1909
+ "left",
1910
+ "right"
1911
+ ], s = {
1912
+ top: Math.min(...r.map((e) => e.rect.top)) - 20,
1913
+ bottom: Math.max(...r.map((e) => e.rect.bottom)) + 20,
1914
+ left: Math.min(...r.map((e) => e.rect.left)) - 20,
1915
+ right: Math.max(...r.map((e) => e.rect.right)) + 20
1916
+ }, c = e.filter((e) => !e.isLayoutOnly), l = new Map(c.map((e, t) => [e, t])), u = /* @__PURE__ */ t((e) => {
1917
+ let t = e === "left" || e === "top" ? -1 : 1, n = [];
1918
+ for (let r = 0; r <= 2; r++) n.push(s[e] + t * 20 * r);
1919
+ return n;
1920
+ }, "outwardTracksForSide"), d = /* @__PURE__ */ t((e, t = /* @__PURE__ */ new Map()) => D(t.get(e) ?? e.points ?? []), "replacementPointsFor"), f = /* @__PURE__ */ t((e, t) => {
1921
+ let n = 0;
1922
+ for (let r of e) for (let e of t) V(r.a, r.b, e.a, e.b, Y) && n++;
1923
+ return n;
1924
+ }, "crossingCountBetweenSegments"), p = /* @__PURE__ */ t((e, t) => f(Z(e), Z(t)), "crossingCountBetweenPaths"), m = /* @__PURE__ */ t((e = /* @__PURE__ */ new Map()) => {
1925
+ let n = 0, r = [], i = /* @__PURE__ */ new Set(), a = [], o = /* @__PURE__ */ t((e) => {
1926
+ i.has(e) || (i.add(e), a.push(e));
1927
+ }, "addEdge");
1928
+ for (let t = 0; t < c.length; t++) {
1929
+ let i = c[t], a = d(i, e);
1930
+ for (let s = t + 1; s < c.length; s++) {
1931
+ let t = c[s], l = p(a, d(t, e));
1932
+ l > 0 && (n += l, r.push({
1933
+ first: i,
1934
+ second: t,
1935
+ count: l
1936
+ }), o(i), o(t));
1937
+ }
1938
+ }
1939
+ return a.sort((e, t) => (l.get(e) ?? 0) - (l.get(t) ?? 0)), {
1940
+ count: n,
1941
+ pairs: r,
1942
+ edgeSet: i,
1943
+ edges: a
1944
+ };
1945
+ }, "crossingSnapshot"), h = /* @__PURE__ */ t((e, t) => {
1946
+ let n = new Set(t.keys());
1947
+ if (n.size === 0) return e.count;
1948
+ let r = 0;
1949
+ for (let t of e.pairs) (n.has(t.first) || n.has(t.second)) && (r += t.count);
1950
+ let i = 0;
1951
+ for (let e = 0; e < c.length; e++) {
1952
+ let r = c[e], a = n.has(r), o = d(r, t);
1953
+ for (let r = e + 1; r < c.length; r++) {
1954
+ let e = c[r];
1955
+ (a || n.has(e)) && (i += p(o, d(e, t)));
1956
+ }
1957
+ }
1958
+ return e.count - r + i;
1959
+ }, "crossingCountWithReplacements"), g = /* @__PURE__ */ t((e) => {
1960
+ let t = /* @__PURE__ */ new Map();
1961
+ for (let n of e.pairs) {
1962
+ let e = t.get(n.first) ?? /* @__PURE__ */ new Set();
1963
+ e.add(n.second), t.set(n.first, e);
1964
+ let r = t.get(n.second) ?? /* @__PURE__ */ new Set();
1965
+ r.add(n.first), t.set(n.second, r);
1966
+ }
1967
+ let n = [], r = /* @__PURE__ */ new Set();
1968
+ for (let i of e.edges) {
1969
+ if (r.has(i)) continue;
1970
+ let e = [i], a = [];
1971
+ for (r.add(i); e.length > 0;) {
1972
+ let n = e.pop();
1973
+ a.push(n);
1974
+ for (let i of t.get(n) ?? []) r.has(i) || (r.add(i), e.push(i));
1975
+ }
1976
+ a.sort((e, t) => (l.get(e) ?? 0) - (l.get(t) ?? 0)), a.length > 1 && n.push(a);
1977
+ }
1978
+ return n;
1979
+ }, "crossingComponents"), _ = /* @__PURE__ */ t((e) => [e.start, e.end].filter((e) => !!e), "endpointIdsFor"), v = /* @__PURE__ */ t((e) => {
1980
+ let t = [];
1981
+ for (let n of g(e)) {
1982
+ let e = new Set(n), r = new Set(n.flatMap((e) => _(e))), i = [...n];
1983
+ for (let t of c) e.has(t) || _(t).some((e) => r.has(e)) && i.push(t);
1984
+ i.sort((e, t) => (l.get(e) ?? 0) - (l.get(t) ?? 0)), t.push(i);
1985
+ }
1986
+ return t;
1987
+ }, "pairSearchGroups"), y = /* @__PURE__ */ t((e, t, n) => h(e, /* @__PURE__ */ new Map([[t, n]])), "crossingCountWithSingleReplacement"), b = /* @__PURE__ */ t((e) => {
1988
+ let t = /* @__PURE__ */ new Map();
1989
+ for (let n of e.pairs) t.set(n.first, (t.get(n.first) ?? 0) + n.count), t.set(n.second, (t.get(n.second) ?? 0) + n.count);
1990
+ return t;
1991
+ }, "currentCrossingsByEdge"), C = /* @__PURE__ */ t((e) => e.slice(1).reduce((t, n, r) => {
1992
+ let i = e[r];
1993
+ return t + Math.abs(n.x - i.x) + Math.abs(n.y - i.y);
1994
+ }, 0), "pathLength"), T = /* @__PURE__ */ t((e = /* @__PURE__ */ new Map()) => c.reduce((t, n) => t + E(d(n, e)), 0), "totalBends"), O = /* @__PURE__ */ t((e = /* @__PURE__ */ new Map()) => c.reduce((t, n) => t + C(d(n, e)), 0), "totalLength"), k = /* @__PURE__ */ t((e, t, n = /* @__PURE__ */ new Map()) => {
1995
+ let r = Z(t);
1996
+ for (let t of c) if (t !== e) {
1997
+ for (let e of r) for (let r of Z(d(t, n))) if (w(e, r, .5) >= X) return !0;
1998
+ }
1999
+ return !1;
2000
+ }, "pathHasSegmentConflict"), A = /* @__PURE__ */ t((e, t) => {
2001
+ let n = [e.start, e.end].filter((e) => !!e);
2002
+ for (let e of Z(t)) if (B(e.a, e.b, a, n, -2)) return !0;
2003
+ return !1;
2004
+ }, "pathHitsNode"), j = /* @__PURE__ */ t((e, t) => {
2005
+ let n = G(D(t));
2006
+ Z(n).length === n.length - 1 && e.push(n);
2007
+ }, "pushOrthogonalCandidate"), M = /* @__PURE__ */ t((e) => e === "left" || e === "right", "sideIsHorizontal"), N = /* @__PURE__ */ t((e, t, n) => {
2008
+ switch (t) {
2009
+ case "left": return Math.min(e.x, n.x) - 20;
2010
+ case "right": return Math.max(e.x, n.x) + 20;
2011
+ case "top": return Math.min(e.y, n.y) - 20;
2012
+ case "bottom": return Math.max(e.y, n.y) + 20;
2013
+ }
2014
+ }, "localTrackForSameSide"), P = /* @__PURE__ */ t((e, t, n, r) => {
2015
+ let i = n === "left" || n === "top" ? -1 : 1, a = [N(t, n, r), s[n]];
2016
+ for (let o of a) for (let a = 0; a <= 2; a++) j(e, L(t, n, r, o + i * 20 * a));
2017
+ }, "addSameSideCandidates"), R = /* @__PURE__ */ t((e, t, n, r, i) => {
2018
+ for (let a of u(n)) for (let n of u(i)) j(e, [
2019
+ t,
2020
+ {
2021
+ x: a,
2022
+ y: t.y
2023
+ },
2024
+ {
2025
+ x: a,
2026
+ y: n
2027
+ },
2028
+ {
2029
+ x: r.x,
2030
+ y: n
2031
+ },
2032
+ r
2033
+ ]);
2034
+ }, "addHorizontalToVerticalCandidates"), z = /* @__PURE__ */ t((e, t, n, r, i) => {
2035
+ for (let a of u(n)) for (let n of u(i)) j(e, [
2036
+ t,
2037
+ {
2038
+ x: t.x,
2039
+ y: a
2040
+ },
2041
+ {
2042
+ x: n,
2043
+ y: a
2044
+ },
2045
+ {
2046
+ x: n,
2047
+ y: r.y
2048
+ },
2049
+ r
2050
+ ]);
2051
+ }, "addVerticalToHorizontalCandidates"), te = /* @__PURE__ */ t((e, t, n, r, i) => {
2052
+ let a = [...u("top"), ...u("bottom")];
2053
+ for (let o of u(n)) for (let n of u(i)) for (let i of a) j(e, [
2054
+ t,
2055
+ {
2056
+ x: o,
2057
+ y: t.y
2058
+ },
2059
+ {
2060
+ x: o,
2061
+ y: i
2062
+ },
2063
+ {
2064
+ x: n,
2065
+ y: i
2066
+ },
2067
+ {
2068
+ x: n,
2069
+ y: r.y
2070
+ },
2071
+ r
2072
+ ]);
2073
+ }, "addHorizontalPairCandidates"), ne = /* @__PURE__ */ t((e, t, n, r, i) => {
2074
+ let a = [...u("left"), ...u("right")];
2075
+ for (let o of u(n)) for (let n of u(i)) for (let i of a) j(e, [
2076
+ t,
2077
+ {
2078
+ x: t.x,
2079
+ y: o
2080
+ },
2081
+ {
2082
+ x: i,
2083
+ y: o
2084
+ },
2085
+ {
2086
+ x: i,
2087
+ y: n
2088
+ },
2089
+ {
2090
+ x: r.x,
2091
+ y: n
2092
+ },
2093
+ r
2094
+ ]);
2095
+ }, "addVerticalPairCandidates"), re = /* @__PURE__ */ t((e) => {
2096
+ let t = /* @__PURE__ */ new Set();
2097
+ return e.map((e) => D(e)).filter((e) => {
2098
+ let n = e.map((e) => `${e.x.toFixed(3)},${e.y.toFixed(3)}`).join("|");
2099
+ return t.has(n) || e.length < 2 ? !1 : (t.add(n), !0);
2100
+ });
2101
+ }, "dedupeCandidatePaths"), ie = /* @__PURE__ */ t((e, t, n, r) => {
2102
+ let i = [], a = ee(e, t, n, r, 20, Y);
2103
+ a && j(i, a), t === r && P(i, e, t, n);
2104
+ let o = M(t), s = M(r);
2105
+ return o && !s ? R(i, e, t, n, r) : !o && s ? z(i, e, t, n, r) : o ? te(i, e, t, n, r) : ne(i, e, t, n, r), re(i);
2106
+ }, "buildCandidatesForSides"), ae = /* @__PURE__ */ t((e, t, n, r) => {
2107
+ let i = [...u("left"), ...u("right")], a = [...u("top"), ...u("bottom")];
2108
+ for (let s of o) {
2109
+ let o = I(r, s), c = s === "top" || s === "bottom" ? u(s) : a;
2110
+ for (let r of i) {
2111
+ j(e, [
2112
+ t,
2113
+ n,
2114
+ {
2115
+ x: r,
2116
+ y: n.y
2117
+ },
2118
+ {
2119
+ x: r,
2120
+ y: o.y
2121
+ },
2122
+ o
2123
+ ]);
2124
+ for (let i of c) j(e, [
2125
+ t,
2126
+ n,
2127
+ {
2128
+ x: r,
2129
+ y: n.y
2130
+ },
2131
+ {
2132
+ x: r,
2133
+ y: i
2134
+ },
2135
+ {
2136
+ x: o.x,
2137
+ y: i
2138
+ },
2139
+ o
2140
+ ]);
2141
+ }
2142
+ }
2143
+ }, "addVerticalDepartureOuterTrackCandidates"), oe = /* @__PURE__ */ t((e, t, n, r) => {
2144
+ let i = [...u("left"), ...u("right")], a = [...u("top"), ...u("bottom")];
2145
+ for (let s of o) {
2146
+ let o = I(r, s), c = s === "left" || s === "right" ? u(s) : i;
2147
+ for (let r of a) {
2148
+ j(e, [
2149
+ t,
2150
+ n,
2151
+ {
2152
+ x: n.x,
2153
+ y: r
2154
+ },
2155
+ {
2156
+ x: o.x,
2157
+ y: r
2158
+ },
2159
+ o
2160
+ ]);
2161
+ for (let i of c) j(e, [
2162
+ t,
2163
+ n,
2164
+ {
2165
+ x: n.x,
2166
+ y: r
2167
+ },
2168
+ {
2169
+ x: i,
2170
+ y: r
2171
+ },
2172
+ {
2173
+ x: i,
2174
+ y: o.y
2175
+ },
2176
+ o
2177
+ ]);
2178
+ }
2179
+ }
2180
+ }, "addHorizontalDepartureOuterTrackCandidates"), H = /* @__PURE__ */ t((e) => {
2181
+ let t = e.start, n = e.end, r = n ? i.get(n) : void 0;
2182
+ if (!t || !r) return [];
2183
+ let a = D(e.points ?? []);
2184
+ if (a.length < 4) return [];
2185
+ let o = a[0], s = a[1], c = [];
2186
+ return S(o, s, Y) ? ae(c, o, s, r) : x(o, s, Y) && oe(c, o, s, r), c;
2187
+ }, "terminalPreservingOuterTrackCandidates"), U = /* @__PURE__ */ t((e) => {
2188
+ let t = e.start, n = e.end, r = t ? i.get(t) : void 0, a = n ? i.get(n) : void 0;
2189
+ if (!r || !a) return [];
2190
+ let s = [];
2191
+ for (let e of o) {
2192
+ let t = I(r, e);
2193
+ for (let n of o) s.push(...ie(t, e, I(a, n), n));
2194
+ }
2195
+ return s.push(...H(e)), s;
2196
+ }, "candidatePathsFor"), W = /* @__PURE__ */ t(() => new Map(c.map((e) => [e, Z(d(e))])), "currentSegmentsByEdge"), K = /* @__PURE__ */ t((e, t, n) => {
2197
+ let r = /* @__PURE__ */ new Set();
2198
+ for (let i of c) {
2199
+ if (i === e) continue;
2200
+ let a = n.get(i) ?? Z(d(i));
2201
+ t.some((e) => a.some((t) => w(e, t, .5) >= X)) && r.add(i);
2202
+ }
2203
+ return r;
2204
+ }, "sharedTrackConflictsFor"), se = /* @__PURE__ */ t((e, t, n, r) => {
2205
+ let i = /* @__PURE__ */ new Set();
2206
+ return U(e).map((e) => G(D(e))).filter((t) => {
2207
+ if (A(e, t)) return !1;
2208
+ let n = t.map((e) => `${e.x.toFixed(3)},${e.y.toFixed(3)}`).join("|");
2209
+ return i.has(n) || t.length < 2 ? !1 : (i.add(n), !0);
2210
+ }).map((i) => {
2211
+ let a = Z(i), o = 0;
2212
+ for (let t of c) t !== e && (o += f(a, n.get(t) ?? Z(d(t))));
2213
+ return {
2214
+ candidate: i,
2215
+ candidateSegments: a,
2216
+ crossings: t.count - (r.get(e) ?? 0) + o,
2217
+ bends: E(i, Y),
2218
+ totalBends: E(i),
2219
+ length: C(i)
2220
+ };
2221
+ }).filter(({ crossings: e }) => e <= t.count).sort((e, t) => e.crossings - t.crossings || e.bends - t.bends || e.length - t.length).slice(0, 48).map((t) => ({
2222
+ path: t.candidate,
2223
+ segments: t.candidateSegments,
2224
+ sharedTrackConflicts: K(e, t.candidateSegments, n),
2225
+ totalBends: t.totalBends,
2226
+ length: t.length
2227
+ }));
2228
+ }, "pairCandidatesFor"), ce = /* @__PURE__ */ t((e, t, n, r, i, a) => {
2229
+ let o = 0;
2230
+ for (let n of e.pairs) (n.first === t || n.second === t || n.first === r || n.second === r) && (o += n.count);
2231
+ let s = f(n.segments, i.segments);
2232
+ for (let e of c) {
2233
+ if (e === t || e === r) continue;
2234
+ let o = a.get(e) ?? Z(d(e));
2235
+ s += f(n.segments, o) + f(i.segments, o);
2236
+ }
2237
+ return e.count - o + s;
2238
+ }, "pairCrossingCount"), le = /* @__PURE__ */ t((e, t) => {
2239
+ for (let n of e.sharedTrackConflicts) if (n !== t) return !1;
2240
+ return !0;
2241
+ }, "conflictsOnlyWith"), ue = /* @__PURE__ */ t((e, t) => e.segments.some((e) => t.segments.some((t) => w(e, t, .5) >= X)), "candidatesShareTrack"), de = /* @__PURE__ */ t((e, t, n, r) => le(t, n.edge) && le(r, e.edge) && !ue(t, r), "pairCandidatesAreCompatible"), q = /* @__PURE__ */ t((e, t, n, r, i) => {
2242
+ let a = ce(e.current, t.edge, n, r.edge, i, e.baseSegments);
2243
+ if (!(a >= e.current.count)) return {
2244
+ replacements: /* @__PURE__ */ new Map([[t.edge, n.path], [r.edge, i.path]]),
2245
+ crossings: a,
2246
+ bends: e.currentBends - (e.baseBendsByEdge.get(t.edge) ?? 0) - (e.baseBendsByEdge.get(r.edge) ?? 0) + n.totalBends + i.totalBends,
2247
+ length: e.currentLength - (e.baseLengthByEdge.get(t.edge) ?? 0) - (e.baseLengthByEdge.get(r.edge) ?? 0) + n.length + i.length
2248
+ };
2249
+ }, "scorePairReplacement"), J = /* @__PURE__ */ t((e, t) => e.crossings < t.crossings || e.crossings === t.crossings && (e.bends < t.bends || e.bends === t.bends && e.length < t.length), "pairScoreIsBetter"), fe = /* @__PURE__ */ t((e, t, n, r) => {
2250
+ let i = r;
2251
+ for (let r of t.candidates) for (let a of n.candidates) {
2252
+ if (!de(t, r, n, a)) continue;
2253
+ let o = q(e, t, r, n, a);
2254
+ o && J(o, i) && (i = o);
2255
+ }
2256
+ return i;
2257
+ }, "bestScoreForOptionPair"), pe = /* @__PURE__ */ t((e) => {
2258
+ let t = T(), n = O(), r = W(), i = b(e), a = new Map(c.map((e) => [e, E(d(e))])), o = new Map(c.map((e) => [e, C(d(e))])), s = /* @__PURE__ */ new Map(), l = v(e);
2259
+ for (let t of l) for (let n of t) {
2260
+ if (s.has(n)) continue;
2261
+ let t = se(n, e, r, i);
2262
+ t.length > 0 && s.set(n, {
2263
+ edge: n,
2264
+ candidates: t
2265
+ });
2266
+ }
2267
+ let u = {
2268
+ replacements: /* @__PURE__ */ new Map(),
2269
+ crossings: e.count,
2270
+ bends: t,
2271
+ length: n
2272
+ }, f = {
2273
+ current: e,
2274
+ currentBends: t,
2275
+ currentLength: n,
2276
+ baseBendsByEdge: a,
2277
+ baseLengthByEdge: o,
2278
+ baseSegments: r
2279
+ };
2280
+ for (let t of l) {
2281
+ let n = new Set(t.filter((t) => e.edgeSet.has(t))), r = t.map((e) => s.get(e)).filter((e) => !!e);
2282
+ for (let e = 0; e < r.length; e++) {
2283
+ let t = r[e];
2284
+ for (let i = e + 1; i < r.length; i++) {
2285
+ let e = r[i];
2286
+ (n.has(t.edge) || n.has(e.edge)) && (u = fe(f, t, e, u));
2287
+ }
2288
+ }
2289
+ }
2290
+ return u.replacements.size > 0 ? u.replacements : void 0;
2291
+ }, "bestPairedReplacement");
2292
+ for (let e = 0; e < 4; e++) {
2293
+ let e = m(), t = e.count;
2294
+ if (t === 0) return;
2295
+ let n, r, i = t, a = Infinity;
2296
+ for (let o of e.edges) {
2297
+ let s = E(d(o), Y);
2298
+ for (let c of U(o)) {
2299
+ let l = A(o, c), u = !l && k(o, c), d = y(e, o, c), f = E(c, Y);
2300
+ l || u || (d < t || d === t && f < s) && (d > i || d === i && f >= a || (n = o, r = c, i = d, a = f));
2301
+ }
2302
+ }
2303
+ if (n && r) {
2304
+ n.points = r;
2305
+ continue;
2306
+ }
2307
+ let o = pe(e);
2308
+ if (!o) return;
2309
+ for (let [e, t] of o) e.points = t;
2310
+ }
2311
+ }
2312
+ t(et, "resolveRenderedOrthogonalCrossings");
2313
+ var tt = .001, nt = 8;
2314
+ function rt(e, n) {
2315
+ let { nodeInfoById: r, realNodeRects: i } = R(n), a = [
2316
+ "top",
2317
+ "bottom",
2318
+ "left",
2319
+ "right"
2320
+ ], o = {
2321
+ top: Math.min(...i.map((e) => e.rect.top)) - 20,
2322
+ bottom: Math.max(...i.map((e) => e.rect.bottom)) + 20,
2323
+ left: Math.min(...i.map((e) => e.rect.left)) - 20,
2324
+ right: Math.max(...i.map((e) => e.rect.right)) + 20
2325
+ }, s = /* @__PURE__ */ t((e, t, n, r) => {
2326
+ let i = [], a = ee(e, t, n, r, 20, tt);
2327
+ return a && i.push(a), t === r && i.push(L(e, t, n, o[t])), i;
2328
+ }, "buildOrthogonalPathCandidates"), c = /* @__PURE__ */ t((e, t) => {
2329
+ for (let n = 0; n < e.length - 1; n++) {
2330
+ let r = e[n], a = e[n + 1];
2331
+ if (B(r, a, i, t, 1)) return !0;
2332
+ }
2333
+ return !1;
2334
+ }, "pathHitsNode"), l = /* @__PURE__ */ t((t, n, r = !1) => {
2335
+ let i = 0, a = T(t, tt), o = n.start, s = n.end;
2336
+ for (let t of e) {
2337
+ if (t === n || t.isLayoutOnly) continue;
2338
+ let e = t.start, c = t.end;
2339
+ if (!r && o && s && (e === o || e === s || c === o || c === s)) continue;
2340
+ let l = t.points;
2341
+ if (!(!l || l.length < 2)) for (let e of a) for (let t of T(l, tt)) (re(e.a, e.b, t.a, t.b, tt, tt) || w(e, t, tt) >= nt) && i++;
2342
+ }
2343
+ return i;
2344
+ }, "pathConflictCount"), u = /* @__PURE__ */ t((e, t) => {
2345
+ let n = Math.abs(e.y - t.rect.top), r = Math.abs(e.y - t.rect.bottom), i = Math.abs(e.x - t.rect.left), a = Math.abs(e.x - t.rect.right), o = "top", s = n;
2346
+ return r < s && (o = "bottom", s = r), i < s && (o = "left", s = i), a < s && (o = "right", s = a), o;
2347
+ }, "nearestSideOfRect"), d = /* @__PURE__ */ new Map(), f = /* @__PURE__ */ t((e, t, n) => {
2348
+ let r = d.get(e) ?? [];
2349
+ r.push({
2350
+ side: t,
2351
+ edgeId: n
2352
+ }), d.set(e, r);
2353
+ }, "addFaceClaim");
2354
+ for (let t of e) {
2355
+ if (t.isLayoutOnly) continue;
2356
+ let e = t.points ?? [];
2357
+ if (e.length < 1) continue;
2358
+ let n = t.id ?? "", i = t.start, a = t.end;
2359
+ if (i) {
2360
+ let t = r.get(i);
2361
+ t && f(i, u(e[0], t), n);
2362
+ }
2363
+ if (a) {
2364
+ let t = r.get(a);
2365
+ t && f(a, u(e[e.length - 1], t), n);
2366
+ }
2367
+ }
2368
+ let p = /* @__PURE__ */ t((e, t, n) => d.get(e)?.some((e) => e.edgeId !== n && e.side === t) ?? !1, "faceIsClaimed");
2369
+ for (let t of e) {
2370
+ if (t.isLayoutOnly) continue;
2371
+ let e = t.points;
2372
+ if (!e || e.length < 2) continue;
2373
+ let n = E(e, tt);
2374
+ if (n < 4) continue;
2375
+ let i = t.start, o = t.end;
2376
+ if (!i || !o) continue;
2377
+ let m = r.get(i), h = r.get(o);
2378
+ if (!m || !h) continue;
2379
+ let g = t.id ?? "", _ = l(e, t, !0), v = l(e, t), y, b = _, x = n;
2380
+ for (let e of a) {
2381
+ if (p(i, e, g)) continue;
2382
+ let n = I(m, e);
2383
+ for (let r of a) {
2384
+ if (p(o, r, g)) continue;
2385
+ let a = I(h, r);
2386
+ for (let u of s(n, e, a, r)) {
2387
+ if (c(u, [i, o])) continue;
2388
+ let e = E(u, tt);
2389
+ if (_ > 0) {
2390
+ let n = l(u, t, !0);
2391
+ if (n > b || n === b && e >= x) continue;
2392
+ b = n, x = e, y = u;
2393
+ } else l(u, t) > v || e < x && (x = e, y = u);
2394
+ }
2395
+ }
2396
+ }
2397
+ if (y) {
2398
+ t.points = y;
2399
+ let e = d.get(i);
2400
+ e && d.set(i, e.filter((e) => e.edgeId !== g));
2401
+ let n = d.get(o);
2402
+ n && d.set(o, n.filter((e) => e.edgeId !== g)), f(i, u(y[0], m), g), f(o, u(y[y.length - 1], h), g);
2403
+ }
2404
+ }
2405
+ }
2406
+ t(rt, "simplifyDetouredEdges");
2407
+ var Q = .001, it = 10, at = 7;
2408
+ function ot(e, t) {
2409
+ let n = t ? 0 : e.length - 1, r = t ? 1 : -1, i = e[n], a = e[n + r];
2410
+ if (!i || !a) return;
2411
+ let o = a.x - i.x, s = a.y - i.y;
2412
+ if (!(Math.abs(o) + Math.abs(s) < Q)) {
2413
+ if (Math.abs(s) <= Q) {
2414
+ let e = i.x + Math.sign(o) * it;
2415
+ return {
2416
+ left: Math.min(i.x, e),
2417
+ right: Math.max(i.x, e),
2418
+ top: i.y - at,
2419
+ bottom: i.y + at
2420
+ };
2421
+ }
2422
+ if (Math.abs(o) <= Q) {
2423
+ let e = i.y + Math.sign(s) * it;
2424
+ return {
2425
+ left: i.x - at,
2426
+ right: i.x + at,
2427
+ top: Math.min(i.y, e),
2428
+ bottom: Math.max(i.y, e)
2429
+ };
2430
+ }
2431
+ return {
2432
+ left: Math.min(i.x, a.x),
2433
+ right: Math.max(i.x, a.x),
2434
+ top: Math.min(i.y, a.y),
2435
+ bottom: Math.max(i.y, a.y)
2436
+ };
2437
+ }
2438
+ }
2439
+ t(ot, "markerClearanceRectFor");
2440
+ function st(e) {
2441
+ return {
2442
+ left: Math.min(e.left, e.right),
2443
+ right: Math.max(e.left, e.right),
2444
+ top: Math.min(e.top, e.bottom),
2445
+ bottom: Math.max(e.top, e.bottom)
2446
+ };
2447
+ }
2448
+ t(st, "normalizeRect");
2449
+ function ct(e, t) {
2450
+ let n = D(t);
2451
+ return [ot(n, !0), ot(n, !1)].some((t) => t && M(e, st(t)));
2452
+ }
2453
+ t(ct, "labelOverlapsOwnMarker");
2454
+ function lt(e, n) {
2455
+ let r = [];
2456
+ for (let t of e) {
2457
+ if (t.isLayoutOnly) continue;
2458
+ let e = t.points;
2459
+ if (!(!e || e.length < 2)) for (let n = 0; n < e.length - 1; n++) r.push({
2460
+ edgeId: t.id,
2461
+ p1: e[n],
2462
+ p2: e[n + 1]
2463
+ });
2464
+ }
2465
+ let i = [], a = [];
2466
+ for (let e of n.values()) {
2467
+ let t = e.isGroup, n = e.parentId;
2468
+ if (t && !n) {
2469
+ let t = F(e);
2470
+ t && a.push({
2471
+ id: e.id,
2472
+ rect: t
2473
+ });
2474
+ continue;
2475
+ }
2476
+ if (t || e.isEdgeLabel) continue;
2477
+ let r = F(e);
2478
+ r && i.push({
2479
+ nodeId: e.id,
2480
+ rect: r
2481
+ });
2482
+ }
2483
+ let o = /* @__PURE__ */ t((e, t) => {
2484
+ let n = N(t, 3);
2485
+ for (let { nodeId: t, rect: r } of i) if (t !== e && M(n, r)) return !0;
2486
+ return !1;
2487
+ }, "labelOverlapsForeignNode"), s = /* @__PURE__ */ t((e, t) => {
2488
+ let n = N(t, 3);
2489
+ for (let t of r) if (t.edgeId !== e && k(t.p1, t.p2, n)) return !0;
2490
+ return !1;
2491
+ }, "labelOverlapsForeignEdge"), c = /* @__PURE__ */ t((e, t, n) => o(e, n) || s(t, n), "labelOverlapsAnything"), l = [], u = /* @__PURE__ */ t((e) => {
2492
+ for (let { id: t, rect: n } of a) if (j(n, e)) return t;
2493
+ }, "findContainingLane"), d = /* @__PURE__ */ t((e, t) => l.some((n) => n.labelId !== e && M(t, n.rect)), "overlapsPlacedLabel");
2494
+ for (let r of e) {
2495
+ if (r.isLayoutOnly) continue;
2496
+ let e = r.labelNodeId;
2497
+ if (!e) continue;
2498
+ let i = n.get(e);
2499
+ if (!i) continue;
2500
+ let f = r.points;
2501
+ if (!f || f.length < 2) continue;
2502
+ let p = i.width ?? 0, m = i.height ?? 0;
2503
+ if (p <= 0 || m <= 0) continue;
2504
+ let h = [];
2505
+ for (let e = 0; e < f.length - 1; e++) {
2506
+ let t = f[e], n = f[e + 1], r = Math.abs(t.x - n.x), i = Math.abs(t.y - n.y);
2507
+ r < Q && i < Q || r >= Q && i >= Q || h.push({
2508
+ idx: e,
2509
+ length: r + i,
2510
+ orientation: r >= Q ? "horizontal" : "vertical",
2511
+ midX: (t.x + n.x) / 2,
2512
+ midY: (t.y + n.y) / 2
2513
+ });
2514
+ }
2515
+ if (h.length === 0) continue;
2516
+ let g = h.length >= 3 ? h.filter((e) => e.idx > 0 && e.idx < h.length - 1) : h, _ = g.length > 0 ? g : h, v = p >= m ? "horizontal" : "vertical", y = /* @__PURE__ */ t((e) => [...e].sort((e, t) => {
2517
+ let n = e.orientation === v;
2518
+ if (n !== (t.orientation === v)) return n ? -1 : 1;
2519
+ let r = e.length >= (e.orientation === "horizontal" ? p : m) + 2;
2520
+ return r === t.length >= (t.orientation === "horizontal" ? p : m) + 2 ? t.length - e.length : r ? -1 : 1;
2521
+ }), "rankSegments"), b = h[0], x = h[h.length - 1], S = [
2522
+ .5,
2523
+ .25,
2524
+ .75,
2525
+ .05,
2526
+ .95,
2527
+ .15,
2528
+ .85,
2529
+ .1,
2530
+ .9
2531
+ ], C = /* @__PURE__ */ t((e, t) => {
2532
+ let n = f[e.idx], r = f[e.idx + 1];
2533
+ return {
2534
+ midX: n.x + (r.x - n.x) * t,
2535
+ midY: n.y + (r.y - n.y) * t
2536
+ };
2537
+ }, "anchorAtT"), w = /* @__PURE__ */ t((e, t, n) => Math.min(n, Math.max(t, e)), "clamp"), T = /* @__PURE__ */ t((e, t) => e.midX >= t.left - Q && e.midX <= t.right + Q && e.midY >= t.top - Q && e.midY <= t.bottom + Q, "pointInsideRectInclusive"), E = /* @__PURE__ */ t((e) => {
2538
+ let t = P(e.midX, e.midY, p, m), n = u(t);
2539
+ if (n) return {
2540
+ laneId: n,
2541
+ anchor: e,
2542
+ rect: t
2543
+ };
2544
+ let r = a.find(({ rect: t }) => T(e, t));
2545
+ if (!r) return;
2546
+ let i = r.rect.left + p / 2 + 1, o = r.rect.right - p / 2 - 1, s = r.rect.top + m / 2 + 1, c = r.rect.bottom - m / 2 - 1;
2547
+ if (i > o || s > c) return;
2548
+ let l = {
2549
+ midX: w(e.midX, i, o),
2550
+ midY: w(e.midY, s, c)
2551
+ }, d = P(l.midX, l.midY, p, m);
2552
+ return T(e, d) ? {
2553
+ laneId: r.id,
2554
+ anchor: l,
2555
+ rect: d
2556
+ } : void 0;
2557
+ }, "placementForAnchor"), D = /* @__PURE__ */ t((e, t, n) => e.orientation === "horizontal" ? Math.abs(t.midX - n.x) : Math.abs(t.midY - n.y), "distanceAlongSegment"), O = /* @__PURE__ */ t((e, t) => {
2558
+ let n = (e.orientation === "horizontal" ? p / 2 : m / 2) + 12;
2559
+ if (e === b) {
2560
+ let r = f[e.idx];
2561
+ if (D(e, t, r) + Q < n) return !1;
2562
+ }
2563
+ if (e === x) {
2564
+ let r = f[e.idx + 1];
2565
+ if (D(e, t, r) + Q < n) return !1;
2566
+ }
2567
+ return !0;
2568
+ }, "labelClearsTerminalEndpoints"), k = /* @__PURE__ */ t((t) => {
2569
+ let n = y(t);
2570
+ for (let t of n) for (let n of S) {
2571
+ let i = C(t, n);
2572
+ if (!O(t, i)) continue;
2573
+ let a = E(i);
2574
+ if (a && !ct(a.rect, f) && !d(e, a.rect) && !c(e, r.id, a.rect)) return {
2575
+ laneId: a.laneId,
2576
+ anchor: a.anchor
2577
+ };
2578
+ }
2579
+ }, "tryPool"), A = /* @__PURE__ */ t((t, n, i = !1) => {
2580
+ let a = y(t);
2581
+ for (let t of a) {
2582
+ let a = {
2583
+ midX: t.midX,
2584
+ midY: t.midY
2585
+ };
2586
+ if (n && !O(t, a)) continue;
2587
+ let c = E(a);
2588
+ if (c && !ct(c.rect, f) && !d(e, c.rect) && !o(e, c.rect) && (i || !s(r.id, c.rect))) return {
2589
+ laneId: c.laneId,
2590
+ anchor: c.anchor
2591
+ };
2592
+ }
2593
+ }, "findLaneContainingFallback"), j = k(_) ?? (_.length < h.length ? k(h) : void 0) ?? A(h, !0) ?? A(h, !1) ?? A(h, !1, !0);
2594
+ if (j) {
2595
+ i.x = j.anchor.midX, i.y = j.anchor.midY, i.parentId = j.laneId;
2596
+ let t = P(j.anchor.midX, j.anchor.midY, p, m), n = l.findIndex((t) => t.labelId === e);
2597
+ n >= 0 ? l[n] = {
2598
+ labelId: e,
2599
+ rect: t
2600
+ } : l.push({
2601
+ labelId: e,
2602
+ rect: t
2603
+ });
2604
+ }
2605
+ }
2606
+ }
2607
+ t(lt, "anchorLabelsToPolyline");
2608
+ var ut = 1e-6, dt = 4, ft = 3;
2609
+ function pt(e, t) {
2610
+ return e < t ? `${e}::${t}` : `${t}::${e}`;
2611
+ }
2612
+ t(pt, "pairKey");
2613
+ function mt(e, n) {
2614
+ let { nodeInfoById: r, realNodeRects: i } = R(n), a = /* @__PURE__ */ new Map();
2615
+ for (let e of n) {
2616
+ let t = e.id;
2617
+ e.isGroup || e.isEdgeLabel && a.set(t, {
2618
+ w: e.width ?? 0,
2619
+ h: e.height ?? 0
2620
+ });
2621
+ }
2622
+ let o = /* @__PURE__ */ t((n, r, i, o) => {
2623
+ let s = pt(r, i), c = 0, l = /* @__PURE__ */ t((e) => {
2624
+ if (!e) return;
2625
+ let t = a.get(e);
2626
+ if (!t) return;
2627
+ let n = o === "x" ? t.w / 2 : t.h / 2;
2628
+ n > c && (c = n);
2629
+ }, "consider");
2630
+ l(n.labelNodeId);
2631
+ for (let t of e) {
2632
+ if (t === n || t.isLayoutOnly) continue;
2633
+ let e = t.start, r = t.end;
2634
+ e && r && pt(e, r) === s && l(t.labelNodeId);
2635
+ }
2636
+ return c > 0 ? c + ft : 0;
2637
+ }, "labelClearanceFor");
2638
+ for (let t of e) {
2639
+ if (t.isLayoutOnly) continue;
2640
+ let n = t.points;
2641
+ if (!O(n, ut)) continue;
2642
+ let a = ne(t, r, ut);
2643
+ if (!a) continue;
2644
+ let { srcId: s, dstId: c, srcInfo: l, dstInfo: u, collinearX: d, collinearY: f } = a;
2645
+ if (d === f) continue;
2646
+ let p, m;
2647
+ if (d) {
2648
+ let e = u.cy > l.cy;
2649
+ p = {
2650
+ x: l.cx,
2651
+ y: e ? l.rect.bottom : l.rect.top
2652
+ }, m = {
2653
+ x: u.cx,
2654
+ y: e ? u.rect.top : u.rect.bottom
2655
+ };
2656
+ } else {
2657
+ let e = u.cx > l.cx;
2658
+ p = {
2659
+ x: e ? l.rect.right : l.rect.left,
2660
+ y: l.cy
2661
+ }, m = {
2662
+ x: e ? u.rect.left : u.rect.right,
2663
+ y: u.cy
2664
+ };
2665
+ }
2666
+ if (B(p, m, i, [s, c], 1)) continue;
2667
+ let h = o(t, s, c, d ? "x" : "y"), g = h > dt ? h : dt, _ = [
2668
+ 0,
2669
+ g,
2670
+ -g
2671
+ ];
2672
+ for (let n of _) {
2673
+ let r = { ...p }, a = { ...m };
2674
+ if (d) {
2675
+ if (r.x += n, a.x += n, r.x <= l.rect.left || r.x >= l.rect.right || a.x <= u.rect.left || a.x >= u.rect.right) continue;
2676
+ } else if (r.y += n, a.y += n, r.y <= l.rect.top || r.y >= l.rect.bottom || a.y <= u.rect.top || a.y >= u.rect.bottom) continue;
2677
+ if (!B(r, a, i, [s, c], 1) && !ae(r, a, e, t, { epsilon: ut })) {
2678
+ t.points = [r, a];
2679
+ break;
2680
+ }
2681
+ }
2682
+ }
2683
+ }
2684
+ t(mt, "straightenCollinearSiblingDetours");
2685
+ function ht(e, n) {
2686
+ let r = .001, { realNodeRects: i, labelNodeRects: a } = z(n.values()), o = /* @__PURE__ */ t((e, t) => T(t, r).map((n) => ({
2687
+ ...n,
2688
+ edge: e,
2689
+ interior: n.index >= 1 && n.index <= t.length - 3
2690
+ })), "segmentsFor"), s = /* @__PURE__ */ t(() => {
2691
+ let t = [];
2692
+ for (let n of e) {
2693
+ if (n.isLayoutOnly) continue;
2694
+ let e = n.points;
2695
+ !e || e.length < 2 || t.push(...o(n, D(e)));
2696
+ }
2697
+ return t;
2698
+ }, "allSegments"), c = /* @__PURE__ */ t((e, t) => e.horizontal && t.horizontal ? C(e.a.x, e.b.x, t.a.x, t.b.x) >= 8 && Math.abs(e.a.y - t.a.y) < 7 : e.vertical && t.vertical ? C(e.a.y, e.b.y, t.a.y, t.b.y) >= 8 && Math.abs(e.a.x - t.a.x) < 7 : !1, "hasCrowdedParallelTrack"), l = /* @__PURE__ */ t((t, n) => {
2699
+ let s = t.start, l = t.end, u = o(t, n);
2700
+ if (u.length !== n.length - 1) return !1;
2701
+ let d = [s, l].filter((e) => !!e), f = t.labelNodeId ? [t.labelNodeId] : [];
2702
+ for (let e of u) if (B(e.a, e.b, i, d, -2) || B(e.a, e.b, a, f, -2)) return !1;
2703
+ for (let n of e) {
2704
+ if (n === t || n.isLayoutOnly) continue;
2705
+ let e = n.points;
2706
+ if (!(!e || e.length < 2)) {
2707
+ for (let t of u) for (let i of o(n, D(e))) if (c(t, i) || V(t.a, t.b, i.a, i.b, r)) return !1;
2708
+ }
2709
+ }
2710
+ return !0;
2711
+ }, "candidateIsSafe"), u = /* @__PURE__ */ t((e, t) => {
2712
+ let n = D(e.edge.points ?? []);
2713
+ if (n.length < 4 || e.index >= n.length - 1) return;
2714
+ let r = n.map((e) => ({ ...e }));
2715
+ if (e.horizontal) r[e.index].y += t, r[e.index + 1].y += t;
2716
+ else if (e.vertical) r[e.index].x += t, r[e.index + 1].x += t;
2717
+ else return;
2718
+ return o(e.edge, r).length === r.length - 1 ? r : void 0;
2719
+ }, "shiftedCandidate"), d = /* @__PURE__ */ t((e, t) => ({
2720
+ x: e.x ?? (t.left + t.right) / 2,
2721
+ y: e.y ?? (t.top + t.bottom) / 2
2722
+ }), "nodeCenter"), f = /* @__PURE__ */ t((e) => {
2723
+ let t = e.edge, r = D(t.points ?? []);
2724
+ if (r.length !== 4 || e.index !== 1) return;
2725
+ let i = t.start ? n.get(t.start) : void 0, a = t.end ? n.get(t.end) : void 0, o = i ? F(i) : void 0, s = a ? F(a) : void 0, c = r.slice(e.index + 2);
2726
+ if (i && a && o && s && c.length !== 0) return {
2727
+ sourceCenter: d(i, o),
2728
+ targetCenter: d(a, s),
2729
+ sourceRect: o,
2730
+ tail: c
2731
+ };
2732
+ }, "sourceDetourContextFor"), p = /* @__PURE__ */ t((e, t, n, i, a, o) => {
2733
+ let s = i.y >= n.y, c = s ? a.bottom : a.top, l = c + (s ? 20 : -20);
2734
+ if (s && e.b.y <= l + r || !s && e.b.y >= l - r) return;
2735
+ let u = e.a.x + t;
2736
+ return D([
2737
+ {
2738
+ x: n.x,
2739
+ y: c
2740
+ },
2741
+ {
2742
+ x: n.x,
2743
+ y: l
2744
+ },
2745
+ {
2746
+ x: u,
2747
+ y: l
2748
+ },
2749
+ {
2750
+ x: u,
2751
+ y: e.b.y
2752
+ },
2753
+ ...o
2754
+ ], r);
2755
+ }, "verticalSourceDetour"), m = /* @__PURE__ */ t((e, t, n, i, a, o) => {
2756
+ let s = i.x >= n.x, c = s ? a.right : a.left, l = c + (s ? 20 : -20);
2757
+ if (s && e.b.x <= l + r || !s && e.b.x >= l - r) return;
2758
+ let u = e.a.y + t;
2759
+ return D([
2760
+ {
2761
+ x: c,
2762
+ y: n.y
2763
+ },
2764
+ {
2765
+ x: l,
2766
+ y: n.y
2767
+ },
2768
+ {
2769
+ x: l,
2770
+ y: u
2771
+ },
2772
+ {
2773
+ x: e.b.x,
2774
+ y: u
2775
+ },
2776
+ ...o
2777
+ ], r);
2778
+ }, "horizontalSourceDetour"), h = /* @__PURE__ */ t((e, t) => {
2779
+ let n = f(e);
2780
+ if (n) {
2781
+ if (e.vertical) return p(e, t, n.sourceCenter, n.targetCenter, n.sourceRect, n.tail);
2782
+ if (e.horizontal) return m(e, t, n.sourceCenter, n.targetCenter, n.sourceRect, n.tail);
2783
+ }
2784
+ }, "sourceDetourCandidate"), g = [
2785
+ -7,
2786
+ 7,
2787
+ -14,
2788
+ 14,
2789
+ -21,
2790
+ 21
2791
+ ];
2792
+ for (let e = 0; e < 12; e++) {
2793
+ let e = s(), t = !1;
2794
+ for (let n = 0; n < e.length && !t; n++) for (let r = n + 1; r < e.length && !t; r++) {
2795
+ let i = e[n], a = e[r];
2796
+ if (i.edge === a.edge || !c(i, a)) continue;
2797
+ let o = [i, a].filter((e) => e.interior);
2798
+ for (let e of o) {
2799
+ for (let n of g) {
2800
+ let r = u(e, n);
2801
+ if (r && l(e.edge, r)) {
2802
+ e.edge.points = r, t = !0;
2803
+ break;
2804
+ }
2805
+ let i = h(e, n);
2806
+ if (i && l(e.edge, i)) {
2807
+ e.edge.points = i, t = !0;
2808
+ break;
2809
+ }
2810
+ }
2811
+ if (t) break;
2812
+ }
2813
+ }
2814
+ if (!t) return;
2815
+ }
2816
+ }
2817
+ t(ht, "nudgeSharedInteriorSubpaths");
2818
+ function gt(e, t, n, r) {
2819
+ let i = t.x - e.x, a = t.y - e.y, o = r.x - n.x, s = r.y - n.y, c = i * s - a * o;
2820
+ if (Math.abs(c) < 1e-10) return !1;
2821
+ let l = n.x - e.x, u = n.y - e.y, d = (l * s - u * o) / c, f = (l * a - u * i) / c, p = .01;
2822
+ return d > p && d < .99 && f > p && f < .99;
2823
+ }
2824
+ t(gt, "segmentsIntersect");
2825
+ function _t(t) {
2826
+ let n = t.nodes ?? [], r = t.edges ?? [], i = [];
2827
+ if (!r.length || !n.length) return i;
2828
+ let a = te(n), o = [];
2829
+ for (let e of r) {
2830
+ if (e.isLayoutOnly) continue;
2831
+ let t = e.points;
2832
+ if (!t || t.length < 2) continue;
2833
+ let n = e.start, r = e.end, s = e.labelNodeId, c = e.id ?? `${n}->${r}`;
2834
+ for (let e of a) if (e.nodeId !== n && e.nodeId !== r && !(s && e.nodeId === s)) {
2835
+ for (let n = 0; n < t.length - 1; n++) if (k(t[n], t[n + 1], e, -1)) {
2836
+ i.push({
2837
+ type: "edge-node-overlap",
2838
+ edgeId: c,
2839
+ targetId: e.nodeId,
2840
+ detail: `segment ${n} passes through node "${e.nodeId}"`
2841
+ });
2842
+ break;
2843
+ }
2844
+ }
2845
+ for (let e = 0; e < t.length - 1; e++) o.push({
2846
+ edgeId: c,
2847
+ start: n,
2848
+ end: r,
2849
+ p1: t[e],
2850
+ p2: t[e + 1]
2851
+ });
2852
+ }
2853
+ let s = /* @__PURE__ */ new Set();
2854
+ for (let e = 0; e < o.length; e++) for (let t = e + 1; t < o.length; t++) {
2855
+ let n = o[e], r = o[t];
2856
+ if (n.edgeId !== r.edgeId && n.start !== r.start && n.start !== r.end && n.end !== r.start && n.end !== r.end && gt(n.p1, n.p2, r.p1, r.p2)) {
2857
+ let e = n.edgeId < r.edgeId ? `${n.edgeId}|${r.edgeId}` : `${r.edgeId}|${n.edgeId}`;
2858
+ s.has(e) || (s.add(e), i.push({
2859
+ type: "edge-edge-crossing",
2860
+ edgeId: n.edgeId,
2861
+ targetId: r.edgeId,
2862
+ detail: `edges "${n.edgeId}" and "${r.edgeId}" cross`
2863
+ }));
2864
+ }
2865
+ }
2866
+ if (i.length > 0) {
2867
+ let t = i.filter((e) => e.type === "edge-node-overlap").length, n = i.filter((e) => e.type === "edge-edge-crossing").length;
2868
+ e.warn(`[SWIMLANE_VALIDATE] ${i.length} issue(s) detected: ${t} edge-node overlap(s), ${n} edge crossing(s)`);
2869
+ for (let t of i) e.warn(`[SWIMLANE_VALIDATE] ${t.type}: ${t.detail}`);
2870
+ }
2871
+ return i;
2872
+ }
2873
+ t(_t, "validateSwimlanesLayout");
2874
+ function vt(e, n) {
2875
+ let r = e.nodes ?? [], i = e.edges ?? [], a = r.filter((e) => !e.isGroup);
2876
+ if ((n === "LR" || n === "RL") && a.length > 0 && !Re(e, n) || n === "BT" && a.length > 0 && !Le(e)) return;
2877
+ for (let e of i) {
2878
+ if (e.isLayoutOnly) continue;
2879
+ let t = e.points;
2880
+ !t || t.length < 2 || (e.points = G(W(t)));
2881
+ }
2882
+ rt(i, r), mt(i, r), He(i, r);
2883
+ let o = /* @__PURE__ */ new Map();
2884
+ for (let e of r) o.set(String(e.id), e);
2885
+ lt(i, o), q(i, o), Ue(i, o), ht(i, o), Ke(i, o), qe(i, o), Je(i, o), Ze(i, o);
2886
+ let s = /* @__PURE__ */ t(() => {
2887
+ et(i, o), Ke(i, o), Qe(i, o), $e(i, o), lt(i, o), ke(i, o), Je(i, o), lt(i, o), ke(i, o);
2888
+ }, "finalizeRenderedEdges");
2889
+ s(), ht(i, o), s(), Ye(i, o, n), Xe(i, o, n), Ye(i, o, n), Xe(i, o, n);
2890
+ }
2891
+ t(vt, "postProcessSwimlaneLayout");
2892
+ function yt(e) {
2893
+ let t = new Map(e.nodeById), n = /* @__PURE__ */ new Set(), r = [];
2894
+ for (let i of e.edges) {
2895
+ if (!t.has(i.src) || !t.has(i.dst)) continue;
2896
+ let e = `${i.id}:${i.src}->${i.dst}`;
2897
+ n.has(e) || (n.add(e), r.push(i));
2898
+ }
2899
+ return {
2900
+ nodes: [...t.keys()],
2901
+ edges: r,
2902
+ layout: e.layout,
2903
+ nodeById: t
2904
+ };
2905
+ }
2906
+ t(yt, "normalizeGraph");
2907
+ function bt(e, t) {
2908
+ return e.edges.filter((e) => e.dst === t);
2909
+ }
2910
+ t(bt, "incoming");
2911
+ function xt(e) {
2912
+ let t = /* @__PURE__ */ new Map();
2913
+ for (let n of e.nodes) t.set(n, []);
2914
+ for (let n of e.edges) t.get(n.src).push(n.dst);
2915
+ return t;
2916
+ }
2917
+ t(xt, "buildSuccessorMap");
2918
+ function St(e) {
2919
+ let t = xt(e);
2920
+ for (let e of t.values()) e.sort((e, t) => e.localeCompare(t));
2921
+ return t;
2922
+ }
2923
+ t(St, "buildSortedSuccessorMap");
2924
+ function Ct(e) {
2925
+ let t = /* @__PURE__ */ new Map();
2926
+ for (let n of e.nodes) t.set(n, 0);
2927
+ for (let n of e.edges) t.set(n.dst, (t.get(n.dst) ?? 0) + 1);
2928
+ return t;
2929
+ }
2930
+ t(Ct, "buildInDegreeMap");
2931
+ function wt(e, n) {
2932
+ let r = [...n.entries()].filter(([, e]) => e === 0).map(([e]) => e).sort((e, t) => e.localeCompare(t)), i = new Set(e.edges.flatMap((e) => [e.src, e.dst])), a = /* @__PURE__ */ t((t) => !i.has(t) && !e.nodeById.get(t)?.isGroup, "isUnconnected"), o = [...n.keys()].filter((e) => n.get(e) === 0 && a(e)), s = 0;
2933
+ return r.map((e) => a(e) ? o[s++] : e);
2934
+ }
2935
+ t(wt, "sortedZeroInDegreeNodes");
2936
+ function Tt(e, t = () => !0) {
2937
+ let n = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map();
2938
+ for (let t of e.nodes) n.set(t, []), r.set(t, []);
2939
+ for (let i of e.edges) t(i) && (r.get(i.src).push(i.dst), n.get(i.dst).push(i.src));
2940
+ return {
2941
+ preds: n,
2942
+ succs: r
2943
+ };
2944
+ }
2945
+ t(Tt, "buildPredecessorSuccessorMaps");
2946
+ function Et(e, t, n, r) {
2947
+ let i = 0;
2948
+ for (let t of e.nodes) r?.skipGroups && e.nodeById.get(t)?.isGroup || (i = Math.max(i, n[t] ?? 0));
2949
+ let a = Array.from({ length: i + 1 }, () => []);
2950
+ for (let i of t) r?.skipGroups && e.nodeById.get(i)?.isGroup || a[Math.max(0, n[i] ?? 0)].push(i);
2951
+ return a;
2952
+ }
2953
+ t(Et, "buildLayersFromRanks");
2954
+ function Dt(e) {
2955
+ let t = Ct(e), n = wt(e, t), r = [], i = St(e);
2956
+ for (; n.length;) {
2957
+ let e = n.shift();
2958
+ r.push(e);
2959
+ for (let r of i.get(e) ?? []) if (t.set(r, (t.get(r) ?? 0) - 1), (t.get(r) ?? 0) === 0) {
2960
+ let e = 0;
2961
+ for (; e < n.length && n[e] < r;) e++;
2962
+ n.splice(e, 0, r);
2963
+ }
2964
+ }
2965
+ return r.length === e.nodes.length ? r : null;
2966
+ }
2967
+ t(Dt, "topoSortIfAcyclic");
2968
+ function Ot(e) {
2969
+ let t = /* @__PURE__ */ new Map(), n = 0;
2970
+ for (let r of e) t.set(r, n), n++;
2971
+ return t;
2972
+ }
2973
+ t(Ot, "buildLayerIndex");
2974
+ function kt(e) {
2975
+ let n = Array(e.length), r = /* @__PURE__ */ t((t, i) => {
2976
+ if (i - t <= 1) return 0;
2977
+ let a = t + i >> 1, o = r(t, a) + r(a, i), s = t, c = a, l = t;
2978
+ for (; s < a || c < i;) c >= i || s < a && e[s] <= e[c] ? n[l++] = e[s++] : (n[l++] = e[c++], o += a - s);
2979
+ for (let r = t; r < i; r++) e[r] = n[r];
2980
+ return o;
2981
+ }, "count");
2982
+ return r(0, e.length);
2983
+ }
2984
+ t(kt, "countInversions");
2985
+ function At(e) {
2986
+ let n = yt(e), r = /* @__PURE__ */ new Map();
2987
+ for (let e of n.nodes) r.set(e, []);
2988
+ for (let e of n.edges) r.get(e.src).push(e);
2989
+ for (let e of r.values()) e.sort((e, t) => e.dst === t.dst ? e.id.localeCompare(t.id) : e.dst.localeCompare(t.dst));
2990
+ let i = /* @__PURE__ */ Object.create(null);
2991
+ for (let e of n.nodes) i[e] = 0;
2992
+ let a = [], o = /* @__PURE__ */ t((e) => {
2993
+ i[e] = 1;
2994
+ for (let t of r.get(e) ?? []) {
2995
+ let e = t.dst;
2996
+ i[e] === 0 ? o(e) : i[e] === 1 && a.push(t);
2997
+ }
2998
+ i[e] = 2;
2999
+ }, "dfs"), s = Ct(n), c = [...n.nodes.filter((e) => (s.get(e) ?? 0) === 0), ...n.nodes.filter((e) => (s.get(e) ?? 0) !== 0)];
3000
+ for (let e of c) i[e] === 0 && o(e);
3001
+ let l = new Set(a.map((e) => `${e.id}:${e.src}->${e.dst}`)), u = n.edges.map((e) => l.has(`${e.id}:${e.src}->${e.dst}`) ? {
3002
+ id: e.id,
3003
+ src: e.dst,
3004
+ dst: e.src,
3005
+ weight: e.weight,
3006
+ ref: e.ref
3007
+ } : e);
3008
+ return {
3009
+ acyclic: {
3010
+ nodes: [...n.nodes],
3011
+ edges: u,
3012
+ layout: n.layout,
3013
+ nodeById: new Map(n.nodeById)
3014
+ },
3015
+ reversed: a
3016
+ };
3017
+ }
3018
+ t(At, "removeCycles_DFS");
3019
+ function jt(e) {
3020
+ let n = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ t((t) => {
3021
+ if (n.has(t)) return n.get(t);
3022
+ let i = e.nodeById.get(t);
3023
+ if (!i) return n.set(t, null), null;
3024
+ let a = i.parentId;
3025
+ if (!a) return n.set(t, null), null;
3026
+ let o = r(a) ?? a;
3027
+ return n.set(t, o), o;
3028
+ }, "resolve");
3029
+ for (let t of e.nodes) r(t);
3030
+ return n;
3031
+ }
3032
+ t(jt, "buildTopLaneMap");
3033
+ function Mt(e) {
3034
+ let t = jt(e);
3035
+ return (e) => t.get(e) ?? null;
3036
+ }
3037
+ t(Mt, "createTopLaneResolver");
3038
+ function Nt(e) {
3039
+ let t = [];
3040
+ for (let n of e.layout.nodes ?? []) n.isGroup && !n.parentId && t.push(n.id);
3041
+ return [...new Set(t)].reverse();
3042
+ }
3043
+ t(Nt, "buildTopLaneOrder");
3044
+ function Pt(e, t) {
3045
+ let n = Nt(e);
3046
+ if (!t || t.length === 0) return n;
3047
+ let r = new Set(n), i = /* @__PURE__ */ new Set(), a = [];
3048
+ for (let e of t) r.has(e) && !i.has(e) && (i.add(e), a.push(e));
3049
+ for (let e of n) i.has(e) || a.push(e);
3050
+ return a;
3051
+ }
3052
+ t(Pt, "resolveTopLaneOrder");
3053
+ var Ft = { EPSILON: 1e-6 }, It = {
3054
+ GRAVITY_ITERATIONS: 8,
3055
+ MAX_CROSSING_OPTIMIZATION_PASSES: 4,
3056
+ DEFAULT_COMPACT_SINGLE_INPUT: !0
3057
+ }, Lt = {
3058
+ DEFAULT_LAYER_GAP: 100,
3059
+ DEFAULT_NODE_GAP: 40
3060
+ };
3061
+ function Rt(e, n) {
3062
+ let r = yt(e), i = n?.laneOf ?? (() => null), a = n?.rankHint, { preds: o } = Tt(r);
3063
+ for (let e of o.values()) e.sort((e, t) => e.localeCompare(t));
3064
+ let s = Dt(r) ?? [...r.nodes].sort((e, t) => e.localeCompare(t)), c = /* @__PURE__ */ new Map();
3065
+ for (let [e, t] of s.entries()) c.set(t, e);
3066
+ let l = /* @__PURE__ */ new Map(), u = /* @__PURE__ */ new Map();
3067
+ for (let e of r.nodes) u.set(e, []);
3068
+ for (let e of s) {
3069
+ let t = (o.get(e) ?? []).filter((e) => l.has(e));
3070
+ if (t.length > 0) {
3071
+ let n = zt(e, t, {
3072
+ laneOf: i,
3073
+ rankHint: a,
3074
+ topoIndex: c
3075
+ });
3076
+ l.set(e, n), u.get(n).push(e);
3077
+ } else l.has(e) || l.set(e, null);
3078
+ }
3079
+ for (let e of r.nodes) l.has(e) || l.set(e, null);
3080
+ let d = /* @__PURE__ */ new Set();
3081
+ for (let e of r.nodes) (l.get(e) ?? null) === null && d.add(e);
3082
+ let f = [...d].sort((e, t) => {
3083
+ let n = c.get(e) ?? 0, r = c.get(t) ?? 0;
3084
+ return n === r ? e.localeCompare(t) : n - r;
3085
+ }), p = Bt(r), m = /* @__PURE__ */ new Map();
3086
+ for (let [e, t] of p.entries()) m.set(e, [...t].sort((e, t) => e.localeCompare(t)));
3087
+ let h = Vt(m), g = Ht(m), _ = /* @__PURE__ */ new Map();
3088
+ for (let e of r.nodes) _.set(e, []);
3089
+ for (let e of g) for (let t of e.nodes) {
3090
+ let n = _.get(t);
3091
+ n ? n.push(e.id) : _.set(t, [e.id]);
3092
+ }
3093
+ let v = [], y = [], b = /* @__PURE__ */ new Set(), x = /* @__PURE__ */ t((e) => {
3094
+ if (!b.has(e)) {
3095
+ b.add(e), v.push(e);
3096
+ for (let t of u.get(e) ?? []) x(t);
3097
+ y.push(e);
3098
+ }
3099
+ }, "walk");
3100
+ for (let e of f) x(e);
3101
+ for (let e of s) x(e);
3102
+ return {
3103
+ parent: l,
3104
+ children: u,
3105
+ roots: f,
3106
+ componentOf: h,
3107
+ blocks: g,
3108
+ nodeBlocks: _,
3109
+ adjacency: m,
3110
+ preorder: v,
3111
+ postorder: y,
3112
+ topologicalOrder: s
3113
+ };
3114
+ }
3115
+ t(Rt, "buildDrivingTree");
3116
+ function zt(e, t, n) {
3117
+ let r = n.laneOf(e);
3118
+ return [...t].sort((e, t) => {
3119
+ let i = n.laneOf(e), a = n.laneOf(t), o = i != null && i === r;
3120
+ if (o !== (a != null && a === r)) return o ? -1 : 1;
3121
+ let s = n.rankHint?.[e], c = n.rankHint?.[t];
3122
+ if (s != null && c != null && s !== c) return c - s;
3123
+ let l = n.topoIndex.get(e) ?? 0, u = n.topoIndex.get(t) ?? 0;
3124
+ return l === u ? e.localeCompare(t) : l - u;
3125
+ })[0];
3126
+ }
3127
+ t(zt, "chooseParent");
3128
+ function Bt(e) {
3129
+ let t = /* @__PURE__ */ new Map();
3130
+ for (let n of e.nodes) t.set(n, /* @__PURE__ */ new Set());
3131
+ for (let n of e.edges) t.get(n.src).add(n.dst), t.get(n.dst).add(n.src);
3132
+ return t;
3133
+ }
3134
+ t(Bt, "buildAdjacency");
3135
+ function Vt(e) {
3136
+ let t = /* @__PURE__ */ new Map(), n = 0;
3137
+ for (let r of e.keys()) {
3138
+ if (t.has(r)) continue;
3139
+ let i = [r];
3140
+ for (; i.length > 0;) {
3141
+ let r = i.pop();
3142
+ if (!t.has(r)) {
3143
+ t.set(r, n);
3144
+ for (let n of e.get(r) ?? []) t.has(n) || i.push(n);
3145
+ }
3146
+ }
3147
+ n++;
3148
+ }
3149
+ return t;
3150
+ }
3151
+ t(Vt, "assignComponents");
3152
+ function Ht(e) {
3153
+ let n = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map(), i = [], a = [], o = 0, s = /* @__PURE__ */ t((t, c) => {
3154
+ n.set(t, ++o), r.set(t, o);
3155
+ for (let l of e.get(t) ?? []) l !== c && (n.has(l) ? (n.get(l) ?? 0) < (n.get(t) ?? 0) && (i.push([t, l]), r.set(t, Math.min(r.get(t) ?? o, n.get(l) ?? o))) : (i.push([t, l]), s(l, t), r.set(t, Math.min(r.get(t) ?? o, r.get(l) ?? o)), (r.get(l) ?? 0) >= (n.get(t) ?? 0) && a.push(Ut(t, l, i, a.length))));
3156
+ }, "visit");
3157
+ for (let t of e.keys()) n.has(t) || s(t, null);
3158
+ return a;
3159
+ }
3160
+ t(Ht, "computeBlocks");
3161
+ function Ut(e, t, n, r) {
3162
+ let i = [], a = /* @__PURE__ */ new Set();
3163
+ for (; n.length > 0;) {
3164
+ let r = n.pop();
3165
+ if (i.push(r), a.add(r[0]), a.add(r[1]), r[0] === e && r[1] === t || r[0] === t && r[1] === e) break;
3166
+ }
3167
+ return {
3168
+ id: r,
3169
+ edges: i,
3170
+ nodes: [...a]
3171
+ };
3172
+ }
3173
+ t(Ut, "popBlock");
3174
+ function Wt(e, n, r) {
3175
+ let i = [...e.nodes], a = /* @__PURE__ */ new Map();
3176
+ for (let [e, t] of i.entries()) a.set(t, e);
3177
+ let o = i.length, s = Array(o).fill(-1), c = Array(o).fill(0), l = [], u = /* @__PURE__ */ new Set();
3178
+ for (let e of i) {
3179
+ let t = r.parent.get(e) ?? null, n = a.get(e);
3180
+ n != null && (t ?? (s[n] = -1, c[n] = 0, u.has(e) || (u.add(e), l.push(e))));
3181
+ }
3182
+ for (; l.length > 0;) {
3183
+ let e = l.shift(), t = a.get(e);
3184
+ if (t == null) continue;
3185
+ let n = r.children.get(e) ?? [];
3186
+ for (let e of n) {
3187
+ if (u.has(e)) continue;
3188
+ let n = a.get(e);
3189
+ n != null && (s[n] = t, c[n] = c[t] + 1, u.add(e), l.push(e));
3190
+ }
3191
+ }
3192
+ for (let e of i) {
3193
+ if (u.has(e)) continue;
3194
+ let t = a.get(e);
3195
+ t != null && (s[t] = -1, c[t] = 0, u.add(e));
3196
+ }
3197
+ let d = Math.max(1, Math.ceil(Math.log2(Math.max(1, o))) + 1), f = Array.from({ length: d }, () => Array(o).fill(-1));
3198
+ for (let e = 0; e < o; e++) f[0][e] = s[e];
3199
+ for (let e = 1; e < d; e++) for (let t = 0; t < o; t++) {
3200
+ let n = f[e - 1][t];
3201
+ f[e][t] = n === -1 ? -1 : f[e - 1][n];
3202
+ }
3203
+ let p = /* @__PURE__ */ t((e, t) => {
3204
+ if (e === -1 || t === -1) return -1;
3205
+ c[e] < c[t] && ([e, t] = [t, e]);
3206
+ let n = c[e] - c[t];
3207
+ for (let t = 0; t < d; t++) if (n >> t & 1 && (e = f[t][e], e === -1)) return -1;
3208
+ if (e === t) return e;
3209
+ for (let n = d - 1; n >= 0; n--) {
3210
+ let r = f[n][e], i = f[n][t];
3211
+ r !== -1 && i !== -1 && r !== i && (e = r, t = i);
3212
+ }
3213
+ return f[0][e];
3214
+ }, "lcaIndex"), m = Array.from({ length: o }, () => /* @__PURE__ */ new Map());
3215
+ for (let t of e.edges) {
3216
+ let e = t.src, r = t.dst, i = n[e], o = n[r];
3217
+ if (i == null || o == null || (i > o && ([e, r] = [r, e], [i, o] = [o, i]), i == null || o == null || i === o)) continue;
3218
+ let s = a.get(e), c = a.get(r);
3219
+ if (s == null || c == null) continue;
3220
+ let l = p(s, c);
3221
+ if (l === -1) continue;
3222
+ let u = m[l];
3223
+ for (let e = i; e < o; e++) u.set(e, (u.get(e) ?? 0) + 1);
3224
+ }
3225
+ let h = /* @__PURE__ */ new Map(), g = /* @__PURE__ */ t((e, t) => {
3226
+ if (t.size !== 0) for (let [n, r] of t) e.set(n, (e.get(n) ?? 0) + r);
3227
+ }, "mergeInto"), _ = /* @__PURE__ */ new Set(), v = /* @__PURE__ */ t((e) => {
3228
+ let t = a.get(e);
3229
+ _.add(e);
3230
+ let i = t == null ? void 0 : m[t], o = i ? new Map(i) : /* @__PURE__ */ new Map(), s = r.children.get(e) ?? [];
3231
+ for (let t of s) {
3232
+ let r = v(t), i = n[e];
3233
+ if (i != null) {
3234
+ let a = h.get(e);
3235
+ a || (a = /* @__PURE__ */ new Map(), h.set(e, a));
3236
+ let o = r.get(i) ?? 0, s = n[t];
3237
+ s != null && s > i && (o += 1), a.set(t, o);
3238
+ }
3239
+ g(o, r);
3240
+ }
3241
+ return o;
3242
+ }, "dfs");
3243
+ for (let e of r.roots) _.has(e) || v(e);
3244
+ for (let e of i) _.has(e) || v(e);
3245
+ return h;
3246
+ }
3247
+ t(Wt, "computeSubtreeCrossCounts");
3248
+ function Gt(e, n, r) {
3249
+ let i = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ t((e) => {
3250
+ let t = r[e] ?? 0, o = [...n.get(e) ?? []];
3251
+ o.sort(Kt(r));
3252
+ for (let e of o) {
3253
+ a(e);
3254
+ let n = i.get(e);
3255
+ n != null && (t = Math.min(t, n));
3256
+ }
3257
+ i.set(e, t);
3258
+ }, "annotate");
3259
+ for (let t of e) a(t);
3260
+ return i;
3261
+ }
3262
+ t(Gt, "annotateMinimumLayers");
3263
+ function Kt(e) {
3264
+ return (t, n) => {
3265
+ let r = e[t] ?? 0, i = e[n] ?? 0;
3266
+ return r === i ? t.localeCompare(n) : r - i;
3267
+ };
3268
+ }
3269
+ t(Kt, "compareByRankThenId");
3270
+ function qt(e, n, r, i) {
3271
+ let a = 0;
3272
+ for (let e of n) {
3273
+ let t = r[e] ?? 0;
3274
+ t > a && (a = t);
3275
+ }
3276
+ let o = Array.from({ length: a + 1 }, () => []), s = /* @__PURE__ */ new Set(), c = /* @__PURE__ */ t((e) => {
3277
+ if (s.has(e)) return;
3278
+ s.add(e);
3279
+ let t = r[e] ?? 0;
3280
+ o[t] || (o[t] = []), o[t].push(e);
3281
+ for (let t of i(e)) c(t);
3282
+ }, "emit");
3283
+ for (let t of e) c(t);
3284
+ for (let e of n) if (!s.has(e)) {
3285
+ let t = r[e] ?? 0;
3286
+ o[t] || (o[t] = []), o[t].push(e), s.add(e);
3287
+ }
3288
+ return o;
3289
+ }
3290
+ t(qt, "emitNodesInTreeOrder");
3291
+ function Jt(e) {
3292
+ let t = [];
3293
+ for (let n of e) {
3294
+ let e = /* @__PURE__ */ new Set(), r = [];
3295
+ for (let t of n) e.has(t) || (e.add(t), r.push(t));
3296
+ t.push(r);
3297
+ }
3298
+ return t;
3299
+ }
3300
+ t(Jt, "deduplicateLayers");
3301
+ function Yt(e, t, n, r) {
3302
+ return (i) => {
3303
+ let a = e.get(i) ?? [];
3304
+ if (a.length === 0) return [];
3305
+ let o = t[i] ?? 0, s = [], c = [], l = n.get(i);
3306
+ for (let e of a) {
3307
+ let t = r.get(e) ?? o;
3308
+ t > o ? s.push({
3309
+ child: e,
3310
+ min: t
3311
+ }) : c.push(e);
3312
+ }
3313
+ return s.sort((e, t) => e.min === t.min ? e.child.localeCompare(t.child) : e.min - t.min), c.sort((e, t) => {
3314
+ let n = l?.get(e) ?? 0, i = l?.get(t) ?? 0;
3315
+ if (n !== i) return n - i;
3316
+ let a = r.get(e) ?? o, s = r.get(t) ?? o;
3317
+ return a === s ? e.localeCompare(t) : a - s;
3318
+ }), [...s.map((e) => e.child), ...c];
3319
+ };
3320
+ }
3321
+ t(Yt, "createChildOrderer");
3322
+ function Xt(e, t, n) {
3323
+ let r = Rt(e, {
3324
+ rankHint: t,
3325
+ laneOf: n
3326
+ }), { children: i, roots: a } = r;
3327
+ for (let t of e.nodes) i.has(t) || i.set(t, []);
3328
+ let o = Wt(e, t, r), s = [...a].sort(Kt(t)), c = Yt(i, t, o, Gt(s, i, t)), l = qt(s, e.nodes, t, c);
3329
+ return l = Jt(l), l;
3330
+ }
3331
+ t(Xt, "buildMultitreeLayerOrder");
3332
+ function Zt(e, t, n) {
3333
+ let r = new Set(e), i = new Set(t), a = Ot(t), o = [];
3334
+ for (let e of n) r.has(e.src) && i.has(e.dst) && o.push(a.get(e.dst));
3335
+ return kt(o);
3336
+ }
3337
+ t(Zt, "countCrossingsBetweenAdjacent");
3338
+ function Qt(e, t, n) {
3339
+ let r = [];
3340
+ for (let e of t) {
3341
+ let t = n[e.src], i = n[e.dst];
3342
+ if (t == null || i == null || t === i) continue;
3343
+ let a = e.src, o = e.dst, s = t, c = i;
3344
+ t > i && (a = e.dst, o = e.src, s = i, c = t);
3345
+ for (let t = s; t < c; t++) r.push({
3346
+ id: `${e.id}@${t}`,
3347
+ src: a,
3348
+ dst: o,
3349
+ ref: e.ref
3350
+ });
3351
+ }
3352
+ let i = 0;
3353
+ for (let t = 0; t + 1 < e.length; t++) i += Zt(e[t], e[t + 1], r);
3354
+ return i;
3355
+ }
3356
+ t(Qt, "totalCrossings");
3357
+ function $t(e, t) {
3358
+ let n = { ...t }, { preds: r } = Tt(e), i = Mt(e), a = Qt(Xt(e, n, i), e.edges, n), o = It.MAX_CROSSING_OPTIMIZATION_PASSES;
3359
+ for (let t = 0; t < o; t++) {
3360
+ let t = !1, o = [...e.nodes].sort((e, t) => (n[t] ?? 0) - (n[e] ?? 0));
3361
+ for (let s of o) {
3362
+ let o = n[s] ?? 0;
3363
+ if (o === 0) continue;
3364
+ let c = 0;
3365
+ for (let e of r.get(s) ?? []) c = Math.max(c, (n[e] ?? 0) + 1);
3366
+ if (c >= o) continue;
3367
+ let l = o;
3368
+ n[s] = c;
3369
+ let u = Qt(Xt(e, n, i), e.edges, n);
3370
+ u < a ? (a = u, t = !0) : n[s] = l;
3371
+ }
3372
+ if (!t) break;
3373
+ }
3374
+ return n;
3375
+ }
3376
+ t($t, "optimizeRanksByCrossings");
3377
+ function en(e, t) {
3378
+ let n = Mt(e), r = [...e.nodes].sort((e, n) => (t[e] ?? 0) - (t[n] ?? 0) || e.localeCompare(n));
3379
+ for (let i of r) {
3380
+ let r = n(i);
3381
+ if (!r) continue;
3382
+ let a = e.edges.filter((e) => e.src === i);
3383
+ if (a.length === 0) continue;
3384
+ let o = !1, s = 0;
3385
+ for (let e of a) {
3386
+ let t = n(e.dst);
3387
+ t == null || t === r ? o = !0 : s++;
3388
+ }
3389
+ if (s === 0 || o) continue;
3390
+ let c = 0, l = !1;
3391
+ for (let t of e.edges) {
3392
+ if (t.dst !== i) continue;
3393
+ let e = n(t.src);
3394
+ e && (e === r ? l = !0 : c++);
3395
+ }
3396
+ if (c > 0 || !l) continue;
3397
+ let u = t[i] ?? 0, d = u + s, f = 0;
3398
+ for (let n of e.edges) n.dst === i && (f = Math.max(f, (t[n.src] ?? 0) + 1));
3399
+ let p = Math.max(u, f, d);
3400
+ p !== u && (t[i] = p);
3401
+ }
3402
+ }
3403
+ t(en, "adjustCrossLaneSources");
3404
+ function tn(e, t) {
3405
+ let n = yt(e), r = Dt(n) ?? [...n.nodes].sort(), i = t?.compactSingleInput ?? !1, a = Mt(n), o = /* @__PURE__ */ Object.create(null);
3406
+ for (let e of r) {
3407
+ let r = bt(n, e), s = t?.ignoreCrossLaneEdges ? r.filter((t) => {
3408
+ let n = a(t.src), r = a(e);
3409
+ return !n || !r || n === r;
3410
+ }) : r;
3411
+ if (s.length === 0) o[e] = 0;
3412
+ else if (i && s.length === 1) {
3413
+ let t = s[0].src;
3414
+ a(t) === a(e) ? o[e] = (o[t] ?? 0) + 1 : o[e] = o[t] ?? 0;
3415
+ } else {
3416
+ let t = -Infinity;
3417
+ for (let e of s) t = Math.max(t, (o[e.src] ?? 0) + 1);
3418
+ o[e] = t === -Infinity ? 0 : t;
3419
+ }
3420
+ }
3421
+ return (t?.optimizeRanksByCrossings ?? !1) && (o = $t(n, o)), t?.ignoreCrossLaneEdges && en(n, o), {
3422
+ layers: Xt(n, o, a),
3423
+ rankOf: o,
3424
+ dummy: /* @__PURE__ */ new Set()
3425
+ };
3426
+ }
3427
+ t(tn, "assignLayers_LongestPath");
3428
+ function nn(e, n) {
3429
+ let r = yt(e), i = { ...tn(r, {
3430
+ compactSingleInput: n?.compactSingleInput,
3431
+ ignoreCrossLaneEdges: n?.ignoreCrossLaneEdges,
3432
+ optimizeRanksByCrossings: n?.optimizeRanksByCrossings
3433
+ }).rankOf }, a = Mt(r), { preds: o, succs: s } = Tt(r, (e) => {
3434
+ if (n?.ignoreCrossLaneEdges) {
3435
+ let t = a(e.src), n = a(e.dst);
3436
+ if (t && n && t !== n) return !1;
3437
+ }
3438
+ return !0;
3439
+ }), c = Dt(r) ?? [...r.nodes], l = [...c].reverse(), u = /* @__PURE__ */ t((e, t) => {
3440
+ let n = 0;
3441
+ for (let t of o.get(e) ?? []) n = Math.max(n, (i[t] ?? 0) + 1);
3442
+ let r = Infinity, a = s.get(e) ?? [];
3443
+ return a.length > 0 && (r = Math.min(...a.map((e) => (i[e] ?? 0) - 1))), Number.isFinite(r) || (r = Math.max(n, t)), Math.min(Math.max(t, n), r);
3444
+ }, "clampFeasible"), d = It.GRAVITY_ITERATIONS, f = /* @__PURE__ */ t((e) => {
3445
+ let t = !1;
3446
+ for (let n of e) {
3447
+ let e = o.get(n) ?? [], r = s.get(n) ?? [];
3448
+ if (e.length === 0 && r.length === 0) continue;
3449
+ let a = e.length > 0 ? e.reduce((e, t) => e + (i[t] ?? 0) + 1, 0) / e.length : i[n] ?? 0, c = r.length > 0 ? r.reduce((e, t) => e + (i[t] ?? 0) - 1, 0) / r.length : i[n] ?? 0, l = Math.round((a + c) / 2), d = u(n, l);
3450
+ d !== i[n] && (i[n] = d, t = !0);
3451
+ }
3452
+ return t;
3453
+ }, "relaxOrder");
3454
+ for (let e = 0; e < d; e++) {
3455
+ let e = f(c), t = f(l);
3456
+ if (!e && !t) break;
3457
+ }
3458
+ for (let e of c) {
3459
+ let t = 0;
3460
+ for (let n of o.get(e) ?? []) t = Math.max(t, (i[n] ?? 0) + 1);
3461
+ (i[e] ?? 0) < t && (i[e] = t);
3462
+ }
3463
+ for (let e of l) {
3464
+ let t = s.get(e) ?? [];
3465
+ if (t.length > 0) {
3466
+ let n = Math.min(...t.map((e) => (i[e] ?? 0) - 1));
3467
+ (i[e] ?? 0) > n && (i[e] = n);
3468
+ }
3469
+ }
3470
+ return {
3471
+ layers: Et(r, c, i),
3472
+ rankOf: i,
3473
+ dummy: /* @__PURE__ */ new Set()
3474
+ };
3475
+ }
3476
+ t(nn, "assignLayers_Gravity");
3477
+ function rn(e) {
3478
+ let t = Ct(e), n = St(e), r = wt(e, t), i = [];
3479
+ for (; r.length > 0;) {
3480
+ let e = [];
3481
+ for (let a of r) {
3482
+ i.push(a);
3483
+ for (let r of n.get(a) ?? []) t.set(r, (t.get(r) ?? 0) - 1), (t.get(r) ?? 0) === 0 && e.push(r);
3484
+ }
3485
+ r = e.sort((e, t) => e.localeCompare(t));
3486
+ }
3487
+ return i.length === e.nodes.length ? i : null;
3488
+ }
3489
+ t(rn, "topoSortByGenerationIfAcyclic");
3490
+ function an(e, n) {
3491
+ let r = yt(e), i = n?.direction === "LR" ? rn(r) ?? [...r.nodes].sort() : Dt(r) ?? [...r.nodes].sort(), a = Mt(r), o = /* @__PURE__ */ t((e) => a(e) ?? e, "laneOf"), s = /* @__PURE__ */ Object.create(null), c = /* @__PURE__ */ new Map(), l = /* @__PURE__ */ t((e, t) => n?.ignoreCrossLaneEdges ?? !0 ? +(o(e) === o(t)) : 1, "edgeWeight");
3492
+ for (let e of i) {
3493
+ if (r.nodeById.get(e)?.isGroup) continue;
3494
+ let t = bt(r, e), n = 0;
3495
+ if (t.length > 0) for (let r of t) {
3496
+ let t = r.src, i = s[t] ?? 0;
3497
+ n = Math.max(n, i + l(t, e));
3498
+ }
3499
+ let i = o(e), a = c.get(i) ?? 0, u = Math.max(n, a);
3500
+ s[e] = u, c.set(i, u + 1);
3501
+ }
3502
+ return {
3503
+ layers: Et(r, i, s, { skipGroups: !0 }),
3504
+ rankOf: s,
3505
+ dummy: /* @__PURE__ */ new Set()
3506
+ };
3507
+ }
3508
+ t(an, "assignLayers_LaneAwareCompact");
3509
+ function on(e, n) {
3510
+ let r = yt(n), { rankOf: i } = e, a = e.layers.map((e) => [...e]), o = new Set(e.dummy ? [...e.dummy] : []), s = 0, c = new Map(r.nodeById), l = /* @__PURE__ */ t((e) => {
3511
+ let t = `placeholder-${s++}`, n = {
3512
+ id: t,
3513
+ isGroup: !1,
3514
+ isDummy: !0,
3515
+ width: 0,
3516
+ height: 0
3517
+ };
3518
+ for (c.set(t, n), o.add(t); a.length <= e;) a.push([]);
3519
+ return a[e].push(t), i[t] = e, t;
3520
+ }, "addDummyAt"), u = [...r.edges].sort((e, t) => e.id === t.id ? e.src === t.src ? e.dst.localeCompare(t.dst) : e.src.localeCompare(t.src) : e.id.localeCompare(t.id)), d = [];
3521
+ for (let e of u) {
3522
+ let t = i[e.src] ?? 0, n = i[e.dst] ?? 0;
3523
+ if (n - t <= 1) {
3524
+ d.push(e);
3525
+ continue;
3526
+ }
3527
+ let r = e.src;
3528
+ for (let i = t + 1, a = 0; i < n; i++, a++) {
3529
+ let t = l(i);
3530
+ d.push({
3531
+ id: `${e.id}#${a}`,
3532
+ src: r,
3533
+ dst: t,
3534
+ weight: e.weight,
3535
+ ref: e.ref
3536
+ }), r = t;
3537
+ }
3538
+ let a = n - t - 2;
3539
+ d.push({
3540
+ id: `${e.id}#${Math.max(a + 1, 0)}`,
3541
+ src: r,
3542
+ dst: e.dst,
3543
+ weight: e.weight,
3544
+ ref: e.ref
3545
+ });
3546
+ }
3547
+ let f = {
3548
+ nodes: [...r.nodes, ...[...o].filter((e) => !r.nodes.includes(e))],
3549
+ edges: d,
3550
+ layout: r.layout,
3551
+ nodeById: c
3552
+ };
3553
+ return {
3554
+ layering: {
3555
+ layers: a,
3556
+ rankOf: i,
3557
+ dummy: o
3558
+ },
3559
+ graphWithDummies: f
3560
+ };
3561
+ }
3562
+ t(on, "makeProperLayering");
3563
+ function sn(e) {
3564
+ let t = e.length;
3565
+ if (t === 0) return Infinity;
3566
+ let n = [...e].sort((e, t) => e - t);
3567
+ return t % 2 == 1 ? n[(t - 1) / 2] : .5 * (n[t / 2 - 1] + n[t / 2]);
3568
+ }
3569
+ t(sn, "median");
3570
+ function cn(e) {
3571
+ return e.length === 0 ? Infinity : e.reduce((e, t) => e + t, 0) / e.length;
3572
+ }
3573
+ t(cn, "barycenter");
3574
+ function ln(e, t, n, r) {
3575
+ let i = /* @__PURE__ */ new Map();
3576
+ for (let t of e) i.set(t, []);
3577
+ for (let e of n) r === "down" ? t.has(e.src) && i.has(e.dst) && i.get(e.dst).push(t.get(e.src)) : t.has(e.dst) && i.has(e.src) && i.get(e.src).push(t.get(e.dst));
3578
+ return i;
3579
+ }
3580
+ t(ln, "neighborPositionsFor");
3581
+ function un(e, t, n) {
3582
+ let r = n.get(e) ?? 0, i = n.get(t) ?? 0;
3583
+ return r === i ? e.localeCompare(t) : r - i;
3584
+ }
3585
+ t(un, "currentOrderTieBreak");
3586
+ function dn(e, t, n) {
3587
+ let r = new Set(e), i = new Set(t), a = Ot(e), o = Ot(t), s = [];
3588
+ for (let e of n) r.has(e.src) && i.has(e.dst) && s.push({
3589
+ u: a.get(e.src),
3590
+ v: o.get(e.dst)
3591
+ });
3592
+ return s.sort((e, t) => e.u === t.u ? e.v - t.v : e.u - t.u), kt(s.map((e) => e.v));
3593
+ }
3594
+ t(dn, "countCrossingsBetweenAdjacent");
3595
+ function fn(e, t, n) {
3596
+ return [...e].sort((e, r) => {
3597
+ let i = sn(t.get(e) ?? []), a = sn(t.get(r) ?? []);
3598
+ return i === a ? un(e, r, n) : isFinite(i) ? isFinite(a) ? i - a : -1 : 1;
3599
+ });
3600
+ }
3601
+ t(fn, "sortByHeuristic");
3602
+ function pn(e, t, n, r, i, a) {
3603
+ let o = Ot(e), s = Ot(t), c = ln(t, o, n, r);
3604
+ if (!i || !a || a.length === 0) return fn(t, c, s);
3605
+ let l = /* @__PURE__ */ new Map();
3606
+ for (let e of t) {
3607
+ let t = i(e), n = l.get(t) ?? [];
3608
+ n.push(e), l.set(t, n);
3609
+ }
3610
+ let u = [];
3611
+ for (let e of a) {
3612
+ let t = l.get(e);
3613
+ if (!t || t.length === 0) continue;
3614
+ let n = fn(t, c, s);
3615
+ u.push(...n);
3616
+ }
3617
+ let d = l.get(null);
3618
+ if (d && d.length > 0) {
3619
+ let e = fn(d, c, s);
3620
+ for (let t of e) {
3621
+ let e = cn(c.get(t) ?? []), n = u.length;
3622
+ if (isFinite(e)) {
3623
+ for (let [t, r] of u.entries()) if (e < cn(c.get(r) ?? [])) {
3624
+ n = t;
3625
+ break;
3626
+ }
3627
+ }
3628
+ u.splice(n, 0, t);
3629
+ }
3630
+ }
3631
+ return u;
3632
+ }
3633
+ t(pn, "reorderLayer");
3634
+ function mn(e, n, r, i, a) {
3635
+ let o = [...n], s = new Set(e), c = new Set(n), l = i ? new Set(i) : null, u = r.filter((e) => s.has(e.src) && c.has(e.dst)), d = l ? r.filter((e) => c.has(e.src) && l.has(e.dst)) : void 0, f = /* @__PURE__ */ t((t) => {
3636
+ let n = dn(e, t, u);
3637
+ return d && i && (n += dn(t, i, d)), n;
3638
+ }, "crossingScore"), p = a ? /* @__PURE__ */ new Map() : null;
3639
+ if (a && p) for (let e of n) p.set(e, a(e));
3640
+ let m = !0, h = f(o);
3641
+ for (; m;) {
3642
+ m = !1;
3643
+ for (let e = 0; e + 1 < o.length; e++) {
3644
+ if (p && p.get(o[e]) !== p.get(o[e + 1])) continue;
3645
+ let t = h;
3646
+ [o[e], o[e + 1]] = [o[e + 1], o[e]];
3647
+ let n = f(o);
3648
+ n < t ? (h = n, m = !0) : [o[e], o[e + 1]] = [o[e + 1], o[e]];
3649
+ }
3650
+ }
3651
+ return o;
3652
+ }
3653
+ t(mn, "transposeImprove");
3654
+ function hn(e, t, n) {
3655
+ let r = e.layers.map((e) => [...e]), i = t.edges, a = Mt(t), o = Pt(t, n?.laneOrder);
3656
+ for (let e = 0; e < 3; e++) {
3657
+ for (let e = 1; e < r.length; e++) r[e] = pn(r[e - 1], r[e], i, "down", a, o), r[e] = mn(r[e - 1], r[e], i, r[e + 1], a);
3658
+ for (let e = r.length - 2; e >= 0; e--) r[e] = pn(r[e + 1], r[e], i, "up", a, o), r[e] = mn(r[e + 1], r[e], i, r[e - 1], a);
3659
+ }
3660
+ return { layers: r };
3661
+ }
3662
+ t(hn, "orderLayers");
3663
+ function gn(e, n, r) {
3664
+ let i = r?.layerGap ?? Lt.DEFAULT_LAYER_GAP, a = r?.nodeGap ?? Lt.DEFAULT_NODE_GAP, o = r?.laneGap ?? a * 2, s = r?.direction ?? "TB", c = s === "LR" || s === "RL", l = e.layers, u = /* @__PURE__ */ Object.create(null), d = /* @__PURE__ */ Object.create(null), f = /* @__PURE__ */ t((e) => n.nodeById.get(e), "getNode"), p = /* @__PURE__ */ t((e) => f(e)?.width ?? 0, "getWidth"), m = /* @__PURE__ */ t((e) => f(e)?.height ?? 0, "getHeight"), h = Mt(n), g = Pt(n, r?.laneOrder), _ = l.map((e) => e.reduce((e, t) => Math.max(e, m(t)), 0)), v = [];
3665
+ if (c) for (let e = 0; e + 1 < l.length; e++) {
3666
+ let t = l[e].reduce((e, t) => Math.max(e, p(t)), 0), n = l[e + 1].reduce((e, t) => Math.max(e, p(t)), 0), r = _[e], a = _[e + 1], o = r / 2 + a / 2, s = (t + n) / 2, c = Math.max(0, s - o - i);
3667
+ v.push(c);
3668
+ }
3669
+ let y = /* @__PURE__ */ new Set();
3670
+ for (let e of l) for (let t of e) y.add(h(t));
3671
+ let b = y.has(null), x = g.filter((e) => y.has(e)), S = [...b ? [null] : [], ...x], C = /* @__PURE__ */ Object.create(null);
3672
+ for (let e of x) C[e] = 0;
3673
+ b && (C.null = 0);
3674
+ for (let e of l) {
3675
+ let t = /* @__PURE__ */ Object.create(null), n = [];
3676
+ for (let r of e) {
3677
+ let e = h(r);
3678
+ e === null ? n.push(r) : (t[e] ||= []).push(r);
3679
+ }
3680
+ for (let [e, n] of Object.entries(t)) {
3681
+ let t = n.reduce((e, t) => e + p(t), 0) + a * Math.max(0, n.length - 1);
3682
+ C[e] = Math.max(C[e] ?? 0, t);
3683
+ }
3684
+ if (b && n.length) {
3685
+ let e = n.reduce((e, t) => e + p(t), 0) + a * Math.max(0, n.length - 1);
3686
+ C.null = Math.max(C.null ?? 0, e);
3687
+ }
3688
+ }
3689
+ let w = /* @__PURE__ */ new Map();
3690
+ {
3691
+ let e = S.map((e) => (e === null ? C.null : C[e]) ?? 0), t = -(e.reduce((e, t) => e + t, 0) + o * Math.max(0, S.length - 1)) / 2;
3692
+ for (let n = 0; n < S.length; n++) {
3693
+ let r = S[n], i = e[n] ?? 0, a = t + i / 2;
3694
+ w.set(r, a), t += i, n < S.length - 1 && (t += o);
3695
+ }
3696
+ }
3697
+ let T = 0;
3698
+ for (let [e, t] of l.entries()) {
3699
+ let n = _[e] ?? 0, r = /* @__PURE__ */ new Map();
3700
+ for (let e of t) {
3701
+ let t = h(e), n = r.get(t) ?? [];
3702
+ n.push(e), r.set(t, n);
3703
+ }
3704
+ for (let e of S) {
3705
+ let t = r.get(e) ?? [];
3706
+ if (t.length === 0) continue;
3707
+ let i = w.get(e);
3708
+ if (t.length === 1) {
3709
+ let e = t[0];
3710
+ u[e] = i, d[e] = T + n / 2;
3711
+ } else {
3712
+ let e = t.map((e) => p(e)), r = i - (e.reduce((e, t) => e + t, 0) + a * (t.length - 1)) / 2;
3713
+ for (let [i, o] of t.entries()) {
3714
+ let t = e[i];
3715
+ u[o] = r + t / 2, d[o] = T + n / 2, r += t + a;
3716
+ }
3717
+ }
3718
+ }
3719
+ let o = v[e] ?? 0;
3720
+ T += n + i + o;
3721
+ }
3722
+ let E = /* @__PURE__ */ new Map();
3723
+ for (let e of n.edges) {
3724
+ let t = e.ref.id;
3725
+ E.has(t) || E.set(t, []), E.get(t).push(e);
3726
+ }
3727
+ for (let [, e] of E) {
3728
+ if (e.length === 0) continue;
3729
+ let t = e[0].ref, r = t.start, i = t.end;
3730
+ if (r == null || i == null) continue;
3731
+ let a = Math.round(((u[r] ?? 0) + (u[i] ?? 0)) / 2), o = /* @__PURE__ */ new Set();
3732
+ for (let t of e) o.add(t.src), o.add(t.dst);
3733
+ for (let e of o) e !== r && e !== i && n.nodeById.get(e)?.isDummy && (u[e] = a);
3734
+ }
3735
+ return {
3736
+ x: u,
3737
+ y: d
3738
+ };
3739
+ }
3740
+ t(gn, "assignCoordinates");
3741
+ var _n = 8;
3742
+ function vn(e) {
3743
+ let t = 2166136261;
3744
+ for (let n = 0; n < e.length; n++) t ^= e.charCodeAt(n), t = Math.imul(t, 16777619);
3745
+ return t >>> 0;
3746
+ }
3747
+ t(vn, "hashString");
3748
+ function yn(e) {
3749
+ let t = e >>> 0;
3750
+ return () => {
3751
+ t += 1831565813;
3752
+ let e = t;
3753
+ return e = Math.imul(e ^ e >>> 15, e | 1), e ^= e + Math.imul(e ^ e >>> 7, e | 61), ((e ^ e >>> 14) >>> 0) / 4294967296;
3754
+ };
3755
+ }
3756
+ t(yn, "mulberry32");
3757
+ function bn(e, t) {
3758
+ let n = [...e], r = yn(t);
3759
+ for (let e = n.length - 1; e > 0; e--) {
3760
+ let t = Math.floor(r() * (e + 1));
3761
+ [n[e], n[t]] = [n[t], n[e]];
3762
+ }
3763
+ return n;
3764
+ }
3765
+ t(bn, "deterministicShuffle");
3766
+ function xn(e, t) {
3767
+ let n = 0;
3768
+ for (let [r, i] of e.entries()) n += Math.abs(r - (t.get(i) ?? r));
3769
+ return n;
3770
+ }
3771
+ t(xn, "sourceDistance");
3772
+ function Sn(e, t) {
3773
+ let n = /* @__PURE__ */ new Map();
3774
+ for (let [t, r] of e.entries()) n.set(r, t);
3775
+ let r = 0;
3776
+ for (let { a: e, b: i, weight: a } of t) {
3777
+ let t = n.get(e), o = n.get(i);
3778
+ t != null && o != null && (r += a * Math.abs(t - o));
3779
+ }
3780
+ return r;
3781
+ }
3782
+ t(Sn, "laneArrangementCost");
3783
+ function Cn(e) {
3784
+ let t = Nt(e);
3785
+ if (t.length < 2) return [];
3786
+ let n = new Map(t.map((e, t) => [e, t])), r = Mt(e), i = /* @__PURE__ */ new Map();
3787
+ for (let t of e.layout.edges ?? []) {
3788
+ if (t.isLayoutOnly) continue;
3789
+ let a = typeof t.start == "string" ? t.start : void 0, o = typeof t.end == "string" ? t.end : void 0;
3790
+ if (!a || !o || !e.nodeById.has(a) || !e.nodeById.has(o)) continue;
3791
+ let s = r(a), c = r(o);
3792
+ if (!s || !c || s === c) continue;
3793
+ let l = n.get(s), u = n.get(c);
3794
+ if (l == null || u == null) continue;
3795
+ let [d, f] = l <= u ? [s, c] : [c, s], p = `${d}\0${f}`, m = i.get(p);
3796
+ m ? m.weight++ : i.set(p, {
3797
+ a: d,
3798
+ b: f,
3799
+ weight: 1
3800
+ });
3801
+ }
3802
+ return [...i.values()];
3803
+ }
3804
+ t(Cn, "buildWeightedLaneEdges");
3805
+ function wn(e, t, n) {
3806
+ let r = [...e], i = Sn(r, t), a = !0, o = 0, s = Math.max(1, r.length);
3807
+ for (; a && o < s;) {
3808
+ a = !1, o++;
3809
+ for (let e = 0; e + 1 < r.length; e++) {
3810
+ [r[e], r[e + 1]] = [r[e + 1], r[e]];
3811
+ let n = Sn(r, t);
3812
+ n < i ? (i = n, a = !0) : [r[e], r[e + 1]] = [r[e + 1], r[e]];
3813
+ }
3814
+ }
3815
+ return {
3816
+ order: r,
3817
+ cost: i,
3818
+ sourceDistance: xn(r, n)
3819
+ };
3820
+ }
3821
+ t(wn, "greedySwitch");
3822
+ function Tn(e, t) {
3823
+ return e.cost === t.cost ? e.sourceDistance < t.sourceDistance : e.cost < t.cost;
3824
+ }
3825
+ t(Tn, "isBetterCandidate");
3826
+ function En(e, t, n) {
3827
+ let r = [...t].sort((e, t) => e.a === t.a ? e.b.localeCompare(t.b) : e.a.localeCompare(t.a)).map(({ a: e, b: t, weight: n }) => `${e}:${t}:${n}`).join("|");
3828
+ return vn(`${e.join("|")}#${r}#${n}`);
3829
+ }
3830
+ t(En, "seedForRestart");
3831
+ function Dn(e, t = {}) {
3832
+ let n = Nt(e);
3833
+ if (n.length < 2) return n;
3834
+ let r = Cn(e);
3835
+ if (r.length === 0) return n;
3836
+ let i = new Map(n.map((e, t) => [e, t])), a = wn(n, r, i), o = Math.max(0, t.restarts ?? _n);
3837
+ for (let e = 0; e < o; e++) {
3838
+ let t = wn(bn(n, En(n, r, e)), r, i);
3839
+ Tn(t, a) && (a = t);
3840
+ }
3841
+ return a.order;
3842
+ }
3843
+ t(Dn, "optimizeTopLaneOrder");
3844
+ function On(e, t) {
3845
+ let n = t?.ignoreCrossLaneEdges ?? !0, r = t?.optimizeRanksByCrossings ?? !0, i = yt(e), a = t?.automaticLaneOrdering ? Dn(i, { restarts: _n }) : void 0, o = At(i), s = o.acyclic, { layering: c, graphWithDummies: l } = on(n ? an(s, {
3846
+ compactSingleInput: t?.compactSingleInput ?? It.DEFAULT_COMPACT_SINGLE_INPUT,
3847
+ ignoreCrossLaneEdges: !0,
3848
+ direction: t?.direction
3849
+ }) : nn(s, {
3850
+ compactSingleInput: t?.compactSingleInput ?? It.DEFAULT_COMPACT_SINGLE_INPUT,
3851
+ ignoreCrossLaneEdges: !1,
3852
+ optimizeRanksByCrossings: r
3853
+ }), s), u = hn(c, l, { laneOrder: a }), d = gn(u, l, {
3854
+ layerGap: t?.layerGap,
3855
+ nodeGap: t?.nodeGap,
3856
+ direction: t?.direction,
3857
+ laneOrder: a
3858
+ });
3859
+ return {
3860
+ acyclic: s,
3861
+ reversed: o.reversed,
3862
+ layering: c,
3863
+ ordered: u,
3864
+ coordinates: d
3865
+ };
3866
+ }
3867
+ t(On, "sugiyamaLayout");
3868
+ var $ = Ft.EPSILON, kn = 8, An = 15, jn = 15, Mn = 25, Nn = 20, Pn = 10;
3869
+ function Fn(e, t, n) {
3870
+ let r = e.x ?? 0, i = e.y ?? 0, a = t.x - r, o = t.y - i, s = Math.abs(a), c = Math.abs(o);
3871
+ return s < $ && c < $ ? n : c > $ && c * 3 >= s ? o > 0 ? "bottom" : "top" : s > $ ? a > 0 ? "right" : "left" : n;
3872
+ }
3873
+ t(Fn, "chooseOrthogonalSide");
3874
+ function In(e, t) {
3875
+ return Math.abs(e.to - t.from) < $ || Math.abs(e.to - t.to) < $ ? e.to : e.from;
3876
+ }
3877
+ t(In, "sharedLineEndpointCoord");
3878
+ function Ln(e, t) {
3879
+ return e.orient === "vertical" ? {
3880
+ x: e.coord,
3881
+ y: t
3882
+ } : {
3883
+ x: t,
3884
+ y: e.coord
3885
+ };
3886
+ }
3887
+ t(Ln, "pointOnLine");
3888
+ function Rn(e, n) {
3889
+ let r = e.nodes ?? [], i = e.edges ?? [], a = [];
3890
+ for (let e of i) e.isLayoutOnly || a.push({
3891
+ ...e,
3892
+ __originalEdge: e
3893
+ });
3894
+ let o = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map(), c = [], l = n === "LR";
3895
+ for (let e of r) o.set(e.id, e);
3896
+ let u = r.filter((e) => e.isGroup && !e.parentId);
3897
+ for (let e of u) {
3898
+ let n = { id: e.id }, i = /* @__PURE__ */ t((e) => {
3899
+ s.set(e.id, n), r.filter((t) => t.parentId === e.id).forEach(i);
3900
+ }, "assignLane");
3901
+ i(e);
3902
+ }
3903
+ let d = r.filter((e) => !e.isGroup && !e.isEdgeLabel).map((e) => {
3904
+ let t = e.width ?? 10, n = e.height ?? 10, r = e.x ?? 0, i = e.y ?? 0, a = kn;
3905
+ return {
3906
+ nodeId: e.id,
3907
+ minX: r - t / 2 - a,
3908
+ maxX: r + t / 2 + a,
3909
+ minY: i - n / 2 - a,
3910
+ maxY: i + n / 2 + a,
3911
+ visualXHalfExtent: l ? n / 2 + a : t / 2 + a
3912
+ };
3913
+ }), f = /* @__PURE__ */ t((e, t, n, r) => {
3914
+ let i = c.find((n) => n.orientation === e && Math.abs(n.coord - t) < 1);
3915
+ return i || (i = {
3916
+ id: `pipe-${e}-${t.toFixed(0)}`,
3917
+ orientation: e,
3918
+ coord: t,
3919
+ spanMin: n,
3920
+ spanMax: r,
3921
+ tracks: []
3922
+ }, c.push(i)), i.spanMin = Math.min(i.spanMin, n), i.spanMax = Math.max(i.spanMax, r), i;
3923
+ }, "getOrAddPipe"), p = /* @__PURE__ */ t((e, t) => {
3924
+ let n = e.width ?? 10, r = e.height ?? 10, i = e.x ?? 0, a = e.y ?? 0;
3925
+ switch (t) {
3926
+ case "top": return {
3927
+ x: i,
3928
+ y: a - r / 2
3929
+ };
3930
+ case "bottom": return {
3931
+ x: i,
3932
+ y: a + r / 2
3933
+ };
3934
+ case "left": return {
3935
+ x: i - n / 2,
3936
+ y: a
3937
+ };
3938
+ case "right": return {
3939
+ x: i + n / 2,
3940
+ y: a
3941
+ };
3942
+ }
3943
+ }, "portForSide"), m = /* @__PURE__ */ t((e, t, n) => p(e, Fn(e, t, n ? "bottom" : "top")), "getOrthogonalPort"), h = [], g = [], _ = /* @__PURE__ */ new Set(), v = 1e3, y = /* @__PURE__ */ t((e, t, n) => {
3944
+ if (h.length === 0) return 0;
3945
+ let r = Math.abs(t.y - n.y) < $, i = Math.abs(t.x - n.x) < $;
3946
+ if (!r && !i) return 0;
3947
+ let a = 0;
3948
+ if (r) {
3949
+ let r = t.y, i = Math.min(t.x, n.x) - $, o = Math.max(t.x, n.x) + $;
3950
+ if (o <= i) return 0;
3951
+ for (let t of h) t.edgeIndex !== e && t.orientation === "vertical" && (t.pipe.coord < i || t.pipe.coord > o || t.from - $ <= r && t.to + $ >= r && (a += v));
3952
+ } else if (i) {
3953
+ let r = t.x, i = Math.min(t.y, n.y) - $, o = Math.max(t.y, n.y) + $;
3954
+ if (o <= i) return 0;
3955
+ for (let t of h) t.edgeIndex !== e && t.orientation === "horizontal" && (t.pipe.coord < i || t.pipe.coord > o || t.from - $ <= r && t.to + $ >= r && (a += v));
3956
+ }
3957
+ return a;
3958
+ }, "crossingPenalty"), b = a.map((e, t) => {
3959
+ if (!e.start || !e.end) return {
3960
+ idx: t,
3961
+ crossLane: 0,
3962
+ dx: 0,
3963
+ dy: 0
3964
+ };
3965
+ let n = o.get(e.start), r = o.get(e.end), i = s.get(e.start), a = s.get(e.end);
3966
+ return {
3967
+ idx: t,
3968
+ crossLane: i && a && i.id !== a.id ? 1 : 0,
3969
+ dx: n && r ? Math.abs((r.x ?? 0) - (n.x ?? 0)) : 0,
3970
+ dy: n && r ? Math.abs((r.y ?? 0) - (n.y ?? 0)) : 0
3971
+ };
3972
+ }).sort((e, t) => {
3973
+ if (e.crossLane !== t.crossLane) return t.crossLane - e.crossLane;
3974
+ let n = e.dx + e.dy, r = t.dx + t.dy;
3975
+ return Math.abs(n - r) > 1 ? n - r : e.idx - t.idx;
3976
+ }).map((e) => e.idx), x = /* @__PURE__ */ t((e, t, n, r) => {
3977
+ let i = Math.min(e.x, t.x), a = Math.max(e.x, t.x), o = Math.min(e.y, t.y), s = Math.max(e.y, t.y);
3978
+ return !!d.find((c) => n && c.nodeId === n || r && c.nodeId === r ? !1 : Math.abs(e.x - t.x) > $ ? c.minY < e.y && c.maxY > e.y && c.maxX > i && c.minX < a : c.minX < e.x && c.maxX > e.x && c.maxY > o && c.minY < s);
3979
+ }, "isSegmentBlocked"), S = /* @__PURE__ */ new Map(), C = /* @__PURE__ */ new Map();
3980
+ for (let e of a) e.start && e.end && e.start !== e.end && (C.set(e.start, (C.get(e.start) ?? 0) + 1), C.set(e.end, (C.get(e.end) ?? 0) + 1));
3981
+ let w = /* @__PURE__ */ t((e, t) => Fn(e, t, "bottom"), "determineSide"), T = /* @__PURE__ */ new Map();
3982
+ for (let [e, t] of a.entries()) {
3983
+ if (!t.start || !t.end || t.start === t.end || t.points && t.points.length > 0) continue;
3984
+ let n = o.get(t.start), r = o.get(t.end);
3985
+ if (!n || !r) continue;
3986
+ let i = (r.x ?? 0) - (n.x ?? 0), a = (r.y ?? 0) - (n.y ?? 0);
3987
+ T.set(e, {
3988
+ edgeIdx: e,
3989
+ srcId: t.start,
3990
+ dstId: t.end,
3991
+ srcSide: w(n, {
3992
+ x: r.x ?? 0,
3993
+ y: r.y ?? 0
3994
+ }),
3995
+ dstSide: w(r, {
3996
+ x: n.x ?? 0,
3997
+ y: n.y ?? 0
3998
+ }),
3999
+ absDx: Math.abs(i),
4000
+ absDy: Math.abs(a),
4001
+ dxSign: Math.sign(i),
4002
+ dySign: Math.sign(a)
4003
+ });
4004
+ }
4005
+ let E = /* @__PURE__ */ t((e) => e.srcSide === "top" || e.srcSide === "bottom" ? e.absDx === 0 ? Infinity : e.absDy / e.absDx : e.absDy === 0 ? Infinity : e.absDx / e.absDy, "preferenceStrength"), D = /* @__PURE__ */ t((e) => e.srcSide === "top" || e.srcSide === "bottom" ? e.dxSign >= 0 ? "right" : "left" : e.dySign >= 0 ? "bottom" : "top", "secondarySide"), O = /* @__PURE__ */ new Map();
4006
+ for (let e of T.values()) {
4007
+ let t = `${e.srcId}:${e.srcSide}`;
4008
+ O.has(t) || O.set(t, []), O.get(t).push(e);
4009
+ }
4010
+ let k = /* @__PURE__ */ new Map(), A = /* @__PURE__ */ t((e, t) => `${e}:${t}`, "loadKey");
4011
+ for (let e of T.values()) k.set(A(e.srcId, e.srcSide), (k.get(A(e.srcId, e.srcSide)) ?? 0) + 1), k.set(A(e.dstId, e.dstSide), (k.get(A(e.dstId, e.dstSide)) ?? 0) + 1);
4012
+ for (let e of O.values()) if (!(e.length < 2)) {
4013
+ e.sort((e, t) => {
4014
+ let n = E(e), r = E(t);
4015
+ return Math.abs(n - r) > 1e-9 ? r - n : e.edgeIdx - t.edgeIdx;
4016
+ });
4017
+ for (let t = 1; t < e.length; t++) {
4018
+ let n = e[t], r = D(n), i = k.get(A(n.srcId, n.srcSide)) ?? 0, a = k.get(A(n.srcId, r)) ?? 0;
4019
+ a >= i || (k.set(A(n.srcId, n.srcSide), i - 1), k.set(A(n.srcId, r), a + 1), n.srcSide = r);
4020
+ }
4021
+ }
4022
+ let j = /* @__PURE__ */ t((e) => {
4023
+ let t = e?.shape;
4024
+ return t === "question" || t === "diamond";
4025
+ }, "isDiamondNode"), M = /* @__PURE__ */ new Map();
4026
+ for (let e of T.values()) M.has(e.dstId) || M.set(e.dstId, /* @__PURE__ */ new Set()), M.get(e.dstId).add(e.dstSide);
4027
+ for (let e of T.values()) {
4028
+ if (!j(o.get(e.srcId))) continue;
4029
+ let t = M.get(e.srcId);
4030
+ if (!t?.has(e.srcSide)) continue;
4031
+ let n = D(e);
4032
+ if (t.has(n) || (k.get(A(e.srcId, n)) ?? 0) > 0) continue;
4033
+ let r = k.get(A(e.srcId, e.srcSide)) ?? 0;
4034
+ k.set(A(e.srcId, e.srcSide), Math.max(0, r - 1)), k.set(A(e.srcId, n), 1), e.srcSide = n;
4035
+ }
4036
+ for (let e of T.values()) {
4037
+ let { edgeIdx: t, srcId: n, dstId: r, srcSide: i, dstSide: a } = e, s = o.get(n), c = o.get(r), l = `${n}:${i}:src`, u = i === "top" || i === "bottom" ? c.x ?? 0 : c.y ?? 0;
4038
+ S.has(l) || S.set(l, []), S.get(l).push({
4039
+ edgeIdx: t,
4040
+ oppositeCoord: u
4041
+ });
4042
+ let d = `${r}:${a}:dst`, f = a === "top" || a === "bottom" ? s.x ?? 0 : s.y ?? 0;
4043
+ S.has(d) || S.set(d, []), S.get(d).push({
4044
+ edgeIdx: t,
4045
+ oppositeCoord: f
4046
+ });
4047
+ }
4048
+ let N = /* @__PURE__ */ new Map();
4049
+ for (let [e, t] of S) {
4050
+ if (t.length < 2) continue;
4051
+ t.sort((e, t) => e.oppositeCoord - t.oppositeCoord);
4052
+ let n = e.split(":"), r = n.slice(0, -2).join(":"), i = n[n.length - 2], a = n[n.length - 1], s = o.get(r);
4053
+ if (!s) continue;
4054
+ let c = i === "left" || i === "right" ? s.height ?? 10 : s.width ?? 10, l = s.shape, u = l === "question" || l === "diamond" ? c * .3 : c, d = Math.min(20, Math.max(8, u / (t.length + 1))), f = -(d * (t.length - 1)) / 2;
4055
+ for (let [e, n] of t.entries()) {
4056
+ let t = f + e * d, r = `${n.edgeIdx}:${a}`;
4057
+ N.set(r, t);
4058
+ }
4059
+ }
4060
+ let P = /* @__PURE__ */ t((e) => !!a[e]?.labelNodeId, "edgeHasLabelNode"), F = /* @__PURE__ */ t((e, t) => e ? (S.get(`${e}:${t}:src`) ?? []).some(({ edgeIdx: e }) => P(e)) || (S.get(`${e}:${t}:dst`) ?? []).some(({ edgeIdx: e }) => P(e)) : !1, "faceHasLabelNode"), I = /* @__PURE__ */ t((e, t, n) => t === "top" || t === "bottom" ? {
4061
+ x: e.x + n,
4062
+ y: e.y
4063
+ } : {
4064
+ x: e.x,
4065
+ y: e.y + n
4066
+ }, "applyPortOffset"), ee = /* @__PURE__ */ t((e, t, n) => {
4067
+ let r = T.get(e), i = {
4068
+ x: n.x ?? 0,
4069
+ y: n.y ?? 0
4070
+ }, a = {
4071
+ x: t.x ?? 0,
4072
+ y: t.y ?? 0
4073
+ }, o = r?.srcSide ?? w(t, i), s = r?.dstSide ?? w(n, a), c = r ? p(t, r.srcSide) : m(t, i, !0), l = r ? p(n, r.dstSide) : m(n, a, !1), u = N.get(`${e}:src`), d = N.get(`${e}:dst`);
4074
+ return u !== void 0 && (c = I(c, o, u)), d !== void 0 && (l = I(l, s, d)), {
4075
+ pSrcPort: c,
4076
+ pDstPort: l,
4077
+ srcSide: o,
4078
+ dstSide: s
4079
+ };
4080
+ }, "portsForEdge");
4081
+ for (let e of b) {
4082
+ let n = a[e];
4083
+ if (g[e] = [], !n.start || !n.end || n.points && n.points.length > 0 || n.start === n.end) continue;
4084
+ let r = o.get(n.start), i = o.get(n.end);
4085
+ if (!r || !i) continue;
4086
+ let { pSrcPort: s, pDstPort: u, srcSide: p, dstSide: m } = ee(e, r, i), v = { ...s }, b = { ...u }, w = p === "top" || p === "bottom", T = m === "top" || m === "bottom";
4087
+ w ? v.y = s.y > (r.y ?? 0) ? s.y + Nn : s.y - Nn : v.x = s.x > (r.x ?? 0) ? s.x + Nn : s.x - Nn, T ? b.y = u.y > (i.y ?? 0) ? u.y + Nn : u.y - Nn : b.x = u.x > (i.x ?? 0) ? u.x + Nn : u.x - Nn;
4088
+ let E = /* @__PURE__ */ t((e, t) => {
4089
+ for (let n of d) if (!t.includes(n.nodeId) && e.x > n.minX && e.x < n.maxX && e.y > n.minY && e.y < n.maxY) return {
4090
+ inside: !0,
4091
+ obstacle: n
4092
+ };
4093
+ return { inside: !1 };
4094
+ }, "isPointInObstacle"), D = /* @__PURE__ */ t((e, t, n, r, i) => {
4095
+ if (i) {
4096
+ let i = e.y > (t.y ?? 0);
4097
+ return {
4098
+ x: (n.x ?? 0) >= e.x ? r.maxX + An : r.minX - An,
4099
+ y: i ? r.maxY + jn : r.minY - jn,
4100
+ leavesPositiveSide: i
4101
+ };
4102
+ }
4103
+ let a = e.x > (t.x ?? 0), o = (n.y ?? 0) >= e.y;
4104
+ return {
4105
+ x: a ? r.maxX + An : r.minX - An,
4106
+ y: o ? r.maxY + jn : r.minY - jn,
4107
+ leavesPositiveSide: a
4108
+ };
4109
+ }, "obstacleDetour"), O = [], k = [n.start, n.end], A = E(v, k);
4110
+ if (A.inside && A.obstacle) {
4111
+ let e = A.obstacle;
4112
+ if (w) {
4113
+ let t = D(s, r, i, e, !0);
4114
+ v.x = t.x, v.y = t.y;
4115
+ let n = t.leavesPositiveSide ? Math.min(e.minY - 2, s.y + Nn) : Math.max(e.maxY + 2, s.y - Nn);
4116
+ O = [
4117
+ {
4118
+ x: s.x,
4119
+ y: n
4120
+ },
4121
+ {
4122
+ x: t.x,
4123
+ y: n
4124
+ },
4125
+ {
4126
+ x: t.x,
4127
+ y: t.y
4128
+ }
4129
+ ];
4130
+ } else {
4131
+ let t = D(s, r, i, e, !1), n = t.leavesPositiveSide ? Math.min(e.minX - 2, s.x + Nn) : Math.max(e.maxX + 2, s.x - Nn);
4132
+ v.x = t.x, v.y = t.y, O = [
4133
+ {
4134
+ x: n,
4135
+ y: s.y
4136
+ },
4137
+ {
4138
+ x: n,
4139
+ y: t.y
4140
+ },
4141
+ {
4142
+ x: t.x,
4143
+ y: t.y
4144
+ }
4145
+ ];
4146
+ }
4147
+ }
4148
+ let j = [], M = E(b, k);
4149
+ if (M.inside && M.obstacle) {
4150
+ let e = M.obstacle;
4151
+ if (T) {
4152
+ let t = D(u, i, r, e, !0);
4153
+ b.x = t.x, b.y = t.y, j = [{
4154
+ x: t.x,
4155
+ y: t.y
4156
+ }, {
4157
+ x: u.x,
4158
+ y: t.y
4159
+ }];
4160
+ } else {
4161
+ let t = D(u, i, r, e, !1);
4162
+ b.x = t.x, b.y = t.y, j = [{
4163
+ x: t.x,
4164
+ y: t.y
4165
+ }, {
4166
+ x: t.x,
4167
+ y: u.y
4168
+ }];
4169
+ }
4170
+ }
4171
+ if (O.length === 0 && j.length === 0) {
4172
+ let t = An, r = Math.abs(v.x - b.x) < t, i = Math.abs(v.y - b.y) < t, a = N.get(`${e}:src`) !== void 0 || N.get(`${e}:dst`) !== void 0, o = (S.get(`${n.start ?? ""}:${p}:src`)?.length ?? 0) + (S.get(`${n.start ?? ""}:${p}:dst`)?.length ?? 0), c = (S.get(`${n.end ?? ""}:${m}:src`)?.length ?? 0) + (S.get(`${n.end ?? ""}:${m}:dst`)?.length ?? 0), l = o > 1 || c > 1, d = C.get(n.start ?? "") ?? 0, f = C.get(n.end ?? "") ?? 0, g = o > 1 && F(n.start, p) || c > 1 && F(n.end, m);
4173
+ if ((r || i) && !a && (!l || l && !g && (o <= 1 || d <= 2) && (c <= 1 || f <= 2)) && !x(s, u, n.start, n.end)) {
4174
+ n.points = [
4175
+ { ...s },
4176
+ { ...v },
4177
+ { ...b },
4178
+ { ...u }
4179
+ ], _.add(e);
4180
+ let t = i ? "horizontal" : "vertical", r = i ? s.y : s.x, a = i ? Math.min(s.x, u.x) : Math.min(s.y, u.y), o = i ? Math.max(s.x, u.x) : Math.max(s.y, u.y), c = {
4181
+ id: `fast-path-${t}-${r.toFixed(0)}-${e}`,
4182
+ orientation: t,
4183
+ coord: r,
4184
+ spanMin: a,
4185
+ spanMax: o,
4186
+ tracks: []
4187
+ };
4188
+ h.push({
4189
+ edgeIndex: e,
4190
+ segmentIndex: 0,
4191
+ orientation: t,
4192
+ pipe: c,
4193
+ trackIndex: 0,
4194
+ from: a,
4195
+ to: o
4196
+ });
4197
+ continue;
4198
+ }
4199
+ }
4200
+ v.x = f("vertical", v.x, v.y, v.y).coord, b.x = f("vertical", b.x, b.y, b.y).coord;
4201
+ let P = Math.min(v.x, b.x) - 50, I = Math.max(v.x, b.x) + 50, L = Math.min(v.y, b.y) - 50, R = Math.max(v.y, b.y) + 50;
4202
+ for (let e of d) {
4203
+ let t = Math.min(v.x, b.x), n = Math.max(v.x, b.x), r = Math.min(v.y, b.y), i = Math.max(v.y, b.y);
4204
+ e.minX < n && e.maxX > t && e.minY < i && e.maxY > r && (P = Math.min(P, e.minX - Mn), I = Math.max(I, e.maxX + Mn), L = Math.min(L, e.minY - Mn), R = Math.max(R, e.maxY + Mn));
4205
+ }
4206
+ for (let e of d) {
4207
+ if (e.maxX < P || e.minX > I || e.maxY < L || e.minY > R) continue;
4208
+ let t = An;
4209
+ f("horizontal", e.minY - t, P, I), f("horizontal", e.maxY + t, P, I);
4210
+ let n = jn;
4211
+ f("vertical", e.minX - n, L, R), f("vertical", e.maxX + n, L, R);
4212
+ }
4213
+ f("horizontal", v.y, P, I), f("horizontal", b.y, P, I);
4214
+ let z = c.filter((e) => e.orientation === "horizontal" && e.coord >= L && e.coord <= R), te = c.filter((e) => e.orientation === "vertical" && e.coord >= P && e.coord <= I), ne = /* @__PURE__ */ t((e, t) => `${e.toFixed(1)},${t.toFixed(1)}`, "getKey"), B = ne(v.x, v.y), re = ne(b.x, b.y), ie = /* @__PURE__ */ new Map(), ae = /* @__PURE__ */ new Map(), V = /* @__PURE__ */ new Map(), oe = /* @__PURE__ */ new Set(), H = [];
4215
+ ie.set(B, 0), V.set(B, "n"), H.push({
4216
+ key: B,
4217
+ f: Math.hypot(b.x - v.x, b.y - v.y),
4218
+ pt: v
4219
+ }), oe.add(B);
4220
+ let U = [], W = /* @__PURE__ */ t((e, t) => x(e, t, n.start, n.end), "checkSegmentBlocked"), G = {
4221
+ x: b.x,
4222
+ y: v.y
4223
+ }, K = W(v, G), se = W(G, b), ce = K || se, le = {
4224
+ x: v.x,
4225
+ y: b.y
4226
+ }, ue = W(v, le), de = W(le, b);
4227
+ if (ce ? ue || de || (U = Math.abs(v.x - b.x) < $ ? [v, b] : [
4228
+ v,
4229
+ le,
4230
+ b
4231
+ ]) : U = Math.abs(v.y - b.y) < $ || Math.abs(v.x - b.x) < $ ? [v, b] : [
4232
+ v,
4233
+ G,
4234
+ b
4235
+ ], U.length === 0) for (; H.length > 0;) {
4236
+ H.sort((e, t) => e.f - t.f);
4237
+ let t = H.shift();
4238
+ if (oe.delete(t.key), t.key === re) {
4239
+ let e = re, t = b;
4240
+ for (U = [t]; ae.has(e);) {
4241
+ let n = ae.get(e);
4242
+ U.unshift(n), t = n, e = ne(n.x, n.y);
4243
+ }
4244
+ break;
4245
+ }
4246
+ let r = t.pt.x, i = t.pt.y, a = te.sort((e, t) => e.coord - t.coord), o = a.findIndex((e) => Math.abs(e.coord - r) < 1), s = z.sort((e, t) => e.coord - t.coord), c = s.findIndex((e) => Math.abs(e.coord - i) < 1), l = [];
4247
+ o > 0 && l.push({
4248
+ x: a[o - 1].coord,
4249
+ y: i
4250
+ }), o >= 0 && o < a.length - 1 && l.push({
4251
+ x: a[o + 1].coord,
4252
+ y: i
4253
+ }), c > 0 && l.push({
4254
+ x: r,
4255
+ y: s[c - 1].coord
4256
+ }), c >= 0 && c < s.length - 1 && l.push({
4257
+ x: r,
4258
+ y: s[c + 1].coord
4259
+ });
4260
+ for (let a of l) {
4261
+ let o = Math.min(r, a.x), s = Math.max(r, a.x), c = Math.min(i, a.y), l = Math.max(i, a.y);
4262
+ if (d.some((e) => e.nodeId === n.start || e.nodeId === n.end ? !1 : o === s ? e.minX < r && e.maxX > r && e.maxY > c && e.minY < l : e.minY < i && e.maxY > i && e.maxX > o && e.minX < s)) continue;
4263
+ let u = ne(a.x, a.y), f = Math.abs(a.x - r) + Math.abs(a.y - i), p = y(e, t.pt, a), m = 0, h = b.x - v.x, g = b.y - v.y, _ = a.x - r, x = a.y - i;
4264
+ (g > 10 && x < -5 || g < -10 && x > 5) && (m = Math.abs(x) * 100), (h > 10 && _ < -5 || h < -10 && _ > 5) && (m += Math.abs(_) * 50);
4265
+ let S = 0, C = V.get(t.key) ?? "n", w = Math.abs(_) > $ ? "h" : "v";
4266
+ C !== "n" && C !== w && (S = 50);
4267
+ let T = f + p + m + S, E = (ie.get(t.key) ?? Infinity) + T, D = Math.abs(b.x - a.x) + Math.abs(b.y - a.y);
4268
+ if (E < (ie.get(u) ?? Infinity)) {
4269
+ if (ae.set(u, t.pt), ie.set(u, E), V.set(u, w), !oe.has(u)) H.push({
4270
+ key: u,
4271
+ f: E + D,
4272
+ pt: a
4273
+ }), oe.add(u);
4274
+ else {
4275
+ let e = H.findIndex((e) => e.key === u);
4276
+ e !== -1 && (H[e].f = E + D);
4277
+ }
4278
+ }
4279
+ }
4280
+ }
4281
+ if (U.length === 0 && (U = [
4282
+ v,
4283
+ {
4284
+ x: v.x,
4285
+ y: b.y
4286
+ },
4287
+ b
4288
+ ]), U.length > 4) {
4289
+ let e = U[0], n = U[U.length - 1], r = Math.min(e.x, n.x), i = Math.max(e.x, n.x), a = Math.min(e.y, n.y), o = Math.max(e.y, n.y);
4290
+ for (let e of U) r = Math.min(r, e.x), i = Math.max(i, e.x), a = Math.min(a, e.y), o = Math.max(o, e.y);
4291
+ let s = i > Math.max(e.x, n.x), c = r < Math.min(e.x, n.x);
4292
+ if (l) {
4293
+ let t = jn;
4294
+ if (s) {
4295
+ let r = Math.max(e.x, n.x), a = Math.min(e.y, n.y), o = Math.max(e.y, n.y), s = d.filter((e) => e.minX < r && e.maxX > r && e.minY < o && e.maxY > a);
4296
+ if (s.length > 0) {
4297
+ let r = Math.max(e.x, n.x);
4298
+ for (let e of s) {
4299
+ let n = (e.minX + e.maxX) / 2;
4300
+ if (e.visualXHalfExtent === void 0 || isNaN(e.visualXHalfExtent)) continue;
4301
+ let i = n + e.visualXHalfExtent + t;
4302
+ r = Math.max(r, i);
4303
+ }
4304
+ isNaN(r) || (i = r);
4305
+ }
4306
+ }
4307
+ if (c) {
4308
+ let i = d.filter((r) => r.minX < Math.min(e.x, n.x) + t && r.minY < Math.max(e.y, n.y) && r.maxY > Math.min(e.y, n.y));
4309
+ if (i.length > 0) {
4310
+ let a = Math.min(e.x, n.x);
4311
+ for (let e of i) {
4312
+ let n = (e.minX + e.maxX) / 2 - e.visualXHalfExtent - t;
4313
+ a = Math.min(a, n);
4314
+ }
4315
+ r = a;
4316
+ }
4317
+ }
4318
+ }
4319
+ let u = /* @__PURE__ */ t((t) => {
4320
+ let r = n.y > e.y, i = d.filter((t) => {
4321
+ let r = Math.min(e.x, n.x) < t.maxX && Math.max(e.x, n.x) > t.minX, i = Math.min(e.y, n.y) < t.maxY && Math.max(e.y, n.y) > t.minY;
4322
+ return r && i;
4323
+ }), a = i;
4324
+ if (l && i.length > 0) {
4325
+ let e = i.filter((e) => e.minX < t && e.maxX > t);
4326
+ e.length > 0 && (a = e);
4327
+ }
4328
+ if (a.length === 0) return n.y;
4329
+ let o = An;
4330
+ if (r) {
4331
+ let e = Math.max(...a.map((e) => e.maxY)) + o;
4332
+ if (e < n.y - $) return e;
4333
+ } else {
4334
+ let e = Math.min(...a.map((e) => e.minY)) - o;
4335
+ if (e > n.y + $) return e;
4336
+ }
4337
+ return n.y;
4338
+ }, "findBestReturnY"), f = /* @__PURE__ */ t((t) => {
4339
+ let r = u(t), i = {
4340
+ x: t,
4341
+ y: e.y
4342
+ }, a = {
4343
+ x: t,
4344
+ y: r
4345
+ }, o = {
4346
+ x: n.x,
4347
+ y: r
4348
+ }, s = W(e, i), c = W(i, a), l = W(a, o), d = r !== n.y && W(o, n);
4349
+ return !s && !c && !l && !d ? Math.abs(r - n.y) < $ ? [
4350
+ e,
4351
+ i,
4352
+ a,
4353
+ n
4354
+ ] : [
4355
+ e,
4356
+ i,
4357
+ a,
4358
+ o,
4359
+ n
4360
+ ] : null;
4361
+ }, "trySimplifyWithDetourX"), p = s && !c ? f(i) : c && !s ? f(r) : null;
4362
+ p && (U = p);
4363
+ }
4364
+ let q = [
4365
+ s,
4366
+ ...O,
4367
+ ...U,
4368
+ ...j.reverse(),
4369
+ u
4370
+ ];
4371
+ if (q.length >= 3) {
4372
+ let e = q[q.length - 1], t = q[q.length - 2], n = q[q.length - 3], r = Math.abs(n.y - t.y) < $ && Math.abs(t.y - e.y) < $, i = Math.abs(n.x - t.x) < $ && Math.abs(t.x - e.x) < $;
4373
+ if (r) {
4374
+ let r = Math.sign(t.x - n.x), i = Math.sign(e.x - n.x);
4375
+ r !== 0 && r === i && Math.abs(t.x - n.x) > Math.abs(e.x - n.x) && q.splice(-2, 1);
4376
+ } else if (i) {
4377
+ let r = Math.sign(t.y - n.y), i = Math.sign(e.y - n.y);
4378
+ r !== 0 && r === i && Math.abs(t.y - n.y) > Math.abs(e.y - n.y) && q.splice(-2, 1);
4379
+ }
4380
+ }
4381
+ let J = [q[0]];
4382
+ for (let e = 1; e < q.length - 1; e++) {
4383
+ if (e === 1) {
4384
+ J.push(q[e]);
4385
+ continue;
4386
+ }
4387
+ let t = J[J.length - 1], n = q[e], r = q[e + 1];
4388
+ if (Math.abs(t.y - n.y) < $ && Math.abs(n.y - r.y) < $) {
4389
+ if (n.x > t.x != r.x > n.x) {
4390
+ J.push(n);
4391
+ continue;
4392
+ }
4393
+ } else if (Math.abs(t.x - n.x) < $ && Math.abs(n.x - r.x) < $) {
4394
+ if (n.y > t.y != r.y > n.y) {
4395
+ J.push(n);
4396
+ continue;
4397
+ }
4398
+ } else J.push(n);
4399
+ }
4400
+ J.push(q[q.length - 1]);
4401
+ for (let t = 0; t < J.length - 1; t++) {
4402
+ let n = J[t], r = J[t + 1], i = Math.abs(n.x - r.x) < $ ? "vertical" : "horizontal", a = i === "vertical" ? n.x : n.y, o = i === "vertical" ? Math.min(n.y, r.y) : Math.min(n.x, r.x), s = i === "vertical" ? Math.max(n.y, r.y) : Math.max(n.x, r.x), c = f(i, a, o, s), l = {
4403
+ edgeIndex: e,
4404
+ segmentIndex: t,
4405
+ orientation: i,
4406
+ pipe: c,
4407
+ trackIndex: 0,
4408
+ from: o,
4409
+ to: s
4410
+ };
4411
+ h.push(l), g[e].push(h.length - 1), c.tracks[0] || (c.tracks[0] = {
4412
+ index: 0,
4413
+ coord: c.coord,
4414
+ segments: []
4415
+ }), c.tracks[0].segments.push({
4416
+ edgeIndex: e,
4417
+ segmentIndex: t,
4418
+ from: o,
4419
+ to: s
4420
+ });
4421
+ }
4422
+ }
4423
+ let L = /* @__PURE__ */ t((e, t) => e.from < t.to && t.from < e.to, "segmentsOverlap"), R = /* @__PURE__ */ t((e, t, n, r) => {
4424
+ let i = !r.segments.some((n) => (n.edgeIndex !== t.edgeIndex || n.segmentIndex !== t.segmentIndex) && L(n, e)), a = !n.segments.some((n) => (n.edgeIndex !== e.edgeIndex || n.segmentIndex !== e.segmentIndex) && L(n, t));
4425
+ return i && a ? (e.trackIndex = r.index, t.trackIndex = n.index, n.segments = [...n.segments.filter((t) => t.edgeIndex !== e.edgeIndex || t.segmentIndex !== e.segmentIndex), {
4426
+ edgeIndex: t.edgeIndex,
4427
+ segmentIndex: t.segmentIndex,
4428
+ from: t.from,
4429
+ to: t.to
4430
+ }], r.segments = [...r.segments.filter((e) => e.edgeIndex !== t.edgeIndex || e.segmentIndex !== t.segmentIndex), {
4431
+ edgeIndex: e.edgeIndex,
4432
+ segmentIndex: e.segmentIndex,
4433
+ from: e.from,
4434
+ to: e.to
4435
+ }], !0) : !1;
4436
+ }, "trySwapSegmentsAcrossTracks"), z = /* @__PURE__ */ t((e) => {
4437
+ let t = e.tracks.length;
4438
+ return e.tracks[t] = {
4439
+ index: t,
4440
+ coord: e.coord,
4441
+ segments: []
4442
+ }, t;
4443
+ }, "createNewTrack"), te = /* @__PURE__ */ t((e, t) => {
4444
+ let n = e.pipe.tracks[e.trackIndex];
4445
+ n.segments = n.segments.filter((t) => t.edgeIndex !== e.edgeIndex || t.segmentIndex !== e.segmentIndex), e.trackIndex = t, e.pipe.tracks[t].segments.push({
4446
+ edgeIndex: e.edgeIndex,
4447
+ segmentIndex: e.segmentIndex,
4448
+ from: e.from,
4449
+ to: e.to
4450
+ });
4451
+ }, "moveSegmentToTrack"), ne = /* @__PURE__ */ t((e, t) => {
4452
+ let n = g[e.edgeIndex];
4453
+ for (let r of n) {
4454
+ let n = h[r];
4455
+ n.pipe === e.pipe && te(n, t);
4456
+ }
4457
+ }, "moveSegmentChainToTrack"), B = /* @__PURE__ */ t((e) => {
4458
+ let t = g[e.edgeIndex], n = t.indexOf(h.indexOf(e)), r = [];
4459
+ return n > 0 && r.push(h[t[n - 1]]), n < t.length - 1 && r.push(h[t[n + 1]]), r;
4460
+ }, "getAdjacentSegmentsAlongEdge"), re = /* @__PURE__ */ t((e, t) => {
4461
+ if (e.orientation === t.orientation) return !1;
4462
+ let n = e.orientation === "horizontal" ? e : t, r = e.orientation === "horizontal" ? t : e;
4463
+ return r.pipe.coord > n.from && r.pipe.coord < n.to && n.pipe.coord > r.from && n.pipe.coord < r.to;
4464
+ }, "haveAnyCrossing"), ie = /* @__PURE__ */ t((e, t) => {
4465
+ for (let n of e.tracks) if (!n.segments.some((e) => (e.edgeIndex !== t.edgeIndex || e.segmentIndex !== t.segmentIndex) && L(e, t))) return n.index;
4466
+ return -1;
4467
+ }, "findAvailableTrack"), ae = /* @__PURE__ */ t((e, t) => {
4468
+ if (e.trackIndex === t.trackIndex) return L(e, t);
4469
+ let n = B(e), r = B(t);
4470
+ return n.some((e) => r.some((t) => re(e, t)));
4471
+ }, "segmentsConflict"), V = /* @__PURE__ */ t((e, t, n) => {
4472
+ if (R(e, t, e.pipe.tracks[e.trackIndex], t.pipe.tracks[t.trackIndex])) return;
4473
+ let r = ie(e.pipe, t);
4474
+ n(t, r === -1 ? z(e.pipe) : r);
4475
+ }, "resolveTrackConflict"), oe = /* @__PURE__ */ t((e) => {
4476
+ let t = 0;
4477
+ for (let n = 0; n < e.length; n++) for (let r = n + 1; r < e.length; r++) {
4478
+ let i = e[n], a = e[r];
4479
+ i.pipe === a.pipe && ae(i, a) && (t++, V(i, a, ne));
4480
+ }
4481
+ return t;
4482
+ }, "resolveHandleConflicts"), H = /* @__PURE__ */ new Map(), U = /* @__PURE__ */ t((e) => {
4483
+ if (H.has(e)) return H.get(e);
4484
+ let t = g[e];
4485
+ if (t.length === 0) {
4486
+ let t = {
4487
+ dest: 0,
4488
+ deviation: 0,
4489
+ base: 0,
4490
+ delta: 0
4491
+ };
4492
+ return H.set(e, t), t;
4493
+ }
4494
+ let n = h[t[0]].pipe.coord, r = n;
4495
+ for (let e = 1; e < t.length; e++) {
4496
+ let i = h[t[e]];
4497
+ if (i.orientation === "horizontal") {
4498
+ let e = i.from, t = i.to;
4499
+ r = Math.abs(e - n) > Math.abs(t - n) ? e : t;
4500
+ break;
4501
+ }
4502
+ }
4503
+ let i = Math.abs(r - n), a = {
4504
+ dest: r,
4505
+ deviation: i,
4506
+ base: n,
4507
+ delta: r - n
4508
+ };
4509
+ return H.set(e, a), a;
4510
+ }, "getDestInfo"), W = /* @__PURE__ */ t(() => {
4511
+ let e = 0, n = /* @__PURE__ */ new Map();
4512
+ for (let [e, t] of a.entries()) g[e].length !== 0 && t.start && (n.has(t.start) || n.set(t.start, []), n.get(t.start).push(e));
4513
+ let r = /* @__PURE__ */ t((e) => {
4514
+ let t = a[e];
4515
+ if (!t.start || !t.end) return 0;
4516
+ let n = o.get(t.start), r = o.get(t.end);
4517
+ if (!n || !r) return 0;
4518
+ let i = (r.x ?? 0) - (n.x ?? 0), s = (r.y ?? 0) - (n.y ?? 0);
4519
+ return Math.abs(i) + Math.abs(s);
4520
+ }, "getEdgeDistance");
4521
+ for (let t of n.values()) {
4522
+ t.sort((e, t) => {
4523
+ let n = U(e), i = U(t);
4524
+ if (Math.abs(n.deviation - i.deviation) > 1) return n.deviation - i.deviation;
4525
+ if (Math.abs(n.dest - i.dest) > 1) return n.dest - i.dest;
4526
+ let a = r(e), o = r(t);
4527
+ if (Math.abs(a - o) > 1) return o - a;
4528
+ let s = g[e].length, c = g[t].length;
4529
+ if (s !== c) return s - c;
4530
+ if (s === 1) {
4531
+ let n = g[e][0], r = g[t][0];
4532
+ if (h[n] && h[r]) {
4533
+ let e = h[n], t = h[r], i = Math.abs(e.to - e.from), a = Math.abs(t.to - t.from);
4534
+ if (Math.abs(i - a) > 1) return i - a;
4535
+ }
4536
+ }
4537
+ return 0;
4538
+ });
4539
+ let n = t.map((e) => h[g[e][0]]);
4540
+ e += oe(n);
4541
+ }
4542
+ return e;
4543
+ }, "fixSourceHandleCrossings"), G = /* @__PURE__ */ t(() => {
4544
+ let e = 0, n = /* @__PURE__ */ new Map();
4545
+ for (let [e, t] of a.entries()) g[e].length !== 0 && t.end && (n.has(t.end) || n.set(t.end, []), n.get(t.end).push(e));
4546
+ for (let r of n.values()) {
4547
+ r.sort((e, n) => {
4548
+ let r = /* @__PURE__ */ t((e) => {
4549
+ let t = g[e];
4550
+ if (t.length < 2) return 0;
4551
+ let n = h[t[t.length - 2]];
4552
+ return Math.abs(n.to - n.from);
4553
+ }, "getDist"), i = r(e), a = r(n);
4554
+ return Math.abs(i - a) > .1 ? i - a : e - n;
4555
+ });
4556
+ let n = r.map((e) => h[g[e][g[e].length - 1]]);
4557
+ e += oe(n);
4558
+ }
4559
+ return e;
4560
+ }, "fixTargetHandleCrossings"), K = /* @__PURE__ */ t(() => {
4561
+ let e = 0;
4562
+ for (let t of c) {
4563
+ let n = [];
4564
+ for (let e of t.tracks) for (let t of e.segments) {
4565
+ let e = g[t.edgeIndex].find((e) => h[e].segmentIndex === t.segmentIndex);
4566
+ e !== void 0 && n.push(h[e]);
4567
+ }
4568
+ n.sort((e, t) => e.edgeIndex - t.edgeIndex || e.segmentIndex - t.segmentIndex);
4569
+ for (let t = 0; t < n.length; t++) for (let r = t + 1; r < n.length; r++) {
4570
+ let i = n[t], a = n[r];
4571
+ ae(i, a) && (e++, V(i, a, te));
4572
+ }
4573
+ }
4574
+ return e;
4575
+ }, "fixPipeCrossings"), se = 0;
4576
+ for (; se < 10;) {
4577
+ let e = 0;
4578
+ if (e += W(), e += G(), e += K(), e === 0) break;
4579
+ se++;
4580
+ }
4581
+ let ce = /* @__PURE__ */ new Map();
4582
+ for (let e of c) {
4583
+ let n = [];
4584
+ e.tracks.forEach((e) => {
4585
+ e.segments.forEach((t) => {
4586
+ n.push({
4587
+ edgeIndex: t.edgeIndex,
4588
+ segmentIndex: t.segmentIndex,
4589
+ trackIndex: e.index,
4590
+ from: t.from,
4591
+ to: t.to
4592
+ });
4593
+ });
4594
+ }), n.sort((e, t) => e.from - t.from);
4595
+ let r = [];
4596
+ if (n.length > 0) {
4597
+ let e = [n[0]], t = n[0].to;
4598
+ for (let i = 1; i < n.length; i++) {
4599
+ let a = n[i];
4600
+ a.from < t ? (e.push(a), t = Math.max(t, a.to)) : (r.push(e), e = [a], t = a.to);
4601
+ }
4602
+ r.push(e);
4603
+ }
4604
+ for (let n of r) {
4605
+ let r = /* @__PURE__ */ new Set();
4606
+ n.forEach((e) => r.add(e.trackIndex));
4607
+ let i = /* @__PURE__ */ new Map();
4608
+ n.forEach((e) => {
4609
+ let t = U(e.edgeIndex);
4610
+ i.set(e.trackIndex, (i.get(e.trackIndex) ?? 0) + t.delta);
4611
+ });
4612
+ let a = [...r].filter((e) => (i.get(e) ?? 0) < -1), o = [...r].filter((e) => (i.get(e) ?? 0) > 1), s = [...r].filter((e) => Math.abs(i.get(e) ?? 0) <= 1);
4613
+ a.sort((e, t) => (i.get(t) ?? 0) - (i.get(e) ?? 0)), o.sort((e, t) => (i.get(e) ?? 0) - (i.get(t) ?? 0));
4614
+ let c = /* @__PURE__ */ t((t, r) => {
4615
+ n.filter((e) => e.trackIndex === t).forEach((t) => {
4616
+ let n = _.has(t.edgeIndex) ? e.coord : r;
4617
+ ce.set(`${t.edgeIndex}-${t.segmentIndex}`, n);
4618
+ });
4619
+ }, "assignCoord"), l = 0;
4620
+ for (let t of a) l++, c(t, e.coord - l * Pn);
4621
+ if (s.length === 0 && r.size > 0) {
4622
+ let e = [...r].sort((e, t) => Math.abs(i.get(e) ?? 0) - Math.abs(i.get(t) ?? 0))[0], t = a.indexOf(e);
4623
+ t !== -1 && a.splice(t, 1);
4624
+ let n = o.indexOf(e);
4625
+ n !== -1 && o.splice(n, 1), s.push(e);
4626
+ }
4627
+ let u = 0;
4628
+ for (let t of s) {
4629
+ if (u === 0) c(t, e.coord);
4630
+ else {
4631
+ let n = u % 2 == 1 ? 1 : -1, r = Math.ceil(u / 2);
4632
+ c(t, e.coord + n * r * Pn * .5);
4633
+ }
4634
+ u++;
4635
+ }
4636
+ let d = 0;
4637
+ for (let t of o) d++, c(t, e.coord + d * Pn);
4638
+ }
4639
+ }
4640
+ for (let [e, t] of a.entries()) {
4641
+ let n = g[e] ?? [];
4642
+ if (n.length === 0) continue;
4643
+ let r = [], { pSrcPort: i, pDstPort: a } = ee(e, o.get(t.start), o.get(t.end)), s = n.map((e) => {
4644
+ let t = h[e], n = ce.get(`${t.edgeIndex}-${t.segmentIndex}`) ?? t.pipe.coord;
4645
+ return {
4646
+ orient: t.orientation,
4647
+ coord: n,
4648
+ from: t.from,
4649
+ to: t.to
4650
+ };
4651
+ });
4652
+ r.push(i);
4653
+ for (let e = 0; e < s.length; e++) {
4654
+ let t = s[e], n = r[r.length - 1], i = t.orient === "vertical" ? n.y : n.x, a = t.orient === "vertical" ? n.x : n.y, o = s[e + 1], c = e < s.length - 1;
4655
+ if (Math.abs(a - t.coord) > $ && r.push(Ln(t, i)), c && o.orient === t.orient) {
4656
+ if (Math.abs(t.coord - o.coord) > $) {
4657
+ let e = t.orient === "vertical" ? (i + o.from) / 2 : In(t, o);
4658
+ r.push(Ln(t, e), Ln(o, e));
4659
+ } else (e === 0 || e === s.length - 2) && r.push(Ln(t, In(t, o)));
4660
+ } else if (c) r.push(Ln(t, o.coord));
4661
+ else {
4662
+ let e = Math.abs(t.from - i) < Math.abs(t.to - i) ? t.to : t.from;
4663
+ r.push(Ln(t, e));
4664
+ }
4665
+ }
4666
+ let c = r[r.length - 1];
4667
+ (Math.abs(c.x - a.x) > $ || Math.abs(c.y - a.y) > $) && r.push(a);
4668
+ let l = [];
4669
+ r.length > 0 && l.push(r[0]);
4670
+ for (let e = 1; e < r.length; e++) {
4671
+ let t = r[e], n = l[l.length - 1];
4672
+ (Math.abs(t.x - n.x) > $ || Math.abs(t.y - n.y) > $) && l.push(t);
4673
+ }
4674
+ t.points = l;
4675
+ }
4676
+ for (let e of a) {
4677
+ let t = e.__originalEdge;
4678
+ t && e.points && (t.points = e.points);
4679
+ }
4680
+ e.edges = (e.edges ?? []).filter((e) => !e.isLayoutOnly);
4681
+ let le = /* @__PURE__ */ t((e, t) => {
4682
+ let n = t.x ?? 0, r = t.y ?? 0, i = t.width ?? 0, a = t.height ?? 0;
4683
+ if (i <= 0 || a <= 0) return e;
4684
+ let o = n - i / 2, s = n + i / 2, c = r - a / 2, l = r + a / 2;
4685
+ if (e.x < o || e.x > s || e.y < c || e.y > l) return e;
4686
+ let u = e.x - o, d = s - e.x, f = e.y - c, p = l - e.y, m = Math.min(u, d, f, p);
4687
+ return m === u ? {
4688
+ x: o,
4689
+ y: e.y
4690
+ } : m === d ? {
4691
+ x: s,
4692
+ y: e.y
4693
+ } : m === f ? {
4694
+ x: e.x,
4695
+ y: c
4696
+ } : {
4697
+ x: e.x,
4698
+ y: l
4699
+ };
4700
+ }, "nodeBoundaryClamp");
4701
+ for (let t of e.edges) {
4702
+ let e = t.points;
4703
+ if (!e || e.length < 2) continue;
4704
+ let n = t.start, r = t.end, i = n ? o.get(n) : void 0, a = r ? o.get(r) : void 0;
4705
+ i && (e[0] = le(e[0], i)), a && (e[e.length - 1] = le(e[e.length - 1], a));
4706
+ }
4707
+ return e;
4708
+ }
4709
+ t(Rn, "routeEdgesOrthogonal");
4710
+ function zn(e) {
4711
+ return e.direction ?? "TB";
4712
+ }
4713
+ t(zn, "getSwimlaneDirection");
4714
+ function Bn(e) {
4715
+ let t = d(e), n = e.config.flowchart?.nodeSpacing ?? 40, r = e.config.flowchart?.rankSpacing ?? 100, i = e.config.swimlane?.ignoreCrossLaneEdges ?? !0, a = e.config.swimlane?.optimizeRanksByCrossings ?? !0, o = e.config.swimlane?.automaticLaneOrdering ?? !1, s = zn(e), { ordered: c, coordinates: l } = On(t, {
4716
+ nodeGap: n,
4717
+ layerGap: r,
4718
+ ignoreCrossLaneEdges: i,
4719
+ optimizeRanksByCrossings: a,
4720
+ automaticLaneOrdering: o,
4721
+ direction: s
4722
+ });
4723
+ f(t, c, l, {
4724
+ nodeGap: n,
4725
+ layerGap: r
4726
+ });
4727
+ for (let t of e.edges ?? []) delete t.points;
4728
+ Rn(e, s);
4729
+ for (let t of e.edges ?? []) (!t.curve || t.curve === "basis") && (t.curve = "rounded");
4730
+ return vt(e, s), _t(e), s;
4731
+ }
4732
+ t(Bn, "runSwimlaneLayoutCore");
4733
+ function Vn(e) {
4734
+ u(e);
4735
+ let t = m(e);
4736
+ e.nodes = t.nodes, e.edges = t.edges;
4737
+ }
4738
+ t(Vn, "prepareSwimlaneLayout");
4739
+ var Hn = n({
4740
+ prepareLayout: Vn,
4741
+ runLayoutCore: Bn,
4742
+ afterPaint: i
4743
+ });
4744
+ //#endregion
4745
+ export { Hn as render };