happy-dom 10.10.3 → 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.
- package/cjs/css/declaration/property-manager/CSSStyleDeclarationValueParser.cjs +1 -1
- package/cjs/css/declaration/property-manager/CSSStyleDeclarationValueParser.cjs.map +1 -1
- package/cjs/dom-parser/DOMParser.cjs +5 -5
- package/cjs/dom-parser/DOMParser.cjs.map +1 -1
- package/cjs/dom-parser/DOMParser.d.ts.map +1 -1
- package/cjs/nodes/child-node/ChildNodeUtility.cjs +3 -3
- package/cjs/nodes/child-node/ChildNodeUtility.cjs.map +1 -1
- package/cjs/nodes/child-node/ChildNodeUtility.d.ts.map +1 -1
- package/cjs/nodes/document/Document.cjs +24 -18
- package/cjs/nodes/document/Document.cjs.map +1 -1
- package/cjs/nodes/document/Document.d.ts +5 -1
- package/cjs/nodes/document/Document.d.ts.map +1 -1
- package/cjs/nodes/document-fragment/DocumentFragment.cjs +14 -8
- package/cjs/nodes/document-fragment/DocumentFragment.cjs.map +1 -1
- package/cjs/nodes/document-fragment/DocumentFragment.d.ts +5 -1
- package/cjs/nodes/document-fragment/DocumentFragment.d.ts.map +1 -1
- package/cjs/nodes/element/Element.cjs +17 -11
- package/cjs/nodes/element/Element.cjs.map +1 -1
- package/cjs/nodes/element/Element.d.ts +5 -1
- package/cjs/nodes/element/Element.d.ts.map +1 -1
- package/cjs/nodes/element/ElementNamedNodeMap.cjs +5 -5
- package/cjs/nodes/element/ElementNamedNodeMap.cjs.map +1 -1
- package/cjs/nodes/element/ElementUtility.cjs +37 -28
- package/cjs/nodes/element/ElementUtility.cjs.map +1 -1
- package/cjs/nodes/element/ElementUtility.d.ts.map +1 -1
- package/cjs/nodes/html-element/HTMLElement.cjs +2 -2
- package/cjs/nodes/html-element/HTMLElement.cjs.map +1 -1
- package/cjs/nodes/html-slot-element/HTMLSlotElement.cjs +3 -3
- package/cjs/nodes/html-slot-element/HTMLSlotElement.cjs.map +1 -1
- package/cjs/nodes/html-template-element/HTMLTemplateElement.cjs +2 -2
- package/cjs/nodes/html-template-element/HTMLTemplateElement.cjs.map +1 -1
- package/cjs/nodes/html-template-element/HTMLTemplateElement.d.ts.map +1 -1
- package/cjs/nodes/html-unknown-element/HTMLUnknownElement.cjs +11 -11
- package/cjs/nodes/html-unknown-element/HTMLUnknownElement.cjs.map +1 -1
- package/cjs/nodes/node/Node.cjs +29 -21
- package/cjs/nodes/node/Node.cjs.map +1 -1
- package/cjs/nodes/node/Node.d.ts +7 -1
- package/cjs/nodes/node/Node.d.ts.map +1 -1
- package/cjs/nodes/node/NodeUtility.cjs +17 -17
- package/cjs/nodes/node/NodeUtility.cjs.map +1 -1
- package/cjs/nodes/node/NodeUtility.d.ts.map +1 -1
- package/cjs/nodes/parent-node/ParentNodeUtility.cjs +7 -7
- package/cjs/nodes/parent-node/ParentNodeUtility.cjs.map +1 -1
- package/cjs/nodes/parent-node/ParentNodeUtility.d.ts.map +1 -1
- package/cjs/nodes/shadow-root/ShadowRoot.cjs +2 -2
- package/cjs/nodes/shadow-root/ShadowRoot.cjs.map +1 -1
- package/cjs/query-selector/QuerySelector.cjs +10 -8
- package/cjs/query-selector/QuerySelector.cjs.map +1 -1
- package/cjs/query-selector/QuerySelector.d.ts.map +1 -1
- package/cjs/query-selector/SelectorItem.cjs +15 -14
- package/cjs/query-selector/SelectorItem.cjs.map +1 -1
- package/cjs/query-selector/SelectorItem.d.ts.map +1 -1
- package/cjs/range/Range.cjs +12 -12
- package/cjs/range/Range.cjs.map +1 -1
- package/cjs/range/Range.d.ts.map +1 -1
- package/cjs/range/RangeUtility.cjs +1 -1
- package/cjs/range/RangeUtility.cjs.map +1 -1
- package/cjs/range/RangeUtility.d.ts.map +1 -1
- package/cjs/tree-walker/TreeWalker.cjs +4 -4
- package/cjs/tree-walker/TreeWalker.cjs.map +1 -1
- package/cjs/xml-serializer/XMLSerializer.cjs +4 -4
- package/cjs/xml-serializer/XMLSerializer.cjs.map +1 -1
- package/cjs/xml-serializer/XMLSerializer.d.ts.map +1 -1
- package/lib/css/declaration/property-manager/CSSStyleDeclarationValueParser.js +1 -1
- package/lib/css/declaration/property-manager/CSSStyleDeclarationValueParser.js.map +1 -1
- package/lib/dom-parser/DOMParser.d.ts.map +1 -1
- package/lib/dom-parser/DOMParser.js +5 -5
- package/lib/dom-parser/DOMParser.js.map +1 -1
- package/lib/nodes/child-node/ChildNodeUtility.d.ts.map +1 -1
- package/lib/nodes/child-node/ChildNodeUtility.js +3 -3
- package/lib/nodes/child-node/ChildNodeUtility.js.map +1 -1
- package/lib/nodes/document/Document.d.ts +5 -1
- package/lib/nodes/document/Document.d.ts.map +1 -1
- package/lib/nodes/document/Document.js +24 -18
- package/lib/nodes/document/Document.js.map +1 -1
- package/lib/nodes/document-fragment/DocumentFragment.d.ts +5 -1
- package/lib/nodes/document-fragment/DocumentFragment.d.ts.map +1 -1
- package/lib/nodes/document-fragment/DocumentFragment.js +14 -8
- package/lib/nodes/document-fragment/DocumentFragment.js.map +1 -1
- package/lib/nodes/element/Element.d.ts +5 -1
- package/lib/nodes/element/Element.d.ts.map +1 -1
- package/lib/nodes/element/Element.js +17 -11
- package/lib/nodes/element/Element.js.map +1 -1
- package/lib/nodes/element/ElementNamedNodeMap.js +5 -5
- package/lib/nodes/element/ElementNamedNodeMap.js.map +1 -1
- package/lib/nodes/element/ElementUtility.d.ts.map +1 -1
- package/lib/nodes/element/ElementUtility.js +37 -28
- package/lib/nodes/element/ElementUtility.js.map +1 -1
- package/lib/nodes/html-element/HTMLElement.js +2 -2
- package/lib/nodes/html-element/HTMLElement.js.map +1 -1
- package/lib/nodes/html-slot-element/HTMLSlotElement.js +3 -3
- package/lib/nodes/html-slot-element/HTMLSlotElement.js.map +1 -1
- package/lib/nodes/html-template-element/HTMLTemplateElement.d.ts.map +1 -1
- package/lib/nodes/html-template-element/HTMLTemplateElement.js +2 -2
- package/lib/nodes/html-template-element/HTMLTemplateElement.js.map +1 -1
- package/lib/nodes/html-unknown-element/HTMLUnknownElement.js +11 -11
- package/lib/nodes/html-unknown-element/HTMLUnknownElement.js.map +1 -1
- package/lib/nodes/node/Node.d.ts +7 -1
- package/lib/nodes/node/Node.d.ts.map +1 -1
- package/lib/nodes/node/Node.js +29 -21
- package/lib/nodes/node/Node.js.map +1 -1
- package/lib/nodes/node/NodeUtility.d.ts.map +1 -1
- package/lib/nodes/node/NodeUtility.js +17 -17
- package/lib/nodes/node/NodeUtility.js.map +1 -1
- package/lib/nodes/parent-node/ParentNodeUtility.d.ts.map +1 -1
- package/lib/nodes/parent-node/ParentNodeUtility.js +7 -7
- package/lib/nodes/parent-node/ParentNodeUtility.js.map +1 -1
- package/lib/nodes/shadow-root/ShadowRoot.js +2 -2
- package/lib/nodes/shadow-root/ShadowRoot.js.map +1 -1
- package/lib/query-selector/QuerySelector.d.ts.map +1 -1
- package/lib/query-selector/QuerySelector.js +10 -8
- package/lib/query-selector/QuerySelector.js.map +1 -1
- package/lib/query-selector/SelectorItem.d.ts.map +1 -1
- package/lib/query-selector/SelectorItem.js +15 -14
- package/lib/query-selector/SelectorItem.js.map +1 -1
- package/lib/range/Range.d.ts.map +1 -1
- package/lib/range/Range.js +12 -12
- package/lib/range/Range.js.map +1 -1
- package/lib/range/RangeUtility.d.ts.map +1 -1
- package/lib/range/RangeUtility.js +1 -1
- package/lib/range/RangeUtility.js.map +1 -1
- package/lib/tree-walker/TreeWalker.js +4 -4
- package/lib/tree-walker/TreeWalker.js.map +1 -1
- package/lib/xml-serializer/XMLSerializer.d.ts.map +1 -1
- package/lib/xml-serializer/XMLSerializer.js +4 -4
- package/lib/xml-serializer/XMLSerializer.js.map +1 -1
- package/package.json +1 -1
- package/src/css/declaration/property-manager/CSSStyleDeclarationValueParser.ts +1 -1
- package/src/dom-parser/DOMParser.ts +9 -7
- package/src/nodes/child-node/ChildNodeUtility.ts +10 -12
- package/src/nodes/document/Document.ts +29 -22
- package/src/nodes/document-fragment/DocumentFragment.ts +16 -9
- package/src/nodes/element/Element.ts +23 -12
- package/src/nodes/element/ElementNamedNodeMap.ts +5 -5
- package/src/nodes/element/ElementUtility.ts +44 -43
- package/src/nodes/html-element/HTMLElement.ts +2 -2
- package/src/nodes/html-slot-element/HTMLSlotElement.ts +3 -3
- package/src/nodes/html-template-element/HTMLTemplateElement.ts +3 -2
- package/src/nodes/html-unknown-element/HTMLUnknownElement.ts +11 -11
- package/src/nodes/node/Node.ts +30 -21
- package/src/nodes/node/NodeUtility.ts +21 -17
- package/src/nodes/parent-node/ParentNodeUtility.ts +10 -10
- package/src/nodes/shadow-root/ShadowRoot.ts +2 -2
- package/src/query-selector/QuerySelector.ts +24 -8
- package/src/query-selector/SelectorItem.ts +15 -14
- package/src/range/Range.ts +13 -12
- package/src/range/RangeUtility.ts +2 -1
- package/src/tree-walker/TreeWalker.ts +4 -4
- package/src/xml-serializer/XMLSerializer.ts +6 -4
@@ -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.
|
38
|
-
(<IHTMLCollection<IElement>>newElement.
|
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.
|
53
|
-
(<IHTMLCollection<IElement>>this.
|
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.
|
63
|
-
if (this.parentNode.
|
64
|
-
this.parentNode.
|
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 ((<
|
70
|
-
for (let i = 0, max = (<
|
71
|
-
if ((<
|
72
|
-
(<
|
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
|
}
|
package/src/nodes/node/Node.ts
CHANGED
@@ -54,7 +54,6 @@ export default class Node extends EventTarget implements INode {
|
|
54
54
|
public readonly ownerDocument: IDocument = null;
|
55
55
|
public readonly parentNode: INode = null;
|
56
56
|
public readonly nodeType: number;
|
57
|
-
public readonly childNodes: INodeList<INode> = new NodeList<INode>();
|
58
57
|
public readonly isConnected: boolean = false;
|
59
58
|
|
60
59
|
// Custom Properties (not part of HTML standard)
|
@@ -63,6 +62,7 @@ export default class Node extends EventTarget implements INode {
|
|
63
62
|
public _selectNode: INode = null;
|
64
63
|
public _textAreaNode: INode = null;
|
65
64
|
public _observers: MutationListener[] = [];
|
65
|
+
public readonly _childNodes: INodeList<INode> = new NodeList<INode>();
|
66
66
|
|
67
67
|
/**
|
68
68
|
* Constructor.
|
@@ -81,6 +81,15 @@ export default class Node extends EventTarget implements INode {
|
|
81
81
|
return this.constructor.name;
|
82
82
|
}
|
83
83
|
|
84
|
+
/**
|
85
|
+
* Get child nodes.
|
86
|
+
*
|
87
|
+
* @returns Child nodes list.
|
88
|
+
*/
|
89
|
+
public get childNodes(): INodeList<INode> {
|
90
|
+
return this._childNodes;
|
91
|
+
}
|
92
|
+
|
84
93
|
/**
|
85
94
|
* Get text value of children.
|
86
95
|
*
|
@@ -133,9 +142,9 @@ export default class Node extends EventTarget implements INode {
|
|
133
142
|
*/
|
134
143
|
public get previousSibling(): INode {
|
135
144
|
if (this.parentNode) {
|
136
|
-
const index = this.parentNode.
|
145
|
+
const index = (<Node>this.parentNode)._childNodes.indexOf(this);
|
137
146
|
if (index > 0) {
|
138
|
-
return this.parentNode.
|
147
|
+
return (<Node>this.parentNode)._childNodes[index - 1];
|
139
148
|
}
|
140
149
|
}
|
141
150
|
return null;
|
@@ -148,9 +157,9 @@ export default class Node extends EventTarget implements INode {
|
|
148
157
|
*/
|
149
158
|
public get nextSibling(): INode {
|
150
159
|
if (this.parentNode) {
|
151
|
-
const index = this.parentNode.
|
152
|
-
if (index > -1 && index + 1 < this.parentNode.
|
153
|
-
return this.parentNode.
|
160
|
+
const index = (<Node>this.parentNode)._childNodes.indexOf(this);
|
161
|
+
if (index > -1 && index + 1 < (<Node>this.parentNode)._childNodes.length) {
|
162
|
+
return (<Node>this.parentNode)._childNodes[index + 1];
|
154
163
|
}
|
155
164
|
}
|
156
165
|
return null;
|
@@ -162,8 +171,8 @@ export default class Node extends EventTarget implements INode {
|
|
162
171
|
* @returns Node.
|
163
172
|
*/
|
164
173
|
public get firstChild(): INode {
|
165
|
-
if (this.
|
166
|
-
return this.
|
174
|
+
if (this._childNodes.length > 0) {
|
175
|
+
return this._childNodes[0];
|
167
176
|
}
|
168
177
|
return null;
|
169
178
|
}
|
@@ -174,8 +183,8 @@ export default class Node extends EventTarget implements INode {
|
|
174
183
|
* @returns Node.
|
175
184
|
*/
|
176
185
|
public get lastChild(): INode {
|
177
|
-
if (this.
|
178
|
-
return this.
|
186
|
+
if (this._childNodes.length > 0) {
|
187
|
+
return this._childNodes[this._childNodes.length - 1];
|
179
188
|
}
|
180
189
|
return null;
|
181
190
|
}
|
@@ -222,7 +231,7 @@ export default class Node extends EventTarget implements INode {
|
|
222
231
|
* @returns "true" if the node has child nodes.
|
223
232
|
*/
|
224
233
|
public hasChildNodes(): boolean {
|
225
|
-
return this.
|
234
|
+
return this._childNodes.length > 0;
|
226
235
|
}
|
227
236
|
|
228
237
|
/**
|
@@ -264,17 +273,17 @@ export default class Node extends EventTarget implements INode {
|
|
264
273
|
const clone = new (<typeof Node>this.constructor)();
|
265
274
|
|
266
275
|
// Document has childNodes directly when it is created
|
267
|
-
if (clone.
|
268
|
-
for (const node of clone.
|
276
|
+
if (clone._childNodes.length) {
|
277
|
+
for (const node of clone._childNodes.slice()) {
|
269
278
|
node.parentNode.removeChild(node);
|
270
279
|
}
|
271
280
|
}
|
272
281
|
|
273
282
|
if (deep) {
|
274
|
-
for (const childNode of this.
|
283
|
+
for (const childNode of this._childNodes) {
|
275
284
|
const childClone = childNode.cloneNode(true);
|
276
285
|
(<Node>childClone.parentNode) = clone;
|
277
|
-
clone.
|
286
|
+
clone._childNodes.push(childClone);
|
278
287
|
}
|
279
288
|
}
|
280
289
|
|
@@ -351,7 +360,7 @@ export default class Node extends EventTarget implements INode {
|
|
351
360
|
public _observe(listener: MutationListener): void {
|
352
361
|
this._observers.push(listener);
|
353
362
|
if (listener.options.subtree) {
|
354
|
-
for (const node of this.
|
363
|
+
for (const node of this._childNodes) {
|
355
364
|
(<Node>node)._observe(listener);
|
356
365
|
}
|
357
366
|
}
|
@@ -369,7 +378,7 @@ export default class Node extends EventTarget implements INode {
|
|
369
378
|
this._observers.splice(index, 1);
|
370
379
|
}
|
371
380
|
if (listener.options.subtree) {
|
372
|
-
for (const node of this.
|
381
|
+
for (const node of this._childNodes) {
|
373
382
|
(<Node>node)._unobserve(listener);
|
374
383
|
}
|
375
384
|
}
|
@@ -418,7 +427,7 @@ export default class Node extends EventTarget implements INode {
|
|
418
427
|
this.disconnectedCallback();
|
419
428
|
}
|
420
429
|
|
421
|
-
for (const child of this.
|
430
|
+
for (const child of this._childNodes) {
|
422
431
|
(<Node>child)._connectToNode(this);
|
423
432
|
}
|
424
433
|
|
@@ -432,7 +441,7 @@ export default class Node extends EventTarget implements INode {
|
|
432
441
|
selectNode !== this._selectNode ||
|
433
442
|
textAreaNode !== this._textAreaNode
|
434
443
|
) {
|
435
|
-
for (const child of this.
|
444
|
+
for (const child of this._childNodes) {
|
436
445
|
(<Node>child)._connectToNode(this);
|
437
446
|
}
|
438
447
|
}
|
@@ -584,7 +593,7 @@ export default class Node extends EventTarget implements INode {
|
|
584
593
|
|
585
594
|
const computeNodeIndexes = (nodes: INode[]): void => {
|
586
595
|
for (const childNode of nodes) {
|
587
|
-
computeNodeIndexes(childNode.
|
596
|
+
computeNodeIndexes((<Node>childNode)._childNodes);
|
588
597
|
|
589
598
|
if (childNode === node2Node) {
|
590
599
|
node2Index = indexes;
|
@@ -600,7 +609,7 @@ export default class Node extends EventTarget implements INode {
|
|
600
609
|
}
|
601
610
|
};
|
602
611
|
|
603
|
-
computeNodeIndexes(commonAncestor.
|
612
|
+
computeNodeIndexes((<Node>commonAncestor)._childNodes);
|
604
613
|
|
605
614
|
/**
|
606
615
|
* 9. If node1 is preceding node2, then return DOCUMENT_POSITION_PRECEDING.
|
@@ -47,7 +47,7 @@ export default class NodeUtility {
|
|
47
47
|
// If the type is DocumentFragment, then the child nodes of if it should be moved instead of the actual node.
|
48
48
|
// See: https://developer.mozilla.org/en-US/docs/Web/API/DocumentFragment
|
49
49
|
if (node.nodeType === NodeTypeEnum.documentFragmentNode) {
|
50
|
-
for (const child of node.
|
50
|
+
for (const child of (<Node>node)._childNodes.slice()) {
|
51
51
|
ancestorNode.appendChild(child);
|
52
52
|
}
|
53
53
|
return node;
|
@@ -55,9 +55,9 @@ export default class NodeUtility {
|
|
55
55
|
|
56
56
|
// Remove the node from its previous parent if it has any.
|
57
57
|
if (node.parentNode) {
|
58
|
-
const index = node.parentNode.
|
58
|
+
const index = (<Node>node.parentNode)._childNodes.indexOf(node);
|
59
59
|
if (index !== -1) {
|
60
|
-
node.parentNode.
|
60
|
+
(<Node>node.parentNode)._childNodes.splice(index, 1);
|
61
61
|
}
|
62
62
|
}
|
63
63
|
|
@@ -65,7 +65,7 @@ export default class NodeUtility {
|
|
65
65
|
(ancestorNode.ownerDocument || this)['_cacheID']++;
|
66
66
|
}
|
67
67
|
|
68
|
-
ancestorNode.
|
68
|
+
(<Node>ancestorNode)._childNodes.push(node);
|
69
69
|
|
70
70
|
(<Node>node)._connectToNode(ancestorNode);
|
71
71
|
|
@@ -97,7 +97,7 @@ export default class NodeUtility {
|
|
97
97
|
* @returns Removed node.
|
98
98
|
*/
|
99
99
|
public static removeChild(ancestorNode: INode, node: INode): INode {
|
100
|
-
const index = ancestorNode.
|
100
|
+
const index = (<Node>ancestorNode)._childNodes.indexOf(node);
|
101
101
|
|
102
102
|
if (index === -1) {
|
103
103
|
throw new DOMException('Failed to remove node. Node is not child of parent.');
|
@@ -107,7 +107,7 @@ export default class NodeUtility {
|
|
107
107
|
(ancestorNode.ownerDocument || this)['_cacheID']++;
|
108
108
|
}
|
109
109
|
|
110
|
-
ancestorNode.
|
110
|
+
(<Node>ancestorNode)._childNodes.splice(index, 1);
|
111
111
|
|
112
112
|
(<Node>node)._connectToNode(null);
|
113
113
|
|
@@ -158,7 +158,7 @@ export default class NodeUtility {
|
|
158
158
|
// If the type is DocumentFragment, then the child nodes of if it should be moved instead of the actual node.
|
159
159
|
// See: https://developer.mozilla.org/en-US/docs/Web/API/DocumentFragment
|
160
160
|
if (newNode.nodeType === Node.DOCUMENT_FRAGMENT_NODE) {
|
161
|
-
for (const child of newNode.
|
161
|
+
for (const child of (<Node>newNode)._childNodes.slice()) {
|
162
162
|
ancestorNode.insertBefore(child, referenceNode);
|
163
163
|
}
|
164
164
|
return newNode;
|
@@ -171,7 +171,7 @@ export default class NodeUtility {
|
|
171
171
|
return newNode;
|
172
172
|
}
|
173
173
|
|
174
|
-
if (ancestorNode.
|
174
|
+
if ((<Node>ancestorNode)._childNodes.indexOf(referenceNode) === -1) {
|
175
175
|
throw new DOMException(
|
176
176
|
"Failed to execute 'insertBefore' on 'Node': The node before which the new node is to be inserted is not a child of this node."
|
177
177
|
);
|
@@ -182,13 +182,17 @@ export default class NodeUtility {
|
|
182
182
|
}
|
183
183
|
|
184
184
|
if (newNode.parentNode) {
|
185
|
-
const index = newNode.parentNode.
|
185
|
+
const index = (<Node>newNode.parentNode)._childNodes.indexOf(newNode);
|
186
186
|
if (index !== -1) {
|
187
|
-
newNode.parentNode.
|
187
|
+
(<Node>newNode.parentNode)._childNodes.splice(index, 1);
|
188
188
|
}
|
189
189
|
}
|
190
190
|
|
191
|
-
ancestorNode.
|
191
|
+
(<Node>ancestorNode)._childNodes.splice(
|
192
|
+
(<Node>ancestorNode)._childNodes.indexOf(referenceNode),
|
193
|
+
0,
|
194
|
+
newNode
|
195
|
+
);
|
192
196
|
|
193
197
|
(<Node>newNode)._connectToNode(ancestorNode);
|
194
198
|
|
@@ -247,7 +251,7 @@ export default class NodeUtility {
|
|
247
251
|
return true;
|
248
252
|
}
|
249
253
|
|
250
|
-
if (!ancestorNode.
|
254
|
+
if (!(<Node>ancestorNode)._childNodes.length) {
|
251
255
|
return false;
|
252
256
|
}
|
253
257
|
|
@@ -330,7 +334,7 @@ export default class NodeUtility {
|
|
330
334
|
return (<IText | IComment>node).data.length;
|
331
335
|
|
332
336
|
default:
|
333
|
-
return node.
|
337
|
+
return (<Node>node)._childNodes.length;
|
334
338
|
}
|
335
339
|
}
|
336
340
|
|
@@ -488,13 +492,13 @@ export default class NodeUtility {
|
|
488
492
|
return false;
|
489
493
|
}
|
490
494
|
|
491
|
-
if (nodeA.
|
495
|
+
if ((<Node>nodeA)._childNodes.length !== (<Node>nodeB)._childNodes.length) {
|
492
496
|
return false;
|
493
497
|
}
|
494
498
|
|
495
|
-
for (let i = 0; i < nodeA.
|
496
|
-
const childNodeA = nodeA.
|
497
|
-
const childNodeB = nodeB.
|
499
|
+
for (let i = 0; i < (<Node>nodeA)._childNodes.length; i++) {
|
500
|
+
const childNodeA = (<Node>nodeA)._childNodes[i];
|
501
|
+
const childNodeB = (<Node>nodeB)._childNodes[i];
|
498
502
|
|
499
503
|
if (!NodeUtility.isEqualNode(childNodeA, childNodeB)) {
|
500
504
|
return false;
|
@@ -5,6 +5,7 @@ import IElement from '../element/IElement.js';
|
|
5
5
|
import IHTMLCollection from '../element/IHTMLCollection.js';
|
6
6
|
import INode from '../node/INode.js';
|
7
7
|
import HTMLCollection from '../element/HTMLCollection.js';
|
8
|
+
import DocumentFragment from '../document-fragment/DocumentFragment.js';
|
8
9
|
|
9
10
|
/**
|
10
11
|
* Parent node utility.
|
@@ -42,10 +43,9 @@ export default class ParentNodeUtility {
|
|
42
43
|
const firstChild = parentNode.firstChild;
|
43
44
|
for (const node of nodes) {
|
44
45
|
if (typeof node === 'string') {
|
45
|
-
const newChildNodes =
|
46
|
-
<IDocument>parentNode.ownerDocument,
|
47
|
-
|
48
|
-
).childNodes.slice();
|
46
|
+
const newChildNodes = (<DocumentFragment>(
|
47
|
+
XMLParser.parse(<IDocument>parentNode.ownerDocument, node)
|
48
|
+
))._childNodes.slice();
|
49
49
|
for (const newChildNode of newChildNodes) {
|
50
50
|
parentNode.insertBefore(newChildNode, firstChild);
|
51
51
|
}
|
@@ -65,7 +65,7 @@ export default class ParentNodeUtility {
|
|
65
65
|
parentNode: IElement | IDocument | IDocumentFragment,
|
66
66
|
...nodes: (string | INode)[]
|
67
67
|
): void {
|
68
|
-
for (const node of parentNode.
|
68
|
+
for (const node of (<DocumentFragment>parentNode)._childNodes.slice()) {
|
69
69
|
parentNode.removeChild(node);
|
70
70
|
}
|
71
71
|
|
@@ -84,7 +84,7 @@ export default class ParentNodeUtility {
|
|
84
84
|
): IHTMLCollection<IElement> {
|
85
85
|
let matches = new HTMLCollection<IElement>();
|
86
86
|
|
87
|
-
for (const child of parentNode.
|
87
|
+
for (const child of (<DocumentFragment>parentNode)._children) {
|
88
88
|
if (child.className.split(' ').includes(className)) {
|
89
89
|
matches.push(child);
|
90
90
|
}
|
@@ -111,7 +111,7 @@ export default class ParentNodeUtility {
|
|
111
111
|
const includeAll = tagName === '*';
|
112
112
|
let matches = new HTMLCollection<IElement>();
|
113
113
|
|
114
|
-
for (const child of parentNode.
|
114
|
+
for (const child of (<DocumentFragment>parentNode)._children) {
|
115
115
|
if (includeAll || child.tagName === upperTagName) {
|
116
116
|
matches.push(child);
|
117
117
|
}
|
@@ -140,7 +140,7 @@ export default class ParentNodeUtility {
|
|
140
140
|
const includeAll = tagName === '*';
|
141
141
|
let matches = new HTMLCollection<IElement>();
|
142
142
|
|
143
|
-
for (const child of parentNode.
|
143
|
+
for (const child of (<DocumentFragment>parentNode)._children) {
|
144
144
|
if ((includeAll || child.tagName === upperTagName) && child.namespaceURI === namespaceURI) {
|
145
145
|
matches.push(child);
|
146
146
|
}
|
@@ -166,7 +166,7 @@ export default class ParentNodeUtility {
|
|
166
166
|
): IElement {
|
167
167
|
const upperTagName = tagName.toUpperCase();
|
168
168
|
|
169
|
-
for (const child of parentNode.
|
169
|
+
for (const child of (<DocumentFragment>parentNode)._children) {
|
170
170
|
if (child.tagName === upperTagName) {
|
171
171
|
return <IElement>child;
|
172
172
|
}
|
@@ -191,7 +191,7 @@ export default class ParentNodeUtility {
|
|
191
191
|
id: string
|
192
192
|
): IElement {
|
193
193
|
id = String(id);
|
194
|
-
for (const child of parentNode.
|
194
|
+
for (const child of (<DocumentFragment>parentNode)._children) {
|
195
195
|
if (child.id === id) {
|
196
196
|
return <IElement>child;
|
197
197
|
}
|
@@ -28,7 +28,7 @@ export default class ShadowRoot extends DocumentFragment implements IShadowRoot
|
|
28
28
|
escapeEntities: false
|
29
29
|
});
|
30
30
|
let xml = '';
|
31
|
-
for (const node of this.
|
31
|
+
for (const node of this._childNodes) {
|
32
32
|
xml += xmlSerializer.serializeToString(node);
|
33
33
|
}
|
34
34
|
return xml;
|
@@ -40,7 +40,7 @@ export default class ShadowRoot extends DocumentFragment implements IShadowRoot
|
|
40
40
|
* @param html HTML.
|
41
41
|
*/
|
42
42
|
public set innerHTML(html: string) {
|
43
|
-
for (const child of this.
|
43
|
+
for (const child of this._childNodes.slice()) {
|
44
44
|
this.removeChild(child);
|
45
45
|
}
|
46
46
|
|
@@ -8,6 +8,7 @@ import IDocument from '../nodes/document/IDocument.js';
|
|
8
8
|
import IDocumentFragment from '../nodes/document-fragment/IDocumentFragment.js';
|
9
9
|
import SelectorParser from './SelectorParser.js';
|
10
10
|
import ISelectorMatch from './ISelectorMatch.js';
|
11
|
+
import Element from '../nodes/element/Element.js';
|
11
12
|
|
12
13
|
type IDocumentPositionAndElement = {
|
13
14
|
documentPosition: string;
|
@@ -48,7 +49,7 @@ export default class QuerySelector {
|
|
48
49
|
matches = matches.concat(
|
49
50
|
node.nodeType === NodeTypeEnum.elementNode
|
50
51
|
? this.findAll(<IElement>node, [<IElement>node], items)
|
51
|
-
: this.findAll(null, node.
|
52
|
+
: this.findAll(null, (<Element>node)._children, items)
|
52
53
|
);
|
53
54
|
}
|
54
55
|
|
@@ -92,7 +93,7 @@ export default class QuerySelector {
|
|
92
93
|
const match =
|
93
94
|
node.nodeType === NodeTypeEnum.elementNode
|
94
95
|
? this.findFirst(<IElement>node, [<IElement>node], items)
|
95
|
-
: this.findFirst(null, node.
|
96
|
+
: this.findFirst(null, (<Element>node)._children, items);
|
96
97
|
|
97
98
|
if (match) {
|
98
99
|
return match;
|
@@ -248,16 +249,24 @@ export default class QuerySelector {
|
|
248
249
|
case SelectorCombinatorEnum.descendant:
|
249
250
|
case SelectorCombinatorEnum.child:
|
250
251
|
matched = matched.concat(
|
251
|
-
this.findAll(
|
252
|
+
this.findAll(
|
253
|
+
rootElement,
|
254
|
+
(<Element>child)._children,
|
255
|
+
selectorItems.slice(1),
|
256
|
+
position
|
257
|
+
)
|
252
258
|
);
|
253
259
|
break;
|
254
260
|
}
|
255
261
|
}
|
256
262
|
}
|
257
263
|
|
258
|
-
if (
|
264
|
+
if (
|
265
|
+
selectorItem.combinator === SelectorCombinatorEnum.descendant &&
|
266
|
+
(<Element>child)._children.length
|
267
|
+
) {
|
259
268
|
matched = matched.concat(
|
260
|
-
this.findAll(rootElement, child.
|
269
|
+
this.findAll(rootElement, (<Element>child)._children, selectorItems, position)
|
261
270
|
);
|
262
271
|
}
|
263
272
|
}
|
@@ -303,7 +312,11 @@ export default class QuerySelector {
|
|
303
312
|
break;
|
304
313
|
case SelectorCombinatorEnum.descendant:
|
305
314
|
case SelectorCombinatorEnum.child:
|
306
|
-
const match = this.findFirst(
|
315
|
+
const match = this.findFirst(
|
316
|
+
rootElement,
|
317
|
+
(<Element>child)._children,
|
318
|
+
selectorItems.slice(1)
|
319
|
+
);
|
307
320
|
if (match) {
|
308
321
|
return match;
|
309
322
|
}
|
@@ -312,8 +325,11 @@ export default class QuerySelector {
|
|
312
325
|
}
|
313
326
|
}
|
314
327
|
|
315
|
-
if (
|
316
|
-
|
328
|
+
if (
|
329
|
+
selectorItem.combinator === SelectorCombinatorEnum.descendant &&
|
330
|
+
(<Element>child)._children.length
|
331
|
+
) {
|
332
|
+
const match = this.findFirst(rootElement, (<Element>child)._children, selectorItems);
|
317
333
|
|
318
334
|
if (match) {
|
319
335
|
return match;
|
@@ -112,6 +112,7 @@ export default class SelectorItem {
|
|
112
112
|
*/
|
113
113
|
private matchPsuedo(element: IElement): boolean {
|
114
114
|
const parent = <IElement>element.parentNode;
|
115
|
+
const parentChildren = element.parentNode ? (<Element>element.parentNode)._children : [];
|
115
116
|
|
116
117
|
if (!this.pseudos) {
|
117
118
|
return true;
|
@@ -150,21 +151,21 @@ export default class SelectorItem {
|
|
150
151
|
|
151
152
|
switch (psuedo.name) {
|
152
153
|
case 'first-child':
|
153
|
-
return
|
154
|
+
return parentChildren[0] === element;
|
154
155
|
case 'last-child':
|
155
|
-
return
|
156
|
+
return parentChildren.length && parentChildren[parentChildren.length - 1] === element;
|
156
157
|
case 'only-child':
|
157
|
-
return
|
158
|
+
return parentChildren.length === 1 && parentChildren[0] === element;
|
158
159
|
case 'first-of-type':
|
159
|
-
for (const child of
|
160
|
+
for (const child of parentChildren) {
|
160
161
|
if (child.tagName === element.tagName) {
|
161
162
|
return child === element;
|
162
163
|
}
|
163
164
|
}
|
164
165
|
return false;
|
165
166
|
case 'last-of-type':
|
166
|
-
for (let i =
|
167
|
-
const child =
|
167
|
+
for (let i = parentChildren.length - 1; i >= 0; i--) {
|
168
|
+
const child = parentChildren[i];
|
168
169
|
if (child.tagName === element.tagName) {
|
169
170
|
return child === element;
|
170
171
|
}
|
@@ -172,7 +173,7 @@ export default class SelectorItem {
|
|
172
173
|
return false;
|
173
174
|
case 'only-of-type':
|
174
175
|
let isFound = false;
|
175
|
-
for (const child of
|
176
|
+
for (const child of parentChildren) {
|
176
177
|
if (child.tagName === element.tagName) {
|
177
178
|
if (isFound || child !== element) {
|
178
179
|
return false;
|
@@ -184,34 +185,34 @@ export default class SelectorItem {
|
|
184
185
|
case 'checked':
|
185
186
|
return element.tagName === 'INPUT' && (<IHTMLInputElement>element).checked;
|
186
187
|
case 'empty':
|
187
|
-
return !element.
|
188
|
+
return !(<Element>element)._children.length;
|
188
189
|
case 'root':
|
189
190
|
return element.tagName === 'HTML';
|
190
191
|
case 'not':
|
191
192
|
return !psuedo.selectorItem.match(element);
|
192
193
|
case 'nth-child':
|
193
194
|
const nthChildIndex = psuedo.selectorItem
|
194
|
-
?
|
195
|
-
:
|
195
|
+
? parentChildren.filter((child) => psuedo.selectorItem.match(child)).indexOf(element)
|
196
|
+
: parentChildren.indexOf(element);
|
196
197
|
return nthChildIndex !== -1 && psuedo.nthFunction(nthChildIndex + 1);
|
197
198
|
case 'nth-of-type':
|
198
199
|
if (!element.parentNode) {
|
199
200
|
return false;
|
200
201
|
}
|
201
|
-
const nthOfTypeIndex =
|
202
|
+
const nthOfTypeIndex = parentChildren
|
202
203
|
.filter((child) => child.tagName === element.tagName)
|
203
204
|
.indexOf(element);
|
204
205
|
return nthOfTypeIndex !== -1 && psuedo.nthFunction(nthOfTypeIndex + 1);
|
205
206
|
case 'nth-last-child':
|
206
207
|
const nthLastChildIndex = psuedo.selectorItem
|
207
|
-
?
|
208
|
+
? parentChildren
|
208
209
|
.filter((child) => psuedo.selectorItem.match(child))
|
209
210
|
.reverse()
|
210
211
|
.indexOf(element)
|
211
|
-
:
|
212
|
+
: parentChildren.reverse().indexOf(element);
|
212
213
|
return nthLastChildIndex !== -1 && psuedo.nthFunction(nthLastChildIndex + 1);
|
213
214
|
case 'nth-last-of-type':
|
214
|
-
const nthLastOfTypeIndex =
|
215
|
+
const nthLastOfTypeIndex = parentChildren
|
215
216
|
.filter((child) => child.tagName === element.tagName)
|
216
217
|
.reverse()
|
217
218
|
.indexOf(element);
|