Leon4gr45 commited on
Commit
74b538a
·
verified ·
1 Parent(s): e94010c

Upload folder using huggingface_hub (part 13)

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .gitattributes +2 -0
  2. node_modules/jsdom/lib/jsdom/living/nodes/HTMLSpanElement-impl.js +9 -0
  3. node_modules/jsdom/lib/jsdom/living/nodes/HTMLStyleElement-impl.js +83 -0
  4. node_modules/jsdom/lib/jsdom/living/nodes/HTMLTableCaptionElement-impl.js +9 -0
  5. node_modules/jsdom/lib/jsdom/living/nodes/HTMLTableCellElement-impl.js +40 -0
  6. node_modules/jsdom/lib/jsdom/living/nodes/HTMLTableColElement-impl.js +9 -0
  7. node_modules/jsdom/lib/jsdom/living/nodes/HTMLTableElement-impl.js +236 -0
  8. node_modules/jsdom/lib/jsdom/living/nodes/HTMLTableRowElement-impl.js +88 -0
  9. node_modules/jsdom/lib/jsdom/living/nodes/HTMLTableSectionElement-impl.js +61 -0
  10. node_modules/jsdom/lib/jsdom/living/nodes/HTMLTemplateElement-impl.js +67 -0
  11. node_modules/jsdom/lib/jsdom/living/nodes/HTMLTextAreaElement-impl.js +244 -0
  12. node_modules/jsdom/lib/jsdom/living/nodes/HTMLTimeElement-impl.js +9 -0
  13. node_modules/jsdom/lib/jsdom/living/nodes/HTMLTitleElement-impl.js +18 -0
  14. node_modules/jsdom/lib/jsdom/living/nodes/HTMLTrackElement-impl.js +13 -0
  15. node_modules/jsdom/lib/jsdom/living/nodes/HTMLUListElement-impl.js +9 -0
  16. node_modules/jsdom/lib/jsdom/living/nodes/HTMLUnknownElement-impl.js +9 -0
  17. node_modules/jsdom/lib/jsdom/living/nodes/HTMLVideoElement-impl.js +17 -0
  18. node_modules/jsdom/lib/jsdom/living/nodes/LinkStyle-impl.js +2 -0
  19. node_modules/jsdom/lib/jsdom/living/nodes/Node-impl.js +1182 -0
  20. node_modules/jsdom/lib/jsdom/living/nodes/NodeList-impl.js +43 -0
  21. node_modules/jsdom/lib/jsdom/living/nodes/NonDocumentTypeChildNode-impl.js +28 -0
  22. node_modules/jsdom/lib/jsdom/living/nodes/NonElementParentNode-impl.js +11 -0
  23. node_modules/jsdom/lib/jsdom/living/nodes/ParentNode-impl.js +90 -0
  24. node_modules/jsdom/lib/jsdom/living/nodes/ProcessingInstruction-impl.js +22 -0
  25. node_modules/jsdom/lib/jsdom/living/nodes/RadioNodeList-impl.js +49 -0
  26. node_modules/jsdom/lib/jsdom/living/nodes/SVGDefsElement-impl.js +9 -0
  27. node_modules/jsdom/lib/jsdom/living/nodes/SVGDescElement-impl.js +9 -0
  28. node_modules/jsdom/lib/jsdom/living/nodes/SVGElement-impl.js +64 -0
  29. node_modules/jsdom/lib/jsdom/living/nodes/SVGGElement-impl.js +9 -0
  30. node_modules/jsdom/lib/jsdom/living/nodes/SVGGraphicsElement-impl.js +16 -0
  31. node_modules/jsdom/lib/jsdom/living/nodes/SVGMetadataElement-impl.js +9 -0
  32. node_modules/jsdom/lib/jsdom/living/nodes/SVGSVGElement-impl.js +40 -0
  33. node_modules/jsdom/lib/jsdom/living/nodes/SVGSwitchElement-impl.js +9 -0
  34. node_modules/jsdom/lib/jsdom/living/nodes/SVGSymbolElement-impl.js +9 -0
  35. node_modules/jsdom/lib/jsdom/living/nodes/SVGTests-impl.js +42 -0
  36. node_modules/jsdom/lib/jsdom/living/nodes/SVGTitleElement-impl.js +9 -0
  37. node_modules/jsdom/lib/jsdom/living/nodes/ShadowRoot-impl.js +41 -0
  38. node_modules/jsdom/lib/jsdom/living/nodes/Slotable-impl.js +48 -0
  39. node_modules/jsdom/lib/jsdom/living/nodes/Text-impl.js +96 -0
  40. node_modules/jsdom/lib/jsdom/living/nodes/WindowEventHandlers-impl.js +14 -0
  41. node_modules/jsdom/lib/jsdom/living/nodes/XMLDocument-impl.js +4 -0
  42. node_modules/jsdom/lib/jsdom/living/range/AbstractRange-impl.js +43 -0
  43. node_modules/jsdom/lib/jsdom/living/range/Range-impl.js +902 -0
  44. node_modules/jsdom/lib/jsdom/living/range/StaticRange-impl.js +39 -0
  45. node_modules/jsdom/lib/jsdom/living/range/boundary-point.js +47 -0
  46. node_modules/jsdom/lib/jsdom/living/selection/Selection-impl.js +358 -0
  47. node_modules/jsdom/lib/jsdom/living/svg/SVGAnimatedPreserveAspectRatio-impl.js +24 -0
  48. node_modules/jsdom/lib/jsdom/living/svg/SVGAnimatedRect-impl.js +122 -0
  49. node_modules/jsdom/lib/jsdom/living/svg/SVGAnimatedString-impl.js +42 -0
  50. node_modules/jsdom/lib/jsdom/living/svg/SVGListBase.js +195 -0
.gitattributes CHANGED
@@ -51,3 +51,5 @@ node_modules/gifwrap/test/fixtures/quantized/hairstreak32_Sorokin.png filter=lfs
51
  node_modules/gifwrap/test/fixtures/quantized/hairstreak32_Wu.png filter=lfs diff=lfs merge=lfs -text
52
  node_modules/gifwrap/test/fixtures/quantized/sculptmap256_Sorokin_FloydSteinberg.png filter=lfs diff=lfs merge=lfs -text
53
  node_modules/gifwrap/test/fixtures/rnaples-offsets-public.gif filter=lfs diff=lfs merge=lfs -text
 
 
 
51
  node_modules/gifwrap/test/fixtures/quantized/hairstreak32_Wu.png filter=lfs diff=lfs merge=lfs -text
52
  node_modules/gifwrap/test/fixtures/quantized/sculptmap256_Sorokin_FloydSteinberg.png filter=lfs diff=lfs merge=lfs -text
53
  node_modules/gifwrap/test/fixtures/rnaples-offsets-public.gif filter=lfs diff=lfs merge=lfs -text
