node.d.ts 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. import { ElementType } from "domelementtype";
  2. /**
  3. * This object will be used as the prototype for Nodes when creating a
  4. * DOM-Level-1-compliant structure.
  5. */
  6. export declare class Node {
  7. type: ElementType;
  8. /** Parent of the node */
  9. parent: NodeWithChildren | null;
  10. /** Previous sibling */
  11. prev: Node | null;
  12. /** Next sibling */
  13. next: Node | null;
  14. /** The start index of the node. Requires `withStartIndices` on the handler to be `true. */
  15. startIndex: number | null;
  16. /** The end index of the node. Requires `withEndIndices` on the handler to be `true. */
  17. endIndex: number | null;
  18. /**
  19. *
  20. * @param type The type of the node.
  21. */
  22. constructor(type: ElementType);
  23. get nodeType(): number;
  24. get parentNode(): NodeWithChildren | null;
  25. set parentNode(parent: NodeWithChildren | null);
  26. get previousSibling(): Node | null;
  27. set previousSibling(prev: Node | null);
  28. get nextSibling(): Node | null;
  29. set nextSibling(next: Node | null);
  30. /**
  31. * Clone this node, and optionally its children.
  32. *
  33. * @param recursive Clone child nodes as well.
  34. * @returns A clone of the node.
  35. */
  36. cloneNode<T extends Node>(this: T, recursive?: boolean): T;
  37. }
  38. /**
  39. * A node that contains some data.
  40. */
  41. export declare class DataNode extends Node {
  42. data: string;
  43. /**
  44. * @param type The type of the node
  45. * @param data The content of the data node
  46. */
  47. constructor(type: ElementType.Comment | ElementType.Text | ElementType.Directive, data: string);
  48. get nodeValue(): string;
  49. set nodeValue(data: string);
  50. }
  51. /**
  52. * Text within the document.
  53. */
  54. export declare class Text extends DataNode {
  55. constructor(data: string);
  56. }
  57. /**
  58. * Comments within the document.
  59. */
  60. export declare class Comment extends DataNode {
  61. constructor(data: string);
  62. }
  63. /**
  64. * Processing instructions, including doc types.
  65. */
  66. export declare class ProcessingInstruction extends DataNode {
  67. name: string;
  68. constructor(name: string, data: string);
  69. "x-name"?: string;
  70. "x-publicId"?: string;
  71. "x-systemId"?: string;
  72. }
  73. /**
  74. * A `Node` that can have children.
  75. */
  76. export declare class NodeWithChildren extends Node {
  77. children: Node[];
  78. /**
  79. * @param type Type of the node.
  80. * @param children Children of the node. Only certain node types can have children.
  81. */
  82. constructor(type: ElementType.Root | ElementType.CDATA | ElementType.Script | ElementType.Style | ElementType.Tag, children: Node[]);
  83. get firstChild(): Node | null;
  84. get lastChild(): Node | null;
  85. get childNodes(): Node[];
  86. set childNodes(children: Node[]);
  87. }
  88. /**
  89. * The root node of the document.
  90. */
  91. export declare class Document extends NodeWithChildren {
  92. constructor(children: Node[]);
  93. "x-mode"?: "no-quirks" | "quirks" | "limited-quirks";
  94. }
  95. /**
  96. * The description of an individual attribute.
  97. */
  98. interface Attribute {
  99. name: string;
  100. value: string;
  101. namespace?: string;
  102. prefix?: string;
  103. }
  104. /**
  105. * An element within the DOM.
  106. */
  107. export declare class Element extends NodeWithChildren {
  108. name: string;
  109. attribs: {
  110. [name: string]: string;
  111. };
  112. /**
  113. * @param name Name of the tag, eg. `div`, `span`.
  114. * @param attribs Object mapping attribute names to attribute values.
  115. * @param children Children of the node.
  116. */
  117. constructor(name: string, attribs: {
  118. [name: string]: string;
  119. }, children?: Node[], type?: ElementType.Tag | ElementType.Script | ElementType.Style);
  120. get tagName(): string;
  121. set tagName(name: string);
  122. get attributes(): Attribute[];
  123. "x-attribsNamespace"?: Record<string, string>;
  124. "x-attribsPrefix"?: Record<string, string>;
  125. }
  126. /**
  127. * @param node Node to check.
  128. * @returns `true` if the node is a `Element`, `false` otherwise.
  129. */
  130. export declare function isTag(node: Node): node is Element;
  131. /**
  132. * @param node Node to check.
  133. * @returns `true` if the node has the type `CDATA`, `false` otherwise.
  134. */
  135. export declare function isCDATA(node: Node): node is NodeWithChildren;
  136. /**
  137. * @param node Node to check.
  138. * @returns `true` if the node has the type `Text`, `false` otherwise.
  139. */
  140. export declare function isText(node: Node): node is Text;
  141. /**
  142. * @param node Node to check.
  143. * @returns `true` if the node has the type `Comment`, `false` otherwise.
  144. */
  145. export declare function isComment(node: Node): node is DataNode;
  146. /**
  147. * @param node Node to check.
  148. * @returns `true` if the node has the type `ProcessingInstruction`, `false` otherwise.
  149. */
  150. export declare function isDirective(node: Node): node is ProcessingInstruction;
  151. /**
  152. * @param node Node to check.
  153. * @returns `true` if the node has the type `ProcessingInstruction`, `false` otherwise.
  154. */
  155. export declare function isDocument(node: Node): node is Document;
  156. /**
  157. * @param node Node to check.
  158. * @returns `true` if the node is a `NodeWithChildren` (has children), `false` otherwise.
  159. */
  160. export declare function hasChildren(node: Node): node is NodeWithChildren;
  161. /**
  162. * Clone a node, and optionally its children.
  163. *
  164. * @param recursive Clone child nodes as well.
  165. * @returns A clone of the node.
  166. */
  167. export declare function cloneNode<T extends Node>(node: T, recursive?: boolean): T;
  168. export {};
  169. //# sourceMappingURL=node.d.ts.map