yuhwa 1.9.0 → 1.11.0

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.
Files changed (59) hide show
  1. package/dist/{api-DHkPcxuZ.d.ts → api-C3G57UWP.d.ts} +4 -4
  2. package/dist/{api-DZunc9Tf.js → api-DgN94Ia1.js} +138 -56
  3. package/dist/astro.d.ts +1 -1
  4. package/dist/astro.js +1 -1
  5. package/dist/browser.d.ts +3 -3
  6. package/dist/browser.js +6 -6
  7. package/dist/canvas.js +1 -1
  8. package/dist/cli.js +3 -2
  9. package/dist/edit-CGlOr7JF.js +1815 -0
  10. package/dist/editor/assets/index-BS6hb9gg.css +1 -0
  11. package/dist/editor/assets/index-BwZSlP7B.js +983 -0
  12. package/dist/editor/assets/lsp.worker-dqJH5PcT.js +63 -0
  13. package/dist/editor/index.html +2 -2
  14. package/dist/{figure-Dlri_efy.d.ts → figure-DX7Wgxue.d.ts} +1 -1
  15. package/dist/{index-rUYmvQft.d.ts → index-D9DnkCVK.d.ts} +1 -1
  16. package/dist/index.d.ts +3 -3
  17. package/dist/index.js +6 -6
  18. package/dist/ironmark.d.ts +1 -1
  19. package/dist/ironmark.js +1 -1
  20. package/dist/{lex-BgngnZsA.js → lex-BODknbgk.js} +37 -5
  21. package/dist/llms.txt +19 -7
  22. package/dist/lsp-browser.js +1 -1
  23. package/dist/lsp-node.js +3 -1
  24. package/dist/lsp-server.js +1 -1
  25. package/dist/lsp.js +1 -1
  26. package/dist/markdown-it.d.ts +1 -1
  27. package/dist/markdown-it.js +2 -2
  28. package/dist/{node-DoenSsSL.js → node-CT1lI4A1.js} +4 -4
  29. package/dist/{plugin-CUnb4PAy.js → plugin-0SWraI4f.js} +1 -1
  30. package/dist/plugin-C7_KZZrW.d.ts +19 -0
  31. package/dist/plugin.d.ts +3 -3
  32. package/dist/plugin.js +3 -3
  33. package/dist/plugins-3oYK28f5.js +15910 -0
  34. package/dist/plugins.d.ts +7 -2
  35. package/dist/plugins.js +3 -3
  36. package/dist/{raster-CA2EZVsH.js → raster-D1uJMbl7.js} +1 -1
  37. package/dist/remark.d.ts +1 -1
  38. package/dist/remark.js +1 -1
  39. package/dist/satteri.d.ts +1 -1
  40. package/dist/satteri.js +1 -1
  41. package/dist/{server-CMv83EL8.js → server-DqKDSDjt.js} +2 -2
  42. package/dist/{service-DUPpv6QR.js → service-C01nJa8B.js} +6 -4
  43. package/dist/{shapes-dSoHjzhn.d.ts → shapes-EDGQ3ksZ.d.ts} +32 -7
  44. package/dist/{shared-BNy-W1fR.js → shared-pKyDW6fZ.js} +15625 -7487
  45. package/dist/slim.d.ts +2 -2
  46. package/dist/slim.js +4 -4
  47. package/dist/{src-DegXsZtj.js → src-DmT2jkJ-.js} +5 -4
  48. package/dist/vite.d.ts +1 -1
  49. package/dist/vite.js +3 -3
  50. package/dist/vuepress.d.ts +1 -1
  51. package/dist/vuepress.js +1 -1
  52. package/dist/yuhwa.iife.js +77 -69
  53. package/package.json +1 -1
  54. package/dist/editor/assets/index-BtyZhez4.css +0 -1
  55. package/dist/editor/assets/index-DuDUY7_0.js +0 -842
  56. package/dist/editor/assets/lsp.worker-DrpLBfKZ.js +0 -55
  57. package/dist/grammar-BgXa5hBR.js +0 -974
  58. package/dist/plugin-DGmREJ8U.d.ts +0 -9
  59. package/dist/plugins-CUSZZfpe.js +0 -8675
