@remote-dom/polyfill 1.5.1 → 1.6.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.
- package/CHANGELOG.md +88 -0
- package/README.md +51 -3
- package/build/cjs/Attr.cjs +33 -4
- package/build/cjs/CharacterData.cjs +10 -0
- package/build/cjs/ChildNode.cjs +79 -13
- package/build/cjs/Comment.cjs +1 -1
- package/build/cjs/CustomElementRegistry.cjs +27 -2
- package/build/cjs/CustomEvent.cjs +2 -2
- package/build/cjs/Document.cjs +56 -32
- package/build/cjs/DocumentFragment.cjs +6 -2
- package/build/cjs/Element.cjs +68 -8
- package/build/cjs/Event.cjs +29 -27
- package/build/cjs/EventTarget.cjs +128 -58
- package/build/cjs/HTMLTemplateElement.cjs +1 -0
- package/build/cjs/MutationObserver.cjs +167 -1
- package/build/cjs/NamedNodeMap.cjs +82 -45
- package/build/cjs/Node.cjs +47 -11
- package/build/cjs/NodeList.cjs +9 -1
- package/build/cjs/ParentNode.cjs +319 -77
- package/build/cjs/SVGElement.cjs +1 -1
- package/build/cjs/Text.cjs +1 -1
- package/build/cjs/Window.cjs +131 -38
- package/build/cjs/attribute-reactions.cjs +20 -0
- package/build/cjs/constants.cjs +48 -24
- package/build/cjs/custom-element-reactions.cjs +52 -0
- package/build/cjs/dom-exception.cjs +15 -0
- package/build/cjs/hook-effects.cjs +51 -0
- package/build/cjs/names.cjs +61 -0
- package/build/cjs/selectors.cjs +213 -122
- package/build/cjs/serialization.cjs +168 -65
- package/build/cjs/shared.cjs +177 -28
- package/build/esm/Attr.mjs +34 -5
- package/build/esm/CharacterData.mjs +10 -0
- package/build/esm/ChildNode.mjs +76 -15
- package/build/esm/Comment.mjs +2 -2
- package/build/esm/CustomElementRegistry.mjs +27 -2
- package/build/esm/CustomEvent.mjs +2 -2
- package/build/esm/Document.mjs +60 -35
- package/build/esm/DocumentFragment.mjs +7 -3
- package/build/esm/Element.mjs +69 -9
- package/build/esm/Event.mjs +27 -27
- package/build/esm/EventTarget.mjs +130 -60
- package/build/esm/HTMLTemplateElement.mjs +2 -1
- package/build/esm/MutationObserver.mjs +166 -2
- package/build/esm/NamedNodeMap.mjs +83 -46
- package/build/esm/Node.mjs +48 -12
- package/build/esm/NodeList.mjs +9 -1
- package/build/esm/ParentNode.mjs +322 -81
- package/build/esm/SVGElement.mjs +2 -2
- package/build/esm/Text.mjs +2 -2
- package/build/esm/Window.mjs +132 -39
- package/build/esm/attribute-reactions.mjs +16 -0
- package/build/esm/constants.mjs +28 -23
- package/build/esm/custom-element-reactions.mjs +47 -0
- package/build/esm/dom-exception.mjs +11 -0
- package/build/esm/hook-effects.mjs +46 -0
- package/build/esm/names.mjs +54 -0
- package/build/esm/selectors.mjs +202 -124
- package/build/esm/serialization.mjs +169 -66
- package/build/esm/shared.mjs +173 -30
- package/build/esnext/Attr.esnext +45 -5
- package/build/esnext/CharacterData.esnext +10 -0
- package/build/esnext/ChildNode.esnext +84 -15
- package/build/esnext/Comment.esnext +2 -2
- package/build/esnext/CustomElementRegistry.esnext +42 -0
- package/build/esnext/CustomEvent.esnext +2 -2
- package/build/esnext/Document.esnext +69 -32
- package/build/esnext/DocumentFragment.esnext +6 -2
- package/build/esnext/Element.esnext +78 -9
- package/build/esnext/Event.esnext +36 -37
- package/build/esnext/EventTarget.esnext +133 -61
- package/build/esnext/HTMLTemplateElement.esnext +3 -1
- package/build/esnext/MutationObserver.esnext +163 -2
- package/build/esnext/NamedNodeMap.esnext +110 -42
- package/build/esnext/Node.esnext +50 -12
- package/build/esnext/NodeList.esnext +1 -1
- package/build/esnext/ParentNode.esnext +352 -79
- package/build/esnext/SVGElement.esnext +2 -2
- package/build/esnext/Text.esnext +2 -2
- package/build/esnext/Window.esnext +120 -16
- package/build/esnext/attribute-reactions.esnext +21 -0
- package/build/esnext/constants.esnext +34 -21
- package/build/esnext/custom-element-reactions.esnext +49 -0
- package/build/esnext/dom-exception.esnext +11 -0
- package/build/esnext/hook-effects.esnext +46 -0
- package/build/esnext/names.esnext +61 -0
- package/build/esnext/selectors.esnext +202 -100
- package/build/esnext/serialization.esnext +171 -48
- package/build/esnext/shared.esnext +181 -34
- package/build/tsconfig.tsbuildinfo +1 -1
- package/build/typescript/Attr.d.ts +6 -4
- package/build/typescript/Attr.d.ts.map +1 -1
- package/build/typescript/CharacterData.d.ts.map +1 -1
- package/build/typescript/ChildNode.d.ts +5 -0
- package/build/typescript/ChildNode.d.ts.map +1 -1
- package/build/typescript/ClipboardEvent.d.ts.map +1 -1
- package/build/typescript/Comment.d.ts +2 -2
- package/build/typescript/Comment.d.ts.map +1 -1
- package/build/typescript/CustomElementRegistry.d.ts +1 -0
- package/build/typescript/CustomElementRegistry.d.ts.map +1 -1
- package/build/typescript/CustomEvent.d.ts.map +1 -1
- package/build/typescript/Document.d.ts +10 -5
- package/build/typescript/Document.d.ts.map +1 -1
- package/build/typescript/DocumentFragment.d.ts +2 -1
- package/build/typescript/DocumentFragment.d.ts.map +1 -1
- package/build/typescript/Element.d.ts +16 -7
- package/build/typescript/Element.d.ts.map +1 -1
- package/build/typescript/ErrorEvent.d.ts.map +1 -1
- package/build/typescript/Event.d.ts +9 -10
- package/build/typescript/Event.d.ts.map +1 -1
- package/build/typescript/EventTarget.d.ts +20 -3
- package/build/typescript/EventTarget.d.ts.map +1 -1
- package/build/typescript/FocusEvent.d.ts.map +1 -1
- package/build/typescript/HTMLTemplateElement.d.ts.map +1 -1
- package/build/typescript/MutationObserver.d.ts +42 -0
- package/build/typescript/MutationObserver.d.ts.map +1 -1
- package/build/typescript/NamedNodeMap.d.ts +5 -3
- package/build/typescript/NamedNodeMap.d.ts.map +1 -1
- package/build/typescript/Node.d.ts +4 -3
- package/build/typescript/Node.d.ts.map +1 -1
- package/build/typescript/NodeList.d.ts +3 -2
- package/build/typescript/NodeList.d.ts.map +1 -1
- package/build/typescript/ParentNode.d.ts +29 -10
- package/build/typescript/ParentNode.d.ts.map +1 -1
- package/build/typescript/PromiseRejectionEvent.d.ts.map +1 -1
- package/build/typescript/SVGElement.d.ts +1 -1
- package/build/typescript/SVGElement.d.ts.map +1 -1
- package/build/typescript/Text.d.ts +1 -1
- package/build/typescript/Text.d.ts.map +1 -1
- package/build/typescript/ToggleEvent.d.ts.map +1 -1
- package/build/typescript/Window.d.ts +5 -1
- package/build/typescript/Window.d.ts.map +1 -1
- package/build/typescript/attribute-reactions.d.ts +4 -0
- package/build/typescript/attribute-reactions.d.ts.map +1 -0
- package/build/typescript/constants.d.ts +27 -18
- package/build/typescript/constants.d.ts.map +1 -1
- package/build/typescript/custom-element-reactions.d.ts +6 -0
- package/build/typescript/custom-element-reactions.d.ts.map +1 -0
- package/build/typescript/dom-exception.d.ts +2 -0
- package/build/typescript/dom-exception.d.ts.map +1 -0
- package/build/typescript/extensions.d.ts +4 -0
- package/build/typescript/extensions.d.ts.map +1 -0
- package/build/typescript/hook-effects.d.ts +6 -0
- package/build/typescript/hook-effects.d.ts.map +1 -0
- package/build/typescript/hooks.d.ts +3 -3
- package/build/typescript/hooks.d.ts.map +1 -1
- package/build/typescript/index.d.ts +1 -0
- package/build/typescript/index.d.ts.map +1 -1
- package/build/typescript/names.d.ts +11 -0
- package/build/typescript/names.d.ts.map +1 -0
- package/build/typescript/selectors.d.ts +21 -22
- package/build/typescript/selectors.d.ts.map +1 -1
- package/build/typescript/serialization.d.ts.map +1 -1
- package/build/typescript/shared.d.ts +10 -0
- package/build/typescript/shared.d.ts.map +1 -1
- package/build/typescript/tests/ChildNode.test.d.ts +2 -0
- package/build/typescript/tests/ChildNode.test.d.ts.map +1 -0
- package/build/typescript/tests/MutationObserver.test.d.ts +2 -0
- package/build/typescript/tests/MutationObserver.test.d.ts.map +1 -0
- package/build/typescript/tests/adopt-inserted-subtrees.test.d.ts +2 -0
- package/build/typescript/tests/adopt-inserted-subtrees.test.d.ts.map +1 -0
- package/build/typescript/tests/attr-mutation.test.d.ts +2 -0
- package/build/typescript/tests/attr-mutation.test.d.ts.map +1 -0
- package/build/typescript/tests/child-node-before-after.test.d.ts +2 -0
- package/build/typescript/tests/child-node-before-after.test.d.ts.map +1 -0
- package/build/typescript/tests/child-node-replace-with.test.d.ts +2 -0
- package/build/typescript/tests/child-node-replace-with.test.d.ts.map +1 -0
- package/build/typescript/tests/clone-import-namespaces.test.d.ts +2 -0
- package/build/typescript/tests/clone-import-namespaces.test.d.ts.map +1 -0
- package/build/typescript/tests/constants.test.d.ts +2 -0
- package/build/typescript/tests/constants.test.d.ts.map +1 -0
- package/build/typescript/tests/create-element-namespaces.test.d.ts +2 -0
- package/build/typescript/tests/create-element-namespaces.test.d.ts.map +1 -0
- package/build/typescript/tests/create-text-node.test.d.ts +2 -0
- package/build/typescript/tests/create-text-node.test.d.ts.map +1 -0
- package/build/typescript/tests/custom-element-reactions.test.d.ts +2 -0
- package/build/typescript/tests/custom-element-reactions.test.d.ts.map +1 -0
- package/build/typescript/tests/custom-element-registry.test.d.ts +2 -0
- package/build/typescript/tests/custom-element-registry.test.d.ts.map +1 -0
- package/build/typescript/tests/custom-event.test.d.ts +2 -0
- package/build/typescript/tests/custom-event.test.d.ts.map +1 -0
- package/build/typescript/tests/document-clone-import-contract.test.d.ts +2 -0
- package/build/typescript/tests/document-clone-import-contract.test.d.ts.map +1 -0
- package/build/typescript/tests/document.test.d.ts +2 -0
- package/build/typescript/tests/document.test.d.ts.map +1 -0
- package/build/typescript/tests/dom-mutation-selector-errors.test.d.ts +2 -0
- package/build/typescript/tests/dom-mutation-selector-errors.test.d.ts.map +1 -0
- package/build/typescript/tests/event-dispatch.test.d.ts +2 -0
- package/build/typescript/tests/event-dispatch.test.d.ts.map +1 -0
- package/build/typescript/tests/event-target.test.d.ts +2 -0
- package/build/typescript/tests/event-target.test.d.ts.map +1 -0
- package/build/typescript/tests/event.test.d.ts +2 -0
- package/build/typescript/tests/event.test.d.ts.map +1 -0
- package/build/typescript/tests/extensions.test.d.ts +2 -0
- package/build/typescript/tests/extensions.test.d.ts.map +1 -0
- package/build/typescript/tests/get-elements-by-tag-name.test.d.ts +2 -0
- package/build/typescript/tests/get-elements-by-tag-name.test.d.ts.map +1 -0
- package/build/typescript/tests/getElementsByClassName.test.d.ts +2 -0
- package/build/typescript/tests/getElementsByClassName.test.d.ts.map +1 -0
- package/build/typescript/tests/hooks.test.d.ts +2 -0
- package/build/typescript/tests/hooks.test.d.ts.map +1 -0
- package/build/typescript/tests/inner-html-parsing.test.d.ts +2 -0
- package/build/typescript/tests/inner-html-parsing.test.d.ts.map +1 -0
- package/build/typescript/tests/is-default-namespace.test.d.ts +2 -0
- package/build/typescript/tests/is-default-namespace.test.d.ts.map +1 -0
- package/build/typescript/tests/name-and-namespace-normalization.test.d.ts +2 -0
- package/build/typescript/tests/name-and-namespace-normalization.test.d.ts.map +1 -0
- package/build/typescript/tests/named-node-map.test.d.ts +2 -0
- package/build/typescript/tests/named-node-map.test.d.ts.map +1 -0
- package/build/typescript/tests/namespaced-attribute-reactions.test.d.ts +2 -0
- package/build/typescript/tests/namespaced-attribute-reactions.test.d.ts.map +1 -0
- package/build/typescript/tests/node.test.d.ts +2 -0
- package/build/typescript/tests/node.test.d.ts.map +1 -0
- package/build/typescript/tests/parent-node-mutation-return-values.test.d.ts +2 -0
- package/build/typescript/tests/parent-node-mutation-return-values.test.d.ts.map +1 -0
- package/build/typescript/tests/parent-node-mutation-validation.test.d.ts +2 -0
- package/build/typescript/tests/parent-node-mutation-validation.test.d.ts.map +1 -0
- package/build/typescript/tests/parent-node.test.d.ts +2 -0
- package/build/typescript/tests/parent-node.test.d.ts.map +1 -0
- package/build/typescript/tests/serialization-template.test.d.ts +2 -0
- package/build/typescript/tests/serialization-template.test.d.ts.map +1 -0
- package/build/typescript/tests/slot-attribute.test.d.ts +2 -0
- package/build/typescript/tests/slot-attribute.test.d.ts.map +1 -0
- package/build/typescript/tests/text-content.test.d.ts +2 -0
- package/build/typescript/tests/text-content.test.d.ts.map +1 -0
- package/build/typescript/tests/toggle-attribute.test.d.ts +2 -0
- package/build/typescript/tests/toggle-attribute.test.d.ts.map +1 -0
- package/build/typescript/tests/wide-tree-traversal.test.d.ts +2 -0
- package/build/typescript/tests/wide-tree-traversal.test.d.ts.map +1 -0
- package/build/typescript/tests/window-set-global.test.d.ts +2 -0
- package/build/typescript/tests/window-set-global.test.d.ts.map +1 -0
- package/package.json +1 -1
- package/source/Attr.ts +60 -8
- package/source/CharacterData.ts +13 -0
- package/source/ChildNode.ts +107 -14
- package/source/Comment.ts +2 -2
- package/source/CustomElementRegistry.ts +56 -0
- package/source/CustomEvent.ts +2 -2
- package/source/Document.ts +104 -38
- package/source/DocumentFragment.ts +12 -2
- package/source/Element.ts +129 -14
- package/source/Event.ts +34 -32
- package/source/EventTarget.ts +203 -79
- package/source/HTMLTemplateElement.ts +2 -1
- package/source/MutationObserver.ts +279 -1
- package/source/NamedNodeMap.ts +141 -60
- package/source/Node.ts +70 -14
- package/source/NodeList.ts +13 -3
- package/source/ParentNode.ts +500 -88
- package/source/SVGElement.ts +2 -2
- package/source/Text.ts +2 -2
- package/source/Window.ts +156 -17
- package/source/attribute-reactions.ts +32 -0
- package/source/constants.ts +40 -17
- package/source/custom-element-reactions.ts +64 -0
- package/source/dom-exception.ts +14 -0
- package/source/extensions.ts +4 -0
- package/source/hook-effects.ts +56 -0
- package/source/hooks.ts +11 -3
- package/source/index.ts +1 -0
- package/source/names.ts +94 -0
- package/source/selectors.ts +301 -138
- package/source/serialization.ts +224 -66
- package/source/shared.ts +269 -40
- package/source/tests/ChildNode.test.ts +178 -0
- package/source/tests/MutationObserver.test.ts +303 -0
- package/source/tests/adopt-inserted-subtrees.test.ts +584 -0
- package/source/tests/attr-mutation.test.ts +112 -0
- package/source/tests/child-node-before-after.test.ts +421 -0
- package/source/tests/child-node-replace-with.test.ts +251 -0
- package/source/tests/clone-import-namespaces.test.ts +365 -0
- package/source/tests/constants.test.ts +46 -0
- package/source/tests/create-element-namespaces.test.ts +142 -0
- package/source/tests/create-text-node.test.ts +38 -0
- package/source/tests/custom-element-reactions.test.ts +600 -0
- package/source/tests/custom-element-registry.test.ts +137 -0
- package/source/tests/custom-event.test.ts +26 -0
- package/source/tests/document-clone-import-contract.test.ts +77 -0
- package/source/tests/document.test.ts +122 -0
- package/source/tests/dom-mutation-selector-errors.test.ts +484 -0
- package/source/tests/event-dispatch.test.ts +270 -0
- package/source/tests/event-target.test.ts +208 -0
- package/source/tests/event.test.ts +98 -0
- package/source/tests/extensions.test.ts +159 -0
- package/source/tests/get-elements-by-tag-name.test.ts +79 -0
- package/source/tests/getElementsByClassName.test.ts +109 -0
- package/source/tests/hooks.test.ts +43 -0
- package/source/tests/inner-html-parsing.test.ts +461 -0
- package/source/tests/is-default-namespace.test.ts +111 -0
- package/source/tests/name-and-namespace-normalization.test.ts +319 -0
- package/source/tests/named-node-map.test.ts +122 -0
- package/source/tests/namespaced-attribute-reactions.test.ts +141 -0
- package/source/tests/node.test.ts +56 -0
- package/source/tests/parent-node-mutation-return-values.test.ts +63 -0
- package/source/tests/parent-node-mutation-validation.test.ts +362 -0
- package/source/tests/parent-node.test.ts +169 -0
- package/source/tests/selectors.test.ts +533 -22
- package/source/tests/serialization-template.test.ts +232 -0
- package/source/tests/slot-attribute.test.ts +133 -0
- package/source/tests/text-content.test.ts +440 -0
- package/source/tests/toggle-attribute.test.ts +113 -0
- package/source/tests/wide-tree-traversal.test.ts +699 -0
- package/source/tests/window-set-global.test.ts +321 -0
- package/tsconfig.json +1 -1
package/build/cjs/ParentNode.cjs
CHANGED
|
@@ -7,69 +7,112 @@ const ChildNode = require('./ChildNode.cjs');
|
|
|
7
7
|
const NodeList = require('./NodeList.cjs');
|
|
8
8
|
const selectors = require('./selectors.cjs');
|
|
9
9
|
const shared = require('./shared.cjs');
|
|
10
|
+
const MutationObserver = require('./MutationObserver.cjs');
|
|
11
|
+
const customElementReactions = require('./custom-element-reactions.cjs');
|
|
12
|
+
const hookEffects = require('./hook-effects.cjs');
|
|
13
|
+
const domException = require('./dom-exception.cjs');
|
|
10
14
|
|
|
11
15
|
class ParentNode extends ChildNode.ChildNode {
|
|
12
|
-
childNodes =
|
|
13
|
-
children =
|
|
16
|
+
childNodes = new NodeList.NodeList();
|
|
17
|
+
children = new NodeList.NodeList();
|
|
14
18
|
appendChild(child) {
|
|
15
|
-
this.
|
|
19
|
+
return customElementReactions.performWithCustomElementReactions(() => this[ChildNode.INSERT_NODE](child, null));
|
|
16
20
|
}
|
|
17
21
|
insertBefore(child, ref) {
|
|
18
|
-
this.
|
|
22
|
+
return customElementReactions.performWithCustomElementReactions(() => this[ChildNode.INSERT_NODE](child, ref || null));
|
|
19
23
|
}
|
|
20
24
|
append(...nodes) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
+
return customElementReactions.performWithCustomElementReactions(() => {
|
|
26
|
+
const staged = ChildNode.stageNodes(nodes.filter(node => node != null));
|
|
27
|
+
if (staged.length > 1) ChildNode.validateInsertionNodes(this, staged);
|
|
28
|
+
for (const child of staged) {
|
|
29
|
+
this[ChildNode.INSERT_NODE](ChildNode.toNode(this, child), null);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
25
32
|
}
|
|
26
33
|
prepend(...nodes) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
if (
|
|
30
|
-
this.
|
|
31
|
-
|
|
34
|
+
return customElementReactions.performWithCustomElementReactions(() => {
|
|
35
|
+
const staged = ChildNode.stageNodes(nodes.filter(node => node != null));
|
|
36
|
+
if (staged.length > 1) ChildNode.validateInsertionNodes(this, staged);
|
|
37
|
+
const before = this.firstChild;
|
|
38
|
+
for (const child of staged) {
|
|
39
|
+
this[ChildNode.INSERT_NODE](ChildNode.toNode(this, child), before);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
32
42
|
}
|
|
33
43
|
replaceChildren(...nodes) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
44
|
+
return customElementReactions.performWithCustomElementReactions(() => {
|
|
45
|
+
const staged = ChildNode.stageNodes(nodes.filter(node => node != null));
|
|
46
|
+
ChildNode.validateInsertionNodes(this, staged);
|
|
47
|
+
let child;
|
|
48
|
+
while (child = this.firstChild) {
|
|
49
|
+
this.removeChildImmediately(child);
|
|
50
|
+
}
|
|
51
|
+
for (const node of staged) {
|
|
52
|
+
this[ChildNode.INSERT_NODE](ChildNode.toNode(this, node), null);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
39
55
|
}
|
|
40
56
|
removeChild(child) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
if (this[constants.IS_CONNECTED]) {
|
|
57
|
-
for (const node of shared.selfAndDescendants(child)) {
|
|
58
|
-
node[constants.IS_CONNECTED] = false;
|
|
59
|
-
node.disconnectedCallback?.();
|
|
60
|
-
}
|
|
57
|
+
return customElementReactions.performWithCustomElementReactions(() => {
|
|
58
|
+
this.removeChildImmediately(child);
|
|
59
|
+
return child;
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
removeChildImmediately(child) {
|
|
63
|
+
if (child.parentNode !== this) {
|
|
64
|
+
throw domException.createDOMException('The node is not a child of this node', 'NotFoundError');
|
|
65
|
+
}
|
|
66
|
+
const disconnectedNodes = this[constants.IS_CONNECTED] ? shared.selfAndDescendants(child) : undefined;
|
|
67
|
+
const previousSibling = child[constants.PREV];
|
|
68
|
+
const nextSibling = child[constants.NEXT];
|
|
69
|
+
const childNodesIndex = detachChild(this, child);
|
|
70
|
+
if (disconnectedNodes) {
|
|
71
|
+
for (const node of disconnectedNodes) node[constants.IS_CONNECTED] = false;
|
|
61
72
|
}
|
|
62
|
-
|
|
63
|
-
|
|
73
|
+
this.queueRemovalMutationRecord(this, child, previousSibling, nextSibling);
|
|
74
|
+
if (disconnectedNodes) {
|
|
75
|
+
this.enqueueTreeReactions(disconnectedNodes, 'disconnectedCallback');
|
|
64
76
|
}
|
|
77
|
+
hookEffects.performHookEffects(this.collectRemovalHookEffects(child, childNodesIndex));
|
|
65
78
|
}
|
|
66
79
|
replaceChild(newChild, oldChild) {
|
|
80
|
+
return customElementReactions.performWithCustomElementReactions(() => this[ChildNode.REPLACE_NODE](newChild, oldChild));
|
|
81
|
+
}
|
|
82
|
+
[ChildNode.REPLACE_NODE](newChild, oldChild, hookEffects) {
|
|
83
|
+
ChildNode.validateInsertionNodes(this, [newChild]);
|
|
67
84
|
if (oldChild.parentNode !== this) {
|
|
68
|
-
throw
|
|
85
|
+
throw domException.createDOMException('The reference node is not a child of this parent', 'NotFoundError');
|
|
69
86
|
}
|
|
87
|
+
const previous = oldChild[constants.PREV];
|
|
70
88
|
const next = oldChild[constants.NEXT];
|
|
71
|
-
this.
|
|
72
|
-
this.
|
|
89
|
+
const insertion = this.prepareInsertion(newChild);
|
|
90
|
+
const removedNodes = this[constants.IS_CONNECTED] ? shared.selfAndDescendants(oldChild) : undefined;
|
|
91
|
+
const insertionRoots = new Set(insertion.map(({
|
|
92
|
+
node
|
|
93
|
+
}) => node));
|
|
94
|
+
let before = next;
|
|
95
|
+
while (before && insertionRoots.has(before)) before = before[constants.NEXT];
|
|
96
|
+
const oldChildIndex = detachChild(this, oldChild);
|
|
97
|
+
if (removedNodes) {
|
|
98
|
+
for (const node of removedNodes) node[constants.IS_CONNECTED] = false;
|
|
99
|
+
const removedNodeSet = new Set(removedNodes);
|
|
100
|
+
for (const prepared of insertion) {
|
|
101
|
+
if (removedNodeSet.has(prepared.node)) {
|
|
102
|
+
prepared.shouldDisconnect = false;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
this.commitInsertion(insertion, before);
|
|
107
|
+
const destinationIsConnected = this[constants.IS_CONNECTED];
|
|
108
|
+
this.queueRemovalMutationRecord(this, oldChild, previous, next);
|
|
109
|
+
this.queueInsertionMutationRecords(insertion);
|
|
110
|
+
if (removedNodes) {
|
|
111
|
+
this.enqueueTreeReactions(removedNodes, 'disconnectedCallback');
|
|
112
|
+
}
|
|
113
|
+
this.enqueueInsertionReactions(insertion, destinationIsConnected);
|
|
114
|
+
this.performOrCollectHookEffects([...this.collectRemovalHookEffects(oldChild, oldChildIndex), ...this.collectInsertionHookEffects(insertion)], hookEffects);
|
|
115
|
+
return oldChild;
|
|
73
116
|
}
|
|
74
117
|
querySelectorAll(selector) {
|
|
75
118
|
return selectors.querySelectorAll(this, selector);
|
|
@@ -77,27 +120,111 @@ class ParentNode extends ChildNode.ChildNode {
|
|
|
77
120
|
querySelector(selector) {
|
|
78
121
|
return selectors.querySelector(this, selector);
|
|
79
122
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
123
|
+
[ChildNode.INSERT_NODE](child, before, hookEffects) {
|
|
124
|
+
this.validateInsertion(child, before);
|
|
125
|
+
this.insertIntoValidated(child, before, hookEffects);
|
|
126
|
+
return child;
|
|
127
|
+
}
|
|
128
|
+
[ChildNode.PREFLIGHT_INSERTIONS](children) {
|
|
129
|
+
for (const child of children) {
|
|
130
|
+
this.validateInsertion(child, null);
|
|
131
|
+
this.prepareInsertion(child);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
validateInsertion(child, before) {
|
|
135
|
+
ChildNode.validateInsertionNodes(this, [child]);
|
|
136
|
+
if (before && before.parentNode !== this) {
|
|
137
|
+
throw domException.createDOMException('The reference node is not a child of this parent', 'NotFoundError');
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
insertIntoValidated(child, before, hookEffects) {
|
|
141
|
+
if (child === before) before = child[constants.NEXT];
|
|
142
|
+
const insertion = this.prepareInsertion(child);
|
|
143
|
+
this.commitInsertion(insertion, before);
|
|
144
|
+
const destinationIsConnected = this[constants.IS_CONNECTED];
|
|
145
|
+
this.queueInsertionMutationRecords(insertion);
|
|
146
|
+
this.enqueueInsertionReactions(insertion, destinationIsConnected);
|
|
147
|
+
this.performOrCollectHookEffects(this.collectInsertionHookEffects(insertion), hookEffects);
|
|
148
|
+
}
|
|
149
|
+
performOrCollectHookEffects(effects, hookEffects$1) {
|
|
150
|
+
if (hookEffects$1) hookEffects$1.push(...effects);else hookEffects.performHookEffects(effects);
|
|
151
|
+
}
|
|
152
|
+
prepareInsertion(child) {
|
|
153
|
+
const roots = [];
|
|
154
|
+
if (child.nodeType === constants.NODE_TYPE_DOCUMENT_FRAGMENT) {
|
|
83
155
|
let node = child[constants.CHILD];
|
|
84
156
|
while (node) {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
node = next;
|
|
157
|
+
roots.push(node);
|
|
158
|
+
node = node[constants.NEXT];
|
|
88
159
|
}
|
|
89
|
-
|
|
160
|
+
} else {
|
|
161
|
+
roots.push(child);
|
|
90
162
|
}
|
|
91
|
-
|
|
92
|
-
|
|
163
|
+
const destinationIsConnected = this[constants.IS_CONNECTED];
|
|
164
|
+
const ownerDocument = this[constants.OWNER_DOCUMENT];
|
|
165
|
+
const insertion = [];
|
|
166
|
+
for (const node of roots) {
|
|
167
|
+
const wasConnected = node[constants.IS_CONNECTED];
|
|
168
|
+
const shouldTraverse = wasConnected || destinationIsConnected;
|
|
169
|
+
let nodes;
|
|
170
|
+
let adoption;
|
|
171
|
+
if (node[constants.OWNER_DOCUMENT] === ownerDocument) {
|
|
172
|
+
if (shouldTraverse) nodes = shared.selfAndDescendants(node);
|
|
173
|
+
} else {
|
|
174
|
+
const snapshot = shared.collectAdoptionSnapshot(node);
|
|
175
|
+
adoption = snapshot.nodes;
|
|
176
|
+
if (shouldTraverse) nodes = snapshot.treeNodes;
|
|
177
|
+
}
|
|
178
|
+
insertion.push({
|
|
179
|
+
node,
|
|
180
|
+
nodes,
|
|
181
|
+
adoption,
|
|
182
|
+
shouldDisconnect: wasConnected
|
|
183
|
+
});
|
|
93
184
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
185
|
+
return insertion;
|
|
186
|
+
}
|
|
187
|
+
commitInsertion(insertion, before) {
|
|
188
|
+
for (const prepared of insertion) {
|
|
189
|
+
const sourceParent = prepared.node[constants.PARENT];
|
|
190
|
+
if (sourceParent) {
|
|
191
|
+
const previousSibling = prepared.node[constants.PREV];
|
|
192
|
+
const nextSibling = prepared.node[constants.NEXT];
|
|
193
|
+
prepared.source = {
|
|
194
|
+
parent: sourceParent,
|
|
195
|
+
index: detachChild(sourceParent, prepared.node),
|
|
196
|
+
previousSibling,
|
|
197
|
+
nextSibling
|
|
198
|
+
};
|
|
97
199
|
}
|
|
200
|
+
}
|
|
201
|
+
for (const prepared of insertion) {
|
|
202
|
+
const attached = this.attachChild(prepared.node, before);
|
|
203
|
+
prepared.insertIndex = attached.index;
|
|
204
|
+
prepared.previousSibling = attached.previousSibling;
|
|
205
|
+
prepared.nextSibling = attached.nextSibling;
|
|
206
|
+
}
|
|
207
|
+
const ownerDocument = this[constants.OWNER_DOCUMENT];
|
|
208
|
+
for (const {
|
|
209
|
+
adoption
|
|
210
|
+
} of insertion) {
|
|
211
|
+
if (adoption) shared.adoptNodes(adoption, ownerDocument);
|
|
212
|
+
}
|
|
213
|
+
const isConnected = this[constants.IS_CONNECTED];
|
|
214
|
+
for (const {
|
|
215
|
+
nodes
|
|
216
|
+
} of insertion) {
|
|
217
|
+
if (nodes) {
|
|
218
|
+
for (const node of nodes) node[constants.IS_CONNECTED] = isConnected;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
attachChild(child, before) {
|
|
223
|
+
if (before) {
|
|
224
|
+
const previous = before[constants.PREV];
|
|
98
225
|
child[constants.NEXT] = before;
|
|
99
|
-
child[constants.PREV] =
|
|
100
|
-
if (
|
|
226
|
+
child[constants.PREV] = previous;
|
|
227
|
+
if (previous) previous[constants.NEXT] = child;else this[constants.CHILD] = child;
|
|
101
228
|
before[constants.PREV] = child;
|
|
102
229
|
} else {
|
|
103
230
|
child[constants.NEXT] = null;
|
|
@@ -112,40 +239,155 @@ class ParentNode extends ChildNode.ChildNode {
|
|
|
112
239
|
child[constants.PREV] = null;
|
|
113
240
|
}
|
|
114
241
|
}
|
|
115
|
-
const
|
|
116
|
-
const isElement = child.nodeType === constants.NodeType.ELEMENT_NODE;
|
|
242
|
+
const isElement = shared.isElementNode(child);
|
|
117
243
|
child[constants.PARENT] = this;
|
|
118
|
-
child[constants.OWNER_DOCUMENT] = ownerDocument;
|
|
119
|
-
const childNodes = this.childNodes;
|
|
120
244
|
let insertIndex;
|
|
121
245
|
if (before) {
|
|
122
|
-
insertIndex = childNodes.indexOf(before);
|
|
123
|
-
childNodes.splice(insertIndex, 0, child);
|
|
246
|
+
insertIndex = this.childNodes.indexOf(before);
|
|
247
|
+
this.childNodes.splice(insertIndex, 0, child);
|
|
124
248
|
if (isElement) {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
249
|
+
let reference = before;
|
|
250
|
+
while (reference && !shared.isElementNode(reference)) {
|
|
251
|
+
reference = reference[constants.NEXT];
|
|
252
|
+
}
|
|
253
|
+
if (reference) {
|
|
254
|
+
this.children.splice(this.children.indexOf(reference), 0, child);
|
|
130
255
|
} else {
|
|
131
|
-
children.push(child);
|
|
256
|
+
this.children.push(child);
|
|
132
257
|
}
|
|
133
258
|
}
|
|
134
259
|
} else {
|
|
135
|
-
insertIndex = childNodes.length;
|
|
136
|
-
childNodes.push(child);
|
|
260
|
+
insertIndex = this.childNodes.length;
|
|
261
|
+
this.childNodes.push(child);
|
|
137
262
|
if (isElement) this.children.push(child);
|
|
138
263
|
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
264
|
+
return {
|
|
265
|
+
index: insertIndex,
|
|
266
|
+
previousSibling: child[constants.PREV],
|
|
267
|
+
nextSibling: child[constants.NEXT]
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
queueRemovalMutationRecord(parent, child, previousSibling, nextSibling) {
|
|
271
|
+
if (!MutationObserver.childListObserversActive) return;
|
|
272
|
+
MutationObserver.queueMutationRecord({
|
|
273
|
+
type: 'childList',
|
|
274
|
+
target: parent,
|
|
275
|
+
removedNodes: MutationObserver.mutationNodeList(child),
|
|
276
|
+
previousSibling,
|
|
277
|
+
nextSibling
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
queueInsertionMutationRecords(insertion) {
|
|
281
|
+
if (!MutationObserver.childListObserversActive) return;
|
|
282
|
+
for (const prepared of insertion) {
|
|
283
|
+
const {
|
|
284
|
+
node,
|
|
285
|
+
source
|
|
286
|
+
} = prepared;
|
|
287
|
+
if (source) {
|
|
288
|
+
this.queueRemovalMutationRecord(source.parent, node, source.previousSibling, source.nextSibling);
|
|
289
|
+
}
|
|
290
|
+
MutationObserver.queueMutationRecord({
|
|
291
|
+
type: 'childList',
|
|
292
|
+
target: this,
|
|
293
|
+
addedNodes: MutationObserver.mutationNodeList(node),
|
|
294
|
+
previousSibling: prepared.previousSibling,
|
|
295
|
+
nextSibling: prepared.nextSibling
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
collectRemovalHookEffects(child, childNodesIndex) {
|
|
300
|
+
if (this.nodeType !== constants.NODE_TYPE_ELEMENT || hookEffects.isCoveredByPendingPublication(this)) {
|
|
301
|
+
return [];
|
|
302
|
+
}
|
|
303
|
+
return [[() => this[constants.HOOKS].removeChild?.(this, child, childNodesIndex)]];
|
|
304
|
+
}
|
|
305
|
+
collectInsertionHookEffects(insertion) {
|
|
306
|
+
const effects = [];
|
|
307
|
+
for (const prepared of insertion) {
|
|
308
|
+
const {
|
|
309
|
+
node,
|
|
310
|
+
source
|
|
311
|
+
} = prepared;
|
|
312
|
+
if (source?.parent.nodeType === constants.NODE_TYPE_ELEMENT && !hookEffects.isCoveredByPendingPublication(source.parent)) {
|
|
313
|
+
effects.push([() => source.parent[constants.HOOKS].removeChild?.(source.parent, node, source.index)]);
|
|
314
|
+
}
|
|
315
|
+
if (this.nodeType === constants.NODE_TYPE_ELEMENT && !hookEffects.isCoveredByPendingPublication(this)) {
|
|
316
|
+
effects.push([() => this[constants.HOOKS].insertChild?.(this, node, prepared.insertIndex), node]);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
return effects;
|
|
320
|
+
}
|
|
321
|
+
enqueueInsertionReactions(insertion, destinationIsConnected) {
|
|
322
|
+
for (const prepared of insertion) {
|
|
323
|
+
const {
|
|
324
|
+
nodes
|
|
325
|
+
} = prepared;
|
|
326
|
+
if (nodes) {
|
|
327
|
+
if (prepared.shouldDisconnect) {
|
|
328
|
+
this.enqueueTreeReactions(nodes, 'disconnectedCallback');
|
|
329
|
+
}
|
|
330
|
+
if (destinationIsConnected) {
|
|
331
|
+
this.enqueueTreeReactions(nodes, 'connectedCallback');
|
|
332
|
+
}
|
|
143
333
|
}
|
|
144
334
|
}
|
|
145
|
-
|
|
146
|
-
|
|
335
|
+
}
|
|
336
|
+
enqueueTreeReactions(nodes, callbackName) {
|
|
337
|
+
enqueueTreeReactions(nodes, callbackName);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
function removeChildForAdoption(parent, child, adoption, destination) {
|
|
341
|
+
if (child.parentNode !== parent) throw Error(`not a child of this node`);
|
|
342
|
+
const disconnectedNodes = parent[constants.IS_CONNECTED] ? adoption.treeNodes : undefined;
|
|
343
|
+
const previousSibling = child[constants.PREV];
|
|
344
|
+
const nextSibling = child[constants.NEXT];
|
|
345
|
+
const childNodesIndex = detachChild(parent, child);
|
|
346
|
+
if (disconnectedNodes) {
|
|
347
|
+
for (const node of disconnectedNodes) node[constants.IS_CONNECTED] = false;
|
|
348
|
+
}
|
|
349
|
+
shared.adoptNodes(adoption.nodes, destination);
|
|
350
|
+
if (MutationObserver.childListObserversActive) {
|
|
351
|
+
MutationObserver.queueMutationRecord({
|
|
352
|
+
type: 'childList',
|
|
353
|
+
target: parent,
|
|
354
|
+
removedNodes: MutationObserver.mutationNodeList(child),
|
|
355
|
+
previousSibling,
|
|
356
|
+
nextSibling
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
if (disconnectedNodes) {
|
|
360
|
+
enqueueTreeReactions(disconnectedNodes, 'disconnectedCallback');
|
|
361
|
+
}
|
|
362
|
+
const effects = [];
|
|
363
|
+
if (parent.nodeType === constants.NODE_TYPE_ELEMENT && !hookEffects.isCoveredByPendingPublication(parent)) {
|
|
364
|
+
effects.push([() => parent[constants.HOOKS].removeChild?.(parent, child, childNodesIndex)]);
|
|
365
|
+
}
|
|
366
|
+
hookEffects.performHookEffects(effects);
|
|
367
|
+
}
|
|
368
|
+
function detachChild(parent, child) {
|
|
369
|
+
const previous = child[constants.PREV];
|
|
370
|
+
const next = child[constants.NEXT];
|
|
371
|
+
if (previous) previous[constants.NEXT] = next;else parent[constants.CHILD] = next;
|
|
372
|
+
if (next) next[constants.PREV] = previous;
|
|
373
|
+
const childNodesIndex = parent.childNodes.indexOf(child);
|
|
374
|
+
parent.childNodes.splice(childNodesIndex, 1);
|
|
375
|
+
if (shared.isElementNode(child)) {
|
|
376
|
+
parent.children.splice(parent.children.indexOf(child), 1);
|
|
377
|
+
}
|
|
378
|
+
child[constants.PARENT] = null;
|
|
379
|
+
child[constants.NEXT] = null;
|
|
380
|
+
child[constants.PREV] = null;
|
|
381
|
+
return childNodesIndex;
|
|
382
|
+
}
|
|
383
|
+
function enqueueTreeReactions(nodes, callbackName) {
|
|
384
|
+
for (const node of nodes) {
|
|
385
|
+
const callback = node[callbackName];
|
|
386
|
+
if (typeof callback === 'function') {
|
|
387
|
+
customElementReactions.enqueueCustomElementReaction(node, () => callback.call(node));
|
|
147
388
|
}
|
|
148
389
|
}
|
|
149
390
|
}
|
|
150
391
|
|
|
151
392
|
exports.ParentNode = ParentNode;
|
|
393
|
+
exports.removeChildForAdoption = removeChildForAdoption;
|
package/build/cjs/SVGElement.cjs
CHANGED
|
@@ -6,7 +6,7 @@ const constants = require('./constants.cjs');
|
|
|
6
6
|
const Element = require('./Element.cjs');
|
|
7
7
|
|
|
8
8
|
class SVGElement extends Element.Element {
|
|
9
|
-
[constants.NS] =
|
|
9
|
+
[constants.NS] = constants.SVG_NAMESPACE;
|
|
10
10
|
get ownerSVGElement() {
|
|
11
11
|
let root = null;
|
|
12
12
|
let parent = this.parentNode;
|
package/build/cjs/Text.cjs
CHANGED
|
@@ -6,7 +6,7 @@ const constants = require('./constants.cjs');
|
|
|
6
6
|
const CharacterData = require('./CharacterData.cjs');
|
|
7
7
|
|
|
8
8
|
class Text extends CharacterData.CharacterData {
|
|
9
|
-
nodeType =
|
|
9
|
+
nodeType = constants.NODE_TYPE_TEXT;
|
|
10
10
|
[constants.NAME] = '#text';
|
|
11
11
|
}
|
|
12
12
|
|