yuhwa 1.8.2 → 1.9.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 (56) hide show
  1. package/dist/{index-0qJC6glR.d.ts → api-DHkPcxuZ.d.ts} +18 -22
  2. package/dist/{src-BWFm7GlK.js → api-DZunc9Tf.js} +6142 -8752
  3. package/dist/astro.d.ts +1 -1
  4. package/dist/astro.js +1 -1
  5. package/dist/browser.d.ts +26 -3
  6. package/dist/browser.js +103 -32
  7. package/dist/canvas.js +1 -1
  8. package/dist/cli.js +65 -39
  9. package/dist/editor/assets/index-DuDUY7_0.js +842 -0
  10. package/dist/editor/assets/lsp.worker-DrpLBfKZ.js +55 -0
  11. package/dist/editor/index.html +1 -1
  12. package/dist/{figure-Cn5Ls_0U.d.ts → figure-Dlri_efy.d.ts} +1 -1
  13. package/dist/grammar-BgXa5hBR.js +974 -0
  14. package/dist/index-Bab6qq3T.d.ts +2 -0
  15. package/dist/index-rUYmvQft.d.ts +20 -0
  16. package/dist/index.d.ts +10 -3
  17. package/dist/index.js +7 -5
  18. package/dist/ironmark.d.ts +1 -1
  19. package/dist/ironmark.js +1 -1
  20. package/dist/{lex-DIq2EFvl.js → lex-BgngnZsA.js} +49 -17
  21. package/dist/llms.txt +23 -6
  22. package/dist/lsp-browser.js +1 -1
  23. package/dist/lsp-node.js +6 -4
  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-GljwUyhc.js → node-DoenSsSL.js} +4 -3
  29. package/dist/plugin-CUnb4PAy.js +970 -0
  30. package/dist/plugin-DGmREJ8U.d.ts +9 -0
  31. package/dist/plugin.d.ts +3 -2
  32. package/dist/plugin.js +3 -3
  33. package/dist/plugins-CUSZZfpe.js +8675 -0
  34. package/dist/plugins.d.ts +12 -0
  35. package/dist/plugins.js +3 -0
  36. package/dist/{raster-Bqtxssxh.js → raster-CA2EZVsH.js} +8 -8
  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-8-F7RVrN.js → server-CMv83EL8.js} +2 -2
  42. package/dist/{service-S1OY7wrO.js → service-DUPpv6QR.js} +31 -8
  43. package/dist/{plugin-COlq-EO9.d.ts → shapes-dSoHjzhn.d.ts} +109 -13
  44. package/dist/{shared-Bhnvepka.js → shared-BNy-W1fR.js} +14227 -6170
  45. package/dist/slim.d.ts +12 -0
  46. package/dist/slim.js +5 -0
  47. package/dist/src-DegXsZtj.js +337 -0
  48. package/dist/vite.d.ts +1 -1
  49. package/dist/vite.js +3 -2
  50. package/dist/vuepress.d.ts +1 -1
  51. package/dist/vuepress.js +1 -1
  52. package/dist/yuhwa.iife.js +79 -55
  53. package/package.json +11 -1
  54. package/dist/editor/assets/index-BzQE05yU.js +0 -689
  55. package/dist/editor/assets/lsp.worker-B8uA5kfW.js +0 -36
  56. package/dist/plugin-3vxnUvv9.js +0 -307
package/dist/astro.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { t as YuhwaDocsOptions } from "./figure-Cn5Ls_0U.js";
1
+ import { t as YuhwaDocsOptions } from "./figure-Dlri_efy.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-GljwUyhc.js";
3
+ import { n as onTrack, o as clientImports, r as pagesUsing } from "./node-DoenSsSL.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,8 +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 Side, A as GroupDecl, At as Seg, B as NodeOverride, C as Component, Ct as registry, D as Direction, Dt as ShapeKind, E as Diagram, Et as MarkerKind, F as LaidNode, Ft as parseInline, G as PartAction, Gt as RAMPS, H as PanelHandle, I as LaidPanel, J as Point, Jt as THEME_KEYS, K as PartChange, L as Layout, Lt as renderSegs, M as LabelRef, N as LaidEdge, O as EdgeDecl, Ot as renderHead, P as LaidGroup, Q as ShapeName, Qt as ThemeInput, R as LayoutOverrides, Rt as segsW, S as Box, St as recolor, T as Diagnostic, Tt as use, U as PanelOverride, Ut as LineStyle, V as PanelDecl, Vt as tspans, W as PanelPart, X as ResolvedEdgeStyle, Xt as TONES, Y as Props, Yt as THEME_NAMES, Z as ResolvedNodeStyle, Zt as Theme, _ as setTrailingProp, _t as RowPaint, a as portOn, at as groupProp, b as Align, bt as optionKind, c as LexedLine, cn as isSafeLink, d as blockBraces, dn as registerTheme, dt as FrameKind, en as createTheme, et as SourceRef, f as lex, ft as PanelCtx, g as setLineProp, gn as canvasMeasure, gt as RowKind, h as serializeProps, hn as approxMeasure, ht as RowCtx, in as getTheme, it as groupPath, j as HeadKind, jt as esc, k as EdgeOverride, kt as InkColors, l as Tok, ln as isToneOrHex, m as parseProps, mt as PanelOption, nn as fontFamilies, on as isGenericFont, ot as lineStyle, p as onlyColor, pn as themeNames, pt as PanelKind, q as PartEdit, qt as THEMES, r as SHAPES, rn as fontStack, sn as isSafeCss, tt as dashFor, u as TokKind, un as ramp, ut as Decoration, v as splitTrailingProps, vt as StatementKind, w as Curve, wt as unuse, x as AlignSide, xt as perPass, yt as YuhwaPlugin, z as NodeDecl } from "./plugin-COlq-EO9.js";
15
- import { $ as addNode, A as GROUP_PROPS, B as MdBlock, C as markers, Ct as ParseOptions, D as COLORS, E as BOOLS, F as lint, G as replaceBlockSource, H as MdResult, I as ConvertResult, J as embedFonts, K as FontSource, L as fromMermaid, M as NUMBERS, N as PANEL_PROPS, O as EDGE_PROPS, P as PANEL_PROP_HELP, Q as addEdge, R as isMermaid, S as themes, St as SETTING_VALUES, T as GUIDE, U as findBlocks, V as MdOptions, W as processMarkdown, X as svgToCanvas, Y as loadFonts, Z as Target, _ as legend, _t as isYuhwaPath, at as setProp, b as tables, bt as KNOWN_SETTINGS, c as treeview, ct as writePanelDrag, d as gantt, dt as DiagramJSON, et as editPart, f as mindmap, ft as JsonResult, g as sequence, gt as parse, h as timeline, ht as layout, i as hash, it as setPartTone, j as NODE_PROPS, k as ENUMS, l as kanban, lt as ALIGN_SIDES, m as chart, mt as renderSvg, n as Options, nt as removeElement, o as toSource, ot as setSetting, p as git, pt as fromJSON, q as RasterOptions, r as Result, rt as setLabel, s as builtins, st as writeLayout, t as InputFormat, tt as formatLayout, u as quadrant, ut as GRID, v as footer, vt as joinPath, w as shapes, x as charts, xt as SETTING_HELP, y as frames, yt as PANELS, z as MD_LANGUAGES } from "./index-0qJC6glR.js";
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";
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";
16
18
  import { i as zoomable, n as Zoomer, r as zoomHeight, t as ZoomOptions } from "./zoom-CCSUbX1X.js";
