2020-01-06 19:34:22 +04:00
|
|
|
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>;
|
|
|
|
|
2020-01-06 19:34:22 +04:00
|
|
|
export function resizeTest(
|
|
|
|
element: ExcalidrawElement,
|
|
|
|
x: number,
|
|
|
|
y: number,
|
|
|
|
sceneState: SceneState
|
2020-01-08 16:55:13 +01:00
|
|
|
): HandlerRectanglesRet | false {
|
2020-01-06 19:34:22 +04:00
|
|
|
if (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]!;
|
2020-01-06 19:34:22 +04:00
|
|
|
|
|
|
|
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;
|
2020-01-06 19:34:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|