constants.ts 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. import cssVariables from "./css/variables.module.scss";
  2. import { AppProps } from "./types";
  3. import { FontFamilyValues } from "./element/types";
  4. export const APP_NAME = "Excalidraw";
  5. export const DRAGGING_THRESHOLD = 10; // px
  6. export const LINE_CONFIRM_THRESHOLD = 8; // px
  7. export const ELEMENT_SHIFT_TRANSLATE_AMOUNT = 5;
  8. export const ELEMENT_TRANSLATE_AMOUNT = 1;
  9. export const TEXT_TO_CENTER_SNAP_THRESHOLD = 30;
  10. export const SHIFT_LOCKING_ANGLE = Math.PI / 12;
  11. export const CURSOR_TYPE = {
  12. TEXT: "text",
  13. CROSSHAIR: "crosshair",
  14. GRABBING: "grabbing",
  15. GRAB: "grab",
  16. POINTER: "pointer",
  17. MOVE: "move",
  18. AUTO: "",
  19. };
  20. export const POINTER_BUTTON = {
  21. MAIN: 0,
  22. WHEEL: 1,
  23. SECONDARY: 2,
  24. TOUCH: -1,
  25. };
  26. export enum EVENT {
  27. COPY = "copy",
  28. PASTE = "paste",
  29. CUT = "cut",
  30. KEYDOWN = "keydown",
  31. KEYUP = "keyup",
  32. MOUSE_MOVE = "mousemove",
  33. RESIZE = "resize",
  34. UNLOAD = "unload",
  35. FOCUS = "focus",
  36. BLUR = "blur",
  37. DRAG_OVER = "dragover",
  38. DROP = "drop",
  39. GESTURE_END = "gestureend",
  40. BEFORE_UNLOAD = "beforeunload",
  41. GESTURE_START = "gesturestart",
  42. GESTURE_CHANGE = "gesturechange",
  43. POINTER_MOVE = "pointermove",
  44. POINTER_UP = "pointerup",
  45. STATE_CHANGE = "statechange",
  46. WHEEL = "wheel",
  47. TOUCH_START = "touchstart",
  48. TOUCH_END = "touchend",
  49. HASHCHANGE = "hashchange",
  50. VISIBILITY_CHANGE = "visibilitychange",
  51. SCROLL = "scroll",
  52. }
  53. export const ENV = {
  54. TEST: "test",
  55. DEVELOPMENT: "development",
  56. };
  57. export const CLASSES = {
  58. SHAPE_ACTIONS_MENU: "App-menu__left",
  59. };
  60. // 1-based in case we ever do `if(element.fontFamily)`
  61. export const FONT_FAMILY = {
  62. Virgil: 1,
  63. Helvetica: 2,
  64. Cascadia: 3,
  65. };
  66. export const THEME = {
  67. LIGHT: "light",
  68. DARK: "dark",
  69. };
  70. export const WINDOWS_EMOJI_FALLBACK_FONT = "Segoe UI Emoji";
  71. export const DEFAULT_FONT_SIZE = 20;
  72. export const DEFAULT_FONT_FAMILY: FontFamilyValues = FONT_FAMILY.Virgil;
  73. export const DEFAULT_TEXT_ALIGN = "left";
  74. export const DEFAULT_VERTICAL_ALIGN = "top";
  75. export const DEFAULT_VERSION = "{version}";
  76. export const CANVAS_ONLY_ACTIONS = ["selectAll"];
  77. export const GRID_SIZE = 20; // TODO make it configurable?
  78. export const MIME_TYPES = {
  79. excalidraw: "application/vnd.excalidraw+json",
  80. excalidrawlib: "application/vnd.excalidrawlib+json",
  81. json: "application/json",
  82. svg: "image/svg+xml",
  83. png: "image/png",
  84. jpg: "image/jpeg",
  85. gif: "image/gif",
  86. binary: "application/octet-stream",
  87. } as const;
  88. export const EXPORT_DATA_TYPES = {
  89. excalidraw: "excalidraw",
  90. excalidrawClipboard: "excalidraw/clipboard",
  91. excalidrawLibrary: "excalidrawlib",
  92. } as const;
  93. export const EXPORT_SOURCE = window.location.origin;
  94. // time in milliseconds
  95. export const IMAGE_RENDER_TIMEOUT = 500;
  96. export const TAP_TWICE_TIMEOUT = 300;
  97. export const TOUCH_CTX_MENU_TIMEOUT = 500;
  98. export const TITLE_TIMEOUT = 10000;
  99. export const TOAST_TIMEOUT = 5000;
  100. export const VERSION_TIMEOUT = 30000;
  101. export const SCROLL_TIMEOUT = 100;
  102. export const ZOOM_STEP = 0.1;
  103. // Report a user inactive after IDLE_THRESHOLD milliseconds
  104. export const IDLE_THRESHOLD = 60_000;
  105. // Report a user active each ACTIVE_THRESHOLD milliseconds
  106. export const ACTIVE_THRESHOLD = 3_000;
  107. export const MODES = {
  108. VIEW: "viewMode",
  109. ZEN: "zenMode",
  110. GRID: "gridMode",
  111. };
  112. export const THEME_FILTER = cssVariables.themeFilter;
  113. export const URL_QUERY_KEYS = {
  114. addLibrary: "addLibrary",
  115. } as const;
  116. export const URL_HASH_KEYS = {
  117. addLibrary: "addLibrary",
  118. } as const;
  119. export const DEFAULT_UI_OPTIONS: AppProps["UIOptions"] = {
  120. canvasActions: {
  121. changeViewBackgroundColor: true,
  122. clearCanvas: true,
  123. export: { saveFileToDisk: true },
  124. loadScene: true,
  125. saveToActiveFile: true,
  126. theme: true,
  127. saveAsImage: true,
  128. },
  129. };
  130. export const MQ_MAX_WIDTH_PORTRAIT = 730;
  131. export const MQ_MAX_WIDTH_LANDSCAPE = 1000;
  132. export const MQ_MAX_HEIGHT_LANDSCAPE = 500;
  133. export const MAX_DECIMALS_FOR_SVG_EXPORT = 2;
  134. export const EXPORT_SCALES = [1, 2, 3];
  135. export const DEFAULT_EXPORT_PADDING = 10; // px
  136. export const DEFAULT_MAX_IMAGE_WIDTH_OR_HEIGHT = 1440;
  137. export const ALLOWED_IMAGE_MIME_TYPES = [
  138. MIME_TYPES.png,
  139. MIME_TYPES.jpg,
  140. MIME_TYPES.svg,
  141. MIME_TYPES.gif,
  142. ] as const;
  143. export const MAX_ALLOWED_FILE_BYTES = 2 * 1024 * 1024;
  144. export const SVG_NS = "http://www.w3.org/2000/svg";
  145. export const ENCRYPTION_KEY_BITS = 128;
  146. export const VERSIONS = {
  147. excalidraw: 2,
  148. excalidrawLibrary: 2,
  149. } as const;
  150. export const BOUND_TEXT_PADDING = 5;