export type GridRangeIndex = number | null; export type RequiredGridRangeIndex = number; type LeftIndex = GridRangeIndex; type RightIndex = GridRangeIndex; type TopIndex = GridRangeIndex; type BottomIndex = GridRangeIndex; export type GridCell = { column: RequiredGridRangeIndex; row: RequiredGridRangeIndex; }; export interface BoundedGridRange extends GridRange { startColumn: RequiredGridRangeIndex; startRow: RequiredGridRangeIndex; endColumn: RequiredGridRangeIndex; endRow: RequiredGridRangeIndex; } export declare enum SELECTION_DIRECTION { DOWN = "DOWN", UP = "UP", LEFT = "LEFT", RIGHT = "RIGHT" } export declare class GridRange { startColumn: GridRangeIndex; startRow: GridRangeIndex; endColumn: GridRangeIndex; endRow: GridRangeIndex; static SELECTION_DIRECTION: typeof SELECTION_DIRECTION; /** * Returns a normalized array of indexes ensuring left <= right and top <= bottom * @param startColumn Start column index * @param startRow Start row index * @param endColumn End column index * @param endRow End row index * @returns Array containing normalized indexes [left, top, right, bottom] */ static normalize(startColumn: GridRangeIndex, startRow: GridRangeIndex, endColumn: GridRangeIndex, endRow: GridRangeIndex): [LeftIndex, TopIndex, RightIndex, BottomIndex]; /** * Makes a GridRange ensuring startColumn <= endColumn, startRow <= endRow * @param startColumn Start column index * @param startRow Start row index * @param endColumn End column index * @param endRow End row index * @returns Normalized GridRange */ static makeNormalized(startColumn: GridRangeIndex, startRow: GridRangeIndex, endColumn: GridRangeIndex, endRow: GridRangeIndex): GridRange; /** * Creates a GridRange representing a single cell * @param column Column index * @param row Row index * @returns GridRange representing the cell */ static makeCell(column: GridRangeIndex, row: GridRangeIndex): GridRange; /** * Creates a GridRange representing an infinite length column * @param column Column index * @returns GridRange representing the column */ static makeColumn(column: GridRangeIndex): GridRange; /** * Creates a GridRange representing an infinite length row * @param row Row index * @returns GridRange representing the row */ static makeRow(row: GridRangeIndex): GridRange; /** * Returns the minimum value between 2 range indexes or null if at least 1 is null * @param index1 First grid range index * @param index2 Second grid range index * @returns Minimum index or null if either index is null */ static minOrNull(index1: GridRangeIndex, index2: GridRangeIndex): number | null; /** * Returns the maximum value between 2 range indexes or null if at least 1 is null * @param index1 First grid range index * @param index2 Second grid range index * @returns Maximum index or null if either index is null */ static maxOrNull(index1: GridRangeIndex, index2: GridRangeIndex): number | null; /** * Consolidate the passed in ranges to the minimum set, merging overlapping ranges. * @param ranges The ranges to consolidate * @returns Consolidated ranges */ static consolidate(ranges: readonly GridRange[]): GridRange[]; /** * Checks if the 1-D ranges between 2 index pairs overlap or are continuous. * For example ranges [0, 1] and [2, 3] are continuous and will return true. * [0, 1] and [1, 3] overlap and return true. * [0, 1] and [3, 4] do not overlap and have a gap so this will return false. * @param start1 Start of 1st range * @param end1 End of 1st range * @param start2 Start of 2nd range * @param end2 End of 2nd range * @returns True if the ranges overlap or touch, else false */ static isAxisRangeTouching(start1: GridRangeIndex, end1: GridRangeIndex, start2: GridRangeIndex, end2: GridRangeIndex): boolean; /** * Checks if 2 arrays of ranges are the same ranges * @param ranges1 First array of ranges * @param ranges2 Second array of ranges * @returns True if the arrays contain the same ranges in the same order */ static rangeArraysEqual(ranges1: readonly GridRange[], ranges2: readonly GridRange[]): boolean; /** * Get the intersection (overlapping area) of two ranges * @param range One range to check for the intersection * @param otherRange The other range to check for the intersection * @returns Intersection of the two ranges. If they do not intersect, returns `null`. */ static intersection(range: GridRange, otherRange: GridRange): GridRange | null; /** * Subtracts 1 range from another * @param range The range to be subtracted from * @param subtractRange The range to subtract from within this range * @returns The ranges needed to represent the remaining */ static subtractFromRange(range: GridRange, subtractRange: GridRange): GridRange[]; /** * Subtract a range from multiple ranges * @param ranges The ranges to be subtracted from * @param subtractRange The range to subtract from within these ranges * @returns The ranges needed to represent the remaining */ static subtractFromRanges(ranges: readonly GridRange[], subtractRange: GridRange): GridRange[]; /** * Subtract multiple ranges from multiple ranges * @param ranges The ranges to be subtracted from * @param subtractRanges The ranges to subtract from within these ranges * @returns The ranges needed to represent the remaining */ static subtractRangesFromRanges(ranges: readonly GridRange[], subtractRanges: readonly GridRange[]): GridRange[]; /** * Test if a given range is bounded (all values are non-null) * @param range The range to test * @returns True if this range is bounded, false otherwise */ static isBounded(range: GridRange): range is BoundedGridRange; /** * Converts any GridRange passed in that is a full row or column selection to be bound * to the `columnCount` and `rowCount` passed in * * @param range The range to get the bounded range of * @param columnCount The number of columns * @param rowCount The number of rows * @returns The passed in GridRange with any null values filled in */ static boundedRange(range: GridRange, columnCount: number, rowCount: number): BoundedGridRange; /** * Converts the GridRanges passed in to be bound to the `columnCount` and `rowCount` passed in * * @param ranges The ranges to get the bounded ranges of * @param columnCount The number of columns * @param rowCount The number of rows * @returns The passed in GridRange with any null values filled in */ static boundedRanges(ranges: readonly GridRange[], columnCount: number, rowCount: number): BoundedGridRange[]; /** * Offsets a GridRange by the specified amount in the x and y directions * * @param range The range to offset * @param columnOffset The number of columns to offset * @param rowOffset The number of rows to offset * @returns The new grid range offset from the original */ static offset(range: GridRange, columnOffset: number, rowOffset: number): GridRange; /** * Get the next cell given the selected ranges and the current cell * @param ranges The selected bounded ranges within the grid * @param column The cursor column, or null if none focused * @param row The cursor row, or null if none focused * @param direction The direction in which to select next * @returns The next cell to focus, or null if there should be no more focus */ static nextCell(ranges: readonly GridRange[], column?: GridRangeIndex, row?: GridRangeIndex, direction?: SELECTION_DIRECTION): GridCell | null; /** * Count the number of cells in the provided grid ranges * @param ranges The ranges to count the rows of * @returns The number of cells in the ranges, or `NaN` if any of the ranges were unbounded */ static cellCount(ranges: readonly GridRange[]): number; /** * Count the number of rows in the provided grid ranges * @param ranges The ranges to count the rows of * @returns The number of rows in the ranges, or `NaN` if any of the ranges were unbounded */ static rowCount(ranges: readonly GridRange[]): number; /** * Count the number of columns in the provided grid ranges * @param ranges The ranges to count the columns of * @returns The number of columns in the ranges, or `NaN` if any of the ranges were unbounded */ static columnCount(ranges: readonly GridRange[]): number; /** * Check if the provided ranges contain the provided cell * @param ranges The ranges to check * @param column The column index * @param row The row index * @returns True if the cell is within the provided ranges, false otherwise. */ static containsCell(ranges: readonly GridRange[], column: GridRangeIndex, row: GridRangeIndex): boolean; /** * Iterate through each cell in the provided ranges * @param ranges The ranges to iterate through * @param callback The callback to execute. `index` is the index within that range * @param direction The direction to iterate in */ static forEachCell(ranges: readonly GridRange[], callback: (column: number, row: number, index: number) => void, direction?: SELECTION_DIRECTION): void; constructor(startColumn: GridRangeIndex, startRow: GridRangeIndex, endColumn: GridRangeIndex, endRow: GridRangeIndex); /** * Checks if the provided range is equivalent to this range (same start and end column/row indexes) * @param other Grid range to check against * @returns True if the ranges cover the same area */ equals(other: GridRange): boolean; /** * Checks if this GridRange contains another range * @param other The range to check * @returns True if this GridRange completely contains `other` * */ contains(other: GridRange): boolean; /** * Check if the provided cell is in this range * @param column The column to check * @param row The row to check * @returns True if this cell is within this range */ containsCell(column: GridRangeIndex, row: GridRangeIndex): boolean; /** * Check if the provided range touches (or overlaps) this GridRange * Effectively checks if the 2 ranges could be represented by 1 continuous range * @param other The range to check * @returns True if this GridRange touches `other` * */ touches(other: GridRange): boolean; /** * Subtracts a range from this range * @param other The range to deselect from within this range * @returns The ranges needed to represent the remaining */ subtract(other: GridRange): GridRange[]; /** * Get the first cell in this range. Throws if this range is unbounded. * * @param direction The direction to get the starting cell in. Defaults to DOWN * @returns The first cell in this range in the direction specified */ startCell(direction?: SELECTION_DIRECTION): GridCell; /** * Get the next cell in the direction specified. Throws if this range is unbounded. * If already at the bounds of the range in that direction, wrap to the next column or row * If at the end of the entire range, return null * If outside of the range, returns the next cell closest within this range. * * @param column The cursor column * @param row The cursor row * @param direction The direction to go in * @returns The next cell in the direction specified, or `null` if at the end of the range */ nextCell(column: GridRangeIndex, row: GridRangeIndex, direction: SELECTION_DIRECTION): GridCell | null; /** * Iterate through each cell in the range * @param callback Callback to execute. `index` is the index within this range * @param direction The direction to iterate in */ forEach(callback: (column: number, row: number, index: number) => void, direction?: SELECTION_DIRECTION): void; } export default GridRange; //# sourceMappingURL=GridRange.d.ts.map