@squoosh-kit/resize 0.0.15 → 0.0.17

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,3 +1,3 @@
1
- import{a as E}from"./bridge.browser.mjs";import"./chunk-xrd0djzj.js";var y=null;async function J(v,j,q){if(!y)y=E("worker");return y.resize(v,j,q)}function K(v="worker"){let j=E(v),q=(F,G,H)=>{return j.resize(F,G,H)};return q.terminate=async()=>{await j.terminate()},q}export{J as resize,K as createResizer};
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{resize:(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=1FB4560D622A5BC164756E2164756E21
3
+ //# debugId=75B6A08A6503D4B664756E2164756E21
@@ -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(\n mode: 'worker' | 'client' = 'worker'\n): ResizerFactory {\n const bridge = createBridge(mode);\n\n const resizer = (\n imageData: ImageInput,\n options: ResizeOptions,\n signal?: AbortSignal\n ) => {\n return bridge.resize(imageData, options, signal);\n };\n\n resizer.terminate = async () => {\n await bridge.terminate();\n };\n\n return resizer as ResizerFactory;\n}\n"
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 {\n resize: (\n imageData: ImageInput,\n options: ResizeOptions,\n signal?: AbortSignal\n ) => {\n return bridge.resize(imageData, options, signal);\n },\n terminate: async () => await bridge.terminate(),\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,CAC3B,EAA4B,SACZ,CAChB,IAAM,EAAS,EAAa,CAAI,EAE1B,EAAU,CACd,EACA,EACA,IACG,CACH,OAAO,EAAO,OAAO,EAAW,EAAS,CAAM,GAOjD,OAJA,EAAQ,UAAY,SAAY,CAC9B,MAAM,EAAO,UAAU,GAGlB",
8
- "debugId": "1FB4560D622A5BC164756E2164756E21",
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,CAAC,EAA4B,SAAU,CAClE,IAAM,EAAS,EAAa,CAAI,EAEhC,MAAO,CACL,OAAQ,CACN,EACA,EACA,IACG,CACH,OAAO,EAAO,OAAO,EAAW,EAAS,CAAM,GAEjD,UAAW,SAAY,MAAM,EAAO,UAAU,CAChD",
8
+ "debugId": "75B6A08A6503D4B664756E2164756E21",
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 J(v,j,q){if(!y)y=E("worker");return y.resize(v,j,q)}function K(v="worker"){let j=E(v),q=(F,G,H)=>{return j.resize(F,G,H)};return q.terminate=async()=>{await j.terminate()},q}export{J as resize,K as createResizer};
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{resize:(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=19508812115D7B3764756E2164756E21
4
+ //# debugId=CF438B5DB502964764756E2164756E21
@@ -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(\n mode: 'worker' | 'client' = 'worker'\n): ResizerFactory {\n const bridge = createBridge(mode);\n\n const resizer = (\n imageData: ImageInput,\n options: ResizeOptions,\n signal?: AbortSignal\n ) => {\n return bridge.resize(imageData, options, signal);\n };\n\n resizer.terminate = async () => {\n await bridge.terminate();\n };\n\n return resizer as ResizerFactory;\n}\n"
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 {\n resize: (\n imageData: ImageInput,\n options: ResizeOptions,\n signal?: AbortSignal\n ) => {\n return bridge.resize(imageData, options, signal);\n },\n terminate: async () => await bridge.terminate(),\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,CAC3B,EAA4B,SACZ,CAChB,IAAM,EAAS,EAAa,CAAI,EAE1B,EAAU,CACd,EACA,EACA,IACG,CACH,OAAO,EAAO,OAAO,EAAW,EAAS,CAAM,GAOjD,OAJA,EAAQ,UAAY,SAAY,CAC9B,MAAM,EAAO,UAAU,GAGlB",
8
- "debugId": "19508812115D7B3764756E2164756E21",
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,CAAC,EAA4B,SAAU,CAClE,IAAM,EAAS,EAAa,CAAI,EAEhC,MAAO,CACL,OAAQ,CACN,EACA,EACA,IACG,CACH,OAAO,EAAO,OAAO,EAAW,EAAS,CAAM,GAEjD,UAAW,SAAY,MAAM,EAAO,UAAU,CAChD",
8
+ "debugId": "CF438B5DB502964764756E2164756E21",
9
9
  "names": []
10
10
  }
package/dist/index.d.ts CHANGED
@@ -51,5 +51,8 @@ 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'): ResizerFactory;
54
+ export declare function createResizer(mode?: 'worker' | 'client'): {
55
+ resize: (imageData: ImageInput, options: ResizeOptions, signal?: AbortSignal) => Promise<ImageInput>;
56
+ terminate: () => Promise<void>;
57
+ };
55
58
  //# sourceMappingURL=index.d.ts.map
@@ -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,CAC3B,IAAI,GAAE,QAAQ,GAAG,QAAmB,GACnC,cAAc,CAgBhB"}
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,CAAC,IAAI,GAAE,QAAQ,GAAG,QAAmB;wBAKjD,UAAU,WACZ,aAAa,WACb,WAAW;;EAMzB"}
@@ -1,3 +1,3 @@
1
- var M={};J(M,{resize:()=>K,createResizer:()=>L});module.exports=I(M);var y=null;async function K(v,j,q){if(!y)y=E("worker");return y.resize(v,j,q)}function L(v="worker"){let j=E(v),q=(F,G,H)=>{return j.resize(F,G,H)};return q.terminate=async()=>{await j.terminate()},q}
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{resize:(v,F,G)=>{return j.resize(v,F,G)},terminate:async()=>await j.terminate()}}
2
2
 
3
- //# debugId=E500F0EBCC628D0F64756E2164756E21
3
+ //# debugId=6DF1CBD14565A39364756E2164756E21
@@ -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(\n mode: 'worker' | 'client' = 'worker'\n): ResizerFactory {\n const bridge = createBridge(mode);\n\n const resizer = (\n imageData: ImageInput,\n options: ResizeOptions,\n signal?: AbortSignal\n ) => {\n return bridge.resize(imageData, options, signal);\n };\n\n resizer.terminate = async () => {\n await bridge.terminate();\n };\n\n return resizer as ResizerFactory;\n}\n"
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 {\n resize: (\n imageData: ImageInput,\n options: ResizeOptions,\n signal?: AbortSignal\n ) => {\n return bridge.resize(imageData, options, signal);\n },\n terminate: async () => await bridge.terminate(),\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,CAC3B,EAA4B,SACZ,CAChB,IAAM,EAAS,EAAa,CAAI,EAE1B,EAAU,CACd,EACA,EACA,IACG,CACH,OAAO,EAAO,OAAO,EAAW,EAAS,CAAM,GAOjD,OAJA,EAAQ,UAAY,SAAY,CAC9B,MAAM,EAAO,UAAU,GAGlB",
8
- "debugId": "E500F0EBCC628D0F64756E2164756E21",
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,CAAC,EAA4B,SAAU,CAClE,IAAM,EAAS,EAAa,CAAI,EAEhC,MAAO,CACL,OAAQ,CACN,EACA,EACA,IACG,CACH,OAAO,EAAO,OAAO,EAAW,EAAS,CAAM,GAEjD,UAAW,SAAY,MAAM,EAAO,UAAU,CAChD",
8
+ "debugId": "6DF1CBD14565A39364756E2164756E21",
9
9
  "names": []
10
10
  }
@@ -1,3 +1,3 @@
1
- import{a as E}from"./bridge.node.mjs";import"./chunk-dfj7cgx8.js";var y=null;async function J(v,j,q){if(!y)y=E("worker");return y.resize(v,j,q)}function K(v="worker"){let j=E(v),q=(F,G,H)=>{return j.resize(F,G,H)};return q.terminate=async()=>{await j.terminate()},q}export{J as resize,K as createResizer};
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{resize:(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=38F583F7E607D41664756E2164756E21
3
+ //# debugId=8D5D858313FDA57764756E2164756E21
@@ -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(\n mode: 'worker' | 'client' = 'worker'\n): ResizerFactory {\n const bridge = createBridge(mode);\n\n const resizer = (\n imageData: ImageInput,\n options: ResizeOptions,\n signal?: AbortSignal\n ) => {\n return bridge.resize(imageData, options, signal);\n };\n\n resizer.terminate = async () => {\n await bridge.terminate();\n };\n\n return resizer as ResizerFactory;\n}\n"
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 {\n resize: (\n imageData: ImageInput,\n options: ResizeOptions,\n signal?: AbortSignal\n ) => {\n return bridge.resize(imageData, options, signal);\n },\n terminate: async () => await bridge.terminate(),\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,CAC3B,EAA4B,SACZ,CAChB,IAAM,EAAS,EAAa,CAAI,EAE1B,EAAU,CACd,EACA,EACA,IACG,CACH,OAAO,EAAO,OAAO,EAAW,EAAS,CAAM,GAOjD,OAJA,EAAQ,UAAY,SAAY,CAC9B,MAAM,EAAO,UAAU,GAGlB",
8
- "debugId": "38F583F7E607D41664756E2164756E21",
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,CAAC,EAA4B,SAAU,CAClE,IAAM,EAAS,EAAa,CAAI,EAEhC,MAAO,CACL,OAAQ,CACN,EACA,EACA,IACG,CACH,OAAO,EAAO,OAAO,EAAW,EAAS,CAAM,GAEjD,UAAW,SAAY,MAAM,EAAO,UAAU,CAChD",
8
+ "debugId": "8D5D858313FDA57764756E2164756E21",
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.15",
3
+ "version": "0.0.17",
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.14"
48
+ "@squoosh-kit/runtime": "0.0.16"
49
49
  }
50
50
  }