yuhwa 1.0.2 → 1.2.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 (51) hide show
  1. package/README.md +13 -12
  2. package/client.d.ts +9 -1
  3. package/dist/astro.d.ts +2 -2
  4. package/dist/astro.js +8 -1
  5. package/dist/browser.d.ts +11 -5
  6. package/dist/browser.js +27 -7
  7. package/dist/cli.js +612 -49
  8. package/dist/editor/assets/index-BphHLTvA.js +689 -0
  9. package/dist/editor/assets/lsp.worker-sZtzIA6-.js +30 -0
  10. package/dist/editor/index.html +5 -4
  11. package/dist/figure-CA2hy0xh.d.ts +48 -0
  12. package/dist/{index-Dl845tUQ.d.ts → index-CnnoZYl0.d.ts} +76 -7
  13. package/dist/index.d.ts +2 -2
  14. package/dist/index.js +1 -1
  15. package/dist/ironmark.d.ts +4 -2
  16. package/dist/ironmark.js +18 -7
  17. package/dist/llms.txt +26 -17
  18. package/dist/lsp-browser.d.ts +2 -2
  19. package/dist/lsp-browser.js +1 -1
  20. package/dist/lsp-node.js +208 -212
  21. package/dist/lsp-server.d.ts +1 -1
  22. package/dist/lsp-server.js +1 -1
  23. package/dist/lsp.d.ts +44 -2
  24. package/dist/lsp.js +1 -1
  25. package/dist/markdown-it.d.ts +2 -1
  26. package/dist/markdown-it.js +7 -6
  27. package/dist/node-Bzn2uKXZ.js +224 -0
  28. package/dist/remark.d.ts +2 -1
  29. package/dist/remark.js +16 -5
  30. package/dist/{server-DJC_fQMe.d.ts → server--jHjJjOS.d.ts} +2 -2
  31. package/dist/{server-DmQuHQrG.js → server-Dxo7OG8K.js} +19 -2
  32. package/dist/{service-BYS9Qfkq.js → service-B1fpOg_L.js} +348 -44
  33. package/dist/{service-ClZ8clSQ.d.ts → service-Brvpt7Do.d.ts} +3 -1
  34. package/dist/{shared-qo_r6RUN.js → shared-Ddw88O9D.js} +3069 -742
  35. package/dist/{src-wk7tBpWs.js → src-DkQj7aIV.js} +2842 -744
  36. package/dist/style.css +14 -0
  37. package/dist/vite.d.ts +1 -1
  38. package/dist/vite.js +19 -12
  39. package/dist/vuepress.d.ts +3 -1
  40. package/dist/vuepress.js +7 -2
  41. package/dist/yuhwa.iife.js +91 -75
  42. package/dist/zoom-CCSUbX1X.d.ts +49 -0
  43. package/dist/zoom-QeqB6QlH.js +275 -0
  44. package/dist/zoom-script-CVdAzMhX.js +51 -0
  45. package/dist/zoom.d.ts +35 -0
  46. package/dist/zoom.js +19 -0
  47. package/package.json +10 -2
  48. package/dist/editor/assets/index-BQLsumas.js +0 -587
  49. package/dist/editor/assets/lsp.worker-RlPj9blG.js +0 -26
  50. package/dist/figure-BZHIKnxv.d.ts +0 -27
  51. package/dist/node-Bneu5eJV.js +0 -108
package/README.md CHANGED
@@ -28,7 +28,7 @@ with a visual editor that writes your tweaks back into the source.
28
28
  </div>
29
29
 
30
30
  <details>
31
- <summary><b>The source of this picture</b>: one <code>.yuhwa</code> file</summary>
31
+ <summary><b>The source of this picture</b>: one <code>.yu</code> file</summary>
32
32
 
