@squoosh-kit/webp 0.0.11 → 0.0.13
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 +17 -0
- package/dist/bridge.browser.mjs +2 -2
- package/dist/bridge.browser.mjs.map +4 -4
- package/dist/bridge.bun.js +2 -2
- package/dist/bridge.bun.js.map +4 -4
- package/dist/bridge.d.ts +2 -2
- package/dist/bridge.d.ts.map +1 -1
- package/dist/bridge.node.cjs +2 -2
- package/dist/bridge.node.cjs.map +4 -4
- package/dist/bridge.node.mjs +2 -2
- package/dist/bridge.node.mjs.map +4 -4
- package/dist/chunk-124gpwf3.js +3 -0
- package/dist/chunk-124gpwf3.js.map +10 -0
- package/dist/chunk-3e1dzjy4.js +27 -0
- package/dist/chunk-3e1dzjy4.js.map +10 -0
- package/dist/chunk-460jgek8.js +3 -0
- package/dist/chunk-460jgek8.js.map +10 -0
- package/dist/chunk-494e4bws.js +4 -0
- package/dist/chunk-494e4bws.js.map +9 -0
- package/dist/chunk-6k9yrqxa.js +5 -0
- package/dist/chunk-6k9yrqxa.js.map +9 -0
- package/dist/chunk-8pja0p5b.js +5 -0
- package/dist/chunk-8pja0p5b.js.map +10 -0
- package/dist/chunk-a31j12b6.js +4 -0
- package/dist/chunk-a31j12b6.js.map +10 -0
- package/dist/chunk-h3s3se69.js +5 -0
- package/dist/chunk-h3s3se69.js.map +10 -0
- package/dist/chunk-ks7kcgv0.js +4 -0
- package/dist/chunk-ks7kcgv0.js.map +9 -0
- package/dist/chunk-nscv6dhm.js +4 -0
- package/dist/chunk-nscv6dhm.js.map +10 -0
- package/dist/chunk-sc3b6r8w.js +27 -0
- package/dist/chunk-sc3b6r8w.js.map +10 -0
- package/dist/chunk-t6tcztdc.js +28 -0
- package/dist/chunk-t6tcztdc.js.map +10 -0
- package/dist/chunk-zwen5g92.js +27 -0
- package/dist/chunk-zwen5g92.js.map +10 -0
- 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 +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.mjs +2 -2
- package/dist/index.node.mjs.map +3 -3
- package/dist/types.d.ts +3 -23
- package/dist/types.d.ts.map +1 -1
- package/dist/types.node.cjs +2 -2
- package/dist/types.node.cjs.map +1 -1
- package/dist/wasm/webp/webp_enc_simd.d.ts +1 -0
- package/dist/wasm/webp/webp_enc_simd.js +16 -0
- package/dist/wasm/webp/webp_enc_simd.wasm +0 -0
- package/dist/wasm/webp/webp_node_enc.js +16 -0
- package/dist/wasm/webp/webp_node_enc.wasm +0 -0
- package/dist/wasm/webp-dec/webp_node_dec.js +16 -0
- package/dist/wasm/webp-dec/webp_node_dec.wasm +0 -0
- package/dist/webp.worker.browser.mjs +20 -21
- package/dist/webp.worker.browser.mjs.map +7 -6
- package/dist/webp.worker.bun.js +20 -21
- package/dist/webp.worker.bun.js.map +7 -6
- package/dist/webp.worker.d.ts +2 -2
- package/dist/webp.worker.d.ts.map +1 -1
- package/dist/webp.worker.node.cjs +20 -20
- package/dist/webp.worker.node.cjs.map +7 -6
- package/dist/webp.worker.node.mjs +20 -21
- package/dist/webp.worker.node.mjs.map +7 -6
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -292,6 +292,23 @@ type WebpOptions = {
|
|
|
292
292
|
- **Batch with persistent encoders** - More efficient than one-off calls
|
|
293
293
|
- **Adjust quality strategically** - Often 80-90% quality looks identical to 100%
|
|
294
294
|
|
|
295
|
+
## Encoding Quality & File Size
|
|
296
|
+
|
|
297
|
+
The encoder uses quality-aware compression that automatically adjusts encoding parameters based on your quality setting:
|
|
298
|
+
|
|
299
|
+
- **High quality (80-100%)** - Faster encoding, lower CPU overhead
|
|
300
|
+
- **Medium quality (60-80%)** - Balanced compression and speed
|
|
301
|
+
- **Low quality (0-60%)** - More aggressive compression, slower encoding
|
|
302
|
+
|
|
303
|
+
This means that at 85% quality, you get smaller files than the original by applying targeted compression techniques like:
|
|
304
|
+
|
|
305
|
+
- Adaptive filtering based on content
|
|
306
|
+
- Spatial noise shaping for better detail preservation
|
|
307
|
+
- Multiple encoding passes for optimal results
|
|
308
|
+
- Sharp YUV conversion for better color handling
|
|
309
|
+
|
|
310
|
+
**Result**: Your image at 85% quality WebP will typically be **30-70% smaller** than the original JPEG or PNG while maintaining near-identical visual quality.
|
|
311
|
+
|
|
295
312
|
## Works With
|
|
296
313
|
|
|
297
314
|
- **Bun** - First-class support, fastest performance
|
package/dist/bridge.browser.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{b as
|
|
1
|
+
import{b as I,c as P}from"./chunk-nscv6dhm.js";import{e as z,f as E}from"./chunk-494e4bws.js";function O(){return typeof Bun<"u"}var q=0;async function U(G,J,V,K,H){return new Promise((L,X)=>{let Q=++q;if(K?.aborted){X(new DOMException("Aborted","AbortError"));return}let Z=(x)=>{let D=x.data;if(D.id!==Q)return;if($(),D.ok&&D.data!==void 0)L(D.data);else X(Error(D.error||"Unknown worker error"))},R=(x)=>{$(),X(Error(`Worker error: ${x.message}`))},_=()=>{$(),X(new DOMException("Aborted","AbortError"))},$=()=>{G.removeEventListener("message",Z),G.removeEventListener("error",R),K?.removeEventListener("abort",_)};G.addEventListener("message",Z),G.addEventListener("error",R),K?.addEventListener("abort",_);let Y={type:J,id:Q,payload:V};if(H&&H.length>0)G.postMessage(Y,H);else G.postMessage(Y)})}function T(G){let J=G.endsWith(".js")?G:`${G}.js`,V={"resize.worker.js":{package:"@squoosh-kit/resize",specifier:"resize.worker.js"},"webp.worker.js":{package:"@squoosh-kit/webp",specifier:"webp.worker.js"}},K=V[J];if(!K)throw Error(`Unknown worker: ${J}. Supported workers: ${Object.keys(V).join(", ")}`);try{if(typeof window<"u"){let Q=K.package.split("/")[1],Z=J.replace(".js",".browser.mjs"),R=[`../../${Q}/dist/${Z}`,`../../../node_modules/@squoosh-kit/${Q}/dist/${Z}`,`../../../${Q}/dist/${Z}`],_=null;for(let $ of R)try{let Y=new URL($,import.meta.url);return new Worker(Y,{type:"module"})}catch(Y){_=Y instanceof Error?Y:Error(String(Y))}if(_)throw _;throw Error(`Could not resolve worker ${J} using any available path strategy`)}if(typeof import.meta.resolve==="function")try{let Q=import.meta.resolve(`${K.package}/${K.specifier}`);return new Worker(Q,{type:"module"})}catch{}let H=O()?".bun.js":".node.mjs",L=J.replace(".js",""),X=K.package.includes("resize")?`../../resize/dist/${L}.${H.slice(1)}`:`../../webp/dist/${L}.${H.slice(1)}`;return new Worker(new URL(X,import.meta.url),{type:"module"})}catch(H){let L=H instanceof Error?H.message:String(H);throw Error(`Failed to create worker from ${J}: ${L}. Ensure the @squoosh-kit/resize and @squoosh-kit/webp packages are installed. If you're using Vite, ensure the worker files are not being optimized as dependencies.`)}}function A(G,J=1e4){return new Promise((V,K)=>{let H=setTimeout(()=>{K(Error(`Worker initialization timeout after ${J}ms. Worker file: ${G}`))},J),L;try{L=T(G)}catch(Q){clearTimeout(H),K(Q);return}let X=(Q)=>{if(Q.data?.type==="worker:ready")clearTimeout(H),L.removeEventListener("message",X),V(L)};L.addEventListener("message",X),L.postMessage({type:"worker:ping"})})}class S{async encode(G,J,V){let H=(await import("./webp.worker.browser.mjs")).webpEncodeClient;return H(G,J,V)}async terminate(){}}class B{worker=null;workerReady=null;async getWorker(){if(!this.worker){if(!this.workerReady)this.workerReady=this.createWorker();this.worker=await this.workerReady}return this.worker}async createWorker(){return A("webp.worker")}async encode(G,J,V){let K=await this.getWorker();P(G);let H=G.data.buffer;return I(H),U(K,"webp:encode",{image:G,options:J},V,[H])}async terminate(){if(this.worker)this.worker.terminate(),this.worker=null,this.workerReady=null}}function y(G){return G==="client"?new S:new B}export{y as createBridge};
|
|
2
2
|
export{y as a};
|
|
3
3
|
|
|
4
|
-
//# debugId=
|
|
4
|
+
//# debugId=9009508C801550AE64756E2164756E21
|
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
"sourcesContent": [
|
|
5
5
|
"/**\n * Runtime environment detection utilities\n */\n\n/**\n * Detect if running in a Web Worker context\n */\nexport function isWorker(): boolean {\n return (\n typeof self !== 'undefined' &&\n typeof (globalThis as unknown as { DedicatedWorkerGlobalScope?: unknown })\n .DedicatedWorkerGlobalScope !== 'undefined'\n );\n}\n\n/**\n * Detect if running in a browser context\n */\nexport function isBrowser(): boolean {\n return typeof window !== 'undefined' && typeof document !== 'undefined';\n}\n\n/**\n * Detect if running in Bun\n */\nexport function isBun(): boolean {\n return typeof Bun !== 'undefined';\n}\n\n/**\n * Detect if running in Node.js\n */\nexport function isNode(): boolean {\n return (\n typeof process !== 'undefined' &&\n process.versions != null &&\n process.versions.node != null\n );\n}\n\n/**\n * Check if ImageData is available in the current environment\n */\nexport function hasImageData(): boolean {\n return typeof ImageData !== 'undefined';\n}\n",
|
|
6
6
|
"/**\n * Generic worker communication helper with support for transferables and AbortSignal\n */\n\nexport interface WorkerRequest<T = unknown> {\n type: string;\n id: number;\n payload: T;\n}\n\nexport interface WorkerResponse<T = unknown> {\n id: number;\n ok: boolean;\n data?: T;\n error?: string;\n}\n\nlet requestId = 0;\n\n/**\n * Call a worker with a typed request and wait for response\n *\n * @param worker - The worker instance to call\n * @param type - The message type\n * @param payload - The payload to send\n * @param signal - Optional AbortSignal to cancel the operation\n * @param transfer - Optional list of Transferable objects to transfer\n * @returns Promise that resolves with the worker's response data\n */\nexport async function callWorker<TPayload, TResponse>(\n worker: Worker,\n type: string,\n payload: TPayload,\n signal?: AbortSignal,\n transfer?: Transferable[]\n): Promise<TResponse> {\n return new Promise<TResponse>((resolve, reject) => {\n const id = ++requestId;\n\n // Check if already aborted\n if (signal?.aborted) {\n reject(new DOMException('Aborted', 'AbortError'));\n return;\n }\n\n const handleMessage = (event: MessageEvent) => {\n const response = event.data as WorkerResponse<TResponse>;\n if (response.id !== id) return;\n\n cleanup();\n\n if (response.ok && response.data !== undefined) {\n resolve(response.data);\n } else {\n reject(new Error(response.error || 'Unknown worker error'));\n }\n };\n\n const handleError = (error: ErrorEvent) => {\n cleanup();\n reject(new Error(`Worker error: ${error.message}`));\n };\n\n const handleAbort = () => {\n cleanup();\n reject(new DOMException('Aborted', 'AbortError'));\n };\n\n const cleanup = () => {\n worker.removeEventListener('message', handleMessage);\n worker.removeEventListener('error', handleError);\n signal?.removeEventListener('abort', handleAbort);\n };\n\n // Set up listeners\n worker.addEventListener('message', handleMessage);\n worker.addEventListener('error', handleError);\n signal?.addEventListener('abort', handleAbort);\n\n // Send the request\n const request: WorkerRequest<TPayload> = { type, id, payload };\n\n if (transfer && transfer.length > 0) {\n worker.postMessage(request, transfer);\n } else {\n worker.postMessage(request);\n }\n });\n}\n",
|
|
7
|
-
"/**\n * Worker helper utilities for creating and managing Web Workers\n *\n * This module provides centralized logic for creating worker instances\n * in different environments (browser, Node.js, Bun) using import.meta.resolve\n * for server-side and package-relative paths for browsers.\n */\n\nimport { isBun } from './env';\n\n/**\n * Create a Web Worker for a specific codec\n *\n * In Node.js/Bun environments, uses import.meta.resolve to locate worker files.\n * In browser environments, uses relative paths within node_modules that Vite can resolve.\n *\n * @param workerFilename - The name of the worker file (e.g., 'resize.worker' or 'webp.worker')\n * @returns Worker instance\n * @throws Error if worker creation fails with detailed error message\n */\nexport function createCodecWorker(workerFilename: string): Worker {\n // Ensure filename has correct format\n const normalizedName = workerFilename.endsWith('.js')\n ? workerFilename\n : `${workerFilename}.js`;\n\n // Map worker filenames to their package and export\n const workerMap: Record<string, { package: string; specifier: string }> = {\n 'resize.worker.js': {\n package: '@squoosh-kit/resize',\n specifier: 'resize.worker.js',\n },\n 'webp.worker.js': {\n package: '@squoosh-kit/webp',\n specifier: 'webp.worker.js',\n },\n };\n\n const workerConfig = workerMap[normalizedName];\n if (!workerConfig) {\n throw new Error(\n `Unknown worker: ${normalizedName}. ` +\n `Supported workers: ${Object.keys(workerMap).join(', ')}`\n );\n }\n\n try {\n // In browser contexts, use relative paths within the installed packages\n if (typeof window !== 'undefined') {\n const packageName = workerConfig.package.split('/')[1]; // Extract 'resize' or 'webp'\n const workerFile = normalizedName.replace('.js', '.browser.mjs');\n\n // Try multiple path strategies to support both:\n // 1. Monorepo development structure: ../../{package}/dist/{workerFile}\n // 2. npm installed structure: ../../../{package}/dist/{workerFile}\n const pathStrategies = [\n // First try monorepo structure (when runtime is at packages/runtime/src)\n `../../${packageName}/dist/${workerFile}`,\n // Then try npm structure (when runtime is at node_modules/@squoosh-kit/runtime)\n `../../../node_modules/@squoosh-kit/${packageName}/dist/${workerFile}`,\n // Alternative npm structure for cases where packages are flattened\n `../../../${packageName}/dist/${workerFile}`,\n ];\n\n let lastError: Error | null = null;\n\n for (const relPath of pathStrategies) {\n try {\n const workerUrl = new URL(relPath, import.meta.url);\n return new Worker(workerUrl, {\n type: 'module',\n });\n } catch (error) {\n lastError = error instanceof Error ? error : new Error(String(error));\n // Continue to next strategy\n }\n }\n\n // If all strategies failed, throw the last error\n if (lastError) {\n throw lastError;\n }\n throw new Error(\n `Could not resolve worker ${normalizedName} using any available path strategy`\n );\n }\n\n // Node.js/Bun: use import.meta.resolve if available\n if (typeof import.meta.resolve === 'function') {\n const resolved = import.meta.resolve(\n
|
|
8
|
-
"/**\n * Bridge implementation for the WebP package, handling worker and client modes.\n */\n\nimport {\n callWorker,\n createReadyWorker,\n type ImageInput,\n} from '@squoosh-kit/runtime';\nimport { validateArrayBuffer, validateImageInput } from '@squoosh-kit/runtime';\nimport
|
|
7
|
+
"/**\n * Worker helper utilities for creating and managing Web Workers\n *\n * This module provides centralized logic for creating worker instances\n * in different environments (browser, Node.js, Bun) using import.meta.resolve\n * for server-side and package-relative paths for browsers.\n */\n\nimport { isBun } from './env';\n\n/**\n * Create a Web Worker for a specific codec\n *\n * In Node.js/Bun environments, uses import.meta.resolve to locate worker files.\n * In browser environments, uses relative paths within node_modules that Vite can resolve.\n *\n * @param workerFilename - The name of the worker file (e.g., 'resize.worker' or 'webp.worker')\n * @returns Worker instance\n * @throws Error if worker creation fails with detailed error message\n */\nexport function createCodecWorker(workerFilename: string): Worker {\n // Ensure filename has correct format\n const normalizedName = workerFilename.endsWith('.js')\n ? workerFilename\n : `${workerFilename}.js`;\n\n // Map worker filenames to their package and export\n const workerMap: Record<string, { package: string; specifier: string }> = {\n 'resize.worker.js': {\n package: '@squoosh-kit/resize',\n specifier: 'resize.worker.js',\n },\n 'webp.worker.js': {\n package: '@squoosh-kit/webp',\n specifier: 'webp.worker.js',\n },\n };\n\n const workerConfig = workerMap[normalizedName];\n if (!workerConfig) {\n throw new Error(\n `Unknown worker: ${normalizedName}. ` +\n `Supported workers: ${Object.keys(workerMap).join(', ')}`\n );\n }\n\n try {\n // In browser contexts, use relative paths within the installed packages\n if (typeof window !== 'undefined') {\n const packageName = workerConfig.package.split('/')[1]; // Extract 'resize' or 'webp'\n const workerFile = normalizedName.replace('.js', '.browser.mjs');\n\n // Try multiple path strategies to support both:\n // 1. Monorepo development structure: ../../{package}/dist/{workerFile}\n // 2. npm installed structure: ../../../{package}/dist/{workerFile}\n const pathStrategies = [\n // First try monorepo structure (when runtime is at packages/runtime/src)\n `../../${packageName}/dist/${workerFile}`,\n // Then try npm structure (when runtime is at node_modules/@squoosh-kit/runtime)\n `../../../node_modules/@squoosh-kit/${packageName}/dist/${workerFile}`,\n // Alternative npm structure for cases where packages are flattened\n `../../../${packageName}/dist/${workerFile}`,\n ];\n\n let lastError: Error | null = null;\n\n for (const relPath of pathStrategies) {\n try {\n const workerUrl = new URL(relPath, import.meta.url);\n return new Worker(workerUrl, {\n type: 'module',\n });\n } catch (error) {\n lastError = error instanceof Error ? error : new Error(String(error));\n // Continue to next strategy\n }\n }\n\n // If all strategies failed, throw the last error\n if (lastError) {\n throw lastError;\n }\n throw new Error(\n `Could not resolve worker ${normalizedName} using any available path strategy`\n );\n }\n\n // Node.js/Bun: use import.meta.resolve if available\n if (typeof import.meta.resolve === 'function') {\n try {\n const resolved = import.meta.resolve(\n `${workerConfig.package}/${workerConfig.specifier}`\n );\n return new Worker(resolved, { type: 'module' });\n } catch {\n // Fallback if resolve fails - use relative path as last resort\n }\n }\n\n // Fallback for Bun: use relative path from this file's location\n const platformExt = isBun() ? '.bun.js' : '.node.mjs';\n const baseName = normalizedName.replace('.js', '');\n const relPath = workerConfig.package.includes('resize')\n ? `../../resize/dist/${baseName}.${platformExt.slice(1)}`\n : `../../webp/dist/${baseName}.${platformExt.slice(1)}`;\n\n return new Worker(new URL(relPath, import.meta.url), { type: 'module' });\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : String(error);\n throw new Error(\n `Failed to create worker from ${normalizedName}: ${errorMessage}. ` +\n `Ensure the @squoosh-kit/resize and @squoosh-kit/webp packages are installed. ` +\n `If you're using Vite, ensure the worker files are not being optimized as dependencies.`\n );\n }\n}\n\n/**\n * Create a worker with initialization timeout and ready signal handling\n *\n * This is a higher-level function that creates a worker and waits for it\n * to signal that it's ready to receive messages.\n *\n * @param workerFilename - The name of the worker file\n * @param timeoutMs - Timeout in milliseconds (default: 10000)\n * @returns Promise that resolves to a ready Worker instance\n * @throws Error if worker creation fails or times out\n */\nexport function createReadyWorker(\n workerFilename: string,\n timeoutMs: number = 10000\n): Promise<Worker> {\n return new Promise((resolve, reject) => {\n const timeout = setTimeout(() => {\n reject(\n new Error(\n `Worker initialization timeout after ${timeoutMs}ms. Worker file: ${workerFilename}`\n )\n );\n }, timeoutMs);\n\n let worker: Worker;\n try {\n worker = createCodecWorker(workerFilename);\n } catch (error) {\n clearTimeout(timeout);\n reject(error);\n return;\n }\n\n const handleMessage = (event: MessageEvent) => {\n if (event.data?.type === 'worker:ready') {\n clearTimeout(timeout);\n worker.removeEventListener('message', handleMessage);\n resolve(worker);\n }\n };\n\n worker.addEventListener('message', handleMessage);\n worker.postMessage({ type: 'worker:ping' });\n });\n}\n",
|
|
8
|
+
"/**\n * Bridge implementation for the WebP package, handling worker and client modes.\n */\n\nimport {\n callWorker,\n createReadyWorker,\n type ImageInput,\n} from '@squoosh-kit/runtime';\nimport { validateArrayBuffer, validateImageInput } from '@squoosh-kit/runtime';\nimport type { EncodeInputOptions } from './types';\n\ninterface WebPBridge {\n encode(\n image: ImageInput,\n options?: EncodeInputOptions,\n signal?: AbortSignal\n ): Promise<Uint8Array>;\n terminate(): Promise<void>;\n}\n\nclass WebpClientBridge implements WebPBridge {\n async encode(\n image: ImageInput,\n options?: EncodeInputOptions,\n signal?: AbortSignal\n ): Promise<Uint8Array> {\n // Dynamically import the client encoder to avoid module loading issues in Vite\n const module = await import('./webp.worker.js');\n const webpEncodeClient = module.webpEncodeClient as (\n image: ImageInput,\n options?: EncodeInputOptions,\n signal?: AbortSignal\n ) => Promise<Uint8Array>;\n return webpEncodeClient(image, options, signal);\n }\n\n async terminate(): Promise<void> {\n // Client mode has nothing to terminate\n }\n}\n\nclass WebpWorkerBridge implements WebPBridge {\n private worker: Worker | null = null;\n private workerReady: Promise<Worker> | null = null;\n\n private async getWorker(): Promise<Worker> {\n if (!this.worker) {\n if (!this.workerReady) {\n this.workerReady = this.createWorker();\n }\n this.worker = await this.workerReady;\n }\n return this.worker;\n }\n\n private async createWorker(): Promise<Worker> {\n // Use the centralized worker helper for robust path resolution\n return createReadyWorker('webp.worker');\n }\n\n async encode(\n image: ImageInput,\n options?: EncodeInputOptions,\n signal?: AbortSignal\n ): Promise<Uint8Array> {\n const worker = await this.getWorker();\n\n validateImageInput(image);\n const buffer = image.data.buffer;\n validateArrayBuffer(buffer);\n return callWorker(worker, 'webp:encode', { image, options }, signal, [\n buffer,\n ]);\n }\n\n async terminate(): Promise<void> {\n if (this.worker) {\n this.worker.terminate();\n this.worker = null;\n this.workerReady = null;\n }\n }\n}\n\nexport function createBridge(mode: 'worker' | 'client'): WebPBridge {\n return mode === 'client' ? new WebpClientBridge() : new WebpWorkerBridge();\n}\n"
|
|
9
9
|
],
|
|
10
|
-
"mappings": "
|
|
11
|
-
"debugId": "
|
|
10
|
+
"mappings": "oGAyBO,GAAS,CAAK,E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bun.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{b as
|
|
2
|
+
import{b as I,c as P}from"./chunk-h3s3se69.js";import{e as z,f as E}from"./chunk-6k9yrqxa.js";function O(){return typeof Bun<"u"}var q=0;async function U(G,J,V,K,H){return new Promise((L,X)=>{let Q=++q;if(K?.aborted){X(new DOMException("Aborted","AbortError"));return}let Z=(x)=>{let D=x.data;if(D.id!==Q)return;if($(),D.ok&&D.data!==void 0)L(D.data);else X(Error(D.error||"Unknown worker error"))},R=(x)=>{$(),X(Error(`Worker error: ${x.message}`))},_=()=>{$(),X(new DOMException("Aborted","AbortError"))},$=()=>{G.removeEventListener("message",Z),G.removeEventListener("error",R),K?.removeEventListener("abort",_)};G.addEventListener("message",Z),G.addEventListener("error",R),K?.addEventListener("abort",_);let Y={type:J,id:Q,payload:V};if(H&&H.length>0)G.postMessage(Y,H);else G.postMessage(Y)})}function T(G){let J=G.endsWith(".js")?G:`${G}.js`,V={"resize.worker.js":{package:"@squoosh-kit/resize",specifier:"resize.worker.js"},"webp.worker.js":{package:"@squoosh-kit/webp",specifier:"webp.worker.js"}},K=V[J];if(!K)throw Error(`Unknown worker: ${J}. Supported workers: ${Object.keys(V).join(", ")}`);try{if(typeof window<"u"){let Q=K.package.split("/")[1],Z=J.replace(".js",".browser.mjs"),R=[`../../${Q}/dist/${Z}`,`../../../node_modules/@squoosh-kit/${Q}/dist/${Z}`,`../../../${Q}/dist/${Z}`],_=null;for(let $ of R)try{let Y=new URL($,import.meta.url);return new Worker(Y,{type:"module"})}catch(Y){_=Y instanceof Error?Y:Error(String(Y))}if(_)throw _;throw Error(`Could not resolve worker ${J} using any available path strategy`)}if(typeof import.meta.resolve==="function")try{let Q=import.meta.resolve(`${K.package}/${K.specifier}`);return new Worker(Q,{type:"module"})}catch{}let H=O()?".bun.js":".node.mjs",L=J.replace(".js",""),X=K.package.includes("resize")?`../../resize/dist/${L}.${H.slice(1)}`:`../../webp/dist/${L}.${H.slice(1)}`;return new Worker(new URL(X,import.meta.url),{type:"module"})}catch(H){let L=H instanceof Error?H.message:String(H);throw Error(`Failed to create worker from ${J}: ${L}. Ensure the @squoosh-kit/resize and @squoosh-kit/webp packages are installed. If you're using Vite, ensure the worker files are not being optimized as dependencies.`)}}function A(G,J=1e4){return new Promise((V,K)=>{let H=setTimeout(()=>{K(Error(`Worker initialization timeout after ${J}ms. Worker file: ${G}`))},J),L;try{L=T(G)}catch(Q){clearTimeout(H),K(Q);return}let X=(Q)=>{if(Q.data?.type==="worker:ready")clearTimeout(H),L.removeEventListener("message",X),V(L)};L.addEventListener("message",X),L.postMessage({type:"worker:ping"})})}class S{async encode(G,J,V){let H=(await import("./webp.worker.bun.js")).webpEncodeClient;return H(G,J,V)}async terminate(){}}class B{worker=null;workerReady=null;async getWorker(){if(!this.worker){if(!this.workerReady)this.workerReady=this.createWorker();this.worker=await this.workerReady}return this.worker}async createWorker(){return A("webp.worker")}async encode(G,J,V){let K=await this.getWorker();P(G);let H=G.data.buffer;return I(H),U(K,"webp:encode",{image:G,options:J},V,[H])}async terminate(){if(this.worker)this.worker.terminate(),this.worker=null,this.workerReady=null}}function y(G){return G==="client"?new S:new B}export{y as createBridge};
|
|
3
3
|
export{y as a};
|
|
4
4
|
|
|
5
|
-
//# debugId=
|
|
5
|
+
//# debugId=A7A7ECF92DCC46BF64756E2164756E21
|
package/dist/bridge.bun.js.map
CHANGED
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
"sourcesContent": [
|
|
5
5
|
"/**\n * Runtime environment detection utilities\n */\n\n/**\n * Detect if running in a Web Worker context\n */\nexport function isWorker(): boolean {\n return (\n typeof self !== 'undefined' &&\n typeof (globalThis as unknown as { DedicatedWorkerGlobalScope?: unknown })\n .DedicatedWorkerGlobalScope !== 'undefined'\n );\n}\n\n/**\n * Detect if running in a browser context\n */\nexport function isBrowser(): boolean {\n return typeof window !== 'undefined' && typeof document !== 'undefined';\n}\n\n/**\n * Detect if running in Bun\n */\nexport function isBun(): boolean {\n return typeof Bun !== 'undefined';\n}\n\n/**\n * Detect if running in Node.js\n */\nexport function isNode(): boolean {\n return (\n typeof process !== 'undefined' &&\n process.versions != null &&\n process.versions.node != null\n );\n}\n\n/**\n * Check if ImageData is available in the current environment\n */\nexport function hasImageData(): boolean {\n return typeof ImageData !== 'undefined';\n}\n",
|
|
6
6
|
"/**\n * Generic worker communication helper with support for transferables and AbortSignal\n */\n\nexport interface WorkerRequest<T = unknown> {\n type: string;\n id: number;\n payload: T;\n}\n\nexport interface WorkerResponse<T = unknown> {\n id: number;\n ok: boolean;\n data?: T;\n error?: string;\n}\n\nlet requestId = 0;\n\n/**\n * Call a worker with a typed request and wait for response\n *\n * @param worker - The worker instance to call\n * @param type - The message type\n * @param payload - The payload to send\n * @param signal - Optional AbortSignal to cancel the operation\n * @param transfer - Optional list of Transferable objects to transfer\n * @returns Promise that resolves with the worker's response data\n */\nexport async function callWorker<TPayload, TResponse>(\n worker: Worker,\n type: string,\n payload: TPayload,\n signal?: AbortSignal,\n transfer?: Transferable[]\n): Promise<TResponse> {\n return new Promise<TResponse>((resolve, reject) => {\n const id = ++requestId;\n\n // Check if already aborted\n if (signal?.aborted) {\n reject(new DOMException('Aborted', 'AbortError'));\n return;\n }\n\n const handleMessage = (event: MessageEvent) => {\n const response = event.data as WorkerResponse<TResponse>;\n if (response.id !== id) return;\n\n cleanup();\n\n if (response.ok && response.data !== undefined) {\n resolve(response.data);\n } else {\n reject(new Error(response.error || 'Unknown worker error'));\n }\n };\n\n const handleError = (error: ErrorEvent) => {\n cleanup();\n reject(new Error(`Worker error: ${error.message}`));\n };\n\n const handleAbort = () => {\n cleanup();\n reject(new DOMException('Aborted', 'AbortError'));\n };\n\n const cleanup = () => {\n worker.removeEventListener('message', handleMessage);\n worker.removeEventListener('error', handleError);\n signal?.removeEventListener('abort', handleAbort);\n };\n\n // Set up listeners\n worker.addEventListener('message', handleMessage);\n worker.addEventListener('error', handleError);\n signal?.addEventListener('abort', handleAbort);\n\n // Send the request\n const request: WorkerRequest<TPayload> = { type, id, payload };\n\n if (transfer && transfer.length > 0) {\n worker.postMessage(request, transfer);\n } else {\n worker.postMessage(request);\n }\n });\n}\n",
|
|
7
|
-
"/**\n * Worker helper utilities for creating and managing Web Workers\n *\n * This module provides centralized logic for creating worker instances\n * in different environments (browser, Node.js, Bun) using import.meta.resolve\n * for server-side and package-relative paths for browsers.\n */\n\nimport { isBun } from './env';\n\n/**\n * Create a Web Worker for a specific codec\n *\n * In Node.js/Bun environments, uses import.meta.resolve to locate worker files.\n * In browser environments, uses relative paths within node_modules that Vite can resolve.\n *\n * @param workerFilename - The name of the worker file (e.g., 'resize.worker' or 'webp.worker')\n * @returns Worker instance\n * @throws Error if worker creation fails with detailed error message\n */\nexport function createCodecWorker(workerFilename: string): Worker {\n // Ensure filename has correct format\n const normalizedName = workerFilename.endsWith('.js')\n ? workerFilename\n : `${workerFilename}.js`;\n\n // Map worker filenames to their package and export\n const workerMap: Record<string, { package: string; specifier: string }> = {\n 'resize.worker.js': {\n package: '@squoosh-kit/resize',\n specifier: 'resize.worker.js',\n },\n 'webp.worker.js': {\n package: '@squoosh-kit/webp',\n specifier: 'webp.worker.js',\n },\n };\n\n const workerConfig = workerMap[normalizedName];\n if (!workerConfig) {\n throw new Error(\n `Unknown worker: ${normalizedName}. ` +\n `Supported workers: ${Object.keys(workerMap).join(', ')}`\n );\n }\n\n try {\n // In browser contexts, use relative paths within the installed packages\n if (typeof window !== 'undefined') {\n const packageName = workerConfig.package.split('/')[1]; // Extract 'resize' or 'webp'\n const workerFile = normalizedName.replace('.js', '.browser.mjs');\n\n // Try multiple path strategies to support both:\n // 1. Monorepo development structure: ../../{package}/dist/{workerFile}\n // 2. npm installed structure: ../../../{package}/dist/{workerFile}\n const pathStrategies = [\n // First try monorepo structure (when runtime is at packages/runtime/src)\n `../../${packageName}/dist/${workerFile}`,\n // Then try npm structure (when runtime is at node_modules/@squoosh-kit/runtime)\n `../../../node_modules/@squoosh-kit/${packageName}/dist/${workerFile}`,\n // Alternative npm structure for cases where packages are flattened\n `../../../${packageName}/dist/${workerFile}`,\n ];\n\n let lastError: Error | null = null;\n\n for (const relPath of pathStrategies) {\n try {\n const workerUrl = new URL(relPath, import.meta.url);\n return new Worker(workerUrl, {\n type: 'module',\n });\n } catch (error) {\n lastError = error instanceof Error ? error : new Error(String(error));\n // Continue to next strategy\n }\n }\n\n // If all strategies failed, throw the last error\n if (lastError) {\n throw lastError;\n }\n throw new Error(\n `Could not resolve worker ${normalizedName} using any available path strategy`\n );\n }\n\n // Node.js/Bun: use import.meta.resolve if available\n if (typeof import.meta.resolve === 'function') {\n const resolved = import.meta.resolve(\n
|
|
8
|
-
"/**\n * Bridge implementation for the WebP package, handling worker and client modes.\n */\n\nimport {\n callWorker,\n createReadyWorker,\n type ImageInput,\n} from '@squoosh-kit/runtime';\nimport { validateArrayBuffer, validateImageInput } from '@squoosh-kit/runtime';\nimport
|
|
7
|
+
"/**\n * Worker helper utilities for creating and managing Web Workers\n *\n * This module provides centralized logic for creating worker instances\n * in different environments (browser, Node.js, Bun) using import.meta.resolve\n * for server-side and package-relative paths for browsers.\n */\n\nimport { isBun } from './env';\n\n/**\n * Create a Web Worker for a specific codec\n *\n * In Node.js/Bun environments, uses import.meta.resolve to locate worker files.\n * In browser environments, uses relative paths within node_modules that Vite can resolve.\n *\n * @param workerFilename - The name of the worker file (e.g., 'resize.worker' or 'webp.worker')\n * @returns Worker instance\n * @throws Error if worker creation fails with detailed error message\n */\nexport function createCodecWorker(workerFilename: string): Worker {\n // Ensure filename has correct format\n const normalizedName = workerFilename.endsWith('.js')\n ? workerFilename\n : `${workerFilename}.js`;\n\n // Map worker filenames to their package and export\n const workerMap: Record<string, { package: string; specifier: string }> = {\n 'resize.worker.js': {\n package: '@squoosh-kit/resize',\n specifier: 'resize.worker.js',\n },\n 'webp.worker.js': {\n package: '@squoosh-kit/webp',\n specifier: 'webp.worker.js',\n },\n };\n\n const workerConfig = workerMap[normalizedName];\n if (!workerConfig) {\n throw new Error(\n `Unknown worker: ${normalizedName}. ` +\n `Supported workers: ${Object.keys(workerMap).join(', ')}`\n );\n }\n\n try {\n // In browser contexts, use relative paths within the installed packages\n if (typeof window !== 'undefined') {\n const packageName = workerConfig.package.split('/')[1]; // Extract 'resize' or 'webp'\n const workerFile = normalizedName.replace('.js', '.browser.mjs');\n\n // Try multiple path strategies to support both:\n // 1. Monorepo development structure: ../../{package}/dist/{workerFile}\n // 2. npm installed structure: ../../../{package}/dist/{workerFile}\n const pathStrategies = [\n // First try monorepo structure (when runtime is at packages/runtime/src)\n `../../${packageName}/dist/${workerFile}`,\n // Then try npm structure (when runtime is at node_modules/@squoosh-kit/runtime)\n `../../../node_modules/@squoosh-kit/${packageName}/dist/${workerFile}`,\n // Alternative npm structure for cases where packages are flattened\n `../../../${packageName}/dist/${workerFile}`,\n ];\n\n let lastError: Error | null = null;\n\n for (const relPath of pathStrategies) {\n try {\n const workerUrl = new URL(relPath, import.meta.url);\n return new Worker(workerUrl, {\n type: 'module',\n });\n } catch (error) {\n lastError = error instanceof Error ? error : new Error(String(error));\n // Continue to next strategy\n }\n }\n\n // If all strategies failed, throw the last error\n if (lastError) {\n throw lastError;\n }\n throw new Error(\n `Could not resolve worker ${normalizedName} using any available path strategy`\n );\n }\n\n // Node.js/Bun: use import.meta.resolve if available\n if (typeof import.meta.resolve === 'function') {\n try {\n const resolved = import.meta.resolve(\n `${workerConfig.package}/${workerConfig.specifier}`\n );\n return new Worker(resolved, { type: 'module' });\n } catch {\n // Fallback if resolve fails - use relative path as last resort\n }\n }\n\n // Fallback for Bun: use relative path from this file's location\n const platformExt = isBun() ? '.bun.js' : '.node.mjs';\n const baseName = normalizedName.replace('.js', '');\n const relPath = workerConfig.package.includes('resize')\n ? `../../resize/dist/${baseName}.${platformExt.slice(1)}`\n : `../../webp/dist/${baseName}.${platformExt.slice(1)}`;\n\n return new Worker(new URL(relPath, import.meta.url), { type: 'module' });\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : String(error);\n throw new Error(\n `Failed to create worker from ${normalizedName}: ${errorMessage}. ` +\n `Ensure the @squoosh-kit/resize and @squoosh-kit/webp packages are installed. ` +\n `If you're using Vite, ensure the worker files are not being optimized as dependencies.`\n );\n }\n}\n\n/**\n * Create a worker with initialization timeout and ready signal handling\n *\n * This is a higher-level function that creates a worker and waits for it\n * to signal that it's ready to receive messages.\n *\n * @param workerFilename - The name of the worker file\n * @param timeoutMs - Timeout in milliseconds (default: 10000)\n * @returns Promise that resolves to a ready Worker instance\n * @throws Error if worker creation fails or times out\n */\nexport function createReadyWorker(\n workerFilename: string,\n timeoutMs: number = 10000\n): Promise<Worker> {\n return new Promise((resolve, reject) => {\n const timeout = setTimeout(() => {\n reject(\n new Error(\n `Worker initialization timeout after ${timeoutMs}ms. Worker file: ${workerFilename}`\n )\n );\n }, timeoutMs);\n\n let worker: Worker;\n try {\n worker = createCodecWorker(workerFilename);\n } catch (error) {\n clearTimeout(timeout);\n reject(error);\n return;\n }\n\n const handleMessage = (event: MessageEvent) => {\n if (event.data?.type === 'worker:ready') {\n clearTimeout(timeout);\n worker.removeEventListener('message', handleMessage);\n resolve(worker);\n }\n };\n\n worker.addEventListener('message', handleMessage);\n worker.postMessage({ type: 'worker:ping' });\n });\n}\n",
|
|
8
|
+
"/**\n * Bridge implementation for the WebP package, handling worker and client modes.\n */\n\nimport {\n callWorker,\n createReadyWorker,\n type ImageInput,\n} from '@squoosh-kit/runtime';\nimport { validateArrayBuffer, validateImageInput } from '@squoosh-kit/runtime';\nimport type { EncodeInputOptions } from './types';\n\ninterface WebPBridge {\n encode(\n image: ImageInput,\n options?: EncodeInputOptions,\n signal?: AbortSignal\n ): Promise<Uint8Array>;\n terminate(): Promise<void>;\n}\n\nclass WebpClientBridge implements WebPBridge {\n async encode(\n image: ImageInput,\n options?: EncodeInputOptions,\n signal?: AbortSignal\n ): Promise<Uint8Array> {\n // Dynamically import the client encoder to avoid module loading issues in Vite\n const module = await import('./webp.worker.js');\n const webpEncodeClient = module.webpEncodeClient as (\n image: ImageInput,\n options?: EncodeInputOptions,\n signal?: AbortSignal\n ) => Promise<Uint8Array>;\n return webpEncodeClient(image, options, signal);\n }\n\n async terminate(): Promise<void> {\n // Client mode has nothing to terminate\n }\n}\n\nclass WebpWorkerBridge implements WebPBridge {\n private worker: Worker | null = null;\n private workerReady: Promise<Worker> | null = null;\n\n private async getWorker(): Promise<Worker> {\n if (!this.worker) {\n if (!this.workerReady) {\n this.workerReady = this.createWorker();\n }\n this.worker = await this.workerReady;\n }\n return this.worker;\n }\n\n private async createWorker(): Promise<Worker> {\n // Use the centralized worker helper for robust path resolution\n return createReadyWorker('webp.worker');\n }\n\n async encode(\n image: ImageInput,\n options?: EncodeInputOptions,\n signal?: AbortSignal\n ): Promise<Uint8Array> {\n const worker = await this.getWorker();\n\n validateImageInput(image);\n const buffer = image.data.buffer;\n validateArrayBuffer(buffer);\n return callWorker(worker, 'webp:encode', { image, options }, signal, [\n buffer,\n ]);\n }\n\n async terminate(): Promise<void> {\n if (this.worker) {\n this.worker.terminate();\n this.worker = null;\n this.workerReady = null;\n }\n }\n}\n\nexport function createBridge(mode: 'worker' | 'client'): WebPBridge {\n return mode === 'client' ? new WebpClientBridge() : new WebpWorkerBridge();\n}\n"
|
|
9
9
|
],
|
|
10
|
-
"mappings": ";
|
|
11
|
-
"debugId": "
|
|
10
|
+
"mappings": ";oGAyBO,GAAS,CAAK,EAAY,CAC/B,OAAO,OAAO,IAAQ,ICTxB,IAAI,EAAY,EAYhB,eAAsB,CAA+B,CACnD,EACA,EACA,EACA,EACA,EACoB,CACpB,OAAO,IAAI,QAAmB,CAAC,EAAS,IAAW,CACjD,IAAM,EAAK,EAAE,EAGb,GAAI,GAAQ,QAAS,CACnB,EAAO,IAAI,aAAa,UAAW,YAAY,CAAC,EAChD,OAGF,IAAM,EAAgB,CAAC,IAAwB,CAC7C,IAAM,EAAW,EAAM,KACvB,GAAI,EAAS,KAA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KAAM,aAAc,CAAC,EAC3C,EC3IH,MAAM,CAAuC,MACrC,OAAM,CACV,EACA,EACA,EACqB,CAGrB,IAAM,GADS,KAAa,iCACI,iBAKhC,OAAO,EAAiB,EAAO,EAAS,CAAM,OAG1C,UAAS,EAAkB,EAGnC,CAEA,MAAM,CAAuC,CACnC,OAAwB,KACxB,YAAsC,UAEhC,UAAS,EAAoB,CACzC,GAAI,CAAC,KAAK,OAAQ,CAChB,GAAI,CAAC,KAAK,YACR,KAAK,YAAc,KAAK,aAAa,EAEvC,KAAK,OAAS,MAAM,KAAK,YAE3B,OAAO,KAAK,YAGA,aAAY,EAAoB,CAE5C,OAAO,EAAkB,aAAa,OAGlC,OAAM,CACV,EACA,EACA,EACqB,CACrB,IAAM,EAAS,MAAM,KAAK,UAAU,EAEpC,EAAmB,CAAK,EACxB,IAAM,EAAS,EAAM,KAAK,OAE1B,OADA,EAAoB,CAAM,EACnB,EAAW,EAAQ,cAAe,CAAE,QAAO,SAAQ,EAAG,EAAQ,CACnE,CACF,CAAC,OAGG,UAAS,EAAkB,CAC/B,GAAI,KAAK,OACP,KAAK,OAAO,UAAU,EACtB,KAAK,OAAS,KACd,KAAK,YAAc,KAGzB,CAEO,SAAS,CAAY,CAAC,EAAuC,CAClE,OAAO,IAAS,SAAW,IAAI,EAAqB,IAAI",
|
|
11
|
+
"debugId": "A7A7ECF92DCC46BF64756E2164756E21",
|
|
12
12
|
"names": []
|
|
13
13
|
}
|
package/dist/bridge.d.ts
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
* Bridge implementation for the WebP package, handling worker and client modes.
|
|
3
3
|
*/
|
|
4
4
|
import { type ImageInput } from '@squoosh-kit/runtime';
|
|
5
|
-
import type {
|
|
5
|
+
import type { EncodeInputOptions } from './types';
|
|
6
6
|
interface WebPBridge {
|
|
7
|
-
encode(image: ImageInput, options?:
|
|
7
|
+
encode(image: ImageInput, options?: EncodeInputOptions, signal?: AbortSignal): Promise<Uint8Array>;
|
|
8
8
|
terminate(): Promise<void>;
|
|
9
9
|
}
|
|
10
10
|
export declare function createBridge(mode: 'worker' | 'client'): WebPBridge;
|
package/dist/bridge.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bridge.d.ts","sourceRoot":"","sources":["../src/bridge.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAGL,KAAK,UAAU,EAChB,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"bridge.d.ts","sourceRoot":"","sources":["../src/bridge.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAGL,KAAK,UAAU,EAChB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAElD,UAAU,UAAU;IAClB,MAAM,CACJ,KAAK,EAAE,UAAU,EACjB,OAAO,CAAC,EAAE,kBAAkB,EAC5B,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,UAAU,CAAC,CAAC;IACvB,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC5B;AAkED,wBAAgB,YAAY,CAAC,IAAI,EAAE,QAAQ,GAAG,QAAQ,GAAG,UAAU,CAElE"}
|
package/dist/bridge.node.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
var M={};
|
|
1
|
+
var M={};W(M,{createBridge:()=>N});module.exports=E(M);function O(){return typeof Bun<"u"}var q=0;async function U(G,J,V,K,H){return new Promise((L,X)=>{let Q=++q;if(K?.aborted){X(new DOMException("Aborted","AbortError"));return}let Z=(x)=>{let D=x.data;if(D.id!==Q)return;if($(),D.ok&&D.data!==void 0)L(D.data);else X(Error(D.error||"Unknown worker error"))},R=(x)=>{$(),X(Error(`Worker error: ${x.message}`))},_=()=>{$(),X(new DOMException("Aborted","AbortError"))},$=()=>{G.removeEventListener("message",Z),G.removeEventListener("error",R),K?.removeEventListener("abort",_)};G.addEventListener("message",Z),G.addEventListener("error",R),K?.addEventListener("abort",_);let Y={type:J,id:Q,payload:V};if(H&&H.length>0)G.postMessage(Y,H);else G.postMessage(Y)})}function T(G){let J=G.endsWith(".js")?G:`${G}.js`,V={"resize.worker.js":{package:"@squoosh-kit/resize",specifier:"resize.worker.js"},"webp.worker.js":{package:"@squoosh-kit/webp",specifier:"webp.worker.js"}},K=V[J];if(!K)throw Error(`Unknown worker: ${J}. Supported workers: ${Object.keys(V).join(", ")}`);try{if(typeof window<"u"){let Q=K.package.split("/")[1],Z=J.replace(".js",".browser.mjs"),R=[`../../${Q}/dist/${Z}`,`../../../node_modules/@squoosh-kit/${Q}/dist/${Z}`,`../../../${Q}/dist/${Z}`],_=null;for(let $ of R)try{let Y=new URL($,"file:///home/bnowak/repos/squoosh-kit/packages/runtime/src/worker-helper.ts");return new Worker(Y,{type:"module"})}catch(Y){_=Y instanceof Error?Y:Error(String(Y))}if(_)throw _;throw Error(`Could not resolve worker ${J} using any available path strategy`)}if(typeof import.meta.resolve==="function")try{let Q=import.meta.resolve(`${K.package}/${K.specifier}`);return new Worker(Q,{type:"module"})}catch{}let H=O()?".bun.js":".node.mjs",L=J.replace(".js",""),X=K.package.includes("resize")?`../../resize/dist/${L}.${H.slice(1)}`:`../../webp/dist/${L}.${H.slice(1)}`;return new Worker(new URL(X,"file:///home/bnowak/repos/squoosh-kit/packages/runtime/src/worker-helper.ts"),{type:"module"})}catch(H){let L=H instanceof Error?H.message:String(H);throw Error(`Failed to create worker from ${J}: ${L}. Ensure the @squoosh-kit/resize and @squoosh-kit/webp packages are installed. If you're using Vite, ensure the worker files are not being optimized as dependencies.`)}}function A(G,J=1e4){return new Promise((V,K)=>{let H=setTimeout(()=>{K(Error(`Worker initialization timeout after ${J}ms. Worker file: ${G}`))},J),L;try{L=T(G)}catch(Q){clearTimeout(H),K(Q);return}let X=(Q)=>{if(Q.data?.type==="worker:ready")clearTimeout(H),L.removeEventListener("message",X),V(L)};L.addEventListener("message",X),L.postMessage({type:"worker:ping"})})}class S{async encode(G,J,V){let H=(await import("./webp.worker.node.cjs")).webpEncodeClient;return H(G,J,V)}async terminate(){}}class B{worker=null;workerReady=null;async getWorker(){if(!this.worker){if(!this.workerReady)this.workerReady=this.createWorker();this.worker=await this.workerReady}return this.worker}async createWorker(){return A("webp.worker")}async encode(G,J,V){let K=await this.getWorker();P(G);let H=G.data.buffer;return I(H),U(K,"webp:encode",{image:G,options:J},V,[H])}async terminate(){if(this.worker)this.worker.terminate(),this.worker=null,this.workerReady=null}}function N(G){return G==="client"?new S:new B}
|
|
2
2
|
|
|
3
|
-
//# debugId=
|
|
3
|
+
//# debugId=377ADCB638D525EB64756E2164756E21
|
package/dist/bridge.node.cjs.map
CHANGED
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
"sourcesContent": [
|
|
5
5
|
"/**\n * Runtime environment detection utilities\n */\n\n/**\n * Detect if running in a Web Worker context\n */\nexport function isWorker(): boolean {\n return (\n typeof self !== 'undefined' &&\n typeof (globalThis as unknown as { DedicatedWorkerGlobalScope?: unknown })\n .DedicatedWorkerGlobalScope !== 'undefined'\n );\n}\n\n/**\n * Detect if running in a browser context\n */\nexport function isBrowser(): boolean {\n return typeof window !== 'undefined' && typeof document !== 'undefined';\n}\n\n/**\n * Detect if running in Bun\n */\nexport function isBun(): boolean {\n return typeof Bun !== 'undefined';\n}\n\n/**\n * Detect if running in Node.js\n */\nexport function isNode(): boolean {\n return (\n typeof process !== 'undefined' &&\n process.versions != null &&\n process.versions.node != null\n );\n}\n\n/**\n * Check if ImageData is available in the current environment\n */\nexport function hasImageData(): boolean {\n return typeof ImageData !== 'undefined';\n}\n",
|
|
6
6
|
"/**\n * Generic worker communication helper with support for transferables and AbortSignal\n */\n\nexport interface WorkerRequest<T = unknown> {\n type: string;\n id: number;\n payload: T;\n}\n\nexport interface WorkerResponse<T = unknown> {\n id: number;\n ok: boolean;\n data?: T;\n error?: string;\n}\n\nlet requestId = 0;\n\n/**\n * Call a worker with a typed request and wait for response\n *\n * @param worker - The worker instance to call\n * @param type - The message type\n * @param payload - The payload to send\n * @param signal - Optional AbortSignal to cancel the operation\n * @param transfer - Optional list of Transferable objects to transfer\n * @returns Promise that resolves with the worker's response data\n */\nexport async function callWorker<TPayload, TResponse>(\n worker: Worker,\n type: string,\n payload: TPayload,\n signal?: AbortSignal,\n transfer?: Transferable[]\n): Promise<TResponse> {\n return new Promise<TResponse>((resolve, reject) => {\n const id = ++requestId;\n\n // Check if already aborted\n if (signal?.aborted) {\n reject(new DOMException('Aborted', 'AbortError'));\n return;\n }\n\n const handleMessage = (event: MessageEvent) => {\n const response = event.data as WorkerResponse<TResponse>;\n if (response.id !== id) return;\n\n cleanup();\n\n if (response.ok && response.data !== undefined) {\n resolve(response.data);\n } else {\n reject(new Error(response.error || 'Unknown worker error'));\n }\n };\n\n const handleError = (error: ErrorEvent) => {\n cleanup();\n reject(new Error(`Worker error: ${error.message}`));\n };\n\n const handleAbort = () => {\n cleanup();\n reject(new DOMException('Aborted', 'AbortError'));\n };\n\n const cleanup = () => {\n worker.removeEventListener('message', handleMessage);\n worker.removeEventListener('error', handleError);\n signal?.removeEventListener('abort', handleAbort);\n };\n\n // Set up listeners\n worker.addEventListener('message', handleMessage);\n worker.addEventListener('error', handleError);\n signal?.addEventListener('abort', handleAbort);\n\n // Send the request\n const request: WorkerRequest<TPayload> = { type, id, payload };\n\n if (transfer && transfer.length > 0) {\n worker.postMessage(request, transfer);\n } else {\n worker.postMessage(request);\n }\n });\n}\n",
|
|
7
|
-
"/**\n * Worker helper utilities for creating and managing Web Workers\n *\n * This module provides centralized logic for creating worker instances\n * in different environments (browser, Node.js, Bun) using import.meta.resolve\n * for server-side and package-relative paths for browsers.\n */\n\nimport { isBun } from './env';\n\n/**\n * Create a Web Worker for a specific codec\n *\n * In Node.js/Bun environments, uses import.meta.resolve to locate worker files.\n * In browser environments, uses relative paths within node_modules that Vite can resolve.\n *\n * @param workerFilename - The name of the worker file (e.g., 'resize.worker' or 'webp.worker')\n * @returns Worker instance\n * @throws Error if worker creation fails with detailed error message\n */\nexport function createCodecWorker(workerFilename: string): Worker {\n // Ensure filename has correct format\n const normalizedName = workerFilename.endsWith('.js')\n ? workerFilename\n : `${workerFilename}.js`;\n\n // Map worker filenames to their package and export\n const workerMap: Record<string, { package: string; specifier: string }> = {\n 'resize.worker.js': {\n package: '@squoosh-kit/resize',\n specifier: 'resize.worker.js',\n },\n 'webp.worker.js': {\n package: '@squoosh-kit/webp',\n specifier: 'webp.worker.js',\n },\n };\n\n const workerConfig = workerMap[normalizedName];\n if (!workerConfig) {\n throw new Error(\n `Unknown worker: ${normalizedName}. ` +\n `Supported workers: ${Object.keys(workerMap).join(', ')}`\n );\n }\n\n try {\n // In browser contexts, use relative paths within the installed packages\n if (typeof window !== 'undefined') {\n const packageName = workerConfig.package.split('/')[1]; // Extract 'resize' or 'webp'\n const workerFile = normalizedName.replace('.js', '.browser.mjs');\n\n // Try multiple path strategies to support both:\n // 1. Monorepo development structure: ../../{package}/dist/{workerFile}\n // 2. npm installed structure: ../../../{package}/dist/{workerFile}\n const pathStrategies = [\n // First try monorepo structure (when runtime is at packages/runtime/src)\n `../../${packageName}/dist/${workerFile}`,\n // Then try npm structure (when runtime is at node_modules/@squoosh-kit/runtime)\n `../../../node_modules/@squoosh-kit/${packageName}/dist/${workerFile}`,\n // Alternative npm structure for cases where packages are flattened\n `../../../${packageName}/dist/${workerFile}`,\n ];\n\n let lastError: Error | null = null;\n\n for (const relPath of pathStrategies) {\n try {\n const workerUrl = new URL(relPath, import.meta.url);\n return new Worker(workerUrl, {\n type: 'module',\n });\n } catch (error) {\n lastError = error instanceof Error ? error : new Error(String(error));\n // Continue to next strategy\n }\n }\n\n // If all strategies failed, throw the last error\n if (lastError) {\n throw lastError;\n }\n throw new Error(\n `Could not resolve worker ${normalizedName} using any available path strategy`\n );\n }\n\n // Node.js/Bun: use import.meta.resolve if available\n if (typeof import.meta.resolve === 'function') {\n const resolved = import.meta.resolve(\n
|
|
8
|
-
"/**\n * Bridge implementation for the WebP package, handling worker and client modes.\n */\n\nimport {\n callWorker,\n createReadyWorker,\n type ImageInput,\n} from '@squoosh-kit/runtime';\nimport { validateArrayBuffer, validateImageInput } from '@squoosh-kit/runtime';\nimport
|
|
7
|
+
"/**\n * Worker helper utilities for creating and managing Web Workers\n *\n * This module provides centralized logic for creating worker instances\n * in different environments (browser, Node.js, Bun) using import.meta.resolve\n * for server-side and package-relative paths for browsers.\n */\n\nimport { isBun } from './env';\n\n/**\n * Create a Web Worker for a specific codec\n *\n * In Node.js/Bun environments, uses import.meta.resolve to locate worker files.\n * In browser environments, uses relative paths within node_modules that Vite can resolve.\n *\n * @param workerFilename - The name of the worker file (e.g., 'resize.worker' or 'webp.worker')\n * @returns Worker instance\n * @throws Error if worker creation fails with detailed error message\n */\nexport function createCodecWorker(workerFilename: string): Worker {\n // Ensure filename has correct format\n const normalizedName = workerFilename.endsWith('.js')\n ? workerFilename\n : `${workerFilename}.js`;\n\n // Map worker filenames to their package and export\n const workerMap: Record<string, { package: string; specifier: string }> = {\n 'resize.worker.js': {\n package: '@squoosh-kit/resize',\n specifier: 'resize.worker.js',\n },\n 'webp.worker.js': {\n package: '@squoosh-kit/webp',\n specifier: 'webp.worker.js',\n },\n };\n\n const workerConfig = workerMap[normalizedName];\n if (!workerConfig) {\n throw new Error(\n `Unknown worker: ${normalizedName}. ` +\n `Supported workers: ${Object.keys(workerMap).join(', ')}`\n );\n }\n\n try {\n // In browser contexts, use relative paths within the installed packages\n if (typeof window !== 'undefined') {\n const packageName = workerConfig.package.split('/')[1]; // Extract 'resize' or 'webp'\n const workerFile = normalizedName.replace('.js', '.browser.mjs');\n\n // Try multiple path strategies to support both:\n // 1. Monorepo development structure: ../../{package}/dist/{workerFile}\n // 2. npm installed structure: ../../../{package}/dist/{workerFile}\n const pathStrategies = [\n // First try monorepo structure (when runtime is at packages/runtime/src)\n `../../${packageName}/dist/${workerFile}`,\n // Then try npm structure (when runtime is at node_modules/@squoosh-kit/runtime)\n `../../../node_modules/@squoosh-kit/${packageName}/dist/${workerFile}`,\n // Alternative npm structure for cases where packages are flattened\n `../../../${packageName}/dist/${workerFile}`,\n ];\n\n let lastError: Error | null = null;\n\n for (const relPath of pathStrategies) {\n try {\n const workerUrl = new URL(relPath, import.meta.url);\n return new Worker(workerUrl, {\n type: 'module',\n });\n } catch (error) {\n lastError = error instanceof Error ? error : new Error(String(error));\n // Continue to next strategy\n }\n }\n\n // If all strategies failed, throw the last error\n if (lastError) {\n throw lastError;\n }\n throw new Error(\n `Could not resolve worker ${normalizedName} using any available path strategy`\n );\n }\n\n // Node.js/Bun: use import.meta.resolve if available\n if (typeof import.meta.resolve === 'function') {\n try {\n const resolved = import.meta.resolve(\n `${workerConfig.package}/${workerConfig.specifier}`\n );\n return new Worker(resolved, { type: 'module' });\n } catch {\n // Fallback if resolve fails - use relative path as last resort\n }\n }\n\n // Fallback for Bun: use relative path from this file's location\n const platformExt = isBun() ? '.bun.js' : '.node.mjs';\n const baseName = normalizedName.replace('.js', '');\n const relPath = workerConfig.package.includes('resize')\n ? `../../resize/dist/${baseName}.${platformExt.slice(1)}`\n : `../../webp/dist/${baseName}.${platformExt.slice(1)}`;\n\n return new Worker(new URL(relPath, import.meta.url), { type: 'module' });\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : String(error);\n throw new Error(\n `Failed to create worker from ${normalizedName}: ${errorMessage}. ` +\n `Ensure the @squoosh-kit/resize and @squoosh-kit/webp packages are installed. ` +\n `If you're using Vite, ensure the worker files are not being optimized as dependencies.`\n );\n }\n}\n\n/**\n * Create a worker with initialization timeout and ready signal handling\n *\n * This is a higher-level function that creates a worker and waits for it\n * to signal that it's ready to receive messages.\n *\n * @param workerFilename - The name of the worker file\n * @param timeoutMs - Timeout in milliseconds (default: 10000)\n * @returns Promise that resolves to a ready Worker instance\n * @throws Error if worker creation fails or times out\n */\nexport function createReadyWorker(\n workerFilename: string,\n timeoutMs: number = 10000\n): Promise<Worker> {\n return new Promise((resolve, reject) => {\n const timeout = setTimeout(() => {\n reject(\n new Error(\n `Worker initialization timeout after ${timeoutMs}ms. Worker file: ${workerFilename}`\n )\n );\n }, timeoutMs);\n\n let worker: Worker;\n try {\n worker = createCodecWorker(workerFilename);\n } catch (error) {\n clearTimeout(timeout);\n reject(error);\n return;\n }\n\n const handleMessage = (event: MessageEvent) => {\n if (event.data?.type === 'worker:ready') {\n clearTimeout(timeout);\n worker.removeEventListener('message', handleMessage);\n resolve(worker);\n }\n };\n\n worker.addEventListener('message', handleMessage);\n worker.postMessage({ type: 'worker:ping' });\n });\n}\n",
|
|
8
|
+
"/**\n * Bridge implementation for the WebP package, handling worker and client modes.\n */\n\nimport {\n callWorker,\n createReadyWorker,\n type ImageInput,\n} from '@squoosh-kit/runtime';\nimport { validateArrayBuffer, validateImageInput } from '@squoosh-kit/runtime';\nimport type { EncodeInputOptions } from './types';\n\ninterface WebPBridge {\n encode(\n image: ImageInput,\n options?: EncodeInputOptions,\n signal?: AbortSignal\n ): Promise<Uint8Array>;\n terminate(): Promise<void>;\n}\n\nclass WebpClientBridge implements WebPBridge {\n async encode(\n image: ImageInput,\n options?: EncodeInputOptions,\n signal?: AbortSignal\n ): Promise<Uint8Array> {\n // Dynamically import the client encoder to avoid module loading issues in Vite\n const module = await import('./webp.worker.js');\n const webpEncodeClient = module.webpEncodeClient as (\n image: ImageInput,\n options?: EncodeInputOptions,\n signal?: AbortSignal\n ) => Promise<Uint8Array>;\n return webpEncodeClient(image, options, signal);\n }\n\n async terminate(): Promise<void> {\n // Client mode has nothing to terminate\n }\n}\n\nclass WebpWorkerBridge implements WebPBridge {\n private worker: Worker | null = null;\n private workerReady: Promise<Worker> | null = null;\n\n private async getWorker(): Promise<Worker> {\n if (!this.worker) {\n if (!this.workerReady) {\n this.workerReady = this.createWorker();\n }\n this.worker = await this.workerReady;\n }\n return this.worker;\n }\n\n private async createWorker(): Promise<Worker> {\n // Use the centralized worker helper for robust path resolution\n return createReadyWorker('webp.worker');\n }\n\n async encode(\n image: ImageInput,\n options?: EncodeInputOptions,\n signal?: AbortSignal\n ): Promise<Uint8Array> {\n const worker = await this.getWorker();\n\n validateImageInput(image);\n const buffer = image.data.buffer;\n validateArrayBuffer(buffer);\n return callWorker(worker, 'webp:encode', { image, options }, signal, [\n buffer,\n ]);\n }\n\n async terminate(): Promise<void> {\n if (this.worker) {\n this.worker.terminate();\n this.worker = null;\n this.workerReady = null;\n }\n }\n}\n\nexport function createBridge(mode: 'worker' | 'client'): WebPBridge {\n return mode === 'client' ? new WebpClientBridge() : new WebpWorkerBridge();\n}\n"
|
|
9
9
|
],
|
|
10
|
-
"mappings": "uDAyBO,SAAS,CAAK,EAAY,CAC/B,OAAO,OAAO,IAAQ,ICTxB,IAAI,EAAY,EAYhB,eAAsB,CAA+B,CACnD,EACA,EACA,EACA,EACA,EACoB,CACpB,OAAO,IAAI,QAAmB,CAAC,EAAS,IAAW,CACjD,IAAM,EAAK,EAAE,EAGb,GAAI,GAAQ,QAAS,CACnB,EAAO,IAAI,aAAa,UAAW,YAAY,CAAC,EAChD,OAGF,IAAM,EAAgB,CAAC,IAAwB,CAC7C,IAAM,EAAW,EAAM,KACvB,GAAI,EAAS,KAAO,EAAI,OAIxB,GAFA,EAAQ,EAEJ,EAAS,IAAM,EAAS,OAAS,OACnC,EAAQ,EAAS,IAAI,EAErB,OAAW,MAAM,EAAS,OAAS,sBAAsB,CAAC,GAIxD,EAAc,CAAC,IAAsB,CACzC,EAAQ,EACR,EAAW,MAAM,iBAAiB,EAAM,SAAS,CAAC,GAG9C,EAAc,IAAM,CACxB,EAAQ,EACR,EAAO,IAAI,aAAa,UAAW,YAAY,CAAC,GAG5C,EAAU,IAAM,CACpB,EAAO,oBAAoB,UAAW,CAAa,EACnD,EAAO,oBAAoB,QAAS,CAAW,EAC/C,GAAQ,oBAAoB,QAAS,CAAW,GAIlD,EAAO,iBAAiB,UAAW,CAAa,EAChD,EAAO,iBAAiB,QAAS,CAAW,EAC5C,GAAQ,i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S,KAAa,mCACI,iBAKhC,OAAO,EAAiB,EAAO,EAAS,CAAM,OAG1C,UAAS,EAAkB,EAGnC,CAEA,MAAM,CAAuC,CACnC,OAAwB,KACxB,YAAsC,UAEhC,UAAS,EAAoB,CACzC,GAAI,CAAC,KAAK,OAAQ,CAChB,GAAI,CAAC,KAAK,YACR,KAAK,YAAc,KAAK,aAAa,EAEvC,KAAK,OAAS,MAAM,KAAK,YAE3B,OAAO,KAAK,YAGA,aAAY,EAAoB,CAE5C,OAAO,EAAkB,aAAa,OAGlC,OAAM,CACV,EACA,EACA,EACqB,CACrB,IAAM,EAAS,MAAM,KAAK,UAAU,EAEpC,EAAmB,CAAK,EACxB,IAAM,EAAS,EAAM,KAAK,OAE1B,OADA,EAAoB,CAAM,EACnB,EAAW,EAAQ,cAAe,CAAE,QAAO,SAAQ,EAAG,EAAQ,CACnE,CACF,CAAC,OAGG,UAAS,EAAkB,CAC/B,GAAI,KAAK,OACP,KAAK,OAAO,UAAU,EACtB,KAAK,OAAS,KACd,KAAK,YAAc,KAGzB,CAEO,SAAS,CAAY,CAAC,EAAuC,CAClE,OAAO,IAAS,SAAW,IAAI,EAAqB,IAAI",
|
|
11
|
+
"debugId": "377ADCB638D525EB64756E2164756E21",
|
|
12
12
|
"names": []
|
|
13
13
|
}
|
package/dist/bridge.node.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{b as
|
|
1
|
+
import{b as I,c as P}from"./chunk-nscv6dhm.js";import{e as z,f as E}from"./chunk-ks7kcgv0.js";function O(){return typeof Bun<"u"}var q=0;async function U(G,J,V,K,H){return new Promise((L,X)=>{let Q=++q;if(K?.aborted){X(new DOMException("Aborted","AbortError"));return}let Z=(x)=>{let D=x.data;if(D.id!==Q)return;if($(),D.ok&&D.data!==void 0)L(D.data);else X(Error(D.error||"Unknown worker error"))},R=(x)=>{$(),X(Error(`Worker error: ${x.message}`))},_=()=>{$(),X(new DOMException("Aborted","AbortError"))},$=()=>{G.removeEventListener("message",Z),G.removeEventListener("error",R),K?.removeEventListener("abort",_)};G.addEventListener("message",Z),G.addEventListener("error",R),K?.addEventListener("abort",_);let Y={type:J,id:Q,payload:V};if(H&&H.length>0)G.postMessage(Y,H);else G.postMessage(Y)})}function T(G){let J=G.endsWith(".js")?G:`${G}.js`,V={"resize.worker.js":{package:"@squoosh-kit/resize",specifier:"resize.worker.js"},"webp.worker.js":{package:"@squoosh-kit/webp",specifier:"webp.worker.js"}},K=V[J];if(!K)throw Error(`Unknown worker: ${J}. Supported workers: ${Object.keys(V).join(", ")}`);try{if(typeof window<"u"){let Q=K.package.split("/")[1],Z=J.replace(".js",".browser.mjs"),R=[`../../${Q}/dist/${Z}`,`../../../node_modules/@squoosh-kit/${Q}/dist/${Z}`,`../../../${Q}/dist/${Z}`],_=null;for(let $ of R)try{let Y=new URL($,import.meta.url);return new Worker(Y,{type:"module"})}catch(Y){_=Y instanceof Error?Y:Error(String(Y))}if(_)throw _;throw Error(`Could not resolve worker ${J} using any available path strategy`)}if(typeof import.meta.resolve==="function")try{let Q=import.meta.resolve(`${K.package}/${K.specifier}`);return new Worker(Q,{type:"module"})}catch{}let H=O()?".bun.js":".node.mjs",L=J.replace(".js",""),X=K.package.includes("resize")?`../../resize/dist/${L}.${H.slice(1)}`:`../../webp/dist/${L}.${H.slice(1)}`;return new Worker(new URL(X,import.meta.url),{type:"module"})}catch(H){let L=H instanceof Error?H.message:String(H);throw Error(`Failed to create worker from ${J}: ${L}. Ensure the @squoosh-kit/resize and @squoosh-kit/webp packages are installed. If you're using Vite, ensure the worker files are not being optimized as dependencies.`)}}function A(G,J=1e4){return new Promise((V,K)=>{let H=setTimeout(()=>{K(Error(`Worker initialization timeout after ${J}ms. Worker file: ${G}`))},J),L;try{L=T(G)}catch(Q){clearTimeout(H),K(Q);return}let X=(Q)=>{if(Q.data?.type==="worker:ready")clearTimeout(H),L.removeEventListener("message",X),V(L)};L.addEventListener("message",X),L.postMessage({type:"worker:ping"})})}class S{async encode(G,J,V){let H=(await import("./webp.worker.node.mjs")).webpEncodeClient;return H(G,J,V)}async terminate(){}}class B{worker=null;workerReady=null;async getWorker(){if(!this.worker){if(!this.workerReady)this.workerReady=this.createWorker();this.worker=await this.workerReady}return this.worker}async createWorker(){return A("webp.worker")}async encode(G,J,V){let K=await this.getWorker();P(G);let H=G.data.buffer;return I(H),U(K,"webp:encode",{image:G,options:J},V,[H])}async terminate(){if(this.worker)this.worker.terminate(),this.worker=null,this.workerReady=null}}function y(G){return G==="client"?new S:new B}export{y as createBridge};
|
|
2
2
|
export{y as a};
|
|
3
3
|
|
|
4
|
-
//# debugId=
|
|
4
|
+
//# debugId=000D23DB9916FD9564756E2164756E21
|
package/dist/bridge.node.mjs.map
CHANGED
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
"sourcesContent": [
|
|
5
5
|
"/**\n * Runtime environment detection utilities\n */\n\n/**\n * Detect if running in a Web Worker context\n */\nexport function isWorker(): boolean {\n return (\n typeof self !== 'undefined' &&\n typeof (globalThis as unknown as { DedicatedWorkerGlobalScope?: unknown })\n .DedicatedWorkerGlobalScope !== 'undefined'\n );\n}\n\n/**\n * Detect if running in a browser context\n */\nexport function isBrowser(): boolean {\n return typeof window !== 'undefined' && typeof document !== 'undefined';\n}\n\n/**\n * Detect if running in Bun\n */\nexport function isBun(): boolean {\n return typeof Bun !== 'undefined';\n}\n\n/**\n * Detect if running in Node.js\n */\nexport function isNode(): boolean {\n return (\n typeof process !== 'undefined' &&\n process.versions != null &&\n process.versions.node != null\n );\n}\n\n/**\n * Check if ImageData is available in the current environment\n */\nexport function hasImageData(): boolean {\n return typeof ImageData !== 'undefined';\n}\n",
|
|
6
6
|
"/**\n * Generic worker communication helper with support for transferables and AbortSignal\n */\n\nexport interface WorkerRequest<T = unknown> {\n type: string;\n id: number;\n payload: T;\n}\n\nexport interface WorkerResponse<T = unknown> {\n id: number;\n ok: boolean;\n data?: T;\n error?: string;\n}\n\nlet requestId = 0;\n\n/**\n * Call a worker with a typed request and wait for response\n *\n * @param worker - The worker instance to call\n * @param type - The message type\n * @param payload - The payload to send\n * @param signal - Optional AbortSignal to cancel the operation\n * @param transfer - Optional list of Transferable objects to transfer\n * @returns Promise that resolves with the worker's response data\n */\nexport async function callWorker<TPayload, TResponse>(\n worker: Worker,\n type: string,\n payload: TPayload,\n signal?: AbortSignal,\n transfer?: Transferable[]\n): Promise<TResponse> {\n return new Promise<TResponse>((resolve, reject) => {\n const id = ++requestId;\n\n // Check if already aborted\n if (signal?.aborted) {\n reject(new DOMException('Aborted', 'AbortError'));\n return;\n }\n\n const handleMessage = (event: MessageEvent) => {\n const response = event.data as WorkerResponse<TResponse>;\n if (response.id !== id) return;\n\n cleanup();\n\n if (response.ok && response.data !== undefined) {\n resolve(response.data);\n } else {\n reject(new Error(response.error || 'Unknown worker error'));\n }\n };\n\n const handleError = (error: ErrorEvent) => {\n cleanup();\n reject(new Error(`Worker error: ${error.message}`));\n };\n\n const handleAbort = () => {\n cleanup();\n reject(new DOMException('Aborted', 'AbortError'));\n };\n\n const cleanup = () => {\n worker.removeEventListener('message', handleMessage);\n worker.removeEventListener('error', handleError);\n signal?.removeEventListener('abort', handleAbort);\n };\n\n // Set up listeners\n worker.addEventListener('message', handleMessage);\n worker.addEventListener('error', handleError);\n signal?.addEventListener('abort', handleAbort);\n\n // Send the request\n const request: WorkerRequest<TPayload> = { type, id, payload };\n\n if (transfer && transfer.length > 0) {\n worker.postMessage(request, transfer);\n } else {\n worker.postMessage(request);\n }\n });\n}\n",
|
|
7
|
-
"/**\n * Worker helper utilities for creating and managing Web Workers\n *\n * This module provides centralized logic for creating worker instances\n * in different environments (browser, Node.js, Bun) using import.meta.resolve\n * for server-side and package-relative paths for browsers.\n */\n\nimport { isBun } from './env';\n\n/**\n * Create a Web Worker for a specific codec\n *\n * In Node.js/Bun environments, uses import.meta.resolve to locate worker files.\n * In browser environments, uses relative paths within node_modules that Vite can resolve.\n *\n * @param workerFilename - The name of the worker file (e.g., 'resize.worker' or 'webp.worker')\n * @returns Worker instance\n * @throws Error if worker creation fails with detailed error message\n */\nexport function createCodecWorker(workerFilename: string): Worker {\n // Ensure filename has correct format\n const normalizedName = workerFilename.endsWith('.js')\n ? workerFilename\n : `${workerFilename}.js`;\n\n // Map worker filenames to their package and export\n const workerMap: Record<string, { package: string; specifier: string }> = {\n 'resize.worker.js': {\n package: '@squoosh-kit/resize',\n specifier: 'resize.worker.js',\n },\n 'webp.worker.js': {\n package: '@squoosh-kit/webp',\n specifier: 'webp.worker.js',\n },\n };\n\n const workerConfig = workerMap[normalizedName];\n if (!workerConfig) {\n throw new Error(\n `Unknown worker: ${normalizedName}. ` +\n `Supported workers: ${Object.keys(workerMap).join(', ')}`\n );\n }\n\n try {\n // In browser contexts, use relative paths within the installed packages\n if (typeof window !== 'undefined') {\n const packageName = workerConfig.package.split('/')[1]; // Extract 'resize' or 'webp'\n const workerFile = normalizedName.replace('.js', '.browser.mjs');\n\n // Try multiple path strategies to support both:\n // 1. Monorepo development structure: ../../{package}/dist/{workerFile}\n // 2. npm installed structure: ../../../{package}/dist/{workerFile}\n const pathStrategies = [\n // First try monorepo structure (when runtime is at packages/runtime/src)\n `../../${packageName}/dist/${workerFile}`,\n // Then try npm structure (when runtime is at node_modules/@squoosh-kit/runtime)\n `../../../node_modules/@squoosh-kit/${packageName}/dist/${workerFile}`,\n // Alternative npm structure for cases where packages are flattened\n `../../../${packageName}/dist/${workerFile}`,\n ];\n\n let lastError: Error | null = null;\n\n for (const relPath of pathStrategies) {\n try {\n const workerUrl = new URL(relPath, import.meta.url);\n return new Worker(workerUrl, {\n type: 'module',\n });\n } catch (error) {\n lastError = error instanceof Error ? error : new Error(String(error));\n // Continue to next strategy\n }\n }\n\n // If all strategies failed, throw the last error\n if (lastError) {\n throw lastError;\n }\n throw new Error(\n `Could not resolve worker ${normalizedName} using any available path strategy`\n );\n }\n\n // Node.js/Bun: use import.meta.resolve if available\n if (typeof import.meta.resolve === 'function') {\n const resolved = import.meta.resolve(\n
|
|
8
|
-
"/**\n * Bridge implementation for the WebP package, handling worker and client modes.\n */\n\nimport {\n callWorker,\n createReadyWorker,\n type ImageInput,\n} from '@squoosh-kit/runtime';\nimport { validateArrayBuffer, validateImageInput } from '@squoosh-kit/runtime';\nimport
|
|
7
|
+
"/**\n * Worker helper utilities for creating and managing Web Workers\n *\n * This module provides centralized logic for creating worker instances\n * in different environments (browser, Node.js, Bun) using import.meta.resolve\n * for server-side and package-relative paths for browsers.\n */\n\nimport { isBun } from './env';\n\n/**\n * Create a Web Worker for a specific codec\n *\n * In Node.js/Bun environments, uses import.meta.resolve to locate worker files.\n * In browser environments, uses relative paths within node_modules that Vite can resolve.\n *\n * @param workerFilename - The name of the worker file (e.g., 'resize.worker' or 'webp.worker')\n * @returns Worker instance\n * @throws Error if worker creation fails with detailed error message\n */\nexport function createCodecWorker(workerFilename: string): Worker {\n // Ensure filename has correct format\n const normalizedName = workerFilename.endsWith('.js')\n ? workerFilename\n : `${workerFilename}.js`;\n\n // Map worker filenames to their package and export\n const workerMap: Record<string, { package: string; specifier: string }> = {\n 'resize.worker.js': {\n package: '@squoosh-kit/resize',\n specifier: 'resize.worker.js',\n },\n 'webp.worker.js': {\n package: '@squoosh-kit/webp',\n specifier: 'webp.worker.js',\n },\n };\n\n const workerConfig = workerMap[normalizedName];\n if (!workerConfig) {\n throw new Error(\n `Unknown worker: ${normalizedName}. ` +\n `Supported workers: ${Object.keys(workerMap).join(', ')}`\n );\n }\n\n try {\n // In browser contexts, use relative paths within the installed packages\n if (typeof window !== 'undefined') {\n const packageName = workerConfig.package.split('/')[1]; // Extract 'resize' or 'webp'\n const workerFile = normalizedName.replace('.js', '.browser.mjs');\n\n // Try multiple path strategies to support both:\n // 1. Monorepo development structure: ../../{package}/dist/{workerFile}\n // 2. npm installed structure: ../../../{package}/dist/{workerFile}\n const pathStrategies = [\n // First try monorepo structure (when runtime is at packages/runtime/src)\n `../../${packageName}/dist/${workerFile}`,\n // Then try npm structure (when runtime is at node_modules/@squoosh-kit/runtime)\n `../../../node_modules/@squoosh-kit/${packageName}/dist/${workerFile}`,\n // Alternative npm structure for cases where packages are flattened\n `../../../${packageName}/dist/${workerFile}`,\n ];\n\n let lastError: Error | null = null;\n\n for (const relPath of pathStrategies) {\n try {\n const workerUrl = new URL(relPath, import.meta.url);\n return new Worker(workerUrl, {\n type: 'module',\n });\n } catch (error) {\n lastError = error instanceof Error ? error : new Error(String(error));\n // Continue to next strategy\n }\n }\n\n // If all strategies failed, throw the last error\n if (lastError) {\n throw lastError;\n }\n throw new Error(\n `Could not resolve worker ${normalizedName} using any available path strategy`\n );\n }\n\n // Node.js/Bun: use import.meta.resolve if available\n if (typeof import.meta.resolve === 'function') {\n try {\n const resolved = import.meta.resolve(\n `${workerConfig.package}/${workerConfig.specifier}`\n );\n return new Worker(resolved, { type: 'module' });\n } catch {\n // Fallback if resolve fails - use relative path as last resort\n }\n }\n\n // Fallback for Bun: use relative path from this file's location\n const platformExt = isBun() ? '.bun.js' : '.node.mjs';\n const baseName = normalizedName.replace('.js', '');\n const relPath = workerConfig.package.includes('resize')\n ? `../../resize/dist/${baseName}.${platformExt.slice(1)}`\n : `../../webp/dist/${baseName}.${platformExt.slice(1)}`;\n\n return new Worker(new URL(relPath, import.meta.url), { type: 'module' });\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : String(error);\n throw new Error(\n `Failed to create worker from ${normalizedName}: ${errorMessage}. ` +\n `Ensure the @squoosh-kit/resize and @squoosh-kit/webp packages are installed. ` +\n `If you're using Vite, ensure the worker files are not being optimized as dependencies.`\n );\n }\n}\n\n/**\n * Create a worker with initialization timeout and ready signal handling\n *\n * This is a higher-level function that creates a worker and waits for it\n * to signal that it's ready to receive messages.\n *\n * @param workerFilename - The name of the worker file\n * @param timeoutMs - Timeout in milliseconds (default: 10000)\n * @returns Promise that resolves to a ready Worker instance\n * @throws Error if worker creation fails or times out\n */\nexport function createReadyWorker(\n workerFilename: string,\n timeoutMs: number = 10000\n): Promise<Worker> {\n return new Promise((resolve, reject) => {\n const timeout = setTimeout(() => {\n reject(\n new Error(\n `Worker initialization timeout after ${timeoutMs}ms. Worker file: ${workerFilename}`\n )\n );\n }, timeoutMs);\n\n let worker: Worker;\n try {\n worker = createCodecWorker(workerFilename);\n } catch (error) {\n clearTimeout(timeout);\n reject(error);\n return;\n }\n\n const handleMessage = (event: MessageEvent) => {\n if (event.data?.type === 'worker:ready') {\n clearTimeout(timeout);\n worker.removeEventListener('message', handleMessage);\n resolve(worker);\n }\n };\n\n worker.addEventListener('message', handleMessage);\n worker.postMessage({ type: 'worker:ping' });\n });\n}\n",
|
|
8
|
+
"/**\n * Bridge implementation for the WebP package, handling worker and client modes.\n */\n\nimport {\n callWorker,\n createReadyWorker,\n type ImageInput,\n} from '@squoosh-kit/runtime';\nimport { validateArrayBuffer, validateImageInput } from '@squoosh-kit/runtime';\nimport type { EncodeInputOptions } from './types';\n\ninterface WebPBridge {\n encode(\n image: ImageInput,\n options?: EncodeInputOptions,\n signal?: AbortSignal\n ): Promise<Uint8Array>;\n terminate(): Promise<void>;\n}\n\nclass WebpClientBridge implements WebPBridge {\n async encode(\n image: ImageInput,\n options?: EncodeInputOptions,\n signal?: AbortSignal\n ): Promise<Uint8Array> {\n // Dynamically import the client encoder to avoid module loading issues in Vite\n const module = await import('./webp.worker.js');\n const webpEncodeClient = module.webpEncodeClient as (\n image: ImageInput,\n options?: EncodeInputOptions,\n signal?: AbortSignal\n ) => Promise<Uint8Array>;\n return webpEncodeClient(image, options, signal);\n }\n\n async terminate(): Promise<void> {\n // Client mode has nothing to terminate\n }\n}\n\nclass WebpWorkerBridge implements WebPBridge {\n private worker: Worker | null = null;\n private workerReady: Promise<Worker> | null = null;\n\n private async getWorker(): Promise<Worker> {\n if (!this.worker) {\n if (!this.workerReady) {\n this.workerReady = this.createWorker();\n }\n this.worker = await this.workerReady;\n }\n return this.worker;\n }\n\n private async createWorker(): Promise<Worker> {\n // Use the centralized worker helper for robust path resolution\n return createReadyWorker('webp.worker');\n }\n\n async encode(\n image: ImageInput,\n options?: EncodeInputOptions,\n signal?: AbortSignal\n ): Promise<Uint8Array> {\n const worker = await this.getWorker();\n\n validateImageInput(image);\n const buffer = image.data.buffer;\n validateArrayBuffer(buffer);\n return callWorker(worker, 'webp:encode', { image, options }, signal, [\n buffer,\n ]);\n }\n\n async terminate(): Promise<void> {\n if (this.worker) {\n this.worker.terminate();\n this.worker = null;\n this.workerReady = null;\n }\n }\n}\n\nexport function createBridge(mode: 'worker' | 'client'): WebPBridge {\n return mode === 'client' ? new WebpClientBridge() : new WebpWorkerBridge();\n}\n"
|
|
9
9
|
],
|
|
10
|
-
"mappings": "
|
|
11
|
-
"debugId": "
|
|
10
|
+
"mappings": "oGAyBO,GAAS,CAAK,EAAY,CAC/B,OAAO,OAAO,IAAQ,ICTxB,IAAI,EAAY,EAYhB,eAAsB,CAA+B,CACnD,EACA,EACA,EACA,EACA,EACoB,CACpB,OAAO,IAAI,QAAmB,CAAC,EAAS,IAAW,CACjD,IAAM,EAAK,EAAE,EAGb,GAAI,GAAQ,QAAS,CACnB,EAAO,IAAI,aAAa,UAAW,YAAY,CAAC,EAChD,OAGF,IAAM,EAAgB,CAAC,IAAwB,CAC7C,IAAM,EAAW,EAAM,KACvB,GAAI,EAAS,KAAO,EAAI,OAIxB,GAFA,EAAQ,EAEJ,EAAS,IAAM,EAAS,OAAS,OACnC,EAAQ,EAAS,IAAI,EAErB,OAAW,MAAM,EAAS,OAAS,sBAAsB,CAAC,GAIxD,EAAc,CAAC,IAAsB,CACzC,EAAQ,EACR,EAAW,MAAM,iBAAiB,EAAM,SAAS,CAAC,GAG9C,EAAc,IAAM,CACxB,EAAQ,EACR,EAAO,IAAI,aAAa,UAAW,YAAY,CAAC,GAG5C,EAAU,IAAM,CACpB,EAAO,oBAAoB,UAAW,CAAa,EACnD,EAAO,oBAAoB,QAAS,CAAW,EAC/C,GAAQ,oBAAoB,QAAS,CAAW,GAIlD,EAAO,iBAAiB,UAAW,CA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CACV,EACA,EACA,EACqB,CACrB,IAAM,EAAS,MAAM,KAAK,UAAU,EAEpC,EAAmB,CAAK,EACxB,IAAM,EAAS,EAAM,KAAK,OAE1B,OADA,EAAoB,CAAM,EACnB,EAAW,EAAQ,cAAe,CAAE,QAAO,SAAQ,EAAG,EAAQ,CACnE,CACF,CAAC,OAGG,UAAS,EAAkB,CAC/B,GAAI,KAAK,OACP,KAAK,OAAO,UAAU,EACtB,KAAK,OAAS,KACd,KAAK,YAAc,KAGzB,CAEO,SAAS,CAAY,CAAC,EAAuC,CAClE,OAAO,IAAS,SAAW,IAAI,EAAqB,IAAI",
|
|
11
|
+
"debugId": "000D23DB9916FD9564756E2164756E21",
|
|
12
12
|
"names": []
|
|
13
13
|
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
function a(e){if(e instanceof SharedArrayBuffer)throw Error("SharedArrayBuffer is not supported. Use regular ArrayBuffer or Uint8Array instead.");if(!(e instanceof ArrayBuffer))throw TypeError("image.data.buffer must be an ArrayBuffer")}function s(e){if(!e||typeof e!=="object")throw TypeError("image must be an object");let r=e;if(!("data"in r))throw TypeError("image.data is required");let{data:t}=r;if(!(t instanceof Uint8Array||t instanceof Uint8ClampedArray))throw TypeError("image.data must be Uint8Array or Uint8ClampedArray");if(!("width"in r)||!("height"in r))throw TypeError("image.width and image.height are required");let{width:n,height:i}=r;if(typeof n!=="number"||!Number.isInteger(n)||n<=0)throw RangeError(`image.width must be a positive integer, got ${n}`);if(typeof i!=="number"||!Number.isInteger(i)||i<=0)throw RangeError(`image.height must be a positive integer, got ${i}`);let o=n*i*4;if(t.length<o)throw RangeError(`image.data too small: ${t.length} bytes, expected at least ${o} bytes for ${n}x${i} RGBA image`)}function u(e){if(e===void 0)return;if(typeof e!=="object"||e===null)throw TypeError("options must be an object or undefined");let r=e;if("quality"in r&&r.quality!==void 0){let t=r.quality;if(Number.isNaN(t))throw RangeError("quality must be a valid number in the range 0-100, got NaN");if(typeof t!=="number")throw TypeError("quality must be a number");if(!Number.isInteger(t))throw RangeError("quality must be an integer in the range 0-100, got floating point");if(t<0||t>100)throw RangeError(`quality must be in the range 0-100, got ${t}`)}}
|
|
2
|
+
|
|
3
|
+
//# debugId=1F9D16AC2A9C06C664756E2164756E21
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../runtime/src/validators.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"import type { ImageInput } from './types.js';\n\nexport function validateArrayBuffer(\n buffer: unknown\n): asserts buffer is ArrayBuffer {\n if (buffer instanceof SharedArrayBuffer) {\n throw new Error(\n 'SharedArrayBuffer is not supported. ' +\n 'Use regular ArrayBuffer or Uint8Array instead.'\n );\n }\n\n if (!(buffer instanceof ArrayBuffer)) {\n throw new TypeError('image.data.buffer must be an ArrayBuffer');\n }\n}\n\nexport function validateImageInput(\n image: unknown\n): asserts image is ImageInput {\n if (!image || typeof image !== 'object') {\n throw new TypeError('image must be an object');\n }\n\n const imageObj = image as Record<string, unknown>;\n\n if (!('data' in imageObj)) {\n throw new TypeError('image.data is required');\n }\n\n const { data } = imageObj;\n if (!(data instanceof Uint8Array || data instanceof Uint8ClampedArray)) {\n throw new TypeError('image.data must be Uint8Array or Uint8ClampedArray');\n }\n\n if (!('width' in imageObj) || !('height' in imageObj)) {\n throw new TypeError('image.width and image.height are required');\n }\n\n const { width, height } = imageObj;\n\n if (typeof width !== 'number' || !Number.isInteger(width) || width <= 0) {\n throw new RangeError(\n `image.width must be a positive integer, got ${width}`\n );\n }\n\n if (typeof height !== 'number' || !Number.isInteger(height) || height <= 0) {\n throw new RangeError(\n `image.height must be a positive integer, got ${height}`\n );\n }\n\n const expectedSize = width * height * 4;\n if (data.length < expectedSize) {\n throw new RangeError(\n `image.data too small: ${data.length} bytes, expected at least ${expectedSize} bytes for ${width}x${height} RGBA image`\n );\n }\n}\n\nexport function validateResizeOptions(options: unknown): asserts options is {\n width?: number;\n height?: number;\n method?: 'triangular' | 'catrom' | 'mitchell' | 'lanczos3';\n premultiply?: boolean;\n linearRGB?: boolean;\n} {\n if (typeof options !== 'object' || options === null) {\n throw new TypeError('options must be an object');\n }\n\n const opts = options as Record<string, unknown>;\n\n if (opts.width !== undefined) {\n if (\n typeof opts.width !== 'number' ||\n !Number.isInteger(opts.width) ||\n opts.width <= 0\n ) {\n throw new RangeError(\n `options.width must be a positive integer, got ${opts.width}`\n );\n }\n }\n\n if (opts.height !== undefined) {\n if (\n typeof opts.height !== 'number' ||\n !Number.isInteger(opts.height) ||\n opts.height <= 0\n ) {\n throw new RangeError(\n `options.height must be a positive integer, got ${opts.height}`\n );\n }\n }\n\n if (opts.method !== undefined) {\n const validMethods = ['triangular', 'catrom', 'mitchell', 'lanczos3'];\n if (!validMethods.includes(opts.method as string)) {\n throw new TypeError(\n `options.method must be one of: ${validMethods.join(', ')}, got ${opts.method}`\n );\n }\n }\n\n if (opts.premultiply !== undefined && typeof opts.premultiply !== 'boolean') {\n throw new TypeError(\n `options.premultiply must be boolean, got ${typeof opts.premultiply}`\n );\n }\n\n if (opts.linearRGB !== undefined && typeof opts.linearRGB !== 'boolean') {\n throw new TypeError(\n `options.linearRGB must be boolean, got ${typeof opts.linearRGB}`\n );\n }\n}\n\nexport function validateWebpOptions(\n options: unknown\n): asserts options is Record<string, unknown> | undefined {\n if (options === undefined) {\n return;\n }\n\n if (typeof options !== 'object' || options === null) {\n throw new TypeError('options must be an object or undefined');\n }\n\n const opts = options as Record<string, unknown>;\n\n if ('quality' in opts && opts.quality !== undefined) {\n const quality = opts.quality;\n\n if (Number.isNaN(quality)) {\n throw new RangeError(\n 'quality must be a valid number in the range 0-100, got NaN'\n );\n }\n\n if (typeof quality !== 'number') {\n throw new TypeError('quality must be a number');\n }\n\n if (!Number.isInteger(quality)) {\n throw new RangeError(\n 'quality must be an integer in the range 0-100, got floating point'\n );\n }\n\n if (quality < 0 || quality > 100) {\n throw new RangeError(\n `quality must be in the range 0-100, got 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