@dwelle/excalidraw 0.4.0-9db4535 → 0.4.0-9fa56da

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (143) hide show
  1. package/CHANGELOG.md +255 -1
  2. package/README.md +4 -0
  3. package/dist/excalidraw-assets/{vendor-2002fe1b8862917b36c1.js → vendor-d415b28e9024dee4bb1b.js} +2 -2
  4. package/dist/excalidraw-assets-dev/{vendor-e6df8519da951026ff69.js → vendor-a14cd58fa2db417e42b2.js} +6 -6
  5. package/dist/excalidraw.development.js +2123 -1783
  6. package/dist/excalidraw.production.min.js +1 -1
  7. package/package.json +7 -2
  8. package/types/actions/actionAddToLibrary.d.ts +84 -43
  9. package/types/actions/actionAlign.d.ts +33 -28
  10. package/types/actions/actionBoundText.d.ts +60 -32
  11. package/types/actions/actionCanvas.d.ts +436 -164
  12. package/types/actions/actionClipboard.d.ts +140 -74
  13. package/types/actions/actionDeleteSelected.d.ts +80 -42
  14. package/types/actions/actionDistribute.d.ts +11 -12
  15. package/types/actions/actionDuplicateSelection.d.ts +2 -3
  16. package/types/actions/actionElementLock.d.ts +58 -30
  17. package/types/actions/actionExport.d.ts +303 -177
  18. package/types/actions/actionFinalize.d.ts +56 -32
  19. package/types/actions/actionFlip.d.ts +8 -9
  20. package/types/actions/actionFrame.d.ts +423 -0
  21. package/types/actions/actionGroup.d.ts +250 -13
  22. package/types/actions/actionLinearEditor.d.ts +30 -17
  23. package/types/actions/actionMenu.d.ts +87 -47
  24. package/types/actions/actionNavigate.d.ts +1 -1
  25. package/types/actions/actionProperties.d.ts +370 -187
  26. package/types/actions/actionSelectAll.d.ts +123 -4
  27. package/types/actions/actionStyles.d.ts +32 -19
  28. package/types/actions/actionToggleGridMode.d.ts +30 -17
  29. package/types/actions/actionToggleObjectsSnapMode.d.ts +137 -0
  30. package/types/actions/actionToggleStats.d.ts +30 -17
  31. package/types/actions/actionToggleViewMode.d.ts +30 -17
  32. package/types/actions/actionToggleZenMode.d.ts +30 -17
  33. package/types/actions/actionZindex.d.ts +12 -12
  34. package/types/actions/index.d.ts +1 -0
  35. package/types/actions/shortcuts.d.ts +1 -1
  36. package/types/actions/types.d.ts +4 -3
  37. package/types/appState.d.ts +10 -15
  38. package/types/clients.d.ts +1 -5
  39. package/types/clipboard.d.ts +1 -0
  40. package/types/colors.d.ts +9 -9
  41. package/types/components/Actions.d.ts +4 -5
  42. package/types/components/App.d.ts +61 -28
  43. package/types/components/Avatar.d.ts +0 -1
  44. package/types/components/Button.d.ts +0 -1
  45. package/types/components/Card.d.ts +0 -1
  46. package/types/components/ColorPicker/ColorInput.d.ts +3 -1
  47. package/types/components/ColorPicker/keyboardNavHandlers.d.ts +0 -1
  48. package/types/components/DefaultSidebar.d.ts +0 -1
  49. package/types/components/Dialog.d.ts +2 -1
  50. package/types/components/ExcalidrawLogo.d.ts +15 -0
  51. package/types/components/EyeDropper.d.ts +18 -8
  52. package/types/components/FilledButton.d.ts +2 -1
  53. package/types/components/HintViewer.d.ts +3 -4
  54. package/types/components/JSONExportDialog.d.ts +1 -1
  55. package/types/components/LaserTool/LaserPathManager.d.ts +28 -0
  56. package/types/components/LaserTool/LaserPointerButton.d.ts +10 -0
  57. package/types/components/LaserTool/LaserTool.d.ts +7 -0
  58. package/types/components/LayerUI.d.ts +6 -2
  59. package/types/components/LibraryMenuHeaderContent.d.ts +0 -1
  60. package/types/components/LibraryUnit.d.ts +0 -1
  61. package/types/components/LoadingMessage.d.ts +0 -1
  62. package/types/components/MobileMenu.d.ts +4 -3
  63. package/types/components/OverwriteConfirm/OverwriteConfirm.d.ts +17 -0
  64. package/types/components/OverwriteConfirm/OverwriteConfirmActions.d.ts +17 -0
  65. package/types/components/OverwriteConfirm/OverwriteConfirmState.d.ts +22 -0
  66. package/types/components/Section.d.ts +1 -1
  67. package/types/components/Sidebar/Sidebar.d.ts +1 -1
  68. package/types/components/Sidebar/SidebarTab.d.ts +0 -1
  69. package/types/components/Sidebar/SidebarTabTrigger.d.ts +0 -1
  70. package/types/components/Sidebar/SidebarTabTriggers.d.ts +0 -1
  71. package/types/components/Sidebar/SidebarTabs.d.ts +0 -1
  72. package/types/components/Stack.d.ts +2 -2
  73. package/types/components/ToolButton.d.ts +2 -1
  74. package/types/components/Trans.d.ts +2 -1
  75. package/types/components/canvases/InteractiveCanvas.d.ts +27 -0
  76. package/types/components/canvases/StaticCanvas.d.ts +18 -0
  77. package/types/components/canvases/index.d.ts +3 -0
  78. package/types/components/dropdownMenu/DropdownMenu.d.ts +9 -5
  79. package/types/components/dropdownMenu/DropdownMenuItem.d.ts +2 -1
  80. package/types/components/dropdownMenu/DropdownMenuItemCustom.d.ts +2 -1
  81. package/types/components/dropdownMenu/DropdownMenuItemLink.d.ts +2 -1
  82. package/types/components/dropdownMenu/DropdownMenuTrigger.d.ts +3 -2
  83. package/types/components/dropdownMenu/common.d.ts +1 -1
  84. package/types/components/icons.d.ts +6 -0
  85. package/types/components/live-collaboration/LiveCollaborationTrigger.d.ts +0 -1
  86. package/types/components/main-menu/MainMenu.d.ts +9 -5
  87. package/types/components/welcome-screen/WelcomeScreen.Center.d.ts +0 -1
  88. package/types/components/welcome-screen/WelcomeScreen.d.ts +0 -1
  89. package/types/constants.d.ts +35 -3
  90. package/types/context/tunnels.d.ts +1 -0
  91. package/types/data/transform.d.ts +71 -0
  92. package/types/data/url.d.ts +7 -0
  93. package/types/element/Hyperlink.d.ts +40 -23
  94. package/types/element/binding.d.ts +2 -1
  95. package/types/element/bounds.d.ts +30 -6
  96. package/types/element/collision.d.ts +7 -7
  97. package/types/element/dragElements.d.ts +12 -2
  98. package/types/element/embeddable.d.ts +153 -0
  99. package/types/element/index.d.ts +3 -2
  100. package/types/element/linearElementEditor.d.ts +33 -20
  101. package/types/element/newElement.d.ts +15 -6
  102. package/types/element/resizeElements.d.ts +2 -2
  103. package/types/element/sizeHelpers.d.ts +8 -1
  104. package/types/element/textElement.d.ts +5 -7
  105. package/types/element/textWysiwyg.d.ts +1 -1
  106. package/types/element/transformHandles.d.ts +10 -3
  107. package/types/element/typeChecks.d.ts +3 -1
  108. package/types/element/types.d.ts +19 -3
  109. package/types/frame.d.ts +40 -0
  110. package/types/groups.d.ts +15 -11
  111. package/types/history.d.ts +3 -3
  112. package/types/hooks/useOutsideClick.d.ts +0 -1
  113. package/types/hooks/useScrollPosition.d.ts +0 -1
  114. package/types/hooks/useStable.d.ts +1 -0
  115. package/types/i18n.d.ts +5 -2
  116. package/types/keys.d.ts +4 -0
  117. package/types/math.d.ts +3 -0
  118. package/types/packages/excalidraw/example/initialData.d.ts +182 -64
  119. package/types/packages/excalidraw/index.d.ts +3 -1
  120. package/types/packages/excalidraw/webpack.dev.config.d.ts +5 -2
  121. package/types/packages/excalidraw/webpack.prod.config.d.ts +3 -0
  122. package/types/packages/utils.d.ts +4 -1
  123. package/types/renderer/renderElement.d.ts +11 -22
  124. package/types/renderer/renderScene.d.ts +19 -27
  125. package/types/renderer/renderSnaps.d.ts +2 -0
  126. package/types/renderer/roundRect.d.ts +1 -1
  127. package/types/scene/Renderer.d.ts +25 -0
  128. package/types/scene/Scene.d.ts +23 -1
  129. package/types/scene/Shape.d.ts +12 -0
  130. package/types/scene/ShapeCache.d.ts +20 -0
  131. package/types/scene/export.d.ts +35 -9
  132. package/types/scene/scroll.d.ts +1 -1
  133. package/types/scene/scrollbars.d.ts +2 -6
  134. package/types/scene/selection.d.ts +26 -5
  135. package/types/scene/types.d.ts +66 -31
  136. package/types/snapping.d.ts +108 -0
  137. package/types/types.d.ts +130 -25
  138. package/types/utility-types.d.ts +3 -1
  139. package/types/utils.d.ts +60 -23
  140. package/types/zindex.d.ts +4 -4
  141. /package/dist/excalidraw-assets/{vendor-2002fe1b8862917b36c1.js.LICENSE.txt → vendor-d415b28e9024dee4bb1b.js.LICENSE.txt} +0 -0
  142. /package/types/packages/excalidraw/dist/excalidraw-assets/{vendor-2002fe1b8862917b36c1.d.ts → vendor-d415b28e9024dee4bb1b.d.ts} +0 -0
  143. /package/types/packages/excalidraw/dist/excalidraw-assets-dev/{vendor-e6df8519da951026ff69.d.ts → vendor-a14cd58fa2db417e42b2.d.ts} +0 -0
