yuhwa 1.2.0 → 1.4.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/README.md +5 -3
- package/dist/astro.d.ts +1 -1
- package/dist/astro.js +4 -3
- package/dist/browser.d.ts +10 -3
- package/dist/browser.js +85 -21
- package/dist/canvas.d.ts +2 -0
- package/dist/canvas.js +40 -0
- package/dist/cli.js +485 -236
- package/dist/editor/assets/index-DWm3xV_v.js +689 -0
- package/dist/editor/assets/{lsp.worker-sZtzIA6-.js → lsp.worker-N6A9m364.js} +23 -17
- package/dist/editor/index.html +4 -1
- package/dist/{figure-CA2hy0xh.d.ts → figure-BLHfxz_e.d.ts} +28 -5
- package/dist/index-xVW43gqW.d.ts +261 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.js +5 -1
- package/dist/ironmark.d.ts +1 -1
- package/dist/ironmark.js +1 -1
- package/dist/lsp-browser.d.ts +2 -2
- package/dist/lsp-browser.js +2 -1
- package/dist/lsp-node.js +47 -27
- package/dist/lsp-server.d.ts +5 -1
- package/dist/lsp-server.js +1 -1
- package/dist/lsp.d.ts +1 -1
- package/dist/lsp.js +1 -1
- package/dist/markdown-it.d.ts +1 -1
- package/dist/markdown-it.js +5 -3
- package/dist/{node-Bzn2uKXZ.js → node-CkrQnPFb.js} +90 -12
- package/dist/parse--ljBMU60.js +3884 -0
- package/dist/plugin-CitzbblK.js +301 -0
- package/dist/{index-CnnoZYl0.d.ts → plugin-NMP_uf1a.d.ts} +93 -208
- package/dist/plugin.d.ts +12 -0
- package/dist/plugin.js +3 -0
- package/dist/raster-iqi6XRPU.js +299 -0
- package/dist/remark.d.ts +1 -1
- package/dist/remark.js +1 -1
- package/dist/rolldown-runtime-CEjnN5Q1.js +37 -0
- package/dist/{server-Dxo7OG8K.js → server-BTYtmr6B.js} +41 -63
- package/dist/{server--jHjJjOS.d.ts → server-DMAOtqqK.d.ts} +1 -1
- package/dist/{service-B1fpOg_L.js → service-C60VdeKS.js} +35 -3
- package/dist/{service-Brvpt7Do.d.ts → service-DimTFsE3.d.ts} +2 -0
- package/dist/{shared-Ddw88O9D.js → shared-h8tkFLY4.js} +719 -421
- package/dist/{src-DkQj7aIV.js → src-NCXCTK_4.js} +512 -4548
- package/dist/svg-uri-Dx8SGV-n.js +7 -0
- package/dist/vite.d.ts +1 -1
- package/dist/vite.js +3 -2
- package/dist/vuepress.d.ts +3 -2
- package/dist/vuepress.js +4 -2
- package/dist/watch-2VeW5DUN.js +35 -0
- package/dist/yuhwa.iife.js +55 -54
- package/dist/zoom-script-CaJ5MNUw.js +29 -0
- package/dist/{zoom-QeqB6QlH.js → zoom-yxhxX16c.js} +1 -1
- package/dist/zoom.d.ts +16 -7
- package/dist/zoom.js +2 -2
- package/package.json +24 -2
- package/skills/yuhwa/SKILL.md +12 -0
- package/dist/editor/assets/index-BphHLTvA.js +0 -689
- package/dist/zoom-script-CVdAzMhX.js +0 -51
|
@@ -1,8 +1,61 @@
|
|
|
1
1
|
import { readFileSync, realpathSync } from "node:fs";
|
|
2
2
|
import { basename, dirname, isAbsolute, join, relative, resolve } from "node:path";
|
|
3
|
-
import {
|
|
4
|
-
import { n as
|
|
5
|
-
import {
|
|
3
|
+
import { en as table, s as isYuhwaPath } from "./parse--ljBMU60.js";
|
|
4
|
+
import { a as MD_LANGUAGES, n as render } from "./src-NCXCTK_4.js";
|
|
5
|
+
import { n as zoomScript } from "./zoom-script-CaJ5MNUw.js";
|
|
6
|
+
import { t as zoomHeight } from "./zoom-yxhxX16c.js";
|
|
7
|
+
import { o as svgSize, t as base64 } from "./raster-iqi6XRPU.js";
|
|
8
|
+
import { t as svgDataUri } from "./svg-uri-Dx8SGV-n.js";
|
|
9
|
+
// src/integrations/png.ts
|
|
10
|
+
let resvg;
|
|
11
|
+
function builtin(id) {
|
|
12
|
+
const get = globalThis.process?.getBuiltinModule;
|
|
13
|
+
if (!get) throw new Error("PNG output needs Node 22.3 or later");
|
|
14
|
+
return get(id);
|
|
15
|
+
}
|
|
16
|
+
const pathCache = /* @__PURE__ */ new Map();
|
|
17
|
+
/** `fonts` checked and sorted into files and folders, once per list: a site build draws many diagrams */
|
|
18
|
+
function fontPaths(fonts) {
|
|
19
|
+
const key = fonts.join("\0");
|
|
20
|
+
const hit = pathCache.get(key);
|
|
21
|
+
if (hit) return hit;
|
|
22
|
+
const { existsSync, statSync } = builtin("node:fs");
|
|
23
|
+
const { resolve } = builtin("node:path");
|
|
24
|
+
const paths = {
|
|
25
|
+
fontFiles: [],
|
|
26
|
+
fontDirs: []
|
|
27
|
+
};
|
|
28
|
+
for (const f of fonts) {
|
|
29
|
+
if (!existsSync(f)) throw new Error(`no such font file or folder: ${f}`);
|
|
30
|
+
if (/\.woff2?$/i.test(f)) throw new Error(`PNG output reads ttf, otf and ttc fonts, not woff: ${f}`);
|
|
31
|
+
(statSync(f).isDirectory() ? paths.fontDirs : paths.fontFiles).push(resolve(f));
|
|
32
|
+
}
|
|
33
|
+
pathCache.set(key, paths);
|
|
34
|
+
return paths;
|
|
35
|
+
}
|
|
36
|
+
function svgToPng(svg, { scale = 2, fonts = [], systemFonts = true } = {}) {
|
|
37
|
+
if (!(scale > 0)) throw new Error("the PNG scale must be a number above 0");
|
|
38
|
+
if (!resvg) {
|
|
39
|
+
const { createRequire } = builtin("node:module");
|
|
40
|
+
try {
|
|
41
|
+
resvg = createRequire(import.meta.url)("@resvg/resvg-js").Resvg;
|
|
42
|
+
} catch {
|
|
43
|
+
throw new Error("PNG output needs @resvg/resvg-js: npm install -D @resvg/resvg-js, or pnpm add -D @resvg/resvg-js");
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
const { fontFiles, fontDirs } = fontPaths(fonts);
|
|
47
|
+
return new resvg(svg, {
|
|
48
|
+
fitTo: {
|
|
49
|
+
mode: "zoom",
|
|
50
|
+
value: scale
|
|
51
|
+
},
|
|
52
|
+
font: {
|
|
53
|
+
loadSystemFonts: systemFonts,
|
|
54
|
+
fontFiles,
|
|
55
|
+
fontDirs
|
|
56
|
+
}
|
|
57
|
+
}).render().asPng();
|
|
58
|
+
}
|
|
6
59
|
// src/integrations/figure.ts
|
|
7
60
|
/**
|
|
8
61
|
* Shared core of the docs integrations (markdown-it, remark, Astro, VuePress):
|
|
@@ -19,7 +72,6 @@ const el = (tagName, properties, children = []) => ({
|
|
|
19
72
|
properties,
|
|
20
73
|
children
|
|
21
74
|
});
|
|
22
|
-
const dataUri = (svg) => `data:image/svg+xml,${encodeURIComponent(svg)}`;
|
|
23
75
|
const where = (at) => `${at.file ?? "markdown"}${at.line ? `:${at.line}` : ""}${at.diagram ? ` (${at.diagram})` : ""}`;
|
|
24
76
|
function errorMessage(errors, at) {
|
|
25
77
|
return `yuhwa block at ${where(at)}:\n${errors.map((d) => ` line ${d.line}: ${d.message}`).join("\n")}`;
|
|
@@ -65,13 +117,33 @@ function fenceZoom(meta, opts = {}) {
|
|
|
65
117
|
zoomHeight: m[2] ?? m[3] ?? m[4] ?? opts.zoomHeight
|
|
66
118
|
};
|
|
67
119
|
}
|
|
120
|
+
/**
|
|
121
|
+
* `output=img`, `output=png` or `output=canvas` in a fence's meta, over the
|
|
122
|
+
* options. A fence cannot pick `svg`: MDX and Vue-based sites cannot take it.
|
|
123
|
+
*/
|
|
124
|
+
function fenceOutput(meta, opts = {}) {
|
|
125
|
+
return /(?:^|\s)output=(img|png|canvas)(?=\s|$)/.exec(meta ?? "")?.[1] ?? opts.output;
|
|
126
|
+
}
|
|
68
127
|
/** the pan and zoom script as an inline `<script>`, once per page */
|
|
69
128
|
const zoomTag = () => el("script", {}, [{
|
|
70
129
|
type: "text",
|
|
71
130
|
value: zoomScript
|
|
72
131
|
}]);
|
|
132
|
+
/**
|
|
133
|
+
* The modules a site loads in its client code for these options: the
|
|
134
|
+
* stylesheet, the pan and zoom script with `zoom`, and the canvas script,
|
|
135
|
+
* which any fence can ask for with `output=canvas` (it does nothing without
|
|
136
|
+
* such a figure).
|
|
137
|
+
*/
|
|
138
|
+
function clientImports(opts = {}) {
|
|
139
|
+
return [
|
|
140
|
+
"yuhwa/style.css",
|
|
141
|
+
...opts.zoom ? ["yuhwa/zoom"] : [],
|
|
142
|
+
"yuhwa/canvas"
|
|
143
|
+
];
|
|
144
|
+
}
|
|
73
145
|
function renderFigure(source, opts = {}, at = {}) {
|
|
74
|
-
const { theme, darkTheme = "midnight", darkMode = "class", output = "img", strict = true, languages: _, root: __, zoom, zoomHeight: zoomHeightOpt, ...rest } = opts;
|
|
146
|
+
const { theme, darkTheme = "midnight", darkMode = "class", output = "img", png, strict = true, languages: _, root: __, zoom, zoomHeight: zoomHeightOpt, ...rest } = opts;
|
|
75
147
|
const base = {
|
|
76
148
|
...rest,
|
|
77
149
|
file: at.diagram ?? at.file
|
|
@@ -88,9 +160,12 @@ function renderFigure(source, opts = {}, at = {}) {
|
|
|
88
160
|
theme: darkTheme
|
|
89
161
|
}) : void 0;
|
|
90
162
|
const children = [];
|
|
163
|
+
const asPng = output === "png";
|
|
164
|
+
const src = (svg) => asPng ? `data:image/png;base64,${base64(svgToPng(svg, png))}` : svgDataUri(svg);
|
|
91
165
|
const img = (svg, cls) => el("img", {
|
|
92
|
-
src:
|
|
166
|
+
src: src(svg),
|
|
93
167
|
alt,
|
|
168
|
+
width: asPng ? svgSize(svg).width : void 0,
|
|
94
169
|
className: cls,
|
|
95
170
|
loading: "lazy",
|
|
96
171
|
decoding: "async"
|
|
@@ -101,9 +176,9 @@ function renderFigure(source, opts = {}, at = {}) {
|
|
|
101
176
|
}]);
|
|
102
177
|
const one = output === "svg" ? inline : img;
|
|
103
178
|
if (!dark) children.push(one(light.svg, ["yuhwa-svg"]));
|
|
104
|
-
else if (darkMode === "media" && output === "img") children.push(el("picture", {}, [el("source", {
|
|
179
|
+
else if (darkMode === "media" && (output === "img" || asPng)) children.push(el("picture", {}, [el("source", {
|
|
105
180
|
media: "(prefers-color-scheme: dark)",
|
|
106
|
-
srcSet:
|
|
181
|
+
srcSet: src(dark.svg)
|
|
107
182
|
}), img(light.svg, ["yuhwa-svg"])]));
|
|
108
183
|
else children.push(one(light.svg, ["yuhwa-svg", "yuhwa-light"]), one(dark.svg, ["yuhwa-svg", "yuhwa-dark"]));
|
|
109
184
|
if (zoom) children.splice(0, children.length, el("div", { className: ["yuhwa-view"] }, [...children]));
|
|
@@ -115,7 +190,8 @@ function renderFigure(source, opts = {}, at = {}) {
|
|
|
115
190
|
const hast = el("figure", {
|
|
116
191
|
className: ["yuhwa"],
|
|
117
192
|
dataYuhwa: "",
|
|
118
|
-
dataZoom: height
|
|
193
|
+
dataZoom: height,
|
|
194
|
+
dataRender: output === "canvas" ? "canvas" : void 0
|
|
119
195
|
}, children);
|
|
120
196
|
return {
|
|
121
197
|
hast,
|
|
@@ -127,7 +203,8 @@ const ATTR = table({
|
|
|
127
203
|
className: "class",
|
|
128
204
|
srcSet: "srcset",
|
|
129
205
|
dataYuhwa: "data-yuhwa",
|
|
130
|
-
dataZoom: "data-zoom"
|
|
206
|
+
dataZoom: "data-zoom",
|
|
207
|
+
dataRender: "data-render"
|
|
131
208
|
});
|
|
132
209
|
const escape = (s) => s.replace(/[&<>"]/g, (c) => ({
|
|
133
210
|
"&": "&",
|
|
@@ -145,7 +222,7 @@ function toHtml(node, raw = false, parent = "") {
|
|
|
145
222
|
return `<${node.tagName}${attrs}>${inner}</${node.tagName}>`;
|
|
146
223
|
}
|
|
147
224
|
/** `yuhwa no-render` (or any flag list) on a fence: leave it as a code block */
|
|
148
|
-
function wantsRender(lang, meta, languages =
|
|
225
|
+
function wantsRender(lang, meta, languages = MD_LANGUAGES) {
|
|
149
226
|
return !!lang && languages.includes(lang) && !/(^|\s)no-render(\s|$)/.test(meta ?? "");
|
|
150
227
|
}
|
|
151
228
|
// src/integrations/node.ts
|
|
@@ -214,6 +291,7 @@ function renderBlock(body, meta, opts, at) {
|
|
|
214
291
|
return renderFigure(source, {
|
|
215
292
|
...opts,
|
|
216
293
|
...fenceZoom(meta, opts),
|
|
294
|
+
output: fenceOutput(meta, opts),
|
|
217
295
|
resolve: resolve$1
|
|
218
296
|
}, block);
|
|
219
297
|
} catch (e) {
|
|
@@ -221,4 +299,4 @@ function renderBlock(body, meta, opts, at) {
|
|
|
221
299
|
throw e;
|
|
222
300
|
}
|
|
223
301
|
}
|
|
224
|
-
export {
|
|
302
|
+
export { toHtml as a, errorMessage as i, renderBlock as n, wantsRender as o, clientImports as r, zoomTag as s, diskResolve as t };
|