satoru-render 1.0.11 → 1.0.13
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/CHANGELOG.md +113 -0
- package/README.md +76 -9
- package/dist/cli.js +60 -0
- package/dist/core.d.ts +105 -0
- package/dist/core.js +227 -33
- package/dist/resources.d.ts +60 -0
- package/dist/resources.js +175 -0
- package/dist/satoru-single.js +0 -0
- package/dist/satoru.js +2 -2
- package/dist/satoru.wasm +0 -0
- package/dist/web-workers.js +473 -247
- package/dist/workers-parent.js +316 -37
- package/dist/workers.d.ts +39 -4
- package/dist/workers.js +104 -5
- package/package.json +15 -7
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
## v1.0.13 - 2026-05-19
|
|
6
|
+
|
|
7
|
+
- **Diagnostics & Tooling**:
|
|
8
|
+
- [Feature] Stabilize `RenderDiagnostics` schema (version 1) for reliable automated analysis.
|
|
9
|
+
- [Feature] Add Inspection Workspace to Playground with Resources, Fonts, Timings, and Logs tabs.
|
|
10
|
+
- [Improvement] Make CLI `--json-report` output deterministic by sorting resources and fonts.
|
|
11
|
+
- [Improvement] Add regression tests for diagnostics and resource resolution.
|
|
12
|
+
|
|
13
|
+
## v1.0.12 - 2026-05-18
|
|
14
|
+
|
|
15
|
+
- **Performance**:
|
|
16
|
+
- [Optimization] Add performance optimizations for rendering speed.
|
|
17
|
+
|
|
18
|
+
## v1.0.11 - 2026-05-17
|
|
19
|
+
|
|
20
|
+
- **Rendering Engine & Text Layout**:
|
|
21
|
+
- [Feature] Implement text layout measurement engine with vertical writing mode and profiling support.
|
|
22
|
+
- [Feature] Implement core interfaces and font resolution logic, including Google Fonts resolution.
|
|
23
|
+
- **Core API & Infrastructure**:
|
|
24
|
+
- [Feature] Implement core Satoru module interface, resource resolution, and C++ API bindings.
|
|
25
|
+
- [Improvement] Initialize and adjust `satoru-render` package configuration and exports.
|
|
26
|
+
|
|
27
|
+
## v1.0.10 - 2026-04-26
|
|
28
|
+
|
|
29
|
+
- **Rendering Capabilities**:
|
|
30
|
+
- [Feature] Implement PNG, PDF, and SVG rendering engines with Skia-based text and layout management.
|
|
31
|
+
- **Configuration & Build**:
|
|
32
|
+
- [Improvement] Initialize `package.json` with multi-environment exports.
|
|
33
|
+
|
|
34
|
+
## v1.0.9 - 2026-04-25
|
|
35
|
+
|
|
36
|
+
- **Rendering Engine**:
|
|
37
|
+
- [Feature] Add `backdrop-filter` support via Skia.
|
|
38
|
+
|
|
39
|
+
## v1.0.7 - 2026-04-24
|
|
40
|
+
|
|
41
|
+
- **Rendering Engine**:
|
|
42
|
+
- [Feature] Implement `backdrop-filter` in Skia container.
|
|
43
|
+
- [Feature] Add initial font rendering infrastructure.
|
|
44
|
+
- [Feature] Implement PDF and PNG rendering engines using Skia and litehtml integration.
|
|
45
|
+
|
|
46
|
+
## v1.0.5 - 2026-04-23
|
|
47
|
+
|
|
48
|
+
- **Core Capabilities**:
|
|
49
|
+
- [Feature] Implement multi-format rendering supporting PNG, WebP, PDF, and SVG engines.
|
|
50
|
+
|
|
51
|
+
## v1.0.4 - 2026-04-22
|
|
52
|
+
|
|
53
|
+
- **Configuration & Build**:
|
|
54
|
+
- [Improvement] Initialize `package.json` for `satoru-render`.
|
|
55
|
+
|
|
56
|
+
## v1.0.3 - 2026-04-22
|
|
57
|
+
|
|
58
|
+
- **Rendering Engine**:
|
|
59
|
+
- [Feature] Implement core rendering engine including litehtml integration and showcase page scaffolding.
|
|
60
|
+
|
|
61
|
+
## v1.0.2 - 2026-04-21
|
|
62
|
+
|
|
63
|
+
- **Rendering Engine**:
|
|
64
|
+
- [Feature] Implement C++ rendering engine with bridge support and add initial assets.
|
|
65
|
+
- [Feature] Add WebP renderer support and expand core TypeScript interfaces.
|
|
66
|
+
|
|
67
|
+
## v0.0.7 - 2026-03-03
|
|
68
|
+
|
|
69
|
+
- **CSS Support & Rendering**:
|
|
70
|
+
- [Feature] Add support for CSS gradients in the `border-image` property.
|
|
71
|
+
- [Feature] Implement full SVG mask rendering, including images and gradients.
|
|
72
|
+
|
|
73
|
+
## v0.0.6 - 2026-03-03
|
|
74
|
+
|
|
75
|
+
- **CSS Support**:
|
|
76
|
+
- [Feature] Implement `object-fit` CSS property for images (reflected in rendering and visual tests).
|
|
77
|
+
|
|
78
|
+
## v0.0.5 - 2026-03-03
|
|
79
|
+
|
|
80
|
+
- **General**:
|
|
81
|
+
- [Improvement] Version bump and cleanup of image rendering debug output.
|
|
82
|
+
|
|
83
|
+
## v0.0.4 - 2026-02-27
|
|
84
|
+
|
|
85
|
+
- **Asset Management**:
|
|
86
|
+
- [Feature] Allow direct asset linking via URL parameters.
|
|
87
|
+
- [Optimization] Improve asset loading logic.
|
|
88
|
+
|
|
89
|
+
## v0.0.3 - 2026-02-26
|
|
90
|
+
|
|
91
|
+
- **Code Quality**:
|
|
92
|
+
- [Refactor] Format text layout and rendering code for improved readability.
|
|
93
|
+
|
|
94
|
+
## v0.0.2 - 2026-02-25
|
|
95
|
+
|
|
96
|
+
- **Performance & Build**:
|
|
97
|
+
- [Optimization] Optimize WASM builds using Thin LTO and `-O3`.
|
|
98
|
+
- [Improvement] Improve height handling in core API.
|
|
99
|
+
|
|
100
|
+
## v0.0.1 - 2026-02-23
|
|
101
|
+
|
|
102
|
+
- **Architecture & Ecosystem**:
|
|
103
|
+
- [Feature] Major structural changes including entry point setup for multiple environments (Node, Workers, Deno, etc.).
|
|
104
|
+
- [Feature] Add Cloudflare OGP generator package and Deno OGP service.
|
|
105
|
+
- [Feature] Implement automatic font resolution with configurable font map and Google Fonts integration.
|
|
106
|
+
- [Improvement] Rename package from `satoru` to `satoru-render`.
|
|
107
|
+
|
|
108
|
+
## v1.0.0 - 2026-02-06
|
|
109
|
+
|
|
110
|
+
- **Initial Setup & Monorepo**:
|
|
111
|
+
- [Refactor] Refactor to pnpm monorepo structure.
|
|
112
|
+
- [Feature] Create initial `@satoru/core` WASM package and add Cloudflare Workers (workerd) support.
|
|
113
|
+
- [Feature] Add visual regression testing suite and comprehensive HTML/CSS test assets.
|
package/README.md
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
# Satoru Render: High-Performance HTML to Image/PDF Engine
|
|
2
2
|
|
|
3
3
|
[](https://sorakumo001.github.io/satoru/master)
|
|
4
|
+
[](https://sorakumo001.github.io/satoru/master/docs/)
|
|
4
5
|
[](https://www.npmjs.com/package/satoru-render)
|
|
5
6
|
[](https://www.npmjs.com/package/satoru-render)
|
|
6
7
|
[](https://www.npmjs.com/package/satoru-render)
|
|
7
8
|
[](https://deepwiki.com/SoraKumo001/satoru)
|
|
8
9
|
|
|
9
|
-
**Satoru Render** is a high-fidelity HTML-to-Image/PDF conversion engine built with WebAssembly. It
|
|
10
|
+
**Satoru Render** is a high-fidelity HTML-to-Image/PDF conversion engine built with WebAssembly. It generates high-quality visuals and documents across **Node.js**, **Cloudflare Workers**, **Deno**, and **Web Browsers** without requiring a headless browser or system-level rendering service.
|
|
10
11
|
|
|
11
12
|
By combining the **Skia** graphics engine with a custom **litehtml** layout core, Satoru performs all layout and drawing operations entirely within WASM, eliminating the need for headless browsers or system-level dependencies.
|
|
12
13
|
|
|
13
|
-

|
|
14
15
|
|
|
15
16
|
## Example
|
|
16
17
|
|
|
@@ -23,7 +24,9 @@ By combining the **Skia** graphics engine with a custom **litehtml** layout core
|
|
|
23
24
|
|
|
24
25
|
---
|
|
25
26
|
|
|
26
|
-
## 📋
|
|
27
|
+
## 📋 Tested CSS Feature Coverage
|
|
28
|
+
|
|
29
|
+
Satoru supports and tests a broad subset of modern CSS. The list below highlights the main feature areas covered by the renderer and visual test suite. For detailed status and known differences, see the [compatibility evidence](https://sorakumo001.github.io/satoru/master/docs/docs/compatibility/).
|
|
27
30
|
|
|
28
31
|
<details>
|
|
29
32
|
<summary>Click to expand supported properties list</summary>
|
|
@@ -177,12 +180,12 @@ const pdf = await render({
|
|
|
177
180
|
});
|
|
178
181
|
```
|
|
179
182
|
|
|
180
|
-
###
|
|
183
|
+
### 4. Edge/Cloudflare Workers
|
|
181
184
|
|
|
182
185
|
Use the specialized `workerd` export for serverless environments.
|
|
183
186
|
|
|
184
187
|
```typescript
|
|
185
|
-
import { render } from "satoru-render";
|
|
188
|
+
import { render } from "satoru-render/workerd";
|
|
186
189
|
|
|
187
190
|
export default {
|
|
188
191
|
async fetch(request) {
|
|
@@ -197,7 +200,7 @@ export default {
|
|
|
197
200
|
};
|
|
198
201
|
```
|
|
199
202
|
|
|
200
|
-
###
|
|
203
|
+
### 5. Multi-threaded Rendering (Worker Proxy)
|
|
201
204
|
|
|
202
205
|
Distribute rendering tasks across multiple background workers for high-throughput applications.
|
|
203
206
|
|
|
@@ -213,7 +216,7 @@ const png = await satoru.render({
|
|
|
213
216
|
});
|
|
214
217
|
```
|
|
215
218
|
|
|
216
|
-
###
|
|
219
|
+
### 6. preact + tailwind
|
|
217
220
|
|
|
218
221
|
- install
|
|
219
222
|
|
|
@@ -261,7 +264,7 @@ const png = await render({
|
|
|
261
264
|
|
|
262
265
|
---
|
|
263
266
|
|
|
264
|
-
###
|
|
267
|
+
### 7. JSDOM Hydration (For Next.js / SPAs)
|
|
265
268
|
|
|
266
269
|
For complex client-side applications (like Next.js) that require full Javascript evaluation and DOM hydration before rendering, Satoru provides an optional `jsdom` helper.
|
|
267
270
|
|
|
@@ -295,7 +298,7 @@ const pngBytes = await render({
|
|
|
295
298
|
});
|
|
296
299
|
```
|
|
297
300
|
|
|
298
|
-
###
|
|
301
|
+
### 8. DOM Capture (html2canvas alternative)
|
|
299
302
|
|
|
300
303
|
Satoru can capture live DOM elements directly in the browser, preserving computed styles, pseudo-elements (`::before`/`::after`), canvas contents, and form states.
|
|
301
304
|
|
|
@@ -320,6 +323,28 @@ const png = await satoru.render({
|
|
|
320
323
|
});
|
|
321
324
|
```
|
|
322
325
|
|
|
326
|
+
### 9. Rendering Diagnostics
|
|
327
|
+
|
|
328
|
+
Get detailed insights into the rendering process, including resource loading status, font resolution, and performance timings.
|
|
329
|
+
|
|
330
|
+
```typescript
|
|
331
|
+
import { render } from "satoru-render";
|
|
332
|
+
|
|
333
|
+
const png = await render({
|
|
334
|
+
value: "<h1>Hello World</h1>",
|
|
335
|
+
width: 800,
|
|
336
|
+
format: "png",
|
|
337
|
+
diagnostics: true,
|
|
338
|
+
onDiagnostics: (report) => {
|
|
339
|
+
console.log(`Version: ${report.version}`);
|
|
340
|
+
console.log(`Format: ${report.format}`);
|
|
341
|
+
console.log("Resources:", report.resources);
|
|
342
|
+
console.log("Fonts:", report.fonts);
|
|
343
|
+
console.log("Timings:", report.timings);
|
|
344
|
+
},
|
|
345
|
+
});
|
|
346
|
+
```
|
|
347
|
+
|
|
323
348
|
---
|
|
324
349
|
|
|
325
350
|
## 💻 CLI Tool
|
|
@@ -338,6 +363,16 @@ npx satoru-render https://example.com --no-jsdom -o example.pdf
|
|
|
338
363
|
|
|
339
364
|
# WebP conversion with verbose logs
|
|
340
365
|
npx satoru-render input.html -f webp --verbose
|
|
366
|
+
|
|
367
|
+
# Write rendering diagnostics to a JSON file
|
|
368
|
+
npx satoru-render input.html -o output.png --json-report report.json
|
|
369
|
+
|
|
370
|
+
# Restrict network access for safer server-side usage
|
|
371
|
+
npx satoru-render https://example.com -o output.png \
|
|
372
|
+
--timeout 5000 \
|
|
373
|
+
--max-resource-count 50 \
|
|
374
|
+
--max-total-resource-bytes 10000000 \
|
|
375
|
+
--allowed-protocols https:
|
|
341
376
|
```
|
|
342
377
|
|
|
343
378
|
---
|
|
@@ -356,13 +391,45 @@ npx satoru-render input.html -f webp --verbose
|
|
|
356
391
|
| `outputWidth` | `number` | Output image width. Default: canvas/crop width. |
|
|
357
392
|
| `outputHeight` | `number` | Output image height. Default: canvas/crop height. |
|
|
358
393
|
| `fit` | `"contain" \| "cover" \| "fill"` | Fit strategy when canvas/crop size differs from output. |
|
|
394
|
+
| `fitPosition` | `{ x, y }` | Alignment origin for `contain`/`cover`. Default: center. |
|
|
395
|
+
| `backgroundColor` | `string` | Background color for raster/PDF output. |
|
|
359
396
|
| `format` | `"svg" \| "png" \| "webp" \| "pdf"` | Output format. Default: `"svg"`. |
|
|
360
397
|
| `resolveResource` | `ResourceResolver` | Async callback to fetch assets (fonts, images, CSS). |
|
|
361
398
|
| `fonts` | `Object[]` | Pre-load fonts: `[{ name, data: Uint8Array }]`. |
|
|
399
|
+
| `fallbackFonts` | `Uint8Array[]` | Font data used as fallback faces. |
|
|
400
|
+
| `images` | `Object[]` | Pre-load named images for resource resolution. |
|
|
362
401
|
| `css` | `string` | Extra CSS to inject into the document. |
|
|
363
402
|
| `baseUrl` | `string` | Base URL for relative path resolution. |
|
|
403
|
+
| `userAgent` | `string` | User agent used by the default resource resolver. |
|
|
404
|
+
| `fontMap` | `Record<string, string>` | Override font-family to remote font URL mapping. |
|
|
364
405
|
| `logLevel` | `LogLevel` | Verbosity: `None`, `Error`, `Warning`, `Info`, `Debug`. |
|
|
365
406
|
| `mediaType` | `"screen" \| "print"` | CSS media type for `@media` queries. Default: `"screen"`. |
|
|
407
|
+
| `limits` | `RenderLimits` | Timeout, resource size, protocol, and host restrictions. |
|
|
408
|
+
| `profile` | `boolean` | Collect coarse render timings. |
|
|
409
|
+
| `onProfile` | `(profile) => void` | Callback that receives coarse render timings. |
|
|
410
|
+
| `diagnostics` | `boolean` | Enable detailed rendering diagnostics. |
|
|
411
|
+
| `onDiagnostics` | `(report: RenderDiagnostics) => void` | Callback that receives the full diagnostics report. |
|
|
412
|
+
| `pdfTitle` / `pdfAuthor` | `string` | PDF metadata fields. |
|
|
413
|
+
| `pdfMargin` | `{ top, right, bottom, left }` | PDF page margins in pixels. |
|
|
414
|
+
| `pdfHeader` / `pdfFooter` | `string` | PDF header/footer HTML. Supports `{{pageNumber}}` and `{{totalPages}}`. |
|
|
415
|
+
|
|
416
|
+
For the full API surface, see the [API Reference](https://sorakumo001.github.io/satoru/master/docs/docs/api-reference/).
|
|
417
|
+
|
|
418
|
+
---
|
|
419
|
+
|
|
420
|
+
## 📝 Changelog
|
|
421
|
+
|
|
422
|
+
Please see [CHANGELOG.md](./CHANGELOG.md) for a history of changes.
|
|
423
|
+
|
|
424
|
+
## 📖 Recipes
|
|
425
|
+
|
|
426
|
+
- [Production OGP Generation](https://sorakumo001.github.io/satoru/master/docs/docs/recipes/ogp-production/): Caching, safety limits, and diagnostics for high-traffic services.
|
|
427
|
+
|
|
428
|
+
---
|
|
429
|
+
|
|
430
|
+
## 🔬 Compatibility Evidence
|
|
431
|
+
|
|
432
|
+
For a detailed breakdown of CSS feature support and visual test coverage, see the [Compatibility Matrix](https://sorakumo001.github.io/satoru/master/docs/docs/compatibility/).
|
|
366
433
|
|
|
367
434
|
---
|
|
368
435
|
|
package/dist/cli.js
CHANGED
|
@@ -24,6 +24,9 @@ async function main() {
|
|
|
24
24
|
else if (arg === "-o" || arg === "--output") {
|
|
25
25
|
options.output = args[++i];
|
|
26
26
|
}
|
|
27
|
+
else if (arg === "--json-report") {
|
|
28
|
+
options.jsonReport = args[++i];
|
|
29
|
+
}
|
|
27
30
|
else if (arg === "--no-jsdom") {
|
|
28
31
|
options.jsdom = false;
|
|
29
32
|
}
|
|
@@ -33,6 +36,27 @@ async function main() {
|
|
|
33
36
|
else if (arg === "--media") {
|
|
34
37
|
options.mediaType = args[++i];
|
|
35
38
|
}
|
|
39
|
+
else if (arg === "--timeout") {
|
|
40
|
+
options.timeout = parseInt(args[++i]);
|
|
41
|
+
}
|
|
42
|
+
else if (arg === "--max-resource-bytes") {
|
|
43
|
+
options.maxResourceBytes = parseInt(args[++i]);
|
|
44
|
+
}
|
|
45
|
+
else if (arg === "--max-total-resource-bytes") {
|
|
46
|
+
options.maxTotalResourceBytes = parseInt(args[++i]);
|
|
47
|
+
}
|
|
48
|
+
else if (arg === "--max-resource-count") {
|
|
49
|
+
options.maxResourceCount = parseInt(args[++i]);
|
|
50
|
+
}
|
|
51
|
+
else if (arg === "--allowed-protocols") {
|
|
52
|
+
options.allowedProtocols = args[++i].split(",");
|
|
53
|
+
}
|
|
54
|
+
else if (arg === "--allowed-hosts") {
|
|
55
|
+
options.allowedHosts = args[++i].split(",");
|
|
56
|
+
}
|
|
57
|
+
else if (arg === "--blocked-hosts") {
|
|
58
|
+
options.blockedHosts = args[++i].split(",");
|
|
59
|
+
}
|
|
36
60
|
else if (arg === "--help") {
|
|
37
61
|
printHelp();
|
|
38
62
|
return;
|
|
@@ -71,8 +95,36 @@ async function main() {
|
|
|
71
95
|
format: options.format,
|
|
72
96
|
logLevel: options.verbose ? LogLevel.Debug : LogLevel.None,
|
|
73
97
|
mediaType: options.mediaType,
|
|
98
|
+
limits: {
|
|
99
|
+
timeoutMs: options.timeout,
|
|
100
|
+
maxResourceBytes: options.maxResourceBytes,
|
|
101
|
+
maxTotalResourceBytes: options.maxTotalResourceBytes,
|
|
102
|
+
maxResourceCount: options.maxResourceCount,
|
|
103
|
+
allowedProtocols: options.allowedProtocols,
|
|
104
|
+
allowedHosts: options.allowedHosts,
|
|
105
|
+
blockedHosts: options.blockedHosts,
|
|
106
|
+
},
|
|
74
107
|
css: "body { background-color: white; }",
|
|
75
108
|
};
|
|
109
|
+
if (options.jsonReport) {
|
|
110
|
+
renderOptions.diagnostics = true;
|
|
111
|
+
renderOptions.onDiagnostics = (report) => {
|
|
112
|
+
const deterministicReport = {
|
|
113
|
+
...report,
|
|
114
|
+
timings: { omitted: 1 },
|
|
115
|
+
};
|
|
116
|
+
if (deterministicReport.resources) {
|
|
117
|
+
deterministicReport.resources.sort((a, b) => (a.url || "").localeCompare(b.url || ""));
|
|
118
|
+
}
|
|
119
|
+
if (deterministicReport.fonts) {
|
|
120
|
+
deterministicReport.fonts.sort((a, b) => (a.family || "").localeCompare(b.family || ""));
|
|
121
|
+
}
|
|
122
|
+
fs.writeFileSync(options.jsonReport, JSON.stringify(deterministicReport, null, 2));
|
|
123
|
+
if (options.verbose) {
|
|
124
|
+
console.error(`[Satoru] Diagnostics report written to ${options.jsonReport}`);
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
}
|
|
76
128
|
if (options.verbose) {
|
|
77
129
|
renderOptions.onLog = (level, message) => {
|
|
78
130
|
console.error(`[Satoru] ${LogLevel[level]}: ${message}`);
|
|
@@ -155,8 +207,16 @@ Options:
|
|
|
155
207
|
-w, --width <number> Viewport width (default: 800)
|
|
156
208
|
-h, --height <number> Viewport height (default: 0, auto-calculate)
|
|
157
209
|
-f, --format <format> Output format: svg, png, webp, pdf
|
|
210
|
+
--json-report <path> Write diagnostics report to a JSON file
|
|
158
211
|
--no-jsdom Disable JSDOM hydration (enabled by default)
|
|
159
212
|
--media <type> Media type: screen, print (default: screen)
|
|
213
|
+
--timeout <ms> Rendering timeout in milliseconds
|
|
214
|
+
--max-resource-bytes <bytes> Max size for a single resource
|
|
215
|
+
--max-total-resource-bytes <bytes> Max total size for all resources
|
|
216
|
+
--max-resource-count <count> Max number of resources to load
|
|
217
|
+
--allowed-protocols <list> Comma-separated allowed protocols (e.g. http:,https:)
|
|
218
|
+
--allowed-hosts <list> Comma-separated allowed hostnames
|
|
219
|
+
--blocked-hosts <list> Comma-separated blocked hostnames
|
|
160
220
|
--verbose Enable detailed logging
|
|
161
221
|
--help Show this help message
|
|
162
222
|
`);
|
package/dist/core.d.ts
CHANGED
|
@@ -3,7 +3,10 @@ export interface SatoruModule {
|
|
|
3
3
|
create_instance: () => any;
|
|
4
4
|
destroy_instance: (inst: any) => void;
|
|
5
5
|
collect_resources: (inst: any, html: string, width: number, height: number, mediaType: number) => void;
|
|
6
|
+
get_collect_profile: (inst: any) => string;
|
|
7
|
+
set_collect_profile_enabled: (inst: any, enabled: boolean) => void;
|
|
6
8
|
get_pending_resources: (inst: any) => Uint8Array | null;
|
|
9
|
+
get_font_diagnostics: (inst: any) => string;
|
|
7
10
|
add_resource: (inst: any, url: string, type: number, data: Uint8Array) => void;
|
|
8
11
|
scan_css: (inst: any, css: string) => void;
|
|
9
12
|
load_font: (inst: any, name: string, data: Uint8Array) => void;
|
|
@@ -20,6 +23,20 @@ export interface SatoruModule {
|
|
|
20
23
|
onLog?: (level: LogLevel, message: string) => void;
|
|
21
24
|
logLevel: LogLevel;
|
|
22
25
|
}
|
|
26
|
+
export interface WorkerPoolStats {
|
|
27
|
+
/** Number of workers in the pool */
|
|
28
|
+
workerCount: number;
|
|
29
|
+
/** Jobs currently being executed */
|
|
30
|
+
activeJobs: number;
|
|
31
|
+
/** Jobs waiting for a free worker */
|
|
32
|
+
queuedJobs: number;
|
|
33
|
+
/** Total jobs completed successfully since start */
|
|
34
|
+
completedJobs: number;
|
|
35
|
+
/** Total jobs that failed since start */
|
|
36
|
+
failedJobs: number;
|
|
37
|
+
/** Average time per job in milliseconds */
|
|
38
|
+
avgJobTimeMs: number;
|
|
39
|
+
}
|
|
23
40
|
export interface RequiredResource {
|
|
24
41
|
type: "font" | "css" | "image";
|
|
25
42
|
url: string;
|
|
@@ -35,7 +52,66 @@ export interface ResolvedFontResult {
|
|
|
35
52
|
}[];
|
|
36
53
|
}
|
|
37
54
|
export type ResourceResolver = (resource: RequiredResource, defaultResolver: (resource: RequiredResource) => Promise<Uint8Array | ResolvedFontResult | null>) => Promise<Uint8Array | ArrayBufferView | ResolvedFontResult | null>;
|
|
55
|
+
export interface RenderDiagnostics {
|
|
56
|
+
version: 1;
|
|
57
|
+
format: "svg" | "png" | "webp" | "pdf";
|
|
58
|
+
width: number;
|
|
59
|
+
height?: number;
|
|
60
|
+
mediaType: "screen" | "print";
|
|
61
|
+
timings: Record<string, number>;
|
|
62
|
+
resources: ResourceDiagnostic[];
|
|
63
|
+
fonts: FontDiagnostic[];
|
|
64
|
+
warnings: DiagnosticMessage[];
|
|
65
|
+
errors: DiagnosticMessage[];
|
|
66
|
+
}
|
|
67
|
+
export interface ResourceDiagnostic {
|
|
68
|
+
type: "font" | "css" | "image";
|
|
69
|
+
url: string;
|
|
70
|
+
name?: string;
|
|
71
|
+
status: "pending" | "loaded" | "failed" | "skipped";
|
|
72
|
+
bytes?: number;
|
|
73
|
+
reason?: string;
|
|
74
|
+
}
|
|
75
|
+
export interface FontDiagnostic {
|
|
76
|
+
family: string;
|
|
77
|
+
weight?: number;
|
|
78
|
+
style?: "normal" | "italic" | "oblique";
|
|
79
|
+
status: "loaded" | "fallback" | "missing";
|
|
80
|
+
source?: string;
|
|
81
|
+
characters?: string;
|
|
82
|
+
}
|
|
83
|
+
export interface DiagnosticMessage {
|
|
84
|
+
code: string;
|
|
85
|
+
message: string;
|
|
86
|
+
source?: string;
|
|
87
|
+
}
|
|
88
|
+
export declare const DIAGNOSTIC_CODES: {
|
|
89
|
+
readonly LIMIT_TIMEOUT: "LIMIT_TIMEOUT";
|
|
90
|
+
readonly LIMIT_RESOURCE_SIZE: "LIMIT_RESOURCE_SIZE";
|
|
91
|
+
readonly LIMIT_TOTAL_SIZE: "LIMIT_TOTAL_SIZE";
|
|
92
|
+
readonly LIMIT_RESOURCE_COUNT: "LIMIT_RESOURCE_COUNT";
|
|
93
|
+
readonly LIMIT_PROTOCOL_BLOCKED: "LIMIT_PROTOCOL_BLOCKED";
|
|
94
|
+
readonly LIMIT_HOST_BLOCKED: "LIMIT_HOST_BLOCKED";
|
|
95
|
+
};
|
|
96
|
+
export interface RenderLimits {
|
|
97
|
+
/** Timeout for the entire render process in milliseconds */
|
|
98
|
+
timeoutMs?: number;
|
|
99
|
+
/** Maximum bytes for a single resource */
|
|
100
|
+
maxResourceBytes?: number;
|
|
101
|
+
/** Maximum total bytes for all resources */
|
|
102
|
+
maxTotalResourceBytes?: number;
|
|
103
|
+
/** Maximum number of resources to load */
|
|
104
|
+
maxResourceCount?: number;
|
|
105
|
+
/** Allowed URL protocols (e.g., ["http:", "https:"]) */
|
|
106
|
+
allowedProtocols?: string[];
|
|
107
|
+
/** Allowed hostnames (e.g., ["example.com", "fonts.googleapis.com"]) */
|
|
108
|
+
allowedHosts?: string[];
|
|
109
|
+
/** Blocked hostnames */
|
|
110
|
+
blockedHosts?: string[];
|
|
111
|
+
}
|
|
38
112
|
export interface RenderOptions {
|
|
113
|
+
/** Abort signal to cancel rendering */
|
|
114
|
+
signal?: AbortSignal;
|
|
39
115
|
/** Input content (HTML string or state object) */
|
|
40
116
|
value?: string | string[] | any | any[];
|
|
41
117
|
/** Source URL */
|
|
@@ -87,10 +163,39 @@ export interface RenderOptions {
|
|
|
87
163
|
onLog?: (level: LogLevel, message: string) => void;
|
|
88
164
|
/** Media type for CSS @media queries (default: "screen") */
|
|
89
165
|
mediaType?: "screen" | "print";
|
|
166
|
+
/** Rendering limits for safety and performance */
|
|
167
|
+
limits?: RenderLimits;
|
|
90
168
|
/** Collect coarse render timings for diagnostics */
|
|
91
169
|
profile?: boolean;
|
|
92
170
|
/** Receives coarse render timings when profile is enabled */
|
|
93
171
|
onProfile?: (profile: Record<string, number>) => void;
|
|
172
|
+
/** Enable full rendering diagnostics */
|
|
173
|
+
diagnostics?: boolean;
|
|
174
|
+
/** Receives the full diagnostics report if diagnostics is enabled */
|
|
175
|
+
onDiagnostics?: (report: RenderDiagnostics) => void;
|
|
176
|
+
/** PDF Title metadata */
|
|
177
|
+
pdfTitle?: string;
|
|
178
|
+
/** PDF Author metadata */
|
|
179
|
+
pdfAuthor?: string;
|
|
180
|
+
/** PDF Subject metadata */
|
|
181
|
+
pdfSubject?: string;
|
|
182
|
+
/** PDF Keywords metadata */
|
|
183
|
+
pdfKeywords?: string;
|
|
184
|
+
/** PDF Creator metadata */
|
|
185
|
+
pdfCreator?: string;
|
|
186
|
+
/** PDF Producer metadata */
|
|
187
|
+
pdfProducer?: string;
|
|
188
|
+
/** PDF page margins in pixels */
|
|
189
|
+
pdfMargin?: {
|
|
190
|
+
top?: number;
|
|
191
|
+
right?: number;
|
|
192
|
+
bottom?: number;
|
|
193
|
+
left?: number;
|
|
194
|
+
};
|
|
195
|
+
/** PDF header HTML template. Supports {{pageNumber}} and {{totalPages}} */
|
|
196
|
+
pdfHeader?: string;
|
|
197
|
+
/** PDF footer HTML template. Supports {{pageNumber}} and {{totalPages}} */
|
|
198
|
+
pdfFooter?: string;
|
|
94
199
|
}
|
|
95
200
|
export declare const DEFAULT_FONT_MAP: Record<string, string>;
|
|
96
201
|
export declare function resolveGoogleFonts(resource: RequiredResource, userAgent?: string): Promise<ResolvedFontResult | Uint8Array | null>;
|