happy-dom 2.55.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of happy-dom might be problematic. Click here for more details.

Files changed (284) hide show
  1. package/README.md +26 -6
  2. package/lib/async-task-manager/AsyncTaskManager.js +34 -78
  3. package/lib/async-task-manager/AsyncTaskManager.js.map +1 -1
  4. package/lib/attribute/Attr.js +19 -28
  5. package/lib/attribute/Attr.js.map +1 -1
  6. package/lib/config/ElementTag.js +15 -15
  7. package/lib/config/ElementTag.js.map +1 -1
  8. package/lib/cookie/CookieUtility.js +21 -26
  9. package/lib/cookie/CookieUtility.js.map +1 -1
  10. package/lib/css/CSS.js +12 -18
  11. package/lib/css/CSS.js.map +1 -1
  12. package/lib/css/CSSParser.js +29 -33
  13. package/lib/css/CSSParser.js.map +1 -1
  14. package/lib/css/CSSRule.js +24 -29
  15. package/lib/css/CSSRule.js.map +1 -1
  16. package/lib/css/CSSStyleDeclaration.js +4516 -6005
  17. package/lib/css/CSSStyleDeclaration.js.map +1 -1
  18. package/lib/css/CSSStyleSheet.js +17 -59
  19. package/lib/css/CSSStyleSheet.js.map +1 -1
  20. package/lib/css/CSSUnitValue.js +4 -5
  21. package/lib/css/CSSUnitValue.js.map +1 -1
  22. package/lib/css/MediaList.js +23 -28
  23. package/lib/css/MediaList.js.map +1 -1
  24. package/lib/css/rules/CSSFontFaceRule.js +6 -24
  25. package/lib/css/rules/CSSFontFaceRule.js.map +1 -1
  26. package/lib/css/rules/CSSKeyframeRule.js +14 -36
  27. package/lib/css/rules/CSSKeyframeRule.js.map +1 -1
  28. package/lib/css/rules/CSSKeyframesRule.js +31 -54
  29. package/lib/css/rules/CSSKeyframesRule.js.map +1 -1
  30. package/lib/css/rules/CSSMediaRule.js +29 -56
  31. package/lib/css/rules/CSSMediaRule.js.map +1 -1
  32. package/lib/css/rules/CSSStyleRule.js +16 -38
  33. package/lib/css/rules/CSSStyleRule.js.map +1 -1
  34. package/lib/custom-element/CustomElementRegistry.js +21 -24
  35. package/lib/custom-element/CustomElementRegistry.js.map +1 -1
  36. package/lib/dom-implementation/DOMImplementation.js +12 -13
  37. package/lib/dom-implementation/DOMImplementation.js.map +1 -1
  38. package/lib/dom-parser/DOMParser.js +29 -35
  39. package/lib/dom-parser/DOMParser.js.map +1 -1
  40. package/lib/dom-token-list/DOMTokenList.js +64 -79
  41. package/lib/dom-token-list/DOMTokenList.js.map +1 -1
  42. package/lib/event/DataTransfer.js +4 -5
  43. package/lib/event/DataTransfer.js.map +1 -1
  44. package/lib/event/DataTransferItem.js +7 -8
  45. package/lib/event/DataTransferItem.js.map +1 -1
  46. package/lib/event/DataTransferItemList.js +10 -11
  47. package/lib/event/DataTransferItemList.js.map +1 -1
  48. package/lib/event/Event.js +11 -15
  49. package/lib/event/Event.js.map +1 -1
  50. package/lib/event/EventTarget.js +14 -16
  51. package/lib/event/EventTarget.js.map +1 -1
  52. package/lib/event/IUIEventInit.d.ts +2 -2
  53. package/lib/event/UIEvent.d.ts +2 -2
  54. package/lib/event/UIEvent.js +25 -46
  55. package/lib/event/UIEvent.js.map +1 -1
  56. package/lib/event/events/AnimationEvent.js +11 -29
  57. package/lib/event/events/AnimationEvent.js.map +1 -1
  58. package/lib/event/events/CustomEvent.js +9 -31
  59. package/lib/event/events/CustomEvent.js.map +1 -1
  60. package/lib/event/events/ErrorEvent.js +15 -34
  61. package/lib/event/events/ErrorEvent.js.map +1 -1
  62. package/lib/event/events/FocusEvent.js +7 -26
  63. package/lib/event/events/FocusEvent.js.map +1 -1
  64. package/lib/event/events/InputEvent.js +13 -32
  65. package/lib/event/events/InputEvent.js.map +1 -1
  66. package/lib/event/events/KeyboardEvent.js +27 -46
  67. package/lib/event/events/KeyboardEvent.js.map +1 -1
  68. package/lib/event/events/MouseEvent.js +33 -52
  69. package/lib/event/events/MouseEvent.js.map +1 -1
  70. package/lib/event/events/PointerEvent.js +25 -44
  71. package/lib/event/events/PointerEvent.js.map +1 -1
  72. package/lib/event/events/ProgressEvent.js +11 -30
  73. package/lib/event/events/ProgressEvent.js.map +1 -1
  74. package/lib/event/events/StorageEvent.js +13 -32
  75. package/lib/event/events/StorageEvent.js.map +1 -1
  76. package/lib/event/events/WheelEvent.js +16 -35
  77. package/lib/event/events/WheelEvent.js.map +1 -1
  78. package/lib/exception/DOMException.js +5 -24
  79. package/lib/exception/DOMException.js.map +1 -1
  80. package/lib/fetch/FetchHandler.js +18 -22
  81. package/lib/fetch/FetchHandler.js.map +1 -1
  82. package/lib/fetch/Headers.js +3 -23
  83. package/lib/fetch/Headers.js.map +1 -1
  84. package/lib/fetch/Request.js +61 -81
  85. package/lib/fetch/Request.js.map +1 -1
  86. package/lib/fetch/ResourceFetchHandler.js +18 -67
  87. package/lib/fetch/ResourceFetchHandler.js.map +1 -1
  88. package/lib/fetch/Response.js +61 -81
  89. package/lib/fetch/Response.js.map +1 -1
  90. package/lib/file/Blob.js +29 -78
  91. package/lib/file/Blob.js.map +1 -1
  92. package/lib/file/File.js +9 -27
  93. package/lib/file/File.js.map +1 -1
  94. package/lib/file/FileReader.js +57 -78
  95. package/lib/file/FileReader.js.map +1 -1
  96. package/lib/history/History.js +32 -37
  97. package/lib/history/History.js.map +1 -1
  98. package/lib/index.d.ts +3 -3
  99. package/lib/index.js +69 -69
  100. package/lib/index.js.map +1 -1
  101. package/lib/location/Location.js +11 -28
  102. package/lib/location/Location.js.map +1 -1
  103. package/lib/location/RelativeURL.js +5 -8
  104. package/lib/location/RelativeURL.js.map +1 -1
  105. package/lib/location/URL.js +46 -59
  106. package/lib/location/URL.js.map +1 -1
  107. package/lib/match-media/MediaQueryList.js +28 -54
  108. package/lib/match-media/MediaQueryList.js.map +1 -1
  109. package/lib/mutation-observer/MutationListener.js +3 -4
  110. package/lib/mutation-observer/MutationListener.js.map +1 -1
  111. package/lib/mutation-observer/MutationObserver.js +12 -13
  112. package/lib/mutation-observer/MutationObserver.js.map +1 -1
  113. package/lib/mutation-observer/MutationRecord.js +3 -4
  114. package/lib/mutation-observer/MutationRecord.js.map +1 -1
  115. package/lib/navigator/MimeType.js +5 -6
  116. package/lib/navigator/MimeType.js.map +1 -1
  117. package/lib/navigator/MimeTypeArray.js +10 -11
  118. package/lib/navigator/MimeTypeArray.js.map +1 -1
  119. package/lib/navigator/Navigator.js +7 -8
  120. package/lib/navigator/Navigator.js.map +1 -1
  121. package/lib/navigator/Plugin.js +10 -11
  122. package/lib/navigator/Plugin.js.map +1 -1
  123. package/lib/navigator/PluginArray.js +12 -13
  124. package/lib/navigator/PluginArray.js.map +1 -1
  125. package/lib/nodes/character-data/CharacterData.js +119 -184
  126. package/lib/nodes/character-data/CharacterData.js.map +1 -1
  127. package/lib/nodes/character-data/CharacterDataUtility.js +12 -15
  128. package/lib/nodes/character-data/CharacterDataUtility.js.map +1 -1
  129. package/lib/nodes/child-node/ChildNodeUtility.js +24 -45
  130. package/lib/nodes/child-node/ChildNodeUtility.js.map +1 -1
  131. package/lib/nodes/child-node/NonDocumentChildNodeUtility.js +9 -12
  132. package/lib/nodes/child-node/NonDocumentChildNodeUtility.js.map +1 -1
  133. package/lib/nodes/comment/Comment.js +20 -43
  134. package/lib/nodes/comment/Comment.js.map +1 -1
  135. package/lib/nodes/document/Document.d.ts +3 -3
  136. package/lib/nodes/document/Document.js +334 -461
  137. package/lib/nodes/document/Document.js.map +1 -1
  138. package/lib/nodes/document/DocumentReadyStateManager.js +16 -19
  139. package/lib/nodes/document/DocumentReadyStateManager.js.map +1 -1
  140. package/lib/nodes/document/IDocument.d.ts +2 -2
  141. package/lib/nodes/document-fragment/DocumentFragment.js +93 -153
  142. package/lib/nodes/document-fragment/DocumentFragment.js.map +1 -1
  143. package/lib/nodes/document-type/DocumentType.js +22 -45
  144. package/lib/nodes/document-type/DocumentType.js.map +1 -1
  145. package/lib/nodes/element/DOMRect.js +3 -4
  146. package/lib/nodes/element/DOMRect.js.map +1 -1
  147. package/lib/nodes/element/Element.js +367 -496
  148. package/lib/nodes/element/Element.js.map +1 -1
  149. package/lib/nodes/element/HTMLCollection.js +4 -24
  150. package/lib/nodes/element/HTMLCollection.js.map +1 -1
  151. package/lib/nodes/element/HTMLCollectionFactory.js +6 -9
  152. package/lib/nodes/element/HTMLCollectionFactory.js.map +1 -1
  153. package/lib/nodes/element/Range.js +89 -114
  154. package/lib/nodes/element/Range.js.map +1 -1
  155. package/lib/nodes/html-base-element/HTMLBaseElement.js +41 -70
  156. package/lib/nodes/html-base-element/HTMLBaseElement.js.map +1 -1
  157. package/lib/nodes/html-document/HTMLDocument.js +3 -23
  158. package/lib/nodes/html-document/HTMLDocument.js.map +1 -1
  159. package/lib/nodes/html-element/DatasetUtility.js +9 -12
  160. package/lib/nodes/html-element/DatasetUtility.js.map +1 -1
  161. package/lib/nodes/html-element/HTMLElement.js +232 -290
  162. package/lib/nodes/html-element/HTMLElement.js.map +1 -1
  163. package/lib/nodes/html-form-element/HTMLFormElement.js +170 -235
  164. package/lib/nodes/html-form-element/HTMLFormElement.js.map +1 -1
  165. package/lib/nodes/html-image-element/HTMLImageElement.js +178 -237
  166. package/lib/nodes/html-image-element/HTMLImageElement.js.map +1 -1
  167. package/lib/nodes/html-image-element/Image.js +7 -27
  168. package/lib/nodes/html-image-element/Image.js.map +1 -1
  169. package/lib/nodes/html-input-element/HTMLInputElement.js +705 -872
  170. package/lib/nodes/html-input-element/HTMLInputElement.js.map +1 -1
  171. package/lib/nodes/html-input-element/HTMLInputElementValueSanitizer.js +9 -12
  172. package/lib/nodes/html-input-element/HTMLInputElementValueSanitizer.js.map +1 -1
  173. package/lib/nodes/html-input-element/HTMLInputElementValueStepping.js +5 -8
  174. package/lib/nodes/html-input-element/HTMLInputElementValueStepping.js.map +1 -1
  175. package/lib/nodes/html-input-element/ValidityState.js +47 -69
  176. package/lib/nodes/html-input-element/ValidityState.js.map +1 -1
  177. package/lib/nodes/html-label-element/HTMLLabelElement.js +53 -87
  178. package/lib/nodes/html-label-element/HTMLLabelElement.js.map +1 -1
  179. package/lib/nodes/html-link-element/HTMLLinkElement.js +197 -252
  180. package/lib/nodes/html-link-element/HTMLLinkElement.js.map +1 -1
  181. package/lib/nodes/html-meta-element/HTMLMetaElement.js +66 -102
  182. package/lib/nodes/html-meta-element/HTMLMetaElement.js.map +1 -1
  183. package/lib/nodes/html-script-element/HTMLScriptElement.js +145 -193
  184. package/lib/nodes/html-script-element/HTMLScriptElement.js.map +1 -1
  185. package/lib/nodes/html-script-element/ScriptUtility.js +58 -112
  186. package/lib/nodes/html-script-element/ScriptUtility.js.map +1 -1
  187. package/lib/nodes/html-slot-element/HTMLSlotElement.js +33 -65
  188. package/lib/nodes/html-slot-element/HTMLSlotElement.js.map +1 -1
  189. package/lib/nodes/html-style-element/HTMLStyleElement.js +75 -109
  190. package/lib/nodes/html-style-element/HTMLStyleElement.js.map +1 -1
  191. package/lib/nodes/html-template-element/HTMLTemplateElement.js +60 -99
  192. package/lib/nodes/html-template-element/HTMLTemplateElement.js.map +1 -1
  193. package/lib/nodes/html-text-area-element/HTMLTextAreaElement.js +349 -444
  194. package/lib/nodes/html-text-area-element/HTMLTextAreaElement.js.map +1 -1
  195. package/lib/nodes/html-unknown-element/HTMLUnknownElement.js +17 -37
  196. package/lib/nodes/html-unknown-element/HTMLUnknownElement.js.map +1 -1
  197. package/lib/nodes/node/Node.js +193 -260
  198. package/lib/nodes/node/Node.js.map +1 -1
  199. package/lib/nodes/node/NodeList.js +4 -24
  200. package/lib/nodes/node/NodeList.js.map +1 -1
  201. package/lib/nodes/node/NodeListFactory.js +6 -9
  202. package/lib/nodes/node/NodeListFactory.js.map +1 -1
  203. package/lib/nodes/parent-node/ParentNodeUtility.js +43 -78
  204. package/lib/nodes/parent-node/ParentNodeUtility.js.map +1 -1
  205. package/lib/nodes/shadow-root/ShadowRoot.js +53 -83
  206. package/lib/nodes/shadow-root/ShadowRoot.js.map +1 -1
  207. package/lib/nodes/svg-document/SVGDocument.js +3 -23
  208. package/lib/nodes/svg-document/SVGDocument.js.map +1 -1
  209. package/lib/nodes/svg-element/DOMMatrix.js +3 -4
  210. package/lib/nodes/svg-element/DOMMatrix.js.map +1 -1
  211. package/lib/nodes/svg-element/SVGAngle.js +10 -11
  212. package/lib/nodes/svg-element/SVGAngle.js.map +1 -1
  213. package/lib/nodes/svg-element/SVGAnimatedRect.js +4 -5
  214. package/lib/nodes/svg-element/SVGAnimatedRect.js.map +1 -1
  215. package/lib/nodes/svg-element/SVGElement.js +58 -93
  216. package/lib/nodes/svg-element/SVGElement.js.map +1 -1
  217. package/lib/nodes/svg-element/SVGGraphicsElement.js +14 -32
  218. package/lib/nodes/svg-element/SVGGraphicsElement.js.map +1 -1
  219. package/lib/nodes/svg-element/SVGLength.js +16 -17
  220. package/lib/nodes/svg-element/SVGLength.js.map +1 -1
  221. package/lib/nodes/svg-element/SVGNumber.js +3 -4
  222. package/lib/nodes/svg-element/SVGNumber.js.map +1 -1
  223. package/lib/nodes/svg-element/SVGPoint.js +3 -4
  224. package/lib/nodes/svg-element/SVGPoint.js.map +1 -1
  225. package/lib/nodes/svg-element/SVGRect.js +3 -4
  226. package/lib/nodes/svg-element/SVGRect.js.map +1 -1
  227. package/lib/nodes/svg-element/SVGSVGElement.js +187 -248
  228. package/lib/nodes/svg-element/SVGSVGElement.js.map +1 -1
  229. package/lib/nodes/svg-element/SVGTransform.js +16 -17
  230. package/lib/nodes/svg-element/SVGTransform.js.map +1 -1
  231. package/lib/nodes/text/Text.js +20 -43
  232. package/lib/nodes/text/Text.js.map +1 -1
  233. package/lib/nodes/xml-document/XMLDocument.js +3 -23
  234. package/lib/nodes/xml-document/XMLDocument.js.map +1 -1
  235. package/lib/query-selector/QuerySelector.js +36 -44
  236. package/lib/query-selector/QuerySelector.js.map +1 -1
  237. package/lib/query-selector/SelectorItem.js +62 -66
  238. package/lib/query-selector/SelectorItem.js.map +1 -1
  239. package/lib/resize-observer/ResizeObserver.js +8 -11
  240. package/lib/resize-observer/ResizeObserver.js.map +1 -1
  241. package/lib/screen/Screen.js +3 -4
  242. package/lib/screen/Screen.js.map +1 -1
  243. package/lib/selection/Selection.js +29 -30
  244. package/lib/selection/Selection.js.map +1 -1
  245. package/lib/storage/Storage.js +22 -27
  246. package/lib/storage/Storage.js.map +1 -1
  247. package/lib/tree-walker/NodeFilterMask.js +1 -1
  248. package/lib/tree-walker/NodeFilterMask.js.map +1 -1
  249. package/lib/tree-walker/TreeWalker.js +30 -33
  250. package/lib/tree-walker/TreeWalker.js.map +1 -1
  251. package/lib/window/GlobalWindow.d.ts +84 -0
  252. package/lib/window/GlobalWindow.js +90 -0
  253. package/lib/window/GlobalWindow.js.map +1 -0
  254. package/lib/window/IWindow.d.ts +29 -18
  255. package/lib/window/VMGlobalPropertyScript.d.ts +2 -0
  256. package/lib/window/VMGlobalPropertyScript.js +65 -0
  257. package/lib/window/VMGlobalPropertyScript.js.map +1 -0
  258. package/lib/window/Window.d.ts +70 -105
  259. package/lib/window/Window.js +269 -491
  260. package/lib/window/Window.js.map +1 -1
  261. package/lib/xml-parser/XMLParser.js +65 -71
  262. package/lib/xml-parser/XMLParser.js.map +1 -1
  263. package/lib/xml-serializer/XMLSerializer.js +30 -37
  264. package/lib/xml-serializer/XMLSerializer.js.map +1 -1
  265. package/package.json +6 -7
  266. package/src/dom-parser/DOMParser.ts +4 -5
  267. package/src/event/IUIEventInit.ts +2 -2
  268. package/src/event/UIEvent.ts +2 -2
  269. package/src/fetch/FetchHandler.ts +3 -3
  270. package/src/fetch/ResourceFetchHandler.ts +3 -3
  271. package/src/index.ts +3 -3
  272. package/src/nodes/document/Document.ts +4 -4
  273. package/src/nodes/document/IDocument.ts +2 -2
  274. package/src/nodes/html-link-element/HTMLLinkElement.ts +8 -2
  275. package/src/nodes/html-script-element/ScriptUtility.ts +4 -4
  276. package/src/window/GlobalWindow.ts +82 -0
  277. package/src/window/IWindow.ts +24 -12
  278. package/src/window/VMGlobalPropertyScript.ts +62 -0
  279. package/src/window/Window.ts +104 -173
  280. package/tsconfig.json +1 -1
  281. package/lib/window/AsyncWindow.d.ts +0 -10
  282. package/lib/window/AsyncWindow.js +0 -38
  283. package/lib/window/AsyncWindow.js.map +0 -1
  284. package/src/window/AsyncWindow.ts +0 -17
