@core-graphics/rect
Version:
JS utilities for managing rects
75 lines (74 loc) • 2.96 kB
TypeScript
import { Point, PointValue } from "@core-graphics/point";
import { AlignOptions, HAlign, VAlign } from "./align";
import { ElementRectOptions, WindowRectOptions } from "./create";
import { collisions, intersection, intersects } from "./intersection";
import { Rect as RectLite, RectValue } from "./lite";
import { RectInset, SymmetricRectInset } from "./operations";
import { union } from "./union";
/**
* A structure that contains the location and dimensions of a rectangle.
*/
export declare class Rect extends RectLite {
/**
* Creates a rectangle from a set of points
*/
static fromPoints: (...points: PointValue[]) => Rect;
/**
* Creates a Rect from specified point and size as arguments
*/
static create: (rect: RectValue) => Rect;
/**
* Creates a rectangle from an HTML element
*/
static fromElement: (el: HTMLElement, opts?: ElementRectOptions) => Rect;
/**
* Creates a rectange from window object
*/
static fromWindow: (win: Window, opts?: WindowRectOptions) => Rect;
/**
* Creates a Rect from a DOM range. To learn more about ranges (text selection)
* @see MDN https://developer.mozilla.org/en-US/docs/Web/API/Range
* @see QuirksMode https://www.quirksmode.org/dom/range_intro.html
*/
static fromRange: (range: Range) => Rect;
/**
* Returns the shrinked or expanded version of the rectangle
* based on the inset values specified.
*/
egdeInset: (inset: RectInset) => this;
/**
* Returns a symmetrically contracted/expanded Rect based on
* the specified amount.
*/
inset: (value: SymmetricRectInset) => this;
/**
* Returns a new Rect with its origin shifted by the specified offset
*/
shift: (offset: Partial<PointValue>) => this;
containsPoint: (point: PointValue) => boolean;
containsRect: (rectOrValue: RectValue | Rect) => boolean;
/**
* Returns whether a Point or Rect is within this Rect
*/
contains: (pointOrRect: RectValue | PointValue) => boolean;
intersection: (rect: Rect) => this;
intersects: (rect: Rect) => boolean;
distanceFromPoint: (point: Point | PointValue) => import("./distance").DistanceValue;
distanceFromRect: (rectOrValue: Rect | RectValue) => import("./distance").DistanceValue;
/**
* Align this rect to a reference rect horizontally
*/
horizontalAlignTo: (rect: Rect, align: HAlign) => this;
/**
* Align this rect to a reference rect vertically
*/
verticalAlignTo: (rect: Rect, align: VAlign) => this;
/**
* Align this rect to a reference rect based on the specifed placement
*/
alignTo: (rect: Rect, opts: AlignOptions) => this;
static intersection: typeof intersection;
static collisions: typeof collisions;
static union: typeof union;
static intersects: typeof intersects;
}