@spinajs/templates-puppeteer 2.0.490 → 2.0.494
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 +44 -44
- package/lib/tsconfig.cjs.tsbuildinfo +1 -1
- package/lib/tsconfig.mjs.tsbuildinfo +1 -1
- package/package.json +71 -71
package/README.md
CHANGED
|
@@ -1,44 +1,44 @@
|
|
|
1
|
-
# @spinajs/templates-puppeteer
|
|
2
|
-
|
|
3
|
-
Base Puppeteer renderer for SpineJS templates. This package provides shared logic for rendering templates using Puppeteer.
|
|
4
|
-
|
|
5
|
-
## Installation
|
|
6
|
-
|
|
7
|
-
``bash
|
|
8
|
-
npm install @spinajs/templates-puppeteer
|
|
9
|
-
``
|
|
10
|
-
|
|
11
|
-
## Render progress
|
|
12
|
-
|
|
13
|
-
PDF/image renders can take a long time when the HTML pulls in many external
|
|
14
|
-
resources (images, fonts, stylesheets). Pass an `onProgress` callback to observe
|
|
15
|
-
what the render is doing - especially while resources are loading.
|
|
16
|
-
|
|
17
|
-
Progress is reported through discrete phases (`starting` → `preparing` →
|
|
18
|
-
`loading` → `rendering` → `done`, or `failed`) with a best-effort `percent`,
|
|
19
|
-
live resource counters, and elapsed time. The callback is fire-and-forget: it is
|
|
20
|
-
never awaited and its errors are swallowed, so it can neither slow nor break a
|
|
21
|
-
render. Emissions are throttled, with a heartbeat during the long phases so the
|
|
22
|
-
value keeps moving even when a single resource is slow.
|
|
23
|
-
|
|
24
|
-
``ts
|
|
25
|
-
await pdfRenderer.renderToFile('invoice.pdf', model, 'out/invoice.pdf', 'en', {
|
|
26
|
-
onProgress: (p) => {
|
|
27
|
-
// p: { phase, percent, resourcesLoaded, resourcesPending, resourcesFailed, elapsedMs, filePath, message }
|
|
28
|
-
console.log(`${p.phase} ${p.percent}% - ${p.message}`);
|
|
29
|
-
},
|
|
30
|
-
});
|
|
31
|
-
``
|
|
32
|
-
|
|
33
|
-
The same option works on `renderHtmlToFile(html, filePath, { onProgress })` and
|
|
34
|
-
flows through the `Templates` facade (`render` / `renderToFile` / `compile` /
|
|
35
|
-
`compileToFile`). The CLI commands `render-pdf` / `render-image` already render a
|
|
36
|
-
live progress line via the shared `cliProgressReporter()`.
|
|
37
|
-
|
|
38
|
-
Reporting progress from a queue job is a one-liner - forward the percentage:
|
|
39
|
-
|
|
40
|
-
``ts
|
|
41
|
-
await templates.renderToFile('report.pdf', model, out, lang, {
|
|
42
|
-
onProgress: (p) => void jobProgress(p.percent),
|
|
43
|
-
});
|
|
44
|
-
``
|
|
1
|
+
# @spinajs/templates-puppeteer
|
|
2
|
+
|
|
3
|
+
Base Puppeteer renderer for SpineJS templates. This package provides shared logic for rendering templates using Puppeteer.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
``bash
|
|
8
|
+
npm install @spinajs/templates-puppeteer
|
|
9
|
+
``
|
|
10
|
+
|
|
11
|
+
## Render progress
|
|
12
|
+
|
|
13
|
+
PDF/image renders can take a long time when the HTML pulls in many external
|
|
14
|
+
resources (images, fonts, stylesheets). Pass an `onProgress` callback to observe
|
|
15
|
+
what the render is doing - especially while resources are loading.
|
|
16
|
+
|
|
17
|
+
Progress is reported through discrete phases (`starting` → `preparing` →
|
|
18
|
+
`loading` → `rendering` → `done`, or `failed`) with a best-effort `percent`,
|
|
19
|
+
live resource counters, and elapsed time. The callback is fire-and-forget: it is
|
|
20
|
+
never awaited and its errors are swallowed, so it can neither slow nor break a
|
|
21
|
+
render. Emissions are throttled, with a heartbeat during the long phases so the
|
|
22
|
+
value keeps moving even when a single resource is slow.
|
|
23
|
+
|
|
24
|
+
``ts
|
|
25
|
+
await pdfRenderer.renderToFile('invoice.pdf', model, 'out/invoice.pdf', 'en', {
|
|
26
|
+
onProgress: (p) => {
|
|
27
|
+
// p: { phase, percent, resourcesLoaded, resourcesPending, resourcesFailed, elapsedMs, filePath, message }
|
|
28
|
+
console.log(`${p.phase} ${p.percent}% - ${p.message}`);
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
``
|
|
32
|
+
|
|
33
|
+
The same option works on `renderHtmlToFile(html, filePath, { onProgress })` and
|
|
34
|
+
flows through the `Templates` facade (`render` / `renderToFile` / `compile` /
|
|
35
|
+
`compileToFile`). The CLI commands `render-pdf` / `render-image` already render a
|
|
36
|
+
live progress line via the shared `cliProgressReporter()`.
|
|
37
|
+
|
|
38
|
+
Reporting progress from a queue job is a one-liner - forward the percentage:
|
|
39
|
+
|
|
40
|
+
``ts
|
|
41
|
+
await templates.renderToFile('report.pdf', model, out, lang, {
|
|
42
|
+
onProgress: (p) => void jobProgress(p.percent),
|
|
43
|
+
});
|
|
44
|
+
``
|