33
33
  ```yuhwa
34
34
  title: How **yuhwa** works
@@ -41,7 +41,7 @@ footer: `npx yuhwa render` | 0 runtime deps | light + dark | {green: 0 diagnosti
41
41
  .tool [blue]
42
42
  .you [purple]
43
43
 
44
- src "1. Write text" .you [frame: window diagram.yuhwa] {
44
+ src "1. Write text" .you [frame: window diagram.yu] {
45
45
  web -> api -> db
46
46
  db [cylinder, amber]
47
47
  api -> cache: read [dashed]
@@ -49,7 +49,7 @@ src "1. Write text" .you [frame: window diagram.yuhwa] {
49
49
 
50
50
  group yuhwa "yuhwa" [blue, dashed] {
51
51
  cli "2. Render" .tool [frame: terminal ~/docs, meta: 1ms] {
52
- $$ yuhwa render diagram.yuhwa
52
+ $$ yuhwa render diagram.yu
53
53
  ✓ parse || [[green: ok]]
54
54
  ✓ layout || [[green: ok]]
55
55
  ✓ route || [[green: ok]]
@@ -129,24 +129,24 @@ above and change something. Drag a box and watch the source update.
129
129
  fetch the CLI (Node.js 22+):
130
130
 
131
131
  ```bash
132
- echo 'web "Web app" -> api "API" -> db "Postgres" [cylinder]' > hello.yuhwa
132
+ echo 'web "Web app" -> api "API" -> db "Postgres" [cylinder]' > hello.yu
133
133
 
134
- npx yuhwa render hello.yuhwa -o hello.svg # npm
135
- pnpm dlx yuhwa render hello.yuhwa -o hello.svg # pnpm
134
+ npx yuhwa render hello.yu -o hello.svg # npm
135
+ pnpm dlx yuhwa render hello.yu -o hello.svg # pnpm
136
136
  ```
137
137
 
138
138
  **3. Edit it visually and check it:**
139
139
 
140
140
  ```bash
141
- npx yuhwa edit hello.yuhwa # visual editor, saves back to the file
142
- npx yuhwa check hello.yuhwa # diagnostics, exit 1 on errors
141
+ npx yuhwa edit hello.yu # visual editor, saves back to the file
142
+ npx yuhwa check hello.yu # diagnostics, exit 1 on errors
143
143
  ```
144
144
 
145
145
  **4. Keep it around.** Install globally to drop the `npx`, or add it to a
146
146
  project:
147
147
 
148
148
  ```bash
149
- npm install -g yuhwa # or: pnpm add -g yuhwa
149
+ npm install -g yuhwa # adds the `yu` and `yuhwa` commands
150
150
  pnpm add -D yuhwa # or: npm install -D yuhwa
151
151
  ```
152
152
 
@@ -173,7 +173,8 @@ Full reference: [syntax](https://ph1p.github.io/yuhwa/guide/syntax) ·
173
173
  Positions land in the source as a small `layout { }` block, so the diagram
174
174
  stays put on every re-render and in every diff.
175
175
  - **One language, every diagram.** Flowcharts, sequence, timeline, gantt,
176
- kanban, mindmap, quadrant, git history and charts, side by side in one file.
176
+ kanban, mindmap, quadrant, file trees, git history and charts, side by side
177
+ in one file.
177
178
  - **Built for docs.** Plugins for VitePress, Astro, Docusaurus, VuePress, MDX
178
179
  and more. Light and dark variants, and a broken diagram fails the build.
179
180
  - **Built for AI agents.** `yuhwa guide` prints the language reference.
@@ -245,7 +246,7 @@ Also: an [HTTP render service](https://ph1p.github.io/yuhwa/guide/embedding) for
245
246
 
246
247
  ```bash
247
248
  npx yuhwa guide # language reference, written for agents
