@formepdf/core 0.1.2 → 0.1.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@formepdf/core",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "WASM-powered PDF rendering engine for Forme",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -12,7 +12,7 @@
12
12
  }
13
13
  },
14
14
  "scripts": {
15
- "build:wasm": "./build.sh",
15
+ "build:wasm": "./build.sh && rm -f pkg/.gitignore",
16
16
  "build:ts": "tsc",
17
17
  "build": "npm run build:wasm && npm run build:ts",
18
18
  "test": "vitest run"
package/pkg/forme.d.ts ADDED
@@ -0,0 +1,44 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ export function render_pdf(json: string): Uint8Array;
5
+
6
+ export function render_pdf_with_layout(json: string): any;
7
+
8
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
9
+
10
+ export interface InitOutput {
11
+ readonly memory: WebAssembly.Memory;
12
+ readonly render_pdf: (a: number, b: number) => [number, number, number, number];
13
+ readonly render_pdf_with_layout: (a: number, b: number) => [number, number, number];
14
+ readonly __wbindgen_malloc: (a: number, b: number) => number;
15
+ readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
16
+ readonly __wbindgen_exn_store: (a: number) => void;
17
+ readonly __externref_table_alloc: () => number;
18
+ readonly __wbindgen_externrefs: WebAssembly.Table;
19
+ readonly __externref_table_dealloc: (a: number) => void;
20
+ readonly __wbindgen_free: (a: number, b: number, c: number) => void;
21
+ readonly __wbindgen_start: () => void;
22
+ }
23
+
24
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
25
+
26
+ /**
27
+ * Instantiates the given `module`, which can either be bytes or
28
+ * a precompiled `WebAssembly.Module`.
29
+ *
30
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
31
+ *
32
+ * @returns {InitOutput}
33
+ */
34
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
35
+
36
+ /**
37
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
38
+ * for everything else, calls `WebAssembly.instantiate` directly.
39
+ *
40
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
41
+ *
42
+ * @returns {Promise<InitOutput>}
43
+ */
44
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
package/pkg/forme.js ADDED
@@ -0,0 +1,298 @@
1
+ /* @ts-self-types="./forme.d.ts" */
2
+
3
+ /**
4
+ * @param {string} json
5
+ * @returns {Uint8Array}
6
+ */
7
+ export function render_pdf(json) {
8
+ const ptr0 = passStringToWasm0(json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
9
+ const len0 = WASM_VECTOR_LEN;
10
+ const ret = wasm.render_pdf(ptr0, len0);
11
+ if (ret[3]) {
12
+ throw takeFromExternrefTable0(ret[2]);
13
+ }
14
+ var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
15
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
16
+ return v2;
17
+ }
18
+
19
+ /**
20
+ * @param {string} json
21
+ * @returns {any}
22
+ */
23
+ export function render_pdf_with_layout(json) {
24
+ const ptr0 = passStringToWasm0(json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
25
+ const len0 = WASM_VECTOR_LEN;
26
+ const ret = wasm.render_pdf_with_layout(ptr0, len0);
27
+ if (ret[2]) {
28
+ throw takeFromExternrefTable0(ret[1]);
29
+ }
30
+ return takeFromExternrefTable0(ret[0]);
31
+ }
32
+
33
+ function __wbg_get_imports() {
34
+ const import0 = {
35
+ __proto__: null,
36
+ __wbg_String_8f0eb39a4a4c2f66: function(arg0, arg1) {
37
+ const ret = String(arg1);
38
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
39
+ const len1 = WASM_VECTOR_LEN;
40
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
41
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
42
+ },
43
+ __wbg___wbindgen_throw_be289d5034ed271b: function(arg0, arg1) {
44
+ throw new Error(getStringFromWasm0(arg0, arg1));
45
+ },
46
+ __wbg_new_361308b2356cecd0: function() {
47
+ const ret = new Object();
48
+ return ret;
49
+ },
50
+ __wbg_new_3eb36ae241fe6f44: function() {
51
+ const ret = new Array();
52
+ return ret;
53
+ },
54
+ __wbg_new_from_slice_a3d2629dc1826784: function(arg0, arg1) {
55
+ const ret = new Uint8Array(getArrayU8FromWasm0(arg0, arg1));
56
+ return ret;
57
+ },
58
+ __wbg_set_3f1d0b984ed272ed: function(arg0, arg1, arg2) {
59
+ arg0[arg1] = arg2;
60
+ },
61
+ __wbg_set_6cb8631f80447a67: function() { return handleError(function (arg0, arg1, arg2) {
62
+ const ret = Reflect.set(arg0, arg1, arg2);
63
+ return ret;
64
+ }, arguments); },
65
+ __wbg_set_f43e577aea94465b: function(arg0, arg1, arg2) {
66
+ arg0[arg1 >>> 0] = arg2;
67
+ },
68
+ __wbindgen_cast_0000000000000001: function(arg0) {
69
+ // Cast intrinsic for `F64 -> Externref`.
70
+ const ret = arg0;
71
+ return ret;
72
+ },
73
+ __wbindgen_cast_0000000000000002: function(arg0, arg1) {
74
+ // Cast intrinsic for `Ref(String) -> Externref`.
75
+ const ret = getStringFromWasm0(arg0, arg1);
76
+ return ret;
77
+ },
78
+ __wbindgen_init_externref_table: function() {
79
+ const table = wasm.__wbindgen_externrefs;
80
+ const offset = table.grow(4);
81
+ table.set(0, undefined);
82
+ table.set(offset + 0, undefined);
83
+ table.set(offset + 1, null);
84
+ table.set(offset + 2, true);
85
+ table.set(offset + 3, false);
86
+ },
87
+ };
88
+ return {
89
+ __proto__: null,
90
+ "./forme_bg.js": import0,
91
+ };
92
+ }
93
+
94
+ function addToExternrefTable0(obj) {
95
+ const idx = wasm.__externref_table_alloc();
96
+ wasm.__wbindgen_externrefs.set(idx, obj);
97
+ return idx;
98
+ }
99
+
100
+ function getArrayU8FromWasm0(ptr, len) {
101
+ ptr = ptr >>> 0;
102
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
103
+ }
104
+
105
+ let cachedDataViewMemory0 = null;
106
+ function getDataViewMemory0() {
107
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
108
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
109
+ }
110
+ return cachedDataViewMemory0;
111
+ }
112
+
113
+ function getStringFromWasm0(ptr, len) {
114
+ ptr = ptr >>> 0;
115
+ return decodeText(ptr, len);
116
+ }
117
+
118
+ let cachedUint8ArrayMemory0 = null;
119
+ function getUint8ArrayMemory0() {
120
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
121
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
122
+ }
123
+ return cachedUint8ArrayMemory0;
124
+ }
125
+
126
+ function handleError(f, args) {
127
+ try {
128
+ return f.apply(this, args);
129
+ } catch (e) {
130
+ const idx = addToExternrefTable0(e);
131
+ wasm.__wbindgen_exn_store(idx);
132
+ }
133
+ }
134
+
135
+ function passStringToWasm0(arg, malloc, realloc) {
136
+ if (realloc === undefined) {
137
+ const buf = cachedTextEncoder.encode(arg);
138
+ const ptr = malloc(buf.length, 1) >>> 0;
139
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
140
+ WASM_VECTOR_LEN = buf.length;
141
+ return ptr;
142
+ }
143
+
144
+ let len = arg.length;
145
+ let ptr = malloc(len, 1) >>> 0;
146
+
147
+ const mem = getUint8ArrayMemory0();
148
+
149
+ let offset = 0;
150
+
151
+ for (; offset < len; offset++) {
152
+ const code = arg.charCodeAt(offset);
153
+ if (code > 0x7F) break;
154
+ mem[ptr + offset] = code;
155
+ }
156
+ if (offset !== len) {
157
+ if (offset !== 0) {
158
+ arg = arg.slice(offset);
159
+ }
160
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
161
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
162
+ const ret = cachedTextEncoder.encodeInto(arg, view);
163
+
164
+ offset += ret.written;
165
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
166
+ }
167
+
168
+ WASM_VECTOR_LEN = offset;
169
+ return ptr;
170
+ }
171
+
172
+ function takeFromExternrefTable0(idx) {
173
+ const value = wasm.__wbindgen_externrefs.get(idx);
174
+ wasm.__externref_table_dealloc(idx);
175
+ return value;
176
+ }
177
+
178
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
179
+ cachedTextDecoder.decode();
180
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
181
+ let numBytesDecoded = 0;
182
+ function decodeText(ptr, len) {
183
+ numBytesDecoded += len;
184
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
185
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
186
+ cachedTextDecoder.decode();
187
+ numBytesDecoded = len;
188
+ }
189
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
190
+ }
191
+
192
+ const cachedTextEncoder = new TextEncoder();
193
+
194
+ if (!('encodeInto' in cachedTextEncoder)) {
195
+ cachedTextEncoder.encodeInto = function (arg, view) {
196
+ const buf = cachedTextEncoder.encode(arg);
197
+ view.set(buf);
198
+ return {
199
+ read: arg.length,
200
+ written: buf.length
201
+ };
202
+ };
203
+ }
204
+
205
+ let WASM_VECTOR_LEN = 0;
206
+
207
+ let wasmModule, wasm;
208
+ function __wbg_finalize_init(instance, module) {
209
+ wasm = instance.exports;
210
+ wasmModule = module;
211
+ cachedDataViewMemory0 = null;
212
+ cachedUint8ArrayMemory0 = null;
213
+ wasm.__wbindgen_start();
214
+ return wasm;
215
+ }
216
+
217
+ async function __wbg_load(module, imports) {
218
+ if (typeof Response === 'function' && module instanceof Response) {
219
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
220
+ try {
221
+ return await WebAssembly.instantiateStreaming(module, imports);
222
+ } catch (e) {
223
+ const validResponse = module.ok && expectedResponseType(module.type);
224
+
225
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
226
+ 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);
227
+
228
+ } else { throw e; }
229
+ }
230
+ }
231
+
232
+ const bytes = await module.arrayBuffer();
233
+ return await WebAssembly.instantiate(bytes, imports);
234
+ } else {
235
+ const instance = await WebAssembly.instantiate(module, imports);
236
+
237
+ if (instance instanceof WebAssembly.Instance) {
238
+ return { instance, module };
239
+ } else {
240
+ return instance;
241
+ }
242
+ }
243
+
244
+ function expectedResponseType(type) {
245
+ switch (type) {
246
+ case 'basic': case 'cors': case 'default': return true;
247
+ }
248
+ return false;
249
+ }
250
+ }
251
+
252
+ function initSync(module) {
253
+ if (wasm !== undefined) return wasm;
254
+
255
+
256
+ if (module !== undefined) {
257
+ if (Object.getPrototypeOf(module) === Object.prototype) {
258
+ ({module} = module)
259
+ } else {
260
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
261
+ }
262
+ }
263
+
264
+ const imports = __wbg_get_imports();
265
+ if (!(module instanceof WebAssembly.Module)) {
266
+ module = new WebAssembly.Module(module);
267
+ }
268
+ const instance = new WebAssembly.Instance(module, imports);
269
+ return __wbg_finalize_init(instance, module);
270
+ }
271
+
272
+ async function __wbg_init(module_or_path) {
273
+ if (wasm !== undefined) return wasm;
274
+
275
+
276
+ if (module_or_path !== undefined) {
277
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
278
+ ({module_or_path} = module_or_path)
279
+ } else {
280
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
281
+ }
282
+ }
283
+
284
+ if (module_or_path === undefined) {
285
+ module_or_path = new URL('forme_bg.wasm', import.meta.url);
286
+ }
287
+ const imports = __wbg_get_imports();
288
+
289
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
290
+ module_or_path = fetch(module_or_path);
291
+ }
292
+
293
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
294
+
295
+ return __wbg_finalize_init(instance, module);
296
+ }
297
+
298
+ export { initSync, __wbg_init as default };
Binary file
@@ -0,0 +1,13 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ export const memory: WebAssembly.Memory;
4
+ export const render_pdf: (a: number, b: number) => [number, number, number, number];
5
+ export const render_pdf_with_layout: (a: number, b: number) => [number, number, number];
6
+ export const __wbindgen_malloc: (a: number, b: number) => number;
7
+ export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
8
+ export const __wbindgen_exn_store: (a: number) => void;
9
+ export const __externref_table_alloc: () => number;
10
+ export const __wbindgen_externrefs: WebAssembly.Table;
11
+ export const __externref_table_dealloc: (a: number) => void;
12
+ export const __wbindgen_free: (a: number, b: number, c: number) => void;
13
+ export const __wbindgen_start: () => void;
@@ -0,0 +1,16 @@
1
+ {
2
+ "name": "forme",
3
+ "type": "module",
4
+ "description": "A page-native PDF rendering engine. Layout INTO pages, not onto an infinite canvas.",
5
+ "version": "0.1.0",
6
+ "files": [
7
+ "forme_bg.wasm",
8
+ "forme.js",
9
+ "forme.d.ts"
10
+ ],
11
+ "main": "forme.js",
12
+ "types": "forme.d.ts",
13
+ "sideEffects": [
14
+ "./snippets/*"
15
+ ]
16
+ }