17
19
  export declare function render(source: string, opts?: Options): Result;
18
20
  /** `render`, then draw the diagram into a canvas. */
@@ -27,6 +29,27 @@ export declare function renderCanvas(source: string, opts?: Options & RasterOpti
27
29
  */
28
30
  export declare function fetchImports(source: string, file: string, load?: (path: string) => Promise<string>): Promise<Record<string, string>>;
29
31
  export declare function run(root?: ParentNode, opts?: Options): void;
32
+ export interface MountOptions extends Options {
33
+ /** `svg` (default), `png` or `canvas`, as the `render` attribute of `<yuhwa-diagram>` */
34
+ render?: "svg" | "png" | "canvas";
35
+ /** pan and zoom; a number or CSS length sets the height */
36
+ zoom?: boolean | number | string;
37
+ }
38
+ export interface Mounted {
39
+ /** the latest render: diagnostics, layout, the SVG */
40
+ readonly result: Result;
41
+ /** re-renders with new source, and options merged over the ones given before */
42
+ update(source: string, opts?: MountOptions): Result;
43
+ /** empties the element and stops following fonts and the colour scheme */
44
+ destroy(): void;
45
+ }
46
+ /**
47
+ * Renders `source` into `el` and keeps it there: `update` re-renders in place,
48
+ * for live previews and editors. With no theme set, or `auto`, the diagram
49
+ * follows the reader's light or dark mode as it changes. Never throws on bad
50
+ * source: the diagnostics are on `result`.
51
+ */
52
+ export declare function mount(el: HTMLElement, source: string, opts?: MountOptions): Mounted;
30
53
  declare const Base: typeof HTMLElement;
31
54
  /**
32
55
  * <yuhwa-diagram [theme] [src] [zoom[=height]] [wheel]>source</yuhwa-diagram>;
@@ -41,4 +64,4 @@ export declare class YuhwaDiagram extends Base {
41
64
  connectedCallback(): void;
42
65
  attributeChangedCallback(): void;
43
66
  }
44
- export { ALIGN_SIDES, type Align, type AlignSide, BOOLS, type Box, COLORS, type Component, type ConvertResult, type Curve, type Decoration, type Diagnostic, type Diagram, type DiagramJSON, type Direction, EDGE_PROPS, ENUMS, type EdgeDecl, type EdgeOverride, type FontSource, type FrameKind, GRID, GROUP_PROPS, GUIDE, type GroupDecl, type HeadKind, type InkColors, InputFormat, type JsonResult, KNOWN_SETTINGS, type LabelRef, type LaidEdge, type LaidGroup, type LaidNode, type LaidPanel, type Layout, type LayoutOverrides, type LexedLine, type LineStyle, MD_LANGUAGES, type MarkerKind, type MdBlock, type MdOptions, type MdResult, NODE_PROPS, NUMBERS, type NodeDecl, type NodeOverride, Options, PANELS, PANEL_PROPS, PANEL_PROP_HELP, type PanelCtx, type PanelDecl, type PanelHandle, type PanelKind, type PanelOption, type PanelOverride, type PanelPart, type ParseOptions, type PartAction, type PartChange, type PartEdit, type Point, type Props, RAMPS, type RasterOptions, type ResolvedEdgeStyle, type ResolvedNodeStyle, Result, type RowCtx, type RowKind, type RowPaint, SETTING_HELP, SETTING_VALUES, SHAPES, type Seg, type ShapeKind, type ShapeName, type Side, type SourceRef, type StatementKind, THEMES, THEME_KEYS, THEME_NAMES, TONES, type Target, type Theme, type ThemeInput, type Tok, type TokKind, type YuhwaPlugin, type ZoomOptions, type Zoomer, addEdge, addNode, approxMeasure, blockBraces, builtins, canvasMeasure, chart, charts, createTheme, dashFor, editPart, embedFonts, esc, findBlocks, fontFamilies, fontStack, footer, formatLayout, frames, fromJSON, fromMermaid, gantt, getTheme, git, groupPath, groupProp, hash, isGenericFont, isMermaid, isSafeCss, isSafeLink, isToneOrHex, isYuhwaPath, joinPath, kanban, layout, legend, lex, lineStyle, lint, loadFonts, markers, mindmap, onlyColor, optionKind, parse, parseInline, parseProps, perPass, portOn, processMarkdown, quadrant, ramp, recolor, registerTheme, registry, removeElement, renderHead, renderSegs, renderSvg, replaceBlockSource, segsW, sequence, serializeProps, setLabel, setLineProp, setPartTone, setProp, setSetting, setTrailingProp, shapes, splitTrailingProps, svgToCanvas, tables, themeNames, themes, timeline, toSource, treeview, tspans, unuse, use, writeLayout, writePanelDrag, zoomHeight, zoomable };
67
+ export { ALIGN_SIDES, type Align, type AlignSide, BOOLS, type Box, COLORS, type Component, type ConvertResult, type Curve, type Decoration, type Diagnostic, type DiagnosticCode, type Diagram, type DiagramJSON, type Direction, EDGE_PROPS, ENUMS, type EdgeDecl, type EdgeOverride, type FontSource, type FrameKind, GRID, GROUP_PROPS, GUIDE, type GroupDecl, type HeadKind, type InkColors, InputFormat, type JsonResult, KNOWN_SETTINGS, type LabelRef, type LaidEdge, type LaidGroup, type LaidNode, type LaidPanel, type Layout, type LayoutOverrides, type LexedLine, type LineStyle, MD_LANGUAGES, type MarkerKind, type MdBlock, type MdOptions, type MdResult, NODE_PROPS, NUMBERS, type NodeDecl, type NodeOverride, Options, PANELS, PANEL_PROPS, PANEL_PROP_HELP, PLAIN_THEMES, type PanelCtx, type PanelDecl, type PanelHandle, type PanelKind, type PanelOption, type PanelOverride, type PanelPart, type ParseOptions, type PartAction, type PartChange, type PartEdit, type Point, type Props, RAMPS, type RasterOptions, type ResolvedEdgeStyle, type ResolvedNodeStyle, Result, type RowCtx, type RowKind, type RowPaint, SCHEMES, SETTING_HELP, SETTING_VALUES, SHAPES, type Scheme, type Seg, type ShapeKind, type ShapeName, type Side, type SourceRef, type StatementKind, THEMES, THEME_KEYS, THEME_NAMES, TONES, type Target, type TextOptions, type Theme, type ThemeInput, type Tok, type TokKind, type YuhwaPlugin, type ZoomOptions, type Zoomer, addEdge, addNode, approxMeasure, blockBraces, builtins, canvasMeasure, chart, charts, createTheme, dashFor, editPart, embedFonts, esc, findBlocks, fontFamilies, fontStack, footer, formatLayout, frames, fromJSON, fromMermaid, gantt, getScheme, getTheme, git, groupPath, groupProp, hash, isGenericFont, isMermaid, isSafeCss, isSafeLink, isToneOrHex, isYuhwaPath, joinPath, kanban, layout, legend, lex, lineStyle, lint, loadFonts, markers, mindmap, onlyColor, optionKind, parse, parseInline, parseProps, perPass, plainThemeNames, portOn, processMarkdown, quadrant, ramp, recolor, registerTheme, registry, removeElement, renderHead, renderSegs, renderSvg, renderText, replaceBlockSource, segsW, sequence, serializeProps, setLabel, setLineProp, setPartTone, setProp, setSetting, setTrailingProp, shapes, splitTrailingProps, svgToCanvas, tables, themeNames, themes, timeline, toSource, treeview, tspans, unuse, use, writeLayout, writePanelDrag, zoomHeight, zoomable };
package/dist/browser.js CHANGED
@@ -1,8 +1,10 @@
1
- import { A as joinPath, B as timeline, C as isMermaid, D as GRID, E as layout, F as quadrant, G as tables, H as legend, I as gantt, J as markers, K as charts, L as mindmap, M as builtins, N as treeview, O as parse, P as kanban, R as git, S as fromMermaid, T as renderSvg, U as footer, V as sequence, W as frames, Y as shapes, _ as setPartTone, a as MD_LANGUAGES, b as writeLayout, d as addEdge, f as addNode, g as setLabel, h as removeElement, i as GUIDE, k as isYuhwaPath, l as processMarkdown, m as formatLayout, n as render$1, o as findBlocks, p as editPart, q as themes, r as toSource, t as hash, u as replaceBlockSource, v as setProp, w as fromJSON, x as writePanelDrag, y as setSetting, z as chart } from "./src-BWFm7GlK.js";
2
- import { a as perPass, c as unuse, i as optionKind, l as use, n as approxMeasure, o as recolor, r as canvasMeasure, s as registry, u as PANELS } from "./plugin-3vxnUvv9.js";
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";
3
3
  import { n as zoomable, t as zoomHeight } from "./zoom-D3Lahr1T.js";
4
- import { a as svgFamilies, c as swapForRaster, n as embedFonts, r as loadFonts, s as svgToCanvas } from "./raster-Bqtxssxh.js";
5
- import { An as isSafeCss, C as SETTING_VALUES, Cn as createTheme, D as EDGE_PROPS, Dn as getTheme, E as COLORS, En as fontStack, H as SHAPES, In as themeNames, Jt as esc, K as portOn, M as NUMBERS, Mn as isToneOrHex, Mt as groupProp, N as PANEL_PROPS, Nn as ramp, O as ENUMS, P as PANEL_PROP_HELP, Pn as registerTheme, Pt as lineStyle, T as BOOLS, Tn as fontFamilies, Tt as dashFor, a as lex, b as KNOWN_SETTINGS, bn as THEME_NAMES, bt as ALIGN_SIDES, c as parseProps, d as serializeProps, en as parseInline, gn as RAMPS, h as splitTrailingProps, i as blockBraces, j as NODE_PROPS, jn as isSafeLink, jt as groupPath, k as GROUP_PROPS, kn as isGenericFont, m as setTrailingProp, on as segsW, p as setLineProp, pn as tspans, rn as renderSegs, rt as renderHead, s as onlyColor, v as unquote, vn as THEMES, x as SETTING_HELP, xn as TONES, yn as THEME_KEYS, z as lint } from "./lex-DIq2EFvl.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";
6
8
  // src/browser.ts
7
9
  /**
8
10
  * Drop-in browser runtime: <script src="yuhwa.js"><\/script>
@@ -26,15 +28,10 @@ function prefersDark() {
26
28
  return typeof matchMedia === "function" && matchMedia("(prefers-color-scheme: dark)").matches;
27
29
  }
28
30
  function render(source, opts = {}) {
29
- let theme = opts.theme;
30
- if (!theme || theme === "auto") {
31
- const m = source.match(/^\s*theme\s*:\s*(\S+)/m);
32
- if (!m || m[1] === "auto") theme = prefersDark() ? "midnight" : "paper";
33
- }
34
31
  return render$1(source, {
35
32
  measureFor: (t) => canvasMeasure(t.font),
36
- ...opts,
37
- theme
33
+ scheme: prefersDark() ? "dark" : "light",
34
+ ...opts
38
35
  });
39
36
  }
40
37
  /** `render`, then draw the diagram into a canvas. */
@@ -88,11 +85,11 @@ let listening = false;
88
85
  * font still loading is measured with its fallback. One `loadingdone`
89
86
  * listener serves every diagram; a node that left the page drops out.
90
87
  */
91
- function redrawOnFonts(node, svg, redraw) {
88
+ function redrawOnFonts(node, families, redraw) {
92
89
  const fonts = typeof document === "undefined" ? void 0 : document.fonts;
93
90
  if (!fonts) return;
94
91
  waiting.set(node, {
95
- families: svgFamilies(svg),
92
+ families,
96
93
  redraw
97
94
  });
98
95
  if (listening) return;
@@ -106,16 +103,30 @@ function redrawOnFonts(node, svg, redraw) {
106
103
  /**
107
104
  * Puts the SVG into `host`. `render="png"` or `"canvas"` then draws it and
108
105
  * swaps the drawing in for the SVG, unless `current()` says a newer draw came.
106
+ * Without `families` it skips looking for web fonts: the draw before named the same.
109
107
  */
110
- function show(host, svg, mode, label, current) {
108
+ function show(host, svg, mode, label, current, families) {
111
109
  host.querySelectorAll("img[src^=\"blob:\"]").forEach((img) => URL.revokeObjectURL(img.src));
112
110
  host.innerHTML = svg;
113
111
  const node = host.querySelector("svg");
114
112
  fit(node);
115
- const fonts = loadFonts(svg);
113
+ const fonts = families ? loadFonts(svg, families) : Promise.resolve(false);
116
114
  if (!node || mode !== "png" && mode !== "canvas") return;
117
115
  fonts.then((changed) => changed ? void 0 : swapForRaster(node, svg, mode, label, current)).then(fit, (e) => console.warn(`yuhwa: ${mode} drawing failed: ${e.message}`));
118
116
  }
117
+ /** per element, the number of its latest draw: an older draw's PNG swap is dropped */
118
+ const draws = /* @__PURE__ */ new WeakMap();
119
+ /** Shows `r` in `el` in place of the draw before: the SVG or its drawing, the zoom viewer and the font redraw. */
120
+ function paintInto(el, r, p) {
121
+ el.yuhwaZoom?.destroy();
122
+ const draw = (draws.get(el) ?? 0) + 1;
123
+ draws.set(el, draw);
124
+ const families = p.fonts === false ? void 0 : p.fonts ?? svgFamilies(r.svg);
125
+ const current = () => draws.get(el) === draw && (p.live?.() ?? true);
126
+ show(el, r.svg, p.mode, p.label ?? r.diagram.settings.title ?? "diagram", current, families);
127
+ if (p.zoom) zoomable(el, p.zoom);
128
+ if (families) redrawOnFonts(el, families, p.redraw);
129
+ }
119
130
  function run(root = document, opts = {}) {
120
131
  root.querySelectorAll(SELECTOR).forEach((el) => {
121
132
  const host = el.tagName === "CODE" ? el.parentElement : el;
@@ -124,17 +135,16 @@ function run(root = document, opts = {}) {
124
135
  out.className = "yuhwa";
125
136
  out.dataset.rendered = "true";
126
137
  out.dataset.source = source;
127
- let draws = 0;
128
138
  const paint = () => {
129
139
  const r = render(source, {
130
140
  theme: host.dataset.theme,
131
141
  ...opts
132
142
  });
133
- out.yuhwaZoom?.destroy();
134
- const draw = ++draws;
135
- show(out, r.svg, host.dataset.render, r.diagram.settings.title ?? "diagram", () => draw === draws);
136
- if (host.dataset.zoom !== void 0) zoomable(out, { height: zoomHeight(host.dataset.zoom) });
137
- redrawOnFonts(out, r.svg, paint);
143
+ paintInto(out, r, {
144
+ mode: host.dataset.render,
145
+ zoom: host.dataset.zoom === void 0 ? void 0 : { height: zoomHeight(host.dataset.zoom) },
146
+ redraw: paint
147
+ });
138
148
  return r;
139
149
  };
140
150
  host.replaceWith(out);
@@ -147,6 +157,68 @@ function run(root = document, opts = {}) {
147
157
  }
148
158
  });
149
159
  }
160
+ /**
161
+ * Renders `source` into `el` and keeps it there: `update` re-renders in place,
162
+ * for live previews and editors. With no theme set, or `auto`, the diagram
163
+ * follows the reader's light or dark mode as it changes. Never throws on bad
164
+ * source: the diagnostics are on `result`.
165
+ */
166
+ function mount(el, source, opts = {}) {
167
+ let src = source;
168
+ let options = opts;
169
+ let result;
170
+ let alive = true;
171
+ const scheme = typeof matchMedia === "undefined" ? void 0 : matchMedia("(prefers-color-scheme: dark)");
172
+ let following = false;
173
+ const follow = (on) => {
174
+ if (scheme && on !== following) {
175
+ following = on;
176
+ scheme[on ? "addEventListener" : "removeEventListener"]("change", paint);
177
+ }
178
+ };
179
+ let fonts;
180
+ const paint = () => {
181
+ if (!alive) return result;
182
+ const { render: mode, zoom, ...renderOpts } = options;
183
+ result = render(src, renderOpts);
184
+ const families = svgFamilies(result.svg);
185
+ const key = [...families].sort().join("|");
186
+ const scan = key !== fonts;
187
+ fonts = key;
188
+ paintInto(el, result, {
189
+ mode,
190
+ zoom: zoom === void 0 || zoom === false ? void 0 : { height: zoomHeight(zoom === true ? "" : String(zoom)) },
191
+ redraw: paint,
192
+ fonts: scan && families,
193
+ live: () => alive
194
+ });
195
+ const theme = renderOpts.theme ?? result.diagram.settings.theme;
196
+ follow(theme === void 0 || getScheme(theme, result.diagram.themes) !== void 0);
197
+ return result;
198
+ };
199
+ paint();
200
+ return {
201
+ get result() {
202
+ return result;
203
+ },
204
+ update(next, more) {
205
+ src = next;
206
+ if (more) options = {
207
+ ...options,
208
+ ...more
209
+ };
210
+ return paint();
211
+ },
212
+ destroy() {
213
+ alive = false;
214
+ follow(false);
215
+ waiting.delete(el);
216
+ el.yuhwaZoom?.destroy();
217
+ el.querySelectorAll("img[src^=\"blob:\"]").forEach((img) => URL.revokeObjectURL(img.src));
218
+ el.replaceChildren();
219
+ }
220
+ };
221
+ }
150
222
  const Base = typeof HTMLElement === "undefined" ? class {} : HTMLElement;
151
223
  /**
152
224
  * <yuhwa-diagram [theme] [src] [zoom[=height]] [wheel]>source</yuhwa-diagram>;
@@ -166,7 +238,6 @@ var YuhwaDiagram = class extends Base {
166
238
  #request = 0;
167
239
  #file;
168
240
  #files = {};
169
- #draws = 0;
170
241
  get source() {
171
242
  return this.#source ?? "";
172
243
  }
@@ -214,23 +285,23 @@ var YuhwaDiagram = class extends Base {
214
285
  file: this.#file,
215
286
  resolve: (p) => files[p]
216
287
  });
217
- this.yuhwaZoom?.destroy();
218
- const draw = ++this.#draws;
219
- const label = this.getAttribute("aria-label") ?? r.diagram.settings.title ?? "diagram";
220
- show(this, r.svg, this.getAttribute("render") ?? void 0, label, () => draw === this.#draws);
221
288
  const zoom = this.getAttribute("zoom");
222
- this.setAttribute("role", zoom === null ? "img" : "group");
223
- if (zoom !== null) zoomable(this, {
224
- height: zoomHeight(zoom),
225
- wheel: this.hasAttribute("wheel")
289
+ paintInto(this, r, {
290
+ mode: this.getAttribute("render") ?? void 0,
291
+ label: this.getAttribute("aria-label") ?? void 0,
292
+ zoom: zoom === null ? void 0 : {
293
+ height: zoomHeight(zoom),
294
+ wheel: this.hasAttribute("wheel")
295
+ },
296
+ redraw: () => this.#draw()
226
297
  });
298
+ this.setAttribute("role", zoom === null ? "img" : "group");
227
299
  if (!this.hasAttribute("aria-label") || this.dataset.autoLabel) {
228
300
  const t = r.diagram.settings.title;
229
301
  if (t) this.setAttribute("aria-label", t), this.dataset.autoLabel = "1";
230
302
  else if (this.dataset.autoLabel) this.removeAttribute("aria-label"), delete this.dataset.autoLabel;
231
303
  }
232
304
  for (const d of r.diagnostics) console.warn(`yuhwa:${d.line}: ${d.message}`);
233
- redrawOnFonts(this, r.svg, () => this.#draw());
234
305
  this.dispatchEvent(new CustomEvent("yuhwa:render", { detail: {
235
306
  diagnostics: r.diagnostics,
236
307
  format: r.format
@@ -251,4 +322,4 @@ if (typeof document !== "undefined") {
251
322
  else run();
252
323
  }
253
324
  }
254
- export { ALIGN_SIDES, BOOLS, COLORS, EDGE_PROPS, ENUMS, GRID, GROUP_PROPS, GUIDE, KNOWN_SETTINGS, MD_LANGUAGES, NODE_PROPS, NUMBERS, PANELS, PANEL_PROPS, PANEL_PROP_HELP, RAMPS, SETTING_HELP, SETTING_VALUES, SHAPES, THEMES, THEME_KEYS, THEME_NAMES, TONES, YuhwaDiagram, addEdge, addNode, approxMeasure, blockBraces, builtins, canvasMeasure, chart, charts, createTheme, dashFor, editPart, embedFonts, esc, fetchImports, findBlocks, fontFamilies, fontStack, footer, formatLayout, frames, fromJSON, fromMermaid, gantt, getTheme, git, groupPath, groupProp, hash, isGenericFont, isMermaid, isSafeCss, isSafeLink, isToneOrHex, isYuhwaPath, joinPath, kanban, layout, legend, lex, lineStyle, lint, loadFonts, markers, mindmap, onlyColor, optionKind, parse, parseInline, parseProps, perPass, portOn, processMarkdown, quadrant, ramp, recolor, registerTheme, registry, removeElement, render, renderCanvas, renderHead, renderSegs, renderSvg, replaceBlockSource, run, segsW, sequence, serializeProps, setLabel, setLineProp, setPartTone, setProp, setSetting, setTrailingProp, shapes, splitTrailingProps, svgToCanvas, tables, themeNames, themes, timeline, toSource, treeview, tspans, unuse, use, writeLayout, writePanelDrag, zoomHeight, zoomable };
325
+ export { ALIGN_SIDES, BOOLS, COLORS, EDGE_PROPS, ENUMS, GRID, GROUP_PROPS, GUIDE, KNOWN_SETTINGS, MD_LANGUAGES, NODE_PROPS, NUMBERS, PANELS, PANEL_PROPS, PANEL_PROP_HELP, PLAIN_THEMES, RAMPS, SCHEMES, SETTING_HELP, SETTING_VALUES, SHAPES, THEMES, THEME_KEYS, THEME_NAMES, TONES, YuhwaDiagram, addEdge, addNode, approxMeasure, blockBraces, builtins, canvasMeasure, chart, charts, createTheme, dashFor, editPart, embedFonts, esc, fetchImports, findBlocks, fontFamilies, fontStack, footer, formatLayout, frames, fromJSON, fromMermaid, gantt, getScheme, getTheme, git, groupPath, groupProp, hash, isGenericFont, isMermaid, isSafeCss, isSafeLink, isToneOrHex, isYuhwaPath, joinPath, kanban, layout, legend, lex, lineStyle, lint, loadFonts, markers, mindmap, mount, onlyColor, optionKind, parse, parseInline, parseProps, perPass, plainThemeNames, portOn, processMarkdown, quadrant, ramp, recolor, registerTheme, registry, removeElement, render, renderCanvas, renderHead, renderSegs, renderSvg, renderText, replaceBlockSource, run, segsW, sequence, serializeProps, setLabel, setLineProp, setPartTone, setProp, setSetting, setTrailingProp, shapes, splitTrailingProps, svgToCanvas, tables, themeNames, themes, timeline, toSource, treeview, tspans, unuse, use, writeLayout, writePanelDrag, zoomHeight, zoomable };
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-Bqtxssxh.js").then((n) => n.i);
20
+ const { swapForRaster } = await import("./raster-CA2EZVsH.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 isSafeCss, C as canvasMeasure, D as KNOWN_SETTINGS, F as GROUP_PROPS, H as SHAPES, I as NODE_PROPS, M as COLORS, N as EDGE_PROPS, P as ENUMS, Q as TONES, R as PANEL_PROPS, S as unquote, T as registry, W as ALIGN_SIDES_HINT, X as THEME_KEYS, Z as THEME_NAMES, a as formatPage, c as diskResolve, d as MD_LANGUAGES, f as findBlocks, g as replaceBlockSource, h as processMarkdown, i as format, k as SETTING_VALUES, l as render$1, m as pageBlocks, nt as isYuhwaPath, p as isMarkdown, q as esc, rt as joinPath, s as tidy, t as VERSION, u as toSource, w as optionKind } from "./shared-Bhnvepka.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-BNy-W1fR.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";
@@ -42,7 +42,7 @@ const WEIGHT_WORDS = {
42
42
  normal: 400,
43
43
  bold: 700
44
44
  };
45
- function fontUsage(svg) {
45
+ function fontUsage(svg, families = svgFamilies(svg)) {
46
46
  const chars = /* @__PURE__ */ new Set();
47
47
  const text = svg.replace(/<style\b[^>]*>[\s\S]*?<\/style>/g, "").match(/>[^<]+</g) ?? [];
48
48
  for (const t of text) for (const ch of decode(t.slice(1, -1))) chars.add(ch.codePointAt(0));
@@ -51,12 +51,11 @@ function fontUsage(svg) {
51
51
  const w = WEIGHT_WORDS[v] ?? Number(v);
52
52
  if (w > 0) weights.add(w);
53
53
  }
54
- const italic = svgProp(svg, "font-style").some((v) => /^(?:italic|oblique)/.test(v));
55
54
  return {
56
- families: svgFamilies(svg),
55
+ families,
57
56
  chars,
58
57
  weights,
59
- italic
58
+ italic: svgProp(svg, "font-style").some((v) => /^(?:italic|oblique)/.test(v))
60
59
  };
61
60
  }
62
61
  /** a face's weight range: `400`, `100 900` (variable font) or `bold` */
@@ -231,14 +230,15 @@ async function embedFonts(svg, fonts = "page") {
231
230
  * it uses. Text is measured when the diagram renders, and a font that has
232
231
  * not loaded yet is measured with its fallback. Resolves true when a font
233
232
  * finished loading that was not ready before: render again for exact boxes.
233
+ * `families` saves a scan when the caller already has `svgFamilies(svg)`.
234
234
  */
235
- async function loadFonts(svg) {
235
+ async function loadFonts(svg, families) {
236
236
  const fonts = typeof document === "undefined" ? void 0 : document.fonts;
237
237
  if (!fonts) return false;
238
- const { families, chars, weights, italic } = fontUsage(svg);
238
+ const { families: named, chars, weights, italic } = fontUsage(svg, families);
239
239
  const text = String.fromCodePoint(...chars) || "a";
240
240
  const specs = [];
241
- for (const family of families) for (const w of weights) for (const style of italic ? ["normal", "italic"] : ["normal"]) specs.push(`${style} ${w} 16px ${cssString(family)}`);
241
+ for (const family of named) for (const w of weights) for (const style of italic ? ["normal", "italic"] : ["normal"]) specs.push(`${style} ${w} 16px ${cssString(family)}`);
242
242
  const missing = specs.filter((s) => {
243
243
  try {
244
244
  return !fonts.check(s, text);
@@ -306,6 +306,8 @@ async function swapForRaster(node, svg, mode, label, current = () => true) {
306
306
  const list$1 = (xs) => [...xs].join(", ");
307
307
  const code = (xs) => list$1([...xs].map((x) => "`" + x + "`"));
308
308
  const panels = [...registry.panels.values()];
309
+ /** the light/dark pairs in words: `auto` follows light or dark mode (paper/midnight) */
310
+ const schemes = () => list$1(Object.entries(SCHEMES).map(([n, s]) => `\`${n}\` follows light or dark mode (${s.light}/${s.dark})`));
309
311
  const PLACEHOLDER = {
310
312
  color: "<colour>",
311
313
  number: "N",
@@ -423,6 +425,10 @@ failed -> idle: reset [dashed]
423
425
  repeated shape of nodes instead of copying lines.
424
426
  - Group: \`group id "Label" .class [props] { ... }\`, may nest. \`group "Label" {\`
425
427
  gets a slug id. Edges connect nodes and panel ids (\`plan -> sales\`), never groups.
428
+ - Swimlanes: \`[lane]\` on a top-level group, or \`lanes: on\` for every
429
+ top-level group, lays them out as bands across the whole diagram (rows with
430
+ \`direction: right\`, columns with \`direction: down\`) in declared order,
431
+ with a header strip. Nodes keep their ranks across lanes; groups may nest in a lane.
426
432
  - Props: \`[key: value, key: "a, b", flag]\`; a bare flag means true, a bare
427
433
  value names its key: \`[cylinder, amber, dashed]\`.
428
434
  - Props on their own lines: a \`key: value\` line indented under a node, edge,
@@ -445,7 +451,7 @@ failed -> idle: reset [dashed]
445
451
  props (${list$1(COLORS)}) take the same values and colour one part.
446
452
  - Shapes: ${list$1(SHAPES)}.
447
453
  - Line styles: ${list$1(ENUMS.style)}. Heads: ${list$1(ENUMS.head)}. Sides (\`exit\`, \`enter\`): ${list$1(ENUMS.exit)}.
448
- - Themes: ${list$1(THEME_NAMES)}. Define one with \`theme brand [base: midnight, accent: orange]\`
454
+ - Themes: ${list$1(PLAIN_THEMES)}; ${schemes()}. Define one with \`theme brand [base: midnight, accent: orange]\`
449
455
  or \`theme brand {\` and one \`key: value\` per line, then \`theme: brand\`.
450
456
  Keys: ${list$1(Object.keys(THEME_KEYS))}.
451
457
 
@@ -1249,15 +1255,10 @@ function prefersDark() {
1249
1255
  return typeof matchMedia === "function" && matchMedia("(prefers-color-scheme: dark)").matches;
1250
1256
  }
1251
1257
  function render(source, opts = {}) {
1252
- let theme = opts.theme;
1253
- if (!theme || theme === "auto") {
1254
- const m = source.match(/^\s*theme\s*:\s*(\S+)/m);
1255
- if (!m || m[1] === "auto") theme = prefersDark() ? "midnight" : "paper";
1256
- }
1257
1258
  return render$1(source, {
1258
1259
  measureFor: (t) => canvasMeasure(t.font),
1259
- ...opts,
1260
- theme
1260
+ scheme: prefersDark() ? "dark" : "light",
1261
+ ...opts
1261
1262
  });
1262
1263
  }
1263
1264
  const IMPORT_RE = /^\s*import\s+(?:\{[^}]*\}\s*from\s+)?"([^"]+)"/gm;
@@ -1302,11 +1303,11 @@ let listening = false;
1302
1303
  * font still loading is measured with its fallback. One `loadingdone`
1303
1304
  * listener serves every diagram; a node that left the page drops out.
1304
1305
  */
1305
- function redrawOnFonts(node, svg, redraw) {
1306
+ function redrawOnFonts(node, families, redraw) {
1306
1307
  const fonts = typeof document === "undefined" ? void 0 : document.fonts;
1307
1308
  if (!fonts) return;
1308
1309
  waiting.set(node, {
1309
- families: svgFamilies(svg),
1310
+ families,
1310
1311
  redraw
1311
1312
  });
1312
1313
  if (listening) return;
@@ -1320,16 +1321,30 @@ function redrawOnFonts(node, svg, redraw) {
1320
1321
  /**
1321
1322
  * Puts the SVG into `host`. `render="png"` or `"canvas"` then draws it and
1322
1323
  * swaps the drawing in for the SVG, unless `current()` says a newer draw came.
1324
+ * Without `families` it skips looking for web fonts: the draw before named the same.
1323
1325
  */
1324
- function show(host, svg, mode, label, current) {
1326
+ function show(host, svg, mode, label, current, families) {
1325
1327
  host.querySelectorAll("img[src^=\"blob:\"]").forEach((img) => URL.revokeObjectURL(img.src));
1326
1328
  host.innerHTML = svg;
1327
1329
  const node = host.querySelector("svg");
1328
1330
  fit(node);
1329
- const fonts = loadFonts(svg);
1331
+ const fonts = families ? loadFonts(svg, families) : Promise.resolve(false);
1330
1332
  if (!node || mode !== "png" && mode !== "canvas") return;
1331
1333
  fonts.then((changed) => changed ? void 0 : swapForRaster(node, svg, mode, label, current)).then(fit, (e) => console.warn(`yuhwa: ${mode} drawing failed: ${e.message}`));
1332
1334
  }
1335
+ /** per element, the number of its latest draw: an older draw's PNG swap is dropped */
1336
+ const draws = /* @__PURE__ */ new WeakMap();
1337
+ /** Shows `r` in `el` in place of the draw before: the SVG or its drawing, the zoom viewer and the font redraw. */
1338
+ function paintInto(el, r, p) {
1339
+ el.yuhwaZoom?.destroy();
1340
+ const draw = (draws.get(el) ?? 0) + 1;
1341
+ draws.set(el, draw);
1342
+ const families = p.fonts === false ? void 0 : p.fonts ?? svgFamilies(r.svg);
1343
+ const current = () => draws.get(el) === draw && (p.live?.() ?? true);
1344
+ show(el, r.svg, p.mode, p.label ?? r.diagram.settings.title ?? "diagram", current, families);
1345
+ if (p.zoom) zoomable(el, p.zoom);
1346
+ if (families) redrawOnFonts(el, families, p.redraw);
1347
+ }
1333
1348
  function run(root = document, opts = {}) {
1334
1349
  root.querySelectorAll(SELECTOR).forEach((el) => {
1335
1350
  const host = el.tagName === "CODE" ? el.parentElement : el;
@@ -1338,17 +1353,16 @@ function run(root = document, opts = {}) {
1338
1353
  out.className = "yuhwa";
1339
1354
  out.dataset.rendered = "true";
1340
1355
  out.dataset.source = source;
1341
- let draws = 0;
1342
1356
  const paint = () => {
1343
1357
  const r = render(source, {
1344
1358
  theme: host.dataset.theme,
1345
1359
  ...opts
1346
1360
  });
1347
- out.yuhwaZoom?.destroy();
1348
- const draw = ++draws;
1349
- show(out, r.svg, host.dataset.render, r.diagram.settings.title ?? "diagram", () => draw === draws);
1350
- if (host.dataset.zoom !== void 0) zoomable(out, { height: zoomHeight(host.dataset.zoom) });
1351
- redrawOnFonts(out, r.svg, paint);
1361
+ paintInto(out, r, {
1362
+ mode: host.dataset.render,
1363
+ zoom: host.dataset.zoom === void 0 ? void 0 : { height: zoomHeight(host.dataset.zoom) },
1364
+ redraw: paint
1365
+ });
1352
1366
  return r;
1353
1367
  };
1354
1368
  host.replaceWith(out);
@@ -1380,7 +1394,6 @@ var YuhwaDiagram = class extends Base {
1380
1394
  #request = 0;
1381
1395
  #file;
1382
1396
  #files = {};
1383
- #draws = 0;
1384
1397
  get source() {
1385
1398
  return this.#source ?? "";
1386
1399
  }
@@ -1428,23 +1441,23 @@ var YuhwaDiagram = class extends Base {
1428
1441
  file: this.#file,
1429
1442
  resolve: (p) => files[p]
1430
1443
  });
1431
- this.yuhwaZoom?.destroy();
1432
- const draw = ++this.#draws;
1433
- const label = this.getAttribute("aria-label") ?? r.diagram.settings.title ?? "diagram";
1434
- show(this, r.svg, this.getAttribute("render") ?? void 0, label, () => draw === this.#draws);
1435
1444
  const zoom = this.getAttribute("zoom");
1436
- this.setAttribute("role", zoom === null ? "img" : "group");
1437
- if (zoom !== null) zoomable(this, {
1438
- height: zoomHeight(zoom),
1439
- wheel: this.hasAttribute("wheel")
1445
+ paintInto(this, r, {
1446
+ mode: this.getAttribute("render") ?? void 0,
1447
+ label: this.getAttribute("aria-label") ?? void 0,
1448
+ zoom: zoom === null ? void 0 : {
1449
+ height: zoomHeight(zoom),
1450
+ wheel: this.hasAttribute("wheel")
1451
+ },
1452
+ redraw: () => this.#draw()
1440
1453
  });
1454
+ this.setAttribute("role", zoom === null ? "img" : "group");
1441
1455
  if (!this.hasAttribute("aria-label") || this.dataset.autoLabel) {
1442
1456
  const t = r.diagram.settings.title;
1443
1457
  if (t) this.setAttribute("aria-label", t), this.dataset.autoLabel = "1";
1444
1458
  else if (this.dataset.autoLabel) this.removeAttribute("aria-label"), delete this.dataset.autoLabel;
1445
1459
  }
1446
1460
  for (const d of r.diagnostics) console.warn(`yuhwa:${d.line}: ${d.message}`);
1447
- redrawOnFonts(this, r.svg, () => this.#draw());
1448
1461
  this.dispatchEvent(new CustomEvent("yuhwa:render", { detail: {
1449
1462
  diagnostics: r.diagnostics,
1450
1463
  format: r.format
@@ -1469,7 +1482,7 @@ if (typeof document !== "undefined") {
1469
1482
  const HELP = `yuhwa — diagrams that look good and stay where you put them
1470
1483
 
1471
1484
  Usage
1472
- yuhwa render <file|-|source> [-e source] [-o out.svg|out.html|out.png] [--html] [--png] [--scale 2] [--font f] [--no-system-fonts] [--theme name] [--block n]
1485
+ yuhwa render <file|-|source> [-e source] [-o out.svg|out.html|out.png|out.txt] [--html] [--png] [--text|--ascii] [--scale 2] [--font f] [--no-system-fonts] [--theme name] [--block n]
1473
1486
  yuhwa check <file|-|source...> [-e source] [--json] [--strict] [--lang yuhwa,yu]
1474
1487
  yuhwa lint <file...> [--fix] [--json] [--lang yuhwa,yu]
1475
1488
  yuhwa convert <file.mmd|file.json|-|source> [-e source] [-o out.yu]
@@ -1495,6 +1508,8 @@ render Render one diagram to SVG (stdout unless -o is given). From a
1495
1508
  (default 2). PNG needs the optional @resvg/resvg-js package and
1496
1509
  uses system fonts; --font adds a font file or folder (repeatable),
1497
1510
  --no-system-fonts uses only those, the same on every machine.
1511
+ -o x.txt or --text draws the diagram with box-drawing characters,
1512
+ --ascii with plain ASCII only, for terminals, commits and READMEs.
1498
1513
  check Validate without rendering. --json prints machine-readable diagnostics.
1499
1514
  --strict fails on warnings too (exit code 1, \`ok: false\`).
1500
1515
  A .md/.mdx/.markdown file is checked block by block: every
@@ -1567,9 +1582,19 @@ function cmdRender(a) {
1567
1582
  if (!b) throw new Error(blocks.length ? `${file} has no yuhwa block #${n} (it has ${blocks.length})` : `${file} has no yuhwa blocks`);
1568
1583
  ({source, line: at} = b);
1569
1584
  }
1585
+ const out = str(a.out);
1586
+ if (a.text || a.ascii || /\.txt$/i.test(out ?? "")) {
1587
+ const t = renderText(source, {
1588
+ ...fileOpts(file),
1589
+ ascii: !!a.ascii
1590
+ });
1591
+ printDiagnostics(file, offsetLines(t.diagnostics, at));
1592
+ writeOut(out, t.text + "\n");
1593
+ if (!passes(t.diagnostics)) process.exitCode = 1;
1594
+ return;
1595
+ }
1570
1596
  const r = renderAs(a, file, source);
1571
1597
  printDiagnostics(file, offsetLines(r.diagnostics, at));
1572
- const out = str(a.out);
1573
1598
  const kind = a.html || /\.html?$/i.test(out ?? "") ? "html" : a.png || /\.png$/i.test(out ?? "") ? "png" : "svg";
1574
1599
  if (kind === "png") writeOut(out, svgToPng(r.svg, {
1575
1600
  scale: Number(str(a.scale) ?? 2),
@@ -1733,7 +1758,8 @@ function cmdLint(a) {
1733
1758
  } else for (const at of unformatted) diagnostics.push({
1734
1759
  ...at,
1735
1760
  message: "Not formatted: run yuhwa lint --fix",
1736
- severity: "warning"
1761
+ severity: "warning",
1762
+ code: "unformatted"
1737
1763
  });
1738
1764
  }
1739
1765
  diagnostics.sort((x, y) => x.line - y.line);