@@ -1,412 +1,302 @@
1
1
  "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
18
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
19
- if (ar || !(i in from)) {
20
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
21
- ar[i] = from[i];
22
- }
23
- }
24
- return to.concat(ar || Array.prototype.slice.call(from));
25
- };
26
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
27
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
28
4
  };
29
5
  Object.defineProperty(exports, "__esModule", { value: true });
30
- var HTMLUnknownElement_1 = __importDefault(require("../html-unknown-element/HTMLUnknownElement"));
31
- var Text_1 = __importDefault(require("../text/Text"));
32
- var Comment_1 = __importDefault(require("../comment/Comment"));
33
- var Node_1 = __importDefault(require("../node/Node"));
34
- var TreeWalker_1 = __importDefault(require("../../tree-walker/TreeWalker"));
35
- var DocumentFragment_1 = __importDefault(require("../document-fragment/DocumentFragment"));
36
- var XMLParser_1 = __importDefault(require("../../xml-parser/XMLParser"));
37
- var Event_1 = __importDefault(require("../../event/Event"));
38
- var DOMImplementation_1 = __importDefault(require("../../dom-implementation/DOMImplementation"));
39
- var ElementTag_1 = __importDefault(require("../../config/ElementTag"));
40
- var Attr_1 = __importDefault(require("../../attribute/Attr"));
41
- var NamespaceURI_1 = __importDefault(require("../../config/NamespaceURI"));
42
- var DocumentType_1 = __importDefault(require("../document-type/DocumentType"));
43
- var ParentNodeUtility_1 = __importDefault(require("../parent-node/ParentNodeUtility"));
44
- var QuerySelector_1 = __importDefault(require("../../query-selector/QuerySelector"));
45
- var DOMException_1 = __importDefault(require("../../exception/DOMException"));
46
- var CookieUtility_1 = __importDefault(require("../../cookie/CookieUtility"));
47
- var HTMLCollectionFactory_1 = __importDefault(require("../element/HTMLCollectionFactory"));
48
- var DocumentReadyStateEnum_1 = __importDefault(require("./DocumentReadyStateEnum"));
49
- var DocumentReadyStateManager_1 = __importDefault(require("./DocumentReadyStateManager"));
50
- var Selection_1 = __importDefault(require("../../selection/Selection"));
6
+ const HTMLUnknownElement_1 = __importDefault(require("../html-unknown-element/HTMLUnknownElement"));
7
+ const Text_1 = __importDefault(require("../text/Text"));
8
+ const Comment_1 = __importDefault(require("../comment/Comment"));
9
+ const Node_1 = __importDefault(require("../node/Node"));
10
+ const TreeWalker_1 = __importDefault(require("../../tree-walker/TreeWalker"));
11
+ const DocumentFragment_1 = __importDefault(require("../document-fragment/DocumentFragment"));
12
+ const XMLParser_1 = __importDefault(require("../../xml-parser/XMLParser"));
13
+ const Event_1 = __importDefault(require("../../event/Event"));
14
+ const DOMImplementation_1 = __importDefault(require("../../dom-implementation/DOMImplementation"));
15
+ const ElementTag_1 = __importDefault(require("../../config/ElementTag"));
16
+ const Attr_1 = __importDefault(require("../../attribute/Attr"));
17
+ const NamespaceURI_1 = __importDefault(require("../../config/NamespaceURI"));
18
+ const DocumentType_1 = __importDefault(require("../document-type/DocumentType"));
19
+ const ParentNodeUtility_1 = __importDefault(require("../parent-node/ParentNodeUtility"));
20
+ const QuerySelector_1 = __importDefault(require("../../query-selector/QuerySelector"));
21
+ const DOMException_1 = __importDefault(require("../../exception/DOMException"));
22
+ const CookieUtility_1 = __importDefault(require("../../cookie/CookieUtility"));
23
+ const HTMLCollectionFactory_1 = __importDefault(require("../element/HTMLCollectionFactory"));
24
+ const DocumentReadyStateEnum_1 = __importDefault(require("./DocumentReadyStateEnum"));
25
+ const DocumentReadyStateManager_1 = __importDefault(require("./DocumentReadyStateManager"));
26
+ const Selection_1 = __importDefault(require("../../selection/Selection"));
51
27
  /**
52
28
  * Document.
53
29
  */
