yuhwa 1.6.1 → 1.8.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.
- package/dist/astro.d.ts +1 -1
- package/dist/astro.js +1 -1
- package/dist/browser.d.ts +2 -2
- package/dist/browser.js +4 -4
- package/dist/canvas.js +1 -1
- package/dist/cli.js +207 -64
- package/dist/editor/assets/index-B7LvqDCZ.js +689 -0
- package/dist/editor/assets/lsp.worker-BCEqba2A.js +36 -0
- package/dist/editor/index.html +5 -14
- package/dist/{figure-CqzRbgF5.d.ts → figure-Cn5Ls_0U.d.ts} +1 -1
- package/dist/{index-CT7AJAf8.d.ts → index-0qJC6glR.d.ts} +50 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +4 -4
- package/dist/ironmark.d.ts +1 -1
- package/dist/ironmark.js +1 -1
- package/dist/{parse-BBETEHLI.js → lex-B95erg9Z.js} +158 -1871
- package/dist/llms.txt +97 -14
- package/dist/lsp-browser.d.ts +2 -2
- package/dist/lsp-browser.js +1 -1
- package/dist/lsp-node.js +649 -640
- package/dist/lsp-server.d.ts +1 -1
- package/dist/lsp-server.js +1 -1
- package/dist/lsp.d.ts +7 -2
- package/dist/lsp.js +1 -1
- package/dist/markdown-it.d.ts +1 -1
- package/dist/markdown-it.js +2 -2
- package/dist/{node-MjEWjzvE.js → node-D1wvmy4u.js} +4 -4
- package/dist/{plugin-y9uy8ayQ.d.ts → plugin-COlq-EO9.d.ts} +2 -48
- package/dist/{plugin-BvUxNMpW.js → plugin-D5lzFpzv.js} +9 -2
- package/dist/plugin.d.ts +1 -1
- package/dist/plugin.js +2 -2
- package/dist/{raster-B_C620-4.js → raster-Cy1jbYgz.js} +1 -1
- package/dist/remark.d.ts +1 -1
- package/dist/remark.js +1 -1
- package/dist/satteri.d.ts +1 -1
- package/dist/satteri.js +1 -1
- package/dist/{server-IKsgBoqH.js → server-BrO0eGn8.js} +2 -2
- package/dist/{server-Bb5_7tRV.d.ts → server-C54CveoI.d.ts} +1 -1
- package/dist/{service-wlaqtXGz.d.ts → service-Bjx4ZpF3.d.ts} +1 -17
- package/dist/{service-UapanBwK.js → service-C1M9jbzR.js} +652 -643
- package/dist/{shared-Dz7tyOXD.js → shared-BsaZuOAh.js} +4955 -4652
- package/dist/{src-H9qazt2P.js → src-DXSUoZMj.js} +4392 -2300
- package/dist/vite.d.ts +1 -1
- package/dist/vite.js +2 -3
- package/dist/vuepress.d.ts +1 -1
- package/dist/vuepress.js +1 -1
- package/dist/yuhwa.iife.js +152 -69
- package/package.json +1 -1
- package/skills/yuhwa/SKILL.md +15 -6
- package/dist/editor/assets/index-BdMhpac8.js +0 -689
- package/dist/editor/assets/lsp.worker-MP6GH67i.js +0 -36
package/dist/astro.d.ts
CHANGED
package/dist/astro.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import remarkYuhwa from "./remark.js";
|
|
2
2
|
import satteriYuhwa from "./satteri.js";
|
|
3
|
-
import { n as onTrack, o as clientImports, r as pagesUsing } from "./node-
|
|
3
|
+
import { n as onTrack, o as clientImports, r as pagesUsing } from "./node-D1wvmy4u.js";
|
|
4
4
|
// src/integrations/astro.ts
|
|
5
5
|
/**
|
|
6
6
|
* Astro integration, also for Starlight: renders ```yuhwa blocks in .md and
|
package/dist/browser.d.ts
CHANGED
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
* <yuhwa-diagram render="canvas">a -> b</yuhwa-diagram> // or png; default svg
|
|
12
12
|
* el.source = 'a -> b' // re-renders
|
|
13
13
|
*/
|
|
14
|
-
import { $ as
|
|
15
|
-
import { $ as addNode, A as GROUP_PROPS, B as MdBlock, C as markers, D as COLORS, E as BOOLS, F as lint, G as replaceBlockSource, H as MdResult, I as ConvertResult, J as embedFonts, K as FontSource, L as fromMermaid, M as NUMBERS, N as PANEL_PROPS, O as EDGE_PROPS, P as PANEL_PROP_HELP, Q as addEdge, R as isMermaid, S as themes, T as GUIDE, U as findBlocks, V as MdOptions, W as processMarkdown, X as svgToCanvas, Y as loadFonts, Z as Target, _ as legend, at as setProp, b as tables, c as treeview, ct as writePanelDrag, d as gantt, dt as
|
|
14
|
+
import { $ as Side, A as GroupDecl, At as Seg, B as NodeOverride, C as Component, Ct as registry, D as Direction, Dt as ShapeKind, E as Diagram, Et as MarkerKind, F as LaidNode, Ft as parseInline, G as PartAction, Gt as RAMPS, H as PanelHandle, I as LaidPanel, J as Point, Jt as THEME_KEYS, K as PartChange, L as Layout, Lt as renderSegs, M as LabelRef, N as LaidEdge, O as EdgeDecl, Ot as renderHead, P as LaidGroup, Q as ShapeName, Qt as ThemeInput, R as LayoutOverrides, Rt as segsW, S as Box, St as recolor, T as Diagnostic, Tt as use, U as PanelOverride, Ut as LineStyle, V as PanelDecl, Vt as tspans, W as PanelPart, X as ResolvedEdgeStyle, Xt as TONES, Y as Props, Yt as THEME_NAMES, Z as ResolvedNodeStyle, Zt as Theme, _ as setTrailingProp, _t as RowPaint, a as portOn, at as groupProp, b as Align, bt as optionKind, c as LexedLine, cn as isSafeLink, d as blockBraces, dn as registerTheme, dt as FrameKind, en as createTheme, et as SourceRef, f as lex, ft as PanelCtx, g as setLineProp, gn as canvasMeasure, gt as RowKind, h as serializeProps, hn as approxMeasure, ht as RowCtx, in as getTheme, it as groupPath, j as HeadKind, jt as esc, k as EdgeOverride, kt as InkColors, l as Tok, ln as isToneOrHex, m as parseProps, mt as PanelOption, nn as fontFamilies, on as isGenericFont, ot as lineStyle, p as onlyColor, pn as themeNames, pt as PanelKind, q as PartEdit, qt as THEMES, r as SHAPES, rn as fontStack, sn as isSafeCss, tt as dashFor, u as TokKind, un as ramp, ut as Decoration, v as splitTrailingProps, vt as StatementKind, w as Curve, wt as unuse, x as AlignSide, xt as perPass, yt as YuhwaPlugin, z as NodeDecl } from "./plugin-COlq-EO9.js";
|
|
15
|
+
import { $ as addNode, A as GROUP_PROPS, B as MdBlock, C as markers, Ct as ParseOptions, D as COLORS, E as BOOLS, F as lint, G as replaceBlockSource, H as MdResult, I as ConvertResult, J as embedFonts, K as FontSource, L as fromMermaid, M as NUMBERS, N as PANEL_PROPS, O as EDGE_PROPS, P as PANEL_PROP_HELP, Q as addEdge, R as isMermaid, S as themes, St as SETTING_VALUES, T as GUIDE, U as findBlocks, V as MdOptions, W as processMarkdown, X as svgToCanvas, Y as loadFonts, Z as Target, _ as legend, _t as isYuhwaPath, at as setProp, b as tables, bt as KNOWN_SETTINGS, c as treeview, ct as writePanelDrag, d as gantt, dt as DiagramJSON, et as editPart, f as mindmap, ft as JsonResult, g as sequence, gt as parse, h as timeline, ht as layout, i as hash, it as setPartTone, j as NODE_PROPS, k as ENUMS, l as kanban, lt as ALIGN_SIDES, m as chart, mt as renderSvg, n as Options, nt as removeElement, o as toSource, ot as setSetting, p as git, pt as fromJSON, q as RasterOptions, r as Result, rt as setLabel, s as builtins, st as writeLayout, t as InputFormat, tt as formatLayout, u as quadrant, ut as GRID, v as footer, vt as joinPath, w as shapes, x as charts, xt as SETTING_HELP, y as frames, yt as PANELS, z as MD_LANGUAGES } from "./index-0qJC6glR.js";
|
|
16
16
|
import { i as zoomable, n as Zoomer, r as zoomHeight, t as ZoomOptions } from "./zoom-CCSUbX1X.js";
|
|
17
17
|
export declare function render(source: string, opts?: Options): Result;
|
|
18
18
|
/** `render`, then draw the diagram into a canvas. */
|
package/dist/browser.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { A as
|
|
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-
|
|
1
|
+
import { A as joinPath, B as timeline, C as isMermaid, D as GRID, E as layout, F as quadrant, G as tables, H as legend, I as gantt, J as markers, K as charts, L as mindmap, M as builtins, N as treeview, O as parse, P as kanban, R as git, S as fromMermaid, T as renderSvg, U as footer, V as sequence, W as frames, Y as shapes, _ as setPartTone, a as MD_LANGUAGES, b as writeLayout, d as addEdge, f as addNode, g as setLabel, h as removeElement, i as GUIDE, k as isYuhwaPath, l as processMarkdown, m as formatLayout, n as render$1, o as findBlocks, p as editPart, q as themes, r as toSource, t as hash, u as replaceBlockSource, v as setProp, w as fromJSON, x as writePanelDrag, y as setSetting, z as chart } from "./src-DXSUoZMj.js";
|
|
2
|
+
import { a as perPass, c as unuse, i as optionKind, l as use, n as approxMeasure, o as recolor, r as canvasMeasure, s as registry, u as PANELS } from "./plugin-D5lzFpzv.js";
|
|
3
3
|
import { n as zoomable, t as zoomHeight } from "./zoom-D3Lahr1T.js";
|
|
4
|
-
import { a as svgFamilies, c as swapForRaster, n as embedFonts, r as loadFonts, s as svgToCanvas } from "./raster-
|
|
5
|
-
import { $t as
|
|
4
|
+
import { a as svgFamilies, c as swapForRaster, n as embedFonts, r as loadFonts, s as svgToCanvas } from "./raster-Cy1jbYgz.js";
|
|
5
|
+
import { $t as parseInline, An as isSafeLink, C as SETTING_VALUES, D as EDGE_PROPS, E as COLORS, En as getTheme, Fn as themeNames, H as SHAPES, K as portOn, M as NUMBERS, Mn as ramp, Mt as groupProp, N as PANEL_PROPS, Nn as registerTheme, O as ENUMS, On as isGenericFont, P as PANEL_PROP_HELP, Pt as lineStyle, Sn as createTheme, T as BOOLS, Tn as fontStack, Tt as dashFor, _n as THEMES, a as lex, an as segsW, b as KNOWN_SETTINGS, bn as TONES, bt as ALIGN_SIDES, c as parseProps, d as serializeProps, fn as tspans, h as splitTrailingProps, hn as RAMPS, i as blockBraces, j as NODE_PROPS, jn as isToneOrHex, jt as groupPath, k as GROUP_PROPS, kn as isSafeCss, m as setTrailingProp, nn as renderSegs, p as setLineProp, qt as esc, rt as renderHead, s as onlyColor, v as unquote, vn as THEME_KEYS, wn as fontFamilies, x as SETTING_HELP, yn as THEME_NAMES, z as lint } from "./lex-B95erg9Z.js";
|
|
6
6
|
// src/browser.ts
|
|
7
7
|
/**
|
|
8
8
|
* Drop-in browser runtime: <script src="yuhwa.js"><\/script>
|
package/dist/canvas.js
CHANGED
|
@@ -17,7 +17,7 @@ function installCanvas() {
|
|
|
17
17
|
const swap = async (img) => {
|
|
18
18
|
const svg = svgFromDataUri(img.getAttribute("src") ?? "");
|
|
19
19
|
if (svg === void 0) return;
|
|
20
|
-
const { swapForRaster } = await import("./raster-
|
|
20
|
+
const { swapForRaster } = await import("./raster-Cy1jbYgz.js").then((n) => n.i);
|
|
21
21
|
const canvas = await swapForRaster(img, svg, "canvas", img.alt);
|
|
22
22
|
if (canvas) canvas.className = img.className;
|
|
23
23
|
};
|
package/dist/cli.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
|
|
3
|
-
import {
|
|
3
|
+
import { $ as isSafeCss, C as canvasMeasure, D as KNOWN_SETTINGS, F as GROUP_PROPS, H as SHAPES, I as NODE_PROPS, M as COLORS, N as EDGE_PROPS, P as ENUMS, Q as TONES, R as PANEL_PROPS, S as unquote, T as registry, W as ALIGN_SIDES_HINT, X as THEME_KEYS, Z as THEME_NAMES, a as formatPage, c as diskResolve, d as MD_LANGUAGES, f as findBlocks, g as replaceBlockSource, h as processMarkdown, i as format, k as SETTING_VALUES, l as render$1, m as pageBlocks, nt as isYuhwaPath, p as isMarkdown, q as esc, rt as joinPath, s as tidy, t as VERSION, u as toSource, w as optionKind } from "./shared-BsaZuOAh.js";
|
|
4
4
|
import { createServer } from "node:http";
|
|
5
5
|
import { basename, dirname, extname, join, resolve, sep } from "node:path";
|
|
6
6
|
import { fileURLToPath } from "node:url";
|
|
@@ -328,9 +328,10 @@ yuhwa is a text diagram language that renders to a self-contained SVG. One
|
|
|
328
328
|
statement per line. \`//\` at line start or after a space starts a comment, so
|
|
329
329
|
URLs in labels stay text. There is no \`#\` comment.
|
|
330
330
|
|
|
331
|
-
Workflow: write the source, run \`yuhwa check file.yu --
|
|
332
|
-
\`diagnostics\` of \`render\`), fix
|
|
333
|
-
|
|
331
|
+
Workflow: write the source, run \`yuhwa check file.yu --strict\` (\`--json\`
|
|
332
|
+
for a machine-readable report, or read the \`diagnostics\` of \`render\`), fix
|
|
333
|
+
every error and warning, then \`yuhwa render file.yu -o file.svg\`. Done when
|
|
334
|
+
it reports 0 diagnostics; they name the fix ("did you mean ...", "write ...").
|
|
334
335
|
|
|
335
336
|
## Example
|
|
336
337
|
|
|
@@ -353,6 +354,52 @@ orders -> db: SQL
|
|
|
353
354
|
orders --> queue "Events" [shape: hexagon]: publish [flow: true]
|
|
354
355
|
\`\`\`
|
|
355
356
|
|
|
357
|
+
## Pick the construct
|
|
358
|
+
|
|
359
|
+
- Architecture, components, data flow: nodes, edges and groups (the graph).
|
|
360
|
+
- Process or flowchart: the graph with \`[diamond]\` decisions and \`yes\`/\`no\` edge labels.
|
|
361
|
+
- State machine: the graph with \`[pill]\` states and edges labelled by events.
|
|
362
|
+
- Calls over time (login flow, API handshake): a \`sequence\` panel.
|
|
363
|
+
- Project plan or schedule: \`gantt\`. Milestones or history: \`timeline\`.
|
|
364
|
+
- Branches and releases: \`git\`. Files and folders: \`treeview\`.
|
|
365
|
+
- Topic breakdown: \`mindmap\`. Task board: \`kanban\`.
|
|
366
|
+
- Numbers: \`chart\`. Two-axis prioritisation: \`quadrant\`.
|
|
367
|
+
|
|
368
|
+
Graph and panels mix in one file (see Panels).
|
|
369
|
+
|
|
370
|
+
## Recipes
|
|
371
|
+
|
|
372
|
+
Flowchart with a decision and a loop back:
|
|
373
|
+
|
|
374
|
+
\`\`\`yuhwa
|
|
375
|
+
direction: down
|
|
376
|
+
start "Start" [pill, green]
|
|
377
|
+
form "Fill in form"
|
|
378
|
+
valid "Valid?" [diamond, amber]
|
|
379
|
+
save "Save order"
|
|
380
|
+
done "Done" [pill, green]
|
|
381
|
+
start -> form -> valid
|
|
382
|
+
valid -> save: yes
|
|
383
|
+
valid -> form: no [dashed]
|
|
384
|
+
save -> done
|
|
385
|
+
\`\`\`
|
|
386
|
+
|
|
387
|
+
State machine:
|
|
388
|
+
|
|
389
|
+
\`\`\`yuhwa
|
|
390
|
+
direction: right
|
|
391
|
+
.state [pill]
|
|
392
|
+
idle "Idle" .state
|
|
393
|
+
running "Running" .state [blue]
|
|
394
|
+
paused "Paused" .state
|
|
395
|
+
failed "Failed" .state [red]
|
|
396
|
+
idle -> running: start
|
|
397
|
+
running -> paused: pause
|
|
398
|
+
paused -> running: resume
|
|
399
|
+
running -> failed: error
|
|
400
|
+
failed -> idle: reset [dashed]
|
|
401
|
+
\`\`\`
|
|
402
|
+
|
|
356
403
|
## Statements
|
|
357
404
|
|
|
358
405
|
- Setting: \`key: value\` at top level. Keys: ${settings}.
|
|
@@ -410,14 +457,21 @@ orders --> queue "Events" [shape: hexagon]: publish [flow: true]
|
|
|
410
457
|
|
|
411
458
|
\`sub\` is a second, smaller line; \`icon\` an emoji before the label; \`link\`
|
|
412
459
|
makes a node clickable; \`flow: true\` animates an edge; \`constraint: false\`
|
|
413
|
-
keeps an edge out of the layout; \`
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
\`
|
|
420
|
-
|
|
460
|
+
keeps an edge out of the layout; \`shape: text\` is an annotation without a box.
|
|
461
|
+
|
|
462
|
+
\`merge: in|out|both\` joins edges sharing a node and side into one trunk with
|
|
463
|
+
a single arrow head. It works as a setting, on a node or group (the edges
|
|
464
|
+
ending there) or on an edge (its own ends).
|
|
465
|
+
|
|
466
|
+
\`below: <id>\`, \`above\`, \`right-of\`, \`left-of\` and \`rank\` place a node
|
|
467
|
+
next to another node without drawing an edge; do not use invisible edges for
|
|
468
|
+
that. \`align: [side] <id>\` lines a node or group up with another. On a
|
|
469
|
+
group, \`align: <side>\` alone puts its members' <side> edges on one line,
|
|
470
|
+
keeping their ranks.
|
|
471
|
+
|
|
472
|
+
A group's \`gap: <px>\` spaces its members, also between ranks its own edges
|
|
473
|
+
join; nested groups inherit it. \`padding\` takes 1 to 4 numbers like CSS
|
|
474
|
+
(\`8 24\` = top/bottom 8, left/right 24). The \`max-width: <px>\` setting
|
|
421
475
|
wraps the ranks of a right or left diagram into rows that fit that width.
|
|
422
476
|
\`frame: <kind> <text>\` draws window chrome: ${list$1(registry.frames.keys())}.
|
|
423
477
|
|
|
@@ -475,6 +529,31 @@ lines take \`[props]\` before the colon or at the end of the line.
|
|
|
475
529
|
|
|
476
530
|
${panelLines}
|
|
477
531
|
|
|
532
|
+
\`\`\`yuhwa
|
|
533
|
+
panels: row
|
|
534
|
+
gantt plan "Launch" [today: 2026-03-10] {
|
|
535
|
+
--- Build ---
|
|
536
|
+
api "API": 2026-03-02, 5d
|
|
537
|
+
ui "UI" [active]: after api, 4d
|
|
538
|
+
--- Ship ---
|
|
539
|
+
beta "Beta" [milestone]: after ui, 0d
|
|
540
|
+
}
|
|
541
|
+
treeview repo "Repo" {
|
|
542
|
+
src/
|
|
543
|
+
index.ts
|
|
544
|
+
core/
|
|
545
|
+
parse.ts [modified]
|
|
546
|
+
package.json
|
|
547
|
+
}
|
|
548
|
+
git flow "Release" {
|
|
549
|
+
commit "init"
|
|
550
|
+
branch feature
|
|
551
|
+
commit "add login"
|
|
552
|
+
checkout main
|
|
553
|
+
merge feature [tag: v1.0]
|
|
554
|
+
}
|
|
555
|
+
\`\`\`
|
|
556
|
+
|
|
478
557
|
## Imports
|
|
479
558
|
|
|
480
559
|
\`import "./shared.yu"\` at top level pulls in another file's classes,
|
|
@@ -505,8 +584,9 @@ layout {
|
|
|
505
584
|
\`rank a b c\` keeps nodes in one rank. \`align ${ALIGN_SIDES_HINT} a b c\`
|
|
506
585
|
lines up nodes or groups on one edge or their centres; neither pins anything.
|
|
507
586
|
|
|
508
|
-
\`panel at X Y\` pins a panel
|
|
509
|
-
parts
|
|
587
|
+
The editor also writes \`panel at X Y\` (pins a panel) and \`panel:part D\`
|
|
588
|
+
(\`panel:part DX DY\` for free parts, nudges one part). Keep them when editing;
|
|
589
|
+
never write them from scratch:
|
|
510
590
|
|
|
511
591
|
${partLines}
|
|
512
592
|
|
|
@@ -535,6 +615,9 @@ panel. \`yuhwa convert file.mmd\` prints the yuhwa source.
|
|
|
535
615
|
- \`a -> b "calls"\` renames b. Edge labels: \`a -> b: calls\`.
|
|
536
616
|
- Mermaid habits (\`%%\`, \`-->|label|\`, \`subgraph ... end\`, \`A[Label]\`) are
|
|
537
617
|
\`//\`, \`a -> b: label\`, \`group id "Label" { }\`, \`a "Label"\` here.
|
|
618
|
+
Shapes are props: \`B{Ok?}\` is \`b "Ok?" [diamond]\`, \`C((Hub))\` is
|
|
619
|
+
\`c "Hub" [circle]\`, \`D[(DB)]\` is \`d "DB" [cylinder]\`.
|
|
620
|
+
- There is no \`label\` prop: the label is the quoted text after the id.
|
|
538
621
|
- A node lives in one group; declaring it in a second one moves it.
|
|
539
622
|
- A \`layout { }\` line for a node that no longer exists warns: delete it.
|
|
540
623
|
|
|
@@ -851,7 +934,7 @@ function svgToPng(svg, { scale = 2, fonts = [], systemFonts = true } = {}) {
|
|
|
851
934
|
try {
|
|
852
935
|
resvg = createRequire(import.meta.url)("@resvg/resvg-js").Resvg;
|
|
853
936
|
} catch {
|
|
854
|
-
throw new Error("PNG output needs @resvg/resvg-js: npm install -D @resvg/resvg-js, or pnpm add -D @resvg/resvg-js");
|
|
937
|
+
throw new Error("PNG output needs @resvg/resvg-js: npm install -D @resvg/resvg-js, or pnpm add -D @resvg/resvg-js. Through npx or pnpm dlx, fetch both: npx -p yuhwa -p @resvg/resvg-js yuhwa render diagram.yu -o diagram.png, or pnpm --package=yuhwa --package=@resvg/resvg-js dlx yuhwa render diagram.yu -o diagram.png");
|
|
855
938
|
}
|
|
856
939
|
}
|
|
857
940
|
const { fontFiles, fontDirs } = fontPaths(fonts);
|
|
@@ -876,6 +959,16 @@ function parseLanguages(v) {
|
|
|
876
959
|
if (!langs.length) throw new Error("--lang: give at least one fence language, e.g. --lang yuhwa,yu");
|
|
877
960
|
return langs;
|
|
878
961
|
}
|
|
962
|
+
// src/cli/report.ts
|
|
963
|
+
/** what a check report counts, shared by `yuhwa check` and `POST /check` */
|
|
964
|
+
const stats = (d) => ({
|
|
965
|
+
nodes: d.nodes.size,
|
|
966
|
+
edges: d.edges.length,
|
|
967
|
+
groups: d.groups.size,
|
|
968
|
+
panels: d.panels.length
|
|
969
|
+
});
|
|
970
|
+
/** no errors; with `strict` no warnings either */
|
|
971
|
+
const passes = (ds, strict = false) => !ds.some((d) => d.severity === "error" || strict && d.severity === "warning");
|
|
879
972
|
// src/cli/view.ts
|
|
880
973
|
/**
|
|
881
974
|
* A standalone HTML page that shows one diagram in a full-window pan and zoom
|
|
@@ -914,7 +1007,7 @@ ${svg}
|
|
|
914
1007
|
* GET /view?src=…, /view/<base64url>, /yuhwa/view/<deflate + base64url>
|
|
915
1008
|
* the same as a page with pan and zoom
|
|
916
1009
|
* POST /svg body: source (yuhwa, Mermaid or JSON)
|
|
917
|
-
* POST /check body: source → { ok, format, diagnostics }
|
|
1010
|
+
* POST /check body: source → { ok, format, nodes, edges, groups, panels, diagnostics }
|
|
918
1011
|
* GET /llms.txt language reference for AI tools
|
|
919
1012
|
*
|
|
920
1013
|
* Output is deterministic, so GET responses are cacheable forever.
|
|
@@ -933,12 +1026,25 @@ function viewUrl(source, base) {
|
|
|
933
1026
|
function decodeSource(encoded, compressed) {
|
|
934
1027
|
const buf = Buffer.from(encoded.replace(/\.svg$/, ""), "base64url");
|
|
935
1028
|
if (!compressed) return buf.toString("utf8");
|
|
1029
|
+
const opts = { maxOutputLength: MAX_BODY };
|
|
1030
|
+
const tooLarge = (e) => e.code === "ERR_BUFFER_TOO_LARGE";
|
|
936
1031
|
try {
|
|
937
|
-
return inflateSync(buf).toString("utf8");
|
|
938
|
-
} catch {
|
|
939
|
-
|
|
1032
|
+
return inflateSync(buf, opts).toString("utf8");
|
|
1033
|
+
} catch (e) {
|
|
1034
|
+
let err = e;
|
|
1035
|
+
if (!tooLarge(err)) try {
|
|
1036
|
+
return inflateRawSync(buf, opts).toString("utf8");
|
|
1037
|
+
} catch (raw) {
|
|
1038
|
+
err = raw;
|
|
1039
|
+
}
|
|
1040
|
+
throw tooLarge(err) ? Object.assign(/* @__PURE__ */ new Error("source too large"), { status: 413 }) : err;
|
|
940
1041
|
}
|
|
941
1042
|
}
|
|
1043
|
+
/** header values must be Latin-1 without controls: keep printable ASCII, write the rest as `\u` escapes */
|
|
1044
|
+
function headerSafe(text) {
|
|
1045
|
+
return text.replace(/[^\x20-\x7e]/g, (c) => c === "\n" ? " " : `\\u${c.charCodeAt(0).toString(16).padStart(4, "0")}`);
|
|
1046
|
+
}
|
|
1047
|
+
const escHtml = (s) => s.replace(/[&<>"']/g, (c) => `&#${c.charCodeAt(0)};`);
|
|
942
1048
|
function readBody(req, max = MAX_BODY) {
|
|
943
1049
|
return new Promise((ok, fail) => {
|
|
944
1050
|
let size = 0;
|
|
@@ -995,7 +1101,7 @@ function handler(req, res) {
|
|
|
995
1101
|
res.setHeader("content-security-policy", "default-src 'none'; style-src 'unsafe-inline'; img-src data:");
|
|
996
1102
|
res.setHeader("x-content-type-options", "nosniff");
|
|
997
1103
|
res.setHeader("x-yuhwa-format", r.format);
|
|
998
|
-
if (errors.length) res.setHeader("x-yuhwa-errors", errors.map((d) => `${d.line}: ${d.message}`).join(" | ").slice(0, 2e3));
|
|
1104
|
+
if (errors.length) res.setHeader("x-yuhwa-errors", headerSafe(errors.map((d) => `${d.line}: ${d.message}`).join(" | ").slice(0, 2e3)));
|
|
999
1105
|
if (cache && !errors.length) res.setHeader("cache-control", "public, max-age=31536000, immutable");
|
|
1000
1106
|
res.end(r.svg);
|
|
1001
1107
|
};
|
|
@@ -1019,7 +1125,7 @@ function handler(req, res) {
|
|
|
1019
1125
|
try {
|
|
1020
1126
|
if (req.method === "GET") {
|
|
1021
1127
|
if (path === "/") {
|
|
1022
|
-
res.writeHead(200, { "content-type": "text/html; charset=utf-8" }).end(HOME(`http://${req.headers.host ?? "localhost"}`));
|
|
1128
|
+
res.writeHead(200, { "content-type": "text/html; charset=utf-8" }).end(HOME(escHtml(`http://${req.headers.host ?? "localhost"}`)));
|
|
1023
1129
|
return;
|
|
1024
1130
|
}
|
|
1025
1131
|
if (path === "/llms.txt" || path === "/guide") {
|
|
@@ -1055,8 +1161,9 @@ function handler(req, res) {
|
|
|
1055
1161
|
if (path !== "/check") return sendSvg(source, false);
|
|
1056
1162
|
const r = render$1(source, { theme });
|
|
1057
1163
|
sendJson(200, {
|
|
1058
|
-
ok:
|
|
1164
|
+
ok: passes(r.diagnostics),
|
|
1059
1165
|
format: r.format,
|
|
1166
|
+
...stats(r.diagram),
|
|
1060
1167
|
diagnostics: r.diagnostics
|
|
1061
1168
|
});
|
|
1062
1169
|
}).catch((e) => {
|
|
@@ -1067,7 +1174,7 @@ function handler(req, res) {
|
|
|
1067
1174
|
}
|
|
1068
1175
|
fail(404, `not found: ${req.method} ${path} (see GET /)`);
|
|
1069
1176
|
} catch (e) {
|
|
1070
|
-
fail(400, e.message);
|
|
1177
|
+
fail(e.status ?? 400, e.message);
|
|
1071
1178
|
}
|
|
1072
1179
|
}
|
|
1073
1180
|
function serve(port, host) {
|
|
@@ -1366,21 +1473,24 @@ if (typeof document !== "undefined") {
|
|
|
1366
1473
|
const HELP = `yuhwa — diagrams that look good and stay where you put them
|
|
1367
1474
|
|
|
1368
1475
|
Usage
|
|
1369
|
-
yuhwa render <file
|
|
1370
|
-
yuhwa check <file
|
|
1476
|
+
yuhwa render <file|-|source> [-e source] [-o out.svg|out.html|out.png] [--html] [--png] [--scale 2] [--font f] [--no-system-fonts] [--theme name] [--block n]
|
|
1477
|
+
yuhwa check <file|-|source...> [-e source] [--json] [--strict] [--lang yuhwa,yu]
|
|
1371
1478
|
yuhwa lint <file...> [--fix] [--json] [--lang yuhwa,yu]
|
|
1372
|
-
yuhwa convert <file.mmd|file.json
|
|
1479
|
+
yuhwa convert <file.mmd|file.json|-|source> [-e source] [-o out.yu]
|
|
1373
1480
|
yuhwa md <file.md...> [--out-dir diagrams] [--dark] [--keep-fences] [--view[=base]]
|
|
1374
1481
|
yuhwa edit <file.yu|file.md> [--block n] [--port 4747] [--no-open]
|
|
1375
1482
|
yuhwa serve [--port 4749] [--host 127.0.0.1]
|
|
1376
|
-
yuhwa url <file
|
|
1377
|
-
yuhwa <file>
|
|
1483
|
+
yuhwa url <file|-|source> [-e source] [--base http://localhost:4749] [--view]
|
|
1484
|
+
yuhwa <file|source> same as yuhwa render <file|source>
|
|
1378
1485
|
yuhwa guide language reference for AI tools (alias: llms)
|
|
1379
1486
|
yuhwa themes
|
|
1380
1487
|
yuhwa --version | -v
|
|
1381
1488
|
yuhwa --help | -h
|
|
1382
1489
|
|
|
1383
1490
|
Input can be yuhwa, a Mermaid flowchart or JSON; the format is detected.
|
|
1491
|
+
Instead of a file, give the source itself: -e/--source "a -> b", or as the
|
|
1492
|
+
argument when no such file exists and it reads as source (an arrow or a
|
|
1493
|
+
newline), like yuhwa render "a -> b". Imports resolve from the current folder.
|
|
1384
1494
|
|
|
1385
1495
|
render Render one diagram to SVG (stdout unless -o is given). From a
|
|
1386
1496
|
Markdown file it renders block --block n (from 0, default 0).
|
|
@@ -1390,6 +1500,7 @@ render Render one diagram to SVG (stdout unless -o is given). From a
|
|
|
1390
1500
|
uses system fonts; --font adds a font file or folder (repeatable),
|
|
1391
1501
|
--no-system-fonts uses only those, the same on every machine.
|
|
1392
1502
|
check Validate without rendering. --json prints machine-readable diagnostics.
|
|
1503
|
+
--strict fails on warnings too (exit code 1, \`ok: false\`).
|
|
1393
1504
|
A .md/.mdx/.markdown file is checked block by block: every
|
|
1394
1505
|
\`\`\`yuhwa and \`\`\`yu fence (--lang picks others) and every
|
|
1395
1506
|
<!--yuhwa --> comment, with line numbers in the Markdown file.
|
|
@@ -1413,6 +1524,7 @@ guide Print the language reference (same as llms.txt). AI agents: read
|
|
|
1413
1524
|
`;
|
|
1414
1525
|
/** flags that take a value; repeatable ones collect every value in a list */
|
|
1415
1526
|
const VALUE_FLAGS = /* @__PURE__ */ new Set([
|
|
1527
|
+
"source",
|
|
1416
1528
|
"theme",
|
|
1417
1529
|
"out",
|
|
1418
1530
|
"out-dir",
|
|
@@ -1430,6 +1542,7 @@ function parseArgs(argv) {
|
|
|
1430
1542
|
for (let i = 0; i < argv.length; i++) {
|
|
1431
1543
|
const s = argv[i];
|
|
1432
1544
|
if (s === "-o") a.out = argv[++i];
|
|
1545
|
+
else if (s === "-e") a.source = argv[++i] ?? "";
|
|
1433
1546
|
else if (s === "-h") a.help = true;
|
|
1434
1547
|
else if (s === "-v") a.version = true;
|
|
1435
1548
|
else if (s.startsWith("--")) {
|
|
@@ -1459,7 +1572,7 @@ function cmdRender(a) {
|
|
|
1459
1572
|
({source, line: at} = b);
|
|
1460
1573
|
}
|
|
1461
1574
|
const r = renderAs(a, file, source);
|
|
1462
|
-
printDiagnostics(file,
|
|
1575
|
+
printDiagnostics(file, offsetLines(r.diagnostics, at));
|
|
1463
1576
|
const out = str(a.out);
|
|
1464
1577
|
const kind = a.html || /\.html?$/i.test(out ?? "") ? "html" : a.png || /\.png$/i.test(out ?? "") ? "png" : "svg";
|
|
1465
1578
|
if (kind === "png") writeOut(out, svgToPng(r.svg, {
|
|
@@ -1474,13 +1587,32 @@ function cmdRender(a) {
|
|
|
1474
1587
|
background: r.layout.theme.background
|
|
1475
1588
|
}));
|
|
1476
1589
|
} else writeOut(out, r.svg + "\n");
|
|
1477
|
-
if (r.diagnostics
|
|
1590
|
+
if (!passes(r.diagnostics)) process.exitCode = 1;
|
|
1591
|
+
}
|
|
1592
|
+
/** sources given on the command line, by the name that stands for them in `a._` and in diagnostics */
|
|
1593
|
+
const inline = /* @__PURE__ */ new Map();
|
|
1594
|
+
/** no such file, but it reads as source: an arrow, a `--` edge or a newline */
|
|
1595
|
+
const looksInline = (arg) => !existsSync(arg) && /\n|->|<-|--|=>/.test(arg);
|
|
1596
|
+
/** `-e`/`--source` and source-like arguments become named inline inputs */
|
|
1597
|
+
function takeInline(a) {
|
|
1598
|
+
const given = typeof a.source === "string" ? [stash(a.source)] : [];
|
|
1599
|
+
const args = a._.slice(1).map((x) => x !== "-" && looksInline(x) ? stash(x) : x);
|
|
1600
|
+
a._ = [
|
|
1601
|
+
a._[0],
|
|
1602
|
+
...given,
|
|
1603
|
+
...args
|
|
1604
|
+
];
|
|
1605
|
+
}
|
|
1606
|
+
function stash(source) {
|
|
1607
|
+
const name = inline.size ? `<source ${inline.size + 1}>` : "<source>";
|
|
1608
|
+
inline.set(name, source);
|
|
1609
|
+
return name;
|
|
1478
1610
|
}
|
|
1479
1611
|
const fileOpts = (file) => ({
|
|
1480
1612
|
resolve: diskResolve,
|
|
1481
|
-
file: file === "-" ? void 0 : file
|
|
1613
|
+
file: file === "-" || inline.has(file) ? void 0 : file
|
|
1482
1614
|
});
|
|
1483
|
-
const readInput = (file) => file === "-" ? readFileSync(0, "utf8") : readFileSync(file, "utf8");
|
|
1615
|
+
const readInput = (file) => inline.get(file) ?? (file === "-" ? readFileSync(0, "utf8") : readFileSync(file, "utf8"));
|
|
1484
1616
|
function writeOut(out, text) {
|
|
1485
1617
|
if (!out) {
|
|
1486
1618
|
process.stdout.write(text);
|
|
@@ -1491,7 +1623,7 @@ function writeOut(out, text) {
|
|
|
1491
1623
|
process.stderr.write(`wrote ${out}\n`);
|
|
1492
1624
|
}
|
|
1493
1625
|
/** block diagnostics carry block lines; `at` is the opening fence's page line */
|
|
1494
|
-
const
|
|
1626
|
+
const offsetLines = (ds, at) => at ? ds.map((d) => ({
|
|
1495
1627
|
...d,
|
|
1496
1628
|
line: at + Math.max(d.line, 1)
|
|
1497
1629
|
})) : ds;
|
|
@@ -1509,26 +1641,23 @@ function checkPage(file, a) {
|
|
|
1509
1641
|
const counts = {
|
|
1510
1642
|
nodes: 0,
|
|
1511
1643
|
edges: 0,
|
|
1512
|
-
groups: 0
|
|
1644
|
+
groups: 0,
|
|
1645
|
+
panels: 0
|
|
1513
1646
|
};
|
|
1514
1647
|
const entries = blocks.map((b) => {
|
|
1515
1648
|
const r = renderAs(a, file, b.source);
|
|
1516
|
-
for (const d of
|
|
1649
|
+
for (const d of offsetLines(r.diagnostics, b.line)) diagnostics.push({
|
|
1517
1650
|
...d,
|
|
1518
1651
|
block: b.index
|
|
1519
1652
|
});
|
|
1520
|
-
const
|
|
1521
|
-
counts
|
|
1522
|
-
counts.edges += edges.length;
|
|
1523
|
-
counts.groups += groups.size;
|
|
1653
|
+
const n = stats(r.diagram);
|
|
1654
|
+
for (const k of Object.keys(counts)) counts[k] += n[k];
|
|
1524
1655
|
const { source: _, ...where } = b;
|
|
1525
1656
|
return {
|
|
1526
1657
|
...where,
|
|
1527
|
-
ok:
|
|
1658
|
+
ok: passes(r.diagnostics, !!a.strict),
|
|
1528
1659
|
format: r.format,
|
|
1529
|
-
|
|
1530
|
-
edges: edges.length,
|
|
1531
|
-
groups: groups.size
|
|
1660
|
+
...n
|
|
1532
1661
|
};
|
|
1533
1662
|
});
|
|
1534
1663
|
const ok = entries.every((e) => e.ok);
|
|
@@ -1558,9 +1687,8 @@ function cmdCheck(a) {
|
|
|
1558
1687
|
perFile(a, "check", (file) => {
|
|
1559
1688
|
if (isMarkdown(file)) return checkPage(file, a);
|
|
1560
1689
|
const r = renderAs(a, file, readInput(file));
|
|
1561
|
-
const ok =
|
|
1690
|
+
const ok = passes(r.diagnostics, !!a.strict);
|
|
1562
1691
|
if (!ok) process.exitCode = 1;
|
|
1563
|
-
const { nodes, edges, groups } = r.diagram;
|
|
1564
1692
|
if (!a.json) {
|
|
1565
1693
|
printDiagnostics(file, r.diagnostics);
|
|
1566
1694
|
process.stderr.write(`${file}: ${ok ? "ok" : "errors"} (${r.format}, ${r.diagnostics.length} diagnostic(s))\n`);
|
|
@@ -1569,9 +1697,7 @@ function cmdCheck(a) {
|
|
|
1569
1697
|
file,
|
|
1570
1698
|
ok,
|
|
1571
1699
|
format: r.format,
|
|
1572
|
-
|
|
1573
|
-
edges: edges.length,
|
|
1574
|
-
groups: groups.size,
|
|
1700
|
+
...stats(r.diagram),
|
|
1575
1701
|
diagnostics: r.diagnostics
|
|
1576
1702
|
};
|
|
1577
1703
|
});
|
|
@@ -1580,7 +1706,7 @@ function cmdCheck(a) {
|
|
|
1580
1706
|
function cmdLint(a) {
|
|
1581
1707
|
const lintOne = (source, file, at = 0) => {
|
|
1582
1708
|
const r = renderAs(a, file, source);
|
|
1583
|
-
return
|
|
1709
|
+
return offsetLines([...r.diagnostics, ...r.format === "yuhwa" ? tidy(source, r.diagram) : []], at);
|
|
1584
1710
|
};
|
|
1585
1711
|
perFile(a, "lint", (file) => {
|
|
1586
1712
|
let diagnostics;
|
|
@@ -1633,7 +1759,7 @@ function cmdConvert(a) {
|
|
|
1633
1759
|
if (!file) throw new Error("convert: missing input file");
|
|
1634
1760
|
const r = toSource(readInput(file));
|
|
1635
1761
|
printDiagnostics(file, r.diagnostics);
|
|
1636
|
-
if (r.diagnostics
|
|
1762
|
+
if (!passes(r.diagnostics)) {
|
|
1637
1763
|
process.exitCode = 1;
|
|
1638
1764
|
return;
|
|
1639
1765
|
}
|
|
@@ -1664,7 +1790,7 @@ function cmdMd(a) {
|
|
|
1664
1790
|
...fileOpts(file)
|
|
1665
1791
|
});
|
|
1666
1792
|
for (const d of res.diagnostics) process.stderr.write(`${file} [${d.block}]:${d.line}: ${d.severity}: ${d.message}\n`);
|
|
1667
|
-
if (res.diagnostics
|
|
1793
|
+
if (!passes(res.diagnostics)) process.exitCode = 1;
|
|
1668
1794
|
const base = dirname(resolve(file));
|
|
1669
1795
|
for (const f of res.files) {
|
|
1670
1796
|
const p = join(base, f.path);
|
|
@@ -1780,22 +1906,39 @@ function main() {
|
|
|
1780
1906
|
const cmd = a._[0];
|
|
1781
1907
|
try {
|
|
1782
1908
|
if (a.version || cmd === "version") process.stdout.write(VERSION + "\n");
|
|
1783
|
-
else if (!cmd
|
|
1784
|
-
|
|
1785
|
-
|
|
1909
|
+
else if (!cmd && typeof a.source === "string") {
|
|
1910
|
+
takeInline(a);
|
|
1911
|
+
cmdRender({
|
|
1912
|
+
...a,
|
|
1913
|
+
_: ["render", ...a._.slice(1)]
|
|
1914
|
+
});
|
|
1915
|
+
} else if (!cmd || cmd === "help" || a.help) process.stdout.write(HELP);
|
|
1916
|
+
else if (cmd === "render") {
|
|
1917
|
+
takeInline(a);
|
|
1918
|
+
cmdRender(a);
|
|
1919
|
+
} else if (cmd === "md") cmdMd(a);
|
|
1786
1920
|
else if (cmd === "edit") cmdEdit(a);
|
|
1787
|
-
else if (cmd === "check")
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
else if (cmd === "
|
|
1791
|
-
else if (cmd === "
|
|
1921
|
+
else if (cmd === "check") {
|
|
1922
|
+
takeInline(a);
|
|
1923
|
+
cmdCheck(a);
|
|
1924
|
+
} else if (cmd === "lint") cmdLint(a);
|
|
1925
|
+
else if (cmd === "convert") {
|
|
1926
|
+
takeInline(a);
|
|
1927
|
+
cmdConvert(a);
|
|
1928
|
+
} else if (cmd === "url") {
|
|
1929
|
+
takeInline(a);
|
|
1930
|
+
cmdUrl(a);
|
|
1931
|
+
} else if (cmd === "serve") serve(Number(str(a.port) ?? 4749), str(a.host) ?? "127.0.0.1");
|
|
1792
1932
|
else if (cmd === "guide" || cmd === "llms") process.stdout.write(GUIDE);
|
|
1793
1933
|
else if (cmd === "themes") process.stdout.write(THEME_NAMES.join("\n") + "\n");
|
|
1794
|
-
else if (existsSync(cmd))
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1934
|
+
else if (existsSync(cmd) || looksInline(cmd)) {
|
|
1935
|
+
const r = {
|
|
1936
|
+
...a,
|
|
1937
|
+
_: ["render", ...a._]
|
|
1938
|
+
};
|
|
1939
|
+
takeInline(r);
|
|
1940
|
+
cmdRender(r);
|
|
1941
|
+
} else throw new Error(`unknown command "${cmd}"`);
|
|
1799
1942
|
} catch (e) {
|
|
1800
1943
|
process.stderr.write(`yuhwa: ${e.message}\n`);
|
|
1801
1944
|
process.exitCode = 1;
|