// ...existing code... const worker = new Worker(new URL('./image.worker.ts', import.meta.url), { type: 'module' }); type WorkerReq = | { id: number; type: 'blurhashToBase64Image'; payload: { blurhash: string; width: number; height: number } } | { id: number; type: 'base64ImageToBlurhash'; payload: { base64Image: string } }; type WorkerRes = | { id: number; ok: true; data: string } | { id: number; ok: false; error: string }; let seq = 0; const pending = new Map void>(); worker.onmessage = (e: MessageEvent) => { const res = e.data; const cb = pending.get(res.id); if (cb) { pending.delete(res.id); cb(res); } }; function callWorker(req: Omit): Promise { return new Promise((resolve, reject) => { const id = ++seq; pending.set(id, (res) => (res.ok ? resolve(res.data) : reject(res.error))); worker.postMessage({ ...req, id }); }); } export function blurhashToBase64Image(blurhash: string, width: number, height: number): Promise { return callWorker({ type: 'blurhashToBase64Image', payload: { blurhash, width, height } }); } export function base64ImageToBlurhash(base64Image: string): Promise { return callWorker({ type: 'base64ImageToBlurhash', payload: { base64Image } }); } // ...existing code...