cd52a2f82f
Browser-based photo catalog with an optional team server (SQLite + LibRaw). Local database, uploaded photos, build output and dependencies are gitignored. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
35 lines
1.1 KiB
JavaScript
35 lines
1.1 KiB
JavaScript
/**
|
|
* 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;
|
|
}
|