mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
remove closures from mutateElement, get rid of the element spreading (#902)
This commit is contained in:
parent
13b838117c
commit
83a2f5de28
10 changed files with 218 additions and 196 deletions
|
@ -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,
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue