版博士V2.0程序
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

232 строки
7.1 KiB

  1. import EventTarget from '../../event/EventTarget';
  2. import MutationListener from '../../mutation-observer/MutationListener';
  3. import Event from '../../event/Event';
  4. import INode from './INode';
  5. import IDocument from '../document/IDocument';
  6. import IElement from '../element/IElement';
  7. import INodeList from './INodeList';
  8. import NodeTypeEnum from './NodeTypeEnum';
  9. import NodeDocumentPositionEnum from './NodeDocumentPositionEnum';
  10. /**
  11. * Node.
  12. */
  13. export default class Node extends EventTarget implements INode {
  14. static _ownerDocument: IDocument;
  15. static readonly ELEMENT_NODE = NodeTypeEnum.elementNode;
  16. static readonly ATTRIBUTE_NODE = NodeTypeEnum.attributeNode;
  17. static readonly TEXT_NODE = NodeTypeEnum.textNode;
  18. static readonly CDATA_SECTION_NODE = NodeTypeEnum.cdataSectionNode;
  19. static readonly COMMENT_NODE = NodeTypeEnum.commentNode;
  20. static readonly DOCUMENT_NODE = NodeTypeEnum.documentNode;
  21. static readonly DOCUMENT_TYPE_NODE = NodeTypeEnum.documentTypeNode;
  22. static readonly DOCUMENT_FRAGMENT_NODE = NodeTypeEnum.documentFragmentNode;
  23. static readonly PROCESSING_INSTRUCTION_NODE = NodeTypeEnum.processingInstructionNode;
  24. static readonly DOCUMENT_POSITION_CONTAINED_BY = NodeDocumentPositionEnum.containedBy;
  25. static readonly DOCUMENT_POSITION_CONTAINS = NodeDocumentPositionEnum.contains;
  26. static readonly DOCUMENT_POSITION_DISCONNECTED = NodeDocumentPositionEnum.disconnect;
  27. static readonly DOCUMENT_POSITION_FOLLOWING = NodeDocumentPositionEnum.following;
  28. static readonly DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC = NodeDocumentPositionEnum.implementationSpecific;
  29. static readonly DOCUMENT_POSITION_PRECEDING = NodeDocumentPositionEnum.preceding;
  30. readonly ELEMENT_NODE = NodeTypeEnum.elementNode;
  31. readonly ATTRIBUTE_NODE = NodeTypeEnum.attributeNode;
  32. readonly TEXT_NODE = NodeTypeEnum.textNode;
  33. readonly CDATA_SECTION_NODE = NodeTypeEnum.cdataSectionNode;
  34. readonly COMMENT_NODE = NodeTypeEnum.commentNode;
  35. readonly DOCUMENT_NODE = NodeTypeEnum.documentNode;
  36. readonly DOCUMENT_TYPE_NODE = NodeTypeEnum.documentTypeNode;
  37. readonly DOCUMENT_FRAGMENT_NODE = NodeTypeEnum.documentFragmentNode;
  38. readonly PROCESSING_INSTRUCTION_NODE = NodeTypeEnum.processingInstructionNode;
  39. readonly DOCUMENT_POSITION_CONTAINED_BY = NodeDocumentPositionEnum.containedBy;
  40. readonly DOCUMENT_POSITION_CONTAINS = NodeDocumentPositionEnum.contains;
  41. readonly DOCUMENT_POSITION_DISCONNECTED = NodeDocumentPositionEnum.disconnect;
  42. readonly DOCUMENT_POSITION_FOLLOWING = NodeDocumentPositionEnum.following;
  43. readonly DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC = NodeDocumentPositionEnum.implementationSpecific;
  44. readonly DOCUMENT_POSITION_PRECEDING = NodeDocumentPositionEnum.preceding;
  45. readonly ownerDocument: IDocument;
  46. readonly parentNode: INode;
  47. readonly nodeType: number;
  48. readonly childNodes: INodeList<INode>;
  49. readonly isConnected: boolean;
  50. _rootNode: INode;
  51. _observers: MutationListener[];
  52. /**
  53. * Constructor.
  54. */
  55. constructor();
  56. /**
  57. * Returns `Symbol.toStringTag`.
  58. *
  59. * @returns `Symbol.toStringTag`.
  60. */
  61. get [Symbol.toStringTag](): string;
  62. /**
  63. * Get text value of children.
  64. *
  65. * @returns Text content.
  66. */
  67. get textContent(): string;
  68. /**
  69. * Sets text content.
  70. *
  71. * @param _textContent Text content.
  72. */
  73. set textContent(_textContent: string);
  74. /**
  75. * Node value.
  76. *
  77. * @returns Node value.
  78. */
  79. get nodeValue(): string;
  80. /**
  81. * Sets node value.
  82. */
  83. set nodeValue(_nodeValue: string);
  84. /**
  85. * Node name.
  86. *
  87. * @returns Node name.
  88. */
  89. get nodeName(): string;
  90. /**
  91. * Previous sibling.
  92. *
  93. * @returns Node.
  94. */
  95. get previousSibling(): INode;
  96. /**
  97. * Next sibling.
  98. *
  99. * @returns Node.
  100. */
  101. get nextSibling(): INode;
  102. /**
  103. * First child.
  104. *
  105. * @returns Node.
  106. */
  107. get firstChild(): INode;
  108. /**
  109. * Last child.
  110. *
  111. * @returns Node.
  112. */
  113. get lastChild(): INode;
  114. /**
  115. * Returns parent element.
  116. *
  117. * @returns Element.
  118. */
  119. get parentElement(): IElement;
  120. /**
  121. * Returns base URI.
  122. *
  123. * @returns Base URI.
  124. */
  125. get baseURI(): string;
  126. /**
  127. * Connected callback.
  128. */
  129. connectedCallback?(): void;
  130. /**
  131. * Disconnected callback.
  132. */
  133. disconnectedCallback?(): void;
  134. /**
  135. * Returns "true" if the node has child nodes.
  136. *
  137. * @returns "true" if the node has child nodes.
  138. */
  139. hasChildNodes(): boolean;
  140. /**
  141. * Returns "true" if this node contains the other node.
  142. *
  143. * @param otherNode Node to test with.
  144. * @returns "true" if this node contains the other node.
  145. */
  146. contains(otherNode: INode): boolean;
  147. /**
  148. * Returns closest root node (Document or ShadowRoot).
  149. *
  150. * @param options Options.
  151. * @param options.composed A Boolean that indicates whether the shadow root should be returned (false, the default), or a root node beyond shadow root (true).
  152. * @returns Node.
  153. */
  154. getRootNode(options?: {
  155. composed: boolean;
  156. }): INode;
  157. /**
  158. * Clones a node.
  159. *
  160. * @param [deep=false] "true" to clone deep.
  161. * @returns Cloned node.
  162. */
  163. cloneNode(deep?: boolean): INode;
  164. /**
  165. * Append a child node to childNodes.
  166. *
  167. * @param node Node to append.
  168. * @returns Appended node.
  169. */
  170. appendChild(node: INode): INode;
  171. /**
  172. * Remove Child element from childNodes array.
  173. *
  174. * @param node Node to remove.
  175. * @returns Removed node.
  176. */
  177. removeChild(node: INode): INode;
  178. /**
  179. * Inserts a node before another.
  180. *
  181. * @param newNode Node to insert.
  182. * @param referenceNode Node to insert before.
  183. * @returns Inserted node.
  184. */
  185. insertBefore(newNode: INode, referenceNode: INode | null): INode;
  186. /**
  187. * Replaces a node with another.
  188. *
  189. * @param newChild New child.
  190. * @param oldChild Old child.
  191. * @returns Replaced node.
  192. */
  193. replaceChild(newChild: INode, oldChild: INode): INode;
  194. /**
  195. * @override
  196. */
  197. dispatchEvent(event: Event): boolean;
  198. /**
  199. * Converts the node to a string.
  200. *
  201. * @param listener Listener.
  202. */
  203. toString(): string;
  204. /**
  205. * Observeres the node.
  206. * Used by MutationObserver, but it is not part of the HTML standard.
  207. *
  208. * @param listener Listener.
  209. */
  210. _observe(listener: MutationListener): void;
  211. /**
  212. * Stops observing the node.
  213. * Used by MutationObserver, but it is not part of the HTML standard.
  214. *
  215. * @param listener Listener.
  216. */
  217. _unobserve(listener: MutationListener): void;
  218. /**
  219. * Connects this element to another element.
  220. *
  221. * @param parentNode Parent node.
  222. */
  223. _connectToNode(parentNode?: INode): void;
  224. /**
  225. * Reports the position of its argument node relative to the node on which it is called.
  226. *
  227. * @see https://dom.spec.whatwg.org/#dom-node-comparedocumentposition
  228. * @param otherNode Other node.
  229. */
  230. compareDocumentPosition(otherNode: INode): number;
  231. }