yuhwa 1.7.0 → 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.
Files changed (49) hide show
  1. package/dist/astro.d.ts +1 -1
  2. package/dist/astro.js +1 -1
  3. package/dist/browser.d.ts +2 -2
  4. package/dist/browser.js +4 -4
  5. package/dist/canvas.js +1 -1
  6. package/dist/cli.js +85 -31
  7. package/dist/editor/assets/index-B7LvqDCZ.js +689 -0
  8. package/dist/editor/assets/lsp.worker-BCEqba2A.js +36 -0
  9. package/dist/editor/index.html +5 -14
  10. package/dist/{figure-BCgY5uVw.d.ts → figure-Cn5Ls_0U.d.ts} +1 -1
  11. package/dist/{index-HrJIjhCS.d.ts → index-0qJC6glR.d.ts} +36 -2
  12. package/dist/index.d.ts +2 -2
  13. package/dist/index.js +4 -4
  14. package/dist/ironmark.d.ts +1 -1
  15. package/dist/ironmark.js +1 -1
  16. package/dist/{parse-B4TOA3gC.js → lex-B95erg9Z.js} +230 -2180
  17. package/dist/lsp-browser.d.ts +2 -2
  18. package/dist/lsp-browser.js +1 -1
  19. package/dist/lsp-node.js +649 -640
  20. package/dist/lsp-server.d.ts +1 -1
  21. package/dist/lsp-server.js +1 -1
  22. package/dist/lsp.d.ts +7 -2
  23. package/dist/lsp.js +1 -1
  24. package/dist/markdown-it.d.ts +1 -1
  25. package/dist/markdown-it.js +2 -2
  26. package/dist/{node-BerWCoTJ.js → node-D1wvmy4u.js} +3 -3
  27. package/dist/{plugin-DD34oni4.d.ts → plugin-COlq-EO9.d.ts} +3 -35
  28. package/dist/{plugin-C3Y1OsdZ.js → plugin-D5lzFpzv.js} +9 -2
  29. package/dist/plugin.d.ts +1 -1
  30. package/dist/plugin.js +2 -2
  31. package/dist/{raster-C7BAAu8q.js → raster-Cy1jbYgz.js} +1 -1
  32. package/dist/remark.d.ts +1 -1
  33. package/dist/remark.js +1 -1
  34. package/dist/satteri.d.ts +1 -1
  35. package/dist/satteri.js +1 -1
  36. package/dist/{server-G_aomh0d.js → server-BrO0eGn8.js} +2 -2
  37. package/dist/{server-Bb5_7tRV.d.ts → server-C54CveoI.d.ts} +1 -1
  38. package/dist/{service-wlaqtXGz.d.ts → service-Bjx4ZpF3.d.ts} +1 -17
  39. package/dist/{service-CihRTF6I.js → service-C1M9jbzR.js} +652 -643
  40. package/dist/{shared-DiOHyqG5.js → shared-BsaZuOAh.js} +5655 -5465
  41. package/dist/{src-DOnn1bDA.js → src-DXSUoZMj.js} +2934 -801
  42. package/dist/vite.d.ts +1 -1
  43. package/dist/vite.js +2 -3
  44. package/dist/vuepress.d.ts +1 -1
  45. package/dist/vuepress.js +1 -1
  46. package/dist/yuhwa.iife.js +56 -56
  47. package/package.json +1 -1
  48. package/dist/editor/assets/index-Qlffmtt7.js +0 -689
  49. package/dist/editor/assets/lsp.worker-waLMr9u-.js +0 -36
