happy-dom 10.10.4 → 10.11.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 (144) hide show
  1. package/cjs/dom-parser/DOMParser.cjs +5 -5
  2. package/cjs/dom-parser/DOMParser.cjs.map +1 -1
  3. package/cjs/dom-parser/DOMParser.d.ts.map +1 -1
  4. package/cjs/nodes/child-node/ChildNodeUtility.cjs +3 -3
  5. package/cjs/nodes/child-node/ChildNodeUtility.cjs.map +1 -1
  6. package/cjs/nodes/child-node/ChildNodeUtility.d.ts.map +1 -1
  7. package/cjs/nodes/document/Document.cjs +24 -18
  8. package/cjs/nodes/document/Document.cjs.map +1 -1
  9. package/cjs/nodes/document/Document.d.ts +5 -1
  10. package/cjs/nodes/document/Document.d.ts.map +1 -1
  11. package/cjs/nodes/document-fragment/DocumentFragment.cjs +14 -8
  12. package/cjs/nodes/document-fragment/DocumentFragment.cjs.map +1 -1
  13. package/cjs/nodes/document-fragment/DocumentFragment.d.ts +5 -1
  14. package/cjs/nodes/document-fragment/DocumentFragment.d.ts.map +1 -1
  15. package/cjs/nodes/element/Element.cjs +17 -11
  16. package/cjs/nodes/element/Element.cjs.map +1 -1
  17. package/cjs/nodes/element/Element.d.ts +5 -1
  18. package/cjs/nodes/element/Element.d.ts.map +1 -1
  19. package/cjs/nodes/element/ElementNamedNodeMap.cjs +5 -5
  20. package/cjs/nodes/element/ElementNamedNodeMap.cjs.map +1 -1
  21. package/cjs/nodes/element/ElementUtility.cjs +37 -28
  22. package/cjs/nodes/element/ElementUtility.cjs.map +1 -1
  23. package/cjs/nodes/element/ElementUtility.d.ts.map +1 -1
  24. package/cjs/nodes/html-element/HTMLElement.cjs +2 -2
  25. package/cjs/nodes/html-element/HTMLElement.cjs.map +1 -1
  26. package/cjs/nodes/html-slot-element/HTMLSlotElement.cjs +3 -3
  27. package/cjs/nodes/html-slot-element/HTMLSlotElement.cjs.map +1 -1
  28. package/cjs/nodes/html-template-element/HTMLTemplateElement.cjs +2 -2
  29. package/cjs/nodes/html-template-element/HTMLTemplateElement.cjs.map +1 -1
  30. package/cjs/nodes/html-template-element/HTMLTemplateElement.d.ts.map +1 -1
  31. package/cjs/nodes/html-unknown-element/HTMLUnknownElement.cjs +11 -11
  32. package/cjs/nodes/html-unknown-element/HTMLUnknownElement.cjs.map +1 -1
  33. package/cjs/nodes/node/Node.cjs +29 -21
  34. package/cjs/nodes/node/Node.cjs.map +1 -1
  35. package/cjs/nodes/node/Node.d.ts +7 -1
  36. package/cjs/nodes/node/Node.d.ts.map +1 -1
  37. package/cjs/nodes/node/NodeUtility.cjs +17 -17
  38. package/cjs/nodes/node/NodeUtility.cjs.map +1 -1
  39. package/cjs/nodes/node/NodeUtility.d.ts.map +1 -1
  40. package/cjs/nodes/parent-node/ParentNodeUtility.cjs +7 -7
  41. package/cjs/nodes/parent-node/ParentNodeUtility.cjs.map +1 -1
  42. package/cjs/nodes/parent-node/ParentNodeUtility.d.ts.map +1 -1
  43. package/cjs/nodes/shadow-root/ShadowRoot.cjs +2 -2
  44. package/cjs/nodes/shadow-root/ShadowRoot.cjs.map +1 -1
  45. package/cjs/query-selector/QuerySelector.cjs +10 -8
  46. package/cjs/query-selector/QuerySelector.cjs.map +1 -1
  47. package/cjs/query-selector/QuerySelector.d.ts.map +1 -1
  48. package/cjs/query-selector/SelectorItem.cjs +15 -14
  49. package/cjs/query-selector/SelectorItem.cjs.map +1 -1
  50. package/cjs/query-selector/SelectorItem.d.ts.map +1 -1
  51. package/cjs/range/Range.cjs +12 -12
  52. package/cjs/range/Range.cjs.map +1 -1
  53. package/cjs/range/Range.d.ts.map +1 -1
  54. package/cjs/range/RangeUtility.cjs +1 -1
  55. package/cjs/range/RangeUtility.cjs.map +1 -1
  56. package/cjs/range/RangeUtility.d.ts.map +1 -1
  57. package/cjs/tree-walker/TreeWalker.cjs +4 -4
  58. package/cjs/tree-walker/TreeWalker.cjs.map +1 -1
  59. package/cjs/xml-serializer/XMLSerializer.cjs +4 -4
  60. package/cjs/xml-serializer/XMLSerializer.cjs.map +1 -1
  61. package/cjs/xml-serializer/XMLSerializer.d.ts.map +1 -1
  62. package/lib/dom-parser/DOMParser.d.ts.map +1 -1
  63. package/lib/dom-parser/DOMParser.js +5 -5
  64. package/lib/dom-parser/DOMParser.js.map +1 -1
  65. package/lib/nodes/child-node/ChildNodeUtility.d.ts.map +1 -1
  66. package/lib/nodes/child-node/ChildNodeUtility.js +3 -3
  67. package/lib/nodes/child-node/ChildNodeUtility.js.map +1 -1
  68. package/lib/nodes/document/Document.d.ts +5 -1
  69. package/lib/nodes/document/Document.d.ts.map +1 -1
  70. package/lib/nodes/document/Document.js +24 -18
  71. package/lib/nodes/document/Document.js.map +1 -1
  72. package/lib/nodes/document-fragment/DocumentFragment.d.ts +5 -1
  73. package/lib/nodes/document-fragment/DocumentFragment.d.ts.map +1 -1
  74. package/lib/nodes/document-fragment/DocumentFragment.js +14 -8
  75. package/lib/nodes/document-fragment/DocumentFragment.js.map +1 -1
  76. package/lib/nodes/element/Element.d.ts +5 -1
  77. package/lib/nodes/element/Element.d.ts.map +1 -1
  78. package/lib/nodes/element/Element.js +17 -11
  79. package/lib/nodes/element/Element.js.map +1 -1
  80. package/lib/nodes/element/ElementNamedNodeMap.js +5 -5
  81. package/lib/nodes/element/ElementNamedNodeMap.js.map +1 -1
  82. package/lib/nodes/element/ElementUtility.d.ts.map +1 -1
  83. package/lib/nodes/element/ElementUtility.js +37 -28
  84. package/lib/nodes/element/ElementUtility.js.map +1 -1
  85. package/lib/nodes/html-element/HTMLElement.js +2 -2
  86. package/lib/nodes/html-element/HTMLElement.js.map +1 -1
  87. package/lib/nodes/html-slot-element/HTMLSlotElement.js +3 -3
  88. package/lib/nodes/html-slot-element/HTMLSlotElement.js.map +1 -1
  89. package/lib/nodes/html-template-element/HTMLTemplateElement.d.ts.map +1 -1
  90. package/lib/nodes/html-template-element/HTMLTemplateElement.js +2 -2
  91. package/lib/nodes/html-template-element/HTMLTemplateElement.js.map +1 -1
  92. package/lib/nodes/html-unknown-element/HTMLUnknownElement.js +11 -11
  93. package/lib/nodes/html-unknown-element/HTMLUnknownElement.js.map +1 -1
  94. package/lib/nodes/node/Node.d.ts +7 -1
  95. package/lib/nodes/node/Node.d.ts.map +1 -1
  96. package/lib/nodes/node/Node.js +29 -21
  97. package/lib/nodes/node/Node.js.map +1 -1
  98. package/lib/nodes/node/NodeUtility.d.ts.map +1 -1
  99. package/lib/nodes/node/NodeUtility.js +17 -17
  100. package/lib/nodes/node/NodeUtility.js.map +1 -1
  101. package/lib/nodes/parent-node/ParentNodeUtility.d.ts.map +1 -1
  102. package/lib/nodes/parent-node/ParentNodeUtility.js +7 -7
  103. package/lib/nodes/parent-node/ParentNodeUtility.js.map +1 -1
  104. package/lib/nodes/shadow-root/ShadowRoot.js +2 -2
  105. package/lib/nodes/shadow-root/ShadowRoot.js.map +1 -1
  106. package/lib/query-selector/QuerySelector.d.ts.map +1 -1
  107. package/lib/query-selector/QuerySelector.js +10 -8
  108. package/lib/query-selector/QuerySelector.js.map +1 -1
  109. package/lib/query-selector/SelectorItem.d.ts.map +1 -1
  110. package/lib/query-selector/SelectorItem.js +15 -14
  111. package/lib/query-selector/SelectorItem.js.map +1 -1
  112. package/lib/range/Range.d.ts.map +1 -1
  113. package/lib/range/Range.js +12 -12
  114. package/lib/range/Range.js.map +1 -1
  115. package/lib/range/RangeUtility.d.ts.map +1 -1
  116. package/lib/range/RangeUtility.js +1 -1
  117. package/lib/range/RangeUtility.js.map +1 -1
  118. package/lib/tree-walker/TreeWalker.js +4 -4
  119. package/lib/tree-walker/TreeWalker.js.map +1 -1
  120. package/lib/xml-serializer/XMLSerializer.d.ts.map +1 -1
  121. package/lib/xml-serializer/XMLSerializer.js +4 -4
  122. package/lib/xml-serializer/XMLSerializer.js.map +1 -1
  123. package/package.json +1 -1
  124. package/src/dom-parser/DOMParser.ts +9 -7
  125. package/src/nodes/child-node/ChildNodeUtility.ts +10 -12
  126. package/src/nodes/document/Document.ts +29 -22
  127. package/src/nodes/document-fragment/DocumentFragment.ts +16 -9
  128. package/src/nodes/element/Element.ts +23 -12
  129. package/src/nodes/element/ElementNamedNodeMap.ts +5 -5
  130. package/src/nodes/element/ElementUtility.ts +44 -43
  131. package/src/nodes/html-element/HTMLElement.ts +2 -2
  132. package/src/nodes/html-slot-element/HTMLSlotElement.ts +3 -3
  133. package/src/nodes/html-template-element/HTMLTemplateElement.ts +3 -2
  134. package/src/nodes/html-unknown-element/HTMLUnknownElement.ts +11 -11
  135. package/src/nodes/node/Node.ts +30 -21
  136. package/src/nodes/node/NodeUtility.ts +21 -17
  137. package/src/nodes/parent-node/ParentNodeUtility.ts +10 -10
  138. package/src/nodes/shadow-root/ShadowRoot.ts +2 -2
  139. package/src/query-selector/QuerySelector.ts +24 -8
  140. package/src/query-selector/SelectorItem.ts +15 -14
  141. package/src/range/Range.ts +13 -12
  142. package/src/range/RangeUtility.ts +2 -1
  143. package/src/tree-walker/TreeWalker.ts +4 -4
  144. package/src/xml-serializer/XMLSerializer.ts +6 -4