54
+ node_modules/lightningcss-linux-x64-gnu/lightningcss.linux-x64-gnu.node filter=lfs diff=lfs merge=lfs -text
55
+ node_modules/lightningcss-linux-x64-musl/lightningcss.linux-x64-musl.node filter=lfs diff=lfs merge=lfs -text
node_modules/jsdom/lib/jsdom/living/nodes/HTMLSpanElement-impl.js ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ "use strict";
2
+
3
+ const HTMLElementImpl = require("./HTMLElement-impl").implementation;
4
+
5
+ class HTMLSpanElementImpl extends HTMLElementImpl { }
6
+
7
+ module.exports = {
8
+ implementation: HTMLSpanElementImpl
9
+ };
node_modules/jsdom/lib/jsdom/living/nodes/HTMLStyleElement-impl.js ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "use strict";
2
+ const HTMLElementImpl = require("./HTMLElement-impl").implementation;
3
+ const { addStyleSheet, removeStyleSheet, createStyleSheetForElement } = require("../css/helpers/stylesheets");
4
+ const { childTextContent } = require("../helpers/text");
5
+ const { asciiCaseInsensitiveMatch } = require("../helpers/strings");
6
+
7
+ class HTMLStyleElementImpl extends HTMLElementImpl {
8
+ constructor(globalObject, args, privateData) {
9
+ super(globalObject, args, privateData);
10
+
11
+ this.sheet = null;
12
+ this._isOnStackOfOpenElements = false;
13
+ }
14
+
15
+ get disabled() {
16
+ return this.sheet?.disabled ?? false;
17
+ }
18
+
19
+ set disabled(value) {
20
+ if (this.sheet) {
21
+ this.sheet.disabled = value;
22
+ }
23
+ }
24
+
25
+ _attach() {
26
+ super._attach();
27
+ if (!this._isOnStackOfOpenElements) {
28
+ this._updateAStyleBlock();
29
+ }
30
+ }
31
+
32
+ _detach() {
33
+ super._detach();
34
+ if (!this._isOnStackOfOpenElements) {
35
+ this._updateAStyleBlock();
36
+ }
37
+ }
38
+
39
+ _childTextContentChangeSteps() {
40
+ super._childTextContentChangeSteps();
41
+
42
+ // This guard is not required by the spec, but should be unobservable (since you can't run script during the middle
43
+ // of parsing a <style> element) and saves a bunch of unnecessary work.
44
+ if (!this._isOnStackOfOpenElements) {
45
+ this._updateAStyleBlock();
46
+ }
47
+ }
48
+
49
+ _poppedOffStackOfOpenElements() {
50
+ this._isOnStackOfOpenElements = false;
51
+ this._updateAStyleBlock();
52
+ }
53
+
54
+ _pushedOnStackOfOpenElements() {
55
+ this._isOnStackOfOpenElements = true;
56
+ }
57
+
58
+ _updateAStyleBlock() {
59
+ if (this.sheet) {
60
+ removeStyleSheet(this.sheet, this);
61
+ }
62
+
63
+ // Browsing-context connected, per https://github.com/whatwg/html/issues/4547
64
+ if (!this.isConnected || !this._ownerDocument._defaultView) {
65
+ return;
66
+ }
67
+
68
+ const type = this.getAttributeNS(null, "type");
69
+ if (type !== null && type !== "" && !asciiCaseInsensitiveMatch(type, "text/css")) {
70
+ return;
71
+ }
72
+
73
+ // Not implemented: CSP
74
+
75
+ const content = childTextContent(this);
76
+ const createdSheet = createStyleSheetForElement(content, this);
77
+ addStyleSheet(createdSheet, this);
78
+ }
79
+ }
80
+
81
+ module.exports = {
82
+ implementation: HTMLStyleElementImpl
83
+ };
node_modules/jsdom/lib/jsdom/living/nodes/HTMLTableCaptionElement-impl.js ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ "use strict";
2
+
3
+ const HTMLElementImpl = require("./HTMLElement-impl").implementation;
4
+
5
+ class HTMLTableCaptionElementImpl extends HTMLElementImpl { }
6
+
7
+ module.exports = {
8
+ implementation: HTMLTableCaptionElementImpl
9
+ };
node_modules/jsdom/lib/jsdom/living/nodes/HTMLTableCellElement-impl.js ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "use strict";
2
+
3
+ const HTMLElementImpl = require("./HTMLElement-impl").implementation;
4
+
5
+ const { asciiLowercase } = require("../helpers/strings");
6
+ const { closest } = require("../helpers/traversal");
7
+
8
+ class HTMLTableCellElementImpl extends HTMLElementImpl {
9
+ get cellIndex() {
10
+ const tr = closest(this, "tr");
11
+ if (tr === null) {
12
+ return -1;
13
+ }
14
+
15
+ return tr.cells.indexOf(this);
16
+ }
17
+
18
+ get scope() {
19
+ let value = this.getAttributeNS(null, "scope");
20
+ if (value === null) {
21
+ return "";
22
+ }
23
+
24
+ // Enumerated attribute is matched ASCII-case-insensitively.
25
+ value = asciiLowercase(value);
26
+ if (value === "row" || value === "col" || value === "rowgroup" || value === "colgroup") {
27
+ return value;
28
+ }
29
+
30
+ return "";
31
+ }
32
+
33
+ set scope(V) {
34
+ this.setAttributeNS(null, "scope", V);
35
+ }
36
+ }
37
+
38
+ module.exports = {
39
+ implementation: HTMLTableCellElementImpl
40
+ };
node_modules/jsdom/lib/jsdom/living/nodes/HTMLTableColElement-impl.js ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ "use strict";
2
+
3
+ const HTMLElementImpl = require("./HTMLElement-impl").implementation;
4
+
5
+ class HTMLTableColElementImpl extends HTMLElementImpl { }
6
+
7
+ module.exports = {
8
+ implementation: HTMLTableColElementImpl
9
+ };
node_modules/jsdom/lib/jsdom/living/nodes/HTMLTableElement-impl.js ADDED
@@ -0,0 +1,236 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "use strict";
2
+ const DOMException = require("../../../generated/idl/DOMException");
3
+ const HTMLElementImpl = require("./HTMLElement-impl").implementation;
4
+ const { HTML_NS } = require("../helpers/namespaces");
5
+ const { domSymbolTree } = require("../helpers/internal-constants");
6
+ const { firstChildWithLocalName, childrenByLocalName } = require("../helpers/traversal");
7
+ const HTMLCollection = require("../../../generated/idl/HTMLCollection");
8
+ const NODE_TYPE = require("../node-type");
9
+
10
+ function tHeadInsertionPoint(table) {
11
+ const iterator = domSymbolTree.childrenIterator(table);
12
+ for (const child of iterator) {
13
+ if (child.nodeType !== NODE_TYPE.ELEMENT_NODE) {
14
+ continue;
15
+ }
16
+
17
+ if (child._namespaceURI !== HTML_NS || (child._localName !== "caption" && child._localName !== "colgroup")) {
18
+ return child;
19
+ }
20
+ }
21
+
22
+ return null;
23
+ }
24
+
25
+ class HTMLTableElementImpl extends HTMLElementImpl {
26
+ get caption() {
27
+ return firstChildWithLocalName(this, "caption");
28
+ }
29
+
30
+ set caption(value) {
31
+ const currentCaption = this.caption;
32
+ if (currentCaption !== null) {
33
+ this.removeChild(currentCaption);
34
+ }
35
+
36
+ if (value !== null) {
37
+ const insertionPoint = this.firstChild;
38
+ this.insertBefore(value, insertionPoint);
39
+ }
40
+ }
41
+
42
+ get tHead() {
43
+ return firstChildWithLocalName(this, "thead");
44
+ }
45
+
46
+ set tHead(value) {
47
+ if (value !== null && value._localName !== "thead") {
48
+ throw DOMException.create(this._globalObject, [
49
+ "Cannot set a non-thead element as a table header",
50
+ "HierarchyRequestError"
51
+ ]);
52
+ }
53
+
54
+ const currentHead = this.tHead;
55
+ if (currentHead !== null) {
56
+ this.removeChild(currentHead);
57
+ }
58
+
59
+ if (value !== null) {
60
+ const insertionPoint = tHeadInsertionPoint(this);
61
+ this.insertBefore(value, insertionPoint);
62
+ }
63
+ }
64
+
65
+ get tFoot() {
66
+ return firstChildWithLocalName(this, "tfoot");
67
+ }
68
+
69
+ set tFoot(value) {
70
+ if (value !== null && value._localName !== "tfoot") {
71
+ throw DOMException.create(this._globalObject, [
72
+ "Cannot set a non-tfoot element as a table footer",
73
+ "HierarchyRequestError"
74
+ ]);
75
+ }
76
+
77
+ const currentFoot = this.tFoot;
78
+ if (currentFoot !== null) {
79
+ this.removeChild(currentFoot);
80
+ }
81
+
82
+ if (value !== null) {
83
+ this.appendChild(value);
84
+ }
85
+ }
86
+
87
+ get rows() {
88
+ if (!this._rows) {
89
+ this._rows = HTMLCollection.createImpl(this._globalObject, [], {
90
+ element: this,
91
+ query: () => {
92
+ const headerRows = [];
93
+ const bodyRows = [];
94
+ const footerRows = [];
95
+
96
+ const iterator = domSymbolTree.childrenIterator(this);
97
+ for (const child of iterator) {
98
+ if (child.nodeType !== NODE_TYPE.ELEMENT_NODE || child._namespaceURI !== HTML_NS) {
99
+ continue;
100
+ }
101
+
102
+ if (child._localName === "thead") {
103
+ headerRows.push(...childrenByLocalName(child, "tr"));
104
+ } else if (child._localName === "tbody") {
105
+ bodyRows.push(...childrenByLocalName(child, "tr"));
106
+ } else if (child._localName === "tfoot") {
107
+ footerRows.push(...childrenByLocalName(child, "tr"));
108
+ } else if (child._localName === "tr") {
109
+ bodyRows.push(child);
110
+ }
111
+ }
112
+
113
+ return [...headerRows, ...bodyRows, ...footerRows];
114
+ }
115
+ });
116
+ }
117
+ return this._rows;
118
+ }
119
+
120
+ get tBodies() {
121
+ if (!this._tBodies) {
122
+ this._tBodies = HTMLCollection.createImpl(this._globalObject, [], {
123
+ element: this,
124
+ query: () => childrenByLocalName(this, "tbody")
125
+ });
126
+ }
127
+ return this._tBodies;
128
+ }
129
+
130
+ createTBody() {
131
+ const el = this._ownerDocument.createElement("TBODY");
132
+
133
+ const tbodies = childrenByLocalName(this, "tbody");
134
+ const insertionPoint = tbodies[tbodies.length - 1];
135
+
136
+ if (insertionPoint) {
137
+ this.insertBefore(el, insertionPoint.nextSibling);
138
+ } else {
139
+ this.appendChild(el);
140
+ }
141
+ return el;
142
+ }
143
+
144
+ createTHead() {
145
+ let el = this.tHead;
146
+ if (!el) {
147
+ el = this.tHead = this._ownerDocument.createElement("THEAD");
148
+ }
149
+ return el;
150
+ }
151
+
152
+ deleteTHead() {
153
+ this.tHead = null;
154
+ }
155
+
156
+ createTFoot() {
157
+ let el = this.tFoot;
158
+ if (!el) {
159
+ el = this.tFoot = this._ownerDocument.createElement("TFOOT");
160
+ }
161
+ return el;
162
+ }
163
+
164
+ deleteTFoot() {
165
+ this.tFoot = null;
166
+ }
167
+
168
+ createCaption() {
169
+ let el = this.caption;
170
+ if (!el) {
171
+ el = this.caption = this._ownerDocument.createElement("CAPTION");
172
+ }
173
+ return el;
174
+ }
175
+
176
+ deleteCaption() {
177
+ const c = this.caption;
178
+ if (c) {
179
+ c.parentNode.removeChild(c);
180
+ }
181
+ }
182
+
183
+ insertRow(index) {
184
+ if (index < -1 || index > this.rows.length) {
185
+ throw DOMException.create(this._globalObject, [
186
+ "Cannot insert a row at an index that is less than -1 or greater than the number of existing rows",
187
+ "IndexSizeError"
188
+ ]);
189
+ }
190
+
191
+ const tr = this._ownerDocument.createElement("tr");
192
+
193
+ if (this.rows.length === 0 && this.tBodies.length === 0) {
194
+ const tBody = this._ownerDocument.createElement("tbody");
195
+ tBody.appendChild(tr);
196
+ this.appendChild(tBody);
197
+ } else if (this.rows.length === 0) {
198
+ const tBody = this.tBodies.item(this.tBodies.length - 1);
199
+ tBody.appendChild(tr);
200
+ } else if (index === -1 || index === this.rows.length) {
201
+ const tSection = this.rows.item(this.rows.length - 1).parentNode;
202
+ tSection.appendChild(tr);
203
+ } else {
204
+ const beforeTR = this.rows.item(index);
205
+ const tSection = beforeTR.parentNode;
206
+ tSection.insertBefore(tr, beforeTR);
207
+ }
208
+
209
+ return tr;
210
+ }
211
+
212
+ deleteRow(index) {
213
+ const rowLength = this.rows.length;
214
+ if (index < -1 || index >= rowLength) {
215
+ throw DOMException.create(this._globalObject, [
216
+ `Cannot delete a row at index ${index}, where no row exists`,
217
+ "IndexSizeError"
218
+ ]);
219
+ }
220
+
221
+ if (index === -1) {
222
+ if (rowLength === 0) {
223
+ return;
224
+ }
225
+
226
+ index = rowLength - 1;
227
+ }
228
+
229
+ const tr = this.rows.item(index);
230
+ tr.parentNode.removeChild(tr);
231
+ }
232
+ }
233
+
234
+ module.exports = {
235
+ implementation: HTMLTableElementImpl
236
+ };
node_modules/jsdom/lib/jsdom/living/nodes/HTMLTableRowElement-impl.js ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "use strict";
2
+
3
+ const DOMException = require("../../../generated/idl/DOMException");
4
+ const HTMLElementImpl = require("./HTMLElement-impl").implementation;
5
+ const HTMLCollection = require("../../../generated/idl/HTMLCollection");
6
+ const { HTML_NS } = require("../helpers/namespaces");
7
+ const { childrenByLocalNames } = require("../helpers/traversal");
8
+ const { domSymbolTree } = require("../helpers/internal-constants");
9
+
10
+ const cellLocalNames = new Set(["td", "th"]);
11
+
12
+ class HTMLTableRowElementImpl extends HTMLElementImpl {
13
+ get cells() {
14
+ if (!this._cells) {
15
+ this._cells = HTMLCollection.createImpl(this._globalObject, [], {
16
+ element: this,
17
+ query: () => childrenByLocalNames(this, cellLocalNames)
18
+ });
19
+ }
20
+ return this._cells;
21
+ }
22
+
23
+ get rowIndex() {
24
+ const parent = this.parentElement;
25
+ if (parent === null || parent.namespaceURI !== HTML_NS) {
26
+ return -1;
27
+ }
28
+
29
+ let tableElement = parent;
30
+ if (parent.localName === "thead" || parent.localName === "tbody" || parent.localName === "tfoot") {
31
+ tableElement = parent.parentElement;
32
+ }
33
+ if (tableElement === null || tableElement.namespaceURI !== HTML_NS || tableElement.localName !== "table") {
34
+ return -1;
35
+ }
36
+
37
+ return tableElement.rows.indexOf(this);
38
+ }
39
+
40
+ get sectionRowIndex() {
41
+ const parent = domSymbolTree.parent(this);
42
+ if (parent === null) {
43
+ return -1;
44
+ }
45
+
46
+ const { rows } = parent;
47
+ if (!rows) {
48
+ return -1;
49
+ }
50
+
51
+ return rows.indexOf(this);
52
+ }
53
+
54
+ insertCell(index) {
55
+ const td = this._ownerDocument.createElement("TD");
56
+ const { cells } = this;
57
+ if (index < -1 || index > cells.length) {
58
+ throw DOMException.create(this._globalObject, ["The index is not in the allowed range.", "IndexSizeError"]);
59
+ }
60
+ if (index === -1 || index === cells.length) {
61
+ this._append(td);
62
+ } else {
63
+ const ref = cells.item(index);
64
+ this._insert(td, ref);
65
+ }
66
+ return td;
67
+ }
68
+
69
+ deleteCell(index) {
70
+ const { cells } = this;
71
+ if (index < -1 || index >= cells.length) {
72
+ throw DOMException.create(this._globalObject, ["The index is not in the allowed range.", "IndexSizeError"]);
73
+ }
74
+ if (index === -1) {
75
+ if (cells.length === 0) {
76
+ return;
77
+ }
78
+
79
+ index = cells.length - 1;
80
+ }
81
+ const td = cells.item(index);
82
+ this._remove(td);
83
+ }
84
+ }
85
+
86
+ module.exports = {
87
+ implementation: HTMLTableRowElementImpl
88
+ };
node_modules/jsdom/lib/jsdom/living/nodes/HTMLTableSectionElement-impl.js ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "use strict";
2
+
3
+ const HTMLElementImpl = require("./HTMLElement-impl").implementation;
4
+ const { childrenByLocalName } = require("../helpers/traversal");
5
+ const HTMLCollection = require("../../../generated/idl/HTMLCollection");
6
+ const DOMException = require("../../../generated/idl/DOMException");
7
+
8
+ class HTMLTableSectionElementImpl extends HTMLElementImpl {
9
+ get rows() {
10
+ if (!this._rows) {
11
+ this._rows = HTMLCollection.createImpl(this._globalObject, [], {
12
+ element: this,
13
+ query: () => childrenByLocalName(this, "tr")
14
+ });
15
+ }
16
+ return this._rows;
17
+ }
18
+
19
+ insertRow(index) {
20
+ if (index < -1 || index > this.rows.length) {
21
+ throw DOMException.create(this._globalObject, [
22
+ "Cannot insert a row at an index that is less than -1 or greater than the number of existing rows",
23
+ "IndexSizeError"
24
+ ]);
25
+ }
26
+
27
+ const tr = this._ownerDocument.createElement("tr");
28
+
29
+ if (index === -1 || index === this.rows.length) {
30
+ this._append(tr);
31
+ } else {
32
+ const beforeTR = this.rows.item(index);
33
+ this._insert(tr, beforeTR);
34
+ }
35
+
36
+ return tr;
37
+ }
38
+
39
+ deleteRow(index) {
40
+ if (index < -1 || index >= this.rows.length) {
41
+ throw DOMException.create(this._globalObject, [
42
+ `Cannot delete a row at index ${index}, where no row exists`,
43
+ "IndexSizeError"
44
+ ]);
45
+ }
46
+
47
+ if (index === -1) {
48
+ if (this.rows.length > 0) {
49
+ const tr = this.rows.item(this.rows.length - 1);
50
+ this._remove(tr);
51
+ }
52
+ } else {
53
+ const tr = this.rows.item(index);
54
+ this._remove(tr);
55
+ }
56
+ }
57
+ }
58
+
59
+ module.exports = {
60
+ implementation: HTMLTableSectionElementImpl
61
+ };
node_modules/jsdom/lib/jsdom/living/nodes/HTMLTemplateElement-impl.js ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "use strict";
2
+
3
+ const HTMLElementImpl = require("./HTMLElement-impl").implementation;
4
+
5
+ const Document = require("../../../generated/idl/Document");
6
+ const DocumentFragment = require("../../../generated/idl/DocumentFragment");
7
+
8
+ const { cloningSteps, domSymbolTree } = require("../helpers/internal-constants");
9
+ const { clone } = require("../node");
10
+
11
+ class HTMLTemplateElementImpl extends HTMLElementImpl {
12
+ constructor(globalObject, args, privateData) {
13
+ super(globalObject, args, privateData);
14
+
15
+ const doc = this._appropriateTemplateContentsOwnerDocument(this._ownerDocument);
16
+ this._templateContents = DocumentFragment.createImpl(this._globalObject, [], {
17
+ ownerDocument: doc,
18
+ host: this
19
+ });
20
+ }
21
+
22
+ // https://html.spec.whatwg.org/multipage/scripting.html#appropriate-template-contents-owner-document
23
+ _appropriateTemplateContentsOwnerDocument(doc) {
24
+ if (!doc._isInertTemplateDocument) {
25
+ if (doc._associatedInertTemplateDocument === undefined) {
26
+ const newDoc = Document.createImpl(this._globalObject, [], {
27
+ options: {
28
+ parsingMode: doc._parsingMode,
29
+ encoding: doc._encoding
30
+ }
31
+ });
32
+ newDoc._isInertTemplateDocument = true;
33
+
34
+ doc._associatedInertTemplateDocument = newDoc;
35
+ }
36
+
37
+ doc = doc._associatedInertTemplateDocument;
38
+ }
39
+
40
+ return doc;
41
+ }
42
+
43
+ // https://html.spec.whatwg.org/multipage/scripting.html#template-adopting-steps
44
+ _adoptingSteps() {
45
+ const doc = this._appropriateTemplateContentsOwnerDocument(this._ownerDocument);
46
+ doc._adoptNode(this._templateContents);
47
+ }
48
+
49
+ get content() {
50
+ return this._templateContents;
51
+ }
52
+
53
+ [cloningSteps](copy, node, document, cloneChildren) {
54
+ if (!cloneChildren) {
55
+ return;
56
+ }
57
+
58
+ for (const child of domSymbolTree.childrenIterator(node._templateContents)) {
59
+ const childCopy = clone(child, copy._templateContents._ownerDocument, true);
60
+ copy._templateContents.appendChild(childCopy);
61
+ }
62
+ }
63
+ }
64
+
65
+ module.exports = {
66
+ implementation: HTMLTemplateElementImpl
67
+ };
node_modules/jsdom/lib/jsdom/living/nodes/HTMLTextAreaElement-impl.js ADDED
@@ -0,0 +1,244 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "use strict";
2
+
3
+ const HTMLElementImpl = require("./HTMLElement-impl").implementation;
4
+
5
+ const DefaultConstraintValidationImpl =
6
+ require("../constraint-validation/DefaultConstraintValidation-impl").implementation;
7
+ const ValidityState = require("../../../generated/idl/ValidityState");
8
+ const { mixin } = require("../../utils");
9
+
10
+ const DOMException = require("../../../generated/idl/DOMException");
11
+ const { cloningSteps } = require("../helpers/internal-constants");
12
+ const { isDisabled, getLabelsForLabelable, formOwner } = require("../helpers/form-controls");
13
+ const { childTextContent } = require("../helpers/text");
14
+ const { fireAnEvent } = require("../helpers/events");
15
+
16
+ class HTMLTextAreaElementImpl extends HTMLElementImpl {
17
+ constructor(globalObject, args, privateData) {
18
+ super(globalObject, args, privateData);
19
+
20
+ this._selectionStart = this._selectionEnd = 0;
21
+ this._selectionDirection = "none";
22
+ this._rawValue = "";
23
+ this._dirtyValue = false;
24
+
25
+ this._customValidityErrorMessage = "";
26
+
27
+ this._labels = null;
28
+ }
29
+
30
+ _formReset() {
31
+ this._rawValue = childTextContent(this);
32
+ this._dirtyValue = false;
33
+ }
34
+
35
+ _getAPIValue() {
36
+ return this._rawValue.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
37
+ }
38
+
39
+ // https://html.spec.whatwg.org/multipage/form-elements.html#textarea-wrapping-transformation
40
+ _getValue() {
41
+ const apiValue = this._getAPIValue();
42
+ const wrap = this.getAttributeNS(null, "wrap");
43
+ return wrap === "hard" ?
44
+ textareaWrappingTransformation(apiValue, this.getAttributeNS(null, "cols") ?? 20) :
45
+ apiValue;
46
+ }
47
+
48
+ _childTextContentChangeSteps() {
49
+ super._childTextContentChangeSteps();
50
+
51
+ if (this._dirtyValue === false) {
52
+ this._rawValue = childTextContent(this);
53
+ }
54
+ }
55
+
56
+ get labels() {
57
+ return getLabelsForLabelable(this);
58
+ }
59
+
60
+ get form() {
61
+ return formOwner(this);
62
+ }
63
+
64
+ get defaultValue() {
65
+ return childTextContent(this);
66
+ }
67
+
68
+ set defaultValue(val) {
69
+ this.textContent = val;
70
+ }
71
+
72
+ get value() {
73
+ return this._getAPIValue();
74
+ }
75
+
76
+ set value(val) {
77
+ // https://html.spec.whatwg.org/multipage/form-elements.html#dom-textarea-value
78
+ const oldAPIValue = this._getAPIValue();
79
+ this._rawValue = val;
80
+ this._dirtyValue = true;
81
+
82
+ if (oldAPIValue !== this._getAPIValue()) {
83
+ this._selectionStart = this._selectionEnd = this._getValueLength();
84
+ this._selectionDirection = "none";
85
+ }
86
+ }
87
+
88
+ get textLength() {
89
+ return this.value.length; // code unit length (16 bit)
90
+ }
91
+
92
+ get type() {
93
+ return "textarea";
94
+ }
95
+
96
+ _dispatchSelectEvent() {
97
+ setTimeout(() => fireAnEvent("select", this, undefined, { bubbles: true, cancelable: false }), 0);
98
+ }
99
+
100
+ _getValueLength() {
101
+ return typeof this.value === "string" ? this.value.length : 0;
102
+ }
103
+
104
+ select() {
105
+ this._selectionStart = 0;
106
+ this._selectionEnd = this._getValueLength();
107
+ this._selectionDirection = "none";
108
+ this._dispatchSelectEvent();
109
+ }
110
+
111
+ get selectionStart() {
112
+ return this._selectionStart;
113
+ }
114
+
115
+ set selectionStart(start) {
116
+ this.setSelectionRange(start, Math.max(start, this._selectionEnd), this._selectionDirection);
117
+ }
118
+
119
+ get selectionEnd() {
120
+ return this._selectionEnd;
121
+ }
122
+
123
+ set selectionEnd(end) {
124
+ this.setSelectionRange(this._selectionStart, end, this._selectionDirection);
125
+ }
126
+
127
+ get selectionDirection() {
128
+ return this._selectionDirection;
129
+ }
130
+
131
+ set selectionDirection(dir) {
132
+ this.setSelectionRange(this._selectionStart, this._selectionEnd, dir);
133
+ }
134
+
135
+ setSelectionRange(start, end, dir) {
136
+ this._selectionEnd = Math.min(end, this._getValueLength());
137
+ this._selectionStart = Math.min(start, this._selectionEnd);
138
+ this._selectionDirection = dir === "forward" || dir === "backward" ? dir : "none";
139
+ this._dispatchSelectEvent();
140
+ }
141
+
142
+ setRangeText(repl, start, end, selectionMode = "preserve") {
143
+ if (arguments.length < 2) {
144
+ start = this._selectionStart;
145
+ end = this._selectionEnd;
146
+ } else if (start > end) {
147
+ throw DOMException.create(this._globalObject, ["The index is not in the allowed range.", "IndexSizeError"]);
148
+ }
149
+
150
+ start = Math.min(start, this._getValueLength());
151
+ end = Math.min(end, this._getValueLength());
152
+
153
+ const val = this.value;
154
+ let selStart = this._selectionStart;
155
+ let selEnd = this._selectionEnd;
156
+
157
+ this.value = val.slice(0, start) + repl + val.slice(end);
158
+
159
+ const newEnd = start + repl.length;
160
+
161
+ if (selectionMode === "select") {
162
+ this.setSelectionRange(start, newEnd);
163
+ } else if (selectionMode === "start") {
164
+ this.setSelectionRange(start, start);
165
+ } else if (selectionMode === "end") {
166
+ this.setSelectionRange(newEnd, newEnd);
167
+ } else { // preserve
168
+ const delta = repl.length - (end - start);
169
+
170
+ if (selStart > end) {
171
+ selStart += delta;
172
+ } else if (selStart > start) {
173
+ selStart = start;
174
+ }
175
+
176
+ if (selEnd > end) {
177
+ selEnd += delta;
178
+ } else if (selEnd > start) {
179
+ selEnd = newEnd;
180
+ }
181
+
182
+ this.setSelectionRange(selStart, selEnd);
183
+ }
184
+ }
185
+
186
+ _barredFromConstraintValidationSpecialization() {
187
+ return this.hasAttributeNS(null, "readonly");
188
+ }
189
+
190
+ get _mutable() {
191
+ return !isDisabled(this) && !this.hasAttributeNS(null, "readonly");
192
+ }
193
+
194
+ // https://html.spec.whatwg.org/multipage/form-elements.html#attr-textarea-required
195
+ get validity() {
196
+ if (!this._validity) {
197
+ const state = {
198
+ valueMissing: () => this.hasAttributeNS(null, "required") && this._mutable && this.value === ""
199
+ };
200
+
201
+ this._validity = ValidityState.createImpl(this._globalObject, [], {
202
+ element: this,
203
+ state
204
+ });
205
+ }
206
+ return this._validity;
207
+ }
208
+
209
+ [cloningSteps](copy, node) {
210
+ copy._dirtyValue = node._dirtyValue;
211
+ copy._rawValue = node._rawValue;
212
+ }
213
+ }
214
+
215
+ mixin(HTMLTextAreaElementImpl.prototype, DefaultConstraintValidationImpl.prototype);
216
+
217
+ module.exports = {
218
+ implementation: HTMLTextAreaElementImpl
219
+ };
220
+
221
+ function textareaWrappingTransformation(text, cols) {
222
+ let lineStart = 0;
223
+ let lineEnd = text.indexOf("\n");
224
+ if (lineEnd === -1) {
225
+ lineEnd = text.length;
226
+ }
227
+
228
+ while (lineStart < text.length) {
229
+ const lineLength = lineEnd - lineStart;
230
+ if (lineLength > cols) {
231
+ // split the line
232
+ lineEnd = lineStart + cols;
233
+ text = text.slice(0, lineEnd) + "\n" + text.slice(lineEnd);
234
+ }
235
+ // move to next line
236
+ lineStart = lineEnd + 1; // step over the newline
237
+ lineEnd = text.indexOf("\n", lineStart);
238
+ if (lineEnd === -1) {
239
+ lineEnd = text.length;
240
+ }
241
+ }
242
+
243
+ return text;
244
+ }
node_modules/jsdom/lib/jsdom/living/nodes/HTMLTimeElement-impl.js ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ "use strict";
2
+
3
+ const HTMLElementImpl = require("./HTMLElement-impl").implementation;
4
+
5
+ class HTMLTimeElementImpl extends HTMLElementImpl { }
6
+
7
+ module.exports = {
8
+ implementation: HTMLTimeElementImpl
9
+ };
node_modules/jsdom/lib/jsdom/living/nodes/HTMLTitleElement-impl.js ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "use strict";
2
+
3
+ const HTMLElementImpl = require("./HTMLElement-impl").implementation;
4
+ const { childTextContent } = require("../helpers/text");
5
+
6
+ class HTMLTitleElementImpl extends HTMLElementImpl {
7
+ get text() {
8
+ return childTextContent(this);
9
+ }
10
+
11
+ set text(value) {
12
+ this.textContent = value;
13
+ }
14
+ }
15
+
16
+ module.exports = {
17
+ implementation: HTMLTitleElementImpl
18
+ };
node_modules/jsdom/lib/jsdom/living/nodes/HTMLTrackElement-impl.js ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "use strict";
2
+
3
+ const HTMLElementImpl = require("./HTMLElement-impl").implementation;
4
+
5
+ class HTMLTrackElementImpl extends HTMLElementImpl {
6
+ get readyState() {
7
+ return 0;
8
+ }
9
+ }
10
+
11
+ module.exports = {
12
+ implementation: HTMLTrackElementImpl
13
+ };
node_modules/jsdom/lib/jsdom/living/nodes/HTMLUListElement-impl.js ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ "use strict";
2
+
3
+ const HTMLElementImpl = require("./HTMLElement-impl").implementation;
4
+
5
+ class HTMLUListElementImpl extends HTMLElementImpl { }
6
+
7
+ module.exports = {
8
+ implementation: HTMLUListElementImpl
9
+ };
node_modules/jsdom/lib/jsdom/living/nodes/HTMLUnknownElement-impl.js ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ "use strict";
2
+
3
+ const HTMLElementImpl = require("./HTMLElement-impl").implementation;
4
+
5
+ class HTMLUnknownElementImpl extends HTMLElementImpl { }
6
+
7
+ module.exports = {
8
+ implementation: HTMLUnknownElementImpl
9
+ };
node_modules/jsdom/lib/jsdom/living/nodes/HTMLVideoElement-impl.js ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "use strict";
2
+
3
+ const HTMLMediaElementImpl = require("./HTMLMediaElement-impl").implementation;
4
+
5
+ class HTMLVideoElementImpl extends HTMLMediaElementImpl {
6
+ get videoWidth() {
7
+ return 0;
8
+ }
9
+
10
+ get videoHeight() {
11
+ return 0;
12
+ }
13
+ }
14
+
15
+ module.exports = {
16
+ implementation: HTMLVideoElementImpl
17
+ };
node_modules/jsdom/lib/jsdom/living/nodes/LinkStyle-impl.js ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ "use strict";
2
+ module.exports = class LinkStyleImpl {};
node_modules/jsdom/lib/jsdom/living/nodes/Node-impl.js ADDED
@@ -0,0 +1,1182 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "use strict";
2
+
3
+ const DOMException = require("../../../generated/idl/DOMException");
4
+
5
+ const EventTargetImpl = require("../events/EventTarget-impl").implementation;
6
+ const { simultaneousIterators } = require("../../utils");
7
+ const NODE_TYPE = require("../node-type");
8
+ const NODE_DOCUMENT_POSITION = require("../node-document-position");
9
+ const { clone, locateNamespacePrefix, locateNamespace } = require("../node");
10
+ const { setAnExistingAttributeValue } = require("../attributes");
11
+
12
+ const NodeList = require("../../../generated/idl/NodeList");
13
+
14
+ const { nodeRoot, nodeLength, isInclusiveAncestor } = require("../helpers/node");
15
+ const { domSymbolTree } = require("../helpers/internal-constants");
16
+ const { queueTreeMutationRecord } = require("../helpers/mutation-observers");
17
+ const { enqueueCECallbackReaction, tryUpgradeElement } = require("../helpers/custom-elements");
18
+ const {
19
+ isShadowRoot, shadowIncludingRoot, assignSlot, assignSlotableForTree, assignSlotable, signalSlotChange, isSlot,
20
+ shadowIncludingInclusiveDescendantsIterator, shadowIncludingDescendantsIterator
21
+ } = require("../helpers/shadow-dom");
22
+
23
+ function nodeEquals(a, b) {
24
+ if (a.nodeType !== b.nodeType) {
25
+ return false;
26
+ }
27
+
28
+ switch (a.nodeType) {
29
+ case NODE_TYPE.DOCUMENT_TYPE_NODE:
30
+ if (a.name !== b.name || a.publicId !== b.publicId ||
31
+ a.systemId !== b.systemId) {
32
+ return false;
33
+ }
34
+ break;
35
+ case NODE_TYPE.ELEMENT_NODE:
36
+ if (a._namespaceURI !== b._namespaceURI || a._prefix !== b._prefix || a._localName !== b._localName ||
37
+ a._attributeList.length !== b._attributeList.length) {
38
+ return false;
39
+ }
40
+ break;
41
+ case NODE_TYPE.ATTRIBUTE_NODE:
42
+ if (a._namespace !== b._namespace || a._localName !== b._localName || a._value !== b._value) {
43
+ return false;
44
+ }
45
+ break;
46
+ case NODE_TYPE.PROCESSING_INSTRUCTION_NODE:
47
+ if (a._target !== b._target || a._data !== b._data) {
48
+ return false;
49
+ }
50
+ break;
51
+ case NODE_TYPE.TEXT_NODE:
52
+ case NODE_TYPE.COMMENT_NODE:
53
+ if (a._data !== b._data) {
54
+ return false;
55
+ }
56
+ break;
57
+ }
58
+
59
+ if (a.nodeType === NODE_TYPE.ELEMENT_NODE && !attributeListsEqual(a, b)) {
60
+ return false;
61
+ }
62
+
63
+ for (const nodes of simultaneousIterators(domSymbolTree.childrenIterator(a), domSymbolTree.childrenIterator(b))) {
64
+ if (!nodes[0] || !nodes[1]) {
65
+ // mismatch in the amount of childNodes
66
+ return false;
67
+ }
68
+
69
+ if (!nodeEquals(nodes[0], nodes[1])) {
70
+ return false;
71
+ }
72
+ }
73
+
74
+ return true;
75
+ }
76
+
77
+ // Needed by https://dom.spec.whatwg.org/#concept-node-equals
78
+ function attributeListsEqual(elementA, elementB) {
79
+ const listA = elementA._attributeList;
80
+ const listB = elementB._attributeList;
81
+
82
+ const lengthA = listA.length;
83
+ const lengthB = listB.length;
84
+
85
+ if (lengthA !== lengthB) {
86
+ return false;
87
+ }
88
+
89
+ for (let i = 0; i < lengthA; ++i) {
90
+ const attrA = listA[i];
91
+
92
+ if (!listB.some(attrB => nodeEquals(attrA, attrB))) {
93
+ return false;
94
+ }
95
+ }
96
+
97
+ return true;
98
+ }
99
+
100
+ // https://dom.spec.whatwg.org/#concept-tree-host-including-inclusive-ancestor
101
+ function isHostInclusiveAncestor(nodeImplA, nodeImplB) {
102
+ for (const ancestor of domSymbolTree.ancestorsIterator(nodeImplB)) {
103
+ if (ancestor === nodeImplA) {
104
+ return true;
105
+ }
106
+ }
107
+
108
+ const rootImplB = nodeRoot(nodeImplB);
109
+ if (rootImplB._host) {
110
+ return isHostInclusiveAncestor(nodeImplA, rootImplB._host);
111
+ }
112
+
113
+ return false;
114
+ }
115
+
116
+ class NodeImpl extends EventTargetImpl {
117
+ constructor(globalObject, args, privateData) {
118
+ super(globalObject, args, privateData);
119
+
120
+ domSymbolTree.initialize(this);
121
+
122
+ this._ownerDocument = privateData.ownerDocument;
123
+
124
+ this._childNodesList = null;
125
+ this._childrenList = null;
126
+ this._version = 0;
127
+ this._cachedRoot = null;
128
+ this._memoizedQueries = {};
129
+ this._registeredObserverList = [];
130
+ this._referencedRanges = new Set(); // Set of WeakRef<Range>
131
+ }
132
+
133
+ // Generator that yields live Range objects from _referencedRanges,
134
+ // cleaning up any dead WeakRefs encountered during iteration.
135
+ * _liveRanges() {
136
+ for (const weakRef of this._referencedRanges) {
137
+ const range = weakRef.deref();
138
+ if (range) {
139
+ yield range;
140
+ } else {
141
+ // Range was garbage collected - remove the dead WeakRef
142
+ this._referencedRanges.delete(weakRef);
143
+ }
144
+ }
145
+ }
146
+
147
+ _getTheParent() {
148
+ if (this._assignedSlot) {
149
+ return this._assignedSlot;
150
+ }
151
+
152
+ return domSymbolTree.parent(this);
153
+ }
154
+
155
+ get parentNode() {
156
+ return domSymbolTree.parent(this);
157
+ }
158
+
159
+ getRootNode(options) {
160
+ return options?.composed ? shadowIncludingRoot(this) : nodeRoot(this);
161
+ }
162
+
163
+ get nodeName() {
164
+ switch (this.nodeType) {
165
+ case NODE_TYPE.ELEMENT_NODE:
166
+ return this.tagName;
167
+ case NODE_TYPE.ATTRIBUTE_NODE:
168
+ return this._qualifiedName;
169
+ case NODE_TYPE.TEXT_NODE:
170
+ return "#text";
171
+ case NODE_TYPE.CDATA_SECTION_NODE:
172
+ return "#cdata-section";
173
+ case NODE_TYPE.PROCESSING_INSTRUCTION_NODE:
174
+ return this.target;
175
+ case NODE_TYPE.COMMENT_NODE:
176
+ return "#comment";
177
+ case NODE_TYPE.DOCUMENT_NODE:
178
+ return "#document";
179
+ case NODE_TYPE.DOCUMENT_TYPE_NODE:
180
+ return this.name;
181
+ case NODE_TYPE.DOCUMENT_FRAGMENT_NODE:
182
+ return "#document-fragment";
183
+ }
184
+
185
+ // should never happen
186
+ return null;
187
+ }
188
+
189
+ get firstChild() {
190
+ return domSymbolTree.firstChild(this);
191
+ }
192
+
193
+ // https://dom.spec.whatwg.org/#connected
194
+ // https://dom.spec.whatwg.org/#dom-node-isconnected
195
+ get isConnected() {
196
+ const root = shadowIncludingRoot(this);
197
+ return root && root.nodeType === NODE_TYPE.DOCUMENT_NODE;
198
+ }
199
+
200
+ get ownerDocument() {
201
+ return this.nodeType === NODE_TYPE.DOCUMENT_NODE ? null : this._ownerDocument;
202
+ }
203
+
204
+ get lastChild() {
205
+ return domSymbolTree.lastChild(this);
206
+ }
207
+
208
+ get childNodes() {
209
+ if (!this._childNodesList) {
210
+ this._childNodesList = NodeList.createImpl(this._globalObject, [], {
211
+ element: this,
212
+ query: () => domSymbolTree.childrenToArray(this)
213
+ });
214
+ } else {
215
+ this._childNodesList._update();
216
+ }
217
+
218
+ return this._childNodesList;
219
+ }
220
+
221
+ get nextSibling() {
222
+ return domSymbolTree.nextSibling(this);
223
+ }
224
+
225
+ get previousSibling() {
226
+ return domSymbolTree.previousSibling(this);
227
+ }
228
+
229
+ _modified() {
230
+ this._version++;
231
+ for (const ancestor of domSymbolTree.ancestorsIterator(this)) {
232
+ ancestor._version++;
233
+ }
234
+
235
+ if (this._childrenList) {
236
+ this._childrenList._update();
237
+ }
238
+ if (this._childNodesList) {
239
+ this._childNodesList._update();
240
+ }
241
+ this._clearMemoizedQueries();
242
+ if (this._attached) {
243
+ this._ownerDocument._clearStyleCache();
244
+ }
245
+ }
246
+
247
+ _childTextContentChangeSteps() {
248
+ if (this._attached) {
249
+ this._ownerDocument._clearStyleCache();
250
+ }
251
+ }
252
+
253
+ _clearMemoizedQueries() {
254
+ this._memoizedQueries = {};
255
+ const myParent = domSymbolTree.parent(this);
256
+ if (myParent) {
257
+ myParent._clearMemoizedQueries();
258
+ }
259
+ }
260
+
261
+ _descendantRemoved(parent, child) {
262
+ const myParent = domSymbolTree.parent(this);
263
+ if (myParent) {
264
+ myParent._descendantRemoved(parent, child);
265
+ }
266
+ }
267
+
268
+ _descendantAdded(parent, child) {
269
+ const myParent = domSymbolTree.parent(this);
270
+ if (myParent) {
271
+ myParent._descendantAdded(parent, child);
272
+ }
273
+ }
274
+
275
+ _attach() {
276
+ this._attached = true;
277
+
278
+ for (const child of domSymbolTree.childrenIterator(this)) {
279
+ if (child._attach) {
280
+ child._attach();
281
+ }
282
+ }
283
+ }
284
+
285
+ _detach() {
286
+ this._attached = false;
287
+
288
+ if (this._ownerDocument && this._ownerDocument._lastFocusedElement === this) {
289
+ this._ownerDocument._lastFocusedElement = null;
290
+ }
291
+
292
+ for (const child of domSymbolTree.childrenIterator(this)) {
293
+ if (child._detach) {
294
+ child._detach();
295
+ }
296
+ }
297
+ }
298
+
299
+ hasChildNodes() {
300
+ return domSymbolTree.hasChildren(this);
301
+ }
302
+
303
+ // https://dom.spec.whatwg.org/#dom-node-normalize
304
+ normalize() {
305
+ // It is important to use a treeToArray instead of a treeToIterator here, because the
306
+ // treeToIterator doesn't support tree mutation in the middle of the traversal.
307
+ for (const node of domSymbolTree.treeToArray(this)) {
308
+ const parentNode = domSymbolTree.parent(node);
309
+ if (parentNode === null || node.nodeType !== NODE_TYPE.TEXT_NODE) {
310
+ continue;
311
+ }
312
+
313
+ let length = nodeLength(node);
314
+
315
+ if (length === 0) {
316
+ parentNode._remove(node);
317
+ continue;
318
+ }
319
+
320
+ const continuousExclusiveTextNodes = [];
321
+
322
+ for (const currentNode of domSymbolTree.previousSiblingsIterator(node)) {
323
+ if (currentNode.nodeType !== NODE_TYPE.TEXT_NODE) {
324
+ break;
325
+ }
326
+
327
+ continuousExclusiveTextNodes.unshift(currentNode);
328
+ }
329
+ for (const currentNode of domSymbolTree.nextSiblingsIterator(node)) {
330
+ if (currentNode.nodeType !== NODE_TYPE.TEXT_NODE) {
331
+ break;
332
+ }
333
+
334
+ continuousExclusiveTextNodes.push(currentNode);
335
+ }
336
+
337
+ const data = continuousExclusiveTextNodes.reduce((d, n) => d + n._data, "");
338
+ node.replaceData(length, 0, data);
339
+
340
+ let currentNode = domSymbolTree.nextSibling(node);
341
+ while (currentNode && currentNode.nodeType === NODE_TYPE.TEXT_NODE) {
342
+ const currentNodeIndex = domSymbolTree.index(currentNode);
343
+
344
+ for (const range of node._liveRanges()) {
345
+ const { _start, _end } = range;
346
+
347
+ if (_start.node === currentNode) {
348
+ range._setLiveRangeStart(node, _start.offset + length);
349
+ }
350
+ if (_end.node === currentNode) {
351
+ range._setLiveRangeEnd(node, _end.offset + length);
352
+ }
353
+ }
354
+
355
+ for (const range of parentNode._liveRanges()) {
356
+ const { _start, _end } = range;
357
+
358
+ if (_start.node === parentNode && _start.offset === currentNodeIndex) {
359
+ range._setLiveRangeStart(node, length);
360
+ }
361
+ if (_end.node === parentNode && _end.offset === currentNodeIndex) {
362
+ range._setLiveRangeEnd(node, length);
363
+ }
364
+ }
365
+
366
+ length += nodeLength(currentNode);
367
+ currentNode = domSymbolTree.nextSibling(currentNode);
368
+ }
369
+
370
+ for (const continuousExclusiveTextNode of continuousExclusiveTextNodes) {
371
+ parentNode._remove(continuousExclusiveTextNode);
372
+ }
373
+ }
374
+ }
375
+
376
+ get parentElement() {
377
+ const parentNode = domSymbolTree.parent(this);
378
+ return parentNode !== null && parentNode.nodeType === NODE_TYPE.ELEMENT_NODE ? parentNode : null;
379
+ }
380
+
381
+ get baseURI() {
382
+ return this._ownerDocument.baseURLSerialized();
383
+ }
384
+
385
+ compareDocumentPosition(other) {
386
+ // Let node1 be other and node2 be the context object.
387
+ let node1 = other;
388
+ let node2 = this;
389
+
390
+ let attr1 = null;
391
+ let attr2;
392
+
393
+ if (node1.nodeType === NODE_TYPE.ATTRIBUTE_NODE) {
394
+ attr1 = node1;
395
+ node1 = attr1._element;
396
+ }
397
+
398
+ if (node2.nodeType === NODE_TYPE.ATTRIBUTE_NODE) {
399
+ attr2 = node2;
400
+ node2 = attr2._element;
401
+
402
+ if (attr1 !== null && node1 !== null && node2 === node1) {
403
+ for (const attr of node2._attributeList) {
404
+ if (nodeEquals(attr, attr1)) {
405
+ return NODE_DOCUMENT_POSITION.DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC |
406
+ NODE_DOCUMENT_POSITION.DOCUMENT_POSITION_PRECEDING;
407
+ }
408
+
409
+ if (nodeEquals(attr, attr2)) {
410
+ return NODE_DOCUMENT_POSITION.DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC |
411
+ NODE_DOCUMENT_POSITION.DOCUMENT_POSITION_FOLLOWING;
412
+ }
413
+ }
414
+ }
415
+ }
416
+
417
+ const result = domSymbolTree.compareTreePosition(node2, node1);
418
+
419
+ // “If other and reference are not in the same tree, return the result of adding DOCUMENT_POSITION_DISCONNECTED,
420
+ // DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC, and either DOCUMENT_POSITION_PRECEDING or
421
+ // DOCUMENT_POSITION_FOLLOWING, with the constraint that this is to be consistent, together.”
422
+ if (result === NODE_DOCUMENT_POSITION.DOCUMENT_POSITION_DISCONNECTED) {
423
+ // symbol-tree does not add these bits required by the spec:
424
+ return NODE_DOCUMENT_POSITION.DOCUMENT_POSITION_DISCONNECTED |
425
+ NODE_DOCUMENT_POSITION.DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC |
426
+ NODE_DOCUMENT_POSITION.DOCUMENT_POSITION_FOLLOWING;
427
+ }
428
+
429
+ return result;
430
+ }
431
+
432
+ lookupPrefix(namespace) {
433
+ if (namespace === null || namespace === "") {
434
+ return null;
435
+ }
436
+
437
+ switch (this.nodeType) {
438
+ case NODE_TYPE.ELEMENT_NODE: {
439
+ return locateNamespacePrefix(this, namespace);
440
+ }
441
+ case NODE_TYPE.DOCUMENT_NODE: {
442
+ return this.documentElement !== null ? locateNamespacePrefix(this.documentElement, namespace) : null;
443
+ }
444
+ case NODE_TYPE.DOCUMENT_TYPE_NODE:
445
+ case NODE_TYPE.DOCUMENT_FRAGMENT_NODE: {
446
+ return null;
447
+ }
448
+ case NODE_TYPE.ATTRIBUTE_NODE: {
449
+ return this._element !== null ? locateNamespacePrefix(this._element, namespace) : null;
450
+ }
451
+ default: {
452
+ return this.parentElement !== null ? locateNamespacePrefix(this.parentElement, namespace) : null;
453
+ }
454
+ }
455
+ }
456
+
457
+ lookupNamespaceURI(prefix) {
458
+ if (prefix === "") {
459
+ prefix = null;
460
+ }
461
+
462
+ return locateNamespace(this, prefix);
463
+ }
464
+
465
+ isDefaultNamespace(namespace) {
466
+ if (namespace === "") {
467
+ namespace = null;
468
+ }
469
+
470
+ const defaultNamespace = locateNamespace(this, null);
471
+ return defaultNamespace === namespace;
472
+ }
473
+
474
+ contains(other) {
475
+ return isInclusiveAncestor(this, other);
476
+ }
477
+
478
+ isEqualNode(node) {
479
+ if (node === null) {
480
+ return false;
481
+ }
482
+
483
+ // Fast-path, not in the spec
484
+ if (this === node) {
485
+ return true;
486
+ }
487
+
488
+ return nodeEquals(this, node);
489
+ }
490
+
491
+ isSameNode(node) {
492
+ if (this === node) {
493
+ return true;
494
+ }
495
+
496
+ return false;
497
+ }
498
+
499
+ cloneNode(deep) {
500
+ if (isShadowRoot(this)) {
501
+ throw DOMException.create(this._globalObject, ["ShadowRoot nodes are not clonable.", "NotSupportedError"]);
502
+ }
503
+
504
+ deep = Boolean(deep);
505
+
506
+ return clone(this, undefined, deep);
507
+ }
508
+
509
+ get nodeValue() {
510
+ switch (this.nodeType) {
511
+ case NODE_TYPE.ATTRIBUTE_NODE: {
512
+ return this._value;
513
+ }
514
+ case NODE_TYPE.TEXT_NODE:
515
+ case NODE_TYPE.CDATA_SECTION_NODE: // CDATASection is a subclass of Text
516
+ case NODE_TYPE.PROCESSING_INSTRUCTION_NODE:
517
+ case NODE_TYPE.COMMENT_NODE: {
518
+ return this._data;
519
+ }
520
+ default: {
521
+ return null;
522
+ }
523
+ }
524
+ }
525
+
526
+ set nodeValue(value) {
527
+ if (value === null) {
528
+ value = "";
529
+ }
530
+
531
+ switch (this.nodeType) {
532
+ case NODE_TYPE.ATTRIBUTE_NODE: {
533
+ setAnExistingAttributeValue(this, value);
534
+ break;
535
+ }
536
+ case NODE_TYPE.TEXT_NODE:
537
+ case NODE_TYPE.CDATA_SECTION_NODE: // CDATASection is a subclass of Text
538
+ case NODE_TYPE.PROCESSING_INSTRUCTION_NODE:
539
+ case NODE_TYPE.COMMENT_NODE: {
540
+ this.replaceData(0, this.length, value);
541
+ break;
542
+ }
543
+ }
544
+ }
545
+
546
+ // https://dom.spec.whatwg.org/#dom-node-textcontent
547
+ get textContent() {
548
+ switch (this.nodeType) {
549
+ case NODE_TYPE.DOCUMENT_FRAGMENT_NODE:
550
+ case NODE_TYPE.ELEMENT_NODE: {
551
+ let text = "";
552
+ for (const child of domSymbolTree.treeIterator(this)) {
553
+ if (child.nodeType === NODE_TYPE.TEXT_NODE || child.nodeType === NODE_TYPE.CDATA_SECTION_NODE) {
554
+ text += child.nodeValue;
555
+ }
556
+ }
557
+ return text;
558
+ }
559
+
560
+ case NODE_TYPE.ATTRIBUTE_NODE: {
561
+ return this._value;
562
+ }
563
+
564
+ case NODE_TYPE.TEXT_NODE:
565
+ case NODE_TYPE.CDATA_SECTION_NODE: // CDATASection is a subclass of Text
566
+ case NODE_TYPE.PROCESSING_INSTRUCTION_NODE:
567
+ case NODE_TYPE.COMMENT_NODE: {
568
+ return this._data;
569
+ }
570
+
571
+ default: {
572
+ return null;
573
+ }
574
+ }
575
+ }
576
+ set textContent(value) {
577
+ if (value === null) {
578
+ value = "";
579
+ }
580
+
581
+ switch (this.nodeType) {
582
+ case NODE_TYPE.DOCUMENT_FRAGMENT_NODE:
583
+ case NODE_TYPE.ELEMENT_NODE: {
584
+ // https://dom.spec.whatwg.org/#string-replace-all
585
+ let nodeImpl = null;
586
+
587
+ if (value !== "") {
588
+ nodeImpl = this._ownerDocument.createTextNode(value);
589
+ }
590
+
591
+ this._replaceAll(nodeImpl);
592
+ break;
593
+ }
594
+
595
+ case NODE_TYPE.ATTRIBUTE_NODE: {
596
+ setAnExistingAttributeValue(this, value);
597
+ break;
598
+ }
599
+
600
+ case NODE_TYPE.TEXT_NODE:
601
+ case NODE_TYPE.CDATA_SECTION_NODE: // CDATASection is a subclass of Text
602
+ case NODE_TYPE.PROCESSING_INSTRUCTION_NODE:
603
+ case NODE_TYPE.COMMENT_NODE: {
604
+ this.replaceData(0, this.length, value);
605
+ break;
606
+ }
607
+ }
608
+ }
609
+
610
+ // https://dom.spec.whatwg.org/#dom-node-insertbefore
611
+ insertBefore(nodeImpl, childImpl) {
612
+ return this._preInsert(nodeImpl, childImpl);
613
+ }
614
+
615
+ // https://dom.spec.whatwg.org/#dom-node-appendchild
616
+ appendChild(nodeImpl) {
617
+ return this._append(nodeImpl);
618
+ }
619
+
620
+ // https://dom.spec.whatwg.org/#dom-node-replacechild
621
+ replaceChild(nodeImpl, childImpl) {
622
+ return this._replace(nodeImpl, childImpl);
623
+ }
624
+
625
+ // https://dom.spec.whatwg.org/#dom-node-removechild
626
+ removeChild(oldChildImpl) {
627
+ return this._preRemove(oldChildImpl);
628
+ }
629
+
630
+ // https://dom.spec.whatwg.org/#concept-node-ensure-pre-insertion-validity
631
+ _preInsertValidity(nodeImpl, childImpl) {
632
+ const { nodeType } = nodeImpl;
633
+ const parentType = this.nodeType;
634
+
635
+ if (
636
+ parentType !== NODE_TYPE.DOCUMENT_NODE &&
637
+ parentType !== NODE_TYPE.DOCUMENT_FRAGMENT_NODE &&
638
+ parentType !== NODE_TYPE.ELEMENT_NODE
639
+ ) {
640
+ throw DOMException.create(this._globalObject, [
641
+ `Node can't be inserted in a ${this.nodeName} parent.`,
642
+ "HierarchyRequestError"
643
+ ]);
644
+ }
645
+
646
+ if (isHostInclusiveAncestor(nodeImpl, this)) {
647
+ throw DOMException.create(this._globalObject, [
648
+ "The operation would yield an incorrect node tree.",
649
+ "HierarchyRequestError"
650
+ ]);
651
+ }
652
+
653
+ if (childImpl && domSymbolTree.parent(childImpl) !== this) {
654
+ throw DOMException.create(this._globalObject, [
655
+ "The child can not be found in the parent.",
656
+ "NotFoundError"
657
+ ]);
658
+ }
659
+
660
+ if (
661
+ nodeType !== NODE_TYPE.DOCUMENT_FRAGMENT_NODE &&
662
+ nodeType !== NODE_TYPE.DOCUMENT_TYPE_NODE &&
663
+ nodeType !== NODE_TYPE.ELEMENT_NODE &&
664
+ nodeType !== NODE_TYPE.TEXT_NODE &&
665
+ nodeType !== NODE_TYPE.CDATA_SECTION_NODE && // CData section extends from Text
666
+ nodeType !== NODE_TYPE.PROCESSING_INSTRUCTION_NODE &&
667
+ nodeType !== NODE_TYPE.COMMENT_NODE
668
+ ) {
669
+ throw DOMException.create(this._globalObject, [
670
+ `${nodeImpl.nodeName} node can't be inserted in parent node.`,
671
+ "HierarchyRequestError"
672
+ ]);
673
+ }
674
+
675
+ if (
676
+ (nodeType === NODE_TYPE.TEXT_NODE && parentType === NODE_TYPE.DOCUMENT_NODE) ||
677
+ (nodeType === NODE_TYPE.DOCUMENT_TYPE_NODE && parentType !== NODE_TYPE.DOCUMENT_NODE)
678
+ ) {
679
+ throw DOMException.create(this._globalObject, [
680
+ `${nodeImpl.nodeName} node can't be inserted in ${this.nodeName} parent.`,
681
+ "HierarchyRequestError"
682
+ ]);
683
+ }
684
+
685
+ if (parentType === NODE_TYPE.DOCUMENT_NODE) {
686
+ const nodeChildren = domSymbolTree.childrenToArray(nodeImpl);
687
+ const parentChildren = domSymbolTree.childrenToArray(this);
688
+
689
+ switch (nodeType) {
690
+ case NODE_TYPE.DOCUMENT_FRAGMENT_NODE: {
691
+ const nodeChildrenElements = nodeChildren.filter(child => child.nodeType === NODE_TYPE.ELEMENT_NODE);
692
+ if (nodeChildrenElements.length > 1) {
693
+ throw DOMException.create(this._globalObject, [
694
+ `Invalid insertion of ${nodeImpl.nodeName} node in ${this.nodeName} node.`,
695
+ "HierarchyRequestError"
696
+ ]);
697
+ }
698
+
699
+ const hasNodeTextChildren = nodeChildren.some(child => child.nodeType === NODE_TYPE.TEXT_NODE);
700
+ if (hasNodeTextChildren) {
701
+ throw DOMException.create(this._globalObject, [
702
+ `Invalid insertion of ${nodeImpl.nodeName} node in ${this.nodeName} node.`,
703
+ "HierarchyRequestError"
704
+ ]);
705
+ }
706
+
707
+ if (
708
+ nodeChildrenElements.length === 1 &&
709
+ (
710
+ parentChildren.some(child => child.nodeType === NODE_TYPE.ELEMENT_NODE) ||
711
+ (childImpl && childImpl.nodeType === NODE_TYPE.DOCUMENT_TYPE_NODE) ||
712
+ (
713
+ childImpl &&
714
+ domSymbolTree.nextSibling(childImpl) &&
715
+ domSymbolTree.nextSibling(childImpl).nodeType === NODE_TYPE.DOCUMENT_TYPE_NODE
716
+ )
717
+ )
718
+ ) {
719
+ throw DOMException.create(this._globalObject, [
720
+ `Invalid insertion of ${nodeImpl.nodeName} node in ${this.nodeName} node.`,
721
+ "HierarchyRequestError"
722
+ ]);
723
+ }
724
+ break;
725
+ }
726
+
727
+ case NODE_TYPE.ELEMENT_NODE:
728
+ if (
729
+ parentChildren.some(child => child.nodeType === NODE_TYPE.ELEMENT_NODE) ||
730
+ (childImpl && childImpl.nodeType === NODE_TYPE.DOCUMENT_TYPE_NODE) ||
731
+ (
732
+ childImpl &&
733
+ domSymbolTree.nextSibling(childImpl) &&
734
+ domSymbolTree.nextSibling(childImpl).nodeType === NODE_TYPE.DOCUMENT_TYPE_NODE
735
+ )
736
+ ) {
737
+ throw DOMException.create(this._globalObject, [
738
+ `Invalid insertion of ${nodeImpl.nodeName} node in ${this.nodeName} node.`,
739
+ "HierarchyRequestError"
740
+ ]);
741
+ }
742
+ break;
743
+
744
+ case NODE_TYPE.DOCUMENT_TYPE_NODE:
745
+ if (
746
+ parentChildren.some(child => child.nodeType === NODE_TYPE.DOCUMENT_TYPE_NODE) ||
747
+ (
748
+ childImpl &&
749
+ domSymbolTree.previousSibling(childImpl) &&
750
+ domSymbolTree.previousSibling(childImpl).nodeType === NODE_TYPE.ELEMENT_NODE
751
+ ) ||
752
+ (!childImpl && parentChildren.some(child => child.nodeType === NODE_TYPE.ELEMENT_NODE))
753
+ ) {
754
+ throw DOMException.create(this._globalObject, [
755
+ `Invalid insertion of ${nodeImpl.nodeName} node in ${this.nodeName} node.`,
756
+ "HierarchyRequestError"
757
+ ]);
758
+ }
759
+ break;
760
+ }
761
+ }
762
+ }
763
+
764
+ // https://dom.spec.whatwg.org/#concept-node-pre-insert
765
+ _preInsert(nodeImpl, childImpl) {
766
+ this._preInsertValidity(nodeImpl, childImpl);
767
+
768
+ let referenceChildImpl = childImpl;
769
+ if (referenceChildImpl === nodeImpl) {
770
+ referenceChildImpl = domSymbolTree.nextSibling(nodeImpl);
771
+ }
772
+
773
+ this._ownerDocument._adoptNode(nodeImpl);
774
+
775
+ this._insert(nodeImpl, referenceChildImpl);
776
+
777
+ return nodeImpl;
778
+ }
779
+
780
+ // https://dom.spec.whatwg.org/#concept-node-insert
781
+ _insert(nodeImpl, childImpl, suppressObservers) {
782
+ const count = nodeImpl.nodeType === NODE_TYPE.DOCUMENT_FRAGMENT_NODE ?
783
+ domSymbolTree.childrenCount(nodeImpl) :
784
+ 1;
785
+
786
+ if (childImpl) {
787
+ const childIndex = domSymbolTree.index(childImpl);
788
+
789
+ for (const range of this._liveRanges()) {
790
+ const { _start, _end } = range;
791
+
792
+ if (_start.offset > childIndex) {
793
+ range._setLiveRangeStart(this, _start.offset + count);
794
+ }
795
+
796
+ if (_end.offset > childIndex) {
797
+ range._setLiveRangeEnd(this, _end.offset + count);
798
+ }
799
+ }
800
+ }
801
+
802
+ const nodesImpl = nodeImpl.nodeType === NODE_TYPE.DOCUMENT_FRAGMENT_NODE ?
803
+ domSymbolTree.childrenToArray(nodeImpl) :
804
+ [nodeImpl];
805
+
806
+ if (nodeImpl.nodeType === NODE_TYPE.DOCUMENT_FRAGMENT_NODE) {
807
+ let grandChildImpl;
808
+ while ((grandChildImpl = domSymbolTree.firstChild(nodeImpl))) {
809
+ nodeImpl._remove(grandChildImpl, true);
810
+ }
811
+ }
812
+
813
+ if (nodeImpl.nodeType === NODE_TYPE.DOCUMENT_FRAGMENT_NODE) {
814
+ queueTreeMutationRecord(nodeImpl, [], nodesImpl, null, null);
815
+ }
816
+
817
+ const previousChildImpl = childImpl ?
818
+ domSymbolTree.previousSibling(childImpl) :
819
+ domSymbolTree.lastChild(this);
820
+
821
+ let isConnected;
822
+
823
+ for (const node of nodesImpl) {
824
+ if (!childImpl) {
825
+ domSymbolTree.appendChild(this, node);
826
+ } else {
827
+ domSymbolTree.insertBefore(childImpl, node);
828
+ }
829
+
830
+ if (
831
+ (this.nodeType === NODE_TYPE.ELEMENT_NODE && this._shadowRoot !== null) &&
832
+ (node.nodeType === NODE_TYPE.ELEMENT_NODE || node.nodeType === NODE_TYPE.TEXT_NODE)
833
+ ) {
834
+ assignSlot(node);
835
+ }
836
+
837
+ this._modified();
838
+
839
+ if (node.nodeType === NODE_TYPE.TEXT_NODE ||
840
+ node.nodeType === NODE_TYPE.CDATA_SECTION_NODE) {
841
+ this._childTextContentChangeSteps();
842
+ }
843
+
844
+ if (isSlot(this) && this._assignedNodes.length === 0 && isShadowRoot(nodeRoot(this))) {
845
+ signalSlotChange(this);
846
+ }
847
+
848
+ const root = nodeRoot(node);
849
+ if (isShadowRoot(root)) {
850
+ assignSlotableForTree(root);
851
+ }
852
+
853
+ if (this._attached && nodeImpl._attach) {
854
+ node._attach();
855
+ }
856
+
857
+ this._descendantAdded(this, node);
858
+
859
+ if (isConnected === undefined) {
860
+ isConnected = node.isConnected;
861
+ }
862
+
863
+ if (isConnected) {
864
+ for (const inclusiveDescendant of shadowIncludingInclusiveDescendantsIterator(node)) {
865
+ if (inclusiveDescendant._ceState === "custom") {
866
+ enqueueCECallbackReaction(inclusiveDescendant, "connectedCallback", []);
867
+ } else {
868
+ tryUpgradeElement(inclusiveDescendant);
869
+ }
870
+ }
871
+ }
872
+ }
873
+
874
+ if (!suppressObservers) {
875
+ queueTreeMutationRecord(this, nodesImpl, [], previousChildImpl, childImpl);
876
+ }
877
+ }
878
+
879
+ // https://dom.spec.whatwg.org/#concept-node-append
880
+ _append(nodeImpl) {
881
+ return this._preInsert(nodeImpl, null);
882
+ }
883
+
884
+ // https://dom.spec.whatwg.org/#concept-node-replace
885
+ _replace(nodeImpl, childImpl) {
886
+ const { nodeType, nodeName } = nodeImpl;
887
+ const { nodeType: parentType, nodeName: parentName } = this;
888
+
889
+ // Note: This section differs from the pre-insert validation algorithm.
890
+ if (
891
+ parentType !== NODE_TYPE.DOCUMENT_NODE &&
892
+ parentType !== NODE_TYPE.DOCUMENT_FRAGMENT_NODE &&
893
+ parentType !== NODE_TYPE.ELEMENT_NODE
894
+ ) {
895
+ throw DOMException.create(this._globalObject, [
896
+ `Node can't be inserted in a ${parentName} parent.`,
897
+ "HierarchyRequestError"
898
+ ]);
899
+ }
900
+
901
+ if (isHostInclusiveAncestor(nodeImpl, this)) {
902
+ throw DOMException.create(this._globalObject, [
903
+ "The operation would yield an incorrect node tree.",
904
+ "HierarchyRequestError"
905
+ ]);
906
+ }
907
+
908
+ if (childImpl && domSymbolTree.parent(childImpl) !== this) {
909
+ throw DOMException.create(this._globalObject, [
910
+ "The child can not be found in the parent.",
911
+ "NotFoundError"
912
+ ]);
913
+ }
914
+
915
+ if (
916
+ nodeType !== NODE_TYPE.DOCUMENT_FRAGMENT_NODE &&
917
+ nodeType !== NODE_TYPE.DOCUMENT_TYPE_NODE &&
918
+ nodeType !== NODE_TYPE.ELEMENT_NODE &&
919
+ nodeType !== NODE_TYPE.TEXT_NODE &&
920
+ nodeType !== NODE_TYPE.CDATA_SECTION_NODE && // CData section extends from Text
921
+ nodeType !== NODE_TYPE.PROCESSING_INSTRUCTION_NODE &&
922
+ nodeType !== NODE_TYPE.COMMENT_NODE
923
+ ) {
924
+ throw DOMException.create(this._globalObject, [
925
+ `${nodeName} node can't be inserted in parent node.`,
926
+ "HierarchyRequestError"
927
+ ]);
928
+ }
929
+
930
+ if (
931
+ (nodeType === NODE_TYPE.TEXT_NODE && parentType === NODE_TYPE.DOCUMENT_NODE) ||
932
+ (nodeType === NODE_TYPE.DOCUMENT_TYPE_NODE && parentType !== NODE_TYPE.DOCUMENT_NODE)
933
+ ) {
934
+ throw DOMException.create(this._globalObject, [
935
+ `${nodeName} node can't be inserted in ${parentName} parent.`,
936
+ "HierarchyRequestError"
937
+ ]);
938
+ }
939
+
940
+ if (parentType === NODE_TYPE.DOCUMENT_NODE) {
941
+ const nodeChildren = domSymbolTree.childrenToArray(nodeImpl);
942
+ const parentChildren = domSymbolTree.childrenToArray(this);
943
+
944
+ switch (nodeType) {
945
+ case NODE_TYPE.DOCUMENT_FRAGMENT_NODE: {
946
+ const nodeChildrenElements = nodeChildren.filter(child => child.nodeType === NODE_TYPE.ELEMENT_NODE);
947
+ if (nodeChildrenElements.length > 1) {
948
+ throw DOMException.create(this._globalObject, [
949
+ `Invalid insertion of ${nodeName} node in ${parentName} node.`,
950
+ "HierarchyRequestError"
951
+ ]);
952
+ }
953
+
954
+ const hasNodeTextChildren = nodeChildren.some(child => child.nodeType === NODE_TYPE.TEXT_NODE);
955
+ if (hasNodeTextChildren) {
956
+ throw DOMException.create(this._globalObject, [
957
+ `Invalid insertion of ${nodeName} node in ${parentName} node.`,
958
+ "HierarchyRequestError"
959
+ ]);
960
+ }
961
+
962
+
963
+ const parentChildElements = parentChildren.filter(child => child.nodeType === NODE_TYPE.ELEMENT_NODE);
964
+ if (
965
+ nodeChildrenElements.length === 1 &&
966
+ (
967
+ (parentChildElements.length === 1 && parentChildElements[0] !== childImpl) ||
968
+ (
969
+ childImpl &&
970
+ domSymbolTree.nextSibling(childImpl) &&
971
+ domSymbolTree.nextSibling(childImpl).nodeType === NODE_TYPE.DOCUMENT_TYPE_NODE
972
+ )
973
+ )
974
+ ) {
975
+ throw DOMException.create(this._globalObject, [
976
+ `Invalid insertion of ${nodeName} node in ${parentName} node.`,
977
+ "HierarchyRequestError"
978
+ ]);
979
+ }
980
+ break;
981
+ }
982
+
983
+ case NODE_TYPE.ELEMENT_NODE:
984
+ if (
985
+ parentChildren.some(child => child.nodeType === NODE_TYPE.ELEMENT_NODE && child !== childImpl) ||
986
+ (
987
+ childImpl &&
988
+ domSymbolTree.nextSibling(childImpl) &&
989
+ domSymbolTree.nextSibling(childImpl).nodeType === NODE_TYPE.DOCUMENT_TYPE_NODE
990
+ )
991
+ ) {
992
+ throw DOMException.create(this._globalObject, [
993
+ `Invalid insertion of ${nodeName} node in ${parentName} node.`,
994
+ "HierarchyRequestError"
995
+ ]);
996
+ }
997
+ break;
998
+
999
+ case NODE_TYPE.DOCUMENT_TYPE_NODE:
1000
+ if (
1001
+ parentChildren.some(child => child.nodeType === NODE_TYPE.DOCUMENT_TYPE_NODE && child !== childImpl) ||
1002
+ (
1003
+ childImpl &&
1004
+ domSymbolTree.previousSibling(childImpl) &&
1005
+ domSymbolTree.previousSibling(childImpl).nodeType === NODE_TYPE.ELEMENT_NODE
1006
+ )
1007
+ ) {
1008
+ throw DOMException.create(this._globalObject, [
1009
+ `Invalid insertion of ${nodeName} node in ${parentName} node.`,
1010
+ "HierarchyRequestError"
1011
+ ]);
1012
+ }
1013
+ break;
1014
+ }
1015
+ }
1016
+
1017
+ let referenceChildImpl = domSymbolTree.nextSibling(childImpl);
1018
+ if (referenceChildImpl === nodeImpl) {
1019
+ referenceChildImpl = domSymbolTree.nextSibling(nodeImpl);
1020
+ }
1021
+
1022
+ const previousSiblingImpl = domSymbolTree.previousSibling(childImpl);
1023
+
1024
+ this._ownerDocument._adoptNode(nodeImpl);
1025
+
1026
+ let removedNodesImpl = [];
1027
+
1028
+ if (domSymbolTree.parent(childImpl)) {
1029
+ removedNodesImpl = [childImpl];
1030
+ this._remove(childImpl, true);
1031
+ }
1032
+
1033
+ const nodesImpl = nodeImpl.nodeType === NODE_TYPE.DOCUMENT_FRAGMENT_NODE ?
1034
+ domSymbolTree.childrenToArray(nodeImpl) :
1035
+ [nodeImpl];
1036
+
1037
+ this._insert(nodeImpl, referenceChildImpl, true);
1038
+
1039
+ queueTreeMutationRecord(this, nodesImpl, removedNodesImpl, previousSiblingImpl, referenceChildImpl);
1040
+
1041
+ return childImpl;
1042
+ }
1043
+
1044
+ // https://dom.spec.whatwg.org/#concept-node-replace-all
1045
+ _replaceAll(nodeImpl) {
1046
+ if (nodeImpl !== null) {
1047
+ this._ownerDocument._adoptNode(nodeImpl);
1048
+ }
1049
+
1050
+ const removedNodesImpl = domSymbolTree.childrenToArray(this);
1051
+
1052
+ let addedNodesImpl;
1053
+ if (nodeImpl === null) {
1054
+ addedNodesImpl = [];
1055
+ } else if (nodeImpl.nodeType === NODE_TYPE.DOCUMENT_FRAGMENT_NODE) {
1056
+ addedNodesImpl = domSymbolTree.childrenToArray(nodeImpl);
1057
+ } else {
1058
+ addedNodesImpl = [nodeImpl];
1059
+ }
1060
+
1061
+ for (const childImpl of domSymbolTree.childrenIterator(this)) {
1062
+ this._remove(childImpl, true);
1063
+ }
1064
+
1065
+ if (nodeImpl !== null) {
1066
+ this._insert(nodeImpl, null, true);
1067
+ }
1068
+
1069
+ if (addedNodesImpl.length > 0 || removedNodesImpl.length > 0) {
1070
+ queueTreeMutationRecord(this, addedNodesImpl, removedNodesImpl, null, null);
1071
+ }
1072
+ }
1073
+
1074
+ // https://dom.spec.whatwg.org/#concept-node-pre-remove
1075
+ _preRemove(childImpl) {
1076
+ if (domSymbolTree.parent(childImpl) !== this) {
1077
+ throw DOMException.create(this._globalObject, [
1078
+ "The node to be removed is not a child of this node.",
1079
+ "NotFoundError"
1080
+ ]);
1081
+ }
1082
+
1083
+ this._remove(childImpl);
1084
+
1085
+ return childImpl;
1086
+ }
1087
+
1088
+ // https://dom.spec.whatwg.org/#concept-node-remove
1089
+ _remove(nodeImpl, suppressObservers) {
1090
+ const index = domSymbolTree.index(nodeImpl);
1091
+
1092
+ for (const descendant of domSymbolTree.treeIterator(nodeImpl)) {
1093
+ for (const range of descendant._liveRanges()) {
1094
+ const { _start, _end } = range;
1095
+
1096
+ if (_start.node === descendant) {
1097
+ range._setLiveRangeStart(this, index);
1098
+ }
1099
+
1100
+ if (_end.node === descendant) {
1101
+ range._setLiveRangeEnd(this, index);
1102
+ }
1103
+ }
1104
+ }
1105
+
1106
+ for (const range of this._liveRanges()) {
1107
+ const { _start, _end } = range;
1108
+
1109
+ if (_start.node === this && _start.offset > index) {
1110
+ range._setLiveRangeStart(this, _start.offset - 1);
1111
+ }
1112
+
1113
+ if (_end.node === this && _end.offset > index) {
1114
+ range._setLiveRangeEnd(this, _end.offset - 1);
1115
+ }
1116
+ }
1117
+
1118
+ if (this._ownerDocument) {
1119
+ this._ownerDocument._runPreRemovingSteps(nodeImpl);
1120
+ }
1121
+
1122
+ const oldPreviousSiblingImpl = domSymbolTree.previousSibling(nodeImpl);
1123
+ const oldNextSiblingImpl = domSymbolTree.nextSibling(nodeImpl);
1124
+
1125
+ domSymbolTree.remove(nodeImpl);
1126
+ nodeImpl._cachedRoot = null;
1127
+
1128
+ if (nodeImpl._assignedSlot) {
1129
+ assignSlotable(nodeImpl._assignedSlot);
1130
+ }
1131
+
1132
+ if (isSlot(this) && this._assignedNodes.length === 0 && isShadowRoot(nodeRoot(this))) {
1133
+ signalSlotChange(this);
1134
+ }
1135
+
1136
+ let hasSlotDescendant = isSlot(nodeImpl);
1137
+ if (!hasSlotDescendant) {
1138
+ for (const child of domSymbolTree.treeIterator(nodeImpl)) {
1139
+ if (isSlot(child)) {
1140
+ hasSlotDescendant = true;
1141
+ break;
1142
+ }
1143
+ }
1144
+ }
1145
+
1146
+ if (hasSlotDescendant) {
1147
+ assignSlotableForTree(nodeRoot(this));
1148
+ assignSlotableForTree(nodeImpl);
1149
+ }
1150
+
1151
+ this._modified();
1152
+ if (nodeImpl._attached) {
1153
+ nodeImpl._detach();
1154
+ }
1155
+ this._descendantRemoved(this, nodeImpl);
1156
+
1157
+ if (this.isConnected) {
1158
+ if (nodeImpl._ceState === "custom") {
1159
+ enqueueCECallbackReaction(nodeImpl, "disconnectedCallback", []);
1160
+ }
1161
+
1162
+ for (const descendantImpl of shadowIncludingDescendantsIterator(nodeImpl)) {
1163
+ descendantImpl._cachedRoot = null;
1164
+ if (descendantImpl._ceState === "custom") {
1165
+ enqueueCECallbackReaction(descendantImpl, "disconnectedCallback", []);
1166
+ }
1167
+ }
1168
+ }
1169
+
1170
+ if (!suppressObservers) {
1171
+ queueTreeMutationRecord(this, [], [nodeImpl], oldPreviousSiblingImpl, oldNextSiblingImpl);
1172
+ }
1173
+
1174
+ if (nodeImpl.nodeType === NODE_TYPE.TEXT_NODE) {
1175
+ this._childTextContentChangeSteps();
1176
+ }
1177
+ }
1178
+ }
1179
+
1180
+ module.exports = {
1181
+ implementation: NodeImpl
1182
+ };
node_modules/jsdom/lib/jsdom/living/nodes/NodeList-impl.js ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "use strict";
2
+
3
+ const idlUtils = require("../../../generated/idl/utils.js");
4
+
5
+ exports.implementation = class NodeListImpl {
6
+ constructor(globalObject, args, privateData) {
7
+ if (privateData.nodes) {
8
+ this._list = [...privateData.nodes];
9
+ this._isLive = false;
10
+ } else {
11
+ this._list = [];
12
+ this._isLive = true;
13
+ this._version = -1;
14
+ this._element = privateData.element;
15
+ this._query = privateData.query;
16
+ this._update();
17
+ }
18
+ }
19
+ get length() {
20
+ this._update();
21
+ return this._list.length;
22
+ }
23
+ item(index) {
24
+ this._update();
25
+ return this._list[index] || null;
26
+ }
27
+ _update() {
28
+ if (this._isLive) {
29
+ if (this._version < this._element._version) {
30
+ const snapshot = this._query();
31
+ for (let i = 0; i < snapshot.length; i++) {
32
+ this._list[i] = snapshot[i];
33
+ }
34
+ this._list.length = snapshot.length;
35
+ this._version = this._element._version;
36
+ }
37
+ }
38
+ }
39
+ get [idlUtils.supportedPropertyIndices]() {
40
+ this._update();
41
+ return this._list.keys();
42
+ }
43
+ };
node_modules/jsdom/lib/jsdom/living/nodes/NonDocumentTypeChildNode-impl.js ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "use strict";
2
+
3
+ const { domSymbolTree } = require("../helpers/internal-constants");
4
+ const NODE_TYPE = require("../node-type");
5
+
6
+ class NonDocumentTypeChildNodeImpl {
7
+ get nextElementSibling() {
8
+ for (const sibling of domSymbolTree.nextSiblingsIterator(this)) {
9
+ if (sibling.nodeType === NODE_TYPE.ELEMENT_NODE) {
10
+ return sibling;
11
+ }
12
+ }
13
+ return null;
14
+ }
15
+
16
+ get previousElementSibling() {
17
+ for (const sibling of domSymbolTree.previousSiblingsIterator(this)) {
18
+ if (sibling.nodeType === NODE_TYPE.ELEMENT_NODE) {
19
+ return sibling;
20
+ }
21
+ }
22
+ return null;
23
+ }
24
+ }
25
+
26
+ module.exports = {
27
+ implementation: NonDocumentTypeChildNodeImpl
28
+ };
node_modules/jsdom/lib/jsdom/living/nodes/NonElementParentNode-impl.js ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "use strict";
2
+
3
+ // https://dom.spec.whatwg.org/#interface-nonelementparentnode
4
+ // getElementById is implemented separately inside Document and DocumentFragment.
5
+ class NonElementParentNodeImpl {
6
+
7
+ }
8
+
9
+ module.exports = {
10
+ implementation: NonElementParentNodeImpl
11
+ };
node_modules/jsdom/lib/jsdom/living/nodes/ParentNode-impl.js ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "use strict";
2
+
3
+ const NodeList = require("../../../generated/idl/NodeList");
4
+ const HTMLCollection = require("../../../generated/idl/HTMLCollection");
5
+ const { domSymbolTree } = require("../helpers/internal-constants");
6
+ const NODE_TYPE = require("../node-type");
7
+ const { convertNodesIntoNode } = require("../node");
8
+
9
+ class ParentNodeImpl {
10
+ get children() {
11
+ if (!this._childrenList) {
12
+ this._childrenList = HTMLCollection.createImpl(this._globalObject, [], {
13
+ element: this,
14
+ query: () => domSymbolTree.childrenToArray(this, {
15
+ filter: node => node.nodeType === NODE_TYPE.ELEMENT_NODE
16
+ })
17
+ });
18
+ } else {
19
+ this._childrenList._update();
20
+ }
21
+ return this._childrenList;
22
+ }
23
+
24
+ get firstElementChild() {
25
+ for (const child of domSymbolTree.childrenIterator(this)) {
26
+ if (child.nodeType === NODE_TYPE.ELEMENT_NODE) {
27
+ return child;
28
+ }
29
+ }
30
+
31
+ return null;
32
+ }
33
+
34
+ get lastElementChild() {
35
+ for (const child of domSymbolTree.childrenIterator(this, { reverse: true })) {
36
+ if (child.nodeType === NODE_TYPE.ELEMENT_NODE) {
37
+ return child;
38
+ }
39
+ }
40
+
41
+ return null;
42
+ }
43
+
44
+ get childElementCount() {
45
+ return this.children.length;
46
+ }
47
+
48
+ prepend(...nodes) {
49
+ this._preInsert(convertNodesIntoNode(this._ownerDocument, nodes), this.firstChild);
50
+ }
51
+
52
+ append(...nodes) {
53
+ this._append(convertNodesIntoNode(this._ownerDocument, nodes));
54
+ }
55
+
56
+ replaceChildren(...nodes) {
57
+ const node = convertNodesIntoNode(this._ownerDocument, nodes);
58
+ this._preInsertValidity(node, null);
59
+ this._replaceAll(node);
60
+ }
61
+
62
+ querySelector(selectors) {
63
+ if (shouldAlwaysSelectNothing(this)) {
64
+ return null;
65
+ }
66
+ const domSelector = this._ownerDocument._getDOMSelector();
67
+ return domSelector.querySelector(selectors, this);
68
+ }
69
+
70
+ // WARNING FOR INTERNAL USERS:
71
+ // This returns a NodeList impl, not a NodeList wrapper. NodeList impls are not iterable and do not have indexed
72
+ // properties. To iterate over them, use `for (let i = 0; i < nodeListImpl.length; ++i) { nodeListImpl.item(i) }`.
73
+ querySelectorAll(selectors) {
74
+ if (shouldAlwaysSelectNothing(this)) {
75
+ return NodeList.createImpl(this._globalObject, [], { nodes: [] });
76
+ }
77
+ const domSelector = this._ownerDocument._getDOMSelector();
78
+ const nodes = domSelector.querySelectorAll(selectors, this);
79
+ return NodeList.createImpl(this._globalObject, [], { nodes });
80
+ }
81
+ }
82
+
83
+ function shouldAlwaysSelectNothing(elImpl) {
84
+ // This is true during initialization.
85
+ return elImpl === elImpl._ownerDocument && !elImpl.documentElement;
86
+ }
87
+
88
+ module.exports = {
89
+ implementation: ParentNodeImpl
90
+ };
node_modules/jsdom/lib/jsdom/living/nodes/ProcessingInstruction-impl.js ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "use strict";
2
+
3
+ const CharacterDataImpl = require("./CharacterData-impl").implementation;
4
+
5
+ const NODE_TYPE = require("../node-type");
6
+
7
+ class ProcessingInstructionImpl extends CharacterDataImpl {
8
+ constructor(globalObject, args, privateData) {
9
+ super(globalObject, args, privateData);
10
+
11
+ this.nodeType = NODE_TYPE.PROCESSING_INSTRUCTION_NODE;
12
+ this._target = privateData.target;
13
+ }
14
+
15
+ get target() {
16
+ return this._target;
17
+ }
18
+ }
19
+
20
+ module.exports = {
21
+ implementation: ProcessingInstructionImpl
22
+ };
node_modules/jsdom/lib/jsdom/living/nodes/RadioNodeList-impl.js ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "use strict";
2
+
3
+ const NodeListImpl = require("./NodeList-impl").implementation;
4
+
5
+ class RadioNodeListImpl extends NodeListImpl {
6
+ // https://html.spec.whatwg.org/multipage/common-dom-interfaces.html#dom-radionodelist-value
7
+ // Note in general the spec says to manipulate/consult checkedness, but we use `checked` instead
8
+ // because the spec isn't very good here: https://github.com/whatwg/html/issues/7612.
9
+
10
+ get value() {
11
+ this._update();
12
+
13
+ const element = this._list.find(e => e._localName === "input" && e.type === "radio" && e.checked);
14
+ if (element === undefined) {
15
+ return "";
16
+ }
17
+
18
+ if (!element.hasAttributeNS(null, "value")) {
19
+ return "on";
20
+ }
21
+
22
+ return element.getAttributeNS(null, "value");
23
+ }
24
+
25
+ set value(value) {
26
+ let element;
27
+ if (value === "on") {
28
+ element = this._list.find(
29
+ e => e._localName === "input" &&
30
+ e.type === "radio" &&
31
+ (!e.hasAttributeNS(null, "value") || e.getAttributeNS(null, "value") === value)
32
+ );
33
+ } else {
34
+ element = this._list.find(
35
+ e => e._localName === "input" &&
36
+ e.type === "radio" &&
37
+ (e.hasAttributeNS(null, "value") && e.getAttributeNS(null, "value") === value)
38
+ );
39
+ }
40
+
41
+ if (element) {
42
+ element.checked = true;
43
+ }
44
+ }
45
+ }
46
+
47
+ module.exports = {
48
+ implementation: RadioNodeListImpl
49
+ };
node_modules/jsdom/lib/jsdom/living/nodes/SVGDefsElement-impl.js ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ "use strict";
2
+
3
+ const SVGGraphicsElementImpl = require("./SVGGraphicsElement-impl").implementation;
4
+
5
+ class SVGDefsElementImpl extends SVGGraphicsElementImpl {}
6
+
7
+ module.exports = {
8
+ implementation: SVGDefsElementImpl
9
+ };
node_modules/jsdom/lib/jsdom/living/nodes/SVGDescElement-impl.js ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ "use strict";
2
+
3
+ const SVGElementImpl = require("./SVGElement-impl").implementation;
4
+
5
+ class SVGDescElementImpl extends SVGElementImpl {}
6
+
7
+ module.exports = {
8
+ implementation: SVGDescElementImpl
9
+ };
node_modules/jsdom/lib/jsdom/living/nodes/SVGElement-impl.js ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "use strict";
2
+
3
+ const { domSymbolTree } = require("../helpers/internal-constants");
4
+ const { SVG_NS } = require("../helpers/namespaces");
5
+ const { mixin } = require("../../utils");
6
+ const ElementImpl = require("./Element-impl").implementation;
7
+ const ElementCSSInlineStyleImpl = require("../css/ElementCSSInlineStyle-impl").implementation;
8
+ const GlobalEventHandlersImpl = require("./GlobalEventHandlers-impl").implementation;
9
+ const HTMLOrSVGElementImpl = require("./HTMLOrSVGElement-impl").implementation;
10
+
11
+ class SVGElementImpl extends ElementImpl {
12
+ constructor(globalObject, args, privateData) {
13
+ super(globalObject, args, privateData);
14
+ this._initHTMLOrSVGElement();
15
+ this._initElementCSSInlineStyle();
16
+ this._initGlobalEvents();
17
+ }
18
+
19
+ // Keep in sync with HTMLElement. https://github.com/jsdom/jsdom/issues/2599
20
+ _attrModified(name, value, oldValue) {
21
+ if (name === "style" && value !== oldValue && !this._settingCssText) {
22
+ this._settingCssText = true;
23
+ this.style.cssText = value;
24
+ this._settingCssText = false;
25
+ } else if (name.startsWith("on")) {
26
+ this._globalEventChanged(name.substring(2));
27
+ }
28
+
29
+ super._attrModified(name, value, oldValue);
30
+ }
31
+
32
+ get ownerSVGElement() {
33
+ let e = domSymbolTree.parent(this);
34
+ while (e && e.namespaceURI === SVG_NS) {
35
+ if (e.localName === "svg") {
36
+ return e;
37
+ }
38
+ e = domSymbolTree.parent(e);
39
+ }
40
+
41
+ return null;
42
+ }
43
+
44
+ get viewportElement() {
45
+ // Get the nearest ancestor that establishes the viewport.
46
+ // https://svgwg.org/svg2-draft/coords.html#EstablishingANewSVGViewport
47
+ let e = domSymbolTree.parent(this);
48
+ while (e && e.namespaceURI === SVG_NS) {
49
+ if (e.localName === "svg" || e.localName === "symbol") {
50
+ return e;
51
+ }
52
+ e = domSymbolTree.parent(e);
53
+ }
54
+ return null;
55
+ }
56
+ }
57
+
58
+ SVGElementImpl.attributeRegistry = new Map();
59
+
60
+ mixin(SVGElementImpl.prototype, ElementCSSInlineStyleImpl.prototype);
61
+ mixin(SVGElementImpl.prototype, GlobalEventHandlersImpl.prototype);
62
+ mixin(SVGElementImpl.prototype, HTMLOrSVGElementImpl.prototype);
63
+
64
+ exports.implementation = SVGElementImpl;
node_modules/jsdom/lib/jsdom/living/nodes/SVGGElement-impl.js ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ "use strict";
2
+
3
+ const SVGGraphicsElementImpl = require("./SVGGraphicsElement-impl").implementation;
4
+
5
+ class SVGGElementImpl extends SVGGraphicsElementImpl {}
6
+
7
+ module.exports = {
8
+ implementation: SVGGElementImpl
9
+ };
node_modules/jsdom/lib/jsdom/living/nodes/SVGGraphicsElement-impl.js ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "use strict";
2
+
3
+ const { mixin } = require("../../utils");
4
+ const SVGElementImpl = require("./SVGElement-impl").implementation;
5
+ const SVGTestsImpl = require("./SVGTests-impl").implementation;
6
+
7
+ class SVGGraphicsElementImpl extends SVGElementImpl {}
8
+
9
+ SVGGraphicsElementImpl.attributeRegistry = new Map([
10
+ ...SVGElementImpl.attributeRegistry,
11
+ ...SVGTestsImpl.attributeRegistry
12
+ ]);
13
+
14
+ mixin(SVGGraphicsElementImpl.prototype, SVGTestsImpl.prototype);
15
+
16
+ exports.implementation = SVGGraphicsElementImpl;
node_modules/jsdom/lib/jsdom/living/nodes/SVGMetadataElement-impl.js ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ "use strict";
2
+
3
+ const SVGElementImpl = require("./SVGElement-impl").implementation;
4
+
5
+ class SVGMetadataElementImpl extends SVGElementImpl {}
6
+
7
+ module.exports = {
8
+ implementation: SVGMetadataElementImpl
9
+ };
node_modules/jsdom/lib/jsdom/living/nodes/SVGSVGElement-impl.js ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "use strict";
2
+
3
+ const SVGNumber = require("../../../generated/idl/SVGNumber");
4
+ const SVGRect = require("../../../generated/idl/SVGRect");
5
+ const SVGGraphicsElementImpl = require("./SVGGraphicsElement-impl").implementation;
6
+ const { domSymbolTree } = require("../helpers/internal-constants");
7
+ const { ELEMENT_NODE } = require("../node-type");
8
+
9
+ class SVGSVGElementImpl extends SVGGraphicsElementImpl {
10
+ createSVGNumber() {
11
+ return SVGNumber.createImpl(this._globalObject, [], {});
12
+ }
13
+
14
+ createSVGRect() {
15
+ return SVGRect.createImpl(this._globalObject, [], {});
16
+ }
17
+
18
+ // Unlike `Document`'s `getElementById()`, this searches within this element's subtree, so the document-level
19
+ // `ByIdCache` can't be used (it might return an element outside this subtree). A per-`<svg>` cache isn't worthwhile
20
+ // since `SVGSVGElement`'s `getElementById()` is rarely called and `<svg>` subtrees are typically small.
21
+ getElementById(elementId) {
22
+ for (const node of domSymbolTree.treeIterator(this)) {
23
+ if (node.nodeType === ELEMENT_NODE && node.getAttributeNS(null, "id") === elementId) {
24
+ return node;
25
+ }
26
+ }
27
+ return null;
28
+ }
29
+
30
+ suspendRedraw() {
31
+ return 1;
32
+ }
33
+ unsuspendRedraw() {}
34
+ unsuspendRedrawAll() {}
35
+ forceRedraw() {}
36
+ }
37
+
38
+ module.exports = {
39
+ implementation: SVGSVGElementImpl
40
+ };
node_modules/jsdom/lib/jsdom/living/nodes/SVGSwitchElement-impl.js ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ "use strict";
2
+
3
+ const SVGGraphicsElementImpl = require("./SVGGraphicsElement-impl").implementation;
4
+
5
+ class SVGSwitchElementImpl extends SVGGraphicsElementImpl {}
6
+
7
+ module.exports = {
8
+ implementation: SVGSwitchElementImpl
9
+ };
node_modules/jsdom/lib/jsdom/living/nodes/SVGSymbolElement-impl.js ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ "use strict";
2
+
3
+ const SVGGraphicsElementImpl = require("./SVGGraphicsElement-impl").implementation;
4
+
5
+ class SVGSymbolElementImpl extends SVGGraphicsElementImpl {}
6
+
7
+ module.exports = {
8
+ implementation: SVGSymbolElementImpl
9
+ };
node_modules/jsdom/lib/jsdom/living/nodes/SVGTests-impl.js ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "use strict";
2
+
3
+ const { splitOnASCIIWhitespace, splitOnCommas } = require("../helpers/strings");
4
+ const { reserializeCommaSeparatedTokens, reserializeSpaceSeparatedTokens } = require("../helpers/svg/basic-types");
5
+ const SVGStringList = require("../../../generated/idl/SVGStringList");
6
+
7
+ class SVGTestsImpl {
8
+ get requiredExtensions() {
9
+ return SVGStringList.createImpl(this._globalObject, [], {
10
+ element: this,
11
+ attribute: "requiredExtensions"
12
+ });
13
+ }
14
+
15
+ get systemLanguage() {
16
+ return SVGStringList.createImpl(this._globalObject, [], {
17
+ element: this,
18
+ attribute: "systemLanguage"
19
+ });
20
+ }
21
+ }
22
+
23
+ SVGTestsImpl.attributeRegistry = new Map([
24
+ // https://svgwg.org/svg2-draft/struct.html#RequiredExtensionsAttribute
25
+ [
26
+ "requiredExtensions", {
27
+ getValue: splitOnASCIIWhitespace,
28
+ serialize: reserializeSpaceSeparatedTokens,
29
+ initialValue: undefined
30
+ }
31
+ ],
32
+ // https://svgwg.org/svg2-draft/struct.html#SystemLanguageAttribute
33
+ [
34
+ "systemLanguage", {
35
+ getValue: splitOnCommas,
36
+ serialize: reserializeCommaSeparatedTokens,
37
+ initialValue: undefined
38
+ }
39
+ ]
40
+ ]);
41
+
42
+ exports.implementation = SVGTestsImpl;
node_modules/jsdom/lib/jsdom/living/nodes/SVGTitleElement-impl.js ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ "use strict";
2
+
3
+ const SVGElementImpl = require("./SVGElement-impl").implementation;
4
+
5
+ class SVGTitleElementImpl extends SVGElementImpl { }
6
+
7
+ module.exports = {
8
+ implementation: SVGTitleElementImpl
9
+ };
node_modules/jsdom/lib/jsdom/living/nodes/ShadowRoot-impl.js ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "use strict";
2
+
3
+ const { nodeRoot } = require("../helpers/node");
4
+ const { mixin } = require("../../utils");
5
+
6
+ const DocumentFragment = require("./DocumentFragment-impl").implementation;
7
+ const DocumentOrShadowRootImpl = require("./DocumentOrShadowRoot-impl").implementation;
8
+ const InnerHTMLImpl = require("../domparsing/InnerHTML-impl").implementation;
9
+
10
+ class ShadowRootImpl extends DocumentFragment {
11
+ constructor(globalObject, args, privateData) {
12
+ super(globalObject, args, privateData);
13
+
14
+ const { mode } = privateData;
15
+ this._mode = mode;
16
+ this._availableToElementInternals = false;
17
+ }
18
+
19
+ _getTheParent(event) {
20
+ if (!event.composed && this === nodeRoot(event._path[0].item)) {
21
+ return null;
22
+ }
23
+
24
+ return this._host;
25
+ }
26
+
27
+ get mode() {
28
+ return this._mode;
29
+ }
30
+
31
+ get host() {
32
+ return this._host;
33
+ }
34
+ }
35
+
36
+ mixin(ShadowRootImpl.prototype, DocumentOrShadowRootImpl.prototype);
37
+ mixin(ShadowRootImpl.prototype, InnerHTMLImpl.prototype);
38
+
39
+ module.exports = {
40
+ implementation: ShadowRootImpl
41
+ };
node_modules/jsdom/lib/jsdom/living/nodes/Slotable-impl.js ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "use strict";
2
+
3
+ const { findSlot, assignSlot, assignSlotable } = require("../helpers/shadow-dom");
4
+
5
+ // https://dom.spec.whatwg.org/#mixin-slotable
6
+ // https://dom.spec.whatwg.org/#light-tree-slotables
7
+ class SlotableMixinImpl {
8
+ _initSlotableMixin() {
9
+ this._slotableName = "";
10
+ }
11
+
12
+ _attrModifiedSlotableMixin(name, value, oldValue) {
13
+ if (name === "slot") {
14
+ if (value === oldValue) {
15
+ return;
16
+ }
17
+
18
+ if (value === null && oldValue === "") {
19
+ return;
20
+ }
21
+
22
+ if (value === "" && oldValue === null) {
23
+ return;
24
+ }
25
+
26
+ if (value === null || value === "") {
27
+ this._slotableName = "";
28
+ } else {
29
+ this._slotableName = value;
30
+ }
31
+
32
+
33
+ if (this._assignedSlot) {
34
+ assignSlotable(this._assignedSlot);
35
+ }
36
+
37
+ assignSlot(this);
38
+ }
39
+ }
40
+
41
+ get assignedSlot() {
42
+ return findSlot(this, "open");
43
+ }
44
+ }
45
+
46
+ module.exports = {
47
+ implementation: SlotableMixinImpl
48
+ };
node_modules/jsdom/lib/jsdom/living/nodes/Text-impl.js ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "use strict";
2
+ const SlotableMixinImpl = require("./Slotable-impl").implementation;
3
+ const CharacterDataImpl = require("./CharacterData-impl").implementation;
4
+ const idlUtils = require("../../../generated/idl/utils");
5
+ const { domSymbolTree } = require("../helpers/internal-constants");
6
+ const DOMException = require("../../../generated/idl/DOMException");
7
+ const NODE_TYPE = require("../node-type");
8
+ const { mixin } = require("../../utils");
9
+
10
+ // https://dom.spec.whatwg.org/#text
11
+ class TextImpl extends CharacterDataImpl {
12
+ constructor(globalObject, args, privateData) {
13
+ super(globalObject, args, {
14
+ data: args[0],
15
+ ownerDocument: idlUtils.implForWrapper(globalObject._document),
16
+ ...privateData
17
+ });
18
+
19
+ this._initSlotableMixin();
20
+
21
+ this.nodeType = NODE_TYPE.TEXT_NODE;
22
+ }
23
+
24
+ // https://dom.spec.whatwg.org/#dom-text-splittext
25
+ // https://dom.spec.whatwg.org/#concept-text-split
26
+ splitText(offset) {
27
+ const { length } = this;
28
+
29
+ if (offset > length) {
30
+ throw DOMException.create(this._globalObject, ["The index is not in the allowed range.", "IndexSizeError"]);
31
+ }
32
+
33
+ const count = length - offset;
34
+ const newData = this.substringData(offset, count);
35
+
36
+ const newNode = this._ownerDocument.createTextNode(newData);
37
+
38
+ const parent = domSymbolTree.parent(this);
39
+
40
+ if (parent !== null) {
41
+ parent._insert(newNode, this.nextSibling);
42
+
43
+ for (const range of this._liveRanges()) {
44
+ const { _start, _end } = range;
45
+
46
+ if (_start.node === this && _start.offset > offset) {
47
+ range._setLiveRangeStart(newNode, _start.offset - offset);
48
+ }
49
+
50
+ if (_end.node === this && _end.offset > offset) {
51
+ range._setLiveRangeEnd(newNode, _end.offset - offset);
52
+ }
53
+ }
54
+
55
+ const nodeIndex = domSymbolTree.index(this);
56
+ for (const range of parent._liveRanges()) {
57
+ const { _start, _end } = range;
58
+
59
+ if (_start.node === parent && _start.offset === nodeIndex + 1) {
60
+ range._setLiveRangeStart(parent, _start.offset + 1);
61
+ }
62
+
63
+ if (_end.node === parent && _end.offset === nodeIndex + 1) {
64
+ range._setLiveRangeEnd(parent, _end.offset + 1);
65
+ }
66
+ }
67
+ }
68
+
69
+ this.replaceData(offset, count, "");
70
+
71
+ return newNode;
72
+ }
73
+
74
+ // https://dom.spec.whatwg.org/#dom-text-wholetext
75
+ get wholeText() {
76
+ let wholeText = this.textContent;
77
+ let next;
78
+ let current = this;
79
+ while ((next = domSymbolTree.previousSibling(current)) && next.nodeType === NODE_TYPE.TEXT_NODE) {
80
+ wholeText = next.textContent + wholeText;
81
+ current = next;
82
+ }
83
+ current = this;
84
+ while ((next = domSymbolTree.nextSibling(current)) && next.nodeType === NODE_TYPE.TEXT_NODE) {
85
+ wholeText += next.textContent;
86
+ current = next;
87
+ }
88
+ return wholeText;
89
+ }
90
+ }
91
+
92
+ mixin(TextImpl.prototype, SlotableMixinImpl.prototype);
93
+
94
+ module.exports = {
95
+ implementation: TextImpl
96
+ };
node_modules/jsdom/lib/jsdom/living/nodes/WindowEventHandlers-impl.js ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "use strict";
2
+
3
+ const { createEventAccessor } = require("../helpers/create-event-accessor");
4
+ const { windowEventHandlersEvents } = require("../../../generated/event-sets");
5
+
6
+ class WindowEventHandlersImpl {}
7
+
8
+ for (const event of windowEventHandlersEvents) {
9
+ createEventAccessor(WindowEventHandlersImpl.prototype, event);
10
+ }
11
+
12
+ module.exports = {
13
+ implementation: WindowEventHandlersImpl
14
+ };
node_modules/jsdom/lib/jsdom/living/nodes/XMLDocument-impl.js ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ "use strict";
2
+ const DocumentImpl = require("./Document-impl").implementation;
3
+
4
+ exports.implementation = class XMLDocumentImpl extends DocumentImpl {};
node_modules/jsdom/lib/jsdom/living/range/AbstractRange-impl.js ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "use strict";
2
+
3
+ // https://dom.spec.whatwg.org/#abstractrange
4
+ class AbstractRangeImpl {
5
+ constructor(globalObject, args, privateData) {
6
+ const { start, end } = privateData;
7
+
8
+ this._start = start;
9
+ this._end = end;
10
+
11
+ this._globalObject = globalObject;
12
+ }
13
+
14
+ // https://dom.spec.whatwg.org/#dom-range-startcontainer
15
+ get startContainer() {
16
+ return this._start.node;
17
+ }
18
+
19
+ // https://dom.spec.whatwg.org/#dom-range-startoffset
20
+ get startOffset() {
21
+ return this._start.offset;
22
+ }
23
+
24
+ // https://dom.spec.whatwg.org/#dom-range-endcontainer
25
+ get endContainer() {
26
+ return this._end.node;
27
+ }
28
+
29
+ // https://dom.spec.whatwg.org/#dom-range-endoffset
30
+ get endOffset() {
31
+ return this._end.offset;
32
+ }
33
+
34
+ // https://dom.spec.whatwg.org/#dom-range-collapsed
35
+ get collapsed() {
36
+ const { _start, _end } = this;
37
+ return _start.node === _end.node && _start.offset === _end.offset;
38
+ }
39
+ }
40
+
41
+ module.exports = {
42
+ implementation: AbstractRangeImpl
43
+ };
node_modules/jsdom/lib/jsdom/living/range/Range-impl.js ADDED
@@ -0,0 +1,902 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "use strict";
2
+
3
+ const DOMException = require("../../../generated/idl/DOMException");
4
+
5
+ const { clone } = require("../node");
6
+ const NODE_TYPE = require("../node-type");
7
+ const { parseFragment } = require("../../browser/parser/index");
8
+
9
+ const { HTML_NS } = require("../helpers/namespaces");
10
+ const { domSymbolTree } = require("../helpers/internal-constants");
11
+ const { compareBoundaryPointsPosition } = require("./boundary-point");
12
+ const { nodeRoot, nodeLength, isInclusiveAncestor } = require("../helpers/node");
13
+ const { createElement } = require("../helpers/create-element");
14
+
15
+ const AbstractRangeImpl = require("./AbstractRange-impl").implementation;
16
+
17
+ const Range = require("../../../generated/idl/Range");
18
+ const DocumentFragment = require("../../../generated/idl/DocumentFragment");
19
+ const { implForWrapper } = require("../../../generated/idl/utils");
20
+
21
+ const RANGE_COMPARISON_TYPE = {
22
+ START_TO_START: 0,
23
+ START_TO_END: 1,
24
+ END_TO_END: 2,
25
+ END_TO_START: 3
26
+ };
27
+
28
+ class RangeImpl extends AbstractRangeImpl {
29
+ constructor(globalObject, args, privateData) {
30
+ super(globalObject, args, privateData);
31
+
32
+ // Store a WeakRef to this Range for use in _referencedRanges.
33
+ // This allows Ranges to be garbage collected when no longer referenced by user code,
34
+ // preventing accumulation in long-lived nodes like document.body.
35
+ this._weakRef = new WeakRef(this);
36
+
37
+ const defaultBoundaryPoint = {
38
+ node: implForWrapper(globalObject._document),
39
+ offset: 0
40
+ };
41
+
42
+ const {
43
+ start = defaultBoundaryPoint,
44
+ end = defaultBoundaryPoint
45
+ } = privateData;
46
+
47
+ this._setLiveRangeStart(start.node, start.offset);
48
+ this._setLiveRangeEnd(end.node, end.offset);
49
+ }
50
+
51
+ // https://dom.spec.whatwg.org/#dom-range-commonancestorcontainer
52
+ get commonAncestorContainer() {
53
+ const { _start, _end } = this;
54
+
55
+ for (const container of domSymbolTree.ancestorsIterator(_start.node)) {
56
+ if (isInclusiveAncestor(container, _end.node)) {
57
+ return container;
58
+ }
59
+ }
60
+
61
+ return null;
62
+ }
63
+
64
+ // https://dom.spec.whatwg.org/#dom-range-setstart
65
+ setStart(node, offset) {
66
+ setBoundaryPointStart(this, node, offset);
67
+ }
68
+
69
+ // https://dom.spec.whatwg.org/#dom-range-setend
70
+ setEnd(node, offset) {
71
+ setBoundaryPointEnd(this, node, offset);
72
+ }
73
+
74
+ // https://dom.spec.whatwg.org/#dom-range-setstartbefore
75
+ setStartBefore(node) {
76
+ const parent = domSymbolTree.parent(node);
77
+
78
+ if (!parent) {
79
+ throw DOMException.create(this._globalObject, ["The given Node has no parent.", "InvalidNodeTypeError"]);
80
+ }
81
+
82
+ setBoundaryPointStart(this, parent, domSymbolTree.index(node));
83
+ }
84
+
85
+ // https://dom.spec.whatwg.org/#dom-range-setstartafter
86
+ setStartAfter(node) {
87
+ const parent = domSymbolTree.parent(node);
88
+
89
+ if (!parent) {
90
+ throw DOMException.create(this._globalObject, ["The given Node has no parent.", "InvalidNodeTypeError"]);
91
+ }
92
+
93
+ setBoundaryPointStart(this, parent, domSymbolTree.index(node) + 1);
94
+ }
95
+
96
+ // https://dom.spec.whatwg.org/#dom-range-setendbefore
97
+ setEndBefore(node) {
98
+ const parent = domSymbolTree.parent(node);
99
+
100
+ if (!parent) {
101
+ throw DOMException.create(this._globalObject, ["The given Node has no parent.", "InvalidNodeTypeError"]);
102
+ }
103
+
104
+ setBoundaryPointEnd(this, parent, domSymbolTree.index(node));
105
+ }
106
+
107
+ // https://dom.spec.whatwg.org/#dom-range-setendafter
108
+ setEndAfter(node) {
109
+ const parent = domSymbolTree.parent(node);
110
+
111
+ if (!parent) {
112
+ throw DOMException.create(this._globalObject, ["The given Node has no parent.", "InvalidNodeTypeError"]);
113
+ }
114
+
115
+ setBoundaryPointEnd(this, parent, domSymbolTree.index(node) + 1);
116
+ }
117
+
118
+ // https://dom.spec.whatwg.org/#dom-range-collapse
119
+ collapse(toStart) {
120
+ if (toStart) {
121
+ this._setLiveRangeEnd(this._start.node, this._start.offset);
122
+ } else {
123
+ this._setLiveRangeStart(this._end.node, this._end.offset);
124
+ }
125
+ }
126
+
127
+ // https://dom.spec.whatwg.org/#dom-range-selectnode
128
+ selectNode(node) {
129
+ selectNodeWithinRange(node, this);
130
+ }
131
+
132
+ // https://dom.spec.whatwg.org/#dom-range-selectnodecontents
133
+ selectNodeContents(node) {
134
+ if (node.nodeType === NODE_TYPE.DOCUMENT_TYPE_NODE) {
135
+ throw DOMException.create(this._globalObject, [
136
+ "DocumentType Node can't be used as boundary point.",
137
+ "InvalidNodeTypeError"
138
+ ]);
139
+ }
140
+
141
+ const length = nodeLength(node);
142
+
143
+ this._setLiveRangeStart(node, 0);
144
+ this._setLiveRangeEnd(node, length);
145
+ }
146
+
147
+ // https://dom.spec.whatwg.org/#dom-range-compareboundarypoints
148
+ compareBoundaryPoints(how, sourceRange) {
149
+ if (
150
+ how !== RANGE_COMPARISON_TYPE.START_TO_START &&
151
+ how !== RANGE_COMPARISON_TYPE.START_TO_END &&
152
+ how !== RANGE_COMPARISON_TYPE.END_TO_END &&
153
+ how !== RANGE_COMPARISON_TYPE.END_TO_START
154
+ ) {
155
+ const message = "The comparison method provided must be one of 'START_TO_START', 'START_TO_END', 'END_TO_END', " +
156
+ "or 'END_TO_START'.";
157
+ throw DOMException.create(this._globalObject, [message, "NotSupportedError"]);
158
+ }
159
+
160
+ if (this._root !== sourceRange._root) {
161
+ throw DOMException.create(this._globalObject, ["The two Ranges are not in the same tree.", "WrongDocumentError"]);
162
+ }
163
+
164
+ let thisPoint, otherPoint;
165
+ if (how === RANGE_COMPARISON_TYPE.START_TO_START) {
166
+ thisPoint = this._start;
167
+ otherPoint = sourceRange._start;
168
+ } else if (how === RANGE_COMPARISON_TYPE.START_TO_END) {
169
+ thisPoint = this._end;
170
+ otherPoint = sourceRange._start;
171
+ } else if (how === RANGE_COMPARISON_TYPE.END_TO_END) {
172
+ thisPoint = this._end;
173
+ otherPoint = sourceRange._end;
174
+ } else {
175
+ thisPoint = this._start;
176
+ otherPoint = sourceRange._end;
177
+ }
178
+
179
+ return compareBoundaryPointsPosition(thisPoint, otherPoint);
180
+ }
181
+
182
+ // https://dom.spec.whatwg.org/#dom-range-deletecontents
183
+ deleteContents() {
184
+ if (this.collapsed) {
185
+ return;
186
+ }
187
+
188
+ const { _start: originalStart, _end: originalEnd } = this;
189
+
190
+ if (
191
+ originalStart.node === originalEnd.node &&
192
+ (
193
+ originalStart.node.nodeType === NODE_TYPE.TEXT_NODE ||
194
+ originalStart.node.nodeType === NODE_TYPE.PROCESSING_INSTRUCTION_NODE ||
195
+ originalStart.node.nodeType === NODE_TYPE.COMMENT_NODE
196
+ )
197
+ ) {
198
+ originalStart.node.replaceData(originalStart.offset, originalEnd.offset - originalStart.offset, "");
199
+ return;
200
+ }
201
+
202
+ const nodesToRemove = [];
203
+ let currentNode = this._start.node;
204
+ const endNode = nextNodeDescendant(this._end.node);
205
+ while (currentNode && currentNode !== endNode) {
206
+ if (
207
+ isContained(currentNode, this) &&
208
+ !isContained(domSymbolTree.parent(currentNode), this)
209
+ ) {
210
+ nodesToRemove.push(currentNode);
211
+ }
212
+
213
+ currentNode = domSymbolTree.following(currentNode);
214
+ }
215
+
216
+ let newNode, newOffset;
217
+ if (isInclusiveAncestor(originalStart.node, originalEnd.node)) {
218
+ newNode = originalStart.node;
219
+ newOffset = originalStart.offset;
220
+ } else {
221
+ let referenceNode = originalStart.node;
222
+
223
+ while (
224
+ referenceNode &&
225
+ !isInclusiveAncestor(domSymbolTree.parent(referenceNode), originalEnd.node)
226
+ ) {
227
+ referenceNode = domSymbolTree.parent(referenceNode);
228
+ }
229
+
230
+ newNode = domSymbolTree.parent(referenceNode);
231
+ newOffset = domSymbolTree.index(referenceNode) + 1;
232
+ }
233
+
234
+ if (
235
+ originalStart.node.nodeType === NODE_TYPE.TEXT_NODE ||
236
+ originalStart.node.nodeType === NODE_TYPE.PROCESSING_INSTRUCTION_NODE ||
237
+ originalStart.node.nodeType === NODE_TYPE.COMMENT_NODE
238
+ ) {
239
+ originalStart.node.replaceData(originalStart.offset, nodeLength(originalStart.node) - originalStart.offset, "");
240
+ }
241
+
242
+ for (const node of nodesToRemove) {
243
+ const parent = domSymbolTree.parent(node);
244
+ parent.removeChild(node);
245
+ }
246
+
247
+ if (
248
+ originalEnd.node.nodeType === NODE_TYPE.TEXT_NODE ||
249
+ originalEnd.node.nodeType === NODE_TYPE.PROCESSING_INSTRUCTION_NODE ||
250
+ originalEnd.node.nodeType === NODE_TYPE.COMMENT_NODE
251
+ ) {
252
+ originalEnd.node.replaceData(0, originalEnd.offset, "");
253
+ }
254
+
255
+ this._setLiveRangeStart(newNode, newOffset);
256
+ this._setLiveRangeEnd(newNode, newOffset);
257
+ }
258
+
259
+ // https://dom.spec.whatwg.org/#dom-range-extractcontents
260
+ extractContents() {
261
+ return extractRange(this);
262
+ }
263
+
264
+ // https://dom.spec.whatwg.org/#dom-range-clonecontents
265
+ cloneContents() {
266
+ return cloneRange(this);
267
+ }
268
+
269
+ // https://dom.spec.whatwg.org/#dom-range-insertnode
270
+ insertNode(node) {
271
+ insertNodeInRange(node, this);
272
+ }
273
+
274
+ // https://dom.spec.whatwg.org/#dom-range-surroundcontents
275
+ surroundContents(newParent) {
276
+ let node = this.commonAncestorContainer;
277
+ const endNode = nextNodeDescendant(node);
278
+ while (node !== endNode) {
279
+ if (node.nodeType !== NODE_TYPE.TEXT_NODE && isPartiallyContained(node, this)) {
280
+ throw DOMException.create(this._globalObject, [
281
+ "The Range has partially contains a non-Text node.",
282
+ "InvalidStateError"
283
+ ]);
284
+ }
285
+
286
+ node = domSymbolTree.following(node);
287
+ }
288
+
289
+ if (
290
+ newParent.nodeType === NODE_TYPE.DOCUMENT_NODE ||
291
+ newParent.nodeType === NODE_TYPE.DOCUMENT_TYPE_NODE ||
292
+ newParent.nodeType === NODE_TYPE.DOCUMENT_FRAGMENT_NODE
293
+ ) {
294
+ throw DOMException.create(this._globalObject, ["Invalid element type.", "InvalidNodeTypeError"]);
295
+ }
296
+
297
+ const fragment = extractRange(this);
298
+
299
+ while (domSymbolTree.firstChild(newParent)) {
300
+ newParent.removeChild(domSymbolTree.firstChild(newParent));
301
+ }
302
+
303
+ insertNodeInRange(newParent, this);
304
+
305
+ newParent.appendChild(fragment);
306
+
307
+ selectNodeWithinRange(newParent, this);
308
+ }
309
+
310
+ // https://dom.spec.whatwg.org/#dom-range-clonerange
311
+ cloneRange() {
312
+ const { _start, _end, _globalObject } = this;
313
+
314
+ return Range.createImpl(_globalObject, [], {
315
+ start: { node: _start.node, offset: _start.offset },
316
+ end: { node: _end.node, offset: _end.offset }
317
+ });
318
+ }
319
+
320
+ // https://dom.spec.whatwg.org/#dom-range-detach
321
+ detach() {
322
+ // Do nothing by spec!
323
+ }
324
+
325
+ // https://dom.spec.whatwg.org/#dom-range-ispointinrange
326
+ isPointInRange(node, offset) {
327
+ if (nodeRoot(node) !== this._root) {
328
+ return false;
329
+ }
330
+
331
+ validateSetBoundaryPoint(node, offset);
332
+
333
+ const bp = { node, offset };
334
+
335
+ if (
336
+ compareBoundaryPointsPosition(bp, this._start) === -1 ||
337
+ compareBoundaryPointsPosition(bp, this._end) === 1
338
+ ) {
339
+ return false;
340
+ }
341
+
342
+ return true;
343
+ }
344
+
345
+ // https://dom.spec.whatwg.org/#dom-range-comparepoint
346
+ comparePoint(node, offset) {
347
+ if (nodeRoot(node) !== this._root) {
348
+ throw DOMException.create(this._globalObject, [
349
+ "The given Node and the Range are not in the same tree.",
350
+ "WrongDocumentError"
351
+ ]);
352
+ }
353
+
354
+ validateSetBoundaryPoint(node, offset);
355
+
356
+ const bp = { node, offset };
357
+ if (compareBoundaryPointsPosition(bp, this._start) === -1) {
358
+ return -1;
359
+ } else if (compareBoundaryPointsPosition(bp, this._end) === 1) {
360
+ return 1;
361
+ }
362
+
363
+ return 0;
364
+ }
365
+
366
+ // https://dom.spec.whatwg.org/#dom-range-intersectsnode
367
+ intersectsNode(node) {
368
+ if (nodeRoot(node) !== this._root) {
369
+ return false;
370
+ }
371
+
372
+ const parent = domSymbolTree.parent(node);
373
+ if (!parent) {
374
+ return true;
375
+ }
376
+
377
+ const offset = domSymbolTree.index(node);
378
+
379
+ return (
380
+ compareBoundaryPointsPosition({ node: parent, offset }, this._end) === -1 &&
381
+ compareBoundaryPointsPosition({ node: parent, offset: offset + 1 }, this._start) === 1
382
+ );
383
+ }
384
+
385
+ // https://dom.spec.whatwg.org/#dom-range-stringifier
386
+ toString() {
387
+ let s = "";
388
+ const { _start, _end } = this;
389
+
390
+ if (_start.node === _end.node && _start.node.nodeType === NODE_TYPE.TEXT_NODE) {
391
+ return _start.node.data.slice(_start.offset, _end.offset);
392
+ }
393
+
394
+ if (_start.node.nodeType === NODE_TYPE.TEXT_NODE) {
395
+ s += _start.node.data.slice(_start.offset);
396
+ }
397
+
398
+ let currentNode = _start.node;
399
+ const endNode = nextNodeDescendant(_end.node);
400
+ while (currentNode && currentNode !== endNode) {
401
+ if (currentNode.nodeType === NODE_TYPE.TEXT_NODE && isContained(currentNode, this)) {
402
+ s += currentNode.data;
403
+ }
404
+
405
+ currentNode = domSymbolTree.following(currentNode);
406
+ }
407
+
408
+ if (_end.node.nodeType === NODE_TYPE.TEXT_NODE) {
409
+ s += _end.node.data.slice(0, _end.offset);
410
+ }
411
+
412
+ return s;
413
+ }
414
+
415
+ // https://w3c.github.io/DOM-Parsing/#dom-range-createcontextualfragment
416
+ createContextualFragment(fragment) {
417
+ const { node } = this._start;
418
+
419
+ let element;
420
+ switch (node.nodeType) {
421
+ case NODE_TYPE.DOCUMENT_NODE:
422
+ case NODE_TYPE.DOCUMENT_FRAGMENT_NODE:
423
+ element = null;
424
+ break;
425
+
426
+ case NODE_TYPE.ELEMENT_NODE:
427
+ element = node;
428
+ break;
429
+
430
+ case NODE_TYPE.TEXT_NODE:
431
+ case NODE_TYPE.COMMENT_NODE:
432
+ element = node.parentElement;
433
+ break;
434
+
435
+ default:
436
+ throw new Error("Internal error: Invalid range start node");
437
+ }
438
+
439
+ if (
440
+ element === null || (
441
+ element._ownerDocument._parsingMode === "html" &&
442
+ element._localName === "html" &&
443
+ element._namespaceURI === HTML_NS
444
+ )
445
+ ) {
446
+ element = createElement(node._ownerDocument, "body", HTML_NS);
447
+ }
448
+
449
+ return parseFragment(fragment, element);
450
+ }
451
+
452
+ // https://dom.spec.whatwg.org/#concept-range-root
453
+ get _root() {
454
+ return nodeRoot(this._start.node);
455
+ }
456
+
457
+ _setLiveRangeStart(node, offset) {
458
+ if (
459
+ this._start &&
460
+ this._start.node !== node &&
461
+ this._start.node !== this._end.node
462
+ ) {
463
+ this._start.node._referencedRanges.delete(this._weakRef);
464
+ }
465
+
466
+ if (!node._referencedRanges.has(this._weakRef)) {
467
+ node._referencedRanges.add(this._weakRef);
468
+ }
469
+
470
+ this._start = {
471
+ node,
472
+ offset
473
+ };
474
+ }
475
+
476
+ _setLiveRangeEnd(node, offset) {
477
+ if (
478
+ this._end &&
479
+ this._end.node !== node &&
480
+ this._end.node !== this._start.node
481
+ ) {
482
+ this._end.node._referencedRanges.delete(this._weakRef);
483
+ }
484
+
485
+ if (!node._referencedRanges.has(this._weakRef)) {
486
+ node._referencedRanges.add(this._weakRef);
487
+ }
488
+
489
+ this._end = {
490
+ node,
491
+ offset
492
+ };
493
+ }
494
+ }
495
+
496
+
497
+ function nextNodeDescendant(node) {
498
+ while (node && !domSymbolTree.nextSibling(node)) {
499
+ node = domSymbolTree.parent(node);
500
+ }
501
+
502
+ if (!node) {
503
+ return null;
504
+ }
505
+
506
+ return domSymbolTree.nextSibling(node);
507
+ }
508
+
509
+ // https://dom.spec.whatwg.org/#concept-range-bp-set
510
+ function validateSetBoundaryPoint(node, offset) {
511
+ if (node.nodeType === NODE_TYPE.DOCUMENT_TYPE_NODE) {
512
+ throw DOMException.create(node._globalObject, [
513
+ "DocumentType Node can't be used as boundary point.",
514
+ "InvalidNodeTypeError"
515
+ ]);
516
+ }
517
+
518
+ if (offset > nodeLength(node)) {
519
+ throw DOMException.create(node._globalObject, ["Offset out of bound.", "IndexSizeError"]);
520
+ }
521
+ }
522
+ function setBoundaryPointStart(range, node, offset) {
523
+ validateSetBoundaryPoint(node, offset);
524
+
525
+ const bp = { node, offset };
526
+ if (
527
+ nodeRoot(node) !== range._root ||
528
+ compareBoundaryPointsPosition(bp, range._end) === 1
529
+ ) {
530
+ range._setLiveRangeEnd(node, offset);
531
+ }
532
+
533
+ range._setLiveRangeStart(node, offset);
534
+ }
535
+ function setBoundaryPointEnd(range, node, offset) {
536
+ validateSetBoundaryPoint(node, offset);
537
+
538
+ const bp = { node, offset };
539
+ if (
540
+ nodeRoot(node) !== range._root ||
541
+ compareBoundaryPointsPosition(bp, range._start) === -1
542
+ ) {
543
+ range._setLiveRangeStart(node, offset);
544
+ }
545
+
546
+ range._setLiveRangeEnd(node, offset);
547
+ }
548
+
549
+ // https://dom.spec.whatwg.org/#concept-range-select
550
+ function selectNodeWithinRange(node, range) {
551
+ const parent = domSymbolTree.parent(node);
552
+
553
+ if (!parent) {
554
+ throw DOMException.create(node._globalObject, ["The given Node has no parent.", "InvalidNodeTypeError"]);
555
+ }
556
+
557
+ const index = domSymbolTree.index(node);
558
+
559
+ range._setLiveRangeStart(parent, index);
560
+ range._setLiveRangeEnd(parent, index + 1);
561
+ }
562
+
563
+ // https://dom.spec.whatwg.org/#contained
564
+ function isContained(node, range) {
565
+ const { _start, _end } = range;
566
+ return (
567
+ compareBoundaryPointsPosition({ node, offset: 0 }, _start) === 1 &&
568
+ compareBoundaryPointsPosition({ node, offset: nodeLength(node) }, _end) === -1
569
+ );
570
+ }
571
+
572
+ // https://dom.spec.whatwg.org/#partially-contained
573
+ function isPartiallyContained(node, range) {
574
+ const { _start, _end } = range;
575
+ return (
576
+ (isInclusiveAncestor(node, _start.node) && !isInclusiveAncestor(node, _end.node)) ||
577
+ (!isInclusiveAncestor(node, _start.node) && isInclusiveAncestor(node, _end.node))
578
+ );
579
+ }
580
+
581
+ // https://dom.spec.whatwg.org/#concept-range-insert
582
+ function insertNodeInRange(node, range) {
583
+ const { node: startNode, offset: startOffset } = range._start;
584
+
585
+ if (
586
+ startNode.nodeType === NODE_TYPE.PROCESSING_INSTRUCTION_NODE ||
587
+ startNode.nodeType === NODE_TYPE.COMMENT_NODE ||
588
+ (startNode.nodeType === NODE_TYPE.TEXT_NODE && !domSymbolTree.parent(startNode)) ||
589
+ node === startNode
590
+ ) {
591
+ throw DOMException.create(node._globalObject, ["Invalid start node.", "HierarchyRequestError"]);
592
+ }
593
+
594
+ let referenceNode = startNode.nodeType === NODE_TYPE.TEXT_NODE ?
595
+ startNode :
596
+ domSymbolTree.childrenToArray(startNode)[startOffset] || null;
597
+ const parent = !referenceNode ?
598
+ startNode :
599
+ domSymbolTree.parent(referenceNode);
600
+
601
+ parent._preInsertValidity(node, referenceNode);
602
+
603
+ if (startNode.nodeType === NODE_TYPE.TEXT_NODE) {
604
+ referenceNode = startNode.splitText(startOffset);
605
+ }
606
+
607
+ if (node === referenceNode) {
608
+ referenceNode = domSymbolTree.nextSibling(referenceNode);
609
+ }
610
+
611
+ const nodeParent = domSymbolTree.parent(node);
612
+ if (nodeParent) {
613
+ nodeParent.removeChild(node);
614
+ }
615
+
616
+ let newOffset = !referenceNode ? nodeLength(parent) : domSymbolTree.index(referenceNode);
617
+ newOffset += node.nodeType === NODE_TYPE.DOCUMENT_FRAGMENT_NODE ? nodeLength(node) : 1;
618
+
619
+ parent.insertBefore(node, referenceNode);
620
+
621
+ if (range.collapsed) {
622
+ range._setLiveRangeEnd(parent, newOffset);
623
+ }
624
+ }
625
+
626
+ // https://dom.spec.whatwg.org/#concept-range-clone
627
+ function cloneRange(range) {
628
+ const { _start: originalStart, _end: originalEnd, _globalObject } = range;
629
+
630
+ const fragment = DocumentFragment.createImpl(_globalObject, [], {
631
+ ownerDocument: originalStart.node._ownerDocument
632
+ });
633
+
634
+ if (range.collapsed) {
635
+ return fragment;
636
+ }
637
+
638
+ if (
639
+ originalStart.node === originalEnd.node &&
640
+ (
641
+ originalStart.node.nodeType === NODE_TYPE.TEXT_NODE ||
642
+ originalStart.node.nodeType === NODE_TYPE.PROCESSING_INSTRUCTION_NODE ||
643
+ originalStart.node.nodeType === NODE_TYPE.COMMENT_NODE
644
+ )
645
+ ) {
646
+ const cloned = clone(originalStart.node);
647
+ cloned._data = cloned.substringData(originalStart.offset, originalEnd.offset - originalStart.offset);
648
+
649
+ fragment.appendChild(cloned);
650
+
651
+ return fragment;
652
+ }
653
+
654
+ let commonAncestor = originalStart.node;
655
+ while (!isInclusiveAncestor(commonAncestor, originalEnd.node)) {
656
+ commonAncestor = domSymbolTree.parent(commonAncestor);
657
+ }
658
+
659
+ let firstPartialContainedChild = null;
660
+ if (!isInclusiveAncestor(originalStart.node, originalEnd.node)) {
661
+ let candidate = domSymbolTree.firstChild(commonAncestor);
662
+ while (!firstPartialContainedChild) {
663
+ if (isPartiallyContained(candidate, range)) {
664
+ firstPartialContainedChild = candidate;
665
+ }
666
+
667
+ candidate = domSymbolTree.nextSibling(candidate);
668
+ }
669
+ }
670
+
671
+ let lastPartiallyContainedChild = null;
672
+ if (!isInclusiveAncestor(originalEnd.node, originalStart.node)) {
673
+ let candidate = domSymbolTree.lastChild(commonAncestor);
674
+ while (!lastPartiallyContainedChild) {
675
+ if (isPartiallyContained(candidate, range)) {
676
+ lastPartiallyContainedChild = candidate;
677
+ }
678
+
679
+ candidate = domSymbolTree.previousSibling(candidate);
680
+ }
681
+ }
682
+
683
+ const containedChildren = domSymbolTree.childrenToArray(commonAncestor)
684
+ .filter(node => isContained(node, range));
685
+
686
+ const hasDoctypeChildren = containedChildren.some(node => node.nodeType === NODE_TYPE.DOCUMENT_TYPE_NODE);
687
+ if (hasDoctypeChildren) {
688
+ throw DOMException.create(range._globalObject, ["Invalid document type element.", "HierarchyRequestError"]);
689
+ }
690
+
691
+ if (
692
+ firstPartialContainedChild !== null &&
693
+ (
694
+ firstPartialContainedChild.nodeType === NODE_TYPE.TEXT_NODE ||
695
+ firstPartialContainedChild.nodeType === NODE_TYPE.PROCESSING_INSTRUCTION_NODE ||
696
+ firstPartialContainedChild.nodeType === NODE_TYPE.COMMENT_NODE
697
+ )
698
+ ) {
699
+ const cloned = clone(originalStart.node);
700
+ cloned._data = cloned.substringData(originalStart.offset, nodeLength(originalStart.node) - originalStart.offset);
701
+
702
+ fragment.appendChild(cloned);
703
+ } else if (firstPartialContainedChild !== null) {
704
+ const cloned = clone(firstPartialContainedChild);
705
+ fragment.appendChild(cloned);
706
+
707
+ const subrange = Range.createImpl(_globalObject, [], {
708
+ start: { node: originalStart.node, offset: originalStart.offset },
709
+ end: { node: firstPartialContainedChild, offset: nodeLength(firstPartialContainedChild) }
710
+ });
711
+
712
+ const subfragment = cloneRange(subrange);
713
+ cloned.appendChild(subfragment);
714
+ }
715
+
716
+ for (const containedChild of containedChildren) {
717
+ const cloned = clone(containedChild, undefined, true);
718
+ fragment.appendChild(cloned);
719
+ }
720
+
721
+ if (
722
+ lastPartiallyContainedChild !== null &&
723
+ (
724
+ lastPartiallyContainedChild.nodeType === NODE_TYPE.TEXT_NODE ||
725
+ lastPartiallyContainedChild.nodeType === NODE_TYPE.PROCESSING_INSTRUCTION_NODE ||
726
+ lastPartiallyContainedChild.nodeType === NODE_TYPE.COMMENT_NODE
727
+ )
728
+ ) {
729
+ const cloned = clone(originalEnd.node);
730
+ cloned._data = cloned.substringData(0, originalEnd.offset);
731
+
732
+ fragment.appendChild(cloned);
733
+ } else if (lastPartiallyContainedChild !== null) {
734
+ const cloned = clone(lastPartiallyContainedChild);
735
+ fragment.appendChild(cloned);
736
+
737
+ const subrange = Range.createImpl(_globalObject, [], {
738
+ start: { node: lastPartiallyContainedChild, offset: 0 },
739
+ end: { node: originalEnd.node, offset: originalEnd.offset }
740
+ });
741
+
742
+ const subfragment = cloneRange(subrange);
743
+ cloned.appendChild(subfragment);
744
+ }
745
+
746
+ return fragment;
747
+ }
748
+
749
+ // https://dom.spec.whatwg.org/#concept-range-extract
750
+ function extractRange(range) {
751
+ const { _start: originalStart, _end: originalEnd, _globalObject } = range;
752
+
753
+ const fragment = DocumentFragment.createImpl(_globalObject, [], {
754
+ ownerDocument: originalStart.node._ownerDocument
755
+ });
756
+
757
+ if (range.collapsed) {
758
+ return fragment;
759
+ }
760
+
761
+ if (
762
+ originalStart.node === originalEnd.node &&
763
+ (
764
+ originalStart.node.nodeType === NODE_TYPE.TEXT_NODE ||
765
+ originalStart.node.nodeType === NODE_TYPE.PROCESSING_INSTRUCTION_NODE ||
766
+ originalStart.node.nodeType === NODE_TYPE.COMMENT_NODE
767
+ )
768
+ ) {
769
+ const cloned = clone(originalStart.node);
770
+ cloned._data = cloned.substringData(originalStart.offset, originalEnd.offset - originalStart.offset);
771
+
772
+ fragment.appendChild(cloned);
773
+ originalStart.node.replaceData(originalStart.offset, originalEnd.offset - originalStart.offset, "");
774
+
775
+ return fragment;
776
+ }
777
+
778
+ let commonAncestor = originalStart.node;
779
+ while (!isInclusiveAncestor(commonAncestor, originalEnd.node)) {
780
+ commonAncestor = domSymbolTree.parent(commonAncestor);
781
+ }
782
+
783
+ let firstPartialContainedChild = null;
784
+ if (!isInclusiveAncestor(originalStart.node, originalEnd.node)) {
785
+ let candidate = domSymbolTree.firstChild(commonAncestor);
786
+ while (!firstPartialContainedChild) {
787
+ if (isPartiallyContained(candidate, range)) {
788
+ firstPartialContainedChild = candidate;
789
+ }
790
+
791
+ candidate = domSymbolTree.nextSibling(candidate);
792
+ }
793
+ }
794
+
795
+ let lastPartiallyContainedChild = null;
796
+ if (!isInclusiveAncestor(originalEnd.node, originalStart.node)) {
797
+ let candidate = domSymbolTree.lastChild(commonAncestor);
798
+ while (!lastPartiallyContainedChild) {
799
+ if (isPartiallyContained(candidate, range)) {
800
+ lastPartiallyContainedChild = candidate;
801
+ }
802
+
803
+ candidate = domSymbolTree.previousSibling(candidate);
804
+ }
805
+ }
806
+
807
+ const containedChildren = domSymbolTree.childrenToArray(commonAncestor)
808
+ .filter(node => isContained(node, range));
809
+
810
+ const hasDoctypeChildren = containedChildren.some(node => node.nodeType === NODE_TYPE.DOCUMENT_TYPE_NODE);
811
+ if (hasDoctypeChildren) {
812
+ throw DOMException.create(range._globalObject, ["Invalid document type element.", "HierarchyRequestError"]);
813
+ }
814
+
815
+ let newNode, newOffset;
816
+ if (isInclusiveAncestor(originalStart.node, originalEnd.node)) {
817
+ newNode = originalStart.node;
818
+ newOffset = originalStart.offset;
819
+ } else {
820
+ let referenceNode = originalStart.node;
821
+
822
+ while (
823
+ referenceNode &&
824
+ !isInclusiveAncestor(domSymbolTree.parent(referenceNode), originalEnd.node)
825
+ ) {
826
+ referenceNode = domSymbolTree.parent(referenceNode);
827
+ }
828
+
829
+ newNode = domSymbolTree.parent(referenceNode);
830
+ newOffset = domSymbolTree.index(referenceNode) + 1;
831
+ }
832
+
833
+ if (
834
+ firstPartialContainedChild !== null &&
835
+ (
836
+ firstPartialContainedChild.nodeType === NODE_TYPE.TEXT_NODE ||
837
+ firstPartialContainedChild.nodeType === NODE_TYPE.PROCESSING_INSTRUCTION_NODE ||
838
+ firstPartialContainedChild.nodeType === NODE_TYPE.COMMENT_NODE
839
+ )
840
+ ) {
841
+ const cloned = clone(originalStart.node);
842
+ cloned._data = cloned.substringData(originalStart.offset, nodeLength(originalStart.node) - originalStart.offset);
843
+
844
+ fragment.appendChild(cloned);
845
+
846
+ originalStart.node.replaceData(originalStart.offset, nodeLength(originalStart.node) - originalStart.offset, "");
847
+ } else if (firstPartialContainedChild !== null) {
848
+ const cloned = clone(firstPartialContainedChild);
849
+ fragment.appendChild(cloned);
850
+
851
+ const subrange = Range.createImpl(_globalObject, [], {
852
+ start: { node: originalStart.node, offset: originalStart.offset },
853
+ end: { node: firstPartialContainedChild, offset: nodeLength(firstPartialContainedChild) }
854
+ });
855
+
856
+ const subfragment = extractRange(subrange);
857
+ cloned.appendChild(subfragment);
858
+ }
859
+
860
+ for (const containedChild of containedChildren) {
861
+ fragment.appendChild(containedChild);
862
+ }
863
+
864
+ if (
865
+ lastPartiallyContainedChild !== null &&
866
+ (
867
+ lastPartiallyContainedChild.nodeType === NODE_TYPE.TEXT_NODE ||
868
+ lastPartiallyContainedChild.nodeType === NODE_TYPE.PROCESSING_INSTRUCTION_NODE ||
869
+ lastPartiallyContainedChild.nodeType === NODE_TYPE.COMMENT_NODE
870
+ )
871
+ ) {
872
+ const cloned = clone(originalEnd.node);
873
+ cloned._data = cloned.substringData(0, originalEnd.offset);
874
+
875
+ fragment.appendChild(cloned);
876
+
877
+ originalEnd.node.replaceData(0, originalEnd.offset, "");
878
+ } else if (lastPartiallyContainedChild !== null) {
879
+ const cloned = clone(lastPartiallyContainedChild);
880
+ fragment.appendChild(cloned);
881
+
882
+ const subrange = Range.createImpl(_globalObject, [], {
883
+ start: { node: lastPartiallyContainedChild, offset: 0 },
884
+ end: { node: originalEnd.node, offset: originalEnd.offset }
885
+ });
886
+
887
+ const subfragment = extractRange(subrange);
888
+ cloned.appendChild(subfragment);
889
+ }
890
+
891
+ range._setLiveRangeStart(newNode, newOffset);
892
+ range._setLiveRangeEnd(newNode, newOffset);
893
+
894
+ return fragment;
895
+ }
896
+
897
+ module.exports = {
898
+ implementation: RangeImpl,
899
+
900
+ setBoundaryPointStart,
901
+ setBoundaryPointEnd
902
+ };
node_modules/jsdom/lib/jsdom/living/range/StaticRange-impl.js ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "use strict";
2
+
3
+ const DOMException = require("../../../generated/idl/DOMException");
4
+
5
+ const NODE_TYPE = require("../node-type");
6
+
7
+ const AbstractRangeImpl = require("./AbstractRange-impl").implementation;
8
+
9
+ // https://dom.spec.whatwg.org/#staticrange
10
+ class StaticRangeImpl extends AbstractRangeImpl {
11
+ // https://dom.spec.whatwg.org/#dom-staticrange-staticrange
12
+ constructor(globalObject, args) {
13
+ const { startContainer, startOffset, endContainer, endOffset } = args[0];
14
+
15
+ if (
16
+ startContainer.nodeType === NODE_TYPE.DOCUMENT_TYPE_NODE ||
17
+ startContainer.nodeType === NODE_TYPE.ATTRIBUTE_NODE ||
18
+ endContainer.nodeType === NODE_TYPE.DOCUMENT_TYPE_NODE ||
19
+ endContainer.nodeType === NODE_TYPE.ATTRIBUTE_NODE
20
+ ) {
21
+ throw DOMException.create(globalObject, ["The supplied node is incorrect.", "InvalidNodeTypeError"]);
22
+ }
23
+
24
+ super(globalObject, [], {
25
+ start: {
26
+ node: startContainer,
27
+ offset: startOffset
28
+ },
29
+ end: {
30
+ node: endContainer,
31
+ offset: endOffset
32
+ }
33
+ });
34
+ }
35
+ }
36
+
37
+ module.exports = {
38
+ implementation: StaticRangeImpl
39
+ };
node_modules/jsdom/lib/jsdom/living/range/boundary-point.js ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "use strict";
2
+
3
+ const { domSymbolTree } = require("../helpers/internal-constants");
4
+ const { nodeRoot, isFollowing, isInclusiveAncestor } = require("../helpers/node");
5
+
6
+ // Returns 0 if equal, +1 for after and -1 for before
7
+ // https://dom.spec.whatwg.org/#concept-range-bp-after
8
+ function compareBoundaryPointsPosition(bpA, bpB) {
9
+ const { node: nodeA, offset: offsetA } = bpA;
10
+ const { node: nodeB, offset: offsetB } = bpB;
11
+
12
+ if (nodeRoot(nodeA) !== nodeRoot(nodeB)) {
13
+ throw new Error(`Internal Error: Boundary points should have the same root!`);
14
+ }
15
+
16
+ if (nodeA === nodeB) {
17
+ if (offsetA === offsetB) {
18
+ return 0;
19
+ } else if (offsetA < offsetB) {
20
+ return -1;
21
+ }
22
+
23
+ return 1;
24
+ }
25
+
26
+ if (isFollowing(nodeA, nodeB)) {
27
+ return compareBoundaryPointsPosition(bpB, bpA) === -1 ? 1 : -1;
28
+ }
29
+
30
+ if (isInclusiveAncestor(nodeA, nodeB)) {
31
+ let child = nodeB;
32
+
33
+ while (domSymbolTree.parent(child) !== nodeA) {
34
+ child = domSymbolTree.parent(child);
35
+ }
36
+
37
+ if (domSymbolTree.index(child) < offsetA) {
38
+ return 1;
39
+ }
40
+ }
41
+
42
+ return -1;
43
+ }
44
+
45
+ module.exports = {
46
+ compareBoundaryPointsPosition
47
+ };
node_modules/jsdom/lib/jsdom/living/selection/Selection-impl.js ADDED
@@ -0,0 +1,358 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "use strict";
2
+
3
+ const DOMException = require("../../../generated/idl/DOMException");
4
+
5
+ const NODE_TYPE = require("../node-type");
6
+ const { nodeLength, nodeRoot } = require("../helpers/node");
7
+ const { domSymbolTree } = require("../helpers/internal-constants");
8
+ const { compareBoundaryPointsPosition } = require("../range/boundary-point");
9
+
10
+ const { setBoundaryPointStart, setBoundaryPointEnd } = require("../range/Range-impl");
11
+
12
+ const Range = require("../../../generated/idl/Range");
13
+ const { implForWrapper } = require("../../../generated/idl/utils");
14
+ const { fireAnEvent } = require("../helpers/events");
15
+
16
+ // https://w3c.github.io/selection-api/#dfn-direction
17
+ const SELECTION_DIRECTION = {
18
+ FORWARDS: 1,
19
+ BACKWARDS: -1,
20
+ DIRECTIONLESS: 0
21
+ };
22
+
23
+ // https://w3c.github.io/selection-api/#dom-selection
24
+ class SelectionImpl {
25
+ constructor(globalObject) {
26
+ this._range = null;
27
+ this._direction = SELECTION_DIRECTION.DIRECTIONLESS;
28
+
29
+ this._globalObject = globalObject;
30
+ }
31
+
32
+ // https://w3c.github.io/selection-api/#dom-selection-anchornode
33
+ get anchorNode() {
34
+ const anchor = this._anchor;
35
+ return anchor ? anchor.node : null;
36
+ }
37
+
38
+ // https://w3c.github.io/selection-api/#dom-selection-anchoroffset
39
+ get anchorOffset() {
40
+ const anchor = this._anchor;
41
+ return anchor ? anchor.offset : 0;
42
+ }
43
+
44
+ // https://w3c.github.io/selection-api/#dom-selection-focusnode
45
+ get focusNode() {
46
+ const focus = this._focus;
47
+ return focus ? focus.node : null;
48
+ }
49
+
50
+ // https://w3c.github.io/selection-api/#dom-selection-focusoffset
51
+ get focusOffset() {
52
+ const focus = this._focus;
53
+ return focus ? focus.offset : 0;
54
+ }
55
+
56
+ // https://w3c.github.io/selection-api/#dom-selection-iscollapsed
57
+ get isCollapsed() {
58
+ return this._range === null || this._range.collapsed;
59
+ }
60
+
61
+ // https://w3c.github.io/selection-api/#dom-selection-rangecount
62
+ get rangeCount() {
63
+ return this._isEmpty() ? 0 : 1;
64
+ }
65
+
66
+ // https://w3c.github.io/selection-api/#dom-selection-type
67
+ get type() {
68
+ if (this._isEmpty()) {
69
+ return "None";
70
+ } else if (this._range.collapsed) {
71
+ return "Caret";
72
+ }
73
+
74
+ return "Range";
75
+ }
76
+
77
+ // https://w3c.github.io/selection-api/#dom-selection-getrangeat
78
+ getRangeAt(index) {
79
+ if (index !== 0 || this._isEmpty()) {
80
+ throw DOMException.create(this._globalObject, ["Invalid range index.", "IndexSizeError"]);
81
+ }
82
+
83
+ return this._range;
84
+ }
85
+
86
+ // https://w3c.github.io/selection-api/#dom-selection-addrange
87
+ addRange(range) {
88
+ if (range._root === implForWrapper(this._globalObject._document) && this.rangeCount === 0) {
89
+ this._associateRange(range);
90
+ }
91
+ }
92
+
93
+ // https://w3c.github.io/selection-api/#dom-selection-removerange
94
+ removeRange(range) {
95
+ if (range !== this._range) {
96
+ throw DOMException.create(this._globalObject, ["Invalid range.", "NotFoundError"]);
97
+ }
98
+
99
+ this._associateRange(null);
100
+ }
101
+
102
+ // https://w3c.github.io/selection-api/#dom-selection-removeallranges
103
+ removeAllRanges() {
104
+ this._associateRange(null);
105
+ }
106
+
107
+ // https://w3c.github.io/selection-api/#dom-selection-empty
108
+ empty() {
109
+ this.removeAllRanges();
110
+ }
111
+
112
+ // https://w3c.github.io/selection-api/#dom-selection-collapse
113
+ collapse(node, offset) {
114
+ if (node === null) {
115
+ this.removeAllRanges();
116
+ return;
117
+ }
118
+
119
+ if (node.nodeType === NODE_TYPE.DOCUMENT_TYPE_NODE) {
120
+ throw DOMException.create(this._globalObject, [
121
+ "DocumentType Node can't be used as boundary point.",
122
+ "InvalidNodeTypeError"
123
+ ]);
124
+ }
125
+
126
+ if (offset > nodeLength(node)) {
127
+ throw DOMException.create(this._globalObject, ["Invalid range index.", "IndexSizeError"]);
128
+ }
129
+
130
+ if (nodeRoot(node) !== implForWrapper(this._globalObject._document)) {
131
+ return;
132
+ }
133
+
134
+ const newRange = Range.createImpl(this._globalObject, [], {
135
+ start: { node, offset: 0 },
136
+ end: { node, offset: 0 }
137
+ });
138
+
139
+ setBoundaryPointStart(newRange, node, offset);
140
+ setBoundaryPointEnd(newRange, node, offset);
141
+
142
+ this._associateRange(newRange);
143
+ }
144
+
145
+ // https://w3c.github.io/selection-api/#dom-selection-setposition
146
+ setPosition(node, offset) {
147
+ this.collapse(node, offset);
148
+ }
149
+
150
+ // https://w3c.github.io/selection-api/#dom-selection-collapsetostart
151
+ collapseToStart() {
152
+ if (this._isEmpty()) {
153
+ throw DOMException.create(this._globalObject, ["There is no selection to collapse.", "InvalidStateError"]);
154
+ }
155
+
156
+ const { node, offset } = this._range._start;
157
+ const newRange = Range.createImpl(this._globalObject, [], {
158
+ start: { node, offset },
159
+ end: { node, offset }
160
+ });
161
+
162
+ this._associateRange(newRange);
163
+ }
164
+
165
+ // https://w3c.github.io/selection-api/#dom-selection-collapsetoend
166
+ collapseToEnd() {
167
+ if (this._isEmpty()) {
168
+ throw DOMException.create(this._globalObject, ["There is no selection to collapse.", "InvalidStateError"]);
169
+ }
170
+
171
+ const { node, offset } = this._range._end;
172
+ const newRange = Range.createImpl(this._globalObject, [], {
173
+ start: { node, offset },
174
+ end: { node, offset }
175
+ });
176
+
177
+ this._associateRange(newRange);
178
+ }
179
+
180
+ // https://w3c.github.io/selection-api/#dom-selection-extend
181
+ extend(node, offset) {
182
+ if (nodeRoot(node) !== implForWrapper(this._globalObject._document)) {
183
+ return;
184
+ }
185
+
186
+ if (this._isEmpty()) {
187
+ throw DOMException.create(this._globalObject, ["There is no selection to extend.", "InvalidStateError"]);
188
+ }
189
+
190
+ const { _anchor: oldAnchor } = this;
191
+ const newFocus = { node, offset };
192
+
193
+ const newRange = Range.createImpl(this._globalObject, [], {
194
+ start: { node, offset: 0 },
195
+ end: { node, offset: 0 }
196
+ });
197
+
198
+ if (nodeRoot(node) !== this._range._root) {
199
+ setBoundaryPointStart(newRange, newFocus.node, newFocus.offset);
200
+ setBoundaryPointEnd(newRange, newFocus.node, newFocus.offset);
201
+ } else if (compareBoundaryPointsPosition(oldAnchor, newFocus) <= 0) {
202
+ setBoundaryPointStart(newRange, oldAnchor.node, oldAnchor.offset);
203
+ setBoundaryPointEnd(newRange, newFocus.node, newFocus.offset);
204
+ } else {
205
+ setBoundaryPointStart(newRange, newFocus.node, newFocus.offset);
206
+ setBoundaryPointEnd(newRange, oldAnchor.node, oldAnchor.offset);
207
+ }
208
+
209
+ this._associateRange(newRange);
210
+
211
+ this._direction = compareBoundaryPointsPosition(newFocus, oldAnchor) === -1 ?
212
+ SELECTION_DIRECTION.BACKWARDS :
213
+ SELECTION_DIRECTION.FORWARDS;
214
+ }
215
+
216
+ // https://w3c.github.io/selection-api/#dom-selection-setbaseandextent
217
+ setBaseAndExtent(anchorNode, anchorOffset, focusNode, focusOffset) {
218
+ if (anchorOffset > nodeLength(anchorNode) || focusOffset > nodeLength(focusNode)) {
219
+ throw DOMException.create(this._globalObject, ["Invalid anchor or focus offset.", "IndexSizeError"]);
220
+ }
221
+
222
+ const document = implForWrapper(this._globalObject._document);
223
+ if (document !== nodeRoot(anchorNode) || document !== nodeRoot(focusNode)) {
224
+ return;
225
+ }
226
+
227
+ const anchor = { node: anchorNode, offset: anchorOffset };
228
+ const focus = { node: focusNode, offset: focusOffset };
229
+
230
+ let newRange;
231
+ if (compareBoundaryPointsPosition(anchor, focus) === -1) {
232
+ newRange = Range.createImpl(this._globalObject, [], {
233
+ start: { node: anchor.node, offset: anchor.offset },
234
+ end: { node: focus.node, offset: focus.offset }
235
+ });
236
+ } else {
237
+ newRange = Range.createImpl(this._globalObject, [], {
238
+ start: { node: focus.node, offset: focus.offset },
239
+ end: { node: anchor.node, offset: anchor.offset }
240
+ });
241
+ }
242
+
243
+ this._associateRange(newRange);
244
+
245
+ this._direction = compareBoundaryPointsPosition(focus, anchor) === -1 ?
246
+ SELECTION_DIRECTION.BACKWARDS :
247
+ SELECTION_DIRECTION.FORWARDS;
248
+ }
249
+
250
+ // https://w3c.github.io/selection-api/#dom-selection-selectallchildren
251
+ selectAllChildren(node) {
252
+ if (node.nodeType === NODE_TYPE.DOCUMENT_TYPE_NODE) {
253
+ throw DOMException.create(this._globalObject, [
254
+ "DocumentType Node can't be used as boundary point.",
255
+ "InvalidNodeTypeError"
256
+ ]);
257
+ }
258
+
259
+ const document = implForWrapper(this._globalObject._document);
260
+ if (document !== nodeRoot(node)) {
261
+ return;
262
+ }
263
+
264
+ const length = domSymbolTree.childrenCount(node);
265
+
266
+ const newRange = Range.createImpl(this._globalObject, [], {
267
+ start: { node, offset: 0 },
268
+ end: { node, offset: 0 }
269
+ });
270
+
271
+ setBoundaryPointStart(newRange, node, 0);
272
+ setBoundaryPointEnd(newRange, node, length);
273
+
274
+ this._associateRange(newRange);
275
+ }
276
+
277
+ // https://w3c.github.io/selection-api/#dom-selection-deletefromdocument
278
+ deleteFromDocument() {
279
+ if (!this._isEmpty()) {
280
+ this._range.deleteContents();
281
+ }
282
+ }
283
+
284
+ // https://w3c.github.io/selection-api/#dom-selection-containsnode
285
+ containsNode(node, allowPartialContainment) {
286
+ if (this._isEmpty() || nodeRoot(node) !== implForWrapper(this._globalObject._document)) {
287
+ return false;
288
+ }
289
+
290
+ const { _start, _end } = this._range;
291
+
292
+ const startIsBeforeNode = compareBoundaryPointsPosition(_start, { node, offset: 0 }) === -1;
293
+ const endIsAfterNode = compareBoundaryPointsPosition(_end, { node, offset: nodeLength(node) }) === 1;
294
+
295
+ return allowPartialContainment ?
296
+ startIsBeforeNode || endIsAfterNode :
297
+ startIsBeforeNode && endIsAfterNode;
298
+ }
299
+
300
+ // https://w3c.github.io/selection-api/#dom-selection-stringifier
301
+ toString() {
302
+ return this._range ? this._range.toString() : "";
303
+ }
304
+
305
+ // https://w3c.github.io/selection-api/#dfn-empty
306
+ _isEmpty() {
307
+ return this._range === null;
308
+ }
309
+
310
+ // https://w3c.github.io/selection-api/#dfn-anchor
311
+ get _anchor() {
312
+ if (!this._range) {
313
+ return null;
314
+ }
315
+
316
+ return this._direction === SELECTION_DIRECTION.FORWARDS ?
317
+ this._range._start :
318
+ this._range._end;
319
+ }
320
+
321
+ // https://w3c.github.io/selection-api/#dfn-focus
322
+ get _focus() {
323
+ if (!this._range) {
324
+ return null;
325
+ }
326
+
327
+ return this._direction === SELECTION_DIRECTION.FORWARDS ?
328
+ this._range._end :
329
+ this._range._start;
330
+ }
331
+
332
+ _associateRange(newRange) {
333
+ const didSelectionChange = this._range !== newRange &&
334
+ (
335
+ // Change from/to null selection
336
+ newRange === null ||
337
+ this._range === null ||
338
+ // Change of selection range
339
+ compareBoundaryPointsPosition(newRange._start, this._range._start) !== 0 ||
340
+ compareBoundaryPointsPosition(newRange._end, this._range._end) !== 0
341
+ );
342
+ this._range = newRange;
343
+ this._direction = newRange === null ? SELECTION_DIRECTION.DIRECTIONLESS : SELECTION_DIRECTION.FORWARDS;
344
+
345
+ // https://w3c.github.io/selection-api/#selectionchange-event
346
+ if (didSelectionChange) {
347
+ // Fire the event asynchronously, as it's done in the browser
348
+ const document = this._globalObject._document;
349
+ setTimeout(() => {
350
+ fireAnEvent("selectionchange", implForWrapper(document));
351
+ }, 0);
352
+ }
353
+ }
354
+ }
355
+
356
+ module.exports = {
357
+ implementation: SelectionImpl
358
+ };
node_modules/jsdom/lib/jsdom/living/svg/SVGAnimatedPreserveAspectRatio-impl.js ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "use strict";
2
+
3
+ const SVGPreserveAspectRatio = require("../../../generated/idl/SVGPreserveAspectRatio");
4
+
5
+ class SVGAnimatedPreserveAspectRatioImpl {
6
+ constructor(globalObject, args, privateData) {
7
+ this._globalObject = globalObject;
8
+ this._element = privateData.element;
9
+ }
10
+
11
+ get baseVal() {
12
+ return SVGPreserveAspectRatio.createImpl(this._globalObject, [], {
13
+ element: this._element
14
+ });
15
+ }
16
+
17
+ get animVal() {
18
+ return SVGPreserveAspectRatio.createImpl(this._globalObject, [], {
19
+ element: this._element
20
+ });
21
+ }
22
+ }
23
+
24
+ exports.implementation = SVGAnimatedPreserveAspectRatioImpl;
node_modules/jsdom/lib/jsdom/living/svg/SVGAnimatedRect-impl.js ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "use strict";
2
+
3
+ const SVGRect = require("../../../generated/idl/SVGRect");
4
+
5
+ // https://drafts.csswg.org/css-syntax/#number-token-diagram
6
+ const numberRe = /^[+-]?(?:\d*\.)?\d+(?:[eE][+-]?\d+)?/;
7
+
8
+ // https://svgwg.org/svg2-draft/coords.html#ViewBoxAttribute
9
+ function parseViewBox(str) {
10
+ // Use a do-while "loop" as JavaScript `goto end`.
11
+ // eslint-disable-next-line no-unreachable-loop
12
+ do {
13
+ // When the attribute does not exist.
14
+ if (typeof str !== "string") {
15
+ break;
16
+ }
17
+
18
+ let i = 0;
19
+ skipSpace();
20
+ const xStr = matchNumber();
21
+ if (!xStr) {
22
+ break;
23
+ }
24
+ if (!skipDelimiter()) {
25
+ break;
26
+ }
27
+ const yStr = matchNumber();
28
+ if (!yStr) {
29
+ break;
30
+ }
31
+ if (!skipDelimiter()) {
32
+ break;
33
+ }
34
+ const widthStr = matchNumber();
35
+ if (!widthStr) {
36
+ break;
37
+ }
38
+ if (!skipDelimiter()) {
39
+ break;
40
+ }
41
+ const heightStr = matchNumber();
42
+ if (!heightStr) {
43
+ break;
44
+ }
45
+ // Test for trailing junk.
46
+ skipSpace();
47
+ if (i < str.length) {
48
+ break;
49
+ }
50
+
51
+ // A negative value for <width> or <height> is an error and invalidates the 'viewBox' attribute.
52
+ const width = Number(widthStr);
53
+ if (width < 0) {
54
+ break;
55
+ }
56
+ const height = Number(heightStr);
57
+ if (height < 0) {
58
+ break;
59
+ }
60
+
61
+ return {
62
+ x: Number(xStr),
63
+ y: Number(yStr),
64
+ width,
65
+ height
66
+ };
67
+
68
+ function skipSpace() {
69
+ while (i < str.length && str[i] === " ") {
70
+ i += 1;
71
+ }
72
+ }
73
+
74
+ function matchNumber() {
75
+ const numMatch = numberRe.exec(str.slice(i));
76
+ if (!numMatch) {
77
+ return undefined;
78
+ }
79
+ i += numMatch[0].length;
80
+ return numMatch[0];
81
+ }
82
+
83
+ function skipDelimiter() {
84
+ const start = i;
85
+ skipSpace();
86
+ if (i < str.length && str[i] === ",") {
87
+ i += 1;
88
+ }
89
+ skipSpace();
90
+ return i > start;
91
+ }
92
+ } while (false);
93
+
94
+ return { x: 0, y: 0, width: 0, height: 0 };
95
+ }
96
+
97
+ class SVGAnimatedRectImpl {
98
+ constructor(globalObject, args, privateData) {
99
+ this._globalObject = globalObject;
100
+ this._element = privateData.element;
101
+ this._attribute = privateData.attribute;
102
+ }
103
+
104
+ get baseVal() {
105
+ return SVGRect.createImpl(this._globalObject, [], {
106
+ reflectedElement: this._element,
107
+ reflectedAttribute: this._attribute,
108
+ parser: parseViewBox
109
+ });
110
+ }
111
+
112
+ get animVal() {
113
+ return SVGRect.createImpl(this._globalObject, [], {
114
+ reflectedElement: this._element,
115
+ reflectedAttribute: this._attribute,
116
+ parser: parseViewBox,
117
+ readOnly: true
118
+ });
119
+ }
120
+ }
121
+
122
+ exports.implementation = SVGAnimatedRectImpl;
node_modules/jsdom/lib/jsdom/living/svg/SVGAnimatedString-impl.js ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "use strict";
2
+
3
+ class SVGAnimatedStringImpl {
4
+ constructor(globalObject, args, privateData) {
5
+ this._element = privateData.element;
6
+ this._attribute = privateData.attribute;
7
+
8
+ // These three can be undefined.
9
+ this._attributeDeprecated = privateData.attributeDeprecated;
10
+ this._attributeDeprecatedNamespace = privateData.attributeDeprecatedNamespace;
11
+ this._initialValue = privateData.initialValue;
12
+ }
13
+
14
+ get baseVal() {
15
+ if (!this._element.hasAttributeNS(null, this._attribute)) {
16
+ if (this._attributeDeprecated !== undefined &&
17
+ this._element.hasAttributeNS(this._attributeDeprecatedNamespace, this._attributeDeprecated)) {
18
+ return this._element.getAttributeNS(this._attributeDeprecatedNamespace, this._attributeDeprecated);
19
+ } else if (this._initialValue !== undefined) {
20
+ return this._initialValue;
21
+ }
22
+ return "";
23
+ }
24
+ return this._element.getAttributeNS(null, this._attribute);
25
+ }
26
+
27
+ set baseVal(base) {
28
+ if (!this._element.hasAttributeNS(null, this._attribute) &&
29
+ this._attributeDeprecated !== undefined &&
30
+ this._element.hasAttributeNS(null, this._attributeDeprecated)) {
31
+ this._element.setAttributeNS(null, this._attributeDeprecated, base);
32
+ } else {
33
+ this._element.setAttributeNS(null, this._attribute, base);
34
+ }
35
+ }
36
+
37
+ get animVal() {
38
+ return this.baseVal;
39
+ }
40
+ }
41
+
42
+ exports.implementation = SVGAnimatedStringImpl;
node_modules/jsdom/lib/jsdom/living/svg/SVGListBase.js ADDED
@@ -0,0 +1,195 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "use strict";
2
+
3
+ const DOMException = require("../../../generated/idl/DOMException");
4
+ const idlUtils = require("../../../generated/idl/utils");
5
+ const { attach, detach } = require("../helpers/svg/basic-types");
6
+
7
+ // https://svgwg.org/svg2-draft/types.html#ListInterfaces
8
+
9
+ // Child classes must implement _reserialize()
10
+ class List {
11
+ _initList({
12
+ element,
13
+ attribute,
14
+ readOnly = false
15
+ }) {
16
+ this._element = element;
17
+ this._attribute = attribute;
18
+ this._attributeRegistryEntry = element.constructor.attributeRegistry.get(attribute);
19
+ this._readOnly = readOnly;
20
+ this._list = [];
21
+ this._version = -1;
22
+ }
23
+
24
+ get _needsResync() {
25
+ return this._version < this._element._version;
26
+ }
27
+
28
+ _synchronize() {
29
+ if (!this._needsResync) {
30
+ return;
31
+ }
32
+ let value = [];
33
+ if (this._element.hasAttributeNS(null, this._attribute)) {
34
+ value = this._attributeRegistryEntry.getValue(this._element.getAttributeNS(null, this._attribute));
35
+ }
36
+ if (value.length === 0 && this._attributeRegistryEntry.initialValue !== undefined) {
37
+ value = this._attributeRegistryEntry.getValue(this._attributeRegistryEntry.initialValue);
38
+ }
39
+ // TODO: support non-DOMString lists.
40
+ this._list = value;
41
+ this._version = this._element._version;
42
+ }
43
+
44
+ _reserialize() {
45
+ const elements = this._list;
46
+ this._element.setAttributeNS(null, this._attribute, this._attributeRegistryEntry.serialize(elements));
47
+ // Prevent ping-ponging back and forth between _reserialize() and _synchronize().
48
+ this._version = this._element._version;
49
+ }
50
+
51
+ [idlUtils.supportsPropertyIndex](index) {
52
+ this._synchronize();
53
+ return index >= 0 && index < this.length;
54
+ }
55
+
56
+ get [idlUtils.supportedPropertyIndices]() {
57
+ this._synchronize();
58
+ return this._list.keys();
59
+ }
60
+
61
+ get length() {
62
+ this._synchronize();
63
+ return this._list.length;
64
+ }
65
+
66
+ get numberOfItems() {
67
+ this._synchronize();
68
+ return this._list.length;
69
+ }
70
+
71
+ clear() {
72
+ this._synchronize();
73
+ if (this._readOnly) {
74
+ throw DOMException.create(this._globalObject, [
75
+ "Attempting to modify a read-only list",
76
+ "NoModificationAllowedError"
77
+ ]);
78
+ }
79
+ for (const item of this._list) {
80
+ detach(item);
81
+ }
82
+ this._list.length = 0;
83
+ this._reserialize();
84
+ }
85
+
86
+ initialize(newItem) {
87
+ this._synchronize();
88
+ if (this._readOnly) {
89
+ throw DOMException.create(this._globalObject, [
90
+ "Attempting to modify a read-only list",
91
+ "NoModificationAllowedError"
92
+ ]);
93
+ }
94
+ for (const item of this._list) {
95
+ detach(item);
96
+ }
97
+ this._list.length = 0;
98
+ // TODO: clone non-DOMString list elements.
99
+ attach(newItem, this);
100
+ this._list.push(newItem);
101
+ this._reserialize();
102
+ }
103
+
104
+ getItem(index) {
105
+ this._synchronize();
106
+ if (index >= this._list.length) {
107
+ throw DOMException.create(this._globalObject, [
108
+ `The index provided (${index}) is greater than or equal to the maximum bound (${this._list.length}).`,
109
+ "IndexSizeError"
110
+ ]);
111
+ }
112
+ return this._list[index];
113
+ }
114
+
115
+ insertItemBefore(newItem, index) {
116
+ this._synchronize();
117
+ if (this._readOnly) {
118
+ throw DOMException.create(this._globalObject, [
119
+ "Attempting to modify a read-only list",
120
+ "NoModificationAllowedError"
121
+ ]);
122
+ }
123
+ // TODO: clone non-DOMString list elements.
124
+ if (index > this._list.length) {
125
+ index = this._list.length;
126
+ }
127
+ this._list.splice(index, 0, newItem);
128
+ attach(newItem, this);
129
+ this._reserialize();
130
+ return newItem;
131
+ }
132
+
133
+ replaceItem(newItem, index) {
134
+ this._synchronize();
135
+ if (this._readOnly) {
136
+ throw DOMException.create(this._globalObject, [
137
+ "Attempting to modify a read-only list",
138
+ "NoModificationAllowedError"
139
+ ]);
140
+ }
141
+ if (index >= this._list.length) {
142
+ throw DOMException.create(this._globalObject, [
143
+ `The index provided (${index}) is greater than or equal to the maximum bound (${this._list.length}).`,
144
+ "IndexSizeError"
145
+ ]);
146
+ }
147
+ // TODO: clone non-DOMString list elements.
148
+ detach(this._list[index]);
149
+ this._list[index] = newItem;
150
+ attach(newItem, this);
151
+ this._reserialize();
152
+ return newItem;
153
+ }
154
+
155
+ removeItem(index) {
156
+ this._synchronize();
157
+ if (this._readOnly) {
158
+ throw DOMException.create(this._globalObject, [
159
+ "Attempting to modify a read-only list",
160
+ "NoModificationAllowedError"
161
+ ]);
162
+ }
163
+ if (index >= this._list.length) {
164
+ throw DOMException.create(this._globalObject, [
165
+ `The index provided (${index}) is greater than or equal to the maximum bound (${this._list.length}).`,
166
+ "IndexSizeError"
167
+ ]);
168
+ }
169
+ const item = this._list[index];
170
+ detach(item);
171
+ this._list.splice(index, 1);
172
+ this._reserialize();
173
+ return item;
174
+ }
175
+
176
+ appendItem(newItem) {
177
+ this._synchronize();
178
+ // TODO: clone non-DOMString list elements.
179
+ this._list.push(newItem);
180
+ attach(newItem, this);
181
+ this._reserialize();
182
+ return newItem;
183
+ }
184
+
185
+ [idlUtils.indexedSetNew](index, value) {
186
+ // Note: this will always throw a IndexSizeError.
187
+ this.replaceItem(value, index);
188
+ }
189
+
190
+ [idlUtils.indexedSetExisting](index, value) {
191
+ this.replaceItem(value, index);
192
+ }
193
+ }
194
+
195
+ module.exports = List;