package/types/types.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import React from "react";
2
- import { PointerType, ExcalidrawLinearElement, NonDeletedExcalidrawElement, NonDeleted, TextAlign, ExcalidrawElement, GroupId, ExcalidrawBindableElement, Arrowhead, ChartType, FontFamilyValues, FileId, ExcalidrawImageElement, Theme, StrokeRoundness } from "./element/types";
3
- import { SHAPES } from "./shapes";
2
+ import { PointerType, ExcalidrawLinearElement, NonDeletedExcalidrawElement, NonDeleted, TextAlign, ExcalidrawElement, GroupId, ExcalidrawBindableElement, Arrowhead, ChartType, FontFamilyValues, FileId, ExcalidrawImageElement, Theme, StrokeRoundness, ExcalidrawFrameElement, ExcalidrawEmbeddableElement } from "./element/types";
4
3
  import { Point as RoughPoint } from "roughjs/bin/geometry";
5
4
  import { LinearElementEditor } from "./element/linearElementEditor";
6
5
  import { SuggestedBinding } from "./element/binding";
@@ -16,13 +15,11 @@ import Library from "./data/library";
16
15
  import type { FileSystemHandle } from "./data/filesystem";
17
16
  import type { IMAGE_MIME_TYPES, MIME_TYPES } from "./constants";
