@excalidraw/element 0.18.0-4e471c107 → 0.18.0-5fffc47

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/dist/dev/index.js +1048 -613
  2. package/dist/dev/index.js.map +4 -4
  3. package/dist/prod/index.js +14 -14
  4. package/dist/types/common/src/constants.d.ts +24 -4
  5. package/dist/types/common/src/utils.d.ts +3 -0
  6. package/dist/types/element/src/Scene.d.ts +6 -2
  7. package/dist/types/element/src/align.d.ts +2 -1
  8. package/dist/types/element/src/bounds.d.ts +1 -1
  9. package/dist/types/element/src/delta.d.ts +16 -4
  10. package/dist/types/element/src/distribute.d.ts +2 -1
  11. package/dist/types/element/src/groups.d.ts +1 -0
  12. package/dist/types/element/src/index.d.ts +1 -0
  13. package/dist/types/element/src/linearElementEditor.d.ts +2 -1
  14. package/dist/types/element/src/positionElementsOnGrid.d.ts +2 -0
  15. package/dist/types/element/src/renderElement.d.ts +4 -1
  16. package/dist/types/element/src/store.d.ts +6 -1
  17. package/dist/types/element/src/textElement.d.ts +1 -1
  18. package/dist/types/excalidraw/actions/actionAddToLibrary.d.ts +21 -9
  19. package/dist/types/excalidraw/actions/actionBoundText.d.ts +14 -6
  20. package/dist/types/excalidraw/actions/actionCanvas.d.ts +94 -41
  21. package/dist/types/excalidraw/actions/actionClipboard.d.ts +45 -20
  22. package/dist/types/excalidraw/actions/actionCropEditor.d.ts +7 -3
  23. package/dist/types/excalidraw/actions/actionDeleteSelected.d.ts +24 -12
  24. package/dist/types/excalidraw/actions/actionElementLink.d.ts +7 -3
  25. package/dist/types/excalidraw/actions/actionElementLock.d.ts +14 -6
  26. package/dist/types/excalidraw/actions/actionEmbeddable.d.ts +7 -3
  27. package/dist/types/excalidraw/actions/actionExport.d.ts +63 -27
  28. package/dist/types/excalidraw/actions/actionFinalize.d.ts +16 -7
  29. package/dist/types/excalidraw/actions/actionFrame.d.ts +28 -12
  30. package/dist/types/excalidraw/actions/actionGroup.d.ts +14 -6
  31. package/dist/types/excalidraw/actions/actionLinearEditor.d.ts +41 -6
  32. package/dist/types/excalidraw/actions/actionLink.d.ts +6 -2
  33. package/dist/types/excalidraw/actions/actionMenu.d.ts +7 -371
  34. package/dist/types/excalidraw/actions/actionNavigate.d.ts +14 -6
  35. package/dist/types/excalidraw/actions/actionProperties.d.ts +122 -53
  36. package/dist/types/excalidraw/actions/actionSelectAll.d.ts +7 -3
  37. package/dist/types/excalidraw/actions/actionStyles.d.ts +7 -3
  38. package/dist/types/excalidraw/actions/actionToggleGridMode.d.ts +7 -3
  39. package/dist/types/excalidraw/actions/actionToggleObjectsSnapMode.d.ts +7 -3
  40. package/dist/types/excalidraw/actions/actionToggleSearchMenu.d.ts +7 -3
  41. package/dist/types/excalidraw/actions/actionToggleStats.d.ts +7 -3
  42. package/dist/types/excalidraw/actions/actionToggleViewMode.d.ts +7 -3
  43. package/dist/types/excalidraw/actions/actionToggleZenMode.d.ts +7 -3
  44. package/dist/types/excalidraw/actions/index.d.ts +2 -2
  45. package/dist/types/excalidraw/actions/types.d.ts +1 -1
  46. package/dist/types/excalidraw/appState.d.ts +5 -1
  47. package/dist/types/excalidraw/clipboard.d.ts +64 -1
  48. package/dist/types/excalidraw/components/Actions.d.ts +17 -7
  49. package/dist/types/excalidraw/components/App.d.ts +10 -8
  50. package/dist/types/excalidraw/components/ColorPicker/ColorPicker.d.ts +1 -0
  51. package/dist/types/excalidraw/components/ColorPicker/Picker.d.ts +2 -0
  52. package/dist/types/excalidraw/components/ColorPicker/PickerColorList.d.ts +2 -1
  53. package/dist/types/excalidraw/components/ColorPicker/ShadeList.d.ts +2 -1
  54. package/dist/types/excalidraw/components/CommandPalette/CommandPalette.d.ts +1 -0
  55. package/dist/types/excalidraw/components/Ellipsify.d.ts +4 -0
  56. package/dist/types/excalidraw/components/ExcalidrawLogo.d.ts +1 -1
  57. package/dist/types/excalidraw/components/FontPicker/FontPicker.d.ts +2 -1
  58. package/dist/types/excalidraw/components/FontPicker/FontPickerTrigger.d.ts +3 -1
  59. package/dist/types/excalidraw/components/InlineIcon.d.ts +3 -1
  60. package/dist/types/excalidraw/components/LayerUI.d.ts +2 -1
  61. package/dist/types/excalidraw/components/LibraryMenuSection.d.ts +1 -1
  62. package/dist/types/excalidraw/components/MobileMenu.d.ts +3 -5
  63. package/dist/types/excalidraw/components/MobileToolBar.d.ts +11 -0
  64. package/dist/types/excalidraw/components/PropertiesPopover.d.ts +1 -0
  65. package/dist/types/excalidraw/components/TTDDialog/TTDDialogTrigger.d.ts +1 -2
  66. package/dist/types/excalidraw/components/TextField.d.ts +1 -0
  67. package/dist/types/excalidraw/components/ToolPopover.d.ts +25 -0
  68. package/dist/types/excalidraw/components/dropdownMenu/DropdownMenu.d.ts +4 -2
  69. package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuContent.d.ts +2 -1
  70. package/dist/types/excalidraw/components/icons.d.ts +5 -0
  71. package/dist/types/excalidraw/components/shapes.d.ts +129 -1
  72. package/dist/types/excalidraw/data/blob.d.ts +3 -7
  73. package/dist/types/excalidraw/data/reconcile.d.ts +1 -0
  74. package/dist/types/excalidraw/data/restore.d.ts +6 -1
  75. package/dist/types/excalidraw/data/types.d.ts +4 -1
  76. package/dist/types/excalidraw/hooks/useLibraryItemSvg.d.ts +1 -1
  77. package/dist/types/excalidraw/hooks/useTextEditorFocus.d.ts +14 -0
  78. package/dist/types/excalidraw/index.d.ts +2 -1
  79. package/dist/types/excalidraw/renderer/staticScene.d.ts +4 -1
  80. package/dist/types/excalidraw/types.d.ts +16 -6
  81. package/dist/types/math/src/segment.d.ts +1 -0
  82. package/package.json +3 -3
