wasm-html-to-image 1.0.16 → 1.0.17
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/cli-options.d.ts +13 -1
- package/dist/cli-options.js +17 -3
- package/dist/cli.js +5 -1
- package/dist/core.d.ts +7 -0
- package/dist/html-to-image-wasm.js +3 -3
- package/dist/html-to-image.wasm +0 -0
- package/dist/js-page.d.ts +42 -0
- package/dist/js-page.js +138 -0
- package/dist/single.d.ts +2 -0
- package/dist/single.js +3 -1
- package/dist/web-workers.js +1 -1
- package/package.json +8 -2
package/dist/cli-options.d.ts
CHANGED
|
@@ -25,7 +25,16 @@ export interface CliFlags {
|
|
|
25
25
|
animationLoop?: number;
|
|
26
26
|
/** `--font <path-or-glob>` (repeatable); local font files to register. */
|
|
27
27
|
font?: string[];
|
|
28
|
+
/** `--js`: run the page's scripts (jsdom) before rendering. */
|
|
29
|
+
js?: boolean;
|
|
30
|
+
/** `--js-wait <ms|selector>`: a number is the settle time after load, anything else a CSS selector to wait for. */
|
|
31
|
+
jsWait?: string;
|
|
28
32
|
}
|
|
33
|
+
/** `--js-wait`: milliseconds to settle after load, or a CSS selector to wait for. */
|
|
34
|
+
export declare function resolveJavaScript(wait: string | undefined): true | {
|
|
35
|
+
settleMs?: number;
|
|
36
|
+
waitFor?: string;
|
|
37
|
+
};
|
|
29
38
|
/** Default frame rate for `--animation` when `--animation-fps` is omitted. */
|
|
30
39
|
export declare const DEFAULT_ANIMATION_FPS = 15;
|
|
31
40
|
/**
|
|
@@ -57,7 +66,10 @@ export declare function isInlineHtml(input: string): boolean;
|
|
|
57
66
|
export declare function readStdin(): Promise<string>;
|
|
58
67
|
/** Expand `*` / `?` in the last path segment; other patterns are literal paths. */
|
|
59
68
|
export declare function expandGlob(pattern: string): Promise<string[]>;
|
|
60
|
-
/**
|
|
69
|
+
/**
|
|
70
|
+
* Load `--font` files. Each is named after its file (without extension), or after the family
|
|
71
|
+
* given as `Family Name=path` (use it to stand in for a system font such as `Segoe UI`).
|
|
72
|
+
*/
|
|
61
73
|
export declare function loadFonts(patterns: string[]): Promise<{
|
|
62
74
|
name: string;
|
|
63
75
|
data: Uint8Array;
|
package/dist/cli-options.js
CHANGED
|
@@ -7,6 +7,12 @@
|
|
|
7
7
|
import fs from "node:fs/promises";
|
|
8
8
|
import path from "node:path";
|
|
9
9
|
import { isImageInput } from "./input.js";
|
|
10
|
+
/** `--js-wait`: milliseconds to settle after load, or a CSS selector to wait for. */
|
|
11
|
+
export function resolveJavaScript(wait) {
|
|
12
|
+
if (wait === undefined || wait === "")
|
|
13
|
+
return true;
|
|
14
|
+
return /^\d+(\.\d+)?$/.test(wait) ? { settleMs: Number(wait) } : { waitFor: wait };
|
|
15
|
+
}
|
|
10
16
|
/** Default frame rate for `--animation` when `--animation-fps` is omitted. */
|
|
11
17
|
export const DEFAULT_ANIMATION_FPS = 15;
|
|
12
18
|
/** Map `--animation` / `--animation-fps` / `--animation-loop` to the `render()` animation option. */
|
|
@@ -88,17 +94,24 @@ export async function expandGlob(pattern) {
|
|
|
88
94
|
.sort()
|
|
89
95
|
.map((n) => path.join(dir, n));
|
|
90
96
|
}
|
|
91
|
-
/**
|
|
97
|
+
/**
|
|
98
|
+
* Load `--font` files. Each is named after its file (without extension), or after the family
|
|
99
|
+
* given as `Family Name=path` (use it to stand in for a system font such as `Segoe UI`).
|
|
100
|
+
*/
|
|
92
101
|
export async function loadFonts(patterns) {
|
|
93
102
|
const fonts = [];
|
|
94
|
-
for (const
|
|
103
|
+
for (const spec of patterns) {
|
|
104
|
+
// `Family=path`: a drive letter (`C:\...`) has no `=`, so the first `=` splits family and path.
|
|
105
|
+
const eq = spec.indexOf("=");
|
|
106
|
+
const family = eq > 0 ? spec.slice(0, eq).trim() : undefined;
|
|
107
|
+
const pattern = eq > 0 ? spec.slice(eq + 1) : spec;
|
|
95
108
|
const files = await expandGlob(pattern);
|
|
96
109
|
if (files.length === 0) {
|
|
97
110
|
console.warn(`wasm-html-to-image: no font files match "${pattern}"`);
|
|
98
111
|
}
|
|
99
112
|
for (const file of files) {
|
|
100
113
|
fonts.push({
|
|
101
|
-
name: path.basename(file, path.extname(file)),
|
|
114
|
+
name: family ?? path.basename(file, path.extname(file)),
|
|
102
115
|
data: new Uint8Array(await fs.readFile(file)),
|
|
103
116
|
});
|
|
104
117
|
}
|
|
@@ -162,5 +175,6 @@ export async function buildRenderOptions(input, flags) {
|
|
|
162
175
|
...(flags.dpi !== undefined ? { dpi: flags.dpi } : {}),
|
|
163
176
|
...(animation ? { animation } : {}),
|
|
164
177
|
...(fonts.length ? { fonts } : {}),
|
|
178
|
+
...(flags.js ? { javascript: resolveJavaScript(flags.jsWait) } : {}),
|
|
165
179
|
};
|
|
166
180
|
}
|
package/dist/cli.js
CHANGED
|
@@ -31,7 +31,7 @@ program
|
|
|
31
31
|
.option("-w, --width <number>", "viewport width", (v) => parseInt(v, 10), 800)
|
|
32
32
|
.option("-h, --height <number>", "viewport height (omit for auto)", (v) => parseInt(v, 10))
|
|
33
33
|
.option("-f, --format <format>", `output format (${OUTPUT_FORMATS.join(", ")}); default: from the --output extension, else png`)
|
|
34
|
-
.option("--font <path>", "local font file or glob such as './fonts/*.woff2' (repeatable)", (v, prev = []) => [...prev, v])
|
|
34
|
+
.option("--font <path>", "local font file or glob such as './fonts/*.woff2' (repeatable); 'Family=path' registers it under that family name, e.g. 'Segoe UI=C:/Windows/Fonts/segoeui.ttf'", (v, prev = []) => [...prev, v])
|
|
35
35
|
.option("-q, --quality <number>", "encode quality 0-100 (encode stage only)", (v) => parseFloat(v), 85)
|
|
36
36
|
.option("--base-url <url>", "base URL for relative resources (URL input: defaults to the post-redirect document URL; file input: defaults to the file's directory)")
|
|
37
37
|
.option("--color-space <srgb|cmyk>", "output color space of tiff and pdf (default srgb; cmyk rewrites colors for print, with no ICC profile)", (v) => v.toLowerCase())
|
|
@@ -40,6 +40,8 @@ program
|
|
|
40
40
|
.option("--animation <duration-ms>", "sample the document's @keyframes opacity / transform / color animation into an animated WebP / APNG / GIF; one loop duration in ms (webp, apng and gif output only; the CSS animation-duration wins and this value is an upper bound)", (v) => parseInt(v, 10))
|
|
41
41
|
.option("--animation-fps <n>", "animation frame rate (default 15, capped at ~75 frames total; requires --animation)", (v) => parseInt(v, 10))
|
|
42
42
|
.option("--animation-loop <n>", "how many times the animated WebP / APNG / GIF repeats (0 = infinite, the default; 1 = play once; requires --animation)", (v) => parseInt(v, 10))
|
|
43
|
+
.option("--js", "run the page's scripts in jsdom before rendering (needs the optional peer dependency jsdom; trusted pages only)")
|
|
44
|
+
.option("--js-wait <ms|selector>", "with --js: milliseconds to wait after load (default 1000), or a CSS selector to wait for")
|
|
43
45
|
.action(async (input, options) => {
|
|
44
46
|
try {
|
|
45
47
|
const format = String(options.format ?? inferFormat(options.output) ?? "png").toLowerCase();
|
|
@@ -84,6 +86,8 @@ program
|
|
|
84
86
|
animationFps: options.animationFps,
|
|
85
87
|
animationLoop: options.animationLoop,
|
|
86
88
|
font: options.font,
|
|
89
|
+
js: options.js,
|
|
90
|
+
jsWait: options.jsWait,
|
|
87
91
|
};
|
|
88
92
|
const result = await render(await buildRenderOptions(input, flags));
|
|
89
93
|
await fs.writeFile(outputPath, typeof result.data === "string"
|
package/dist/core.d.ts
CHANGED
|
@@ -76,6 +76,13 @@ export interface LayoutBox {
|
|
|
76
76
|
h: number;
|
|
77
77
|
}
|
|
78
78
|
export interface HtmlToImageOptions extends RenderOptions {
|
|
79
|
+
/**
|
|
80
|
+
* Run the page's scripts before rendering (Node only; `single` entry point and the CLI's `--js`).
|
|
81
|
+
* The page is loaded into jsdom (optional peer dependency `jsdom`), its scripts run, and the resulting
|
|
82
|
+
* DOM is rendered. `true` waits for `load` plus 1 s; pass `{ timeout, settleMs, waitFor }` to tune it.
|
|
83
|
+
* jsdom has no layout and is not a security sandbox: only use it with pages you trust.
|
|
84
|
+
*/
|
|
85
|
+
javascript?: boolean | import("./js-page.js").JavaScriptOptions;
|
|
79
86
|
/** Encode quality 0-100 (encode stage only, default 85; ignored for svg/pdf). */
|
|
80
87
|
quality?: number;
|
|
81
88
|
/** Encode speed 0-10 for AVIF, JXL and animated (lossy) WebP (encode stage only; default 8 for AVIF, 6 otherwise). Animated WebP uses libwebp method `8 - speed`: the default 6 is method 2, 5 is method 3 (Skia's, smaller by ~4%), 9 is method 0 (fastest, ~30% larger). */
|