export declare enum PointAffinity { START = 0, END = 1 } export declare type PointHoistOptions = { /** * Condition that must hold for the point's node throughout the hoist. * * This condition also applies to the ancestor being hoisted up to. * * It is intended to avoid mutating DOM nodes unnecessarily, e.g. when bolding a substring of text that is * already bold. */ condition: (node: Node) => boolean; /** * Condition that must hold for a node to be split. * * If the base condition also applies, then the point will hoist up to the node resulting from the split. * * This is intended to control how far to force the point to be hoisted up. For example, bolding can be done * at the text node level, so you would return true for text nodes only. In contrast, removing bold should * be done as high up in the flow content element (paragraph) as possible, to split ancestors, so * you would return true for phrasing content elements. */ splitCondition: (node: Node) => boolean; /** * Whether to prefer a start or end point after a split. */ splitAffinity: PointAffinity; /** * Condition that must hold for a point at the start of a node to be hoisted up. * * For example, you may want the node to be the first (non-whitespace) child of its parent. */ startCondition: (node: Node) => boolean; /** * Condition that must remain true for a point at the end of a node to be hoisted up. * * For example, you may want the node to be the last (non-whitespace) child of its parent. */ endCondition: (node: Node) => boolean; }; /** * Represents a point in the DOM, i.e. one side of a DOM Range. * * Use createPointWithOffsetInContainer to create the appropriate subclass. * * Unlike a DOM Range, these points are stable under DOM mutations. For example, if a node is appended to a new parent, * the point will move to the node's new index in that new container. */ export declare abstract class Point { protected readonly node: Node; protected readonly originalParentNode: Node | null; protected readonly originalPreviousSibling: Node | null; protected readonly originalNextSibling: Node | null; private readonly wasDenormalizedTextNode; private readonly originalPrecedingNonTextSibling; private readonly originalPrecedingText; private readonly originalText; constructor(node: Node); isValid(): boolean; /** If this point is in the middle of a node, move to its start. */ moveToStart(): PointAtStartOfNode | this; /** If this point is in the middle of a node, move to its end. */ moveToEnd(): PointAtEndOfNode | this; /** * Returns values suitable as arguments for Range#setStart and Range#setEnd. * * Returns null if the node has since been removed from its document. */ abstract getOffsetInContainer(): [Node, number] | null; /** * Returns a node (container) and offset pair corrected for DOM normalization. * * See Node#normalize(). * * @param offset * The offset within the original text node to correct. May be Infinity, which will be interpreted as the * end of the original text node. */ protected getNormalizedOffsetInContainer(offset?: number): [Node, number] | null; /** * Hoists this point up as much as possible while staying on the same node. * * In practice, this performs a split if the point is in the middle of a node. This is intended to be used * to keep a point further down in the tree so that it will remain valid/stable throughout hoisting up * higher in the tree. */ abstract hoistSplit(options: PointHoistOptions, container: Node): Point; /** * Hoists this point up to an ancestor. * * This performs #hoistSplit() before recursing up the tree. * * This can be used, for example, to move a point from the start of a text node to the start of its parent * container if there are no previous siblings. Or to split an element at the cursor all the way up to the * top level container. */ abstract hoist(options: PointHoistOptions, container: Node): Point; isAtStartOfNode(node: Node, startCondition: (node: Node) => boolean, container: Node): boolean; isAtStartOfNode(node: Node): boolean; isAtEndOfNode(node: Node, endCondition: (node: Node) => boolean, container: Node): boolean; isAtEndOfNode(node: Node): boolean; intersectsNode(node: Node): boolean; isAfterNode(node: Node): boolean; isAfterPoint(point: Point): boolean; isEqual(point: Point): boolean; findNearestElement(container: Element): Element; findNearestElement(container: Node): Element | null; /** * Finds the next whole node after this point and inside the container. * * If this point is at the start of a node, it returns that node. */ abstract findNextNode(container: Node): Node | null; abstract insertNode(node: Node, returnPointAffinity: PointAffinity.START): PointAtStartOfNode | this; abstract insertNode(node: Node, returnPointAffinity: PointAffinity.END): PointAtEndOfNode | this; abstract insertNode(node: Node): PointAtEndOfNode | this; abstract insertNode(node: Node, returnPointAffinity?: PointAffinity): PointAtStartOfNode | PointAtEndOfNode | this; scrollIntoViewIfNeeded(): void; } /** * Represent a point within a text node. * * While it is illegal to create a new PointInText at the start or end of a text node (use PointAtStartOfNode * or PointAtEndOfNode instead) it may end up being so if the text node gets mutated after the point has been * created. */ export declare class PointInText extends Point { readonly text: Text; private readonly originalOffset; private readonly originalDataAfterOffset; constructor(text: Text, offset: number); get offset(): number; get endOffset(): number; getOffsetInContainer(): [Node, number]; hoistSplit(options: PointHoistOptions, container: Node): PointAtStartOfNode | PointAtEndOfNode | this; hoist(options: PointHoistOptions, container: Node): Point; isAtStartOfNode(node: Node, startCondition: (node: Node) => boolean, container: Node): boolean; isAtStartOfNode(node: Node): boolean; isAtEndOfNode(node: Node, endCondition: (node: Node) => boolean, container: Node): boolean; isAtEndOfNode(node: Node): boolean; isAfterPoint(point: Point): boolean; isEqual(point: Point): boolean; findNextNode(container: Node): Node | null; insertNode(node: Node, returnPointAffinity?: PointAffinity): PointAtStartOfNode | PointAtEndOfNode | this; toString(): string; } /** * Represents a point immediately before a node. */ export declare class PointAtStartOfNode extends Point { getOffsetInContainer(): [Node, number] | null; hoistSplit(options: PointHoistOptions, container: Node): PointAtStartOfNode; hoist(options: PointHoistOptions, container: Node): PointAtStartOfNode; isAtStartOfNode(otherNode: Node, startCondition: (node: Node) => boolean, container: Node): boolean; isAtStartOfNode(otherNode: Node): boolean; findNextNode(container: Node): Node | null; insertNode(newNode: Node, returnPointAffinity?: PointAffinity): PointAtStartOfNode | PointAtEndOfNode | this; toString(): string; } /** * Represents a point immediately after a node. */ export declare class PointAtEndOfNode extends Point { getOffsetInContainer(): [Node, number] | null; hoistSplit(options: PointHoistOptions, container: Node): PointAtEndOfNode; hoist(options: PointHoistOptions, container: Node): PointAtEndOfNode; isAtEndOfNode(otherNode: Node, endCondition: (node: Node) => boolean, container: Node): boolean; isAtEndOfNode(otherNode: Node): boolean; findNextNode(container: Node): Node | null; insertNode(newNode: Node, returnPointAffinity?: PointAffinity): PointAtStartOfNode | PointAtEndOfNode | this; toString(): string; } /** * Represent a point in an empty element. * * If an element becomes non-empty, the point becames equivalent to a point at the start of the first child. */ export declare class PointInLeaf extends Point { constructor(node: Node); moveToStart(): PointAtStartOfNode | this; moveToEnd(): PointAtEndOfNode | this; getOffsetInContainer(): [Node, number]; hoistSplit(options: PointHoistOptions, container: Node): PointAtStartOfNode | this; hoist(options: PointHoistOptions, container: Node): Point; isAtStartOfNode(targetNode: Node, startCondition: (node: Node) => boolean, container: Node): boolean; isAtStartOfNode(targetNode: Node): boolean; isAtEndOfNode(targetNode: Node, endCondition: (node: Node) => boolean, container: Node): boolean; isAtEndOfNode(targetNode: Node): boolean; isEqual(point: Point): boolean; findNextNode(container: Node): Node | null; insertNode(newNode: Node, returnPointAffinity?: PointAffinity): PointAtStartOfNode | PointAtEndOfNode | this; toString(): string; } export declare function createRangeWithPoint(document: Document, point: Point): Range; export declare function createRangeWithPoints(document: Document, startPoint: Point, endPoint: Point): Range; export declare function cloneRangeWithPoint(otherRange: Range, point: Point): Range; export declare function cloneRangeWithPoints(otherRange: Range, startPoint: Point, endPoint: Point): Range; export declare function updateRangeWithPoints(range: Range, startPoint: Point, endPoint: Point): Range; export declare function setStartOfRangeWithPoint(range: Range, startPoint: Point): Range; export declare function setEndOfRangeWithPoint(range: Range, endPoint: Point): Range; export declare function createPointWithStartOfRange(range: Range): Point; export declare function createPointWithEndOfRange(range: Range): Point; export declare function updateSelectionWithPoints(selection: Selection, anchorPoint: Point, focusPoint: Point): void; export declare function setAnchorInSelectionWithPoint(selection: Selection, point: Point): void; export declare function setFocusInSelectionWithPoint(selection: Selection, point: Point): void; export declare function createPointWithOffsetInContainer(container: Node, offset: number): Point; export declare function isPointInText(point: Point): point is PointInText; export declare function createPointAtStartOfNode(node: Node): PointAtStartOfNode; export declare function createPointAtEndOfNode(node: Node): PointAtEndOfNode; export declare function createPointAtStartOfNodeContents(node: Node): PointAtStartOfNode | PointInLeaf; export declare function createPointAtEndOfNodeContents(node: Node): PointAtEndOfNode | PointInLeaf; export declare function findFirstTextPoint(container: Node, startNode?: Node): Point | undefined; export declare function findLastTextPoint(container: Node, startNode?: Node, maxIterations?: number): Point | undefined;