@metools/web-image-converter 1.0.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 ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2025 Mathew E. Thompson
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/dist/index.js ADDED
@@ -0,0 +1,650 @@
1
+ // src/image_converter_binary/image_converter_back_end.js
2
+ var wasm;
3
+ var cachedTextDecoder = typeof TextDecoder !== "undefined" ? new TextDecoder("utf-8", { ignoreBOM: true, fatal: true }) : { decode: () => {
4
+ throw Error("TextDecoder not available");
5
+ } };
6
+ if (typeof TextDecoder !== "undefined") {
7
+ cachedTextDecoder.decode();
8
+ }
9
+ var cachedUint8ArrayMemory0 = null;
10
+ function getUint8ArrayMemory0() {
11
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
12
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
13
+ }
14
+ return cachedUint8ArrayMemory0;
15
+ }
16
+ function getStringFromWasm0(ptr, len) {
17
+ ptr = ptr >>> 0;
18
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
19
+ }
20
+ function addToExternrefTable0(obj) {
21
+ const idx = wasm.__externref_table_alloc();
22
+ wasm.__wbindgen_export_2.set(idx, obj);
23
+ return idx;
24
+ }
25
+ function handleError(f, args) {
26
+ try {
27
+ return f.apply(this, args);
28
+ } catch (e) {
29
+ const idx = addToExternrefTable0(e);
30
+ wasm.__wbindgen_exn_store(idx);
31
+ }
32
+ }
33
+ function debugString(val) {
34
+ const type = typeof val;
35
+ if (type == "number" || type == "boolean" || val == null) {
36
+ return `${val}`;
37
+ }
38
+ if (type == "string") {
39
+ return `"${val}"`;
40
+ }
41
+ if (type == "symbol") {
42
+ const description = val.description;
43
+ if (description == null) {
44
+ return "Symbol";
45
+ } else {
46
+ return `Symbol(${description})`;
47
+ }
48
+ }
49
+ if (type == "function") {
50
+ const name = val.name;
51
+ if (typeof name == "string" && name.length > 0) {
52
+ return `Function(${name})`;
53
+ } else {
54
+ return "Function";
55
+ }
56
+ }
57
+ if (Array.isArray(val)) {
58
+ const length = val.length;
59
+ let debug = "[";
60
+ if (length > 0) {
61
+ debug += debugString(val[0]);
62
+ }
63
+ for (let i = 1; i < length; i++) {
64
+ debug += ", " + debugString(val[i]);
65
+ }
66
+ debug += "]";
67
+ return debug;
68
+ }
69
+ const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
70
+ let className;
71
+ if (builtInMatches && builtInMatches.length > 1) {
72
+ className = builtInMatches[1];
73
+ } else {
74
+ return toString.call(val);
75
+ }
76
+ if (className == "Object") {
77
+ try {
78
+ return "Object(" + JSON.stringify(val) + ")";
79
+ } catch (_) {
80
+ return "Object";
81
+ }
82
+ }
83
+ if (val instanceof Error) {
84
+ return `${val.name}: ${val.message}
85
+ ${val.stack}`;
86
+ }
87
+ return className;
88
+ }
89
+ var WASM_VECTOR_LEN = 0;
90
+ var cachedTextEncoder = typeof TextEncoder !== "undefined" ? new TextEncoder("utf-8") : { encode: () => {
91
+ throw Error("TextEncoder not available");
92
+ } };
93
+ var encodeString = typeof cachedTextEncoder.encodeInto === "function" ? function(arg, view) {
94
+ return cachedTextEncoder.encodeInto(arg, view);
95
+ } : function(arg, view) {
96
+ const buf = cachedTextEncoder.encode(arg);
97
+ view.set(buf);
98
+ return {
99
+ read: arg.length,
100
+ written: buf.length
101
+ };
102
+ };
103
+ function passStringToWasm0(arg, malloc, realloc) {
104
+ if (realloc === void 0) {
105
+ const buf = cachedTextEncoder.encode(arg);
106
+ const ptr2 = malloc(buf.length, 1) >>> 0;
107
+ getUint8ArrayMemory0().subarray(ptr2, ptr2 + buf.length).set(buf);
108
+ WASM_VECTOR_LEN = buf.length;
109
+ return ptr2;
110
+ }
111
+ let len = arg.length;
112
+ let ptr = malloc(len, 1) >>> 0;
113
+ const mem = getUint8ArrayMemory0();
114
+ let offset = 0;
115
+ for (; offset < len; offset++) {
116
+ const code = arg.charCodeAt(offset);
117
+ if (code > 127) break;
118
+ mem[ptr + offset] = code;
119
+ }
120
+ if (offset !== len) {
121
+ if (offset !== 0) {
122
+ arg = arg.slice(offset);
123
+ }
124
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
125
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
126
+ const ret = encodeString(arg, view);
127
+ offset += ret.written;
128
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
129
+ }
130
+ WASM_VECTOR_LEN = offset;
131
+ return ptr;
132
+ }
133
+ var cachedDataViewMemory0 = null;
134
+ function getDataViewMemory0() {
135
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || cachedDataViewMemory0.buffer.detached === void 0 && cachedDataViewMemory0.buffer !== wasm.memory.buffer) {
136
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
137
+ }
138
+ return cachedDataViewMemory0;
139
+ }
140
+ function isLikeNone(x) {
141
+ return x === void 0 || x === null;
142
+ }
143
+ function passArray8ToWasm0(arg, malloc) {
144
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
145
+ getUint8ArrayMemory0().set(arg, ptr / 1);
146
+ WASM_VECTOR_LEN = arg.length;
147
+ return ptr;
148
+ }
149
+ function process_image(bytes, input) {
150
+ const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
151
+ const len0 = WASM_VECTOR_LEN;
152
+ const ret = wasm.process_image(ptr0, len0, input);
153
+ return ret;
154
+ }
155
+ var ChromaSamplePosition = Object.freeze({
156
+ /**
157
+ * The source video transfer function must be signaled
158
+ * outside the AV1 bitstream.
159
+ */
160
+ Unknown: 0,
161
+ "0": "Unknown",
162
+ /**
163
+ * Horizontally co-located with (0, 0) luma sample, vertically positioned
164
+ * in the middle between two luma samples.
165
+ */
166
+ Vertical: 1,
167
+ "1": "Vertical",
168
+ /**
169
+ * Co-located with (0, 0) luma sample.
170
+ */
171
+ Colocated: 2,
172
+ "2": "Colocated"
173
+ });
174
+ var ChromaSampling = Object.freeze({
175
+ /**
176
+ * Both vertically and horizontally subsampled.
177
+ */
178
+ Cs420: 0,
179
+ "0": "Cs420",
180
+ /**
181
+ * Horizontally subsampled.
182
+ */
183
+ Cs422: 1,
184
+ "1": "Cs422",
185
+ /**
186
+ * Not subsampled.
187
+ */
188
+ Cs444: 2,
189
+ "2": "Cs444",
190
+ /**
191
+ * Monochrome.
192
+ */
193
+ Cs400: 3,
194
+ "3": "Cs400"
195
+ });
196
+ var PixelRange = Object.freeze({
197
+ /**
198
+ * Studio swing representation
199
+ */
200
+ Limited: 0,
201
+ "0": "Limited",
202
+ /**
203
+ * Full swing representation
204
+ */
205
+ Full: 1,
206
+ "1": "Full"
207
+ });
208
+ var Tune = Object.freeze({
209
+ Psnr: 0,
210
+ "0": "Psnr",
211
+ Psychovisual: 1,
212
+ "1": "Psychovisual"
213
+ });
214
+ async function __wbg_load(module, imports) {
215
+ if (typeof Response === "function" && module instanceof Response) {
216
+ if (typeof WebAssembly.instantiateStreaming === "function") {
217
+ try {
218
+ return await WebAssembly.instantiateStreaming(module, imports);
219
+ } catch (e) {
220
+ if (module.headers.get("Content-Type") != "application/wasm") {
221
+ 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);
222
+ } else {
223
+ throw e;
224
+ }
225
+ }
226
+ }
227
+ const bytes = await module.arrayBuffer();
228
+ return await WebAssembly.instantiate(bytes, imports);
229
+ } else {
230
+ const instance = await WebAssembly.instantiate(module, imports);
231
+ if (instance instanceof WebAssembly.Instance) {
232
+ return { instance, module };
233
+ } else {
234
+ return instance;
235
+ }
236
+ }
237
+ }
238
+ function __wbg_get_imports() {
239
+ const imports = {};
240
+ imports.wbg = {};
241
+ imports.wbg.__wbg_buffer_609cc3eee51ed158 = function(arg0) {
242
+ const ret = arg0.buffer;
243
+ return ret;
244
+ };
245
+ imports.wbg.__wbg_error_7561f6100a063e85 = function(arg0, arg1) {
246
+ console.error(getStringFromWasm0(arg0, arg1));
247
+ };
248
+ imports.wbg.__wbg_get_67b2ba62fc30de12 = function() {
249
+ return handleError(function(arg0, arg1) {
250
+ const ret = Reflect.get(arg0, arg1);
251
+ return ret;
252
+ }, arguments);
253
+ };
254
+ imports.wbg.__wbg_getwithrefkey_1dc361bd10053bfe = function(arg0, arg1) {
255
+ const ret = arg0[arg1];
256
+ return ret;
257
+ };
258
+ imports.wbg.__wbg_instanceof_ArrayBuffer_e14585432e3737fc = function(arg0) {
259
+ let result;
260
+ try {
261
+ result = arg0 instanceof ArrayBuffer;
262
+ } catch (_) {
263
+ result = false;
264
+ }
265
+ const ret = result;
266
+ return ret;
267
+ };
268
+ imports.wbg.__wbg_instanceof_Uint8Array_17156bcf118086a9 = function(arg0) {
269
+ let result;
270
+ try {
271
+ result = arg0 instanceof Uint8Array;
272
+ } catch (_) {
273
+ result = false;
274
+ }
275
+ const ret = result;
276
+ return ret;
277
+ };
278
+ imports.wbg.__wbg_isSafeInteger_343e2beeeece1bb0 = function(arg0) {
279
+ const ret = Number.isSafeInteger(arg0);
280
+ return ret;
281
+ };
282
+ imports.wbg.__wbg_length_a446193dc22c12f8 = function(arg0) {
283
+ const ret = arg0.length;
284
+ return ret;
285
+ };
286
+ imports.wbg.__wbg_new_a12002a7f91c75be = function(arg0) {
287
+ const ret = new Uint8Array(arg0);
288
+ return ret;
289
+ };
290
+ imports.wbg.__wbg_newwithbyteoffsetandlength_d97e637ebe145a9a = function(arg0, arg1, arg2) {
291
+ const ret = new Uint8Array(arg0, arg1 >>> 0, arg2 >>> 0);
292
+ return ret;
293
+ };
294
+ imports.wbg.__wbg_set_65595bdd868b3009 = function(arg0, arg1, arg2) {
295
+ arg0.set(arg1, arg2 >>> 0);
296
+ };
297
+ imports.wbg.__wbindgen_as_number = function(arg0) {
298
+ const ret = +arg0;
299
+ return ret;
300
+ };
301
+ imports.wbg.__wbindgen_boolean_get = function(arg0) {
302
+ const v = arg0;
303
+ const ret = typeof v === "boolean" ? v ? 1 : 0 : 2;
304
+ return ret;
305
+ };
306
+ imports.wbg.__wbindgen_debug_string = function(arg0, arg1) {
307
+ const ret = debugString(arg1);
308
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
309
+ const len1 = WASM_VECTOR_LEN;
310
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
311
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
312
+ };
313
+ imports.wbg.__wbindgen_error_new = function(arg0, arg1) {
314
+ const ret = new Error(getStringFromWasm0(arg0, arg1));
315
+ return ret;
316
+ };
317
+ imports.wbg.__wbindgen_in = function(arg0, arg1) {
318
+ const ret = arg0 in arg1;
319
+ return ret;
320
+ };
321
+ imports.wbg.__wbindgen_init_externref_table = function() {
322
+ const table = wasm.__wbindgen_export_2;
323
+ const offset = table.grow(4);
324
+ table.set(0, void 0);
325
+ table.set(offset + 0, void 0);
326
+ table.set(offset + 1, null);
327
+ table.set(offset + 2, true);
328
+ table.set(offset + 3, false);
329
+ ;
330
+ };
331
+ imports.wbg.__wbindgen_is_object = function(arg0) {
332
+ const val = arg0;
333
+ const ret = typeof val === "object" && val !== null;
334
+ return ret;
335
+ };
336
+ imports.wbg.__wbindgen_is_undefined = function(arg0) {
337
+ const ret = arg0 === void 0;
338
+ return ret;
339
+ };
340
+ imports.wbg.__wbindgen_jsval_loose_eq = function(arg0, arg1) {
341
+ const ret = arg0 == arg1;
342
+ return ret;
343
+ };
344
+ imports.wbg.__wbindgen_memory = function() {
345
+ const ret = wasm.memory;
346
+ return ret;
347
+ };
348
+ imports.wbg.__wbindgen_number_get = function(arg0, arg1) {
349
+ const obj = arg1;
350
+ const ret = typeof obj === "number" ? obj : void 0;
351
+ getDataViewMemory0().setFloat64(arg0 + 8 * 1, isLikeNone(ret) ? 0 : ret, true);
352
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
353
+ };
354
+ imports.wbg.__wbindgen_string_get = function(arg0, arg1) {
355
+ const obj = arg1;
356
+ const ret = typeof obj === "string" ? obj : void 0;
357
+ var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
358
+ var len1 = WASM_VECTOR_LEN;
359
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
360
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
361
+ };
362
+ imports.wbg.__wbindgen_string_new = function(arg0, arg1) {
363
+ const ret = getStringFromWasm0(arg0, arg1);
364
+ return ret;
365
+ };
366
+ imports.wbg.__wbindgen_throw = function(arg0, arg1) {
367
+ throw new Error(getStringFromWasm0(arg0, arg1));
368
+ };
369
+ return imports;
370
+ }
371
+ function __wbg_init_memory(imports, memory) {
372
+ }
373
+ function __wbg_finalize_init(instance, module) {
374
+ wasm = instance.exports;
375
+ __wbg_init.__wbindgen_wasm_module = module;
376
+ cachedDataViewMemory0 = null;
377
+ cachedUint8ArrayMemory0 = null;
378
+ wasm.__wbindgen_start();
379
+ return wasm;
380
+ }
381
+ async function __wbg_init(module_or_path) {
382
+ if (wasm !== void 0) return wasm;
383
+ if (typeof module_or_path !== "undefined") {
384
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
385
+ ({ module_or_path } = module_or_path);
386
+ } else {
387
+ console.warn("using deprecated parameters for the initialization function; pass a single object instead");
388
+ }
389
+ }
390
+ if (typeof module_or_path === "undefined") {
391
+ module_or_path = new URL("image_converter_back_end_bg.wasm", import.meta.url);
392
+ }
393
+ const imports = __wbg_get_imports();
394
+ if (typeof module_or_path === "string" || typeof Request === "function" && module_or_path instanceof Request || typeof URL === "function" && module_or_path instanceof URL) {
395
+ module_or_path = fetch(module_or_path);
396
+ }
397
+ __wbg_init_memory(imports);
398
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
399
+ return __wbg_finalize_init(instance, module);
400
+ }
401
+ var image_converter_back_end_default = __wbg_init;
402
+
403
+ // src/models/image_converter.ts
404
+ var ImageConverter = class {
405
+ constructor(payload) {
406
+ this.compression = payload.compression;
407
+ this.resize = payload.resize;
408
+ this.crop = payload.crop;
409
+ }
410
+ get options() {
411
+ const options = {};
412
+ if (this.compression) {
413
+ options.compressionOptions = this.compression.optionExport;
414
+ }
415
+ if (this.resize) {
416
+ options.resizeOptions = this.resize.optionExport;
417
+ }
418
+ if (this.crop) {
419
+ options.cropOptions = this.crop.optionExport;
420
+ }
421
+ return options;
422
+ }
423
+ async convertImageFile(file) {
424
+ const buf = await file.arrayBuffer();
425
+ const uint8Arr = new Uint8Array(buf);
426
+ return this.convertImageBytes(uint8Arr);
427
+ }
428
+ async convertImageBytes(bytes) {
429
+ await image_converter_back_end_default();
430
+ const result = process_image(bytes, this.options);
431
+ return result;
432
+ }
433
+ };
434
+
435
+ // src/models/compression_options.ts
436
+ var ImageCompressionOptions = class {
437
+ };
438
+ var JpegCompressionOptions = class extends ImageCompressionOptions {
439
+ constructor(quality) {
440
+ super();
441
+ if (quality < 0 || quality > 100) {
442
+ throw new Error("Quality must be between 0 and 100");
443
+ }
444
+ this.quality = quality;
445
+ }
446
+ get optionExport() {
447
+ return {
448
+ format: "jpeg",
449
+ quality: this.quality
450
+ };
451
+ }
452
+ };
453
+ var PngCompressionOptions = class extends ImageCompressionOptions {
454
+ constructor(compressionLevel) {
455
+ super();
456
+ if (compressionLevel < 0 || compressionLevel > 9) {
457
+ throw new Error("Compression level must be between 0 and 9");
458
+ }
459
+ this.compressionLevel = compressionLevel;
460
+ }
461
+ get optionExport() {
462
+ return {
463
+ format: "png",
464
+ quality: this.compressionLevel
465
+ };
466
+ }
467
+ };
468
+ var GifCompressionOptions = class extends ImageCompressionOptions {
469
+ get optionExport() {
470
+ return { format: "gif" };
471
+ }
472
+ };
473
+ var BmpCompressionOptions = class extends ImageCompressionOptions {
474
+ get optionExport() {
475
+ return { format: "bmp" };
476
+ }
477
+ };
478
+ var TgaCompressionOptions = class extends ImageCompressionOptions {
479
+ get optionExport() {
480
+ return { format: "tga" };
481
+ }
482
+ };
483
+ var TiffCompressionOptions = class extends ImageCompressionOptions {
484
+ get optionExport() {
485
+ return { format: "tiff" };
486
+ }
487
+ };
488
+
489
+ // src/models/crop_options.ts
490
+ var ImageCropOptions = class {
491
+ };
492
+ var ImageCropDimensionOptions = class extends ImageCropOptions {
493
+ constructor(payload) {
494
+ super();
495
+ const { x, y, width, height } = payload;
496
+ if (x < 0 || y < 0 || width <= 0 || height <= 0) {
497
+ throw new Error("Values must be greater than or equal to 0");
498
+ }
499
+ this.x = x;
500
+ this.y = y;
501
+ this.width = width;
502
+ this.height = height;
503
+ }
504
+ get optionExport() {
505
+ return {
506
+ x: this.x,
507
+ y: this.y,
508
+ width: this.width,
509
+ height: this.height
510
+ };
511
+ }
512
+ };
513
+ var ImageCropAspectRatioOptions = class extends ImageCropOptions {
514
+ constructor(payload) {
515
+ super();
516
+ const { ratio_width, ratio_height } = payload;
517
+ if (ratio_width <= 0 || ratio_height <= 0) {
518
+ throw new Error("Ratio width and height must be greater than 0");
519
+ }
520
+ this.ratio_width = ratio_width;
521
+ this.ratio_height = ratio_height;
522
+ }
523
+ get optionExport() {
524
+ return {
525
+ ratio_width: this.ratio_width,
526
+ ratio_height: this.ratio_height
527
+ };
528
+ }
529
+ };
530
+ var ImageCropEachSideOptions = class extends ImageCropOptions {
531
+ constructor(payload) {
532
+ super();
533
+ const { crop_left, crop_right, crop_top, crop_bottom } = payload;
534
+ if (crop_left < 0 || crop_right < 0 || crop_top < 0 || crop_bottom < 0) {
535
+ throw new Error("Values must be greater than or equal to 0");
536
+ }
537
+ this.crop_left = crop_left;
538
+ this.crop_right = crop_right;
539
+ this.crop_top = crop_top;
540
+ this.crop_bottom = crop_bottom;
541
+ }
542
+ get optionExport() {
543
+ return {
544
+ crop_left: this.crop_left,
545
+ crop_right: this.crop_right,
546
+ crop_top: this.crop_top,
547
+ crop_bottom: this.crop_bottom
548
+ };
549
+ }
550
+ };
551
+
552
+ // src/models/resize_options.ts
553
+ var ImpageResizeOptions = class {
554
+ };
555
+ var ImageResizeDimensionOptions = class extends ImpageResizeOptions {
556
+ constructor(payload) {
557
+ super();
558
+ if (payload.width <= 0 || payload.height <= 0) {
559
+ throw new Error("Width and height must be greater than 0");
560
+ }
561
+ const { width, height } = payload;
562
+ this.width = width;
563
+ this.height = height;
564
+ }
565
+ get optionExport() {
566
+ return {
567
+ width: this.width,
568
+ height: this.height
569
+ };
570
+ }
571
+ };
572
+ var ImageResizeAspectRatioOptions = class extends ImpageResizeOptions {
573
+ constructor(payload) {
574
+ super();
575
+ if (payload.ratio_width <= 0 || payload.ratio_height <= 0) {
576
+ throw new Error("Ratio width and height must be greater than 0");
577
+ }
578
+ const { ratio_width, ratio_height } = payload;
579
+ this.ratio_width = ratio_width;
580
+ this.ratio_height = ratio_height;
581
+ }
582
+ get optionExport() {
583
+ return {
584
+ ratio_width: this.ratio_width,
585
+ ratio_height: this.ratio_height
586
+ };
587
+ }
588
+ };
589
+ var ImageResizeLongestSideOptions = class extends ImpageResizeOptions {
590
+ constructor(payload) {
591
+ super();
592
+ if (payload.longest_side <= 0) {
593
+ throw new Error("Longest side must be greater than 0");
594
+ }
595
+ const { longest_side } = payload;
596
+ this.longest_side = longest_side;
597
+ }
598
+ get optionExport() {
599
+ return {
600
+ longest_side: this.longest_side
601
+ };
602
+ }
603
+ };
604
+
605
+ // src/convenience/jpg_converter.ts
606
+ function getJpegConverter(payload) {
607
+ const { quality, longest_side } = payload ?? {};
608
+ const input = {};
609
+ if (quality) {
610
+ input.compression = new JpegCompressionOptions(quality);
611
+ }
612
+ if (longest_side) {
613
+ input.resize = new ImageResizeLongestSideOptions({
614
+ longest_side
615
+ });
616
+ }
617
+ return new ImageConverter(input);
618
+ }
619
+
620
+ // src/convenience/png_converter.ts
621
+ function getPngConverter(payload) {
622
+ const { compressionLevel, longest_side } = payload ?? {};
623
+ const input = {};
624
+ if (compressionLevel) {
625
+ input.compression = new PngCompressionOptions(compressionLevel);
626
+ }
627
+ if (longest_side) {
628
+ input.resize = new ImageResizeLongestSideOptions({
629
+ longest_side
630
+ });
631
+ }
632
+ return new ImageConverter(input);
633
+ }
634
+ export {
635
+ BmpCompressionOptions,
636
+ GifCompressionOptions,
637
+ ImageConverter,
638
+ ImageCropAspectRatioOptions,
639
+ ImageCropDimensionOptions,
640
+ ImageCropEachSideOptions,
641
+ ImageResizeAspectRatioOptions,
642
+ ImageResizeDimensionOptions,
643
+ ImageResizeLongestSideOptions,
644
+ JpegCompressionOptions,
645
+ PngCompressionOptions,
646
+ TgaCompressionOptions,
647
+ TiffCompressionOptions,
648
+ getJpegConverter,
649
+ getPngConverter
650
+ };
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@metools/web-image-converter",
3
+ "version": "1.0.0",
4
+ "main": "dist/index.js",
5
+ "module": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "files": [
8
+ "dist/image_converter_back_end_bg.wasm"
9
+ ],
10
+ "type": "module",
11
+ "sideEffects": false,
12
+ "author": "Mathew E. Thompson",
13
+ "license": "Apache-2.0",
14
+ "description": "JS Image converter for web from a Rust-based WebAssembly Back End",
15
+ "homepage": "https://github.com/methompson/image_converter",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/methompson/image_converter.git"
19
+ },
20
+ "scripts": {
21
+ "build": "tsup && cp src/image_converter_binary/image_converter_back_end_bg.wasm dist/",
22
+ "lint": "eslint",
23
+ "test": "jest"
24
+ },
25
+ "devDependencies": {
26
+ "@jest/globals": "^29.7.0",
27
+ "@types/jest": "^29.5.14",
28
+ "@typescript-eslint/parser": "^8.32.1",
29
+ "eslint-config-prettier": "^10.1.5",
30
+ "eslint-plugin-prettier": "^5.4.0",
31
+ "jest": "^29.7.0",
32
+ "prettier": "^3.5.3",
33
+ "ts-jest": "^29.3.4",
34
+ "tsup": "^8.5.0",
35
+ "typescript": "^5.8.3",
36
+ "typescript-eslint": "^8.32.1"
37
+ }
38
+ }