@gjsify/dom-elements 0.3.13 → 0.3.15
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/lib/esm/_virtual/_rolldown/runtime.js +18 -0
- package/lib/esm/attr.js +37 -30
- package/lib/esm/character-data.js +61 -54
- package/lib/esm/comment.js +26 -19
- package/lib/esm/document-fragment.js +116 -109
- package/lib/esm/document.js +75 -81
- package/lib/esm/dom-matrix.js +158 -123
- package/lib/esm/dom-token-list.js +114 -108
- package/lib/esm/element.js +244 -246
- package/lib/esm/font-face.js +94 -89
- package/lib/esm/gst-time.js +17 -6
- package/lib/esm/html-canvas-element.js +82 -75
- package/lib/esm/html-element.js +424 -424
- package/lib/esm/html-image-element.js +226 -225
- package/lib/esm/html-media-element.js +117 -114
- package/lib/esm/html-video-element.js +110 -108
- package/lib/esm/image.js +27 -21
- package/lib/esm/index.js +13 -45
- package/lib/esm/intersection-observer.js +22 -18
- package/lib/esm/location-stub.js +25 -23
- package/lib/esm/match-media.js +18 -19
- package/lib/esm/mutation-observer.js +18 -13
- package/lib/esm/named-node-map.js +121 -121
- package/lib/esm/namespace-uri.js +9 -8
- package/lib/esm/node-list.js +39 -33
- package/lib/esm/node-type.js +13 -12
- package/lib/esm/node.js +241 -246
- package/lib/esm/property-symbol.js +36 -30
- package/lib/esm/register/canvas.js +11 -7
- package/lib/esm/register/document.js +19 -18
- package/lib/esm/register/font-face.js +10 -6
- package/lib/esm/register/helpers.js +14 -12
- package/lib/esm/register/image.js +4 -0
- package/lib/esm/register/location.js +4 -0
- package/lib/esm/register/match-media.js +4 -0
- package/lib/esm/register/navigator.js +4 -1
- package/lib/esm/register/observers.js +5 -1
- package/lib/esm/resize-observer.js +15 -12
- package/lib/esm/text.js +56 -49
- package/lib/esm/types/index.js +3 -3
- package/package.json +11 -11
package/lib/esm/element.js
CHANGED
|
@@ -1,249 +1,247 @@
|
|
|
1
|
-
|
|
2
|
-
import { Node } from "./node.js";
|
|
1
|
+
import { attributes, childNodesList, elementChildren, localName, namespaceURI, nodeType, parentNode, prefix, propertyEventListeners, tagName } from "./property-symbol.js";
|
|
3
2
|
import { NodeType } from "./node-type.js";
|
|
4
|
-
import {
|
|
3
|
+
import { Node } from "./node.js";
|
|
5
4
|
import { NamespaceURI } from "./namespace-uri.js";
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
export {
|
|
248
|
-
Element
|
|
5
|
+
import { NamedNodeMap } from "./named-node-map.js";
|
|
6
|
+
|
|
7
|
+
//#region src/element.ts
|
|
8
|
+
let _PS$tagName, _PS$localName, _PS$namespaceURI, _PS$prefix, _PS$attributes, _PS$propertyEventList;
|
|
9
|
+
/**
|
|
10
|
+
* DOM Element class.
|
|
11
|
+
*
|
|
12
|
+
* Reference: https://developer.mozilla.org/en-US/docs/Web/API/Element
|
|
13
|
+
*/
|
|
14
|
+
var Element = class extends Node {
|
|
15
|
+
constructor() {
|
|
16
|
+
super();
|
|
17
|
+
this[_PS$tagName] = "";
|
|
18
|
+
this[_PS$localName] = "";
|
|
19
|
+
this[_PS$namespaceURI] = NamespaceURI.html;
|
|
20
|
+
this[_PS$prefix] = null;
|
|
21
|
+
this[_PS$attributes] = new NamedNodeMap(this);
|
|
22
|
+
this[_PS$propertyEventList] = new Map();
|
|
23
|
+
this._pointerCaptures = new Set();
|
|
24
|
+
this[nodeType] = NodeType.ELEMENT_NODE;
|
|
25
|
+
}
|
|
26
|
+
get tagName() {
|
|
27
|
+
return this[tagName];
|
|
28
|
+
}
|
|
29
|
+
get localName() {
|
|
30
|
+
return this[localName];
|
|
31
|
+
}
|
|
32
|
+
get namespaceURI() {
|
|
33
|
+
return this[namespaceURI];
|
|
34
|
+
}
|
|
35
|
+
get prefix() {
|
|
36
|
+
return this[prefix];
|
|
37
|
+
}
|
|
38
|
+
get nodeName() {
|
|
39
|
+
return this[tagName];
|
|
40
|
+
}
|
|
41
|
+
get attributes() {
|
|
42
|
+
return this[attributes];
|
|
43
|
+
}
|
|
44
|
+
get id() {
|
|
45
|
+
return this.getAttribute("id") ?? "";
|
|
46
|
+
}
|
|
47
|
+
set id(value) {
|
|
48
|
+
this.setAttribute("id", value);
|
|
49
|
+
}
|
|
50
|
+
get className() {
|
|
51
|
+
return this.getAttribute("class") ?? "";
|
|
52
|
+
}
|
|
53
|
+
set className(value) {
|
|
54
|
+
this.setAttribute("class", value);
|
|
55
|
+
}
|
|
56
|
+
get children() {
|
|
57
|
+
return this[elementChildren];
|
|
58
|
+
}
|
|
59
|
+
get childElementCount() {
|
|
60
|
+
return this[elementChildren].length;
|
|
61
|
+
}
|
|
62
|
+
get firstElementChild() {
|
|
63
|
+
return this[elementChildren][0] ?? null;
|
|
64
|
+
}
|
|
65
|
+
get lastElementChild() {
|
|
66
|
+
const children = this[elementChildren];
|
|
67
|
+
return children[children.length - 1] ?? null;
|
|
68
|
+
}
|
|
69
|
+
get previousElementSibling() {
|
|
70
|
+
const parent = this[parentNode];
|
|
71
|
+
if (!parent) return null;
|
|
72
|
+
const siblings = parent[elementChildren];
|
|
73
|
+
const idx = siblings.indexOf(this);
|
|
74
|
+
return idx > 0 ? siblings[idx - 1] : null;
|
|
75
|
+
}
|
|
76
|
+
get nextElementSibling() {
|
|
77
|
+
const parent = this[parentNode];
|
|
78
|
+
if (!parent) return null;
|
|
79
|
+
const siblings = parent[elementChildren];
|
|
80
|
+
const idx = siblings.indexOf(this);
|
|
81
|
+
return idx !== -1 && idx < siblings.length - 1 ? siblings[idx + 1] : null;
|
|
82
|
+
}
|
|
83
|
+
get textContent() {
|
|
84
|
+
let text = "";
|
|
85
|
+
for (const child of this[childNodesList]) {
|
|
86
|
+
if (child.textContent !== null) {
|
|
87
|
+
text += child.textContent;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return text;
|
|
91
|
+
}
|
|
92
|
+
set textContent(_value) {
|
|
93
|
+
const children = this[childNodesList];
|
|
94
|
+
while (children.length > 0) {
|
|
95
|
+
this.removeChild(children[0]);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
getAttribute(qualifiedName) {
|
|
99
|
+
const attr = this[attributes].getNamedItem(qualifiedName);
|
|
100
|
+
return attr ? attr.value : null;
|
|
101
|
+
}
|
|
102
|
+
getAttributeNS(namespace, localName) {
|
|
103
|
+
const attr = this[attributes].getNamedItemNS(namespace, localName);
|
|
104
|
+
return attr ? attr.value : null;
|
|
105
|
+
}
|
|
106
|
+
setAttribute(qualifiedName, value) {
|
|
107
|
+
this[attributes]._setNamedItem(qualifiedName, String(value));
|
|
108
|
+
}
|
|
109
|
+
setAttributeNS(namespace, qualifiedName, value) {
|
|
110
|
+
const ns = namespace === "" ? null : namespace;
|
|
111
|
+
const parts = qualifiedName.split(":");
|
|
112
|
+
const prefix = parts.length > 1 ? parts[0] : null;
|
|
113
|
+
this[attributes]._setNamedItem(qualifiedName, String(value), ns, prefix);
|
|
114
|
+
}
|
|
115
|
+
removeAttribute(qualifiedName) {
|
|
116
|
+
this[attributes]._removeNamedItem(qualifiedName);
|
|
117
|
+
}
|
|
118
|
+
removeAttributeNS(namespace, localName) {
|
|
119
|
+
const ns = namespace === "" ? null : namespace;
|
|
120
|
+
this[attributes]._removeNamedItemNS(ns, localName);
|
|
121
|
+
}
|
|
122
|
+
hasAttribute(qualifiedName) {
|
|
123
|
+
return this[attributes].getNamedItem(qualifiedName) !== null;
|
|
124
|
+
}
|
|
125
|
+
hasAttributeNS(namespace, localName) {
|
|
126
|
+
return this[attributes].getNamedItemNS(namespace, localName) !== null;
|
|
127
|
+
}
|
|
128
|
+
getAttributeNode(qualifiedName) {
|
|
129
|
+
return this[attributes].getNamedItem(qualifiedName);
|
|
130
|
+
}
|
|
131
|
+
setAttributeNode(attr) {
|
|
132
|
+
return this[attributes].setNamedItem(attr);
|
|
133
|
+
}
|
|
134
|
+
removeAttributeNode(attr) {
|
|
135
|
+
const existing = this[attributes].getNamedItem(attr.name);
|
|
136
|
+
if (!existing) {
|
|
137
|
+
throw new DOMException("Failed to execute 'removeAttributeNode' on 'Element': The attribute is not owned by this element.", "NotFoundError");
|
|
138
|
+
}
|
|
139
|
+
this[attributes].removeNamedItem(existing.name);
|
|
140
|
+
return existing;
|
|
141
|
+
}
|
|
142
|
+
toggleAttribute(qualifiedName, force) {
|
|
143
|
+
if (force !== undefined) {
|
|
144
|
+
if (force) {
|
|
145
|
+
this.setAttribute(qualifiedName, "");
|
|
146
|
+
return true;
|
|
147
|
+
}
|
|
148
|
+
this.removeAttribute(qualifiedName);
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
if (this.hasAttribute(qualifiedName)) {
|
|
152
|
+
this.removeAttribute(qualifiedName);
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
this.setAttribute(qualifiedName, "");
|
|
156
|
+
return true;
|
|
157
|
+
}
|
|
158
|
+
hasAttributes() {
|
|
159
|
+
return this[attributes].length > 0;
|
|
160
|
+
}
|
|
161
|
+
dispatchEvent(event) {
|
|
162
|
+
const result = super.dispatchEvent(event);
|
|
163
|
+
const handler = this[propertyEventListeners].get("on" + event.type);
|
|
164
|
+
if (typeof handler === "function") {
|
|
165
|
+
handler.call(this, event);
|
|
166
|
+
}
|
|
167
|
+
return result;
|
|
168
|
+
}
|
|
169
|
+
querySelector(_selectors) {
|
|
170
|
+
return null;
|
|
171
|
+
}
|
|
172
|
+
querySelectorAll(_selectors) {
|
|
173
|
+
return [];
|
|
174
|
+
}
|
|
175
|
+
matches(_selectors) {
|
|
176
|
+
return false;
|
|
177
|
+
}
|
|
178
|
+
closest(_selectors) {
|
|
179
|
+
return null;
|
|
180
|
+
}
|
|
181
|
+
getElementsByTagName(tagName$1) {
|
|
182
|
+
const results = [];
|
|
183
|
+
const upperTag = tagName$1.toUpperCase();
|
|
184
|
+
const walk = (node) => {
|
|
185
|
+
for (const child of node[childNodesList]) {
|
|
186
|
+
if (child[nodeType] === NodeType.ELEMENT_NODE) {
|
|
187
|
+
const el = child;
|
|
188
|
+
if (tagName$1 === "*" || el[tagName] === upperTag) {
|
|
189
|
+
results.push(el);
|
|
190
|
+
}
|
|
191
|
+
walk(el);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
walk(this);
|
|
196
|
+
return results;
|
|
197
|
+
}
|
|
198
|
+
getElementsByClassName(className) {
|
|
199
|
+
const results = [];
|
|
200
|
+
const targetClasses = className.split(/\s+/).filter(Boolean);
|
|
201
|
+
const walk = (node) => {
|
|
202
|
+
for (const child of node[childNodesList]) {
|
|
203
|
+
if (child[nodeType] === NodeType.ELEMENT_NODE) {
|
|
204
|
+
const el = child;
|
|
205
|
+
const elClasses = el.className.split(/\s+/);
|
|
206
|
+
if (targetClasses.every((c) => elClasses.includes(c))) {
|
|
207
|
+
results.push(el);
|
|
208
|
+
}
|
|
209
|
+
walk(el);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
walk(this);
|
|
214
|
+
return results;
|
|
215
|
+
}
|
|
216
|
+
cloneNode(deep = false) {
|
|
217
|
+
const clone = super.cloneNode(false);
|
|
218
|
+
clone[tagName] = this[tagName];
|
|
219
|
+
clone[localName] = this[localName];
|
|
220
|
+
clone[namespaceURI] = this[namespaceURI];
|
|
221
|
+
clone[prefix] = this[prefix];
|
|
222
|
+
for (const attr of this[attributes]) {
|
|
223
|
+
clone.setAttributeNS(attr.namespaceURI, attr.name, attr.value);
|
|
224
|
+
}
|
|
225
|
+
if (deep) {
|
|
226
|
+
for (const child of this[childNodesList]) {
|
|
227
|
+
clone.appendChild(child.cloneNode(true));
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
return clone;
|
|
231
|
+
}
|
|
232
|
+
setPointerCapture(pointerId) {
|
|
233
|
+
this._pointerCaptures.add(pointerId);
|
|
234
|
+
}
|
|
235
|
+
releasePointerCapture(pointerId) {
|
|
236
|
+
this._pointerCaptures.delete(pointerId);
|
|
237
|
+
}
|
|
238
|
+
hasPointerCapture(pointerId) {
|
|
239
|
+
return this._pointerCaptures.has(pointerId);
|
|
240
|
+
}
|
|
241
|
+
get [(_PS$tagName = tagName, _PS$localName = localName, _PS$namespaceURI = namespaceURI, _PS$prefix = prefix, _PS$attributes = attributes, _PS$propertyEventList = propertyEventListeners, Symbol.toStringTag)]() {
|
|
242
|
+
return "Element";
|
|
243
|
+
}
|
|
249
244
|
};
|
|
245
|
+
|
|
246
|
+
//#endregion
|
|
247
|
+
export { Element };
|