import init, { hash_all, resize_preview, dct_coefficients, dct_masks, phash_lowfreq, mutate } from './pkg/image_similarity.js'; const ready = init(); onmessage = async (e) => { const { id, op, args } = e.data; await ready; try { const bytes = new Uint8Array(args.buffer); let result; switch (op) { case 'pipeline': result = { resize8: resize_preview(bytes, 8), resize32: resize_preview(bytes, 32), coefficients: dct_coefficients(bytes), masks: dct_masks(bytes), lowfreq: phash_lowfreq(bytes), hashes: hash_all(bytes), }; break; case 'hashes': result = { hashes: hash_all(bytes) }; break; case 'mutate': { const png = mutate(bytes, args.kind, args.amount); result = { png, hashes: hash_all(png) }; break; } default: throw new Error(`unknown op ${op}`); } postMessage({ id, ok: true, result }); } catch (err) { postMessage({ id, ok: false, error: String(err) }); } };