@diagrammo/dgmo 0.45.0 → 0.47.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (250) hide show
  1. package/dist/advanced.cjs +31 -25
  2. package/dist/advanced.d.cts +3 -855
  3. package/dist/advanced.d.ts +3 -855
  4. package/dist/advanced.js +541 -70101
  5. package/dist/analyzer-UYKBXAKR.js +15 -0
  6. package/dist/auto.cjs +500 -341
  7. package/dist/auto.css +342 -159
  8. package/dist/auto.d.cts +10 -8
  9. package/dist/auto.d.ts +10 -8
  10. package/dist/auto.js +373 -265
  11. package/dist/auto.mjs +500 -341
  12. package/dist/block.cjs +31 -25
  13. package/dist/block.js +83 -69411
  14. package/dist/calculator-LDYQCDDY.js +11 -0
  15. package/dist/charts-d3-QOZHKTCT.js +25 -0
  16. package/dist/chunk-2DXMZRWJ.js +800 -0
  17. package/dist/chunk-2LACINWN.js +786 -0
  18. package/dist/chunk-33LCUH4H.js +893 -0
  19. package/dist/chunk-3CIOJ5YJ.js +35 -0
  20. package/dist/chunk-3HDBAXF5.js +86 -0
  21. package/dist/chunk-3JLKYGBQ.js +290 -0
  22. package/dist/chunk-3MQQNXPD.js +415 -0
  23. package/dist/chunk-3R5POCTZ.js +967 -0
  24. package/dist/chunk-3SMGIJDD.js +112 -0
  25. package/dist/chunk-44CM72SQ.js +409 -0
  26. package/dist/chunk-4GRI7MEB.js +1604 -0
  27. package/dist/chunk-4OHACBGX.js +606 -0
  28. package/dist/chunk-5DH3KYFH.js +21 -0
  29. package/dist/chunk-5MLYVTYM.js +76 -0
  30. package/dist/chunk-5QXL4NYS.js +553 -0
  31. package/dist/chunk-5WRI5ZAA.js +31 -0
  32. package/dist/chunk-6EK55ART.js +117 -0
  33. package/dist/chunk-6FZYCKXB.js +2065 -0
  34. package/dist/chunk-6HO5ZTXK.js +277 -0
  35. package/dist/chunk-6KFWC4CO.js +7 -0
  36. package/dist/chunk-6MTWIQVO.js +121 -0
  37. package/dist/chunk-6NYWYNBI.js +329 -0
  38. package/dist/chunk-6SM5NJQH.js +620 -0
  39. package/dist/chunk-725LDASD.js +422 -0
  40. package/dist/chunk-76OWZ3BA.js +130 -0
  41. package/dist/chunk-7JEGTRLD.js +338 -0
  42. package/dist/chunk-A44USUV7.js +923 -0
  43. package/dist/chunk-A4GOY3PE.js +25 -0
  44. package/dist/chunk-A4VFQH5G.js +251 -0
  45. package/dist/chunk-AELOBFW5.js +375 -0
  46. package/dist/chunk-AN2MOO5T.js +522 -0
  47. package/dist/chunk-BMR4CIEO.js +41 -0
  48. package/dist/chunk-BS7SV7C3.js +51 -0
  49. package/dist/chunk-BUPDIHML.js +613 -0
  50. package/dist/chunk-BUVJFRPY.js +887 -0
  51. package/dist/chunk-C3Z4DX3V.js +112 -0
  52. package/dist/chunk-CI2G3OEB.js +1818 -0
  53. package/dist/chunk-CKNVO24D.js +54 -0
  54. package/dist/chunk-CUVHQHZ7.js +391 -0
  55. package/dist/chunk-CXK4DZH3.js +114 -0
  56. package/dist/chunk-DKEPS5LH.js +315 -0
  57. package/dist/chunk-DU7W62N5.js +487 -0
  58. package/dist/chunk-DZAQBW35.js +751 -0
  59. package/dist/chunk-EB6FPQUP.js +316 -0
  60. package/dist/chunk-EMS2SK26.js +376 -0
  61. package/dist/chunk-ERLBPDGU.js +510 -0
  62. package/dist/chunk-EVCVDTXE.js +732 -0
  63. package/dist/chunk-FCIIHT24.js +384 -0
  64. package/dist/chunk-FFUN5D66.js +97 -0
  65. package/dist/chunk-FITOLXSX.js +714 -0
  66. package/dist/chunk-FMDSF3OV.js +68 -0
  67. package/dist/chunk-FNB3PNGF.js +410 -0
  68. package/dist/chunk-G2H74XJZ.js +2104 -0
  69. package/dist/chunk-GMR5MFHJ.js +339 -0
  70. package/dist/chunk-H6PI3KJT.js +305 -0
  71. package/dist/chunk-I46X5VUA.js +59 -0
  72. package/dist/chunk-I5IGB56C.js +255 -0
  73. package/dist/chunk-IH6ZMVQ5.js +3950 -0
  74. package/dist/chunk-IJZFN3HM.js +463 -0
  75. package/dist/chunk-IPWPWM6R.js +3079 -0
  76. package/dist/chunk-IYULMRBE.js +23 -0
  77. package/dist/chunk-IZMRON6C.js +167 -0
  78. package/dist/chunk-J5FIXQRT.js +813 -0
  79. package/dist/chunk-JED6ZDEE.js +73 -0
  80. package/dist/chunk-JEUJOX5X.js +136 -0
  81. package/dist/chunk-JM4LEPY3.js +436 -0
  82. package/dist/chunk-L3UHP6TD.js +101 -0
  83. package/dist/chunk-L66GEFB6.js +524 -0
  84. package/dist/chunk-LIOHW36Z.js +469 -0
  85. package/dist/chunk-LP7EC4MI.js +16 -0
  86. package/dist/chunk-MITI6NOL.js +548 -0
  87. package/dist/chunk-MO5YHHMQ.js +168 -0
  88. package/dist/chunk-MZSBFAPJ.js +885 -0
  89. package/dist/chunk-NNAAJVBU.js +9 -0
  90. package/dist/chunk-NOTA6TEI.js +47 -0
  91. package/dist/chunk-NURGB5Z4.js +335 -0
  92. package/dist/chunk-NX4EQS3U.js +1062 -0
  93. package/dist/chunk-NXMESY4J.js +1 -0
  94. package/dist/chunk-OJR3MQYV.js +1458 -0
  95. package/dist/chunk-OURHMODR.js +454 -0
  96. package/dist/chunk-P235SVAH.js +1057 -0
  97. package/dist/chunk-P4RH4OSP.js +1038 -0
  98. package/dist/chunk-P6T66CCZ.js +226 -0
  99. package/dist/chunk-PBAHEPLQ.js +223 -0
  100. package/dist/chunk-PBHE5UG6.js +1530 -0
  101. package/dist/chunk-PDKUANDZ.js +35 -0
  102. package/dist/chunk-PWIHZ6NJ.js +296 -0
  103. package/dist/chunk-QEBUY5NY.js +1685 -0
  104. package/dist/chunk-QLCCJEJI.js +253 -0
  105. package/dist/chunk-QOOUC2J5.js +52 -0
  106. package/dist/chunk-QYTPPDAO.js +402 -0
  107. package/dist/chunk-R3XI2VC7.js +801 -0
  108. package/dist/chunk-RCERWOJR.js +154 -0
  109. package/dist/chunk-RJE5JTVK.js +362 -0
  110. package/dist/chunk-RTLBSQ3G.js +1155 -0
  111. package/dist/chunk-RUNNI6VE.js +448 -0
  112. package/dist/chunk-RVMRZAPB.js +354 -0
  113. package/dist/chunk-RYEGFMUO.js +955 -0
  114. package/dist/chunk-RZCF2VVM.js +528 -0
  115. package/dist/chunk-SML67VPV.js +1025 -0
  116. package/dist/chunk-SQ7IY53Q.js +44 -0
  117. package/dist/chunk-SQAG3UXH.js +161 -0
  118. package/dist/chunk-SRTU6HMQ.js +1851 -0
  119. package/dist/chunk-T2OE3YQB.js +550 -0
  120. package/dist/chunk-T3UBLACL.js +299 -0
  121. package/dist/chunk-TLVIHFRO.js +296 -0
  122. package/dist/chunk-TYS6CSS5.js +52 -0
  123. package/dist/chunk-U6EQI3U6.js +130 -0
  124. package/dist/chunk-UJ4FJLBF.js +86 -0
  125. package/dist/chunk-ULOEATBZ.js +347 -0
  126. package/dist/chunk-UNCCZ3NU.js +127 -0
  127. package/dist/chunk-USZW2HHU.js +197 -0
  128. package/dist/chunk-UWN33VNX.js +1610 -0
  129. package/dist/chunk-UZ7EZW3B.js +40 -0
  130. package/dist/chunk-VOKGH627.js +37 -0
  131. package/dist/chunk-WBRZJOEC.js +204 -0
  132. package/dist/chunk-WCSOJFU3.js +380 -0
  133. package/dist/chunk-WCT3NYCV.js +160 -0
  134. package/dist/chunk-WVAJFAIA.js +529 -0
  135. package/dist/chunk-X5LCYCL5.js +394 -0
  136. package/dist/chunk-XAKEUMEJ.js +1256 -0
  137. package/dist/chunk-Y2ZE3MSG.js +590 -0
  138. package/dist/chunk-Y3J7VR52.js +646 -0
  139. package/dist/chunk-Y5QGVTVC.js +33 -0
  140. package/dist/chunk-YAA6IID3.js +548 -0
  141. package/dist/chunk-YGJTDXVR.js +692 -0
  142. package/dist/chunk-YRYKTYMQ.js +186 -0
  143. package/dist/chunk-YYVTBZZC.js +61 -0
  144. package/dist/chunk-Z5CGSFJB.js +647 -0
  145. package/dist/chunk-Z72XRXD4.js +787 -0
  146. package/dist/chunk-ZGR7ULFJ.js +978 -0
  147. package/dist/chunk-ZJEL4H2R.js +851 -0
  148. package/dist/chunk-ZO27FGJS.js +554 -0
  149. package/dist/cli.cjs +112 -112
  150. package/dist/collapse-CLPJD2RL.js +11 -0
  151. package/dist/collapse-SLINJQW6.js +9 -0
  152. package/dist/collapse-ZWUFFCK2.js +9 -0
  153. package/dist/compute-G55RG53N.js +8 -0
  154. package/dist/dgmo-router-DZCIDUO5.js +73 -0
  155. package/dist/dimensions-J3FHIMJ6.js +22 -0
  156. package/dist/element.cjs +492 -325
  157. package/dist/element.js +367 -259
  158. package/dist/element.mjs +492 -325
  159. package/dist/flowchart-parser-ZNSKIBVR.js +21 -0
  160. package/dist/flowchart-renderer-ZAEOL4DX.js +35 -0
  161. package/dist/index.cjs +34 -28
  162. package/dist/index.d.cts +3 -469
  163. package/dist/index.d.ts +3 -469
  164. package/dist/index.js +137 -69679
  165. package/dist/layout-46N4JJYK.js +17 -0
  166. package/dist/layout-5RA6QWR6.js +26 -0
  167. package/dist/layout-5T6RH5M6.js +14 -0
  168. package/dist/layout-7QXCNOVS.js +13 -0
  169. package/dist/layout-EE6GE46Y.js +17 -0
  170. package/dist/layout-G23F7LDH.js +9 -0
  171. package/dist/layout-HRBZPFCN.js +23 -0
  172. package/dist/layout-HWDSRX5E.js +20 -0
  173. package/dist/layout-HYZPWAK5.js +18 -0
  174. package/dist/layout-N76NR4ZO.js +19 -0
  175. package/dist/layout-OB3RI63S.js +14 -0
  176. package/dist/layout-S2QBYSK2.js +15 -0
  177. package/dist/layout-UM5F4DJB.js +15 -0
  178. package/dist/layout-search-OYV77HHS.js +1655 -0
  179. package/dist/load-data-EHDDZ5ZS.js +8 -0
  180. package/dist/palettes-PRJ2RI6D.js +56 -0
  181. package/dist/parser-2MFP2H2E.js +11 -0
  182. package/dist/parser-3STE62GB.js +21 -0
  183. package/dist/parser-4FL2CMDG.js +18 -0
  184. package/dist/parser-4OGOBJJ4.js +13 -0
  185. package/dist/parser-6BTRLKRZ.js +15 -0
  186. package/dist/parser-AQETEVRW.js +21 -0
  187. package/dist/parser-CFZD5IBL.js +12 -0
  188. package/dist/parser-FUSKFGZN.js +16 -0
  189. package/dist/parser-I6KXEYFK.js +13 -0
  190. package/dist/parser-IXSZZQHY.js +18 -0
  191. package/dist/parser-JAL2HD4I.js +13 -0
  192. package/dist/parser-KNSQSKQO.js +20 -0
  193. package/dist/parser-N5O4IHUN.js +13 -0
  194. package/dist/parser-NGU3ETO6.js +16 -0
  195. package/dist/parser-NRAI6O25.js +19 -0
  196. package/dist/parser-O5J4VBII.js +11 -0
  197. package/dist/parser-OV7NOBW6.js +21 -0
  198. package/dist/parser-PQ3POX45.js +23 -0
  199. package/dist/parser-TFZFBVWN.js +11 -0
  200. package/dist/parser-TRTHDFPP.js +18 -0
  201. package/dist/parser-VQP2UJ6W.js +11 -0
  202. package/dist/parser-XDVELHRK.js +13 -0
  203. package/dist/parser-XKRP7QKP.js +11 -0
  204. package/dist/parser-Y6WTBU76.js +14 -0
  205. package/dist/parser-ZSDPZYQP.js +12 -0
  206. package/dist/renderer-2XQQQ6QR.js +28 -0
  207. package/dist/renderer-5NDVNDAZ.js +26 -0
  208. package/dist/renderer-6EEZHMH4.js +26 -0
  209. package/dist/renderer-6W5462RB.js +43 -0
  210. package/dist/renderer-7MVLWWQD.js +22 -0
  211. package/dist/renderer-AWWAF6XD.js +33 -0
  212. package/dist/renderer-BYCNMBF7.js +34 -0
  213. package/dist/renderer-CLJHQPBJ.js +29 -0
  214. package/dist/renderer-GHPZMFU2.js +15 -0
  215. package/dist/renderer-JGBKUCZD.js +16 -0
  216. package/dist/renderer-KQB7UGDS.js +19 -0
  217. package/dist/renderer-PGX2TKVS.js +24 -0
  218. package/dist/renderer-QIWVHWZO.js +15 -0
  219. package/dist/renderer-RPOA5YPZ.js +35 -0
  220. package/dist/renderer-SMIBCRVB.js +24 -0
  221. package/dist/renderer-T7YKC5VP.js +28 -0
  222. package/dist/renderer-TOCOVLHS.js +37 -0
  223. package/dist/renderer-UWA5XS74.js +39 -0
  224. package/dist/renderer-VACVQYML.js +25 -0
  225. package/dist/renderer-W4M6QLIJ.js +37 -0
  226. package/dist/renderer-WZRREQ2P.js +23 -0
  227. package/dist/renderer-YY2OSF6E.js +27 -0
  228. package/dist/renderer-Z7I3W2PP.js +24 -0
  229. package/dist/renderer-ZGNTUWC4.js +22 -0
  230. package/dist/renderer-ZTR3DER3.js +19 -0
  231. package/dist/renderer-radial-C32GPJQ7.js +21 -0
  232. package/dist/resolver-NOAA7ID7.js +13 -0
  233. package/dist/state-collapse-HCGD6IVJ.js +8 -0
  234. package/dist/state-parser-Z2V23ATR.js +18 -0
  235. package/dist/state-renderer-RFYHSP4K.js +34 -0
  236. package/dist/themes-1-CuKpeH.d.cts +908 -0
  237. package/dist/themes-1-CuKpeH.d.ts +908 -0
  238. package/package.json +1 -1
  239. package/src/auto/index.ts +55 -57
  240. package/src/auto/shared.ts +142 -142
  241. package/src/auto/styles.ts +44 -199
  242. package/src/c4/renderer.ts +2 -2
  243. package/src/element/index.ts +29 -21
  244. package/src/infra/renderer.ts +1 -1
  245. package/src/render.ts +34 -14
  246. package/src/sitemap/renderer.ts +1 -1
  247. package/src/timeline/renderer.ts +1 -1
  248. package/src/utils/hover-styles.ts +6 -1
  249. package/src/utils/legend-d3.ts +1 -4
  250. package/src/utils/legend-svg.ts +1 -1
