@excalidraw/excalidraw 0.18.0-a18b139 → 0.18.0-a30e1b2

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 (97) hide show
  1. package/dist/dev/{chunk-X3RYHLJU.js → chunk-CARD3WJZ.js} +9 -4
  2. package/dist/dev/chunk-CARD3WJZ.js.map +7 -0
  3. package/dist/dev/{chunk-U3G3LY5D.js → chunk-ETWEPOFC.js} +7284 -6864
  4. package/dist/dev/chunk-ETWEPOFC.js.map +7 -0
  5. package/dist/dev/{chunk-MJMGTOVG.js → chunk-RS23HYC4.js} +2 -2
  6. package/dist/dev/data/{image-Y366K5SN.js → image-AYLHSOBV.js} +3 -3
  7. package/dist/dev/index.css +43 -2
  8. package/dist/dev/index.css.map +3 -3
  9. package/dist/dev/index.js +2959 -1807
  10. package/dist/dev/index.js.map +4 -4
  11. package/dist/dev/locales/{en-CKWC2GMK.js → en-E3O5XSXJ.js} +2 -2
  12. package/dist/dev/subset-shared.chunk.js +1 -1
  13. package/dist/dev/subset-worker.chunk.js +1 -1
  14. package/dist/prod/chunk-6BSJPDKJ.js +33 -0
  15. package/dist/prod/{chunk-IUH5AXLB.js → chunk-FGHASORR.js} +4 -4
  16. package/dist/prod/{chunk-VQA74LVG.js → chunk-SBKTMZM7.js} +1 -1
  17. package/dist/prod/data/image-VAYKYPXV.js +1 -0
  18. package/dist/prod/index.css +1 -1
  19. package/dist/prod/index.js +19 -18
  20. package/dist/prod/locales/{en-SBO6ZHT2.js → en-44IKVKYT.js} +1 -1
  21. package/dist/prod/subset-shared.chunk.js +1 -1
  22. package/dist/prod/subset-worker.chunk.js +1 -1
  23. package/dist/types/common/src/constants.d.ts +2 -0
  24. package/dist/types/{excalidraw → common/src}/emitter.d.ts +1 -1
  25. package/dist/types/common/src/font-metadata.d.ts +4 -2
  26. package/dist/types/common/src/index.d.ts +1 -0
  27. package/dist/types/common/src/utility-types.d.ts +5 -0
  28. package/dist/types/common/src/utils.d.ts +9 -0
  29. package/dist/types/element/src/binding.d.ts +10 -2
  30. package/dist/types/element/src/bounds.d.ts +1 -1
  31. package/dist/types/{excalidraw/change.d.ts → element/src/delta.d.ts} +40 -35
  32. package/dist/types/element/src/frame.d.ts +1 -0
  33. package/dist/types/element/src/index.d.ts +2 -2
  34. package/dist/types/element/src/linearElementEditor.d.ts +3 -7
  35. package/dist/types/element/src/newElement.d.ts +2 -2
  36. package/dist/types/element/src/store.d.ts +227 -0
  37. package/dist/types/element/src/transformHandles.d.ts +2 -2
  38. package/dist/types/element/src/typeChecks.d.ts +3 -0
  39. package/dist/types/element/src/types.d.ts +7 -0
  40. package/dist/types/excalidraw/actions/actionAddToLibrary.d.ts +18 -36
  41. package/dist/types/excalidraw/actions/actionAlign.d.ts +8 -8
  42. package/dist/types/excalidraw/actions/actionBoundText.d.ts +12 -24
  43. package/dist/types/excalidraw/actions/actionCanvas.d.ts +107 -185
  44. package/dist/types/excalidraw/actions/actionClipboard.d.ts +39 -75
  45. package/dist/types/excalidraw/actions/actionCropEditor.d.ts +6 -12
  46. package/dist/types/excalidraw/actions/actionDeleteSelected.d.ts +19 -37
  47. package/dist/types/excalidraw/actions/actionDistribute.d.ts +4 -4
  48. package/dist/types/excalidraw/actions/actionDuplicateSelection.d.ts +2 -2
  49. package/dist/types/excalidraw/actions/actionElementLink.d.ts +5 -11
  50. package/dist/types/excalidraw/actions/actionElementLock.d.ts +14 -26
  51. package/dist/types/excalidraw/actions/actionEmbeddable.d.ts +6 -12
  52. package/dist/types/excalidraw/actions/actionExport.d.ts +81 -135
  53. package/dist/types/excalidraw/actions/actionFinalize.d.ts +13 -25
  54. package/dist/types/excalidraw/actions/actionFlip.d.ts +4 -4
  55. package/dist/types/excalidraw/actions/actionFrame.d.ts +26 -50
  56. package/dist/types/excalidraw/actions/actionGroup.d.ts +16 -28
  57. package/dist/types/excalidraw/actions/actionHistory.d.ts +1 -2
  58. package/dist/types/excalidraw/actions/actionLinearEditor.d.ts +6 -12
  59. package/dist/types/excalidraw/actions/actionLink.d.ts +8 -14
  60. package/dist/types/excalidraw/actions/actionMenu.d.ts +19 -37
  61. package/dist/types/excalidraw/actions/actionNavigate.d.ts +12 -24
  62. package/dist/types/excalidraw/actions/actionProperties.d.ts +96 -186
  63. package/dist/types/excalidraw/actions/actionSelectAll.d.ts +8 -14
  64. package/dist/types/excalidraw/actions/actionStyles.d.ts +10 -16
  65. package/dist/types/excalidraw/actions/actionToggleGridMode.d.ts +8 -14
  66. package/dist/types/excalidraw/actions/actionToggleObjectsSnapMode.d.ts +8 -14
  67. package/dist/types/excalidraw/actions/actionToggleSearchMenu.d.ts +7 -186
  68. package/dist/types/excalidraw/actions/actionToggleShapeSwitch.d.ts +19 -0
  69. package/dist/types/excalidraw/actions/actionToggleStats.d.ts +8 -14
  70. package/dist/types/excalidraw/actions/actionToggleViewMode.d.ts +8 -14
  71. package/dist/types/excalidraw/actions/actionToggleZenMode.d.ts +8 -14
  72. package/dist/types/excalidraw/actions/actionZindex.d.ts +8 -8
  73. package/dist/types/excalidraw/actions/types.d.ts +3 -3
  74. package/dist/types/excalidraw/appState.d.ts +14 -14
  75. package/dist/types/excalidraw/components/App.d.ts +5 -3
  76. package/dist/types/excalidraw/components/ConvertElementTypePopup.d.ts +49 -0
  77. package/dist/types/excalidraw/components/Stats/Collapsible.d.ts +2 -1
  78. package/dist/types/excalidraw/components/Stats/utils.d.ts +1 -8
  79. package/dist/types/excalidraw/editor-jotai.d.ts +6 -6
  80. package/dist/types/excalidraw/history.d.ts +14 -22
  81. package/dist/types/excalidraw/hooks/useEmitter.d.ts +1 -1
  82. package/dist/types/excalidraw/index.d.ts +1 -1
  83. package/dist/types/excalidraw/renderer/helpers.d.ts +6 -1
  84. package/dist/types/excalidraw/types.d.ts +11 -3
  85. package/dist/types/excalidraw/wysiwyg/textWysiwyg.d.ts +3 -1
  86. package/dist/types/math/src/curve.d.ts +2 -0
  87. package/dist/types/math/src/vector.d.ts +4 -0
  88. package/history.ts +68 -94
  89. package/package.json +3 -3
  90. package/dist/dev/chunk-U3G3LY5D.js.map +0 -7
  91. package/dist/dev/chunk-X3RYHLJU.js.map +0 -7
  92. package/dist/prod/chunk-PUQLEN73.js +0 -33
  93. package/dist/prod/data/image-WY2VMQLG.js +0 -1
  94. package/dist/types/excalidraw/store.d.ts +0 -129
  95. /package/dist/dev/{chunk-MJMGTOVG.js.map → chunk-RS23HYC4.js.map} +0 -0
  96. /package/dist/dev/data/{image-Y366K5SN.js.map → image-AYLHSOBV.js.map} +0 -0
  97. /package/dist/dev/locales/{en-CKWC2GMK.js.map → en-E3O5XSXJ.js.map} +0 -0
