yuhwa 1.3.0 → 1.4.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 (57) hide show
  1. package/README.md +5 -3
  2. package/dist/astro.d.ts +1 -1
  3. package/dist/astro.js +4 -3
  4. package/dist/browser.d.ts +10 -4
  5. package/dist/browser.js +85 -22
  6. package/dist/canvas.d.ts +2 -0
  7. package/dist/canvas.js +40 -0
  8. package/dist/cli.js +485 -236
  9. package/dist/editor/assets/index-DWm3xV_v.js +689 -0
  10. package/dist/editor/assets/{lsp.worker-CMSpDTsX.js → lsp.worker-N6A9m364.js} +23 -17
  11. package/dist/editor/index.html +4 -1
  12. package/dist/{figure-QAwSU1Ry.d.ts → figure-BLHfxz_e.d.ts} +28 -5
  13. package/dist/{index-6ZPJGThY.d.ts → index-xVW43gqW.d.ts} +48 -3
  14. package/dist/index.d.ts +3 -3
  15. package/dist/index.js +5 -3
  16. package/dist/ironmark.d.ts +1 -1
  17. package/dist/ironmark.js +1 -1
  18. package/dist/lsp-browser.d.ts +2 -2
  19. package/dist/lsp-browser.js +2 -1
  20. package/dist/lsp-node.js +46 -26
  21. package/dist/lsp-server.d.ts +5 -1
  22. package/dist/lsp-server.js +1 -1
  23. package/dist/lsp.d.ts +1 -1
  24. package/dist/lsp.js +1 -1
  25. package/dist/markdown-it.d.ts +1 -1
  26. package/dist/markdown-it.js +5 -3
  27. package/dist/{node-CLu2Pp_2.js → node-CkrQnPFb.js} +90 -13
  28. package/dist/{plugin-Bs4eiAuz.js → parse--ljBMU60.js} +25 -307
  29. package/dist/plugin-CitzbblK.js +301 -0
  30. package/dist/{plugin-NSkNyoUj.d.ts → plugin-NMP_uf1a.d.ts} +15 -1
  31. package/dist/plugin.d.ts +1 -1
  32. package/dist/plugin.js +3 -1
  33. package/dist/raster-iqi6XRPU.js +299 -0
  34. package/dist/remark.d.ts +1 -1
  35. package/dist/remark.js +1 -1
  36. package/dist/rolldown-runtime-CEjnN5Q1.js +37 -0
  37. package/dist/{server-D6BSNC1P.js → server-BTYtmr6B.js} +41 -63
  38. package/dist/{server--jHjJjOS.d.ts → server-DMAOtqqK.d.ts} +1 -1
  39. package/dist/{service-D7DNWBAU.js → service-C60VdeKS.js} +34 -3
  40. package/dist/{service-Brvpt7Do.d.ts → service-DimTFsE3.d.ts} +2 -0
  41. package/dist/{shared-6aCU_HaV.js → shared-h8tkFLY4.js} +231 -21
  42. package/dist/{src-BjOhvTAB.js → src-NCXCTK_4.js} +81 -45
  43. package/dist/svg-uri-Dx8SGV-n.js +7 -0
  44. package/dist/vite.d.ts +1 -1
  45. package/dist/vite.js +3 -3
  46. package/dist/vuepress.d.ts +3 -2
  47. package/dist/vuepress.js +4 -2
  48. package/dist/watch-2VeW5DUN.js +35 -0
  49. package/dist/yuhwa.iife.js +55 -54
  50. package/dist/zoom-script-CaJ5MNUw.js +29 -0
  51. package/dist/{zoom-QeqB6QlH.js → zoom-yxhxX16c.js} +1 -1
  52. package/dist/zoom.d.ts +16 -7
  53. package/dist/zoom.js +2 -2
  54. package/package.json +19 -2
  55. package/skills/yuhwa/SKILL.md +12 -0
  56. package/dist/editor/assets/index-DAk6b1UB.js +0 -689
  57. package/dist/zoom-script-CVdAzMhX.js +0 -51
@@ -9,7 +9,7 @@
9
9
  rel="icon"
10
10
  href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 64'%3E%3Cdefs%3E%3ClinearGradient id='g' x1='0' y1='0' x2='1' y2='1'%3E%3Cstop offset='0' stop-color='%232563eb'/%3E%3Cstop offset='1' stop-color='%239333ea'/%3E%3C/linearGradient%3E%3C/defs%3E%3Crect width='64' height='64' rx='15' fill='url%28%23g%29'/%3E%3Crect x='9' y='11' width='26' height='17' rx='5' fill='%23fff'/%3E%3Cpath d='M15 17.5h10M15 22h14' stroke='%237c3aed' stroke-opacity='.35' stroke-width='2.5' stroke-linecap='round'/%3E%3Cpath d='M18 28v5a11 11 0 0 0 11 11h1' fill='none' stroke='%23fff' stroke-width='4' stroke-linecap='round'/%3E%3Cpath d='m29 38 6 6-6 6' fill='none' stroke='%23fff' stroke-width='4' stroke-linecap='round' stroke-linejoin='round'/%3E%3Crect x='38' y='36' width='17' height='16' rx='5' fill='%23fff' fill-opacity='.9'/%3E%3C/svg%3E"
11
11
  />
12
- <script type="module" crossorigin src="./assets/index-DAk6b1UB.js"></script>
12
+ <script type="module" crossorigin src="./assets/index-DWm3xV_v.js"></script>
13
13
  <link rel="stylesheet" crossorigin href="./assets/index-DaWl0OPj.css">
14
14
  </head>
15
15
  <body>
@@ -173,6 +173,9 @@
173
173
  <button id="download" title="Download SVG">
174
174
  <svg><use href="#i-download" /></svg><span class="wide">Download</span>
175
175
  </button>
176
+ <button id="download-png" title="Download PNG">
177
+ <svg><use href="#i-download" /></svg>PNG
178
+ </button>
176
179
  <button id="copy-md" title="Copy as Markdown">
177
180
  <svg><use href="#i-md" /></svg><span class="wide">Markdown</span>
178
181
  </button>
@@ -1,4 +1,18 @@
1
- import { n as Options } from "./index-6ZPJGThY.js";
1
+ import { n as Options } from "./index-xVW43gqW.js";
2
+ /**
3
+ * SVG to PNG in Node, with @resvg/resvg-js (an optional peer dependency: Node
4
+ * has no canvas). Synchronous, so markdown plugins can call it while they
5
+ * render. Node modules load on first use only, so bundlers that pull in the
6
+ * integrations for the browser never meet them.
7
+ */
8
+ interface PngOptions {
9
+ /** pixels per SVG unit (default 2) */
10
+ scale?: number;
11
+ /** font files (ttf, otf, ttc) or folders of them */
12
+ fonts?: string[];
13
+ /** also use the fonts installed on the system (default `true`) */
14
+ systemFonts?: boolean;
15
+ }
2
16
  interface YuhwaDocsOptions extends Omit<Options, "theme" | "file"> {
3
17
  /** theme for light mode (default `paper`) */
4
18
  theme?: string;
@@ -16,13 +30,22 @@ interface YuhwaDocsOptions extends Omit<Options, "theme" | "file"> {
16
30
  */
17
31
  darkMode?: "class" | "media";
18
32
  /**
19
- * `svg` inlines the SVG instead of an `<img>` (markdown-it only; keeps
20
- * diagram text selectable and links clickable). Not for Vue-based sites.
33
+ * What the page gets:
34
+ * - `img` (default): the SVG as an `<img>`
35
+ * - `svg`: the SVG inline (markdown-it only; keeps diagram text selectable
36
+ * and links clickable). Not for Vue-based sites
37
+ * - `png`: a PNG drawn at build time, as an `<img>`. Needs the optional
38
+ * `@resvg/resvg-js` package; `png` sets its scale and fonts
39
+ * - `canvas`: a `<canvas>` drawn in the browser with the page's web fonts.
40
+ * The page gets the SVG `<img>`, and `yuhwa/canvas` swaps it for the
41
+ * canvas (Astro and VuePress load it for you)
21
42
  */
22
- output?: "img" | "svg";
43
+ output?: "img" | "svg" | "png" | "canvas";
44
+ /** scale and fonts for `output: 'png'` (default scale 2, system fonts) */
45
+ png?: PngOptions;
23
46
  /** throw on errors and fail the build (default `true`); `false` shows them under the diagram */
24
47
  strict?: boolean;
25
- /** fence languages handled (default `['yuhwa']`) */
48
+ /** fence languages handled (default `['yuhwa', 'yu']`) */
26
49
  languages?: string[];
27
50
  /**
28
51
  * Folder that `file="..."` blocks and imports must stay inside. A `file`
@@ -1,4 +1,4 @@
1
- import { Et as YuhwaPlugin, L as Diagnostic, R as Diagram, X as LayoutOverrides, Y as Layout, at as PartEdit, et as PanelHandle, mt as LayoutOptions, v as ParseOptions, vn as Measure, xt as PanelOption } from "./plugin-NSkNyoUj.js";
1
+ import { Et as YuhwaPlugin, L as Diagnostic, R as Diagram, X as LayoutOverrides, Y as Layout, at as PartEdit, et as PanelHandle, mt as LayoutOptions, v as ParseOptions, xn as Measure, xt as PanelOption } from "./plugin-NMP_uf1a.js";
2
2
  interface RenderOptions {
3
3
  /** prefix for ids inside the SVG, so several diagrams can live on one page */
4
4
  idPrefix?: string;
@@ -89,6 +89,49 @@ declare function editPart(source: string, panelId: string, edit: PartEdit, d?: D
89
89
  };
90
90
  /** Finish a panel drag. Prefer the declaration; a purely visual handle uses layout. */
91
91
  declare function writePanelDrag(source: string, d: Diagram, id: string, handle: PanelHandle): string;
92
+ /** a font file to embed, as `@font-face` would name it */
93
+ interface FontSource {
94
+ family: string;
95
+ /** URL of the font file (woff2, woff, ttf, otf) or a `data:` URL */
96
+ url: string;
97
+ /** CSS font-weight, e.g. `400` or `100 900` for a variable font */
98
+ weight?: string;
99
+ /** CSS font-style: `normal` or `italic` */
100
+ style?: string;
101
+ /** CSS unicode-range; the font is left out when the diagram uses none of it */
102
+ unicodeRange?: string;
103
+ }
104
+ interface RasterOptions {
105
+ /** canvas to draw into; resized to fit. Default: a new canvas */
106
+ canvas?: HTMLCanvasElement;
107
+ /** pixels per SVG unit. Default: `devicePixelRatio`, or 1 */
108
+ scale?: number;
109
+ /** fill behind the diagram, e.g. white under a `transparent` SVG saved as JPEG */
110
+ background?: string;
111
+ /**
112
+ * Fonts to embed. `'page'` (default) embeds the page's `@font-face` fonts
113
+ * that the diagram names; a list embeds those files; `false` embeds
114
+ * nothing, so only fonts installed on the system are used.
115
+ */
116
+ fonts?: "page" | false | FontSource[];
117
+ }
118
+ /**
119
+ * Embeds the fonts the SVG names as an `@font-face` `<style>` inside it.
120
+ * Fonts it cannot fetch are skipped: the image then falls back to system fonts.
121
+ */
122
+ declare function embedFonts(svg: string, fonts?: "page" | FontSource[]): Promise<string>;
123
+ /**
124
+ * Loads the page's web fonts that the SVG names, in the weights and styles
125
+ * it uses. Text is measured when the diagram renders, and a font that has
126
+ * not loaded yet is measured with its fallback. Resolves true when a font
127
+ * finished loading that was not ready before: render again for exact boxes.
128
+ */
129
+ declare function loadFonts(svg: string): Promise<boolean>;
130
+ /**
131
+ * Draws an SVG string, such as `render(...).svg`, into a canvas. The page's
132
+ * web fonts that the diagram names are embedded first (see `fonts`).
133
+ */
134
+ declare function svgToCanvas(svg: string, opts?: RasterOptions): Promise<HTMLCanvasElement>;
92
135
  interface MdBlock {
93
136
  index: number;
94
137
  name: string;
@@ -107,7 +150,7 @@ interface MdOptions {
107
150
  baseName?: string;
108
151
  /** also write a dark variant and emit a <picture> element */
109
152
  dark?: boolean;
110
- /** keep ```yuhwa fences instead of converting them to comments */
153
+ /** keep ```yuhwa and ```yu fences instead of converting them to comments */
111
154
  keepFences?: boolean;
112
155
  /** reads `import "..."` targets, see Options.resolve */
113
156
  resolve?: (path: string) => string | undefined;
@@ -133,6 +176,8 @@ interface MdResult {
133
176
  severity: string;
134
177
  }[];
135
178
  }
179
+ /** fence languages that hold a diagram */
180
+ declare const MD_LANGUAGES: string[];
136
181
  declare function findBlocks(md: string, baseName?: string, outDir?: string): MdBlock[];
137
182
  declare function processMarkdown(md: string, opts?: MdOptions): MdResult;
138
183
  /** Replace the source of block `index` in a markdown document. */
@@ -213,4 +258,4 @@ declare function toSource(input: string | DiagramJSON): {
213
258
  };
214
259
  /** Parse, lay out and render a diagram to an SVG string. Never throws on bad input. */
215
260
  declare function render(input: string | DiagramJSON, opts?: Options): Result;
216
- export { JsonResult as $, GROUP_PROPS as A, MdResult as B, markers as C, COLORS as D, BOOLS as E, ConvertResult as F, formatLayout as G, processMarkdown as H, fromMermaid as I, setProp as J, setLabel as K, isMermaid as L, NUMBERS as M, PANEL_PROPS as N, EDGE_PROPS as O, lint as P, DiagramJSON as Q, MdBlock as R, themes as S, GUIDE as T, replaceBlockSource as U, findBlocks as V, editPart as W, writeLayout as X, setSetting as Y, writePanelDrag as Z, legend as _, render as a, tables as b, treeview as c, gantt as d, fromJSON as et, mindmap as f, sequence as g, timeline as h, hash as i, NODE_PROPS as j, ENUMS as k, kanban as l, chart as m, Options as n, toSource as o, git as p, setPartTone as q, Result as r, builtins as s, InputFormat as t, renderSvg as tt, quadrant as u, footer as v, shapes as w, charts as x, frames as y, MdOptions as z };
261
+ export { setPartTone as $, GROUP_PROPS as A, MdOptions as B, markers as C, COLORS as D, BOOLS as E, ConvertResult as F, FontSource as G, findBlocks as H, fromMermaid as I, loadFonts as J, RasterOptions as K, isMermaid as L, NUMBERS as M, PANEL_PROPS as N, EDGE_PROPS as O, lint as P, setLabel as Q, MD_LANGUAGES as R, themes as S, GUIDE as T, processMarkdown as U, MdResult as V, replaceBlockSource as W, editPart as X, svgToCanvas as Y, formatLayout as Z, legend as _, render as a, JsonResult as at, tables as b, treeview as c, gantt as d, setProp as et, mindmap as f, sequence as g, timeline as h, hash as i, DiagramJSON as it, NODE_PROPS as j, ENUMS as k, kanban as l, chart as m, Options as n, writeLayout as nt, toSource as o, fromJSON as ot, git as p, embedFonts as q, Result as r, writePanelDrag as rt, builtins as s, renderSvg as st, InputFormat as t, setSetting as tt, quadrant as u, footer as v, shapes as w, charts as x, frames as y, MdBlock as z };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import { $ as PanelDecl, A as setLineProp, At as registry, B as EdgeDecl, C as isYuhwaPath, Ct as RowKind, D as parse, Dt as optionKind, E as onlyColor, Et as YuhwaPlugin, F as Component, Ft as renderHead, G as LaidEdge, Gt as segsW, H as GroupDecl, Ht as parseInline, I as Curve, It as InkColors, J as LaidPanel, Jt as tspans, K as LaidGroup, L as Diagnostic, Lt as Seg, M as splitTrailingProps, Mt as use, Nt as MarkerKind, O as parseProps, Ot as perPass, P as Box, Pt as ShapeKind, Q as NodeOverride, Qt as RAMPS, R as Diagram, Rt as esc, S as blockBraces, St as RowCtx, T as lex, Tt as StatementKind, U as HeadKind, V as EdgeOverride, W as LabelRef, Wt as renderSegs, X as LayoutOverrides, Xt as LineStyle, Y as Layout, Z as NodeDecl, _ as PANELS, _n as themeNames, _t as Decoration, an as ThemeInput, at as PartEdit, b as Tok, bn as canvasMeasure, bt as PanelKind, ct as ResolvedEdgeStyle, dn as isSafeCss, dt as Side, en as THEMES, et as PanelHandle, f as portOn, fn as isSafeLink, ft as SourceRef, g as LexedLine, gt as layout, h as KNOWN_SETTINGS, hn as registerTheme, ht as groupPath, in as Theme, it as PartChange, j as setTrailingProp, jt as unuse, k as serializeProps, kt as recolor, ln as getTheme, lt as ResolvedNodeStyle, mn as ramp, nn as THEME_NAMES, nt as PanelPart, o as lineStyle, ot as Point, pn as isToneOrHex, pt as GRID, q as LaidNode, r as dashFor, rn as TONES, rt as PartAction, sn as createTheme, st as Props, tn as THEME_KEYS, tt as PanelOverride, u as SHAPES, ut as ShapeName, v as ParseOptions, vt as FrameKind, w as joinPath, wt as RowPaint, x as TokKind, xt as PanelOption, y as SETTING_VALUES, yn as approxMeasure, yt as PanelCtx, z as Direction } from "./plugin-NSkNyoUj.js";
2
- import { $ as JsonResult, A as GROUP_PROPS, B as MdResult, C as markers, D as COLORS, E as BOOLS, F as ConvertResult, G as formatLayout, H as processMarkdown, I as fromMermaid, J as setProp, K as setLabel, L as isMermaid, M as NUMBERS, N as PANEL_PROPS, O as EDGE_PROPS, P as lint, Q as DiagramJSON, R as MdBlock, S as themes, T as GUIDE, U as replaceBlockSource, V as findBlocks, W as editPart, X as writeLayout, Y as setSetting, Z as writePanelDrag, _ as legend, a as render, b as tables, c as treeview, d as gantt, et as fromJSON, f as mindmap, g as sequence, h as timeline, i as hash, j as NODE_PROPS, k as ENUMS, l as kanban, m as chart, n as Options, o as toSource, p as git, q as setPartTone, r as Result, s as builtins, t as InputFormat, tt as renderSvg, u as quadrant, v as footer, w as shapes, x as charts, y as frames, z as MdOptions } from "./index-6ZPJGThY.js";
3
- export { 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 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, type MarkerKind, type MdBlock, type MdOptions, type MdResult, NODE_PROPS, NUMBERS, type NodeDecl, type NodeOverride, Options, PANELS, PANEL_PROPS, 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 ResolvedEdgeStyle, type ResolvedNodeStyle, Result, type RowCtx, type RowKind, type RowPaint, SETTING_VALUES, SHAPES, type Seg, type ShapeKind, type ShapeName, type Side, type SourceRef, type StatementKind, THEMES, THEME_KEYS, THEME_NAMES, TONES, type Theme, type ThemeInput, type Tok, type TokKind, type YuhwaPlugin, approxMeasure, blockBraces, builtins, canvasMeasure, chart, charts, createTheme, dashFor, editPart, esc, findBlocks, footer, formatLayout, frames, fromJSON, fromMermaid, gantt, getTheme, git, groupPath, hash, isMermaid, isSafeCss, isSafeLink, isToneOrHex, isYuhwaPath, joinPath, kanban, layout, legend, lex, lineStyle, lint, markers, mindmap, onlyColor, optionKind, parse, parseInline, parseProps, perPass, portOn, processMarkdown, quadrant, ramp, recolor, registerTheme, registry, render, renderHead, renderSegs, renderSvg, replaceBlockSource, segsW, sequence, serializeProps, setLabel, setLineProp, setPartTone, setProp, setSetting, setTrailingProp, shapes, splitTrailingProps, tables, themeNames, themes, timeline, toSource, treeview, tspans, unuse, use, writeLayout, writePanelDrag };
1
+ import { $ as PanelDecl, A as setLineProp, At as registry, B as EdgeDecl, C as isYuhwaPath, Cn as canvasMeasure, Ct as RowKind, D as parse, Dt as optionKind, E as onlyColor, Et as YuhwaPlugin, F as Component, Ft as renderHead, G as LaidEdge, Gt as segsW, H as GroupDecl, Ht as parseInline, I as Curve, It as InkColors, J as LaidPanel, Jt as tspans, K as LaidGroup, L as Diagnostic, Lt as Seg, M as splitTrailingProps, Mt as use, Nt as MarkerKind, O as parseProps, Ot as perPass, P as Box, Pt as ShapeKind, Q as NodeOverride, Qt as RAMPS, R as Diagram, Rt as esc, S as blockBraces, Sn as approxMeasure, St as RowCtx, T as lex, Tt as StatementKind, U as HeadKind, V as EdgeOverride, W as LabelRef, Wt as renderSegs, X as LayoutOverrides, Xt as LineStyle, Y as Layout, Z as NodeDecl, _ as PANELS, _n as ramp, _t as Decoration, an as ThemeInput, at as PartEdit, b as Tok, bn as themeNames, bt as PanelKind, ct as ResolvedEdgeStyle, dn as getTheme, dt as Side, en as THEMES, et as PanelHandle, f as portOn, ft as SourceRef, g as LexedLine, gn as isToneOrHex, gt as layout, h as KNOWN_SETTINGS, hn as isSafeLink, ht as groupPath, in as Theme, it as PartChange, j as setTrailingProp, jt as unuse, k as serializeProps, kt as recolor, ln as fontFamilies, lt as ResolvedNodeStyle, mn as isSafeCss, nn as THEME_NAMES, nt as PanelPart, o as lineStyle, ot as Point, pn as isGenericFont, pt as GRID, q as LaidNode, r as dashFor, rn as TONES, rt as PartAction, sn as createTheme, st as Props, tn as THEME_KEYS, tt as PanelOverride, u as SHAPES, un as fontStack, ut as ShapeName, v as ParseOptions, vn as registerTheme, vt as FrameKind, w as joinPath, wt as RowPaint, x as TokKind, xt as PanelOption, y as SETTING_VALUES, yt as PanelCtx, z as Direction } from "./plugin-NMP_uf1a.js";
2
+ import { $ as setPartTone, A as GROUP_PROPS, B as MdOptions, C as markers, D as COLORS, E as BOOLS, F as ConvertResult, G as FontSource, H as findBlocks, I as fromMermaid, J as loadFonts, K as RasterOptions, L as isMermaid, M as NUMBERS, N as PANEL_PROPS, O as EDGE_PROPS, P as lint, Q as setLabel, R as MD_LANGUAGES, S as themes, T as GUIDE, U as processMarkdown, V as MdResult, W as replaceBlockSource, X as editPart, Y as svgToCanvas, Z as formatLayout, _ as legend, a as render, at as JsonResult, b as tables, c as treeview, d as gantt, et as setProp, f as mindmap, g as sequence, h as timeline, i as hash, it as DiagramJSON, j as NODE_PROPS, k as ENUMS, l as kanban, m as chart, n as Options, nt as writeLayout, o as toSource, ot as fromJSON, p as git, q as embedFonts, r as Result, rt as writePanelDrag, s as builtins, st as renderSvg, t as InputFormat, tt as setSetting, u as quadrant, v as footer, w as shapes, x as charts, y as frames, z as MdBlock } from "./index-xVW43gqW.js";
3
+ export { 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, 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_VALUES, SHAPES, type Seg, type ShapeKind, type ShapeName, type Side, type SourceRef, type StatementKind, THEMES, THEME_KEYS, THEME_NAMES, TONES, type Theme, type ThemeInput, type Tok, type TokKind, type YuhwaPlugin, approxMeasure, blockBraces, builtins, canvasMeasure, chart, charts, createTheme, dashFor, editPart, embedFonts, esc, findBlocks, fontFamilies, fontStack, footer, formatLayout, frames, fromJSON, fromMermaid, gantt, getTheme, git, groupPath, 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, render, 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 };
package/dist/index.js CHANGED
@@ -1,3 +1,5 @@
1
- import { A as ENUMS, At as tspans, Bt as createTheme, C as setLineProp, Ct as segsW, D as BOOLS, Ft as THEMES, Gt as isSafeCss, I as lint, It as THEME_KEYS, Jt as ramp, Kt as isSafeLink, Lt as THEME_NAMES, M as NODE_PROPS, N as NUMBERS, Nt as RAMPS, O as COLORS, P as PANEL_PROPS, Rt as TONES, S as serializeProps, T as splitTrailingProps, Ut as getTheme, V as portOn, Y as renderHead, Yt as registerTheme, Z as dashFor, Zt as themeNames, _ as onlyColor, _t as parseInline, a as perPass, bt as renderSegs, c as unuse, d as PANELS, f as SETTING_VALUES, ft as esc, g as lex, h as joinPath, i as optionKind, j as GROUP_PROPS, k as EDGE_PROPS, l as use, m as isYuhwaPath, n as approxMeasure, o as recolor, p as blockBraces, qt as isToneOrHex, r as canvasMeasure, s as registry, tt as lineStyle, u as KNOWN_SETTINGS, v as parse, w as setTrailingProp, y as parseProps, z as SHAPES } from "./plugin-Bs4eiAuz.js";
2
- import { A as chart, B as shapes, C as builtins, D as gantt, E as quadrant, F as frames, I as tables, L as charts, M as sequence, N as legend, O as mindmap, P as footer, R as themes, S as layout, T as kanban, _ as isMermaid, a as findBlocks, b as GRID, c as editPart, d as setPartTone, f as setProp, g as fromMermaid, h as writePanelDrag, i as GUIDE, j as timeline, k as git, l as formatLayout, m as writeLayout, n as render, o as processMarkdown, p as setSetting, r as toSource, s as replaceBlockSource, t as hash, u as setLabel, v as fromJSON, w as treeview, x as groupPath, y as renderSvg, z as markers } from "./src-BjOhvTAB.js";
3
- export { BOOLS, COLORS, EDGE_PROPS, ENUMS, GRID, GROUP_PROPS, GUIDE, KNOWN_SETTINGS, NODE_PROPS, NUMBERS, PANELS, PANEL_PROPS, RAMPS, SETTING_VALUES, SHAPES, THEMES, THEME_KEYS, THEME_NAMES, TONES, approxMeasure, blockBraces, builtins, canvasMeasure, chart, charts, createTheme, dashFor, editPart, esc, findBlocks, footer, formatLayout, frames, fromJSON, fromMermaid, gantt, getTheme, git, groupPath, hash, isMermaid, isSafeCss, isSafeLink, isToneOrHex, isYuhwaPath, joinPath, kanban, layout, legend, lex, lineStyle, lint, markers, mindmap, onlyColor, optionKind, parse, parseInline, parseProps, perPass, portOn, processMarkdown, quadrant, ramp, recolor, registerTheme, registry, render, renderHead, renderSegs, renderSvg, replaceBlockSource, segsW, sequence, serializeProps, setLabel, setLineProp, setPartTone, setProp, setSetting, setTrailingProp, shapes, splitTrailingProps, tables, themeNames, themes, timeline, toSource, treeview, tspans, unuse, use, writeLayout, writePanelDrag };
1
+ import { Bt as getTheme, C as ENUMS, D as PANEL_PROPS, E as NUMBERS, Et as tspans, F as portOn, G as renderHead, Gt as isToneOrHex, Ht as isGenericFont, It as createTheme, Kt as ramp, M as SHAPES, Mt as THEME_KEYS, Nt as THEME_NAMES, Pt as TONES, Rt as fontFamilies, S as EDGE_PROPS, T as NODE_PROPS, Ut as isSafeCss, Wt as isSafeLink, Yt as themeNames, Z as lineStyle, _ as setTrailingProp, b as BOOLS, c as joinPath, ct as esc, d as parse, f as parseProps, g as setLineProp, gt as renderSegs, h as serializeProps, jt as THEMES, k as lint, kt as RAMPS, l as lex, n as PANELS, o as blockBraces, pt as parseInline, q as dashFor, qt as registerTheme, r as SETTING_VALUES, s as isYuhwaPath, t as KNOWN_SETTINGS, u as onlyColor, v as splitTrailingProps, w as GROUP_PROPS, x as COLORS, yt as segsW, zt as fontStack } from "./parse--ljBMU60.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 } from "./plugin-CitzbblK.js";
3
+ import { A as gantt, B as charts, C as GRID, D as treeview, E as builtins, F as sequence, H as markers, I as legend, L as footer, M as git, N as chart, O as kanban, P as timeline, R as frames, S as renderSvg, T as layout, U as shapes, V as themes, _ as writeLayout, a as MD_LANGUAGES, b as isMermaid, d as editPart, f as formatLayout, g as setSetting, h as setProp, i as GUIDE, j as mindmap, k as quadrant, l as processMarkdown, m as setPartTone, n as render, o as findBlocks, p as setLabel, r as toSource, t as hash, u as replaceBlockSource, v as writePanelDrag, w as groupPath, x as fromJSON, y as fromMermaid, z as tables } from "./src-NCXCTK_4.js";
4
+ import { n as embedFonts, r as loadFonts, s as svgToCanvas } from "./raster-iqi6XRPU.js";
5
+ export { BOOLS, COLORS, EDGE_PROPS, ENUMS, GRID, GROUP_PROPS, GUIDE, KNOWN_SETTINGS, MD_LANGUAGES, NODE_PROPS, NUMBERS, PANELS, PANEL_PROPS, RAMPS, SETTING_VALUES, SHAPES, THEMES, THEME_KEYS, THEME_NAMES, TONES, approxMeasure, blockBraces, builtins, canvasMeasure, chart, charts, createTheme, dashFor, editPart, embedFonts, esc, findBlocks, fontFamilies, fontStack, footer, formatLayout, frames, fromJSON, fromMermaid, gantt, getTheme, git, groupPath, 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, render, 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 };
@@ -18,7 +18,7 @@
18
18
  * ```yuhwa file="diagrams/arch.yu" renders that file instead of the block.
19
19
  * `zoom: 'inline'` adds the zoom script to `.md` output only; in `.mdx`, import `yuhwa/zoom`.
20
20
  */
21
- import { t as YuhwaDocsOptions } from "./figure-QAwSU1Ry.js";
21
+ import { t as YuhwaDocsOptions } from "./figure-BLHfxz_e.js";
22
22
  /** replaces every yuhwa fence in `md` with its rendered figure */
23
23
  export declare function renderFences(md: string, opts?: YuhwaDocsOptions, file?: string): string;
24
24
  interface VitePlugin {
package/dist/ironmark.js CHANGED
@@ -1,4 +1,4 @@
1
- import { a as wantsRender, i as toHtml, n as renderBlock, o as zoomTag } from "./node-CLu2Pp_2.js";
1
+ import { a as toHtml, n as renderBlock, o as wantsRender, s as zoomTag } from "./node-CkrQnPFb.js";
2
2
  // src/integrations/ironmark.ts
3
3
  /**
4
4
  * ironmark support: renders ```yuhwa fences before ironmark parses the file.
@@ -1,3 +1,3 @@
1
- import { t as ServerOptions } from "./server--jHjJjOS.js";
2
- import { a as YuhwaService } from "./service-Brvpt7Do.js";
1
+ import { t as ServerOptions } from "./server-DMAOtqqK.js";
2
+ import { a as YuhwaService } from "./service-DimTFsE3.js";
3
3
  export declare function startWorkerServer(opts?: ServerOptions): YuhwaService;
@@ -1,4 +1,5 @@
1
- import { a as __commonJSMin, i as require_api, n as require_api$2, r as require_api$1, t as startServer } from "./server-D6BSNC1P.js";
1
+ import { t as __commonJSMin } from "./rolldown-runtime-CEjnN5Q1.js";
2
+ import { i as require_api, n as require_api$2, r as require_api$1, t as startServer } from "./server-BTYtmr6B.js";
2
3
  // ../../node_modules/.pnpm/vscode-jsonrpc@10.0.0/node_modules/vscode-jsonrpc/lib/browser/ril.js
3
4
  var require_ril = /* @__PURE__ */ __commonJSMin(((exports) => {
4
5
  Object.defineProperty(exports, "__esModule", { value: true });
package/dist/lsp-node.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import { createRequire } from "node:module";
3
- import { A as PLACEMENT_PROPS, B as themeNames, C as COLORS, D as NODE_PROPS, E as GROUP_PROPS, F as spanKey, I as THEME_KEYS, M as SPAN_KEYS, O as NUMBERS, P as parseSpanStyle, R as TONES, S as BOOLS, T as ENUMS, V as table, a as onTypeEdits, b as parse, d as optionKind, g as blockBraces, h as SETTING_VALUES, i as format, j as SHAPES, k as PANEL_PROPS, m as PANELS, n as applyChange, o as tidy, p as KNOWN_SETTINGS, r as diffEdits, s as diskResolve, t as VERSION, v as joinPath, w as EDGE_PROPS, x as serializeProps, y as lex } from "./shared-6aCU_HaV.js";
3
+ import { A as BOOLS, B as SPAN_KEYS, C as blockBraces, D as parse, E as lex, F as NODE_PROPS, H as parseSpanStyle, I as NUMBERS, J as themeNames, K as TONES, L as PANEL_PROPS, M as EDGE_PROPS, N as ENUMS, O as serializeProps, P as GROUP_PROPS, R as PLACEMENT_PROPS, S as SETTING_VALUES, T as joinPath, U as spanKey, W as THEME_KEYS, Y as table, a as formatPage, b as KNOWN_SETTINGS, c as diskResolve, i as format, j as COLORS, n as applyChange, o as onTypeEdits, p as isMarkdown, r as diffEdits, s as tidy, t as VERSION, v as optionKind, x as PANELS, z as SHAPES } from "./shared-h8tkFLY4.js";
4
4
  import { fileURLToPath, pathToFileURL } from "node:url";
5
5
  // \0rolldown/runtime.js
6
6
  var __defProp = Object.defineProperty;
@@ -11535,6 +11535,10 @@ var YuhwaService = class {
11535
11535
  format(text) {
11536
11536
  return diffEdits(text, format(text));
11537
11537
  }
11538
+ /** Edits that format the diagram blocks of a Markdown page. */
11539
+ formatPage(text) {
11540
+ return diffEdits(text, formatPage(text).text);
11541
+ }
11538
11542
  /** Re-indent after a newline or `}` was typed at `pos`. */
11539
11543
  onType(text, pos, ch) {
11540
11544
  return onTypeEdits(text, pos, ch);
@@ -11570,6 +11574,10 @@ var YuhwaService = class {
11570
11574
  *
11571
11575
  * Diagnostics are pulled (`textDocument/diagnostic`) by clients that can, and
11572
11576
  * pushed (`publishDiagnostics`) to the rest, never both.
11577
+ *
11578
+ * Markdown documents (`.md`, `.mdx`, `.markdown`) only get formatting: the
11579
+ * diagram blocks in them are formatted like `.yu` files. Every other feature
11580
+ * sees them as empty. `yuhwa/formatMarkdown` formats a page sent as text.
11573
11581
  */
11574
11582
  const REQUEST_FAILED = -32803;
11575
11583
  const DEBOUNCE_MS = 150;
@@ -11591,7 +11599,10 @@ function startServer(connection, opts = {}) {
11591
11599
  resolve: (p) => docs.get(p) ?? opts.readFile?.(p),
11592
11600
  files: () => [...docs.keys()]
11593
11601
  });
11602
+ const pages = /* @__PURE__ */ new Map();
11594
11603
  const text = (uri) => docs.get(toPath(uri)) ?? "";
11604
+ const isPage = (uri) => isMarkdown(toPath(uri));
11605
+ const pageText = (uri) => pages.get(toPath(uri));
11595
11606
  let pull = false;
11596
11607
  let refresh = false;
11597
11608
  let watch = false;
@@ -11613,6 +11624,7 @@ function startServer(connection, opts = {}) {
11613
11624
  };
11614
11625
  const changed = (uri, src) => {
11615
11626
  const path = toPath(uri);
11627
+ if (isMarkdown(path)) return void (src === void 0 ? pages.delete(path) : pages.set(path, src));
11616
11628
  if (src === void 0) {
11617
11629
  docs.delete(path);
11618
11630
  uris.delete(path);
@@ -11679,7 +11691,7 @@ function startServer(connection, opts = {}) {
11679
11691
  connection.onDidOpenTextDocument((p) => changed(p.textDocument.uri, p.textDocument.text));
11680
11692
  connection.onDidChangeTextDocument((p) => {
11681
11693
  if (!p.contentChanges.length) return;
11682
- changed(p.textDocument.uri, p.contentChanges.reduce((t, ch) => applyChange(t, ch), text(p.textDocument.uri)));
11694
+ changed(p.textDocument.uri, p.contentChanges.reduce((t, ch) => applyChange(t, ch), pageText(p.textDocument.uri) ?? text(p.textDocument.uri)));
11683
11695
  });
11684
11696
  connection.onDidCloseTextDocument((p) => changed(p.textDocument.uri, void 0));
11685
11697
  connection.onDidChangeWatchedFiles(() => {
@@ -11687,46 +11699,54 @@ function startServer(connection, opts = {}) {
11687
11699
  validate();
11688
11700
  });
11689
11701
  connection.onDidChangeConfiguration(() => {});
11690
- connection.languages.diagnostics.on((p) => ({
11702
+ const yu = (none, f) => (p) => {
11703
+ const uri = p.textDocument.uri;
11704
+ return isPage(uri) ? none : f(p, text(uri), toPath(uri));
11705
+ };
11706
+ connection.languages.diagnostics.on(yu({
11691
11707
  kind: "full",
11692
- items: service.diagnostics(text(p.textDocument.uri), toPath(p.textDocument.uri))
11693
- }));
11694
- connection.onDocumentFormatting((p) => service.format(text(p.textDocument.uri)));
11695
- connection.onDocumentOnTypeFormatting((p) => service.onType(text(p.textDocument.uri), p.position, p.ch));
11696
- connection.onCompletion((p) => service.completion(text(p.textDocument.uri), p.position, toPath(p.textDocument.uri)));
11697
- connection.onHover((p) => service.hover(text(p.textDocument.uri), p.position, toPath(p.textDocument.uri)));
11698
- connection.onDefinition((p) => {
11699
- const t = service.definition(text(p.textDocument.uri), p.position, toPath(p.textDocument.uri));
11708
+ items: []
11709
+ }, (_, src, path) => ({
11710
+ kind: "full",
11711
+ items: service.diagnostics(src, path)
11712
+ })));
11713
+ connection.onDocumentFormatting((p) => isPage(p.textDocument.uri) ? service.formatPage(pageText(p.textDocument.uri) ?? "") : service.format(text(p.textDocument.uri)));
11714
+ connection.onRequest("yuhwa/formatMarkdown", (p) => service.formatPage(p.text));
11715
+ connection.onDocumentOnTypeFormatting(yu([], (p, src) => service.onType(src, p.position, p.ch)));
11716
+ connection.onCompletion(yu([], (p, src, path) => service.completion(src, p.position, path)));
11717
+ connection.onHover(yu(null, (p, src, path) => service.hover(src, p.position, path)));
11718
+ connection.onDefinition(yu(null, (p, src, path) => {
11719
+ const t = service.definition(src, p.position, path);
11700
11720
  return t && {
11701
11721
  uri: t.file ? uris.get(t.file) ?? toUri(t.file) : p.textDocument.uri,
11702
11722
  range: t.range
11703
11723
  };
11704
- });
11705
- connection.onReferences((p) => service.references(text(p.textDocument.uri), p.position, toPath(p.textDocument.uri), p.context.includeDeclaration).map((range) => ({
11724
+ }));
11725
+ connection.onReferences(yu([], (p, src, path) => service.references(src, p.position, path, p.context.includeDeclaration).map((range) => ({
11706
11726
  uri: p.textDocument.uri,
11707
11727
  range
11708
- })));
11709
- connection.onDocumentHighlight((p) => service.highlights(text(p.textDocument.uri), p.position, toPath(p.textDocument.uri)));
11710
- connection.onDocumentSymbol((p) => service.symbols(text(p.textDocument.uri), toPath(p.textDocument.uri)));
11711
- connection.languages.semanticTokens.on((p) => service.semanticTokens(text(p.textDocument.uri), toPath(p.textDocument.uri)));
11712
- connection.onFoldingRanges((p) => service.folding(text(p.textDocument.uri), toPath(p.textDocument.uri)));
11713
- connection.onPrepareRename((p) => {
11714
- const r = service.prepareRename(text(p.textDocument.uri), p.position, toPath(p.textDocument.uri));
11728
+ }))));
11729
+ connection.onDocumentHighlight(yu([], (p, src, path) => service.highlights(src, p.position, path)));
11730
+ connection.onDocumentSymbol(yu([], (_, src, path) => service.symbols(src, path)));
11731
+ connection.languages.semanticTokens.on(yu({ data: [] }, (_, src, path) => service.semanticTokens(src, path)));
11732
+ connection.onFoldingRanges(yu([], (_, src, path) => service.folding(src, path)));
11733
+ connection.onPrepareRename(yu(null, (p, src, path) => {
11734
+ const r = service.prepareRename(src, p.position, path);
11715
11735
  if ("error" in r) throw new import_api.ResponseError(REQUEST_FAILED, r.error);
11716
11736
  return r;
11717
- });
11718
- connection.onRenameRequest((p) => {
11719
- const r = service.rename(text(p.textDocument.uri), p.position, p.newName, toPath(p.textDocument.uri));
11737
+ }));
11738
+ connection.onRenameRequest(yu(null, (p, src, path) => {
11739
+ const r = service.rename(src, p.position, p.newName, path);
11720
11740
  if ("error" in r) throw new import_api.ResponseError(REQUEST_FAILED, r.error);
11721
11741
  return { changes: { [p.textDocument.uri]: r } };
11722
- });
11723
- connection.onCodeAction((p) => service.fixes(text(p.textDocument.uri), p.context.diagnostics).map((f) => ({
11742
+ }));
11743
+ connection.onCodeAction(yu([], (p, src) => service.fixes(src, p.context.diagnostics).map((f) => ({
11724
11744
  title: f.title,
11725
11745
  kind: "quickfix",
11726
11746
  diagnostics: [f.diagnostic],
11727
11747
  isPreferred: true,
11728
11748
  edit: { changes: { [p.textDocument.uri]: f.edits } }
11729
- })));
11749
+ }))));
11730
11750
  connection.listen();
11731
11751
  return service;
11732
11752
  }
@@ -5,6 +5,10 @@
5
5
  *
6
6
  * Diagnostics are pulled (`textDocument/diagnostic`) by clients that can, and
7
7
  * pushed (`publishDiagnostics`) to the rest, never both.
8
+ *
9
+ * Markdown documents (`.md`, `.mdx`, `.markdown`) only get formatting: the
10
+ * diagram blocks in them are formatted like `.yu` files. Every other feature
11
+ * sees them as empty. `yuhwa/formatMarkdown` formats a page sent as text.
8
12
  */
9
- import { n as startServer, t as ServerOptions } from "./server--jHjJjOS.js";
13
+ import { n as startServer, t as ServerOptions } from "./server-DMAOtqqK.js";
10
14
  export { ServerOptions, startServer };
@@ -1 +1 @@
1
- export { t as startServer } from "./server-D6BSNC1P.js";
1
+ export { t as startServer } from "./server-BTYtmr6B.js";
package/dist/lsp.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { a as YuhwaService, i as Target, n as SEMANTIC_LEGEND, r as ServiceOptions, t as Fix } from "./service-Brvpt7Do.js";
1
+ import { a as YuhwaService, i as Target, n as SEMANTIC_LEGEND, r as ServiceOptions, t as Fix } from "./service-DimTFsE3.js";
2
2
  import { H as Position, U as Range, nt as TextEdit } from "./main-DYrwpkoa.js";
3
3
  /** Format yuhwa source. Returns the new text; whitespace is all that changes. */
4
4
  export declare function format(text: string): string;
package/dist/lsp.js CHANGED
@@ -1 +1 @@
1
- export { t as SEMANTIC_LEGEND, n as YuhwaService, r as applyChange, i as closeIndent, a as diffEdits, o as enterEdit, s as format, c as newlineIndent, l as newlinePrefix, u as offsetAt, d as onTypeEdits, f as positionAt, p as shiftLines } from "./service-D7DNWBAU.js";
1
+ export { t as SEMANTIC_LEGEND, n as YuhwaService, r as applyChange, i as closeIndent, a as diffEdits, o as enterEdit, s as format, c as newlineIndent, l as newlinePrefix, u as offsetAt, d as onTypeEdits, f as positionAt, p as shiftLines } from "./service-C60VdeKS.js";
@@ -9,7 +9,7 @@
9
9
  * A fence with `no-render` (```yuhwa no-render) stays a code block.
10
10
  * ```yuhwa file="diagrams/arch.yu" renders that file instead of the block.
11
11
  */
12
- import { t as YuhwaDocsOptions } from "./figure-QAwSU1Ry.js";
12
+ import { t as YuhwaDocsOptions } from "./figure-BLHfxz_e.js";
13
13
  type Rule = (tokens: any[], idx: number, options: any, env: any, self: any) => string;
14
14
  interface MarkdownIt {
15
15
  renderer: {
@@ -1,4 +1,5 @@
1
- import { a as wantsRender, i as toHtml, n as renderBlock, o as zoomTag } from "./node-CLu2Pp_2.js";
1
+ import { a as toHtml, n as renderBlock, o as wantsRender, s as zoomTag } from "./node-CkrQnPFb.js";
2
+ import { a as MD_LANGUAGES } from "./src-NCXCTK_4.js";
2
3
  // src/integrations/markdown-it.ts
3
4
  /**
4
5
  * markdown-it plugin: renders ```yuhwa fences at build time.
@@ -17,11 +18,12 @@ function fileOf(env) {
17
18
  }
18
19
  function yuhwaMarkdownIt(md, opts = {}) {
19
20
  const fence = md.renderer.rules.fence;
21
+ const languages = opts.languages ?? MD_LANGUAGES;
20
22
  md.renderer.rules.fence = (tokens, idx, options, env, self) => {
21
23
  const token = tokens[idx];
22
24
  const [lang, ...meta] = token.info.trim().split(/\s+/);
23
- if (!wantsRender(lang, meta.join(" "), opts.languages)) {
24
- if (lang && (opts.languages ?? ["yuhwa"]).includes(lang)) token.info = lang;
25
+ if (!wantsRender(lang, meta.join(" "), languages)) {
26
+ if (lang && languages.includes(lang)) token.info = "yuhwa";
25
27
  return fence(tokens, idx, options, env, self);
26
28
  }
27
29
  const file = fileOf(env);
@@ -1,9 +1,61 @@
1
1
  import { readFileSync, realpathSync } from "node:fs";
2
2
  import { basename, dirname, isAbsolute, join, relative, resolve } from "node:path";
3
- import { $t as table, m as isYuhwaPath } from "./plugin-Bs4eiAuz.js";
4
- import { n as render } from "./src-BjOhvTAB.js";
5
- import { n as zoomScript } from "./zoom-script-CVdAzMhX.js";
6
- import { t as zoomHeight } from "./zoom-QeqB6QlH.js";
3
+ import { en as table, s as isYuhwaPath } from "./parse--ljBMU60.js";
4
+ import { a as MD_LANGUAGES, n as render } from "./src-NCXCTK_4.js";
5
+ import { n as zoomScript } from "./zoom-script-CaJ5MNUw.js";
6
+ import { t as zoomHeight } from "./zoom-yxhxX16c.js";
7
+ import { o as svgSize, t as base64 } from "./raster-iqi6XRPU.js";
8
+ import { t as svgDataUri } from "./svg-uri-Dx8SGV-n.js";
9
+ // src/integrations/png.ts
10
+ let resvg;
11
+ function builtin(id) {
12
+ const get = globalThis.process?.getBuiltinModule;
13
+ if (!get) throw new Error("PNG output needs Node 22.3 or later");
14
+ return get(id);
15
+ }
16
+ const pathCache = /* @__PURE__ */ new Map();
17
+ /** `fonts` checked and sorted into files and folders, once per list: a site build draws many diagrams */
18
+ function fontPaths(fonts) {
19
+ const key = fonts.join("\0");
20
+ const hit = pathCache.get(key);
21
+ if (hit) return hit;
22
+ const { existsSync, statSync } = builtin("node:fs");
23
+ const { resolve } = builtin("node:path");
24
+ const paths = {
25
+ fontFiles: [],
26
+ fontDirs: []
27
+ };
28
+ for (const f of fonts) {
29
+ if (!existsSync(f)) throw new Error(`no such font file or folder: ${f}`);
30
+ if (/\.woff2?$/i.test(f)) throw new Error(`PNG output reads ttf, otf and ttc fonts, not woff: ${f}`);
31
+ (statSync(f).isDirectory() ? paths.fontDirs : paths.fontFiles).push(resolve(f));
32
+ }
33
+ pathCache.set(key, paths);
34
+ return paths;
35
+ }
36
+ function svgToPng(svg, { scale = 2, fonts = [], systemFonts = true } = {}) {
37
+ if (!(scale > 0)) throw new Error("the PNG scale must be a number above 0");
38
+ if (!resvg) {
39
+ const { createRequire } = builtin("node:module");
40
+ try {
41
+ resvg = createRequire(import.meta.url)("@resvg/resvg-js").Resvg;
42
+ } catch {
43
+ throw new Error("PNG output needs @resvg/resvg-js: npm install -D @resvg/resvg-js, or pnpm add -D @resvg/resvg-js");
44
+ }
45
+ }
46
+ const { fontFiles, fontDirs } = fontPaths(fonts);
47
+ return new resvg(svg, {
48
+ fitTo: {
49
+ mode: "zoom",
50
+ value: scale
51
+ },
52
+ font: {
53
+ loadSystemFonts: systemFonts,
54
+ fontFiles,
55
+ fontDirs
56
+ }
57
+ }).render().asPng();
58
+ }
7
59
  // src/integrations/figure.ts
8
60
  /**
9
61
  * Shared core of the docs integrations (markdown-it, remark, Astro, VuePress):
@@ -20,7 +72,6 @@ const el = (tagName, properties, children = []) => ({
20
72
  properties,
21
73
  children
22
74
  });
23
- const dataUri = (svg) => `data:image/svg+xml,${encodeURIComponent(svg)}`;
24
75
  const where = (at) => `${at.file ?? "markdown"}${at.line ? `:${at.line}` : ""}${at.diagram ? ` (${at.diagram})` : ""}`;
25
76
  function errorMessage(errors, at) {
26
77
  return `yuhwa block at ${where(at)}:\n${errors.map((d) => ` line ${d.line}: ${d.message}`).join("\n")}`;
@@ -66,13 +117,33 @@ function fenceZoom(meta, opts = {}) {
66
117
  zoomHeight: m[2] ?? m[3] ?? m[4] ?? opts.zoomHeight
67
118
  };
68
119
  }
120
+ /**
121
+ * `output=img`, `output=png` or `output=canvas` in a fence's meta, over the
122
+ * options. A fence cannot pick `svg`: MDX and Vue-based sites cannot take it.
123
+ */
124
+ function fenceOutput(meta, opts = {}) {
125
+ return /(?:^|\s)output=(img|png|canvas)(?=\s|$)/.exec(meta ?? "")?.[1] ?? opts.output;
126
+ }
69
127
  /** the pan and zoom script as an inline `<script>`, once per page */
70
128
  const zoomTag = () => el("script", {}, [{
71
129
  type: "text",
72
130
  value: zoomScript
73
131
  }]);
132
+ /**
133
+ * The modules a site loads in its client code for these options: the
134
+ * stylesheet, the pan and zoom script with `zoom`, and the canvas script,
135
+ * which any fence can ask for with `output=canvas` (it does nothing without
136
+ * such a figure).
137
+ */
138
+ function clientImports(opts = {}) {
139
+ return [
140
+ "yuhwa/style.css",
141
+ ...opts.zoom ? ["yuhwa/zoom"] : [],
142
+ "yuhwa/canvas"
143
+ ];
144
+ }
74
145
  function renderFigure(source, opts = {}, at = {}) {
75
- const { theme, darkTheme = "midnight", darkMode = "class", output = "img", strict = true, languages: _, root: __, zoom, zoomHeight: zoomHeightOpt, ...rest } = opts;
146
+ const { theme, darkTheme = "midnight", darkMode = "class", output = "img", png, strict = true, languages: _, root: __, zoom, zoomHeight: zoomHeightOpt, ...rest } = opts;
76
147
  const base = {
77
148
  ...rest,
78
149
  file: at.diagram ?? at.file
@@ -89,9 +160,12 @@ function renderFigure(source, opts = {}, at = {}) {
89
160
  theme: darkTheme
90
161
  }) : void 0;
91
162
  const children = [];
163
+ const asPng = output === "png";
164
+ const src = (svg) => asPng ? `data:image/png;base64,${base64(svgToPng(svg, png))}` : svgDataUri(svg);
92
165
  const img = (svg, cls) => el("img", {
93
- src: dataUri(svg),
166
+ src: src(svg),
94
167
  alt,
168
+ width: asPng ? svgSize(svg).width : void 0,
95
169
  className: cls,
96
170
  loading: "lazy",
97
171
  decoding: "async"
@@ -102,9 +176,9 @@ function renderFigure(source, opts = {}, at = {}) {
102
176
  }]);
103
177
  const one = output === "svg" ? inline : img;
104
178
  if (!dark) children.push(one(light.svg, ["yuhwa-svg"]));
105
- else if (darkMode === "media" && output === "img") children.push(el("picture", {}, [el("source", {
179
+ else if (darkMode === "media" && (output === "img" || asPng)) children.push(el("picture", {}, [el("source", {
106
180
  media: "(prefers-color-scheme: dark)",
107
- srcSet: dataUri(dark.svg)
181
+ srcSet: src(dark.svg)
108
182
  }), img(light.svg, ["yuhwa-svg"])]));
109
183
  else children.push(one(light.svg, ["yuhwa-svg", "yuhwa-light"]), one(dark.svg, ["yuhwa-svg", "yuhwa-dark"]));
110
184
  if (zoom) children.splice(0, children.length, el("div", { className: ["yuhwa-view"] }, [...children]));
@@ -116,7 +190,8 @@ function renderFigure(source, opts = {}, at = {}) {
116
190
  const hast = el("figure", {
117
191
  className: ["yuhwa"],
118
192
  dataYuhwa: "",
119
- dataZoom: height
193
+ dataZoom: height,
194
+ dataRender: output === "canvas" ? "canvas" : void 0
120
195
  }, children);
121
196
  return {
122
197
  hast,
@@ -128,7 +203,8 @@ const ATTR = table({
128
203
  className: "class",
129
204
  srcSet: "srcset",
130
205
  dataYuhwa: "data-yuhwa",
131
- dataZoom: "data-zoom"
206
+ dataZoom: "data-zoom",
207
+ dataRender: "data-render"
132
208
  });
133
209
  const escape = (s) => s.replace(/[&<>"]/g, (c) => ({
134
210
  "&": "&amp;",
@@ -146,7 +222,7 @@ function toHtml(node, raw = false, parent = "") {
146
222
  return `<${node.tagName}${attrs}>${inner}</${node.tagName}>`;
147
223
  }
148
224
  /** `yuhwa no-render` (or any flag list) on a fence: leave it as a code block */
149
- function wantsRender(lang, meta, languages = ["yuhwa"]) {
225
+ function wantsRender(lang, meta, languages = MD_LANGUAGES) {
150
226
  return !!lang && languages.includes(lang) && !/(^|\s)no-render(\s|$)/.test(meta ?? "");
151
227
  }
152
228
  // src/integrations/node.ts
@@ -215,6 +291,7 @@ function renderBlock(body, meta, opts, at) {
215
291
  return renderFigure(source, {
216
292
  ...opts,
217
293
  ...fenceZoom(meta, opts),
294
+ output: fenceOutput(meta, opts),
218
295
  resolve: resolve$1
219
296
  }, block);
220
297
  } catch (e) {
@@ -222,4 +299,4 @@ function renderBlock(body, meta, opts, at) {
222
299
  throw e;
223
300
  }
224
301
  }
225
- export { wantsRender as a, toHtml as i, renderBlock as n, zoomTag as o, errorMessage as r, diskResolve as t };
302
+ export { toHtml as a, errorMessage as i, renderBlock as n, wantsRender as o, clientImports as r, zoomTag as s, diskResolve as t };