@zsviczian/excalidraw 0.17.1-obsidian-20 → 0.17.1-obsidian-21

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 (82) hide show
  1. package/dist/excalidraw.development.js +190 -80
  2. package/dist/excalidraw.production.min.js +1 -1
  3. package/dist/styles.development.css +78 -50
  4. package/dist/styles.production.css +5 -5
  5. package/package.json +2 -1
  6. package/types/excalidraw/actions/actionAddToLibrary.d.ts +4 -4
  7. package/types/excalidraw/actions/actionAlign.d.ts +20 -20
  8. package/types/excalidraw/actions/actionBoundText.d.ts +7 -7
  9. package/types/excalidraw/actions/actionCanvas.d.ts +65 -65
  10. package/types/excalidraw/actions/actionClipboard.d.ts +24 -24
  11. package/types/excalidraw/actions/actionDeleteSelected.d.ts +8 -8
  12. package/types/excalidraw/actions/actionDistribute.d.ts +8 -8
  13. package/types/excalidraw/actions/actionDuplicateSelection.d.ts +5 -6
  14. package/types/excalidraw/actions/actionElementLock.d.ts +8 -8
  15. package/types/excalidraw/actions/actionExport.d.ts +32 -32
  16. package/types/excalidraw/actions/actionFinalize.d.ts +8 -8
  17. package/types/excalidraw/actions/actionFlip.d.ts +9 -9
  18. package/types/excalidraw/actions/actionFrame.d.ts +14 -202
  19. package/types/excalidraw/actions/actionGroup.d.ts +11 -387
  20. package/types/excalidraw/actions/actionHistory.d.ts +3 -2
  21. package/types/excalidraw/actions/actionLinearEditor.d.ts +2 -2
  22. package/types/excalidraw/actions/actionLink.d.ts +5 -5
  23. package/types/excalidraw/actions/actionMenu.d.ts +8 -8
  24. package/types/excalidraw/actions/actionNavigate.d.ts +3 -3
  25. package/types/excalidraw/actions/actionProperties.d.ts +32 -32
  26. package/types/excalidraw/actions/actionSelectAll.d.ts +4 -4
  27. package/types/excalidraw/actions/actionStyles.d.ts +9 -12
  28. package/types/excalidraw/actions/actionToggleGridMode.d.ts +6 -4
  29. package/types/excalidraw/actions/actionToggleObjectsSnapMode.d.ts +4 -4
  30. package/types/excalidraw/actions/actionToggleStats.d.ts +4 -4
  31. package/types/excalidraw/actions/actionToggleViewMode.d.ts +4 -4
  32. package/types/excalidraw/actions/actionToggleZenMode.d.ts +4 -4
  33. package/types/excalidraw/actions/actionZindex.d.ts +18 -19
  34. package/types/excalidraw/actions/manager.d.ts +3 -3
  35. package/types/excalidraw/actions/types.d.ts +4 -4
  36. package/types/excalidraw/appState.d.ts +4 -4
  37. package/types/excalidraw/change.d.ts +191 -0
  38. package/types/excalidraw/components/App.d.ts +22 -8
  39. package/types/excalidraw/components/RadioGroup.d.ts +2 -1
  40. package/types/excalidraw/components/ToolButton.d.ts +1 -0
  41. package/types/excalidraw/components/canvases/InteractiveCanvas.d.ts +2 -1
  42. package/types/excalidraw/components/dropdownMenu/DropdownMenuItemContentRadio.d.ts +17 -0
  43. package/types/excalidraw/components/icons.d.ts +4 -0
  44. package/types/excalidraw/components/main-menu/DefaultItems.d.ts +12 -2
  45. package/types/excalidraw/constants.d.ts +3 -0
  46. package/types/excalidraw/data/reconcile.d.ts +6 -0
  47. package/types/excalidraw/data/restore.d.ts +3 -3
  48. package/types/excalidraw/data/transform.d.ts +1 -1
  49. package/types/excalidraw/data/url.d.ts +1 -0
  50. package/types/excalidraw/element/binding.d.ts +52 -9
  51. package/types/excalidraw/element/bounds.d.ts +0 -1
  52. package/types/excalidraw/element/collision.d.ts +14 -19
  53. package/types/excalidraw/element/embeddable.d.ts +7 -4
  54. package/types/excalidraw/element/index.d.ts +0 -1
  55. package/types/excalidraw/element/linearElementEditor.d.ts +12 -12
  56. package/types/excalidraw/element/mutateElement.d.ts +1 -2
  57. package/types/excalidraw/element/newElement.d.ts +1 -1
  58. package/types/excalidraw/element/resizeElements.d.ts +1 -1
  59. package/types/excalidraw/element/resizeTest.d.ts +4 -4
  60. package/types/excalidraw/element/textElement.d.ts +1 -2
  61. package/types/excalidraw/element/transformHandles.d.ts +22 -4
  62. package/types/excalidraw/element/typeChecks.d.ts +2 -2
  63. package/types/excalidraw/element/types.d.ts +22 -6
  64. package/types/excalidraw/errors.d.ts +3 -0
  65. package/types/excalidraw/fractionalIndex.d.ts +40 -0
  66. package/types/excalidraw/frame.d.ts +1 -1
  67. package/types/excalidraw/groups.d.ts +2 -0
  68. package/types/excalidraw/history.d.ts +34 -46
  69. package/types/excalidraw/hooks/useEmitter.d.ts +2 -0
  70. package/types/excalidraw/index.d.ts +2 -0
  71. package/types/excalidraw/renderer/interactiveScene.d.ts +1 -1
  72. package/types/excalidraw/scene/Scene.d.ts +7 -6
  73. package/types/excalidraw/scene/types.d.ts +2 -1
  74. package/types/excalidraw/store.d.ts +99 -0
  75. package/types/excalidraw/types.d.ts +18 -4
  76. package/types/excalidraw/utils.d.ts +7 -0
  77. package/types/excalidraw/webpack.prod.config.d.ts +1 -1
  78. package/types/excalidraw/zindex.d.ts +2 -2
  79. package/types/utils/collision.d.ts +4 -0
  80. package/types/utils/export.d.ts +2 -2
  81. package/types/utils/geometry/geometry.d.ts +71 -0
  82. package/types/utils/geometry/shape.d.ts +56 -0
