constants.ts 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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. binary: "application/octet-stream",
  91. } as const;
  92. export const EXPORT_DATA_TYPES = {
  93. excalidraw: "excalidraw",
  94. excalidrawClipboard: "excalidraw/clipboard",
  95. excalidrawLibrary: "excalidrawlib",
  96. } as const;
  97. export const EXPORT_SOURCE =
  98. window.EXCALIDRAW_EXPORT_SOURCE || window.location.origin;
  99. // time in milliseconds
  100. export const IMAGE_RENDER_TIMEOUT = 500;
  101. export const TAP_TWICE_TIMEOUT = 300;
  102. export const TOUCH_CTX_MENU_TIMEOUT = 500;
  103. export const TITLE_TIMEOUT = 10000;
  104. export const VERSION_TIMEOUT = 30000;
  105. export const SCROLL_TIMEOUT = 100;
  106. export const ZOOM_STEP = 0.1;
  107. export const HYPERLINK_TOOLTIP_DELAY = 300;
  108. // Report a user inactive after IDLE_THRESHOLD milliseconds
  109. export const IDLE_THRESHOLD = 60_000;
  110. // Report a user active each ACTIVE_THRESHOLD milliseconds
  111. export const ACTIVE_THRESHOLD = 3_000;
  112. export const MODES = {
  113. VIEW: "viewMode",
  114. ZEN: "zenMode",
  115. GRID: "gridMode",
  116. };
  117. export const THEME_FILTER = cssVariables.themeFilter;
  118. export const URL_QUERY_KEYS = {
  119. addLibrary: "addLibrary",
  120. } as const;
  121. export const URL_HASH_KEYS = {
  122. addLibrary: "addLibrary",
  123. } as const;
  124. export const DEFAULT_UI_OPTIONS: AppProps["UIOptions"] = {
  125. canvasActions: {
  126. changeViewBackgroundColor: true,
  127. clearCanvas: true,
  128. export: { saveFileToDisk: true },
  129. loadScene: true,
  130. saveToActiveFile: true,
  131. theme: true,
  132. saveAsImage: true,
  133. },
  134. };
  135. // breakpoints
  136. // -----------------------------------------------------------------------------
  137. // sm screen
  138. export const MQ_SM_MAX_WIDTH = 640;
  139. // md screen
  140. export const MQ_MAX_WIDTH_PORTRAIT = 730;
  141. export const MQ_MAX_WIDTH_LANDSCAPE = 1000;
  142. export const MQ_MAX_HEIGHT_LANDSCAPE = 500;
  143. // sidebar
  144. export const MQ_RIGHT_SIDEBAR_MIN_WIDTH = 1229;
  145. // -----------------------------------------------------------------------------
  146. export const LIBRARY_SIDEBAR_WIDTH = parseInt(cssVariables.rightSidebarWidth);
  147. export const MAX_DECIMALS_FOR_SVG_EXPORT = 2;
  148. export const EXPORT_SCALES = [1, 2, 3];
  149. export const DEFAULT_EXPORT_PADDING = 10; // px
  150. export const DEFAULT_MAX_IMAGE_WIDTH_OR_HEIGHT = 1440;
  151. export const ALLOWED_IMAGE_MIME_TYPES = [
  152. MIME_TYPES.png,
  153. MIME_TYPES.jpg,
  154. MIME_TYPES.svg,
  155. MIME_TYPES.gif,
  156. ] as const;
  157. export const MAX_ALLOWED_FILE_BYTES = 2 * 1024 * 1024;
  158. export const SVG_NS = "http://www.w3.org/2000/svg";
  159. export const ENCRYPTION_KEY_BITS = 128;
  160. export const VERSIONS = {
  161. excalidraw: 2,
  162. excalidrawLibrary: 2,
  163. } as const;
  164. export const BOUND_TEXT_PADDING = 5;
  165. export const VERTICAL_ALIGN = {
  166. TOP: "top",
  167. MIDDLE: "middle",
  168. BOTTOM: "bottom",
  169. };
  170. export const ELEMENT_READY_TO_ERASE_OPACITY = 20;
  171. export const COOKIES = {
  172. AUTH_STATE_COOKIE: "excplus-auth",
  173. } as const;