@native-dom/runtime 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -0
- package/README.md +44 -0
- package/dist/attributes.d.ts +20 -0
- package/dist/attributes.d.ts.map +1 -0
- package/dist/attributes.js +145 -0
- package/dist/attributes.js.map +1 -0
- package/dist/css.d.ts +139 -0
- package/dist/css.d.ts.map +1 -0
- package/dist/css.js +573 -0
- package/dist/css.js.map +1 -0
- package/dist/custom-elements.d.ts +22 -0
- package/dist/custom-elements.d.ts.map +1 -0
- package/dist/custom-elements.js +62 -0
- package/dist/custom-elements.js.map +1 -0
- package/dist/errors.d.ts +4 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +7 -0
- package/dist/errors.js.map +1 -0
- package/dist/event-init.d.ts +93 -0
- package/dist/event-init.d.ts.map +1 -0
- package/dist/event-init.js +2 -0
- package/dist/event-init.js.map +1 -0
- package/dist/events.d.ts +164 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +470 -0
- package/dist/events.js.map +1 -0
- package/dist/geometry.d.ts +46 -0
- package/dist/geometry.d.ts.map +1 -0
- package/dist/geometry.js +73 -0
- package/dist/geometry.js.map +1 -0
- package/dist/history.d.ts +16 -0
- package/dist/history.d.ts.map +1 -0
- package/dist/history.js +64 -0
- package/dist/history.js.map +1 -0
- package/dist/index.d.ts +824 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3685 -0
- package/dist/index.js.map +1 -0
- package/dist/observers.d.ts +49 -0
- package/dist/observers.d.ts.map +1 -0
- package/dist/observers.js +59 -0
- package/dist/observers.js.map +1 -0
- package/dist/platform.d.ts +77 -0
- package/dist/platform.d.ts.map +1 -0
- package/dist/platform.js +216 -0
- package/dist/platform.js.map +1 -0
- package/dist/stats.d.ts +33 -0
- package/dist/stats.d.ts.map +1 -0
- package/dist/stats.js +105 -0
- package/dist/stats.js.map +1 -0
- package/package.json +51 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,3685 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import { createDataset, DOMTokenList } from "./attributes.js";
|
|
3
|
+
import { CSSMediaRule, CSSRule, CSSStyleDeclaration, CSSStyleRule, CSSStyleSheet } from "./css.js";
|
|
4
|
+
import { CustomElementRegistry } from "./custom-elements.js";
|
|
5
|
+
import { DOMException } from "./errors.js";
|
|
6
|
+
import { ClipboardEvent, CustomEvent, Event, EventTarget, FocusEvent, InputEvent, KeyboardEvent, MediaQueryList, MediaQueryListEvent, MouseEvent, PointerEvent, PopStateEvent, SubmitEvent, Touch, TouchEvent, UIEvent } from "./events.js";
|
|
7
|
+
import { DOMRect, DOMRectReadOnly, ValidityState } from "./geometry.js";
|
|
8
|
+
import { History } from "./history.js";
|
|
9
|
+
import { IntersectionObserver, IntersectionObserverEntry, ResizeObserver } from "./observers.js";
|
|
10
|
+
import { getRuntimeStats, prepareNativeDocument, recordNativeCall, recordOperation, recordWrapperCreated, resetRuntimeStats, runtimeStats, setRuntimeStatsEnabled } from "./stats.js";
|
|
11
|
+
import { DataTransfer, DataTransferItemList, FileList, Location, Navigator, Screen, ScreenOrientation, Storage, URL } from "./platform.js";
|
|
12
|
+
export { ClipboardEvent, CSSMediaRule, CSSRule, CSSStyleDeclaration, CSSStyleRule, CSSStyleSheet, CustomEvent, CustomElementRegistry, DataTransfer, DataTransferItemList, DOMException, DOMTokenList, DOMRect, DOMRectReadOnly, Event, EventTarget, FileList, FocusEvent, getRuntimeStats, History, InputEvent, IntersectionObserver, IntersectionObserverEntry, KeyboardEvent, Location, MediaQueryList, MediaQueryListEvent, MouseEvent, Navigator, PointerEvent, PopStateEvent, resetRuntimeStats, ResizeObserver, Screen, ScreenOrientation, setRuntimeStatsEnabled, Storage, SubmitEvent, Touch, TouchEvent, UIEvent, ValidityState, URL, };
|
|
13
|
+
const require = createRequire(import.meta.url);
|
|
14
|
+
const nativeCore = require("@native-dom/native-core");
|
|
15
|
+
const { parseHtmlDocumentNative } = nativeCore;
|
|
16
|
+
const hostSetTimeout = globalThis.setTimeout.bind(globalThis);
|
|
17
|
+
const hostClearTimeout = globalThis.clearTimeout.bind(globalThis);
|
|
18
|
+
const hostSetInterval = globalThis.setInterval.bind(globalThis);
|
|
19
|
+
const hostClearInterval = globalThis.clearInterval.bind(globalThis);
|
|
20
|
+
const hostQueueMicrotask = globalThis.queueMicrotask.bind(globalThis);
|
|
21
|
+
const HTML_NAMESPACE = "http://www.w3.org/1999/xhtml";
|
|
22
|
+
const SVG_NAMESPACE = "http://www.w3.org/2000/svg";
|
|
23
|
+
const MATHML_NAMESPACE = "http://www.w3.org/1998/Math/MathML";
|
|
24
|
+
export const NodeFilter = {
|
|
25
|
+
FILTER_ACCEPT: 1,
|
|
26
|
+
FILTER_REJECT: 2,
|
|
27
|
+
FILTER_SKIP: 3,
|
|
28
|
+
SHOW_ALL: 0xffffffff,
|
|
29
|
+
SHOW_ELEMENT: 0x1,
|
|
30
|
+
SHOW_ATTRIBUTE: 0x2,
|
|
31
|
+
SHOW_TEXT: 0x4,
|
|
32
|
+
SHOW_CDATA_SECTION: 0x8,
|
|
33
|
+
SHOW_ENTITY_REFERENCE: 0x10,
|
|
34
|
+
SHOW_ENTITY: 0x20,
|
|
35
|
+
SHOW_PROCESSING_INSTRUCTION: 0x40,
|
|
36
|
+
SHOW_COMMENT: 0x80,
|
|
37
|
+
SHOW_DOCUMENT: 0x100,
|
|
38
|
+
SHOW_DOCUMENT_TYPE: 0x200,
|
|
39
|
+
SHOW_DOCUMENT_FRAGMENT: 0x400,
|
|
40
|
+
SHOW_NOTATION: 0x800
|
|
41
|
+
};
|
|
42
|
+
export class Selection {
|
|
43
|
+
#ranges = [];
|
|
44
|
+
get rangeCount() {
|
|
45
|
+
return this.#ranges.length;
|
|
46
|
+
}
|
|
47
|
+
get anchorNode() {
|
|
48
|
+
return this.#ranges[0]?.startContainer ?? null;
|
|
49
|
+
}
|
|
50
|
+
get focusNode() {
|
|
51
|
+
return this.#ranges[0]?.endContainer ?? null;
|
|
52
|
+
}
|
|
53
|
+
get isCollapsed() {
|
|
54
|
+
return this.rangeCount === 0 || this.#ranges.every((range) => range.collapsed);
|
|
55
|
+
}
|
|
56
|
+
addRange(range) {
|
|
57
|
+
this.#ranges = [range];
|
|
58
|
+
}
|
|
59
|
+
removeAllRanges() {
|
|
60
|
+
this.#ranges = [];
|
|
61
|
+
}
|
|
62
|
+
getRangeAt(index) {
|
|
63
|
+
const range = this.#ranges[index];
|
|
64
|
+
if (!range) {
|
|
65
|
+
throw new DOMException("Selection range index is out of bounds", "IndexSizeError");
|
|
66
|
+
}
|
|
67
|
+
return range;
|
|
68
|
+
}
|
|
69
|
+
toString() {
|
|
70
|
+
return this.#ranges.map((range) => String(range)).join("");
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
export class FormData {
|
|
74
|
+
#entries = [];
|
|
75
|
+
constructor(form) {
|
|
76
|
+
if (!form) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
if (!(form instanceof HTMLElement) || form.localName !== "form") {
|
|
80
|
+
throw new TypeError("FormData constructor argument must be a form element");
|
|
81
|
+
}
|
|
82
|
+
for (const element of form.elements ?? []) {
|
|
83
|
+
const entry = formDataEntryFor(element);
|
|
84
|
+
if (entry) {
|
|
85
|
+
this.#entries.push(entry);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
append(name, value) {
|
|
90
|
+
this.#entries.push([String(name), String(value)]);
|
|
91
|
+
}
|
|
92
|
+
delete(name) {
|
|
93
|
+
const normalizedName = String(name);
|
|
94
|
+
for (let index = this.#entries.length - 1; index >= 0; index--) {
|
|
95
|
+
if (this.#entries[index][0] === normalizedName) {
|
|
96
|
+
this.#entries.splice(index, 1);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
get(name) {
|
|
101
|
+
return this.#entries.find(([entryName]) => entryName === String(name))?.[1] ?? null;
|
|
102
|
+
}
|
|
103
|
+
getAll(name) {
|
|
104
|
+
return this.#entries
|
|
105
|
+
.filter(([entryName]) => entryName === String(name))
|
|
106
|
+
.map(([, value]) => value);
|
|
107
|
+
}
|
|
108
|
+
has(name) {
|
|
109
|
+
return this.#entries.some(([entryName]) => entryName === String(name));
|
|
110
|
+
}
|
|
111
|
+
set(name, value) {
|
|
112
|
+
const normalizedName = String(name);
|
|
113
|
+
const firstIndex = this.#entries.findIndex(([entryName]) => entryName === normalizedName);
|
|
114
|
+
if (firstIndex === -1) {
|
|
115
|
+
this.append(normalizedName, value);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
this.#entries[firstIndex] = [normalizedName, String(value)];
|
|
119
|
+
for (let index = this.#entries.length - 1; index > firstIndex; index--) {
|
|
120
|
+
if (this.#entries[index][0] === normalizedName) {
|
|
121
|
+
this.#entries.splice(index, 1);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
forEach(callback, thisArg) {
|
|
126
|
+
for (const [name, value] of this.#entries) {
|
|
127
|
+
callback.call(thisArg, value, name, this);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
entries() {
|
|
131
|
+
return this.#entries[Symbol.iterator]();
|
|
132
|
+
}
|
|
133
|
+
keys() {
|
|
134
|
+
return this.#entries.map(([name]) => name)[Symbol.iterator]();
|
|
135
|
+
}
|
|
136
|
+
values() {
|
|
137
|
+
return this.#entries.map(([, value]) => value)[Symbol.iterator]();
|
|
138
|
+
}
|
|
139
|
+
[Symbol.iterator]() {
|
|
140
|
+
return this.entries();
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
export class Range {
|
|
144
|
+
static START_TO_START = 0;
|
|
145
|
+
static START_TO_END = 1;
|
|
146
|
+
static END_TO_END = 2;
|
|
147
|
+
static END_TO_START = 3;
|
|
148
|
+
START_TO_START = Range.START_TO_START;
|
|
149
|
+
START_TO_END = Range.START_TO_END;
|
|
150
|
+
END_TO_END = Range.END_TO_END;
|
|
151
|
+
END_TO_START = Range.END_TO_START;
|
|
152
|
+
startContainer;
|
|
153
|
+
startOffset = 0;
|
|
154
|
+
endContainer;
|
|
155
|
+
endOffset = 0;
|
|
156
|
+
#document;
|
|
157
|
+
constructor(document) {
|
|
158
|
+
this.#document = document;
|
|
159
|
+
this.startContainer = document;
|
|
160
|
+
this.endContainer = document;
|
|
161
|
+
}
|
|
162
|
+
get collapsed() {
|
|
163
|
+
return this.startContainer === this.endContainer && this.startOffset === this.endOffset;
|
|
164
|
+
}
|
|
165
|
+
get commonAncestorContainer() {
|
|
166
|
+
let current = this.startContainer;
|
|
167
|
+
while (current) {
|
|
168
|
+
if (current.contains(this.endContainer)) {
|
|
169
|
+
return current;
|
|
170
|
+
}
|
|
171
|
+
current = current.parentNode;
|
|
172
|
+
}
|
|
173
|
+
return this.#document;
|
|
174
|
+
}
|
|
175
|
+
setStart(node, offset) {
|
|
176
|
+
this.startContainer = node;
|
|
177
|
+
this.startOffset = offset;
|
|
178
|
+
}
|
|
179
|
+
setEnd(node, offset) {
|
|
180
|
+
this.endContainer = node;
|
|
181
|
+
this.endOffset = offset;
|
|
182
|
+
}
|
|
183
|
+
setStartBefore(node) {
|
|
184
|
+
const parent = node.parentNode;
|
|
185
|
+
if (!parent) {
|
|
186
|
+
throw new DOMException("Node has no parent.", "InvalidNodeTypeError");
|
|
187
|
+
}
|
|
188
|
+
this.setStart(parent, nodeIndex(node));
|
|
189
|
+
}
|
|
190
|
+
setStartAfter(node) {
|
|
191
|
+
const parent = node.parentNode;
|
|
192
|
+
if (!parent) {
|
|
193
|
+
throw new DOMException("Node has no parent.", "InvalidNodeTypeError");
|
|
194
|
+
}
|
|
195
|
+
this.setStart(parent, nodeIndex(node) + 1);
|
|
196
|
+
}
|
|
197
|
+
setEndBefore(node) {
|
|
198
|
+
const parent = node.parentNode;
|
|
199
|
+
if (!parent) {
|
|
200
|
+
throw new DOMException("Node has no parent.", "InvalidNodeTypeError");
|
|
201
|
+
}
|
|
202
|
+
this.setEnd(parent, nodeIndex(node));
|
|
203
|
+
}
|
|
204
|
+
setEndAfter(node) {
|
|
205
|
+
const parent = node.parentNode;
|
|
206
|
+
if (!parent) {
|
|
207
|
+
throw new DOMException("Node has no parent.", "InvalidNodeTypeError");
|
|
208
|
+
}
|
|
209
|
+
this.setEnd(parent, nodeIndex(node) + 1);
|
|
210
|
+
}
|
|
211
|
+
selectNode(node) {
|
|
212
|
+
const parent = node.parentNode;
|
|
213
|
+
if (!parent) {
|
|
214
|
+
throw new DOMException("Node has no parent.", "InvalidNodeTypeError");
|
|
215
|
+
}
|
|
216
|
+
const index = nodeIndex(node);
|
|
217
|
+
this.setStart(parent, index);
|
|
218
|
+
this.setEnd(parent, index + 1);
|
|
219
|
+
}
|
|
220
|
+
selectNodeContents(node) {
|
|
221
|
+
this.setStart(node, 0);
|
|
222
|
+
this.setEnd(node, rangeNodeLength(node));
|
|
223
|
+
}
|
|
224
|
+
collapse(toStart = false) {
|
|
225
|
+
if (toStart) {
|
|
226
|
+
this.setEnd(this.startContainer, this.startOffset);
|
|
227
|
+
}
|
|
228
|
+
else {
|
|
229
|
+
this.setStart(this.endContainer, this.endOffset);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
cloneRange() {
|
|
233
|
+
const range = new Range(this.#document);
|
|
234
|
+
range.setStart(this.startContainer, this.startOffset);
|
|
235
|
+
range.setEnd(this.endContainer, this.endOffset);
|
|
236
|
+
return range;
|
|
237
|
+
}
|
|
238
|
+
cloneContents() {
|
|
239
|
+
const fragment = this.#document.createDocumentFragment();
|
|
240
|
+
if (this.startContainer !== this.endContainer) {
|
|
241
|
+
return fragment;
|
|
242
|
+
}
|
|
243
|
+
if (this.startContainer.nodeType === Node.TEXT_NODE) {
|
|
244
|
+
fragment.appendChild(this.#document.createTextNode((this.startContainer.nodeValue ?? "").slice(this.startOffset, this.endOffset)));
|
|
245
|
+
return fragment;
|
|
246
|
+
}
|
|
247
|
+
const children = [...this.startContainer.childNodes].slice(this.startOffset, this.endOffset);
|
|
248
|
+
for (const child of children) {
|
|
249
|
+
fragment.appendChild(this.#document.importNode(child, true));
|
|
250
|
+
}
|
|
251
|
+
return fragment;
|
|
252
|
+
}
|
|
253
|
+
deleteContents() {
|
|
254
|
+
if (this.startContainer !== this.endContainer || this.startContainer.nodeType === Node.TEXT_NODE) {
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
const children = [...this.startContainer.childNodes].slice(this.startOffset, this.endOffset);
|
|
258
|
+
for (const child of children) {
|
|
259
|
+
this.startContainer.removeChild(child);
|
|
260
|
+
}
|
|
261
|
+
this.collapse(true);
|
|
262
|
+
}
|
|
263
|
+
insertNode(node) {
|
|
264
|
+
if (this.startContainer.nodeType === Node.TEXT_NODE) {
|
|
265
|
+
this.startContainer.parentNode?.insertBefore(node, this.startContainer);
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
this.startContainer.insertBefore(node, this.startContainer.childNodes.item(this.startOffset));
|
|
269
|
+
}
|
|
270
|
+
createContextualFragment(html) {
|
|
271
|
+
return fragmentFromHtml(this.#document, html);
|
|
272
|
+
}
|
|
273
|
+
detach() { }
|
|
274
|
+
toString() {
|
|
275
|
+
return this.cloneContents().textContent;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
function rangeNodeLength(node) {
|
|
279
|
+
return node.nodeType === Node.TEXT_NODE || node.nodeType === Node.COMMENT_NODE
|
|
280
|
+
? (node.nodeValue ?? "").length
|
|
281
|
+
: node.childNodes.length;
|
|
282
|
+
}
|
|
283
|
+
function nodeIndex(node) {
|
|
284
|
+
return node.parentNode ? [...node.parentNode.childNodes].indexOf(node) : -1;
|
|
285
|
+
}
|
|
286
|
+
export class Window extends EventTarget {
|
|
287
|
+
#animationFrameHandle = 0;
|
|
288
|
+
#animationFrames = new Map();
|
|
289
|
+
#timeouts = new Set();
|
|
290
|
+
#intervals = new Set();
|
|
291
|
+
#closed = false;
|
|
292
|
+
#selection = new Selection();
|
|
293
|
+
document;
|
|
294
|
+
Window = Window;
|
|
295
|
+
window = this;
|
|
296
|
+
self = this;
|
|
297
|
+
top = this;
|
|
298
|
+
parent = this;
|
|
299
|
+
location;
|
|
300
|
+
history;
|
|
301
|
+
Image;
|
|
302
|
+
navigator = new Navigator();
|
|
303
|
+
screen = new Screen();
|
|
304
|
+
localStorage = new Storage();
|
|
305
|
+
sessionStorage = new Storage();
|
|
306
|
+
URL = URL;
|
|
307
|
+
URLSearchParams = globalThis.URLSearchParams;
|
|
308
|
+
Blob = globalThis.Blob;
|
|
309
|
+
File = globalThis.File;
|
|
310
|
+
Headers = globalThis.Headers;
|
|
311
|
+
Request = globalThis.Request;
|
|
312
|
+
Response = globalThis.Response;
|
|
313
|
+
AbortController = globalThis.AbortController;
|
|
314
|
+
fetch = globalThis.fetch.bind(globalThis);
|
|
315
|
+
customElements = new CustomElementRegistry();
|
|
316
|
+
innerWidth = 1024;
|
|
317
|
+
innerHeight = 768;
|
|
318
|
+
outerWidth = 1024;
|
|
319
|
+
outerHeight = 768;
|
|
320
|
+
queueMicrotask = hostQueueMicrotask;
|
|
321
|
+
devicePixelRatio = 1;
|
|
322
|
+
FormData = FormData;
|
|
323
|
+
Storage = Storage;
|
|
324
|
+
Node = Node;
|
|
325
|
+
Element = Element;
|
|
326
|
+
HTMLElement = HTMLElement;
|
|
327
|
+
HTMLHtmlElement = HTMLHtmlElement;
|
|
328
|
+
HTMLBodyElement = HTMLBodyElement;
|
|
329
|
+
SVGElement = SVGElement;
|
|
330
|
+
MathMLElement = MathMLElement;
|
|
331
|
+
DocumentFragment = DocumentFragment;
|
|
332
|
+
ShadowRoot = ShadowRoot;
|
|
333
|
+
HTMLButtonElement = HTMLButtonElement;
|
|
334
|
+
HTMLCanvasElement = HTMLCanvasElement;
|
|
335
|
+
HTMLFormElement = HTMLFormElement;
|
|
336
|
+
HTMLIFrameElement = HTMLElement;
|
|
337
|
+
HTMLImageElement = HTMLImageElement;
|
|
338
|
+
HTMLInputElement = HTMLInputElement;
|
|
339
|
+
HTMLLinkElement = HTMLLinkElement;
|
|
340
|
+
HTMLOptionElement = HTMLOptionElement;
|
|
341
|
+
HTMLScriptElement = HTMLScriptElement;
|
|
342
|
+
HTMLSelectElement = HTMLSelectElement;
|
|
343
|
+
HTMLStyleElement = HTMLStyleElement;
|
|
344
|
+
HTMLTableCellElement = HTMLTableCellElement;
|
|
345
|
+
HTMLTableElement = HTMLTableElement;
|
|
346
|
+
HTMLTableRowElement = HTMLTableRowElement;
|
|
347
|
+
HTMLTableSectionElement = HTMLTableSectionElement;
|
|
348
|
+
HTMLTemplateElement = HTMLTemplateElement;
|
|
349
|
+
HTMLTextAreaElement = HTMLTextAreaElement;
|
|
350
|
+
HTMLCollection = NativeNodeList;
|
|
351
|
+
NodeList = NativeNodeList;
|
|
352
|
+
Document = Document;
|
|
353
|
+
Text = Text;
|
|
354
|
+
Comment = Comment;
|
|
355
|
+
DOMParser = DOMParser;
|
|
356
|
+
DocumentType = DocumentType;
|
|
357
|
+
DOMRect = DOMRect;
|
|
358
|
+
DOMRectReadOnly = DOMRectReadOnly;
|
|
359
|
+
EventTarget = EventTarget;
|
|
360
|
+
Event = Event;
|
|
361
|
+
CustomEvent = CustomEvent;
|
|
362
|
+
UIEvent = UIEvent;
|
|
363
|
+
MouseEvent = MouseEvent;
|
|
364
|
+
PointerEvent = PointerEvent;
|
|
365
|
+
KeyboardEvent = KeyboardEvent;
|
|
366
|
+
InputEvent = InputEvent;
|
|
367
|
+
FocusEvent = FocusEvent;
|
|
368
|
+
SubmitEvent = SubmitEvent;
|
|
369
|
+
PopStateEvent = PopStateEvent;
|
|
370
|
+
ClipboardEvent = ClipboardEvent;
|
|
371
|
+
Touch = Touch;
|
|
372
|
+
TouchEvent = TouchEvent;
|
|
373
|
+
ResizeObserver = ResizeObserver;
|
|
374
|
+
IntersectionObserver = IntersectionObserver;
|
|
375
|
+
IntersectionObserverEntry = IntersectionObserverEntry;
|
|
376
|
+
Selection = Selection;
|
|
377
|
+
DataTransfer = DataTransfer;
|
|
378
|
+
DataTransferItemList = DataTransferItemList;
|
|
379
|
+
FileList = FileList;
|
|
380
|
+
MutationObserver = MutationObserver;
|
|
381
|
+
DOMException = DOMException;
|
|
382
|
+
Range = Range;
|
|
383
|
+
TreeWalker = TreeWalker;
|
|
384
|
+
NodeIterator = NodeIterator;
|
|
385
|
+
ValidityState = ValidityState;
|
|
386
|
+
NodeFilter = NodeFilter;
|
|
387
|
+
Location = Location;
|
|
388
|
+
History = History;
|
|
389
|
+
Navigator = Navigator;
|
|
390
|
+
Screen = Screen;
|
|
391
|
+
ScreenOrientation = ScreenOrientation;
|
|
392
|
+
MediaQueryList = MediaQueryList;
|
|
393
|
+
MediaQueryListEvent = MediaQueryListEvent;
|
|
394
|
+
NamedNodeMap = NamedNodeMap;
|
|
395
|
+
XMLSerializer = XMLSerializer;
|
|
396
|
+
CSSStyleDeclaration = CSSStyleDeclaration;
|
|
397
|
+
CSSRule = CSSRule;
|
|
398
|
+
CSSStyleRule = CSSStyleRule;
|
|
399
|
+
CSSMediaRule = CSSMediaRule;
|
|
400
|
+
CSSStyleSheet = CSSStyleSheet;
|
|
401
|
+
CustomElementRegistry = CustomElementRegistry;
|
|
402
|
+
constructor(html = "", url = "about:blank") {
|
|
403
|
+
super();
|
|
404
|
+
this.location = new Location(url);
|
|
405
|
+
this.history = new History(this.location, this);
|
|
406
|
+
this.document = new Document(this, html);
|
|
407
|
+
this.Image = createImageConstructor(this.document);
|
|
408
|
+
}
|
|
409
|
+
setTimeout(handler, timeout, ...arguments_) {
|
|
410
|
+
const handle = hostSetTimeout(() => {
|
|
411
|
+
this.#timeouts.delete(handle);
|
|
412
|
+
if (this.#closed) {
|
|
413
|
+
return;
|
|
414
|
+
}
|
|
415
|
+
if (typeof handler === "function") {
|
|
416
|
+
handler(...arguments_);
|
|
417
|
+
}
|
|
418
|
+
else {
|
|
419
|
+
globalThis.Function(String(handler))();
|
|
420
|
+
}
|
|
421
|
+
}, timeout);
|
|
422
|
+
this.#timeouts.add(handle);
|
|
423
|
+
return handle;
|
|
424
|
+
}
|
|
425
|
+
clearTimeout(handle) {
|
|
426
|
+
if (handle === undefined) {
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
429
|
+
this.#timeouts.delete(handle);
|
|
430
|
+
hostClearTimeout(handle);
|
|
431
|
+
}
|
|
432
|
+
setInterval(handler, timeout, ...arguments_) {
|
|
433
|
+
const handle = hostSetInterval(() => {
|
|
434
|
+
if (this.#closed) {
|
|
435
|
+
return;
|
|
436
|
+
}
|
|
437
|
+
if (typeof handler === "function") {
|
|
438
|
+
handler(...arguments_);
|
|
439
|
+
}
|
|
440
|
+
else {
|
|
441
|
+
globalThis.Function(String(handler))();
|
|
442
|
+
}
|
|
443
|
+
}, timeout);
|
|
444
|
+
this.#intervals.add(handle);
|
|
445
|
+
return handle;
|
|
446
|
+
}
|
|
447
|
+
clearInterval(handle) {
|
|
448
|
+
if (handle === undefined) {
|
|
449
|
+
return;
|
|
450
|
+
}
|
|
451
|
+
this.#intervals.delete(handle);
|
|
452
|
+
hostClearInterval(handle);
|
|
453
|
+
}
|
|
454
|
+
getComputedStyle(element, _pseudoElement) {
|
|
455
|
+
const style = new CSSStyleDeclaration(element.getAttribute("style") ?? "");
|
|
456
|
+
if (element.hasAttribute("hidden")) {
|
|
457
|
+
style.display = "none";
|
|
458
|
+
}
|
|
459
|
+
if (!style.display) {
|
|
460
|
+
style.display = defaultDisplayFor(element.localName);
|
|
461
|
+
}
|
|
462
|
+
if (!style.visibility) {
|
|
463
|
+
style.visibility = inheritedVisibility(element);
|
|
464
|
+
}
|
|
465
|
+
return style;
|
|
466
|
+
}
|
|
467
|
+
requestAnimationFrame(callback) {
|
|
468
|
+
const id = ++this.#animationFrameHandle;
|
|
469
|
+
const handle = hostSetTimeout(() => {
|
|
470
|
+
this.#animationFrames.delete(id);
|
|
471
|
+
callback(Date.now());
|
|
472
|
+
}, 16);
|
|
473
|
+
this.#animationFrames.set(id, handle);
|
|
474
|
+
return id;
|
|
475
|
+
}
|
|
476
|
+
cancelAnimationFrame(id) {
|
|
477
|
+
const handle = this.#animationFrames.get(id);
|
|
478
|
+
if (handle) {
|
|
479
|
+
hostClearTimeout(handle);
|
|
480
|
+
this.#animationFrames.delete(id);
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
matchMedia(query) {
|
|
484
|
+
return new MediaQueryList(String(query), false);
|
|
485
|
+
}
|
|
486
|
+
getSelection() {
|
|
487
|
+
return this.#selection;
|
|
488
|
+
}
|
|
489
|
+
close() {
|
|
490
|
+
this.#closed = true;
|
|
491
|
+
for (const handle of this.#timeouts) {
|
|
492
|
+
hostClearTimeout(handle);
|
|
493
|
+
}
|
|
494
|
+
this.#timeouts.clear();
|
|
495
|
+
for (const handle of this.#intervals) {
|
|
496
|
+
hostClearInterval(handle);
|
|
497
|
+
}
|
|
498
|
+
this.#intervals.clear();
|
|
499
|
+
for (const handle of this.#animationFrames.values()) {
|
|
500
|
+
hostClearTimeout(handle);
|
|
501
|
+
}
|
|
502
|
+
this.#animationFrames.clear();
|
|
503
|
+
}
|
|
504
|
+
cancelAsync() {
|
|
505
|
+
this.close();
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
function inheritedVisibility(element) {
|
|
509
|
+
let current = element;
|
|
510
|
+
while (current) {
|
|
511
|
+
const visibility = new CSSStyleDeclaration(current.getAttribute("style") ?? "").visibility;
|
|
512
|
+
if (visibility) {
|
|
513
|
+
return visibility;
|
|
514
|
+
}
|
|
515
|
+
current = current.parentElement;
|
|
516
|
+
}
|
|
517
|
+
return "";
|
|
518
|
+
}
|
|
519
|
+
function defaultDisplayFor(localName) {
|
|
520
|
+
switch (localName) {
|
|
521
|
+
case "body":
|
|
522
|
+
case "div":
|
|
523
|
+
case "form":
|
|
524
|
+
case "main":
|
|
525
|
+
case "option":
|
|
526
|
+
case "p":
|
|
527
|
+
case "section":
|
|
528
|
+
return "block";
|
|
529
|
+
case "button":
|
|
530
|
+
case "input":
|
|
531
|
+
case "select":
|
|
532
|
+
case "textarea":
|
|
533
|
+
return "inline-block";
|
|
534
|
+
case "table":
|
|
535
|
+
return "table";
|
|
536
|
+
case "tbody":
|
|
537
|
+
return "table-row-group";
|
|
538
|
+
case "tr":
|
|
539
|
+
return "table-row";
|
|
540
|
+
case "th":
|
|
541
|
+
case "td":
|
|
542
|
+
return "table-cell";
|
|
543
|
+
default:
|
|
544
|
+
return "";
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
export class Node extends EventTarget {
|
|
548
|
+
static ELEMENT_NODE = 1;
|
|
549
|
+
static TEXT_NODE = 3;
|
|
550
|
+
static COMMENT_NODE = 8;
|
|
551
|
+
static DOCUMENT_NODE = 9;
|
|
552
|
+
static DOCUMENT_TYPE_NODE = 10;
|
|
553
|
+
static DOCUMENT_FRAGMENT_NODE = 11;
|
|
554
|
+
static DOCUMENT_POSITION_DISCONNECTED = 1;
|
|
555
|
+
static DOCUMENT_POSITION_PRECEDING = 2;
|
|
556
|
+
static DOCUMENT_POSITION_FOLLOWING = 4;
|
|
557
|
+
static DOCUMENT_POSITION_CONTAINS = 8;
|
|
558
|
+
static DOCUMENT_POSITION_CONTAINED_BY = 16;
|
|
559
|
+
static DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC = 32;
|
|
560
|
+
_document;
|
|
561
|
+
_id;
|
|
562
|
+
#nodeName;
|
|
563
|
+
#textContentCache = "";
|
|
564
|
+
#textContentCacheVersion = -1;
|
|
565
|
+
constructor(document, id, nodeName = null) {
|
|
566
|
+
super();
|
|
567
|
+
this._document = document;
|
|
568
|
+
this._id = id;
|
|
569
|
+
this.#nodeName = nodeName;
|
|
570
|
+
}
|
|
571
|
+
get nodeName() {
|
|
572
|
+
this.#nodeName ??= this._document._native.nodeName(this._id);
|
|
573
|
+
return this.#nodeName;
|
|
574
|
+
}
|
|
575
|
+
get nodeType() {
|
|
576
|
+
switch (this.nodeName) {
|
|
577
|
+
case "#document":
|
|
578
|
+
return 9;
|
|
579
|
+
case "#document-type":
|
|
580
|
+
return 10;
|
|
581
|
+
case "#document-fragment":
|
|
582
|
+
return 11;
|
|
583
|
+
case "#text":
|
|
584
|
+
return 3;
|
|
585
|
+
case "#comment":
|
|
586
|
+
return 8;
|
|
587
|
+
default:
|
|
588
|
+
return 1;
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
get nodeValue() {
|
|
592
|
+
return this._document._native.nodeValue(this._id);
|
|
593
|
+
}
|
|
594
|
+
set nodeValue(value) {
|
|
595
|
+
if (runtimeStats.enabled) {
|
|
596
|
+
recordOperation("nodeValueSet");
|
|
597
|
+
}
|
|
598
|
+
if (!hasMutationObservers()) {
|
|
599
|
+
this._document._native.setNodeValue(this._id, value ?? "");
|
|
600
|
+
if (this.nodeType === 3 || this.nodeType === 8) {
|
|
601
|
+
this._document._bumpMutationVersion();
|
|
602
|
+
}
|
|
603
|
+
return;
|
|
604
|
+
}
|
|
605
|
+
const oldValue = this.nodeValue;
|
|
606
|
+
this._document._native.setNodeValue(this._id, value ?? "");
|
|
607
|
+
if (this.nodeType === 3 || this.nodeType === 8) {
|
|
608
|
+
this._document._bumpMutationVersion();
|
|
609
|
+
notifyMutation({
|
|
610
|
+
type: "characterData",
|
|
611
|
+
target: this,
|
|
612
|
+
addedNodes: [],
|
|
613
|
+
removedNodes: [],
|
|
614
|
+
attributeName: null,
|
|
615
|
+
oldValue
|
|
616
|
+
});
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
get textContent() {
|
|
620
|
+
if (this.nodeType === 3 || this.nodeType === 8) {
|
|
621
|
+
return this.nodeValue ?? "";
|
|
622
|
+
}
|
|
623
|
+
const mutationVersion = this._document._mutationVersion();
|
|
624
|
+
if (this.#textContentCacheVersion === mutationVersion) {
|
|
625
|
+
return this.#textContentCache;
|
|
626
|
+
}
|
|
627
|
+
const value = this._document._native.textContent(this._id);
|
|
628
|
+
this.#textContentCache = value;
|
|
629
|
+
this.#textContentCacheVersion = mutationVersion;
|
|
630
|
+
return value;
|
|
631
|
+
}
|
|
632
|
+
set textContent(value) {
|
|
633
|
+
if (runtimeStats.enabled) {
|
|
634
|
+
recordOperation("textContentSet");
|
|
635
|
+
}
|
|
636
|
+
if (this.nodeType === 3 || this.nodeType === 8) {
|
|
637
|
+
if (!hasActiveMutationObservers) {
|
|
638
|
+
this._document._native.setNodeValue(this._id, value);
|
|
639
|
+
this._document._bumpMutationVersion();
|
|
640
|
+
return;
|
|
641
|
+
}
|
|
642
|
+
const oldValue = this.nodeValue;
|
|
643
|
+
this._document._native.setNodeValue(this._id, value);
|
|
644
|
+
this._document._bumpMutationVersion();
|
|
645
|
+
notifyMutation({
|
|
646
|
+
type: "characterData",
|
|
647
|
+
target: this,
|
|
648
|
+
addedNodes: [],
|
|
649
|
+
removedNodes: [],
|
|
650
|
+
attributeName: null,
|
|
651
|
+
oldValue
|
|
652
|
+
});
|
|
653
|
+
return;
|
|
654
|
+
}
|
|
655
|
+
if (hasActiveMutationObservers) {
|
|
656
|
+
while (this.firstChild) {
|
|
657
|
+
this.removeChild(this.firstChild);
|
|
658
|
+
}
|
|
659
|
+
if (value !== "") {
|
|
660
|
+
this.appendChild(this._document.createTextNode(value));
|
|
661
|
+
}
|
|
662
|
+
return;
|
|
663
|
+
}
|
|
664
|
+
this._document._native.setTextContent(this._id, value);
|
|
665
|
+
this._document._bumpMutationVersion();
|
|
666
|
+
}
|
|
667
|
+
get ownerDocument() {
|
|
668
|
+
return this._document;
|
|
669
|
+
}
|
|
670
|
+
get parentNode() {
|
|
671
|
+
const id = this._document._native.parentNode(this._id);
|
|
672
|
+
return id == null ? null : this._document._wrap(id);
|
|
673
|
+
}
|
|
674
|
+
get parentElement() {
|
|
675
|
+
const parent = this.parentNode;
|
|
676
|
+
return parent instanceof Element ? parent : null;
|
|
677
|
+
}
|
|
678
|
+
get isConnected() {
|
|
679
|
+
return this._document._native.isConnected(this._id);
|
|
680
|
+
}
|
|
681
|
+
get firstChild() {
|
|
682
|
+
const id = this._document._native.firstChild(this._id);
|
|
683
|
+
return id == null ? null : this._document._wrap(id);
|
|
684
|
+
}
|
|
685
|
+
get lastChild() {
|
|
686
|
+
const id = this._document._native.lastChild(this._id);
|
|
687
|
+
return id == null ? null : this._document._wrap(id);
|
|
688
|
+
}
|
|
689
|
+
get nextSibling() {
|
|
690
|
+
const id = this._document._native.nextSibling(this._id);
|
|
691
|
+
return id == null ? null : this._document._wrap(id);
|
|
692
|
+
}
|
|
693
|
+
get previousSibling() {
|
|
694
|
+
const id = this._document._native.previousSibling(this._id);
|
|
695
|
+
return id == null ? null : this._document._wrap(id);
|
|
696
|
+
}
|
|
697
|
+
get previousElementSibling() {
|
|
698
|
+
const id = this._document._native.previousElementSibling(this._id);
|
|
699
|
+
return id == null ? null : this._document._wrap(id);
|
|
700
|
+
}
|
|
701
|
+
get nextElementSibling() {
|
|
702
|
+
const id = this._document._native.nextElementSibling(this._id);
|
|
703
|
+
return id == null ? null : this._document._wrap(id);
|
|
704
|
+
}
|
|
705
|
+
get childNodes() {
|
|
706
|
+
return new NativeNodeList(this._document, this._document._native.childNodes(this._id));
|
|
707
|
+
}
|
|
708
|
+
hasChildNodes() {
|
|
709
|
+
return this.firstChild !== null;
|
|
710
|
+
}
|
|
711
|
+
appendChild(child) {
|
|
712
|
+
if (runtimeStats.enabled) {
|
|
713
|
+
recordOperation("appendChild");
|
|
714
|
+
}
|
|
715
|
+
child = this.#adoptForMutation(child);
|
|
716
|
+
const hasObservers = hasActiveMutationObservers;
|
|
717
|
+
if (child instanceof DocumentFragment) {
|
|
718
|
+
if (!hasObservers) {
|
|
719
|
+
if (this._document._native.appendDocumentFragment(this._id, child._nativeId)) {
|
|
720
|
+
this._document._bumpMutationVersion();
|
|
721
|
+
}
|
|
722
|
+
return child;
|
|
723
|
+
}
|
|
724
|
+
while (child.firstChild) {
|
|
725
|
+
this.appendChild(child.firstChild);
|
|
726
|
+
}
|
|
727
|
+
return child;
|
|
728
|
+
}
|
|
729
|
+
const hasCustomElements = this._document._hasCustomElementDefinitions();
|
|
730
|
+
if (!hasObservers && !hasCustomElements) {
|
|
731
|
+
this._document._native.appendChild(this._id, child._nativeId);
|
|
732
|
+
this._document._bumpMutationVersion();
|
|
733
|
+
return child;
|
|
734
|
+
}
|
|
735
|
+
const oldParent = hasCustomElements ? child.parentNode : null;
|
|
736
|
+
const wasConnected = hasCustomElements && child.isConnected;
|
|
737
|
+
this._document._native.appendChild(this._id, child._nativeId);
|
|
738
|
+
this._document._bumpMutationVersion();
|
|
739
|
+
if (hasCustomElements) {
|
|
740
|
+
notifyCustomElementReparented(child, oldParent, wasConnected);
|
|
741
|
+
}
|
|
742
|
+
if (hasObservers) {
|
|
743
|
+
notifyMutation({
|
|
744
|
+
type: "childList",
|
|
745
|
+
target: this,
|
|
746
|
+
addedNodes: [child],
|
|
747
|
+
removedNodes: [],
|
|
748
|
+
attributeName: null,
|
|
749
|
+
oldValue: null
|
|
750
|
+
});
|
|
751
|
+
}
|
|
752
|
+
return child;
|
|
753
|
+
}
|
|
754
|
+
append(...nodes) {
|
|
755
|
+
for (const node of nodes) {
|
|
756
|
+
this.appendChild(this.#toNode(node));
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
prepend(...nodes) {
|
|
760
|
+
const reference = this.firstChild;
|
|
761
|
+
for (const node of nodes) {
|
|
762
|
+
this.insertBefore(this.#toNode(node), reference);
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
insertBefore(child, referenceNode) {
|
|
766
|
+
if (runtimeStats.enabled) {
|
|
767
|
+
recordOperation("insertBefore");
|
|
768
|
+
}
|
|
769
|
+
child = this.#adoptForMutation(child);
|
|
770
|
+
if (referenceNode) {
|
|
771
|
+
this.#assertSameDocument(referenceNode);
|
|
772
|
+
}
|
|
773
|
+
const hasObservers = hasActiveMutationObservers;
|
|
774
|
+
if (child instanceof DocumentFragment) {
|
|
775
|
+
if (!hasObservers) {
|
|
776
|
+
const moved = this._document._native.insertDocumentFragment(this._id, child._nativeId, referenceNode?._nativeId ?? null);
|
|
777
|
+
if (moved) {
|
|
778
|
+
this._document._bumpMutationVersion();
|
|
779
|
+
}
|
|
780
|
+
return child;
|
|
781
|
+
}
|
|
782
|
+
while (child.firstChild) {
|
|
783
|
+
this.insertBefore(child.firstChild, referenceNode);
|
|
784
|
+
}
|
|
785
|
+
return child;
|
|
786
|
+
}
|
|
787
|
+
const hasCustomElements = this._document._hasCustomElementDefinitions();
|
|
788
|
+
if (!hasObservers && !hasCustomElements) {
|
|
789
|
+
this._document._native.insertBefore(this._id, child._nativeId, referenceNode?._nativeId ?? null);
|
|
790
|
+
this._document._bumpMutationVersion();
|
|
791
|
+
return child;
|
|
792
|
+
}
|
|
793
|
+
const oldParent = hasCustomElements ? child.parentNode : null;
|
|
794
|
+
const wasConnected = hasCustomElements && child.isConnected;
|
|
795
|
+
this._document._native.insertBefore(this._id, child._nativeId, referenceNode?._nativeId ?? null);
|
|
796
|
+
this._document._bumpMutationVersion();
|
|
797
|
+
if (hasCustomElements) {
|
|
798
|
+
notifyCustomElementReparented(child, oldParent, wasConnected);
|
|
799
|
+
}
|
|
800
|
+
if (hasObservers) {
|
|
801
|
+
notifyMutation({
|
|
802
|
+
type: "childList",
|
|
803
|
+
target: this,
|
|
804
|
+
addedNodes: [child],
|
|
805
|
+
removedNodes: [],
|
|
806
|
+
attributeName: null,
|
|
807
|
+
oldValue: null
|
|
808
|
+
});
|
|
809
|
+
}
|
|
810
|
+
return child;
|
|
811
|
+
}
|
|
812
|
+
removeChild(child) {
|
|
813
|
+
if (runtimeStats.enabled) {
|
|
814
|
+
recordOperation("removeChild");
|
|
815
|
+
}
|
|
816
|
+
this.#assertSameDocument(child);
|
|
817
|
+
const hasCustomElements = this._document._hasCustomElementDefinitions();
|
|
818
|
+
const wasConnected = hasCustomElements && child.isConnected;
|
|
819
|
+
const hasObservers = hasMutationObservers();
|
|
820
|
+
if (!hasObservers) {
|
|
821
|
+
this._document._native.removeChild(this._id, child._nativeId);
|
|
822
|
+
this._document._bumpMutationVersion();
|
|
823
|
+
if (hasCustomElements && wasConnected) {
|
|
824
|
+
notifyCustomElementDisconnected(child);
|
|
825
|
+
}
|
|
826
|
+
return child;
|
|
827
|
+
}
|
|
828
|
+
const previousSibling = child.previousSibling;
|
|
829
|
+
const nextSibling = child.nextSibling;
|
|
830
|
+
this._document._native.removeChild(this._id, child._nativeId);
|
|
831
|
+
this._document._bumpMutationVersion();
|
|
832
|
+
if (hasCustomElements && wasConnected) {
|
|
833
|
+
notifyCustomElementDisconnected(child);
|
|
834
|
+
}
|
|
835
|
+
notifyMutation({
|
|
836
|
+
type: "childList",
|
|
837
|
+
target: this,
|
|
838
|
+
addedNodes: [],
|
|
839
|
+
removedNodes: [child],
|
|
840
|
+
attributeName: null,
|
|
841
|
+
oldValue: null,
|
|
842
|
+
previousSibling,
|
|
843
|
+
nextSibling
|
|
844
|
+
});
|
|
845
|
+
return child;
|
|
846
|
+
}
|
|
847
|
+
replaceChild(newChild, oldChild) {
|
|
848
|
+
if (runtimeStats.enabled) {
|
|
849
|
+
recordOperation("replaceChild");
|
|
850
|
+
}
|
|
851
|
+
newChild = this.#adoptForMutation(newChild);
|
|
852
|
+
this.#assertSameDocument(oldChild);
|
|
853
|
+
if (newChild === oldChild) {
|
|
854
|
+
return oldChild;
|
|
855
|
+
}
|
|
856
|
+
if (newChild instanceof DocumentFragment) {
|
|
857
|
+
this.insertBefore(newChild, oldChild);
|
|
858
|
+
this.removeChild(oldChild);
|
|
859
|
+
return oldChild;
|
|
860
|
+
}
|
|
861
|
+
if (!hasMutationObservers()) {
|
|
862
|
+
const hasCustomElements = this._document._hasCustomElementDefinitions();
|
|
863
|
+
const oldWasConnected = hasCustomElements && oldChild.isConnected;
|
|
864
|
+
const newOldParent = hasCustomElements ? newChild.parentNode : null;
|
|
865
|
+
const newWasConnected = hasCustomElements && newChild.isConnected;
|
|
866
|
+
this._document._native.replaceChild(this._id, newChild._nativeId, oldChild._nativeId);
|
|
867
|
+
this._document._bumpMutationVersion();
|
|
868
|
+
if (hasCustomElements && oldWasConnected) {
|
|
869
|
+
notifyCustomElementDisconnected(oldChild);
|
|
870
|
+
}
|
|
871
|
+
if (hasCustomElements) {
|
|
872
|
+
notifyCustomElementReparented(newChild, newOldParent, newWasConnected);
|
|
873
|
+
}
|
|
874
|
+
return oldChild;
|
|
875
|
+
}
|
|
876
|
+
this.insertBefore(newChild, oldChild);
|
|
877
|
+
this.removeChild(oldChild);
|
|
878
|
+
return oldChild;
|
|
879
|
+
}
|
|
880
|
+
replaceChildren(...nodes) {
|
|
881
|
+
if (runtimeStats.enabled) {
|
|
882
|
+
recordOperation("replaceChildren");
|
|
883
|
+
}
|
|
884
|
+
if (hasMutationObservers()) {
|
|
885
|
+
while (this.firstChild) {
|
|
886
|
+
this.removeChild(this.firstChild);
|
|
887
|
+
}
|
|
888
|
+
this.append(...nodes);
|
|
889
|
+
return;
|
|
890
|
+
}
|
|
891
|
+
this._document._native.clearChildren(this._id);
|
|
892
|
+
this._document._bumpMutationVersion();
|
|
893
|
+
this.append(...nodes);
|
|
894
|
+
}
|
|
895
|
+
cloneNode(deep = false) {
|
|
896
|
+
return this._document._wrap(this._document._native.cloneNode(this._id, deep));
|
|
897
|
+
}
|
|
898
|
+
contains(other) {
|
|
899
|
+
if (!other || other._document !== this._document) {
|
|
900
|
+
return false;
|
|
901
|
+
}
|
|
902
|
+
return this._document._native.contains(this._id, other._nativeId);
|
|
903
|
+
}
|
|
904
|
+
getRootNode() {
|
|
905
|
+
let current = this;
|
|
906
|
+
while (current.parentNode) {
|
|
907
|
+
current = current.parentNode;
|
|
908
|
+
}
|
|
909
|
+
return current;
|
|
910
|
+
}
|
|
911
|
+
isSameNode(other) {
|
|
912
|
+
return this === other;
|
|
913
|
+
}
|
|
914
|
+
isEqualNode(other) {
|
|
915
|
+
if (!other || this.nodeType !== other.nodeType || this.nodeName !== other.nodeName) {
|
|
916
|
+
return false;
|
|
917
|
+
}
|
|
918
|
+
if (this.nodeValue !== other.nodeValue) {
|
|
919
|
+
return false;
|
|
920
|
+
}
|
|
921
|
+
if (this instanceof Element || other instanceof Element) {
|
|
922
|
+
if (!(this instanceof Element) || !(other instanceof Element)) {
|
|
923
|
+
return false;
|
|
924
|
+
}
|
|
925
|
+
const attributeNames = this.getAttributeNames();
|
|
926
|
+
const otherAttributeNames = other.getAttributeNames();
|
|
927
|
+
if (attributeNames.length !== otherAttributeNames.length) {
|
|
928
|
+
return false;
|
|
929
|
+
}
|
|
930
|
+
for (const name of attributeNames) {
|
|
931
|
+
if (this.getAttribute(name) !== other.getAttribute(name)) {
|
|
932
|
+
return false;
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
}
|
|
936
|
+
const children = [...this.childNodes];
|
|
937
|
+
const otherChildren = [...other.childNodes];
|
|
938
|
+
return (children.length === otherChildren.length &&
|
|
939
|
+
children.every((child, index) => child.isEqualNode(otherChildren[index])));
|
|
940
|
+
}
|
|
941
|
+
compareDocumentPosition(other) {
|
|
942
|
+
if (this === other) {
|
|
943
|
+
return 0;
|
|
944
|
+
}
|
|
945
|
+
if (other._document !== this._document) {
|
|
946
|
+
return (Node.DOCUMENT_POSITION_DISCONNECTED |
|
|
947
|
+
Node.DOCUMENT_POSITION_FOLLOWING |
|
|
948
|
+
Node.DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC);
|
|
949
|
+
}
|
|
950
|
+
return this._document._native.compareDocumentPosition(this._id, other._nativeId);
|
|
951
|
+
}
|
|
952
|
+
normalize() {
|
|
953
|
+
if (runtimeStats.enabled) {
|
|
954
|
+
recordOperation("normalize");
|
|
955
|
+
}
|
|
956
|
+
if (!hasMutationObservers()) {
|
|
957
|
+
if (this._document._native.normalizeSubtree(this._id)) {
|
|
958
|
+
this._document._bumpMutationVersion();
|
|
959
|
+
}
|
|
960
|
+
return;
|
|
961
|
+
}
|
|
962
|
+
let child = this.firstChild;
|
|
963
|
+
while (child) {
|
|
964
|
+
const next = child.nextSibling;
|
|
965
|
+
if (child.nodeType !== Node.TEXT_NODE) {
|
|
966
|
+
child.normalize();
|
|
967
|
+
child = next;
|
|
968
|
+
continue;
|
|
969
|
+
}
|
|
970
|
+
let data = child.nodeValue ?? "";
|
|
971
|
+
let sibling = next;
|
|
972
|
+
while (sibling?.nodeType === Node.TEXT_NODE) {
|
|
973
|
+
data += sibling.nodeValue ?? "";
|
|
974
|
+
const siblingToRemove = sibling;
|
|
975
|
+
sibling = sibling.nextSibling;
|
|
976
|
+
this.removeChild(siblingToRemove);
|
|
977
|
+
}
|
|
978
|
+
if (data === "") {
|
|
979
|
+
this.removeChild(child);
|
|
980
|
+
}
|
|
981
|
+
else if (child.nodeValue !== data) {
|
|
982
|
+
child.nodeValue = data;
|
|
983
|
+
}
|
|
984
|
+
child = sibling;
|
|
985
|
+
}
|
|
986
|
+
}
|
|
987
|
+
remove() {
|
|
988
|
+
this.parentNode?.removeChild(this);
|
|
989
|
+
}
|
|
990
|
+
before(...nodes) {
|
|
991
|
+
const parent = this.parentNode;
|
|
992
|
+
if (!parent) {
|
|
993
|
+
return;
|
|
994
|
+
}
|
|
995
|
+
for (const node of nodes) {
|
|
996
|
+
parent.insertBefore(this.#toNode(node), this);
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
after(...nodes) {
|
|
1000
|
+
const parent = this.parentNode;
|
|
1001
|
+
if (!parent) {
|
|
1002
|
+
return;
|
|
1003
|
+
}
|
|
1004
|
+
const reference = this.nextSibling;
|
|
1005
|
+
for (const node of nodes) {
|
|
1006
|
+
parent.insertBefore(this.#toNode(node), reference);
|
|
1007
|
+
}
|
|
1008
|
+
}
|
|
1009
|
+
replaceWith(...nodes) {
|
|
1010
|
+
const parent = this.parentNode;
|
|
1011
|
+
if (!parent) {
|
|
1012
|
+
return;
|
|
1013
|
+
}
|
|
1014
|
+
for (const node of nodes) {
|
|
1015
|
+
parent.insertBefore(this.#toNode(node), this);
|
|
1016
|
+
}
|
|
1017
|
+
parent.removeChild(this);
|
|
1018
|
+
}
|
|
1019
|
+
_eventPath() {
|
|
1020
|
+
const path = [this];
|
|
1021
|
+
let current = this.parentNode;
|
|
1022
|
+
while (current) {
|
|
1023
|
+
path.push(current);
|
|
1024
|
+
current = current.parentNode;
|
|
1025
|
+
}
|
|
1026
|
+
path.push(this._document.defaultView);
|
|
1027
|
+
return path;
|
|
1028
|
+
}
|
|
1029
|
+
get _nativeId() {
|
|
1030
|
+
return this._id;
|
|
1031
|
+
}
|
|
1032
|
+
#assertSameDocument(node) {
|
|
1033
|
+
if (node._document !== this._document) {
|
|
1034
|
+
throw new Error("Cross-document node mutations are not implemented");
|
|
1035
|
+
}
|
|
1036
|
+
}
|
|
1037
|
+
#adoptForMutation(node) {
|
|
1038
|
+
const targetDocument = this._document;
|
|
1039
|
+
return !targetDocument || node._document === targetDocument
|
|
1040
|
+
? node
|
|
1041
|
+
: importNodeIntoDocument(targetDocument, node, true);
|
|
1042
|
+
}
|
|
1043
|
+
#toNode(node) {
|
|
1044
|
+
return typeof node === "string" ? this._document.createTextNode(node) : node;
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1047
|
+
Object.defineProperties(Node.prototype, {
|
|
1048
|
+
ELEMENT_NODE: { value: Node.ELEMENT_NODE },
|
|
1049
|
+
TEXT_NODE: { value: Node.TEXT_NODE },
|
|
1050
|
+
COMMENT_NODE: { value: Node.COMMENT_NODE },
|
|
1051
|
+
DOCUMENT_NODE: { value: Node.DOCUMENT_NODE },
|
|
1052
|
+
DOCUMENT_TYPE_NODE: { value: Node.DOCUMENT_TYPE_NODE },
|
|
1053
|
+
DOCUMENT_FRAGMENT_NODE: { value: Node.DOCUMENT_FRAGMENT_NODE },
|
|
1054
|
+
DOCUMENT_POSITION_DISCONNECTED: { value: Node.DOCUMENT_POSITION_DISCONNECTED },
|
|
1055
|
+
DOCUMENT_POSITION_PRECEDING: { value: Node.DOCUMENT_POSITION_PRECEDING },
|
|
1056
|
+
DOCUMENT_POSITION_FOLLOWING: { value: Node.DOCUMENT_POSITION_FOLLOWING },
|
|
1057
|
+
DOCUMENT_POSITION_CONTAINS: { value: Node.DOCUMENT_POSITION_CONTAINS },
|
|
1058
|
+
DOCUMENT_POSITION_CONTAINED_BY: { value: Node.DOCUMENT_POSITION_CONTAINED_BY },
|
|
1059
|
+
DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC: {
|
|
1060
|
+
value: Node.DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC
|
|
1061
|
+
}
|
|
1062
|
+
});
|
|
1063
|
+
function nativeDocumentOrder(root) {
|
|
1064
|
+
const document = root.ownerDocument;
|
|
1065
|
+
if (!document) {
|
|
1066
|
+
throw new Error("Node has no owner document");
|
|
1067
|
+
}
|
|
1068
|
+
return {
|
|
1069
|
+
document,
|
|
1070
|
+
ids: document._native.documentOrderIds(root._nativeId)
|
|
1071
|
+
};
|
|
1072
|
+
}
|
|
1073
|
+
export class NamedNodeMap extends Array {
|
|
1074
|
+
static get [Symbol.species]() {
|
|
1075
|
+
return Array;
|
|
1076
|
+
}
|
|
1077
|
+
constructor(attributes = []) {
|
|
1078
|
+
super();
|
|
1079
|
+
for (const attribute of attributes) {
|
|
1080
|
+
this.push(attribute);
|
|
1081
|
+
}
|
|
1082
|
+
}
|
|
1083
|
+
item(index) {
|
|
1084
|
+
return this[index] ?? null;
|
|
1085
|
+
}
|
|
1086
|
+
getNamedItem(name) {
|
|
1087
|
+
const normalizedName = String(name).toLowerCase();
|
|
1088
|
+
return this.find((attribute) => attribute.name === normalizedName) ?? null;
|
|
1089
|
+
}
|
|
1090
|
+
getNamedItemNS(_namespace, localName) {
|
|
1091
|
+
const normalizedName = String(localName).toLowerCase();
|
|
1092
|
+
return this.find((attribute) => attribute.localName === normalizedName) ?? null;
|
|
1093
|
+
}
|
|
1094
|
+
}
|
|
1095
|
+
export class MutationRecord {
|
|
1096
|
+
type;
|
|
1097
|
+
target;
|
|
1098
|
+
addedNodes;
|
|
1099
|
+
removedNodes;
|
|
1100
|
+
attributeName;
|
|
1101
|
+
oldValue;
|
|
1102
|
+
previousSibling;
|
|
1103
|
+
nextSibling;
|
|
1104
|
+
constructor(init) {
|
|
1105
|
+
this.type = init.type;
|
|
1106
|
+
this.target = init.target;
|
|
1107
|
+
this.addedNodes = init.addedNodes;
|
|
1108
|
+
this.removedNodes = init.removedNodes;
|
|
1109
|
+
this.attributeName = init.attributeName;
|
|
1110
|
+
this.oldValue = init.oldValue;
|
|
1111
|
+
this.previousSibling = init.previousSibling ?? null;
|
|
1112
|
+
this.nextSibling = init.nextSibling ?? null;
|
|
1113
|
+
}
|
|
1114
|
+
}
|
|
1115
|
+
const mutationObservers = new Set();
|
|
1116
|
+
let hasActiveMutationObservers = false;
|
|
1117
|
+
function hasMutationObservers() {
|
|
1118
|
+
if (runtimeStats.enabled) {
|
|
1119
|
+
recordOperation("observerChecks");
|
|
1120
|
+
}
|
|
1121
|
+
return hasActiveMutationObservers;
|
|
1122
|
+
}
|
|
1123
|
+
export class MutationObserver {
|
|
1124
|
+
#callback;
|
|
1125
|
+
#observed = new Map();
|
|
1126
|
+
#records = [];
|
|
1127
|
+
#scheduled = false;
|
|
1128
|
+
constructor(callback) {
|
|
1129
|
+
this.#callback = callback;
|
|
1130
|
+
}
|
|
1131
|
+
observe(target, options) {
|
|
1132
|
+
if (!target) {
|
|
1133
|
+
throw new TypeError("Failed to execute 'observe' on 'MutationObserver': The first parameter \"target\" should be of type \"Node\".");
|
|
1134
|
+
}
|
|
1135
|
+
this.#observed.set(target, normalizeMutationObserverOptions(options));
|
|
1136
|
+
mutationObservers.add(this);
|
|
1137
|
+
hasActiveMutationObservers = true;
|
|
1138
|
+
}
|
|
1139
|
+
disconnect() {
|
|
1140
|
+
this.#observed.clear();
|
|
1141
|
+
this.#records = [];
|
|
1142
|
+
mutationObservers.delete(this);
|
|
1143
|
+
hasActiveMutationObservers = mutationObservers.size > 0;
|
|
1144
|
+
}
|
|
1145
|
+
takeRecords() {
|
|
1146
|
+
const records = this.#records;
|
|
1147
|
+
this.#records = [];
|
|
1148
|
+
return records;
|
|
1149
|
+
}
|
|
1150
|
+
_enqueue(record) {
|
|
1151
|
+
const matched = this.#matchingOptions(record);
|
|
1152
|
+
if (!matched) {
|
|
1153
|
+
return;
|
|
1154
|
+
}
|
|
1155
|
+
this.#records.push(new MutationRecord({
|
|
1156
|
+
...record,
|
|
1157
|
+
oldValue: (record.type === "attributes" && matched.attributeOldValue) ||
|
|
1158
|
+
(record.type === "characterData" && matched.characterDataOldValue)
|
|
1159
|
+
? record.oldValue
|
|
1160
|
+
: null
|
|
1161
|
+
}));
|
|
1162
|
+
if (!this.#scheduled) {
|
|
1163
|
+
this.#scheduled = true;
|
|
1164
|
+
queueMicrotask(() => {
|
|
1165
|
+
this.#scheduled = false;
|
|
1166
|
+
const records = this.takeRecords();
|
|
1167
|
+
if (records.length > 0) {
|
|
1168
|
+
this.#callback(records, this);
|
|
1169
|
+
}
|
|
1170
|
+
});
|
|
1171
|
+
}
|
|
1172
|
+
}
|
|
1173
|
+
#matchingOptions(record) {
|
|
1174
|
+
for (const [target, options] of this.#observed) {
|
|
1175
|
+
if (record.target !== target && !(options.subtree && target.contains(record.target))) {
|
|
1176
|
+
continue;
|
|
1177
|
+
}
|
|
1178
|
+
if (record.type === "childList" && options.childList) {
|
|
1179
|
+
return options;
|
|
1180
|
+
}
|
|
1181
|
+
if (record.type === "attributes" && options.attributes) {
|
|
1182
|
+
if (options.attributeFilter &&
|
|
1183
|
+
(!record.attributeName || !options.attributeFilter.includes(record.attributeName))) {
|
|
1184
|
+
continue;
|
|
1185
|
+
}
|
|
1186
|
+
return options;
|
|
1187
|
+
}
|
|
1188
|
+
if (record.type === "characterData" && options.characterData) {
|
|
1189
|
+
return options;
|
|
1190
|
+
}
|
|
1191
|
+
}
|
|
1192
|
+
return null;
|
|
1193
|
+
}
|
|
1194
|
+
}
|
|
1195
|
+
function normalizeMutationObserverOptions(options) {
|
|
1196
|
+
if (!options) {
|
|
1197
|
+
throw new TypeError("Failed to execute 'observe' on 'MutationObserver': The options object must set at least one of 'attributes', 'characterData', or 'childList' to true.");
|
|
1198
|
+
}
|
|
1199
|
+
if (options.attributeOldValue && options.attributes === false) {
|
|
1200
|
+
throw new TypeError("Failed to execute 'observe' on 'MutationObserver': The options object may only set 'attributeOldValue' to true when 'attributes' is true or not present.");
|
|
1201
|
+
}
|
|
1202
|
+
if (options.attributeFilter && options.attributes === false) {
|
|
1203
|
+
throw new TypeError("Failed to execute 'observe' on 'MutationObserver': The options object may only set 'attributeFilter' when 'attributes' is true or not present.");
|
|
1204
|
+
}
|
|
1205
|
+
if (options.characterDataOldValue && options.characterData === false) {
|
|
1206
|
+
throw new TypeError("Failed to execute 'observe' on 'MutationObserver': The options object may only set 'characterDataOldValue' to true when 'characterData' is true or not present.");
|
|
1207
|
+
}
|
|
1208
|
+
const normalized = {
|
|
1209
|
+
...options,
|
|
1210
|
+
attributes: options.attributes ?? (options.attributeOldValue || options.attributeFilter ? true : undefined),
|
|
1211
|
+
characterData: options.characterData ?? (options.characterDataOldValue ? true : undefined),
|
|
1212
|
+
attributeFilter: options.attributeFilter?.map((name) => name.toLowerCase())
|
|
1213
|
+
};
|
|
1214
|
+
if (!normalized.childList && !normalized.attributes && !normalized.characterData) {
|
|
1215
|
+
throw new TypeError("Failed to execute 'observe' on 'MutationObserver': The options object must set at least one of 'attributes', 'characterData', or 'childList' to true.");
|
|
1216
|
+
}
|
|
1217
|
+
return normalized;
|
|
1218
|
+
}
|
|
1219
|
+
function notifyMutation(record) {
|
|
1220
|
+
if (mutationObservers.size === 0) {
|
|
1221
|
+
return;
|
|
1222
|
+
}
|
|
1223
|
+
const mutationRecord = new MutationRecord(record);
|
|
1224
|
+
for (const observer of mutationObservers) {
|
|
1225
|
+
observer._enqueue(mutationRecord);
|
|
1226
|
+
}
|
|
1227
|
+
}
|
|
1228
|
+
export class DOMImplementation {
|
|
1229
|
+
#document;
|
|
1230
|
+
constructor(document = null) {
|
|
1231
|
+
this.#document = document;
|
|
1232
|
+
}
|
|
1233
|
+
createHTMLDocument(_title = "") {
|
|
1234
|
+
return new Window().document;
|
|
1235
|
+
}
|
|
1236
|
+
createDocumentType(name, publicId = "", systemId = "") {
|
|
1237
|
+
const document = this.#document ?? new Window().document;
|
|
1238
|
+
return document._wrap(document._native.createDocumentType(String(name), String(publicId), String(systemId)));
|
|
1239
|
+
}
|
|
1240
|
+
}
|
|
1241
|
+
export class DOMParser {
|
|
1242
|
+
parseFromString(markup, _type) {
|
|
1243
|
+
return new Window(String(markup)).document;
|
|
1244
|
+
}
|
|
1245
|
+
}
|
|
1246
|
+
export class XMLSerializer {
|
|
1247
|
+
serializeToString(node) {
|
|
1248
|
+
if (node instanceof Document) {
|
|
1249
|
+
return addRootHtmlNamespace(node.documentElement.outerHTML);
|
|
1250
|
+
}
|
|
1251
|
+
if (node instanceof Element) {
|
|
1252
|
+
return addRootHtmlNamespace(node.outerHTML);
|
|
1253
|
+
}
|
|
1254
|
+
const document = node instanceof Document ? node : node.ownerDocument;
|
|
1255
|
+
return document?._native.serializeNode(node._nativeId) ?? "";
|
|
1256
|
+
}
|
|
1257
|
+
}
|
|
1258
|
+
function addRootHtmlNamespace(markup) {
|
|
1259
|
+
if (/^<[^\s>]+[\s>]/.test(markup) && !/^<[^\s>]+\s[^>]*\bxmlns=/.test(markup)) {
|
|
1260
|
+
return markup.replace(/^<([^\s>]+)/, '<$1 xmlns="http://www.w3.org/1999/xhtml"');
|
|
1261
|
+
}
|
|
1262
|
+
return markup;
|
|
1263
|
+
}
|
|
1264
|
+
let customElementConstruction = null;
|
|
1265
|
+
function parseDocumentCookie(cookieText) {
|
|
1266
|
+
const [pair] = cookieText.split(";");
|
|
1267
|
+
const trimmedPair = pair?.trim() ?? "";
|
|
1268
|
+
if (!trimmedPair) {
|
|
1269
|
+
return null;
|
|
1270
|
+
}
|
|
1271
|
+
const equalsIndex = trimmedPair.indexOf("=");
|
|
1272
|
+
if (equalsIndex === -1) {
|
|
1273
|
+
return {
|
|
1274
|
+
hasValue: false,
|
|
1275
|
+
name: trimmedPair,
|
|
1276
|
+
value: ""
|
|
1277
|
+
};
|
|
1278
|
+
}
|
|
1279
|
+
const name = trimmedPair.slice(0, equalsIndex).trim();
|
|
1280
|
+
if (!name) {
|
|
1281
|
+
return null;
|
|
1282
|
+
}
|
|
1283
|
+
return {
|
|
1284
|
+
hasValue: true,
|
|
1285
|
+
name,
|
|
1286
|
+
value: trimmedPair.slice(equalsIndex + 1).trim()
|
|
1287
|
+
};
|
|
1288
|
+
}
|
|
1289
|
+
export class Document extends Node {
|
|
1290
|
+
defaultView;
|
|
1291
|
+
implementation;
|
|
1292
|
+
_native;
|
|
1293
|
+
#wrappers = new Map();
|
|
1294
|
+
#activeElement = null;
|
|
1295
|
+
#documentNodeId;
|
|
1296
|
+
#documentElementId;
|
|
1297
|
+
#headId;
|
|
1298
|
+
#bodyId;
|
|
1299
|
+
#mutationVersion = 0;
|
|
1300
|
+
#namespaces = new Map();
|
|
1301
|
+
#cookies = new Map();
|
|
1302
|
+
#queryAllCache = new Map();
|
|
1303
|
+
#lastQueryAllRootId = null;
|
|
1304
|
+
#lastQueryAllSelector = "";
|
|
1305
|
+
#lastQueryAllVersion = -1;
|
|
1306
|
+
#lastQueryAllIds = [];
|
|
1307
|
+
#queryOneCache = new Map();
|
|
1308
|
+
#lastQueryOneRootId = null;
|
|
1309
|
+
#lastQueryOneSelector = "";
|
|
1310
|
+
#lastQueryOneVersion = -1;
|
|
1311
|
+
#lastQueryOneId = null;
|
|
1312
|
+
#classNameCache = new Map();
|
|
1313
|
+
#lastClassNameRootId = null;
|
|
1314
|
+
#lastClassNameSelector = "";
|
|
1315
|
+
#lastClassNameVersion = -1;
|
|
1316
|
+
#lastClassNameIds = [];
|
|
1317
|
+
#matchesCache = new Map();
|
|
1318
|
+
#lastMatchesId = null;
|
|
1319
|
+
#lastMatchesSelector = "";
|
|
1320
|
+
#lastMatchesVersion = -1;
|
|
1321
|
+
#lastMatchesResult = false;
|
|
1322
|
+
#closestCache = new Map();
|
|
1323
|
+
#lastClosestId = null;
|
|
1324
|
+
#lastClosestSelector = "";
|
|
1325
|
+
#lastClosestVersion = -1;
|
|
1326
|
+
#lastClosestResult = null;
|
|
1327
|
+
#customElementRegistryVersion = -1;
|
|
1328
|
+
#hasCustomElementDefinitions = false;
|
|
1329
|
+
constructor(defaultView, html = "") {
|
|
1330
|
+
if (runtimeStats.enabled) {
|
|
1331
|
+
recordNativeCall("parseHtmlDocumentNative");
|
|
1332
|
+
}
|
|
1333
|
+
const native = prepareNativeDocument(parseHtmlDocumentNative(html));
|
|
1334
|
+
const documentNodeId = native.documentNode();
|
|
1335
|
+
super(undefined, documentNodeId, "#document");
|
|
1336
|
+
this.defaultView = defaultView;
|
|
1337
|
+
this._native = native;
|
|
1338
|
+
this.#documentNodeId = documentNodeId;
|
|
1339
|
+
this.#documentElementId = native.documentElement();
|
|
1340
|
+
this.#headId = native.head();
|
|
1341
|
+
this.#bodyId = native.body();
|
|
1342
|
+
this.implementation = new DOMImplementation(this);
|
|
1343
|
+
Object.defineProperty(this, "_document", {
|
|
1344
|
+
configurable: false,
|
|
1345
|
+
value: this
|
|
1346
|
+
});
|
|
1347
|
+
if (runtimeStats.enabled) {
|
|
1348
|
+
recordWrapperCreated("#document");
|
|
1349
|
+
}
|
|
1350
|
+
}
|
|
1351
|
+
get documentElement() {
|
|
1352
|
+
return this._wrap(this.#documentElementId, "HTML");
|
|
1353
|
+
}
|
|
1354
|
+
get doctype() {
|
|
1355
|
+
const id = this._native.documentType();
|
|
1356
|
+
return id == null ? null : this._wrap(id);
|
|
1357
|
+
}
|
|
1358
|
+
get head() {
|
|
1359
|
+
return this._wrap(this.#headId, "HEAD");
|
|
1360
|
+
}
|
|
1361
|
+
get body() {
|
|
1362
|
+
return this._wrap(this.#bodyId, "BODY");
|
|
1363
|
+
}
|
|
1364
|
+
get URL() {
|
|
1365
|
+
return this.defaultView.location.href;
|
|
1366
|
+
}
|
|
1367
|
+
get documentURI() {
|
|
1368
|
+
return this.URL;
|
|
1369
|
+
}
|
|
1370
|
+
get characterSet() {
|
|
1371
|
+
return "UTF-8";
|
|
1372
|
+
}
|
|
1373
|
+
get charset() {
|
|
1374
|
+
return this.characterSet;
|
|
1375
|
+
}
|
|
1376
|
+
get inputEncoding() {
|
|
1377
|
+
return this.characterSet;
|
|
1378
|
+
}
|
|
1379
|
+
get contentType() {
|
|
1380
|
+
return "text/html";
|
|
1381
|
+
}
|
|
1382
|
+
get readyState() {
|
|
1383
|
+
return "interactive";
|
|
1384
|
+
}
|
|
1385
|
+
get visibilityState() {
|
|
1386
|
+
return "visible";
|
|
1387
|
+
}
|
|
1388
|
+
get hidden() {
|
|
1389
|
+
return this.visibilityState !== "visible";
|
|
1390
|
+
}
|
|
1391
|
+
get cookie() {
|
|
1392
|
+
return [...this.#cookies.values()]
|
|
1393
|
+
.map((cookie) => (cookie.hasValue ? `${cookie.name}=${cookie.value}` : cookie.name))
|
|
1394
|
+
.join("; ");
|
|
1395
|
+
}
|
|
1396
|
+
set cookie(value) {
|
|
1397
|
+
const cookie = parseDocumentCookie(String(value));
|
|
1398
|
+
if (!cookie) {
|
|
1399
|
+
return;
|
|
1400
|
+
}
|
|
1401
|
+
this.#cookies.delete(cookie.name);
|
|
1402
|
+
this.#cookies.set(cookie.name, cookie);
|
|
1403
|
+
}
|
|
1404
|
+
get styleSheets() {
|
|
1405
|
+
return [...this.querySelectorAll("style")]
|
|
1406
|
+
.filter((element) => element instanceof HTMLStyleElement)
|
|
1407
|
+
.map((element) => element.sheet)
|
|
1408
|
+
.filter((sheet) => sheet !== null);
|
|
1409
|
+
}
|
|
1410
|
+
hasFocus() {
|
|
1411
|
+
return true;
|
|
1412
|
+
}
|
|
1413
|
+
get title() {
|
|
1414
|
+
return this.head.querySelector("title")?.textContent ?? "";
|
|
1415
|
+
}
|
|
1416
|
+
set title(value) {
|
|
1417
|
+
let title = this.head.querySelector("title");
|
|
1418
|
+
if (!title) {
|
|
1419
|
+
title = this.createElement("title");
|
|
1420
|
+
this.head.appendChild(title);
|
|
1421
|
+
}
|
|
1422
|
+
title.textContent = String(value);
|
|
1423
|
+
}
|
|
1424
|
+
get ownerDocument() {
|
|
1425
|
+
return null;
|
|
1426
|
+
}
|
|
1427
|
+
get activeElement() {
|
|
1428
|
+
return this.#activeElement ?? this.body;
|
|
1429
|
+
}
|
|
1430
|
+
querySelector(selector) {
|
|
1431
|
+
const id = this._querySelector(this.#documentNodeId, selector);
|
|
1432
|
+
return id == null ? null : this._wrap(id);
|
|
1433
|
+
}
|
|
1434
|
+
querySelectorAll(selector) {
|
|
1435
|
+
return new NativeNodeList(this, this._querySelectorAll(this.#documentNodeId, selector));
|
|
1436
|
+
}
|
|
1437
|
+
getElementById(id) {
|
|
1438
|
+
const nativeId = this._native.elementById(this.#documentNodeId, String(id));
|
|
1439
|
+
return nativeId == null ? null : this._wrap(nativeId);
|
|
1440
|
+
}
|
|
1441
|
+
createElement(localName) {
|
|
1442
|
+
if (runtimeStats.enabled) {
|
|
1443
|
+
recordOperation("createElement");
|
|
1444
|
+
}
|
|
1445
|
+
const normalizedName = String(localName).toLowerCase();
|
|
1446
|
+
const id = this._native.createElement(normalizedName);
|
|
1447
|
+
const nodeName = normalizedName.toUpperCase();
|
|
1448
|
+
const definition = normalizedName.includes("-") && this._hasCustomElementDefinitions()
|
|
1449
|
+
? this.defaultView.customElements._definitionFor(normalizedName)
|
|
1450
|
+
: undefined;
|
|
1451
|
+
if (definition) {
|
|
1452
|
+
const previousConstruction = customElementConstruction;
|
|
1453
|
+
customElementConstruction = {
|
|
1454
|
+
document: this,
|
|
1455
|
+
id,
|
|
1456
|
+
nodeName
|
|
1457
|
+
};
|
|
1458
|
+
try {
|
|
1459
|
+
const element = new definition.constructor();
|
|
1460
|
+
this._storeWrapper(id, element);
|
|
1461
|
+
return element;
|
|
1462
|
+
}
|
|
1463
|
+
finally {
|
|
1464
|
+
customElementConstruction = previousConstruction;
|
|
1465
|
+
}
|
|
1466
|
+
}
|
|
1467
|
+
return this._wrapCreatedHTMLElement(id, nodeName);
|
|
1468
|
+
}
|
|
1469
|
+
createElementNS(namespaceURI, qualifiedName) {
|
|
1470
|
+
if (runtimeStats.enabled) {
|
|
1471
|
+
recordOperation("createElementNS");
|
|
1472
|
+
}
|
|
1473
|
+
const id = this._native.createElement(qualifiedName);
|
|
1474
|
+
if (namespaceURI) {
|
|
1475
|
+
this.#namespaces.set(id, namespaceURI);
|
|
1476
|
+
}
|
|
1477
|
+
return this._wrap(id, qualifiedName.toUpperCase());
|
|
1478
|
+
}
|
|
1479
|
+
createTextNode(value) {
|
|
1480
|
+
if (runtimeStats.enabled) {
|
|
1481
|
+
recordOperation("createTextNode");
|
|
1482
|
+
}
|
|
1483
|
+
const id = this._native.createTextNode(value);
|
|
1484
|
+
const node = new Text(this, id, "#text");
|
|
1485
|
+
this.#wrappers.set(id, node);
|
|
1486
|
+
if (runtimeStats.enabled) {
|
|
1487
|
+
recordWrapperCreated("#text");
|
|
1488
|
+
}
|
|
1489
|
+
return node;
|
|
1490
|
+
}
|
|
1491
|
+
createComment(value) {
|
|
1492
|
+
if (runtimeStats.enabled) {
|
|
1493
|
+
recordOperation("createComment");
|
|
1494
|
+
}
|
|
1495
|
+
const id = this._native.createComment(value);
|
|
1496
|
+
const node = new Comment(this, id, "#comment");
|
|
1497
|
+
this.#wrappers.set(id, node);
|
|
1498
|
+
if (runtimeStats.enabled) {
|
|
1499
|
+
recordWrapperCreated("#comment");
|
|
1500
|
+
}
|
|
1501
|
+
return node;
|
|
1502
|
+
}
|
|
1503
|
+
createDocumentFragment() {
|
|
1504
|
+
if (runtimeStats.enabled) {
|
|
1505
|
+
recordOperation("createDocumentFragment");
|
|
1506
|
+
}
|
|
1507
|
+
const id = this._native.createDocumentFragment();
|
|
1508
|
+
const fragment = new DocumentFragment(this, id, "#document-fragment");
|
|
1509
|
+
this.#wrappers.set(id, fragment);
|
|
1510
|
+
if (runtimeStats.enabled) {
|
|
1511
|
+
recordWrapperCreated("#document-fragment");
|
|
1512
|
+
}
|
|
1513
|
+
return fragment;
|
|
1514
|
+
}
|
|
1515
|
+
createRange() {
|
|
1516
|
+
return new Range(this);
|
|
1517
|
+
}
|
|
1518
|
+
createEvent(eventInterface) {
|
|
1519
|
+
switch (String(eventInterface).toLowerCase()) {
|
|
1520
|
+
case "customevent":
|
|
1521
|
+
return new CustomEvent("");
|
|
1522
|
+
case "event":
|
|
1523
|
+
case "events":
|
|
1524
|
+
case "htmlevents":
|
|
1525
|
+
return new Event("");
|
|
1526
|
+
case "uievent":
|
|
1527
|
+
case "uievents":
|
|
1528
|
+
return new UIEvent("");
|
|
1529
|
+
case "mouseevent":
|
|
1530
|
+
case "mouseevents":
|
|
1531
|
+
return new MouseEvent("");
|
|
1532
|
+
case "pointerevent":
|
|
1533
|
+
case "pointerevents":
|
|
1534
|
+
return new PointerEvent("");
|
|
1535
|
+
case "keyboardevent":
|
|
1536
|
+
case "keyboardevents":
|
|
1537
|
+
return new KeyboardEvent("");
|
|
1538
|
+
case "focusevent":
|
|
1539
|
+
case "focusevents":
|
|
1540
|
+
return new FocusEvent("");
|
|
1541
|
+
case "inputevent":
|
|
1542
|
+
case "inputevents":
|
|
1543
|
+
return new InputEvent("");
|
|
1544
|
+
case "clipboardevent":
|
|
1545
|
+
case "clipboardevents":
|
|
1546
|
+
return new ClipboardEvent("");
|
|
1547
|
+
case "touchevent":
|
|
1548
|
+
case "touchevents":
|
|
1549
|
+
return new TouchEvent("");
|
|
1550
|
+
default:
|
|
1551
|
+
throw new DOMException(`The event interface "${eventInterface}" is not supported.`, "NotSupportedError");
|
|
1552
|
+
}
|
|
1553
|
+
}
|
|
1554
|
+
getSelection() {
|
|
1555
|
+
return this.defaultView.getSelection();
|
|
1556
|
+
}
|
|
1557
|
+
createTreeWalker(root, whatToShow = NodeFilter.SHOW_ALL, filter = null) {
|
|
1558
|
+
return new TreeWalker(root, whatToShow, filter);
|
|
1559
|
+
}
|
|
1560
|
+
createNodeIterator(root, whatToShow = NodeFilter.SHOW_ALL, filter = null) {
|
|
1561
|
+
return new NodeIterator(root, whatToShow, filter);
|
|
1562
|
+
}
|
|
1563
|
+
importNode(node, deep = false) {
|
|
1564
|
+
return importNodeIntoDocument(this, node, deep);
|
|
1565
|
+
}
|
|
1566
|
+
adoptNode(node) {
|
|
1567
|
+
if (node instanceof Document) {
|
|
1568
|
+
throw new DOMException("Document nodes cannot be adopted.", "NotSupportedError");
|
|
1569
|
+
}
|
|
1570
|
+
if (node.ownerDocument === this) {
|
|
1571
|
+
node.parentNode?.removeChild(node);
|
|
1572
|
+
return node;
|
|
1573
|
+
}
|
|
1574
|
+
const adopted = importNodeIntoDocument(this, node, true);
|
|
1575
|
+
node.parentNode?.removeChild(node);
|
|
1576
|
+
return adopted;
|
|
1577
|
+
}
|
|
1578
|
+
getElementsByTagName(tagName) {
|
|
1579
|
+
return this.querySelectorAll(tagName);
|
|
1580
|
+
}
|
|
1581
|
+
getElementsByClassName(classNames) {
|
|
1582
|
+
return new NativeNodeList(this, this._elementsByClassName(this.#documentNodeId, String(classNames)));
|
|
1583
|
+
}
|
|
1584
|
+
getElementsByName(name) {
|
|
1585
|
+
return new NativeNodeList(this, this._native.elementsByName(this.#documentNodeId, String(name)));
|
|
1586
|
+
}
|
|
1587
|
+
_setActiveElement(element) {
|
|
1588
|
+
this.#activeElement = element;
|
|
1589
|
+
}
|
|
1590
|
+
_replaceWithHtml(html) {
|
|
1591
|
+
if (runtimeStats.enabled) {
|
|
1592
|
+
recordNativeCall("parseHtmlDocumentNative");
|
|
1593
|
+
}
|
|
1594
|
+
this._native = prepareNativeDocument(parseHtmlDocumentNative(html));
|
|
1595
|
+
this.#wrappers = new Map();
|
|
1596
|
+
this.#activeElement = null;
|
|
1597
|
+
this.#documentNodeId = this._native.documentNode();
|
|
1598
|
+
this.#documentElementId = this._native.documentElement();
|
|
1599
|
+
this.#headId = this._native.head();
|
|
1600
|
+
this.#bodyId = this._native.body();
|
|
1601
|
+
this.#namespaces.clear();
|
|
1602
|
+
this.#mutationVersion++;
|
|
1603
|
+
this.#queryAllCache.clear();
|
|
1604
|
+
this.#queryOneCache.clear();
|
|
1605
|
+
this.#classNameCache.clear();
|
|
1606
|
+
this.#matchesCache.clear();
|
|
1607
|
+
this.#closestCache.clear();
|
|
1608
|
+
this.#lastQueryAllRootId = null;
|
|
1609
|
+
this.#lastQueryOneRootId = null;
|
|
1610
|
+
this.#lastClassNameRootId = null;
|
|
1611
|
+
this.#lastMatchesId = null;
|
|
1612
|
+
this.#lastClosestId = null;
|
|
1613
|
+
this._id = this.#documentNodeId;
|
|
1614
|
+
}
|
|
1615
|
+
_mutationVersion() {
|
|
1616
|
+
return this.#mutationVersion;
|
|
1617
|
+
}
|
|
1618
|
+
_documentNodeId() {
|
|
1619
|
+
return this.#documentNodeId;
|
|
1620
|
+
}
|
|
1621
|
+
_storeWrapper(id, node) {
|
|
1622
|
+
this.#wrappers.set(id, node);
|
|
1623
|
+
}
|
|
1624
|
+
_hasCustomElementDefinitions() {
|
|
1625
|
+
if (runtimeStats.enabled) {
|
|
1626
|
+
recordOperation("customElementCheckCalls");
|
|
1627
|
+
}
|
|
1628
|
+
const registry = this.defaultView.customElements;
|
|
1629
|
+
const version = registry._version();
|
|
1630
|
+
if (version !== this.#customElementRegistryVersion) {
|
|
1631
|
+
if (runtimeStats.enabled) {
|
|
1632
|
+
recordOperation("customElementRegistryReads");
|
|
1633
|
+
}
|
|
1634
|
+
this.#customElementRegistryVersion = version;
|
|
1635
|
+
this.#hasCustomElementDefinitions = registry._hasDefinitions();
|
|
1636
|
+
}
|
|
1637
|
+
return this.#hasCustomElementDefinitions;
|
|
1638
|
+
}
|
|
1639
|
+
_bumpMutationVersion() {
|
|
1640
|
+
if (runtimeStats.enabled) {
|
|
1641
|
+
recordOperation("mutationBumps");
|
|
1642
|
+
}
|
|
1643
|
+
this.#mutationVersion++;
|
|
1644
|
+
// Cache entries are version-tagged, so hot mutation loops only need to
|
|
1645
|
+
// advance the version. Periodic pruning bounds stale entries.
|
|
1646
|
+
if ((this.#mutationVersion & 1023) === 0 &&
|
|
1647
|
+
(this.#queryAllCache.size > 0 ||
|
|
1648
|
+
this.#queryOneCache.size > 0 ||
|
|
1649
|
+
this.#classNameCache.size > 0 ||
|
|
1650
|
+
this.#matchesCache.size > 0 ||
|
|
1651
|
+
this.#closestCache.size > 0)) {
|
|
1652
|
+
this.#queryAllCache.clear();
|
|
1653
|
+
this.#queryOneCache.clear();
|
|
1654
|
+
this.#classNameCache.clear();
|
|
1655
|
+
this.#matchesCache.clear();
|
|
1656
|
+
this.#closestCache.clear();
|
|
1657
|
+
}
|
|
1658
|
+
}
|
|
1659
|
+
_namespaceFor(id) {
|
|
1660
|
+
return this.#namespaces.get(id) ?? HTML_NAMESPACE;
|
|
1661
|
+
}
|
|
1662
|
+
_querySelectorAll(rootId, selector) {
|
|
1663
|
+
if (this.#lastQueryAllVersion === this.#mutationVersion &&
|
|
1664
|
+
this.#lastQueryAllRootId === rootId &&
|
|
1665
|
+
this.#lastQueryAllSelector === selector) {
|
|
1666
|
+
return this.#lastQueryAllIds;
|
|
1667
|
+
}
|
|
1668
|
+
const key = `${rootId}\u0000${selector}`;
|
|
1669
|
+
const cached = this.#queryAllCache.get(key);
|
|
1670
|
+
if (cached?.version === this.#mutationVersion) {
|
|
1671
|
+
this.#lastQueryAllRootId = rootId;
|
|
1672
|
+
this.#lastQueryAllSelector = selector;
|
|
1673
|
+
this.#lastQueryAllVersion = this.#mutationVersion;
|
|
1674
|
+
this.#lastQueryAllIds = cached.ids;
|
|
1675
|
+
return cached.ids;
|
|
1676
|
+
}
|
|
1677
|
+
const ids = this._native.querySelectorAll(rootId, selector);
|
|
1678
|
+
this.#queryAllCache.set(key, {
|
|
1679
|
+
version: this.#mutationVersion,
|
|
1680
|
+
ids
|
|
1681
|
+
});
|
|
1682
|
+
this.#lastQueryAllRootId = rootId;
|
|
1683
|
+
this.#lastQueryAllSelector = selector;
|
|
1684
|
+
this.#lastQueryAllVersion = this.#mutationVersion;
|
|
1685
|
+
this.#lastQueryAllIds = ids;
|
|
1686
|
+
return ids;
|
|
1687
|
+
}
|
|
1688
|
+
_querySelector(rootId, selector) {
|
|
1689
|
+
if (this.#lastQueryOneVersion === this.#mutationVersion &&
|
|
1690
|
+
this.#lastQueryOneRootId === rootId &&
|
|
1691
|
+
this.#lastQueryOneSelector === selector) {
|
|
1692
|
+
return this.#lastQueryOneId;
|
|
1693
|
+
}
|
|
1694
|
+
const key = `${rootId}\u0000${selector}`;
|
|
1695
|
+
const cached = this.#queryOneCache.get(key);
|
|
1696
|
+
if (cached?.version === this.#mutationVersion) {
|
|
1697
|
+
this.#lastQueryOneRootId = rootId;
|
|
1698
|
+
this.#lastQueryOneSelector = selector;
|
|
1699
|
+
this.#lastQueryOneVersion = this.#mutationVersion;
|
|
1700
|
+
this.#lastQueryOneId = cached.id;
|
|
1701
|
+
return cached.id;
|
|
1702
|
+
}
|
|
1703
|
+
const id = this._native.querySelector(rootId, selector) ?? null;
|
|
1704
|
+
this.#queryOneCache.set(key, {
|
|
1705
|
+
version: this.#mutationVersion,
|
|
1706
|
+
id
|
|
1707
|
+
});
|
|
1708
|
+
this.#lastQueryOneRootId = rootId;
|
|
1709
|
+
this.#lastQueryOneSelector = selector;
|
|
1710
|
+
this.#lastQueryOneVersion = this.#mutationVersion;
|
|
1711
|
+
this.#lastQueryOneId = id;
|
|
1712
|
+
return id;
|
|
1713
|
+
}
|
|
1714
|
+
_elementsByClassName(rootId, classNames) {
|
|
1715
|
+
if (this.#lastClassNameVersion === this.#mutationVersion &&
|
|
1716
|
+
this.#lastClassNameRootId === rootId &&
|
|
1717
|
+
this.#lastClassNameSelector === classNames) {
|
|
1718
|
+
return this.#lastClassNameIds;
|
|
1719
|
+
}
|
|
1720
|
+
const key = `${rootId}\u0000${classNames}`;
|
|
1721
|
+
const cached = this.#classNameCache.get(key);
|
|
1722
|
+
if (cached?.version === this.#mutationVersion) {
|
|
1723
|
+
this.#lastClassNameRootId = rootId;
|
|
1724
|
+
this.#lastClassNameSelector = classNames;
|
|
1725
|
+
this.#lastClassNameVersion = this.#mutationVersion;
|
|
1726
|
+
this.#lastClassNameIds = cached.ids;
|
|
1727
|
+
return cached.ids;
|
|
1728
|
+
}
|
|
1729
|
+
const ids = this._native.elementsByClassName(rootId, classNames);
|
|
1730
|
+
this.#classNameCache.set(key, {
|
|
1731
|
+
version: this.#mutationVersion,
|
|
1732
|
+
ids
|
|
1733
|
+
});
|
|
1734
|
+
this.#lastClassNameRootId = rootId;
|
|
1735
|
+
this.#lastClassNameSelector = classNames;
|
|
1736
|
+
this.#lastClassNameVersion = this.#mutationVersion;
|
|
1737
|
+
this.#lastClassNameIds = ids;
|
|
1738
|
+
return ids;
|
|
1739
|
+
}
|
|
1740
|
+
_matchesSelector(id, selector) {
|
|
1741
|
+
if (this.#lastMatchesVersion === this.#mutationVersion &&
|
|
1742
|
+
this.#lastMatchesId === id &&
|
|
1743
|
+
this.#lastMatchesSelector === selector) {
|
|
1744
|
+
return this.#lastMatchesResult;
|
|
1745
|
+
}
|
|
1746
|
+
const key = `${id}\u0000${selector}`;
|
|
1747
|
+
const cached = this.#matchesCache.get(key);
|
|
1748
|
+
if (cached?.version === this.#mutationVersion) {
|
|
1749
|
+
this.#lastMatchesId = id;
|
|
1750
|
+
this.#lastMatchesSelector = selector;
|
|
1751
|
+
this.#lastMatchesVersion = this.#mutationVersion;
|
|
1752
|
+
this.#lastMatchesResult = cached.result;
|
|
1753
|
+
return cached.result;
|
|
1754
|
+
}
|
|
1755
|
+
const result = this._native.matchesSelector(id, selector);
|
|
1756
|
+
this.#matchesCache.set(key, {
|
|
1757
|
+
version: this.#mutationVersion,
|
|
1758
|
+
result
|
|
1759
|
+
});
|
|
1760
|
+
this.#lastMatchesId = id;
|
|
1761
|
+
this.#lastMatchesSelector = selector;
|
|
1762
|
+
this.#lastMatchesVersion = this.#mutationVersion;
|
|
1763
|
+
this.#lastMatchesResult = result;
|
|
1764
|
+
return result;
|
|
1765
|
+
}
|
|
1766
|
+
_closest(id, selector) {
|
|
1767
|
+
if (this.#lastClosestVersion === this.#mutationVersion &&
|
|
1768
|
+
this.#lastClosestId === id &&
|
|
1769
|
+
this.#lastClosestSelector === selector) {
|
|
1770
|
+
return this.#lastClosestResult;
|
|
1771
|
+
}
|
|
1772
|
+
const key = `${id}\u0000${selector}`;
|
|
1773
|
+
const cached = this.#closestCache.get(key);
|
|
1774
|
+
if (cached?.version === this.#mutationVersion) {
|
|
1775
|
+
this.#lastClosestId = id;
|
|
1776
|
+
this.#lastClosestSelector = selector;
|
|
1777
|
+
this.#lastClosestVersion = this.#mutationVersion;
|
|
1778
|
+
this.#lastClosestResult = cached.id;
|
|
1779
|
+
return cached.id;
|
|
1780
|
+
}
|
|
1781
|
+
const result = this._native.closest(id, selector) ?? null;
|
|
1782
|
+
this.#closestCache.set(key, {
|
|
1783
|
+
version: this.#mutationVersion,
|
|
1784
|
+
id: result
|
|
1785
|
+
});
|
|
1786
|
+
this.#lastClosestId = id;
|
|
1787
|
+
this.#lastClosestSelector = selector;
|
|
1788
|
+
this.#lastClosestVersion = this.#mutationVersion;
|
|
1789
|
+
this.#lastClosestResult = result;
|
|
1790
|
+
return result;
|
|
1791
|
+
}
|
|
1792
|
+
_wrapCreatedHTMLElement(id, nodeName) {
|
|
1793
|
+
const wrapper = createHTMLElementWrapper(this, id, nodeName);
|
|
1794
|
+
this.#wrappers.set(id, wrapper);
|
|
1795
|
+
if (runtimeStats.enabled) {
|
|
1796
|
+
recordWrapperCreated(nodeName);
|
|
1797
|
+
}
|
|
1798
|
+
return wrapper;
|
|
1799
|
+
}
|
|
1800
|
+
_wrap(id, knownNodeName = null) {
|
|
1801
|
+
if (id === this.#documentNodeId) {
|
|
1802
|
+
if (runtimeStats.enabled) {
|
|
1803
|
+
runtimeStats.wrappers.documentHits++;
|
|
1804
|
+
}
|
|
1805
|
+
return this;
|
|
1806
|
+
}
|
|
1807
|
+
const existing = this.#wrappers.get(id);
|
|
1808
|
+
if (existing) {
|
|
1809
|
+
if (runtimeStats.enabled) {
|
|
1810
|
+
runtimeStats.wrappers.cacheHits++;
|
|
1811
|
+
}
|
|
1812
|
+
return existing;
|
|
1813
|
+
}
|
|
1814
|
+
if (knownNodeName != null) {
|
|
1815
|
+
const wrapper = knownNodeName === "#text"
|
|
1816
|
+
? new Text(this, id, knownNodeName)
|
|
1817
|
+
: knownNodeName === "#comment"
|
|
1818
|
+
? new Comment(this, id, knownNodeName)
|
|
1819
|
+
: knownNodeName === "#document-fragment"
|
|
1820
|
+
? new DocumentFragment(this, id, knownNodeName)
|
|
1821
|
+
: this.#namespaces.get(id) === SVG_NAMESPACE
|
|
1822
|
+
? new SVGElement(this, id, knownNodeName)
|
|
1823
|
+
: this.#namespaces.get(id) === MATHML_NAMESPACE
|
|
1824
|
+
? new MathMLElement(this, id, knownNodeName)
|
|
1825
|
+
: createHTMLElementWrapper(this, id, knownNodeName);
|
|
1826
|
+
this.#wrappers.set(id, wrapper);
|
|
1827
|
+
if (runtimeStats.enabled) {
|
|
1828
|
+
recordWrapperCreated(knownNodeName);
|
|
1829
|
+
}
|
|
1830
|
+
return wrapper;
|
|
1831
|
+
}
|
|
1832
|
+
const nodeType = this._native.nodeType(id);
|
|
1833
|
+
const nodeName = this._native.nodeName(id);
|
|
1834
|
+
const wrapper = nodeType === Node.TEXT_NODE
|
|
1835
|
+
? new Text(this, id, nodeName)
|
|
1836
|
+
: nodeType === Node.COMMENT_NODE
|
|
1837
|
+
? new Comment(this, id, nodeName)
|
|
1838
|
+
: nodeType === Node.DOCUMENT_TYPE_NODE
|
|
1839
|
+
? new DocumentType(this, id, nodeName)
|
|
1840
|
+
: nodeType === Node.DOCUMENT_FRAGMENT_NODE
|
|
1841
|
+
? new DocumentFragment(this, id, nodeName)
|
|
1842
|
+
: this.#namespaces.get(id) === SVG_NAMESPACE
|
|
1843
|
+
? new SVGElement(this, id, nodeName)
|
|
1844
|
+
: this.#namespaces.get(id) === MATHML_NAMESPACE
|
|
1845
|
+
? new MathMLElement(this, id, nodeName)
|
|
1846
|
+
: createHTMLElementWrapper(this, id, nodeName);
|
|
1847
|
+
this.#wrappers.set(id, wrapper);
|
|
1848
|
+
if (runtimeStats.enabled) {
|
|
1849
|
+
recordWrapperCreated(nodeName);
|
|
1850
|
+
}
|
|
1851
|
+
return wrapper;
|
|
1852
|
+
}
|
|
1853
|
+
}
|
|
1854
|
+
function importNodeIntoDocument(document, node, deep) {
|
|
1855
|
+
switch (node.nodeType) {
|
|
1856
|
+
case Node.ELEMENT_NODE: {
|
|
1857
|
+
const element = node;
|
|
1858
|
+
const clone = document.createElement(element.localName);
|
|
1859
|
+
for (const attribute of element.attributes) {
|
|
1860
|
+
clone.setAttribute(attribute.name, attribute.value);
|
|
1861
|
+
}
|
|
1862
|
+
if (deep) {
|
|
1863
|
+
appendImportedChildren(document, clone, element instanceof HTMLTemplateElement ? element.content : element);
|
|
1864
|
+
}
|
|
1865
|
+
return clone;
|
|
1866
|
+
}
|
|
1867
|
+
case Node.TEXT_NODE:
|
|
1868
|
+
return document.createTextNode(node.nodeValue ?? "");
|
|
1869
|
+
case Node.COMMENT_NODE:
|
|
1870
|
+
return document.createComment(node.nodeValue ?? "");
|
|
1871
|
+
case Node.DOCUMENT_TYPE_NODE: {
|
|
1872
|
+
const documentType = node;
|
|
1873
|
+
return document.implementation.createDocumentType(documentType.name, documentType.publicId, documentType.systemId);
|
|
1874
|
+
}
|
|
1875
|
+
case Node.DOCUMENT_FRAGMENT_NODE: {
|
|
1876
|
+
const fragment = document.createDocumentFragment();
|
|
1877
|
+
if (deep) {
|
|
1878
|
+
appendImportedChildren(document, fragment, node);
|
|
1879
|
+
}
|
|
1880
|
+
return fragment;
|
|
1881
|
+
}
|
|
1882
|
+
default: {
|
|
1883
|
+
const fragment = document.createDocumentFragment();
|
|
1884
|
+
if (deep) {
|
|
1885
|
+
appendImportedChildren(document, fragment, node);
|
|
1886
|
+
}
|
|
1887
|
+
return fragment;
|
|
1888
|
+
}
|
|
1889
|
+
}
|
|
1890
|
+
}
|
|
1891
|
+
function appendImportedChildren(document, clone, source) {
|
|
1892
|
+
for (const child of source.childNodes) {
|
|
1893
|
+
clone.appendChild(importNodeIntoDocument(document, child, true));
|
|
1894
|
+
}
|
|
1895
|
+
}
|
|
1896
|
+
function createHTMLElementWrapper(document, id, nodeName) {
|
|
1897
|
+
switch (nodeName) {
|
|
1898
|
+
case "BUTTON":
|
|
1899
|
+
return new HTMLButtonElement(document, id, nodeName);
|
|
1900
|
+
case "CANVAS":
|
|
1901
|
+
return new HTMLCanvasElement(document, id, nodeName);
|
|
1902
|
+
case "FORM":
|
|
1903
|
+
return new HTMLFormElement(document, id, nodeName);
|
|
1904
|
+
case "HTML":
|
|
1905
|
+
return new HTMLHtmlElement(document, id, nodeName);
|
|
1906
|
+
case "BODY":
|
|
1907
|
+
return new HTMLBodyElement(document, id, nodeName);
|
|
1908
|
+
case "IMG":
|
|
1909
|
+
return new HTMLImageElement(document, id, nodeName);
|
|
1910
|
+
case "INPUT":
|
|
1911
|
+
return new HTMLInputElement(document, id, nodeName);
|
|
1912
|
+
case "LINK":
|
|
1913
|
+
return new HTMLLinkElement(document, id, nodeName);
|
|
1914
|
+
case "OPTION":
|
|
1915
|
+
return new HTMLOptionElement(document, id, nodeName);
|
|
1916
|
+
case "SCRIPT":
|
|
1917
|
+
return new HTMLScriptElement(document, id, nodeName);
|
|
1918
|
+
case "SELECT":
|
|
1919
|
+
return new HTMLSelectElement(document, id, nodeName);
|
|
1920
|
+
case "STYLE":
|
|
1921
|
+
return new HTMLStyleElement(document, id, nodeName);
|
|
1922
|
+
case "TABLE":
|
|
1923
|
+
return new HTMLTableElement(document, id, nodeName);
|
|
1924
|
+
case "TBODY":
|
|
1925
|
+
case "TFOOT":
|
|
1926
|
+
case "THEAD":
|
|
1927
|
+
return new HTMLTableSectionElement(document, id, nodeName);
|
|
1928
|
+
case "TD":
|
|
1929
|
+
case "TH":
|
|
1930
|
+
return new HTMLTableCellElement(document, id, nodeName);
|
|
1931
|
+
case "TEMPLATE":
|
|
1932
|
+
return new HTMLTemplateElement(document, id, nodeName);
|
|
1933
|
+
case "TR":
|
|
1934
|
+
return new HTMLTableRowElement(document, id, nodeName);
|
|
1935
|
+
case "TEXTAREA":
|
|
1936
|
+
return new HTMLTextAreaElement(document, id, nodeName);
|
|
1937
|
+
default:
|
|
1938
|
+
return new HTMLElement(document, id, nodeName);
|
|
1939
|
+
}
|
|
1940
|
+
}
|
|
1941
|
+
export class Element extends Node {
|
|
1942
|
+
#classList = null;
|
|
1943
|
+
#dataset = null;
|
|
1944
|
+
#localName = null;
|
|
1945
|
+
#shadowRoot = null;
|
|
1946
|
+
#style = null;
|
|
1947
|
+
get children() {
|
|
1948
|
+
return new NativeNodeList(this._document, this._document._native.elementChildren(this._id));
|
|
1949
|
+
}
|
|
1950
|
+
get childElementCount() {
|
|
1951
|
+
return this._document._native.childElementCount(this._id);
|
|
1952
|
+
}
|
|
1953
|
+
get firstElementChild() {
|
|
1954
|
+
const id = this._document._native.firstElementChild(this._id);
|
|
1955
|
+
return id == null ? null : this._document._wrap(id);
|
|
1956
|
+
}
|
|
1957
|
+
get lastElementChild() {
|
|
1958
|
+
const id = this._document._native.lastElementChild(this._id);
|
|
1959
|
+
return id == null ? null : this._document._wrap(id);
|
|
1960
|
+
}
|
|
1961
|
+
get previousElementSibling() {
|
|
1962
|
+
const id = this._document._native.previousElementSibling(this._id);
|
|
1963
|
+
return id == null ? null : this._document._wrap(id);
|
|
1964
|
+
}
|
|
1965
|
+
get nextElementSibling() {
|
|
1966
|
+
const id = this._document._native.nextElementSibling(this._id);
|
|
1967
|
+
return id == null ? null : this._document._wrap(id);
|
|
1968
|
+
}
|
|
1969
|
+
get tagName() {
|
|
1970
|
+
return this.nodeName;
|
|
1971
|
+
}
|
|
1972
|
+
get localName() {
|
|
1973
|
+
this.#localName ??= this.nodeName.toLowerCase();
|
|
1974
|
+
return this.#localName;
|
|
1975
|
+
}
|
|
1976
|
+
get namespaceURI() {
|
|
1977
|
+
return this._document._namespaceFor(this._id);
|
|
1978
|
+
}
|
|
1979
|
+
get shadowRoot() {
|
|
1980
|
+
return this.#shadowRoot?.mode === "open" ? this.#shadowRoot : null;
|
|
1981
|
+
}
|
|
1982
|
+
attachShadow(init) {
|
|
1983
|
+
if (this.#shadowRoot) {
|
|
1984
|
+
throw new DOMException("Shadow root has already been attached.", "DOMException");
|
|
1985
|
+
}
|
|
1986
|
+
const mode = init.mode;
|
|
1987
|
+
if (mode !== "open" && mode !== "closed") {
|
|
1988
|
+
throw new TypeError("Shadow root mode must be \"open\" or \"closed\".");
|
|
1989
|
+
}
|
|
1990
|
+
const root = new ShadowRoot(this._document, this._document._native.createDocumentFragment(), this, mode);
|
|
1991
|
+
this.#shadowRoot = root;
|
|
1992
|
+
return root;
|
|
1993
|
+
}
|
|
1994
|
+
get innerHTML() {
|
|
1995
|
+
return this._document._native.serializeChildren(this._id);
|
|
1996
|
+
}
|
|
1997
|
+
set innerHTML(html) {
|
|
1998
|
+
if (!hasMutationObservers()) {
|
|
1999
|
+
this._document._native.setInnerHtml(this._id, html);
|
|
2000
|
+
this._document._bumpMutationVersion();
|
|
2001
|
+
return;
|
|
2002
|
+
}
|
|
2003
|
+
const removedNodes = [...this.childNodes];
|
|
2004
|
+
this._document._native.setInnerHtml(this._id, html);
|
|
2005
|
+
this._document._bumpMutationVersion();
|
|
2006
|
+
notifyMutation({
|
|
2007
|
+
type: "childList",
|
|
2008
|
+
target: this,
|
|
2009
|
+
addedNodes: [...this.childNodes],
|
|
2010
|
+
removedNodes,
|
|
2011
|
+
attributeName: null,
|
|
2012
|
+
oldValue: null
|
|
2013
|
+
});
|
|
2014
|
+
}
|
|
2015
|
+
get outerHTML() {
|
|
2016
|
+
return this._document._native.serializeNode(this._id);
|
|
2017
|
+
}
|
|
2018
|
+
set outerHTML(html) {
|
|
2019
|
+
const parentId = this._document._native.parentNode(this._id);
|
|
2020
|
+
if (parentId == null) {
|
|
2021
|
+
return;
|
|
2022
|
+
}
|
|
2023
|
+
if (!hasMutationObservers() && !this._document._hasCustomElementDefinitions()) {
|
|
2024
|
+
if (this._document._native.replaceWithHtmlFragment(this._id, html, "div")) {
|
|
2025
|
+
this._document._bumpMutationVersion();
|
|
2026
|
+
}
|
|
2027
|
+
return;
|
|
2028
|
+
}
|
|
2029
|
+
const parent = this._document._wrap(parentId);
|
|
2030
|
+
const fragment = fragmentFromHtml(this._document, html);
|
|
2031
|
+
parent.insertBefore(fragment, this);
|
|
2032
|
+
parent.removeChild(this);
|
|
2033
|
+
}
|
|
2034
|
+
get id() {
|
|
2035
|
+
return this.getAttribute("id") ?? "";
|
|
2036
|
+
}
|
|
2037
|
+
set id(value) {
|
|
2038
|
+
this.setAttribute("id", value);
|
|
2039
|
+
}
|
|
2040
|
+
get className() {
|
|
2041
|
+
return this.getAttribute("class") ?? "";
|
|
2042
|
+
}
|
|
2043
|
+
set className(value) {
|
|
2044
|
+
this.setAttribute("class", value);
|
|
2045
|
+
}
|
|
2046
|
+
get classList() {
|
|
2047
|
+
this.#classList ??= new DOMTokenList(this, "class");
|
|
2048
|
+
return this.#classList;
|
|
2049
|
+
}
|
|
2050
|
+
get dataset() {
|
|
2051
|
+
this.#dataset ??= createDataset(this);
|
|
2052
|
+
return this.#dataset;
|
|
2053
|
+
}
|
|
2054
|
+
get style() {
|
|
2055
|
+
this.#style ??= new CSSStyleDeclaration(this.getAttribute("style") ?? "", this);
|
|
2056
|
+
return this.#style;
|
|
2057
|
+
}
|
|
2058
|
+
get clientWidth() {
|
|
2059
|
+
return elementBox(this).width;
|
|
2060
|
+
}
|
|
2061
|
+
get clientHeight() {
|
|
2062
|
+
return elementBox(this).height;
|
|
2063
|
+
}
|
|
2064
|
+
get scrollWidth() {
|
|
2065
|
+
return this.clientWidth;
|
|
2066
|
+
}
|
|
2067
|
+
get scrollHeight() {
|
|
2068
|
+
return this.clientHeight;
|
|
2069
|
+
}
|
|
2070
|
+
get offsetWidth() {
|
|
2071
|
+
return elementBox(this).width;
|
|
2072
|
+
}
|
|
2073
|
+
get offsetHeight() {
|
|
2074
|
+
return elementBox(this).height;
|
|
2075
|
+
}
|
|
2076
|
+
getBoundingClientRect() {
|
|
2077
|
+
const box = elementBox(this);
|
|
2078
|
+
return new DOMRect(box.left, box.top, box.width, box.height);
|
|
2079
|
+
}
|
|
2080
|
+
getClientRects() {
|
|
2081
|
+
if (this.ownerDocument && this.isConnected && elementDisplay(this) !== "none") {
|
|
2082
|
+
return [this.getBoundingClientRect()];
|
|
2083
|
+
}
|
|
2084
|
+
return [];
|
|
2085
|
+
}
|
|
2086
|
+
setAttribute(name, value) {
|
|
2087
|
+
if (runtimeStats.enabled) {
|
|
2088
|
+
recordOperation("setAttribute");
|
|
2089
|
+
}
|
|
2090
|
+
const normalizedName = this.#normalizeAttributeName(name);
|
|
2091
|
+
const stringValue = String(value);
|
|
2092
|
+
const hasObservers = hasMutationObservers();
|
|
2093
|
+
const hasCustomElements = this._document._hasCustomElementDefinitions();
|
|
2094
|
+
if (!hasObservers && !hasCustomElements) {
|
|
2095
|
+
this._document._native.setAttribute(this._id, normalizedName, stringValue);
|
|
2096
|
+
this._document._bumpMutationVersion();
|
|
2097
|
+
return;
|
|
2098
|
+
}
|
|
2099
|
+
const oldValue = this.getAttribute(normalizedName);
|
|
2100
|
+
this._document._native.setAttribute(this._id, normalizedName, stringValue);
|
|
2101
|
+
this._document._bumpMutationVersion();
|
|
2102
|
+
if (hasCustomElements) {
|
|
2103
|
+
notifyCustomElementAttributeChanged(this, normalizedName, oldValue, stringValue);
|
|
2104
|
+
}
|
|
2105
|
+
if (hasObservers) {
|
|
2106
|
+
notifyMutation({
|
|
2107
|
+
type: "attributes",
|
|
2108
|
+
target: this,
|
|
2109
|
+
addedNodes: [],
|
|
2110
|
+
removedNodes: [],
|
|
2111
|
+
attributeName: normalizedName,
|
|
2112
|
+
oldValue
|
|
2113
|
+
});
|
|
2114
|
+
}
|
|
2115
|
+
}
|
|
2116
|
+
getAttribute(name) {
|
|
2117
|
+
return this._document._native.getAttribute(this._id, this.#normalizeAttributeName(name));
|
|
2118
|
+
}
|
|
2119
|
+
getAttributeNode(name) {
|
|
2120
|
+
const normalizedName = this.#normalizeAttributeName(name);
|
|
2121
|
+
const value = this.getAttribute(normalizedName);
|
|
2122
|
+
return value == null
|
|
2123
|
+
? null
|
|
2124
|
+
: {
|
|
2125
|
+
localName: normalizedName,
|
|
2126
|
+
name: normalizedName,
|
|
2127
|
+
value
|
|
2128
|
+
};
|
|
2129
|
+
}
|
|
2130
|
+
hasAttribute(name) {
|
|
2131
|
+
return this.getAttribute(name) !== null;
|
|
2132
|
+
}
|
|
2133
|
+
hasAttributes() {
|
|
2134
|
+
return this.getAttributeNames().length > 0;
|
|
2135
|
+
}
|
|
2136
|
+
getAttributeNames() {
|
|
2137
|
+
return this._document._native.attributeNames(this._id);
|
|
2138
|
+
}
|
|
2139
|
+
get attributes() {
|
|
2140
|
+
return new NamedNodeMap(this.getAttributeNames().map((name) => ({
|
|
2141
|
+
localName: name,
|
|
2142
|
+
name,
|
|
2143
|
+
value: this.getAttribute(name) ?? ""
|
|
2144
|
+
})));
|
|
2145
|
+
}
|
|
2146
|
+
matches(selector) {
|
|
2147
|
+
try {
|
|
2148
|
+
return this._document._matchesSelector(this._id, selector);
|
|
2149
|
+
}
|
|
2150
|
+
catch {
|
|
2151
|
+
return false;
|
|
2152
|
+
}
|
|
2153
|
+
}
|
|
2154
|
+
scrollIntoView(_arg) { }
|
|
2155
|
+
removeAttribute(name) {
|
|
2156
|
+
if (runtimeStats.enabled) {
|
|
2157
|
+
recordOperation("removeAttribute");
|
|
2158
|
+
}
|
|
2159
|
+
const normalizedName = this.#normalizeAttributeName(name);
|
|
2160
|
+
const oldValue = this.getAttribute(normalizedName);
|
|
2161
|
+
if (oldValue === null) {
|
|
2162
|
+
return;
|
|
2163
|
+
}
|
|
2164
|
+
if (!hasMutationObservers()) {
|
|
2165
|
+
this._document._native.removeAttribute(this._id, normalizedName);
|
|
2166
|
+
this._document._bumpMutationVersion();
|
|
2167
|
+
notifyCustomElementAttributeChanged(this, normalizedName, oldValue, null);
|
|
2168
|
+
return;
|
|
2169
|
+
}
|
|
2170
|
+
this._document._native.removeAttribute(this._id, normalizedName);
|
|
2171
|
+
this._document._bumpMutationVersion();
|
|
2172
|
+
notifyCustomElementAttributeChanged(this, normalizedName, oldValue, null);
|
|
2173
|
+
notifyMutation({
|
|
2174
|
+
type: "attributes",
|
|
2175
|
+
target: this,
|
|
2176
|
+
addedNodes: [],
|
|
2177
|
+
removedNodes: [],
|
|
2178
|
+
attributeName: normalizedName,
|
|
2179
|
+
oldValue
|
|
2180
|
+
});
|
|
2181
|
+
}
|
|
2182
|
+
toggleAttribute(name, force) {
|
|
2183
|
+
if (force === true) {
|
|
2184
|
+
this.setAttribute(name, "");
|
|
2185
|
+
return true;
|
|
2186
|
+
}
|
|
2187
|
+
if (force === false) {
|
|
2188
|
+
this.removeAttribute(name);
|
|
2189
|
+
return false;
|
|
2190
|
+
}
|
|
2191
|
+
if (this.hasAttribute(name)) {
|
|
2192
|
+
this.removeAttribute(name);
|
|
2193
|
+
return false;
|
|
2194
|
+
}
|
|
2195
|
+
this.setAttribute(name, "");
|
|
2196
|
+
return true;
|
|
2197
|
+
}
|
|
2198
|
+
querySelector(selector) {
|
|
2199
|
+
const id = this._document._querySelector(this._id, selector);
|
|
2200
|
+
return id == null ? null : this._document._wrap(id);
|
|
2201
|
+
}
|
|
2202
|
+
querySelectorAll(selector) {
|
|
2203
|
+
return new NativeNodeList(this._document, this._document._querySelectorAll(this._id, selector));
|
|
2204
|
+
}
|
|
2205
|
+
closest(selector) {
|
|
2206
|
+
try {
|
|
2207
|
+
const id = this._document._closest(this._id, selector);
|
|
2208
|
+
return id == null ? null : this._document._wrap(id);
|
|
2209
|
+
}
|
|
2210
|
+
catch {
|
|
2211
|
+
return null;
|
|
2212
|
+
}
|
|
2213
|
+
}
|
|
2214
|
+
getElementsByTagName(tagName) {
|
|
2215
|
+
return this.querySelectorAll(tagName);
|
|
2216
|
+
}
|
|
2217
|
+
getElementsByClassName(classNames) {
|
|
2218
|
+
return new NativeNodeList(this._document, this._document._elementsByClassName(this._id, String(classNames)));
|
|
2219
|
+
}
|
|
2220
|
+
insertAdjacentElement(position, element) {
|
|
2221
|
+
return this.#insertAdjacentNode(position, element) ? element : null;
|
|
2222
|
+
}
|
|
2223
|
+
insertAdjacentHTML(position, html) {
|
|
2224
|
+
if (!hasMutationObservers() && !this._document._hasCustomElementDefinitions()) {
|
|
2225
|
+
const normalized = position.toLowerCase();
|
|
2226
|
+
let moved = false;
|
|
2227
|
+
switch (normalized) {
|
|
2228
|
+
case "beforebegin": {
|
|
2229
|
+
const parentId = this._document._native.parentNode(this._id);
|
|
2230
|
+
if (parentId != null) {
|
|
2231
|
+
moved = this._document._native.insertHtmlFragment(parentId, this._id, html, "div");
|
|
2232
|
+
}
|
|
2233
|
+
break;
|
|
2234
|
+
}
|
|
2235
|
+
case "afterbegin":
|
|
2236
|
+
moved = this._document._native.insertHtmlFragment(this._id, this._document._native.firstChild(this._id), html, "div");
|
|
2237
|
+
break;
|
|
2238
|
+
case "beforeend":
|
|
2239
|
+
moved = this._document._native.insertHtmlFragment(this._id, null, html, "div");
|
|
2240
|
+
break;
|
|
2241
|
+
case "afterend": {
|
|
2242
|
+
const parentId = this._document._native.parentNode(this._id);
|
|
2243
|
+
if (parentId != null) {
|
|
2244
|
+
moved = this._document._native.insertHtmlFragment(parentId, this._document._native.nextSibling(this._id), html, "div");
|
|
2245
|
+
}
|
|
2246
|
+
break;
|
|
2247
|
+
}
|
|
2248
|
+
default:
|
|
2249
|
+
throw new DOMException("Position must be one of beforebegin, afterbegin, beforeend, or afterend", "SyntaxError");
|
|
2250
|
+
}
|
|
2251
|
+
if (moved) {
|
|
2252
|
+
this._document._bumpMutationVersion();
|
|
2253
|
+
}
|
|
2254
|
+
return;
|
|
2255
|
+
}
|
|
2256
|
+
this.#insertAdjacentNode(position, fragmentFromHtml(this._document, html));
|
|
2257
|
+
}
|
|
2258
|
+
insertAdjacentText(position, data) {
|
|
2259
|
+
this.#insertAdjacentNode(position, this._document.createTextNode(String(data)));
|
|
2260
|
+
}
|
|
2261
|
+
#insertAdjacentNode(position, node) {
|
|
2262
|
+
switch (position.toLowerCase()) {
|
|
2263
|
+
case "beforebegin":
|
|
2264
|
+
return this.parentNode ? this.parentNode.insertBefore(node, this) : null;
|
|
2265
|
+
case "afterbegin":
|
|
2266
|
+
return this.insertBefore(node, this.firstChild);
|
|
2267
|
+
case "beforeend":
|
|
2268
|
+
return this.appendChild(node);
|
|
2269
|
+
case "afterend":
|
|
2270
|
+
return this.parentNode ? this.parentNode.insertBefore(node, this.nextSibling) : null;
|
|
2271
|
+
default:
|
|
2272
|
+
throw new DOMException("Position must be one of beforebegin, afterbegin, beforeend, or afterend", "SyntaxError");
|
|
2273
|
+
}
|
|
2274
|
+
}
|
|
2275
|
+
#normalizeAttributeName(name) {
|
|
2276
|
+
const value = String(name);
|
|
2277
|
+
return this.namespaceURI === HTML_NAMESPACE ? value.toLowerCase() : value;
|
|
2278
|
+
}
|
|
2279
|
+
}
|
|
2280
|
+
function elementBox(element) {
|
|
2281
|
+
if (elementDisplay(element) === "none") {
|
|
2282
|
+
return { left: 0, top: 0, width: 0, height: 0 };
|
|
2283
|
+
}
|
|
2284
|
+
const style = inlineStyleFor(element);
|
|
2285
|
+
return {
|
|
2286
|
+
left: pixelValue(style.getPropertyValue("left")),
|
|
2287
|
+
top: pixelValue(style.getPropertyValue("top")),
|
|
2288
|
+
width: pixelValue(style.getPropertyValue("width")),
|
|
2289
|
+
height: pixelValue(style.getPropertyValue("height"))
|
|
2290
|
+
};
|
|
2291
|
+
}
|
|
2292
|
+
function elementDisplay(element) {
|
|
2293
|
+
if (element.hasAttribute("hidden")) {
|
|
2294
|
+
return "none";
|
|
2295
|
+
}
|
|
2296
|
+
return inlineStyleFor(element).display;
|
|
2297
|
+
}
|
|
2298
|
+
function inlineStyleFor(element) {
|
|
2299
|
+
return new CSSStyleDeclaration(element.getAttribute("style") ?? "");
|
|
2300
|
+
}
|
|
2301
|
+
function pixelValue(value) {
|
|
2302
|
+
const parsed = Number.parseFloat(value);
|
|
2303
|
+
return Number.isFinite(parsed) ? parsed : 0;
|
|
2304
|
+
}
|
|
2305
|
+
function parseNonNegativeInteger(value, fallback) {
|
|
2306
|
+
const parsed = Number.parseInt(value ?? "", 10);
|
|
2307
|
+
return Number.isFinite(parsed) && parsed >= 0 ? parsed : fallback;
|
|
2308
|
+
}
|
|
2309
|
+
function resolveElementUrl(element, value) {
|
|
2310
|
+
if (!value) {
|
|
2311
|
+
return "";
|
|
2312
|
+
}
|
|
2313
|
+
const base = element.ownerDocument?.URL ?? "about:blank";
|
|
2314
|
+
if (base.startsWith("about:") || base.startsWith("data:")) {
|
|
2315
|
+
return value;
|
|
2316
|
+
}
|
|
2317
|
+
try {
|
|
2318
|
+
return new URL(value, base).href;
|
|
2319
|
+
}
|
|
2320
|
+
catch {
|
|
2321
|
+
return value;
|
|
2322
|
+
}
|
|
2323
|
+
}
|
|
2324
|
+
function fragmentFromHtml(document, html) {
|
|
2325
|
+
return document._wrap(document._native.createHtmlFragment(String(html), "div"));
|
|
2326
|
+
}
|
|
2327
|
+
export class SVGElement extends Element {
|
|
2328
|
+
}
|
|
2329
|
+
export class MathMLElement extends Element {
|
|
2330
|
+
}
|
|
2331
|
+
const htmlElementState = new WeakMap();
|
|
2332
|
+
function getHTMLElementState(element) {
|
|
2333
|
+
let state = htmlElementState.get(element);
|
|
2334
|
+
if (!state) {
|
|
2335
|
+
state = {};
|
|
2336
|
+
htmlElementState.set(element, state);
|
|
2337
|
+
}
|
|
2338
|
+
return state;
|
|
2339
|
+
}
|
|
2340
|
+
export class HTMLElement extends Element {
|
|
2341
|
+
constructor(document, id, nodeName = null) {
|
|
2342
|
+
if (document && id !== undefined) {
|
|
2343
|
+
super(document, id, nodeName);
|
|
2344
|
+
return;
|
|
2345
|
+
}
|
|
2346
|
+
if (customElementConstruction) {
|
|
2347
|
+
super(customElementConstruction.document, customElementConstruction.id, customElementConstruction.nodeName);
|
|
2348
|
+
return;
|
|
2349
|
+
}
|
|
2350
|
+
const active = activeDocument();
|
|
2351
|
+
super(active, active._native.createElement("div"), "DIV");
|
|
2352
|
+
}
|
|
2353
|
+
get innerText() {
|
|
2354
|
+
return this.textContent;
|
|
2355
|
+
}
|
|
2356
|
+
set innerText(value) {
|
|
2357
|
+
this.textContent = String(value);
|
|
2358
|
+
}
|
|
2359
|
+
get hidden() {
|
|
2360
|
+
return this.hasAttribute("hidden");
|
|
2361
|
+
}
|
|
2362
|
+
set hidden(value) {
|
|
2363
|
+
if (value) {
|
|
2364
|
+
this.setAttribute("hidden", "");
|
|
2365
|
+
}
|
|
2366
|
+
else {
|
|
2367
|
+
this.removeAttribute("hidden");
|
|
2368
|
+
}
|
|
2369
|
+
}
|
|
2370
|
+
get type() {
|
|
2371
|
+
return this.getAttribute("type") ?? (this.localName === "input" ? "text" : "");
|
|
2372
|
+
}
|
|
2373
|
+
set type(value) {
|
|
2374
|
+
this.setAttribute("type", String(value));
|
|
2375
|
+
}
|
|
2376
|
+
get name() {
|
|
2377
|
+
return this.getAttribute("name") ?? "";
|
|
2378
|
+
}
|
|
2379
|
+
set name(value) {
|
|
2380
|
+
this.setAttribute("name", String(value));
|
|
2381
|
+
}
|
|
2382
|
+
get placeholder() {
|
|
2383
|
+
return this.getAttribute("placeholder") ?? "";
|
|
2384
|
+
}
|
|
2385
|
+
set placeholder(value) {
|
|
2386
|
+
this.setAttribute("placeholder", String(value));
|
|
2387
|
+
}
|
|
2388
|
+
get htmlFor() {
|
|
2389
|
+
return this.getAttribute("for") ?? "";
|
|
2390
|
+
}
|
|
2391
|
+
set htmlFor(value) {
|
|
2392
|
+
this.setAttribute("for", String(value));
|
|
2393
|
+
}
|
|
2394
|
+
get value() {
|
|
2395
|
+
if (this.localName === "select") {
|
|
2396
|
+
const option = this.options?.item(this.selectedIndex);
|
|
2397
|
+
return option?.value ?? "";
|
|
2398
|
+
}
|
|
2399
|
+
if (this.localName === "option") {
|
|
2400
|
+
return this.getAttribute("value") ?? this.textContent;
|
|
2401
|
+
}
|
|
2402
|
+
if (this.localName === "textarea") {
|
|
2403
|
+
return htmlElementState.get(this)?.value ?? this.defaultValue;
|
|
2404
|
+
}
|
|
2405
|
+
return htmlElementState.get(this)?.value ?? this.defaultValue;
|
|
2406
|
+
}
|
|
2407
|
+
set value(value) {
|
|
2408
|
+
if (this.localName === "select") {
|
|
2409
|
+
const options = [...(this.options ?? [])];
|
|
2410
|
+
const index = options.findIndex((option) => option.value === String(value));
|
|
2411
|
+
if (index !== -1) {
|
|
2412
|
+
this.selectedIndex = index;
|
|
2413
|
+
}
|
|
2414
|
+
return;
|
|
2415
|
+
}
|
|
2416
|
+
const nextValue = value === null ? "" : String(value);
|
|
2417
|
+
if (this.localName === "input" &&
|
|
2418
|
+
this.type.toLowerCase() === "number" &&
|
|
2419
|
+
nextValue !== "" &&
|
|
2420
|
+
!isValidNumberValue(nextValue)) {
|
|
2421
|
+
getHTMLElementState(this).value = "";
|
|
2422
|
+
return;
|
|
2423
|
+
}
|
|
2424
|
+
getHTMLElementState(this).value = nextValue;
|
|
2425
|
+
}
|
|
2426
|
+
get defaultValue() {
|
|
2427
|
+
if (this.localName === "textarea") {
|
|
2428
|
+
return this.textContent;
|
|
2429
|
+
}
|
|
2430
|
+
return this.getAttribute("value") ?? "";
|
|
2431
|
+
}
|
|
2432
|
+
set defaultValue(value) {
|
|
2433
|
+
if (this.localName === "textarea") {
|
|
2434
|
+
this.textContent = String(value);
|
|
2435
|
+
return;
|
|
2436
|
+
}
|
|
2437
|
+
this.setAttribute("value", String(value));
|
|
2438
|
+
}
|
|
2439
|
+
get checked() {
|
|
2440
|
+
return htmlElementState.get(this)?.checked ?? this.defaultChecked;
|
|
2441
|
+
}
|
|
2442
|
+
set checked(value) {
|
|
2443
|
+
getHTMLElementState(this).checked = value;
|
|
2444
|
+
}
|
|
2445
|
+
get defaultChecked() {
|
|
2446
|
+
return this.hasAttribute("checked");
|
|
2447
|
+
}
|
|
2448
|
+
set defaultChecked(value) {
|
|
2449
|
+
this.#toggleBooleanAttribute("checked", value);
|
|
2450
|
+
}
|
|
2451
|
+
get readOnly() {
|
|
2452
|
+
return this.hasAttribute("readonly");
|
|
2453
|
+
}
|
|
2454
|
+
set readOnly(value) {
|
|
2455
|
+
this.#toggleBooleanAttribute("readonly", value);
|
|
2456
|
+
}
|
|
2457
|
+
get multiple() {
|
|
2458
|
+
return this.hasAttribute("multiple");
|
|
2459
|
+
}
|
|
2460
|
+
set multiple(value) {
|
|
2461
|
+
this.#toggleBooleanAttribute("multiple", value);
|
|
2462
|
+
}
|
|
2463
|
+
get selected() {
|
|
2464
|
+
return htmlElementState.get(this)?.selected ?? this.hasAttribute("selected");
|
|
2465
|
+
}
|
|
2466
|
+
set selected(value) {
|
|
2467
|
+
getHTMLElementState(this).selected = value;
|
|
2468
|
+
}
|
|
2469
|
+
get selectedIndex() {
|
|
2470
|
+
const options = [...(this.options ?? [])];
|
|
2471
|
+
if (options.length === 0) {
|
|
2472
|
+
return -1;
|
|
2473
|
+
}
|
|
2474
|
+
const selectedIndex = options.findIndex((option) => option.selected);
|
|
2475
|
+
return selectedIndex === -1 ? 0 : selectedIndex;
|
|
2476
|
+
}
|
|
2477
|
+
set selectedIndex(value) {
|
|
2478
|
+
const options = [...(this.options ?? [])];
|
|
2479
|
+
options.forEach((option, index) => {
|
|
2480
|
+
option.selected = index === value;
|
|
2481
|
+
});
|
|
2482
|
+
}
|
|
2483
|
+
get options() {
|
|
2484
|
+
if (this.localName !== "select") {
|
|
2485
|
+
return undefined;
|
|
2486
|
+
}
|
|
2487
|
+
return new NativeNodeList(this._document, [...this.querySelectorAll("option")].map((option) => option._nativeId));
|
|
2488
|
+
}
|
|
2489
|
+
get text() {
|
|
2490
|
+
return this.textContent;
|
|
2491
|
+
}
|
|
2492
|
+
set text(value) {
|
|
2493
|
+
this.textContent = String(value);
|
|
2494
|
+
}
|
|
2495
|
+
get form() {
|
|
2496
|
+
if (!isFormAssociatedElement(this)) {
|
|
2497
|
+
return null;
|
|
2498
|
+
}
|
|
2499
|
+
const formId = this.getAttribute("form");
|
|
2500
|
+
if (formId) {
|
|
2501
|
+
const form = this._document.getElementById(formId);
|
|
2502
|
+
return form instanceof HTMLElement && form.localName === "form" ? form : null;
|
|
2503
|
+
}
|
|
2504
|
+
const form = this.closest("form");
|
|
2505
|
+
return form instanceof HTMLElement ? form : null;
|
|
2506
|
+
}
|
|
2507
|
+
get elements() {
|
|
2508
|
+
if (this.localName !== "form") {
|
|
2509
|
+
return undefined;
|
|
2510
|
+
}
|
|
2511
|
+
const selector = "button, fieldset, input, object, output, select, textarea";
|
|
2512
|
+
const descendants = [...this.querySelectorAll(selector)];
|
|
2513
|
+
const external = this.id
|
|
2514
|
+
? [...this._document.querySelectorAll("[form]")]
|
|
2515
|
+
.filter((element) => element.getAttribute("form") === this.id)
|
|
2516
|
+
: [];
|
|
2517
|
+
return new NativeNodeList(this._document, [...descendants, ...external]
|
|
2518
|
+
.filter((element) => element instanceof HTMLElement)
|
|
2519
|
+
.filter((element) => element.form === this)
|
|
2520
|
+
.map((element) => element._nativeId));
|
|
2521
|
+
}
|
|
2522
|
+
get control() {
|
|
2523
|
+
if (this.localName !== "label") {
|
|
2524
|
+
return null;
|
|
2525
|
+
}
|
|
2526
|
+
if (this.htmlFor) {
|
|
2527
|
+
const control = this._document.getElementById(this.htmlFor);
|
|
2528
|
+
return control instanceof HTMLElement ? control : null;
|
|
2529
|
+
}
|
|
2530
|
+
return [...this.querySelectorAll("button, input, meter, output, progress, select, textarea")]
|
|
2531
|
+
.filter(isLabelableElement)[0] ?? null;
|
|
2532
|
+
}
|
|
2533
|
+
get labels() {
|
|
2534
|
+
if (!isLabelableElement(this)) {
|
|
2535
|
+
return undefined;
|
|
2536
|
+
}
|
|
2537
|
+
const labels = [...this._document.querySelectorAll("label")].filter((label) => label instanceof HTMLElement && label.control === this);
|
|
2538
|
+
return new NativeNodeList(this._document, labels.map((label) => label._nativeId));
|
|
2539
|
+
}
|
|
2540
|
+
get validity() {
|
|
2541
|
+
if (!hasValidityState(this)) {
|
|
2542
|
+
return undefined;
|
|
2543
|
+
}
|
|
2544
|
+
return new ValidityState({
|
|
2545
|
+
customError: (htmlElementState.get(this)?.customValidityMessage ?? "") !== "",
|
|
2546
|
+
rangeOverflow: this.#isRangeOverflow(),
|
|
2547
|
+
rangeUnderflow: this.#isRangeUnderflow(),
|
|
2548
|
+
tooLong: this.#isTooLong(),
|
|
2549
|
+
tooShort: this.#isTooShort(),
|
|
2550
|
+
typeMismatch: this.#isTypeMismatch(),
|
|
2551
|
+
valueMissing: this.#isValueMissing()
|
|
2552
|
+
});
|
|
2553
|
+
}
|
|
2554
|
+
get validationMessage() {
|
|
2555
|
+
return htmlElementState.get(this)?.customValidityMessage ?? "";
|
|
2556
|
+
}
|
|
2557
|
+
get willValidate() {
|
|
2558
|
+
if (this.localName !== "input" && this.localName !== "select") {
|
|
2559
|
+
return undefined;
|
|
2560
|
+
}
|
|
2561
|
+
if (isDisabledFormElement(this) || this.readOnly) {
|
|
2562
|
+
return false;
|
|
2563
|
+
}
|
|
2564
|
+
return !(this.localName === "input" && this.type.toLowerCase() === "hidden");
|
|
2565
|
+
}
|
|
2566
|
+
setCustomValidity(message) {
|
|
2567
|
+
getHTMLElementState(this).customValidityMessage = String(message);
|
|
2568
|
+
}
|
|
2569
|
+
checkValidity() {
|
|
2570
|
+
if (this.localName === "form") {
|
|
2571
|
+
return [...(this.elements ?? [])].every((element) => element.checkValidity());
|
|
2572
|
+
}
|
|
2573
|
+
if (!hasValidityState(this)) {
|
|
2574
|
+
return true;
|
|
2575
|
+
}
|
|
2576
|
+
if (isDisabledFormElement(this) ||
|
|
2577
|
+
this.readOnly ||
|
|
2578
|
+
(this.localName === "input" && this.type.toLowerCase() === "hidden")) {
|
|
2579
|
+
return true;
|
|
2580
|
+
}
|
|
2581
|
+
return this.validity?.valid ?? true;
|
|
2582
|
+
}
|
|
2583
|
+
reportValidity() {
|
|
2584
|
+
return this.checkValidity();
|
|
2585
|
+
}
|
|
2586
|
+
click() {
|
|
2587
|
+
this.dispatchEvent(new MouseEvent("click", { bubbles: true, cancelable: true }));
|
|
2588
|
+
}
|
|
2589
|
+
submit() {
|
|
2590
|
+
this.requestSubmit();
|
|
2591
|
+
}
|
|
2592
|
+
requestSubmit() {
|
|
2593
|
+
if (this.localName !== "form") {
|
|
2594
|
+
return;
|
|
2595
|
+
}
|
|
2596
|
+
if (!this.checkValidity()) {
|
|
2597
|
+
return;
|
|
2598
|
+
}
|
|
2599
|
+
this.dispatchEvent(new SubmitEvent("submit", { bubbles: true, cancelable: true }));
|
|
2600
|
+
}
|
|
2601
|
+
reset() {
|
|
2602
|
+
if (this.localName !== "form") {
|
|
2603
|
+
return;
|
|
2604
|
+
}
|
|
2605
|
+
const event = new Event("reset", { bubbles: true, cancelable: true });
|
|
2606
|
+
if (!this.dispatchEvent(event)) {
|
|
2607
|
+
return;
|
|
2608
|
+
}
|
|
2609
|
+
for (const element of this.elements ?? []) {
|
|
2610
|
+
element.#resetFormValue();
|
|
2611
|
+
}
|
|
2612
|
+
}
|
|
2613
|
+
focus() {
|
|
2614
|
+
if (this._document.activeElement === this) {
|
|
2615
|
+
return;
|
|
2616
|
+
}
|
|
2617
|
+
const previous = this._document.activeElement;
|
|
2618
|
+
if (previous instanceof HTMLElement && previous !== this._document.body) {
|
|
2619
|
+
previous.#blurWithoutFocusCheck();
|
|
2620
|
+
}
|
|
2621
|
+
this._document._setActiveElement(this);
|
|
2622
|
+
this.dispatchEvent(new FocusEvent("focus"));
|
|
2623
|
+
this.dispatchEvent(new FocusEvent("focusin", { bubbles: true }));
|
|
2624
|
+
}
|
|
2625
|
+
blur() {
|
|
2626
|
+
if (this._document.activeElement !== this) {
|
|
2627
|
+
return;
|
|
2628
|
+
}
|
|
2629
|
+
this.#blurWithoutFocusCheck();
|
|
2630
|
+
}
|
|
2631
|
+
#blurWithoutFocusCheck() {
|
|
2632
|
+
this._document._setActiveElement(null);
|
|
2633
|
+
this.dispatchEvent(new FocusEvent("blur"));
|
|
2634
|
+
this.dispatchEvent(new FocusEvent("focusout", { bubbles: true }));
|
|
2635
|
+
}
|
|
2636
|
+
#toggleBooleanAttribute(name, value) {
|
|
2637
|
+
if (value) {
|
|
2638
|
+
this.setAttribute(name, "");
|
|
2639
|
+
}
|
|
2640
|
+
else {
|
|
2641
|
+
this.removeAttribute(name);
|
|
2642
|
+
}
|
|
2643
|
+
}
|
|
2644
|
+
#resetFormValue() {
|
|
2645
|
+
if (this.localName === "input") {
|
|
2646
|
+
const state = getHTMLElementState(this);
|
|
2647
|
+
state.value = null;
|
|
2648
|
+
state.checked = null;
|
|
2649
|
+
return;
|
|
2650
|
+
}
|
|
2651
|
+
if (this.localName === "textarea") {
|
|
2652
|
+
getHTMLElementState(this).value = null;
|
|
2653
|
+
return;
|
|
2654
|
+
}
|
|
2655
|
+
if (this.localName === "select") {
|
|
2656
|
+
for (const option of this.options ?? []) {
|
|
2657
|
+
getHTMLElementState(option).selected = null;
|
|
2658
|
+
}
|
|
2659
|
+
const options = [...(this.options ?? [])];
|
|
2660
|
+
const selectedIndex = options.findIndex((option) => option.hasAttribute("selected"));
|
|
2661
|
+
this.selectedIndex = selectedIndex === -1 && options.length > 0 ? 0 : selectedIndex;
|
|
2662
|
+
}
|
|
2663
|
+
}
|
|
2664
|
+
#isValueMissing() {
|
|
2665
|
+
if (!["input", "select", "textarea"].includes(this.localName)) {
|
|
2666
|
+
return false;
|
|
2667
|
+
}
|
|
2668
|
+
if (!this.hasAttribute("required")) {
|
|
2669
|
+
return false;
|
|
2670
|
+
}
|
|
2671
|
+
if (this.localName === "input") {
|
|
2672
|
+
const type = this.type.toLowerCase();
|
|
2673
|
+
if (type === "checkbox" || type === "radio") {
|
|
2674
|
+
return !this.checked;
|
|
2675
|
+
}
|
|
2676
|
+
}
|
|
2677
|
+
return this.value === "";
|
|
2678
|
+
}
|
|
2679
|
+
#isTypeMismatch() {
|
|
2680
|
+
if (this.localName !== "input" || this.value === "") {
|
|
2681
|
+
return false;
|
|
2682
|
+
}
|
|
2683
|
+
if (this.type.toLowerCase() === "email") {
|
|
2684
|
+
return !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(this.value);
|
|
2685
|
+
}
|
|
2686
|
+
return false;
|
|
2687
|
+
}
|
|
2688
|
+
#isRangeUnderflow() {
|
|
2689
|
+
if (this.localName !== "input" || this.type.toLowerCase() !== "number" || this.value === "") {
|
|
2690
|
+
return false;
|
|
2691
|
+
}
|
|
2692
|
+
const min = Number.parseFloat(this.getAttribute("min") ?? "");
|
|
2693
|
+
return Number.isFinite(min) && Number.parseFloat(this.value) < min;
|
|
2694
|
+
}
|
|
2695
|
+
#isRangeOverflow() {
|
|
2696
|
+
if (this.localName !== "input" || this.type.toLowerCase() !== "number" || this.value === "") {
|
|
2697
|
+
return false;
|
|
2698
|
+
}
|
|
2699
|
+
const max = Number.parseFloat(this.getAttribute("max") ?? "");
|
|
2700
|
+
return Number.isFinite(max) && Number.parseFloat(this.value) > max;
|
|
2701
|
+
}
|
|
2702
|
+
#isTooShort() {
|
|
2703
|
+
if (!["input", "textarea"].includes(this.localName) || this.value === "") {
|
|
2704
|
+
return false;
|
|
2705
|
+
}
|
|
2706
|
+
const minLength = Number.parseInt(this.getAttribute("minlength") ?? "", 10);
|
|
2707
|
+
return Number.isFinite(minLength) && this.value.length < minLength;
|
|
2708
|
+
}
|
|
2709
|
+
#isTooLong() {
|
|
2710
|
+
if (!["input", "textarea"].includes(this.localName) || this.value === "") {
|
|
2711
|
+
return false;
|
|
2712
|
+
}
|
|
2713
|
+
const maxLength = Number.parseInt(this.getAttribute("maxlength") ?? "", 10);
|
|
2714
|
+
return Number.isFinite(maxLength) && this.value.length > maxLength;
|
|
2715
|
+
}
|
|
2716
|
+
}
|
|
2717
|
+
export class HTMLButtonElement extends HTMLElement {
|
|
2718
|
+
get disabled() {
|
|
2719
|
+
return this.hasAttribute("disabled");
|
|
2720
|
+
}
|
|
2721
|
+
set disabled(value) {
|
|
2722
|
+
toggleBooleanAttribute(this, "disabled", value);
|
|
2723
|
+
}
|
|
2724
|
+
}
|
|
2725
|
+
export class HTMLCanvasElement extends HTMLElement {
|
|
2726
|
+
get width() {
|
|
2727
|
+
return Number.parseInt(this.getAttribute("width") ?? "300", 10);
|
|
2728
|
+
}
|
|
2729
|
+
set width(value) {
|
|
2730
|
+
this.setAttribute("width", String(value));
|
|
2731
|
+
}
|
|
2732
|
+
get height() {
|
|
2733
|
+
return Number.parseInt(this.getAttribute("height") ?? "150", 10);
|
|
2734
|
+
}
|
|
2735
|
+
set height(value) {
|
|
2736
|
+
this.setAttribute("height", String(value));
|
|
2737
|
+
}
|
|
2738
|
+
getContext(_contextId, ..._arguments_) {
|
|
2739
|
+
return null;
|
|
2740
|
+
}
|
|
2741
|
+
toDataURL(_type, ..._arguments_) {
|
|
2742
|
+
return "data:,";
|
|
2743
|
+
}
|
|
2744
|
+
}
|
|
2745
|
+
export class HTMLFormElement extends HTMLElement {
|
|
2746
|
+
}
|
|
2747
|
+
export class HTMLHtmlElement extends HTMLElement {
|
|
2748
|
+
}
|
|
2749
|
+
export class HTMLBodyElement extends HTMLElement {
|
|
2750
|
+
}
|
|
2751
|
+
export class HTMLImageElement extends HTMLElement {
|
|
2752
|
+
get alt() {
|
|
2753
|
+
return this.getAttribute("alt") ?? "";
|
|
2754
|
+
}
|
|
2755
|
+
set alt(value) {
|
|
2756
|
+
this.setAttribute("alt", String(value));
|
|
2757
|
+
}
|
|
2758
|
+
get src() {
|
|
2759
|
+
return resolveElementUrl(this, this.getAttribute("src") ?? "");
|
|
2760
|
+
}
|
|
2761
|
+
set src(value) {
|
|
2762
|
+
this.setAttribute("src", String(value));
|
|
2763
|
+
}
|
|
2764
|
+
get currentSrc() {
|
|
2765
|
+
return this.src;
|
|
2766
|
+
}
|
|
2767
|
+
get srcset() {
|
|
2768
|
+
return this.getAttribute("srcset") ?? "";
|
|
2769
|
+
}
|
|
2770
|
+
set srcset(value) {
|
|
2771
|
+
this.setAttribute("srcset", String(value));
|
|
2772
|
+
}
|
|
2773
|
+
get sizes() {
|
|
2774
|
+
return this.getAttribute("sizes") ?? "";
|
|
2775
|
+
}
|
|
2776
|
+
set sizes(value) {
|
|
2777
|
+
this.setAttribute("sizes", String(value));
|
|
2778
|
+
}
|
|
2779
|
+
get width() {
|
|
2780
|
+
return parseNonNegativeInteger(this.getAttribute("width"), 0);
|
|
2781
|
+
}
|
|
2782
|
+
set width(value) {
|
|
2783
|
+
this.setAttribute("width", String(Math.max(0, Number(value) || 0)));
|
|
2784
|
+
}
|
|
2785
|
+
get height() {
|
|
2786
|
+
return parseNonNegativeInteger(this.getAttribute("height"), 0);
|
|
2787
|
+
}
|
|
2788
|
+
set height(value) {
|
|
2789
|
+
this.setAttribute("height", String(Math.max(0, Number(value) || 0)));
|
|
2790
|
+
}
|
|
2791
|
+
get naturalWidth() {
|
|
2792
|
+
return 0;
|
|
2793
|
+
}
|
|
2794
|
+
get naturalHeight() {
|
|
2795
|
+
return 0;
|
|
2796
|
+
}
|
|
2797
|
+
get complete() {
|
|
2798
|
+
return false;
|
|
2799
|
+
}
|
|
2800
|
+
get loading() {
|
|
2801
|
+
return this.getAttribute("loading") ?? "auto";
|
|
2802
|
+
}
|
|
2803
|
+
set loading(value) {
|
|
2804
|
+
this.setAttribute("loading", String(value));
|
|
2805
|
+
}
|
|
2806
|
+
get decoding() {
|
|
2807
|
+
return this.getAttribute("decoding") ?? "auto";
|
|
2808
|
+
}
|
|
2809
|
+
set decoding(value) {
|
|
2810
|
+
this.setAttribute("decoding", String(value));
|
|
2811
|
+
}
|
|
2812
|
+
get crossOrigin() {
|
|
2813
|
+
return this.getAttribute("crossorigin");
|
|
2814
|
+
}
|
|
2815
|
+
set crossOrigin(value) {
|
|
2816
|
+
if (value === null) {
|
|
2817
|
+
this.removeAttribute("crossorigin");
|
|
2818
|
+
return;
|
|
2819
|
+
}
|
|
2820
|
+
this.setAttribute("crossorigin", String(value));
|
|
2821
|
+
}
|
|
2822
|
+
get referrerPolicy() {
|
|
2823
|
+
return this.getAttribute("referrerpolicy") ?? "";
|
|
2824
|
+
}
|
|
2825
|
+
set referrerPolicy(value) {
|
|
2826
|
+
this.setAttribute("referrerpolicy", String(value));
|
|
2827
|
+
}
|
|
2828
|
+
}
|
|
2829
|
+
function createImageConstructor(document) {
|
|
2830
|
+
const ImageConstructor = function Image(width, height) {
|
|
2831
|
+
const element = document.createElement("img");
|
|
2832
|
+
Object.setPrototypeOf(element, ImageConstructor.prototype);
|
|
2833
|
+
if (width !== undefined) {
|
|
2834
|
+
element.width = width;
|
|
2835
|
+
}
|
|
2836
|
+
if (height !== undefined) {
|
|
2837
|
+
element.height = height;
|
|
2838
|
+
}
|
|
2839
|
+
return element;
|
|
2840
|
+
};
|
|
2841
|
+
Object.setPrototypeOf(ImageConstructor.prototype, HTMLImageElement.prototype);
|
|
2842
|
+
Object.defineProperty(ImageConstructor.prototype, "constructor", {
|
|
2843
|
+
configurable: true,
|
|
2844
|
+
value: ImageConstructor,
|
|
2845
|
+
writable: true
|
|
2846
|
+
});
|
|
2847
|
+
return ImageConstructor;
|
|
2848
|
+
}
|
|
2849
|
+
export class HTMLLinkElement extends HTMLElement {
|
|
2850
|
+
#disabled;
|
|
2851
|
+
get href() {
|
|
2852
|
+
return resolveElementUrl(this, this.getAttribute("href") ?? "");
|
|
2853
|
+
}
|
|
2854
|
+
set href(value) {
|
|
2855
|
+
this.setAttribute("href", String(value));
|
|
2856
|
+
}
|
|
2857
|
+
get rel() {
|
|
2858
|
+
return this.getAttribute("rel") ?? "";
|
|
2859
|
+
}
|
|
2860
|
+
set rel(value) {
|
|
2861
|
+
this.setAttribute("rel", String(value));
|
|
2862
|
+
}
|
|
2863
|
+
get as() {
|
|
2864
|
+
return this.getAttribute("as") ?? "";
|
|
2865
|
+
}
|
|
2866
|
+
set as(value) {
|
|
2867
|
+
this.setAttribute("as", String(value));
|
|
2868
|
+
}
|
|
2869
|
+
get type() {
|
|
2870
|
+
return this.getAttribute("type") ?? "";
|
|
2871
|
+
}
|
|
2872
|
+
set type(value) {
|
|
2873
|
+
this.setAttribute("type", String(value));
|
|
2874
|
+
}
|
|
2875
|
+
get media() {
|
|
2876
|
+
return this.getAttribute("media") ?? "";
|
|
2877
|
+
}
|
|
2878
|
+
set media(value) {
|
|
2879
|
+
this.setAttribute("media", String(value));
|
|
2880
|
+
}
|
|
2881
|
+
get crossOrigin() {
|
|
2882
|
+
return this.getAttribute("crossorigin") ?? "";
|
|
2883
|
+
}
|
|
2884
|
+
set crossOrigin(value) {
|
|
2885
|
+
this.setAttribute("crossorigin", String(value));
|
|
2886
|
+
}
|
|
2887
|
+
get referrerPolicy() {
|
|
2888
|
+
return this.getAttribute("referrerpolicy") ?? "";
|
|
2889
|
+
}
|
|
2890
|
+
set referrerPolicy(value) {
|
|
2891
|
+
this.setAttribute("referrerpolicy", String(value));
|
|
2892
|
+
}
|
|
2893
|
+
get disabled() {
|
|
2894
|
+
return this.#disabled;
|
|
2895
|
+
}
|
|
2896
|
+
set disabled(value) {
|
|
2897
|
+
this.#disabled = Boolean(value);
|
|
2898
|
+
}
|
|
2899
|
+
get sheet() {
|
|
2900
|
+
return null;
|
|
2901
|
+
}
|
|
2902
|
+
}
|
|
2903
|
+
export class HTMLScriptElement extends HTMLElement {
|
|
2904
|
+
get src() {
|
|
2905
|
+
return resolveElementUrl(this, this.getAttribute("src") ?? "");
|
|
2906
|
+
}
|
|
2907
|
+
set src(value) {
|
|
2908
|
+
this.setAttribute("src", String(value));
|
|
2909
|
+
}
|
|
2910
|
+
get type() {
|
|
2911
|
+
return this.getAttribute("type") ?? "";
|
|
2912
|
+
}
|
|
2913
|
+
set type(value) {
|
|
2914
|
+
this.setAttribute("type", String(value));
|
|
2915
|
+
}
|
|
2916
|
+
get charset() {
|
|
2917
|
+
return this.getAttribute("charset") ?? "";
|
|
2918
|
+
}
|
|
2919
|
+
set charset(value) {
|
|
2920
|
+
this.setAttribute("charset", String(value));
|
|
2921
|
+
}
|
|
2922
|
+
get lang() {
|
|
2923
|
+
return this.getAttribute("lang") ?? "";
|
|
2924
|
+
}
|
|
2925
|
+
set lang(value) {
|
|
2926
|
+
this.setAttribute("lang", String(value));
|
|
2927
|
+
}
|
|
2928
|
+
get async() {
|
|
2929
|
+
return this.hasAttribute("async");
|
|
2930
|
+
}
|
|
2931
|
+
set async(value) {
|
|
2932
|
+
toggleBooleanAttribute(this, "async", value);
|
|
2933
|
+
}
|
|
2934
|
+
get defer() {
|
|
2935
|
+
return this.hasAttribute("defer");
|
|
2936
|
+
}
|
|
2937
|
+
set defer(value) {
|
|
2938
|
+
toggleBooleanAttribute(this, "defer", value);
|
|
2939
|
+
}
|
|
2940
|
+
get noModule() {
|
|
2941
|
+
return this.hasAttribute("nomodule");
|
|
2942
|
+
}
|
|
2943
|
+
set noModule(value) {
|
|
2944
|
+
toggleBooleanAttribute(this, "nomodule", value);
|
|
2945
|
+
}
|
|
2946
|
+
get crossOrigin() {
|
|
2947
|
+
return this.getAttribute("crossorigin") ?? "";
|
|
2948
|
+
}
|
|
2949
|
+
set crossOrigin(value) {
|
|
2950
|
+
this.setAttribute("crossorigin", String(value));
|
|
2951
|
+
}
|
|
2952
|
+
get integrity() {
|
|
2953
|
+
return this.getAttribute("integrity") ?? "";
|
|
2954
|
+
}
|
|
2955
|
+
set integrity(value) {
|
|
2956
|
+
this.setAttribute("integrity", String(value));
|
|
2957
|
+
}
|
|
2958
|
+
get referrerPolicy() {
|
|
2959
|
+
return this.getAttribute("referrerpolicy") ?? "";
|
|
2960
|
+
}
|
|
2961
|
+
set referrerPolicy(value) {
|
|
2962
|
+
this.setAttribute("referrerpolicy", String(value));
|
|
2963
|
+
}
|
|
2964
|
+
get text() {
|
|
2965
|
+
return this.textContent;
|
|
2966
|
+
}
|
|
2967
|
+
set text(value) {
|
|
2968
|
+
this.textContent = String(value);
|
|
2969
|
+
}
|
|
2970
|
+
}
|
|
2971
|
+
export class HTMLTableElement extends HTMLElement {
|
|
2972
|
+
get caption() {
|
|
2973
|
+
return this.#directChild("caption");
|
|
2974
|
+
}
|
|
2975
|
+
get tHead() {
|
|
2976
|
+
return this.#directChild("thead");
|
|
2977
|
+
}
|
|
2978
|
+
get tFoot() {
|
|
2979
|
+
return this.#directChild("tfoot");
|
|
2980
|
+
}
|
|
2981
|
+
get tBodies() {
|
|
2982
|
+
return collectionFromElements(this._document, [...this.children].filter((element) => element instanceof HTMLTableSectionElement && element.localName === "tbody"));
|
|
2983
|
+
}
|
|
2984
|
+
get rows() {
|
|
2985
|
+
return collectionFromElements(this._document, [...this.querySelectorAll("tr")].filter((element) => element instanceof HTMLTableRowElement));
|
|
2986
|
+
}
|
|
2987
|
+
createTHead() {
|
|
2988
|
+
return this.tHead ?? this.appendChild(this._document.createElement("thead"));
|
|
2989
|
+
}
|
|
2990
|
+
deleteTHead() {
|
|
2991
|
+
this.tHead?.remove();
|
|
2992
|
+
}
|
|
2993
|
+
createTFoot() {
|
|
2994
|
+
return this.tFoot ?? this.appendChild(this._document.createElement("tfoot"));
|
|
2995
|
+
}
|
|
2996
|
+
deleteTFoot() {
|
|
2997
|
+
this.tFoot?.remove();
|
|
2998
|
+
}
|
|
2999
|
+
createTBody() {
|
|
3000
|
+
return this.appendChild(this._document.createElement("tbody"));
|
|
3001
|
+
}
|
|
3002
|
+
insertRow(index = -1) {
|
|
3003
|
+
const rows = [...this.rows];
|
|
3004
|
+
const normalizedIndex = normalizeTableIndex(index, rows.length, true);
|
|
3005
|
+
const row = this._document.createElement("tr");
|
|
3006
|
+
if (normalizedIndex === rows.length) {
|
|
3007
|
+
const bodies = [...this.tBodies];
|
|
3008
|
+
const container = bodies[bodies.length - 1] ?? this.createTBody();
|
|
3009
|
+
container.appendChild(row);
|
|
3010
|
+
return row;
|
|
3011
|
+
}
|
|
3012
|
+
rows[normalizedIndex].parentNode?.insertBefore(row, rows[normalizedIndex]);
|
|
3013
|
+
return row;
|
|
3014
|
+
}
|
|
3015
|
+
deleteRow(index) {
|
|
3016
|
+
const rows = [...this.rows];
|
|
3017
|
+
const normalizedIndex = normalizeTableIndex(index, rows.length, false);
|
|
3018
|
+
rows[normalizedIndex]?.remove();
|
|
3019
|
+
}
|
|
3020
|
+
#directChild(localName) {
|
|
3021
|
+
return ([...this.children].find((element) => element instanceof HTMLElement && element.localName === localName) ?? null);
|
|
3022
|
+
}
|
|
3023
|
+
}
|
|
3024
|
+
export class HTMLTableSectionElement extends HTMLElement {
|
|
3025
|
+
get rows() {
|
|
3026
|
+
return collectionFromElements(this._document, [...this.children].filter((element) => element instanceof HTMLTableRowElement));
|
|
3027
|
+
}
|
|
3028
|
+
insertRow(index = -1) {
|
|
3029
|
+
const rows = [...this.rows];
|
|
3030
|
+
const normalizedIndex = normalizeTableIndex(index, rows.length, true);
|
|
3031
|
+
const row = this._document.createElement("tr");
|
|
3032
|
+
if (normalizedIndex === rows.length) {
|
|
3033
|
+
this.appendChild(row);
|
|
3034
|
+
return row;
|
|
3035
|
+
}
|
|
3036
|
+
this.insertBefore(row, rows[normalizedIndex]);
|
|
3037
|
+
return row;
|
|
3038
|
+
}
|
|
3039
|
+
deleteRow(index) {
|
|
3040
|
+
const rows = [...this.rows];
|
|
3041
|
+
const normalizedIndex = normalizeTableIndex(index, rows.length, false);
|
|
3042
|
+
rows[normalizedIndex]?.remove();
|
|
3043
|
+
}
|
|
3044
|
+
}
|
|
3045
|
+
export class HTMLTableRowElement extends HTMLElement {
|
|
3046
|
+
get cells() {
|
|
3047
|
+
return collectionFromElements(this._document, [...this.children].filter((element) => element instanceof HTMLTableCellElement));
|
|
3048
|
+
}
|
|
3049
|
+
get rowIndex() {
|
|
3050
|
+
const table = this.closest("table");
|
|
3051
|
+
return table ? [...table.rows].indexOf(this) : -1;
|
|
3052
|
+
}
|
|
3053
|
+
get sectionRowIndex() {
|
|
3054
|
+
const parent = this.parentElement;
|
|
3055
|
+
if (parent instanceof HTMLTableSectionElement) {
|
|
3056
|
+
return [...parent.rows].indexOf(this);
|
|
3057
|
+
}
|
|
3058
|
+
return -1;
|
|
3059
|
+
}
|
|
3060
|
+
insertCell(index = -1) {
|
|
3061
|
+
const cells = [...this.cells];
|
|
3062
|
+
const normalizedIndex = normalizeTableIndex(index, cells.length, true);
|
|
3063
|
+
const cell = this._document.createElement("td");
|
|
3064
|
+
if (normalizedIndex === cells.length) {
|
|
3065
|
+
this.appendChild(cell);
|
|
3066
|
+
return cell;
|
|
3067
|
+
}
|
|
3068
|
+
this.insertBefore(cell, cells[normalizedIndex]);
|
|
3069
|
+
return cell;
|
|
3070
|
+
}
|
|
3071
|
+
deleteCell(index) {
|
|
3072
|
+
const cells = [...this.cells];
|
|
3073
|
+
const normalizedIndex = normalizeTableIndex(index, cells.length, false);
|
|
3074
|
+
cells[normalizedIndex]?.remove();
|
|
3075
|
+
}
|
|
3076
|
+
}
|
|
3077
|
+
export class HTMLTableCellElement extends HTMLElement {
|
|
3078
|
+
get cellIndex() {
|
|
3079
|
+
const parent = this.parentElement;
|
|
3080
|
+
if (parent instanceof HTMLTableRowElement) {
|
|
3081
|
+
return [...parent.cells].indexOf(this);
|
|
3082
|
+
}
|
|
3083
|
+
return -1;
|
|
3084
|
+
}
|
|
3085
|
+
get colSpan() {
|
|
3086
|
+
return parseNonNegativeInteger(this.getAttribute("colspan"), 1) || 1;
|
|
3087
|
+
}
|
|
3088
|
+
set colSpan(value) {
|
|
3089
|
+
this.setAttribute("colspan", String(Math.max(1, Number(value) || 1)));
|
|
3090
|
+
}
|
|
3091
|
+
get rowSpan() {
|
|
3092
|
+
return parseNonNegativeInteger(this.getAttribute("rowspan"), 1) || 1;
|
|
3093
|
+
}
|
|
3094
|
+
set rowSpan(value) {
|
|
3095
|
+
this.setAttribute("rowspan", String(Math.max(1, Number(value) || 1)));
|
|
3096
|
+
}
|
|
3097
|
+
}
|
|
3098
|
+
function collectionFromElements(document, elements) {
|
|
3099
|
+
return new NativeNodeList(document, elements.map((element) => element._nativeId));
|
|
3100
|
+
}
|
|
3101
|
+
function normalizeTableIndex(index, length, allowAppend) {
|
|
3102
|
+
const normalizedIndex = Number(index);
|
|
3103
|
+
if (!Number.isInteger(normalizedIndex)) {
|
|
3104
|
+
throw new DOMException("The index is outside the allowed range.", "IndexSizeError");
|
|
3105
|
+
}
|
|
3106
|
+
if (normalizedIndex === -1) {
|
|
3107
|
+
return allowAppend ? length : length - 1;
|
|
3108
|
+
}
|
|
3109
|
+
if (normalizedIndex < 0 || normalizedIndex > length || (!allowAppend && normalizedIndex === length)) {
|
|
3110
|
+
throw new DOMException("The index is outside the allowed range.", "IndexSizeError");
|
|
3111
|
+
}
|
|
3112
|
+
return normalizedIndex;
|
|
3113
|
+
}
|
|
3114
|
+
function customElementDefinitionFor(element) {
|
|
3115
|
+
return element.ownerDocument?.defaultView.customElements._definitionFor(element.localName);
|
|
3116
|
+
}
|
|
3117
|
+
function notifyCustomElementReparented(node, oldParent, wasConnected) {
|
|
3118
|
+
const movedBetweenParents = oldParent !== null && oldParent !== node.parentNode;
|
|
3119
|
+
const isConnected = node.isConnected;
|
|
3120
|
+
if (wasConnected && (movedBetweenParents || !isConnected)) {
|
|
3121
|
+
notifyCustomElementDisconnected(node);
|
|
3122
|
+
}
|
|
3123
|
+
if (isConnected && (!wasConnected || movedBetweenParents)) {
|
|
3124
|
+
notifyCustomElementConnected(node);
|
|
3125
|
+
}
|
|
3126
|
+
}
|
|
3127
|
+
function notifyCustomElementConnected(node) {
|
|
3128
|
+
if (node instanceof Element) {
|
|
3129
|
+
const callback = node.connectedCallback;
|
|
3130
|
+
if (customElementDefinitionFor(node) && typeof callback === "function") {
|
|
3131
|
+
callback.call(node);
|
|
3132
|
+
}
|
|
3133
|
+
}
|
|
3134
|
+
for (const child of node.childNodes) {
|
|
3135
|
+
notifyCustomElementConnected(child);
|
|
3136
|
+
}
|
|
3137
|
+
}
|
|
3138
|
+
function notifyCustomElementDisconnected(node) {
|
|
3139
|
+
if (node instanceof Element) {
|
|
3140
|
+
const callback = node.disconnectedCallback;
|
|
3141
|
+
if (customElementDefinitionFor(node) && typeof callback === "function") {
|
|
3142
|
+
callback.call(node);
|
|
3143
|
+
}
|
|
3144
|
+
}
|
|
3145
|
+
for (const child of node.childNodes) {
|
|
3146
|
+
notifyCustomElementDisconnected(child);
|
|
3147
|
+
}
|
|
3148
|
+
}
|
|
3149
|
+
function notifyCustomElementAttributeChanged(element, name, oldValue, newValue) {
|
|
3150
|
+
const definition = customElementDefinitionFor(element);
|
|
3151
|
+
if (!definition?.observedAttributes.includes(name)) {
|
|
3152
|
+
return;
|
|
3153
|
+
}
|
|
3154
|
+
const callback = element.attributeChangedCallback;
|
|
3155
|
+
if (typeof callback === "function") {
|
|
3156
|
+
callback.call(element, name, oldValue, newValue);
|
|
3157
|
+
}
|
|
3158
|
+
}
|
|
3159
|
+
export class HTMLTemplateElement extends HTMLElement {
|
|
3160
|
+
#content;
|
|
3161
|
+
constructor(document, id, nodeName) {
|
|
3162
|
+
super(document, id, nodeName);
|
|
3163
|
+
const contentId = document._native.templateContent(id);
|
|
3164
|
+
this.#content =
|
|
3165
|
+
contentId == null
|
|
3166
|
+
? document.createDocumentFragment()
|
|
3167
|
+
: document._wrap(contentId, "#document-fragment");
|
|
3168
|
+
}
|
|
3169
|
+
get content() {
|
|
3170
|
+
return this.#content;
|
|
3171
|
+
}
|
|
3172
|
+
get firstChild() {
|
|
3173
|
+
return this.#content.firstChild;
|
|
3174
|
+
}
|
|
3175
|
+
get lastChild() {
|
|
3176
|
+
return this.#content.lastChild;
|
|
3177
|
+
}
|
|
3178
|
+
get innerHTML() {
|
|
3179
|
+
return this.#content.innerHTML;
|
|
3180
|
+
}
|
|
3181
|
+
set innerHTML(html) {
|
|
3182
|
+
this.#content.innerHTML = html;
|
|
3183
|
+
}
|
|
3184
|
+
appendChild(child) {
|
|
3185
|
+
return this.#content.appendChild(child);
|
|
3186
|
+
}
|
|
3187
|
+
append(...nodes) {
|
|
3188
|
+
this.#content.append(...nodes);
|
|
3189
|
+
}
|
|
3190
|
+
prepend(...nodes) {
|
|
3191
|
+
this.#content.prepend(...nodes);
|
|
3192
|
+
}
|
|
3193
|
+
insertBefore(child, referenceNode) {
|
|
3194
|
+
return this.#content.insertBefore(child, referenceNode);
|
|
3195
|
+
}
|
|
3196
|
+
removeChild(child) {
|
|
3197
|
+
return this.#content.removeChild(child);
|
|
3198
|
+
}
|
|
3199
|
+
replaceChild(newChild, oldChild) {
|
|
3200
|
+
return this.#content.replaceChild(newChild, oldChild);
|
|
3201
|
+
}
|
|
3202
|
+
replaceChildren(...nodes) {
|
|
3203
|
+
this.#content.replaceChildren(...nodes);
|
|
3204
|
+
}
|
|
3205
|
+
}
|
|
3206
|
+
export class HTMLInputElement extends HTMLElement {
|
|
3207
|
+
get accept() {
|
|
3208
|
+
return this.getAttribute("accept") ?? "";
|
|
3209
|
+
}
|
|
3210
|
+
set accept(value) {
|
|
3211
|
+
this.setAttribute("accept", String(value));
|
|
3212
|
+
}
|
|
3213
|
+
get files() {
|
|
3214
|
+
return [];
|
|
3215
|
+
}
|
|
3216
|
+
get value() {
|
|
3217
|
+
return super.value;
|
|
3218
|
+
}
|
|
3219
|
+
set value(value) {
|
|
3220
|
+
super.value = value;
|
|
3221
|
+
}
|
|
3222
|
+
get checked() {
|
|
3223
|
+
return super.checked;
|
|
3224
|
+
}
|
|
3225
|
+
set checked(value) {
|
|
3226
|
+
super.checked = value;
|
|
3227
|
+
}
|
|
3228
|
+
get disabled() {
|
|
3229
|
+
return this.hasAttribute("disabled");
|
|
3230
|
+
}
|
|
3231
|
+
set disabled(value) {
|
|
3232
|
+
toggleBooleanAttribute(this, "disabled", value);
|
|
3233
|
+
}
|
|
3234
|
+
get multiple() {
|
|
3235
|
+
return super.multiple;
|
|
3236
|
+
}
|
|
3237
|
+
set multiple(value) {
|
|
3238
|
+
super.multiple = value;
|
|
3239
|
+
}
|
|
3240
|
+
get required() {
|
|
3241
|
+
return this.hasAttribute("required");
|
|
3242
|
+
}
|
|
3243
|
+
set required(value) {
|
|
3244
|
+
toggleBooleanAttribute(this, "required", value);
|
|
3245
|
+
}
|
|
3246
|
+
}
|
|
3247
|
+
export class HTMLOptionElement extends HTMLElement {
|
|
3248
|
+
get disabled() {
|
|
3249
|
+
return this.hasAttribute("disabled");
|
|
3250
|
+
}
|
|
3251
|
+
set disabled(value) {
|
|
3252
|
+
toggleBooleanAttribute(this, "disabled", value);
|
|
3253
|
+
}
|
|
3254
|
+
}
|
|
3255
|
+
export class HTMLSelectElement extends HTMLElement {
|
|
3256
|
+
get value() {
|
|
3257
|
+
return super.value;
|
|
3258
|
+
}
|
|
3259
|
+
set value(value) {
|
|
3260
|
+
super.value = value;
|
|
3261
|
+
}
|
|
3262
|
+
get disabled() {
|
|
3263
|
+
return this.hasAttribute("disabled");
|
|
3264
|
+
}
|
|
3265
|
+
set disabled(value) {
|
|
3266
|
+
toggleBooleanAttribute(this, "disabled", value);
|
|
3267
|
+
}
|
|
3268
|
+
get required() {
|
|
3269
|
+
return this.hasAttribute("required");
|
|
3270
|
+
}
|
|
3271
|
+
set required(value) {
|
|
3272
|
+
toggleBooleanAttribute(this, "required", value);
|
|
3273
|
+
}
|
|
3274
|
+
}
|
|
3275
|
+
export class HTMLStyleElement extends HTMLElement {
|
|
3276
|
+
#sheet = null;
|
|
3277
|
+
#sheetText = "";
|
|
3278
|
+
get disabled() {
|
|
3279
|
+
return this.hasAttribute("disabled");
|
|
3280
|
+
}
|
|
3281
|
+
set disabled(value) {
|
|
3282
|
+
toggleBooleanAttribute(this, "disabled", value);
|
|
3283
|
+
}
|
|
3284
|
+
get media() {
|
|
3285
|
+
return this.getAttribute("media") ?? "";
|
|
3286
|
+
}
|
|
3287
|
+
set media(value) {
|
|
3288
|
+
this.setAttribute("media", String(value));
|
|
3289
|
+
}
|
|
3290
|
+
get type() {
|
|
3291
|
+
return this.getAttribute("type") ?? "";
|
|
3292
|
+
}
|
|
3293
|
+
set type(value) {
|
|
3294
|
+
this.setAttribute("type", String(value));
|
|
3295
|
+
}
|
|
3296
|
+
get sheet() {
|
|
3297
|
+
if (!this.isConnected) {
|
|
3298
|
+
return null;
|
|
3299
|
+
}
|
|
3300
|
+
this.#sheet ??= new CSSStyleSheet();
|
|
3301
|
+
const text = this.textContent;
|
|
3302
|
+
if (text !== this.#sheetText) {
|
|
3303
|
+
this.#sheet.replaceSync(text);
|
|
3304
|
+
this.#sheetText = text;
|
|
3305
|
+
}
|
|
3306
|
+
return this.#sheet;
|
|
3307
|
+
}
|
|
3308
|
+
}
|
|
3309
|
+
export class HTMLTextAreaElement extends HTMLElement {
|
|
3310
|
+
get disabled() {
|
|
3311
|
+
return this.hasAttribute("disabled");
|
|
3312
|
+
}
|
|
3313
|
+
set disabled(value) {
|
|
3314
|
+
toggleBooleanAttribute(this, "disabled", value);
|
|
3315
|
+
}
|
|
3316
|
+
get required() {
|
|
3317
|
+
return this.hasAttribute("required");
|
|
3318
|
+
}
|
|
3319
|
+
set required(value) {
|
|
3320
|
+
toggleBooleanAttribute(this, "required", value);
|
|
3321
|
+
}
|
|
3322
|
+
}
|
|
3323
|
+
function toggleBooleanAttribute(element, name, value) {
|
|
3324
|
+
if (value) {
|
|
3325
|
+
element.setAttribute(name, "");
|
|
3326
|
+
}
|
|
3327
|
+
else {
|
|
3328
|
+
element.removeAttribute(name);
|
|
3329
|
+
}
|
|
3330
|
+
}
|
|
3331
|
+
function isValidNumberValue(value) {
|
|
3332
|
+
return value.trim() !== "" && Number.isFinite(Number(value));
|
|
3333
|
+
}
|
|
3334
|
+
function isLabelableElement(element) {
|
|
3335
|
+
if (!(element instanceof HTMLElement)) {
|
|
3336
|
+
return false;
|
|
3337
|
+
}
|
|
3338
|
+
if (element.localName === "input" && element.type.toLowerCase() === "hidden") {
|
|
3339
|
+
return false;
|
|
3340
|
+
}
|
|
3341
|
+
return ["button", "meter", "output", "progress", "select", "textarea", "input"].includes(element.localName);
|
|
3342
|
+
}
|
|
3343
|
+
function isDisabledFormElement(element) {
|
|
3344
|
+
return element.hasAttribute("disabled");
|
|
3345
|
+
}
|
|
3346
|
+
function hasValidityState(element) {
|
|
3347
|
+
return (element instanceof HTMLElement &&
|
|
3348
|
+
["button", "input", "select", "textarea"].includes(element.localName));
|
|
3349
|
+
}
|
|
3350
|
+
function isFormAssociatedElement(element) {
|
|
3351
|
+
return (element instanceof HTMLElement &&
|
|
3352
|
+
["button", "fieldset", "input", "object", "output", "select", "textarea"].includes(element.localName));
|
|
3353
|
+
}
|
|
3354
|
+
function formDataEntryFor(element) {
|
|
3355
|
+
if (!["input", "select", "textarea"].includes(element.localName)) {
|
|
3356
|
+
return null;
|
|
3357
|
+
}
|
|
3358
|
+
if (isDisabledFormElement(element) || !element.name) {
|
|
3359
|
+
return null;
|
|
3360
|
+
}
|
|
3361
|
+
if (element.localName === "input") {
|
|
3362
|
+
const type = element.type.toLowerCase();
|
|
3363
|
+
if (["button", "file", "image", "reset", "submit"].includes(type)) {
|
|
3364
|
+
return null;
|
|
3365
|
+
}
|
|
3366
|
+
if ((type === "checkbox" || type === "radio") && !element.checked) {
|
|
3367
|
+
return null;
|
|
3368
|
+
}
|
|
3369
|
+
if ((type === "checkbox" || type === "radio") && !element.hasAttribute("value")) {
|
|
3370
|
+
return [element.name, "on"];
|
|
3371
|
+
}
|
|
3372
|
+
}
|
|
3373
|
+
return [element.name, element.value];
|
|
3374
|
+
}
|
|
3375
|
+
function activeDocument() {
|
|
3376
|
+
const candidate = globalThis.document;
|
|
3377
|
+
return candidate instanceof Document ? candidate : new Window().document;
|
|
3378
|
+
}
|
|
3379
|
+
export class Text extends Node {
|
|
3380
|
+
constructor(documentOrData = "", id, nodeName = "#text") {
|
|
3381
|
+
if (documentOrData instanceof Document && id !== undefined) {
|
|
3382
|
+
super(documentOrData, id, nodeName);
|
|
3383
|
+
return;
|
|
3384
|
+
}
|
|
3385
|
+
const document = activeDocument();
|
|
3386
|
+
super(document, document._native.createTextNode(String(documentOrData ?? "")), "#text");
|
|
3387
|
+
}
|
|
3388
|
+
get data() {
|
|
3389
|
+
return this.nodeValue ?? "";
|
|
3390
|
+
}
|
|
3391
|
+
set data(value) {
|
|
3392
|
+
this.nodeValue = value;
|
|
3393
|
+
}
|
|
3394
|
+
}
|
|
3395
|
+
export class Comment extends Node {
|
|
3396
|
+
constructor(documentOrData = "", id, nodeName = "#comment") {
|
|
3397
|
+
if (documentOrData instanceof Document && id !== undefined) {
|
|
3398
|
+
super(documentOrData, id, nodeName);
|
|
3399
|
+
return;
|
|
3400
|
+
}
|
|
3401
|
+
const document = activeDocument();
|
|
3402
|
+
super(document, document._native.createComment(String(documentOrData ?? "")), "#comment");
|
|
3403
|
+
}
|
|
3404
|
+
get data() {
|
|
3405
|
+
return this.nodeValue ?? "";
|
|
3406
|
+
}
|
|
3407
|
+
set data(value) {
|
|
3408
|
+
this.nodeValue = value;
|
|
3409
|
+
}
|
|
3410
|
+
}
|
|
3411
|
+
export class DocumentType extends Node {
|
|
3412
|
+
constructor(document, id, nodeName = null) {
|
|
3413
|
+
super(document, id, nodeName);
|
|
3414
|
+
}
|
|
3415
|
+
get name() {
|
|
3416
|
+
return this._document._native.documentTypeName(this._id);
|
|
3417
|
+
}
|
|
3418
|
+
get publicId() {
|
|
3419
|
+
return this._document._native.documentTypePublicId(this._id);
|
|
3420
|
+
}
|
|
3421
|
+
get systemId() {
|
|
3422
|
+
return this._document._native.documentTypeSystemId(this._id);
|
|
3423
|
+
}
|
|
3424
|
+
get nodeType() {
|
|
3425
|
+
return Node.DOCUMENT_TYPE_NODE;
|
|
3426
|
+
}
|
|
3427
|
+
get nodeValue() {
|
|
3428
|
+
return null;
|
|
3429
|
+
}
|
|
3430
|
+
set nodeValue(_value) { }
|
|
3431
|
+
get textContent() {
|
|
3432
|
+
return "";
|
|
3433
|
+
}
|
|
3434
|
+
set textContent(_value) { }
|
|
3435
|
+
get outerHTML() {
|
|
3436
|
+
return this._document._native.serializeNode(this._id);
|
|
3437
|
+
}
|
|
3438
|
+
}
|
|
3439
|
+
export class DocumentFragment extends Node {
|
|
3440
|
+
constructor(document, id, nodeName = "#document-fragment") {
|
|
3441
|
+
if (document instanceof Document && id !== undefined) {
|
|
3442
|
+
super(document, id, nodeName);
|
|
3443
|
+
return;
|
|
3444
|
+
}
|
|
3445
|
+
const active = activeDocument();
|
|
3446
|
+
super(active, active._native.createDocumentFragment(), "#document-fragment");
|
|
3447
|
+
}
|
|
3448
|
+
get children() {
|
|
3449
|
+
return new NativeNodeList(this._document, this._document._native.elementChildren(this._id));
|
|
3450
|
+
}
|
|
3451
|
+
get childElementCount() {
|
|
3452
|
+
return this._document._native.childElementCount(this._id);
|
|
3453
|
+
}
|
|
3454
|
+
get firstElementChild() {
|
|
3455
|
+
const id = this._document._native.firstElementChild(this._id);
|
|
3456
|
+
return id == null ? null : this._document._wrap(id);
|
|
3457
|
+
}
|
|
3458
|
+
get lastElementChild() {
|
|
3459
|
+
const id = this._document._native.lastElementChild(this._id);
|
|
3460
|
+
return id == null ? null : this._document._wrap(id);
|
|
3461
|
+
}
|
|
3462
|
+
get innerHTML() {
|
|
3463
|
+
return this._document._native.serializeChildren(this._id);
|
|
3464
|
+
}
|
|
3465
|
+
set innerHTML(html) {
|
|
3466
|
+
if (!hasMutationObservers()) {
|
|
3467
|
+
this._document._native.setInnerHtml(this._id, html);
|
|
3468
|
+
this._document._bumpMutationVersion();
|
|
3469
|
+
return;
|
|
3470
|
+
}
|
|
3471
|
+
while (this.firstChild) {
|
|
3472
|
+
this.removeChild(this.firstChild);
|
|
3473
|
+
}
|
|
3474
|
+
this.appendChild(fragmentFromHtml(this._document, html));
|
|
3475
|
+
}
|
|
3476
|
+
querySelector(selector) {
|
|
3477
|
+
const id = this._document._querySelector(this._id, selector);
|
|
3478
|
+
return id == null ? null : this._document._wrap(id);
|
|
3479
|
+
}
|
|
3480
|
+
querySelectorAll(selector) {
|
|
3481
|
+
return new NativeNodeList(this._document, this._document._querySelectorAll(this._id, selector));
|
|
3482
|
+
}
|
|
3483
|
+
getElementById(id) {
|
|
3484
|
+
const nativeId = this._document._native.elementById(this._id, String(id));
|
|
3485
|
+
return nativeId == null ? null : this._document._wrap(nativeId);
|
|
3486
|
+
}
|
|
3487
|
+
}
|
|
3488
|
+
export class ShadowRoot extends DocumentFragment {
|
|
3489
|
+
delegatesFocus = false;
|
|
3490
|
+
host;
|
|
3491
|
+
mode;
|
|
3492
|
+
constructor(document, id, host, mode) {
|
|
3493
|
+
super(document, id, "#document-fragment");
|
|
3494
|
+
this.host = host;
|
|
3495
|
+
this.mode = mode;
|
|
3496
|
+
}
|
|
3497
|
+
}
|
|
3498
|
+
export class TreeWalker {
|
|
3499
|
+
currentNode;
|
|
3500
|
+
root;
|
|
3501
|
+
whatToShow;
|
|
3502
|
+
filter;
|
|
3503
|
+
#document;
|
|
3504
|
+
#nodeIds;
|
|
3505
|
+
#index = 0;
|
|
3506
|
+
constructor(root, whatToShow = NodeFilter.SHOW_ALL, filter = null) {
|
|
3507
|
+
this.root = root;
|
|
3508
|
+
this.currentNode = root;
|
|
3509
|
+
this.whatToShow = whatToShow;
|
|
3510
|
+
this.filter = filter;
|
|
3511
|
+
const order = nativeDocumentOrder(root);
|
|
3512
|
+
this.#document = order.document;
|
|
3513
|
+
this.#nodeIds = order.ids;
|
|
3514
|
+
}
|
|
3515
|
+
nextNode() {
|
|
3516
|
+
for (let index = this.#index + 1; index < this.#nodeIds.length; index++) {
|
|
3517
|
+
const node = this.#document._wrap(this.#nodeIds[index]);
|
|
3518
|
+
if (this.#accepts(node)) {
|
|
3519
|
+
this.#index = index;
|
|
3520
|
+
this.currentNode = node;
|
|
3521
|
+
return node;
|
|
3522
|
+
}
|
|
3523
|
+
}
|
|
3524
|
+
return null;
|
|
3525
|
+
}
|
|
3526
|
+
previousNode() {
|
|
3527
|
+
for (let index = this.#index - 1; index >= 0; index--) {
|
|
3528
|
+
const node = this.#document._wrap(this.#nodeIds[index]);
|
|
3529
|
+
if (this.#accepts(node)) {
|
|
3530
|
+
this.#index = index;
|
|
3531
|
+
this.currentNode = node;
|
|
3532
|
+
return node;
|
|
3533
|
+
}
|
|
3534
|
+
}
|
|
3535
|
+
return null;
|
|
3536
|
+
}
|
|
3537
|
+
#accepts(node) {
|
|
3538
|
+
if (!(this.whatToShow & nodeFilterMaskFor(node))) {
|
|
3539
|
+
return false;
|
|
3540
|
+
}
|
|
3541
|
+
if (!this.filter) {
|
|
3542
|
+
return true;
|
|
3543
|
+
}
|
|
3544
|
+
const result = typeof this.filter === "function"
|
|
3545
|
+
? this.filter(node)
|
|
3546
|
+
: this.filter.acceptNode(node);
|
|
3547
|
+
return result === NodeFilter.FILTER_ACCEPT;
|
|
3548
|
+
}
|
|
3549
|
+
}
|
|
3550
|
+
export class NodeIterator {
|
|
3551
|
+
root;
|
|
3552
|
+
whatToShow;
|
|
3553
|
+
filter;
|
|
3554
|
+
#document;
|
|
3555
|
+
#nodeIds;
|
|
3556
|
+
#index = -1;
|
|
3557
|
+
constructor(root, whatToShow = NodeFilter.SHOW_ALL, filter = null) {
|
|
3558
|
+
this.root = root;
|
|
3559
|
+
this.whatToShow = whatToShow;
|
|
3560
|
+
this.filter = filter;
|
|
3561
|
+
const order = nativeDocumentOrder(root);
|
|
3562
|
+
this.#document = order.document;
|
|
3563
|
+
this.#nodeIds = order.ids;
|
|
3564
|
+
}
|
|
3565
|
+
nextNode() {
|
|
3566
|
+
for (let index = this.#index + 1; index < this.#nodeIds.length; index++) {
|
|
3567
|
+
const node = this.#document._wrap(this.#nodeIds[index]);
|
|
3568
|
+
if (this.#accepts(node)) {
|
|
3569
|
+
this.#index = index;
|
|
3570
|
+
return node;
|
|
3571
|
+
}
|
|
3572
|
+
}
|
|
3573
|
+
return null;
|
|
3574
|
+
}
|
|
3575
|
+
previousNode() {
|
|
3576
|
+
for (let index = this.#index - 1; index >= 0; index--) {
|
|
3577
|
+
const node = this.#document._wrap(this.#nodeIds[index]);
|
|
3578
|
+
if (this.#accepts(node)) {
|
|
3579
|
+
this.#index = index;
|
|
3580
|
+
return node;
|
|
3581
|
+
}
|
|
3582
|
+
}
|
|
3583
|
+
return null;
|
|
3584
|
+
}
|
|
3585
|
+
detach() { }
|
|
3586
|
+
#accepts(node) {
|
|
3587
|
+
if (!(this.whatToShow & nodeFilterMaskFor(node))) {
|
|
3588
|
+
return false;
|
|
3589
|
+
}
|
|
3590
|
+
if (!this.filter) {
|
|
3591
|
+
return true;
|
|
3592
|
+
}
|
|
3593
|
+
const result = typeof this.filter === "function"
|
|
3594
|
+
? this.filter(node)
|
|
3595
|
+
: this.filter.acceptNode(node);
|
|
3596
|
+
return result === NodeFilter.FILTER_ACCEPT;
|
|
3597
|
+
}
|
|
3598
|
+
}
|
|
3599
|
+
function nodeFilterMaskFor(node) {
|
|
3600
|
+
switch (node.nodeType) {
|
|
3601
|
+
case Node.ELEMENT_NODE:
|
|
3602
|
+
return NodeFilter.SHOW_ELEMENT;
|
|
3603
|
+
case Node.TEXT_NODE:
|
|
3604
|
+
return NodeFilter.SHOW_TEXT;
|
|
3605
|
+
case Node.COMMENT_NODE:
|
|
3606
|
+
return NodeFilter.SHOW_COMMENT;
|
|
3607
|
+
case Node.DOCUMENT_NODE:
|
|
3608
|
+
return NodeFilter.SHOW_DOCUMENT;
|
|
3609
|
+
case Node.DOCUMENT_TYPE_NODE:
|
|
3610
|
+
return NodeFilter.SHOW_DOCUMENT_TYPE;
|
|
3611
|
+
case Node.DOCUMENT_FRAGMENT_NODE:
|
|
3612
|
+
return NodeFilter.SHOW_DOCUMENT_FRAGMENT;
|
|
3613
|
+
default:
|
|
3614
|
+
return 0;
|
|
3615
|
+
}
|
|
3616
|
+
}
|
|
3617
|
+
export class NativeNodeList {
|
|
3618
|
+
#document;
|
|
3619
|
+
#ids;
|
|
3620
|
+
constructor(document, ids) {
|
|
3621
|
+
this.#document = document;
|
|
3622
|
+
this.#ids = ids;
|
|
3623
|
+
return new Proxy(this, {
|
|
3624
|
+
get(target, property) {
|
|
3625
|
+
if (typeof property === "string" && isNodeListIndex(property, target.length)) {
|
|
3626
|
+
return target.item(Number(property));
|
|
3627
|
+
}
|
|
3628
|
+
const value = Reflect.get(target, property, target);
|
|
3629
|
+
return typeof value === "function" ? value.bind(target) : value;
|
|
3630
|
+
},
|
|
3631
|
+
getOwnPropertyDescriptor(target, property) {
|
|
3632
|
+
if (typeof property === "string" && isNodeListIndex(property, target.length)) {
|
|
3633
|
+
return {
|
|
3634
|
+
configurable: true,
|
|
3635
|
+
enumerable: true,
|
|
3636
|
+
value: target.item(Number(property))
|
|
3637
|
+
};
|
|
3638
|
+
}
|
|
3639
|
+
return Reflect.getOwnPropertyDescriptor(target, property);
|
|
3640
|
+
},
|
|
3641
|
+
has(target, property) {
|
|
3642
|
+
return ((typeof property === "string" && isNodeListIndex(property, target.length)) ||
|
|
3643
|
+
Reflect.has(target, property));
|
|
3644
|
+
},
|
|
3645
|
+
ownKeys(target) {
|
|
3646
|
+
return [
|
|
3647
|
+
...Array.from({ length: target.length }, (_value, index) => String(index)),
|
|
3648
|
+
...Reflect.ownKeys(target)
|
|
3649
|
+
];
|
|
3650
|
+
}
|
|
3651
|
+
});
|
|
3652
|
+
}
|
|
3653
|
+
get length() {
|
|
3654
|
+
return this.#ids.length;
|
|
3655
|
+
}
|
|
3656
|
+
item(index) {
|
|
3657
|
+
const id = this.#ids[index];
|
|
3658
|
+
return id == null ? null : this.#document._wrap(id);
|
|
3659
|
+
}
|
|
3660
|
+
forEach(callback) {
|
|
3661
|
+
for (let index = 0; index < this.length; index++) {
|
|
3662
|
+
const value = this.item(index);
|
|
3663
|
+
if (value) {
|
|
3664
|
+
callback(value, index, this);
|
|
3665
|
+
}
|
|
3666
|
+
}
|
|
3667
|
+
}
|
|
3668
|
+
[Symbol.iterator]() {
|
|
3669
|
+
let index = 0;
|
|
3670
|
+
return {
|
|
3671
|
+
next: () => {
|
|
3672
|
+
const value = this.item(index++);
|
|
3673
|
+
return value == null ? { done: true, value: undefined } : { done: false, value };
|
|
3674
|
+
}
|
|
3675
|
+
};
|
|
3676
|
+
}
|
|
3677
|
+
}
|
|
3678
|
+
function isNodeListIndex(property, length) {
|
|
3679
|
+
if (!/^(0|[1-9]\d*)$/.test(property)) {
|
|
3680
|
+
return false;
|
|
3681
|
+
}
|
|
3682
|
+
const index = Number(property);
|
|
3683
|
+
return Number.isSafeInteger(index) && index >= 0 && index < length;
|
|
3684
|
+
}
|
|
3685
|
+
//# sourceMappingURL=index.js.map
|