@jsquash/resize 1.1.1 → 2.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/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { WorkerResizeOptions } from './meta.js';
2
- import type { InitInput as InitResizeInput } from './lib/resize/squoosh_resize.js';
3
- import type { InitInput as InitHqxInput } from './lib/hqx/squooshhqx.js';
2
+ import type { InitInput as InitResizeInput } from './lib/resize/pkg/squoosh_resize.js';
3
+ import type { InitInput as InitHqxInput } from './lib/hqx/pkg/squooshhqx.js';
4
4
  export declare function initResize(moduleOrPath?: InitResizeInput): Promise<unknown>;
5
5
  export declare function initHqx(moduleOrPath?: InitHqxInput): Promise<unknown>;
6
6
  export default function resize(data: ImageData, overrideOptions: Partial<WorkerResizeOptions> & {
package/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { getContainOffsets } from './util.js';
2
- import initResizeWasm, { resize as wasmResize, } from './lib/resize/squoosh_resize.js';
3
- import initHqxWasm, { resize as wasmHqx } from './lib/hqx/squooshhqx.js';
2
+ import initResizeWasm, { resize as wasmResize, } from './lib/resize/pkg/squoosh_resize.js';
3
+ import initHqxWasm, { resize as wasmHqx } from './lib/hqx/pkg/squooshhqx.js';
4
4
  import { defaultOptions } from './meta.js';
5
5
  let resizeWasmReady;
6
6
  let hqxWasmReady;
@@ -1,16 +1,8 @@
1
1
  {
2
2
  "name": "squooshhqx",
3
- "collaborators": [
4
- "Surma <surma@surma.link>"
5
- ],
6
- "version": "0.1.0",
7
- "files": [
8
- "squooshhqx_bg.wasm",
9
- "squooshhqx.js",
10
- "squooshhqx.d.ts"
11
- ],
12
- "module": "squooshhqx.js",
13
- "types": "squooshhqx.d.ts",
14
- "sideEffects": false,
3
+ "scripts": {
4
+ "build": "../../../../tools/build-rust.sh && npm run patch-pre-script",
5
+ "patch-pre-script": "cat pre.js >> pkg/squooshhqx.js"
6
+ },
15
7
  "type": "module"
16
8
  }
@@ -0,0 +1,5 @@
1
+ # HQX
2
+
3
+ - Source: <https://github.com/CryZe/wasmboy-rs>
4
+ - Version: v0.1.2
5
+ - License: Apache 2.0
@@ -15,10 +15,21 @@ export interface InitOutput {
15
15
  readonly memory: WebAssembly.Memory;
16
16
  readonly resize: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
17
17
  readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
18
- readonly __wbindgen_malloc: (a: number) => number;
19
- readonly __wbindgen_free: (a: number, b: number) => void;
18
+ readonly __wbindgen_malloc: (a: number, b: number) => number;
19
+ readonly __wbindgen_free: (a: number, b: number, c: number) => void;
20
20
  }
21
21
 
22
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
23
+ /**
24
+ * Instantiates the given `module`, which can either be bytes or
25
+ * a precompiled `WebAssembly.Module`.
26
+ *
27
+ * @param {SyncInitInput} module
28
+ *
29
+ * @returns {InitOutput}
30
+ */
31
+ export function initSync(module: SyncInitInput): InitOutput;
32
+
22
33
  /**
23
34
  * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
24
35
  * for everything else, calls `WebAssembly.instantiate` directly.
@@ -27,4 +38,4 @@ export interface InitOutput {
27
38
  *
28
39
  * @returns {Promise<InitOutput>}
29
40
  */
30
- export default function init (module_or_path?: InitInput | Promise<InitInput>): Promise<InitOutput>;
41
+ export default function __wbg_init (module_or_path?: InitInput | Promise<InitInput>): Promise<InitOutput>;
@@ -1,32 +1,34 @@
1
-
2
1
  let wasm;
3
2
 
4
- let cachegetUint32Memory0 = null;
3
+ let cachedUint32Memory0 = null;
4
+
5
5
  function getUint32Memory0() {
6
- if (cachegetUint32Memory0 === null || cachegetUint32Memory0.buffer !== wasm.memory.buffer) {
7
- cachegetUint32Memory0 = new Uint32Array(wasm.memory.buffer);
6
+ if (cachedUint32Memory0 === null || cachedUint32Memory0.byteLength === 0) {
7
+ cachedUint32Memory0 = new Uint32Array(wasm.memory.buffer);
8
8
  }
9
- return cachegetUint32Memory0;
9
+ return cachedUint32Memory0;
10
10
  }
11
11
 
12
12
  let WASM_VECTOR_LEN = 0;
13
13
 
14
14
  function passArray32ToWasm0(arg, malloc) {
15
- const ptr = malloc(arg.length * 4);
15
+ const ptr = malloc(arg.length * 4, 4) >>> 0;
16
16
  getUint32Memory0().set(arg, ptr / 4);
17
17
  WASM_VECTOR_LEN = arg.length;
18
18
  return ptr;
19
19
  }
20
20
 
21
- let cachegetInt32Memory0 = null;
21
+ let cachedInt32Memory0 = null;
22
+
22
23
  function getInt32Memory0() {
23
- if (cachegetInt32Memory0 === null || cachegetInt32Memory0.buffer !== wasm.memory.buffer) {
24
- cachegetInt32Memory0 = new Int32Array(wasm.memory.buffer);
24
+ if (cachedInt32Memory0 === null || cachedInt32Memory0.byteLength === 0) {
25
+ cachedInt32Memory0 = new Int32Array(wasm.memory.buffer);
25
26
  }
26
- return cachegetInt32Memory0;
27
+ return cachedInt32Memory0;
27
28
  }
28
29
 
29
30
  function getArrayU32FromWasm0(ptr, len) {
31
+ ptr = ptr >>> 0;
30
32
  return getUint32Memory0().subarray(ptr / 4, ptr / 4 + len);
31
33
  }
32
34
  /**
@@ -39,20 +41,20 @@ function getArrayU32FromWasm0(ptr, len) {
39
41
  export function resize(input_image, input_width, input_height, factor) {
40
42
  try {
41
43
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
42
- var ptr0 = passArray32ToWasm0(input_image, wasm.__wbindgen_malloc);
43
- var len0 = WASM_VECTOR_LEN;
44
+ const ptr0 = passArray32ToWasm0(input_image, wasm.__wbindgen_malloc);
45
+ const len0 = WASM_VECTOR_LEN;
44
46
  wasm.resize(retptr, ptr0, len0, input_width, input_height, factor);
45
47
  var r0 = getInt32Memory0()[retptr / 4 + 0];
46
48
  var r1 = getInt32Memory0()[retptr / 4 + 1];
47
- var v1 = getArrayU32FromWasm0(r0, r1).slice();
48
- wasm.__wbindgen_free(r0, r1 * 4);
49
- return v1;
49
+ var v2 = getArrayU32FromWasm0(r0, r1).slice();
50
+ wasm.__wbindgen_free(r0, r1 * 4, 4);
51
+ return v2;
50
52
  } finally {
51
53
  wasm.__wbindgen_add_to_stack_pointer(16);
52
54
  }
53
55
  }
54
56
 
55
- async function load(module, imports) {
57
+ async function __wbg_load(module, imports) {
56
58
  if (typeof Response === 'function' && module instanceof Response) {
57
59
  if (typeof WebAssembly.instantiateStreaming === 'function') {
58
60
  try {
@@ -83,29 +85,64 @@ async function load(module, imports) {
83
85
  }
84
86
  }
85
87
 
86
- async function init(input) {
88
+ function __wbg_get_imports() {
89
+ const imports = {};
90
+ imports.wbg = {};
91
+
92
+ return imports;
93
+ }
94
+
95
+ function __wbg_init_memory(imports, maybe_memory) {
96
+
97
+ }
98
+
99
+ function __wbg_finalize_init(instance, module) {
100
+ wasm = instance.exports;
101
+ __wbg_init.__wbindgen_wasm_module = module;
102
+ cachedInt32Memory0 = null;
103
+ cachedUint32Memory0 = null;
104
+
105
+
106
+ return wasm;
107
+ }
108
+
109
+ function initSync(module) {
110
+ if (wasm !== undefined) return wasm;
111
+
112
+ const imports = __wbg_get_imports();
113
+
114
+ __wbg_init_memory(imports);
115
+
116
+ if (!(module instanceof WebAssembly.Module)) {
117
+ module = new WebAssembly.Module(module);
118
+ }
119
+
120
+ const instance = new WebAssembly.Instance(module, imports);
121
+
122
+ return __wbg_finalize_init(instance, module);
123
+ }
124
+
125
+ async function __wbg_init(input) {
126
+ if (wasm !== undefined) return wasm;
127
+
87
128
  if (typeof input === 'undefined') {
88
129
  input = new URL('squooshhqx_bg.wasm', import.meta.url);
89
130
  }
90
- const imports = {};
91
-
131
+ const imports = __wbg_get_imports();
92
132
 
93
133
  if (typeof input === 'string' || (typeof Request === 'function' && input instanceof Request) || (typeof URL === 'function' && input instanceof URL)) {
94
134
  input = fetch(input);
95
135
  }
96
136
 
137
+ __wbg_init_memory(imports);
97
138
 
139
+ const { instance, module } = await __wbg_load(await input, imports);
98
140
 
99
- const { instance, module } = await load(await input, imports);
100
-
101
- wasm = instance.exports;
102
- init.__wbindgen_wasm_module = module;
103
-
104
- return wasm;
141
+ return __wbg_finalize_init(instance, module);
105
142
  }
106
143
 
107
- export default init;
108
-
144
+ export { initSync }
145
+ export default __wbg_init;
109
146
  const isServiceWorker = globalThis.ServiceWorkerGlobalScope !== undefined;
110
147
  const isRunningInCloudFlareWorkers = isServiceWorker && typeof self !== 'undefined' && globalThis.caches && globalThis.caches.default !== undefined;
111
148
  const isRunningInNode = typeof process === 'object' && process.release && process.release.name === 'node';
Binary file
@@ -0,0 +1,7 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ export const memory: WebAssembly.Memory;
4
+ export function resize(a: number, b: number, c: number, d: number, e: number, f: number): void;
5
+ export function __wbindgen_add_to_stack_pointer(a: number): number;
6
+ export function __wbindgen_malloc(a: number, b: number): number;
7
+ export function __wbindgen_free(a: number, b: number, c: number): void;
@@ -1,16 +1,8 @@
1
1
  {
2
2
  "name": "squoosh-resize",
3
- "collaborators": [
4
- "Surma <surma@surma.link>"
5
- ],
6
- "version": "0.1.0",
7
- "files": [
8
- "squoosh_resize_bg.wasm",
9
- "squoosh_resize.js",
10
- "squoosh_resize.d.ts"
11
- ],
12
- "module": "squoosh_resize.js",
13
- "types": "squoosh_resize.d.ts",
14
- "sideEffects": false,
3
+ "scripts": {
4
+ "build": "../../../../tools/build-rust.sh && npm run patch-pre-script",
5
+ "patch-pre-script": "cat pre.js >> pkg/squoosh_resize.js"
6
+ },
15
7
  "type": "module"
16
8
  }
@@ -0,0 +1,5 @@
1
+ # Resize
2
+
3
+ - Source: <https://github.com/PistonDevelopers/resize>
4
+ - Version: v0.3.0
5
+ - License: MIT
@@ -19,10 +19,21 @@ export interface InitOutput {
19
19
  readonly memory: WebAssembly.Memory;
20
20
  readonly resize: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number) => void;
21
21
  readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
22
- readonly __wbindgen_malloc: (a: number) => number;
23
- readonly __wbindgen_free: (a: number, b: number) => void;
22
+ readonly __wbindgen_malloc: (a: number, b: number) => number;
23
+ readonly __wbindgen_free: (a: number, b: number, c: number) => void;
24
24
  }
25
25
 
26
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
27
+ /**
28
+ * Instantiates the given `module`, which can either be bytes or
29
+ * a precompiled `WebAssembly.Module`.
30
+ *
31
+ * @param {SyncInitInput} module
32
+ *
33
+ * @returns {InitOutput}
34
+ */
35
+ export function initSync(module: SyncInitInput): InitOutput;
36
+
26
37
  /**
27
38
  * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
28
39
  * for everything else, calls `WebAssembly.instantiate` directly.
@@ -31,4 +42,4 @@ export interface InitOutput {
31
42
  *
32
43
  * @returns {Promise<InitOutput>}
33
44
  */
34
- export default function init (module_or_path?: InitInput | Promise<InitInput>): Promise<InitOutput>;
45
+ export default function __wbg_init (module_or_path?: InitInput | Promise<InitInput>): Promise<InitOutput>;
@@ -1,40 +1,43 @@
1
-
2
1
  let wasm;
3
2
 
4
- let cachegetUint8Memory0 = null;
3
+ let cachedUint8Memory0 = null;
4
+
5
5
  function getUint8Memory0() {
6
- if (cachegetUint8Memory0 === null || cachegetUint8Memory0.buffer !== wasm.memory.buffer) {
7
- cachegetUint8Memory0 = new Uint8Array(wasm.memory.buffer);
6
+ if (cachedUint8Memory0 === null || cachedUint8Memory0.byteLength === 0) {
7
+ cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer);
8
8
  }
9
- return cachegetUint8Memory0;
9
+ return cachedUint8Memory0;
10
10
  }
11
11
 
12
12
  let WASM_VECTOR_LEN = 0;
13
13
 
14
14
  function passArray8ToWasm0(arg, malloc) {
15
- const ptr = malloc(arg.length * 1);
15
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
16
16
  getUint8Memory0().set(arg, ptr / 1);
17
17
  WASM_VECTOR_LEN = arg.length;
18
18
  return ptr;
19
19
  }
20
20
 
21
- let cachegetInt32Memory0 = null;
21
+ let cachedInt32Memory0 = null;
22
+
22
23
  function getInt32Memory0() {
23
- if (cachegetInt32Memory0 === null || cachegetInt32Memory0.buffer !== wasm.memory.buffer) {
24
- cachegetInt32Memory0 = new Int32Array(wasm.memory.buffer);
24
+ if (cachedInt32Memory0 === null || cachedInt32Memory0.byteLength === 0) {
25
+ cachedInt32Memory0 = new Int32Array(wasm.memory.buffer);
25
26
  }
26
- return cachegetInt32Memory0;
27
+ return cachedInt32Memory0;
27
28
  }
28
29
 
29
- let cachegetUint8ClampedMemory0 = null;
30
+ let cachedUint8ClampedMemory0 = null;
31
+
30
32
  function getUint8ClampedMemory0() {
31
- if (cachegetUint8ClampedMemory0 === null || cachegetUint8ClampedMemory0.buffer !== wasm.memory.buffer) {
32
- cachegetUint8ClampedMemory0 = new Uint8ClampedArray(wasm.memory.buffer);
33
+ if (cachedUint8ClampedMemory0 === null || cachedUint8ClampedMemory0.byteLength === 0) {
34
+ cachedUint8ClampedMemory0 = new Uint8ClampedArray(wasm.memory.buffer);
33
35
  }
34
- return cachegetUint8ClampedMemory0;
36
+ return cachedUint8ClampedMemory0;
35
37
  }
36
38
 
37
39
  function getClampedArrayU8FromWasm0(ptr, len) {
40
+ ptr = ptr >>> 0;
38
41
  return getUint8ClampedMemory0().subarray(ptr / 1, ptr / 1 + len);
39
42
  }
40
43
  /**
@@ -51,20 +54,20 @@ function getClampedArrayU8FromWasm0(ptr, len) {
51
54
  export function resize(input_image, input_width, input_height, output_width, output_height, typ_idx, premultiply, color_space_conversion) {
52
55
  try {
53
56
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
54
- var ptr0 = passArray8ToWasm0(input_image, wasm.__wbindgen_malloc);
55
- var len0 = WASM_VECTOR_LEN;
57
+ const ptr0 = passArray8ToWasm0(input_image, wasm.__wbindgen_malloc);
58
+ const len0 = WASM_VECTOR_LEN;
56
59
  wasm.resize(retptr, ptr0, len0, input_width, input_height, output_width, output_height, typ_idx, premultiply, color_space_conversion);
57
60
  var r0 = getInt32Memory0()[retptr / 4 + 0];
58
61
  var r1 = getInt32Memory0()[retptr / 4 + 1];
59
- var v1 = getClampedArrayU8FromWasm0(r0, r1).slice();
60
- wasm.__wbindgen_free(r0, r1 * 1);
61
- return v1;
62
+ var v2 = getClampedArrayU8FromWasm0(r0, r1).slice();
63
+ wasm.__wbindgen_free(r0, r1 * 1, 1);
64
+ return v2;
62
65
  } finally {
63
66
  wasm.__wbindgen_add_to_stack_pointer(16);
64
67
  }
65
68
  }
66
69
 
67
- async function load(module, imports) {
70
+ async function __wbg_load(module, imports) {
68
71
  if (typeof Response === 'function' && module instanceof Response) {
69
72
  if (typeof WebAssembly.instantiateStreaming === 'function') {
70
73
  try {
@@ -95,29 +98,65 @@ async function load(module, imports) {
95
98
  }
96
99
  }
97
100
 
98
- async function init(input) {
101
+ function __wbg_get_imports() {
102
+ const imports = {};
103
+ imports.wbg = {};
104
+
105
+ return imports;
106
+ }
107
+
108
+ function __wbg_init_memory(imports, maybe_memory) {
109
+
110
+ }
111
+
112
+ function __wbg_finalize_init(instance, module) {
113
+ wasm = instance.exports;
114
+ __wbg_init.__wbindgen_wasm_module = module;
115
+ cachedInt32Memory0 = null;
116
+ cachedUint8Memory0 = null;
117
+ cachedUint8ClampedMemory0 = null;
118
+
119
+
120
+ return wasm;
121
+ }
122
+
123
+ function initSync(module) {
124
+ if (wasm !== undefined) return wasm;
125
+
126
+ const imports = __wbg_get_imports();
127
+
128
+ __wbg_init_memory(imports);
129
+
130
+ if (!(module instanceof WebAssembly.Module)) {
131
+ module = new WebAssembly.Module(module);
132
+ }
133
+
134
+ const instance = new WebAssembly.Instance(module, imports);
135
+
136
+ return __wbg_finalize_init(instance, module);
137
+ }
138
+
139
+ async function __wbg_init(input) {
140
+ if (wasm !== undefined) return wasm;
141
+
99
142
  if (typeof input === 'undefined') {
100
143
  input = new URL('squoosh_resize_bg.wasm', import.meta.url);
101
144
  }
102
- const imports = {};
103
-
145
+ const imports = __wbg_get_imports();
104
146
 
105
147
  if (typeof input === 'string' || (typeof Request === 'function' && input instanceof Request) || (typeof URL === 'function' && input instanceof URL)) {
106
148
  input = fetch(input);
107
149
  }
108
150
 
151
+ __wbg_init_memory(imports);
109
152
 
153
+ const { instance, module } = await __wbg_load(await input, imports);
110
154
 
111
- const { instance, module } = await load(await input, imports);
112
-
113
- wasm = instance.exports;
114
- init.__wbindgen_wasm_module = module;
115
-
116
- return wasm;
155
+ return __wbg_finalize_init(instance, module);
117
156
  }
118
157
 
119
- export default init;
120
-
158
+ export { initSync }
159
+ export default __wbg_init;
121
160
  const isServiceWorker = globalThis.ServiceWorkerGlobalScope !== undefined;
122
161
  const isRunningInCloudFlareWorkers = isServiceWorker && typeof self !== 'undefined' && globalThis.caches && globalThis.caches.default !== undefined;
123
162
  const isRunningInNode = typeof process === 'object' && process.release && process.release.name === 'node';
@@ -3,5 +3,5 @@
3
3
  export const memory: WebAssembly.Memory;
4
4
  export function resize(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number): void;
5
5
  export function __wbindgen_add_to_stack_pointer(a: number): number;
6
- export function __wbindgen_malloc(a: number): number;
7
- export function __wbindgen_free(a: number, b: number): void;
6
+ export function __wbindgen_malloc(a: number, b: number): number;
7
+ export function __wbindgen_free(a: number, b: number, c: number): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsquash/resize",
3
- "version": "1.1.1",
3
+ "version": "2.0.0",
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",
@@ -21,7 +21,7 @@
21
21
  "license": "Apache-2.0",
22
22
  "scripts": {
23
23
  "clean": "rm -rf dist",
24
- "build": "npm run clean && tsc && cp -r lib package.json README.md .npmignore ../../LICENSE dist",
24
+ "build": "npm run clean && tsc && cp -r lib package.json README.md .npmignore ../../LICENSE dist && (rm dist/lib/*/pkg/package.json dist/lib/*/pkg/.gitignore || true)",
25
25
  "prepublishOnly": "[[ \"$PWD\" == *'/dist' ]] && exit 0 || (echo 'Please run npm publish from the dist directory' && exit 1)"
26
26
  },
27
27
  "devDependencies": {
Binary file
Binary file