Fix embedding scene to PNG on Safari (#2235)

This commit is contained in:
David Luzar 2020-10-13 16:55:08 +02:00 committed by GitHub
parent 5950fa9a40
commit f40a2230ec
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 51 additions and 26 deletions

View file

@ -345,17 +345,10 @@ export const exportCanvas = async (
tempCanvas.toBlob(async (blob) => {
if (blob) {
if (appState.exportEmbedScene) {
const { default: tEXt } = await import("png-chunk-text");
const { default: encodePng } = await import("png-chunks-encode");
const { default: decodePng } = await import("png-chunks-extract");
const chunks = decodePng(new Uint8Array(await blob.arrayBuffer()));
const metadata = tEXt.encode(
MIME_TYPES.excalidraw,
serializeAsJSON(elements, appState),
);
// insert metadata before last chunk (iEND)
chunks.splice(-1, 0, metadata);
blob = new Blob([encodePng(chunks)], { type: "image/png" });
blob = await (await import("./png")).encodeTEXtChunk(blob, {
keyword: MIME_TYPES.excalidraw,
text: serializeAsJSON(elements, appState),
});
}
await fileSave(blob, {