appState.ts 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import oc from "open-color";
  2. import { AppState, FlooredNumber } from "./types";
  3. import { getDateTime } from "./utils";
  4. import { t } from "./i18n";
  5. import { FontFamily } from "./element/types";
  6. export const DEFAULT_FONT_SIZE = 20;
  7. export const DEFAULT_FONT_FAMILY: FontFamily = 1;
  8. export const DEFAULT_TEXT_ALIGN = "left";
  9. export const getDefaultAppState = (): AppState => {
  10. return {
  11. isLoading: false,
  12. errorMessage: null,
  13. draggingElement: null,
  14. resizingElement: null,
  15. multiElement: null,
  16. editingElement: null,
  17. editingLinearElement: null,
  18. elementType: "selection",
  19. elementLocked: false,
  20. exportBackground: true,
  21. shouldAddWatermark: false,
  22. currentItemStrokeColor: oc.black,
  23. currentItemBackgroundColor: "transparent",
  24. currentItemFillStyle: "hachure",
  25. currentItemStrokeWidth: 1,
  26. currentItemStrokeStyle: "solid",
  27. currentItemRoughness: 1,
  28. currentItemOpacity: 100,
  29. currentItemFontSize: DEFAULT_FONT_SIZE,
  30. currentItemFontFamily: DEFAULT_FONT_FAMILY,
  31. currentItemTextAlign: DEFAULT_TEXT_ALIGN,
  32. viewBackgroundColor: oc.white,
  33. scrollX: 0 as FlooredNumber,
  34. scrollY: 0 as FlooredNumber,
  35. cursorX: 0,
  36. cursorY: 0,
  37. cursorButton: "up",
  38. scrolledOutside: false,
  39. name: `${t("labels.untitled")}-${getDateTime()}`,
  40. username: "",
  41. isCollaborating: false,
  42. isResizing: false,
  43. isRotating: false,
  44. selectionElement: null,
  45. zoom: 1,
  46. openMenu: null,
  47. lastPointerDownWith: "mouse",
  48. selectedElementIds: {},
  49. previousSelectedElementIds: {},
  50. collaborators: new Map(),
  51. shouldCacheIgnoreZoom: false,
  52. showShortcutsDialog: false,
  53. zenModeEnabled: false,
  54. editingGroupId: null,
  55. selectedGroupIds: {},
  56. };
  57. };
  58. export const clearAppStateForLocalStorage = (appState: AppState) => {
  59. const {
  60. draggingElement,
  61. resizingElement,
  62. multiElement,
  63. editingElement,
  64. selectionElement,
  65. isResizing,
  66. isRotating,
  67. collaborators,
  68. isCollaborating,
  69. isLoading,
  70. errorMessage,
  71. showShortcutsDialog,
  72. editingLinearElement,
  73. ...exportedState
  74. } = appState;
  75. return exportedState;
  76. };
  77. export const cleanAppStateForExport = (appState: AppState) => {
  78. return {
  79. viewBackgroundColor: appState.viewBackgroundColor,
  80. };
  81. };