|
import { ElementType } from "domelementtype"; |
|
interface SourceCodeLocation { |
|
|
|
startLine: number; |
|
|
|
startCol: number; |
|
|
|
startOffset: number; |
|
|
|
endLine: number; |
|
|
|
endCol: number; |
|
|
|
endOffset: number; |
|
} |
|
interface TagSourceCodeLocation extends SourceCodeLocation { |
|
startTag?: SourceCodeLocation; |
|
endTag?: SourceCodeLocation; |
|
} |
|
export declare type ParentNode = Document | Element | CDATA; |
|
export declare type ChildNode = Text | Comment | ProcessingInstruction | Element | CDATA | Document; |
|
export declare type AnyNode = ParentNode | ChildNode; |
|
|
|
|
|
|
|
|
|
export declare abstract class Node { |
|
|
|
abstract readonly type: ElementType; |
|
|
|
parent: ParentNode | null; |
|
|
|
prev: ChildNode | null; |
|
|
|
next: ChildNode | null; |
|
|
|
startIndex: number | null; |
|
|
|
endIndex: number | null; |
|
|
|
|
|
|
|
|
|
|
|
sourceCodeLocation?: SourceCodeLocation | null; |
|
|
|
|
|
|
|
|
|
abstract readonly nodeType: number; |
|
|
|
|
|
|
|
|
|
get parentNode(): ParentNode | null; |
|
set parentNode(parent: ParentNode | null); |
|
|
|
|
|
|
|
|
|
get previousSibling(): ChildNode | null; |
|
set previousSibling(prev: ChildNode | null); |
|
|
|
|
|
|
|
|
|
get nextSibling(): ChildNode | null; |
|
set nextSibling(next: ChildNode | null); |
|
|
|
|
|
|
|
|
|
|
|
|
|
cloneNode<T extends Node>(this: T, recursive?: boolean): T; |
|
} |
|
|
|
|
|
|
|
export declare abstract class DataNode extends Node { |
|
data: string; |
|
|
|
|
|
|
|
constructor(data: string); |
|
|
|
|
|
|
|
|
|
get nodeValue(): string; |
|
set nodeValue(data: string); |
|
} |
|
|
|
|
|
|
|
export declare class Text extends DataNode { |
|
type: ElementType.Text; |
|
get nodeType(): 3; |
|
} |
|
|
|
|
|
|
|
export declare class Comment extends DataNode { |
|
type: ElementType.Comment; |
|
get nodeType(): 8; |
|
} |
|
|
|
|
|
|
|
export declare class ProcessingInstruction extends DataNode { |
|
name: string; |
|
type: ElementType.Directive; |
|
constructor(name: string, data: string); |
|
get nodeType(): 1; |
|
|
|
"x-name"?: string; |
|
|
|
"x-publicId"?: string; |
|
|
|
"x-systemId"?: string; |
|
} |
|
|
|
|
|
|
|
export declare abstract class NodeWithChildren extends Node { |
|
children: ChildNode[]; |
|
|
|
|
|
|
|
constructor(children: ChildNode[]); |
|
|
|
get firstChild(): ChildNode | null; |
|
|
|
get lastChild(): ChildNode | null; |
|
|
|
|
|
|
|
|
|
get childNodes(): ChildNode[]; |
|
set childNodes(children: ChildNode[]); |
|
} |
|
export declare class CDATA extends NodeWithChildren { |
|
type: ElementType.CDATA; |
|
get nodeType(): 4; |
|
} |
|
|
|
|
|
|
|
export declare class Document extends NodeWithChildren { |
|
type: ElementType.Root; |
|
get nodeType(): 9; |
|
|
|
"x-mode"?: "no-quirks" | "quirks" | "limited-quirks"; |
|
} |
|
|
|
|
|
|
|
interface Attribute { |
|
name: string; |
|
value: string; |
|
namespace?: string; |
|
prefix?: string; |
|
} |
|
/** |
|
* An element within the DOM. |
|
*/ |
|
export declare class Element extends NodeWithChildren { |
|
name: string; |
|
attribs: { |
|
[name: string]: string; |
|
}; |
|
type: ElementType.Tag | ElementType.Script | ElementType.Style; |
|
|
|
|
|
|
|
|
|
|
|
constructor(name: string, attribs: { |
|
[name: string]: string; |
|
}, children?: ChildNode[], type?: ElementType.Tag | ElementType.Script | ElementType.Style); |
|
get nodeType(): 1; |
|
|
|
|
|
|
|
|
|
|
|
sourceCodeLocation?: TagSourceCodeLocation | null; |
|
|
|
|
|
|
|
|
|
get tagName(): string; |
|
set tagName(name: string); |
|
get attributes(): Attribute[]; |
|
|
|
namespace?: string; |
|
/** Element attribute namespaces (parse5 only). */ |
|
"x-attribsNamespace"?: Record<string, string>; |
|
/** Element attribute namespace-related prefixes (parse5 only). */ |
|
"x-attribsPrefix"?: Record<string, string>; |
|
} |
|
/** |
|
* @param node Node to check. |
|
* @returns `true` if the node is a `Element`, `false` otherwise. |
|
*/ |
|
export declare function isTag(node: Node): node is Element; |
|
/** |
|
* @param node Node to check. |
|
* @returns `true` if the node has the type `CDATA`, `false` otherwise. |
|
*/ |
|
export declare function isCDATA(node: Node): node is CDATA; |
|
/** |
|
* @param node Node to check. |
|
* @returns `true` if the node has the type `Text`, `false` otherwise. |
|
*/ |
|
export declare function isText(node: Node): node is Text; |
|
/** |
|
* @param node Node to check. |
|
* @returns `true` if the node has the type `Comment`, `false` otherwise. |
|
*/ |
|
export declare function isComment(node: Node): node is Comment; |
|
/** |
|
* @param node Node to check. |
|
* @returns `true` if the node has the type `ProcessingInstruction`, `false` otherwise. |
|
*/ |
|
export declare function isDirective(node: Node): node is ProcessingInstruction; |
|
/** |
|
* @param node Node to check. |
|
* @returns `true` if the node has the type `ProcessingInstruction`, `false` otherwise. |
|
*/ |
|
export declare function isDocument(node: Node): node is Document; |
|
/** |
|
* @param node Node to check. |
|
* @returns `true` if the node has children, `false` otherwise. |
|
*/ |
|
export declare function hasChildren(node: Node): node is ParentNode; |
|
/** |
|
* Clone a node, and optionally its children. |
|
* |
|
* @param recursive Clone child nodes as well. |
|
* @returns A clone of the node. |
|
*/ |
|
export declare function cloneNode<T extends Node>(node: T, recursive?: boolean): T; |
|
export {}; |
|
|