@squoosh-kit/webp 0.0.15 → 0.0.16

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.
@@ -2,9 +2,9 @@
2
2
  "version": 3,
3
3
  "sources": ["../src/index.ts"],
4
4
  "sourcesContent": [
5
- "/**\n * @squoosh-kit/webp public API\n */\n\nimport type { ImageInput } from '@squoosh-kit/runtime';\nimport { createBridge } from './bridge';\nimport type { EncodeInputOptions } from './types';\n\nexport type { ImageInput, EncodeInputOptions };\n\n// Global bridge instance for reuse\nlet globalClientBridge: ReturnType<typeof createBridge> | null = null;\n\n/**\n * A WebP image encoder that can be reused for multiple operations.\n * Can be terminated to clean up associated resources (especially workers).\n */\nexport type WebpEncoderFactory = ((\n imageData: ImageInput,\n options?: EncodeInputOptions,\n signal?: AbortSignal\n) => Promise<Uint8Array>) & {\n /**\n * Terminates the encoder and cleans up resources.\n * Important for worker mode to prevent memory leaks.\n *\n * @example\n * const encoder = createWebpEncoder('worker');\n * try {\n * const result = await encoder(imageData, options);\n * } finally {\n * await encoder.terminate();\n * }\n */\n terminate(): Promise<void>;\n};\n\n/**\n * Encodes an image to WebP format. Uses worker mode for UI responsiveness.\n *\n * @param imageData - The image data to encode.\n * @param options - WebP encoding options.\n * @param signal - (Optional) AbortSignal to cancel the encoding 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 encoded WebP data as a Uint8Array.\n *\n * @example\n * // With cancellation support\n * const controller = new AbortController();\n * const result = await encode(imageData, { quality: 85 }, controller.signal);\n * setTimeout(() => controller.abort(), 5000);\n *\n * @example\n * // Without cancellation (operation cannot be stopped)\n * const result = await encode(imageData, { quality: 85 });\n */\nexport async function encode(\n imageData: ImageInput,\n options?: EncodeInputOptions,\n signal?: AbortSignal\n): Promise<Uint8Array> {\n // Use worker mode for UI responsiveness - prevents blocking the main thread\n if (!globalClientBridge) {\n globalClientBridge = createBridge('worker');\n }\n\n return globalClientBridge.encode(imageData, options, signal);\n}\n\n/**\n * Creates a reusable WebP encoder function for a specific execution mode.\n * This is useful for processing multiple images without the overhead of\n * creating a new worker or client instance each time.\n *\n * @param mode - The execution mode, either 'worker' or 'client'.\n * @returns A function that encodes an image to WebP format with optional AbortSignal.\n */\nexport function createWebpEncoder(\n mode: 'worker' | 'client' = 'worker'\n): WebpEncoderFactory {\n const bridge = createBridge(mode);\n\n const encoder = (\n imageData: ImageInput,\n options?: EncodeInputOptions,\n signal?: AbortSignal\n ) => {\n return bridge.encode(imageData, options, signal);\n };\n\n encoder.terminate = async () => {\n await bridge.terminate();\n };\n\n return encoder as WebpEncoderFactory;\n}\n"
5
+ "/**\n * @squoosh-kit/webp public API\n */\n\nimport type { ImageInput } from '@squoosh-kit/runtime';\nimport { createBridge } from './bridge';\nimport type { EncodeInputOptions } from './types';\n\nexport type { ImageInput, EncodeInputOptions };\n\n// Global bridge instance for reuse\nlet globalClientBridge: ReturnType<typeof createBridge> | null = null;\n\n/**\n * A WebP image encoder that can be reused for multiple operations.\n * Can be terminated to clean up associated resources (especially workers).\n */\nexport type WebpEncoderFactory = ((\n imageData: ImageInput,\n options?: EncodeInputOptions,\n signal?: AbortSignal\n) => Promise<Uint8Array>) & {\n /**\n * Terminates the encoder and cleans up resources.\n * Important for worker mode to prevent memory leaks.\n *\n * @example\n * const encoder = createWebpEncoder('worker');\n * try {\n * const result = await encoder(imageData, options);\n * } finally {\n * await encoder.terminate();\n * }\n */\n terminate(): Promise<void>;\n};\n\n/**\n * Encodes an image to WebP format. Uses worker mode for UI responsiveness.\n *\n * @param imageData - The image data to encode.\n * @param options - WebP encoding options.\n * @param signal - (Optional) AbortSignal to cancel the encoding 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 encoded WebP data as a Uint8Array.\n *\n * @example\n * // With cancellation support\n * const controller = new AbortController();\n * const result = await encode(imageData, { quality: 85 }, controller.signal);\n * setTimeout(() => controller.abort(), 5000);\n *\n * @example\n * // Without cancellation (operation cannot be stopped)\n * const result = await encode(imageData, { quality: 85 });\n */\nexport async function encode(\n imageData: ImageInput,\n options?: EncodeInputOptions,\n signal?: AbortSignal\n): Promise<Uint8Array> {\n // Use worker mode for UI responsiveness - prevents blocking the main thread\n if (!globalClientBridge) {\n globalClientBridge = createBridge('worker');\n }\n\n return globalClientBridge.encode(imageData, options, signal);\n}\n\n/**\n * Creates a reusable WebP encoder function for a specific execution mode.\n * This is useful for processing multiple images without the overhead of\n * creating a new worker or client instance each time.\n *\n * @param mode - The execution mode, either 'worker' or 'client'.\n * @returns A function that encodes an image to WebP format with optional AbortSignal.\n */\nexport function createWebpEncoder(mode: 'worker' | 'client' = 'worker') {\n const bridge = createBridge(mode);\n\n const encoder = (\n imageData: ImageInput,\n options?: EncodeInputOptions,\n signal?: AbortSignal\n ) => {\n return bridge.encode(imageData, options, signal);\n };\n\n encoder.terminate = async () => {\n await bridge.terminate();\n };\n\n return encoder;\n}\n"
6
6
  ],
