yuhwa 1.0.1 → 1.0.2

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 CHANGED
@@ -1,4 +1,4 @@
1
- import { t as YuhwaDocsOptions } from "./figure-Cp1kIReq.js";
1
+ import { t as YuhwaDocsOptions } from "./figure-BZHIKnxv.js";
2
2
  interface SetupParams {
3
3
  updateConfig: (config: {
4
4
  markdown: {
package/dist/browser.d.ts CHANGED
@@ -8,7 +8,7 @@
8
8
  * <yuhwa-diagram src="docs/arch.yuhwa"></yuhwa-diagram>
9
9
  * el.source = 'a -> b' // re-renders
10
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-DY1ZuIhZ.js";
11
+ import { $ as PANELS, $t as PanelCtx, A as MdBlock, An as isSafeLink, At as Layout, B as setProp, Bt as PartEdit, C as NODE_PROPS, Cn as THEME_NAMES, Ct as GroupDecl, D as ConvertResult, Dn as createTheme, Dt as LaidGroup, E as lint, En as ThemeInput, Et as LaidEdge, F as replaceBlockSource, Fn as approxMeasure, Ft as PanelHandle, G as lineStyle, Gt as ShapeName, H as writeLayout, Ht as Props, I as editPart, In as canvasMeasure, It as PanelOverride, J as JsonResult, Jt as GRID, K as SHAPES, Kt as Side, L as formatLayout, Lt as PanelPart, M as MdResult, Mn as ramp, Mt as NodeDecl, N as findBlocks, Nn as registerTheme, Nt as NodeOverride, O as fromMermaid, On as getTheme, Ot as LaidNode, P as processMarkdown, Pn as themeNames, Pt as PanelDecl, Q as LexedLine, Qt as FrameKind, R as setLabel, Rt as PartAction, S as GROUP_PROPS, Sn as THEME_KEYS, St as EdgeOverride, T as PANEL_PROPS, Tn as Theme, Tt as LabelRef, U as writePanelDrag, Ut as ResolvedEdgeStyle, V as setSetting, Vt as Point, W as dashFor, Wt as ResolvedNodeStyle, X as renderSvg, Xt as layout, Y as fromJSON, Yt as groupPath, Z as KNOWN_SETTINGS, Zt as Decoration, _ as themes, _n as segsW, _t as Curve, an as YuhwaPlugin, at as isYuhwaPath, b as EDGE_PROPS, bn as RAMPS, bt as Direction, c as git, cn as registry, ct as onlyColor, d as sequence, dn as ShapeKind, dt as serializeProps, en as PanelKind, et as ParseOptions, f as legend, fn as renderHead, ft as setLineProp, g as charts, gn as renderSegs, gt as Component, h as tables, hn as parseInline, ht as Box, i as hash, in as StatementKind, it as blockBraces, j as MdOptions, jn as isToneOrHex, jt as LayoutOverrides, k as isMermaid, kn as isSafeCss, kt as LaidPanel, l as chart, ln as use, lt as parse, m as frames, mn as Seg, mt as splitTrailingProps, n as Options, nn as RowKind, nt as Tok, o as toSource, on as perPass, ot as joinPath, p as footer, pn as InkColors, pt as setTrailingProp, q as DiagramJSON, qt as SourceRef, r as Result, rn as RowPaint, rt as TokKind, s as builtins, sn as recolor, st as lex, t as InputFormat, tn as RowCtx, tt as SETTING_VALUES, u as timeline, un as MarkerKind, ut as parseProps, v as GUIDE, vn as tspans, vt as Diagnostic, w as NUMBERS, wn as TONES, wt as HeadKind, x as ENUMS, xn as THEMES, xt as EdgeDecl, y as BOOLS, yn as LineStyle, yt as Diagram, z as setPartTone, zt as PartChange } from "./index-Dl845tUQ.js";
12
12
  export declare function render(source: string, opts?: Options): Result;
13
13
  /**
14
14
  * Fetches every file that `source` imports, and what those import, so
@@ -28,4 +28,4 @@ export declare class YuhwaDiagram extends Base {
28
28
  connectedCallback(): void;
29
29
  attributeChangedCallback(): void;
30
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 };
31
+ export { BOOLS, type Box, type Component, type ConvertResult, type Curve, type Decoration, type Diagnostic, type Diagram, type DiagramJSON, type Direction, EDGE_PROPS, ENUMS, type EdgeDecl, type EdgeOverride, type FrameKind, GRID, GROUP_PROPS, GUIDE, type GroupDecl, type HeadKind, type InkColors, InputFormat, type JsonResult, KNOWN_SETTINGS, type LabelRef, type LaidEdge, type LaidGroup, type LaidNode, type LaidPanel, type Layout, type LayoutOverrides, type LexedLine, type LineStyle, type MarkerKind, type MdBlock, type MdOptions, type MdResult, NODE_PROPS, NUMBERS, type NodeDecl, type NodeOverride, Options, PANELS, PANEL_PROPS, type PanelCtx, type PanelDecl, type PanelHandle, type PanelKind, type PanelOverride, type PanelPart, type ParseOptions, type PartAction, type PartChange, type PartEdit, type Point, type Props, RAMPS, type ResolvedEdgeStyle, type ResolvedNodeStyle, Result, type RowCtx, type RowKind, type RowPaint, SETTING_VALUES, SHAPES, type Seg, type ShapeKind, type ShapeName, type Side, type SourceRef, type StatementKind, THEMES, THEME_KEYS, THEME_NAMES, TONES, type Theme, type ThemeInput, type Tok, type TokKind, type YuhwaPlugin, approxMeasure, blockBraces, builtins, canvasMeasure, chart, charts, createTheme, dashFor, editPart, findBlocks, footer, formatLayout, frames, fromJSON, fromMermaid, getTheme, git, groupPath, hash, isMermaid, isSafeCss, isSafeLink, isToneOrHex, isYuhwaPath, joinPath, layout, legend, lex, lineStyle, lint, onlyColor, parse, parseInline, parseProps, perPass, processMarkdown, ramp, recolor, registerTheme, registry, renderHead, renderSegs, renderSvg, replaceBlockSource, segsW, sequence, serializeProps, setLabel, setLineProp, setPartTone, setProp, setSetting, setTrailingProp, splitTrailingProps, tables, themeNames, themes, timeline, toSource, tspans, use, writeLayout, writePanelDrag };
package/dist/browser.js CHANGED
@@ -1,4 +1,4 @@
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-Dl2VCr7N.js";
1
+ import { $ as splitTrailingProps, A as canvasMeasure, B as KNOWN_SETTINGS, C as builtins, Ct as isSafeCss, D as sequence, Dt as registerTheme, E as timeline, Et as ramp, F as themes, G as joinPath, H as SETTING_VALUES, I as perPass, J as parse, K as lex, L as recolor, M as frames, N as tables, O as legend, Ot as themeNames, P as charts, Q as setTrailingProp, R as registry, S as layout, St as getTheme, T as chart, Tt as isToneOrHex, U as blockBraces, V as PANELS, W as isYuhwaPath, X as serializeProps, Y as parseProps, Z as setLineProp, _ as isMermaid, _t as THEMES, a as findBlocks, at as NUMBERS, b as GRID, bt as TONES, c as editPart, ct as SHAPES, d as setPartTone, dt as lineStyle, et as BOOLS, f as setProp, ft as parseInline, g as fromMermaid, gt as RAMPS, h as writePanelDrag, ht as tspans, i as GUIDE, it as NODE_PROPS, j as footer, k as approxMeasure, l as formatLayout, lt as renderHead, m as writeLayout, mt as segsW, n as render$1, nt as ENUMS, o as processMarkdown, ot as PANEL_PROPS, p as setSetting, pt as renderSegs, q as onlyColor, r as toSource, rt as GROUP_PROPS, s as replaceBlockSource, st as lint, t as hash, tt as EDGE_PROPS, u as setLabel, ut as dashFor, v as fromJSON, vt as THEME_KEYS, w as git, wt as isSafeLink, x as groupPath, xt as createTheme, y as renderSvg, yt as THEME_NAMES, z as use } from "./src-wk7tBpWs.js";
2
2
  // src/browser.ts
3
3
  /**
4
4
  * Drop-in browser runtime: <script src="yuhwa.js"><\/script>
@@ -164,4 +164,4 @@ if (typeof document !== "undefined") {
164
164
  else run();
165
165
  }
166
166
  }
167
- export { BOOLS, EDGE_PROPS, ENUMS, GRID, GROUP_PROPS, GUIDE, KNOWN_SETTINGS, NODE_PROPS, NUMBERS, PANELS, PANEL_PROPS, RAMPS, SETTING_VALUES, SHAPES, THEMES, THEME_KEYS, THEME_NAMES, TONES, YuhwaDiagram, approxMeasure, blockBraces, builtins, canvasMeasure, chart, charts, createTheme, dashFor, editPart, fetchImports, findBlocks, footer, formatLayout, frames, fromJSON, fromMermaid, getTheme, git, groupPath, hash, isMermaid, 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 };
167
+ export { BOOLS, EDGE_PROPS, ENUMS, GRID, GROUP_PROPS, GUIDE, KNOWN_SETTINGS, NODE_PROPS, NUMBERS, PANELS, PANEL_PROPS, RAMPS, SETTING_VALUES, SHAPES, THEMES, THEME_KEYS, THEME_NAMES, TONES, YuhwaDiagram, approxMeasure, blockBraces, builtins, canvasMeasure, chart, charts, createTheme, dashFor, editPart, fetchImports, findBlocks, footer, formatLayout, frames, fromJSON, fromMermaid, getTheme, git, groupPath, hash, isMermaid, isSafeCss, isSafeLink, isToneOrHex, isYuhwaPath, joinPath, layout, legend, lex, lineStyle, lint, onlyColor, parse, parseInline, parseProps, perPass, processMarkdown, ramp, recolor, registerTheme, registry, render, renderHead, renderSegs, renderSvg, replaceBlockSource, run, segsW, sequence, serializeProps, setLabel, setLineProp, setPartTone, setProp, setSetting, setTrailingProp, splitTrailingProps, tables, themeNames, themes, timeline, toSource, tspans, use, writeLayout, writePanelDrag };
package/dist/cli.js CHANGED
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
  import { existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
3
- import { C as PANEL_PROPS, D as TONES, E as THEME_NAMES, T as THEME_KEYS, a as canvasMeasure, b as GROUP_PROPS, c as KNOWN_SETTINGS, f as isYuhwaPath, n as render$1, o as registry, p as joinPath$1, r as toSource, s as diskResolve, t as VERSION, u as SETTING_VALUES, v as EDGE_PROPS, w as SHAPES, x as NODE_PROPS, y as ENUMS } from "./shared-CEPwGvSm.js";
3
+ import { C as PANEL_PROPS, D as TONES, E as THEME_NAMES, T as THEME_KEYS, a as canvasMeasure, b as GROUP_PROPS, c as KNOWN_SETTINGS, f as isYuhwaPath, n as render$1, o as registry, p as joinPath$1, r as toSource, s as diskResolve, t as VERSION, u as SETTING_VALUES, v as EDGE_PROPS, w as SHAPES, x as NODE_PROPS, y as ENUMS } from "./shared-qo_r6RUN.js";
4
4
  import { createServer } from "node:http";
5
- import { basename, dirname, extname, join, resolve } from "node:path";
5
+ import { basename, dirname, extname, join, resolve, sep } from "node:path";
6
6
  import { fileURLToPath } from "node:url";
7
7
  import { spawn } from "node:child_process";
8
8
  import { deflateSync, inflateRawSync, inflateSync } from "node:zlib";
@@ -374,16 +374,15 @@ function decodeSource(encoded, compressed) {
374
374
  return inflateRawSync(buf).toString("utf8");
375
375
  }
376
376
  }
377
- function readBody(req) {
377
+ function readBody(req, max = MAX_BODY) {
378
378
  return new Promise((ok, fail) => {
379
379
  let size = 0;
380
380
  const chunks = [];
381
381
  req.on("data", (c) => {
382
382
  size += c.length;
383
- if (size > MAX_BODY) fail(Object.assign(/* @__PURE__ */ new Error("body too large"), { status: 413 }));
384
- else chunks.push(c);
383
+ if (size <= max) chunks.push(c);
385
384
  });
