@excalidraw/excalidraw 0.18.0-c4c0649 → 0.18.0-c6f8ef9

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 (130) hide show
  1. package/dist/dev/chunk-CP5DND7P.js +7 -0
  2. package/dist/dev/chunk-CP5DND7P.js.map +7 -0
  3. package/dist/dev/chunk-CRKRRBMD.js +5677 -0
  4. package/dist/dev/chunk-CRKRRBMD.js.map +7 -0
  5. package/dist/dev/{chunk-JCUIYZXF.js → chunk-QF5FRM6O.js} +6 -2
  6. package/dist/dev/chunk-QF5FRM6O.js.map +7 -0
  7. package/dist/dev/data/{image-SLEZBMLG.js → image-IWGLHPIX.js} +3 -3
  8. package/dist/dev/index.css +51 -20
  9. package/dist/dev/index.css.map +3 -3
  10. package/dist/dev/index.js +6874 -4280
  11. package/dist/dev/index.js.map +4 -4
  12. package/dist/dev/locales/{en-ZDTPSZNL.js → en-SMAPCEOQ.js} +2 -2
  13. package/dist/dev/subset-shared.chunk.js +1 -1
  14. package/dist/dev/subset-worker.chunk.js +1 -1
  15. package/dist/prod/chunk-A66AFZZU.js +7 -0
  16. package/dist/prod/chunk-HHV2PJKY.js +4 -0
  17. package/dist/prod/{chunk-GCFVWREF.js → chunk-I4UNSFV6.js} +4 -4
  18. package/dist/prod/data/image-4SM4COIL.js +1 -0
  19. package/dist/prod/index.css +1 -1
  20. package/dist/prod/index.js +25 -18
  21. package/dist/prod/locales/{en-MHZ26NAR.js → en-TYY6KWIJ.js} +1 -1
  22. package/dist/prod/subset-shared.chunk.js +1 -1
  23. package/dist/prod/subset-worker.chunk.js +1 -1
  24. package/dist/types/common/src/constants.d.ts +19 -3
  25. package/dist/types/common/src/utils.d.ts +3 -5
  26. package/dist/types/element/src/Scene.d.ts +7 -3
  27. package/dist/types/element/src/align.d.ts +2 -1
  28. package/dist/types/element/src/binding.d.ts +10 -7
  29. package/dist/types/element/src/bounds.d.ts +11 -3
  30. package/dist/types/element/src/collision.d.ts +18 -12
  31. package/dist/types/element/src/cropElement.d.ts +1 -1
  32. package/dist/types/element/src/delta.d.ts +42 -9
  33. package/dist/types/element/src/distance.d.ts +2 -2
  34. package/dist/types/element/src/distribute.d.ts +2 -1
  35. package/dist/types/element/src/fractionalIndex.d.ts +8 -2
  36. package/dist/types/element/src/frame.d.ts +2 -2
  37. package/dist/types/element/src/groups.d.ts +1 -0
  38. package/dist/types/element/src/index.d.ts +1 -3
  39. package/dist/types/element/src/linearElementEditor.d.ts +14 -23
  40. package/dist/types/element/src/mutateElement.d.ts +1 -1
  41. package/dist/types/element/src/newElement.d.ts +2 -1
  42. package/dist/types/element/src/resizeElements.d.ts +1 -0
  43. package/dist/types/element/src/selection.d.ts +1 -1
  44. package/dist/types/element/src/shape.d.ts +42 -0
  45. package/dist/types/element/src/sizeHelpers.d.ts +2 -1
  46. package/dist/types/element/src/store.d.ts +19 -9
  47. package/dist/types/element/src/transformHandles.d.ts +4 -4
  48. package/dist/types/element/src/typeChecks.d.ts +15 -1
  49. package/dist/types/element/src/types.d.ts +8 -3
  50. package/dist/types/element/src/utils.d.ts +16 -6
  51. package/dist/types/excalidraw/actions/actionAddToLibrary.d.ts +21 -15
  52. package/dist/types/excalidraw/actions/actionAlign.d.ts +8 -8
  53. package/dist/types/excalidraw/actions/actionBoundText.d.ts +14 -10
  54. package/dist/types/excalidraw/actions/actionCanvas.d.ts +180 -154
  55. package/dist/types/excalidraw/actions/actionClipboard.d.ts +50 -36
  56. package/dist/types/excalidraw/actions/actionCropEditor.d.ts +7 -5
  57. package/dist/types/excalidraw/actions/actionDeleteSelected.d.ts +27 -20
  58. package/dist/types/excalidraw/actions/actionDistribute.d.ts +4 -4
  59. package/dist/types/excalidraw/actions/actionDuplicateSelection.d.ts +2 -2
  60. package/dist/types/excalidraw/actions/actionElementLink.d.ts +6 -4
  61. package/dist/types/excalidraw/actions/actionElementLock.d.ts +29 -26
  62. package/dist/types/excalidraw/actions/actionEmbeddable.d.ts +7 -5
  63. package/dist/types/excalidraw/actions/actionExport.d.ts +147 -129
  64. package/dist/types/excalidraw/actions/actionFinalize.d.ts +65 -20
  65. package/dist/types/excalidraw/actions/actionFlip.d.ts +4 -4
  66. package/dist/types/excalidraw/actions/actionFrame.d.ts +78 -70
  67. package/dist/types/excalidraw/actions/actionGroup.d.ts +20 -16
  68. package/dist/types/excalidraw/actions/actionLinearEditor.d.ts +533 -7
  69. package/dist/types/excalidraw/actions/actionLink.d.ts +8 -6
  70. package/dist/types/excalidraw/actions/actionMenu.d.ts +22 -16
  71. package/dist/types/excalidraw/actions/actionNavigate.d.ts +14 -10
  72. package/dist/types/excalidraw/actions/actionProperties.d.ts +119 -81
  73. package/dist/types/excalidraw/actions/actionSelectAll.d.ts +10 -8
  74. package/dist/types/excalidraw/actions/actionStyles.d.ts +11 -9
  75. package/dist/types/excalidraw/actions/actionToggleGridMode.d.ts +9 -7
  76. package/dist/types/excalidraw/actions/actionToggleObjectsSnapMode.d.ts +9 -7
  77. package/dist/types/excalidraw/actions/actionToggleSearchMenu.d.ts +8 -6
  78. package/dist/types/excalidraw/actions/actionToggleStats.d.ts +9 -7
  79. package/dist/types/excalidraw/actions/actionToggleViewMode.d.ts +9 -7
  80. package/dist/types/excalidraw/actions/actionToggleZenMode.d.ts +9 -7
  81. package/dist/types/excalidraw/actions/actionZindex.d.ts +8 -8
  82. package/dist/types/excalidraw/actions/types.d.ts +2 -1
  83. package/dist/types/excalidraw/appState.d.ts +29 -20
  84. package/dist/types/excalidraw/components/Actions.d.ts +0 -4
  85. package/dist/types/excalidraw/components/App.d.ts +15 -16
  86. package/dist/types/excalidraw/components/ButtonIcon.d.ts +1 -0
  87. package/dist/types/excalidraw/components/Ellipsify.d.ts +4 -0
  88. package/dist/types/excalidraw/components/{ButtonIconSelect.d.ts → RadioSelection.d.ts} +1 -1
  89. package/dist/types/excalidraw/components/Stats/DragInput.d.ts +11 -1
  90. package/dist/types/excalidraw/components/UnlockPopup.d.ts +8 -0
  91. package/dist/types/excalidraw/components/hyperlink/helpers.d.ts +1 -0
  92. package/dist/types/excalidraw/components/icons.d.ts +2 -0
  93. package/dist/types/excalidraw/components/shapes.d.ts +1 -1
  94. package/dist/types/excalidraw/data/blob.d.ts +1 -1
  95. package/dist/types/excalidraw/data/reconcile.d.ts +1 -0
  96. package/dist/types/excalidraw/data/restore.d.ts +6 -1
  97. package/dist/types/excalidraw/eraser/index.d.ts +0 -2
  98. package/dist/types/excalidraw/history.d.ts +21 -5
  99. package/dist/types/excalidraw/index.d.ts +2 -1
  100. package/dist/types/excalidraw/lasso/index.d.ts +1 -0
  101. package/dist/types/excalidraw/lasso/utils.d.ts +2 -1
  102. package/dist/types/excalidraw/renderer/helpers.d.ts +4 -4
  103. package/dist/types/excalidraw/renderer/staticScene.d.ts +4 -1
  104. package/dist/types/excalidraw/scene/Renderer.d.ts +0 -1
  105. package/dist/types/excalidraw/types.d.ts +15 -8
  106. package/dist/types/math/src/angle.d.ts +2 -0
  107. package/dist/types/math/src/constants.d.ts +3 -0
  108. package/dist/types/math/src/curve.d.ts +32 -0
  109. package/dist/types/math/src/index.d.ts +1 -0
  110. package/dist/types/math/src/point.d.ts +1 -1
  111. package/dist/types/math/src/rectangle.d.ts +2 -0
  112. package/dist/types/math/src/vector.d.ts +4 -2
  113. package/history.ts +107 -44
  114. package/package.json +12 -9
  115. package/dist/dev/chunk-HNRFOURL.js +0 -23482
  116. package/dist/dev/chunk-HNRFOURL.js.map +0 -7
  117. package/dist/dev/chunk-JCUIYZXF.js.map +0 -7
  118. package/dist/dev/chunk-VKWYDXFZ.js +0 -7
  119. package/dist/dev/chunk-VKWYDXFZ.js.map +0 -7
  120. package/dist/prod/chunk-G6SRO7HP.js +0 -7
  121. package/dist/prod/chunk-M3D5LUUK.js +0 -33
  122. package/dist/prod/data/image-PMKVN4IF.js +0 -1
  123. package/dist/types/element/src/Shape.d.ts +0 -17
  124. package/dist/types/element/src/ShapeCache.d.ts +0 -25
  125. package/dist/types/element/src/shapes.d.ts +0 -23
  126. package/dist/types/excalidraw/components/ButtonSelect.d.ts +0 -9
  127. package/dist/types/excalidraw/visualdebug.d.ts +0 -41
  128. package/dist/types/utils/src/collision.d.ts +0 -8
  129. /package/dist/dev/data/{image-SLEZBMLG.js.map → image-IWGLHPIX.js.map} +0 -0
  130. /package/dist/dev/locales/{en-ZDTPSZNL.js.map → en-SMAPCEOQ.js.map} +0 -0
