import type { AstNode as AstNodeBase, TokenTypes, LintError } from '../base'; import type { NodeLike } from '../mixin/nodeLike'; import type { AstText, Token } from '../internal'; export type AstNodes = AstText | Token; export interface Dimension { readonly height: number; readonly width: number; } export interface Position { readonly top: number; readonly left: number; } export interface CaretPosition { readonly offsetNode: AstNodes; readonly offset: number; } export interface Font { bold: boolean; italic: boolean; } export interface AstNode extends NodeLike { } /** * Node-like * * 类似Node */ export declare abstract class AstNode implements AstNodeBase { #private; data?: string | undefined; readonly childNodes: readonly AstNodes[]; abstract get type(): TokenTypes | 'text'; abstract set type(value: TokenTypes | "text"); /** * Get the visible text * * 可见部分 */ text(): string; lint(): LintError[] & { output?: string; }; print(): string; /** parent node / 父节点 */ get parentNode(): Token | undefined; /** next sibling node / 后一个兄弟节点 */ get nextSibling(): AstNodes | undefined; /** previous sibling node / 前一个兄弟节点 */ get previousSibling(): AstNodes | undefined; /** next sibling element / 后一个非文本兄弟节点 */ get nextElementSibling(): Token | undefined; /** previous sibling element / 前一个非文本兄弟节点 */ get previousElementSibling(): Token | undefined; /** next visibling sibling node / 后一个可见的兄弟节点 */ get nextVisibleSibling(): AstNodes | undefined; /** previous visible sibling node / 前一个可见的兄弟节点 */ get previousVisibleSibling(): AstNodes | undefined; /** whether to be connected to a root token / 是否具有根节点 */ get isConnected(): boolean; /** whether to be the end of a document / 后方是否还有其他节点(不含后代) */ get eof(): boolean | undefined; /** line number relative to its parent / 相对于父容器的行号 */ get offsetTop(): number; /** column number of the last line relative to its parent / 相对于父容器的列号 */ get offsetLeft(): number; /** position, dimension and paddings / 位置、大小和padding */ get style(): Position & Dimension & { padding: number; }; /** * font weigth and style * * 字体样式 * @since v.1.8.0 */ get font(): Font; /** * whether to be bold * * 是否粗体 * @since v.1.8.0 */ get bold(): boolean; /** * whether to be italic * * 是否斜体 * @since v.1.8.0 */ get italic(): boolean; constructor(); /** * Get the root node * * 获取根节点 */ getRootNode(): Token | this; /** * Convert the position to the character index * * 将行列号转换为字符位置 * @param top line number / 行号 * @param left column number / 列号 */ indexFromPos(top: number, left: number): number | undefined; /** * Convert the character indenx to the position * * 将字符位置转换为行列号 * @param index character index / 字符位置 */ posFromIndex(index: number): Position | undefined; /** * Get the relative character index of the current node, or its `j`-th child node * * 获取当前节点的相对字符位置,或其第`j`个子节点的相对字符位置 * @param j rank of the child node / 子节点序号 */ getRelativeIndex(j?: number): number; /** * Get the absolute character index of the current node * * 获取当前节点的绝对位置 */ getAbsoluteIndex(): number; /** * Get the position and dimension of the current node * * 获取当前节点的行列位置和大小 */ getBoundingClientRect(): Dimension & Position; /** * Whether to be of a certain type * * 是否是某种类型的节点 * @param type token type / 节点类型 * @since v1.10.0 */ is(type: TokenTypes): this is T; /** * Get the text and the start/end positions of all lines * * 获取所有行的wikitext和起止位置 * @since v1.16.3 */ getLines(): [string, number, number][]; /** * Check if the node is identical * * 是否是全同节点 * @param node node to be compared to / 待比较的节点 * @throws `assert.AssertionError` */ isEqualNode(node: AstNode): boolean; /** * Insert a batch of sibling nodes after the current node * * 在后方批量插入兄弟节点 * @param nodes nodes to be inserted / 插入节点 */ after(...nodes: (AstNodes | string)[]): void; /** * Insert a batch of sibling nodes before the current node * * 在前方批量插入兄弟节点 * @param nodes nodes to be inserted / 插入节点 */ before(...nodes: (AstNodes | string)[]): void; /** * Remove the current node * * 移除当前节点 * @param ownLine whether to remove the current line if it is empty / 是否删除所在的空行 */ remove(ownLine?: boolean): void; /** * Replace the current node with new nodes * * 将当前节点批量替换为新的节点 * @param nodes nodes to be inserted / 插入节点 */ replaceWith(...nodes: (AstNodes | string)[]): void; /** * Check if the node is a descendant * * 是自身或后代节点 * @param node node to be compared to / 待检测节点 */ contains(node: AstNode): boolean; /** * Add an event listener * * 添加事件监听 * @param types event type / 事件类型 * @param listener listener function / 监听函数 * @param options options / 选项 * @param options.once to be executed only once / 仅执行一次 */ addEventListener(types: string | string[], listener: (...args: any[]) => void, options?: { once?: boolean; }): void; /** * Remove an event listener * * 移除事件监听 * @param types event type / 事件类型 * @param listener listener function / 监听函数 */ removeEventListener(types: string | string[], listener: (...args: any[]) => void): void; /** * Remove all event listeners * * 移除事件的所有监听 * @param types event type / 事件类型 */ removeAllEventListeners(types: string | string[]): void; /** * List all event listeners * * 列举事件监听 * @param type event type / 事件类型 */ listEventListeners(type: string): Function[]; /** * Dispatch an event * * 触发事件 * @param e event object / 事件对象 * @param data event data / 事件数据 */ dispatchEvent(e: Event, data: unknown): void; /** * Get all the ancestor nodes * * 获取所有祖先节点 */ getAncestors(): Token[]; /** * Compare the relative position with another node * * 比较和另一个节点的相对位置 * @param other node to be compared with / 待比较的节点 * @throws `RangeError` 不在同一个语法树 */ compareDocumentPosition(other: AstNodes): number; /** * Destroy the instance * * 销毁 */ destroy(): void; /** * Get the wikitext of a line * * 获取某一行的wikitext * @param n line number / 行号 */ getLine(n: number): string | undefined; }