yuhwa 1.5.0 → 1.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/astro.d.ts +1 -1
- package/dist/astro.js +1 -1
- package/dist/browser.d.ts +3 -3
- package/dist/browser.js +10 -7
- package/dist/canvas.js +1 -1
- package/dist/cli.js +32 -11
- package/dist/editor/assets/index-Dd3yJXpt.css +1 -0
- package/dist/editor/assets/index-DyXXchTq.js +689 -0
- package/dist/editor/assets/lsp.worker-BuZEbjK9.js +36 -0
- package/dist/editor/index.html +68 -57
- package/dist/{figure-BXrdbiqy.d.ts → figure-BtRpJvZ9.d.ts} +1 -1
- package/dist/{index-DVU2kSdX.d.ts → index-C6v0NhkF.d.ts} +35 -2
- package/dist/index.d.ts +3 -3
- package/dist/index.js +5 -5
- package/dist/ironmark.d.ts +1 -1
- package/dist/ironmark.js +1 -1
- package/dist/llms.txt +4 -4
- package/dist/lsp-browser.js +1 -1
- package/dist/lsp-node.js +20 -13
- package/dist/lsp-server.js +1 -1
- package/dist/lsp.js +1 -1
- package/dist/markdown-it.d.ts +1 -1
- package/dist/markdown-it.js +2 -2
- package/dist/{node-B8dLsEzl.js → node-Cdzt2Mis.js} +6 -6
- package/dist/{parse-CD6SmUc1.js → parse-fnqTkelX.js} +120 -42
- package/dist/{plugin-Dq5VmHe8.js → plugin-DX1Pv2Tq.js} +1 -1
- package/dist/{plugin-Dj66dvC1.d.ts → plugin-DhSeDLo1.d.ts} +43 -27
- package/dist/plugin.d.ts +1 -1
- package/dist/plugin.js +2 -2
- package/dist/{raster-Cul5L1bT.js → raster-B_SJsm-q.js} +3 -3
- package/dist/remark.d.ts +1 -1
- package/dist/remark.js +1 -1
- package/dist/satteri.d.ts +1 -1
- package/dist/satteri.js +1 -1
- package/dist/{server-DCZj9bmz.js → server-BW2tKjSu.js} +6 -3
- package/dist/{service-Cno307YA.js → service-CXRIavFP.js} +18 -14
- package/dist/{shared-DgVcoAJb.js → shared-DJCDEbFf.js} +1877 -1312
- package/dist/{src-CBd46GH5.js → src-CQ8ltV_K.js} +1906 -1267
- package/dist/vite.d.ts +1 -1
- package/dist/vite.js +3 -3
- package/dist/vuepress.d.ts +1 -1
- package/dist/vuepress.js +1 -1
- package/dist/yuhwa.iife.js +54 -54
- package/dist/{zoom-yxhxX16c.js → zoom-D3Lahr1T.js} +1 -1
- package/dist/{zoom-script-CaJ5MNUw.js → zoom-script-DPxmav2F.js} +1 -1
- package/dist/zoom.js +2 -2
- package/package.json +1 -1
- package/dist/editor/assets/index-BAdhu8vV.js +0 -689
- package/dist/editor/assets/index-DaWl0OPj.css +0 -1
- package/dist/editor/assets/lsp.worker-PVetuBwo.js +0 -36
|
@@ -347,7 +347,7 @@ function cssHex(v) {
|
|
|
347
347
|
const fn = c.match(/^(rgba?|hsla?)\(\s*([^)]*)\)$/);
|
|
348
348
|
if (fn) {
|
|
349
349
|
const a = fn[2].split(/\s*[,/]\s*|\s+/).filter(Boolean);
|
|
350
|
-
if (a.length < 3 || a.slice(0, 3).some((x) => !Number.isFinite(parseFloat(x)))) return
|
|
350
|
+
if (a.length < 3 || a.slice(0, 3).some((x) => !Number.isFinite(parseFloat(x)))) return;
|
|
351
351
|
if (fn[1].startsWith("rgb")) return "#" + a.slice(0, 3).map((x) => hex2(channel(x, 255))).join("");
|
|
352
352
|
const hue = (parseFloat(a[0]) % 360 + 360) % 360 / 360;
|
|
353
353
|
const sat = Math.min(1, channel(a[1], 1) / (a[1].endsWith("%") ? 1 : 100));
|
|
@@ -383,7 +383,7 @@ const mix = (a, b, t) => {
|
|
|
383
383
|
/** colours for any CSS colour (not a palette name): a tint of it on the theme background */
|
|
384
384
|
function hexTone(css, theme, group) {
|
|
385
385
|
const c = cssHex(css);
|
|
386
|
-
if (!c) return
|
|
386
|
+
if (!c) return;
|
|
387
387
|
const bg = HEX_RE.test(theme.background) ? theme.background : theme.dark ? "#000000" : "#ffffff";
|
|
388
388
|
const tint = theme.dark ? group ? .14 : .22 : group ? .07 : .12;
|
|
389
389
|
return {
|
|
@@ -419,12 +419,6 @@ const GENERIC_FONT = /^(serif|sans-serif|monospace|cursive|fantasy|math|emoji|sy
|
|
|
419
419
|
const isGenericFont = (family) => GENERIC_FONT.test(family);
|
|
420
420
|
/** the family names of a CSS font stack, unquoted */
|
|
421
421
|
const fontFamilies = (stack) => stack.split(",").map((f) => f.trim().replace(/^(['"])(.*)\1$/, "$2")).filter(Boolean);
|
|
422
|
-
/**
|
|
423
|
-
* a font setting as a CSS font stack: a family name or a fallback list such
|
|
424
|
-
* as `Lora, Georgia, serif`. `sans`, `serif` and `mono` expand to their
|
|
425
|
-
* stacks; a list that ends without a generic family gets one that matches
|
|
426
|
-
* the first font
|
|
427
|
-
*/
|
|
428
422
|
function fontStack(font) {
|
|
429
423
|
const names = font.split(",").map((f) => f.trim()).filter(Boolean);
|
|
430
424
|
const first = fontFamilies(font)[0] ?? "sans";
|
|
@@ -438,6 +432,17 @@ function fontStack(font) {
|
|
|
438
432
|
};
|
|
439
433
|
}
|
|
440
434
|
/**
|
|
435
|
+
* An element's or a span's `font` as a stack: `sans`, `serif`, `mono` or font
|
|
436
|
+
* names. Undefined when unset, or when it holds more than names, quotes and commas.
|
|
437
|
+
*/
|
|
438
|
+
function textFamily(v) {
|
|
439
|
+
if (!v || !/^[\w\s'",.-]+$/.test(v)) return;
|
|
440
|
+
let stack = FAMILIES.get(v);
|
|
441
|
+
if (!stack) FAMILIES.set(v, stack = fontStack(v));
|
|
442
|
+
return stack;
|
|
443
|
+
}
|
|
444
|
+
const FAMILIES = /* @__PURE__ */ new Map();
|
|
445
|
+
/**
|
|
441
446
|
* The keys a `theme name { … }` block (or `createTheme`) takes. Colours take
|
|
442
447
|
* palette names (`slate-800`) or any CSS colour.
|
|
443
448
|
*/
|
|
@@ -654,7 +659,7 @@ const isColor = (v) => {
|
|
|
654
659
|
const COLOR_TOKEN = String.raw`#[0-9a-fA-F]{3,8}|(?:rgba?|hsla?)\([^)]*\)|[a-zA-Z][\w-]*`;
|
|
655
660
|
/** Resolve a colour value: tone names (`blue`, `blue-500`) or any CSS colour. */
|
|
656
661
|
function resolveColor(v, theme, fallbackLevel) {
|
|
657
|
-
if (!v) return
|
|
662
|
+
if (!v) return;
|
|
658
663
|
const m = v.match(/^([a-z]+)(?:-(\d{2,3}))?$/);
|
|
659
664
|
if (m && RAMPS[m[1]]) {
|
|
660
665
|
const lvl = m[2] ? Number(m[2]) : fallbackLevel;
|
|
@@ -722,6 +727,15 @@ const SPAN_KEYS = table({
|
|
|
722
727
|
"900"
|
|
723
728
|
]
|
|
724
729
|
},
|
|
730
|
+
font: {
|
|
731
|
+
aliases: ["family", "font-family"],
|
|
732
|
+
info: "font: sans, serif, mono or a font name",
|
|
733
|
+
values: [
|
|
734
|
+
"sans",
|
|
735
|
+
"serif",
|
|
736
|
+
"mono"
|
|
737
|
+
]
|
|
738
|
+
},
|
|
725
739
|
italic: {
|
|
726
740
|
aliases: [],
|
|
727
741
|
info: "italic text",
|
|
@@ -760,6 +774,11 @@ function parseSpanStyle(spec) {
|
|
|
760
774
|
} else if (k === "color") {
|
|
761
775
|
if (!isColor(v)) return;
|
|
762
776
|
st.color = v;
|
|
777
|
+
} else if (k === "font") {
|
|
778
|
+
const fam = textFamily(v);
|
|
779
|
+
if (!fam) return;
|
|
780
|
+
st.font = fam.font;
|
|
781
|
+
st.mono = fam.mono;
|
|
763
782
|
} else {
|
|
764
783
|
const n = parseFloat(v);
|
|
765
784
|
if (!(n > 0 && n <= 1e3)) return;
|
|
@@ -897,7 +916,7 @@ const textLines = (lines, x, y, body) => lines.map((l, i) => `<tspan x="${f$1(x)
|
|
|
897
916
|
*/
|
|
898
917
|
function richText(line, col, theme, caps = false) {
|
|
899
918
|
const segs = richSegs(line, caps);
|
|
900
|
-
if (segs.every((x) => x.kind === "text")) return esc
|
|
919
|
+
if (segs.every((x) => x.kind === "text")) return esc(plain(segs));
|
|
901
920
|
return tspans(segs, col, theme);
|
|
902
921
|
}
|
|
903
922
|
/** the text without markup */
|
|
@@ -911,7 +930,9 @@ function dedent(lines) {
|
|
|
911
930
|
while (lines.length && !lines[lines.length - 1].trim()) lines.pop();
|
|
912
931
|
return lines.map((l) => l.slice(cut).replace(/\t/g, " "));
|
|
913
932
|
}
|
|
914
|
-
const esc
|
|
933
|
+
const esc = (s) => s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
934
|
+
/** ` font-style` and ` font-family` for a text's own italic and `font`; nothing when it follows the theme */
|
|
935
|
+
const fontAttrs = (italic, family) => (italic ? " font-style=\"italic\"" : "") + (family ? ` font-family="${esc(family)}"` : "");
|
|
915
936
|
const f$1 = (n) => (Math.round(n * 100) / 100).toString();
|
|
916
937
|
/** a single-line `<text>` centred vertically on `y` */
|
|
917
938
|
const textEl = (x, y, fs, fill, body, extra = "") => `<text x="${f$1(x)}" y="${f$1(y)}" dominant-baseline="central" font-size="${f$1(fs)}" fill="${fill}"${extra}>${body}</text>`;
|
|
@@ -924,7 +945,7 @@ function segsW(segs, fs, mono, m, weight = 400) {
|
|
|
924
945
|
let total = 0;
|
|
925
946
|
for (const s of segs) {
|
|
926
947
|
const size = s.size ?? fs;
|
|
927
|
-
const w = m(s.text, size, segWeight(s, weight), mono);
|
|
948
|
+
const w = m(s.text, size, segWeight(s, weight), s.mono ?? mono);
|
|
928
949
|
s.w = s.kind === "chip" ? w + size * CHIP_PAD * 2 : w;
|
|
929
950
|
total += s.w;
|
|
930
951
|
}
|
|
@@ -951,11 +972,11 @@ function renderSegs(segs, x, cy, fs, col, theme, muted = false, weight = 400) {
|
|
|
951
972
|
const ch = fs * 1.6;
|
|
952
973
|
const fill = s.color && c.startsWith("#") && c.length === 7 ? `${c}1f` : "none";
|
|
953
974
|
out.push(`<rect x="${f$1(x)}" y="${f$1(cy - ch / 2)}" width="${f$1(w)}" height="${f$1(ch)}" rx="4" fill="${fill}" stroke="${s.color ? c : col.stroke}" stroke-width="1"/>`);
|
|
954
|
-
out.push(textEl(x + fs * CHIP_PAD, cy, fs, s.color ? c : col.text, esc
|
|
975
|
+
out.push(textEl(x + fs * CHIP_PAD, cy, fs, s.color ? c : col.text, esc(s.text), " xml:space=\"preserve\""));
|
|
955
976
|
} else {
|
|
956
977
|
const wt = segWeight(s, weight);
|
|
957
|
-
const it = s.italic
|
|
958
|
-
out.push(textEl(x, cy, s.size ?? fs, c, esc
|
|
978
|
+
const it = fontAttrs(s.italic, s.font);
|
|
979
|
+
out.push(textEl(x, cy, s.size ?? fs, c, esc(s.text), ` xml:space="preserve"${wt !== 400 ? ` font-weight="${wt}"` : ""}${it}`));
|
|
959
980
|
if (s.kind === "strike") {
|
|
960
981
|
const lead = s.text.length - s.text.trimStart().length;
|
|
961
982
|
const x0 = x + w * lead / Math.max(1, s.text.length);
|
|
@@ -977,9 +998,10 @@ function tspans(segs, col, theme, muted = false) {
|
|
|
977
998
|
if (s.weight) a.push(`font-weight="${s.weight}"`);
|
|
978
999
|
else if (s.kind === "bold") a.push("font-weight=\"750\"");
|
|
979
1000
|
if (s.italic) a.push("font-style=\"italic\"");
|
|
1001
|
+
if (s.font) a.push(`font-family="${esc(s.font)}"`);
|
|
980
1002
|
if (s.kind === "strike") a.push("text-decoration=\"line-through\"");
|
|
981
1003
|
if (s.kind === "chip") a.push("font-weight=\"600\"");
|
|
982
|
-
return `<tspan ${a.join(" ")}>${esc
|
|
1004
|
+
return `<tspan ${a.join(" ")}>${esc(s.text)}</tspan>`;
|
|
983
1005
|
}).join("");
|
|
984
1006
|
}
|
|
985
1007
|
// src/core/style.ts
|
|
@@ -1032,14 +1054,18 @@ const posNum = (v) => {
|
|
|
1032
1054
|
const n = num$1(v, NaN);
|
|
1033
1055
|
return n > 0 ? n : void 0;
|
|
1034
1056
|
};
|
|
1035
|
-
|
|
1036
|
-
const
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1057
|
+
const textFont = (p, size, weight, theme) => {
|
|
1058
|
+
const family = textFamily(p.font);
|
|
1059
|
+
return {
|
|
1060
|
+
size: posNum(p["font-size"]) ?? size,
|
|
1061
|
+
weight: posNum(p["font-weight"]) ?? weight,
|
|
1062
|
+
italic: bool(p.italic, false),
|
|
1063
|
+
family: family?.font,
|
|
1064
|
+
mono: family?.mono ?? theme.mono
|
|
1065
|
+
};
|
|
1066
|
+
};
|
|
1041
1067
|
/** an edge label's font */
|
|
1042
|
-
const edgeFont = (p, theme) => textFont(p, theme.fontSize * .86, 500);
|
|
1068
|
+
const edgeFont = (p, theme) => textFont(p, theme.fontSize * .86, 500, theme);
|
|
1043
1069
|
/** Merge class props then own props (own wins). */
|
|
1044
1070
|
function effectiveProps(d, decl) {
|
|
1045
1071
|
const out = {};
|
|
@@ -1061,7 +1087,7 @@ function resolveNodeStyle(d, n, p, theme) {
|
|
|
1061
1087
|
const fill = resolveColor(p.fill, theme, theme.dark ? 900 : 100) ?? tone?.fill ?? theme.node.fill;
|
|
1062
1088
|
const stroke = resolveColor(p.stroke, theme, 500) ?? tone?.stroke ?? theme.node.stroke;
|
|
1063
1089
|
const text = resolveColor(p.text, theme, theme.dark ? 100 : 800) ?? tone?.text ?? theme.node.text;
|
|
1064
|
-
const font = textFont(p, posNum(s["font-size"]) ?? theme.fontSize, 500);
|
|
1090
|
+
const font = textFont(p, posNum(s["font-size"]) ?? theme.fontSize, 500, theme);
|
|
1065
1091
|
const fontSize = font.size;
|
|
1066
1092
|
return {
|
|
1067
1093
|
fill,
|
|
@@ -1078,6 +1104,8 @@ function resolveNodeStyle(d, n, p, theme) {
|
|
|
1078
1104
|
bodyWeight: posNum(p["body-weight"]) ?? 400,
|
|
1079
1105
|
lineHeight: posNum(p["line-height"]) ?? 1.75,
|
|
1080
1106
|
italic: font.italic,
|
|
1107
|
+
family: font.family,
|
|
1108
|
+
mono: font.mono,
|
|
1081
1109
|
shadow: bool(p.shadow, bool(s.shadow, theme.shadow !== null)),
|
|
1082
1110
|
opacity: num$1(p.opacity, 1)
|
|
1083
1111
|
};
|
|
@@ -1156,6 +1184,8 @@ function resolveEdgeStyle(d, e, p, theme, defaultCurve) {
|
|
|
1156
1184
|
fontSize: font.size,
|
|
1157
1185
|
fontWeight: font.weight,
|
|
1158
1186
|
italic: font.italic,
|
|
1187
|
+
family: font.family,
|
|
1188
|
+
mono: font.mono,
|
|
1159
1189
|
labelBg: resolveColor(p["label-bg"], theme, theme.dark ? 900 : 50) ?? theme.edge.labelBg,
|
|
1160
1190
|
flow,
|
|
1161
1191
|
opacity: num$1(p.opacity, 1)
|
|
@@ -1290,7 +1320,7 @@ function routeEdges(d, nodes, ctx) {
|
|
|
1290
1320
|
const lanes = bundle.map((k) => {
|
|
1291
1321
|
const x = edgeByKey.get(k);
|
|
1292
1322
|
const font = x?.label ? edgeFont(effectiveProps(d, x), ctx.theme) : void 0;
|
|
1293
|
-
const w = font ? Math.max(...x.label.split("\n").map((t) => richW(t, font.size, font.weight,
|
|
1323
|
+
const w = font ? Math.max(...x.label.split("\n").map((t) => richW(t, font.size, font.weight, font.mono, ctx.measure))) + 18 : 0;
|
|
1294
1324
|
return Math.max(fanGap, Math.abs(dir.y) * w + Math.abs(dir.x) * fanGap + 6);
|
|
1295
1325
|
});
|
|
1296
1326
|
const total = lanes.reduce((x, y) => x + y, 0);
|
|
@@ -1955,11 +1985,13 @@ const PLACEMENT_PROPS = [
|
|
|
1955
1985
|
];
|
|
1956
1986
|
/**
|
|
1957
1987
|
* Text props every element takes: nodes (label), edges (label), groups and
|
|
1958
|
-
* panels (title).
|
|
1988
|
+
* panels (title). `font` takes `sans`, `serif`, `mono` or font names. Inline
|
|
1989
|
+
* `{color: …, size: …, weight: …, font: …, italic | text}` spans
|
|
1959
1990
|
* style part of a text.
|
|
1960
1991
|
*/
|
|
1961
1992
|
const TEXT_PROPS = [
|
|
1962
1993
|
"text",
|
|
1994
|
+
"font",
|
|
1963
1995
|
"font-size",
|
|
1964
1996
|
"font-weight",
|
|
1965
1997
|
"italic"
|
|
@@ -2048,8 +2080,18 @@ const PANEL_PROPS = [
|
|
|
2048
2080
|
"shadow",
|
|
2049
2081
|
"frame",
|
|
2050
2082
|
"edge-color",
|
|
2051
|
-
"edge-width"
|
|
2083
|
+
"edge-width",
|
|
2084
|
+
"width",
|
|
2085
|
+
"height"
|
|
2052
2086
|
];
|
|
2087
|
+
/** what a panel prop does, where the value alone does not say it (hover, the editor, the guide) */
|
|
2088
|
+
const PANEL_PROP_HELP = {
|
|
2089
|
+
width: "the smallest width of the panel's frame, in pixels",
|
|
2090
|
+
height: "the smallest height of the panel's frame, in pixels",
|
|
2091
|
+
frame: "`false` drops the box",
|
|
2092
|
+
theme: "a theme name",
|
|
2093
|
+
border: "`none`, a palette name or any CSS colour"
|
|
2094
|
+
};
|
|
2053
2095
|
/** allowed values for enum-like props */
|
|
2054
2096
|
const ENUMS = table({
|
|
2055
2097
|
shape: [...SHAPES$2, ...Object.keys(SHAPE_ALIASES)],
|
|
@@ -2401,7 +2443,7 @@ const SIDES = /* @__PURE__ */ new Set([
|
|
|
2401
2443
|
]);
|
|
2402
2444
|
const IDENT_RE = /^[\p{L}_][\p{L}\p{N}_]*(?:-[\p{L}\p{N}_]+)*/u;
|
|
2403
2445
|
const ARROW_RE = /^(<)?(--|-|\.\.|==|=)(>)?/;
|
|
2404
|
-
const CLASS_RE$
|
|
2446
|
+
const CLASS_RE$3 = /^\.[\p{L}_][\p{L}\p{N}_-]*/u;
|
|
2405
2447
|
const NUMBER_RE = /^-?\d+(?:\.\d+)?/;
|
|
2406
2448
|
function unescape(s) {
|
|
2407
2449
|
return s.replace(/\\(n|t|"|'|\\)/g, (_, c) => c === "n" ? "\n" : c === "t" ? " " : c);
|
|
@@ -2466,7 +2508,7 @@ function lex(line) {
|
|
|
2466
2508
|
i += m[0].length;
|
|
2467
2509
|
continue;
|
|
2468
2510
|
}
|
|
2469
|
-
if (m = rest.match(CLASS_RE$
|
|
2511
|
+
if (m = rest.match(CLASS_RE$3)) {
|
|
2470
2512
|
tokens.push({
|
|
2471
2513
|
kind: "class",
|
|
2472
2514
|
value: m[0].slice(1),
|
|
@@ -2612,7 +2654,7 @@ function parseProps(raw = "") {
|
|
|
2612
2654
|
return out;
|
|
2613
2655
|
}
|
|
2614
2656
|
/** `text // comment` → `text`; a search for one fixed-width mark, so a long whitespace run stays linear */
|
|
2615
|
-
const stripComment = (s) => {
|
|
2657
|
+
const stripComment$1 = (s) => {
|
|
2616
2658
|
const i = s.search(/\s\/\//);
|
|
2617
2659
|
return i < 0 ? s : s.slice(0, i).trimEnd();
|
|
2618
2660
|
};
|
|
@@ -2676,9 +2718,13 @@ function serializeProps(props) {
|
|
|
2676
2718
|
return Object.entries(props).map(([k, v]) => {
|
|
2677
2719
|
if (v === "true" && !TONE_SET.has(k) && !isShape(k) && !CURVES.has(k) && !isColor(k)) return k;
|
|
2678
2720
|
if (k === "color" && isColor(v) && !isShape(v) && !CURVES.has(v.toLowerCase()) && !/[;[\]]/.test(v)) return v;
|
|
2679
|
-
return `${k}: ${
|
|
2721
|
+
return `${k}: ${serializeValue(v)}`;
|
|
2680
2722
|
}).join(", ");
|
|
2681
2723
|
}
|
|
2724
|
+
/** a prop value as written after `key: `, quoted when it holds what parseProps splits on */
|
|
2725
|
+
function serializeValue(v) {
|
|
2726
|
+
return /[,;[\]"'()\n\r]|^\s|\s$|^$/.test(v) ? quote(v) : v;
|
|
2727
|
+
}
|
|
2682
2728
|
function arrowInfo(a) {
|
|
2683
2729
|
const m = a.match(ARROW_RE);
|
|
2684
2730
|
const start = !!m[1];
|
|
@@ -2891,11 +2937,17 @@ function parse(source, opts = {}) {
|
|
|
2891
2937
|
const named = a.match(/^([A-Za-z_]\w*)\s*[:=]\s*([\s\S]*)$/);
|
|
2892
2938
|
if (named && def.params.some((p) => p.name === named[1])) local[named[1]] = unquote(named[2]);
|
|
2893
2939
|
else if (pos < def.params.length) local[def.params[pos++].name] = unquote(a);
|
|
2894
|
-
else
|
|
2940
|
+
else {
|
|
2941
|
+
warn(li, `${def.name}() takes ${def.params.length} argument(s), got ${args.length}`, "error");
|
|
2942
|
+
return;
|
|
2943
|
+
}
|
|
2895
2944
|
}
|
|
2896
2945
|
for (const p of def.params) {
|
|
2897
2946
|
if (p.name in local) continue;
|
|
2898
|
-
if (p.default === void 0)
|
|
2947
|
+
if (p.default === void 0) {
|
|
2948
|
+
warn(li, `${def.name}(): missing argument "${p.name}" (${def.params.map((x) => x.name).join(", ")})`, "error");
|
|
2949
|
+
return;
|
|
2950
|
+
}
|
|
2899
2951
|
local[p.name] = p.default;
|
|
2900
2952
|
}
|
|
2901
2953
|
const open = stack.length;
|
|
@@ -2914,11 +2966,17 @@ function parse(source, opts = {}) {
|
|
|
2914
2966
|
};
|
|
2915
2967
|
/** one source line: variables, components, then the statement itself */
|
|
2916
2968
|
const step = (raw0, li, done = false, scope = defs) => {
|
|
2917
|
-
if (/^\s*#(\s|$)/.test(raw0))
|
|
2969
|
+
if (/^\s*#(\s|$)/.test(raw0)) {
|
|
2970
|
+
warn(li, "Comments start with \"//\", not \"#\"", "error");
|
|
2971
|
+
return;
|
|
2972
|
+
}
|
|
2918
2973
|
const top = stack[stack.length - 1];
|
|
2919
2974
|
if (top?.kind === "def") {
|
|
2920
2975
|
for (const b of blockBraces(lex(raw0).tokens)) top.depth += b === "{" ? 1 : -1;
|
|
2921
|
-
if (top.depth > 0)
|
|
2976
|
+
if (top.depth > 0) {
|
|
2977
|
+
top.lines.push(raw0);
|
|
2978
|
+
return;
|
|
2979
|
+
}
|
|
2922
2980
|
stack.pop();
|
|
2923
2981
|
if (raw0.trim() !== "}") warn(li, `Expected "}" alone on the line that closes ${top.id}()`, "error");
|
|
2924
2982
|
const params = top.params;
|
|
@@ -2938,7 +2996,7 @@ function parse(source, opts = {}) {
|
|
|
2938
2996
|
if (!verbatim && top?.kind !== "layout") {
|
|
2939
2997
|
const v = raw0.match(VAR_DEF_RE);
|
|
2940
2998
|
if (v) {
|
|
2941
|
-
vars[v[1]] = unquote(stripComment(done ? v[2] : substitute(v[2], li)).trimEnd());
|
|
2999
|
+
vars[v[1]] = unquote(stripComment$1(done ? v[2] : substitute(v[2], li)).trimEnd());
|
|
2942
3000
|
(d.varLines ??= {})[v[1]] = li;
|
|
2943
3001
|
return;
|
|
2944
3002
|
}
|
|
@@ -2963,7 +3021,7 @@ function parse(source, opts = {}) {
|
|
|
2963
3021
|
});
|
|
2964
3022
|
return;
|
|
2965
3023
|
}
|
|
2966
|
-
const c = stripComment(raw0).match(CALL_RE);
|
|
3024
|
+
const c = stripComment$1(raw0).match(CALL_RE);
|
|
2967
3025
|
if (c) {
|
|
2968
3026
|
const def = scope[c[1]] ?? defs[c[1]];
|
|
2969
3027
|
if (def) {
|
|
@@ -2971,7 +3029,10 @@ function parse(source, opts = {}) {
|
|
|
2971
3029
|
expand(def, done ? c[2] : substitute(c[2], li), li);
|
|
2972
3030
|
return;
|
|
2973
3031
|
}
|
|
2974
|
-
if (!lex(raw0).tokens.some((x) => x.kind === "arrow"))
|
|
3032
|
+
if (!lex(raw0).tokens.some((x) => x.kind === "arrow")) {
|
|
3033
|
+
warn(li, `Unknown component "${c[1]}"${didYouMean(c[1], Object.keys(defs))}`, "error");
|
|
3034
|
+
return;
|
|
3035
|
+
}
|
|
2975
3036
|
}
|
|
2976
3037
|
}
|
|
2977
3038
|
const raw = done || top?.kind === "layout" || !verbatim && /^\s*(import|export)\b/.test(raw0) ? raw0 : substitute(raw0, li, void 0, verbatim);
|
|
@@ -3020,7 +3081,10 @@ function parse(source, opts = {}) {
|
|
|
3020
3081
|
return;
|
|
3021
3082
|
}
|
|
3022
3083
|
const m = code.match(/^([A-Za-z][\w-]*)\s*:\s*(.*)$/);
|
|
3023
|
-
if (!m)
|
|
3084
|
+
if (!m) {
|
|
3085
|
+
warn(li, `Expected "key: value" in theme ${top.id} (keys: ${THEME_KEY_NAMES.join(", ")})`, "error");
|
|
3086
|
+
return;
|
|
3087
|
+
}
|
|
3024
3088
|
themeProp(top.props, m[1].toLowerCase(), unquote(m[2].trim()), li);
|
|
3025
3089
|
};
|
|
3026
3090
|
const layoutLine = (raw, li) => {
|
|
@@ -3036,7 +3100,11 @@ function parse(source, opts = {}) {
|
|
|
3036
3100
|
};
|
|
3037
3101
|
const closeBlock = (li) => {
|
|
3038
3102
|
if (!stack.length) warn(li, "Unmatched \"}\"", "error");
|
|
3039
|
-
else
|
|
3103
|
+
else {
|
|
3104
|
+
const top = stack.pop();
|
|
3105
|
+
const g = top.kind === "group" ? d.groups.get(top.id) : void 0;
|
|
3106
|
+
if (g?.ref) g.ref.end = li;
|
|
3107
|
+
}
|
|
3040
3108
|
lastDecl = null;
|
|
3041
3109
|
};
|
|
3042
3110
|
/** import "./shared.yu" | import { api, db as store, .svc } from "./shared.yu" */
|
|
@@ -3082,12 +3150,15 @@ function parse(source, opts = {}) {
|
|
|
3082
3150
|
if (t[k]?.value === "{") {
|
|
3083
3151
|
k++;
|
|
3084
3152
|
if (t[k]?.value === "}") k++;
|
|
3085
|
-
else if (k === t.length)
|
|
3086
|
-
|
|
3087
|
-
|
|
3088
|
-
|
|
3089
|
-
|
|
3090
|
-
|
|
3153
|
+
else if (k === t.length) {
|
|
3154
|
+
stack.push({
|
|
3155
|
+
kind: "theme",
|
|
3156
|
+
id: t[1].value,
|
|
3157
|
+
start: li,
|
|
3158
|
+
props
|
|
3159
|
+
});
|
|
3160
|
+
return;
|
|
3161
|
+
}
|
|
3091
3162
|
}
|
|
3092
3163
|
if (k < t.length) warn(li, `Unexpected "${t[k].value}" in theme ${t[1].value}`, "error");
|
|
3093
3164
|
defineTheme(t[1].value, props, li);
|
|
@@ -3205,6 +3276,7 @@ function parse(source, opts = {}) {
|
|
|
3205
3276
|
k++;
|
|
3206
3277
|
const close = t.findIndex((x, idx) => idx >= k && x.value === "}");
|
|
3207
3278
|
if (close >= 0) {
|
|
3279
|
+
ref.end = li;
|
|
3208
3280
|
for (let j = k; j < close; j++) if (t[j].kind === "ident") {
|
|
3209
3281
|
const n = touchNode(t[j].value);
|
|
3210
3282
|
n.group = id;
|
|
@@ -3360,17 +3432,23 @@ function parse(source, opts = {}) {
|
|
|
3360
3432
|
const { tokens: t, codeEnd } = lex(raw);
|
|
3361
3433
|
if (!t.length) return;
|
|
3362
3434
|
const foreign = /^\s*%%/.test(raw) ? "Comments start with //" : /(--|==|-\.|->|=>)\|[^|]*\|/.test(raw) ? "Edge labels go after a colon: a -> b: label" : void 0;
|
|
3363
|
-
if (foreign)
|
|
3435
|
+
if (foreign) {
|
|
3436
|
+
warn(li, foreign, "error");
|
|
3437
|
+
return;
|
|
3438
|
+
}
|
|
3364
3439
|
if (t[0].kind === "punct" && t[0].value === "}") return closeBlock(li);
|
|
3365
3440
|
const head = t[0].kind === "ident" ? t[0].value : void 0;
|
|
3366
3441
|
const selective = t[1]?.value === "{" && t.some((x) => x.kind === "ident" && x.value === "from");
|
|
3367
3442
|
if (head === "import" && (t[1]?.kind === "string" || t.length === 1 || selective)) return importStmt(t, li, selective);
|
|
3368
3443
|
if (head === "export" && t.length > 1 && t[1].kind !== "arrow" && t[1].value !== ":") return exportStmt(t, raw, li);
|
|
3369
3444
|
const stmt = head !== void 0 ? STATEMENTS.get(head) : void 0;
|
|
3370
|
-
if (stmt && t[1]?.kind !== "arrow" && t[1]?.value !== ":" && t[1]?.value !== ",")
|
|
3371
|
-
|
|
3372
|
-
|
|
3373
|
-
|
|
3445
|
+
if (stmt && t[1]?.kind !== "arrow" && t[1]?.value !== ":" && t[1]?.value !== ",") {
|
|
3446
|
+
stmt.parse(raw.slice(t[0].end, codeEnd).trim(), d, {
|
|
3447
|
+
line: li,
|
|
3448
|
+
warn: (msg, sev) => warn(li, msg, sev)
|
|
3449
|
+
});
|
|
3450
|
+
return;
|
|
3451
|
+
}
|
|
3374
3452
|
if (head === "theme" && t[1]?.kind === "ident" && (t[2]?.kind === "props" || t[2]?.value === "{")) return themeStmt(t, li);
|
|
3375
3453
|
const opensBlock = t[t.length - 1].value === "{";
|
|
3376
3454
|
if (head !== void 0 && t.length > 2 && !PANELS.has(head) && t[1].kind === "ident" && opensBlock && head !== "group" && head !== "layout") unknownPanelHint(t, li);
|
|
@@ -4881,7 +4959,7 @@ const progress = {
|
|
|
4881
4959
|
const ty = box.y + lh + fs * .05;
|
|
4882
4960
|
const th = fs * .42;
|
|
4883
4961
|
const c = toneOf(r.color, ctx);
|
|
4884
|
-
return renderSegs(r.label, box.x, cy, fs, col, theme) + textEl(box.x + box.w, cy, fs, col.sub, esc
|
|
4962
|
+
return renderSegs(r.label, box.x, cy, fs, col, theme) + textEl(box.x + box.w, cy, fs, col.sub, esc(r.value), " text-anchor=\"end\" font-weight=\"600\"") + `<rect x="${f$1(box.x)}" y="${f$1(ty)}" width="${f$1(box.w)}" height="${f$1(th)}" rx="${f$1(th / 2)}" fill="${col.stroke}" fill-opacity="0.45"/>` + (r.ratio > 0 ? `<rect x="${f$1(box.x)}" y="${f$1(ty)}" width="${f$1(Math.max(th, box.w * r.ratio))}" height="${f$1(th)}" rx="${f$1(th / 2)}" fill="${c}"/>` : "");
|
|
4885
4963
|
}
|
|
4886
4964
|
};
|
|
4887
4965
|
const STAT_BIG = 1.75;
|
|
@@ -5038,7 +5116,7 @@ const browser = {
|
|
|
5038
5116
|
const ph = fs * 1.35;
|
|
5039
5117
|
const py = b.y + (h - ph) / 2;
|
|
5040
5118
|
const sub = fs * .78;
|
|
5041
|
-
const pill = x1 - x0 > fs * 3 ? `<rect x="${f$1(x0)}" y="${f$1(py)}" width="${f$1(x1 - x0)}" height="${f$1(ph)}" rx="${f$1(ph / 2)}" fill="${theme.background === "none" ? theme.node.fill : theme.background}" stroke="${col.stroke}" stroke-width="1"/>` + (arg ? textEl(x0 + fs * .7, b.y + h / 2, sub, col.sub, esc
|
|
5119
|
+
const pill = x1 - x0 > fs * 3 ? `<rect x="${f$1(x0)}" y="${f$1(py)}" width="${f$1(x1 - x0)}" height="${f$1(ph)}" rx="${f$1(ph / 2)}" fill="${theme.background === "none" ? theme.node.fill : theme.background}" stroke="${col.stroke}" stroke-width="1"/>` + (arg ? textEl(x0 + fs * .7, b.y + h / 2, sub, col.sub, esc(arg)) : "") : "";
|
|
5042
5120
|
return `<g class="frame">${bar(b, fs, radius, col.stroke, theme.dark)}${pill}</g>`;
|
|
5043
5121
|
}
|
|
5044
5122
|
};
|
|
@@ -5047,7 +5125,7 @@ const titled = (name, prefix) => ({
|
|
|
5047
5125
|
inset: (fs) => ({ top: barH(fs) }),
|
|
5048
5126
|
render(b, { theme, col, arg, radius, fs }) {
|
|
5049
5127
|
const h = barH(fs);
|
|
5050
|
-
const t = arg ? textEl(b.x + b.w / 2, b.y + h / 2, fs * .78, col.sub, esc
|
|
5128
|
+
const t = arg ? textEl(b.x + b.w / 2, b.y + h / 2, fs * .78, col.sub, esc(prefix + arg), " text-anchor=\"middle\" font-weight=\"500\"") : "";
|
|
5051
5129
|
return `<g class="frame">${bar(b, fs, radius, col.stroke, theme.dark)}${t}</g>`;
|
|
5052
5130
|
}
|
|
5053
5131
|
});
|
|
@@ -5242,7 +5320,7 @@ const MSG_RE$1 = new RegExp(String.raw`^(${ID})\s*(-->|->|\.\.>|=>)\s*(${ID})\s*
|
|
|
5242
5320
|
/** `a -> b [red]: hi`: props before the colon, which messages do not take */
|
|
5243
5321
|
const MSG_PROPS_RE = new RegExp(String.raw`^(${ID}\s*(?:-->|->|\.\.>|=>)\s*${ID})\s*\[([^\]]*)\]\s*(?::\s*(.*))?$`, "u");
|
|
5244
5322
|
const LIST_RE = new RegExp(String.raw`^(participant|actor)\s+(${ID}(?:\s*,\s*${ID})+)$`, "u");
|
|
5245
|
-
const NOTE_RE = new RegExp(String.raw`^note\s+(${ID}(?:\s*,\s*${ID})*)\s*:\s*(.*)$`, "u");
|
|
5323
|
+
const NOTE_RE$3 = new RegExp(String.raw`^note\s+(${ID}(?:\s*,\s*${ID})*)\s*:\s*(.*)$`, "u");
|
|
5246
5324
|
const DIV_RE = /^(?:-{3,}|={2,})\s*(.*?)\s*(?:-{3,}|={2,})?$/;
|
|
5247
5325
|
/**
|
|
5248
5326
|
* Trailing props on a message or note: `[red]`, `[#f80]`, `[color: red,
|
|
@@ -5301,7 +5379,7 @@ function parseSeq(body, _props, warn) {
|
|
|
5301
5379
|
p.actor = m[1] === "actor";
|
|
5302
5380
|
p.list ??= i;
|
|
5303
5381
|
}
|
|
5304
|
-
else if (m = line.match(NOTE_RE)) {
|
|
5382
|
+
else if (m = line.match(NOTE_RE$3)) {
|
|
5305
5383
|
const over = m[1].split(",").map((s) => s.trim());
|
|
5306
5384
|
over.forEach(part);
|
|
5307
5385
|
const [text, p] = splitTail(m[2]);
|
|
@@ -5450,7 +5528,7 @@ function renderSeq(s, box, ctx) {
|
|
|
5450
5528
|
const tone = p.tone ? T.tone(p.tone) : void 0;
|
|
5451
5529
|
const w = g.widths[i];
|
|
5452
5530
|
const rx = p.actor ? boxH / 2 : Math.min(10, T.radius + 2);
|
|
5453
|
-
return `<rect x="${f$1(X(i) - w / 2)}" y="${f$1(y)}" width="${f$1(w)}" height="${f$1(boxH)}" rx="${f$1(rx)}" fill="${tone?.fill ?? T.node.fill}" stroke="${tone?.stroke ?? T.node.stroke}" stroke-width="${f$1(T.strokeWidth)}"/><text x="${f$1(X(i))}" y="${f$1(y + boxH / 2)}" dominant-baseline="central" text-anchor="middle" font-size="${f$1(ctx.fs)}" font-weight="600" fill="${tone?.text ?? T.node.text}">${esc
|
|
5531
|
+
return `<rect x="${f$1(X(i) - w / 2)}" y="${f$1(y)}" width="${f$1(w)}" height="${f$1(boxH)}" rx="${f$1(rx)}" fill="${tone?.fill ?? T.node.fill}" stroke="${tone?.stroke ?? T.node.stroke}" stroke-width="${f$1(T.strokeWidth)}"/><text x="${f$1(X(i))}" y="${f$1(y + boxH / 2)}" dominant-baseline="central" text-anchor="middle" font-size="${f$1(ctx.fs)}" font-weight="600" fill="${tone?.text ?? T.node.text}">${esc(p.label)}</text>`;
|
|
5454
5532
|
}).join("");
|
|
5455
5533
|
out.push(head(top), head(bottom));
|
|
5456
5534
|
let y = top + boxH + fs * .7;
|
|
@@ -5513,7 +5591,7 @@ function renderSeq(s, box, ctx) {
|
|
|
5513
5591
|
out.push(`<path d="M${f$1(box.x)},${f$1(cy)}H${f$1(box.x + box.w)}" stroke="${T.group.stroke}" stroke-width="1" stroke-dasharray="4 4"/>`);
|
|
5514
5592
|
if (tw) {
|
|
5515
5593
|
out.push(`<rect x="${f$1(cx - tw / 2)}" y="${f$1(cy - fs * .85)}" width="${f$1(tw)}" height="${f$1(fs * 1.7)}" rx="${f$1(fs * .85)}" fill="${T.background === "none" ? T.node.fill : T.background}" stroke="${T.group.stroke}" stroke-width="1"/>`);
|
|
5516
|
-
out.push(`<text x="${f$1(cx)}" y="${f$1(cy)}" dominant-baseline="central" text-anchor="middle" font-size="${f$1(fs * .92)}" font-weight="600" fill="${T.node.sub}">${esc
|
|
5594
|
+
out.push(`<text x="${f$1(cx)}" y="${f$1(cy)}" dominant-baseline="central" text-anchor="middle" font-size="${f$1(fs * .92)}" font-weight="600" fill="${T.node.sub}">${esc(st.text)}</text>`);
|
|
5517
5595
|
}
|
|
5518
5596
|
}
|
|
5519
5597
|
y += rh;
|
|
@@ -5733,7 +5811,7 @@ function renderTimeline(ev, box, ctx) {
|
|
|
5733
5811
|
out.push(`<path d="M${f$1(ax)},${f$1(box.y + fs * .5)}V${f$1(box.y + g.h - fs * .5)}" stroke="${axis}" stroke-width="2" stroke-linecap="round"/>`);
|
|
5734
5812
|
ev.forEach((e, i) => {
|
|
5735
5813
|
const y = box.y + fs * .5 + g.at[i];
|
|
5736
|
-
out.push(`<text x="${f$1(ax - 16)}" y="${f$1(y)}" dominant-baseline="central" text-anchor="end" font-size="${f$1(fs * .9)}" font-weight="600" fill="${inkColor(e.tone, T, T.node.sub)}">${esc
|
|
5814
|
+
out.push(`<text x="${f$1(ax - 16)}" y="${f$1(y)}" dominant-baseline="central" text-anchor="end" font-size="${f$1(fs * .9)}" font-weight="600" fill="${inkColor(e.tone, T, T.node.sub)}">${esc(e.when)}</text>`);
|
|
5737
5815
|
out.push(dot(ax, y, e));
|
|
5738
5816
|
out.push(text(ax + 20, y, e.title, fs, 600, "start", false));
|
|
5739
5817
|
e.details.forEach((d, k) => out.push(text(ax + 20, y + (k + 1) * fs * 1.45, d, fs * .92, 400, "start", true)));
|
|
@@ -5744,7 +5822,7 @@ function renderTimeline(ev, box, ctx) {
|
|
|
5744
5822
|
out.push(`<path d="M${f$1(box.x)},${f$1(ay)}H${f$1(box.x + box.w)}" stroke="${axis}" stroke-width="2" stroke-linecap="round"/>`);
|
|
5745
5823
|
ev.forEach((e, i) => {
|
|
5746
5824
|
const x = box.x + g.at[i];
|
|
5747
|
-
out.push(`<text x="${f$1(x)}" y="${f$1(box.y + fs * .5)}" dominant-baseline="central" font-size="${f$1(fs * .9)}" font-weight="600" fill="${inkColor(e.tone, T, T.node.sub)}">${esc
|
|
5825
|
+
out.push(`<text x="${f$1(x)}" y="${f$1(box.y + fs * .5)}" dominant-baseline="central" font-size="${f$1(fs * .9)}" font-weight="600" fill="${inkColor(e.tone, T, T.node.sub)}">${esc(e.when)}</text>`);
|
|
5748
5826
|
out.push(dot(x + fs * .42, ay, e));
|
|
5749
5827
|
out.push(text(x, ay + fs * 1.55, e.title, fs, 600, "start", false));
|
|
5750
5828
|
e.details.forEach((d, k) => out.push(text(x, ay + fs * 1.55 + (k + 1) * fs * 1.45, d, fs * .92, 400, "start", true)));
|
|
@@ -5943,7 +6021,7 @@ function renderChart(c, box, ctx) {
|
|
|
5943
6021
|
const g = geometry$6(c, ctx);
|
|
5944
6022
|
const { fs, unit } = g;
|
|
5945
6023
|
const out = [];
|
|
5946
|
-
const label = (x, y, s, anchor = "start", fill = T.node.text, weight = 400, size = fs) => `<text x="${f$1(x)}" y="${f$1(y)}" dominant-baseline="central" text-anchor="${anchor}" font-size="${f$1(size)}"${weight !== 400 ? ` font-weight="${weight}"` : ""} fill="${fill}">${esc
|
|
6024
|
+
const label = (x, y, s, anchor = "start", fill = T.node.text, weight = 400, size = fs) => `<text x="${f$1(x)}" y="${f$1(y)}" dominant-baseline="central" text-anchor="${anchor}" font-size="${f$1(size)}"${weight !== 400 ? ` font-weight="${weight}"` : ""} fill="${fill}">${esc(s)}</text>`;
|
|
5947
6025
|
const max = maxOf$1(c.items.map((it) => it.value), 0) || 1;
|
|
5948
6026
|
if (c.type === "pie" || c.type === "donut") {
|
|
5949
6027
|
const cx = box.x + g.r;
|
|
@@ -6089,10 +6167,10 @@ const PALETTE$2 = [
|
|
|
6089
6167
|
];
|
|
6090
6168
|
const NAME = String.raw`[\p{L}\p{N}_][\p{L}\p{N}_./-]*`;
|
|
6091
6169
|
const PROPS = String.raw`(?:\s*\[([^\]]*)\])?`;
|
|
6092
|
-
const COMMIT_RE = new RegExp(String.raw`^commit(?:\s+(.*?))?${PROPS}$`, "u");
|
|
6093
|
-
const BRANCH_RE = new RegExp(String.raw`^(?:branch|checkout\s+-b|switch\s+-c)\s+(${NAME})(?:\s+from\s+(\S+))?${PROPS}$`, "u");
|
|
6094
|
-
const CHECKOUT_RE = new RegExp(String.raw`^(?:checkout|switch)\s+(${NAME})$`, "u");
|
|
6095
|
-
const MERGE_RE = new RegExp(String.raw`^merge\s+(${NAME})(?:\s+(.*?))?${PROPS}$`, "u");
|
|
6170
|
+
const COMMIT_RE$1 = new RegExp(String.raw`^commit(?:\s+(.*?))?${PROPS}$`, "u");
|
|
6171
|
+
const BRANCH_RE$1 = new RegExp(String.raw`^(?:branch|checkout\s+-b|switch\s+-c)\s+(${NAME})(?:\s+from\s+(\S+))?${PROPS}$`, "u");
|
|
6172
|
+
const CHECKOUT_RE$1 = new RegExp(String.raw`^(?:checkout|switch)\s+(${NAME})$`, "u");
|
|
6173
|
+
const MERGE_RE$1 = new RegExp(String.raw`^merge\s+(${NAME})(?:\s+(.*?))?${PROPS}$`, "u");
|
|
6096
6174
|
const PICK_RE = new RegExp(String.raw`^cherry-pick\s+(\S+?)(?:\s+(.*?))?${PROPS}$`, "u");
|
|
6097
6175
|
const TAG_RE = /^tag\s+(\S+)$/;
|
|
6098
6176
|
/** `tag: v1, red, highlight` → { tag: 'v1', color: 'red', type: 'highlight' }: the core prop reader plus commit types */
|
|
@@ -6142,7 +6220,7 @@ function parseGit(body, props, warn) {
|
|
|
6142
6220
|
const line = raw.trim();
|
|
6143
6221
|
if (!line) return;
|
|
6144
6222
|
let m;
|
|
6145
|
-
if (m = line.match(BRANCH_RE)) {
|
|
6223
|
+
if (m = line.match(BRANCH_RE$1)) {
|
|
6146
6224
|
if (find(m[1])) return warn(i, `git: branch "${m[1]}" already exists (use "checkout ${m[1]}")`);
|
|
6147
6225
|
let head = cur.head;
|
|
6148
6226
|
if (m[2]) {
|
|
@@ -6164,11 +6242,11 @@ function parseGit(body, props, warn) {
|
|
|
6164
6242
|
};
|
|
6165
6243
|
branches.push(b);
|
|
6166
6244
|
cur = b;
|
|
6167
|
-
} else if (m = line.match(CHECKOUT_RE)) {
|
|
6245
|
+
} else if (m = line.match(CHECKOUT_RE$1)) {
|
|
6168
6246
|
const b = find(m[1]);
|
|
6169
6247
|
if (b) cur = b;
|
|
6170
6248
|
else warn(i, `git: unknown branch "${m[1]}" (create it with "branch ${m[1]}")`);
|
|
6171
|
-
} else if (m = line.match(MERGE_RE)) {
|
|
6249
|
+
} else if (m = line.match(MERGE_RE$1)) {
|
|
6172
6250
|
const b = find(m[1]);
|
|
6173
6251
|
if (!b) return warn(i, `git: unknown branch "${m[1]}"`);
|
|
6174
6252
|
if (b === cur) return warn(i, `git: cannot merge "${m[1]}" into itself`);
|
|
@@ -6192,7 +6270,7 @@ function parseGit(body, props, warn) {
|
|
|
6192
6270
|
} else if (m = line.match(TAG_RE)) {
|
|
6193
6271
|
if (cur.head < 0) warn(i, "git: nothing to tag yet");
|
|
6194
6272
|
else commits[cur.head].tags.push(m[1]);
|
|
6195
|
-
} else if (m = line.match(COMMIT_RE)) add({
|
|
6273
|
+
} else if (m = line.match(COMMIT_RE$1)) add({
|
|
6196
6274
|
msg: unquote(m[1] ?? ""),
|
|
6197
6275
|
parents: cur.head >= 0 ? [cur.head] : [],
|
|
6198
6276
|
merge: false
|
|
@@ -6449,11 +6527,11 @@ function renderGit(g, box, ctx) {
|
|
|
6449
6527
|
const w = G.pillW(t);
|
|
6450
6528
|
const x0 = anchor === "middle" ? x - w / 2 : x;
|
|
6451
6529
|
const h = fs * 1.3;
|
|
6452
|
-
return `<rect x="${f$1(x0)}" y="${f$1(y - h / 2)}" width="${f$1(w)}" height="${f$1(h)}" rx="${f$1(h / 2)}" fill="${filled ? color : bg}" stroke="${color}" stroke-width="1.2"/><text x="${f$1(x0 + w / 2)}" y="${f$1(y)}" dominant-baseline="central" text-anchor="middle" font-size="${f$1(fs * .82)}" font-weight="600" fill="${filled ? bg : color}">${esc
|
|
6530
|
+
return `<rect x="${f$1(x0)}" y="${f$1(y - h / 2)}" width="${f$1(w)}" height="${f$1(h)}" rx="${f$1(h / 2)}" fill="${filled ? color : bg}" stroke="${color}" stroke-width="1.2"/><text x="${f$1(x0 + w / 2)}" y="${f$1(y)}" dominant-baseline="central" text-anchor="middle" font-size="${f$1(fs * .82)}" font-weight="600" fill="${filled ? bg : color}">${esc(t)}</text>`;
|
|
6453
6531
|
};
|
|
6454
6532
|
if (!G.vertical) for (const b of G.used) {
|
|
6455
6533
|
const y = box.y + G.top + G.lanePos[G.slot.get(b.lane)];
|
|
6456
|
-
out.push(`<text x="${f$1(box.x)}" y="${f$1(y)}" dominant-baseline="central" font-size="${f$1(fs)}" font-weight="600" fill="${laneColor(g, b.lane, ctx)}">${esc
|
|
6534
|
+
out.push(`<text x="${f$1(box.x)}" y="${f$1(y)}" dominant-baseline="central" font-size="${f$1(fs)}" font-weight="600" fill="${laneColor(g, b.lane, ctx)}">${esc(b.label ?? b.name)}</text>`);
|
|
6457
6535
|
}
|
|
6458
6536
|
const sw = Math.max(2, T.edgeWidth * 1.4);
|
|
6459
6537
|
const R = routes(g, G, box);
|
|
@@ -6475,7 +6553,7 @@ function renderGit(g, box, ctx) {
|
|
|
6475
6553
|
if (G.vertical) {
|
|
6476
6554
|
let tx = box.x + G.textX;
|
|
6477
6555
|
if (c.id) {
|
|
6478
|
-
out.push(`<text x="${f$1(tx)}" y="${f$1(y)}" dominant-baseline="central" font-size="${f$1(fs)}" font-family="${esc
|
|
6556
|
+
out.push(`<text x="${f$1(tx)}" y="${f$1(y)}" dominant-baseline="central" font-size="${f$1(fs)}" font-family="${esc(MONO)}" fill="${T.node.sub}">${esc(c.id)}</text>`);
|
|
6479
6557
|
tx += ctx.measure(c.id, fs, 400, true) + fs * .6;
|
|
6480
6558
|
}
|
|
6481
6559
|
for (const b of G.heads.get(i) ?? []) {
|
|
@@ -6950,7 +7028,7 @@ const MONTHS = [
|
|
|
6950
7028
|
];
|
|
6951
7029
|
const TASK_RE = /^([\w.-]+)(?:\s+"((?:[^"\\]|\\.)*)")?(?:\s*\[([^\]]*)\])?\s*:\s*(.*)$/;
|
|
6952
7030
|
const HEAD_RE$1 = /^(\s*[\w.-]+(?:\s+"(?:[^"\\]|\\.)*")?)(?:\s*\[([^\]]*)\])?(\s*:.*)$/;
|
|
6953
|
-
const SECTION_RE = /^(?:-{3,}\s*(.*?)\s*-{3,}|section\s+(.+))$/;
|
|
7031
|
+
const SECTION_RE$1 = /^(?:-{3,}\s*(.*?)\s*-{3,}|section\s+(.+))$/;
|
|
6954
7032
|
/** UTC ms of `2025-01-06` or `2025-01-06 14:00`, NaN when invalid */
|
|
6955
7033
|
function parseDate(s) {
|
|
6956
7034
|
const m = s.trim().match(/^(\d{4})-(\d{1,2})-(\d{1,2})(?:[ T](\d{1,2}):(\d{2}))?$/);
|
|
@@ -6979,7 +7057,7 @@ function parseGantt(body, _props, warn) {
|
|
|
6979
7057
|
body.forEach((raw, i) => {
|
|
6980
7058
|
const line = raw.trim();
|
|
6981
7059
|
if (!line) return;
|
|
6982
|
-
const sec = line.match(SECTION_RE);
|
|
7060
|
+
const sec = line.match(SECTION_RE$1);
|
|
6983
7061
|
if (sec) {
|
|
6984
7062
|
const name = (sec[1] ?? sec[2]).trim();
|
|
6985
7063
|
const pm = name.match(/^(.*?)\s*\[([^\]]*)\]$/);
|
|
@@ -7127,7 +7205,7 @@ function taskLines(body) {
|
|
|
7127
7205
|
const out = [];
|
|
7128
7206
|
body.forEach((raw, i) => {
|
|
7129
7207
|
const line = raw.trim();
|
|
7130
|
-
if (line && !/^(\/\/|#)/.test(line) && !SECTION_RE.test(line) && TASK_RE.test(splitTrailingProps(line)[0])) out.push(i);
|
|
7208
|
+
if (line && !/^(\/\/|#)/.test(line) && !SECTION_RE$1.test(line) && TASK_RE.test(splitTrailingProps(line)[0])) out.push(i);
|
|
7131
7209
|
});
|
|
7132
7210
|
return out;
|
|
7133
7211
|
}
|
|
@@ -7382,7 +7460,7 @@ function renderGantt(g, box, ctx) {
|
|
|
7382
7460
|
...ink,
|
|
7383
7461
|
text: fill
|
|
7384
7462
|
} : ink, T)}</text>`;
|
|
7385
|
-
const note = (tx, ty, s, fill, end = false) => `<text x="${f$1(tx)}" y="${f$1(ty)}" dominant-baseline="central"${end ? " text-anchor=\"end\"" : ""} font-size="${f$1(fs * .82)}" font-weight="500" fill="${fill}">${esc
|
|
7463
|
+
const note = (tx, ty, s, fill, end = false) => `<text x="${f$1(tx)}" y="${f$1(ty)}" dominant-baseline="central"${end ? " text-anchor=\"end\"" : ""} font-size="${f$1(fs * .82)}" font-weight="500" fill="${fill}">${esc(s)}</text>`;
|
|
7386
7464
|
if (P.weekends === "show" && G.dayW >= fs * .3 && (G.max - G.min) / DAY <= MAX_WEEKEND_DAYS) for (let t = G.min; t < G.max; t += DAY) {
|
|
7387
7465
|
const wd = new Date(t).getUTCDay();
|
|
7388
7466
|
if (wd === 0 || wd === 6) out.push(`<rect x="${f$1(X(t))}" y="${f$1(box.y + G.axisH * .8)}" width="${f$1(G.dayW)}" height="${f$1(G.h - G.axisH * .8)}" fill="${grid}" opacity="0.14"/>`);
|
|
@@ -7399,7 +7477,7 @@ function renderGantt(g, box, ctx) {
|
|
|
7399
7477
|
const lx = Math.max(box.x + G.labelW + lw / 2, Math.min(tx, plotR - lw / 2));
|
|
7400
7478
|
const hidden = tag && lx + lw / 2 > tagX - fs * .4 && lx - lw / 2 < tagX + tagW + fs * .4;
|
|
7401
7479
|
if (P.grid !== "none") out.push(`<path d="M${f$1(tx)},${f$1(box.y + G.axisH * .75)}V${f$1(bottom)}" stroke="${grid}" stroke-width="1" opacity="0.45"/>`);
|
|
7402
|
-
if (!hidden) out.push(`<text x="${f$1(lx)}" y="${f$1(box.y + G.axisH * .35)}" dominant-baseline="central" text-anchor="middle" font-size="${f$1(fs * .82)}" fill="${T.node.sub}">${esc
|
|
7480
|
+
if (!hidden) out.push(`<text x="${f$1(lx)}" y="${f$1(box.y + G.axisH * .35)}" dominant-baseline="central" text-anchor="middle" font-size="${f$1(fs * .82)}" fill="${T.node.sub}">${esc(tk.label)}</text>`);
|
|
7403
7481
|
}
|
|
7404
7482
|
out.push(`<path d="M${f$1(box.x + G.labelW)},${f$1(box.y + G.axisH * .75)}H${f$1(box.x + G.labelW + G.plotW)}" stroke="${grid}" stroke-width="1.5"/>`);
|
|
7405
7483
|
const rowOf = /* @__PURE__ */ new Map();
|
|
@@ -7524,7 +7602,7 @@ function renderGantt(g, box, ctx) {
|
|
|
7524
7602
|
if (showToday) {
|
|
7525
7603
|
const c = inkColor("red", T, T.accent);
|
|
7526
7604
|
const ty = box.y + G.axisH * .35;
|
|
7527
|
-
out.push(`<rect x="${f$1(tagX)}" y="${f$1(ty - fs * .55)}" width="${f$1(tagW)}" height="${f$1(fs * 1.1)}" rx="${f$1(fs * .55)}" fill="${c}"/>`, `<text x="${f$1(tagX + tagW / 2)}" y="${f$1(ty)}" dominant-baseline="central" text-anchor="middle" font-size="${f$1(fs * .72)}" font-weight="650" fill="${contrast(c)}">${esc
|
|
7605
|
+
out.push(`<rect x="${f$1(tagX)}" y="${f$1(ty - fs * .55)}" width="${f$1(tagW)}" height="${f$1(fs * 1.1)}" rx="${f$1(fs * .55)}" fill="${c}"/>`, `<text x="${f$1(tagX + tagW / 2)}" y="${f$1(ty)}" dominant-baseline="central" text-anchor="middle" font-size="${f$1(fs * .72)}" font-weight="650" fill="${contrast(c)}">${esc(tag)}</text>`);
|
|
7528
7606
|
}
|
|
7529
7607
|
return out.join("");
|
|
7530
7608
|
}
|
|
@@ -7898,7 +7976,7 @@ function renderQuadrant(q, box, ctx) {
|
|
|
7898
7976
|
}, T)}</text>`);
|
|
7899
7977
|
});
|
|
7900
7978
|
out.push(`<rect x="${f$1(px)}" y="${f$1(py)}" width="${f$1(S)}" height="${f$1(S)}" fill="none" stroke="${T.group.stroke}" stroke-width="1.5"/>`, `<path d="M${f$1(px + half)},${f$1(py)}V${f$1(py + S)}M${f$1(px)},${f$1(py + half)}H${f$1(px + S)}" stroke="${T.group.stroke}" stroke-width="1"/>`);
|
|
7901
|
-
const axisText = (x, y, s, rotate) => s ? `<text x="${f$1(x)}" y="${f$1(y)}" dominant-baseline="central" text-anchor="middle" font-size="${f$1(fs * .85)}" fill="${T.node.sub}"${rotate ? ` transform="rotate(-90 ${f$1(x)} ${f$1(y)})"` : ""}>${esc
|
|
7979
|
+
const axisText = (x, y, s, rotate) => s ? `<text x="${f$1(x)}" y="${f$1(y)}" dominant-baseline="central" text-anchor="middle" font-size="${f$1(fs * .85)}" fill="${T.node.sub}"${rotate ? ` transform="rotate(-90 ${f$1(x)} ${f$1(y)})"` : ""}>${esc(s)}</text>` : "";
|
|
7902
7980
|
const ax = py + S + G.bottom / 2;
|
|
7903
7981
|
out.push(axisText(px + half / 2, ax, q.x[0], false), axisText(px + half * 1.5, ax, q.x[1], false));
|
|
7904
7982
|
const ay = box.x + G.left / 2;
|
|
@@ -7991,7 +8069,7 @@ const skip = (l) => !l.trim();
|
|
|
7991
8069
|
const CARD = /^[-*]\s+/;
|
|
7992
8070
|
/** a WIP limit, or undefined when blank or not a number of 0 or more */
|
|
7993
8071
|
function readLimit(v) {
|
|
7994
|
-
if (v === void 0 || !v.trim()) return
|
|
8072
|
+
if (v === void 0 || !v.trim()) return;
|
|
7995
8073
|
const n = Number(v);
|
|
7996
8074
|
return Number.isFinite(n) && n >= 0 ? n : void 0;
|
|
7997
8075
|
}
|
|
@@ -8252,7 +8330,7 @@ function renderKanban(cols, box, ctx) {
|
|
|
8252
8330
|
const b = G.badge(c);
|
|
8253
8331
|
const bw = ctx.measure(b, fs * .8, 600, T.mono) + fs * .9;
|
|
8254
8332
|
const bx = x + G.colW - G.cpad - bw;
|
|
8255
|
-
out.push(`<rect x="${f$1(bx)}" y="${f$1(hy - fs * .6)}" width="${f$1(bw)}" height="${f$1(fs * 1.2)}" rx="${f$1(fs * .6)}" fill="${over ? red : T.node.fill}" stroke="${over ? red : T.node.stroke}"/>`, `<text x="${f$1(bx + bw / 2)}" y="${f$1(hy)}" dominant-baseline="central" text-anchor="middle" font-size="${f$1(fs * .8)}" font-weight="600" fill="${over ? T.dark ? "#000" : "#fff" : T.node.sub}">${esc
|
|
8333
|
+
out.push(`<rect x="${f$1(bx)}" y="${f$1(hy - fs * .6)}" width="${f$1(bw)}" height="${f$1(fs * 1.2)}" rx="${f$1(fs * .6)}" fill="${over ? red : T.node.fill}" stroke="${over ? red : T.node.stroke}"/>`, `<text x="${f$1(bx + bw / 2)}" y="${f$1(hy)}" dominant-baseline="central" text-anchor="middle" font-size="${f$1(fs * .8)}" font-weight="600" fill="${over ? T.dark ? "#000" : "#fff" : T.node.sub}">${esc(b)}</text>`);
|
|
8256
8334
|
let cy = y + G.headH;
|
|
8257
8335
|
c.cards.forEach((k, j) => {
|
|
8258
8336
|
const s = G.sizes[i][j];
|
|
@@ -8274,7 +8352,7 @@ function renderKanban(cols, box, ctx) {
|
|
|
8274
8352
|
for (const ch of k.chips) {
|
|
8275
8353
|
const w = G.chipW(ch);
|
|
8276
8354
|
const ct = ch.tone ? T.tone(ch.tone) : void 0;
|
|
8277
|
-
out.push(`<rect x="${f$1(chx)}" y="${f$1(chy - G.chipFs * .75)}" width="${f$1(w)}" height="${f$1(G.chipFs * 1.5)}" rx="${f$1(G.chipFs * .75)}" fill="${ct?.fill ?? T.group.fill}" stroke="${ct?.stroke ?? T.node.stroke}" stroke-width="0.8"/>`, `<text x="${f$1(chx + w / 2)}" y="${f$1(chy)}" dominant-baseline="central" text-anchor="middle" font-size="${f$1(G.chipFs)}" font-weight="600"${ch.mono ? " font-family=\"ui-monospace, SFMono-Regular, Menlo, monospace\"" : ""} fill="${ct?.text ?? T.node.sub}">${esc
|
|
8355
|
+
out.push(`<rect x="${f$1(chx)}" y="${f$1(chy - G.chipFs * .75)}" width="${f$1(w)}" height="${f$1(G.chipFs * 1.5)}" rx="${f$1(G.chipFs * .75)}" fill="${ct?.fill ?? T.group.fill}" stroke="${ct?.stroke ?? T.node.stroke}" stroke-width="0.8"/>`, `<text x="${f$1(chx + w / 2)}" y="${f$1(chy)}" dominant-baseline="central" text-anchor="middle" font-size="${f$1(G.chipFs)}" font-weight="600"${ch.mono ? " font-family=\"ui-monospace, SFMono-Regular, Menlo, monospace\"" : ""} fill="${ct?.text ?? T.node.sub}">${esc(ch.text)}</text>`);
|
|
8278
8356
|
chx += w + fs * .35;
|
|
8279
8357
|
}
|
|
8280
8358
|
}
|
|
@@ -8401,6 +8479,13 @@ const KEYS = [
|
|
|
8401
8479
|
"size",
|
|
8402
8480
|
"status"
|
|
8403
8481
|
];
|
|
8482
|
+
/** a status from props: a flag (`[modified]`) or `status:` */
|
|
8483
|
+
const readStatus = (p) => STATUSES.find((s) => p[s] === "true") ?? (STATUSES.includes(p.status) ? p.status : void 0);
|
|
8484
|
+
/** drop every way of writing a status from `p` */
|
|
8485
|
+
function clearStatus(p) {
|
|
8486
|
+
for (const s of STATUSES) delete p[s];
|
|
8487
|
+
delete p.status;
|
|
8488
|
+
}
|
|
8404
8489
|
/** the icons drawn as vector glyphs; anything else in `icon:` is shown as text */
|
|
8405
8490
|
const TREE_ICONS = [
|
|
8406
8491
|
"folder",
|
|
@@ -8564,7 +8649,6 @@ function parseTreeview(body, _props, warn) {
|
|
|
8564
8649
|
const roots = [];
|
|
8565
8650
|
const stack = [];
|
|
8566
8651
|
const rules = [];
|
|
8567
|
-
const own = /* @__PURE__ */ new Map();
|
|
8568
8652
|
let tooDeep = false;
|
|
8569
8653
|
body.forEach((raw, i) => {
|
|
8570
8654
|
if (!raw.trim() || /^\s*#/.test(raw)) return;
|
|
@@ -8619,19 +8703,22 @@ function parseTreeview(body, _props, warn) {
|
|
|
8619
8703
|
highlight: false,
|
|
8620
8704
|
dim: false,
|
|
8621
8705
|
line: i,
|
|
8706
|
+
lead: raw.slice(0, base),
|
|
8707
|
+
depth: 0,
|
|
8708
|
+
own: {
|
|
8709
|
+
props,
|
|
8710
|
+
note: props.note ?? note
|
|
8711
|
+
},
|
|
8622
8712
|
children: []
|
|
8623
8713
|
};
|
|
8624
8714
|
if (propSpan) node.propSpan = propSpan;
|
|
8625
|
-
own.set(node, {
|
|
8626
|
-
props,
|
|
8627
|
-
note
|
|
8628
|
-
});
|
|
8629
8715
|
while (stack.length && stack[stack.length - 1].indent >= indent) stack.pop();
|
|
8630
8716
|
if (stack.length >= MAX_DEPTH) {
|
|
8631
8717
|
if (!tooDeep) warn(i, `treeview: entries nest at most ${MAX_DEPTH} levels deep`);
|
|
8632
8718
|
tooDeep = true;
|
|
8633
8719
|
stack.length = 99;
|
|
8634
8720
|
}
|
|
8721
|
+
node.depth = stack.length;
|
|
8635
8722
|
(stack.length ? stack[stack.length - 1].node.children : roots).push(node);
|
|
8636
8723
|
stack.push({
|
|
8637
8724
|
indent,
|
|
@@ -8641,7 +8728,7 @@ function parseTreeview(body, _props, warn) {
|
|
|
8641
8728
|
const resolve = (list, dir) => {
|
|
8642
8729
|
for (const n of list) {
|
|
8643
8730
|
const path = dir + bare$1(n.text);
|
|
8644
|
-
const { props: mine, note } = own
|
|
8731
|
+
const { props: mine, note } = n.own;
|
|
8645
8732
|
const folder = mine.folder === "true" || mine.file !== "true" && (n.children.length > 0 || n.text.endsWith("/"));
|
|
8646
8733
|
const props = {};
|
|
8647
8734
|
for (const r of rules) if ((!r.folders || folder) && r.re.test(r.path ? path : bare$1(n.text))) {
|
|
@@ -8650,17 +8737,14 @@ function parseTreeview(body, _props, warn) {
|
|
|
8650
8737
|
}
|
|
8651
8738
|
if (mine.folder === "true") delete props.file;
|
|
8652
8739
|
if (mine.file === "true") delete props.folder;
|
|
8653
|
-
if (STATUSES.some((s) => mine[s] === "true") || mine.status)
|
|
8654
|
-
for (const s of STATUSES) delete props[s];
|
|
8655
|
-
delete props.status;
|
|
8656
|
-
}
|
|
8740
|
+
if (STATUSES.some((s) => mine[s] === "true") || mine.status) clearStatus(props);
|
|
8657
8741
|
Object.assign(props, mine);
|
|
8658
|
-
n.note =
|
|
8742
|
+
n.note = note ?? props.note;
|
|
8659
8743
|
n.tone = props.color;
|
|
8660
8744
|
n.icon = props.icon;
|
|
8661
8745
|
n.badge = props.badge;
|
|
8662
8746
|
n.size = props.size;
|
|
8663
|
-
n.status =
|
|
8747
|
+
n.status = readStatus(props);
|
|
8664
8748
|
n.collapsed = props.collapsed === "true";
|
|
8665
8749
|
n.highlight = props.highlight === "true";
|
|
8666
8750
|
n.dim = props.dim === "true";
|
|
@@ -8979,8 +9063,11 @@ function renderTreeview(roots, box, ctx) {
|
|
|
8979
9063
|
const guideW = edgeWidthOf(props) ?? 1;
|
|
8980
9064
|
const guideStyle = `fill="none" stroke="${guide}" stroke-width="${f$1(guideW)}" stroke-opacity="0.55"${dash(lines)}${lines === "rounded" ? " stroke-linejoin=\"round\"" : ""}`;
|
|
8981
9065
|
const bandR = Math.min(num(props.radius) ?? T.radius, (g.rowH - 2) / 2);
|
|
9066
|
+
const extra = Math.max(0, box.w - g.w);
|
|
9067
|
+
const sizeRight = g.sizeRight + extra;
|
|
9068
|
+
const markX = g.markX + extra;
|
|
8982
9069
|
const bandX = f$1(X(-g.fs * .35));
|
|
8983
|
-
const bandW = f$1(g.w + g.fs * .7);
|
|
9070
|
+
const bandW = f$1(g.w + extra + g.fs * .7);
|
|
8984
9071
|
g.rows.forEach((r, k) => {
|
|
8985
9072
|
const n = r.node;
|
|
8986
9073
|
const cy = r.y + g.rowH / 2;
|
|
@@ -9008,7 +9095,7 @@ function renderTreeview(roots, box, ctx) {
|
|
|
9008
9095
|
if (g.iconW && !r.more) {
|
|
9009
9096
|
const ix = X(r.x + g.chevW);
|
|
9010
9097
|
const iy = Y(cy - g.iconW / 2);
|
|
9011
|
-
if (r.iconText || g.icons === "emoji") row.push(`<text x="${f$1(ix + g.iconW / 2)}" y="${f$1(Y(cy))}" dominant-baseline="central" text-anchor="middle" font-size="${f$1(g.fs * .95)}">${esc
|
|
9098
|
+
if (r.iconText || g.icons === "emoji") row.push(`<text x="${f$1(ix + g.iconW / 2)}" y="${f$1(Y(cy))}" dominant-baseline="central" text-anchor="middle" font-size="${f$1(g.fs * .95)}">${esc(r.iconText ?? EMOJI[r.icon] ?? "📄")}</text>`);
|
|
9012
9099
|
else {
|
|
9013
9100
|
const mono = g.icons === "mono";
|
|
9014
9101
|
const tc = !mono && r.iconTone ? T.tone(r.iconTone) : void 0;
|
|
@@ -9033,7 +9120,7 @@ function renderTreeview(roots, box, ctx) {
|
|
|
9033
9120
|
const tc = T.tone(n.tone ?? badgeTone);
|
|
9034
9121
|
const bx = X(g.badgeX(r));
|
|
9035
9122
|
const bh = g.fs * 1.15;
|
|
9036
|
-
row.push(`<rect x="${f$1(bx)}" y="${f$1(Y(cy) - bh / 2)}" width="${f$1(r.badgeW)}" height="${f$1(bh)}" rx="${f$1(bh / 2)}" fill="${tc?.fill ?? T.node.fill}" stroke="${tc?.stroke ?? T.node.stroke}"/><text x="${f$1(bx + r.badgeW / 2)}" y="${f$1(Y(cy))}" dominant-baseline="central" text-anchor="middle" font-size="${f$1(g.fs * .72)}" font-weight="600" fill="${tc?.text ?? T.node.text}">${esc
|
|
9123
|
+
row.push(`<rect x="${f$1(bx)}" y="${f$1(Y(cy) - bh / 2)}" width="${f$1(r.badgeW)}" height="${f$1(bh)}" rx="${f$1(bh / 2)}" fill="${tc?.fill ?? T.node.fill}" stroke="${tc?.stroke ?? T.node.stroke}"/><text x="${f$1(bx + r.badgeW / 2)}" y="${f$1(Y(cy))}" dominant-baseline="central" text-anchor="middle" font-size="${f$1(g.fs * .72)}" font-weight="600" fill="${tc?.text ?? T.node.text}">${esc(n.badge)}</text>`);
|
|
9037
9124
|
}
|
|
9038
9125
|
if (r.count) {
|
|
9039
9126
|
const cx = X(g.countX(r));
|
|
@@ -9045,17 +9132,132 @@ function renderTreeview(roots, box, ctx) {
|
|
|
9045
9132
|
sub: noteInk,
|
|
9046
9133
|
stroke: noteInk
|
|
9047
9134
|
}, T, true)}</text>`);
|
|
9048
|
-
if (n.size) row.push(`<text x="${f$1(X(
|
|
9135
|
+
if (n.size) row.push(`<text x="${f$1(X(sizeRight))}" y="${f$1(Y(cy))}" dominant-baseline="central" text-anchor="end" font-size="${f$1(g.fs * .82)}" fill="${T.node.sub}">${esc(n.size)}</text>`);
|
|
9049
9136
|
if (g.mark(r)) {
|
|
9050
9137
|
const status = n.status ?? r.rollup;
|
|
9051
9138
|
const color = ink(STATUS_TONE[status], T.node.text);
|
|
9052
|
-
if (g.marks === "dot" || !n.status) row.push(`<circle cx="${f$1(X(
|
|
9053
|
-
else row.push(`<text x="${f$1(X(
|
|
9139
|
+
if (g.marks === "dot" || !n.status) row.push(`<circle cx="${f$1(X(markX))}" cy="${f$1(Y(cy))}" r="${f$1(g.fs * .22)}" fill="${color}"/>`);
|
|
9140
|
+
else row.push(`<text x="${f$1(X(markX))}" y="${f$1(Y(cy))}" dominant-baseline="central" text-anchor="middle" font-size="${f$1(g.fs * .85)}" font-weight="700" fill="${color}">${STATUS_MARK[status]}</text>`);
|
|
9054
9141
|
}
|
|
9055
9142
|
out.push(n.dim ? `<g opacity="0.45">${row.join("")}</g>` : row.join(""));
|
|
9056
9143
|
});
|
|
9057
9144
|
return bands.join("") + guides.join("") + out.join("");
|
|
9058
9145
|
}
|
|
9146
|
+
/** the fields an editor offers for an entry; `''` / `'true'` lists are on/off switches */
|
|
9147
|
+
const ENTRY_FIELDS = {
|
|
9148
|
+
text: [],
|
|
9149
|
+
note: [],
|
|
9150
|
+
status: ["", ...STATUSES],
|
|
9151
|
+
icon: ["", ...TREE_ICONS],
|
|
9152
|
+
badge: [],
|
|
9153
|
+
size: [],
|
|
9154
|
+
collapsed: ["", "true"],
|
|
9155
|
+
highlight: ["", "true"],
|
|
9156
|
+
dim: ["", "true"]
|
|
9157
|
+
};
|
|
9158
|
+
/** the body line index just past `n` and everything nested under it */
|
|
9159
|
+
const blockEnd = (n) => n.children.length ? blockEnd(n.children.at(-1)) : n.line + 1;
|
|
9160
|
+
/** `n`'s line written out again from its name, note and props */
|
|
9161
|
+
function writeEntry(n, text, note, props) {
|
|
9162
|
+
const p = serializeProps(props);
|
|
9163
|
+
return n.lead + text + (note ? `: ${note}` : "") + (p ? ` [${p}]` : "");
|
|
9164
|
+
}
|
|
9165
|
+
/** the indentation (and bullet) a new child of `n`, or a new top-level entry, gets */
|
|
9166
|
+
function childLead(n, roots) {
|
|
9167
|
+
const first = n ? n.children[0] : roots[0];
|
|
9168
|
+
const plain = (lead) => lead.replace(/[^\s\-*+]/gu, " ").replace(/[-*+](?!\s)/g, " ");
|
|
9169
|
+
if (first) return plain(first.lead);
|
|
9170
|
+
if (!n) return "";
|
|
9171
|
+
const bullet = n.lead.match(/[-*+]\s+$/)?.[0] ?? "";
|
|
9172
|
+
return " ".repeat(plain(n.lead).length - bullet.length + 2) + bullet;
|
|
9173
|
+
}
|
|
9174
|
+
function editTreeview(body, edit, roots) {
|
|
9175
|
+
const all = walk(roots);
|
|
9176
|
+
const ids = entryParts(all);
|
|
9177
|
+
const at = edit.id === void 0 ? -1 : ids.indexOf(edit.id);
|
|
9178
|
+
const n = all[at];
|
|
9179
|
+
/** the new body, and the id of the entry now on body line `line` (ids follow position) */
|
|
9180
|
+
const done = (out, line, parsed) => {
|
|
9181
|
+
if (line === void 0) return { body: out };
|
|
9182
|
+
const list = walk(parsed ?? parseTreeview(out, {}, () => {}));
|
|
9183
|
+
return {
|
|
9184
|
+
body: out,
|
|
9185
|
+
id: entryParts(list)[list.findIndex((e) => e.line === line)]
|
|
9186
|
+
};
|
|
9187
|
+
};
|
|
9188
|
+
const siblings = (e) => all.find((p) => p.children.includes(e))?.children ?? roots;
|
|
9189
|
+
switch (edit.op) {
|
|
9190
|
+
case "set": {
|
|
9191
|
+
if (!n) return null;
|
|
9192
|
+
const { key } = edit;
|
|
9193
|
+
const value = edit.value?.trim() || null;
|
|
9194
|
+
if (value && /[\r\n]/.test(value)) return null;
|
|
9195
|
+
if (key !== "color" && !(key in ENTRY_FIELDS)) return null;
|
|
9196
|
+
if (ENTRY_FIELDS[key]?.length && value && !ENTRY_FIELDS[key].includes(value) && key !== "icon") return null;
|
|
9197
|
+
if (key === "color" && value && !isSafeCss(value)) return null;
|
|
9198
|
+
const out = [...body];
|
|
9199
|
+
let text = n.text;
|
|
9200
|
+
let note = n.own.note;
|
|
9201
|
+
if (key === "text" || key === "note") {
|
|
9202
|
+
if (key === "text") {
|
|
9203
|
+
if (!value) return null;
|
|
9204
|
+
text = value;
|
|
9205
|
+
} else note = value ?? void 0;
|
|
9206
|
+
const { note: _, ...props } = n.own.props;
|
|
9207
|
+
out[n.line] = writeEntry(n, text, note, props);
|
|
9208
|
+
} else {
|
|
9209
|
+
const { color: tone, ...props } = n.own.props;
|
|
9210
|
+
if (key === "status") {
|
|
9211
|
+
clearStatus(props);
|
|
9212
|
+
if (value) props[value] = "true";
|
|
9213
|
+
} else if (key !== "color") {
|
|
9214
|
+
if (value) props[key] = value;
|
|
9215
|
+
else delete props[key];
|
|
9216
|
+
}
|
|
9217
|
+
const color = key === "color" ? value : tone;
|
|
9218
|
+
const p = serializeProps(color ? {
|
|
9219
|
+
color,
|
|
9220
|
+
...props
|
|
9221
|
+
} : props);
|
|
9222
|
+
const line = body[n.line];
|
|
9223
|
+
const [from, to] = n.propSpan ?? [line.trimEnd().length, line.trimEnd().length];
|
|
9224
|
+
out[n.line] = line.slice(0, from) + (p ? ` [${p}]` : "") + line.slice(to);
|
|
9225
|
+
}
|
|
9226
|
+
const back = parseTreeview(out, {}, () => {});
|
|
9227
|
+
const now = walk(back)[at];
|
|
9228
|
+
if (!now || now.text !== text || now.own.note !== note) return null;
|
|
9229
|
+
return done(out, n.line, back);
|
|
9230
|
+
}
|
|
9231
|
+
case "up":
|
|
9232
|
+
case "down": {
|
|
9233
|
+
if (!n) return null;
|
|
9234
|
+
const list = siblings(n);
|
|
9235
|
+
const i = list.indexOf(n);
|
|
9236
|
+
const up = edit.op === "up";
|
|
9237
|
+
const other = list[up ? i - 1 : i + 1];
|
|
9238
|
+
if (!other) return null;
|
|
9239
|
+
const [a, b] = up ? [other, n] : [n, other];
|
|
9240
|
+
const out = [...body];
|
|
9241
|
+
const first = body.slice(a.line, b.line);
|
|
9242
|
+
const second = body.slice(b.line, blockEnd(b));
|
|
9243
|
+
out.splice(a.line, first.length + second.length, ...second, ...first);
|
|
9244
|
+
return done(out, up ? a.line : a.line + second.length);
|
|
9245
|
+
}
|
|
9246
|
+
case "remove": {
|
|
9247
|
+
if (!n) return null;
|
|
9248
|
+
const out = [...body];
|
|
9249
|
+
out.splice(n.line, blockEnd(n) - n.line);
|
|
9250
|
+
return done(out);
|
|
9251
|
+
}
|
|
9252
|
+
case "add": {
|
|
9253
|
+
if (edit.id !== void 0 && !n) return null;
|
|
9254
|
+
const out = [...body];
|
|
9255
|
+
const where = n ? blockEnd(n) : roots.length ? blockEnd(roots[roots.length - 1]) : body.length;
|
|
9256
|
+
out.splice(where, 0, childLead(n, roots) + "new-file");
|
|
9257
|
+
return done(out, where);
|
|
9258
|
+
}
|
|
9259
|
+
}
|
|
9260
|
+
}
|
|
9059
9261
|
// src/setup.ts
|
|
9060
9262
|
/** Registers the built-in plugins. Imported for its side effect by every entry point. */
|
|
9061
9263
|
use(...[
|
|
@@ -9108,6 +9310,29 @@ use(...[
|
|
|
9108
9310
|
"strike-color": "color",
|
|
9109
9311
|
"strike-width": "number"
|
|
9110
9312
|
},
|
|
9313
|
+
help: {
|
|
9314
|
+
icons: "how files and folders are drawn: coloured glyphs, one colour, emoji or no icon",
|
|
9315
|
+
lines: "the guide lines that join an entry to its folder",
|
|
9316
|
+
sort: "reorder entries: as written, by name, or folders first",
|
|
9317
|
+
notes: "notes in their own column, or right after the name",
|
|
9318
|
+
chevrons: "an open/closed arrow before each folder",
|
|
9319
|
+
rows: "every other row shaded",
|
|
9320
|
+
spacing: "the row height",
|
|
9321
|
+
slashes: "a `/` after folder names",
|
|
9322
|
+
compact: "fold a folder whose only child is a folder into one `a/b/` row",
|
|
9323
|
+
counts: "how many entries a folder holds: on collapsed folders, on all, or none",
|
|
9324
|
+
marks: "the git status column on the right: letters (M, A, D, R), dots, or none",
|
|
9325
|
+
rollup: "a dot on folders that hold changed files",
|
|
9326
|
+
depth: "show this many levels; deeper folders are drawn collapsed",
|
|
9327
|
+
indent: "how far each level is indented, in pixels",
|
|
9328
|
+
"folder-color": "the folder icon colour",
|
|
9329
|
+
"line-color": "the guide line colour",
|
|
9330
|
+
"highlight-color": "the band behind highlighted entries",
|
|
9331
|
+
"badge-color": "the badge colour",
|
|
9332
|
+
"note-color": "the note text colour",
|
|
9333
|
+
"strike-color": "the line through deleted entries",
|
|
9334
|
+
"strike-width": "how thick the line through deleted entries is"
|
|
9335
|
+
},
|
|
9111
9336
|
parse: parseTreeview,
|
|
9112
9337
|
measure(roots, ctx) {
|
|
9113
9338
|
if (!roots.length) return {
|
|
@@ -9123,29 +9348,44 @@ use(...[
|
|
|
9123
9348
|
render: renderTreeview,
|
|
9124
9349
|
parts(roots) {
|
|
9125
9350
|
const all = walk(roots);
|
|
9126
|
-
return entryParts(all).map((id, i) =>
|
|
9127
|
-
|
|
9128
|
-
|
|
9129
|
-
|
|
9130
|
-
|
|
9131
|
-
|
|
9351
|
+
return entryParts(all).map((id, i) => {
|
|
9352
|
+
const n = all[i];
|
|
9353
|
+
const p = n.own.props;
|
|
9354
|
+
const folder = isFolder(n);
|
|
9355
|
+
return {
|
|
9356
|
+
id,
|
|
9357
|
+
label: n.text,
|
|
9358
|
+
kind: "entry",
|
|
9359
|
+
depth: n.depth,
|
|
9360
|
+
tone: n.tone,
|
|
9361
|
+
fields: ENTRY_FIELDS,
|
|
9362
|
+
values: {
|
|
9363
|
+
text: n.text,
|
|
9364
|
+
note: n.own.note ?? "",
|
|
9365
|
+
status: readStatus(p) ?? "",
|
|
9366
|
+
icon: p.icon ?? "",
|
|
9367
|
+
badge: p.badge ?? "",
|
|
9368
|
+
size: p.size ?? "",
|
|
9369
|
+
collapsed: p.collapsed === "true" ? "true" : "",
|
|
9370
|
+
highlight: p.highlight === "true" ? "true" : "",
|
|
9371
|
+
dim: p.dim === "true" ? "true" : ""
|
|
9372
|
+
},
|
|
9373
|
+
actions: folder ? [
|
|
9374
|
+
"up",
|
|
9375
|
+
"down",
|
|
9376
|
+
"remove",
|
|
9377
|
+
"add"
|
|
9378
|
+
] : [
|
|
9379
|
+
"up",
|
|
9380
|
+
"down",
|
|
9381
|
+
"remove"
|
|
9382
|
+
],
|
|
9383
|
+
...folder ? { adds: "entry" } : {}
|
|
9384
|
+
};
|
|
9385
|
+
});
|
|
9132
9386
|
},
|
|
9133
|
-
editPart:
|
|
9134
|
-
|
|
9135
|
-
const n = all[entryParts(all).indexOf(id)];
|
|
9136
|
-
if (!n) return null;
|
|
9137
|
-
const out = [...body];
|
|
9138
|
-
const line = body[n.line];
|
|
9139
|
-
const [from, to] = n.propSpan ?? [line.trimEnd().length, line.trimEnd().length];
|
|
9140
|
-
const m = line.slice(from, to).match(/\[([^\]]*)\]/);
|
|
9141
|
-
const { color: _, ...rest } = m ? parseProps(m[1]) : {};
|
|
9142
|
-
const props = serializeProps(tone ? {
|
|
9143
|
-
color: tone,
|
|
9144
|
-
...rest
|
|
9145
|
-
} : rest);
|
|
9146
|
-
out[n.line] = line.slice(0, from) + (props ? ` [${props}]` : "") + line.slice(to);
|
|
9147
|
-
return out;
|
|
9148
|
-
})
|
|
9387
|
+
editPart: editTreeview,
|
|
9388
|
+
adds: "entry"
|
|
9149
9389
|
}]
|
|
9150
9390
|
}
|
|
9151
9391
|
]);
|
|
@@ -9315,7 +9555,7 @@ function renderCard(cb, x, y, w, h, col, theme) {
|
|
|
9315
9555
|
const first = top + (cb.label.length ? cb.labelLh : cb.subLh) / 2;
|
|
9316
9556
|
let lx = left;
|
|
9317
9557
|
if (cb.icon) {
|
|
9318
|
-
out.push(textEl(left + cb.iconSize / 2, first, cb.iconSize, col.text, esc
|
|
9558
|
+
out.push(textEl(left + cb.iconSize / 2, first, cb.iconSize, col.text, esc(cb.icon), " text-anchor=\"middle\""));
|
|
9319
9559
|
lx += cb.iconSize + 8;
|
|
9320
9560
|
}
|
|
9321
9561
|
const ls = cb.letterSpacing ? ` letter-spacing="${f$1(cb.letterSpacing)}"` : "";
|
|
@@ -9364,7 +9604,7 @@ function renderBody(b, left, right, top, col, theme) {
|
|
|
9364
9604
|
h: rh
|
|
9365
9605
|
}, ctx) ?? "");
|
|
9366
9606
|
});
|
|
9367
|
-
return `<g class="body"${b.mono && !theme.mono ? ` font-family="${esc
|
|
9607
|
+
return `<g class="body"${b.mono && !theme.mono ? ` font-family="${esc(MONO)}"` : ""}>${out.join("")}</g>`;
|
|
9368
9608
|
}
|
|
9369
9609
|
/** Break `text` into lines no wider than `max` px, at spaces; explicit `\n` breaks stay. */
|
|
9370
9610
|
function wrapText(text, max, width) {
|
|
@@ -9386,15 +9626,15 @@ function wrapText(text, max, width) {
|
|
|
9386
9626
|
}
|
|
9387
9627
|
return out;
|
|
9388
9628
|
}
|
|
9389
|
-
function textBlock(label, sub, icon, fontSize, weight, theme, measure, caps = false, maxWidth = 0) {
|
|
9629
|
+
function textBlock(label, sub, icon, fontSize, weight, theme, measure, caps = false, maxWidth = 0, mono = theme.mono) {
|
|
9390
9630
|
const letterSpacing = caps ? fontSize * .1 : 0;
|
|
9391
9631
|
const subSize = Math.round(fontSize * .82 * 10) / 10;
|
|
9392
9632
|
const memo = (w) => {
|
|
9393
9633
|
const seen = /* @__PURE__ */ new Map();
|
|
9394
9634
|
return (l) => seen.get(l) ?? (seen.set(l, w(l)), seen.get(l));
|
|
9395
9635
|
};
|
|
9396
|
-
const labelW = memo((l) => richW(l, fontSize, weight,
|
|
9397
|
-
const subW = memo((l) => richW(l, subSize, 400,
|
|
9636
|
+
const labelW = memo((l) => richW(l, fontSize, weight, mono, measure, caps, letterSpacing));
|
|
9637
|
+
const subW = memo((l) => richW(l, subSize, 400, mono, measure));
|
|
9398
9638
|
const lines = wrapText(label, maxWidth, labelW);
|
|
9399
9639
|
const subLines = sub ? wrapText(sub, maxWidth, subW) : [];
|
|
9400
9640
|
const lineHeight$1 = lineHeight(lines, fontSize);
|
|
@@ -9631,7 +9871,7 @@ function place(d, opts) {
|
|
|
9631
9871
|
const shape = normalizeShape(p.shape ?? defaultShape);
|
|
9632
9872
|
const caps = p.caps !== void 0 && p.caps !== "false";
|
|
9633
9873
|
const wrap = size(p["max-width"], size(d.settings.wrap, 0));
|
|
9634
|
-
const tb = textBlock(n.label, p.sub, p.icon, style.fontSize, style.fontWeight, theme, measure, caps, wrap);
|
|
9874
|
+
const tb = textBlock(n.label, p.sub, p.icon, style.fontSize, style.fontWeight, theme, measure, caps, wrap, style.mono);
|
|
9635
9875
|
let sz;
|
|
9636
9876
|
if (n.body?.length || p.meta || p.frame) {
|
|
9637
9877
|
tb.card = cardBlock({
|
|
@@ -9855,7 +10095,7 @@ function place(d, opts) {
|
|
|
9855
10095
|
if (Math.abs(rank.get(e.from) - rank.get(e.to)) !== 1) return;
|
|
9856
10096
|
const font = edgeFont(effectiveProps(d, e), theme);
|
|
9857
10097
|
const lines = e.label.split("\n");
|
|
9858
|
-
const ext = horiz ? Math.max(...lines.map((l) => richW(l, font.size, font.weight,
|
|
10098
|
+
const ext = horiz ? Math.max(...lines.map((l) => richW(l, font.size, font.weight, font.mono, measure))) + 16 : lines.length * lineHeight(lines, font.size) + 10;
|
|
9859
10099
|
labelRoom[r] = Math.max(labelRoom[r], ext);
|
|
9860
10100
|
});
|
|
9861
10101
|
const rankPos = [];
|
|
@@ -10234,7 +10474,7 @@ function alignRanks(rank, edges, sets) {
|
|
|
10234
10474
|
if (!changed) return;
|
|
10235
10475
|
}
|
|
10236
10476
|
}
|
|
10237
|
-
const even = (n) => Math.ceil(n / 2) * 2;
|
|
10477
|
+
const even = (n, min = 0) => Math.ceil(Math.max(n, min) / 2) * 2;
|
|
10238
10478
|
function breakCycles(ids, edges) {
|
|
10239
10479
|
const out = /* @__PURE__ */ new Map();
|
|
10240
10480
|
for (const id of ids) out.set(id, []);
|
|
@@ -10525,8 +10765,8 @@ function applyOverrides(d, nodes, horiz, gap) {
|
|
|
10525
10765
|
*/
|
|
10526
10766
|
function groupHeadText(g, theme, measure) {
|
|
10527
10767
|
const p = g.props;
|
|
10528
|
-
const { size, weight, caps, spacing } = groupFont(g, theme);
|
|
10529
|
-
const width = (l) => richW(l, size, weight,
|
|
10768
|
+
const { size, weight, caps, spacing, mono } = groupFont(g, theme);
|
|
10769
|
+
const width = (l) => richW(l, size, weight, mono, measure, caps, spacing);
|
|
10530
10770
|
const meta = p.meta ? richW(p.meta, theme.fontSize * .82, 400, theme.mono, measure) : 0;
|
|
10531
10771
|
return {
|
|
10532
10772
|
text: g.label,
|
|
@@ -10538,7 +10778,7 @@ function groupHeadText(g, theme, measure) {
|
|
|
10538
10778
|
/** a group label's font: `font-size`, `font-weight`, `italic` and `caps` */
|
|
10539
10779
|
function groupFont(g, theme) {
|
|
10540
10780
|
const caps = bool(g.props.caps, false);
|
|
10541
|
-
const font = textFont(g.props, theme.fontSize * .82, 600);
|
|
10781
|
+
const font = textFont(g.props, theme.fontSize * .82, 600, theme);
|
|
10542
10782
|
const size = caps ? font.size * .92 : font.size;
|
|
10543
10783
|
return {
|
|
10544
10784
|
...font,
|
|
@@ -10768,14 +11008,15 @@ function placePanels(d, theme, measure, graph) {
|
|
|
10768
11008
|
h: 0
|
|
10769
11009
|
} : kind.measure(decl.data, ctx);
|
|
10770
11010
|
const head = panelHead(decl.label, ctx.fs);
|
|
10771
|
-
const
|
|
10772
|
-
const
|
|
10773
|
-
const
|
|
11011
|
+
const tf = textFont(decl.props, ctx.fs, 650, theme);
|
|
11012
|
+
const tw = decl.label ? richW(decl.label, ctx.fs * 1.05, tf.weight, tf.mono, measure) : 0;
|
|
11013
|
+
const w = even(Math.max(c.w, tw) + 32, posNum(decl.props.width));
|
|
11014
|
+
const h = even(c.h + head + 32, posNum(decl.props.height));
|
|
10774
11015
|
const inner = {
|
|
10775
11016
|
x: 0,
|
|
10776
11017
|
y: 0,
|
|
10777
11018
|
w: w - 32,
|
|
10778
|
-
h: c.h
|
|
11019
|
+
h: decl.props.height ? h - head - 32 : c.h
|
|
10779
11020
|
};
|
|
10780
11021
|
let handles;
|
|
10781
11022
|
out.push({
|
|
@@ -10844,7 +11085,6 @@ function placePanels(d, theme, measure, graph) {
|
|
|
10844
11085
|
return out;
|
|
10845
11086
|
}
|
|
10846
11087
|
// src/core/render.ts
|
|
10847
|
-
const esc = (s) => s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
10848
11088
|
/** wrap a node in its `link:`; unsafe schemes are dropped (lint reports them) */
|
|
10849
11089
|
function withLink(g, link) {
|
|
10850
11090
|
if (!link || !isSafeLink(link)) return g;
|
|
@@ -10935,10 +11175,10 @@ function renderPanel(p, L, measure, shadow, id) {
|
|
|
10935
11175
|
const s = resolvePanelStyle(p.decl.props, T, base);
|
|
10936
11176
|
const { box } = p;
|
|
10937
11177
|
const capMid = p.ctx.fs * 1.05 * .35;
|
|
10938
|
-
const tf = textFont(p.decl.props, p.ctx.fs, 650);
|
|
11178
|
+
const tf = textFont(p.decl.props, p.ctx.fs, 650, T);
|
|
10939
11179
|
const out = [`<g${attr("data-panel", p.decl.id)}${attr("class", `panel panel-${p.decl.kind}`)}>`];
|
|
10940
11180
|
if (s.framed) out.push(`<rect x="${f(box.x)}" y="${f(box.y)}" width="${f(box.w)}" height="${f(box.h)}" rx="${f(s.radius)}" fill="${s.fill}" stroke="${s.stroke}" stroke-width="${f(s.width)}"${attr("stroke-dasharray", s.dash)}${s.shadow && shadow ? ` filter="url(#${shadow})"` : ""}/>`);
|
|
10941
|
-
if (p.decl.label) out.push(`<text x="${f(box.x + 16)}" y="${f(box.y + 16 + capMid)}" dominant-baseline="central" font-size="${f(p.ctx.fs * 1.05)}" font-weight="${tf.weight}"${tf.italic
|
|
11181
|
+
if (p.decl.label) out.push(`<text x="${f(box.x + 16)}" y="${f(box.y + 16 + capMid)}" dominant-baseline="central" font-size="${f(p.ctx.fs * 1.05)}" font-weight="${tf.weight}"${fontAttrs(tf.italic, tf.family)} fill="${s.text}" xml:space="preserve">${tspans(parseInline(p.decl.label), nodeInk(T, s.text), T)}</text>`);
|
|
10942
11182
|
p.ctx.idPrefix = `${id}-${p.decl.id}`;
|
|
10943
11183
|
if (!p.decl.failed) out.push(kind.render(p.decl.data, p.inner, !measure || measure === p.ctx.measure ? p.ctx : {
|
|
10944
11184
|
...p.ctx,
|
|
@@ -10959,7 +11199,7 @@ function renderGroup(g, L, interactive) {
|
|
|
10959
11199
|
const inset = 14;
|
|
10960
11200
|
const base = g.y + inset + Math.round(font.size * .7);
|
|
10961
11201
|
const body = lines.length > 1 ? textLines(lines, g.x + inset, (i) => base + i * g.lineHeight, (l) => richText(l, ink, T, font.caps)) : richText(text, ink, T, font.caps);
|
|
10962
|
-
const label = text ? `<text x="${f(g.x + inset)}" y="${f(base)}" font-size="${f(font.size)}" font-weight="${font.weight}"${font.italic
|
|
11202
|
+
const label = text ? `<text x="${f(g.x + inset)}" y="${f(base)}" font-size="${f(font.size)}" font-weight="${font.weight}"${fontAttrs(font.italic, font.family)} letter-spacing="${font.caps ? "0.1em" : "0.02em"}" fill="${s.text}" xml:space="preserve">${body}</text>` : "";
|
|
10963
11203
|
const meta = p.meta ? `<text x="${f(g.x + g.w - inset)}" y="${f(base)}" text-anchor="end" font-size="${f(fs)}" fill="${T.node.sub}" xml:space="preserve">${richText(p.meta, subInk(ink), T)}</text>` : "";
|
|
10964
11204
|
return `<g${attr("data-group", g.id)}${interactive ? " cursor=\"move\"" : ""}><rect x="${f(g.x)}" y="${f(g.y)}" width="${f(g.w)}" height="${f(g.h)}" rx="${f(Math.min(14, T.radius + 4))}" fill="${s.fill}" stroke="${s.stroke}" stroke-width="1"${attr("stroke-dasharray", s.dash)}/>` + label + meta + "</g>";
|
|
10965
11205
|
}
|
|
@@ -11014,7 +11254,7 @@ function renderEdgeLabel(e, L) {
|
|
|
11014
11254
|
const text = textLines(lines, ax, (i) => y0 + i * lh, (l) => richText(l, ink, T));
|
|
11015
11255
|
const stroke = T.edge.labelStroke;
|
|
11016
11256
|
const box = `x="${f(ax - w / 2)}" y="${f(ay - h / 2)}" width="${f(w)}" height="${f(h)}" rx="${stroke ? f(h / 2) : 4}"`;
|
|
11017
|
-
parts.push(`<rect ${box} fill="${e.style.labelBg}"` + (stroke ? ` stroke="${stroke}" stroke-width="1"` : "") + "/>", ...groupTint(ax, ay, e, L).map((fill) => `<rect ${box} fill="${fill}"/>`), `<text text-anchor="middle" dominant-baseline="central" font-size="${f(fs)}" font-weight="${s.fontWeight}"${s.italic
|
|
11257
|
+
parts.push(`<rect ${box} fill="${e.style.labelBg}"` + (stroke ? ` stroke="${stroke}" stroke-width="1"` : "") + "/>", ...groupTint(ax, ay, e, L).map((fill) => `<rect ${box} fill="${fill}"/>`), `<text text-anchor="middle" dominant-baseline="central" font-size="${f(fs)}" font-weight="${s.fontWeight}"${fontAttrs(s.italic, s.family)} fill="${s.text}" xml:space="preserve">${text}</text>`);
|
|
11018
11258
|
}
|
|
11019
11259
|
if (lb.caption) {
|
|
11020
11260
|
const cs = fs * .88;
|
|
@@ -11070,7 +11310,7 @@ function renderNode(d, n, L, shadowId) {
|
|
|
11070
11310
|
parts.push(`<text x="${f(cx)}" y="${f(y + tb.iconSize / 2)}" text-anchor="middle" dominant-baseline="central" font-size="${f(tb.iconSize)}">${esc(tb.icon)}</text>`);
|
|
11071
11311
|
y += tb.iconSize + 4;
|
|
11072
11312
|
}
|
|
11073
|
-
const textAttrs = `text-anchor="middle" dominant-baseline="central" font-size="${f(s.fontSize)}" font-weight="${s.fontWeight}" fill="${s.text}"` + (s.italic
|
|
11313
|
+
const textAttrs = `text-anchor="middle" dominant-baseline="central" font-size="${f(s.fontSize)}" font-weight="${s.fontWeight}" fill="${s.text}"` + fontAttrs(s.italic, s.family) + (tb.letterSpacing ? ` letter-spacing="${f(tb.letterSpacing)}"` : "");
|
|
11074
11314
|
const ink = {
|
|
11075
11315
|
text: s.text,
|
|
11076
11316
|
sub: s.sub,
|
|
@@ -11116,7 +11356,7 @@ const ARROWS = /* @__PURE__ */ new Set([
|
|
|
11116
11356
|
"-"
|
|
11117
11357
|
]);
|
|
11118
11358
|
const ID_RE = /^[\p{L}_][\p{L}\p{N}_]*(?:-[\p{L}\p{N}_]+)*$/u;
|
|
11119
|
-
const CLASS_RE = /^[\p{L}_][\p{L}\p{N}_-]*$/u;
|
|
11359
|
+
const CLASS_RE$2 = /^[\p{L}_][\p{L}\p{N}_-]*$/u;
|
|
11120
11360
|
const KEY_RE = /^[\p{L}_][\p{L}\p{N}_-]*$/u;
|
|
11121
11361
|
const q$1 = quote;
|
|
11122
11362
|
function props(bag, skip, errors) {
|
|
@@ -11133,7 +11373,7 @@ function props(bag, skip, errors) {
|
|
|
11133
11373
|
return s ? ` [${s}]` : "";
|
|
11134
11374
|
}
|
|
11135
11375
|
const isObj = (v) => !!v && typeof v === "object" && !Array.isArray(v);
|
|
11136
|
-
const classes = (c, errors) => (Array.isArray(c) ? c : c ? [c] : []).filter((x) => typeof x === "string" && CLASS_RE.test(x) || (errors.push(`class name ${JSON.stringify(x)} is not a valid name`), false)).map((x) => ` .${x}`).join("");
|
|
11376
|
+
const classes = (c, errors) => (Array.isArray(c) ? c : c ? [c] : []).filter((x) => typeof x === "string" && CLASS_RE$2.test(x) || (errors.push(`class name ${JSON.stringify(x)} is not a valid name`), false)).map((x) => ` .${x}`).join("");
|
|
11137
11377
|
const list = (v) => Array.isArray(v) ? v : [v];
|
|
11138
11378
|
function fromJSON(input) {
|
|
11139
11379
|
const errors = [];
|
|
@@ -11174,7 +11414,7 @@ function fromJSON(input) {
|
|
|
11174
11414
|
else out.push(`${k}: ${/[\n\r"'{}]|\s\/\/|^\s|\s$/.test(String(v)) ? q$1(String(v)) : String(v)}`);
|
|
11175
11415
|
if (out.length) out.push("");
|
|
11176
11416
|
const classDefs = Object.entries(bag("classes"));
|
|
11177
|
-
for (const [name, p] of classDefs) if (!CLASS_RE.test(name)) errors.push(`class name ${JSON.stringify(name)} is not a valid name`);
|
|
11417
|
+
for (const [name, p] of classDefs) if (!CLASS_RE$2.test(name)) errors.push(`class name ${JSON.stringify(name)} is not a valid name`);
|
|
11178
11418
|
else if (isObj(p)) out.push(`.${name}${props(p, [], errors)}`);
|
|
11179
11419
|
else errors.push(`class "${name}" must be an object of props`);
|
|
11180
11420
|
if (classDefs.length) out.push("");
|
|
@@ -11292,19 +11532,58 @@ function panel(kind, id, title, props, body) {
|
|
|
11292
11532
|
"}"
|
|
11293
11533
|
];
|
|
11294
11534
|
}
|
|
11295
|
-
/**
|
|
11296
|
-
|
|
11297
|
-
|
|
11535
|
+
/**
|
|
11536
|
+
* `title x`, `title: x` or `title "x"`. Class and state diagrams match only a
|
|
11537
|
+
* lowercase `title`, so a `Title : x` member or description stays one.
|
|
11538
|
+
*/
|
|
11539
|
+
function titleOf(text, ignoreCase = true) {
|
|
11540
|
+
const m = text.match(ignoreCase ? /^title\b\s*:?\s*(.*)$/i : /^title\b\s*:?\s*(.*)$/);
|
|
11298
11541
|
return m ? cleanLabel(m[1]) : void 0;
|
|
11299
11542
|
}
|
|
11300
11543
|
/** statements every diagram type shares; true when handled */
|
|
11544
|
+
/** `accTitle` and `accDescr` lines, which yuhwa skips */
|
|
11545
|
+
const ACC_RE = /^(accTitle|accDescr)\b/;
|
|
11301
11546
|
function common(l, ctx) {
|
|
11302
|
-
if (
|
|
11547
|
+
if (ACC_RE.test(l.text)) {
|
|
11303
11548
|
ctx.warnOnce("acc", l.line, "accessibility titles (accTitle, accDescr) are skipped");
|
|
11304
11549
|
return true;
|
|
11305
11550
|
}
|
|
11306
11551
|
return false;
|
|
11307
11552
|
}
|
|
11553
|
+
/** Runs `read` on every line `common` does not handle, and warns about each line it does not read. */
|
|
11554
|
+
function readLines(cursor, ctx, read) {
|
|
11555
|
+
for (; cursor.index < cursor.lines.length; cursor.index++) {
|
|
11556
|
+
const l = cursor.lines[cursor.index];
|
|
11557
|
+
if (!common(l, ctx) && !read(l)) ctx.warn(l.line, `could not read "${l.text}"`);
|
|
11558
|
+
}
|
|
11559
|
+
}
|
|
11560
|
+
/** Mermaid direction → yuhwa direction */
|
|
11561
|
+
const DIRECTIONS = {
|
|
11562
|
+
TD: "down",
|
|
11563
|
+
TB: "down",
|
|
11564
|
+
BT: "up",
|
|
11565
|
+
LR: "right",
|
|
11566
|
+
RL: "left"
|
|
11567
|
+
};
|
|
11568
|
+
/** a `direction LR` statement */
|
|
11569
|
+
const DIRECTION_RE = /^direction\s+(TD|TB|BT|LR|RL)$/i;
|
|
11570
|
+
const STYLE_RE = /^style\s+(\S+)\s+(.*)$/;
|
|
11571
|
+
/** `style id fill:#f00` → its target and yuhwa props; undefined when not a style */
|
|
11572
|
+
function styleOf(text, warn) {
|
|
11573
|
+
const match = text.match(STYLE_RE);
|
|
11574
|
+
return match ? {
|
|
11575
|
+
target: match[1],
|
|
11576
|
+
props: cssProps(match[2], warn)
|
|
11577
|
+
} : void 0;
|
|
11578
|
+
}
|
|
11579
|
+
const CLASS_DEF_RE = /^classDef\s+([\w,-]+)\s+(.*)$/;
|
|
11580
|
+
/** `classDef a,b fill:#f00` → one yuhwa class line per name; undefined when not a classDef */
|
|
11581
|
+
function classDefLines(text, warn) {
|
|
11582
|
+
const match = text.match(CLASS_DEF_RE);
|
|
11583
|
+
if (!match) return;
|
|
11584
|
+
const props = cssProps(match[2], warn);
|
|
11585
|
+
return match[1].split(",").map((name) => `.${name.trim()} [${props}]`);
|
|
11586
|
+
}
|
|
11308
11587
|
/** `[a, "b c", 3]` → ['a', 'b c', '3'] */
|
|
11309
11588
|
function splitList(s) {
|
|
11310
11589
|
const inner = s.trim().replace(/^\[|\]$/g, "");
|
|
@@ -11377,50 +11656,94 @@ const PALETTE = [
|
|
|
11377
11656
|
* entity becomes a card with a table of its attributes. Relations become
|
|
11378
11657
|
* edges with yuhwa end markers, and cardinalities become the edge caption.
|
|
11379
11658
|
*/
|
|
11380
|
-
const
|
|
11381
|
-
|
|
11382
|
-
|
|
11383
|
-
|
|
11384
|
-
|
|
11385
|
-
|
|
11659
|
+
const QUOTED_RE = /^"(.*)"$/;
|
|
11660
|
+
function newCard(id) {
|
|
11661
|
+
return {
|
|
11662
|
+
id,
|
|
11663
|
+
attrs: [],
|
|
11664
|
+
methods: [],
|
|
11665
|
+
rows: [],
|
|
11666
|
+
classes: []
|
|
11667
|
+
};
|
|
11668
|
+
}
|
|
11669
|
+
function newState(lines, ctx) {
|
|
11670
|
+
return {
|
|
11671
|
+
ctx,
|
|
11672
|
+
lines,
|
|
11673
|
+
index: 0,
|
|
11674
|
+
cards: /* @__PURE__ */ new Map(),
|
|
11675
|
+
root: {
|
|
11676
|
+
id: "",
|
|
11677
|
+
label: "",
|
|
11678
|
+
items: []
|
|
11679
|
+
},
|
|
11680
|
+
rels: [],
|
|
11681
|
+
direction: "down",
|
|
11682
|
+
title: ctx.title
|
|
11683
|
+
};
|
|
11684
|
+
}
|
|
11685
|
+
/** Runs the first matching statement reader on every line. */
|
|
11686
|
+
function readStatements$1(state, statements) {
|
|
11687
|
+
readLines(state, state.ctx, ({ text, line }) => statements.some((read) => read(text, state, line)));
|
|
11688
|
+
}
|
|
11689
|
+
/** Calls `onLine` for each line up to the closing `}`, leaving the index on it. */
|
|
11690
|
+
function readBlock(state, onLine) {
|
|
11691
|
+
while (++state.index < state.lines.length && state.lines[state.index].text !== "}") onLine(state.lines[state.index]);
|
|
11692
|
+
}
|
|
11693
|
+
const readTitle = (text, state) => {
|
|
11694
|
+
const title = titleOf(text, false);
|
|
11695
|
+
if (title !== void 0) state.title = title;
|
|
11696
|
+
return title !== void 0;
|
|
11697
|
+
};
|
|
11698
|
+
const readDirection = (text, state) => {
|
|
11699
|
+
const match = text.match(DIRECTION_RE);
|
|
11700
|
+
if (match) state.direction = DIRECTIONS[match[1].toUpperCase()];
|
|
11701
|
+
return !!match;
|
|
11386
11702
|
};
|
|
11387
|
-
function
|
|
11388
|
-
const head = [
|
|
11389
|
-
if (
|
|
11390
|
-
for (const
|
|
11703
|
+
function cardHeader(card) {
|
|
11704
|
+
const head = [card.id];
|
|
11705
|
+
if (card.label !== void 0 && card.label !== card.id) head.push(q(card.label));
|
|
11706
|
+
for (const name of card.classes) head.push(`.${name}`);
|
|
11391
11707
|
const props = [];
|
|
11392
|
-
if (
|
|
11393
|
-
if (
|
|
11394
|
-
if (
|
|
11708
|
+
if (card.note) props.push("shape: note");
|
|
11709
|
+
if (card.sub) props.push(`sub: ${q(card.sub)}`);
|
|
11710
|
+
if (card.style) props.push(card.style);
|
|
11395
11711
|
if (props.length) head.push(`[${props.join(", ")}]`);
|
|
11396
|
-
|
|
11397
|
-
|
|
11398
|
-
|
|
11399
|
-
|
|
11712
|
+
return head;
|
|
11713
|
+
}
|
|
11714
|
+
/** table rows for an entity, else attributes and methods split by a rule */
|
|
11715
|
+
function cardBody(card) {
|
|
11716
|
+
if (card.rows.length) return card.rows;
|
|
11717
|
+
const rule = card.attrs.length && card.methods.length ? ["---"] : [];
|
|
11718
|
+
return [
|
|
11719
|
+
...card.attrs,
|
|
11720
|
+
...rule,
|
|
11721
|
+
...card.methods
|
|
11400
11722
|
];
|
|
11723
|
+
}
|
|
11724
|
+
function cardLines(card, pad) {
|
|
11725
|
+
const head = cardHeader(card);
|
|
11726
|
+
const body = cardBody(card);
|
|
11401
11727
|
if (!body.length) return [pad + head.join(" ")];
|
|
11402
|
-
if (head.length === 1) head.push(q(
|
|
11728
|
+
if (head.length === 1) head.push(q(card.id));
|
|
11403
11729
|
return [
|
|
11404
11730
|
`${pad}${head.join(" ")} {`,
|
|
11405
|
-
...body.map((
|
|
11731
|
+
...body.map((row) => `${pad} ${row}`),
|
|
11406
11732
|
`${pad}}`
|
|
11407
11733
|
];
|
|
11408
11734
|
}
|
|
11409
|
-
function
|
|
11410
|
-
const
|
|
11411
|
-
|
|
11412
|
-
|
|
11413
|
-
|
|
11414
|
-
|
|
11415
|
-
|
|
11416
|
-
}
|
|
11417
|
-
if (rels.length) out.push("");
|
|
11418
|
-
|
|
11419
|
-
const tail = [r.label ? edgeLabel(r.label) : "", r.props.length ? `[${r.props.join(", ")}]` : ""].filter(Boolean).join(" ");
|
|
11420
|
-
out.push(`${r.from} ${r.arrow} ${r.to}${tail ? ": " + tail : ""}`);
|
|
11421
|
-
}
|
|
11735
|
+
function relLine(rel) {
|
|
11736
|
+
const tail = [rel.label ? edgeLabel(rel.label) : "", rel.props.length ? `[${rel.props.join(", ")}]` : ""].filter(Boolean).join(" ");
|
|
11737
|
+
return `${rel.from} ${rel.arrow} ${rel.to}${tail ? ": " + tail : ""}`;
|
|
11738
|
+
}
|
|
11739
|
+
function emit(state, classDefs, scopes) {
|
|
11740
|
+
const cardsOf = (scope, pad) => scope.items.flatMap((id) => cardLines(state.cards.get(id), pad));
|
|
11741
|
+
const out = cardsOf(state.root, "");
|
|
11742
|
+
for (const scope of scopes) out.push(`group ${scope.id} ${q(scope.label)} {`, ...cardsOf(scope, " "), "}");
|
|
11743
|
+
if (state.rels.length) out.push("");
|
|
11744
|
+
out.push(...state.rels.map(relLine));
|
|
11422
11745
|
return [
|
|
11423
|
-
...[title ? `title: ${title}` : "", `direction: ${direction}`].filter(Boolean),
|
|
11746
|
+
...[state.title ? `title: ${state.title}` : "", `direction: ${state.direction}`].filter(Boolean),
|
|
11424
11747
|
...classDefs.length ? ["", ...classDefs] : [],
|
|
11425
11748
|
"",
|
|
11426
11749
|
...out
|
|
@@ -11436,174 +11759,173 @@ const MARK = table({
|
|
|
11436
11759
|
});
|
|
11437
11760
|
const REL_SPACED = /^(\S+?)\s+(?:"([^"]*)"\s+)?(<\||\*|o|<|)(--|\.\.)(\|>|\*|o|>|)\s+(?:"([^"]*)"\s+)?(\S+?)\s*(?::\s*(.*))?$/;
|
|
11438
11761
|
const REL_TIGHT = /^([^\s<*.-]+?)\s*(?:"([^"]*)"\s*)?(<\||\*|<|)(--|\.\.)(\|>|\*|>|)\s*(?:"([^"]*)"\s*)?([^\s:]+?)\s*(?::\s*(.*))?$/;
|
|
11762
|
+
/** `class Name~T~["Label"]:::style {` with optional generic, label, style class and body */
|
|
11763
|
+
const CLASS_RE$1 = /^class\s+([^\s[{:~]+)(~[^~]+~)?(?:\["([^"]*)"\])?(?::::([\w-]+))?\s*(\{)?\s*(\})?$/;
|
|
11764
|
+
const NAMESPACE_RE = /^namespace\s+(\S+)\s*\{$/;
|
|
11765
|
+
const ANNOTATION_RE = /^<<(.+)>>$/;
|
|
11766
|
+
const ANNOTATION_FOR_RE = /^<<(.+)>>\s+(\S+)$/;
|
|
11767
|
+
const NOTE_FOR_RE = /^note\s+for\s+(\S+)\s+"(.*)"$/;
|
|
11768
|
+
const NOTE_RE$2 = /^note\s+"(.*)"$/;
|
|
11769
|
+
const CSS_CLASS_RE = /^cssClass\s+"([^"]+)"\s+([\w-]+)$/;
|
|
11770
|
+
const INTERACTION_RE = /^(click|callback|link)\b/;
|
|
11771
|
+
const MEMBER_RE = /^([^\s:]+)\s*:\s*(.*)$/;
|
|
11439
11772
|
const generic = (s) => s.replace(/~([^~]*)~/g, "<$1>");
|
|
11440
11773
|
const bare = (s) => s.replace(/~[^~]*~/g, "");
|
|
11774
|
+
const stereotype = (s) => `«${s.trim()}»`;
|
|
11775
|
+
/** the card for a class name, created in the current namespace on first use */
|
|
11776
|
+
function classCard(state, raw) {
|
|
11777
|
+
const id = toId(bare(raw));
|
|
11778
|
+
let card = state.cards.get(id);
|
|
11779
|
+
if (!card) {
|
|
11780
|
+
card = newCard(id);
|
|
11781
|
+
if (id !== raw || /~/.test(raw)) card.label = generic(raw.replace(QUOTED_RE, "$1"));
|
|
11782
|
+
state.cards.set(id, card);
|
|
11783
|
+
state.scope.items.push(id);
|
|
11784
|
+
}
|
|
11785
|
+
return card;
|
|
11786
|
+
}
|
|
11787
|
+
/** an attribute, a method (has parentheses) or a `<<stereotype>>` line */
|
|
11788
|
+
function addMember(card, raw) {
|
|
11789
|
+
const text = generic(raw.trim());
|
|
11790
|
+
if (!text) return;
|
|
11791
|
+
const annotation = text.match(ANNOTATION_RE);
|
|
11792
|
+
if (annotation) card.sub = stereotype(annotation[1]);
|
|
11793
|
+
else (text.includes("(") ? card.methods : card.attrs).push(text);
|
|
11794
|
+
}
|
|
11795
|
+
function addNote(state, label) {
|
|
11796
|
+
const id = `note${++state.notes}`;
|
|
11797
|
+
state.cards.set(id, {
|
|
11798
|
+
...newCard(id),
|
|
11799
|
+
label: cleanLabel(label),
|
|
11800
|
+
note: true
|
|
11801
|
+
});
|
|
11802
|
+
state.scope.items.push(id);
|
|
11803
|
+
return id;
|
|
11804
|
+
}
|
|
11805
|
+
const readNamespace = (text, state) => {
|
|
11806
|
+
const match = text.match(NAMESPACE_RE);
|
|
11807
|
+
if (match) {
|
|
11808
|
+
state.scope = {
|
|
11809
|
+
id: toId(match[1]),
|
|
11810
|
+
label: match[1],
|
|
11811
|
+
items: []
|
|
11812
|
+
};
|
|
11813
|
+
state.scopes.push(state.scope);
|
|
11814
|
+
}
|
|
11815
|
+
return !!match;
|
|
11816
|
+
};
|
|
11817
|
+
const readNamespaceEnd = (text, state, line) => {
|
|
11818
|
+
if (text !== "}") return false;
|
|
11819
|
+
if (state.scope !== state.root) state.scope = state.root;
|
|
11820
|
+
else state.ctx.warn(line, "\"}\" without a namespace");
|
|
11821
|
+
return true;
|
|
11822
|
+
};
|
|
11823
|
+
const readClass = (text, state) => {
|
|
11824
|
+
const match = text.match(CLASS_RE$1);
|
|
11825
|
+
if (!match) return false;
|
|
11826
|
+
const [, name, genericPart, label, styleClass, open, close] = match;
|
|
11827
|
+
const card = classCard(state, name + (genericPart ?? ""));
|
|
11828
|
+
if (label !== void 0) card.label = oneLine(label);
|
|
11829
|
+
if (styleClass) card.classes.push(styleClass);
|
|
11830
|
+
if (open && !close) readBlock(state, (line) => addMember(card, line.text));
|
|
11831
|
+
return true;
|
|
11832
|
+
};
|
|
11833
|
+
const readAnnotation = (text, state) => {
|
|
11834
|
+
const match = text.match(ANNOTATION_FOR_RE);
|
|
11835
|
+
if (match) classCard(state, match[2]).sub = stereotype(match[1]);
|
|
11836
|
+
return !!match;
|
|
11837
|
+
};
|
|
11838
|
+
const readNoteFor = (text, state) => {
|
|
11839
|
+
const match = text.match(NOTE_FOR_RE);
|
|
11840
|
+
if (match) {
|
|
11841
|
+
const id = addNote(state, match[2]);
|
|
11842
|
+
state.rels.push({
|
|
11843
|
+
from: id,
|
|
11844
|
+
to: classCard(state, match[1]).id,
|
|
11845
|
+
arrow: "..",
|
|
11846
|
+
props: []
|
|
11847
|
+
});
|
|
11848
|
+
}
|
|
11849
|
+
return !!match;
|
|
11850
|
+
};
|
|
11851
|
+
const readNote = (text, state) => {
|
|
11852
|
+
const match = text.match(NOTE_RE$2);
|
|
11853
|
+
if (match) addNote(state, match[1]);
|
|
11854
|
+
return !!match;
|
|
11855
|
+
};
|
|
11856
|
+
const readClassDef = (text, state, line) => {
|
|
11857
|
+
const lines = classDefLines(text, (message) => state.ctx.warn(line, message));
|
|
11858
|
+
state.classDefs.push(...lines ?? []);
|
|
11859
|
+
return !!lines;
|
|
11860
|
+
};
|
|
11861
|
+
const readCssClass = (text, state) => {
|
|
11862
|
+
const match = text.match(CSS_CLASS_RE);
|
|
11863
|
+
if (match) for (const name of match[1].split(",")) classCard(state, name.trim()).classes.push(match[2]);
|
|
11864
|
+
return !!match;
|
|
11865
|
+
};
|
|
11866
|
+
const readStyle = (text, state, line) => {
|
|
11867
|
+
const style = styleOf(text, (message) => state.ctx.warn(line, message));
|
|
11868
|
+
if (style) classCard(state, style.target).style = style.props;
|
|
11869
|
+
return !!style;
|
|
11870
|
+
};
|
|
11871
|
+
const skipInteraction = (text, state, line) => {
|
|
11872
|
+
if (!INTERACTION_RE.test(text)) return false;
|
|
11873
|
+
state.ctx.warnOnce("click", line, "click, link and callback are skipped");
|
|
11874
|
+
return true;
|
|
11875
|
+
};
|
|
11876
|
+
/** `A "1" <|-- "*" B : label`: end markers become head/tail, cardinalities the caption */
|
|
11877
|
+
const readRelation = (text, state, line) => {
|
|
11878
|
+
const match = text.match(REL_SPACED) ?? text.match(REL_TIGHT);
|
|
11879
|
+
if (!match) return false;
|
|
11880
|
+
const [, from, fromCount, tailMark, arrow, headMark, toCount, to, label] = match;
|
|
11881
|
+
const props = [];
|
|
11882
|
+
if (tailMark) props.push(`tail: ${MARK[tailMark]}`);
|
|
11883
|
+
if (headMark) props.push(`head: ${MARK[headMark]}`);
|
|
11884
|
+
if (tailMark === "o" || headMark === "o") state.ctx.warnOnce("aggr", line, "aggregation (o--) is drawn with a filled diamond, like composition");
|
|
11885
|
+
const counts = [fromCount, toCount].filter((count) => count !== void 0);
|
|
11886
|
+
if (counts.length) props.push(`caption: ${q(counts.join(" to "))}`);
|
|
11887
|
+
state.rels.push({
|
|
11888
|
+
from: classCard(state, from).id,
|
|
11889
|
+
to: classCard(state, to).id,
|
|
11890
|
+
arrow,
|
|
11891
|
+
props,
|
|
11892
|
+
label: label ? oneLine(label) : void 0
|
|
11893
|
+
});
|
|
11894
|
+
return true;
|
|
11895
|
+
};
|
|
11896
|
+
/** `Name : +member` outside a class body */
|
|
11897
|
+
const readMember = (text, state) => {
|
|
11898
|
+
const match = text.match(MEMBER_RE);
|
|
11899
|
+
if (match) addMember(classCard(state, match[1]), match[2]);
|
|
11900
|
+
return !!match;
|
|
11901
|
+
};
|
|
11902
|
+
const CLASS_STATEMENTS = [
|
|
11903
|
+
readTitle,
|
|
11904
|
+
readDirection,
|
|
11905
|
+
readNamespace,
|
|
11906
|
+
readNamespaceEnd,
|
|
11907
|
+
readClass,
|
|
11908
|
+
readAnnotation,
|
|
11909
|
+
readNoteFor,
|
|
11910
|
+
readNote,
|
|
11911
|
+
readClassDef,
|
|
11912
|
+
readCssClass,
|
|
11913
|
+
readStyle,
|
|
11914
|
+
skipInteraction,
|
|
11915
|
+
readRelation,
|
|
11916
|
+
readMember
|
|
11917
|
+
];
|
|
11441
11918
|
const classDiagram = (lines, ctx) => {
|
|
11442
|
-
const
|
|
11443
|
-
const
|
|
11444
|
-
|
|
11445
|
-
|
|
11446
|
-
|
|
11447
|
-
|
|
11448
|
-
|
|
11449
|
-
let scope = root;
|
|
11450
|
-
const rels = [];
|
|
11451
|
-
const classDefs = [];
|
|
11452
|
-
let direction = "down";
|
|
11453
|
-
let title = ctx.title;
|
|
11454
|
-
let notes = 0;
|
|
11455
|
-
const card = (raw) => {
|
|
11456
|
-
const id = toId(bare(raw));
|
|
11457
|
-
let c = cards.get(id);
|
|
11458
|
-
if (!c) {
|
|
11459
|
-
c = {
|
|
11460
|
-
id,
|
|
11461
|
-
attrs: [],
|
|
11462
|
-
methods: [],
|
|
11463
|
-
rows: [],
|
|
11464
|
-
classes: []
|
|
11465
|
-
};
|
|
11466
|
-
if (id !== raw || /~/.test(raw)) c.label = generic(raw.replace(/^"(.*)"$/, "$1"));
|
|
11467
|
-
cards.set(id, c);
|
|
11468
|
-
scope.items.push(id);
|
|
11469
|
-
}
|
|
11470
|
-
return c;
|
|
11471
|
-
};
|
|
11472
|
-
const member = (c, m) => {
|
|
11473
|
-
const t = generic(m.trim());
|
|
11474
|
-
if (!t) return;
|
|
11475
|
-
const anno = t.match(/^<<(.+)>>$/);
|
|
11476
|
-
if (anno) c.sub = `«${anno[1].trim()}»`;
|
|
11477
|
-
else (t.includes("(") ? c.methods : c.attrs).push(t);
|
|
11919
|
+
const base = newState(lines, ctx);
|
|
11920
|
+
const state = {
|
|
11921
|
+
...base,
|
|
11922
|
+
scopes: [],
|
|
11923
|
+
scope: base.root,
|
|
11924
|
+
classDefs: [],
|
|
11925
|
+
notes: 0
|
|
11478
11926
|
};
|
|
11479
|
-
|
|
11480
|
-
|
|
11481
|
-
const t = l.text;
|
|
11482
|
-
const warn = (m) => ctx.warn(l.line, m);
|
|
11483
|
-
if (/^(accTitle|accDescr)\b/.test(t)) {
|
|
11484
|
-
ctx.warnOnce("acc", l.line, "accessibility titles (accTitle, accDescr) are skipped");
|
|
11485
|
-
continue;
|
|
11486
|
-
}
|
|
11487
|
-
const tt = t.match(/^title\s*:?\s*(.*)$/);
|
|
11488
|
-
if (tt) {
|
|
11489
|
-
title = cleanLabel(tt[1]);
|
|
11490
|
-
continue;
|
|
11491
|
-
}
|
|
11492
|
-
const d = t.match(/^direction\s+(TD|TB|BT|LR|RL)$/i);
|
|
11493
|
-
if (d) {
|
|
11494
|
-
direction = DIRECTIONS$2[d[1].toUpperCase()];
|
|
11495
|
-
continue;
|
|
11496
|
-
}
|
|
11497
|
-
const ns = t.match(/^namespace\s+(\S+)\s*\{$/);
|
|
11498
|
-
if (ns) {
|
|
11499
|
-
scope = {
|
|
11500
|
-
id: toId(ns[1]),
|
|
11501
|
-
label: ns[1],
|
|
11502
|
-
items: []
|
|
11503
|
-
};
|
|
11504
|
-
scopes.push(scope);
|
|
11505
|
-
continue;
|
|
11506
|
-
}
|
|
11507
|
-
if (t === "}") {
|
|
11508
|
-
if (scope !== root) scope = root;
|
|
11509
|
-
else warn("\"}\" without a namespace");
|
|
11510
|
-
continue;
|
|
11511
|
-
}
|
|
11512
|
-
const cl = t.match(/^class\s+([^\s[{:~]+)(~[^~]+~)?(?:\["([^"]*)"\])?(?::::([\w-]+))?\s*(\{)?\s*(\})?$/);
|
|
11513
|
-
if (cl) {
|
|
11514
|
-
const c = card(cl[1] + (cl[2] ?? ""));
|
|
11515
|
-
if (cl[3] !== void 0) c.label = oneLine(cl[3]);
|
|
11516
|
-
if (cl[4]) c.classes.push(cl[4]);
|
|
11517
|
-
if (cl[5] && !cl[6]) while (++i < lines.length && lines[i].text !== "}") member(c, lines[i].text);
|
|
11518
|
-
continue;
|
|
11519
|
-
}
|
|
11520
|
-
const an = t.match(/^<<(.+)>>\s+(\S+)$/);
|
|
11521
|
-
if (an) {
|
|
11522
|
-
card(an[2]).sub = `«${an[1].trim()}»`;
|
|
11523
|
-
continue;
|
|
11524
|
-
}
|
|
11525
|
-
const nf = t.match(/^note\s+for\s+(\S+)\s+"(.*)"$/);
|
|
11526
|
-
if (nf) {
|
|
11527
|
-
const id = `note${++notes}`;
|
|
11528
|
-
cards.set(id, {
|
|
11529
|
-
id,
|
|
11530
|
-
label: cleanLabel(nf[2]),
|
|
11531
|
-
attrs: [],
|
|
11532
|
-
methods: [],
|
|
11533
|
-
rows: [],
|
|
11534
|
-
classes: [],
|
|
11535
|
-
note: true
|
|
11536
|
-
});
|
|
11537
|
-
scope.items.push(id);
|
|
11538
|
-
rels.push({
|
|
11539
|
-
from: id,
|
|
11540
|
-
to: card(nf[1]).id,
|
|
11541
|
-
arrow: "..",
|
|
11542
|
-
props: []
|
|
11543
|
-
});
|
|
11544
|
-
continue;
|
|
11545
|
-
}
|
|
11546
|
-
const n = t.match(/^note\s+"(.*)"$/);
|
|
11547
|
-
if (n) {
|
|
11548
|
-
const id = `note${++notes}`;
|
|
11549
|
-
cards.set(id, {
|
|
11550
|
-
id,
|
|
11551
|
-
label: cleanLabel(n[1]),
|
|
11552
|
-
attrs: [],
|
|
11553
|
-
methods: [],
|
|
11554
|
-
rows: [],
|
|
11555
|
-
classes: [],
|
|
11556
|
-
note: true
|
|
11557
|
-
});
|
|
11558
|
-
scope.items.push(id);
|
|
11559
|
-
continue;
|
|
11560
|
-
}
|
|
11561
|
-
const cd = t.match(/^classDef\s+([\w,-]+)\s+(.*)$/);
|
|
11562
|
-
if (cd) {
|
|
11563
|
-
const props = cssProps(cd[2], warn);
|
|
11564
|
-
for (const name of cd[1].split(",")) classDefs.push(`.${name.trim()} [${props}]`);
|
|
11565
|
-
continue;
|
|
11566
|
-
}
|
|
11567
|
-
const cc = t.match(/^cssClass\s+"([^"]+)"\s+([\w-]+)$/);
|
|
11568
|
-
if (cc) {
|
|
11569
|
-
for (const name of cc[1].split(",")) card(name.trim()).classes.push(cc[2]);
|
|
11570
|
-
continue;
|
|
11571
|
-
}
|
|
11572
|
-
const sty = t.match(/^style\s+(\S+)\s+(.*)$/);
|
|
11573
|
-
if (sty) {
|
|
11574
|
-
card(sty[1]).style = cssProps(sty[2], warn);
|
|
11575
|
-
continue;
|
|
11576
|
-
}
|
|
11577
|
-
if (/^(click|callback|link)\b/.test(t)) {
|
|
11578
|
-
ctx.warnOnce("click", l.line, "click, link and callback are skipped");
|
|
11579
|
-
continue;
|
|
11580
|
-
}
|
|
11581
|
-
const r = t.match(REL_SPACED) ?? t.match(REL_TIGHT);
|
|
11582
|
-
if (r) {
|
|
11583
|
-
const [, a, ca, ta, line, hb, cb, b, label] = r;
|
|
11584
|
-
const props = [];
|
|
11585
|
-
if (ta) props.push(`tail: ${MARK[ta]}`);
|
|
11586
|
-
if (hb) props.push(`head: ${MARK[hb]}`);
|
|
11587
|
-
if (ta === "o" || hb === "o") ctx.warnOnce("aggr", l.line, "aggregation (o--) is drawn with a filled diamond, like composition");
|
|
11588
|
-
const card2 = [ca, cb].filter((x) => x !== void 0);
|
|
11589
|
-
if (card2.length) props.push(`caption: ${q(card2.join(" to "))}`);
|
|
11590
|
-
rels.push({
|
|
11591
|
-
from: card(a).id,
|
|
11592
|
-
to: card(b).id,
|
|
11593
|
-
arrow: line,
|
|
11594
|
-
props,
|
|
11595
|
-
label: label ? oneLine(label) : void 0
|
|
11596
|
-
});
|
|
11597
|
-
continue;
|
|
11598
|
-
}
|
|
11599
|
-
const mem = t.match(/^([^\s:]+)\s*:\s*(.*)$/);
|
|
11600
|
-
if (mem) {
|
|
11601
|
-
member(card(mem[1]), mem[2]);
|
|
11602
|
-
continue;
|
|
11603
|
-
}
|
|
11604
|
-
warn(`could not read "${t}"`);
|
|
11605
|
-
}
|
|
11606
|
-
return emit(title, direction, classDefs, cards, root, scopes, rels);
|
|
11927
|
+
readStatements$1(state, CLASS_STATEMENTS);
|
|
11928
|
+
return emit(state, state.classDefs, state.scopes);
|
|
11607
11929
|
};
|
|
11608
11930
|
const LEFT = {
|
|
11609
11931
|
"||": "1",
|
|
@@ -11619,107 +11941,98 @@ const RIGHT = {
|
|
|
11619
11941
|
};
|
|
11620
11942
|
const ER_REL = /^("[^"]*"|[^\s|}o{]+?)\s*(\|\||\|o|\}\||\}o)(--|\.\.)(\|\||o\||\|\{|o\{)\s*("[^"]*"|\S+?)\s*:\s*(.*)$/;
|
|
11621
11943
|
const ER_ATTR = /^(\S+)\s+(\S+)((?:\s+(?:PK|FK|UK)(?:\s*,\s*(?:PK|FK|UK))*)?)(?:\s+"([^"]*)")?$/;
|
|
11622
|
-
|
|
11623
|
-
|
|
11624
|
-
|
|
11625
|
-
|
|
11626
|
-
|
|
11627
|
-
|
|
11628
|
-
|
|
11629
|
-
|
|
11630
|
-
|
|
11631
|
-
|
|
11632
|
-
|
|
11633
|
-
|
|
11634
|
-
|
|
11635
|
-
|
|
11636
|
-
|
|
11637
|
-
|
|
11638
|
-
|
|
11639
|
-
|
|
11640
|
-
|
|
11641
|
-
|
|
11642
|
-
|
|
11643
|
-
|
|
11644
|
-
|
|
11645
|
-
|
|
11646
|
-
|
|
11647
|
-
}
|
|
11648
|
-
return c;
|
|
11649
|
-
};
|
|
11650
|
-
for (let i = 0; i < lines.length; i++) {
|
|
11651
|
-
const l = lines[i];
|
|
11652
|
-
const t = l.text;
|
|
11653
|
-
if (/^(accTitle|accDescr)\b/.test(t)) {
|
|
11654
|
-
ctx.warnOnce("acc", l.line, "accessibility titles (accTitle, accDescr) are skipped");
|
|
11655
|
-
continue;
|
|
11656
|
-
}
|
|
11657
|
-
const tt = t.match(/^title\s*:?\s*(.*)$/);
|
|
11658
|
-
if (tt) {
|
|
11659
|
-
title = cleanLabel(tt[1]);
|
|
11660
|
-
continue;
|
|
11661
|
-
}
|
|
11662
|
-
const d = t.match(/^direction\s+(TD|TB|BT|LR|RL)$/i);
|
|
11663
|
-
if (d) {
|
|
11664
|
-
direction = DIRECTIONS$2[d[1].toUpperCase()];
|
|
11665
|
-
continue;
|
|
11666
|
-
}
|
|
11667
|
-
const blk = t.match(/^("[^"]*"|[^\s[{]+)\s*(?:\["?([^"\]]*)"?\])?\s*\{\s*(\})?$/);
|
|
11668
|
-
if (blk) {
|
|
11669
|
-
const c = entity(blk[1]);
|
|
11670
|
-
if (blk[2] !== void 0) c.label = blk[2];
|
|
11671
|
-
if (blk[3]) continue;
|
|
11672
|
-
while (++i < lines.length && lines[i].text !== "}") {
|
|
11673
|
-
const a = lines[i].text.match(ER_ATTR);
|
|
11674
|
-
if (!a) {
|
|
11675
|
-
ctx.warn(lines[i].line, `could not read attribute "${lines[i].text}"`);
|
|
11676
|
-
continue;
|
|
11677
|
-
}
|
|
11678
|
-
const keys = a[3].replace(/\s+/g, "").replace(/,/g, ", ");
|
|
11679
|
-
const cells = [
|
|
11680
|
-
a[1],
|
|
11681
|
-
a[2],
|
|
11682
|
-
keys,
|
|
11683
|
-
a[4] ?? ""
|
|
11684
|
-
].map((x) => x.replace(/\|/g, "/"));
|
|
11685
|
-
c.rows.push(`| ${cells.join(" | ")} |`);
|
|
11686
|
-
}
|
|
11687
|
-
continue;
|
|
11688
|
-
}
|
|
11689
|
-
const r = t.match(ER_REL);
|
|
11690
|
-
if (r) {
|
|
11691
|
-
const [, a, ea, line, eb, b, label] = r;
|
|
11692
|
-
rels.push({
|
|
11693
|
-
from: entity(a).id,
|
|
11694
|
-
to: entity(b).id,
|
|
11695
|
-
arrow: line === ".." ? ".." : "--",
|
|
11696
|
-
props: [`caption: ${q(`${LEFT[ea]} to ${RIGHT[eb]}`)}`],
|
|
11697
|
-
label: oneLine(label) || void 0
|
|
11698
|
-
});
|
|
11699
|
-
continue;
|
|
11700
|
-
}
|
|
11701
|
-
const al = t.match(/^("[^"]*"|[^\s[]+)\s*\["?([^"\]]*)"?\]$/);
|
|
11702
|
-
if (al) {
|
|
11703
|
-
entity(al[1]).label = al[2];
|
|
11704
|
-
continue;
|
|
11705
|
-
}
|
|
11706
|
-
if (/^(classDef|class|style)\b/.test(t)) {
|
|
11707
|
-
ctx.warnOnce("erstyle", l.line, "ER styles and classes are skipped");
|
|
11708
|
-
continue;
|
|
11709
|
-
}
|
|
11710
|
-
if (/^("[^"]*"|[\w-]+)$/.test(t)) {
|
|
11711
|
-
entity(t);
|
|
11712
|
-
continue;
|
|
11713
|
-
}
|
|
11714
|
-
ctx.warn(l.line, `could not read "${t}"`);
|
|
11944
|
+
/** `NAME["Label"] {` opening an attribute block, or `NAME {}` */
|
|
11945
|
+
const ER_BLOCK = /^("[^"]*"|[^\s[{]+)\s*(?:\["?([^"\]]*)"?\])?\s*\{\s*(\})?$/;
|
|
11946
|
+
/** `NAME["Label"]` alias without a block */
|
|
11947
|
+
const ER_ALIAS = /^("[^"]*"|[^\s[]+)\s*\["?([^"\]]*)"?\]$/;
|
|
11948
|
+
const ER_STYLE = /^(classDef|class|style)\b/;
|
|
11949
|
+
const ER_NAME = /^("[^"]*"|[\w-]+)$/;
|
|
11950
|
+
/** the card for an entity name, created on first use */
|
|
11951
|
+
function entity(state, raw) {
|
|
11952
|
+
const name = raw.replace(QUOTED_RE, "$1");
|
|
11953
|
+
const id = toId(name);
|
|
11954
|
+
let card = state.cards.get(id);
|
|
11955
|
+
if (!card) {
|
|
11956
|
+
card = newCard(id);
|
|
11957
|
+
if (id !== name) card.label = name;
|
|
11958
|
+
state.cards.set(id, card);
|
|
11959
|
+
state.root.items.push(id);
|
|
11960
|
+
}
|
|
11961
|
+
return card;
|
|
11962
|
+
}
|
|
11963
|
+
/** `type name PK, FK "comment"` → a table row; `|` would split the cell, so it becomes `/` */
|
|
11964
|
+
function addAttribute(state, card, line) {
|
|
11965
|
+
const match = line.text.match(ER_ATTR);
|
|
11966
|
+
if (!match) {
|
|
11967
|
+
state.ctx.warn(line.line, `could not read attribute "${line.text}"`);
|
|
11968
|
+
return;
|
|
11715
11969
|
}
|
|
11716
|
-
|
|
11970
|
+
const [, type, name, keyList, comment] = match;
|
|
11971
|
+
const cells = [
|
|
11972
|
+
type,
|
|
11973
|
+
name,
|
|
11974
|
+
keyList.replace(/\s+/g, "").replace(/,/g, ", "),
|
|
11975
|
+
comment ?? ""
|
|
11976
|
+
].map((cell) => cell.replace(/\|/g, "/"));
|
|
11977
|
+
card.rows.push(`| ${cells.join(" | ")} |`);
|
|
11978
|
+
}
|
|
11979
|
+
const readEntityBlock = (text, state) => {
|
|
11980
|
+
const match = text.match(ER_BLOCK);
|
|
11981
|
+
if (!match) return false;
|
|
11982
|
+
const [, name, label, closed] = match;
|
|
11983
|
+
const card = entity(state, name);
|
|
11984
|
+
if (label !== void 0) card.label = label;
|
|
11985
|
+
if (!closed) readBlock(state, (line) => addAttribute(state, card, line));
|
|
11986
|
+
return true;
|
|
11717
11987
|
};
|
|
11718
|
-
|
|
11719
|
-
|
|
11720
|
-
|
|
11721
|
-
|
|
11988
|
+
const readEntityRelation = (text, state) => {
|
|
11989
|
+
const match = text.match(ER_REL);
|
|
11990
|
+
if (!match) return false;
|
|
11991
|
+
const [, from, fromEnd, arrow, toEnd, to, label] = match;
|
|
11992
|
+
state.rels.push({
|
|
11993
|
+
from: entity(state, from).id,
|
|
11994
|
+
to: entity(state, to).id,
|
|
11995
|
+
arrow: arrow === ".." ? ".." : "--",
|
|
11996
|
+
props: [`caption: ${q(`${LEFT[fromEnd]} to ${RIGHT[toEnd]}`)}`],
|
|
11997
|
+
label: oneLine(label) || void 0
|
|
11998
|
+
});
|
|
11999
|
+
return true;
|
|
12000
|
+
};
|
|
12001
|
+
const readEntityAlias = (text, state) => {
|
|
12002
|
+
const match = text.match(ER_ALIAS);
|
|
12003
|
+
if (match) entity(state, match[1]).label = match[2];
|
|
12004
|
+
return !!match;
|
|
12005
|
+
};
|
|
12006
|
+
const skipEntityStyle = (text, state, line) => {
|
|
12007
|
+
if (!ER_STYLE.test(text)) return false;
|
|
12008
|
+
state.ctx.warnOnce("erstyle", line, "ER styles and classes are skipped");
|
|
12009
|
+
return true;
|
|
12010
|
+
};
|
|
12011
|
+
const readEntityName = (text, state) => {
|
|
12012
|
+
if (!ER_NAME.test(text)) return false;
|
|
12013
|
+
entity(state, text);
|
|
12014
|
+
return true;
|
|
12015
|
+
};
|
|
12016
|
+
const ER_STATEMENTS = [
|
|
12017
|
+
readTitle,
|
|
12018
|
+
readDirection,
|
|
12019
|
+
readEntityBlock,
|
|
12020
|
+
readEntityRelation,
|
|
12021
|
+
readEntityAlias,
|
|
12022
|
+
skipEntityStyle,
|
|
12023
|
+
readEntityName
|
|
12024
|
+
];
|
|
12025
|
+
const erDiagram = (lines, ctx) => {
|
|
12026
|
+
const state = newState(lines, ctx);
|
|
12027
|
+
readStatements$1(state, ER_STATEMENTS);
|
|
12028
|
+
return emit(state, [], []);
|
|
12029
|
+
};
|
|
12030
|
+
// src/convert/mermaid/panels.ts
|
|
12031
|
+
/**
|
|
12032
|
+
* Mermaid diagram types that map to one yuhwa panel: sequence, timeline,
|
|
12033
|
+
* gitGraph, pie, xychart, journey, mindmap, gantt, quadrantChart, kanban.
|
|
11722
12034
|
*/
|
|
12035
|
+
const SECTION_RE = /^section\s+(.*)$/;
|
|
11723
12036
|
/** a title line, else the front matter title */
|
|
11724
12037
|
function takeTitle(l, state) {
|
|
11725
12038
|
const t = titleOf(l.text);
|
|
@@ -11727,15 +12040,37 @@ function takeTitle(l, state) {
|
|
|
11727
12040
|
state.title = t;
|
|
11728
12041
|
return true;
|
|
11729
12042
|
}
|
|
12043
|
+
/**
|
|
12044
|
+
* Hands every statement that is neither shared (comments, accessibility) nor a
|
|
12045
|
+
* title line to `read`, and warns about each one `read` does not recognise.
|
|
12046
|
+
*/
|
|
12047
|
+
function readStatements(lines, ctx, state, read) {
|
|
12048
|
+
readLines({
|
|
12049
|
+
lines,
|
|
12050
|
+
index: 0
|
|
12051
|
+
}, ctx, (l) => takeTitle(l, state) || read(l));
|
|
12052
|
+
}
|
|
12053
|
+
/** `head [a, b]`, or just `head` without options */
|
|
12054
|
+
function withOptions(head, options) {
|
|
12055
|
+
return options.length ? `${head} [${options.join(", ")}]` : head;
|
|
12056
|
+
}
|
|
12057
|
+
/** pushes each non-empty detail as a ` - detail` row */
|
|
12058
|
+
function pushDetails(body, details) {
|
|
12059
|
+
for (const detail of details.filter(Boolean)) body.push(` - ${detail}`);
|
|
12060
|
+
}
|
|
11730
12061
|
const MSG_RE = /^(.+?)\s*(<<-->>|<<->>|-->>|->>|--x|-x|--\)|-\)|-->|->)\s*([+-]?)\s*(.+?)\s*:\s*(.*)$/;
|
|
11731
12062
|
const BLOCK_RE = /^(loop|alt|else|opt|par|and|critical|option|break)\b\s*(.*)$/;
|
|
11732
|
-
const
|
|
11733
|
-
|
|
11734
|
-
|
|
12063
|
+
const PARTICIPANT_RE = /^(participant|actor)\s+(.+?)(?:\s+as\s+(.+))?$/;
|
|
12064
|
+
const NOTE_RE$1 = /^note\s+(?:right of|left of|over)\s+([^:]+?)\s*:\s*(.*)$/i;
|
|
12065
|
+
const SEQUENCE_SKIPPED_RE = /^(activate|deactivate|create|destroy|box|link|links|properties|details)\b/;
|
|
12066
|
+
/**
|
|
12067
|
+
* Maps Mermaid participant names to yuhwa ids. A participant is declared in
|
|
12068
|
+
* `body` the first time it gets a label, or when its id differs from its name.
|
|
12069
|
+
*/
|
|
12070
|
+
function participantIds(body) {
|
|
11735
12071
|
const ids = /* @__PURE__ */ new Map();
|
|
11736
12072
|
const declared = /* @__PURE__ */ new Set();
|
|
11737
|
-
|
|
11738
|
-
const pid = (raw, label, actor = false) => {
|
|
12073
|
+
return (raw, label, actor = false) => {
|
|
11739
12074
|
const name = raw.trim();
|
|
11740
12075
|
let id = ids.get(name);
|
|
11741
12076
|
const fresh = !id;
|
|
@@ -11744,250 +12079,250 @@ const sequence = (lines, ctx) => {
|
|
|
11744
12079
|
ids.set(name, id);
|
|
11745
12080
|
}
|
|
11746
12081
|
if (label !== void 0 || fresh && id !== name) {
|
|
11747
|
-
const
|
|
12082
|
+
const keyword = actor ? "actor" : "participant";
|
|
11748
12083
|
const text = label ?? name;
|
|
11749
|
-
if (!declared.has(id)) body.push(text === id ? `${
|
|
12084
|
+
if (!declared.has(id)) body.push(text === id ? `${keyword} ${id}` : `${keyword} ${id} ${q(text)}`);
|
|
11750
12085
|
declared.add(id);
|
|
11751
12086
|
}
|
|
11752
12087
|
return id;
|
|
11753
12088
|
};
|
|
11754
|
-
|
|
11755
|
-
|
|
11756
|
-
|
|
11757
|
-
|
|
11758
|
-
|
|
11759
|
-
|
|
11760
|
-
|
|
11761
|
-
|
|
11762
|
-
|
|
11763
|
-
|
|
11764
|
-
|
|
11765
|
-
|
|
11766
|
-
|
|
11767
|
-
|
|
11768
|
-
|
|
11769
|
-
|
|
11770
|
-
|
|
11771
|
-
|
|
11772
|
-
if (
|
|
11773
|
-
|
|
11774
|
-
|
|
11775
|
-
|
|
11776
|
-
|
|
11777
|
-
|
|
11778
|
-
|
|
11779
|
-
|
|
11780
|
-
|
|
11781
|
-
|
|
11782
|
-
|
|
11783
|
-
|
|
11784
|
-
|
|
12089
|
+
}
|
|
12090
|
+
/** warns about the parts of a message arrow yuhwa does not draw, returns the yuhwa arrow */
|
|
12091
|
+
function sequenceArrow(arrow, activation, ctx, line) {
|
|
12092
|
+
if (activation) ctx.warnOnce("act", line, "activation markers (+/-) are skipped");
|
|
12093
|
+
if (arrow.endsWith("x")) ctx.warnOnce("cross", line, "cross arrow ends (-x) are drawn as normal arrows");
|
|
12094
|
+
if (arrow.startsWith("<<")) ctx.warnOnce("bidi", line, "two-way arrows (<<->>) are drawn one way");
|
|
12095
|
+
return arrow.replace(/^<</, "").startsWith("--") ? "-->" : "->";
|
|
12096
|
+
}
|
|
12097
|
+
const sequence = (lines, ctx) => {
|
|
12098
|
+
const state = { title: ctx.title };
|
|
12099
|
+
const body = [];
|
|
12100
|
+
const participant = participantIds(body);
|
|
12101
|
+
let numbered = false;
|
|
12102
|
+
const readParticipant = (l) => {
|
|
12103
|
+
const m = l.text.match(PARTICIPANT_RE);
|
|
12104
|
+
if (!m) return false;
|
|
12105
|
+
const [, kind, rawName, alias] = m;
|
|
12106
|
+
let name = rawName;
|
|
12107
|
+
if (/@\{/.test(name)) {
|
|
12108
|
+
ctx.warnOnce("ptype", l.line, "participant types (@{ \"type\": … }) are skipped");
|
|
12109
|
+
name = name.replace(/@\{.*$/, "");
|
|
12110
|
+
}
|
|
12111
|
+
participant(name, alias !== void 0 ? oneLine(alias) : name.trim(), kind === "actor");
|
|
12112
|
+
return true;
|
|
12113
|
+
};
|
|
12114
|
+
const readNote = (l) => {
|
|
12115
|
+
const m = l.text.match(NOTE_RE$1);
|
|
12116
|
+
if (!m) return false;
|
|
12117
|
+
const who = m[1].split(",").map((s) => participant(s));
|
|
12118
|
+
body.push(`note ${who.join(", ")}: ${oneLine(m[2])}`);
|
|
12119
|
+
return true;
|
|
12120
|
+
};
|
|
12121
|
+
const readBlock = (l) => {
|
|
12122
|
+
const m = l.text.match(BLOCK_RE);
|
|
12123
|
+
if (!m) return false;
|
|
12124
|
+
ctx.warnOnce("block", l.line, "loop/alt/opt/par blocks become \"--- … ---\" dividers");
|
|
12125
|
+
body.push(`--- ${[m[1], oneLine(m[2])].filter(Boolean).join(" ")} ---`);
|
|
12126
|
+
return true;
|
|
12127
|
+
};
|
|
12128
|
+
const skipUnsupported = (l) => {
|
|
12129
|
+
if (/^rect\b/.test(l.text)) {
|
|
11785
12130
|
ctx.warnOnce("rect", l.line, "\"rect\" highlight boxes are skipped");
|
|
11786
|
-
|
|
11787
|
-
}
|
|
11788
|
-
const kw = t.match(/^(activate|deactivate|create|destroy|box|link|links|properties|details)\b/);
|
|
11789
|
-
if (kw) {
|
|
11790
|
-
ctx.warnOnce(kw[1], l.line, `"${kw[1]}" is not supported and was skipped`);
|
|
11791
|
-
continue;
|
|
12131
|
+
return true;
|
|
11792
12132
|
}
|
|
11793
|
-
const m =
|
|
11794
|
-
if (m)
|
|
11795
|
-
|
|
11796
|
-
|
|
11797
|
-
|
|
11798
|
-
|
|
11799
|
-
|
|
11800
|
-
|
|
11801
|
-
|
|
12133
|
+
const m = l.text.match(SEQUENCE_SKIPPED_RE);
|
|
12134
|
+
if (!m) return false;
|
|
12135
|
+
ctx.warnOnce(m[1], l.line, `"${m[1]}" is not supported and was skipped`);
|
|
12136
|
+
return true;
|
|
12137
|
+
};
|
|
12138
|
+
const readMessage = (l) => {
|
|
12139
|
+
const m = l.text.match(MSG_RE);
|
|
12140
|
+
if (!m) return false;
|
|
12141
|
+
const [, from, arrow, activation, to, text] = m;
|
|
12142
|
+
const yuhwaArrow = sequenceArrow(arrow, activation, ctx, l.line);
|
|
12143
|
+
body.push(`${participant(from)} ${yuhwaArrow} ${participant(to)}: ${oneLine(text)}`);
|
|
12144
|
+
return true;
|
|
12145
|
+
};
|
|
12146
|
+
readStatements(lines, ctx, state, (l) => {
|
|
12147
|
+
if (l.text === "autonumber" || l.text.startsWith("autonumber ")) {
|
|
12148
|
+
numbered = true;
|
|
12149
|
+
return true;
|
|
11802
12150
|
}
|
|
11803
|
-
|
|
11804
|
-
}
|
|
11805
|
-
return panel("sequence", panelId(
|
|
12151
|
+
return readParticipant(l) || readNote(l) || readBlock(l) || l.text === "end" || skipUnsupported(l) || readMessage(l);
|
|
12152
|
+
});
|
|
12153
|
+
return panel("sequence", panelId(state.title, "seq"), state.title, numbered ? ["numbered"] : [], body);
|
|
11806
12154
|
};
|
|
11807
12155
|
const timeline = (lines, ctx) => {
|
|
11808
|
-
const
|
|
12156
|
+
const state = { title: ctx.title };
|
|
11809
12157
|
const body = [];
|
|
11810
12158
|
let tone;
|
|
11811
12159
|
let sections = 0;
|
|
11812
|
-
|
|
11813
|
-
const
|
|
11814
|
-
if (common(l, ctx) || takeTitle(l, st)) continue;
|
|
11815
|
-
const s = t.match(/^section\s+(.*)$/);
|
|
11816
|
-
if (s) {
|
|
11817
|
-
tone = PALETTE[sections++ % PALETTE.length];
|
|
11818
|
-
ctx.warnOnce("section", l.line, "timeline sections become a colour per section");
|
|
11819
|
-
body.push(`// ${oneLine(s[1])}`);
|
|
11820
|
-
continue;
|
|
11821
|
-
}
|
|
11822
|
-
const parts = t.split(/\s*:\s*/).map((p) => oneLine(p));
|
|
11823
|
-
if (t.startsWith(":")) {
|
|
11824
|
-
if (!body.length || body[body.length - 1].startsWith("//")) {
|
|
11825
|
-
ctx.warn(l.line, `event detail "${t}" has no event above it`);
|
|
11826
|
-
continue;
|
|
11827
|
-
}
|
|
11828
|
-
for (const d of parts.slice(1).filter(Boolean)) body.push(` - ${d}`);
|
|
11829
|
-
continue;
|
|
11830
|
-
}
|
|
11831
|
-
const [when, title, ...rest] = parts;
|
|
12160
|
+
const addEvent = (l, [when, title, ...details]) => {
|
|
12161
|
+
const toneOption = tone ? ` [${tone}]` : "";
|
|
11832
12162
|
if (!title) {
|
|
11833
12163
|
ctx.warn(l.line, `event "${when}" has no text`);
|
|
11834
|
-
body.push(`${when}${
|
|
11835
|
-
|
|
12164
|
+
body.push(`${when}${toneOption}: ${when}`);
|
|
12165
|
+
return;
|
|
11836
12166
|
}
|
|
11837
|
-
body.push(`${when}${
|
|
11838
|
-
|
|
11839
|
-
}
|
|
11840
|
-
|
|
12167
|
+
body.push(`${when}${toneOption}: ${title}`);
|
|
12168
|
+
pushDetails(body, details);
|
|
12169
|
+
};
|
|
12170
|
+
const addDetails = (l, parts) => {
|
|
12171
|
+
if (!body.length || body[body.length - 1].startsWith("//")) {
|
|
12172
|
+
ctx.warn(l.line, `event detail "${l.text}" has no event above it`);
|
|
12173
|
+
return;
|
|
12174
|
+
}
|
|
12175
|
+
pushDetails(body, parts.slice(1));
|
|
12176
|
+
};
|
|
12177
|
+
readStatements(lines, ctx, state, (l) => {
|
|
12178
|
+
const section = l.text.match(SECTION_RE);
|
|
12179
|
+
if (section) {
|
|
12180
|
+
tone = PALETTE[sections++ % PALETTE.length];
|
|
12181
|
+
ctx.warnOnce("section", l.line, "timeline sections become a colour per section");
|
|
12182
|
+
body.push(`// ${oneLine(section[1])}`);
|
|
12183
|
+
return true;
|
|
12184
|
+
}
|
|
12185
|
+
const parts = l.text.split(/\s*:\s*/).map((p) => oneLine(p));
|
|
12186
|
+
if (l.text.startsWith(":")) addDetails(l, parts);
|
|
12187
|
+
else addEvent(l, parts);
|
|
12188
|
+
return true;
|
|
12189
|
+
});
|
|
12190
|
+
return panel("timeline", panelId(state.title, "events"), state.title, [], body);
|
|
11841
12191
|
};
|
|
11842
12192
|
const ATTR_RE = /(\w+)\s*:\s*("[^"]*"|\S+)/g;
|
|
12193
|
+
const COMMIT_RE = /^commit\b(.*)$/;
|
|
12194
|
+
const BRANCH_RE = /^branch\s+("[^"]*"|\S+)(.*)$/;
|
|
12195
|
+
const CHECKOUT_RE = /^(checkout|switch)\s+(.+)$/;
|
|
12196
|
+
const MERGE_RE = /^merge\s+("[^"]*"|\S+)(.*)$/;
|
|
12197
|
+
const CHERRY_PICK_RE = /^cherry-pick\b(.*)$/;
|
|
12198
|
+
/** `key: value` and `key: "quoted value"` pairs */
|
|
11843
12199
|
function attrs(s) {
|
|
11844
12200
|
const out = {};
|
|
11845
12201
|
for (const m of s.matchAll(ATTR_RE)) out[m[1]] = m[2].replace(/^"(.*)"$/, "$1");
|
|
11846
12202
|
return out;
|
|
11847
12203
|
}
|
|
11848
12204
|
const gitName = (s) => s.trim().replace(/^"(.*)"$/, "$1").replace(/\s+/g, "-").replace(/[^\p{L}\p{N}_./-]/gu, "_").replace(/^[^\p{L}\p{N}_]+/u, "");
|
|
12205
|
+
/** the id, tag and type options shared by commits and merges */
|
|
12206
|
+
function commitOptions(a) {
|
|
12207
|
+
const options = [];
|
|
12208
|
+
if (a.id) options.push(`id: ${pv(gitName(a.id))}`);
|
|
12209
|
+
if (a.tag) options.push(`tag: ${pv(a.tag)}`);
|
|
12210
|
+
const type = a.type?.toUpperCase();
|
|
12211
|
+
if (type === "HIGHLIGHT") options.push("highlight");
|
|
12212
|
+
else if (type === "REVERSE") options.push("reverse");
|
|
12213
|
+
return options;
|
|
12214
|
+
}
|
|
12215
|
+
/** panel props for the `LR`/`TB`/`BT` header word */
|
|
12216
|
+
function gitDirection(lines, ctx) {
|
|
12217
|
+
const direction = ctx.header.match(/^\s*(LR|TB|BT)\s*:?/)?.[1];
|
|
12218
|
+
if (direction === "BT") ctx.warn(lines[0]?.line ?? 1, "bottom-to-top git graphs are drawn top to bottom");
|
|
12219
|
+
return direction === "TB" || direction === "BT" ? ["direction: down"] : [];
|
|
12220
|
+
}
|
|
11849
12221
|
const git = (lines, ctx) => {
|
|
11850
|
-
const
|
|
11851
|
-
const props =
|
|
11852
|
-
const dir = ctx.header.match(/^\s*(LR|TB|BT)\s*:?/);
|
|
11853
|
-
if (dir?.[1] === "TB" || dir?.[1] === "BT") props.push("direction: down");
|
|
11854
|
-
if (dir?.[1] === "BT") ctx.warn(lines[0]?.line ?? 1, "bottom-to-top git graphs are drawn top to bottom");
|
|
12222
|
+
const state = { title: ctx.title };
|
|
12223
|
+
const props = gitDirection(lines, ctx);
|
|
11855
12224
|
const body = [];
|
|
11856
|
-
const
|
|
11857
|
-
|
|
11858
|
-
if (
|
|
11859
|
-
|
|
12225
|
+
const readCherryPick = (l, a) => {
|
|
12226
|
+
if (a.parent) ctx.warnOnce("parent", l.line, "cherry-pick \"parent\" is skipped");
|
|
12227
|
+
if (a.tag) ctx.warnOnce("cptag", l.line, "cherry-pick \"tag\" is skipped");
|
|
12228
|
+
if (!a.id) ctx.warn(l.line, "cherry-pick needs an id");
|
|
12229
|
+
else body.push(`cherry-pick ${gitName(a.id)}`);
|
|
11860
12230
|
};
|
|
11861
|
-
|
|
12231
|
+
readStatements(lines, ctx, state, (l) => {
|
|
11862
12232
|
const t = l.text;
|
|
11863
|
-
|
|
11864
|
-
|
|
11865
|
-
|
|
11866
|
-
|
|
11867
|
-
|
|
11868
|
-
|
|
11869
|
-
|
|
11870
|
-
|
|
11871
|
-
|
|
11872
|
-
|
|
11873
|
-
|
|
11874
|
-
|
|
11875
|
-
|
|
11876
|
-
|
|
11877
|
-
}
|
|
11878
|
-
const br = t.match(/^branch\s+("[^"]*"|\S+)(.*)$/);
|
|
11879
|
-
if (br) {
|
|
11880
|
-
const a = attrs(br[2]);
|
|
11881
|
-
body.push(`branch ${gitName(br[1])}${a.order ? ` [order: ${a.order}]` : ""}`);
|
|
11882
|
-
continue;
|
|
11883
|
-
}
|
|
11884
|
-
const co = t.match(/^(checkout|switch)\s+(.+)$/);
|
|
11885
|
-
if (co) {
|
|
11886
|
-
body.push(`${co[1]} ${gitName(co[2])}`);
|
|
11887
|
-
continue;
|
|
11888
|
-
}
|
|
11889
|
-
const mg = t.match(/^merge\s+("[^"]*"|\S+)(.*)$/);
|
|
11890
|
-
if (mg) {
|
|
11891
|
-
const a = attrs(mg[2]);
|
|
11892
|
-
const opts = [];
|
|
11893
|
-
if (a.id) opts.push(`id: ${pv(gitName(a.id))}`);
|
|
11894
|
-
if (a.tag) opts.push(`tag: ${pv(a.tag)}`);
|
|
11895
|
-
typeProp(a, opts);
|
|
11896
|
-
body.push(`merge ${gitName(mg[1])}${opts.length ? ` [${opts.join(", ")}]` : ""}`);
|
|
11897
|
-
continue;
|
|
11898
|
-
}
|
|
11899
|
-
const cp = t.match(/^cherry-pick\b(.*)$/);
|
|
11900
|
-
if (cp) {
|
|
11901
|
-
const a = attrs(cp[1]);
|
|
11902
|
-
if (a.parent) ctx.warnOnce("parent", l.line, "cherry-pick \"parent\" is skipped");
|
|
11903
|
-
if (a.tag) ctx.warnOnce("cptag", l.line, "cherry-pick \"tag\" is skipped");
|
|
11904
|
-
if (!a.id) ctx.warn(l.line, "cherry-pick needs an id");
|
|
11905
|
-
else body.push(`cherry-pick ${gitName(a.id)}`);
|
|
11906
|
-
continue;
|
|
11907
|
-
}
|
|
11908
|
-
ctx.warn(l.line, `could not read "${t}"`);
|
|
11909
|
-
}
|
|
11910
|
-
return panel("git", panelId(st.title, "history"), st.title, props, body);
|
|
12233
|
+
let m;
|
|
12234
|
+
if (m = t.match(COMMIT_RE)) {
|
|
12235
|
+
const a = attrs(m[1]);
|
|
12236
|
+
body.push(withOptions(a.msg ? `commit ${q(a.msg)}` : "commit", commitOptions(a)));
|
|
12237
|
+
} else if (m = t.match(BRANCH_RE)) {
|
|
12238
|
+
const order = attrs(m[2]).order;
|
|
12239
|
+
body.push(withOptions(`branch ${gitName(m[1])}`, order ? [`order: ${order}`] : []));
|
|
12240
|
+
} else if (m = t.match(CHECKOUT_RE)) body.push(`${m[1]} ${gitName(m[2])}`);
|
|
12241
|
+
else if (m = t.match(MERGE_RE)) body.push(withOptions(`merge ${gitName(m[1])}`, commitOptions(attrs(m[2]))));
|
|
12242
|
+
else if (m = t.match(CHERRY_PICK_RE)) readCherryPick(l, attrs(m[1]));
|
|
12243
|
+
else return false;
|
|
12244
|
+
return true;
|
|
12245
|
+
});
|
|
12246
|
+
return panel("git", panelId(state.title, "history"), state.title, props, body);
|
|
11911
12247
|
};
|
|
12248
|
+
const PIE_SLICE_RE = /^("[^"]*"|'[^']*'|[^:]+?)\s*:\s*(-?\d+(?:\.\d+)?)\s*$/;
|
|
11912
12249
|
/** a chart row label, quoted when it would confuse the row syntax */
|
|
11913
12250
|
const chartLabel = (s) => /[[\]:]|^"/.test(s) ? q(s) : s;
|
|
11914
12251
|
const pie = (lines, ctx) => {
|
|
11915
|
-
const
|
|
11916
|
-
const
|
|
11917
|
-
if (
|
|
12252
|
+
const state = { title: ctx.title };
|
|
12253
|
+
const headerTitle = ctx.header.replace(/\bshowData\b/, "").trim();
|
|
12254
|
+
if (headerTitle) state.title = titleOf(headerTitle) ?? state.title;
|
|
11918
12255
|
const body = [];
|
|
11919
|
-
|
|
11920
|
-
if (
|
|
11921
|
-
const m = l.text.match(
|
|
12256
|
+
readStatements(lines, ctx, state, (l) => {
|
|
12257
|
+
if (l.text === "showData") return true;
|
|
12258
|
+
const m = l.text.match(PIE_SLICE_RE);
|
|
11922
12259
|
if (m) body.push(`${chartLabel(oneLine(m[1]))}: ${m[2]}`);
|
|
11923
|
-
|
|
11924
|
-
}
|
|
11925
|
-
return panel("chart", panelId(
|
|
12260
|
+
return !!m;
|
|
12261
|
+
});
|
|
12262
|
+
return panel("chart", panelId(state.title, "pie"), state.title, ["type: pie"], body);
|
|
11926
12263
|
};
|
|
12264
|
+
const X_AXIS_RE = /^x-axis\b\s*(?:"[^"]*"|[^\s[]+)?\s*(.*)$/;
|
|
12265
|
+
const SERIES_RE = /^(bar|line)\b\s*(?:"[^"]*")?\s*(\[.*\])\s*$/;
|
|
12266
|
+
/** one chart panel per series, since a yuhwa chart plots one series */
|
|
12267
|
+
function seriesCharts(series, categories, horizontal, title) {
|
|
12268
|
+
const base = panelId(title, "xy");
|
|
12269
|
+
if (!series.length) return panel("chart", base, title, ["type: column"], []);
|
|
12270
|
+
const out = [];
|
|
12271
|
+
series.forEach((s, k) => {
|
|
12272
|
+
const body = s.values.map((v, i) => `${chartLabel(categories[i] ?? String(i + 1))}: ${v}`);
|
|
12273
|
+
const type = s.type === "line" ? "line" : horizontal ? "bar" : "column";
|
|
12274
|
+
if (k) out.push("");
|
|
12275
|
+
out.push(...panel("chart", k ? `${base}${k + 1}` : base, title, [`type: ${type}`], body));
|
|
12276
|
+
});
|
|
12277
|
+
return out;
|
|
12278
|
+
}
|
|
11927
12279
|
const xychart = (lines, ctx) => {
|
|
11928
|
-
const
|
|
11929
|
-
|
|
11930
|
-
let cats = [];
|
|
12280
|
+
const state = { title: ctx.title };
|
|
12281
|
+
let categories = [];
|
|
11931
12282
|
const series = [];
|
|
11932
|
-
|
|
11933
|
-
const
|
|
11934
|
-
if (
|
|
11935
|
-
|
|
11936
|
-
|
|
11937
|
-
const rest = x[1].trim();
|
|
11938
|
-
if (rest.startsWith("[")) cats = splitList(rest).map((c) => oneLine(c));
|
|
12283
|
+
readStatements(lines, ctx, state, (l) => {
|
|
12284
|
+
const xAxis = l.text.match(X_AXIS_RE);
|
|
12285
|
+
if (xAxis) {
|
|
12286
|
+
const rest = xAxis[1].trim();
|
|
12287
|
+
if (rest.startsWith("[")) categories = splitList(rest).map((c) => oneLine(c));
|
|
11939
12288
|
else ctx.warnOnce("xrange", l.line, "a numeric x-axis range becomes 1, 2, 3, …");
|
|
11940
|
-
|
|
12289
|
+
return true;
|
|
11941
12290
|
}
|
|
11942
|
-
if (/^y-axis\b/.test(
|
|
12291
|
+
if (/^y-axis\b/.test(l.text)) {
|
|
11943
12292
|
ctx.warnOnce("yaxis", l.line, "the y-axis title and range are skipped; the chart scales to the data");
|
|
11944
|
-
|
|
11945
|
-
}
|
|
11946
|
-
const s = t.match(/^(bar|line)\b\s*(?:"[^"]*")?\s*(\[.*\])\s*$/);
|
|
11947
|
-
if (s) {
|
|
11948
|
-
series.push({
|
|
11949
|
-
type: s[1],
|
|
11950
|
-
values: splitList(s[2]),
|
|
11951
|
-
line: l.line
|
|
11952
|
-
});
|
|
11953
|
-
continue;
|
|
12293
|
+
return true;
|
|
11954
12294
|
}
|
|
11955
|
-
|
|
11956
|
-
|
|
11957
|
-
|
|
11958
|
-
|
|
11959
|
-
|
|
11960
|
-
|
|
11961
|
-
|
|
11962
|
-
const type = s.type === "line" ? "line" : horizontal ? "bar" : "column";
|
|
11963
|
-
if (k) out.push("");
|
|
11964
|
-
out.push(...panel("chart", k ? `${base}${k + 1}` : base, st.title, [`type: ${type}`], body));
|
|
12295
|
+
const s = l.text.match(SERIES_RE);
|
|
12296
|
+
if (s) series.push({
|
|
12297
|
+
type: s[1],
|
|
12298
|
+
values: splitList(s[2]),
|
|
12299
|
+
line: l.line
|
|
12300
|
+
});
|
|
12301
|
+
return !!s;
|
|
11965
12302
|
});
|
|
11966
|
-
if (
|
|
11967
|
-
return
|
|
12303
|
+
if (series.length > 1) ctx.warn(series[1].line, "each xychart series becomes its own chart; yuhwa charts plot one series");
|
|
12304
|
+
return seriesCharts(series, categories, /\bhorizontal\b/.test(ctx.header), state.title);
|
|
11968
12305
|
};
|
|
12306
|
+
const JOURNEY_TASK_RE = /^(.+?)\s*:\s*(\d+(?:\.\d+)?)\s*(?::\s*(.*))?$/;
|
|
12307
|
+
/** red for unhappy scores (≤ 2), amber in between, green from 4 */
|
|
12308
|
+
const scoreTone = (score) => score <= 2 ? "red" : score < 4 ? "amber" : "green";
|
|
11969
12309
|
const journey = (lines, ctx) => {
|
|
11970
|
-
const
|
|
12310
|
+
const state = { title: ctx.title };
|
|
11971
12311
|
const body = [];
|
|
11972
|
-
|
|
11973
|
-
const
|
|
11974
|
-
if (
|
|
11975
|
-
|
|
11976
|
-
|
|
11977
|
-
|
|
11978
|
-
|
|
11979
|
-
|
|
11980
|
-
const
|
|
11981
|
-
if (
|
|
11982
|
-
|
|
11983
|
-
|
|
11984
|
-
|
|
11985
|
-
|
|
11986
|
-
continue;
|
|
11987
|
-
}
|
|
11988
|
-
ctx.warn(l.line, `could not read "${t}"`);
|
|
11989
|
-
}
|
|
11990
|
-
return panel("chart", panelId(st.title, "journey"), st.title, ["type: column"], body);
|
|
12312
|
+
readStatements(lines, ctx, state, (l) => {
|
|
12313
|
+
const section = l.text.match(SECTION_RE);
|
|
12314
|
+
if (section) {
|
|
12315
|
+
body.push(`// ${oneLine(section[1])}`);
|
|
12316
|
+
return true;
|
|
12317
|
+
}
|
|
12318
|
+
const m = l.text.match(JOURNEY_TASK_RE);
|
|
12319
|
+
if (!m) return false;
|
|
12320
|
+
const [, task, score, actors] = m;
|
|
12321
|
+
if (actors) ctx.warnOnce("actors", l.line, "journey actors are skipped; scores become a column chart");
|
|
12322
|
+
body.push(`${chartLabel(oneLine(task))} [${scoreTone(Number(score))}]: ${score}`);
|
|
12323
|
+
return true;
|
|
12324
|
+
});
|
|
12325
|
+
return panel("chart", panelId(state.title, "journey"), state.title, ["type: column"], body);
|
|
11991
12326
|
};
|
|
11992
12327
|
const MM_SHAPES = [
|
|
11993
12328
|
[
|
|
@@ -12041,7 +12376,7 @@ function mindNode(text, ctx, line) {
|
|
|
12041
12376
|
}
|
|
12042
12377
|
const mindmap = (lines, ctx) => {
|
|
12043
12378
|
const body = [];
|
|
12044
|
-
const
|
|
12379
|
+
const ancestors = [];
|
|
12045
12380
|
let roots = 0;
|
|
12046
12381
|
for (const l of lines) {
|
|
12047
12382
|
if (common(l, ctx)) continue;
|
|
@@ -12049,13 +12384,13 @@ const mindmap = (lines, ctx) => {
|
|
|
12049
12384
|
ctx.warnOnce("icon", l.line, "mindmap icons (::icon) are skipped");
|
|
12050
12385
|
continue;
|
|
12051
12386
|
}
|
|
12052
|
-
while (
|
|
12053
|
-
const depth =
|
|
12054
|
-
|
|
12387
|
+
while (ancestors.length && ancestors[ancestors.length - 1] >= l.indent) ancestors.pop();
|
|
12388
|
+
const depth = ancestors.length;
|
|
12389
|
+
ancestors.push(l.indent);
|
|
12055
12390
|
if (depth === 0 && roots++) ctx.warn(l.line, "a mindmap has one root; this node starts a second tree");
|
|
12056
|
-
const
|
|
12057
|
-
const text =
|
|
12058
|
-
body.push(" ".repeat(depth) + text + (
|
|
12391
|
+
const node = mindNode(l.text, ctx, l.line);
|
|
12392
|
+
const text = node.text.replace(/\s*\n\s*/g, " ");
|
|
12393
|
+
body.push(" ".repeat(depth) + text + (node.shape ? ` [shape: ${node.shape}]` : ""));
|
|
12059
12394
|
}
|
|
12060
12395
|
return panel("mindmap", panelId(ctx.title, "map"), ctx.title, ["layout: both"], body);
|
|
12061
12396
|
};
|
|
@@ -12066,137 +12401,161 @@ const TAGS = /* @__PURE__ */ new Set([
|
|
|
12066
12401
|
"milestone"
|
|
12067
12402
|
]);
|
|
12068
12403
|
const GANTT_SKIP = /^(axisFormat|tickInterval|excludes|includes|weekday|weekend|todayMarker|inclusiveEndDates|topAxis|displayMode|click)\b/;
|
|
12069
|
-
const
|
|
12070
|
-
|
|
12404
|
+
const GANTT_TASK_RE = /^([^:]+?)\s*:\s*(.*)$/;
|
|
12405
|
+
const GANTT_LENGTH_RE = /^(\d+(?:\.\d+)?)(ms|s|m|h|d|w)$/;
|
|
12406
|
+
/**
|
|
12407
|
+
* Pass 1: every task line with its comma-separated fields, plus the ids
|
|
12408
|
+
* Mermaid gives, so generated ones do not collide.
|
|
12409
|
+
*/
|
|
12410
|
+
function ganttTasks(lines) {
|
|
12071
12411
|
const taken = /* @__PURE__ */ new Set();
|
|
12072
|
-
const
|
|
12412
|
+
const tasks = [];
|
|
12073
12413
|
for (const l of lines) {
|
|
12074
|
-
const m = l.text.match(
|
|
12075
|
-
if (!m || /^(title|dateFormat|section)\b/.test(l.text) || GANTT_SKIP.test(l.text)) continue;
|
|
12414
|
+
const m = l.text.match(GANTT_TASK_RE);
|
|
12415
|
+
if (!m || /^(title|dateFormat|section)\b/.test(l.text) || GANTT_SKIP.test(l.text) || ACC_RE.test(l.text)) continue;
|
|
12076
12416
|
const items = m[2].split(",").map((s) => s.trim()).filter(Boolean);
|
|
12077
|
-
|
|
12417
|
+
tasks.push({
|
|
12078
12418
|
l,
|
|
12079
12419
|
label: m[1],
|
|
12080
12420
|
items
|
|
12081
12421
|
});
|
|
12082
|
-
const
|
|
12083
|
-
if (
|
|
12422
|
+
const fields = items.filter((i) => !TAGS.has(i));
|
|
12423
|
+
if (fields.length === 3) taken.add(toId(fields[0]));
|
|
12084
12424
|
}
|
|
12085
|
-
|
|
12425
|
+
return {
|
|
12426
|
+
tasks,
|
|
12427
|
+
taken
|
|
12428
|
+
};
|
|
12429
|
+
}
|
|
12430
|
+
/** `t1`, `t2`, … skipping ids already taken */
|
|
12431
|
+
function idGenerator(taken) {
|
|
12086
12432
|
let n = 0;
|
|
12087
|
-
|
|
12433
|
+
return () => {
|
|
12088
12434
|
let id;
|
|
12089
12435
|
do
|
|
12090
12436
|
id = `t${++n}`;
|
|
12091
12437
|
while (taken.has(id));
|
|
12092
12438
|
return id;
|
|
12093
12439
|
};
|
|
12094
|
-
|
|
12095
|
-
|
|
12096
|
-
|
|
12097
|
-
|
|
12098
|
-
|
|
12099
|
-
|
|
12100
|
-
|
|
12101
|
-
|
|
12102
|
-
|
|
12103
|
-
|
|
12104
|
-
|
|
12440
|
+
}
|
|
12441
|
+
/** a task length; minutes and seconds round up to 1h */
|
|
12442
|
+
function ganttLength(s, ctx, line) {
|
|
12443
|
+
const m = s.match(GANTT_LENGTH_RE);
|
|
12444
|
+
if (!m || [
|
|
12445
|
+
"h",
|
|
12446
|
+
"d",
|
|
12447
|
+
"w"
|
|
12448
|
+
].includes(m[2])) return s;
|
|
12449
|
+
ctx.warnOnce("mins", line, "minute and second lengths are rounded up to 1h");
|
|
12450
|
+
return "1h";
|
|
12451
|
+
}
|
|
12452
|
+
/** a task start, with `after a b` ids mapped to their yuhwa ids */
|
|
12453
|
+
function ganttStart(s, idMap) {
|
|
12454
|
+
return s.replace(/^after\s+(.*)$/, (_, ids) => "after " + ids.split(/\s+/).map((x) => idMap.get(x) ?? toId(x)).join(" "));
|
|
12455
|
+
}
|
|
12456
|
+
const gantt = (lines, ctx) => {
|
|
12457
|
+
const state = { title: ctx.title };
|
|
12458
|
+
const { tasks, taken } = ganttTasks(lines);
|
|
12459
|
+
const nextId = idGenerator(taken);
|
|
12460
|
+
const idMap = /* @__PURE__ */ new Map();
|
|
12105
12461
|
const body = [];
|
|
12106
|
-
let
|
|
12462
|
+
let taskIndex = 0;
|
|
12107
12463
|
let first = true;
|
|
12108
|
-
|
|
12109
|
-
|
|
12110
|
-
if (
|
|
12111
|
-
|
|
12112
|
-
|
|
12113
|
-
|
|
12114
|
-
|
|
12115
|
-
|
|
12116
|
-
|
|
12117
|
-
|
|
12118
|
-
|
|
12119
|
-
|
|
12120
|
-
|
|
12121
|
-
|
|
12122
|
-
|
|
12123
|
-
|
|
12124
|
-
|
|
12125
|
-
|
|
12126
|
-
|
|
12127
|
-
|
|
12128
|
-
|
|
12129
|
-
|
|
12130
|
-
|
|
12131
|
-
|
|
12132
|
-
const tags = p.items.filter((i) => TAGS.has(i));
|
|
12133
|
-
const rest = p.items.filter((i) => !TAGS.has(i));
|
|
12134
|
-
let id;
|
|
12135
|
-
let from;
|
|
12136
|
-
let to;
|
|
12137
|
-
if (rest.length >= 3) [id, from, to] = [
|
|
12138
|
-
toId(rest[0]),
|
|
12139
|
-
rest[1],
|
|
12140
|
-
rest[2]
|
|
12141
|
-
];
|
|
12142
|
-
else if (rest.length === 2) [id, from, to] = [
|
|
12143
|
-
fresh(),
|
|
12144
|
-
rest[0],
|
|
12145
|
-
rest[1]
|
|
12146
|
-
];
|
|
12147
|
-
else [id, to] = [fresh(), rest[0]];
|
|
12148
|
-
if (rest.length >= 3) idMap.set(rest[0], id);
|
|
12149
|
-
if (rest.length > 3) ctx.warn(l.line, `extra task fields "${rest.slice(3).join(", ")}" are skipped`);
|
|
12464
|
+
/** `id, start, end`, `start, end` or `end` (tags removed) */
|
|
12465
|
+
const taskFields = (fields) => {
|
|
12466
|
+
if (fields.length >= 3) return {
|
|
12467
|
+
id: toId(fields[0]),
|
|
12468
|
+
from: fields[1],
|
|
12469
|
+
to: fields[2]
|
|
12470
|
+
};
|
|
12471
|
+
if (fields.length === 2) return {
|
|
12472
|
+
id: nextId(),
|
|
12473
|
+
from: fields[0],
|
|
12474
|
+
to: fields[1]
|
|
12475
|
+
};
|
|
12476
|
+
return {
|
|
12477
|
+
id: nextId(),
|
|
12478
|
+
to: fields[0]
|
|
12479
|
+
};
|
|
12480
|
+
};
|
|
12481
|
+
/** a task line as `id "label" [tags]: start, length` */
|
|
12482
|
+
const readTask = (l, task) => {
|
|
12483
|
+
const tags = task.items.filter((i) => TAGS.has(i));
|
|
12484
|
+
const fields = task.items.filter((i) => !TAGS.has(i));
|
|
12485
|
+
const { id, from, to: end } = taskFields(fields);
|
|
12486
|
+
if (fields.length >= 3) idMap.set(fields[0], id);
|
|
12487
|
+
if (fields.length > 3) ctx.warn(l.line, `extra task fields "${fields.slice(3).join(", ")}" are skipped`);
|
|
12150
12488
|
if (first && !from) ctx.warn(l.line, "the first task has no start date");
|
|
12151
12489
|
first = false;
|
|
12490
|
+
let to = end;
|
|
12152
12491
|
if (to?.startsWith("until ")) {
|
|
12153
12492
|
ctx.warnOnce("until", l.line, "\"until\" ends become a 1d length");
|
|
12154
12493
|
to = "1d";
|
|
12155
12494
|
}
|
|
12156
|
-
if (to) to =
|
|
12157
|
-
const
|
|
12495
|
+
if (to) to = ganttLength(to, ctx, l.line);
|
|
12496
|
+
const start = from ? ganttStart(from, idMap) : "";
|
|
12497
|
+
const value = (tags.includes("milestone") ? [start] : [start, to ?? ""]).filter(Boolean).join(", ");
|
|
12158
12498
|
const head = [
|
|
12159
12499
|
id,
|
|
12160
|
-
q(oneLine(
|
|
12500
|
+
q(oneLine(task.label)),
|
|
12161
12501
|
tags.length ? `[${tags.join(", ")}]` : ""
|
|
12162
12502
|
].filter(Boolean).join(" ");
|
|
12163
12503
|
body.push(value ? `${head}: ${value}` : head);
|
|
12164
|
-
}
|
|
12165
|
-
|
|
12504
|
+
};
|
|
12505
|
+
readStatements(lines, ctx, state, (l) => {
|
|
12506
|
+
const t = l.text;
|
|
12507
|
+
const dateFormat = t.match(/^dateFormat\s+(.*)$/);
|
|
12508
|
+
if (dateFormat) {
|
|
12509
|
+
if (!/^YYYY-MM-DD( HH:mm)?$/.test(dateFormat[1].trim())) ctx.warn(l.line, `dateFormat "${dateFormat[1].trim()}" is kept as written; yuhwa reads YYYY-MM-DD dates`);
|
|
12510
|
+
return true;
|
|
12511
|
+
}
|
|
12512
|
+
if (GANTT_SKIP.test(t)) {
|
|
12513
|
+
const keyword = t.split(/\s+/)[0];
|
|
12514
|
+
ctx.warnOnce(keyword, l.line, `"${keyword}" is not supported and was skipped`);
|
|
12515
|
+
return true;
|
|
12516
|
+
}
|
|
12517
|
+
const section = t.match(SECTION_RE);
|
|
12518
|
+
if (section) {
|
|
12519
|
+
body.push(`--- ${oneLine(section[1])} ---`);
|
|
12520
|
+
return true;
|
|
12521
|
+
}
|
|
12522
|
+
const task = tasks[taskIndex];
|
|
12523
|
+
if (!task || task.l !== l) return false;
|
|
12524
|
+
taskIndex++;
|
|
12525
|
+
readTask(l, task);
|
|
12526
|
+
return true;
|
|
12527
|
+
});
|
|
12528
|
+
return panel("gantt", panelId(state.title, "plan"), state.title, [], body);
|
|
12166
12529
|
};
|
|
12530
|
+
const QUADRANT_AXIS_RE = /^([xy])-axis\s+(.*)$/;
|
|
12531
|
+
const QUADRANT_LABEL_RE = /^quadrant-([1-4])\s+(.*)$/;
|
|
12532
|
+
const QUADRANT_POINT_RE = /^(.+?)(?::::[\w-]+)?\s*:\s*\[\s*([\d.]+)\s*,\s*([\d.]+)\s*\]\s*(.*)$/;
|
|
12533
|
+
const HEX_COLOR_RE = /^#[0-9a-f]{3}(?:[0-9a-f]{3})?$/i;
|
|
12534
|
+
/** `name [#color]: x, y`; radius, stroke and classes are skipped */
|
|
12535
|
+
function quadrantPoint(l, m, ctx) {
|
|
12536
|
+
const [, name, x, y, style] = m;
|
|
12537
|
+
const a = attrs(style.replace(/,/g, " "));
|
|
12538
|
+
if (/:::/.test(l.text)) ctx.warnOnce("qclass", l.line, "quadrant point classes are skipped");
|
|
12539
|
+
if (a.radius || a["stroke-color"] || a["stroke-width"]) ctx.warnOnce("qstyle", l.line, "point radius and stroke are skipped");
|
|
12540
|
+
const color = a.color && HEX_COLOR_RE.test(a.color) ? ` [${a.color}]` : "";
|
|
12541
|
+
return `${oneLine(name)}${color}: ${x}, ${y}`;
|
|
12542
|
+
}
|
|
12167
12543
|
const quadrant = (lines, ctx) => {
|
|
12168
|
-
const
|
|
12544
|
+
const state = { title: ctx.title };
|
|
12169
12545
|
const body = [];
|
|
12170
|
-
|
|
12546
|
+
readStatements(lines, ctx, state, (l) => {
|
|
12171
12547
|
const t = l.text;
|
|
12172
|
-
|
|
12173
|
-
|
|
12174
|
-
|
|
12175
|
-
|
|
12176
|
-
|
|
12177
|
-
|
|
12178
|
-
|
|
12179
|
-
|
|
12180
|
-
|
|
12181
|
-
|
|
12182
|
-
|
|
12183
|
-
}
|
|
12184
|
-
if (/^classDef\b/.test(t)) {
|
|
12185
|
-
ctx.warnOnce("qclass", l.line, "quadrant point classes are skipped");
|
|
12186
|
-
continue;
|
|
12187
|
-
}
|
|
12188
|
-
const pt = t.match(/^(.+?)(?::::[\w-]+)?\s*:\s*\[\s*([\d.]+)\s*,\s*([\d.]+)\s*\]\s*(.*)$/);
|
|
12189
|
-
if (pt) {
|
|
12190
|
-
const a = attrs(pt[4].replace(/,/g, " "));
|
|
12191
|
-
if (/:::/.test(t)) ctx.warnOnce("qclass", l.line, "quadrant point classes are skipped");
|
|
12192
|
-
if (a.radius || a["stroke-color"] || a["stroke-width"]) ctx.warnOnce("qstyle", l.line, "point radius and stroke are skipped");
|
|
12193
|
-
const color = a.color && /^#[0-9a-f]{3}(?:[0-9a-f]{3})?$/i.test(a.color) ? ` [${a.color}]` : "";
|
|
12194
|
-
body.push(`${oneLine(pt[1])}${color}: ${pt[2]}, ${pt[3]}`);
|
|
12195
|
-
continue;
|
|
12196
|
-
}
|
|
12197
|
-
ctx.warn(l.line, `could not read "${t}"`);
|
|
12198
|
-
}
|
|
12199
|
-
return panel("quadrant", panelId(st.title, "matrix"), st.title, [], body);
|
|
12548
|
+
let m;
|
|
12549
|
+
if (m = t.match(QUADRANT_AXIS_RE)) {
|
|
12550
|
+
const [low, high] = m[2].split(/\s*-->\s*/).map((s) => oneLine(s));
|
|
12551
|
+
body.push(`${m[1]}-axis ${low}${high ? ` -> ${high}` : ""}`);
|
|
12552
|
+
} else if (m = t.match(QUADRANT_LABEL_RE)) body.push(`q${m[1]}: ${oneLine(m[2])}`);
|
|
12553
|
+
else if (/^classDef\b/.test(t)) ctx.warnOnce("qclass", l.line, "quadrant point classes are skipped");
|
|
12554
|
+
else if (m = t.match(QUADRANT_POINT_RE)) body.push(quadrantPoint(l, m, ctx));
|
|
12555
|
+
else return false;
|
|
12556
|
+
return true;
|
|
12557
|
+
});
|
|
12558
|
+
return panel("quadrant", panelId(state.title, "matrix"), state.title, [], body);
|
|
12200
12559
|
};
|
|
12201
12560
|
const PRIORITY = table({
|
|
12202
12561
|
"very high": "high",
|
|
@@ -12205,45 +12564,52 @@ const PRIORITY = table({
|
|
|
12205
12564
|
low: "low",
|
|
12206
12565
|
"very low": "low"
|
|
12207
12566
|
});
|
|
12567
|
+
const KANBAN_META_RE = /([\w-]+)\s*:\s*('[^']*'|"[^"]*"|[^,]+)/g;
|
|
12568
|
+
const KNOWN_META = [
|
|
12569
|
+
"assigned",
|
|
12570
|
+
"ticket",
|
|
12571
|
+
"priority"
|
|
12572
|
+
];
|
|
12573
|
+
/** an item's text and its `@{ key: value }` metadata */
|
|
12208
12574
|
function kanbanItem(t) {
|
|
12209
12575
|
const meta = {};
|
|
12210
12576
|
const at = t.match(/@\{(.*)\}\s*$/);
|
|
12211
12577
|
let s = at ? t.slice(0, at.index).trim() : t;
|
|
12212
|
-
if (at) for (const m of at[1].matchAll(
|
|
12213
|
-
const
|
|
12214
|
-
if (
|
|
12578
|
+
if (at) for (const m of at[1].matchAll(KANBAN_META_RE)) meta[m[1]] = m[2].trim().replace(/^(['"])(.*)\1$/, "$2");
|
|
12579
|
+
const bracketed = s.match(/^[\w-]*\[(.*)\]$/);
|
|
12580
|
+
if (bracketed) s = bracketed[1];
|
|
12215
12581
|
return {
|
|
12216
12582
|
text: oneLine(s, true),
|
|
12217
12583
|
meta
|
|
12218
12584
|
};
|
|
12219
12585
|
}
|
|
12586
|
+
/** card props from kanban metadata: owner, ticket, priority, then the rest as chips */
|
|
12587
|
+
function kanbanProps(meta, ctx, line) {
|
|
12588
|
+
const props = [];
|
|
12589
|
+
if (meta.assigned) props.push(`owner: ${pv(meta.assigned)}`);
|
|
12590
|
+
if (meta.ticket) props.push(`ticket: ${pv(meta.ticket)}`);
|
|
12591
|
+
if (meta.priority) {
|
|
12592
|
+
const priority = PRIORITY[meta.priority.toLowerCase()];
|
|
12593
|
+
if (!priority) ctx.warn(line, `priority "${meta.priority}" is skipped`);
|
|
12594
|
+
else {
|
|
12595
|
+
if (/very/i.test(meta.priority)) ctx.warnOnce("very", line, "\"Very High\" and \"Very Low\" priorities become high and low");
|
|
12596
|
+
props.push(`priority: ${priority}`);
|
|
12597
|
+
}
|
|
12598
|
+
}
|
|
12599
|
+
for (const [k, v] of Object.entries(meta)) if (!KNOWN_META.includes(k) && /^[\w-]+$/.test(k)) props.push(`${k}: ${pv(v)}`);
|
|
12600
|
+
return props;
|
|
12601
|
+
}
|
|
12220
12602
|
const kanban = (lines, ctx) => {
|
|
12221
12603
|
const body = [];
|
|
12222
|
-
const
|
|
12604
|
+
const columnIndent = Math.min(...lines.filter((l) => !ACC_RE.test(l.text)).map((l) => l.indent));
|
|
12223
12605
|
for (const l of lines) {
|
|
12224
12606
|
if (common(l, ctx)) continue;
|
|
12225
12607
|
const { text, meta } = kanbanItem(l.text);
|
|
12226
|
-
if (l.indent <=
|
|
12608
|
+
if (l.indent <= columnIndent) {
|
|
12227
12609
|
body.push(text);
|
|
12228
12610
|
continue;
|
|
12229
12611
|
}
|
|
12230
|
-
|
|
12231
|
-
if (meta.assigned) props.push(`owner: ${pv(meta.assigned)}`);
|
|
12232
|
-
if (meta.ticket) props.push(`ticket: ${pv(meta.ticket)}`);
|
|
12233
|
-
if (meta.priority) {
|
|
12234
|
-
const p = PRIORITY[meta.priority.toLowerCase()];
|
|
12235
|
-
if (!p) ctx.warn(l.line, `priority "${meta.priority}" is skipped`);
|
|
12236
|
-
else {
|
|
12237
|
-
if (/very/i.test(meta.priority)) ctx.warnOnce("very", l.line, "\"Very High\" and \"Very Low\" priorities become high and low");
|
|
12238
|
-
props.push(`priority: ${p}`);
|
|
12239
|
-
}
|
|
12240
|
-
}
|
|
12241
|
-
for (const [k, v] of Object.entries(meta)) if (![
|
|
12242
|
-
"assigned",
|
|
12243
|
-
"ticket",
|
|
12244
|
-
"priority"
|
|
12245
|
-
].includes(k) && /^[\w-]+$/.test(k)) props.push(`${k}: ${pv(v)}`);
|
|
12246
|
-
body.push(` - ${text}${props.length ? ` [${props.join(", ")}]` : ""}`);
|
|
12612
|
+
body.push(withOptions(` - ${text}`, kanbanProps(meta, ctx, l.line)));
|
|
12247
12613
|
}
|
|
12248
12614
|
return panel("kanban", panelId(ctx.title, "board"), ctx.title, [], body);
|
|
12249
12615
|
};
|
|
@@ -12256,270 +12622,336 @@ const kanban = (lines, ctx) => {
|
|
|
12256
12622
|
* edges to a composite go to its inner start (or first child), since yuhwa
|
|
12257
12623
|
* edges connect nodes, not groups.
|
|
12258
12624
|
*/
|
|
12259
|
-
const DIRECTIONS$1 = {
|
|
12260
|
-
TD: "down",
|
|
12261
|
-
TB: "down",
|
|
12262
|
-
BT: "up",
|
|
12263
|
-
LR: "right",
|
|
12264
|
-
RL: "left"
|
|
12265
|
-
};
|
|
12266
12625
|
const CLASS_OF = {
|
|
12267
12626
|
start: "state-start",
|
|
12268
12627
|
end: "state-end",
|
|
12269
12628
|
fork: "state-bar",
|
|
12270
12629
|
choice: "state-choice"
|
|
12271
12630
|
};
|
|
12272
|
-
const
|
|
12273
|
-
|
|
12274
|
-
|
|
12275
|
-
|
|
12631
|
+
const IGNORED_RE = /^(hide empty description|scale\b)/;
|
|
12632
|
+
const COMPOSITE_RE = /^state\s+(?:"([^"]*)"\s+as\s+)?([^\s{]+)\s*\{$/;
|
|
12633
|
+
const PSEUDO_KIND_RE = /^state\s+(\S+)\s+<<(fork|join|choice)>>$/;
|
|
12634
|
+
const STATE_ALIAS_RE = /^state\s+"([^"]*)"\s+as\s+(\S+)$/;
|
|
12635
|
+
const STATE_DECL_RE = /^state\s+([^\s:]+)\s*(?::\s*(.*))?$/;
|
|
12636
|
+
const CLASS_RE = /^class\s+([\w,\s-]+?)\s+([\w-]+)$/;
|
|
12637
|
+
const NOTE_RE = /^note\s+(?:right of|left of|over)\s+([^:]+?)\s*(?::\s*(.*))?$/i;
|
|
12638
|
+
const TRANSITION_RE = /^(\S+)\s*-->\s*(\S+?)\s*(?::\s*(.*))?$/;
|
|
12639
|
+
const DESCRIPTION_RE = /^([^\s:]+)\s*:\s*(.*)$/;
|
|
12640
|
+
const CLICK_RE = /^(click|link|callback)\b/;
|
|
12641
|
+
const BARE_NAME_RE = /^[\p{L}\p{N}_-]+$/u;
|
|
12642
|
+
const ENDPOINT_RE = /^(.+?)(?::::([\w-]+))?$/;
|
|
12643
|
+
/** Parses state diagram lines into nodes, composite boxes and edges, then writes yuhwa. */
|
|
12644
|
+
var StateDiagram = class StateDiagram {
|
|
12645
|
+
nodes = /* @__PURE__ */ new Map();
|
|
12646
|
+
boxes = /* @__PURE__ */ new Map();
|
|
12647
|
+
root = {
|
|
12276
12648
|
id: "",
|
|
12277
12649
|
label: "",
|
|
12278
12650
|
items: []
|
|
12279
12651
|
};
|
|
12280
|
-
|
|
12281
|
-
|
|
12282
|
-
|
|
12283
|
-
|
|
12284
|
-
|
|
12285
|
-
|
|
12286
|
-
|
|
12287
|
-
|
|
12652
|
+
stack = [this.root];
|
|
12653
|
+
edges = [];
|
|
12654
|
+
classDefs = [];
|
|
12655
|
+
direction = "down";
|
|
12656
|
+
title;
|
|
12657
|
+
noteCount = 0;
|
|
12658
|
+
/** the line being read; a multi-line note moves it past its `end note` */
|
|
12659
|
+
cursor;
|
|
12660
|
+
ctx;
|
|
12661
|
+
constructor(lines, ctx) {
|
|
12662
|
+
this.cursor = {
|
|
12663
|
+
lines,
|
|
12664
|
+
index: 0
|
|
12665
|
+
};
|
|
12666
|
+
this.ctx = ctx;
|
|
12667
|
+
this.title = ctx.title;
|
|
12668
|
+
}
|
|
12669
|
+
convert() {
|
|
12670
|
+
readLines(this.cursor, this.ctx, (line) => StateDiagram.HANDLERS.some((handler) => handler.call(this, line.text, line)));
|
|
12671
|
+
if (this.stack.length > 1) this.ctx.warn(this.cursor.lines[this.cursor.lines.length - 1]?.line ?? 1, "composite state is missing \"}\"");
|
|
12672
|
+
this.attachCompositeEdges();
|
|
12673
|
+
return this.write();
|
|
12674
|
+
}
|
|
12675
|
+
/** statement readers; the first match wins, so the order matters */
|
|
12676
|
+
static HANDLERS = [
|
|
12677
|
+
StateDiagram.prototype.readSkipped,
|
|
12678
|
+
StateDiagram.prototype.readTitle,
|
|
12679
|
+
StateDiagram.prototype.readDirection,
|
|
12680
|
+
StateDiagram.prototype.readCompositeClose,
|
|
12681
|
+
StateDiagram.prototype.readConcurrency,
|
|
12682
|
+
StateDiagram.prototype.readCompositeOpen,
|
|
12683
|
+
StateDiagram.prototype.readPseudoState,
|
|
12684
|
+
StateDiagram.prototype.readStateAlias,
|
|
12685
|
+
StateDiagram.prototype.readStateDeclaration,
|
|
12686
|
+
StateDiagram.prototype.readClassDef,
|
|
12687
|
+
StateDiagram.prototype.readClass,
|
|
12688
|
+
StateDiagram.prototype.readStyle,
|
|
12689
|
+
StateDiagram.prototype.readNote,
|
|
12690
|
+
StateDiagram.prototype.readTransition,
|
|
12691
|
+
StateDiagram.prototype.readDescription,
|
|
12692
|
+
StateDiagram.prototype.readClick,
|
|
12693
|
+
StateDiagram.prototype.readBareName
|
|
12694
|
+
];
|
|
12695
|
+
get current() {
|
|
12696
|
+
return this.stack[this.stack.length - 1];
|
|
12697
|
+
}
|
|
12698
|
+
/** The node for a state name, created in the current box on first mention. */
|
|
12699
|
+
node(raw, kind = "state") {
|
|
12288
12700
|
const id = toId(raw);
|
|
12289
|
-
|
|
12290
|
-
if (
|
|
12291
|
-
|
|
12292
|
-
|
|
12293
|
-
|
|
12294
|
-
|
|
12295
|
-
|
|
12296
|
-
|
|
12297
|
-
|
|
12298
|
-
|
|
12299
|
-
|
|
12300
|
-
|
|
12301
|
-
|
|
12302
|
-
|
|
12701
|
+
const existing = this.nodes.get(id);
|
|
12702
|
+
if (existing) {
|
|
12703
|
+
if (kind !== "state") existing.kind = kind;
|
|
12704
|
+
return existing;
|
|
12705
|
+
}
|
|
12706
|
+
const created = {
|
|
12707
|
+
id,
|
|
12708
|
+
kind,
|
|
12709
|
+
descs: [],
|
|
12710
|
+
classes: []
|
|
12711
|
+
};
|
|
12712
|
+
if (id !== raw.trim()) created.label = cleanLabel(raw);
|
|
12713
|
+
this.nodes.set(id, created);
|
|
12714
|
+
if (!this.boxes.has(id)) this.current.items.push(id);
|
|
12715
|
+
return created;
|
|
12716
|
+
}
|
|
12303
12717
|
/** `[*]` in the current box, as its start or end node */
|
|
12304
|
-
|
|
12305
|
-
const
|
|
12306
|
-
const key =
|
|
12307
|
-
if (!
|
|
12308
|
-
const id =
|
|
12309
|
-
|
|
12310
|
-
nodes.set(id, {
|
|
12718
|
+
pseudo(isEnd) {
|
|
12719
|
+
const box = this.current;
|
|
12720
|
+
const key = isEnd ? "end" : "start";
|
|
12721
|
+
if (!box[key]) {
|
|
12722
|
+
const id = box.id ? `${box.id}_${key}` : key;
|
|
12723
|
+
box[key] = id;
|
|
12724
|
+
this.nodes.set(id, {
|
|
12311
12725
|
id,
|
|
12312
12726
|
label: "",
|
|
12313
12727
|
kind: key,
|
|
12314
12728
|
descs: [],
|
|
12315
12729
|
classes: []
|
|
12316
12730
|
});
|
|
12317
|
-
|
|
12731
|
+
box.items.push(id);
|
|
12318
12732
|
}
|
|
12319
|
-
return
|
|
12320
|
-
}
|
|
12733
|
+
return box[key];
|
|
12734
|
+
}
|
|
12321
12735
|
/** an endpoint name: `[*]`, `X:::cls` or a plain state */
|
|
12322
|
-
|
|
12323
|
-
if (raw === "[*]") return pseudo(
|
|
12324
|
-
const
|
|
12325
|
-
if (boxes.has(toId(
|
|
12326
|
-
const
|
|
12327
|
-
if (
|
|
12328
|
-
return
|
|
12329
|
-
}
|
|
12330
|
-
|
|
12331
|
-
|
|
12332
|
-
|
|
12333
|
-
|
|
12334
|
-
|
|
12335
|
-
|
|
12336
|
-
|
|
12337
|
-
|
|
12338
|
-
|
|
12339
|
-
|
|
12340
|
-
|
|
12341
|
-
|
|
12342
|
-
|
|
12343
|
-
|
|
12344
|
-
|
|
12345
|
-
|
|
12346
|
-
|
|
12347
|
-
|
|
12348
|
-
}
|
|
12349
|
-
|
|
12350
|
-
|
|
12351
|
-
|
|
12352
|
-
|
|
12353
|
-
|
|
12354
|
-
|
|
12355
|
-
|
|
12356
|
-
|
|
12357
|
-
|
|
12358
|
-
|
|
12359
|
-
const
|
|
12360
|
-
|
|
12361
|
-
|
|
12362
|
-
|
|
12363
|
-
|
|
12364
|
-
|
|
12365
|
-
|
|
12366
|
-
|
|
12367
|
-
|
|
12368
|
-
|
|
12369
|
-
|
|
12370
|
-
|
|
12371
|
-
|
|
12372
|
-
|
|
12373
|
-
|
|
12374
|
-
|
|
12375
|
-
|
|
12376
|
-
|
|
12377
|
-
|
|
12378
|
-
|
|
12379
|
-
|
|
12380
|
-
|
|
12381
|
-
|
|
12382
|
-
|
|
12383
|
-
|
|
12384
|
-
|
|
12385
|
-
|
|
12386
|
-
|
|
12387
|
-
|
|
12388
|
-
|
|
12389
|
-
|
|
12390
|
-
|
|
12391
|
-
|
|
12392
|
-
|
|
12393
|
-
|
|
12394
|
-
|
|
12395
|
-
|
|
12396
|
-
|
|
12397
|
-
|
|
12398
|
-
|
|
12399
|
-
|
|
12400
|
-
|
|
12401
|
-
|
|
12402
|
-
|
|
12403
|
-
|
|
12404
|
-
|
|
12405
|
-
|
|
12406
|
-
|
|
12407
|
-
|
|
12408
|
-
|
|
12409
|
-
|
|
12410
|
-
|
|
12411
|
-
|
|
12412
|
-
|
|
12413
|
-
|
|
12414
|
-
|
|
12415
|
-
|
|
12416
|
-
|
|
12417
|
-
|
|
12418
|
-
|
|
12419
|
-
|
|
12420
|
-
|
|
12421
|
-
|
|
12422
|
-
|
|
12423
|
-
|
|
12424
|
-
|
|
12425
|
-
|
|
12426
|
-
|
|
12427
|
-
|
|
12428
|
-
|
|
12429
|
-
|
|
12430
|
-
const
|
|
12431
|
-
|
|
12432
|
-
|
|
12433
|
-
|
|
12434
|
-
|
|
12435
|
-
|
|
12436
|
-
|
|
12437
|
-
|
|
12438
|
-
|
|
12439
|
-
|
|
12440
|
-
|
|
12441
|
-
|
|
12442
|
-
|
|
12443
|
-
|
|
12444
|
-
|
|
12445
|
-
|
|
12446
|
-
|
|
12447
|
-
|
|
12448
|
-
|
|
12449
|
-
|
|
12450
|
-
|
|
12451
|
-
|
|
12452
|
-
|
|
12453
|
-
|
|
12736
|
+
endpoint(raw, isEnd) {
|
|
12737
|
+
if (raw === "[*]") return this.pseudo(isEnd);
|
|
12738
|
+
const [, name, className] = raw.match(ENDPOINT_RE);
|
|
12739
|
+
if (this.boxes.has(toId(name))) return toId(name);
|
|
12740
|
+
const target = this.node(name);
|
|
12741
|
+
if (className && !target.classes.includes(className)) target.classes.push(className);
|
|
12742
|
+
return target.id;
|
|
12743
|
+
}
|
|
12744
|
+
readSkipped(text) {
|
|
12745
|
+
return IGNORED_RE.test(text);
|
|
12746
|
+
}
|
|
12747
|
+
readTitle(text) {
|
|
12748
|
+
const title = titleOf(text, false);
|
|
12749
|
+
if (title !== void 0) this.title = title;
|
|
12750
|
+
return title !== void 0;
|
|
12751
|
+
}
|
|
12752
|
+
readDirection(text, line) {
|
|
12753
|
+
const match = text.match(DIRECTION_RE);
|
|
12754
|
+
if (!match) return false;
|
|
12755
|
+
if (this.stack.length > 1) this.ctx.warnOnce("subdir", line.line, "direction inside a composite state is skipped");
|
|
12756
|
+
else this.direction = DIRECTIONS[match[1].toUpperCase()];
|
|
12757
|
+
return true;
|
|
12758
|
+
}
|
|
12759
|
+
readCompositeClose(text, line) {
|
|
12760
|
+
if (text !== "}") return false;
|
|
12761
|
+
if (this.stack.length > 1) this.stack.pop();
|
|
12762
|
+
else this.ctx.warn(line.line, "\"}\" without a composite state");
|
|
12763
|
+
return true;
|
|
12764
|
+
}
|
|
12765
|
+
readConcurrency(text, line) {
|
|
12766
|
+
if (text !== "--") return false;
|
|
12767
|
+
this.ctx.warnOnce("conc", line.line, "concurrent regions (--) are drawn as one region");
|
|
12768
|
+
return true;
|
|
12769
|
+
}
|
|
12770
|
+
readCompositeOpen(text) {
|
|
12771
|
+
const match = text.match(COMPOSITE_RE);
|
|
12772
|
+
if (!match) return false;
|
|
12773
|
+
const [, quotedLabel, name] = match;
|
|
12774
|
+
const id = toId(name);
|
|
12775
|
+
if (this.nodes.delete(id)) for (const box of [this.root, ...this.boxes.values()]) box.items = box.items.filter((item) => item !== id);
|
|
12776
|
+
const box = {
|
|
12777
|
+
id,
|
|
12778
|
+
label: quotedLabel !== void 0 ? cleanLabel(quotedLabel) : name,
|
|
12779
|
+
items: []
|
|
12780
|
+
};
|
|
12781
|
+
this.boxes.set(id, box);
|
|
12782
|
+
this.current.items.push(box);
|
|
12783
|
+
this.stack.push(box);
|
|
12784
|
+
return true;
|
|
12785
|
+
}
|
|
12786
|
+
/** `state x <<fork>>`, `<<join>>` or `<<choice>>` */
|
|
12787
|
+
readPseudoState(text) {
|
|
12788
|
+
const match = text.match(PSEUDO_KIND_RE);
|
|
12789
|
+
if (match) this.node(match[1], match[2] === "choice" ? "choice" : "fork").label = "";
|
|
12790
|
+
return !!match;
|
|
12791
|
+
}
|
|
12792
|
+
readStateAlias(text) {
|
|
12793
|
+
const match = text.match(STATE_ALIAS_RE);
|
|
12794
|
+
if (match) this.node(match[2]).label = oneLine(match[1]);
|
|
12795
|
+
return !!match;
|
|
12796
|
+
}
|
|
12797
|
+
readStateDeclaration(text) {
|
|
12798
|
+
const match = text.match(STATE_DECL_RE);
|
|
12799
|
+
if (!match) return false;
|
|
12800
|
+
const declared = this.node(match[1]);
|
|
12801
|
+
if (match[2]) declared.descs.push(oneLine(match[2]));
|
|
12802
|
+
return true;
|
|
12803
|
+
}
|
|
12804
|
+
readClassDef(text, line) {
|
|
12805
|
+
const lines = classDefLines(text, (message) => this.ctx.warn(line.line, message));
|
|
12806
|
+
this.classDefs.push(...lines ?? []);
|
|
12807
|
+
return !!lines;
|
|
12808
|
+
}
|
|
12809
|
+
readClass(text) {
|
|
12810
|
+
const match = text.match(CLASS_RE);
|
|
12811
|
+
if (!match) return false;
|
|
12812
|
+
for (const name of match[1].split(",")) this.node(name.trim()).classes.push(match[2]);
|
|
12813
|
+
return true;
|
|
12814
|
+
}
|
|
12815
|
+
readStyle(text, line) {
|
|
12816
|
+
const style = styleOf(text, (message) => this.ctx.warn(line.line, message));
|
|
12817
|
+
if (style) this.node(style.target).style = style.props;
|
|
12818
|
+
return !!style;
|
|
12819
|
+
}
|
|
12820
|
+
/** A note becomes a note-shaped node with a dotted line to its state. */
|
|
12821
|
+
readNote(text) {
|
|
12822
|
+
const match = text.match(NOTE_RE);
|
|
12823
|
+
if (!match) return false;
|
|
12824
|
+
const body = match[2] ?? this.readNoteBody();
|
|
12825
|
+
const target = this.endpoint(match[1].trim(), false);
|
|
12826
|
+
const id = `note${++this.noteCount}`;
|
|
12827
|
+
this.nodes.set(id, {
|
|
12828
|
+
id,
|
|
12829
|
+
label: cleanLabel(body),
|
|
12830
|
+
kind: "note",
|
|
12831
|
+
descs: [],
|
|
12832
|
+
classes: []
|
|
12833
|
+
});
|
|
12834
|
+
this.current.items.push(id);
|
|
12835
|
+
this.edges.push({
|
|
12836
|
+
from: id,
|
|
12837
|
+
to: target,
|
|
12838
|
+
dotted: true
|
|
12839
|
+
});
|
|
12840
|
+
return true;
|
|
12841
|
+
}
|
|
12842
|
+
/** the lines up to `end note`, consumed from the input */
|
|
12843
|
+
readNoteBody() {
|
|
12844
|
+
const body = [];
|
|
12845
|
+
while (++this.cursor.index < this.cursor.lines.length && this.cursor.lines[this.cursor.index].text !== "end note") body.push(this.cursor.lines[this.cursor.index].text);
|
|
12846
|
+
return body.join("\n");
|
|
12847
|
+
}
|
|
12848
|
+
readTransition(text, line) {
|
|
12849
|
+
const match = text.match(TRANSITION_RE);
|
|
12850
|
+
if (!match) return false;
|
|
12851
|
+
const from = this.endpoint(match[1], false);
|
|
12852
|
+
const to = this.endpoint(match[2], true);
|
|
12853
|
+
this.edges.push({
|
|
12854
|
+
from,
|
|
12855
|
+
to,
|
|
12856
|
+
label: match[3] ? oneLine(match[3]) : void 0,
|
|
12857
|
+
line: line.line
|
|
12858
|
+
});
|
|
12859
|
+
return true;
|
|
12860
|
+
}
|
|
12861
|
+
readDescription(text) {
|
|
12862
|
+
const match = text.match(DESCRIPTION_RE);
|
|
12863
|
+
if (match) this.node(match[1]).descs.push(oneLine(match[2]));
|
|
12864
|
+
return !!match;
|
|
12865
|
+
}
|
|
12866
|
+
readClick(text, line) {
|
|
12867
|
+
if (!CLICK_RE.test(text)) return false;
|
|
12868
|
+
this.ctx.warnOnce("click", line.line, "click handlers are skipped");
|
|
12869
|
+
return true;
|
|
12870
|
+
}
|
|
12871
|
+
readBareName(text) {
|
|
12872
|
+
if (!BARE_NAME_RE.test(text)) return false;
|
|
12873
|
+
this.node(text);
|
|
12874
|
+
return true;
|
|
12875
|
+
}
|
|
12876
|
+
attachCompositeEdges() {
|
|
12877
|
+
for (const edge of this.edges) {
|
|
12878
|
+
const fromBox = this.boxes.get(edge.from);
|
|
12879
|
+
const toBox = this.boxes.get(edge.to);
|
|
12880
|
+
if (fromBox || toBox) this.ctx.warnOnce("composite", edge.line ?? 1, "edges to a composite state attach to its start or end inside");
|
|
12881
|
+
if (fromBox) edge.from = fromBox.end ?? lastNode(fromBox) ?? edge.from;
|
|
12882
|
+
if (toBox) edge.to = toBox.start ?? firstNode(toBox) ?? edge.to;
|
|
12454
12883
|
}
|
|
12455
|
-
warn(`could not read "${t}"`);
|
|
12456
12884
|
}
|
|
12457
|
-
|
|
12458
|
-
|
|
12459
|
-
|
|
12460
|
-
|
|
12461
|
-
|
|
12462
|
-
|
|
12463
|
-
|
|
12464
|
-
|
|
12465
|
-
|
|
12466
|
-
|
|
12467
|
-
|
|
12468
|
-
|
|
12469
|
-
|
|
12470
|
-
|
|
12471
|
-
|
|
12472
|
-
const out = [];
|
|
12473
|
-
const emit = (b, depth) => {
|
|
12885
|
+
write() {
|
|
12886
|
+
const out = [];
|
|
12887
|
+
this.writeBox(this.root, 0, out);
|
|
12888
|
+
if (this.edges.length) out.push("");
|
|
12889
|
+
for (const edge of this.edges) out.push(writeEdge(edge));
|
|
12890
|
+
const head = [this.title ? `title: ${this.title}` : "", `direction: ${this.direction}`].filter(Boolean);
|
|
12891
|
+
const defs = [...this.pseudoClassDefs(), ...this.classDefs];
|
|
12892
|
+
return [
|
|
12893
|
+
...head,
|
|
12894
|
+
...defs.length ? ["", ...defs] : [],
|
|
12895
|
+
"",
|
|
12896
|
+
...out
|
|
12897
|
+
];
|
|
12898
|
+
}
|
|
12899
|
+
writeBox(box, depth, out) {
|
|
12474
12900
|
const pad = " ".repeat(depth);
|
|
12475
|
-
for (const
|
|
12476
|
-
if (typeof
|
|
12477
|
-
out.push(
|
|
12478
|
-
emit(it, depth + 1);
|
|
12479
|
-
out.push(`${pad}}`);
|
|
12901
|
+
for (const item of box.items) {
|
|
12902
|
+
if (typeof item === "string") {
|
|
12903
|
+
out.push(pad + writeNode(this.nodes.get(item)));
|
|
12480
12904
|
continue;
|
|
12481
12905
|
}
|
|
12482
|
-
|
|
12483
|
-
|
|
12484
|
-
|
|
12485
|
-
|
|
12486
|
-
|
|
12487
|
-
|
|
12488
|
-
|
|
12489
|
-
|
|
12490
|
-
|
|
12491
|
-
|
|
12492
|
-
|
|
12493
|
-
|
|
12494
|
-
|
|
12495
|
-
|
|
12496
|
-
|
|
12497
|
-
emit(root, 0);
|
|
12498
|
-
if (edges.length) out.push("");
|
|
12499
|
-
for (const e of edges) {
|
|
12500
|
-
const arrow = e.dotted ? ".." : "->";
|
|
12501
|
-
out.push(`${e.from} ${arrow} ${e.to}${e.label ? ": " + edgeLabel(e.label) : ""}`);
|
|
12906
|
+
out.push(`${pad}group ${item.id} ${q(item.label)} {`);
|
|
12907
|
+
this.writeBox(item, depth + 1, out);
|
|
12908
|
+
out.push(`${pad}}`);
|
|
12909
|
+
}
|
|
12910
|
+
}
|
|
12911
|
+
/** classes for the pseudo-states that occur, sized for the diagram direction */
|
|
12912
|
+
pseudoClassDefs() {
|
|
12913
|
+
const used = new Set([...this.nodes.values()].map((n) => n.kind));
|
|
12914
|
+
const across = this.direction === "right" || this.direction === "left";
|
|
12915
|
+
const defs = [];
|
|
12916
|
+
if (used.has("start")) defs.push(".state-start [shape: circle, fill: slate-700, stroke: slate-700, width: 16, height: 16]");
|
|
12917
|
+
if (used.has("end")) defs.push(".state-end [shape: circle, fill: slate-700, stroke: slate-300, stroke-width: 3, width: 20, height: 20]");
|
|
12918
|
+
if (used.has("fork")) defs.push(`.state-bar [shape: box, fill: slate-700, stroke: slate-700, width: ${across ? 8 : 70}, height: ${across ? 70 : 8}]`);
|
|
12919
|
+
if (used.has("choice")) defs.push(".state-choice [shape: diamond, width: 28, height: 28]");
|
|
12920
|
+
return defs;
|
|
12502
12921
|
}
|
|
12503
|
-
const head = [title ? `title: ${title}` : "", `direction: ${direction}`].filter(Boolean);
|
|
12504
|
-
const defs = [...pseudoDefs, ...classDefs];
|
|
12505
|
-
return [
|
|
12506
|
-
...head,
|
|
12507
|
-
...defs.length ? ["", ...defs] : [],
|
|
12508
|
-
"",
|
|
12509
|
-
...out
|
|
12510
|
-
];
|
|
12511
12922
|
};
|
|
12512
|
-
|
|
12513
|
-
|
|
12514
|
-
|
|
12515
|
-
|
|
12923
|
+
const state = (lines, ctx) => new StateDiagram(lines, ctx).convert();
|
|
12924
|
+
function writeNode(node) {
|
|
12925
|
+
const parts = [node.id];
|
|
12926
|
+
const label = node.label ?? node.id;
|
|
12927
|
+
if (label !== node.id || node.kind === "note") parts.push(q(label));
|
|
12928
|
+
const kindClass = CLASS_OF[node.kind];
|
|
12929
|
+
if (kindClass) parts.push(`.${kindClass}`);
|
|
12930
|
+
for (const className of node.classes) parts.push(`.${className}`);
|
|
12931
|
+
const props = [];
|
|
12932
|
+
if (node.kind === "note") props.push("shape: note");
|
|
12933
|
+
if (node.descs.length) props.push(`sub: ${q(node.descs.join(" / "))}`);
|
|
12934
|
+
if (node.style) props.push(node.style);
|
|
12935
|
+
if (props.length) parts.push(`[${props.join(", ")}]`);
|
|
12936
|
+
return parts.join(" ");
|
|
12937
|
+
}
|
|
12938
|
+
function writeEdge(edge) {
|
|
12939
|
+
const arrow = edge.dotted ? ".." : "->";
|
|
12940
|
+
return `${edge.from} ${arrow} ${edge.to}${edge.label ? ": " + edgeLabel(edge.label) : ""}`;
|
|
12941
|
+
}
|
|
12942
|
+
/** the first node of a box, descending into child boxes */
|
|
12943
|
+
function firstNode(box) {
|
|
12944
|
+
for (const item of box.items) {
|
|
12945
|
+
const found = typeof item === "string" ? item : item.start ?? firstNode(item);
|
|
12946
|
+
if (found) return found;
|
|
12516
12947
|
}
|
|
12517
12948
|
}
|
|
12518
|
-
|
|
12519
|
-
|
|
12520
|
-
|
|
12521
|
-
const
|
|
12522
|
-
|
|
12949
|
+
/** the last node of a box, descending into child boxes */
|
|
12950
|
+
function lastNode(box) {
|
|
12951
|
+
for (let i = box.items.length - 1; i >= 0; i--) {
|
|
12952
|
+
const item = box.items[i];
|
|
12953
|
+
const found = typeof item === "string" ? item : item.end ?? lastNode(item);
|
|
12954
|
+
if (found) return found;
|
|
12523
12955
|
}
|
|
12524
12956
|
}
|
|
12525
12957
|
// src/convert/mermaid.ts
|
|
@@ -12535,13 +12967,6 @@ function lastNode(b) {
|
|
|
12535
12967
|
* over is reported, never silently dropped.
|
|
12536
12968
|
*/
|
|
12537
12969
|
const HEADER_RE = /^\s*(graph|flowchart)\b\s*(TD|TB|BT|RL|LR)?\s*;?\s*$/i;
|
|
12538
|
-
const DIRECTIONS = {
|
|
12539
|
-
TD: "down",
|
|
12540
|
-
TB: "down",
|
|
12541
|
-
BT: "up",
|
|
12542
|
-
LR: "right",
|
|
12543
|
-
RL: "left"
|
|
12544
|
-
};
|
|
12545
12970
|
/** Mermaid diagram keywords yuhwa converts, besides flowcharts */
|
|
12546
12971
|
const CONVERTERS = table({
|
|
12547
12972
|
sequenceDiagram: sequence,
|
|
@@ -12586,13 +13011,13 @@ function firstStatementIndex(lines) {
|
|
|
12586
13011
|
function mermaidHeader(source) {
|
|
12587
13012
|
const lines = source.split("\n");
|
|
12588
13013
|
const index = firstStatementIndex(lines);
|
|
12589
|
-
if (index < 0) return
|
|
13014
|
+
if (index < 0) return;
|
|
12590
13015
|
const m = lines[index].trim().match(/^([A-Za-z][\w-]*)(.*)$/);
|
|
12591
|
-
if (!m) return
|
|
13016
|
+
if (!m) return;
|
|
12592
13017
|
const [, type, rest] = m;
|
|
12593
|
-
if (!(type in CONVERTERS) && !UNSUPPORTED.test(type)) return
|
|
12594
|
-
if (/^[\w-]/.test(rest)) return
|
|
12595
|
-
if (!(type === "pie" && /^\s*(showData\b|title\b)/.test(rest)) && /"/.test(rest) || /[{]|->|=>|\.\.>|^\s*[,:.[]/.test(rest)) return
|
|
13018
|
+
if (!(type in CONVERTERS) && !UNSUPPORTED.test(type)) return;
|
|
13019
|
+
if (/^[\w-]/.test(rest)) return;
|
|
13020
|
+
if (!(type === "pie" && /^\s*(showData\b|title\b)/.test(rest)) && /"/.test(rest) || /[{]|->|=>|\.\.>|^\s*[,:.[]/.test(rest)) return;
|
|
12596
13021
|
return {
|
|
12597
13022
|
type,
|
|
12598
13023
|
rest,
|
|
@@ -12612,41 +13037,25 @@ function isOtherMermaid(source) {
|
|
|
12612
13037
|
const h = mermaidHeader(source);
|
|
12613
13038
|
return h && !(h.type in CONVERTERS) ? h.type : void 0;
|
|
12614
13039
|
}
|
|
13040
|
+
/** Converts Mermaid source to yuhwa: flowcharts here, every other type through `CONVERTERS`. */
|
|
12615
13041
|
function fromMermaid(source) {
|
|
12616
|
-
const
|
|
12617
|
-
const convert =
|
|
12618
|
-
if (!
|
|
12619
|
-
const warnings = [];
|
|
12620
|
-
const once = /* @__PURE__ */ new Set();
|
|
13042
|
+
const header = mermaidHeader(source);
|
|
13043
|
+
const convert = header && CONVERTERS[header.type];
|
|
13044
|
+
if (!header || !convert) return fromFlowchart(source);
|
|
12621
13045
|
const raw = source.split("\n");
|
|
12622
|
-
|
|
12623
|
-
|
|
12624
|
-
const t = raw[i].match(/^\s*title\s*:\s*(.+)$/);
|
|
12625
|
-
if (t) title = cleanLabel(t[1]);
|
|
12626
|
-
}
|
|
12627
|
-
const lines = [];
|
|
12628
|
-
for (let i = h.index + 1; i < raw.length; i++) {
|
|
12629
|
-
const noComment = raw[i].replace(/%%.*$/, "").replace(/\s+$/, "");
|
|
12630
|
-
const text = noComment.trim();
|
|
12631
|
-
if (!text) continue;
|
|
12632
|
-
const lead = noComment.match(/^\s*/)[0];
|
|
12633
|
-
lines.push({
|
|
12634
|
-
text,
|
|
12635
|
-
line: i + 1,
|
|
12636
|
-
indent: lead.replace(/\t/g, " ").length
|
|
12637
|
-
});
|
|
12638
|
-
}
|
|
13046
|
+
const warnings = [];
|
|
13047
|
+
const warnedKeys = /* @__PURE__ */ new Set();
|
|
12639
13048
|
return {
|
|
12640
|
-
source: convert(
|
|
12641
|
-
header:
|
|
12642
|
-
title,
|
|
13049
|
+
source: convert(bodyLines(raw, header.index + 1), {
|
|
13050
|
+
header: stripComment(header.rest).trim(),
|
|
13051
|
+
title: frontMatterTitle(raw),
|
|
12643
13052
|
warn: (line, message) => warnings.push({
|
|
12644
13053
|
line,
|
|
12645
13054
|
message
|
|
12646
13055
|
}),
|
|
12647
13056
|
warnOnce(key, line, message) {
|
|
12648
|
-
if (
|
|
12649
|
-
|
|
13057
|
+
if (warnedKeys.has(key)) return;
|
|
13058
|
+
warnedKeys.add(key);
|
|
12650
13059
|
warnings.push({
|
|
12651
13060
|
line,
|
|
12652
13061
|
message
|
|
@@ -12656,6 +13065,37 @@ function fromMermaid(source) {
|
|
|
12656
13065
|
warnings
|
|
12657
13066
|
};
|
|
12658
13067
|
}
|
|
13068
|
+
const COMMENT_RE = /%%.*$/;
|
|
13069
|
+
const FRONT_MATTER_TITLE_RE = /^\s*title\s*:\s*(.+)$/;
|
|
13070
|
+
function stripComment(line) {
|
|
13071
|
+
return line.replace(COMMENT_RE, "");
|
|
13072
|
+
}
|
|
13073
|
+
/** the `title:` of the front matter block, if any */
|
|
13074
|
+
function frontMatterTitle(lines) {
|
|
13075
|
+
let title;
|
|
13076
|
+
for (let i = 0; i < frontMatterLines(lines); i++) {
|
|
13077
|
+
const match = lines[i].match(FRONT_MATTER_TITLE_RE);
|
|
13078
|
+
if (match) title = cleanLabel(match[1]);
|
|
13079
|
+
}
|
|
13080
|
+
return title;
|
|
13081
|
+
}
|
|
13082
|
+
/** the non-blank lines from `start` on, without comments, with their indent width */
|
|
13083
|
+
function bodyLines(lines, start) {
|
|
13084
|
+
const body = [];
|
|
13085
|
+
for (let i = start; i < lines.length; i++) {
|
|
13086
|
+
const code = stripComment(lines[i]).replace(/\s+$/, "");
|
|
13087
|
+
const text = code.trim();
|
|
13088
|
+
if (!text) continue;
|
|
13089
|
+
const lead = code.match(/^\s*/)[0];
|
|
13090
|
+
body.push({
|
|
13091
|
+
text,
|
|
13092
|
+
line: i + 1,
|
|
13093
|
+
indent: lead.replace(/\t/g, " ").length
|
|
13094
|
+
});
|
|
13095
|
+
}
|
|
13096
|
+
return body;
|
|
13097
|
+
}
|
|
13098
|
+
/** opening bracket, closing bracket and the yuhwa shape ('' for the default box) */
|
|
12659
13099
|
const SHAPES = [
|
|
12660
13100
|
[
|
|
12661
13101
|
"(((",
|
|
@@ -12728,293 +13168,418 @@ const SHAPES = [
|
|
|
12728
13168
|
"box"
|
|
12729
13169
|
]
|
|
12730
13170
|
];
|
|
12731
|
-
const
|
|
13171
|
+
const NODE_ID_RE = /^[A-Za-z0-9_][\w]*(?:[.-](?![-.=>ox]\s|[-.=>])[\w]+)*/;
|
|
13172
|
+
const CLASS_NAME_RE = /^[\w-]+/;
|
|
13173
|
+
const CLASS_SHORTHAND = ":::";
|
|
13174
|
+
/** a link with its text inside: `-- text -->`, `== text ==>`, `-. text .->` */
|
|
12732
13175
|
const LINK_TEXT_RE = /^([<ox])?(--|==|-\.)([^-=.>|][^>|]*?)(-{2,}>?|={2,}>?|\.+-+>?|-\.+-*>?)(?:([ox])(?=\s|$))?/;
|
|
13176
|
+
/** a plain link, optionally followed by `|text|` */
|
|
12733
13177
|
const LINK_RE = /^([<ox])?(-{2,}|={2,}|-\.+-)(>|[ox](?=[\s|]|$))?(?:\s*\|([^|]*)\|)?/;
|
|
12734
|
-
/**
|
|
12735
|
-
|
|
12736
|
-
|
|
12737
|
-
|
|
12738
|
-
|
|
12739
|
-
|
|
12740
|
-
|
|
12741
|
-
|
|
12742
|
-
|
|
12743
|
-
|
|
12744
|
-
|
|
12745
|
-
|
|
12746
|
-
|
|
12747
|
-
|
|
12748
|
-
|
|
12749
|
-
|
|
12750
|
-
|
|
12751
|
-
|
|
12752
|
-
|
|
12753
|
-
|
|
12754
|
-
|
|
12755
|
-
|
|
12756
|
-
|
|
12757
|
-
|
|
12758
|
-
|
|
12759
|
-
|
|
12760
|
-
|
|
12761
|
-
|
|
12762
|
-
const t = lines[li].match(/^\s*title\s*:\s*(.+)$/);
|
|
12763
|
-
if (t) settings.push(`title: ${t[1].trim().replace(/^(["'])(.*)\1$/, "$2")}`);
|
|
12764
|
-
continue;
|
|
12765
|
-
}
|
|
12766
|
-
const rawLine = lines[li].replace(/%%.*$/, "");
|
|
12767
|
-
for (const stmt0 of splitStatements(rawLine)) {
|
|
12768
|
-
const stmt = stmt0.trim();
|
|
12769
|
-
if (!stmt) continue;
|
|
12770
|
-
const hm = stmt.match(HEADER_RE);
|
|
12771
|
-
if (hm) {
|
|
12772
|
-
if (hm[2]) settings.push(`direction: ${DIRECTIONS[hm[2].toUpperCase()]}`);
|
|
12773
|
-
continue;
|
|
12774
|
-
}
|
|
12775
|
-
if (/^title\s*:?/i.test(stmt) && depth === 0) {
|
|
12776
|
-
settings.push(`title: ${stmt.replace(/^title\s*:?\s*/i, "")}`);
|
|
12777
|
-
continue;
|
|
12778
|
-
}
|
|
12779
|
-
if (/^direction\s+(TD|TB|BT|RL|LR)$/i.test(stmt)) {
|
|
12780
|
-
if (depth) warn("subgraph direction is not supported; the whole diagram uses one direction");
|
|
12781
|
-
else settings.push(`direction: ${DIRECTIONS[stmt.split(/\s+/)[1].toUpperCase()]}`);
|
|
12782
|
-
continue;
|
|
12783
|
-
}
|
|
12784
|
-
const sg = stmt.match(/^subgraph\s+(.*)$/);
|
|
12785
|
-
if (sg) {
|
|
12786
|
-
const rest = sg[1].trim();
|
|
12787
|
-
let id;
|
|
12788
|
-
let title;
|
|
12789
|
-
const m1 = rest.match(/^([\w-]+)\s*\[(.*)\]$/);
|
|
12790
|
-
if (m1) [id, title] = [cid(m1[1]), cleanLabel(m1[2])];
|
|
12791
|
-
else if (/^".*"$/.test(rest)) [title, id] = [cleanLabel(rest), cid(cleanLabel(rest).toLowerCase())];
|
|
12792
|
-
else if (/^[\w-]+$/.test(rest)) [id, title] = [cid(rest), rest];
|
|
12793
|
-
else [title, id] = [rest, cid(rest.toLowerCase())];
|
|
12794
|
-
groupIds.add(id);
|
|
12795
|
-
out.push(`${pad()}group ${id} ${q(title)} {`);
|
|
12796
|
-
depth++;
|
|
12797
|
-
continue;
|
|
12798
|
-
}
|
|
12799
|
-
if (stmt === "end") {
|
|
12800
|
-
if (depth) {
|
|
12801
|
-
depth--;
|
|
12802
|
-
out.push(`${pad()}}`);
|
|
12803
|
-
} else warn("\"end\" without subgraph");
|
|
12804
|
-
continue;
|
|
12805
|
-
}
|
|
12806
|
-
const cd = stmt.match(/^classDef\s+([\w,-]+)\s+(.*)$/);
|
|
12807
|
-
if (cd) {
|
|
12808
|
-
const props = cssProps(cd[2], warn);
|
|
12809
|
-
for (const name of cd[1].split(",")) classDefs.push(`.${name.trim()} [${props}]`);
|
|
12810
|
-
continue;
|
|
12811
|
-
}
|
|
12812
|
-
const cl = stmt.match(/^class\s+([\w,\s-]+?)\s+([\w-]+)$/);
|
|
12813
|
-
if (cl) {
|
|
12814
|
-
for (const n of cl[1].split(",")) out.push(`${pad()}${cid(n.trim())} .${cl[2]}`);
|
|
12815
|
-
continue;
|
|
12816
|
-
}
|
|
12817
|
-
const st = stmt.match(/^style\s+([\w-]+)\s+(.*)$/);
|
|
12818
|
-
if (st) {
|
|
12819
|
-
const props = cssProps(st[2], warn);
|
|
12820
|
-
if (props) out.push(`${pad()}${cid(st[1])} [${props}]`);
|
|
12821
|
-
continue;
|
|
12822
|
-
}
|
|
12823
|
-
if (/^(linkStyle|click|accTitle|accDescr|callback|interpolate)\b/.test(stmt)) {
|
|
12824
|
-
warn(`"${stmt.split(/\s+/)[0]}" is not supported and was skipped`);
|
|
12825
|
-
continue;
|
|
12826
|
-
}
|
|
12827
|
-
const r = parseFlowStatement(stmt, cid, warn);
|
|
12828
|
-
if (!r) continue;
|
|
12829
|
-
for (const n of r.nodes) {
|
|
12830
|
-
const parts = [n.id];
|
|
12831
|
-
if (n.label !== void 0 && n.label !== n.id) parts.push(q(n.label));
|
|
12832
|
-
for (const c of n.classes) parts.push(`.${c}`);
|
|
12833
|
-
if (n.shape) parts.push(`[shape: ${n.shape}]`);
|
|
12834
|
-
if (!declared.has(n.id) || parts.length > 1 || depth) {
|
|
12835
|
-
out.push(pad() + parts.join(" "));
|
|
12836
|
-
declared.add(n.id);
|
|
12837
|
-
}
|
|
13178
|
+
/**
|
|
13179
|
+
* Reads one node/link statement such as `A[Start] --> B & C -->|yes| D`.
|
|
13180
|
+
* `A & B --> C` links every node on the left to every node on the right.
|
|
13181
|
+
*/
|
|
13182
|
+
var FlowStatementReader = class {
|
|
13183
|
+
pos = 0;
|
|
13184
|
+
nodes = [];
|
|
13185
|
+
edges = [];
|
|
13186
|
+
text;
|
|
13187
|
+
toId;
|
|
13188
|
+
warn;
|
|
13189
|
+
constructor(text, toId, warn) {
|
|
13190
|
+
this.text = text;
|
|
13191
|
+
this.toId = toId;
|
|
13192
|
+
this.warn = warn;
|
|
13193
|
+
}
|
|
13194
|
+
read() {
|
|
13195
|
+
const first = this.readNodeGroup();
|
|
13196
|
+
if (!first) {
|
|
13197
|
+
this.warn(`could not read "${this.text}"`);
|
|
13198
|
+
return null;
|
|
13199
|
+
}
|
|
13200
|
+
let left = first;
|
|
13201
|
+
while (!this.atEnd()) {
|
|
13202
|
+
const link = this.readLink();
|
|
13203
|
+
if (!link) {
|
|
13204
|
+
this.warn(`could not read "${this.text.slice(this.pos)}"`);
|
|
13205
|
+
break;
|
|
12838
13206
|
}
|
|
12839
|
-
|
|
12840
|
-
|
|
12841
|
-
|
|
13207
|
+
const right = this.readNodeGroup();
|
|
13208
|
+
if (!right) {
|
|
13209
|
+
this.warn(`link without a target in "${this.text}"`);
|
|
13210
|
+
break;
|
|
12842
13211
|
}
|
|
13212
|
+
this.addEdges(left, right, link);
|
|
13213
|
+
left = right;
|
|
13214
|
+
}
|
|
13215
|
+
return {
|
|
13216
|
+
nodes: this.nodes,
|
|
13217
|
+
edges: this.edges
|
|
13218
|
+
};
|
|
13219
|
+
}
|
|
13220
|
+
atEnd() {
|
|
13221
|
+
this.skipSpace();
|
|
13222
|
+
return this.pos >= this.text.length;
|
|
13223
|
+
}
|
|
13224
|
+
skipSpace() {
|
|
13225
|
+
while (this.pos < this.text.length && /\s/.test(this.text[this.pos])) this.pos++;
|
|
13226
|
+
}
|
|
13227
|
+
rest() {
|
|
13228
|
+
return this.text.slice(this.pos);
|
|
13229
|
+
}
|
|
13230
|
+
/** `A & B & C`: one or more nodes joined by `&` */
|
|
13231
|
+
readNodeGroup() {
|
|
13232
|
+
const group = [];
|
|
13233
|
+
for (;;) {
|
|
13234
|
+
const node = this.readNode();
|
|
13235
|
+
if (!node) return group.length ? group : null;
|
|
13236
|
+
group.push(node);
|
|
13237
|
+
this.skipSpace();
|
|
13238
|
+
if (this.text[this.pos] !== "&") return group;
|
|
13239
|
+
this.pos++;
|
|
13240
|
+
}
|
|
13241
|
+
}
|
|
13242
|
+
/** `id`, optionally followed by a bracketed label and `:::class` suffixes */
|
|
13243
|
+
readNode() {
|
|
13244
|
+
this.skipSpace();
|
|
13245
|
+
const idMatch = this.rest().match(NODE_ID_RE);
|
|
13246
|
+
if (!idMatch) return null;
|
|
13247
|
+
this.pos += idMatch[0].length;
|
|
13248
|
+
const node = {
|
|
13249
|
+
id: this.toId(idMatch[0]),
|
|
13250
|
+
classes: []
|
|
13251
|
+
};
|
|
13252
|
+
this.readShape(node);
|
|
13253
|
+
this.readClasses(node);
|
|
13254
|
+
this.nodes.push(node);
|
|
13255
|
+
return node;
|
|
13256
|
+
}
|
|
13257
|
+
readShape(node) {
|
|
13258
|
+
for (const [open, close, shape] of SHAPES) {
|
|
13259
|
+
if (!this.text.startsWith(open, this.pos)) continue;
|
|
13260
|
+
const labelStart = this.pos + open.length;
|
|
13261
|
+
const closeAt = findClose(this.text, labelStart, close);
|
|
13262
|
+
if (closeAt < 0) continue;
|
|
13263
|
+
node.label = cleanLabel(this.text.slice(labelStart, closeAt));
|
|
13264
|
+
node.shape = shape || void 0;
|
|
13265
|
+
this.pos = closeAt + close.length;
|
|
13266
|
+
return;
|
|
12843
13267
|
}
|
|
12844
13268
|
}
|
|
12845
|
-
|
|
12846
|
-
|
|
12847
|
-
|
|
12848
|
-
|
|
12849
|
-
|
|
12850
|
-
|
|
13269
|
+
readClasses(node) {
|
|
13270
|
+
while (this.text.startsWith(CLASS_SHORTHAND, this.pos)) {
|
|
13271
|
+
const name = this.text.slice(this.pos + 3).match(CLASS_NAME_RE);
|
|
13272
|
+
if (!name) return;
|
|
13273
|
+
node.classes.push(name[0]);
|
|
13274
|
+
this.pos += 3 + name[0].length;
|
|
13275
|
+
}
|
|
13276
|
+
}
|
|
13277
|
+
readLink() {
|
|
13278
|
+
const rest = this.rest();
|
|
13279
|
+
const withText = rest.match(LINK_TEXT_RE);
|
|
13280
|
+
if (withText && /[->=]/.test(withText[4])) {
|
|
13281
|
+
this.pos += withText[0].length;
|
|
13282
|
+
const [, start, body, label, closing, endMarker] = withText;
|
|
13283
|
+
return {
|
|
13284
|
+
start,
|
|
13285
|
+
body,
|
|
13286
|
+
end: closing.endsWith(">") ? ">" : endMarker,
|
|
13287
|
+
label: cleanLabel(label)
|
|
13288
|
+
};
|
|
13289
|
+
}
|
|
13290
|
+
const plain = rest.match(LINK_RE);
|
|
13291
|
+
if (!plain) return null;
|
|
13292
|
+
this.pos += plain[0].length;
|
|
13293
|
+
const [, start, body, end, label] = plain;
|
|
13294
|
+
return {
|
|
13295
|
+
start,
|
|
13296
|
+
body,
|
|
13297
|
+
end,
|
|
13298
|
+
label: label !== void 0 ? cleanLabel(label) : void 0
|
|
13299
|
+
};
|
|
13300
|
+
}
|
|
13301
|
+
addEdges(left, right, link) {
|
|
13302
|
+
const { arrow, props } = edgeStyle(link);
|
|
13303
|
+
for (const from of left) for (const to of right) this.edges.push({
|
|
13304
|
+
from: from.id,
|
|
13305
|
+
to: to.id,
|
|
13306
|
+
arrow,
|
|
13307
|
+
label: link.label || void 0,
|
|
13308
|
+
props
|
|
12851
13309
|
});
|
|
12852
13310
|
}
|
|
12853
|
-
|
|
12854
|
-
|
|
12855
|
-
|
|
12856
|
-
|
|
12857
|
-
|
|
13311
|
+
};
|
|
13312
|
+
const END_MARKER_PROPS = {
|
|
13313
|
+
o: "dot",
|
|
13314
|
+
x: "bar"
|
|
13315
|
+
};
|
|
13316
|
+
/** the yuhwa arrow and edge props for a Mermaid link */
|
|
13317
|
+
function edgeStyle({ start, body, end }) {
|
|
13318
|
+
const thick = body.startsWith("=");
|
|
13319
|
+
const dotted = body.includes(".");
|
|
13320
|
+
const arrow = start && end ? "<->" : !end ? "--" : thick ? "=>" : dotted ? "..>" : "->";
|
|
13321
|
+
const props = [];
|
|
13322
|
+
if (arrow === "<->" || arrow === "--") pushLineProps(props, thick, dotted);
|
|
13323
|
+
pushMarkerProps(props, start, end);
|
|
13324
|
+
if (start && !end) props.push("tail: arrow");
|
|
12858
13325
|
return {
|
|
12859
|
-
|
|
12860
|
-
|
|
12861
|
-
...head.length ? [""] : [],
|
|
12862
|
-
...out
|
|
12863
|
-
].join("\n") + "\n",
|
|
12864
|
-
warnings
|
|
13326
|
+
arrow,
|
|
13327
|
+
props
|
|
12865
13328
|
};
|
|
12866
13329
|
}
|
|
13330
|
+
/** width and dash for arrows that cannot carry them in the arrow itself (`--`, `<->`) */
|
|
13331
|
+
function pushLineProps(props, thick, dotted) {
|
|
13332
|
+
if (thick) props.push("width: 3");
|
|
13333
|
+
if (dotted) props.push("style: dotted");
|
|
13334
|
+
}
|
|
13335
|
+
function pushMarkerProps(props, start, end) {
|
|
13336
|
+
if (end && end in END_MARKER_PROPS) props.push(`head: ${END_MARKER_PROPS[end]}`);
|
|
13337
|
+
if (start && start in END_MARKER_PROPS) props.push(`tail: ${END_MARKER_PROPS[start]}`);
|
|
13338
|
+
}
|
|
13339
|
+
/** index of `close` at or after `from`, skipping quoted text; -1 when missing */
|
|
13340
|
+
function findClose(text, from, close) {
|
|
13341
|
+
let quoted = false;
|
|
13342
|
+
for (let i = from; i < text.length; i++) {
|
|
13343
|
+
if (text[i] === "\"") quoted = !quoted;
|
|
13344
|
+
if (!quoted && text.startsWith(close, i)) return i;
|
|
13345
|
+
}
|
|
13346
|
+
return -1;
|
|
13347
|
+
}
|
|
12867
13348
|
/** split on `;` outside brackets and quotes */
|
|
12868
13349
|
function splitStatements(line) {
|
|
12869
|
-
const
|
|
13350
|
+
const statements = [];
|
|
12870
13351
|
let depth = 0;
|
|
12871
13352
|
let quote = "";
|
|
12872
13353
|
let start = 0;
|
|
12873
13354
|
for (let i = 0; i < line.length; i++) {
|
|
12874
|
-
const
|
|
13355
|
+
const char = line[i];
|
|
12875
13356
|
if (quote) {
|
|
12876
|
-
if (
|
|
12877
|
-
} else if (
|
|
12878
|
-
else if ("[({".includes(
|
|
12879
|
-
else if (")]}".includes(
|
|
12880
|
-
else if (
|
|
12881
|
-
|
|
13357
|
+
if (char === quote) quote = "";
|
|
13358
|
+
} else if (char === "\"") quote = char;
|
|
13359
|
+
else if ("[({".includes(char)) depth++;
|
|
13360
|
+
else if (")]}".includes(char)) depth = Math.max(0, depth - 1);
|
|
13361
|
+
else if (char === ";" && depth === 0) {
|
|
13362
|
+
statements.push(line.slice(start, i));
|
|
12882
13363
|
start = i + 1;
|
|
12883
13364
|
}
|
|
12884
13365
|
}
|
|
12885
|
-
|
|
12886
|
-
return
|
|
13366
|
+
statements.push(line.slice(start));
|
|
13367
|
+
return statements;
|
|
12887
13368
|
}
|
|
12888
|
-
|
|
12889
|
-
|
|
12890
|
-
|
|
12891
|
-
|
|
12892
|
-
|
|
12893
|
-
|
|
12894
|
-
|
|
12895
|
-
|
|
12896
|
-
|
|
12897
|
-
|
|
12898
|
-
|
|
12899
|
-
|
|
12900
|
-
|
|
12901
|
-
|
|
12902
|
-
|
|
12903
|
-
|
|
12904
|
-
|
|
12905
|
-
|
|
12906
|
-
|
|
12907
|
-
|
|
12908
|
-
|
|
12909
|
-
|
|
12910
|
-
|
|
12911
|
-
|
|
12912
|
-
|
|
12913
|
-
|
|
12914
|
-
|
|
12915
|
-
|
|
12916
|
-
|
|
12917
|
-
|
|
13369
|
+
const SUBGRAPH_RE = /^subgraph\s+(.*)$/;
|
|
13370
|
+
const SUBGRAPH_ID_TITLE_RE = /^([\w-]+)\s*\[(.*)\]$/;
|
|
13371
|
+
const CLASS_ASSIGN_RE = /^class\s+([\w,\s-]+?)\s+([\w-]+)$/;
|
|
13372
|
+
const UNSUPPORTED_STATEMENT_RE = /^(linkStyle|click|accTitle|accDescr|callback|interpolate)\b/;
|
|
13373
|
+
/** edge labels that read fine without quotes */
|
|
13374
|
+
const PLAIN_LABEL_RE = /^[\p{L}\p{N}][\p{L}\p{N} ,!?'()+-]*$/u;
|
|
13375
|
+
/** Mermaid flowchart → yuhwa nodes, edges and groups */
|
|
13376
|
+
function fromFlowchart(source) {
|
|
13377
|
+
const lines = source.split("\n");
|
|
13378
|
+
const writer = new FlowchartWriter(frontMatterTitle(lines));
|
|
13379
|
+
for (let index = frontMatterLines(lines); index < lines.length; index++) for (const statement of splitStatements(stripComment(lines[index]))) writer.statement(statement.trim(), index + 1);
|
|
13380
|
+
return writer.finish(lines.length);
|
|
13381
|
+
}
|
|
13382
|
+
var FlowchartWriter = class {
|
|
13383
|
+
warnings = [];
|
|
13384
|
+
settings = [];
|
|
13385
|
+
classDefs = [];
|
|
13386
|
+
/** written lines; edge lines stay open so later edges can join them */
|
|
13387
|
+
body = [];
|
|
13388
|
+
/** Mermaid id → yuhwa id */
|
|
13389
|
+
ids = /* @__PURE__ */ new Map();
|
|
13390
|
+
/** node ids already written or created by an edge */
|
|
13391
|
+
declared = /* @__PURE__ */ new Set();
|
|
13392
|
+
groupIds = /* @__PURE__ */ new Set();
|
|
13393
|
+
depth = 0;
|
|
13394
|
+
/** edge lines of the current block, by head and tail */
|
|
13395
|
+
openEdges = /* @__PURE__ */ new Map();
|
|
13396
|
+
/** 1-based number of the line being read, for warnings */
|
|
13397
|
+
line = 0;
|
|
13398
|
+
/** `title` is the front matter title; Mermaid's config does not apply */
|
|
13399
|
+
constructor(title) {
|
|
13400
|
+
if (title !== void 0) this.settings.push(`title: ${title}`);
|
|
13401
|
+
}
|
|
13402
|
+
statement(text, line) {
|
|
13403
|
+
if (!text) return;
|
|
13404
|
+
this.line = line;
|
|
13405
|
+
if (!(this.header(text) || this.title(text) || this.direction(text) || this.subgraph(text) || this.end(text) || this.classDef(text) || this.classAssign(text) || this.style(text) || this.unsupported(text))) this.nodesAndEdges(text);
|
|
13406
|
+
}
|
|
13407
|
+
finish(lineCount) {
|
|
13408
|
+
while (this.depth > 0) {
|
|
13409
|
+
this.closeGroup();
|
|
13410
|
+
this.warnings.push({
|
|
13411
|
+
line: lineCount,
|
|
13412
|
+
message: "subgraph is missing \"end\""
|
|
13413
|
+
});
|
|
12918
13414
|
}
|
|
12919
|
-
|
|
12920
|
-
|
|
12921
|
-
|
|
12922
|
-
|
|
12923
|
-
const
|
|
12924
|
-
|
|
12925
|
-
|
|
12926
|
-
|
|
12927
|
-
|
|
12928
|
-
|
|
12929
|
-
|
|
12930
|
-
|
|
12931
|
-
|
|
12932
|
-
|
|
12933
|
-
|
|
13415
|
+
for (const id of this.groupIds) if (this.declared.has(id)) this.warnings.push({
|
|
13416
|
+
line: 1,
|
|
13417
|
+
message: `"${id}" is both a node and a subgraph; edges to subgraphs are not supported`
|
|
13418
|
+
});
|
|
13419
|
+
const head = [...this.settings, ...this.classDefs.length ? ["", ...this.classDefs] : []];
|
|
13420
|
+
const body = this.body.map((line) => typeof line === "string" ? line : edgeLine(line));
|
|
13421
|
+
return {
|
|
13422
|
+
source: [
|
|
13423
|
+
...head,
|
|
13424
|
+
...head.length ? [""] : [],
|
|
13425
|
+
...body
|
|
13426
|
+
].join("\n") + "\n",
|
|
13427
|
+
warnings: this.warnings
|
|
13428
|
+
};
|
|
13429
|
+
}
|
|
13430
|
+
header(text) {
|
|
13431
|
+
const match = text.match(HEADER_RE);
|
|
13432
|
+
if (!match) return false;
|
|
13433
|
+
if (match[2]) this.settings.push(`direction: ${DIRECTIONS[match[2].toUpperCase()]}`);
|
|
13434
|
+
return true;
|
|
13435
|
+
}
|
|
13436
|
+
/** `title` inside a subgraph is a node id, not a setting */
|
|
13437
|
+
title(text) {
|
|
13438
|
+
const title = titleOf(text);
|
|
13439
|
+
if (title === void 0 || this.depth > 0) return false;
|
|
13440
|
+
this.settings.push(`title: ${title}`);
|
|
13441
|
+
return true;
|
|
13442
|
+
}
|
|
13443
|
+
direction(text) {
|
|
13444
|
+
const match = text.match(DIRECTION_RE);
|
|
13445
|
+
if (!match) return false;
|
|
13446
|
+
if (this.depth > 0) this.warn("subgraph direction is not supported; the whole diagram uses one direction");
|
|
13447
|
+
else this.settings.push(`direction: ${DIRECTIONS[match[1].toUpperCase()]}`);
|
|
13448
|
+
return true;
|
|
13449
|
+
}
|
|
13450
|
+
subgraph(text) {
|
|
13451
|
+
const match = text.match(SUBGRAPH_RE);
|
|
13452
|
+
if (!match) return false;
|
|
13453
|
+
const { id, title } = this.subgraphIdAndTitle(match[1].trim());
|
|
13454
|
+
this.groupIds.add(id);
|
|
13455
|
+
this.write(`group ${id} ${q(title)} {`);
|
|
13456
|
+
this.depth++;
|
|
13457
|
+
this.openEdges = /* @__PURE__ */ new Map();
|
|
13458
|
+
return true;
|
|
13459
|
+
}
|
|
13460
|
+
/** `id [Title]`, `"Title"`, `id` or a bare multi-word title */
|
|
13461
|
+
subgraphIdAndTitle(rest) {
|
|
13462
|
+
const idAndTitle = rest.match(SUBGRAPH_ID_TITLE_RE);
|
|
13463
|
+
if (idAndTitle) return {
|
|
13464
|
+
id: this.toId(idAndTitle[1]),
|
|
13465
|
+
title: cleanLabel(idAndTitle[2])
|
|
13466
|
+
};
|
|
13467
|
+
if (/^".*"$/.test(rest)) {
|
|
13468
|
+
const title = cleanLabel(rest);
|
|
13469
|
+
return {
|
|
13470
|
+
id: this.toId(title.toLowerCase()),
|
|
13471
|
+
title
|
|
13472
|
+
};
|
|
12934
13473
|
}
|
|
12935
|
-
|
|
12936
|
-
|
|
12937
|
-
|
|
12938
|
-
|
|
12939
|
-
return
|
|
13474
|
+
if (/^[\w-]+$/.test(rest)) return {
|
|
13475
|
+
id: this.toId(rest),
|
|
13476
|
+
title: rest
|
|
13477
|
+
};
|
|
13478
|
+
return {
|
|
13479
|
+
id: this.toId(rest.toLowerCase()),
|
|
13480
|
+
title: rest
|
|
13481
|
+
};
|
|
12940
13482
|
}
|
|
12941
|
-
|
|
12942
|
-
|
|
12943
|
-
|
|
12944
|
-
|
|
12945
|
-
|
|
12946
|
-
|
|
12947
|
-
|
|
12948
|
-
|
|
12949
|
-
|
|
12950
|
-
|
|
12951
|
-
|
|
12952
|
-
|
|
12953
|
-
|
|
12954
|
-
|
|
12955
|
-
|
|
12956
|
-
|
|
12957
|
-
|
|
12958
|
-
|
|
12959
|
-
|
|
12960
|
-
|
|
12961
|
-
|
|
12962
|
-
|
|
12963
|
-
|
|
12964
|
-
|
|
12965
|
-
|
|
12966
|
-
|
|
12967
|
-
|
|
12968
|
-
|
|
12969
|
-
|
|
12970
|
-
}
|
|
12971
|
-
|
|
12972
|
-
|
|
12973
|
-
|
|
12974
|
-
const
|
|
12975
|
-
|
|
12976
|
-
const
|
|
12977
|
-
|
|
12978
|
-
|
|
12979
|
-
|
|
12980
|
-
|
|
12981
|
-
|
|
12982
|
-
|
|
12983
|
-
|
|
12984
|
-
|
|
12985
|
-
|
|
12986
|
-
if (
|
|
12987
|
-
|
|
12988
|
-
if (
|
|
12989
|
-
|
|
12990
|
-
|
|
12991
|
-
|
|
12992
|
-
|
|
12993
|
-
if (!
|
|
12994
|
-
|
|
12995
|
-
|
|
13483
|
+
end(text) {
|
|
13484
|
+
if (text !== "end") return false;
|
|
13485
|
+
if (this.depth > 0) this.closeGroup();
|
|
13486
|
+
else this.warn("\"end\" without subgraph");
|
|
13487
|
+
return true;
|
|
13488
|
+
}
|
|
13489
|
+
closeGroup() {
|
|
13490
|
+
this.depth--;
|
|
13491
|
+
this.openEdges = /* @__PURE__ */ new Map();
|
|
13492
|
+
this.write("}");
|
|
13493
|
+
}
|
|
13494
|
+
classDef(text) {
|
|
13495
|
+
const lines = classDefLines(text, (message) => this.warn(message));
|
|
13496
|
+
this.classDefs.push(...lines ?? []);
|
|
13497
|
+
return !!lines;
|
|
13498
|
+
}
|
|
13499
|
+
classAssign(text) {
|
|
13500
|
+
const match = text.match(CLASS_ASSIGN_RE);
|
|
13501
|
+
if (!match) return false;
|
|
13502
|
+
for (const node of match[1].split(",")) this.write(`${this.toId(node.trim())} .${match[2]}`);
|
|
13503
|
+
return true;
|
|
13504
|
+
}
|
|
13505
|
+
style(text) {
|
|
13506
|
+
const style = styleOf(text, (message) => this.warn(message));
|
|
13507
|
+
if (style?.props) this.write(`${this.toId(style.target)} [${style.props}]`);
|
|
13508
|
+
return !!style;
|
|
13509
|
+
}
|
|
13510
|
+
unsupported(text) {
|
|
13511
|
+
if (!UNSUPPORTED_STATEMENT_RE.test(text)) return false;
|
|
13512
|
+
this.warn(`"${text.split(/\s+/)[0]}" is not supported and was skipped`);
|
|
13513
|
+
return true;
|
|
13514
|
+
}
|
|
13515
|
+
nodesAndEdges(text) {
|
|
13516
|
+
const statement = new FlowStatementReader(text, (raw) => this.toId(raw), (message) => this.warn(message)).read();
|
|
13517
|
+
if (!statement) return;
|
|
13518
|
+
const linked = new Set(statement.edges.flatMap((edge) => [edge.from, edge.to]));
|
|
13519
|
+
for (const node of statement.nodes) this.writeNode(node, linked.has(node.id));
|
|
13520
|
+
for (const edge of statement.edges) this.writeEdge(edge);
|
|
13521
|
+
}
|
|
13522
|
+
/**
|
|
13523
|
+
* Writes a node line only when it adds something. A bare id at the top level
|
|
13524
|
+
* is created by its edge; inside a subgraph it marks membership.
|
|
13525
|
+
*/
|
|
13526
|
+
writeNode(node, linked) {
|
|
13527
|
+
const parts = [node.id];
|
|
13528
|
+
if (node.label !== void 0 && node.label !== node.id) parts.push(q(node.label));
|
|
13529
|
+
for (const name of node.classes) parts.push(`.${name}`);
|
|
13530
|
+
if (node.shape) parts.push(`[shape: ${node.shape}]`);
|
|
13531
|
+
const bare = parts.length === 1;
|
|
13532
|
+
const inGroup = this.depth > 0;
|
|
13533
|
+
if (this.declared.has(node.id) && bare && !inGroup) return;
|
|
13534
|
+
this.declared.add(node.id);
|
|
13535
|
+
if (!bare || inGroup || !linked) this.write(parts.join(" "));
|
|
13536
|
+
}
|
|
13537
|
+
/** edges in one block from one node with the same arrow and tail fan out: `a -> b, c` */
|
|
13538
|
+
writeEdge(edge) {
|
|
13539
|
+
const tail = edgeTail(edge);
|
|
13540
|
+
const head = `${this.indent()}${edge.from} ${edge.arrow} `;
|
|
13541
|
+
const key = `${head}\0${tail}`;
|
|
13542
|
+
const open = this.openEdges.get(key);
|
|
13543
|
+
if (open) {
|
|
13544
|
+
open.targets.push(edge.to);
|
|
13545
|
+
return;
|
|
12996
13546
|
}
|
|
12997
|
-
|
|
12998
|
-
|
|
12999
|
-
|
|
13000
|
-
|
|
13001
|
-
|
|
13002
|
-
|
|
13547
|
+
const line = {
|
|
13548
|
+
head,
|
|
13549
|
+
targets: [edge.to],
|
|
13550
|
+
tail
|
|
13551
|
+
};
|
|
13552
|
+
this.openEdges.set(key, line);
|
|
13553
|
+
this.body.push(line);
|
|
13554
|
+
}
|
|
13555
|
+
warn(message) {
|
|
13556
|
+
this.warnings.push({
|
|
13557
|
+
line: this.line,
|
|
13558
|
+
message
|
|
13003
13559
|
});
|
|
13004
|
-
left = right;
|
|
13005
13560
|
}
|
|
13006
|
-
|
|
13007
|
-
|
|
13008
|
-
edges
|
|
13009
|
-
};
|
|
13010
|
-
}
|
|
13011
|
-
function findClose(s, from, close) {
|
|
13012
|
-
let quote = false;
|
|
13013
|
-
for (let j = from; j < s.length; j++) {
|
|
13014
|
-
if (s[j] === "\"") quote = !quote;
|
|
13015
|
-
if (!quote && s.startsWith(close, j)) return j;
|
|
13561
|
+
write(line) {
|
|
13562
|
+
this.body.push(this.indent() + line);
|
|
13016
13563
|
}
|
|
13017
|
-
|
|
13564
|
+
indent() {
|
|
13565
|
+
return " ".repeat(this.depth);
|
|
13566
|
+
}
|
|
13567
|
+
/** a valid yuhwa id for a Mermaid id; the same input gives the same id */
|
|
13568
|
+
toId(raw) {
|
|
13569
|
+
let id = this.ids.get(raw);
|
|
13570
|
+
if (id === void 0) {
|
|
13571
|
+
id = toId(raw);
|
|
13572
|
+
this.ids.set(raw, id);
|
|
13573
|
+
}
|
|
13574
|
+
return id;
|
|
13575
|
+
}
|
|
13576
|
+
};
|
|
13577
|
+
/** what follows the colon of an edge: its label and props */
|
|
13578
|
+
function edgeTail(edge) {
|
|
13579
|
+
return [edge.label ? PLAIN_LABEL_RE.test(edge.label) ? edge.label : q(edge.label) : "", edge.props.length ? `[${edge.props.join(", ")}]` : ""].filter(Boolean).join(" ");
|
|
13580
|
+
}
|
|
13581
|
+
function edgeLine({ head, targets, tail }) {
|
|
13582
|
+
return `${head}${targets.join(", ")}${tail ? ": " + tail : ""}`;
|
|
13018
13583
|
}
|
|
13019
13584
|
// src/markdown.ts
|
|
13020
13585
|
/**
|
|
@@ -13259,7 +13824,7 @@ function render(input, opts = {}) {
|
|
|
13259
13824
|
/** Node-only helper for the CLI and build-time integrations: `import` reads from disk. */
|
|
13260
13825
|
/** Reads an `import "..."` target from disk; like `parse`, only `.yu` files. */
|
|
13261
13826
|
function diskResolve(path) {
|
|
13262
|
-
if (!isYuhwaPath(path)) return
|
|
13827
|
+
if (!isYuhwaPath(path)) return;
|
|
13263
13828
|
try {
|
|
13264
13829
|
return readFileSync(path, "utf8");
|
|
13265
13830
|
} catch {
|
|
@@ -13570,5 +14135,5 @@ function onTypeEdits(text, pos, ch) {
|
|
|
13570
14135
|
}
|
|
13571
14136
|
// src/version.ts
|
|
13572
14137
|
/** the package version, inlined by the build */
|
|
13573
|
-
const VERSION = "1.5.
|
|
13574
|
-
export { BOOLS as A,
|
|
14138
|
+
const VERSION = "1.5.2";
|
|
14139
|
+
export { BOOLS as A, SHAPES$2 as B, blockBraces as C, parse as D, lex as E, NODE_PROPS as F, THEME_KEYS as G, esc as H, NUMBERS as I, isSafeCss as J, THEME_NAMES as K, PANEL_PROPS as L, EDGE_PROPS as M, ENUMS as N, serializeProps as O, GROUP_PROPS as P, PANEL_PROP_HELP as R, SETTING_VALUES as S, joinPath$1 as T, parseSpanStyle as U, SPAN_KEYS as V, spanKey as W, table as X, themeNames as Y, canvasMeasure as _, formatPage as a, KNOWN_SETTINGS as b, diskResolve as c, MD_LANGUAGES as d, findBlocks as f, replaceBlockSource as g, processMarkdown as h, format as i, COLORS as j, unquote as k, render as l, pageBlocks as m, applyChange as n, onTypeEdits as o, isMarkdown as p, TONES as q, diffEdits as r, tidy as s, VERSION as t, toSource as u, optionKind as v, isYuhwaPath as w, PANELS as x, registry as y, PLACEMENT_PROPS as z };
|