yuhwa 0.0.0-stage → 1.0.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 (47) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +285 -2
  3. package/client.d.ts +9 -0
  4. package/dist/astro.d.ts +17 -0
  5. package/dist/astro.js +20 -0
  6. package/dist/browser.d.ts +31 -0
  7. package/dist/browser.js +158 -0
  8. package/dist/cli.js +920 -0
  9. package/dist/editor/assets/index-Cnjd5PIx.js +585 -0
  10. package/dist/editor/assets/index-DaWl0OPj.css +1 -0
  11. package/dist/editor/assets/lsp.worker-C79O_uwt.js +26 -0
  12. package/dist/editor/index.html +237 -0
  13. package/dist/figure-CCHRsOjO.d.ts +27 -0
  14. package/dist/index-vqADUsNi.d.ts +1072 -0
  15. package/dist/index.d.ts +2 -0
  16. package/dist/index.js +1 -0
  17. package/dist/ironmark.d.ts +33 -0
  18. package/dist/ironmark.js +73 -0
  19. package/dist/llms.txt +218 -0
  20. package/dist/lsp-browser.d.ts +3 -0
  21. package/dist/lsp-browser.js +343 -0
  22. package/dist/lsp-client.d.ts +34 -0
  23. package/dist/lsp-client.js +98 -0
  24. package/dist/lsp-node.js +11781 -0
  25. package/dist/lsp-server.d.ts +10 -0
  26. package/dist/lsp-server.js +1 -0
  27. package/dist/lsp.d.ts +16 -0
  28. package/dist/lsp.js +1 -0
  29. package/dist/main-DYrwpkoa.d.ts +3280 -0
  30. package/dist/markdown-it.d.ts +21 -0
  31. package/dist/markdown-it.js +36 -0
  32. package/dist/node-BSuTy08h.js +108 -0
  33. package/dist/remark.d.ts +14 -0
  34. package/dist/remark.js +42 -0
  35. package/dist/server-Bl_1n2bb.js +9889 -0
  36. package/dist/server-DJC_fQMe.d.ts +5892 -0
  37. package/dist/service-BAPEZrJQ.js +930 -0
  38. package/dist/service-ClZ8clSQ.d.ts +71 -0
  39. package/dist/shared-BHxDevlD.js +10915 -0
  40. package/dist/src-CAxa6h4u.js +11454 -0
  41. package/dist/style.css +48 -0
  42. package/dist/vite.d.ts +12 -0
  43. package/dist/vite.js +55 -0
  44. package/dist/vuepress.d.ts +20 -0
  45. package/dist/vuepress.js +17 -0
  46. package/dist/yuhwa.iife.js +261 -0
  47. package/package.json +138 -3
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 ph1p
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,286 @@
1
- # Temporary Holding Version
1
+ <div align="center">
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ <img src="https://raw.githubusercontent.com/ph1p/yuhwa/main/.github/assets/logo.svg" width="72" alt="" />
4
+
5
+ # yuhwa
6
+
7
+ **Text diagrams that look good and stay where you put them.**
8
+
9
+ A few lines of text become a clean SVG. A friendlier alternative to Mermaid,
10
+ with a visual editor that writes your tweaks back into the source.
11
+
12
+ [![npm](https://img.shields.io/npm/v/yuhwa?color=2563eb)](https://www.npmjs.com/package/yuhwa)
13
+ [![license](https://img.shields.io/npm/l/yuhwa?color=9333ea)](https://github.com/ph1p/yuhwa/blob/main/LICENSE)
14
+ ![dependencies](https://img.shields.io/badge/runtime%20deps-0-16a34a)
15
+
16
+ [**Try it in the browser**](https://ph1p.github.io/yuhwa/editor/) ·
17
+ [Docs](https://ph1p.github.io/yuhwa/) ·
18
+ [Syntax](https://ph1p.github.io/yuhwa/guide/syntax) ·
19
+ [Examples](https://ph1p.github.io/yuhwa/guide/examples)
20
+
21
+ <br />
22
+
23
+ <picture>
24
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/ph1p/yuhwa/main/.github/assets/hero-dark.svg" />
25
+ <img src="https://raw.githubusercontent.com/ph1p/yuhwa/main/.github/assets/hero-light.svg" alt="How yuhwa works: write text in a window, render it in the terminal, ship the SVG to the browser, tweak it in the visual editor; below it sequence, chart, mindmap, kanban and timeline panels from the same file" width="820" />
26
+ </picture>
27
+
28
+ </div>
29
+
30
+ <details>
31
+ <summary><b>The source of this picture</b>: one <code>.yuhwa</code> file</summary>
32
+
33
+ ```yuhwa
34
+ title: How **yuhwa** works
35
+ subtitle: one text file: graphs, windows, charts, sequences and more
36
+ direction: right
37
+ panels: wrap
38
+ legend: .tool yuhwa | .you You | --> live | ..> writes back
39
+ footer: `npx yuhwa render` | 0 runtime deps | light + dark | {green: 0 diagnostics}
40
+
41
+ .tool [blue]
42
+ .you [purple]
43
+
44
+ src "1. Write text" .you [frame: window diagram.yuhwa] {
45
+ web -> api -> db
46
+ db [cylinder, amber]
47
+ api -> cache: read [dashed]
48
+ }
49
+
50
+ group yuhwa "yuhwa" [blue, dashed] {
51
+ cli "2. Render" .tool [frame: terminal ~/docs, meta: 1ms] {
52
+ $$ yuhwa render diagram.yuhwa
53
+ ✓ parse || [[green: ok]]
54
+ ✓ layout || [[green: ok]]
55
+ ✓ route || [[green: ok]]
56
+ }
57
+ lsp "Language server" .tool [hexagon, sub: "check, hover, format"]
58
+ }
59
+
60
+ site "3. Ship the SVG" [frame: browser docs.example.com, green] {
61
+ stat: 0 deps | 12 themes | 100% text
62
+ ---
63
+ spark green: 3 5 4 6 8 7 9 12
64
+ }
65
+
66
+ edit "Tweak visually" [frame: window yuhwa edit, amber] {
67
+ drag boxes || [[green: on]]
68
+ bend edges || [[green: on]]
69
+ recolour || [[green: on]]
70
+ }
71
+
72
+ src -> cli
73
+ src -> lsp: as you type
74
+ cli -> site: SVG [flow]
75
+ cli --> edit: live preview
76
+ edit ..> src: "writes layout { }"
77
+
78
+ sequence save "Saving a drag" [numbered] {
79
+ actor you "You" [purple]
80
+ you -> editor: drag a box
81
+ editor -> file: write layout { }
82
+ file --> editor: re-render
83
+ }
84
+
85
+ chart speed "Render time" [type: column, unit: ms] {
86
+ checkout [blue]: 0.6
87
+ this picture [purple]: 1.0
88
+ showcase [green]: 2.7
89
+ }
90
+
91
+ mindmap kinds "One language" {
92
+ yuhwa
93
+ graphs
94
+ panels
95
+ sequence
96
+ gantt
97
+ kanban
98
+ cards
99
+ }
100
+
101
+ kanban plan "Docs to draw" {
102
+ Todo
103
+ - auth flow
104
+ - deploy pipeline
105
+ Doing
106
+ - login sequence
107
+ Done
108
+ - architecture
109
+ - README hero
110
+ }
111
+
112
+ timeline ship "Ship it" [direction: right] {
113
+ write [purple]: source
114
+ check [blue]: 0 errors
115
+ tweak [amber]: drag
116
+ render [green]: SVG
117
+ }
118
+ ```
119
+
120
+ </details>
121
+
122
+ ## Get started
123
+
124
+ **1. Try it without installing.** Open the
125
+ [visual editor](https://ph1p.github.io/yuhwa/editor/), paste the source of the picture
126
+ above and change something. Drag a box and watch the source update.
127
+
128
+ **2. Render your first diagram.** No install needed: `npx` or `pnpm dlx`
129
+ fetch the CLI (Node.js 22+):
130
+
131
+ ```bash
132
+ echo 'web "Web app" -> api "API" -> db "Postgres" [cylinder]' > hello.yuhwa
133
+
134
+ npx yuhwa render hello.yuhwa -o hello.svg # npm
135
+ pnpm dlx yuhwa render hello.yuhwa -o hello.svg # pnpm
136
+ ```
137
+
138
+ **3. Edit it visually and check it:**
139
+
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
143
+ ```
144
+
145
+ **4. Keep it around.** Install globally to drop the `npx`, or add it to a
146
+ project:
147
+
148
+ ```bash
149
+ npm install -g yuhwa # or: pnpm add -g yuhwa
150
+ pnpm add -D yuhwa # or: npm install -D yuhwa
151
+ ```
152
+
153
+ ### The syntax in 30 seconds
154
+
155
+ ```yuhwa
156
+ direction: right // a setting
157
+ .svc [blue] // a class
158
+ api "Orders API" .svc // a node: id, label, class
159
+ db [cylinder, amber] // props in brackets
160
+ api -> db: SQL [dashed] // an edge with a label and props
161
+ group core "Core" { api } // a group
162
+ ```
163
+
164
+ Arrows: `->` solid, `-->` dashed, `..>` dotted, `=>` thick, `<->` both ways.
165
+ Full reference: [syntax](https://ph1p.github.io/yuhwa/guide/syntax) ·
166
+ [cheatsheet](https://ph1p.github.io/yuhwa/guide/cheatsheet).
167
+
168
+ ## Why yuhwa
169
+
170
+ - **Looks good with zero styling.** Clean auto-layout, curved routing, soft
171
+ colours. Twelve built-in themes, or define your own in a `theme { }` block.
172
+ - **Layout you control.** Drag boxes and bend edges in the visual editor.
173
+ Positions land in the source as a small `layout { }` block, so the diagram
174
+ stays put on every re-render and in every diff.
175
+ - **One language, every diagram.** Flowcharts, sequence, timeline, gantt,
176
+ kanban, mindmap, quadrant, git history and charts, side by side in one file.
177
+ - **Built for docs.** Plugins for VitePress, Astro, Docusaurus, VuePress, MDX
178
+ and more. Light and dark variants, and a broken diagram fails the build.
179
+ - **Built for AI agents.** `yuhwa guide` prints the language reference.
180
+ `yuhwa check --json` returns diagnostics that name the fix.
181
+ - **Speaks Mermaid.** Mermaid flowcharts render as-is and convert to yuhwa.
182
+ - **Small and deterministic.** TypeScript, no runtime dependencies, same
183
+ input gives the same SVG.
184
+
185
+ <details>
186
+ <summary><b>See everything in one file</b> (the editor's <i>Everything</i> template)</summary>
187
+ <br />
188
+ <img src="https://raw.githubusercontent.com/ph1p/yuhwa/main/.github/assets/showcase.svg" alt="yuhwa showcase: a service graph with cards, plus sequence, chart, quadrant, gantt, timeline, kanban, git and mindmap panels" />
189
+ </details>
190
+
191
+ ## Use it anywhere
192
+
193
+ **In the browser**
194
+
195
+ ```html
196
+ <script src="https://cdn.jsdelivr.net/npm/yuhwa/dist/yuhwa.iife.js"></script>
197
+ <yuhwa-diagram>web -> api -> db [shape: cylinder]</yuhwa-diagram>
198
+ ```
199
+
200
+ **From JavaScript**
201
+
202
+ ```js
203
+ import { render } from 'yuhwa';
204
+
205
+ const { svg, diagnostics } = render('a -> b -> c', { theme: 'midnight' });
206
+ ```
207
+
208
+ `render()` never throws. Problems come back as `diagnostics` with line, message and severity.
209
+
210
+ **In Markdown on GitHub or GitLab**: `npx yuhwa md README.md` renders every
211
+ ` ```yuhwa ` block to an SVG file and links it in ([details](https://ph1p.github.io/yuhwa/guide/markdown)).
212
+
213
+ **In docs sites**: `pnpm add -D yuhwa`, write ` ```yuhwa ` blocks, get SVG
214
+ figures at build time.
215
+
216
+ | site generator | plugin |
217
+ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------- |
218
+ | [VitePress](https://ph1p.github.io/yuhwa/guide/integrations#vitepress), [Eleventy](https://ph1p.github.io/yuhwa/guide/integrations#eleventy), any markdown-it | `yuhwa/markdown-it` |
219
+ | [VuePress 2](https://ph1p.github.io/yuhwa/guide/integrations#vuepress) | `yuhwa/vuepress` |
220
+ | [Astro, Starlight](https://ph1p.github.io/yuhwa/guide/integrations#astro-and-starlight) | `yuhwa/astro` |
221
+ | [Docusaurus](https://ph1p.github.io/yuhwa/guide/integrations#docusaurus), [Vocs](https://ph1p.github.io/yuhwa/guide/integrations#vocs), [Nextra](https://ph1p.github.io/yuhwa/guide/integrations#nextra), [Fumadocs](https://ph1p.github.io/yuhwa/guide/integrations#fumadocs), [Rspress](https://ph1p.github.io/yuhwa/guide/integrations#rspress), any MDX | `yuhwa/remark` |
222
+ | [ironmark](https://ph1p.github.io/yuhwa/guide/integrations#ironmark) | `yuhwa/ironmark` |
223
+ | [Vite apps](https://ph1p.github.io/yuhwa/guide/integrations#vite-apps) (React, Vue, Svelte, Solid) | `yuhwa/vite` |
224
+ | [Docsify](https://ph1p.github.io/yuhwa/guide/integrations#docsify), [Hugo](https://ph1p.github.io/yuhwa/guide/integrations#hugo), [Jekyll, plain HTML](https://ph1p.github.io/yuhwa/guide/integrations#jekyll-and-plain-html) | the script tag |
225
+
226
+ VitePress, for example:
227
+
228
+ ```ts
229
+ // .vitepress/config.ts
230
+ import { defineConfig } from 'vitepress';
231
+ import yuhwa from 'yuhwa/markdown-it';
232
+
233
+ export default defineConfig({
234
+ markdown: { config: (md) => md.use(yuhwa) },
235
+ });
236
+ ```
237
+
238
+ Add `import 'yuhwa/style.css'` to `.vitepress/theme/index.ts`. Other tools:
239
+ [how the plugins work](https://ph1p.github.io/yuhwa/guide/integrations#what-the-plugins-do) and
240
+ [anything else](https://ph1p.github.io/yuhwa/guide/integrations#something-else).
241
+
242
+ Also: an [HTTP render service](https://ph1p.github.io/yuhwa/guide/embedding) for `<img src>` URLs.
243
+
244
+ ## For AI agents
245
+
246
+ ```bash
247
+ npx yuhwa guide # language reference, written for agents
248
+ npx yuhwa check x.yuhwa --json # diagnostics that name the fix
249
+ ```
250
+
251
+ Point your agent at `yuhwa guide`, let it write source, loop on `check --json`
252
+ until clean. The docs site also serves `llms.txt` and `llms-full.txt`.
253
+ Rules-file and skill snippets: [AI guide](https://ph1p.github.io/yuhwa/guide/ai).
254
+
255
+ ## Editor support
256
+
257
+ `yuhwa-lsp` ships with the `yuhwa` package: diagnostics, quick fixes,
258
+ completion, hover, rename, formatting and semantic colouring.
259
+
260
+ - **VS Code, Cursor, VSCodium:** the extension in [`packages/vscode`](https://github.com/ph1p/yuhwa/blob/main/packages/vscode) bundles the server.
261
+ - **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
+
264
+ Per-editor config: [editor setup](https://ph1p.github.io/yuhwa/guide/lsp).
265
+
266
+ ## Contributing
267
+
268
+ ```bash
269
+ pnpm install
270
+ pnpm dev # visual editor with hot reload
271
+ pnpm docs:dev # docs site
272
+ pnpm check # lint, format, typecheck, tests, build (what CI runs)
273
+ ```
274
+
275
+ | path | contents |
276
+ | ---------------------- | ------------------------------------------------------------------------------------------ |
277
+ | `packages/core` | library, CLI, language server: parser, layout, router, SVG renderer, plugins, integrations |
278
+ | `packages/vscode` | VS Code extension and TextMate grammar |
279
+ | `packages/tree-sitter` | tree-sitter grammar |
280
+ | `packages/zed` | Zed extension |
281
+ | `apps/editor` | visual editor (Vite), served by `yuhwa edit` |
282
+ | `apps/docs` | docs site (VitePress) |
283
+
284
+ ## License
285
+
286
+ MIT
package/client.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ // Types for `.yuhwa` imports through `yuhwa/vite`.
2
+ // Reference once: /// <reference types="yuhwa/client" />
3
+ declare module '*.yuhwa' {
4
+ const svg: string;
5
+ export default svg;
6
+ export const darkSvg: string;
7
+ export const source: string;
8
+ export const title: string;
9
+ }
@@ -0,0 +1,17 @@
1
+ import { t as YuhwaDocsOptions } from "./figure-CCHRsOjO.js";
2
+ interface SetupParams {
3
+ updateConfig: (config: {
4
+ markdown: {
5
+ remarkPlugins: unknown[];
6
+ };
7
+ }) => unknown;
8
+ injectScript: (stage: "page-ssr", content: string) => void;
9
+ }
10
+ export interface AstroIntegration {
11
+ name: string;
12
+ hooks: {
13
+ "astro:config:setup": (params: SetupParams) => void;
14
+ };
15
+ }
16
+ export default function yuhwa(opts?: YuhwaDocsOptions): AstroIntegration;
17
+ export type { YuhwaDocsOptions };
package/dist/astro.js ADDED
@@ -0,0 +1,20 @@
1
+ import remarkYuhwa from "./remark.js";
2
+ // src/integrations/astro.ts
3
+ /**
4
+ * Astro integration, also for Starlight: renders ```yuhwa blocks in .md and
5
+ * .mdx and adds the light/dark stylesheet.
6
+ *
7
+ * // astro.config.mjs
8
+ * import yuhwa from 'yuhwa/astro';
9
+ * export default defineConfig({ integrations: [starlight({...}), yuhwa()] });
10
+ */
11
+ function yuhwa(opts = {}) {
12
+ return {
13
+ name: "yuhwa",
14
+ hooks: { "astro:config:setup": ({ updateConfig, injectScript }) => {
15
+ updateConfig({ markdown: { remarkPlugins: [[remarkYuhwa, opts]] } });
16
+ injectScript("page-ssr", `import 'yuhwa/style.css';`);
17
+ } }
18
+ };
19
+ }
20
+ export { yuhwa as default };
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Drop-in browser runtime: <script src="yuhwa.js"><\/script>
3
+ * Renders every `pre > code.language-yuhwa` (or `.lang-yuhwa`), `pre.yuhwa` and
4
+ * `div.yuhwa` element on the page, and defines the <yuhwa-diagram>
5
+ * custom element:
6
+ *
7
+ * <yuhwa-diagram theme="midnight">a -> b -> c</yuhwa-diagram>
8
+ * <yuhwa-diagram src="docs/arch.yuhwa"></yuhwa-diagram>
9
+ * el.source = 'a -> b' // re-renders
10
+ */
11
+ import { $ as ParseOptions, $t as PanelKind, A as MdBlock, An as registerTheme, At as LayoutOverrides, B as setProp, Bt as Point, C as NODE_PROPS, Cn as TONES, Ct as HeadKind, D as ConvertResult, Dn as getTheme, Dt as LaidNode, E as lint, En as createTheme, Et as LaidGroup, F as replaceBlockSource, Ft as PanelOverride, G as SHAPES, Gt as Side, H as writeLayout, Ht as ResolvedEdgeStyle, I as editPart, It as PanelPart, J as fromJSON, Jt as groupPath, K as DiagramJSON, Kt as SourceRef, L as formatLayout, Lt as PartAction, M as MdResult, Mn as approxMeasure, Mt as NodeOverride, N as findBlocks, Nn as canvasMeasure, Nt as PanelDecl, O as fromMermaid, On as isToneOrHex, Ot as LaidPanel, P as processMarkdown, Pt as PanelHandle, Q as PANELS, Qt as PanelCtx, R as setLabel, Rt as PartChange, S as GROUP_PROPS, Sn as THEME_NAMES, St as GroupDecl, T as PANEL_PROPS, Tn as ThemeInput, Tt as LaidEdge, U as dashFor, Ut as ResolvedNodeStyle, V as setSetting, Vt as Props, W as lineStyle, Wt as ShapeName, X as KNOWN_SETTINGS, Xt as Decoration, Y as renderSvg, Yt as layout, Z as LexedLine, Zt as FrameKind, _ as themes, _n as tspans, _t as Diagnostic, an as perPass, at as joinPath, b as EDGE_PROPS, bn as THEMES, bt as EdgeDecl, c as git, cn as use, ct as parse, d as sequence, dn as renderHead, dt as setLineProp, en as RowCtx, et as SETTING_VALUES, f as legend, fn as InkColors, ft as setTrailingProp, g as charts, gn as segsW, gt as Curve, h as tables, hn as renderSegs, ht as Component, i as hash, in as YuhwaPlugin, it as isYuhwaPath, j as MdOptions, jn as themeNames, jt as NodeDecl, k as isMermaid, kn as ramp, kt as Layout, l as chart, ln as MarkerKind, lt as parseProps, m as frames, mn as parseInline, mt as Box, n as Options, nn as RowPaint, nt as TokKind, o as toSource, on as recolor, ot as lex, p as footer, pn as Seg, pt as splitTrailingProps, q as JsonResult, qt as GRID, r as Result, rn as StatementKind, rt as blockBraces, s as builtins, sn as registry, st as onlyColor, t as InputFormat, tn as RowKind, tt as Tok, u as timeline, un as ShapeKind, ut as serializeProps, v as GUIDE, vn as LineStyle, vt as Diagram, w as NUMBERS, wn as Theme, wt as LabelRef, x as ENUMS, xn as THEME_KEYS, xt as EdgeOverride, y as BOOLS, yn as RAMPS, yt as Direction, z as setPartTone, zt as PartEdit } from "./index-vqADUsNi.js";
12
+ export declare function render(source: string, opts?: Options): Result;
13
+ /**
14
+ * Fetches every file that `source` imports, and what those import, so
15
+ * `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
17
+ * shows up as a diagnostic on its import line.
18
+ */
19
+ export declare function fetchImports(source: string, file: string, load?: (path: string) => Promise<string>): Promise<Record<string, string>>;
20
+ export declare function run(root?: ParentNode, opts?: Options): void;
21
+ declare const Base: typeof HTMLElement;
22
+ /** <yuhwa-diagram [theme] [src]>source</yuhwa-diagram>; fires `yuhwa:render` with the diagnostics */
23
+ export declare class YuhwaDiagram extends Base {
24
+ #private;
25
+ static observedAttributes: string[];
26
+ get source(): string;
27
+ set source(v: string);
28
+ connectedCallback(): void;
29
+ attributeChangedCallback(): void;
30
+ }
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, 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 };
@@ -0,0 +1,158 @@
1
+ import { $ as BOOLS, A as footer, B as PANELS, C as git, Ct as ramp, D as legend, E as sequence, F as perPass, G as lex, H as blockBraces, I as recolor, J as parseProps, K as onlyColor, L as registry, M as tables, N as charts, O as approxMeasure, P as themes, Q as splitTrailingProps, R as use, S as builtins, St as isToneOrHex, T as timeline, Tt as themeNames, U as isYuhwaPath, V as SETTING_VALUES, W as joinPath, X as setLineProp, Y as serializeProps, Z as setTrailingProp, _ as fromJSON, _t as THEME_KEYS, a as findBlocks, at as PANEL_PROPS, b as groupPath, bt as createTheme, c as editPart, ct as renderHead, d as setPartTone, dt as parseInline, et as EDGE_PROPS, f as setProp, ft as renderSegs, g as isMermaid, gt as THEMES, h as fromMermaid, ht as RAMPS, i as GUIDE, it as NUMBERS, j as frames, k as canvasMeasure, l as formatLayout, lt as dashFor, m as writeLayout, mt as tspans, n as render$1, nt as GROUP_PROPS, o as processMarkdown, ot as lint, p as setSetting, pt as segsW, q as parse, r as toSource, rt as NODE_PROPS, s as replaceBlockSource, st as SHAPES, t as hash, tt as ENUMS, u as setLabel, ut as lineStyle, v as renderSvg, vt as THEME_NAMES, w as chart, wt as registerTheme, x as layout, xt as getTheme, y as GRID, yt as TONES, z as KNOWN_SETTINGS } from "./src-CAxa6h4u.js";
2
+ // src/browser.ts
3
+ /**
4
+ * Drop-in browser runtime: <script src="yuhwa.js"><\/script>
5
+ * Renders every `pre > code.language-yuhwa` (or `.lang-yuhwa`), `pre.yuhwa` and
6
+ * `div.yuhwa` element on the page, and defines the <yuhwa-diagram>
7
+ * custom element:
8
+ *
9
+ * <yuhwa-diagram theme="midnight">a -> b -> c</yuhwa-diagram>
10
+ * <yuhwa-diagram src="docs/arch.yuhwa"></yuhwa-diagram>
11
+ * el.source = 'a -> b' // re-renders
12
+ */
13
+ const SELECTOR = "pre > code.language-yuhwa, pre > code.lang-yuhwa, pre.yuhwa, div.yuhwa:not([data-rendered])";
14
+ function prefersDark() {
15
+ return typeof matchMedia === "function" && matchMedia("(prefers-color-scheme: dark)").matches;
16
+ }
17
+ function render(source, opts = {}) {
18
+ let theme = opts.theme;
19
+ if (!theme || theme === "auto") {
20
+ const m = source.match(/^\s*theme\s*:\s*(\S+)/m);
21
+ if (!m || m[1] === "auto") theme = prefersDark() ? "midnight" : "paper";
22
+ }
23
+ return render$1(source, {
24
+ measureFor: (t) => canvasMeasure(t.font),
25
+ ...opts,
26
+ theme
27
+ });
28
+ }
29
+ const IMPORT_RE = /^\s*import\s+(?:\{[^}]*\}\s*from\s+)?"([^"]+)"/gm;
30
+ /**
31
+ * Fetches every file that `source` imports, and what those import, so
32
+ * `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
34
+ * shows up as a diagnostic on its import line.
35
+ */
36
+ async function fetchImports(source, file, load = fetchText) {
37
+ const files = {};
38
+ const queue = [[source, file]];
39
+ while (queue.length) {
40
+ const [text, from] = queue.shift();
41
+ const paths = [...text.matchAll(IMPORT_RE)].map((m) => joinPath(from, m[1])).filter((p) => isYuhwaPath(p) && !(p in files));
42
+ await Promise.all(paths.map(async (p) => {
43
+ files[p] = "";
44
+ try {
45
+ files[p] = await load(p);
46
+ queue.push([files[p], p]);
47
+ } catch {
48
+ delete files[p];
49
+ }
50
+ }));
51
+ }
52
+ return files;
53
+ }
54
+ const fetchText = (url) => fetch(url).then((r) => r.ok ? r.text() : Promise.reject(/* @__PURE__ */ new Error(`${url}: HTTP ${r.status}`)));
55
+ function fit(svg) {
56
+ if (!svg) return;
57
+ svg.removeAttribute("height");
58
+ svg.style.maxWidth = "100%";
59
+ svg.style.height = "auto";
60
+ svg.style.display = "block";
61
+ }
62
+ function run(root = document, opts = {}) {
63
+ root.querySelectorAll(SELECTOR).forEach((el) => {
64
+ const host = el.tagName === "CODE" ? el.parentElement : el;
65
+ const source = el.textContent ?? "";
66
+ const out = document.createElement("div");
67
+ out.className = "yuhwa";
68
+ out.dataset.rendered = "true";
69
+ out.dataset.source = source;
70
+ try {
71
+ const r = render(source, {
72
+ theme: host.dataset.theme,
73
+ ...opts
74
+ });
75
+ out.innerHTML = r.svg;
76
+ fit(out.querySelector("svg"));
77
+ for (const d of r.diagnostics) console.warn(`yuhwa:${d.line}: ${d.message}`);
78
+ } catch (e) {
79
+ out.textContent = `yuhwa error: ${e.message}`;
80
+ out.style.color = "crimson";
81
+ }
82
+ host.replaceWith(out);
83
+ });
84
+ }
85
+ const Base = typeof HTMLElement === "undefined" ? class {} : HTMLElement;
86
+ /** <yuhwa-diagram [theme] [src]>source</yuhwa-diagram>; fires `yuhwa:render` with the diagnostics */
87
+ var YuhwaDiagram = class extends Base {
88
+ static observedAttributes = ["theme", "src"];
89
+ #source = null;
90
+ #fetched = "";
91
+ #file;
92
+ #files = {};
93
+ get source() {
94
+ return this.#source ?? "";
95
+ }
96
+ set source(v) {
97
+ this.#source = v;
98
+ this.#draw();
99
+ }
100
+ connectedCallback() {
101
+ if (document.readyState === "loading" && !this.textContent?.trim() && !this.hasAttribute("src")) return void document.addEventListener("DOMContentLoaded", () => this.connectedCallback(), { once: true });
102
+ if (this.#source === null && !this.hasAttribute("src")) this.#source = this.textContent ?? "";
103
+ this.#update();
104
+ }
105
+ attributeChangedCallback() {
106
+ if (this.isConnected) this.#update();
107
+ }
108
+ #update() {
109
+ const src = this.getAttribute("src");
110
+ if (!src || src === this.#fetched) return this.#draw();
111
+ this.#fetched = src;
112
+ const url = new URL(src, location.href);
113
+ const file = url.origin === location.origin ? url.pathname : url.href;
114
+ fetchText(url.href).then(async (t) => {
115
+ this.#files = await fetchImports(t, file);
116
+ this.#file = file;
117
+ this.source = t;
118
+ }).catch((e) => this.#fail(e.message));
119
+ }
120
+ #draw() {
121
+ if (this.#source === null) return;
122
+ try {
123
+ const files = this.#files;
124
+ const r = render(this.#source, {
125
+ theme: this.getAttribute("theme") ?? void 0,
126
+ file: this.#file,
127
+ resolve: (p) => files[p]
128
+ });
129
+ this.innerHTML = r.svg;
130
+ fit(this.querySelector("svg"));
131
+ this.setAttribute("role", "img");
132
+ if (!this.hasAttribute("aria-label") || this.dataset.autoLabel) {
133
+ const t = r.diagram.settings.title;
134
+ if (t) this.setAttribute("aria-label", t), this.dataset.autoLabel = "1";
135
+ else if (this.dataset.autoLabel) this.removeAttribute("aria-label"), delete this.dataset.autoLabel;
136
+ }
137
+ for (const d of r.diagnostics) console.warn(`yuhwa:${d.line}: ${d.message}`);
138
+ this.dispatchEvent(new CustomEvent("yuhwa:render", { detail: {
139
+ diagnostics: r.diagnostics,
140
+ format: r.format
141
+ } }));
142
+ } catch (e) {
143
+ this.#fail(e.message);
144
+ }
145
+ }
146
+ #fail(msg) {
147
+ this.textContent = `yuhwa error: ${msg}`;
148
+ this.style.color = "crimson";
149
+ }
150
+ };
151
+ if (typeof customElements !== "undefined" && !customElements.get("yuhwa-diagram")) customElements.define("yuhwa-diagram", YuhwaDiagram);
152
+ if (typeof document !== "undefined") {
153
+ if (!document.currentScript?.hasAttribute("data-manual")) {
154
+ if (document.readyState === "loading") document.addEventListener("DOMContentLoaded", () => run());
155
+ else run();
156
+ }
157
+ }
158
+ 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, 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 };