// heic-to 1.6.6 (LGPL-3.0); notices and corresponding source links: /licenses/heic.html import { heicTo, isHeic } from 'heic-to/next'; self.onmessage = async ({ data }: MessageEvent<{ file: File; quality: number }>) => { try { if (!await isHeic(data.file)) throw new Error('This is not a supported HEIC/HEIF image.'); const bitmap = await heicTo({ blob: data.file, type: 'bitmap' }); try { if (!bitmap.width || !bitmap.height || bitmap.width * bitmap.height > 40_000_000) throw new Error('HEIC image exceeds the 40-megapixel limit.'); const canvas = new OffscreenCanvas(bitmap.width, bitmap.height); const ctx = canvas.getContext('2d'); if (!ctx) throw new Error('OffscreenCanvas is unavailable in this browser.'); ctx.fillStyle = '#ffffff'; ctx.fillRect(0, 0, bitmap.width, bitmap.height); ctx.drawImage(bitmap, 0, 0); const blob = await canvas.convertToBlob({ type: 'image/jpeg', quality: data.quality }); self.postMessage({ blob }); } finally { bitmap.close(); } } catch (e) { self.postMessage({ error: (e as Error).message || 'Cannot decode this HEIC image.' }); } };