386
- req.on("end", () => ok(Buffer.concat(chunks).toString("utf8")));
385
+ req.on("end", () => size > max ? fail(Object.assign(/* @__PURE__ */ new Error("body too large"), { status: 413 })) : ok(Buffer.concat(chunks).toString("utf8")));
387
386
  req.on("error", fail);
388
387
  });
389
388
  }
@@ -424,6 +423,8 @@ function handler(req, res) {
424
423
  const r = render$1(source, { theme });
425
424
  const errors = r.diagnostics.filter((d) => d.severity === "error");
426
425
  res.setHeader("content-type", "image/svg+xml; charset=utf-8");
426
+ res.setHeader("content-security-policy", "default-src 'none'; style-src 'unsafe-inline'; img-src data:");
427
+ res.setHeader("x-content-type-options", "nosniff");
427
428
  res.setHeader("x-yuhwa-format", r.format);
428
429
  if (errors.length) res.setHeader("x-yuhwa-errors", errors.map((d) => `${d.line}: ${d.message}`).join(" | ").slice(0, 2e3));
429
430
  if (cache && !errors.length) res.setHeader("cache-control", "public, max-age=31536000, immutable");
@@ -881,7 +882,14 @@ function cmdEdit(a) {
881
882
  }
882
883
  if (url.pathname === "/api/source") {
883
884
  if (req.method === "GET") {
884
- const source = readSource();
885
+ let source;
886
+ try {
887
+ source = readSource();
888
+ } catch (e) {
889
+ res.statusCode = 500;
890
+ res.end(JSON.stringify({ error: String(e) }));
891
+ return;
892
+ }
885
893
  fetchImports(source, basename(file), async (p) => diskResolve(join(base, p)) ?? Promise.reject(/* @__PURE__ */ new Error(`cannot import ${p}`))).then((files) => {
886
894
  for (const p of Object.keys(files)) loaded.add(p);
887
895
  res.setHeader("content-type", "application/json");
@@ -895,27 +903,23 @@ function cmdEdit(a) {
895
903
  return;
896
904
  }
897
905
  if (req.method === "PUT") {
898
- let body = "";
899
- req.on("data", (c) => body += c);
900
- req.on("end", () => {
901
- try {
902
- const j = JSON.parse(body);
903
- const written = saveEditorFiles(file, mainName, isMd ? blockIdx : void 0, loaded, j);
904
- res.end(JSON.stringify({
905
- ok: true,
906
- written
907
- }));
908
- } catch (e) {
909
- res.statusCode = 400;
910
- res.end(JSON.stringify({ error: String(e) }));
911
- }
906
+ readBody(req, 16 << 20).then((body) => {
907
+ const j = JSON.parse(body);
908
+ const written = saveEditorFiles(file, mainName, isMd ? blockIdx : void 0, loaded, j);
909
+ res.end(JSON.stringify({
910
+ ok: true,
911
+ written
912
+ }));
913
+ }).catch((e) => {
914
+ res.statusCode = e.status ?? 400;
915
+ res.end(JSON.stringify({ error: String(e) }));
912
916
  });
913
917
  return;
914
918
  }
915
919
  }
916
920
  const name = url.pathname === "/" ? "index.html" : url.pathname.slice(1);
917
921
  const p = join(dir, name);
918
- if (!p.startsWith(dir) || !existsSync(p) || statSync(p).isDirectory()) {
922
+ if (!p.startsWith(dir + sep) || !existsSync(p) || statSync(p).isDirectory()) {
919
923
  res.statusCode = 404;
920
924
  res.end("not found");
921
925
  return;