package/history.ts CHANGED
@@ -4,14 +4,81 @@ import {
4
4
  CaptureUpdateAction,
5
5
  StoreChange,
6
6
  StoreDelta,
7
- type Store,
8
7
  } from "@excalidraw/element";
9
8
 
9
+ import type { StoreSnapshot, Store } from "@excalidraw/element";
10
+
10
11
  import type { SceneElementsMap } from "@excalidraw/element/types";
11
12
 
12
13
  import type { AppState } from "./types";
13
14
 
14
- class HistoryEntry extends StoreDelta {}
15
+ export class HistoryDelta extends StoreDelta {
16
+ /**
17
+ * Apply the delta to the passed elements and appState, does not modify the snapshot.
18
+ */
19
+ public applyTo(
20
+ elements: SceneElementsMap,
21
+ appState: AppState,
22
+ snapshot: StoreSnapshot,
23
+ ): [SceneElementsMap, AppState, boolean] {
24
+ const [nextElements, elementsContainVisibleChange] = this.elements.applyTo(
25
+ elements,
26
+ // used to fallback into local snapshot in case we couldn't apply the delta
27
+ // due to a missing (force deleted) elements in the scene
28
+ snapshot.elements,
29
+ // we don't want to apply the `version` and `versionNonce` properties for history
30
+ // as we always need to end up with a new version due to collaboration,
31
+ // approaching each undo / redo as a new user action
32
+ {
33
+ excludedProperties: new Set(["version", "versionNonce"]),
34
+ },
35
+ );
36
+
37
+ const [nextAppState, appStateContainsVisibleChange] = this.appState.applyTo(
38
+ appState,
39
+ nextElements,
40
+ );
41
+
42
+ const appliedVisibleChanges =
43
+ elementsContainVisibleChange || appStateContainsVisibleChange;
44
+
45
+ return [nextElements, nextAppState, appliedVisibleChanges];
46
+ }
47
+
48
+ /**
49
+ * Overriding once to avoid type casting everywhere.
50
+ */
51
+ public static override calculate(
52
+ prevSnapshot: StoreSnapshot,
53
+ nextSnapshot: StoreSnapshot,
54
+ ) {
55
+ return super.calculate(prevSnapshot, nextSnapshot) as HistoryDelta;
56
+ }
57
+
58
+ /**
59
+ * Overriding once to avoid type casting everywhere.
60
+ */
61
+ public static override inverse(delta: StoreDelta): HistoryDelta {
62
+ return super.inverse(delta) as HistoryDelta;
63
+ }
64
+
65
+ /**
66
+ * Overriding once to avoid type casting everywhere.
67
+ */
68
+ public static override applyLatestChanges(
69
+ delta: StoreDelta,
70
+ prevElements: SceneElementsMap,
71
+ nextElements: SceneElementsMap,
72
+ modifierOptions?: "deleted" | "inserted",
73
+ ) {
74
+ return super.applyLatestChanges(
75
+ delta,
76
+ prevElements,
77
+ nextElements,
78
+ modifierOptions,
79
+ ) as HistoryDelta;
80
+ }
81
+ }
15
82
 
