@excalidraw/element 0.18.0-f0063e113 → 0.18.0-f5d54ac5a

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 (46) hide show
  1. package/dist/dev/index.js +373 -145
  2. package/dist/dev/index.js.map +3 -3
  3. package/dist/prod/index.js +12 -12
  4. package/dist/types/common/src/constants.d.ts +1 -0
  5. package/dist/types/element/src/Scene.d.ts +6 -2
  6. package/dist/types/element/src/align.d.ts +2 -1
  7. package/dist/types/element/src/delta.d.ts +18 -5
  8. package/dist/types/element/src/distribute.d.ts +2 -1
  9. package/dist/types/element/src/groups.d.ts +1 -0
  10. package/dist/types/element/src/linearElementEditor.d.ts +2 -1
  11. package/dist/types/element/src/store.d.ts +7 -2
  12. package/dist/types/excalidraw/actions/actionAddToLibrary.d.ts +0 -3
  13. package/dist/types/excalidraw/actions/actionBoundText.d.ts +0 -2
  14. package/dist/types/excalidraw/actions/actionCanvas.d.ts +0 -13
  15. package/dist/types/excalidraw/actions/actionClipboard.d.ts +3 -8
  16. package/dist/types/excalidraw/actions/actionCropEditor.d.ts +0 -1
  17. package/dist/types/excalidraw/actions/actionDeleteSelected.d.ts +3 -6
  18. package/dist/types/excalidraw/actions/actionElementLink.d.ts +0 -1
  19. package/dist/types/excalidraw/actions/actionElementLock.d.ts +0 -2
  20. package/dist/types/excalidraw/actions/actionEmbeddable.d.ts +0 -1
  21. package/dist/types/excalidraw/actions/actionExport.d.ts +0 -9
  22. package/dist/types/excalidraw/actions/actionFinalize.d.ts +2 -3
  23. package/dist/types/excalidraw/actions/actionFrame.d.ts +0 -4
  24. package/dist/types/excalidraw/actions/actionGroup.d.ts +0 -2
  25. package/dist/types/excalidraw/actions/actionLinearEditor.d.ts +33 -3
  26. package/dist/types/excalidraw/actions/actionLink.d.ts +0 -1
  27. package/dist/types/excalidraw/actions/actionMenu.d.ts +0 -3
  28. package/dist/types/excalidraw/actions/actionNavigate.d.ts +0 -2
  29. package/dist/types/excalidraw/actions/actionProperties.d.ts +0 -15
  30. package/dist/types/excalidraw/actions/actionSelectAll.d.ts +0 -1
  31. package/dist/types/excalidraw/actions/actionStyles.d.ts +0 -1
  32. package/dist/types/excalidraw/actions/actionToggleGridMode.d.ts +0 -1
  33. package/dist/types/excalidraw/actions/actionToggleObjectsSnapMode.d.ts +0 -1
  34. package/dist/types/excalidraw/actions/actionToggleSearchMenu.d.ts +0 -1
  35. package/dist/types/excalidraw/actions/actionToggleStats.d.ts +0 -1
  36. package/dist/types/excalidraw/actions/actionToggleViewMode.d.ts +0 -1
  37. package/dist/types/excalidraw/actions/actionToggleZenMode.d.ts +0 -1
  38. package/dist/types/excalidraw/components/Actions.d.ts +0 -4
  39. package/dist/types/excalidraw/components/App.d.ts +5 -3
  40. package/dist/types/excalidraw/components/Ellipsify.d.ts +4 -0
  41. package/dist/types/excalidraw/data/reconcile.d.ts +1 -0
  42. package/dist/types/excalidraw/data/restore.d.ts +6 -1
  43. package/dist/types/excalidraw/index.d.ts +2 -1
  44. package/dist/types/excalidraw/renderer/staticScene.d.ts +4 -1
  45. package/dist/types/excalidraw/types.d.ts +5 -4
  46. package/package.json +7 -3