7
- "mappings": "6GAWA,FAAI,JAA6D,KA+CjE,eAAsB,CAAM,CAC1B,EACA,EACA,EACqB,CAErB,GAAI,CAAC,EACH,EAAqB,EAAa,QAAQ,EAG5C,OAAO,EAAmB,OAAO,EAAW,EAAS,CAAM,EAWtD,SAAS,CAAiB,CAC/B,EAA4B,SACR,CACpB,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",
7
+ "mappings": "6GAWA,FAAI,JAA6D,KA+CjE,eAAsB,CAAM,CAC1B,EACA,EACA,EACqB,CAErB,GAAI,CAAC,EACH,EAAqB,EAAa,QAAQ,EAG5C,OAAO,EAAmB,OAAO,EAAW,EAAS,CAAM,EAWtD,SAAS,CAAiB,CAAC,EAA4B,SAAU,CACtE,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
8
  "debugId": "EC0097D47BB87B3E64756E2164756E21",
9
9
  "names": []
10
10
  }
@@ -2,9 +2,9 @@
2
2
  "version": 3,
3
3
  "sources": ["../src/index.ts"],
4
4
  "sourcesContent": [
5
- "/**\n * @squoosh-kit/webp public API\n */\n\nimport type { ImageInput } from '@squoosh-kit/runtime';\nimport { createBridge } from './bridge';\nimport type { EncodeInputOptions } from './types';\n\nexport type { ImageInput, EncodeInputOptions };\n\n// Global bridge instance for reuse\nlet globalClientBridge: ReturnType<typeof createBridge> | null = null;\n\n/**\n * A WebP image encoder that can be reused for multiple operations.\n * Can be terminated to clean up associated resources (especially workers).\n */\nexport type WebpEncoderFactory = ((\n imageData: ImageInput,\n options?: EncodeInputOptions,\n signal?: AbortSignal\n) => Promise<Uint8Array>) & {\n /**\n * Terminates the encoder and cleans up resources.\n * Important for worker mode to prevent memory leaks.\n *\n * @example\n * const encoder = createWebpEncoder('worker');\n * try {\n * const result = await encoder(imageData, options);\n * } finally {\n * await encoder.terminate();\n * }\n */\n terminate(): Promise<void>;\n};\n\n/**\n * Encodes an image to WebP format. Uses worker mode for UI responsiveness.\n *\n * @param imageData - The image data to encode.\n * @param options - WebP encoding options.\n * @param signal - (Optional) AbortSignal to cancel the encoding 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 encoded WebP data as a Uint8Array.\n *\n * @example\n * // With cancellation support\n * const controller = new AbortController();\n * const result = await encode(imageData, { quality: 85 }, controller.signal);\n * setTimeout(() => controller.abort(), 5000);\n *\n * @example\n * // Without cancellation (operation cannot be stopped)\n * const result = await encode(imageData, { quality: 85 });\n */\nexport async function encode(\n imageData: ImageInput,\n options?: EncodeInputOptions,\n signal?: AbortSignal\n): Promise<Uint8Array> {\n // Use worker mode for UI responsiveness - prevents blocking the main thread\n if (!globalClientBridge) {\n globalClientBridge = createBridge('worker');\n }\n\n return globalClientBridge.encode(imageData, options, signal);\n}\n\n/**\n * Creates a reusable WebP encoder function for a specific execution mode.\n * This is useful for processing multiple images without the overhead of\n * creating a new worker or client instance each time.\n *\n * @param mode - The execution mode, either 'worker' or 'client'.\n * @returns A function that encodes an image to WebP format with optional AbortSignal.\n */\nexport function createWebpEncoder(\n mode: 'worker' | 'client' = 'worker'\n): WebpEncoderFactory {\n const bridge = createBridge(mode);\n\n const encoder = (\n imageData: ImageInput,\n options?: EncodeInputOptions,\n signal?: AbortSignal\n ) => {\n return bridge.encode(imageData, options, signal);\n };\n\n encoder.terminate = async () => {\n await bridge.terminate();\n };\n\n return encoder as WebpEncoderFactory;\n}\n"
5
+ "/**\n * @squoosh-kit/webp public API\n */\n\nimport type { ImageInput } from '@squoosh-kit/runtime';\nimport { createBridge } from './bridge';\nimport type { EncodeInputOptions } from './types';\n\nexport type { ImageInput, EncodeInputOptions };\n\n// Global bridge instance for reuse\nlet globalClientBridge: ReturnType<typeof createBridge> | null = null;\n\n/**\n * A WebP image encoder that can be reused for multiple operations.\n * Can be terminated to clean up associated resources (especially workers).\n */\nexport type WebpEncoderFactory = ((\n imageData: ImageInput,\n options?: EncodeInputOptions,\n signal?: AbortSignal\n) => Promise<Uint8Array>) & {\n /**\n * Terminates the encoder and cleans up resources.\n * Important for worker mode to prevent memory leaks.\n *\n * @example\n * const encoder = createWebpEncoder('worker');\n * try {\n * const result = await encoder(imageData, options);\n * } finally {\n * await encoder.terminate();\n * }\n */\n terminate(): Promise<void>;\n};\n\n/**\n * Encodes an image to WebP format. Uses worker mode for UI responsiveness.\n *\n * @param imageData - The image data to encode.\n * @param options - WebP encoding options.\n * @param signal - (Optional) AbortSignal to cancel the encoding 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 encoded WebP data as a Uint8Array.\n *\n * @example\n * // With cancellation support\n * const controller = new AbortController();\n * const result = await encode(imageData, { quality: 85 }, controller.signal);\n * setTimeout(() => controller.abort(), 5000);\n *\n * @example\n * // Without cancellation (operation cannot be stopped)\n * const result = await encode(imageData, { quality: 85 });\n */\nexport async function encode(\n imageData: ImageInput,\n options?: EncodeInputOptions,\n signal?: AbortSignal\n): Promise<Uint8Array> {\n // Use worker mode for UI responsiveness - prevents blocking the main thread\n if (!globalClientBridge) {\n globalClientBridge = createBridge('worker');\n }\n\n return globalClientBridge.encode(imageData, options, signal);\n}\n\n/**\n * Creates a reusable WebP encoder function for a specific execution mode.\n * This is useful for processing multiple images without the overhead of\n * creating a new worker or client instance each time.\n *\n * @param mode - The execution mode, either 'worker' or 'client'.\n * @returns A function that encodes an image to WebP format with optional AbortSignal.\n */\nexport function createWebpEncoder(mode: 'worker' | 'client' = 'worker') {\n const bridge = createBridge(mode);\n\n const encoder = (\n imageData: ImageInput,\n options?: EncodeInputOptions,\n signal?: AbortSignal\n ) => {\n return bridge.encode(imageData, options, signal);\n };\n\n encoder.terminate = async () => {\n await bridge.terminate();\n };\n\n return encoder;\n}\n"
6
6
  ],
