mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
Prefer arrow functions and callbacks (#1210)
This commit is contained in:
parent
33fe223b5d
commit
c427aa3cce
64 changed files with 784 additions and 847 deletions
|
@ -3,21 +3,23 @@ import { mutateElement } from "./mutateElement";
|
|||
import { isLinearElement } from "./typeChecks";
|
||||
import { SHIFT_LOCKING_ANGLE } from "../constants";
|
||||
|
||||
export function isInvisiblySmallElement(element: ExcalidrawElement): boolean {
|
||||
export const isInvisiblySmallElement = (
|
||||
element: ExcalidrawElement,
|
||||
): boolean => {
|
||||
if (isLinearElement(element)) {
|
||||
return element.points.length < 2;
|
||||
}
|
||||
return element.width === 0 && element.height === 0;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Makes a perfect shape or diagonal/horizontal/vertical line
|
||||
*/
|
||||
export function getPerfectElementSize(
|
||||
export const getPerfectElementSize = (
|
||||
elementType: string,
|
||||
width: number,
|
||||
height: number,
|
||||
): { width: number; height: number } {
|
||||
): { width: number; height: number } => {
|
||||
const absWidth = Math.abs(width);
|
||||
const absHeight = Math.abs(height);
|
||||
|
||||
|
@ -42,13 +44,13 @@ export function getPerfectElementSize(
|
|||
height = absWidth * Math.sign(height);
|
||||
}
|
||||
return { width, height };
|
||||
}
|
||||
};
|
||||
|
||||
export function resizePerfectLineForNWHandler(
|
||||
export const resizePerfectLineForNWHandler = (
|
||||
element: ExcalidrawElement,
|
||||
x: number,
|
||||
y: number,
|
||||
) {
|
||||
) => {
|
||||
const anchorX = element.x + element.width;
|
||||
const anchorY = element.y + element.height;
|
||||
const distanceToAnchorX = x - anchorX;
|
||||
|
@ -77,14 +79,14 @@ export function resizePerfectLineForNWHandler(
|
|||
height: nextHeight,
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @returns {boolean} whether element was normalized
|
||||
*/
|
||||
export function normalizeDimensions(
|
||||
export const normalizeDimensions = (
|
||||
element: ExcalidrawElement | null,
|
||||
): element is ExcalidrawElement {
|
||||
): element is ExcalidrawElement => {
|
||||
if (!element || (element.width >= 0 && element.height >= 0)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -106,4 +108,4 @@ export function normalizeDimensions(
|
|||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue