File size: 854 Bytes
2bc6d22 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
import type { OutputType } from '../types';
// Track WASM module initialization
const wasmInitialized = new Map<OutputType, boolean>();
export async function ensureWasmLoaded(format: OutputType): Promise<void> {
if (wasmInitialized.get(format)) return;
try {
switch (format) {
case 'avif':
await import('@jsquash/avif');
break;
case 'jpeg':
await import('@jsquash/jpeg');
break;
case 'jxl':
await import('@jsquash/jxl');
break;
case 'png':
await import('@jsquash/png');
break;
case 'webp':
await import('@jsquash/webp');
break;
}
wasmInitialized.set(format, true);
} catch (error) {
console.error(`Failed to initialize WASM for ${format}:`, error);
throw new Error(`Failed to initialize ${format} support`);
}
} |