16
83
  export class HistoryChangedEvent {
17
84
  constructor(
@@ -25,8 +92,8 @@ export class History {
25
92
  [HistoryChangedEvent]
26
93
  >();
27
94
 
28
- public readonly undoStack: HistoryEntry[] = [];
29
- public readonly redoStack: HistoryEntry[] = [];
95
+ public readonly undoStack: HistoryDelta[] = [];
96
+ public readonly redoStack: HistoryDelta[] = [];
30
97
 
31
98
  public get isUndoStackEmpty() {
32
99
  return this.undoStack.length === 0;
@@ -48,16 +115,16 @@ export class History {
48
115
  * Do not re-record history entries, which were already pushed to undo / redo stack, as part of history action.
49
116
  */
50
117
  public record(delta: StoreDelta) {
51
- if (delta.isEmpty() || delta instanceof HistoryEntry) {
118
+ if (delta.isEmpty() || delta instanceof HistoryDelta) {
52
119
  return;
53
120
  }
54
121
 
55
122
  // construct history entry, so once it's emitted, it's not recorded again
56
- const entry = HistoryEntry.inverse(delta);
123
+ const historyDelta = HistoryDelta.inverse(delta);
57
124
 
58
- this.undoStack.push(entry);
125
+ this.undoStack.push(historyDelta);
59
126
 
60
- if (!entry.elements.isEmpty()) {
127
+ if (!historyDelta.elements.isEmpty()) {
61
128
  // don't reset redo stack on local appState changes,
62
129
  // as a simple click (unselect) could lead to losing all the redo entries
63
130
  // only reset on non empty elements changes!
@@ -74,7 +141,7 @@ export class History {
74
141
  elements,
75
142
  appState,
76
143
  () => History.pop(this.undoStack),
77
- (entry: HistoryEntry) => History.push(this.redoStack, entry, elements),
144
+ (entry: HistoryDelta) => History.push(this.redoStack, entry),
78
145
  );
79
146
  }
80
147
 
@@ -83,20 +150,20 @@ export class History {
83
150
  elements,
84
151
  appState,
85
152
  () => History.pop(this.redoStack),
86
- (entry: HistoryEntry) => History.push(this.undoStack, entry, elements),
153
+ (entry: HistoryDelta) => History.push(this.undoStack, entry),
87
154
  );
88
155
  }
89
156
 
90
157
  private perform(
91
158
  elements: SceneElementsMap,
92
159
  appState: AppState,
93
- pop: () => HistoryEntry | null,
94
- push: (entry: HistoryEntry) => void,
160
+ pop: () => HistoryDelta | null,
161
+ push: (entry: HistoryDelta) => void,
95
162
  ): [SceneElementsMap, AppState] | void {
96
163
  try {
97
- let historyEntry = pop();
164
+ let historyDelta = pop();
98
165
 
99
- if (historyEntry === null) {
166
+ if (historyDelta === null) {
100
167
  return;
101
168
  }
102
169
 
@@ -109,40 +176,46 @@ export class History {
109
176
  let containsVisibleChange = false;
110
177
 
111
178
  // iterate through the history entries in case they result in no visible changes
112
- while (historyEntry) {
179
+ while (historyDelta) {
113
180
  try {
114
181
  [nextElements, nextAppState, containsVisibleChange] =
115
- StoreDelta.applyTo(
116
- historyEntry,
117
- nextElements,
118
- nextAppState,
119
- prevSnapshot,
120
- );
182
+ historyDelta.applyTo(nextElements, nextAppState, prevSnapshot);
121
183
 
184
+ const prevElements = prevSnapshot.elements;
122
185
  const nextSnapshot = prevSnapshot.maybeClone(
123
186
  action,
124
187
  nextElements,
125
188
  nextAppState,
126
189
  );
127
190
 
128
- // schedule immediate capture, so that it's emitted for the sync purposes
129
- this.store.scheduleMicroAction({
130
- action,
131
- change: StoreChange.create(prevSnapshot, nextSnapshot),
132
- delta: historyEntry,
133
- });
191
+ const change = StoreChange.create(prevSnapshot, nextSnapshot);
192
+ const delta = HistoryDelta.applyLatestChanges(
193
+ historyDelta,
194
+ prevElements,
195
+ nextElements,
196
+ );
197
+
198
+ if (!delta.isEmpty()) {
199
+ // schedule immediate capture, so that it's emitted for the sync purposes
200
+ this.store.scheduleMicroAction({
201
+ action,
202
+ change,
203
+ delta,
204
+ });
205
+
206
+ historyDelta = delta;
207
+ }
134
208
 
135
209
  prevSnapshot = nextSnapshot;
136
210
  } finally {
137
- // make sure to always push, even if the delta is corrupted
138
- push(historyEntry);
211
+ push(historyDelta);
139
212
  }
140
213
 
141
214
  if (containsVisibleChange) {
142
215
  break;
143
216
  }
144
217
 
145
- historyEntry = pop();
218
+ historyDelta = pop();
146
219
  }
147
220
 
148
221
  return [nextElements, nextAppState];
@@ -155,7 +228,7 @@ export class History {
155
228
  }
156
229
  }
157
230
 
158
- private static pop(stack: HistoryEntry[]): HistoryEntry | null {
231
+ private static pop(stack: HistoryDelta[]): HistoryDelta | null {
159
232
  if (!stack.length) {
160
233
  return null;
161
234
  }
@@ -169,18 +242,8 @@ export class History {
169
242
  return null;
170
243
  }
171
244
 
172
- private static push(
173
- stack: HistoryEntry[],
174
- entry: HistoryEntry,
175
- prevElements: SceneElementsMap,
176
- ) {
177
- const inversedEntry = HistoryEntry.inverse(entry);
178
- const updatedEntry = HistoryEntry.applyLatestChanges(
179
- inversedEntry,
180
- prevElements,
181
- "inserted",
182
- );
183
-
184
- return stack.push(updatedEntry);
245
+ private static push(stack: HistoryDelta[], entry: HistoryDelta) {
246
+ const inversedEntry = HistoryDelta.inverse(entry);
247
+ return stack.push(inversedEntry);
185
248
  }
186
249
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@excalidraw/excalidraw",
3
- "version": "0.18.0-c4c0649",
3
+ "version": "0.18.0-c6f8ef9",
4
4
  "type": "module",
5
5
  "types": "./dist/types/excalidraw/index.d.ts",
6
6
  "main": "./dist/prod/index.js",
@@ -66,12 +66,22 @@
66
66
  "last 1 safari version"
67
67
  ]
68
68
  },
69
+ "repository": "https://github.com/excalidraw/excalidraw",
70
+ "bugs": "https://github.com/excalidraw/excalidraw/issues",
71
+ "homepage": "https://github.com/excalidraw/excalidraw/tree/master/packages/excalidraw",
72
+ "scripts": {
73
+ "gen:types": "rimraf types && tsc",
74
+ "build:esm": "rimraf dist && node ../../scripts/buildPackage.js && yarn gen:types"
75
+ },
69
76
  "peerDependencies": {
70
77
  "react": "^17.0.2 || ^18.2.0 || ^19.0.0",
71
78
  "react-dom": "^17.0.2 || ^18.2.0 || ^19.0.0"
72
79
  },
73
80
  "dependencies": {
74
81
  "@braintree/sanitize-url": "6.0.2",
82
+ "@excalidraw/common": "0.18.0-c6f8ef9",
83
+ "@excalidraw/element": "0.18.0-c6f8ef9",
84
+ "@excalidraw/math": "0.18.0-c6f8ef9",
75
85
  "@excalidraw/laser-pointer": "1.3.1",
76
86
  "@excalidraw/mermaid-to-excalidraw": "1.1.2",
77
87
  "@excalidraw/random-username": "1.1.0",
@@ -124,12 +134,5 @@
124
134
  "harfbuzzjs": "0.3.6",
125
135
  "jest-diff": "29.7.0",
126
136
  "typescript": "4.9.4"
127
- },
128
- "repository": "https://github.com/excalidraw/excalidraw",
129
- "bugs": "https://github.com/excalidraw/excalidraw/issues",
130
- "homepage": "https://github.com/excalidraw/excalidraw/tree/master/packages/excalidraw",
131
- "scripts": {
132
- "gen:types": "rimraf types && tsc",
133
- "build:esm": "rimraf dist && node ../../scripts/buildPackage.js && yarn gen:types"
134
137
  }
135
- }
138
+ }