@@ -1 +1 @@
1
- import{A,B,C,D,E,F,G,H,I,J,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z}from"../chunk-IUH5AXLB.js";import"../chunk-SRAX5OIU.js";export{f as alerts,e as buttons,l as canvasError,s as clearCanvasDialog,C as colorPicker,A as colors,I as commandPalette,v as confirmDialog,J as default,i as element,b as elementLink,x as encrypted,p as errorDialog,m as errorSplash,g as errors,q as exportDialog,G as fontList,j as headings,r as helpDialog,k as hints,w as imageExportDialog,a as labels,c as library,E as mermaid,D as overwriteConfirm,t as publishDialog,u as publishSuccessDialog,F as quickSearch,o as roomDialog,d as search,n as shareDialog,y as stats,z as toast,h as toolBar,H as userList,B as welcomeScreen};
1
+ import{A,B,C,D,E,F,G,H,I,J,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z}from"../chunk-FGHASORR.js";import"../chunk-SRAX5OIU.js";export{f as alerts,e as buttons,l as canvasError,s as clearCanvasDialog,C as colorPicker,A as colors,I as commandPalette,v as confirmDialog,J as default,i as element,b as elementLink,x as encrypted,p as errorDialog,m as errorSplash,g as errors,q as exportDialog,G as fontList,j as headings,r as helpDialog,k as hints,w as imageExportDialog,a as labels,c as library,E as mermaid,D as overwriteConfirm,t as publishDialog,u as publishSuccessDialog,F as quickSearch,o as roomDialog,d as search,n as shareDialog,y as stats,z as toast,h as toolBar,H as userList,B as welcomeScreen};
@@ -1 +1 @@
1
- import{a,b,c,d}from"./chunk-LS7FJGPW.js";import"./chunk-VQA74LVG.js";import"./chunk-SRAX5OIU.js";export{a as Commands,b as subsetToBase64,c as subsetToBinary,d as toBase64};
1
+ import{a,b,c,d}from"./chunk-LS7FJGPW.js";import"./chunk-SBKTMZM7.js";import"./chunk-SRAX5OIU.js";export{a as Commands,b as subsetToBase64,c as subsetToBinary,d as toBase64};
@@ -1 +1 @@
1
- import{a as r,c as t}from"./chunk-LS7FJGPW.js";import"./chunk-VQA74LVG.js";import"./chunk-SRAX5OIU.js";var s=import.meta.url?new URL(import.meta.url):void 0;typeof window>"u"&&typeof self<"u"&&(self.onmessage=async e=>{switch(e.data.command){case r.Subset:let a=await t(e.data.arrayBuffer,e.data.codePoints);self.postMessage(a,{transfer:[a]});break}});export{s as WorkerUrl};
1
+ import{a as r,c as t}from"./chunk-LS7FJGPW.js";import"./chunk-SBKTMZM7.js";import"./chunk-SRAX5OIU.js";var s=import.meta.url?new URL(import.meta.url):void 0;typeof window>"u"&&typeof self<"u"&&(self.onmessage=async e=>{switch(e.data.command){case r.Subset:let a=await t(e.data.arrayBuffer,e.data.codePoints);self.postMessage(a,{transfer:[a]});break}});export{s as WorkerUrl};
@@ -88,6 +88,7 @@ export declare const CLASSES: {
88
88
  SHAPE_ACTIONS_MENU: string;
89
89
  ZOOM_ACTIONS: string;
90
90
  SEARCH_MENU_INPUT_WRAPPER: string;
91
+ CONVERT_ELEMENT_TYPE_POPUP: string;
91
92
  };
92
93
  export declare const CJK_HAND_DRAWN_FALLBACK_FONT = "Xiaolai";
93
94
  export declare const WINDOWS_EMOJI_FALLBACK_FONT = "Segoe UI Emoji";
@@ -108,6 +109,7 @@ export declare const FONT_FAMILY: {
108
109
  "Lilita One": number;
109
110
  "Comic Shanns": number;
110
111
  "Liberation Sans": number;
112
+ Assistant: number;
111
113
  };
