refactor: add elementCenterPoint util

This commit is contained in:
jhanma17dev 2025-03-24 16:13:45 +00:00 committed by Mark Tolmacs
parent 6fc85022ae
commit 6290d76927

View file

@ -4,6 +4,7 @@ import type {
ExcalidrawBindableElement,
FontFamilyValues,
FontString,
ExcalidrawElement,
} from "@excalidraw/element/types";
import type {
@ -1201,3 +1202,13 @@ export const escapeDoubleQuotes = (str: string) => {
export const castArray = <T>(value: T | T[]): T[] =>
Array.isArray(value) ? value : [value];
export const elementCenterPoint = (element: ExcalidrawElement) => {
const { x, y, width, height } = element;
const centerXPoint = x + width / 2;
const centerYPoint = y + height / 2;
return { x: centerXPoint, y: centerYPoint };
};