Skip to content

Virtual whiteboard for sketching hand-drawn like diagrams

feat: render frames on export (#7210)

David Luzar864c0b3ea808
diff --git a/excalidraw-app/tests/reconciliation.test.ts b/excalidraw-app/tests/reconciliation.test.ts
index c3e247406c..26fb5b8ca0 100644
--- a/excalidraw-app/tests/reconciliation.test.ts
+++ b/excalidraw-app/tests/reconciliation.test.ts
@@ -8,6 +8,7 @@ import {
} from "../../excalidraw-app/collab/reconciliation";
import { randomInteger } from "../../src/random";
import { AppState } from "../../src/types";
+import { cloneJSON } from "../../src/utils";
type Id = string;
type ElementLike = {
@@ -93,8 +94,6 @@ const cleanElements = (elements: ReconciledElements) => {
});
};
-const cloneDeep = (data: any) => JSON.parse(JSON.stringify(data));
-
const test = <U extends `${string}:${"L" | "R"}`>(
local: (Id | ElementLike)[],
remote: (Id | ElementLike)[],
@@ -115,15 +114,15 @@ const test = <U extends `${string}:${"L" | "R"}`>(
"remote reconciliation",
);
- const __local = cleanElements(cloneDeep(_remote));
- const __remote = addParents(cleanElements(cloneDeep(remoteReconciled)));
+ const __local = cleanElements(cloneJSON(_remote) as ReconciledElements);
+ const __remote = addParents(cleanElements(cloneJSON(remoteReconciled)));
if (bidirectional) {
try {
expect(
cleanElements(
reconcileElements(
- cloneDeep(__local),
- cloneDeep(__remote),
+ cloneJSON(__local),
+ cloneJSON(__remote),
{} as AppState,
),
),
diff --git a/src/actions/actionClipboard.tsx b/src/actions/actionClipboard.tsx
index 03fdc6a4d0..dadc610136 100644
--- a/src/actions/actionClipboard.tsx
+++ b/src/actions/actionClipboard.tsx
@@ -9,8 +9,8 @@ import {
readSystemClipboard,
} from "../clipboard";
import { actionDeleteSelected } from "./actionDeleteSelected";
-import { exportCanvas } from "../data/index";
-import { getNonDeletedElements, isTextElement } from "../element";
+import { exportCanvas, prepareElementsForExport } from "../data/index";
+import { isTextElement } from "../element";
import { t } from "../i18n";
import { isFirefox } from "../constants";
@@ -122,20 +122,23 @@ export const actionCopyAsSvg = register({
commitToHistory: false,
};
}
- const selectedElements = app.scene.getSelectedElements({
- selectedElementIds: appState.selectedElementIds,
- includeBoundTextElement: true,
- includeElementsInFrames: true,
- });
+
+ const { exportedElements, exportingFrame } = prepareElementsForExport(
+ elements,
+ appState,
+ true,
+ );
+
try {
await exportCanvas(
"clipboard-svg",
- selectedElements.length
- ? selectedElements
- : getNonDeletedElements(elements),
+ exportedElements,
appState,
app.files,
- appState,
+ {
+ ...appState,
+ exportingFrame,
+ },
);
return {
commitToHistory: false,
@@ -171,16 +174,17 @@ export const actionCopyAsPng = register({
includeBoundTextElement: true,
includeElementsInFrames: true,
});
+
+ const { exportedElements, exportingFrame } = prepareElementsForExport(
+ elements,
+ appState,
+ true,
+ );
try {
- await exportCanvas(
- "clipboard",
- selectedElements.length
- ? selectedElements
- : getNonDeletedElements(elements),
- appState,
- app.files,
- appState,
- );
+ await exportCanvas("clipboard", exportedElements, appState, app.files, {
+ ...appState,
+ exportingFrame,
+ });
return {
appState: {
...appState,
diff --git a/src/actions/actionDuplicateSelection.tsx b/src/actions/actionDuplicateSelection.tsx
index a21260d5bb..060a286800 100644
--- a/src/actions/actionDuplicateSelection.tsx
+++ b/src/actions/actionDuplicateSelection.tsx
@@ -25,7 +25,7 @@ import { normalizeElementOrder } from "../element/sortElements";
import { DuplicateIcon } from "../components/icons";
import {
bindElementsToFramesAfterDuplication,
- getFrameElements,
+ getFrameChildren,
} from "../frame";
import {
excludeElementsInFramesFromSelection,
@@ -155,7 +155,7 @@ const duplicateElements = (
groupId,
).flatMap((element) =>
isFrameElement(element)
- ? [...getFrameElements(elements, element.id), element]
+ ? [...getFrameChildren(elements, element.id), element]
: [element],
);
@@ -181,7 +181,7 @@ const duplicateElements = (
continue;
}
if (isElementAFrame) {
- const elementsInFrame = getFrameElements(sortedElements, element.id);
+ const elementsInFrame = getFrameChildren(sortedElements, element.id);
elementsWithClones.push(
...markAsProcessed([
diff --git a/src/actions/actionFrame.ts b/src/actions/actionFrame.ts
index 1266920ea7..9e8c16c23d 100644
--- a/src/actions/actionFrame.ts
+++ b/src/actions/actionFrame.ts
@@ -1,7 +1,7 @@
import { getNonDeletedElements } from "../element";
import { ExcalidrawElement } from "../element/types";
import { removeAllElementsFromFrame } from "../frame";
-import { getFrameElements } from "../frame";
+import { getFrameChildren } from "../frame";
import { KEYS } from "../keys";
import { AppClassProperties, AppState } from "../types";
import { updateActiveTool } from "../utils";
@@ -21,7 +21,7 @@ export const actionSelectAllElementsInFrame = register({
const selectedFrame = app.scene.getSelectedElements(appState)[0];
if (selectedFrame && selectedFrame.type === "frame") {
- const elementsInFrame = getFrameElements(
+ const elementsInFrame = getFrameChildren(
getNonDeletedElements(elements),
selectedFrame.id,
).filter((element) => !(element.type === "text" && element.containerId));
diff --git a/src/actions/actionStyles.ts b/src/actions/actionStyles.ts
index 88d4b4c479..2b656b050e 100644
--- a/src/actions/actionStyles.ts
+++ b/src/actions/actionStyles.ts
@@ -21,8 +21,10 @@ import {
canApplyRoundnessTypeToElement,
getDefaultRoundnessTypeForElement,
isFrameElement,
+ isArrowElement,
} from "../element/typeChecks";
import { getSelectedElements } from "../scene";
+import { ExcalidrawTextElement } from "../element/types";
// `copiedStyles` is exported only for tests.
export let copiedStyles: string = "{}";
@@ -99,16 +101,19 @@ export const actionPasteStyles = register({
if (isTextElement(newElement)) {
const fontSize =
- elementStylesToCopyFrom?.fontSize || DEFAULT_FONT_SIZE;
+ (elementStylesToCopyFrom as ExcalidrawTextElement).fontSize ||
+ DEFAULT_FONT_SIZE;
const fontFamily =
- elementStylesToCopyFrom?.fontFamily || DEFAULT_FONT_FAMILY;
+ (elementStylesToCopyFrom as ExcalidrawTextElement).fontFamily ||
+ DEFAULT_FONT_FAMILY;
newElement = newElementWith(newElement, {
fontSize,
fontFamily,
textAlign:
- elementStylesToCopyFrom?.textAlign || DEFAULT_TEXT_ALIGN,
+ (elementStylesToCopyFrom as ExcalidrawTextElement).textAlign ||
+ DEFAULT_TEXT_ALIGN,
lineHeight:
- elementStylesToCopyFrom.lineHeight ||
+ (elementStylesToCopyFrom as ExcalidrawTextElement).lineHeight ||
getDefaultLineHeight(fontFamily),
});
let container = null;
@@ -123,7 +128,10 @@ export const actionPasteStyles = register({
redrawTextBoundingBox(newElement, container);
}
- if (newElement.type === "arrow") {
+ if (
+ newElement.type === "arrow" &&
+ isArrowElement(elementStylesToCopyFrom)
+ ) {
newElement = newElementWith(newElement, {
startArrowhead: elementStylesToCopyFrom.startArrowhead,
endArrowhead: elementStylesToCopyFrom.endArrowhead,
diff --git a/src/components/App.tsx b/src/components/App.tsx
index 889c816dd0..493877c2c2 100644
--- a/src/components/App.tsx
+++ b/src/components/App.tsx
@@ -87,7 +87,7 @@ import {
ZOOM_STEP,
POINTER_EVENTS,
} from "../constants";
-import { exportCanvas, loadFromBlob } from "../data";
+import { ExportedElements, exportCanvas, loadFromBlob } from "../data";
import Library, { distributeLibraryItemsOnSquareGrid } from "../data/library";
import { restore, restoreElements } from "../data/restore";
import {
@@ -317,7 +317,7 @@ import { shouldShowBoundingBox } from "../element/transformHandles";
import { actionUnlockAllElements } from "../actions/actionElementLock";
import { Fonts } from "../scene/Fonts";
import {
- getFrameElements,
+ getFrameChildren,
isCursorInFrame,
bindElementsToFramesAfterDuplication,
addElementsToFrame,
@@ -1048,12 +1048,6 @@ class App extends React.Component<AppProps, AppState> {
this.state,
);
- const { x: x2 } = sceneCoordsToViewportCoords(
- { sceneX: f.x + f.width, sceneY: f.y + f.height },
- this.state,
- );
-
- const FRAME_NAME_GAP = 20;
const FRAME_NAME_EDIT_PADDING = 6;
const reset = () => {
@@ -1098,13 +1092,12 @@ class App extends React.Component<AppProps, AppState> {
boxShadow: "inset 0 0 0 1px var(--color-primary)",
fontFamily: "Assistant",
fontSize: "14px",
- transform: `translateY(-${FRAME_NAME_EDIT_PADDING}px)`,
+ transform: `translate(-${FRAME_NAME_EDIT_PADDING}px, ${FRAME_NAME_EDIT_PADDING}px)`,
color: "var(--color-gray-80)",
overflow: "hidden",
- maxWidth: `${Math.min(
- x2 - x1 - FRAME_NAME_EDIT_PADDING,
- document.body.clientWidth - x1 - FRAME_NAME_EDIT_PADDING,
- )}px`,
+ maxWidth: `${
+ document.body.clientWidth - x1 - FRAME_NAME_EDIT_PADDING
+ }px`,
}}
size={frameNameInEdit.length + 1 || 1}
dir="auto"
@@ -1126,19 +1119,26 @@ class App extends React.Component<AppProps, AppState> {
key={f.id}
style={{
position: "absolute",
- top: `${y1 - FRAME_NAME_GAP - this.state.offsetTop}px`,
- left: `${
- x1 -
- this.state.offsetLeft -
- (this.state.editingFrame === f.id ? FRAME_NAME_EDIT_PADDING : 0)
+ // Positioning from bottom so that we don't to either
+ // calculate text height or adjust using transform (which)
+ // messes up input position when editing the frame name.
+ // This makes the positioning deterministic and we can calculate
+ // the same position when rendering to canvas / svg.
+ bottom: `${
+ this.state.height +
+ FRAME_STYLE.nameOffsetY -
+ y1 +
+ this.state.offsetTop
}px`,
+ left: `${x1 - this.state.offsetLeft}px`,
zIndex: 2,
- fontSize: "14px",
+ fontSize: FRAME_STYLE.nameFontSize,
color: isDarkTheme
- ? "var(--color-gray-60)"
- : "var(--color-gray-50)",
+ ? FRAME_STYLE.nameColorDarkTheme
+ : FRAME_STYLE.nameColorLightTheme,
+ lineHeight: FRAME_STYLE.nameLineHeight,
width: "max-content",
- maxWidth: `${x2 - x1 + FRAME_NAME_EDIT_PADDING * 2}px`,
+ maxWidth: `${f.width}px`,
overflow: f.id === this.state.editingFrame ? "visible" : "hidden",
whiteSpace: "nowrap",
textOverflow: "ellipsis",
@@ -1370,7 +1370,8 @@ class App extends React.Component<AppProps, AppState> {
public onExportImage = async (
type: keyof typeof EXPORT_IMAGE_TYPES,
- elements: readonly NonDeletedExcalidrawElement[],
+ elements: ExportedElements,
+ opts: { exportingFrame: ExcalidrawFrameElement | null },
) => {
trackEvent("export", type, "ui");
const fileHandle = await exportCanvas(
@@ -1382,6 +1383,7 @@ class App extends React.Component<AppProps, AppState> {
exportBackground: this.state.exportBackground,
name: this.state.name,
viewBackgroundColor: this.state.viewBackgroundColor,
+ exportingFrame: opts.exportingFrame,
},
)
.catch(muteFSAbortError)
@@ -5330,7 +5332,7 @@ class App extends React.Component<AppProps, AppState> {
// if hitElement is frame, deselect all of its elements if they are selected
if (hitElement.type === "frame") {
- getFrameElements(
+ getFrameChildren(
previouslySelectedElements,
hitElement.id,
).forEach((element) => {
@@ -8194,7 +8196,7 @@ class App extends React.Component<AppProps, AppState> {
>();
selectedFrames.forEach((frame) => {
- const elementsInFrame = getFrameElements(
+ const elementsInFrame = getFrameChildren(
this.scene.getNonDeletedElements(),
frame.id,
);
@@ -8264,7 +8266,7 @@ class App extends React.Component<AppProps, AppState> {
const elementsToHighlight = new Set<ExcalidrawElement>();
selectedFrames.forEach((frame) => {
- const elementsInFrame = getFrameElements(
+ const elementsInFrame = getFrameChildren(
this.scene.getNonDeletedElements(),
frame.id,
);
diff --git a/src/components/ImageExportDialog.tsx b/src/components/ImageExportDialog.tsx
index 960c87f2db..c85272abff 100644
--- a/src/components/ImageExportDialog.tsx
+++ b/src/components/ImageExportDialog.tsx
@@ -22,7 +22,7 @@ import { canvasToBlob } from "../data/blob";
import { nativeFileSystemSupported } from "../data/filesystem";
import { NonDeletedExcalidrawElement } from "../element/types";
import { t } from "../i18n";
-import { getSelectedElements, isSomeElementSelected } from "../scene";
+import { isSomeElementSelected } from "../scene";
import { exportToCanvas } from "../packages/utils";
import { copyIcon, downloadIcon, helpIcon } from "./icons";
@@ -34,6 +34,8 @@ import { Tooltip } from "./Tooltip";
import "./ImageExportDialog.scss";
import { useAppProps } from "./App";
import { FilledButton } from "./FilledButton";
+import { cloneJSON } from "../utils";
+import { prepareElementsForExport } from "../data";
const supportsContextFilters =
"filter" in document.createElement("canvas").getContext("2d")!;
@@ -51,44 +53,47 @@ export const ErrorCanvasPreview = () => {
};
type ImageExportModalProps = {
- appState: UIAppState;
- elements: readonly NonDeletedExcalidrawElement[];
+ appStateSnapshot: Readonly<UIAppState>;
+ elementsSnapshot: readonly NonDeletedExcalidrawElement[];
files: BinaryFiles;
actionManager: ActionManager;
onExportImage: AppClassProperties["onExportImage"];
};
const ImageExportModal = ({
- appState,
- elements,
+ appStateSnapshot,
+ elementsSnapshot,
files,
actionManager,
onExportImage,
}: ImageExportModalProps) => {
- const appProps = useAppProps();
- const [projectName, setProjectName] = useState(appState.name);
-
- const someElementIsSelected = isSomeElementSelected(elements, appState);
+ const hasSelection = isSomeElementSelected(
+ elementsSnapshot,
+ appStateSnapshot,
+ );
- const [exportSelected, setExportSelected] = useState(someElementIsSelected);
+ const appProps = useAppProps();
+ const [projectName, setProjectName] = useState(appStateSnapshot.name);
+ const [exportSelectionOnly, setExportSelectionOnly] = useState(hasSelection);
const [exportWithBackground, setExportWithBackground] = useState(
- appState.exportBackground,
+ appStateSnapshot.exportBackground,
);
const [exportDarkMode, setExportDarkMode] = useState(
- appState.exportWithDarkMode,
+ appStateSnapshot.exportWithDarkMode,
+ );
+ const [embedScene, setEmbedScene] = useState(
+ appStateSnapshot.exportEmbedScene,
);
- const [embedScene, setEmbedScene] = useState(appState.exportEmbedScene);
- const [exportScale, setExportScale] = useState(appState.exportScale);
+ const [exportScale, setExportScale] = useState(appStateSnapshot.exportScale);
const previewRef = useRef<HTMLDivElement>(null);
const [renderError, setRenderError] = useState<Error | null>(null);
- const exportedElements = exportSelected
- ? getSelectedElements(elements, appState, {
- includeBoundTextElement: true,
- includeElementsInFrames: true,
- })
- : elements;
+ const { exportedElements, exportingFrame } = prepareElementsForExport(
+ elementsSnapshot,
+ appStateSnapshot,
+ exportSelectionOnly,
+ );
useEffect(() => {
const previewNode = previewRef.current;
@@ -102,10 +107,18 @@ const ImageExportModal = ({
}
exportToCanvas({
elements: exportedElements,
- appState,
+ appState: {
+ ...appStateSnapshot,
+ name: projectName,
+ exportBackground: exportWithBackground,
+ exportWithDarkMode: exportDarkMode,
+ exportScale,
+ exportEmbedScene: embedScene,
+ },
files,
exportPadding: DEFAULT_EXPORT_PADDING,
maxWidthOrHeight: Math.max(maxWidth, maxHeight),
+ exportingFrame,
})
.then((canvas) => {
setRenderError(null);
@@ -119,7 +132,17 @@ const ImageExportModal = ({
console.error(error);
setRenderError(error);
});
- }, [appState, files, exportedElements]);
+ }, [
+ appStateSnapshot,
+ files,
+ exportedElements,
+ exportingFrame,
+ projectName,
+ exportWithBackground,
+ exportDarkMode,
+ exportScale,
+ embedScene,
+ ]);
return (
<div className="ImageExportModal">
@@ -136,7 +159,8 @@ const ImageExportModal = ({
value={projectName}
style={{ width: "30ch" }}
disabled={
- typeof appProps.name !== "undefined" || appState.viewModeEnabled
+ typeof appProps.name !== "undefined" ||
+ appStateSnapshot.viewModeEnabled
}
onChange={(event) => {
setProjectName(event.target.value);
@@ -152,16 +176,16 @@ const ImageExportModal = ({
</div>
<div className="ImageExportModal__settings">
<h3>{t("imageExportDialog.header")}</h3>
- {someElementIsSelected && (
+ {hasSelection && (
<ExportSetting
label={t("imageExportDialog.label.onlySelected")}
name="exportOnlySelected"
>
<Switch
name="exportOnlySelected"
- checked={exportSelected}
+ checked={exportSelectionOnly}
onChange={(checked) => {
- setExportSelected(checked);
+ setExportSelectionOnly(checked);
}}
/>
</ExportSetting>
@@ -243,7 +267,9 @@ const ImageExportModal = ({
className="ImageExportModal__settings__buttons__button"
label={t("imageExportDialog.title.exportToPng")}
onClick={() =>
- onExportImage(EXPORT_IMAGE_TYPES.png, exportedElements)
+ onExportImage(EXPORT_IMAGE_TYPES.png, exportedElements, {
+ exportingFrame,
+ })
}
startIcon={downloadIcon}
>
@@ -253,7 +279,9 @@ const ImageExportModal = ({
className="ImageExportModal__settings__buttons__button"
label={t("imageExportDialog.title.exportToSvg")}
onClick={() =>
- onExportImage(EXPORT_IMAGE_TYPES.svg, exportedElements)
+ onExportImage(EXPORT_IMAGE_TYPES.svg, exportedElements, {
+ exportingFrame,
+ })
}
startIcon={downloadIcon}
>
@@ -264,7 +292,9 @@ const ImageExportModal = ({
className="ImageExportModal__settings__buttons__button"
label={t("imageExportDialog.title.copyPngToClipboard")}
onClick={() =>
- onExportImage(EXPORT_IMAGE_TYPES.clipboard, exportedElements)
+ onExportImage(EXPORT_IMAGE_TYPES.clipboard, exportedElements, {
+ exportingFrame,
+ })
}
startIcon={copyIcon}
>
@@ -325,15 +355,20 @@ export const ImageExportDialog = ({
onExportImage: AppClassProperties["onExportImage"];
onCloseRequest: () => void;
}) => {
- if (appState.openDialog !== "imageExport") {
- return null;
- }
+ // we need to take a snapshot so that the exported state can't be modified
+ // while the dialog is open
+ const [{ appStateSnapshot, elementsSnapshot }] = useState(() => {
+ return {
+ appStateSnapshot: cloneJSON(appState),
+ elementsSnapshot: cloneJSON(elements),
+ };
+ });
return (
<Dialog onCloseRequest={onCloseRequest} size="wide" title={false}>
<ImageExportModal
- elements={elements}
- appState={appState}
+ elementsSnapshot={elementsSnapshot}
+ appStateSnapshot={appStateSnapshot}
files={files}
actionManager={actionManager}
onExportImage={onExportImage}
diff --git a/src/components/LayerUI.tsx b/src/components/LayerUI.tsx
index 4d87d1eccd..8b909da236 100644
--- a/src/components/LayerUI.tsx
+++ b/src/components/LayerUI.tsx
@@ -161,7 +161,10 @@ const LayerUI = ({
};
const renderImageExportDialog = () => {
- if (!UIOptions.canvasActions.saveAsImage) {
+ if (
+ !UIOptions.canvasActions.saveAsImage ||
+ appState.openDialog !== "imageExport"
+ ) {
return null;
}
diff --git a/src/constants.ts b/src/constants.ts
index ffea01225d..fca1c0d29c 100644
--- a/src/constants.ts
+++ b/src/constants.ts
@@ -105,6 +105,7 @@ export const FONT_FAMILY = {
Virgil: 1,
Helvetica: 2,
Cascadia: 3,
+ Assistant: 4,
};
export const THEME = {
@@ -114,13 +115,18 @@ export const THEME = {
export const FRAME_STYLE = {
strokeColor: "#bbb" as ExcalidrawElement["strokeColor"],
- strokeWidth: 1 as ExcalidrawElement["strokeWidth"],
+ strokeWidth: 2 as ExcalidrawElement["strokeWidth"],
strokeStyle: "solid" as ExcalidrawElement["strokeStyle"],
fillStyle: "solid" as ExcalidrawElement["fillStyle"],
roughness: 0 as ExcalidrawElement["roughness"],
roundness: null as ExcalidrawElement["roundness"],
backgroundColor: "transparent" as ExcalidrawElement["backgroundColor"],
radius: 8,
+ nameOffsetY: 3,
+ nameColorLightTheme: "#999999",
+ nameColorDarkTheme: "#7a7a7a",
+ nameFontSize: 14,
+ nameLineHeight: 1.25,
};
export const WINDOWS_EMOJI_FALLBACK_FONT = "Segoe UI Emoji";
diff --git a/src/data/index.ts b/src/data/index.ts
index 29eedb2a7f..7554c1cbbb 100644
--- a/src/data/index.ts
+++ b/src/data/index.ts
@@ -3,11 +3,19 @@ import {
copyTextToSystemClipboard,
} from "../clipboard";
import { DEFAULT_EXPORT_PADDING, isFirefox, MIME_TYPES } from "../constants";
-import { NonDeletedExcalidrawElement } from "../element/types";
+import { getNonDeletedElements, isFrameElement } from "../element";
+import {
+ ExcalidrawElement,
+ ExcalidrawFrameElement,
+ NonDeletedExcalidrawElement,
+} from "../element/types";
import { t } from "../i18n";
+import { elementsOverlappingBBox } from "../packages/withinBounds";
+import { isSomeElementSelected, getSelectedElements } from "../scene";
import { exportToCanvas, exportToSvg } from "../scene/export";
import { ExportType } from "../scene/types";
import { AppState, BinaryFiles } from "../types";
+import { cloneJSON } from "../utils";
import { canvasToBlob } from "./blob";
import { fileSave, FileSystemHandle } from "./filesystem";
import { serializeAsJSON } from "./json";
@@ -15,9 +23,61 @@ import { serializeAsJSON } from "./json";
export { loadFromBlob } from "./blob";
export { loadFromJSON, saveAsJSON } from "./json";
+export type ExportedElements = readonly NonDeletedExcalidrawElement[] & {
+ _brand: "exportedElements";
+};
+
+export const prepareElementsForExport = (
+ elements: readonly ExcalidrawElement[],
+ { selectedElementIds }: Pick<AppState, "selectedElementIds">,
+ exportSelectionOnly: boolean,
+) => {
+ elements = getNonDeletedElements(elements);
+
+ const isExportingSelection =
+ exportSelectionOnly &&
+ isSomeElementSelected(elements, { selectedElementIds });
+
+ let exportingFrame: ExcalidrawFrameElement | null = null;
+ let exportedElements = isExportingSelection
+ ? getSelectedElements(
+ elements,
+ { selectedElementIds },
+ {
+ includeBoundTextElement: true,
+ },
+ )
+ : elements;
+
+ if (isExportingSelection) {
+ if (exportedElements.length === 1 && isFrameElement(exportedElements[0])) {
+ exportingFrame = exportedElements[0];
+ exportedElements = elementsOverlappingBBox({
+ elements,
+ bounds: exportingFrame,
+ type: "overlap",
+ });
+ } else if (exportedElements.length > 1) {
+ exportedElements = getSelectedElements(
+ elements,
+ { selectedElementIds },
+ {
+ includeBoundTextElement: true,
+ includeElementsInFrames: true,
+ },
+ );
+ }
+ }
+
+ return {
+ exportingFrame,
+ exportedElements: cloneJSON(exportedElements) as ExportedElements,
+ };
+};
+
export const exportCanvas = async (
type: Omit<ExportType, "backend">,
- elements: readonly NonDeletedExcalidrawElement[],
+ elements: ExportedElements,
appState: AppState,
files: BinaryFiles,
{
@@ -26,12 +86,14 @@ export const exportCanvas = async (
viewBackgroundColor,
name,
fileHandle = null,
+ exportingFrame = null,
}: {
exportBackground: boolean;
exportPadding?: number;
viewBackgroundColor: string;
name: string;
fileHandle?: FileSystemHandle | null;
+ exportingFrame: ExcalidrawFrameElement | null;
},
) => {
if (elements.length === 0) {
@@ -49,6 +111,7 @@ export const exportCanvas = async (
exportEmbedScene: appState.exportEmbedScene && type === "svg",
},
files,
+ { exportingFrame },
);
if (type === "svg") {
return await fileSave(
@@ -70,6 +133,7 @@ export const exportCanvas = async (
exportBackground,
viewBackgroundColor,
exportPadding,
+ exportingFrame,
});
if (type === "png") {
diff --git a/src/data/library.ts b/src/data/library.ts
index 381caed113..7b936efc1c 100644
--- a/src/data/library.ts
+++ b/src/data/library.ts
@@ -23,6 +23,7 @@ import {
LIBRARY_SIDEBAR_TAB,
} from "../constants";
import { libraryItemSvgsCache } from "../hooks/useLibraryItemSvg";
+import { cloneJSON } from "../utils";
export const libraryItemsAtom = atom<{
status: "loading" | "loaded";
@@ -31,7 +32,7 @@ export const libraryItemsAtom = atom<{
}>({ status: "loaded", isInitialized: true, libraryItems: [] });
const cloneLibraryItems = (libraryItems: LibraryItems): LibraryItems =>
- JSON.parse(JSON.stringify(libraryItems));
+ cloneJSON(libraryItems);
/**
* checks if library item does not exist already in current library
diff --git a/src/data/resave.ts b/src/data/resave.ts
index ede6f424ac..0998fd3c7b 100644
--- a/src/data/resave.ts
+++ b/src/data/resave.ts
@@ -1,7 +1,6 @@
import { ExcalidrawElement } from "../element/types";
import { AppState, BinaryFiles } from "../types";
-import { exportCanvas } from ".";
-import { getNonDeletedElements } from "../element";
+import { exportCanvas, prepareElementsForExport } from ".";
import { getFileHandleType, isImageFileHandleType } from "./blob";
export const resaveAsImageWithScene = async (
@@ -23,18 +22,19 @@ export const resaveAsImageWithScene = async (
exportEmbedScene: true,
};
- await exportCanvas(
- fileHandleType,
- getNonDeletedElements(elements),
+ const { exportedElements, exportingFrame } = prepareElementsForExport(
+ elements,
appState,
- files,
- {
- exportBackground,
- viewBackgroundColor,
- name,
- fileHandle,
- },
+ false,
);
+ await exportCanvas(fileHandleType, exportedElements, appState, files, {
+ exportBackground,
+ viewBackgroundColor,
+ name,
+ fileHandle,
+ exportingFrame,
+ });
+
return { fileHandle };
};
diff --git a/src/data/transform.ts b/src/data/transform.ts
index 1020826173..954ab5f7d6 100644
--- a/src/data/transform.ts
+++ b/src/data/transform.ts
@@ -40,7 +40,7 @@ import {
VerticalAlign,
} from "../element/types";
import { MarkOptional } from "../utility-types";
-import { assertNever, getFontString } from "../utils";
+import { assertNever, cloneJSON, getFontString } from "../utils";
import { getSizeFromPoints } from "../points";
import { randomId } from "../random";
@@ -368,7 +368,8 @@ const bindLinearElementToElement = (
// Update start/end points by 0.5 so bindings don't overlap with start/end bound element coordinates.
const endPointIndex = linearElement.points.length - 1;
const delta = 0.5;
- const newPoints = JSON.parse(JSON.stringify(linearElement.points));
+
+ const newPoints = cloneJSON(linearElement.points) as [number, number][];
// left to right so shift the arrow towards right
if (
linearElement.points[endPointIndex][0] >
@@ -439,9 +440,7 @@ export const convertToExcalidrawElements = (
if (!elementsSkeleton) {
return [];
}
- const elements: ExcalidrawElementSkeleton[] = JSON.parse(
- JSON.stringify(elementsSkeleton),
- );
+ const elements = cloneJSON(elementsSkeleton);
const elementStore = new ElementStore();
const elementsWithIds = new Map<string, ExcalidrawElementSkeleton>();
const oldToNewElementIdMap = new Map<string, string>();
diff --git a/src/element/embeddable.ts b/src/element/embeddable.ts
index 29aac1bcdb..c0ade4fe27 100644
--- a/src/element/embeddable.ts
+++ b/src/element/embeddable.ts
@@ -200,7 +200,7 @@ export const getEmbedLink = (link: string | null | undefined): EmbeddedLink => {
return { link, aspectRatio, type };
};
-export const isEmbeddableOrFrameLabel = (
+export const isEmbeddableOrLabel = (
element: NonDeletedExcalidrawElement,
): Boolean => {
if (isEmbeddableElement(element)) {
diff --git a/src/element/typeChecks.ts b/src/element/typeChecks.ts
index a9c568a409..6d581a490d 100644
--- a/src/element/typeChecks.ts
+++ b/src/element/typeChecks.ts
@@ -1,6 +1,7 @@
import { ROUNDNESS } from "../constants";
import { AppState } from "../types";
import { MarkNonNullable } from "../utility-types";
+import { assertNever } from "../utils";
import {
ExcalidrawElement,
ExcalidrawTextElement,
@@ -140,17 +141,32 @@ export const isTextBindableContainer = (
);
};
-export const isExcalidrawElement = (element: any): boolean => {
- return (
- element?.type === "text" ||
- element?.type === "diamond" ||
- element?.type === "rectangle" ||
- element?.type === "embeddable" ||
- element?.type === "ellipse" ||
- element?.type === "arrow" ||
- element?.type === "freedraw" ||
- element?.type === "line"
- );
+export const isExcalidrawElement = (
+ element: any,
+): element is ExcalidrawElement => {
+ const type: ExcalidrawElement["type"] | undefined = element?.type;
+ if (!type) {
+ return false;
+ }
+ switch (type) {
+ case "text":
+ case "diamond":
+ case "rectangle":
+ case "embeddable":
+ case "ellipse":
+ case "arrow":
+ case "freedraw":
+ case "line":
+ case "frame":
+ case "image":
+ case "selection": {
+ return true;
+ }
+ default: {
+ assertNever(type, null);
+ return false;
+ }
+ }
};
export const hasBoundTextElement = (
diff --git a/src/frame.ts b/src/frame.ts
index 0e7bc93a00..eda384f654 100644
--- a/src/frame.ts
+++ b/src/frame.ts
@@ -201,24 +201,52 @@ export const groupByFrames = (elements: readonly ExcalidrawElement[]) => {
for (const element of elements) {
const frameId = isFrameElement(element) ? element.id : element.frameId;
if (frameId && !frameElementsMap.has(frameId)) {
- frameElementsMap.set(frameId, getFrameElements(elements, frameId));
+ frameElementsMap.set(frameId, getFrameChildren(elements, frameId));
}
}
return frameElementsMap;
};
-export const getFrameElements = (
+export const getFrameChildren = (
allElements: ExcalidrawElementsIncludingDeleted,
frameId: string,
) => allElements.filter((element) => element.frameId === frameId);
+export const getFrameElements = (
+ allElements: ExcalidrawElementsIncludingDeleted,
+): ExcalidrawFrameElement[] => {
+ return allElements.filter((element) =>
+ isFrameElement(element),
+ ) as ExcalidrawFrameElement[];
+};
+
+/**
+ * Returns ExcalidrawFrameElements and non-frame-children elements.
+ *
+ * Considers children as root elements if they point to a frame parent
+ * non-existing in the elements set.
+ *
+ * Considers non-frame bound elements (container or arrow labels) as root.
+ */
+export const getRootElements = (
+ allElements: ExcalidrawElementsIncludingDeleted,
+) => {
+ const frameElements = arrayToMap(getFrameElements(allElements));
+ return allElements.filter(
+ (element) =>
+ frameElements.has(element.id) ||
+ !element.frameId ||
+ !frameElements.has(element.frameId),
+ );
+};
+
export const getElementsInResizingFrame = (
allElements: ExcalidrawElementsIncludingDeleted,
frame: ExcalidrawFrameElement,
appState: AppState,
): ExcalidrawElement[] => {
- const prevElementsInFrame = getFrameElements(allElements, frame.id);
+ const prevElementsInFrame = getFrameChildren(allElements, frame.id);
const nextElementsInFrame = new Set<ExcalidrawElement>(prevElementsInFrame);
const elementsCompletelyInFrame = new Set([
@@ -449,7 +477,7 @@ export const removeAllElementsFromFrame = (
frame: ExcalidrawFrameElement,
appState: AppState,
) => {
- const elementsInFrame = getFrameElements(allElements, frame.id);
+ const elementsInFrame = getFrameChildren(allElements, frame.id);
return removeElementsFromFrame(allElements, elementsInFrame, appState);
};
diff --git a/src/packages/utils.ts b/src/packages/utils.ts
index 2d896ed3cd..b23cab3263 100644
--- a/src/packages/utils.ts
+++ b/src/packages/utils.ts
@@ -4,7 +4,11 @@ import {
} from "../scene/export";
import { getDefaultAppState } from "../appState";
import { AppState, BinaryFiles } from "../types";
-import { ExcalidrawElement, NonDeleted } from "../element/types";
+import {
+ ExcalidrawElement,
+ ExcalidrawFrameElement,
+ NonDeleted,
+} from "../element/types";
import { restore } from "../data/restore";
import { MIME_TYPES } from "../constants";
import { encodePngMetadata } from "../data/image";
@@ -14,24 +18,6 @@ import {
copyTextToSystemClipboard,
copyToClipboard,
} from "../clipboard";
-import Scene from "../scene/Scene";
-import { duplicateElements } from "../element/newElement";
-
-// getContainerElement and getBoundTextElement and potentially other helpers
-// depend on `Scene` which will not be available when these pure utils are
-// called outside initialized Excalidraw editor instance or even if called
-// from inside Excalidraw if the elements were never cached by Scene (e.g.
-// for library elements).
-//
-// As such, before passing the elements down, we need to initialize a custom
-// Scene instance and assign them to it.
-//
-// FIXME This is a super hacky workaround and we'll need to rewrite this soon.
-const passElementsSafely = (elements: readonly ExcalidrawElement[]) => {
- const scene = new Scene();
- scene.replaceAllElements(duplicateElements(elements));
- return scene.getNonDeletedElements();
-};
export { MIME_TYPES };
@@ -40,6 +26,7 @@ type ExportOpts = {
appState?: Partial<Omit<AppState, "offsetTop" | "offsetLeft">>;
files: BinaryFiles | null;
maxWidthOrHeight?: number;
+ exportingFrame?: ExcalidrawFrameElement | null;
getDimensions?: (
width: number,
height: number,
@@ -53,6 +40,7 @@ export const exportToCanvas = ({
maxWidthOrHeight,
getDimensions,
exportPadding,
+ exportingFrame,
}: ExportOpts & {
exportPadding?: number;
}) => {
@@ -63,10 +51,10 @@ export const exportToCanvas = ({
);
const { exportBackground, viewBackgroundColor } = restoredAppState;
return _exportToCanvas(
- passElementsSafely(restoredElements),
+ restoredElements,
{ ...restoredAppState, offsetTop: 0, offsetLeft: 0, width: 0, height: 0 },
files || {},
- { exportBackground, exportPadding, viewBackgroundColor },
+ { exportBackground, exportPadding, viewBackgroundColor, exportingFrame },
(width: number, height: number) => {
const canvas = document.createElement("canvas");
@@ -135,10 +123,8 @@ export const exportToBlob = async (
};
}
- const canvas = await exportToCanvas({
- ...opts,
- elements: passElementsSafely(opts.elements),
- });
+ const canvas = await exportToCanvas(opts);
+
quality = quality ? quality : /image\/jpe?g/.test(mimeType) ? 0.92 : 0.8;
return new Promise((resolve, reject) => {
@@ -179,6 +165,7 @@ export const exportToSvg = async ({
files = {},
exportPadding,
renderEmbeddables,
+ exportingFrame,
}: Omit<ExportOpts, "getDimensions"> & {
exportPadding?: number;
renderEmbeddables?: boolean;
@@ -194,20 +181,10 @@ export const exportToSvg = async ({
exportPadding,
};
- return _exportToSvg(
- passElementsSafely(restoredElements),
- exportAppState,
- files,
- {
- renderEmbeddables,
- // NOTE as long as we're using the Scene hack, we need to ensure
- // we pass the original, uncloned elements when serializing
- // so that we keep ids stable. Hence adding the serializeAsJSON helper
- // support into the downstream exportToSvg function.
- serializeAsJSON: () =>
- serializeAsJSON(restoredElements, exportAppState, files || {}, "local"),
- },
- );
+ return _exportToSvg(restoredElements, exportAppState, files, {
+ exportingFrame,
+ renderEmbeddables,
+ });
};
export const exportToClipboard = async (
diff --git a/src/packages/withinBounds.ts b/src/packages/withinBounds.ts
index 75ea10b721..417ec36d7a 100644
--- a/src/packages/withinBounds.ts
+++ b/src/packages/withinBounds.ts
@@ -6,13 +6,14 @@ import type {
} from "../element/types";
import {
isArrowElement,
+ isExcalidrawElement,
isFreeDrawElement,
isLinearElement,
isTextElement,
} from "../element/typeChecks";
import { isValueInRange, rotatePoint } from "../math";
import type { Point } from "../types";
-import { Bounds } from "../element/bounds";
+import { Bounds, getElementBounds } from "../element/bounds";
type Element = NonDeletedExcalidrawElement;
type Elements = readonly NonDeletedExcalidrawElement[];
@@ -146,7 +147,7 @@ export const elementsOverlappingBBox = ({
errorMargin = 0,
}: {
elements: Elements;
- bounds: Bounds;
+ bounds: Bounds | ExcalidrawElement;
/** safety offset. Defaults to 0. */
errorMargin?: number;
/**
@@ -156,6 +157,9 @@ export const elementsOverlappingBBox = ({
**/
type: "overlap" | "contain" | "inside";
}) => {
+ if (isExcalidrawElement(bounds)) {
+ bounds = getElementBounds(bounds);
+ }
const adjustedBBox: Bounds = [
bounds[0] - errorMargin,
bounds[1] - errorMargin,
diff --git a/src/renderer/renderElement.ts b/src/renderer/renderElement.ts
index 9b040e9a52..d346fa6ab6 100644
--- a/src/renderer/renderElement.ts
+++ b/src/renderer/renderElement.ts
@@ -20,7 +20,13 @@ import type { Drawable } from "roughjs/bin/core";
import type { RoughSVG } from "roughjs/bin/svg";
import { StaticCanvasRenderConfig } from "../scene/types";
-import { distance, getFontString, getFontFamilyString, isRTL } from "../utils";
+import {
+ distance,
+ getFontString,
+ getFontFamilyString,
+ isRTL,
+ isTestEnv,
+} from "../utils";
import { getCornerRadius, isPathALoop, isRightAngle } from "../math";
import rough from "roughjs/bin/rough";
import {
@@ -589,11 +595,7 @@ export const renderElement = (
) => {
switch (element.type) {
case "frame": {
- if (
- !renderConfig.isExporting &&
- appState.frameRendering.enabled &&
- appState.frameRendering.outline
- ) {
+ if (appState.frameRendering.enabled && appState.frameRendering.outline) {
context.save();
context.translate(
element.x + appState.scrollX,
@@ -601,7 +603,7 @@ export const renderElement = (
);
context.fillStyle = "rgba(0, 0, 200, 0.04)";
- context.lineWidth = 2 / appState.zoom.value;
+ context.lineWidth = FRAME_STYLE.strokeWidth / appState.zoom.value;
context.strokeStyle = FRAME_STYLE.strokeColor;
if (FRAME_STYLE.radius && context.roundRect) {
@@ -841,10 +843,13 @@ const maybeWrapNodesInFrameClipPath = (
element: NonDeletedExcalidrawElement,
root: SVGElement,
nodes: SVGElement[],
- exportedFrameId?: string | null,
+ frameRendering: AppState["frameRendering"],
) => {
+ if (!frameRendering.enabled || !frameRendering.clip) {
+ return null;
+ }
const frame = getContainingFrame(element);
- if (frame && frame.id === exportedFrameId) {
+ if (frame) {
const g = root.ownerDocument!.createElementNS(SVG_NS, "g");
g.setAttributeNS(SVG_NS, "clip-path", `url(#${frame.id})`);
nodes.forEach((node) => g.appendChild(node));
@@ -861,9 +866,11 @@ export const renderElementToSvg = (
files: BinaryFiles,
offsetX: number,
offsetY: number,
- exportWithDarkMode?: boolean,
- exportingFrameId?: string | null,
- renderEmbeddables?: boolean,
+ renderConfig: {
+ exportWithDarkMode: boolean;
+ renderEmbeddables: boolean;
+ frameRendering: AppState["frameRendering"];
+ },
) => {
const offset = { x: offsetX, y: offsetY };
const [x1, y1, x2, y2] = getElementAbsoluteCoords(element);
@@ -897,6 +904,13 @@ export const renderElementToSvg = (
root = anchorTag;
}
+ const addToRoot = (node: SVGElement, element: ExcalidrawElement) => {
+ if (isTestEnv()) {
+ node.setAttribute("data-id", element.id);
+ }
+ root.appendChild(node);
+ };
+
const opacity =
((getContainingFrame(element)?.opacity ?? 100) * element.opacity) / 10000;
@@ -931,10 +945,10 @@ export const renderElementToSvg = (
element,
root,
[node],
- exportingFrameId,
+ renderConfig.frameRendering,
);
- g ? root.appendChild(g) : root.appendChild(node);
+ addToRoot(g || node, element);
break;
}
case "embeddable": {
@@ -957,7 +971,7 @@ export const renderElementToSvg = (
offsetY || 0
}) rotate(${degree} ${cx} ${cy})`,
);
- root.appendChild(node);
+ addToRoot(node, element);
const label: ExcalidrawElement =
createPlaceholderEmbeddableLabel(element);
@@ -968,9 +982,7 @@ export const renderElementToSvg = (
files,
label.x + offset.x - element.x,
label.y + offset.y - element.y,
- exportWithDarkMode,
- exportingFrameId,
- renderEmbeddables,
+ renderConfig,
);
// render embeddable element + iframe
@@ -999,7 +1011,10 @@ export const renderElementToSvg = (
// if rendering embeddables explicitly disabled or
// embedding documents via srcdoc (which doesn't seem to work for SVGs)
// replace with a link instead
- if (renderEmbeddables === false || embedLink?.type === "document") {
+ if (
+ renderConfig.renderEmbeddables === false ||
+ embedLink?.type === "document"
+ ) {
const anchorTag = svgRoot.ownerDocument!.createElementNS(SVG_NS, "a");
anchorTag.setAttribute("href", normalizeLink(element.link || ""));
anchorTag.setAttribute("target", "_blank");
@@ -1033,8 +1048,7 @@ export const renderElementToSvg = (
embeddableNode.appendChild(foreignObject);
}
-
- root.appendChild(embeddableNode);
+ addToRoot(embeddableNode, element);
break;
}
case "line":
@@ -1119,12 +1133,13 @@ export const renderElementToSvg = (
element,
root,
[group, maskPath],
- exportingFrameId,
+ renderConfig.frameRendering,
);
if (g) {
+ addToRoot(g, element);
root.appendChild(g);
} else {
- root.appendChild(group);
+ addToRoot(group, element);
root.append(maskPath);
}
break;
@@ -1158,10 +1173,10 @@ export const renderElementToSvg = (
element,
root,
[node],
- exportingFrameId,
+ renderConfig.frameRendering,
);
- g ? root.appendChild(g) : root.appendChild(node);
+ addToRoot(g || node, element);
break;
}
case "image": {
@@ -1191,7 +1206,10 @@ export const renderElementToSvg = (
use.setAttribute("href", `#${symbolId}`);
// in dark theme, revert the image color filter
- if (exportWithDarkMode && fileData.mimeType !== MIME_TYPES.svg) {
+ if (
+ renderConfig.exportWithDarkMode &&
+ fileData.mimeType !== MIME_TYPES.svg
+ ) {
use.setAttribute("filter", IMAGE_INVERT_FILTER);
}
@@ -1227,14 +1245,39 @@ export const renderElementToSvg = (
element,
root,
[g],
- exportingFrameId,
+ renderConfig.frameRendering,
);
- clipG ? root.appendChild(clipG) : root.appendChild(g);
+ addToRoot(clipG || g, element);
}
break;
}
// frames are not rendered and only acts as a container
case "frame": {
+ if (
+ renderConfig.frameRendering.enabled &&
+ renderConfig.frameRendering.outline
+ ) {
+ const rect = document.createElementNS(SVG_NS, "rect");
+
+ rect.setAttribute(
+ "transform",
+ `translate(${offsetX || 0} ${
+ offsetY || 0
+ }) rotate(${degree} ${cx} ${cy})`,
+ );
+
+ rect.setAttribute("width", `${element.width}px`);
+ rect.setAttribute("height", `${element.height}px`);
+ // Rounded corners
+ rect.setAttribute("rx", FRAME_STYLE.radius.toString());
+ rect.setAttribute("ry", FRAME_STYLE.radius.toString());
+
+ rect.setAttribute("fill", "none");
+ rect.setAttribute("stroke", FRAME_STYLE.strokeColor);
+ rect.setAttribute("stroke-width", FRAME_STYLE.strokeWidth.toString());
+
+ addToRoot(rect, element);
+ }
break;
}
default: {
@@ -1288,10 +1331,10 @@ export const renderElementToSvg = (
element,
root,
[node],
- exportingFrameId,
+ renderConfig.frameRendering,
);
- g ? root.appendChild(g) : root.appendChild(node);
+ addToRoot(g || node, element);
} else {
// @ts-ignore
throw new Error(`Unimplemented type ${element.type}`);
diff --git a/src/renderer/renderScene.ts b/src/renderer/renderScene.ts
index 6395ed0e7a..2a183777bb 100644
--- a/src/renderer/renderScene.ts
+++ b/src/renderer/renderScene.ts
@@ -60,7 +60,7 @@ import {
TransformHandles,
TransformHandleType,
} from "../element/transformHandles";
-import { throttleRAF, isOnlyExportingSingleFrame } from "../utils";
+import { throttleRAF } from "../utils";
import { UserIdleState } from "../types";
import { FRAME_STYLE, THEME_FILTER } from "../constants";
import {
@@ -74,7 +74,7 @@ import {
isLinearElement,
} from "../element/typeChecks";
import {
- isEmbeddableOrFrameLabel,
+ isEmbeddableOrLabel,
createPlaceholderEmbeddableLabel,
} from "../element/embeddable";
import {
@@ -369,7 +369,7 @@ const frameClip = (
) => {
context.translate(frame.x + appState.scrollX, frame.y + appState.scrollY);
context.beginPath();
- if (context.roundRect && !renderConfig.isExporting) {
+ if (context.roundRect) {
context.roundRect(
0,
0,
@@ -963,20 +963,15 @@ const _renderStaticScene = ({
// Paint visible elements
visibleElements
- .filter((el) => !isEmbeddableOrFrameLabel(el))
+ .filter((el) => !isEmbeddableOrLabel(el))
.forEach((element) => {
try {
- // - when exporting the whole canvas, we DO NOT apply clipping
- // - when we are exporting a particular frame, apply clipping
- // if the containing frame is not selected, apply clipping
const frameId = element.frameId || appState.frameToHighlight?.id;
if (
frameId &&
- ((renderConfig.isExporting && isOnlyExportingSingleFrame(elements)) ||
- (!renderConfig.isExporting &&
- appState.frameRendering.enabled &&
- appState.frameRendering.clip))
+ appState.frameRendering.enabled &&
+ appState.frameRendering.clip
) {
context.save();
@@ -1001,7 +996,7 @@ const _renderStaticScene = ({
// render embeddables on top
visibleElements
- .filter((el) => isEmbeddableOrFrameLabel(el))
+ .filter((el) => isEmbeddableOrLabel(el))
.forEach((element) => {
try {
const render = () => {
@@ -1027,10 +1022,8 @@ const _renderStaticScene = ({
if (
frameId &&
- ((renderConfig.isExporting && isOnlyExportingSingleFrame(elements)) ||
- (!renderConfig.isExporting &&
- appState.frameRendering.enabled &&
- appState.frameRendering.clip))
+ appState.frameRendering.enabled &&
+ appState.frameRendering.clip
) {
context.save();
@@ -1298,7 +1291,7 @@ const renderFrameHighlight = (
const height = y2 - y1;
context.strokeStyle = "rgb(0,118,255)";
- context.lineWidth = (FRAME_STYLE.strokeWidth * 2) / appState.zoom.value;
+ context.lineWidth = FRAME_STYLE.strokeWidth / appState.zoom.value;
context.save();
context.translate(appState.scrollX, appState.scrollY);
@@ -1454,24 +1447,29 @@ export const renderSceneToSvg = (
{
offsetX = 0,
offsetY = 0,
- exportWithDarkMode = false,
- exportingFrameId = null,
+ exportWithDarkMode,
renderEmbeddables,
+ frameRendering,
}: {
offsetX?: number;
offsetY?: number;
- exportWithDarkMode?: boolean;
- exportingFrameId?: string | null;
- renderEmbeddables?: boolean;
- } = {},
+ exportWithDarkMode: boolean;
+ renderEmbeddables: boolean;
+ frameRendering: AppState["frameRendering"];
+ },
) => {
if (!svgRoot) {
return;
}
+ const renderConfig = {
+ exportWithDarkMode,
+ renderEmbeddables,
+ frameRendering,
+ };
// render elements
elements
- .filter((el) => !isEmbeddableOrFrameLabel(el))
+ .filter((el) => !isEmbeddableOrLabel(el))
.forEach((element) => {
if (!element.isDeleted) {
try {
@@ -1482,9 +1480,7 @@ export const renderSceneToSvg = (
files,
element.x + offsetX,
element.y + offsetY,
- exportWithDarkMode,
- exportingFrameId,
- renderEmbeddables,
+ renderConfig,
);
} catch (error: any) {
console.error(error);
@@ -1505,9 +1501,7 @@ export const renderSceneToSvg = (
files,
element.x + offsetX,
element.y + offsetY,
- exportWithDarkMode,
- exportingFrameId,
- renderEmbeddables,
+ renderConfig,
);
} catch (error: any) {
console.error(error);
diff --git a/src/scene/Scene.ts b/src/scene/Scene.ts
index e64da78fcd..9c1b3d3298 100644
--- a/src/scene/Scene.ts
+++ b/src/scene/Scene.ts
@@ -66,16 +66,29 @@ class Scene {
private static sceneMapByElement = new WeakMap<ExcalidrawElement, Scene>();
private static sceneMapById = new Map<string, Scene>();
- static mapElementToScene(elementKey: ElementKey, scene: Scene) {
+ static mapElementToScene(
+ elementKey: ElementKey,
+ scene: Scene,
+ /**
+ * needed because of frame exporting hack.
+ * elementId:Scene mapping will be removed completely, soon.
+ */
+ mapElementIds = true,
+ ) {
if (isIdKey(elementKey)) {
+ if (!mapElementIds) {
+ return;
+ }
// for cases where we don't have access to the element object
// (e.g. restore serialized appState with id references)
this.sceneMapById.set(elementKey, scene);
} else {
this.sceneMapByElement.set(elementKey, scene);
- // if mapping element objects, also cache the id string when later
- // looking up by id alone
- this.sceneMapById.set(elementKey.id, scene);
+ if (!mapElementIds) {
+ // if mapping element objects, also cache the id string when later
+ // looking up by id alone
+ this.sceneMapById.set(elementKey.id, scene);
+ }
}
}
@@ -217,7 +230,10 @@ class Scene {
return didChange;
}
- replaceAllElements(nextElements: readonly ExcalidrawElement[]) {
+ replaceAllElements(
+ nextElements: readonly ExcalidrawElement[],
+ mapElementIds = true,
+ ) {
this.elements = nextElements;
const nextFrames: ExcalidrawFrameElement[] = [];
this.elementsMap.clear();
diff --git a/src/scene/export.ts b/src/scene/export.ts
index 3aa0cec6f8..694c162da2 100644
--- a/src/scene/export.ts
+++ b/src/scene/export.ts
@@ -1,24 +1,144 @@
import rough from "roughjs/bin/rough";
-import { NonDeletedExcalidrawElement } from "../element/types";
+import {
+ ExcalidrawElement,
+ ExcalidrawFrameElement,
+ ExcalidrawTextElement,
+ NonDeletedExcalidrawElement,
+} from "../element/types";
import {
Bounds,
getCommonBounds,
getElementAbsoluteCoords,
} from "../element/bounds";
import { renderSceneToSvg, renderStaticScene } from "../renderer/renderScene";
-import { distance, isOnlyExportingSingleFrame } from "../utils";
+import { distance, getFontString } from "../utils";
import { AppState, BinaryFiles } from "../types";
-import { DEFAULT_EXPORT_PADDING, SVG_NS, THEME_FILTER } from "../constants";
+import {
+ DEFAULT_EXPORT_PADDING,
+ FRAME_STYLE,
+ SVG_NS,
+ THEME_FILTER,
+} from "../constants";
import { getDefaultAppState } from "../appState";
import { serializeAsJSON } from "../data/json";
import {
getInitializedImageElements,
updateImageCache,
} from "../element/image";
+import { elementsOverlappingBBox } from "../packages/withinBounds";
+import { getFrameElements, getRootElements } from "../frame";
+import { isFrameElement, newTextElement } from "../element";
+import { Mutable } from "../utility-types";
+import { newElementWith } from "../element/mutateElement";
import Scene from "./Scene";
const SVG_EXPORT_TAG = `<!-- svg-source:excalidraw -->`;
+// getContainerElement and getBoundTextElement and potentially other helpers
+// depend on `Scene` which will not be available when these pure utils are
+// called outside initialized Excalidraw editor instance or even if called
+// from inside Excalidraw if the elements were never cached by Scene (e.g.
+// for library elements).
+//
+// As such, before passing the elements down, we need to initialize a custom
+// Scene instance and assign them to it.
+//
+// FIXME This is a super hacky workaround and we'll need to rewrite this soon.
+const __createSceneForElementsHack__ = (
+ elements: readonly ExcalidrawElement[],
+) => {
+ const scene = new Scene();
+ // we can't duplicate elements to regenerate ids because we need the
+ // orig ids when embedding. So we do another hack of not mapping element
+ // ids to Scene instances so that we don't override the editor elements
+ // mapping
+ scene.replaceAllElements(elements, false);
+ return scene;
+};
+
+const truncateText = (element: ExcalidrawTextElement, maxWidth: number) => {
+ if (element.width <= maxWidth) {
+ return element;
+ }
+ const canvas = document.createElement("canvas");
+ const ctx = canvas.getContext("2d")!;
+ ctx.font = getFontString({
+ fontFamily: element.fontFamily,
+ fontSize: element.fontSize,
+ });
+
+ let text = element.text;
+
+ const metrics = ctx.measureText(text);
+
+ if (metrics.width > maxWidth) {
+ // we iterate from the right, removing characters one by one instead
+ // of bulding the string up. This assumes that it's more likely
+ // your frame names will overflow by not that many characters
+ // (if ever), so it sohuld be faster this way.
+ for (let i = text.length; i > 0; i--) {
+ const newText = `${text.slice(0, i)}...`;
+ if (ctx.measureText(newText).width <= maxWidth) {
+ text = newText;
+ break;
+ }
+ }
+ }
+ return newElementWith(element, { text, width: maxWidth });
+};
+
+/**
+ * When exporting frames, we need to render frame labels which are currently
+ * being rendered in DOM when editing. Adding the labels as regular text
+ * elements seems like a simple hack. In the future we'll want to move to
+ * proper canvas rendering, even within editor (instead of DOM).
+ */
+const addFrameLabelsAsTextElements = (
+ elements: readonly NonDeletedExcalidrawElement[],
+ opts: Pick<AppState, "exportWithDarkMode">,
+) => {
+ const nextElements: NonDeletedExcalidrawElement[] = [];
+ let frameIdx = 0;
+ for (const element of elements) {
+ if (isFrameElement(element)) {
+ frameIdx++;
+ let textElement: Mutable<ExcalidrawTextElement> = newTextElement({
+ x: element.x,
+ y: element.y - FRAME_STYLE.nameOffsetY,
+ fontFamily: 4,
+ fontSize: FRAME_STYLE.nameFontSize,
+ lineHeight:
+ FRAME_STYLE.nameLineHeight as ExcalidrawTextElement["lineHeight"],
+ strokeColor: opts.exportWithDarkMode
+ ? FRAME_STYLE.nameColorDarkTheme
+ : FRAME_STYLE.nameColorLightTheme,
+ text: element.name || `Frame ${frameIdx}`,
+ });
+ textElement.y -= textElement.height;
+
+ textElement = truncateText(textElement, element.width);
+
+ nextElements.push(textElement);
+ }
+ nextElements.push(element);
+ }
+
+ return nextElements;
+};
+
+const getFrameRenderingConfig = (
+ exportingFrame: ExcalidrawFrameElement | null,
+ frameRendering: AppState["frameRendering"] | null,
+): AppState["frameRendering"] => {
+ frameRendering = frameRendering || getDefaultAppState().frameRendering;
+ return {
+ enabled: exportingFrame ? true : frameRendering.enabled,
+ outline: exportingFrame ? false : frameRendering.outline,
+ name: exportingFrame ? false : frameRendering.name,
+ clip: exportingFrame ? true : frameRendering.clip,
+ };
+};
+
export const exportToCanvas = async (
elements: readonly NonDeletedExcalidrawElement[],
appState: AppState,
@@ -27,10 +147,12 @@ export const exportToCanvas = async (
exportBackground,
exportPadding = DEFAULT_EXPORT_PADDING,
viewBackgroundColor,
+ exportingFrame,
}: {
exportBackground: boolean;
exportPadding?: number;
viewBackgroundColor: string;
+ exportingFrame?: ExcalidrawFrameElement | null;
},
createCanvas: (
width: number,
@@ -42,7 +164,26 @@ export const exportToCanvas = async (
return { canvas, scale: appState.exportScale };
},
) => {
- const [minX, minY, width, height] = getCanvasSize(elements, exportPadding);
+ const tempScene = __createSceneForElementsHack__(elements);
+ elements = tempScene.getNonDeletedElements();
+
+ let nextElements: ExcalidrawElement[];
+
+ if (exportingFrame) {
+ exportPadding = 0;
+ nextElements = elementsOverlappingBBox({
+ elements,
+ bounds: exportingFrame,
+ type: "overlap",
+ });
+ } else {
+ nextElements = addFrameLabelsAsTextElements(elements, appState);
+ }
+
+ const [minX, minY, width, height] = getCanvasSize(
+ exportingFrame ? [exportingFrame] : getRootElements(nextElements),
+ exportPadding,
+ );
const { canvas, scale = 1 } = createCanvas(width, height);
@@ -50,25 +191,27 @@ export const exportToCanvas = async (
const { imageCache } = await updateImageCache({
imageCache: new Map(),
- fileIds: getInitializedImageElements(elements).map(
+ fileIds: getInitializedImageElements(nextElements).map(
(element) => element.fileId,
),
files,
});
- const onlyExportingSingleFrame = isOnlyExportingSingleFrame(elements);
-
renderStaticScene({
canvas,
rc: rough.canvas(canvas),
- elements,
- visibleElements: elements,
+ elements: nextElements,
+ visibleElements: nextElements,
scale,
appState: {
...appState,
+ frameRendering: getFrameRenderingConfig(
+ exportingFrame ?? null,
+ appState.frameRendering ?? null,
+ ),
viewBackgroundColor: exportBackground ? viewBackgroundColor : null,
- scrollX: -minX + (onlyExportingSingleFrame ? 0 : exportPadding),
- scrollY: -minY + (onlyExportingSingleFrame ? 0 : exportPadding),
+ scrollX: -minX + exportPadding,
+ scrollY: -minY + exportPadding,
zoom: defaultAppState.zoom,
shouldCacheIgnoreZoom: false,
theme: appState.exportWithDarkMode ? "dark" : "light",
@@ -80,6 +223,8 @@ export const exportToCanvas = async (
},
});
+ tempScene.destroy();
+
return canvas;
};
@@ -92,35 +237,65 @@ export const exportToSvg = async (
viewBackgroundColor: string;
exportWithDarkMode?: boolean;
exportEmbedScene?: boolean;
- renderFrame?: boolean;
+ frameRendering?: AppState["frameRendering"];
},
files: BinaryFiles | null,
opts?: {
- serializeAsJSON?: () => string;
renderEmbeddables?: boolean;
+ exportingFrame?: ExcalidrawFrameElement | null;
},
): Promise<SVGSVGElement> => {
- const {
+ const tempScene = __createSceneForElementsHack__(elements);
+ elements = tempScene.getNonDeletedElements();
+
+ let {
exportPadding = DEFAULT_EXPORT_PADDING,
viewBackgroundColor,
exportScale = 1,
exportEmbedScene,
} = appState;
+
+ const { exportingFrame = null } = opts || {};
+
+ let nextElements: ExcalidrawElement[] = [];
+
+ if (exportingFrame) {
+ exportPadding = 0;
+ nextElements = elementsOverlappingBBox({
+ elements,
+ bounds: exportingFrame,
+ type: "overlap",
+ });
+ } else {
+ nextElements = addFrameLabelsAsTextElements(elements, {
+ exportWithDarkMode: appState.exportWithDarkMode ?? false,
+ });
+ }
+
let metadata = "";
+
+ // we need to serialize the "original" elements before we put them through
+ // the tempScene hack which duplicates and regenerates ids
if (exportEmbedScene) {
try {
metadata = await (
await import(/* webpackChunkName: "image" */ "../../src/data/image")
).encodeSvgMetadata({
- text: opts?.serializeAsJSON
- ? opts?.serializeAsJSON?.()
- : serializeAsJSON(elements, appState, files || {}, "local"),
+ // when embedding scene, we want to embed the origionally supplied
+ // elements which don't contain the temp frame labels.
+ // But it also requires that the exportToSvg is being supplied with
+ // only the elements that we're exporting, and no extra.
+ text: serializeAsJSON(elements, appState, files || {}, "local"),
});
} catch (error: any) {
console.error(error);
}
}
- const [minX, minY, width, height] = getCanvasSize(elements, exportPadding);
+
+ const [minX, minY, width, height] = getCanvasSize(
+ exportingFrame ? [exportingFrame] : getRootElements(nextElements),
+ exportPadding,
+ );
// initialize SVG root
const svgRoot = document.createElementNS(SVG_NS, "svg");
@@ -148,33 +323,23 @@ export const exportToSvg = async (
assetPath = `${assetPath}/dist/excalidraw-assets/`;
}
- // do not apply clipping when we're exporting the whole scene
- const isExportingWholeCanvas =
- Scene.getScene(elements[0])?.getNonDeletedElements()?.length ===
- elements.length;
+ const offsetX = -minX + exportPadding;
+ const offsetY = -minY + exportPadding;
- const onlyExportingSingleFrame = isOnlyExportingSingleFrame(elements);
-
- const offsetX = -minX + (onlyExportingSingleFrame ? 0 : exportPadding);
- const offsetY = -minY + (onlyExportingSingleFrame ? 0 : exportPadding);
-
- const exportingFrame =
- isExportingWholeCanvas || !onlyExportingSingleFrame
- ? undefined
- : elements.find((element) => element.type === "frame");
+ const frameElements = getFrameElements(elements);
let exportingFrameClipPath = "";
- if (exportingFrame) {
- const [x1, y1, x2, y2] = getElementAbsoluteCoords(exportingFrame);
- const cx = (x2 - x1) / 2 - (exportingFrame.x - x1);
- const cy = (y2 - y1) / 2 - (exportingFrame.y - y1);
-
- exportingFrameClipPath = `<clipPath id=${exportingFrame.id}>
- <rect transform="translate(${exportingFrame.x + offsetX} ${
- exportingFrame.y + offsetY
- }) rotate(${exportingFrame.angle} ${cx} ${cy})"
- width="${exportingFrame.width}"
- height="${exportingFrame.height}"
+ for (const frame of frameElements) {
+ const [x1, y1, x2, y2] = getElementAbsoluteCoords(frame);
+ const cx = (x2 - x1) / 2 - (frame.x - x1);
+ const cy = (y2 - y1) / 2 - (frame.y - y1);
+
+ exportingFrameClipPath += `<clipPath id=${frame.id}>
+ <rect transform="translate(${frame.x + offsetX} ${
+ frame.y + offsetY
+ }) rotate(${frame.angle} ${cx} ${cy})"
+ width="${frame.width}"
+ height="${frame.height}"
>
</rect>
</clipPath>`;
@@ -193,6 +358,10 @@ export const exportToSvg = async (
font-family: "Cascadia";
src: url("${assetPath}Cascadia.woff2");
}
+ @font-face {
+ font-family: "Assistant";
+ src: url("${assetPath}Assistant-Regular.woff2");
+ }
</style>
${exportingFrameClipPath}
</defs>
@@ -210,14 +379,19 @@ export const exportToSvg = async (
}
const rsvg = rough.svg(svgRoot);
- renderSceneToSvg(elements, rsvg, svgRoot, files || {}, {
+ renderSceneToSvg(nextElements, rsvg, svgRoot, files || {}, {
offsetX,
offsetY,
- exportWithDarkMode: appState.exportWithDarkMode,
- exportingFrameId: exportingFrame?.id || null,
- renderEmbeddables: opts?.renderEmbeddables,
+ exportWithDarkMode: appState.exportWithDarkMode ?? false,
+ renderEmbeddables: opts?.renderEmbeddables ?? false,
+ frameRendering: getFrameRenderingConfig(
+ exportingFrame ?? null,
+ appState.frameRendering ?? null,
+ ),
});
+ tempScene.destroy();
+
return svgRoot;
};
@@ -226,36 +400,9 @@ const getCanvasSize = (
elements: readonly NonDeletedExcalidrawElement[],
exportPadding: number,
): Bounds => {
- // we should decide if we are exporting the whole canvas
- // if so, we are not clipping elements in the frame
- // and therefore, we should not do anything special
-
- const isExportingWholeCanvas =
- Scene.getScene(elements[0])?.getNonDeletedElements()?.length ===
- elements.length;
-
- const onlyExportingSingleFrame = isOnlyExportingSingleFrame(elements);
-
- if (!isExportingWholeCanvas || onlyExportingSingleFrame) {
- const frames = elements.filter((element) => element.type === "frame");
-
- const exportedFrameIds = frames.reduce((acc, frame) => {
- acc[frame.id] = true;
- return acc;
- }, {} as Record<string, true>);
-
- // elements in a frame do not affect the canvas size if we're not exporting
- // the whole canvas
- elements = elements.filter(
- (element) => !exportedFrameIds[element.frameId ?? ""],
- );
- }
-
const [minX, minY, maxX, maxY] = getCommonBounds(elements);
- const width =
- distance(minX, maxX) + (onlyExportingSingleFrame ? 0 : exportPadding * 2);
- const height =
- distance(minY, maxY) + (onlyExportingSingleFrame ? 0 : exportPadding * 2);
+ const width = distance(minX, maxX) + exportPadding * 2;
+ const height = distance(minY, maxY) + exportPadding * 2;
return [minX, minY, width, height];
};
diff --git a/src/scene/selection.ts b/src/scene/selection.ts
index dce7c9cd54..510dd9ef59 100644
--- a/src/scene/selection.ts
+++ b/src/scene/selection.ts
@@ -8,7 +8,7 @@ import { isBoundToContainer } from "../element/typeChecks";
import {
elementOverlapsWithFrame,
getContainingFrame,
- getFrameElements,
+ getFrameChildren,
} from "../frame";
import { isShallowEqual } from "../utils";
import { isElementInViewport } from "../element/sizeHelpers";
@@ -191,7 +191,7 @@ export const getSelectedElements = (
const elementsToInclude: ExcalidrawElement[] = [];
selectedElements.forEach((element) => {
if (element.type === "frame") {
- getFrameElements(elements, element.id).forEach((e) =>
+ getFrameChildren(elements, element.id).forEach((e) =>
elementsToInclude.push(e),
);
}
diff --git a/src/tests/__snapshots__/export.test.tsx.snap b/src/tests/__snapshots__/export.test.tsx.snap
index 8eb93c74e8..eff82ae4c4 100644
--- a/src/tests/__snapshots__/export.test.tsx.snap
+++ b/src/tests/__snapshots__/export.test.tsx.snap
@@ -14,8 +14,12 @@ exports[`export > exporting svg containing transformed images > svg export outpu
font-family: \\"Cascadia\\";
src: url(\\"https://excalidraw.com/Cascadia.woff2\\");
}
+ @font-face {
+ font-family: \\"Assistant\\";
+ src: url(\\"https://excalidraw.com/Assistant-Regular.woff2\\");
+ }
</style>
</defs>
- <g transform=\\"translate(30.710678118654755 30.710678118654755) rotate(315 50 50)\\"><use href=\\"#image-file_A\\" width=\\"100\\" height=\\"100\\" opacity=\\"1\\"></use></g><g transform=\\"translate(130.71067811865476 30.710678118654755) rotate(45 25 25)\\"><use href=\\"#image-file_A\\" width=\\"50\\" height=\\"50\\" opacity=\\"1\\" transform=\\"scale(-1, 1) translate(-50 0)\\"></use></g><g transform=\\"translate(30.710678118654755 130.71067811865476) rotate(45 50 50)\\"><use href=\\"#image-file_A\\" width=\\"100\\" height=\\"100\\" opacity=\\"1\\" transform=\\"scale(1, -1) translate(0 -100)\\"></use></g><g transform=\\"translate(130.71067811865476 130.71067811865476) rotate(315 25 25)\\"><use href=\\"#image-file_A\\" width=\\"50\\" height=\\"50\\" opacity=\\"1\\" transform=\\"scale(-1, -1) translate(-50 -50)\\"></use></g></svg>"
+ <g transform=\\"translate(30.710678118654755 30.710678118654755) rotate(315 50 50)\\" data-id=\\"id1\\"><use href=\\"#image-file_A\\" width=\\"100\\" height=\\"100\\" opacity=\\"1\\"></use></g><g transform=\\"translate(130.71067811865476 30.710678118654755) rotate(45 25 25)\\" data-id=\\"id2\\"><use href=\\"#image-file_A\\" width=\\"50\\" height=\\"50\\" opacity=\\"1\\" transform=\\"scale(-1, 1) translate(-50 0)\\"></use></g><g transform=\\"translate(30.710678118654755 130.71067811865476) rotate(45 50 50)\\" data-id=\\"id3\\"><use href=\\"#image-file_A\\" width=\\"100\\" height=\\"100\\" opacity=\\"1\\" transform=\\"scale(1, -1) translate(0 -100)\\"></use></g><g transform=\\"translate(130.71067811865476 130.71067811865476) rotate(315 25 25)\\" data-id=\\"id4\\"><use href=\\"#image-file_A\\" width=\\"50\\" height=\\"50\\" opacity=\\"1\\" transform=\\"scale(-1, -1) translate(-50 -50)\\"></use></g></svg>"
`;
diff --git a/src/tests/flip.test.tsx b/src/tests/flip.test.tsx
index d384f1224a..13edec641f 100644
--- a/src/tests/flip.test.tsx
+++ b/src/tests/flip.test.tsx
@@ -27,6 +27,7 @@ import * as blob from "../data/blob";
import { KEYS } from "../keys";
import { getBoundTextElementPosition } from "../element/textElement";
import { createPasteEvent } from "../clipboard";
+import { cloneJSON } from "../utils";
const { h } = window;
const mouse = new Pointer("mouse");
@@ -206,16 +207,14 @@ const checkElementsBoundingBox = async (
};
const checkHorizontalFlip = async (toleranceInPx: number = 0.00001) => {
- const originalElement = JSON.parse(JSON.stringify(h.elements[0]));
+ const originalElement = cloneJSON(h.elements[0]);
h.app.actionManager.executeAction(actionFlipHorizontal);
const newElement = h.elements[0];
await checkElementsBoundingBox(originalElement, newElement, toleranceInPx);
};
const checkTwoPointsLineHorizontalFlip = async () => {
- const originalElement = JSON.parse(
- JSON.stringify(h.elements[0]),
- ) as ExcalidrawLinearElement;
+ const originalElement = cloneJSON(h.elements[0]) as ExcalidrawLinearElement;
h.app.actionManager.executeAction(actionFlipHorizontal);
const newElement = h.elements[0] as ExcalidrawLinearElement;
await waitFor(() => {
@@ -239,9 +238,7 @@ const checkTwoPointsLineHorizontalFlip = async () => {
};
const checkTwoPointsLineVerticalFlip = async () => {
- const originalElement = JSON.parse(
- JSON.stringify(h.elements[0]),
- ) as ExcalidrawLinearElement;
+ const originalElement = cloneJSON(h.elements[0]) as ExcalidrawLinearElement;
h.app.actionManager.executeAction(actionFlipVertical);
const newElement = h.elements[0] as ExcalidrawLinearElement;
await waitFor(() => {
@@ -268,7 +265,7 @@ const checkRotatedHorizontalFlip = async (
expectedAngle: number,
toleranceInPx: number = 0.00001,
) => {
- const originalElement = JSON.parse(JSON.stringify(h.elements[0]));
+ const originalElement = cloneJSON(h.elements[0]);
h.app.actionManager.executeAction(actionFlipHorizontal);
const newElement = h.elements[0];
await waitFor(() => {
@@ -281,7 +278,7 @@ const checkRotatedVerticalFlip = async (
expectedAngle: number,
toleranceInPx: number = 0.00001,
) => {
- const originalElement = JSON.parse(JSON.stringify(h.elements[0]));
+ const originalElement = cloneJSON(h.elements[0]);
h.app.actionManager.executeAction(actionFlipVertical);
const newElement = h.elements[0];
await waitFor(() => {
@@ -291,7 +288,7 @@ const checkRotatedVerticalFlip = async (
};
const checkVerticalFlip = async (toleranceInPx: number = 0.00001) => {
- const originalElement = JSON.parse(JSON.stringify(h.elements[0]));
+ const originalElement = cloneJSON(h.elements[0]);
h.app.actionManager.executeAction(actionFlipVertical);
@@ -300,7 +297,7 @@ const checkVerticalFlip = async (toleranceInPx: number = 0.00001) => {
};
const checkVerticalHorizontalFlip = async (toleranceInPx: number = 0.00001) => {
- const originalElement = JSON.parse(JSON.stringify(h.elements[0]));
+ const originalElement = cloneJSON(h.elements[0]);
h.app.actionManager.executeAction(actionFlipHorizontal);
h.app.actionManager.executeAction(actionFlipVertical);
diff --git a/src/tests/helpers/api.ts b/src/tests/helpers/api.ts
index f62821431b..cdf95de22f 100644
--- a/src/tests/helpers/api.ts
+++ b/src/tests/helpers/api.ts
@@ -6,6 +6,7 @@ import {
ExcalidrawFreeDrawElement,
ExcalidrawImageElement,
FileId,
+ ExcalidrawFrameElement,
} from "../../element/types";
import { newElement, newTextElement, newLinearElement } from "../../element";
import { DEFAULT_VERTICAL_ALIGN, ROUNDNESS } from "../../constants";
@@ -136,6 +137,8 @@ export class API {
? ExcalidrawTextElement
: T extends "image"
? ExcalidrawImageElement
+ : T extends "frame"
+ ? ExcalidrawFrameElement
: ExcalidrawGenericElement => {
let element: Mutable<ExcalidrawElement> = null!;
diff --git a/src/tests/packages/utils.test.ts b/src/tests/packages/utils.test.ts
index 7d880d296f..df8c2633a3 100644
--- a/src/tests/packages/utils.test.ts
+++ b/src/tests/packages/utils.test.ts
@@ -92,7 +92,10 @@ describe("exportToSvg", () => {
expect(passedOptionsWhenDefault).toMatchSnapshot();
});
- it("with deleted elements", async () => {
+ // FIXME the utils.exportToSvg no longer filters out deleted elements.
+ // It's already supposed to be passed non-deleted elements by we're not
+ // type-checking for it correctly.
+ it.skip("with deleted elements", async () => {
await utils.exportToSvg({
...diagramFactory({
overrides: { appState: void 0 },
diff --git a/src/tests/scene/__snapshots__/export.test.ts.snap b/src/tests/scene/__snapshots__/export.test.ts.snap
index 33a1f9ca9c..d64ddfb3bb 100644
--- a/src/tests/scene/__snapshots__/export.test.ts.snap
+++ b/src/tests/scene/__snapshots__/export.test.ts.snap
@@ -29,6 +29,10 @@ exports[`exportToSvg > with default arguments 1`] = `
font-family: "Cascadia";
src: url("https://excalidraw.com/Cascadia.woff2");
}
+ @font-face {
+ font-family: "Assistant";
+ src: url("https://excalidraw.com/Assistant-Regular.woff2");
+ }
</style>
@@ -38,6 +42,7 @@ exports[`exportToSvg > with default arguments 1`] = `
<g
+ data-id="vWrqOAfkind2qcm7LDAGZ"
stroke-linecap="round"
transform="translate(10 10) rotate(0 50 50)"
>
@@ -55,6 +60,7 @@ exports[`exportToSvg > with default arguments 1`] = `
/>
</g>
<g
+ data-id="vWrqOAfkind2qcm7LDAGZ"
stroke-linecap="round"
transform="translate(10 10) rotate(0 50 50)"
>
@@ -88,10 +94,14 @@ exports[`exportToSvg > with elements that have a link 1`] = `
font-family: \\"Cascadia\\";
src: url(\\"https://excalidraw.com/Cascadia.woff2\\");
}
+ @font-face {
+ font-family: \\"Assistant\\";
+ src: url(\\"https://excalidraw.com/Assistant-Regular.woff2\\");
+ }
</style>
</defs>
- <a href=\\"excalidraw.com\\"><g stroke-linecap=\\"round\\" transform=\\"translate(10 10) rotate(0 107 107)\\"><path d=\\"M0 0 C0 0, 0 0, 0 0 M0 0 C0 0, 0 0, 0 0 M-0.26 6.4 C1.86 4, 4.58 1.9, 4.99 0.36 M-0.26 6.4 C1.63 4.44, 3.93 2.27, 4.99 0.36 M0.13 12.04 C3.95 10, 6.87 6.25, 10.63 -0.03 M0.13 12.04 C4.24 8, 8.06 2.86, 10.63 -0.03 M-0.13 18.44 C5.28 13.88, 10.16 9.29, 15.62 0.33 M-0.13 18.44 C6.82 11.86, 11.95 4.69, 15.62 0.33 M0.27 24.08 C6.17 19.69, 7.89 13.49, 21.26 -0.07 M0.27 24.08 C6.69 17.67, 12.57 11.51, 21.26 -0.07 M0 30.48 C6.64 25.53, 11.29 19.01, 26.25 0.29 M0 30.48 C6.03 23.38, 13.21 15.66, 26.25 0.29 M-0.26 36.88 C12.06 23.79, 21.4 11.71, 31.89 -0.1 M-0.26 36.88 C11.45 24.22, 21.96 12.66, 31.89 -0.1 M0.14 42.52 C6.62 34.58, 15.94 25.34, 36.88 0.26 M0.14 42.52 C7.83 34.52, 15.09 25.32, 36.88 0.26 M-0.12 48.92 C13.28 33.05, 26.09 18.51, 42.52 -0.14 M-0.12 48.92 C10.99 37.78, 21.49 24.2, 42.52 -0.14 M0.27 54.56 C13.01 40.54, 23.3 25.42, 47.51 0.22 M0.27 54.56 C15.47 36.04, 31.1 18.72, 47.51 0.22 M0.01 60.96 C10.87 47.68, 23.13 35.11, 53.15 -0.17 M0.01 60.96 C18.56 40.11, 36.41 19.39, 53.15 -0.17 M-0.25 67.36 C20.79 43.07, 42.42 21.37, 58.14 0.19 M-0.25 67.36 C17.81 45.33, 37.48 25.21, 58.14 0.19 M0.14 73 C25.91 45.9, 49.11 18.5, 63.78 -0.21 M0.14 73 C25 45.31, 48.21 16.72, 63.78 -0.21 M-0.12 79.4 C15.39 61.52, 27.49 47.58, 68.77 0.15 M-0.12 79.4 C17.44 56.79, 37.05 36.11, 68.77 0.15 M0.28 85.04 C15.54 68.41, 29.98 51.05, 74.41 -0.24 M0.28 85.04 C23.6 57.82, 46.47 32.51, 74.41 -0.24 M0.01 91.44 C18.03 71.3, 38.92 49.68, 79.4 0.12 M0.01 91.44 C25.4 62.24, 49.81 32.43, 79.4 0.12 M-0.25 97.84 C29.02 63.08, 59.29 30.29, 85.04 -0.28 M-0.25 97.84 C28.7 66.24, 57.17 33.34, 85.04 -0.28 M0.15 103.48 C26.17 73.61, 51 46.03, 90.03 0.08 M0.15 103.48 C34.47 63.4, 70.29 21.93, 90.03 0.08 M-0.11 109.88 C18.44 89.24, 39.8 65.49, 95.67 -0.31 M-0.11 109.88 C24.86 81.34, 47.28 55.5, 95.67 -0.31 M0.28 115.52 C33.95 80.6, 61.48 42.72, 100.66 0.05 M0.28 115.52 C27.07 85.07, 56.15 53.1, 100.66 0.05 M0.02 121.92 C39.77 71.9, 83.86 25.4, 106.3 -0.34 M0.02 121.92 C27.47 87.71, 55.48 54.73, 106.3 -0.34 M-0.24 128.32 C40.26 81.78, 80.15 34.82, 111.29 0.02 M-0.24 128.32 C37.61 86.75, 73.92 43.34, 111.29 0.02 M0.15 133.96 C30.8 98.07, 58.38 67.16, 116.27 0.38 M0.15 133.96 C27.66 100.67, 56.66 68.37, 116.27 0.38 M-0.11 140.36 C40.59 90.66, 83.77 41.08, 121.92 -0.02 M-0.11 140.36 C44.96 87.24, 91.49 34.77, 121.92 -0.02 M0.29 146 C47.5 90.78, 95.63 32.43, 126.91 0.34 M0.29 146 C29.66 110.08, 60.49 75.33, 126.91 0.34 M0.02 152.4 C35.86 111.47, 70.38 70.12, 132.55 -0.05 M0.02 152.4 C29.98 119.8, 59.3 86.19, 132.55 -0.05 M-0.24 158.8 C36.95 113.82, 74.41 71.44, 137.54 0.31 M-0.24 158.8 C44.93 107.87, 90.54 55.25, 137.54 0.31 M0.16 164.44 C59.09 100.28, 114.1 35.84, 143.18 -0.09 M0.16 164.44 C45.21 114.44, 88.37 64.27, 143.18 -0.09 M-0.1 170.84 C43.02 117.18, 86.47 68.38, 148.17 0.27 M-0.1 170.84 C30.93 135.74, 61.3 100.57, 148.17 0.27 M0.29 176.48 C46.83 122.33, 89.85 71.57, 153.81 -0.12 M0.29 176.48 C43.99 127.03, 88.54 74.59, 153.81 -0.12 M0.03 182.88 C48.59 127.82, 96.48 72.69, 158.8 0.24 M0.03 182.88 C60.61 109.68, 123.78 38.97, 158.8 0.24 M-0.23 189.27 C32.06 148.78, 65.75 112.55, 164.44 -0.16 M-0.23 189.27 C40.24 142.67, 81.3 96.18, 164.44 -0.16 M0.16 194.92 C38.01 148.88, 74.39 107.93, 169.43 0.2 M0.16 194.92 C38.3 149.33, 76.87 105.56, 169.43 0.2 M-0.1 201.32 C41.83 150.49, 86.42 99.86, 175.07 -0.19 M-0.1 201.32 C46.63 145.56, 96.25 88.59, 175.07 -0.19 M0.3 206.96 C49.1 152.74, 97.83 95.64, 180.06 0.17 M0.3 206.96 C46.53 152.54, 93.85 98.73, 180.06 0.17 M0.03 213.36 C44.3 164.56, 87.56 112.2, 185.7 -0.23 M0.03 213.36 C54.58 152.94, 107.86 90.98, 185.7 -0.23 M4.36 214.47 C64.78 144.22, 126.94 73.15, 190.69 0.13 M4.36 214.47 C52.36 157.93, 101.34 101.25, 190.69 0.13 M10.01 214.08 C53.42 162.57, 98.03 111.13, 196.33 -0.26 M10.01 214.08 C50.54 169, 91.26 123.9, 196.33 -0.26 M14.99 214.44 C90.59 131.61, 162.36 46.07, 201.32 0.1 M14.99 214.44 C59.65 166.34, 101.09 116.11, 201.32 0.1 M20.64 214.04 C63.23 162.27, 107.34 111.15, 206.96 -0.3 M20.64 214.04 C58.98 171.57, 96.82 126.63, 206.96 -0.3 M25.62 214.4 C84.94 149.41, 141.6 83.44, 211.95 0.06 M25.62 214.4 C94.43 134.68, 162.22 55.16, 211.95 0.06 M30.61 214.76 C78.58 155.55, 128.08 98.95, 214.31 3.44 M30.61 214.76 C75.03 164.16, 118.12 115.46, 214.31 3.44 M36.26 214.37 C74.5 174.12, 110.12 130.96, 214.05 9.84 M36.26 214.37 C92.39 150.27, 149.3 85.75, 214.05 9.84 M41.24 214.73 C87.17 160.35, 132.74 107.6, 214.44 15.48 M41.24 214.73 C91.24 156.59, 140.46 100.04, 214.44 15.48 M46.89 214.33 C98.71 152.16, 151.56 91.85, 214.18 21.88 M46.89 214.33 C98.74 156.45, 150.37 97.64, 214.18 21.88 M51.87 214.69 C90.69 172.15, 130.23 125.37, 214.57 27.53 M51.87 214.69 C111.77 146.37, 171.45 76.76, 214.57 27.53 M57.52 214.3 C110.5 151.43, 163.83 91.58, 214.31 33.92 M57.52 214.3 C93 175.68, 126.88 135.68, 214.31 33.92 M62.5 214.66 C104.96 168.13, 147.06 117.35, 214.05 40.32 M62.5 214.66 C109.29 158.93, 155.94 104.22, 214.05 40.32 M68.15 214.26 C105.89 170.44, 144.19 128.05, 214.45 45.96 M68.15 214.26 C116.92 156.96, 165.72 101.69, 214.45 45.96 M73.13 214.62 C121.61 157.37, 171.93 100.84, 214.19 52.36 M73.13 214.62 C123.2 156.26, 172.77 97, 214.19 52.36 M78.78 214.23 C123.99 162.65, 168.54 112.83, 214.58 58 M78.78 214.23 C126.69 159.63, 175.57 104.04, 214.58 58 M83.76 214.59 C125.13 166.22, 168.45 116.61, 214.32 64.4 M83.76 214.59 C131.17 159.77, 180.03 104.16, 214.32 64.4 M89.41 214.2 C127.13 170.54, 163.12 131.23, 214.06 70.8 M89.41 214.2 C116.58 182.86, 142.76 153.97, 214.06 70.8 M94.39 214.56 C129.16 172.19, 168.93 128.63, 214.45 76.44 M94.39 214.56 C123.53 182.2, 151.09 151.6, 214.45 76.44 M100.04 214.16 C143.57 163.36, 190.88 114.02, 214.19 82.84 M100.04 214.16 C126.89 183.31, 153.16 153.27, 214.19 82.84 M105.02 214.52 C142.5 172.88, 182.51 127.18, 214.58 88.48 M105.02 214.52 C131.4 183.31, 158.54 153.16, 214.58 88.48 M110.67 214.13 C141.86 175.44, 175.2 139.12, 214.32 94.88 M110.67 214.13 C152.79 167.39, 193.06 120.28, 214.32 94.88 M115.65 214.49 C148.13 176.9, 179.74 140.07, 214.06 101.28 M115.65 214.49 C148.07 178.59, 180.64 142.78, 214.06 101.28 M121.3 214.09 C145.71 188.17, 167.91 157.36, 214.46 106.92 M121.3 214.09 C147.71 184.83, 171.36 157.26, 214.46 106.92 M126.28 214.45 C146.54 192.43, 164.94 168.59, 214.19 113.32 M126.28 214.45 C144.98 193.3, 161.8 171.97, 214.19 113.32 M131.93 214.06 C155.88 185.67, 180.21 158.65, 214.59 118.96 M131.93 214.06 C151.85 191.06, 171.09 168.01, 214.59 118.96 M136.91 214.42 C160.1 188.38, 182.21 161.51, 214.33 125.36 M136.91 214.42 C158.68 191.07, 177.98 167.43, 214.33 125.36 M142.56 214.02 C169.06 182.79, 195.5 153.12, 214.07 131.76 M142.56 214.02 C166.82 186.11, 192.2 158.08, 214.07 131.76 M147.54 214.38 C167.86 193.37, 186.97 171.57, 214.46 137.4 M147.54 214.38 C164.09 194.7, 181.74 174.84, 214.46 137.4 M152.53 214.74 C171.53 190.99, 190.47 172.46, 214.2 143.8 M152.53 214.74 C165.32 200.71, 178.49 184.48, 214.2 143.8 M158.17 214.35 C171.73 200.55, 184.23 185.22, 214.59 149.44 M158.17 214.35 C180.24 188.99, 202.79 163.92, 214.59 149.44 M163.16 214.71 C175.07 199.76, 187.35 187.33, 214.33 155.84 M163.16 214.71 C177.61 196.45, 193.13 178.88, 214.33 155.84 M168.8 214.31 C177.01 204.44, 189.05 191.27, 214.07 162.24 M168.8 214.31 C180.2 200.58, 193.81 186.51, 214.07 162.24 M173.79 214.67 C186.68 199.8, 199.12 182.17, 214.47 167.88 M173.79 214.67 C184.37 203.24, 195.74 190.73, 214.47 167.88 M179.43 214.28 C186.54 206.43, 193.87 194.75, 214.2 174.28 M179.43 214.28 C192.03 200.39, 202.21 186.14, 214.2 174.28 M184.42 214.64 C193.06 202.86, 202.37 194.14, 214.6 179.92 M184.42 214.64 C191.6 207.41, 197.45 199.78, 214.6 179.92 M190.06 214.25 C197.36 204.92, 207.53 195.21, 214.34 186.32 M190.06 214.25 C196.03 207.43, 201.66 200.16, 214.34 186.32 M195.05 214.61 C200.06 210.45, 203.81 203.75, 214.08 192.72 M195.05 214.61 C200.37 208.28, 204.8 203.01, 214.08 192.72 M200.69 214.21 C203.31 207.7, 208.66 205.6, 214.47 198.36 M200.69 214.21 C204.63 209.52, 207.41 205.7, 214.47 198.36 M205.68 214.57 C208.36 211.42, 210.09 210.31, 214.21 204.76 M205.68 214.57 C208.96 210.99, 211.69 207.87, 214.21 204.76 M211.32 214.18 C212.2 213.32, 213.44 212.01, 214.6 210.4 M211.32 214.18 C212.31 213.55, 212.84 212.38, 214.6 210.4\\" stroke=\\"#15aabf\\" stroke-width=\\"0.5\\" fill=\\"none\\"></path><path d=\\"M0 0 C56.1 -0.99, 111.94 -0.97, 214 0 M0 0 C76.32 0.56, 152.1 -0.37, 214 0 M214 0 C213.17 51.96, 213.7 104.26, 214 214 M214 0 C216.19 79.54, 215.05 161.15, 214 214 M214 214 C134.35 212.91, 56.14 213.64, 0 214 M214 214 C132.56 212.83, 48.96 213.92, 0 214 M0 214 C0.52 161.49, 1.36 109.33, 0 0 M0 214 C-0.59 157.45, -0.74 100.81, 0 0\\" stroke=\\"#000000\\" stroke-width=\\"1\\" fill=\\"none\\"></path></g></a>"
+ <a href=\\"excalidraw.com\\"><g stroke-linecap=\\"round\\" transform=\\"translate(10 10) rotate(0 107 107)\\" data-id=\\"vWrqOAfkind2qcm7LDAGZ\\"><path d=\\"M0 0 C0 0, 0 0, 0 0 M0 0 C0 0, 0 0, 0 0 M-0.26 6.4 C1.86 4, 4.58 1.9, 4.99 0.36 M-0.26 6.4 C1.63 4.44, 3.93 2.27, 4.99 0.36 M0.13 12.04 C3.95 10, 6.87 6.25, 10.63 -0.03 M0.13 12.04 C4.24 8, 8.06 2.86, 10.63 -0.03 M-0.13 18.44 C5.28 13.88, 10.16 9.29, 15.62 0.33 M-0.13 18.44 C6.82 11.86, 11.95 4.69, 15.62 0.33 M0.27 24.08 C6.17 19.69, 7.89 13.49, 21.26 -0.07 M0.27 24.08 C6.69 17.67, 12.57 11.51, 21.26 -0.07 M0 30.48 C6.64 25.53, 11.29 19.01, 26.25 0.29 M0 30.48 C6.03 23.38, 13.21 15.66, 26.25 0.29 M-0.26 36.88 C12.06 23.79, 21.4 11.71, 31.89 -0.1 M-0.26 36.88 C11.45 24.22, 21.96 12.66, 31.89 -0.1 M0.14 42.52 C6.62 34.58, 15.94 25.34, 36.88 0.26 M0.14 42.52 C7.83 34.52, 15.09 25.32, 36.88 0.26 M-0.12 48.92 C13.28 33.05, 26.09 18.51, 42.52 -0.14 M-0.12 48.92 C10.99 37.78, 21.49 24.2, 42.52 -0.14 M0.27 54.56 C13.01 40.54, 23.3 25.42, 47.51 0.22 M0.27 54.56 C15.47 36.04, 31.1 18.72, 47.51 0.22 M0.01 60.96 C10.87 47.68, 23.13 35.11, 53.15 -0.17 M0.01 60.96 C18.56 40.11, 36.41 19.39, 53.15 -0.17 M-0.25 67.36 C20.79 43.07, 42.42 21.37, 58.14 0.19 M-0.25 67.36 C17.81 45.33, 37.48 25.21, 58.14 0.19 M0.14 73 C25.91 45.9, 49.11 18.5, 63.78 -0.21 M0.14 73 C25 45.31, 48.21 16.72, 63.78 -0.21 M-0.12 79.4 C15.39 61.52, 27.49 47.58, 68.77 0.15 M-0.12 79.4 C17.44 56.79, 37.05 36.11, 68.77 0.15 M0.28 85.04 C15.54 68.41, 29.98 51.05, 74.41 -0.24 M0.28 85.04 C23.6 57.82, 46.47 32.51, 74.41 -0.24 M0.01 91.44 C18.03 71.3, 38.92 49.68, 79.4 0.12 M0.01 91.44 C25.4 62.24, 49.81 32.43, 79.4 0.12 M-0.25 97.84 C29.02 63.08, 59.29 30.29, 85.04 -0.28 M-0.25 97.84 C28.7 66.24, 57.17 33.34, 85.04 -0.28 M0.15 103.48 C26.17 73.61, 51 46.03, 90.03 0.08 M0.15 103.48 C34.47 63.4, 70.29 21.93, 90.03 0.08 M-0.11 109.88 C18.44 89.24, 39.8 65.49, 95.67 -0.31 M-0.11 109.88 C24.86 81.34, 47.28 55.5, 95.67 -0.31 M0.28 115.52 C33.95 80.6, 61.48 42.72, 100.66 0.05 M0.28 115.52 C27.07 85.07, 56.15 53.1, 100.66 0.05 M0.02 121.92 C39.77 71.9, 83.86 25.4, 106.3 -0.34 M0.02 121.92 C27.47 87.71, 55.48 54.73, 106.3 -0.34 M-0.24 128.32 C40.26 81.78, 80.15 34.82, 111.29 0.02 M-0.24 128.32 C37.61 86.75, 73.92 43.34, 111.29 0.02 M0.15 133.96 C30.8 98.07, 58.38 67.16, 116.27 0.38 M0.15 133.96 C27.66 100.67, 56.66 68.37, 116.27 0.38 M-0.11 140.36 C40.59 90.66, 83.77 41.08, 121.92 -0.02 M-0.11 140.36 C44.96 87.24, 91.49 34.77, 121.92 -0.02 M0.29 146 C47.5 90.78, 95.63 32.43, 126.91 0.34 M0.29 146 C29.66 110.08, 60.49 75.33, 126.91 0.34 M0.02 152.4 C35.86 111.47, 70.38 70.12, 132.55 -0.05 M0.02 152.4 C29.98 119.8, 59.3 86.19, 132.55 -0.05 M-0.24 158.8 C36.95 113.82, 74.41 71.44, 137.54 0.31 M-0.24 158.8 C44.93 107.87, 90.54 55.25, 137.54 0.31 M0.16 164.44 C59.09 100.28, 114.1 35.84, 143.18 -0.09 M0.16 164.44 C45.21 114.44, 88.37 64.27, 143.18 -0.09 M-0.1 170.84 C43.02 117.18, 86.47 68.38, 148.17 0.27 M-0.1 170.84 C30.93 135.74, 61.3 100.57, 148.17 0.27 M0.29 176.48 C46.83 122.33, 89.85 71.57, 153.81 -0.12 M0.29 176.48 C43.99 127.03, 88.54 74.59, 153.81 -0.12 M0.03 182.88 C48.59 127.82, 96.48 72.69, 158.8 0.24 M0.03 182.88 C60.61 109.68, 123.78 38.97, 158.8 0.24 M-0.23 189.27 C32.06 148.78, 65.75 112.55, 164.44 -0.16 M-0.23 189.27 C40.24 142.67, 81.3 96.18, 164.44 -0.16 M0.16 194.92 C38.01 148.88, 74.39 107.93, 169.43 0.2 M0.16 194.92 C38.3 149.33, 76.87 105.56, 169.43 0.2 M-0.1 201.32 C41.83 150.49, 86.42 99.86, 175.07 -0.19 M-0.1 201.32 C46.63 145.56, 96.25 88.59, 175.07 -0.19 M0.3 206.96 C49.1 152.74, 97.83 95.64, 180.06 0.17 M0.3 206.96 C46.53 152.54, 93.85 98.73, 180.06 0.17 M0.03 213.36 C44.3 164.56, 87.56 112.2, 185.7 -0.23 M0.03 213.36 C54.58 152.94, 107.86 90.98, 185.7 -0.23 M4.36 214.47 C64.78 144.22, 126.94 73.15, 190.69 0.13 M4.36 214.47 C52.36 157.93, 101.34 101.25, 190.69 0.13 M10.01 214.08 C53.42 162.57, 98.03 111.13, 196.33 -0.26 M10.01 214.08 C50.54 169, 91.26 123.9, 196.33 -0.26 M14.99 214.44 C90.59 131.61, 162.36 46.07, 201.32 0.1 M14.99 214.44 C59.65 166.34, 101.09 116.11, 201.32 0.1 M20.64 214.04 C63.23 162.27, 107.34 111.15, 206.96 -0.3 M20.64 214.04 C58.98 171.57, 96.82 126.63, 206.96 -0.3 M25.62 214.4 C84.94 149.41, 141.6 83.44, 211.95 0.06 M25.62 214.4 C94.43 134.68, 162.22 55.16, 211.95 0.06 M30.61 214.76 C78.58 155.55, 128.08 98.95, 214.31 3.44 M30.61 214.76 C75.03 164.16, 118.12 115.46, 214.31 3.44 M36.26 214.37 C74.5 174.12, 110.12 130.96, 214.05 9.84 M36.26 214.37 C92.39 150.27, 149.3 85.75, 214.05 9.84 M41.24 214.73 C87.17 160.35, 132.74 107.6, 214.44 15.48 M41.24 214.73 C91.24 156.59, 140.46 100.04, 214.44 15.48 M46.89 214.33 C98.71 152.16, 151.56 91.85, 214.18 21.88 M46.89 214.33 C98.74 156.45, 150.37 97.64, 214.18 21.88 M51.87 214.69 C90.69 172.15, 130.23 125.37, 214.57 27.53 M51.87 214.69 C111.77 146.37, 171.45 76.76, 214.57 27.53 M57.52 214.3 C110.5 151.43, 163.83 91.58, 214.31 33.92 M57.52 214.3 C93 175.68, 126.88 135.68, 214.31 33.92 M62.5 214.66 C104.96 168.13, 147.06 117.35, 214.05 40.32 M62.5 214.66 C109.29 158.93, 155.94 104.22, 214.05 40.32 M68.15 214.26 C105.89 170.44, 144.19 128.05, 214.45 45.96 M68.15 214.26 C116.92 156.96, 165.72 101.69, 214.45 45.96 M73.13 214.62 C121.61 157.37, 171.93 100.84, 214.19 52.36 M73.13 214.62 C123.2 156.26, 172.77 97, 214.19 52.36 M78.78 214.23 C123.99 162.65, 168.54 112.83, 214.58 58 M78.78 214.23 C126.69 159.63, 175.57 104.04, 214.58 58 M83.76 214.59 C125.13 166.22, 168.45 116.61, 214.32 64.4 M83.76 214.59 C131.17 159.77, 180.03 104.16, 214.32 64.4 M89.41 214.2 C127.13 170.54, 163.12 131.23, 214.06 70.8 M89.41 214.2 C116.58 182.86, 142.76 153.97, 214.06 70.8 M94.39 214.56 C129.16 172.19, 168.93 128.63, 214.45 76.44 M94.39 214.56 C123.53 182.2, 151.09 151.6, 214.45 76.44 M100.04 214.16 C143.57 163.36, 190.88 114.02, 214.19 82.84 M100.04 214.16 C126.89 183.31, 153.16 153.27, 214.19 82.84 M105.02 214.52 C142.5 172.88, 182.51 127.18, 214.58 88.48 M105.02 214.52 C131.4 183.31, 158.54 153.16, 214.58 88.48 M110.67 214.13 C141.86 175.44, 175.2 139.12, 214.32 94.88 M110.67 214.13 C152.79 167.39, 193.06 120.28, 214.32 94.88 M115.65 214.49 C148.13 176.9, 179.74 140.07, 214.06 101.28 M115.65 214.49 C148.07 178.59, 180.64 142.78, 214.06 101.28 M121.3 214.09 C145.71 188.17, 167.91 157.36, 214.46 106.92 M121.3 214.09 C147.71 184.83, 171.36 157.26, 214.46 106.92 M126.28 214.45 C146.54 192.43, 164.94 168.59, 214.19 113.32 M126.28 214.45 C144.98 193.3, 161.8 171.97, 214.19 113.32 M131.93 214.06 C155.88 185.67, 180.21 158.65, 214.59 118.96 M131.93 214.06 C151.85 191.06, 171.09 168.01, 214.59 118.96 M136.91 214.42 C160.1 188.38, 182.21 161.51, 214.33 125.36 M136.91 214.42 C158.68 191.07, 177.98 167.43, 214.33 125.36 M142.56 214.02 C169.06 182.79, 195.5 153.12, 214.07 131.76 M142.56 214.02 C166.82 186.11, 192.2 158.08, 214.07 131.76 M147.54 214.38 C167.86 193.37, 186.97 171.57, 214.46 137.4 M147.54 214.38 C164.09 194.7, 181.74 174.84, 214.46 137.4 M152.53 214.74 C171.53 190.99, 190.47 172.46, 214.2 143.8 M152.53 214.74 C165.32 200.71, 178.49 184.48, 214.2 143.8 M158.17 214.35 C171.73 200.55, 184.23 185.22, 214.59 149.44 M158.17 214.35 C180.24 188.99, 202.79 163.92, 214.59 149.44 M163.16 214.71 C175.07 199.76, 187.35 187.33, 214.33 155.84 M163.16 214.71 C177.61 196.45, 193.13 178.88, 214.33 155.84 M168.8 214.31 C177.01 204.44, 189.05 191.27, 214.07 162.24 M168.8 214.31 C180.2 200.58, 193.81 186.51, 214.07 162.24 M173.79 214.67 C186.68 199.8, 199.12 182.17, 214.47 167.88 M173.79 214.67 C184.37 203.24, 195.74 190.73, 214.47 167.88 M179.43 214.28 C186.54 206.43, 193.87 194.75, 214.2 174.28 M179.43 214.28 C192.03 200.39, 202.21 186.14, 214.2 174.28 M184.42 214.64 C193.06 202.86, 202.37 194.14, 214.6 179.92 M184.42 214.64 C191.6 207.41, 197.45 199.78, 214.6 179.92 M190.06 214.25 C197.36 204.92, 207.53 195.21, 214.34 186.32 M190.06 214.25 C196.03 207.43, 201.66 200.16, 214.34 186.32 M195.05 214.61 C200.06 210.45, 203.81 203.75, 214.08 192.72 M195.05 214.61 C200.37 208.28, 204.8 203.01, 214.08 192.72 M200.69 214.21 C203.31 207.7, 208.66 205.6, 214.47 198.36 M200.69 214.21 C204.63 209.52, 207.41 205.7, 214.47 198.36 M205.68 214.57 C208.36 211.42, 210.09 210.31, 214.21 204.76 M205.68 214.57 C208.96 210.99, 211.69 207.87, 214.21 204.76 M211.32 214.18 C212.2 213.32, 213.44 212.01, 214.6 210.4 M211.32 214.18 C212.31 213.55, 212.84 212.38, 214.6 210.4\\" stroke=\\"#15aabf\\" stroke-width=\\"0.5\\" fill=\\"none\\"></path><path d=\\"M0 0 C56.1 -0.99, 111.94 -0.97, 214 0 M0 0 C76.32 0.56, 152.1 -0.37, 214 0 M214 0 C213.17 51.96, 213.7 104.26, 214 214 M214 0 C216.19 79.54, 215.05 161.15, 214 214 M214 214 C134.35 212.91, 56.14 213.64, 0 214 M214 214 C132.56 212.83, 48.96 213.92, 0 214 M0 214 C0.52 161.49, 1.36 109.33, 0 0 M0 214 C-0.59 157.45, -0.74 100.81, 0 0\\" stroke=\\"#000000\\" stroke-width=\\"1\\" fill=\\"none\\"></path></g></a>"
`;
exports[`exportToSvg > with exportEmbedScene 1`] = `
@@ -108,8 +118,12 @@ exports[`exportToSvg > with exportEmbedScene 1`] = `
font-family: \\"Cascadia\\";
src: url(\\"https://excalidraw.com/Cascadia.woff2\\");
}
+ @font-face {
+ font-family: \\"Assistant\\";
+ src: url(\\"https://excalidraw.com/Assistant-Regular.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 M2.68 54.01 C17.68 37.03, 33.95 20.86, 40.74 10.24 M2.68 54.01 C16.59 38.38, 31.52 22.36, 40.74 10.24 M5.7 56.63 C19.86 43.02, 33.12 27.27, 52.94 2.29 M5.7 56.63 C23.06 37.39, 40.39 16.53, 52.94 2.29 M8.72 59.26 C23.62 43.85, 37.66 28.7, 55.96 4.92 M8.72 59.26 C27.67 38.75, 44.88 17.7, 55.96 4.92 M11.74 61.88 C23.55 50.54, 31.34 37.36, 58.98 7.54 M11.74 61.88 C25.4 47.12, 38.59 32.54, 58.98 7.54 M14.76 64.51 C25.64 54.29, 34.7 42.69, 61.34 10.92 M14.76 64.51 C25.83 51.81, 38 38.36, 61.34 10.92 M17.12 67.88 C34.34 49.26, 48.5 31.65, 64.36 13.55 M17.12 67.88 C33.86 49.33, 49.44 31.94, 64.36 13.55 M20.14 70.51 C28.87 60.06, 40.4 48.29, 66.72 16.92 M20.14 70.51 C29.76 60.14, 39.05 48.61, 66.72 16.92 M23.16 73.13 C37.73 55.91, 51.72 40.01, 69.74 19.55 M23.16 73.13 C35.28 60.9, 46.76 46.19, 69.74 19.55 M26.18 75.76 C38.75 61.93, 48.87 47, 72.76 22.17 M26.18 75.76 C41.17 57.48, 56.57 40.42, 72.76 22.17 M29.2 78.38 C38.58 66.84, 49.28 56.06, 75.12 25.55 M29.2 78.38 C45.23 60.41, 60.56 42.59, 75.12 25.55 M31.56 81.76 C48.47 62.24, 65.95 45.31, 78.14 28.18 M31.56 81.76 C45.84 64.05, 61.69 48.32, 78.14 28.18 M34.58 84.39 C53.9 64.75, 70.59 44.84, 81.16 30.8 M34.58 84.39 C52.97 64.26, 69.66 43.17, 81.16 30.8 M37.6 87.01 C48.25 74.78, 55.5 66.41, 83.52 34.18 M37.6 87.01 C48.99 71.83, 62.27 58.43, 83.52 34.18 M40.62 89.63 C50.34 79.26, 59.13 68.4, 86.54 36.8 M40.62 89.63 C54.92 72.51, 68.88 57.45, 86.54 36.8 M43.64 92.26 C53.65 80.81, 66.89 67.98, 89.56 39.43 M43.64 92.26 C58.66 75.45, 72.42 57.89, 89.56 39.43 M46 95.64 C61.79 76.78, 78.15 59.99, 91.92 42.81 M46 95.64 C61.9 78.99, 77.17 61.29, 91.92 42.81 M49.02 98.26 C62.86 82.2, 75.55 68.59, 94.94 45.43 M49.02 98.26 C66.35 78.07, 84.72 56.67, 94.94 45.43 M61.22 90.32 C67.86 83.05, 77.21 73.12, 97.96 48.06 M61.22 90.32 C71.29 78.99, 79.23 69.82, 97.96 48.06\\" stroke=\\"#15aabf\\" stroke-width=\\"0.5\\" fill=\\"none\\"></path><path d=\\"M51 0 C63.55 12.43, 75.75 25.91, 100 51 M51 0 C68.7 19, 85.84 36.05, 100 51 M100 51 C86.33 62.39, 74.98 74.41, 51 100 M100 51 C82.86 68.81, 63.17 88.61, 51 100 M51 100 C30.58 80.76, 12.2 63.63, 0 51 M51 100 C32.58 80.36, 11.39 62.79, 0 51 M0 51 C13.05 38.39, 26.48 26.08, 51 0 M0 51 C14.03 37.59, 27.42 24.3, 51 0\\" stroke=\\"#000000\\" stroke-width=\\"1\\" fill=\\"none\\"></path></g><g stroke-linecap=\\"round\\" transform=\\"translate(10 10) rotate(0 50 50)\\"><path d=\\"M16.06 13.96 C16.06 13.96, 16.06 13.96, 16.06 13.96 M16.06 13.96 C16.06 13.96, 16.06 13.96, 16.06 13.96 M4.65 33.19 C11.77 27.87, 17.81 20.43, 26.3 8.29 M4.65 33.19 C12.84 24.59, 20.75 14.56, 26.3 8.29 M4.39 39.59 C14.94 29.16, 24.78 18.84, 37.19 1.85 M4.39 39.59 C17.83 25.46, 29.51 10.78, 37.19 1.85 M4.13 45.99 C13.58 37.43, 18.93 27.04, 40.86 3.72 M4.13 45.99 C14.89 34.56, 25.16 23.35, 40.86 3.72 M3.86 52.38 C13.79 43.36, 21.85 32.91, 45.85 4.08 M3.86 52.38 C13.79 40.95, 24.84 28.8, 45.85 4.08 M0.98 61.8 C19.05 42.22, 34.04 23.64, 50.84 4.44 M0.98 61.8 C18.6 42.22, 35.05 23.82, 50.84 4.44 M2.69 65.93 C13.07 53.65, 26.22 40.02, 56.48 4.05 M2.69 65.93 C13.71 53.84, 24.49 40.6, 56.48 4.05 M5.05 69.31 C22.52 48.71, 39.47 29.41, 61.47 4.41 M5.05 69.31 C19.68 54.34, 33.61 36.81, 61.47 4.41 M7.41 72.69 C23.29 55.19, 36.64 36.55, 66.46 4.77 M7.41 72.69 C26.51 49.67, 46.1 27.78, 66.46 4.77 M9.12 76.83 C21.59 61.65, 35.54 47.13, 70.13 6.64 M9.12 76.83 C30.41 52.84, 51 28.96, 70.13 6.64 M11.48 80.21 C33.9 54.33, 56.91 31.04, 73.81 8.51 M11.48 80.21 C30.8 56.74, 51.74 35.15, 73.81 8.51 M13.84 83.58 C39.61 56.49, 62.81 29.08, 77.48 10.38 M13.84 83.58 C38.7 55.9, 61.91 27.31, 77.48 10.38 M16.21 86.96 C30.75 70.22, 41.87 57.39, 80.5 13 M16.21 86.96 C32.53 65.84, 50.87 46.62, 80.5 13 M19.88 88.83 C33.21 74.39, 45.68 59.3, 84.17 14.87 M19.88 88.83 C40.06 65.13, 59.82 43.4, 84.17 14.87 M23.56 90.7 C37.96 74.48, 55.4 56.83, 87.85 16.74 M23.56 90.7 C44.27 67.09, 63.87 42.81, 87.85 16.74 M26.57 93.33 C48.43 67.31, 71.05 43.33, 90.21 20.12 M26.57 93.33 C48.35 69.95, 69.55 45.41, 90.21 20.12 M30.25 95.2 C48.46 74.18, 65.49 55.57, 91.92 24.25 M30.25 95.2 C53.67 67.88, 78.29 39.3, 91.92 24.25 M33.92 97.07 C45.33 84.45, 59.49 68.99, 94.28 27.63 M33.92 97.07 C49.95 78.85, 63.69 63.01, 94.28 27.63 M37.6 98.93 C57.98 79.1, 72.57 56.11, 95.99 31.77 M37.6 98.93 C52.82 81.56, 70.36 62.86, 95.99 31.77 M42.59 99.3 C62.5 72.18, 86.66 48.61, 98.35 35.14 M42.59 99.3 C56.8 81.15, 71.26 63.76, 98.35 35.14 M48.23 98.9 C67.5 76.43, 86.2 53.85, 100.71 38.52 M48.23 98.9 C66.04 79.87, 82.62 59.16, 100.71 38.52 M53.87 98.51 C66.57 83.45, 76.58 72.74, 100.45 44.92 M53.87 98.51 C64.66 85.25, 76.57 72.6, 100.45 44.92 M58.86 98.87 C72.85 81.35, 88.43 63.51, 100.85 50.56 M58.86 98.87 C74.11 80.25, 90.51 62.43, 100.85 50.56 M63.19 99.98 C76.96 84.2, 90.81 65.29, 100.59 56.96 M63.19 99.98 C71.88 89.37, 81.43 79.1, 100.59 56.96 M74.08 93.55 C81.37 85.47, 87.74 76.3, 99.67 64.11 M74.08 93.55 C79.97 87.9, 85.67 81.47, 99.67 64.11\\" stroke=\\"#15aabf\\" stroke-width=\\"0.5\\" fill=\\"none\\"></path><path d=\\"M38.1 1.46 C45.72 -1.06, 55.49 -0.08, 63.58 2.19 C71.68 4.46, 80.88 9.29, 86.67 15.09 C92.46 20.89, 96.33 29.02, 98.32 36.99 C100.32 44.97, 101 54.87, 98.62 62.96 C96.24 71.05, 90.17 79.66, 84.03 85.55 C77.89 91.43, 69.57 96.06, 61.79 98.28 C54 100.51, 45.12 100.97, 37.32 98.91 C29.52 96.84, 21.11 92.03, 14.99 85.89 C8.88 79.75, 2.75 70.16, 0.63 62.05 C-1.48 53.94, -0.22 45.19, 2.3 37.23 C4.82 29.28, 9.28 20.51, 15.77 14.3 C22.25 8.1, 36.21 2.25, 41.23 0.02 C46.25 -2.21, 45.49 0.09, 45.88 0.91 M40.94 1.53 C48.29 -0.28, 59.04 0.38, 66.96 3.27 C74.89 6.16, 83.12 12.22, 88.48 18.88 C93.85 25.53, 97.82 35.15, 99.18 43.21 C100.54 51.28, 99.41 59.58, 96.65 67.29 C93.89 74.99, 88.87 84.03, 82.63 89.47 C76.39 94.91, 67.44 98.55, 59.2 99.93 C50.97 101.3, 41.25 100.52, 33.2 97.7 C25.15 94.87, 16.16 89.68, 10.9 82.99 C5.64 76.3, 2.84 65.86, 1.64 57.57 C0.45 49.28, 0.99 40.72, 3.74 33.24 C6.5 25.76, 11.77 18.2, 18.18 12.7 C24.59 7.2, 38.36 1.99, 42.22 0.24 C46.09 -1.5, 41.49 1.56, 41.37 2.2\\" stroke=\\"#000000\\" stroke-width=\\"1\\" fill=\\"none\\"></path></g>"
+ <g stroke-linecap=\\"round\\" transform=\\"translate(10 10) rotate(0 50 50)\\" data-id=\\"vWrqOAfkind2qcm7LDAGZ\\"><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 M2.68 54.01 C17.68 37.03, 33.95 20.86, 40.74 10.24 M2.68 54.01 C16.59 38.38, 31.52 22.36, 40.74 10.24 M5.7 56.63 C19.86 43.02, 33.12 27.27, 52.94 2.29 M5.7 56.63 C23.06 37.39, 40.39 16.53, 52.94 2.29 M8.72 59.26 C23.62 43.85, 37.66 28.7, 55.96 4.92 M8.72 59.26 C27.67 38.75, 44.88 17.7, 55.96 4.92 M11.74 61.88 C23.55 50.54, 31.34 37.36, 58.98 7.54 M11.74 61.88 C25.4 47.12, 38.59 32.54, 58.98 7.54 M14.76 64.51 C25.64 54.29, 34.7 42.69, 61.34 10.92 M14.76 64.51 C25.83 51.81, 38 38.36, 61.34 10.92 M17.12 67.88 C34.34 49.26, 48.5 31.65, 64.36 13.55 M17.12 67.88 C33.86 49.33, 49.44 31.94, 64.36 13.55 M20.14 70.51 C28.87 60.06, 40.4 48.29, 66.72 16.92 M20.14 70.51 C29.76 60.14, 39.05 48.61, 66.72 16.92 M23.16 73.13 C37.73 55.91, 51.72 40.01, 69.74 19.55 M23.16 73.13 C35.28 60.9, 46.76 46.19, 69.74 19.55 M26.18 75.76 C38.75 61.93, 48.87 47, 72.76 22.17 M26.18 75.76 C41.17 57.48, 56.57 40.42, 72.76 22.17 M29.2 78.38 C38.58 66.84, 49.28 56.06, 75.12 25.55 M29.2 78.38 C45.23 60.41, 60.56 42.59, 75.12 25.55 M31.56 81.76 C48.47 62.24, 65.95 45.31, 78.14 28.18 M31.56 81.76 C45.84 64.05, 61.69 48.32, 78.14 28.18 M34.58 84.39 C53.9 64.75, 70.59 44.84, 81.16 30.8 M34.58 84.39 C52.97 64.26, 69.66 43.17, 81.16 30.8 M37.6 87.01 C48.25 74.78, 55.5 66.41, 83.52 34.18 M37.6 87.01 C48.99 71.83, 62.27 58.43, 83.52 34.18 M40.62 89.63 C50.34 79.26, 59.13 68.4, 86.54 36.8 M40.62 89.63 C54.92 72.51, 68.88 57.45, 86.54 36.8 M43.64 92.26 C53.65 80.81, 66.89 67.98, 89.56 39.43 M43.64 92.26 C58.66 75.45, 72.42 57.89, 89.56 39.43 M46 95.64 C61.79 76.78, 78.15 59.99, 91.92 42.81 M46 95.64 C61.9 78.99, 77.17 61.29, 91.92 42.81 M49.02 98.26 C62.86 82.2, 75.55 68.59, 94.94 45.43 M49.02 98.26 C66.35 78.07, 84.72 56.67, 94.94 45.43 M61.22 90.32 C67.86 83.05, 77.21 73.12, 97.96 48.06 M61.22 90.32 C71.29 78.99, 79.23 69.82, 97.96 48.06\\" stroke=\\"#15aabf\\" stroke-width=\\"0.5\\" fill=\\"none\\"></path><path d=\\"M51 0 C63.55 12.43, 75.75 25.91, 100 51 M51 0 C68.7 19, 85.84 36.05, 100 51 M100 51 C86.33 62.39, 74.98 74.41, 51 100 M100 51 C82.86 68.81, 63.17 88.61, 51 100 M51 100 C30.58 80.76, 12.2 63.63, 0 51 M51 100 C32.58 80.36, 11.39 62.79, 0 51 M0 51 C13.05 38.39, 26.48 26.08, 51 0 M0 51 C14.03 37.59, 27.42 24.3, 51 0\\" stroke=\\"#000000\\" stroke-width=\\"1\\" fill=\\"none\\"></path></g><g stroke-linecap=\\"round\\" transform=\\"translate(10 10) rotate(0 50 50)\\" data-id=\\"vWrqOAfkind2qcm7LDAGZ\\"><path d=\\"M16.06 13.96 C16.06 13.96, 16.06 13.96, 16.06 13.96 M16.06 13.96 C16.06 13.96, 16.06 13.96, 16.06 13.96 M4.65 33.19 C11.77 27.87, 17.81 20.43, 26.3 8.29 M4.65 33.19 C12.84 24.59, 20.75 14.56, 26.3 8.29 M4.39 39.59 C14.94 29.16, 24.78 18.84, 37.19 1.85 M4.39 39.59 C17.83 25.46, 29.51 10.78, 37.19 1.85 M4.13 45.99 C13.58 37.43, 18.93 27.04, 40.86 3.72 M4.13 45.99 C14.89 34.56, 25.16 23.35, 40.86 3.72 M3.86 52.38 C13.79 43.36, 21.85 32.91, 45.85 4.08 M3.86 52.38 C13.79 40.95, 24.84 28.8, 45.85 4.08 M0.98 61.8 C19.05 42.22, 34.04 23.64, 50.84 4.44 M0.98 61.8 C18.6 42.22, 35.05 23.82, 50.84 4.44 M2.69 65.93 C13.07 53.65, 26.22 40.02, 56.48 4.05 M2.69 65.93 C13.71 53.84, 24.49 40.6, 56.48 4.05 M5.05 69.31 C22.52 48.71, 39.47 29.41, 61.47 4.41 M5.05 69.31 C19.68 54.34, 33.61 36.81, 61.47 4.41 M7.41 72.69 C23.29 55.19, 36.64 36.55, 66.46 4.77 M7.41 72.69 C26.51 49.67, 46.1 27.78, 66.46 4.77 M9.12 76.83 C21.59 61.65, 35.54 47.13, 70.13 6.64 M9.12 76.83 C30.41 52.84, 51 28.96, 70.13 6.64 M11.48 80.21 C33.9 54.33, 56.91 31.04, 73.81 8.51 M11.48 80.21 C30.8 56.74, 51.74 35.15, 73.81 8.51 M13.84 83.58 C39.61 56.49, 62.81 29.08, 77.48 10.38 M13.84 83.58 C38.7 55.9, 61.91 27.31, 77.48 10.38 M16.21 86.96 C30.75 70.22, 41.87 57.39, 80.5 13 M16.21 86.96 C32.53 65.84, 50.87 46.62, 80.5 13 M19.88 88.83 C33.21 74.39, 45.68 59.3, 84.17 14.87 M19.88 88.83 C40.06 65.13, 59.82 43.4, 84.17 14.87 M23.56 90.7 C37.96 74.48, 55.4 56.83, 87.85 16.74 M23.56 90.7 C44.27 67.09, 63.87 42.81, 87.85 16.74 M26.57 93.33 C48.43 67.31, 71.05 43.33, 90.21 20.12 M26.57 93.33 C48.35 69.95, 69.55 45.41, 90.21 20.12 M30.25 95.2 C48.46 74.18, 65.49 55.57, 91.92 24.25 M30.25 95.2 C53.67 67.88, 78.29 39.3, 91.92 24.25 M33.92 97.07 C45.33 84.45, 59.49 68.99, 94.28 27.63 M33.92 97.07 C49.95 78.85, 63.69 63.01, 94.28 27.63 M37.6 98.93 C57.98 79.1, 72.57 56.11, 95.99 31.77 M37.6 98.93 C52.82 81.56, 70.36 62.86, 95.99 31.77 M42.59 99.3 C62.5 72.18, 86.66 48.61, 98.35 35.14 M42.59 99.3 C56.8 81.15, 71.26 63.76, 98.35 35.14 M48.23 98.9 C67.5 76.43, 86.2 53.85, 100.71 38.52 M48.23 98.9 C66.04 79.87, 82.62 59.16, 100.71 38.52 M53.87 98.51 C66.57 83.45, 76.58 72.74, 100.45 44.92 M53.87 98.51 C64.66 85.25, 76.57 72.6, 100.45 44.92 M58.86 98.87 C72.85 81.35, 88.43 63.51, 100.85 50.56 M58.86 98.87 C74.11 80.25, 90.51 62.43, 100.85 50.56 M63.19 99.98 C76.96 84.2, 90.81 65.29, 100.59 56.96 M63.19 99.98 C71.88 89.37, 81.43 79.1, 100.59 56.96 M74.08 93.55 C81.37 85.47, 87.74 76.3, 99.67 64.11 M74.08 93.55 C79.97 87.9, 85.67 81.47, 99.67 64.11\\" stroke=\\"#15aabf\\" stroke-width=\\"0.5\\" fill=\\"none\\"></path><path d=\\"M38.1 1.46 C45.72 -1.06, 55.49 -0.08, 63.58 2.19 C71.68 4.46, 80.88 9.29, 86.67 15.09 C92.46 20.89, 96.33 29.02, 98.32 36.99 C100.32 44.97, 101 54.87, 98.62 62.96 C96.24 71.05, 90.17 79.66, 84.03 85.55 C77.89 91.43, 69.57 96.06, 61.79 98.28 C54 100.51, 45.12 100.97, 37.32 98.91 C29.52 96.84, 21.11 92.03, 14.99 85.89 C8.88 79.75, 2.75 70.16, 0.63 62.05 C-1.48 53.94, -0.22 45.19, 2.3 37.23 C4.82 29.28, 9.28 20.51, 15.77 14.3 C22.25 8.1, 36.21 2.25, 41.23 0.02 C46.25 -2.21, 45.49 0.09, 45.88 0.91 M40.94 1.53 C48.29 -0.28, 59.04 0.38, 66.96 3.27 C74.89 6.16, 83.12 12.22, 88.48 18.88 C93.85 25.53, 97.82 35.15, 99.18 43.21 C100.54 51.28, 99.41 59.58, 96.65 67.29 C93.89 74.99, 88.87 84.03, 82.63 89.47 C76.39 94.91, 67.44 98.55, 59.2 99.93 C50.97 101.3, 41.25 100.52, 33.2 97.7 C25.15 94.87, 16.16 89.68, 10.9 82.99 C5.64 76.3, 2.84 65.86, 1.64 57.57 C0.45 49.28, 0.99 40.72, 3.74 33.24 C6.5 25.76, 11.77 18.2, 18.18 12.7 C24.59 7.2, 38.36 1.99, 42.22 0.24 C46.09 -1.5, 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.ts
index 4da7a702e0..297401d2ae 100644
--- a/src/tests/scene/export.test.ts
+++ b/src/tests/scene/export.test.ts
@@ -5,6 +5,10 @@ import {
ellipseFixture,
rectangleWithLinkFixture,
} from "../fixtures/elementFixture";
+import { API } from "../helpers/api";
+import { exportToCanvas, exportToSvg } from "../../packages/utils";
+import { FRAME_STYLE } from "../../constants";
+import { prepareElementsForExport } from "../../data";
describe("exportToSvg", () => {
window.EXCALIDRAW_ASSET_PATH = "/";
@@ -127,3 +131,280 @@ describe("exportToSvg", () => {
expect(svgElement.innerHTML).toMatchSnapshot();
});
});
+
+describe("exporting frames", () => {
+ const getFrameNameHeight = (exportType: "canvas" | "svg") => {
+ const height =
+ FRAME_STYLE.nameFontSize * FRAME_STYLE.nameLineHeight +
+ FRAME_STYLE.nameOffsetY;
+ // canvas truncates dimensions to integers
+ if (exportType === "canvas") {
+ return Math.trunc(height);
+ }
+ return height;
+ };
+
+ // a few tests with exportToCanvas (where we can't inspect elements)
+ // ---------------------------------------------------------------------------
+
+ describe("exportToCanvas", () => {
+ it("exporting canvas with a single frame shouldn't crop if not exporting frame directly", async () => {
+ const elements = [
+ API.createElement({
+ type: "frame",
+ width: 100,
+ height: 100,
+ x: 0,
+ y: 0,
+ }),
+ API.createElement({
+ type: "rectangle",
+ width: 100,
+ height: 100,
+ x: 100,
+ y: 0,
+ }),
+ ];
+
+ const canvas = await exportToCanvas({
+ elements,
+ files: null,
+ exportPadding: 0,
+ });
+
+ expect(canvas.width).toEqual(200);
+ expect(canvas.height).toEqual(100 + getFrameNameHeight("canvas"));
+ });
+
+ it("exporting canvas with a single frame should crop when exporting frame directly", async () => {
+ const frame = API.createElement({
+ type: "frame",
+ width: 100,
+ height: 100,
+ x: 0,
+ y: 0,
+ });
+ const elements = [
+ frame,
+ API.createElement({
+ type: "rectangle",
+ width: 100,
+ height: 100,
+ x: 100,
+ y: 0,
+ }),
+ ];
+
+ const canvas = await exportToCanvas({
+ elements,
+ files: null,
+ exportPadding: 0,
+ exportingFrame: frame,
+ });
+
+ expect(canvas.width).toEqual(frame.width);
+ expect(canvas.height).toEqual(frame.height);
+ });
+ });
+
+ // exportToSvg (so we can test for element existence)
+ // ---------------------------------------------------------------------------
+ describe("exportToSvg", () => {
+ it("exporting frame should include overlapping elements, but crop to frame", async () => {
+ const frame = API.createElement({
+ type: "frame",
+ width: 100,
+ height: 100,
+ x: 0,
+ y: 0,
+ });
+ const frameChild = API.createElement({
+ type: "rectangle",
+ width: 100,
+ height: 100,
+ x: 0,
+ y: 50,
+ frameId: frame.id,
+ });
+ const rectOverlapping = API.createElement({
+ type: "rectangle",
+ width: 100,
+ height: 100,
+ x: 50,
+ y: 0,
+ });
+
+ const svg = await exportToSvg({
+ elements: [rectOverlapping, frame, frameChild],
+ files: null,
+ exportPadding: 0,
+ exportingFrame: frame,
+ });
+
+ // frame itself isn't exported
+ expect(svg.querySelector(`[data-id="${frame.id}"]`)).toBeNull();
+ // frame child is exported
+ expect(svg.querySelector(`[data-id="${frameChild.id}"]`)).not.toBeNull();
+ // overlapping element is exported
+ expect(
+ svg.querySelector(`[data-id="${rectOverlapping.id}"]`),
+ ).not.toBeNull();
+
+ expect(svg.getAttribute("width")).toBe(frame.width.toString());
+ expect(svg.getAttribute("height")).toBe(frame.height.toString());
+ });
+
+ it("should filter non-overlapping elements when exporting a frame", async () => {
+ const frame = API.createElement({
+ type: "frame",
+ width: 100,
+ height: 100,
+ x: 0,
+ y: 0,
+ });
+ const frameChild = API.createElement({
+ type: "rectangle",
+ width: 100,
+ height: 100,
+ x: 0,
+ y: 50,
+ frameId: frame.id,
+ });
+ const elementOutside = API.createElement({
+ type: "rectangle",
+ width: 100,
+ height: 100,
+ x: 200,
+ y: 0,
+ });
+
+ const svg = await exportToSvg({
+ elements: [frameChild, frame, elementOutside],
+ files: null,
+ exportPadding: 0,
+ exportingFrame: frame,
+ });
+
+ // frame itself isn't exported
+ expect(svg.querySelector(`[data-id="${frame.id}"]`)).toBeNull();
+ // frame child is exported
+ expect(svg.querySelector(`[data-id="${frameChild.id}"]`)).not.toBeNull();
+ // non-overlapping element is not exported
+ expect(svg.querySelector(`[data-id="${elementOutside.id}"]`)).toBeNull();
+
+ expect(svg.getAttribute("width")).toBe(frame.width.toString());
+ expect(svg.getAttribute("height")).toBe(frame.height.toString());
+ });
+
+ it("should export multiple frames when selected, excluding overlapping elements", async () => {
+ const frame1 = API.createElement({
+ type: "frame",
+ width: 100,
+ height: 100,
+ x: 0,
+ y: 0,
+ });
+ const frame2 = API.createElement({
+ type: "frame",
+ width: 100,
+ height: 100,
+ x: 200,
+ y: 0,
+ });
+
+ const frame1Child = API.createElement({
+ type: "rectangle",
+ width: 100,
+ height: 100,
+ x: 0,
+ y: 50,
+ frameId: frame1.id,
+ });
+ const frame2Child = API.createElement({
+ type: "rectangle",
+ width: 100,
+ height: 100,
+ x: 200,
+ y: 0,
+ frameId: frame2.id,
+ });
+ const frame2Overlapping = API.createElement({
+ type: "rectangle",
+ width: 100,
+ height: 100,
+ x: 350,
+ y: 0,
+ });
+
+ // low-level exportToSvg api expects elements to be pre-filtered, so let's
+ // use the filter we use in the editor
+ const { exportedElements, exportingFrame } = prepareElementsForExport(
+ [frame1Child, frame1, frame2Child, frame2, frame2Overlapping],
+ {
+ selectedElementIds: { [frame1.id]: true, [frame2.id]: true },
+ },
+ true,
+ );
+
+ const svg = await exportToSvg({
+ elements: exportedElements,
+ files: null,
+ exportPadding: 0,
+ exportingFrame,
+ });
+
+ // frames themselves should be exported when multiple frames selected
+ expect(svg.querySelector(`[data-id="${frame1.id}"]`)).not.toBeNull();
+ expect(svg.querySelector(`[data-id="${frame2.id}"]`)).not.toBeNull();
+ // children should be epxorted
+ expect(svg.querySelector(`[data-id="${frame1Child.id}"]`)).not.toBeNull();
+ expect(svg.querySelector(`[data-id="${frame2Child.id}"]`)).not.toBeNull();
+ // overlapping elements or non-overlapping elements should not be exported
+ expect(
+ svg.querySelector(`[data-id="${frame2Overlapping.id}"]`),
+ ).toBeNull();
+
+ expect(svg.getAttribute("width")).toBe(
+ (frame2.x + frame2.width).toString(),
+ );
+ expect(svg.getAttribute("height")).toBe(
+ (frame2.y + frame2.height + getFrameNameHeight("svg")).toString(),
+ );
+ });
+
+ it("should render frame alone when not selected", async () => {
+ const frame = API.createElement({
+ type: "frame",
+ width: 100,
+ height: 100,
+ x: 0,
+ y: 0,
+ });
+
+ // low-level exportToSvg api expects elements to be pre-filtered, so let's
+ // use the filter we use in the editor
+ const { exportedElements, exportingFrame } = prepareElementsForExport(
+ [frame],
+ {
+ selectedElementIds: {},
+ },
+ false,
+ );
+
+ const svg = await exportToSvg({
+ elements: exportedElements,
+ files: null,
+ exportPadding: 0,
+ exportingFrame,
+ });
+
+ // frame itself isn't exported
+ expect(svg.querySelector(`[data-id="${frame.id}"]`)).not.toBeNull();
+
+ expect(svg.getAttribute("width")).toBe(frame.width.toString());
+ expect(svg.getAttribute("height")).toBe(
+ (frame.height + getFrameNameHeight("svg")).toString(),
+ );
+ });
+ });
+});
diff --git a/src/utils.ts b/src/utils.ts
index 67481960fc..d5fb432ed1 100644
--- a/src/utils.ts
+++ b/src/utils.ts
@@ -834,11 +834,18 @@ export const isOnlyExportingSingleFrame = (
);
};
+/**
+ * supply `null` as message if non-never value is valid, you just need to
+ * typecheck against it
+ */
export const assertNever = (
value: never,
- message: string,
+ message: string | null,
softAssert?: boolean,
): never => {
+ if (!message) {
+ return value;
+ }
if (softAssert) {
console.error(message);
return value;
@@ -931,3 +938,5 @@ export const isMemberOf = <T extends string>(
? collection.includes(value as T)
: collection.hasOwnProperty(value);
};
+
+export const cloneJSON = <T>(obj: T): T => JSON.parse(JSON.stringify(obj));