@@ -1,4 +1,4 @@
1
- import { Dn as Measure, G as Layout, K as LayoutOverrides, M as Diagnostic, O as AlignSide, P as Diagram, St as PanelOption, X as PanelHandle, cn as Theme, d as TextOptions, tt as PartEdit, xt as PanelKind } from "./shapes-dSoHjzhn.js";
1
+ import { A as AlignSide, Ct as PanelKind, I as Diagram, J as LayoutOverrides, P as Diagnostic, Q as PanelHandle, d as TextOptions, kn as Measure, q as Layout, rt as PartEdit, un as Theme } from "./shapes-EDGQ3ksZ.js";
2
2
  interface ParseOptions {
3
3
  /**
4
4
  * Reads a file named by `import "..."`. Gets the resolved path (relative
@@ -286,9 +286,9 @@ declare const ENUMS: Record<string, string[]>;
286
286
  declare const COLORS: string[];
287
287
  declare const BOOLS: string[];
288
288
  declare const NUMBERS: string[];
289
- /** a panel kind's typed header props, looked up by kind name */
290
- type PanelOptions = (kind: string) => Record<string, PanelOption> | undefined;
291
- declare function lint(d: Diagram, panelOptions?: PanelOptions): void;
289
+ /** the panel kind of a name, for its header options and where each applies */
290
+ type PanelKinds = (kind: string) => Pick<PanelKind, "options" | "applies"> | undefined;
291
+ declare function lint(d: Diagram, panelKinds?: PanelKinds): void;
292
292
  interface Options extends LayoutOptions, RenderOptions {
293
293
  /**
294
294
  * Reads files named by `import "..."`: gets the resolved path, returns the
@@ -1,6 +1,6 @@
1
- import { $ as AFTER_LAYOUT, $t as lineHeight, A as MAX_NUMBER, An as getScheme, At as groupPadding, B as placementOf, Bn as resolveColor, Bt as resolveGroupStyle, C as SETTING_VALUES, Ct as alignSide, D as EDGE_PROPS, Et as edgeFont, Fn as isSafeLink, G as normalizeShape, Gn as errorText, Gt as withEdgeInk, Ht as resolvePanelStyle, I as SIDES$2, It as num, Jn as table, Jt as dedent, L as didYouMean, Lt as panelTheme, Mn as isColor, Nt as inheritedProp, Ot as effectiveProps, Pt as isLane, Q as textOffset, R as inRange, Rt as posNum, S as SETTING_NAMES, Sn as THEME_KEYS, St as alignSets, Tn as bool, Ut as size, V as propLine, Vn as themeNames, Vt as resolveNodeStyle, W as SIDE_NORMAL, Wn as collecting, Wt as textFont, X as shapePath, Xt as f$1, Y as shapeDetail, Yt as esc, Z as sizeForShape, Zt as fontAttrs, _ as unescape, _t as sub, a as lex, an as richText, at as headSize, b as KNOWN_SETTINGS, bn as SCHEMES, c as parseProps, ct as trimFor, d as serializeProps, dn as sumW, dt as center, en as nodeInk, et as MARKER_KINDS, f as serializeValue, fn as textEl, ft as hits, g as stripComment$1, gn as MONO, gt as sample, ht as pointAtHalf, i as blockBraces, in as renderSegs, it as endDirection, j as NODE_PROPS, jn as getTheme, jt as groupPath, k as GROUP_PROPS, kn as fontStack, kt as groupGap, l as propKey, ln as splitWords, lt as SIDES$1, mn as tspans, mt as pathData, n as addNodeProps, o as nodeProps, on as richW, ot as labelSpot, pn as textLines, pt as norm, q as portPoint, qn as ownerOf, qt as bakeBaselines, r as arrowInfo, rn as plain, rt as renderHead, sn as segsW, st as trim, t as KEYED_TAIL_RE, tn as parseInline, tt as POST_RENDER, u as quote$1, un as subInk, ut as add, v as unquote, vt as orthoRoute, w as STATEMENT_KEYWORDS, wn as TONES, wt as listsIds, xt as ALIGN_SIDES_HINT, y as DIRECTION_ALIASES, yt as smoothRoute, z as lint, zt as resolveEdgeStyle } from "./lex-BgngnZsA.js";
2
- import { C as TRANSFORMS, S as STATEMENTS, b as unknownPanelHint, c as drawText, f as startMeasure, g as registry, u as approxMeasure, x as PANELS, y as foreignHint } from "./plugin-CUnb4PAy.js";
3
- import { d as indentTree, n as toEbnf, r as csvFields } from "./grammar-BgXa5hBR.js";
1
+ import { $ as AFTER_LAYOUT, $t as f$1, A as MAX_NUMBER, B as placementOf, Bt as panelTheme, C as SETTING_VALUES, Cn as SCHEMES, D as EDGE_PROPS, Dn as TONES, Dt as listsIds, Et as alignSide, Fn as isColor, G as normalizeShape, Gt as resolvePanelStyle, Ht as resolveEdgeStyle, I as SIDES$2, It as inheritedProp, Jn as errorText, Jt as withEdgeInk, Kt as size, L as didYouMean, Lt as isLane, Mn as fontStack, Mt as groupGap, Nn as getScheme, Nt as groupPadding, On as bool, Pn as getTheme, Pt as groupPath, Q as textOffset, Qt as esc, R as inRange, Rn as isSafeLink, S as SETTING_NAMES, Tn as THEME_KEYS, Tt as alignSets, Un as resolveColor, Ut as resolveGroupStyle, V as propLine, Vt as posNum, W as SIDE_NORMAL, Wn as themeNames, Wt as resolveNodeStyle, X as shapePath, Xn as ownerOf, Xt as bakeBaselines, Y as shapeDetail, Z as sizeForShape, Zn as table, Zt as dedent, _ as unescape, _n as tspans, _t as sub, a as lex, at as headSize, b as KNOWN_SETTINGS, c as parseProps, cn as richText, ct as trimFor, d as serializeProps, dt as center, en as fontAttrs, et as MARKER_KINDS, f as serializeValue, fn as splitWords, ft as hits, g as stripComment$1, gn as textLines, gt as sample, hn as textEl, ht as pointAtHalf, i as blockBraces, in as parseInline, it as endDirection, j as NODE_PROPS, jt as effectiveProps, k as GROUP_PROPS, kt as edgeFont, l as propKey, ln as richW, lt as SIDES$1, mn as sumW, mt as pathData, n as addNodeProps, nn as lineHeight, o as nodeProps, on as plain, ot as labelSpot, pn as subInk, pt as norm, q as portPoint, qn as collecting, qt as textFont, r as arrowInfo, rn as nodeInk, rt as renderHead, sn as renderSegs, st as trim, t as KEYED_TAIL_RE, tt as POST_RENDER, u as quote$1, un as segsW, ut as add, v as unquote, vt as orthoRoute, w as STATEMENT_KEYWORDS, wt as ALIGN_SIDES_HINT, y as DIRECTION_ALIASES, yn as MONO, yt as smoothRoute, z as lint, zt as num } from "./lex-BODknbgk.js";
2
+ import { C as TRANSFORMS, S as STATEMENTS, b as unknownPanelHint, c as drawText, f as startMeasure, g as registry, u as approxMeasure, x as PANELS, y as foreignHint } from "./plugin-0SWraI4f.js";
3
+ import { J as indentTree, a as taskLine, d as csvFields, r as labelToken, s as clampScore, u as toEbnf } from "./edit-CGlOr7JF.js";
4
4
  // src/core/route/sides.ts
5
5
  /** Choose the side of `box` facing `target`. */
6
6
  function autoSide(box, target, other, dir) {
@@ -1214,8 +1214,12 @@ function closePanel(p, top, end) {
1214
1214
  const lead = top.lines.findIndex((l) => l.trim());
1215
1215
  panel.body = dedent(top.lines);
1216
1216
  panel.lines = [top.start, end];
1217
+ const code = p.gen ? [] : p.lines.slice(top.start + 1, end).map((l) => l.slice(0, lex(l).codeEnd).trimEnd());
1218
+ const first = Math.max(0, code.findIndex((l) => l.trim()));
1219
+ if (!p.gen && dedent([...code]).join("\n") === panel.body.join("\n")) panel.bodyAt = top.start + 1 + first;
1220
+ const at = panel.bodyAt ?? top.start + 1 + Math.max(0, lead);
1217
1221
  try {
1218
- panel.data = PANELS.get(panel.kind).parse(panel.body, panel.props, (i, msg) => p.warn(i < 0 ? top.start : top.start + 1 + Math.max(0, lead) + i, msg));
1222
+ panel.data = PANELS.get(panel.kind).parse(panel.body, panel.props, (i, msg) => p.warn(i < 0 ? top.start : at + i, msg));
1219
1223
  } catch (e) {
1220
1224
  const who = ownerOf("panel", panel.kind);
1221
1225
  p.warn(top.start, `${who ? `plugin "${who}": ` : ""}${panel.kind} panel failed to parse: ${errorText(e)}`, "error");
@@ -1759,7 +1763,7 @@ function finish(p) {
1759
1763
  if (p.hasExport) checkExports(p);
1760
1764
  settlePanels(p);
1761
1765
  checkNames(p);
1762
- lint(p.d, (kind) => PANELS.get(kind)?.options);
1766
+ lint(p.d, (kind) => PANELS.get(kind));
1763
1767
  if (!p.opts.chain) collecting(p.d.diagnostics, () => TRANSFORMS.forEach((t) => t(p.d)));
1764
1768
  checkLayout(p);
1765
1769
  checkLanes(p);
@@ -5441,17 +5445,32 @@ const pie = (lines, ctx) => {
5441
5445
  return panel("chart", panelId(state.title, "pie"), state.title, ["type: pie"], body);
5442
5446
  };
5443
5447
  const X_AXIS_RE = /^x-axis\b\s*(?:"[^"]*"|[^\s[]+)?\s*(.*)$/;
5444
- const SERIES_RE = /^(bar|line)\b\s*(?:"[^"]*")?\s*(\[.*\])\s*$/;
5445
- /** one chart panel per series, since a yuhwa chart plots one series */
5448
+ const SERIES_RE = /^(bar|line)\b\s*(?:"([^"]*)")?\s*(\[.*\])\s*$/;
5449
+ const axisLabel = (s) => quoteIf(s, /[,[\]:"]/);
5450
+ /**
5451
+ * Series of one type become one multi-series chart under an `axes:` line;
5452
+ * a mix of bars and lines becomes one chart per series, since a yuhwa
5453
+ * chart has a single type.
5454
+ */
5446
5455
  function seriesCharts(series, categories, horizontal, title) {
5447
5456
  const base = panelId(title, "xy");
5448
5457
  if (!series.length) return panel("chart", base, title, ["type: column"], []);
5458
+ const typeOf = (s) => s.type === "line" ? "line" : horizontal ? "bar" : "column";
5459
+ const category = (i) => categories[i] ?? String(i + 1);
5460
+ if (series.length > 1 && series.every((s) => s.type === series[0].type)) {
5461
+ const n = Math.max(...series.map((s) => s.values.length));
5462
+ const body = [`axes: ${Array.from({ length: n }, (_, i) => axisLabel(category(i))).join(", ")}`];
5463
+ series.forEach((s, k) => {
5464
+ const values = Array.from({ length: n }, (_, i) => s.values[i] ?? "0");
5465
+ body.push(`${chartLabel(s.name || `Series ${k + 1}`)}: ${values.join(", ")}`);
5466
+ });
5467
+ return panel("chart", base, title, [`type: ${typeOf(series[0])}`], body);
5468
+ }
5449
5469
  const out = [];
5450
5470
  series.forEach((s, k) => {
5451
- const body = s.values.map((v, i) => `${chartLabel(categories[i] ?? String(i + 1))}: ${v}`);
5452
- const type = s.type === "line" ? "line" : horizontal ? "bar" : "column";
5471
+ const body = s.values.map((v, i) => `${chartLabel(category(i))}: ${v}`);
5453
5472
  if (k) out.push("");
5454
- out.push(...panel("chart", k ? `${base}${k + 1}` : base, title, [`type: ${type}`], body));
5473
+ out.push(...panel("chart", k ? `${base}${k + 1}` : base, title, [`type: ${typeOf(s)}`], body));
5455
5474
  });
5456
5475
  return out;
5457
5476
  }
@@ -5474,12 +5493,14 @@ const xychart = (lines, ctx) => {
5474
5493
  const s = l.text.match(SERIES_RE);
5475
5494
  if (s) series.push({
5476
5495
  type: s[1],
5477
- values: splitList$1(s[2]),
5496
+ name: s[2],
5497
+ values: splitList$1(s[3]),
5478
5498
  line: l.line
5479
5499
  });
5480
5500
  return !!s;
5481
5501
  });
5482
- if (series.length > 1) ctx.warn(series[1].line, "each xychart series becomes its own chart; yuhwa charts plot one series");
5502
+ const mixed = series.find((s) => s.type !== series[0].type);
5503
+ if (mixed) ctx.warn(mixed.line, "bars and lines become separate charts; a yuhwa chart has one type");
5483
5504
  return seriesCharts(series, categories, /\bhorizontal\b/.test(ctx.header), state.title);
5484
5505
  };
5485
5506
  const QUADRANT_AXIS_RE = /^([xy])-axis\s+(.*)$/;
@@ -5648,7 +5669,7 @@ const gantt = (lines, ctx) => {
5648
5669
  return panel("gantt", panelId(state.title, "plan"), state.title, [], body);
5649
5670
  };
5650
5671
  // src/convert/mermaid/panels/boards.ts
5651
- /** Mermaid timeline, journey, mindmap and kanban: diagrams of sections and items. */
5672
+ /** Mermaid timeline, mindmap and kanban: diagrams of sections and items. */
5652
5673
  const timeline = (lines, ctx) => {
5653
5674
  const state = { title: ctx.title };
5654
5675
  const body = [];
@@ -5686,27 +5707,6 @@ const timeline = (lines, ctx) => {
5686
5707
  });
5687
5708
  return panel("timeline", panelId(state.title, "events"), state.title, [], body);
5688
5709
  };
5689
- const JOURNEY_TASK_RE = /^(.+?)\s*:\s*(\d+(?:\.\d+)?)\s*(?::\s*(.*))?$/;
5690
- /** red for unhappy scores (≤ 2), amber in between, green from 4 */
5691
- const scoreTone = (score) => score <= 2 ? "red" : score < 4 ? "amber" : "green";
5692
- const journey = (lines, ctx) => {
5693
- const state = { title: ctx.title };
5694
- const body = [];
5695
- readStatements(lines, ctx, state, (l) => {
5696
- const section = l.text.match(SECTION_RE);
5697
- if (section) {
5698
- body.push(`// ${oneLine(section[1])}`);
5699
- return true;
5700
- }
5701
- const m = l.text.match(JOURNEY_TASK_RE);
5702
- if (!m) return false;
5703
- const [, task, score, actors] = m;
5704
- if (actors) ctx.warnOnce("actors", l.line, "journey actors are skipped; scores become a column chart");
5705
- body.push(`${chartLabel(oneLine(task))} [${scoreTone(Number(score))}]: ${score}`);
5706
- return true;
5707
- });
5708
- return panel("chart", panelId(state.title, "journey"), state.title, ["type: column"], body);
5709
- };
5710
5710
  const MM_SHAPES = [
5711
5711
  [
5712
5712
  "((",
@@ -5831,6 +5831,38 @@ const kanban = (lines, ctx) => {
5831
5831
  }
5832
5832
  return panel("kanban", panelId(ctx.title, "board"), ctx.title, [], body);
5833
5833
  };
5834
+ // src/convert/mermaid/panels/journey.ts
5835
+ /**
5836
+ * Mermaid journey to a yuhwa `journey` panel. The panel reads the same
5837
+ * sections and `task: score: actors` lines, so the body carries over; tasks
5838
+ * are indented under their section, and scores outside 1–5 are clamped.
5839
+ */
5840
+ const TASK_RE = /^(.+?)\s*:\s*(-?\d+(?:\.\d+)?)\s*(?::\s*(.*))?$/;
5841
+ const journey = (lines, ctx) => {
5842
+ const state = { title: ctx.title };
5843
+ const body = [];
5844
+ let indent = "";
5845
+ readStatements(lines, ctx, state, (l) => {
5846
+ const section = l.text.match(SECTION_RE);
5847
+ if (section) {
5848
+ const name = oneLine(section[1]);
5849
+ if (name) {
5850
+ body.push(`section ${name}`);
5851
+ indent = " ";
5852
+ }
5853
+ return true;
5854
+ }
5855
+ const m = l.text.match(TASK_RE);
5856
+ if (!m) return false;
5857
+ const [, task, raw, who] = m;
5858
+ const score = clampScore(Number(raw));
5859
+ if (score !== Number(raw)) ctx.warn(l.line, `score ${raw} of "${oneLine(task)}" was clamped to ${score}`);
5860
+ const actors = (who ?? "").split(",").map((a) => oneLine(a)).filter(Boolean);
5861
+ body.push(taskLine(indent, labelToken(oneLine(task)), void 0, score, actors));
5862
+ return true;
5863
+ });
5864
+ return panel("journey", panelId(state.title, "journey"), state.title, [], body);
5865
+ };
5834
5866
  // src/convert/mermaid/state.ts
5835
5867
  /**
5836
5868
  * Mermaid stateDiagram → yuhwa nodes and groups.
@@ -9345,19 +9377,46 @@ function setPartTone(source, panelId, partId, tone, d = parse(source)) {
9345
9377
  function editPart(source, panelId, edit, d = parse(source)) {
9346
9378
  let id;
9347
9379
  const out = editBody(source, panelId, d, (kind, decl) => {
9380
+ if (edit.op === "set") {
9381
+ const part = kind.parts?.(decl.data).find((p) => p.id === edit.id);
9382
+ if (/[\r\n]/.test(edit.value ?? "") || !part || edit.key !== "color" && !(edit.key in (part.fields ?? {}))) return null;
9383
+ }
9348
9384
  const r = kind.editPart?.(decl.body, edit, decl.data);
9349
9385
  id = r?.id;
9350
9386
  return r?.body ?? null;
9351
9387
  });
9388
+ if (out === source || !bracketsReadBack(out, panelId, edit, id)) return { source };
9352
9389
  return {
9353
9390
  source: out,
9354
- id: out === source ? void 0 : id
9391
+ id
9355
9392
  };
9356
9393
  }
9394
+ /**
9395
+ * A set value with brackets must read back as written: a trailing `[red]`
9396
+ * easily turns into the part's colour, and `[a [b]]` breaks a props tail.
9397
+ * Other values may come back normalised (`1w` as `7d`), so only these are checked.
9398
+ */
9399
+ function bracketsReadBack(out, panelId, edit, id) {
9400
+ if (edit.op !== "set" || edit.key === "color" || !/[[\]]/.test(edit.value ?? "")) return true;
9401
+ const decl = parse(out).panels.find((p) => p.id === panelId);
9402
+ return (id === void 0 ? void 0 : decl && PANELS.get(decl.kind)?.parts?.(decl.data).find((p) => p.id === id))?.values?.[edit.key] === edit.value.trim();
9403
+ }
9357
9404
  /** Finish a panel drag. Prefer the declaration; a purely visual handle uses layout. */
9358
9405
  function writePanelDrag(source, d, id, handle) {
9359
9406
  const decl = d.panels.find((p) => p.id === id);
9360
9407
  const offset = d.layout.panels?.[id]?.parts?.[handle.part];
9408
+ if (offset && handle.editProps && decl?.ref && !decl.ref.generated) {
9409
+ const props = handle.editProps(offset);
9410
+ if (!props) return writeLayout(source, d.layout, d);
9411
+ let out = source;
9412
+ for (const [key, value] of Object.entries(props)) out = setProp(out, {
9413
+ kind: "panel",
9414
+ id
9415
+ }, key, value);
9416
+ const lines = splitLines(out);
9417
+ dropPartEntry(lines, parse(out).layoutBlock, id + ":" + handle.part);
9418
+ return joinLines(lines, out);
9419
+ }
9361
9420
  if (!offset || !handle.editPosition || !decl?.lines || decl.ref?.generated) return writeLayout(source, d.layout, d);
9362
9421
  const [start, end] = decl.lines;
9363
9422
  const lines = splitLines(source);
@@ -9367,39 +9426,62 @@ function writePanelDrag(source, d, id, handle) {
9367
9426
  if (first < 0) return writeLayout(source, d.layout, d);
9368
9427
  const editable = code.slice(first, first + decl.body.length);
9369
9428
  const edited = handle.editPosition(editable, offset);
9370
- if (!edited || edited.length !== editable.length) return writeLayout(source, d.layout, d);
9371
- edited.forEach((line, i) => {
9429
+ const commented = editable.some((line, i) => body[first + i].length !== line.length);
9430
+ if (!edited || edited.length !== editable.length && commented) return writeLayout(source, d.layout, d);
9431
+ if (edited.length === editable.length) edited.forEach((line, i) => {
9372
9432
  lines[start + 1 + first + i] = line + body[first + i].slice(editable[i].length);
9373
9433
  });
9374
- if (d.layoutBlock) {
9375
- const [a, b] = d.layoutBlock;
9376
- const key = id + ":" + handle.part;
9377
- const entries = lines.slice(a + 1, b);
9378
- const keep = entries.filter((line) => line.trimStart().split(/\s+/, 1)[0] !== key);
9379
- if (keep.length !== entries.length) {
9380
- if (keep.some((line) => line.trim())) lines.splice(a + 1, entries.length, ...keep);
9381
- else {
9382
- const from = a > 0 && !lines[a - 1].trim() ? a - 1 : a;
9383
- lines.splice(from, b - from + 1);
9384
- }
9385
- }
9386
- }
9434
+ else lines.splice(start + 1 + first, editable.length, ...edited);
9435
+ const lb = d.layoutBlock;
9436
+ const shift = lb && lb[0] > start ? edited.length - editable.length : 0;
9437
+ dropPartEntry(lines, lb && [lb[0] + shift, lb[1] + shift], id + ":" + handle.part);
9387
9438
  return joinLines(lines, source);
9388
9439
  }
9440
+ /** drop the `key` entry from the layout block at `block`, and the block when nothing else is left in it */
9441
+ function dropPartEntry(lines, block, key) {
9442
+ if (!block) return;
9443
+ const [a, b] = block;
9444
+ const entries = lines.slice(a + 1, b);
9445
+ const keep = entries.filter((line) => line.trimStart().split(/\s+/, 1)[0] !== key);
9446
+ if (keep.length === entries.length) return;
9447
+ if (keep.some((line) => line.trim())) lines.splice(a + 1, entries.length, ...keep);
9448
+ else {
9449
+ const from = a > 0 && !lines[a - 1].trim() ? a - 1 : a;
9450
+ lines.splice(from, b - from + 1);
9451
+ }
9452
+ }
9389
9453
  /** rewrite a panel's body lines, re-indented like the old ones */
9390
9454
  function editBody(source, panelId, d, fn) {
9391
9455
  const decl = d.panels.find((p) => p.id === panelId);
9392
9456
  const kind = decl && PANELS.get(decl.kind);
9393
- if (!decl?.lines || !kind || decl.failed || decl.ref?.generated) return source;
9394
- const [start, end] = decl.lines;
9395
- if (end - start - 1 !== decl.body.length) return source;
9457
+ const at = decl?.bodyAt;
9458
+ if (!decl?.lines || at === void 0 || !kind || decl.failed || decl.ref?.generated) return source;
9396
9459
  const body = fn(kind, decl);
9397
- if (!body) return source;
9460
+ if (!body || body.some((l) => lex(l).codeEnd < l.trimEnd().length)) return source;
9398
9461
  const lines = splitLines(source);
9399
- const indent = innerIndent(lines, start, end);
9400
- lines.splice(start + 1, end - start - 1, ...body.map((l) => l.trim() ? indent + l : ""));
9462
+ const indent = innerIndent(lines, decl.lines[0], decl.lines[1]);
9463
+ const n = decl.body.length;
9464
+ lines.splice(at, n, ...keepComments(body, decl.body, lines.slice(at, at + n), indent));
9401
9465
  return joinLines(lines, source);
9402
9466
  }
9467
+ /**
9468
+ * Source lines for an edited panel body. The body a plugin edits has its
9469
+ * comments cut (a comment line reads as empty), so each line it kept is
9470
+ * written back as it was in the source, comment and all; a changed line keeps
9471
+ * the comment of the line it replaced, when the body did not grow or shrink.
9472
+ */
9473
+ function keepComments(next, old, src, indent) {
9474
+ const used = /* @__PURE__ */ new Set();
9475
+ return next.map((l, i) => {
9476
+ let k = old.findIndex((o, j) => !used.has(j) && o === l);
9477
+ if (k < 0 && next.length === old.length && !used.has(i) && !next.includes(old[i])) k = i;
9478
+ if (k < 0) return l.trim() ? indent + l : "";
9479
+ used.add(k);
9480
+ if (old[k] === l) return src[k];
9481
+ const tail = src[k].slice(lex(src[k]).codeEnd).trim();
9482
+ return (l.trim() ? indent + l.trimEnd() : "") + (tail ? (l.trim() ? " " : indent) + tail : "");
9483
+ });
9484
+ }
9403
9485
  const indentOf = (line) => line.match(/^\s*/)[0];
9404
9486
  /** the indentation of the lines between `open` and `close`: the least of them, or one step in from `open` */
9405
9487
  function innerIndent(lines, open, close) {
package/dist/astro.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { t as YuhwaDocsOptions } from "./figure-Dlri_efy.js";
1
+ import { t as YuhwaDocsOptions } from "./figure-DX7Wgxue.js";
2
2
  interface Watcher {
3
3
  on: (event: "change" | "add", fn: (file: string) => void) => unknown;
4
4
  add: (files: string[]) => unknown;
package/dist/astro.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import remarkYuhwa from "./remark.js";
2
2
  import satteriYuhwa from "./satteri.js";
3
- import { n as onTrack, o as clientImports, r as pagesUsing } from "./node-DoenSsSL.js";
3
+ import { n as onTrack, o as clientImports, r as pagesUsing } from "./node-CT1lI4A1.js";
4
4
  // src/integrations/astro.ts
5
5
  /**
6
6
  * Astro integration, also for Starlight: renders ```yuhwa blocks in .md and
package/dist/browser.d.ts CHANGED
@@ -11,10 +11,10 @@
11
11
  * <yuhwa-diagram render="canvas">a -> b</yuhwa-diagram> // or png; default svg
12
12
  * el.source = 'a -> b' // re-renders
13
13
  */
14
- import { $ as PartAction, $t as PLAIN_THEMES, A as Component, At as recolor, B as LabelRef, C as setLineProp, Cn as ramp, Ct as RowCtx, D as Align, Dt as YuhwaPlugin, En as themeNames, Et as StatementKind, F as Direction, Ft as ShapeKind, G as Layout, Gt as renderSegs, H as LaidGroup, I as EdgeDecl, It as renderHead, J as NodeOverride, K as LayoutOverrides, Kt as segsW, L as EdgeOverride, Lt as InkColors, M as Diagnostic, Mt as unuse, N as DiagnosticCode, Nt as use, O as AlignSide, On as approxMeasure, Ot as optionKind, P as Diagram, Pt as MarkerKind, Q as PanelPart, R as GroupDecl, Rt as Seg, S as serializeProps, Sn as plainThemeNames, St as PanelOption, T as splitTrailingProps, Tt as RowPaint, U as LaidNode, Ut as parseInline, V as LaidEdge, W as LaidPanel, X as PanelHandle, Y as PanelDecl, Yt as tspans, Z as PanelOverride, Zt as LineStyle, _ as TokKind, an as THEME_KEYS, at as ResolvedNodeStyle, b as onlyColor, bn as isSafeLink, bt as PanelCtx, cn as Theme, ct as SourceRef, d as TextOptions, dn as createTheme, en as RAMPS, et as PartChange, ft as groupPath, g as Tok, gn as getTheme, h as LexedLine, hn as getScheme, in as THEMES, it as ResolvedEdgeStyle, j as Curve, jt as registry, k as Box, kn as canvasMeasure, kt as perPass, ln as ThemeInput, lt as dashFor, mn as fontStack, mt as lineStyle, nn as SCHEMES, nt as Point, on as THEME_NAMES, ot as ShapeName, pn as fontFamilies, pt as groupProp, q as NodeDecl, r as portOn, rn as Scheme, rt as Props, sn as TONES, st as Side, t as SHAPES, tt as PartEdit, v as blockBraces, vn as isGenericFont, vt as Decoration, w as setTrailingProp, wn as registerTheme, wt as RowKind, x as parseProps, xn as isToneOrHex, xt as PanelKind, y as lex, yn as isSafeCss, yt as FrameKind, z as HeadKind, zt as esc } from "./shapes-dSoHjzhn.js";
15
- import { $ as isYuhwaPath, A as embedFonts, B as setPartTone, C as MdOptions, D as replaceBlockSource, E as processMarkdown, F as addNode, G as ALIGN_SIDES, H as setSetting, I as editPart, J as JsonResult, K as GRID, L as formatLayout, M as svgToCanvas, N as Target, O as FontSource, P as addEdge, Q as parse, R as removeElement, S as MdBlock, T as findBlocks, U as writeLayout, V as setProp, W as writePanelDrag, X as renderSvg, Y as fromJSON, Z as layout, _ as lint, at as ParseOptions, b as isMermaid, c as BOOLS, d as ENUMS, et as joinPath, f as GROUP_PROPS, g as PANEL_PROP_HELP, h as PANEL_PROPS, i as hash, it as SETTING_VALUES, j as loadFonts, k as RasterOptions, l as COLORS, m as NUMBERS, n as Options, nt as KNOWN_SETTINGS, o as renderText, p as NODE_PROPS, q as DiagramJSON, r as Result, rt as SETTING_HELP, s as toSource, t as InputFormat, tt as PANELS, u as EDGE_PROPS, v as ConvertResult, w as MdResult, x as MD_LANGUAGES, y as fromMermaid, z as setLabel } from "./api-DHkPcxuZ.js";
14
+ import { $ as PanelOverride, $t as LineStyle, A as AlignSide, An as approxMeasure, At as optionKind, B as GroupDecl, Bt as Seg, C as serializeProps, Cn as isToneOrHex, Ct as PanelKind, Dt as RowPaint, E as splitTrailingProps, En as registerTheme, Et as RowKind, F as DiagnosticCode, Ft as use, G as LaidNode, Gt as parseInline, H as LabelRef, I as Diagram, It as MarkerKind, J as LayoutOverrides, Jt as segsW, K as LaidPanel, L as Direction, Lt as ShapeKind, M as Component, Mt as recolor, N as Curve, Nt as registry, On as themeNames, Ot as StatementKind, P as Diagnostic, Pt as unuse, Q as PanelHandle, R as EdgeDecl, Rt as renderHead, Sn as isSafeLink, St as PanelCtx, T as setTrailingProp, Tn as ramp, Tt as RowCtx, U as LaidEdge, V as HeadKind, Vt as esc, W as LaidGroup, X as NodeOverride, Y as NodeDecl, Z as PanelDecl, Zt as tspans, _ as TokKind, _n as getScheme, an as Scheme, at as Props, b as onlyColor, bn as isGenericFont, bt as Decoration, cn as THEME_NAMES, ct as ShapeName, d as TextOptions, dn as ThemeInput, dt as dashFor, et as PanelPart, g as Tok, gn as fontStack, gt as lineStyle, h as LexedLine, hn as fontFamilies, ht as groupProp, in as SCHEMES, it as Point, j as Box, jn as canvasMeasure, jt as perPass, k as Align, kt as YuhwaPlugin, ln as TONES, lt as Side, mt as groupPath, nn as RAMPS, nt as PartChange, on as THEMES, ot as ResolvedEdgeStyle, pn as createTheme, q as Layout, qt as renderSegs, r as portOn, rt as PartEdit, sn as THEME_KEYS, st as ResolvedNodeStyle, t as SHAPES, tn as PLAIN_THEMES, tt as PartAction, un as Theme, ut as SourceRef, v as blockBraces, vn as getTheme, w as setLineProp, wn as plainThemeNames, wt as PanelOption, x as parseProps, xn as isSafeCss, xt as FrameKind, y as lex, z as EdgeOverride, zt as InkColors } from "./shapes-EDGQ3ksZ.js";
15
+ import { $ as isYuhwaPath, A as embedFonts, B as setPartTone, C as MdOptions, D as replaceBlockSource, E as processMarkdown, F as addNode, G as ALIGN_SIDES, H as setSetting, I as editPart, J as JsonResult, K as GRID, L as formatLayout, M as svgToCanvas, N as Target, O as FontSource, P as addEdge, Q as parse, R as removeElement, S as MdBlock, T as findBlocks, U as writeLayout, V as setProp, W as writePanelDrag, X as renderSvg, Y as fromJSON, Z as layout, _ as lint, at as ParseOptions, b as isMermaid, c as BOOLS, d as ENUMS, et as joinPath, f as GROUP_PROPS, g as PANEL_PROP_HELP, h as PANEL_PROPS, i as hash, it as SETTING_VALUES, j as loadFonts, k as RasterOptions, l as COLORS, m as NUMBERS, n as Options, nt as KNOWN_SETTINGS, o as renderText, p as NODE_PROPS, q as DiagramJSON, r as Result, rt as SETTING_HELP, s as toSource, t as InputFormat, tt as PANELS, u as EDGE_PROPS, v as ConvertResult, w as MdResult, x as MD_LANGUAGES, y as fromMermaid, z as setLabel } from "./api-C3G57UWP.js";
16
16
  import { t as GUIDE } from "./index-Bab6qq3T.js";
17
- import { _ as markers, a as gantt, c as chart, d as legend, f as footer, g as themes, h as charts, i as quadrant, l as timeline, m as tables, n as treeview, o as mindmap, p as frames, r as kanban, s as git, t as builtins, u as sequence, v as shapes } from "./index-rUYmvQft.js";
17
+ import { _ as markers, a as gantt, c as chart, d as legend, f as footer, g as themes, h as charts, i as quadrant, l as timeline, m as tables, n as treeview, o as mindmap, p as frames, r as kanban, s as git, t as builtins, u as sequence, v as shapes } from "./index-D9DnkCVK.js";
18
18
  import { i as zoomable, n as Zoomer, r as zoomHeight, t as ZoomOptions } from "./zoom-CCSUbX1X.js";
19
19
  export declare function render(source: string, opts?: Options): Result;
20
20
  /** `render`, then draw the diagram into a canvas. */
package/dist/browser.js CHANGED
@@ -1,10 +1,10 @@
1
- import { t as GUIDE } from "./src-DegXsZtj.js";
2
- import { _ as unuse, d as canvasMeasure, g as registry, h as recolor, m as perPass, p as optionKind, u as approxMeasure, v as use, x as PANELS } from "./plugin-CUnb4PAy.js";
1
+ import { t as GUIDE } from "./src-DmT2jkJ-.js";
2
+ import { _ as unuse, d as canvasMeasure, g as registry, h as recolor, m as perPass, p as optionKind, u as approxMeasure, v as use, x as PANELS } from "./plugin-0SWraI4f.js";
3
3
  import { n as zoomable, t as zoomHeight } from "./zoom-D3Lahr1T.js";
4
- import { C as themes, S as charts, T as shapes, _ as sequence, b as frames, d as quadrant, f as gantt, g as timeline, h as chart, l as treeview, m as git, p as mindmap, t as builtins, u as kanban, v as legend, w as markers, x as tables, y as footer } from "./plugins-CUSZZfpe.js";
5
- import { a as svgFamilies, c as swapForRaster, n as embedFonts, r as loadFonts, s as svgToCanvas } from "./raster-CA2EZVsH.js";
6
- import { An as getScheme, C as SETTING_VALUES, Cn as THEME_NAMES, D as EDGE_PROPS, E as COLORS, En as createTheme, Fn as isSafeLink, Ft as lineStyle, H as SHAPES, In as isToneOrHex, K as portOn, Ln as plainThemeNames, M as NUMBERS, Mt as groupProp, N as PANEL_PROPS, Nn as isGenericFont, O as ENUMS, On as fontFamilies, P as PANEL_PROP_HELP, Pn as isSafeCss, Rn as ramp, Sn as THEME_KEYS, T as BOOLS, Tt as dashFor, Vn as themeNames, Yt as esc, _n as PLAIN_THEMES, a as lex, b as KNOWN_SETTINGS, bn as SCHEMES, bt as ALIGN_SIDES, c as parseProps, d as serializeProps, h as splitTrailingProps, i as blockBraces, in as renderSegs, j as NODE_PROPS, jn as getTheme, jt as groupPath, k as GROUP_PROPS, kn as fontStack, m as setTrailingProp, mn as tspans, p as setLineProp, rt as renderHead, s as onlyColor, sn as segsW, tn as parseInline, v as unquote, vn as RAMPS, wn as TONES, x as SETTING_HELP, xn as THEMES, z as lint, zn as registerTheme } from "./lex-BgngnZsA.js";
7
- import { A as joinPath, C as isMermaid, D as GRID, E as layout, O as parse, S as fromMermaid, T as renderSvg, _ as setPartTone, a as MD_LANGUAGES, b as writeLayout, d as addEdge, f as addNode, g as setLabel, h as removeElement, i as toSource, k as isYuhwaPath, l as processMarkdown, m as formatLayout, n as render$1, o as findBlocks, p as editPart, r as renderText, t as hash, u as replaceBlockSource, v as setProp, w as fromJSON, x as writePanelDrag, y as setSetting } from "./api-DZunc9Tf.js";
4
+ import { A as shapes, C as legend, D as charts, E as tables, O as themes, S as sequence, T as frames, _ as gantt, b as chart, g as quadrant, h as kanban, k as markers, m as treeview, t as builtins, v as mindmap, w as footer, x as timeline, y as git } from "./plugins-3oYK28f5.js";
5
+ import { a as svgFamilies, c as swapForRaster, n as embedFonts, r as loadFonts, s as svgToCanvas } from "./raster-D1uJMbl7.js";
6
+ import { Bn as plainThemeNames, C as SETTING_VALUES, Cn as SCHEMES, Ct as ALIGN_SIDES, D as EDGE_PROPS, Dn as TONES, E as COLORS, En as THEME_NAMES, Ft as groupProp, H as SHAPES, Hn as registerTheme, In as isGenericFont, K as portOn, Ln as isSafeCss, M as NUMBERS, Mn as fontStack, N as PANEL_PROPS, Nn as getScheme, O as ENUMS, Ot as dashFor, P as PANEL_PROP_HELP, Pn as getTheme, Pt as groupPath, Qt as esc, Rn as isSafeLink, Rt as lineStyle, T as BOOLS, Tn as THEME_KEYS, Vn as ramp, Wn as themeNames, _n as tspans, a as lex, b as KNOWN_SETTINGS, bn as PLAIN_THEMES, c as parseProps, d as serializeProps, h as splitTrailingProps, i as blockBraces, in as parseInline, j as NODE_PROPS, jn as fontFamilies, k as GROUP_PROPS, kn as createTheme, m as setTrailingProp, p as setLineProp, rt as renderHead, s as onlyColor, sn as renderSegs, un as segsW, v as unquote, wn as THEMES, x as SETTING_HELP, xn as RAMPS, z as lint, zn as isToneOrHex } from "./lex-BODknbgk.js";
7
+ import { A as joinPath, C as isMermaid, D as GRID, E as layout, O as parse, S as fromMermaid, T as renderSvg, _ as setPartTone, a as MD_LANGUAGES, b as writeLayout, d as addEdge, f as addNode, g as setLabel, h as removeElement, i as toSource, k as isYuhwaPath, l as processMarkdown, m as formatLayout, n as render$1, o as findBlocks, p as editPart, r as renderText, t as hash, u as replaceBlockSource, v as setProp, w as fromJSON, x as writePanelDrag, y as setSetting } from "./api-DgN94Ia1.js";
8
8
  // src/browser.ts
9
9
  /**
10
10
  * Drop-in browser runtime: <script src="yuhwa.js"><\/script>
package/dist/canvas.js CHANGED
@@ -17,7 +17,7 @@ function installCanvas() {
17
17
  const swap = async (img) => {
18
18
  const svg = svgFromDataUri(img.getAttribute("src") ?? "");
19
19
  if (svg === void 0) return;
20
- const { swapForRaster } = await import("./raster-CA2EZVsH.js").then((n) => n.i);
20
+ const { swapForRaster } = await import("./raster-D1uJMbl7.js").then((n) => n.i);
21
21
  const canvas = await swapForRaster(img, svg, "canvas", img.alt);
22
22
  if (canvas) canvas.className = img.className;
23
23
  };
package/dist/cli.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import { existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
3
- import { $ as THEME_KEYS, A as SETTING_VALUES, E as unquote, F as ENUMS, G as ALIGN_SIDES_HINT, I as GROUP_PROPS, J as esc, L as NODE_PROPS, N as COLORS, O as KNOWN_SETTINGS, P as EDGE_PROPS, Q as SCHEMES, S as registry, U as SHAPES, Z as PLAIN_THEMES, _ as replaceBlockSource, a as formatPage, b as canvasMeasure, c as diskResolve, d as toSource, et as THEME_NAMES, f as MD_LANGUAGES, g as processMarkdown, h as pageBlocks, i as format, l as render$1, m as isMarkdown, nt as isSafeCss, ot as isYuhwaPath, p as findBlocks, s as tidy, st as joinPath, t as VERSION, tt as TONES, u as renderText, x as optionKind, z as PANEL_PROPS } from "./shared-BNy-W1fR.js";
3
+ import { $ as THEME_KEYS, A as SETTING_VALUES, E as unquote, F as ENUMS, G as ALIGN_SIDES_HINT, I as GROUP_PROPS, J as esc, L as NODE_PROPS, N as COLORS, O as KNOWN_SETTINGS, P as EDGE_PROPS, Q as SCHEMES, S as registry, U as SHAPES, Z as PLAIN_THEMES, _ as replaceBlockSource, a as formatPage, b as canvasMeasure, c as diskResolve, d as toSource, et as THEME_NAMES, f as MD_LANGUAGES, g as processMarkdown, h as pageBlocks, i as format, l as render$1, m as isMarkdown, nt as isSafeCss, ot as isYuhwaPath, p as findBlocks, s as tidy, st as joinPath, t as VERSION, tt as TONES, u as renderText, x as optionKind, z as PANEL_PROPS } from "./shared-pKyDW6fZ.js";
4
4
  import { createServer } from "node:http";
5
5
  import { basename, dirname, extname, join, resolve, sep } from "node:path";
6
6
  import { fileURLToPath } from "node:url";
@@ -311,7 +311,8 @@ const schemes = () => list$1(Object.entries(SCHEMES).map(([n, s]) => `\`${n}\` f
311
311
  const PLACEHOLDER = {
312
312
  color: "<colour>",
313
313
  number: "N",
314
- text: "…"
314
+ text: "…",
315
+ date: "YYYY-MM-DD|now"
315
316
  };
316
317
  const settings = list$1([...KNOWN_SETTINGS].map((k) => SETTING_VALUES[k] ? `${k} (${SETTING_VALUES[k].join("|")})` : k));
317
318
  const panelLines = panels.map((p) => {