1
0
mirror of https://github.com/excalidraw/excalidraw.git synced 2025-02-18 13:29:36 +01:00
excalidraw/src/appState.ts
2020-02-07 10:43:30 +00:00

71 lines
1.9 KiB
TypeScript

import { AppState } from "./types";
import { getDateTime } from "./utils";
import { getLanguage } from "./i18n";
const DEFAULT_PROJECT_NAME = `excalidraw-${getDateTime()}`;
export function getDefaultAppState(): AppState {
return {
draggingElement: null,
resizingElement: null,
multiElement: null,
editingElement: null,
elementType: "selection",
elementLocked: false,
exportBackground: true,
currentItemStrokeColor: "#000000",
currentItemBackgroundColor: "transparent",
currentItemFillStyle: "hachure",
currentItemStrokeWidth: 1,
currentItemRoughness: 1,
currentItemOpacity: 100,
currentItemFont: "20px Virgil",
viewBackgroundColor: "#ffffff",
scrollX: 0,
scrollY: 0,
cursorX: 0,
cursorY: 0,
scrolledOutside: false,
name: DEFAULT_PROJECT_NAME,
isResizing: false,
selectionElement: null,
lng: getLanguage(),
};
}
export function clearAppStateForLocalStorage(appState: AppState) {
const {
draggingElement,
resizingElement,
multiElement,
editingElement,
selectionElement,
isResizing,
...exportedState
} = appState;
return exportedState;
}
export function clearAppStatePropertiesForHistory(
appState: AppState,
): Partial<AppState> {
return {
exportBackground: appState.exportBackground,
currentItemStrokeColor: appState.currentItemStrokeColor,
currentItemBackgroundColor: appState.currentItemBackgroundColor,
currentItemFillStyle: appState.currentItemFillStyle,
currentItemStrokeWidth: appState.currentItemStrokeWidth,
currentItemRoughness: appState.currentItemRoughness,
currentItemOpacity: appState.currentItemOpacity,
currentItemFont: appState.currentItemFont,
viewBackgroundColor: appState.viewBackgroundColor,
name: appState.name,
};
}
export function cleanAppStateForExport(appState: AppState) {
return {
viewBackgroundColor: appState.viewBackgroundColor,
};
}