@@ -1,52 +1,40 @@
1
+ import { AppStateChange, ElementsChange } from "./change";
2
+ import { SceneElementsMap } from "./element/types";
3
+ import { Emitter } from "./emitter";
4
+ import { Snapshot } from "./store";
1
5
  import { AppState } from "./types";
2
- import { ExcalidrawElement } from "./element/types";
3
- export interface HistoryEntry {
4
- appState: ReturnType<typeof clearAppStatePropertiesForHistory>;
5
- elements: ExcalidrawElement[];
6
+ export declare class HistoryChangedEvent {
7
+ readonly isUndoStackEmpty: boolean;
8
+ readonly isRedoStackEmpty: boolean;
9
+ constructor(isUndoStackEmpty?: boolean, isRedoStackEmpty?: boolean);
6
10
  }
7
- declare const clearAppStatePropertiesForHistory: (appState: AppState) => {
8
- selectedElementIds: Readonly<{
9
- [id: string]: true;
10
- }>;
11
- selectedGroupIds: {
12
- [groupId: string]: boolean;
13
- };
14
- viewBackgroundColor: string;
15
- editingLinearElement: import("./element/linearElementEditor").LinearElementEditor | null;
16
- editingGroupId: string | null;
17
- name: string | null;
18
- };
19
- declare class History {
20
- private elementCache;
21
- private recording;
22
- private stateHistory;
23
- private redoStack;
24
- private lastEntry;
25
- private hydrateHistoryEntry;
26
- private dehydrateHistoryEntry;
27
- getSnapshotForTest(): {
28
- recording: boolean;
29
- stateHistory: HistoryEntry[];
30
- redoStack: HistoryEntry[];
31
- };
11
+ export declare class History {
12
+ readonly onHistoryChangedEmitter: Emitter<[HistoryChangedEvent]>;
13
+ private readonly undoStack;
14
+ private readonly redoStack;
15
+ get isUndoStackEmpty(): boolean;
16
+ get isRedoStackEmpty(): boolean;
32
17
  clear(): void;
33
- private generateEntry;
34
- shouldCreateEntry(nextEntry: HistoryEntry): boolean;
35
- pushEntry(appState: AppState, elements: readonly ExcalidrawElement[]): void;
36
- clearRedoStack(): void;
37
- redoOnce(): HistoryEntry | null;
38
- undoOnce(): HistoryEntry | null;
39
18
  /**
40
- * Updates history's `lastEntry` to latest app state. This is necessary
41
- * when doing undo/redo which itself doesn't commit to history, but updates
42
- * app state in a way that would break `shouldCreateEntry` which relies on
43
- * `lastEntry` to reflect last comittable history state.
44
- * We can't update `lastEntry` from within history when calling undo/redo
45
- * because the action potentially mutates appState/elements before storing
46
- * it.
19
+ * Record a local change which will go into the history
47
20
  */
48
- setCurrentState(appState: AppState, elements: readonly ExcalidrawElement[]): void;
49
- resumeRecording(): void;
50
- record(state: AppState, elements: readonly ExcalidrawElement[]): void;
21
+ record(elementsChange: ElementsChange, appStateChange: AppStateChange): void;
22
+ undo(elements: SceneElementsMap, appState: AppState, snapshot: Readonly<Snapshot>): void | [SceneElementsMap, AppState];
23
+ redo(elements: SceneElementsMap, appState: AppState, snapshot: Readonly<Snapshot>): void | [SceneElementsMap, AppState];
24
+ private perform;
25
+ private static pop;
26
+ private static push;
27
+ }
28
+ export declare class HistoryEntry {
29
+ readonly appStateChange: AppStateChange;
30
+ readonly elementsChange: ElementsChange;
31
+ private constructor();
32
+ static create(appStateChange: AppStateChange, elementsChange: ElementsChange): HistoryEntry;
33
+ inverse(): HistoryEntry;
34
+ applyTo(elements: SceneElementsMap, appState: AppState, snapshot: Readonly<Snapshot>): [SceneElementsMap, AppState, boolean];
35
+ /**
36
+ * Apply latest (remote) changes to the history entry, creates new instance of `HistoryEntry`.
37
+ */
38
+ applyLatestChanges(elements: SceneElementsMap): HistoryEntry;
39
+ isEmpty(): boolean;
51
40
  }
52
- export default History;
@@ -0,0 +1,2 @@
1
+ import { Emitter } from "../emitter";
2
+ export declare const useEmitter: <TEvent extends unknown>(emitter: Emitter<[TEvent]>, initialState: TEvent) => TEvent;
@@ -11,6 +11,7 @@ export declare const Excalidraw: React.MemoExoticComponent<(props: ExcalidrawPro
11
11
  export { getSceneVersion, hashElementsVersion, hashString, isInvisiblySmallElement, getNonDeletedElements, } from "./element";
12
12
  export { defaultLang, useI18n, languages } from "./i18n";
13
13
  export { restore, restoreAppState, restoreElements, restoreLibraryItems, } from "./data/restore";
14
+ export { reconcileElements } from "./data/reconcile";
14
15
  export { exportToCanvas, exportToBlob, exportToSvg, exportToClipboard, getCommonBoundingBox, //zsviczian
15
16
  getMaximumGroups, //zsviczian
16
17
  intersectElementWithLine, //zsviczian
@@ -28,6 +29,7 @@ export { mergeLibraryItems, getLibraryItemsHash } from "./data/library";
28
29
  export { isLinearElement } from "./element/typeChecks";
29
30
  export { FONT_FAMILY, THEME, MIME_TYPES, ROUNDNESS, DEFAULT_LASER_COLOR, } from "./constants";
30
31
  export { mutateElement, newElementWith, bumpVersion, } from "./element/mutateElement";
32
+ export { StoreAction } from "./store";
31
33
  export { parseLibraryTokensFromUrl, useHandleLibrary } from "./data/library";
32
34
  export { sceneCoordsToViewportCoords, viewportCoordsToSceneCoords, } from "./utils";
33
35
  export { getEmbedLink } from "./element/embeddable";
@@ -9,7 +9,7 @@ export declare const renderInteractiveSceneThrottled: {
9
9
  * Interactive scene is the ui-canvas where we render bounding boxes, selections
10
10
  * and other ui stuff.
11
11
  */
12
- export declare const renderInteractiveScene: <U extends ({ canvas, elementsMap, visibleElements, selectedElements, scale, appState, renderConfig, }: InteractiveSceneRenderConfig) => {
12
+ export declare const renderInteractiveScene: <U extends ({ canvas, elementsMap, visibleElements, selectedElements, scale, appState, renderConfig, device, }: InteractiveSceneRenderConfig) => {
13
13
  atLeastOneVisibleElement: boolean;
14
14
  elementsMap: RenderableElementsMap;
15
15
  scrollBars?: undefined;
@@ -1,4 +1,4 @@
1
- import { ExcalidrawElement, NonDeletedExcalidrawElement, NonDeleted, ExcalidrawFrameLikeElement, ElementsMapOrArray } from "../element/types";
1
+ import { ExcalidrawElement, NonDeletedExcalidrawElement, NonDeleted, ExcalidrawFrameLikeElement, ElementsMapOrArray, OrderedExcalidrawElement, Ordered } from "../element/types";
2
2
  import { LinearElementEditor } from "../element/linearElementEditor";
3
3
  import { AppState } from "../types";
4
4
  type ElementIdKey = InstanceType<typeof LinearElementEditor>["elementId"];
@@ -20,10 +20,10 @@ declare class Scene {
20
20
  private elementsMap;
21
21
  private selectedElementsCache;
22
22
  private versionNonce;
23
- getElementsMapIncludingDeleted(): Map<string, ExcalidrawElement> & import("../utility-types").MakeBrand<"SceneElementsMap">;
24
- getNonDeletedElementsMap(): Map<string, NonDeletedExcalidrawElement> & import("../utility-types").MakeBrand<"NonDeletedSceneElementsMap">;
25
- getElementsIncludingDeleted(): readonly ExcalidrawElement[];
26
- getNonDeletedElements(): readonly NonDeletedExcalidrawElement[];
23
+ getNonDeletedElementsMap(): Map<string, Ordered<NonDeletedExcalidrawElement>> & import("../utility-types").MakeBrand<"NonDeletedSceneElementsMap">;
24
+ getElementsIncludingDeleted(): readonly OrderedExcalidrawElement[];
25
+ getElementsMapIncludingDeleted(): Map<string, Ordered<ExcalidrawElement>> & import("../utility-types").MakeBrand<"SceneElementsMap">;
26
+ getNonDeletedElements(): readonly Ordered<NonDeletedExcalidrawElement>[];
27
27
  getFramesIncludingDeleted(): readonly ExcalidrawFrameLikeElement[];
28
28
  getSelectedElements(opts: {
29
29
  selectedElementIds: AppState["selectedElementIds"];
@@ -59,7 +59,8 @@ declare class Scene {
59
59
  destroy(): void;
60
60
  insertElementAtIndex(element: ExcalidrawElement, index: number): void;
61
61
  insertElementsAtIndex(elements: ExcalidrawElement[], index: number): void;
62
- addNewElement: (element: ExcalidrawElement) => void;
62
+ insertElement: (element: ExcalidrawElement, idx?: number) => void;
63
+ insertElements: (elements: ExcalidrawElement[]) => void;
63
64
  getElementIndex(elementId: string): number;
64
65
  getContainerElement: (element: (ExcalidrawElement & {
65
66
  containerId: ExcalidrawElement["id"] | null;
@@ -1,7 +1,7 @@
1
1
  import type { RoughCanvas } from "roughjs/bin/canvas";
2
2
  import { Drawable } from "roughjs/bin/core";
3
3
  import { ExcalidrawElement, ExcalidrawTextElement, NonDeletedElementsMap, NonDeletedExcalidrawElement, NonDeletedSceneElementsMap } from "../element/types";
4
- import { AppClassProperties, AppState, EmbedsValidationStatus, ElementsPendingErasure, InteractiveCanvasAppState, StaticCanvasAppState, SocketId, UserIdleState } from "../types";
4
+ import { AppClassProperties, AppState, EmbedsValidationStatus, ElementsPendingErasure, InteractiveCanvasAppState, StaticCanvasAppState, SocketId, UserIdleState, Device } from "../types";
5
5
  import { MakeBrand } from "../utility-types";
6
6
  export type RenderableElementsMap = NonDeletedElementsMap & MakeBrand<"RenderableElementsMap">;
7
7
  export type StaticCanvasRenderConfig = {
@@ -60,6 +60,7 @@ export type InteractiveSceneRenderConfig = {
60
60
  scale: number;
61
61
  appState: InteractiveCanvasAppState;
62
62
  renderConfig: InteractiveCanvasRenderConfig;
63
+ device: Device;
63
64
  callback: (data: RenderInteractiveSceneCallback) => void;
64
65
  };
65
66
  export type SceneScroll = {
@@ -0,0 +1,99 @@
1
+ import { AppStateChange, ElementsChange } from "./change";
2
+ import { OrderedExcalidrawElement } from "./element/types";
3
+ import { Emitter } from "./emitter";
4
+ import { AppState, ObservedAppState } from "./types";
5
+ export declare const getObservedAppState: (appState: AppState) => ObservedAppState;
6
+ export type StoreActionType = "capture" | "update" | "none";
7
+ export declare const StoreAction: {
8
+ [K in Uppercase<StoreActionType>]: StoreActionType;
9
+ };
10
+ /**
11
+ * Represent an increment to the Store.
12
+ */
13
+ declare class StoreIncrementEvent {
14
+ readonly elementsChange: ElementsChange;
15
+ readonly appStateChange: AppStateChange;
16
+ constructor(elementsChange: ElementsChange, appStateChange: AppStateChange);
17
+ }
18
+ /**
19
+ * Store which captures the observed changes and emits them as `StoreIncrementEvent` events.
20
+ *
21
+ * @experimental this interface is experimental and subject to change.
22
+ */
23
+ export interface IStore {
24
+ onStoreIncrementEmitter: Emitter<[StoreIncrementEvent]>;
25
+ get snapshot(): Snapshot;
26
+ set snapshot(snapshot: Snapshot);
27
+ /**
28
+ * Use to schedule update of the snapshot, useful on updates for which we don't need to calculate increments (i.e. remote updates).
29
+ */
30
+ shouldUpdateSnapshot(): void;
31
+ /**
32
+ * Use to schedule calculation of a store increment.
33
+ */
34
+ shouldCaptureIncrement(): void;
35
+ /**
36
+ * Based on the scheduled operation, either only updates store snapshot or also calculates increment and emits the result as a `StoreIncrementEvent`.
37
+ *
38
+ * @emits StoreIncrementEvent when increment is calculated.
39
+ */
40
+ commit(elements: Map<string, OrderedExcalidrawElement> | undefined, appState: AppState | ObservedAppState | undefined): void;
41
+ /**
42
+ * Clears the store instance.
43
+ */
44
+ clear(): void;
45
+ /**
46
+ * Filters out yet uncomitted elements from `nextElements`, which are part of in-progress local async actions (ephemerals) and thus were not yet commited to the snapshot.
47
+ *
48
+ * This is necessary in updates in which we receive reconciled elements, already containing elements which were not yet captured by the local store (i.e. collab).
49
+ */
50
+ filterUncomittedElements(prevElements: Map<string, OrderedExcalidrawElement>, nextElements: Map<string, OrderedExcalidrawElement>): Map<string, OrderedExcalidrawElement>;
51
+ }
52
+ export declare class Store implements IStore {
53
+ readonly onStoreIncrementEmitter: Emitter<[StoreIncrementEvent]>;
54
+ private scheduledActions;
55
+ private _snapshot;
56
+ get snapshot(): Snapshot;
57
+ set snapshot(snapshot: Snapshot);
58
+ shouldCaptureIncrement: () => void;
59
+ shouldUpdateSnapshot: () => void;
60
+ private scheduleAction;
61
+ commit: (elements: Map<string, OrderedExcalidrawElement> | undefined, appState: AppState | ObservedAppState | undefined) => void;
62
+ captureIncrement: (elements: Map<string, OrderedExcalidrawElement> | undefined, appState: AppState | ObservedAppState | undefined) => void;
63
+ updateSnapshot: (elements: Map<string, OrderedExcalidrawElement> | undefined, appState: AppState | ObservedAppState | undefined) => void;
64
+ filterUncomittedElements: (prevElements: Map<string, OrderedExcalidrawElement>, nextElements: Map<string, OrderedExcalidrawElement>) => Map<string, OrderedExcalidrawElement>;
65
+ clear: () => void;
66
+ private satisfiesScheduledActionsInvariant;
67
+ }
68
+ export declare class Snapshot {
69
+ readonly elements: Map<string, OrderedExcalidrawElement>;
70
+ readonly appState: ObservedAppState;
71
+ readonly meta: {
72
+ didElementsChange: boolean;
73
+ didAppStateChange: boolean;
74
+ isEmpty?: boolean;
75
+ };
76
+ private constructor();
77
+ static empty(): Snapshot;
78
+ isEmpty(): boolean | undefined;
79
+ /**
80
+ * Efficiently clone the existing snapshot, only if we detected changes.
81
+ *
82
+ * @returns same instance if there are no changes detected, new instance otherwise.
83
+ */
84
+ maybeClone(elements: Map<string, OrderedExcalidrawElement> | undefined, appState: AppState | ObservedAppState | undefined): Snapshot;
85
+ private maybeCreateAppStateSnapshot;
86
+ private detectChangedAppState;
87
+ private maybeCreateElementsSnapshot;
88
+ /**
89
+ * Detect if there any changed elements.
90
+ *
91
+ * NOTE: we shouldn't just use `sceneVersionNonce` instead, as we need to call this before the scene updates.
92
+ */
93
+ private detectChangedElements;
94
+ /**
95
+ * Perform structural clone, cloning only elements that changed.
96
+ */
97
+ private createElementsSnapshot;
98
+ }
99
+ export {};
@@ -1,5 +1,5 @@
1
1
  import React from "react";
2
- import { PointerType, ExcalidrawLinearElement, NonDeletedExcalidrawElement, NonDeleted, TextAlign, ExcalidrawElement, GroupId, ExcalidrawBindableElement, Arrowhead, ChartType, FontFamilyValues, ExcalidrawTextElement, FileId, ExcalidrawImageElement, Theme, StrokeRoundness, ExcalidrawEmbeddableElement, ExcalidrawMagicFrameElement, ExcalidrawFrameLikeElement, ExcalidrawElementType, ExcalidrawIframeLikeElement } from "./element/types";
2
+ import { PointerType, ExcalidrawLinearElement, NonDeletedExcalidrawElement, NonDeleted, TextAlign, ExcalidrawElement, GroupId, ExcalidrawBindableElement, Arrowhead, ChartType, FontFamilyValues, ExcalidrawTextElement, FileId, ExcalidrawImageElement, Theme, StrokeRoundness, ExcalidrawEmbeddableElement, ExcalidrawMagicFrameElement, ExcalidrawFrameLikeElement, ExcalidrawElementType, ExcalidrawIframeLikeElement, OrderedExcalidrawElement } from "./element/types";
3
3
  import { Action } from "./actions/types";
4
4
  import { Point as RoughPoint } from "roughjs/bin/geometry";
5
5
  import { LinearElementEditor } from "./element/linearElementEditor";
@@ -19,6 +19,7 @@ import { ContextMenuItems } from "./components/ContextMenu";
19
19
  import { SnapLine } from "./snapping";
20
20
  import { Merge, MaybePromise, ValueOf } from "./utility-types";
21
21
  import { ColorPaletteCustom } from "./colors";
22
+ import { StoreActionType } from "./store";
22
23
  export type Point = Readonly<RoughPoint>;
23
24
  export type SocketId = string & {
24
25
  _brand: "SocketId";
@@ -138,6 +139,18 @@ export type InteractiveCanvasAppState = Readonly<_CommonCanvasAppState & {
138
139
  snapLines: AppState["snapLines"];
139
140
  zenModeEnabled: AppState["zenModeEnabled"];
140
141
  }>;
142
+ export type ObservedAppState = ObservedStandaloneAppState & ObservedElementsAppState;
143
+ export type ObservedStandaloneAppState = {
144
+ name: AppState["name"];
145
+ viewBackgroundColor: AppState["viewBackgroundColor"];
146
+ };
147
+ export type ObservedElementsAppState = {
148
+ editingGroupId: AppState["editingGroupId"];
149
+ selectedElementIds: AppState["selectedElementIds"];
150
+ selectedGroupIds: AppState["selectedGroupIds"];
151
+ editingLinearElementId: LinearElementEditor["elementId"] | null;
152
+ selectedLinearElementId: LinearElementEditor["elementId"] | null;
153
+ };
141
154
  export interface AppState {
142
155
  contextMenu: {
143
156
  items: ContextMenuItems;
@@ -368,7 +381,7 @@ export type OnUserFollowedPayload = {
368
381
  action: "FOLLOW" | "UNFOLLOW";
369
382
  };
370
383
  export interface ExcalidrawProps {
371
- onChange?: (elements: readonly ExcalidrawElement[], appState: AppState, files: BinaryFiles) => void;
384
+ onChange?: (elements: readonly OrderedExcalidrawElement[], appState: AppState, files: BinaryFiles) => void;
372
385
  initialData?: MaybePromise<ExcalidrawInitialDataState | null>;
373
386
  excalidrawAPI?: (api: ExcalidrawImperativeAPI) => void;
374
387
  isCollaborating?: boolean;
@@ -426,7 +439,7 @@ export type SceneData = {
426
439
  elements?: ImportedDataState["elements"];
427
440
  appState?: ImportedDataState["appState"];
428
441
  collaborators?: Map<SocketId, Collaborator>;
429
- commitToHistory?: boolean;
442
+ storeAction?: StoreActionType;
430
443
  };
431
444
  export declare enum UserIdleState {
432
445
  ACTIVE = "active",
@@ -499,6 +512,7 @@ export type AppClassProperties = {
499
512
  setOpenDialog: App["setOpenDialog"];
500
513
  insertEmbeddableElement: App["insertEmbeddableElement"];
501
514
  onMagicframeToolSelect: App["onMagicframeToolSelect"];
515
+ getElementShape: App["getElementShape"];
502
516
  getName: App["getName"];
503
517
  };
504
518
  export type PointerDownState = Readonly<{
@@ -611,7 +625,7 @@ export type Device = Readonly<{
611
625
  };
612
626
  isTouchScreen: boolean;
613
627
  }>;
614
- type FrameNameBounds = {
628
+ export type FrameNameBounds = {
615
629
  x: number;
616
630
  y: number;
617
631
  width: number;
@@ -160,7 +160,14 @@ export declare const arrayToMap: <T extends string | {
160
160
  export declare const arrayToMapWithIndex: <T extends {
161
161
  id: string;
162
162
  }>(elements: readonly T[]) => Map<string, [element: T, index: number]>;
163
+ /**
164
+ * Transform array into an object, use only when array order is irrelevant.
165
+ */
166
+ export declare const arrayToObject: <T>(array: readonly T[], groupBy?: ((value: T) => string) | undefined) => {
167
+ [key: string]: T;
168
+ };
163
169
  export declare const isTestEnv: () => boolean;
170
+ export declare const isDevEnv: () => boolean;
164
171
  export declare const wrapEvent: <T extends Event>(name: EVENT, nativeEvent: T) => CustomEvent<{
165
172
  nativeEvent: T;
166
173
  }>;
@@ -78,7 +78,7 @@ export namespace module {
78
78
  }
79
79
  export namespace optimization {
80
80
  const minimize: boolean;
81
- const minimizer: TerserPlugin<import("terser").MinifyOptions>[];
81
+ const minimizer: TerserPlugin<import("terser-webpack-plugin/node_modules/terser").MinifyOptions>[];
82
82
  }
83
83
  export const plugins: any[];
84
84
  export const externals: {
@@ -1,6 +1,6 @@
1
1
  import { ExcalidrawElement } from "./element/types";
2
2
  import { AppState } from "./types";
3
- export declare const moveOneLeft: (allElements: readonly ExcalidrawElement[], appState: AppState) => ExcalidrawElement[];
4
- export declare const moveOneRight: (allElements: readonly ExcalidrawElement[], appState: AppState) => ExcalidrawElement[];
3
+ export declare const moveOneLeft: (allElements: readonly ExcalidrawElement[], appState: AppState) => readonly ExcalidrawElement[];
4
+ export declare const moveOneRight: (allElements: readonly ExcalidrawElement[], appState: AppState) => readonly ExcalidrawElement[];
5
5
  export declare const moveAllLeft: (allElements: readonly ExcalidrawElement[], appState: AppState) => readonly ExcalidrawElement[] | ExcalidrawElement[];
6
6
  export declare const moveAllRight: (allElements: readonly ExcalidrawElement[], appState: AppState) => readonly ExcalidrawElement[] | ExcalidrawElement[];
@@ -0,0 +1,4 @@
1
+ import { Point, Polygon, GeometricShape } from "./geometry/shape";
2
+ export declare const isPointOnShape: (point: Point, shape: GeometricShape, tolerance?: number) => boolean;
3
+ export declare const isPointInShape: (point: Point, shape: GeometricShape) => boolean;
4
+ export declare const isPointInBounds: (point: Point, bounds: Polygon) => boolean;
@@ -33,8 +33,8 @@ export declare const exportToClipboard: (opts: ExportOpts & {
33
33
  }) => Promise<void>;
34
34
  export { getCommonBoundingBox } from "../excalidraw/element/bounds";
35
35
  export { getMaximumGroups } from "../excalidraw/groups";
36
- export { intersectElementWithLine } from "../excalidraw/element/collision";
37
- export { determineFocusDistance } from "../excalidraw/element/collision";
36
+ export { intersectElementWithLine } from "../excalidraw/element/binding";
37
+ export { determineFocusDistance } from "../excalidraw/element/binding";
38
38
  export { measureText, wrapText, getDefaultLineHeight, } from "../excalidraw/element/textElement";
39
39
  export { getFontString } from "../excalidraw/utils";
40
40
  export { getBoundTextMaxWidth } from "../excalidraw/element/textElement";
@@ -0,0 +1,71 @@
1
+ import { Point, Line, Polygon, Curve, Ellipse, Polycurve, Polyline } from "./shape";
2
+ /**
3
+ * utils
4
+ */
5
+ export declare const cross: (a: Point, b: Point, o: Point) => number;
6
+ export declare const isClosed: (polygon: Polygon) => boolean;
7
+ export declare const close: (polygon: Polygon) => Polygon;
8
+ /**
9
+ * angles
10
+ */
11
+ export declare const angleToDegrees: (angle: number) => number;
12
+ export declare const angleToRadians: (angle: number) => number;
13
+ export declare const angleReflect: (incidenceAngle: number, surfaceAngle: number) => number;
14
+ export declare const pointRotate: (point: Point, angle: number, origin?: Point) => Point;
15
+ export declare const pointTranslate: (point: Point, angle?: number, distance?: number) => Point;
16
+ export declare const pointInverse: (point: Point) => Point;
17
+ export declare const pointAdd: (pointA: Point, pointB: Point) => Point;
18
+ export declare const distanceToPoint: (p1: Point, p2: Point) => number;
19
+ /**
20
+ * lines
21
+ */
22
+ export declare const lineAngle: (line: Line) => number;
23
+ export declare const lineLength: (line: Line) => number;
24
+ export declare const lineMidpoint: (line: Line) => Point;
25
+ export declare const lineRotate: (line: Line, angle: number, origin?: Point) => Line;
26
+ export declare const lineTranslate: (line: Line, angle: number, distance: number) => Point[];
27
+ export declare const lineInterpolate: (line: Line, clamp?: boolean) => (t: number) => Point;
28
+ export declare const curveToBezier: (pointsIn: readonly Point[], curveTightness?: number) => Point[];
29
+ export declare const curveRotate: (curve: Curve, angle: number, origin: Point) => Point[];
30
+ export declare const cubicBezierPoint: (t: number, controlPoints: Curve) => Point;
31
+ export declare const cubicBezierDistance: (point: Point, controlPoints: Curve) => number;
32
+ /**
33
+ * polygons
34
+ */
35
+ export declare const polygonRotate: (polygon: Polygon, angle: number, origin: Point) => Point[];
36
+ export declare const polygonBounds: (polygon: Polygon) => [Point, Point];
37
+ export declare const polygonCentroid: (vertices: Point[]) => Point;
38
+ export declare const polygonScale: (polygon: Polygon, scale: number, origin?: Point) => Polygon;
39
+ export declare const polygonScaleX: (polygon: Polygon, scale: number, origin?: Point) => Polygon;
40
+ export declare const polygonScaleY: (polygon: Polygon, scale: number, origin?: Point) => Polygon;
41
+ export declare const polygonReflectX: (polygon: Polygon, reflectFactor?: number) => Point[];
42
+ export declare const polygonReflectY: (polygon: Polygon, reflectFactor?: number) => Point[];
43
+ export declare const polygonTranslate: (polygon: Polygon, angle: number, distance: number) => Point[];
44
+ /**
45
+ * ellipses
46
+ */
47
+ export declare const ellipseAxes: (ellipse: Ellipse) => {
48
+ majorAxis: number;
49
+ minorAxis: number;
50
+ };
51
+ export declare const ellipseFocusToCenter: (ellipse: Ellipse) => number;
52
+ export declare const ellipseExtremes: (ellipse: Ellipse) => Point[];
53
+ export declare const pointRelativeToCenter: (point: Point, center: Point, angle: number) => Point;
54
+ export declare const pointLeftofLine: (point: Point, line: Line) => boolean;
55
+ export declare const pointRightofLine: (point: Point, line: Line) => boolean;
56
+ export declare const distanceToSegment: (point: Point, line: Line) => number;
57
+ export declare const pointOnLine: (point: Point, line: Line, threshold?: number) => boolean;
58
+ export declare const pointOnPolyline: (point: Point, polyline: Polyline, threshold?: number) => boolean;
59
+ export declare const lineIntersectsLine: (lineA: Line, lineB: Line) => boolean;
60
+ export declare const lineIntersectsPolygon: (line: Line, polygon: Polygon) => boolean;
61
+ export declare const pointInBezierEquation: (p0: Point, p1: Point, p2: Point, p3: Point, [mx, my]: Point, lineThreshold: number) => boolean;
62
+ export declare const cubicBezierEquation: (curve: Curve) => (t: number, idx: number) => number;
63
+ export declare const polyLineFromCurve: (curve: Curve, segments?: number) => Polyline;
64
+ export declare const pointOnCurve: (point: Point, curve: Curve, threshold?: number) => boolean;
65
+ export declare const pointOnPolycurve: (point: Point, polycurve: Polycurve, threshold?: number) => boolean;
66
+ export declare const pointInPolygon: (point: Point, polygon: Polygon) => boolean;
67
+ export declare const pointOnPolygon: (point: Point, polygon: Polygon, threshold?: number) => boolean;
68
+ export declare const polygonInPolygon: (polygonA: Polygon, polygonB: Polygon) => boolean;
69
+ export declare const polygonIntersectPolygon: (polygonA: Polygon, polygonB: Polygon) => boolean;
70
+ export declare const pointOnEllipse: (point: Point, ellipse: Ellipse, threshold?: number) => boolean;
71
+ export declare const pointInEllipse: (point: Point, ellipse: Ellipse) => boolean;
@@ -0,0 +1,56 @@
1
+ /**
2
+ * this file defines pure geometric shapes
3
+ *
4
+ * for instance, a cubic bezier curve is specified by its four control points and
5
+ * an ellipse is defined by its center, angle, semi major axis and semi minor axis
6
+ * (but in semi-width and semi-height so it's more relevant to Excalidraw)
7
+ *
8
+ * the idea with pure shapes is so that we can provide collision and other geoemtric methods not depending on
9
+ * the specifics of roughjs or elements in Excalidraw; instead, we can focus on the pure shapes themselves
10
+ *
11
+ * also included in this file are methods for converting an Excalidraw element or a Drawable from roughjs
12
+ * to pure shapes
13
+ */
14
+ import { ElementsMap, ExcalidrawDiamondElement, ExcalidrawElement, ExcalidrawEllipseElement, ExcalidrawEmbeddableElement, ExcalidrawFrameLikeElement, ExcalidrawFreeDrawElement, ExcalidrawIframeElement, ExcalidrawImageElement, ExcalidrawLinearElement, ExcalidrawRectangleElement, ExcalidrawSelectionElement, ExcalidrawTextElement } from "../../excalidraw/element/types";
15
+ import type { Drawable, Op } from "roughjs/bin/core";
16
+ export type Point = [number, number];
17
+ export type Vector = Point;
18
+ export type Line = [Point, Point];
19
+ export type Polyline = Line[];
20
+ export type Curve = [Point, Point, Point, Point];
21
+ export type Polycurve = Curve[];
22
+ export type Polygon = Point[];
23
+ export type Ellipse = {
24
+ center: Point;
25
+ angle: number;
26
+ halfWidth: number;
27
+ halfHeight: number;
28
+ };
29
+ export type GeometricShape = {
30
+ type: "line";
31
+ data: Line;
32
+ } | {
33
+ type: "polygon";
34
+ data: Polygon;
35
+ } | {
36
+ type: "curve";
37
+ data: Curve;
38
+ } | {
39
+ type: "ellipse";
40
+ data: Ellipse;
41
+ } | {
42
+ type: "polyline";
43
+ data: Polyline;
44
+ } | {
45
+ type: "polycurve";
46
+ data: Polycurve;
47
+ };
48
+ type RectangularElement = ExcalidrawRectangleElement | ExcalidrawDiamondElement | ExcalidrawFrameLikeElement | ExcalidrawEmbeddableElement | ExcalidrawImageElement | ExcalidrawIframeElement | ExcalidrawTextElement | ExcalidrawSelectionElement;
49
+ export declare const getPolygonShape: (element: RectangularElement) => GeometricShape;
50
+ export declare const getSelectionBoxShape: (element: ExcalidrawElement, elementsMap: ElementsMap, padding?: number) => GeometricShape;
51
+ export declare const getEllipseShape: (element: ExcalidrawEllipseElement) => GeometricShape;
52
+ export declare const getCurvePathOps: (shape: Drawable) => Op[];
53
+ export declare const getCurveShape: (roughShape: Drawable, startingPoint: Point | undefined, angleInRadian: number, center: Point) => GeometricShape;
54
+ export declare const getFreedrawShape: (element: ExcalidrawFreeDrawElement, center: Point, isClosed?: boolean) => GeometricShape;
55
+ export declare const getClosedCurveShape: (element: ExcalidrawLinearElement, roughShape: Drawable, startingPoint: Point | undefined, angleInRadian: number, center: Point) => GeometricShape;
56
+ export {};