@ckeditor/ckeditor5-ai
Version:
AI features for CKEditor 5.
42 lines (41 loc) • 2 kB
TypeScript
/**
* @license Copyright (c) 2003-2025, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
*/
import { type AnyNode, type Document, type DocumentPath } from './htmlparser.js';
/**
* Represents a position in htmlparser's Document.
*
* * When the parent of the position is not a `Text`, the index represents the index of a child.
* * When the parent of the positions is a `Text`, the index represents a character in that text node.
*/
export declare class DocumentPosition {
readonly parent: AnyNode;
readonly index: number;
readonly document: Document;
constructor(document: Document, parent: AnyNode, index: number);
get path(): DocumentPath;
isEqual(otherPosition: DocumentPosition): boolean;
/**
* Returns the next node in the document. It traverses both horizontally and vertically (like a walker).
*/
get nextNode(): AnyNode | null;
/**
* Returns the previous node in the document. It traverses both horizontally and vertically (like a walker).
*/
get previousNode(): AnyNode | null;
/**
* Returns a position nudged to the word boundary so that the position does not split a word.
*
* For instance:
* * "fo^o bar baz" nudged to "start" will return "^foo bar baz",
* * "fo^o bar baz" nudged to "end" will return "foo ^bar baz",
* * "^foo bar baz" nudged any way will return "^foo bar baz",
* * "foo ^bar baz" nudged any way will return "foo ^bar baz",
*/
getNudgedToWordBoundary(gravity?: 'start' | 'end'): DocumentPosition;
static createAfter(document: Document, node: AnyNode): DocumentPosition | null;
static createBefore(document: Document, node: AnyNode): DocumentPosition | null;
static createAt(document: Document, node: AnyNode, where?: 'start' | 'end' | number): DocumentPosition;
static createFromPath(document: Document, path: DocumentPath): DocumentPosition;
}