package/dist/dev/index.js CHANGED
@@ -2261,17 +2261,17 @@ var rough_default = {
2261
2261
  // src/bounds.ts
2262
2262
  import {
2263
2263
  arrayToMap as arrayToMap6,
2264
- invariant as invariant7,
2264
+ invariant as invariant8,
2265
2265
  rescalePoints,
2266
2266
  sizeOf
2267
2267
  } from "@excalidraw/common";
2268
2268
  import {
2269
2269
  degreesToRadians,
2270
- lineSegment as lineSegment5,
2270
+ lineSegment as lineSegment6,
2271
2271
  pointDistance as pointDistance7,
2272
- pointFrom as pointFrom12,
2272
+ pointFrom as pointFrom14,
2273
2273
  pointFromArray as pointFromArray3,
2274
- pointRotateRads as pointRotateRads10
2274
+ pointRotateRads as pointRotateRads12
2275
2275
  } from "@excalidraw/math";
2276
2276
 
2277
2277
  // ../utils/src/shape.ts
@@ -2448,9 +2448,9 @@ var getClosedCurveShape = (element, roughShape, startingPoint = pointFrom(0, 0),
2448
2448
  // src/shape.ts
2449
2449
  init_define_import_meta_env();
2450
2450
  import {
2451
- pointFrom as pointFrom11,
2451
+ pointFrom as pointFrom13,
2452
2452
  pointDistance as pointDistance6,
2453
- pointRotateRads as pointRotateRads9
2453
+ pointRotateRads as pointRotateRads11
2454
2454
  } from "@excalidraw/math";
2455
2455
  import {
2456
2456
  ROUGHNESS,
@@ -2627,7 +2627,12 @@ function ae(e, t = {}) {
2627
2627
  }
2628
2628
 
2629
2629
  // src/renderElement.ts
2630
- import { isRightAngleRads } from "@excalidraw/math";
2630
+ import {
2631
+ isRightAngleRads,
2632
+ lineSegment as lineSegment5,
2633
+ pointFrom as pointFrom12,
2634
+ pointRotateRads as pointRotateRads10
2635
+ } from "@excalidraw/math";
2631
2636
  import {
2632
2637
  BOUND_TEXT_PADDING as BOUND_TEXT_PADDING3,
2633
2638
  DEFAULT_REDUCED_GLOBAL_ALPHA,
@@ -2638,7 +2643,8 @@ import {
2638
2643
  distance as distance2,
2639
2644
  getFontString as getFontString3,
2640
2645
  isRTL,
2641
- getVerticalOffset
2646
+ getVerticalOffset,
2647
+ invariant as invariant7
2642
2648
  } from "@excalidraw/common";
2643
2649
 
2644
2650
  // src/cropElement.ts
@@ -3103,8 +3109,8 @@ var getFlipAdjustedCropPosition = (element, natural = false) => {
3103
3109
  init_define_import_meta_env();
3104
3110
  import {
3105
3111
  pointCenter as pointCenter2,
3106
- pointFrom as pointFrom8,
3107
- pointRotateRads as pointRotateRads7,
3112
+ pointFrom as pointFrom9,
3113
+ pointRotateRads as pointRotateRads8,
3108
3114
  pointsEqual as pointsEqual6,
3109
3115
  pointDistance as pointDistance5,
3110
3116
  vectorFromPoint as vectorFromPoint7,
@@ -3138,8 +3144,8 @@ import {
3138
3144
  } from "@excalidraw/common";
3139
3145
  import {
3140
3146
  lineSegment as lineSegment4,
3141
- pointFrom as pointFrom7,
3142
- pointRotateRads as pointRotateRads6,
3147
+ pointFrom as pointFrom8,
3148
+ pointRotateRads as pointRotateRads7,
3143
3149
  vectorFromPoint as vectorFromPoint6,
3144
3150
  pointDistanceSq,
3145
3151
  clamp as clamp3,
@@ -3161,9 +3167,9 @@ import {
3161
3167
  isPointWithinBounds,
3162
3168
  lineSegment as lineSegment3,
3163
3169
  lineSegmentIntersectionPoints,
3164
- pointFrom as pointFrom4,
3170
+ pointFrom as pointFrom5,
3165
3171
  pointFromVector as pointFromVector3,
3166
- pointRotateRads as pointRotateRads4,
3172
+ pointRotateRads as pointRotateRads5,
3167
3173
  pointsEqual as pointsEqual2,
3168
3174
  vectorFromPoint as vectorFromPoint3,
3169
3175
  vectorNormalize as vectorNormalize2,
@@ -3711,6 +3717,7 @@ import {
3711
3717
  isProdEnv,
3712
3718
  invariant as invariant2
3713
3719
  } from "@excalidraw/common";
3720
+ import { pointFrom as pointFrom4, pointRotateRads as pointRotateRads3 } from "@excalidraw/math";
3714
3721
 
3715
3722
  // src/containerCache.ts
3716
3723
  init_define_import_meta_env();
@@ -3825,9 +3832,6 @@ var getTextWidth = (text, font) => {
3825
3832
  return width;
3826
3833
  };
3827
3834
  var getTextHeight = (text, fontSize, lineHeight) => {
3828
- if (text === "") {
3829
- return 0;
3830
- }
3831
3835
  const lineCount = splitIntoLines(text).length;
3832
3836
  return getLineHeightInPx(fontSize, lineHeight) * lineCount;
3833
3837
  };
@@ -4393,6 +4397,22 @@ var computeBoundTextPosition = (container, boundTextElement, elementsMap) => {
4393
4397
  } else {
4394
4398
  x = containerCoords.x + (maxContainerWidth / 2 - boundTextElement.width / 2);
4395
4399
  }
4400
+ const angle = container.angle ?? 0;
4401
+ if (angle !== 0) {
4402
+ const contentCenter = pointFrom4(
4403
+ containerCoords.x + maxContainerWidth / 2,
4404
+ containerCoords.y + maxContainerHeight / 2
4405
+ );
4406
+ const textCenter = pointFrom4(
4407
+ x + boundTextElement.width / 2,
4408
+ y + boundTextElement.height / 2
4409
+ );
4410
+ const [rx, ry] = pointRotateRads3(textCenter, contentCenter, angle);
4411
+ return {
4412
+ x: rx - boundTextElement.width / 2,
4413
+ y: ry - boundTextElement.height / 2
4414
+ };
4415
+ }
4396
4416
  return { x, y };
4397
4417
  };
4398
4418
  var getBoundTextElementId = (container) => {
@@ -4576,7 +4596,7 @@ init_define_import_meta_env();
4576
4596
  import {
4577
4597
  curvePointDistance,
4578
4598
  distanceToLineSegment,
4579
- pointRotateRads as pointRotateRads3
4599
+ pointRotateRads as pointRotateRads4
4580
4600
  } from "@excalidraw/math";
4581
4601
  import { ellipse as ellipse2, ellipseDistanceFromPoint } from "@excalidraw/math/ellipse";
4582
4602
  var distanceToElement = (element, elementsMap, p) => {
@@ -4602,7 +4622,7 @@ var distanceToElement = (element, elementsMap, p) => {
4602
4622
  };
4603
4623
  var distanceToRectanguloidElement = (element, elementsMap, p) => {
4604
4624
  const center = elementCenterPoint(element, elementsMap);
4605
- const rotatedPoint = pointRotateRads3(p, center, -element.angle);
4625
+ const rotatedPoint = pointRotateRads4(p, center, -element.angle);
4606
4626
  const [sides, corners] = deconstructRectanguloidElement(element);
4607
4627
  return Math.min(
4608
4628
  ...sides.map((s) => distanceToLineSegment(rotatedPoint, s)),
@@ -4611,7 +4631,7 @@ var distanceToRectanguloidElement = (element, elementsMap, p) => {
4611
4631
  };
4612
4632
  var distanceToDiamondElement = (element, elementsMap, p) => {
4613
4633
  const center = elementCenterPoint(element, elementsMap);
4614
- const rotatedPoint = pointRotateRads3(p, center, -element.angle);
4634
+ const rotatedPoint = pointRotateRads4(p, center, -element.angle);
4615
4635
  const [sides, curves] = deconstructDiamondElement(element);
4616
4636
  return Math.min(
4617
4637
  ...sides.map((s) => distanceToLineSegment(rotatedPoint, s)),
@@ -4622,7 +4642,7 @@ var distanceToEllipseElement = (element, elementsMap, p) => {
4622
4642
  const center = elementCenterPoint(element, elementsMap);
4623
4643
  return ellipseDistanceFromPoint(
4624
4644
  // Instead of rotating the ellipse, rotate the point to the inverse angle
4625
- pointRotateRads3(p, center, -element.angle),
4645
+ pointRotateRads4(p, center, -element.angle),
4626
4646
  ellipse2(center, element.width / 2, element.height / 2)
4627
4647
  );
4628
4648
  };
@@ -4656,22 +4676,22 @@ var hitElementItself = ({
4656
4676
  frameNameBound = null
4657
4677
  }) => {
4658
4678
  const hitFrameName = frameNameBound ? isPointWithinBounds(
4659
- pointFrom4(frameNameBound.x - threshold, frameNameBound.y - threshold),
4679
+ pointFrom5(frameNameBound.x - threshold, frameNameBound.y - threshold),
4660
4680
  point,
4661
- pointFrom4(
4681
+ pointFrom5(
4662
4682
  frameNameBound.x + frameNameBound.width + threshold,
4663
4683
  frameNameBound.y + frameNameBound.height + threshold
4664
4684
  )
4665
4685
  ) : false;
4666
4686
  const bounds = getElementBounds(element, elementsMap, true);
4667
4687
  const hitBounds = isPointWithinBounds(
4668
- pointFrom4(bounds[0] - threshold, bounds[1] - threshold),
4669
- pointRotateRads4(
4688
+ pointFrom5(bounds[0] - threshold, bounds[1] - threshold),
4689
+ pointRotateRads5(
4670
4690
  point,
4671
4691
  getCenterForBounds(bounds),
4672
4692
  -element.angle
4673
4693
  ),
4674
- pointFrom4(bounds[2] + threshold, bounds[3] + threshold)
4694
+ pointFrom5(bounds[2] + threshold, bounds[3] + threshold)
4675
4695
  );
4676
4696
  if (!hitBounds && !hitFrameName) {
4677
4697
  return false;
@@ -4689,7 +4709,7 @@ var hitElementBoundingBox = (point, element, elementsMap, tolerance = 0) => {
4689
4709
  y1 -= tolerance;
4690
4710
  x2 += tolerance;
4691
4711
  y2 += tolerance;
4692
- return isPointWithinBounds(pointFrom4(x1, y1), point, pointFrom4(x2, y2));
4712
+ return isPointWithinBounds(pointFrom5(x1, y1), point, pointFrom5(x2, y2));
4693
4713
  };
4694
4714
  var hitElementBoundingBoxOnly = (hitArgs, elementsMap) => !hitElementItself(hitArgs) && // bound text is considered part of the element (even if it's outside the bounding box)
4695
4715
  !hitElementBoundText(hitArgs.point, hitArgs.element, elementsMap) && hitElementBoundingBox(hitArgs.point, hitArgs.element, elementsMap);
@@ -4773,7 +4793,7 @@ var curveIntersections = (curves, segment, intersections, center, angle, onlyFir
4773
4793
  const hits = curveIntersectLineSegment(c, segment);
4774
4794
  if (hits.length > 0) {
4775
4795
  for (const j of hits) {
4776
- intersections.push(pointRotateRads4(j, center, angle));
4796
+ intersections.push(pointRotateRads5(j, center, angle));
4777
4797
  }
4778
4798
  if (onlyFirst) {
4779
4799
  return intersections;
@@ -4786,7 +4806,7 @@ var lineIntersections = (lines, segment, intersections, center, angle, onlyFirst
4786
4806
  for (const l2 of lines) {
4787
4807
  const intersection = lineSegmentIntersectionPoints(l2, segment);
4788
4808
  if (intersection) {
4789
- intersections.push(pointRotateRads4(intersection, center, angle));
4809
+ intersections.push(pointRotateRads5(intersection, center, angle));
4790
4810
  if (onlyFirst) {
4791
4811
  return intersections;
4792
4812
  }
@@ -4829,12 +4849,12 @@ var intersectLinearOrFreeDrawWithLineSegment = (element, segment, onlyFirst = fa
4829
4849
  };
4830
4850
  var intersectRectanguloidWithLineSegment = (element, elementsMap, segment, offset = 0, onlyFirst = false) => {
4831
4851
  const center = elementCenterPoint(element, elementsMap);
4832
- const rotatedA = pointRotateRads4(
4852
+ const rotatedA = pointRotateRads5(
4833
4853
  segment[0],
4834
4854
  center,
4835
4855
  -element.angle
4836
4856
  );
4837
- const rotatedB = pointRotateRads4(
4857
+ const rotatedB = pointRotateRads5(
4838
4858
  segment[1],
4839
4859
  center,
4840
4860
  -element.angle
@@ -4865,8 +4885,8 @@ var intersectRectanguloidWithLineSegment = (element, elementsMap, segment, offse
4865
4885
  };
4866
4886
  var intersectDiamondWithLineSegment = (element, elementsMap, l2, offset = 0, onlyFirst = false) => {
4867
4887
  const center = elementCenterPoint(element, elementsMap);
4868
- const rotatedA = pointRotateRads4(l2[0], center, -element.angle);
4869
- const rotatedB = pointRotateRads4(l2[1], center, -element.angle);
4888
+ const rotatedA = pointRotateRads5(l2[0], center, -element.angle);
4889
+ const rotatedB = pointRotateRads5(l2[1], center, -element.angle);
4870
4890
  const rotatedIntersector = lineSegment3(rotatedA, rotatedB);
4871
4891
  const [sides, corners] = deconstructDiamondElement(element, offset);
4872
4892
  const intersections = [];
@@ -4893,12 +4913,12 @@ var intersectDiamondWithLineSegment = (element, elementsMap, l2, offset = 0, onl
4893
4913
  };
4894
4914
  var intersectEllipseWithLineSegment = (element, elementsMap, l2, offset = 0) => {
4895
4915
  const center = elementCenterPoint(element, elementsMap);
4896
- const rotatedA = pointRotateRads4(l2[0], center, -element.angle);
4897
- const rotatedB = pointRotateRads4(l2[1], center, -element.angle);
4916
+ const rotatedA = pointRotateRads5(l2[0], center, -element.angle);
4917
+ const rotatedB = pointRotateRads5(l2[1], center, -element.angle);
4898
4918
  return ellipseSegmentInterceptPoints(
4899
4919
  ellipse3(center, element.width / 2 + offset, element.height / 2 + offset),
4900
4920
  lineSegment3(rotatedA, rotatedB)
4901
- ).map((p) => pointRotateRads4(p, center, element.angle));
4921
+ ).map((p) => pointRotateRads5(p, center, element.angle));
4902
4922
  };
4903
4923
  var isPointOnElementOutline = (point, element, elementsMap, tolerance = 1) => distanceToElement(element, elementsMap, point) <= tolerance;
4904
4924
  var isPointInElement = (point, element, elementsMap) => {
@@ -4906,10 +4926,10 @@ var isPointInElement = (point, element, elementsMap) => {
4906
4926
  return false;
4907
4927
  }
4908
4928
  const [x1, y1, x2, y2] = getElementBounds(element, elementsMap);
4909
- if (!isPointWithinBounds(pointFrom4(x1, y1), point, pointFrom4(x2, y2))) {
4929
+ if (!isPointWithinBounds(pointFrom5(x1, y1), point, pointFrom5(x2, y2))) {
4910
4930
  return false;
4911
4931
  }
4912
- const center = pointFrom4((x1 + x2) / 2, (y1 + y2) / 2);
4932
+ const center = pointFrom5((x1 + x2) / 2, (y1 + y2) / 2);
4913
4933
  const otherPoint = pointFromVector3(
4914
4934
  vectorScale3(
4915
4935
  vectorNormalize2(vectorFromPoint3(point, center, 0.1)),
@@ -4930,9 +4950,9 @@ var isPointInElement = (point, element, elementsMap) => {
4930
4950
  init_define_import_meta_env();
4931
4951
  import { invariant as invariant3, isDevEnv as isDevEnv2, isTestEnv as isTestEnv3 } from "@excalidraw/common";
4932
4952
  import {
4933
- pointFrom as pointFrom5,
4953
+ pointFrom as pointFrom6,
4934
4954
  pointFromVector as pointFromVector4,
4935
- pointRotateRads as pointRotateRads5,
4955
+ pointRotateRads as pointRotateRads6,
4936
4956
  pointScaleFromOrigin,
4937
4957
  pointsEqual as pointsEqual3,
4938
4958
  triangleIncludesPoint,
@@ -4978,8 +4998,8 @@ var headingForPointFromDiamondElement = (element, aabb, point) => {
4978
4998
  const top = pointFromVector4(
4979
4999
  vectorScale4(
4980
5000
  vectorFromPoint4(
4981
- pointRotateRads5(
4982
- pointFrom5(element.x + element.width / 2, element.y),
5001
+ pointRotateRads6(
5002
+ pointFrom6(element.x + element.width / 2, element.y),
4983
5003
  midPoint,
4984
5004
  element.angle
4985
5005
  ),
@@ -4992,8 +5012,8 @@ var headingForPointFromDiamondElement = (element, aabb, point) => {
4992
5012
  const right = pointFromVector4(
4993
5013
  vectorScale4(
4994
5014
  vectorFromPoint4(
4995
- pointRotateRads5(
4996
- pointFrom5(
5015
+ pointRotateRads6(
5016
+ pointFrom6(
4997
5017
  element.x + element.width,
4998
5018
  element.y + element.height / 2
4999
5019
  ),
@@ -5009,8 +5029,8 @@ var headingForPointFromDiamondElement = (element, aabb, point) => {
5009
5029
  const bottom = pointFromVector4(
5010
5030
  vectorScale4(
5011
5031
  vectorFromPoint4(
5012
- pointRotateRads5(
5013
- pointFrom5(
5032
+ pointRotateRads6(
5033
+ pointFrom6(
5014
5034
  element.x + element.width / 2,
5015
5035
  element.y + element.height
5016
5036
  ),
@@ -5026,8 +5046,8 @@ var headingForPointFromDiamondElement = (element, aabb, point) => {
5026
5046
  const left = pointFromVector4(
5027
5047
  vectorScale4(
5028
5048
  vectorFromPoint4(
5029
- pointRotateRads5(
5030
- pointFrom5(element.x, element.y + element.height / 2),
5049
+ pointRotateRads6(
5050
+ pointFrom6(element.x, element.y + element.height / 2),
5031
5051
  midPoint,
5032
5052
  element.angle
5033
5053
  ),
@@ -5093,22 +5113,22 @@ var headingForPointFromElement = (element, aabb, p) => {
5093
5113
  return headingForPointFromDiamondElement(element, aabb, p);
5094
5114
  }
5095
5115
  const topLeft = pointScaleFromOrigin(
5096
- pointFrom5(aabb[0], aabb[1]),
5116
+ pointFrom6(aabb[0], aabb[1]),
5097
5117
  midPoint,
5098
5118
  SEARCH_CONE_MULTIPLIER
5099
5119
  );
5100
5120
  const topRight = pointScaleFromOrigin(
5101
- pointFrom5(aabb[2], aabb[1]),
5121
+ pointFrom6(aabb[2], aabb[1]),
5102
5122
  midPoint,
5103
5123
  SEARCH_CONE_MULTIPLIER
5104
5124
  );
5105
5125
  const bottomLeft = pointScaleFromOrigin(
5106
- pointFrom5(aabb[0], aabb[3]),
5126
+ pointFrom6(aabb[0], aabb[3]),
5107
5127
  midPoint,
5108
5128
  SEARCH_CONE_MULTIPLIER
5109
5129
  );
5110
5130
  const bottomRight = pointScaleFromOrigin(
5111
- pointFrom5(aabb[2], aabb[3]),
5131
+ pointFrom6(aabb[2], aabb[3]),
5112
5132
  midPoint,
5113
5133
  SEARCH_CONE_MULTIPLIER
5114
5134
  );
@@ -5141,7 +5161,7 @@ init_define_import_meta_env();
5141
5161
  import {
5142
5162
  clamp as clamp2,
5143
5163
  pointDistance as pointDistance3,
5144
- pointFrom as pointFrom6,
5164
+ pointFrom as pointFrom7,
5145
5165
  pointScaleFromOrigin as pointScaleFromOrigin2,
5146
5166
  pointsEqual as pointsEqual4,
5147
5167
  pointTranslate,
@@ -5165,7 +5185,7 @@ var handleSegmentRenormalization = (arrow, elementsMap) => {
5165
5185
  const nextFixedSegments = arrow.fixedSegments ? arrow.fixedSegments.slice() : null;
5166
5186
  if (nextFixedSegments) {
5167
5187
  const _nextPoints = [];
5168
- arrow.points.map((p) => pointFrom6(arrow.x + p[0], arrow.y + p[1])).forEach((p, i, points) => {
5188
+ arrow.points.map((p) => pointFrom7(arrow.x + p[0], arrow.y + p[1])).forEach((p, i, points) => {
5169
5189
  if (i < 2) {
5170
5190
  return _nextPoints.push(p);
5171
5191
  }
@@ -5183,7 +5203,7 @@ var handleSegmentRenormalization = (arrow, elementsMap) => {
5183
5203
  ) ?? -1;
5184
5204
  const segmentIdx = nextFixedSegments?.findIndex((segment) => segment.index === i) ?? -1;
5185
5205
  if (segmentIdx !== -1) {
5186
- nextFixedSegments[segmentIdx].start = pointFrom6(
5206
+ nextFixedSegments[segmentIdx].start = pointFrom7(
5187
5207
  points[i - 2][0] - arrow.x,
5188
5208
  points[i - 2][1] - arrow.y
5189
5209
  );
@@ -5225,7 +5245,7 @@ var handleSegmentRenormalization = (arrow, elementsMap) => {
5225
5245
  });
5226
5246
  const isHorizontal = headingForPointIsHorizontal(p, points[i - 1]);
5227
5247
  return nextPoints.push(
5228
- pointFrom6(
5248
+ pointFrom7(
5229
5249
  !isHorizontal ? points[i - 2][0] : p[0],
5230
5250
  isHorizontal ? points[i - 2][1] : p[1]
5231
5251
  )
@@ -5246,7 +5266,7 @@ var handleSegmentRenormalization = (arrow, elementsMap) => {
5246
5266
  arrow,
5247
5267
  elementsMap,
5248
5268
  nextPoints.map(
5249
- (p) => pointFrom6(p[0] - arrow.x, p[1] - arrow.y)
5269
+ (p) => pointFrom7(p[0] - arrow.x, p[1] - arrow.y)
5250
5270
  )
5251
5271
  )
5252
5272
  ) ?? []
@@ -5315,8 +5335,8 @@ var handleSegmentRelease = (arrow, fixedSegments, elementsMap) => {
5315
5335
  },
5316
5336
  elementsMap,
5317
5337
  [
5318
- pointFrom6(0, 0),
5319
- pointFrom6(
5338
+ pointFrom7(0, 0),
5339
+ pointFrom7(
5320
5340
  arrow.x + (nextSegment?.start[0] ?? arrow.points[arrow.points.length - 1][0]) - x,
5321
5341
  arrow.y + (nextSegment?.start[1] ?? arrow.points[arrow.points.length - 1][1]) - y
5322
5342
  )
@@ -5341,11 +5361,16 @@ var handleSegmentRelease = (arrow, fixedSegments, elementsMap) => {
5341
5361
  null,
5342
5362
  null
5343
5363
  );
5364
+ if (!restoredPoints || restoredPoints.length < 2) {
5365
+ throw new Error(
5366
+ "Property 'points' is required in the update returned by normalizeArrowElementUpdate()"
5367
+ );
5368
+ }
5344
5369
  const nextPoints = [];
5345
5370
  if (prevSegment) {
5346
5371
  for (let i = 0; i < prevSegment.index; i++) {
5347
5372
  nextPoints.push(
5348
- pointFrom6(
5373
+ pointFrom7(
5349
5374
  arrow.x + arrow.points[i][0],
5350
5375
  arrow.y + arrow.points[i][1]
5351
5376
  )
@@ -5354,7 +5379,7 @@ var handleSegmentRelease = (arrow, fixedSegments, elementsMap) => {
5354
5379
  }
5355
5380
  restoredPoints.forEach((p) => {
5356
5381
  nextPoints.push(
5357
- pointFrom6(
5382
+ pointFrom7(
5358
5383
  arrow.x + (prevSegment ? prevSegment.end[0] : 0) + p[0],
5359
5384
  arrow.y + (prevSegment ? prevSegment.end[1] : 0) + p[1]
5360
5385
  )
@@ -5363,7 +5388,7 @@ var handleSegmentRelease = (arrow, fixedSegments, elementsMap) => {
5363
5388
  if (nextSegment) {
5364
5389
  for (let i = nextSegment.index; i < arrow.points.length; i++) {
5365
5390
  nextPoints.push(
5366
- pointFrom6(
5391
+ pointFrom7(
5367
5392
  arrow.x + arrow.points[i][0],
5368
5393
  arrow.y + arrow.points[i][1]
5369
5394
  )
@@ -5434,7 +5459,7 @@ var handleSegmentMove = (arrow, fixedSegments, startHeading, endHeading, hovered
5434
5459
  const startIsHorizontal = headingIsHorizontal(startHeading);
5435
5460
  const startIsPositive = startIsHorizontal ? compareHeading(startHeading, HEADING_RIGHT) : compareHeading(startHeading, HEADING_DOWN);
5436
5461
  const padding = startIsPositive ? segmentIsTooShort ? segmentLength / 2 : BASE_PADDING : segmentIsTooShort ? -segmentLength / 2 : -BASE_PADDING;
5437
- fixedSegments[activelyModifiedSegmentIdx].start = pointFrom6(
5462
+ fixedSegments[activelyModifiedSegmentIdx].start = pointFrom7(
5438
5463
  fixedSegments[activelyModifiedSegmentIdx].start[0] + (startIsHorizontal ? padding : 0),
5439
5464
  fixedSegments[activelyModifiedSegmentIdx].start[1] + (!startIsHorizontal ? padding : 0)
5440
5465
  );
@@ -5443,24 +5468,24 @@ var handleSegmentMove = (arrow, fixedSegments, startHeading, endHeading, hovered
5443
5468
  const endIsHorizontal = headingIsHorizontal(endHeading);
5444
5469
  const endIsPositive = endIsHorizontal ? compareHeading(endHeading, HEADING_RIGHT) : compareHeading(endHeading, HEADING_DOWN);
5445
5470
  const padding = endIsPositive ? segmentIsTooShort ? segmentLength / 2 : BASE_PADDING : segmentIsTooShort ? -segmentLength / 2 : -BASE_PADDING;
5446
- fixedSegments[activelyModifiedSegmentIdx].end = pointFrom6(
5471
+ fixedSegments[activelyModifiedSegmentIdx].end = pointFrom7(
5447
5472
  fixedSegments[activelyModifiedSegmentIdx].end[0] + (endIsHorizontal ? padding : 0),
5448
5473
  fixedSegments[activelyModifiedSegmentIdx].end[1] + (!endIsHorizontal ? padding : 0)
5449
5474
  );
5450
5475
  }
5451
5476
  const nextFixedSegments = fixedSegments.map((segment) => ({
5452
5477
  ...segment,
5453
- start: pointFrom6(
5478
+ start: pointFrom7(
5454
5479
  arrow.x + segment.start[0],
5455
5480
  arrow.y + segment.start[1]
5456
5481
  ),
5457
- end: pointFrom6(
5482
+ end: pointFrom7(
5458
5483
  arrow.x + segment.end[0],
5459
5484
  arrow.y + segment.end[1]
5460
5485
  )
5461
5486
  }));
5462
5487
  const newPoints = arrow.points.map(
5463
- (p, i) => pointFrom6(arrow.x + p[0], arrow.y + p[1])
5488
+ (p, i) => pointFrom7(arrow.x + p[0], arrow.y + p[1])
5464
5489
  );
5465
5490
  const startIdx = nextFixedSegments[activelyModifiedSegmentIdx].index - 1;
5466
5491
  const endIdx = nextFixedSegments[activelyModifiedSegmentIdx].index;
@@ -5506,14 +5531,14 @@ var handleSegmentMove = (arrow, fixedSegments, startHeading, endHeading, hovered
5506
5531
  if (firstSegmentIdx === -1 && startIdx === 0) {
5507
5532
  const startIsHorizontal = hoveredStartElement ? headingIsHorizontal(startHeading) : headingForPointIsHorizontal(newPoints[1], newPoints[0]);
5508
5533
  newPoints.unshift(
5509
- pointFrom6(
5534
+ pointFrom7(
5510
5535
  startIsHorizontal ? start[0] : arrow.x + arrow.points[0][0],
5511
5536
  !startIsHorizontal ? start[1] : arrow.y + arrow.points[0][1]
5512
5537
  )
5513
5538
  );
5514
5539
  if (hoveredStartElement) {
5515
5540
  newPoints.unshift(
5516
- pointFrom6(
5541
+ pointFrom7(
5517
5542
  arrow.x + arrow.points[0][0],
5518
5543
  arrow.y + arrow.points[0][1]
5519
5544
  )
@@ -5526,14 +5551,14 @@ var handleSegmentMove = (arrow, fixedSegments, startHeading, endHeading, hovered
5526
5551
  if (lastSegmentIdx === -1 && endIdx === arrow.points.length - 1) {
5527
5552
  const endIsHorizontal = headingIsHorizontal(endHeading);
5528
5553
  newPoints.push(
5529
- pointFrom6(
5554
+ pointFrom7(
5530
5555
  endIsHorizontal ? end[0] : arrow.x + arrow.points[arrow.points.length - 1][0],
5531
5556
  !endIsHorizontal ? end[1] : arrow.y + arrow.points[arrow.points.length - 1][1]
5532
5557
  )
5533
5558
  );
5534
5559
  if (hoveredEndElement) {
5535
5560
  newPoints.push(
5536
- pointFrom6(
5561
+ pointFrom7(
5537
5562
  arrow.x + arrow.points[arrow.points.length - 1][0],
5538
5563
  arrow.y + arrow.points[arrow.points.length - 1][1]
5539
5564
  )
@@ -5544,11 +5569,11 @@ var handleSegmentMove = (arrow, fixedSegments, startHeading, endHeading, hovered
5544
5569
  newPoints,
5545
5570
  nextFixedSegments.map((segment) => ({
5546
5571
  ...segment,
5547
- start: pointFrom6(
5572
+ start: pointFrom7(
5548
5573
  segment.start[0] - arrow.x,
5549
5574
  segment.start[1] - arrow.y
5550
5575
  ),
5551
- end: pointFrom6(
5576
+ end: pointFrom7(
5552
5577
  segment.end[0] - arrow.x,
5553
5578
  segment.end[1] - arrow.y
5554
5579
  )
@@ -5563,18 +5588,18 @@ var handleEndpointDrag = (arrow, updatedPoints, fixedSegments, startHeading, end
5563
5588
  let startIsSpecial = arrow.startIsSpecial ?? null;
5564
5589
  let endIsSpecial = arrow.endIsSpecial ?? null;
5565
5590
  const globalUpdatedPoints = updatedPoints.map(
5566
- (p, i) => i === 0 ? pointFrom6(arrow.x + p[0], arrow.y + p[1]) : i === updatedPoints.length - 1 ? pointFrom6(arrow.x + p[0], arrow.y + p[1]) : pointFrom6(
5591
+ (p, i) => i === 0 ? pointFrom7(arrow.x + p[0], arrow.y + p[1]) : i === updatedPoints.length - 1 ? pointFrom7(arrow.x + p[0], arrow.y + p[1]) : pointFrom7(
5567
5592
  arrow.x + arrow.points[i][0],
5568
5593
  arrow.y + arrow.points[i][1]
5569
5594
  )
5570
5595
  );
5571
5596
  const nextFixedSegments = fixedSegments.map((segment) => ({
5572
5597
  ...segment,
5573
- start: pointFrom6(
5598
+ start: pointFrom7(
5574
5599
  arrow.x + (segment.start[0] - updatedPoints[0][0]),
5575
5600
  arrow.y + (segment.start[1] - updatedPoints[0][1])
5576
5601
  ),
5577
- end: pointFrom6(
5602
+ end: pointFrom7(
5578
5603
  arrow.x + (segment.end[0] - updatedPoints[0][0]),
5579
5604
  arrow.y + (segment.end[1] - updatedPoints[0][1])
5580
5605
  )
@@ -5586,8 +5611,13 @@ var handleEndpointDrag = (arrow, updatedPoints, fixedSegments, startHeading, end
5586
5611
  newPoints.push(globalUpdatedPoints[newPoints.length + offset]);
5587
5612
  }
5588
5613
  {
5589
- const secondPoint = globalUpdatedPoints[startIsSpecial ? 2 : 1];
5590
- const thirdPoint = globalUpdatedPoints[startIsSpecial ? 3 : 2];
5614
+ const secondPoint = globalUpdatedPoints.at(startIsSpecial ? 2 : 1);
5615
+ const thirdPoint = globalUpdatedPoints.at(startIsSpecial ? 3 : 2);
5616
+ if (!secondPoint || !thirdPoint) {
5617
+ throw new Error(
5618
+ `Second and third points must exist when handling endpoint drag (${startIsSpecial})`
5619
+ );
5620
+ }
5591
5621
  const startIsHorizontal = headingIsHorizontal(startHeading);
5592
5622
  const secondIsHorizontal = headingIsHorizontal(
5593
5623
  vectorToHeading(vectorFromPoint5(secondPoint, thirdPoint))
@@ -5595,13 +5625,13 @@ var handleEndpointDrag = (arrow, updatedPoints, fixedSegments, startHeading, end
5595
5625
  if (hoveredStartElement && startIsHorizontal === secondIsHorizontal) {
5596
5626
  const positive = startIsHorizontal ? compareHeading(startHeading, HEADING_RIGHT) : compareHeading(startHeading, HEADING_DOWN);
5597
5627
  newPoints.unshift(
5598
- pointFrom6(
5628
+ pointFrom7(
5599
5629
  !secondIsHorizontal ? thirdPoint[0] : startGlobalPoint[0] + (positive ? BASE_PADDING : -BASE_PADDING),
5600
5630
  secondIsHorizontal ? thirdPoint[1] : startGlobalPoint[1] + (positive ? BASE_PADDING : -BASE_PADDING)
5601
5631
  )
5602
5632
  );
5603
5633
  newPoints.unshift(
5604
- pointFrom6(
5634
+ pointFrom7(
5605
5635
  startIsHorizontal ? startGlobalPoint[0] + (positive ? BASE_PADDING : -BASE_PADDING) : startGlobalPoint[0],
5606
5636
  !startIsHorizontal ? startGlobalPoint[1] + (positive ? BASE_PADDING : -BASE_PADDING) : startGlobalPoint[1]
5607
5637
  )
@@ -5616,7 +5646,7 @@ var handleEndpointDrag = (arrow, updatedPoints, fixedSegments, startHeading, end
5616
5646
  }
5617
5647
  } else {
5618
5648
  newPoints.unshift(
5619
- pointFrom6(
5649
+ pointFrom7(
5620
5650
  !secondIsHorizontal ? secondPoint[0] : startGlobalPoint[0],
5621
5651
  secondIsHorizontal ? secondPoint[1] : startGlobalPoint[1]
5622
5652
  )
@@ -5633,8 +5663,17 @@ var handleEndpointDrag = (arrow, updatedPoints, fixedSegments, startHeading, end
5633
5663
  newPoints.unshift(startGlobalPoint);
5634
5664
  }
5635
5665
  {
5636
- const secondToLastPoint = globalUpdatedPoints[globalUpdatedPoints.length - (endIsSpecial ? 3 : 2)];
5637
- const thirdToLastPoint = globalUpdatedPoints[globalUpdatedPoints.length - (endIsSpecial ? 4 : 3)];
5666
+ const secondToLastPoint = globalUpdatedPoints.at(
5667
+ globalUpdatedPoints.length - (endIsSpecial ? 3 : 2)
5668
+ );
5669
+ const thirdToLastPoint = globalUpdatedPoints.at(
5670
+ globalUpdatedPoints.length - (endIsSpecial ? 4 : 3)
5671
+ );
5672
+ if (!secondToLastPoint || !thirdToLastPoint) {
5673
+ throw new Error(
5674
+ `Second and third to last points must exist when handling endpoint drag (${endIsSpecial})`
5675
+ );
5676
+ }
5638
5677
  const endIsHorizontal = headingIsHorizontal(endHeading);
5639
5678
  const secondIsHorizontal = headingForPointIsHorizontal(
5640
5679
  thirdToLastPoint,
@@ -5643,13 +5682,13 @@ var handleEndpointDrag = (arrow, updatedPoints, fixedSegments, startHeading, end
5643
5682
  if (hoveredEndElement && endIsHorizontal === secondIsHorizontal) {
5644
5683
  const positive = endIsHorizontal ? compareHeading(endHeading, HEADING_RIGHT) : compareHeading(endHeading, HEADING_DOWN);
5645
5684
  newPoints.push(
5646
- pointFrom6(
5685
+ pointFrom7(
5647
5686
  !secondIsHorizontal ? thirdToLastPoint[0] : endGlobalPoint[0] + (positive ? BASE_PADDING : -BASE_PADDING),
5648
5687
  secondIsHorizontal ? thirdToLastPoint[1] : endGlobalPoint[1] + (positive ? BASE_PADDING : -BASE_PADDING)
5649
5688
  )
5650
5689
  );
5651
5690
  newPoints.push(
5652
- pointFrom6(
5691
+ pointFrom7(
5653
5692
  endIsHorizontal ? endGlobalPoint[0] + (positive ? BASE_PADDING : -BASE_PADDING) : endGlobalPoint[0],
5654
5693
  !endIsHorizontal ? endGlobalPoint[1] + (positive ? BASE_PADDING : -BASE_PADDING) : endGlobalPoint[1]
5655
5694
  )
@@ -5659,7 +5698,7 @@ var handleEndpointDrag = (arrow, updatedPoints, fixedSegments, startHeading, end
5659
5698
  }
5660
5699
  } else {
5661
5700
  newPoints.push(
5662
- pointFrom6(
5701
+ pointFrom7(
5663
5702
  !secondIsHorizontal ? secondToLastPoint[0] : endGlobalPoint[0],
5664
5703
  secondIsHorizontal ? secondToLastPoint[1] : endGlobalPoint[1]
5665
5704
  )
@@ -5678,11 +5717,11 @@ var handleEndpointDrag = (arrow, updatedPoints, fixedSegments, startHeading, end
5678
5717
  end: newPoints[index]
5679
5718
  })).map((segment) => ({
5680
5719
  ...segment,
5681
- start: pointFrom6(
5720
+ start: pointFrom7(
5682
5721
  segment.start[0] - startGlobalPoint[0],
5683
5722
  segment.start[1] - startGlobalPoint[1]
5684
5723
  ),
5685
- end: pointFrom6(
5724
+ end: pointFrom7(
5686
5725
  segment.end[0] - startGlobalPoint[0],
5687
5726
  segment.end[1] - startGlobalPoint[1]
5688
5727
  )
@@ -5744,7 +5783,7 @@ var updateElbowArrowPoints = (arrow, elementsMap, updates, options) => {
5744
5783
  if (startBinding && !startElement && areUpdatedPointsValid || endBinding && !endElement && areUpdatedPointsValid || elementsMap.size === 0 && areUpdatedPointsValid || Object.keys(restOfTheUpdates).length === 0 && (startElement?.id !== startBinding?.elementId || endElement?.id !== endBinding?.elementId)) {
5745
5784
  return normalizeArrowElementUpdate(
5746
5785
  updatedPoints.map(
5747
- (p) => pointFrom6(arrow.x + p[0], arrow.y + p[1])
5786
+ (p) => pointFrom7(arrow.x + p[0], arrow.y + p[1])
5748
5787
  ),
5749
5788
  arrow.fixedSegments,
5750
5789
  arrow.startIsSpecial,
@@ -5776,7 +5815,7 @@ var updateElbowArrowPoints = (arrow, elementsMap, updates, options) => {
5776
5815
  if (elementsMap.size === 0 && areUpdatedPointsValid) {
5777
5816
  return normalizeArrowElementUpdate(
5778
5817
  updatedPoints.map(
5779
- (p) => pointFrom6(arrow.x + p[0], arrow.y + p[1])
5818
+ (p) => pointFrom7(arrow.x + p[0], arrow.y + p[1])
5780
5819
  ),
5781
5820
  arrow.fixedSegments,
5782
5821
  arrow.startIsSpecial,
@@ -5789,7 +5828,7 @@ var updateElbowArrowPoints = (arrow, elementsMap, updates, options) => {
5789
5828
  if (updates.startBinding === arrow.startBinding && updates.endBinding === arrow.endBinding && (updates.points ?? []).every(
5790
5829
  (p, i) => pointsEqual4(
5791
5830
  p,
5792
- arrow.points[i] ?? pointFrom6(Infinity, Infinity)
5831
+ arrow.points[i] ?? pointFrom7(Infinity, Infinity)
5793
5832
  )
5794
5833
  ) && areUpdatedPointsValid) {
5795
5834
  return {};
@@ -6283,13 +6322,13 @@ var calculateGrid = (aabbs, start, startHeading, end, endHeading, common) => {
6283
6322
  var getDonglePosition = (bounds, heading, p) => {
6284
6323
  switch (heading) {
6285
6324
  case HEADING_UP:
6286
- return pointFrom6(p[0], bounds[1]);
6325
+ return pointFrom7(p[0], bounds[1]);
6287
6326
  case HEADING_RIGHT:
6288
- return pointFrom6(bounds[2], p[1]);
6327
+ return pointFrom7(bounds[2], p[1]);
6289
6328
  case HEADING_DOWN:
6290
- return pointFrom6(p[0], bounds[3]);
6329
+ return pointFrom7(p[0], bounds[3]);
6291
6330
  }
6292
- return pointFrom6(bounds[0], p[1]);
6331
+ return pointFrom7(bounds[0], p[1]);
6293
6332
  };
6294
6333
  var estimateSegmentCount = (start, end, startHeading, endHeading) => {
6295
6334
  if (endHeading === HEADING_RIGHT) {
@@ -6457,7 +6496,7 @@ var normalizeArrowElementUpdate = (global2, nextFixedSegments, startIsSpecial, e
6457
6496
  );
6458
6497
  }
6459
6498
  points = points.map(
6460
- ([x, y]) => pointFrom6(clamp2(x, -1e6, 1e6), clamp2(y, -1e6, 1e6))
6499
+ ([x, y]) => pointFrom7(clamp2(x, -1e6, 1e6), clamp2(y, -1e6, 1e6))
6461
6500
  );
6462
6501
  return {
6463
6502
  points,
@@ -7195,7 +7234,7 @@ var bindPointToSnapToElementOutline = (arrow, bindableElement, startOrEnd, eleme
7195
7234
  }
7196
7235
  const aabb = aabbForElement(bindableElement, elementsMap);
7197
7236
  const localP = arrow.points[startOrEnd === "start" ? 0 : arrow.points.length - 1];
7198
- const globalP = pointFrom7(
7237
+ const globalP = pointFrom8(
7199
7238
  arrow.x + localP[0],
7200
7239
  arrow.y + localP[1]
7201
7240
  );
@@ -7203,8 +7242,8 @@ var bindPointToSnapToElementOutline = (arrow, bindableElement, startOrEnd, eleme
7203
7242
  const elbowed = isElbowArrow(arrow);
7204
7243
  const center = getCenterForBounds(aabb);
7205
7244
  const adjacentPointIdx = startOrEnd === "start" ? 1 : arrow.points.length - 2;
7206
- const adjacentPoint = pointRotateRads6(
7207
- pointFrom7(
7245
+ const adjacentPoint = pointRotateRads7(
7246
+ pointFrom8(
7208
7247
  arrow.x + arrow.points[adjacentPointIdx][0],
7209
7248
  arrow.y + arrow.points[adjacentPointIdx][1]
7210
7249
  ),
@@ -7217,7 +7256,7 @@ var bindPointToSnapToElementOutline = (arrow, bindableElement, startOrEnd, eleme
7217
7256
  headingForPointFromElement(bindableElement, aabb, globalP)
7218
7257
  );
7219
7258
  const snapPoint = snapToMid(bindableElement, elementsMap, edgePoint);
7220
- const otherPoint = pointFrom7(
7259
+ const otherPoint = pointFrom8(
7221
7260
  isHorizontal ? center[0] : snapPoint[0],
7222
7261
  !isHorizontal ? center[1] : snapPoint[1]
7223
7262
  );
@@ -7237,6 +7276,28 @@ var bindPointToSnapToElementOutline = (arrow, bindableElement, startOrEnd, eleme
7237
7276
  intersector,
7238
7277
  FIXED_BINDING_DISTANCE
7239
7278
  ).sort(pointDistanceSq)[0];
7279
+ if (!intersection) {
7280
+ const anotherPoint = pointFrom8(
7281
+ !isHorizontal ? center[0] : snapPoint[0],
7282
+ isHorizontal ? center[1] : snapPoint[1]
7283
+ );
7284
+ const anotherIntersector = lineSegment4(
7285
+ anotherPoint,
7286
+ pointFromVector5(
7287
+ vectorScale6(
7288
+ vectorNormalize3(vectorFromPoint6(snapPoint, anotherPoint)),
7289
+ Math.max(bindableElement.width, bindableElement.height) * 2
7290
+ ),
7291
+ anotherPoint
7292
+ )
7293
+ );
7294
+ intersection = intersectElementWithLineSegment(
7295
+ bindableElement,
7296
+ elementsMap,
7297
+ anotherIntersector,
7298
+ FIXED_BINDING_DISTANCE
7299
+ ).sort(pointDistanceSq)[0];
7300
+ }
7240
7301
  } else {
7241
7302
  intersection = intersectElementWithLineSegment(
7242
7303
  bindableElement,
@@ -7264,24 +7325,24 @@ var bindPointToSnapToElementOutline = (arrow, bindableElement, startOrEnd, eleme
7264
7325
  };
7265
7326
  var avoidRectangularCorner = (element, elementsMap, p) => {
7266
7327
  const center = elementCenterPoint(element, elementsMap);
7267
- const nonRotatedPoint = pointRotateRads6(p, center, -element.angle);
7328
+ const nonRotatedPoint = pointRotateRads7(p, center, -element.angle);
7268
7329
  if (nonRotatedPoint[0] < element.x && nonRotatedPoint[1] < element.y) {
7269
7330
  if (nonRotatedPoint[1] - element.y > -FIXED_BINDING_DISTANCE) {
7270
- return pointRotateRads6(
7271
- pointFrom7(element.x - FIXED_BINDING_DISTANCE, element.y),
7331
+ return pointRotateRads7(
7332
+ pointFrom8(element.x - FIXED_BINDING_DISTANCE, element.y),
7272
7333
  center,
7273
7334
  element.angle
7274
7335
  );
7275
7336
  }
7276
- return pointRotateRads6(
7277
- pointFrom7(element.x, element.y - FIXED_BINDING_DISTANCE),
7337
+ return pointRotateRads7(
7338
+ pointFrom8(element.x, element.y - FIXED_BINDING_DISTANCE),
7278
7339
  center,
7279
7340
  element.angle
7280
7341
  );
7281
7342
  } else if (nonRotatedPoint[0] < element.x && nonRotatedPoint[1] > element.y + element.height) {
7282
7343
  if (nonRotatedPoint[0] - element.x > -FIXED_BINDING_DISTANCE) {
7283
- return pointRotateRads6(
7284
- pointFrom7(
7344
+ return pointRotateRads7(
7345
+ pointFrom8(
7285
7346
  element.x,
7286
7347
  element.y + element.height + FIXED_BINDING_DISTANCE
7287
7348
  ),
@@ -7289,15 +7350,15 @@ var avoidRectangularCorner = (element, elementsMap, p) => {
7289
7350
  element.angle
7290
7351
  );
7291
7352
  }
7292
- return pointRotateRads6(
7293
- pointFrom7(element.x - FIXED_BINDING_DISTANCE, element.y + element.height),
7353
+ return pointRotateRads7(
7354
+ pointFrom8(element.x - FIXED_BINDING_DISTANCE, element.y + element.height),
7294
7355
  center,
7295
7356
  element.angle
7296
7357
  );
7297
7358
  } else if (nonRotatedPoint[0] > element.x + element.width && nonRotatedPoint[1] > element.y + element.height) {
7298
7359
  if (nonRotatedPoint[0] - element.x < element.width + FIXED_BINDING_DISTANCE) {
7299
- return pointRotateRads6(
7300
- pointFrom7(
7360
+ return pointRotateRads7(
7361
+ pointFrom8(
7301
7362
  element.x + element.width,
7302
7363
  element.y + element.height + FIXED_BINDING_DISTANCE
7303
7364
  ),
@@ -7305,8 +7366,8 @@ var avoidRectangularCorner = (element, elementsMap, p) => {
7305
7366
  element.angle
7306
7367
  );
7307
7368
  }
7308
- return pointRotateRads6(
7309
- pointFrom7(
7369
+ return pointRotateRads7(
7370
+ pointFrom8(
7310
7371
  element.x + element.width + FIXED_BINDING_DISTANCE,
7311
7372
  element.y + element.height
7312
7373
  ),
@@ -7315,8 +7376,8 @@ var avoidRectangularCorner = (element, elementsMap, p) => {
7315
7376
  );
7316
7377
  } else if (nonRotatedPoint[0] > element.x + element.width && nonRotatedPoint[1] < element.y) {
7317
7378
  if (nonRotatedPoint[0] - element.x < element.width + FIXED_BINDING_DISTANCE) {
7318
- return pointRotateRads6(
7319
- pointFrom7(
7379
+ return pointRotateRads7(
7380
+ pointFrom8(
7320
7381
  element.x + element.width,
7321
7382
  element.y - FIXED_BINDING_DISTANCE
7322
7383
  ),
@@ -7324,8 +7385,8 @@ var avoidRectangularCorner = (element, elementsMap, p) => {
7324
7385
  element.angle
7325
7386
  );
7326
7387
  }
7327
- return pointRotateRads6(
7328
- pointFrom7(element.x + element.width + FIXED_BINDING_DISTANCE, element.y),
7388
+ return pointRotateRads7(
7389
+ pointFrom8(element.x + element.width + FIXED_BINDING_DISTANCE, element.y),
7329
7390
  center,
7330
7391
  element.angle
7331
7392
  );
@@ -7335,62 +7396,62 @@ var avoidRectangularCorner = (element, elementsMap, p) => {
7335
7396
  var snapToMid = (element, elementsMap, p, tolerance = 0.05) => {
7336
7397
  const { x, y, width, height, angle } = element;
7337
7398
  const center = elementCenterPoint(element, elementsMap, -0.1, -0.1);
7338
- const nonRotated = pointRotateRads6(p, center, -angle);
7399
+ const nonRotated = pointRotateRads7(p, center, -angle);
7339
7400
  const verticalThreshold = clamp3(tolerance * height, 5, 80);
7340
7401
  const horizontalThreshold = clamp3(tolerance * width, 5, 80);
7341
7402
  if (nonRotated[0] <= x + width / 2 && nonRotated[1] > center[1] - verticalThreshold && nonRotated[1] < center[1] + verticalThreshold) {
7342
- return pointRotateRads6(
7343
- pointFrom7(x - FIXED_BINDING_DISTANCE, center[1]),
7403
+ return pointRotateRads7(
7404
+ pointFrom8(x - FIXED_BINDING_DISTANCE, center[1]),
7344
7405
  center,
7345
7406
  angle
7346
7407
  );
7347
7408
  } else if (nonRotated[1] <= y + height / 2 && nonRotated[0] > center[0] - horizontalThreshold && nonRotated[0] < center[0] + horizontalThreshold) {
7348
- return pointRotateRads6(
7349
- pointFrom7(center[0], y - FIXED_BINDING_DISTANCE),
7409
+ return pointRotateRads7(
7410
+ pointFrom8(center[0], y - FIXED_BINDING_DISTANCE),
7350
7411
  center,
7351
7412
  angle
7352
7413
  );
7353
7414
  } else if (nonRotated[0] >= x + width / 2 && nonRotated[1] > center[1] - verticalThreshold && nonRotated[1] < center[1] + verticalThreshold) {
7354
- return pointRotateRads6(
7355
- pointFrom7(x + width + FIXED_BINDING_DISTANCE, center[1]),
7415
+ return pointRotateRads7(
7416
+ pointFrom8(x + width + FIXED_BINDING_DISTANCE, center[1]),
7356
7417
  center,
7357
7418
  angle
7358
7419
  );
7359
7420
  } else if (nonRotated[1] >= y + height / 2 && nonRotated[0] > center[0] - horizontalThreshold && nonRotated[0] < center[0] + horizontalThreshold) {
7360
- return pointRotateRads6(
7361
- pointFrom7(center[0], y + height + FIXED_BINDING_DISTANCE),
7421
+ return pointRotateRads7(
7422
+ pointFrom8(center[0], y + height + FIXED_BINDING_DISTANCE),
7362
7423
  center,
7363
7424
  angle
7364
7425
  );
7365
7426
  } else if (element.type === "diamond") {
7366
7427
  const distance3 = FIXED_BINDING_DISTANCE;
7367
- const topLeft = pointFrom7(
7428
+ const topLeft = pointFrom8(
7368
7429
  x + width / 4 - distance3,
7369
7430
  y + height / 4 - distance3
7370
7431
  );
7371
- const topRight = pointFrom7(
7432
+ const topRight = pointFrom8(
7372
7433
  x + 3 * width / 4 + distance3,
7373
7434
  y + height / 4 - distance3
7374
7435
  );
7375
- const bottomLeft = pointFrom7(
7436
+ const bottomLeft = pointFrom8(
7376
7437
  x + width / 4 - distance3,
7377
7438
  y + 3 * height / 4 + distance3
7378
7439
  );
7379
- const bottomRight = pointFrom7(
7440
+ const bottomRight = pointFrom8(
7380
7441
  x + 3 * width / 4 + distance3,
7381
7442
  y + 3 * height / 4 + distance3
7382
7443
  );
7383
7444
  if (pointDistance4(topLeft, nonRotated) < Math.max(horizontalThreshold, verticalThreshold)) {
7384
- return pointRotateRads6(topLeft, center, angle);
7445
+ return pointRotateRads7(topLeft, center, angle);
7385
7446
  }
7386
7447
  if (pointDistance4(topRight, nonRotated) < Math.max(horizontalThreshold, verticalThreshold)) {
7387
- return pointRotateRads6(topRight, center, angle);
7448
+ return pointRotateRads7(topRight, center, angle);
7388
7449
  }
7389
7450
  if (pointDistance4(bottomLeft, nonRotated) < Math.max(horizontalThreshold, verticalThreshold)) {
7390
- return pointRotateRads6(bottomLeft, center, angle);
7451
+ return pointRotateRads7(bottomLeft, center, angle);
7391
7452
  }
7392
7453
  if (pointDistance4(bottomRight, nonRotated) < Math.max(horizontalThreshold, verticalThreshold)) {
7393
- return pointRotateRads6(bottomRight, center, angle);
7454
+ return pointRotateRads7(bottomRight, center, angle);
7394
7455
  }
7395
7456
  }
7396
7457
  return p;
@@ -7410,11 +7471,11 @@ var updateBoundPoint = (linearElement, startOrEnd, binding, bindableElement, ele
7410
7471
  elementsMap
7411
7472
  ).fixedPoint;
7412
7473
  const globalMidPoint = elementCenterPoint(bindableElement, elementsMap);
7413
- const global2 = pointFrom7(
7474
+ const global2 = pointFrom8(
7414
7475
  bindableElement.x + fixedPoint[0] * bindableElement.width,
7415
7476
  bindableElement.y + fixedPoint[1] * bindableElement.height
7416
7477
  );
7417
- const rotatedGlobal = pointRotateRads6(
7478
+ const rotatedGlobal = pointRotateRads7(
7418
7479
  global2,
7419
7480
  globalMidPoint,
7420
7481
  bindableElement.angle
@@ -7504,11 +7565,11 @@ var calculateFixedPointForElbowArrowBinding = (linearElement, hoveredElement, st
7504
7565
  startOrEnd,
7505
7566
  elementsMap
7506
7567
  );
7507
- const globalMidPoint = pointFrom7(
7568
+ const globalMidPoint = pointFrom8(
7508
7569
  bounds[0] + (bounds[2] - bounds[0]) / 2,
7509
7570
  bounds[1] + (bounds[3] - bounds[1]) / 2
7510
7571
  );
7511
- const nonRotatedSnappedGlobalPoint = pointRotateRads6(
7572
+ const nonRotatedSnappedGlobalPoint = pointRotateRads7(
7512
7573
  snappedPoint,
7513
7574
  globalMidPoint,
7514
7575
  -hoveredElement.angle
@@ -7641,7 +7702,7 @@ var newBoundElements = (boundElements, idsToRemove, elementsToAdd = []) => {
7641
7702
  return nextBoundElements;
7642
7703
  };
7643
7704
  var bindingBorderTest = (element, { x, y }, elementsMap, zoom, fullShape) => {
7644
- const p = pointFrom7(x, y);
7705
+ const p = pointFrom8(x, y);
7645
7706
  const threshold = maxBindingGap(element, element.width, element.height, zoom);
7646
7707
  const shouldTestInside2 = (
7647
7708
  // disable fullshape snapping for frame elements so we
@@ -7683,8 +7744,8 @@ var determineFocusDistance = (element, elementsMap, a2, b2) => {
7683
7744
  if (pointsEqual5(a2, b2)) {
7684
7745
  return 0;
7685
7746
  }
7686
- const rotatedA = pointRotateRads6(a2, center, -element.angle);
7687
- const rotatedB = pointRotateRads6(b2, center, -element.angle);
7747
+ const rotatedA = pointRotateRads7(a2, center, -element.angle);
7748
+ const rotatedB = pointRotateRads7(b2, center, -element.angle);
7688
7749
  const sign = Math.sign(
7689
7750
  vectorCross3(
7690
7751
  vectorFromPoint6(rotatedB, a2),
@@ -7703,70 +7764,70 @@ var determineFocusDistance = (element, elementsMap, a2, b2) => {
7703
7764
  );
7704
7765
  const axes = element.type === "diamond" ? [
7705
7766
  lineSegment4(
7706
- pointFrom7(element.x + element.width / 2, element.y),
7707
- pointFrom7(
7767
+ pointFrom8(element.x + element.width / 2, element.y),
7768
+ pointFrom8(
7708
7769
  element.x + element.width / 2,
7709
7770
  element.y + element.height
7710
7771
  )
7711
7772
  ),
7712
7773
  lineSegment4(
7713
- pointFrom7(element.x, element.y + element.height / 2),
7714
- pointFrom7(
7774
+ pointFrom8(element.x, element.y + element.height / 2),
7775
+ pointFrom8(
7715
7776
  element.x + element.width,
7716
7777
  element.y + element.height / 2
7717
7778
  )
7718
7779
  )
7719
7780
  ] : [
7720
7781
  lineSegment4(
7721
- pointFrom7(element.x, element.y),
7722
- pointFrom7(
7782
+ pointFrom8(element.x, element.y),
7783
+ pointFrom8(
7723
7784
  element.x + element.width,
7724
7785
  element.y + element.height
7725
7786
  )
7726
7787
  ),
7727
7788
  lineSegment4(
7728
- pointFrom7(element.x + element.width, element.y),
7729
- pointFrom7(element.x, element.y + element.height)
7789
+ pointFrom8(element.x + element.width, element.y),
7790
+ pointFrom8(element.x, element.y + element.height)
7730
7791
  )
7731
7792
  ];
7732
7793
  const interceptees = element.type === "diamond" ? [
7733
7794
  lineSegment4(
7734
- pointFrom7(
7795
+ pointFrom8(
7735
7796
  element.x + element.width / 2,
7736
7797
  element.y - element.height
7737
7798
  ),
7738
- pointFrom7(
7799
+ pointFrom8(
7739
7800
  element.x + element.width / 2,
7740
7801
  element.y + element.height * 2
7741
7802
  )
7742
7803
  ),
7743
7804
  lineSegment4(
7744
- pointFrom7(
7805
+ pointFrom8(
7745
7806
  element.x - element.width,
7746
7807
  element.y + element.height / 2
7747
7808
  ),
7748
- pointFrom7(
7809
+ pointFrom8(
7749
7810
  element.x + element.width * 2,
7750
7811
  element.y + element.height / 2
7751
7812
  )
7752
7813
  )
7753
7814
  ] : [
7754
7815
  lineSegment4(
7755
- pointFrom7(
7816
+ pointFrom8(
7756
7817
  element.x - element.width,
7757
7818
  element.y - element.height
7758
7819
  ),
7759
- pointFrom7(
7820
+ pointFrom8(
7760
7821
  element.x + element.width * 2,
7761
7822
  element.y + element.height * 2
7762
7823
  )
7763
7824
  ),
7764
7825
  lineSegment4(
7765
- pointFrom7(
7826
+ pointFrom8(
7766
7827
  element.x + element.width * 2,
7767
7828
  element.y - element.height
7768
7829
  ),
7769
- pointFrom7(
7830
+ pointFrom8(
7770
7831
  element.x - element.width,
7771
7832
  element.y + element.height * 2
7772
7833
  )
@@ -7787,30 +7848,30 @@ var determineFocusPoint = (element, elementsMap, focus, adjacentPoint) => {
7787
7848
  return center;
7788
7849
  }
7789
7850
  const candidates = (element.type === "diamond" ? [
7790
- pointFrom7(element.x, element.y + element.height / 2),
7791
- pointFrom7(element.x + element.width / 2, element.y),
7792
- pointFrom7(
7851
+ pointFrom8(element.x, element.y + element.height / 2),
7852
+ pointFrom8(element.x + element.width / 2, element.y),
7853
+ pointFrom8(
7793
7854
  element.x + element.width,
7794
7855
  element.y + element.height / 2
7795
7856
  ),
7796
- pointFrom7(
7857
+ pointFrom8(
7797
7858
  element.x + element.width / 2,
7798
7859
  element.y + element.height
7799
7860
  )
7800
7861
  ] : [
7801
- pointFrom7(element.x, element.y),
7802
- pointFrom7(element.x + element.width, element.y),
7803
- pointFrom7(
7862
+ pointFrom8(element.x, element.y),
7863
+ pointFrom8(element.x + element.width, element.y),
7864
+ pointFrom8(
7804
7865
  element.x + element.width,
7805
7866
  element.y + element.height
7806
7867
  ),
7807
- pointFrom7(element.x, element.y + element.height)
7868
+ pointFrom8(element.x, element.y + element.height)
7808
7869
  ]).map(
7809
7870
  (p) => pointFromVector5(
7810
7871
  vectorScale6(vectorFromPoint6(p, center), Math.abs(focus)),
7811
7872
  center
7812
7873
  )
7813
- ).map((p) => pointRotateRads6(p, center, element.angle));
7874
+ ).map((p) => pointRotateRads7(p, center, element.angle));
7814
7875
  const selected = [
7815
7876
  vectorCross3(
7816
7877
  vectorFromPoint6(adjacentPoint, candidates[0]),
@@ -8055,8 +8116,8 @@ var BindableElement = class {
8055
8116
  };
8056
8117
  var getGlobalFixedPointForBindableElement = (fixedPointRatio, element, elementsMap) => {
8057
8118
  const [fixedX, fixedY] = normalizeFixedPoint(fixedPointRatio);
8058
- return pointRotateRads6(
8059
- pointFrom7(
8119
+ return pointRotateRads7(
8120
+ pointFrom8(
8060
8121
  element.x + element.width * fixedX,
8061
8122
  element.y + element.height * fixedY
8062
8123
  ),
@@ -8071,7 +8132,7 @@ var getGlobalFixedPoints = (arrow, elementsMap) => {
8071
8132
  arrow.startBinding.fixedPoint,
8072
8133
  startElement,
8073
8134
  elementsMap
8074
- ) : pointFrom7(
8135
+ ) : pointFrom8(
8075
8136
  arrow.x + arrow.points[0][0],
8076
8137
  arrow.y + arrow.points[0][1]
8077
8138
  );
@@ -8079,7 +8140,7 @@ var getGlobalFixedPoints = (arrow, elementsMap) => {
8079
8140
  arrow.endBinding.fixedPoint,
8080
8141
  endElement,
8081
8142
  elementsMap
8082
- ) : pointFrom7(
8143
+ ) : pointFrom8(
8083
8144
  arrow.x + arrow.points[arrow.points.length - 1][0],
8084
8145
  arrow.y + arrow.points[arrow.points.length - 1][1]
8085
8146
  );
@@ -8109,7 +8170,7 @@ var getNormalizedPoints = ({
8109
8170
  const offsetY = points[0][1];
8110
8171
  return {
8111
8172
  points: points.map((p) => {
8112
- return pointFrom8(p[0] - offsetX, p[1] - offsetY);
8173
+ return pointFrom9(p[0] - offsetX, p[1] - offsetY);
8113
8174
  }),
8114
8175
  offsetX,
8115
8176
  offsetY
@@ -8130,9 +8191,10 @@ var LinearElementEditor = class _LinearElementEditor {
8130
8191
  segmentMidPointHoveredCoords;
8131
8192
  elbowed;
8132
8193
  customLineAngle;
8133
- constructor(element, elementsMap) {
8194
+ isEditing;
8195
+ constructor(element, elementsMap, isEditing = false) {
8134
8196
  this.elementId = element.id;
8135
- if (!pointsEqual6(element.points[0], pointFrom8(0, 0))) {
8197
+ if (!pointsEqual6(element.points[0], pointFrom9(0, 0))) {
8136
8198
  console.error("Linear element is not normalized", Error().stack);
8137
8199
  mutateElement(
8138
8200
  element,
@@ -8161,6 +8223,7 @@ var LinearElementEditor = class _LinearElementEditor {
8161
8223
  this.segmentMidPointHoveredCoords = null;
8162
8224
  this.elbowed = isElbowArrow(element) && element.elbowed;
8163
8225
  this.customLineAngle = null;
8226
+ this.isEditing = isEditing;
8164
8227
  }
8165
8228
  // ---------------------------------------------------------------------------
8166
8229
  // static methods
@@ -8178,11 +8241,11 @@ var LinearElementEditor = class _LinearElementEditor {
8178
8241
  return null;
8179
8242
  }
8180
8243
  static handleBoxSelection(event, appState, setState, elementsMap) {
8181
- if (!appState.editingLinearElement || !appState.selectionElement) {
8244
+ if (!appState.selectedLinearElement?.isEditing || !appState.selectionElement) {
8182
8245
  return false;
8183
8246
  }
8184
- const { editingLinearElement } = appState;
8185
- const { selectedPointsIndices, elementId } = editingLinearElement;
8247
+ const { selectedLinearElement } = appState;
8248
+ const { selectedPointsIndices, elementId } = selectedLinearElement;
8186
8249
  const element = _LinearElementEditor.getElement(elementId, elementsMap);
8187
8250
  if (!element) {
8188
8251
  return false;
@@ -8204,8 +8267,8 @@ var LinearElementEditor = class _LinearElementEditor {
8204
8267
  return true;
8205
8268
  });
8206
8269
  setState({
8207
- editingLinearElement: {
8208
- ...editingLinearElement,
8270
+ selectedLinearElement: {
8271
+ ...selectedLinearElement,
8209
8272
  selectedPointsIndices: nextSelectedPoints.length ? nextSelectedPoints : null
8210
8273
  }
8211
8274
  });
@@ -8245,7 +8308,7 @@ var LinearElementEditor = class _LinearElementEditor {
8245
8308
  element,
8246
8309
  elementsMap,
8247
8310
  referencePoint,
8248
- pointFrom8(scenePointerX, scenePointerY),
8311
+ pointFrom9(scenePointerX, scenePointerY),
8249
8312
  event[KEYS2.CTRL_OR_CMD] ? null : app.getEffectiveGridSize(),
8250
8313
  customLineAngle
8251
8314
  );
@@ -8256,7 +8319,7 @@ var LinearElementEditor = class _LinearElementEditor {
8256
8319
  [
8257
8320
  selectedIndex,
8258
8321
  {
8259
- point: pointFrom8(
8322
+ point: pointFrom9(
8260
8323
  width + referencePoint[0],
8261
8324
  height + referencePoint[1]
8262
8325
  ),
@@ -8286,7 +8349,7 @@ var LinearElementEditor = class _LinearElementEditor {
8286
8349
  scenePointerX - linearElementEditor.pointerOffset.x,
8287
8350
  scenePointerY - linearElementEditor.pointerOffset.y,
8288
8351
  event[KEYS2.CTRL_OR_CMD] ? null : app.getEffectiveGridSize()
8289
- ) : pointFrom8(
8352
+ ) : pointFrom9(
8290
8353
  element.points[pointIndex][0] + deltaX,
8291
8354
  element.points[pointIndex][1] + deltaY
8292
8355
  );
@@ -8359,7 +8422,6 @@ var LinearElementEditor = class _LinearElementEditor {
8359
8422
  };
8360
8423
  return {
8361
8424
  ...app.state,
8362
- editingLinearElement: app.state.editingLinearElement ? newLinearElementEditor : null,
8363
8425
  selectedLinearElement: newLinearElementEditor,
8364
8426
  suggestedBindings
8365
8427
  };
@@ -8443,7 +8505,7 @@ var LinearElementEditor = class _LinearElementEditor {
8443
8505
  }
8444
8506
  static getEditorMidPoints = (element, elementsMap, appState) => {
8445
8507
  const boundText = getBoundTextElement(element, elementsMap);
8446
- if (!isElbowArrow(element) && !appState.editingLinearElement && element.points.length > 2 && !boundText) {
8508
+ if (!isElbowArrow(element) && !appState.selectedLinearElement?.isEditing && element.points.length > 2 && !boundText) {
8447
8509
  return [];
8448
8510
  }
8449
8511
  const points = _LinearElementEditor.getPointsGlobalCoordinates(
@@ -8493,18 +8555,18 @@ var LinearElementEditor = class _LinearElementEditor {
8493
8555
  element,
8494
8556
  elementsMap
8495
8557
  );
8496
- if (points.length >= 3 && !appState.editingLinearElement && !isElbowArrow(element)) {
8558
+ if (points.length >= 3 && !appState.selectedLinearElement?.isEditing && !isElbowArrow(element)) {
8497
8559
  return null;
8498
8560
  }
8499
8561
  const threshold = (_LinearElementEditor.POINT_HANDLE_SIZE + 1) / appState.zoom.value;
8500
8562
  const existingSegmentMidpointHitCoords = linearElementEditor.segmentMidPointHoveredCoords;
8501
8563
  if (existingSegmentMidpointHitCoords) {
8502
8564
  const distance3 = pointDistance5(
8503
- pointFrom8(
8565
+ pointFrom9(
8504
8566
  existingSegmentMidpointHitCoords[0],
8505
8567
  existingSegmentMidpointHitCoords[1]
8506
8568
  ),
8507
- pointFrom8(scenePointer.x, scenePointer.y)
8569
+ pointFrom9(scenePointer.x, scenePointer.y)
8508
8570
  );
8509
8571
  if (distance3 <= threshold) {
8510
8572
  return existingSegmentMidpointHitCoords;
@@ -8520,7 +8582,7 @@ var LinearElementEditor = class _LinearElementEditor {
8520
8582
  if (midPoints[index] !== null) {
8521
8583
  const distance3 = pointDistance5(
8522
8584
  midPoints[index],
8523
- pointFrom8(scenePointer.x, scenePointer.y)
8585
+ pointFrom9(scenePointer.x, scenePointer.y)
8524
8586
  );
8525
8587
  if (distance3 <= threshold) {
8526
8588
  return midPoints[index];
@@ -8559,7 +8621,7 @@ var LinearElementEditor = class _LinearElementEditor {
8559
8621
  "Invalid segment index while calculating elbow arrow mid point"
8560
8622
  );
8561
8623
  const p = pointCenter2(element.points[index - 1], element.points[index]);
8562
- return pointFrom8(element.x + p[0], element.y + p[1]);
8624
+ return pointFrom9(element.x + p[0], element.y + p[1]);
8563
8625
  }
8564
8626
  const [lines, curves] = deconstructLinearOrFreeDrawElement2(element);
8565
8627
  invariant6(
@@ -8633,7 +8695,7 @@ var LinearElementEditor = class _LinearElementEditor {
8633
8695
  segmentMidpoint,
8634
8696
  elementsMap
8635
8697
  );
8636
- } else if (event.altKey && appState.editingLinearElement) {
8698
+ } else if (event.altKey && appState.selectedLinearElement?.isEditing) {
8637
8699
  if (linearElementEditor.lastUncommittedPoint == null) {
8638
8700
  scene.mutateElement(element, {
8639
8701
  points: [
@@ -8699,12 +8761,12 @@ var LinearElementEditor = class _LinearElementEditor {
8699
8761
  const [x1, y1, x2, y2] = getElementAbsoluteCoords2(element, elementsMap);
8700
8762
  const cx = (x1 + x2) / 2;
8701
8763
  const cy = (y1 + y2) / 2;
8702
- const targetPoint = clickedPointIndex > -1 && pointRotateRads7(
8703
- pointFrom8(
8764
+ const targetPoint = clickedPointIndex > -1 && pointRotateRads8(
8765
+ pointFrom9(
8704
8766
  element.x + element.points[clickedPointIndex][0],
8705
8767
  element.y + element.points[clickedPointIndex][1]
8706
8768
  ),
8707
- pointFrom8(cx, cy),
8769
+ pointFrom9(cx, cy),
8708
8770
  element.angle
8709
8771
  );
8710
8772
  const nextSelectedPointsIndices = clickedPointIndex > -1 || event.shiftKey ? event.shiftKey || linearElementEditor.selectedPointsIndices?.includes(clickedPointIndex) ? normalizeSelectedPoints([
@@ -8743,14 +8805,14 @@ var LinearElementEditor = class _LinearElementEditor {
8743
8805
  }
8744
8806
  static handlePointerMove(event, scenePointerX, scenePointerY, app) {
8745
8807
  const appState = app.state;
8746
- if (!appState.editingLinearElement) {
8808
+ if (!appState.selectedLinearElement?.isEditing) {
8747
8809
  return null;
8748
8810
  }
8749
- const { elementId, lastUncommittedPoint } = appState.editingLinearElement;
8811
+ const { elementId, lastUncommittedPoint } = appState.selectedLinearElement;
8750
8812
  const elementsMap = app.scene.getNonDeletedElementsMap();
8751
8813
  const element = _LinearElementEditor.getElement(elementId, elementsMap);
8752
8814
  if (!element) {
8753
- return appState.editingLinearElement;
8815
+ return appState.selectedLinearElement;
8754
8816
  }
8755
8817
  const { points } = element;
8756
8818
  const lastPoint = points[points.length - 1];
@@ -8758,10 +8820,10 @@ var LinearElementEditor = class _LinearElementEditor {
8758
8820
  if (lastPoint === lastUncommittedPoint) {
8759
8821
  _LinearElementEditor.deletePoints(element, app, [points.length - 1]);
8760
8822
  }
8761
- return {
8762
- ...appState.editingLinearElement,
8823
+ return appState.selectedLinearElement?.lastUncommittedPoint ? {
8824
+ ...appState.selectedLinearElement,
8763
8825
  lastUncommittedPoint: null
8764
- };
8826
+ } : appState.selectedLinearElement;
8765
8827
  }
8766
8828
  let newPoint;
8767
8829
  if (shouldRotateWithDiscreteAngle(event) && points.length >= 2) {
@@ -8770,10 +8832,10 @@ var LinearElementEditor = class _LinearElementEditor {
8770
8832
  element,
8771
8833
  elementsMap,
8772
8834
  lastCommittedPoint,
8773
- pointFrom8(scenePointerX, scenePointerY),
8835
+ pointFrom9(scenePointerX, scenePointerY),
8774
8836
  event[KEYS2.CTRL_OR_CMD] ? null : app.getEffectiveGridSize()
8775
8837
  );
8776
- newPoint = pointFrom8(
8838
+ newPoint = pointFrom9(
8777
8839
  width + lastCommittedPoint[0],
8778
8840
  height + lastCommittedPoint[1]
8779
8841
  );
@@ -8781,8 +8843,8 @@ var LinearElementEditor = class _LinearElementEditor {
8781
8843
  newPoint = _LinearElementEditor.createPointAt(
8782
8844
  element,
8783
8845
  elementsMap,
8784
- scenePointerX - appState.editingLinearElement.pointerOffset.x,
8785
- scenePointerY - appState.editingLinearElement.pointerOffset.y,
8846
+ scenePointerX - appState.selectedLinearElement.pointerOffset.x,
8847
+ scenePointerY - appState.selectedLinearElement.pointerOffset.y,
8786
8848
  event[KEYS2.CTRL_OR_CMD] || isElbowArrow(element) ? null : app.getEffectiveGridSize()
8787
8849
  );
8788
8850
  }
@@ -8803,7 +8865,7 @@ var LinearElementEditor = class _LinearElementEditor {
8803
8865
  _LinearElementEditor.addPoints(element, app.scene, [newPoint]);
8804
8866
  }
8805
8867
  return {
8806
- ...appState.editingLinearElement,
8868
+ ...appState.selectedLinearElement,
8807
8869
  lastUncommittedPoint: element.points[element.points.length - 1]
8808
8870
  };
8809
8871
  }
@@ -8813,9 +8875,9 @@ var LinearElementEditor = class _LinearElementEditor {
8813
8875
  const cx = (x1 + x2) / 2;
8814
8876
  const cy = (y1 + y2) / 2;
8815
8877
  const { x, y } = element;
8816
- return pointRotateRads7(
8817
- pointFrom8(x + p[0], y + p[1]),
8818
- pointFrom8(cx, cy),
8878
+ return pointRotateRads8(
8879
+ pointFrom9(x + p[0], y + p[1]),
8880
+ pointFrom9(cx, cy),
8819
8881
  element.angle
8820
8882
  );
8821
8883
  }
@@ -8826,9 +8888,9 @@ var LinearElementEditor = class _LinearElementEditor {
8826
8888
  const cy = (y1 + y2) / 2;
8827
8889
  return element.points.map((p) => {
8828
8890
  const { x, y } = element;
8829
- return pointRotateRads7(
8830
- pointFrom8(x + p[0], y + p[1]),
8831
- pointFrom8(cx, cy),
8891
+ return pointRotateRads8(
8892
+ pointFrom9(x + p[0], y + p[1]),
8893
+ pointFrom9(cx, cy),
8832
8894
  element.angle
8833
8895
  );
8834
8896
  });
@@ -8840,15 +8902,15 @@ var LinearElementEditor = class _LinearElementEditor {
8840
8902
  const cy = (y1 + y2) / 2;
8841
8903
  const p = element.points[index];
8842
8904
  const { x, y } = element;
8843
- return p ? pointRotateRads7(
8844
- pointFrom8(x + p[0], y + p[1]),
8845
- pointFrom8(cx, cy),
8905
+ return p ? pointRotateRads8(
8906
+ pointFrom9(x + p[0], y + p[1]),
8907
+ pointFrom9(cx, cy),
8846
8908
  element.angle
8847
- ) : pointRotateRads7(pointFrom8(x, y), pointFrom8(cx, cy), element.angle);
8909
+ ) : pointRotateRads8(pointFrom9(x, y), pointFrom9(cx, cy), element.angle);
8848
8910
  }
8849
8911
  static pointFromAbsoluteCoords(element, absoluteCoords, elementsMap) {
8850
8912
  if (isElbowArrow(element)) {
8851
- return pointFrom8(
8913
+ return pointFrom9(
8852
8914
  absoluteCoords[0] - element.x,
8853
8915
  absoluteCoords[1] - element.y
8854
8916
  );
@@ -8856,12 +8918,12 @@ var LinearElementEditor = class _LinearElementEditor {
8856
8918
  const [x1, y1, x2, y2] = getElementAbsoluteCoords2(element, elementsMap);
8857
8919
  const cx = (x1 + x2) / 2;
8858
8920
  const cy = (y1 + y2) / 2;
8859
- const [x, y] = pointRotateRads7(
8860
- pointFrom8(absoluteCoords[0], absoluteCoords[1]),
8861
- pointFrom8(cx, cy),
8921
+ const [x, y] = pointRotateRads8(
8922
+ pointFrom9(absoluteCoords[0], absoluteCoords[1]),
8923
+ pointFrom9(cx, cy),
8862
8924
  -element.angle
8863
8925
  );
8864
- return pointFrom8(x - element.x, y - element.y);
8926
+ return pointFrom9(x - element.x, y - element.y);
8865
8927
  }
8866
8928
  static getPointIndexUnderCursor(element, elementsMap, zoom, x, y) {
8867
8929
  const pointHandles = _LinearElementEditor.getPointsGlobalCoordinates(
@@ -8871,7 +8933,7 @@ var LinearElementEditor = class _LinearElementEditor {
8871
8933
  let idx = pointHandles.length;
8872
8934
  while (--idx > -1) {
8873
8935
  const p = pointHandles[idx];
8874
- if (pointDistance5(pointFrom8(x, y), pointFrom8(p[0], p[1])) * zoom.value < // +1px to account for outline stroke
8936
+ if (pointDistance5(pointFrom9(x, y), pointFrom9(p[0], p[1])) * zoom.value < // +1px to account for outline stroke
8875
8937
  _LinearElementEditor.POINT_HANDLE_SIZE + 1) {
8876
8938
  return idx;
8877
8939
  }
@@ -8883,12 +8945,12 @@ var LinearElementEditor = class _LinearElementEditor {
8883
8945
  const [x1, y1, x2, y2] = getElementAbsoluteCoords2(element, elementsMap);
8884
8946
  const cx = (x1 + x2) / 2;
8885
8947
  const cy = (y1 + y2) / 2;
8886
- const [rotatedX, rotatedY] = pointRotateRads7(
8887
- pointFrom8(pointerOnGrid[0], pointerOnGrid[1]),
8888
- pointFrom8(cx, cy),
8948
+ const [rotatedX, rotatedY] = pointRotateRads8(
8949
+ pointFrom9(pointerOnGrid[0], pointerOnGrid[1]),
8950
+ pointFrom9(cx, cy),
8889
8951
  -element.angle
8890
8952
  );
8891
- return pointFrom8(rotatedX - element.x, rotatedY - element.y);
8953
+ return pointFrom9(rotatedX - element.x, rotatedY - element.y);
8892
8954
  }
8893
8955
  /**
8894
8956
  * Normalizes line points so that the start point is at [0,0]. This is
@@ -8909,11 +8971,11 @@ var LinearElementEditor = class _LinearElementEditor {
8909
8971
  // ---------------------------------------------------------------------------
8910
8972
  static duplicateSelectedPoints(appState, scene) {
8911
8973
  invariant6(
8912
- appState.editingLinearElement,
8974
+ appState.selectedLinearElement?.isEditing,
8913
8975
  "Not currently editing a linear element"
8914
8976
  );
8915
8977
  const elementsMap = scene.getNonDeletedElementsMap();
8916
- const { selectedPointsIndices, elementId } = appState.editingLinearElement;
8978
+ const { selectedPointsIndices, elementId } = appState.selectedLinearElement;
8917
8979
  const element = _LinearElementEditor.getElement(elementId, elementsMap);
8918
8980
  invariant6(
8919
8981
  element,
@@ -8937,7 +8999,7 @@ var LinearElementEditor = class _LinearElementEditor {
8937
8999
  pointAddedToEnd = true;
8938
9000
  }
8939
9001
  acc.push(
8940
- nextPoint ? pointFrom8((p[0] + nextPoint[0]) / 2, (p[1] + nextPoint[1]) / 2) : pointFrom8(p[0], p[1])
9002
+ nextPoint ? pointFrom9((p[0] + nextPoint[0]) / 2, (p[1] + nextPoint[1]) / 2) : pointFrom9(p[0], p[1])
8941
9003
  );
8942
9004
  nextSelectedIndices.push(indexCursor + 1);
8943
9005
  ++indexCursor;
@@ -8953,27 +9015,27 @@ var LinearElementEditor = class _LinearElementEditor {
8953
9015
  /* @__PURE__ */ new Map([
8954
9016
  [
8955
9017
  element.points.length - 1,
8956
- { point: pointFrom8(lastPoint[0] + 30, lastPoint[1] + 30) }
9018
+ { point: pointFrom9(lastPoint[0] + 30, lastPoint[1] + 30) }
8957
9019
  ]
8958
9020
  ])
8959
9021
  );
8960
9022
  }
8961
9023
  return {
8962
9024
  ...appState,
8963
- editingLinearElement: {
8964
- ...appState.editingLinearElement,
9025
+ selectedLinearElement: {
9026
+ ...appState.selectedLinearElement,
8965
9027
  selectedPointsIndices: nextSelectedIndices
8966
9028
  }
8967
9029
  };
8968
9030
  }
8969
9031
  static deletePoints(element, app, pointIndices) {
8970
- const isUncommittedPoint = app.state.editingLinearElement?.lastUncommittedPoint === element.points[element.points.length - 1];
9032
+ const isUncommittedPoint = app.state.selectedLinearElement?.isEditing && app.state.selectedLinearElement?.lastUncommittedPoint === element.points[element.points.length - 1];
8971
9033
  const nextPoints = element.points.filter((_, idx) => {
8972
9034
  return !pointIndices.includes(idx);
8973
9035
  });
8974
9036
  const isPolygon = isLineElement(element) && element.polygon;
8975
9037
  if (isPolygon && (isUncommittedPoint || pointIndices.includes(0) || pointIndices.includes(element.points.length - 1))) {
8976
- nextPoints[0] = pointFrom8(
9038
+ nextPoints[0] = pointFrom9(
8977
9039
  nextPoints[nextPoints.length - 1][0],
8978
9040
  nextPoints[nextPoints.length - 1][1]
8979
9041
  );
@@ -8994,7 +9056,7 @@ var LinearElementEditor = class _LinearElementEditor {
8994
9056
  static addPoints(element, scene, addedPoints) {
8995
9057
  const nextPoints = [...element.points, ...addedPoints];
8996
9058
  if (isLineElement(element) && element.polygon) {
8997
- nextPoints[0] = pointFrom8(
9059
+ nextPoints[0] = pointFrom9(
8998
9060
  nextPoints[nextPoints.length - 1][0],
8999
9061
  nextPoints[nextPoints.length - 1][1]
9000
9062
  );
@@ -9019,7 +9081,7 @@ var LinearElementEditor = class _LinearElementEditor {
9019
9081
  const lastPointUpdate = pointUpdates.get(points.length - 1);
9020
9082
  if (firstPointUpdate) {
9021
9083
  pointUpdates.set(points.length - 1, {
9022
- point: pointFrom8(
9084
+ point: pointFrom9(
9023
9085
  firstPointUpdate.point[0],
9024
9086
  firstPointUpdate.point[1]
9025
9087
  ),
@@ -9027,19 +9089,19 @@ var LinearElementEditor = class _LinearElementEditor {
9027
9089
  });
9028
9090
  } else if (lastPointUpdate) {
9029
9091
  pointUpdates.set(0, {
9030
- point: pointFrom8(lastPointUpdate.point[0], lastPointUpdate.point[1]),
9092
+ point: pointFrom9(lastPointUpdate.point[0], lastPointUpdate.point[1]),
9031
9093
  isDragging: lastPointUpdate.isDragging
9032
9094
  });
9033
9095
  }
9034
9096
  }
9035
- const updatedOriginPoint = pointUpdates.get(0)?.point ?? pointFrom8(0, 0);
9097
+ const updatedOriginPoint = pointUpdates.get(0)?.point ?? pointFrom9(0, 0);
9036
9098
  const [offsetX, offsetY] = updatedOriginPoint;
9037
9099
  const nextPoints = isElbowArrow(element) ? [
9038
9100
  pointUpdates.get(0)?.point ?? points[0],
9039
9101
  pointUpdates.get(points.length - 1)?.point ?? points[points.length - 1]
9040
9102
  ] : points.map((p, idx) => {
9041
9103
  const current = pointUpdates.get(idx)?.point ?? p;
9042
- return pointFrom8(
9104
+ return pointFrom9(
9043
9105
  current[0] - offsetX,
9044
9106
  current[1] - offsetY
9045
9107
  );
@@ -9073,10 +9135,10 @@ var LinearElementEditor = class _LinearElementEditor {
9073
9135
  }
9074
9136
  const origin = linearElementEditor.pointerDownState.origin;
9075
9137
  const dist = pointDistance5(
9076
- pointFrom8(origin.x, origin.y),
9077
- pointFrom8(pointerCoords.x, pointerCoords.y)
9138
+ pointFrom9(origin.x, origin.y),
9139
+ pointFrom9(pointerCoords.x, pointerCoords.y)
9078
9140
  );
9079
- if (!appState.editingLinearElement && dist < DRAGGING_THRESHOLD / appState.zoom.value) {
9141
+ if (!appState.selectedLinearElement?.isEditing && dist < DRAGGING_THRESHOLD / appState.zoom.value) {
9080
9142
  return false;
9081
9143
  }
9082
9144
  return true;
@@ -9142,9 +9204,9 @@ var LinearElementEditor = class _LinearElementEditor {
9142
9204
  const prevCenterY = (prevCoords[1] + prevCoords[3]) / 2;
9143
9205
  const dX = prevCenterX - nextCenterX;
9144
9206
  const dY = prevCenterY - nextCenterY;
9145
- const rotatedOffset = pointRotateRads7(
9146
- pointFrom8(offsetX, offsetY),
9147
- pointFrom8(dX, dY),
9207
+ const rotatedOffset = pointRotateRads8(
9208
+ pointFrom9(offsetX, offsetY),
9209
+ pointFrom9(dX, dY),
9148
9210
  element.angle
9149
9211
  );
9150
9212
  scene.mutateElement(element, {
@@ -9179,9 +9241,9 @@ var LinearElementEditor = class _LinearElementEditor {
9179
9241
  gridY,
9180
9242
  customLineAngle
9181
9243
  );
9182
- return pointRotateRads7(
9183
- pointFrom8(width, height),
9184
- pointFrom8(0, 0),
9244
+ return pointRotateRads8(
9245
+ pointFrom9(width, height),
9246
+ pointFrom9(0, 0),
9185
9247
  -element.angle
9186
9248
  );
9187
9249
  }
@@ -9226,34 +9288,34 @@ var LinearElementEditor = class _LinearElementEditor {
9226
9288
  );
9227
9289
  const boundTextX2 = boundTextX1 + boundTextElement.width;
9228
9290
  const boundTextY2 = boundTextY1 + boundTextElement.height;
9229
- const centerPoint = pointFrom8(cx, cy);
9230
- const topLeftRotatedPoint = pointRotateRads7(
9231
- pointFrom8(x1, y1),
9291
+ const centerPoint = pointFrom9(cx, cy);
9292
+ const topLeftRotatedPoint = pointRotateRads8(
9293
+ pointFrom9(x1, y1),
9232
9294
  centerPoint,
9233
9295
  element.angle
9234
9296
  );
9235
- const topRightRotatedPoint = pointRotateRads7(
9236
- pointFrom8(x2, y1),
9297
+ const topRightRotatedPoint = pointRotateRads8(
9298
+ pointFrom9(x2, y1),
9237
9299
  centerPoint,
9238
9300
  element.angle
9239
9301
  );
9240
- const counterRotateBoundTextTopLeft = pointRotateRads7(
9241
- pointFrom8(boundTextX1, boundTextY1),
9302
+ const counterRotateBoundTextTopLeft = pointRotateRads8(
9303
+ pointFrom9(boundTextX1, boundTextY1),
9242
9304
  centerPoint,
9243
9305
  -element.angle
9244
9306
  );
9245
- const counterRotateBoundTextTopRight = pointRotateRads7(
9246
- pointFrom8(boundTextX2, boundTextY1),
9307
+ const counterRotateBoundTextTopRight = pointRotateRads8(
9308
+ pointFrom9(boundTextX2, boundTextY1),
9247
9309
  centerPoint,
9248
9310
  -element.angle
9249
9311
  );
9250
- const counterRotateBoundTextBottomLeft = pointRotateRads7(
9251
- pointFrom8(boundTextX1, boundTextY2),
9312
+ const counterRotateBoundTextBottomLeft = pointRotateRads8(
9313
+ pointFrom9(boundTextX1, boundTextY2),
9252
9314
  centerPoint,
9253
9315
  -element.angle
9254
9316
  );
9255
- const counterRotateBoundTextBottomRight = pointRotateRads7(
9256
- pointFrom8(boundTextX2, boundTextY2),
9317
+ const counterRotateBoundTextBottomRight = pointRotateRads8(
9318
+ pointFrom9(boundTextX2, boundTextY2),
9257
9319
  centerPoint,
9258
9320
  -element.angle
9259
9321
  );
@@ -9369,11 +9431,11 @@ var LinearElementEditor = class _LinearElementEditor {
9369
9431
  );
9370
9432
  fixedSegments[index] = {
9371
9433
  index,
9372
- start: pointFrom8(
9434
+ start: pointFrom9(
9373
9435
  !isHorizontal ? x - element.x : element.points[index - 1][0],
9374
9436
  isHorizontal ? y - element.y : element.points[index - 1][1]
9375
9437
  ),
9376
- end: pointFrom8(
9438
+ end: pointFrom9(
9377
9439
  !isHorizontal ? x - element.x : element.points[index][0],
9378
9440
  isHorizontal ? y - element.y : element.points[index][1]
9379
9441
  )
@@ -9385,7 +9447,7 @@ var LinearElementEditor = class _LinearElementEditor {
9385
9447
  scene.mutateElement(element, {
9386
9448
  fixedSegments: nextFixedSegments
9387
9449
  });
9388
- const point = pointFrom8(
9450
+ const point = pointFrom9(
9389
9451
  element.x + (element.fixedSegments[offset].start[0] + element.fixedSegments[offset].end[0]) / 2,
9390
9452
  element.y + (element.fixedSegments[offset].start[1] + element.fixedSegments[offset].end[1]) / 2
9391
9453
  );
@@ -9423,7 +9485,7 @@ var normalizeSelectedPoints = (points) => {
9423
9485
  // src/frame.ts
9424
9486
  init_define_import_meta_env();
9425
9487
  import { arrayToMap as arrayToMap5 } from "@excalidraw/common";
9426
- import { isPointWithinBounds as isPointWithinBounds2, pointFrom as pointFrom10 } from "@excalidraw/math";
9488
+ import { isPointWithinBounds as isPointWithinBounds2, pointFrom as pointFrom11 } from "@excalidraw/math";
9427
9489
 
9428
9490
  // ../utils/src/bbox.ts
9429
9491
  init_define_import_meta_env();
@@ -9474,24 +9536,24 @@ import {
9474
9536
  } from "@excalidraw/element";
9475
9537
  import {
9476
9538
  rangeIncludesValue,
9477
- pointFrom as pointFrom9,
9478
- pointRotateRads as pointRotateRads8,
9539
+ pointFrom as pointFrom10,
9540
+ pointRotateRads as pointRotateRads9,
9479
9541
  rangeInclusive
9480
9542
  } from "@excalidraw/math";
9481
9543
  var getNonLinearElementRelativePoints = (element) => {
9482
9544
  if (element.type === "diamond") {
9483
9545
  return [
9484
- pointFrom9(element.width / 2, 0),
9485
- pointFrom9(element.width, element.height / 2),
9486
- pointFrom9(element.width / 2, element.height),
9487
- pointFrom9(0, element.height / 2)
9546
+ pointFrom10(element.width / 2, 0),
9547
+ pointFrom10(element.width, element.height / 2),
9548
+ pointFrom10(element.width / 2, element.height),
9549
+ pointFrom10(0, element.height / 2)
9488
9550
  ];
9489
9551
  }
9490
9552
  return [
9491
- pointFrom9(0, 0),
9492
- pointFrom9(0 + element.width, 0),
9493
- pointFrom9(0 + element.width, element.height),
9494
- pointFrom9(0, element.height)
9553
+ pointFrom10(0, 0),
9554
+ pointFrom10(0 + element.width, 0),
9555
+ pointFrom10(0 + element.width, element.height),
9556
+ pointFrom10(0, element.height)
9495
9557
  ];
9496
9558
  };
9497
9559
  var getElementRelativePoints = (element) => {
@@ -9525,9 +9587,9 @@ var getMinMaxPoints = (points) => {
9525
9587
  var getRotatedBBox = (element) => {
9526
9588
  const points = getElementRelativePoints(element);
9527
9589
  const { cx, cy } = getMinMaxPoints(points);
9528
- const centerPoint = pointFrom9(cx, cy);
9590
+ const centerPoint = pointFrom10(cx, cy);
9529
9591
  const rotatedPoints = points.map(
9530
- (p) => pointRotateRads8(p, centerPoint, element.angle)
9592
+ (p) => pointRotateRads9(p, centerPoint, element.angle)
9531
9593
  );
9532
9594
  const { minX, minY, maxX, maxY } = getMinMaxPoints(rotatedPoints);
9533
9595
  return [
@@ -9829,6 +9891,55 @@ var getNewGroupIdsForDuplication = (groupIds, editingGroupId, mapper) => {
9829
9891
  }
9830
9892
  return copy;
9831
9893
  };
9894
+ var getSelectedElementsByGroup = (selectedElements, elementsMap, appState) => {
9895
+ const selectedGroupIds = getSelectedGroupIds(appState);
9896
+ const unboundElements = selectedElements.filter(
9897
+ (element) => !isBoundToContainer(element)
9898
+ );
9899
+ const groups = /* @__PURE__ */ new Map();
9900
+ const elements = /* @__PURE__ */ new Map();
9901
+ const addToElementsMap = (element) => {
9902
+ const currentElementMembers = elements.get(element.id) || [];
9903
+ const boundTextElement = getBoundTextElement(element, elementsMap);
9904
+ if (boundTextElement) {
9905
+ currentElementMembers.push(boundTextElement);
9906
+ }
9907
+ elements.set(element.id, [...currentElementMembers, element]);
9908
+ };
9909
+ const addToGroupsMap = (element, groupId) => {
9910
+ const currentGroupMembers = groups.get(groupId) || [];
9911
+ const boundTextElement = getBoundTextElement(element, elementsMap);
9912
+ if (boundTextElement) {
9913
+ currentGroupMembers.push(boundTextElement);
9914
+ }
9915
+ groups.set(groupId, [...currentGroupMembers, element]);
9916
+ };
9917
+ const handleSingleSelectedGroupCase = (element, selectedGroupId) => {
9918
+ const indexOfSelectedGroupId = element.groupIds.indexOf(selectedGroupId, 0);
9919
+ const nestedGroupCount = element.groupIds.slice(
9920
+ 0,
9921
+ indexOfSelectedGroupId
9922
+ ).length;
9923
+ return nestedGroupCount > 0 ? addToGroupsMap(element, element.groupIds[indexOfSelectedGroupId - 1]) : addToElementsMap(element);
9924
+ };
9925
+ const isAllInSameGroup = selectedElements.every(
9926
+ (element) => isSelectedViaGroup(appState, element)
9927
+ );
9928
+ unboundElements.forEach((element) => {
9929
+ const selectedGroupId = getSelectedGroupIdForElement(
9930
+ element,
9931
+ appState.selectedGroupIds
9932
+ );
9933
+ if (!selectedGroupId) {
9934
+ addToElementsMap(element);
9935
+ } else if (selectedGroupIds.length === 1 && isAllInSameGroup) {
9936
+ handleSingleSelectedGroupCase(element, selectedGroupId);
9937
+ } else {
9938
+ addToGroupsMap(element, selectedGroupId);
9939
+ }
9940
+ });
9941
+ return Array.from(groups.values()).concat(Array.from(elements.values()));
9942
+ };
9832
9943
 
9833
9944
  // src/selection.ts
9834
9945
  var excludeElementsInFramesFromSelection = (selectedElements) => {
@@ -10042,9 +10153,9 @@ var elementOverlapsWithFrame = (element, frame, elementsMap) => {
10042
10153
  var isCursorInFrame = (cursorCoords, frame, elementsMap) => {
10043
10154
  const [fx1, fy1, fx2, fy2] = getElementAbsoluteCoords2(frame, elementsMap);
10044
10155
  return isPointWithinBounds2(
10045
- pointFrom10(fx1, fy1),
10046
- pointFrom10(cursorCoords.x, cursorCoords.y),
10047
- pointFrom10(fx2, fy2)
10156
+ pointFrom11(fx1, fy1),
10157
+ pointFrom11(cursorCoords.x, cursorCoords.y),
10158
+ pointFrom11(fx2, fy2)
10048
10159
  );
10049
10160
  };
10050
10161
  var groupsAreAtLeastIntersectingTheFrame = (elements, groupIds, frame) => {
@@ -10516,6 +10627,11 @@ var getCanvasPadding = (element) => {
10516
10627
  return element.strokeWidth * 12;
10517
10628
  case "text":
10518
10629
  return element.fontSize / 2;
10630
+ case "arrow":
10631
+ if (element.endArrowhead || element.endArrowhead) {
10632
+ return 40;
10633
+ }
10634
+ return 20;
10519
10635
  default:
10520
10636
  return 20;
10521
10637
  }
@@ -11103,6 +11219,58 @@ function getFreeDrawPath2D(element) {
11103
11219
  return pathsCache.get(element);
11104
11220
  }
11105
11221
  function getFreeDrawSvgPath(element) {
11222
+ return getSvgPathFromStroke(getFreedrawOutlinePoints(element));
11223
+ }
11224
+ function getFreedrawOutlineAsSegments(element, points, elementsMap) {
11225
+ const bounds = getElementBounds(
11226
+ {
11227
+ ...element,
11228
+ angle: 0
11229
+ },
11230
+ elementsMap
11231
+ );
11232
+ const center = pointFrom12(
11233
+ (bounds[0] + bounds[2]) / 2,
11234
+ (bounds[1] + bounds[3]) / 2
11235
+ );
11236
+ invariant7(points.length >= 2, "Freepath outline must have at least 2 points");
11237
+ return points.slice(2).reduce(
11238
+ (acc, curr) => {
11239
+ acc.push(
11240
+ lineSegment5(
11241
+ acc[acc.length - 1][1],
11242
+ pointRotateRads10(
11243
+ pointFrom12(curr[0] + element.x, curr[1] + element.y),
11244
+ center,
11245
+ element.angle
11246
+ )
11247
+ )
11248
+ );
11249
+ return acc;
11250
+ },
11251
+ [
11252
+ lineSegment5(
11253
+ pointRotateRads10(
11254
+ pointFrom12(
11255
+ points[0][0] + element.x,
11256
+ points[0][1] + element.y
11257
+ ),
11258
+ center,
11259
+ element.angle
11260
+ ),
11261
+ pointRotateRads10(
11262
+ pointFrom12(
11263
+ points[1][0] + element.x,
11264
+ points[1][1] + element.y
11265
+ ),
11266
+ center,
11267
+ element.angle
11268
+ )
11269
+ )
11270
+ ]
11271
+ );
11272
+ }
11273
+ function getFreedrawOutlinePoints(element) {
11106
11274
  const inputPoints = element.simulatePressure ? element.points : element.points.length ? element.points.map(([x, y], i) => [x, y, element.pressures[i]]) : [[0, 0, 0.5]];
11107
11275
  const options = {
11108
11276
  simulatePressure: element.simulatePressure,
@@ -11115,7 +11283,7 @@ function getFreeDrawSvgPath(element) {
11115
11283
  last: !!element.lastCommittedPoint
11116
11284
  // LastCommittedPoint is added on pointerup
11117
11285
  };
11118
- return getSvgPathFromStroke(ae(inputPoints, options));
11286
+ return ae(inputPoints, options);
11119
11287
  }
11120
11288
  function med(A2, B2) {
11121
11289
  return [(A2[0] + B2[0]) / 2, (A2[1] + B2[1]) / 2];
@@ -11142,7 +11310,7 @@ function getSvgPathFromStroke(points) {
11142
11310
  // src/comparisons.ts
11143
11311
  init_define_import_meta_env();
11144
11312
  var hasBackground = (type) => type === "rectangle" || type === "iframe" || type === "embeddable" || type === "ellipse" || type === "diamond" || type === "line" || type === "freedraw";
11145
- var hasStrokeColor = (type) => type !== "image" && type !== "frame" && type !== "magicframe";
11313
+ var hasStrokeColor = (type) => type === "rectangle" || type === "ellipse" || type === "diamond" || type === "freedraw" || type === "arrow" || type === "line" || type === "text";
11146
11314
  var hasStrokeWidth = (type) => type === "rectangle" || type === "iframe" || type === "embeddable" || type === "ellipse" || type === "diamond" || type === "freedraw" || type === "arrow" || type === "line";
11147
11315
  var hasStrokeStyle = (type) => type === "rectangle" || type === "iframe" || type === "embeddable" || type === "ellipse" || type === "diamond" || type === "arrow" || type === "line";
11148
11316
  var canChangeRoundness = (type) => type === "rectangle" || type === "iframe" || type === "embeddable" || type === "line" || type === "diamond" || type === "image";
@@ -11398,26 +11566,26 @@ var generateLinearCollisionShape = (element) => {
11398
11566
  switch (element.type) {
11399
11567
  case "line":
11400
11568
  case "arrow": {
11401
- const points = element.points.length ? element.points : [pointFrom11(0, 0)];
11569
+ const points = element.points.length ? element.points : [pointFrom13(0, 0)];
11402
11570
  if (isElbowArrow(element)) {
11403
11571
  return generator.path(generateElbowArrowShape(points, 16), options).sets[0].ops;
11404
11572
  } else if (!element.roundness) {
11405
11573
  return points.map((point, idx) => {
11406
- const p = pointRotateRads9(
11407
- pointFrom11(element.x + point[0], element.y + point[1]),
11574
+ const p = pointRotateRads11(
11575
+ pointFrom13(element.x + point[0], element.y + point[1]),
11408
11576
  center,
11409
11577
  element.angle
11410
11578
  );
11411
11579
  return {
11412
11580
  op: idx === 0 ? "move" : "lineTo",
11413
- data: pointFrom11(p[0] - element.x, p[1] - element.y)
11581
+ data: pointFrom13(p[0] - element.x, p[1] - element.y)
11414
11582
  };
11415
11583
  });
11416
11584
  }
11417
11585
  return generator.curve(points, options).sets[0].ops.slice(0, element.points.length).map((op, i) => {
11418
11586
  if (i === 0) {
11419
- const p = pointRotateRads9(
11420
- pointFrom11(
11587
+ const p = pointRotateRads11(
11588
+ pointFrom13(
11421
11589
  element.x + op.data[0],
11422
11590
  element.y + op.data[1]
11423
11591
  ),
@@ -11426,30 +11594,30 @@ var generateLinearCollisionShape = (element) => {
11426
11594
  );
11427
11595
  return {
11428
11596
  op: "move",
11429
- data: pointFrom11(p[0] - element.x, p[1] - element.y)
11597
+ data: pointFrom13(p[0] - element.x, p[1] - element.y)
11430
11598
  };
11431
11599
  }
11432
11600
  return {
11433
11601
  op: "bcurveTo",
11434
11602
  data: [
11435
- pointRotateRads9(
11436
- pointFrom11(
11603
+ pointRotateRads11(
11604
+ pointFrom13(
11437
11605
  element.x + op.data[0],
11438
11606
  element.y + op.data[1]
11439
11607
  ),
11440
11608
  center,
11441
11609
  element.angle
11442
11610
  ),
11443
- pointRotateRads9(
11444
- pointFrom11(
11611
+ pointRotateRads11(
11612
+ pointFrom13(
11445
11613
  element.x + op.data[2],
11446
11614
  element.y + op.data[3]
11447
11615
  ),
11448
11616
  center,
11449
11617
  element.angle
11450
11618
  ),
11451
- pointRotateRads9(
11452
- pointFrom11(
11619
+ pointRotateRads11(
11620
+ pointFrom13(
11453
11621
  element.x + op.data[4],
11454
11622
  element.y + op.data[5]
11455
11623
  ),
@@ -11457,7 +11625,7 @@ var generateLinearCollisionShape = (element) => {
11457
11625
  element.angle
11458
11626
  )
11459
11627
  ].map(
11460
- (p) => pointFrom11(p[0] - element.x, p[1] - element.y)
11628
+ (p) => pointFrom13(p[0] - element.x, p[1] - element.y)
11461
11629
  ).flat()
11462
11630
  };
11463
11631
  });
@@ -11472,8 +11640,8 @@ var generateLinearCollisionShape = (element) => {
11472
11640
  );
11473
11641
  return generator.curve(simplifiedPoints, options).sets[0].ops.slice(0, element.points.length).map((op, i) => {
11474
11642
  if (i === 0) {
11475
- const p = pointRotateRads9(
11476
- pointFrom11(
11643
+ const p = pointRotateRads11(
11644
+ pointFrom13(
11477
11645
  element.x + op.data[0],
11478
11646
  element.y + op.data[1]
11479
11647
  ),
@@ -11482,30 +11650,30 @@ var generateLinearCollisionShape = (element) => {
11482
11650
  );
11483
11651
  return {
11484
11652
  op: "move",
11485
- data: pointFrom11(p[0] - element.x, p[1] - element.y)
11653
+ data: pointFrom13(p[0] - element.x, p[1] - element.y)
11486
11654
  };
11487
11655
  }
11488
11656
  return {
11489
11657
  op: "bcurveTo",
11490
11658
  data: [
11491
- pointRotateRads9(
11492
- pointFrom11(
11659
+ pointRotateRads11(
11660
+ pointFrom13(
11493
11661
  element.x + op.data[0],
11494
11662
  element.y + op.data[1]
11495
11663
  ),
11496
11664
  center,
11497
11665
  element.angle
11498
11666
  ),
11499
- pointRotateRads9(
11500
- pointFrom11(
11667
+ pointRotateRads11(
11668
+ pointFrom13(
11501
11669
  element.x + op.data[2],
11502
11670
  element.y + op.data[3]
11503
11671
  ),
11504
11672
  center,
11505
11673
  element.angle
11506
11674
  ),
11507
- pointRotateRads9(
11508
- pointFrom11(
11675
+ pointRotateRads11(
11676
+ pointFrom13(
11509
11677
  element.x + op.data[4],
11510
11678
  element.y + op.data[5]
11511
11679
  ),
@@ -11513,7 +11681,7 @@ var generateLinearCollisionShape = (element) => {
11513
11681
  element.angle
11514
11682
  )
11515
11683
  ].map(
11516
- (p) => pointFrom11(p[0] - element.x, p[1] - element.y)
11684
+ (p) => pointFrom13(p[0] - element.x, p[1] - element.y)
11517
11685
  ).flat()
11518
11686
  };
11519
11687
  });
@@ -11610,7 +11778,7 @@ var generateElementShape = (element, generator, {
11610
11778
  case "arrow": {
11611
11779
  let shape;
11612
11780
  const options = generateRoughOptions(element);
11613
- const points = element.points.length ? element.points : [pointFrom11(0, 0)];
11781
+ const points = element.points.length ? element.points : [pointFrom13(0, 0)];
11614
11782
  if (isElbowArrow(element)) {
11615
11783
  if (!points.every(
11616
11784
  (point) => Math.abs(point[0]) <= 1e6 && Math.abs(point[1]) <= 1e6
@@ -11772,14 +11940,14 @@ var getElementShape = (element, elementsMap) => {
11772
11940
  return shouldTestInside(element) ? getClosedCurveShape(
11773
11941
  element,
11774
11942
  roughShape,
11775
- pointFrom11(element.x, element.y),
11943
+ pointFrom13(element.x, element.y),
11776
11944
  element.angle,
11777
- pointFrom11(cx, cy)
11945
+ pointFrom13(cx, cy)
11778
11946
  ) : getCurveShape(
11779
11947
  roughShape,
11780
- pointFrom11(element.x, element.y),
11948
+ pointFrom13(element.x, element.y),
11781
11949
  element.angle,
11782
- pointFrom11(cx, cy)
11950
+ pointFrom13(cx, cy)
11783
11951
  );
11784
11952
  }
11785
11953
  case "ellipse":
@@ -11788,7 +11956,7 @@ var getElementShape = (element, elementsMap) => {
11788
11956
  const [, , , , cx, cy] = getElementAbsoluteCoords2(element, elementsMap);
11789
11957
  return getFreedrawShape(
11790
11958
  element,
11791
- pointFrom11(cx, cy),
11959
+ pointFrom13(cx, cy),
11792
11960
  shouldTestInside(element)
11793
11961
  );
11794
11962
  }
@@ -11807,9 +11975,9 @@ var toggleLinePolygonState = (element, nextPolygonState) => {
11807
11975
  firstPoint[1] - lastPoint[1]
11808
11976
  );
11809
11977
  if (distance3 > LINE_POLYGON_POINT_MERGE_DISTANCE || updatedPoints.length < 4) {
11810
- updatedPoints.push(pointFrom11(firstPoint[0], firstPoint[1]));
11978
+ updatedPoints.push(pointFrom13(firstPoint[0], firstPoint[1]));
11811
11979
  } else {
11812
- updatedPoints[updatedPoints.length - 1] = pointFrom11(
11980
+ updatedPoints[updatedPoints.length - 1] = pointFrom13(
11813
11981
  firstPoint[0],
11814
11982
  firstPoint[1]
11815
11983
  );
@@ -11863,9 +12031,9 @@ var ElementBounds = class _ElementBounds {
11863
12031
  if (isFreeDrawElement(element)) {
11864
12032
  const [minX, minY, maxX, maxY] = getBoundsFromPoints(
11865
12033
  element.points.map(
11866
- ([x, y]) => pointRotateRads10(
11867
- pointFrom12(x, y),
11868
- pointFrom12(cx - element.x, cy - element.y),
12034
+ ([x, y]) => pointRotateRads12(
12035
+ pointFrom14(x, y),
12036
+ pointFrom14(cx - element.x, cy - element.y),
11869
12037
  element.angle
11870
12038
  )
11871
12039
  )
@@ -11879,24 +12047,24 @@ var ElementBounds = class _ElementBounds {
11879
12047
  } else if (isLinearElement(element)) {
11880
12048
  bounds = getLinearElementRotatedBounds(element, cx, cy, elementsMap);
11881
12049
  } else if (element.type === "diamond") {
11882
- const [x11, y11] = pointRotateRads10(
11883
- pointFrom12(cx, y1),
11884
- pointFrom12(cx, cy),
12050
+ const [x11, y11] = pointRotateRads12(
12051
+ pointFrom14(cx, y1),
12052
+ pointFrom14(cx, cy),
11885
12053
  element.angle
11886
12054
  );
11887
- const [x12, y12] = pointRotateRads10(
11888
- pointFrom12(cx, y2),
11889
- pointFrom12(cx, cy),
12055
+ const [x12, y12] = pointRotateRads12(
12056
+ pointFrom14(cx, y2),
12057
+ pointFrom14(cx, cy),
11890
12058
  element.angle
11891
12059
  );
11892
- const [x22, y22] = pointRotateRads10(
11893
- pointFrom12(x1, cy),
11894
- pointFrom12(cx, cy),
12060
+ const [x22, y22] = pointRotateRads12(
12061
+ pointFrom14(x1, cy),
12062
+ pointFrom14(cx, cy),
11895
12063
  element.angle
11896
12064
  );
11897
- const [x21, y21] = pointRotateRads10(
11898
- pointFrom12(x2, cy),
11899
- pointFrom12(cx, cy),
12065
+ const [x21, y21] = pointRotateRads12(
12066
+ pointFrom14(x2, cy),
12067
+ pointFrom14(cx, cy),
11900
12068
  element.angle
11901
12069
  );
11902
12070
  const minX = Math.min(x11, x12, x22, x21);
@@ -11913,24 +12081,24 @@ var ElementBounds = class _ElementBounds {
11913
12081
  const hh = Math.hypot(h * cos, w * sin);
11914
12082
  bounds = [cx - ww, cy - hh, cx + ww, cy + hh];
11915
12083
  } else {
11916
- const [x11, y11] = pointRotateRads10(
11917
- pointFrom12(x1, y1),
11918
- pointFrom12(cx, cy),
12084
+ const [x11, y11] = pointRotateRads12(
12085
+ pointFrom14(x1, y1),
12086
+ pointFrom14(cx, cy),
11919
12087
  element.angle
11920
12088
  );
11921
- const [x12, y12] = pointRotateRads10(
11922
- pointFrom12(x1, y2),
11923
- pointFrom12(cx, cy),
12089
+ const [x12, y12] = pointRotateRads12(
12090
+ pointFrom14(x1, y2),
12091
+ pointFrom14(cx, cy),
11924
12092
  element.angle
11925
12093
  );
11926
- const [x22, y22] = pointRotateRads10(
11927
- pointFrom12(x2, y2),
11928
- pointFrom12(cx, cy),
12094
+ const [x22, y22] = pointRotateRads12(
12095
+ pointFrom14(x2, y2),
12096
+ pointFrom14(cx, cy),
11929
12097
  element.angle
11930
12098
  );
11931
- const [x21, y21] = pointRotateRads10(
11932
- pointFrom12(x2, y1),
11933
- pointFrom12(cx, cy),
12099
+ const [x21, y21] = pointRotateRads12(
12100
+ pointFrom14(x2, y1),
12101
+ pointFrom14(cx, cy),
11934
12102
  element.angle
11935
12103
  );
11936
12104
  const minX = Math.min(x11, x12, x22, x21);
@@ -11984,20 +12152,38 @@ var getElementLineSegments = (element, elementsMap) => {
11984
12152
  element,
11985
12153
  elementsMap
11986
12154
  );
11987
- const center = pointFrom12(cx, cy);
12155
+ const center = pointFrom14(cx, cy);
11988
12156
  if (shape.type === "polycurve") {
11989
12157
  const curves = shape.data;
11990
- const points = curves.map((curve4) => pointsOnBezierCurves(curve4, 10)).flat();
11991
- let i = 0;
12158
+ const pointsOnCurves = curves.map(
12159
+ (curve4) => pointsOnBezierCurves(curve4, 10)
12160
+ );
11992
12161
  const segments = [];
11993
- while (i < points.length - 1) {
11994
- segments.push(
11995
- lineSegment5(
11996
- pointFrom12(points[i][0], points[i][1]),
11997
- pointFrom12(points[i + 1][0], points[i + 1][1])
11998
- )
11999
- );
12000
- i++;
12162
+ if (isLineElement(element) && !element.polygon || isArrowElement(element)) {
12163
+ for (const points of pointsOnCurves) {
12164
+ let i = 0;
12165
+ while (i < points.length - 1) {
12166
+ segments.push(
12167
+ lineSegment6(
12168
+ pointFrom14(points[i][0], points[i][1]),
12169
+ pointFrom14(points[i + 1][0], points[i + 1][1])
12170
+ )
12171
+ );
12172
+ i++;
12173
+ }
12174
+ }
12175
+ } else {
12176
+ const points = pointsOnCurves.flat();
12177
+ let i = 0;
12178
+ while (i < points.length - 1) {
12179
+ segments.push(
12180
+ lineSegment6(
12181
+ pointFrom14(points[i][0], points[i][1]),
12182
+ pointFrom14(points[i + 1][0], points[i + 1][1])
12183
+ )
12184
+ );
12185
+ i++;
12186
+ }
12001
12187
  }
12002
12188
  return segments;
12003
12189
  } else if (shape.type === "polyline") {
@@ -12017,10 +12203,10 @@ var getElementLineSegments = (element, elementsMap) => {
12017
12203
  const container = getContainerElement(element, elementsMap);
12018
12204
  if (container && isLinearElement(container)) {
12019
12205
  const segments2 = [
12020
- lineSegment5(pointFrom12(x1, y1), pointFrom12(x2, y1)),
12021
- lineSegment5(pointFrom12(x2, y1), pointFrom12(x2, y2)),
12022
- lineSegment5(pointFrom12(x2, y2), pointFrom12(x1, y2)),
12023
- lineSegment5(pointFrom12(x1, y2), pointFrom12(x1, y1))
12206
+ lineSegment6(pointFrom14(x1, y1), pointFrom14(x2, y1)),
12207
+ lineSegment6(pointFrom14(x2, y1), pointFrom14(x2, y2)),
12208
+ lineSegment6(pointFrom14(x2, y2), pointFrom14(x1, y2)),
12209
+ lineSegment6(pointFrom14(x1, y2), pointFrom14(x1, y1))
12024
12210
  ];
12025
12211
  return segments2;
12026
12212
  }
@@ -12028,7 +12214,7 @@ var getElementLineSegments = (element, elementsMap) => {
12028
12214
  const points = shape.data;
12029
12215
  const segments = [];
12030
12216
  for (let i = 0; i < points.length - 1; i++) {
12031
- segments.push(lineSegment5(points[i], points[i + 1]));
12217
+ segments.push(lineSegment6(points[i], points[i + 1]));
12032
12218
  }
12033
12219
  return segments;
12034
12220
  } else if (shape.type === "ellipse") {
@@ -12043,16 +12229,16 @@ var getElementLineSegments = (element, elementsMap) => {
12043
12229
  [cx, y2],
12044
12230
  [x1, cy],
12045
12231
  [x2, cy]
12046
- ].map((point) => pointRotateRads10(point, center, element.angle));
12232
+ ].map((point) => pointRotateRads12(point, center, element.angle));
12047
12233
  return [
12048
- lineSegment5(nw, ne),
12049
- lineSegment5(sw, se2),
12050
- lineSegment5(nw, sw),
12051
- lineSegment5(ne, se2),
12052
- lineSegment5(nw, e),
12053
- lineSegment5(sw, e),
12054
- lineSegment5(ne, w),
12055
- lineSegment5(se2, w)
12234
+ lineSegment6(nw, ne),
12235
+ lineSegment6(sw, se2),
12236
+ lineSegment6(nw, sw),
12237
+ lineSegment6(ne, se2),
12238
+ lineSegment6(nw, e),
12239
+ lineSegment6(sw, e),
12240
+ lineSegment6(ne, w),
12241
+ lineSegment6(se2, w)
12056
12242
  ];
12057
12243
  };
12058
12244
  var _isRectanguloidElement = (element) => {
@@ -12060,9 +12246,9 @@ var _isRectanguloidElement = (element) => {
12060
12246
  };
12061
12247
  var getRotatedSides = (sides, center, angle) => {
12062
12248
  return sides.map((side) => {
12063
- return lineSegment5(
12064
- pointRotateRads10(side[0], center, angle),
12065
- pointRotateRads10(side[1], center, angle)
12249
+ return lineSegment6(
12250
+ pointRotateRads12(side[0], center, angle),
12251
+ pointRotateRads12(side[1], center, angle)
12066
12252
  );
12067
12253
  });
12068
12254
  };
@@ -12072,14 +12258,14 @@ var getSegmentsOnCurve = (curve4, center, angle) => {
12072
12258
  const segments = [];
12073
12259
  while (i < points.length - 1) {
12074
12260
  segments.push(
12075
- lineSegment5(
12076
- pointRotateRads10(
12077
- pointFrom12(points[i][0], points[i][1]),
12261
+ lineSegment6(
12262
+ pointRotateRads12(
12263
+ pointFrom14(points[i][0], points[i][1]),
12078
12264
  center,
12079
12265
  angle
12080
12266
  ),
12081
- pointRotateRads10(
12082
- pointFrom12(points[i + 1][0], points[i + 1][1]),
12267
+ pointRotateRads12(
12268
+ pointFrom14(points[i + 1][0], points[i + 1][1]),
12083
12269
  center,
12084
12270
  angle
12085
12271
  )
@@ -12090,7 +12276,7 @@ var getSegmentsOnCurve = (curve4, center, angle) => {
12090
12276
  return segments;
12091
12277
  };
12092
12278
  var getSegmentsOnEllipse = (ellipse4) => {
12093
- const center = pointFrom12(
12279
+ const center = pointFrom14(
12094
12280
  ellipse4.x + ellipse4.width / 2,
12095
12281
  ellipse4.y + ellipse4.height / 2
12096
12282
  );
@@ -12104,12 +12290,12 @@ var getSegmentsOnEllipse = (ellipse4) => {
12104
12290
  const t = i * deltaT;
12105
12291
  const x = center[0] + a2 * Math.cos(t);
12106
12292
  const y = center[1] + b2 * Math.sin(t);
12107
- points.push(pointRotateRads10(pointFrom12(x, y), center, ellipse4.angle));
12293
+ points.push(pointRotateRads12(pointFrom14(x, y), center, ellipse4.angle));
12108
12294
  }
12109
12295
  for (let i = 0; i < points.length - 1; i++) {
12110
- segments.push(lineSegment5(points[i], points[i + 1]));
12296
+ segments.push(lineSegment6(points[i], points[i + 1]));
12111
12297
  }
12112
- segments.push(lineSegment5(points[points.length - 1], points[0]));
12298
+ segments.push(lineSegment6(points[points.length - 1], points[0]));
12113
12299
  return segments;
12114
12300
  };
12115
12301
  var getRectangleBoxAbsoluteCoords = (boxSceneCoords) => {
@@ -12187,17 +12373,17 @@ var getCubicBezierCurveBound = (p0, p1, p2, p3) => {
12187
12373
  return [minX, minY, maxX, maxY];
12188
12374
  };
12189
12375
  var getMinMaxXYFromCurvePathOps = (ops, transformXY) => {
12190
- let currentP = pointFrom12(0, 0);
12376
+ let currentP = pointFrom14(0, 0);
12191
12377
  const { minX, minY, maxX, maxY } = ops.reduce(
12192
12378
  (limits, { op, data }) => {
12193
12379
  if (op === "move") {
12194
12380
  const p = pointFromArray3(data);
12195
- invariant7(p != null, "Op data is not a point");
12381
+ invariant8(p != null, "Op data is not a point");
12196
12382
  currentP = p;
12197
12383
  } else if (op === "bcurveTo") {
12198
- const _p1 = pointFrom12(data[0], data[1]);
12199
- const _p2 = pointFrom12(data[2], data[3]);
12200
- const _p3 = pointFrom12(data[4], data[5]);
12384
+ const _p1 = pointFrom14(data[0], data[1]);
12385
+ const _p2 = pointFrom14(data[2], data[3]);
12386
+ const _p3 = pointFrom14(data[4], data[5]);
12201
12387
  const p1 = transformXY ? transformXY(_p1) : _p1;
12202
12388
  const p2 = transformXY ? transformXY(_p2) : _p2;
12203
12389
  const p3 = transformXY ? transformXY(_p3) : _p3;
@@ -12278,18 +12464,18 @@ var getArrowheadPoints = (element, shape, position, arrowhead) => {
12278
12464
  }
12279
12465
  const index = position === "start" ? 1 : ops.length - 1;
12280
12466
  const data = ops[index].data;
12281
- invariant7(data.length === 6, "Op data length is not 6");
12282
- const p3 = pointFrom12(data[4], data[5]);
12283
- const p2 = pointFrom12(data[2], data[3]);
12284
- const p1 = pointFrom12(data[0], data[1]);
12467
+ invariant8(data.length === 6, "Op data length is not 6");
12468
+ const p3 = pointFrom14(data[4], data[5]);
12469
+ const p2 = pointFrom14(data[2], data[3]);
12470
+ const p1 = pointFrom14(data[0], data[1]);
12285
12471
  const prevOp = ops[index - 1];
12286
- let p0 = pointFrom12(0, 0);
12472
+ let p0 = pointFrom14(0, 0);
12287
12473
  if (prevOp.op === "move") {
12288
12474
  const p = pointFromArray3(prevOp.data);
12289
- invariant7(p != null, "Op data is not a point");
12475
+ invariant8(p != null, "Op data is not a point");
12290
12476
  p0 = p;
12291
12477
  } else if (prevOp.op === "bcurveTo") {
12292
- p0 = pointFrom12(prevOp.data[4], prevOp.data[5]);
12478
+ p0 = pointFrom14(prevOp.data[4], prevOp.data[5]);
12293
12479
  }
12294
12480
  const equation = (t, idx) => Math.pow(1 - t, 3) * p3[idx] + 3 * t * Math.pow(1 - t, 2) * p2[idx] + 3 * Math.pow(t, 2) * (1 - t) * p1[idx] + p0[idx] * Math.pow(t, 3);
12295
12481
  const [x2, y2] = position === "start" ? p0 : p3;
@@ -12314,26 +12500,26 @@ var getArrowheadPoints = (element, shape, position, arrowhead) => {
12314
12500
  }
12315
12501
  const angle = getArrowheadAngle(arrowhead);
12316
12502
  if (arrowhead === "crowfoot_many" || arrowhead === "crowfoot_one_or_many") {
12317
- const [x32, y32] = pointRotateRads10(
12318
- pointFrom12(x2, y2),
12319
- pointFrom12(xs, ys),
12503
+ const [x32, y32] = pointRotateRads12(
12504
+ pointFrom14(x2, y2),
12505
+ pointFrom14(xs, ys),
12320
12506
  degreesToRadians(-angle)
12321
12507
  );
12322
- const [x42, y42] = pointRotateRads10(
12323
- pointFrom12(x2, y2),
12324
- pointFrom12(xs, ys),
12508
+ const [x42, y42] = pointRotateRads12(
12509
+ pointFrom14(x2, y2),
12510
+ pointFrom14(xs, ys),
12325
12511
  degreesToRadians(angle)
12326
12512
  );
12327
12513
  return [xs, ys, x32, y32, x42, y42];
12328
12514
  }
12329
- const [x3, y3] = pointRotateRads10(
12330
- pointFrom12(xs, ys),
12331
- pointFrom12(x2, y2),
12515
+ const [x3, y3] = pointRotateRads12(
12516
+ pointFrom14(xs, ys),
12517
+ pointFrom14(x2, y2),
12332
12518
  -angle * Math.PI / 180
12333
12519
  );
12334
- const [x4, y4] = pointRotateRads10(
12335
- pointFrom12(xs, ys),
12336
- pointFrom12(x2, y2),
12520
+ const [x4, y4] = pointRotateRads12(
12521
+ pointFrom14(xs, ys),
12522
+ pointFrom14(x2, y2),
12337
12523
  degreesToRadians(angle)
12338
12524
  );
12339
12525
  if (arrowhead === "diamond" || arrowhead === "diamond_outline") {
@@ -12341,16 +12527,16 @@ var getArrowheadPoints = (element, shape, position, arrowhead) => {
12341
12527
  let oy;
12342
12528
  if (position === "start") {
12343
12529
  const [px, py] = element.points.length > 1 ? element.points[1] : [0, 0];
12344
- [ox, oy] = pointRotateRads10(
12345
- pointFrom12(x2 + minSize * 2, y2),
12346
- pointFrom12(x2, y2),
12530
+ [ox, oy] = pointRotateRads12(
12531
+ pointFrom14(x2 + minSize * 2, y2),
12532
+ pointFrom14(x2, y2),
12347
12533
  Math.atan2(py - y2, px - x2)
12348
12534
  );
12349
12535
  } else {
12350
12536
  const [px, py] = element.points.length > 1 ? element.points[element.points.length - 2] : [0, 0];
12351
- [ox, oy] = pointRotateRads10(
12352
- pointFrom12(x2 - minSize * 2, y2),
12353
- pointFrom12(x2, y2),
12537
+ [ox, oy] = pointRotateRads12(
12538
+ pointFrom14(x2 - minSize * 2, y2),
12539
+ pointFrom14(x2, y2),
12354
12540
  Math.atan2(y2 - py, x2 - px)
12355
12541
  );
12356
12542
  }
@@ -12379,9 +12565,9 @@ var getLinearElementRotatedBounds = (element, cx, cy, elementsMap) => {
12379
12565
  const boundTextElement = getBoundTextElement(element, elementsMap);
12380
12566
  if (element.points.length < 2) {
12381
12567
  const [pointX, pointY] = element.points[0];
12382
- const [x, y] = pointRotateRads10(
12383
- pointFrom12(element.x + pointX, element.y + pointY),
12384
- pointFrom12(cx, cy),
12568
+ const [x, y] = pointRotateRads12(
12569
+ pointFrom14(element.x + pointX, element.y + pointY),
12570
+ pointFrom14(cx, cy),
12385
12571
  element.angle
12386
12572
  );
12387
12573
  let coords2 = [x, y, x, y];
@@ -12404,9 +12590,9 @@ var getLinearElementRotatedBounds = (element, cx, cy, elementsMap) => {
12404
12590
  const cachedShape = ShapeCache.get(element)?.[0];
12405
12591
  const shape = cachedShape ?? generateLinearElementShape(element);
12406
12592
  const ops = getCurvePathOps(shape);
12407
- const transformXY = ([x, y]) => pointRotateRads10(
12408
- pointFrom12(element.x + x, element.y + y),
12409
- pointFrom12(cx, cy),
12593
+ const transformXY = ([x, y]) => pointRotateRads12(
12594
+ pointFrom14(element.x + x, element.y + y),
12595
+ pointFrom14(cx, cy),
12410
12596
  element.angle
12411
12597
  );
12412
12598
  const res = getMinMaxXYFromCurvePathOps(ops, transformXY);
@@ -12517,8 +12703,8 @@ var getClosestElementBounds = (elements, from) => {
12517
12703
  elements.forEach((element) => {
12518
12704
  const [x1, y1, x2, y2] = getElementBounds(element, elementsMap);
12519
12705
  const distance3 = pointDistance7(
12520
- pointFrom12((x1 + x2) / 2, (y1 + y2) / 2),
12521
- pointFrom12(from.x, from.y)
12706
+ pointFrom14((x1 + x2) / 2, (y1 + y2) / 2),
12707
+ pointFrom14(from.x, from.y)
12522
12708
  );
12523
12709
  if (distance3 < minDistance) {
12524
12710
  minDistance = distance3;
@@ -12554,7 +12740,7 @@ var getVisibleSceneBounds = ({
12554
12740
  -scrollY + height / zoom.value
12555
12741
  ];
12556
12742
  };
12557
- var getCenterForBounds = (bounds) => pointFrom12(
12743
+ var getCenterForBounds = (bounds) => pointFrom14(
12558
12744
  bounds[0] + (bounds[2] - bounds[0]) / 2,
12559
12745
  bounds[1] + (bounds[3] - bounds[1]) / 2
12560
12746
  );
@@ -12568,23 +12754,23 @@ var aabbForElement = (element, elementsMap, offset) => {
12568
12754
  midY: element.y + element.height / 2
12569
12755
  };
12570
12756
  const center = elementCenterPoint(element, elementsMap);
12571
- const [topLeftX, topLeftY] = pointRotateRads10(
12572
- pointFrom12(bbox.minX, bbox.minY),
12757
+ const [topLeftX, topLeftY] = pointRotateRads12(
12758
+ pointFrom14(bbox.minX, bbox.minY),
12573
12759
  center,
12574
12760
  element.angle
12575
12761
  );
12576
- const [topRightX, topRightY] = pointRotateRads10(
12577
- pointFrom12(bbox.maxX, bbox.minY),
12762
+ const [topRightX, topRightY] = pointRotateRads12(
12763
+ pointFrom14(bbox.maxX, bbox.minY),
12578
12764
  center,
12579
12765
  element.angle
12580
12766
  );
12581
- const [bottomRightX, bottomRightY] = pointRotateRads10(
12582
- pointFrom12(bbox.maxX, bbox.maxY),
12767
+ const [bottomRightX, bottomRightY] = pointRotateRads12(
12768
+ pointFrom14(bbox.maxX, bbox.maxY),
12583
12769
  center,
12584
12770
  element.angle
12585
12771
  );
12586
- const [bottomLeftX, bottomLeftY] = pointRotateRads10(
12587
- pointFrom12(bbox.minX, bbox.maxY),
12772
+ const [bottomLeftX, bottomLeftY] = pointRotateRads12(
12773
+ pointFrom14(bbox.minX, bbox.maxY),
12588
12774
  center,
12589
12775
  element.angle
12590
12776
  );
@@ -12616,7 +12802,7 @@ var doBoundsIntersect = (bounds1, bounds2) => {
12616
12802
  };
12617
12803
  var elementCenterPoint = (element, elementsMap, xOffset = 0, yOffset = 0) => {
12618
12804
  const [x, y] = getCenterForBounds(getElementBounds(element, elementsMap));
12619
- return pointFrom12(x + xOffset, y + yOffset);
12805
+ return pointFrom14(x + xOffset, y + yOffset);
12620
12806
  };
12621
12807
 
12622
12808
  // src/sizeHelpers.ts
@@ -12745,11 +12931,11 @@ var getNormalizedDimensions = (element) => {
12745
12931
 
12746
12932
  // src/align.ts
12747
12933
  init_define_import_meta_env();
12748
- var alignElements = (selectedElements, alignment, scene) => {
12749
- const elementsMap = scene.getNonDeletedElementsMap();
12750
- const groups = getMaximumGroups(
12934
+ var alignElements = (selectedElements, alignment, scene, appState) => {
12935
+ const groups = getSelectedElementsByGroup(
12751
12936
  selectedElements,
12752
- elementsMap
12937
+ scene.getNonDeletedElementsMap(),
12938
+ appState
12753
12939
  );
12754
12940
  const selectionBoundingBox = getCommonBoundingBox(selectedElements);
12755
12941
  return groups.flatMap((group) => {
@@ -13185,8 +13371,9 @@ var Store = class {
13185
13371
  constructor(app) {
13186
13372
  this.app = app;
13187
13373
  }
13188
- // internally used by history
13374
+ // for internal use by history
13189
13375
  onDurableIncrementEmitter = new Emitter();
13376
+ // for public use as part of onIncrement API
13190
13377
  onStoreIncrementEmitter = new Emitter();
13191
13378
  scheduledMacroActions = /* @__PURE__ */ new Set();
13192
13379
  scheduledMicroActions = [];
@@ -13442,7 +13629,7 @@ var EphemeralIncrement = class extends StoreIncrement {
13442
13629
  this.change = change;
13443
13630
  }
13444
13631
  };
13445
- var StoreDelta = class {
13632
+ var StoreDelta = class _StoreDelta {
13446
13633
  constructor(id, elements, appState) {
13447
13634
  this.id = id;
13448
13635
  this.elements = elements;
@@ -13480,10 +13667,23 @@ var StoreDelta = class {
13480
13667
  */
13481
13668
  static load({
13482
13669
  id,
13483
- elements: { added, removed, updated }
13670
+ elements: { added, removed, updated },
13671
+ appState: { delta: appStateDelta }
13484
13672
  }) {
13485
13673
  const elements = ElementsDelta.create(added, removed, updated);
13486
- return new this(id, elements, AppStateDelta.empty());
13674
+ const appState = AppStateDelta.create(appStateDelta);
13675
+ return new this(id, elements, appState);
13676
+ }
13677
+ /**
13678
+ * Squash the passed deltas into the aggregated delta instance.
13679
+ */
13680
+ static squash(...deltas) {
13681
+ const aggregatedDelta = _StoreDelta.empty();
13682
+ for (const delta of deltas) {
13683
+ aggregatedDelta.elements.squash(delta.elements);
13684
+ aggregatedDelta.appState.squash(delta.appState);
13685
+ }
13686
+ return aggregatedDelta;
13487
13687
  }
13488
13688
  /**
13489
13689
  * Inverse store delta, creates new instance of `StoreDelta`.
@@ -13494,9 +13694,7 @@ var StoreDelta = class {
13494
13694
  /**
13495
13695
  * Apply the delta to the passed elements and appState, does not modify the snapshot.
13496
13696
  */
13497
- static applyTo(delta, elements, appState, options = {
13498
- excludedProperties: /* @__PURE__ */ new Set()
13499
- }) {
13697
+ static applyTo(delta, elements, appState, options) {
13500
13698
  const [nextElements, elementsContainVisibleChange] = delta.elements.applyTo(
13501
13699
  elements,
13502
13700
  StoreSnapshot.empty().elements,
@@ -13522,6 +13720,9 @@ var StoreDelta = class {
13522
13720
  }
13523
13721
  );
13524
13722
  }
13723
+ static empty() {
13724
+ return _StoreDelta.create(ElementsDelta.empty(), AppStateDelta.empty());
13725
+ }
13525
13726
  isEmpty() {
13526
13727
  return this.elements.isEmpty() && this.appState.isEmpty();
13527
13728
  }
@@ -13762,8 +13963,7 @@ var getDefaultObservedAppState = () => {
13762
13963
  viewBackgroundColor: COLOR_PALETTE2.white,
13763
13964
  selectedElementIds: {},
13764
13965
  selectedGroupIds: {},
13765
- editingLinearElementId: null,
13766
- selectedLinearElementId: null,
13966
+ selectedLinearElement: null,
13767
13967
  croppingElementId: null,
13768
13968
  activeLockedId: null,
13769
13969
  lockedMultiSelections: {}
@@ -13779,10 +13979,10 @@ var getObservedAppState = (appState) => {
13779
13979
  croppingElementId: appState.croppingElementId,
13780
13980
  activeLockedId: appState.activeLockedId,
13781
13981
  lockedMultiSelections: appState.lockedMultiSelections,
13782
- editingLinearElementId: appState.editingLinearElement?.elementId ?? // prefer app state, as it's likely newer
13783
- appState.editingLinearElementId ?? // fallback to observed app state, as it's likely older coming from a previous snapshot
13784
- null,
13785
- selectedLinearElementId: appState.selectedLinearElement?.elementId ?? appState.selectedLinearElementId ?? null
13982
+ selectedLinearElement: appState.selectedLinearElement ? {
13983
+ elementId: appState.selectedLinearElement.elementId,
13984
+ isEditing: !!appState.selectedLinearElement.isEditing
13985
+ } : null
13786
13986
  };
13787
13987
  Reflect.defineProperty(observedAppState, hiddenObservedAppStateProp, {
13788
13988
  value: true,
@@ -14346,9 +14546,9 @@ var Scene = class {
14346
14546
  getFramesIncludingDeleted() {
14347
14547
  return this.frames;
14348
14548
  }
14349
- constructor(elements = null) {
14549
+ constructor(elements = null, options) {
14350
14550
  if (elements) {
14351
- this.replaceAllElements(elements);
14551
+ this.replaceAllElements(elements, options);
14352
14552
  }
14353
14553
  }
14354
14554
  getSelectedElements(opts) {
@@ -14413,10 +14613,12 @@ var Scene = class {
14413
14613
  }
14414
14614
  return didChange;
14415
14615
  }
14416
- replaceAllElements(nextElements) {
14616
+ replaceAllElements(nextElements, options) {
14417
14617
  const _nextElements = toArray(nextElements);
14418
14618
  const nextFrameLikes = [];
14419
- validateIndicesThrottled(_nextElements);
14619
+ if (!options?.skipValidation) {
14620
+ validateIndicesThrottled(_nextElements);
14621
+ }
14420
14622
  this.elements = syncInvalidIndices2(_nextElements);
14421
14623
  this.elementsMap.clear();
14422
14624
  this.elements.forEach((element) => {
@@ -14586,10 +14788,19 @@ var Delta = class _Delta {
14586
14788
  static isEmpty(delta) {
14587
14789
  return !Object.keys(delta.deleted).length && !Object.keys(delta.inserted).length;
14588
14790
  }
14791
+ /**
14792
+ * Merges two deltas into a new one.
14793
+ */
14794
+ static merge(delta1, delta2, delta3 = _Delta.empty()) {
14795
+ return _Delta.create(
14796
+ { ...delta1.deleted, ...delta2.deleted, ...delta3.deleted },
14797
+ { ...delta1.inserted, ...delta2.inserted, ...delta3.inserted }
14798
+ );
14799
+ }
14589
14800
  /**
14590
14801
  * Merges deleted and inserted object partials.
14591
14802
  */
14592
- static mergeObjects(prev, added, removed) {
14803
+ static mergeObjects(prev, added, removed = {}) {
14593
14804
  const cloned = { ...prev };
14594
14805
  for (const key of Object.keys(removed)) {
14595
14806
  delete cloned[key];
@@ -14810,6 +15021,9 @@ var AppStateDelta = class _AppStateDelta {
14810
15021
  constructor(delta) {
14811
15022
  this.delta = delta;
14812
15023
  }
15024
+ static create(delta) {
15025
+ return new _AppStateDelta(delta);
15026
+ }
14813
15027
  static calculate(prevAppState, nextAppState) {
14814
15028
  const delta = Delta.calculate(
14815
15029
  prevAppState,
@@ -14831,50 +15045,98 @@ var AppStateDelta = class _AppStateDelta {
14831
15045
  const inversedDelta = Delta.create(this.delta.inserted, this.delta.deleted);
14832
15046
  return new _AppStateDelta(inversedDelta);
14833
15047
  }
15048
+ squash(delta) {
15049
+ if (delta.isEmpty()) {
15050
+ return this;
15051
+ }
15052
+ const mergedDeletedSelectedElementIds = Delta.mergeObjects(
15053
+ this.delta.deleted.selectedElementIds ?? {},
15054
+ delta.delta.deleted.selectedElementIds ?? {}
15055
+ );
15056
+ const mergedInsertedSelectedElementIds = Delta.mergeObjects(
15057
+ this.delta.inserted.selectedElementIds ?? {},
15058
+ delta.delta.inserted.selectedElementIds ?? {}
15059
+ );
15060
+ const mergedDeletedSelectedGroupIds = Delta.mergeObjects(
15061
+ this.delta.deleted.selectedGroupIds ?? {},
15062
+ delta.delta.deleted.selectedGroupIds ?? {}
15063
+ );
15064
+ const mergedInsertedSelectedGroupIds = Delta.mergeObjects(
15065
+ this.delta.inserted.selectedGroupIds ?? {},
15066
+ delta.delta.inserted.selectedGroupIds ?? {}
15067
+ );
15068
+ const mergedDeletedLockedMultiSelections = Delta.mergeObjects(
15069
+ this.delta.deleted.lockedMultiSelections ?? {},
15070
+ delta.delta.deleted.lockedMultiSelections ?? {}
15071
+ );
15072
+ const mergedInsertedLockedMultiSelections = Delta.mergeObjects(
15073
+ this.delta.inserted.lockedMultiSelections ?? {},
15074
+ delta.delta.inserted.lockedMultiSelections ?? {}
15075
+ );
15076
+ const mergedInserted = {};
15077
+ const mergedDeleted = {};
15078
+ if (Object.keys(mergedDeletedSelectedElementIds).length || Object.keys(mergedInsertedSelectedElementIds).length) {
15079
+ mergedDeleted.selectedElementIds = mergedDeletedSelectedElementIds;
15080
+ mergedInserted.selectedElementIds = mergedInsertedSelectedElementIds;
15081
+ }
15082
+ if (Object.keys(mergedDeletedSelectedGroupIds).length || Object.keys(mergedInsertedSelectedGroupIds).length) {
15083
+ mergedDeleted.selectedGroupIds = mergedDeletedSelectedGroupIds;
15084
+ mergedInserted.selectedGroupIds = mergedInsertedSelectedGroupIds;
15085
+ }
15086
+ if (Object.keys(mergedDeletedLockedMultiSelections).length || Object.keys(mergedInsertedLockedMultiSelections).length) {
15087
+ mergedDeleted.lockedMultiSelections = mergedDeletedLockedMultiSelections;
15088
+ mergedInserted.lockedMultiSelections = mergedInsertedLockedMultiSelections;
15089
+ }
15090
+ this.delta = Delta.merge(
15091
+ this.delta,
15092
+ delta.delta,
15093
+ Delta.create(mergedDeleted, mergedInserted)
15094
+ );
15095
+ return this;
15096
+ }
14834
15097
  applyTo(appState, nextElements) {
14835
15098
  try {
14836
15099
  const {
14837
- selectedElementIds: removedSelectedElementIds = {},
14838
- selectedGroupIds: removedSelectedGroupIds = {}
15100
+ selectedElementIds: deletedSelectedElementIds = {},
15101
+ selectedGroupIds: deletedSelectedGroupIds = {},
15102
+ lockedMultiSelections: deletedLockedMultiSelections = {}
14839
15103
  } = this.delta.deleted;
14840
15104
  const {
14841
- selectedElementIds: addedSelectedElementIds = {},
14842
- selectedGroupIds: addedSelectedGroupIds = {},
14843
- selectedLinearElementId,
14844
- editingLinearElementId,
15105
+ selectedElementIds: insertedSelectedElementIds = {},
15106
+ selectedGroupIds: insertedSelectedGroupIds = {},
15107
+ lockedMultiSelections: insertedLockedMultiSelections = {},
15108
+ selectedLinearElement: insertedSelectedLinearElement,
14845
15109
  ...directlyApplicablePartial
14846
15110
  } = this.delta.inserted;
14847
15111
  const mergedSelectedElementIds = Delta.mergeObjects(
14848
15112
  appState.selectedElementIds,
14849
- addedSelectedElementIds,
14850
- removedSelectedElementIds
15113
+ insertedSelectedElementIds,
15114
+ deletedSelectedElementIds
14851
15115
  );
14852
15116
  const mergedSelectedGroupIds = Delta.mergeObjects(
14853
15117
  appState.selectedGroupIds,
14854
- addedSelectedGroupIds,
14855
- removedSelectedGroupIds
15118
+ insertedSelectedGroupIds,
15119
+ deletedSelectedGroupIds
14856
15120
  );
14857
- const selectedLinearElement = selectedLinearElementId && nextElements.has(selectedLinearElementId) ? new LinearElementEditor(
14858
- nextElements.get(
14859
- selectedLinearElementId
14860
- ),
14861
- nextElements
14862
- ) : null;
14863
- const editingLinearElement = editingLinearElementId && nextElements.has(editingLinearElementId) ? new LinearElementEditor(
15121
+ const mergedLockedMultiSelections = Delta.mergeObjects(
15122
+ appState.lockedMultiSelections,
15123
+ insertedLockedMultiSelections,
15124
+ deletedLockedMultiSelections
15125
+ );
15126
+ const selectedLinearElement = insertedSelectedLinearElement && nextElements.has(insertedSelectedLinearElement.elementId) ? new LinearElementEditor(
14864
15127
  nextElements.get(
14865
- editingLinearElementId
15128
+ insertedSelectedLinearElement.elementId
14866
15129
  ),
14867
- nextElements
15130
+ nextElements,
15131
+ insertedSelectedLinearElement.isEditing
14868
15132
  ) : null;
14869
15133
  const nextAppState = {
14870
15134
  ...appState,
14871
15135
  ...directlyApplicablePartial,
14872
15136
  selectedElementIds: mergedSelectedElementIds,
14873
15137
  selectedGroupIds: mergedSelectedGroupIds,
14874
- selectedLinearElement: typeof selectedLinearElementId !== "undefined" ? selectedLinearElement : appState.selectedLinearElement,
14875
- // otherwise assign what we had before
14876
- editingLinearElement: typeof editingLinearElementId !== "undefined" ? editingLinearElement : appState.editingLinearElement
14877
- // otherwise assign what we had before
15138
+ lockedMultiSelections: mergedLockedMultiSelections,
15139
+ selectedLinearElement: typeof insertedSelectedLinearElement !== "undefined" ? selectedLinearElement : appState.selectedLinearElement
14878
15140
  };
14879
15141
  const constainsVisibleChanges = this.filterInvisibleChanges(
14880
15142
  appState,
@@ -14964,57 +15226,44 @@ var AppStateDelta = class _AppStateDelta {
14964
15226
  nextAppState[key] = null;
14965
15227
  }
14966
15228
  break;
14967
- case "selectedLinearElementId":
14968
- case "editingLinearElementId":
14969
- const appStateKey = _AppStateDelta.convertToAppStateKey(key);
14970
- const linearElement = nextAppState[appStateKey];
14971
- if (!linearElement) {
15229
+ case "selectedLinearElement":
15230
+ const nextLinearElement = nextAppState[key];
15231
+ if (!nextLinearElement) {
14972
15232
  visibleDifferenceFlag.value = true;
14973
15233
  } else {
14974
- const element = nextElements.get(linearElement.elementId);
15234
+ const element = nextElements.get(nextLinearElement.elementId);
14975
15235
  if (element && !element.isDeleted) {
14976
15236
  visibleDifferenceFlag.value = true;
14977
15237
  } else {
14978
- nextAppState[appStateKey] = null;
15238
+ nextAppState[key] = null;
14979
15239
  }
14980
15240
  }
14981
15241
  break;
14982
- case "lockedMultiSelections": {
15242
+ case "lockedMultiSelections":
14983
15243
  const prevLockedUnits = prevAppState[key] || {};
14984
15244
  const nextLockedUnits = nextAppState[key] || {};
14985
15245
  if (!isShallowEqual2(prevLockedUnits, nextLockedUnits)) {
14986
15246
  visibleDifferenceFlag.value = true;
14987
15247
  }
14988
15248
  break;
14989
- }
14990
- case "activeLockedId": {
15249
+ case "activeLockedId":
14991
15250
  const prevHitLockedId = prevAppState[key] || null;
14992
15251
  const nextHitLockedId = nextAppState[key] || null;
14993
15252
  if (prevHitLockedId !== nextHitLockedId) {
14994
15253
  visibleDifferenceFlag.value = true;
14995
15254
  }
14996
15255
  break;
14997
- }
14998
- default: {
15256
+ default:
14999
15257
  assertNever4(
15000
15258
  key,
15001
15259
  `Unknown ObservedElementsAppState's key "${key}"`,
15002
15260
  true
15003
15261
  );
15004
- }
15005
15262
  }
15006
15263
  }
15007
15264
  }
15008
15265
  return visibleDifferenceFlag.value;
15009
15266
  }
15010
- static convertToAppStateKey(key) {
15011
- switch (key) {
15012
- case "selectedLinearElementId":
15013
- return "selectedLinearElement";
15014
- case "editingLinearElementId":
15015
- return "editingLinearElement";
15016
- }
15017
- }
15018
15267
  static filterSelectedElements(selectedElementIds, elements, visibleDifferenceFlag) {
15019
15268
  const ids = Object.keys(selectedElementIds);
15020
15269
  if (!ids.length) {
@@ -15053,8 +15302,7 @@ var AppStateDelta = class _AppStateDelta {
15053
15302
  editingGroupId,
15054
15303
  selectedGroupIds,
15055
15304
  selectedElementIds,
15056
- editingLinearElementId,
15057
- selectedLinearElementId,
15305
+ selectedLinearElement,
15058
15306
  croppingElementId,
15059
15307
  lockedMultiSelections,
15060
15308
  activeLockedId,
@@ -15091,12 +15339,6 @@ var AppStateDelta = class _AppStateDelta {
15091
15339
  "lockedMultiSelections",
15092
15340
  (prevValue) => prevValue ?? {}
15093
15341
  );
15094
- Delta.diffObjects(
15095
- deleted,
15096
- inserted,
15097
- "activeLockedId",
15098
- (prevValue) => prevValue ?? null
15099
- );
15100
15342
  } catch (e) {
15101
15343
  console.error(`Couldn't postprocess appstate change deltas.`);
15102
15344
  if (isTestEnv8() || isDevEnv7()) {
@@ -15175,13 +15417,17 @@ var ElementsDelta = class _ElementsDelta {
15175
15417
  static satisfiesCommmonInvariants = ({
15176
15418
  deleted,
15177
15419
  inserted
15178
- }) => !!(deleted.version && inserted.version && // versions are required integers
15179
- Number.isInteger(deleted.version) && Number.isInteger(inserted.version) && // versions should be positive, zero included
15420
+ }) => !!// versions are required integers
15421
+ (Number.isInteger(deleted.version) && Number.isInteger(inserted.version) && // versions should be positive, zero included
15180
15422
  deleted.version >= 0 && inserted.version >= 0 && // versions should never be the same
15181
15423
  deleted.version !== inserted.version);
15424
+ static satisfiesUniqueInvariants = (elementsDelta, id) => {
15425
+ const { added, removed, updated } = elementsDelta;
15426
+ return [added[id], removed[id], updated[id]].filter(Boolean).length === 1;
15427
+ };
15182
15428
  static validate(elementsDelta, type, satifiesSpecialInvariants) {
15183
15429
  for (const [id, delta] of Object.entries(elementsDelta[type])) {
15184
- if (!this.satisfiesCommmonInvariants(delta) || !satifiesSpecialInvariants(delta)) {
15430
+ if (!this.satisfiesCommmonInvariants(delta) || !this.satisfiesUniqueInvariants(elementsDelta, id) || !satifiesSpecialInvariants(delta)) {
15185
15431
  console.error(
15186
15432
  `Broken invariant for "${type}" delta, element "${id}", delta:`,
15187
15433
  delta
@@ -15208,7 +15454,7 @@ var ElementsDelta = class _ElementsDelta {
15208
15454
  for (const prevElement of prevElements.values()) {
15209
15455
  const nextElement = nextElements.get(prevElement.id);
15210
15456
  if (!nextElement) {
15211
- const deleted = { ...prevElement, isDeleted: false };
15457
+ const deleted = { ...prevElement };
15212
15458
  const inserted = {
15213
15459
  isDeleted: true,
15214
15460
  version: prevElement.version + 1,
@@ -15219,7 +15465,11 @@ var ElementsDelta = class _ElementsDelta {
15219
15465
  inserted,
15220
15466
  _ElementsDelta.stripIrrelevantProps
15221
15467
  );
15222
- removed[prevElement.id] = delta;
15468
+ if (!prevElement.isDeleted) {
15469
+ removed[prevElement.id] = delta;
15470
+ } else {
15471
+ updated[prevElement.id] = delta;
15472
+ }
15223
15473
  }
15224
15474
  }
15225
15475
  for (const nextElement of nextElements.values()) {
@@ -15231,15 +15481,18 @@ var ElementsDelta = class _ElementsDelta {
15231
15481
  versionNonce: randomInteger4()
15232
15482
  };
15233
15483
  const inserted = {
15234
- ...nextElement,
15235
- isDeleted: false
15484
+ ...nextElement
15236
15485
  };
15237
15486
  const delta = Delta.create(
15238
15487
  deleted,
15239
15488
  inserted,
15240
15489
  _ElementsDelta.stripIrrelevantProps
15241
15490
  );
15242
- added[nextElement.id] = delta;
15491
+ if (!nextElement.isDeleted) {
15492
+ added[nextElement.id] = delta;
15493
+ } else {
15494
+ updated[nextElement.id] = delta;
15495
+ }
15243
15496
  continue;
15244
15497
  }
15245
15498
  if (prevElement.versionNonce !== nextElement.versionNonce) {
@@ -15260,9 +15513,7 @@ var ElementsDelta = class _ElementsDelta {
15260
15513
  }
15261
15514
  continue;
15262
15515
  }
15263
- if (!Delta.isEmpty(delta)) {
15264
- updated[nextElement.id] = delta;
15265
- }
15516
+ updated[nextElement.id] = delta;
15266
15517
  }
15267
15518
  }
15268
15519
  return _ElementsDelta.create(added, removed, updated);
@@ -15273,8 +15524,8 @@ var ElementsDelta = class _ElementsDelta {
15273
15524
  inverse() {
15274
15525
  const inverseInternal = (deltas) => {
15275
15526
  const inversedDeltas = {};
15276
- for (const [id, delta] of Object.entries(deltas)) {
15277
- inversedDeltas[id] = Delta.create(delta.inserted, delta.deleted);
15527
+ for (const [id, { inserted, deleted }] of Object.entries(deltas)) {
15528
+ inversedDeltas[id] = Delta.create({ ...inserted }, { ...deleted });
15278
15529
  }
15279
15530
  return inversedDeltas;
15280
15531
  };
@@ -15352,26 +15603,30 @@ var ElementsDelta = class _ElementsDelta {
15352
15603
  // redistribute the deltas as `isDeleted` could have been updated
15353
15604
  });
15354
15605
  }
15355
- applyTo(elements, snapshot = StoreSnapshot.empty().elements, options = {
15356
- excludedProperties: /* @__PURE__ */ new Set()
15357
- }) {
15606
+ applyTo(elements, snapshot = StoreSnapshot.empty().elements, options) {
15358
15607
  let nextElements = new Map(elements);
15359
15608
  let changedElements;
15360
15609
  const flags = {
15361
15610
  containsVisibleDifference: false,
15362
- containsZindexDifference: false
15611
+ containsZindexDifference: false,
15612
+ applyDirection: void 0
15363
15613
  };
15364
15614
  try {
15365
15615
  const applyDeltas = _ElementsDelta.createApplier(
15616
+ elements,
15366
15617
  nextElements,
15367
15618
  snapshot,
15368
- options,
15369
- flags
15619
+ flags,
15620
+ options
15370
15621
  );
15371
15622
  const addedElements = applyDeltas(this.added);
15372
15623
  const removedElements = applyDeltas(this.removed);
15373
15624
  const updatedElements = applyDeltas(this.updated);
15374
- const affectedElements = this.resolveConflicts(elements, nextElements);
15625
+ const affectedElements = this.resolveConflicts(
15626
+ elements,
15627
+ nextElements,
15628
+ flags.applyDirection
15629
+ );
15375
15630
  changedElements = new Map([
15376
15631
  ...addedElements,
15377
15632
  ...removedElements,
@@ -15391,9 +15646,7 @@ var ElementsDelta = class _ElementsDelta {
15391
15646
  changedElements,
15392
15647
  flags
15393
15648
  );
15394
- const tempScene = new Scene(nextElements);
15395
- _ElementsDelta.redrawTextBoundingBoxes(tempScene, changedElements);
15396
- _ElementsDelta.redrawBoundArrows(tempScene, changedElements);
15649
+ _ElementsDelta.redrawElements(nextElements, changedElements);
15397
15650
  } catch (e) {
15398
15651
  console.error(
15399
15652
  `Couldn't mutate elements after applying elements change`,
@@ -15406,7 +15659,82 @@ var ElementsDelta = class _ElementsDelta {
15406
15659
  return [nextElements, flags.containsVisibleDifference];
15407
15660
  }
15408
15661
  }
15409
- static createApplier = (nextElements, snapshot, options, flags) => (deltas) => {
15662
+ squash(delta) {
15663
+ if (delta.isEmpty()) {
15664
+ return this;
15665
+ }
15666
+ const { added, removed, updated } = delta;
15667
+ const mergeBoundElements = (prevDelta, nextDelta) => {
15668
+ const mergedDeletedBoundElements = Delta.mergeArrays(
15669
+ prevDelta.deleted.boundElements ?? [],
15670
+ nextDelta.deleted.boundElements ?? [],
15671
+ void 0,
15672
+ (x) => x.id
15673
+ ) ?? [];
15674
+ const mergedInsertedBoundElements = Delta.mergeArrays(
15675
+ prevDelta.inserted.boundElements ?? [],
15676
+ nextDelta.inserted.boundElements ?? [],
15677
+ void 0,
15678
+ (x) => x.id
15679
+ ) ?? [];
15680
+ if (!mergedDeletedBoundElements.length && !mergedInsertedBoundElements.length) {
15681
+ return;
15682
+ }
15683
+ return Delta.create(
15684
+ {
15685
+ boundElements: mergedDeletedBoundElements
15686
+ },
15687
+ {
15688
+ boundElements: mergedInsertedBoundElements
15689
+ }
15690
+ );
15691
+ };
15692
+ for (const [id, nextDelta] of Object.entries(added)) {
15693
+ const prevDelta = this.added[id] ?? this.removed[id] ?? this.updated[id];
15694
+ if (!prevDelta) {
15695
+ this.added[id] = nextDelta;
15696
+ } else {
15697
+ const mergedDelta = mergeBoundElements(prevDelta, nextDelta);
15698
+ delete this.removed[id];
15699
+ delete this.updated[id];
15700
+ this.added[id] = Delta.merge(prevDelta, nextDelta, mergedDelta);
15701
+ }
15702
+ }
15703
+ for (const [id, nextDelta] of Object.entries(removed)) {
15704
+ const prevDelta = this.added[id] ?? this.removed[id] ?? this.updated[id];
15705
+ if (!prevDelta) {
15706
+ this.removed[id] = nextDelta;
15707
+ } else {
15708
+ const mergedDelta = mergeBoundElements(prevDelta, nextDelta);
15709
+ delete this.added[id];
15710
+ delete this.updated[id];
15711
+ this.removed[id] = Delta.merge(prevDelta, nextDelta, mergedDelta);
15712
+ }
15713
+ }
15714
+ for (const [id, nextDelta] of Object.entries(updated)) {
15715
+ const prevDelta = this.added[id] ?? this.removed[id] ?? this.updated[id];
15716
+ if (!prevDelta) {
15717
+ this.updated[id] = nextDelta;
15718
+ } else {
15719
+ const mergedDelta = mergeBoundElements(prevDelta, nextDelta);
15720
+ const updatedDelta = Delta.merge(prevDelta, nextDelta, mergedDelta);
15721
+ if (prevDelta === this.added[id]) {
15722
+ this.added[id] = updatedDelta;
15723
+ } else if (prevDelta === this.removed[id]) {
15724
+ this.removed[id] = updatedDelta;
15725
+ } else {
15726
+ this.updated[id] = updatedDelta;
15727
+ }
15728
+ }
15729
+ }
15730
+ if (isTestEnv8() || isDevEnv7()) {
15731
+ _ElementsDelta.validate(this, "added", _ElementsDelta.satisfiesAddition);
15732
+ _ElementsDelta.validate(this, "removed", _ElementsDelta.satisfiesRemoval);
15733
+ _ElementsDelta.validate(this, "updated", _ElementsDelta.satisfiesUpdate);
15734
+ }
15735
+ return this;
15736
+ }
15737
+ static createApplier = (prevElements, nextElements, snapshot, flags, options) => (deltas) => {
15410
15738
  const getElement = _ElementsDelta.createGetter(
15411
15739
  nextElements,
15412
15740
  snapshot,
@@ -15415,14 +15743,20 @@ var ElementsDelta = class _ElementsDelta {
15415
15743
  return Object.entries(deltas).reduce((acc, [id, delta]) => {
15416
15744
  const element = getElement(id, delta.inserted);
15417
15745
  if (element) {
15418
- const newElement2 = _ElementsDelta.applyDelta(
15746
+ const nextElement = _ElementsDelta.applyDelta(
15419
15747
  element,
15420
15748
  delta,
15421
- options,
15422
- flags
15749
+ flags,
15750
+ options
15423
15751
  );
15424
- nextElements.set(newElement2.id, newElement2);
15425
- acc.set(newElement2.id, newElement2);
15752
+ nextElements.set(nextElement.id, nextElement);
15753
+ acc.set(nextElement.id, nextElement);
15754
+ if (!flags.applyDirection) {
15755
+ const prevElement = prevElements.get(id);
15756
+ if (prevElement) {
15757
+ flags.applyDirection = prevElement.version > nextElement.version ? "backward" : "forward";
15758
+ }
15759
+ }
15426
15760
  }
15427
15761
  return acc;
15428
15762
  }, /* @__PURE__ */ new Map());
@@ -15447,13 +15781,13 @@ var ElementsDelta = class _ElementsDelta {
15447
15781
  }
15448
15782
  return element;
15449
15783
  };
15450
- static applyDelta(element, delta, options, flags) {
15784
+ static applyDelta(element, delta, flags, options) {
15451
15785
  const directlyApplicablePartial = {};
15452
15786
  for (const key of Object.keys(delta.inserted)) {
15453
15787
  if (key === "boundElements") {
15454
15788
  continue;
15455
15789
  }
15456
- if (options.excludedProperties.has(key)) {
15790
+ if (options?.excludedProperties?.has(key)) {
15457
15791
  continue;
15458
15792
  }
15459
15793
  const value = delta.inserted[key];
@@ -15481,7 +15815,7 @@ var ElementsDelta = class _ElementsDelta {
15481
15815
  if (!flags.containsZindexDifference) {
15482
15816
  flags.containsZindexDifference = delta.deleted.index !== delta.inserted.index;
15483
15817
  }
15484
- return newElementWith(element, directlyApplicablePartial);
15818
+ return newElementWith(element, directlyApplicablePartial, true);
15485
15819
  }
15486
15820
  /**
15487
15821
  * Check for visible changes regardless of whether they were removed, added or updated.
@@ -15506,25 +15840,32 @@ var ElementsDelta = class _ElementsDelta {
15506
15840
  *
15507
15841
  * @returns all elements affected by the conflict resolution
15508
15842
  */
15509
- resolveConflicts(prevElements, nextElements) {
15843
+ resolveConflicts(prevElements, nextElements, applyDirection = "forward") {
15510
15844
  const nextAffectedElements = /* @__PURE__ */ new Map();
15511
15845
  const updater = (element, updates) => {
15512
15846
  const nextElement = nextElements.get(element.id);
15513
15847
  if (!nextElement) {
15514
15848
  return;
15515
15849
  }
15850
+ const prevElement = prevElements.get(element.id);
15851
+ const nextVersion = applyDirection === "forward" ? nextElement.version + 1 : nextElement.version - 1;
15852
+ const elementUpdates = updates;
15516
15853
  let affectedElement;
15517
- if (prevElements.get(element.id) === nextElement) {
15854
+ if (prevElement === nextElement) {
15518
15855
  affectedElement = newElementWith(
15519
15856
  nextElement,
15520
- updates
15857
+ {
15858
+ ...elementUpdates,
15859
+ version: nextVersion
15860
+ },
15861
+ true
15521
15862
  );
15522
15863
  } else {
15523
- affectedElement = mutateElement(
15524
- nextElement,
15525
- nextElements,
15526
- updates
15527
- );
15864
+ affectedElement = mutateElement(nextElement, nextElements, {
15865
+ ...elementUpdates,
15866
+ // don't modify the version further, if it's already different
15867
+ version: prevElement?.version !== nextElement.version ? nextElement.version : nextVersion
15868
+ });
15528
15869
  }
15529
15870
  nextAffectedElements.set(affectedElement.id, affectedElement);
15530
15871
  nextElements.set(affectedElement.id, affectedElement);
@@ -15549,19 +15890,10 @@ var ElementsDelta = class _ElementsDelta {
15549
15890
  const prevAffectedElements = new Map(
15550
15891
  Array.from(prevElements).filter(([id]) => nextAffectedElements.has(id))
15551
15892
  );
15552
- const { added, removed, updated } = _ElementsDelta.calculate(
15553
- prevAffectedElements,
15554
- nextAffectedElements
15893
+ this.squash(
15894
+ // technically we could do better here if perf. would become an issue
15895
+ _ElementsDelta.calculate(prevAffectedElements, nextAffectedElements)
15555
15896
  );
15556
- for (const [id, delta] of Object.entries(added)) {
15557
- this.added[id] = delta;
15558
- }
15559
- for (const [id, delta] of Object.entries(removed)) {
15560
- this.removed[id] = delta;
15561
- }
15562
- for (const [id, delta] of Object.entries(updated)) {
15563
- this.updated[id] = delta;
15564
- }
15565
15897
  return nextAffectedElements;
15566
15898
  }
15567
15899
  /**
@@ -15596,6 +15928,20 @@ var ElementsDelta = class _ElementsDelta {
15596
15928
  );
15597
15929
  BindableElement.rebindAffected(nextElements, nextElement(), updater);
15598
15930
  }
15931
+ static redrawElements(nextElements, changedElements) {
15932
+ try {
15933
+ const tempScene = new Scene(nextElements, { skipValidation: true });
15934
+ _ElementsDelta.redrawTextBoundingBoxes(tempScene, changedElements);
15935
+ _ElementsDelta.redrawBoundArrows(tempScene, changedElements);
15936
+ } catch (e) {
15937
+ console.error(`Couldn't redraw elements`, e);
15938
+ if (isTestEnv8() || isDevEnv7()) {
15939
+ throw e;
15940
+ }
15941
+ } finally {
15942
+ return nextElements;
15943
+ }
15944
+ }
15599
15945
  static redrawTextBoundingBoxes(scene, changed) {
15600
15946
  const elements = scene.getNonDeletedElementsMap();
15601
15947
  const boxesToRedraw = /* @__PURE__ */ new Map();
@@ -15688,10 +16034,14 @@ var ElementsDelta = class _ElementsDelta {
15688
16034
 
15689
16035
  // src/distribute.ts
15690
16036
  init_define_import_meta_env();
15691
- var distributeElements = (selectedElements, elementsMap, distribution) => {
16037
+ var distributeElements = (selectedElements, elementsMap, distribution, appState) => {
15692
16038
  const [start, mid, end, extent] = distribution.axis === "x" ? ["minX", "midX", "maxX", "width"] : ["minY", "midY", "maxY", "height"];
15693
16039
  const bounds = getCommonBoundingBox(selectedElements);
15694
- const groups = getMaximumGroups(selectedElements, elementsMap).map((group) => [group, getCommonBoundingBox(group)]).sort((a2, b2) => a2[1][mid] - b2[1][mid]);
16040
+ const groups = getSelectedElementsByGroup(
16041
+ selectedElements,
16042
+ elementsMap,
16043
+ appState
16044
+ ).map((group) => [group, getCommonBoundingBox(group)]).sort((a2, b2) => a2[1][mid] - b2[1][mid]);
15695
16045
  let span = 0;
15696
16046
  for (const group of groups) {
15697
16047
  span += group[1][extent];
@@ -16683,8 +17033,8 @@ var embeddableURLValidator = (url, validateEmbeddable) => {
16683
17033
 
16684
17034
  // src/flowchart.ts
16685
17035
  init_define_import_meta_env();
16686
- import { KEYS as KEYS3, invariant as invariant8, toBrandedType as toBrandedType2 } from "@excalidraw/common";
16687
- import { pointFrom as pointFrom13 } from "@excalidraw/math";
17036
+ import { KEYS as KEYS3, invariant as invariant9, toBrandedType as toBrandedType2 } from "@excalidraw/common";
17037
+ import { pointFrom as pointFrom15 } from "@excalidraw/math";
16688
17038
  var VERTICAL_OFFSET = 100;
16689
17039
  var HORIZONTAL_OFFSET = 100;
16690
17040
  var getLinkDirectionFromKey = (key) => {
@@ -16713,7 +17063,7 @@ var getNodeRelatives = (type, node, elementsMap, direction) => {
16713
17063
  if (!relative) {
16714
17064
  return acc;
16715
17065
  }
16716
- invariant8(
17066
+ invariant9(
16717
17067
  isBindableElement(relative),
16718
17068
  "not an ExcalidrawBindableElement"
16719
17069
  );
@@ -16829,7 +17179,7 @@ var addNewNode = (element, appState, direction, scene) => {
16829
17179
  fillStyle: element.fillStyle,
16830
17180
  strokeStyle: element.strokeStyle
16831
17181
  });
16832
- invariant8(
17182
+ invariant9(
16833
17183
  isFlowchartNodeElement(nextNode),
16834
17184
  "not an ExcalidrawFlowchartNodeElement"
16835
17185
  );
@@ -16887,7 +17237,7 @@ var addNewNodes = (startNode, appState, direction, scene, numberOfNodes) => {
16887
17237
  fillStyle: startNode.fillStyle,
16888
17238
  strokeStyle: startNode.strokeStyle
16889
17239
  });
16890
- invariant8(
17240
+ invariant9(
16891
17241
  isFlowchartNodeElement(nextNode),
16892
17242
  "not an ExcalidrawFlowchartNodeElement"
16893
17243
  );
@@ -16964,7 +17314,7 @@ var createBindingArrow = (startBindingElement, endBindingElement, direction, app
16964
17314
  strokeWidth: startBindingElement.strokeWidth,
16965
17315
  opacity: startBindingElement.opacity,
16966
17316
  roughness: startBindingElement.roughness,
16967
- points: [pointFrom13(0, 0), pointFrom13(endX, endY)],
17317
+ points: [pointFrom15(0, 0), pointFrom15(endX, endY)],
16968
17318
  elbowed: true
16969
17319
  });
16970
17320
  const elementsMap = scene.getNonDeletedElementsMap();
@@ -17113,7 +17463,7 @@ var FlowChartCreator = class {
17113
17463
  }
17114
17464
  if (startNode.frameId) {
17115
17465
  const frame = elementsMap.get(startNode.frameId);
17116
- invariant8(
17466
+ invariant9(
17117
17467
  frame && isFrameElement(frame),
17118
17468
  "not an ExcalidrawFrameElement"
17119
17469
  );
@@ -17248,13 +17598,80 @@ var normalizeSVG = (SVGString) => {
17248
17598
  }
17249
17599
  };
17250
17600
 
17601
+ // src/positionElementsOnGrid.ts
17602
+ init_define_import_meta_env();
17603
+ var positionElementsOnGrid = (elements, centerX, centerY, padding = 50) => {
17604
+ if (!elements || elements.length === 0) {
17605
+ return [];
17606
+ }
17607
+ const res = [];
17608
+ const atomicUnits = Array.isArray(elements[0]) ? elements : elements.map((element) => [element]);
17609
+ const numUnits = atomicUnits.length;
17610
+ const numColumns = Math.max(1, Math.ceil(Math.sqrt(numUnits)));
17611
+ const rows = [];
17612
+ for (let i = 0; i < numUnits; i += numColumns) {
17613
+ rows.push(atomicUnits.slice(i, i + numColumns));
17614
+ }
17615
+ let totalGridActualHeight = 0;
17616
+ const rowProperties = rows.map((rowUnits) => {
17617
+ let rowWidth = 0;
17618
+ let maxUnitHeightInRow = 0;
17619
+ const unitBounds = rowUnits.map((unit) => {
17620
+ const [minX, minY, maxX, maxY] = getCommonBounds(unit);
17621
+ return {
17622
+ elements: unit,
17623
+ bounds: [minX, minY, maxX, maxY],
17624
+ width: maxX - minX,
17625
+ height: maxY - minY
17626
+ };
17627
+ });
17628
+ unitBounds.forEach((unitBound, index) => {
17629
+ rowWidth += unitBound.width;
17630
+ if (index < unitBounds.length - 1) {
17631
+ rowWidth += padding;
17632
+ }
17633
+ if (unitBound.height > maxUnitHeightInRow) {
17634
+ maxUnitHeightInRow = unitBound.height;
17635
+ }
17636
+ });
17637
+ totalGridActualHeight += maxUnitHeightInRow;
17638
+ return {
17639
+ unitBounds,
17640
+ width: rowWidth,
17641
+ maxHeight: maxUnitHeightInRow
17642
+ };
17643
+ });
17644
+ const totalGridHeightWithPadding = totalGridActualHeight + Math.max(0, rows.length - 1) * padding;
17645
+ let currentY = centerY - totalGridHeightWithPadding / 2;
17646
+ rowProperties.forEach((rowProp) => {
17647
+ const { unitBounds, width: rowWidth, maxHeight: rowMaxHeight } = rowProp;
17648
+ let currentX = centerX - rowWidth / 2;
17649
+ unitBounds.forEach((unitBound) => {
17650
+ const [originalMinX, originalMinY] = unitBound.bounds;
17651
+ const offsetX = currentX - originalMinX;
17652
+ const offsetY = currentY - originalMinY;
17653
+ unitBound.elements.forEach((element) => {
17654
+ res.push(
17655
+ newElementWith(element, {
17656
+ x: element.x + offsetX,
17657
+ y: element.y + offsetY
17658
+ })
17659
+ );
17660
+ });
17661
+ currentX += unitBound.width + padding;
17662
+ });
17663
+ currentY += rowMaxHeight + padding;
17664
+ });
17665
+ return res;
17666
+ };
17667
+
17251
17668
  // src/resizeElements.ts
17252
17669
  init_define_import_meta_env();
17253
17670
  import {
17254
17671
  pointCenter as pointCenter3,
17255
17672
  normalizeRadians as normalizeRadians2,
17256
- pointFrom as pointFrom14,
17257
- pointRotateRads as pointRotateRads11
17673
+ pointFrom as pointFrom16,
17674
+ pointRotateRads as pointRotateRads13
17258
17675
  } from "@excalidraw/math";
17259
17676
  import {
17260
17677
  MIN_FONT_SIZE,
@@ -17382,7 +17799,16 @@ var rotateSingleElement = (element, scene, pointerX, pointerY, shouldRotateWithD
17382
17799
  if (boundTextElementId) {
17383
17800
  const textElement = scene.getElement(boundTextElementId);
17384
17801
  if (textElement && !isArrowElement(element)) {
17385
- scene.mutateElement(textElement, { angle });
17802
+ const { x, y } = computeBoundTextPosition(
17803
+ element,
17804
+ textElement,
17805
+ scene.getNonDeletedElementsMap()
17806
+ );
17807
+ scene.mutateElement(textElement, {
17808
+ angle,
17809
+ x,
17810
+ y
17811
+ });
17386
17812
  }
17387
17813
  }
17388
17814
  };
@@ -17419,7 +17845,7 @@ var resizeSingleTextElement = (origElement, element, scene, transformHandleType,
17419
17845
  return;
17420
17846
  }
17421
17847
  if (transformHandleType.includes("n") || transformHandleType.includes("s")) {
17422
- const previousOrigin = pointFrom14(origElement.x, origElement.y);
17848
+ const previousOrigin = pointFrom16(origElement.x, origElement.y);
17423
17849
  const newOrigin = getResizedOrigin(
17424
17850
  previousOrigin,
17425
17851
  origElement.width,
@@ -17460,7 +17886,7 @@ var resizeSingleTextElement = (origElement, element, scene, transformHandleType,
17460
17886
  element.lineHeight
17461
17887
  );
17462
17888
  const newHeight = metrics2.height;
17463
- const previousOrigin = pointFrom14(origElement.x, origElement.y);
17889
+ const previousOrigin = pointFrom16(origElement.x, origElement.y);
17464
17890
  const newOrigin = getResizedOrigin(
17465
17891
  previousOrigin,
17466
17892
  origElement.width,
@@ -17496,9 +17922,9 @@ var rotateMultipleElements = (originalElements, elements, scene, pointerX, point
17496
17922
  const cx = (x1 + x2) / 2;
17497
17923
  const cy = (y1 + y2) / 2;
17498
17924
  const origAngle = originalElements.get(element.id)?.angle ?? element.angle;
17499
- const [rotatedCX, rotatedCY] = pointRotateRads11(
17500
- pointFrom14(cx, cy),
17501
- pointFrom14(centerX, centerY),
17925
+ const [rotatedCX, rotatedCY] = pointRotateRads13(
17926
+ pointFrom16(cx, cy),
17927
+ pointFrom16(centerX, centerY),
17502
17928
  centerAngle + origAngle - element.angle
17503
17929
  );
17504
17930
  const updates = isElbowArrow(element) ? {
@@ -17515,9 +17941,14 @@ var rotateMultipleElements = (originalElements, elements, scene, pointerX, point
17515
17941
  });
17516
17942
  const boundText = getBoundTextElement(element, elementsMap);
17517
17943
  if (boundText && !isArrowElement(element)) {
17944
+ const { x, y } = computeBoundTextPosition(
17945
+ element,
17946
+ boundText,
17947
+ elementsMap
17948
+ );
17518
17949
  scene.mutateElement(boundText, {
17519
- x: boundText.x + (rotatedCX - cx),
17520
- y: boundText.y + (rotatedCY - cy),
17950
+ x,
17951
+ y,
17521
17952
  angle: normalizeRadians2(centerAngle + origAngle)
17522
17953
  });
17523
17954
  }
@@ -17530,44 +17961,44 @@ var getResizeOffsetXY = (transformHandleType, selectedElements, elementsMap, x,
17530
17961
  const cx = (x1 + x2) / 2;
17531
17962
  const cy = (y1 + y2) / 2;
17532
17963
  const angle = selectedElements.length === 1 ? selectedElements[0].angle : 0;
17533
- [x, y] = pointRotateRads11(
17534
- pointFrom14(x, y),
17535
- pointFrom14(cx, cy),
17964
+ [x, y] = pointRotateRads13(
17965
+ pointFrom16(x, y),
17966
+ pointFrom16(cx, cy),
17536
17967
  -angle
17537
17968
  );
17538
17969
  switch (transformHandleType) {
17539
17970
  case "n":
17540
- return pointRotateRads11(
17541
- pointFrom14(x - (x1 + x2) / 2, y - y1),
17542
- pointFrom14(0, 0),
17971
+ return pointRotateRads13(
17972
+ pointFrom16(x - (x1 + x2) / 2, y - y1),
17973
+ pointFrom16(0, 0),
17543
17974
  angle
17544
17975
  );
17545
17976
  case "s":
17546
- return pointRotateRads11(
17547
- pointFrom14(x - (x1 + x2) / 2, y - y2),
17548
- pointFrom14(0, 0),
17977
+ return pointRotateRads13(
17978
+ pointFrom16(x - (x1 + x2) / 2, y - y2),
17979
+ pointFrom16(0, 0),
17549
17980
  angle
17550
17981
  );
17551
17982
  case "w":
17552
- return pointRotateRads11(
17553
- pointFrom14(x - x1, y - (y1 + y2) / 2),
17554
- pointFrom14(0, 0),
17983
+ return pointRotateRads13(
17984
+ pointFrom16(x - x1, y - (y1 + y2) / 2),
17985
+ pointFrom16(0, 0),
17555
17986
  angle
17556
17987
  );
17557
17988
  case "e":
17558
- return pointRotateRads11(
17559
- pointFrom14(x - x2, y - (y1 + y2) / 2),
17560
- pointFrom14(0, 0),
17989
+ return pointRotateRads13(
17990
+ pointFrom16(x - x2, y - (y1 + y2) / 2),
17991
+ pointFrom16(0, 0),
17561
17992
  angle
17562
17993
  );
17563
17994
  case "nw":
17564
- return pointRotateRads11(pointFrom14(x - x1, y - y1), pointFrom14(0, 0), angle);
17995
+ return pointRotateRads13(pointFrom16(x - x1, y - y1), pointFrom16(0, 0), angle);
17565
17996
  case "ne":
17566
- return pointRotateRads11(pointFrom14(x - x2, y - y1), pointFrom14(0, 0), angle);
17997
+ return pointRotateRads13(pointFrom16(x - x2, y - y1), pointFrom16(0, 0), angle);
17567
17998
  case "sw":
17568
- return pointRotateRads11(pointFrom14(x - x1, y - y2), pointFrom14(0, 0), angle);
17999
+ return pointRotateRads13(pointFrom16(x - x1, y - y2), pointFrom16(0, 0), angle);
17569
18000
  case "se":
17570
- return pointRotateRads11(pointFrom14(x - x2, y - y2), pointFrom14(0, 0), angle);
18001
+ return pointRotateRads13(pointFrom16(x - x2, y - y2), pointFrom16(0, 0), angle);
17571
18002
  default:
17572
18003
  return [0, 0];
17573
18004
  }
@@ -17730,10 +18161,10 @@ var resizeSingleElement = (nextWidth, nextHeight, latestElement, origElement, or
17730
18161
  nextHeight,
17731
18162
  true
17732
18163
  );
17733
- let previousOrigin = pointFrom14(origElement.x, origElement.y);
18164
+ let previousOrigin = pointFrom16(origElement.x, origElement.y);
17734
18165
  if (isLinearElement(origElement)) {
17735
18166
  const [x1, y1] = getElementBounds(origElement, originalElementsMap);
17736
- previousOrigin = pointFrom14(x1, y1);
18167
+ previousOrigin = pointFrom16(x1, y1);
17737
18168
  }
17738
18169
  const newOrigin = getResizedOrigin(
17739
18170
  previousOrigin,
@@ -17756,7 +18187,7 @@ var resizeSingleElement = (nextWidth, nextHeight, latestElement, origElement, or
17756
18187
  newOrigin.x += scaledX;
17757
18188
  newOrigin.y += scaledY;
17758
18189
  rescaledPoints.points = rescaledPoints.points.map(
17759
- (p) => pointFrom14(p[0] - scaledX, p[1] - scaledY)
18190
+ (p) => pointFrom16(p[0] - scaledX, p[1] - scaledY)
17760
18191
  );
17761
18192
  }
17762
18193
  if (nextWidth < 0) {
@@ -17819,11 +18250,11 @@ var getNextSingleWidthAndHeightFromPointer = (latestElement, origElement, handle
17819
18250
  origElement.height,
17820
18251
  true
17821
18252
  );
17822
- const startTopLeft = pointFrom14(x1, y1);
17823
- const startBottomRight = pointFrom14(x2, y2);
18253
+ const startTopLeft = pointFrom16(x1, y1);
18254
+ const startBottomRight = pointFrom16(x2, y2);
17824
18255
  const startCenter = pointCenter3(startTopLeft, startBottomRight);
17825
- const rotatedPointer = pointRotateRads11(
17826
- pointFrom14(pointerX, pointerY),
18256
+ const rotatedPointer = pointRotateRads13(
18257
+ pointFrom16(pointerX, pointerY),
17827
18258
  startCenter,
17828
18259
  -origElement.angle
17829
18260
  );
@@ -18181,9 +18612,9 @@ var resizeMultipleElements = (selectedElements, elementsMap, handleDirection, sc
18181
18612
  // src/resizeTest.ts
18182
18613
  init_define_import_meta_env();
18183
18614
  import {
18184
- pointFrom as pointFrom16,
18615
+ pointFrom as pointFrom18,
18185
18616
  pointOnLineSegment,
18186
- pointRotateRads as pointRotateRads13
18617
+ pointRotateRads as pointRotateRads15
18187
18618
  } from "@excalidraw/math";
18188
18619
  import { SIDE_RESIZING_THRESHOLD } from "@excalidraw/common";
18189
18620
 
@@ -18194,7 +18625,7 @@ import {
18194
18625
  isAndroid,
18195
18626
  isIOS
18196
18627
  } from "@excalidraw/common";
18197
- import { pointFrom as pointFrom15, pointRotateRads as pointRotateRads12 } from "@excalidraw/math";
18628
+ import { pointFrom as pointFrom17, pointRotateRads as pointRotateRads14 } from "@excalidraw/math";
18198
18629
  var transformHandleSizes = {
18199
18630
  mouse: 8,
18200
18631
  pen: 16,
@@ -18235,9 +18666,9 @@ var OMIT_SIDES_FOR_LINE_BACKSLASH = {
18235
18666
  w: true
18236
18667
  };
18237
18668
  var generateTransformHandle = (x, y, width, height, cx, cy, angle) => {
18238
- const [xx, yy] = pointRotateRads12(
18239
- pointFrom15(x + width / 2, y + height / 2),
18240
- pointFrom15(cx, cy),
18669
+ const [xx, yy] = pointRotateRads14(
18670
+ pointFrom17(x + width / 2, y + height / 2),
18671
+ pointFrom17(cx, cy),
18241
18672
  angle
18242
18673
  );
18243
18674
  return [xx - width / 2, yy - height / 2, width, height];
@@ -18403,7 +18834,7 @@ var getTransformHandles = (element, zoom, elementsMap, pointerType = "mouse", om
18403
18834
  );
18404
18835
  };
18405
18836
  var shouldShowBoundingBox = (elements, appState) => {
18406
- if (appState.editingLinearElement) {
18837
+ if (appState.selectedLinearElement?.isEditing) {
18407
18838
  return false;
18408
18839
  }
18409
18840
  if (elements.length > 1) {
@@ -18454,14 +18885,14 @@ var resizeTest = (element, elementsMap, appState, x, y, zoom, pointerType, devic
18454
18885
  const SPACING = isImageElement(element) ? 0 : SIDE_RESIZING_THRESHOLD / zoom.value;
18455
18886
  const ZOOMED_SIDE_RESIZING_THRESHOLD = SIDE_RESIZING_THRESHOLD / zoom.value;
18456
18887
  const sides = getSelectionBorders(
18457
- pointFrom16(x1 - SPACING, y1 - SPACING),
18458
- pointFrom16(x2 + SPACING, y2 + SPACING),
18459
- pointFrom16(cx, cy),
18888
+ pointFrom18(x1 - SPACING, y1 - SPACING),
18889
+ pointFrom18(x2 + SPACING, y2 + SPACING),
18890
+ pointFrom18(cx, cy),
18460
18891
  element.angle
18461
18892
  );
18462
18893
  for (const [dir, side] of Object.entries(sides)) {
18463
18894
  if (pointOnLineSegment(
18464
- pointFrom16(x, y),
18895
+ pointFrom18(x, y),
18465
18896
  side,
18466
18897
  ZOOMED_SIDE_RESIZING_THRESHOLD
18467
18898
  )) {
@@ -18510,14 +18941,14 @@ var getTransformHandleTypeFromCoords = ([x1, y1, x2, y2], scenePointerX, scenePo
18510
18941
  const cy = (y1 + y2) / 2;
18511
18942
  const SPACING = SIDE_RESIZING_THRESHOLD / zoom.value;
18512
18943
  const sides = getSelectionBorders(
18513
- pointFrom16(x1 - SPACING, y1 - SPACING),
18514
- pointFrom16(x2 + SPACING, y2 + SPACING),
18515
- pointFrom16(cx, cy),
18944
+ pointFrom18(x1 - SPACING, y1 - SPACING),
18945
+ pointFrom18(x2 + SPACING, y2 + SPACING),
18946
+ pointFrom18(cx, cy),
18516
18947
  0
18517
18948
  );
18518
18949
  for (const [dir, side] of Object.entries(sides)) {
18519
18950
  if (pointOnLineSegment(
18520
- pointFrom16(scenePointerX, scenePointerY),
18951
+ pointFrom18(scenePointerX, scenePointerY),
18521
18952
  side,
18522
18953
  SPACING
18523
18954
  )) {
@@ -18574,10 +19005,10 @@ var getCursorForResizingElement = (resizingElement) => {
18574
19005
  return cursor ? `${cursor}-resize` : "";
18575
19006
  };
18576
19007
  var getSelectionBorders = ([x1, y1], [x2, y2], center, angle) => {
18577
- const topLeft = pointRotateRads13(pointFrom16(x1, y1), center, angle);
18578
- const topRight = pointRotateRads13(pointFrom16(x2, y1), center, angle);
18579
- const bottomLeft = pointRotateRads13(pointFrom16(x1, y2), center, angle);
18580
- const bottomRight = pointRotateRads13(pointFrom16(x2, y2), center, angle);
19008
+ const topLeft = pointRotateRads15(pointFrom18(x1, y1), center, angle);
19009
+ const topRight = pointRotateRads15(pointFrom18(x2, y1), center, angle);
19010
+ const bottomLeft = pointRotateRads15(pointFrom18(x1, y2), center, angle);
19011
+ const bottomRight = pointRotateRads15(pointFrom18(x2, y2), center, angle);
18581
19012
  return {
18582
19013
  n: [topLeft, topRight],
18583
19014
  e: [topRight, bottomRight],
@@ -19118,6 +19549,8 @@ export {
19118
19549
  getFrameLikeTitle,
19119
19550
  getFreeDrawPath2D,
19120
19551
  getFreeDrawSvgPath,
19552
+ getFreedrawOutlineAsSegments,
19553
+ getFreedrawOutlinePoints,
19121
19554
  getGlobalFixedPointForBindableElement,
19122
19555
  getGlobalFixedPoints,
19123
19556
  getHeadingForElbowArrowSnap,
@@ -19151,6 +19584,7 @@ export {
19151
19584
  getRootElements,
19152
19585
  getSceneVersion,
19153
19586
  getSelectedElements,
19587
+ getSelectedElementsByGroup,
19154
19588
  getSelectedGroupForElement,
19155
19589
  getSelectedGroupIdForElement,
19156
19590
  getSelectedGroupIds,
@@ -19282,6 +19716,7 @@ export {
19282
19716
  parseTokens,
19283
19717
  pathsCache,
19284
19718
  pointInsideBounds,
19719
+ positionElementsOnGrid,
19285
19720
  redrawTextBoundingBox,
19286
19721
  refreshTextDimensions,
19287
19722
  removeAllElementsFromFrame,