54
- var Document = /** @class */ (function (_super) {
55
- __extends(Document, _super);
30
+ class Document extends Node_1.default {
56
31
  /**
57
32
  * Creates an instance of Document.
58
33
  */
59
- function Document() {
60
- var _this = _super.call(this) || this;
61
- _this.onreadystatechange = null;
62
- _this.nodeType = Node_1.default.DOCUMENT_NODE;
63
- _this.adoptedStyleSheets = [];
64
- _this.children = HTMLCollectionFactory_1.default.create();
65
- _this.readyState = DocumentReadyStateEnum_1.default.interactive;
66
- _this.isConnected = true;
67
- _this._readyStateManager = null;
68
- _this._activeElement = null;
69
- _this._isFirstWrite = true;
70
- _this._isFirstWriteAfterOpen = false;
71
- _this._defaultView = null;
72
- _this._cookie = '';
73
- _this.implementation = new DOMImplementation_1.default();
74
- _this.implementation._ownerDocument = _this;
75
- var doctype = _this.implementation.createDocumentType('html', '', '');
76
- var documentElement = _this.createElement('html');
77
- var bodyElement = _this.createElement('body');
78
- var headElement = _this.createElement('head');
79
- _this.appendChild(doctype);
80
- _this.appendChild(documentElement);
34
+ constructor() {
35
+ super();
36
+ this.onreadystatechange = null;
37
+ this.nodeType = Node_1.default.DOCUMENT_NODE;
38
+ this.adoptedStyleSheets = [];
39
+ this.children = HTMLCollectionFactory_1.default.create();
40
+ this.readyState = DocumentReadyStateEnum_1.default.interactive;
41
+ this.isConnected = true;
42
+ this._readyStateManager = null;
43
+ this._activeElement = null;
44
+ this._isFirstWrite = true;
45
+ this._isFirstWriteAfterOpen = false;
46
+ this._defaultView = null;
47
+ this._cookie = '';
48
+ this.implementation = new DOMImplementation_1.default();
49
+ this.implementation._ownerDocument = this;
50
+ const doctype = this.implementation.createDocumentType('html', '', '');
51
+ const documentElement = this.createElement('html');
52
+ const bodyElement = this.createElement('body');
53
+ const headElement = this.createElement('head');
54
+ this.appendChild(doctype);
55
+ this.appendChild(documentElement);
81
56
  documentElement.appendChild(headElement);
82
57
  documentElement.appendChild(bodyElement);
83
- return _this;
84
- }
85
- Object.defineProperty(Document.prototype, "charset", {
86
- /**
87
- * Returns character set.
88
- *
89
- * @deprecated
90
- * @returns Character set.
91
- */
92
- get: function () {
93
- return this.characterSet;
94
- },
95
- enumerable: false,
96
- configurable: true
97
- });
98
- Object.defineProperty(Document.prototype, "characterSet", {
99
- /**
100
- * Returns character set.
101
- *
102
- * @returns Character set.
103
- */
104
- get: function () {
105
- var _a;
106
- var charset = (_a = this.querySelector('meta[charset]')) === null || _a === void 0 ? void 0 : _a.getAttributeNS(null, 'charset');
107
- return charset ? charset : 'UTF-8';
108
- },
109
- enumerable: false,
110
- configurable: true
111
- });
112
- Object.defineProperty(Document.prototype, "defaultView", {
113
- /**
114
- * Returns default view.
115
- *
116
- * @returns Default view.
117
- */
118
- get: function () {
119
- return this._defaultView;
120
- },
121
- /**
122
- * Sets a default view.
123
- *
124
- * @param defaultView Default view.
125
- */
126
- set: function (defaultView) {
127
- var _this = this;
128
- this._defaultView = defaultView;
129
- this._readyStateManager = new DocumentReadyStateManager_1.default(defaultView);
130
- this._readyStateManager.whenComplete().then(function () {
131
- _this.readyState = DocumentReadyStateEnum_1.default.complete;
132
- _this.dispatchEvent(new Event_1.default('readystatechange'));
133
- });
134
- },
135
- enumerable: false,
136
- configurable: true
137
- });
138
- Object.defineProperty(Document.prototype, "childElementCount", {
139
- /**
140
- * Last element child.
141
- *
142
- * @returns Element.
143
- */
144
- get: function () {
145
- return this.children.length;
146
- },
147
- enumerable: false,
148
- configurable: true
149
- });
150
- Object.defineProperty(Document.prototype, "firstElementChild", {
151
- /**
152
- * First element child.
153
- *
154
- * @returns Element.
155
- */
156
- get: function () {
157
- return this.children ? this.children[0] || null : null;
158
- },
159
- enumerable: false,
160
- configurable: true
161
- });
162
- Object.defineProperty(Document.prototype, "lastElementChild", {
163
- /**
164
- * Last element child.
165
- *
166
- * @returns Element.
167
- */
168
- get: function () {
169
- return this.children ? this.children[this.children.length - 1] || null : null;
170
- },
171
- enumerable: false,
172
- configurable: true
173
- });
174
- Object.defineProperty(Document.prototype, "cookie", {
175
- /**
176
- * Returns cookie string.
177
- *
178
- * @returns Cookie.
179
- */
180
- get: function () {
181
- return this._cookie;
182
- },
183
- /**
184
- * Sets a cookie string.
185
- *
186
- * @param cookie Cookie string.
187
- */
188
- set: function (cookie) {
189
- this._cookie = CookieUtility_1.default.getCookieString(this.defaultView.location, this._cookie, cookie);
190
- },
191
- enumerable: false,
192
- configurable: true
193
- });
194
- Object.defineProperty(Document.prototype, "nodeName", {
195
- /**
196
- * Node name.
197
- *
198
- * @returns Node name.
199
- */
200
- get: function () {
201
- return '#document';
202
- },
203
- enumerable: false,
204
- configurable: true
205
- });
206
- Object.defineProperty(Document.prototype, "documentElement", {
207
- /**
208
- * Returns <html> element.
209
- *
210
- * @returns Element.
211
- */
212
- get: function () {
213
- return ParentNodeUtility_1.default.getElementByTagName(this, 'html');
214
- },
215
- enumerable: false,
216
- configurable: true
217
- });
218
- Object.defineProperty(Document.prototype, "doctype", {
219
- /**
220
- * Returns document type element.
221
- *
222
- * @returns Document type.
223
- */
224
- get: function () {
225
- for (var _i = 0, _a = this.childNodes; _i < _a.length; _i++) {
226
- var node = _a[_i];
227
- if (node instanceof DocumentType_1.default) {
228
- return node;
229
- }
58
+ }
59
+ /**
60
+ * Returns character set.
61
+ *
62
+ * @deprecated
63
+ * @returns Character set.
64
+ */
65
+ get charset() {
66
+ return this.characterSet;
67
+ }
68
+ /**
69
+ * Returns character set.
70
+ *
71
+ * @returns Character set.
72
+ */
73
+ get characterSet() {
74
+ const charset = this.querySelector('meta[charset]')?.getAttributeNS(null, 'charset');
75
+ return charset ? charset : 'UTF-8';
76
+ }
77
+ /**
78
+ * Returns default view.
79
+ *
80
+ * @returns Default view.
81
+ */
82
+ get defaultView() {
83
+ return this._defaultView;
84
+ }
85
+ /**
86
+ * Sets a default view.
87
+ *
88
+ * @param defaultView Default view.
89
+ */
90
+ set defaultView(defaultView) {
91
+ this._defaultView = defaultView;
92
+ this._readyStateManager = new DocumentReadyStateManager_1.default(defaultView);
93
+ this._readyStateManager.whenComplete().then(() => {
94
+ this.readyState = DocumentReadyStateEnum_1.default.complete;
95
+ this.dispatchEvent(new Event_1.default('readystatechange'));
96
+ });
97
+ }
98
+ /**
99
+ * Last element child.
100
+ *
101
+ * @returns Element.
102
+ */
103
+ get childElementCount() {
104
+ return this.children.length;
105
+ }
106
+ /**
107
+ * First element child.
108
+ *
109
+ * @returns Element.
110
+ */
111
+ get firstElementChild() {
112
+ return this.children ? this.children[0] || null : null;
113
+ }
114
+ /**
115
+ * Last element child.
116
+ *
117
+ * @returns Element.
118
+ */
119
+ get lastElementChild() {
120
+ return this.children ? this.children[this.children.length - 1] || null : null;
121
+ }
122
+ /**
123
+ * Returns cookie string.
124
+ *
125
+ * @returns Cookie.
126
+ */
127
+ get cookie() {
128
+ return this._cookie;
129
+ }
130
+ /**
131
+ * Sets a cookie string.
132
+ *
133
+ * @param cookie Cookie string.
134
+ */
135
+ set cookie(cookie) {
136
+ this._cookie = CookieUtility_1.default.getCookieString(this.defaultView.location, this._cookie, cookie);
137
+ }
138
+ /**
139
+ * Node name.
140
+ *
141
+ * @returns Node name.
142
+ */
143
+ get nodeName() {
144
+ return '#document';
145
+ }
146
+ /**
147
+ * Returns <html> element.
148
+ *
149
+ * @returns Element.
150
+ */
151
+ get documentElement() {
152
+ return ParentNodeUtility_1.default.getElementByTagName(this, 'html');
153
+ }
154
+ /**
155
+ * Returns document type element.
156
+ *
157
+ * @returns Document type.
158
+ */
159
+ get doctype() {
160
+ for (const node of this.childNodes) {
161
+ if (node instanceof DocumentType_1.default) {
162
+ return node;
230
163
  }
231
- return null;
232
- },
233
- enumerable: false,
234
- configurable: true
235
- });
236
- Object.defineProperty(Document.prototype, "body", {
237
- /**
238
- * Returns <body> element.
239
- *
240
- * @returns Element.
241
- */
242
- get: function () {
243
- return ParentNodeUtility_1.default.getElementByTagName(this, 'body');
244
- },
245
- enumerable: false,
246
- configurable: true
247
- });
248
- Object.defineProperty(Document.prototype, "head", {
249
- /**
250
- * Returns <head> element.
251
- *
252
- * @returns Element.
253
- */
254
- get: function () {
255
- return ParentNodeUtility_1.default.getElementByTagName(this, 'head');
256
- },
257
- enumerable: false,
258
- configurable: true
259
- });
260
- Object.defineProperty(Document.prototype, "styleSheets", {
261
- /**
262
- * Returns CSS style sheets.
263
- *
264
- * @returns CSS style sheets.
265
- */
266
- get: function () {
267
- var styles = (this.querySelectorAll('link[rel="stylesheet"][href],style'));
268
- var styleSheets = [];
269
- for (var _i = 0, styles_1 = styles; _i < styles_1.length; _i++) {
270
- var style = styles_1[_i];
271
- var sheet = style.sheet;
272
- if (sheet) {
273
- styleSheets.push(sheet);
274
- }
164
+ }
165
+ return null;
166
+ }
167
+ /**
168
+ * Returns <body> element.
169
+ *
170
+ * @returns Element.
171
+ */
172
+ get body() {
173
+ return ParentNodeUtility_1.default.getElementByTagName(this, 'body');
174
+ }
175
+ /**
176
+ * Returns <head> element.
177
+ *
178
+ * @returns Element.
179
+ */
180
+ get head() {
181
+ return ParentNodeUtility_1.default.getElementByTagName(this, 'head');
182
+ }
183
+ /**
184
+ * Returns CSS style sheets.
185
+ *
186
+ * @returns CSS style sheets.
187
+ */
188
+ get styleSheets() {
189
+ const styles = (this.querySelectorAll('link[rel="stylesheet"][href],style'));
190
+ const styleSheets = [];
191
+ for (const style of styles) {
192
+ const sheet = style.sheet;
193
+ if (sheet) {
194
+ styleSheets.push(sheet);
275
195
  }
276
- return styleSheets;
277
- },
278
- enumerable: false,
279
- configurable: true
280
- });
281
- Object.defineProperty(Document.prototype, "activeElement", {
282
- /**
283
- * Returns active element.
284
- *
285
- * @returns Active element.
286
- */
287
- get: function () {
288
- if (this._activeElement) {
289
- var rootNode = (this._activeElement.getRootNode());
290
- var activeElement = this._activeElement;
291
- while (rootNode !== this) {
292
- activeElement = rootNode.host;
293
- rootNode = activeElement.getRootNode();
294
- }
295
- return activeElement;
196
+ }
197
+ return styleSheets;
198
+ }
199
+ /**
200
+ * Returns active element.
201
+ *
202
+ * @returns Active element.
203
+ */
204
+ get activeElement() {
205
+ if (this._activeElement) {
206
+ let rootNode = (this._activeElement.getRootNode());
207
+ let activeElement = this._activeElement;
208
+ while (rootNode !== this) {
209
+ activeElement = rootNode.host;
210
+ rootNode = activeElement.getRootNode();
296
211
  }
297
- return this._activeElement || this.body || this.documentElement || null;
298
- },
299
- enumerable: false,
300
- configurable: true
301
- });
302
- Object.defineProperty(Document.prototype, "scrollingElement", {
303
- /**
304
- * Returns scrolling element.
305
- *
306
- * @returns Scrolling element.
307
- */
308
- get: function () {
309
- return this.documentElement;
310
- },
311
- enumerable: false,
312
- configurable: true
313
- });
314
- Object.defineProperty(Document.prototype, "location", {
315
- /**
316
- * Returns location.
317
- *
318
- * @returns Location.
319
- */
320
- get: function () {
321
- return this._defaultView.location;
322
- },
323
- enumerable: false,
324
- configurable: true
325
- });
326
- Object.defineProperty(Document.prototype, "scripts", {
327
- /**
328
- * Returns scripts.
329
- *
330
- * @returns Scripts.
331
- */
332
- get: function () {
333
- return this.getElementsByTagName('script');
334
- },
335
- enumerable: false,
336
- configurable: true
337
- });
212
+ return activeElement;
213
+ }
214
+ return this._activeElement || this.body || this.documentElement || null;
215
+ }
216
+ /**
217
+ * Returns scrolling element.
218
+ *
219
+ * @returns Scrolling element.
220
+ */
221
+ get scrollingElement() {
222
+ return this.documentElement;
223
+ }
224
+ /**
225
+ * Returns location.
226
+ *
227
+ * @returns Location.
228
+ */
229
+ get location() {
230
+ return this._defaultView.location;
231
+ }
232
+ /**
233
+ * Returns scripts.
234
+ *
235
+ * @returns Scripts.
236
+ */
237
+ get scripts() {
238
+ return this.getElementsByTagName('script');
239
+ }
338
240
  /**
339
241
  * Inserts a set of Node objects or DOMString objects after the last child of the ParentNode. DOMString objects are inserted as equivalent Text nodes.
340
242
  *
341
243
  * @param nodes List of Node or DOMString.
342
244
  */
343
- Document.prototype.append = function () {
344
- var nodes = [];
345
- for (var _i = 0; _i < arguments.length; _i++) {
346
- nodes[_i] = arguments[_i];
347
- }
348
- ParentNodeUtility_1.default.append.apply(ParentNodeUtility_1.default, __spreadArray([this], nodes, false));
349
- };
245
+ append(...nodes) {
246
+ ParentNodeUtility_1.default.append(this, ...nodes);
247
+ }
350
248
  /**
351
249
  * Inserts a set of Node objects or DOMString objects before the first child of the ParentNode. DOMString objects are inserted as equivalent Text nodes.
352
250
  *
353
251
  * @param nodes List of Node or DOMString.
354
252
  */
355
- Document.prototype.prepend = function () {
356
- var nodes = [];
357
- for (var _i = 0; _i < arguments.length; _i++) {
358
- nodes[_i] = arguments[_i];
359
- }
360
- ParentNodeUtility_1.default.prepend.apply(ParentNodeUtility_1.default, __spreadArray([this], nodes, false));
361
- };
253
+ prepend(...nodes) {
254
+ ParentNodeUtility_1.default.prepend(this, ...nodes);
255
+ }
362
256
  /**
363
257
  * Replaces the existing children of a node with a specified new set of children.
364
258
  *
365
259
  * @param nodes List of Node or DOMString.
366
260
  */
367
- Document.prototype.replaceChildren = function () {
368
- var nodes = [];
369
- for (var _i = 0; _i < arguments.length; _i++) {
370
- nodes[_i] = arguments[_i];
371
- }
372
- ParentNodeUtility_1.default.replaceChildren.apply(ParentNodeUtility_1.default, __spreadArray([this], nodes, false));
373
- };
261
+ replaceChildren(...nodes) {
262
+ ParentNodeUtility_1.default.replaceChildren(this, ...nodes);
263
+ }
374
264
  /**
375
265
  * Query CSS selector to find matching elments.
376
266
  *
377
267
  * @param selector CSS selector.
378
268
  * @returns Matching elements.
379
269
  */
380
- Document.prototype.querySelectorAll = function (selector) {
270
+ querySelectorAll(selector) {
381
271
  return QuerySelector_1.default.querySelectorAll(this, selector);
382
- };
272
+ }
383
273
  /**
384
274
  * Query CSS Selector to find a matching element.
385
275
  *
386
276
  * @param selector CSS selector.
387
277
  * @returns Matching element.
388
278
  */
389
- Document.prototype.querySelector = function (selector) {
279
+ querySelector(selector) {
390
280
  return QuerySelector_1.default.querySelector(this, selector);
391
- };
281
+ }
392
282
  /**
393
283
  * Returns an elements by class name.
394
284
  *
395
285
  * @param className Tag name.
396
286
  * @returns Matching element.
397
287
  */
398
- Document.prototype.getElementsByClassName = function (className) {
288
+ getElementsByClassName(className) {
399
289
  return ParentNodeUtility_1.default.getElementsByClassName(this, className);
400
- };
290
+ }
401
291
  /**
402
292
  * Returns an elements by tag name.
403
293
  *
404
294
  * @param tagName Tag name.
405
295
  * @returns Matching element.
406
296
  */
407
- Document.prototype.getElementsByTagName = function (tagName) {
297
+ getElementsByTagName(tagName) {
408
298
  return ParentNodeUtility_1.default.getElementsByTagName(this, tagName);
409
- };
299
+ }
410
300
  /**
411
301
  * Returns an elements by tag name and namespace.
412
302
  *
@@ -414,41 +304,39 @@ var Document = /** @class */ (function (_super) {
414
304
  * @param tagName Tag name.
415
305
  * @returns Matching element.
416
306
  */
417
- Document.prototype.getElementsByTagNameNS = function (namespaceURI, tagName) {
307
+ getElementsByTagNameNS(namespaceURI, tagName) {
418
308
  return ParentNodeUtility_1.default.getElementsByTagNameNS(this, namespaceURI, tagName);
419
- };
309
+ }
420
310
  /**
421
311
  * Returns an element by ID.
422
312
  *
423
313
  * @param id ID.
424
314
  * @returns Matching element.
425
315
  */
426
- Document.prototype.getElementById = function (id) {
316
+ getElementById(id) {
427
317
  return ParentNodeUtility_1.default.getElementById(this, id);
428
- };
318
+ }
429
319
  /**
430
320
  * Returns an element by Name.
431
321
  *
432
322
  * @returns Matching element.
433
323
  * @param name
434
324
  */
435
- Document.prototype.getElementsByName = function (name) {
436
- var _getElementsByName = function (_parentNode, _name) {
437
- var matches = HTMLCollectionFactory_1.default.create();
438
- for (var _i = 0, _a = _parentNode.children; _i < _a.length; _i++) {
439
- var child = _a[_i];
325
+ getElementsByName(name) {
326
+ const _getElementsByName = (_parentNode, _name) => {
327
+ const matches = HTMLCollectionFactory_1.default.create();
328
+ for (const child of _parentNode.children) {
440
329
  if ((child.getAttributeNS(null, 'name') || '') === _name) {
441
330
  matches.push(child);
442
331
  }
443
- for (var _b = 0, _c = _getElementsByName(child, _name); _b < _c.length; _b++) {
444
- var match = _c[_b];
332
+ for (const match of _getElementsByName(child, _name)) {
445
333
  matches.push(match);
446
334
  }
447
335
  }
448
336
  return matches;
449
337
  };
450
338
  return _getElementsByName(this, name);
451
- };
339
+ }
452
340
  /**
453
341
  * Clones a node.
454
342
  *
@@ -456,12 +344,10 @@ var Document = /** @class */ (function (_super) {
456
344
  * @param [deep=false] "true" to clone deep.
457
345
  * @returns Cloned node.
458
346
  */
459
- Document.prototype.cloneNode = function (deep) {
460
- if (deep === void 0) { deep = false; }
461
- var clone = _super.prototype.cloneNode.call(this, deep);
347
+ cloneNode(deep = false) {
348
+ const clone = super.cloneNode(deep);
462
349
  if (deep) {
463
- for (var _i = 0, _a = clone.childNodes; _i < _a.length; _i++) {
464
- var node = _a[_i];
350
+ for (const node of clone.childNodes) {
465
351
  if (node.nodeType === Node_1.default.ELEMENT_NODE) {
466
352
  clone.children.push(node);
467
353
  }
@@ -469,7 +355,7 @@ var Document = /** @class */ (function (_super) {
469
355
  }
470
356
  clone.defaultView = this.defaultView;
471
357
  return clone;
472
- };
358
+ }
473
359
  /**
474
360
  * Append a child node to childNodes.
475
361
  *
@@ -477,12 +363,12 @@ var Document = /** @class */ (function (_super) {
477
363
  * @param node Node to append.
478
364
  * @returns Appended node.
479
365
  */
480
- Document.prototype.appendChild = function (node) {
366
+ appendChild(node) {
481
367
  // If the type is DocumentFragment, then the child nodes of if it should be moved instead of the actual node.
482
368
  // See: https://developer.mozilla.org/en-US/docs/Web/API/DocumentFragment
483
369
  if (node.nodeType !== Node_1.default.DOCUMENT_FRAGMENT_NODE) {
484
370
  if (node.parentNode && node.parentNode['children']) {
485
- var index = node.parentNode['children'].indexOf(node);
371
+ const index = node.parentNode['children'].indexOf(node);
486
372
  if (index !== -1) {
487
373
  node.parentNode['children'].splice(index, 1);
488
374
  }
@@ -491,23 +377,23 @@ var Document = /** @class */ (function (_super) {
491
377
  this.children.push(node);
492
378
  }
493
379
  }
494
- return _super.prototype.appendChild.call(this, node);
495
- };
380
+ return super.appendChild(node);
381
+ }
496
382
  /**
497
383
  * Remove Child element from childNodes array.
498
384
  *
499
385
  * @override
500
386
  * @param node Node to remove.
501
387
  */
502
- Document.prototype.removeChild = function (node) {
388
+ removeChild(node) {
503
389
  if (node.nodeType === Node_1.default.ELEMENT_NODE) {
504
- var index = this.children.indexOf(node);
390
+ const index = this.children.indexOf(node);
505
391
  if (index !== -1) {
506
392
  this.children.splice(index, 1);
507
393
  }
508
394
  }
509
- return _super.prototype.removeChild.call(this, node);
510
- };
395
+ return super.removeChild(node);
396
+ }
511
397
  /**
512
398
  * Inserts a node before another.
513
399
  *
@@ -516,34 +402,33 @@ var Document = /** @class */ (function (_super) {
516
402
  * @param [referenceNode] Node to insert before.
517
403
  * @returns Inserted node.
518
404
  */
519
- Document.prototype.insertBefore = function (newNode, referenceNode) {
520
- var returnValue = _super.prototype.insertBefore.call(this, newNode, referenceNode);
405
+ insertBefore(newNode, referenceNode) {
406
+ const returnValue = super.insertBefore(newNode, referenceNode);
521
407
  // If the type is DocumentFragment, then the child nodes of if it should be moved instead of the actual node.
522
408
  // See: https://developer.mozilla.org/en-US/docs/Web/API/DocumentFragment
523
409
  if (newNode.nodeType !== Node_1.default.DOCUMENT_FRAGMENT_NODE) {
524
410
  if (newNode.parentNode && newNode.parentNode['children']) {
525
- var index = newNode.parentNode['children'].indexOf(newNode);
411
+ const index = newNode.parentNode['children'].indexOf(newNode);
526
412
  if (index !== -1) {
527
413
  newNode.parentNode['children'].splice(index, 1);
528
414
  }
529
415
  }
530
416
  this.children.length = 0;
531
- for (var _i = 0, _a = this.childNodes; _i < _a.length; _i++) {
532
- var node = _a[_i];
417
+ for (const node of this.childNodes) {
533
418
  if (node.nodeType === Node_1.default.ELEMENT_NODE) {
534
419
  this.children.push(node);
535
420
  }
536
421
  }
537
422
  }
538
423
  return returnValue;
539
- };
424
+ }
540
425
  /**
541
426
  * Replaces the document HTML with new HTML.
542
427
  *
543
428
  * @param html HTML.
544
429
  */
545
- Document.prototype.write = function (html) {
546
- var root = XMLParser_1.default.parse(this, html, true);
430
+ write(html) {
431
+ const root = XMLParser_1.default.parse(this, html, true);
547
432
  if (this._isFirstWrite || this._isFirstWriteAfterOpen) {
548
433
  if (this._isFirstWrite) {
549
434
  if (!this._isFirstWriteAfterOpen) {
@@ -552,10 +437,9 @@ var Document = /** @class */ (function (_super) {
552
437
  this._isFirstWrite = false;
553
438
  }
554
439
  this._isFirstWriteAfterOpen = false;
555
- var documentElement = null;
556
- var documentTypeNode = null;
557
- for (var _i = 0, _a = root.childNodes; _i < _a.length; _i++) {
558
- var node = _a[_i];
440
+ let documentElement = null;
441
+ let documentTypeNode = null;
442
+ for (const node of root.childNodes) {
559
443
  if (node['tagName'] === 'HTML') {
560
444
  documentElement = node;
561
445
  }
@@ -574,19 +458,17 @@ var Document = /** @class */ (function (_super) {
574
458
  this.appendChild(documentElement);
575
459
  }
576
460
  else {
577
- var rootBody = root.querySelector('body');
578
- var body_1 = this.querySelector('body');
579
- if (rootBody && body_1) {
580
- for (var _b = 0, _c = rootBody.childNodes.slice(); _b < _c.length; _b++) {
581
- var child = _c[_b];
582
- body_1.appendChild(child);
461
+ const rootBody = root.querySelector('body');
462
+ const body = this.querySelector('body');
463
+ if (rootBody && body) {
464
+ for (const child of rootBody.childNodes.slice()) {
465
+ body.appendChild(child);
583
466
  }
584
467
  }
585
468
  }
586
- var body = this.querySelector('body');
469
+ const body = this.querySelector('body');
587
470
  if (body) {
588
- for (var _d = 0, _e = root.childNodes.slice(); _d < _e.length; _d++) {
589
- var child = _e[_d];
471
+ for (const child of root.childNodes.slice()) {
590
472
  if (child['tagName'] !== 'HTML' && child.nodeType !== Node_1.default.DOCUMENT_TYPE_NODE) {
591
473
  body.appendChild(child);
592
474
  }
@@ -594,53 +476,48 @@ var Document = /** @class */ (function (_super) {
594
476
  }
595
477
  }
596
478
  else {
597
- var documentElement_1 = this.createElement('html');
598
- var bodyElement = this.createElement('body');
599
- var headElement = this.createElement('head');
600
- for (var _f = 0, _g = root.childNodes.slice(); _f < _g.length; _f++) {
601
- var child = _g[_f];
479
+ const documentElement = this.createElement('html');
480
+ const bodyElement = this.createElement('body');
481
+ const headElement = this.createElement('head');
482
+ for (const child of root.childNodes.slice()) {
602
483
  bodyElement.appendChild(child);
603
484
  }
604
- documentElement_1.appendChild(headElement);
605
- documentElement_1.appendChild(bodyElement);
606
- this.appendChild(documentElement_1);
485
+ documentElement.appendChild(headElement);
486
+ documentElement.appendChild(bodyElement);
487
+ this.appendChild(documentElement);
607
488
  }
608
489
  }
609
490
  else {
610
- var bodyNode = root.querySelector('body');
611
- for (var _h = 0, _j = (bodyNode || root).childNodes.slice(); _h < _j.length; _h++) {
612
- var child = _j[_h];
491
+ const bodyNode = root.querySelector('body');
492
+ for (const child of (bodyNode || root).childNodes.slice()) {
613
493
  this.body.appendChild(child);
614
494
  }
615
495
  }
616
- };
496
+ }
617
497
  /**
618
498
  * Opens the document.
619
499
  *
620
500
  * @returns Document.
621
501
  */
622
- Document.prototype.open = function () {
502
+ open() {
623
503
  this._isFirstWriteAfterOpen = true;
624
- for (var _i = 0, _a = Object.keys(this._listeners); _i < _a.length; _i++) {
625
- var eventType = _a[_i];
626
- var listeners = this._listeners[eventType];
504
+ for (const eventType of Object.keys(this._listeners)) {
505
+ const listeners = this._listeners[eventType];
627
506
  if (listeners) {
628
- for (var _b = 0, listeners_1 = listeners; _b < listeners_1.length; _b++) {
629
- var listener = listeners_1[_b];
507
+ for (const listener of listeners) {
630
508
  this.removeEventListener(eventType, listener);
631
509
  }
632
510
  }
633
511
  }
634
- for (var _c = 0, _d = this.childNodes.slice(); _c < _d.length; _c++) {
635
- var child = _d[_c];
512
+ for (const child of this.childNodes.slice()) {
636
513
  this.removeChild(child);
637
514
  }
638
515
  return this;
639
- };
516
+ }
640
517
  /**
641
518
  * Closes the document.
642
519
  */
643
- Document.prototype.close = function () { };
520
+ close() { }
644
521
  /* eslint-disable jsdoc/valid-types */
645
522
  /**
646
523
  * Creates an element.
@@ -650,9 +527,9 @@ var Document = /** @class */ (function (_super) {
650
527
  * @param [options.is] Tag name of a custom element previously defined via customElements.define().
651
528
  * @returns Element.
652
529
  */
653
- Document.prototype.createElement = function (qualifiedName, options) {
530
+ createElement(qualifiedName, options) {
654
531
  return this.createElementNS(NamespaceURI_1.default.html, qualifiedName, options);
655
- };
532
+ }
656
533
  /**
657
534
  * Creates an element with the specified namespace URI and qualified name.
658
535
  *
@@ -662,23 +539,23 @@ var Document = /** @class */ (function (_super) {
662
539
  * @param [options.is] Tag name of a custom element previously defined via customElements.define().
663
540
  * @returns Element.
664
541
  */
665
- Document.prototype.createElementNS = function (namespaceURI, qualifiedName, options) {
666
- var tagName = String(qualifiedName).toUpperCase();
667
- var customElementClass;
542
+ createElementNS(namespaceURI, qualifiedName, options) {
543
+ const tagName = String(qualifiedName).toUpperCase();
544
+ let customElementClass;
668
545
  if (this.defaultView && options && options.is) {
669
546
  customElementClass = this.defaultView.customElements.get(String(options.is));
670
547
  }
671
548
  else if (this.defaultView) {
672
549
  customElementClass = this.defaultView.customElements.get(tagName);
673
550
  }
674
- var elementClass = customElementClass || ElementTag_1.default[tagName] || HTMLUnknownElement_1.default;
551
+ const elementClass = customElementClass || ElementTag_1.default[tagName] || HTMLUnknownElement_1.default;
675
552
  elementClass.ownerDocument = this;
676
- var element = new elementClass();
553
+ const element = new elementClass();
677
554
  element.tagName = tagName;
678
555
  element.ownerDocument = this;
679
556
  element.namespaceURI = namespaceURI;
680
557
  return element;
681
- };
558
+ }
682
559
  /* eslint-enable jsdoc/valid-types */
683
560
  /**
684
561
  * Creates a text node.
@@ -686,29 +563,29 @@ var Document = /** @class */ (function (_super) {
686
563
  * @param [data] Text data.
687
564
  * @returns Text node.
688
565
  */
689
- Document.prototype.createTextNode = function (data) {
566
+ createTextNode(data) {
690
567
  Text_1.default.ownerDocument = this;
691
568
  return new Text_1.default(data);
692
- };
569
+ }
693
570
  /**
694
571
  * Creates a comment node.
695
572
  *
696
573
  * @param [data] Text data.
697
574
  * @returns Text node.
698
575
  */
699
- Document.prototype.createComment = function (data) {
576
+ createComment(data) {
700
577
  Comment_1.default.ownerDocument = this;
701
578
  return new Comment_1.default(data);
702
- };
579
+ }
703
580
  /**
704
581
  * Creates a document fragment.
705
582
  *
706
583
  * @returns Document fragment.
707
584
  */
708
- Document.prototype.createDocumentFragment = function () {
585
+ createDocumentFragment() {
709
586
  DocumentFragment_1.default.ownerDocument = this;
710
587
  return new DocumentFragment_1.default();
711
- };
588
+ }
712
589
  /**
713
590
  * Creates a Tree Walker.
714
591
  *
@@ -716,11 +593,9 @@ var Document = /** @class */ (function (_super) {
716
593
  * @param [whatToShow] What to show.
717
594
  * @param [filter] Filter.
718
595
  */
719
- Document.prototype.createTreeWalker = function (root, whatToShow, filter) {
720
- if (whatToShow === void 0) { whatToShow = -1; }
721
- if (filter === void 0) { filter = null; }
596
+ createTreeWalker(root, whatToShow = -1, filter = null) {
722
597
  return new TreeWalker_1.default(root, whatToShow, filter);
723
- };
598
+ }
724
599
  /**
725
600
  * Creates an event.
726
601
  *
@@ -728,24 +603,24 @@ var Document = /** @class */ (function (_super) {
728
603
  * @param type Type.
729
604
  * @returns Event.
730
605
  */
731
- Document.prototype.createEvent = function (type) {
606
+ createEvent(type) {
732
607
  if (this.defaultView[type]) {
733
608
  return new this.defaultView[type]('init');
734
609
  }
735
610
  return new Event_1.default('init');
736
- };
611
+ }
737
612
  /**
738
613
  * Creates an Attr node.
739
614
  *
740
615
  * @param name Name.
741
616
  * @returns Attribute.
742
617
  */
743
- Document.prototype.createAttribute = function (name) {
744
- var attribute = new Attr_1.default();
618
+ createAttribute(name) {
619
+ const attribute = new Attr_1.default();
745
620
  attribute.name = name.toLowerCase();
746
621
  attribute.ownerDocument = this;
747
622
  return attribute;
748
- };
623
+ }
749
624
  /**
750
625
  * Creates a namespaced Attr node.
751
626
  *
@@ -753,13 +628,13 @@ var Document = /** @class */ (function (_super) {
753
628
  * @param qualifiedName Qualified name.
754
629
  * @returns Element.
755
630
  */
756
- Document.prototype.createAttributeNS = function (namespaceURI, qualifiedName) {
757
- var attribute = new Attr_1.default();
631
+ createAttributeNS(namespaceURI, qualifiedName) {
632
+ const attribute = new Attr_1.default();
758
633
  attribute.namespaceURI = namespaceURI;
759
634
  attribute.name = qualifiedName;
760
635
  attribute.ownerDocument = this;
761
636
  return attribute;
762
- };
637
+ }
763
638
  /**
764
639
  * Imports a node.
765
640
  *
@@ -767,56 +642,54 @@ var Document = /** @class */ (function (_super) {
767
642
  * @param [deep=false] Set to "true" if the clone should be deep.
768
643
  * @param Imported Node.
769
644
  */
770
- Document.prototype.importNode = function (node, deep) {
771
- if (deep === void 0) { deep = false; }
645
+ importNode(node, deep = false) {
772
646
  if (!(node instanceof Node_1.default)) {
773
647
  throw new DOMException_1.default('Parameter 1 was not of type Node.');
774
648
  }
775
- var clone = node.cloneNode(deep);
649
+ const clone = node.cloneNode(deep);
776
650
  clone.ownerDocument = this;
777
651
  return clone;
778
- };
652
+ }
779
653
  /**
780
654
  * Adopts a node.
781
655
  *
782
656
  * @param node Node to adopt.
783
657
  * @returns Adopted node.
784
658
  */
785
- Document.prototype.adoptNode = function (node) {
659
+ adoptNode(node) {
786
660
  if (!(node instanceof Node_1.default)) {
787
661
  throw new DOMException_1.default('Parameter 1 was not of type Node.');
788
662
  }
789
- var adopted = node.parentNode ? node.parentNode.removeChild(node) : node;
663
+ const adopted = node.parentNode ? node.parentNode.removeChild(node) : node;
790
664
  adopted.ownerDocument = this;
791
665
  return adopted;
792
- };
666
+ }
793
667
  /**
794
668
  * Returns selection.
795
669
  *
796
670
  * @returns Selection.
797
671
  */
798
- Document.prototype.getSelection = function () {
672
+ getSelection() {
799
673
  return new Selection_1.default();
800
- };
674
+ }
801
675
  /**
802
676
  * Returns a boolean value indicating whether the document or any element inside the document has focus.
803
677
  *
804
678
  * @returns "true" if the document has focus.
805
679
  */
806
- Document.prototype.hasFocus = function () {
680
+ hasFocus() {
807
681
  return !!this.activeElement;
808
- };
682
+ }
809
683
  /**
810
684
  * @override
811
685
  */
812
- Document.prototype.dispatchEvent = function (event) {
813
- var returnValue = _super.prototype.dispatchEvent.call(this, event);
686
+ dispatchEvent(event) {
687
+ const returnValue = super.dispatchEvent(event);
814
688
  if (event.bubbles && !event._propagationStopped) {
815
689
  return this.defaultView.dispatchEvent(event);
816
690
  }
817
691
  return returnValue;
818
- };
819
- return Document;
820
- }(Node_1.default));
692
+ }
693
+ }
821
694
  exports.default = Document;
822
695
  //# sourceMappingURL=Document.js.map