/** * A direction relative to a rectangle. * * Represents one of the four cardinal directions from the perspective of the element. * * @typedef {'top' | 'bottom' | 'left' | 'right'} Dirs */ export type Dirs = 'top' | 'bottom' | 'left' | 'right'; export type CollDirs = { /** * - The dominant direction of entry. `'center'` if all sides are equally overlapped. `null` if no collision. */ in: Dirs | 'center' | null; /** * - The horizontal direction (`'left'` or `'right'`) the collision is biased toward, or `null`. */ x: Dirs | null; /** * - The vertical direction (`'top'` or `'bottom'`) the collision is biased toward, or `null`. */ y: Dirs | null; }; export type NegCollDirs = { /** * - Horizontal direction of negative overlap, if any. */ x: Dirs | null; /** * - Vertical direction of negative overlap, if any. */ y: Dirs | null; }; export type CollData = { /** * - Depth from rect2's top into rect1. */ top: number; /** * - Depth from rect2's bottom into rect1. */ bottom: number; /** * - Depth from rect2's left into rect1. */ left: number; /** * - Depth from rect2's right into rect1. */ right: number; }; export type CollCenter = { /** * - Horizontal distance in pixels from rect1's center to rect2's center. */ x: number; /** * - Vertical distance in pixels from rect1's center to rect2's center. */ y: number; }; export type ObjRect = { /** * - The total height of the rectangle in pixels. */ height: number; /** * - The total width of the rectangle in pixels. */ width: number; /** * - The Y-coordinate of the top edge of the rectangle. */ top: number; /** * - The Y-coordinate of the bottom edge of the rectangle. */ bottom: number; /** * - The X-coordinate of the left edge of the rectangle. */ left: number; /** * - The X-coordinate of the right edge of the rectangle. */ right: number; }; /** * Represents all directional aspects of a collision. * * @typedef {Object} CollDirs * @property {Dirs | 'center' | null} in - The dominant direction of entry. `'center'` if all sides are equally overlapped. `null` if no collision. * @property {Dirs | null} x - The horizontal direction (`'left'` or `'right'`) the collision is biased toward, or `null`. * @property {Dirs | null} y - The vertical direction (`'top'` or `'bottom'`) the collision is biased toward, or `null`. */ /** * Indicates if a collision is in the negative direction (rect2 is outside rect1). * * @typedef {Object} NegCollDirs * @property {Dirs | null} x - Horizontal direction of negative overlap, if any. * @property {Dirs | null} y - Vertical direction of negative overlap, if any. */ /** * Collision depth values from each side of rect2 inside rect1. * * Positive values indicate penetration; negative values indicate gaps. * * @typedef {Object} CollData * @property {number} top - Depth from rect2's top into rect1. * @property {number} bottom - Depth from rect2's bottom into rect1. * @property {number} left - Depth from rect2's left into rect1. * @property {number} right - Depth from rect2's right into rect1. */ /** * X and Y offset representing center difference between two rectangles. * * Useful to measure how far one element's center is from another. * * @typedef {Object} CollCenter * @property {number} x - Horizontal distance in pixels from rect1's center to rect2's center. * @property {number} y - Vertical distance in pixels from rect1's center to rect2's center. */ /** * Represents a rectangular area in absolute pixel values. * * Similar to `DOMRect`, this object describes the dimensions and position of a box * in the 2D plane, typically representing an element's bounding box. * * @typedef {Object} ObjRect * @property {number} height - The total height of the rectangle in pixels. * @property {number} width - The total width of the rectangle in pixels. * @property {number} top - The Y-coordinate of the top edge of the rectangle. * @property {number} bottom - The Y-coordinate of the bottom edge of the rectangle. * @property {number} left - The X-coordinate of the left edge of the rectangle. * @property {number} right - The X-coordinate of the right edge of the rectangle. */ /** * Checks if rect1 is completely above rect2 (no vertical overlap). * * @param {ObjRect} rect1 - The bounding rectangle of the first element. * @param {ObjRect} rect2 - The bounding rectangle of the second element. * @returns {boolean} True if rect1 is entirely above rect2. */ export declare const areElsCollTop: (rect1: ObjRect, rect2: ObjRect) => boolean; /** * Checks if rect1 is completely below rect2 (no vertical overlap). * * @param {ObjRect} rect1 * @param {ObjRect} rect2 * @returns {boolean} True if rect1 is entirely below rect2. */ export declare const areElsCollBottom: (rect1: ObjRect, rect2: ObjRect) => boolean; /** * Checks if rect1 is completely to the left of rect2 (no horizontal overlap). * * @param {ObjRect} rect1 * @param {ObjRect} rect2 * @returns {boolean} True if rect1 is entirely to the left of rect2. */ export declare const areElsCollLeft: (rect1: ObjRect, rect2: ObjRect) => boolean; /** * Checks if rect1 is completely to the right of rect2 (no horizontal overlap). * * @param {ObjRect} rect1 * @param {ObjRect} rect2 * @returns {boolean} True if rect1 is entirely to the right of rect2. */ export declare const areElsCollRight: (rect1: ObjRect, rect2: ObjRect) => boolean; /** * Checks if rect1 is perfectly above rect2 (no vertical touch or overlap). * * @param {ObjRect} rect1 * @param {ObjRect} rect2 * @returns {boolean} True if rect1 is fully above or touching rect2's top. */ export declare const areElsCollPerfTop: (rect1: ObjRect, rect2: ObjRect) => boolean; /** * Checks if rect1 is perfectly below rect2 (no vertical touch or overlap). * * @param {ObjRect} rect1 * @param {ObjRect} rect2 * @returns {boolean} True if rect1 is fully below or touching rect2's bottom. */ export declare const areElsCollPerfBottom: (rect1: ObjRect, rect2: ObjRect) => boolean; /** * Checks if rect1 is perfectly to the left of rect2 (no horizontal touch or overlap). * * @param {ObjRect} rect1 * @param {ObjRect} rect2 * @returns {boolean} True if rect1 is fully left or touching rect2's left. */ export declare const areElsCollPerfLeft: (rect1: ObjRect, rect2: ObjRect) => boolean; /** * Checks if rect1 is perfectly to the right of rect2 (no horizontal touch or overlap). * * @param {ObjRect} rect1 * @param {ObjRect} rect2 * @returns {boolean} True if rect1 is fully right or touching rect2's right. */ export declare const areElsCollPerfRight: (rect1: ObjRect, rect2: ObjRect) => boolean; /** * Returns true if rect1 and rect2 are colliding (partially or fully overlapping). * * @param {ObjRect} rect1 * @param {ObjRect} rect2 * @returns {boolean} True if there's any collision between rect1 and rect2. */ export declare const areElsColliding: (rect1: ObjRect, rect2: ObjRect) => boolean; /** * Returns true if rect1 and rect2 are colliding or perfectly touching. * * @param {ObjRect} rect1 * @param {ObjRect} rect2 * @returns {boolean} True if there's any contact or overlap. */ export declare const areElsPerfColliding: (rect1: ObjRect, rect2: ObjRect) => boolean; /** * Attempts to determine the direction rect1 entered rect2 based on loose overlap rules. * * @param {ObjRect} rect1 * @param {ObjRect} rect2 * @returns {string|null} 'top' | 'bottom' | 'left' | 'right' | null */ export declare const getElsColliding: (rect1: ObjRect, rect2: ObjRect) => string | null; /** * Attempts to determine the direction rect1 touched or entered rect2 using perfect mode. * * @param {ObjRect} rect1 * @param {ObjRect} rect2 * @returns {'top' | 'bottom' | 'left' | 'right' | null} */ export declare const getElsPerfColliding: (rect1: ObjRect, rect2: ObjRect) => 'top' | 'bottom' | 'left' | 'right' | null; /** * Calculates overlap values between rect1 and rect2 in all directions. * * @param {ObjRect} rect1 * @param {ObjRect} rect2 * @returns {{ * overlapLeft: number, * overlapRight: number, * overlapTop: number, * overlapBottom: number * }} Distance of overlap from each direction (can be negative). */ export declare const getElsCollOverlap: (rect1: ObjRect, rect2: ObjRect) => { overlapLeft: number; overlapRight: number; overlapTop: number; overlapBottom: number; }; /** * Determines directional collision based on overlap depth. * * @param {Object} [settings={}] * @param {number} [settings.overlapLeft] * @param {number} [settings.overlapRight] * @param {number} [settings.overlapTop] * @param {number} [settings.overlapBottom] * @returns {{ dirX: Dirs, dirY: Dirs }} Direction of strongest X/Y overlap. */ export declare const getElsCollOverlapPos: ({ overlapLeft, overlapRight, overlapTop, overlapBottom, }?: { overlapLeft?: number; overlapRight?: number; overlapTop?: number; overlapBottom?: number; }) => { dirX: Dirs; dirY: Dirs; }; /** * Calculates the center point (X and Y) of a given Rect. * * @param {ObjRect} rect - The bounding rectangle of the element. * @returns {{ x: number, y: number }} An object with the `x` and `y` coordinates of the center. */ export declare const getRectCenter: (rect: ObjRect) => { x: number; y: number; }; /** * Calculates the offset between the center of rect2 and the center of rect1. * * The values will be 0 when rect1 is perfectly centered over rect2. * * @param {ObjRect} rect1 - The bounding rectangle of the reference element. * @param {ObjRect} rect2 - The bounding rectangle of the element being compared. * @returns {{ * x: number, * y: number * }} An object with the X and Y offset in pixels from rect1's center to rect2's center. */ export declare function getElsRelativeCenterOffset(rect1: ObjRect, rect2: ObjRect): { x: number; y: number; }; /** * Detects the direction of the dominant collision between two elements * and calculates how deep the overlap is in both x and y axes. * * @param {ObjRect} rect1 - The bounding rectangle of the first element. * @param {ObjRect} rect2 - The bounding rectangle of the second element. * @returns {{ * inDir: Dirs | null; * dirX: Dirs | null; * dirY: Dirs | null; * depthX: number; * depthY: number; * }} An object containing the collision direction and how deep the overlap is. */ export declare function getElsCollDirDepth(rect1: ObjRect, rect2: ObjRect): { inDir: Dirs | null; dirX: Dirs | null; dirY: Dirs | null; depthX: number; depthY: number; }; /** * Detects the collision direction and depth between two DOMRects. * * @param {ObjRect} rect1 - The bounding rectangle of the first element. * @param {ObjRect} rect2 - The bounding rectangle of the second element. * @returns {{ depth: CollData; dirs: CollDirs; isNeg: NegCollDirs; }} Collision info or null if no collision is detected. */ export declare function getElsCollDetails(rect1: ObjRect, rect2: ObjRect): { depth: CollData; dirs: CollDirs; isNeg: NegCollDirs; }; //# sourceMappingURL=collision.d.mts.map