excalidraw/src/element/resizeTest.ts

35 lines
940 B
TypeScript
Raw Normal View History

import { ExcalidrawElement } from "./types";
import { SceneState } from "../scene/types";
import { handlerRectangles } from "./handlerRectangles";
2020-01-08 16:55:13 +01:00
type HandlerRectanglesRet = keyof ReturnType<typeof handlerRectangles>;
export function resizeTest(
element: ExcalidrawElement,
x: number,
y: number,
sceneState: SceneState
2020-01-08 16:55:13 +01:00
): HandlerRectanglesRet | false {
if (!element.isSelected || element.type === "text") return false;
const handlers = handlerRectangles(element, sceneState);
const filter = Object.keys(handlers).filter(key => {
2020-01-08 16:55:13 +01:00
const handler = handlers[key as HandlerRectanglesRet]!;
return (
x + sceneState.scrollX >= handler[0] &&
x + sceneState.scrollX <= handler[0] + handler[2] &&
y + sceneState.scrollY >= handler[1] &&
y + sceneState.scrollY <= handler[1] + handler[3]
);
});
if (filter.length > 0) {
2020-01-08 16:55:13 +01:00
return filter[0] as HandlerRectanglesRet;
}
return false;
}