Adding ability to copy to clipboard as SVG (#1250)

This commit is contained in:
Roxana Chiorean 2020-04-05 16:13:17 -07:00 committed by GitHub
parent 2de4fe29ad
commit d5366db341
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 55 additions and 7 deletions

View file

@ -7,7 +7,10 @@ import { exportToCanvas, exportToSvg } from "../scene/export";
import { fileSave } from "browser-nativefs";
import { t } from "../i18n";
import { copyCanvasToClipboardAsPng } from "../clipboard";
import {
copyCanvasToClipboardAsPng,
copyCanvasToClipboardAsSvg,
} from "../clipboard";
import { serializeAsJSON } from "./json";
import { ExportType } from "../scene/types";
@ -299,16 +302,21 @@ export async function exportCanvas(
if (!hasNonDeletedElements(elements)) {
return window.alert(t("alerts.cannotExportEmptyCanvas"));
}
if (type === "svg") {
if (type === "svg" || type === "clipboard-svg") {
const tempSvg = exportToSvg(elements, {
exportBackground,
viewBackgroundColor,
exportPadding,
});
await fileSave(new Blob([tempSvg.outerHTML], { type: "image/svg+xml" }), {
fileName: `${name}.svg`,
});
return;
if (type === "svg") {
await fileSave(new Blob([tempSvg.outerHTML], { type: "image/svg+xml" }), {
fileName: `${name}.svg`,
});
return;
} else if (type === "clipboard-svg") {
copyCanvasToClipboardAsSvg(tempSvg);
return;
}
}
const tempCanvas = exportToCanvas(elements, appState, {