@@ -0,0 +1,692 @@
1
+ import {
2
+ NODE_HEIGHT,
3
+ NODE_WIDTH
4
+ } from "./chunk-IJZFN3HM.js";
5
+
6
+ // src/boxes-and-lines/layout-grouped.ts
7
+ var NODESEP = 50;
8
+ var RANKSEP = 60;
9
+ var DUMMY_THICK = 10;
10
+ var MARGIN = 40;
11
+ var GROUP_PAD = 16;
12
+ var GROUP_LABEL_ZONE = 32;
13
+ var GROUP_GAP = 24;
14
+ var TIER_GAP = GROUP_LABEL_ZONE + 2 * GROUP_PAD;
15
+ var W_REAL_REAL = 1;
16
+ var W_REAL_DUMMY = 2;
17
+ var W_DUMMY_DUMMY = 8;
18
+ function rng(s) {
19
+ return () => {
20
+ s |= 0;
21
+ s = s + 1831565813 | 0;
22
+ let t = Math.imul(s ^ s >>> 15, 1 | s);
23
+ t = t + Math.imul(t ^ t >>> 7, 61 | t) ^ t;
24
+ return ((t ^ t >>> 14) >>> 0) / 4294967296;
25
+ };
26
+ }
27
+ function median(vals) {
28
+ if (vals.length === 0) return -1;
29
+ vals.sort((x, y) => x - y);
30
+ const m = Math.floor(vals.length / 2);
31
+ if (vals.length % 2 === 1) return vals[m];
32
+ if (vals.length === 2) return (vals[0] + vals[1]) / 2;
33
+ const left = vals[m - 1] - vals[0];
34
+ const right = vals[vals.length - 1] - vals[m];
35
+ return left + right === 0 ? (vals[m - 1] + vals[m]) / 2 : (vals[m - 1] * right + vals[m] * left) / (left + right);
36
+ }
37
+ function acyclicOrient(ids, edges) {
38
+ const adj = /* @__PURE__ */ new Map();
39
+ for (const l of ids) adj.set(l, []);
40
+ for (const e of edges) adj.get(e.from)?.push({ to: e.to, idx: e.idx });
41
+ const reversed = /* @__PURE__ */ new Set();
42
+ const state = /* @__PURE__ */ new Map();
43
+ for (const l of ids) state.set(l, 0);
44
+ const stack = [];
45
+ const visit = (root) => {
46
+ stack.push(root);
47
+ const it = /* @__PURE__ */ new Map();
48
+ while (stack.length) {
49
+ const u = stack[stack.length - 1];
50
+ if (state.get(u) === 0) state.set(u, 1);
51
+ const list = adj.get(u);
52
+ let i = it.get(u) ?? 0;
53
+ let descended = false;
54
+ for (; i < list.length; i++) {
55
+ const { to, idx } = list[i];
56
+ const st = state.get(to);
57
+ if (st === 1) reversed.add(idx);
58
+ else if (st === 0) {
59
+ it.set(u, i + 1);
60
+ stack.push(to);
61
+ descended = true;
62
+ break;
63
+ }
64
+ }
65
+ if (!descended) {
66
+ it.set(u, list.length);
67
+ state.set(u, 2);
68
+ stack.pop();
69
+ }
70
+ }
71
+ };
72
+ for (const l of ids) if (state.get(l) === 0) visit(l);
73
+ const dag = edges.map(
74
+ (e) => reversed.has(e.idx) ? { from: e.to, to: e.from, idx: e.idx, rev: true } : { from: e.from, to: e.to, idx: e.idx, rev: false }
75
+ );
76
+ return { dag };
77
+ }
78
+ function longestPath(ids, dag) {
79
+ const out = /* @__PURE__ */ new Map();
80
+ const inDeg = /* @__PURE__ */ new Map();
81
+ for (const l of ids) {
82
+ out.set(l, []);
83
+ inDeg.set(l, 0);
84
+ }
85
+ for (const d of dag) {
86
+ out.get(d.from).push(d.to);
87
+ inDeg.set(d.to, (inDeg.get(d.to) ?? 0) + 1);
88
+ }
89
+ const rank = /* @__PURE__ */ new Map();
90
+ for (const l of ids) rank.set(l, 0);
91
+ const queue = ids.filter((l) => (inDeg.get(l) ?? 0) === 0);
92
+ const indeg2 = new Map(inDeg);
93
+ let seen = 0;
94
+ while (queue.length) {
95
+ const u = queue.shift();
96
+ seen++;
97
+ for (const v of out.get(u)) {
98
+ rank.set(v, Math.max(rank.get(v), rank.get(u) + 1));
99
+ indeg2.set(v, indeg2.get(v) - 1);
100
+ if (indeg2.get(v) === 0) queue.push(v);
101
+ }
102
+ }
103
+ return seen === ids.length ? rank : null;
104
+ }
105
+ function groupedTierCandidates(parsed, sizes, opts) {
106
+ if (parsed.groups.length === 0) return [];
107
+ const nCount = parsed.nodes.length;
108
+ if (nCount < 3 || nCount > 60) return [];
109
+ const isTB = parsed.direction === "TB";
110
+ const labels = parsed.nodes.map((n) => n.label);
111
+ const labelSet = new Set(labels);
112
+ for (const e of parsed.edges)
113
+ if (e.source.startsWith("__group_") || e.target.startsWith("__group_"))
114
+ return [];
115
+ const groupByLabel = new Map(parsed.groups.map((g) => [g.label, g]));
116
+ const directGroupOf = /* @__PURE__ */ new Map();
117
+ for (const grp of parsed.groups)
118
+ for (const c of grp.children)
119
+ if (labelSet.has(c)) directGroupOf.set(c, grp.label);
120
+ const topGroupOf = (groupLabel) => {
121
+ let cur = groupLabel;
122
+ const guard = /* @__PURE__ */ new Set();
123
+ while (true) {
124
+ const g = groupByLabel.get(cur);
125
+ if (!g?.parentGroup || guard.has(cur)) return cur;
126
+ guard.add(cur);
127
+ cur = g.parentGroup;
128
+ }
129
+ };
130
+ const pathOf = (label) => {
131
+ const direct = directGroupOf.get(label);
132
+ if (!direct) return [];
133
+ const chain = [direct];
134
+ let cur = direct;
135
+ const guard = /* @__PURE__ */ new Set([direct]);
136
+ while (true) {
137
+ const g = groupByLabel.get(cur);
138
+ if (!g?.parentGroup || guard.has(g.parentGroup)) break;
139
+ chain.push(g.parentGroup);
140
+ guard.add(g.parentGroup);
141
+ cur = g.parentGroup;
142
+ }
143
+ return chain.reverse();
144
+ };
145
+ const SINGLE = "\0node\0";
146
+ const unitOf = (label) => {
147
+ const direct = directGroupOf.get(label);
148
+ return direct ? topGroupOf(direct) : SINGLE + label;
149
+ };
150
+ const edges = parsed.edges.map((e, i) => ({ e, i })).filter(
151
+ ({ e }) => labelSet.has(e.source) && labelSet.has(e.target) && e.source !== e.target
152
+ );
153
+ if (edges.length === 0) return [];
154
+ const unitOfNode = /* @__PURE__ */ new Map();
155
+ for (const l of labels) unitOfNode.set(l, unitOf(l));
156
+ const units = Array.from(new Set(labels.map((l) => unitOfNode.get(l))));
157
+ const interUnit = edges.filter(({ e }) => unitOfNode.get(e.source) !== unitOfNode.get(e.target)).map(({ e, i }) => ({
158
+ from: unitOfNode.get(e.source),
159
+ to: unitOfNode.get(e.target),
160
+ idx: i
161
+ }));
162
+ const { dag: unitDag } = acyclicOrient(units, interUnit);
163
+ const tier = longestPath(
164
+ units,
165
+ unitDag.map((d) => ({ from: d.from, to: d.to }))
166
+ );
167
+ if (!tier) return [];
168
+ const localRank = /* @__PURE__ */ new Map();
169
+ const unitMembers = /* @__PURE__ */ new Map();
170
+ for (const l of labels) {
171
+ const u = unitOfNode.get(l);
172
+ (unitMembers.get(u) ?? unitMembers.set(u, []).get(u)).push(l);
173
+ }
174
+ for (const [u, members] of unitMembers) {
175
+ const memberSet = new Set(members);
176
+ const intra = edges.filter(
177
+ ({ e }) => unitOfNode.get(e.source) === u && unitOfNode.get(e.target) === u && memberSet.has(e.source) && memberSet.has(e.target)
178
+ ).map(({ e, i }) => ({ from: e.source, to: e.target, idx: i }));
179
+ const { dag } = acyclicOrient(members, intra);
180
+ const lr = longestPath(
181
+ members,
182
+ dag.map((d) => ({ from: d.from, to: d.to }))
183
+ );
184
+ if (!lr) return [];
185
+ for (const m of members) localRank.set(m, lr.get(m));
186
+ }
187
+ const maxTier = Math.max(...units.map((u) => tier.get(u)));
188
+ const bandHeight = Array.from({ length: maxTier + 1 }, () => 1);
189
+ for (const u of units) {
190
+ const h = Math.max(
191
+ ...unitMembers.get(u).map((m) => localRank.get(m) + 1)
192
+ );
193
+ const t = tier.get(u);
194
+ bandHeight[t] = Math.max(bandHeight[t], h);
195
+ }
196
+ const tierBase = [];
197
+ let accBase = 0;
198
+ for (let t = 0; t <= maxTier; t++) {
199
+ tierBase[t] = accBase;
200
+ accBase += bandHeight[t];
201
+ }
202
+ const tierStartRanks = new Set(tierBase.slice(1));
203
+ const globalRank = /* @__PURE__ */ new Map();
204
+ for (const l of labels)
205
+ globalRank.set(
206
+ l,
207
+ tierBase[tier.get(unitOfNode.get(l))] + localRank.get(l)
208
+ );
209
+ const maxRank = Math.max(...labels.map((l) => globalRank.get(l)));
210
+ const node = /* @__PURE__ */ new Map();
211
+ for (const n of parsed.nodes) {
212
+ const s = sizes.get(n.label) ?? { width: NODE_WIDTH, height: NODE_HEIGHT };
213
+ node.set(n.label, {
214
+ id: n.label,
215
+ dummy: false,
216
+ rank: globalRank.get(n.label),
217
+ cross: 0,
218
+ thick: isTB ? s.width : s.height,
219
+ depth: isTB ? s.height : s.width,
220
+ realW: s.width,
221
+ realH: s.height,
222
+ unit: unitOfNode.get(n.label),
223
+ path: pathOf(n.label)
224
+ });
225
+ }
226
+ const chains = [];
227
+ const segs = [];
228
+ const backEdges = [];
229
+ const flatEdges = [];
230
+ for (const { e, i } of edges) {
231
+ const rs = globalRank.get(e.source);
232
+ const rt = globalRank.get(e.target);
233
+ if (rs === rt) {
234
+ flatEdges.push({ edgeIdx: i, a: e.source, b: e.target });
235
+ continue;
236
+ }
237
+ if (rt < rs) {
238
+ backEdges.push({ edgeIdx: i, src: e.source, tgt: e.target });
239
+ continue;
240
+ }
241
+ const chain = [e.source];
242
+ let prev = e.source;
243
+ for (let r = rs + 1; r < rt; r++) {
244
+ const id = `__d${i}_${r}`;
245
+ node.set(id, {
246
+ id,
247
+ dummy: true,
248
+ rank: r,
249
+ cross: 0,
250
+ thick: DUMMY_THICK,
251
+ depth: 0,
252
+ realW: 0,
253
+ realH: 0,
254
+ unit: SINGLE + id,
255
+ path: []
256
+ });
257
+ segs.push({ a: prev, b: id });
258
+ chain.push(id);
259
+ prev = id;
260
+ }
261
+ segs.push({ a: prev, b: e.target });
262
+ chain.push(e.target);
263
+ chains.push({ edgeIdx: i, chain });
264
+ }
265
+ const ranks = Array.from({ length: maxRank + 1 }, () => []);
266
+ for (const n of node.values()) ranks[n.rank].push(n.id);
267
+ const up = /* @__PURE__ */ new Map();
268
+ const down = /* @__PURE__ */ new Map();
269
+ for (const id of node.keys()) {
270
+ up.set(id, []);
271
+ down.set(id, []);
272
+ }
273
+ for (const s of segs) {
274
+ down.get(s.a).push(s.b);
275
+ up.get(s.b).push(s.a);
276
+ }
277
+ const orderOf = /* @__PURE__ */ new Map();
278
+ const gapCrossings = (r) => {
279
+ const lower = ranks[r + 1];
280
+ if (!lower) return 0;
281
+ const es = [];
282
+ for (const a of ranks[r]) {
283
+ const pa = orderOf.get(a);
284
+ for (const b of down.get(a)) es.push({ p: pa, q: orderOf.get(b) });
285
+ }
286
+ let c = 0;
287
+ for (let i = 0; i < es.length; i++)
288
+ for (let j = i + 1; j < es.length; j++) {
289
+ const A = es[i], B = es[j];
290
+ if ((A.p - B.p) * (A.q - B.q) < 0) c++;
291
+ }
292
+ return c;
293
+ };
294
+ const totalCrossings = () => {
295
+ let c = 0;
296
+ for (let r = 0; r < maxRank; r++) c += gapCrossings(r);
297
+ return c;
298
+ };
299
+ const wmedianRank = (r, useUp) => {
300
+ const ids = ranks[r];
301
+ const neigh = useUp ? up : down;
302
+ const med = /* @__PURE__ */ new Map();
303
+ for (const id of ids)
304
+ med.set(id, median(neigh.get(id).map((x) => orderOf.get(x))));
305
+ const movable = ids.filter((id) => med.get(id) >= 0).sort((a, b) => med.get(a) - med.get(b));
306
+ const out = new Array(ids.length).fill(null);
307
+ for (const id of ids) if (med.get(id) < 0) out[orderOf.get(id)] = id;
308
+ let mi = 0;
309
+ for (let slot = 0; slot < out.length; slot++)
310
+ if (out[slot] === null) out[slot] = movable[mi++];
311
+ const final = out;
312
+ final.forEach((id, i) => orderOf.set(id, i));
313
+ ranks[r] = final;
314
+ };
315
+ const transpose = () => {
316
+ let improved = true;
317
+ let guard = 0;
318
+ while (improved && guard++ < 12) {
319
+ improved = false;
320
+ for (let r = 0; r <= maxRank; r++) {
321
+ const ids = ranks[r];
322
+ for (let i = 0; i < ids.length - 1; i++) {
323
+ const before = (r > 0 ? gapCrossings(r - 1) : 0) + (r < maxRank ? gapCrossings(r) : 0);
324
+ const a = ids[i], b = ids[i + 1];
325
+ ids[i] = b;
326
+ ids[i + 1] = a;
327
+ orderOf.set(b, i);
328
+ orderOf.set(a, i + 1);
329
+ const after = (r > 0 ? gapCrossings(r - 1) : 0) + (r < maxRank ? gapCrossings(r) : 0);
330
+ if (after < before) improved = true;
331
+ else {
332
+ ids[i] = a;
333
+ ids[i + 1] = b;
334
+ orderOf.set(a, i);
335
+ orderOf.set(b, i + 1);
336
+ }
337
+ }
338
+ }
339
+ }
340
+ };
341
+ const initOrder = (seed) => {
342
+ const r = seed === 0 ? null : rng(seed);
343
+ for (let rr = 0; rr <= maxRank; rr++) {
344
+ const ids = ranks[rr].slice();
345
+ if (r)
346
+ for (let i = ids.length - 1; i > 0; i--) {
347
+ const j = Math.floor(r() * (i + 1));
348
+ [ids[i], ids[j]] = [ids[j], ids[i]];
349
+ }
350
+ ranks[rr] = ids;
351
+ ids.forEach((id, i) => orderOf.set(id, i));
352
+ }
353
+ };
354
+ const restarts = opts?.restarts ?? (nCount <= 16 ? 20 : nCount <= 30 ? 12 : 6);
355
+ const keepK = opts?.keepK ?? 3;
356
+ const found = [];
357
+ for (let s = 0; s < restarts; s++) {
358
+ initOrder(s);
359
+ let best = totalCrossings();
360
+ let bestSnap = new Map(orderOf);
361
+ for (let iter = 0; iter < 8; iter++) {
362
+ if (iter % 2 === 0)
363
+ for (let r = 1; r <= maxRank; r++) wmedianRank(r, true);
364
+ else for (let r = maxRank - 1; r >= 0; r--) wmedianRank(r, false);
365
+ transpose();
366
+ const c = totalCrossings();
367
+ if (c < best) {
368
+ best = c;
369
+ bestSnap = new Map(orderOf);
370
+ }
371
+ if (c === 0) break;
372
+ }
373
+ for (const [k, v] of bestSnap) orderOf.set(k, v);
374
+ for (let r = 0; r <= maxRank; r++)
375
+ ranks[r].sort((a, b) => orderOf.get(a) - orderOf.get(b));
376
+ const sig = ranks.map((r) => r.join(",")).join("|");
377
+ if (!found.some((f) => f.sig === sig))
378
+ found.push({ sig, cross: best, order: new Map(bestSnap) });
379
+ }
380
+ found.sort((a, b) => a.cross - b.cross);
381
+ const keep = found.slice(0, keepK);
382
+ if (keep.length === 0) return [];
383
+ const results = [];
384
+ for (const cand of keep) {
385
+ for (const [k, v] of cand.order) orderOf.set(k, v);
386
+ const rk = Array.from({ length: maxRank + 1 }, () => []);
387
+ for (const n of node.values()) rk[n.rank].push(n.id);
388
+ for (let r = 0; r <= maxRank; r++)
389
+ rk[r].sort((a, b) => cand.order.get(a) - cand.order.get(b));
390
+ results.push(realize(rk));
391
+ }
392
+ return results;
393
+ function weight(a, b) {
394
+ if (a.dummy && b.dummy) return W_DUMMY_DUMMY;
395
+ if (a.dummy || b.dummy) return W_REAL_DUMMY;
396
+ return W_REAL_REAL;
397
+ }
398
+ function placeWithSeparation(ids, desired, gap) {
399
+ const n = ids.length;
400
+ if (n === 0) return;
401
+ const off = [0];
402
+ for (let i = 1; i < n; i++) off[i] = off[i - 1] + gap[i];
403
+ const d = desired.map((v, i) => v - off[i]);
404
+ const blocks = [];
405
+ for (let i = 0; i < n; i++) {
406
+ let b = { pos: d[i], count: 1, sumOffset: d[i], first: i };
407
+ while (blocks.length && blocks[blocks.length - 1].pos >= b.pos) {
408
+ const prev = blocks.pop();
409
+ const count = prev.count + b.count;
410
+ const sumOffset = prev.sumOffset + b.sumOffset;
411
+ b = { pos: sumOffset / count, count, sumOffset, first: prev.first };
412
+ }
413
+ blocks.push(b);
414
+ }
415
+ const xs = new Array(n);
416
+ for (const b of blocks)
417
+ for (let k = 0; k < b.count; k++) xs[b.first + k] = b.pos;
418
+ for (let i = 0; i < n; i++) node.get(ids[i]).cross = xs[i] + off[i];
419
+ }
420
+ function gapBetween(a, b) {
421
+ const base = a.thick / 2 + b.thick / 2 + NODESEP;
422
+ if (a.dummy || b.dummy) return base;
423
+ if (a.unit !== b.unit) return base + 2 * GROUP_PAD + GROUP_GAP;
424
+ const da = a.path[a.path.length - 1];
425
+ const db = b.path[b.path.length - 1];
426
+ if (da !== db && (da || db)) return base + 2 * GROUP_PAD;
427
+ return base;
428
+ }
429
+ function realize(rk) {
430
+ const bandDepth = rk.map(
431
+ (ids) => Math.max(0, ...ids.map((id) => node.get(id).depth))
432
+ );
433
+ const bandCenter = [];
434
+ let acc = MARGIN;
435
+ for (let r = 0; r <= maxRank; r++) {
436
+ if (r > 0) acc += RANKSEP + (tierStartRanks.has(r) ? TIER_GAP : 0);
437
+ bandCenter[r] = acc + bandDepth[r] / 2;
438
+ acc += bandDepth[r];
439
+ }
440
+ const gapsFor = (ids) => ids.map(
441
+ (id, i) => i === 0 ? 0 : gapBetween(node.get(ids[i - 1]), node.get(id))
442
+ );
443
+ for (let r = 0; r <= maxRank; r++) {
444
+ const ids = rk[r];
445
+ const gap = gapsFor(ids);
446
+ let x = MARGIN;
447
+ for (let i = 0; i < ids.length; i++) {
448
+ const n = node.get(ids[i]);
449
+ x += gap[i];
450
+ n.cross = i === 0 ? MARGIN + n.thick / 2 : x;
451
+ }
452
+ }
453
+ const ITER = 18;
454
+ for (let it = 0; it < ITER; it++) {
455
+ const downPass = it % 2 === 0;
456
+ const order = downPass ? Array.from({ length: maxRank + 1 }, (_, i) => i) : Array.from({ length: maxRank + 1 }, (_, i) => maxRank - i);
457
+ for (const r of order) {
458
+ const ids = rk[r];
459
+ const desired = ids.map((id) => {
460
+ const n = node.get(id);
461
+ let sw = 0, sx2 = 0;
462
+ for (const nb of up.get(id)) {
463
+ const w = weight(n, node.get(nb));
464
+ sw += w;
465
+ sx2 += w * node.get(nb).cross;
466
+ }
467
+ for (const nb of down.get(id)) {
468
+ const w = weight(n, node.get(nb));
469
+ sw += w;
470
+ sx2 += w * node.get(nb).cross;
471
+ }
472
+ return sw > 0 ? sx2 / sw : n.cross;
473
+ });
474
+ placeWithSeparation(ids, desired, gapsFor(ids));
475
+ }
476
+ }
477
+ let minC = Infinity;
478
+ for (const n of node.values()) minC = Math.min(minC, n.cross - n.thick / 2);
479
+ const shiftC = MARGIN - minC;
480
+ for (const n of node.values()) n.cross += shiftC;
481
+ const coord = (n) => isTB ? { x: n.cross, y: bandCenter[n.rank] } : { x: bandCenter[n.rank], y: n.cross };
482
+ const layoutNodes = parsed.nodes.map((pn) => {
483
+ const n = node.get(pn.label);
484
+ const c = coord(n);
485
+ return {
486
+ label: pn.label,
487
+ x: c.x,
488
+ y: c.y,
489
+ width: n.realW,
490
+ height: n.realH
491
+ };
492
+ });
493
+ const chainById = /* @__PURE__ */ new Map();
494
+ for (const ch of chains) chainById.set(ch.edgeIdx, ch.chain);
495
+ let minCross = Infinity, maxCross = -Infinity;
496
+ for (const n of node.values()) {
497
+ if (n.dummy) continue;
498
+ minCross = Math.min(minCross, n.cross - n.thick / 2);
499
+ maxCross = Math.max(maxCross, n.cross + n.thick / 2);
500
+ }
501
+ const GAP = 34;
502
+ const LANE = 28;
503
+ const faceLim = (depth) => Math.max(0, depth / 2 - 6);
504
+ const sideOf = (b) => {
505
+ const d = node.get(b.src).cross - node.get(b.tgt).cross;
506
+ return d >= 0 ? 1 : -1;
507
+ };
508
+ const backSorted = backEdges.map((b) => ({
509
+ ...b,
510
+ side: sideOf(b),
511
+ span: Math.abs(node.get(b.src).rank - node.get(b.tgt).rank)
512
+ })).sort((a, b) => a.side - b.side || a.span - b.span);
513
+ const sideCounts = /* @__PURE__ */ new Map();
514
+ for (const b of backSorted)
515
+ sideCounts.set(b.side, (sideCounts.get(b.side) ?? 0) + 1);
516
+ const laneCounter = /* @__PURE__ */ new Map();
517
+ const backPoints = /* @__PURE__ */ new Map();
518
+ for (const b of backSorted) {
519
+ const s = b.side;
520
+ const k = laneCounter.get(s) ?? 0;
521
+ laneCounter.set(s, k + 1);
522
+ const K = sideCounts.get(s);
523
+ const src = node.get(b.src);
524
+ const tgt = node.get(b.tgt);
525
+ const laneC = s > 0 ? maxCross + GAP + k * LANE : minCross - GAP - k * LANE;
526
+ const srcCtr = bandCenter[src.rank];
527
+ const tgtCtr = bandCenter[tgt.rank];
528
+ const frac = K > 1 ? (k + 1) / (K + 1) : 0;
529
+ const srcR = srcCtr - frac * faceLim(src.depth);
530
+ const tgtR = tgtCtr + frac * faceLim(tgt.depth);
531
+ const m = (c, rr) => isTB ? { x: c, y: rr } : { x: rr, y: c };
532
+ const off = 10;
533
+ const srcEdgeC = src.cross + s * (src.thick / 2 + off);
534
+ const tgtEdgeC = tgt.cross + s * (tgt.thick / 2 + off);
535
+ backPoints.set(b.edgeIdx, [
536
+ m(src.cross, srcCtr),
537
+ m(srcEdgeC, srcR),
538
+ m(laneC, srcR),
539
+ m(laneC, tgtR),
540
+ m(tgtEdgeC, tgtR),
541
+ m(tgt.cross, tgtCtr)
542
+ ]);
543
+ }
544
+ const flatPoints = /* @__PURE__ */ new Map();
545
+ for (const f of flatEdges) {
546
+ const a = node.get(f.a);
547
+ const b = node.get(f.b);
548
+ const ctr = bandCenter[a.rank];
549
+ const bow = ctr - (a.depth / 2 + 26);
550
+ const m = (c, rr) => isTB ? { x: c, y: rr } : { x: rr, y: c };
551
+ flatPoints.set(f.edgeIdx, [
552
+ m(a.cross, ctr),
553
+ m(a.cross, bow),
554
+ m(b.cross, bow),
555
+ m(b.cross, ctr)
556
+ ]);
557
+ }
558
+ const layoutEdges = [];
559
+ for (let i = 0; i < parsed.edges.length; i++) {
560
+ const e = parsed.edges[i];
561
+ if (!labelSet.has(e.source) || !labelSet.has(e.target)) continue;
562
+ let points;
563
+ if (e.source === e.target) {
564
+ const c = coord(node.get(e.source));
565
+ points = [c, c];
566
+ } else if (backPoints.has(i)) points = backPoints.get(i);
567
+ else if (flatPoints.has(i)) points = flatPoints.get(i);
568
+ else {
569
+ const chain = chainById.get(i);
570
+ if (!chain) continue;
571
+ points = chain.map((id) => coord(node.get(id)));
572
+ }
573
+ layoutEdges.push({
574
+ source: e.source,
575
+ target: e.target,
576
+ ...e.label !== void 0 && { label: e.label },
577
+ bidirectional: e.bidirectional,
578
+ lineNumber: e.lineNumber,
579
+ points,
580
+ yOffset: 0,
581
+ parallelCount: 1,
582
+ metadata: e.metadata
583
+ });
584
+ }
585
+ const nodeBox = new Map(
586
+ layoutNodes.map((n) => [
587
+ n.label,
588
+ {
589
+ l: n.x - n.width / 2,
590
+ r: n.x + n.width / 2,
591
+ t: n.y - n.height / 2,
592
+ b: n.y + n.height / 2
593
+ }
594
+ ])
595
+ );
596
+ const depthOf = (label) => {
597
+ let d = 0;
598
+ let cur = label;
599
+ const guard = /* @__PURE__ */ new Set();
600
+ while (cur && !guard.has(cur)) {
601
+ guard.add(cur);
602
+ cur = groupByLabel.get(cur)?.parentGroup;
603
+ if (cur) d++;
604
+ }
605
+ return d;
606
+ };
607
+ const childGroups = /* @__PURE__ */ new Map();
608
+ for (const g of parsed.groups)
609
+ if (g.parentGroup)
610
+ (childGroups.get(g.parentGroup) ?? childGroups.set(g.parentGroup, []).get(g.parentGroup)).push(g.label);
611
+ const rectByGroup = /* @__PURE__ */ new Map();
612
+ const ordered = [...parsed.groups].sort(
613
+ (a, b) => depthOf(b.label) - depthOf(a.label)
614
+ );
615
+ const layoutGroups = [];
616
+ for (const grp of ordered) {
617
+ let l = Infinity, r = -Infinity, t = Infinity, bm = -Infinity;
618
+ const acc2 = (box) => {
619
+ l = Math.min(l, box.l);
620
+ r = Math.max(r, box.r);
621
+ t = Math.min(t, box.t);
622
+ bm = Math.max(bm, box.b);
623
+ };
624
+ for (const c of grp.children) {
625
+ const nb = nodeBox.get(c);
626
+ if (nb) acc2(nb);
627
+ }
628
+ for (const sub of childGroups.get(grp.label) ?? []) {
629
+ const sr = rectByGroup.get(sub);
630
+ if (sr) acc2(sr);
631
+ }
632
+ if (!Number.isFinite(l)) continue;
633
+ const x0 = l - GROUP_PAD;
634
+ const x1 = r + GROUP_PAD;
635
+ const y0 = t - GROUP_LABEL_ZONE;
636
+ const y1 = bm + GROUP_PAD;
637
+ rectByGroup.set(grp.label, { l: x0, r: x1, t: y0, b: y1 });
638
+ layoutGroups.push({
639
+ label: grp.label,
640
+ lineNumber: grp.lineNumber,
641
+ x: (x0 + x1) / 2,
642
+ y: (y0 + y1) / 2,
643
+ width: x1 - x0,
644
+ height: y1 - y0,
645
+ collapsed: false,
646
+ childCount: grp.children.length
647
+ });
648
+ }
649
+ let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
650
+ const ext = (x0, y0, x1, y1) => {
651
+ minX = Math.min(minX, x0);
652
+ minY = Math.min(minY, y0);
653
+ maxX = Math.max(maxX, x1);
654
+ maxY = Math.max(maxY, y1);
655
+ };
656
+ for (const n of layoutNodes)
657
+ ext(
658
+ n.x - n.width / 2,
659
+ n.y - n.height / 2,
660
+ n.x + n.width / 2,
661
+ n.y + n.height / 2
662
+ );
663
+ for (const e of layoutEdges)
664
+ for (const p of e.points) ext(p.x, p.y, p.x, p.y);
665
+ for (const g of layoutGroups)
666
+ ext(
667
+ g.x - g.width / 2,
668
+ g.y - g.height / 2,
669
+ g.x + g.width / 2,
670
+ g.y + g.height / 2
671
+ );
672
+ const sx = MARGIN - minX;
673
+ const sy = MARGIN - minY;
674
+ const shift = sx !== 0 || sy !== 0;
675
+ return {
676
+ nodes: shift ? layoutNodes.map((n) => ({ ...n, x: n.x + sx, y: n.y + sy })) : layoutNodes,
677
+ edges: shift ? layoutEdges.map((e) => ({
678
+ ...e,
679
+ points: e.points.map((p) => ({ x: p.x + sx, y: p.y + sy }))
680
+ })) : layoutEdges,
681
+ groups: shift ? layoutGroups.map((g) => ({ ...g, x: g.x + sx, y: g.y + sy })) : layoutGroups,
682
+ width: maxX + sx + MARGIN,
683
+ height: maxY + sy + MARGIN
684
+ };
685
+ }
686
+ }
687
+
688
+ export {
689
+ acyclicOrient,
690
+ groupedTierCandidates
691
+ };
692
+ //# sourceMappingURL=chunk-YGJTDXVR.js.map