18
17
  import { ContextMenuItems } from "./components/ContextMenu";
18
+ import { SnapLine } from "./snapping";
19
19
  import { Merge, ForwardRef, ValueOf } from "./utility-types";
20
20
  export type Point = Readonly<RoughPoint>;
21
21
  export type Collaborator = {
22
- pointer?: {
23
- x: number;
24
- y: number;
25
- };
22
+ pointer?: CollaboratorPointer;
26
23
  button?: "up" | "down";
27
24
  selectedElementIds?: AppState["selectedElementIds"];
28
25
  username?: string | null;
@@ -34,6 +31,18 @@ export type Collaborator = {
34
31
  avatarUrl?: string;
35
32
  id?: string;
36
33
  };
34
+ export type CollaboratorPointer = {
35
+ x: number;
36
+ y: number;
37
+ tool: "pointer" | "laser";
38
+ /**
39
+ * Whether to render cursor + username. Useful when you only want to render
40
+ * laser trail.
41
+ *
42
+ * @default true
43
+ */
44
+ renderPointer?: boolean;
45
+ };
37
46
  export type DataURL = string & {
38
47
  _brand: "DataURL";
39
48
  };
@@ -56,15 +65,55 @@ export type BinaryFileData = {
56
65
  };
57
66
  export type BinaryFileMetadata = Omit<BinaryFileData, "dataURL">;
58
67
  export type BinaryFiles = Record<ExcalidrawElement["id"], BinaryFileData>;
59
- export type LastActiveTool = {
60
- type: typeof SHAPES[number]["value"] | "eraser" | "hand";
68
+ export type ToolType = "selection" | "rectangle" | "diamond" | "ellipse" | "arrow" | "line" | "freedraw" | "text" | "image" | "eraser" | "hand" | "frame" | "embeddable" | "laser";
69
+ export type ActiveTool = {
70
+ type: ToolType;
61
71
  customType: null;
62
72
  } | {
63
73
  type: "custom";
64
74
  customType: string;
65
- } | null;
75
+ };
66
76
  export type SidebarName = string;
67
77
  export type SidebarTabName = string;
78
+ type _CommonCanvasAppState = {
79
+ zoom: AppState["zoom"];
80
+ scrollX: AppState["scrollX"];
81
+ scrollY: AppState["scrollY"];
82
+ width: AppState["width"];
83
+ height: AppState["height"];
84
+ viewModeEnabled: AppState["viewModeEnabled"];
85
+ editingGroupId: AppState["editingGroupId"];
86
+ selectedElementIds: AppState["selectedElementIds"];
87
+ frameToHighlight: AppState["frameToHighlight"];
88
+ offsetLeft: AppState["offsetLeft"];
89
+ offsetTop: AppState["offsetTop"];
90
+ theme: AppState["theme"];
91
+ pendingImageElementId: AppState["pendingImageElementId"];
92
+ };
93
+ export type StaticCanvasAppState = Readonly<_CommonCanvasAppState & {
94
+ shouldCacheIgnoreZoom: AppState["shouldCacheIgnoreZoom"];
95
+ exportScale: AppState["exportScale"];
96
+ selectedElementsAreBeingDragged: AppState["selectedElementsAreBeingDragged"];
97
+ gridSize: AppState["gridSize"];
98
+ frameRendering: AppState["frameRendering"];
99
+ }>;
100
+ export type InteractiveCanvasAppState = Readonly<_CommonCanvasAppState & {
101
+ activeEmbeddable: AppState["activeEmbeddable"];
102
+ editingLinearElement: AppState["editingLinearElement"];
103
+ selectionElement: AppState["selectionElement"];
104
+ selectedGroupIds: AppState["selectedGroupIds"];
105
+ selectedLinearElement: AppState["selectedLinearElement"];
106
+ multiElement: AppState["multiElement"];
107
+ isBindingEnabled: AppState["isBindingEnabled"];
108
+ suggestedBindings: AppState["suggestedBindings"];
109
+ isRotating: AppState["isRotating"];
110
+ elementsToHighlight: AppState["elementsToHighlight"];
111
+ openSidebar: AppState["openSidebar"];
112
+ showHyperlinkPopup: AppState["showHyperlinkPopup"];
113
+ collaborators: AppState["collaborators"];
114
+ snapLines: AppState["snapLines"];
115
+ zenModeEnabled: AppState["zenModeEnabled"];
116
+ }>;
68
117
  export type AppState = {
69
118
  contextMenu: {
70
119
  items: ContextMenuItems;
@@ -74,6 +123,10 @@ export type AppState = {
74
123
  showWelcomeScreen: boolean;
75
124
  isLoading: boolean;
76
125
  errorMessage: React.ReactNode;
126
+ activeEmbeddable: {
127
+ element: NonDeletedExcalidrawElement;
128
+ state: "hover" | "active";
129
+ } | null;
77
130
  draggingElement: NonDeletedExcalidrawElement | null;
78
131
  resizingElement: NonDeletedExcalidrawElement | null;
79
132
  multiElement: NonDeleted<ExcalidrawLinearElement> | null;
@@ -81,6 +134,15 @@ export type AppState = {
81
134
  isBindingEnabled: boolean;
82
135
  startBoundElement: NonDeleted<ExcalidrawBindableElement> | null;
83
136
  suggestedBindings: SuggestedBinding[];
137
+ frameToHighlight: NonDeleted<ExcalidrawFrameElement> | null;
138
+ frameRendering: {
139
+ enabled: boolean;
140
+ name: boolean;
141
+ outline: boolean;
142
+ clip: boolean;
143
+ };
144
+ editingFrame: string | null;
145
+ elementsToHighlight: NonDeleted<ExcalidrawElement>[] | null;
84
146
  editingElement: NonDeletedExcalidrawElement | null;
85
147
  editingLinearElement: LinearElementEditor | null;
86
148
  activeTool: {
@@ -88,15 +150,9 @@ export type AppState = {
88
150
  * indicates a previous tool we should revert back to if we deselect the
89
151
  * currently active tool. At the moment applies to `eraser` and `hand` tool.
90
152
  */
91
- lastActiveTool: LastActiveTool;
153
+ lastActiveTool: ActiveTool | null;
92
154
  locked: boolean;
93
- } & ({
94
- type: typeof SHAPES[number]["value"] | "eraser" | "hand";
95
- customType: null;
96
- } | {
97
- type: "custom";
98
- customType: string;
99
- });
155
+ } & ActiveTool;
100
156
  penMode: boolean;
101
157
  penDetected: boolean;
102
158
  exportBackground: boolean;
@@ -141,12 +197,13 @@ export type AppState = {
141
197
  */
142
198
  defaultSidebarDockedPreference: boolean;
143
199
  lastPointerDownWith: PointerType;
144
- selectedElementIds: {
145
- [id: string]: boolean;
146
- };
200
+ selectedElementIds: Readonly<{
201
+ [id: string]: true;
202
+ }>;
147
203
  previousSelectedElementIds: {
148
- [id: string]: boolean;
204
+ [id: string]: true;
149
205
  };
206
+ selectedElementsAreBeingDragged: boolean;
150
207
  shouldCacheIgnoreZoom: boolean;
151
208
  toast: {
152
209
  message: string;
@@ -183,6 +240,12 @@ export type AppState = {
183
240
  pendingImageElementId: ExcalidrawImageElement["id"] | null;
184
241
  showHyperlinkPopup: false | "info" | "editor";
185
242
  selectedLinearElement: LinearElementEditor | null;
243
+ snapLines: readonly SnapLine[];
244
+ originSnapOffset: {
245
+ x: number;
246
+ y: number;
247
+ } | null;
248
+ objectsSnapModeEnabled: boolean;
186
249
  };
187
250
  export type UIAppState = Omit<AppState, "suggestedBindings" | "startBoundElement" | "cursorButton" | "scrollX" | "scrollY">;
188
251
  export type NormalizedZoomValue = number & {
@@ -248,6 +311,7 @@ export interface ExcalidrawProps {
248
311
  pointer: {
249
312
  x: number;
250
313
  y: number;
314
+ tool: "pointer" | "laser";
251
315
  };
252
316
  button: "down" | "up";
253
317
  pointersMap: Gesture["pointers"];
@@ -258,6 +322,7 @@ export interface ExcalidrawProps {
258
322
  viewModeEnabled?: boolean;
259
323
  zenModeEnabled?: boolean;
260
324
  gridModeEnabled?: boolean;
325
+ objectsSnapModeEnabled?: boolean;
261
326
  libraryReturnUrl?: string;
262
327
  theme?: Theme;
263
328
  name?: string;
@@ -274,6 +339,16 @@ export interface ExcalidrawProps {
274
339
  onPointerDown?: (activeTool: AppState["activeTool"], pointerDownState: PointerDownState) => void;
275
340
  onScrollChange?: (scrollX: number, scrollY: number) => void;
276
341
  children?: React.ReactNode;
342
+ validateEmbeddable?: boolean | string[] | RegExp | RegExp[] | ((link: string) => boolean | undefined);
343
+ renderEmbeddable?: (element: NonDeleted<ExcalidrawEmbeddableElement>, appState: AppState) => JSX.Element | null;
344
+ activeTool?: {
345
+ type: ToolType;
346
+ } | {
347
+ type: "custom";
348
+ customType: string;
349
+ };
350
+ interactive?: boolean;
351
+ ui?: boolean;
277
352
  }
278
353
  export type SceneData = {
279
354
  elements?: ImportedDataState["elements"];
@@ -288,8 +363,8 @@ export declare enum UserIdleState {
288
363
  }
289
364
  export type ExportOpts = {
290
365
  saveFileToDisk?: boolean;
291
- onExportToBackend?: (exportedElements: readonly NonDeletedExcalidrawElement[], appState: UIAppState, files: BinaryFiles, canvas: HTMLCanvasElement | null) => void;
292
- renderCustomUI?: (exportedElements: readonly NonDeletedExcalidrawElement[], appState: UIAppState, files: BinaryFiles, canvas: HTMLCanvasElement | null) => JSX.Element;
366
+ onExportToBackend?: (exportedElements: readonly NonDeletedExcalidrawElement[], appState: UIAppState, files: BinaryFiles, canvas: HTMLCanvasElement) => void;
367
+ renderCustomUI?: (exportedElements: readonly NonDeletedExcalidrawElement[], appState: UIAppState, files: BinaryFiles, canvas: HTMLCanvasElement) => JSX.Element;
293
368
  };
294
369
  type CanvasActions = Partial<{
295
370
  changeViewBackgroundColor: boolean;
@@ -321,7 +396,9 @@ export type AppProps = Merge<ExcalidrawProps, {
321
396
  * in the app, eg Manager. Factored out into a separate type to keep DRY. */
322
397
  export type AppClassProperties = {
323
398
  props: AppProps;
324
- canvas: HTMLCanvasElement | null;
399
+ interactiveCanvas: HTMLCanvasElement | null;
400
+ /** static canvas */
401
+ canvas: HTMLCanvasElement;
325
402
  focusContainer(): void;
326
403
  library: Library;
327
404
  imageCache: Map<FileId, {
@@ -336,6 +413,8 @@ export type AppClassProperties = {
336
413
  onInsertElements: App["onInsertElements"];
337
414
  onExportImage: App["onExportImage"];
338
415
  lastViewportPosition: App["lastViewportPosition"];
416
+ togglePenMode: App["togglePenMode"];
417
+ setActiveTool: App["setActiveTool"];
339
418
  };
340
419
  export type PointerDownState = Readonly<{
341
420
  origin: Readonly<{
@@ -419,9 +498,15 @@ export type ExcalidrawImperativeAPI = {
419
498
  setCursor: InstanceType<typeof App>["setCursor"];
420
499
  resetCursor: InstanceType<typeof App>["resetCursor"];
421
500
  toggleSidebar: InstanceType<typeof App>["toggleSidebar"];
501
+ /**
502
+ * Disables rendering of frames (including element clipping), but currently
503
+ * the frames are still interactive in edit mode. As such, this API should be
504
+ * used in conjunction with view mode (props.viewModeEnabled).
505
+ */
506
+ updateFrameRendering: InstanceType<typeof App>["updateFrameRendering"];
422
507
  app: InstanceType<typeof App>;
423
508
  onChange: (callback: (elements: readonly ExcalidrawElement[], appState: AppState, files: BinaryFiles) => void) => UnsubscribeCallback;
424
- onPointerDown: (callback: (activeTool: AppState["activeTool"], pointerDownState: PointerDownState, event: React.PointerEvent<HTMLCanvasElement>) => void) => UnsubscribeCallback;
509
+ onPointerDown: (callback: (activeTool: AppState["activeTool"], pointerDownState: PointerDownState, event: React.PointerEvent<HTMLElement>) => void) => UnsubscribeCallback;
425
510
  onPointerUp: (callback: (activeTool: AppState["activeTool"], pointerDownState: PointerDownState, event: PointerEvent) => void) => UnsubscribeCallback;
426
511
  };
427
512
  export type Device = Readonly<{
@@ -431,4 +516,24 @@ export type Device = Readonly<{
431
516
  canDeviceFitSidebar: boolean;
432
517
  isLandscape: boolean;
433
518
  }>;
519
+ type FrameNameBounds = {
520
+ x: number;
521
+ y: number;
522
+ width: number;
523
+ height: number;
524
+ angle: number;
525
+ };
526
+ export type FrameNameBoundsCache = {
527
+ get: (frameElement: ExcalidrawFrameElement) => FrameNameBounds | null;
528
+ _cache: Map<string, FrameNameBounds & {
529
+ zoom: AppState["zoom"]["value"];
530
+ versionNonce: ExcalidrawFrameElement["versionNonce"];
531
+ }>;
532
+ };
533
+ export type KeyboardModifiersObject = {
534
+ ctrlKey: boolean;
535
+ shiftKey: boolean;
536
+ altKey: boolean;
537
+ metaKey: boolean;
538
+ };
434
539
  export {};
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  export type Mutable<T> = {
3
2
  -readonly [P in keyof T]: T[P];
4
3
  };
@@ -20,3 +19,6 @@ export type SignatureType<T> = T extends (...args: infer R) => any ? R : never;
20
19
  export type CallableType<T extends (...args: any[]) => any> = (...args: SignatureType<T>) => ReturnType<T>;
21
20
  export type ForwardRef<T, P = any> = Parameters<CallableType<React.ForwardRefRenderFunction<T, P>>>[1];
22
21
  export type ExtractSetType<T extends Set<any>> = T extends Set<infer U> ? U : never;
22
+ export type SameType<T, U> = T extends U ? (U extends T ? true : false) : false;
23
+ export type Assert<T extends true> = T;
24
+ export type NestedKeyOf<T, K = keyof T> = K extends keyof T & (string | number) ? `${K}` | (T[K] extends object ? `${K}.${NestedKeyOf<T[K]>}` : never) : never;
package/types/utils.d.ts CHANGED
@@ -1,12 +1,12 @@
1
1
  import { EVENT } from "./constants";
2
- import { FontFamilyValues, FontString } from "./element/types";
3
- import { AppState, LastActiveTool, Zoom } from "./types";
4
- import { SHAPES } from "./shapes";
2
+ import { FontFamilyValues, FontString, NonDeletedExcalidrawElement } from "./element/types";
3
+ import { ActiveTool, AppState, ToolType, Zoom } from "./types";
5
4
  export declare const setDateTimeForTests: (dateTime: string) => void;
6
5
  export declare const getDateTime: () => string;
7
6
  export declare const capitalizeString: (str: string) => string;
8
7
  export declare const isToolIcon: (target: Element | EventTarget | null) => target is HTMLElement;
9
8
  export declare const isInputLike: (target: Element | EventTarget | null) => target is HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement | HTMLBRElement | HTMLDivElement;
9
+ export declare const isInteractive: (target: Element | EventTarget | null) => boolean;
10
10
  export declare const isWritableElement: (target: Element | EventTarget | null) => target is HTMLInputElement | HTMLTextAreaElement | HTMLBRElement | HTMLDivElement;
11
11
  export declare const getFontFamilyString: ({ fontFamily, }: {
12
12
  fontFamily: FontFamilyValues;
@@ -29,43 +29,70 @@ export declare const throttleRAF: <T extends any[]>(fn: (...args: T) => void, op
29
29
  cancel(): void;
30
30
  };
31
31
  /**
32
- * Compute new values based on the same ease function and trigger the
33
- * callback through a requestAnimationFrame call
32
+ * Exponential ease-out method
34
33
  *
35
- * use `opts` to define a duration and/or an easeFn
34
+ * @param {number} k - The value to be tweened.
35
+ * @returns {number} The tweened value.
36
+ */
37
+ export declare const easeOut: (k: number) => number;
38
+ /**
39
+ * Animates values from `fromValues` to `toValues` using the requestAnimationFrame API.
40
+ * Executes the `onStep` callback on each step with the interpolated values.
41
+ * Returns a function that can be called to cancel the animation.
42
+ *
43
+ * @example
44
+ * // Example usage:
45
+ * const fromValues = { x: 0, y: 0 };
46
+ * const toValues = { x: 100, y: 200 };
47
+ * const onStep = ({x, y}) => {
48
+ * setState(x, y)
49
+ * };
50
+ * const onCancel = () => {
51
+ * console.log("Animation canceled");
52
+ * };
36
53
  *
37
- * for example:
38
- * ```ts
39
- * easeToValuesRAF([10, 20, 10], [0, 0, 0], (a, b, c) => setState(a,b, c))
40
- * ```
54
+ * const cancelAnimation = easeToValuesRAF({
55
+ * fromValues,
56
+ * toValues,
57
+ * onStep,
58
+ * onCancel,
59
+ * });
41
60
  *
42
- * @param fromValues The initial values, must be numeric
43
- * @param toValues The destination values, must also be numeric
44
- * @param callback The callback receiving the values
45
- * @param opts default to 250ms duration and the easeOut function
61
+ * // To cancel the animation:
62
+ * cancelAnimation();
46
63
  */
47
- export declare const easeToValuesRAF: (fromValues: number[], toValues: number[], callback: (...values: number[]) => void, opts?: {
64
+ export declare const easeToValuesRAF: <T extends Record<keyof T, number>, K extends keyof T>({ fromValues, toValues, onStep, duration, interpolateValue, onStart, onEnd, onCancel, }: {
65
+ fromValues: T;
66
+ toValues: T;
67
+ /**
68
+ * Interpolate a single value.
69
+ * Return undefined to be handled by the default interpolator.
70
+ */
71
+ interpolateValue?: ((fromValue: number, toValue: number, progress: number, key: K) => number | undefined) | undefined;
72
+ onStep: (values: T) => void;
48
73
  duration?: number | undefined;
49
- easeFn?: ((value: number) => number) | undefined;
50
- } | undefined) => () => void;
74
+ onStart?: (() => void) | undefined;
75
+ onEnd?: (() => void) | undefined;
76
+ onCancel?: (() => void) | undefined;
77
+ }) => () => void;
51
78
  export declare const chunk: <T extends unknown>(array: readonly T[], size: number) => T[][];
52
79
  export declare const selectNode: (node: Element) => void;
53
80
  export declare const removeSelection: () => void;
54
81
  export declare const distance: (x: number, y: number) => number;
55
82
  export declare const updateActiveTool: (appState: Pick<AppState, "activeTool">, data: ({
56
- type: (typeof SHAPES)[number]["value"] | "eraser" | "hand";
83
+ type: ToolType;
57
84
  locked?: boolean;
58
85
  } | {
59
86
  type: "custom";
60
87
  customType: string;
61
88
  locked?: boolean;
62
89
  }) & {
63
- lastActiveToolBeforeEraser?: LastActiveTool;
90
+ lastActiveToolBeforeEraser?: ActiveTool | null;
64
91
  }) => AppState["activeTool"];
65
- export declare const resetCursor: (canvas: HTMLCanvasElement | null) => void;
66
- export declare const setCursor: (canvas: HTMLCanvasElement | null, cursor: string) => void;
67
- export declare const setEraserCursor: (canvas: HTMLCanvasElement | null, theme: AppState["theme"]) => void;
68
- export declare const setCursorForShape: (canvas: HTMLCanvasElement | null, appState: Pick<AppState, "activeTool" | "theme">) => void;
92
+ export declare const resetCursor: (interactiveCanvas: HTMLCanvasElement | null) => void;
93
+ export declare const setCursor: (interactiveCanvas: HTMLCanvasElement | null, cursor: string) => void;
94
+ export declare const setEraserCursor: (interactiveCanvas: HTMLCanvasElement | null, theme: AppState["theme"]) => void;
95
+ export declare const setCursorForShape: (interactiveCanvas: HTMLCanvasElement | null, appState: Pick<AppState, "activeTool" | "theme">) => void;
69
96
  export declare const isFullScreen: () => boolean;
70
97
  export declare const allowFullScreen: () => Promise<void>;
71
98
  export declare const exitFullScreen: () => Promise<void>;
@@ -156,9 +183,19 @@ export declare const wrapEvent: <T extends Event>(name: EVENT, nativeEvent: T) =
156
183
  export declare const updateObject: <T extends Record<string, any>>(obj: T, updates: Partial<T>) => T;
157
184
  export declare const isPrimitive: (val: any) => boolean;
158
185
  export declare const getFrame: () => "top" | "iframe";
186
+ export declare const isRunningInIframe: () => boolean;
159
187
  export declare const isPromiseLike: (value: any) => value is Promise<any>;
160
188
  export declare const queryFocusableElements: (container: HTMLElement | null) => HTMLElement[];
161
189
  export declare const isShallowEqual: <T extends Record<string, any>, I extends keyof T>(objA: T, objB: T, comparators?: Record<I, (a: T[I], b: T[I]) => boolean> | undefined, debug?: boolean) => boolean;
162
190
  export declare const composeEventHandlers: <E>(originalEventHandler?: ((event: E) => void) | undefined, ourEventHandler?: ((event: E) => void) | undefined, { checkForDefaultPrevented }?: {
163
191
  checkForDefaultPrevented?: boolean | undefined;
164
192
  }) => (event: E) => void;
193
+ export declare const isOnlyExportingSingleFrame: (elements: readonly NonDeletedExcalidrawElement[]) => boolean;
194
+ export declare const assertNever: (value: never, message: string, softAssert?: boolean) => never;
195
+ /**
196
+ * Memoizes on values of `opts` object (strict equality).
197
+ */
198
+ export declare const memoize: <T extends Record<string, any>, R extends unknown>(func: (opts: T) => R) => ((opts: T) => R) & {
199
+ clear: () => void;
200
+ };
201
+ export declare const isRenderThrottlingEnabled: () => boolean;
package/types/zindex.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { ExcalidrawElement } from "./element/types";
2
2
  import { AppState } from "./types";
3
- export declare const moveOneLeft: (elements: readonly ExcalidrawElement[], appState: AppState) => (import("./element/types").ExcalidrawLinearElement | import("./element/types").ExcalidrawSelectionElement | import("./element/types").ExcalidrawRectangleElement | import("./element/types").ExcalidrawDiamondElement | import("./element/types").ExcalidrawEllipseElement | import("./element/types").ExcalidrawImageElement | import("./element/types").ExcalidrawTextElement | import("./element/types").ExcalidrawFreeDrawElement)[];
4
- export declare const moveOneRight: (elements: readonly ExcalidrawElement[], appState: AppState) => (import("./element/types").ExcalidrawLinearElement | import("./element/types").ExcalidrawSelectionElement | import("./element/types").ExcalidrawRectangleElement | import("./element/types").ExcalidrawDiamondElement | import("./element/types").ExcalidrawEllipseElement | import("./element/types").ExcalidrawImageElement | import("./element/types").ExcalidrawTextElement | import("./element/types").ExcalidrawFreeDrawElement)[];
5
- export declare const moveAllLeft: (elements: readonly ExcalidrawElement[], appState: AppState) => readonly ExcalidrawElement[];
6
- export declare const moveAllRight: (elements: readonly ExcalidrawElement[], appState: AppState) => readonly ExcalidrawElement[];
3
+ export declare const moveOneLeft: (elements: readonly ExcalidrawElement[], appState: AppState, elementsToBeMoved?: readonly ExcalidrawElement[]) => ExcalidrawElement[];
4
+ export declare const moveOneRight: (elements: readonly ExcalidrawElement[], appState: AppState, elementsToBeMoved?: readonly ExcalidrawElement[]) => ExcalidrawElement[];
5
+ export declare const moveAllLeft: (elements: readonly ExcalidrawElement[], appState: AppState, elementsToBeMoved?: readonly ExcalidrawElement[]) => ExcalidrawElement[];
6
+ export declare const moveAllRight: (elements: readonly ExcalidrawElement[], appState: AppState, elementsToBeMoved?: readonly ExcalidrawElement[]) => ExcalidrawElement[];