@lpdfio/lpdf 0.29.0 → 0.31.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/LICENSE +1 -1
- package/README.md +2 -2
- package/dist/L.d.ts +7 -2
- package/dist/L.js +6 -0
- package/dist/_shared.d.ts +42 -3
- package/dist/_shared.js +52 -3
- package/dist/attrs.d.ts +733 -65
- package/dist/browser.js +126 -47
- package/dist/canvas.d.ts +13 -12
- package/dist/constants.d.ts +27 -0
- package/dist/constants.js +25 -1
- package/dist/engine.d.ts +19 -28
- package/dist/engine.js +129 -27
- package/dist/index.d.ts +6 -5
- package/dist/index.js +7 -1
- package/dist/kit.d.ts +49 -33
- package/dist/kit.js +7 -1
- package/dist/layout.d.ts +62 -19
- package/dist/layout.js +26 -0
- package/dist/markdown.d.ts +76 -0
- package/dist/markdown.js +63 -0
- package/dist/wasm/lpdf-web.js +191 -36
- package/dist/wasm/lpdf.js +197 -36
- package/dist/wasm/lpdf_bg.wasm +0 -0
- package/package.json +4 -1
package/dist/wasm/lpdf.js
CHANGED
|
@@ -12,10 +12,17 @@ class LpdfEngine {
|
|
|
12
12
|
wasm.__wbg_lpdfengine_free(ptr, 0);
|
|
13
13
|
}
|
|
14
14
|
/**
|
|
15
|
-
*
|
|
15
|
+
* Register the bytes of a file a document carries, for the `<file>` of its `<attachments>` whose `ref`, or with
|
|
16
|
+
* no ref whose name, is `name`. The PDF carries them as they are.
|
|
17
|
+
* @param {string} name
|
|
18
|
+
* @param {Uint8Array} bytes
|
|
16
19
|
*/
|
|
17
|
-
|
|
18
|
-
wasm.
|
|
20
|
+
load_file(name, bytes) {
|
|
21
|
+
const ptr0 = passStringToWasm0(name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
22
|
+
const len0 = WASM_VECTOR_LEN;
|
|
23
|
+
const ptr1 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
|
|
24
|
+
const len1 = WASM_VECTOR_LEN;
|
|
25
|
+
wasm.lpdfengine_load_file(this.__wbg_ptr, ptr0, len0, ptr1, len1);
|
|
19
26
|
}
|
|
20
27
|
/**
|
|
21
28
|
* Register raw font bytes (TTF/OTF) for a custom font name.
|
|
@@ -46,6 +53,20 @@ class LpdfEngine {
|
|
|
46
53
|
const len1 = WASM_VECTOR_LEN;
|
|
47
54
|
wasm.lpdfengine_load_image(this.__wbg_ptr, ptr0, len0, ptr1, len1);
|
|
48
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* Register the text of a file of Markdown rules, the root of which is a `<markdown-styles>`, for the
|
|
58
|
+
* `src` that names it. The engine reads no files: call this once for every `<markdown-styles src="…">`
|
|
59
|
+
* of the document before `render_pdf`, as `load_font` is called for a font.
|
|
60
|
+
* @param {string} src
|
|
61
|
+
* @param {string} xml
|
|
62
|
+
*/
|
|
63
|
+
load_markdown_styles(src, xml) {
|
|
64
|
+
const ptr0 = passStringToWasm0(src, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
65
|
+
const len0 = WASM_VECTOR_LEN;
|
|
66
|
+
const ptr1 = passStringToWasm0(xml, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
67
|
+
const len1 = WASM_VECTOR_LEN;
|
|
68
|
+
wasm.lpdfengine_load_markdown_styles(this.__wbg_ptr, ptr0, len0, ptr1, len1);
|
|
69
|
+
}
|
|
49
70
|
/**
|
|
50
71
|
* @param {string} license_key
|
|
51
72
|
*/
|
|
@@ -84,22 +105,38 @@ class LpdfEngine {
|
|
|
84
105
|
* `json_data` is an optional JSON string used to resolve `data-*`
|
|
85
106
|
* attributes in the template. Pass `None` (or `null` / `undefined` from
|
|
86
107
|
* JavaScript) to render the template with its inline fallback content.
|
|
108
|
+
*
|
|
109
|
+
* The rest is for a document that asks for encryption in its `<output>`, which sets the cipher and
|
|
110
|
+
* the permissions: the passwords, which the template never holds, and `entropy`, at least 32 random
|
|
111
|
+
* bytes from the host's secure generator for AES-256. A document that asks for encryption needs an
|
|
112
|
+
* owner password, or `skip_encryption` to render it unencrypted, as a preview does; passwords for a
|
|
113
|
+
* document that doesn't ask for it are an error, and so are passwords with `skip_encryption`.
|
|
87
114
|
* @param {string} xml
|
|
88
|
-
* @param {string | null}
|
|
115
|
+
* @param {string | null | undefined} json_data
|
|
116
|
+
* @param {string | null | undefined} user_password
|
|
117
|
+
* @param {string | null | undefined} owner_password
|
|
118
|
+
* @param {boolean} skip_encryption
|
|
119
|
+
* @param {Uint8Array} entropy
|
|
89
120
|
* @returns {Uint8Array}
|
|
90
121
|
*/
|
|
91
|
-
render_pdf(xml, json_data) {
|
|
122
|
+
render_pdf(xml, json_data, user_password, owner_password, skip_encryption, entropy) {
|
|
92
123
|
const ptr0 = passStringToWasm0(xml, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
93
124
|
const len0 = WASM_VECTOR_LEN;
|
|
94
125
|
var ptr1 = isLikeNone(json_data) ? 0 : passStringToWasm0(json_data, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
95
126
|
var len1 = WASM_VECTOR_LEN;
|
|
96
|
-
|
|
127
|
+
var ptr2 = isLikeNone(user_password) ? 0 : passStringToWasm0(user_password, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
128
|
+
var len2 = WASM_VECTOR_LEN;
|
|
129
|
+
var ptr3 = isLikeNone(owner_password) ? 0 : passStringToWasm0(owner_password, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
130
|
+
var len3 = WASM_VECTOR_LEN;
|
|
131
|
+
const ptr4 = passArray8ToWasm0(entropy, wasm.__wbindgen_malloc);
|
|
132
|
+
const len4 = WASM_VECTOR_LEN;
|
|
133
|
+
const ret = wasm.lpdfengine_render_pdf(this.__wbg_ptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, skip_encryption, ptr4, len4);
|
|
97
134
|
if (ret[3]) {
|
|
98
135
|
throw takeFromExternrefTable0(ret[2]);
|
|
99
136
|
}
|
|
100
|
-
var
|
|
137
|
+
var v6 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
101
138
|
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
102
|
-
return
|
|
139
|
+
return v6;
|
|
103
140
|
}
|
|
104
141
|
/**
|
|
105
142
|
* @param {string} json
|
|
@@ -126,23 +163,37 @@ class LpdfEngine {
|
|
|
126
163
|
* when an `LpdfDocument` Kit tree is passed to `renderPdf()`, avoiding an
|
|
127
164
|
* intermediate XML serialisation step. PHP, Python, and .NET adapters also
|
|
128
165
|
* use this entry point.
|
|
166
|
+
*
|
|
167
|
+
* The passwords, `skip_encryption` and `entropy` are those of `render_pdf`, for a document whose
|
|
168
|
+
* `output` asks for encryption.
|
|
129
169
|
* @param {string} json
|
|
170
|
+
* @param {string | null | undefined} user_password
|
|
171
|
+
* @param {string | null | undefined} owner_password
|
|
172
|
+
* @param {boolean} skip_encryption
|
|
173
|
+
* @param {Uint8Array} entropy
|
|
130
174
|
* @returns {Uint8Array}
|
|
131
175
|
*/
|
|
132
|
-
render_tree_pdf(json) {
|
|
176
|
+
render_tree_pdf(json, user_password, owner_password, skip_encryption, entropy) {
|
|
133
177
|
const ptr0 = passStringToWasm0(json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
134
178
|
const len0 = WASM_VECTOR_LEN;
|
|
135
|
-
|
|
179
|
+
var ptr1 = isLikeNone(user_password) ? 0 : passStringToWasm0(user_password, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
180
|
+
var len1 = WASM_VECTOR_LEN;
|
|
181
|
+
var ptr2 = isLikeNone(owner_password) ? 0 : passStringToWasm0(owner_password, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
182
|
+
var len2 = WASM_VECTOR_LEN;
|
|
183
|
+
const ptr3 = passArray8ToWasm0(entropy, wasm.__wbindgen_malloc);
|
|
184
|
+
const len3 = WASM_VECTOR_LEN;
|
|
185
|
+
const ret = wasm.lpdfengine_render_tree_pdf(this.__wbg_ptr, ptr0, len0, ptr1, len1, ptr2, len2, skip_encryption, ptr3, len3);
|
|
136
186
|
if (ret[3]) {
|
|
137
187
|
throw takeFromExternrefTable0(ret[2]);
|
|
138
188
|
}
|
|
139
|
-
var
|
|
189
|
+
var v5 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
140
190
|
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
141
|
-
return
|
|
191
|
+
return v5;
|
|
142
192
|
}
|
|
143
193
|
/**
|
|
144
|
-
* Set an optional ISO 8601 creation timestamp (e.g. `"2024-06-01T12:00:00"`
|
|
145
|
-
* When provided, written as `/CreationDate` in the PDF info dictionary
|
|
194
|
+
* Set an optional ISO 8601 creation timestamp (e.g. `"2024-06-01T12:00:00"`, `"2024-06-01T12:00:00.000Z"` or
|
|
195
|
+
* `"2024-06-01T12:00:00+01:00"`). When provided, written as `/CreationDate` in the PDF info dictionary, with
|
|
196
|
+
* the precision and the time zone it was given in; a value that is not a date makes the render an error.
|
|
146
197
|
* Omitting this keeps builds reproducible (no embedded timestamp).
|
|
147
198
|
* @param {string} iso
|
|
148
199
|
*/
|
|
@@ -151,28 +202,6 @@ class LpdfEngine {
|
|
|
151
202
|
const len0 = WASM_VECTOR_LEN;
|
|
152
203
|
wasm.lpdfengine_set_created_on(this.__wbg_ptr, ptr0, len0);
|
|
153
204
|
}
|
|
154
|
-
/**
|
|
155
|
-
* Configure RC4-128 encryption applied to every subsequent `render_pdf` call.
|
|
156
|
-
*
|
|
157
|
-
* `permissions_json` is a JSON object with boolean fields matching the
|
|
158
|
-
* `Permissions` struct (`print`, `modify`, `copy`, `annotate`, `fill_forms`,
|
|
159
|
-
* `accessibility`, `assemble`, `print_hq`). Omitted fields default to `true`.
|
|
160
|
-
*
|
|
161
|
-
* To apply permissions without an open password, pass an empty `user_password`
|
|
162
|
-
* and a non-empty `owner_password`.
|
|
163
|
-
* @param {string} user_password
|
|
164
|
-
* @param {string} owner_password
|
|
165
|
-
* @param {string} permissions_json
|
|
166
|
-
*/
|
|
167
|
-
set_encryption(user_password, owner_password, permissions_json) {
|
|
168
|
-
const ptr0 = passStringToWasm0(user_password, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
169
|
-
const len0 = WASM_VECTOR_LEN;
|
|
170
|
-
const ptr1 = passStringToWasm0(owner_password, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
171
|
-
const len1 = WASM_VECTOR_LEN;
|
|
172
|
-
const ptr2 = passStringToWasm0(permissions_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
173
|
-
const len2 = WASM_VECTOR_LEN;
|
|
174
|
-
wasm.lpdfengine_set_encryption(this.__wbg_ptr, ptr0, len0, ptr1, len1, ptr2, len2);
|
|
175
|
-
}
|
|
176
205
|
/**
|
|
177
206
|
* Inject glyph advance-width tables for custom fonts.
|
|
178
207
|
*
|
|
@@ -349,6 +378,138 @@ function kit_to_xml(json) {
|
|
|
349
378
|
}
|
|
350
379
|
}
|
|
351
380
|
exports.kit_to_xml = kit_to_xml;
|
|
381
|
+
|
|
382
|
+
/**
|
|
383
|
+
* The template `template` with an `<image>` declared for each path of the JSON array `srcs`, named as
|
|
384
|
+
* `markdown_file_images` says.
|
|
385
|
+
* @param {string} template
|
|
386
|
+
* @param {string} srcs
|
|
387
|
+
* @returns {string}
|
|
388
|
+
*/
|
|
389
|
+
function markdown_declare_images(template, srcs) {
|
|
390
|
+
let deferred4_0;
|
|
391
|
+
let deferred4_1;
|
|
392
|
+
try {
|
|
393
|
+
const ptr0 = passStringToWasm0(template, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
394
|
+
const len0 = WASM_VECTOR_LEN;
|
|
395
|
+
const ptr1 = passStringToWasm0(srcs, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
396
|
+
const len1 = WASM_VECTOR_LEN;
|
|
397
|
+
const ret = wasm.markdown_declare_images(ptr0, len0, ptr1, len1);
|
|
398
|
+
var ptr3 = ret[0];
|
|
399
|
+
var len3 = ret[1];
|
|
400
|
+
if (ret[3]) {
|
|
401
|
+
ptr3 = 0; len3 = 0;
|
|
402
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
403
|
+
}
|
|
404
|
+
deferred4_0 = ptr3;
|
|
405
|
+
deferred4_1 = len3;
|
|
406
|
+
return getStringFromWasm0(ptr3, len3);
|
|
407
|
+
} finally {
|
|
408
|
+
wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
exports.markdown_declare_images = markdown_declare_images;
|
|
412
|
+
|
|
413
|
+
/**
|
|
414
|
+
* The rules a `<markdown>` with no styles uses, as the file to start a style of one's own from.
|
|
415
|
+
* @returns {string}
|
|
416
|
+
*/
|
|
417
|
+
function markdown_default_styles() {
|
|
418
|
+
let deferred1_0;
|
|
419
|
+
let deferred1_1;
|
|
420
|
+
try {
|
|
421
|
+
const ret = wasm.markdown_default_styles();
|
|
422
|
+
deferred1_0 = ret[0];
|
|
423
|
+
deferred1_1 = ret[1];
|
|
424
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
425
|
+
} finally {
|
|
426
|
+
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
exports.markdown_default_styles = markdown_default_styles;
|
|
430
|
+
|
|
431
|
+
/**
|
|
432
|
+
* The data a template gets for the `.md` file `markdown`, as JSON: the text as `markdown`, and the fields of its
|
|
433
|
+
* front matter, each a string.
|
|
434
|
+
* @param {string} markdown
|
|
435
|
+
* @returns {string}
|
|
436
|
+
*/
|
|
437
|
+
function markdown_file_data(markdown) {
|
|
438
|
+
let deferred2_0;
|
|
439
|
+
let deferred2_1;
|
|
440
|
+
try {
|
|
441
|
+
const ptr0 = passStringToWasm0(markdown, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
442
|
+
const len0 = WASM_VECTOR_LEN;
|
|
443
|
+
const ret = wasm.markdown_file_data(ptr0, len0);
|
|
444
|
+
deferred2_0 = ret[0];
|
|
445
|
+
deferred2_1 = ret[1];
|
|
446
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
447
|
+
} finally {
|
|
448
|
+
wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
exports.markdown_file_data = markdown_file_data;
|
|
452
|
+
|
|
453
|
+
/**
|
|
454
|
+
* The relative paths of the images of the `.md` file `markdown`, as a JSON array. The caller declares them with
|
|
455
|
+
* `markdown_declare_images` and loads each file, relative to the `.md`, under the name `markdown-image-N` where N
|
|
456
|
+
* counts from 1 in the order of the array.
|
|
457
|
+
* @param {string} markdown
|
|
458
|
+
* @returns {string}
|
|
459
|
+
*/
|
|
460
|
+
function markdown_file_images(markdown) {
|
|
461
|
+
let deferred2_0;
|
|
462
|
+
let deferred2_1;
|
|
463
|
+
try {
|
|
464
|
+
const ptr0 = passStringToWasm0(markdown, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
465
|
+
const len0 = WASM_VECTOR_LEN;
|
|
466
|
+
const ret = wasm.markdown_file_images(ptr0, len0);
|
|
467
|
+
deferred2_0 = ret[0];
|
|
468
|
+
deferred2_1 = ret[1];
|
|
469
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
470
|
+
} finally {
|
|
471
|
+
wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
exports.markdown_file_images = markdown_file_images;
|
|
475
|
+
|
|
476
|
+
/**
|
|
477
|
+
* The looks a `.md` file can start from besides the default one, as a JSON array of `name`, `label`, `description`
|
|
478
|
+
* and `styles`: the file of styles, to write beside the `.md` file and edit.
|
|
479
|
+
* @returns {string}
|
|
480
|
+
*/
|
|
481
|
+
function markdown_style_presets() {
|
|
482
|
+
let deferred1_0;
|
|
483
|
+
let deferred1_1;
|
|
484
|
+
try {
|
|
485
|
+
const ret = wasm.markdown_style_presets();
|
|
486
|
+
deferred1_0 = ret[0];
|
|
487
|
+
deferred1_1 = ret[1];
|
|
488
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
489
|
+
} finally {
|
|
490
|
+
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
exports.markdown_style_presets = markdown_style_presets;
|
|
494
|
+
|
|
495
|
+
/**
|
|
496
|
+
* The template that wraps a `.md` file when it is rendered with no template of its own: A4, a margin and the
|
|
497
|
+
* page number. It reads the Markdown from the data `markdown`, the rest of which is the file's front matter.
|
|
498
|
+
* @returns {string}
|
|
499
|
+
*/
|
|
500
|
+
function markdown_template() {
|
|
501
|
+
let deferred1_0;
|
|
502
|
+
let deferred1_1;
|
|
503
|
+
try {
|
|
504
|
+
const ret = wasm.markdown_template();
|
|
505
|
+
deferred1_0 = ret[0];
|
|
506
|
+
deferred1_1 = ret[1];
|
|
507
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
508
|
+
} finally {
|
|
509
|
+
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
exports.markdown_template = markdown_template;
|
|
352
513
|
function __wbg_get_imports() {
|
|
353
514
|
const import0 = {
|
|
354
515
|
__proto__: null,
|
package/dist/wasm/lpdf_bg.wasm
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lpdfio/lpdf",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.31.0",
|
|
4
4
|
"description": "Node.js SDK for Lpdf — PDF as Code on every platform. You describe a document as code or XML. Lpdf renders a compact, pixel-perfect PDF — identical across platforms.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -48,5 +48,8 @@
|
|
|
48
48
|
"@types/node": "^20.0.0",
|
|
49
49
|
"esbuild": "^0.25.0",
|
|
50
50
|
"typescript": "^5.0.0"
|
|
51
|
+
},
|
|
52
|
+
"allowScripts": {
|
|
53
|
+
"esbuild": false
|
|
51
54
|
}
|
|
52
55
|
}
|