@jsquash/resize 2.1.0 → 2.1.1
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,27 +1,22 @@
|
|
|
1
1
|
/* tslint:disable */
|
|
2
2
|
/* eslint-disable */
|
|
3
|
-
|
|
4
|
-
* @param {Uint8Array} data
|
|
5
|
-
* @param {number} input_width
|
|
6
|
-
* @param {number} input_height
|
|
7
|
-
* @param {number} output_width
|
|
8
|
-
* @param {number} output_height
|
|
9
|
-
* @param {string} version
|
|
10
|
-
* @returns {ImageData}
|
|
11
|
-
*/
|
|
3
|
+
|
|
12
4
|
export function resize(data: Uint8Array, input_width: number, input_height: number, output_width: number, output_height: number, version: string): ImageData;
|
|
13
5
|
|
|
14
6
|
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
15
7
|
|
|
16
8
|
export interface InitOutput {
|
|
17
9
|
readonly memory: WebAssembly.Memory;
|
|
18
|
-
readonly resize: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) =>
|
|
10
|
+
readonly resize: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => any;
|
|
19
11
|
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
12
|
+
readonly __wbindgen_externrefs: WebAssembly.Table;
|
|
20
13
|
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
21
14
|
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
15
|
+
readonly __wbindgen_start: () => void;
|
|
22
16
|
}
|
|
23
17
|
|
|
24
18
|
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
|
19
|
+
|
|
25
20
|
/**
|
|
26
21
|
* Instantiates the given `module`, which can either be bytes or
|
|
27
22
|
* a precompiled `WebAssembly.Module`.
|
|
@@ -1,36 +1,11 @@
|
|
|
1
1
|
let wasm;
|
|
2
2
|
|
|
3
|
-
let cachedUint8ClampedArrayMemory0 = null;
|
|
4
|
-
|
|
5
|
-
function getUint8ClampedArrayMemory0() {
|
|
6
|
-
if (cachedUint8ClampedArrayMemory0 === null || cachedUint8ClampedArrayMemory0.byteLength === 0) {
|
|
7
|
-
cachedUint8ClampedArrayMemory0 = new Uint8ClampedArray(wasm.memory.buffer);
|
|
8
|
-
}
|
|
9
|
-
return cachedUint8ClampedArrayMemory0;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
3
|
function getClampedArrayU8FromWasm0(ptr, len) {
|
|
13
4
|
ptr = ptr >>> 0;
|
|
14
5
|
return getUint8ClampedArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
|
|
15
6
|
}
|
|
16
7
|
|
|
17
|
-
const heap = new Array(128).fill(undefined);
|
|
18
|
-
|
|
19
|
-
heap.push(undefined, null, true, false);
|
|
20
|
-
|
|
21
|
-
let heap_next = heap.length;
|
|
22
|
-
|
|
23
|
-
function addHeapObject(obj) {
|
|
24
|
-
if (heap_next === heap.length) heap.push(heap.length + 1);
|
|
25
|
-
const idx = heap_next;
|
|
26
|
-
heap_next = heap[idx];
|
|
27
|
-
|
|
28
|
-
heap[idx] = obj;
|
|
29
|
-
return idx;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
8
|
let cachedUint8ArrayMemory0 = null;
|
|
33
|
-
|
|
34
9
|
function getUint8ArrayMemory0() {
|
|
35
10
|
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
36
11
|
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
@@ -38,7 +13,13 @@ function getUint8ArrayMemory0() {
|
|
|
38
13
|
return cachedUint8ArrayMemory0;
|
|
39
14
|
}
|
|
40
15
|
|
|
41
|
-
let
|
|
16
|
+
let cachedUint8ClampedArrayMemory0 = null;
|
|
17
|
+
function getUint8ClampedArrayMemory0() {
|
|
18
|
+
if (cachedUint8ClampedArrayMemory0 === null || cachedUint8ClampedArrayMemory0.byteLength === 0) {
|
|
19
|
+
cachedUint8ClampedArrayMemory0 = new Uint8ClampedArray(wasm.memory.buffer);
|
|
20
|
+
}
|
|
21
|
+
return cachedUint8ClampedArrayMemory0;
|
|
22
|
+
}
|
|
42
23
|
|
|
43
24
|
function passArray8ToWasm0(arg, malloc) {
|
|
44
25
|
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
|
@@ -47,23 +28,7 @@ function passArray8ToWasm0(arg, malloc) {
|
|
|
47
28
|
return ptr;
|
|
48
29
|
}
|
|
49
30
|
|
|
50
|
-
const cachedTextEncoder = (typeof TextEncoder !== 'undefined' ? new TextEncoder('utf-8') : { encode: () => { throw Error('TextEncoder not available') } } );
|
|
51
|
-
|
|
52
|
-
const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
|
|
53
|
-
? function (arg, view) {
|
|
54
|
-
return cachedTextEncoder.encodeInto(arg, view);
|
|
55
|
-
}
|
|
56
|
-
: function (arg, view) {
|
|
57
|
-
const buf = cachedTextEncoder.encode(arg);
|
|
58
|
-
view.set(buf);
|
|
59
|
-
return {
|
|
60
|
-
read: arg.length,
|
|
61
|
-
written: buf.length
|
|
62
|
-
};
|
|
63
|
-
});
|
|
64
|
-
|
|
65
31
|
function passStringToWasm0(arg, malloc, realloc) {
|
|
66
|
-
|
|
67
32
|
if (realloc === undefined) {
|
|
68
33
|
const buf = cachedTextEncoder.encode(arg);
|
|
69
34
|
const ptr = malloc(buf.length, 1) >>> 0;
|
|
@@ -84,14 +49,13 @@ function passStringToWasm0(arg, malloc, realloc) {
|
|
|
84
49
|
if (code > 0x7F) break;
|
|
85
50
|
mem[ptr + offset] = code;
|
|
86
51
|
}
|
|
87
|
-
|
|
88
52
|
if (offset !== len) {
|
|
89
53
|
if (offset !== 0) {
|
|
90
54
|
arg = arg.slice(offset);
|
|
91
55
|
}
|
|
92
56
|
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
93
57
|
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
94
|
-
const ret =
|
|
58
|
+
const ret = cachedTextEncoder.encodeInto(arg, view);
|
|
95
59
|
|
|
96
60
|
offset += ret.written;
|
|
97
61
|
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
@@ -101,19 +65,21 @@ function passStringToWasm0(arg, malloc, realloc) {
|
|
|
101
65
|
return ptr;
|
|
102
66
|
}
|
|
103
67
|
|
|
104
|
-
|
|
68
|
+
const cachedTextEncoder = new TextEncoder();
|
|
105
69
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
70
|
+
if (!('encodeInto' in cachedTextEncoder)) {
|
|
71
|
+
cachedTextEncoder.encodeInto = function (arg, view) {
|
|
72
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
73
|
+
view.set(buf);
|
|
74
|
+
return {
|
|
75
|
+
read: arg.length,
|
|
76
|
+
written: buf.length
|
|
77
|
+
};
|
|
78
|
+
}
|
|
110
79
|
}
|
|
111
80
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
dropObject(idx);
|
|
115
|
-
return ret;
|
|
116
|
-
}
|
|
81
|
+
let WASM_VECTOR_LEN = 0;
|
|
82
|
+
|
|
117
83
|
/**
|
|
118
84
|
* @param {Uint8Array} data
|
|
119
85
|
* @param {number} input_width
|
|
@@ -129,17 +95,20 @@ export function resize(data, input_width, input_height, output_width, output_hei
|
|
|
129
95
|
const ptr1 = passStringToWasm0(version, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
130
96
|
const len1 = WASM_VECTOR_LEN;
|
|
131
97
|
const ret = wasm.resize(ptr0, len0, input_width, input_height, output_width, output_height, ptr1, len1);
|
|
132
|
-
return
|
|
98
|
+
return ret;
|
|
133
99
|
}
|
|
134
100
|
|
|
101
|
+
const EXPECTED_RESPONSE_TYPES = new Set(['basic', 'cors', 'default']);
|
|
102
|
+
|
|
135
103
|
async function __wbg_load(module, imports) {
|
|
136
104
|
if (typeof Response === 'function' && module instanceof Response) {
|
|
137
105
|
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
|
138
106
|
try {
|
|
139
107
|
return await WebAssembly.instantiateStreaming(module, imports);
|
|
140
|
-
|
|
141
108
|
} catch (e) {
|
|
142
|
-
|
|
109
|
+
const validResponse = module.ok && EXPECTED_RESPONSE_TYPES.has(module.type);
|
|
110
|
+
|
|
111
|
+
if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
|
|
143
112
|
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);
|
|
144
113
|
|
|
145
114
|
} else {
|
|
@@ -150,13 +119,11 @@ async function __wbg_load(module, imports) {
|
|
|
150
119
|
|
|
151
120
|
const bytes = await module.arrayBuffer();
|
|
152
121
|
return await WebAssembly.instantiate(bytes, imports);
|
|
153
|
-
|
|
154
122
|
} else {
|
|
155
123
|
const instance = await WebAssembly.instantiate(module, imports);
|
|
156
124
|
|
|
157
125
|
if (instance instanceof WebAssembly.Instance) {
|
|
158
126
|
return { instance, module };
|
|
159
|
-
|
|
160
127
|
} else {
|
|
161
128
|
return instance;
|
|
162
129
|
}
|
|
@@ -166,20 +133,25 @@ async function __wbg_load(module, imports) {
|
|
|
166
133
|
function __wbg_get_imports() {
|
|
167
134
|
const imports = {};
|
|
168
135
|
imports.wbg = {};
|
|
169
|
-
imports.wbg.
|
|
136
|
+
imports.wbg.__wbg_new_with_owned_u8_clamped_array_and_sh_e8143e95833a3ec3 = function(arg0, arg1, arg2, arg3) {
|
|
170
137
|
var v0 = getClampedArrayU8FromWasm0(arg0, arg1).slice();
|
|
171
138
|
wasm.__wbindgen_free(arg0, arg1 * 1, 1);
|
|
172
139
|
const ret = new ImageData(v0, arg2 >>> 0, arg3 >>> 0);
|
|
173
|
-
return
|
|
140
|
+
return ret;
|
|
141
|
+
};
|
|
142
|
+
imports.wbg.__wbindgen_init_externref_table = function() {
|
|
143
|
+
const table = wasm.__wbindgen_externrefs;
|
|
144
|
+
const offset = table.grow(4);
|
|
145
|
+
table.set(0, undefined);
|
|
146
|
+
table.set(offset + 0, undefined);
|
|
147
|
+
table.set(offset + 1, null);
|
|
148
|
+
table.set(offset + 2, true);
|
|
149
|
+
table.set(offset + 3, false);
|
|
174
150
|
};
|
|
175
151
|
|
|
176
152
|
return imports;
|
|
177
153
|
}
|
|
178
154
|
|
|
179
|
-
function __wbg_init_memory(imports, memory) {
|
|
180
|
-
|
|
181
|
-
}
|
|
182
|
-
|
|
183
155
|
function __wbg_finalize_init(instance, module) {
|
|
184
156
|
wasm = instance.exports;
|
|
185
157
|
__wbg_init.__wbindgen_wasm_module = module;
|
|
@@ -187,7 +159,7 @@ function __wbg_finalize_init(instance, module) {
|
|
|
187
159
|
cachedUint8ClampedArrayMemory0 = null;
|
|
188
160
|
|
|
189
161
|
|
|
190
|
-
|
|
162
|
+
wasm.__wbindgen_start();
|
|
191
163
|
return wasm;
|
|
192
164
|
}
|
|
193
165
|
|
|
@@ -204,15 +176,10 @@ function initSync(module) {
|
|
|
204
176
|
}
|
|
205
177
|
|
|
206
178
|
const imports = __wbg_get_imports();
|
|
207
|
-
|
|
208
|
-
__wbg_init_memory(imports);
|
|
209
|
-
|
|
210
179
|
if (!(module instanceof WebAssembly.Module)) {
|
|
211
180
|
module = new WebAssembly.Module(module);
|
|
212
181
|
}
|
|
213
|
-
|
|
214
182
|
const instance = new WebAssembly.Instance(module, imports);
|
|
215
|
-
|
|
216
183
|
return __wbg_finalize_init(instance, module);
|
|
217
184
|
}
|
|
218
185
|
|
|
@@ -237,8 +204,6 @@ async function __wbg_init(module_or_path) {
|
|
|
237
204
|
module_or_path = fetch(module_or_path);
|
|
238
205
|
}
|
|
239
206
|
|
|
240
|
-
__wbg_init_memory(imports);
|
|
241
|
-
|
|
242
207
|
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
|
243
208
|
|
|
244
209
|
return __wbg_finalize_init(instance, module);
|
|
@@ -246,3 +211,27 @@ async function __wbg_init(module_or_path) {
|
|
|
246
211
|
|
|
247
212
|
export { initSync };
|
|
248
213
|
export default __wbg_init;
|
|
214
|
+
const isServiceWorker = globalThis.ServiceWorkerGlobalScope !== undefined;
|
|
215
|
+
const isRunningInCloudFlareWorkers = isServiceWorker && typeof self !== 'undefined' && globalThis.caches && globalThis.caches.default !== undefined;
|
|
216
|
+
const isRunningInNode = typeof process === 'object' && process.release && process.release.name === 'node';
|
|
217
|
+
|
|
218
|
+
if (isRunningInCloudFlareWorkers || isRunningInNode) {
|
|
219
|
+
if (!globalThis.ImageData) {
|
|
220
|
+
// Simple Polyfill for ImageData Object
|
|
221
|
+
globalThis.ImageData = class ImageData {
|
|
222
|
+
constructor(data, width, height) {
|
|
223
|
+
this.data = data;
|
|
224
|
+
this.width = width;
|
|
225
|
+
this.height = height;
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
if (import.meta.url === undefined) {
|
|
231
|
+
import.meta.url = 'https://localhost';
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
if (typeof self !== 'undefined' && self.location === undefined) {
|
|
235
|
+
self.location = { href: '' };
|
|
236
|
+
}
|
|
237
|
+
}
|
|
Binary file
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
/* tslint:disable */
|
|
2
2
|
/* eslint-disable */
|
|
3
3
|
export const memory: WebAssembly.Memory;
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
export
|
|
7
|
-
export
|
|
4
|
+
export const resize: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => any;
|
|
5
|
+
export const __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
6
|
+
export const __wbindgen_externrefs: WebAssembly.Table;
|
|
7
|
+
export const __wbindgen_malloc: (a: number, b: number) => number;
|
|
8
|
+
export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
9
|
+
export const __wbindgen_start: () => void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsquash/resize",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.1",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"description": "Wasm image resize methods supporting the browser and V8 environments. Repackaged from Squoosh App.",
|
|
6
6
|
"repository": "jamsinclair/jSquash/packages/resize",
|