Virtual whiteboard for sketching hand-drawn like diagrams
feat: support appState.exportEmbedScene to embed scene data in exportToSvg util (#3777)
Aakansha Doshif861a9fdd044
diff --git a/src/components/LibraryUnit.tsx b/src/components/LibraryUnit.tsxindex 30fc4f1239..4eb6b780c8 100644--- a/src/components/LibraryUnit.tsx+++ b/src/components/LibraryUnit.tsx@@ -36,21 +36,27 @@ export const LibraryUnit = ({if (!elementsToRender) {return;}- const svg = exportToSvg(elementsToRender, {- exportBackground: false,- viewBackgroundColor: oc.white,- });- for (const child of ref.current!.children) {- if (child.tagName !== "svg") {- continue;+ let svg: SVGSVGElement;+ const current = ref.current!;++ (async () => {+ svg = await exportToSvg(elementsToRender, {+ exportBackground: false,+ viewBackgroundColor: oc.white,+ });+ for (const child of ref.current!.children) {+ if (child.tagName !== "svg") {+ continue;+ }+ current!.removeChild(child);}- ref.current!.removeChild(child);- }- ref.current!.appendChild(svg);+ current!.appendChild(svg);+ })();- const current = ref.current!;return () => {- current.removeChild(svg);+ if (svg) {+ current.removeChild(svg);+ }};}, [elements, pendingElements]);diff --git a/src/components/PasteChartDialog.tsx b/src/components/PasteChartDialog.tsxindex 3c60921188..9f42355a55 100644--- a/src/components/PasteChartDialog.tsx+++ b/src/components/PasteChartDialog.tsx@@ -34,19 +34,21 @@ const ChartPreviewBtn = (props: {0,);setChartElements(elements);-- const svg = exportToSvg(elements, {- exportBackground: false,- viewBackgroundColor: oc.white,- });-+ let svg: SVGSVGElement;const previewNode = previewRef.current!;- previewNode.appendChild(svg);+ (async () => {+ svg = await exportToSvg(elements, {+ exportBackground: false,+ viewBackgroundColor: oc.white,+ });- if (props.selected) {- (previewNode.parentNode as HTMLDivElement).focus();- }+ previewNode.appendChild(svg);++ if (props.selected) {+ (previewNode.parentNode as HTMLDivElement).focus();+ }+ })();return () => {previewNode.removeChild(svg);diff --git a/src/data/index.ts b/src/data/index.tsindex 62d7e864d1..c1b50d8df0 100644--- a/src/data/index.ts+++ b/src/data/index.ts@@ -35,20 +35,13 @@ export const exportCanvas = async (throw new Error(t("alerts.cannotExportEmptyCanvas"));}if (type === "svg" || type === "clipboard-svg") {- const tempSvg = exportToSvg(elements, {+ const tempSvg = await exportToSvg(elements, {exportBackground,exportWithDarkMode: appState.exportWithDarkMode,viewBackgroundColor,exportPadding,exportScale: appState.exportScale,- metadata:- appState.exportEmbedScene && type === "svg"- ? await (- await import(/* webpackChunkName: "image" */ "./image")- ).encodeSvgMetadata({- text: serializeAsJSON(elements, appState),- })- : undefined,+ exportEmbedScene: appState.exportEmbedScene && type === "svg",});if (type === "svg") {await fileSave(new Blob([tempSvg.outerHTML], { type: "image/svg+xml" }), {@@ -57,7 +50,7 @@ export const exportCanvas = async (});return;} else if (type === "clipboard-svg") {- copyTextToSystemClipboard(tempSvg.outerHTML);+ await copyTextToSystemClipboard(tempSvg.outerHTML);return;}}diff --git a/src/data/json.ts b/src/data/json.tsindex 6ca7c75bfc..e1ed15de60 100644--- a/src/data/json.ts+++ b/src/data/json.ts@@ -15,7 +15,7 @@ import Library from "./library";export const serializeAsJSON = (elements: readonly ExcalidrawElement[],- appState: AppState,+ appState: Partial<AppState>,): string => {const data: ExportedDataState = {type: EXPORT_DATA_TYPES.excalidraw,diff --git a/src/packages/excalidraw/CHANGELOG.md b/src/packages/excalidraw/CHANGELOG.mdindex 901e7ef895..dd3a5e2b3f 100644--- a/src/packages/excalidraw/CHANGELOG.md+++ b/src/packages/excalidraw/CHANGELOG.md@@ -19,6 +19,13 @@ Please add the latest change on the top under the correct section.### Features+- Support `appState.exportEmbedScene` attribute in [`exportToSvg`](https://github.com/excalidraw/excalidraw/blob/master/src/packages/excalidraw/README.md#exportToSvg) which allows to embed the scene data.++ #### BREAKING CHANGE++ - The attribute `metadata` is now removed as `metadata` was only used to embed scene data which is now supported with the `appState.exportEmbedScene` attribute.+ - [`exportToSvg`](https://github.com/excalidraw/excalidraw/blob/master/src/packages/excalidraw/README.md#exportToSvg) now resolves to a promise which resolves to `svg` of the exported drawing.+- Expose [`loadLibraryFromBlob`](https://github.com/excalidraw/excalidraw/blob/master/src/packages/excalidraw/README.md#loadLibraryFromBlobY), [`loadFromBlob`](https://github.com/excalidraw/excalidraw/blob/master/src/packages/excalidraw/README.md#loadFromBlob), and [`getFreeDrawSvgPath`](https://github.com/excalidraw/excalidraw/blob/master/src/packages/excalidraw/README.md#getFreeDrawSvgPath).- Expose [`FONT_FAMILY`](https://github.com/excalidraw/excalidraw/blob/master/src/packages/excalidraw/README.md#FONT_FAMILY) so that consumer can use when passing `initialData.appState.currentItemFontFamily`.diff --git a/src/packages/excalidraw/README_NEXT.md b/src/packages/excalidraw/README_NEXT.mdindex 1c0c010a08..1cb4d85229 100644--- a/src/packages/excalidraw/README_NEXT.md+++ b/src/packages/excalidraw/README_NEXT.md@@ -829,9 +829,8 @@ exportToSvg({| elements | [Excalidraw Element []](https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#L78) | | The elements to exported as svg || appState | [AppState](https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L42) | [defaultAppState](https://github.com/excalidraw/excalidraw/blob/master/src/appState.ts#L11) | The app state of the scene || exportPadding | number | 10 | The padding to be added on canvas |-| metadata | string | '' | The metadata to be embedded in svg |-This function returns a svg with the exported elements.+This function returns a promise which resolves to svg of the exported drawing.##### Additional attributes of appState for `export\*` APIs@@ -840,6 +839,7 @@ This function returns a svg with the exported elements.| exportBackground | boolean | true | Indicates whether background should be exported || viewBackgroundColor | string | #fff | The default background color || exportWithDarkMode | boolean | false | Indicates whether to export with dark mode |+| exportEmbedScene | boolean | false | Indicates whether scene data should be embedded in svg. This will increase the svg size. |### FONT_FAMILYdiff --git a/src/packages/utils.ts b/src/packages/utils.tsindex 3fb446f679..3a21e190f1 100644--- a/src/packages/utils.ts+++ b/src/packages/utils.ts@@ -74,15 +74,13 @@ export const exportToBlob = (});};-export const exportToSvg = ({+export const exportToSvg = async ({elements,appState = getDefaultAppState(),exportPadding,- metadata,}: Omit<ExportOpts, "getDimensions"> & {exportPadding?: number;- metadata?: string;-}): SVGSVGElement => {+}): Promise<SVGSVGElement> => {const { elements: restoredElements, appState: restoredAppState } = restore({ elements, appState },null,@@ -90,7 +88,6 @@ export const exportToSvg = ({return _exportToSvg(getNonDeletedElements(restoredElements), {...restoredAppState,exportPadding,- metadata,});};diff --git a/src/scene/export.ts b/src/scene/export.tsindex 81823c1425..dabe80f95c 100644--- a/src/scene/export.ts+++ b/src/scene/export.ts@@ -6,6 +6,7 @@ import { distance, SVG_NS } from "../utils";import { AppState } from "../types";import { DEFAULT_EXPORT_PADDING, THEME_FILTER } from "../constants";import { getDefaultAppState } from "../appState";+import { serializeAsJSON } from "../data/json";export const SVG_EXPORT_TAG = `<!-- svg-source:excalidraw -->`;@@ -65,24 +66,35 @@ export const exportToCanvas = (return canvas;};-export const exportToSvg = (+export const exportToSvg = async (elements: readonly NonDeletedExcalidrawElement[],- {- exportBackground,- exportPadding = DEFAULT_EXPORT_PADDING,- viewBackgroundColor,- exportWithDarkMode,- exportScale = 1,- metadata = "",- }: {+ appState: {exportBackground: boolean;exportPadding?: number;exportScale?: number;viewBackgroundColor: string;exportWithDarkMode?: boolean;- metadata?: string;+ exportEmbedScene?: boolean;},-): SVGSVGElement => {+): Promise<SVGSVGElement> => {+ const {+ exportPadding = DEFAULT_EXPORT_PADDING,+ viewBackgroundColor,+ exportScale = 1,+ exportEmbedScene,+ } = appState;+ let metadata = "";+ if (exportEmbedScene) {+ try {+ metadata = await (+ await import(/* webpackChunkName: "image" */ "../../src/data/image")+ ).encodeSvgMetadata({+ text: serializeAsJSON(elements, appState),+ });+ } catch (err) {+ console.error(err);+ }+ }const [minX, minY, width, height] = getCanvasSize(elements, exportPadding);// initialze SVG root@@ -92,7 +104,7 @@ export const exportToSvg = (svgRoot.setAttribute("viewBox", `0 0 ${width} ${height}`);svgRoot.setAttribute("width", `${width * exportScale}`);svgRoot.setAttribute("height", `${height * exportScale}`);- if (exportWithDarkMode) {+ if (appState.exportWithDarkMode) {svgRoot.setAttribute("filter", THEME_FILTER);}@@ -114,7 +126,7 @@ export const exportToSvg = (`;// render background rect- if (exportBackground && viewBackgroundColor) {+ if (appState.exportBackground && viewBackgroundColor) {const rect = svgRoot.ownerDocument!.createElementNS(SVG_NS, "rect");rect.setAttribute("x", "0");rect.setAttribute("y", "0");diff --git a/src/tests/packages/__snapshots__/utils.test.ts.snap b/src/tests/packages/__snapshots__/utils.test.ts.snapindex 3fd22f6d54..81f142f36d 100644--- a/src/tests/packages/__snapshots__/utils.test.ts.snap+++ b/src/tests/packages/__snapshots__/utils.test.ts.snap@@ -39,7 +39,6 @@ Object {"isResizing": false,"isRotating": false,"lastPointerDownWith": "mouse",- "metadata": undefined,"multiElement": null,"name": "name","openMenu": null,diff --git a/src/tests/packages/utils.test.ts b/src/tests/packages/utils.test.tsindex 1eaad10958..cf7821e390 100644--- a/src/tests/packages/utils.test.ts+++ b/src/tests/packages/utils.test.ts@@ -73,11 +73,10 @@ describe("exportToSvg", () => {const mockedExportUtil = mockedSceneExportUtils.exportToSvg as jest.Mock;const passedElements = () => mockedExportUtil.mock.calls[0][0];const passedOptions = () => mockedExportUtil.mock.calls[0][1];-afterEach(jest.resetAllMocks);- it("with default arguments", () => {- utils.exportToSvg({+ it("with default arguments", async () => {+ await utils.exportToSvg({...diagramFactory({overrides: { appState: void 0 },}),@@ -88,13 +87,12 @@ describe("exportToSvg", () => {// To avoid varying snapshotsname: "name",};-expect(passedElements().length).toBe(3);expect(passedOptionsWhenDefault).toMatchSnapshot();});- it("with deleted elements", () => {- utils.exportToSvg({+ it("with deleted elements", async () => {+ await utils.exportToSvg({...diagramFactory({overrides: { appState: void 0 },elementOverrides: { isDeleted: true },@@ -104,18 +102,28 @@ describe("exportToSvg", () => {expect(passedElements().length).toBe(0);});- it("with exportPadding and metadata", () => {- const METADATA = "some metada";-- utils.exportToSvg({+ it("with exportPadding", async () => {+ await utils.exportToSvg({...diagramFactory({ overrides: { appState: { name: "diagram name" } } }),exportPadding: 0,- metadata: METADATA,});expect(passedElements().length).toBe(3);expect(passedOptions()).toEqual(- expect.objectContaining({ exportPadding: 0, metadata: METADATA }),+ expect.objectContaining({ exportPadding: 0 }),);});++ it("with exportEmbedScene", async () => {+ await utils.exportToSvg({+ ...diagramFactory({+ overrides: {+ appState: { name: "diagram name", exportEmbedScene: true },+ },+ }),+ });++ expect(passedElements().length).toBe(3);+ expect(passedOptions().exportEmbedScene).toBe(true);+ });});diff --git a/src/tests/scene/__snapshots__/export.test.ts.snap b/src/tests/scene/__snapshots__/export.test.ts.snapindex 6e683378cf..aee07550bb 100644--- a/src/tests/scene/__snapshots__/export.test.ts.snap+++ b/src/tests/scene/__snapshots__/export.test.ts.snap@@ -70,3 +70,22 @@ exports[`exportToSvg with default arguments 1`] = `</g></svg>`;++exports[`exportToSvg with exportEmbedScene 1`] = `+"+ <!-- svg-source:excalidraw -->+ <!-- payload-type:application/vnd.excalidraw+json --><!-- payload-version:2 --><!-- payload-start -->eyJ2ZXJzaW9uIjoiMSIsImVuY29kaW5nIjoiYnN0cmluZyIsImNvbXByZXNzZWQiOnRydWUsImVuY29kZWQiOiJ4nO1SQW7CMFx1MDAxMLzzisi9XCKRpIFQbrRUVaWqPXBAatWDiTexhbGD7Vx1MDAwMFx1MDAxMeLvtVx1MDAxZEjaqP1BfbC0szO76/WcXHUwMDA2QYBMXVx1MDAwMppcdTAwMDVcYo5cdTAwMTnmjCh8QEOH70FpJoVNxT7WslKZZ1JjytloxKVcdTAwMTVQqU3DXHUwMDA3XHUwMDBlW1x1MDAxMEZbxoeNg+Dkb5thxKn2K7V7m+dcdTAwMWImSLzLtunLYv707qWedLScJErauHaNb9M2PjBiqMWiMGwxXG6soKZcdTAwMDdiUXA3Zodoo+RcdTAwMDZcdTAwMWUkl8pccnJcdTAwMTP607Ve42xTKFlcdNJxojHG67zj5Izzpal5s1x1MDAwMJzRSlx1MDAwMep1WF1H7OGtTku74E5lW1x1MDAxNlSA1j80ssRcdTAwMTkzde9Vbr7ymfjtfvbrU6zKS1x1MDAxZKRd8G0yXHUwMDAw4ksl0WSc3oXTNtP9b1x1MDAxNId99FVcbv/XUTSdhmFcdTAwMTKnk5bB9MJ+tfFlc8w1dHt0K3xsbNCMKirO2/TVaIThrVx1MDAxNFx1MDAwNHn8PPz3yr9X/vRcbnDOSlxyXHUwMDE3r9jbv1x1MDAwN+GyXFxcdTAwMWFsXHUwMDFjpXFcdTAwMGXaMzjc//I3uT9Of1x1MDAxZZy/XHUwMDAw6cxEtiJ9<!-- payload-end -->+ <defs>+ <style>+ @font-face {+ font-family: \\"Virgil\\";+ src: url(\\"https://excalidraw.com/Virgil.woff2\\");+ }+ @font-face {+ font-family: \\"Cascadia\\";+ src: url(\\"https://excalidraw.com/Cascadia.woff2\\");+ }+ </style>+ </defs>+ <g stroke-linecap=\\"round\\" transform=\\"translate(10 10) rotate(0 50 50)\\"><path d=\\"M0.32 50.63 C0.32 50.63, 0.32 50.63, 0.32 50.63 M0.32 50.63 C0.32 50.63, 0.32 50.63, 0.32 50.63 M1.31 55.08 C15.31 40.32, 29.59 22.37, 41.3 9.81 M2.95 54.67 C16.06 38.64, 28.38 26.08, 41.31 11.16 M5.17 55.28 C18.64 40.54, 34.59 23.3, 53.31 1.2 M6.19 55.83 C19.7 40.85, 33.94 25.36, 52.84 2.99 M8.12 57.33 C28.32 38.18, 46.32 16.69, 57.78 5.54 M9.05 59.26 C25.33 39.84, 41.83 20.42, 56.36 4.41 M12.23 63.33 C23.99 47.5, 34.76 34.04, 58.25 7.72 M12.1 62.42 C25.64 45.74, 39.58 29.47, 59.39 6.7 M14.29 65.31 C33.6 44.37, 51.89 21.73, 61.4 11.6 M14.95 64.35 C25.42 51.41, 36.81 39.88, 61.57 11.19 M17.44 69.69 C30.26 56.06, 39.46 44.26, 65.11 14.18 M17.51 68.63 C34.43 47.57, 51.04 27.25, 64.33 13.82 M21.98 70.02 C37.96 53.4, 51.32 32.51, 66.76 17.85 M20.5 70.41 C29.55 59.82, 39.04 48.82, 66.82 15.79 M21.73 71.26 C33.76 59.36, 45.61 49.75, 69.47 19.91 M23.35 73.09 C39.91 53.14, 58.94 32.17, 69.77 19.39 M26.91 74.54 C41.56 60.59, 55.7 44.03, 72.29 22.07 M26.74 75.44 C39.06 62.99, 49.89 47.62, 73.34 21.9 M27.68 77.61 C45.49 62.49, 58.86 43.36, 74.53 26.67 M29.77 78.46 C46.48 58.69, 65.8 38.46, 75.03 24.23 M29.82 83.37 C45.64 68.39, 59.09 52.88, 78 26.2 M31.24 82.29 C42.16 70.24, 50.48 58.61, 77.54 28.77 M33.5 84.64 C46.6 69.19, 61.43 52.15, 81.17 32.8 M34.1 85.27 C44.17 73.12, 52.8 63.6, 80.62 31.25 M37.69 88.37 C54.96 70.16, 71.4 49.55, 82.89 35.26 M37.41 86.61 C46.27 76.03, 56.22 65.63, 84.34 34.18 M38.98 88.4 C54.78 76.48, 66.88 59.43, 87.83 36.78 M40.83 89.54 C52.97 74.67, 64.21 61.17, 86.21 36.91 M43.18 94 C60.91 72.19, 77.04 51.45, 90.21 39.94 M43.86 92.11 C52.94 82.13, 62.98 68.89, 90.51 39.02 M44.93 94.32 C62.61 77.05, 76.42 59.94, 91.95 44.23 M45.02 96.15 C61.2 76.98, 78.3 58.77, 92.03 42.23 M50.55 99.15 C60.63 81.82, 75.04 67.37, 96.9 43.53 M48.39 98.32 C65.04 78.28, 81.92 59.44, 94.04 46.22 M50.38 99.19 C69.54 81.19, 85.85 58.94, 99.21 46.38 M51.53 100.79 C62.45 87.27, 73.41 74.93, 98.13 47.3\\" stroke=\\"#15aabf\\" stroke-width=\\"0.5\\" fill=\\"none\\"></path><path d=\\"M50.55 -1.01 C62.82 12.44, 78.03 26.68, 100.3 51.7 M50.44 0.46 C69.95 19.26, 89.63 39.73, 99.86 51.76 M98.12 50.21 C82.92 71.13, 65.15 88.19, 49.66 98.72 M99.37 50.68 C88.57 62.94, 74.79 76.37, 50.44 100 M52.55 99.9 C35.86 87.61, 23.16 74.12, 0.75 52.33 M51.67 99.75 C32.82 83.31, 13.73 65.72, 0.11 50.74 M-1.95 52.94 C13.84 37.62, 25.27 26.82, 50.8 2 M0.66 50.92 C16.45 35.71, 32.61 18.7, 51.59 0.01\\" stroke=\\"#000000\\" stroke-width=\\"1\\" fill=\\"none\\"></path></g><g stroke-linecap=\\"round\\" transform=\\"translate(10 10) rotate(0 50 50)\\"><path d=\\"M9.1 22.49 C9.1 22.49, 9.1 22.49, 9.1 22.49 M9.1 22.49 C9.1 22.49, 9.1 22.49, 9.1 22.49 M5.77 34.22 C14.36 22.39, 22.36 11.34, 31.07 6.16 M5.74 33.57 C13.28 24.57, 21.83 14.09, 29.33 4.8 M1.23 43.13 C12.49 30.87, 24.28 17.19, 34.78 7.14 M0.78 46 C12.56 32.19, 24.3 18.11, 32.96 6.34 M2.3 48.83 C11.51 37.56, 20.27 29.99, 39.82 4.91 M2.21 50.21 C10.16 39.89, 19.68 28.47, 40.7 3.65 M4.46 52.24 C13.09 44.78, 21.1 35.66, 46.51 4.97 M3.22 53.5 C15.99 38.74, 28.11 23.79, 45.23 4.55 M3.7 57.1 C21.08 38.76, 39.06 16.84, 49.96 5.38 M4 57.63 C21.68 38.63, 38.67 19.88, 51.09 4.43 M5.63 62.59 C22.78 43.8, 38.57 25.25, 57.12 5.4 M6.42 63.73 C20 47.05, 33.52 29.6, 55.39 5.18 M6.29 69.75 C28.35 43.73, 50.39 20.01, 62.3 5.41 M6.55 67.14 C26.89 44.76, 48.04 20.25, 60.97 5.55 M6.43 71.54 C23.57 54.72, 38.46 35.12, 65.52 4.96 M8.48 71.83 C24.77 52.24, 41.74 32.02, 68.31 3.52 M9.85 78.82 C21.92 63.22, 36.32 49.18, 72.01 7.25 M10.34 76.77 C27.8 55.85, 45.88 36.07, 70.74 7.22 M13.47 81.32 C26.18 62.12, 40.64 46.38, 72.42 9.85 M11.98 79.26 C28.81 59.84, 44.9 40.14, 74.2 7.97 M14.47 81.96 C29.58 65.65, 48.85 43.63, 77.17 11.75 M15.71 83.63 C33.93 59.85, 53.84 38.02, 77.26 9.73 M19.67 86.03 C41.16 55.76, 63.43 30.34, 80.66 12.59 M17.37 84.79 C38.71 60.94, 61.5 34.23, 80.96 12.69 M19.91 87.73 C41.44 67.18, 59.41 43.22, 83.48 14.14 M20.25 89.16 C44.7 60.7, 70.47 31.42, 84.59 15.14 M24.91 90.9 C46.5 64.19, 68.96 37.43, 88.75 16.59 M23.65 91.77 C41.74 71.55, 57.53 52.68, 87.72 16.15 M26.22 94.31 C42.53 75.86, 55.98 57.16, 92.28 20.02 M25.38 93.87 C44.67 73.25, 64.62 51.62, 91.97 19.36 M28.08 96.32 C54.48 69.01, 76.82 39.31, 90.89 24.16 M28.34 96.1 C48.97 75.04, 66.53 54.17, 92.9 23.19 M33.02 97.72 C47.48 83.29, 62.73 64.85, 92.58 25.89 M33.66 97.55 C55.76 73.21, 77.03 49.03, 93.88 28.62 M37.54 98.21 C61 73.98, 80.28 54.46, 97.51 30.73 M38.05 98.71 C55.6 79.01, 75.12 58.73, 96.66 31.16 M40.92 99.39 C55.99 83.84, 65.31 70.37, 99.58 35.1 M42.21 98.8 C59.51 80.81, 76.05 64.07, 98.57 35.42 M48.14 101.48 C61.55 83.13, 75.71 68.34, 98.66 42.07 M47.41 100.91 C67.12 78.22, 87.79 53.87, 100.38 41.25 M52.83 100.62 C65.19 89.21, 73.66 75.25, 101.5 44.37 M52.01 99.58 C63.62 88.79, 74.27 77.94, 102.85 43.1 M60.18 98.08 C72.2 83.16, 84.82 72.21, 100.73 50.13 M60.05 98.5 C75.4 81.69, 89.82 65.38, 101.33 50.2 M69.22 94.3 C81.71 79.01, 90.86 65.35, 98.94 57.1 M67.15 94.84 C80.76 81.44, 92.01 66.54, 99.48 57.09 M73.7 91.36 C80.74 85.9, 88.97 76.41, 98.39 64.44 M74.95 92.14 C82 85.41, 86.16 79.57, 98.62 65.83\\" stroke=\\"#15aabf\\" stroke-width=\\"0.5\\" fill=\\"none\\"></path><path d=\\"M38.1 1.46 C46.16 -1.16, 56.71 -0.02, 65.18 2.66 C73.65 5.34, 83.24 11.02, 88.93 17.56 C94.62 24.1, 98.08 33.29, 99.33 41.91 C100.57 50.52, 100.02 61.1, 96.4 69.26 C92.78 77.42, 85.02 85.78, 77.6 90.87 C70.18 95.96, 60.4 99.19, 51.89 99.79 C43.38 100.39, 34 98.58, 26.52 94.48 C19.04 90.38, 11.58 83.1, 7.02 75.21 C2.45 67.32, -1.27 55.98, -0.88 47.14 C-0.49 38.3, 4.07 29.35, 9.38 22.18 C14.68 15, 25.59 7.81, 30.94 4.11 C36.3 0.41, 38.93 0.51, 41.51 -0.03 C44.09 -0.57, 46.05 0.05, 46.43 0.87 M40.94 1.53 C48.74 -0.34, 60.25 0.56, 68.52 3.89 C76.78 7.23, 85.3 14.15, 90.51 21.54 C95.71 28.92, 99.17 39.56, 99.73 48.2 C100.29 56.83, 97.86 65.69, 93.86 73.36 C89.86 81.02, 83.18 89.65, 75.74 94.18 C68.29 98.7, 58.02 100.83, 49.21 100.52 C40.4 100.21, 30.4 97.11, 22.85 92.3 C15.31 87.48, 7.5 79.9, 3.94 71.62 C0.38 63.33, 0.13 51.37, 1.51 42.58 C2.88 33.8, 6.72 25.34, 12.17 18.9 C17.62 12.46, 29.22 7.05, 34.23 3.94 C39.24 0.83, 41.03 0.53, 42.22 0.24 C43.41 -0.05, 41.49 1.56, 41.37 2.2\\" stroke=\\"#000000\\" stroke-width=\\"1\\" fill=\\"none\\"></path></g>"+`;diff --git a/src/tests/scene/export.test.ts b/src/tests/scene/export.test.tsindex e31d4ff47d..f9e0211e8e 100644--- a/src/tests/scene/export.test.ts+++ b/src/tests/scene/export.test.ts@@ -15,16 +15,16 @@ describe("exportToSvg", () => {viewBackgroundColor: "#ffffff",};- it("with default arguments", () => {- const svgElement = exportUtils.exportToSvg(ELEMENTS, DEFAULT_OPTIONS);+ it("with default arguments", async () => {+ const svgElement = await exportUtils.exportToSvg(ELEMENTS, DEFAULT_OPTIONS);expect(svgElement).toMatchSnapshot();});- it("with background color", () => {+ it("with background color", async () => {const BACKGROUND_COLOR = "#abcdef";- const svgElement = exportUtils.exportToSvg(ELEMENTS, {+ const svgElement = await exportUtils.exportToSvg(ELEMENTS, {...DEFAULT_OPTIONS,exportBackground: true,viewBackgroundColor: BACKGROUND_COLOR,@@ -36,8 +36,8 @@ describe("exportToSvg", () => {);});- it("with dark mode", () => {- const svgElement = exportUtils.exportToSvg(ELEMENTS, {+ it("with dark mode", async () => {+ const svgElement = await exportUtils.exportToSvg(ELEMENTS, {...DEFAULT_OPTIONS,exportWithDarkMode: true,});@@ -47,14 +47,12 @@ describe("exportToSvg", () => {);});- it("with exportPadding, metadata", () => {- const svgElement = exportUtils.exportToSvg(ELEMENTS, {+ it("with exportPadding", async () => {+ const svgElement = await exportUtils.exportToSvg(ELEMENTS, {...DEFAULT_OPTIONS,exportPadding: 0,- metadata: "some metadata",});- expect(svgElement.innerHTML).toMatch(/some metadata/);expect(svgElement).toHaveAttribute("height", ELEMENT_HEIGHT.toString());expect(svgElement).toHaveAttribute("width", ELEMENT_WIDTH.toString());expect(svgElement).toHaveAttribute(@@ -63,10 +61,10 @@ describe("exportToSvg", () => {);});- it("with scale", () => {+ it("with scale", async () => {const SCALE = 2;- const svgElement = exportUtils.exportToSvg(ELEMENTS, {+ const svgElement = await exportUtils.exportToSvg(ELEMENTS, {...DEFAULT_OPTIONS,exportPadding: 0,exportScale: SCALE,@@ -81,4 +79,12 @@ describe("exportToSvg", () => {(ELEMENT_WIDTH * SCALE).toString(),);});++ it("with exportEmbedScene", async () => {+ const svgElement = await exportUtils.exportToSvg(ELEMENTS, {+ ...DEFAULT_OPTIONS,+ exportEmbedScene: true,+ });+ expect(svgElement.innerHTML).toMatchSnapshot();+ });});