Break apart and improve the JS for rasterizing SVGs and downloading files (#786)

It now uses a blob URL instead of a data URL in the download process, which is cleaner and better performance.
This commit is contained in:
Keavon Chambers
2022-10-08 11:34:31 -07:00
committed by GitHub
parent 7291edeef5
commit 2ee57df709
9 changed files with 76 additions and 46 deletions

View File

@@ -6,13 +6,15 @@ export function createBlobManager(editor: Editor): void {
editor.subscriptions.subscribeJsMessage(UpdateImageData, (updateImageData) => {
updateImageData.imageData.forEach(async (element) => {
// Using updateImageData.imageData.buffer returns undefined for some reason?
const blob = new Blob([new Uint8Array(element.imageData.values()).buffer], { type: element.mime });
const buffer = new Uint8Array(element.imageData.values()).buffer;
const blob = new Blob([buffer], { type: element.mime });
const url = URL.createObjectURL(blob);
// 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, url, image.width, image.height);
editor.instance.setImageBlobUrl(element.path, blobURL, image.width, image.height);
});
});
}