feat: resave to png/svg with metadata if you loaded your scene from a png/svg file (#3645)

Co-authored-by: dwelle <luzar.david@gmail.com>
This commit is contained in:
David Laban 2021-07-15 09:54:26 -04:00 committed by GitHub
parent 9581c45522
commit 685abac81a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 108 additions and 15 deletions

View file

@ -1,4 +1,4 @@
import { fileSave } from "browser-fs-access";
import { fileSave, FileSystemHandle } from "browser-fs-access";
import {
copyBlobToClipboardAsPng,
copyTextToSystemClipboard,
@ -24,11 +24,13 @@ export const exportCanvas = async (
exportPadding = DEFAULT_EXPORT_PADDING,
viewBackgroundColor,
name,
fileHandle = null,
}: {
exportBackground: boolean;
exportPadding?: number;
viewBackgroundColor: string;
name: string;
fileHandle?: FileSystemHandle | null;
},
) => {
if (elements.length === 0) {
@ -44,11 +46,14 @@ export const exportCanvas = async (
exportEmbedScene: appState.exportEmbedScene && type === "svg",
});
if (type === "svg") {
await fileSave(new Blob([tempSvg.outerHTML], { type: "image/svg+xml" }), {
fileName: `${name}.svg`,
extensions: [".svg"],
});
return;
return await fileSave(
new Blob([tempSvg.outerHTML], { type: "image/svg+xml" }),
{
fileName: `${name}.svg`,
extensions: [".svg"],
},
fileHandle,
);
} else if (type === "clipboard-svg") {
await copyTextToSystemClipboard(tempSvg.outerHTML);
return;
@ -76,10 +81,14 @@ export const exportCanvas = async (
});
}
await fileSave(blob, {
fileName,
extensions: [".png"],
});
return await fileSave(
blob,
{
fileName,
extensions: [".png"],
},
fileHandle,
);
} else if (type === "clipboard") {
try {
await copyBlobToClipboardAsPng(blob);