import {Inset} from "../../core/generated/zenid-types.generated.js"; /** * Returns the intersection of two DOMRect objects. * If there is no intersection, returns null. * * @param a - The first DOMRect * @param b - The second DOMRect * @returns The intersection DOMRect or null if there is no intersection */ export function getViewportIntersection(a: DOMRect, b: DOMRect): DOMRect | null { const left = Math.max(a.left, b.left); const top = Math.max(a.top, b.top); const right = Math.min(a.right, b.right); const bottom = Math.min(a.bottom, b.bottom); const width = right - left; const height = bottom - top; if (width <= 0 || height <= 0) return null; return new DOMRect(left, top, width, height); } /** * Calculates the relative position of rect1 with respect to rect2. * * @param rect1 - The first DOMRect * @param rect2 - The second DOMRect * @returns An Inset object representing the relative position */ export function getRelativePosition(rect1: DOMRect, rect2: DOMRect): Inset { return { Top: rect1.top - rect2.top, Bottom: rect2.bottom - rect1.bottom, Left: rect1.left - rect2.left, Right: rect2.right - rect1.right }; }