@laminapdf/wasm 0.2.0-alpha.6 → 0.3.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.
@@ -0,0 +1,259 @@
1
+ /* @ts-self-types="./lamina_pdf_tiff.d.ts" */
2
+
3
+ /**
4
+ * A TIFF file being written, one page per [`TiffFile::add_page`].
5
+ */
6
+ export class TiffFile {
7
+ __destroy_into_raw() {
8
+ const ptr = this.__wbg_ptr;
9
+ this.__wbg_ptr = 0;
10
+ TiffFileFinalization.unregister(this);
11
+ return ptr;
12
+ }
13
+ free() {
14
+ const ptr = this.__destroy_into_raw();
15
+ wasm.__wbg_tifffile_free(ptr, 0);
16
+ }
17
+ /**
18
+ * Adds a page of `width` × `height` straight RGBA pixels, row by row, drawn at `dpi`.
19
+ *
20
+ * # Errors
21
+ * `invalid-argument` when `rgba` isn't `width × height × 4` bytes, `dpi` isn't
22
+ * positive, or the file is finished; `export-failed` if the encoder fails.
23
+ * @param {number} width
24
+ * @param {number} height
25
+ * @param {Uint8Array} rgba
26
+ * @param {number} dpi
27
+ */
28
+ addPage(width, height, rgba, dpi) {
29
+ const ptr0 = passArray8ToWasm0(rgba, wasm.__wbindgen_malloc);
30
+ const len0 = WASM_VECTOR_LEN;
31
+ const ret = wasm.tifffile_addPage(this.__wbg_ptr, width, height, ptr0, len0, dpi);
32
+ if (ret[1]) {
33
+ throw takeFromExternrefTable0(ret[0]);
34
+ }
35
+ }
36
+ /**
37
+ * The file's bytes. The file is finished: it takes no more pages.
38
+ *
39
+ * # Errors
40
+ * `invalid-argument` when it was already finished.
41
+ * @returns {Uint8Array}
42
+ */
43
+ finish() {
44
+ const ret = wasm.tifffile_finish(this.__wbg_ptr);
45
+ if (ret[3]) {
46
+ throw takeFromExternrefTable0(ret[2]);
47
+ }
48
+ var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
49
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
50
+ return v1;
51
+ }
52
+ /**
53
+ * An empty file.
54
+ *
55
+ * # Errors
56
+ * `export-failed` if the encoder can't write the file's header.
57
+ */
58
+ constructor() {
59
+ const ret = wasm.tifffile_new();
60
+ if (ret[2]) {
61
+ throw takeFromExternrefTable0(ret[1]);
62
+ }
63
+ this.__wbg_ptr = ret[0];
64
+ TiffFileFinalization.register(this, this.__wbg_ptr, this);
65
+ return this;
66
+ }
67
+ }
68
+ if (Symbol.dispose) TiffFile.prototype[Symbol.dispose] = TiffFile.prototype.free;
69
+ function __wbg_get_imports() {
70
+ const import0 = {
71
+ __proto__: null,
72
+ __wbg___wbindgen_throw_41e9ee4f547fc59a: function(arg0, arg1) {
73
+ throw new Error(getStringFromWasm0(arg0, arg1));
74
+ },
75
+ __wbg_new_343a093a3c2ffb4e: function(arg0, arg1) {
76
+ const ret = new Error(getStringFromWasm0(arg0, arg1));
77
+ return ret;
78
+ },
79
+ __wbg_parse_0fc53dead14b3b42: function() { return handleError(function (arg0, arg1) {
80
+ const ret = JSON.parse(getStringFromWasm0(arg0, arg1));
81
+ return ret;
82
+ }, arguments); },
83
+ __wbindgen_init_externref_table: function() {
84
+ const table = wasm.__wbindgen_externrefs;
85
+ const offset = table.grow(4);
86
+ table.set(0, undefined);
87
+ table.set(offset + 0, undefined);
88
+ table.set(offset + 1, null);
89
+ table.set(offset + 2, true);
90
+ table.set(offset + 3, false);
91
+ },
92
+ };
93
+ return {
94
+ __proto__: null,
95
+ "./lamina_pdf_tiff_bg.js": import0,
96
+ };
97
+ }
98
+
99
+ const TiffFileFinalization = (typeof FinalizationRegistry === 'undefined')
100
+ ? { register: () => {}, unregister: () => {} }
101
+ : new FinalizationRegistry(ptr => wasm.__wbg_tifffile_free(ptr, 1));
102
+
103
+ function addToExternrefTable0(obj) {
104
+ const idx = wasm.__externref_table_alloc();
105
+ wasm.__wbindgen_externrefs.set(idx, obj);
106
+ return idx;
107
+ }
108
+
109
+ function getArrayU8FromWasm0(ptr, len) {
110
+ ptr = ptr >>> 0;
111
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
112
+ }
113
+
114
+ function getStringFromWasm0(ptr, len) {
115
+ return decodeText(ptr >>> 0, 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 passArray8ToWasm0(arg, malloc) {
136
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
137
+ getUint8ArrayMemory0().set(arg, ptr / 1);
138
+ WASM_VECTOR_LEN = arg.length;
139
+ return ptr;
140
+ }
141
+
142
+ function takeFromExternrefTable0(idx) {
143
+ const value = wasm.__wbindgen_externrefs.get(idx);
144
+ wasm.__externref_table_dealloc(idx);
145
+ return value;
146
+ }
147
+
148
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
149
+ cachedTextDecoder.decode();
150
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
151
+ let numBytesDecoded = 0;
152
+ function decodeText(ptr, len) {
153
+ numBytesDecoded += len;
154
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
155
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
156
+ cachedTextDecoder.decode();
157
+ numBytesDecoded = len;
158
+ }
159
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
160
+ }
161
+
162
+ let WASM_VECTOR_LEN = 0;
163
+
164
+ let wasmModule, wasmInstance, wasm;
165
+ function __wbg_finalize_init(instance, module) {
166
+ wasmInstance = instance;
167
+ wasm = instance.exports;
168
+ wasmModule = module;
169
+ cachedUint8ArrayMemory0 = null;
170
+ wasm.__wbindgen_start();
171
+ return wasm;
172
+ }
173
+
174
+ async function __wbg_load(module, imports) {
175
+ if (typeof Response === 'function' && module instanceof Response) {
176
+ if (!module.ok) {
177
+ throw new Error(`failed to fetch Wasm: ${module.status} ${module.statusText} fetching '${module.url}'`);
178
+ }
179
+
180
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
181
+ try {
182
+ return await WebAssembly.instantiateStreaming(module, imports);
183
+ } catch (e) {
184
+ const validResponse = expectedResponseType(module.type);
185
+
186
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
187
+ 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);
188
+
189
+ } else { throw e; }
190
+ }
191
+ }
192
+
193
+ const bytes = await module.arrayBuffer();
194
+ return await WebAssembly.instantiate(bytes, imports);
195
+ } else {
196
+ const instance = await WebAssembly.instantiate(module, imports);
197
+
198
+ if (instance instanceof WebAssembly.Instance) {
199
+ return { instance, module };
200
+ } else {
201
+ return instance;
202
+ }
203
+ }
204
+
205
+ function expectedResponseType(type) {
206
+ switch (type) {
207
+ case 'basic': case 'cors': case 'default': return true;
208
+ }
209
+ return false;
210
+ }
211
+ }
212
+
213
+ function initSync(module) {
214
+ if (wasm !== undefined) return wasm;
215
+
216
+
217
+ if (module !== undefined) {
218
+ if (Object.getPrototypeOf(module) === Object.prototype) {
219
+ ({module} = module)
220
+ } else {
221
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
222
+ }
223
+ }
224
+
225
+ const imports = __wbg_get_imports();
226
+ if (!(module instanceof WebAssembly.Module)) {
227
+ module = new WebAssembly.Module(module);
228
+ }
229
+ const instance = new WebAssembly.Instance(module, imports);
230
+ return __wbg_finalize_init(instance, module);
231
+ }
232
+
233
+ async function __wbg_init(module_or_path) {
234
+ if (wasm !== undefined) return wasm;
235
+
236
+
237
+ if (module_or_path !== undefined) {
238
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
239
+ ({module_or_path} = module_or_path)
240
+ } else {
241
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
242
+ }
243
+ }
244
+
245
+ if (module_or_path === undefined) {
246
+ module_or_path = new URL('lamina_pdf_tiff.wasm', import.meta.url);
247
+ }
248
+ const imports = __wbg_get_imports();
249
+
250
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
251
+ module_or_path = fetch(module_or_path);
252
+ }
253
+
254
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
255
+
256
+ return __wbg_finalize_init(instance, module);
257
+ }
258
+
259
+ export { initSync, __wbg_init as default };
Binary file
package/package.json CHANGED
@@ -1,9 +1,12 @@
1
1
  {
2
2
  "name": "@laminapdf/wasm",
3
- "version": "0.2.0-alpha.6",
4
- "description": "Lamina PDF's WebAssembly modules and their wasm-bindgen glue: lamina_pdf_base (open, read, edit, save, vector and image pages), lamina_pdf_text (all of base plus fonts and text) and lamina_pdf_extract (all of base plus text extraction); and lamina_pdf_render_hayro, laminapdf-render's hayro adapter, which @laminapdf/render-hayro wraps. Generated into dist/ by `cargo xtask wasm`; @laminapdf/sdk is the API to use.",
3
+ "version": "0.3.0",
4
+ "description": "The WebAssembly build of Lamina PDF's Rust core, which @laminapdf/sdk runs on: create, read, edit and save PDFs and extract their text. Use @laminapdf/sdk; this package holds its compiled modules.",
5
5
  "license": "MIT OR Apache-2.0",
6
6
  "homepage": "https://laminapdf.com",
7
+ "bugs": {
8
+ "url": "https://github.com/laudebugs/laminapdf/issues"
9
+ },
7
10
  "repository": {
8
11
  "type": "git",
9
12
  "url": "git+https://github.com/laudebugs/laminapdf.git",
@@ -12,7 +15,10 @@
12
15
  "keywords": [
13
16
  "pdf",
14
17
  "wasm",
15
- "webassembly"
18
+ "webassembly",
19
+ "pdf-generation",
20
+ "pdf-editing",
21
+ "text-extraction"
16
22
  ],
17
23
  "type": "module",
18
24
  "sideEffects": false,
@@ -39,10 +45,15 @@
39
45
  "types": "./dist/lamina_pdf_render_hayro.d.ts",
40
46
  "default": "./dist/lamina_pdf_render_hayro.js"
41
47
  },
48
+ "./tiff": {
49
+ "types": "./dist/lamina_pdf_tiff.d.ts",
50
+ "default": "./dist/lamina_pdf_tiff.js"
51
+ },
42
52
  "./lamina_pdf_base.wasm": "./dist/lamina_pdf_base.wasm",
43
53
  "./lamina_pdf_text.wasm": "./dist/lamina_pdf_text.wasm",
44
54
  "./lamina_pdf_extract.wasm": "./dist/lamina_pdf_extract.wasm",
45
55
  "./lamina_pdf_render_hayro.wasm": "./dist/lamina_pdf_render_hayro.wasm",
56
+ "./lamina_pdf_tiff.wasm": "./dist/lamina_pdf_tiff.wasm",
46
57
  "./package.json": "./package.json"
47
58
  },
48
59
  "devDependencies": {