yuhwa 1.7.0 → 1.8.1
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 +75 -23
- package/dist/editor/assets/index-CzZbWTHS.js +689 -0
- package/dist/editor/assets/lsp.worker-DE33sIum.js +36 -0
- package/dist/editor/index.html +5 -14
- package/dist/{figure-BCgY5uVw.d.ts → figure-Cn5Ls_0U.d.ts} +1 -1
- package/dist/{index-HrJIjhCS.d.ts → index-0qJC6glR.d.ts} +36 -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-B4TOA3gC.js → lex-D4UEbl0Y.js} +230 -2186
- 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-BerWCoTJ.js → node-B4v84i-l.js} +3 -3
- package/dist/{plugin-C3Y1OsdZ.js → plugin-Bp8z1wBE.js} +9 -2
- package/dist/{plugin-DD34oni4.d.ts → plugin-COlq-EO9.d.ts} +3 -35
- package/dist/plugin.d.ts +1 -1
- package/dist/plugin.js +2 -2
- package/dist/{raster-C7BAAu8q.js → raster-DI66_cLD.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-Bb5_7tRV.d.ts → server-C54CveoI.d.ts} +1 -1
- package/dist/{server-G_aomh0d.js → server-I2YzR5H3.js} +2 -2
- package/dist/{service-wlaqtXGz.d.ts → service-Bjx4ZpF3.d.ts} +1 -17
- package/dist/{service-CihRTF6I.js → service-DU8fxD4h.js} +652 -643
- package/dist/{shared-DiOHyqG5.js → shared-B153eecg.js} +6222 -6036
- package/dist/{src-DOnn1bDA.js → src-De2RtCva.js} +2937 -802
- 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 +56 -56
- package/package.json +1 -1
- package/dist/editor/assets/index-Qlffmtt7.js +0 -689
- package/dist/editor/assets/lsp.worker-waLMr9u-.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-B4v84i-l.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 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-
|
|
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-De2RtCva.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-Bp8z1wBE.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 { $ as
|
|
4
|
+
import { a as svgFamilies, c as swapForRaster, n as embedFonts, r as loadFonts, s as svgToCanvas } from "./raster-DI66_cLD.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-D4UEbl0Y.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-DI66_cLD.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
|
|
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-B153eecg.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,21 @@ 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
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
return
|
|
1029
|
+
const opts = { maxOutputLength: MAX_BODY };
|
|
1030
|
+
let err;
|
|
1031
|
+
for (const inflate of [inflateSync, inflateRawSync]) try {
|
|
1032
|
+
return inflate(buf, opts).toString("utf8");
|
|
1033
|
+
} catch (e) {
|
|
1034
|
+
if (e.code === "ERR_BUFFER_TOO_LARGE") throw Object.assign(/* @__PURE__ */ new Error("source too large"), { status: 413 });
|
|
1035
|
+
err = e;
|
|
1033
1036
|
}
|
|
1037
|
+
throw err;
|
|
1034
1038
|
}
|
|
1039
|
+
/** header values must be Latin-1 without controls: keep printable ASCII, write the rest as `\u` escapes */
|
|
1040
|
+
function headerSafe(text) {
|
|
1041
|
+
return text.replace(/[^\x20-\x7e]/g, (c) => c === "\n" ? " " : `\\u${c.charCodeAt(0).toString(16).padStart(4, "0")}`);
|
|
1042
|
+
}
|
|
1043
|
+
const escHtml = (s) => s.replace(/[&<>"']/g, (c) => `&#${c.charCodeAt(0)};`);
|
|
1035
1044
|
function readBody(req, max = MAX_BODY) {
|
|
1036
1045
|
return new Promise((ok, fail) => {
|
|
1037
1046
|
let size = 0;
|
|
@@ -1088,7 +1097,7 @@ function handler(req, res) {
|
|
|
1088
1097
|
res.setHeader("content-security-policy", "default-src 'none'; style-src 'unsafe-inline'; img-src data:");
|
|
1089
1098
|
res.setHeader("x-content-type-options", "nosniff");
|
|
1090
1099
|
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));
|
|
1100
|
+
if (errors.length) res.setHeader("x-yuhwa-errors", headerSafe(errors.map((d) => `${d.line}: ${d.message}`).join(" | ").slice(0, 2e3)));
|
|
1092
1101
|
if (cache && !errors.length) res.setHeader("cache-control", "public, max-age=31536000, immutable");
|
|
1093
1102
|
res.end(r.svg);
|
|
1094
1103
|
};
|
|
@@ -1112,7 +1121,7 @@ function handler(req, res) {
|
|
|
1112
1121
|
try {
|
|
1113
1122
|
if (req.method === "GET") {
|
|
1114
1123
|
if (path === "/") {
|
|
1115
|
-
res.writeHead(200, { "content-type": "text/html; charset=utf-8" }).end(HOME(`http://${req.headers.host ?? "localhost"}`));
|
|
1124
|
+
res.writeHead(200, { "content-type": "text/html; charset=utf-8" }).end(HOME(escHtml(`http://${req.headers.host ?? "localhost"}`)));
|
|
1116
1125
|
return;
|
|
1117
1126
|
}
|
|
1118
1127
|
if (path === "/llms.txt" || path === "/guide") {
|
|
@@ -1161,7 +1170,7 @@ function handler(req, res) {
|
|
|
1161
1170
|
}
|
|
1162
1171
|
fail(404, `not found: ${req.method} ${path} (see GET /)`);
|
|
1163
1172
|
} catch (e) {
|
|
1164
|
-
fail(400, e.message);
|
|
1173
|
+
fail(e.status ?? 400, e.message);
|
|
1165
1174
|
}
|
|
1166
1175
|
}
|
|
1167
1176
|
function serve(port, host) {
|
|
@@ -1460,21 +1469,24 @@ if (typeof document !== "undefined") {
|
|
|
1460
1469
|
const HELP = `yuhwa — diagrams that look good and stay where you put them
|
|
1461
1470
|
|
|
1462
1471
|
Usage
|
|
1463
|
-
yuhwa render <file
|
|
1464
|
-
yuhwa check <file
|
|
1472
|
+
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]
|
|
1473
|
+
yuhwa check <file|-|source...> [-e source] [--json] [--strict] [--lang yuhwa,yu]
|
|
1465
1474
|
yuhwa lint <file...> [--fix] [--json] [--lang yuhwa,yu]
|
|
1466
|
-
yuhwa convert <file.mmd|file.json
|
|
1475
|
+
yuhwa convert <file.mmd|file.json|-|source> [-e source] [-o out.yu]
|
|
1467
1476
|
yuhwa md <file.md...> [--out-dir diagrams] [--dark] [--keep-fences] [--view[=base]]
|
|
1468
1477
|
yuhwa edit <file.yu|file.md> [--block n] [--port 4747] [--no-open]
|
|
1469
1478
|
yuhwa serve [--port 4749] [--host 127.0.0.1]
|
|
1470
|
-
yuhwa url <file
|
|
1471
|
-
yuhwa <file>
|
|
1479
|
+
yuhwa url <file|-|source> [-e source] [--base http://localhost:4749] [--view]
|
|
1480
|
+
yuhwa <file|source> same as yuhwa render <file|source>
|
|
1472
1481
|
yuhwa guide language reference for AI tools (alias: llms)
|
|
1473
1482
|
yuhwa themes
|
|
1474
1483
|
yuhwa --version | -v
|
|
1475
1484
|
yuhwa --help | -h
|
|
1476
1485
|
|
|
1477
1486
|
Input can be yuhwa, a Mermaid flowchart or JSON; the format is detected.
|
|
1487
|
+
Instead of a file, give the source itself: -e/--source "a -> b", or as the
|
|
1488
|
+
argument when no such file exists and it reads as source (an arrow or a
|
|
1489
|
+
newline), like yuhwa render "a -> b". Imports resolve from the current folder.
|
|
1478
1490
|
|
|
1479
1491
|
render Render one diagram to SVG (stdout unless -o is given). From a
|
|
1480
1492
|
Markdown file it renders block --block n (from 0, default 0).
|
|
@@ -1508,6 +1520,7 @@ guide Print the language reference (same as llms.txt). AI agents: read
|
|
|
1508
1520
|
`;
|
|
1509
1521
|
/** flags that take a value; repeatable ones collect every value in a list */
|
|
1510
1522
|
const VALUE_FLAGS = /* @__PURE__ */ new Set([
|
|
1523
|
+
"source",
|
|
1511
1524
|
"theme",
|
|
1512
1525
|
"out",
|
|
1513
1526
|
"out-dir",
|
|
@@ -1525,6 +1538,7 @@ function parseArgs(argv) {
|
|
|
1525
1538
|
for (let i = 0; i < argv.length; i++) {
|
|
1526
1539
|
const s = argv[i];
|
|
1527
1540
|
if (s === "-o") a.out = argv[++i];
|
|
1541
|
+
else if (s === "-e") a.source = argv[++i] ?? "";
|
|
1528
1542
|
else if (s === "-h") a.help = true;
|
|
1529
1543
|
else if (s === "-v") a.version = true;
|
|
1530
1544
|
else if (s.startsWith("--")) {
|
|
@@ -1554,7 +1568,7 @@ function cmdRender(a) {
|
|
|
1554
1568
|
({source, line: at} = b);
|
|
1555
1569
|
}
|
|
1556
1570
|
const r = renderAs(a, file, source);
|
|
1557
|
-
printDiagnostics(file,
|
|
1571
|
+
printDiagnostics(file, offsetLines(r.diagnostics, at));
|
|
1558
1572
|
const out = str(a.out);
|
|
1559
1573
|
const kind = a.html || /\.html?$/i.test(out ?? "") ? "html" : a.png || /\.png$/i.test(out ?? "") ? "png" : "svg";
|
|
1560
1574
|
if (kind === "png") writeOut(out, svgToPng(r.svg, {
|
|
@@ -1571,11 +1585,30 @@ function cmdRender(a) {
|
|
|
1571
1585
|
} else writeOut(out, r.svg + "\n");
|
|
1572
1586
|
if (!passes(r.diagnostics)) process.exitCode = 1;
|
|
1573
1587
|
}
|
|
1588
|
+
/** sources given on the command line, by the name that stands for them in `a._` and in diagnostics */
|
|
1589
|
+
const inline = /* @__PURE__ */ new Map();
|
|
1590
|
+
/** no such file, but it reads as source: an arrow, a `--` edge or a newline */
|
|
1591
|
+
const looksInline = (arg) => !existsSync(arg) && /\n|->|<-|--|=>/.test(arg);
|
|
1592
|
+
/** `-e`/`--source` and source-like arguments become named inline inputs */
|
|
1593
|
+
function takeInline(a) {
|
|
1594
|
+
const given = typeof a.source === "string" ? [stash(a.source)] : [];
|
|
1595
|
+
const args = a._.slice(1).map((x) => x !== "-" && looksInline(x) ? stash(x) : x);
|
|
1596
|
+
a._ = [
|
|
1597
|
+
a._[0],
|
|
1598
|
+
...given,
|
|
1599
|
+
...args
|
|
1600
|
+
];
|
|
1601
|
+
}
|
|
1602
|
+
function stash(source) {
|
|
1603
|
+
const name = inline.size ? `<source ${inline.size + 1}>` : "<source>";
|
|
1604
|
+
inline.set(name, source);
|
|
1605
|
+
return name;
|
|
1606
|
+
}
|
|
1574
1607
|
const fileOpts = (file) => ({
|
|
1575
1608
|
resolve: diskResolve,
|
|
1576
|
-
file: file === "-" ? void 0 : file
|
|
1609
|
+
file: file === "-" || inline.has(file) ? void 0 : file
|
|
1577
1610
|
});
|
|
1578
|
-
const readInput = (file) => file === "-" ? readFileSync(0, "utf8") : readFileSync(file, "utf8");
|
|
1611
|
+
const readInput = (file) => inline.get(file) ?? (file === "-" ? readFileSync(0, "utf8") : readFileSync(file, "utf8"));
|
|
1579
1612
|
function writeOut(out, text) {
|
|
1580
1613
|
if (!out) {
|
|
1581
1614
|
process.stdout.write(text);
|
|
@@ -1586,7 +1619,7 @@ function writeOut(out, text) {
|
|
|
1586
1619
|
process.stderr.write(`wrote ${out}\n`);
|
|
1587
1620
|
}
|
|
1588
1621
|
/** block diagnostics carry block lines; `at` is the opening fence's page line */
|
|
1589
|
-
const
|
|
1622
|
+
const offsetLines = (ds, at) => at ? ds.map((d) => ({
|
|
1590
1623
|
...d,
|
|
1591
1624
|
line: at + Math.max(d.line, 1)
|
|
1592
1625
|
})) : ds;
|
|
@@ -1609,7 +1642,7 @@ function checkPage(file, a) {
|
|
|
1609
1642
|
};
|
|
1610
1643
|
const entries = blocks.map((b) => {
|
|
1611
1644
|
const r = renderAs(a, file, b.source);
|
|
1612
|
-
for (const d of
|
|
1645
|
+
for (const d of offsetLines(r.diagnostics, b.line)) diagnostics.push({
|
|
1613
1646
|
...d,
|
|
1614
1647
|
block: b.index
|
|
1615
1648
|
});
|
|
@@ -1669,7 +1702,7 @@ function cmdCheck(a) {
|
|
|
1669
1702
|
function cmdLint(a) {
|
|
1670
1703
|
const lintOne = (source, file, at = 0) => {
|
|
1671
1704
|
const r = renderAs(a, file, source);
|
|
1672
|
-
return
|
|
1705
|
+
return offsetLines([...r.diagnostics, ...r.format === "yuhwa" ? tidy(source, r.diagram) : []], at);
|
|
1673
1706
|
};
|
|
1674
1707
|
perFile(a, "lint", (file) => {
|
|
1675
1708
|
let diagnostics;
|
|
@@ -1864,10 +1897,33 @@ function cmdEdit(a) {
|
|
|
1864
1897
|
if (!a["no-open"]) openBrowser(url);
|
|
1865
1898
|
});
|
|
1866
1899
|
}
|
|
1900
|
+
const COMMANDS = /* @__PURE__ */ new Set([
|
|
1901
|
+
"render",
|
|
1902
|
+
"md",
|
|
1903
|
+
"edit",
|
|
1904
|
+
"check",
|
|
1905
|
+
"lint",
|
|
1906
|
+
"convert",
|
|
1907
|
+
"url",
|
|
1908
|
+
"serve",
|
|
1909
|
+
"guide",
|
|
1910
|
+
"llms",
|
|
1911
|
+
"themes"
|
|
1912
|
+
]);
|
|
1913
|
+
/** the commands that take diagram source on the command line */
|
|
1914
|
+
const TAKES_INLINE = /* @__PURE__ */ new Set([
|
|
1915
|
+
"render",
|
|
1916
|
+
"check",
|
|
1917
|
+
"convert",
|
|
1918
|
+
"url"
|
|
1919
|
+
]);
|
|
1867
1920
|
function main() {
|
|
1868
1921
|
const a = parseArgs(process.argv.slice(2));
|
|
1922
|
+
const first = a._[0];
|
|
1923
|
+
if (first ? !COMMANDS.has(first) && (existsSync(first) || looksInline(first)) : typeof a.source === "string") a._.unshift("render");
|
|
1869
1924
|
const cmd = a._[0];
|
|
1870
1925
|
try {
|
|
1926
|
+
if (TAKES_INLINE.has(cmd)) takeInline(a);
|
|
1871
1927
|
if (a.version || cmd === "version") process.stdout.write(VERSION + "\n");
|
|
1872
1928
|
else if (!cmd || cmd === "help" || a.help) process.stdout.write(HELP);
|
|
1873
1929
|
else if (cmd === "render") cmdRender(a);
|
|
@@ -1880,10 +1936,6 @@ function main() {
|
|
|
1880
1936
|
else if (cmd === "serve") serve(Number(str(a.port) ?? 4749), str(a.host) ?? "127.0.0.1");
|
|
1881
1937
|
else if (cmd === "guide" || cmd === "llms") process.stdout.write(GUIDE);
|
|
1882
1938
|
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
1939
|
else throw new Error(`unknown command "${cmd}"`);
|
|
1888
1940
|
} catch (e) {
|
|
1889
1941
|
process.stderr.write(`yuhwa: ${e.message}\n`);
|