import type { IoConfig } from './io/protocol.js'; /** Width and height in pixels. */ export interface Dimensions { readonly width: number; readonly height: number; } /** Complete metadata returned when a slide is opened. */ export interface SlideInfo { readonly levelCount: number; readonly levelDimensions: readonly Dimensions[]; readonly levelDownsamples: readonly number[]; readonly properties: ReadonlyMap; readonly associatedImageNames: readonly string[]; } /** Deep Zoom Image descriptor info. */ export interface DziInfo { readonly tileSize: number; readonly overlap: number; readonly format: string; readonly width: number; readonly height: number; } /** * Options for OpenSlide.initialize(). * * With no options, the worker and WASM are resolved relative to the package at * runtime — this works under plain (no-bundler) ESM only. Under a bundler * (webpack/Next.js, Vite) you MUST wire the assets explicitly via the subpath * exports + the options below; see INTEGRATION.md. The package deliberately avoids * literal `new Worker`/`import()` paths so bundlers don't force-trace the * pthreaded WASM graph (which crashes Next.js). */ export interface OpenSlideOptions { /** Number of Web Workers to spawn (default: navigator.hardwareConcurrency or 4). */ workerCount?: number; /** * URL to the WASM module loader JS (the `@.../openslide-js/wasm/openslide.js` * export). Providing it makes the worker load the glue from this URL instead of * its package-relative default — required under bundlers. Pair with `wasmBinary`. */ wasmUrl?: string; /** * URL to the worker JS (the `@.../openslide-js/worker` export). Required under * bundlers / CJS, where the package-relative default cannot be resolved at runtime. */ workerUrl?: string; /** * Factory that constructs a worker for each pool slot — the preferred way to wire * the worker under a bundler. Build the URL yourself so the bundler emits it as an * untraced asset, e.g. * `() => new Worker(new URL('@.../openslide-js/worker', import.meta.url), { type: 'module' })`. * Takes precedence over `workerUrl`. */ workerFactory?: () => Worker; /** * Pre-fetched WASM binary bytes. When provided, the worker hands these to the * Emscripten module instead of fetching `openslide.wasm` itself — removes the * sibling-file layout requirement under bundlers. Fetch/import the * `@.../openslide-js/wasm/openslide.wasm` export as an asset URL and pass the bytes. * Transferred to the worker, so it is consumed once. */ wasmBinary?: ArrayBuffer | Uint8Array; /** * Tuning for the shared I/O layer. When enabled (the default), one extra * lightweight broker worker is spawned via the same worker wiring; it owns * a block cache shared by all decode workers, serves local-file and * HTTP-range reads asynchronously, dedupes identical requests, and * prefetches ahead of sequential access. Disable to fall back to fully * independent per-worker I/O (Emscripten createLazyFile / WORKERFS). */ io?: { /** Spawn the shared I/O broker (default: true). */ enabled?: boolean; /** Bytes per cached block / per HTTP range request (default: 1 MiB). */ blockSize?: number; /** Byte budget of the broker's shared block cache (default: 256 MiB). */ brokerCacheBytes?: number; /** Blocks prefetched ahead of sequential reads (default: 2). */ readAhead?: number; /** Max concurrent readRegion calls per decode worker (default: 4). */ maxConcurrentReads?: number; }; } /** Source that can be opened as a slide. */ export type SlideSource = File | File[] | VirtualFile[] | URL | string; /** A file with a relative path, used for multi-file formats (MIRAX, VMS, DICOM). */ export interface VirtualFile { readonly path: string; readonly file: File; } /** * Messages sent from the main thread to a worker. * Each command has a unique `id` so responses can be matched. */ export type WorkerCommand = { id: number; cmd: 'init'; wasmUrl?: string; wasmBinary?: ArrayBuffer | Uint8Array; /** Present when a shared I/O broker is attached (port is transferred). */ ioPort?: MessagePort; ioSab?: SharedArrayBuffer; ioConfig?: IoConfig; } | { id: number; cmd: 'init-broker'; ioConfig: IoConfig; } | { id: number; cmd: 'attach-channel'; port: MessagePort; sab: SharedArrayBuffer; } | { id: number; cmd: 'open'; mountId: string; } | { id: number; cmd: 'close'; handle: number; } | { id: number; cmd: 'getSlideInfo'; handle: number; } | { id: number; cmd: 'readRegion'; handle: number; x: number; y: number; level: number; w: number; h: number; } | { id: number; cmd: 'readAssociatedImage'; handle: number; name: string; } | { id: number; cmd: 'getAssociatedImageDimensions'; handle: number; name: string; } | { id: number; cmd: 'detectVendor'; mountId: string; } | { id: number; cmd: 'getVersion'; } | { id: number; cmd: 'getIccProfile'; handle: number; } | { id: number; cmd: 'mountFile'; files: File[]; mountId: string; } | { id: number; cmd: 'mountDir'; entries: VirtualFile[]; indexFile: string; mountId: string; } | { id: number; cmd: 'mountUrl'; url: string; mountId: string; } | { id: number; cmd: 'unmount'; mountId: string; } | { id: number; cmd: 'cancel'; targetId: number; }; /** Messages sent from a worker back to the main thread. */ export type WorkerResponse = { id: number; ok: true; result: unknown; } | { id: number; ok: false; error: string; code?: string; }; /** * Emscripten module shape we expect after createOpenSlideModule() resolves. * Only the parts we use are typed here. */ export interface OpenSlideWasmModule { cwrap: (name: string, returnType: string | null, argTypes: string[], opts?: { async?: boolean; }) => (...args: unknown[]) => unknown; UTF8ToString: (ptr: number) => string; HEAPU8: Uint8Array; HEAP32: Int32Array; HEAP64: BigInt64Array; _malloc: (size: number) => number; _free: (ptr: number) => void; FS: EmscriptenFS; MEMFS: unknown; WORKERFS: unknown; } export interface EmscriptenFS { mkdir: (path: string) => void; rmdir: (path: string) => void; unlink: (path: string) => void; mount: (type: unknown, opts: Record, mountpoint: string) => unknown; unmount: (mountpoint: string) => void; readdir: (path: string) => string[]; readFile: (path: string, opts?: { encoding?: string; }) => Uint8Array; writeFile: (path: string, data: Uint8Array) => void; createLazyFile: (parent: string, name: string, url: string, canRead: boolean, canWrite: boolean) => unknown; /** Emscripten FS error class; instances carry an `errno`. */ ErrnoError: new (errno: number) => Error; } //# sourceMappingURL=types.d.ts.map