@lpdfio/lpdf 0.31.0 → 0.33.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 +2 -0
- package/dist/L.d.ts +8 -2
- package/dist/L.js +7 -2
- package/dist/_shared.d.ts +23 -3
- package/dist/_shared.js +19 -3
- package/dist/attrs.d.ts +600 -13
- package/dist/browser.js +282 -33
- package/dist/constants.d.ts +7 -0
- package/dist/constants.js +7 -1
- package/dist/engine.d.ts +58 -13
- package/dist/engine.js +185 -102
- package/dist/index.d.ts +3 -2
- package/dist/index.js +2 -1
- package/dist/kit-to-xml.js +5 -4
- package/dist/kit.d.ts +87 -5
- package/dist/kit.js +11 -2
- package/dist/render-error.d.ts +11 -0
- package/dist/render-error.js +19 -0
- package/dist/render-job.d.ts +67 -0
- package/dist/render-job.js +74 -0
- package/dist/render-queue.d.ts +52 -0
- package/dist/render-queue.js +116 -0
- package/dist/render-worker.d.ts +1 -0
- package/dist/render-worker.js +16 -0
- package/dist/stamp.d.ts +51 -0
- package/dist/stamp.js +30 -0
- package/dist/wasm/lpdf-web.js +73 -2
- package/dist/wasm/lpdf.js +73 -2
- package/dist/wasm/lpdf_bg.wasm +0 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -47,6 +47,8 @@ An ES module or a TypeScript file imports the same names, and gets the same clas
|
|
|
47
47
|
import { L, NoAttr } from '@lpdfio/lpdf'
|
|
48
48
|
```
|
|
49
49
|
|
|
50
|
+
A render runs on a worker thread, one at a time, and doesn't hold up the event loop. It stops with an `LpdfRenderError` after 5 seconds; `L.engine({ timeout: 60 })` sets another limit in seconds, and `timeout: 0` sets none. It also stops once it needs more than 1024 MB of memory; `L.engine({ maxMemoryMb: 2048 })` sets another cap, from 1 to 4096 MB.
|
|
51
|
+
|
|
50
52
|
## Requirements
|
|
51
53
|
|
|
52
54
|
- Node.js 20+
|
package/dist/L.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { DocumentAssets, DocumentTokens, PdfDocument } from './kit';
|
|
2
|
+
import type { EngineOptions } from './_shared';
|
|
2
3
|
import { PdfEngine } from './engine';
|
|
3
4
|
/** Pass as `attrs` when a node has no attributes. Equivalent to `null`. */
|
|
4
5
|
export declare const NoAttr: null;
|
|
@@ -25,8 +26,13 @@ export declare const NoAttr: null;
|
|
|
25
26
|
* ```
|
|
26
27
|
*/
|
|
27
28
|
export declare const L: Readonly<{
|
|
28
|
-
/**
|
|
29
|
-
|
|
29
|
+
/**
|
|
30
|
+
* Create a new {@link PdfEngine} instance. Call `.setLicenseKey()` to configure.
|
|
31
|
+
*
|
|
32
|
+
* @param options - `timeout`: the seconds a render may run, 5 when left out, no limit at 0. `maxMemoryMb`: the
|
|
33
|
+
* megabytes a render may allocate, 1024 when left out, from 1 to 4096.
|
|
34
|
+
*/
|
|
35
|
+
engine: (options?: EngineOptions) => PdfEngine;
|
|
30
36
|
/** Convert a `PdfDocument` tree to an lpdf XML string. */
|
|
31
37
|
toXml: (doc: PdfDocument) => string;
|
|
32
38
|
document: (attrs: import("./kit").DocumentAttr | null, nodes?: import("./kit").LpdfSectionNode[]) => PdfDocument;
|
package/dist/L.js
CHANGED
|
@@ -32,8 +32,13 @@ exports.NoAttr = null;
|
|
|
32
32
|
* ```
|
|
33
33
|
*/
|
|
34
34
|
exports.L = Object.freeze({
|
|
35
|
-
/**
|
|
36
|
-
|
|
35
|
+
/**
|
|
36
|
+
* Create a new {@link PdfEngine} instance. Call `.setLicenseKey()` to configure.
|
|
37
|
+
*
|
|
38
|
+
* @param options - `timeout`: the seconds a render may run, 5 when left out, no limit at 0. `maxMemoryMb`: the
|
|
39
|
+
* megabytes a render may allocate, 1024 when left out, from 1 to 4096.
|
|
40
|
+
*/
|
|
41
|
+
engine: (options) => new engine_1.PdfEngine(options),
|
|
37
42
|
/** Convert a `PdfDocument` tree to an lpdf XML string. */
|
|
38
43
|
toXml: (doc) => (0, kit_to_xml_1.kitToXml)(doc),
|
|
39
44
|
// ── Kit ───────────────────────────────────────────────────────────────────
|
package/dist/_shared.d.ts
CHANGED
|
@@ -1,15 +1,35 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Shared types used by both the Node.js and browser entry points.
|
|
3
3
|
*/
|
|
4
|
-
|
|
4
|
+
import type { EncryptionArguments } from './render-job';
|
|
5
|
+
/** Construction-time configuration for `PdfEngine`, `L.engine()` and `initLpdf`. */
|
|
5
6
|
export interface EngineOptions {
|
|
7
|
+
/**
|
|
8
|
+
* The seconds a render may run before it rejects with an `LpdfRenderError` that names the limit: 5 when left out,
|
|
9
|
+
* no limit at 0. A render runs on a worker, which is stopped at the limit and replaced for the next render.
|
|
10
|
+
*/
|
|
11
|
+
timeout?: number;
|
|
12
|
+
/**
|
|
13
|
+
* The megabytes of memory a render may allocate: 1024 when left out, a whole number from 1 to 4096. A render that
|
|
14
|
+
* needs more rejects with an `LpdfRenderError` that names the cap. What the engine holds before the render, such as
|
|
15
|
+
* the fonts it loaded, doesn't count.
|
|
16
|
+
*/
|
|
17
|
+
maxMemoryMb?: number;
|
|
6
18
|
}
|
|
19
|
+
/** The megabytes a render may allocate when `maxMemoryMb` is left out. */
|
|
20
|
+
export declare const DEFAULT_MAX_MEMORY_MB = 1024;
|
|
21
|
+
/**
|
|
22
|
+
* The megabytes a render may allocate, from the `maxMemoryMb` of the engine's options: 1024 when left out.
|
|
23
|
+
*
|
|
24
|
+
* @throws {RangeError} when `maxMemoryMb` is not a whole number from 1 to 4096.
|
|
25
|
+
*/
|
|
26
|
+
export declare function maxMemoryMb(value: number | undefined): number;
|
|
7
27
|
export interface RenderOptions {
|
|
8
28
|
/**
|
|
9
29
|
* Optional ISO 8601 creation timestamp (e.g. `"2024-06-01T12:00:00"`).
|
|
10
30
|
* When provided, written as `/CreationDate` in the PDF info dictionary.
|
|
11
31
|
* Omitting this keeps builds reproducible (no embedded timestamp).
|
|
12
|
-
* Required for a document whose `output` asks for `pdfa`, which writes it as both dates of the file.
|
|
32
|
+
* Required for a document whose `output` asks for `pdfa`, `pdfua` or `pdfx`, which writes it as both dates of the file.
|
|
13
33
|
*/
|
|
14
34
|
createdOn?: string;
|
|
15
35
|
/**
|
|
@@ -41,7 +61,7 @@ export interface RenderOptions {
|
|
|
41
61
|
* and, when there is a password, 32 bytes from the platform's secure generator for AES-256 to cut its key, salts
|
|
42
62
|
* and IVs from, fresh for each render.
|
|
43
63
|
*/
|
|
44
|
-
export declare function encryptionArguments(options: RenderOptions, randomBytes: (count: number) => Uint8Array):
|
|
64
|
+
export declare function encryptionArguments(options: RenderOptions, randomBytes: (count: number) => Uint8Array): EncryptionArguments;
|
|
45
65
|
/** The value of an attribute in a document tree: a string, a number or a boolean, as the schema types it. */
|
|
46
66
|
export type AttrValue = string | number | boolean;
|
|
47
67
|
/**
|
package/dist/_shared.js
CHANGED
|
@@ -1,12 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Shared types used by both the Node.js and browser entry points.
|
|
4
|
-
*/
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_MAX_MEMORY_MB = void 0;
|
|
4
|
+
exports.maxMemoryMb = maxMemoryMb;
|
|
6
5
|
exports.encryptionArguments = encryptionArguments;
|
|
7
6
|
exports.buildAttrs = buildAttrs;
|
|
8
7
|
exports.assertFinite = assertFinite;
|
|
9
8
|
exports.assertFiniteIn = assertFiniteIn;
|
|
9
|
+
/** The megabytes a render may allocate when `maxMemoryMb` is left out. */
|
|
10
|
+
exports.DEFAULT_MAX_MEMORY_MB = 1024;
|
|
11
|
+
/** The most `maxMemoryMb` may be: 32-bit WebAssembly addresses 4 GB at most. */
|
|
12
|
+
const MAX_MEMORY_MB = 4096;
|
|
13
|
+
/**
|
|
14
|
+
* The megabytes a render may allocate, from the `maxMemoryMb` of the engine's options: 1024 when left out.
|
|
15
|
+
*
|
|
16
|
+
* @throws {RangeError} when `maxMemoryMb` is not a whole number from 1 to 4096.
|
|
17
|
+
*/
|
|
18
|
+
function maxMemoryMb(value) {
|
|
19
|
+
if (value === undefined)
|
|
20
|
+
return exports.DEFAULT_MAX_MEMORY_MB;
|
|
21
|
+
if (!Number.isInteger(value) || value < 1 || value > MAX_MEMORY_MB) {
|
|
22
|
+
throw new RangeError(`maxMemoryMb must be a whole number of megabytes from 1 to ${MAX_MEMORY_MB}, not ${value}`);
|
|
23
|
+
}
|
|
24
|
+
return value;
|
|
25
|
+
}
|
|
10
26
|
/** The random bytes AES-256 needs from the host, one 256-bit key's worth. The engine makes none itself. */
|
|
11
27
|
const ENTROPY_BYTES = 32;
|
|
12
28
|
/**
|