constants.ts 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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. } as const;
  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. // custom events
  53. EXCALIDRAW_LINK = "excalidraw-link",
  54. }
  55. export const ENV = {
  56. TEST: "test",
  57. DEVELOPMENT: "development",
  58. };
  59. export const CLASSES = {
  60. SHAPE_ACTIONS_MENU: "App-menu__left",
  61. };
  62. // 1-based in case we ever do `if(element.fontFamily)`
  63. export const FONT_FAMILY = {
  64. Virgil: 1,
  65. Helvetica: 2,
  66. Cascadia: 3,
  67. };
  68. export const THEME = {
  69. LIGHT: "light",
  70. DARK: "dark",
  71. };
  72. export const WINDOWS_EMOJI_FALLBACK_FONT = "Segoe UI Emoji";
  73. export const DEFAULT_FONT_SIZE = 20;
  74. export const DEFAULT_FONT_FAMILY: FontFamilyValues = FONT_FAMILY.Virgil;
  75. export const DEFAULT_TEXT_ALIGN = "left";
  76. export const DEFAULT_VERTICAL_ALIGN = "top";
  77. export const DEFAULT_VERSION = "{version}";
  78. export const CANVAS_ONLY_ACTIONS = ["selectAll"];
  79. export const GRID_SIZE = 20; // TODO make it configurable?
  80. export const MIME_TYPES = {
  81. excalidraw: "application/vnd.excalidraw+json",
  82. excalidrawlib: "application/vnd.excalidrawlib+json",
  83. json: "application/json",
  84. svg: "image/svg+xml",
  85. "excalidraw.svg": "image/svg+xml",
  86. png: "image/png",
  87. "excalidraw.png": "image/png",
  88. jpg: "image/jpeg",
  89. gif: "image/gif",
  90. webp: "image/webp",
  91. bmp: "image/bmp",
  92. ico: "image/x-icon",
  93. binary: "application/octet-stream",
  94. } as const;
  95. export const EXPORT_DATA_TYPES = {
  96. excalidraw: "excalidraw",
  97. excalidrawClipboard: "excalidraw/clipboard",
  98. excalidrawLibrary: "excalidrawlib",
  99. } as const;
  100. export const EXPORT_SOURCE =
  101. window.EXCALIDRAW_EXPORT_SOURCE || window.location.origin;
  102. // time in milliseconds
  103. export const IMAGE_RENDER_TIMEOUT = 500;
  104. export const TAP_TWICE_TIMEOUT = 300;
  105. export const TOUCH_CTX_MENU_TIMEOUT = 500;
  106. export const TITLE_TIMEOUT = 10000;
  107. export const VERSION_TIMEOUT = 30000;
  108. export const SCROLL_TIMEOUT = 100;
  109. export const ZOOM_STEP = 0.1;
  110. export const HYPERLINK_TOOLTIP_DELAY = 300;
  111. // Report a user inactive after IDLE_THRESHOLD milliseconds
  112. export const IDLE_THRESHOLD = 60_000;
  113. // Report a user active each ACTIVE_THRESHOLD milliseconds
  114. export const ACTIVE_THRESHOLD = 3_000;
  115. export const MODES = {
  116. VIEW: "viewMode",
  117. ZEN: "zenMode",
  118. GRID: "gridMode",
  119. };
  120. export const THEME_FILTER = cssVariables.themeFilter;
  121. export const URL_QUERY_KEYS = {
  122. addLibrary: "addLibrary",
  123. } as const;
  124. export const URL_HASH_KEYS = {
  125. addLibrary: "addLibrary",
  126. } as const;
  127. export const DEFAULT_UI_OPTIONS: AppProps["UIOptions"] = {
  128. canvasActions: {
  129. changeViewBackgroundColor: true,
  130. clearCanvas: true,
  131. export: { saveFileToDisk: true },
  132. loadScene: true,
  133. saveToActiveFile: true,
  134. toggleTheme: null,
  135. saveAsImage: true,
  136. },
  137. };
  138. // breakpoints
  139. // -----------------------------------------------------------------------------
  140. // sm screen
  141. export const MQ_SM_MAX_WIDTH = 640;
  142. // md screen
  143. export const MQ_MAX_WIDTH_PORTRAIT = 730;
  144. export const MQ_MAX_WIDTH_LANDSCAPE = 1000;
  145. export const MQ_MAX_HEIGHT_LANDSCAPE = 500;
  146. // sidebar
  147. export const MQ_RIGHT_SIDEBAR_MIN_WIDTH = 1229;
  148. // -----------------------------------------------------------------------------
  149. export const LIBRARY_SIDEBAR_WIDTH = parseInt(cssVariables.rightSidebarWidth);
  150. export const MAX_DECIMALS_FOR_SVG_EXPORT = 2;
  151. export const EXPORT_SCALES = [1, 2, 3];
  152. export const DEFAULT_EXPORT_PADDING = 10; // px
  153. export const DEFAULT_MAX_IMAGE_WIDTH_OR_HEIGHT = 1440;
  154. export const ALLOWED_IMAGE_MIME_TYPES = [
  155. MIME_TYPES.png,
  156. MIME_TYPES.jpg,
  157. MIME_TYPES.svg,
  158. MIME_TYPES.gif,
  159. MIME_TYPES.webp,
  160. MIME_TYPES.bmp,
  161. MIME_TYPES.ico,
  162. ] as const;
  163. export const MAX_ALLOWED_FILE_BYTES = 2 * 1024 * 1024;
  164. export const SVG_NS = "http://www.w3.org/2000/svg";
  165. export const ENCRYPTION_KEY_BITS = 128;
  166. export const VERSIONS = {
  167. excalidraw: 2,
  168. excalidrawLibrary: 2,
  169. } as const;
  170. export const BOUND_TEXT_PADDING = 5;
  171. export const VERTICAL_ALIGN = {
  172. TOP: "top",
  173. MIDDLE: "middle",
  174. BOTTOM: "bottom",
  175. };
  176. export const TEXT_ALIGN = {
  177. LEFT: "left",
  178. CENTER: "center",
  179. RIGHT: "right",
  180. };
  181. export const ELEMENT_READY_TO_ERASE_OPACITY = 20;
  182. export const COOKIES = {
  183. AUTH_STATE_COOKIE: "excplus-auth",
  184. } as const;
  185. /** key containt id of precedeing elemnt id we use in reconciliation during
  186. * collaboration */
  187. export const PRECEDING_ELEMENT_KEY = "__precedingElement__";