smallpeg 0.13.1 → 0.14.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.
@@ -1,88 +1,156 @@
1
- let wasm;
1
+ /* @ts-self-types="./smallpeg_wasm.d.ts" */
2
2
 
3
- const cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : { decode: () => { throw Error('TextDecoder not available') } } );
4
-
5
- if (typeof TextDecoder !== 'undefined') { cachedTextDecoder.decode(); };
6
-
7
- let cachedUint8ArrayMemory0 = null;
8
-
9
- function getUint8ArrayMemory0() {
10
- if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
11
- cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
3
+ /**
4
+ * Decoded or transformed pixels. The TypeScript layer reads the fields,
5
+ * moves the pixels out with `take_pixels`, and frees it.
6
+ */
7
+ export class Image {
8
+ static __wrap(ptr) {
9
+ const obj = Object.create(Image.prototype);
10
+ obj.__wbg_ptr = ptr;
11
+ ImageFinalization.register(obj, obj.__wbg_ptr, obj);
12
+ return obj;
13
+ }
14
+ __destroy_into_raw() {
15
+ const ptr = this.__wbg_ptr;
16
+ this.__wbg_ptr = 0;
17
+ ImageFinalization.unregister(this);
18
+ return ptr;
19
+ }
20
+ free() {
21
+ const ptr = this.__destroy_into_raw();
22
+ wasm.__wbg_image_free(ptr, 0);
23
+ }
24
+ /**
25
+ * @returns {number}
26
+ */
27
+ get channels() {
28
+ const ret = wasm.image_channels(this.__wbg_ptr);
29
+ return ret;
30
+ }
31
+ /**
32
+ * @returns {number}
33
+ */
34
+ get height() {
35
+ const ret = wasm.image_height(this.__wbg_ptr);
36
+ return ret >>> 0;
37
+ }
38
+ /**
39
+ * Moves the pixels out (no copy on the Rust side); a second call
40
+ * returns an empty array.
41
+ * @returns {Uint8Array}
42
+ */
43
+ take_pixels() {
44
+ const ret = wasm.image_take_pixels(this.__wbg_ptr);
45
+ var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
46
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
47
+ return v1;
48
+ }
49
+ /**
50
+ * @returns {number}
51
+ */
52
+ get width() {
53
+ const ret = wasm.image_width(this.__wbg_ptr);
54
+ return ret >>> 0;
12
55
  }
13
- return cachedUint8ArrayMemory0;
14
- }
15
-
16
- function getStringFromWasm0(ptr, len) {
17
- ptr = ptr >>> 0;
18
- return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
19
- }
20
-
21
- let WASM_VECTOR_LEN = 0;
22
-
23
- function passArray8ToWasm0(arg, malloc) {
24
- const ptr = malloc(arg.length * 1, 1) >>> 0;
25
- getUint8ArrayMemory0().set(arg, ptr / 1);
26
- WASM_VECTOR_LEN = arg.length;
27
- return ptr;
28
- }
29
-
30
- function isLikeNone(x) {
31
- return x === undefined || x === null;
32
56
  }
57
+ if (Symbol.dispose) Image.prototype[Symbol.dispose] = Image.prototype.free;
33
58
 
34
- function takeFromExternrefTable0(idx) {
35
- const value = wasm.__wbindgen_export_0.get(idx);
36
- wasm.__externref_table_dealloc(idx);
37
- return value;
59
+ /**
60
+ * Frame-header facts, returned by `info`.
61
+ */
62
+ export class JpegInfo {
63
+ static __wrap(ptr) {
64
+ const obj = Object.create(JpegInfo.prototype);
65
+ obj.__wbg_ptr = ptr;
66
+ JpegInfoFinalization.register(obj, obj.__wbg_ptr, obj);
67
+ return obj;
68
+ }
69
+ __destroy_into_raw() {
70
+ const ptr = this.__wbg_ptr;
71
+ this.__wbg_ptr = 0;
72
+ JpegInfoFinalization.unregister(this);
73
+ return ptr;
74
+ }
75
+ free() {
76
+ const ptr = this.__destroy_into_raw();
77
+ wasm.__wbg_jpeginfo_free(ptr, 0);
78
+ }
79
+ /**
80
+ * @returns {number}
81
+ */
82
+ get components() {
83
+ const ret = wasm.jpeginfo_components(this.__wbg_ptr);
84
+ return ret;
85
+ }
86
+ /**
87
+ * @returns {number}
88
+ */
89
+ get height() {
90
+ const ret = wasm.jpeginfo_height(this.__wbg_ptr);
91
+ return ret >>> 0;
92
+ }
93
+ /**
94
+ * @returns {number}
95
+ */
96
+ get orientation() {
97
+ const ret = wasm.jpeginfo_orientation(this.__wbg_ptr);
98
+ return ret;
99
+ }
100
+ /**
101
+ * @returns {boolean}
102
+ */
103
+ get progressive() {
104
+ const ret = wasm.jpeginfo_progressive(this.__wbg_ptr);
105
+ return ret !== 0;
106
+ }
107
+ /**
108
+ * @returns {number}
109
+ */
110
+ get width() {
111
+ const ret = wasm.jpeginfo_width(this.__wbg_ptr);
112
+ return ret >>> 0;
113
+ }
38
114
  }
115
+ if (Symbol.dispose) JpegInfo.prototype[Symbol.dispose] = JpegInfo.prototype.free;
39
116
 
40
- function getArrayU8FromWasm0(ptr, len) {
41
- ptr = ptr >>> 0;
42
- return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
43
- }
44
117
  /**
45
- * Encode pixels as a JPEG.
46
- *
47
- * `channels` is 1 (gray), 3 (RGB) or 4 (RGBA, as from a canvas; alpha is
48
- * flattened onto white). `quality` is 1..=100 (default 80). `fullColor`
49
- * keeps chroma at full resolution (4:4:4) instead of halving it (4:2:0):
50
- * sharper colored text and lines, larger files. Both dimensions must be at
51
- * most 65535.
52
118
  * @param {Uint8Array} pixels
53
119
  * @param {number} width
54
120
  * @param {number} height
55
121
  * @param {number} channels
56
- * @param {number | undefined} [quality]
57
- * @param {boolean | undefined} [fullColor]
58
- * @returns {Uint8Array}
122
+ * @param {number} orientation
123
+ * @returns {Image}
59
124
  */
60
- export function encode(pixels, width, height, channels, quality, fullColor) {
125
+ export function apply_orientation(pixels, width, height, channels, orientation) {
61
126
  const ptr0 = passArray8ToWasm0(pixels, wasm.__wbindgen_malloc);
62
127
  const len0 = WASM_VECTOR_LEN;
63
- const ret = wasm.encode(ptr0, len0, width, height, channels, isLikeNone(quality) ? 0xFFFFFF : quality, isLikeNone(fullColor) ? 0xFFFFFF : fullColor ? 1 : 0);
64
- if (ret[3]) {
65
- throw takeFromExternrefTable0(ret[2]);
128
+ const ret = wasm.apply_orientation(ptr0, len0, width, height, channels, orientation);
129
+ if (ret[2]) {
130
+ throw takeFromExternrefTable0(ret[1]);
66
131
  }
67
- var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
68
- wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
69
- return v2;
132
+ return Image.__wrap(ret[0]);
70
133
  }
71
134
 
72
135
  /**
73
- * Make an existing JPEG smaller without changing a pixel. `undefined` if
74
- * the file is not one this can re-code. The result can come out larger
75
- * for files that are already optimized; compare lengths. `baseline`
76
- * forces baseline sequential output (for targets that dislike
77
- * progressive JPEGs, such as PDF embedding).
78
- * @param {Uint8Array} jpeg
79
- * @param {boolean | undefined} [baseline]
136
+ * `undefined` if the rectangle is empty or not entirely inside the image.
137
+ * @param {Uint8Array} pixels
138
+ * @param {number} width
139
+ * @param {number} height
140
+ * @param {number} channels
141
+ * @param {number} x
142
+ * @param {number} y
143
+ * @param {number} crop_width
144
+ * @param {number} crop_height
80
145
  * @returns {Uint8Array | undefined}
81
146
  */
82
- export function optimize(jpeg, baseline) {
83
- const ptr0 = passArray8ToWasm0(jpeg, wasm.__wbindgen_malloc);
147
+ export function crop(pixels, width, height, channels, x, y, crop_width, crop_height) {
148
+ const ptr0 = passArray8ToWasm0(pixels, wasm.__wbindgen_malloc);
84
149
  const len0 = WASM_VECTOR_LEN;
85
- const ret = wasm.optimize(ptr0, len0, isLikeNone(baseline) ? 0xFFFFFF : baseline ? 1 : 0);
150
+ const ret = wasm.crop(ptr0, len0, width, height, channels, x, y, crop_width, crop_height);
151
+ if (ret[3]) {
152
+ throw takeFromExternrefTable0(ret[2]);
153
+ }
86
154
  let v2;
87
155
  if (ret[0] !== 0) {
88
156
  v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
@@ -92,27 +160,57 @@ export function optimize(jpeg, baseline) {
92
160
  }
93
161
 
94
162
  /**
95
- * Remove EXIF (including GPS), XMP, comments and other metadata without
96
- * touching the image data. Keeps the color profile and the photo's
97
- * orientation. `undefined` if the file cannot be parsed.
98
163
  * @param {Uint8Array} jpeg
99
- * @returns {Uint8Array | undefined}
164
+ * @returns {Image | undefined}
100
165
  */
101
- export function stripMetadata(jpeg) {
166
+ export function decode(jpeg) {
102
167
  const ptr0 = passArray8ToWasm0(jpeg, wasm.__wbindgen_malloc);
103
168
  const len0 = WASM_VECTOR_LEN;
104
- const ret = wasm.stripMetadata(ptr0, len0);
105
- let v2;
106
- if (ret[0] !== 0) {
107
- v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
108
- wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
169
+ const ret = wasm.decode(ptr0, len0);
170
+ return ret === 0 ? undefined : Image.__wrap(ret);
171
+ }
172
+
173
+ /**
174
+ * Encode pixels; 4 channels are RGBA, flattened onto white.
175
+ * @param {Uint8Array} pixels
176
+ * @param {number} width
177
+ * @param {number} height
178
+ * @param {number} channels
179
+ * @param {number | null} [quality]
180
+ * @param {boolean | null} [full_color]
181
+ * @returns {Uint8Array}
182
+ */
183
+ export function encode(pixels, width, height, channels, quality, full_color) {
184
+ const ptr0 = passArray8ToWasm0(pixels, wasm.__wbindgen_malloc);
185
+ const len0 = WASM_VECTOR_LEN;
186
+ const ret = wasm.encode(ptr0, len0, width, height, channels, isLikeNone(quality) ? 0xFFFFFF : quality, isLikeNone(full_color) ? 0xFFFFFF : full_color ? 1 : 0);
187
+ if (ret[3]) {
188
+ throw takeFromExternrefTable0(ret[2]);
109
189
  }
190
+ var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
191
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
110
192
  return v2;
111
193
  }
112
194
 
113
195
  /**
114
- * Read a JPEG's frame header without decoding it. `undefined` if the
115
- * bytes are not a JPEG this library understands.
196
+ * `[width, height]` that fits, keeping the aspect ratio; never enlarges.
197
+ * @param {number} width
198
+ * @param {number} height
199
+ * @param {number} max_width
200
+ * @param {number} max_height
201
+ * @returns {Uint32Array}
202
+ */
203
+ export function fit_within(width, height, max_width, max_height) {
204
+ const ret = wasm.fit_within(width, height, max_width, max_height);
205
+ if (ret[3]) {
206
+ throw takeFromExternrefTable0(ret[2]);
207
+ }
208
+ var v1 = getArrayU32FromWasm0(ret[0], ret[1]).slice();
209
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
210
+ return v1;
211
+ }
212
+
213
+ /**
116
214
  * @param {Uint8Array} jpeg
117
215
  * @returns {JpegInfo | undefined}
118
216
  */
@@ -124,60 +222,38 @@ export function info(jpeg) {
124
222
  }
125
223
 
126
224
  /**
127
- * Decode a grayscale or color JPEG to 8-bit gray or RGB pixels, as
128
- * stored (see `applyOrientation`). `undefined` for CMYK files, codings
129
- * this library does not decode, malformed input, or frames over 100
130
- * megapixels.
225
+ * Lossless re-coding; `baseline` forces sequential output.
131
226
  * @param {Uint8Array} jpeg
132
- * @returns {Image | undefined}
227
+ * @param {boolean} baseline
228
+ * @returns {Uint8Array | undefined}
133
229
  */
134
- export function decode(jpeg) {
230
+ export function optimize(jpeg, baseline) {
135
231
  const ptr0 = passArray8ToWasm0(jpeg, wasm.__wbindgen_malloc);
136
232
  const len0 = WASM_VECTOR_LEN;
137
- const ret = wasm.decode(ptr0, len0);
138
- return ret === 0 ? undefined : Image.__wrap(ret);
139
- }
140
-
141
- /**
142
- * Turn decoded pixels upright for an EXIF orientation (1..=8; other
143
- * values leave them as they are). Orientations 5 to 8 swap width and
144
- * height.
145
- * @param {Uint8Array} pixels
146
- * @param {number} width
147
- * @param {number} height
148
- * @param {number} channels
149
- * @param {number} orientation
150
- * @returns {Image}
151
- */
152
- export function applyOrientation(pixels, width, height, channels, orientation) {
153
- const ptr0 = passArray8ToWasm0(pixels, wasm.__wbindgen_malloc);
154
- const len0 = WASM_VECTOR_LEN;
155
- const ret = wasm.applyOrientation(ptr0, len0, width, height, channels, orientation);
156
- if (ret[2]) {
157
- throw takeFromExternrefTable0(ret[1]);
233
+ const ret = wasm.optimize(ptr0, len0, baseline);
234
+ let v2;
235
+ if (ret[0] !== 0) {
236
+ v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
237
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
158
238
  }
159
- return Image.__wrap(ret[0]);
239
+ return v2;
160
240
  }
161
241
 
162
242
  /**
163
- * Resize with a Lanczos3 filter. `channels` is 1 (gray), 3 (RGB) or 4
164
- * (any four-channel layout, each channel filtered independently).
165
- * `linear` filters RGB or gray in linear light, which keeps fine
166
- * light-and-dark detail from darkening when reducing; it assumes sRGB
167
- * input and is not available for 4 channels.
243
+ * Lanczos3 resize; `linear` filters gray or RGB in linear light.
168
244
  * @param {Uint8Array} pixels
169
245
  * @param {number} width
170
246
  * @param {number} height
171
247
  * @param {number} channels
172
- * @param {number} newWidth
173
- * @param {number} newHeight
174
- * @param {boolean | undefined} [linear]
248
+ * @param {number} new_width
249
+ * @param {number} new_height
250
+ * @param {boolean} linear
175
251
  * @returns {Uint8Array}
176
252
  */
177
- export function resize(pixels, width, height, channels, newWidth, newHeight, linear) {
253
+ export function resize(pixels, width, height, channels, new_width, new_height, linear) {
178
254
  const ptr0 = passArray8ToWasm0(pixels, wasm.__wbindgen_malloc);
179
255
  const len0 = WASM_VECTOR_LEN;
180
- const ret = wasm.resize(ptr0, len0, width, height, channels, newWidth, newHeight, isLikeNone(linear) ? 0xFFFFFF : linear ? 1 : 0);
256
+ const ret = wasm.resize(ptr0, len0, width, height, channels, new_width, new_height, linear);
181
257
  if (ret[3]) {
182
258
  throw takeFromExternrefTable0(ret[2]);
183
259
  }
@@ -187,25 +263,13 @@ export function resize(pixels, width, height, channels, newWidth, newHeight, lin
187
263
  }
188
264
 
189
265
  /**
190
- * Copy a rectangle out of pixels with any channel count. `undefined` if
191
- * the rectangle is empty or not entirely inside the image.
192
- * @param {Uint8Array} pixels
193
- * @param {number} width
194
- * @param {number} height
195
- * @param {number} channels
196
- * @param {number} x
197
- * @param {number} y
198
- * @param {number} cropWidth
199
- * @param {number} cropHeight
266
+ * @param {Uint8Array} jpeg
200
267
  * @returns {Uint8Array | undefined}
201
268
  */
202
- export function crop(pixels, width, height, channels, x, y, cropWidth, cropHeight) {
203
- const ptr0 = passArray8ToWasm0(pixels, wasm.__wbindgen_malloc);
269
+ export function strip_metadata(jpeg) {
270
+ const ptr0 = passArray8ToWasm0(jpeg, wasm.__wbindgen_malloc);
204
271
  const len0 = WASM_VECTOR_LEN;
205
- const ret = wasm.crop(ptr0, len0, width, height, channels, x, y, cropWidth, cropHeight);
206
- if (ret[3]) {
207
- throw takeFromExternrefTable0(ret[2]);
208
- }
272
+ const ret = wasm.strip_metadata(ptr0, len0);
209
273
  let v2;
210
274
  if (ret[0] !== 0) {
211
275
  v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
@@ -213,247 +277,157 @@ export function crop(pixels, width, height, channels, x, y, cropWidth, cropHeigh
213
277
  }
214
278
  return v2;
215
279
  }
216
-
217
- let cachedUint32ArrayMemory0 = null;
218
-
219
- function getUint32ArrayMemory0() {
220
- if (cachedUint32ArrayMemory0 === null || cachedUint32ArrayMemory0.byteLength === 0) {
221
- cachedUint32ArrayMemory0 = new Uint32Array(wasm.memory.buffer);
222
- }
223
- return cachedUint32ArrayMemory0;
280
+ function __wbg_get_imports() {
281
+ const import0 = {
282
+ __proto__: null,
283
+ __wbg_Error_408e67f47ca7b58b: function(arg0, arg1) {
284
+ const ret = Error(getStringFromWasm0(arg0, arg1));
285
+ return ret;
286
+ },
287
+ __wbg___wbindgen_throw_bb96b2010945f0bc: function(arg0, arg1) {
288
+ throw new Error(getStringFromWasm0(arg0, arg1));
289
+ },
290
+ __wbindgen_init_externref_table: function() {
291
+ const table = wasm.__wbindgen_externrefs;
292
+ const offset = table.grow(4);
293
+ table.set(0, undefined);
294
+ table.set(offset + 0, undefined);
295
+ table.set(offset + 1, null);
296
+ table.set(offset + 2, true);
297
+ table.set(offset + 3, false);
298
+ },
299
+ };
300
+ return {
301
+ __proto__: null,
302
+ "./smallpeg_wasm_bg.js": import0,
303
+ };
224
304
  }
225
305
 
306
+ const ImageFinalization = (typeof FinalizationRegistry === 'undefined')
307
+ ? { register: () => {}, unregister: () => {} }
308
+ : new FinalizationRegistry(ptr => wasm.__wbg_image_free(ptr, 1));
309
+ const JpegInfoFinalization = (typeof FinalizationRegistry === 'undefined')
310
+ ? { register: () => {}, unregister: () => {} }
311
+ : new FinalizationRegistry(ptr => wasm.__wbg_jpeginfo_free(ptr, 1));
312
+
226
313
  function getArrayU32FromWasm0(ptr, len) {
227
314
  ptr = ptr >>> 0;
228
315
  return getUint32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
229
316
  }
230
- /**
231
- * The largest `[width, height]` that fits inside `maxWidth` x `maxHeight`
232
- * with the same aspect ratio. Never enlarges.
233
- * @param {number} width
234
- * @param {number} height
235
- * @param {number} maxWidth
236
- * @param {number} maxHeight
237
- * @returns {Uint32Array}
238
- */
239
- export function fitWithin(width, height, maxWidth, maxHeight) {
240
- const ret = wasm.fitWithin(width, height, maxWidth, maxHeight);
241
- if (ret[3]) {
242
- throw takeFromExternrefTable0(ret[2]);
243
- }
244
- var v1 = getArrayU32FromWasm0(ret[0], ret[1]).slice();
245
- wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
246
- return v1;
317
+
318
+ function getArrayU8FromWasm0(ptr, len) {
319
+ ptr = ptr >>> 0;
320
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
247
321
  }
248
322
 
249
- const ImageFinalization = (typeof FinalizationRegistry === 'undefined')
250
- ? { register: () => {}, unregister: () => {} }
251
- : new FinalizationRegistry(ptr => wasm.__wbg_image_free(ptr >>> 0, 1));
252
- /**
253
- * Pixels plus their layout, returned by `decode` and `applyOrientation`.
254
- */
255
- export class Image {
323
+ function getStringFromWasm0(ptr, len) {
324
+ return decodeText(ptr >>> 0, len);
325
+ }
256
326
 
257
- static __wrap(ptr) {
258
- ptr = ptr >>> 0;
259
- const obj = Object.create(Image.prototype);
260
- obj.__wbg_ptr = ptr;
261
- ImageFinalization.register(obj, obj.__wbg_ptr, obj);
262
- return obj;
327
+ let cachedUint32ArrayMemory0 = null;
328
+ function getUint32ArrayMemory0() {
329
+ if (cachedUint32ArrayMemory0 === null || cachedUint32ArrayMemory0.byteLength === 0) {
330
+ cachedUint32ArrayMemory0 = new Uint32Array(wasm.memory.buffer);
263
331
  }
332
+ return cachedUint32ArrayMemory0;
333
+ }
264
334
 
265
- __destroy_into_raw() {
266
- const ptr = this.__wbg_ptr;
267
- this.__wbg_ptr = 0;
268
- ImageFinalization.unregister(this);
269
- return ptr;
335
+ let cachedUint8ArrayMemory0 = null;
336
+ function getUint8ArrayMemory0() {
337
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
338
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
270
339
  }
340
+ return cachedUint8ArrayMemory0;
341
+ }
271
342
 
272
- free() {
273
- const ptr = this.__destroy_into_raw();
274
- wasm.__wbg_image_free(ptr, 0);
275
- }
276
- /**
277
- * Width in pixels.
278
- * @returns {number}
279
- */
280
- get width() {
281
- const ret = wasm.image_width(this.__wbg_ptr);
282
- return ret >>> 0;
283
- }
284
- /**
285
- * Height in pixels.
286
- * @returns {number}
287
- */
288
- get height() {
289
- const ret = wasm.image_height(this.__wbg_ptr);
290
- return ret >>> 0;
291
- }
292
- /**
293
- * `width * height * channels` bytes, interleaved, top row first.
294
- * @returns {Uint8Array}
295
- */
296
- get pixels() {
297
- const ret = wasm.image_pixels(this.__wbg_ptr);
298
- var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
299
- wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
300
- return v1;
301
- }
302
- /**
303
- * 1 (gray) or 3 (RGB) for decoded JPEGs; whatever was passed in for
304
- * `applyOrientation`.
305
- * @returns {number}
306
- */
307
- get channels() {
308
- const ret = wasm.image_channels(this.__wbg_ptr);
309
- return ret;
310
- }
343
+ function isLikeNone(x) {
344
+ return x === undefined || x === null;
311
345
  }
312
346
 
313
- const JpegInfoFinalization = (typeof FinalizationRegistry === 'undefined')
314
- ? { register: () => {}, unregister: () => {} }
315
- : new FinalizationRegistry(ptr => wasm.__wbg_jpeginfo_free(ptr >>> 0, 1));
316
- /**
317
- * Frame-header facts about a JPEG, returned by `info`.
318
- */
319
- export class JpegInfo {
347
+ function passArray8ToWasm0(arg, malloc) {
348
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
349
+ getUint8ArrayMemory0().set(arg, ptr / 1);
350
+ WASM_VECTOR_LEN = arg.length;
351
+ return ptr;
352
+ }
320
353
 
321
- static __wrap(ptr) {
322
- ptr = ptr >>> 0;
323
- const obj = Object.create(JpegInfo.prototype);
324
- obj.__wbg_ptr = ptr;
325
- JpegInfoFinalization.register(obj, obj.__wbg_ptr, obj);
326
- return obj;
327
- }
354
+ function takeFromExternrefTable0(idx) {
355
+ const value = wasm.__wbindgen_externrefs.get(idx);
356
+ wasm.__externref_table_dealloc(idx);
357
+ return value;
358
+ }
328
359
 
329
- __destroy_into_raw() {
330
- const ptr = this.__wbg_ptr;
331
- this.__wbg_ptr = 0;
332
- JpegInfoFinalization.unregister(this);
333
- return ptr;
360
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
361
+ cachedTextDecoder.decode();
362
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
363
+ let numBytesDecoded = 0;
364
+ function decodeText(ptr, len) {
365
+ numBytesDecoded += len;
366
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
367
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
368
+ cachedTextDecoder.decode();
369
+ numBytesDecoded = len;
334
370
  }
371
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
372
+ }
335
373
 
336
- free() {
337
- const ptr = this.__destroy_into_raw();
338
- wasm.__wbg_jpeginfo_free(ptr, 0);
339
- }
340
- /**
341
- * 1 (gray), 3 (color) or 4 (CMYK / YCCK).
342
- * @returns {number}
343
- */
344
- get components() {
345
- const ret = wasm.jpeginfo_components(this.__wbg_ptr);
346
- return ret;
347
- }
348
- /**
349
- * EXIF orientation, 1..=8 (1 when the file has none).
350
- * @returns {number}
351
- */
352
- get orientation() {
353
- const ret = wasm.jpeginfo_orientation(this.__wbg_ptr);
354
- return ret;
355
- }
356
- /**
357
- * True for progressive files.
358
- * @returns {boolean}
359
- */
360
- get progressive() {
361
- const ret = wasm.jpeginfo_progressive(this.__wbg_ptr);
362
- return ret !== 0;
363
- }
364
- /**
365
- * Width in pixels.
366
- * @returns {number}
367
- */
368
- get width() {
369
- const ret = wasm.jpeginfo_width(this.__wbg_ptr);
370
- return ret >>> 0;
371
- }
372
- /**
373
- * Height in pixels.
374
- * @returns {number}
375
- */
376
- get height() {
377
- const ret = wasm.jpeginfo_height(this.__wbg_ptr);
378
- return ret >>> 0;
379
- }
374
+ let WASM_VECTOR_LEN = 0;
375
+
376
+ let wasmModule, wasmInstance, wasm;
377
+ function __wbg_finalize_init(instance, module) {
378
+ wasmInstance = instance;
379
+ wasm = instance.exports;
380
+ wasmModule = module;
381
+ cachedUint32ArrayMemory0 = null;
382
+ cachedUint8ArrayMemory0 = null;
383
+ wasm.__wbindgen_start();
384
+ return wasm;
380
385
  }
381
386
 
382
387
  async function __wbg_load(module, imports) {
383
388
  if (typeof Response === 'function' && module instanceof Response) {
389
+ if (!module.ok) {
390
+ throw new Error(`failed to fetch Wasm: ${module.status} ${module.statusText} fetching '${module.url}'`);
391
+ }
392
+
384
393
  if (typeof WebAssembly.instantiateStreaming === 'function') {
385
394
  try {
386
395
  return await WebAssembly.instantiateStreaming(module, imports);
387
-
388
396
  } catch (e) {
389
- if (module.headers.get('Content-Type') != 'application/wasm') {
397
+ const validResponse = expectedResponseType(module.type);
398
+
399
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
390
400
  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);
391
401
 
392
- } else {
393
- throw e;
394
- }
402
+ } else { throw e; }
395
403
  }
396
404
  }
397
405
 
398
406
  const bytes = await module.arrayBuffer();
399
407
  return await WebAssembly.instantiate(bytes, imports);
400
-
401
408
  } else {
402
409
  const instance = await WebAssembly.instantiate(module, imports);
403
410
 
404
411
  if (instance instanceof WebAssembly.Instance) {
405
412
  return { instance, module };
406
-
407
413
  } else {
408
414
  return instance;
409
415
  }
410
416
  }
411
- }
412
-
413
- function __wbg_get_imports() {
414
- const imports = {};
415
- imports.wbg = {};
416
- imports.wbg.__wbindgen_error_new = function(arg0, arg1) {
417
- const ret = new Error(getStringFromWasm0(arg0, arg1));
418
- return ret;
419
- };
420
- imports.wbg.__wbindgen_throw = function(arg0, arg1) {
421
- throw new Error(getStringFromWasm0(arg0, arg1));
422
- };
423
- imports.wbg.__wbindgen_init_externref_table = function() {
424
- const table = wasm.__wbindgen_export_0;
425
- const offset = table.grow(4);
426
- table.set(0, undefined);
427
- table.set(offset + 0, undefined);
428
- table.set(offset + 1, null);
429
- table.set(offset + 2, true);
430
- table.set(offset + 3, false);
431
- ;
432
- };
433
417
 
434
- return imports;
435
- }
436
-
437
- function __wbg_init_memory(imports, memory) {
438
-
439
- }
440
-
441
- function __wbg_finalize_init(instance, module) {
442
- wasm = instance.exports;
443
- __wbg_init.__wbindgen_wasm_module = module;
444
- cachedUint32ArrayMemory0 = null;
445
- cachedUint8ArrayMemory0 = null;
446
-
447
-
448
- wasm.__wbindgen_start();
449
- return wasm;
418
+ function expectedResponseType(type) {
419
+ switch (type) {
420
+ case 'basic': case 'cors': case 'default': return true;
421
+ }
422
+ return false;
423
+ }
450
424
  }
451
425
 
452
426
  function initSync(module) {
453
427
  if (wasm !== undefined) return wasm;
454
428
 
455
429
 
456
- if (typeof module !== 'undefined') {
430
+ if (module !== undefined) {
457
431
  if (Object.getPrototypeOf(module) === Object.prototype) {
458
432
  ({module} = module)
459
433
  } else {
@@ -462,15 +436,10 @@ function initSync(module) {
462
436
  }
463
437
 
464
438
  const imports = __wbg_get_imports();
465
-
466
- __wbg_init_memory(imports);
467
-
468
439
  if (!(module instanceof WebAssembly.Module)) {
469
440
  module = new WebAssembly.Module(module);
470
441
  }
471
-
472
442
  const instance = new WebAssembly.Instance(module, imports);
473
-
474
443
  return __wbg_finalize_init(instance, module);
475
444
  }
476
445
 
@@ -478,7 +447,7 @@ async function __wbg_init(module_or_path) {
478
447
  if (wasm !== undefined) return wasm;
479
448
 
480
449
 
481
- if (typeof module_or_path !== 'undefined') {
450
+ if (module_or_path !== undefined) {
482
451
  if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
483
452
  ({module_or_path} = module_or_path)
484
453
  } else {
@@ -486,7 +455,7 @@ async function __wbg_init(module_or_path) {
486
455
  }
487
456
  }
488
457
 
489
- if (typeof module_or_path === 'undefined') {
458
+ if (module_or_path === undefined) {
490
459
  module_or_path = new URL('smallpeg_wasm_bg.wasm', import.meta.url);
491
460
  }
492
461
  const imports = __wbg_get_imports();
@@ -495,12 +464,9 @@ async function __wbg_init(module_or_path) {
495
464
  module_or_path = fetch(module_or_path);
496
465
  }
497
466
 
498
- __wbg_init_memory(imports);
499
-
500
467
  const { instance, module } = await __wbg_load(await module_or_path, imports);
501
468
 
502
469
  return __wbg_finalize_init(instance, module);
503
470
  }
504
471
 
505
- export { initSync };
506
- export default __wbg_init;
472
+ export { initSync, __wbg_init as default };