package/dist/dev/index.js CHANGED
@@ -8127,7 +8127,8 @@ var LinearElementEditor = class _LinearElementEditor {
8127
8127
  segmentMidPointHoveredCoords;
8128
8128
  elbowed;
8129
8129
  customLineAngle;
8130
- constructor(element, elementsMap) {
8130
+ isEditing;
8131
+ constructor(element, elementsMap, isEditing = false) {
8131
8132
  this.elementId = element.id;
8132
8133
  if (!pointsEqual6(element.points[0], pointFrom8(0, 0))) {
8133
8134
  console.error("Linear element is not normalized", Error().stack);
@@ -8158,6 +8159,7 @@ var LinearElementEditor = class _LinearElementEditor {
8158
8159
  this.segmentMidPointHoveredCoords = null;
8159
8160
  this.elbowed = isElbowArrow(element) && element.elbowed;
8160
8161
  this.customLineAngle = null;
8162
+ this.isEditing = isEditing;
8161
8163
  }
8162
8164
  // ---------------------------------------------------------------------------
8163
8165
  // static methods
@@ -8175,11 +8177,11 @@ var LinearElementEditor = class _LinearElementEditor {
8175
8177
  return null;
8176
8178
  }
8177
8179
  static handleBoxSelection(event, appState, setState, elementsMap) {
8178
- if (!appState.editingLinearElement || !appState.selectionElement) {
8180
+ if (!appState.selectedLinearElement?.isEditing || !appState.selectionElement) {
8179
8181
  return false;
8180
8182
  }
8181
- const { editingLinearElement } = appState;
8182
- const { selectedPointsIndices, elementId } = editingLinearElement;
8183
+ const { selectedLinearElement } = appState;
8184
+ const { selectedPointsIndices, elementId } = selectedLinearElement;
8183
8185
  const element = _LinearElementEditor.getElement(elementId, elementsMap);
8184
8186
  if (!element) {
8185
8187
  return false;
@@ -8201,8 +8203,8 @@ var LinearElementEditor = class _LinearElementEditor {
8201
8203
  return true;
8202
8204
  });
8203
8205
  setState({
8204
- editingLinearElement: {
8205
- ...editingLinearElement,
8206
+ selectedLinearElement: {
8207
+ ...selectedLinearElement,
8206
8208
  selectedPointsIndices: nextSelectedPoints.length ? nextSelectedPoints : null
8207
8209
  }
8208
8210
  });
@@ -8356,7 +8358,6 @@ var LinearElementEditor = class _LinearElementEditor {
8356
8358
  };
8357
8359
  return {
8358
8360
  ...app.state,
8359
- editingLinearElement: app.state.editingLinearElement ? newLinearElementEditor : null,
8360
8361
  selectedLinearElement: newLinearElementEditor,
8361
8362
  suggestedBindings
8362
8363
  };
@@ -8440,7 +8441,7 @@ var LinearElementEditor = class _LinearElementEditor {
8440
8441
  }
8441
8442
  static getEditorMidPoints = (element, elementsMap, appState) => {
8442
8443
  const boundText = getBoundTextElement(element, elementsMap);
8443
- if (!isElbowArrow(element) && !appState.editingLinearElement && element.points.length > 2 && !boundText) {
8444
+ if (!isElbowArrow(element) && !appState.selectedLinearElement?.isEditing && element.points.length > 2 && !boundText) {
8444
8445
  return [];
8445
8446
  }
8446
8447
  const points = _LinearElementEditor.getPointsGlobalCoordinates(
@@ -8490,7 +8491,7 @@ var LinearElementEditor = class _LinearElementEditor {
8490
8491
  element,
8491
8492
  elementsMap
8492
8493
  );
8493
- if (points.length >= 3 && !appState.editingLinearElement && !isElbowArrow(element)) {
8494
+ if (points.length >= 3 && !appState.selectedLinearElement?.isEditing && !isElbowArrow(element)) {
8494
8495
  return null;
8495
8496
  }
8496
8497
  const threshold = (_LinearElementEditor.POINT_HANDLE_SIZE + 1) / appState.zoom.value;
@@ -8630,7 +8631,7 @@ var LinearElementEditor = class _LinearElementEditor {
8630
8631
  segmentMidpoint,
8631
8632
  elementsMap
8632
8633
  );
8633
- } else if (event.altKey && appState.editingLinearElement) {
8634
+ } else if (event.altKey && appState.selectedLinearElement?.isEditing) {
8634
8635
  if (linearElementEditor.lastUncommittedPoint == null) {
8635
8636
  scene.mutateElement(element, {
8636
8637
  points: [
@@ -8740,14 +8741,14 @@ var LinearElementEditor = class _LinearElementEditor {
8740
8741
  }
8741
8742
  static handlePointerMove(event, scenePointerX, scenePointerY, app) {
8742
8743
  const appState = app.state;
8743
- if (!appState.editingLinearElement) {
8744
+ if (!appState.selectedLinearElement?.isEditing) {
8744
8745
  return null;
8745
8746
  }
8746
- const { elementId, lastUncommittedPoint } = appState.editingLinearElement;
8747
+ const { elementId, lastUncommittedPoint } = appState.selectedLinearElement;
8747
8748
  const elementsMap = app.scene.getNonDeletedElementsMap();
8748
8749
  const element = _LinearElementEditor.getElement(elementId, elementsMap);
8749
8750
  if (!element) {
8750
- return appState.editingLinearElement;
8751
+ return appState.selectedLinearElement;
8751
8752
  }
8752
8753
  const { points } = element;
8753
8754
  const lastPoint = points[points.length - 1];
@@ -8755,10 +8756,10 @@ var LinearElementEditor = class _LinearElementEditor {
8755
8756
  if (lastPoint === lastUncommittedPoint) {
8756
8757
  _LinearElementEditor.deletePoints(element, app, [points.length - 1]);
8757
8758
  }
8758
- return {
8759
- ...appState.editingLinearElement,
8759
+ return appState.selectedLinearElement?.lastUncommittedPoint ? {
8760
+ ...appState.selectedLinearElement,
8760
8761
  lastUncommittedPoint: null
8761
- };
8762
+ } : appState.selectedLinearElement;
8762
8763
  }
8763
8764
  let newPoint;
8764
8765
  if (shouldRotateWithDiscreteAngle(event) && points.length >= 2) {
@@ -8778,8 +8779,8 @@ var LinearElementEditor = class _LinearElementEditor {
8778
8779
  newPoint = _LinearElementEditor.createPointAt(
8779
8780
  element,
8780
8781
  elementsMap,
8781
- scenePointerX - appState.editingLinearElement.pointerOffset.x,
8782
- scenePointerY - appState.editingLinearElement.pointerOffset.y,
8782
+ scenePointerX - appState.selectedLinearElement.pointerOffset.x,
8783
+ scenePointerY - appState.selectedLinearElement.pointerOffset.y,
8783
8784
  event[KEYS2.CTRL_OR_CMD] || isElbowArrow(element) ? null : app.getEffectiveGridSize()
8784
8785
  );
8785
8786
  }
@@ -8800,7 +8801,7 @@ var LinearElementEditor = class _LinearElementEditor {
8800
8801
  _LinearElementEditor.addPoints(element, app.scene, [newPoint]);
8801
8802
  }
8802
8803
  return {
8803
- ...appState.editingLinearElement,
8804
+ ...appState.selectedLinearElement,
8804
8805
  lastUncommittedPoint: element.points[element.points.length - 1]
8805
8806
  };
8806
8807
  }
@@ -8906,11 +8907,11 @@ var LinearElementEditor = class _LinearElementEditor {
8906
8907
  // ---------------------------------------------------------------------------
8907
8908
  static duplicateSelectedPoints(appState, scene) {
8908
8909
  invariant6(
8909
- appState.editingLinearElement,
8910
+ appState.selectedLinearElement?.isEditing,
8910
8911
  "Not currently editing a linear element"
8911
8912
  );
8912
8913
  const elementsMap = scene.getNonDeletedElementsMap();
8913
- const { selectedPointsIndices, elementId } = appState.editingLinearElement;
8914
+ const { selectedPointsIndices, elementId } = appState.selectedLinearElement;
8914
8915
  const element = _LinearElementEditor.getElement(elementId, elementsMap);
8915
8916
  invariant6(
8916
8917
  element,
@@ -8957,14 +8958,14 @@ var LinearElementEditor = class _LinearElementEditor {
8957
8958
  }
8958
8959
  return {
8959
8960
  ...appState,
8960
- editingLinearElement: {
8961
- ...appState.editingLinearElement,
8961
+ selectedLinearElement: {
8962
+ ...appState.selectedLinearElement,
8962
8963
  selectedPointsIndices: nextSelectedIndices
8963
8964
  }
8964
8965
  };
8965
8966
  }
8966
8967
  static deletePoints(element, app, pointIndices) {
8967
- const isUncommittedPoint = app.state.editingLinearElement?.lastUncommittedPoint === element.points[element.points.length - 1];
8968
+ const isUncommittedPoint = app.state.selectedLinearElement?.isEditing && app.state.selectedLinearElement?.lastUncommittedPoint === element.points[element.points.length - 1];
8968
8969
  const nextPoints = element.points.filter((_, idx) => {
8969
8970
  return !pointIndices.includes(idx);
8970
8971
  });
@@ -9073,7 +9074,7 @@ var LinearElementEditor = class _LinearElementEditor {
9073
9074
  pointFrom8(origin.x, origin.y),
9074
9075
  pointFrom8(pointerCoords.x, pointerCoords.y)
9075
9076
  );
9076
- if (!appState.editingLinearElement && dist < DRAGGING_THRESHOLD / appState.zoom.value) {
9077
+ if (!appState.selectedLinearElement?.isEditing && dist < DRAGGING_THRESHOLD / appState.zoom.value) {
9077
9078
  return false;
9078
9079
  }
9079
9080
  return true;
@@ -9826,6 +9827,55 @@ var getNewGroupIdsForDuplication = (groupIds, editingGroupId, mapper) => {
9826
9827
  }
9827
9828
  return copy;
9828
9829
  };
9830
+ var getSelectedElementsByGroup = (selectedElements, elementsMap, appState) => {
9831
+ const selectedGroupIds = getSelectedGroupIds(appState);
9832
+ const unboundElements = selectedElements.filter(
9833
+ (element) => !isBoundToContainer(element)
9834
+ );
9835
+ const groups = /* @__PURE__ */ new Map();
9836
+ const elements = /* @__PURE__ */ new Map();
9837
+ const addToElementsMap = (element) => {
9838
+ const currentElementMembers = elements.get(element.id) || [];
9839
+ const boundTextElement = getBoundTextElement(element, elementsMap);
9840
+ if (boundTextElement) {
9841
+ currentElementMembers.push(boundTextElement);
9842
+ }
9843
+ elements.set(element.id, [...currentElementMembers, element]);
9844
+ };
9845
+ const addToGroupsMap = (element, groupId) => {
9846
+ const currentGroupMembers = groups.get(groupId) || [];
9847
+ const boundTextElement = getBoundTextElement(element, elementsMap);
9848
+ if (boundTextElement) {
9849
+ currentGroupMembers.push(boundTextElement);
9850
+ }
9851
+ groups.set(groupId, [...currentGroupMembers, element]);
9852
+ };
9853
+ const handleSingleSelectedGroupCase = (element, selectedGroupId) => {
9854
+ const indexOfSelectedGroupId = element.groupIds.indexOf(selectedGroupId, 0);
9855
+ const nestedGroupCount = element.groupIds.slice(
9856
+ 0,
9857
+ indexOfSelectedGroupId
9858
+ ).length;
9859
+ return nestedGroupCount > 0 ? addToGroupsMap(element, element.groupIds[indexOfSelectedGroupId - 1]) : addToElementsMap(element);
9860
+ };
9861
+ const isAllInSameGroup = selectedElements.every(
9862
+ (element) => isSelectedViaGroup(appState, element)
9863
+ );
9864
+ unboundElements.forEach((element) => {
9865
+ const selectedGroupId = getSelectedGroupIdForElement(
9866
+ element,
9867
+ appState.selectedGroupIds
9868
+ );
9869
+ if (!selectedGroupId) {
9870
+ addToElementsMap(element);
9871
+ } else if (selectedGroupIds.length === 1 && isAllInSameGroup) {
9872
+ handleSingleSelectedGroupCase(element, selectedGroupId);
9873
+ } else {
9874
+ addToGroupsMap(element, selectedGroupId);
9875
+ }
9876
+ });
9877
+ return Array.from(groups.values()).concat(Array.from(elements.values()));
9878
+ };
9829
9879
 
9830
9880
  // src/selection.ts
9831
9881
  var excludeElementsInFramesFromSelection = (selectedElements) => {
@@ -10513,6 +10563,11 @@ var getCanvasPadding = (element) => {
10513
10563
  return element.strokeWidth * 12;
10514
10564
  case "text":
10515
10565
  return element.fontSize / 2;
10566
+ case "arrow":
10567
+ if (element.endArrowhead || element.endArrowhead) {
10568
+ return 40;
10569
+ }
10570
+ return 20;
10516
10571
  default:
10517
10572
  return 20;
10518
10573
  }
@@ -12742,11 +12797,11 @@ var getNormalizedDimensions = (element) => {
12742
12797
 
12743
12798
  // src/align.ts
12744
12799
  init_define_import_meta_env();
12745
- var alignElements = (selectedElements, alignment, scene) => {
12746
- const elementsMap = scene.getNonDeletedElementsMap();
12747
- const groups = getMaximumGroups(
12800
+ var alignElements = (selectedElements, alignment, scene, appState) => {
12801
+ const groups = getSelectedElementsByGroup(
12748
12802
  selectedElements,
12749
- elementsMap
12803
+ scene.getNonDeletedElementsMap(),
12804
+ appState
12750
12805
  );
12751
12806
  const selectionBoundingBox = getCommonBoundingBox(selectedElements);
12752
12807
  return groups.flatMap((group) => {
@@ -13182,8 +13237,9 @@ var Store = class {
13182
13237
  constructor(app) {
13183
13238
  this.app = app;
13184
13239
  }
13185
- // internally used by history
13240
+ // for internal use by history
13186
13241
  onDurableIncrementEmitter = new Emitter();
13242
+ // for public use as part of onIncrement API
13187
13243
  onStoreIncrementEmitter = new Emitter();
13188
13244
  scheduledMacroActions = /* @__PURE__ */ new Set();
13189
13245
  scheduledMicroActions = [];
@@ -13477,10 +13533,20 @@ var StoreDelta = class {
13477
13533
  */
13478
13534
  static load({
13479
13535
  id,
13480
- elements: { added, removed, updated }
13536
+ elements: { added, removed, updated },
13537
+ appState: { delta: appStateDelta }
13481
13538
  }) {
13482
13539
  const elements = ElementsDelta.create(added, removed, updated);
13483
- return new this(id, elements, AppStateDelta.empty());
13540
+ const appState = AppStateDelta.create(appStateDelta);
13541
+ return new this(id, elements, appState);
13542
+ }
13543
+ /**
13544
+ * Squash the passed delta into the current instance.
13545
+ */
13546
+ squash(delta) {
13547
+ this.elements.squash(delta.elements);
13548
+ this.appState.squash(delta.appState);
13549
+ return this;
13484
13550
  }
13485
13551
  /**
13486
13552
  * Inverse store delta, creates new instance of `StoreDelta`.
@@ -13491,8 +13557,12 @@ var StoreDelta = class {
13491
13557
  /**
13492
13558
  * Apply the delta to the passed elements and appState, does not modify the snapshot.
13493
13559
  */
13494
- static applyTo(delta, elements, appState) {
13495
- const [nextElements, elementsContainVisibleChange] = delta.elements.applyTo(elements);
13560
+ static applyTo(delta, elements, appState, options) {
13561
+ const [nextElements, elementsContainVisibleChange] = delta.elements.applyTo(
13562
+ elements,
13563
+ StoreSnapshot.empty().elements,
13564
+ options
13565
+ );
13496
13566
  const [nextAppState, appStateContainsVisibleChange] = delta.appState.applyTo(appState, nextElements);
13497
13567
  const appliedVisibleChanges = elementsContainVisibleChange || appStateContainsVisibleChange;
13498
13568
  return [nextElements, nextAppState, appliedVisibleChanges];
@@ -13753,8 +13823,7 @@ var getDefaultObservedAppState = () => {
13753
13823
  viewBackgroundColor: COLOR_PALETTE2.white,
13754
13824
  selectedElementIds: {},
13755
13825
  selectedGroupIds: {},
13756
- editingLinearElementId: null,
13757
- selectedLinearElementId: null,
13826
+ selectedLinearElement: null,
13758
13827
  croppingElementId: null,
13759
13828
  activeLockedId: null,
13760
13829
  lockedMultiSelections: {}
@@ -13770,10 +13839,10 @@ var getObservedAppState = (appState) => {
13770
13839
  croppingElementId: appState.croppingElementId,
13771
13840
  activeLockedId: appState.activeLockedId,
13772
13841
  lockedMultiSelections: appState.lockedMultiSelections,
13773
- editingLinearElementId: appState.editingLinearElement?.elementId ?? // prefer app state, as it's likely newer
13774
- appState.editingLinearElementId ?? // fallback to observed app state, as it's likely older coming from a previous snapshot
13775
- null,
13776
- selectedLinearElementId: appState.selectedLinearElement?.elementId ?? appState.selectedLinearElementId ?? null
13842
+ selectedLinearElement: appState.selectedLinearElement ? {
13843
+ elementId: appState.selectedLinearElement.elementId,
13844
+ isEditing: !!appState.selectedLinearElement.isEditing
13845
+ } : null
13777
13846
  };
13778
13847
  Reflect.defineProperty(observedAppState, hiddenObservedAppStateProp, {
13779
13848
  value: true,
@@ -14337,9 +14406,9 @@ var Scene = class {
14337
14406
  getFramesIncludingDeleted() {
14338
14407
  return this.frames;
14339
14408
  }
14340
- constructor(elements = null) {
14409
+ constructor(elements = null, options) {
14341
14410
  if (elements) {
14342
- this.replaceAllElements(elements);
14411
+ this.replaceAllElements(elements, options);
14343
14412
  }
14344
14413
  }
14345
14414
  getSelectedElements(opts) {
@@ -14404,10 +14473,12 @@ var Scene = class {
14404
14473
  }
14405
14474
  return didChange;
14406
14475
  }
14407
- replaceAllElements(nextElements) {
14476
+ replaceAllElements(nextElements, options) {
14408
14477
  const _nextElements = toArray(nextElements);
14409
14478
  const nextFrameLikes = [];
14410
- validateIndicesThrottled(_nextElements);
14479
+ if (!options?.skipValidation) {
14480
+ validateIndicesThrottled(_nextElements);
14481
+ }
14411
14482
  this.elements = syncInvalidIndices2(_nextElements);
14412
14483
  this.elementsMap.clear();
14413
14484
  this.elements.forEach((element) => {
@@ -14577,12 +14648,21 @@ var Delta = class _Delta {
14577
14648
  static isEmpty(delta) {
14578
14649
  return !Object.keys(delta.deleted).length && !Object.keys(delta.inserted).length;
14579
14650
  }
14651
+ /**
14652
+ * Merges two deltas into a new one.
14653
+ */
14654
+ static merge(delta1, delta2, delta3) {
14655
+ return _Delta.create(
14656
+ { ...delta1.deleted, ...delta2.deleted, ...delta3?.deleted ?? {} },
14657
+ { ...delta1.inserted, ...delta2.inserted, ...delta3?.inserted ?? {} }
14658
+ );
14659
+ }
14580
14660
  /**
14581
14661
  * Merges deleted and inserted object partials.
14582
14662
  */
14583
14663
  static mergeObjects(prev, added, removed) {
14584
14664
  const cloned = { ...prev };
14585
- for (const key of Object.keys(removed)) {
14665
+ for (const key of Object.keys(removed ?? {})) {
14586
14666
  delete cloned[key];
14587
14667
  }
14588
14668
  return { ...cloned, ...added };
@@ -14801,6 +14881,9 @@ var AppStateDelta = class _AppStateDelta {
14801
14881
  constructor(delta) {
14802
14882
  this.delta = delta;
14803
14883
  }
14884
+ static create(delta) {
14885
+ return new _AppStateDelta(delta);
14886
+ }
14804
14887
  static calculate(prevAppState, nextAppState) {
14805
14888
  const delta = Delta.calculate(
14806
14889
  prevAppState,
@@ -14822,50 +14905,71 @@ var AppStateDelta = class _AppStateDelta {
14822
14905
  const inversedDelta = Delta.create(this.delta.inserted, this.delta.deleted);
14823
14906
  return new _AppStateDelta(inversedDelta);
14824
14907
  }
14908
+ squash(delta) {
14909
+ const mergedDeletedSelectedElementIds = Delta.mergeObjects(
14910
+ this.delta.deleted.selectedElementIds ?? {},
14911
+ delta.delta.deleted.selectedElementIds ?? {}
14912
+ );
14913
+ const mergedInsertedSelectedElementIds = Delta.mergeObjects(
14914
+ this.delta.inserted.selectedElementIds ?? {},
14915
+ delta.delta.inserted.selectedElementIds ?? {}
14916
+ );
14917
+ const mergedInsertedSelectedGroupIds = Delta.mergeObjects(
14918
+ this.delta.inserted.selectedGroupIds ?? {},
14919
+ delta.delta.inserted.selectedGroupIds ?? {}
14920
+ );
14921
+ const mergedDeletedSelectedGroupIds = Delta.mergeObjects(
14922
+ this.delta.deleted.selectedGroupIds ?? {},
14923
+ delta.delta.deleted.selectedGroupIds ?? {}
14924
+ );
14925
+ const mergedDelta = Delta.create(
14926
+ {
14927
+ selectedElementIds: mergedDeletedSelectedElementIds,
14928
+ selectedGroupIds: mergedDeletedSelectedGroupIds
14929
+ },
14930
+ {
14931
+ selectedElementIds: mergedInsertedSelectedElementIds,
14932
+ selectedGroupIds: mergedInsertedSelectedGroupIds
14933
+ }
14934
+ );
14935
+ this.delta = Delta.merge(this.delta, delta.delta, mergedDelta);
14936
+ return this;
14937
+ }
14825
14938
  applyTo(appState, nextElements) {
14826
14939
  try {
14827
14940
  const {
14828
- selectedElementIds: removedSelectedElementIds = {},
14829
- selectedGroupIds: removedSelectedGroupIds = {}
14941
+ selectedElementIds: deletedSelectedElementIds = {},
14942
+ selectedGroupIds: deletedSelectedGroupIds = {}
14830
14943
  } = this.delta.deleted;
14831
14944
  const {
14832
- selectedElementIds: addedSelectedElementIds = {},
14833
- selectedGroupIds: addedSelectedGroupIds = {},
14834
- selectedLinearElementId,
14835
- editingLinearElementId,
14945
+ selectedElementIds: insertedSelectedElementIds = {},
14946
+ selectedGroupIds: insertedSelectedGroupIds = {},
14947
+ selectedLinearElement: insertedSelectedLinearElement,
14836
14948
  ...directlyApplicablePartial
14837
14949
  } = this.delta.inserted;
14838
14950
  const mergedSelectedElementIds = Delta.mergeObjects(
14839
14951
  appState.selectedElementIds,
14840
- addedSelectedElementIds,
14841
- removedSelectedElementIds
14952
+ insertedSelectedElementIds,
14953
+ deletedSelectedElementIds
14842
14954
  );
14843
14955
  const mergedSelectedGroupIds = Delta.mergeObjects(
14844
14956
  appState.selectedGroupIds,
14845
- addedSelectedGroupIds,
14846
- removedSelectedGroupIds
14957
+ insertedSelectedGroupIds,
14958
+ deletedSelectedGroupIds
14847
14959
  );
14848
- const selectedLinearElement = selectedLinearElementId && nextElements.has(selectedLinearElementId) ? new LinearElementEditor(
14960
+ const selectedLinearElement = insertedSelectedLinearElement && nextElements.has(insertedSelectedLinearElement.elementId) ? new LinearElementEditor(
14849
14961
  nextElements.get(
14850
- selectedLinearElementId
14962
+ insertedSelectedLinearElement.elementId
14851
14963
  ),
14852
- nextElements
14853
- ) : null;
14854
- const editingLinearElement = editingLinearElementId && nextElements.has(editingLinearElementId) ? new LinearElementEditor(
14855
- nextElements.get(
14856
- editingLinearElementId
14857
- ),
14858
- nextElements
14964
+ nextElements,
14965
+ insertedSelectedLinearElement.isEditing
14859
14966
  ) : null;
14860
14967
  const nextAppState = {
14861
14968
  ...appState,
14862
14969
  ...directlyApplicablePartial,
14863
14970
  selectedElementIds: mergedSelectedElementIds,
14864
14971
  selectedGroupIds: mergedSelectedGroupIds,
14865
- selectedLinearElement: typeof selectedLinearElementId !== "undefined" ? selectedLinearElement : appState.selectedLinearElement,
14866
- // otherwise assign what we had before
14867
- editingLinearElement: typeof editingLinearElementId !== "undefined" ? editingLinearElement : appState.editingLinearElement
14868
- // otherwise assign what we had before
14972
+ selectedLinearElement: typeof insertedSelectedLinearElement !== "undefined" ? selectedLinearElement : appState.selectedLinearElement
14869
14973
  };
14870
14974
  const constainsVisibleChanges = this.filterInvisibleChanges(
14871
14975
  appState,
@@ -14955,57 +15059,44 @@ var AppStateDelta = class _AppStateDelta {
14955
15059
  nextAppState[key] = null;
14956
15060
  }
14957
15061
  break;
14958
- case "selectedLinearElementId":
14959
- case "editingLinearElementId":
14960
- const appStateKey = _AppStateDelta.convertToAppStateKey(key);
14961
- const linearElement = nextAppState[appStateKey];
14962
- if (!linearElement) {
15062
+ case "selectedLinearElement":
15063
+ const nextLinearElement = nextAppState[key];
15064
+ if (!nextLinearElement) {
14963
15065
  visibleDifferenceFlag.value = true;
14964
15066
  } else {
14965
- const element = nextElements.get(linearElement.elementId);
15067
+ const element = nextElements.get(nextLinearElement.elementId);
14966
15068
  if (element && !element.isDeleted) {
14967
15069
  visibleDifferenceFlag.value = true;
14968
15070
  } else {
14969
- nextAppState[appStateKey] = null;
15071
+ nextAppState[key] = null;
14970
15072
  }
14971
15073
  }
14972
15074
  break;
14973
- case "lockedMultiSelections": {
15075
+ case "lockedMultiSelections":
14974
15076
  const prevLockedUnits = prevAppState[key] || {};
14975
15077
  const nextLockedUnits = nextAppState[key] || {};
14976
15078
  if (!isShallowEqual2(prevLockedUnits, nextLockedUnits)) {
14977
15079
  visibleDifferenceFlag.value = true;
14978
15080
  }
14979
15081
  break;
14980
- }
14981
- case "activeLockedId": {
15082
+ case "activeLockedId":
14982
15083
  const prevHitLockedId = prevAppState[key] || null;
14983
15084
  const nextHitLockedId = nextAppState[key] || null;
14984
15085
  if (prevHitLockedId !== nextHitLockedId) {
14985
15086
  visibleDifferenceFlag.value = true;
14986
15087
  }
14987
15088
  break;
14988
- }
14989
- default: {
15089
+ default:
14990
15090
  assertNever4(
14991
15091
  key,
14992
15092
  `Unknown ObservedElementsAppState's key "${key}"`,
14993
15093
  true
14994
15094
  );
14995
- }
14996
15095
  }
14997
15096
  }
14998
15097
  }
14999
15098
  return visibleDifferenceFlag.value;
15000
15099
  }
15001
- static convertToAppStateKey(key) {
15002
- switch (key) {
15003
- case "selectedLinearElementId":
15004
- return "selectedLinearElement";
15005
- case "editingLinearElementId":
15006
- return "editingLinearElement";
15007
- }
15008
- }
15009
15100
  static filterSelectedElements(selectedElementIds, elements, visibleDifferenceFlag) {
15010
15101
  const ids = Object.keys(selectedElementIds);
15011
15102
  if (!ids.length) {
@@ -15044,8 +15135,7 @@ var AppStateDelta = class _AppStateDelta {
15044
15135
  editingGroupId,
15045
15136
  selectedGroupIds,
15046
15137
  selectedElementIds,
15047
- editingLinearElementId,
15048
- selectedLinearElementId,
15138
+ selectedLinearElement,
15049
15139
  croppingElementId,
15050
15140
  lockedMultiSelections,
15051
15141
  activeLockedId,
@@ -15170,9 +15260,13 @@ var ElementsDelta = class _ElementsDelta {
15170
15260
  Number.isInteger(deleted.version) && Number.isInteger(inserted.version) && // versions should be positive, zero included
15171
15261
  deleted.version >= 0 && inserted.version >= 0 && // versions should never be the same
15172
15262
  deleted.version !== inserted.version);
15263
+ static satisfiesUniqueInvariants = (elementsDelta, id) => {
15264
+ const { added, removed, updated } = elementsDelta;
15265
+ return [added[id], removed[id], updated[id]].filter(Boolean).length === 1;
15266
+ };
15173
15267
  static validate(elementsDelta, type, satifiesSpecialInvariants) {
15174
15268
  for (const [id, delta] of Object.entries(elementsDelta[type])) {
15175
- if (!this.satisfiesCommmonInvariants(delta) || !satifiesSpecialInvariants(delta)) {
15269
+ if (!this.satisfiesCommmonInvariants(delta) || !this.satisfiesUniqueInvariants(elementsDelta, id) || !satifiesSpecialInvariants(delta)) {
15176
15270
  console.error(
15177
15271
  `Broken invariant for "${type}" delta, element "${id}", delta:`,
15178
15272
  delta
@@ -15199,7 +15293,7 @@ var ElementsDelta = class _ElementsDelta {
15199
15293
  for (const prevElement of prevElements.values()) {
15200
15294
  const nextElement = nextElements.get(prevElement.id);
15201
15295
  if (!nextElement) {
15202
- const deleted = { ...prevElement, isDeleted: false };
15296
+ const deleted = { ...prevElement };
15203
15297
  const inserted = {
15204
15298
  isDeleted: true,
15205
15299
  version: prevElement.version + 1,
@@ -15210,7 +15304,9 @@ var ElementsDelta = class _ElementsDelta {
15210
15304
  inserted,
15211
15305
  _ElementsDelta.stripIrrelevantProps
15212
15306
  );
15213
- removed[prevElement.id] = delta;
15307
+ if (!prevElement.isDeleted) {
15308
+ removed[prevElement.id] = delta;
15309
+ }
15214
15310
  }
15215
15311
  }
15216
15312
  for (const nextElement of nextElements.values()) {
@@ -15222,15 +15318,16 @@ var ElementsDelta = class _ElementsDelta {
15222
15318
  versionNonce: randomInteger4()
15223
15319
  };
15224
15320
  const inserted = {
15225
- ...nextElement,
15226
- isDeleted: false
15321
+ ...nextElement
15227
15322
  };
15228
15323
  const delta = Delta.create(
15229
15324
  deleted,
15230
15325
  inserted,
15231
15326
  _ElementsDelta.stripIrrelevantProps
15232
15327
  );
15233
- added[nextElement.id] = delta;
15328
+ if (!nextElement.isDeleted) {
15329
+ added[nextElement.id] = delta;
15330
+ }
15234
15331
  continue;
15235
15332
  }
15236
15333
  if (prevElement.versionNonce !== nextElement.versionNonce) {
@@ -15251,7 +15348,11 @@ var ElementsDelta = class _ElementsDelta {
15251
15348
  }
15252
15349
  continue;
15253
15350
  }
15254
- if (!Delta.isEmpty(delta)) {
15351
+ const strippedDeleted = _ElementsDelta.stripVersionProps(delta.deleted);
15352
+ const strippedInserted = _ElementsDelta.stripVersionProps(
15353
+ delta.inserted
15354
+ );
15355
+ if (Delta.isInnerDifferent(strippedDeleted, strippedInserted, true)) {
15255
15356
  updated[nextElement.id] = delta;
15256
15357
  }
15257
15358
  }
@@ -15264,8 +15365,8 @@ var ElementsDelta = class _ElementsDelta {
15264
15365
  inverse() {
15265
15366
  const inverseInternal = (deltas) => {
15266
15367
  const inversedDeltas = {};
15267
- for (const [id, delta] of Object.entries(deltas)) {
15268
- inversedDeltas[id] = Delta.create(delta.inserted, delta.deleted);
15368
+ for (const [id, { inserted, deleted }] of Object.entries(deltas)) {
15369
+ inversedDeltas[id] = Delta.create({ ...inserted }, { ...deleted });
15269
15370
  }
15270
15371
  return inversedDeltas;
15271
15372
  };
@@ -15329,7 +15430,13 @@ var ElementsDelta = class _ElementsDelta {
15329
15430
  } else {
15330
15431
  latestDelta = delta;
15331
15432
  }
15332
- if (Delta.isInnerDifferent(latestDelta.deleted, latestDelta.inserted)) {
15433
+ const strippedDeleted = _ElementsDelta.stripVersionProps(
15434
+ latestDelta.deleted
15435
+ );
15436
+ const strippedInserted = _ElementsDelta.stripVersionProps(
15437
+ latestDelta.inserted
15438
+ );
15439
+ if (Delta.isInnerDifferent(strippedDeleted, strippedInserted)) {
15333
15440
  modifiedDeltas[id] = latestDelta;
15334
15441
  }
15335
15442
  }
@@ -15343,26 +15450,30 @@ var ElementsDelta = class _ElementsDelta {
15343
15450
  // redistribute the deltas as `isDeleted` could have been updated
15344
15451
  });
15345
15452
  }
15346
- applyTo(elements, snapshot = StoreSnapshot.empty().elements, options = {
15347
- excludedProperties: /* @__PURE__ */ new Set()
15348
- }) {
15453
+ applyTo(elements, snapshot = StoreSnapshot.empty().elements, options) {
15349
15454
  let nextElements = new Map(elements);
15350
15455
  let changedElements;
15351
15456
  const flags = {
15352
15457
  containsVisibleDifference: false,
15353
- containsZindexDifference: false
15458
+ containsZindexDifference: false,
15459
+ applyDirection: void 0
15354
15460
  };
15355
15461
  try {
15356
15462
  const applyDeltas = _ElementsDelta.createApplier(
15463
+ elements,
15357
15464
  nextElements,
15358
15465
  snapshot,
15359
- options,
15360
- flags
15466
+ flags,
15467
+ options
15361
15468
  );
15362
15469
  const addedElements = applyDeltas(this.added);
15363
15470
  const removedElements = applyDeltas(this.removed);
15364
15471
  const updatedElements = applyDeltas(this.updated);
15365
- const affectedElements = this.resolveConflicts(elements, nextElements);
15472
+ const affectedElements = this.resolveConflicts(
15473
+ elements,
15474
+ nextElements,
15475
+ flags.applyDirection
15476
+ );
15366
15477
  changedElements = new Map([
15367
15478
  ...addedElements,
15368
15479
  ...removedElements,
@@ -15382,9 +15493,7 @@ var ElementsDelta = class _ElementsDelta {
15382
15493
  changedElements,
15383
15494
  flags
15384
15495
  );
15385
- const tempScene = new Scene(nextElements);
15386
- _ElementsDelta.redrawTextBoundingBoxes(tempScene, changedElements);
15387
- _ElementsDelta.redrawBoundArrows(tempScene, changedElements);
15496
+ _ElementsDelta.redrawElements(nextElements, changedElements);
15388
15497
  } catch (e) {
15389
15498
  console.error(
15390
15499
  `Couldn't mutate elements after applying elements change`,
@@ -15397,7 +15506,76 @@ var ElementsDelta = class _ElementsDelta {
15397
15506
  return [nextElements, flags.containsVisibleDifference];
15398
15507
  }
15399
15508
  }
15400
- static createApplier = (nextElements, snapshot, options, flags) => (deltas) => {
15509
+ squash(delta) {
15510
+ const { added, removed, updated } = delta;
15511
+ const mergeBoundElements = (prevDelta, nextDelta) => {
15512
+ const mergedDeletedBoundElements = Delta.mergeArrays(
15513
+ prevDelta.deleted.boundElements ?? [],
15514
+ nextDelta.deleted.boundElements ?? [],
15515
+ void 0,
15516
+ (x) => x.id
15517
+ ) ?? [];
15518
+ const mergedInsertedBoundElements = Delta.mergeArrays(
15519
+ prevDelta.inserted.boundElements ?? [],
15520
+ nextDelta.inserted.boundElements ?? [],
15521
+ void 0,
15522
+ (x) => x.id
15523
+ ) ?? [];
15524
+ return Delta.create(
15525
+ {
15526
+ boundElements: mergedDeletedBoundElements
15527
+ },
15528
+ {
15529
+ boundElements: mergedInsertedBoundElements
15530
+ }
15531
+ );
15532
+ };
15533
+ for (const [id, nextDelta] of Object.entries(added)) {
15534
+ const prevDelta = this.added[id] ?? this.removed[id] ?? this.updated[id];
15535
+ if (!prevDelta) {
15536
+ this.added[id] = nextDelta;
15537
+ } else {
15538
+ const mergedDelta = mergeBoundElements(prevDelta, nextDelta);
15539
+ delete this.removed[id];
15540
+ delete this.updated[id];
15541
+ this.added[id] = Delta.merge(prevDelta, nextDelta, mergedDelta);
15542
+ }
15543
+ }
15544
+ for (const [id, nextDelta] of Object.entries(removed)) {
15545
+ const prevDelta = this.added[id] ?? this.removed[id] ?? this.updated[id];
15546
+ if (!prevDelta) {
15547
+ this.removed[id] = nextDelta;
15548
+ } else {
15549
+ const mergedDelta = mergeBoundElements(prevDelta, nextDelta);
15550
+ delete this.added[id];
15551
+ delete this.updated[id];
15552
+ this.removed[id] = Delta.merge(prevDelta, nextDelta, mergedDelta);
15553
+ }
15554
+ }
15555
+ for (const [id, nextDelta] of Object.entries(updated)) {
15556
+ const prevDelta = this.added[id] ?? this.removed[id] ?? this.updated[id];
15557
+ if (!prevDelta) {
15558
+ this.updated[id] = nextDelta;
15559
+ } else {
15560
+ const mergedDelta = mergeBoundElements(prevDelta, nextDelta);
15561
+ const updatedDelta = Delta.merge(prevDelta, nextDelta, mergedDelta);
15562
+ if (prevDelta === this.added[id]) {
15563
+ this.added[id] = updatedDelta;
15564
+ } else if (prevDelta === this.removed[id]) {
15565
+ this.removed[id] = updatedDelta;
15566
+ } else {
15567
+ this.updated[id] = updatedDelta;
15568
+ }
15569
+ }
15570
+ }
15571
+ if (isTestEnv8() || isDevEnv7()) {
15572
+ _ElementsDelta.validate(this, "added", _ElementsDelta.satisfiesAddition);
15573
+ _ElementsDelta.validate(this, "removed", _ElementsDelta.satisfiesRemoval);
15574
+ _ElementsDelta.validate(this, "updated", _ElementsDelta.satisfiesUpdate);
15575
+ }
15576
+ return this;
15577
+ }
15578
+ static createApplier = (prevElements, nextElements, snapshot, flags, options) => (deltas) => {
15401
15579
  const getElement = _ElementsDelta.createGetter(
15402
15580
  nextElements,
15403
15581
  snapshot,
@@ -15406,14 +15584,20 @@ var ElementsDelta = class _ElementsDelta {
15406
15584
  return Object.entries(deltas).reduce((acc, [id, delta]) => {
15407
15585
  const element = getElement(id, delta.inserted);
15408
15586
  if (element) {
15409
- const newElement2 = _ElementsDelta.applyDelta(
15587
+ const nextElement = _ElementsDelta.applyDelta(
15410
15588
  element,
15411
15589
  delta,
15412
- options,
15413
- flags
15590
+ flags,
15591
+ options
15414
15592
  );
15415
- nextElements.set(newElement2.id, newElement2);
15416
- acc.set(newElement2.id, newElement2);
15593
+ nextElements.set(nextElement.id, nextElement);
15594
+ acc.set(nextElement.id, nextElement);
15595
+ if (!flags.applyDirection) {
15596
+ const prevElement = prevElements.get(id);
15597
+ if (prevElement) {
15598
+ flags.applyDirection = prevElement.version > nextElement.version ? "backward" : "forward";
15599
+ }
15600
+ }
15417
15601
  }
15418
15602
  return acc;
15419
15603
  }, /* @__PURE__ */ new Map());
@@ -15438,13 +15622,13 @@ var ElementsDelta = class _ElementsDelta {
15438
15622
  }
15439
15623
  return element;
15440
15624
  };
15441
- static applyDelta(element, delta, options, flags) {
15625
+ static applyDelta(element, delta, flags, options) {
15442
15626
  const directlyApplicablePartial = {};
15443
15627
  for (const key of Object.keys(delta.inserted)) {
15444
15628
  if (key === "boundElements") {
15445
15629
  continue;
15446
15630
  }
15447
- if (options.excludedProperties.has(key)) {
15631
+ if (options?.excludedProperties?.has(key)) {
15448
15632
  continue;
15449
15633
  }
15450
15634
  const value = delta.inserted[key];
@@ -15472,7 +15656,7 @@ var ElementsDelta = class _ElementsDelta {
15472
15656
  if (!flags.containsZindexDifference) {
15473
15657
  flags.containsZindexDifference = delta.deleted.index !== delta.inserted.index;
15474
15658
  }
15475
- return newElementWith(element, directlyApplicablePartial);
15659
+ return newElementWith(element, directlyApplicablePartial, true);
15476
15660
  }
15477
15661
  /**
15478
15662
  * Check for visible changes regardless of whether they were removed, added or updated.
@@ -15497,25 +15681,32 @@ var ElementsDelta = class _ElementsDelta {
15497
15681
  *
15498
15682
  * @returns all elements affected by the conflict resolution
15499
15683
  */
15500
- resolveConflicts(prevElements, nextElements) {
15684
+ resolveConflicts(prevElements, nextElements, applyDirection = "forward") {
15501
15685
  const nextAffectedElements = /* @__PURE__ */ new Map();
15502
15686
  const updater = (element, updates) => {
15503
15687
  const nextElement = nextElements.get(element.id);
15504
15688
  if (!nextElement) {
15505
15689
  return;
15506
15690
  }
15691
+ const prevElement = prevElements.get(element.id);
15692
+ const nextVersion = applyDirection === "forward" ? nextElement.version + 1 : nextElement.version - 1;
15693
+ const elementUpdates = updates;
15507
15694
  let affectedElement;
15508
- if (prevElements.get(element.id) === nextElement) {
15695
+ if (prevElement === nextElement) {
15509
15696
  affectedElement = newElementWith(
15510
15697
  nextElement,
15511
- updates
15698
+ {
15699
+ ...elementUpdates,
15700
+ version: nextVersion
15701
+ },
15702
+ true
15512
15703
  );
15513
15704
  } else {
15514
- affectedElement = mutateElement(
15515
- nextElement,
15516
- nextElements,
15517
- updates
15518
- );
15705
+ affectedElement = mutateElement(nextElement, nextElements, {
15706
+ ...elementUpdates,
15707
+ // don't modify the version further, if it's already different
15708
+ version: prevElement?.version !== nextElement.version ? nextElement.version : nextVersion
15709
+ });
15519
15710
  }
15520
15711
  nextAffectedElements.set(affectedElement.id, affectedElement);
15521
15712
  nextElements.set(affectedElement.id, affectedElement);
@@ -15540,19 +15731,10 @@ var ElementsDelta = class _ElementsDelta {
15540
15731
  const prevAffectedElements = new Map(
15541
15732
  Array.from(prevElements).filter(([id]) => nextAffectedElements.has(id))
15542
15733
  );
15543
- const { added, removed, updated } = _ElementsDelta.calculate(
15544
- prevAffectedElements,
15545
- nextAffectedElements
15734
+ this.squash(
15735
+ // technically we could do better here if perf. would become an issue
15736
+ _ElementsDelta.calculate(prevAffectedElements, nextAffectedElements)
15546
15737
  );
15547
- for (const [id, delta] of Object.entries(added)) {
15548
- this.added[id] = delta;
15549
- }
15550
- for (const [id, delta] of Object.entries(removed)) {
15551
- this.removed[id] = delta;
15552
- }
15553
- for (const [id, delta] of Object.entries(updated)) {
15554
- this.updated[id] = delta;
15555
- }
15556
15738
  return nextAffectedElements;
15557
15739
  }
15558
15740
  /**
@@ -15587,6 +15769,20 @@ var ElementsDelta = class _ElementsDelta {
15587
15769
  );
15588
15770
  BindableElement.rebindAffected(nextElements, nextElement(), updater);
15589
15771
  }
15772
+ static redrawElements(nextElements, changedElements) {
15773
+ try {
15774
+ const tempScene = new Scene(nextElements, { skipValidation: true });
15775
+ _ElementsDelta.redrawTextBoundingBoxes(tempScene, changedElements);
15776
+ _ElementsDelta.redrawBoundArrows(tempScene, changedElements);
15777
+ } catch (e) {
15778
+ console.error(`Couldn't redraw elements`, e);
15779
+ if (isTestEnv8() || isDevEnv7()) {
15780
+ throw e;
15781
+ }
15782
+ } finally {
15783
+ return nextElements;
15784
+ }
15785
+ }
15590
15786
  static redrawTextBoundingBoxes(scene, changed) {
15591
15787
  const elements = scene.getNonDeletedElementsMap();
15592
15788
  const boxesToRedraw = /* @__PURE__ */ new Map();
@@ -15675,14 +15871,22 @@ var ElementsDelta = class _ElementsDelta {
15675
15871
  const { id, updated, ...strippedPartial } = partial;
15676
15872
  return strippedPartial;
15677
15873
  }
15874
+ static stripVersionProps(partial) {
15875
+ const { version, versionNonce, ...strippedPartial } = partial;
15876
+ return strippedPartial;
15877
+ }
15678
15878
  };
15679
15879
 
15680
15880
  // src/distribute.ts
15681
15881
  init_define_import_meta_env();
15682
- var distributeElements = (selectedElements, elementsMap, distribution) => {
15882
+ var distributeElements = (selectedElements, elementsMap, distribution, appState) => {
15683
15883
  const [start, mid, end, extent] = distribution.axis === "x" ? ["minX", "midX", "maxX", "width"] : ["minY", "midY", "maxY", "height"];
15684
15884
  const bounds = getCommonBoundingBox(selectedElements);
15685
- const groups = getMaximumGroups(selectedElements, elementsMap).map((group) => [group, getCommonBoundingBox(group)]).sort((a2, b2) => a2[1][mid] - b2[1][mid]);
15885
+ const groups = getSelectedElementsByGroup(
15886
+ selectedElements,
15887
+ elementsMap,
15888
+ appState
15889
+ ).map((group) => [group, getCommonBoundingBox(group)]).sort((a2, b2) => a2[1][mid] - b2[1][mid]);
15686
15890
  let span = 0;
15687
15891
  for (const group of groups) {
15688
15892
  span += group[1][extent];
@@ -16325,7 +16529,7 @@ var newImageElement = (opts) => {
16325
16529
 
16326
16530
  // src/embeddable.ts
16327
16531
  var embeddedLinkCache = /* @__PURE__ */ new Map();
16328
- var RE_YOUTUBE = /^(?:http(?:s)?:\/\/)?(?:www\.)?youtu(?:be\.com|\.be)\/(embed\/|watch\?v=|shorts\/|playlist\?list=|embed\/videoseries\?list=)?([a-zA-Z0-9_-]+)(?:\?t=|&t=|\?start=|&start=)?([a-zA-Z0-9_-]+)?[^\s]*$/;
16532
+ var RE_YOUTUBE = /^(?:http(?:s)?:\/\/)?(?:www\.)?youtu(?:be\.com|\.be)\/(embed\/|watch\?v=|shorts\/|playlist\?list=|embed\/videoseries\?list=)?([a-zA-Z0-9_-]+)/;
16329
16533
  var RE_VIMEO = /^(?:http(?:s)?:\/\/)?(?:(?:w){3}\.)?(?:player\.)?vimeo\.com\/(?:video\/)?([^?\s]+)(?:\?.*)?$/;
16330
16534
  var RE_FIGMA = /^https:\/\/(?:www\.)?figma\.com/;
16331
16535
  var RE_GH_GIST = /^https:\/\/gist\.github\.com\/([\w_-]+)\/([\w_-]+)/;
@@ -16338,6 +16542,28 @@ var RE_GENERIC_EMBED = /^<(?:iframe|blockquote)[\s\S]*?\s(?:src|href)=["']([^"']
16338
16542
  var RE_GIPHY = /giphy.com\/(?:clips|embed|gifs)\/[a-zA-Z0-9]*?-?([a-zA-Z0-9]+)(?:[^a-zA-Z0-9]|$)/;
16339
16543
  var RE_REDDIT = /^(?:http(?:s)?:\/\/)?(?:www\.)?reddit\.com\/r\/([a-zA-Z0-9_]+)\/comments\/([a-zA-Z0-9_]+)\/([a-zA-Z0-9_]+)\/?(?:\?[^#\s]*)?(?:#[^\s]*)?$/;
16340
16544
  var RE_REDDIT_EMBED = /^<blockquote[\s\S]*?\shref=["'](https?:\/\/(?:www\.)?reddit\.com\/[^"']*)/i;
16545
+ var parseYouTubeTimestamp = (url) => {
16546
+ let timeParam;
16547
+ try {
16548
+ const urlObj = new URL(url.startsWith("http") ? url : `https://${url}`);
16549
+ timeParam = urlObj.searchParams.get("t") || urlObj.searchParams.get("start");
16550
+ } catch (error) {
16551
+ const timeMatch2 = url.match(/[?&#](?:t|start)=([^&#\s]+)/);
16552
+ timeParam = timeMatch2?.[1];
16553
+ }
16554
+ if (!timeParam) {
16555
+ return 0;
16556
+ }
16557
+ if (/^\d+$/.test(timeParam)) {
16558
+ return parseInt(timeParam, 10);
16559
+ }
16560
+ const timeMatch = timeParam.match(/^(?:(\d+)h)?(?:(\d+)m)?(?:(\d+)s)?$/);
16561
+ if (!timeMatch) {
16562
+ return 0;
16563
+ }
16564
+ const [, hours = "0", minutes = "0", seconds = "0"] = timeMatch;
16565
+ return parseInt(hours) * 3600 + parseInt(minutes) * 60 + parseInt(seconds);
16566
+ };
16341
16567
  var ALLOWED_DOMAINS = /* @__PURE__ */ new Set([
16342
16568
  "youtube.com",
16343
16569
  "youtu.be",
@@ -16386,7 +16612,8 @@ var getEmbedLink = (link) => {
16386
16612
  let aspectRatio = { w: 560, h: 840 };
16387
16613
  const ytLink = link.match(RE_YOUTUBE);
16388
16614
  if (ytLink?.[2]) {
16389
- const time = ytLink[3] ? `&start=${ytLink[3]}` : ``;
16615
+ const startTime = parseYouTubeTimestamp(originalLink);
16616
+ const time = startTime > 0 ? `&start=${startTime}` : ``;
16390
16617
  const isPortrait = link.includes("shorts");
16391
16618
  type = "video";
16392
16619
  switch (ytLink[1]) {
@@ -18371,7 +18598,7 @@ var getTransformHandles = (element, zoom, elementsMap, pointerType = "mouse", om
18371
18598
  );
18372
18599
  };
18373
18600
  var shouldShowBoundingBox = (elements, appState) => {
18374
- if (appState.editingLinearElement) {
18601
+ if (appState.selectedLinearElement?.isEditing) {
18375
18602
  return false;
18376
18603
  }
18377
18604
  if (elements.length > 1) {
@@ -19119,6 +19346,7 @@ export {
19119
19346
  getRootElements,
19120
19347
  getSceneVersion,
19121
19348
  getSelectedElements,
19349
+ getSelectedElementsByGroup,
19122
19350
  getSelectedGroupForElement,
19123
19351
  getSelectedGroupIdForElement,
19124
19352
  getSelectedGroupIds,