excalidraw/src/scene/comparisons.ts
Gasim Gasimzada 86a1c29eec
Extract scene functions to their respective modules (#208)
- Also, extract utilities into utils module -- capitalizeString, getDateTime, isInputLike
2020-01-06 20:24:54 +04:00

39 lines
1008 B
TypeScript

import { ExcalidrawElement } from "../element/types";
import { hitTest } from "../element/collision";
export const hasBackground = (elements: ExcalidrawElement[]) =>
elements.some(
element =>
element.isSelected &&
(element.type === "rectangle" ||
element.type === "ellipse" ||
element.type === "diamond")
);
export const hasStroke = (elements: ExcalidrawElement[]) =>
elements.some(
element =>
element.isSelected &&
(element.type === "rectangle" ||
element.type === "ellipse" ||
element.type === "diamond" ||
element.type === "arrow")
);
export function getElementAtPosition(
elements: ExcalidrawElement[],
x: number,
y: number
) {
let hitElement = null;
// We need to to hit testing from front (end of the array) to back (beginning of the array)
for (let i = elements.length - 1; i >= 0; --i) {
if (hitTest(elements[i], x, y)) {
hitElement = elements[i];
break;
}
}
return hitElement;
}