/** * libraw-wasm is browser-first: the wrapper spawns a Web Worker and the * Emscripten build loads libraw.wasm with fetch(). Node has neither a global * Worker nor file:// support in fetch, so the decoder runs in a worker_thread * with a tiny browser-globals shim (see libraw-worker.mjs). * * This is a no-op in the browser, where the real Worker already exists. */ let installed = false; export async function installLibrawRuntime() { if (installed) return; installed = true; if (typeof globalThis.Worker === 'function') return; const { Worker: NodeWorker } = await import('node:worker_threads'); const entry = new URL('./libraw-worker.mjs', import.meta.url); class BrowserWorker { constructor() { this._worker = new NodeWorker(entry); this._worker.on('message', (data) => this.onmessage?.({ data })); this._worker.on('error', (err) => this.onerror?.(err)); } postMessage(message, transfer) { this._worker.postMessage(message, transfer); } terminate() { return this._worker.terminate(); } } globalThis.Worker = BrowserWorker; }