mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
Extract scene functions to their respective modules (#208)
- Also, extract utilities into utils module -- capitalizeString, getDateTime, isInputLike
This commit is contained in:
parent
01805f734d
commit
86a1c29eec
12 changed files with 695 additions and 530 deletions
38
src/scene/comparisons.ts
Normal file
38
src/scene/comparisons.ts
Normal file
|
@ -0,0 +1,38 @@
|
|||
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;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue