@squoosh-kit/webp 0.2.8 → 0.2.10

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 CHANGED
@@ -45,8 +45,8 @@ const imageData: ImageInput = {
45
45
  const controller = new AbortController();
46
46
  const webpBuffer = await encode(imageData, { quality: 85 }, controller.signal);
47
47
 
48
- // For multiple images, create a persistent encoder
49
- const encoder = createWebpEncoder('worker');
48
+ // For multiple images, create a persistent encoder (auto mode by default)
49
+ const encoder = createWebpEncoder();
50
50
  const optimized = await encoder(
51
51
  imageData,
52
52
  { quality: 90, lossless: false },
@@ -121,7 +121,7 @@ for (const imagePath of imageFiles) {
121
121
 
122
122
  The main encoding function. Handles everything automatically and returns a Promise.
123
123
 
124
- **Note**: `encode()` uses a global singleton worker that is never automatically terminated. For long-running applications where worker cleanup is important, use `createWebpEncoder()` instead so you can call `.terminate()` when done.
124
+ **Note**: `encode()` uses a global singleton in **auto** mode (worker in the browser, client in Bun/Node) and is never automatically terminated. For long-running applications where worker cleanup is important, use `createWebpEncoder()` instead so you can call `.terminate()` when done.
125
125
 
126
126
  - `imageData` - `ImageInput` object with your pixel data
127
127
  - `options` - (optional) `WebpOptions` for quality and format settings
@@ -132,7 +132,7 @@ The main encoding function. Handles everything automatically and returns a Promi
132
132
 
133
133
  Creates a reusable encoder function. More efficient for processing multiple images.
134
134
 
135
- - `mode` - (optional) `'worker'` or `'client'`, defaults to `'worker'`
135
+ - `mode` - (optional) `'auto'`, `'worker'`, or `'client'`; defaults to `'auto'` (worker in the browser main thread, client in Bun/Node)
136
136
  - **Returns** - A function with the same signature as `encode()`
137
137
 
138
138
  ## Cancellation Support
@@ -293,8 +293,8 @@ type WebpOptions = {
293
293
 
294
294
  ## Performance Tips
295
295
 
296
- - **Use workers for UI apps** - Keeps your interface responsive during encoding
297
- - **Use client mode for servers** - Direct encoding without worker overhead
296
+ - **Auto mode in the browser** - Uses workers automatically to keep the UI responsive - Keeps your interface responsive during encoding
297
+ - **Auto mode in Bun/Node** - Runs on the main thread without worker overhead - Direct encoding without worker overhead
298
298
  - **Batch with persistent encoders** - More efficient than one-off calls
299
299
  - **Adjust quality strategically** - Often 80-90% quality looks identical to 100%
300
300
 
package/dist/bridge.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Bridge implementation for the WebP package, handling worker and client modes.
3
3
  */
4
- import { type ImageInput } from '@squoosh-kit/runtime';
4
+ import { type ImageInput, type BridgeMode } from '@squoosh-kit/runtime';
5
5
  import type { EncodeInputOptions } from './types';
6
6
  export type BridgeOptions = {
7
7
  /**
@@ -15,6 +15,5 @@ interface WebPBridge {
15
15
  decode(data: BufferSource, signal?: AbortSignal): Promise<ImageData>;
16
16
  terminate(): Promise<void>;
17
17
  }
18
- export declare function createBridge(mode: 'worker' | 'client', options?: BridgeOptions): WebPBridge;
18
+ export declare function createBridge(mode?: BridgeMode, options?: BridgeOptions): WebPBridge;
19
19
  export {};
20
- //# sourceMappingURL=bridge.d.ts.map
@@ -15,10 +15,28 @@ var __export = (target, all) => {
15
15
  var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
16
16
 
17
17
  // ../runtime/src/env.ts
18
+ function isWorker() {
19
+ return typeof self !== "undefined" && typeof globalThis.DedicatedWorkerGlobalScope !== "undefined";
20
+ }
21
+ function isBrowser() {
22
+ return typeof window !== "undefined" && typeof document !== "undefined";
23
+ }
18
24
  function isBun() {
19
25
  return typeof Bun !== "undefined";
20
26
  }
21
27
 
28
+ // ../runtime/src/bridge-mode.ts
29
+ function resolveBridgeMode(mode = "auto") {
30
+ if (mode === "worker" || mode === "client") {
31
+ return mode;
32
+ }
33
+ if (isBrowser() && !isWorker()) {
34
+ return "worker";
35
+ }
36
+ return "client";
37
+ }
38
+ var init_bridge_mode = () => {};
39
+
22
40
  // ../runtime/src/worker-call.ts
23
41
  async function callWorker(worker, type, payload, signal, transfer) {
24
42
  return new Promise((resolve, reject) => {
@@ -365,6 +383,7 @@ var init_simd_detector = () => {};
365
383
 
366
384
  // ../runtime/src/index.ts
367
385
  var init_src = __esm(() => {
386
+ init_bridge_mode();
368
387
  init_worker_helper();
369
388
  init_simd_detector();
370
389
  });
@@ -772,9 +791,10 @@ class WebpWorkerBridge {
772
791
  }
773
792
  }
774
793
  }
775
- function createBridge(mode, options) {
776
- console.log(`[webp/bridge] createBridge called with mode: ${mode}`);
777
- if (mode === "worker") {
794
+ function createBridge(mode = "auto", options) {
795
+ const resolvedMode = resolveBridgeMode(mode);
796
+ console.log(`[webp/bridge] createBridge called with mode: ${resolvedMode}`);
797
+ if (resolvedMode === "worker") {
778
798
  return new WebpWorkerBridge(options);
779
799
  }
780
800
  return new WebpClientBridge;
@@ -784,17 +804,17 @@ function createBridge(mode, options) {
784
804
  var globalClientBridge = null;
785
805
  async function encode(imageData, options, signal) {
786
806
  if (!globalClientBridge) {
787
- globalClientBridge = createBridge("worker");
807
+ globalClientBridge = createBridge("auto");
788
808
  }
789
809
  return globalClientBridge.encode(imageData, options, signal);
790
810
  }
791
811
  async function decode(data, signal) {
792
812
  if (!globalClientBridge) {
793
- globalClientBridge = createBridge("worker");
813
+ globalClientBridge = createBridge("auto");
794
814
  }
795
815
  return globalClientBridge.decode(data, signal);
796
816
  }
797
- function createWebpEncoder(mode = "worker", options) {
817
+ function createWebpEncoder(mode = "auto", options) {
798
818
  const bridge = createBridge(mode, options);
799
819
  return Object.assign((imageData, options2, signal) => {
800
820
  return bridge.encode(imageData, options2, signal);
@@ -804,7 +824,7 @@ function createWebpEncoder(mode = "worker", options) {
804
824
  }
805
825
  });
806
826
  }
807
- function createWebpDecoder(mode = "worker", options) {
827
+ function createWebpDecoder(mode = "auto", options) {
808
828
  const bridge = createBridge(mode, options);
809
829
  return Object.assign((data, signal) => {
810
830
  return bridge.decode(data, signal);
@@ -820,5 +840,3 @@ export {
820
840
  createWebpEncoder,
821
841
  createWebpDecoder
822
842
  };
823
-
824
- //# debugId=D33143D23843CCA764756E2164756E21
package/dist/index.bun.js CHANGED
@@ -16,10 +16,28 @@ var __export = (target, all) => {
16
16
  var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
17
17
 
18
18
  // ../runtime/src/env.ts
19
+ function isWorker() {
20
+ return typeof self !== "undefined" && typeof globalThis.DedicatedWorkerGlobalScope !== "undefined";
21
+ }
22
+ function isBrowser() {
23
+ return typeof window !== "undefined" && typeof document !== "undefined";
24
+ }
19
25
  function isBun() {
20
26
  return typeof Bun !== "undefined";
21
27
  }
22
28
 
29
+ // ../runtime/src/bridge-mode.ts
30
+ function resolveBridgeMode(mode = "auto") {
31
+ if (mode === "worker" || mode === "client") {
32
+ return mode;
33
+ }
34
+ if (isBrowser() && !isWorker()) {
35
+ return "worker";
36
+ }
37
+ return "client";
38
+ }
39
+ var init_bridge_mode = () => {};
40
+
23
41
  // ../runtime/src/worker-call.ts
24
42
  async function callWorker(worker, type, payload, signal, transfer) {
25
43
  return new Promise((resolve, reject) => {
@@ -366,6 +384,7 @@ var init_simd_detector = () => {};
366
384
 
367
385
  // ../runtime/src/index.ts
368
386
  var init_src = __esm(() => {
387
+ init_bridge_mode();
369
388
  init_worker_helper();
370
389
  init_simd_detector();
371
390
  });
@@ -773,9 +792,10 @@ class WebpWorkerBridge {
773
792
  }
774
793
  }
775
794
  }
776
- function createBridge(mode, options) {
777
- console.log(`[webp/bridge] createBridge called with mode: ${mode}`);
778
- if (mode === "worker") {
795
+ function createBridge(mode = "auto", options) {
796
+ const resolvedMode = resolveBridgeMode(mode);
797
+ console.log(`[webp/bridge] createBridge called with mode: ${resolvedMode}`);
798
+ if (resolvedMode === "worker") {
779
799
  return new WebpWorkerBridge(options);
780
800
  }
781
801
  return new WebpClientBridge;
@@ -785,17 +805,17 @@ function createBridge(mode, options) {
785
805
  var globalClientBridge = null;
786
806
  async function encode(imageData, options, signal) {
787
807
  if (!globalClientBridge) {
788
- globalClientBridge = createBridge("worker");
808
+ globalClientBridge = createBridge("auto");
789
809
  }
790
810
  return globalClientBridge.encode(imageData, options, signal);
791
811
  }
792
812
  async function decode(data, signal) {
793
813
  if (!globalClientBridge) {
794
- globalClientBridge = createBridge("worker");
814
+ globalClientBridge = createBridge("auto");
795
815
  }
796
816
  return globalClientBridge.decode(data, signal);
797
817
  }
798
- function createWebpEncoder(mode = "worker", options) {
818
+ function createWebpEncoder(mode = "auto", options) {
799
819
  const bridge = createBridge(mode, options);
800
820
  return Object.assign((imageData, options2, signal) => {
801
821
  return bridge.encode(imageData, options2, signal);
@@ -805,7 +825,7 @@ function createWebpEncoder(mode = "worker", options) {
805
825
  }
806
826
  });
807
827
  }
808
- function createWebpDecoder(mode = "worker", options) {
828
+ function createWebpDecoder(mode = "auto", options) {
809
829
  const bridge = createBridge(mode, options);
810
830
  return Object.assign((data, signal) => {
811
831
  return bridge.decode(data, signal);
@@ -821,5 +841,3 @@ export {
821
841
  createWebpEncoder,
822
842
  createWebpDecoder
823
843
  };
824
-
825
- //# debugId=371D13D58551187764756E2164756E21
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @squoosh-kit/webp public API
3
3
  */
4
- import type { ImageInput } from '@squoosh-kit/runtime';
4
+ import type { BridgeMode, ImageInput } from '@squoosh-kit/runtime';
5
5
  import { type BridgeOptions } from './bridge';
6
6
  import type { EncodeInputOptions } from './types';
7
7
  export type { ImageInput, EncodeInputOptions };
@@ -72,12 +72,11 @@ export declare function decode(data: BufferSource, signal?: AbortSignal): Promis
72
72
  * @param mode - The execution mode, either 'worker' or 'client'.
73
73
  * @returns A function that encodes an image to WebP format with optional AbortSignal.
74
74
  */
75
- export declare function createWebpEncoder(mode?: 'worker' | 'client', options?: BridgeOptions): WebpEncoderFactory;
75
+ export declare function createWebpEncoder(mode?: BridgeMode, options?: BridgeOptions): WebpEncoderFactory;
76
76
  /**
77
77
  * Creates a reusable WebP decoder function for a specific execution mode.
78
78
  *
79
79
  * @param mode - The execution mode, either 'worker' or 'client'.
80
80
  * @returns A function that decodes WebP data to ImageData with optional AbortSignal.
81
81
  */
82
- export declare function createWebpDecoder(mode?: 'worker' | 'client', options?: BridgeOptions): WebpDecoderFactory;
83
- //# sourceMappingURL=index.d.ts.map
82
+ export declare function createWebpDecoder(mode?: BridgeMode, options?: BridgeOptions): WebpDecoderFactory;
@@ -38,10 +38,28 @@ var __export = (target, all) => {
38
38
  var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
39
39
 
40
40
  // ../runtime/src/env.ts
41
+ function isWorker() {
42
+ return typeof self !== "undefined" && typeof globalThis.DedicatedWorkerGlobalScope !== "undefined";
43
+ }
44
+ function isBrowser() {
45
+ return typeof window !== "undefined" && typeof document !== "undefined";
46
+ }
41
47
  function isBun() {
42
48
  return typeof Bun !== "undefined";
43
49
  }
44
50
 
51
+ // ../runtime/src/bridge-mode.ts
52
+ function resolveBridgeMode(mode = "auto") {
53
+ if (mode === "worker" || mode === "client") {
54
+ return mode;
55
+ }
56
+ if (isBrowser() && !isWorker()) {
57
+ return "worker";
58
+ }
59
+ return "client";
60
+ }
61
+ var init_bridge_mode = () => {};
62
+
45
63
  // ../runtime/src/worker-call.ts
46
64
  async function callWorker(worker, type, payload, signal, transfer) {
47
65
  return new Promise((resolve, reject) => {
@@ -388,6 +406,7 @@ var init_simd_detector = () => {};
388
406
 
389
407
  // ../runtime/src/index.ts
390
408
  var init_src = __esm(() => {
409
+ init_bridge_mode();
391
410
  init_worker_helper();
392
411
  init_simd_detector();
393
412
  });
@@ -806,9 +825,10 @@ class WebpWorkerBridge {
806
825
  }
807
826
  }
808
827
  }
809
- function createBridge(mode, options) {
810
- console.log(`[webp/bridge] createBridge called with mode: ${mode}`);
811
- if (mode === "worker") {
828
+ function createBridge(mode = "auto", options) {
829
+ const resolvedMode = resolveBridgeMode(mode);
830
+ console.log(`[webp/bridge] createBridge called with mode: ${resolvedMode}`);
831
+ if (resolvedMode === "worker") {
812
832
  return new WebpWorkerBridge(options);
813
833
  }
814
834
  return new WebpClientBridge;
@@ -818,17 +838,17 @@ function createBridge(mode, options) {
818
838
  var globalClientBridge = null;
819
839
  async function encode(imageData, options, signal) {
820
840
  if (!globalClientBridge) {
821
- globalClientBridge = createBridge("worker");
841
+ globalClientBridge = createBridge("auto");
822
842
  }
823
843
  return globalClientBridge.encode(imageData, options, signal);
824
844
  }
825
845
  async function decode(data, signal) {
826
846
  if (!globalClientBridge) {
827
- globalClientBridge = createBridge("worker");
847
+ globalClientBridge = createBridge("auto");
828
848
  }
829
849
  return globalClientBridge.decode(data, signal);
830
850
  }
831
- function createWebpEncoder(mode = "worker", options) {
851
+ function createWebpEncoder(mode = "auto", options) {
832
852
  const bridge = createBridge(mode, options);
833
853
  return Object.assign((imageData, options2, signal) => {
834
854
  return bridge.encode(imageData, options2, signal);
@@ -838,7 +858,7 @@ function createWebpEncoder(mode = "worker", options) {
838
858
  }
839
859
  });
840
860
  }
841
- function createWebpDecoder(mode = "worker", options) {
861
+ function createWebpDecoder(mode = "auto", options) {
842
862
  const bridge = createBridge(mode, options);
843
863
  return Object.assign((data, signal) => {
844
864
  return bridge.decode(data, signal);
@@ -848,5 +868,3 @@ function createWebpDecoder(mode = "worker", options) {
848
868
  }
849
869
  });
850
870
  }
851
-
852
- //# debugId=CE1C58C01FC97E3E64756E2164756E21
@@ -15,10 +15,28 @@ var __export = (target, all) => {
15
15
  var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
16
16
 
17
17
  // ../runtime/src/env.ts
18
+ function isWorker() {
19
+ return typeof self !== "undefined" && typeof globalThis.DedicatedWorkerGlobalScope !== "undefined";
20
+ }
21
+ function isBrowser() {
22
+ return typeof window !== "undefined" && typeof document !== "undefined";
23
+ }
18
24
  function isBun() {
19
25
  return typeof Bun !== "undefined";
20
26
  }
21
27
 
28
+ // ../runtime/src/bridge-mode.ts
29
+ function resolveBridgeMode(mode = "auto") {
30
+ if (mode === "worker" || mode === "client") {
31
+ return mode;
32
+ }
33
+ if (isBrowser() && !isWorker()) {
34
+ return "worker";
35
+ }
36
+ return "client";
37
+ }
38
+ var init_bridge_mode = () => {};
39
+
22
40
  // ../runtime/src/worker-call.ts
23
41
  async function callWorker(worker, type, payload, signal, transfer) {
24
42
  return new Promise((resolve, reject) => {
@@ -365,6 +383,7 @@ var init_simd_detector = () => {};
365
383
 
366
384
  // ../runtime/src/index.ts
367
385
  var init_src = __esm(() => {
386
+ init_bridge_mode();
368
387
  init_worker_helper();
369
388
  init_simd_detector();
370
389
  });
@@ -772,9 +791,10 @@ class WebpWorkerBridge {
772
791
  }
773
792
  }
774
793
  }
775
- function createBridge(mode, options) {
776
- console.log(`[webp/bridge] createBridge called with mode: ${mode}`);
777
- if (mode === "worker") {
794
+ function createBridge(mode = "auto", options) {
795
+ const resolvedMode = resolveBridgeMode(mode);
796
+ console.log(`[webp/bridge] createBridge called with mode: ${resolvedMode}`);
797
+ if (resolvedMode === "worker") {
778
798
  return new WebpWorkerBridge(options);
779
799
  }
780
800
  return new WebpClientBridge;
@@ -784,17 +804,17 @@ function createBridge(mode, options) {
784
804
  var globalClientBridge = null;
785
805
  async function encode(imageData, options, signal) {
786
806
  if (!globalClientBridge) {
787
- globalClientBridge = createBridge("worker");
807
+ globalClientBridge = createBridge("auto");
788
808
  }
789
809
  return globalClientBridge.encode(imageData, options, signal);
790
810
  }
791
811
  async function decode(data, signal) {
792
812
  if (!globalClientBridge) {
793
- globalClientBridge = createBridge("worker");
813
+ globalClientBridge = createBridge("auto");
794
814
  }
795
815
  return globalClientBridge.decode(data, signal);
796
816
  }
797
- function createWebpEncoder(mode = "worker", options) {
817
+ function createWebpEncoder(mode = "auto", options) {
798
818
  const bridge = createBridge(mode, options);
799
819
  return Object.assign((imageData, options2, signal) => {
800
820
  return bridge.encode(imageData, options2, signal);
@@ -804,7 +824,7 @@ function createWebpEncoder(mode = "worker", options) {
804
824
  }
805
825
  });
806
826
  }
807
- function createWebpDecoder(mode = "worker", options) {
827
+ function createWebpDecoder(mode = "auto", options) {
808
828
  const bridge = createBridge(mode, options);
809
829
  return Object.assign((data, signal) => {
810
830
  return bridge.decode(data, signal);
@@ -820,5 +840,3 @@ export {
820
840
  createWebpEncoder,
821
841
  createWebpDecoder
822
842
  };
823
-
824
- //# debugId=F498B5FD7EF8CBFB64756E2164756E21
package/dist/types.d.ts CHANGED
@@ -1,4 +1,3 @@
1
1
  import type { EncodeOptions, WebPModule } from '../wasm/webp/webp_enc';
2
2
  type EncodeInputOptions = Partial<EncodeOptions>;
3
3
  export type { EncodeOptions, WebPModule, EncodeInputOptions };
4
- //# sourceMappingURL=types.d.ts.map
@@ -1,2 +1 @@
1
1
  export declare function validateWebpOptions(options: unknown): asserts options is Record<string, unknown> | undefined;
2
- //# sourceMappingURL=validators.d.ts.map
@@ -15,10 +15,28 @@ var __export = (target, all) => {
15
15
  var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
16
16
 
17
17
  // ../runtime/src/env.ts
18
+ function isWorker() {
19
+ return typeof self !== "undefined" && typeof globalThis.DedicatedWorkerGlobalScope !== "undefined";
20
+ }
21
+ function isBrowser() {
22
+ return typeof window !== "undefined" && typeof document !== "undefined";
23
+ }
18
24
  function isBun() {
19
25
  return typeof Bun !== "undefined";
20
26
  }
21
27
 
28
+ // ../runtime/src/bridge-mode.ts
29
+ function resolveBridgeMode(mode = "auto") {
30
+ if (mode === "worker" || mode === "client") {
31
+ return mode;
32
+ }
33
+ if (isBrowser() && !isWorker()) {
34
+ return "worker";
35
+ }
36
+ return "client";
37
+ }
38
+ var init_bridge_mode = () => {};
39
+
22
40
  // ../runtime/src/worker-call.ts
23
41
  async function callWorker(worker, type, payload, signal, transfer) {
24
42
  return new Promise((resolve, reject) => {
@@ -365,6 +383,7 @@ var init_simd_detector = () => {};
365
383
 
366
384
  // ../runtime/src/index.ts
367
385
  var init_src = __esm(() => {
386
+ init_bridge_mode();
368
387
  init_worker_helper();
369
388
  init_simd_detector();
370
389
  });
@@ -722,5 +741,3 @@ export {
722
741
  webpEncodeClient,
723
742
  webpDecodeClient
724
743
  };
725
-
726
- //# debugId=A96D53866DF9460464756E2164756E21
@@ -16,10 +16,28 @@ var __export = (target, all) => {
16
16
  var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
17
17
 
18
18
  // ../runtime/src/env.ts
19
+ function isWorker() {
20
+ return typeof self !== "undefined" && typeof globalThis.DedicatedWorkerGlobalScope !== "undefined";
21
+ }
22
+ function isBrowser() {
23
+ return typeof window !== "undefined" && typeof document !== "undefined";
24
+ }
19
25
  function isBun() {
20
26
  return typeof Bun !== "undefined";
21
27
  }
22
28
 
29
+ // ../runtime/src/bridge-mode.ts
30
+ function resolveBridgeMode(mode = "auto") {
31
+ if (mode === "worker" || mode === "client") {
32
+ return mode;
33
+ }
34
+ if (isBrowser() && !isWorker()) {
35
+ return "worker";
36
+ }
37
+ return "client";
38
+ }
39
+ var init_bridge_mode = () => {};
40
+
23
41
  // ../runtime/src/worker-call.ts
24
42
  async function callWorker(worker, type, payload, signal, transfer) {
25
43
  return new Promise((resolve, reject) => {
@@ -366,6 +384,7 @@ var init_simd_detector = () => {};
366
384
 
367
385
  // ../runtime/src/index.ts
368
386
  var init_src = __esm(() => {
387
+ init_bridge_mode();
369
388
  init_worker_helper();
370
389
  init_simd_detector();
371
390
  });
@@ -723,5 +742,3 @@ export {
723
742
  webpEncodeClient,
724
743
  webpDecodeClient
725
744
  };
726
-
727
- //# debugId=4ADDF2D7C50E9ABF64756E2164756E21
@@ -11,4 +11,3 @@ export declare function webpEncodeClient(image: ImageInput, options?: EncodeInpu
11
11
  * Client-mode WebP decoder (exported for direct use)
12
12
  */
13
13
  export declare function webpDecodeClient(data: BufferSource, signal?: AbortSignal): Promise<ImageData>;
14
- //# sourceMappingURL=webp.worker.d.ts.map
@@ -38,10 +38,28 @@ var __export = (target, all) => {
38
38
  var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
39
39
 
40
40
  // ../runtime/src/env.ts
41
+ function isWorker() {
42
+ return typeof self !== "undefined" && typeof globalThis.DedicatedWorkerGlobalScope !== "undefined";
43
+ }
44
+ function isBrowser() {
45
+ return typeof window !== "undefined" && typeof document !== "undefined";
46
+ }
41
47
  function isBun() {
42
48
  return typeof Bun !== "undefined";
43
49
  }
44
50
 
51
+ // ../runtime/src/bridge-mode.ts
52
+ function resolveBridgeMode(mode = "auto") {
53
+ if (mode === "worker" || mode === "client") {
54
+ return mode;
55
+ }
56
+ if (isBrowser() && !isWorker()) {
57
+ return "worker";
58
+ }
59
+ return "client";
60
+ }
61
+ var init_bridge_mode = () => {};
62
+
45
63
  // ../runtime/src/worker-call.ts
46
64
  async function callWorker(worker, type, payload, signal, transfer) {
47
65
  return new Promise((resolve, reject) => {
@@ -388,6 +406,7 @@ var init_simd_detector = () => {};
388
406
 
389
407
  // ../runtime/src/index.ts
390
408
  var init_src = __esm(() => {
409
+ init_bridge_mode();
391
410
  init_worker_helper();
392
411
  init_simd_detector();
393
412
  });
@@ -741,5 +760,3 @@ var init_webp_worker = __esm(() => {
741
760
  }
742
761
  });
743
762
  init_webp_worker();
744
-
745
- //# debugId=E6D90FE4517E7FA464756E2164756E21
@@ -15,10 +15,28 @@ var __export = (target, all) => {
15
15
  var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
16
16
 
17
17
  // ../runtime/src/env.ts
18
+ function isWorker() {
19
+ return typeof self !== "undefined" && typeof globalThis.DedicatedWorkerGlobalScope !== "undefined";
20
+ }
21
+ function isBrowser() {
22
+ return typeof window !== "undefined" && typeof document !== "undefined";
23
+ }
18
24
  function isBun() {
19
25
  return typeof Bun !== "undefined";
20
26
  }
21
27
 
28
+ // ../runtime/src/bridge-mode.ts
29
+ function resolveBridgeMode(mode = "auto") {
30
+ if (mode === "worker" || mode === "client") {
31
+ return mode;
32
+ }
33
+ if (isBrowser() && !isWorker()) {
34
+ return "worker";
35
+ }
36
+ return "client";
37
+ }
38
+ var init_bridge_mode = () => {};
39
+
22
40
  // ../runtime/src/worker-call.ts
23
41
  async function callWorker(worker, type, payload, signal, transfer) {
24
42
  return new Promise((resolve, reject) => {
@@ -365,6 +383,7 @@ var init_simd_detector = () => {};
365
383
 
366
384
  // ../runtime/src/index.ts
367
385
  var init_src = __esm(() => {
386
+ init_bridge_mode();
368
387
  init_worker_helper();
369
388
  init_simd_detector();
370
389
  });
@@ -722,5 +741,3 @@ export {
722
741
  webpEncodeClient,
723
742
  webpDecodeClient
724
743
  };
725
-
726
- //# debugId=923FA418FEEEE29964756E2164756E21
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@squoosh-kit/webp",
3
- "version": "0.2.8",
3
+ "version": "0.2.10",
4
4
  "type": "module",
5
5
  "description": "WebP codec for squoosh-kit, providing encoding functionality.",
6
6
  "author": "Bartosz Nowak <bnowak008@gmail.com>",
@@ -35,6 +35,7 @@
35
35
  },
36
36
  "files": [
37
37
  "dist/**",
38
+ "!dist/**/*.map",
38
39
  "README.md",
39
40
  "LICENSE",
40
41
  "NOTICE"
@@ -47,6 +48,6 @@
47
48
  "test": "bun test"
48
49
  },
49
50
  "dependencies": {
50
- "@squoosh-kit/runtime": "0.2.8"
51
+ "@squoosh-kit/runtime": "0.2.10"
51
52
  }
52
53
  }
@@ -1 +0,0 @@
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,MAAM,MAAM,aAAa,GAAG;IAC1B;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,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,MAAM,CAAC,IAAI,EAAE,YAAY,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;IACrE,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC5B;AAsFD,wBAAgB,YAAY,CAC1B,IAAI,EAAE,QAAQ,GAAG,QAAQ,EACzB,OAAO,CAAC,EAAE,aAAa,GACtB,UAAU,CAMZ"}