package/dist/astro.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { t as YuhwaDocsOptions } from "./figure-BCgY5uVw.js";
1
+ import { t as YuhwaDocsOptions } from "./figure-Cn5Ls_0U.js";
2
2
  interface Watcher {
3
3
  on: (event: "change" | "add", fn: (file: string) => void) => unknown;
4
4
  add: (files: string[]) => unknown;
package/dist/astro.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import remarkYuhwa from "./remark.js";
2
2
  import satteriYuhwa from "./satteri.js";
3
- import { n as onTrack, o as clientImports, r as pagesUsing } from "./node-BerWCoTJ.js";
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 PartAction, $t as RAMPS, A as Box, At as recolor, B as LabelRef, C as SETTING_VALUES, Cn as approxMeasure, Ct as RowCtx, Dt as YuhwaPlugin, E as parse, Et as StatementKind, F as Direction, Ft as ShapeKind, G as Layout, Gt as renderSegs, H as LaidGroup, I as EdgeDecl, It as renderHead, J as NodeOverride, K as LayoutOverrides, Kt as segsW, L as EdgeOverride, Lt as InkColors, M as Curve, Mt as unuse, N as Diagnostic, Nt as use, O as Align, Ot as optionKind, P as Diagram, Pt as MarkerKind, Q as PanelPart, R as GroupDecl, Rt as Seg, S as SETTING_HELP, St as PanelOption, T as joinPath, Tt as RowPaint, U as LaidNode, Ut as parseInline, V as LaidEdge, W as LaidPanel, X as PanelHandle, Y as PanelDecl, Yt as tspans, Z as PanelOverride, Zt as LineStyle, _ as setTrailingProp, _n as isToneOrHex, a as portOn, an as Theme, at as ResolvedNodeStyle, b as PANELS, bt as PanelCtx, c as LexedLine, cn as createTheme, ct as SourceRef, d as blockBraces, dn as fontStack, et as PartChange, f as lex, fn as getTheme, ft as groupPath, g as setLineProp, gn as isSafeLink, h as serializeProps, hn as isSafeCss, in as TONES, it as ResolvedEdgeStyle, j as Component, jt as registry, k as AlignSide, kt as perPass, l as Tok, lt as dashFor, m as parseProps, mn as isGenericFont, mt as lineStyle, nn as THEME_KEYS, nt as Point, on as ThemeInput, ot as ShapeName, p as onlyColor, pt as groupProp, q as NodeDecl, r as SHAPES, rn as THEME_NAMES, rt as Props, st as Side, tn as THEMES, tt as PartEdit, u as TokKind, un as fontFamilies, v as splitTrailingProps, vn as ramp, vt as Decoration, w as isYuhwaPath, wn as canvasMeasure, wt as RowKind, x as ParseOptions, xn as themeNames, xt as PanelKind, y as KNOWN_SETTINGS, yn as registerTheme, yt as FrameKind, z as HeadKind, zt as esc } from "./plugin-DD34oni4.js";
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 DiagramJSON, et as editPart, f as mindmap, ft as JsonResult, g as sequence, 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, w as shapes, x as charts, y as frames, z as MD_LANGUAGES } from "./index-HrJIjhCS.js";
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 kanban, B as frames, C as isMermaid, D as GRID, E as layout, F as chart, G as shapes, H as charts, I as timeline, L as sequence, M as gantt, N as mindmap, O as builtins, P as git, R as legend, S as fromMermaid, T as renderSvg, U as themes, V as tables, W as markers, _ as setPartTone, a as MD_LANGUAGES, b as writeLayout, d as addEdge, f as addNode, g as setLabel, h as removeElement, i as GUIDE, j as quadrant, k as treeview, l as processMarkdown, m as formatLayout, n as render$1, o as findBlocks, p as editPart, r as toSource, t as hash, u as replaceBlockSource, v as setProp, w as fromJSON, x as writePanelDrag, y as setSetting, z as footer } from "./src-DOnn1bDA.js";
2
- import { a as perPass, c as unuse, i as optionKind, l as use, n as approxMeasure, o as recolor, r as canvasMeasure, s as registry } from "./plugin-C3Y1OsdZ.js";
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-C7BAAu8q.js";
5
- import { $ as SHAPES, A as lex, B as BOOLS, Cn as isToneOrHex, Dn as themeNames, Dt as groupProp, Et as groupPath, F as serializeProps, G as NODE_PROPS, Gt as parseInline, H as EDGE_PROPS, J as PANEL_PROP_HELP, Jt as renderSegs, K as NUMBERS, L as setLineProp, M as parseProps, Ot as lineStyle, R as setTrailingProp, Sn as isSafeLink, Tn as registerTheme, U as ENUMS, V as COLORS, W as GROUP_PROPS, X as lint, Zt as segsW, _n as fontStack, bn as isGenericFont, bt as dashFor, c as joinPath, dn as THEME_NAMES, fn as TONES, ft as renderHead, gn as fontFamilies, gt as ALIGN_SIDES, i as SETTING_VALUES, in as tspans, j as onlyColor, k as blockBraces, l as parse, ln as THEMES, mn as createTheme, n as PANELS, nt as portOn, q as PANEL_PROPS, r as SETTING_HELP, s as isYuhwaPath, sn as RAMPS, t as KNOWN_SETTINGS, u as unquote, un as THEME_KEYS, vn as getTheme, wn as ramp, xn as isSafeCss, z as splitTrailingProps, zt as esc } from "./parse-B4TOA3gC.js";
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-C7BAAu8q.js").then((n) => n.i);
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 { C as SETTING_VALUES, D as unquote, F as GROUP_PROPS, I as NODE_PROPS, K as esc, M as COLORS, N as EDGE_PROPS, P as ENUMS, Q as isSafeCss, R as PANEL_PROPS, T as joinPath, U as ALIGN_SIDES_HINT, V as SHAPES, X as THEME_NAMES, Y as THEME_KEYS, Z as TONES, _ as canvasMeasure, a as formatPage, b as KNOWN_SETTINGS, c as diskResolve, d as MD_LANGUAGES, f as findBlocks, g as replaceBlockSource, h as processMarkdown, i as format, l as render$1, m as pageBlocks, p as isMarkdown, s as tidy, t as VERSION, u as toSource, v as optionKind, w as isYuhwaPath, y as registry } from "./shared-DiOHyqG5.js";
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";
@@ -1026,12 +1026,25 @@ function viewUrl(source, base) {
1026
1026
  function decodeSource(encoded, compressed) {
1027
1027
  const buf = Buffer.from(encoded.replace(/\.svg$/, ""), "base64url");
1028
1028
  if (!compressed) return buf.toString("utf8");
1029
+ const opts = { maxOutputLength: MAX_BODY };
1030
+ const tooLarge = (e) => e.code === "ERR_BUFFER_TOO_LARGE";
1029
1031
  try {
1030
- return inflateSync(buf).toString("utf8");
1031
- } catch {
1032
- return inflateRawSync(buf).toString("utf8");
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;
1033
1041
  }
1034
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)};`);
1035
1048
  function readBody(req, max = MAX_BODY) {
1036
1049
  return new Promise((ok, fail) => {
1037
1050
  let size = 0;
@@ -1088,7 +1101,7 @@ function handler(req, res) {
1088
1101
  res.setHeader("content-security-policy", "default-src 'none'; style-src 'unsafe-inline'; img-src data:");
1089
1102
  res.setHeader("x-content-type-options", "nosniff");
1090
1103
  res.setHeader("x-yuhwa-format", r.format);
1091
- 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)));
1092
1105
  if (cache && !errors.length) res.setHeader("cache-control", "public, max-age=31536000, immutable");
1093
1106
  res.end(r.svg);
1094
1107
  };
@@ -1112,7 +1125,7 @@ function handler(req, res) {
1112
1125
  try {
1113
1126
  if (req.method === "GET") {
1114
1127
  if (path === "/") {
1115
- 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"}`)));
1116
1129
  return;
