@squoosh-kit/resize 0.0.2 → 0.0.4
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/dist/bridge.d.ts +1 -0
- package/dist/bridge.d.ts.map +1 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -2
- package/dist/index.js.map +2 -2
- package/dist/resize.worker.d.ts +1 -0
- package/dist/resize.worker.d.ts.map +1 -0
- package/dist/types.d.ts +1 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +4 -2
package/dist/bridge.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bridge.d.ts","sourceRoot":"","sources":["../src/bridge.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAc,KAAK,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAEnE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD,UAAU,YAAY;IACpB,MAAM,CACJ,MAAM,EAAE,WAAW,EACnB,KAAK,EAAE,UAAU,EACjB,OAAO,EAAE,aAAa,GACrB,OAAO,CAAC,UAAU,CAAC,CAAC;CACxB;AAgDD,wBAAgB,YAAY,CAAC,IAAI,EAAE,QAAQ,GAAG,QAAQ,GAAG,YAAY,CAIpE"}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @squoosh-kit/resize public API
|
|
3
3
|
*/
|
|
4
4
|
import type { ImageInput } from '@squoosh-kit/runtime';
|
|
5
|
-
import type { ResizeOptions } from './types
|
|
5
|
+
import type { ResizeOptions } from './types';
|
|
6
6
|
export type { ImageInput, ResizeOptions };
|
|
7
7
|
/**
|
|
8
8
|
* Resizes an image. Defaults to 'worker' mode.
|
|
@@ -20,4 +20,5 @@ export declare function resize(signal: AbortSignal, imageData: ImageInput, optio
|
|
|
20
20
|
* @returns A function that resizes an image.
|
|
21
21
|
*/
|
|
22
22
|
export declare function createResizer(mode?: 'worker' | 'client'): (signal: AbortSignal, image: ImageInput, options: ResizeOptions) => Promise<ImageInput>;
|
|
23
|
-
export { resizeClient } from './resize.worker
|
|
23
|
+
export { resizeClient } from './resize.worker';
|
|
24
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAEvD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7C,YAAY,EAAE,UAAU,EAAE,aAAa,EAAE,CAAC;AAE1C;;;;;;;GAOG;AACH,wBAAsB,MAAM,CAC1B,MAAM,EAAE,WAAW,EACnB,SAAS,EAAE,UAAU,EACrB,OAAO,EAAE,aAAa,GACrB,OAAO,CAAC,UAAU,CAAC,CAIrB;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,IAAI,GAAE,QAAQ,GAAG,QAAmB,2FAGjE;AAID,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{a as o}from"./resize.worker.js";var G=0;async function U(i,m,z,u,g){return new Promise((R,W)=>{let P=++G;if(u?.aborted){W(new DOMException("Aborted","AbortError"));return}let c=(
|
|
2
|
+
import{a as o}from"./resize.worker.js";var G=0;async function U(i,m,z,u,g){return new Promise((R,W)=>{let P=++G;if(u?.aborted){W(new DOMException("Aborted","AbortError"));return}let c=(B)=>{let I=B.data;if(I.id!==P)return;if(console.log("\uD83D\uDD27 Worker call: Response received",I),t(),I.ok&&I.data!==void 0)console.log("\uD83D\uDD27 Worker call: Response data",I.data),R(I.data);else console.log("\uD83D\uDD27 Worker call: Response error",I.error),W(Error(I.error||"Unknown worker error"))},f=(B)=>{t(),W(Error(`Worker error: ${B.message}`))},x=()=>{t(),W(new DOMException("Aborted","AbortError"))},t=()=>{i.removeEventListener("message",c),i.removeEventListener("error",f),u?.removeEventListener("abort",x)};i.addEventListener("message",c),i.addEventListener("error",f),u?.addEventListener("abort",x);let A={type:m,id:P,payload:z};if(g&&g.length>0)i.postMessage(A,g);else i.postMessage(A)})}class k{async resize(i,m,z){return o(i,m,z)}}class F{worker=null;async getWorker(){if(!this.worker){let i=await import.meta.resolve("@squoosh-kit/resize/resize.worker.js");this.worker=new Worker(i,{type:"module"})}return this.worker}async resize(i,m,z){let u=await this.getWorker();console.log("worker",u);let g=m.data.buffer;console.log("buffer",g);try{let R=await U(u,"resize:run",{image:m,options:z},i,[g]);return console.log("result",R),R}catch(R){throw console.error("error",R),R}}}function O(i){return i==="client"?new k:new F}async function Q(i,m,z){return O("worker").resize(i,m,z)}function S(i="worker"){let m=O(i);return m.resize.bind(m)}export{o as resizeClient,Q as resize,S as createResizer};
|
|
3
3
|
|
|
4
|
-
//# debugId=
|
|
4
|
+
//# debugId=59DDCB371911476764756E2164756E21
|
|
5
5
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
"sourcesContent": [
|
|
5
5
|
"/**\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 console.log('🔧 Worker call: Response received', response);\n cleanup();\n\n if (response.ok && response.data !== undefined) {\n console.log('🔧 Worker call: Response data', response.data);\n resolve(response.data);\n } else {\n console.log('🔧 Worker call: Response error', response.error);\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",
|
|
6
6
|
"/**\n * Bridge implementation for the Resize package, handling worker and client modes.\n */\n\nimport { callWorker, type ImageInput } from '@squoosh-kit/runtime';\nimport { resizeClient } from './resize.worker.ts';\nimport type { ResizeOptions } from './types.ts';\n\ninterface ResizeBridge {\n resize(\n signal: AbortSignal,\n image: ImageInput,\n options: ResizeOptions\n ): Promise<ImageInput>;\n}\n\nclass ResizeClientBridge implements ResizeBridge {\n async resize(\n signal: AbortSignal,\n image: ImageInput,\n options: ResizeOptions\n ): Promise<ImageInput> {\n return resizeClient(signal, image, options);\n }\n}\n\nclass ResizeWorkerBridge implements ResizeBridge {\n private worker: Worker | null = null;\n private async getWorker(): Promise<Worker> {\n if (!this.worker) {\n const workerUrl = await import.meta.resolve(\n '@squoosh-kit/resize/resize.worker.js'\n );\n this.worker = new Worker(workerUrl, { type: 'module' });\n }\n return this.worker;\n }\n async resize(\n signal: AbortSignal,\n image: ImageInput,\n options: ResizeOptions\n ): Promise<ImageInput> {\n const worker = await this.getWorker();\n console.log('worker', worker);\n const buffer = image.data.buffer;\n console.log('buffer', buffer);\n\n try {\n const result = await callWorker<{ image: ImageInput; options: ResizeOptions }, ImageInput>(worker, 'resize:run', { image, options }, signal, [\n buffer as ArrayBuffer,\n ]);\n \n console.log('result', result);\n\n return result;\n } catch (error) {\n console.error('error', error);\n throw error;\n }\n }\n}\n\nexport function createBridge(mode: 'worker' | 'client'): ResizeBridge {\n return mode === 'client'\n ? new ResizeClientBridge()\n : new ResizeWorkerBridge();\n}\n",
|
|
7
|
-
"/**\n * @squoosh-kit/resize public API\n */\n\nimport type { ImageInput } from '@squoosh-kit/runtime';\nimport { createBridge } from './bridge
|
|
7
|
+
"/**\n * @squoosh-kit/resize public API\n */\n\nimport type { ImageInput } from '@squoosh-kit/runtime';\nimport { createBridge } from './bridge';\nimport type { ResizeOptions } from './types';\n\nexport type { ImageInput, ResizeOptions };\n\n/**\n * Resizes an image. Defaults to 'worker' mode.\n *\n * @param signal - An AbortSignal to cancel the resizing operation.\n * @param imageData - The image data to resize.\n * @param options - Resize options.\n * @returns A Promise resolving to the resized image data.\n */\nexport async function resize(\n signal: AbortSignal,\n imageData: ImageInput,\n options: ResizeOptions\n): Promise<ImageInput> {\n // Always use a worker for a single, one-off call for best performance.\n const bridge = createBridge('worker');\n return bridge.resize(signal, imageData, options);\n}\n\n/**\n * Creates a reusable resizer function for a specific execution mode.\n *\n * @param mode - The execution mode, either 'worker' or 'client'.\n * @returns A function that resizes an image.\n */\nexport function createResizer(mode: 'worker' | 'client' = 'worker') {\n const bridge = createBridge(mode);\n return bridge.resize.bind(bridge);\n}\n\n// Export the client-side implementation for direct use by the bridge.\n// This is not intended for public consumption.\nexport { resizeClient } from './resize.worker';\n"
|
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AAoB,CACzC,GAAI,CAAC,KAAK,OAAQ,CAChB,IAAM,EAAY,MAAM,YAAY,QAClC,sCACF,EACA,KAAK,OAAS,IAAI,OAAO,EAAW,CAAE,KAAM,QAAS,CAAC,EAExD,OAAO,KAAK,YAER,OAAM,CACV,EACA,EACA,EACqB,CACrB,IAAM,EAAS,MAAM,KAAK,UAAU,EACpC,QAAQ,IAAI,SAAU,CAAM,EAC5B,IAAM,EAAS,EAAM,KAAK,OAC1B,QAAQ,IAAI,SAAU,CAAM,EAE5B,GAAI,CACF,IAAM,EAAS,MAAM,EAAsE,EAAQ,aAAc,CAAE,QAAO,SAAQ,EAAG,EAAQ,CAC3I,CACF,CAAC,EAID,OAFA,QAAQ,IAAI,SAAU,CAAM,EAErB,EACP,MAAO,EAAO,CAEd,MADA,QAAQ,MAAM,QAAS,CAAK,EACtB,GAGZ,CAEO,SAAS,CAAY,CAAC,EAAyC,CACpE,OAAO,IAAS,SACZ,IAAI,EACJ,IAAI,EC/CV,eAAsB,CAAM,CAC1B,EACA,EACA,EACqB,CAGrB,OADe,EAAa,QAAQ,EACtB,OAAO,EAAQ,EAAW,CAAO,EAS1C,SAAS,CAAa,CAAC,EAA4B,SAAU,CAClE,IAAM,EAAS,EAAa,CAAI,EAChC,OAAO,EAAO,OAAO,KAAK,CAAM",
|
|
10
|
-
"debugId": "
|
|
10
|
+
"debugId": "59DDCB371911476764756E2164756E21",
|
|
11
11
|
"names": []
|
|
12
12
|
}
|
package/dist/resize.worker.d.ts
CHANGED
|
@@ -4,3 +4,4 @@
|
|
|
4
4
|
import { type ImageInput } from '@squoosh-kit/runtime';
|
|
5
5
|
import type { ResizeOptions } from './types.ts';
|
|
6
6
|
export declare function resizeClient(signal: AbortSignal, image: ImageInput, options: ResizeOptions): Promise<ImageInput>;
|
|
7
|
+
//# sourceMappingURL=resize.worker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resize.worker.d.ts","sourceRoot":"","sources":["../src/resize.worker.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAIL,KAAK,UAAU,EAChB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AA+EhD,wBAAsB,YAAY,CAChC,MAAM,EAAE,WAAW,EACnB,KAAK,EAAE,UAAU,EACjB,OAAO,EAAE,aAAa,GACrB,OAAO,CAAC,UAAU,CAAC,CAKrB"}
|
package/dist/types.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@squoosh-kit/resize",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Image resize module for squoosh-kit.",
|
|
6
6
|
"author": "Bartosz Nowak <bnowak008@gmail.com>",
|
|
@@ -15,6 +15,8 @@
|
|
|
15
15
|
"access": "public",
|
|
16
16
|
"registry": "https://registry.npmjs.org/"
|
|
17
17
|
},
|
|
18
|
+
"main": "./dist/index.js",
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
18
20
|
"exports": {
|
|
19
21
|
".": {
|
|
20
22
|
"types": "./dist/index.d.ts",
|
|
@@ -36,6 +38,6 @@
|
|
|
36
38
|
"test": "bun test"
|
|
37
39
|
},
|
|
38
40
|
"dependencies": {
|
|
39
|
-
"@squoosh-kit/runtime": "0.
|
|
41
|
+
"@squoosh-kit/runtime": "0.0.3"
|
|
40
42
|
}
|
|
41
43
|
}
|