UNPKG

@exadel/esl

Version:

Exadel Smart Library (ESL) is the lightweight custom elements library that provide a set of super-flexible components

95 lines (94 loc) 4.12 kB
import type { Point } from './point'; /** * A Rect describes the size and position of a rectangle. */ export declare class Rect implements Point { /** The X coordinate of the Rect's origin (top-left corner of the rectangle). */ readonly x: number; /** The Y coordinate of the Rect's origin (top-left corner of the rectangle). */ readonly y: number; /** The width of the Rect. */ readonly width: number; /** The height of the Rect. */ readonly height: number; /** * The static method creates a new Rect instance from a DOMRect object of BoundingClientRect. * @param el - DOM Element */ static from(el: Element): Rect; /** * The static method creates a new Rect instance from a rect-like object. * @param rect - rect-like object */ static from(rect: { x?: number; left?: number; y?: number; top?: number; width?: number; height?: number; }): Rect; /** * The static method checks the equality of the two Rect instances. * @param rect1 - first instance of Rect * @param rect2 - second instance of Rect */ static isEqual(rect1: Rect, rect2: Rect): boolean; /** * The static method returns intersection Rect of two Rect instances * @param rect1 - first instance of Rect * @param rect2 - second instance of Rect */ static intersect(rect1: Rect, rect2: Rect): Rect; constructor(x?: number, y?: number, width?: number, height?: number); /** @returns the top coordinate value of the Rect (has the same value as y) */ get top(): number; /** @returns the left coordinate value of the Rect (has the same value as x) */ get left(): number; /** @returns the right coordinate value of the DOMRect */ get right(): number; /** @returns the bottom coordinate value of the Rect */ get bottom(): number; /** @returns the center X coordinate value of the Rect */ get cx(): number; /** @returns the center Y coordinate value of the Rect */ get cy(): number; /** @returns the numeric value of rectangle area */ get area(): number; /** * Method that accepts one argument and grows the Rect by the specified increment in pixels. * It increases the size of the Rect by moving each point on the edge of the Rect to a certain distance further away from the center of the Rect. * @returns new {@link Rect} * @param increment - distance to grow in pixels for both X and Y-axis */ grow(increment: number): Rect; /** * Method that accepts two arguments where each specified increment grows the rect in different axis in pixels. * @returns new {@link Rect} * @param incrementX - distance to grow in pixels for X-axis * @param incrementY - distance to grow in pixels for Y-axis */ grow(incrementX: number, incrementY: number): Rect; /** * Method that accepts one argument and shrinks the Rect by the specified decrement in pixels. * It reduces the size of the Rect by moving each point on the edge of the Rect to a certain distance closer to the center of the Rect. * @returns new {@link Rect} * @param decrement - distance to shrink in pixels for both X and Y-axis */ shrink(decrement: number): Rect; /** * Method that accepts two arguments where each specified decrement shrinks the rect in different axis in pixels. * @returns new {@link Rect} * @param decrementX - distance to shrink in pixels for X-axis * @param decrementY - distance to shrink in pixels for Y-axis */ shrink(decrementX: number, decrementY: number): Rect; /** @returns new {@link Rect} that is shifted by x and y axis */ shift(x?: number, y?: number): Rect; /** @returns new {@link Rect} that is resized by x and y axis */ resize(xDelta?: number, yDelta?: number): Rect; /** @returns new {@link Rect} an intersection of current and passed Rectangle */ intersect(rect: Rect): Rect; /** @returns if the passed rect is equal to current */ isEqual(rect: Rect): boolean; }