remove closures from mutateElement, get rid of the element spreading (#902)
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
import { ExcalidrawElement, MutableExcalidrawElement } from "./types";
|
||||
import { ExcalidrawElement } from "./types";
|
||||
import { invalidateShapeForElement } from "../renderer/renderElement";
|
||||
import { mutateElement } from "./mutateElement";
|
||||
|
||||
@ -36,7 +36,7 @@ export function getPerfectElementSize(
|
||||
}
|
||||
|
||||
export function resizePerfectLineForNWHandler(
|
||||
element: MutableExcalidrawElement,
|
||||
element: ExcalidrawElement,
|
||||
x: number,
|
||||
y: number,
|
||||
) {
|
||||
@ -45,21 +45,28 @@ export function resizePerfectLineForNWHandler(
|
||||
const distanceToAnchorX = x - anchorX;
|
||||
const distanceToAnchorY = y - anchorY;
|
||||
if (Math.abs(distanceToAnchorX) < Math.abs(distanceToAnchorY) / 2) {
|
||||
element.x = anchorX;
|
||||
element.width = 0;
|
||||
element.y = y;
|
||||
element.height = -distanceToAnchorY;
|
||||
mutateElement(element, {
|
||||
x: anchorX,
|
||||
width: 0,
|
||||
y,
|
||||
height: -distanceToAnchorY,
|
||||
});
|
||||
} else if (Math.abs(distanceToAnchorY) < Math.abs(element.width) / 2) {
|
||||
element.y = anchorY;
|
||||
element.height = 0;
|
||||
mutateElement(element, {
|
||||
y: anchorY,
|
||||
height: 0,
|
||||
});
|
||||
} else {
|
||||
element.x = x;
|
||||
element.width = -distanceToAnchorX;
|
||||
element.height =
|
||||
const nextHeight =
|
||||
Math.sign(distanceToAnchorY) *
|
||||
Math.sign(distanceToAnchorX) *
|
||||
element.width;
|
||||
element.y = anchorY - element.height;
|
||||
mutateElement(element, {
|
||||
x,
|
||||
y: anchorY - nextHeight,
|
||||
width: -distanceToAnchorX,
|
||||
height: nextHeight,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -79,16 +86,18 @@ export function normalizeDimensions(
|
||||
}
|
||||
|
||||
if (element.width < 0) {
|
||||
mutateElement(element, element => {
|
||||
element.width = Math.abs(element.width);
|
||||
element.x -= element.width;
|
||||
const nextWidth = Math.abs(element.width);
|
||||
mutateElement(element, {
|
||||
width: nextWidth,
|
||||
x: element.x - nextWidth,
|
||||
});
|
||||
}
|
||||
|
||||
if (element.height < 0) {
|
||||
mutateElement(element, element => {
|
||||
element.height = Math.abs(element.height);
|
||||
element.y -= element.height;
|
||||
const nextHeight = Math.abs(element.height);
|
||||
mutateElement(element, {
|
||||
height: nextHeight,
|
||||
y: element.y - nextHeight,
|
||||
});
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user