112
114
  export declare const FONT_FAMILY_FALLBACKS: {
113
115
  Xiaolai: number;
@@ -1,4 +1,4 @@
1
- import type { UnsubscribeCallback } from "./types";
1
+ import type { UnsubscribeCallback } from "@excalidraw/excalidraw/types";
2
2
  type Subscriber<T extends any[]> = (...payload: T) => void;
3
3
  export declare class Emitter<T extends any[] = []> {
4
4
  subscribers: Subscriber<T>[];
@@ -16,8 +16,10 @@ export interface FontMetadata {
16
16
  };
17
17
  /** flag to indicate a deprecated font */
18
18
  deprecated?: true;
19
- /** flag to indicate a server-side only font */
20
- serverSide?: true;
19
+ /**
20
+ * whether this is a font that users can use (= shown in font picker)
21
+ */
22
+ private?: true;
21
23
  /** flag to indiccate a local-only font */
22
24
  local?: true;
23
25
  /** flag to indicate a fallback font */
@@ -9,3 +9,4 @@ export * from "./promise-pool";
9
9
  export * from "./random";
10
10
  export * from "./url";
11
11
  export * from "./utils";
12
+ export * from "./emitter";
@@ -31,3 +31,8 @@ export type MakeBrand<T extends string> = {
31
31
  /** Maybe just promise or already fulfilled one! */
32
32
  export type MaybePromise<T> = T | Promise<T>;
33
33
  export type AllPossibleKeys<T> = T extends any ? keyof T : never;
34
+ /** Strip all the methods or functions from a type */
35
+ export type DTO<T> = {
36
+ [K in keyof T as T[K] extends Function ? never : K]: T[K];
37
+ };
38
+ export type MapEntry<M extends Map<any, any>> = M extends Map<infer K, infer V> ? [K, V] : never;
@@ -178,6 +178,15 @@ export type Node<T> = T & {
178
178
  * Creates a circular doubly linked list by adding `prev` and `next` props to the existing array nodes.
179
179
  */
180
180
  export declare const arrayToList: <T>(array: readonly T[]) => Node<T>[];
181
+ /**
182
+ * Converts a readonly array or map into an iterable.
183
+ * Useful for avoiding entry allocations when iterating object / map on each iteration.
184
+ */
185
+ export declare const toIterable: <T>(values: ReadonlyMap<string, T> | readonly T[]) => Iterable<T>;
186
+ /**
187
+ * Converts a readonly array or map into an array.
188
+ */
189
+ export declare const toArray: <T>(values: ReadonlyMap<string, T> | readonly T[]) => T[];
181
190
  export declare const isTestEnv: () => boolean;
182
191
  export declare const isDevEnv: () => boolean;
183
192
  export declare const isProdEnv: () => boolean;
@@ -5,7 +5,7 @@ import { type Heading } from "./heading";
5
5
  import type Scene from "./Scene";
6
6
  import type { Bounds } from "./bounds";
7
7
  import type { ElementUpdate } from "./mutateElement";
8
- import type { ExcalidrawBindableElement, ExcalidrawElement, NonDeleted, ExcalidrawLinearElement, NonDeletedExcalidrawElement, ElementsMap, NonDeletedSceneElementsMap, OrderedExcalidrawElement, ExcalidrawElbowArrowElement, FixedPoint } from "./types";
8
+ import type { ExcalidrawBindableElement, ExcalidrawElement, NonDeleted, ExcalidrawLinearElement, NonDeletedExcalidrawElement, ElementsMap, NonDeletedSceneElementsMap, ExcalidrawElbowArrowElement, FixedPoint } from "./types";
9
9
  export type SuggestedBinding = NonDeleted<ExcalidrawBindableElement> | SuggestedPointBinding;
10
10
  export type SuggestedPointBinding = [
11
11
  NonDeleted<ExcalidrawLinearElement>,
@@ -36,7 +36,15 @@ export declare const updateBoundElements: (changedElement: NonDeletedExcalidrawE
36
36
  width: number;
37
37
  height: number;
38
38
  };
39
- changedElements?: Map<string, OrderedExcalidrawElement>;
39
+ changedElements?: Map<string, ExcalidrawElement>;
40
+ }) => void;
41
+ export declare const updateBindings: (latestElement: ExcalidrawElement, scene: Scene, options?: {
42
+ simultaneouslyUpdated?: readonly ExcalidrawElement[];
43
+ newSize?: {
44
+ width: number;
45
+ height: number;
46
+ };
47
+ zoom?: AppState["zoom"];
40
48
  }) => void;
41
49
  export declare const getHeadingForElbowArrowSnap: (p: Readonly<GlobalPoint>, otherPoint: Readonly<GlobalPoint>, bindableElement: ExcalidrawBindableElement | undefined | null, aabb: Bounds | undefined | null, origPoint: GlobalPoint, zoom?: AppState["zoom"]) => Heading;
42
50
  export declare const bindPointToSnapToElementOutline: (arrow: ExcalidrawElbowArrowElement, bindableElement: ExcalidrawBindableElement, startOrEnd: "start" | "end") => GlobalPoint;
@@ -1,7 +1,7 @@
1
1
  import type { Degrees, GlobalPoint, LineSegment } from "@excalidraw/math";
2
2
  import type { AppState } from "@excalidraw/excalidraw/types";
3
- import type { ExcalidrawElement, ExcalidrawLinearElement, Arrowhead, ExcalidrawFreeDrawElement, NonDeleted, ElementsMap, ElementsMapOrArray } from "./types";
4
3
  import type { Drawable, Op } from "roughjs/bin/core";
4
+ import type { Arrowhead, ElementsMap, ElementsMapOrArray, ExcalidrawElement, ExcalidrawFreeDrawElement, ExcalidrawLinearElement, NonDeleted } from "./types";
5
5
  export type RectangleBox = {
6
6
  x: number;
7
7
  y: number;
@@ -1,7 +1,7 @@
1
- import type { ElementUpdate } from "@excalidraw/element/mutateElement";
2
1
  import type { ExcalidrawElement, Ordered, OrderedExcalidrawElement, SceneElementsMap } from "@excalidraw/element/types";
3
- import type { ValueOf } from "@excalidraw/common/utility-types";
4
- import type { AppState, ObservedAppState } from "./types";
2
+ import type { DTO, ValueOf } from "@excalidraw/common/utility-types";
3
+ import type { AppState, ObservedAppState } from "@excalidraw/excalidraw/types";
4
+ import type { ElementUpdate } from "./mutateElement";
5
5
  /**
6
6
  * Represents the difference between two objects of the same type.
7
7
  *
@@ -11,7 +11,7 @@ import type { AppState, ObservedAppState } from "./types";
11
11
  *
12
12
  * Keeping it as pure object (without transient state, side-effects, etc.), so we won't have to instantiate it on load.
13
13
  */
14
- declare class Delta<T> {
14
+ export declare class Delta<T> {
15
15
  readonly deleted: Partial<T>;
16
16
  readonly inserted: Partial<T>;
17
17
  private constructor();
@@ -56,11 +56,11 @@ declare class Delta<T> {
56
56
  */
57
57
  static isRightDifferent<T extends {}>(object1: T, object2: T, skipShallowCompare?: boolean): boolean;
58
58
  /**
59
- * Returns all the object1 keys that have distinct values.
59
+ * Returns sorted object1 keys that have distinct values.
60
60
  */
61
61
  static getLeftDifferences<T extends {}>(object1: T, object2: T, skipShallowCompare?: boolean): string[];
62
62
  /**
63
- * Returns all the object2 keys that have distinct values.
63
+ * Returns sorted object2 keys that have distinct values.
64
64
  */
65
65
  static getRightDifferences<T extends {}>(object1: T, object2: T, skipShallowCompare?: boolean): string[];
66
66
  /**
@@ -73,37 +73,33 @@ declare class Delta<T> {
73
73
  private static distinctKeysIterator;
74
74
  }
75
75
  /**
76
- * Encapsulates the modifications captured as `Delta`/s.
76
+ * Encapsulates a set of application-level `Delta`s.
77
77
  */
78
- interface Change<T> {
78
+ export interface DeltaContainer<T> {
79
79
  /**
80
- * Inverses the `Delta`s inside while creating a new `Change`.
80
+ * Inverses the `Delta`s while creating a new `DeltaContainer` instance.
81
81
  */
82
- inverse(): Change<T>;
82
+ inverse(): DeltaContainer<T>;
83
83
  /**
84
- * Applies the `Change` to the previous object.
84
+ * Applies the `Delta`s to the previous object.
85
85
  *
86
- * @returns a tuple of the next object `T` with applied change, and `boolean`, indicating whether the applied change resulted in a visible change.
86
+ * @returns a tuple of the next object `T` with applied `Delta`s, and `boolean`, indicating whether the applied deltas resulted in a visible change.
87
87
  */
88
88
  applyTo(previous: T, ...options: unknown[]): [T, boolean];
89
89
  /**
90
- * Checks whether there are actually `Delta`s.
90
+ * Checks whether all `Delta`s are empty.
91
91
  */
92
92
  isEmpty(): boolean;
93
93
  }
94
- export declare class AppStateChange implements Change<AppState> {
95
- private readonly delta;
94
+ export declare class AppStateDelta implements DeltaContainer<AppState> {
95
+ readonly delta: Delta<ObservedAppState>;
96
96
  private constructor();
97
- static calculate<T extends ObservedAppState>(prevAppState: T, nextAppState: T): AppStateChange;
98
- static empty(): AppStateChange;
99
- inverse(): AppStateChange;
97
+ static calculate<T extends ObservedAppState>(prevAppState: T, nextAppState: T): AppStateDelta;
98
+ static restore(appStateDeltaDTO: DTO<AppStateDelta>): AppStateDelta;
99
+ static empty(): AppStateDelta;
100
+ inverse(): AppStateDelta;
100
101
  applyTo(appState: AppState, nextElements: SceneElementsMap): [AppState, boolean];
101
102
  isEmpty(): boolean;
102
- /**
103
- * It is necessary to post process the partials in case of reference values,
104
- * for which we need to calculate the real diff between `deleted` and `inserted`.
105
- */
106
- private static postProcess;
107
103
  /**
108
104
  * Mutates `nextAppState` be filtering out state related to deleted elements.
109
105
  *
@@ -115,20 +111,27 @@ export declare class AppStateChange implements Change<AppState> {
115
111
  private static filterSelectedGroups;
116
112
  private static stripElementsProps;
117
113
  private static stripStandaloneProps;
114
+ /**
115
+ * It is necessary to post process the partials in case of reference values,
116
+ * for which we need to calculate the real diff between `deleted` and `inserted`.
117
+ */
118
+ private static postProcess;
119
+ private static orderAppStateKeys;
118
120
  }
119
121
  type ElementPartial<T extends ExcalidrawElement = ExcalidrawElement> = Omit<ElementUpdate<Ordered<T>>, "seed">;
120
122
  /**
121
123
  * Elements change is a low level primitive to capture a change between two sets of elements.
122
124
  * It does so by encapsulating forward and backward `Delta`s, allowing to time-travel in both directions.
123
125
  */
124
- export declare class ElementsChange implements Change<SceneElementsMap> {
125
- private readonly added;
126
- private readonly removed;
127
- private readonly updated;
126
+ export declare class ElementsDelta implements DeltaContainer<SceneElementsMap> {
127
+ readonly added: Record<string, Delta<ElementPartial>>;
128
+ readonly removed: Record<string, Delta<ElementPartial>>;
129
+ readonly updated: Record<string, Delta<ElementPartial>>;
128
130
  private constructor();
129
- static create(added: Map<string, Delta<ElementPartial>>, removed: Map<string, Delta<ElementPartial>>, updated: Map<string, Delta<ElementPartial>>, options?: {
131
+ static create(added: Record<string, Delta<ElementPartial>>, removed: Record<string, Delta<ElementPartial>>, updated: Record<string, Delta<ElementPartial>>, options?: {
130
132
  shouldRedistribute: boolean;
131
- }): ElementsChange;
133
+ }): ElementsDelta;
134
+ static restore(elementsDeltaDTO: DTO<ElementsDelta>): ElementsDelta;
132
135
  private static satisfiesAddition;
133
136
  private static satisfiesRemoval;
134
137
  private static satisfiesUpdate;
@@ -139,11 +142,11 @@ export declare class ElementsChange implements Change<SceneElementsMap> {
139
142
  * @param prevElements - Map representing the previous state of elements.
140
143
  * @param nextElements - Map representing the next state of elements.
141
144
  *
142
- * @returns `ElementsChange` instance representing the `Delta` changes between the two sets of elements.
145
+ * @returns `ElementsDelta` instance representing the `Delta` changes between the two sets of elements.
143
146
  */
144
- static calculate<T extends OrderedExcalidrawElement>(prevElements: Map<string, T>, nextElements: Map<string, T>): ElementsChange;
145
- static empty(): ElementsChange;
146
- inverse(): ElementsChange;
147
+ static calculate<T extends OrderedExcalidrawElement>(prevElements: Map<string, T>, nextElements: Map<string, T>): ElementsDelta;
148
+ static empty(): ElementsDelta;
149
+ inverse(): ElementsDelta;
147
150
  isEmpty(): boolean;
148
151
  /**
149
152
  * Update delta/s based on the existing elements.
@@ -152,8 +155,8 @@ export declare class ElementsChange implements Change<SceneElementsMap> {
152
155
  * @param modifierOptions defines which of the delta (`deleted` or `inserted`) will be updated
153
156
  * @returns new instance with modified delta/s
154
157
  */
155
- applyLatestChanges(elements: SceneElementsMap): ElementsChange;
156
- applyTo(elements: SceneElementsMap, snapshot: Map<string, OrderedExcalidrawElement>): [SceneElementsMap, boolean];
158
+ applyLatestChanges(elements: SceneElementsMap, modifierOptions: "deleted" | "inserted"): ElementsDelta;
159
+ applyTo(elements: SceneElementsMap, elementsSnapshot: Map<string, OrderedExcalidrawElement>): [SceneElementsMap, boolean];
157
160
  private static createApplier;
158
161
  private static createGetter;
159
162
  private static applyDelta;
@@ -165,6 +168,8 @@ export declare class ElementsChange implements Change<SceneElementsMap> {
165
168
  * Resolves conflicts for all previously added, removed and updated elements.
166
169
  * Updates the previous deltas with all the changes after conflict resolution.
167
170
  *
171
+ * // TODO: revisit since some bound arrows seem to be often redrawn incorrectly
172
+ *
168
173
  * @returns all elements affected by the conflict resolution
169
174
  */
170
175
  private resolveConflicts;
@@ -64,6 +64,7 @@ export declare const isElementInFrame: (element: ExcalidrawElement, allElementsM
64
64
  checkedGroups?: Map<string, boolean>;
65
65
  }) => boolean;
66
66
  export declare const shouldApplyFrameClip: (element: ExcalidrawElement, frame: ExcalidrawFrameLikeElement, appState: StaticCanvasAppState, elementsMap: ElementsMap, checkedGroups?: Map<string, boolean>) => boolean;
67
+ export declare const getDefaultFrameName: (element: ExcalidrawFrameLikeElement) => "Frame" | "AI Frame";
67
68
  export declare const getFrameLikeTitle: (element: ExcalidrawFrameLikeElement) => string;
68
69
  export declare const getElementsOverlappingFrame: (elements: readonly ExcalidrawElement[], frame: ExcalidrawFrameLikeElement) => NonDeletedExcalidrawElement[];
69
70
  export declare const frameAndChildrenSelectedTogether: (selectedElements: readonly ExcalidrawElement[]) => boolean;
@@ -1,4 +1,4 @@
1
- import type { ExcalidrawElement, NonDeletedExcalidrawElement, NonDeleted } from "./types";
1
+ import type { ExcalidrawElement, NonDeletedExcalidrawElement, NonDeleted, ElementsMapOrArray } from "./types";
2
2
  /**
3
3
  * @deprecated unsafe, use hashElementsVersion instead
4
4
  */
@@ -6,7 +6,7 @@ export declare const getSceneVersion: (elements: readonly ExcalidrawElement[]) =
6
6
  /**
7
7
  * Hashes elements' versionNonce (using djb2 algo). Order of elements matters.
8
8
  */
9
- export declare const hashElementsVersion: (elements: readonly ExcalidrawElement[]) => number;
9
+ export declare const hashElementsVersion: (elements: ElementsMapOrArray) => number;
10
10
  export declare const hashString: (s: string) => number;
11
11
  export declare const getVisibleElements: (elements: readonly ExcalidrawElement[]) => readonly NonDeletedExcalidrawElement[];
12
12
  export declare const getNonDeletedElements: <T extends ExcalidrawElement>(elements: readonly T[]) => readonly NonDeleted<T>[];
@@ -1,10 +1,10 @@
1
1
  /// <reference types="react" />
2
2
  import { type GlobalPoint, type LocalPoint } from "@excalidraw/math";
3
- import type { Store } from "@excalidraw/excalidraw/store";
3
+ import type { Store } from "@excalidraw/element/store";
4
4
  import type { AppState, PointerCoords, InteractiveCanvasAppState, AppClassProperties, NullableGridSize, Zoom } from "@excalidraw/excalidraw/types";
5
5
  import type Scene from "./Scene";
6
6
  import type { Bounds } from "./bounds";
7
- import type { NonDeleted, ExcalidrawLinearElement, ExcalidrawElement, PointBinding, ExcalidrawBindableElement, ExcalidrawTextElementWithContainer, ElementsMap, NonDeletedSceneElementsMap, ExcalidrawElbowArrowElement } from "./types";
7
+ import type { NonDeleted, ExcalidrawLinearElement, ExcalidrawElement, PointBinding, ExcalidrawBindableElement, ExcalidrawTextElementWithContainer, ElementsMap, NonDeletedSceneElementsMap, ExcalidrawElbowArrowElement, PointsPositionUpdates } from "./types";
8
8
  declare const editorMidPointsCache: {
9
9
  version: number | null;
10
10
  points: (GlobalPoint | null)[];
@@ -103,11 +103,7 @@ export declare class LinearElementEditor {
103
103
  static addPoints(element: NonDeleted<ExcalidrawLinearElement>, scene: Scene, targetPoints: {
104
104
  point: LocalPoint;
105
105
  }[]): void;
106
- static movePoints(element: NonDeleted<ExcalidrawLinearElement>, scene: Scene, targetPoints: {
107
- index: number;
108
- point: LocalPoint;
109
- isDragging?: boolean;
110
- }[], otherUpdates?: {
106
+ static movePoints(element: NonDeleted<ExcalidrawLinearElement>, scene: Scene, pointUpdates: PointsPositionUpdates, otherUpdates?: {
111
107
  startBinding?: PointBinding | null;
112
108
  endBinding?: PointBinding | null;
113
109
  }): void;
@@ -1,5 +1,5 @@
1
1
  import type { MarkOptional } from "@excalidraw/common/utility-types";
2
- import type { ExcalidrawImageElement, ExcalidrawTextElement, ExcalidrawLinearElement, ExcalidrawGenericElement, NonDeleted, TextAlign, VerticalAlign, Arrowhead, ExcalidrawFreeDrawElement, FontFamilyValues, ExcalidrawTextContainer, ExcalidrawFrameElement, ExcalidrawEmbeddableElement, ExcalidrawMagicFrameElement, ExcalidrawIframeElement, ElementsMap, ExcalidrawArrowElement, FixedSegment, ExcalidrawElbowArrowElement } from "./types";
2
+ import type { ExcalidrawImageElement, ExcalidrawTextElement, ExcalidrawLinearElement, ExcalidrawGenericElement, NonDeleted, TextAlign, VerticalAlign, Arrowhead, ExcalidrawFreeDrawElement, FontFamilyValues, ExcalidrawTextContainer, ExcalidrawFrameElement, ExcalidrawEmbeddableElement, ExcalidrawMagicFrameElement, ExcalidrawIframeElement, ElementsMap, ExcalidrawArrowElement, ExcalidrawElbowArrowElement } from "./types";
3
3
  export type ElementConstructorOpts = MarkOptional<Omit<ExcalidrawGenericElement, "id" | "type" | "isDeleted" | "updated">, "width" | "height" | "angle" | "groupIds" | "frameId" | "index" | "boundElements" | "seed" | "version" | "versionNonce" | "link" | "strokeStyle" | "fillStyle" | "strokeColor" | "backgroundColor" | "roughness" | "strokeWidth" | "roundness" | "locked" | "opacity" | "customData">;
4
4
  export declare const newElement: (opts: {
5
5
  type: ExcalidrawGenericElement["type"];
@@ -50,7 +50,7 @@ export declare const newArrowElement: <T extends boolean>(opts: {
50
50
  endArrowhead?: Arrowhead | null | undefined;
51
51
  points?: readonly import("@excalidraw/math").LocalPoint[] | undefined;
52
52
  elbowed?: T | undefined;
53
- fixedSegments?: FixedSegment[] | null | undefined;
53
+ fixedSegments?: readonly import("./types").FixedSegment[] | null | undefined;
54
54
  } & Omit<Omit<ExcalidrawGenericElement, "id" | "isDeleted" | "updated" | "type">, "link" | "angle" | "strokeColor" | "backgroundColor" | "fillStyle" | "strokeWidth" | "strokeStyle" | "roundness" | "roughness" | "opacity" | "width" | "height" | "seed" | "version" | "versionNonce" | "index" | "groupIds" | "frameId" | "boundElements" | "locked" | "customData"> & Partial<Pick<Omit<ExcalidrawGenericElement, "id" | "isDeleted" | "updated" | "type">, "link" | "angle" | "strokeColor" | "backgroundColor" | "fillStyle" | "strokeWidth" | "strokeStyle" | "roundness" | "roughness" | "opacity" | "width" | "height" | "seed" | "version" | "versionNonce" | "index" | "groupIds" | "frameId" | "boundElements" | "locked" | "customData">>) => T extends true ? NonDeleted<ExcalidrawElbowArrowElement> : NonDeleted<ExcalidrawArrowElement>;
55
55
  export declare const newImageElement: (opts: {
56
56
  type: ExcalidrawImageElement["type"];
@@ -0,0 +1,227 @@
1
+ import { Emitter } from "@excalidraw/common";
2
+ import type App from "@excalidraw/excalidraw/components/App";
3
+ import type { DTO, ValueOf } from "@excalidraw/common/utility-types";
4
+ import type { AppState, ObservedAppState } from "@excalidraw/excalidraw/types";
5
+ import { ElementsDelta, AppStateDelta } from "./delta";
6
+ import type { OrderedExcalidrawElement, SceneElementsMap } from "./types";
7
+ export declare const CaptureUpdateAction: {
8
+ /**
9
+ * Immediately undoable.
10
+ *
11
+ * Use for updates which should be captured.
12
+ * Should be used for most of the local updates, except ephemerals such as dragging or resizing.
13
+ *
14
+ * These updates will _immediately_ make it to the local undo / redo stacks.
15
+ */
16
+ readonly IMMEDIATELY: "IMMEDIATELY";
17
+ /**
18
+ * Never undoable.
19
+ *
20
+ * Use for updates which should never be recorded, such as remote updates
21
+ * or scene initialization.
22
+ *
23
+ * These updates will _never_ make it to the local undo / redo stacks.
24
+ */
25
+ readonly NEVER: "NEVER";
26
+ /**
27
+ * Eventually undoable.
28
+ *
29
+ * Use for updates which should not be captured immediately - likely
30
+ * exceptions which are part of some async multi-step process. Otherwise, all
31
+ * such updates would end up being captured with the next
32
+ * `CaptureUpdateAction.IMMEDIATELY` - triggered either by the next `updateScene`
33
+ * or internally by the editor.
34
+ *
35
+ * These updates will _eventually_ make it to the local undo / redo stacks.
36
+ */
37
+ readonly EVENTUALLY: "EVENTUALLY";
38
+ };
39
+ export type CaptureUpdateActionType = ValueOf<typeof CaptureUpdateAction>;
40
+ /**
41
+ * Store which captures the observed changes and emits them as `StoreIncrement` events.
42
+ */
43
+ export declare class Store {
44
+ private readonly app;
45
+ readonly onDurableIncrementEmitter: Emitter<[DurableIncrement]>;
46
+ readonly onStoreIncrementEmitter: Emitter<[DurableIncrement | EphemeralIncrement]>;
47
+ private scheduledMacroActions;
48
+ private scheduledMicroActions;
49
+ private _snapshot;
50
+ get snapshot(): StoreSnapshot;
51
+ set snapshot(snapshot: StoreSnapshot);
52
+ constructor(app: App);
53
+ scheduleAction(action: CaptureUpdateActionType): void;
54
+ /**
55
+ * Use to schedule a delta calculation, which will consquentially be emitted as `DurableStoreIncrement` and pushed in the undo stack.
56
+ */
57
+ scheduleCapture(): void;
58
+ /**
59
+ * Schedule special "micro" actions, to-be executed before the next commit, before it executes a scheduled "macro" action.
60
+ */
61
+ scheduleMicroAction(params: {
62
+ action: CaptureUpdateActionType;
63
+ elements: SceneElementsMap | undefined;
64
+ appState: AppState | ObservedAppState | undefined;
65
+ } | {
66
+ action: typeof CaptureUpdateAction.IMMEDIATELY;
67
+ change: StoreChange;
68
+ delta: StoreDelta;
69
+ } | {
70
+ action: typeof CaptureUpdateAction.NEVER | typeof CaptureUpdateAction.EVENTUALLY;
71
+ change: StoreChange;
72
+ }): void;
73
+ /**
74
+ * Performs the incoming `CaptureUpdateAction` and emits the corresponding `StoreIncrement`.
75
+ * Emits `DurableStoreIncrement` when action is "capture", emits `EphemeralStoreIncrement` otherwise.
76
+ *
77
+ * @emits StoreIncrement
78
+ */
79
+ commit(elements: SceneElementsMap | undefined, appState: AppState | ObservedAppState | undefined): void;
80
+ /**
81
+ * Clears the store instance.
82
+ */
83
+ clear(): void;
84
+ /**
85
+ * Performs delta & change calculation and emits a durable increment.
86
+ *
87
+ * @emits StoreIncrement.
88
+ */
89
+ private emitDurableIncrement;
90
+ /**
91
+ * Performs change calculation and emits an ephemeral increment.
92
+ *
93
+ * @emits EphemeralStoreIncrement
94
+ */
95
+ private emitEphemeralIncrement;
96
+ private applyChangeToSnapshot;
97
+ /**
98
+ * Clones the snapshot if there are changes detected.
99
+ */
100
+ private maybeCloneSnapshot;
101
+ private flushMicroActions;
102
+ private processAction;
103
+ /**
104
+ * Returns the scheduled macro action.
105
+ */
106
+ private getScheduledMacroAction;
107
+ /**
108
+ * Ensures that the scheduled actions invariant is satisfied.
109
+ */
110
+ private satisfiesScheduledActionsInvariant;
111
+ }
112
+ /**
113
+ * Repsents a change to the store containing changed elements and appState.
114
+ */
115
+ export declare class StoreChange {
116
+ readonly elements: Record<string, OrderedExcalidrawElement>;
117
+ readonly appState: Partial<ObservedAppState>;
118
+ private constructor();
119
+ static create(prevSnapshot: StoreSnapshot, nextSnapshot: StoreSnapshot): StoreChange;
120
+ }
121
+ /**
122
+ * Encpasulates any change to the store (durable or ephemeral).
123
+ */
124
+ export declare abstract class StoreIncrement {
125
+ readonly type: "durable" | "ephemeral";
126
+ readonly change: StoreChange;
127
+ protected constructor(type: "durable" | "ephemeral", change: StoreChange);
128
+ static isDurable(increment: StoreIncrement): increment is DurableIncrement;
129
+ static isEphemeral(increment: StoreIncrement): increment is EphemeralIncrement;
130
+ }
131
+ /**
132
+ * Represents a durable change to the store.
133
+ */
134
+ export declare class DurableIncrement extends StoreIncrement {
135
+ readonly change: StoreChange;
136
+ readonly delta: StoreDelta;
137
+ constructor(change: StoreChange, delta: StoreDelta);
138
+ }
139
+ /**
140
+ * Represents an ephemeral change to the store.
141
+ */
142
+ export declare class EphemeralIncrement extends StoreIncrement {
143
+ readonly change: StoreChange;
144
+ constructor(change: StoreChange);
145
+ }
146
+ /**
147
+ * Represents a captured delta by the Store.
148
+ */
149
+ export declare class StoreDelta {
150
+ readonly id: string;
151
+ readonly elements: ElementsDelta;
152
+ readonly appState: AppStateDelta;
153
+ protected constructor(id: string, elements: ElementsDelta, appState: AppStateDelta);
154
+ /**
155
+ * Create a new instance of `StoreDelta`.
156
+ */
157
+ static create(elements: ElementsDelta, appState: AppStateDelta, opts?: {
158
+ id: string;
159
+ }): StoreDelta;
160
+ /**
161
+ * Restore a store delta instance from a DTO.
162
+ */
163
+ static restore(storeDeltaDTO: DTO<StoreDelta>): StoreDelta;
164
+ /**
165
+ * Parse and load the delta from the remote payload.
166
+ */
167
+ static load({ id, elements: { added, removed, updated }, }: DTO<StoreDelta>): StoreDelta;
168
+ /**
169
+ * Inverse store delta, creates new instance of `StoreDelta`.
170
+ */
171
+ static inverse(delta: StoreDelta): StoreDelta;
172
+ /**
173
+ * Apply latest (remote) changes to the delta, creates new instance of `StoreDelta`.
174
+ */
175
+ static applyLatestChanges(delta: StoreDelta, elements: SceneElementsMap, modifierOptions: "deleted" | "inserted"): StoreDelta;
176
+ /**
177
+ * Apply the delta to the passed elements and appState, does not modify the snapshot.
178
+ */
179
+ static applyTo(delta: StoreDelta, elements: SceneElementsMap, appState: AppState, prevSnapshot?: StoreSnapshot): [SceneElementsMap, AppState, boolean];
180
+ isEmpty(): boolean;
181
+ }
182
+ /**
183
+ * Represents a snapshot of the captured or updated changes in the store,
184
+ * used for producing deltas and emitting `DurableStoreIncrement`s.
185
+ */
186
+ export declare class StoreSnapshot {
187
+ readonly elements: SceneElementsMap;
188
+ readonly appState: ObservedAppState;
189
+ readonly metadata: {
190
+ didElementsChange: boolean;
191
+ didAppStateChange: boolean;
192
+ isEmpty?: boolean;
193
+ };
194
+ private _lastChangedElementsHash;
195
+ private _lastChangedAppStateHash;
196
+ private constructor();
197
+ static create(elements: SceneElementsMap, appState: AppState | ObservedAppState, metadata?: {
198
+ didElementsChange: boolean;
199
+ didAppStateChange: boolean;
200
+ }): StoreSnapshot;
201
+ static empty(): StoreSnapshot;
202
+ getChangedElements(prevSnapshot: StoreSnapshot): Record<string, OrderedExcalidrawElement>;
203
+ getChangedAppState(prevSnapshot: StoreSnapshot): Partial<ObservedAppState>;
204
+ isEmpty(): boolean | undefined;
205
+ /**
206
+ * Apply the change and return a new snapshot instance.
207
+ */
208
+ applyChange(change: StoreChange): StoreSnapshot;
209
+ /**
210
+ * Efficiently clone the existing snapshot, only if we detected changes.
211
+ *
212
+ * @returns same instance if there are no changes detected, new instance otherwise.
213
+ */
214
+ maybeClone(action: CaptureUpdateActionType, elements: SceneElementsMap | undefined, appState: AppState | ObservedAppState | undefined): StoreSnapshot;
215
+ private maybeCreateAppStateSnapshot;
216
+ private maybeCreateElementsSnapshot;
217
+ private detectChangedAppState;
218
+ /**
219
+ * Detect if there any changed elements.
220
+ */
221
+ private detectChangedElements;
222
+ /**
223
+ * Perform structural clone, deep cloning only elements that changed.
224
+ */
225
+ private createElementsSnapshot;
226
+ }
227
+ export declare const getObservedAppState: (appState: AppState) => ObservedAppState;
@@ -31,8 +31,8 @@ export declare const OMIT_SIDES_FOR_FRAME: {
31
31
  export declare const canResizeFromSides: (device: Device) => boolean;
32
32
  export declare const getOmitSidesForDevice: (device: Device) => {};
33
33
  export declare const getTransformHandlesFromCoords: ([x1, y1, x2, y2, cx, cy]: [number, number, number, number, number, number], angle: Radians, zoom: Zoom, pointerType: PointerType, omitSides?: {
34
- s?: boolean | undefined;
35
34
  n?: boolean | undefined;
35
+ s?: boolean | undefined;
36
36
  w?: boolean | undefined;
37
37
  e?: boolean | undefined;
38
38
  nw?: boolean | undefined;
@@ -42,8 +42,8 @@ export declare const getTransformHandlesFromCoords: ([x1, y1, x2, y2, cx, cy]: [
42
42
  rotation?: boolean | undefined;
43
43
  }, margin?: number, spacing?: number) => TransformHandles;
44
44
  export declare const getTransformHandles: (element: ExcalidrawElement, zoom: Zoom, elementsMap: ElementsMap, pointerType?: PointerType, omitSides?: {
45
- s?: boolean | undefined;
46
45
  n?: boolean | undefined;
46
+ s?: boolean | undefined;
47
47
  w?: boolean | undefined;
48
48
  e?: boolean | undefined;
49
49
  nw?: boolean | undefined;
@@ -16,6 +16,8 @@ export declare const isFreeDrawElementType: (elementType: ExcalidrawElementType)
16
16
  export declare const isLinearElement: (element?: ExcalidrawElement | null) => element is ExcalidrawLinearElement;
17
17
  export declare const isArrowElement: (element?: ExcalidrawElement | null) => element is ExcalidrawArrowElement;
18
18
  export declare const isElbowArrow: (element?: ExcalidrawElement) => element is ExcalidrawElbowArrowElement;
19
+ export declare const isSharpArrow: (element?: ExcalidrawElement) => element is ExcalidrawArrowElement;
20
+ export declare const isCurvedArrow: (element?: ExcalidrawElement) => element is ExcalidrawArrowElement;
19
21
  export declare const isLinearElementType: (elementType: ElementOrToolType) => boolean;
20
22
  export declare const isBindingElement: (element?: ExcalidrawElement | null, includeLocked?: boolean) => element is ExcalidrawLinearElement;
21
23
  export declare const isBindingElementType: (elementType: ElementOrToolType) => boolean;
@@ -27,6 +29,7 @@ export declare const isExcalidrawElement: (element: any) => element is Excalidra
27
29
  export declare const isFlowchartNodeElement: (element: ExcalidrawElement) => element is ExcalidrawFlowchartNodeElement;
28
30
  export declare const hasBoundTextElement: (element: ExcalidrawElement | null) => element is MarkNonNullable<ExcalidrawBindableElement, "boundElements">;
29
31
  export declare const isBoundToContainer: (element: ExcalidrawElement | null) => element is ExcalidrawTextElementWithContainer;
32
+ export declare const isArrowBoundToElement: (element: ExcalidrawArrowElement) => boolean;
30
33
  export declare const isUsingAdaptiveRadius: (type: string) => boolean;
31
34
  export declare const isUsingProportionalRadius: (type: string) => boolean;
32
35
  export declare const canApplyRoundnessTypeToElement: (roundnessType: RoundnessType, element: ExcalidrawElement) => boolean;
@@ -205,6 +205,10 @@ export type PointBinding = {
205
205
  export type FixedPointBinding = Merge<PointBinding, {
206
206
  fixedPoint: FixedPoint;
207
207
  }>;
208
+ export type PointsPositionUpdates = Map<number, {
209
+ point: LocalPoint;
210
+ isDragging?: boolean;
211
+ }>;
208
212
  export type Arrowhead = "arrow" | "bar" | "dot" | "circle" | "circle_outline" | "triangle" | "triangle_outline" | "diamond" | "diamond_outline" | "crowfoot_one" | "crowfoot_many" | "crowfoot_one_or_many";
209
213
  export type ExcalidrawLinearElement = _ExcalidrawElementBase & Readonly<{
210
214
  type: "line" | "arrow";
@@ -279,4 +283,7 @@ export type SceneElementsMap = Map<ExcalidrawElement["id"], Ordered<ExcalidrawEl
279
283
  */
280
284
  export type NonDeletedSceneElementsMap = Map<ExcalidrawElement["id"], Ordered<NonDeletedExcalidrawElement>> & MakeBrand<"NonDeletedSceneElementsMap">;
281
285
  export type ElementsMapOrArray = readonly ExcalidrawElement[] | Readonly<ElementsMap>;
286
+ export type ConvertibleGenericTypes = "rectangle" | "diamond" | "ellipse";
287
+ export type ConvertibleLinearTypes = "line" | "sharpArrow" | "curvedArrow" | "elbowArrow";
288
+ export type ConvertibleTypes = ConvertibleGenericTypes | ConvertibleLinearTypes;
282
289
  export {};