1117
1130
  }
1118
1131
  if (path === "/llms.txt" || path === "/guide") {
@@ -1161,7 +1174,7 @@ function handler(req, res) {
1161
1174
  }
1162
1175
  fail(404, `not found: ${req.method} ${path} (see GET /)`);
1163
1176
  } catch (e) {
1164
- fail(400, e.message);
1177
+ fail(e.status ?? 400, e.message);
1165
1178
  }
1166
1179
  }
1167
1180
  function serve(port, host) {
@@ -1460,21 +1473,24 @@ if (typeof document !== "undefined") {
1460
1473
  const HELP = `yuhwa — diagrams that look good and stay where you put them
1461
1474
 
1462
1475
  Usage
1463
- yuhwa render <file|-> [-o out.svg|out.html|out.png] [--html] [--png] [--scale 2] [--font f] [--no-system-fonts] [--theme name] [--block n]
1464
- yuhwa check <file|-...> [--json] [--strict] [--lang yuhwa,yu]
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]
1465
1478
  yuhwa lint <file...> [--fix] [--json] [--lang yuhwa,yu]
1466
- yuhwa convert <file.mmd|file.json|-> [-o out.yu]
1479
+ yuhwa convert <file.mmd|file.json|-|source> [-e source] [-o out.yu]
1467
1480
  yuhwa md <file.md...> [--out-dir diagrams] [--dark] [--keep-fences] [--view[=base]]
1468
1481
  yuhwa edit <file.yu|file.md> [--block n] [--port 4747] [--no-open]
1469
1482
  yuhwa serve [--port 4749] [--host 127.0.0.1]
1470
- yuhwa url <file|-> [--base http://localhost:4749] [--view]
1471
- yuhwa <file> same as yuhwa render <file>
1483
+ yuhwa url <file|-|source> [-e source] [--base http://localhost:4749] [--view]
1484
+ yuhwa <file|source> same as yuhwa render <file|source>
1472
1485
  yuhwa guide language reference for AI tools (alias: llms)
1473
1486
  yuhwa themes
1474
1487
  yuhwa --version | -v
1475
1488
  yuhwa --help | -h
1476
1489
 
1477
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.
1478
1494
 
1479
1495
  render Render one diagram to SVG (stdout unless -o is given). From a
1480
1496
  Markdown file it renders block --block n (from 0, default 0).
@@ -1508,6 +1524,7 @@ guide Print the language reference (same as llms.txt). AI agents: read
1508
1524
  `;
1509
1525
  /** flags that take a value; repeatable ones collect every value in a list */
1510
1526
  const VALUE_FLAGS = /* @__PURE__ */ new Set([
1527
+ "source",
1511
1528
  "theme",
1512
1529
  "out",
1513
1530
  "out-dir",
@@ -1525,6 +1542,7 @@ function parseArgs(argv) {
1525
1542
  for (let i = 0; i < argv.length; i++) {
1526
1543
  const s = argv[i];
1527
1544
  if (s === "-o") a.out = argv[++i];
1545
+ else if (s === "-e") a.source = argv[++i] ?? "";
1528
1546
  else if (s === "-h") a.help = true;
1529
1547
  else if (s === "-v") a.version = true;
1530
1548
  else if (s.startsWith("--")) {
@@ -1554,7 +1572,7 @@ function cmdRender(a) {
1554
1572
  ({source, line: at} = b);
1555
1573
  }
1556
1574
  const r = renderAs(a, file, source);
1557
- printDiagnostics(file, shiftLines(r.diagnostics, at));
1575
+ printDiagnostics(file, offsetLines(r.diagnostics, at));
1558
1576
  const out = str(a.out);
1559
1577
  const kind = a.html || /\.html?$/i.test(out ?? "") ? "html" : a.png || /\.png$/i.test(out ?? "") ? "png" : "svg";
1560
1578
  if (kind === "png") writeOut(out, svgToPng(r.svg, {
@@ -1571,11 +1589,30 @@ function cmdRender(a) {
1571
1589
  } else writeOut(out, r.svg + "\n");
1572
1590
  if (!passes(r.diagnostics)) process.exitCode = 1;
1573
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;
1610
+ }
1574
1611
  const fileOpts = (file) => ({
1575
1612
  resolve: diskResolve,
1576
- file: file === "-" ? void 0 : file
1613
+ file: file === "-" || inline.has(file) ? void 0 : file
1577
1614
  });
1578
- const readInput = (file) => file === "-" ? readFileSync(0, "utf8") : readFileSync(file, "utf8");
1615
+ const readInput = (file) => inline.get(file) ?? (file === "-" ? readFileSync(0, "utf8") : readFileSync(file, "utf8"));
1579
1616
  function writeOut(out, text) {
1580
1617
  if (!out) {
1581
1618
  process.stdout.write(text);
@@ -1586,7 +1623,7 @@ function writeOut(out, text) {
1586
1623
  process.stderr.write(`wrote ${out}\n`);
1587
1624
  }
1588
1625
  /** block diagnostics carry block lines; `at` is the opening fence's page line */
1589
- const shiftLines = (ds, at) => at ? ds.map((d) => ({
1626
+ const offsetLines = (ds, at) => at ? ds.map((d) => ({
1590
1627
  ...d,
1591
1628
  line: at + Math.max(d.line, 1)
1592
1629
  })) : ds;
@@ -1609,7 +1646,7 @@ function checkPage(file, a) {
1609
1646
  };
1610
1647
  const entries = blocks.map((b) => {
1611
1648
  const r = renderAs(a, file, b.source);
1612
- for (const d of shiftLines(r.diagnostics, b.line)) diagnostics.push({
1649
+ for (const d of offsetLines(r.diagnostics, b.line)) diagnostics.push({
1613
1650
  ...d,
1614
1651
  block: b.index
1615
1652
  });
@@ -1669,7 +1706,7 @@ function cmdCheck(a) {
1669
1706
  function cmdLint(a) {
1670
1707
  const lintOne = (source, file, at = 0) => {
1671
1708
  const r = renderAs(a, file, source);
1672
- return shiftLines([...r.diagnostics, ...r.format === "yuhwa" ? tidy(source, r.diagram) : []], at);
1709
+ return offsetLines([...r.diagnostics, ...r.format === "yuhwa" ? tidy(source, r.diagram) : []], at);
1673
1710
  };
1674
1711
  perFile(a, "lint", (file) => {
1675
1712
  let diagnostics;
@@ -1869,22 +1906,39 @@ function main() {
1869
1906
  const cmd = a._[0];
1870
1907
  try {
1871
1908
  if (a.version || cmd === "version") process.stdout.write(VERSION + "\n");
1872
- else if (!cmd || cmd === "help" || a.help) process.stdout.write(HELP);
1873
- else if (cmd === "render") cmdRender(a);
1874
- else if (cmd === "md") cmdMd(a);
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);
1875
1920
  else if (cmd === "edit") cmdEdit(a);
1876
- else if (cmd === "check") cmdCheck(a);
1877
- else if (cmd === "lint") cmdLint(a);
1878
- else if (cmd === "convert") cmdConvert(a);
1879
- else if (cmd === "url") cmdUrl(a);
1880
- else if (cmd === "serve") serve(Number(str(a.port) ?? 4749), str(a.host) ?? "127.0.0.1");
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");
1881
1932
  else if (cmd === "guide" || cmd === "llms") process.stdout.write(GUIDE);
1882
1933
  else if (cmd === "themes") process.stdout.write(THEME_NAMES.join("\n") + "\n");
1883
- else if (existsSync(cmd)) cmdRender({
1884
- ...a,
1885
- _: ["render", ...a._]
1886
- });
1887
- else throw new Error(`unknown command "${cmd}"`);
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}"`);
1888
1942
  } catch (e) {
1889
1943
  process.stderr.write(`yuhwa: ${e.message}\n`);
1890
1944
  process.exitCode = 1;