7
- "mappings": ";wGAWA,FAAI,JAA6D,KA+CjE,eAAsB,CAAM,CAC1B,EACA,EACA,EACqB,CAErB,GAAI,CAAC,EACH,EAAqB,EAAa,QAAQ,EAG5C,OAAO,EAAmB,OAAO,EAAW,EAAS,CAAM,EAWtD,SAAS,CAAiB,CAC/B,EAA4B,SACR,CACpB,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",
7
+ "mappings": ";wGAWA,FAAI,JAA6D,KA+CjE,eAAsB,CAAM,CAC1B,EACA,EACA,EACqB,CAErB,GAAI,CAAC,EACH,EAAqB,EAAa,QAAQ,EAG5C,OAAO,EAAmB,OAAO,EAAW,EAAS,CAAM,EAWtD,SAAS,CAAiB,CAAC,EAA4B,SAAU,CACtE,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
8
  "debugId": "1259714B0D7D63E564756E2164756E21",
9
9
  "names": []
10
10
  }
package/dist/index.d.ts CHANGED
@@ -53,5 +53,8 @@ export declare function encode(imageData: ImageInput, options?: EncodeInputOptio
53
53
  * @param mode - The execution mode, either 'worker' or 'client'.
54
54
  * @returns A function that encodes an image to WebP format with optional AbortSignal.
55
55
  */
56
- export declare function createWebpEncoder(mode?: 'worker' | 'client'): WebpEncoderFactory;
56
+ export declare function createWebpEncoder(mode?: 'worker' | 'client'): {
57
+ (imageData: ImageInput, options?: EncodeInputOptions, signal?: AbortSignal): Promise<Uint8Array<ArrayBufferLike>>;
58
+ terminate(): Promise<void>;
59
+ };
57
60
  //# 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,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAElD,YAAY,EAAE,UAAU,EAAE,kBAAkB,EAAE,CAAC;AAK/C;;;GAGG;AACH,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAChC,SAAS,EAAE,UAAU,EACrB,OAAO,CAAC,EAAE,kBAAkB,EAC5B,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,CAAC,EAAE,kBAAkB,EAC5B,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,UAAU,CAAC,CAOrB;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,GAAE,QAAQ,GAAG,QAAmB,GACnC,kBAAkB,CAgBpB"}
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,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAElD,YAAY,EAAE,UAAU,EAAE,kBAAkB,EAAE,CAAC;AAK/C;;;GAGG;AACH,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAChC,SAAS,EAAE,UAAU,EACrB,OAAO,CAAC,EAAE,kBAAkB,EAC5B,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,CAAC,EAAE,kBAAkB,EAC5B,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,UAAU,CAAC,CAOrB;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,GAAE,QAAQ,GAAG,QAAmB;gBAIvD,UAAU,YACX,kBAAkB,WACnB,WAAW;;EAUvB"}
@@ -2,9 +2,9 @@
2
2
  "version": 3,
3
3
  "sources": ["../src/index.ts"],
4
4
  "sourcesContent": [
5
- "/**\n * @squoosh-kit/webp public API\n */\n\nimport type { ImageInput } from '@squoosh-kit/runtime';\nimport { createBridge } from './bridge';\nimport type { EncodeInputOptions } from './types';\n\nexport type { ImageInput, EncodeInputOptions };\n\n// Global bridge instance for reuse\nlet globalClientBridge: ReturnType<typeof createBridge> | null = null;\n\n/**\n * A WebP image encoder that can be reused for multiple operations.\n * Can be terminated to clean up associated resources (especially workers).\n */\nexport type WebpEncoderFactory = ((\n imageData: ImageInput,\n options?: EncodeInputOptions,\n signal?: AbortSignal\n) => Promise<Uint8Array>) & {\n /**\n * Terminates the encoder and cleans up resources.\n * Important for worker mode to prevent memory leaks.\n *\n * @example\n * const encoder = createWebpEncoder('worker');\n * try {\n * const result = await encoder(imageData, options);\n * } finally {\n * await encoder.terminate();\n * }\n */\n terminate(): Promise<void>;\n};\n\n/**\n * Encodes an image to WebP format. Uses worker mode for UI responsiveness.\n *\n * @param imageData - The image data to encode.\n * @param options - WebP encoding options.\n * @param signal - (Optional) AbortSignal to cancel the encoding 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 encoded WebP data as a Uint8Array.\n *\n * @example\n * // With cancellation support\n * const controller = new AbortController();\n * const result = await encode(imageData, { quality: 85 }, controller.signal);\n * setTimeout(() => controller.abort(), 5000);\n *\n * @example\n * // Without cancellation (operation cannot be stopped)\n * const result = await encode(imageData, { quality: 85 });\n */\nexport async function encode(\n imageData: ImageInput,\n options?: EncodeInputOptions,\n signal?: AbortSignal\n): Promise<Uint8Array> {\n // Use worker mode for UI responsiveness - prevents blocking the main thread\n if (!globalClientBridge) {\n globalClientBridge = createBridge('worker');\n }\n\n return globalClientBridge.encode(imageData, options, signal);\n}\n\n/**\n * Creates a reusable WebP encoder function for a specific execution mode.\n * This is useful for processing multiple images without the overhead of\n * creating a new worker or client instance each time.\n *\n * @param mode - The execution mode, either 'worker' or 'client'.\n * @returns A function that encodes an image to WebP format with optional AbortSignal.\n */\nexport function createWebpEncoder(\n mode: 'worker' | 'client' = 'worker'\n): WebpEncoderFactory {\n const bridge = createBridge(mode);\n\n const encoder = (\n imageData: ImageInput,\n options?: EncodeInputOptions,\n signal?: AbortSignal\n ) => {\n return bridge.encode(imageData, options, signal);\n };\n\n encoder.terminate = async () => {\n await bridge.terminate();\n };\n\n return encoder as WebpEncoderFactory;\n}\n"
5
+ "/**\n * @squoosh-kit/webp public API\n */\n\nimport type { ImageInput } from '@squoosh-kit/runtime';\nimport { createBridge } from './bridge';\nimport type { EncodeInputOptions } from './types';\n\nexport type { ImageInput, EncodeInputOptions };\n\n// Global bridge instance for reuse\nlet globalClientBridge: ReturnType<typeof createBridge> | null = null;\n\n/**\n * A WebP image encoder that can be reused for multiple operations.\n * Can be terminated to clean up associated resources (especially workers).\n */\nexport type WebpEncoderFactory = ((\n imageData: ImageInput,\n options?: EncodeInputOptions,\n signal?: AbortSignal\n) => Promise<Uint8Array>) & {\n /**\n * Terminates the encoder and cleans up resources.\n * Important for worker mode to prevent memory leaks.\n *\n * @example\n * const encoder = createWebpEncoder('worker');\n * try {\n * const result = await encoder(imageData, options);\n * } finally {\n * await encoder.terminate();\n * }\n */\n terminate(): Promise<void>;\n};\n\n/**\n * Encodes an image to WebP format. Uses worker mode for UI responsiveness.\n *\n * @param imageData - The image data to encode.\n * @param options - WebP encoding options.\n * @param signal - (Optional) AbortSignal to cancel the encoding 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 encoded WebP data as a Uint8Array.\n *\n * @example\n * // With cancellation support\n * const controller = new AbortController();\n * const result = await encode(imageData, { quality: 85 }, controller.signal);\n * setTimeout(() => controller.abort(), 5000);\n *\n * @example\n * // Without cancellation (operation cannot be stopped)\n * const result = await encode(imageData, { quality: 85 });\n */\nexport async function encode(\n imageData: ImageInput,\n options?: EncodeInputOptions,\n signal?: AbortSignal\n): Promise<Uint8Array> {\n // Use worker mode for UI responsiveness - prevents blocking the main thread\n if (!globalClientBridge) {\n globalClientBridge = createBridge('worker');\n }\n\n return globalClientBridge.encode(imageData, options, signal);\n}\n\n/**\n * Creates a reusable WebP encoder function for a specific execution mode.\n * This is useful for processing multiple images without the overhead of\n * creating a new worker or client instance each time.\n *\n * @param mode - The execution mode, either 'worker' or 'client'.\n * @returns A function that encodes an image to WebP format with optional AbortSignal.\n */\nexport function createWebpEncoder(mode: 'worker' | 'client' = 'worker') {\n const bridge = createBridge(mode);\n\n const encoder = (\n imageData: ImageInput,\n options?: EncodeInputOptions,\n signal?: AbortSignal\n ) => {\n return bridge.encode(imageData, options, signal);\n };\n\n encoder.terminate = async () => {\n await bridge.terminate();\n };\n\n return encoder;\n}\n"
6
6
  ],
7
- "mappings": "yEAWA,IAAI,EAA6D,KA+CjE,eAAsB,CAAM,CAC1B,EACA,EACA,EACqB,CAErB,GAAI,CAAC,EACH,EAAqB,EAAa,QAAQ,EAG5C,OAAO,EAAmB,OAAO,EAAW,EAAS,CAAM,EAWtD,SAAS,CAAiB,CAC/B,EAA4B,SACR,CACpB,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",
7
+ "mappings": "yEAWA,IAAI,EAA6D,KA+CjE,eAAsB,CAAM,CAC1B,EACA,EACA,EACqB,CAErB,GAAI,CAAC,EACH,EAAqB,EAAa,QAAQ,EAG5C,OAAO,EAAmB,OAAO,EAAW,EAAS,CAAM,EAWtD,SAAS,CAAiB,CAAC,EAA4B,SAAU,CACtE,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
8
  "debugId": "C4671603FEA85F6D64756E2164756E21",
9
9
  "names": []
10
10
  }
