constants.ts 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. png: "image/png",
  86. jpg: "image/jpeg",
  87. gif: "image/gif",
  88. binary: "application/octet-stream",
  89. } as const;
  90. export const EXPORT_DATA_TYPES = {
  91. excalidraw: "excalidraw",
  92. excalidrawClipboard: "excalidraw/clipboard",
  93. excalidrawLibrary: "excalidrawlib",
  94. } as const;
  95. export const EXPORT_SOURCE = window.location.origin;
  96. // time in milliseconds
  97. export const IMAGE_RENDER_TIMEOUT = 500;
  98. export const TAP_TWICE_TIMEOUT = 300;
  99. export const TOUCH_CTX_MENU_TIMEOUT = 500;
  100. export const TITLE_TIMEOUT = 10000;
  101. export const TOAST_TIMEOUT = 5000;
  102. export const VERSION_TIMEOUT = 30000;
  103. export const SCROLL_TIMEOUT = 100;
  104. export const ZOOM_STEP = 0.1;
  105. export const HYPERLINK_TOOLTIP_DELAY = 300;
  106. // Report a user inactive after IDLE_THRESHOLD milliseconds
  107. export const IDLE_THRESHOLD = 60_000;
  108. // Report a user active each ACTIVE_THRESHOLD milliseconds
  109. export const ACTIVE_THRESHOLD = 3_000;
  110. export const MODES = {
  111. VIEW: "viewMode",
  112. ZEN: "zenMode",
  113. GRID: "gridMode",
  114. };
  115. export const THEME_FILTER = cssVariables.themeFilter;
  116. export const URL_QUERY_KEYS = {
  117. addLibrary: "addLibrary",
  118. } as const;
  119. export const URL_HASH_KEYS = {
  120. addLibrary: "addLibrary",
  121. } as const;
  122. export const DEFAULT_UI_OPTIONS: AppProps["UIOptions"] = {
  123. canvasActions: {
  124. changeViewBackgroundColor: true,
  125. clearCanvas: true,
  126. export: { saveFileToDisk: true },
  127. loadScene: true,
  128. saveToActiveFile: true,
  129. theme: true,
  130. saveAsImage: true,
  131. },
  132. };
  133. export const MQ_MAX_WIDTH_PORTRAIT = 730;
  134. export const MQ_MAX_WIDTH_LANDSCAPE = 1000;
  135. export const MQ_MAX_HEIGHT_LANDSCAPE = 500;
  136. export const MAX_DECIMALS_FOR_SVG_EXPORT = 2;
  137. export const EXPORT_SCALES = [1, 2, 3];
  138. export const DEFAULT_EXPORT_PADDING = 10; // px
  139. export const DEFAULT_MAX_IMAGE_WIDTH_OR_HEIGHT = 1440;
  140. export const ALLOWED_IMAGE_MIME_TYPES = [
  141. MIME_TYPES.png,
  142. MIME_TYPES.jpg,
  143. MIME_TYPES.svg,
  144. MIME_TYPES.gif,
  145. ] as const;
  146. export const MAX_ALLOWED_FILE_BYTES = 2 * 1024 * 1024;
  147. export const SVG_NS = "http://www.w3.org/2000/svg";
  148. export const ENCRYPTION_KEY_BITS = 128;
  149. export const VERSIONS = {
  150. excalidraw: 2,
  151. excalidrawLibrary: 2,
  152. } as const;
  153. export const BOUND_TEXT_PADDING = 5;