@squoosh-kit/core 0.0.4 → 0.0.6
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 +16 -12
- package/dist/index.js +26 -3
- package/dist/index.js.map +16 -10
- package/package.json +7 -10
- package/dist/features/resize/bridge.d.ts +0 -11
- package/dist/features/resize/bridge.d.ts.map +0 -1
- package/dist/features/resize/index.d.ts +0 -24
- package/dist/features/resize/index.d.ts.map +0 -1
- package/dist/features/resize/index.js +0 -5
- package/dist/features/resize/index.js.map +0 -12
- package/dist/features/resize/resize.worker.d.ts +0 -7
- package/dist/features/resize/resize.worker.d.ts.map +0 -1
- package/dist/features/resize/resize.worker.js +0 -6
- package/dist/features/resize/resize.worker.js.map +0 -10
- package/dist/features/resize/types.d.ts +0 -27
- package/dist/features/resize/types.d.ts.map +0 -1
- package/dist/features/resize/wasm/squoosh_resize.d.ts +0 -34
- package/dist/features/resize/wasm/squoosh_resize.js +0 -120
- package/dist/features/resize/wasm/squoosh_resize_bg.wasm +0 -0
- package/dist/features/resize/wasm/squoosh_resize_bg.wasm.d.ts +0 -7
- package/dist/features/webp/bridge.d.ts +0 -11
- package/dist/features/webp/bridge.d.ts.map +0 -1
- package/dist/features/webp/index.d.ts +0 -26
- package/dist/features/webp/index.d.ts.map +0 -1
- package/dist/features/webp/index.js +0 -5
- package/dist/features/webp/index.js.map +0 -12
- package/dist/features/webp/types.d.ts +0 -24
- package/dist/features/webp/types.d.ts.map +0 -1
- package/dist/features/webp/wasm/webp/webp_enc.d.ts +0 -42
- package/dist/features/webp/wasm/webp/webp_enc.js +0 -16
- package/dist/features/webp/wasm/webp/webp_enc.wasm +0 -0
- package/dist/features/webp/wasm/webp-dec/webp_dec.d.ts +0 -7
- package/dist/features/webp/wasm/webp-dec/webp_dec.js +0 -16
- package/dist/features/webp/wasm/webp-dec/webp_dec.wasm +0 -0
- package/dist/features/webp/webp.worker.d.ts +0 -10
- package/dist/features/webp/webp.worker.d.ts.map +0 -1
- package/dist/features/webp/webp.worker.js +0 -6
- package/dist/features/webp/webp.worker.js.map +0 -10
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
// @bun
|
|
2
|
-
var N=null;async function U(){if(N)return N;try{if(typeof self>"u")global.self=global;if(typeof self<"u"&&!self.location)self.location={href:import.meta.url};let j="./wasm/webp",x=await import(new URL(`${j}/webp_enc.js`,import.meta.url).href),G=new URL(`${j}/`,import.meta.url).href,I=await x.default({locateFile:(H)=>{if(H.endsWith(".wasm"))return new URL(H,G).href;return H}});return N=I,I}catch(j){throw Error(`Failed to load WebP module: ${j instanceof Error?j.message:String(j)}`)}}function V(j){let z=Math.max(0,Math.min(100,j?.quality??82)),x=j?.lossless??!1,G=j?.nearLossless??!1;return{quality:z,target_size:0,target_PSNR:0,method:4,sns_strength:50,filter_strength:60,filter_sharpness:0,filter_type:1,partitions:0,segments:4,pass:1,show_compressed:0,preprocessing:0,autofilter:0,partition_limit:0,alpha_compression:1,alpha_filtering:1,alpha_quality:100,lossless:x?1:0,exact:0,image_hint:0,emulate_jpeg_size:0,thread_level:0,low_memory:0,near_lossless:G?z:100,use_delta_palette:0,use_sharp_yuv:0}}async function X(j,z,x){if(j.aborted)throw new DOMException("Aborted","AbortError");let{width:G,height:I,data:H}=z;if(!(H instanceof Uint8Array)&&!(H instanceof Uint8ClampedArray))throw Error("Image data must be Uint8Array or Uint8ClampedArray");let J=await U();if(j.aborted)throw new DOMException("Aborted","AbortError");let K=V(x),R=H instanceof Uint8ClampedArray?new Uint8Array(H):H,S=new Uint8Array(R),Q=J.encode(S,G,I,K);if(j.aborted)throw new DOMException("Aborted","AbortError");if(!Q)throw Error("WebP encoding failed");return Q}if(typeof self<"u")self.onmessage=async(j)=>{let z=j.data,x={id:z.id,ok:!1};try{if(z.type==="webp:encode"){let{image:G,options:I}=z.payload,H=new AbortController,J=await X(H.signal,G,I);x.ok=!0,x.data=J;let K=x.data.buffer;self.postMessage(x,[K])}else x.error=`Unknown message type: ${z.type}`,self.postMessage(x)}catch(G){x.error=G instanceof Error?G.message:String(G),self.postMessage(x)}};export{X as webpEncodeClient};
|
|
3
|
-
export{X as a};
|
|
4
|
-
|
|
5
|
-
//# debugId=66000A60E94E382464756E2164756E21
|
|
6
|
-
//# sourceMappingURL=webp.worker.js.map
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/webp.worker.ts"],
|
|
4
|
-
"sourcesContent": [
|
|
5
|
-
"/**\n * WebP encoder - single-source worker/client implementation\n */\n\nimport {\n isWorker,\n type WorkerRequest,\n type WorkerResponse,\n type ImageInput,\n} from '@squoosh-kit/runtime';\nimport type { WebpOptions } from './types.js';\n\n// Types from webp_enc.d.ts\ninterface EncodeOptions {\n quality: number;\n target_size: number;\n target_PSNR: number;\n method: number;\n sns_strength: number;\n filter_strength: number;\n filter_sharpness: number;\n filter_type: number;\n partitions: number;\n segments: number;\n pass: number;\n show_compressed: number;\n preprocessing: number;\n autofilter: number;\n partition_limit: number;\n alpha_compression: number;\n alpha_filtering: number;\n alpha_quality: number;\n lossless: number;\n exact: number;\n image_hint: number;\n emulate_jpeg_size: number;\n thread_level: number;\n low_memory: number;\n near_lossless: number;\n use_delta_palette: number;\n use_sharp_yuv: number;\n}\n\ninterface WebPModule {\n encode(\n data: BufferSource,\n width: number,\n height: number,\n options: EncodeOptions\n ): Uint8Array | null;\n}\n\nlet cachedModule: WebPModule | null = null;\n\nasync function loadWebPModule(): Promise<WebPModule> {\n if (cachedModule) {\n return cachedModule;\n }\n\n try {\n // Environment polyfills for Emscripten-generated code\n // The WebP encoder WASM module expects browser-like globals (self, location)\n // These polyfills ensure compatibility when running in Bun/Node.js environments\n if (typeof self === 'undefined') {\n // Polyfill 'self' global for Emscripten compatibility\n (global as { self?: typeof globalThis }).self = global;\n }\n if (typeof self !== 'undefined' && !self.location) {\n // Polyfill 'location' object for Emscripten module initialization\n (self as { location?: { href: string } }).location = {\n href: import.meta.url,\n };\n }\n\n // The WASM assets are expected to be in a directory relative to the worker script.\n const wasmDirectory = './wasm/webp';\n\n // Dynamically import the WebP encoder module\n const modulePath = new URL(`${wasmDirectory}/webp_enc.js`, import.meta.url)\n .href;\n const moduleFactory = await import(modulePath);\n\n // Initialize the WebP module with locateFile to properly resolve the WASM\n const wasmPath = new URL(`${wasmDirectory}/`, import.meta.url).href;\n const module = await moduleFactory.default({\n locateFile: (path: string) => {\n // Return the full URL to the WASM file\n if (path.endsWith('.wasm')) {\n return new URL(path, wasmPath).href;\n }\n return path;\n },\n });\n\n cachedModule = module;\n return module;\n } catch (error) {\n throw new Error(\n `Failed to load WebP module: ${error instanceof Error ? error.message : String(error)}`\n );\n }\n}\n\n/**\n * Convert our simplified options to full EncodeOptions\n */\nfunction createEncodeOptions(options?: WebpOptions): EncodeOptions {\n const quality = Math.max(0, Math.min(100, options?.quality ?? 82));\n const lossless = options?.lossless ?? false;\n const nearLossless = options?.nearLossless ?? false;\n\n // Default encode options from Squoosh\n return {\n quality,\n target_size: 0,\n target_PSNR: 0,\n method: 4,\n sns_strength: 50,\n filter_strength: 60,\n filter_sharpness: 0,\n filter_type: 1,\n partitions: 0,\n segments: 4,\n pass: 1,\n show_compressed: 0,\n preprocessing: 0,\n autofilter: 0,\n partition_limit: 0,\n alpha_compression: 1,\n alpha_filtering: 1,\n alpha_quality: 100,\n lossless: lossless ? 1 : 0,\n exact: 0,\n image_hint: 0,\n emulate_jpeg_size: 0,\n thread_level: 0,\n low_memory: 0,\n near_lossless: nearLossless ? quality : 100,\n use_delta_palette: 0,\n use_sharp_yuv: 0,\n };\n}\n\n/**\n * Client-mode WebP encoder (exported for direct use)\n */\nexport async function webpEncodeClient(\n signal: AbortSignal,\n image: ImageInput,\n options?: WebpOptions\n): Promise<Uint8Array> {\n // Check abort before starting\n if (signal.aborted) {\n throw new DOMException('Aborted', 'AbortError');\n }\n\n // Normalize image input\n const width = image.width;\n const height = image.height;\n const data = image.data;\n\n if (!(data instanceof Uint8Array) && !(data instanceof Uint8ClampedArray)) {\n throw new Error('Image data must be Uint8Array or Uint8ClampedArray');\n }\n\n const module = await loadWebPModule();\n\n // Check abort after async operation\n if (signal.aborted) {\n throw new DOMException('Aborted', 'AbortError');\n }\n\n const encodeOptions = createEncodeOptions(options);\n\n // Call the encode function\n // Convert Uint8ClampedArray to Uint8Array if needed for BufferSource compatibility\n const dataArray =\n data instanceof Uint8ClampedArray ? new Uint8Array(data) : data;\n // Create a new Uint8Array with a proper ArrayBuffer to satisfy BufferSource\n const buffer = new Uint8Array(dataArray);\n const result = module.encode(buffer, width, height, encodeOptions);\n\n if (signal.aborted) {\n throw new DOMException('Aborted', 'AbortError');\n }\n\n if (!result) {\n throw new Error('WebP encoding failed');\n }\n\n return result;\n}\n\n/**\n * Worker message handler\n * Register the handler regardless of environment (for both worker context and tests)\n */\nif (typeof self !== 'undefined') {\n self.onmessage = async (event: MessageEvent) => {\n const request = event.data as WorkerRequest<{\n image: ImageInput;\n options?: WebpOptions;\n }>;\n\n const response: WorkerResponse<Uint8Array> = {\n id: request.id,\n ok: false,\n };\n\n try {\n if (request.type === 'webp:encode') {\n const { image, options } = request.payload;\n\n // Create an AbortController for this request\n const controller = new AbortController();\n\n const result = await webpEncodeClient(\n controller.signal,\n image,\n options\n );\n\n response.ok = true;\n response.data = result;\n\n // Transfer the result buffer back directly from the response data\n const resultBuffer: ArrayBuffer = response.data.buffer as ArrayBuffer;\n self.postMessage(response, [resultBuffer]);\n } else {\n response.error = `Unknown message type: ${request.type}`;\n self.postMessage(response);\n }\n } catch (error) {\n response.error = error instanceof Error ? error.message : String(error);\n self.postMessage(response);\n }\n };\n}\n"
|
|
6
|
-
],
|
|
7
|
-
"mappings": ";AAoDA,IAAI,EAAkC,KAEtC,eAAe,CAAc,EAAwB,CACnD,GAAI,EACF,OAAO,EAGT,GAAI,CAIF,GAAI,OAAO,KAAS,IAEjB,OAAwC,KAAO,OAElD,GAAI,OAAO,KAAS,KAAe,C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