securityos/components/system/Files/FileManager/Selection/functions.ts

20 lines
726 B
TypeScript
Raw Permalink Normal View History

2024-09-06 15:32:35 +00:00
import type { SelectionRect } from "components/system/Files/FileManager/Selection/useSelection";
export const isSelectionIntersecting = (
element: DOMRect,
containerElement: DOMRect,
selection: SelectionRect,
containerScrollTop: number
): boolean => {
const { x = 0, y = 0, width = 0, height = 0 } = selection;
const selectionRect = new DOMRect(x, y, Number(width), Number(height));
return !(
element.left - containerElement.left >= selectionRect.right ||
element.top - containerElement.top >= selectionRect.bottom ||
element.right - containerElement.left <= selectionRect.left ||
element.bottom - containerElement.top + containerScrollTop <=
selectionRect.top
);
};