248
- npx yuhwa check x.yuhwa --json # diagnostics that name the fix
249
+ npx yuhwa check x.yu --json # diagnostics that name the fix
249
250
  ```
250
251
 
251
252
  Point your agent at `yuhwa guide`, let it write source, loop on `check --json`
@@ -259,7 +260,7 @@ completion, hover, rename, formatting and semantic colouring.
259
260
 
260
261
  - **VS Code, Cursor, VSCodium:** the extension in [`packages/vscode`](https://github.com/ph1p/yuhwa/blob/main/packages/vscode) bundles the server.
261
262
  - **Zed:** extension in [`packages/zed`](https://github.com/ph1p/yuhwa/blob/main/packages/zed).
262
- - **Neovim, Helix, Sublime, Emacs, JetBrains, Vim, Kate:** point the editor at `yuhwa-lsp --stdio` for `.yuhwa` files.
263
+ - **Neovim, Helix, Sublime, Emacs, JetBrains, Vim, Kate:** point the editor at `yuhwa-lsp --stdio` for `.yu` files.
263
264
 
264
265
  Per-editor config: [editor setup](https://ph1p.github.io/yuhwa/guide/lsp).
265
266
 
package/client.d.ts CHANGED
@@ -1,5 +1,13 @@
1
- // Types for `.yuhwa` imports through `yuhwa/vite`.
1
+ // Types for `.yu` imports through `yuhwa/vite`.
2
2
  // Reference once: /// <reference types="yuhwa/client" />
3
+ declare module '*.yu' {
4
+ const svg: string;
5
+ export default svg;
6
+ export const darkSvg: string;
7
+ export const source: string;
8
+ export const title: string;
9
+ }
10
+
3
11
  declare module '*.yuhwa' {
4
12
  const svg: string;
5
13
  export default svg;
package/dist/astro.d.ts CHANGED
@@ -1,11 +1,11 @@
1
- import { t as YuhwaDocsOptions } from "./figure-BZHIKnxv.js";
1
+ import { t as YuhwaDocsOptions } from "./figure-CA2hy0xh.js";
2
2
  interface SetupParams {
3
3
  updateConfig: (config: {
4
4
  markdown: {
5
5
  remarkPlugins: unknown[];
6
6
  };
7
7
  }) => unknown;
8
- injectScript: (stage: "page-ssr", content: string) => void;
8
+ injectScript: (stage: "page-ssr" | "page", content: string) => void;
9
9
  }
10
10
  export interface AstroIntegration {
11
11
  name: string;
package/dist/astro.js CHANGED
@@ -7,13 +7,20 @@ import remarkYuhwa from "./remark.js";
7
7
  * // astro.config.mjs
8
8
  * import yuhwa from 'yuhwa/astro';
9
9
  * export default defineConfig({ integrations: [starlight({...}), yuhwa()] });
10
+ *
11
+ * `yuhwa({ zoom: true })` also loads the pan and zoom script.
10
12
  */
11
13
  function yuhwa(opts = {}) {
14
+ const docs = opts.zoom ? {
15
+ ...opts,
16
+ zoom: true
17
+ } : opts;
12
18
  return {
13
19
  name: "yuhwa",
14
20
  hooks: { "astro:config:setup": ({ updateConfig, injectScript }) => {
15
- updateConfig({ markdown: { remarkPlugins: [[remarkYuhwa, opts]] } });
21
+ updateConfig({ markdown: { remarkPlugins: [[remarkYuhwa, docs]] } });
16
22
  injectScript("page-ssr", `import 'yuhwa/style.css';`);
23
+ if (opts.zoom) injectScript("page", `import 'yuhwa/zoom';`);
17
24
  } }
18
25
  };
19
26
  }
package/dist/browser.d.ts CHANGED
@@ -5,21 +5,27 @@
5
5
  * custom element:
6
6
  *
7
7
  * <yuhwa-diagram theme="midnight">a -> b -> c</yuhwa-diagram>
8
- * <yuhwa-diagram src="docs/arch.yuhwa"></yuhwa-diagram>
8
+ * <yuhwa-diagram src="docs/arch.yu"></yuhwa-diagram>
9
+ * <yuhwa-diagram src="big.yu" zoom="480px"></yuhwa-diagram> // pan and zoom
9
10
  * el.source = 'a -> b' // re-renders
10
11
  */
11
- import { $ as PANELS, $t as PanelCtx, A as MdBlock, An as isSafeLink, At as Layout, B as setProp, Bt as PartEdit, C as NODE_PROPS, Cn as THEME_NAMES, Ct as GroupDecl, D as ConvertResult, Dn as createTheme, Dt as LaidGroup, E as lint, En as ThemeInput, Et as LaidEdge, F as replaceBlockSource, Fn as approxMeasure, Ft as PanelHandle, G as lineStyle, Gt as ShapeName, H as writeLayout, Ht as Props, I as editPart, In as canvasMeasure, It as PanelOverride, J as JsonResult, Jt as GRID, K as SHAPES, Kt as Side, L as formatLayout, Lt as PanelPart, M as MdResult, Mn as ramp, Mt as NodeDecl, N as findBlocks, Nn as registerTheme, Nt as NodeOverride, O as fromMermaid, On as getTheme, Ot as LaidNode, P as processMarkdown, Pn as themeNames, Pt as PanelDecl, Q as LexedLine, Qt as FrameKind, R as setLabel, Rt as PartAction, S as GROUP_PROPS, Sn as THEME_KEYS, St as EdgeOverride, T as PANEL_PROPS, Tn as Theme, Tt as LabelRef, U as writePanelDrag, Ut as ResolvedEdgeStyle, V as setSetting, Vt as Point, W as dashFor, Wt as ResolvedNodeStyle, X as renderSvg, Xt as layout, Y as fromJSON, Yt as groupPath, Z as KNOWN_SETTINGS, Zt as Decoration, _ as themes, _n as segsW, _t as Curve, an as YuhwaPlugin, at as isYuhwaPath, b as EDGE_PROPS, bn as RAMPS, bt as Direction, c as git, cn as registry, ct as onlyColor, d as sequence, dn as ShapeKind, dt as serializeProps, en as PanelKind, et as ParseOptions, f as legend, fn as renderHead, ft as setLineProp, g as charts, gn as renderSegs, gt as Component, h as tables, hn as parseInline, ht as Box, i as hash, in as StatementKind, it as blockBraces, j as MdOptions, jn as isToneOrHex, jt as LayoutOverrides, k as isMermaid, kn as isSafeCss, kt as LaidPanel, l as chart, ln as use, lt as parse, m as frames, mn as Seg, mt as splitTrailingProps, n as Options, nn as RowKind, nt as Tok, o as toSource, on as perPass, ot as joinPath, p as footer, pn as InkColors, pt as setTrailingProp, q as DiagramJSON, qt as SourceRef, r as Result, rn as RowPaint, rt as TokKind, s as builtins, sn as recolor, st as lex, t as InputFormat, tn as RowCtx, tt as SETTING_VALUES, u as timeline, un as MarkerKind, ut as parseProps, v as GUIDE, vn as tspans, vt as Diagnostic, w as NUMBERS, wn as TONES, wt as HeadKind, x as ENUMS, xn as THEMES, xt as EdgeDecl, y as BOOLS, yn as LineStyle, yt as Diagram, z as setPartTone, zt as PartChange } from "./index-Dl845tUQ.js";
12
+ import { $ as LexedLine, $t as FrameKind, A as isMermaid, An as ThemeInput, At as LaidPanel, B as setPartTone, Bn as canvasMeasure, Bt as PartChange, C as GROUP_PROPS, Cn as LineStyle, Ct as EdgeOverride, D as lint, Dn as THEME_NAMES, Dt as LaidEdge, E as PANEL_PROPS, En as THEME_KEYS, Et as LabelRef, F as processMarkdown, Fn as isToneOrHex, Ft as PanelDecl, G as dashFor, Gt as ResolvedNodeStyle, H as setSetting, Ht as Point, I as replaceBlockSource, In as ramp, It as PanelHandle, J as DiagramJSON, Jt as SourceRef, K as lineStyle, Kt as ShapeName, L as editPart, Ln as registerTheme, Lt as PanelOverride, M as MdOptions, Mn as getTheme, Mt as LayoutOverrides, N as MdResult, Nn as isSafeCss, Nt as NodeDecl, O as ConvertResult, On as TONES, Ot as LaidGroup, P as findBlocks, Pn as isSafeLink, Pt as NodeOverride, Q as KNOWN_SETTINGS, Qt as Decoration, R as formatLayout, Rn as themeNames, Rt as PanelPart, S as ENUMS, Sn as tspans, St as EdgeDecl, T as NUMBERS, Tn as THEMES, Tt as HeadKind, U as writeLayout, Ut as Props, V as setProp, Vt as PartEdit, W as writePanelDrag, Wt as ResolvedEdgeStyle, X as fromJSON, Xt as groupPath, Y as JsonResult, Yt as GRID, Z as renderSvg, Zt as layout, _ as themes, _n as InkColors, _t as Component, an as RowPaint, at as blockBraces, b as COLORS, bn as renderSegs, bt as Diagram, c as git, cn as optionKind, ct as lex, d as sequence, dn as registry, dt as parseProps, en as PanelCtx, et as PANELS, f as legend, fn as unuse, ft as serializeProps, g as charts, gn as renderHead, gt as Box, h as tables, hn as ShapeKind, ht as splitTrailingProps, i as hash, in as RowKind, it as TokKind, j as MdBlock, jn as createTheme, jt as Layout, k as fromMermaid, kn as Theme, kt as LaidNode, l as chart, ln as perPass, lt as onlyColor, m as frames, mn as MarkerKind, mt as setTrailingProp, n as Options, nn as PanelOption, nt as SETTING_VALUES, o as toSource, on as StatementKind, ot as isYuhwaPath, p as footer, pn as use, pt as setLineProp, q as SHAPES, qt as Side, r as Result, rn as RowCtx, rt as Tok, s as builtins, sn as YuhwaPlugin, st as joinPath, t as InputFormat, tn as PanelKind, tt as ParseOptions, u as timeline, un as recolor, ut as parse, v as GUIDE, vn as Seg, vt as Curve, w as NODE_PROPS, wn as RAMPS, wt as GroupDecl, x as EDGE_PROPS, xn as segsW, xt as Direction, y as BOOLS, yn as parseInline, yt as Diagnostic, z as setLabel, zn as approxMeasure, zt as PartAction } from "./index-CnnoZYl0.js";
13
+ import { i as zoomable, n as Zoomer, r as zoomHeight, t as ZoomOptions } from "./zoom-CCSUbX1X.js";
12
14
  export declare function render(source: string, opts?: Options): Result;
13
15
  /**
14
16
  * Fetches every file that `source` imports, and what those import, so
15
17
  * `render` can resolve them synchronously. Paths join against `file` (a URL
16
- * path such as `/docs/arch.yuhwa`); a file that fails to load is left out and
18
+ * path such as `/docs/arch.yu`); a file that fails to load is left out and
17
19
  * shows up as a diagnostic on its import line.
18
20
  */
19
21
  export declare function fetchImports(source: string, file: string, load?: (path: string) => Promise<string>): Promise<Record<string, string>>;
20
22
  export declare function run(root?: ParentNode, opts?: Options): void;
21
23
  declare const Base: typeof HTMLElement;
22
- /** <yuhwa-diagram [theme] [src]>source</yuhwa-diagram>; fires `yuhwa:render` with the diagnostics */
24
+ /**
25
+ * <yuhwa-diagram [theme] [src] [zoom[=height]] [wheel]>source</yuhwa-diagram>;
26
+ * fires `yuhwa:render` with the diagnostics. `zoom` makes it a pan and zoom
27
+ * viewer, `wheel` lets the plain mouse wheel zoom it.
28
+ */
23
29
  export declare class YuhwaDiagram extends Base {
24
30
  #private;
25
31
  static observedAttributes: string[];
@@ -28,4 +34,4 @@ export declare class YuhwaDiagram extends Base {
28
34
  connectedCallback(): void;
29
35
  attributeChangedCallback(): void;
30
36
  }
31
- export { BOOLS, type Box, 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 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, findBlocks, footer, formatLayout, frames, fromJSON, fromMermaid, getTheme, git, groupPath, hash, isMermaid, isSafeCss, isSafeLink, isToneOrHex, isYuhwaPath, joinPath, layout, legend, lex, lineStyle, lint, onlyColor, parse, parseInline, parseProps, perPass, processMarkdown, ramp, recolor, registerTheme, registry, renderHead, renderSegs, renderSvg, replaceBlockSource, segsW, sequence, serializeProps, setLabel, setLineProp, setPartTone, setProp, setSetting, setTrailingProp, splitTrailingProps, tables, themeNames, themes, timeline, toSource, tspans, use, writeLayout, writePanelDrag };
37
+ 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, type ZoomOptions, type Zoomer, approxMeasure, blockBraces, builtins, canvasMeasure, chart, charts, createTheme, dashFor, editPart, findBlocks, footer, formatLayout, frames, fromJSON, fromMermaid, getTheme, git, groupPath, hash, isMermaid, isSafeCss, isSafeLink, isToneOrHex, isYuhwaPath, joinPath, layout, legend, lex, lineStyle, lint, onlyColor, optionKind, parse, parseInline, parseProps, perPass, processMarkdown, ramp, recolor, registerTheme, registry, renderHead, renderSegs, renderSvg, replaceBlockSource, segsW, sequence, serializeProps, setLabel, setLineProp, setPartTone, setProp, setSetting, setTrailingProp, splitTrailingProps, tables, themeNames, themes, timeline, toSource, tspans, unuse, use, writeLayout, writePanelDrag, zoomHeight, zoomable };
package/dist/browser.js CHANGED
@@ -1,4 +1,5 @@
1
- import { $ as splitTrailingProps, A as canvasMeasure, B as KNOWN_SETTINGS, C as builtins, Ct as isSafeCss, D as sequence, Dt as registerTheme, E as timeline, Et as ramp, F as themes, G as joinPath, H as SETTING_VALUES, I as perPass, J as parse, K as lex, L as recolor, M as frames, N as tables, O as legend, Ot as themeNames, P as charts, Q as setTrailingProp, R as registry, S as layout, St as getTheme, T as chart, Tt as isToneOrHex, U as blockBraces, V as PANELS, W as isYuhwaPath, X as serializeProps, Y as parseProps, Z as setLineProp, _ as isMermaid, _t as THEMES, a as findBlocks, at as NUMBERS, b as GRID, bt as TONES, c as editPart, ct as SHAPES, d as setPartTone, dt as lineStyle, et as BOOLS, f as setProp, ft as parseInline, g as fromMermaid, gt as RAMPS, h as writePanelDrag, ht as tspans, i as GUIDE, it as NODE_PROPS, j as footer, k as approxMeasure, l as formatLayout, lt as renderHead, m as writeLayout, mt as segsW, n as render$1, nt as ENUMS, o as processMarkdown, ot as PANEL_PROPS, p as setSetting, pt as renderSegs, q as onlyColor, r as toSource, rt as GROUP_PROPS, s as replaceBlockSource, st as lint, t as hash, tt as EDGE_PROPS, u as setLabel, ut as dashFor, v as fromJSON, vt as THEME_KEYS, w as git, wt as isSafeLink, x as groupPath, xt as createTheme, y as renderSvg, yt as THEME_NAMES, z as use } from "./src-wk7tBpWs.js";
1
+ import { $ as setLineProp, A as approxMeasure, At as isSafeCss, B as unuse, C as builtins, Ct as RAMPS, D as sequence, Dt as TONES, E as timeline, Et as THEME_NAMES, F as themes, Ft as themeNames, G as blockBraces, H as KNOWN_SETTINGS, I as optionKind, J as lex, K as isYuhwaPath, L as perPass, M as frames, Mt as isToneOrHex, N as tables, Nt as ramp, O as legend, Ot as createTheme, P as charts, Pt as registerTheme, Q as serializeProps, R as recolor, S as layout, St as tspans, T as chart, Tt as THEME_KEYS, U as PANELS, V as use, W as SETTING_VALUES, X as parse, Y as onlyColor, Z as parseProps, _ as isMermaid, _t as parseInline, a as findBlocks, at as ENUMS, b as GRID, bt as segsW, c as editPart, ct as NUMBERS, d as setPartTone, dt as lint, et as setTrailingProp, f as setProp, ft as SHAPES, g as fromMermaid, h as writePanelDrag, ht as lineStyle, i as GUIDE, it as EDGE_PROPS, j as canvasMeasure, jt as isSafeLink, k as footer, kt as getTheme, l as formatLayout, lt as PANEL_PROPS, m as writeLayout, mt as dashFor, n as render$1, nt as BOOLS, o as processMarkdown, ot as GROUP_PROPS, p as setSetting, pt as renderHead, q as joinPath, r as toSource, rt as COLORS, s as replaceBlockSource, st as NODE_PROPS, t as hash, tt as splitTrailingProps, u as setLabel, v as fromJSON, w as git, wt as THEMES, x as groupPath, y as renderSvg, yt as renderSegs, z as registry } from "./src-DkQj7aIV.js";
2
+ import { n as zoomable, t as zoomHeight } from "./zoom-QeqB6QlH.js";
2
3
  // src/browser.ts
3
4
  /**
4
5
  * Drop-in browser runtime: <script src="yuhwa.js"><\/script>
@@ -7,7 +8,8 @@ import { $ as splitTrailingProps, A as canvasMeasure, B as KNOWN_SETTINGS, C as
7
8
  * custom element:
8
9
  *
9
10
  * <yuhwa-diagram theme="midnight">a -> b -> c</yuhwa-diagram>
10
- * <yuhwa-diagram src="docs/arch.yuhwa"></yuhwa-diagram>
11
+ * <yuhwa-diagram src="docs/arch.yu"></yuhwa-diagram>
12
+ * <yuhwa-diagram src="big.yu" zoom="480px"></yuhwa-diagram> // pan and zoom
11
13
  * el.source = 'a -> b' // re-renders
12
14
  */
13
15
  const SELECTOR = "pre > code.language-yuhwa, pre > code.lang-yuhwa, pre.yuhwa, div.yuhwa:not([data-rendered])";
@@ -30,7 +32,7 @@ const IMPORT_RE = /^\s*import\s+(?:\{[^}]*\}\s*from\s+)?"([^"]+)"/gm;
30
32
  /**
31
33
  * Fetches every file that `source` imports, and what those import, so
32
34
  * `render` can resolve them synchronously. Paths join against `file` (a URL
33
- * path such as `/docs/arch.yuhwa`); a file that fails to load is left out and
35
+ * path such as `/docs/arch.yu`); a file that fails to load is left out and
34
36
  * shows up as a diagnostic on its import line.
35
37
  */
36
38
  async function fetchImports(source, file, load = fetchText) {
@@ -67,6 +69,7 @@ function run(root = document, opts = {}) {
67
69
  out.className = "yuhwa";
68
70
  out.dataset.rendered = "true";
69
71
  out.dataset.source = source;
72
+ let ok = false;
70
73
  try {
71
74
  const r = render(source, {
72
75
  theme: host.dataset.theme,
@@ -75,17 +78,28 @@ function run(root = document, opts = {}) {
75
78
  out.innerHTML = r.svg;
76
79
  fit(out.querySelector("svg"));
77
80
  for (const d of r.diagnostics) console.warn(`yuhwa:${d.line}: ${d.message}`);
81
+ ok = true;
78
82
  } catch (e) {
79
83
  out.textContent = `yuhwa error: ${e.message}`;
80
84
  out.style.color = "crimson";
81
85
  }
82
86
  host.replaceWith(out);
87
+ if (ok && host.dataset.zoom !== void 0) zoomable(out, { height: zoomHeight(host.dataset.zoom) });
83
88
  });
84
89
  }
85
90
  const Base = typeof HTMLElement === "undefined" ? class {} : HTMLElement;
86
- /** <yuhwa-diagram [theme] [src]>source</yuhwa-diagram>; fires `yuhwa:render` with the diagnostics */
91
+ /**
92
+ * <yuhwa-diagram [theme] [src] [zoom[=height]] [wheel]>source</yuhwa-diagram>;
93
+ * fires `yuhwa:render` with the diagnostics. `zoom` makes it a pan and zoom
94
+ * viewer, `wheel` lets the plain mouse wheel zoom it.
95
+ */
87
96
  var YuhwaDiagram = class extends Base {
88
- static observedAttributes = ["theme", "src"];
97
+ static observedAttributes = [
98
+ "theme",
99
+ "src",
100
+ "zoom",
101
+ "wheel"
102
+ ];
89
103
  #source = null;
90
104
  #fetched = null;
91
105
  #request = 0;
@@ -135,9 +149,15 @@ var YuhwaDiagram = class extends Base {
135
149
  file: this.#file,
136
150
  resolve: (p) => files[p]
137
151
  });
152
+ this.yuhwaZoom?.destroy();
138
153
  this.innerHTML = r.svg;
139
154
  fit(this.querySelector("svg"));
140
- this.setAttribute("role", "img");
155
+ const zoom = this.getAttribute("zoom");
156
+ this.setAttribute("role", zoom === null ? "img" : "group");
157
+ if (zoom !== null) zoomable(this, {
158
+ height: zoomHeight(zoom),
159
+ wheel: this.hasAttribute("wheel")
160
+ });
141
161
  if (!this.hasAttribute("aria-label") || this.dataset.autoLabel) {
142
162
  const t = r.diagram.settings.title;
143
163
  if (t) this.setAttribute("aria-label", t), this.dataset.autoLabel = "1";
@@ -164,4 +184,4 @@ if (typeof document !== "undefined") {
164
184
  else run();
165
185
  }
166
186
  }
167
- export { BOOLS, 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, YuhwaDiagram, approxMeasure, blockBraces, builtins, canvasMeasure, chart, charts, createTheme, dashFor, editPart, fetchImports, findBlocks, footer, formatLayout, frames, fromJSON, fromMermaid, getTheme, git, groupPath, hash, isMermaid, isSafeCss, isSafeLink, isToneOrHex, isYuhwaPath, joinPath, layout, legend, lex, lineStyle, lint, onlyColor, parse, parseInline, parseProps, perPass, processMarkdown, ramp, recolor, registerTheme, registry, render, renderHead, renderSegs, renderSvg, replaceBlockSource, run, segsW, sequence, serializeProps, setLabel, setLineProp, setPartTone, setProp, setSetting, setTrailingProp, splitTrailingProps, tables, themeNames, themes, timeline, toSource, tspans, use, writeLayout, writePanelDrag };
187
+ 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, YuhwaDiagram, approxMeasure, blockBraces, builtins, canvasMeasure, chart, charts, createTheme, dashFor, editPart, fetchImports, findBlocks, footer, formatLayout, frames, fromJSON, fromMermaid, getTheme, git, groupPath, hash, isMermaid, isSafeCss, isSafeLink, isToneOrHex, isYuhwaPath, joinPath, layout, legend, lex, lineStyle, lint, onlyColor, optionKind, parse, parseInline, parseProps, perPass, processMarkdown, ramp, recolor, registerTheme, registry, render, renderHead, renderSegs, renderSvg, replaceBlockSource, run, segsW, sequence, serializeProps, setLabel, setLineProp, setPartTone, setProp, setSetting, setTrailingProp, splitTrailingProps, tables, themeNames, themes, timeline, toSource, tspans, unuse, use, writeLayout, writePanelDrag, zoomHeight, zoomable };