@draftably/mermaid 0.2.1 → 0.2.3

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.
@@ -0,0 +1,4157 @@
1
+ import { MERMAID_VERSION as cn } from "./mermaid-facade-BoLWBerE.mjs";
2
+ const _o = {
3
+ "sans-500": { unitsPerEm: 1e3, fallback: 1003, advances: { 0: 646, 1: 415, 2: 616, 3: 627, 4: 656, 5: 603, 6: 630, 7: 571, 8: 629, 9: 630, " ": 267, "!": 304, '"': 494, "#": 639, $: 646, "%": 993, "&": 653, "'": 313, "(": 369, ")": 369, "*": 521, "+": 667, ",": 303, "-": 462, ".": 303, "/": 370, ":": 303, ";": 315, "<": 667, "=": 667, ">": 667, "?": 527, "@": 982, A: 709, B: 657, C: 733, D: 722, E: 603, F: 589, G: 748, H: 745, I: 272, J: 575, K: 688, L: 565, M: 913, N: 756, O: 767, P: 642, Q: 769, R: 648, S: 646, T: 653, U: 740, V: 709, W: 1003, X: 701, Y: 696, Z: 641, "[": 369, "\\": 370, "]": 369, "^": 477, _: 463, "`": 337, a: 568, b: 618, c: 577, d: 618, e: 587, f: 379, g: 620, h: 602, i: 252, j: 252, k: 559, l: 252, m: 888, n: 602, o: 604, p: 618, q: 618, r: 387, s: 539, t: 340, u: 602, v: 575, w: 829, x: 557, y: 575, z: 559, "{": 440, "|": 346, "}": 440, "~": 667, " ": 267, "¡": 304, "¢": 577, "£": 620, "¤": 737, "¥": 557, "¦": 293, "§": 568, "¨": 602, "©": 914, ª: 457, "«": 608, "¬": 667, "­": 0, "®": 665, "¯": 465, "°": 457, "±": 667, "²": 448, "³": 455, "´": 337, µ: 600, "¶": 601, "·": 303, "¸": 300, "¹": 314, º: 485, "»": 608, "¼": 817, "½": 858, "¾": 895, "¿": 527, À: 709, Á: 709, Â: 709, Ã: 709, Ä: 709, Å: 709, Æ: 1003, Ç: 733, È: 603, É: 603, Ê: 603, Ë: 603, Ì: 272, Í: 272, Î: 272, Ï: 272, Ð: 743, Ñ: 756, Ò: 767, Ó: 767, Ô: 767, Õ: 767, Ö: 767, "×": 667, Ø: 767, Ù: 740, Ú: 740, Û: 740, Ü: 740, Ý: 696, Þ: 647, ß: 630, à: 568, á: 568, â: 568, ã: 568, ä: 568, å: 568, æ: 915, ç: 577, è: 587, é: 587, ê: 587, ë: 587, ì: 252, í: 252, î: 252, ï: 252, ð: 588, ñ: 602, ò: 604, ó: 604, ô: 604, õ: 604, ö: 604, "÷": 667, ø: 604, ù: 602, ú: 602, û: 602, ü: 602, ý: 575, þ: 618, ÿ: 575, "‘": 277, "’": 277, "“": 474, "”": 471, "–": 500, "—": 1e3, "…": 910, "•": 533, "→": 1e3, "←": 1e3, "≤": 549, "≥": 549, "≠": 549, "€": 672 } },
4
+ "sans-600": { unitsPerEm: 1e3, fallback: 1020, advances: { 0: 660, 1: 423, 2: 623, 3: 636, 4: 666, 5: 612, 6: 640, 7: 576, 8: 640, 9: 640, " ": 252, "!": 321, '"': 523, "#": 644, $: 650, "%": 1004, "&": 663, "'": 326, "(": 373, ")": 373, "*": 540, "+": 673, ",": 319, "-": 465, ".": 319, "/": 379, ":": 319, ";": 329, "<": 673, "=": 673, ">": 673, "?": 543, "@": 999, A: 728, B: 659, C: 737, D: 722, E: 605, F: 588, G: 749, H: 746, I: 277, J: 580, K: 703, L: 565, M: 922, N: 759, O: 769, P: 645, Q: 773, R: 652, S: 650, T: 660, U: 736, V: 728, W: 1020, X: 720, Y: 713, Z: 652, "[": 373, "\\": 379, "]": 373, "^": 481, _: 469, "`": 351, a: 574, b: 624, c: 583, d: 624, e: 591, f: 389, g: 625, h: 612, i: 262, j: 262, k: 569, l: 262, m: 900, n: 612, o: 609, p: 624, q: 624, r: 397, s: 549, t: 353, u: 612, v: 587, w: 839, x: 569, y: 588, z: 566, "{": 455, "|": 359, "}": 455, "~": 673, " ": 252, "¡": 321, "¢": 583, "£": 629, "¤": 749, "¥": 563, "¦": 316, "§": 568, "¨": 612, "©": 914, ª: 460, "«": 634, "¬": 673, "­": 0, "®": 664, "¯": 452, "°": 458, "±": 673, "²": 454, "³": 463, "´": 351, µ: 614, "¶": 600, "·": 319, "¸": 332, "¹": 324, º: 487, "»": 634, "¼": 831, "½": 870, "¾": 907, "¿": 543, À: 728, Á: 728, Â: 728, Ã: 728, Ä: 728, Å: 728, Æ: 1013, Ç: 737, È: 605, É: 605, Ê: 605, Ë: 605, Ì: 277, Í: 277, Î: 277, Ï: 277, Ð: 751, Ñ: 759, Ò: 769, Ó: 769, Ô: 769, Õ: 769, Ö: 769, "×": 673, Ø: 769, Ù: 736, Ú: 736, Û: 736, Ü: 736, Ý: 713, Þ: 658, ß: 644, à: 574, á: 574, â: 574, ã: 574, ä: 574, å: 574, æ: 913, ç: 583, è: 591, é: 591, ê: 591, ë: 591, ì: 262, í: 262, î: 262, ï: 262, ð: 594, ñ: 612, ò: 609, ó: 609, ô: 609, õ: 609, ö: 609, "÷": 673, ø: 609, ù: 612, ú: 612, û: 612, ü: 612, ý: 588, þ: 624, ÿ: 588, "‘": 294, "’": 294, "“": 507, "”": 501, "–": 500, "—": 1e3, "…": 956, "•": 503, "→": 1e3, "←": 1e3, "≤": 549, "≥": 549, "≠": 549, "€": 679 } },
5
+ "serif-600": { unitsPerEm: 1e3, fallback: 1020, advances: { 0: 547, 1: 547, 2: 547, 3: 547, 4: 547, 5: 547, 6: 547, 7: 547, 8: 547, 9: 547, " ": 228, "!": 314, '"': 423, "#": 544, $: 538, "%": 949, "&": 739, "'": 206, "(": 384, ")": 384, "*": 458, "+": 548, ",": 307, "-": 335, ".": 307, "/": 364, ":": 307, ";": 307, "<": 548, "=": 548, ">": 548, "?": 430, "@": 867, A: 712, B: 668, C: 663, D: 744, E: 634, F: 610, G: 725, H: 809, I: 387, J: 394, K: 726, L: 616, M: 930, N: 757, O: 742, P: 637, Q: 742, R: 707, S: 560, T: 650, U: 757, V: 706, W: 1020, X: 678, Y: 667, Z: 592, "[": 356, "\\": 364, "]": 356, "^": 548, _: 528, "`": 400, a: 554, b: 630, c: 527, d: 623, e: 540, f: 374, g: 573, h: 650, i: 336, j: 313, k: 615, l: 337, m: 961, n: 652, o: 590, p: 632, q: 613, r: 475, s: 475, t: 368, u: 640, v: 581, w: 850, x: 585, y: 592, z: 497, "{": 365, "|": 301, "}": 365, "~": 548, " ": 228, "¡": 314, "¢": 538, "£": 539, "¤": 520, "¥": 538, "¦": 301, "§": 514, "¨": 400, "©": 750, ª: 385, "«": 572, "¬": 548, "­": 0, "®": 465, "¯": 400, "°": 344, "±": 548, "²": 390, "³": 390, "´": 400, µ: 626, "¶": 622, "·": 307, "¸": 400, "¹": 390, º: 409, "»": 572, "¼": 918, "½": 949, "¾": 918, "¿": 430, À: 712, Á: 712, Â: 712, Ã: 712, Ä: 712, Å: 712, Æ: 943, Ç: 663, È: 634, É: 634, Ê: 634, Ë: 634, Ì: 387, Í: 387, Î: 387, Ï: 387, Ð: 744, Ñ: 757, Ò: 742, Ó: 742, Ô: 742, Õ: 742, Ö: 742, "×": 548, Ø: 742, Ù: 757, Ú: 757, Û: 757, Ü: 757, Ý: 667, Þ: 638, ß: 656, à: 554, á: 554, â: 554, ã: 554, ä: 554, å: 554, æ: 831, ç: 527, è: 540, é: 540, ê: 540, ë: 540, ì: 336, í: 336, î: 336, ï: 336, ð: 577, ñ: 652, ò: 590, ó: 590, ô: 590, õ: 590, ö: 590, "÷": 548, ø: 590, ù: 640, ú: 640, û: 640, ü: 640, ý: 592, þ: 622, ÿ: 592, "‘": 236, "’": 236, "“": 460, "”": 459, "–": 528, "—": 828, "…": 853, "•": 320, "→": 1e3, "←": 1e3, "≤": 549, "≥": 549, "≠": 549, "€": 538 } },
6
+ "mono-500": { unitsPerEm: 1e3, fallback: 600, advances: { 0: 600, 1: 600, 2: 600, 3: 600, 4: 600, 5: 600, 6: 600, 7: 600, 8: 600, 9: 600, " ": 600, "!": 600, '"': 600, "#": 600, $: 600, "%": 600, "&": 600, "'": 600, "(": 600, ")": 600, "*": 600, "+": 600, ",": 600, "-": 600, ".": 600, "/": 600, ":": 600, ";": 600, "<": 600, "=": 600, ">": 600, "?": 600, "@": 600, A: 600, B: 600, C: 600, D: 600, E: 600, F: 600, G: 600, H: 600, I: 600, J: 600, K: 600, L: 600, M: 600, N: 600, O: 600, P: 600, Q: 600, R: 600, S: 600, T: 600, U: 600, V: 600, W: 600, X: 600, Y: 600, Z: 600, "[": 600, "\\": 600, "]": 600, "^": 600, _: 600, "`": 600, a: 600, b: 600, c: 600, d: 600, e: 600, f: 600, g: 600, h: 600, i: 600, j: 600, k: 600, l: 600, m: 600, n: 600, o: 600, p: 600, q: 600, r: 600, s: 600, t: 600, u: 600, v: 600, w: 600, x: 600, y: 600, z: 600, "{": 600, "|": 600, "}": 600, "~": 600, " ": 600, "¡": 600, "¢": 600, "£": 600, "¤": 600, "¥": 600, "¦": 600, "§": 600, "¨": 600, "©": 600, ª: 600, "«": 600, "¬": 600, "­": 0, "®": 600, "¯": 600, "°": 600, "±": 600, "²": 600, "³": 600, "´": 600, µ: 600, "¶": 600, "·": 600, "¸": 600, "¹": 600, º: 600, "»": 600, "¼": 600, "½": 600, "¾": 600, "¿": 600, À: 600, Á: 600, Â: 600, Ã: 600, Ä: 600, Å: 600, Æ: 600, Ç: 600, È: 600, É: 600, Ê: 600, Ë: 600, Ì: 600, Í: 600, Î: 600, Ï: 600, Ð: 600, Ñ: 600, Ò: 600, Ó: 600, Ô: 600, Õ: 600, Ö: 600, "×": 600, Ø: 600, Ù: 600, Ú: 600, Û: 600, Ü: 600, Ý: 600, Þ: 600, ß: 600, à: 600, á: 600, â: 600, ã: 600, ä: 600, å: 600, æ: 600, ç: 600, è: 600, é: 600, ê: 600, ë: 600, ì: 600, í: 600, î: 600, ï: 600, ð: 600, ñ: 600, ò: 600, ó: 600, ô: 600, õ: 600, ö: 600, "÷": 600, ø: 600, ù: 600, ú: 600, û: 600, ü: 600, ý: 600, þ: 600, ÿ: 600, "‘": 600, "’": 600, "“": 600, "”": 600, "–": 600, "—": 600, "…": 600, "•": 600, "→": 602, "←": 602, "≤": 549, "≥": 549, "≠": 549, "€": 600 } }
7
+ }, Mt = "269b2d3580f4", Qn = {
8
+ "sans-500": {
9
+ family: `Draft Inter ${Mt}`,
10
+ weight: 500,
11
+ file: "inter-latin-500-normal.woff2"
12
+ },
13
+ "sans-600": {
14
+ family: `Draft Inter ${Mt}`,
15
+ weight: 600,
16
+ file: "inter-latin-600-normal.woff2"
17
+ },
18
+ "serif-600": {
19
+ family: `Draft Source Serif ${Mt}`,
20
+ weight: 600,
21
+ file: "source-serif-4-latin-600-normal.woff2"
22
+ },
23
+ "mono-500": {
24
+ family: `Draft JetBrains Mono ${Mt}`,
25
+ weight: 500,
26
+ file: "jetbrains-mono-latin-500-normal.woff2"
27
+ }
28
+ }, Io = ["sans", "serif", "mono"], To = {
29
+ sans: "Inter, Arial, sans-serif",
30
+ serif: "'Source Serif 4', Georgia, serif",
31
+ mono: "'JetBrains Mono', Menlo, Consolas, monospace"
32
+ }, Vn = (e, t) => e === "serif" ? "serif-600" : e === "mono" ? "mono-500" : t ? "sans-600" : "sans-500", Lo = (e) => `'${Qn[Vn(e, !0)].family}', ${To[e]}`;
33
+ function ct(e, t, s, n) {
34
+ const o = Vn(e, t);
35
+ return { role: e, face: o, family: Lo(e), weight: Qn[o].weight, size: s, lineHeight: n };
36
+ }
37
+ const Ro = _o;
38
+ function ye(e, t) {
39
+ const s = Ro[t.face];
40
+ let n = 0;
41
+ for (const o of e) n += s.advances[o] ?? s.fallback;
42
+ return n * t.size / s.unitsPerEm;
43
+ }
44
+ function Zn(e) {
45
+ const t = [];
46
+ let s = "";
47
+ for (const n of e.split(/(?<=[/._:-])(?=[^/._:-])|(?<=[a-z0-9])(?=[A-Z])/))
48
+ /[\p{L}\p{N}]/u.test(n) ? (t.push(s + n), s = "") : s += n;
49
+ return s && t.length ? t[t.length - 1] += s : s && t.push(s), t.length > 1 && t[t.length - 1].length <= 3 && t.splice(-2, 2, t[t.length - 2] + t[t.length - 1]), t;
50
+ }
51
+ function qt(e, t) {
52
+ return Math.max(
53
+ 0,
54
+ ...String(e).split(/\s+/).flatMap(Zn).map((s) => ye(s, t))
55
+ );
56
+ }
57
+ function Oo(e, t, s) {
58
+ const n = [];
59
+ let o = "";
60
+ for (const r of e.split(/\s+/)) {
61
+ if (!r) continue;
62
+ const d = n[n.length - 1];
63
+ !o && d !== void 0 && /\d$/.test(d) && /^(%|[\p{L}µ]{1,3}[.,;:)]?)$/u.test(r) && ye(d + " " + r, s) <= t ? n[n.length - 1] = d + " " + r : o && ye(o + " " + r, s) <= t ? (n.push(o + " " + r), o = "") : (o && n.push(o), o = "", !/[\p{L}\p{N}]/u.test(r) && r.length <= 2 ? o = r : n.push(r));
64
+ }
65
+ if (o) {
66
+ const r = n[n.length - 1];
67
+ r !== void 0 && ye(r + " " + o, s) <= t ? n[n.length - 1] = r + " " + o : n.push(o);
68
+ }
69
+ return n;
70
+ }
71
+ function $o(e, t, s) {
72
+ const n = (d) => ye(d, s) <= t, o = [];
73
+ let r = "";
74
+ for (const d of e) {
75
+ if (!n(d)) {
76
+ r && o.push(r);
77
+ let h = "";
78
+ for (const c of Zn(d)) {
79
+ if (h && n(h + c)) {
80
+ h += c;
81
+ continue;
82
+ }
83
+ if (h && o.push(h), h = "", n(c)) {
84
+ h = c;
85
+ continue;
86
+ }
87
+ for (const y of c)
88
+ h && !n(h + y) && (o.push(h), h = ""), h += y;
89
+ }
90
+ r = h;
91
+ continue;
92
+ }
93
+ r && !n(r + " " + d) ? (o.push(r), r = d) : r += (r ? " " : "") + d;
94
+ }
95
+ return o.push(r), o;
96
+ }
97
+ function Do(e, t, s, n) {
98
+ const o = e.map((a) => ye(a, n)), r = ye(" ", n);
99
+ if (o.some((a) => a > s)) return;
100
+ const d = [0];
101
+ for (const a of o) d.push(d[d.length - 1] + a);
102
+ const h = (a, i) => d[i] - d[a] + (i - a - 1) * r, c = h(0, o.length) / t, y = (c / 10) ** 2, w = [[0, ...o.map(() => 1 / 0)]], l = [[]];
103
+ for (let a = 1; a <= t; a++) {
104
+ w.push(o.map(() => 1 / 0).concat(1 / 0)), l.push([]);
105
+ for (let i = a; i <= o.length; i++)
106
+ for (let g = i - 1; g >= a - 1 && h(g, i) <= s; g--) {
107
+ const f = w[a - 1][g] + (h(g, i) - c) ** 2;
108
+ f < w[a][i] - y && ([w[a][i], l[a][i]] = [f, g]);
109
+ }
110
+ }
111
+ if (!Number.isFinite(w[t][o.length])) return;
112
+ const p = [];
113
+ for (let a = t, i = o.length; a > 0; i = l[a][i], a--)
114
+ p.unshift(e.slice(l[a][i], i).join(" "));
115
+ return p;
116
+ }
117
+ function it(e, t, s, n = !1) {
118
+ const o = [];
119
+ for (const r of String(e).split(`
120
+ `)) {
121
+ const d = n ? Oo(r, t, s) : r.split(/\s+/).filter(Boolean), h = $o(d, t, s);
122
+ o.push(
123
+ ...n && h.length > 1 ? Do(d, h.length, t, s) ?? h : h
124
+ );
125
+ }
126
+ return o.length ? o : [""];
127
+ }
128
+ const ln = ["drafting", "fieldnotes", "signal", "ink", "blueprint"], It = "drafting", Gt = [50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 950], Ve = 500, No = (e) => Ze[e]?.dark ? 950 : 50, Fo = (e) => Ze[e]?.dark ? 900 : 100, Ht = [
129
+ "primary",
130
+ "secondary",
131
+ "slate",
132
+ "stone",
133
+ "blue",
134
+ "sky",
135
+ "teal",
136
+ "mint",
137
+ "green",
138
+ "amber",
139
+ "orange",
140
+ "red",
141
+ "rose",
142
+ "violet"
143
+ ], Tt = (e) => Ht.includes(e), dn = ["dashed", "solid"], Jn = () => ({
144
+ theme: It,
145
+ overrides: {},
146
+ colors: []
147
+ }), fn = {
148
+ paddingX: { min: 4, max: 48 },
149
+ paddingY: { min: 4, max: 48 },
150
+ radius: { min: 0, max: 24 }
151
+ }, Po = /^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i, Ze = {
152
+ drafting: {
153
+ label: "Drafting",
154
+ description: "Navy ink on cool paper, with drafting blue and marker gold",
155
+ dark: !1,
156
+ canvas: "#F7F7F4",
157
+ text: "#1B2433",
158
+ muted: "#586172",
159
+ connection: "#39414F",
160
+ node: { fill: "#FFFFFF", stroke: "#C3C8CF", ink: "#1B2433" },
161
+ group: { fill: "#EEEFEB", stroke: "#D5D8DC", ink: "#363F4D" },
162
+ paddingX: 12,
163
+ paddingY: 20,
164
+ radius: 4,
165
+ shadow: !1,
166
+ titleFont: "sans",
167
+ annotationFont: "sans",
168
+ titleSize: 13,
169
+ titleLine: 16,
170
+ annotationSize: 11,
171
+ chroma: 0.9,
172
+ primary: ["#2754A6", 700],
173
+ secondary: ["#F0B43C", 400]
174
+ },
175
+ fieldnotes: {
176
+ label: "Fieldnotes",
177
+ description: "Editorial serif titles on warm paper, indigo and terracotta",
178
+ dark: !1,
179
+ canvas: "#F6F1E6",
180
+ text: "#2F2B24",
181
+ muted: "#6B6559",
182
+ connection: "#57503F",
183
+ node: { fill: "#FFFCF5", stroke: "#CFC4AF", ink: "#2F2B24" },
184
+ group: { fill: "#EEE7D8", stroke: "#D8CDB8", ink: "#4A4539" },
185
+ paddingX: 18,
186
+ paddingY: 22,
187
+ radius: 3,
188
+ shadow: !1,
189
+ titleFont: "serif",
190
+ annotationFont: "sans",
191
+ titleSize: 15,
192
+ titleLine: 19,
193
+ annotationSize: 11,
194
+ chroma: 0.72,
195
+ primary: ["#34507F", 700],
196
+ secondary: ["#B5532F", 600],
197
+ hues: { green: [150, 0.1], amber: [80, 0.12], violet: [320, 0.1] }
198
+ },
199
+ signal: {
200
+ label: "Signal",
201
+ description: "Color-blind-safe Okabe–Ito hues on white, with monospace annotations",
202
+ dark: !1,
203
+ canvas: "#FFFFFF",
204
+ text: "#16202B",
205
+ muted: "#4F5B68",
206
+ connection: "#3B4652",
207
+ node: { fill: "#F5F7F9", stroke: "#C3CAD3", ink: "#16202B" },
208
+ group: { fill: "#F6F8FA", stroke: "#D9DEE4", ink: "#2A3644" },
209
+ paddingX: 16,
210
+ paddingY: 20,
211
+ radius: 6,
212
+ shadow: !1,
213
+ titleFont: "sans",
214
+ annotationFont: "mono",
215
+ titleSize: 13,
216
+ titleLine: 16,
217
+ annotationSize: 10.5,
218
+ chroma: 1,
219
+ primary: ["#0067A5", 600],
220
+ secondary: ["#E69F00", 500],
221
+ // After Okabe & Ito's set: blue, sky blue, bluish green, orange, vermilion, reddish purple.
222
+ hues: {
223
+ blue: [248, 0.15],
224
+ sky: [237, 0.11],
225
+ green: [163, 0.13],
226
+ mint: [172, 0.1],
227
+ amber: [72, 0.16],
228
+ orange: [55, 0.16],
229
+ red: [36, 0.18],
230
+ rose: [350, 0.13]
231
+ }
232
+ },
233
+ ink: {
234
+ label: "Ink",
235
+ description: "Sumi ink tones with indigo and a vermilion seal, generous spacing",
236
+ dark: !1,
237
+ canvas: "#F8F6F1",
238
+ text: "#1A1A1A",
239
+ muted: "#625F5A",
240
+ connection: "#3B3A38",
241
+ node: { fill: "#FFFFFF", stroke: "#C8C5BF", ink: "#1A1A1A" },
242
+ group: { fill: "#EFECE5", stroke: "#D9D5CC", ink: "#3F3D39" },
243
+ paddingX: 22,
244
+ paddingY: 26,
245
+ radius: 3,
246
+ shadow: !1,
247
+ titleFont: "sans",
248
+ annotationFont: "sans",
249
+ titleSize: 14,
250
+ titleLine: 19,
251
+ annotationSize: 11.5,
252
+ chroma: 0.6,
253
+ primary: ["#2B3A55", 900],
254
+ secondary: ["#C23B22", 600]
255
+ },
256
+ // The default theme on a dark page: the same type, spacing and families as drafting, so it
257
+ // draws every box in the same place. Graphite surfaces, lighter than the canvas the higher
258
+ // they sit, with drafting blue and marker gold lifted to read on them. Not a file's theme.
259
+ "drafting-dark": {
260
+ label: "Drafting dark",
261
+ description: "Drafting on a graphite page, for a dark host",
262
+ dark: !0,
263
+ canvas: "#16191E",
264
+ text: "#E7EAEF",
265
+ muted: "#9BA3B0",
266
+ connection: "#AEB6C2",
267
+ node: { fill: "#21252C", stroke: "#3D4450", ink: "#E7EAEF" },
268
+ group: { fill: "#1B1F25", stroke: "#30363F", ink: "#C8CED8" },
269
+ paddingX: 12,
270
+ paddingY: 20,
271
+ radius: 4,
272
+ shadow: !1,
273
+ titleFont: "sans",
274
+ annotationFont: "sans",
275
+ titleSize: 13,
276
+ titleLine: 16,
277
+ annotationSize: 11,
278
+ chroma: 0.9,
279
+ primary: ["#7FA4E6", 300],
280
+ secondary: ["#F0B43C", 400]
281
+ },
282
+ blueprint: {
283
+ label: "Blueprint",
284
+ description: "White lines on blueprint blue, cyan and yellow, monospace titles",
285
+ dark: !0,
286
+ canvas: "#13233D",
287
+ text: "#EAF1FB",
288
+ muted: "#A6B8D2",
289
+ connection: "#A9C2E6",
290
+ node: { fill: "#1B3154", stroke: "#45679B", ink: "#EAF1FB" },
291
+ group: { fill: "#172A48", stroke: "#2F4C78", ink: "#CFDCEF" },
292
+ paddingX: 16,
293
+ paddingY: 20,
294
+ radius: 3,
295
+ shadow: !1,
296
+ titleFont: "mono",
297
+ annotationFont: "sans",
298
+ titleSize: 12.5,
299
+ titleLine: 17,
300
+ annotationSize: 11,
301
+ chroma: 0.85,
302
+ primary: ["#7FC4F2", 300],
303
+ secondary: ["#F2C14E", 300]
304
+ }
305
+ }, eo = (e) => e <= 0.04045 ? e / 12.92 : ((e + 0.055) / 1.055) ** 2.4, Co = (e) => e <= 31308e-7 ? 12.92 * e : 1.055 * e ** (1 / 2.4) - 0.055;
306
+ function to(e) {
307
+ const t = e.length === 4 ? e.replace(/[0-9a-f]/gi, (s) => s + s) : e;
308
+ return [1, 3, 5].map((s) => parseInt(t.slice(s, s + 2), 16) / 255);
309
+ }
310
+ function on(e) {
311
+ const [t, s, n] = to(e).map(eo), o = Math.cbrt(0.4122214708 * t + 0.5363325363 * s + 0.0514459929 * n), r = Math.cbrt(0.2119034982 * t + 0.6806995451 * s + 0.1073969566 * n), d = Math.cbrt(0.0883024619 * t + 0.2817188376 * s + 0.6299787005 * n), h = 0.2104542553 * o + 0.793617785 * r - 0.0040720468 * d, c = 1.9779984951 * o - 2.428592205 * r + 0.4505937099 * d, y = 0.0259040371 * o + 0.7827717662 * r - 0.808675766 * d;
312
+ return [h, Math.hypot(c, y), (Math.atan2(y, c) * 180 / Math.PI + 360) % 360];
313
+ }
314
+ function hn([e, t, s]) {
315
+ const n = t * Math.cos(s * Math.PI / 180), o = t * Math.sin(s * Math.PI / 180), r = (e + 0.3963377774 * n + 0.2158037573 * o) ** 3, d = (e - 0.1055613458 * n - 0.0638541728 * o) ** 3, h = (e - 0.0894841775 * n - 1.291485548 * o) ** 3;
316
+ return [
317
+ 4.0767416621 * r - 3.3077115913 * d + 0.2309699292 * h,
318
+ -1.2684380046 * r + 2.6097574011 * d - 0.3413193965 * h,
319
+ -0.0041960863 * r - 0.7034186147 * d + 1.707614701 * h
320
+ ];
321
+ }
322
+ function lt([e, t, s]) {
323
+ let n = t, o = hn([e, n, s]);
324
+ for (; n > 0 && o.some((r) => r < -5e-4 || r > 1.0005); )
325
+ n = Math.max(0, n - 4e-3), o = hn([e, n, s]);
326
+ return "#" + o.map(
327
+ (r) => Math.round(Math.min(1, Math.max(0, Co(Math.min(1, Math.max(0, r))))) * 255).toString(16).padStart(2, "0")
328
+ ).join("").toUpperCase();
329
+ }
330
+ function Yt(e) {
331
+ const [t, s, n] = to(e).map(eo);
332
+ return 0.2126 * t + 0.7152 * s + 0.0722 * n;
333
+ }
334
+ function Lt(e, t) {
335
+ const [s, n] = [Yt(e), Yt(t)].sort((o, r) => r - o);
336
+ return (s + 0.05) / (n + 0.05);
337
+ }
338
+ const pn = {
339
+ 50: 0.975,
340
+ 100: 0.945,
341
+ 200: 0.9,
342
+ 300: 0.84,
343
+ 400: 0.62,
344
+ 500: 0.56,
345
+ 600: 0.5,
346
+ 700: 0.44,
347
+ 800: 0.38,
348
+ 900: 0.32,
349
+ 950: 0.26
350
+ }, sn = (e) => e <= 300, no = (e) => e >= 45 && e <= 110, Wt = { 400: 0.8, 500: 0.74 }, jo = (e, t) => Wt[e] === void 0 ? void 0 : Wt[e] - (t < 65 ? 0.07 : 0), Bo = (e, t) => sn(e) || no(t) && e in Wt, Ne = {
351
+ /** Dark title text on a pale fill. */
352
+ paleInk: 7,
353
+ /** White title text on a dark fill. */
354
+ darkInk: 4.5,
355
+ /** A shape's outline against the canvas when its fill alone does not separate it. */
356
+ outline: 3,
357
+ /** Connection lines and connection label text against the canvas. */
358
+ connection: 4.5,
359
+ /** A group's frame against the canvas. */
360
+ frame: 2
361
+ }, St = (e) => Math.max(0.18, 1 - ((e - 0.6) / 0.42) ** 2), zo = {
362
+ slate: [255, 0.03],
363
+ stone: [70, 0.02],
364
+ blue: [258, 0.14],
365
+ sky: [232, 0.1],
366
+ teal: [195, 0.085],
367
+ mint: [168, 0.09],
368
+ green: [155, 0.12],
369
+ amber: [78, 0.14],
370
+ orange: [50, 0.15],
371
+ red: [32, 0.17],
372
+ rose: [358, 0.12],
373
+ violet: [305, 0.13]
374
+ }, Uo = (e) => lt([0.24, 0.035, e]), qo = "#FFFFFF";
375
+ function Ye(e, t, s) {
376
+ if (Lt(e, t) >= s) return e;
377
+ const [n, o, r] = on(e), d = Yt(t) > 0.18 ? -0.01 : 0.01;
378
+ let h = e;
379
+ for (let c = n; c > 0 && c < 1 && Lt(h, t) < s; c += d)
380
+ h = lt([c, o, r]);
381
+ return h;
382
+ }
383
+ function un(e, t, s, n, o, r, d) {
384
+ const h = Bo(e, n), c = h ? Uo(n) : qo, y = sn(e) ? Ne.paleInk : Ne.darkInk;
385
+ let w = d ? on(d)[0] : t, l = d ?? lt([w, s * St(w), n]);
386
+ for (; Lt(l, c) < y && w > 0.05 && w < 0.995; )
387
+ w += h ? 5e-3 : -0.01, l = lt([w, s * St(w), n]);
388
+ const p = h ? w - 0.2 : r ? w + 0.14 : w - 0.08;
389
+ let a = lt([p, s * St(p) * 1.1, n]);
390
+ return Lt(l, o) < Ne.outline && (a = Ye(a, o, Ne.outline)), { swatch: { fill: l, stroke: a, ink: c }, L: w };
391
+ }
392
+ const Go = 0.055;
393
+ function oo(e, t, s, n, o) {
394
+ const r = /* @__PURE__ */ new Map();
395
+ let d = 1;
396
+ for (const h of Gt) {
397
+ const c = no(e) ? jo(h, e) : void 0, y = sn(h) ? pn[h] : Math.min(c ?? pn[h], d - Go);
398
+ let w = un(
399
+ h,
400
+ y,
401
+ t,
402
+ e,
403
+ s,
404
+ n,
405
+ o?.[1] === h ? o[0] : void 0
406
+ );
407
+ w.L >= d - 0.01 && (w = un(h, y, t, e, s, n)), d = w.L, r.set(h, w.swatch);
408
+ }
409
+ return r;
410
+ }
411
+ function gn([e, t], s, n) {
412
+ const [o, r, d] = on(e);
413
+ return oo(d, r / St(o), s, n, [e.toUpperCase(), t]);
414
+ }
415
+ const mn = /* @__PURE__ */ new Map();
416
+ function Ho(e, t = Ze[e].canvas) {
417
+ const s = e + t;
418
+ let n = mn.get(s);
419
+ if (!n) {
420
+ const o = Ze[e];
421
+ n = /* @__PURE__ */ new Map([
422
+ ["primary", gn(o.primary, t, o.dark)],
423
+ ["secondary", gn(o.secondary, t, o.dark)]
424
+ ]);
425
+ for (const [r, d] of Object.entries(zo)) {
426
+ const [h, c] = o.hues?.[r] ?? d;
427
+ n.set(r, oo(h, c * o.chroma, t, o.dark));
428
+ }
429
+ mn.set(s, n);
430
+ }
431
+ return n;
432
+ }
433
+ const Yo = (e) => Math.round(e + 32), xt = /* @__PURE__ */ new Map();
434
+ function pt(e) {
435
+ const t = e ?? Jn(), s = JSON.stringify(t), n = xt.get(s);
436
+ if (n) return n;
437
+ const o = Ze[t.theme] ?? Ze[It], r = t.overrides, d = r.titleFont ?? o.titleFont, h = r.annotationFont ?? o.annotationFont, c = r.canvas ?? o.canvas, y = new Map(
438
+ [...Ho(t.theme, c)].map(([a, i]) => [a, new Map(i)])
439
+ ), w = /* @__PURE__ */ new Set();
440
+ for (const a of t.colors) {
441
+ y.has(a.family) || (y.set(a.family, /* @__PURE__ */ new Map()), w.add(a.family));
442
+ const i = y.get(a.family), g = i.get(a.shade);
443
+ (g || a.fill && a.stroke && a.ink) && i.set(a.shade, {
444
+ fill: a.fill ?? g.fill,
445
+ stroke: a.stroke ?? g.stroke,
446
+ ink: a.ink ?? g.ink
447
+ });
448
+ }
449
+ const l = ct(d, !0, o.titleSize, o.titleLine), p = {
450
+ theme: t.theme,
451
+ dark: o.dark,
452
+ // Preset colors are held to the contrast targets against the actual canvas; colors the file
453
+ // sets explicitly are used exactly as written.
454
+ canvas: c,
455
+ text: r.text ?? Ye(o.text, c, 7),
456
+ muted: Ye(o.muted, c, Ne.connection),
457
+ connection: r.connection ?? Ye(o.connection, c, Ne.connection),
458
+ node: {
459
+ fill: o.node.fill,
460
+ stroke: Ye(o.node.stroke, c, Ne.outline),
461
+ ink: r.text ?? Ye(o.node.ink, o.node.fill, Ne.paleInk)
462
+ },
463
+ group: {
464
+ fill: o.group.fill,
465
+ stroke: Ye(o.group.stroke, c, Ne.frame),
466
+ ink: Ye(o.group.ink, o.group.fill, Ne.paleInk)
467
+ },
468
+ paddingX: r.paddingX ?? o.paddingX,
469
+ paddingY: r.paddingY ?? o.paddingY,
470
+ radius: r.radius ?? o.radius,
471
+ shadow: o.shadow,
472
+ title: l,
473
+ detail: ct(d, !1, o.titleSize - 1, o.titleLine - 1),
474
+ groupTitle: l,
475
+ annotation: ct(
476
+ h,
477
+ !1,
478
+ o.annotationSize,
479
+ Math.round(o.annotationSize * 1.4)
480
+ ),
481
+ groupHeader: Yo(l.lineHeight),
482
+ families: y,
483
+ custom: w,
484
+ strikeRemoved: !!t.config?.strikeRemoved
485
+ };
486
+ return xt.size > 50 && xt.clear(), xt.set(s, p), p;
487
+ }
488
+ function wn(e, t = 0) {
489
+ if (!e.length) return { x: 70, y: 160, w: 240, h: 160 };
490
+ let s = 1 / 0, n = 1 / 0, o = -1 / 0, r = -1 / 0;
491
+ for (const d of e)
492
+ s = Math.min(s, d.x), n = Math.min(n, d.y), o = Math.max(o, d.x + d.w), r = Math.max(r, d.y + d.h);
493
+ return { x: s - t, y: n - t, w: o - s + t * 2, h: r - n + t * 2 };
494
+ }
495
+ const Se = 24, Wo = 48, Xt = 97, dt = 10, Rt = 18, so = (e, t = Wo) => ({
496
+ x: e.x + Se,
497
+ y: e.y + t
498
+ }), Xo = 48;
499
+ function io(e) {
500
+ return e === "circle" || e === "icon" ? { w: 80, h: 80 } : e === "diamond" ? { w: 112, h: 112 } : e === "text" ? { w: 164, h: 38 } : { w: 164, h: 56 };
501
+ }
502
+ function Ot(e, t, s, n, o = !1) {
503
+ if (e === "diamond") return { width: Math.max(40, t * 0.55), maxHeight: s * 0.45 };
504
+ if (e === "circle") return { width: Math.max(40, t * 0.7), maxHeight: s * 0.7 };
505
+ const r = e === "text" ? Math.min(n.paddingY, 11) : n.paddingY;
506
+ return {
507
+ width: Math.max(40, t - 2 * n.paddingX - (o ? 30 : 0) - (e === "pill" ? 8 : 0)),
508
+ maxHeight: s - 2 * r
509
+ };
510
+ }
511
+ function Ko(e, t, s, n) {
512
+ return e === "circle" ? Math.max(s, Math.ceil(t / 0.7)) : e === "text" ? t + 2 * Math.min(n.paddingY, 11) : t + 2 * n.paddingY;
513
+ }
514
+ function ut(e, t, s) {
515
+ const n = e.indexOf(`
516
+ `), o = n < 0 ? e : e.slice(0, n), r = it(o, t, s.title, !0).map((d) => ({ text: d, detail: !1 }));
517
+ if (n >= 0)
518
+ for (const d of it(e.slice(n + 1), t, s.detail, !0))
519
+ r.push({ text: d, detail: !0 });
520
+ return r;
521
+ }
522
+ const Qo = (e, t) => e.detail ? t.detail : t.title, gt = (e, t) => e.reduce((s, n) => s + Qo(n, t).lineHeight, 0), Vo = 6;
523
+ function Zo(e, t, s) {
524
+ const n = t - 2 * Vo;
525
+ for (let o = 1; o * s.title.lineHeight < n; o++) {
526
+ const r = n - o * s.title.lineHeight;
527
+ if (r >= 40 && gt(ut(e, r, s), s) <= o * s.title.lineHeight)
528
+ return r;
529
+ }
530
+ }
531
+ const yn = 3, _t = (e, t = 1) => e.groupHeader + (t - 1) * e.groupTitle.lineHeight, Jo = 168, ao = (e, t = !1) => t ? { ...e.annotation, size: e.annotation.size + 1.5, lineHeight: e.annotation.lineHeight + 2 } : e.annotation, es = 140, ts = (e, t, s = !1) => it(e, s ? Jo : es, ao(t, s)), We = { out: 36, down: 22, label: 4 };
532
+ function Je(e, t = pt(), s = !1) {
533
+ const n = ao(t, s), o = ts(e, t, s), r = Math.max(...o.map((d) => ye(d, n))) + 16;
534
+ return {
535
+ w: Math.round(Math.max(36, r)),
536
+ h: Math.round(o.length * n.lineHeight + 6)
537
+ };
538
+ }
539
+ function Mn(e, t) {
540
+ if (!e) return { right: We.out, above: 0, below: We.down };
541
+ const { w: s, h: n } = Je(e, t, !0);
542
+ return {
543
+ right: We.out + We.label + s,
544
+ above: Math.max(0, n / 2 - We.down / 2),
545
+ below: Math.max(We.down, We.down / 2 + n / 2)
546
+ };
547
+ }
548
+ const Pt = 8, xn = 16, Kt = 10, ns = 64, os = 240, Qt = (e) => Math.round(e + 14);
549
+ function ss(e, t) {
550
+ if (e.size?.height !== void 0) return { w: e.size.width, h: e.size.height };
551
+ if (e.size) {
552
+ const r = gt(ut(e.label, e.size.width - 2 * t.paddingX, t), t);
553
+ return {
554
+ w: e.size.width,
555
+ h: Math.max(r + 2 * Math.min(t.paddingY, Kt), e.size.minHeight ?? 0)
556
+ };
557
+ }
558
+ const s = 2 * t.paddingX, n = Math.min(os, Math.max(ns, Math.ceil(ye(e.label, t.title)) + s)), o = gt(ut(e.label, n - s, t), t);
559
+ return { w: n, h: o + 2 * Math.min(t.paddingY, Kt) };
560
+ }
561
+ function is(e, t, s, n = 0) {
562
+ const o = e.filter((D) => !D.marker), r = new Map(o.map((D) => [D.id, ss(D, s)])), d = Math.max(
563
+ 1,
564
+ t.columns ?? (t.direction === "down" ? 1 : o.reduce((D, _) => D + (_.span ?? 1), 0))
565
+ ), h = /* @__PURE__ */ new Map();
566
+ let c = 0, y = 0;
567
+ for (const D of o) {
568
+ const _ = Math.min(D.span ?? 1, d);
569
+ y + _ > d && (c++, y = 0), h.set(D.id, { row: c, col: y, span: _ }), y += _;
570
+ }
571
+ const w = Array(d).fill(0), l = Array(o.length ? c + 1 : 0).fill(0);
572
+ for (const D of o) {
573
+ const { row: _, col: $, span: x } = h.get(D.id);
574
+ x === 1 && (w[$] = Math.max(w[$], r.get(D.id).w)), l[_] = Math.max(l[_], r.get(D.id).h);
575
+ }
576
+ for (const D of o) {
577
+ const { col: _, span: $ } = h.get(D.id), x = r.get(D.id).w - w.slice(_, _ + $).reduce((E, v) => E + v, 0);
578
+ x > 0 && (w[_ + $ - 1] += x);
579
+ }
580
+ const p = n - w.reduce((D, _) => D + _, 0);
581
+ p > 0 && (w[d - 1] += p);
582
+ const a = [0], i = [0];
583
+ for (const D of w) a.push(a.at(-1) + D);
584
+ for (const D of l) i.push(i.at(-1) + D);
585
+ const g = a.at(-1), f = i.at(-1), M = /* @__PURE__ */ new Map();
586
+ for (const D of o) {
587
+ const { row: _, col: $, span: x } = h.get(D.id);
588
+ M.set(D.id, { x: a[$], y: i[_], w: a[$ + x] - a[$], h: l[_] });
589
+ }
590
+ const k = Qt(s.groupTitle.lineHeight), S = d > 1 || t.direction === "right";
591
+ return e.forEach((D, _) => {
592
+ if (!D.marker) return;
593
+ const $ = e.slice(_ + 1).find((v) => !v.marker), x = $ ? M.get($.id) : void 0, E = Pt / 2;
594
+ M.set(
595
+ D.id,
596
+ S ? { x: (x?.x ?? g) - E, y: -k, w: Pt, h: f + k + xn } : { x: 0, y: (x?.y ?? f) - E, w: g + xn, h: Pt }
597
+ );
598
+ }), { boxes: M, w: g, h: f };
599
+ }
600
+ const as = { bit: 24, byte: 48 }, rs = { bit: 32, byte: 16 };
601
+ function cs(e, t, s) {
602
+ const n = t.columns ?? rs[t.unit], o = t.unitWidth ?? as[t.unit], r = 2 * Math.min(s.paddingX, 6), d = /* @__PURE__ */ new Map();
603
+ let h = 0, c = 0;
604
+ for (const f of e) {
605
+ const M = [];
606
+ if (f.open)
607
+ M.push({ row: h, col: c, span: n - c }), h++, c = 0;
608
+ else
609
+ for (let k = f.span ?? 1; k > 0; ) {
610
+ const S = Math.min(k, n - c);
611
+ M.push({ row: h, col: c, span: S }), k -= S, c += S, c === n && (h++, c = 0);
612
+ }
613
+ d.set(f.id, M);
614
+ }
615
+ const y = c ? h + 1 : h, w = (f) => d.get(f).reduce((M, k) => k.span > M.span ? k : M), l = Math.max(
616
+ 0,
617
+ ...e.map((f) => {
618
+ const M = ut(f.label, Math.max(8, w(f.id).span * o - r), s);
619
+ return gt(M, s) + 2 * Math.min(s.paddingY, Kt);
620
+ })
621
+ ), p = (f) => ({
622
+ x: f.col * o,
623
+ y: f.row * l,
624
+ w: f.span * o,
625
+ h: l
626
+ }), a = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map();
627
+ for (const f of e) {
628
+ const M = w(f.id), k = d.get(f.id).filter((S) => S !== M);
629
+ a.set(f.id, p(M)), k.length && i.set(f.id, k.map(p));
630
+ }
631
+ const g = t.ruler ? Math.round(s.annotation.lineHeight + 6) : 0;
632
+ return {
633
+ boxes: a,
634
+ pieces: i,
635
+ open: e.filter((f) => f.open).map((f) => f.id),
636
+ ...t.ruler ? {
637
+ ruler: {
638
+ h: g,
639
+ ticks: Array.from({ length: n }, (f, M) => ({
640
+ x: M * o + o / 2,
641
+ label: String(M)
642
+ }))
643
+ }
644
+ } : {},
645
+ w: n * o,
646
+ h: y * l
647
+ };
648
+ }
649
+ const ls = /\[([^\]\n]+)\]\(([^)\s]+)\)/g;
650
+ function ds(e, t, s) {
651
+ let n = "";
652
+ const o = [];
653
+ let r = 0;
654
+ for (const c of e.matchAll(ls)) {
655
+ const y = e.slice(r, c.index);
656
+ n += y + c[1], o.push(
657
+ ...Array(y.length).fill(void 0),
658
+ ...Array(c[1].length).fill(c[2])
659
+ ), r = c.index + c[0].length;
660
+ }
661
+ n += e.slice(r), o.push(...Array(e.length - r).fill(void 0));
662
+ let d = 0;
663
+ const h = (c) => /\s/.test(n[c] ?? "");
664
+ return it(n, t, s).map((c) => {
665
+ for (; d < n.length && h(d); ) d++;
666
+ const y = [];
667
+ for (const p of c)
668
+ if (p === " " && h(d)) {
669
+ const a = o[d - 1];
670
+ for (; d < n.length && h(d); ) d++;
671
+ y.push(a && a === o[d] ? a : void 0);
672
+ } else y.push(o[d++]);
673
+ const w = [];
674
+ y.forEach((p, a) => {
675
+ const i = w.at(-1);
676
+ i && i.href === p ? i.text += c[a] : w.push({ text: c[a], href: p, x: 0, w: 0 });
677
+ });
678
+ let l = 0;
679
+ for (const p of w)
680
+ p.x = l, p.w = ye(p.text, s), l += p.w;
681
+ return w.length ? w : [{ text: "", x: 0, w: 0 }];
682
+ });
683
+ }
684
+ const fs = ["below", "above", "left", "right"], ro = 280, co = { x: 12, y: 8 }, bn = co.x, hs = co.y, ps = 8;
685
+ function us(e, t) {
686
+ const s = e.annotation, n = ds(t.text, (t.width ?? ro) - bn * 2, s), o = Math.ceil(Math.max(...n.map((r) => r.reduce((d, h) => d + h.w, 0)))) + bn * 2;
687
+ return { note: t, lines: n, rect: { x: 0, y: 0, w: o, h: n.length * s.lineHeight + hs * 2 } };
688
+ }
689
+ function gs(e, t, s, { left: n, right: o, top: r }) {
690
+ const d = t.map(() => null);
691
+ for (const h of ["left", "right"]) {
692
+ let c = r;
693
+ t.map((y, w) => ({ note: y, i: w, row: s.get(y.near ?? "") })).filter((y) => y.row !== void 0 && (y.note.side ?? "right") === h).sort((y, w) => y.row - w.row).forEach(({ note: y, i: w, row: l }) => {
694
+ const { w: p, h: a } = us(e, y).rect, i = Math.max(c, Math.round(l - a / 2));
695
+ d[w] = { x: h === "right" ? o : n - p, y: i, w: p, h: a }, c = i + a + ps;
696
+ });
697
+ }
698
+ return d;
699
+ }
700
+ const ms = 1.1;
701
+ function ws(e, t, s) {
702
+ const n = new Map(e), o = [...n].flatMap(
703
+ ([r, d]) => Object.keys(d.lines).filter((h) => d.lines[h]).map((h) => ({ id: r, side: h, n: d.lines[h] }))
704
+ );
705
+ o.sort((r, d) => r.n - d.n || (r.id < d.id ? 1 : -1));
706
+ for (const { id: r, side: d } of o) {
707
+ if (!n.size || s(n) <= t * ms) break;
708
+ const h = { ...n.get(r), lines: { ...n.get(r).lines, [d]: 0 } };
709
+ h[d] = d === "top" ? 0 : Se, Object.values(h.lines).some(Boolean) ? n.set(r, h) : n.delete(r);
710
+ }
711
+ return n;
712
+ }
713
+ const ys = 20, vn = 16, bt = 10;
714
+ function Ms(e, t, s = {}) {
715
+ const n = new Map(e.map((i) => [i.id, i])), o = (i) => {
716
+ const g = [];
717
+ for (let f = n.get(i); f && f.parent !== "root"; f = n.get(f.parent))
718
+ g.push(f.parent);
719
+ return g;
720
+ }, r = (i, g) => i === g || o(i).includes(g), d = /* @__PURE__ */ new Map(), h = (i, g) => {
721
+ const f = d.get(i) ?? { left: 0, right: 0, top: 0, bottom: 0 };
722
+ f[g]++, d.set(i, f);
723
+ }, c = (i) => ({ x: i.x + i.w / 2, y: i.y + i.h / 2 }), y = (i, g, f, M) => e.some((k) => k.id === i.id || k.id === M || !r(k.id, g.id) || k.id === g.id || r(i.id, k.id) || r(M, k.id) || !(f === "left" || f === "right" ? k.y < i.y + i.h + bt && k.y + k.h > i.y - bt : k.x < i.x + i.w + bt && k.x + k.w > i.x - bt) ? !1 : f === "right" ? k.x >= i.x + i.w : f === "left" ? k.x + k.w <= i.x : f === "bottom" ? k.y >= i.y + i.h : k.y + k.h <= i.y), w = (i, g) => [
724
+ ...g.x > i.x + i.w ? ["right"] : [],
725
+ ...g.x < i.x ? ["left"] : [],
726
+ ...g.y > i.y + i.h ? ["bottom"] : [],
727
+ // A line leaves through the top only past the title band, which it may not cross.
728
+ ...g.y < i.y ? ["top"] : []
729
+ ];
730
+ for (const i of t) {
731
+ const g = n.get(i.source), f = n.get(i.target);
732
+ if (!g || !f || g === f || i.from !== "auto" || i.to !== "auto") continue;
733
+ const M = [g.id, ...o(g.id)], k = [f.id, ...o(f.id)].find((x) => M.includes(x) && x !== g.id && x !== f.id), S = k && n.get(k)?.type === "group" ? n.get(k) : void 0, D = (x) => {
734
+ let E = x;
735
+ for (; E.parent !== (S?.id ?? "root"); ) E = n.get(E.parent);
736
+ return E;
737
+ }, [_, $] = [D(g), D(f)];
738
+ if (S && _ !== $) {
739
+ const x = (F, X, B) => F === X || w(X, c(B)).some((G) => !y(F, X, G, ""));
740
+ if (!e.some(
741
+ (F) => F.parent === S.id && F !== _ && F !== $ && xs(_, $, F)
742
+ ) && x(g, _, f) && x(f, $, g)) continue;
743
+ const v = Math.abs(c(_).y - c($).y) > Math.abs(c(_).x - c($).x), u = (F, X, B) => (c(F)[B] - c(X)[B]) / Math.max(1, B === "x" ? X.w : X.h), A = v ? "x" : "y", m = u(g, _, A) + u(f, $, A), b = c($)[v ? "y" : "x"] > c(_)[v ? "y" : "x"], T = Math.abs(m) > 0.1 ? m > 0 : b;
744
+ h(S.id, v ? T ? "right" : "left" : T ? "bottom" : "top");
745
+ continue;
746
+ }
747
+ for (const [x, E] of [
748
+ [g, f],
749
+ [f, g]
750
+ ]) {
751
+ const v = x.parent === "root" ? void 0 : n.get(x.parent);
752
+ if (!v || S && v.id === S.id || r(E.id, v.id)) continue;
753
+ const u = w(v, c(E));
754
+ !u.length || u.some((A) => !y(x, v, A, E.id)) || (u.some((A) => A === "left" || A === "right") ? h(v.id, c(x).y < c(v).y + 24 ? "top" : "bottom") : h(v.id, c(E).x < c(x).x ? "left" : "right"));
755
+ }
756
+ }
757
+ const l = s.standoff ?? ys, p = Math.max(s.edgeGap ?? vn, s.portGap ?? vn), a = (i) => i ? 2 * l + (i - 1) * p : Se;
758
+ return new Map(
759
+ [...d].map(([i, g]) => [
760
+ i,
761
+ {
762
+ left: a(g.left),
763
+ right: a(g.right),
764
+ top: g.top ? l + (g.top - 1) * p : 0,
765
+ bottom: a(g.bottom),
766
+ lines: g
767
+ }
768
+ ])
769
+ );
770
+ }
771
+ function xs(e, t, s) {
772
+ const n = Math.min(e.x + e.w, t.x + t.w), o = Math.max(e.x, t.x), r = Math.min(e.y + e.h, t.y + t.h), d = Math.max(e.y, t.y), h = { x: Math.min(n, o), y: Math.min(r, d) }, c = { x: Math.max(n, o), y: Math.max(r, d) };
773
+ return s.x < c.x && s.x + s.w > h.x && s.y < c.y && s.y + s.h > h.y;
774
+ }
775
+ const kn = 20, vt = 20, bs = 12, vs = 16;
776
+ function ks(e, t, s, n, o = (r) => Je(r)) {
777
+ const r = /* @__PURE__ */ new Map();
778
+ for (const d of e.filter((h) => h.scope === "root")) {
779
+ const h = d.axis === "right", c = (f) => h ? f.x : f.y, y = (f) => h ? f.x + f.w : f.y + f.h, w = (f) => h ? f.y : f.x, l = (f) => h ? f.y + f.h : f.x + f.w, p = (f) => (c(f) + y(f)) / 2, a = (f) => (w(f) + l(f)) / 2, i = [...s.values()].filter((f) => f.parent === d.scope);
780
+ (d.bands?.map((f) => f.map((M) => s.get(M))) ?? [i]).forEach((f) => {
781
+ const M = Math.min(...f.map(w)), k = Math.max(...f.map(l)), S = Math.min(...f.map(c)), D = Math.max(...f.map(y)), _ = new Set(f.map((v) => v.id)), $ = (v) => [...s.values()].some(
782
+ (u) => u.parent === d.scope && !_.has(u.id) && c(u) < D && y(u) > S && (v ? l(u) <= M : w(u) >= k)
783
+ ), x = { before: !$(!0), after: !$(!1) }, E = [];
784
+ for (const v of t) {
785
+ if (n.has(v.id) || v.from !== "auto" || v.to !== "auto") continue;
786
+ const u = s.get(v.source), A = s.get(v.target);
787
+ if (!u || !A || u === A || !_.has(u.id) || !_.has(A.id) || u.type === "group" || A.type === "group") continue;
788
+ const m = p(A) < p(u), [b, T] = m ? [A, u] : [u, A], F = Math.min(a(u), a(A)) - 8, X = Math.max(a(u), a(A)) + 8, B = f.filter(
789
+ (O) => O !== u && O !== A && c(O) >= y(b) - 1 && y(O) <= c(T) + 1
790
+ );
791
+ if (!B.some((O) => w(O) < X && l(O) > F) && !(m && B.length)) continue;
792
+ const P = (O, C) => !f.some(
793
+ (V) => V !== O && c(V) < y(O) && y(V) > c(O) && (C ? l(V) <= w(O) : w(V) >= l(O))
794
+ ), R = (O) => !x[O ? "before" : "after"] || !P(u, O) || !P(A, O) ? 1 / 0 : O ? w(u) - M + (w(A) - M) : k - l(u) + (k - l(A)), [N, U] = [R(!0), R(!1)];
795
+ if (!Number.isFinite(N) && !Number.isFinite(U)) continue;
796
+ const I = N === U ? !m : N < U;
797
+ E.push({ id: v.id, before: I, from: p(b), to: p(T), back: m });
798
+ }
799
+ for (const v of [!0, !1]) {
800
+ const u = E.filter((b) => b.before === v).sort((b, T) => b.to - b.from - (T.to - T.from) || b.from - T.from), A = [], m = /* @__PURE__ */ new Set();
801
+ for (const b of u) {
802
+ const T = t.find((O) => O.id === b.id);
803
+ if (m.has(T.source) || m.has(T.target)) continue;
804
+ m.add(T.source).add(T.target);
805
+ let F = 0;
806
+ for (; A[F]?.some(([O, C]) => b.from < C + vt && b.to > O - vt); ) F++;
807
+ (A[F] ??= []).push([b.from, b.to]);
808
+ const X = t.find((O) => O.id === b.id), B = s.get(X.target), G = v ? M - kn - F * vt : k + kn + F * vt, P = Es(B, f, !b.back, c, y), R = Math.min(vs, (l(B) - w(B)) / 2 - bs), N = As(B, f, !b.back, X.id, t, s, c, y, w, l), U = B.shape === "diamond" && N.length > 0 || N.some((O) => {
809
+ if (!O.label) return !1;
810
+ const { w: C, h: V } = o(O.label);
811
+ return (h ? V : C) / 2 + 2 > R;
812
+ }), I = U ? p(B) : b.back ? y(B) + P / 2 : c(B) - P / 2;
813
+ r.set(b.id, {
814
+ ...h ? { y: Math.round(G) } : { x: Math.round(G) },
815
+ enter: Math.round(I),
816
+ out: !0,
817
+ ...U ? { face: !0 } : {}
818
+ });
819
+ }
820
+ }
821
+ });
822
+ }
823
+ return r;
824
+ }
825
+ function Es(e, t, s, n, o) {
826
+ const r = t.filter((d) => d !== e && (s ? o(d) <= n(e) : n(d) >= o(e))).map((d) => s ? n(e) - o(d) : n(d) - o(e));
827
+ return Math.min(48, ...r);
828
+ }
829
+ function As(e, t, s, n, o, r, d, h, c, y) {
830
+ const w = new Set(
831
+ t.filter(
832
+ (p) => p !== e && (s ? h(p) <= d(e) : d(p) >= h(e)) && c(p) < y(e) && y(p) > c(e)
833
+ ).map((p) => p.id)
834
+ ), l = (p) => {
835
+ for (let a = r.get(p); a; a = r.get(a.parent)) if (w.has(a.id)) return !0;
836
+ return !1;
837
+ };
838
+ return o.filter(
839
+ (p) => p.id !== n && (p.source === e.id && l(p.target) || p.target === e.id && l(p.source))
840
+ );
841
+ }
842
+ const lo = { port: 16, track: 16 }, En = 12, fo = 20, Ct = 0.5;
843
+ function Ss(e, t, s, n, o, r = lo) {
844
+ const d = e === "right", h = /* @__PURE__ */ new Map(), { rectOf: c, usable: y, outPort: w, inPort: l, gaps: p, runs: a } = ho(
845
+ e,
846
+ t,
847
+ s,
848
+ n,
849
+ o,
850
+ r
851
+ ), i = [], g = [];
852
+ for (const [f, M] of t.entries())
853
+ for (const k of M) {
854
+ const S = c(k);
855
+ S && (i[f] = Math.min(i[f] ?? 1 / 0, S.y), g[f] = Math.max(g[f] ?? -1 / 0, S.y + S.h));
856
+ }
857
+ for (const [f, { placed: M, level: k }] of p) {
858
+ const S = Math.max(0, ...k) + 1, D = (i[f + 1] ?? 0) - (g[f] ?? 0), _ = S > 1 ? Math.min(r.track, Math.max(0, D - 2 * fo) / (S - 1)) : 0, $ = (g[f] ?? 0) + (D - (S - 1) * _) / 2;
859
+ M.forEach((x, E) => x.y = ot($ + k[E] * _));
860
+ }
861
+ for (const f of y) {
862
+ const M = c(f.chain[0]), k = c(f.chain.at(-1)), S = w.get(f.id), D = l.get(f.id), _ = [{ x: S, y: M.y + M.h }];
863
+ for (const $ of a.get(f.id)) _.push({ x: $.up, y: $.y }, { x: $.low, y: $.y });
864
+ _.push({ x: D, y: k.y }), h.set(f.id, {
865
+ points: Is(_).map(($) => d ? { x: $.y, y: $.x } : $),
866
+ fromOffset: ot(S - (M.x + M.w / 2)),
867
+ toOffset: ot(D - (k.x + k.w / 2))
868
+ });
869
+ }
870
+ return h;
871
+ }
872
+ function _s(e, t, s, n, o, r = lo) {
873
+ const d = [];
874
+ for (const [h, { level: c }] of ho(e, t, s, n, o, r).gaps)
875
+ d[h] = 2 * fo + Math.max(0, ...c) * r.track;
876
+ return d;
877
+ }
878
+ function ho(e, t, s, n, o, r) {
879
+ const d = e === "right", h = (x) => {
880
+ const E = n(x);
881
+ return E && (d ? { x: E.y, y: E.x, w: E.h, h: E.w } : E);
882
+ }, c = new Map(t.flatMap((x, E) => x.map((v) => [v, E]))), y = s.filter(
883
+ (x) => x.chain.length >= 2 && h(x.chain[0]) && h(x.chain.at(-1)) && x.chain.slice(1, -1).every((E) => o(E) !== void 0) && x.chain.every((E, v) => v === 0 || c.get(E) === c.get(x.chain[v - 1]) + 1)
884
+ ), w = (x) => {
885
+ const E = h(x);
886
+ return E ? E.x + E.w / 2 : o(x);
887
+ }, l = (x, E, v) => {
888
+ const u = h(x), A = u.x + En, m = u.x + u.w - En, b = E.length;
889
+ E.sort((B, G) => B.want - G.want || (B.line < G.line ? -1 : 1));
890
+ const T = b > 1 ? Math.min(r.port, Math.max(0, m - A) / (b - 1)) : 0, F = [];
891
+ for (const [B, G] of E.entries())
892
+ for (F.push({ sum: Math.min(m, Math.max(A, G.want)) - B * T, n: 1 }); F.length > 1 && F.at(-2).sum / F.at(-2).n > F.at(-1).sum / F.at(-1).n; ) {
893
+ const P = F.pop();
894
+ F.at(-1).sum += P.sum, F.at(-1).n += P.n;
895
+ }
896
+ const X = [];
897
+ for (const B of F)
898
+ for (let G = 0; G < B.n; G++)
899
+ X.push(Math.max(A, Math.min(m - (b - 1) * T, B.sum / B.n)) + X.length * T);
900
+ E.forEach((B, G) => v.set(B.line, ot(X[G])));
901
+ }, p = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map();
902
+ for (const x of y) {
903
+ const [E, v] = x.chain;
904
+ (p.get(E) ?? p.set(E, []).get(E)).push({ line: x.id, want: w(v) });
905
+ }
906
+ const i = /* @__PURE__ */ new Map(), g = /* @__PURE__ */ new Map();
907
+ for (const [x, E] of p) l(x, E, i);
908
+ for (const x of y) {
909
+ const E = x.chain.at(-1), v = x.chain.at(-2), u = x.chain.length === 2 ? i.get(x.id) : o(v);
910
+ (a.get(E) ?? a.set(E, []).get(E)).push({ line: x.id, want: u });
911
+ }
912
+ for (const [x, E] of a) l(x, E, g);
913
+ const f = (x, E) => E === 0 ? i.get(x.id) : E === x.chain.length - 1 ? g.get(x.id) : o(x.chain[E]), M = /* @__PURE__ */ new Map(), k = /* @__PURE__ */ new Map();
914
+ for (const x of y) {
915
+ const E = [];
916
+ for (let v = 0; v + 1 < x.chain.length; v++) {
917
+ const u = f(x, v), A = f(x, v + 1);
918
+ if (Math.abs(u - A) < Ct) continue;
919
+ const m = { line: x.id, up: u, low: A, lo: Math.min(u, A), hi: Math.max(u, A) }, b = c.get(x.chain[v]);
920
+ (M.get(b) ?? M.set(b, []).get(b)).push(m), E.push(m);
921
+ }
922
+ k.set(x.id, E);
923
+ }
924
+ const S = (x, E) => x > E.lo + Ct && x < E.hi - Ct, D = (x, E) => (S(x.low, E) ? 1 : 0) + (S(E.up, x) ? 1 : 0), _ = (x, E) => x.lo < E.hi + r.track && E.lo < x.hi + r.track, $ = /* @__PURE__ */ new Map();
925
+ for (const [x, E] of M) {
926
+ const v = [];
927
+ for (const A of [...E].sort((m, b) => m.lo - b.lo || m.hi - b.hi)) {
928
+ let m = 0, b = 1 / 0;
929
+ for (let T = 0; T <= v.length; T++) {
930
+ let F = 0;
931
+ for (let X = 0; X < v.length; X++)
932
+ _(A, v[X]) && (F += X < T ? D(v[X], A) : D(A, v[X]));
933
+ F < b && ([m, b] = [T, F]);
934
+ }
935
+ v.splice(m, 0, A);
936
+ }
937
+ const u = v.map(() => 0);
938
+ for (let A = 0; A < v.length; A++)
939
+ for (let m = 0; m < A; m++)
940
+ _(v[A], v[m]) && (u[A] = Math.max(u[A], u[m] + 1));
941
+ $.set(x, { placed: v, level: u });
942
+ }
943
+ return { rectOf: h, usable: y, outPort: i, inPort: g, gaps: $, runs: k };
944
+ }
945
+ const ot = (e) => Math.round(e * 100) / 100;
946
+ function Is(e) {
947
+ const t = [];
948
+ for (const s of e) {
949
+ const n = { x: ot(s.x), y: ot(s.y) }, o = t.at(-1);
950
+ if (o && Math.abs(o.x - n.x) < 0.01 && Math.abs(o.y - n.y) < 0.01) continue;
951
+ const r = t.at(-2);
952
+ o && r && (Math.abs(r.x - o.x) < 0.01 && Math.abs(o.x - n.x) < 0.01 || Math.abs(r.y - o.y) < 0.01 && Math.abs(o.y - n.y) < 0.01) && t.pop(), t.push(n);
953
+ }
954
+ return t;
955
+ }
956
+ const Ts = ["vscode", "vscode-insiders", "cursor", "windsurf", "zed"], An = [
957
+ "arrow",
958
+ "none",
959
+ "triangle",
960
+ "open-triangle",
961
+ "diamond",
962
+ "open-diamond",
963
+ "circle",
964
+ "cross"
965
+ ];
966
+ function po(e) {
967
+ return {
968
+ title: ct(e.title.role, !0, 20, 26),
969
+ subtitle: ct(e.annotation.role, !1, 13, 18)
970
+ };
971
+ }
972
+ const Sn = 360, Ls = 70;
973
+ function Rs(e, t) {
974
+ const s = po(e).subtitle, n = ye("abcdefghijklmnopqrstuvwxyz ", s) / 27 * Ls;
975
+ return Math.round(Math.min(Math.max(t, Sn), Math.max(n, Sn)));
976
+ }
977
+ const Os = po;
978
+ function $s(e) {
979
+ return [...Ns(e), ...Cs(e), ...js(e)];
980
+ }
981
+ const Ds = /* @__PURE__ */ new Set(["slate", "stone"]);
982
+ function Ns(e) {
983
+ if (e.objects.some((r) => r.status) || e.edges.some((r) => r.status)) return [];
984
+ const t = e.appearance.legend ?? [], s = [];
985
+ if (t.length) {
986
+ const r = new Set(t.map((c) => c.family)), d = e.objects.filter(
987
+ (c) => c.color !== "auto" && !Ds.has(c.color) && !r.has(c.color)
988
+ ), h = [...new Set(d.map((c) => c.color))];
989
+ h.length && s.push({
990
+ level: "warning",
991
+ code: "legend-missing",
992
+ message: `The legend has no row for ${h.join(", ")}. Add a \`legend <color> "meaning"\` line for each color the drawing uses, or draw those objects in slate.`,
993
+ line: e.legendLines[0],
994
+ ids: d.map((c) => c.id)
995
+ });
996
+ }
997
+ const n = e.layouts.some((r) => r.algorithm === "sequence"), o = e.edges.filter((r) => r.dashed);
998
+ return !n && o.length && o.length < e.edges.length && !t.some((r) => r.line) && s.push({
999
+ level: "info",
1000
+ code: "legend-lines",
1001
+ message: 'Some lines are dashed (kind=async) and some solid. Say what each style means with `legend line dashed "meaning"` and `legend line solid "meaning"`.',
1002
+ line: o[0].line,
1003
+ ids: o.map((r) => r.id)
1004
+ }), s;
1005
+ }
1006
+ function Fs(e, t) {
1007
+ if (!Tt(t)) return Ve;
1008
+ const s = new Map(e.objects.map((c) => [c.id, c])), n = !!Ze[e.appearance.theme]?.dark, o = (c) => {
1009
+ for (let y = s.get(s.get(c)?.parent ?? ""); y; y = s.get(y.parent))
1010
+ if (y.color !== "auto") return y;
1011
+ }, r = e.objects.filter((c) => c.type === "node");
1012
+ if (r.some((c) => c.color === t)) return Ve;
1013
+ const d = r.filter((c) => c.color === "auto" && o(c.id)?.color === t), h = d.every((c) => {
1014
+ const y = o(c.id).shade;
1015
+ return y === void 0 || (n ? y >= 700 : y <= 300);
1016
+ });
1017
+ return d.length && h ? No(e.appearance.theme) : Ve;
1018
+ }
1019
+ function Ps(e) {
1020
+ for (const t of e.appearance.legend ?? [])
1021
+ t.family && t.shade === void 0 && (t.shade = Fs(e, t.family));
1022
+ }
1023
+ function Cs(e) {
1024
+ return (e.appearance.legend ?? []).flatMap((t, s) => {
1025
+ if (!t.family) return [];
1026
+ const n = e.objects.filter((d) => d.type === "node" && d.color === t.family), o = t.shade ?? Ve, r = [...new Set(n.map((d) => d.shade ?? Ve))].sort((d, h) => d - h);
1027
+ return !n.length || r.includes(o) ? [] : [
1028
+ {
1029
+ level: "warning",
1030
+ code: "legend-shade",
1031
+ message: `legend ${t.family} is shade ${o}; ${t.family} nodes use ${r.join(", ")}. Add \`shade=${r[0]}\`${r.length > 1 ? " or another of them" : ""}.`,
1032
+ line: e.legendLines[s],
1033
+ ids: n.map((d) => d.id)
1034
+ }
1035
+ ];
1036
+ });
1037
+ }
1038
+ function js(e) {
1039
+ const t = [], s = e.appearance.heading?.subtitle;
1040
+ if (s) {
1041
+ const n = pt(e.appearance), o = it(s, Rs(n, 1 / 0), Os(n).subtitle);
1042
+ o.length > 1 && t.push({
1043
+ level: "warning",
1044
+ code: "heading-prose",
1045
+ message: `The subtitle takes ${o.length} lines. Cut it to one short takeaway, about 10 words; let the drawing say the rest.`,
1046
+ ids: []
1047
+ });
1048
+ }
1049
+ return (e.appearance.notes ?? []).forEach((n, o) => {
1050
+ n.near || t.push({
1051
+ level: "warning",
1052
+ code: "heading-prose",
1053
+ message: "This note has no near=, so it sits under the heading as prose. Anchor it with near=<id> to the object it explains, or make it a footnote under the drawing.",
1054
+ line: e.noteLines[o],
1055
+ ids: []
1056
+ });
1057
+ }), [...t, ...Bs(e)];
1058
+ }
1059
+ function Bs(e) {
1060
+ const t = new Set((e.appearance.footnotes ?? []).flatMap((n) => n.mark ? [n.mark] : []));
1061
+ return t.size ? [
1062
+ ...e.objects.map((n) => ({ id: n.id, text: n.label, line: n.line })),
1063
+ ...e.edges.map((n) => ({ id: n.id, text: n.label, line: n.line }))
1064
+ ].flatMap(
1065
+ (n) => [...n.text.matchAll(/\[([A-Za-z0-9*]{1,3})\]/g)].filter((o) => !t.has(o[1])).map((o) => ({
1066
+ level: "warning",
1067
+ code: "footnote-missing",
1068
+ message: `${n.id} points at [${o[1]}], but no footnote has that marker. Add footnote ${o[1]} "…" or fix the label.`,
1069
+ line: n.line,
1070
+ ids: [n.id]
1071
+ }))
1072
+ ) : [];
1073
+ }
1074
+ class Le extends Error {
1075
+ constructor(t, s = 0, n = 0) {
1076
+ super((s ? `Line ${s}${n ? `, column ${n}` : ""}: ` : "") + t), this.line = s, this.column = n, this.name = "DslError";
1077
+ }
1078
+ }
1079
+ const uo = { "+": "added", "-": "removed", "~": "changed", ".": "context" }, zs = (e) => ({ value: String(e), quoted: !1 }), Us = (e) => ({ value: e, quoted: !0 }), qs = 'A quote inside a quoted string needs a backslash: write \\" for each inner quote.';
1080
+ function Gs(e, t = 0) {
1081
+ const s = [], n = [];
1082
+ let o = "", r = 0, d = 0, h = !1, c = !1;
1083
+ const y = () => {
1084
+ o && (s.push(o), n.push(r + 1)), o = "";
1085
+ };
1086
+ for (let w = 0; w < e.length; w++) {
1087
+ const l = e[w];
1088
+ if (o || (r = w), c) {
1089
+ o += l, c = !1;
1090
+ continue;
1091
+ }
1092
+ if (h && l === "\\") {
1093
+ o += l, c = !0;
1094
+ continue;
1095
+ }
1096
+ if (l === '"') {
1097
+ if (h && w + 1 < e.length && !/[\s#]/.test(e[w + 1]) && !e.startsWith("//", w + 1))
1098
+ throw new Le(qs, t, w + 1);
1099
+ h || (d = w), h = !h, o += l;
1100
+ continue;
1101
+ }
1102
+ const p = l === "/" && e[w + 1] === "/" && !/[^\s"]/.test(e[w - 1] ?? " ");
1103
+ if (!h && (l === "#" || p))
1104
+ return y(), { tokens: s, columns: n, comment: e.slice(w).trim() };
1105
+ !h && /\s/.test(l) ? y() : o += l;
1106
+ }
1107
+ if (h) throw new Le("Unclosed quoted string.", t, d + 1);
1108
+ return y(), { tokens: s, columns: n };
1109
+ }
1110
+ function _n(e, t, s) {
1111
+ if (!e.startsWith('"')) return zs(e);
1112
+ try {
1113
+ return Us(JSON.parse(e));
1114
+ } catch {
1115
+ throw new Le(
1116
+ 'Invalid escape in a quoted string. Use \\" for a quote, \\\\ for a backslash and \\n for a line break.',
1117
+ t,
1118
+ s
1119
+ );
1120
+ }
1121
+ }
1122
+ function Hs(e) {
1123
+ if (typeof e != "string") throw new Le("Source must be text.");
1124
+ if (e.length > 3e5) throw new Le("Limit: 300,000 source characters.");
1125
+ return { lines: e.split(/\r?\n/).map((s, n) => {
1126
+ const o = n + 1, { tokens: r, columns: d, comment: h } = Gs(s, o);
1127
+ if (!r.length) return h ? { kind: "comment", text: h } : { kind: "blank" };
1128
+ const [c, ...y] = r, w = uo[c[0]] && c.length > 1 ? c[0] : void 0, l = w ? c.slice(1) : c, p = [], a = [];
1129
+ return y.forEach((i, g) => {
1130
+ const f = i.indexOf("="), M = d[g + 1];
1131
+ if (f > 0 && !i.startsWith('"')) {
1132
+ const k = i.slice(0, f);
1133
+ if (a.some(([S]) => S === k)) throw new Le(`Duplicate attribute ${k}.`, o);
1134
+ a.push([k, _n(i.slice(f + 1), o, M + f + 1)]);
1135
+ } else p.push(_n(i, o, M));
1136
+ }), { kind: "statement", command: l, ...w ? { mark: w } : {}, args: p, attrs: a, comment: h, line: o };
1137
+ }) };
1138
+ }
1139
+ const Ys = { wide: 2, slide: 1.78, square: 1, page: 0.77, tall: 0.6 };
1140
+ function Vt(e, t, s) {
1141
+ const n = st(e, t);
1142
+ for (let o = s; o && o !== "root"; o = st(e, o))
1143
+ if (st(e, o) === n) return o === t ? void 0 : o;
1144
+ }
1145
+ const Ws = ["near", "nudge", "stay", "pin"], In = {
1146
+ "link-base": "linkBase",
1147
+ editor: "editor",
1148
+ "strike-removed": "strikeRemoved"
1149
+ }, Tn = {
1150
+ "padding-x": "paddingX",
1151
+ "padding-y": "paddingY",
1152
+ radius: "radius",
1153
+ "title-font": "titleFont",
1154
+ "annotation-font": "annotationFont",
1155
+ canvas: "canvas",
1156
+ text: "text",
1157
+ connection: "connection"
1158
+ }, Ln = [
1159
+ "compound-flow",
1160
+ "boundary-align",
1161
+ "compound-spring",
1162
+ "tidy",
1163
+ "stress",
1164
+ "force",
1165
+ "flow",
1166
+ "layered",
1167
+ "tree",
1168
+ "grid"
1169
+ ], Zt = {
1170
+ "rank-gap": { key: "rankGap", min: 12, max: 220 },
1171
+ "group-gap": { key: "groupGap", min: 12, max: 180 },
1172
+ "node-gap": { key: "nodeGap", min: 4, max: 160 },
1173
+ "boundary-pull": { key: "boundaryPull", min: 0, max: 100 },
1174
+ "hierarchy-sweeps": { key: "hierarchySweeps", min: 1, max: 4 },
1175
+ "edge-length": { key: "edgeLength", min: 20, max: 260 },
1176
+ repulsion: { key: "repulsion", min: 0, max: 100 },
1177
+ "flow-strength": { key: "flowStrength", min: 0, max: 100 },
1178
+ alignment: { key: "alignment", min: 0, max: 100 },
1179
+ compactness: { key: "compactness", min: 0, max: 100 },
1180
+ "grid-strength": { key: "gridStrength", min: 0, max: 100 },
1181
+ ordering: { key: "ordering", choices: ["stable", "crossings"] },
1182
+ fold: { key: "fold", choices: ["auto", "never"] },
1183
+ aspect: { key: "aspect", choices: ["1", "1.333", "1.6", "2", "0.75"] },
1184
+ root: { key: "rootId", choices: [] }
1185
+ }, Rn = {
1186
+ clearance: { key: "clearance", min: 4, max: 30 },
1187
+ "port-gap": { key: "portGap", min: 6, max: 28 },
1188
+ "edge-gap": { key: "edgeGap", min: 4, max: 48 },
1189
+ "bend-penalty": { key: "bendPenalty", min: 0, max: 100 },
1190
+ "crossing-penalty": { key: "crossingPenalty", min: 0, max: 1200 },
1191
+ "shared-penalty": { key: "sharedPenalty", min: 0, max: 20 },
1192
+ "parallel-penalty": { key: "parallelPenalty", min: 0, max: 60 },
1193
+ "port-stability": { key: "portStability", min: 0, max: 150 },
1194
+ "fanout-penalty": { key: "fanoutPenalty", min: 0, max: 160 },
1195
+ passes: { key: "passes", min: 1, max: 5 },
1196
+ "corner-radius": { key: "cornerRadius", min: 0, max: 16 },
1197
+ standoff: { key: "standoff", min: 0, max: 40 }
1198
+ };
1199
+ function Xs(e, t) {
1200
+ return t && e === "gap" ? "Engine lines space boxes with node-gap= and rank-gap=." : !t && e in Zt ? `${e}= needs an engine: add engine=layered or another engine.` : e === "fit" ? "fit= goes on the layout root line." : "draftably skill print lists the layout settings.";
1201
+ }
1202
+ const Ks = /^[A-Za-z_][A-Za-z0-9_.-]*$/, jt = /^[A-Za-z_][A-Za-z0-9_-]*$/, go = ["box", "pill", "circle", "diamond", "text", "marker"], Qs = go.filter((e) => e !== "marker"), On = ["box", "soft", "none"], Vs = /^[A-Za-z]{1,8}$/, $n = ["auto", "left", "right", "top", "bottom"];
1203
+ function Zs(e) {
1204
+ const t = typeof e == "string" ? Hs(e) : e, s = {
1205
+ title: "Untitled diagram",
1206
+ objects: [],
1207
+ edges: [],
1208
+ layouts: [],
1209
+ hints: [],
1210
+ routing: {},
1211
+ appearance: Jn(),
1212
+ themeLine: 0,
1213
+ colorLines: /* @__PURE__ */ new Map(),
1214
+ legendLines: [],
1215
+ noteLines: [],
1216
+ footnoteLines: [],
1217
+ stateLines: /* @__PURE__ */ new Map(),
1218
+ phases: [],
1219
+ warnings: []
1220
+ }, n = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Set(), r = /* @__PURE__ */ new Set(), d = /* @__PURE__ */ new Set();
1221
+ let h = 0;
1222
+ for (const c of t.lines) {
1223
+ if (c.kind !== "statement") continue;
1224
+ const y = c.line, { command: w, args: l } = c, p = new Map(c.attrs), a = (m) => {
1225
+ throw new Le(m, y);
1226
+ }, i = (m, b) => {
1227
+ m || a(b);
1228
+ }, g = (m) => {
1229
+ for (const b of p.keys())
1230
+ i(m.includes(b), `Unknown ${w} attribute: ${b}.`);
1231
+ }, f = (m, b = m) => i(l.length >= m && l.length <= b, `Wrong number of arguments for ${w}.`), M = (m) => (i(
1232
+ m && !m.quoted && Ks.test(m.value),
1233
+ "Expected a stable identifier (letters, digits, _, . or -)."
1234
+ ), m.value), k = (m) => m?.value ?? "", S = (m, b, T = -1e5, F = 1e5) => {
1235
+ const X = p.get(m);
1236
+ if (X === void 0) return b;
1237
+ const B = Number(X.value);
1238
+ return i(
1239
+ !X.quoted && Number.isFinite(B) && B >= T && B <= F,
1240
+ `Expected ${m} from ${T} to ${F}; got ${X.value}.`
1241
+ ), B;
1242
+ }, D = (m, b) => {
1243
+ const T = p.get(m);
1244
+ return !T.quoted && Vs.test(T.value) ? T.value : S(m, b, b, 1e6);
1245
+ }, _ = (m, b, T) => {
1246
+ const F = p.get(m)?.value ?? b;
1247
+ return i(T.includes(F), `Expected ${m}=${T.join("|")}; got ${F}.`), F;
1248
+ }, $ = (m) => {
1249
+ const b = Number(m.value);
1250
+ return i(
1251
+ !m.quoted && Gt.includes(b),
1252
+ `Expected shade=${Gt.join("|")}; got ${m.value}.`
1253
+ ), b;
1254
+ }, x = (m) => {
1255
+ const b = p.get(m);
1256
+ return i(
1257
+ b.quoted && Po.test(b.value),
1258
+ `Expected ${m}="#rrggbb" in double quotes; got ${b.value || "nothing"}.`
1259
+ ), b.value.toUpperCase();
1260
+ }, E = (m) => {
1261
+ i(!d.has(m), `Duplicate declaration: ${m}. Edit the existing line instead.`), d.add(m);
1262
+ }, v = c.mark && uo[c.mark];
1263
+ i(
1264
+ !c.mark || ["node", "group", "edge"].includes(w),
1265
+ `Only node, group and edge lines take a ${c.mark} mark.`
1266
+ );
1267
+ const u = () => {
1268
+ for (const m of ["was", "was-shape", "was-count"])
1269
+ i(!p.has(m) || c.mark === "~", `${m}= belongs on a changed (~) line.`);
1270
+ return {
1271
+ ...p.has("was") ? { was: p.get("was").value } : {},
1272
+ ...p.has("was-shape") ? { wasShape: _("was-shape", "box", Qs) } : {},
1273
+ ...p.has("was-count") ? { wasCount: D("was-count", 1) } : {}
1274
+ };
1275
+ }, A = (m) => {
1276
+ const b = {};
1277
+ for (const [T, F] of Object.entries(m))
1278
+ p.has(T) && ("min" in F ? b[F.key] = S(T, 0, F.min, F.max) : F.choices.length ? b[F.key] = _(T, F.choices[0], F.choices) : b[F.key] = M(p.get(T)));
1279
+ return b;
1280
+ };
1281
+ switch (w) {
1282
+ case "diagram":
1283
+ f(1), g(["version", "width"]), i(!h, "Only one diagram declaration is allowed."), h = y, s.title = k(l[0]), S("version", 1, 1, 1), s.title && ((s.appearance.heading ??= {}).title = s.title), p.has("width") && ((s.appearance.heading ??= {}).width = S("width", 0, 160, 8e3));
1284
+ break;
1285
+ case "compare": {
1286
+ f(0, 2), g(["direction", "aspect"]), E("compare");
1287
+ const m = _("direction", "auto", ["auto", "right", "down"]);
1288
+ s.appearance.compare = {
1289
+ before: k(l[0]) || "Before",
1290
+ after: k(l[1]) || "After",
1291
+ ...m !== "auto" ? { direction: m } : {},
1292
+ ...p.has("aspect") ? { aspect: S("aspect", 1.6, 0.25, 8) } : {}
1293
+ };
1294
+ break;
1295
+ }
1296
+ case "config": {
1297
+ f(0), g(Object.keys(In)), i(p.size, `config needs a setting: ${Object.keys(In).join(", ")}.`);
1298
+ const m = s.appearance.config ??= {};
1299
+ for (const [b, T] of p) {
1300
+ const F = n.get(b);
1301
+ F && s.warnings.push({
1302
+ code: "config-repeated",
1303
+ message: `config ${b} is also set on line ${F}; this line wins.`,
1304
+ line: y
1305
+ }), n.set(b, y), b === "editor" ? m.editor = _("editor", "vscode", Ts) : b === "strike-removed" ? m.strikeRemoved = _(b, "off", ["on", "off"]) === "on" : (i(T.quoted, `Expected ${b}="path" in double quotes.`), m.linkBase = T.value);
1306
+ }
1307
+ break;
1308
+ }
1309
+ case "state": {
1310
+ i(l.length >= 1, 'A state needs an ID: state write "Write path" api orders.'), g(["rest"]);
1311
+ const m = M(l[0]), b = l[1]?.quoted ? l[1].value : void 0, T = l.slice(b === void 0 ? 1 : 2).map((B) => M(B)), F = s.appearance.states ??= [];
1312
+ let X = F.find((B) => B.id === m);
1313
+ X || (X = { id: m, label: b ?? m, ids: [], rest: "dim" }, F.push(X)), p.has("rest") && (X.rest = _("rest", "dim", ["dim", "plain"]));
1314
+ for (const B of T)
1315
+ i(!X.ids.includes(B), `${B} is already in state ${m}.`), X.ids.push(B), s.stateLines.set(`${m}:${B}`, y);
1316
+ break;
1317
+ }
1318
+ case "phase": {
1319
+ i(
1320
+ l.length >= 3 && l[1]?.quoted,
1321
+ 'A phase needs an ID, a label and its messages: phase preview "Preview" m1 m2.'
1322
+ ), g([]);
1323
+ const m = M(l[0]);
1324
+ i(!s.phases.some((b) => b.id === m), `Duplicate phase ${m}.`), s.phases.push({ id: m, label: l[1].value, ids: l.slice(2).map((b) => M(b)), line: y });
1325
+ break;
1326
+ }
1327
+ case "was-order":
1328
+ i(l.length, "was-order lists the older message order: was-order m2 m1."), g([]), E("was-order"), s.wasOrder = { ids: l.map((m) => M(m)), line: y };
1329
+ break;
1330
+ case "subtitle":
1331
+ f(1), g([]), E("subtitle"), i(k(l[0]).trim(), "A subtitle needs its text in quotes."), (s.appearance.heading ??= {}).subtitle = k(l[0]);
1332
+ break;
1333
+ case "node":
1334
+ case "group": {
1335
+ f(2), g(
1336
+ w === "node" ? [
1337
+ "in",
1338
+ "color",
1339
+ "shade",
1340
+ "shape",
1341
+ "was",
1342
+ "was-shape",
1343
+ "was-count",
1344
+ "href",
1345
+ "count",
1346
+ "span"
1347
+ ] : ["in", "color", "shade", "was", "href", "frame", "fold"]
1348
+ );
1349
+ const m = M(l[0]);
1350
+ i(m !== "root", "root is reserved for the outer layout scope."), i(!o.has(m), `Duplicate node/group id ${m}.`), o.add(m);
1351
+ const b = p.get("color")?.value ?? "auto";
1352
+ i(
1353
+ !p.get("color")?.quoted && jt.test(b),
1354
+ `Expected color=auto, a built-in color (${Ht.join(", ")}) or a theme-color name; got ${b}.`
1355
+ );
1356
+ const T = p.has("shade") ? $(p.get("shade")) : void 0;
1357
+ s.objects.push({
1358
+ id: m,
1359
+ type: w,
1360
+ label: k(l[1]),
1361
+ parent: p.has("in") ? M(p.get("in")) : "root",
1362
+ color: b,
1363
+ ...T !== void 0 ? { shade: T } : {},
1364
+ shape: w === "node" ? _("shape", "box", go) : "box",
1365
+ ...c.mark ? { status: v } : {},
1366
+ ...u(),
1367
+ ...p.has("href") ? { href: k(p.get("href")) } : {},
1368
+ ...p.has("count") ? { count: D("count", 2) } : {},
1369
+ ...w === "group" && _("fold", "auto", ["auto", "never"]) === "never" ? { fold: "never" } : {},
1370
+ ...w === "group" && _("frame", "box", On) !== "box" ? { frame: _("frame", "box", On) } : {},
1371
+ ...p.has("span") ? {
1372
+ span: p.get("span").value === "var" ? "var" : S("span", 1, 1, 4096)
1373
+ } : {},
1374
+ line: y
1375
+ });
1376
+ break;
1377
+ }
1378
+ case "edge": {
1379
+ f(4, 5), g(["kind", "from", "to", "was", "constraint", "directed", "head", "tail"]), i(
1380
+ l[2]?.value === "->" && !l[2].quoted,
1381
+ 'Edges use: edge id source -> target "label".'
1382
+ );
1383
+ const m = M(l[0]);
1384
+ i(!r.has(m), `Duplicate edge id ${m}.`), r.add(m);
1385
+ const b = _("directed", "true", ["true", "false"]) === "false", T = _("head", "arrow", An), F = _("tail", "none", An);
1386
+ i(
1387
+ !b || !(p.has("head") || p.has("tail")),
1388
+ `Edge ${m} has directed=false, so it has no ends to mark. Remove head= and tail=, or remove directed=false.`
1389
+ ), s.edges.push({
1390
+ id: m,
1391
+ source: M(l[1]),
1392
+ target: M(l[3]),
1393
+ label: k(l[4]),
1394
+ dashed: _("kind", "sync", ["sync", "async"]) === "async",
1395
+ from: _("from", "auto", $n),
1396
+ to: _("to", "auto", $n),
1397
+ ...b ? { directed: !1 } : {},
1398
+ ...T !== "arrow" ? { head: T } : {},
1399
+ ...F !== "none" ? { tail: F } : {},
1400
+ ..._("constraint", "true", ["true", "false"]) === "false" ? { constraint: !1 } : {},
1401
+ ...c.mark ? { status: v } : {},
1402
+ ...u(),
1403
+ line: y
1404
+ });
1405
+ break;
1406
+ }
1407
+ case "layout": {
1408
+ const m = M(l[0]), b = p.get("engine")?.value, T = s.layouts.findIndex((P) => P.scope === m);
1409
+ T >= 0 && (s.warnings.push({
1410
+ code: "layout-repeated",
1411
+ message: `layout ${m} is also set on line ${s.layouts[T].line}; this line wins.`,
1412
+ line: y
1413
+ }), s.layouts.splice(T, 1));
1414
+ const F = (P) => {
1415
+ for (const R of [...p.keys()])
1416
+ P.includes(R) || (s.warnings.push({
1417
+ code: "layout-attribute",
1418
+ message: `This layout line does not take ${R}=, so it is ignored. ${Xs(R, b !== void 0)}`,
1419
+ line: y
1420
+ }), p.delete(R));
1421
+ }, X = [
1422
+ "direction",
1423
+ "min-width",
1424
+ "min-height",
1425
+ ...m === "root" ? ["fit"] : []
1426
+ ];
1427
+ let B;
1428
+ if (b !== void 0)
1429
+ f(1), i(
1430
+ Ln.includes(b),
1431
+ `Unknown layout engine ${b}; use ${Ln.join(", ")}.`
1432
+ ), F(["engine", ...X, ...Object.keys(Zt)]), B = { algorithm: b, params: A(Zt) };
1433
+ else {
1434
+ f(2);
1435
+ const P = l[1]?.value;
1436
+ F(
1437
+ P === "cells" ? ["columns", "unit", "unit-width", "ruler", ...X] : ["gap", ...P === "flow" ? ["fold"] : [], ...X]
1438
+ );
1439
+ }
1440
+ const G = b ? "flow" : l[1]?.value;
1441
+ i(
1442
+ ["flow", "row", "column", "lanes", "sequence", "cells"].includes(G),
1443
+ `The ${G} recipe is not supported; use flow, row, column, lanes, sequence or cells, or engine=.`
1444
+ ), i(
1445
+ !["lanes", "sequence"].includes(G) || m === "root",
1446
+ `${G} arranges the whole diagram: write layout root ${G}.`
1447
+ ), i(
1448
+ G !== "cells" || m !== "root",
1449
+ "Cells lay out a group; give the cells a group and use layout <group> cells."
1450
+ ), s.layouts.push({
1451
+ scope: m,
1452
+ algorithm: G,
1453
+ ...B ? { engine: B } : {},
1454
+ direction: _("direction", "auto", ["auto", "right", "down"]),
1455
+ fold: b ? "auto" : _("fold", "auto", ["auto", "never"]),
1456
+ ...p.has("fit") ? { fit: _("fit", "slide", Object.keys(Ys)) } : {},
1457
+ ...p.has("columns") ? { columns: S("columns", 1, 1, 512) } : {},
1458
+ ...p.has("unit") ? {
1459
+ unit: _("unit", "byte", ["bit", "byte"]),
1460
+ ruler: _("ruler", "on", ["on", "off"]) === "on",
1461
+ ...p.has("unit-width") ? { unitWidth: S("unit-width", 24, 8, 200) } : {}
1462
+ } : {},
1463
+ gap: S("gap", 28, 8, 300),
1464
+ minWidth: S("min-width", 0, 0, 1e4),
1465
+ minHeight: S("min-height", 0, 0, 1e4),
1466
+ line: y
1467
+ });
1468
+ break;
1469
+ }
1470
+ case "theme": {
1471
+ f(1), g(Object.keys(Tn)), E("theme");
1472
+ const m = l[0].value;
1473
+ i(ln.includes(m), `Unknown theme ${m}; use ${ln.join(", ")}.`), s.appearance.theme = m, s.themeLine = y;
1474
+ const b = s.appearance.overrides;
1475
+ for (const [T, F] of Object.entries(Tn))
1476
+ p.has(T) && (F === "paddingX" || F === "paddingY" || F === "radius" ? b[F] = S(T, 0, fn[F].min, fn[F].max) : F === "titleFont" || F === "annotationFont" ? b[F] = _(T, "sans", Io) : b[F] = x(T));
1477
+ break;
1478
+ }
1479
+ case "theme-color": {
1480
+ f(1), g(["shade", "fill", "stroke", "ink"]);
1481
+ const m = l[0].value;
1482
+ i(
1483
+ !l[0].quoted && jt.test(m) && m !== "auto",
1484
+ "Expected a color family name (letters, digits, _ or -)."
1485
+ );
1486
+ const b = p.has("shade") ? $(p.get("shade")) : 500;
1487
+ E(`theme-color:${m}:${b}`);
1488
+ const T = { family: m, shade: b };
1489
+ for (const F of ["fill", "stroke", "ink"])
1490
+ p.has(F) && (T[F] = x(F));
1491
+ i(
1492
+ Tt(m) || T.fill && T.stroke && T.ink,
1493
+ `${m} is not a built-in color, so shade ${b} needs fill, stroke and ink.`
1494
+ ), i(T.fill || T.stroke || T.ink, "Set at least one of fill, stroke and ink."), s.appearance.colors.push(T), s.colorLines.set(`${m}:${b}`, y);
1495
+ break;
1496
+ }
1497
+ case "legend": {
1498
+ if (l[0]?.value === "line" && !l[0].quoted) {
1499
+ f(3), g([]);
1500
+ const T = l[1].value;
1501
+ i(
1502
+ !l[1].quoted && dn.includes(T),
1503
+ `Expected legend line ${dn.join("|")} "meaning".`
1504
+ ), E(`legend:line:${T}`), i(k(l[2]).trim(), "A legend entry needs its meaning in quotes."), (s.appearance.legend ??= []).push({ line: T, label: k(l[2]) }), s.legendLines.push(y);
1505
+ break;
1506
+ }
1507
+ f(2), g(["shade"]);
1508
+ const m = l[0].value;
1509
+ i(
1510
+ !l[0].quoted && jt.test(m) && m !== "auto",
1511
+ `Expected legend family "meaning", with a built-in color (${Ht.join(", ")}) or a theme-color name.`
1512
+ ), E(`legend:${m}:${p.get("shade")?.value ?? ""}`);
1513
+ const b = p.has("shade") ? $(p.get("shade")) : void 0;
1514
+ i(k(l[1]).trim(), "A legend entry needs its meaning in quotes."), (s.appearance.legend ??= []).push({
1515
+ family: m,
1516
+ label: k(l[1]),
1517
+ ...b !== void 0 ? { shade: b } : {}
1518
+ }), s.legendLines.push(y);
1519
+ break;
1520
+ }
1521
+ case "note": {
1522
+ f(1), g(["near", "side", "width"]), i(l[0].quoted && l[0].value.trim(), "A note needs its text in quotes."), i(p.has("near") || !p.has("side"), "side= places a note beside near=<id>."), (s.appearance.notes ??= []).push({
1523
+ text: l[0].value,
1524
+ ...p.has("near") ? { near: M(p.get("near")) } : {},
1525
+ ...p.has("side") ? { side: _("side", "below", fs) } : {},
1526
+ ...p.has("width") ? { width: S("width", ro, 80, 1200) } : {}
1527
+ }), s.noteLines.push(y);
1528
+ break;
1529
+ }
1530
+ case "footnote": {
1531
+ f(1, 2), g([]);
1532
+ const m = l[l.length - 1], b = l.length === 2 ? l[0] : void 0;
1533
+ i(m.quoted && m.value.trim(), "A footnote needs its text in quotes."), i(
1534
+ !b || !b.quoted && /^[A-Za-z0-9*]{1,3}$/.test(b.value),
1535
+ 'A footnote marker is a short word: footnote 1 "text".'
1536
+ ), b && E(`footnote:${b.value}`), (s.appearance.footnotes ??= []).push({
1537
+ text: m.value,
1538
+ ...b ? { mark: b.value } : {}
1539
+ }), s.footnoteLines.push(y);
1540
+ break;
1541
+ }
1542
+ case "routing":
1543
+ f(0), g(Object.keys(Rn)), E("routing"), s.routing = A(Rn);
1544
+ break;
1545
+ case "order":
1546
+ f(2, 300), g([]), s.hints.push({ type: "order", scope: M(l[0]), ids: l.slice(1).map(M), line: y }), E("order:" + l[0].value);
1547
+ break;
1548
+ case "align": {
1549
+ f(3, 300), g(["strength"]);
1550
+ const m = l[0]?.value;
1551
+ i(m === "x" || m === "y", "Expected align x or align y.");
1552
+ const b = l.slice(1).map(M);
1553
+ E(`align:${m}:${b.join(",")}`), s.hints.push({
1554
+ type: "align",
1555
+ axis: m,
1556
+ ids: b,
1557
+ strength: _("strength", "prefer", ["prefer", "required"]),
1558
+ line: y
1559
+ });
1560
+ break;
1561
+ }
1562
+ case "near":
1563
+ case "nudge":
1564
+ case "stay":
1565
+ case "pin":
1566
+ case "size": {
1567
+ f(w === "near" ? 2 : 1);
1568
+ const m = M(l[0]);
1569
+ if (E(`${w}:${m}`), w === "near") {
1570
+ g(["side", "gap", "offset", "strength"]);
1571
+ const b = M(l[1]);
1572
+ i(b !== m, "An object cannot be placed relative to itself."), s.hints.push({
1573
+ type: "near",
1574
+ id: m,
1575
+ ref: b,
1576
+ side: _("side", "right", ["right", "left", "above", "below"]),
1577
+ gap: S("gap", 28, 0, 2e3),
1578
+ offset: S("offset", 0),
1579
+ strength: _("strength", "prefer", ["prefer", "required"]),
1580
+ line: y
1581
+ });
1582
+ } else if (w === "nudge")
1583
+ g(["dx", "dy"]), s.hints.push({ type: "nudge", id: m, dx: S("dx", 0), dy: S("dy", 0), line: y });
1584
+ else if (w === "stay")
1585
+ g(["x", "y", "weight"]), s.hints.push({
1586
+ type: "stay",
1587
+ id: m,
1588
+ // The root has no frame, so an arrangement can place objects left of or above 0,0.
1589
+ x: S("x", 0),
1590
+ y: S("y", 0),
1591
+ weight: S("weight", 8, 1, 100),
1592
+ line: y
1593
+ });
1594
+ else if (w === "pin")
1595
+ g(["x", "y"]), s.hints.push({ type: "pin", id: m, x: S("x", 0, 0), y: S("y", 0, 0), line: y });
1596
+ else {
1597
+ g(["width", "height", "min-height"]);
1598
+ const b = p.get("height")?.value === "auto";
1599
+ i(
1600
+ b || !p.has("min-height"),
1601
+ "min-height is a floor under height=auto. Write height=auto, or remove min-height."
1602
+ ), s.hints.push({
1603
+ type: "size",
1604
+ id: m,
1605
+ width: S("width", 164, 40, 1200),
1606
+ ...b ? {} : { height: S("height", 56, 24, 1200) },
1607
+ ...p.has("min-height") ? { minHeight: S("min-height", 24, 24, 1200) } : {},
1608
+ line: y
1609
+ });
1610
+ }
1611
+ break;
1612
+ }
1613
+ case "view":
1614
+ case "snapshot":
1615
+ case "box":
1616
+ a(`${w} statements are not supported yet. Remove them to open this file.`);
1617
+ break;
1618
+ default:
1619
+ a(`Unknown statement ${w}.`);
1620
+ }
1621
+ }
1622
+ if (s.objects.length > 500) throw new Le("Limit: 500 nodes and groups.");
1623
+ if (s.edges.length > 1200) throw new Le("Limit: 1,200 edges.");
1624
+ return Js(s), s;
1625
+ }
1626
+ function st(e, t) {
1627
+ let s = e.get(t)?.parent ?? "root";
1628
+ for (; s !== "root" && e.get(s)?.frame; ) s = e.get(s).parent;
1629
+ return s;
1630
+ }
1631
+ function Js(e) {
1632
+ const t = new Map(e.objects.map((a) => [a.id, a])), s = (a, i, g) => o(
1633
+ !t.get(a)?.frame,
1634
+ `${a} is a ${t.get(a)?.frame} group, so it has no ${g} of its own. Use frame=box, or ${g === "layout" ? "set the layout of the container around it" : "place its members"}.`,
1635
+ i
1636
+ ), n = (a) => st(t, a), o = (a, i, g) => {
1637
+ if (!a) throw new Le(i, g);
1638
+ }, r = (a, i) => o(t.has(a), `Unknown node/group ${a}.`, i), d = (a, i) => o(a === "root" || t.get(a)?.type === "group", `Unknown container ${a}.`, i), h = /* @__PURE__ */ new Map();
1639
+ for (const a of e.appearance.colors)
1640
+ h.has(a.family) || h.set(a.family, /* @__PURE__ */ new Set()), h.get(a.family).add(a.shade);
1641
+ (e.appearance.legend ?? []).forEach((a, i) => {
1642
+ if (!a.family || Tt(a.family)) return;
1643
+ const g = h.get(a.family), f = a.shade ?? Ve;
1644
+ o(
1645
+ g?.has(f),
1646
+ g ? `${a.family} has no shade ${f}; it defines ${[...g].sort((M, k) => M - k).join(", ")}.` : `Unknown color ${a.family}. Define it with theme-color ${a.family} shade=… fill= stroke= ink=.`,
1647
+ e.legendLines[i]
1648
+ );
1649
+ });
1650
+ for (const a of e.objects) {
1651
+ if (a.color !== "auto" && !Tt(a.color)) {
1652
+ const g = h.get(a.color), f = a.shade ?? (a.type === "group" ? Fo(e.appearance.theme) : Ve);
1653
+ o(
1654
+ g,
1655
+ `Unknown color ${a.color}. Define it with theme-color ${a.color} shade=… fill= stroke= ink=.`,
1656
+ a.line
1657
+ ), o(
1658
+ g.has(f),
1659
+ `${a.color} has no shade ${f}${a.shade === void 0 ? " (the default)" : ""}; it defines ${[...g].sort((M, k) => M - k).join(", ")}.`,
1660
+ a.line
1661
+ );
1662
+ }
1663
+ d(a.parent, a.line);
1664
+ const i = /* @__PURE__ */ new Set();
1665
+ for (let g = a; g; g = t.get(g.parent))
1666
+ o(!i.has(g.id), `Containment cycle at ${g.id}.`, a.line), i.add(g.id), o(i.size <= 12, "Limit: 12 nesting levels.", a.line);
1667
+ }
1668
+ if (e.layouts.some((a) => a.scope === "root" && a.algorithm === "lanes"))
1669
+ for (const a of e.objects)
1670
+ a.parent === "root" && (o(
1671
+ a.type === "group",
1672
+ `In a lanes diagram every node sits in a lane; put ${a.id} in= one of the top-level groups.`,
1673
+ a.line
1674
+ ), o(!a.frame, `${a.id} is a lane, so it needs its frame; remove frame=.`, a.line));
1675
+ const c = e.layouts.some((a) => a.scope === "root" && a.algorithm === "sequence");
1676
+ if (c)
1677
+ for (const a of e.objects)
1678
+ o(
1679
+ a.type === "node" ? t.get(a.parent)?.type !== "node" : a.parent === "root" && !a.frame,
1680
+ `In a sequence diagram a group is a band of participants: put ${a.id} at the top level and its participants in=${a.id}.`,
1681
+ a.line
1682
+ ), o(
1683
+ a.type === "node" || e.objects.some((i) => i.parent === a.id),
1684
+ `Group ${a.id} has no participants, so it has no band to draw. Put a participant in=${a.id} or remove the group.`,
1685
+ a.line
1686
+ );
1687
+ const y = new Set(e.edges.map((a) => a.id)), w = /* @__PURE__ */ new Set();
1688
+ for (const a of e.phases) {
1689
+ o(
1690
+ c,
1691
+ "A phase groups messages in a sequence diagram; use layout root sequence.",
1692
+ a.line
1693
+ );
1694
+ for (const f of a.ids)
1695
+ o(
1696
+ y.has(f),
1697
+ `Unknown message ${f} in phase ${a.id}; a phase lists edge IDs.`,
1698
+ a.line
1699
+ ), o(!w.has(f), `${f} is already in another phase.`, a.line), w.add(f);
1700
+ const i = e.edges.flatMap((f, M) => a.ids.includes(f.id) ? [M] : []), g = e.edges.slice(i[0], i[i.length - 1] + 1).filter((f) => !a.ids.includes(f.id) && f.status !== "removed").map((f) => f.id);
1701
+ o(
1702
+ !g.length,
1703
+ `Phase ${a.id} skips ${g.join(", ")}: a phase is a run of consecutive messages. Include it or split the phase.`,
1704
+ a.line
1705
+ );
1706
+ }
1707
+ if (e.wasOrder) {
1708
+ const { ids: a, line: i } = e.wasOrder, g = (M) => e.edges.find((k) => k.id === M), f = (M) => e.warnings.push({ code: "was-order", message: M, line: i });
1709
+ o(
1710
+ e.layouts.some((M) => M.scope === "root" && M.algorithm === "sequence"),
1711
+ "was-order gives the older order of a sequence diagram; use layout root sequence.",
1712
+ i
1713
+ ), o(new Set(a).size === a.length, "was-order lists a message twice.", i);
1714
+ for (const M of a)
1715
+ o(g(M)?.status !== "added", `${M} is added, so was-order can't list it.`, i), g(M) || f(`was-order lists ${M}, which is not a message. The panels skip it.`);
1716
+ for (const M of e.edges)
1717
+ M.status !== "added" && !a.includes(M.id) && f(`was-order leaves out ${M.id}, so the older panel keeps it on its new row.`);
1718
+ }
1719
+ for (const a of e.edges)
1720
+ for (const i of [a.source, a.target]) {
1721
+ r(i, a.line);
1722
+ const g = t.get(i), f = i === a.source ? a.target : a.source;
1723
+ o(
1724
+ !c || g.type === "node",
1725
+ `A message joins participants, and ${i} is a group. End ${a.id} on one of its participants.`,
1726
+ a.line
1727
+ ), o(
1728
+ g.type === "node" || !g.frame,
1729
+ `${i} is a ${g.frame} group, which has no frame for a line to end on. Connect to one of its members, or use frame=box.`,
1730
+ a.line
1731
+ );
1732
+ let M = !1;
1733
+ for (let k = t.get(f)?.parent; k && k !== "root"; k = t.get(k)?.parent)
1734
+ k === i && (M = !0);
1735
+ o(
1736
+ !M,
1737
+ `${f} is inside ${i}, so a line between them has nowhere to go.`,
1738
+ a.line
1739
+ );
1740
+ }
1741
+ (e.appearance.notes ?? []).forEach((a, i) => {
1742
+ if (!(!a.near || t.has(a.near))) {
1743
+ if (!y.has(a.near)) return r(a.near, e.noteLines[i]);
1744
+ o(
1745
+ c,
1746
+ `near=${a.near} names a connection. Only a sequence diagram anchors a note to a message; use a node or group here.`,
1747
+ e.noteLines[i]
1748
+ );
1749
+ }
1750
+ });
1751
+ const l = new Set(e.edges.map((a) => a.id));
1752
+ for (const a of e.appearance.states ?? [])
1753
+ for (const i of a.ids) {
1754
+ const g = e.stateLines.get(`${a.id}:${i}`);
1755
+ o(
1756
+ t.has(i) || l.has(i),
1757
+ `Unknown node, group or edge ${i} in state ${a.id}.`,
1758
+ g
1759
+ );
1760
+ }
1761
+ const p = new Map(e.layouts.filter((a) => a.algorithm === "cells").map((a) => [a.scope, a]));
1762
+ for (const a of e.objects) {
1763
+ const i = p.get(a.parent);
1764
+ i ? (o(
1765
+ a.type === "node",
1766
+ `Cells are nodes; ${a.id} is a group inside cells ${a.parent}.`,
1767
+ a.line
1768
+ ), o(
1769
+ a.shape !== "marker" || (i.columns ?? 0) <= 1 && !i.unit,
1770
+ i.unit ? `A marker cuts a sequence of cells; ${a.parent} is a ${i.unit} layout.` : `A marker cuts one row or column of cells; ${a.parent} has ${i.columns} columns.`,
1771
+ a.line
1772
+ ), o(
1773
+ a.span !== "var" || !!i.unit,
1774
+ `span=var is for a byte or bit layout; give ${a.parent} unit=byte or unit=bit.`,
1775
+ a.line
1776
+ )) : (o(
1777
+ a.shape !== "marker",
1778
+ `A marker sits between cells; put ${a.id} in a group with layout cells.`,
1779
+ a.line
1780
+ ), o(a.span === void 0, `span= is for cells; ${a.parent} has no layout cells.`, a.line));
1781
+ }
1782
+ for (const a of e.layouts) {
1783
+ d(a.scope, a.line), s(a.scope, a.line, "layout");
1784
+ const i = a.engine?.params.rootId;
1785
+ i && (r(i, a.line), o(t.get(i).type === "node", `The tree root ${i} must be a node.`, a.line));
1786
+ }
1787
+ for (const a of e.hints)
1788
+ if (a.type === "order") {
1789
+ d(a.scope, a.line), s(a.scope, a.line, "layout");
1790
+ for (const i of a.ids)
1791
+ r(i, a.line), s(i, a.line, "position"), o(n(i) === a.scope, `${i} is not a direct child of ${a.scope}.`, a.line);
1792
+ } else if (a.type === "align") {
1793
+ a.ids.forEach((g) => r(g, a.line)), a.ids.forEach((g) => s(g, a.line, "position")), o(new Set(a.ids).size === a.ids.length, "Duplicate member in align.", a.line);
1794
+ const i = n(a.ids[0]);
1795
+ o(
1796
+ a.ids.every((g) => n(g) === i),
1797
+ "Members of align must be direct siblings.",
1798
+ a.line
1799
+ );
1800
+ } else
1801
+ r(a.id, a.line), s(a.id, a.line, "position"), a.type === "near" && (r(a.ref, a.line), s(a.ref, a.line, "position"), o(
1802
+ Vt(t, a.id, a.ref) !== void 0,
1803
+ `Relative placement is between siblings, or with something inside a sibling group. ${a.id} is inside ${n(a.id)}; place ${n(a.id)} relative to ${a.ref} instead.`,
1804
+ a.line
1805
+ )), a.type === "size" && o(
1806
+ t.get(a.id).type === "node",
1807
+ "Use layout min-width/min-height to reserve room in a group.",
1808
+ a.line
1809
+ );
1810
+ }
1811
+ const $t = { width: 1100, height: 720 }, ft = 12, ei = 56, Dn = 24, Nn = 0, ti = 56, Fn = { w: 260, h: 110 }, Pn = (e, t) => Math.max(t.x - e.x - e.w, e.x - t.x - t.w, t.y - e.y - e.h, e.y - t.y - t.h), re = (e) => Math.round(e);
1812
+ function ni(e) {
1813
+ if (!e.appearance.compare || !e.edges.some((n) => n.was)) return e;
1814
+ const t = pt(e.appearance), s = (n) => n ? Je(n, t).w : 0;
1815
+ return {
1816
+ ...e,
1817
+ edges: e.edges.map((n) => n.was && s(n.was) > s(n.label) ? { ...n, label: n.was } : n)
1818
+ };
1819
+ }
1820
+ function oi(e, t) {
1821
+ if (e.model.edges === t.edges) return e;
1822
+ const s = new Map(t.edges.map((n) => [n.id, n.label]));
1823
+ return {
1824
+ ...e,
1825
+ model: { ...e.model, edges: t.edges },
1826
+ edges: e.edges.map((n) => ({ ...n, label: s.get(n.id) }))
1827
+ };
1828
+ }
1829
+ function si(e) {
1830
+ const t = Zs(e), s = hi(t);
1831
+ return fi(
1832
+ mo(mi(oi(tn(ni(s)), s), t))
1833
+ );
1834
+ }
1835
+ const ii = 24, ai = 0, Cn = 36, ri = 40, ci = 16, jn = 8, $e = 16, tt = 20, Bn = 8, li = 104;
1836
+ function di(e, t) {
1837
+ const s = Math.ceil(ye(e.label, t.title));
1838
+ if (e.label.includes(`
1839
+ `) || Ot(e.shape, e.w, e.h, t).width < s) return e.w;
1840
+ let n = li;
1841
+ for (; n < e.w && Ot(e.shape, n, e.h, t).width < s; ) n += 4;
1842
+ return Math.min(n, e.w);
1843
+ }
1844
+ function mo(e) {
1845
+ if (!e.model.layouts.some((I) => I.scope === "root" && I.algorithm === "sequence"))
1846
+ return e;
1847
+ const t = e.look, s = new Set(e.model.hints.flatMap((I) => I.type === "size" ? [I.id] : [])), n = e.objects.filter((I) => I.type === "node"), o = e.objects.filter((I) => I.type === "group");
1848
+ if (!n.length) return e;
1849
+ const r = (I, O) => {
1850
+ const C = e.model.hints.find((oe) => oe.type === "order" && oe.scope === I), V = C?.type === "order" ? C.ids : [];
1851
+ return [...V, ...O.filter((oe) => !V.includes(oe))];
1852
+ }, d = [...new Set(n.map((I) => I.parent === "root" ? I.id : I.parent))], c = r("root", d).flatMap(
1853
+ (I) => e.byId.get(I).type === "node" ? [I] : r(
1854
+ I,
1855
+ n.filter((O) => O.parent === I).map((O) => O.id)
1856
+ )
1857
+ ).map((I) => e.byId.get(I)).map((I) => s.has(I.id) ? I : { ...I, w: di(I, t) }), y = new Map(c.map((I, O) => [I.id, O])), w = e.model.phases.length ? Math.max(...e.model.phases.map((I) => ye(I.label, t.annotation))) + 2 * $e : 0, l = o.length ? t.groupHeader : 0, p = (I) => c[I - 1].parent !== c[I].parent, a = !!e.model.appearance.compare, i = (I) => [I.label, a ? I.was : ""].filter((O) => !!O), g = (I) => {
1858
+ const O = i(I).map((C) => Je(C, t, !0));
1859
+ return { w: Math.max(0, ...O.map((C) => C.w)), h: Math.max(0, ...O.map((C) => C.h)) };
1860
+ }, f = (I) => {
1861
+ const O = i(I).map((C) => Mn(C, t));
1862
+ return O.length ? {
1863
+ right: Math.max(...O.map((C) => C.right)),
1864
+ above: Math.max(...O.map((C) => C.above)),
1865
+ below: Math.max(...O.map((C) => C.below))
1866
+ } : Mn(void 0, t);
1867
+ }, M = /* @__PURE__ */ new Map(), k = c.map(() => []);
1868
+ for (const I of e.edges) {
1869
+ const [O, C] = [y.get(I.source), y.get(I.target)].sort((oe, ae) => oe - ae);
1870
+ if (O < C) {
1871
+ const { w: oe } = g(I);
1872
+ oe && k[C].push({ from: O, room: oe + ci });
1873
+ continue;
1874
+ }
1875
+ const { right: V } = f(I);
1876
+ M.set(I.source, Math.max(M.get(I.source) ?? 0, V)), O + 1 < c.length && k[O + 1].push({
1877
+ from: O,
1878
+ room: V + jn + (p(O + 1) ? 2 * $e + c[O + 1].w / 2 : 0)
1879
+ });
1880
+ }
1881
+ const S = [];
1882
+ c.forEach((I, O) => {
1883
+ if (!O) return void S.push(w + $e + I.w / 2);
1884
+ const C = c[O - 1].w / 2 + ri + (p(O) ? 2 * $e : 0) + I.w / 2;
1885
+ S.push(Math.max(S[O - 1] + C, ...k[O].map((V) => S[V.from] + V.room)));
1886
+ });
1887
+ let D = l + Math.max(0, ...c.map((I) => I.h)) - ai, _ = 0;
1888
+ const $ = /* @__PURE__ */ new Map(), x = /* @__PURE__ */ new Map();
1889
+ for (const I of e.edges) {
1890
+ const O = g(I).h, C = I.source === I.target ? f(I) : void 0, V = C ? C.above : O && O + 1;
1891
+ D = Math.ceil(
1892
+ Math.max(D + Math.max(Cn, O ? O + 8 : 0), _ + jn + V)
1893
+ ), $.set(I.id, D), _ = C ? D + C.below : 0, x.set(I.id, { from: D - Math.max(O, Cn / 2) - 4, to: Math.max(D, _) + 8 }), C && (D += We.down);
1894
+ }
1895
+ const E = Math.max(D, _) + ii, v = new Map(
1896
+ c.map((I) => {
1897
+ const O = re(S[y.get(I.id)] - I.w / 2);
1898
+ return [I.id, { x: O, w: I.w }];
1899
+ })
1900
+ ), u = (I) => Math.max(v.get(I.id).x + I.w, S[y.get(I.id)] + (M.get(I.id) ?? 0)), A = e.objects.map((I) => {
1901
+ if (I.type === "group") {
1902
+ const V = c.filter((le) => le.parent === I.id), oe = re(Math.min(...V.map((le) => v.get(le.id).x)) - $e), ae = re(Math.max(...V.map((le) => u(le))) + $e - oe);
1903
+ return {
1904
+ ...I,
1905
+ x: oe,
1906
+ y: 0,
1907
+ w: ae,
1908
+ h: E + $e,
1909
+ localX: oe,
1910
+ localY: 0,
1911
+ baseX: oe,
1912
+ baseY: 0
1913
+ };
1914
+ }
1915
+ const { x: O, w: C } = v.get(I.id);
1916
+ return {
1917
+ ...I,
1918
+ w: C,
1919
+ x: O,
1920
+ y: l,
1921
+ localX: O,
1922
+ localY: l,
1923
+ baseX: O,
1924
+ baseY: l,
1925
+ lifeline: E - l - I.h
1926
+ };
1927
+ }), m = Math.min(0, ...A.map((I) => I.x)) - (w ? 0 : $e), b = Math.max(
1928
+ ...A.map((I) => I.x + I.w + $e),
1929
+ ...c.map((I) => S[y.get(I.id)] + (M.get(I.id) ?? 0))
1930
+ ), T = {
1931
+ x: m - tt,
1932
+ y: -tt,
1933
+ w: b - m + 2 * tt,
1934
+ h: E + $e + 2 * tt
1935
+ }, F = e.model.appearance.notes ?? [], X = new Map([...$].filter(([I]) => !e.byId.has(I))), B = gs(t, F, X, {
1936
+ left: m - (w ? tt : Bn),
1937
+ right: b + Bn,
1938
+ top: 0
1939
+ }), G = B.filter((I) => I !== null), P = G.length ? wn([T, wn(G, tt)]) : T, R = P.x < T.x ? T.x : void 0, N = e.model.phases.map((I) => {
1940
+ const O = I.ids.map((C) => x.get(C));
1941
+ return {
1942
+ id: I.id,
1943
+ label: I.label,
1944
+ from: re(Math.min(...O.map((C) => C.from))),
1945
+ to: re(Math.max(...O.map((C) => C.to)))
1946
+ };
1947
+ }).sort((I, O) => I.from - O.from), U = N.map(({ id: I, label: O, from: C, to: V }, oe) => ({
1948
+ id: I,
1949
+ label: O,
1950
+ y: C,
1951
+ h: Math.min(V, N[oe + 1]?.from ?? V) - C
1952
+ }));
1953
+ return {
1954
+ ...e,
1955
+ objects: A,
1956
+ byId: new Map(A.map((I) => [I.id, I])),
1957
+ edges: e.edges.map((I) => ({ ...I, lane: void 0, row: $.get(I.id) })),
1958
+ sequence: {
1959
+ panel: P,
1960
+ phases: U,
1961
+ ...R !== void 0 ? { phaseX: R } : {},
1962
+ ...G.length ? { notes: B, inner: T } : {}
1963
+ }
1964
+ };
1965
+ }
1966
+ function fi(e) {
1967
+ const t = e.model.wasOrder?.ids.flatMap((r) => e.edges.filter((d) => d.id === r));
1968
+ if (!t || !e.sequence) return e;
1969
+ const s = [...t], n = mo({
1970
+ ...e,
1971
+ edges: e.edges.map((r) => t.includes(r) ? s.shift() : r)
1972
+ }), o = (r) => r.objects.find((d) => d.type === "node")?.lifeline ?? 0;
1973
+ return {
1974
+ ...e,
1975
+ sequence: {
1976
+ ...e.sequence,
1977
+ before: {
1978
+ rows: Object.fromEntries(n.edges.map((r) => [r.id, r.row])),
1979
+ phases: n.sequence.phases,
1980
+ grow: Math.max(0, o(n) - o(e))
1981
+ }
1982
+ }
1983
+ };
1984
+ }
1985
+ function hi(e) {
1986
+ if (!e.objects.some((n) => n.frame)) return e;
1987
+ const t = new Map(e.objects.map((n) => [n.id, n])), s = (n) => {
1988
+ const o = [];
1989
+ for (let r = t.get(n).parent; r !== "root" && t.get(r).frame; r = t.get(r).parent)
1990
+ o.unshift(r);
1991
+ return o;
1992
+ };
1993
+ return {
1994
+ ...e,
1995
+ objects: e.objects.filter((n) => !n.frame).map((n) => ({ ...n, parent: st(t, n.id), soft: s(n.id) }))
1996
+ };
1997
+ }
1998
+ function an(e, t, s = 0) {
1999
+ if (!e.some((o) => t(o)?.[s])) return e;
2000
+ const n = /* @__PURE__ */ new Map();
2001
+ return e.forEach((o, r) => {
2002
+ const d = t(o)?.[s] ?? `\0${o}`, h = n.get(d) ?? { at: 0, ids: [] };
2003
+ h.at += r, h.ids.push(o), n.set(d, h);
2004
+ }), [...n].sort(([, o], [, r]) => o.at / o.ids.length - r.at / r.ids.length).flatMap(([o, r]) => o.startsWith("\0") ? r.ids : an(r.ids, t, s + 1));
2005
+ }
2006
+ const pi = 8;
2007
+ function Dt(e = [], t = [], s) {
2008
+ const n = e.filter((r) => !t.includes(r)).length, o = t.filter((r) => !e.includes(r)).length;
2009
+ return !n && !o ? 0 : (n + o) * dt + (s && o ? Rt : 0) + pi;
2010
+ }
2011
+ function wo(e, t, s, n) {
2012
+ const o = new Set(e.flatMap((c) => s(c) ?? [])), r = (c, y) => (s(c) ?? []).filter((w) => !y.has(w)), d = new Set(t.flatMap((c) => s(c) ?? []));
2013
+ let h = 0;
2014
+ for (const c of e)
2015
+ for (const y of t) h = Math.max(h, Dt(r(c, d), r(y, o), n));
2016
+ return h;
2017
+ }
2018
+ const kt = (e, t) => e.x < t.x + t.w && e.x + e.w > t.x && e.y < t.y + t.h && e.y + e.h > t.y, ui = (e, t) => ({
2019
+ x: e.x - t,
2020
+ y: e.y - t,
2021
+ w: e.w + 2 * t,
2022
+ h: e.h + 2 * t
2023
+ });
2024
+ function gi(e, t) {
2025
+ const s = Math.max(e.x, t.x), n = Math.min(e.x + e.w, t.x + t.w), o = Math.max(e.y, t.y), r = Math.min(e.y + e.h, t.y + t.h);
2026
+ if (n > s) {
2027
+ const c = Math.min(e.y + e.h, t.y + t.h);
2028
+ return { x: s, y: c, w: n - s, h: Math.max(e.y, t.y) - c };
2029
+ }
2030
+ if (r > o) {
2031
+ const c = Math.min(e.x + e.w, t.x + t.w);
2032
+ return { x: c, y: o, w: Math.max(e.x, t.x) - c, h: r - o };
2033
+ }
2034
+ const d = Math.min(e.x, t.x), h = Math.min(e.y, t.y);
2035
+ return { x: d, y: h, w: Math.max(e.x + e.w, t.x + t.w) - d, h: Math.max(e.y + e.h, t.y + t.h) - h };
2036
+ }
2037
+ function mi(e, t) {
2038
+ const s = t.objects.filter((l) => l.frame);
2039
+ if (!s.length) return e;
2040
+ const n = new Map(t.objects.map((l) => [l.id, l])), o = new Map(
2041
+ e.objects.map((l) => [l.id, { ...l, parent: n.get(l.id).parent, soft: void 0 }])
2042
+ ), r = [...e.diagnostics], d = (l, p) => {
2043
+ for (let a = n.get(l)?.parent; a && a !== "root"; a = n.get(a)?.parent)
2044
+ if (a === p) return !0;
2045
+ return !1;
2046
+ }, h = (l) => {
2047
+ let p = 0;
2048
+ for (let a = n.get(l).parent; a !== "root"; a = n.get(a).parent) p++;
2049
+ return p;
2050
+ }, c = (l) => l.frame === "soft" ? (l.hull ?? []).map((p) => ({ ...p, x: p.x + l.x, y: p.y + l.y })) : l.frame ? [] : [l];
2051
+ for (const l of [...s].sort((p, a) => h(a.id) - h(p.id))) {
2052
+ const p = [...o.values()].filter((v) => d(v.id, l.id)), a = o.get(st(n, l.id)), i = a ? so(a, _t(e.look, a.titleLines)) : { x: 0, y: 0 }, g = [...o.values()].filter(
2053
+ (v) => !v.frame && !d(v.id, l.id) && !d(l.id, v.id)
2054
+ ), f = p.flatMap((v) => c(v).map((u) => ui(u, dt)));
2055
+ let M = [], k = 0;
2056
+ if (f.length) {
2057
+ const v = f.reduce((B, G) => G.y < B.y || G.y === B.y && G.x < B.x ? G : B);
2058
+ v.y -= Rt, v.h += Rt, M = [v, ...f.filter((B) => B !== v)];
2059
+ const u = Math.min(...M.map((B) => B.x)), A = Math.min(...M.map((B) => B.y)), m = {
2060
+ x: u,
2061
+ y: A,
2062
+ w: Math.max(...M.map((B) => B.x + B.w)) - u,
2063
+ h: Math.max(...M.map((B) => B.y + B.h)) - A
2064
+ };
2065
+ g.some((B) => kt(B, m)) || (M = [m]);
2066
+ const b = (B, G) => Math.max(G.x - (B.x + B.w), B.x - (G.x + G.w), G.y - (B.y + B.h), B.y - (G.y + G.h), 0), T = [M[0]], F = M.slice(1), X = [];
2067
+ for (; F.length; ) {
2068
+ let B = { gap: 1 / 0, a: M[0], i: 0 };
2069
+ for (const R of T)
2070
+ F.forEach((N, U) => {
2071
+ const I = b(R, N);
2072
+ I < B.gap && (B = { gap: I, a: R, i: U });
2073
+ });
2074
+ const [G] = F.splice(B.i, 1);
2075
+ if (T.push(G), kt(B.a, G)) continue;
2076
+ const P = gi(B.a, G);
2077
+ g.some((R) => kt(R, P)) ? k++ : X.push(P);
2078
+ }
2079
+ M.push(...X);
2080
+ }
2081
+ const S = M.length ? Math.min(...M.map((v) => v.x)) : i.x, D = M.length ? Math.min(...M.map((v) => v.y)) : i.y, _ = M.length ? Math.max(...M.map((v) => v.x + v.w)) : i.x, $ = M.length ? Math.max(...M.map((v) => v.y + v.h)) : i.y, x = { x: S - i.x, y: D - i.y };
2082
+ if (o.set(l.id, {
2083
+ ...l,
2084
+ x: S,
2085
+ y: D,
2086
+ w: _ - S,
2087
+ h: $ - D,
2088
+ localX: x.x,
2089
+ localY: x.y,
2090
+ baseX: x.x,
2091
+ baseY: x.y,
2092
+ depth: h(l.id),
2093
+ hull: M.map((v) => ({ x: v.x - S, y: v.y - D, w: v.w, h: v.h }))
2094
+ }), l.frame !== "soft") continue;
2095
+ const E = g.filter((v) => M.some((u) => kt(v, u)));
2096
+ E.length && r.push({
2097
+ level: "warning",
2098
+ code: "soft-overlap",
2099
+ message: `${l.id}'s tint covers ${E.map((v) => v.id).join(", ")}, which ${E.length > 1 ? "are" : "is"} not in it. Place its members together, or use frame=box.`,
2100
+ line: l.line,
2101
+ ids: [l.id, ...E.map((v) => v.id)]
2102
+ }), k && r.push({
2103
+ level: "info",
2104
+ code: "soft-split",
2105
+ message: `${l.id}'s members are apart, so its tint is drawn in ${k + 1} pieces. Place its members together, or use frame=box.`,
2106
+ line: l.line,
2107
+ ids: [l.id]
2108
+ });
2109
+ }
2110
+ const y = new Map(t.objects.map((l, p) => [l.id, p])), w = [...o.values()].sort((l, p) => y.get(l.id) - y.get(p.id));
2111
+ return { ...e, model: t, objects: w, byId: new Map(w.map((l) => [l.id, l])), diagnostics: r };
2112
+ }
2113
+ const zn = 4, wi = /* @__PURE__ */ new Set(["slate", "stone"]);
2114
+ function yi(e) {
2115
+ const t = [], s = e.objects.filter((d) => d.color !== "auto"), n = [...new Set(s.map((d) => d.color))].filter((d) => !wi.has(d));
2116
+ n.length > zn && t.push({
2117
+ level: "info",
2118
+ code: "many-colors",
2119
+ message: `${n.length} accent colors (${n.join(", ")}). Use two to four, each for one role, with slate or stone for the rest, and say what each one means with legend lines.`,
2120
+ line: s.find((d) => d.color === n[zn])?.line,
2121
+ ids: s.filter((d) => n.includes(d.color)).map((d) => d.id)
2122
+ });
2123
+ const o = new Map(e.objects.map((d) => [d.id, d])), r = s.filter((d) => o.get(d.parent)?.color === d.color);
2124
+ return r.length && t.push({
2125
+ level: "info",
2126
+ code: "color-matches-container",
2127
+ message: `${r.map((d) => d.id).join(", ")} ${r.length > 1 ? "repeat their containers’ colors" : "repeats its container’s color"}. Drop the color to inherit it, or give the member a family of its own.`,
2128
+ line: r[0].line,
2129
+ ids: r.map((d) => d.id)
2130
+ }), t;
2131
+ }
2132
+ function nt(e) {
2133
+ return e.direction !== "auto" ? e.direction : "right";
2134
+ }
2135
+ function Mi(e, t) {
2136
+ const s = new Map(e.objects.map((n) => [n.id, n.parent]));
2137
+ for (let n = t; n; n = n === "root" ? void 0 : s.get(n)) {
2138
+ const o = e.layouts.find((r) => r.scope === n);
2139
+ if (o) return n === t || o.engine ? o : void 0;
2140
+ }
2141
+ }
2142
+ const xi = 240, bi = 1.25;
2143
+ function vi(e, t, s) {
2144
+ const n = Math.ceil(ye(e, s.groupTitle)) + Xt;
2145
+ let o = Math.max(t, xi);
2146
+ if (n <= o * bi) return { w: n, lines: 1 };
2147
+ const r = () => it(e, o - Xt, s.groupTitle, !0).length;
2148
+ for (; r() > yn && o < n; ) o += 8;
2149
+ return { w: Math.min(o, n), lines: Math.min(r(), yn) };
2150
+ }
2151
+ const Un = 16, ki = 1.5, Fe = 14;
2152
+ function Bt(e, t, s, n) {
2153
+ const o = Je(s, n);
2154
+ return { a: e, b: t, w: o.w + 2 * Fe, h: o.h + 2 * Fe };
2155
+ }
2156
+ function Jt(e, t, s, n, o) {
2157
+ let r = n;
2158
+ for (const d of e)
2159
+ (d.a === t && d.b === s || d.a === s && d.b === t) && (r = Math.max(r, o ? d.w : d.h));
2160
+ return r;
2161
+ }
2162
+ function zt(e, t) {
2163
+ return e.layouts.find((s) => s.scope === t) ?? {
2164
+ scope: t,
2165
+ algorithm: t === "root" ? "flow" : "column",
2166
+ direction: "auto",
2167
+ fold: "auto",
2168
+ gap: t === "root" ? 48 : 24,
2169
+ minWidth: 0,
2170
+ minHeight: 0,
2171
+ line: 0
2172
+ };
2173
+ }
2174
+ const qn = 2;
2175
+ function Ei(e, t, s) {
2176
+ const n = e.label.includes(`
2177
+ `) && e.shape !== "circle" ? e.label.split(`
2178
+ `) : [], o = (y) => y ? s.detail : s.title, r = e.label.split(`
2179
+ `)[0], d = e.label.slice(r.length + 1), h = Math.max(
2180
+ qt(r, s.title),
2181
+ d ? qt(d, s.detail) : 0,
2182
+ ...n.map((y, w) => ye(y, o(w)))
2183
+ );
2184
+ let c = t.w;
2185
+ for (; Ot(e.shape, c, t.h, s).width < h && c < t.w * qn; ) c += 4;
2186
+ return Math.min(c, t.w * qn);
2187
+ }
2188
+ function Et(e, t, s) {
2189
+ const n = io(e.shape);
2190
+ if (e.shape === "diamond") return Ai(e, t, n, s);
2191
+ const o = t?.width ?? Ei(e, n, s), r = Ot(e.shape, o, t?.height ?? n.h, s), d = gt(ut(e.label, r.width, s), s);
2192
+ return t?.height !== void 0 ? { w: o, h: t.height, overflow: d > r.maxHeight + 0.5 } : {
2193
+ w: o,
2194
+ h: Math.max(
2195
+ Ko(e.shape, d, e.shape === "circle" ? n.h : 0, s),
2196
+ t?.minHeight ?? 0
2197
+ ),
2198
+ overflow: !1
2199
+ };
2200
+ }
2201
+ function Ai(e, t, s, n) {
2202
+ const o = qt(e.label, n.title), r = (h) => (Zo(e.label, h, n) ?? 0) >= o;
2203
+ if (t) {
2204
+ const h = Math.max(t.width, t.height ?? t.minHeight ?? 0);
2205
+ return { w: h, h, overflow: !r(h) };
2206
+ }
2207
+ let d = s.w;
2208
+ for (; !r(d); ) d += 4;
2209
+ return { w: d, h: d, overflow: !1 };
2210
+ }
2211
+ const Si = 1.4;
2212
+ function ht(e, t) {
2213
+ const s = new Map(e.map((p) => [p, []]));
2214
+ for (const [p, a] of t)
2215
+ p !== a && s.has(p) && s.has(a) && !s.get(p).includes(a) && s.get(p).push(a);
2216
+ const n = new Set([...s.values()].flat()), o = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Set(), d = (p) => {
2217
+ o.set(p, "open");
2218
+ for (const a of s.get(p))
2219
+ o.get(a) === "open" ? r.add(p + "\0" + a) : o.has(a) || d(a);
2220
+ o.set(p, "done");
2221
+ };
2222
+ for (const p of [...e.filter((a) => !n.has(a)), ...e]) o.has(p) || d(p);
2223
+ const h = new Map(e.map((p) => [p, 0])), c = new Map(e.map((p) => [p, 0])), y = (p) => s.get(p).filter((a) => !r.has(p + "\0" + a));
2224
+ for (const p of e) for (const a of y(p)) h.set(a, h.get(a) + 1);
2225
+ const w = e.filter((p) => !h.get(p));
2226
+ for (; w.length; ) {
2227
+ const p = w.shift();
2228
+ for (const a of y(p))
2229
+ c.set(a, Math.max(c.get(a), c.get(p) + 1)), h.set(a, h.get(a) - 1), h.get(a) || w.push(a);
2230
+ }
2231
+ const l = [];
2232
+ for (const p of e) (l[c.get(p)] ||= []).push(p);
2233
+ return l.filter(Boolean);
2234
+ }
2235
+ const yo = 3, Gn = 5, Hn = 1.25, Qe = 20, _i = 3, Ii = 2, Ti = 1;
2236
+ function Li(e, t) {
2237
+ const s = new Map(e.map((h) => [h, []]));
2238
+ for (const [h, c] of t) s.get(h)?.push(c);
2239
+ const n = (h) => {
2240
+ const c = /* @__PURE__ */ new Set([h]), y = [h];
2241
+ for (; y.length; )
2242
+ for (const w of s.get(y.shift()) ?? [])
2243
+ c.has(w) || (c.add(w), y.push(w));
2244
+ return c;
2245
+ }, o = new Map(e.map((h) => [h, n(h)])), r = [], d = /* @__PURE__ */ new Set();
2246
+ for (const h of e) {
2247
+ if (d.has(h)) continue;
2248
+ const c = e.filter((y) => o.get(h).has(y) && o.get(y).has(h));
2249
+ c.forEach((y) => d.add(y)), c.length > 1 && r.push(c);
2250
+ }
2251
+ return r;
2252
+ }
2253
+ function Ut(e, t, s, n, o, r = [], d = /* @__PURE__ */ new Set(), h = t, {
2254
+ aspect: c = yo,
2255
+ fewest: y = 4,
2256
+ room: w = s === "right" ? $t.width : $t.height
2257
+ } = {}) {
2258
+ const l = new Map(e.map((P) => [P.id, P])), p = s === "right" ? "x" : "y", a = s === "right" ? "y" : "x", i = (P, R) => R === "x" ? P.w : P.h, g = (P) => {
2259
+ const R = [...e].sort((U, I) => P.get(U.id)[p] - P.get(I.id)[p]), N = [];
2260
+ for (const U of R) {
2261
+ const I = P.get(U.id)[p], O = I + i(U, p), C = N[N.length - 1];
2262
+ C && I < C.end ? (C.end = Math.max(C.end, O), C.ids.push(U.id)) : N.push({ start: I, end: O, ids: [U.id] });
2263
+ }
2264
+ return N;
2265
+ }, f = g(t);
2266
+ let M = g(h);
2267
+ const k = (P) => P.map((R) => [...R.ids].sort().join(",")).join("|");
2268
+ k(M) !== k(f) && (h = t, M = f);
2269
+ const S = (P, R) => {
2270
+ const N = Math.min(...e.map((I) => P.get(I.id)[R]));
2271
+ return Math.max(...e.map((I) => P.get(I.id)[R] + i(I, R))) - N;
2272
+ }, D = (P, R, N = 1) => P <= w * N || P <= c * R * N, _ = (P) => D(S(P, p), S(P, a)), $ = (P) => _(P) || S(P, p) <= w * Hn;
2273
+ if (e.length < y || _(h) && $(t)) return { positions: t };
2274
+ const x = new Map(f.flatMap((P, R) => P.ids.map((N) => [N, R]))), E = (P, R, N) => {
2275
+ const [U, I] = [x.get(R), x.get(N)];
2276
+ return U !== void 0 && I !== void 0 && Math.min(U, I) < P && Math.max(U, I) >= P;
2277
+ }, v = (P) => o.filter(([R, N]) => E(P, R, N)).length, u = Li(
2278
+ e.map((P) => P.id),
2279
+ o
2280
+ ), A = (P) => _i * [...d].filter((R) => o.some((N) => N[0] === R && E(P, ...N))).length + Ii * u.filter((R) => R.some((N) => E(P, R[0], N))).length, m = (P, R) => {
2281
+ const N = (R ? r : []).filter((U) => E(P, U.a, U.b)).map((U) => (s === "right" ? U.h : U.w) - 2 * Fe);
2282
+ return Math.max(
2283
+ n + 40,
2284
+ 84,
2285
+ N.length ? Math.max(...N) + 2 * Fe : 0,
2286
+ (v(P) + 1) * Qe + N.reduce((U, I) => U + I, 0)
2287
+ );
2288
+ }, b = (P, R) => {
2289
+ const N = R[R.length - 1].end - R[0].start, U = [], I = new Map(R.flatMap((O) => O.ids.map((C) => [C, O.start])));
2290
+ for (let O = 1; O < P; O++) {
2291
+ const C = (te) => o.filter((Me) => E(te, ...Me)).reduce((Me, [L, j]) => {
2292
+ const [q, W] = x.get(L) < x.get(j) ? [L, j] : [j, L];
2293
+ return Me + Math.abs(I.get(q) - ae - (I.get(W) - R[te].start));
2294
+ }, 0) / (N / P), V = R[0].start + N * O / P, oe = (te) => v(te) + A(te) + C(te) * Ti + Math.abs(R[te].start - V) / (N / P) * 2, ae = R[U.at(-1) ?? 0].start, le = N / P, he = (te, Me, L) => R[te - 1].end - ae >= le * L && R[te - 1].end - ae <= le * (1 + Me) && R[R.length - 1].end - R[te].start <= le * (P - O) * (1 + Me), we = (te) => !A(te) && he(te, 0.25, 0.5) ? 0 : !A(te) && he(te, 0.5, 0) ? 1 : he(te, 0.25, 0.5) ? 2 : 3;
2295
+ let fe = 0;
2296
+ for (let te = (U.at(-1) ?? 0) + 1; te < R.length; te++)
2297
+ (!fe || we(te) < we(fe) || we(te) === we(fe) && oe(te) < oe(fe)) && (fe = te);
2298
+ fe && U.push(fe);
2299
+ }
2300
+ return U;
2301
+ }, T = new Set(
2302
+ f.flatMap(
2303
+ (P) => P.ids.length > 1 ? P.ids.filter((R) => !o.some(([N, U]) => N === R && U !== R)) : []
2304
+ )
2305
+ ), F = (P, R) => {
2306
+ const N = [];
2307
+ return R.forEach((U, I) => I === 0 || P.includes(I) ? N.push([U]) : N.at(-1).push(U)), N;
2308
+ }, X = (P, R) => {
2309
+ const N = F(P, R), U = new Map(N.flatMap((C, V) => C.flatMap((oe) => oe.ids.map((ae) => [ae, V])))), I = new Map(R.flatMap((C) => C.ids.map((V) => [V, C.start]))), O = /* @__PURE__ */ new Map();
2310
+ for (const [C, V] of N.entries()) {
2311
+ if (!C) continue;
2312
+ const oe = [];
2313
+ for (const ae of V[0].ids) {
2314
+ if (d.has(ae)) continue;
2315
+ const le = o.filter(([L, j]) => j === ae && L !== ae).map(([L]) => L), he = o.filter(([L, j]) => L === ae && j !== ae).map(([, L]) => L);
2316
+ if (!le.length || le.some((L) => U.get(L) !== C - 1)) continue;
2317
+ const we = (L, j) => I.get(L) - N[j][0].start, fe = (L) => le.reduce((j, q) => j + Math.abs(we(q, C - 1) - we(ae, L)), 0) + he.reduce((j, q) => j + Math.abs(we(ae, L) - we(q, U.get(q))), 0), te = (L) => (L === C - 1 ? 0 : le.length) + he.filter((j) => U.get(j) !== L).length;
2318
+ if (te(C - 1) > te(C) || fe(C - 1) >= fe(C)) continue;
2319
+ const Me = le.reduce((L, j) => I.get(j) > I.get(L) ? j : L);
2320
+ oe.push({ id: ae, source: Me, saves: fe(C) - fe(C - 1) });
2321
+ }
2322
+ oe.sort((ae, le) => le.saves - ae.saves);
2323
+ for (const ae of oe.slice(0, V[0].ids.length - 1)) O.set(ae.id, ae.source);
2324
+ }
2325
+ return O;
2326
+ }, B = (P, R, N, U, I = /* @__PURE__ */ new Map()) => {
2327
+ const O = F(P, R);
2328
+ if (I.size) {
2329
+ N = new Map(N);
2330
+ const he = [];
2331
+ for (const [we, fe] of I) {
2332
+ const te = l.get(we);
2333
+ let L = N.get(fe)[a] + (i(l.get(fe), a) - i(te, a)) / 2;
2334
+ for (const j of he) L < j.hi + n && L + i(te, a) > j.lo && (L = j.hi + n);
2335
+ he.push({ lo: L, hi: L + i(te, a) }), N.set(we, { ...N.get(we), [a]: L });
2336
+ }
2337
+ }
2338
+ const C = /* @__PURE__ */ new Map(), V = [];
2339
+ let oe = 0, ae = 0, le = 0;
2340
+ for (const [he, we] of O.entries()) {
2341
+ const fe = O[he + 1]?.[0].ids ?? [], te = [
2342
+ ...we.flatMap((Y) => Y.ids).filter((Y) => !I.has(Y)),
2343
+ ...fe.filter((Y) => I.has(Y))
2344
+ ], Me = Math.min(...te.map((Y) => N.get(Y)[p])), L = Math.min(...te.map((Y) => N.get(Y)[a])), j = Math.max(...te.map((Y) => N.get(Y)[a] + i(l.get(Y), a)));
2345
+ for (const Y of te) {
2346
+ const H = N.get(Y), J = H[p] - Me, se = H[a] - L + oe;
2347
+ C.set(Y, s === "right" ? { x: J, y: se } : { x: se, y: J });
2348
+ }
2349
+ const q = he < P.length ? m(P[he], U) : 0, W = te.filter((Y) => !T.has(Y)), ee = W.length ? W : te;
2350
+ oe += j - L + q, le += Math.max(...ee.map((Y) => N.get(Y)[a] + i(l.get(Y), a))) - Math.min(...ee.map((Y) => N.get(Y)[a])) + q, ae = Math.max(
2351
+ ae,
2352
+ Math.max(...te.map((Y) => N.get(Y)[p] + i(l.get(Y), p))) - Me
2353
+ ), V.push(te);
2354
+ }
2355
+ return {
2356
+ out: C,
2357
+ length: ae,
2358
+ // The depth that decides the count leaves side leaves out.
2359
+ depth: le,
2360
+ count: O.length,
2361
+ bands: V
2362
+ };
2363
+ };
2364
+ let G = 0;
2365
+ if (!_(h))
2366
+ for (let P = 2; P <= f.length && !G; P++) {
2367
+ const R = B(b(P, M), M, h, !1);
2368
+ R.count === P && D(R.length, R.depth) && (G = P);
2369
+ }
2370
+ for (let P = Math.max(2, G); P <= f.length; P++) {
2371
+ const R = b(P, M), N = B(R, f, t, !0), U = P === G ? Hn : 1;
2372
+ if (N.count !== P || !D(N.length, N.depth, U)) continue;
2373
+ const I = X(R, M), O = I.size ? B(R, f, t, !0, I) : void 0, C = O && D(O.length, O.depth, U) ? O : N;
2374
+ return { positions: C.out, fold: { bands: C.bands, axis: s } };
2375
+ }
2376
+ return { positions: t };
2377
+ }
2378
+ function Ri(e, t, s, n, o) {
2379
+ const r = /* @__PURE__ */ new Map();
2380
+ for (const { scope: d, fold: h } of e) {
2381
+ const c = h.axis === "right", y = (S) => c ? S.y : S.x, w = (S) => c ? S.y + S.h : S.x + S.w, l = (S) => c ? S.x : S.y, p = (S) => c ? S.x + S.w : S.y + S.h, a = (S) => (l(S) + p(S)) / 2, i = (S) => (y(S) + w(S)) / 2, g = (S, D) => l(S) < p(D) && p(S) > l(D), f = new Map(h.bands.flatMap((S, D) => S.map((_) => [_, D]))), M = (S) => f.get(n(S.id, d) ?? ""), k = (S) => [...s.values()].filter((D) => D.type !== "group" && M(D) === S);
2382
+ for (let S = 0; S + 1 < h.bands.length; S++) {
2383
+ const D = h.bands[S].map((G) => s.get(G)), _ = h.bands[S + 1].map((G) => s.get(G)), $ = Math.max(...D.map(w)), x = Math.min(..._.map(y)), E = Math.max(...D.map(p)) + Qe, v = Math.min(..._.map(l)) - Qe, [u, A] = [k(S), k(S + 1)], m = t.flatMap((G) => {
2384
+ const P = s.get(G.source), R = s.get(G.target);
2385
+ if (M(P) !== S || M(R) !== S + 1) return [];
2386
+ if (G.from !== "auto" || G.to !== "auto") return [];
2387
+ const N = u.some((O) => y(O) > y(P) && g(O, P)), U = n(G.target, d) !== G.target || A.some((O) => y(O) < y(R) && g(O, R)), I = (O, C) => y(O) < w(C) && w(O) > y(C);
2388
+ return N && u.some((O) => I(O, P) && l(O) >= p(P)) ? [] : U && A.some((O) => I(O, R) && p(O) <= l(R)) ? [] : [{ id: G.id, source: P, target: R, leave: N, enter: U }];
2389
+ }), b = /* @__PURE__ */ new Map(), T = /* @__PURE__ */ new Map();
2390
+ for (const G of m)
2391
+ G.leave || T.set(G.source.id, [...T.get(G.source.id) ?? [], G]);
2392
+ for (const G of T.values()) {
2393
+ const P = (R) => Math.abs(a(R.target) - a(R.source)) + Math.abs(i(R.target) - i(R.source));
2394
+ G.sort((R, N) => P(R) - P(N) || (R.id < N.id ? -1 : 1)), G.forEach((R, N) => {
2395
+ const U = a(R.target) < a(R.source) ? -1 : 1, I = Math.ceil(N / 2) * o * (N % 2 ? U : -U);
2396
+ b.set(R.id, a(R.source) + I);
2397
+ });
2398
+ }
2399
+ if (!m.length || x - $ < (m.length + 1) * Qe) continue;
2400
+ const F = (G) => {
2401
+ const P = G.filter((N) => N.leave), R = G.filter((N) => N.enter);
2402
+ return G.map((N, U) => ({
2403
+ w: N,
2404
+ at: re($ + (x - $) * (U + 1) / (G.length + 1)),
2405
+ leave: N.leave ? re(E + Qe * P.indexOf(N)) : void 0,
2406
+ enter: N.enter ? re(v - Qe * (R.length - 1 - R.indexOf(N))) : void 0
2407
+ }));
2408
+ }, X = (G) => F(G).map(({ w: P, at: R, leave: N, enter: U }) => [
2409
+ ...N !== void 0 ? [
2410
+ { u: p(P.source), v: i(P.source) },
2411
+ { u: N, v: i(P.source) },
2412
+ { u: N, v: R }
2413
+ ] : [
2414
+ { u: b.get(P.id), v: $ },
2415
+ { u: b.get(P.id), v: R }
2416
+ ],
2417
+ ...U !== void 0 ? [
2418
+ { u: U, v: R },
2419
+ { u: U, v: i(P.target) },
2420
+ { u: l(P.target), v: i(P.target) }
2421
+ ] : [
2422
+ { u: a(P.target), v: R },
2423
+ { u: a(P.target), v: x }
2424
+ ]
2425
+ ]), B = $i(
2426
+ [...m].sort((G, P) => a(P.source) - a(G.source)),
2427
+ (G) => Oi(X(G))
2428
+ );
2429
+ for (const { w: G, at: P, leave: R, enter: N } of F(B))
2430
+ r.set(G.id, {
2431
+ ...c ? { y: P } : { x: P },
2432
+ ...R !== void 0 ? { leave: R } : {},
2433
+ ...N !== void 0 ? { enter: N } : {}
2434
+ });
2435
+ }
2436
+ }
2437
+ return r;
2438
+ }
2439
+ function Oi(e) {
2440
+ const t = e.map((n) => n.slice(1).map((o, r) => [n[r], o]));
2441
+ let s = 0;
2442
+ for (let n = 0; n < t.length; n++)
2443
+ for (let o = n + 1; o < t.length; o++)
2444
+ for (const [r, d] of t[n])
2445
+ for (const [h, c] of t[o]) {
2446
+ const [y, w] = r.v === d.v && h.u === c.u ? [
2447
+ [r, d],
2448
+ [h, c]
2449
+ ] : h.v === c.v && r.u === d.u ? [
2450
+ [h, c],
2451
+ [r, d]
2452
+ ] : [];
2453
+ if (!y || !w) continue;
2454
+ const l = w[0].u, p = y[0].v;
2455
+ l > Math.min(y[0].u, y[1].u) && l < Math.max(y[0].u, y[1].u) && p > Math.min(w[0].v, w[1].v) && p < Math.max(w[0].v, w[1].v) && s++;
2456
+ }
2457
+ return s;
2458
+ }
2459
+ function $i(e, t) {
2460
+ if (e.length > 6) return e;
2461
+ let s = e, n = t(e);
2462
+ const o = (r, d) => {
2463
+ if (n) {
2464
+ if (!d.length) {
2465
+ const h = t(r);
2466
+ h < n && ([s, n] = [r, h]);
2467
+ return;
2468
+ }
2469
+ d.forEach((h, c) => o([...r, h], [...d.slice(0, c), ...d.slice(c + 1)]));
2470
+ }
2471
+ };
2472
+ return o([], e), s;
2473
+ }
2474
+ const Ge = 4;
2475
+ function Di(e, t, s) {
2476
+ const n = t === "right" ? "x" : "y", o = t === "right" ? "y" : "x", r = (c, y) => y === "x" ? c.w : c.h, d = [], h = /* @__PURE__ */ new Set();
2477
+ for (const c of s) {
2478
+ let [y, w] = [e.get(c.a), e.get(c.b)];
2479
+ if (!y || !w) continue;
2480
+ w[n] < y[n] && ([y, w] = [w, y]);
2481
+ const l = y[n] + r(y, n), p = w[n];
2482
+ if (p <= l) continue;
2483
+ const a = (t === "right" ? c.w : c.h) - 2 * Fe, i = (t === "right" ? c.h : c.w) - 2 * Fe, g = l - a / 2 - Ge, f = p + a / 2 + Ge, M = y[o] + r(y, o) / 2, k = w[o] + r(w, o) / 2, S = Math.min(M, k) + Ge, D = Math.max(M, k) - Ge;
2484
+ if (D - S < i) continue;
2485
+ const _ = [
2486
+ ...[...e.values()].filter((v) => v[n] < f && v[n] + r(v, n) > g).map((v) => ({
2487
+ lo: v[o] - Ge,
2488
+ hi: v[o] + r(v, o) + Ge
2489
+ })),
2490
+ ...d.filter((v) => v.from < f && v.to > g)
2491
+ ], $ = (v) => _.every((u) => v + i <= u.lo || v >= u.hi), x = (S + D - i) / 2, E = [S, x, ..._.map((v) => v.hi)].filter((v) => v >= S && v + i <= D && $(v)).sort((v, u) => Math.abs(v - x) - Math.abs(u - x))[0];
2492
+ E !== void 0 && (h.add(c), d.push({ lo: E - Ge, hi: E + i + Ge, from: g, to: f }));
2493
+ }
2494
+ return h;
2495
+ }
2496
+ const Ni = 96, Fi = 1.25;
2497
+ function Pi(e, t, s, n, o) {
2498
+ const r = new Map(e.flatMap((w, l) => w.map((p) => [p, l]))), d = (w) => !t.some(([l, p]) => l === w && p !== w), h = (w) => [
2499
+ ...new Set(t.filter(([l, p]) => p === w && l !== w).map((l) => l[0]))
2500
+ ], c = /* @__PURE__ */ new Set(), y = Math.max(...e.map(o));
2501
+ for (const [w, l] of e.entries())
2502
+ if (w)
2503
+ for (const p of l) {
2504
+ const a = h(p);
2505
+ if (!s(p) || !d(p) || !a.length || a.some((M) => r.get(M) !== w - 1)) continue;
2506
+ const i = [...new Set(t.filter(([M]) => a.includes(M)).map((M) => M[1]))].filter(
2507
+ (M) => M !== p && r.get(M) === w
2508
+ ), g = [p, ...i].filter(d).sort((M, k) => n(k) - n(M))[0], f = [...e[w - 1], ...l.filter((M) => c.has(M)), p];
2509
+ o(f) > Fi * y || (i.some((M) => !d(M)) || g !== p) && c.add(p);
2510
+ }
2511
+ return c.size ? e.map((w, l) => [
2512
+ ...w.filter((p) => !c.has(p)),
2513
+ ...(e[l + 1] ?? []).filter((p) => c.has(p))
2514
+ ]).filter((w) => w.length) : e;
2515
+ }
2516
+ function Ci(e, t, s, n, o, r, d = !1, h = [], c = /* @__PURE__ */ new Map(), y = /* @__PURE__ */ new Map(), w = () => {
2517
+ }) {
2518
+ const l = new Map(e.map((R) => [R.id, R])), p = e.map((R) => R.id), a = s === "right", i = (R) => a ? l.get(R).w : l.get(R).h, g = (R) => a ? l.get(R).h : l.get(R).w, f = (R) => l.get(R).type === "group", M = (R) => a ? R.y + R.h / 2 : R.x + R.w / 2, k = new Set(n.flat()), S = (R) => {
2519
+ const N = !k.size || k.has(R) ? [] : (c.get(R) ?? []).flatMap((I) => t.get(I) ?? []);
2520
+ if (N.length) return N.reduce((I, O) => I + M(O), 0) / N.length;
2521
+ const U = t.get(R);
2522
+ return a ? U.y + l.get(R).h / 2 : U.x + l.get(R).w / 2;
2523
+ }, D = (R, N) => Math.max(
2524
+ Jt(o, R, N, f(R) || f(N) ? r.group : r.node, !a),
2525
+ Dt(l.get(R).soft, l.get(N).soft, a)
2526
+ ), _ = (R) => R.reduce((N, U, I) => N + g(U) + (I ? D(R[I - 1], U) : 0), 0), $ = Pi(
2527
+ ht(p, n),
2528
+ n,
2529
+ d ? f : () => !1,
2530
+ i,
2531
+ _
2532
+ ).map(
2533
+ (R) => an(
2534
+ [...R].sort((N, U) => S(N) - S(U) || p.indexOf(N) - p.indexOf(U)),
2535
+ (N) => l.get(N).soft
2536
+ )
2537
+ ), x = new Map($.flatMap((R, N) => R.map((U) => [U, N]))), E = $.map(_), v = Math.max(...E), u = new Map(p.map((R) => [R, /* @__PURE__ */ new Set()])), A = new Map(p.map((R) => [R, /* @__PURE__ */ new Set()]));
2538
+ for (const [R, N] of n)
2539
+ x.get(N) > x.get(R) && (u.get(R).add(N), A.get(N).add(R));
2540
+ const m = /* @__PURE__ */ new Map(), b = /* @__PURE__ */ new Map();
2541
+ for (const [R, N] of $.entries()) {
2542
+ let U = (v - E[R]) / 2, I = -1 / 0;
2543
+ for (const [O, C] of N.entries()) {
2544
+ const [V] = A.get(C), oe = A.get(C).size === 1 && u.get(V).size === 1, ae = oe ? w(V, C) : void 0, le = ae !== void 0 ? m.get(V) + ae : oe ? b.get(V) - g(C) / 2 : U, he = O ? Math.max(le, I + D(N[O - 1], C)) : le;
2545
+ m.set(C, he), b.set(C, he + g(C) / 2), I = he + g(C), U = Math.max(U + g(C), I) + (N[O + 1] ? D(C, N[O + 1]) : 0);
2546
+ }
2547
+ }
2548
+ const T = $.length === 1 && F($[0]);
2549
+ function F(R) {
2550
+ const N = R.map((C) => y.get(C));
2551
+ if (R.length < 2 || N.some((C, V) => C === void 0 || V && C < N[V - 1]))
2552
+ return !1;
2553
+ const U = [];
2554
+ let I = -1 / 0;
2555
+ for (const [C, V] of R.entries()) {
2556
+ const oe = N[C] - N[0] + g(R[0]) / 2 - g(V) / 2;
2557
+ U.push(C ? Math.max(oe, I + D(R[C - 1], V)) : oe), I = U[C] + g(V);
2558
+ }
2559
+ const O = N.at(-1) - N[0] + (g(R[0]) + g(R.at(-1))) / 2;
2560
+ return I - U[0] > Math.max(E[0] * 1.25, O + 1) ? !1 : (R.forEach((C, V) => m.set(C, U[V])), !0);
2561
+ }
2562
+ const X = Math.min(...m.values()), B = en($, h, o, s), G = /* @__PURE__ */ new Map();
2563
+ let P = 0;
2564
+ for (const [R, N] of $.entries()) {
2565
+ for (const O of N) {
2566
+ const C = re(m.get(O) - X);
2567
+ G.set(O, a ? { x: P, y: C } : { x: C, y: P });
2568
+ }
2569
+ const U = $[R + 1];
2570
+ if (!U) break;
2571
+ let I = Math.max(
2572
+ N.some(f) || U.some(f) ? r.group : r.rank,
2573
+ B[R],
2574
+ wo(N, U, (O) => l.get(O).soft, !a)
2575
+ );
2576
+ for (const O of o)
2577
+ Math.min(x.get(O.a), x.get(O.b)) === R && Math.abs(x.get(O.a) - x.get(O.b)) === 1 && (I = Math.max(I, a ? O.w : O.h));
2578
+ P += Math.max(...N.map(i)) + I;
2579
+ }
2580
+ return { positions: G, axis: s, followed: T };
2581
+ }
2582
+ const Nt = 20;
2583
+ function en(e, t, s, n) {
2584
+ const o = new Map(e.flatMap((h, c) => h.map((y) => [y, c]))), r = (h) => n === "right" ? 2 * Fe : h.h, d = 2 * Fe;
2585
+ return e.slice(0, -1).map((h, c) => {
2586
+ let y = 0, w = 0;
2587
+ const l = [...s], p = [], a = [];
2588
+ for (const g of t) {
2589
+ const f = g.a !== void 0 ? o.get(g.a) : void 0, M = g.b !== void 0 ? o.get(g.b) : void 0;
2590
+ let k;
2591
+ if (f !== void 0 && M !== void 0) {
2592
+ const S = Math.min(f, M), D = Math.max(f, M);
2593
+ if (k = S <= c && D > c && (S === c || D === c + 1), !k) continue;
2594
+ const _ = l.findIndex(
2595
+ ($) => $.a === g.a && $.b === g.b || $.a === g.b && $.b === g.a
2596
+ );
2597
+ _ >= 0 && (w += r(l.splice(_, 1)[0]) - d, S === c && D === c + 1 && a.push(g));
2598
+ } else {
2599
+ if (k = f !== void 0 ? f === c : M === c + 1, !k) continue;
2600
+ g.label && s.length && (w += r(g.label) - (n === "right" ? d : 0));
2601
+ }
2602
+ y++, p.push(g);
2603
+ }
2604
+ return a.some(
2605
+ (g) => p.some((f) => !(f.a && f.b) && [f.a, f.b].some((M) => M && (M === g.a || M === g.b)))
2606
+ ) ? 2 * Nt + (y - 1) * Qe + w : 0;
2607
+ });
2608
+ }
2609
+ function ji(e, t, s, n, o) {
2610
+ const r = /* @__PURE__ */ new Map(), d = /* @__PURE__ */ new Map();
2611
+ for (const [w, l] of t) {
2612
+ const p = s.get(w), a = s.get(l);
2613
+ if (p === void 0 || a === void 0 || p === a) continue;
2614
+ const [i, g] = p < a ? [w, l] : [l, w];
2615
+ r.set(g, [...r.get(g) ?? [], i]), d.set(i, [...d.get(i) ?? [], g]);
2616
+ }
2617
+ const h = (w) => n.get(w) + o(w) / 2, c = (w, l) => {
2618
+ if (!w.some((M) => l.get(M)?.length)) return;
2619
+ const p = [];
2620
+ for (const [M, k] of w.entries())
2621
+ p.push(M ? p[M - 1] + n.get(k) - n.get(w[M - 1]) : 0);
2622
+ const a = w.map((M, k) => {
2623
+ const S = (l.get(M) ?? []).map(h).sort((_, $) => _ - $);
2624
+ return (S.length ? S[S.length - 1 >> 1] : h(M)) - o(M) / 2 - p[k];
2625
+ }), i = [], g = (M) => M[M.length >> 1];
2626
+ for (const M of a)
2627
+ for (i.push([M]); i.length > 1 && g(i.at(-2)) > g(i.at(-1)); ) {
2628
+ const k = i.pop();
2629
+ i.push([...i.pop(), ...k].sort((S, D) => S - D));
2630
+ }
2631
+ let f = 0;
2632
+ for (const M of i)
2633
+ for (let k = 0; k < M.length; k++, f++) n.set(w[f], re(g(M) + p[f]));
2634
+ };
2635
+ for (const w of e.slice(1)) c(w, r);
2636
+ for (const w of [...e].reverse().slice(1)) c(w, d);
2637
+ for (const w of e.slice(1)) c(w, r);
2638
+ const y = Math.min(...n.values());
2639
+ for (const [w, l] of n) n.set(w, l - y);
2640
+ }
2641
+ const Mo = 16;
2642
+ function Bi(e, t, s, n) {
2643
+ const o = Array.from({ length: e }, () => []);
2644
+ for (const [r, d] of t) {
2645
+ const h = s.get(r), c = s.get(d);
2646
+ if (h === void 0 || c === void 0 || h === c) continue;
2647
+ const y = Math.min(n(r), n(d)), w = Math.max(n(r), n(d));
2648
+ w - y < 1 || (o[Math.min(h, c)].push([y, w]), Math.abs(h - c) > 1 && o[Math.max(h, c) - 1].push([y, w]));
2649
+ }
2650
+ return o.map((r) => {
2651
+ const d = r.flatMap(([y, w]) => [
2652
+ [y, 1],
2653
+ [w, -1]
2654
+ ]);
2655
+ d.sort((y, w) => y[0] - w[0] || y[1] - w[1]);
2656
+ let h = 0, c = 0;
2657
+ for (const [, y] of d) c = Math.max(c, h += y);
2658
+ return c > 1 ? 2 * Nt + (c - 1) * Mo : 0;
2659
+ });
2660
+ }
2661
+ function zi(e, t, s, n = [], o = [], r) {
2662
+ const d = /* @__PURE__ */ new Map(), h = t.gap, c = nt(t);
2663
+ let y;
2664
+ const w = new Map(e.map((l) => [l.id, l]));
2665
+ if (t.algorithm === "row" || t.algorithm === "column") {
2666
+ const l = t.algorithm === "row", p = en(
2667
+ e.map((i) => [i.id]),
2668
+ o,
2669
+ n,
2670
+ l ? "right" : "down"
2671
+ );
2672
+ let a = 0;
2673
+ for (const [i, g] of e.entries()) {
2674
+ const f = e[i + 1]?.id ?? "";
2675
+ d.set(g.id, l ? { x: a, y: 0 } : { x: 0, y: a }), a += (l ? g.w : g.h) + Math.max(
2676
+ Jt(n, g.id, f, h, l),
2677
+ p[i] ?? 0,
2678
+ Dt(g.soft, e[i + 1]?.soft, !l)
2679
+ );
2680
+ }
2681
+ } else {
2682
+ const l = e.map((v) => v.id), p = (v) => w.get(v).soft, a = s.length ? qi(ht(l, s), s, (v) => an(v, p)) : null, i = a ? a.layers : l.map((v) => [v]), g = !!a && a.chains.size >= Gi && a.crossings <= 2 * a.chains.size && !e.some((v) => v.soft?.length), f = g ? a.order : i, M = g ? s.flatMap(([v, u], A) => {
2683
+ const m = [v, ...a.chains.get(A) ?? [], u];
2684
+ return m.slice(1).map((b, T) => [m[T], b]);
2685
+ }) : s, k = (v) => je(v) ? 0 : c === "right" ? w.get(v).w : w.get(v).h, S = (v) => je(v) ? 0 : c === "right" ? w.get(v).h : w.get(v).w, D = new Map(f.flatMap((v, u) => v.map((A) => [A, u]))), _ = en(i, o, n, c), $ = /* @__PURE__ */ new Map();
2686
+ for (const v of f) {
2687
+ let u = 0, A;
2688
+ for (const [m, b] of v.entries()) {
2689
+ const T = v[m - 1];
2690
+ T !== void 0 && je(T) ? u += je(b) ? Mo : Nt : T !== void 0 && je(b) && (u += Nt), !je(b) && A !== void 0 && (u = Math.max(
2691
+ u,
2692
+ $.get(A) + S(A) + Math.max(
2693
+ Jt(n, A, b, h, c !== "right"),
2694
+ Dt(p(A), p(b), c === "right")
2695
+ )
2696
+ )), $.set(b, u), u += S(b), je(b) || (A = b);
2697
+ }
2698
+ }
2699
+ s.length && ji(f, M, D, $, S);
2700
+ const x = Bi(f.length, M, D, (v) => $.get(v) + S(v) / 2);
2701
+ g && _s(
2702
+ c,
2703
+ f,
2704
+ s.flatMap(
2705
+ ([u, A], m) => D.get(u) < D.get(A) ? [{ id: String(m), chain: [u, ...a.chains.get(m) ?? [], A] }] : []
2706
+ ),
2707
+ (u) => je(u) ? void 0 : c === "right" ? { x: 0, y: $.get(u), w: k(u), h: S(u) } : { x: $.get(u), y: 0, w: S(u), h: k(u) },
2708
+ (u) => $.get(u),
2709
+ r
2710
+ ).forEach((u, A) => x[A] = Math.max(x[A] ?? 0, u));
2711
+ let E = 0;
2712
+ for (const [v, u] of i.entries()) {
2713
+ let A = Math.max(h, _[v] ?? 0, x[v] ?? 0);
2714
+ for (const m of u) {
2715
+ const b = $.get(m);
2716
+ d.set(m, c === "right" ? { x: E, y: b } : { x: b, y: E });
2717
+ }
2718
+ i[v + 1] && (A = Math.max(A, wo(u, i[v + 1], p, c === "down")));
2719
+ for (const m of n)
2720
+ Math.min(D.get(m.a), D.get(m.b)) === v && Math.abs(D.get(m.a) - D.get(m.b)) === 1 && (A = Math.max(A, c === "right" ? m.w : m.h));
2721
+ E += Math.max(...u.map(k)) + A;
2722
+ }
2723
+ g && (y = {
2724
+ order: f,
2725
+ chains: a.chains,
2726
+ across: new Map(f.flat().flatMap((v) => je(v) ? [[v, $.get(v)]] : []))
2727
+ });
2728
+ }
2729
+ return { positions: d, axis: c, corridors: y };
2730
+ }
2731
+ function xo(e, t, s = (n) => n) {
2732
+ const n = [s(e[0])];
2733
+ for (let o = 1; o < e.length; o++) {
2734
+ const r = new Map(n[o - 1].map((l, p) => [l, p])), h = e[o].map((l, p) => {
2735
+ const a = t.flatMap(([i, g]) => i === l ? [g] : g === l ? [i] : []).filter((i) => r.has(i)).map((i) => r.get(i));
2736
+ return {
2737
+ id: l,
2738
+ key: a.length ? a.reduce((i, g) => i + g, 0) / a.length : null,
2739
+ k: p
2740
+ };
2741
+ }).filter((l) => l.key !== null), c = [...h].sort((l, p) => l.key - p.key || l.k - p.k), y = h.map((l) => l.k), w = [...e[o]];
2742
+ c.forEach((l, p) => w[y[p]] = l.id), n.push(s(w));
2743
+ }
2744
+ return n;
2745
+ }
2746
+ const Ui = 8;
2747
+ function qi(e, t, s = (n) => n) {
2748
+ const n = xo(e, t, s), o = new Map(n.flatMap((_, $) => _.map((x) => [x, $]))), r = n.map((_) => [..._]), d = /* @__PURE__ */ new Map(), h = /* @__PURE__ */ new Map(), c = (_, $) => {
2749
+ h.set(_, [...h.get(_) ?? [], $]), d.set($, [...d.get($) ?? [], _]);
2750
+ }, y = new Set(o.keys()), w = /* @__PURE__ */ new Map();
2751
+ for (const [_, [$, x]] of t.entries()) {
2752
+ const E = o.get($), v = o.get(x);
2753
+ if (E === void 0 || v === void 0 || E >= v) continue;
2754
+ let u = $;
2755
+ w.set(_, []);
2756
+ for (let A = E + 1; A < v; A++) {
2757
+ const m = `\0${_}:${A}`;
2758
+ w.get(_).push(m);
2759
+ const b = r[A].indexOf(u);
2760
+ r[A].splice(b < 0 ? r[A].length : b + 1, 0, m), c(u, m), u = m;
2761
+ }
2762
+ c(u, x);
2763
+ }
2764
+ if (r.length < 2) return { layers: n, order: n, chains: w, crossings: 0 };
2765
+ const l = (_) => s(_.filter(($) => y.has($))), p = (_) => {
2766
+ const $ = l(_);
2767
+ let x = 0;
2768
+ return _.map((E) => y.has(E) ? $[x++] : E);
2769
+ }, a = (_) => {
2770
+ const $ = new Map(r[_ + 1].map((v, u) => [v, u])), x = r[_].flatMap(
2771
+ (v) => (h.get(v) ?? []).map((u) => $.get(u)).sort((u, A) => u - A)
2772
+ );
2773
+ let E = 0;
2774
+ for (let v = 0; v < x.length; v++)
2775
+ for (let u = v + 1; u < x.length; u++) x[v] > x[u] && E++;
2776
+ return E;
2777
+ }, i = () => r.slice(1).reduce((_, $, x) => _ + a(x), 0), g = (_, $, x, E) => {
2778
+ let v = 0;
2779
+ for (const u of x.get(_) ?? [])
2780
+ for (const A of x.get($) ?? []) E.get(u) > E.get(A) && v++;
2781
+ return v;
2782
+ }, f = (_) => new Map((r[_] ?? []).map(($, x) => [$, x])), M = (_) => {
2783
+ const $ = r[_], x = f(_ - 1), E = f(_ + 1), v = (u, A) => g(u, A, d, x) + g(u, A, h, E);
2784
+ for (let u = !0, A = 0; u && A < $.length; A++) {
2785
+ u = !1;
2786
+ for (let m = 0; m + 1 < $.length; m++) {
2787
+ const b = $[m], T = $[m + 1];
2788
+ if (!(v(T, b) >= v(b, T))) {
2789
+ if ([$[m], $[m + 1]] = [T, b], l($).join(`
2790
+ `) !== $.filter((F) => y.has(F)).join(`
2791
+ `)) {
2792
+ [$[m], $[m + 1]] = [b, T];
2793
+ continue;
2794
+ }
2795
+ u = !0;
2796
+ }
2797
+ }
2798
+ }
2799
+ }, k = (_, $, x) => {
2800
+ const v = r[_].map((m, b) => {
2801
+ const T = ($.get(m) ?? []).map((F) => x.get(F));
2802
+ return { id: m, k: b, key: T.length ? T.reduce((F, X) => F + X, 0) / T.length : null };
2803
+ }).filter((m) => m.key !== null), u = v.map((m) => m.k), A = [...r[_]];
2804
+ [...v].sort((m, b) => m.key - b.key || m.k - b.k).forEach((m, b) => A[u[b]] = m.id), r[_] = p(A);
2805
+ };
2806
+ let S = r.map((_) => [..._]), D = i();
2807
+ for (let _ = 0, $ = 0; _ < Ui && D && $ < 2; _++) {
2808
+ const x = _ % 2 === 0, E = x ? r.map((u, A) => A).slice(1) : r.map((u, A) => A).reverse().slice(1);
2809
+ for (const u of E)
2810
+ k(u, x ? d : h, f(x ? u - 1 : u + 1)), M(u);
2811
+ const v = i();
2812
+ v < D ? [S, D, $] = [r.map((u) => [...u]), v, 0] : $++;
2813
+ }
2814
+ return {
2815
+ layers: S.map((_) => _.filter(($) => y.has($))),
2816
+ order: S,
2817
+ chains: w,
2818
+ crossings: D
2819
+ };
2820
+ }
2821
+ const Gi = 40, je = (e) => e.charCodeAt(0) === 0;
2822
+ class Yn {
2823
+ parent;
2824
+ constructor(t) {
2825
+ this.parent = new Map(t.map((s) => [s, s]));
2826
+ }
2827
+ find(t) {
2828
+ let s = t;
2829
+ for (; this.parent.get(s) !== s; ) s = this.parent.get(s);
2830
+ return s;
2831
+ }
2832
+ join(t, s) {
2833
+ t = this.find(t), s = this.find(s), t !== s && this.parent.set(s, t);
2834
+ }
2835
+ }
2836
+ function Hi(e, t, s, n) {
2837
+ const o = s.filter((l) => l.type === "stay");
2838
+ if (!o.length) return [];
2839
+ const r = new Map(o.map((l) => [l.id, { x: l.x, y: l.y }])), d = /* @__PURE__ */ new Set(), h = n === "right" ? "x" : "y", c = n === "right" ? "y" : "x", y = (l, p) => p === "x" ? l.w : l.h, w = (l, p, a, i, g) => Math.min(p[g] + y(l, g), i[g] + y(a, g)) - Math.max(p[g], i[g]);
2840
+ for (let l = 0; l < e.length; l++)
2841
+ for (let p = l + 1; p < e.length; p++) {
2842
+ const a = e[l], i = e[p], g = r.get(a.id), f = r.get(i.id), M = t.get(a.id), k = t.get(i.id);
2843
+ !g || !f || !M || !k || w(a, M, i, k, h) > 0 || w(a, g, i, f, c) > 0 && w(a, g, i, f, h) >= Math.min(y(a, h), y(i, h)) / 2 && (d.add(a.id), d.add(i.id));
2844
+ }
2845
+ return o.filter((l) => d.has(l.id));
2846
+ }
2847
+ function Yi(e, t, s, n, o, r) {
2848
+ const d = e.map((u) => u.id), h = new Map(e.map((u) => [u.id, u])), c = new Map(e.map((u) => [u.id, { ...t.get(u.id) }])), y = new Map(d.map((u) => [u, 1])), w = s.filter(
2849
+ (u) => "ids" in u ? u.type === "align" && u.ids.every((A) => h.has(A)) : "id" in u && h.has(u.id)
2850
+ ), l = /* @__PURE__ */ new Map(), p = Hi(e, t, w, r);
2851
+ p.length && o.push({
2852
+ level: "info",
2853
+ code: "stale-stay",
2854
+ message: `The stays on ${p.map((u) => u.id).join(", ")} no longer fit ${n}'s arrangement, so they were ignored. Drag again to anchor the new layout.`,
2855
+ line: p[0].line,
2856
+ ids: p.map((u) => u.id)
2857
+ });
2858
+ for (const u of w)
2859
+ u.type === "stay" && !p.includes(u) && (c.set(u.id, { x: u.x, y: u.y }), y.set(u.id, u.weight), l.set(u.id, { pos: { x: u.x, y: u.y }, hint: u }));
2860
+ for (const u of w)
2861
+ if (u.type === "nudge") {
2862
+ const A = t.get(u.id), m = { x: A.x + u.dx, y: A.y + u.dy };
2863
+ c.set(u.id, m), y.set(u.id, 4), l.set(u.id, { pos: m, hint: u });
2864
+ }
2865
+ const a = new Map(
2866
+ w.flatMap((u) => u.type === "near" && h.has(u.ref) ? [[u.id, u]] : [])
2867
+ ), i = /* @__PURE__ */ new Set(), g = /* @__PURE__ */ new Set(), f = (u) => {
2868
+ const A = a.get(u);
2869
+ if (i.has(u) || !A) return;
2870
+ if (g.has(u))
2871
+ throw new Le(
2872
+ `Relative placement cycle in ${n}. Replace one near with nudge.`,
2873
+ A.line
2874
+ );
2875
+ g.add(u), f(A.ref);
2876
+ const m = h.get(u), b = h.get(A.ref), T = c.get(A.ref);
2877
+ let F = T.x + (b.w - m.w) / 2, X = T.y + (b.h - m.h) / 2;
2878
+ A.side === "right" || A.side === "left" ? (F = A.side === "right" ? T.x + b.w + A.gap : T.x - m.w - A.gap, X += A.offset) : (X = A.side === "below" ? T.y + b.h + A.gap : T.y - m.h - A.gap, F += A.offset), c.set(u, { x: F, y: X }), y.set(u, 5), l.set(u, { pos: { x: F, y: X }, hint: A }), g.delete(u), i.add(u);
2879
+ };
2880
+ d.forEach(f);
2881
+ for (const u of w)
2882
+ if (u.type === "align" && u.strength === "prefer") {
2883
+ const A = h.get(u.ids[0]), m = c.get(A.id), b = (F) => u.axis === "x" ? F.w : F.h, T = m[u.axis] + b(A) / 2;
2884
+ for (const F of u.ids.slice(1)) c.get(F)[u.axis] = T - b(h.get(F)) / 2;
2885
+ }
2886
+ const M = new Map(w.flatMap((u) => u.type === "pin" ? [[u.id, u]] : []));
2887
+ for (const [u, A] of M) c.set(u, { x: A.x, y: A.y });
2888
+ const k = (u, A) => (u === "x" ? h.get(A).w : h.get(A).h) / 2, S = { x: new Yn(d), y: new Yn(d) };
2889
+ for (const u of w)
2890
+ if (u.type === "align" && u.strength === "required")
2891
+ for (const A of u.ids.slice(1)) {
2892
+ const m = /* @__PURE__ */ new Set([S[u.axis].find(u.ids[0]), S[u.axis].find(A)]), b = d.filter((T) => M.has(T) && m.has(S[u.axis].find(T))).map((T) => c.get(T)[u.axis] + k(u.axis, T));
2893
+ b.length > 1 && Math.max(...b) - Math.min(...b) > 0.01 ? o.push({
2894
+ level: "error",
2895
+ code: "pin-align-conflict",
2896
+ message: `Pins conflict with required ${u.axis} alignment in ${n}. The pins were kept.`,
2897
+ line: u.line,
2898
+ ids: u.ids
2899
+ }) : S[u.axis].join(u.ids[0], A);
2900
+ }
2901
+ const D = { x: /* @__PURE__ */ new Map(), y: /* @__PURE__ */ new Map() };
2902
+ for (const u of ["x", "y"])
2903
+ for (const A of d) {
2904
+ const m = S[u].find(A), b = c.get(A)[u] + k(u, A);
2905
+ D[u].has(m) || D[u].set(m, { sum: 0, weight: 0, value: 0, fixed: null, members: [] });
2906
+ const T = D[u].get(m);
2907
+ T.sum += b * y.get(A), T.weight += y.get(A), T.members.push(A), M.has(A) && (T.fixed = b);
2908
+ }
2909
+ for (const u of ["x", "y"])
2910
+ for (const A of D[u].values()) A.value = A.fixed ?? A.sum / A.weight;
2911
+ const _ = (u, A) => D[u].get(S[u].find(A)), $ = (u, A) => _(u, A).value, x = (u, A, m, b) => {
2912
+ const T = _(u, A), F = _(u, m), X = b - (T.value - F.value);
2913
+ if (X <= 5e-3 || T === F || T.fixed !== null && F.fixed !== null) return 0;
2914
+ if (T.fixed !== null) F.value -= X;
2915
+ else if (F.fixed !== null) T.value += X;
2916
+ else {
2917
+ const B = T.weight + F.weight;
2918
+ T.value += X * F.weight / B, F.value -= X * T.weight / B;
2919
+ }
2920
+ return X;
2921
+ }, E = w.flatMap(
2922
+ (u) => u.type === "near" && u.strength === "required" && h.has(u.ref) ? [u] : []
2923
+ ), v = r === "right" ? "x" : "y";
2924
+ for (let u = 0; u < 48; u++) {
2925
+ let A = 0;
2926
+ for (const m of E) {
2927
+ const b = m.side === "right" || m.side === "left" ? "x" : "y", T = m.side === "right" || m.side === "below";
2928
+ A += x(
2929
+ b,
2930
+ T ? m.id : m.ref,
2931
+ T ? m.ref : m.id,
2932
+ k(b, m.id) + k(b, m.ref) + m.gap
2933
+ );
2934
+ }
2935
+ for (let m = 0; m < e.length; m++)
2936
+ for (let b = m + 1; b < e.length; b++) {
2937
+ const T = e[m], F = e[b], X = $("x", F.id) - $("x", T.id), B = $("y", F.id) - $("y", T.id), G = (T.w + F.w) / 2 + ft - Math.abs(X), P = (T.h + F.h) / 2 + ft - Math.abs(B);
2938
+ if (G <= 5e-3 || P <= 5e-3) continue;
2939
+ const R = ["x", "y"].filter(
2940
+ (O) => _(O, T.id) !== _(O, F.id) && !(_(O, T.id).fixed !== null && _(O, F.id).fixed !== null)
2941
+ );
2942
+ if (!R.length) continue;
2943
+ const N = (O) => (O === "x" ? G : P) + (O === v ? 0 : 3), U = [...R].sort((O, C) => N(O) - N(C))[0], I = U === "x" ? X : B;
2944
+ A += x(
2945
+ U,
2946
+ I >= 0 ? F.id : T.id,
2947
+ I >= 0 ? T.id : F.id,
2948
+ (U === "x" ? T.w + F.w : T.h + F.h) / 2 + ft
2949
+ );
2950
+ }
2951
+ if (n !== "root")
2952
+ for (const m of ["x", "y"])
2953
+ for (const b of D[m].values()) {
2954
+ const T = Math.max(...b.members.map((F) => k(m, F)));
2955
+ b.value < T && b.fixed === null && (A += T - b.value, b.value = T);
2956
+ }
2957
+ if (A < 0.01) break;
2958
+ }
2959
+ for (const u of e)
2960
+ c.set(u.id, {
2961
+ x: re($("x", u.id) - u.w / 2),
2962
+ y: re($("y", u.id) - u.h / 2)
2963
+ });
2964
+ for (let u = 0; u < e.length; u++)
2965
+ for (let A = u + 1; A < e.length; A++) {
2966
+ const m = e[u], b = e[A], T = c.get(m.id), F = c.get(b.id);
2967
+ T.x + m.w > F.x + 0.1 && F.x + b.w > T.x + 0.1 && T.y + m.h > F.y + 0.1 && F.y + b.h > T.y + 0.1 && o.push({
2968
+ level: "error",
2969
+ code: "overlap",
2970
+ message: `${m.id} overlaps ${b.id}. Release a pin or give ${n} more room.`,
2971
+ ids: [m.id, b.id]
2972
+ });
2973
+ }
2974
+ for (const u of E) {
2975
+ const A = h.get(u.id), m = h.get(u.ref), b = c.get(A.id), T = c.get(m.id);
2976
+ (u.side === "right" ? b.x - T.x - m.w : u.side === "left" ? T.x - b.x - A.w : u.side === "below" ? b.y - T.y - m.h : T.y - b.y - A.h) < u.gap - 0.5 && o.push({
2977
+ level: "error",
2978
+ code: "unsatisfied-near",
2979
+ message: `Required: ${u.id} ${u.side} of ${u.ref} is not satisfied.`,
2980
+ line: u.line,
2981
+ ids: [u.id, u.ref]
2982
+ });
2983
+ }
2984
+ for (const [u, { pos: A, hint: m }] of l) {
2985
+ if (M.has(u) || m.type === "near" && m.strength === "required") continue;
2986
+ const b = c.get(u), T = Math.round(Math.hypot(b.x - A.x, b.y - A.y));
2987
+ T >= 2 && o.push({
2988
+ level: T >= Un ? "warning" : "info",
2989
+ code: "relaxed",
2990
+ message: `${m.type} ${u} gave way by ${T} px to keep ${n} clear.${T >= Un ? ` Remove line ${m.line}, or run format --drop-stale.` : ""}`,
2991
+ line: m.line,
2992
+ ids: [u]
2993
+ });
2994
+ }
2995
+ return c;
2996
+ }
2997
+ const Wi = 0.5, Xi = 16, Wn = (e) => Math.min(e * Wi, Math.max(0, e - Xi));
2998
+ function tn(e, t, s = !1) {
2999
+ if (s) return At(e, t, !0);
3000
+ const n = new Map(e.objects.map((l) => [l.id, l])), o = e.hints.filter(
3001
+ (l) => l.type === "near" && Vt(n, l.id, l.ref) !== l.ref
3002
+ );
3003
+ if (o.length) {
3004
+ const l = tn(
3005
+ { ...e, hints: e.hints.filter((i) => !o.includes(i)) },
3006
+ t
3007
+ ), p = (i, g) => {
3008
+ const f = l.byId.get(i);
3009
+ return g === "x" ? f.x + f.w / 2 : f.y + f.h / 2;
3010
+ }, a = e.hints.map((i) => {
3011
+ if (!o.includes(i) || i.type !== "near") return i;
3012
+ const g = Vt(n, i.id, i.ref), f = i.side === "left" || i.side === "right" ? "y" : "x";
3013
+ return { ...i, ref: g, offset: i.offset + p(i.ref, f) - p(g, f) };
3014
+ });
3015
+ return tn({ ...e, hints: a }, t);
3016
+ }
3017
+ const r = { ...e, hints: e.hints.filter((l) => l.type === "size" || l.type === "order") }, d = At(r, t), h = d, c = bo.get(h), y = (l) => (Math.max(...l.map((p) => p.x + p.w)) - Math.min(...l.map((p) => p.x))) * (Math.max(...l.map((p) => p.y + p.h)) - Math.min(...l.map((p) => p.y))), w = ws(
3018
+ Ms(h.objects, e.edges, e.routing),
3019
+ y(h.objects),
3020
+ (l) => y(At(r, t, !1, l, c).objects)
3021
+ );
3022
+ return At(e, t, !1, w.size ? w : void 0, c);
3023
+ }
3024
+ const bo = /* @__PURE__ */ new WeakMap();
3025
+ function At(e, t, s = !1, n, o) {
3026
+ const r = e.edges.filter((L) => L.constraint !== !1 && L.directed !== !1), d = new Set(r.filter((L) => !L.dashed).map((L) => L.target)), h = r.filter((L) => !L.dashed || !d.has(L.target)), c = {
3027
+ port: Math.max(e.routing.portGap ?? 16, e.routing.edgeGap ?? 16),
3028
+ track: e.routing.edgeGap ?? 16
3029
+ }, y = [], w = /* @__PURE__ */ new Map([["root", []]]);
3030
+ for (const L of e.objects)
3031
+ w.has(L.parent) || w.set(L.parent, []), w.get(L.parent).push(L);
3032
+ const l = pt(e.appearance), p = l.groupHeader, a = /* @__PURE__ */ new Map(), i = l.theme === It ? l : pt({ ...e.appearance, theme: It }), g = /* @__PURE__ */ new Map(), f = /* @__PURE__ */ new Map(), M = /* @__PURE__ */ new Map(), k = /* @__PURE__ */ new Map(), S = /* @__PURE__ */ new Map(), D = /* @__PURE__ */ new Map(), _ = new Map(e.objects.map((L) => [L.id, L])), $ = /* @__PURE__ */ new Map(), x = (L, j) => {
3033
+ let q = _.get(L);
3034
+ for (; q && q.parent !== j; ) q = _.get(q.parent);
3035
+ return q?.id;
3036
+ }, E = [], v = [], u = /* @__PURE__ */ new Map(), A = new Set(o?.groups);
3037
+ let m = o?.wrap ?? !1;
3038
+ const b = (L) => {
3039
+ const j = /* @__PURE__ */ new Map();
3040
+ for (const q of h) {
3041
+ const W = x(q.source, L);
3042
+ W && x(q.target, L) !== W && j.set(W, [...j.get(W) ?? [], q]);
3043
+ }
3044
+ return new Set(
3045
+ [...j].filter(
3046
+ ([q, W]) => W.length > 1 && (_.get(q).shape === "diamond" || W.filter((ee) => ee.label).length > 1)
3047
+ ).map(([q]) => q)
3048
+ );
3049
+ }, T = (L) => h.map((j) => [x(j.source, L), x(j.target, L)]).filter((j) => !!j[0] && !!j[1] && j[0] !== j[1]), F = (L, j, q) => {
3050
+ const W = (se) => x(se, L) !== void 0, ee = e.objects.filter((se) => W(se.id)).map((se) => se.id), Y = new Map(
3051
+ ht(
3052
+ ee,
3053
+ h.filter((se) => W(se.source) && W(se.target)).map((se) => [se.source, se.target])
3054
+ ).flatMap((se, pe) => se.map((ve) => [ve, pe]))
3055
+ ), H = new Map(j.map((se) => [se, 1 / 0]));
3056
+ for (const se of ee) {
3057
+ const pe = x(se, L);
3058
+ H.set(pe, Math.min(H.get(pe), Y.get(se)));
3059
+ }
3060
+ const J = (se, pe) => {
3061
+ const ve = /* @__PURE__ */ new Set([se]), xe = [se];
3062
+ for (; xe.length; ) {
3063
+ const Be = xe.pop();
3064
+ if (Be === pe) return !0;
3065
+ for (const [Xe, Re] of q)
3066
+ Xe === Be && !ve.has(Re) && (ve.add(Re), xe.push(Re));
3067
+ }
3068
+ return !1;
3069
+ };
3070
+ return q.filter(([se, pe]) => !(H.get(pe) < H.get(se) && J(pe, se)));
3071
+ }, X = (L) => {
3072
+ w.get(L);
3073
+ };
3074
+ let B = 0, G = 0;
3075
+ for (const L of w.keys()) {
3076
+ const j = X(L);
3077
+ if (!j) continue;
3078
+ B = Math.max(B, j.groupGap);
3079
+ const q = T(L), W = new Map(
3080
+ ht(
3081
+ (w.get(L) ?? []).map((Y) => Y.id),
3082
+ q
3083
+ ).flatMap((Y, H) => Y.map((J) => [J, H]))
3084
+ ), ee = Math.max(0, ...W.values());
3085
+ for (let Y = 0; Y < ee; Y++)
3086
+ G = Math.max(
3087
+ G,
3088
+ q.filter(
3089
+ ([H, J]) => Math.min(W.get(H), W.get(J)) <= Y && Math.max(W.get(H), W.get(J)) > Y
3090
+ ).length
3091
+ );
3092
+ }
3093
+ B = Math.min(Ni, Math.max(B, (G + 1) * (e.routing.edgeGap ?? 16)));
3094
+ function P(L) {
3095
+ const j = zt(e, L);
3096
+ return j.algorithm === "row" ? "right" : j.algorithm === "column" ? "down" : nt(j);
3097
+ }
3098
+ function R(L, j) {
3099
+ const q = nt(j) === "right", W = Math.max(j.gap, ei), ee = /* @__PURE__ */ new Map();
3100
+ for (const Z of L) for (const me of w.get(Z.id) ?? []) ee.set(me.id, Z.id);
3101
+ const Y = [...ee.keys()], H = (Z) => g.get(Z) ?? k.get(Z), J = (Z) => q ? H(Z).w : H(Z).h, se = (Z) => q ? H(Z).h : H(Z).w, pe = (Z) => {
3102
+ let me = _.get(Z);
3103
+ for (; me && !ee.has(me.id); ) me = _.get(me.parent);
3104
+ return me?.id;
3105
+ }, ve = h.map((Z) => [pe(Z.source), pe(Z.target)]).filter((Z) => !!Z[0] && !!Z[1] && Z[0] !== Z[1]), xe = Y.length ? xo(ht(Y, ve), ve) : [], Be = new Map(xe.flatMap((Z, me) => Z.map((ke) => [ke, me]))), Xe = xe.map((Z) => Math.max(...Z.map(J))), Re = [];
3106
+ let ze = 0;
3107
+ for (const [Z, me] of xe.entries()) {
3108
+ Re.push(ze);
3109
+ let ke = W;
3110
+ for (const Oe of e.edges) {
3111
+ const Ee = Be.get(pe(Oe.source) ?? ""), Ae = Be.get(pe(Oe.target) ?? "");
3112
+ if (Oe.label && Ee !== void 0 && Ae !== void 0 && Math.min(Ee, Ae) === Z && Ee !== Ae) {
3113
+ const _e = Bt("", "", Oe.label, l);
3114
+ ke = Math.max(ke, q ? _e.w : _e.h);
3115
+ }
3116
+ }
3117
+ ze += Xe[Z] + (me === xe.at(-1) ? 0 : ke);
3118
+ }
3119
+ const Ie = ze, mt = /* @__PURE__ */ new Map();
3120
+ for (const Z of L) {
3121
+ const me = xe.map((Ee) => Ee.filter((Ae) => ee.get(Ae) === Z.id)), ke = (Ee) => Ee.reduce((Ae, _e, qe) => Ae + se(_e) + (qe ? Dn : 0), 0), Oe = Math.max(ti, ...me.map(ke));
3122
+ mt.set(Z.id, Oe), me.forEach((Ee, Ae) => {
3123
+ let _e = (Oe - ke(Ee)) / 2;
3124
+ for (const qe of Ee) {
3125
+ const ue = Re[Ae] + (Xe[Ae] - J(qe)) / 2, et = q ? { x: ue, y: _e } : { x: _e, y: ue };
3126
+ S.set(qe, { x: re(et.x), y: re(et.y) }), D.set(qe, et), _e += se(qe) + Dn;
3127
+ }
3128
+ });
3129
+ }
3130
+ const wt = (Z) => Math.ceil(ye(Z.label, l.groupTitle)) + Xt, Pe = Math.max(Ie + 2 * Se, ...L.map(wt));
3131
+ let Ke = 0;
3132
+ for (const Z of L) {
3133
+ const me = mt.get(Z.id);
3134
+ Z.w = q ? Pe : Math.max(me + 2 * Se, wt(Z)), Z.h = p + (q ? me : Ie) + Se;
3135
+ const ke = q ? { x: 0, y: Ke } : { x: Ke, y: 0 };
3136
+ S.set(Z.id, ke), D.set(Z.id, ke), Ke += (q ? Z.h : Z.w) + Nn;
3137
+ }
3138
+ const Ue = Math.max(0, Ke - Nn);
3139
+ return q ? { w: L.length ? Pe : 0, h: Ue } : { w: Ue, h: L.length ? p + Ie + Se : 0 };
3140
+ }
3141
+ function N(L, j) {
3142
+ const q = L.filter((H) => H.type === "node" && (H.shape === "box" || H.shape === "pill"));
3143
+ if (q.length < 2) return;
3144
+ const W = (H) => e.hints.some((J) => J.type === "size" && J.id === H.id), ee = Math.max(...q.map((H) => H.w)), Y = Math.max(...q.map((H) => j.get(H.id)?.ref.w ?? H.w));
3145
+ for (const H of q) {
3146
+ if (W(H) || H.w === ee) continue;
3147
+ const J = Et(H, { width: ee }, l);
3148
+ if (H.w = re(J.w), H.h = re(J.h), !j.get(H.id)) continue;
3149
+ const pe = Et(H, { width: Y }, i);
3150
+ j.set(H.id, {
3151
+ look: { w: H.w, h: H.h },
3152
+ ref: { w: re(pe.w), h: re(pe.h) }
3153
+ });
3154
+ }
3155
+ }
3156
+ function U(L) {
3157
+ const j = zt(e, L), q = e.hints.find((z) => z.type === "order" && z.scope === L);
3158
+ let W = w.get(L) ?? [];
3159
+ if (q?.type === "order" && (W = [...q.ids.flatMap((Q) => W.filter((K) => K.id === Q)), ...W.filter((Q) => !q.ids.includes(Q.id))]), j.algorithm === "cells") return I(L, W, j);
3160
+ const ee = /* @__PURE__ */ new Map(), Y = W.map((z) => {
3161
+ let Q;
3162
+ if (z.type === "group") {
3163
+ const ie = U(z.id), ne = zt(e, z.id), ge = !w.get(z.id)?.length, de = f.get(z.id);
3164
+ Q = de !== void 0 ? {
3165
+ w: Math.max(ie.w, ne.minWidth),
3166
+ h: Math.max(ie.h + de, ne.minHeight)
3167
+ } : (() => {
3168
+ const be = Math.max(
3169
+ ge ? Fn.w : 0,
3170
+ ie.w + Se + (n?.get(z.id)?.right ?? Se),
3171
+ ne.minWidth
3172
+ ), Ce = vi(z.label, be, l);
3173
+ return Ce.lines > 1 && a.set(z.id, Ce.lines), {
3174
+ w: Math.max(be, Ce.w),
3175
+ h: Math.max(
3176
+ ge ? Fn.h : 0,
3177
+ ie.h + _t(l, Ce.lines) + (n?.get(z.id)?.bottom ?? Se),
3178
+ ne.minHeight
3179
+ )
3180
+ };
3181
+ })();
3182
+ } else {
3183
+ const ie = e.hints.find((ge) => ge.type === "size" && ge.id === z.id), ne = Et(z, ie?.type === "size" ? ie : void 0, l);
3184
+ if (Q = ne, i !== l) {
3185
+ const ge = Et(z, ie?.type === "size" ? ie : void 0, i);
3186
+ ee.set(z.id, {
3187
+ look: { w: re(ne.w), h: re(ne.h) },
3188
+ ref: { w: re(ge.w), h: re(ge.h) }
3189
+ });
3190
+ }
3191
+ z.shape === "diamond" && !ie && ne.w > io("diamond").w * Si && y.push({
3192
+ level: "info",
3193
+ code: "big-diamond",
3194
+ message: `${z.id}'s question makes its diamond ${re(ne.w)}px square, much larger than the shapes around it. Shorten the question, or move the detail onto its edges' labels.`,
3195
+ line: z.line,
3196
+ ids: [z.id]
3197
+ }), ne.overflow && y.push({
3198
+ level: "warning",
3199
+ code: "text-overflow",
3200
+ message: `${z.id}'s title does not fit in its requested size. Make it larger or remove the size line.`,
3201
+ line: ie?.line,
3202
+ ids: [z.id]
3203
+ });
3204
+ }
3205
+ const K = { ...z, w: re(Q.w), h: re(Q.h) };
3206
+ return k.set(z.id, K), K;
3207
+ });
3208
+ if (j.algorithm === "column" && N(Y, ee), L === "root" && j.algorithm === "lanes") return R(Y, j);
3209
+ const H = T(L), J = _.get(L)?.parent, se = J !== void 0 && P(J) === P(L), pe = (L === "root" ? [] : e.edges).flatMap((z) => {
3210
+ const Q = x(z.source, L), K = x(z.target, L);
3211
+ return !Q && !K || Q === K || !(Q && K) && !se ? [] : [{ a: Q, b: K, label: z.label && !(Q && K) ? Je(z.label, l) : void 0 }];
3212
+ }), ve = /* @__PURE__ */ new Map();
3213
+ for (const z of h) {
3214
+ const Q = x(z.source, L), K = x(z.target, L);
3215
+ Q && !K && ve.set(Q, [...ve.get(Q) ?? [], z.target]), K && !Q && ve.set(K, [...ve.get(K) ?? [], z.source]);
3216
+ }
3217
+ const xe = (z, Q) => {
3218
+ const K = S.get(z), ie = g.get(z) ?? k.get(z);
3219
+ return Q ? K.y + ie.h / 2 : K.x + ie.w / 2;
3220
+ }, Be = /* @__PURE__ */ new Map(), Xe = _.get(L)?.parent, Re = Xe !== void 0 && w.get(Xe) || [], ze = Y.map((z) => ve.get(z.id) ?? []), Ie = ze[0]?.length === 1 ? _.get(ze[0][0])?.parent : void 0, mt = Re.findIndex((z) => z.id === Ie) < Re.findIndex((z) => z.id === L);
3221
+ if (Ie !== void 0 && Ie !== L && Re.some((z) => z.id === Ie) && mt && ze.every((z) => z.length === 1 && _.get(z[0])?.parent === Ie && S.has(z[0])))
3222
+ for (const [z, Q] of Y.entries())
3223
+ Be.set(Q.id, xe(ze[z][0], P(Ie) === "right"));
3224
+ const wt = (z, Q) => {
3225
+ if ($.get(Q) !== z) return;
3226
+ const K = P(L) === "right", ie = (de) => K ? _t(l, a.get(de)) : Se, ge = e.edges.filter(
3227
+ (de) => _.get(de.source)?.parent === z && _.get(de.target)?.parent === Q
3228
+ ).sort((de, be) => xe(de.target, K) - xe(be.target, K))[0];
3229
+ return ge ? ie(z) + xe(ge.source, K) - ie(Q) - xe(ge.target, K) : void 0;
3230
+ }, Pe = e.edges.flatMap((z) => {
3231
+ const Q = x(z.source, L), K = x(z.target, L);
3232
+ if (!z.label || !Q || !K || Q === K) return [];
3233
+ const ie = Bt(Q, K, z.label, l);
3234
+ if (i === l) return [ie];
3235
+ const ne = Bt(Q, K, z.label, i);
3236
+ return [{ a: Q, b: K, w: Math.max(ne.w, ie.w - Fe), h: Math.max(ne.h, ie.h - Fe) }];
3237
+ }), Ke = t, Ue = X(L), Z = Ue ? { node: Ue.nodeGap, rank: Ue.rankGap, group: B } : void 0, me = Ue ? F(
3238
+ L,
3239
+ Y.map((z) => z.id),
3240
+ H
3241
+ ) : void 0, ke = (z, Q) => {
3242
+ const K = j.algorithm === "row" ? "right" : j.algorithm === "column" ? "down" : z, ie = {
3243
+ x: K === "right",
3244
+ y: K === "down"
3245
+ }, ne = (de) => s ? de : ee.get(de.id)?.look ?? de, ge = /* @__PURE__ */ new Map();
3246
+ return new Map(
3247
+ Y.map((de) => {
3248
+ const be = ne(de);
3249
+ return [
3250
+ de.id,
3251
+ {
3252
+ x: ie.x ? (de.w - be.w) / 2 : 0,
3253
+ y: ge.get(de.id) ?? (ie.y ? (de.h - be.h) / 2 : 0),
3254
+ w: be.w,
3255
+ h: be.h
3256
+ }
3257
+ ];
3258
+ })
3259
+ );
3260
+ }, Oe = (z) => {
3261
+ for (const ce of Y) {
3262
+ const Te = ee.get(ce.id);
3263
+ Te && (ce.w = Math.max(Te.ref.w, Te.look.w - z.w), ce.h = Math.max(Te.ref.h, Te.look.h - z.h));
3264
+ }
3265
+ const Q = (ce) => Z ? Ci(
3266
+ Y,
3267
+ t,
3268
+ nt(Ke),
3269
+ me,
3270
+ ce,
3271
+ Z,
3272
+ L === "root",
3273
+ pe,
3274
+ ve,
3275
+ Be,
3276
+ wt
3277
+ ) : zi(Y, j, H, ce, pe, c), K = Pe.length ? Q([]) : void 0, ie = K ? Di(
3278
+ new Map(
3279
+ Y.map((ce) => {
3280
+ const Te = K.positions.get(ce.id), yt = ke(K.axis, K.positions).get(ce.id);
3281
+ return [ce.id, { x: Te.x + yt.x, y: Te.y + yt.y, w: yt.w, h: yt.h }];
3282
+ })
3283
+ ),
3284
+ K.axis,
3285
+ Pe
3286
+ ) : /* @__PURE__ */ new Set(), ne = Q(Pe.filter((ce) => !ie.has(ce)));
3287
+ let ge;
3288
+ if (j.algorithm === "flow" && j.fold === "auto") {
3289
+ const ce = Ut(
3290
+ Y,
3291
+ ne.positions,
3292
+ ne.axis,
3293
+ j.gap,
3294
+ H,
3295
+ Pe,
3296
+ b(L),
3297
+ (K ?? ne).positions
3298
+ );
3299
+ ne.positions = ce.positions, ge = ce.fold;
3300
+ }
3301
+ const de = !ge && Ue && Ke?.engine?.params.fold !== "never";
3302
+ if (de && A.has(L)) {
3303
+ const ce = Ut(
3304
+ Y,
3305
+ ne.positions,
3306
+ ne.axis,
3307
+ Z.rank,
3308
+ H,
3309
+ Pe,
3310
+ b(L),
3311
+ (K ?? ne).positions,
3312
+ { fewest: 2, room: 0 }
3313
+ );
3314
+ ne.positions = ce.positions, ge = ce.fold;
3315
+ }
3316
+ if (de && L === "root" && m) {
3317
+ const ce = Ut(
3318
+ Y,
3319
+ ne.positions,
3320
+ ne.axis,
3321
+ Z.rank,
3322
+ H,
3323
+ Pe,
3324
+ b(L),
3325
+ (K ?? ne).positions,
3326
+ { aspect: Gn, fewest: 2 }
3327
+ );
3328
+ ne.positions = ce.positions, ge = ce.fold;
3329
+ }
3330
+ const be = n?.get(L);
3331
+ if (be && (be.left > Se || be.top))
3332
+ for (const [ce, Te] of ne.positions)
3333
+ ne.positions.set(ce, { x: Te.x + be.left - Se, y: Te.y + be.top });
3334
+ const Ce = ke(ne.axis, ne.positions), Ao = ee.size ? e.hints.map(
3335
+ (ce) => (ce.type === "stay" || ce.type === "pin") && Ce.has(ce.id) ? { ...ce, x: ce.x - Ce.get(ce.id).x, y: ce.y - Ce.get(ce.id).y } : ce
3336
+ ) : e.hints, So = Yi(Y, ne.positions, Ao, L, y, ne.axis);
3337
+ return "followed" in ne && ne.followed ? $.set(L, Ie) : $.delete(L), { base: ne, fold: ge, pos: So, off: Ce };
3338
+ }, Ee = (z, Q) => {
3339
+ const K = Q.pos.get(z.id), ie = Q.off.get(z.id);
3340
+ return { x: K.x + ie.x, y: K.y + ie.y, w: ie.w, h: ie.h };
3341
+ }, Ae = (z, Q) => ({
3342
+ ...Q.pos.get(z.id),
3343
+ w: z.w,
3344
+ h: z.h
3345
+ }), _e = ee.size ? { w: Wn(j.gap), h: Wn(j.gap) } : { w: 0, h: 0 }, qe = y.length;
3346
+ let ue = Oe(_e);
3347
+ !s && (_e.w || _e.h) && Y.some(
3348
+ (z, Q) => Y.slice(Q + 1).some(
3349
+ (K) => Pn(Ae(z, ue), Ae(K, ue)) >= ft - 0.5 && Pn(Ee(z, ue), Ee(K, ue)) < ft - 0.5
3350
+ )
3351
+ ) && (y.length = qe, ue = Oe({ w: 0, h: 0 })), ue.fold && E.push({ scope: L, fold: ue.fold });
3352
+ const et = ue.base.corridors;
3353
+ et && L === "root" && !ue.fold && !n?.get(L) && Y.every((z) => {
3354
+ const Q = ue.pos.get(z.id), K = ue.base.positions.get(z.id);
3355
+ return Q && K && Math.abs(Q.x - K.x) < 0.01 && Math.abs(Q.y - K.y) < 0.01;
3356
+ }) && u.set(L, { axis: ue.base.axis, corridors: et }), j.algorithm === "flow" && v.push({ scope: L, axis: ue.base.axis });
3357
+ const at = Y.map((z) => Ee(z, ue)), Ft = L === "root" ? 0 : Math.max(0, ...Y.map((z) => z.soft?.length ?? 0)), rt = L === "root" || !Y.length ? { x: 0, y: 0 } : {
3358
+ x: Math.max(0, -Math.min(...at.map((z) => z.x))) + Ft * dt,
3359
+ y: Math.max(0, -Math.min(...at.map((z) => z.y))) + Ft * (dt + Rt)
3360
+ };
3361
+ for (const [z, Q] of Y.entries()) {
3362
+ const K = at[z], ie = ue.off.get(Q.id), ne = ue.base.positions.get(Q.id);
3363
+ S.set(Q.id, { x: re(K.x + rt.x), y: re(K.y + rt.y) }), D.set(Q.id, { x: ne.x + ie.x + rt.x, y: ne.y + ie.y + rt.y }), ee.has(Q.id) && g.set(Q.id, { w: re(K.w), h: re(K.h) });
3364
+ }
3365
+ const rn = (z, Q) => Y.length ? Math.max(
3366
+ ...Y.map(
3367
+ (K, ie) => Math.max(ue.pos.get(K.id)[z] + K[Q], at[ie][z] + at[ie][Q])
3368
+ )
3369
+ ) + rt[z] + Ft * dt : 0;
3370
+ return { w: rn("x", "w"), h: rn("y", "h") };
3371
+ }
3372
+ function I(L, j, q) {
3373
+ if (q.unit) return O(L, j, q);
3374
+ const W = Math.ceil(ye(_.get(L).label, l.groupTitle)) + Xo, ee = (H) => e.hints.find((J) => J.type === "size" && J.id === H), Y = is(
3375
+ j.map((H) => {
3376
+ const J = ee(H.id);
3377
+ return {
3378
+ id: H.id,
3379
+ label: H.label,
3380
+ marker: H.shape === "marker",
3381
+ ...typeof H.span == "number" ? { span: H.span } : {},
3382
+ ...J?.type === "size" ? { size: { width: J.width, height: J.height, minHeight: J.minHeight } } : {}
3383
+ };
3384
+ }),
3385
+ {
3386
+ direction: q.direction === "down" ? "down" : "right",
3387
+ ...q.columns ? { columns: q.columns } : {}
3388
+ },
3389
+ l,
3390
+ W
3391
+ );
3392
+ return C(L, j, Y.boxes), f.set(L, Qt(l.groupTitle.lineHeight)), { w: Math.max(Y.w, W), h: Y.h };
3393
+ }
3394
+ function O(L, j, q) {
3395
+ const W = cs(
3396
+ j.map((H) => ({
3397
+ id: H.id,
3398
+ label: H.label,
3399
+ marker: !1,
3400
+ ...typeof H.span == "number" ? { span: H.span } : {},
3401
+ open: H.span === "var"
3402
+ })),
3403
+ {
3404
+ unit: q.unit,
3405
+ ruler: q.ruler !== !1,
3406
+ ...q.columns ? { columns: q.columns } : {},
3407
+ ...q.unitWidth ? { unitWidth: q.unitWidth } : {}
3408
+ },
3409
+ l
3410
+ ), ee = Qt(l.groupTitle.lineHeight), Y = ee + (W.ruler?.h ?? 0);
3411
+ return C(L, j, W.boxes), f.set(L, Y), M.set(L, {
3412
+ ...W.ruler ? { ruler: { y: ee, ...W.ruler } } : {},
3413
+ ...W.pieces.size ? {
3414
+ pieces: Object.fromEntries(
3415
+ [...W.pieces].map(([H, J]) => [H, J.map((se) => ({ ...se, y: se.y + Y }))])
3416
+ )
3417
+ } : {},
3418
+ ...W.open.length ? { open: W.open } : {}
3419
+ }), { w: W.w, h: W.h };
3420
+ }
3421
+ function C(L, j, q) {
3422
+ for (const W of j) {
3423
+ const ee = q.get(W.id);
3424
+ k.set(W.id, { ...W, w: re(ee.w), h: re(ee.h) }), S.set(W.id, { x: re(ee.x), y: re(ee.y) }), D.set(W.id, { x: ee.x, y: ee.y });
3425
+ const Y = e.hints.find(
3426
+ (H) => Ws.includes(H.type) && "id" in H && H.id === W.id
3427
+ );
3428
+ Y && y.push({
3429
+ level: "warning",
3430
+ code: "cell-position",
3431
+ message: `${W.id} is a cell of ${L}, so it stays in its place. Move ${L} instead, or reorder its cells with order.`,
3432
+ line: Y.line,
3433
+ ids: [W.id]
3434
+ });
3435
+ }
3436
+ }
3437
+ const V = y.length, oe = X("root") && Mi(e, "root");
3438
+ let ae = U("root");
3439
+ if (!o && oe && oe.engine?.params.fold !== "never") {
3440
+ let L = function(H) {
3441
+ return q(H) > yo * W(H);
3442
+ };
3443
+ const j = nt(oe) === "right", q = (H) => j ? H.w : H.h, W = (H) => j ? H.h : H.w, ee = j ? $t.width : $t.height, Y = (H) => q(H) > ee && q(H) > Gn * W(H);
3444
+ for (; Y(ae) && !m; ) {
3445
+ const H = [...k.values()].filter(
3446
+ (J) => J.type === "group" && !A.has(J.id) && X(J.id) && L(J)
3447
+ ).sort((J, se) => q(se) - q(J))[0];
3448
+ H ? A.add(H.id) : m = !0, y.length = V, E.length = v.length = 0, g.clear(), ae = U("root");
3449
+ }
3450
+ }
3451
+ if (!o && oe && nt(oe) === "down" && oe.engine?.params.fold !== "never") {
3452
+ const L = (q) => q.h, j = (q) => q.w * q.h;
3453
+ for (; ; ) {
3454
+ const q = (w.get("root") ?? []).map((H) => k.get(H.id)).filter(Boolean).sort((H, J) => L(J) - L(H)), [W, ee] = q;
3455
+ if (!W || !ee || W.type !== "group" || W.fold === "never" || A.has(W.id) || !X(W.id) || L(W) < ki * L(ee))
3456
+ break;
3457
+ const Y = ae;
3458
+ if (A.add(W.id), y.length = V, E.length = v.length = 0, g.clear(), ae = U("root"), !(j(ae) < j(Y))) {
3459
+ A.delete(W.id), y.length = V, E.length = v.length = 0, g.clear(), U("root");
3460
+ break;
3461
+ }
3462
+ }
3463
+ }
3464
+ const le = [], he = (L, j, q) => {
3465
+ for (const W of w.get(L) ?? []) {
3466
+ const ee = g.get(W.id) ?? k.get(W.id), Y = S.get(W.id), H = D.get(W.id), J = {
3467
+ ...W,
3468
+ x: j.x + Y.x,
3469
+ y: j.y + Y.y,
3470
+ w: ee.w,
3471
+ h: ee.h,
3472
+ localX: Y.x,
3473
+ localY: Y.y,
3474
+ baseX: re(H.x),
3475
+ baseY: re(H.y),
3476
+ depth: q,
3477
+ ...a.has(W.id) ? { titleLines: a.get(W.id) } : {}
3478
+ };
3479
+ le.push(J), W.type === "group" && he(
3480
+ W.id,
3481
+ f.has(W.id) ? { x: J.x, y: J.y + f.get(W.id) } : so(J, _t(l, J.titleLines)),
3482
+ q + 1
3483
+ );
3484
+ }
3485
+ };
3486
+ he("root", { x: 0, y: 0 }, 0);
3487
+ const we = Ki(u, le, h, x, c), fe = Ri(
3488
+ E,
3489
+ e.edges,
3490
+ new Map(le.map((L) => [L.id, L])),
3491
+ x,
3492
+ Math.max(e.routing.portGap ?? 16, e.routing.edgeGap ?? 16)
3493
+ );
3494
+ for (const [L, j] of ks(
3495
+ v.map((q) => ({ ...q, bands: E.find((W) => W.scope === q.scope)?.fold.bands })),
3496
+ e.edges,
3497
+ new Map(le.map((q) => [q.id, q])),
3498
+ new Set(fe.keys()),
3499
+ (q) => Je(q, l)
3500
+ ))
3501
+ fe.set(L, j);
3502
+ for (const L of e.layouts) {
3503
+ const j = le.find((q) => q.id === L.scope);
3504
+ !j || !L.minWidth && !L.minHeight || (L.minWidth && j.w > L.minWidth + 0.5 || L.minHeight && j.h > L.minHeight + 0.5) && y.push({
3505
+ level: "info",
3506
+ code: "group-grew",
3507
+ message: `${j.id} needs at least ${j.w}×${j.h} for its contents.`,
3508
+ line: L.line,
3509
+ ids: [j.id]
3510
+ });
3511
+ }
3512
+ Ps(e), y.push(...yi(e), ...$s(e));
3513
+ for (const L of e.warnings) y.push({ level: "warning", ...L, ids: [] });
3514
+ const te = new Map(e.objects.map((L, j) => [L.id, j]));
3515
+ le.sort((L, j) => te.get(L.id) - te.get(j.id));
3516
+ const Me = {
3517
+ model: e,
3518
+ title: e.title,
3519
+ objects: le,
3520
+ byId: new Map(le.map((L) => [L.id, L])),
3521
+ edges: e.edges.map((L) => {
3522
+ const j = fe.get(L.id), q = j ? void 0 : we.get(L.id);
3523
+ return j ? { ...L, lane: j } : q ? { ...L, plan: q } : L;
3524
+ }),
3525
+ diagnostics: y,
3526
+ look: l,
3527
+ cells: M
3528
+ };
3529
+ return bo.set(Me, { groups: A, wrap: m }), Me;
3530
+ }
3531
+ function Ki(e, t, s, n, o) {
3532
+ const r = /* @__PURE__ */ new Map(), d = new Map(t.map((h) => [h.id, h]));
3533
+ for (const [h, { axis: c, corridors: y }] of e) {
3534
+ const w = s.filter((i) => {
3535
+ const g = n(i.source, h), f = n(i.target, h);
3536
+ return !!g && !!f && g !== f;
3537
+ }), l = new Map(y.order.flatMap((i, g) => i.map((f) => [f, g]))), p = (i) => {
3538
+ const g = d.get(i);
3539
+ return !!g && g.type === "node" && (g.shape ?? "box") === "box";
3540
+ }, a = [];
3541
+ for (const [i, g] of w.entries()) {
3542
+ const f = g.source, M = g.target;
3543
+ n(f, h) !== f || n(M, h) !== M || !p(f) || !p(M) || l.get(f) < l.get(M) && a.push({ id: g.id, chain: [f, ...y.chains.get(i) ?? [], M] });
3544
+ }
3545
+ for (const [i, g] of Ss(
3546
+ c,
3547
+ y.order,
3548
+ a,
3549
+ (f) => d.get(f),
3550
+ (f) => y.across.get(f),
3551
+ o
3552
+ ))
3553
+ r.set(i, g);
3554
+ }
3555
+ return r;
3556
+ }
3557
+ const De = Object.freeze({
3558
+ sourceBytes: 256 * 1024,
3559
+ objects: 500,
3560
+ edges: 1200,
3561
+ depth: 12,
3562
+ labelChars: 16 * 1024,
3563
+ totalLabelBytes: 1024 * 1024,
3564
+ outputBytes: 1024 * 1024,
3565
+ nativeSourceChars: 3e5
3566
+ }), nn = /* @__PURE__ */ new Set(["root", "__proto__", "constructor", "prototype"]);
3567
+ class vo {
3568
+ entries = [];
3569
+ byForeign = /* @__PURE__ */ new Map();
3570
+ taken = new Set(nn);
3571
+ get(t, s, n = s) {
3572
+ const o = JSON.stringify([t, s]), r = this.byForeign.get(o);
3573
+ if (r) return r;
3574
+ let d = [...n].map((c) => /[A-Za-z0-9_.-]/.test(c) ? c : "_u" + c.codePointAt(0).toString(16) + "_").join("");
3575
+ /^[A-Za-z_]/.test(d) || (d = t + "_" + d), (!d || nn.has(d)) && (d = t + "_" + (d || "item"));
3576
+ let h = d;
3577
+ for (let c = 2; this.taken.has(h); c++) h = d + "__" + c;
3578
+ return this.byForeign.set(o, h), this.taken.add(h), this.entries.push({ kind: t, foreign: s, native: h }), h;
3579
+ }
3580
+ }
3581
+ const He = (e) => JSON.stringify(e), ko = (e) => ({
3582
+ title: e,
3583
+ objects: [],
3584
+ edges: [],
3585
+ layouts: [],
3586
+ colors: []
3587
+ });
3588
+ function Eo(e, t, s, n, o) {
3589
+ const r = (i, g, f = "semantics") => n.push({ code: i, severity: "error", impact: f, message: g });
3590
+ (s.objects.length > De.objects || s.edges.length > De.edges) && r(
3591
+ "IMPORT_GRAPH_LIMIT",
3592
+ "Native source allows at most 500 nodes plus groups, and 1,200 edges.",
3593
+ "limit"
3594
+ );
3595
+ const d = new TextEncoder();
3596
+ [s.title, ...s.objects.map((i) => i.label), ...s.edges.map((i) => i.label)].reduce((i, g) => i + d.encode(g).length, 0) > De.totalLabelBytes && r(
3597
+ "IMPORT_TOTAL_LABEL_LIMIT",
3598
+ "Expanded native labels exceed a combined 1 MiB of UTF-8 text.",
3599
+ "limit"
3600
+ ), s.title.length > De.labelChars && r("IMPORT_LABEL_LIMIT", "Diagram title exceeds 16,384 characters.", "limit");
3601
+ const c = new Map(s.objects.map((i) => [i.id, i])), y = [...s.objects.map((i) => i.id), ...s.edges.map((i) => i.id)];
3602
+ (new Set(y).size !== y.length || y.some((i) => nn.has(i) || !/^[A-Za-z_][A-Za-z0-9_.-]*$/.test(i))) && r("IMPORT_ID_INVARIANT", "Generated IDs must be safe, globally unique native identifiers.");
3603
+ const w = (i) => {
3604
+ const g = [];
3605
+ let f = c.get(i)?.parent;
3606
+ for (; f; ) {
3607
+ if (g.includes(f) || g.length >= De.depth) {
3608
+ r("IMPORT_HIERARCHY", "Containment cycle or excessive nesting.");
3609
+ break;
3610
+ }
3611
+ if (g.push(f), c.get(f)?.kind !== "group") {
3612
+ r("IMPORT_PARENT", "Missing or non-group parent: " + f);
3613
+ break;
3614
+ }
3615
+ f = c.get(f)?.parent;
3616
+ }
3617
+ return g;
3618
+ };
3619
+ for (const i of s.objects)
3620
+ w(i.id).length + 1 > De.depth && r("IMPORT_DEPTH", "Native source permits 12 nesting levels.", "limit"), i.label.length > De.labelChars && r("IMPORT_LABEL_LIMIT", "Label exceeds 16,384 characters.", "limit");
3621
+ for (const i of s.edges)
3622
+ (!c.has(i.from) || !c.has(i.to)) && r("IMPORT_ENDPOINT", "Missing endpoint for " + i.id), (w(i.from).includes(i.to) || w(i.to).includes(i.from)) && r(
3623
+ "IMPORT_ANCESTOR_EDGE",
3624
+ "Native source cannot connect a group to one of its descendants."
3625
+ ), i.label.length > De.labelChars && r("IMPORT_LABEL_LIMIT", "Edge label exceeds 16,384 characters.", "limit");
3626
+ const l = s.edges.some((i) => !i.directed) ? ["IMP-02-native-undirected"] : [];
3627
+ if (n.some((i) => i.severity === "error"))
3628
+ return { status: "failed", format: e, family: t, diagnostics: n, ids: o.entries, requires: l };
3629
+ const p = ["diagram " + He(s.title) + " version=1"];
3630
+ for (const i of s.colors)
3631
+ p.push(
3632
+ "theme-color " + i.name + " shade=500 fill=" + He(i.fill) + " stroke=" + He(i.stroke) + " ink=" + He(i.ink)
3633
+ );
3634
+ for (const i of s.objects) {
3635
+ let g = i.kind + " " + i.id + " " + He(i.label);
3636
+ i.parent && (g += " in=" + i.parent), i.shape && i.shape !== "box" && i.kind === "node" && (g += " shape=" + i.shape), i.color && (g += " color=" + i.color + " shade=" + (i.shade ?? 500)), p.push(g);
3637
+ }
3638
+ for (const i of s.edges) {
3639
+ let g = "edge " + i.id + " " + i.from + " -> " + i.to + " " + He(i.label);
3640
+ i.directed || (g += " directed=false"), i.head && i.head !== "arrow" && (g += " head=" + i.head), i.tail && i.tail !== "none" && (g += " tail=" + i.tail), i.dashed && (g += " kind=async"), i.constraint === !1 && (g += " constraint=false"), i.fromSide && (g += " from=" + i.fromSide), i.toSide && (g += " to=" + i.toSide), p.push(g);
3641
+ }
3642
+ for (const i of s.layouts)
3643
+ p.push(
3644
+ "layout " + i.scope + " " + i.kind + (i.direction ? " direction=" + i.direction : "")
3645
+ );
3646
+ for (const i of s.phases ?? [])
3647
+ p.push(["phase", i.id, He(i.label), ...i.members].join(" "));
3648
+ for (const i of s.notes ?? []) {
3649
+ let g = "note " + He(i.text);
3650
+ i.near && (g += " near=" + i.near), i.side && (g += " side=" + i.side), p.push(g);
3651
+ }
3652
+ const a = p.join(`
3653
+ `) + `
3654
+ `;
3655
+ return a.length > De.nativeSourceChars && r(
3656
+ "IMPORT_NATIVE_SOURCE_LIMIT",
3657
+ "Generated source exceeds the native parser limit of 300,000 source characters.",
3658
+ "limit"
3659
+ ), d.encode(a).length > De.outputBytes && r("IMPORT_OUTPUT_LIMIT", "Generated native source exceeds 1 MiB of UTF-8 text.", "limit"), n.some((i) => i.severity === "error") ? { status: "failed", format: e, family: t, diagnostics: n, ids: o.entries, requires: l } : {
3660
+ status: n.some((i) => i.severity === "warning") ? "needs-review" : "ready",
3661
+ format: e,
3662
+ family: t,
3663
+ diagnostics: n,
3664
+ ids: o.entries,
3665
+ requires: l,
3666
+ nativeSource: a,
3667
+ facts: s
3668
+ };
3669
+ }
3670
+ function Qi(e) {
3671
+ if (e) {
3672
+ if (/^#[a-f0-9]{6}$/i.test(e)) return e.toLowerCase();
3673
+ if (/^#[a-f0-9]{3}$/i.test(e))
3674
+ return "#" + [...e.slice(1)].map((t) => t + t).join("").toLowerCase();
3675
+ }
3676
+ }
3677
+ function Vi(e, t, s, n, o) {
3678
+ if (!s && !n && !o) return;
3679
+ const r = { fill: s ?? "#ffffff", stroke: n ?? "#64748b", ink: o ?? "#172033" };
3680
+ let d = e.colors.find((h) => h.fill === r.fill && h.stroke === r.stroke && h.ink === r.ink);
3681
+ d || (d = { name: "import_" + (e.colors.length + 1), ...r }, e.colors.push(d)), t.color = d.name, t.shade = 500;
3682
+ }
3683
+ const Zi = {
3684
+ SOLID: {},
3685
+ DOTTED: { dashed: !0 },
3686
+ SOLID_OPEN: { head: "none" },
3687
+ DOTTED_OPEN: { head: "none", dashed: !0 },
3688
+ SOLID_CROSS: { head: "cross" },
3689
+ DOTTED_CROSS: { head: "cross", dashed: !0 },
3690
+ SOLID_POINT: {},
3691
+ DOTTED_POINT: { dashed: !0 },
3692
+ BIDIRECTIONAL_SOLID: { tail: "arrow" },
3693
+ BIDIRECTIONAL_DOTTED: { tail: "arrow", dashed: !0 }
3694
+ }, Xn = {
3695
+ LOOP_START: "loop",
3696
+ ALT_START: "alt",
3697
+ OPT_START: "opt",
3698
+ PAR_START: "par",
3699
+ PAR_OVER_START: "par",
3700
+ CRITICAL_START: "critical",
3701
+ BREAK_START: "break"
3702
+ }, Kn = {
3703
+ ALT_ELSE: "else",
3704
+ PAR_AND: "and",
3705
+ CRITICAL_OPTION: "option"
3706
+ }, Ji = ["LOOP_END", "ALT_END", "OPT_END", "PAR_END", "CRITICAL_END", "BREAK_END"];
3707
+ function ea(e, t, s, n) {
3708
+ const o = ko(e.title ? t(e.title) : s), r = new vo(), d = /* @__PURE__ */ new Set(), h = (M, k, S = "semantics") => {
3709
+ d.has(M) || (d.add(M), n.push({ code: M, severity: "warning", impact: S, message: k }));
3710
+ }, c = e.boxes.map((M, k) => {
3711
+ const S = r.get("group", "box_" + (k + 1));
3712
+ return o.objects.push({ id: S, kind: "group", label: t(M.name ?? "") }), M.fill && M.fill !== "transparent" && h("MERMAID_SEQUENCE_BOX_COLOR", "Box colors are omitted.", "appearance"), S;
3713
+ }), y = /* @__PURE__ */ new Map();
3714
+ for (const M of e.actors) {
3715
+ const k = r.get("node", M.id);
3716
+ y.set(M.id, k), o.objects.push({
3717
+ id: k,
3718
+ kind: "node",
3719
+ // `participant p as "Name"` keeps its quotes in the DB.
3720
+ label: t(M.name).replace(/^"(.*)"$/s, "$1"),
3721
+ ...M.box != null && M.box >= 0 ? { parent: c[M.box] } : {}
3722
+ }), M.type !== "participant" && h(
3723
+ "MERMAID_SEQUENCE_ACTOR_TYPE",
3724
+ "Participant symbols such as actor or database become ordinary boxes.",
3725
+ "appearance"
3726
+ ), M.links.length && h(
3727
+ "MERMAID_LINK_OMITTED",
3728
+ "Participant link menus are omitted; native participants have no menu.",
3729
+ "security"
3730
+ );
3731
+ }
3732
+ (e.created.length || e.destroyed.length) && h(
3733
+ "MERMAID_SEQUENCE_LIFELINE",
3734
+ "create and destroy are omitted: native participants span the whole diagram."
3735
+ ), o.layouts.push({ scope: "root", kind: "sequence" });
3736
+ const w = [], l = [];
3737
+ let p = 0, a, i;
3738
+ const g = (M, k) => {
3739
+ const S = t(k).trim();
3740
+ a = {
3741
+ id: r.get("phase", String(w.length + 1), "phase_" + (w.length + 1)),
3742
+ label: S ? `${M}: ${S}` : M,
3743
+ members: []
3744
+ }, w.push(a);
3745
+ }, f = (M) => {
3746
+ const k = [M.from, M.to].filter((_) => _ != null), S = i && k.every((_) => i.ends.includes(_)), D = M.placement === "left" ? "left" : M.placement === "right" ? "right" : void 0;
3747
+ l.push({
3748
+ text: t(M.text),
3749
+ near: S ? i.id : y.get(k[0]),
3750
+ side: D ?? (S ? "right" : "below")
3751
+ });
3752
+ };
3753
+ for (const [M, k] of e.events.entries())
3754
+ if (Xn[k.kind])
3755
+ p++, p === 1 ? g(Xn[k.kind], k.text) : h(
3756
+ "MERMAID_SEQUENCE_NESTED_BLOCK",
3757
+ "A nested block has no band of its own; its messages stay in the outer band."
3758
+ ), h(
3759
+ "MERMAID_SEQUENCE_BLOCK",
3760
+ "Native sequences have no fragments. Each block branch becomes a phase band, so the branch logic is only in its label."
3761
+ );
3762
+ else if (Kn[k.kind])
3763
+ p === 1 && g(Kn[k.kind], k.text);
3764
+ else if (Ji.includes(k.kind))
3765
+ p--, p || (a = void 0);
3766
+ else if (k.kind === "NOTE") f(k);
3767
+ else if (k.kind === "ACTIVE_START" || k.kind === "ACTIVE_END")
3768
+ h("MERMAID_SEQUENCE_ACTIVATION", "Activation bars are omitted.", "appearance");
3769
+ else if (k.kind === "AUTONUMBER")
3770
+ h("MERMAID_SEQUENCE_AUTONUMBER", "Message numbers are omitted.", "appearance");
3771
+ else if (k.kind === "RECT_START" || k.kind === "RECT_END")
3772
+ h("MERMAID_SEQUENCE_RECT", "Background rectangles are omitted.", "appearance");
3773
+ else {
3774
+ const S = Zi[k.kind], D = y.get(k.from ?? ""), _ = y.get(k.to ?? "");
3775
+ if (!S || !D || !_ || k.central) {
3776
+ n.push({
3777
+ code: "MERMAID_SEQUENCE_ARROW_UNSUPPORTED",
3778
+ severity: "error",
3779
+ impact: "semantics",
3780
+ message: "Message line type is unsupported: " + (k.central ? "central connection" : k.kind) + ". The import is blocked rather than replacing it with an ordinary arrow."
3781
+ });
3782
+ continue;
3783
+ }
3784
+ k.kind === "SOLID_POINT" && h(
3785
+ "MERMAID_SEQUENCE_ASYNC_ARROW",
3786
+ "The open async arrow `-)` becomes an ordinary solid message, because native async draws dashed."
3787
+ );
3788
+ const $ = r.get("edge-occurrence", String(M + 1), "m" + (o.edges.length + 1));
3789
+ o.edges.push({ id: $, from: D, to: _, label: t(k.text), directed: !0, ...S }), a?.members.push($), i = { id: $, ends: [k.from, k.to] };
3790
+ }
3791
+ return o.phases = w.filter((M) => M.members.length), o.notes = l, Eo("mermaid", "sequence", o, n, r);
3792
+ }
3793
+ const ta = {
3794
+ arrow_point: {},
3795
+ arrow_open: {},
3796
+ arrow_circle: { head: "circle" },
3797
+ arrow_cross: { head: "cross" },
3798
+ double_arrow_point: { tail: "arrow" },
3799
+ double_arrow_circle: { head: "circle", tail: "circle" },
3800
+ double_arrow_cross: { head: "cross", tail: "cross" }
3801
+ };
3802
+ function na(e, t, s = "Imported Mermaid") {
3803
+ const n = ko(s), o = new vo(), r = e.diagnostics.map((f) => ({
3804
+ code: f.code,
3805
+ severity: f.severity,
3806
+ impact: f.code.includes("LIMIT") || f.code.includes("TIMEOUT") ? "limit" : f.code.includes("CONFIGURATION") || f.code.includes("INTERACTION") ? "security" : "syntax",
3807
+ message: f.message + (f.locationKind === "parser-relative" && f.line != null ? ` (Parser-relative line ${f.line}, column ${f.column ?? 1}; original-source mapping is unavailable.)` : ""),
3808
+ ...f.locationKind === "source" && f.line != null ? { line: f.line, column: f.column } : {}
3809
+ })), d = (f, M, k = "appearance", S = "warning", D) => r.push({ code: f, message: M, impact: k, severity: S, ...D ? { foreignIds: D } : {} }), h = () => Eo("mermaid", "flowchart", n, r, o);
3810
+ if (!e.ok) return h();
3811
+ const c = e.snapshot;
3812
+ if (c.parserVersion !== cn)
3813
+ return d(
3814
+ "MERMAID_VERSION_MISMATCH",
3815
+ "This adapter is verified only against Mermaid " + cn + ".",
3816
+ "syntax",
3817
+ "error"
3818
+ ), h();
3819
+ if (c.family === "sequence")
3820
+ return ea(c, t, s, r);
3821
+ const y = (f, M, k) => (/<\/?[a-z][\s\S]*?>/i.test(f) && d(
3822
+ "MERMAID_HTML_LABEL",
3823
+ "HTML label formatting was reduced to plain text; line breaks are retained and no HTML is inserted into the diagram.",
3824
+ "appearance",
3825
+ "warning",
3826
+ [k]
3827
+ ), M === "markdown" && d(
3828
+ "MERMAID_MARKDOWN_LABEL",
3829
+ "Markdown label markers remain literal text in this profile.",
3830
+ "appearance",
3831
+ "warning",
3832
+ [k]
3833
+ ), t(f)), w = (f, M) => {
3834
+ if (f) {
3835
+ if (f === "LR") return "right";
3836
+ if (f === "TB" || f === "TD") return "down";
3837
+ if (f === "RL" || f === "BT")
3838
+ return d(
3839
+ "MERMAID_REVERSED_LAYOUT",
3840
+ `${f} layout is normalized to ${f === "RL" ? "right" : "down"}; edge endpoints keep their semantic order.`,
3841
+ "layout",
3842
+ "warning",
3843
+ [M]
3844
+ ), f === "RL" ? "right" : "down";
3845
+ d("MERMAID_DIRECTION", "Unsupported Mermaid layout direction: " + f, "layout", "error", [
3846
+ M
3847
+ ]);
3848
+ }
3849
+ }, l = new Map(c.classes.map((f) => [f.id, f])), p = (f, M, k, S) => {
3850
+ const D = [];
3851
+ for (const _ of [...k ? ["default", "node"] : [], ...f]) {
3852
+ const $ = l.get(_);
3853
+ $ ? D.push($) : ["default", "node", "clickable"].includes(_) || d(
3854
+ "MERMAID_CLASS_UNRESOLVED",
3855
+ "CSS class has no in-diagram definition and was not imported: " + _,
3856
+ "appearance",
3857
+ "warning",
3858
+ [S]
3859
+ );
3860
+ }
3861
+ return [...D.flatMap((_) => [..._.styles, ..._.textStyles]), ...M];
3862
+ }, a = (f, M, k) => {
3863
+ const S = /* @__PURE__ */ new Map();
3864
+ for (const D of M.flatMap((_) => _.split(";"))) {
3865
+ if (!D.trim()) continue;
3866
+ const _ = /^\s*([a-z-]+)\s*:\s*(.*?)\s*$/i.exec(D), $ = _?.[1]?.toLowerCase(), x = _?.[2];
3867
+ if (!$ || !["fill", "stroke", "color"].includes($)) {
3868
+ d(
3869
+ "MERMAID_STYLE_PROPERTY",
3870
+ "Unsupported style declaration was omitted: " + D,
3871
+ /url\s*\(|javascript:|expression\s*\(/i.test(D) ? "security" : "appearance",
3872
+ "warning",
3873
+ [k]
3874
+ );
3875
+ continue;
3876
+ }
3877
+ const E = Qi(x);
3878
+ if (!E) {
3879
+ d(
3880
+ "MERMAID_COLOR_VALUE",
3881
+ "Only #RGB or #RRGGBB colors are imported: " + D,
3882
+ "appearance",
3883
+ "warning",
3884
+ [k]
3885
+ );
3886
+ continue;
3887
+ }
3888
+ S.set($, E);
3889
+ }
3890
+ Vi(n, f, S.get("fill"), S.get("stroke"), S.get("color"));
3891
+ }, i = {
3892
+ square: "box",
3893
+ rect: "box",
3894
+ rectangle: "box",
3895
+ box: "box",
3896
+ stadium: "pill",
3897
+ circle: "circle",
3898
+ diamond: "diamond",
3899
+ text: "text"
3900
+ }, g = (f, M) => {
3901
+ if (!f) return "box";
3902
+ if (Object.hasOwn(i, f)) return i[f];
3903
+ const k = f === "doublecircle" || f === "ellipse" ? "circle" : f === "round" ? "pill" : "box";
3904
+ return d(
3905
+ "MERMAID_SHAPE_APPROXIMATION",
3906
+ `Mermaid shape ${f} becomes native ${k}; the shape-specific visual meaning is not fully preserved.`,
3907
+ "semantics",
3908
+ "warning",
3909
+ [M]
3910
+ ), k;
3911
+ };
3912
+ try {
3913
+ const f = new Map(c.groups.map((x) => [x.id, x])), M = new Map(c.vertices.map((x) => [x.id, x]));
3914
+ if (f.size !== c.groups.length || M.size !== c.vertices.length)
3915
+ return d(
3916
+ "MERMAID_DUPLICATE_DB_ID",
3917
+ "The parser snapshot contains duplicate group or node identities.",
3918
+ "semantics",
3919
+ "error"
3920
+ ), h();
3921
+ const k = /* @__PURE__ */ new Map();
3922
+ for (const x of c.groups)
3923
+ k.set(x.id, {
3924
+ id: o.get("group", x.id),
3925
+ kind: "group",
3926
+ label: y(x.title, x.labelType, x.id)
3927
+ });
3928
+ for (const x of c.vertices)
3929
+ f.has(x.id) || k.set(x.id, {
3930
+ id: o.get("node", x.id),
3931
+ kind: "node",
3932
+ label: y(x.text, x.labelType, x.id),
3933
+ shape: g(x.type, x.id)
3934
+ });
3935
+ const S = /* @__PURE__ */ new Map();
3936
+ for (const x of c.groups)
3937
+ for (const E of x.nodes) {
3938
+ if (!k.has(E)) {
3939
+ d(
3940
+ "MERMAID_UNKNOWN_MEMBER",
3941
+ "Subgraph references an absent member: " + E,
3942
+ "semantics",
3943
+ "error",
3944
+ [x.id, E]
3945
+ );
3946
+ continue;
3947
+ }
3948
+ const v = S.get(E);
3949
+ if (v && v !== x.id) {
3950
+ d(
3951
+ "MERMAID_MULTIPLE_PARENTS",
3952
+ "A member belongs to multiple native parents; containment was not guessed.",
3953
+ "semantics",
3954
+ "error",
3955
+ [E, v, x.id]
3956
+ );
3957
+ continue;
3958
+ }
3959
+ S.set(E, x.id), k.get(E).parent = k.get(x.id).id;
3960
+ }
3961
+ const D = w(c.direction, "root");
3962
+ D && n.layouts.push({ scope: "root", kind: "flow", direction: D });
3963
+ const _ = /* @__PURE__ */ new Map();
3964
+ for (const x of c.groups) {
3965
+ const E = w(x.dir, x.id);
3966
+ E && _.set(x.id, E);
3967
+ }
3968
+ const $ = (x) => {
3969
+ const E = /* @__PURE__ */ new Set();
3970
+ let v = x;
3971
+ for (; v && !E.has(v); ) {
3972
+ E.add(v);
3973
+ const u = _.get(v);
3974
+ if (u) return u;
3975
+ v = S.get(v);
3976
+ }
3977
+ return D ?? "down";
3978
+ };
3979
+ for (const x of c.groups) {
3980
+ const E = k.get(x.id), v = M.get(x.id);
3981
+ a(
3982
+ E,
3983
+ p([...x.classes, ...v?.classes ?? []], v?.styles ?? [], !1, x.id),
3984
+ x.id
3985
+ ), n.layouts.push({
3986
+ scope: E.id,
3987
+ kind: "flow",
3988
+ direction: $(x.id)
3989
+ }), x.dir ? d(
3990
+ "MERMAID_SUBGRAPH_LAYOUT",
3991
+ "The native group retains its declared direction. Mermaid can ignore a subgraph direction when its members connect outside, so the resulting layout may differ.",
3992
+ "layout",
3993
+ "warning",
3994
+ [x.id]
3995
+ ) : d(
3996
+ "MERMAID_INHERITED_LAYOUT",
3997
+ "This group has no declared direction. Native flow layout uses the nearest declared ancestor/root direction; Mermaid can use another direction depending on its layout engine and external connections.",
3998
+ "layout",
3999
+ "warning",
4000
+ [x.id]
4001
+ ), x.metadata && Object.keys(x.metadata).length && d(
4002
+ "MERMAID_GROUP_METADATA",
4003
+ "Group metadata (including collapsed view and engine hints) is omitted: " + Object.keys(x.metadata).join(", "),
4004
+ "layout",
4005
+ "warning",
4006
+ [x.id]
4007
+ );
4008
+ }
4009
+ for (const x of c.vertices) {
4010
+ const E = k.get(x.id);
4011
+ f.has(x.id) || a(E, p(x.classes, x.styles, !0, x.id), x.id), x.link && d(
4012
+ "MERMAID_LINK_OMITTED",
4013
+ "External link was omitted; the native object has no active link.",
4014
+ "security",
4015
+ "warning",
4016
+ [x.id]
4017
+ ), (x.img || x.icon) && d(
4018
+ "MERMAID_ASSET_OMITTED",
4019
+ "Image/icon references are not fetched or embedded; the object remains a labeled native shape.",
4020
+ "security",
4021
+ "warning",
4022
+ [x.id]
4023
+ ), x.props && Object.keys(x.props).length && d(
4024
+ "MERMAID_NODE_METADATA",
4025
+ "Node properties are omitted: " + Object.keys(x.props).join(", "),
4026
+ "semantics",
4027
+ "warning",
4028
+ [x.id]
4029
+ );
4030
+ }
4031
+ n.objects.push(...k.values());
4032
+ for (const [x, E] of c.edges.entries()) {
4033
+ const v = ta[String(E.type)];
4034
+ if (!v) {
4035
+ d(
4036
+ "MERMAID_ARROW_UNSUPPORTED",
4037
+ "Edge terminal semantics are unsupported: " + String(E.type) + ". The import is blocked rather than replacing them with ordinary arrows.",
4038
+ "semantics",
4039
+ "error",
4040
+ [E.id ?? String(x + 1)]
4041
+ );
4042
+ continue;
4043
+ }
4044
+ if (E.stroke === "invisible") {
4045
+ d(
4046
+ "MERMAID_INVISIBLE_EDGE",
4047
+ "Invisible links express layout constraints, not visible relationships; this profile cannot preserve them.",
4048
+ "layout",
4049
+ "error",
4050
+ [E.id ?? String(x + 1)]
4051
+ );
4052
+ continue;
4053
+ }
4054
+ if (!["normal", "thick", "dotted"].includes(E.stroke ?? "normal")) {
4055
+ d(
4056
+ "MERMAID_EDGE_STROKE",
4057
+ "Unsupported edge stroke: " + String(E.stroke),
4058
+ "appearance",
4059
+ "error",
4060
+ [E.id ?? String(x + 1)]
4061
+ );
4062
+ continue;
4063
+ }
4064
+ const u = k.get(E.start), A = k.get(E.end);
4065
+ if (!u || !A) {
4066
+ d("MERMAID_ENDPOINT", "A parsed edge has a missing endpoint.", "semantics", "error", [
4067
+ E.start,
4068
+ E.end
4069
+ ]);
4070
+ continue;
4071
+ }
4072
+ const m = E.isUserDefinedId && E.id ? o.get("edge-id", E.id, E.id) : o.get("edge-occurrence", String(x + 1), "edge_" + (x + 1)), b = E.id ?? String(x + 1);
4073
+ n.edges.push({
4074
+ id: m,
4075
+ from: u.id,
4076
+ to: A.id,
4077
+ label: y(E.text, E.labelType, b),
4078
+ directed: E.type !== "arrow_open",
4079
+ ...v,
4080
+ ...E.stroke === "dotted" ? { dashed: !0 } : {}
4081
+ }), E.stroke === "dotted" && d(
4082
+ "MERMAID_DASH_STYLE",
4083
+ "Dotted Mermaid stroke uses native kind=async only for its dashed visual treatment; no asynchronous execution semantics are inferred.",
4084
+ "appearance",
4085
+ "info",
4086
+ [b]
4087
+ ), E.stroke === "thick" && d(
4088
+ "MERMAID_THICK_EDGE",
4089
+ "Thick edge emphasis is omitted by this native-source profile.",
4090
+ "appearance",
4091
+ "warning",
4092
+ [b]
4093
+ ), (E.length ?? 1) > 1 && d(
4094
+ "MERMAID_MIN_RANK_LENGTH",
4095
+ "Minimum rank-length hint is omitted; native layout chooses spacing.",
4096
+ "layout",
4097
+ "warning",
4098
+ [b]
4099
+ ), (E.animate || E.animation) && d("MERMAID_EDGE_ANIMATION", "Edge animation is omitted.", "appearance", "warning", [
4100
+ b
4101
+ ]), (E.interpolate || c.defaultEdgeInterpolate) && d(
4102
+ "MERMAID_EDGE_CURVE",
4103
+ "Mermaid curve hints are omitted; native routing is used.",
4104
+ "layout",
4105
+ "warning",
4106
+ [b]
4107
+ );
4108
+ const T = p(
4109
+ E.classes,
4110
+ [...c.defaultEdgeStyle, ...E.style],
4111
+ !1,
4112
+ b
4113
+ );
4114
+ T.length && d(
4115
+ "MERMAID_EDGE_STYLE",
4116
+ "Per-edge CSS is omitted because native edge appearance is not a general CSS style map: " + T.join("; "),
4117
+ "appearance",
4118
+ "warning",
4119
+ [b]
4120
+ );
4121
+ }
4122
+ return h();
4123
+ } catch (f) {
4124
+ return d(
4125
+ "MERMAID_MAPPING_ERROR",
4126
+ "Could not map the parser snapshot: " + (f instanceof Error ? f.message : String(f)),
4127
+ "semantics",
4128
+ "error"
4129
+ ), h();
4130
+ }
4131
+ }
4132
+ function sa(e, t, s) {
4133
+ const n = na(e, t, s);
4134
+ if (!n.nativeSource) return n;
4135
+ try {
4136
+ return si(n.nativeSource), n;
4137
+ } catch (o) {
4138
+ return {
4139
+ ...n,
4140
+ status: "failed",
4141
+ nativeSource: void 0,
4142
+ facts: void 0,
4143
+ diagnostics: [
4144
+ ...n.diagnostics,
4145
+ {
4146
+ code: "IMPORT_NATIVE_INVALID",
4147
+ severity: "error",
4148
+ impact: "semantics",
4149
+ message: "The converted diagram cannot be represented in native source: " + (o instanceof Error ? o.message : String(o))
4150
+ }
4151
+ ]
4152
+ };
4153
+ }
4154
+ }
4155
+ export {
4156
+ sa as importMermaidFlow
4157
+ };