import { PositionType } from 'roosterjs-editor-types'; import type { NodePosition } from 'roosterjs-editor-types'; import type { CompatiblePositionType } from 'roosterjs-editor-types/lib/compatibleTypes'; /** * Represent a position in DOM tree by the node and its offset index */ export default class Position implements NodePosition { private readonly isFromEndOfRange?; readonly node: Node; readonly element: HTMLElement; readonly offset: number; readonly isAtEnd: boolean; /** * Clone and validate a position from existing position. * If the given position has invalid offset, this function will return a corrected value. * @param position The original position to clone from */ constructor(position: NodePosition); /** * Create a Position from node and an offset number * @param node The node of this position * @param offset Offset of this position * @param isFromEndOfRange Whether this position is created from end of a range. An position * created from end of range has different behavior when normalize, it will use the child node * before current position if any as a deeper level node and set isAtEnd to true. */ constructor(node: Node, offset: number, isFromEndOfRange?: boolean); /** * Create a Position from node and a type of position * @param node The node of this position * @param positionType Type of the position, can be Begin, End, Before, After */ constructor(node: Node, positionType: PositionType | CompatiblePositionType); /** * Normalize this position to the leaf node, return the normalize result. * If current position is already using leaf node, return this position object itself */ normalize(): NodePosition; /** * Check if this position is equal to the given position * @param position The position to check */ equalTo(position: NodePosition): boolean; /** * Checks if this position is after the given position */ isAfter(position: NodePosition): boolean; /** * Move this position with offset, returns a new position with a valid offset in the same node * @param offset Offset to move with */ move(offset: number): Position; /** * Get start position of the given Range * @param range The range to get position from */ static getStart(range: Range): Position; /** * Get end position of the given Range * @param range The range to get position from */ static getEnd(range: Range): Position; }