@squoosh-kit/resize 0.0.17 → 0.0.19
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 +12 -3
- package/dist/index.browser.mjs +2 -2
- package/dist/index.browser.mjs.map +3 -3
- package/dist/index.bun.js +2 -2
- package/dist/index.bun.js.map +3 -3
- package/dist/index.d.ts +1 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.node.cjs +2 -2
- package/dist/index.node.cjs.map +3 -3
- package/dist/index.node.mjs +2 -2
- package/dist/index.node.mjs.map +3 -3
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -2,11 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://badge.fury.io/js/%40squoosh-kit%2Fresize)
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
<img width="2560" height="688" alt="image" src="https://github.com/user-attachments/assets/05ee874f-4f53-4070-9383-77bb083b5d2d" />
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
## Squoosh Kit
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
Squoosh Kit is built on a simple idea: provide a lightweight and modular bridge to the powerful, production-tested codecs from Google's Squoosh project. This package (`@squoosh-kit/resize`) is one of those modules.
|
|
10
|
+
|
|
11
|
+
**Directly from the Source**
|
|
12
|
+
We don't modify the core resize codec. The WebAssembly (`.wasm`) binary is taken directly from the official Squoosh repository builds. This means you get the exact same performance, quality, and reliability you'd expect from Squoosh.
|
|
13
|
+
|
|
14
|
+
**A Thin, Modern Wrapper**
|
|
15
|
+
Our goal is to provide a minimal, modern JavaScript wrapper around the codec. We handle the tricky parts—like loading WASM, managing web workers, and providing a clean, type-safe API—so you can focus on your application. The library is designed to be a thin bridge, not a heavy framework.
|
|
16
|
+
|
|
17
|
+
**Modular by Design**
|
|
18
|
+
We believe you should only install what you need. As a standalone package, `@squoosh-kit/resize` allows you to add high-quality image resizing to your project without pulling in other unrelated image processing tools.
|
|
10
19
|
|
|
11
20
|
## Installation
|
|
12
21
|
|
package/dist/index.browser.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{a as E}from"./bridge.browser.mjs";import"./chunk-xrd0djzj.js";var y=null;async function I(q,j,v){if(!y)y=E("worker");return y.resize(q,j,v)}function J(q="worker"){let j=E(q);return
|
|
1
|
+
import{a as E}from"./bridge.browser.mjs";import"./chunk-xrd0djzj.js";var y=null;async function I(q,j,v){if(!y)y=E("worker");return y.resize(q,j,v)}function J(q="worker"){let j=E(q);return Object.assign((v,F,G)=>{return j.resize(v,F,G)},{terminate:async()=>{await j.terminate()}})}export{I as resize,J as createResizer};
|
|
2
2
|
|
|
3
|
-
//# debugId=
|
|
3
|
+
//# debugId=A8725929192B476864756E2164756E21
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"/**\n * @squoosh-kit/resize public API\n */\n\nimport type { ImageInput } from '@squoosh-kit/runtime';\nimport { createBridge } from './bridge';\nimport type { ResizeOptions } from './types';\n\nexport type { ImageInput, ResizeOptions };\n\n// Global bridge instance for reuse\nlet globalClientBridge: ReturnType<typeof createBridge> | null = null;\n\n/**\n * A resizable image processor that can be reused for multiple operations.\n * Can be terminated to clean up associated resources (especially workers).\n */\nexport type ResizerFactory = ((\n imageData: ImageInput,\n options: ResizeOptions,\n signal?: AbortSignal\n) => Promise<ImageInput>) & {\n /**\n * Terminates the resizer and cleans up resources.\n * Important for worker mode to prevent memory leaks.\n *\n * @example\n * const resizer = createResizer('worker');\n * try {\n * const result = await resizer(imageData, options);\n * } finally {\n * await resizer.terminate();\n * }\n */\n terminate(): Promise<void>;\n};\n\n/**\n * Resizes an image. Uses worker mode for UI responsiveness.\n *\n * @param imageData - The image data to resize.\n * @param options - Resize options.\n * @param signal - (Optional) AbortSignal to cancel the resizing operation.\n * If provided, you can cancel the operation by calling\n * `controller.abort()` on the associated AbortController.\n * If not provided, the operation cannot be cancelled.\n * @returns A Promise resolving to the resized image data.\n *\n * @example\n * // With cancellation support\n * const controller = new AbortController();\n * const result = await resize(imageData, { width: 800 }, controller.signal);\n * setTimeout(() => controller.abort(), 5000);\n *\n * @example\n * // Without cancellation (operation cannot be stopped)\n * const result = await resize(imageData, { width: 800 });\n */\nexport async function resize(\n imageData: ImageInput,\n options: ResizeOptions,\n signal?: AbortSignal\n): Promise<ImageInput> {\n // Use worker mode for UI responsiveness - prevents blocking the main thread\n if (!globalClientBridge) {\n globalClientBridge = createBridge('worker');\n }\n\n return globalClientBridge.resize(imageData, options, signal);\n}\n\n/**\n * Creates a reusable resizer function for a specific execution mode.\n *\n * @param mode - The execution mode, either 'worker' or 'client'.\n * @returns A function that resizes an image with optional AbortSignal.\n */\nexport function createResizer(mode: 'worker' | 'client' = 'worker') {\n const bridge = createBridge(mode);\n\n return
|
|
5
|
+
"/**\n * @squoosh-kit/resize public API\n */\n\nimport type { ImageInput } from '@squoosh-kit/runtime';\nimport { createBridge } from './bridge';\nimport type { ResizeOptions } from './types';\n\nexport type { ImageInput, ResizeOptions };\n\n// Global bridge instance for reuse\nlet globalClientBridge: ReturnType<typeof createBridge> | null = null;\n\n/**\n * A resizable image processor that can be reused for multiple operations.\n * Can be terminated to clean up associated resources (especially workers).\n */\nexport type ResizerFactory = ((\n imageData: ImageInput,\n options: ResizeOptions,\n signal?: AbortSignal\n) => Promise<ImageInput>) & {\n /**\n * Terminates the resizer and cleans up resources.\n * Important for worker mode to prevent memory leaks.\n *\n * @example\n * const resizer = createResizer('worker');\n * try {\n * const result = await resizer(imageData, options);\n * } finally {\n * await resizer.terminate();\n * }\n */\n terminate(): Promise<void>;\n};\n\n/**\n * Resizes an image. Uses worker mode for UI responsiveness.\n *\n * @param imageData - The image data to resize.\n * @param options - Resize options.\n * @param signal - (Optional) AbortSignal to cancel the resizing operation.\n * If provided, you can cancel the operation by calling\n * `controller.abort()` on the associated AbortController.\n * If not provided, the operation cannot be cancelled.\n * @returns A Promise resolving to the resized image data.\n *\n * @example\n * // With cancellation support\n * const controller = new AbortController();\n * const result = await resize(imageData, { width: 800 }, controller.signal);\n * setTimeout(() => controller.abort(), 5000);\n *\n * @example\n * // Without cancellation (operation cannot be stopped)\n * const result = await resize(imageData, { width: 800 });\n */\nexport async function resize(\n imageData: ImageInput,\n options: ResizeOptions,\n signal?: AbortSignal\n): Promise<ImageInput> {\n // Use worker mode for UI responsiveness - prevents blocking the main thread\n if (!globalClientBridge) {\n globalClientBridge = createBridge('worker');\n }\n\n return globalClientBridge.resize(imageData, options, signal);\n}\n\n/**\n * Creates a reusable resizer function for a specific execution mode.\n *\n * @param mode - The execution mode, either 'worker' or 'client'.\n * @returns A function that resizes an image with optional AbortSignal.\n */\nexport function createResizer(\n mode: 'worker' | 'client' = 'worker'\n): ResizerFactory {\n const bridge = createBridge(mode);\n\n return Object.assign(\n (imageData: ImageInput, options: ResizeOptions, signal?: AbortSignal) => {\n return bridge.resize(imageData, options, signal);\n },\n {\n terminate: async () => {\n await bridge.terminate();\n },\n }\n );\n}\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": "2EAWA,FAAI,EAA6D,KA+CjE,eAAsB,CAAM,CAC1B,EACA,EACA,EACqB,CAErB,GAAI,CAAC,EACH,EAAqB,EAAa,QAAQ,EAG5C,OAAO,EAAmB,OAAO,EAAW,EAAS,CAAM,EAStD,SAAS,CAAa,
|
|
8
|
-
"debugId": "
|
|
7
|
+
"mappings": "2EAWA,FAAI,EAA6D,KA+CjE,eAAsB,CAAM,CAC1B,EACA,EACA,EACqB,CAErB,GAAI,CAAC,EACH,EAAqB,EAAa,QAAQ,EAG5C,OAAO,EAAmB,OAAO,EAAW,EAAS,CAAM,EAStD,SAAS,CAAa,CAC3B,EAA4B,SACZ,CAChB,IAAM,EAAS,EAAa,CAAI,EAEhC,OAAO,OAAO,OACZ,CAAC,EAAuB,EAAwB,IAAyB,CACvE,OAAO,EAAO,OAAO,EAAW,EAAS,CAAM,GAEjD,CACE,UAAW,SAAY,CACrB,MAAM,EAAO,UAAU,EAE3B,CACF",
|
|
8
|
+
"debugId": "A8725929192B476864756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
package/dist/index.bun.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{a as E}from"./bridge.bun.js";import"./chunk-6qec3cgc.js";var y=null;async function I(q,j,v){if(!y)y=E("worker");return y.resize(q,j,v)}function J(q="worker"){let j=E(q);return
|
|
2
|
+
import{a as E}from"./bridge.bun.js";import"./chunk-6qec3cgc.js";var y=null;async function I(q,j,v){if(!y)y=E("worker");return y.resize(q,j,v)}function J(q="worker"){let j=E(q);return Object.assign((v,F,G)=>{return j.resize(v,F,G)},{terminate:async()=>{await j.terminate()}})}export{I as resize,J as createResizer};
|
|
3
3
|
|
|
4
|
-
//# debugId=
|
|
4
|
+
//# debugId=1DF93200EB2539BE64756E2164756E21
|
package/dist/index.bun.js.map
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"/**\n * @squoosh-kit/resize public API\n */\n\nimport type { ImageInput } from '@squoosh-kit/runtime';\nimport { createBridge } from './bridge';\nimport type { ResizeOptions } from './types';\n\nexport type { ImageInput, ResizeOptions };\n\n// Global bridge instance for reuse\nlet globalClientBridge: ReturnType<typeof createBridge> | null = null;\n\n/**\n * A resizable image processor that can be reused for multiple operations.\n * Can be terminated to clean up associated resources (especially workers).\n */\nexport type ResizerFactory = ((\n imageData: ImageInput,\n options: ResizeOptions,\n signal?: AbortSignal\n) => Promise<ImageInput>) & {\n /**\n * Terminates the resizer and cleans up resources.\n * Important for worker mode to prevent memory leaks.\n *\n * @example\n * const resizer = createResizer('worker');\n * try {\n * const result = await resizer(imageData, options);\n * } finally {\n * await resizer.terminate();\n * }\n */\n terminate(): Promise<void>;\n};\n\n/**\n * Resizes an image. Uses worker mode for UI responsiveness.\n *\n * @param imageData - The image data to resize.\n * @param options - Resize options.\n * @param signal - (Optional) AbortSignal to cancel the resizing operation.\n * If provided, you can cancel the operation by calling\n * `controller.abort()` on the associated AbortController.\n * If not provided, the operation cannot be cancelled.\n * @returns A Promise resolving to the resized image data.\n *\n * @example\n * // With cancellation support\n * const controller = new AbortController();\n * const result = await resize(imageData, { width: 800 }, controller.signal);\n * setTimeout(() => controller.abort(), 5000);\n *\n * @example\n * // Without cancellation (operation cannot be stopped)\n * const result = await resize(imageData, { width: 800 });\n */\nexport async function resize(\n imageData: ImageInput,\n options: ResizeOptions,\n signal?: AbortSignal\n): Promise<ImageInput> {\n // Use worker mode for UI responsiveness - prevents blocking the main thread\n if (!globalClientBridge) {\n globalClientBridge = createBridge('worker');\n }\n\n return globalClientBridge.resize(imageData, options, signal);\n}\n\n/**\n * Creates a reusable resizer function for a specific execution mode.\n *\n * @param mode - The execution mode, either 'worker' or 'client'.\n * @returns A function that resizes an image with optional AbortSignal.\n */\nexport function createResizer(mode: 'worker' | 'client' = 'worker') {\n const bridge = createBridge(mode);\n\n return
|
|
5
|
+
"/**\n * @squoosh-kit/resize public API\n */\n\nimport type { ImageInput } from '@squoosh-kit/runtime';\nimport { createBridge } from './bridge';\nimport type { ResizeOptions } from './types';\n\nexport type { ImageInput, ResizeOptions };\n\n// Global bridge instance for reuse\nlet globalClientBridge: ReturnType<typeof createBridge> | null = null;\n\n/**\n * A resizable image processor that can be reused for multiple operations.\n * Can be terminated to clean up associated resources (especially workers).\n */\nexport type ResizerFactory = ((\n imageData: ImageInput,\n options: ResizeOptions,\n signal?: AbortSignal\n) => Promise<ImageInput>) & {\n /**\n * Terminates the resizer and cleans up resources.\n * Important for worker mode to prevent memory leaks.\n *\n * @example\n * const resizer = createResizer('worker');\n * try {\n * const result = await resizer(imageData, options);\n * } finally {\n * await resizer.terminate();\n * }\n */\n terminate(): Promise<void>;\n};\n\n/**\n * Resizes an image. Uses worker mode for UI responsiveness.\n *\n * @param imageData - The image data to resize.\n * @param options - Resize options.\n * @param signal - (Optional) AbortSignal to cancel the resizing operation.\n * If provided, you can cancel the operation by calling\n * `controller.abort()` on the associated AbortController.\n * If not provided, the operation cannot be cancelled.\n * @returns A Promise resolving to the resized image data.\n *\n * @example\n * // With cancellation support\n * const controller = new AbortController();\n * const result = await resize(imageData, { width: 800 }, controller.signal);\n * setTimeout(() => controller.abort(), 5000);\n *\n * @example\n * // Without cancellation (operation cannot be stopped)\n * const result = await resize(imageData, { width: 800 });\n */\nexport async function resize(\n imageData: ImageInput,\n options: ResizeOptions,\n signal?: AbortSignal\n): Promise<ImageInput> {\n // Use worker mode for UI responsiveness - prevents blocking the main thread\n if (!globalClientBridge) {\n globalClientBridge = createBridge('worker');\n }\n\n return globalClientBridge.resize(imageData, options, signal);\n}\n\n/**\n * Creates a reusable resizer function for a specific execution mode.\n *\n * @param mode - The execution mode, either 'worker' or 'client'.\n * @returns A function that resizes an image with optional AbortSignal.\n */\nexport function createResizer(\n mode: 'worker' | 'client' = 'worker'\n): ResizerFactory {\n const bridge = createBridge(mode);\n\n return Object.assign(\n (imageData: ImageInput, options: ResizeOptions, signal?: AbortSignal) => {\n return bridge.resize(imageData, options, signal);\n },\n {\n terminate: async () => {\n await bridge.terminate();\n },\n }\n );\n}\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": ";sEAWA,FAAI,EAA6D,KA+CjE,eAAsB,CAAM,CAC1B,EACA,EACA,EACqB,CAErB,GAAI,CAAC,EACH,EAAqB,EAAa,QAAQ,EAG5C,OAAO,EAAmB,OAAO,EAAW,EAAS,CAAM,EAStD,SAAS,CAAa,
|
|
8
|
-
"debugId": "
|
|
7
|
+
"mappings": ";sEAWA,FAAI,EAA6D,KA+CjE,eAAsB,CAAM,CAC1B,EACA,EACA,EACqB,CAErB,GAAI,CAAC,EACH,EAAqB,EAAa,QAAQ,EAG5C,OAAO,EAAmB,OAAO,EAAW,EAAS,CAAM,EAStD,SAAS,CAAa,CAC3B,EAA4B,SACZ,CAChB,IAAM,EAAS,EAAa,CAAI,EAEhC,OAAO,OAAO,OACZ,CAAC,EAAuB,EAAwB,IAAyB,CACvE,OAAO,EAAO,OAAO,EAAW,EAAS,CAAM,GAEjD,CACE,UAAW,SAAY,CACrB,MAAM,EAAO,UAAU,EAE3B,CACF",
|
|
8
|
+
"debugId": "1DF93200EB2539BE64756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -51,8 +51,5 @@ export declare function resize(imageData: ImageInput, options: ResizeOptions, si
|
|
|
51
51
|
* @param mode - The execution mode, either 'worker' or 'client'.
|
|
52
52
|
* @returns A function that resizes an image with optional AbortSignal.
|
|
53
53
|
*/
|
|
54
|
-
export declare function createResizer(mode?: 'worker' | 'client'):
|
|
55
|
-
resize: (imageData: ImageInput, options: ResizeOptions, signal?: AbortSignal) => Promise<ImageInput>;
|
|
56
|
-
terminate: () => Promise<void>;
|
|
57
|
-
};
|
|
54
|
+
export declare function createResizer(mode?: 'worker' | 'client'): ResizerFactory;
|
|
58
55
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAEvD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7C,YAAY,EAAE,UAAU,EAAE,aAAa,EAAE,CAAC;AAK1C;;;GAGG;AACH,MAAM,MAAM,cAAc,GAAG,CAAC,CAC5B,SAAS,EAAE,UAAU,EACrB,OAAO,EAAE,aAAa,EACtB,MAAM,CAAC,EAAE,WAAW,KACjB,OAAO,CAAC,UAAU,CAAC,CAAC,GAAG;IAC1B;;;;;;;;;;;OAWG;IACH,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC5B,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAsB,MAAM,CAC1B,SAAS,EAAE,UAAU,EACrB,OAAO,EAAE,aAAa,EACtB,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,UAAU,CAAC,CAOrB;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAEvD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7C,YAAY,EAAE,UAAU,EAAE,aAAa,EAAE,CAAC;AAK1C;;;GAGG;AACH,MAAM,MAAM,cAAc,GAAG,CAAC,CAC5B,SAAS,EAAE,UAAU,EACrB,OAAO,EAAE,aAAa,EACtB,MAAM,CAAC,EAAE,WAAW,KACjB,OAAO,CAAC,UAAU,CAAC,CAAC,GAAG;IAC1B;;;;;;;;;;;OAWG;IACH,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC5B,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAsB,MAAM,CAC1B,SAAS,EAAE,UAAU,EACrB,OAAO,EAAE,aAAa,EACtB,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,UAAU,CAAC,CAOrB;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAC3B,IAAI,GAAE,QAAQ,GAAG,QAAmB,GACnC,cAAc,CAahB"}
|
package/dist/index.node.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
var L={};I(L,{resize:()=>J,createResizer:()=>K});module.exports=H(L);var y=null;async function J(q,j,v){if(!y)y=E("worker");return y.resize(q,j,v)}function K(q="worker"){let j=E(q);return
|
|
1
|
+
var L={};I(L,{resize:()=>J,createResizer:()=>K});module.exports=H(L);var y=null;async function J(q,j,v){if(!y)y=E("worker");return y.resize(q,j,v)}function K(q="worker"){let j=E(q);return Object.assign((v,F,G)=>{return j.resize(v,F,G)},{terminate:async()=>{await j.terminate()}})}
|
|
2
2
|
|
|
3
|
-
//# debugId=
|
|
3
|
+
//# debugId=1A7C87ECFBF883EF64756E2164756E21
|
package/dist/index.node.cjs.map
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"/**\n * @squoosh-kit/resize public API\n */\n\nimport type { ImageInput } from '@squoosh-kit/runtime';\nimport { createBridge } from './bridge';\nimport type { ResizeOptions } from './types';\n\nexport type { ImageInput, ResizeOptions };\n\n// Global bridge instance for reuse\nlet globalClientBridge: ReturnType<typeof createBridge> | null = null;\n\n/**\n * A resizable image processor that can be reused for multiple operations.\n * Can be terminated to clean up associated resources (especially workers).\n */\nexport type ResizerFactory = ((\n imageData: ImageInput,\n options: ResizeOptions,\n signal?: AbortSignal\n) => Promise<ImageInput>) & {\n /**\n * Terminates the resizer and cleans up resources.\n * Important for worker mode to prevent memory leaks.\n *\n * @example\n * const resizer = createResizer('worker');\n * try {\n * const result = await resizer(imageData, options);\n * } finally {\n * await resizer.terminate();\n * }\n */\n terminate(): Promise<void>;\n};\n\n/**\n * Resizes an image. Uses worker mode for UI responsiveness.\n *\n * @param imageData - The image data to resize.\n * @param options - Resize options.\n * @param signal - (Optional) AbortSignal to cancel the resizing operation.\n * If provided, you can cancel the operation by calling\n * `controller.abort()` on the associated AbortController.\n * If not provided, the operation cannot be cancelled.\n * @returns A Promise resolving to the resized image data.\n *\n * @example\n * // With cancellation support\n * const controller = new AbortController();\n * const result = await resize(imageData, { width: 800 }, controller.signal);\n * setTimeout(() => controller.abort(), 5000);\n *\n * @example\n * // Without cancellation (operation cannot be stopped)\n * const result = await resize(imageData, { width: 800 });\n */\nexport async function resize(\n imageData: ImageInput,\n options: ResizeOptions,\n signal?: AbortSignal\n): Promise<ImageInput> {\n // Use worker mode for UI responsiveness - prevents blocking the main thread\n if (!globalClientBridge) {\n globalClientBridge = createBridge('worker');\n }\n\n return globalClientBridge.resize(imageData, options, signal);\n}\n\n/**\n * Creates a reusable resizer function for a specific execution mode.\n *\n * @param mode - The execution mode, either 'worker' or 'client'.\n * @returns A function that resizes an image with optional AbortSignal.\n */\nexport function createResizer(mode: 'worker' | 'client' = 'worker') {\n const bridge = createBridge(mode);\n\n return
|
|
5
|
+
"/**\n * @squoosh-kit/resize public API\n */\n\nimport type { ImageInput } from '@squoosh-kit/runtime';\nimport { createBridge } from './bridge';\nimport type { ResizeOptions } from './types';\n\nexport type { ImageInput, ResizeOptions };\n\n// Global bridge instance for reuse\nlet globalClientBridge: ReturnType<typeof createBridge> | null = null;\n\n/**\n * A resizable image processor that can be reused for multiple operations.\n * Can be terminated to clean up associated resources (especially workers).\n */\nexport type ResizerFactory = ((\n imageData: ImageInput,\n options: ResizeOptions,\n signal?: AbortSignal\n) => Promise<ImageInput>) & {\n /**\n * Terminates the resizer and cleans up resources.\n * Important for worker mode to prevent memory leaks.\n *\n * @example\n * const resizer = createResizer('worker');\n * try {\n * const result = await resizer(imageData, options);\n * } finally {\n * await resizer.terminate();\n * }\n */\n terminate(): Promise<void>;\n};\n\n/**\n * Resizes an image. Uses worker mode for UI responsiveness.\n *\n * @param imageData - The image data to resize.\n * @param options - Resize options.\n * @param signal - (Optional) AbortSignal to cancel the resizing operation.\n * If provided, you can cancel the operation by calling\n * `controller.abort()` on the associated AbortController.\n * If not provided, the operation cannot be cancelled.\n * @returns A Promise resolving to the resized image data.\n *\n * @example\n * // With cancellation support\n * const controller = new AbortController();\n * const result = await resize(imageData, { width: 800 }, controller.signal);\n * setTimeout(() => controller.abort(), 5000);\n *\n * @example\n * // Without cancellation (operation cannot be stopped)\n * const result = await resize(imageData, { width: 800 });\n */\nexport async function resize(\n imageData: ImageInput,\n options: ResizeOptions,\n signal?: AbortSignal\n): Promise<ImageInput> {\n // Use worker mode for UI responsiveness - prevents blocking the main thread\n if (!globalClientBridge) {\n globalClientBridge = createBridge('worker');\n }\n\n return globalClientBridge.resize(imageData, options, signal);\n}\n\n/**\n * Creates a reusable resizer function for a specific execution mode.\n *\n * @param mode - The execution mode, either 'worker' or 'client'.\n * @returns A function that resizes an image with optional AbortSignal.\n */\nexport function createResizer(\n mode: 'worker' | 'client' = 'worker'\n): ResizerFactory {\n const bridge = createBridge(mode);\n\n return Object.assign(\n (imageData: ImageInput, options: ResizeOptions, signal?: AbortSignal) => {\n return bridge.resize(imageData, options, signal);\n },\n {\n terminate: async () => {\n await bridge.terminate();\n },\n }\n );\n}\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": "qEAWA,IAAI,EAA6D,KA+CjE,eAAsB,CAAM,CAC1B,EACA,EACA,EACqB,CAErB,GAAI,CAAC,EACH,EAAqB,EAAa,QAAQ,EAG5C,OAAO,EAAmB,OAAO,EAAW,EAAS,CAAM,EAStD,SAAS,CAAa,
|
|
8
|
-
"debugId": "
|
|
7
|
+
"mappings": "qEAWA,IAAI,EAA6D,KA+CjE,eAAsB,CAAM,CAC1B,EACA,EACA,EACqB,CAErB,GAAI,CAAC,EACH,EAAqB,EAAa,QAAQ,EAG5C,OAAO,EAAmB,OAAO,EAAW,EAAS,CAAM,EAStD,SAAS,CAAa,CAC3B,EAA4B,SACZ,CAChB,IAAM,EAAS,EAAa,CAAI,EAEhC,OAAO,OAAO,OACZ,CAAC,EAAuB,EAAwB,IAAyB,CACvE,OAAO,EAAO,OAAO,EAAW,EAAS,CAAM,GAEjD,CACE,UAAW,SAAY,CACrB,MAAM,EAAO,UAAU,EAE3B,CACF",
|
|
8
|
+
"debugId": "1A7C87ECFBF883EF64756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
package/dist/index.node.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{a as E}from"./bridge.node.mjs";import"./chunk-dfj7cgx8.js";var y=null;async function I(q,j,v){if(!y)y=E("worker");return y.resize(q,j,v)}function J(q="worker"){let j=E(q);return
|
|
1
|
+
import{a as E}from"./bridge.node.mjs";import"./chunk-dfj7cgx8.js";var y=null;async function I(q,j,v){if(!y)y=E("worker");return y.resize(q,j,v)}function J(q="worker"){let j=E(q);return Object.assign((v,F,G)=>{return j.resize(v,F,G)},{terminate:async()=>{await j.terminate()}})}export{I as resize,J as createResizer};
|
|
2
2
|
|
|
3
|
-
//# debugId=
|
|
3
|
+
//# debugId=F7701D7DB05C39C764756E2164756E21
|
package/dist/index.node.mjs.map
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"/**\n * @squoosh-kit/resize public API\n */\n\nimport type { ImageInput } from '@squoosh-kit/runtime';\nimport { createBridge } from './bridge';\nimport type { ResizeOptions } from './types';\n\nexport type { ImageInput, ResizeOptions };\n\n// Global bridge instance for reuse\nlet globalClientBridge: ReturnType<typeof createBridge> | null = null;\n\n/**\n * A resizable image processor that can be reused for multiple operations.\n * Can be terminated to clean up associated resources (especially workers).\n */\nexport type ResizerFactory = ((\n imageData: ImageInput,\n options: ResizeOptions,\n signal?: AbortSignal\n) => Promise<ImageInput>) & {\n /**\n * Terminates the resizer and cleans up resources.\n * Important for worker mode to prevent memory leaks.\n *\n * @example\n * const resizer = createResizer('worker');\n * try {\n * const result = await resizer(imageData, options);\n * } finally {\n * await resizer.terminate();\n * }\n */\n terminate(): Promise<void>;\n};\n\n/**\n * Resizes an image. Uses worker mode for UI responsiveness.\n *\n * @param imageData - The image data to resize.\n * @param options - Resize options.\n * @param signal - (Optional) AbortSignal to cancel the resizing operation.\n * If provided, you can cancel the operation by calling\n * `controller.abort()` on the associated AbortController.\n * If not provided, the operation cannot be cancelled.\n * @returns A Promise resolving to the resized image data.\n *\n * @example\n * // With cancellation support\n * const controller = new AbortController();\n * const result = await resize(imageData, { width: 800 }, controller.signal);\n * setTimeout(() => controller.abort(), 5000);\n *\n * @example\n * // Without cancellation (operation cannot be stopped)\n * const result = await resize(imageData, { width: 800 });\n */\nexport async function resize(\n imageData: ImageInput,\n options: ResizeOptions,\n signal?: AbortSignal\n): Promise<ImageInput> {\n // Use worker mode for UI responsiveness - prevents blocking the main thread\n if (!globalClientBridge) {\n globalClientBridge = createBridge('worker');\n }\n\n return globalClientBridge.resize(imageData, options, signal);\n}\n\n/**\n * Creates a reusable resizer function for a specific execution mode.\n *\n * @param mode - The execution mode, either 'worker' or 'client'.\n * @returns A function that resizes an image with optional AbortSignal.\n */\nexport function createResizer(mode: 'worker' | 'client' = 'worker') {\n const bridge = createBridge(mode);\n\n return
|
|
5
|
+
"/**\n * @squoosh-kit/resize public API\n */\n\nimport type { ImageInput } from '@squoosh-kit/runtime';\nimport { createBridge } from './bridge';\nimport type { ResizeOptions } from './types';\n\nexport type { ImageInput, ResizeOptions };\n\n// Global bridge instance for reuse\nlet globalClientBridge: ReturnType<typeof createBridge> | null = null;\n\n/**\n * A resizable image processor that can be reused for multiple operations.\n * Can be terminated to clean up associated resources (especially workers).\n */\nexport type ResizerFactory = ((\n imageData: ImageInput,\n options: ResizeOptions,\n signal?: AbortSignal\n) => Promise<ImageInput>) & {\n /**\n * Terminates the resizer and cleans up resources.\n * Important for worker mode to prevent memory leaks.\n *\n * @example\n * const resizer = createResizer('worker');\n * try {\n * const result = await resizer(imageData, options);\n * } finally {\n * await resizer.terminate();\n * }\n */\n terminate(): Promise<void>;\n};\n\n/**\n * Resizes an image. Uses worker mode for UI responsiveness.\n *\n * @param imageData - The image data to resize.\n * @param options - Resize options.\n * @param signal - (Optional) AbortSignal to cancel the resizing operation.\n * If provided, you can cancel the operation by calling\n * `controller.abort()` on the associated AbortController.\n * If not provided, the operation cannot be cancelled.\n * @returns A Promise resolving to the resized image data.\n *\n * @example\n * // With cancellation support\n * const controller = new AbortController();\n * const result = await resize(imageData, { width: 800 }, controller.signal);\n * setTimeout(() => controller.abort(), 5000);\n *\n * @example\n * // Without cancellation (operation cannot be stopped)\n * const result = await resize(imageData, { width: 800 });\n */\nexport async function resize(\n imageData: ImageInput,\n options: ResizeOptions,\n signal?: AbortSignal\n): Promise<ImageInput> {\n // Use worker mode for UI responsiveness - prevents blocking the main thread\n if (!globalClientBridge) {\n globalClientBridge = createBridge('worker');\n }\n\n return globalClientBridge.resize(imageData, options, signal);\n}\n\n/**\n * Creates a reusable resizer function for a specific execution mode.\n *\n * @param mode - The execution mode, either 'worker' or 'client'.\n * @returns A function that resizes an image with optional AbortSignal.\n */\nexport function createResizer(\n mode: 'worker' | 'client' = 'worker'\n): ResizerFactory {\n const bridge = createBridge(mode);\n\n return Object.assign(\n (imageData: ImageInput, options: ResizeOptions, signal?: AbortSignal) => {\n return bridge.resize(imageData, options, signal);\n },\n {\n terminate: async () => {\n await bridge.terminate();\n },\n }\n );\n}\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": "wEAWA,FAAI,EAA6D,KA+CjE,eAAsB,CAAM,CAC1B,EACA,EACA,EACqB,CAErB,GAAI,CAAC,EACH,EAAqB,EAAa,QAAQ,EAG5C,OAAO,EAAmB,OAAO,EAAW,EAAS,CAAM,EAStD,SAAS,CAAa,
|
|
8
|
-
"debugId": "
|
|
7
|
+
"mappings": "wEAWA,FAAI,EAA6D,KA+CjE,eAAsB,CAAM,CAC1B,EACA,EACA,EACqB,CAErB,GAAI,CAAC,EACH,EAAqB,EAAa,QAAQ,EAG5C,OAAO,EAAmB,OAAO,EAAW,EAAS,CAAM,EAStD,SAAS,CAAa,CAC3B,EAA4B,SACZ,CAChB,IAAM,EAAS,EAAa,CAAI,EAEhC,OAAO,OAAO,OACZ,CAAC,EAAuB,EAAwB,IAAyB,CACvE,OAAO,EAAO,OAAO,EAAW,EAAS,CAAM,GAEjD,CACE,UAAW,SAAY,CACrB,MAAM,EAAO,UAAU,EAE3B,CACF",
|
|
8
|
+
"debugId": "F7701D7DB05C39C764756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@squoosh-kit/resize",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.19",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Image resize module for squoosh-kit.",
|
|
6
6
|
"author": "Bartosz Nowak <bnowak008@gmail.com>",
|
|
@@ -45,6 +45,6 @@
|
|
|
45
45
|
"test": "bun test"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@squoosh-kit/runtime": "0.0.
|
|
48
|
+
"@squoosh-kit/runtime": "0.0.18"
|
|
49
49
|
}
|
|
50
50
|
}
|