Initial commit: Luminary photo catalog and RAW editor
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>
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
Reference in New Issue
Block a user