import { type Config, type OptimizeResult } from "./core.js"; /** * Lazy worker offload. The core (`index.ts`) `import()`s this module only when * `optimize(svg, { worker: true })` runs, so the main bundle never carries the * worker machinery (or pays for loading `worker.js`) until a caller opts in. * The environment entries install a factory (`setWorkerFactory`); browsers get * a module `Worker` by default. All state is local to this module. * * This file runs on the MAIN thread, managing the shared worker. The script it * spawns (`worker.js` / `worker.node.js`) imports only the loader-free core. */ /** Minimal shape of a `Worker`, kept bundler/type-safe and runtime-agnostic. */ export interface WasmWorker { postMessage(message: unknown, transfer?: readonly Transferable[]): void; addEventListener(type: "message" | "error", listener: (event: { data: unknown; }) => void): void; removeEventListener(type: "message" | "error", listener: (event: { data: unknown; }) => void): void; terminate(): void | Promise; } /** * Produces the shared worker. Browsers get a module `Worker` by default * (`dist/worker.js`); the Node entry installs a `node:worker_threads` wrapper * via `setWorkerFactory`. Advanced callers can swap the factory entirely. */ export type WasmWorkerFactory = () => Promise | WasmWorker; /** Install a custom worker factory (see {@link WasmWorkerFactory}). */ export declare function setWorkerFactory(factory: WasmWorkerFactory | null): void; /** * Permanently shut down the shared worker and release its thread. Only needed * when callers want to free the worker; ordinary `reset()` keeps reusing it, * so concurrent worker use never trips the terminate/recreate reclamation race. */ export declare function shutdownWorkers(): Promise; /** * Run `optimize` on the shared worker, or `null` when no worker could be * brought up (the caller then falls back to the main thread). Rejections from * the worker itself (parse/config errors, `SvgoError`) are not swallowed. */ export declare function tryOptimizeInWorker(svg: string, config?: Config | null): Promise; //# sourceMappingURL=worker-client.d.ts.map