@jsquash/resize 2.0.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.
package/README.md CHANGED
@@ -11,6 +11,9 @@ Composed of:
11
11
  - https://github.com/PistonDevelopers/resize
12
12
  - https://github.com/CryZe/wasmboy-rs/tree/master/hqx
13
13
 
14
+ Addtionally we have added support for the Magic Kernel algorithm for resizing images. This is a Rust implementation of the algorithm.
15
+ - https://github.com/SevInf/magic-kernel-rust
16
+
14
17
  A [jSquash](https://github.com/jamsinclair/jSquash) package. Codecs and supporting code derived from the [Squoosh](https://github.com/GoogleChromeLabs/squoosh) app.
15
18
 
16
19
  ## Installation
@@ -26,7 +29,7 @@ Note: You will need to either manually include the wasm files from the codec dir
26
29
 
27
30
  ### resize(data: ImageData, options: ResizeOptions): Promise<ImageData>
28
31
 
29
- Resizes an ImageData object to the
32
+ Resizes an ImageData object to the specified dimensions.
30
33
 
31
34
  #### data
32
35
  Type: `ImageData`
@@ -37,7 +40,7 @@ Type: `Partial<ResizeOptions> & { width: number, height: number }`
37
40
  The resize options for the output image. [See default values](./meta.ts).
38
41
  - `width` (number) the width to resize the image to
39
42
  - `height` (number) the height to resize the image to
40
- - `method?` (`'triangle'` | `'catrom'` | `'mitchell'` | `'lanczos3'` | `'hqx'`) the algorithm used to resize the image. Defaults to `lanczos3`.
43
+ - `method?` (`'triangle'` | `'catrom'` | `'mitchell'` | `'lanczos3'` | `'hqx'` | `'magicKernel'` | `'magicKernelSharp2013'` | `'magicKernelSharp2021'`) the algorithm used to resize the image. Defaults to `lanczos3`.
41
44
  - `fitMethod?` (`'stretch'` | `'contain'`) whether the image is stretched to fit the dimensions or cropped. Defaults to `stretch`.
42
45
  - `premultiply?` (boolean) Defaults to `true`
43
46
  - `linearRGB?` (boolean) Defaults to `true`
@@ -68,4 +71,10 @@ import resize, { initResize } from '@jsquash/resize';
68
71
  initResize(WASM_MODULE); // The `WASM_MODULE` variable will need to be sourced by yourself and passed as an ArrayBuffer.
69
72
 
70
73
  resize(image, options);
74
+
75
+ // Optionally if you know you are using the hqx method or magicKernel method you can also initialise those modules
76
+ import { initHqx, initMagicKernel } from '@jsquash/resize';
77
+
78
+ initHqx(HQX_WASM_MODULE);
79
+ initMagicKernel(MAGIC_KERNEL_WASM_MODULE);
71
80
  ```
package/index.d.ts CHANGED
@@ -1,8 +1,10 @@
1
1
  import type { WorkerResizeOptions } from './meta.js';
2
2
  import type { InitInput as InitResizeInput } from './lib/resize/pkg/squoosh_resize.js';
3
3
  import type { InitInput as InitHqxInput } from './lib/hqx/pkg/squooshhqx.js';
4
+ import type { InitInput as InitMagicKernelInput } from './lib/magic-kernel/pkg/jsquash_magic_kernel.js';
4
5
  export declare function initResize(moduleOrPath?: InitResizeInput): Promise<unknown>;
5
6
  export declare function initHqx(moduleOrPath?: InitHqxInput): Promise<unknown>;
7
+ export declare function initMagicKernel(moduleOrPath?: InitMagicKernelInput): Promise<unknown>;
6
8
  export default function resize(data: ImageData, overrideOptions: Partial<WorkerResizeOptions> & {
7
9
  width: number;
8
10
  height: number;
package/index.js CHANGED
@@ -1,9 +1,16 @@
1
1
  import { getContainOffsets } from './util.js';
2
2
  import initResizeWasm, { resize as wasmResize, } from './lib/resize/pkg/squoosh_resize.js';
3
3
  import initHqxWasm, { resize as wasmHqx } from './lib/hqx/pkg/squooshhqx.js';
4
+ import initMagicKernelWasm, { resize as wasmMagicKernel, } from './lib/magic-kernel/pkg/jsquash_magic_kernel.js';
4
5
  import { defaultOptions } from './meta.js';
6
+ const MAGIC_KERNEL_METHODS = [
7
+ 'magicKernel',
8
+ 'magicKernelSharp2013',
9
+ 'magicKernelSharp2021',
10
+ ];
5
11
  let resizeWasmReady;
6
12
  let hqxWasmReady;
13
+ let magicKernelWasmReady;
7
14
  export function initResize(moduleOrPath) {
8
15
  if (!resizeWasmReady) {
9
16
  resizeWasmReady = initResizeWasm(moduleOrPath);
@@ -16,9 +23,18 @@ export function initHqx(moduleOrPath) {
16
23
  }
17
24
  return hqxWasmReady;
18
25
  }
26
+ export function initMagicKernel(moduleOrPath) {
27
+ if (!magicKernelWasmReady) {
28
+ magicKernelWasmReady = initMagicKernelWasm(moduleOrPath);
29
+ }
30
+ return magicKernelWasmReady;
31
+ }
19
32
  function optsIsHqxOpts(opts) {
20
33
  return opts.method === 'hqx';
21
34
  }
35
+ function optsIsMagicKernelOpts(opts) {
36
+ return MAGIC_KERNEL_METHODS.includes(opts.method);
37
+ }
22
38
  function crop(data, sx, sy, sw, sh) {
23
39
  const inputPixels = new Uint32Array(data.data.buffer);
24
40
  // Copy within the same buffer for speed and memory efficiency.
@@ -49,6 +65,11 @@ async function hqx(input, opts) {
49
65
  const result = wasmHqx(new Uint32Array(input.data.buffer), input.width, input.height, factor);
50
66
  return new ImageData(new Uint8ClampedArray(result.buffer), input.width * factor, input.height * factor);
51
67
  }
68
+ async function magicKernel(input, opts) {
69
+ await initMagicKernel();
70
+ const result = wasmMagicKernel(new Uint8Array(input.data.buffer), input.width, input.height, opts.width, opts.height, opts.method);
71
+ return result;
72
+ }
52
73
  export default async function resize(data, overrideOptions) {
53
74
  let options = {
54
75
  ...defaultOptions,
@@ -66,6 +87,9 @@ export default async function resize(data, overrideOptions) {
66
87
  const { sx, sy, sw, sh } = getContainOffsets(data.width, data.height, options.width, options.height);
67
88
  input = crop(input, Math.round(sx), Math.round(sy), Math.round(sw), Math.round(sh));
68
89
  }
90
+ if (optsIsMagicKernelOpts(options)) {
91
+ return magicKernel(input, options);
92
+ }
69
93
  const result = wasmResize(new Uint8Array(input.data.buffer), input.width, input.height, options.width, options.height, resizeMethods.indexOf(options.method), options.premultiply, options.linearRGB);
70
94
  return new ImageData(new Uint8ClampedArray(result.buffer), options.width, options.height);
71
95
  }
@@ -0,0 +1,30 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ /**
4
+ * @param {Uint32Array} input_image
5
+ * @param {number} input_width
6
+ * @param {number} input_height
7
+ * @param {number} factor
8
+ * @returns {Uint32Array}
9
+ */
10
+ export function resize(input_image: Uint32Array, input_width: number, input_height: number, factor: number): Uint32Array;
11
+
12
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
13
+
14
+ export interface InitOutput {
15
+ readonly memory: WebAssembly.Memory;
16
+ readonly resize: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
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;
20
+ }
21
+
22
+ /**
23
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
24
+ * for everything else, calls `WebAssembly.instantiate` directly.
25
+ *
26
+ * @param {InitInput | Promise<InitInput>} module_or_path
27
+ *
28
+ * @returns {Promise<InitOutput>}
29
+ */
30
+ export default function init (module_or_path?: InitInput | Promise<InitInput>): Promise<InitOutput>;
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Serhii Tatarintsev
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,5 @@
1
+ # Magic Kernel
2
+
3
+ - Source: https://github.com/SevInf/magic-kernel-rust
4
+ - Version: v0.1.0
5
+ - License: MIT
@@ -0,0 +1,5 @@
1
+ # Magic Kernel
2
+
3
+ - Source: https://github.com/SevInf/magic-kernel-rust
4
+ - Version: v0.1.0
5
+ - License: MIT
@@ -0,0 +1,38 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ export function resize(data: Uint8Array, input_width: number, input_height: number, output_width: number, output_height: number, version: string): ImageData;
5
+
6
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
7
+
8
+ export interface InitOutput {
9
+ readonly memory: WebAssembly.Memory;
10
+ readonly resize: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => any;
11
+ readonly __wbindgen_free: (a: number, b: number, c: number) => void;
12
+ readonly __wbindgen_externrefs: WebAssembly.Table;
13
+ readonly __wbindgen_malloc: (a: number, b: number) => number;
14
+ readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
15
+ readonly __wbindgen_start: () => void;
16
+ }
17
+
18
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
19
+
20
+ /**
21
+ * Instantiates the given `module`, which can either be bytes or
22
+ * a precompiled `WebAssembly.Module`.
23
+ *
24
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
25
+ *
26
+ * @returns {InitOutput}
27
+ */
28
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
29
+
30
+ /**
31
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
32
+ * for everything else, calls `WebAssembly.instantiate` directly.
33
+ *
34
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
35
+ *
36
+ * @returns {Promise<InitOutput>}
37
+ */
38
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
@@ -0,0 +1,237 @@
1
+ let wasm;
2
+
3
+ function getClampedArrayU8FromWasm0(ptr, len) {
4
+ ptr = ptr >>> 0;
5
+ return getUint8ClampedArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
6
+ }
7
+
8
+ let cachedUint8ArrayMemory0 = null;
9
+ function getUint8ArrayMemory0() {
10
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
11
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
12
+ }
13
+ return cachedUint8ArrayMemory0;
14
+ }
15
+
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
+ }
23
+
24
+ function passArray8ToWasm0(arg, malloc) {
25
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
26
+ getUint8ArrayMemory0().set(arg, ptr / 1);
27
+ WASM_VECTOR_LEN = arg.length;
28
+ return ptr;
29
+ }
30
+
31
+ function passStringToWasm0(arg, malloc, realloc) {
32
+ if (realloc === undefined) {
33
+ const buf = cachedTextEncoder.encode(arg);
34
+ const ptr = malloc(buf.length, 1) >>> 0;
35
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
36
+ WASM_VECTOR_LEN = buf.length;
37
+ return ptr;
38
+ }
39
+
40
+ let len = arg.length;
41
+ let ptr = malloc(len, 1) >>> 0;
42
+
43
+ const mem = getUint8ArrayMemory0();
44
+
45
+ let offset = 0;
46
+
47
+ for (; offset < len; offset++) {
48
+ const code = arg.charCodeAt(offset);
49
+ if (code > 0x7F) break;
50
+ mem[ptr + offset] = code;
51
+ }
52
+ if (offset !== len) {
53
+ if (offset !== 0) {
54
+ arg = arg.slice(offset);
55
+ }
56
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
57
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
58
+ const ret = cachedTextEncoder.encodeInto(arg, view);
59
+
60
+ offset += ret.written;
61
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
62
+ }
63
+
64
+ WASM_VECTOR_LEN = offset;
65
+ return ptr;
66
+ }
67
+
68
+ const cachedTextEncoder = new TextEncoder();
69
+
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
+ }
79
+ }
80
+
81
+ let WASM_VECTOR_LEN = 0;
82
+
83
+ /**
84
+ * @param {Uint8Array} data
85
+ * @param {number} input_width
86
+ * @param {number} input_height
87
+ * @param {number} output_width
88
+ * @param {number} output_height
89
+ * @param {string} version
90
+ * @returns {ImageData}
91
+ */
92
+ export function resize(data, input_width, input_height, output_width, output_height, version) {
93
+ const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
94
+ const len0 = WASM_VECTOR_LEN;
95
+ const ptr1 = passStringToWasm0(version, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
96
+ const len1 = WASM_VECTOR_LEN;
97
+ const ret = wasm.resize(ptr0, len0, input_width, input_height, output_width, output_height, ptr1, len1);
98
+ return ret;
99
+ }
100
+
101
+ const EXPECTED_RESPONSE_TYPES = new Set(['basic', 'cors', 'default']);
102
+
103
+ async function __wbg_load(module, imports) {
104
+ if (typeof Response === 'function' && module instanceof Response) {
105
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
106
+ try {
107
+ return await WebAssembly.instantiateStreaming(module, imports);
108
+ } catch (e) {
109
+ const validResponse = module.ok && EXPECTED_RESPONSE_TYPES.has(module.type);
110
+
111
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
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);
113
+
114
+ } else {
115
+ throw e;
116
+ }
117
+ }
118
+ }
119
+
120
+ const bytes = await module.arrayBuffer();
121
+ return await WebAssembly.instantiate(bytes, imports);
122
+ } else {
123
+ const instance = await WebAssembly.instantiate(module, imports);
124
+
125
+ if (instance instanceof WebAssembly.Instance) {
126
+ return { instance, module };
127
+ } else {
128
+ return instance;
129
+ }
130
+ }
131
+ }
132
+
133
+ function __wbg_get_imports() {
134
+ const imports = {};
135
+ imports.wbg = {};
136
+ imports.wbg.__wbg_new_with_owned_u8_clamped_array_and_sh_e8143e95833a3ec3 = function(arg0, arg1, arg2, arg3) {
137
+ var v0 = getClampedArrayU8FromWasm0(arg0, arg1).slice();
138
+ wasm.__wbindgen_free(arg0, arg1 * 1, 1);
139
+ const ret = new ImageData(v0, arg2 >>> 0, arg3 >>> 0);
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);
150
+ };
151
+
152
+ return imports;
153
+ }
154
+
155
+ function __wbg_finalize_init(instance, module) {
156
+ wasm = instance.exports;
157
+ __wbg_init.__wbindgen_wasm_module = module;
158
+ cachedUint8ArrayMemory0 = null;
159
+ cachedUint8ClampedArrayMemory0 = null;
160
+
161
+
162
+ wasm.__wbindgen_start();
163
+ return wasm;
164
+ }
165
+
166
+ function initSync(module) {
167
+ if (wasm !== undefined) return wasm;
168
+
169
+
170
+ if (typeof module !== 'undefined') {
171
+ if (Object.getPrototypeOf(module) === Object.prototype) {
172
+ ({module} = module)
173
+ } else {
174
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
175
+ }
176
+ }
177
+
178
+ const imports = __wbg_get_imports();
179
+ if (!(module instanceof WebAssembly.Module)) {
180
+ module = new WebAssembly.Module(module);
181
+ }
182
+ const instance = new WebAssembly.Instance(module, imports);
183
+ return __wbg_finalize_init(instance, module);
184
+ }
185
+
186
+ async function __wbg_init(module_or_path) {
187
+ if (wasm !== undefined) return wasm;
188
+
189
+
190
+ if (typeof module_or_path !== 'undefined') {
191
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
192
+ ({module_or_path} = module_or_path)
193
+ } else {
194
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
195
+ }
196
+ }
197
+
198
+ if (typeof module_or_path === 'undefined') {
199
+ module_or_path = new URL('jsquash_magic_kernel_bg.wasm', import.meta.url);
200
+ }
201
+ const imports = __wbg_get_imports();
202
+
203
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
204
+ module_or_path = fetch(module_or_path);
205
+ }
206
+
207
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
208
+
209
+ return __wbg_finalize_init(instance, module);
210
+ }
211
+
212
+ export { initSync };
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
+ }
@@ -0,0 +1,9 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ export const memory: WebAssembly.Memory;
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/meta.d.ts CHANGED
@@ -10,7 +10,7 @@
10
10
  * See the License for the specific language governing permissions and
11
11
  * limitations under the License.
12
12
  */
13
- type WorkerResizeMethods = 'triangle' | 'catrom' | 'mitchell' | 'lanczos3' | 'hqx';
13
+ type WorkerResizeMethods = 'triangle' | 'catrom' | 'mitchell' | 'lanczos3' | 'hqx' | 'magicKernel' | 'magicKernelSharp2013' | 'magicKernelSharp2021';
14
14
  export declare const workerResizeMethods: WorkerResizeMethods[];
15
15
  export type Options = WorkerResizeOptions | VectorResizeOptions;
16
16
  export interface ResizeOptionsCommon {
package/meta.js CHANGED
@@ -16,6 +16,9 @@ export const workerResizeMethods = [
16
16
  'mitchell',
17
17
  'lanczos3',
18
18
  'hqx',
19
+ 'magicKernel',
20
+ 'magicKernelSharp2013',
21
+ 'magicKernelSharp2021',
19
22
  ];
20
23
  export const defaultOptions = {
21
24
  // Width and height will always default to the image size.
package/package.json CHANGED
@@ -1,33 +1,34 @@
1
1
  {
2
- "name": "@jsquash/resize",
3
- "version": "2.0.0",
4
- "main": "index.js",
5
- "description": "Wasm image resize methods supporting the browser and V8 environments. Repackaged from Squoosh App.",
6
- "repository": "jamsinclair/jSquash/packages/resize",
7
- "author": {
8
- "name": "Jamie Sinclair",
9
- "email": "jamsinclairnz+npm@gmail.com"
10
- },
11
- "keywords": [
12
- "image",
13
- "resize",
14
- "hqx",
15
- "squoosh",
16
- "wasm",
17
- "webassembly",
18
- "lanczos3",
19
- "crop"
20
- ],
21
- "license": "Apache-2.0",
22
- "scripts": {
23
- "clean": "rm -rf 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
- "prepublishOnly": "[[ \"$PWD\" == *'/dist' ]] && exit 0 || (echo 'Please run npm publish from the dist directory' && exit 1)"
26
- },
27
- "devDependencies": {
28
- "typescript": "^4.4.4"
29
- },
30
- "type": "module",
31
- "sideEffects": false
32
- }
33
-
2
+ "name": "@jsquash/resize",
3
+ "version": "2.1.1",
4
+ "main": "index.js",
5
+ "description": "Wasm image resize methods supporting the browser and V8 environments. Repackaged from Squoosh App.",
6
+ "repository": "jamsinclair/jSquash/packages/resize",
7
+ "author": {
8
+ "name": "Jamie Sinclair",
9
+ "email": "jamsinclairnz+npm@gmail.com"
10
+ },
11
+ "keywords": [
12
+ "image",
13
+ "resize",
14
+ "hqx",
15
+ "squoosh",
16
+ "wasm",
17
+ "webassembly",
18
+ "lanczos3",
19
+ "crop",
20
+ "magic-kernel",
21
+ "magic kernel"
22
+ ],
23
+ "license": "Apache-2.0",
24
+ "scripts": {
25
+ "clean": "rm -rf dist",
26
+ "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)",
27
+ "prepublishOnly": "[[ \"$PWD\" == *'/dist' ]] && exit 0 || (echo 'Please run npm publish from the dist directory' && exit 1)"
28
+ },
29
+ "devDependencies": {
30
+ "typescript": "^4.4.4"
31
+ },
32
+ "type": "module",
33
+ "sideEffects": false
34
+ }
@@ -1,8 +0,0 @@
1
- {
2
- "name": "squooshhqx",
3
- "scripts": {
4
- "build": "../../../../tools/build-rust.sh && npm run patch-pre-script",
5
- "patch-pre-script": "cat pre.js >> pkg/squooshhqx.js"
6
- },
7
- "type": "module"
8
- }
package/lib/hqx/pre.js DELETED
@@ -1,24 +0,0 @@
1
- const isServiceWorker = globalThis.ServiceWorkerGlobalScope !== undefined;
2
- const isRunningInCloudFlareWorkers = isServiceWorker && typeof self !== 'undefined' && globalThis.caches && globalThis.caches.default !== undefined;
3
- const isRunningInNode = typeof process === 'object' && process.release && process.release.name === 'node';
4
-
5
- if (isRunningInCloudFlareWorkers || isRunningInNode) {
6
- if (!globalThis.ImageData) {
7
- // Simple Polyfill for ImageData Object
8
- globalThis.ImageData = class ImageData {
9
- constructor(data, width, height) {
10
- this.data = data;
11
- this.width = width;
12
- this.height = height;
13
- }
14
- };
15
- }
16
-
17
- if (import.meta.url === undefined) {
18
- import.meta.url = 'https://localhost';
19
- }
20
-
21
- if (typeof self !== 'undefined' && self.location === undefined) {
22
- self.location = { href: '' };
23
- }
24
- }
@@ -1,8 +0,0 @@
1
- {
2
- "name": "squoosh-resize",
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
- },
7
- "type": "module"
8
- }
package/lib/resize/pre.js DELETED
@@ -1,24 +0,0 @@
1
- const isServiceWorker = globalThis.ServiceWorkerGlobalScope !== undefined;
2
- const isRunningInCloudFlareWorkers = isServiceWorker && typeof self !== 'undefined' && globalThis.caches && globalThis.caches.default !== undefined;
3
- const isRunningInNode = typeof process === 'object' && process.release && process.release.name === 'node';
4
-
5
- if (isRunningInCloudFlareWorkers || isRunningInNode) {
6
- if (!globalThis.ImageData) {
7
- // Simple Polyfill for ImageData Object
8
- globalThis.ImageData = class ImageData {
9
- constructor(data, width, height) {
10
- this.data = data;
11
- this.width = width;
12
- this.height = height;
13
- }
14
- };
15
- }
16
-
17
- if (import.meta.url === undefined) {
18
- import.meta.url = 'https://localhost';
19
- }
20
-
21
- if (typeof self !== 'undefined' && self.location === undefined) {
22
- self.location = { href: '' };
23
- }
24
- }