@formepdf/core 0.10.0 → 0.10.2

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.
@@ -0,0 +1,84 @@
1
+ # forme-pdf
2
+
3
+ A page-native PDF rendering engine written in Rust. Layout happens **into** pages, not onto an infinite canvas that gets sliced afterward — so page breaks, table headers, and flex layout all work correctly across pages.
4
+
5
+ `cargo add forme-pdf` installs the crate. The library name is `forme`:
6
+
7
+ ```rust
8
+ use forme::{render_json, Document, FormeError};
9
+ ```
10
+
11
+ ## Features
12
+
13
+ - **Page-native layout** — flexbox, tables, and text reflow with real page boundary awareness
14
+ - **CSS-like styling** — flexbox (`row`/`column`, `wrap`, `grow`/`shrink`), CSS Grid, absolute positioning
15
+ - **Text** — OpenType shaping, Knuth-Plass line breaking, hyphenation (35+ languages), BiDi, per-character font fallback
16
+ - **Tables** — automatic header repetition on page breaks, column spans
17
+ - **Images** — JPEG, PNG, WebP (embedded or data URI)
18
+ - **SVG** — inline SVG rendering (rect, circle, line, path, arc)
19
+ - **Charts** — BarChart, LineChart, PieChart, AreaChart, DotPlot (engine-native, no JS)
20
+ - **QR codes & barcodes** — vector rendering (Code128, Code39, EAN13, EAN8, Codabar)
21
+ - **Canvas** — arbitrary vector drawing via a Canvas-like API
22
+ - **Watermarks** — rotated text behind page content
23
+ - **AcroForms** — fillable PDF forms (TextField, Checkbox, Dropdown, RadioButton) with form flattening
24
+ - **PDF/UA-1** — accessibility compliance with structure tree, tab order, role map, artifact tagging
25
+ - **PDF/A** — archival compliance (PDF/A-2b, PDF/A-2a) with full font embedding and XMP metadata
26
+ - **Digital signatures** — PKCS#7 detached signatures with X.509 certificates
27
+ - **Templates** — expression language for dynamic documents (`$ref`, `$each`, `$if`)
28
+ - **WASM** — compiles to WebAssembly for browser and serverless use
29
+
30
+ ## Quick start
31
+
32
+ ```rust
33
+ use forme::{render_json, FormeError};
34
+
35
+ fn main() -> Result<(), FormeError> {
36
+ let json = r#"{
37
+ "pages": [{ "size": "A4" }],
38
+ "children": [{
39
+ "kind": "text",
40
+ "content": "Hello from Forme!",
41
+ "style": { "fontSize": 24, "margin": { "top": 72, "left": 72 } }
42
+ }]
43
+ }"#;
44
+
45
+ let pdf_bytes = render_json(json)?;
46
+ std::fs::write("hello.pdf", pdf_bytes).unwrap();
47
+ Ok(())
48
+ }
49
+ ```
50
+
51
+ ## API
52
+
53
+ ### Rendering
54
+
55
+ | Function | Description |
56
+ |----------|-------------|
57
+ | `render(&Document)` | Render a document struct to PDF bytes |
58
+ | `render_json(&str)` | Parse JSON and render to PDF bytes |
59
+ | `render_with_layout(&Document)` | Render and return PDF bytes + layout metadata |
60
+ | `render_json_with_layout(&str)` | Parse JSON, render, and return PDF bytes + layout metadata |
61
+ | `render_template(&str, &str)` | Evaluate a template with data, then render |
62
+ | `render_template_with_layout(&str, &str)` | Evaluate a template with data, render, and return PDF bytes + layout metadata |
63
+
64
+ ### PDF Operations
65
+
66
+ | Function | Description |
67
+ |----------|-------------|
68
+ | `merge_pdfs(&[&[u8]])` | Combine multiple PDFs into one |
69
+ | `certify_pdf(&[u8], &str, &str, ...)` | Apply a PKCS#7 digital signature to an existing PDF |
70
+ | `redact_pdf(&[u8], &[RedactionRegion])` | Redact regions from a PDF (removes underlying text) |
71
+ | `redact_text(&[u8], &[TextSearchRedaction])` | Find text by pattern and redact matching regions |
72
+ | `find_text_regions(&[u8], &[TextSearchPattern])` | Find text regions in a PDF without redacting |
73
+
74
+ All functions return `Result<Vec<u8>, FormeError>` (or a tuple with `LayoutInfo` for the `_with_layout` variants).
75
+
76
+ ## Documentation
77
+
78
+ - [Full docs](https://docs.formepdf.com) — component reference, styling guide, examples
79
+ - [API reference](https://docs.rs/forme-pdf) — Rust API docs
80
+ - [GitHub](https://github.com/formepdf/forme) — source, issues, JSX/TypeScript packages
81
+
82
+ ## License
83
+
84
+ MIT
@@ -0,0 +1,85 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ /**
5
+ * Certify PDF bytes with an X.509 certificate (PKCS#7 detached signature).
6
+ */
7
+ export function certify_pdf(pdf_bytes: Uint8Array, config_json: string): Uint8Array;
8
+
9
+ /**
10
+ * Find text regions matching patterns in a PDF.
11
+ * Returns JSON string of Vec<RedactionRegion>.
12
+ */
13
+ export function find_text_regions(pdf_bytes: Uint8Array, patterns_json: string): string;
14
+
15
+ export function init_panic_hook(): void;
16
+
17
+ /**
18
+ * Merge multiple PDFs into a single document.
19
+ * Accepts a JSON array of base64-encoded PDF strings.
20
+ */
21
+ export function merge_pdfs(pdfs_json: string): Uint8Array;
22
+
23
+ /**
24
+ * Redact regions of a PDF by overlaying opaque rectangles.
25
+ */
26
+ export function redact_pdf(pdf_bytes: Uint8Array, redactions_json: string): Uint8Array;
27
+
28
+ /**
29
+ * Redact text matching patterns from a PDF.
30
+ */
31
+ export function redact_text(pdf_bytes: Uint8Array, patterns_json: string): Uint8Array;
32
+
33
+ export function render_pdf(json: string): Uint8Array;
34
+
35
+ export function render_pdf_with_layout(json: string): any;
36
+
37
+ export function render_template_pdf(template_json: string, data_json: string): Uint8Array;
38
+
39
+ export function render_template_pdf_with_layout(template_json: string, data_json: string): any;
40
+
41
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
42
+
43
+ export interface InitOutput {
44
+ readonly memory: WebAssembly.Memory;
45
+ readonly certify_pdf: (a: number, b: number, c: number, d: number) => [number, number, number, number];
46
+ readonly find_text_regions: (a: number, b: number, c: number, d: number) => [number, number, number, number];
47
+ readonly merge_pdfs: (a: number, b: number) => [number, number, number, number];
48
+ readonly redact_pdf: (a: number, b: number, c: number, d: number) => [number, number, number, number];
49
+ readonly redact_text: (a: number, b: number, c: number, d: number) => [number, number, number, number];
50
+ readonly render_pdf: (a: number, b: number) => [number, number, number, number];
51
+ readonly render_pdf_with_layout: (a: number, b: number) => [number, number, number];
52
+ readonly render_template_pdf: (a: number, b: number, c: number, d: number) => [number, number, number, number];
53
+ readonly render_template_pdf_with_layout: (a: number, b: number, c: number, d: number) => [number, number, number];
54
+ readonly init_panic_hook: () => void;
55
+ readonly __wbindgen_malloc: (a: number, b: number) => number;
56
+ readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
57
+ readonly __wbindgen_free: (a: number, b: number, c: number) => void;
58
+ readonly __wbindgen_exn_store: (a: number) => void;
59
+ readonly __externref_table_alloc: () => number;
60
+ readonly __wbindgen_externrefs: WebAssembly.Table;
61
+ readonly __externref_table_dealloc: (a: number) => void;
62
+ readonly __wbindgen_start: () => void;
63
+ }
64
+
65
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
66
+
67
+ /**
68
+ * Instantiates the given `module`, which can either be bytes or
69
+ * a precompiled `WebAssembly.Module`.
70
+ *
71
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
72
+ *
73
+ * @returns {InitOutput}
74
+ */
75
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
76
+
77
+ /**
78
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
79
+ * for everything else, calls `WebAssembly.instantiate` directly.
80
+ *
81
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
82
+ *
83
+ * @returns {Promise<InitOutput>}
84
+ */
85
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
@@ -0,0 +1,479 @@
1
+ /* @ts-self-types="./forme.d.ts" */
2
+
3
+ /**
4
+ * Certify PDF bytes with an X.509 certificate (PKCS#7 detached signature).
5
+ * @param {Uint8Array} pdf_bytes
6
+ * @param {string} config_json
7
+ * @returns {Uint8Array}
8
+ */
9
+ export function certify_pdf(pdf_bytes, config_json) {
10
+ const ptr0 = passArray8ToWasm0(pdf_bytes, wasm.__wbindgen_malloc);
11
+ const len0 = WASM_VECTOR_LEN;
12
+ const ptr1 = passStringToWasm0(config_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
13
+ const len1 = WASM_VECTOR_LEN;
14
+ const ret = wasm.certify_pdf(ptr0, len0, ptr1, len1);
15
+ if (ret[3]) {
16
+ throw takeFromExternrefTable0(ret[2]);
17
+ }
18
+ var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
19
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
20
+ return v3;
21
+ }
22
+
23
+ /**
24
+ * Find text regions matching patterns in a PDF.
25
+ * Returns JSON string of Vec<RedactionRegion>.
26
+ * @param {Uint8Array} pdf_bytes
27
+ * @param {string} patterns_json
28
+ * @returns {string}
29
+ */
30
+ export function find_text_regions(pdf_bytes, patterns_json) {
31
+ let deferred4_0;
32
+ let deferred4_1;
33
+ try {
34
+ const ptr0 = passArray8ToWasm0(pdf_bytes, wasm.__wbindgen_malloc);
35
+ const len0 = WASM_VECTOR_LEN;
36
+ const ptr1 = passStringToWasm0(patterns_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
37
+ const len1 = WASM_VECTOR_LEN;
38
+ const ret = wasm.find_text_regions(ptr0, len0, ptr1, len1);
39
+ var ptr3 = ret[0];
40
+ var len3 = ret[1];
41
+ if (ret[3]) {
42
+ ptr3 = 0; len3 = 0;
43
+ throw takeFromExternrefTable0(ret[2]);
44
+ }
45
+ deferred4_0 = ptr3;
46
+ deferred4_1 = len3;
47
+ return getStringFromWasm0(ptr3, len3);
48
+ } finally {
49
+ wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
50
+ }
51
+ }
52
+
53
+ export function init_panic_hook() {
54
+ wasm.init_panic_hook();
55
+ }
56
+
57
+ /**
58
+ * Merge multiple PDFs into a single document.
59
+ * Accepts a JSON array of base64-encoded PDF strings.
60
+ * @param {string} pdfs_json
61
+ * @returns {Uint8Array}
62
+ */
63
+ export function merge_pdfs(pdfs_json) {
64
+ const ptr0 = passStringToWasm0(pdfs_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
65
+ const len0 = WASM_VECTOR_LEN;
66
+ const ret = wasm.merge_pdfs(ptr0, len0);
67
+ if (ret[3]) {
68
+ throw takeFromExternrefTable0(ret[2]);
69
+ }
70
+ var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
71
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
72
+ return v2;
73
+ }
74
+
75
+ /**
76
+ * Redact regions of a PDF by overlaying opaque rectangles.
77
+ * @param {Uint8Array} pdf_bytes
78
+ * @param {string} redactions_json
79
+ * @returns {Uint8Array}
80
+ */
81
+ export function redact_pdf(pdf_bytes, redactions_json) {
82
+ const ptr0 = passArray8ToWasm0(pdf_bytes, wasm.__wbindgen_malloc);
83
+ const len0 = WASM_VECTOR_LEN;
84
+ const ptr1 = passStringToWasm0(redactions_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
85
+ const len1 = WASM_VECTOR_LEN;
86
+ const ret = wasm.redact_pdf(ptr0, len0, ptr1, len1);
87
+ if (ret[3]) {
88
+ throw takeFromExternrefTable0(ret[2]);
89
+ }
90
+ var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
91
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
92
+ return v3;
93
+ }
94
+
95
+ /**
96
+ * Redact text matching patterns from a PDF.
97
+ * @param {Uint8Array} pdf_bytes
98
+ * @param {string} patterns_json
99
+ * @returns {Uint8Array}
100
+ */
101
+ export function redact_text(pdf_bytes, patterns_json) {
102
+ const ptr0 = passArray8ToWasm0(pdf_bytes, wasm.__wbindgen_malloc);
103
+ const len0 = WASM_VECTOR_LEN;
104
+ const ptr1 = passStringToWasm0(patterns_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
105
+ const len1 = WASM_VECTOR_LEN;
106
+ const ret = wasm.redact_text(ptr0, len0, ptr1, len1);
107
+ if (ret[3]) {
108
+ throw takeFromExternrefTable0(ret[2]);
109
+ }
110
+ var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
111
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
112
+ return v3;
113
+ }
114
+
115
+ /**
116
+ * @param {string} json
117
+ * @returns {Uint8Array}
118
+ */
119
+ export function render_pdf(json) {
120
+ const ptr0 = passStringToWasm0(json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
121
+ const len0 = WASM_VECTOR_LEN;
122
+ const ret = wasm.render_pdf(ptr0, len0);
123
+ if (ret[3]) {
124
+ throw takeFromExternrefTable0(ret[2]);
125
+ }
126
+ var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
127
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
128
+ return v2;
129
+ }
130
+
131
+ /**
132
+ * @param {string} json
133
+ * @returns {any}
134
+ */
135
+ export function render_pdf_with_layout(json) {
136
+ const ptr0 = passStringToWasm0(json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
137
+ const len0 = WASM_VECTOR_LEN;
138
+ const ret = wasm.render_pdf_with_layout(ptr0, len0);
139
+ if (ret[2]) {
140
+ throw takeFromExternrefTable0(ret[1]);
141
+ }
142
+ return takeFromExternrefTable0(ret[0]);
143
+ }
144
+
145
+ /**
146
+ * @param {string} template_json
147
+ * @param {string} data_json
148
+ * @returns {Uint8Array}
149
+ */
150
+ export function render_template_pdf(template_json, data_json) {
151
+ const ptr0 = passStringToWasm0(template_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
152
+ const len0 = WASM_VECTOR_LEN;
153
+ const ptr1 = passStringToWasm0(data_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
154
+ const len1 = WASM_VECTOR_LEN;
155
+ const ret = wasm.render_template_pdf(ptr0, len0, ptr1, len1);
156
+ if (ret[3]) {
157
+ throw takeFromExternrefTable0(ret[2]);
158
+ }
159
+ var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
160
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
161
+ return v3;
162
+ }
163
+
164
+ /**
165
+ * @param {string} template_json
166
+ * @param {string} data_json
167
+ * @returns {any}
168
+ */
169
+ export function render_template_pdf_with_layout(template_json, data_json) {
170
+ const ptr0 = passStringToWasm0(template_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
171
+ const len0 = WASM_VECTOR_LEN;
172
+ const ptr1 = passStringToWasm0(data_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
173
+ const len1 = WASM_VECTOR_LEN;
174
+ const ret = wasm.render_template_pdf_with_layout(ptr0, len0, ptr1, len1);
175
+ if (ret[2]) {
176
+ throw takeFromExternrefTable0(ret[1]);
177
+ }
178
+ return takeFromExternrefTable0(ret[0]);
179
+ }
180
+
181
+ function __wbg_get_imports() {
182
+ const import0 = {
183
+ __proto__: null,
184
+ __wbg_String_8f0eb39a4a4c2f66: function(arg0, arg1) {
185
+ const ret = String(arg1);
186
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
187
+ const len1 = WASM_VECTOR_LEN;
188
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
189
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
190
+ },
191
+ __wbg___wbindgen_throw_be289d5034ed271b: function(arg0, arg1) {
192
+ throw new Error(getStringFromWasm0(arg0, arg1));
193
+ },
194
+ __wbg_error_7534b8e9a36f1ab4: function(arg0, arg1) {
195
+ let deferred0_0;
196
+ let deferred0_1;
197
+ try {
198
+ deferred0_0 = arg0;
199
+ deferred0_1 = arg1;
200
+ console.error(getStringFromWasm0(arg0, arg1));
201
+ } finally {
202
+ wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
203
+ }
204
+ },
205
+ __wbg_new_361308b2356cecd0: function() {
206
+ const ret = new Object();
207
+ return ret;
208
+ },
209
+ __wbg_new_3eb36ae241fe6f44: function() {
210
+ const ret = new Array();
211
+ return ret;
212
+ },
213
+ __wbg_new_8a6f238a6ece86ea: function() {
214
+ const ret = new Error();
215
+ return ret;
216
+ },
217
+ __wbg_new_from_slice_a3d2629dc1826784: function(arg0, arg1) {
218
+ const ret = new Uint8Array(getArrayU8FromWasm0(arg0, arg1));
219
+ return ret;
220
+ },
221
+ __wbg_now_a3af9a2f4bbaa4d1: function() {
222
+ const ret = Date.now();
223
+ return ret;
224
+ },
225
+ __wbg_set_3f1d0b984ed272ed: function(arg0, arg1, arg2) {
226
+ arg0[arg1] = arg2;
227
+ },
228
+ __wbg_set_6cb8631f80447a67: function() { return handleError(function (arg0, arg1, arg2) {
229
+ const ret = Reflect.set(arg0, arg1, arg2);
230
+ return ret;
231
+ }, arguments); },
232
+ __wbg_set_f43e577aea94465b: function(arg0, arg1, arg2) {
233
+ arg0[arg1 >>> 0] = arg2;
234
+ },
235
+ __wbg_stack_0ed75d68575b0f3c: function(arg0, arg1) {
236
+ const ret = arg1.stack;
237
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
238
+ const len1 = WASM_VECTOR_LEN;
239
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
240
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
241
+ },
242
+ __wbindgen_cast_0000000000000001: function(arg0) {
243
+ // Cast intrinsic for `F64 -> Externref`.
244
+ const ret = arg0;
245
+ return ret;
246
+ },
247
+ __wbindgen_cast_0000000000000002: function(arg0, arg1) {
248
+ // Cast intrinsic for `Ref(String) -> Externref`.
249
+ const ret = getStringFromWasm0(arg0, arg1);
250
+ return ret;
251
+ },
252
+ __wbindgen_init_externref_table: function() {
253
+ const table = wasm.__wbindgen_externrefs;
254
+ const offset = table.grow(4);
255
+ table.set(0, undefined);
256
+ table.set(offset + 0, undefined);
257
+ table.set(offset + 1, null);
258
+ table.set(offset + 2, true);
259
+ table.set(offset + 3, false);
260
+ },
261
+ };
262
+ return {
263
+ __proto__: null,
264
+ "./forme_bg.js": import0,
265
+ };
266
+ }
267
+
268
+ function addToExternrefTable0(obj) {
269
+ const idx = wasm.__externref_table_alloc();
270
+ wasm.__wbindgen_externrefs.set(idx, obj);
271
+ return idx;
272
+ }
273
+
274
+ function getArrayU8FromWasm0(ptr, len) {
275
+ ptr = ptr >>> 0;
276
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
277
+ }
278
+
279
+ let cachedDataViewMemory0 = null;
280
+ function getDataViewMemory0() {
281
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
282
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
283
+ }
284
+ return cachedDataViewMemory0;
285
+ }
286
+
287
+ function getStringFromWasm0(ptr, len) {
288
+ ptr = ptr >>> 0;
289
+ return decodeText(ptr, len);
290
+ }
291
+
292
+ let cachedUint8ArrayMemory0 = null;
293
+ function getUint8ArrayMemory0() {
294
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
295
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
296
+ }
297
+ return cachedUint8ArrayMemory0;
298
+ }
299
+
300
+ function handleError(f, args) {
301
+ try {
302
+ return f.apply(this, args);
303
+ } catch (e) {
304
+ const idx = addToExternrefTable0(e);
305
+ wasm.__wbindgen_exn_store(idx);
306
+ }
307
+ }
308
+
309
+ function passArray8ToWasm0(arg, malloc) {
310
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
311
+ getUint8ArrayMemory0().set(arg, ptr / 1);
312
+ WASM_VECTOR_LEN = arg.length;
313
+ return ptr;
314
+ }
315
+
316
+ function passStringToWasm0(arg, malloc, realloc) {
317
+ if (realloc === undefined) {
318
+ const buf = cachedTextEncoder.encode(arg);
319
+ const ptr = malloc(buf.length, 1) >>> 0;
320
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
321
+ WASM_VECTOR_LEN = buf.length;
322
+ return ptr;
323
+ }
324
+
325
+ let len = arg.length;
326
+ let ptr = malloc(len, 1) >>> 0;
327
+
328
+ const mem = getUint8ArrayMemory0();
329
+
330
+ let offset = 0;
331
+
332
+ for (; offset < len; offset++) {
333
+ const code = arg.charCodeAt(offset);
334
+ if (code > 0x7F) break;
335
+ mem[ptr + offset] = code;
336
+ }
337
+ if (offset !== len) {
338
+ if (offset !== 0) {
339
+ arg = arg.slice(offset);
340
+ }
341
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
342
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
343
+ const ret = cachedTextEncoder.encodeInto(arg, view);
344
+
345
+ offset += ret.written;
346
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
347
+ }
348
+
349
+ WASM_VECTOR_LEN = offset;
350
+ return ptr;
351
+ }
352
+
353
+ function takeFromExternrefTable0(idx) {
354
+ const value = wasm.__wbindgen_externrefs.get(idx);
355
+ wasm.__externref_table_dealloc(idx);
356
+ return value;
357
+ }
358
+
359
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
360
+ cachedTextDecoder.decode();
361
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
362
+ let numBytesDecoded = 0;
363
+ function decodeText(ptr, len) {
364
+ numBytesDecoded += len;
365
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
366
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
367
+ cachedTextDecoder.decode();
368
+ numBytesDecoded = len;
369
+ }
370
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
371
+ }
372
+
373
+ const cachedTextEncoder = new TextEncoder();
374
+
375
+ if (!('encodeInto' in cachedTextEncoder)) {
376
+ cachedTextEncoder.encodeInto = function (arg, view) {
377
+ const buf = cachedTextEncoder.encode(arg);
378
+ view.set(buf);
379
+ return {
380
+ read: arg.length,
381
+ written: buf.length
382
+ };
383
+ };
384
+ }
385
+
386
+ let WASM_VECTOR_LEN = 0;
387
+
388
+ let wasmModule, wasm;
389
+ function __wbg_finalize_init(instance, module) {
390
+ wasm = instance.exports;
391
+ wasmModule = module;
392
+ cachedDataViewMemory0 = null;
393
+ cachedUint8ArrayMemory0 = null;
394
+ wasm.__wbindgen_start();
395
+ return wasm;
396
+ }
397
+
398
+ async function __wbg_load(module, imports) {
399
+ if (typeof Response === 'function' && module instanceof Response) {
400
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
401
+ try {
402
+ return await WebAssembly.instantiateStreaming(module, imports);
403
+ } catch (e) {
404
+ const validResponse = module.ok && expectedResponseType(module.type);
405
+
406
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
407
+ console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
408
+
409
+ } else { throw e; }
410
+ }
411
+ }
412
+
413
+ const bytes = await module.arrayBuffer();
414
+ return await WebAssembly.instantiate(bytes, imports);
415
+ } else {
416
+ const instance = await WebAssembly.instantiate(module, imports);
417
+
418
+ if (instance instanceof WebAssembly.Instance) {
419
+ return { instance, module };
420
+ } else {
421
+ return instance;
422
+ }
423
+ }
424
+
425
+ function expectedResponseType(type) {
426
+ switch (type) {
427
+ case 'basic': case 'cors': case 'default': return true;
428
+ }
429
+ return false;
430
+ }
431
+ }
432
+
433
+ function initSync(module) {
434
+ if (wasm !== undefined) return wasm;
435
+
436
+
437
+ if (module !== undefined) {
438
+ if (Object.getPrototypeOf(module) === Object.prototype) {
439
+ ({module} = module)
440
+ } else {
441
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
442
+ }
443
+ }
444
+
445
+ const imports = __wbg_get_imports();
446
+ if (!(module instanceof WebAssembly.Module)) {
447
+ module = new WebAssembly.Module(module);
448
+ }
449
+ const instance = new WebAssembly.Instance(module, imports);
450
+ return __wbg_finalize_init(instance, module);
451
+ }
452
+
453
+ async function __wbg_init(module_or_path) {
454
+ if (wasm !== undefined) return wasm;
455
+
456
+
457
+ if (module_or_path !== undefined) {
458
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
459
+ ({module_or_path} = module_or_path)
460
+ } else {
461
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
462
+ }
463
+ }
464
+
465
+ if (module_or_path === undefined) {
466
+ module_or_path = new URL('forme_bg.wasm', import.meta.url);
467
+ }
468
+ const imports = __wbg_get_imports();
469
+
470
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
471
+ module_or_path = fetch(module_or_path);
472
+ }
473
+
474
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
475
+
476
+ return __wbg_finalize_init(instance, module);
477
+ }
478
+
479
+ export { initSync, __wbg_init as default };
Binary file
@@ -0,0 +1,21 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ export const memory: WebAssembly.Memory;
4
+ export const certify_pdf: (a: number, b: number, c: number, d: number) => [number, number, number, number];
5
+ export const find_text_regions: (a: number, b: number, c: number, d: number) => [number, number, number, number];
6
+ export const merge_pdfs: (a: number, b: number) => [number, number, number, number];
7
+ export const redact_pdf: (a: number, b: number, c: number, d: number) => [number, number, number, number];
8
+ export const redact_text: (a: number, b: number, c: number, d: number) => [number, number, number, number];
9
+ export const render_pdf: (a: number, b: number) => [number, number, number, number];
10
+ export const render_pdf_with_layout: (a: number, b: number) => [number, number, number];
11
+ export const render_template_pdf: (a: number, b: number, c: number, d: number) => [number, number, number, number];
12
+ export const render_template_pdf_with_layout: (a: number, b: number, c: number, d: number) => [number, number, number];
13
+ export const init_panic_hook: () => void;
14
+ export const __wbindgen_malloc: (a: number, b: number) => number;
15
+ export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
16
+ export const __wbindgen_free: (a: number, b: number, c: number) => void;
17
+ export const __wbindgen_exn_store: (a: number) => void;
18
+ export const __externref_table_alloc: () => number;
19
+ export const __wbindgen_externrefs: WebAssembly.Table;
20
+ export const __externref_table_dealloc: (a: number) => void;
21
+ export const __wbindgen_start: () => void;
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "forme-pdf",
3
+ "type": "module",
4
+ "description": "A page-native PDF rendering engine. Layout INTO pages, not onto an infinite canvas.",
5
+ "version": "0.10.2",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/formepdf/forme"
10
+ },
11
+ "files": [
12
+ "forme_bg.wasm",
13
+ "forme.js",
14
+ "forme.d.ts"
15
+ ],
16
+ "main": "forme.js",
17
+ "homepage": "https://formepdf.com",
18
+ "types": "forme.d.ts",
19
+ "sideEffects": [
20
+ "./snippets/*"
21
+ ],
22
+ "keywords": [
23
+ "pdf",
24
+ "wasm",
25
+ "layout",
26
+ "document",
27
+ "report"
28
+ ]
29
+ }