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