mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-16 14:58:05 +08:00
It now uses a blob URL instead of a data URL in the download process, which is cleaner and better performance.
21 lines
851 B
TypeScript
21 lines
851 B
TypeScript
import { type Editor } from "@/wasm-communication/editor";
|
|
import { UpdateImageData } from "@/wasm-communication/messages";
|
|
|
|
export function createBlobManager(editor: Editor): void {
|
|
// Subscribe to process backend event
|
|
editor.subscriptions.subscribeJsMessage(UpdateImageData, (updateImageData) => {
|
|
updateImageData.imageData.forEach(async (element) => {
|
|
// Using updateImageData.imageData.buffer returns undefined for some reason?
|
|
const buffer = new Uint8Array(element.imageData.values()).buffer;
|
|
const blob = new Blob([buffer], { type: element.mime });
|
|
|
|
// TODO: Call `URL.revokeObjectURL` at the appropriate time to avoid a memory leak
|
|
const blobURL = URL.createObjectURL(blob);
|
|
|
|
const image = await createImageBitmap(blob);
|
|
|
|
editor.instance.setImageBlobUrl(element.path, blobURL, image.width, image.height);
|
|
});
|
|
});
|
|
}
|