@gjsify/dom-elements 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +31 -0
- package/lib/esm/attr.js +31 -0
- package/lib/esm/character-data.js +56 -0
- package/lib/esm/comment.js +21 -0
- package/lib/esm/document-fragment.js +112 -0
- package/lib/esm/document.js +83 -0
- package/lib/esm/dom-token-list.js +109 -0
- package/lib/esm/element.js +237 -0
- package/lib/esm/html-canvas-element.js +65 -0
- package/lib/esm/html-element.js +346 -0
- package/lib/esm/html-image-element.js +184 -0
- package/lib/esm/image.js +23 -0
- package/lib/esm/index.js +112 -0
- package/lib/esm/intersection-observer.js +19 -0
- package/lib/esm/mutation-observer.js +14 -0
- package/lib/esm/named-node-map.js +124 -0
- package/lib/esm/namespace-uri.js +10 -0
- package/lib/esm/node-list.js +34 -0
- package/lib/esm/node-type.js +14 -0
- package/lib/esm/node.js +227 -0
- package/lib/esm/property-symbol.js +30 -0
- package/lib/esm/resize-observer.js +13 -0
- package/lib/esm/text.js +51 -0
- package/lib/esm/types/i-html-image-element.js +0 -0
- package/lib/esm/types/image-data.js +0 -0
- package/lib/esm/types/index.js +3 -0
- package/lib/esm/types/predefined-color-space.js +0 -0
- package/lib/types/attr.d.ts +22 -0
- package/lib/types/character-data.d.ts +24 -0
- package/lib/types/comment.d.ts +12 -0
- package/lib/types/document-fragment.d.ts +37 -0
- package/lib/types/document.d.ts +39 -0
- package/lib/types/dom-token-list.d.ts +30 -0
- package/lib/types/element.d.ts +58 -0
- package/lib/types/html-canvas-element.d.ts +40 -0
- package/lib/types/html-element.d.ts +119 -0
- package/lib/types/html-image-element.d.ts +65 -0
- package/lib/types/image.d.ts +17 -0
- package/lib/types/index.d.ts +21 -0
- package/lib/types/intersection-observer.d.ts +21 -0
- package/lib/types/mutation-observer.d.ts +24 -0
- package/lib/types/named-node-map.d.ts +31 -0
- package/lib/types/namespace-uri.d.ts +7 -0
- package/lib/types/node-list.d.ts +18 -0
- package/lib/types/node-type.d.ts +11 -0
- package/lib/types/node.d.ts +63 -0
- package/lib/types/property-symbol.d.ts +14 -0
- package/lib/types/resize-observer.d.ts +13 -0
- package/lib/types/text.d.ts +21 -0
- package/lib/types/types/i-html-image-element.d.ts +41 -0
- package/lib/types/types/image-data.d.ts +11 -0
- package/lib/types/types/index.d.ts +3 -0
- package/lib/types/types/predefined-color-space.d.ts +1 -0
- package/package.json +43 -0
- package/src/attr.ts +61 -0
- package/src/character-data.ts +79 -0
- package/src/comment.ts +31 -0
- package/src/document-fragment.ts +137 -0
- package/src/document.ts +93 -0
- package/src/dom-token-list.ts +140 -0
- package/src/element.ts +299 -0
- package/src/html-canvas-element.ts +81 -0
- package/src/html-element.ts +422 -0
- package/src/html-image-element.ts +242 -0
- package/src/image.ts +31 -0
- package/src/index.spec.ts +897 -0
- package/src/index.ts +95 -0
- package/src/intersection-observer.ts +42 -0
- package/src/mutation-observer.ts +39 -0
- package/src/named-node-map.ts +159 -0
- package/src/namespace-uri.ts +11 -0
- package/src/node-list.ts +52 -0
- package/src/node-type.ts +14 -0
- package/src/node.ts +250 -0
- package/src/property-symbol.ts +23 -0
- package/src/resize-observer.ts +28 -0
- package/src/test.mts +6 -0
- package/src/text.ts +67 -0
- package/src/types/i-html-image-element.ts +44 -0
- package/src/types/image-data.ts +12 -0
- package/src/types/index.ts +3 -0
- package/src/types/predefined-color-space.ts +1 -0
- package/tsconfig.json +37 -0
- package/tsconfig.tsbuildinfo +1 -0
package/lib/esm/index.js
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { Attr } from "./attr.js";
|
|
2
|
+
import { NamedNodeMap } from "./named-node-map.js";
|
|
3
|
+
import { NodeList } from "./node-list.js";
|
|
4
|
+
import { Node } from "./node.js";
|
|
5
|
+
import { CharacterData } from "./character-data.js";
|
|
6
|
+
import { Text } from "./text.js";
|
|
7
|
+
import { Comment } from "./comment.js";
|
|
8
|
+
import { DocumentFragment } from "./document-fragment.js";
|
|
9
|
+
import { DOMTokenList } from "./dom-token-list.js";
|
|
10
|
+
import { Element } from "./element.js";
|
|
11
|
+
import { HTMLElement, CSSStyleDeclaration } from "./html-element.js";
|
|
12
|
+
import { HTMLCanvasElement } from "./html-canvas-element.js";
|
|
13
|
+
import { HTMLImageElement } from "./html-image-element.js";
|
|
14
|
+
import { Image } from "./image.js";
|
|
15
|
+
import { Document, document } from "./document.js";
|
|
16
|
+
import { MutationObserver } from "./mutation-observer.js";
|
|
17
|
+
import { ResizeObserver } from "./resize-observer.js";
|
|
18
|
+
import { IntersectionObserver } from "./intersection-observer.js";
|
|
19
|
+
import { NodeType } from "./node-type.js";
|
|
20
|
+
import { NamespaceURI } from "./namespace-uri.js";
|
|
21
|
+
import * as PropertySymbol from "./property-symbol.js";
|
|
22
|
+
import { Text as Text2 } from "./text.js";
|
|
23
|
+
import { Comment as Comment2 } from "./comment.js";
|
|
24
|
+
import { DocumentFragment as DocumentFragment2 } from "./document-fragment.js";
|
|
25
|
+
import { DOMTokenList as DOMTokenList2 } from "./dom-token-list.js";
|
|
26
|
+
import { HTMLCanvasElement as HTMLCanvasElement2 } from "./html-canvas-element.js";
|
|
27
|
+
import { HTMLImageElement as HTMLImageElement2 } from "./html-image-element.js";
|
|
28
|
+
import { Image as Image2 } from "./image.js";
|
|
29
|
+
import { document as document2 } from "./document.js";
|
|
30
|
+
import { MutationObserver as MutationObserver2 } from "./mutation-observer.js";
|
|
31
|
+
import { ResizeObserver as ResizeObserver2 } from "./resize-observer.js";
|
|
32
|
+
import { IntersectionObserver as IntersectionObserver2 } from "./intersection-observer.js";
|
|
33
|
+
Object.defineProperty(globalThis, "Text", {
|
|
34
|
+
value: Text2,
|
|
35
|
+
writable: true,
|
|
36
|
+
configurable: true
|
|
37
|
+
});
|
|
38
|
+
Object.defineProperty(globalThis, "Comment", {
|
|
39
|
+
value: Comment2,
|
|
40
|
+
writable: true,
|
|
41
|
+
configurable: true
|
|
42
|
+
});
|
|
43
|
+
Object.defineProperty(globalThis, "DocumentFragment", {
|
|
44
|
+
value: DocumentFragment2,
|
|
45
|
+
writable: true,
|
|
46
|
+
configurable: true
|
|
47
|
+
});
|
|
48
|
+
Object.defineProperty(globalThis, "DOMTokenList", {
|
|
49
|
+
value: DOMTokenList2,
|
|
50
|
+
writable: true,
|
|
51
|
+
configurable: true
|
|
52
|
+
});
|
|
53
|
+
Object.defineProperty(globalThis, "HTMLCanvasElement", {
|
|
54
|
+
value: HTMLCanvasElement2,
|
|
55
|
+
writable: true,
|
|
56
|
+
configurable: true
|
|
57
|
+
});
|
|
58
|
+
Object.defineProperty(globalThis, "HTMLImageElement", {
|
|
59
|
+
value: HTMLImageElement2,
|
|
60
|
+
writable: true,
|
|
61
|
+
configurable: true
|
|
62
|
+
});
|
|
63
|
+
Object.defineProperty(globalThis, "Image", {
|
|
64
|
+
value: Image2,
|
|
65
|
+
writable: true,
|
|
66
|
+
configurable: true
|
|
67
|
+
});
|
|
68
|
+
Object.defineProperty(globalThis, "document", {
|
|
69
|
+
value: document2,
|
|
70
|
+
writable: true,
|
|
71
|
+
configurable: true
|
|
72
|
+
});
|
|
73
|
+
Object.defineProperty(globalThis, "MutationObserver", {
|
|
74
|
+
value: MutationObserver2,
|
|
75
|
+
writable: true,
|
|
76
|
+
configurable: true
|
|
77
|
+
});
|
|
78
|
+
Object.defineProperty(globalThis, "ResizeObserver", {
|
|
79
|
+
value: ResizeObserver2,
|
|
80
|
+
writable: true,
|
|
81
|
+
configurable: true
|
|
82
|
+
});
|
|
83
|
+
Object.defineProperty(globalThis, "IntersectionObserver", {
|
|
84
|
+
value: IntersectionObserver2,
|
|
85
|
+
writable: true,
|
|
86
|
+
configurable: true
|
|
87
|
+
});
|
|
88
|
+
export {
|
|
89
|
+
Attr,
|
|
90
|
+
CSSStyleDeclaration,
|
|
91
|
+
CharacterData,
|
|
92
|
+
Comment,
|
|
93
|
+
DOMTokenList,
|
|
94
|
+
Document,
|
|
95
|
+
DocumentFragment,
|
|
96
|
+
Element,
|
|
97
|
+
HTMLCanvasElement,
|
|
98
|
+
HTMLElement,
|
|
99
|
+
HTMLImageElement,
|
|
100
|
+
Image,
|
|
101
|
+
IntersectionObserver,
|
|
102
|
+
MutationObserver,
|
|
103
|
+
NamedNodeMap,
|
|
104
|
+
NamespaceURI,
|
|
105
|
+
Node,
|
|
106
|
+
NodeList,
|
|
107
|
+
NodeType,
|
|
108
|
+
PropertySymbol,
|
|
109
|
+
ResizeObserver,
|
|
110
|
+
Text,
|
|
111
|
+
document
|
|
112
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
class IntersectionObserver {
|
|
2
|
+
constructor(_callback, options) {
|
|
3
|
+
this.root = options?.root ?? null;
|
|
4
|
+
this.rootMargin = options?.rootMargin ?? "0px";
|
|
5
|
+
this.thresholds = Array.isArray(options?.threshold) ? options.threshold : [options?.threshold ?? 0];
|
|
6
|
+
}
|
|
7
|
+
observe(_target) {
|
|
8
|
+
}
|
|
9
|
+
unobserve(_target) {
|
|
10
|
+
}
|
|
11
|
+
disconnect() {
|
|
12
|
+
}
|
|
13
|
+
takeRecords() {
|
|
14
|
+
return [];
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export {
|
|
18
|
+
IntersectionObserver
|
|
19
|
+
};
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { Attr } from "./attr.js";
|
|
2
|
+
import { NamespaceURI } from "./namespace-uri.js";
|
|
3
|
+
class NamedNodeMap {
|
|
4
|
+
constructor(ownerElement) {
|
|
5
|
+
this._items = [];
|
|
6
|
+
this._ownerElement = ownerElement;
|
|
7
|
+
}
|
|
8
|
+
get length() {
|
|
9
|
+
return this._items.length;
|
|
10
|
+
}
|
|
11
|
+
item(index) {
|
|
12
|
+
return this._items[index] ?? null;
|
|
13
|
+
}
|
|
14
|
+
getNamedItem(qualifiedName) {
|
|
15
|
+
return this._findByName(qualifiedName);
|
|
16
|
+
}
|
|
17
|
+
getNamedItemNS(namespace, localName) {
|
|
18
|
+
const ns = namespace === "" ? null : namespace;
|
|
19
|
+
for (const attr of this._items) {
|
|
20
|
+
if (attr.namespaceURI === ns && attr.localName === localName) {
|
|
21
|
+
return attr;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
setNamedItem(attr) {
|
|
27
|
+
return this._setAttr(attr);
|
|
28
|
+
}
|
|
29
|
+
setNamedItemNS(attr) {
|
|
30
|
+
return this._setAttr(attr);
|
|
31
|
+
}
|
|
32
|
+
removeNamedItem(qualifiedName) {
|
|
33
|
+
const existing = this._findByName(qualifiedName);
|
|
34
|
+
if (!existing) {
|
|
35
|
+
throw new DOMException(
|
|
36
|
+
`Failed to execute 'removeNamedItem' on 'NamedNodeMap': No item with name '${qualifiedName}' was found.`,
|
|
37
|
+
"NotFoundError"
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
this._removeAttr(existing);
|
|
41
|
+
return existing;
|
|
42
|
+
}
|
|
43
|
+
removeNamedItemNS(namespace, localName) {
|
|
44
|
+
const existing = this.getNamedItemNS(namespace, localName);
|
|
45
|
+
if (!existing) {
|
|
46
|
+
throw new DOMException(
|
|
47
|
+
`Failed to execute 'removeNamedItemNS' on 'NamedNodeMap': No item with namespace '${namespace}' and localName '${localName}' was found.`,
|
|
48
|
+
"NotFoundError"
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
this._removeAttr(existing);
|
|
52
|
+
return existing;
|
|
53
|
+
}
|
|
54
|
+
[Symbol.iterator]() {
|
|
55
|
+
return this._items[Symbol.iterator]();
|
|
56
|
+
}
|
|
57
|
+
get [Symbol.toStringTag]() {
|
|
58
|
+
return "NamedNodeMap";
|
|
59
|
+
}
|
|
60
|
+
// -- Internal helpers --
|
|
61
|
+
/** @internal Add or replace an attribute by name. */
|
|
62
|
+
_setNamedItem(name, value, namespaceURI = null, prefix = null) {
|
|
63
|
+
const existing = namespaceURI !== null ? this.getNamedItemNS(namespaceURI, name.includes(":") ? name.split(":")[1] : name) : this._findByName(name);
|
|
64
|
+
if (existing) {
|
|
65
|
+
existing.value = value;
|
|
66
|
+
} else {
|
|
67
|
+
const attr = new Attr(name, value, namespaceURI, prefix, this._ownerElement);
|
|
68
|
+
this._items.push(attr);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/** @internal Remove an attribute by name. Returns true if removed. */
|
|
72
|
+
_removeNamedItem(name) {
|
|
73
|
+
const existing = this._findByName(name);
|
|
74
|
+
if (existing) {
|
|
75
|
+
this._removeAttr(existing);
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
/** @internal Remove an attribute by namespace + localName. Returns true if removed. */
|
|
81
|
+
_removeNamedItemNS(namespace, localName) {
|
|
82
|
+
const existing = this.getNamedItemNS(namespace, localName);
|
|
83
|
+
if (existing) {
|
|
84
|
+
this._removeAttr(existing);
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
_findByName(qualifiedName) {
|
|
90
|
+
const isHTML = this._ownerElement.namespaceURI === NamespaceURI.html;
|
|
91
|
+
const searchName = isHTML ? qualifiedName.toLowerCase() : qualifiedName;
|
|
92
|
+
for (const attr of this._items) {
|
|
93
|
+
const attrName = isHTML ? attr.name.toLowerCase() : attr.name;
|
|
94
|
+
if (attrName === searchName) {
|
|
95
|
+
return attr;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
_setAttr(attr) {
|
|
101
|
+
let existing = null;
|
|
102
|
+
if (attr.namespaceURI !== null) {
|
|
103
|
+
existing = this.getNamedItemNS(attr.namespaceURI, attr.localName);
|
|
104
|
+
} else {
|
|
105
|
+
existing = this._findByName(attr.name);
|
|
106
|
+
}
|
|
107
|
+
if (existing) {
|
|
108
|
+
const oldAttr = new Attr(existing.name, existing.value, existing.namespaceURI, existing.prefix, existing.ownerElement);
|
|
109
|
+
existing.value = attr.value;
|
|
110
|
+
return oldAttr;
|
|
111
|
+
}
|
|
112
|
+
this._items.push(attr);
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
_removeAttr(attr) {
|
|
116
|
+
const idx = this._items.indexOf(attr);
|
|
117
|
+
if (idx !== -1) {
|
|
118
|
+
this._items.splice(idx, 1);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
export {
|
|
123
|
+
NamedNodeMap
|
|
124
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
const NamespaceURI = {
|
|
2
|
+
html: "http://www.w3.org/1999/xhtml",
|
|
3
|
+
svg: "http://www.w3.org/2000/svg",
|
|
4
|
+
mathML: "http://www.w3.org/1998/Math/MathML",
|
|
5
|
+
xml: "http://www.w3.org/XML/1998/namespace",
|
|
6
|
+
xmlns: "http://www.w3.org/2000/xmlns/"
|
|
7
|
+
};
|
|
8
|
+
export {
|
|
9
|
+
NamespaceURI
|
|
10
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
class NodeList {
|
|
2
|
+
constructor(items) {
|
|
3
|
+
this._items = items;
|
|
4
|
+
}
|
|
5
|
+
get length() {
|
|
6
|
+
return this._items.length;
|
|
7
|
+
}
|
|
8
|
+
item(index) {
|
|
9
|
+
return this._items[index] ?? null;
|
|
10
|
+
}
|
|
11
|
+
forEach(callback, thisArg) {
|
|
12
|
+
for (let i = 0; i < this._items.length; i++) {
|
|
13
|
+
callback.call(thisArg, this._items[i], i, this);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
entries() {
|
|
17
|
+
return this._items.entries();
|
|
18
|
+
}
|
|
19
|
+
keys() {
|
|
20
|
+
return this._items.keys();
|
|
21
|
+
}
|
|
22
|
+
values() {
|
|
23
|
+
return this._items.values();
|
|
24
|
+
}
|
|
25
|
+
[Symbol.iterator]() {
|
|
26
|
+
return this._items[Symbol.iterator]();
|
|
27
|
+
}
|
|
28
|
+
get [Symbol.toStringTag]() {
|
|
29
|
+
return "NodeList";
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export {
|
|
33
|
+
NodeList
|
|
34
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const NodeType = {
|
|
2
|
+
ELEMENT_NODE: 1,
|
|
3
|
+
ATTRIBUTE_NODE: 2,
|
|
4
|
+
TEXT_NODE: 3,
|
|
5
|
+
CDATA_SECTION_NODE: 4,
|
|
6
|
+
PROCESSING_INSTRUCTION_NODE: 7,
|
|
7
|
+
COMMENT_NODE: 8,
|
|
8
|
+
DOCUMENT_NODE: 9,
|
|
9
|
+
DOCUMENT_TYPE_NODE: 10,
|
|
10
|
+
DOCUMENT_FRAGMENT_NODE: 11
|
|
11
|
+
};
|
|
12
|
+
export {
|
|
13
|
+
NodeType
|
|
14
|
+
};
|
package/lib/esm/node.js
ADDED
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
var _a, _b, _c, _d, _e;
|
|
2
|
+
import { EventTarget } from "@gjsify/dom-events";
|
|
3
|
+
import { NodeType } from "./node-type.js";
|
|
4
|
+
import { NodeList } from "./node-list.js";
|
|
5
|
+
import * as PS from "./property-symbol.js";
|
|
6
|
+
class Node extends EventTarget {
|
|
7
|
+
constructor() {
|
|
8
|
+
super(...arguments);
|
|
9
|
+
// Instance node type constants (mirror static for spec compliance)
|
|
10
|
+
this.ELEMENT_NODE = NodeType.ELEMENT_NODE;
|
|
11
|
+
this.ATTRIBUTE_NODE = NodeType.ATTRIBUTE_NODE;
|
|
12
|
+
this.TEXT_NODE = NodeType.TEXT_NODE;
|
|
13
|
+
this.CDATA_SECTION_NODE = NodeType.CDATA_SECTION_NODE;
|
|
14
|
+
this.PROCESSING_INSTRUCTION_NODE = NodeType.PROCESSING_INSTRUCTION_NODE;
|
|
15
|
+
this.COMMENT_NODE = NodeType.COMMENT_NODE;
|
|
16
|
+
this.DOCUMENT_NODE = NodeType.DOCUMENT_NODE;
|
|
17
|
+
this.DOCUMENT_TYPE_NODE = NodeType.DOCUMENT_TYPE_NODE;
|
|
18
|
+
this.DOCUMENT_FRAGMENT_NODE = NodeType.DOCUMENT_FRAGMENT_NODE;
|
|
19
|
+
// Internal state
|
|
20
|
+
this[_e] = NodeType.ELEMENT_NODE;
|
|
21
|
+
this[_d] = null;
|
|
22
|
+
this[_c] = [];
|
|
23
|
+
this[_b] = [];
|
|
24
|
+
this[_a] = false;
|
|
25
|
+
}
|
|
26
|
+
static {
|
|
27
|
+
// Static node type constants
|
|
28
|
+
this.ELEMENT_NODE = NodeType.ELEMENT_NODE;
|
|
29
|
+
}
|
|
30
|
+
static {
|
|
31
|
+
this.ATTRIBUTE_NODE = NodeType.ATTRIBUTE_NODE;
|
|
32
|
+
}
|
|
33
|
+
static {
|
|
34
|
+
this.TEXT_NODE = NodeType.TEXT_NODE;
|
|
35
|
+
}
|
|
36
|
+
static {
|
|
37
|
+
this.CDATA_SECTION_NODE = NodeType.CDATA_SECTION_NODE;
|
|
38
|
+
}
|
|
39
|
+
static {
|
|
40
|
+
this.PROCESSING_INSTRUCTION_NODE = NodeType.PROCESSING_INSTRUCTION_NODE;
|
|
41
|
+
}
|
|
42
|
+
static {
|
|
43
|
+
this.COMMENT_NODE = NodeType.COMMENT_NODE;
|
|
44
|
+
}
|
|
45
|
+
static {
|
|
46
|
+
this.DOCUMENT_NODE = NodeType.DOCUMENT_NODE;
|
|
47
|
+
}
|
|
48
|
+
static {
|
|
49
|
+
this.DOCUMENT_TYPE_NODE = NodeType.DOCUMENT_TYPE_NODE;
|
|
50
|
+
}
|
|
51
|
+
static {
|
|
52
|
+
this.DOCUMENT_FRAGMENT_NODE = NodeType.DOCUMENT_FRAGMENT_NODE;
|
|
53
|
+
}
|
|
54
|
+
static {
|
|
55
|
+
// DOCUMENT_POSITION constants
|
|
56
|
+
this.DOCUMENT_POSITION_DISCONNECTED = 1;
|
|
57
|
+
}
|
|
58
|
+
static {
|
|
59
|
+
this.DOCUMENT_POSITION_PRECEDING = 2;
|
|
60
|
+
}
|
|
61
|
+
static {
|
|
62
|
+
this.DOCUMENT_POSITION_FOLLOWING = 4;
|
|
63
|
+
}
|
|
64
|
+
static {
|
|
65
|
+
this.DOCUMENT_POSITION_CONTAINS = 8;
|
|
66
|
+
}
|
|
67
|
+
static {
|
|
68
|
+
this.DOCUMENT_POSITION_CONTAINED_BY = 16;
|
|
69
|
+
}
|
|
70
|
+
static {
|
|
71
|
+
this.DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC = 32;
|
|
72
|
+
}
|
|
73
|
+
get nodeType() {
|
|
74
|
+
return this[PS.nodeType];
|
|
75
|
+
}
|
|
76
|
+
get nodeName() {
|
|
77
|
+
return "";
|
|
78
|
+
}
|
|
79
|
+
get parentNode() {
|
|
80
|
+
return this[PS.parentNode];
|
|
81
|
+
}
|
|
82
|
+
get parentElement() {
|
|
83
|
+
const parent = this[PS.parentNode];
|
|
84
|
+
return parent && parent[PS.nodeType] === NodeType.ELEMENT_NODE ? parent : null;
|
|
85
|
+
}
|
|
86
|
+
get childNodes() {
|
|
87
|
+
return new NodeList(this[PS.childNodesList]);
|
|
88
|
+
}
|
|
89
|
+
get firstChild() {
|
|
90
|
+
return this[PS.childNodesList][0] ?? null;
|
|
91
|
+
}
|
|
92
|
+
get lastChild() {
|
|
93
|
+
const children = this[PS.childNodesList];
|
|
94
|
+
return children[children.length - 1] ?? null;
|
|
95
|
+
}
|
|
96
|
+
get previousSibling() {
|
|
97
|
+
const parent = this[PS.parentNode];
|
|
98
|
+
if (!parent) return null;
|
|
99
|
+
const siblings = parent[PS.childNodesList];
|
|
100
|
+
const idx = siblings.indexOf(this);
|
|
101
|
+
return idx > 0 ? siblings[idx - 1] : null;
|
|
102
|
+
}
|
|
103
|
+
get nextSibling() {
|
|
104
|
+
const parent = this[PS.parentNode];
|
|
105
|
+
if (!parent) return null;
|
|
106
|
+
const siblings = parent[PS.childNodesList];
|
|
107
|
+
const idx = siblings.indexOf(this);
|
|
108
|
+
return idx !== -1 && idx < siblings.length - 1 ? siblings[idx + 1] : null;
|
|
109
|
+
}
|
|
110
|
+
get textContent() {
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
set textContent(_value) {
|
|
114
|
+
}
|
|
115
|
+
get nodeValue() {
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
set nodeValue(_value) {
|
|
119
|
+
}
|
|
120
|
+
get ownerDocument() {
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
get isConnected() {
|
|
124
|
+
return this[PS.isConnected];
|
|
125
|
+
}
|
|
126
|
+
hasChildNodes() {
|
|
127
|
+
return this[PS.childNodesList].length > 0;
|
|
128
|
+
}
|
|
129
|
+
contains(other) {
|
|
130
|
+
if (other === null) return false;
|
|
131
|
+
if (other === this) return true;
|
|
132
|
+
let node = other;
|
|
133
|
+
while (node) {
|
|
134
|
+
if (node === this) return true;
|
|
135
|
+
node = node[PS.parentNode];
|
|
136
|
+
}
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
getRootNode() {
|
|
140
|
+
let node = this;
|
|
141
|
+
while (node[PS.parentNode]) {
|
|
142
|
+
node = node[PS.parentNode];
|
|
143
|
+
}
|
|
144
|
+
return node;
|
|
145
|
+
}
|
|
146
|
+
appendChild(node) {
|
|
147
|
+
if (node[PS.parentNode]) {
|
|
148
|
+
node[PS.parentNode].removeChild(node);
|
|
149
|
+
}
|
|
150
|
+
node[PS.parentNode] = this;
|
|
151
|
+
this[PS.childNodesList].push(node);
|
|
152
|
+
if (node[PS.nodeType] === NodeType.ELEMENT_NODE) {
|
|
153
|
+
this[PS.elementChildren].push(node);
|
|
154
|
+
}
|
|
155
|
+
return node;
|
|
156
|
+
}
|
|
157
|
+
removeChild(node) {
|
|
158
|
+
const children = this[PS.childNodesList];
|
|
159
|
+
const idx = children.indexOf(node);
|
|
160
|
+
if (idx === -1) {
|
|
161
|
+
throw new DOMException(
|
|
162
|
+
"Failed to execute 'removeChild' on 'Node': The node to be removed is not a child of this node.",
|
|
163
|
+
"NotFoundError"
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
children.splice(idx, 1);
|
|
167
|
+
node[PS.parentNode] = null;
|
|
168
|
+
if (node[PS.nodeType] === NodeType.ELEMENT_NODE) {
|
|
169
|
+
const elemIdx = this[PS.elementChildren].indexOf(node);
|
|
170
|
+
if (elemIdx !== -1) {
|
|
171
|
+
this[PS.elementChildren].splice(elemIdx, 1);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return node;
|
|
175
|
+
}
|
|
176
|
+
insertBefore(newNode, referenceNode) {
|
|
177
|
+
if (referenceNode === null) {
|
|
178
|
+
return this.appendChild(newNode);
|
|
179
|
+
}
|
|
180
|
+
const children = this[PS.childNodesList];
|
|
181
|
+
const refIdx = children.indexOf(referenceNode);
|
|
182
|
+
if (refIdx === -1) {
|
|
183
|
+
throw new DOMException(
|
|
184
|
+
"Failed to execute 'insertBefore' on 'Node': The node before which the new node is to be inserted is not a child of this node.",
|
|
185
|
+
"NotFoundError"
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
if (newNode[PS.parentNode]) {
|
|
189
|
+
newNode[PS.parentNode].removeChild(newNode);
|
|
190
|
+
}
|
|
191
|
+
newNode[PS.parentNode] = this;
|
|
192
|
+
children.splice(refIdx, 0, newNode);
|
|
193
|
+
if (newNode[PS.nodeType] === NodeType.ELEMENT_NODE) {
|
|
194
|
+
const elemChildren = this[PS.elementChildren];
|
|
195
|
+
let elemIdx = elemChildren.length;
|
|
196
|
+
for (let i = refIdx; i < children.length; i++) {
|
|
197
|
+
if (children[i][PS.nodeType] === NodeType.ELEMENT_NODE && children[i] !== newNode) {
|
|
198
|
+
elemIdx = elemChildren.indexOf(children[i]);
|
|
199
|
+
break;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
elemChildren.splice(elemIdx, 0, newNode);
|
|
203
|
+
}
|
|
204
|
+
return newNode;
|
|
205
|
+
}
|
|
206
|
+
replaceChild(newChild, oldChild) {
|
|
207
|
+
this.insertBefore(newChild, oldChild);
|
|
208
|
+
this.removeChild(oldChild);
|
|
209
|
+
return oldChild;
|
|
210
|
+
}
|
|
211
|
+
cloneNode(deep = false) {
|
|
212
|
+
const clone = new this.constructor();
|
|
213
|
+
clone[PS.nodeType] = this[PS.nodeType];
|
|
214
|
+
if (deep) {
|
|
215
|
+
for (const child of this[PS.childNodesList]) {
|
|
216
|
+
clone.appendChild(child.cloneNode(true));
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
return clone;
|
|
220
|
+
}
|
|
221
|
+
get [(_e = PS.nodeType, _d = PS.parentNode, _c = PS.childNodesList, _b = PS.elementChildren, _a = PS.isConnected, Symbol.toStringTag)]() {
|
|
222
|
+
return "Node";
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
export {
|
|
226
|
+
Node
|
|
227
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
const nodeType = /* @__PURE__ */ Symbol("nodeType");
|
|
2
|
+
const parentNode = /* @__PURE__ */ Symbol("parentNode");
|
|
3
|
+
const childNodesList = /* @__PURE__ */ Symbol("childNodesList");
|
|
4
|
+
const elementChildren = /* @__PURE__ */ Symbol("elementChildren");
|
|
5
|
+
const isConnected = /* @__PURE__ */ Symbol("isConnected");
|
|
6
|
+
const tagName = /* @__PURE__ */ Symbol("tagName");
|
|
7
|
+
const localName = /* @__PURE__ */ Symbol("localName");
|
|
8
|
+
const namespaceURI = /* @__PURE__ */ Symbol("namespaceURI");
|
|
9
|
+
const prefix = /* @__PURE__ */ Symbol("prefix");
|
|
10
|
+
const attributes = /* @__PURE__ */ Symbol("attributes");
|
|
11
|
+
const propertyEventListeners = /* @__PURE__ */ Symbol("propertyEventListeners");
|
|
12
|
+
const name = /* @__PURE__ */ Symbol("name");
|
|
13
|
+
const value = /* @__PURE__ */ Symbol("value");
|
|
14
|
+
const ownerElement = /* @__PURE__ */ Symbol("ownerElement");
|
|
15
|
+
export {
|
|
16
|
+
attributes,
|
|
17
|
+
childNodesList,
|
|
18
|
+
elementChildren,
|
|
19
|
+
isConnected,
|
|
20
|
+
localName,
|
|
21
|
+
name,
|
|
22
|
+
namespaceURI,
|
|
23
|
+
nodeType,
|
|
24
|
+
ownerElement,
|
|
25
|
+
parentNode,
|
|
26
|
+
prefix,
|
|
27
|
+
propertyEventListeners,
|
|
28
|
+
tagName,
|
|
29
|
+
value
|
|
30
|
+
};
|
package/lib/esm/text.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { CharacterData } from "./character-data.js";
|
|
2
|
+
import { NodeType } from "./node-type.js";
|
|
3
|
+
import * as PS from "./property-symbol.js";
|
|
4
|
+
class Text extends CharacterData {
|
|
5
|
+
constructor(data = "") {
|
|
6
|
+
super(data);
|
|
7
|
+
this[PS.nodeType] = NodeType.TEXT_NODE;
|
|
8
|
+
}
|
|
9
|
+
get nodeName() {
|
|
10
|
+
return "#text";
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Returns the combined text of this node and all adjacent Text siblings.
|
|
14
|
+
*/
|
|
15
|
+
get wholeText() {
|
|
16
|
+
let text = this.data;
|
|
17
|
+
let prev = this.previousSibling;
|
|
18
|
+
while (prev && prev instanceof Text) {
|
|
19
|
+
text = prev.data + text;
|
|
20
|
+
prev = prev.previousSibling;
|
|
21
|
+
}
|
|
22
|
+
let next = this.nextSibling;
|
|
23
|
+
while (next && next instanceof Text) {
|
|
24
|
+
text += next.data;
|
|
25
|
+
next = next.nextSibling;
|
|
26
|
+
}
|
|
27
|
+
return text;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Splits the text node at the given offset, returning the new Text node
|
|
31
|
+
* containing the text after the offset.
|
|
32
|
+
*/
|
|
33
|
+
splitText(offset) {
|
|
34
|
+
const newData = this.data.substring(offset);
|
|
35
|
+
this.data = this.data.substring(0, offset);
|
|
36
|
+
const newNode = new Text(newData);
|
|
37
|
+
if (this.parentNode) {
|
|
38
|
+
this.parentNode.insertBefore(newNode, this.nextSibling);
|
|
39
|
+
}
|
|
40
|
+
return newNode;
|
|
41
|
+
}
|
|
42
|
+
cloneNode(_deep = false) {
|
|
43
|
+
return new Text(this.data);
|
|
44
|
+
}
|
|
45
|
+
get [Symbol.toStringTag]() {
|
|
46
|
+
return "Text";
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
export {
|
|
50
|
+
Text
|
|
51
|
+
};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import * as PS from './property-symbol.js';
|
|
2
|
+
import type { Element } from './element.js';
|
|
3
|
+
/**
|
|
4
|
+
* Represents a DOM attribute.
|
|
5
|
+
*
|
|
6
|
+
* Reference: https://developer.mozilla.org/en-US/docs/Web/API/Attr
|
|
7
|
+
*/
|
|
8
|
+
export declare class Attr {
|
|
9
|
+
[PS.name]: string;
|
|
10
|
+
[PS.value]: string;
|
|
11
|
+
[PS.ownerElement]: Element | null;
|
|
12
|
+
readonly localName: string;
|
|
13
|
+
readonly namespaceURI: string | null;
|
|
14
|
+
readonly prefix: string | null;
|
|
15
|
+
readonly specified = true;
|
|
16
|
+
constructor(name: string, value: string, namespaceURI?: string | null, prefix?: string | null, ownerElement?: Element | null);
|
|
17
|
+
get name(): string;
|
|
18
|
+
get value(): string;
|
|
19
|
+
set value(value: string);
|
|
20
|
+
get ownerElement(): Element | null;
|
|
21
|
+
get [Symbol.toStringTag](): string;
|
|
22
|
+
}
|