@@ -60,12 +60,12 @@ export default class Document extends Node implements IDocument {
60
60
  public nodeType = Node.DOCUMENT_NODE;
61
61
  public adoptedStyleSheets: CSSStyleSheet[] = [];
62
62
  public implementation: DOMImplementation;
63
- public readonly children: IHTMLCollection<IElement> = new HTMLCollection<IElement>();
64
63
  public readonly readyState = DocumentReadyStateEnum.interactive;
65
64
  public readonly isConnected: boolean = true;
66
65
  public readonly defaultView: IWindow;
67
66
  public readonly _windowClass: {} | null = null;
68
67
  public readonly _readyStateManager: DocumentReadyStateManager;
68
+ public readonly _children: IHTMLCollection<IElement> = new HTMLCollection<IElement>();
69
69
  public _activeElement: IHTMLElement = null;
70
70
 
71
71
  // Used as an unique identifier which is updated whenever the DOM gets modified.
@@ -215,6 +215,13 @@ export default class Document extends Node implements IDocument {
215
215
  documentElement.appendChild(bodyElement);
216
216
  }
217
217
 
218
+ /**
219
+ * Returns document children.
220
+ */
221
+ public get children(): IHTMLCollection<IElement> {
222
+ return this._children;
223
+ }
224
+
218
225
  /**
219
226
  * Returns character set.
220
227
  *
@@ -276,7 +283,7 @@ export default class Document extends Node implements IDocument {
276
283
  * @returns Element.
277
284
  */
278
285
  public get childElementCount(): number {
279
- return this.children.length;
286
+ return this._children.length;
280
287
  }
281
288
 
282
289
  /**
@@ -285,7 +292,7 @@ export default class Document extends Node implements IDocument {
285
292
  * @returns Element.
286
293
  */
287
294
  public get firstElementChild(): IElement {
288
- return this.children ? this.children[0] || null : null;
295
+ return this._children[0] ?? null;
289
296
  }
290
297
 
291
298
  /**
@@ -294,7 +301,7 @@ export default class Document extends Node implements IDocument {
294
301
  * @returns Element.
295
302
  */
296
303
  public get lastElementChild(): IElement {
297
- return this.children ? this.children[this.children.length - 1] || null : null;
304
+ return this._children[this._children.length - 1] ?? null;
298
305
  }
299
306
 
300
307
  /**
@@ -339,7 +346,7 @@ export default class Document extends Node implements IDocument {
339
346
  * @returns Document type.
340
347
  */
341
348
  public get doctype(): IDocumentType {
342
- for (const node of this.childNodes) {
349
+ for (const node of this._childNodes) {
343
350
  if (node instanceof DocumentType) {
344
351
  return node;
345
352
  }
@@ -588,22 +595,22 @@ export default class Document extends Node implements IDocument {
588
595
  * @param name
589
596
  */
590
597
  public getElementsByName(name: string): INodeList<IElement> {
591
- const _getElementsByName = (
592
- _parentNode: IElement | IDocumentFragment | IDocument,
593
- _name: string
598
+ const getElementsByName = (
599
+ parentNode: IElement | IDocumentFragment | IDocument,
600
+ name: string
594
601
  ): INodeList<IElement> => {
595
602
  const matches = new NodeList<IElement>();
596
- for (const child of _parentNode.children) {
597
- if (child.getAttributeNS(null, 'name') === _name) {
603
+ for (const child of (<Element | Document>parentNode)._children) {
604
+ if (child.getAttributeNS(null, 'name') === name) {
598
605
  matches.push(child);
599
606
  }
600
- for (const match of _getElementsByName(<IElement>child, _name)) {
607
+ for (const match of getElementsByName(<IElement>child, name)) {
601
608
  matches.push(match);
602
609
  }
603
610
  }
604
611
  return matches;
605
612
  };
606
- return _getElementsByName(this, name);
613
+ return getElementsByName(this, name);
607
614
  }
608
615
 
609
616
  /**
@@ -619,9 +626,9 @@ export default class Document extends Node implements IDocument {
619
626
  const clone = <Document>super.cloneNode(deep);
620
627
 
621
628
  if (deep) {
622
- for (const node of clone.childNodes) {
629
+ for (const node of clone._childNodes) {
623
630
  if (node.nodeType === Node.ELEMENT_NODE) {
624
- clone.children.push(<IElement>node);
631
+ clone._children.push(<IElement>node);
625
632
  }
626
633
  }
627
634
  }
@@ -665,7 +672,7 @@ export default class Document extends Node implements IDocument {
665
672
  * @param html HTML.
666
673
  */
667
674
  public write(html: string): void {
668
- const root = XMLParser.parse(this, html, { evaluateScripts: true });
675
+ const root = <DocumentFragment>XMLParser.parse(this, html, { evaluateScripts: true });
669
676
 
670
677
  if (this._isFirstWrite || this._isFirstWriteAfterOpen) {
671
678
  if (this._isFirstWrite) {
@@ -680,7 +687,7 @@ export default class Document extends Node implements IDocument {
680
687
  let documentElement = null;
681
688
  let documentTypeNode = null;
682
689
 
683
- for (const node of root.childNodes) {
690
+ for (const node of root._childNodes) {
684
691
  if (node['tagName'] === 'HTML') {
685
692
  documentElement = node;
686
693
  } else if (node.nodeType === NodeTypeEnum.documentTypeNode) {
@@ -700,10 +707,10 @@ export default class Document extends Node implements IDocument {
700
707
 
701
708
  this.appendChild(documentElement);
702
709
  } else {
703
- const rootBody = ParentNodeUtility.getElementByTagName(root, 'body');
710
+ const rootBody = <Element>ParentNodeUtility.getElementByTagName(root, 'body');
704
711
  const body = ParentNodeUtility.getElementByTagName(this, 'body');
705
712
  if (rootBody && body) {
706
- for (const child of rootBody.childNodes.slice()) {
713
+ for (const child of rootBody._childNodes.slice()) {
707
714
  body.appendChild(child);
708
715
  }
709
716
  }
@@ -712,7 +719,7 @@ export default class Document extends Node implements IDocument {
712
719
  // Remaining nodes outside the <html> element are added to the <body> element.
713
720
  const body = ParentNodeUtility.getElementByTagName(this, 'body');
714
721
  if (body) {
715
- for (const child of root.childNodes.slice()) {
722
+ for (const child of root._childNodes.slice()) {
716
723
  if (child['tagName'] !== 'HTML' && child.nodeType !== NodeTypeEnum.documentTypeNode) {
717
724
  body.appendChild(child);
718
725
  }
@@ -723,7 +730,7 @@ export default class Document extends Node implements IDocument {
723
730
  const bodyElement = this.createElement('body');
724
731
  const headElement = this.createElement('head');
725
732
 
726
- for (const child of root.childNodes.slice()) {
733
+ for (const child of root._childNodes.slice()) {
727
734
  bodyElement.appendChild(child);
728
735
  }
729
736
 
@@ -735,7 +742,7 @@ export default class Document extends Node implements IDocument {
735
742
  } else {
736
743
  const bodyNode = ParentNodeUtility.getElementByTagName(root, 'body');
737
744
  const body = ParentNodeUtility.getElementByTagName(this, 'body');
738
- for (const child of (bodyNode || root).childNodes.slice()) {
745
+ for (const child of (<Element>(bodyNode || root))._childNodes.slice()) {
739
746
  body.appendChild(child);
740
747
  }
741
748
  }
@@ -758,7 +765,7 @@ export default class Document extends Node implements IDocument {
758
765
  }
759
766
  }
760
767
 
761
- for (const child of this.childNodes.slice()) {
768
+ for (const child of this._childNodes.slice()) {
762
769
  this.removeChild(child);
763
770
  }
764
771
 
@@ -14,16 +14,23 @@ import INodeList from '../node/INodeList.js';
14
14
  */
15
15
  export default class DocumentFragment extends Node implements IDocumentFragment {
16
16
  public nodeType = Node.DOCUMENT_FRAGMENT_NODE;
17
- public readonly children: IHTMLCollection<IElement> = new HTMLCollection();
17
+ public readonly _children: IHTMLCollection<IElement> = new HTMLCollection();
18
18
  public _rootNode: INode = this;
19
19
 
20
+ /**
21
+ * Returns the document fragment children.
22
+ */
23
+ public get children(): IHTMLCollection<IElement> {
24
+ return this._children;
25
+ }
26
+
20
27
  /**
21
28
  * Last element child.
22
29
  *
23
30
  * @returns Element.
24
31
  */
25
32
  public get childElementCount(): number {
26
- return this.children.length;
33
+ return this._children.length;
27
34
  }
28
35
 
29
36
  /**
@@ -32,7 +39,7 @@ export default class DocumentFragment extends Node implements IDocumentFragment
32
39
  * @returns Element.
33
40
  */
34
41
  public get firstElementChild(): IElement {
35
- return this.children ? this.children[0] || null : null;
42
+ return this._children[0] ?? null;
36
43
  }
37
44
 
38
45
  /**
@@ -41,7 +48,7 @@ export default class DocumentFragment extends Node implements IDocumentFragment
41
48
  * @returns Element.
42
49
  */
43
50
  public get lastElementChild(): IElement {
44
- return this.children ? this.children[this.children.length - 1] || null : null;
51
+ return this._children[this._children.length - 1] ?? null;
45
52
  }
46
53
 
47
54
  /**
@@ -51,7 +58,7 @@ export default class DocumentFragment extends Node implements IDocumentFragment
51
58
  */
52
59
  public get textContent(): string {
53
60
  let result = '';
54
- for (const childNode of this.childNodes) {
61
+ for (const childNode of this._childNodes) {
55
62
  if (childNode.nodeType === Node.ELEMENT_NODE || childNode.nodeType === Node.TEXT_NODE) {
56
63
  result += childNode.textContent;
57
64
  }
@@ -65,7 +72,7 @@ export default class DocumentFragment extends Node implements IDocumentFragment
65
72
  * @param textContent Text content.
66
73
  */
67
74
  public set textContent(textContent: string) {
68
- for (const child of this.childNodes.slice()) {
75
+ for (const child of this._childNodes.slice()) {
69
76
  this.removeChild(child);
70
77
  }
71
78
  if (textContent) {
@@ -138,12 +145,12 @@ export default class DocumentFragment extends Node implements IDocumentFragment
138
145
  * @returns Cloned node.
139
146
  */
140
147
  public cloneNode(deep = false): IDocumentFragment {
141
- const clone = <IDocumentFragment>super.cloneNode(deep);
148
+ const clone = <DocumentFragment>super.cloneNode(deep);
142
149
 
143
150
  if (deep) {
144
- for (const node of clone.childNodes) {
151
+ for (const node of clone._childNodes) {
145
152
  if (node.nodeType === Node.ELEMENT_NODE) {
146
- clone.children.push(<IElement>node);
153
+ clone._children.push(<IElement>node);
147
154
  }
148
155
  }
149
156
  }
@@ -29,6 +29,7 @@ import ElementUtility from './ElementUtility.js';
29
29
  import HTMLCollection from './HTMLCollection.js';
30
30
  import EventPhaseEnum from '../../event/EventPhaseEnum.js';
31
31
  import CSSStyleDeclaration from '../../css/declaration/CSSStyleDeclaration.js';
32
+ import DocumentFragment from '../document-fragment/DocumentFragment.js';
32
33
  import ElementNamedNodeMap from './ElementNamedNodeMap.js';
33
34
 
34
35
  /**
@@ -47,7 +48,6 @@ export default class Element extends Node implements IElement {
47
48
  public scrollHeight = 0;
48
49
  public scrollTop = 0;
49
50
  public scrollLeft = 0;
50
- public children: IHTMLCollection<IElement> = new HTMLCollection<IElement>();
51
51
  public readonly namespaceURI: string = null;
52
52
 
53
53
  // Events
@@ -86,6 +86,8 @@ export default class Element extends Node implements IElement {
86
86
  public ontouchmove: (event: Event) => void | null = null;
87
87
  public ontouchstart: (event: Event) => void | null = null;
88
88
 
89
+ public readonly _children: IHTMLCollection<IElement> = new HTMLCollection<IElement>();
90
+
89
91
  // Used for being able to access closed shadow roots
90
92
  public _shadowRoot: IShadowRoot = null;
91
93
  public readonly attributes: INamedNodeMap = new ElementNamedNodeMap(this);
@@ -94,6 +96,13 @@ export default class Element extends Node implements IElement {
94
96
  public _isValue?: string | null = null;
95
97
  public _computedStyle: CSSStyleDeclaration | null = null;
96
98
 
99
+ /**
100
+ * Returns element children.
101
+ */
102
+ public get children(): IHTMLCollection<IElement> {
103
+ return this._children;
104
+ }
105
+
97
106
  /**
98
107
  * Returns class list.
99
108
  *
@@ -203,7 +212,7 @@ export default class Element extends Node implements IElement {
203
212
  */
204
213
  public get textContent(): string {
205
214
  let result = '';
206
- for (const childNode of this.childNodes) {
215
+ for (const childNode of this._childNodes) {
207
216
  if (childNode.nodeType === Node.ELEMENT_NODE || childNode.nodeType === Node.TEXT_NODE) {
208
217
  result += childNode.textContent;
209
218
  }
@@ -217,7 +226,7 @@ export default class Element extends Node implements IElement {
217
226
  * @param textContent Text content.
218
227
  */
219
228
  public set textContent(textContent: string) {
220
- for (const child of this.childNodes.slice()) {
229
+ for (const child of this._childNodes.slice()) {
221
230
  this.removeChild(child);
222
231
  }
223
232
  if (textContent) {
@@ -240,7 +249,7 @@ export default class Element extends Node implements IElement {
240
249
  * @param html HTML.
241
250
  */
242
251
  public set innerHTML(html: string) {
243
- for (const child of this.childNodes.slice()) {
252
+ for (const child of this._childNodes.slice()) {
244
253
  this.removeChild(child);
245
254
  }
246
255
 
@@ -271,7 +280,7 @@ export default class Element extends Node implements IElement {
271
280
  * @returns Element.
272
281
  */
273
282
  public get firstElementChild(): IElement {
274
- return this.children ? this.children[0] || null : null;
283
+ return this._children[0] ?? null;
275
284
  }
276
285
 
277
286
  /**
@@ -280,7 +289,7 @@ export default class Element extends Node implements IElement {
280
289
  * @returns Element.
281
290
  */
282
291
  public get lastElementChild(): IElement {
283
- return this.children ? this.children[this.children.length - 1] || null : null;
292
+ return this._children[this._children.length - 1] ?? null;
284
293
  }
285
294
 
286
295
  /**
@@ -289,7 +298,7 @@ export default class Element extends Node implements IElement {
289
298
  * @returns Element.
290
299
  */
291
300
  public get childElementCount(): number {
292
- return this.children.length;
301
+ return this._children.length;
293
302
  }
294
303
 
295
304
  /**
@@ -336,7 +345,7 @@ export default class Element extends Node implements IElement {
336
345
  escapeEntities: false
337
346
  });
338
347
  let xml = '';
339
- for (const node of this.childNodes) {
348
+ for (const node of this._childNodes) {
340
349
  xml += xmlSerializer.serializeToString(node);
341
350
  }
342
351
  return xml;
@@ -350,7 +359,7 @@ export default class Element extends Node implements IElement {
350
359
  * @returns Cloned node.
351
360
  */
352
361
  public cloneNode(deep = false): IElement {
353
- const clone = <Element | IElement>super.cloneNode(deep);
362
+ const clone = <Element>super.cloneNode(deep);
354
363
 
355
364
  Attr._ownerDocument = this.ownerDocument;
356
365
 
@@ -360,9 +369,9 @@ export default class Element extends Node implements IElement {
360
369
  }
361
370
 
362
371
  if (deep) {
363
- for (const node of clone.childNodes) {
372
+ for (const node of clone._childNodes) {
364
373
  if (node.nodeType === Node.ELEMENT_NODE) {
365
- clone.children.push(<IElement>node);
374
+ clone._children.push(<IElement>node);
366
375
  }
367
376
  }
368
377
  }
@@ -503,7 +512,9 @@ export default class Element extends Node implements IElement {
503
512
  * @param text HTML string to insert.
504
513
  */
505
514
  public insertAdjacentHTML(position: TInsertAdjacentPositions, text: string): void {
506
- for (const node of XMLParser.parse(this.ownerDocument, text).childNodes.slice()) {
515
+ for (const node of (<DocumentFragment>(
516
+ XMLParser.parse(this.ownerDocument, text)
517
+ ))._childNodes.slice()) {
507
518
  this.insertAdjacentElement(position, node);
508
519
  }
509
520
  }
@@ -66,17 +66,17 @@ export default class ElementNamedNodeMap extends NamedNodeMap {
66
66
  if (item.name === 'id' || item.name === 'name') {
67
67
  if (
68
68
  this._ownerElement.parentNode &&
69
- (<IElement>this._ownerElement.parentNode).children &&
69
+ (<Element>this._ownerElement.parentNode)._children &&
70
70
  item.value !== oldValue
71
71
  ) {
72
72
  if (oldValue) {
73
73
  (<HTMLCollection<IElement>>(
74
- (<IElement>this._ownerElement.parentNode).children
74
+ (<Element>this._ownerElement.parentNode)._children
75
75
  ))._removeNamedItem(this._ownerElement, oldValue);
76
76
  }
77
77
  if (item.value) {
78
78
  (<HTMLCollection<IElement>>(
79
- (<IElement>this._ownerElement.parentNode).children
79
+ (<Element>this._ownerElement.parentNode)._children
80
80
  ))._appendNamedItem(this._ownerElement, item.value);
81
81
  }
82
82
  }
@@ -132,11 +132,11 @@ export default class ElementNamedNodeMap extends NamedNodeMap {
132
132
  if (removedItem.name === 'id' || removedItem.name === 'name') {
133
133
  if (
134
134
  this._ownerElement.parentNode &&
135
- (<IElement>this._ownerElement.parentNode).children &&
135
+ (<Element>this._ownerElement.parentNode)._children &&
136
136
  removedItem.value
137
137
  ) {
138
138
  (<HTMLCollection<IElement>>(
139
- (<IElement>this._ownerElement.parentNode).children
139
+ (<Element>this._ownerElement.parentNode)._children
140
140
  ))._removeNamedItem(this._ownerElement, removedItem.value);
141
141
  }
142
142
  }
@@ -40,34 +40,35 @@ export default class ElementUtility {
40
40
  DOMExceptionNameEnum.domException
41
41
  );
42
42
  }
43
+ if (node.parentNode) {
44
+ const parentNodeChildren = <HTMLCollection<IHTMLElement>>(
45
+ (<Element>node.parentNode)._children
46
+ );
43
47
 
44
- if (node.parentNode && (<IHTMLElement>node.parentNode).children) {
45
- const index = (<IHTMLElement>node.parentNode).children.indexOf(<IHTMLElement>node);
46
- if (index !== -1) {
47
- for (const attributeName of NAMED_ITEM_ATTRIBUTES) {
48
- const attribute = (<Element>node).attributes.getNamedItem(attributeName);
49
- if (attribute) {
50
- (<HTMLCollection<IHTMLElement>>(<IElement>node.parentNode).children)._removeNamedItem(
51
- <IHTMLElement>node,
52
- attribute.value
53
- );
48
+ if (parentNodeChildren) {
49
+ const index = parentNodeChildren.indexOf(<IHTMLElement>node);
50
+ if (index !== -1) {
51
+ for (const attributeName of NAMED_ITEM_ATTRIBUTES) {
52
+ const attribute = (<Element>node).attributes.getNamedItem(attributeName);
53
+ if (attribute) {
54
+ parentNodeChildren._removeNamedItem(<IHTMLElement>node, attribute.value);
55
+ }
54
56
  }
57
+
58
+ parentNodeChildren.splice(index, 1);
55
59
  }
56
- (<IHTMLElement>node.parentNode).children.splice(index, 1);
57
60
  }
58
61
  }
62
+ const ancestorNodeChildren = <HTMLCollection<IHTMLElement>>(<Element>ancestorNode)._children;
59
63
 
60
64
  for (const attributeName of NAMED_ITEM_ATTRIBUTES) {
61
65
  const attribute = (<Element>node).attributes.getNamedItem(attributeName);
62
66
  if (attribute) {
63
- (<HTMLCollection<IHTMLElement>>ancestorNode.children)._appendNamedItem(
64
- <IHTMLElement>node,
65
- attribute.value
66
- );
67
+ ancestorNodeChildren._appendNamedItem(<IHTMLElement>node, attribute.value);
67
68
  }
68
69
  }
69
70
 
70
- ancestorNode.children.push(<IElement>node);
71
+ ancestorNodeChildren.push(<IElement>node);
71
72
 
72
73
  NodeUtility.appendChild(ancestorNode, node, { disableAncestorValidation: true });
73
74
  } else {
@@ -89,18 +90,16 @@ export default class ElementUtility {
89
90
  node: INode
90
91
  ): INode {
91
92
  if (node.nodeType === NodeTypeEnum.elementNode) {
92
- const index = ancestorNode.children.indexOf(<IElement>node);
93
+ const ancestorNodeChildren = <HTMLCollection<IHTMLElement>>(<Element>ancestorNode)._children;
94
+ const index = ancestorNodeChildren.indexOf(<IElement>node);
93
95
  if (index !== -1) {
94
96
  for (const attributeName of NAMED_ITEM_ATTRIBUTES) {
95
97
  const attribute = (<Element>node).attributes.getNamedItem(attributeName);
96
98
  if (attribute) {
97
- (<HTMLCollection<IHTMLElement>>ancestorNode.children)._removeNamedItem(
98
- <IHTMLElement>node,
99
- attribute.value
100
- );
99
+ ancestorNodeChildren._removeNamedItem(<IHTMLElement>node, attribute.value);
101
100
  }
102
101
  }
103
- ancestorNode.children.splice(index, 1);
102
+ ancestorNodeChildren.splice(index, 1);
104
103
  }
105
104
  }
106
105
 
@@ -137,37 +136,42 @@ export default class ElementUtility {
137
136
  DOMExceptionNameEnum.domException
138
137
  );
139
138
  }
139
+ if (newNode.parentNode) {
140
+ const parentNodeChildren = <HTMLCollection<IHTMLElement>>(
141
+ (<Element>newNode.parentNode)._children
142
+ );
140
143
 
141
- if (newNode.parentNode && (<IHTMLElement>newNode.parentNode).children) {
142
- const index = (<IHTMLElement>newNode.parentNode).children.indexOf(<IHTMLElement>newNode);
143
- if (index !== -1) {
144
- for (const attributeName of NAMED_ITEM_ATTRIBUTES) {
145
- const attribute = (<Element>newNode).attributes.getNamedItem(attributeName);
146
- if (attribute) {
147
- (<HTMLCollection<IHTMLElement>>(
148
- (<IElement>newNode.parentNode).children
149
- ))._removeNamedItem(<IHTMLElement>newNode, attribute.value);
144
+ if (parentNodeChildren) {
145
+ const index = parentNodeChildren.indexOf(<IHTMLElement>newNode);
146
+ if (index !== -1) {
147
+ for (const attributeName of NAMED_ITEM_ATTRIBUTES) {
148
+ const attribute = (<Element>newNode).attributes.getNamedItem(attributeName);
149
+ if (attribute) {
150
+ parentNodeChildren._removeNamedItem(<IHTMLElement>newNode, attribute.value);
151
+ }
150
152
  }
151
- }
152
153
 
153
- (<IElement>newNode.parentNode).children.splice(index, 1);
154
+ parentNodeChildren.splice(index, 1);
155
+ }
154
156
  }
155
157
  }
156
158
 
159
+ const ancestorNodeChildren = <HTMLCollection<IHTMLElement>>(<Element>ancestorNode)._children;
160
+
157
161
  if (referenceNode.nodeType === NodeTypeEnum.elementNode) {
158
- const index = ancestorNode.children.indexOf(<IElement>referenceNode);
162
+ const index = ancestorNodeChildren.indexOf(<IElement>referenceNode);
159
163
  if (index !== -1) {
160
- ancestorNode.children.splice(index, 0, <IElement>newNode);
164
+ ancestorNodeChildren.splice(index, 0, <IElement>newNode);
161
165
  }
162
166
  } else {
163
- ancestorNode.children.length = 0;
167
+ ancestorNodeChildren.length = 0;
164
168
 
165
- for (const node of ancestorNode.childNodes) {
169
+ for (const node of (<Element>ancestorNode)._childNodes) {
166
170
  if (node === referenceNode) {
167
- ancestorNode.children.push(<IElement>newNode);
171
+ ancestorNodeChildren.push(<IElement>newNode);
168
172
  }
169
173
  if (node.nodeType === NodeTypeEnum.elementNode) {
170
- ancestorNode.children.push(<IElement>node);
174
+ ancestorNodeChildren.push(<IElement>node);
171
175
  }
172
176
  }
173
177
  }
@@ -175,10 +179,7 @@ export default class ElementUtility {
175
179
  for (const attributeName of NAMED_ITEM_ATTRIBUTES) {
176
180
  const attribute = (<Element>newNode).attributes.getNamedItem(attributeName);
177
181
  if (attribute) {
178
- (<HTMLCollection<IHTMLElement>>ancestorNode.children)._appendNamedItem(
179
- <IHTMLElement>newNode,
180
- attribute.value
181
- );
182
+ ancestorNodeChildren._appendNamedItem(<IHTMLElement>newNode, attribute.value);
182
183
  }
183
184
  }
184
185
 
@@ -95,7 +95,7 @@ export default class HTMLElement extends Element implements IHTMLElement {
95
95
 
96
96
  let result = '';
97
97
 
98
- for (const childNode of this.childNodes) {
98
+ for (const childNode of this._childNodes) {
99
99
  if (childNode.nodeType === NodeTypeEnum.elementNode) {
100
100
  const childElement = <IHTMLElement>childNode;
101
101
  const computedStyle = this.ownerDocument.defaultView.getComputedStyle(childElement);
@@ -141,7 +141,7 @@ export default class HTMLElement extends Element implements IHTMLElement {
141
141
  * @param innerText Inner text.
142
142
  */
143
143
  public set innerText(text: string) {
144
- for (const child of this.childNodes.slice()) {
144
+ for (const child of this._childNodes.slice()) {
145
145
  this.removeChild(child);
146
146
  }
147
147
 
@@ -62,7 +62,7 @@ export default class HTMLSlotElement extends HTMLElement implements IHTMLSlotEle
62
62
  return this.assignedElements(options);
63
63
  }
64
64
 
65
- return host.childNodes.slice();
65
+ return (<HTMLElement>host)._childNodes.slice();
66
66
  }
67
67
 
68
68
  return [];
@@ -86,7 +86,7 @@ export default class HTMLSlotElement extends HTMLElement implements IHTMLSlotEle
86
86
  if (name) {
87
87
  const assignedElements = [];
88
88
 
89
- for (const child of host.children) {
89
+ for (const child of (<HTMLElement>host)._children) {
90
90
  if (child.slot === name) {
91
91
  assignedElements.push(child);
92
92
  }
@@ -95,7 +95,7 @@ export default class HTMLSlotElement extends HTMLElement implements IHTMLSlotEle
95
95
  return assignedElements;
96
96
  }
97
97
 
98
- return host.children.slice();
98
+ return (<HTMLElement>host)._children.slice();
99
99
  }
100
100
 
101
101
  return [];
@@ -4,6 +4,7 @@ import INode from '../node/INode.js';
4
4
  import IHTMLTemplateElement from './IHTMLTemplateElement.js';
5
5
  import XMLSerializer from '../../xml-serializer/XMLSerializer.js';
6
6
  import XMLParser from '../../xml-parser/XMLParser.js';
7
+ import DocumentFragment from '../document-fragment/DocumentFragment.js';
7
8
 
8
9
  /**
9
10
  * HTML Template Element.
@@ -25,7 +26,7 @@ export default class HTMLTemplateElement extends HTMLElement implements IHTMLTem
25
26
  * @override
26
27
  */
27
28
  public set innerHTML(html: string) {
28
- for (const child of this.content.childNodes.slice()) {
29
+ for (const child of (<DocumentFragment>this.content)._childNodes.slice()) {
29
30
  this.content.removeChild(child);
30
31
  }
31
32
 
@@ -55,7 +56,7 @@ export default class HTMLTemplateElement extends HTMLElement implements IHTMLTem
55
56
  escapeEntities: false
56
57
  });
57
58
  let xml = '';
58
- for (const node of this.content.childNodes) {
59
+ for (const node of (<DocumentFragment>this.content)._childNodes) {
59
60
  xml += xmlSerializer.serializeToString(node);
60
61
  }
61
62
  return xml;
@@ -34,8 +34,8 @@ export default class HTMLUnknownElement extends HTMLElement implements IHTMLElem
34
34
  const callback = (): void => {
35
35
  if (this.parentNode) {
36
36
  const newElement = <HTMLElement>this.ownerDocument.createElement(tagName);
37
- (<INodeList<INode>>newElement.childNodes) = this.childNodes;
38
- (<IHTMLCollection<IElement>>newElement.children) = this.children;
37
+ (<INodeList<INode>>newElement._childNodes) = this._childNodes;
38
+ (<IHTMLCollection<IElement>>newElement._children) = this._children;
39
39
  (<boolean>newElement.isConnected) = this.isConnected;
40
40
 
41
41
  newElement._rootNode = this._rootNode;
@@ -49,8 +49,8 @@ export default class HTMLUnknownElement extends HTMLElement implements IHTMLElem
49
49
  newElement.attributes.setNamedItem(this.attributes[i]);
50
50
  }
51
51
 
52
- (<INodeList<INode>>this.childNodes) = new NodeList();
53
- (<IHTMLCollection<IElement>>this.children) = new HTMLCollection();
52
+ (<INodeList<INode>>this._childNodes) = new NodeList();
53
+ (<IHTMLCollection<IElement>>this._children) = new HTMLCollection();
54
54
  this._rootNode = null;
55
55
  this._formNode = null;
56
56
  this._selectNode = null;
@@ -59,17 +59,17 @@ export default class HTMLUnknownElement extends HTMLElement implements IHTMLElem
59
59
  this._isValue = null;
60
60
  (<HTMLElementNamedNodeMap>this.attributes) = new HTMLElementNamedNodeMap(this);
61
61
 
62
- for (let i = 0, max = this.parentNode.childNodes.length; i < max; i++) {
63
- if (this.parentNode.childNodes[i] === this) {
64
- this.parentNode.childNodes[i] = newElement;
62
+ for (let i = 0, max = (<HTMLElement>this.parentNode)._childNodes.length; i < max; i++) {
63
+ if ((<HTMLElement>this.parentNode)._childNodes[i] === this) {
64
+ (<HTMLElement>this.parentNode)._childNodes[i] = newElement;
65
65
  break;
66
66
  }
67
67
  }
68
68
 
69
- if ((<IElement>this.parentNode).children) {
70
- for (let i = 0, max = (<IElement>this.parentNode).children.length; i < max; i++) {
71
- if ((<IElement>this.parentNode).children[i] === this) {
72
- (<IElement>this.parentNode).children[i] = newElement;
69
+ if ((<HTMLElement>this.parentNode)._children) {
70
+ for (let i = 0, max = (<HTMLElement>this.parentNode)._children.length; i < max; i++) {
71
+ if ((<HTMLElement>this.parentNode)._children[i] === this) {
72
+ (<HTMLElement>this.parentNode)._children[i] = newElement;
73
73
  break;
74
74
  }
75
75
  }