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