@excalidraw/element 0.18.0-c65b684e9 → 0.18.0-d1f3982
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.
- package/dist/dev/index.js +936 -611
- package/dist/dev/index.js.map +4 -4
- package/dist/prod/index.js +14 -14
- package/dist/types/common/src/constants.d.ts +18 -15
- package/dist/types/common/src/editorInterface.d.ts +34 -0
- package/dist/types/common/src/index.d.ts +1 -0
- package/dist/types/common/src/utils.d.ts +2 -1
- package/dist/types/element/src/Scene.d.ts +6 -2
- package/dist/types/element/src/bounds.d.ts +1 -1
- package/dist/types/element/src/delta.d.ts +6 -4
- package/dist/types/element/src/index.d.ts +1 -0
- package/dist/types/element/src/positionElementsOnGrid.d.ts +2 -0
- package/dist/types/element/src/renderElement.d.ts +4 -1
- package/dist/types/element/src/resizeTest.d.ts +5 -4
- package/dist/types/element/src/store.d.ts +6 -1
- package/dist/types/element/src/textElement.d.ts +1 -1
- package/dist/types/element/src/transformHandles.d.ts +5 -4
- package/dist/types/excalidraw/actions/actionAddToLibrary.d.ts +21 -9
- package/dist/types/excalidraw/actions/actionBoundText.d.ts +14 -6
- package/dist/types/excalidraw/actions/actionCanvas.d.ts +94 -54
- package/dist/types/excalidraw/actions/actionClipboard.d.ts +42 -18
- package/dist/types/excalidraw/actions/actionCropEditor.d.ts +7 -3
- package/dist/types/excalidraw/actions/actionDeleteSelected.d.ts +22 -10
- package/dist/types/excalidraw/actions/actionDuplicateSelection.d.ts +1 -1
- package/dist/types/excalidraw/actions/actionElementLink.d.ts +7 -3
- package/dist/types/excalidraw/actions/actionElementLock.d.ts +14 -6
- package/dist/types/excalidraw/actions/actionEmbeddable.d.ts +7 -3
- package/dist/types/excalidraw/actions/actionExport.d.ts +63 -27
- package/dist/types/excalidraw/actions/actionFinalize.d.ts +14 -6
- package/dist/types/excalidraw/actions/actionFrame.d.ts +28 -12
- package/dist/types/excalidraw/actions/actionGroup.d.ts +14 -6
- package/dist/types/excalidraw/actions/actionLinearEditor.d.ts +8 -4
- package/dist/types/excalidraw/actions/actionLink.d.ts +5 -1
- package/dist/types/excalidraw/actions/actionMenu.d.ts +7 -369
- package/dist/types/excalidraw/actions/actionNavigate.d.ts +14 -6
- package/dist/types/excalidraw/actions/actionProperties.d.ts +122 -53
- package/dist/types/excalidraw/actions/actionSelectAll.d.ts +7 -3
- package/dist/types/excalidraw/actions/actionStyles.d.ts +7 -3
- package/dist/types/excalidraw/actions/actionToggleGridMode.d.ts +7 -3
- package/dist/types/excalidraw/actions/actionToggleObjectsSnapMode.d.ts +7 -3
- package/dist/types/excalidraw/actions/actionToggleSearchMenu.d.ts +7 -3
- package/dist/types/excalidraw/actions/actionToggleStats.d.ts +7 -3
- package/dist/types/excalidraw/actions/actionToggleViewMode.d.ts +7 -3
- package/dist/types/excalidraw/actions/actionToggleZenMode.d.ts +7 -3
- package/dist/types/excalidraw/actions/index.d.ts +2 -2
- package/dist/types/excalidraw/actions/types.d.ts +1 -1
- package/dist/types/excalidraw/appState.d.ts +5 -1
- package/dist/types/excalidraw/clipboard.d.ts +64 -1
- package/dist/types/excalidraw/components/Actions.d.ts +17 -3
- package/dist/types/excalidraw/components/App.d.ts +28 -23
- package/dist/types/excalidraw/components/ColorPicker/Picker.d.ts +2 -0
- package/dist/types/excalidraw/components/ColorPicker/PickerColorList.d.ts +2 -1
- package/dist/types/excalidraw/components/ColorPicker/ShadeList.d.ts +2 -1
- package/dist/types/excalidraw/components/CommandPalette/CommandPalette.d.ts +1 -0
- package/dist/types/excalidraw/components/ExcalidrawLogo.d.ts +1 -1
- package/dist/types/excalidraw/components/FontPicker/FontPicker.d.ts +2 -1
- package/dist/types/excalidraw/components/FontPicker/FontPickerTrigger.d.ts +3 -1
- package/dist/types/excalidraw/components/HintViewer.d.ts +4 -3
- package/dist/types/excalidraw/components/InlineIcon.d.ts +3 -1
- package/dist/types/excalidraw/components/LayerUI.d.ts +2 -1
- package/dist/types/excalidraw/components/LibraryMenuSection.d.ts +1 -1
- package/dist/types/excalidraw/components/MobileMenu.d.ts +3 -5
- package/dist/types/excalidraw/components/MobileToolBar.d.ts +11 -0
- package/dist/types/excalidraw/components/Popover.d.ts +2 -1
- package/dist/types/excalidraw/components/PropertiesPopover.d.ts +1 -0
- package/dist/types/excalidraw/components/TTDDialog/TTDDialogTrigger.d.ts +1 -2
- package/dist/types/excalidraw/components/TextField.d.ts +1 -0
- package/dist/types/excalidraw/components/ToolPopover.d.ts +25 -0
- package/dist/types/excalidraw/components/canvases/InteractiveCanvas.d.ts +3 -2
- package/dist/types/excalidraw/components/dropdownMenu/DropdownMenu.d.ts +4 -2
- package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuContent.d.ts +2 -1
- package/dist/types/excalidraw/components/icons.d.ts +5 -0
- package/dist/types/excalidraw/components/live-collaboration/LiveCollaborationTrigger.d.ts +13 -1
- package/dist/types/excalidraw/components/main-menu/MainMenu.d.ts +0 -3
- package/dist/types/excalidraw/components/shapes.d.ts +129 -1
- package/dist/types/excalidraw/data/blob.d.ts +3 -7
- package/dist/types/excalidraw/data/reconcile.d.ts +1 -0
- package/dist/types/excalidraw/data/restore.d.ts +6 -1
- package/dist/types/excalidraw/data/types.d.ts +4 -1
- package/dist/types/excalidraw/hooks/useLibraryItemSvg.d.ts +1 -1
- package/dist/types/excalidraw/hooks/useTextEditorFocus.d.ts +14 -0
- package/dist/types/excalidraw/index.d.ts +3 -4
- package/dist/types/excalidraw/renderer/interactiveScene.d.ts +1 -1
- package/dist/types/excalidraw/scene/types.d.ts +3 -3
- package/dist/types/excalidraw/shortcut.d.ts +1 -0
- package/dist/types/excalidraw/types.d.ts +23 -17
- package/dist/types/math/src/segment.d.ts +1 -0
- 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
|
|
2264
|
+
invariant as invariant8,
|
|
2265
2265
|
rescalePoints,
|
|
2266
2266
|
sizeOf
|
|
2267
2267
|
} from "@excalidraw/common";
|
|
2268
2268
|
import {
|
|
2269
2269
|
degreesToRadians,
|
|
2270
|
-
lineSegment as
|
|
2270
|
+
lineSegment as lineSegment6,
|
|
2271
2271
|
pointDistance as pointDistance7,
|
|
2272
|
-
pointFrom as
|
|
2272
|
+
pointFrom as pointFrom14,
|
|
2273
2273
|
pointFromArray as pointFromArray3,
|
|
2274
|
-
pointRotateRads as
|
|
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
|
|
2451
|
+
pointFrom as pointFrom13,
|
|
2452
2452
|
pointDistance as pointDistance6,
|
|
2453
|
-
pointRotateRads as
|
|
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 {
|
|
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
|
|
3107
|
-
pointRotateRads as
|
|
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
|
|
3142
|
-
pointRotateRads as
|
|
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
|
|
3170
|
+
pointFrom as pointFrom5,
|
|
3165
3171
|
pointFromVector as pointFromVector3,
|
|
3166
|
-
pointRotateRads as
|
|
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();
|
|
@@ -4390,6 +4397,22 @@ var computeBoundTextPosition = (container, boundTextElement, elementsMap) => {
|
|
|
4390
4397
|
} else {
|
|
4391
4398
|
x = containerCoords.x + (maxContainerWidth / 2 - boundTextElement.width / 2);
|
|
4392
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
|
+
}
|
|
4393
4416
|
return { x, y };
|
|
4394
4417
|
};
|
|
4395
4418
|
var getBoundTextElementId = (container) => {
|
|
@@ -4573,7 +4596,7 @@ init_define_import_meta_env();
|
|
|
4573
4596
|
import {
|
|
4574
4597
|
curvePointDistance,
|
|
4575
4598
|
distanceToLineSegment,
|
|
4576
|
-
pointRotateRads as
|
|
4599
|
+
pointRotateRads as pointRotateRads4
|
|
4577
4600
|
} from "@excalidraw/math";
|
|
4578
4601
|
import { ellipse as ellipse2, ellipseDistanceFromPoint } from "@excalidraw/math/ellipse";
|
|
4579
4602
|
var distanceToElement = (element, elementsMap, p) => {
|
|
@@ -4599,7 +4622,7 @@ var distanceToElement = (element, elementsMap, p) => {
|
|
|
4599
4622
|
};
|
|
4600
4623
|
var distanceToRectanguloidElement = (element, elementsMap, p) => {
|
|
4601
4624
|
const center = elementCenterPoint(element, elementsMap);
|
|
4602
|
-
const rotatedPoint =
|
|
4625
|
+
const rotatedPoint = pointRotateRads4(p, center, -element.angle);
|
|
4603
4626
|
const [sides, corners] = deconstructRectanguloidElement(element);
|
|
4604
4627
|
return Math.min(
|
|
4605
4628
|
...sides.map((s) => distanceToLineSegment(rotatedPoint, s)),
|
|
@@ -4608,7 +4631,7 @@ var distanceToRectanguloidElement = (element, elementsMap, p) => {
|
|
|
4608
4631
|
};
|
|
4609
4632
|
var distanceToDiamondElement = (element, elementsMap, p) => {
|
|
4610
4633
|
const center = elementCenterPoint(element, elementsMap);
|
|
4611
|
-
const rotatedPoint =
|
|
4634
|
+
const rotatedPoint = pointRotateRads4(p, center, -element.angle);
|
|
4612
4635
|
const [sides, curves] = deconstructDiamondElement(element);
|
|
4613
4636
|
return Math.min(
|
|
4614
4637
|
...sides.map((s) => distanceToLineSegment(rotatedPoint, s)),
|
|
@@ -4619,7 +4642,7 @@ var distanceToEllipseElement = (element, elementsMap, p) => {
|
|
|
4619
4642
|
const center = elementCenterPoint(element, elementsMap);
|
|
4620
4643
|
return ellipseDistanceFromPoint(
|
|
4621
4644
|
// Instead of rotating the ellipse, rotate the point to the inverse angle
|
|
4622
|
-
|
|
4645
|
+
pointRotateRads4(p, center, -element.angle),
|
|
4623
4646
|
ellipse2(center, element.width / 2, element.height / 2)
|
|
4624
4647
|
);
|
|
4625
4648
|
};
|
|
@@ -4653,22 +4676,22 @@ var hitElementItself = ({
|
|
|
4653
4676
|
frameNameBound = null
|
|
4654
4677
|
}) => {
|
|
4655
4678
|
const hitFrameName = frameNameBound ? isPointWithinBounds(
|
|
4656
|
-
|
|
4679
|
+
pointFrom5(frameNameBound.x - threshold, frameNameBound.y - threshold),
|
|
4657
4680
|
point,
|
|
4658
|
-
|
|
4681
|
+
pointFrom5(
|
|
4659
4682
|
frameNameBound.x + frameNameBound.width + threshold,
|
|
4660
4683
|
frameNameBound.y + frameNameBound.height + threshold
|
|
4661
4684
|
)
|
|
4662
4685
|
) : false;
|
|
4663
4686
|
const bounds = getElementBounds(element, elementsMap, true);
|
|
4664
4687
|
const hitBounds = isPointWithinBounds(
|
|
4665
|
-
|
|
4666
|
-
|
|
4688
|
+
pointFrom5(bounds[0] - threshold, bounds[1] - threshold),
|
|
4689
|
+
pointRotateRads5(
|
|
4667
4690
|
point,
|
|
4668
4691
|
getCenterForBounds(bounds),
|
|
4669
4692
|
-element.angle
|
|
4670
4693
|
),
|
|
4671
|
-
|
|
4694
|
+
pointFrom5(bounds[2] + threshold, bounds[3] + threshold)
|
|
4672
4695
|
);
|
|
4673
4696
|
if (!hitBounds && !hitFrameName) {
|
|
4674
4697
|
return false;
|
|
@@ -4686,7 +4709,7 @@ var hitElementBoundingBox = (point, element, elementsMap, tolerance = 0) => {
|
|
|
4686
4709
|
y1 -= tolerance;
|
|
4687
4710
|
x2 += tolerance;
|
|
4688
4711
|
y2 += tolerance;
|
|
4689
|
-
return isPointWithinBounds(
|
|
4712
|
+
return isPointWithinBounds(pointFrom5(x1, y1), point, pointFrom5(x2, y2));
|
|
4690
4713
|
};
|
|
4691
4714
|
var hitElementBoundingBoxOnly = (hitArgs, elementsMap) => !hitElementItself(hitArgs) && // bound text is considered part of the element (even if it's outside the bounding box)
|
|
4692
4715
|
!hitElementBoundText(hitArgs.point, hitArgs.element, elementsMap) && hitElementBoundingBox(hitArgs.point, hitArgs.element, elementsMap);
|
|
@@ -4770,7 +4793,7 @@ var curveIntersections = (curves, segment, intersections, center, angle, onlyFir
|
|
|
4770
4793
|
const hits = curveIntersectLineSegment(c, segment);
|
|
4771
4794
|
if (hits.length > 0) {
|
|
4772
4795
|
for (const j of hits) {
|
|
4773
|
-
intersections.push(
|
|
4796
|
+
intersections.push(pointRotateRads5(j, center, angle));
|
|
4774
4797
|
}
|
|
4775
4798
|
if (onlyFirst) {
|
|
4776
4799
|
return intersections;
|
|
@@ -4783,7 +4806,7 @@ var lineIntersections = (lines, segment, intersections, center, angle, onlyFirst
|
|
|
4783
4806
|
for (const l2 of lines) {
|
|
4784
4807
|
const intersection = lineSegmentIntersectionPoints(l2, segment);
|
|
4785
4808
|
if (intersection) {
|
|
4786
|
-
intersections.push(
|
|
4809
|
+
intersections.push(pointRotateRads5(intersection, center, angle));
|
|
4787
4810
|
if (onlyFirst) {
|
|
4788
4811
|
return intersections;
|
|
4789
4812
|
}
|
|
@@ -4826,12 +4849,12 @@ var intersectLinearOrFreeDrawWithLineSegment = (element, segment, onlyFirst = fa
|
|
|
4826
4849
|
};
|
|
4827
4850
|
var intersectRectanguloidWithLineSegment = (element, elementsMap, segment, offset = 0, onlyFirst = false) => {
|
|
4828
4851
|
const center = elementCenterPoint(element, elementsMap);
|
|
4829
|
-
const rotatedA =
|
|
4852
|
+
const rotatedA = pointRotateRads5(
|
|
4830
4853
|
segment[0],
|
|
4831
4854
|
center,
|
|
4832
4855
|
-element.angle
|
|
4833
4856
|
);
|
|
4834
|
-
const rotatedB =
|
|
4857
|
+
const rotatedB = pointRotateRads5(
|
|
4835
4858
|
segment[1],
|
|
4836
4859
|
center,
|
|
4837
4860
|
-element.angle
|
|
@@ -4862,8 +4885,8 @@ var intersectRectanguloidWithLineSegment = (element, elementsMap, segment, offse
|
|
|
4862
4885
|
};
|
|
4863
4886
|
var intersectDiamondWithLineSegment = (element, elementsMap, l2, offset = 0, onlyFirst = false) => {
|
|
4864
4887
|
const center = elementCenterPoint(element, elementsMap);
|
|
4865
|
-
const rotatedA =
|
|
4866
|
-
const rotatedB =
|
|
4888
|
+
const rotatedA = pointRotateRads5(l2[0], center, -element.angle);
|
|
4889
|
+
const rotatedB = pointRotateRads5(l2[1], center, -element.angle);
|
|
4867
4890
|
const rotatedIntersector = lineSegment3(rotatedA, rotatedB);
|
|
4868
4891
|
const [sides, corners] = deconstructDiamondElement(element, offset);
|
|
4869
4892
|
const intersections = [];
|
|
@@ -4890,12 +4913,12 @@ var intersectDiamondWithLineSegment = (element, elementsMap, l2, offset = 0, onl
|
|
|
4890
4913
|
};
|
|
4891
4914
|
var intersectEllipseWithLineSegment = (element, elementsMap, l2, offset = 0) => {
|
|
4892
4915
|
const center = elementCenterPoint(element, elementsMap);
|
|
4893
|
-
const rotatedA =
|
|
4894
|
-
const rotatedB =
|
|
4916
|
+
const rotatedA = pointRotateRads5(l2[0], center, -element.angle);
|
|
4917
|
+
const rotatedB = pointRotateRads5(l2[1], center, -element.angle);
|
|
4895
4918
|
return ellipseSegmentInterceptPoints(
|
|
4896
4919
|
ellipse3(center, element.width / 2 + offset, element.height / 2 + offset),
|
|
4897
4920
|
lineSegment3(rotatedA, rotatedB)
|
|
4898
|
-
).map((p) =>
|
|
4921
|
+
).map((p) => pointRotateRads5(p, center, element.angle));
|
|
4899
4922
|
};
|
|
4900
4923
|
var isPointOnElementOutline = (point, element, elementsMap, tolerance = 1) => distanceToElement(element, elementsMap, point) <= tolerance;
|
|
4901
4924
|
var isPointInElement = (point, element, elementsMap) => {
|
|
@@ -4903,10 +4926,10 @@ var isPointInElement = (point, element, elementsMap) => {
|
|
|
4903
4926
|
return false;
|
|
4904
4927
|
}
|
|
4905
4928
|
const [x1, y1, x2, y2] = getElementBounds(element, elementsMap);
|
|
4906
|
-
if (!isPointWithinBounds(
|
|
4929
|
+
if (!isPointWithinBounds(pointFrom5(x1, y1), point, pointFrom5(x2, y2))) {
|
|
4907
4930
|
return false;
|
|
4908
4931
|
}
|
|
4909
|
-
const center =
|
|
4932
|
+
const center = pointFrom5((x1 + x2) / 2, (y1 + y2) / 2);
|
|
4910
4933
|
const otherPoint = pointFromVector3(
|
|
4911
4934
|
vectorScale3(
|
|
4912
4935
|
vectorNormalize2(vectorFromPoint3(point, center, 0.1)),
|
|
@@ -4927,9 +4950,9 @@ var isPointInElement = (point, element, elementsMap) => {
|
|
|
4927
4950
|
init_define_import_meta_env();
|
|
4928
4951
|
import { invariant as invariant3, isDevEnv as isDevEnv2, isTestEnv as isTestEnv3 } from "@excalidraw/common";
|
|
4929
4952
|
import {
|
|
4930
|
-
pointFrom as
|
|
4953
|
+
pointFrom as pointFrom6,
|
|
4931
4954
|
pointFromVector as pointFromVector4,
|
|
4932
|
-
pointRotateRads as
|
|
4955
|
+
pointRotateRads as pointRotateRads6,
|
|
4933
4956
|
pointScaleFromOrigin,
|
|
4934
4957
|
pointsEqual as pointsEqual3,
|
|
4935
4958
|
triangleIncludesPoint,
|
|
@@ -4975,8 +4998,8 @@ var headingForPointFromDiamondElement = (element, aabb, point) => {
|
|
|
4975
4998
|
const top = pointFromVector4(
|
|
4976
4999
|
vectorScale4(
|
|
4977
5000
|
vectorFromPoint4(
|
|
4978
|
-
|
|
4979
|
-
|
|
5001
|
+
pointRotateRads6(
|
|
5002
|
+
pointFrom6(element.x + element.width / 2, element.y),
|
|
4980
5003
|
midPoint,
|
|
4981
5004
|
element.angle
|
|
4982
5005
|
),
|
|
@@ -4989,8 +5012,8 @@ var headingForPointFromDiamondElement = (element, aabb, point) => {
|
|
|
4989
5012
|
const right = pointFromVector4(
|
|
4990
5013
|
vectorScale4(
|
|
4991
5014
|
vectorFromPoint4(
|
|
4992
|
-
|
|
4993
|
-
|
|
5015
|
+
pointRotateRads6(
|
|
5016
|
+
pointFrom6(
|
|
4994
5017
|
element.x + element.width,
|
|
4995
5018
|
element.y + element.height / 2
|
|
4996
5019
|
),
|
|
@@ -5006,8 +5029,8 @@ var headingForPointFromDiamondElement = (element, aabb, point) => {
|
|
|
5006
5029
|
const bottom = pointFromVector4(
|
|
5007
5030
|
vectorScale4(
|
|
5008
5031
|
vectorFromPoint4(
|
|
5009
|
-
|
|
5010
|
-
|
|
5032
|
+
pointRotateRads6(
|
|
5033
|
+
pointFrom6(
|
|
5011
5034
|
element.x + element.width / 2,
|
|
5012
5035
|
element.y + element.height
|
|
5013
5036
|
),
|
|
@@ -5023,8 +5046,8 @@ var headingForPointFromDiamondElement = (element, aabb, point) => {
|
|
|
5023
5046
|
const left = pointFromVector4(
|
|
5024
5047
|
vectorScale4(
|
|
5025
5048
|
vectorFromPoint4(
|
|
5026
|
-
|
|
5027
|
-
|
|
5049
|
+
pointRotateRads6(
|
|
5050
|
+
pointFrom6(element.x, element.y + element.height / 2),
|
|
5028
5051
|
midPoint,
|
|
5029
5052
|
element.angle
|
|
5030
5053
|
),
|
|
@@ -5090,22 +5113,22 @@ var headingForPointFromElement = (element, aabb, p) => {
|
|
|
5090
5113
|
return headingForPointFromDiamondElement(element, aabb, p);
|
|
5091
5114
|
}
|
|
5092
5115
|
const topLeft = pointScaleFromOrigin(
|
|
5093
|
-
|
|
5116
|
+
pointFrom6(aabb[0], aabb[1]),
|
|
5094
5117
|
midPoint,
|
|
5095
5118
|
SEARCH_CONE_MULTIPLIER
|
|
5096
5119
|
);
|
|
5097
5120
|
const topRight = pointScaleFromOrigin(
|
|
5098
|
-
|
|
5121
|
+
pointFrom6(aabb[2], aabb[1]),
|
|
5099
5122
|
midPoint,
|
|
5100
5123
|
SEARCH_CONE_MULTIPLIER
|
|
5101
5124
|
);
|
|
5102
5125
|
const bottomLeft = pointScaleFromOrigin(
|
|
5103
|
-
|
|
5126
|
+
pointFrom6(aabb[0], aabb[3]),
|
|
5104
5127
|
midPoint,
|
|
5105
5128
|
SEARCH_CONE_MULTIPLIER
|
|
5106
5129
|
);
|
|
5107
5130
|
const bottomRight = pointScaleFromOrigin(
|
|
5108
|
-
|
|
5131
|
+
pointFrom6(aabb[2], aabb[3]),
|
|
5109
5132
|
midPoint,
|
|
5110
5133
|
SEARCH_CONE_MULTIPLIER
|
|
5111
5134
|
);
|
|
@@ -5138,7 +5161,7 @@ init_define_import_meta_env();
|
|
|
5138
5161
|
import {
|
|
5139
5162
|
clamp as clamp2,
|
|
5140
5163
|
pointDistance as pointDistance3,
|
|
5141
|
-
pointFrom as
|
|
5164
|
+
pointFrom as pointFrom7,
|
|
5142
5165
|
pointScaleFromOrigin as pointScaleFromOrigin2,
|
|
5143
5166
|
pointsEqual as pointsEqual4,
|
|
5144
5167
|
pointTranslate,
|
|
@@ -5162,7 +5185,7 @@ var handleSegmentRenormalization = (arrow, elementsMap) => {
|
|
|
5162
5185
|
const nextFixedSegments = arrow.fixedSegments ? arrow.fixedSegments.slice() : null;
|
|
5163
5186
|
if (nextFixedSegments) {
|
|
5164
5187
|
const _nextPoints = [];
|
|
5165
|
-
arrow.points.map((p) =>
|
|
5188
|
+
arrow.points.map((p) => pointFrom7(arrow.x + p[0], arrow.y + p[1])).forEach((p, i, points) => {
|
|
5166
5189
|
if (i < 2) {
|
|
5167
5190
|
return _nextPoints.push(p);
|
|
5168
5191
|
}
|
|
@@ -5180,7 +5203,7 @@ var handleSegmentRenormalization = (arrow, elementsMap) => {
|
|
|
5180
5203
|
) ?? -1;
|
|
5181
5204
|
const segmentIdx = nextFixedSegments?.findIndex((segment) => segment.index === i) ?? -1;
|
|
5182
5205
|
if (segmentIdx !== -1) {
|
|
5183
|
-
nextFixedSegments[segmentIdx].start =
|
|
5206
|
+
nextFixedSegments[segmentIdx].start = pointFrom7(
|
|
5184
5207
|
points[i - 2][0] - arrow.x,
|
|
5185
5208
|
points[i - 2][1] - arrow.y
|
|
5186
5209
|
);
|
|
@@ -5222,7 +5245,7 @@ var handleSegmentRenormalization = (arrow, elementsMap) => {
|
|
|
5222
5245
|
});
|
|
5223
5246
|
const isHorizontal = headingForPointIsHorizontal(p, points[i - 1]);
|
|
5224
5247
|
return nextPoints.push(
|
|
5225
|
-
|
|
5248
|
+
pointFrom7(
|
|
5226
5249
|
!isHorizontal ? points[i - 2][0] : p[0],
|
|
5227
5250
|
isHorizontal ? points[i - 2][1] : p[1]
|
|
5228
5251
|
)
|
|
@@ -5243,7 +5266,7 @@ var handleSegmentRenormalization = (arrow, elementsMap) => {
|
|
|
5243
5266
|
arrow,
|
|
5244
5267
|
elementsMap,
|
|
5245
5268
|
nextPoints.map(
|
|
5246
|
-
(p) =>
|
|
5269
|
+
(p) => pointFrom7(p[0] - arrow.x, p[1] - arrow.y)
|
|
5247
5270
|
)
|
|
5248
5271
|
)
|
|
5249
5272
|
) ?? []
|
|
@@ -5312,8 +5335,8 @@ var handleSegmentRelease = (arrow, fixedSegments, elementsMap) => {
|
|
|
5312
5335
|
},
|
|
5313
5336
|
elementsMap,
|
|
5314
5337
|
[
|
|
5315
|
-
|
|
5316
|
-
|
|
5338
|
+
pointFrom7(0, 0),
|
|
5339
|
+
pointFrom7(
|
|
5317
5340
|
arrow.x + (nextSegment?.start[0] ?? arrow.points[arrow.points.length - 1][0]) - x,
|
|
5318
5341
|
arrow.y + (nextSegment?.start[1] ?? arrow.points[arrow.points.length - 1][1]) - y
|
|
5319
5342
|
)
|
|
@@ -5338,11 +5361,16 @@ var handleSegmentRelease = (arrow, fixedSegments, elementsMap) => {
|
|
|
5338
5361
|
null,
|
|
5339
5362
|
null
|
|
5340
5363
|
);
|
|
5364
|
+
if (!restoredPoints || restoredPoints.length < 2) {
|
|
5365
|
+
throw new Error(
|
|
5366
|
+
"Property 'points' is required in the update returned by normalizeArrowElementUpdate()"
|
|
5367
|
+
);
|
|
5368
|
+
}
|
|
5341
5369
|
const nextPoints = [];
|
|
5342
5370
|
if (prevSegment) {
|
|
5343
5371
|
for (let i = 0; i < prevSegment.index; i++) {
|
|
5344
5372
|
nextPoints.push(
|
|
5345
|
-
|
|
5373
|
+
pointFrom7(
|
|
5346
5374
|
arrow.x + arrow.points[i][0],
|
|
5347
5375
|
arrow.y + arrow.points[i][1]
|
|
5348
5376
|
)
|
|
@@ -5351,7 +5379,7 @@ var handleSegmentRelease = (arrow, fixedSegments, elementsMap) => {
|
|
|
5351
5379
|
}
|
|
5352
5380
|
restoredPoints.forEach((p) => {
|
|
5353
5381
|
nextPoints.push(
|
|
5354
|
-
|
|
5382
|
+
pointFrom7(
|
|
5355
5383
|
arrow.x + (prevSegment ? prevSegment.end[0] : 0) + p[0],
|
|
5356
5384
|
arrow.y + (prevSegment ? prevSegment.end[1] : 0) + p[1]
|
|
5357
5385
|
)
|
|
@@ -5360,7 +5388,7 @@ var handleSegmentRelease = (arrow, fixedSegments, elementsMap) => {
|
|
|
5360
5388
|
if (nextSegment) {
|
|
5361
5389
|
for (let i = nextSegment.index; i < arrow.points.length; i++) {
|
|
5362
5390
|
nextPoints.push(
|
|
5363
|
-
|
|
5391
|
+
pointFrom7(
|
|
5364
5392
|
arrow.x + arrow.points[i][0],
|
|
5365
5393
|
arrow.y + arrow.points[i][1]
|
|
5366
5394
|
)
|
|
@@ -5431,7 +5459,7 @@ var handleSegmentMove = (arrow, fixedSegments, startHeading, endHeading, hovered
|
|
|
5431
5459
|
const startIsHorizontal = headingIsHorizontal(startHeading);
|
|
5432
5460
|
const startIsPositive = startIsHorizontal ? compareHeading(startHeading, HEADING_RIGHT) : compareHeading(startHeading, HEADING_DOWN);
|
|
5433
5461
|
const padding = startIsPositive ? segmentIsTooShort ? segmentLength / 2 : BASE_PADDING : segmentIsTooShort ? -segmentLength / 2 : -BASE_PADDING;
|
|
5434
|
-
fixedSegments[activelyModifiedSegmentIdx].start =
|
|
5462
|
+
fixedSegments[activelyModifiedSegmentIdx].start = pointFrom7(
|
|
5435
5463
|
fixedSegments[activelyModifiedSegmentIdx].start[0] + (startIsHorizontal ? padding : 0),
|
|
5436
5464
|
fixedSegments[activelyModifiedSegmentIdx].start[1] + (!startIsHorizontal ? padding : 0)
|
|
5437
5465
|
);
|
|
@@ -5440,24 +5468,24 @@ var handleSegmentMove = (arrow, fixedSegments, startHeading, endHeading, hovered
|
|
|
5440
5468
|
const endIsHorizontal = headingIsHorizontal(endHeading);
|
|
5441
5469
|
const endIsPositive = endIsHorizontal ? compareHeading(endHeading, HEADING_RIGHT) : compareHeading(endHeading, HEADING_DOWN);
|
|
5442
5470
|
const padding = endIsPositive ? segmentIsTooShort ? segmentLength / 2 : BASE_PADDING : segmentIsTooShort ? -segmentLength / 2 : -BASE_PADDING;
|
|
5443
|
-
fixedSegments[activelyModifiedSegmentIdx].end =
|
|
5471
|
+
fixedSegments[activelyModifiedSegmentIdx].end = pointFrom7(
|
|
5444
5472
|
fixedSegments[activelyModifiedSegmentIdx].end[0] + (endIsHorizontal ? padding : 0),
|
|
5445
5473
|
fixedSegments[activelyModifiedSegmentIdx].end[1] + (!endIsHorizontal ? padding : 0)
|
|
5446
5474
|
);
|
|
5447
5475
|
}
|
|
5448
5476
|
const nextFixedSegments = fixedSegments.map((segment) => ({
|
|
5449
5477
|
...segment,
|
|
5450
|
-
start:
|
|
5478
|
+
start: pointFrom7(
|
|
5451
5479
|
arrow.x + segment.start[0],
|
|
5452
5480
|
arrow.y + segment.start[1]
|
|
5453
5481
|
),
|
|
5454
|
-
end:
|
|
5482
|
+
end: pointFrom7(
|
|
5455
5483
|
arrow.x + segment.end[0],
|
|
5456
5484
|
arrow.y + segment.end[1]
|
|
5457
5485
|
)
|
|
5458
5486
|
}));
|
|
5459
5487
|
const newPoints = arrow.points.map(
|
|
5460
|
-
(p, i) =>
|
|
5488
|
+
(p, i) => pointFrom7(arrow.x + p[0], arrow.y + p[1])
|
|
5461
5489
|
);
|
|
5462
5490
|
const startIdx = nextFixedSegments[activelyModifiedSegmentIdx].index - 1;
|
|
5463
5491
|
const endIdx = nextFixedSegments[activelyModifiedSegmentIdx].index;
|
|
@@ -5503,14 +5531,14 @@ var handleSegmentMove = (arrow, fixedSegments, startHeading, endHeading, hovered
|
|
|
5503
5531
|
if (firstSegmentIdx === -1 && startIdx === 0) {
|
|
5504
5532
|
const startIsHorizontal = hoveredStartElement ? headingIsHorizontal(startHeading) : headingForPointIsHorizontal(newPoints[1], newPoints[0]);
|
|
5505
5533
|
newPoints.unshift(
|
|
5506
|
-
|
|
5534
|
+
pointFrom7(
|
|
5507
5535
|
startIsHorizontal ? start[0] : arrow.x + arrow.points[0][0],
|
|
5508
5536
|
!startIsHorizontal ? start[1] : arrow.y + arrow.points[0][1]
|
|
5509
5537
|
)
|
|
5510
5538
|
);
|
|
5511
5539
|
if (hoveredStartElement) {
|
|
5512
5540
|
newPoints.unshift(
|
|
5513
|
-
|
|
5541
|
+
pointFrom7(
|
|
5514
5542
|
arrow.x + arrow.points[0][0],
|
|
5515
5543
|
arrow.y + arrow.points[0][1]
|
|
5516
5544
|
)
|
|
@@ -5523,14 +5551,14 @@ var handleSegmentMove = (arrow, fixedSegments, startHeading, endHeading, hovered
|
|
|
5523
5551
|
if (lastSegmentIdx === -1 && endIdx === arrow.points.length - 1) {
|
|
5524
5552
|
const endIsHorizontal = headingIsHorizontal(endHeading);
|
|
5525
5553
|
newPoints.push(
|
|
5526
|
-
|
|
5554
|
+
pointFrom7(
|
|
5527
5555
|
endIsHorizontal ? end[0] : arrow.x + arrow.points[arrow.points.length - 1][0],
|
|
5528
5556
|
!endIsHorizontal ? end[1] : arrow.y + arrow.points[arrow.points.length - 1][1]
|
|
5529
5557
|
)
|
|
5530
5558
|
);
|
|
5531
5559
|
if (hoveredEndElement) {
|
|
5532
5560
|
newPoints.push(
|
|
5533
|
-
|
|
5561
|
+
pointFrom7(
|
|
5534
5562
|
arrow.x + arrow.points[arrow.points.length - 1][0],
|
|
5535
5563
|
arrow.y + arrow.points[arrow.points.length - 1][1]
|
|
5536
5564
|
)
|
|
@@ -5541,11 +5569,11 @@ var handleSegmentMove = (arrow, fixedSegments, startHeading, endHeading, hovered
|
|
|
5541
5569
|
newPoints,
|
|
5542
5570
|
nextFixedSegments.map((segment) => ({
|
|
5543
5571
|
...segment,
|
|
5544
|
-
start:
|
|
5572
|
+
start: pointFrom7(
|
|
5545
5573
|
segment.start[0] - arrow.x,
|
|
5546
5574
|
segment.start[1] - arrow.y
|
|
5547
5575
|
),
|
|
5548
|
-
end:
|
|
5576
|
+
end: pointFrom7(
|
|
5549
5577
|
segment.end[0] - arrow.x,
|
|
5550
5578
|
segment.end[1] - arrow.y
|
|
5551
5579
|
)
|
|
@@ -5560,18 +5588,18 @@ var handleEndpointDrag = (arrow, updatedPoints, fixedSegments, startHeading, end
|
|
|
5560
5588
|
let startIsSpecial = arrow.startIsSpecial ?? null;
|
|
5561
5589
|
let endIsSpecial = arrow.endIsSpecial ?? null;
|
|
5562
5590
|
const globalUpdatedPoints = updatedPoints.map(
|
|
5563
|
-
(p, i) => i === 0 ?
|
|
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(
|
|
5564
5592
|
arrow.x + arrow.points[i][0],
|
|
5565
5593
|
arrow.y + arrow.points[i][1]
|
|
5566
5594
|
)
|
|
5567
5595
|
);
|
|
5568
5596
|
const nextFixedSegments = fixedSegments.map((segment) => ({
|
|
5569
5597
|
...segment,
|
|
5570
|
-
start:
|
|
5598
|
+
start: pointFrom7(
|
|
5571
5599
|
arrow.x + (segment.start[0] - updatedPoints[0][0]),
|
|
5572
5600
|
arrow.y + (segment.start[1] - updatedPoints[0][1])
|
|
5573
5601
|
),
|
|
5574
|
-
end:
|
|
5602
|
+
end: pointFrom7(
|
|
5575
5603
|
arrow.x + (segment.end[0] - updatedPoints[0][0]),
|
|
5576
5604
|
arrow.y + (segment.end[1] - updatedPoints[0][1])
|
|
5577
5605
|
)
|
|
@@ -5583,8 +5611,13 @@ var handleEndpointDrag = (arrow, updatedPoints, fixedSegments, startHeading, end
|
|
|
5583
5611
|
newPoints.push(globalUpdatedPoints[newPoints.length + offset]);
|
|
5584
5612
|
}
|
|
5585
5613
|
{
|
|
5586
|
-
const secondPoint = globalUpdatedPoints
|
|
5587
|
-
const thirdPoint = globalUpdatedPoints
|
|
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
|
+
}
|
|
5588
5621
|
const startIsHorizontal = headingIsHorizontal(startHeading);
|
|
5589
5622
|
const secondIsHorizontal = headingIsHorizontal(
|
|
5590
5623
|
vectorToHeading(vectorFromPoint5(secondPoint, thirdPoint))
|
|
@@ -5592,13 +5625,13 @@ var handleEndpointDrag = (arrow, updatedPoints, fixedSegments, startHeading, end
|
|
|
5592
5625
|
if (hoveredStartElement && startIsHorizontal === secondIsHorizontal) {
|
|
5593
5626
|
const positive = startIsHorizontal ? compareHeading(startHeading, HEADING_RIGHT) : compareHeading(startHeading, HEADING_DOWN);
|
|
5594
5627
|
newPoints.unshift(
|
|
5595
|
-
|
|
5628
|
+
pointFrom7(
|
|
5596
5629
|
!secondIsHorizontal ? thirdPoint[0] : startGlobalPoint[0] + (positive ? BASE_PADDING : -BASE_PADDING),
|
|
5597
5630
|
secondIsHorizontal ? thirdPoint[1] : startGlobalPoint[1] + (positive ? BASE_PADDING : -BASE_PADDING)
|
|
5598
5631
|
)
|
|
5599
5632
|
);
|
|
5600
5633
|
newPoints.unshift(
|
|
5601
|
-
|
|
5634
|
+
pointFrom7(
|
|
5602
5635
|
startIsHorizontal ? startGlobalPoint[0] + (positive ? BASE_PADDING : -BASE_PADDING) : startGlobalPoint[0],
|
|
5603
5636
|
!startIsHorizontal ? startGlobalPoint[1] + (positive ? BASE_PADDING : -BASE_PADDING) : startGlobalPoint[1]
|
|
5604
5637
|
)
|
|
@@ -5613,7 +5646,7 @@ var handleEndpointDrag = (arrow, updatedPoints, fixedSegments, startHeading, end
|
|
|
5613
5646
|
}
|
|
5614
5647
|
} else {
|
|
5615
5648
|
newPoints.unshift(
|
|
5616
|
-
|
|
5649
|
+
pointFrom7(
|
|
5617
5650
|
!secondIsHorizontal ? secondPoint[0] : startGlobalPoint[0],
|
|
5618
5651
|
secondIsHorizontal ? secondPoint[1] : startGlobalPoint[1]
|
|
5619
5652
|
)
|
|
@@ -5630,8 +5663,17 @@ var handleEndpointDrag = (arrow, updatedPoints, fixedSegments, startHeading, end
|
|
|
5630
5663
|
newPoints.unshift(startGlobalPoint);
|
|
5631
5664
|
}
|
|
5632
5665
|
{
|
|
5633
|
-
const secondToLastPoint = globalUpdatedPoints
|
|
5634
|
-
|
|
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
|
+
}
|
|
5635
5677
|
const endIsHorizontal = headingIsHorizontal(endHeading);
|
|
5636
5678
|
const secondIsHorizontal = headingForPointIsHorizontal(
|
|
5637
5679
|
thirdToLastPoint,
|
|
@@ -5640,13 +5682,13 @@ var handleEndpointDrag = (arrow, updatedPoints, fixedSegments, startHeading, end
|
|
|
5640
5682
|
if (hoveredEndElement && endIsHorizontal === secondIsHorizontal) {
|
|
5641
5683
|
const positive = endIsHorizontal ? compareHeading(endHeading, HEADING_RIGHT) : compareHeading(endHeading, HEADING_DOWN);
|
|
5642
5684
|
newPoints.push(
|
|
5643
|
-
|
|
5685
|
+
pointFrom7(
|
|
5644
5686
|
!secondIsHorizontal ? thirdToLastPoint[0] : endGlobalPoint[0] + (positive ? BASE_PADDING : -BASE_PADDING),
|
|
5645
5687
|
secondIsHorizontal ? thirdToLastPoint[1] : endGlobalPoint[1] + (positive ? BASE_PADDING : -BASE_PADDING)
|
|
5646
5688
|
)
|
|
5647
5689
|
);
|
|
5648
5690
|
newPoints.push(
|
|
5649
|
-
|
|
5691
|
+
pointFrom7(
|
|
5650
5692
|
endIsHorizontal ? endGlobalPoint[0] + (positive ? BASE_PADDING : -BASE_PADDING) : endGlobalPoint[0],
|
|
5651
5693
|
!endIsHorizontal ? endGlobalPoint[1] + (positive ? BASE_PADDING : -BASE_PADDING) : endGlobalPoint[1]
|
|
5652
5694
|
)
|
|
@@ -5656,7 +5698,7 @@ var handleEndpointDrag = (arrow, updatedPoints, fixedSegments, startHeading, end
|
|
|
5656
5698
|
}
|
|
5657
5699
|
} else {
|
|
5658
5700
|
newPoints.push(
|
|
5659
|
-
|
|
5701
|
+
pointFrom7(
|
|
5660
5702
|
!secondIsHorizontal ? secondToLastPoint[0] : endGlobalPoint[0],
|
|
5661
5703
|
secondIsHorizontal ? secondToLastPoint[1] : endGlobalPoint[1]
|
|
5662
5704
|
)
|
|
@@ -5675,11 +5717,11 @@ var handleEndpointDrag = (arrow, updatedPoints, fixedSegments, startHeading, end
|
|
|
5675
5717
|
end: newPoints[index]
|
|
5676
5718
|
})).map((segment) => ({
|
|
5677
5719
|
...segment,
|
|
5678
|
-
start:
|
|
5720
|
+
start: pointFrom7(
|
|
5679
5721
|
segment.start[0] - startGlobalPoint[0],
|
|
5680
5722
|
segment.start[1] - startGlobalPoint[1]
|
|
5681
5723
|
),
|
|
5682
|
-
end:
|
|
5724
|
+
end: pointFrom7(
|
|
5683
5725
|
segment.end[0] - startGlobalPoint[0],
|
|
5684
5726
|
segment.end[1] - startGlobalPoint[1]
|
|
5685
5727
|
)
|
|
@@ -5741,7 +5783,7 @@ var updateElbowArrowPoints = (arrow, elementsMap, updates, options) => {
|
|
|
5741
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)) {
|
|
5742
5784
|
return normalizeArrowElementUpdate(
|
|
5743
5785
|
updatedPoints.map(
|
|
5744
|
-
(p) =>
|
|
5786
|
+
(p) => pointFrom7(arrow.x + p[0], arrow.y + p[1])
|
|
5745
5787
|
),
|
|
5746
5788
|
arrow.fixedSegments,
|
|
5747
5789
|
arrow.startIsSpecial,
|
|
@@ -5773,7 +5815,7 @@ var updateElbowArrowPoints = (arrow, elementsMap, updates, options) => {
|
|
|
5773
5815
|
if (elementsMap.size === 0 && areUpdatedPointsValid) {
|
|
5774
5816
|
return normalizeArrowElementUpdate(
|
|
5775
5817
|
updatedPoints.map(
|
|
5776
|
-
(p) =>
|
|
5818
|
+
(p) => pointFrom7(arrow.x + p[0], arrow.y + p[1])
|
|
5777
5819
|
),
|
|
5778
5820
|
arrow.fixedSegments,
|
|
5779
5821
|
arrow.startIsSpecial,
|
|
@@ -5786,7 +5828,7 @@ var updateElbowArrowPoints = (arrow, elementsMap, updates, options) => {
|
|
|
5786
5828
|
if (updates.startBinding === arrow.startBinding && updates.endBinding === arrow.endBinding && (updates.points ?? []).every(
|
|
5787
5829
|
(p, i) => pointsEqual4(
|
|
5788
5830
|
p,
|
|
5789
|
-
arrow.points[i] ??
|
|
5831
|
+
arrow.points[i] ?? pointFrom7(Infinity, Infinity)
|
|
5790
5832
|
)
|
|
5791
5833
|
) && areUpdatedPointsValid) {
|
|
5792
5834
|
return {};
|
|
@@ -6280,13 +6322,13 @@ var calculateGrid = (aabbs, start, startHeading, end, endHeading, common) => {
|
|
|
6280
6322
|
var getDonglePosition = (bounds, heading, p) => {
|
|
6281
6323
|
switch (heading) {
|
|
6282
6324
|
case HEADING_UP:
|
|
6283
|
-
return
|
|
6325
|
+
return pointFrom7(p[0], bounds[1]);
|
|
6284
6326
|
case HEADING_RIGHT:
|
|
6285
|
-
return
|
|
6327
|
+
return pointFrom7(bounds[2], p[1]);
|
|
6286
6328
|
case HEADING_DOWN:
|
|
6287
|
-
return
|
|
6329
|
+
return pointFrom7(p[0], bounds[3]);
|
|
6288
6330
|
}
|
|
6289
|
-
return
|
|
6331
|
+
return pointFrom7(bounds[0], p[1]);
|
|
6290
6332
|
};
|
|
6291
6333
|
var estimateSegmentCount = (start, end, startHeading, endHeading) => {
|
|
6292
6334
|
if (endHeading === HEADING_RIGHT) {
|
|
@@ -6454,7 +6496,7 @@ var normalizeArrowElementUpdate = (global2, nextFixedSegments, startIsSpecial, e
|
|
|
6454
6496
|
);
|
|
6455
6497
|
}
|
|
6456
6498
|
points = points.map(
|
|
6457
|
-
([x, y]) =>
|
|
6499
|
+
([x, y]) => pointFrom7(clamp2(x, -1e6, 1e6), clamp2(y, -1e6, 1e6))
|
|
6458
6500
|
);
|
|
6459
6501
|
return {
|
|
6460
6502
|
points,
|
|
@@ -7192,7 +7234,7 @@ var bindPointToSnapToElementOutline = (arrow, bindableElement, startOrEnd, eleme
|
|
|
7192
7234
|
}
|
|
7193
7235
|
const aabb = aabbForElement(bindableElement, elementsMap);
|
|
7194
7236
|
const localP = arrow.points[startOrEnd === "start" ? 0 : arrow.points.length - 1];
|
|
7195
|
-
const globalP =
|
|
7237
|
+
const globalP = pointFrom8(
|
|
7196
7238
|
arrow.x + localP[0],
|
|
7197
7239
|
arrow.y + localP[1]
|
|
7198
7240
|
);
|
|
@@ -7200,8 +7242,8 @@ var bindPointToSnapToElementOutline = (arrow, bindableElement, startOrEnd, eleme
|
|
|
7200
7242
|
const elbowed = isElbowArrow(arrow);
|
|
7201
7243
|
const center = getCenterForBounds(aabb);
|
|
7202
7244
|
const adjacentPointIdx = startOrEnd === "start" ? 1 : arrow.points.length - 2;
|
|
7203
|
-
const adjacentPoint =
|
|
7204
|
-
|
|
7245
|
+
const adjacentPoint = pointRotateRads7(
|
|
7246
|
+
pointFrom8(
|
|
7205
7247
|
arrow.x + arrow.points[adjacentPointIdx][0],
|
|
7206
7248
|
arrow.y + arrow.points[adjacentPointIdx][1]
|
|
7207
7249
|
),
|
|
@@ -7214,7 +7256,7 @@ var bindPointToSnapToElementOutline = (arrow, bindableElement, startOrEnd, eleme
|
|
|
7214
7256
|
headingForPointFromElement(bindableElement, aabb, globalP)
|
|
7215
7257
|
);
|
|
7216
7258
|
const snapPoint = snapToMid(bindableElement, elementsMap, edgePoint);
|
|
7217
|
-
const otherPoint =
|
|
7259
|
+
const otherPoint = pointFrom8(
|
|
7218
7260
|
isHorizontal ? center[0] : snapPoint[0],
|
|
7219
7261
|
!isHorizontal ? center[1] : snapPoint[1]
|
|
7220
7262
|
);
|
|
@@ -7234,6 +7276,28 @@ var bindPointToSnapToElementOutline = (arrow, bindableElement, startOrEnd, eleme
|
|
|
7234
7276
|
intersector,
|
|
7235
7277
|
FIXED_BINDING_DISTANCE
|
|
7236
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
|
+
}
|
|
7237
7301
|
} else {
|
|
7238
7302
|
intersection = intersectElementWithLineSegment(
|
|
7239
7303
|
bindableElement,
|
|
@@ -7261,24 +7325,24 @@ var bindPointToSnapToElementOutline = (arrow, bindableElement, startOrEnd, eleme
|
|
|
7261
7325
|
};
|
|
7262
7326
|
var avoidRectangularCorner = (element, elementsMap, p) => {
|
|
7263
7327
|
const center = elementCenterPoint(element, elementsMap);
|
|
7264
|
-
const nonRotatedPoint =
|
|
7328
|
+
const nonRotatedPoint = pointRotateRads7(p, center, -element.angle);
|
|
7265
7329
|
if (nonRotatedPoint[0] < element.x && nonRotatedPoint[1] < element.y) {
|
|
7266
7330
|
if (nonRotatedPoint[1] - element.y > -FIXED_BINDING_DISTANCE) {
|
|
7267
|
-
return
|
|
7268
|
-
|
|
7331
|
+
return pointRotateRads7(
|
|
7332
|
+
pointFrom8(element.x - FIXED_BINDING_DISTANCE, element.y),
|
|
7269
7333
|
center,
|
|
7270
7334
|
element.angle
|
|
7271
7335
|
);
|
|
7272
7336
|
}
|
|
7273
|
-
return
|
|
7274
|
-
|
|
7337
|
+
return pointRotateRads7(
|
|
7338
|
+
pointFrom8(element.x, element.y - FIXED_BINDING_DISTANCE),
|
|
7275
7339
|
center,
|
|
7276
7340
|
element.angle
|
|
7277
7341
|
);
|
|
7278
7342
|
} else if (nonRotatedPoint[0] < element.x && nonRotatedPoint[1] > element.y + element.height) {
|
|
7279
7343
|
if (nonRotatedPoint[0] - element.x > -FIXED_BINDING_DISTANCE) {
|
|
7280
|
-
return
|
|
7281
|
-
|
|
7344
|
+
return pointRotateRads7(
|
|
7345
|
+
pointFrom8(
|
|
7282
7346
|
element.x,
|
|
7283
7347
|
element.y + element.height + FIXED_BINDING_DISTANCE
|
|
7284
7348
|
),
|
|
@@ -7286,15 +7350,15 @@ var avoidRectangularCorner = (element, elementsMap, p) => {
|
|
|
7286
7350
|
element.angle
|
|
7287
7351
|
);
|
|
7288
7352
|
}
|
|
7289
|
-
return
|
|
7290
|
-
|
|
7353
|
+
return pointRotateRads7(
|
|
7354
|
+
pointFrom8(element.x - FIXED_BINDING_DISTANCE, element.y + element.height),
|
|
7291
7355
|
center,
|
|
7292
7356
|
element.angle
|
|
7293
7357
|
);
|
|
7294
7358
|
} else if (nonRotatedPoint[0] > element.x + element.width && nonRotatedPoint[1] > element.y + element.height) {
|
|
7295
7359
|
if (nonRotatedPoint[0] - element.x < element.width + FIXED_BINDING_DISTANCE) {
|
|
7296
|
-
return
|
|
7297
|
-
|
|
7360
|
+
return pointRotateRads7(
|
|
7361
|
+
pointFrom8(
|
|
7298
7362
|
element.x + element.width,
|
|
7299
7363
|
element.y + element.height + FIXED_BINDING_DISTANCE
|
|
7300
7364
|
),
|
|
@@ -7302,8 +7366,8 @@ var avoidRectangularCorner = (element, elementsMap, p) => {
|
|
|
7302
7366
|
element.angle
|
|
7303
7367
|
);
|
|
7304
7368
|
}
|
|
7305
|
-
return
|
|
7306
|
-
|
|
7369
|
+
return pointRotateRads7(
|
|
7370
|
+
pointFrom8(
|
|
7307
7371
|
element.x + element.width + FIXED_BINDING_DISTANCE,
|
|
7308
7372
|
element.y + element.height
|
|
7309
7373
|
),
|
|
@@ -7312,8 +7376,8 @@ var avoidRectangularCorner = (element, elementsMap, p) => {
|
|
|
7312
7376
|
);
|
|
7313
7377
|
} else if (nonRotatedPoint[0] > element.x + element.width && nonRotatedPoint[1] < element.y) {
|
|
7314
7378
|
if (nonRotatedPoint[0] - element.x < element.width + FIXED_BINDING_DISTANCE) {
|
|
7315
|
-
return
|
|
7316
|
-
|
|
7379
|
+
return pointRotateRads7(
|
|
7380
|
+
pointFrom8(
|
|
7317
7381
|
element.x + element.width,
|
|
7318
7382
|
element.y - FIXED_BINDING_DISTANCE
|
|
7319
7383
|
),
|
|
@@ -7321,8 +7385,8 @@ var avoidRectangularCorner = (element, elementsMap, p) => {
|
|
|
7321
7385
|
element.angle
|
|
7322
7386
|
);
|
|
7323
7387
|
}
|
|
7324
|
-
return
|
|
7325
|
-
|
|
7388
|
+
return pointRotateRads7(
|
|
7389
|
+
pointFrom8(element.x + element.width + FIXED_BINDING_DISTANCE, element.y),
|
|
7326
7390
|
center,
|
|
7327
7391
|
element.angle
|
|
7328
7392
|
);
|
|
@@ -7332,62 +7396,62 @@ var avoidRectangularCorner = (element, elementsMap, p) => {
|
|
|
7332
7396
|
var snapToMid = (element, elementsMap, p, tolerance = 0.05) => {
|
|
7333
7397
|
const { x, y, width, height, angle } = element;
|
|
7334
7398
|
const center = elementCenterPoint(element, elementsMap, -0.1, -0.1);
|
|
7335
|
-
const nonRotated =
|
|
7399
|
+
const nonRotated = pointRotateRads7(p, center, -angle);
|
|
7336
7400
|
const verticalThreshold = clamp3(tolerance * height, 5, 80);
|
|
7337
7401
|
const horizontalThreshold = clamp3(tolerance * width, 5, 80);
|
|
7338
7402
|
if (nonRotated[0] <= x + width / 2 && nonRotated[1] > center[1] - verticalThreshold && nonRotated[1] < center[1] + verticalThreshold) {
|
|
7339
|
-
return
|
|
7340
|
-
|
|
7403
|
+
return pointRotateRads7(
|
|
7404
|
+
pointFrom8(x - FIXED_BINDING_DISTANCE, center[1]),
|
|
7341
7405
|
center,
|
|
7342
7406
|
angle
|
|
7343
7407
|
);
|
|
7344
7408
|
} else if (nonRotated[1] <= y + height / 2 && nonRotated[0] > center[0] - horizontalThreshold && nonRotated[0] < center[0] + horizontalThreshold) {
|
|
7345
|
-
return
|
|
7346
|
-
|
|
7409
|
+
return pointRotateRads7(
|
|
7410
|
+
pointFrom8(center[0], y - FIXED_BINDING_DISTANCE),
|
|
7347
7411
|
center,
|
|
7348
7412
|
angle
|
|
7349
7413
|
);
|
|
7350
7414
|
} else if (nonRotated[0] >= x + width / 2 && nonRotated[1] > center[1] - verticalThreshold && nonRotated[1] < center[1] + verticalThreshold) {
|
|
7351
|
-
return
|
|
7352
|
-
|
|
7415
|
+
return pointRotateRads7(
|
|
7416
|
+
pointFrom8(x + width + FIXED_BINDING_DISTANCE, center[1]),
|
|
7353
7417
|
center,
|
|
7354
7418
|
angle
|
|
7355
7419
|
);
|
|
7356
7420
|
} else if (nonRotated[1] >= y + height / 2 && nonRotated[0] > center[0] - horizontalThreshold && nonRotated[0] < center[0] + horizontalThreshold) {
|
|
7357
|
-
return
|
|
7358
|
-
|
|
7421
|
+
return pointRotateRads7(
|
|
7422
|
+
pointFrom8(center[0], y + height + FIXED_BINDING_DISTANCE),
|
|
7359
7423
|
center,
|
|
7360
7424
|
angle
|
|
7361
7425
|
);
|
|
7362
7426
|
} else if (element.type === "diamond") {
|
|
7363
7427
|
const distance3 = FIXED_BINDING_DISTANCE;
|
|
7364
|
-
const topLeft =
|
|
7428
|
+
const topLeft = pointFrom8(
|
|
7365
7429
|
x + width / 4 - distance3,
|
|
7366
7430
|
y + height / 4 - distance3
|
|
7367
7431
|
);
|
|
7368
|
-
const topRight =
|
|
7432
|
+
const topRight = pointFrom8(
|
|
7369
7433
|
x + 3 * width / 4 + distance3,
|
|
7370
7434
|
y + height / 4 - distance3
|
|
7371
7435
|
);
|
|
7372
|
-
const bottomLeft =
|
|
7436
|
+
const bottomLeft = pointFrom8(
|
|
7373
7437
|
x + width / 4 - distance3,
|
|
7374
7438
|
y + 3 * height / 4 + distance3
|
|
7375
7439
|
);
|
|
7376
|
-
const bottomRight =
|
|
7440
|
+
const bottomRight = pointFrom8(
|
|
7377
7441
|
x + 3 * width / 4 + distance3,
|
|
7378
7442
|
y + 3 * height / 4 + distance3
|
|
7379
7443
|
);
|
|
7380
7444
|
if (pointDistance4(topLeft, nonRotated) < Math.max(horizontalThreshold, verticalThreshold)) {
|
|
7381
|
-
return
|
|
7445
|
+
return pointRotateRads7(topLeft, center, angle);
|
|
7382
7446
|
}
|
|
7383
7447
|
if (pointDistance4(topRight, nonRotated) < Math.max(horizontalThreshold, verticalThreshold)) {
|
|
7384
|
-
return
|
|
7448
|
+
return pointRotateRads7(topRight, center, angle);
|
|
7385
7449
|
}
|
|
7386
7450
|
if (pointDistance4(bottomLeft, nonRotated) < Math.max(horizontalThreshold, verticalThreshold)) {
|
|
7387
|
-
return
|
|
7451
|
+
return pointRotateRads7(bottomLeft, center, angle);
|
|
7388
7452
|
}
|
|
7389
7453
|
if (pointDistance4(bottomRight, nonRotated) < Math.max(horizontalThreshold, verticalThreshold)) {
|
|
7390
|
-
return
|
|
7454
|
+
return pointRotateRads7(bottomRight, center, angle);
|
|
7391
7455
|
}
|
|
7392
7456
|
}
|
|
7393
7457
|
return p;
|
|
@@ -7407,11 +7471,11 @@ var updateBoundPoint = (linearElement, startOrEnd, binding, bindableElement, ele
|
|
|
7407
7471
|
elementsMap
|
|
7408
7472
|
).fixedPoint;
|
|
7409
7473
|
const globalMidPoint = elementCenterPoint(bindableElement, elementsMap);
|
|
7410
|
-
const global2 =
|
|
7474
|
+
const global2 = pointFrom8(
|
|
7411
7475
|
bindableElement.x + fixedPoint[0] * bindableElement.width,
|
|
7412
7476
|
bindableElement.y + fixedPoint[1] * bindableElement.height
|
|
7413
7477
|
);
|
|
7414
|
-
const rotatedGlobal =
|
|
7478
|
+
const rotatedGlobal = pointRotateRads7(
|
|
7415
7479
|
global2,
|
|
7416
7480
|
globalMidPoint,
|
|
7417
7481
|
bindableElement.angle
|
|
@@ -7501,11 +7565,11 @@ var calculateFixedPointForElbowArrowBinding = (linearElement, hoveredElement, st
|
|
|
7501
7565
|
startOrEnd,
|
|
7502
7566
|
elementsMap
|
|
7503
7567
|
);
|
|
7504
|
-
const globalMidPoint =
|
|
7568
|
+
const globalMidPoint = pointFrom8(
|
|
7505
7569
|
bounds[0] + (bounds[2] - bounds[0]) / 2,
|
|
7506
7570
|
bounds[1] + (bounds[3] - bounds[1]) / 2
|
|
7507
7571
|
);
|
|
7508
|
-
const nonRotatedSnappedGlobalPoint =
|
|
7572
|
+
const nonRotatedSnappedGlobalPoint = pointRotateRads7(
|
|
7509
7573
|
snappedPoint,
|
|
7510
7574
|
globalMidPoint,
|
|
7511
7575
|
-hoveredElement.angle
|
|
@@ -7638,7 +7702,7 @@ var newBoundElements = (boundElements, idsToRemove, elementsToAdd = []) => {
|
|
|
7638
7702
|
return nextBoundElements;
|
|
7639
7703
|
};
|
|
7640
7704
|
var bindingBorderTest = (element, { x, y }, elementsMap, zoom, fullShape) => {
|
|
7641
|
-
const p =
|
|
7705
|
+
const p = pointFrom8(x, y);
|
|
7642
7706
|
const threshold = maxBindingGap(element, element.width, element.height, zoom);
|
|
7643
7707
|
const shouldTestInside2 = (
|
|
7644
7708
|
// disable fullshape snapping for frame elements so we
|
|
@@ -7680,8 +7744,8 @@ var determineFocusDistance = (element, elementsMap, a2, b2) => {
|
|
|
7680
7744
|
if (pointsEqual5(a2, b2)) {
|
|
7681
7745
|
return 0;
|
|
7682
7746
|
}
|
|
7683
|
-
const rotatedA =
|
|
7684
|
-
const rotatedB =
|
|
7747
|
+
const rotatedA = pointRotateRads7(a2, center, -element.angle);
|
|
7748
|
+
const rotatedB = pointRotateRads7(b2, center, -element.angle);
|
|
7685
7749
|
const sign = Math.sign(
|
|
7686
7750
|
vectorCross3(
|
|
7687
7751
|
vectorFromPoint6(rotatedB, a2),
|
|
@@ -7700,70 +7764,70 @@ var determineFocusDistance = (element, elementsMap, a2, b2) => {
|
|
|
7700
7764
|
);
|
|
7701
7765
|
const axes = element.type === "diamond" ? [
|
|
7702
7766
|
lineSegment4(
|
|
7703
|
-
|
|
7704
|
-
|
|
7767
|
+
pointFrom8(element.x + element.width / 2, element.y),
|
|
7768
|
+
pointFrom8(
|
|
7705
7769
|
element.x + element.width / 2,
|
|
7706
7770
|
element.y + element.height
|
|
7707
7771
|
)
|
|
7708
7772
|
),
|
|
7709
7773
|
lineSegment4(
|
|
7710
|
-
|
|
7711
|
-
|
|
7774
|
+
pointFrom8(element.x, element.y + element.height / 2),
|
|
7775
|
+
pointFrom8(
|
|
7712
7776
|
element.x + element.width,
|
|
7713
7777
|
element.y + element.height / 2
|
|
7714
7778
|
)
|
|
7715
7779
|
)
|
|
7716
7780
|
] : [
|
|
7717
7781
|
lineSegment4(
|
|
7718
|
-
|
|
7719
|
-
|
|
7782
|
+
pointFrom8(element.x, element.y),
|
|
7783
|
+
pointFrom8(
|
|
7720
7784
|
element.x + element.width,
|
|
7721
7785
|
element.y + element.height
|
|
7722
7786
|
)
|
|
7723
7787
|
),
|
|
7724
7788
|
lineSegment4(
|
|
7725
|
-
|
|
7726
|
-
|
|
7789
|
+
pointFrom8(element.x + element.width, element.y),
|
|
7790
|
+
pointFrom8(element.x, element.y + element.height)
|
|
7727
7791
|
)
|
|
7728
7792
|
];
|
|
7729
7793
|
const interceptees = element.type === "diamond" ? [
|
|
7730
7794
|
lineSegment4(
|
|
7731
|
-
|
|
7795
|
+
pointFrom8(
|
|
7732
7796
|
element.x + element.width / 2,
|
|
7733
7797
|
element.y - element.height
|
|
7734
7798
|
),
|
|
7735
|
-
|
|
7799
|
+
pointFrom8(
|
|
7736
7800
|
element.x + element.width / 2,
|
|
7737
7801
|
element.y + element.height * 2
|
|
7738
7802
|
)
|
|
7739
7803
|
),
|
|
7740
7804
|
lineSegment4(
|
|
7741
|
-
|
|
7805
|
+
pointFrom8(
|
|
7742
7806
|
element.x - element.width,
|
|
7743
7807
|
element.y + element.height / 2
|
|
7744
7808
|
),
|
|
7745
|
-
|
|
7809
|
+
pointFrom8(
|
|
7746
7810
|
element.x + element.width * 2,
|
|
7747
7811
|
element.y + element.height / 2
|
|
7748
7812
|
)
|
|
7749
7813
|
)
|
|
7750
7814
|
] : [
|
|
7751
7815
|
lineSegment4(
|
|
7752
|
-
|
|
7816
|
+
pointFrom8(
|
|
7753
7817
|
element.x - element.width,
|
|
7754
7818
|
element.y - element.height
|
|
7755
7819
|
),
|
|
7756
|
-
|
|
7820
|
+
pointFrom8(
|
|
7757
7821
|
element.x + element.width * 2,
|
|
7758
7822
|
element.y + element.height * 2
|
|
7759
7823
|
)
|
|
7760
7824
|
),
|
|
7761
7825
|
lineSegment4(
|
|
7762
|
-
|
|
7826
|
+
pointFrom8(
|
|
7763
7827
|
element.x + element.width * 2,
|
|
7764
7828
|
element.y - element.height
|
|
7765
7829
|
),
|
|
7766
|
-
|
|
7830
|
+
pointFrom8(
|
|
7767
7831
|
element.x - element.width,
|
|
7768
7832
|
element.y + element.height * 2
|
|
7769
7833
|
)
|
|
@@ -7784,30 +7848,30 @@ var determineFocusPoint = (element, elementsMap, focus, adjacentPoint) => {
|
|
|
7784
7848
|
return center;
|
|
7785
7849
|
}
|
|
7786
7850
|
const candidates = (element.type === "diamond" ? [
|
|
7787
|
-
|
|
7788
|
-
|
|
7789
|
-
|
|
7851
|
+
pointFrom8(element.x, element.y + element.height / 2),
|
|
7852
|
+
pointFrom8(element.x + element.width / 2, element.y),
|
|
7853
|
+
pointFrom8(
|
|
7790
7854
|
element.x + element.width,
|
|
7791
7855
|
element.y + element.height / 2
|
|
7792
7856
|
),
|
|
7793
|
-
|
|
7857
|
+
pointFrom8(
|
|
7794
7858
|
element.x + element.width / 2,
|
|
7795
7859
|
element.y + element.height
|
|
7796
7860
|
)
|
|
7797
7861
|
] : [
|
|
7798
|
-
|
|
7799
|
-
|
|
7800
|
-
|
|
7862
|
+
pointFrom8(element.x, element.y),
|
|
7863
|
+
pointFrom8(element.x + element.width, element.y),
|
|
7864
|
+
pointFrom8(
|
|
7801
7865
|
element.x + element.width,
|
|
7802
7866
|
element.y + element.height
|
|
7803
7867
|
),
|
|
7804
|
-
|
|
7868
|
+
pointFrom8(element.x, element.y + element.height)
|
|
7805
7869
|
]).map(
|
|
7806
7870
|
(p) => pointFromVector5(
|
|
7807
7871
|
vectorScale6(vectorFromPoint6(p, center), Math.abs(focus)),
|
|
7808
7872
|
center
|
|
7809
7873
|
)
|
|
7810
|
-
).map((p) =>
|
|
7874
|
+
).map((p) => pointRotateRads7(p, center, element.angle));
|
|
7811
7875
|
const selected = [
|
|
7812
7876
|
vectorCross3(
|
|
7813
7877
|
vectorFromPoint6(adjacentPoint, candidates[0]),
|
|
@@ -8052,8 +8116,8 @@ var BindableElement = class {
|
|
|
8052
8116
|
};
|
|
8053
8117
|
var getGlobalFixedPointForBindableElement = (fixedPointRatio, element, elementsMap) => {
|
|
8054
8118
|
const [fixedX, fixedY] = normalizeFixedPoint(fixedPointRatio);
|
|
8055
|
-
return
|
|
8056
|
-
|
|
8119
|
+
return pointRotateRads7(
|
|
8120
|
+
pointFrom8(
|
|
8057
8121
|
element.x + element.width * fixedX,
|
|
8058
8122
|
element.y + element.height * fixedY
|
|
8059
8123
|
),
|
|
@@ -8068,7 +8132,7 @@ var getGlobalFixedPoints = (arrow, elementsMap) => {
|
|
|
8068
8132
|
arrow.startBinding.fixedPoint,
|
|
8069
8133
|
startElement,
|
|
8070
8134
|
elementsMap
|
|
8071
|
-
) :
|
|
8135
|
+
) : pointFrom8(
|
|
8072
8136
|
arrow.x + arrow.points[0][0],
|
|
8073
8137
|
arrow.y + arrow.points[0][1]
|
|
8074
8138
|
);
|
|
@@ -8076,7 +8140,7 @@ var getGlobalFixedPoints = (arrow, elementsMap) => {
|
|
|
8076
8140
|
arrow.endBinding.fixedPoint,
|
|
8077
8141
|
endElement,
|
|
8078
8142
|
elementsMap
|
|
8079
|
-
) :
|
|
8143
|
+
) : pointFrom8(
|
|
8080
8144
|
arrow.x + arrow.points[arrow.points.length - 1][0],
|
|
8081
8145
|
arrow.y + arrow.points[arrow.points.length - 1][1]
|
|
8082
8146
|
);
|
|
@@ -8106,7 +8170,7 @@ var getNormalizedPoints = ({
|
|
|
8106
8170
|
const offsetY = points[0][1];
|
|
8107
8171
|
return {
|
|
8108
8172
|
points: points.map((p) => {
|
|
8109
|
-
return
|
|
8173
|
+
return pointFrom9(p[0] - offsetX, p[1] - offsetY);
|
|
8110
8174
|
}),
|
|
8111
8175
|
offsetX,
|
|
8112
8176
|
offsetY
|
|
@@ -8130,7 +8194,7 @@ var LinearElementEditor = class _LinearElementEditor {
|
|
|
8130
8194
|
isEditing;
|
|
8131
8195
|
constructor(element, elementsMap, isEditing = false) {
|
|
8132
8196
|
this.elementId = element.id;
|
|
8133
|
-
if (!pointsEqual6(element.points[0],
|
|
8197
|
+
if (!pointsEqual6(element.points[0], pointFrom9(0, 0))) {
|
|
8134
8198
|
console.error("Linear element is not normalized", Error().stack);
|
|
8135
8199
|
mutateElement(
|
|
8136
8200
|
element,
|
|
@@ -8244,7 +8308,7 @@ var LinearElementEditor = class _LinearElementEditor {
|
|
|
8244
8308
|
element,
|
|
8245
8309
|
elementsMap,
|
|
8246
8310
|
referencePoint,
|
|
8247
|
-
|
|
8311
|
+
pointFrom9(scenePointerX, scenePointerY),
|
|
8248
8312
|
event[KEYS2.CTRL_OR_CMD] ? null : app.getEffectiveGridSize(),
|
|
8249
8313
|
customLineAngle
|
|
8250
8314
|
);
|
|
@@ -8255,7 +8319,7 @@ var LinearElementEditor = class _LinearElementEditor {
|
|
|
8255
8319
|
[
|
|
8256
8320
|
selectedIndex,
|
|
8257
8321
|
{
|
|
8258
|
-
point:
|
|
8322
|
+
point: pointFrom9(
|
|
8259
8323
|
width + referencePoint[0],
|
|
8260
8324
|
height + referencePoint[1]
|
|
8261
8325
|
),
|
|
@@ -8285,7 +8349,7 @@ var LinearElementEditor = class _LinearElementEditor {
|
|
|
8285
8349
|
scenePointerX - linearElementEditor.pointerOffset.x,
|
|
8286
8350
|
scenePointerY - linearElementEditor.pointerOffset.y,
|
|
8287
8351
|
event[KEYS2.CTRL_OR_CMD] ? null : app.getEffectiveGridSize()
|
|
8288
|
-
) :
|
|
8352
|
+
) : pointFrom9(
|
|
8289
8353
|
element.points[pointIndex][0] + deltaX,
|
|
8290
8354
|
element.points[pointIndex][1] + deltaY
|
|
8291
8355
|
);
|
|
@@ -8498,11 +8562,11 @@ var LinearElementEditor = class _LinearElementEditor {
|
|
|
8498
8562
|
const existingSegmentMidpointHitCoords = linearElementEditor.segmentMidPointHoveredCoords;
|
|
8499
8563
|
if (existingSegmentMidpointHitCoords) {
|
|
8500
8564
|
const distance3 = pointDistance5(
|
|
8501
|
-
|
|
8565
|
+
pointFrom9(
|
|
8502
8566
|
existingSegmentMidpointHitCoords[0],
|
|
8503
8567
|
existingSegmentMidpointHitCoords[1]
|
|
8504
8568
|
),
|
|
8505
|
-
|
|
8569
|
+
pointFrom9(scenePointer.x, scenePointer.y)
|
|
8506
8570
|
);
|
|
8507
8571
|
if (distance3 <= threshold) {
|
|
8508
8572
|
return existingSegmentMidpointHitCoords;
|
|
@@ -8518,7 +8582,7 @@ var LinearElementEditor = class _LinearElementEditor {
|
|
|
8518
8582
|
if (midPoints[index] !== null) {
|
|
8519
8583
|
const distance3 = pointDistance5(
|
|
8520
8584
|
midPoints[index],
|
|
8521
|
-
|
|
8585
|
+
pointFrom9(scenePointer.x, scenePointer.y)
|
|
8522
8586
|
);
|
|
8523
8587
|
if (distance3 <= threshold) {
|
|
8524
8588
|
return midPoints[index];
|
|
@@ -8557,7 +8621,7 @@ var LinearElementEditor = class _LinearElementEditor {
|
|
|
8557
8621
|
"Invalid segment index while calculating elbow arrow mid point"
|
|
8558
8622
|
);
|
|
8559
8623
|
const p = pointCenter2(element.points[index - 1], element.points[index]);
|
|
8560
|
-
return
|
|
8624
|
+
return pointFrom9(element.x + p[0], element.y + p[1]);
|
|
8561
8625
|
}
|
|
8562
8626
|
const [lines, curves] = deconstructLinearOrFreeDrawElement2(element);
|
|
8563
8627
|
invariant6(
|
|
@@ -8697,12 +8761,12 @@ var LinearElementEditor = class _LinearElementEditor {
|
|
|
8697
8761
|
const [x1, y1, x2, y2] = getElementAbsoluteCoords2(element, elementsMap);
|
|
8698
8762
|
const cx = (x1 + x2) / 2;
|
|
8699
8763
|
const cy = (y1 + y2) / 2;
|
|
8700
|
-
const targetPoint = clickedPointIndex > -1 &&
|
|
8701
|
-
|
|
8764
|
+
const targetPoint = clickedPointIndex > -1 && pointRotateRads8(
|
|
8765
|
+
pointFrom9(
|
|
8702
8766
|
element.x + element.points[clickedPointIndex][0],
|
|
8703
8767
|
element.y + element.points[clickedPointIndex][1]
|
|
8704
8768
|
),
|
|
8705
|
-
|
|
8769
|
+
pointFrom9(cx, cy),
|
|
8706
8770
|
element.angle
|
|
8707
8771
|
);
|
|
8708
8772
|
const nextSelectedPointsIndices = clickedPointIndex > -1 || event.shiftKey ? event.shiftKey || linearElementEditor.selectedPointsIndices?.includes(clickedPointIndex) ? normalizeSelectedPoints([
|
|
@@ -8768,10 +8832,10 @@ var LinearElementEditor = class _LinearElementEditor {
|
|
|
8768
8832
|
element,
|
|
8769
8833
|
elementsMap,
|
|
8770
8834
|
lastCommittedPoint,
|
|
8771
|
-
|
|
8835
|
+
pointFrom9(scenePointerX, scenePointerY),
|
|
8772
8836
|
event[KEYS2.CTRL_OR_CMD] ? null : app.getEffectiveGridSize()
|
|
8773
8837
|
);
|
|
8774
|
-
newPoint =
|
|
8838
|
+
newPoint = pointFrom9(
|
|
8775
8839
|
width + lastCommittedPoint[0],
|
|
8776
8840
|
height + lastCommittedPoint[1]
|
|
8777
8841
|
);
|
|
@@ -8811,9 +8875,9 @@ var LinearElementEditor = class _LinearElementEditor {
|
|
|
8811
8875
|
const cx = (x1 + x2) / 2;
|
|
8812
8876
|
const cy = (y1 + y2) / 2;
|
|
8813
8877
|
const { x, y } = element;
|
|
8814
|
-
return
|
|
8815
|
-
|
|
8816
|
-
|
|
8878
|
+
return pointRotateRads8(
|
|
8879
|
+
pointFrom9(x + p[0], y + p[1]),
|
|
8880
|
+
pointFrom9(cx, cy),
|
|
8817
8881
|
element.angle
|
|
8818
8882
|
);
|
|
8819
8883
|
}
|
|
@@ -8824,9 +8888,9 @@ var LinearElementEditor = class _LinearElementEditor {
|
|
|
8824
8888
|
const cy = (y1 + y2) / 2;
|
|
8825
8889
|
return element.points.map((p) => {
|
|
8826
8890
|
const { x, y } = element;
|
|
8827
|
-
return
|
|
8828
|
-
|
|
8829
|
-
|
|
8891
|
+
return pointRotateRads8(
|
|
8892
|
+
pointFrom9(x + p[0], y + p[1]),
|
|
8893
|
+
pointFrom9(cx, cy),
|
|
8830
8894
|
element.angle
|
|
8831
8895
|
);
|
|
8832
8896
|
});
|
|
@@ -8838,15 +8902,15 @@ var LinearElementEditor = class _LinearElementEditor {
|
|
|
8838
8902
|
const cy = (y1 + y2) / 2;
|
|
8839
8903
|
const p = element.points[index];
|
|
8840
8904
|
const { x, y } = element;
|
|
8841
|
-
return p ?
|
|
8842
|
-
|
|
8843
|
-
|
|
8905
|
+
return p ? pointRotateRads8(
|
|
8906
|
+
pointFrom9(x + p[0], y + p[1]),
|
|
8907
|
+
pointFrom9(cx, cy),
|
|
8844
8908
|
element.angle
|
|
8845
|
-
) :
|
|
8909
|
+
) : pointRotateRads8(pointFrom9(x, y), pointFrom9(cx, cy), element.angle);
|
|
8846
8910
|
}
|
|
8847
8911
|
static pointFromAbsoluteCoords(element, absoluteCoords, elementsMap) {
|
|
8848
8912
|
if (isElbowArrow(element)) {
|
|
8849
|
-
return
|
|
8913
|
+
return pointFrom9(
|
|
8850
8914
|
absoluteCoords[0] - element.x,
|
|
8851
8915
|
absoluteCoords[1] - element.y
|
|
8852
8916
|
);
|
|
@@ -8854,12 +8918,12 @@ var LinearElementEditor = class _LinearElementEditor {
|
|
|
8854
8918
|
const [x1, y1, x2, y2] = getElementAbsoluteCoords2(element, elementsMap);
|
|
8855
8919
|
const cx = (x1 + x2) / 2;
|
|
8856
8920
|
const cy = (y1 + y2) / 2;
|
|
8857
|
-
const [x, y] =
|
|
8858
|
-
|
|
8859
|
-
|
|
8921
|
+
const [x, y] = pointRotateRads8(
|
|
8922
|
+
pointFrom9(absoluteCoords[0], absoluteCoords[1]),
|
|
8923
|
+
pointFrom9(cx, cy),
|
|
8860
8924
|
-element.angle
|
|
8861
8925
|
);
|
|
8862
|
-
return
|
|
8926
|
+
return pointFrom9(x - element.x, y - element.y);
|
|
8863
8927
|
}
|
|
8864
8928
|
static getPointIndexUnderCursor(element, elementsMap, zoom, x, y) {
|
|
8865
8929
|
const pointHandles = _LinearElementEditor.getPointsGlobalCoordinates(
|
|
@@ -8869,7 +8933,7 @@ var LinearElementEditor = class _LinearElementEditor {
|
|
|
8869
8933
|
let idx = pointHandles.length;
|
|
8870
8934
|
while (--idx > -1) {
|
|
8871
8935
|
const p = pointHandles[idx];
|
|
8872
|
-
if (pointDistance5(
|
|
8936
|
+
if (pointDistance5(pointFrom9(x, y), pointFrom9(p[0], p[1])) * zoom.value < // +1px to account for outline stroke
|
|
8873
8937
|
_LinearElementEditor.POINT_HANDLE_SIZE + 1) {
|
|
8874
8938
|
return idx;
|
|
8875
8939
|
}
|
|
@@ -8881,12 +8945,12 @@ var LinearElementEditor = class _LinearElementEditor {
|
|
|
8881
8945
|
const [x1, y1, x2, y2] = getElementAbsoluteCoords2(element, elementsMap);
|
|
8882
8946
|
const cx = (x1 + x2) / 2;
|
|
8883
8947
|
const cy = (y1 + y2) / 2;
|
|
8884
|
-
const [rotatedX, rotatedY] =
|
|
8885
|
-
|
|
8886
|
-
|
|
8948
|
+
const [rotatedX, rotatedY] = pointRotateRads8(
|
|
8949
|
+
pointFrom9(pointerOnGrid[0], pointerOnGrid[1]),
|
|
8950
|
+
pointFrom9(cx, cy),
|
|
8887
8951
|
-element.angle
|
|
8888
8952
|
);
|
|
8889
|
-
return
|
|
8953
|
+
return pointFrom9(rotatedX - element.x, rotatedY - element.y);
|
|
8890
8954
|
}
|
|
8891
8955
|
/**
|
|
8892
8956
|
* Normalizes line points so that the start point is at [0,0]. This is
|
|
@@ -8935,7 +8999,7 @@ var LinearElementEditor = class _LinearElementEditor {
|
|
|
8935
8999
|
pointAddedToEnd = true;
|
|
8936
9000
|
}
|
|
8937
9001
|
acc.push(
|
|
8938
|
-
nextPoint ?
|
|
9002
|
+
nextPoint ? pointFrom9((p[0] + nextPoint[0]) / 2, (p[1] + nextPoint[1]) / 2) : pointFrom9(p[0], p[1])
|
|
8939
9003
|
);
|
|
8940
9004
|
nextSelectedIndices.push(indexCursor + 1);
|
|
8941
9005
|
++indexCursor;
|
|
@@ -8951,7 +9015,7 @@ var LinearElementEditor = class _LinearElementEditor {
|
|
|
8951
9015
|
/* @__PURE__ */ new Map([
|
|
8952
9016
|
[
|
|
8953
9017
|
element.points.length - 1,
|
|
8954
|
-
{ point:
|
|
9018
|
+
{ point: pointFrom9(lastPoint[0] + 30, lastPoint[1] + 30) }
|
|
8955
9019
|
]
|
|
8956
9020
|
])
|
|
8957
9021
|
);
|
|
@@ -8971,7 +9035,7 @@ var LinearElementEditor = class _LinearElementEditor {
|
|
|
8971
9035
|
});
|
|
8972
9036
|
const isPolygon = isLineElement(element) && element.polygon;
|
|
8973
9037
|
if (isPolygon && (isUncommittedPoint || pointIndices.includes(0) || pointIndices.includes(element.points.length - 1))) {
|
|
8974
|
-
nextPoints[0] =
|
|
9038
|
+
nextPoints[0] = pointFrom9(
|
|
8975
9039
|
nextPoints[nextPoints.length - 1][0],
|
|
8976
9040
|
nextPoints[nextPoints.length - 1][1]
|
|
8977
9041
|
);
|
|
@@ -8992,7 +9056,7 @@ var LinearElementEditor = class _LinearElementEditor {
|
|
|
8992
9056
|
static addPoints(element, scene, addedPoints) {
|
|
8993
9057
|
const nextPoints = [...element.points, ...addedPoints];
|
|
8994
9058
|
if (isLineElement(element) && element.polygon) {
|
|
8995
|
-
nextPoints[0] =
|
|
9059
|
+
nextPoints[0] = pointFrom9(
|
|
8996
9060
|
nextPoints[nextPoints.length - 1][0],
|
|
8997
9061
|
nextPoints[nextPoints.length - 1][1]
|
|
8998
9062
|
);
|
|
@@ -9017,7 +9081,7 @@ var LinearElementEditor = class _LinearElementEditor {
|
|
|
9017
9081
|
const lastPointUpdate = pointUpdates.get(points.length - 1);
|
|
9018
9082
|
if (firstPointUpdate) {
|
|
9019
9083
|
pointUpdates.set(points.length - 1, {
|
|
9020
|
-
point:
|
|
9084
|
+
point: pointFrom9(
|
|
9021
9085
|
firstPointUpdate.point[0],
|
|
9022
9086
|
firstPointUpdate.point[1]
|
|
9023
9087
|
),
|
|
@@ -9025,19 +9089,19 @@ var LinearElementEditor = class _LinearElementEditor {
|
|
|
9025
9089
|
});
|
|
9026
9090
|
} else if (lastPointUpdate) {
|
|
9027
9091
|
pointUpdates.set(0, {
|
|
9028
|
-
point:
|
|
9092
|
+
point: pointFrom9(lastPointUpdate.point[0], lastPointUpdate.point[1]),
|
|
9029
9093
|
isDragging: lastPointUpdate.isDragging
|
|
9030
9094
|
});
|
|
9031
9095
|
}
|
|
9032
9096
|
}
|
|
9033
|
-
const updatedOriginPoint = pointUpdates.get(0)?.point ??
|
|
9097
|
+
const updatedOriginPoint = pointUpdates.get(0)?.point ?? pointFrom9(0, 0);
|
|
9034
9098
|
const [offsetX, offsetY] = updatedOriginPoint;
|
|
9035
9099
|
const nextPoints = isElbowArrow(element) ? [
|
|
9036
9100
|
pointUpdates.get(0)?.point ?? points[0],
|
|
9037
9101
|
pointUpdates.get(points.length - 1)?.point ?? points[points.length - 1]
|
|
9038
9102
|
] : points.map((p, idx) => {
|
|
9039
9103
|
const current = pointUpdates.get(idx)?.point ?? p;
|
|
9040
|
-
return
|
|
9104
|
+
return pointFrom9(
|
|
9041
9105
|
current[0] - offsetX,
|
|
9042
9106
|
current[1] - offsetY
|
|
9043
9107
|
);
|
|
@@ -9071,8 +9135,8 @@ var LinearElementEditor = class _LinearElementEditor {
|
|
|
9071
9135
|
}
|
|
9072
9136
|
const origin = linearElementEditor.pointerDownState.origin;
|
|
9073
9137
|
const dist = pointDistance5(
|
|
9074
|
-
|
|
9075
|
-
|
|
9138
|
+
pointFrom9(origin.x, origin.y),
|
|
9139
|
+
pointFrom9(pointerCoords.x, pointerCoords.y)
|
|
9076
9140
|
);
|
|
9077
9141
|
if (!appState.selectedLinearElement?.isEditing && dist < DRAGGING_THRESHOLD / appState.zoom.value) {
|
|
9078
9142
|
return false;
|
|
@@ -9140,9 +9204,9 @@ var LinearElementEditor = class _LinearElementEditor {
|
|
|
9140
9204
|
const prevCenterY = (prevCoords[1] + prevCoords[3]) / 2;
|
|
9141
9205
|
const dX = prevCenterX - nextCenterX;
|
|
9142
9206
|
const dY = prevCenterY - nextCenterY;
|
|
9143
|
-
const rotatedOffset =
|
|
9144
|
-
|
|
9145
|
-
|
|
9207
|
+
const rotatedOffset = pointRotateRads8(
|
|
9208
|
+
pointFrom9(offsetX, offsetY),
|
|
9209
|
+
pointFrom9(dX, dY),
|
|
9146
9210
|
element.angle
|
|
9147
9211
|
);
|
|
9148
9212
|
scene.mutateElement(element, {
|
|
@@ -9177,9 +9241,9 @@ var LinearElementEditor = class _LinearElementEditor {
|
|
|
9177
9241
|
gridY,
|
|
9178
9242
|
customLineAngle
|
|
9179
9243
|
);
|
|
9180
|
-
return
|
|
9181
|
-
|
|
9182
|
-
|
|
9244
|
+
return pointRotateRads8(
|
|
9245
|
+
pointFrom9(width, height),
|
|
9246
|
+
pointFrom9(0, 0),
|
|
9183
9247
|
-element.angle
|
|
9184
9248
|
);
|
|
9185
9249
|
}
|
|
@@ -9224,34 +9288,34 @@ var LinearElementEditor = class _LinearElementEditor {
|
|
|
9224
9288
|
);
|
|
9225
9289
|
const boundTextX2 = boundTextX1 + boundTextElement.width;
|
|
9226
9290
|
const boundTextY2 = boundTextY1 + boundTextElement.height;
|
|
9227
|
-
const centerPoint =
|
|
9228
|
-
const topLeftRotatedPoint =
|
|
9229
|
-
|
|
9291
|
+
const centerPoint = pointFrom9(cx, cy);
|
|
9292
|
+
const topLeftRotatedPoint = pointRotateRads8(
|
|
9293
|
+
pointFrom9(x1, y1),
|
|
9230
9294
|
centerPoint,
|
|
9231
9295
|
element.angle
|
|
9232
9296
|
);
|
|
9233
|
-
const topRightRotatedPoint =
|
|
9234
|
-
|
|
9297
|
+
const topRightRotatedPoint = pointRotateRads8(
|
|
9298
|
+
pointFrom9(x2, y1),
|
|
9235
9299
|
centerPoint,
|
|
9236
9300
|
element.angle
|
|
9237
9301
|
);
|
|
9238
|
-
const counterRotateBoundTextTopLeft =
|
|
9239
|
-
|
|
9302
|
+
const counterRotateBoundTextTopLeft = pointRotateRads8(
|
|
9303
|
+
pointFrom9(boundTextX1, boundTextY1),
|
|
9240
9304
|
centerPoint,
|
|
9241
9305
|
-element.angle
|
|
9242
9306
|
);
|
|
9243
|
-
const counterRotateBoundTextTopRight =
|
|
9244
|
-
|
|
9307
|
+
const counterRotateBoundTextTopRight = pointRotateRads8(
|
|
9308
|
+
pointFrom9(boundTextX2, boundTextY1),
|
|
9245
9309
|
centerPoint,
|
|
9246
9310
|
-element.angle
|
|
9247
9311
|
);
|
|
9248
|
-
const counterRotateBoundTextBottomLeft =
|
|
9249
|
-
|
|
9312
|
+
const counterRotateBoundTextBottomLeft = pointRotateRads8(
|
|
9313
|
+
pointFrom9(boundTextX1, boundTextY2),
|
|
9250
9314
|
centerPoint,
|
|
9251
9315
|
-element.angle
|
|
9252
9316
|
);
|
|
9253
|
-
const counterRotateBoundTextBottomRight =
|
|
9254
|
-
|
|
9317
|
+
const counterRotateBoundTextBottomRight = pointRotateRads8(
|
|
9318
|
+
pointFrom9(boundTextX2, boundTextY2),
|
|
9255
9319
|
centerPoint,
|
|
9256
9320
|
-element.angle
|
|
9257
9321
|
);
|
|
@@ -9367,11 +9431,11 @@ var LinearElementEditor = class _LinearElementEditor {
|
|
|
9367
9431
|
);
|
|
9368
9432
|
fixedSegments[index] = {
|
|
9369
9433
|
index,
|
|
9370
|
-
start:
|
|
9434
|
+
start: pointFrom9(
|
|
9371
9435
|
!isHorizontal ? x - element.x : element.points[index - 1][0],
|
|
9372
9436
|
isHorizontal ? y - element.y : element.points[index - 1][1]
|
|
9373
9437
|
),
|
|
9374
|
-
end:
|
|
9438
|
+
end: pointFrom9(
|
|
9375
9439
|
!isHorizontal ? x - element.x : element.points[index][0],
|
|
9376
9440
|
isHorizontal ? y - element.y : element.points[index][1]
|
|
9377
9441
|
)
|
|
@@ -9383,7 +9447,7 @@ var LinearElementEditor = class _LinearElementEditor {
|
|
|
9383
9447
|
scene.mutateElement(element, {
|
|
9384
9448
|
fixedSegments: nextFixedSegments
|
|
9385
9449
|
});
|
|
9386
|
-
const point =
|
|
9450
|
+
const point = pointFrom9(
|
|
9387
9451
|
element.x + (element.fixedSegments[offset].start[0] + element.fixedSegments[offset].end[0]) / 2,
|
|
9388
9452
|
element.y + (element.fixedSegments[offset].start[1] + element.fixedSegments[offset].end[1]) / 2
|
|
9389
9453
|
);
|
|
@@ -9421,7 +9485,7 @@ var normalizeSelectedPoints = (points) => {
|
|
|
9421
9485
|
// src/frame.ts
|
|
9422
9486
|
init_define_import_meta_env();
|
|
9423
9487
|
import { arrayToMap as arrayToMap5 } from "@excalidraw/common";
|
|
9424
|
-
import { isPointWithinBounds as isPointWithinBounds2, pointFrom as
|
|
9488
|
+
import { isPointWithinBounds as isPointWithinBounds2, pointFrom as pointFrom11 } from "@excalidraw/math";
|
|
9425
9489
|
|
|
9426
9490
|
// ../utils/src/bbox.ts
|
|
9427
9491
|
init_define_import_meta_env();
|
|
@@ -9472,24 +9536,24 @@ import {
|
|
|
9472
9536
|
} from "@excalidraw/element";
|
|
9473
9537
|
import {
|
|
9474
9538
|
rangeIncludesValue,
|
|
9475
|
-
pointFrom as
|
|
9476
|
-
pointRotateRads as
|
|
9539
|
+
pointFrom as pointFrom10,
|
|
9540
|
+
pointRotateRads as pointRotateRads9,
|
|
9477
9541
|
rangeInclusive
|
|
9478
9542
|
} from "@excalidraw/math";
|
|
9479
9543
|
var getNonLinearElementRelativePoints = (element) => {
|
|
9480
9544
|
if (element.type === "diamond") {
|
|
9481
9545
|
return [
|
|
9482
|
-
|
|
9483
|
-
|
|
9484
|
-
|
|
9485
|
-
|
|
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)
|
|
9486
9550
|
];
|
|
9487
9551
|
}
|
|
9488
9552
|
return [
|
|
9489
|
-
|
|
9490
|
-
|
|
9491
|
-
|
|
9492
|
-
|
|
9553
|
+
pointFrom10(0, 0),
|
|
9554
|
+
pointFrom10(0 + element.width, 0),
|
|
9555
|
+
pointFrom10(0 + element.width, element.height),
|
|
9556
|
+
pointFrom10(0, element.height)
|
|
9493
9557
|
];
|
|
9494
9558
|
};
|
|
9495
9559
|
var getElementRelativePoints = (element) => {
|
|
@@ -9523,9 +9587,9 @@ var getMinMaxPoints = (points) => {
|
|
|
9523
9587
|
var getRotatedBBox = (element) => {
|
|
9524
9588
|
const points = getElementRelativePoints(element);
|
|
9525
9589
|
const { cx, cy } = getMinMaxPoints(points);
|
|
9526
|
-
const centerPoint =
|
|
9590
|
+
const centerPoint = pointFrom10(cx, cy);
|
|
9527
9591
|
const rotatedPoints = points.map(
|
|
9528
|
-
(p) =>
|
|
9592
|
+
(p) => pointRotateRads9(p, centerPoint, element.angle)
|
|
9529
9593
|
);
|
|
9530
9594
|
const { minX, minY, maxX, maxY } = getMinMaxPoints(rotatedPoints);
|
|
9531
9595
|
return [
|
|
@@ -10089,9 +10153,9 @@ var elementOverlapsWithFrame = (element, frame, elementsMap) => {
|
|
|
10089
10153
|
var isCursorInFrame = (cursorCoords, frame, elementsMap) => {
|
|
10090
10154
|
const [fx1, fy1, fx2, fy2] = getElementAbsoluteCoords2(frame, elementsMap);
|
|
10091
10155
|
return isPointWithinBounds2(
|
|
10092
|
-
|
|
10093
|
-
|
|
10094
|
-
|
|
10156
|
+
pointFrom11(fx1, fy1),
|
|
10157
|
+
pointFrom11(cursorCoords.x, cursorCoords.y),
|
|
10158
|
+
pointFrom11(fx2, fy2)
|
|
10095
10159
|
);
|
|
10096
10160
|
};
|
|
10097
10161
|
var groupsAreAtLeastIntersectingTheFrame = (elements, groupIds, frame) => {
|
|
@@ -11155,6 +11219,58 @@ function getFreeDrawPath2D(element) {
|
|
|
11155
11219
|
return pathsCache.get(element);
|
|
11156
11220
|
}
|
|
11157
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) {
|
|
11158
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]];
|
|
11159
11275
|
const options = {
|
|
11160
11276
|
simulatePressure: element.simulatePressure,
|
|
@@ -11167,7 +11283,7 @@ function getFreeDrawSvgPath(element) {
|
|
|
11167
11283
|
last: !!element.lastCommittedPoint
|
|
11168
11284
|
// LastCommittedPoint is added on pointerup
|
|
11169
11285
|
};
|
|
11170
|
-
return
|
|
11286
|
+
return ae(inputPoints, options);
|
|
11171
11287
|
}
|
|
11172
11288
|
function med(A2, B2) {
|
|
11173
11289
|
return [(A2[0] + B2[0]) / 2, (A2[1] + B2[1]) / 2];
|
|
@@ -11194,7 +11310,7 @@ function getSvgPathFromStroke(points) {
|
|
|
11194
11310
|
// src/comparisons.ts
|
|
11195
11311
|
init_define_import_meta_env();
|
|
11196
11312
|
var hasBackground = (type) => type === "rectangle" || type === "iframe" || type === "embeddable" || type === "ellipse" || type === "diamond" || type === "line" || type === "freedraw";
|
|
11197
|
-
var hasStrokeColor = (type) => type
|
|
11313
|
+
var hasStrokeColor = (type) => type === "rectangle" || type === "ellipse" || type === "diamond" || type === "freedraw" || type === "arrow" || type === "line" || type === "text";
|
|
11198
11314
|
var hasStrokeWidth = (type) => type === "rectangle" || type === "iframe" || type === "embeddable" || type === "ellipse" || type === "diamond" || type === "freedraw" || type === "arrow" || type === "line";
|
|
11199
11315
|
var hasStrokeStyle = (type) => type === "rectangle" || type === "iframe" || type === "embeddable" || type === "ellipse" || type === "diamond" || type === "arrow" || type === "line";
|
|
11200
11316
|
var canChangeRoundness = (type) => type === "rectangle" || type === "iframe" || type === "embeddable" || type === "line" || type === "diamond" || type === "image";
|
|
@@ -11450,26 +11566,26 @@ var generateLinearCollisionShape = (element) => {
|
|
|
11450
11566
|
switch (element.type) {
|
|
11451
11567
|
case "line":
|
|
11452
11568
|
case "arrow": {
|
|
11453
|
-
const points = element.points.length ? element.points : [
|
|
11569
|
+
const points = element.points.length ? element.points : [pointFrom13(0, 0)];
|
|
11454
11570
|
if (isElbowArrow(element)) {
|
|
11455
11571
|
return generator.path(generateElbowArrowShape(points, 16), options).sets[0].ops;
|
|
11456
11572
|
} else if (!element.roundness) {
|
|
11457
11573
|
return points.map((point, idx) => {
|
|
11458
|
-
const p =
|
|
11459
|
-
|
|
11574
|
+
const p = pointRotateRads11(
|
|
11575
|
+
pointFrom13(element.x + point[0], element.y + point[1]),
|
|
11460
11576
|
center,
|
|
11461
11577
|
element.angle
|
|
11462
11578
|
);
|
|
11463
11579
|
return {
|
|
11464
11580
|
op: idx === 0 ? "move" : "lineTo",
|
|
11465
|
-
data:
|
|
11581
|
+
data: pointFrom13(p[0] - element.x, p[1] - element.y)
|
|
11466
11582
|
};
|
|
11467
11583
|
});
|
|
11468
11584
|
}
|
|
11469
11585
|
return generator.curve(points, options).sets[0].ops.slice(0, element.points.length).map((op, i) => {
|
|
11470
11586
|
if (i === 0) {
|
|
11471
|
-
const p =
|
|
11472
|
-
|
|
11587
|
+
const p = pointRotateRads11(
|
|
11588
|
+
pointFrom13(
|
|
11473
11589
|
element.x + op.data[0],
|
|
11474
11590
|
element.y + op.data[1]
|
|
11475
11591
|
),
|
|
@@ -11478,30 +11594,30 @@ var generateLinearCollisionShape = (element) => {
|
|
|
11478
11594
|
);
|
|
11479
11595
|
return {
|
|
11480
11596
|
op: "move",
|
|
11481
|
-
data:
|
|
11597
|
+
data: pointFrom13(p[0] - element.x, p[1] - element.y)
|
|
11482
11598
|
};
|
|
11483
11599
|
}
|
|
11484
11600
|
return {
|
|
11485
11601
|
op: "bcurveTo",
|
|
11486
11602
|
data: [
|
|
11487
|
-
|
|
11488
|
-
|
|
11603
|
+
pointRotateRads11(
|
|
11604
|
+
pointFrom13(
|
|
11489
11605
|
element.x + op.data[0],
|
|
11490
11606
|
element.y + op.data[1]
|
|
11491
11607
|
),
|
|
11492
11608
|
center,
|
|
11493
11609
|
element.angle
|
|
11494
11610
|
),
|
|
11495
|
-
|
|
11496
|
-
|
|
11611
|
+
pointRotateRads11(
|
|
11612
|
+
pointFrom13(
|
|
11497
11613
|
element.x + op.data[2],
|
|
11498
11614
|
element.y + op.data[3]
|
|
11499
11615
|
),
|
|
11500
11616
|
center,
|
|
11501
11617
|
element.angle
|
|
11502
11618
|
),
|
|
11503
|
-
|
|
11504
|
-
|
|
11619
|
+
pointRotateRads11(
|
|
11620
|
+
pointFrom13(
|
|
11505
11621
|
element.x + op.data[4],
|
|
11506
11622
|
element.y + op.data[5]
|
|
11507
11623
|
),
|
|
@@ -11509,7 +11625,7 @@ var generateLinearCollisionShape = (element) => {
|
|
|
11509
11625
|
element.angle
|
|
11510
11626
|
)
|
|
11511
11627
|
].map(
|
|
11512
|
-
(p) =>
|
|
11628
|
+
(p) => pointFrom13(p[0] - element.x, p[1] - element.y)
|
|
11513
11629
|
).flat()
|
|
11514
11630
|
};
|
|
11515
11631
|
});
|
|
@@ -11524,8 +11640,8 @@ var generateLinearCollisionShape = (element) => {
|
|
|
11524
11640
|
);
|
|
11525
11641
|
return generator.curve(simplifiedPoints, options).sets[0].ops.slice(0, element.points.length).map((op, i) => {
|
|
11526
11642
|
if (i === 0) {
|
|
11527
|
-
const p =
|
|
11528
|
-
|
|
11643
|
+
const p = pointRotateRads11(
|
|
11644
|
+
pointFrom13(
|
|
11529
11645
|
element.x + op.data[0],
|
|
11530
11646
|
element.y + op.data[1]
|
|
11531
11647
|
),
|
|
@@ -11534,30 +11650,30 @@ var generateLinearCollisionShape = (element) => {
|
|
|
11534
11650
|
);
|
|
11535
11651
|
return {
|
|
11536
11652
|
op: "move",
|
|
11537
|
-
data:
|
|
11653
|
+
data: pointFrom13(p[0] - element.x, p[1] - element.y)
|
|
11538
11654
|
};
|
|
11539
11655
|
}
|
|
11540
11656
|
return {
|
|
11541
11657
|
op: "bcurveTo",
|
|
11542
11658
|
data: [
|
|
11543
|
-
|
|
11544
|
-
|
|
11659
|
+
pointRotateRads11(
|
|
11660
|
+
pointFrom13(
|
|
11545
11661
|
element.x + op.data[0],
|
|
11546
11662
|
element.y + op.data[1]
|
|
11547
11663
|
),
|
|
11548
11664
|
center,
|
|
11549
11665
|
element.angle
|
|
11550
11666
|
),
|
|
11551
|
-
|
|
11552
|
-
|
|
11667
|
+
pointRotateRads11(
|
|
11668
|
+
pointFrom13(
|
|
11553
11669
|
element.x + op.data[2],
|
|
11554
11670
|
element.y + op.data[3]
|
|
11555
11671
|
),
|
|
11556
11672
|
center,
|
|
11557
11673
|
element.angle
|
|
11558
11674
|
),
|
|
11559
|
-
|
|
11560
|
-
|
|
11675
|
+
pointRotateRads11(
|
|
11676
|
+
pointFrom13(
|
|
11561
11677
|
element.x + op.data[4],
|
|
11562
11678
|
element.y + op.data[5]
|
|
11563
11679
|
),
|
|
@@ -11565,7 +11681,7 @@ var generateLinearCollisionShape = (element) => {
|
|
|
11565
11681
|
element.angle
|
|
11566
11682
|
)
|
|
11567
11683
|
].map(
|
|
11568
|
-
(p) =>
|
|
11684
|
+
(p) => pointFrom13(p[0] - element.x, p[1] - element.y)
|
|
11569
11685
|
).flat()
|
|
11570
11686
|
};
|
|
11571
11687
|
});
|
|
@@ -11662,7 +11778,7 @@ var generateElementShape = (element, generator, {
|
|
|
11662
11778
|
case "arrow": {
|
|
11663
11779
|
let shape;
|
|
11664
11780
|
const options = generateRoughOptions(element);
|
|
11665
|
-
const points = element.points.length ? element.points : [
|
|
11781
|
+
const points = element.points.length ? element.points : [pointFrom13(0, 0)];
|
|
11666
11782
|
if (isElbowArrow(element)) {
|
|
11667
11783
|
if (!points.every(
|
|
11668
11784
|
(point) => Math.abs(point[0]) <= 1e6 && Math.abs(point[1]) <= 1e6
|
|
@@ -11824,14 +11940,14 @@ var getElementShape = (element, elementsMap) => {
|
|
|
11824
11940
|
return shouldTestInside(element) ? getClosedCurveShape(
|
|
11825
11941
|
element,
|
|
11826
11942
|
roughShape,
|
|
11827
|
-
|
|
11943
|
+
pointFrom13(element.x, element.y),
|
|
11828
11944
|
element.angle,
|
|
11829
|
-
|
|
11945
|
+
pointFrom13(cx, cy)
|
|
11830
11946
|
) : getCurveShape(
|
|
11831
11947
|
roughShape,
|
|
11832
|
-
|
|
11948
|
+
pointFrom13(element.x, element.y),
|
|
11833
11949
|
element.angle,
|
|
11834
|
-
|
|
11950
|
+
pointFrom13(cx, cy)
|
|
11835
11951
|
);
|
|
11836
11952
|
}
|
|
11837
11953
|
case "ellipse":
|
|
@@ -11840,7 +11956,7 @@ var getElementShape = (element, elementsMap) => {
|
|
|
11840
11956
|
const [, , , , cx, cy] = getElementAbsoluteCoords2(element, elementsMap);
|
|
11841
11957
|
return getFreedrawShape(
|
|
11842
11958
|
element,
|
|
11843
|
-
|
|
11959
|
+
pointFrom13(cx, cy),
|
|
11844
11960
|
shouldTestInside(element)
|
|
11845
11961
|
);
|
|
11846
11962
|
}
|
|
@@ -11859,9 +11975,9 @@ var toggleLinePolygonState = (element, nextPolygonState) => {
|
|
|
11859
11975
|
firstPoint[1] - lastPoint[1]
|
|
11860
11976
|
);
|
|
11861
11977
|
if (distance3 > LINE_POLYGON_POINT_MERGE_DISTANCE || updatedPoints.length < 4) {
|
|
11862
|
-
updatedPoints.push(
|
|
11978
|
+
updatedPoints.push(pointFrom13(firstPoint[0], firstPoint[1]));
|
|
11863
11979
|
} else {
|
|
11864
|
-
updatedPoints[updatedPoints.length - 1] =
|
|
11980
|
+
updatedPoints[updatedPoints.length - 1] = pointFrom13(
|
|
11865
11981
|
firstPoint[0],
|
|
11866
11982
|
firstPoint[1]
|
|
11867
11983
|
);
|
|
@@ -11915,9 +12031,9 @@ var ElementBounds = class _ElementBounds {
|
|
|
11915
12031
|
if (isFreeDrawElement(element)) {
|
|
11916
12032
|
const [minX, minY, maxX, maxY] = getBoundsFromPoints(
|
|
11917
12033
|
element.points.map(
|
|
11918
|
-
([x, y]) =>
|
|
11919
|
-
|
|
11920
|
-
|
|
12034
|
+
([x, y]) => pointRotateRads12(
|
|
12035
|
+
pointFrom14(x, y),
|
|
12036
|
+
pointFrom14(cx - element.x, cy - element.y),
|
|
11921
12037
|
element.angle
|
|
11922
12038
|
)
|
|
11923
12039
|
)
|
|
@@ -11931,24 +12047,24 @@ var ElementBounds = class _ElementBounds {
|
|
|
11931
12047
|
} else if (isLinearElement(element)) {
|
|
11932
12048
|
bounds = getLinearElementRotatedBounds(element, cx, cy, elementsMap);
|
|
11933
12049
|
} else if (element.type === "diamond") {
|
|
11934
|
-
const [x11, y11] =
|
|
11935
|
-
|
|
11936
|
-
|
|
12050
|
+
const [x11, y11] = pointRotateRads12(
|
|
12051
|
+
pointFrom14(cx, y1),
|
|
12052
|
+
pointFrom14(cx, cy),
|
|
11937
12053
|
element.angle
|
|
11938
12054
|
);
|
|
11939
|
-
const [x12, y12] =
|
|
11940
|
-
|
|
11941
|
-
|
|
12055
|
+
const [x12, y12] = pointRotateRads12(
|
|
12056
|
+
pointFrom14(cx, y2),
|
|
12057
|
+
pointFrom14(cx, cy),
|
|
11942
12058
|
element.angle
|
|
11943
12059
|
);
|
|
11944
|
-
const [x22, y22] =
|
|
11945
|
-
|
|
11946
|
-
|
|
12060
|
+
const [x22, y22] = pointRotateRads12(
|
|
12061
|
+
pointFrom14(x1, cy),
|
|
12062
|
+
pointFrom14(cx, cy),
|
|
11947
12063
|
element.angle
|
|
11948
12064
|
);
|
|
11949
|
-
const [x21, y21] =
|
|
11950
|
-
|
|
11951
|
-
|
|
12065
|
+
const [x21, y21] = pointRotateRads12(
|
|
12066
|
+
pointFrom14(x2, cy),
|
|
12067
|
+
pointFrom14(cx, cy),
|
|
11952
12068
|
element.angle
|
|
11953
12069
|
);
|
|
11954
12070
|
const minX = Math.min(x11, x12, x22, x21);
|
|
@@ -11965,24 +12081,24 @@ var ElementBounds = class _ElementBounds {
|
|
|
11965
12081
|
const hh = Math.hypot(h * cos, w * sin);
|
|
11966
12082
|
bounds = [cx - ww, cy - hh, cx + ww, cy + hh];
|
|
11967
12083
|
} else {
|
|
11968
|
-
const [x11, y11] =
|
|
11969
|
-
|
|
11970
|
-
|
|
12084
|
+
const [x11, y11] = pointRotateRads12(
|
|
12085
|
+
pointFrom14(x1, y1),
|
|
12086
|
+
pointFrom14(cx, cy),
|
|
11971
12087
|
element.angle
|
|
11972
12088
|
);
|
|
11973
|
-
const [x12, y12] =
|
|
11974
|
-
|
|
11975
|
-
|
|
12089
|
+
const [x12, y12] = pointRotateRads12(
|
|
12090
|
+
pointFrom14(x1, y2),
|
|
12091
|
+
pointFrom14(cx, cy),
|
|
11976
12092
|
element.angle
|
|
11977
12093
|
);
|
|
11978
|
-
const [x22, y22] =
|
|
11979
|
-
|
|
11980
|
-
|
|
12094
|
+
const [x22, y22] = pointRotateRads12(
|
|
12095
|
+
pointFrom14(x2, y2),
|
|
12096
|
+
pointFrom14(cx, cy),
|
|
11981
12097
|
element.angle
|
|
11982
12098
|
);
|
|
11983
|
-
const [x21, y21] =
|
|
11984
|
-
|
|
11985
|
-
|
|
12099
|
+
const [x21, y21] = pointRotateRads12(
|
|
12100
|
+
pointFrom14(x2, y1),
|
|
12101
|
+
pointFrom14(cx, cy),
|
|
11986
12102
|
element.angle
|
|
11987
12103
|
);
|
|
11988
12104
|
const minX = Math.min(x11, x12, x22, x21);
|
|
@@ -12036,20 +12152,38 @@ var getElementLineSegments = (element, elementsMap) => {
|
|
|
12036
12152
|
element,
|
|
12037
12153
|
elementsMap
|
|
12038
12154
|
);
|
|
12039
|
-
const center =
|
|
12155
|
+
const center = pointFrom14(cx, cy);
|
|
12040
12156
|
if (shape.type === "polycurve") {
|
|
12041
12157
|
const curves = shape.data;
|
|
12042
|
-
const
|
|
12043
|
-
|
|
12158
|
+
const pointsOnCurves = curves.map(
|
|
12159
|
+
(curve4) => pointsOnBezierCurves(curve4, 10)
|
|
12160
|
+
);
|
|
12044
12161
|
const segments = [];
|
|
12045
|
-
|
|
12046
|
-
|
|
12047
|
-
|
|
12048
|
-
|
|
12049
|
-
|
|
12050
|
-
|
|
12051
|
-
|
|
12052
|
-
|
|
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
|
+
}
|
|
12053
12187
|
}
|
|
12054
12188
|
return segments;
|
|
12055
12189
|
} else if (shape.type === "polyline") {
|
|
@@ -12069,10 +12203,10 @@ var getElementLineSegments = (element, elementsMap) => {
|
|
|
12069
12203
|
const container = getContainerElement(element, elementsMap);
|
|
12070
12204
|
if (container && isLinearElement(container)) {
|
|
12071
12205
|
const segments2 = [
|
|
12072
|
-
|
|
12073
|
-
|
|
12074
|
-
|
|
12075
|
-
|
|
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))
|
|
12076
12210
|
];
|
|
12077
12211
|
return segments2;
|
|
12078
12212
|
}
|
|
@@ -12080,7 +12214,7 @@ var getElementLineSegments = (element, elementsMap) => {
|
|
|
12080
12214
|
const points = shape.data;
|
|
12081
12215
|
const segments = [];
|
|
12082
12216
|
for (let i = 0; i < points.length - 1; i++) {
|
|
12083
|
-
segments.push(
|
|
12217
|
+
segments.push(lineSegment6(points[i], points[i + 1]));
|
|
12084
12218
|
}
|
|
12085
12219
|
return segments;
|
|
12086
12220
|
} else if (shape.type === "ellipse") {
|
|
@@ -12095,16 +12229,16 @@ var getElementLineSegments = (element, elementsMap) => {
|
|
|
12095
12229
|
[cx, y2],
|
|
12096
12230
|
[x1, cy],
|
|
12097
12231
|
[x2, cy]
|
|
12098
|
-
].map((point) =>
|
|
12232
|
+
].map((point) => pointRotateRads12(point, center, element.angle));
|
|
12099
12233
|
return [
|
|
12100
|
-
|
|
12101
|
-
|
|
12102
|
-
|
|
12103
|
-
|
|
12104
|
-
|
|
12105
|
-
|
|
12106
|
-
|
|
12107
|
-
|
|
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)
|
|
12108
12242
|
];
|
|
12109
12243
|
};
|
|
12110
12244
|
var _isRectanguloidElement = (element) => {
|
|
@@ -12112,9 +12246,9 @@ var _isRectanguloidElement = (element) => {
|
|
|
12112
12246
|
};
|
|
12113
12247
|
var getRotatedSides = (sides, center, angle) => {
|
|
12114
12248
|
return sides.map((side) => {
|
|
12115
|
-
return
|
|
12116
|
-
|
|
12117
|
-
|
|
12249
|
+
return lineSegment6(
|
|
12250
|
+
pointRotateRads12(side[0], center, angle),
|
|
12251
|
+
pointRotateRads12(side[1], center, angle)
|
|
12118
12252
|
);
|
|
12119
12253
|
});
|
|
12120
12254
|
};
|
|
@@ -12124,14 +12258,14 @@ var getSegmentsOnCurve = (curve4, center, angle) => {
|
|
|
12124
12258
|
const segments = [];
|
|
12125
12259
|
while (i < points.length - 1) {
|
|
12126
12260
|
segments.push(
|
|
12127
|
-
|
|
12128
|
-
|
|
12129
|
-
|
|
12261
|
+
lineSegment6(
|
|
12262
|
+
pointRotateRads12(
|
|
12263
|
+
pointFrom14(points[i][0], points[i][1]),
|
|
12130
12264
|
center,
|
|
12131
12265
|
angle
|
|
12132
12266
|
),
|
|
12133
|
-
|
|
12134
|
-
|
|
12267
|
+
pointRotateRads12(
|
|
12268
|
+
pointFrom14(points[i + 1][0], points[i + 1][1]),
|
|
12135
12269
|
center,
|
|
12136
12270
|
angle
|
|
12137
12271
|
)
|
|
@@ -12142,7 +12276,7 @@ var getSegmentsOnCurve = (curve4, center, angle) => {
|
|
|
12142
12276
|
return segments;
|
|
12143
12277
|
};
|
|
12144
12278
|
var getSegmentsOnEllipse = (ellipse4) => {
|
|
12145
|
-
const center =
|
|
12279
|
+
const center = pointFrom14(
|
|
12146
12280
|
ellipse4.x + ellipse4.width / 2,
|
|
12147
12281
|
ellipse4.y + ellipse4.height / 2
|
|
12148
12282
|
);
|
|
@@ -12156,12 +12290,12 @@ var getSegmentsOnEllipse = (ellipse4) => {
|
|
|
12156
12290
|
const t = i * deltaT;
|
|
12157
12291
|
const x = center[0] + a2 * Math.cos(t);
|
|
12158
12292
|
const y = center[1] + b2 * Math.sin(t);
|
|
12159
|
-
points.push(
|
|
12293
|
+
points.push(pointRotateRads12(pointFrom14(x, y), center, ellipse4.angle));
|
|
12160
12294
|
}
|
|
12161
12295
|
for (let i = 0; i < points.length - 1; i++) {
|
|
12162
|
-
segments.push(
|
|
12296
|
+
segments.push(lineSegment6(points[i], points[i + 1]));
|
|
12163
12297
|
}
|
|
12164
|
-
segments.push(
|
|
12298
|
+
segments.push(lineSegment6(points[points.length - 1], points[0]));
|
|
12165
12299
|
return segments;
|
|
12166
12300
|
};
|
|
12167
12301
|
var getRectangleBoxAbsoluteCoords = (boxSceneCoords) => {
|
|
@@ -12239,17 +12373,17 @@ var getCubicBezierCurveBound = (p0, p1, p2, p3) => {
|
|
|
12239
12373
|
return [minX, minY, maxX, maxY];
|
|
12240
12374
|
};
|
|
12241
12375
|
var getMinMaxXYFromCurvePathOps = (ops, transformXY) => {
|
|
12242
|
-
let currentP =
|
|
12376
|
+
let currentP = pointFrom14(0, 0);
|
|
12243
12377
|
const { minX, minY, maxX, maxY } = ops.reduce(
|
|
12244
12378
|
(limits, { op, data }) => {
|
|
12245
12379
|
if (op === "move") {
|
|
12246
12380
|
const p = pointFromArray3(data);
|
|
12247
|
-
|
|
12381
|
+
invariant8(p != null, "Op data is not a point");
|
|
12248
12382
|
currentP = p;
|
|
12249
12383
|
} else if (op === "bcurveTo") {
|
|
12250
|
-
const _p1 =
|
|
12251
|
-
const _p2 =
|
|
12252
|
-
const _p3 =
|
|
12384
|
+
const _p1 = pointFrom14(data[0], data[1]);
|
|
12385
|
+
const _p2 = pointFrom14(data[2], data[3]);
|
|
12386
|
+
const _p3 = pointFrom14(data[4], data[5]);
|
|
12253
12387
|
const p1 = transformXY ? transformXY(_p1) : _p1;
|
|
12254
12388
|
const p2 = transformXY ? transformXY(_p2) : _p2;
|
|
12255
12389
|
const p3 = transformXY ? transformXY(_p3) : _p3;
|
|
@@ -12330,18 +12464,18 @@ var getArrowheadPoints = (element, shape, position, arrowhead) => {
|
|
|
12330
12464
|
}
|
|
12331
12465
|
const index = position === "start" ? 1 : ops.length - 1;
|
|
12332
12466
|
const data = ops[index].data;
|
|
12333
|
-
|
|
12334
|
-
const p3 =
|
|
12335
|
-
const p2 =
|
|
12336
|
-
const p1 =
|
|
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]);
|
|
12337
12471
|
const prevOp = ops[index - 1];
|
|
12338
|
-
let p0 =
|
|
12472
|
+
let p0 = pointFrom14(0, 0);
|
|
12339
12473
|
if (prevOp.op === "move") {
|
|
12340
12474
|
const p = pointFromArray3(prevOp.data);
|
|
12341
|
-
|
|
12475
|
+
invariant8(p != null, "Op data is not a point");
|
|
12342
12476
|
p0 = p;
|
|
12343
12477
|
} else if (prevOp.op === "bcurveTo") {
|
|
12344
|
-
p0 =
|
|
12478
|
+
p0 = pointFrom14(prevOp.data[4], prevOp.data[5]);
|
|
12345
12479
|
}
|
|
12346
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);
|
|
12347
12481
|
const [x2, y2] = position === "start" ? p0 : p3;
|
|
@@ -12366,26 +12500,26 @@ var getArrowheadPoints = (element, shape, position, arrowhead) => {
|
|
|
12366
12500
|
}
|
|
12367
12501
|
const angle = getArrowheadAngle(arrowhead);
|
|
12368
12502
|
if (arrowhead === "crowfoot_many" || arrowhead === "crowfoot_one_or_many") {
|
|
12369
|
-
const [x32, y32] =
|
|
12370
|
-
|
|
12371
|
-
|
|
12503
|
+
const [x32, y32] = pointRotateRads12(
|
|
12504
|
+
pointFrom14(x2, y2),
|
|
12505
|
+
pointFrom14(xs, ys),
|
|
12372
12506
|
degreesToRadians(-angle)
|
|
12373
12507
|
);
|
|
12374
|
-
const [x42, y42] =
|
|
12375
|
-
|
|
12376
|
-
|
|
12508
|
+
const [x42, y42] = pointRotateRads12(
|
|
12509
|
+
pointFrom14(x2, y2),
|
|
12510
|
+
pointFrom14(xs, ys),
|
|
12377
12511
|
degreesToRadians(angle)
|
|
12378
12512
|
);
|
|
12379
12513
|
return [xs, ys, x32, y32, x42, y42];
|
|
12380
12514
|
}
|
|
12381
|
-
const [x3, y3] =
|
|
12382
|
-
|
|
12383
|
-
|
|
12515
|
+
const [x3, y3] = pointRotateRads12(
|
|
12516
|
+
pointFrom14(xs, ys),
|
|
12517
|
+
pointFrom14(x2, y2),
|
|
12384
12518
|
-angle * Math.PI / 180
|
|
12385
12519
|
);
|
|
12386
|
-
const [x4, y4] =
|
|
12387
|
-
|
|
12388
|
-
|
|
12520
|
+
const [x4, y4] = pointRotateRads12(
|
|
12521
|
+
pointFrom14(xs, ys),
|
|
12522
|
+
pointFrom14(x2, y2),
|
|
12389
12523
|
degreesToRadians(angle)
|
|
12390
12524
|
);
|
|
12391
12525
|
if (arrowhead === "diamond" || arrowhead === "diamond_outline") {
|
|
@@ -12393,16 +12527,16 @@ var getArrowheadPoints = (element, shape, position, arrowhead) => {
|
|
|
12393
12527
|
let oy;
|
|
12394
12528
|
if (position === "start") {
|
|
12395
12529
|
const [px, py] = element.points.length > 1 ? element.points[1] : [0, 0];
|
|
12396
|
-
[ox, oy] =
|
|
12397
|
-
|
|
12398
|
-
|
|
12530
|
+
[ox, oy] = pointRotateRads12(
|
|
12531
|
+
pointFrom14(x2 + minSize * 2, y2),
|
|
12532
|
+
pointFrom14(x2, y2),
|
|
12399
12533
|
Math.atan2(py - y2, px - x2)
|
|
12400
12534
|
);
|
|
12401
12535
|
} else {
|
|
12402
12536
|
const [px, py] = element.points.length > 1 ? element.points[element.points.length - 2] : [0, 0];
|
|
12403
|
-
[ox, oy] =
|
|
12404
|
-
|
|
12405
|
-
|
|
12537
|
+
[ox, oy] = pointRotateRads12(
|
|
12538
|
+
pointFrom14(x2 - minSize * 2, y2),
|
|
12539
|
+
pointFrom14(x2, y2),
|
|
12406
12540
|
Math.atan2(y2 - py, x2 - px)
|
|
12407
12541
|
);
|
|
12408
12542
|
}
|
|
@@ -12431,9 +12565,9 @@ var getLinearElementRotatedBounds = (element, cx, cy, elementsMap) => {
|
|
|
12431
12565
|
const boundTextElement = getBoundTextElement(element, elementsMap);
|
|
12432
12566
|
if (element.points.length < 2) {
|
|
12433
12567
|
const [pointX, pointY] = element.points[0];
|
|
12434
|
-
const [x, y] =
|
|
12435
|
-
|
|
12436
|
-
|
|
12568
|
+
const [x, y] = pointRotateRads12(
|
|
12569
|
+
pointFrom14(element.x + pointX, element.y + pointY),
|
|
12570
|
+
pointFrom14(cx, cy),
|
|
12437
12571
|
element.angle
|
|
12438
12572
|
);
|
|
12439
12573
|
let coords2 = [x, y, x, y];
|
|
@@ -12456,9 +12590,9 @@ var getLinearElementRotatedBounds = (element, cx, cy, elementsMap) => {
|
|
|
12456
12590
|
const cachedShape = ShapeCache.get(element)?.[0];
|
|
12457
12591
|
const shape = cachedShape ?? generateLinearElementShape(element);
|
|
12458
12592
|
const ops = getCurvePathOps(shape);
|
|
12459
|
-
const transformXY = ([x, y]) =>
|
|
12460
|
-
|
|
12461
|
-
|
|
12593
|
+
const transformXY = ([x, y]) => pointRotateRads12(
|
|
12594
|
+
pointFrom14(element.x + x, element.y + y),
|
|
12595
|
+
pointFrom14(cx, cy),
|
|
12462
12596
|
element.angle
|
|
12463
12597
|
);
|
|
12464
12598
|
const res = getMinMaxXYFromCurvePathOps(ops, transformXY);
|
|
@@ -12569,8 +12703,8 @@ var getClosestElementBounds = (elements, from) => {
|
|
|
12569
12703
|
elements.forEach((element) => {
|
|
12570
12704
|
const [x1, y1, x2, y2] = getElementBounds(element, elementsMap);
|
|
12571
12705
|
const distance3 = pointDistance7(
|
|
12572
|
-
|
|
12573
|
-
|
|
12706
|
+
pointFrom14((x1 + x2) / 2, (y1 + y2) / 2),
|
|
12707
|
+
pointFrom14(from.x, from.y)
|
|
12574
12708
|
);
|
|
12575
12709
|
if (distance3 < minDistance) {
|
|
12576
12710
|
minDistance = distance3;
|
|
@@ -12606,7 +12740,7 @@ var getVisibleSceneBounds = ({
|
|
|
12606
12740
|
-scrollY + height / zoom.value
|
|
12607
12741
|
];
|
|
12608
12742
|
};
|
|
12609
|
-
var getCenterForBounds = (bounds) =>
|
|
12743
|
+
var getCenterForBounds = (bounds) => pointFrom14(
|
|
12610
12744
|
bounds[0] + (bounds[2] - bounds[0]) / 2,
|
|
12611
12745
|
bounds[1] + (bounds[3] - bounds[1]) / 2
|
|
12612
12746
|
);
|
|
@@ -12620,23 +12754,23 @@ var aabbForElement = (element, elementsMap, offset) => {
|
|
|
12620
12754
|
midY: element.y + element.height / 2
|
|
12621
12755
|
};
|
|
12622
12756
|
const center = elementCenterPoint(element, elementsMap);
|
|
12623
|
-
const [topLeftX, topLeftY] =
|
|
12624
|
-
|
|
12757
|
+
const [topLeftX, topLeftY] = pointRotateRads12(
|
|
12758
|
+
pointFrom14(bbox.minX, bbox.minY),
|
|
12625
12759
|
center,
|
|
12626
12760
|
element.angle
|
|
12627
12761
|
);
|
|
12628
|
-
const [topRightX, topRightY] =
|
|
12629
|
-
|
|
12762
|
+
const [topRightX, topRightY] = pointRotateRads12(
|
|
12763
|
+
pointFrom14(bbox.maxX, bbox.minY),
|
|
12630
12764
|
center,
|
|
12631
12765
|
element.angle
|
|
12632
12766
|
);
|
|
12633
|
-
const [bottomRightX, bottomRightY] =
|
|
12634
|
-
|
|
12767
|
+
const [bottomRightX, bottomRightY] = pointRotateRads12(
|
|
12768
|
+
pointFrom14(bbox.maxX, bbox.maxY),
|
|
12635
12769
|
center,
|
|
12636
12770
|
element.angle
|
|
12637
12771
|
);
|
|
12638
|
-
const [bottomLeftX, bottomLeftY] =
|
|
12639
|
-
|
|
12772
|
+
const [bottomLeftX, bottomLeftY] = pointRotateRads12(
|
|
12773
|
+
pointFrom14(bbox.minX, bbox.maxY),
|
|
12640
12774
|
center,
|
|
12641
12775
|
element.angle
|
|
12642
12776
|
);
|
|
@@ -12668,7 +12802,7 @@ var doBoundsIntersect = (bounds1, bounds2) => {
|
|
|
12668
12802
|
};
|
|
12669
12803
|
var elementCenterPoint = (element, elementsMap, xOffset = 0, yOffset = 0) => {
|
|
12670
12804
|
const [x, y] = getCenterForBounds(getElementBounds(element, elementsMap));
|
|
12671
|
-
return
|
|
12805
|
+
return pointFrom14(x + xOffset, y + yOffset);
|
|
12672
12806
|
};
|
|
12673
12807
|
|
|
12674
12808
|
// src/sizeHelpers.ts
|
|
@@ -12849,7 +12983,6 @@ import {
|
|
|
12849
12983
|
arrayToMap as arrayToMap10,
|
|
12850
12984
|
arrayToObject,
|
|
12851
12985
|
assertNever as assertNever4,
|
|
12852
|
-
invariant as invariant8,
|
|
12853
12986
|
isDevEnv as isDevEnv7,
|
|
12854
12987
|
isShallowEqual as isShallowEqual2,
|
|
12855
12988
|
isTestEnv as isTestEnv8,
|
|
@@ -13496,7 +13629,7 @@ var EphemeralIncrement = class extends StoreIncrement {
|
|
|
13496
13629
|
this.change = change;
|
|
13497
13630
|
}
|
|
13498
13631
|
};
|
|
13499
|
-
var StoreDelta = class {
|
|
13632
|
+
var StoreDelta = class _StoreDelta {
|
|
13500
13633
|
constructor(id, elements, appState) {
|
|
13501
13634
|
this.id = id;
|
|
13502
13635
|
this.elements = elements;
|
|
@@ -13534,10 +13667,23 @@ var StoreDelta = class {
|
|
|
13534
13667
|
*/
|
|
13535
13668
|
static load({
|
|
13536
13669
|
id,
|
|
13537
|
-
elements: { added, removed, updated }
|
|
13670
|
+
elements: { added, removed, updated },
|
|
13671
|
+
appState: { delta: appStateDelta }
|
|
13538
13672
|
}) {
|
|
13539
13673
|
const elements = ElementsDelta.create(added, removed, updated);
|
|
13540
|
-
|
|
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;
|
|
13541
13687
|
}
|
|
13542
13688
|
/**
|
|
13543
13689
|
* Inverse store delta, creates new instance of `StoreDelta`.
|
|
@@ -13548,9 +13694,7 @@ var StoreDelta = class {
|
|
|
13548
13694
|
/**
|
|
13549
13695
|
* Apply the delta to the passed elements and appState, does not modify the snapshot.
|
|
13550
13696
|
*/
|
|
13551
|
-
static applyTo(delta, elements, appState, options
|
|
13552
|
-
excludedProperties: /* @__PURE__ */ new Set()
|
|
13553
|
-
}) {
|
|
13697
|
+
static applyTo(delta, elements, appState, options) {
|
|
13554
13698
|
const [nextElements, elementsContainVisibleChange] = delta.elements.applyTo(
|
|
13555
13699
|
elements,
|
|
13556
13700
|
StoreSnapshot.empty().elements,
|
|
@@ -13576,6 +13720,9 @@ var StoreDelta = class {
|
|
|
13576
13720
|
}
|
|
13577
13721
|
);
|
|
13578
13722
|
}
|
|
13723
|
+
static empty() {
|
|
13724
|
+
return _StoreDelta.create(ElementsDelta.empty(), AppStateDelta.empty());
|
|
13725
|
+
}
|
|
13579
13726
|
isEmpty() {
|
|
13580
13727
|
return this.elements.isEmpty() && this.appState.isEmpty();
|
|
13581
13728
|
}
|
|
@@ -13816,8 +13963,7 @@ var getDefaultObservedAppState = () => {
|
|
|
13816
13963
|
viewBackgroundColor: COLOR_PALETTE2.white,
|
|
13817
13964
|
selectedElementIds: {},
|
|
13818
13965
|
selectedGroupIds: {},
|
|
13819
|
-
|
|
13820
|
-
selectedLinearElementIsEditing: null,
|
|
13966
|
+
selectedLinearElement: null,
|
|
13821
13967
|
croppingElementId: null,
|
|
13822
13968
|
activeLockedId: null,
|
|
13823
13969
|
lockedMultiSelections: {}
|
|
@@ -13833,8 +13979,10 @@ var getObservedAppState = (appState) => {
|
|
|
13833
13979
|
croppingElementId: appState.croppingElementId,
|
|
13834
13980
|
activeLockedId: appState.activeLockedId,
|
|
13835
13981
|
lockedMultiSelections: appState.lockedMultiSelections,
|
|
13836
|
-
|
|
13837
|
-
|
|
13982
|
+
selectedLinearElement: appState.selectedLinearElement ? {
|
|
13983
|
+
elementId: appState.selectedLinearElement.elementId,
|
|
13984
|
+
isEditing: !!appState.selectedLinearElement.isEditing
|
|
13985
|
+
} : null
|
|
13838
13986
|
};
|
|
13839
13987
|
Reflect.defineProperty(observedAppState, hiddenObservedAppStateProp, {
|
|
13840
13988
|
value: true,
|
|
@@ -14398,9 +14546,9 @@ var Scene = class {
|
|
|
14398
14546
|
getFramesIncludingDeleted() {
|
|
14399
14547
|
return this.frames;
|
|
14400
14548
|
}
|
|
14401
|
-
constructor(elements = null) {
|
|
14549
|
+
constructor(elements = null, options) {
|
|
14402
14550
|
if (elements) {
|
|
14403
|
-
this.replaceAllElements(elements);
|
|
14551
|
+
this.replaceAllElements(elements, options);
|
|
14404
14552
|
}
|
|
14405
14553
|
}
|
|
14406
14554
|
getSelectedElements(opts) {
|
|
@@ -14465,10 +14613,12 @@ var Scene = class {
|
|
|
14465
14613
|
}
|
|
14466
14614
|
return didChange;
|
|
14467
14615
|
}
|
|
14468
|
-
replaceAllElements(nextElements) {
|
|
14616
|
+
replaceAllElements(nextElements, options) {
|
|
14469
14617
|
const _nextElements = toArray(nextElements);
|
|
14470
14618
|
const nextFrameLikes = [];
|
|
14471
|
-
|
|
14619
|
+
if (!options?.skipValidation) {
|
|
14620
|
+
validateIndicesThrottled(_nextElements);
|
|
14621
|
+
}
|
|
14472
14622
|
this.elements = syncInvalidIndices2(_nextElements);
|
|
14473
14623
|
this.elementsMap.clear();
|
|
14474
14624
|
this.elements.forEach((element) => {
|
|
@@ -14641,16 +14791,16 @@ var Delta = class _Delta {
|
|
|
14641
14791
|
/**
|
|
14642
14792
|
* Merges two deltas into a new one.
|
|
14643
14793
|
*/
|
|
14644
|
-
static merge(delta1, delta2) {
|
|
14794
|
+
static merge(delta1, delta2, delta3 = _Delta.empty()) {
|
|
14645
14795
|
return _Delta.create(
|
|
14646
|
-
{ ...delta1.deleted, ...delta2.deleted },
|
|
14647
|
-
{ ...delta1.inserted, ...delta2.inserted }
|
|
14796
|
+
{ ...delta1.deleted, ...delta2.deleted, ...delta3.deleted },
|
|
14797
|
+
{ ...delta1.inserted, ...delta2.inserted, ...delta3.inserted }
|
|
14648
14798
|
);
|
|
14649
14799
|
}
|
|
14650
14800
|
/**
|
|
14651
14801
|
* Merges deleted and inserted object partials.
|
|
14652
14802
|
*/
|
|
14653
|
-
static mergeObjects(prev, added, removed) {
|
|
14803
|
+
static mergeObjects(prev, added, removed = {}) {
|
|
14654
14804
|
const cloned = { ...prev };
|
|
14655
14805
|
for (const key of Object.keys(removed)) {
|
|
14656
14806
|
delete cloned[key];
|
|
@@ -14871,6 +15021,9 @@ var AppStateDelta = class _AppStateDelta {
|
|
|
14871
15021
|
constructor(delta) {
|
|
14872
15022
|
this.delta = delta;
|
|
14873
15023
|
}
|
|
15024
|
+
static create(delta) {
|
|
15025
|
+
return new _AppStateDelta(delta);
|
|
15026
|
+
}
|
|
14874
15027
|
static calculate(prevAppState, nextAppState) {
|
|
14875
15028
|
const delta = Delta.calculate(
|
|
14876
15029
|
prevAppState,
|
|
@@ -14893,65 +15046,97 @@ var AppStateDelta = class _AppStateDelta {
|
|
|
14893
15046
|
return new _AppStateDelta(inversedDelta);
|
|
14894
15047
|
}
|
|
14895
15048
|
squash(delta) {
|
|
14896
|
-
|
|
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
|
+
);
|
|
14897
15095
|
return this;
|
|
14898
15096
|
}
|
|
14899
15097
|
applyTo(appState, nextElements) {
|
|
14900
15098
|
try {
|
|
14901
15099
|
const {
|
|
14902
|
-
selectedElementIds:
|
|
14903
|
-
selectedGroupIds:
|
|
15100
|
+
selectedElementIds: deletedSelectedElementIds = {},
|
|
15101
|
+
selectedGroupIds: deletedSelectedGroupIds = {},
|
|
15102
|
+
lockedMultiSelections: deletedLockedMultiSelections = {}
|
|
14904
15103
|
} = this.delta.deleted;
|
|
14905
15104
|
const {
|
|
14906
|
-
selectedElementIds:
|
|
14907
|
-
selectedGroupIds:
|
|
14908
|
-
|
|
14909
|
-
|
|
15105
|
+
selectedElementIds: insertedSelectedElementIds = {},
|
|
15106
|
+
selectedGroupIds: insertedSelectedGroupIds = {},
|
|
15107
|
+
lockedMultiSelections: insertedLockedMultiSelections = {},
|
|
15108
|
+
selectedLinearElement: insertedSelectedLinearElement,
|
|
14910
15109
|
...directlyApplicablePartial
|
|
14911
15110
|
} = this.delta.inserted;
|
|
14912
15111
|
const mergedSelectedElementIds = Delta.mergeObjects(
|
|
14913
15112
|
appState.selectedElementIds,
|
|
14914
|
-
|
|
14915
|
-
|
|
15113
|
+
insertedSelectedElementIds,
|
|
15114
|
+
deletedSelectedElementIds
|
|
14916
15115
|
);
|
|
14917
15116
|
const mergedSelectedGroupIds = Delta.mergeObjects(
|
|
14918
15117
|
appState.selectedGroupIds,
|
|
14919
|
-
|
|
14920
|
-
|
|
15118
|
+
insertedSelectedGroupIds,
|
|
15119
|
+
deletedSelectedGroupIds
|
|
14921
15120
|
);
|
|
14922
|
-
|
|
14923
|
-
|
|
14924
|
-
|
|
14925
|
-
|
|
14926
|
-
|
|
14927
|
-
|
|
14928
|
-
|
|
14929
|
-
|
|
14930
|
-
|
|
14931
|
-
|
|
14932
|
-
|
|
14933
|
-
|
|
14934
|
-
}
|
|
14935
|
-
if (
|
|
14936
|
-
// Value being 'null' is equivaluent to unknown in this case because it only gets set
|
|
14937
|
-
// to null when 'selectedLinearElementId' is set to null
|
|
14938
|
-
selectedLinearElementIsEditing != null
|
|
14939
|
-
) {
|
|
14940
|
-
invariant8(
|
|
14941
|
-
selectedLinearElement,
|
|
14942
|
-
`selectedLinearElement is null when selectedLinearElementIsEditing is set to ${selectedLinearElementIsEditing}`
|
|
14943
|
-
);
|
|
14944
|
-
selectedLinearElement = {
|
|
14945
|
-
...selectedLinearElement,
|
|
14946
|
-
isEditing: selectedLinearElementIsEditing
|
|
14947
|
-
};
|
|
14948
|
-
}
|
|
15121
|
+
const mergedLockedMultiSelections = Delta.mergeObjects(
|
|
15122
|
+
appState.lockedMultiSelections,
|
|
15123
|
+
insertedLockedMultiSelections,
|
|
15124
|
+
deletedLockedMultiSelections
|
|
15125
|
+
);
|
|
15126
|
+
const selectedLinearElement = insertedSelectedLinearElement && nextElements.has(insertedSelectedLinearElement.elementId) ? new LinearElementEditor(
|
|
15127
|
+
nextElements.get(
|
|
15128
|
+
insertedSelectedLinearElement.elementId
|
|
15129
|
+
),
|
|
15130
|
+
nextElements,
|
|
15131
|
+
insertedSelectedLinearElement.isEditing
|
|
15132
|
+
) : null;
|
|
14949
15133
|
const nextAppState = {
|
|
14950
15134
|
...appState,
|
|
14951
15135
|
...directlyApplicablePartial,
|
|
14952
15136
|
selectedElementIds: mergedSelectedElementIds,
|
|
14953
15137
|
selectedGroupIds: mergedSelectedGroupIds,
|
|
14954
|
-
|
|
15138
|
+
lockedMultiSelections: mergedLockedMultiSelections,
|
|
15139
|
+
selectedLinearElement: typeof insertedSelectedLinearElement !== "undefined" ? selectedLinearElement : appState.selectedLinearElement
|
|
14955
15140
|
};
|
|
14956
15141
|
const constainsVisibleChanges = this.filterInvisibleChanges(
|
|
14957
15142
|
appState,
|
|
@@ -15041,63 +15226,44 @@ var AppStateDelta = class _AppStateDelta {
|
|
|
15041
15226
|
nextAppState[key] = null;
|
|
15042
15227
|
}
|
|
15043
15228
|
break;
|
|
15044
|
-
case "
|
|
15045
|
-
const
|
|
15046
|
-
|
|
15047
|
-
if (!linearElement) {
|
|
15229
|
+
case "selectedLinearElement":
|
|
15230
|
+
const nextLinearElement = nextAppState[key];
|
|
15231
|
+
if (!nextLinearElement) {
|
|
15048
15232
|
visibleDifferenceFlag.value = true;
|
|
15049
15233
|
} else {
|
|
15050
|
-
const element = nextElements.get(
|
|
15234
|
+
const element = nextElements.get(nextLinearElement.elementId);
|
|
15051
15235
|
if (element && !element.isDeleted) {
|
|
15052
15236
|
visibleDifferenceFlag.value = true;
|
|
15053
15237
|
} else {
|
|
15054
|
-
nextAppState[
|
|
15238
|
+
nextAppState[key] = null;
|
|
15055
15239
|
}
|
|
15056
15240
|
}
|
|
15057
15241
|
break;
|
|
15058
|
-
|
|
15059
|
-
case "selectedLinearElementIsEditing": {
|
|
15060
|
-
const prevIsEditing = prevAppState.selectedLinearElement?.isEditing ?? false;
|
|
15061
|
-
const nextIsEditing = nextAppState.selectedLinearElement?.isEditing ?? false;
|
|
15062
|
-
if (prevIsEditing !== nextIsEditing) {
|
|
15063
|
-
visibleDifferenceFlag.value = true;
|
|
15064
|
-
}
|
|
15065
|
-
break;
|
|
15066
|
-
}
|
|
15067
|
-
case "lockedMultiSelections": {
|
|
15242
|
+
case "lockedMultiSelections":
|
|
15068
15243
|
const prevLockedUnits = prevAppState[key] || {};
|
|
15069
15244
|
const nextLockedUnits = nextAppState[key] || {};
|
|
15070
15245
|
if (!isShallowEqual2(prevLockedUnits, nextLockedUnits)) {
|
|
15071
15246
|
visibleDifferenceFlag.value = true;
|
|
15072
15247
|
}
|
|
15073
15248
|
break;
|
|
15074
|
-
|
|
15075
|
-
case "activeLockedId": {
|
|
15249
|
+
case "activeLockedId":
|
|
15076
15250
|
const prevHitLockedId = prevAppState[key] || null;
|
|
15077
15251
|
const nextHitLockedId = nextAppState[key] || null;
|
|
15078
15252
|
if (prevHitLockedId !== nextHitLockedId) {
|
|
15079
15253
|
visibleDifferenceFlag.value = true;
|
|
15080
15254
|
}
|
|
15081
15255
|
break;
|
|
15082
|
-
|
|
15083
|
-
default: {
|
|
15256
|
+
default:
|
|
15084
15257
|
assertNever4(
|
|
15085
15258
|
key,
|
|
15086
15259
|
`Unknown ObservedElementsAppState's key "${key}"`,
|
|
15087
15260
|
true
|
|
15088
15261
|
);
|
|
15089
|
-
}
|
|
15090
15262
|
}
|
|
15091
15263
|
}
|
|
15092
15264
|
}
|
|
15093
15265
|
return visibleDifferenceFlag.value;
|
|
15094
15266
|
}
|
|
15095
|
-
static convertToAppStateKey(key) {
|
|
15096
|
-
switch (key) {
|
|
15097
|
-
case "selectedLinearElementId":
|
|
15098
|
-
return "selectedLinearElement";
|
|
15099
|
-
}
|
|
15100
|
-
}
|
|
15101
15267
|
static filterSelectedElements(selectedElementIds, elements, visibleDifferenceFlag) {
|
|
15102
15268
|
const ids = Object.keys(selectedElementIds);
|
|
15103
15269
|
if (!ids.length) {
|
|
@@ -15136,8 +15302,7 @@ var AppStateDelta = class _AppStateDelta {
|
|
|
15136
15302
|
editingGroupId,
|
|
15137
15303
|
selectedGroupIds,
|
|
15138
15304
|
selectedElementIds,
|
|
15139
|
-
|
|
15140
|
-
selectedLinearElementIsEditing,
|
|
15305
|
+
selectedLinearElement,
|
|
15141
15306
|
croppingElementId,
|
|
15142
15307
|
lockedMultiSelections,
|
|
15143
15308
|
activeLockedId,
|
|
@@ -15174,12 +15339,6 @@ var AppStateDelta = class _AppStateDelta {
|
|
|
15174
15339
|
"lockedMultiSelections",
|
|
15175
15340
|
(prevValue) => prevValue ?? {}
|
|
15176
15341
|
);
|
|
15177
|
-
Delta.diffObjects(
|
|
15178
|
-
deleted,
|
|
15179
|
-
inserted,
|
|
15180
|
-
"activeLockedId",
|
|
15181
|
-
(prevValue) => prevValue ?? null
|
|
15182
|
-
);
|
|
15183
15342
|
} catch (e) {
|
|
15184
15343
|
console.error(`Couldn't postprocess appstate change deltas.`);
|
|
15185
15344
|
if (isTestEnv8() || isDevEnv7()) {
|
|
@@ -15258,13 +15417,17 @@ var ElementsDelta = class _ElementsDelta {
|
|
|
15258
15417
|
static satisfiesCommmonInvariants = ({
|
|
15259
15418
|
deleted,
|
|
15260
15419
|
inserted
|
|
15261
|
-
}) =>
|
|
15262
|
-
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
|
|
15263
15422
|
deleted.version >= 0 && inserted.version >= 0 && // versions should never be the same
|
|
15264
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
|
+
};
|
|
15265
15428
|
static validate(elementsDelta, type, satifiesSpecialInvariants) {
|
|
15266
15429
|
for (const [id, delta] of Object.entries(elementsDelta[type])) {
|
|
15267
|
-
if (!this.satisfiesCommmonInvariants(delta) || !satifiesSpecialInvariants(delta)) {
|
|
15430
|
+
if (!this.satisfiesCommmonInvariants(delta) || !this.satisfiesUniqueInvariants(elementsDelta, id) || !satifiesSpecialInvariants(delta)) {
|
|
15268
15431
|
console.error(
|
|
15269
15432
|
`Broken invariant for "${type}" delta, element "${id}", delta:`,
|
|
15270
15433
|
delta
|
|
@@ -15291,7 +15454,7 @@ var ElementsDelta = class _ElementsDelta {
|
|
|
15291
15454
|
for (const prevElement of prevElements.values()) {
|
|
15292
15455
|
const nextElement = nextElements.get(prevElement.id);
|
|
15293
15456
|
if (!nextElement) {
|
|
15294
|
-
const deleted = { ...prevElement
|
|
15457
|
+
const deleted = { ...prevElement };
|
|
15295
15458
|
const inserted = {
|
|
15296
15459
|
isDeleted: true,
|
|
15297
15460
|
version: prevElement.version + 1,
|
|
@@ -15302,7 +15465,11 @@ var ElementsDelta = class _ElementsDelta {
|
|
|
15302
15465
|
inserted,
|
|
15303
15466
|
_ElementsDelta.stripIrrelevantProps
|
|
15304
15467
|
);
|
|
15305
|
-
|
|
15468
|
+
if (!prevElement.isDeleted) {
|
|
15469
|
+
removed[prevElement.id] = delta;
|
|
15470
|
+
} else {
|
|
15471
|
+
updated[prevElement.id] = delta;
|
|
15472
|
+
}
|
|
15306
15473
|
}
|
|
15307
15474
|
}
|
|
15308
15475
|
for (const nextElement of nextElements.values()) {
|
|
@@ -15314,15 +15481,18 @@ var ElementsDelta = class _ElementsDelta {
|
|
|
15314
15481
|
versionNonce: randomInteger4()
|
|
15315
15482
|
};
|
|
15316
15483
|
const inserted = {
|
|
15317
|
-
...nextElement
|
|
15318
|
-
isDeleted: false
|
|
15484
|
+
...nextElement
|
|
15319
15485
|
};
|
|
15320
15486
|
const delta = Delta.create(
|
|
15321
15487
|
deleted,
|
|
15322
15488
|
inserted,
|
|
15323
15489
|
_ElementsDelta.stripIrrelevantProps
|
|
15324
15490
|
);
|
|
15325
|
-
|
|
15491
|
+
if (!nextElement.isDeleted) {
|
|
15492
|
+
added[nextElement.id] = delta;
|
|
15493
|
+
} else {
|
|
15494
|
+
updated[nextElement.id] = delta;
|
|
15495
|
+
}
|
|
15326
15496
|
continue;
|
|
15327
15497
|
}
|
|
15328
15498
|
if (prevElement.versionNonce !== nextElement.versionNonce) {
|
|
@@ -15343,9 +15513,7 @@ var ElementsDelta = class _ElementsDelta {
|
|
|
15343
15513
|
}
|
|
15344
15514
|
continue;
|
|
15345
15515
|
}
|
|
15346
|
-
|
|
15347
|
-
updated[nextElement.id] = delta;
|
|
15348
|
-
}
|
|
15516
|
+
updated[nextElement.id] = delta;
|
|
15349
15517
|
}
|
|
15350
15518
|
}
|
|
15351
15519
|
return _ElementsDelta.create(added, removed, updated);
|
|
@@ -15435,26 +15603,30 @@ var ElementsDelta = class _ElementsDelta {
|
|
|
15435
15603
|
// redistribute the deltas as `isDeleted` could have been updated
|
|
15436
15604
|
});
|
|
15437
15605
|
}
|
|
15438
|
-
applyTo(elements, snapshot = StoreSnapshot.empty().elements, options
|
|
15439
|
-
excludedProperties: /* @__PURE__ */ new Set()
|
|
15440
|
-
}) {
|
|
15606
|
+
applyTo(elements, snapshot = StoreSnapshot.empty().elements, options) {
|
|
15441
15607
|
let nextElements = new Map(elements);
|
|
15442
15608
|
let changedElements;
|
|
15443
15609
|
const flags = {
|
|
15444
15610
|
containsVisibleDifference: false,
|
|
15445
|
-
containsZindexDifference: false
|
|
15611
|
+
containsZindexDifference: false,
|
|
15612
|
+
applyDirection: void 0
|
|
15446
15613
|
};
|
|
15447
15614
|
try {
|
|
15448
15615
|
const applyDeltas = _ElementsDelta.createApplier(
|
|
15616
|
+
elements,
|
|
15449
15617
|
nextElements,
|
|
15450
15618
|
snapshot,
|
|
15451
|
-
|
|
15452
|
-
|
|
15619
|
+
flags,
|
|
15620
|
+
options
|
|
15453
15621
|
);
|
|
15454
15622
|
const addedElements = applyDeltas(this.added);
|
|
15455
15623
|
const removedElements = applyDeltas(this.removed);
|
|
15456
15624
|
const updatedElements = applyDeltas(this.updated);
|
|
15457
|
-
const affectedElements = this.resolveConflicts(
|
|
15625
|
+
const affectedElements = this.resolveConflicts(
|
|
15626
|
+
elements,
|
|
15627
|
+
nextElements,
|
|
15628
|
+
flags.applyDirection
|
|
15629
|
+
);
|
|
15458
15630
|
changedElements = new Map([
|
|
15459
15631
|
...addedElements,
|
|
15460
15632
|
...removedElements,
|
|
@@ -15474,9 +15646,7 @@ var ElementsDelta = class _ElementsDelta {
|
|
|
15474
15646
|
changedElements,
|
|
15475
15647
|
flags
|
|
15476
15648
|
);
|
|
15477
|
-
|
|
15478
|
-
_ElementsDelta.redrawTextBoundingBoxes(tempScene, changedElements);
|
|
15479
|
-
_ElementsDelta.redrawBoundArrows(tempScene, changedElements);
|
|
15649
|
+
_ElementsDelta.redrawElements(nextElements, changedElements);
|
|
15480
15650
|
} catch (e) {
|
|
15481
15651
|
console.error(
|
|
15482
15652
|
`Couldn't mutate elements after applying elements change`,
|
|
@@ -15490,34 +15660,81 @@ var ElementsDelta = class _ElementsDelta {
|
|
|
15490
15660
|
}
|
|
15491
15661
|
}
|
|
15492
15662
|
squash(delta) {
|
|
15663
|
+
if (delta.isEmpty()) {
|
|
15664
|
+
return this;
|
|
15665
|
+
}
|
|
15493
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
|
+
};
|
|
15494
15692
|
for (const [id, nextDelta] of Object.entries(added)) {
|
|
15495
|
-
const prevDelta = this.added[id];
|
|
15693
|
+
const prevDelta = this.added[id] ?? this.removed[id] ?? this.updated[id];
|
|
15496
15694
|
if (!prevDelta) {
|
|
15497
15695
|
this.added[id] = nextDelta;
|
|
15498
15696
|
} else {
|
|
15499
|
-
|
|
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);
|
|
15500
15701
|
}
|
|
15501
15702
|
}
|
|
15502
15703
|
for (const [id, nextDelta] of Object.entries(removed)) {
|
|
15503
|
-
const prevDelta = this.removed[id];
|
|
15704
|
+
const prevDelta = this.added[id] ?? this.removed[id] ?? this.updated[id];
|
|
15504
15705
|
if (!prevDelta) {
|
|
15505
15706
|
this.removed[id] = nextDelta;
|
|
15506
15707
|
} else {
|
|
15507
|
-
|
|
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);
|
|
15508
15712
|
}
|
|
15509
15713
|
}
|
|
15510
15714
|
for (const [id, nextDelta] of Object.entries(updated)) {
|
|
15511
|
-
const prevDelta = this.updated[id];
|
|
15715
|
+
const prevDelta = this.added[id] ?? this.removed[id] ?? this.updated[id];
|
|
15512
15716
|
if (!prevDelta) {
|
|
15513
15717
|
this.updated[id] = nextDelta;
|
|
15514
15718
|
} else {
|
|
15515
|
-
|
|
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
|
+
}
|
|
15516
15728
|
}
|
|
15517
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
|
+
}
|
|
15518
15735
|
return this;
|
|
15519
15736
|
}
|
|
15520
|
-
static createApplier = (nextElements, snapshot,
|
|
15737
|
+
static createApplier = (prevElements, nextElements, snapshot, flags, options) => (deltas) => {
|
|
15521
15738
|
const getElement = _ElementsDelta.createGetter(
|
|
15522
15739
|
nextElements,
|
|
15523
15740
|
snapshot,
|
|
@@ -15526,14 +15743,20 @@ var ElementsDelta = class _ElementsDelta {
|
|
|
15526
15743
|
return Object.entries(deltas).reduce((acc, [id, delta]) => {
|
|
15527
15744
|
const element = getElement(id, delta.inserted);
|
|
15528
15745
|
if (element) {
|
|
15529
|
-
const
|
|
15746
|
+
const nextElement = _ElementsDelta.applyDelta(
|
|
15530
15747
|
element,
|
|
15531
15748
|
delta,
|
|
15532
|
-
|
|
15533
|
-
|
|
15749
|
+
flags,
|
|
15750
|
+
options
|
|
15534
15751
|
);
|
|
15535
|
-
nextElements.set(
|
|
15536
|
-
acc.set(
|
|
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
|
+
}
|
|
15537
15760
|
}
|
|
15538
15761
|
return acc;
|
|
15539
15762
|
}, /* @__PURE__ */ new Map());
|
|
@@ -15558,13 +15781,13 @@ var ElementsDelta = class _ElementsDelta {
|
|
|
15558
15781
|
}
|
|
15559
15782
|
return element;
|
|
15560
15783
|
};
|
|
15561
|
-
static applyDelta(element, delta,
|
|
15784
|
+
static applyDelta(element, delta, flags, options) {
|
|
15562
15785
|
const directlyApplicablePartial = {};
|
|
15563
15786
|
for (const key of Object.keys(delta.inserted)) {
|
|
15564
15787
|
if (key === "boundElements") {
|
|
15565
15788
|
continue;
|
|
15566
15789
|
}
|
|
15567
|
-
if (options
|
|
15790
|
+
if (options?.excludedProperties?.has(key)) {
|
|
15568
15791
|
continue;
|
|
15569
15792
|
}
|
|
15570
15793
|
const value = delta.inserted[key];
|
|
@@ -15592,7 +15815,7 @@ var ElementsDelta = class _ElementsDelta {
|
|
|
15592
15815
|
if (!flags.containsZindexDifference) {
|
|
15593
15816
|
flags.containsZindexDifference = delta.deleted.index !== delta.inserted.index;
|
|
15594
15817
|
}
|
|
15595
|
-
return newElementWith(element, directlyApplicablePartial);
|
|
15818
|
+
return newElementWith(element, directlyApplicablePartial, true);
|
|
15596
15819
|
}
|
|
15597
15820
|
/**
|
|
15598
15821
|
* Check for visible changes regardless of whether they were removed, added or updated.
|
|
@@ -15617,25 +15840,32 @@ var ElementsDelta = class _ElementsDelta {
|
|
|
15617
15840
|
*
|
|
15618
15841
|
* @returns all elements affected by the conflict resolution
|
|
15619
15842
|
*/
|
|
15620
|
-
resolveConflicts(prevElements, nextElements) {
|
|
15843
|
+
resolveConflicts(prevElements, nextElements, applyDirection = "forward") {
|
|
15621
15844
|
const nextAffectedElements = /* @__PURE__ */ new Map();
|
|
15622
15845
|
const updater = (element, updates) => {
|
|
15623
15846
|
const nextElement = nextElements.get(element.id);
|
|
15624
15847
|
if (!nextElement) {
|
|
15625
15848
|
return;
|
|
15626
15849
|
}
|
|
15850
|
+
const prevElement = prevElements.get(element.id);
|
|
15851
|
+
const nextVersion = applyDirection === "forward" ? nextElement.version + 1 : nextElement.version - 1;
|
|
15852
|
+
const elementUpdates = updates;
|
|
15627
15853
|
let affectedElement;
|
|
15628
|
-
if (
|
|
15854
|
+
if (prevElement === nextElement) {
|
|
15629
15855
|
affectedElement = newElementWith(
|
|
15630
15856
|
nextElement,
|
|
15631
|
-
|
|
15857
|
+
{
|
|
15858
|
+
...elementUpdates,
|
|
15859
|
+
version: nextVersion
|
|
15860
|
+
},
|
|
15861
|
+
true
|
|
15632
15862
|
);
|
|
15633
15863
|
} else {
|
|
15634
|
-
affectedElement = mutateElement(
|
|
15635
|
-
|
|
15636
|
-
|
|
15637
|
-
|
|
15638
|
-
);
|
|
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
|
+
});
|
|
15639
15869
|
}
|
|
15640
15870
|
nextAffectedElements.set(affectedElement.id, affectedElement);
|
|
15641
15871
|
nextElements.set(affectedElement.id, affectedElement);
|
|
@@ -15698,6 +15928,20 @@ var ElementsDelta = class _ElementsDelta {
|
|
|
15698
15928
|
);
|
|
15699
15929
|
BindableElement.rebindAffected(nextElements, nextElement(), updater);
|
|
15700
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
|
+
}
|
|
15701
15945
|
static redrawTextBoundingBoxes(scene, changed) {
|
|
15702
15946
|
const elements = scene.getNonDeletedElementsMap();
|
|
15703
15947
|
const boxesToRedraw = /* @__PURE__ */ new Map();
|
|
@@ -16790,7 +17034,7 @@ var embeddableURLValidator = (url, validateEmbeddable) => {
|
|
|
16790
17034
|
// src/flowchart.ts
|
|
16791
17035
|
init_define_import_meta_env();
|
|
16792
17036
|
import { KEYS as KEYS3, invariant as invariant9, toBrandedType as toBrandedType2 } from "@excalidraw/common";
|
|
16793
|
-
import { pointFrom as
|
|
17037
|
+
import { pointFrom as pointFrom15 } from "@excalidraw/math";
|
|
16794
17038
|
var VERTICAL_OFFSET = 100;
|
|
16795
17039
|
var HORIZONTAL_OFFSET = 100;
|
|
16796
17040
|
var getLinkDirectionFromKey = (key) => {
|
|
@@ -17070,7 +17314,7 @@ var createBindingArrow = (startBindingElement, endBindingElement, direction, app
|
|
|
17070
17314
|
strokeWidth: startBindingElement.strokeWidth,
|
|
17071
17315
|
opacity: startBindingElement.opacity,
|
|
17072
17316
|
roughness: startBindingElement.roughness,
|
|
17073
|
-
points: [
|
|
17317
|
+
points: [pointFrom15(0, 0), pointFrom15(endX, endY)],
|
|
17074
17318
|
elbowed: true
|
|
17075
17319
|
});
|
|
17076
17320
|
const elementsMap = scene.getNonDeletedElementsMap();
|
|
@@ -17354,13 +17598,80 @@ var normalizeSVG = (SVGString) => {
|
|
|
17354
17598
|
}
|
|
17355
17599
|
};
|
|
17356
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
|
+
|
|
17357
17668
|
// src/resizeElements.ts
|
|
17358
17669
|
init_define_import_meta_env();
|
|
17359
17670
|
import {
|
|
17360
17671
|
pointCenter as pointCenter3,
|
|
17361
17672
|
normalizeRadians as normalizeRadians2,
|
|
17362
|
-
pointFrom as
|
|
17363
|
-
pointRotateRads as
|
|
17673
|
+
pointFrom as pointFrom16,
|
|
17674
|
+
pointRotateRads as pointRotateRads13
|
|
17364
17675
|
} from "@excalidraw/math";
|
|
17365
17676
|
import {
|
|
17366
17677
|
MIN_FONT_SIZE,
|
|
@@ -17488,7 +17799,16 @@ var rotateSingleElement = (element, scene, pointerX, pointerY, shouldRotateWithD
|
|
|
17488
17799
|
if (boundTextElementId) {
|
|
17489
17800
|
const textElement = scene.getElement(boundTextElementId);
|
|
17490
17801
|
if (textElement && !isArrowElement(element)) {
|
|
17491
|
-
|
|
17802
|
+
const { x, y } = computeBoundTextPosition(
|
|
17803
|
+
element,
|
|
17804
|
+
textElement,
|
|
17805
|
+
scene.getNonDeletedElementsMap()
|
|
17806
|
+
);
|
|
17807
|
+
scene.mutateElement(textElement, {
|
|
17808
|
+
angle,
|
|
17809
|
+
x,
|
|
17810
|
+
y
|
|
17811
|
+
});
|
|
17492
17812
|
}
|
|
17493
17813
|
}
|
|
17494
17814
|
};
|
|
@@ -17525,7 +17845,7 @@ var resizeSingleTextElement = (origElement, element, scene, transformHandleType,
|
|
|
17525
17845
|
return;
|
|
17526
17846
|
}
|
|
17527
17847
|
if (transformHandleType.includes("n") || transformHandleType.includes("s")) {
|
|
17528
|
-
const previousOrigin =
|
|
17848
|
+
const previousOrigin = pointFrom16(origElement.x, origElement.y);
|
|
17529
17849
|
const newOrigin = getResizedOrigin(
|
|
17530
17850
|
previousOrigin,
|
|
17531
17851
|
origElement.width,
|
|
@@ -17566,7 +17886,7 @@ var resizeSingleTextElement = (origElement, element, scene, transformHandleType,
|
|
|
17566
17886
|
element.lineHeight
|
|
17567
17887
|
);
|
|
17568
17888
|
const newHeight = metrics2.height;
|
|
17569
|
-
const previousOrigin =
|
|
17889
|
+
const previousOrigin = pointFrom16(origElement.x, origElement.y);
|
|
17570
17890
|
const newOrigin = getResizedOrigin(
|
|
17571
17891
|
previousOrigin,
|
|
17572
17892
|
origElement.width,
|
|
@@ -17602,9 +17922,9 @@ var rotateMultipleElements = (originalElements, elements, scene, pointerX, point
|
|
|
17602
17922
|
const cx = (x1 + x2) / 2;
|
|
17603
17923
|
const cy = (y1 + y2) / 2;
|
|
17604
17924
|
const origAngle = originalElements.get(element.id)?.angle ?? element.angle;
|
|
17605
|
-
const [rotatedCX, rotatedCY] =
|
|
17606
|
-
|
|
17607
|
-
|
|
17925
|
+
const [rotatedCX, rotatedCY] = pointRotateRads13(
|
|
17926
|
+
pointFrom16(cx, cy),
|
|
17927
|
+
pointFrom16(centerX, centerY),
|
|
17608
17928
|
centerAngle + origAngle - element.angle
|
|
17609
17929
|
);
|
|
17610
17930
|
const updates = isElbowArrow(element) ? {
|
|
@@ -17621,9 +17941,14 @@ var rotateMultipleElements = (originalElements, elements, scene, pointerX, point
|
|
|
17621
17941
|
});
|
|
17622
17942
|
const boundText = getBoundTextElement(element, elementsMap);
|
|
17623
17943
|
if (boundText && !isArrowElement(element)) {
|
|
17944
|
+
const { x, y } = computeBoundTextPosition(
|
|
17945
|
+
element,
|
|
17946
|
+
boundText,
|
|
17947
|
+
elementsMap
|
|
17948
|
+
);
|
|
17624
17949
|
scene.mutateElement(boundText, {
|
|
17625
|
-
x
|
|
17626
|
-
y
|
|
17950
|
+
x,
|
|
17951
|
+
y,
|
|
17627
17952
|
angle: normalizeRadians2(centerAngle + origAngle)
|
|
17628
17953
|
});
|
|
17629
17954
|
}
|
|
@@ -17636,44 +17961,44 @@ var getResizeOffsetXY = (transformHandleType, selectedElements, elementsMap, x,
|
|
|
17636
17961
|
const cx = (x1 + x2) / 2;
|
|
17637
17962
|
const cy = (y1 + y2) / 2;
|
|
17638
17963
|
const angle = selectedElements.length === 1 ? selectedElements[0].angle : 0;
|
|
17639
|
-
[x, y] =
|
|
17640
|
-
|
|
17641
|
-
|
|
17964
|
+
[x, y] = pointRotateRads13(
|
|
17965
|
+
pointFrom16(x, y),
|
|
17966
|
+
pointFrom16(cx, cy),
|
|
17642
17967
|
-angle
|
|
17643
17968
|
);
|
|
17644
17969
|
switch (transformHandleType) {
|
|
17645
17970
|
case "n":
|
|
17646
|
-
return
|
|
17647
|
-
|
|
17648
|
-
|
|
17971
|
+
return pointRotateRads13(
|
|
17972
|
+
pointFrom16(x - (x1 + x2) / 2, y - y1),
|
|
17973
|
+
pointFrom16(0, 0),
|
|
17649
17974
|
angle
|
|
17650
17975
|
);
|
|
17651
17976
|
case "s":
|
|
17652
|
-
return
|
|
17653
|
-
|
|
17654
|
-
|
|
17977
|
+
return pointRotateRads13(
|
|
17978
|
+
pointFrom16(x - (x1 + x2) / 2, y - y2),
|
|
17979
|
+
pointFrom16(0, 0),
|
|
17655
17980
|
angle
|
|
17656
17981
|
);
|
|
17657
17982
|
case "w":
|
|
17658
|
-
return
|
|
17659
|
-
|
|
17660
|
-
|
|
17983
|
+
return pointRotateRads13(
|
|
17984
|
+
pointFrom16(x - x1, y - (y1 + y2) / 2),
|
|
17985
|
+
pointFrom16(0, 0),
|
|
17661
17986
|
angle
|
|
17662
17987
|
);
|
|
17663
17988
|
case "e":
|
|
17664
|
-
return
|
|
17665
|
-
|
|
17666
|
-
|
|
17989
|
+
return pointRotateRads13(
|
|
17990
|
+
pointFrom16(x - x2, y - (y1 + y2) / 2),
|
|
17991
|
+
pointFrom16(0, 0),
|
|
17667
17992
|
angle
|
|
17668
17993
|
);
|
|
17669
17994
|
case "nw":
|
|
17670
|
-
return
|
|
17995
|
+
return pointRotateRads13(pointFrom16(x - x1, y - y1), pointFrom16(0, 0), angle);
|
|
17671
17996
|
case "ne":
|
|
17672
|
-
return
|
|
17997
|
+
return pointRotateRads13(pointFrom16(x - x2, y - y1), pointFrom16(0, 0), angle);
|
|
17673
17998
|
case "sw":
|
|
17674
|
-
return
|
|
17999
|
+
return pointRotateRads13(pointFrom16(x - x1, y - y2), pointFrom16(0, 0), angle);
|
|
17675
18000
|
case "se":
|
|
17676
|
-
return
|
|
18001
|
+
return pointRotateRads13(pointFrom16(x - x2, y - y2), pointFrom16(0, 0), angle);
|
|
17677
18002
|
default:
|
|
17678
18003
|
return [0, 0];
|
|
17679
18004
|
}
|
|
@@ -17836,10 +18161,10 @@ var resizeSingleElement = (nextWidth, nextHeight, latestElement, origElement, or
|
|
|
17836
18161
|
nextHeight,
|
|
17837
18162
|
true
|
|
17838
18163
|
);
|
|
17839
|
-
let previousOrigin =
|
|
18164
|
+
let previousOrigin = pointFrom16(origElement.x, origElement.y);
|
|
17840
18165
|
if (isLinearElement(origElement)) {
|
|
17841
18166
|
const [x1, y1] = getElementBounds(origElement, originalElementsMap);
|
|
17842
|
-
previousOrigin =
|
|
18167
|
+
previousOrigin = pointFrom16(x1, y1);
|
|
17843
18168
|
}
|
|
17844
18169
|
const newOrigin = getResizedOrigin(
|
|
17845
18170
|
previousOrigin,
|
|
@@ -17862,7 +18187,7 @@ var resizeSingleElement = (nextWidth, nextHeight, latestElement, origElement, or
|
|
|
17862
18187
|
newOrigin.x += scaledX;
|
|
17863
18188
|
newOrigin.y += scaledY;
|
|
17864
18189
|
rescaledPoints.points = rescaledPoints.points.map(
|
|
17865
|
-
(p) =>
|
|
18190
|
+
(p) => pointFrom16(p[0] - scaledX, p[1] - scaledY)
|
|
17866
18191
|
);
|
|
17867
18192
|
}
|
|
17868
18193
|
if (nextWidth < 0) {
|
|
@@ -17925,11 +18250,11 @@ var getNextSingleWidthAndHeightFromPointer = (latestElement, origElement, handle
|
|
|
17925
18250
|
origElement.height,
|
|
17926
18251
|
true
|
|
17927
18252
|
);
|
|
17928
|
-
const startTopLeft =
|
|
17929
|
-
const startBottomRight =
|
|
18253
|
+
const startTopLeft = pointFrom16(x1, y1);
|
|
18254
|
+
const startBottomRight = pointFrom16(x2, y2);
|
|
17930
18255
|
const startCenter = pointCenter3(startTopLeft, startBottomRight);
|
|
17931
|
-
const rotatedPointer =
|
|
17932
|
-
|
|
18256
|
+
const rotatedPointer = pointRotateRads13(
|
|
18257
|
+
pointFrom16(pointerX, pointerY),
|
|
17933
18258
|
startCenter,
|
|
17934
18259
|
-origElement.angle
|
|
17935
18260
|
);
|
|
@@ -18287,20 +18612,20 @@ var resizeMultipleElements = (selectedElements, elementsMap, handleDirection, sc
|
|
|
18287
18612
|
// src/resizeTest.ts
|
|
18288
18613
|
init_define_import_meta_env();
|
|
18289
18614
|
import {
|
|
18290
|
-
pointFrom as
|
|
18615
|
+
pointFrom as pointFrom18,
|
|
18291
18616
|
pointOnLineSegment,
|
|
18292
|
-
pointRotateRads as
|
|
18617
|
+
pointRotateRads as pointRotateRads15
|
|
18293
18618
|
} from "@excalidraw/math";
|
|
18294
|
-
import {
|
|
18619
|
+
import {
|
|
18620
|
+
SIDE_RESIZING_THRESHOLD
|
|
18621
|
+
} from "@excalidraw/common";
|
|
18295
18622
|
|
|
18296
18623
|
// src/transformHandles.ts
|
|
18297
18624
|
init_define_import_meta_env();
|
|
18298
18625
|
import {
|
|
18299
|
-
DEFAULT_TRANSFORM_HANDLE_SPACING
|
|
18300
|
-
isAndroid,
|
|
18301
|
-
isIOS
|
|
18626
|
+
DEFAULT_TRANSFORM_HANDLE_SPACING
|
|
18302
18627
|
} from "@excalidraw/common";
|
|
18303
|
-
import { pointFrom as
|
|
18628
|
+
import { pointFrom as pointFrom17, pointRotateRads as pointRotateRads14 } from "@excalidraw/math";
|
|
18304
18629
|
var transformHandleSizes = {
|
|
18305
18630
|
mouse: 8,
|
|
18306
18631
|
pen: 16,
|
|
@@ -18341,24 +18666,21 @@ var OMIT_SIDES_FOR_LINE_BACKSLASH = {
|
|
|
18341
18666
|
w: true
|
|
18342
18667
|
};
|
|
18343
18668
|
var generateTransformHandle = (x, y, width, height, cx, cy, angle) => {
|
|
18344
|
-
const [xx, yy] =
|
|
18345
|
-
|
|
18346
|
-
|
|
18669
|
+
const [xx, yy] = pointRotateRads14(
|
|
18670
|
+
pointFrom17(x + width / 2, y + height / 2),
|
|
18671
|
+
pointFrom17(cx, cy),
|
|
18347
18672
|
angle
|
|
18348
18673
|
);
|
|
18349
18674
|
return [xx - width / 2, yy - height / 2, width, height];
|
|
18350
18675
|
};
|
|
18351
|
-
var canResizeFromSides = (
|
|
18352
|
-
if (
|
|
18353
|
-
return false;
|
|
18354
|
-
}
|
|
18355
|
-
if (device.isTouchScreen && (isAndroid || isIOS)) {
|
|
18676
|
+
var canResizeFromSides = (editorInterface) => {
|
|
18677
|
+
if (editorInterface.formFactor === "phone" && editorInterface.userAgent.isMobileDevice) {
|
|
18356
18678
|
return false;
|
|
18357
18679
|
}
|
|
18358
18680
|
return true;
|
|
18359
18681
|
};
|
|
18360
|
-
var
|
|
18361
|
-
if (canResizeFromSides(
|
|
18682
|
+
var getOmitSidesForEditorInterface = (editorInterface) => {
|
|
18683
|
+
if (canResizeFromSides(editorInterface)) {
|
|
18362
18684
|
return DEFAULT_OMIT_SIDES;
|
|
18363
18685
|
}
|
|
18364
18686
|
return {};
|
|
@@ -18508,7 +18830,7 @@ var getTransformHandles = (element, zoom, elementsMap, pointerType = "mouse", om
|
|
|
18508
18830
|
isImageElement(element) ? 0 : void 0
|
|
18509
18831
|
);
|
|
18510
18832
|
};
|
|
18511
|
-
var
|
|
18833
|
+
var hasBoundingBox = (elements, appState, editorInterface) => {
|
|
18512
18834
|
if (appState.selectedLinearElement?.isEditing) {
|
|
18513
18835
|
return false;
|
|
18514
18836
|
}
|
|
@@ -18522,12 +18844,12 @@ var shouldShowBoundingBox = (elements, appState) => {
|
|
|
18522
18844
|
if (!isLinearElement(element)) {
|
|
18523
18845
|
return true;
|
|
18524
18846
|
}
|
|
18525
|
-
return element.points.length > 2;
|
|
18847
|
+
return element.points.length > 2 && !editorInterface.userAgent.isMobileDevice;
|
|
18526
18848
|
};
|
|
18527
18849
|
|
|
18528
18850
|
// src/resizeTest.ts
|
|
18529
18851
|
var isInsideTransformHandle = (transformHandle, x, y) => x >= transformHandle[0] && x <= transformHandle[0] + transformHandle[2] && y >= transformHandle[1] && y <= transformHandle[1] + transformHandle[3];
|
|
18530
|
-
var resizeTest = (element, elementsMap, appState, x, y, zoom, pointerType,
|
|
18852
|
+
var resizeTest = (element, elementsMap, appState, x, y, zoom, pointerType, editorInterface) => {
|
|
18531
18853
|
if (!appState.selectedElementIds[element.id]) {
|
|
18532
18854
|
return false;
|
|
18533
18855
|
}
|
|
@@ -18536,7 +18858,7 @@ var resizeTest = (element, elementsMap, appState, x, y, zoom, pointerType, devic
|
|
|
18536
18858
|
zoom,
|
|
18537
18859
|
elementsMap,
|
|
18538
18860
|
pointerType,
|
|
18539
|
-
|
|
18861
|
+
getOmitSidesForEditorInterface(editorInterface)
|
|
18540
18862
|
);
|
|
18541
18863
|
if (rotationTransformHandle && isInsideTransformHandle(rotationTransformHandle, x, y)) {
|
|
18542
18864
|
return "rotation";
|
|
@@ -18551,7 +18873,7 @@ var resizeTest = (element, elementsMap, appState, x, y, zoom, pointerType, devic
|
|
|
18551
18873
|
if (filter.length > 0) {
|
|
18552
18874
|
return filter[0];
|
|
18553
18875
|
}
|
|
18554
|
-
if (canResizeFromSides(
|
|
18876
|
+
if (canResizeFromSides(editorInterface)) {
|
|
18555
18877
|
const [x1, y1, x2, y2, cx, cy] = getElementAbsoluteCoords2(
|
|
18556
18878
|
element,
|
|
18557
18879
|
elementsMap
|
|
@@ -18560,14 +18882,14 @@ var resizeTest = (element, elementsMap, appState, x, y, zoom, pointerType, devic
|
|
|
18560
18882
|
const SPACING = isImageElement(element) ? 0 : SIDE_RESIZING_THRESHOLD / zoom.value;
|
|
18561
18883
|
const ZOOMED_SIDE_RESIZING_THRESHOLD = SIDE_RESIZING_THRESHOLD / zoom.value;
|
|
18562
18884
|
const sides = getSelectionBorders(
|
|
18563
|
-
|
|
18564
|
-
|
|
18565
|
-
|
|
18885
|
+
pointFrom18(x1 - SPACING, y1 - SPACING),
|
|
18886
|
+
pointFrom18(x2 + SPACING, y2 + SPACING),
|
|
18887
|
+
pointFrom18(cx, cy),
|
|
18566
18888
|
element.angle
|
|
18567
18889
|
);
|
|
18568
18890
|
for (const [dir, side] of Object.entries(sides)) {
|
|
18569
18891
|
if (pointOnLineSegment(
|
|
18570
|
-
|
|
18892
|
+
pointFrom18(x, y),
|
|
18571
18893
|
side,
|
|
18572
18894
|
ZOOMED_SIDE_RESIZING_THRESHOLD
|
|
18573
18895
|
)) {
|
|
@@ -18578,7 +18900,7 @@ var resizeTest = (element, elementsMap, appState, x, y, zoom, pointerType, devic
|
|
|
18578
18900
|
}
|
|
18579
18901
|
return false;
|
|
18580
18902
|
};
|
|
18581
|
-
var getElementWithTransformHandleType = (elements, appState, scenePointerX, scenePointerY, zoom, pointerType, elementsMap,
|
|
18903
|
+
var getElementWithTransformHandleType = (elements, appState, scenePointerX, scenePointerY, zoom, pointerType, elementsMap, editorInterface) => {
|
|
18582
18904
|
return elements.reduce((result, element) => {
|
|
18583
18905
|
if (result) {
|
|
18584
18906
|
return result;
|
|
@@ -18591,18 +18913,18 @@ var getElementWithTransformHandleType = (elements, appState, scenePointerX, scen
|
|
|
18591
18913
|
scenePointerY,
|
|
18592
18914
|
zoom,
|
|
18593
18915
|
pointerType,
|
|
18594
|
-
|
|
18916
|
+
editorInterface
|
|
18595
18917
|
);
|
|
18596
18918
|
return transformHandleType ? { element, transformHandleType } : null;
|
|
18597
18919
|
}, null);
|
|
18598
18920
|
};
|
|
18599
|
-
var getTransformHandleTypeFromCoords = ([x1, y1, x2, y2], scenePointerX, scenePointerY, zoom, pointerType,
|
|
18921
|
+
var getTransformHandleTypeFromCoords = ([x1, y1, x2, y2], scenePointerX, scenePointerY, zoom, pointerType, editorInterface) => {
|
|
18600
18922
|
const transformHandles = getTransformHandlesFromCoords(
|
|
18601
18923
|
[x1, y1, x2, y2, (x1 + x2) / 2, (y1 + y2) / 2],
|
|
18602
18924
|
0,
|
|
18603
18925
|
zoom,
|
|
18604
18926
|
pointerType,
|
|
18605
|
-
|
|
18927
|
+
getOmitSidesForEditorInterface(editorInterface)
|
|
18606
18928
|
);
|
|
18607
18929
|
const found = Object.keys(transformHandles).find((key) => {
|
|
18608
18930
|
const transformHandle = transformHandles[key];
|
|
@@ -18611,19 +18933,19 @@ var getTransformHandleTypeFromCoords = ([x1, y1, x2, y2], scenePointerX, scenePo
|
|
|
18611
18933
|
if (found) {
|
|
18612
18934
|
return found;
|
|
18613
18935
|
}
|
|
18614
|
-
if (canResizeFromSides(
|
|
18936
|
+
if (canResizeFromSides(editorInterface)) {
|
|
18615
18937
|
const cx = (x1 + x2) / 2;
|
|
18616
18938
|
const cy = (y1 + y2) / 2;
|
|
18617
18939
|
const SPACING = SIDE_RESIZING_THRESHOLD / zoom.value;
|
|
18618
18940
|
const sides = getSelectionBorders(
|
|
18619
|
-
|
|
18620
|
-
|
|
18621
|
-
|
|
18941
|
+
pointFrom18(x1 - SPACING, y1 - SPACING),
|
|
18942
|
+
pointFrom18(x2 + SPACING, y2 + SPACING),
|
|
18943
|
+
pointFrom18(cx, cy),
|
|
18622
18944
|
0
|
|
18623
18945
|
);
|
|
18624
18946
|
for (const [dir, side] of Object.entries(sides)) {
|
|
18625
18947
|
if (pointOnLineSegment(
|
|
18626
|
-
|
|
18948
|
+
pointFrom18(scenePointerX, scenePointerY),
|
|
18627
18949
|
side,
|
|
18628
18950
|
SPACING
|
|
18629
18951
|
)) {
|
|
@@ -18680,10 +19002,10 @@ var getCursorForResizingElement = (resizingElement) => {
|
|
|
18680
19002
|
return cursor ? `${cursor}-resize` : "";
|
|
18681
19003
|
};
|
|
18682
19004
|
var getSelectionBorders = ([x1, y1], [x2, y2], center, angle) => {
|
|
18683
|
-
const topLeft =
|
|
18684
|
-
const topRight =
|
|
18685
|
-
const bottomLeft =
|
|
18686
|
-
const bottomRight =
|
|
19005
|
+
const topLeft = pointRotateRads15(pointFrom18(x1, y1), center, angle);
|
|
19006
|
+
const topRight = pointRotateRads15(pointFrom18(x2, y1), center, angle);
|
|
19007
|
+
const bottomLeft = pointRotateRads15(pointFrom18(x1, y2), center, angle);
|
|
19008
|
+
const bottomRight = pointRotateRads15(pointFrom18(x2, y2), center, angle);
|
|
18687
19009
|
return {
|
|
18688
19010
|
n: [topLeft, topRight],
|
|
18689
19011
|
e: [topRight, bottomRight],
|
|
@@ -19224,6 +19546,8 @@ export {
|
|
|
19224
19546
|
getFrameLikeTitle,
|
|
19225
19547
|
getFreeDrawPath2D,
|
|
19226
19548
|
getFreeDrawSvgPath,
|
|
19549
|
+
getFreedrawOutlineAsSegments,
|
|
19550
|
+
getFreedrawOutlinePoints,
|
|
19227
19551
|
getGlobalFixedPointForBindableElement,
|
|
19228
19552
|
getGlobalFixedPoints,
|
|
19229
19553
|
getHeadingForElbowArrowSnap,
|
|
@@ -19245,7 +19569,7 @@ export {
|
|
|
19245
19569
|
getNonDeletedGroupIds,
|
|
19246
19570
|
getNormalizedDimensions,
|
|
19247
19571
|
getObservedAppState,
|
|
19248
|
-
|
|
19572
|
+
getOmitSidesForEditorInterface,
|
|
19249
19573
|
getOriginalContainerHeightFromCache,
|
|
19250
19574
|
getPerfectElementSize,
|
|
19251
19575
|
getPredecessors,
|
|
@@ -19283,6 +19607,7 @@ export {
|
|
|
19283
19607
|
handleBindTextResize,
|
|
19284
19608
|
hasBackground,
|
|
19285
19609
|
hasBoundTextElement,
|
|
19610
|
+
hasBoundingBox,
|
|
19286
19611
|
hasStrokeColor,
|
|
19287
19612
|
hasStrokeStyle,
|
|
19288
19613
|
hasStrokeWidth,
|
|
@@ -19389,6 +19714,7 @@ export {
|
|
|
19389
19714
|
parseTokens,
|
|
19390
19715
|
pathsCache,
|
|
19391
19716
|
pointInsideBounds,
|
|
19717
|
+
positionElementsOnGrid,
|
|
19392
19718
|
redrawTextBoundingBox,
|
|
19393
19719
|
refreshTextDimensions,
|
|
19394
19720
|
removeAllElementsFromFrame,
|
|
@@ -19410,7 +19736,6 @@ export {
|
|
|
19410
19736
|
shouldAllowVerticalAlign,
|
|
19411
19737
|
shouldApplyFrameClip,
|
|
19412
19738
|
shouldEnableBindingForPointerEvent,
|
|
19413
|
-
shouldShowBoundingBox,
|
|
19414
19739
|
shouldTestInside,
|
|
19415
19740
|
showSelectedShapeActions,
|
|
19416
19741
|
snapToMid,
|