@draftably/mermaid 0.2.1 → 0.2.2

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