ente/web/packages/media/heic-convert.ts
Manav Rathi 18cc16bcc0
Use preferred casing of Wasm
From webassembly.org

> WebAssembly (abbreviated _Wasm_) is ...
2025-02-03 11:15:00 +05:30

28 lines
943 B
TypeScript

import { ComlinkWorker } from "@/base/worker/comlink-worker";
import type { HEICConvertWorker } from "./heic-convert.worker";
/**
* Convert a HEIC image to a JPEG.
*
* Behind the scenes, it uses a web worker to do the conversion using a Wasm
* HEIC conversion package.
*
* @param heicBlob The HEIC blob to convert.
*
* @returns The JPEG blob.
*/
export const heicToJPEG = async (heicBlob: Blob) =>
worker().then((w) => w.heicToJPEG(heicBlob));
/** Cached instance of the {@link ComlinkWorker} that wraps our web worker. */
let _comlinkWorker: ComlinkWorker<typeof HEICConvertWorker> | undefined;
/** Lazily created, cached, instance of our web worker. */
const worker = async () => (_comlinkWorker ??= createComlinkWorker()).remote;
const createComlinkWorker = () =>
new ComlinkWorker<typeof HEICConvertWorker>(
"heic-convert-worker",
new Worker(new URL("heic-convert.worker.ts", import.meta.url)),
);