wikiparser-node
Version:
A Node.js parser for MediaWiki markup with AST
244 lines (243 loc) • 7.09 kB
TypeScript
import type { NodeLike } from '../mixin/nodeLike';
import type { ElementLike } from '../mixin/elementLike';
import type { AstNodes, Token } from '../internal';
import type { Dimension, Position } from './node';
export interface AstRange extends NodeLike, ElementLike {
}
/**
* Range-like
*
* 模拟Range对象
*/
export declare class AstRange {
#private;
/** start container / 起点容器 */
get startContainer(): AstNodes;
/** start offset / 起点位置 */
get startOffset(): number;
/** start character index / 起点绝对位置 */
get startIndex(): number;
/** start position / 起点行列位置 */
get startPos(): Position;
/** end container / 终点容器 */
get endContainer(): AstNodes;
/** end offset / 终点位置 */
get endOffset(): number;
/** end character index / 终点绝对位置 */
get endIndex(): number;
/** end position / 终点行列位置 */
get endPos(): Position;
/** whether the start and end positions are identical / 起始和终止位置是否重合 */
get collapsed(): boolean;
/** closest common ancestor / 最近的公共祖先 */
get commonAncestorContainer(): AstNodes;
/**
* nodes in the Range
*
* 范围内的节点
* @since v1.23.0
*/
get childNodes(): AstNodes[];
/**
* Set the start
*
* 设置起点
* @param startNode start container / 起点容器
* @param offset start offset / 起点位置
* @throws `RangeError` offset取值超出范围
*/
setStart(startNode: AstNodes, offset: number): void;
/**
* Set the end
*
* 设置终点
* @param endNode end container / 终点容器
* @param offset end offset / 终点位置
* @throws `RangeError` offset取值超出范围
*/
setEnd(endNode: AstNodes, offset: number): void;
/**
* Set the start after the node
*
* 在节点后设置起点
* @param referenceNode reference node / 节点
*/
setStartAfter(referenceNode: AstNodes): void;
/**
* Set the end after the node
*
* 在节点后设置终点
* @param referenceNode reference node / 节点
*/
setEndAfter(referenceNode: AstNodes): void;
/**
* Set the start before the node
*
* 在节点前设置起点
* @param referenceNode reference node / 节点
*/
setStartBefore(referenceNode: AstNodes): void;
/**
* Set the end before the node
*
* 在节点前设置终点
* @param referenceNode reference node / 节点
*/
setEndBefore(referenceNode: AstNodes): void;
/**
* Set the Range to contain the entire contents of the node
*
* 设置Range包含整个节点的内容
* @param referenceNode reference node / 节点
*/
selectNodeContents(referenceNode: AstNodes): void;
/**
* Set the Range to contain the entire node
*
* 设置Range包含整个节点
* @param referenceNode reference node / 节点
*/
selectNode(referenceNode: AstNodes): void;
/**
* Set the end position to the start position, or the other way around
*
* 使起始和终止位置重合
* @param toStart whether to set the end position to the start position / 重合至起始位置
*/
collapse(toStart?: boolean): void;
/**
* Compare the relative position of a point with the Range
*
* 比较端点和Range的位置
* @param referenceNode node container / 端点容器
* @param offset node offset / 端点位置
* @throws `RangeError` 不在同一个文档
*/
comparePoint(referenceNode: AstNodes, offset: number): -1 | 0 | 1;
/**
* Check if the point is in the Range
*
* 端点是否在Range中
* @param referenceNode node container / 端点容器
* @param offset node offset / 端点位置
*/
isPointInRange(referenceNode: AstNodes, offset: number): boolean;
/**
* Clone the AstRange object
*
* 复制AstRange对象
*/
cloneRange(): AstRange;
/**
* Empty the Range
*
* 清空Range
*/
detach(): void;
/**
* Remove the contents of the Range
*
* 删除Range中的内容
*/
deleteContents(): void;
/**
* Remove the contents of the Range
*
* 删除Range中的内容
* @since v1.23.0
*/
remove(): void;
/**
* Get the position and dimension
*
* 获取行列位置和大小
*/
getBoundingClientRect(): Dimension & Position;
/**
* Get the client rects of all nodes in the Range
*
* 获取范围内所有节点的行列位置和大小
* @since v1.23.0
*/
getClientRects(): (Dimension & Position)[];
/**
* Insert a node before or after the Range
*
* 在范围前或后插入节点
* @param newNode node to be inserted / 插入的节点
* @param after whether to insert after the Range / 是否在范围后插入
*/
insertNode(newNode: AstNodes | string, after?: boolean): void;
/**
* Insert nodes before the Range
*
* 在范围前插入节点
* @param nodes nodes to be inserted / 插入节点
* @since v1.23.0
*/
before(...nodes: (AstNodes | string)[]): void;
/**
* Insert nodes after the Range
*
* 在范围后插入节点
* @param nodes nodes to be inserted / 插入节点
* @since v1.23.0
*/
after(...nodes: (AstNodes | string)[]): void;
/**
* Replace the Range with new nodes
*
* 将当前范围批量替换为新的节点
* @param nodes nodes to be inserted / 插入节点
* @since v1.23.0
*/
replaceWith(...nodes: (AstNodes | string)[]): void;
/**
* Get the contents of the Range
*
* 获取范围内的全部节点
*/
extractContents(): AstNodes[];
/**
* Clone the contents of the Range
*
* 拷贝范围内的全部节点
*/
cloneContents(): AstNodes[];
/**
* Get the root node
*
* 获取根节点
* @since v1.23.0
*/
getRootNode(): AstNodes;
/**
* Get the closest ancestor node that matches the selector
*
* 最近的符合选择器的祖先节点
* @param selector selector / 选择器
*/
closest<T = Token>(selector: string): T | undefined;
/**
* Insert a batch of child nodes at the end
*
* 在末尾批量插入子节点
* @param elements nodes to be inserted / 插入节点
*/
append(...elements: (AstNodes | string)[]): void;
/**
* Insert a batch of child nodes at the start
*
* 在开头批量插入子节点
* @param elements nodes to be inserted / 插入节点
*/
prepend(...elements: (AstNodes | string)[]): void;
/**
* Remove a child node
*
* 移除子节点
* @param node child node to be removed / 子节点
* @throws `RangeError` 不是子节点
*/
removeChild<T extends AstNodes>(node: T): T;
}