@@ -2,9 +2,9 @@
2
2
  "version": 3,
3
3
  "sources": ["../src/index.ts"],
4
4
  "sourcesContent": [
5
- "/**\n * @squoosh-kit/webp public API\n */\n\nimport type { ImageInput } from '@squoosh-kit/runtime';\nimport { createBridge } from './bridge';\nimport type { EncodeInputOptions } from './types';\n\nexport type { ImageInput, EncodeInputOptions };\n\n// Global bridge instance for reuse\nlet globalClientBridge: ReturnType<typeof createBridge> | null = null;\n\n/**\n * A WebP image encoder that can be reused for multiple operations.\n * Can be terminated to clean up associated resources (especially workers).\n */\nexport type WebpEncoderFactory = ((\n imageData: ImageInput,\n options?: EncodeInputOptions,\n signal?: AbortSignal\n) => Promise<Uint8Array>) & {\n /**\n * Terminates the encoder and cleans up resources.\n * Important for worker mode to prevent memory leaks.\n *\n * @example\n * const encoder = createWebpEncoder('worker');\n * try {\n * const result = await encoder(imageData, options);\n * } finally {\n * await encoder.terminate();\n * }\n */\n terminate(): Promise<void>;\n};\n\n/**\n * Encodes an image to WebP format. Uses worker mode for UI responsiveness.\n *\n * @param imageData - The image data to encode.\n * @param options - WebP encoding options.\n * @param signal - (Optional) AbortSignal to cancel the encoding 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 encoded WebP data as a Uint8Array.\n *\n * @example\n * // With cancellation support\n * const controller = new AbortController();\n * const result = await encode(imageData, { quality: 85 }, controller.signal);\n * setTimeout(() => controller.abort(), 5000);\n *\n * @example\n * // Without cancellation (operation cannot be stopped)\n * const result = await encode(imageData, { quality: 85 });\n */\nexport async function encode(\n imageData: ImageInput,\n options?: EncodeInputOptions,\n signal?: AbortSignal\n): Promise<Uint8Array> {\n // Use worker mode for UI responsiveness - prevents blocking the main thread\n if (!globalClientBridge) {\n globalClientBridge = createBridge('worker');\n }\n\n return globalClientBridge.encode(imageData, options, signal);\n}\n\n/**\n * Creates a reusable WebP encoder function for a specific execution mode.\n * This is useful for processing multiple images without the overhead of\n * creating a new worker or client instance each time.\n *\n * @param mode - The execution mode, either 'worker' or 'client'.\n * @returns A function that encodes an image to WebP format with optional AbortSignal.\n */\nexport function createWebpEncoder(\n mode: 'worker' | 'client' = 'worker'\n): WebpEncoderFactory {\n const bridge = createBridge(mode);\n\n const encoder = (\n imageData: ImageInput,\n options?: EncodeInputOptions,\n signal?: AbortSignal\n ) => {\n return bridge.encode(imageData, options, signal);\n };\n\n encoder.terminate = async () => {\n await bridge.terminate();\n };\n\n return encoder as WebpEncoderFactory;\n}\n"
5
+ "/**\n * @squoosh-kit/webp public API\n */\n\nimport type { ImageInput } from '@squoosh-kit/runtime';\nimport { createBridge } from './bridge';\nimport type { EncodeInputOptions } from './types';\n\nexport type { ImageInput, EncodeInputOptions };\n\n// Global bridge instance for reuse\nlet globalClientBridge: ReturnType<typeof createBridge> | null = null;\n\n/**\n * A WebP image encoder that can be reused for multiple operations.\n * Can be terminated to clean up associated resources (especially workers).\n */\nexport type WebpEncoderFactory = ((\n imageData: ImageInput,\n options?: EncodeInputOptions,\n signal?: AbortSignal\n) => Promise<Uint8Array>) & {\n /**\n * Terminates the encoder and cleans up resources.\n * Important for worker mode to prevent memory leaks.\n *\n * @example\n * const encoder = createWebpEncoder('worker');\n * try {\n * const result = await encoder(imageData, options);\n * } finally {\n * await encoder.terminate();\n * }\n */\n terminate(): Promise<void>;\n};\n\n/**\n * Encodes an image to WebP format. Uses worker mode for UI responsiveness.\n *\n * @param imageData - The image data to encode.\n * @param options - WebP encoding options.\n * @param signal - (Optional) AbortSignal to cancel the encoding 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 encoded WebP data as a Uint8Array.\n *\n * @example\n * // With cancellation support\n * const controller = new AbortController();\n * const result = await encode(imageData, { quality: 85 }, controller.signal);\n * setTimeout(() => controller.abort(), 5000);\n *\n * @example\n * // Without cancellation (operation cannot be stopped)\n * const result = await encode(imageData, { quality: 85 });\n */\nexport async function encode(\n imageData: ImageInput,\n options?: EncodeInputOptions,\n signal?: AbortSignal\n): Promise<Uint8Array> {\n // Use worker mode for UI responsiveness - prevents blocking the main thread\n if (!globalClientBridge) {\n globalClientBridge = createBridge('worker');\n }\n\n return globalClientBridge.encode(imageData, options, signal);\n}\n\n/**\n * Creates a reusable WebP encoder function for a specific execution mode.\n * This is useful for processing multiple images without the overhead of\n * creating a new worker or client instance each time.\n *\n * @param mode - The execution mode, either 'worker' or 'client'.\n * @returns A function that encodes an image to WebP format with optional AbortSignal.\n */\nexport function createWebpEncoder(mode: 'worker' | 'client' = 'worker') {\n const bridge = createBridge(mode);\n\n const encoder = (\n imageData: ImageInput,\n options?: EncodeInputOptions,\n signal?: AbortSignal\n ) => {\n return bridge.encode(imageData, options, signal);\n };\n\n encoder.terminate = async () => {\n await bridge.terminate();\n };\n\n return encoder;\n}\n"
6
6
  ],
7
- "mappings": "0GAWA,FAAI,JAA6D,KA+CjE,eAAsB,CAAM,CAC1B,EACA,EACA,EACqB,CAErB,GAAI,CAAC,EACH,EAAqB,EAAa,QAAQ,EAG5C,OAAO,EAAmB,OAAO,EAAW,EAAS,CAAM,EAWtD,SAAS,CAAiB,CAC/B,EAA4B,SACR,CACpB,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",
7
+ "mappings": "0GAWA,FAAI,JAA6D,KA+CjE,eAAsB,CAAM,CAC1B,EACA,EACA,EACqB,CAErB,GAAI,CAAC,EACH,EAAqB,EAAa,QAAQ,EAG5C,OAAO,EAAmB,OAAO,EAAW,EAAS,CAAM,EAWtD,SAAS,CAAiB,CAAC,EAA4B,SAAU,CACtE,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
8
  "debugId": "2C193489B9C116D164756E2164756E21",
9
9
  "names": []
10
10
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@squoosh-kit/webp",
3
- "version": "0.0.15",
3
+ "version": "0.0.16",
4
4
  "type": "module",
5
5
  "description": "WebP codec for squoosh-kit, providing encoding functionality.",
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.15"
49
49
  }
50
50
  }