feat: Support exporting with dark mode (#3046)

Co-authored-by: Lipis <lipiridis@gmail.com>
Co-authored-by: dwelle <luzar.david@gmail.com>
This commit is contained in:
Arun 2021-02-24 19:52:17 +05:30 committed by GitHub
parent d213dbb42d
commit 4e421e6e9e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 264 additions and 14 deletions

View file

@ -7,7 +7,11 @@ import { renderScene, renderSceneToSvg } from "../renderer/renderScene";
import { distance, SVG_NS } from "../utils";
import { AppState } from "../types";
import { t } from "../i18n";
import { DEFAULT_FONT_FAMILY, DEFAULT_VERTICAL_ALIGN } from "../constants";
import {
DEFAULT_FONT_FAMILY,
DEFAULT_VERTICAL_ALIGN,
APPEARANCE_FILTER,
} from "../constants";
import { getDefaultAppState } from "../appState";
export const SVG_EXPORT_TAG = `<!-- svg-source:excalidraw -->`;
@ -61,6 +65,7 @@ export const exportToCanvas = (
tempCanvas,
{
viewBackgroundColor: exportBackground ? viewBackgroundColor : null,
exportWithDarkMode: appState.exportWithDarkMode,
scrollX: -minX + exportPadding,
scrollY: -minY + exportPadding,
zoom: getDefaultAppState().zoom,
@ -87,6 +92,7 @@ export const exportToSvg = (
exportBackground,
exportPadding = 10,
viewBackgroundColor,
exportWithDarkMode,
scale = 1,
shouldAddWatermark,
metadata = "",
@ -95,6 +101,7 @@ export const exportToSvg = (
exportPadding?: number;
scale?: number;
viewBackgroundColor: string;
exportWithDarkMode?: boolean;
shouldAddWatermark: boolean;
metadata?: string;
},
@ -114,6 +121,9 @@ export const exportToSvg = (
svgRoot.setAttribute("viewBox", `0 0 ${width} ${height}`);
svgRoot.setAttribute("width", `${width * scale}`);
svgRoot.setAttribute("height", `${height * scale}`);
if (exportWithDarkMode) {
svgRoot.setAttribute("filter", APPEARANCE_FILTER);
}
svgRoot.innerHTML = `
${SVG_EXPORT_TAG}

View file

@ -6,6 +6,7 @@ export type SceneState = {
scrollY: number;
// null indicates transparent bg
viewBackgroundColor: string | null;
exportWithDarkMode?: boolean;
zoom: Zoom;
shouldCacheIgnoreZoom: boolean;
remotePointerViewportCoords: { [id: string]: { x: number; y: number } };