happy-dom 2.27.0 → 2.29.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.
Potentially problematic release.
This version of happy-dom might be problematic. Click here for more details.
- package/lib/nodes/character-data/CharacterData.d.ts +137 -0
- package/lib/nodes/character-data/CharacterData.js +265 -0
- package/lib/nodes/character-data/CharacterData.js.map +1 -0
- package/lib/nodes/character-data/ICharacterData.d.ts +3 -2
- package/lib/nodes/comment/Comment.d.ts +2 -121
- package/lib/nodes/comment/Comment.js +5 -221
- package/lib/nodes/comment/Comment.js.map +1 -1
- package/lib/nodes/comment/IComment.d.ts +1 -1
- package/lib/nodes/document/Document.d.ts +4 -3
- package/lib/nodes/document/Document.js.map +1 -1
- package/lib/nodes/element/HTMLCollection.d.ts +13 -0
- package/lib/nodes/element/HTMLCollection.js +37 -0
- package/lib/nodes/element/HTMLCollection.js.map +1 -0
- package/lib/nodes/html-style-element/HTMLStyleElement.d.ts +1 -0
- package/lib/nodes/html-style-element/HTMLStyleElement.js +8 -4
- package/lib/nodes/html-style-element/HTMLStyleElement.js.map +1 -1
- package/lib/nodes/node/INode.d.ts +3 -2
- package/lib/nodes/node/Node.d.ts +4 -0
- package/lib/nodes/node/Node.js +6 -0
- package/lib/nodes/node/Node.js.map +1 -1
- package/lib/nodes/node/NodeList.d.ts +13 -0
- package/lib/nodes/node/NodeList.js +37 -0
- package/lib/nodes/node/NodeList.js.map +1 -0
- package/lib/nodes/text/IText.d.ts +1 -1
- package/lib/nodes/text/Text.d.ts +2 -121
- package/lib/nodes/text/Text.js +5 -221
- package/lib/nodes/text/Text.js.map +1 -1
- package/lib/window/IWindow.d.ts +10 -0
- package/lib/window/Window.d.ts +6 -0
- package/lib/window/Window.js +6 -0
- package/lib/window/Window.js.map +1 -1
- package/lib/xml-serializer/XMLSerializer.js +1 -1
- package/package.json +2 -2
- package/src/nodes/character-data/CharacterData.ts +221 -0
- package/src/nodes/character-data/ICharacterData.ts +3 -2
- package/src/nodes/comment/Comment.ts +3 -202
- package/src/nodes/comment/IComment.ts +1 -1
- package/src/nodes/document/Document.ts +4 -3
- package/src/nodes/element/HTMLCollection.ts +16 -0
- package/src/nodes/html-style-element/HTMLStyleElement.ts +7 -3
- package/src/nodes/node/INode.ts +3 -2
- package/src/nodes/node/Node.ts +7 -0
- package/src/nodes/node/NodeList.ts +16 -0
- package/src/nodes/text/IText.ts +1 -1
- package/src/nodes/text/Text.ts +3 -202
- package/src/window/IWindow.ts +10 -0
- package/src/window/Window.ts +6 -0
- package/src/xml-serializer/XMLSerializer.ts +2 -2
@@ -0,0 +1,221 @@
|
|
1
|
+
import Node from '../node/Node';
|
2
|
+
import CharacterDataUtility from './CharacterDataUtility';
|
3
|
+
import ICharacterData from './ICharacterData';
|
4
|
+
import IElement from '../element/IElement';
|
5
|
+
import NonDocumentChildNodeUtility from '../child-node/NonDocumentChildNodeUtility';
|
6
|
+
import ChildNodeUtility from '../child-node/ChildNodeUtility';
|
7
|
+
import MutationRecord from '../../mutation-observer/MutationRecord';
|
8
|
+
import MutationTypeEnum from '../../mutation-observer/MutationTypeEnum';
|
9
|
+
|
10
|
+
/**
|
11
|
+
* Character data base class.
|
12
|
+
*
|
13
|
+
* Reference:
|
14
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/CharacterData.
|
15
|
+
*/
|
16
|
+
export default abstract class CharacterData extends Node implements ICharacterData {
|
17
|
+
protected _data = '';
|
18
|
+
|
19
|
+
/**
|
20
|
+
* Constructor.
|
21
|
+
*
|
22
|
+
* @param [data] Data.
|
23
|
+
*/
|
24
|
+
constructor(data?: string) {
|
25
|
+
super();
|
26
|
+
|
27
|
+
if (data) {
|
28
|
+
this._data = data;
|
29
|
+
}
|
30
|
+
}
|
31
|
+
|
32
|
+
/**
|
33
|
+
* Returns text content.
|
34
|
+
*
|
35
|
+
* @returns Text content.
|
36
|
+
*/
|
37
|
+
public get length(): number {
|
38
|
+
return this._data.length;
|
39
|
+
}
|
40
|
+
|
41
|
+
/**
|
42
|
+
* Returns text content.
|
43
|
+
*
|
44
|
+
* @returns Text content.
|
45
|
+
*/
|
46
|
+
public get data(): string {
|
47
|
+
return this._data;
|
48
|
+
}
|
49
|
+
|
50
|
+
/**
|
51
|
+
* Sets text content.
|
52
|
+
*
|
53
|
+
* @param textContent Text content.
|
54
|
+
*/
|
55
|
+
public set data(data: string) {
|
56
|
+
const oldValue = this._data;
|
57
|
+
this._data = data;
|
58
|
+
|
59
|
+
// MutationObserver
|
60
|
+
if (this._observers.length > 0) {
|
61
|
+
for (const observer of this._observers) {
|
62
|
+
if (observer.options.characterData) {
|
63
|
+
const record = new MutationRecord();
|
64
|
+
record.type = MutationTypeEnum.characterData;
|
65
|
+
record.oldValue = observer.options.characterDataOldValue ? oldValue : null;
|
66
|
+
observer.callback([record]);
|
67
|
+
}
|
68
|
+
}
|
69
|
+
}
|
70
|
+
}
|
71
|
+
|
72
|
+
/**
|
73
|
+
* Returns text content.
|
74
|
+
*
|
75
|
+
* @returns Text content.
|
76
|
+
*/
|
77
|
+
public get textContent(): string {
|
78
|
+
return this._data;
|
79
|
+
}
|
80
|
+
|
81
|
+
/**
|
82
|
+
* Sets text content.
|
83
|
+
*
|
84
|
+
* @param textContent Text content.
|
85
|
+
*/
|
86
|
+
public set textContent(textContent: string) {
|
87
|
+
this.data = textContent;
|
88
|
+
}
|
89
|
+
|
90
|
+
/**
|
91
|
+
* Returns node value.
|
92
|
+
*
|
93
|
+
* @returns Node value.
|
94
|
+
*/
|
95
|
+
public get nodeValue(): string {
|
96
|
+
return this._data;
|
97
|
+
}
|
98
|
+
|
99
|
+
/**
|
100
|
+
* Sets node value.
|
101
|
+
*
|
102
|
+
* @param nodeValue Node value.
|
103
|
+
*/
|
104
|
+
public set nodeValue(nodeValue: string) {
|
105
|
+
this.textContent = nodeValue;
|
106
|
+
}
|
107
|
+
|
108
|
+
/**
|
109
|
+
* Appends the given DOMString to the CharacterData.data string; when this method returns, data contains the concatenated DOMString.
|
110
|
+
*
|
111
|
+
* @param data Data.
|
112
|
+
*/
|
113
|
+
public appendData(data: string): void {
|
114
|
+
CharacterDataUtility.appendData(this, data);
|
115
|
+
}
|
116
|
+
|
117
|
+
/**
|
118
|
+
* Removes the specified amount of characters, starting at the specified offset, from the CharacterData.data string; when this method returns, data contains the shortened DOMString.
|
119
|
+
*
|
120
|
+
* @param offset Offset.
|
121
|
+
* @param count Count.
|
122
|
+
*/
|
123
|
+
public deleteData(offset: number, count: number): void {
|
124
|
+
CharacterDataUtility.deleteData(this, offset, count);
|
125
|
+
}
|
126
|
+
|
127
|
+
/**
|
128
|
+
* Inserts the specified characters, at the specified offset, in the CharacterData.data string; when this method returns, data contains the modified DOMString.
|
129
|
+
*
|
130
|
+
* @param offset Offset.
|
131
|
+
* @param data Data.
|
132
|
+
*/
|
133
|
+
public insertData(offset: number, data: string): void {
|
134
|
+
CharacterDataUtility.insertData(this, offset, data);
|
135
|
+
}
|
136
|
+
|
137
|
+
/**
|
138
|
+
* Replaces the specified amount of characters, starting at the specified offset, with the specified DOMString; when this method returns, data contains the modified DOMString.
|
139
|
+
*
|
140
|
+
* @param offset Offset.
|
141
|
+
* @param count Count.
|
142
|
+
* @param data Data.
|
143
|
+
*/
|
144
|
+
public replaceData(offset: number, count: number, data: string): void {
|
145
|
+
CharacterDataUtility.replaceData(this, offset, count, data);
|
146
|
+
}
|
147
|
+
|
148
|
+
/**
|
149
|
+
* Returns a DOMString containing the part of CharacterData.data of the specified length and starting at the specified offset.
|
150
|
+
*
|
151
|
+
* @param offset Offset.
|
152
|
+
* @param count Count.
|
153
|
+
*/
|
154
|
+
public substringData(offset: number, count: number): string {
|
155
|
+
return CharacterDataUtility.substringData(this, offset, count);
|
156
|
+
}
|
157
|
+
/**
|
158
|
+
* Previous element sibling.
|
159
|
+
*
|
160
|
+
* @returns Element.
|
161
|
+
*/
|
162
|
+
public get previousElementSibling(): IElement {
|
163
|
+
return NonDocumentChildNodeUtility.previousElementSibling(this);
|
164
|
+
}
|
165
|
+
|
166
|
+
/**
|
167
|
+
* Next element sibling.
|
168
|
+
*
|
169
|
+
* @returns Element.
|
170
|
+
*/
|
171
|
+
public get nextElementSibling(): IElement {
|
172
|
+
return NonDocumentChildNodeUtility.nextElementSibling(this);
|
173
|
+
}
|
174
|
+
|
175
|
+
/**
|
176
|
+
* Removes the object from its parent children list.
|
177
|
+
*/
|
178
|
+
public remove(): void {
|
179
|
+
ChildNodeUtility.remove(this);
|
180
|
+
}
|
181
|
+
|
182
|
+
/**
|
183
|
+
* The Node.replaceWith() method replaces this Node in the children list of its parent with a set of Node or DOMString objects.
|
184
|
+
*
|
185
|
+
* @param nodes List of Node or DOMString.
|
186
|
+
*/
|
187
|
+
public replaceWith(...nodes: (Node | string)[]): void {
|
188
|
+
ChildNodeUtility.replaceWith(this, ...nodes);
|
189
|
+
}
|
190
|
+
|
191
|
+
/**
|
192
|
+
* Inserts a set of Node or DOMString objects in the children list of this ChildNode's parent, just before this ChildNode. DOMString objects are inserted as equivalent Text nodes.
|
193
|
+
*
|
194
|
+
* @param nodes List of Node or DOMString.
|
195
|
+
*/
|
196
|
+
public before(...nodes: (string | Node)[]): void {
|
197
|
+
ChildNodeUtility.before(this, ...nodes);
|
198
|
+
}
|
199
|
+
|
200
|
+
/**
|
201
|
+
* Inserts a set of Node or DOMString objects in the children list of this ChildNode's parent, just after this ChildNode. DOMString objects are inserted as equivalent Text nodes.
|
202
|
+
*
|
203
|
+
* @param nodes List of Node or DOMString.
|
204
|
+
*/
|
205
|
+
public after(...nodes: (string | Node)[]): void {
|
206
|
+
ChildNodeUtility.after(this, ...nodes);
|
207
|
+
}
|
208
|
+
|
209
|
+
/**
|
210
|
+
* Clones a node.
|
211
|
+
*
|
212
|
+
* @override
|
213
|
+
* @param [deep=false] "true" to clone deep.
|
214
|
+
* @returns Cloned node.
|
215
|
+
*/
|
216
|
+
public cloneNode(deep = false): ICharacterData {
|
217
|
+
const clone = <CharacterData>super.cloneNode(deep);
|
218
|
+
clone._data = this._data;
|
219
|
+
return clone;
|
220
|
+
}
|
221
|
+
}
|
@@ -1,7 +1,8 @@
|
|
1
|
+
import INode from '../node/INode';
|
1
2
|
import IChildNode from '../child-node/IChildNode';
|
2
3
|
import INonDocumentTypeChildNode from '../child-node/INonDocumentTypeChildNode';
|
3
4
|
|
4
|
-
export default interface ICharacterData extends IChildNode, INonDocumentTypeChildNode {
|
5
|
+
export default interface ICharacterData extends INode, IChildNode, INonDocumentTypeChildNode {
|
5
6
|
data: string;
|
6
7
|
readonly length: number;
|
7
8
|
|
@@ -52,5 +53,5 @@ export default interface ICharacterData extends IChildNode, INonDocumentTypeChil
|
|
52
53
|
* @param [deep=false] "true" to clone deep.
|
53
54
|
* @returns Cloned node.
|
54
55
|
*/
|
55
|
-
cloneNode(deep
|
56
|
+
cloneNode(deep?: boolean): ICharacterData;
|
56
57
|
}
|
@@ -1,31 +1,12 @@
|
|
1
1
|
import Node from '../node/Node';
|
2
|
-
import
|
3
|
-
import MutationTypeEnum from '../../mutation-observer/MutationTypeEnum';
|
4
|
-
import CharacterDataUtility from '../character-data/CharacterDataUtility';
|
5
|
-
import IElement from '../element/IElement';
|
6
|
-
import NonDocumentChildNodeUtility from '../child-node/NonDocumentChildNodeUtility';
|
7
|
-
import ChildNodeUtility from '../child-node/ChildNodeUtility';
|
2
|
+
import CharacterData from '../character-data/CharacterData';
|
8
3
|
import IComment from './IComment';
|
9
4
|
|
10
5
|
/**
|
11
6
|
* Comment node.
|
12
7
|
*/
|
13
|
-
export default class Comment extends
|
8
|
+
export default class Comment extends CharacterData implements IComment {
|
14
9
|
public readonly nodeType = Node.COMMENT_NODE;
|
15
|
-
private _data = '';
|
16
|
-
|
17
|
-
/**
|
18
|
-
* Constructor.
|
19
|
-
*
|
20
|
-
* @param [comment] Comment.
|
21
|
-
*/
|
22
|
-
constructor(comment?: string) {
|
23
|
-
super();
|
24
|
-
|
25
|
-
if (comment) {
|
26
|
-
this._data = comment;
|
27
|
-
}
|
28
|
-
}
|
29
10
|
|
30
11
|
/**
|
31
12
|
* Node name.
|
@@ -36,100 +17,6 @@ export default class Comment extends Node implements IComment {
|
|
36
17
|
return '#comment';
|
37
18
|
}
|
38
19
|
|
39
|
-
/**
|
40
|
-
* Returns text content.
|
41
|
-
*
|
42
|
-
* @returns Text content.
|
43
|
-
*/
|
44
|
-
public get length(): number {
|
45
|
-
return this._data.length;
|
46
|
-
}
|
47
|
-
|
48
|
-
/**
|
49
|
-
* Returns text content.
|
50
|
-
*
|
51
|
-
* @returns Text content.
|
52
|
-
*/
|
53
|
-
public get data(): string {
|
54
|
-
return this._data;
|
55
|
-
}
|
56
|
-
|
57
|
-
/**
|
58
|
-
* Sets text content.
|
59
|
-
*
|
60
|
-
* @param textContent Text content.
|
61
|
-
*/
|
62
|
-
public set data(data: string) {
|
63
|
-
const oldValue = this._data;
|
64
|
-
this._data = data;
|
65
|
-
|
66
|
-
// MutationObserver
|
67
|
-
if (this._observers.length > 0) {
|
68
|
-
for (const observer of this._observers) {
|
69
|
-
if (observer.options.characterData) {
|
70
|
-
const record = new MutationRecord();
|
71
|
-
record.type = MutationTypeEnum.characterData;
|
72
|
-
record.oldValue = observer.options.characterDataOldValue ? oldValue : null;
|
73
|
-
observer.callback([record]);
|
74
|
-
}
|
75
|
-
}
|
76
|
-
}
|
77
|
-
}
|
78
|
-
|
79
|
-
/**
|
80
|
-
* Returns text content.
|
81
|
-
*
|
82
|
-
* @returns Text content.
|
83
|
-
*/
|
84
|
-
public get textContent(): string {
|
85
|
-
return this._data;
|
86
|
-
}
|
87
|
-
|
88
|
-
/**
|
89
|
-
* Sets text content.
|
90
|
-
*
|
91
|
-
* @param textContent Text content.
|
92
|
-
*/
|
93
|
-
public set textContent(textContent: string) {
|
94
|
-
this.data = textContent;
|
95
|
-
}
|
96
|
-
|
97
|
-
/**
|
98
|
-
* Returns node value.
|
99
|
-
*
|
100
|
-
* @returns Node value.
|
101
|
-
*/
|
102
|
-
public get nodeValue(): string {
|
103
|
-
return this._data;
|
104
|
-
}
|
105
|
-
|
106
|
-
/**
|
107
|
-
* Sets node value.
|
108
|
-
*
|
109
|
-
* @param nodeValue Node value.
|
110
|
-
*/
|
111
|
-
public set nodeValue(nodeValue: string) {
|
112
|
-
this.textContent = nodeValue;
|
113
|
-
}
|
114
|
-
|
115
|
-
/**
|
116
|
-
* Previous element sibling.
|
117
|
-
*
|
118
|
-
* @returns Element.
|
119
|
-
*/
|
120
|
-
public get previousElementSibling(): IElement {
|
121
|
-
return NonDocumentChildNodeUtility.previousElementSibling(this);
|
122
|
-
}
|
123
|
-
|
124
|
-
/**
|
125
|
-
* Next element sibling.
|
126
|
-
*
|
127
|
-
* @returns Element.
|
128
|
-
*/
|
129
|
-
public get nextElementSibling(): IElement {
|
130
|
-
return NonDocumentChildNodeUtility.nextElementSibling(this);
|
131
|
-
}
|
132
|
-
|
133
20
|
/**
|
134
21
|
* Converts to string.
|
135
22
|
*
|
@@ -139,90 +26,6 @@ export default class Comment extends Node implements IComment {
|
|
139
26
|
return '[object Comment]';
|
140
27
|
}
|
141
28
|
|
142
|
-
/**
|
143
|
-
* Appends the given DOMString to the CharacterData.data string; when this method returns, data contains the concatenated DOMString.
|
144
|
-
*
|
145
|
-
* @param data Data.
|
146
|
-
*/
|
147
|
-
public appendData(data: string): void {
|
148
|
-
CharacterDataUtility.appendData(this, data);
|
149
|
-
}
|
150
|
-
|
151
|
-
/**
|
152
|
-
* Removes the specified amount of characters, starting at the specified offset, from the CharacterData.data string; when this method returns, data contains the shortened DOMString.
|
153
|
-
*
|
154
|
-
* @param offset Offset.
|
155
|
-
* @param count Count.
|
156
|
-
*/
|
157
|
-
public deleteData(offset: number, count: number): void {
|
158
|
-
CharacterDataUtility.deleteData(this, offset, count);
|
159
|
-
}
|
160
|
-
|
161
|
-
/**
|
162
|
-
* Inserts the specified characters, at the specified offset, in the CharacterData.data string; when this method returns, data contains the modified DOMString.
|
163
|
-
*
|
164
|
-
* @param offset Offset.
|
165
|
-
* @param data Data.
|
166
|
-
*/
|
167
|
-
public insertData(offset: number, data: string): void {
|
168
|
-
CharacterDataUtility.insertData(this, offset, data);
|
169
|
-
}
|
170
|
-
|
171
|
-
/**
|
172
|
-
* Removes the object from its parent children list.
|
173
|
-
*/
|
174
|
-
public remove(): void {
|
175
|
-
ChildNodeUtility.remove(this);
|
176
|
-
}
|
177
|
-
|
178
|
-
/**
|
179
|
-
* The Node.replaceWith() method replaces this Node in the children list of its parent with a set of Node or DOMString objects.
|
180
|
-
*
|
181
|
-
* @param nodes List of Node or DOMString.
|
182
|
-
*/
|
183
|
-
public replaceWith(...nodes: (Node | string)[]): void {
|
184
|
-
ChildNodeUtility.replaceWith(this, ...nodes);
|
185
|
-
}
|
186
|
-
|
187
|
-
/**
|
188
|
-
* Inserts a set of Node or DOMString objects in the children list of this ChildNode's parent, just before this ChildNode. DOMString objects are inserted as equivalent Text nodes.
|
189
|
-
*
|
190
|
-
* @param nodes List of Node or DOMString.
|
191
|
-
*/
|
192
|
-
public before(...nodes: (string | Node)[]): void {
|
193
|
-
ChildNodeUtility.before(this, ...nodes);
|
194
|
-
}
|
195
|
-
|
196
|
-
/**
|
197
|
-
* Inserts a set of Node or DOMString objects in the children list of this ChildNode's parent, just after this ChildNode. DOMString objects are inserted as equivalent Text nodes.
|
198
|
-
*
|
199
|
-
* @param nodes List of Node or DOMString.
|
200
|
-
*/
|
201
|
-
public after(...nodes: (string | Node)[]): void {
|
202
|
-
ChildNodeUtility.after(this, ...nodes);
|
203
|
-
}
|
204
|
-
|
205
|
-
/**
|
206
|
-
* Replaces the specified amount of characters, starting at the specified offset, with the specified DOMString; when this method returns, data contains the modified DOMString.
|
207
|
-
*
|
208
|
-
* @param offset Offset.
|
209
|
-
* @param count Count.
|
210
|
-
* @param data Data.
|
211
|
-
*/
|
212
|
-
public replaceData(offset: number, count: number, data: string): void {
|
213
|
-
CharacterDataUtility.replaceData(this, offset, count, data);
|
214
|
-
}
|
215
|
-
|
216
|
-
/**
|
217
|
-
* Returns a DOMString containing the part of CharacterData.data of the specified length and starting at the specified offset.
|
218
|
-
*
|
219
|
-
* @param offset Offset.
|
220
|
-
* @param count Count.
|
221
|
-
*/
|
222
|
-
public substringData(offset: number, count: number): string {
|
223
|
-
return CharacterDataUtility.substringData(this, offset, count);
|
224
|
-
}
|
225
|
-
|
226
29
|
/**
|
227
30
|
* Clones a node.
|
228
31
|
*
|
@@ -231,8 +34,6 @@ export default class Comment extends Node implements IComment {
|
|
231
34
|
* @returns Cloned node.
|
232
35
|
*/
|
233
36
|
public cloneNode(deep = false): IComment {
|
234
|
-
|
235
|
-
clone._data = this._data;
|
236
|
-
return clone;
|
37
|
+
return <Comment>super.cloneNode(deep);
|
237
38
|
}
|
238
39
|
}
|
@@ -24,7 +24,8 @@ import IElement from '../element/IElement';
|
|
24
24
|
import IHTMLElement from '../html-element/IHTMLElement';
|
25
25
|
import IDocumentType from '../document-type/IDocumentType';
|
26
26
|
import INode from '../node/INode';
|
27
|
-
import
|
27
|
+
import IComment from '../comment/IComment';
|
28
|
+
import IText from '../text/IText';
|
28
29
|
import IDocumentFragment from '../document-fragment/IDocumentFragment';
|
29
30
|
import INodeList from '../node/INodeList';
|
30
31
|
import IHTMLCollection from '../element/IHTMLCollection';
|
@@ -578,7 +579,7 @@ export default class Document extends Node implements IDocument {
|
|
578
579
|
* @param [data] Text data.
|
579
580
|
* @returns Text node.
|
580
581
|
*/
|
581
|
-
public createTextNode(data?: string):
|
582
|
+
public createTextNode(data?: string): IText {
|
582
583
|
Text.ownerDocument = this;
|
583
584
|
return new Text(data);
|
584
585
|
}
|
@@ -589,7 +590,7 @@ export default class Document extends Node implements IDocument {
|
|
589
590
|
* @param [data] Text data.
|
590
591
|
* @returns Text node.
|
591
592
|
*/
|
592
|
-
public createComment(data?: string):
|
593
|
+
public createComment(data?: string): IComment {
|
593
594
|
Comment.ownerDocument = this;
|
594
595
|
return new Comment(data);
|
595
596
|
}
|
@@ -0,0 +1,16 @@
|
|
1
|
+
import IHTMLCollection from './IHTMLCollection';
|
2
|
+
import INode from '../node/INode';
|
3
|
+
|
4
|
+
/**
|
5
|
+
* Class list.
|
6
|
+
*/
|
7
|
+
export default class HTMLCollection extends Array implements IHTMLCollection<INode> {
|
8
|
+
/**
|
9
|
+
* Returns item by index.
|
10
|
+
*
|
11
|
+
* @param index Index.
|
12
|
+
*/
|
13
|
+
public item(index: number): INode {
|
14
|
+
return index >= 0 && this[index] ? this[index] : null;
|
15
|
+
}
|
16
|
+
}
|
@@ -9,6 +9,8 @@ import IHTMLStyleElement from './IHTMLStyleElement';
|
|
9
9
|
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLStyleElement.
|
10
10
|
*/
|
11
11
|
export default class HTMLStyleElement extends HTMLElement implements IHTMLStyleElement {
|
12
|
+
private _styleSheet: CSSStyleSheet | null = null;
|
13
|
+
|
12
14
|
/**
|
13
15
|
* Returns CSS style sheet.
|
14
16
|
*
|
@@ -18,9 +20,11 @@ export default class HTMLStyleElement extends HTMLElement implements IHTMLStyleE
|
|
18
20
|
if (!this.isConnected) {
|
19
21
|
return null;
|
20
22
|
}
|
21
|
-
|
22
|
-
|
23
|
-
|
23
|
+
if (!this._styleSheet) {
|
24
|
+
this._styleSheet = new CSSStyleSheet();
|
25
|
+
this._styleSheet.replaceSync(this.innerText);
|
26
|
+
}
|
27
|
+
return this._styleSheet;
|
24
28
|
}
|
25
29
|
|
26
30
|
/**
|
package/src/nodes/node/INode.ts
CHANGED
@@ -1,20 +1,21 @@
|
|
1
1
|
import IEventTarget from '../../event/IEventTarget';
|
2
2
|
import IDocument from '../document/IDocument';
|
3
3
|
import IElement from '../element/IElement';
|
4
|
+
import INodeList from './INodeList';
|
4
5
|
|
5
6
|
export default interface INode extends IEventTarget {
|
6
7
|
readonly ownerDocument: IDocument;
|
7
8
|
readonly parentNode: INode;
|
8
9
|
readonly parentElement: IElement;
|
9
10
|
readonly nodeType: number;
|
10
|
-
readonly childNodes: INode
|
11
|
+
readonly childNodes: INodeList<INode>;
|
11
12
|
readonly isConnected: boolean;
|
12
|
-
readonly nodeValue: string;
|
13
13
|
readonly nodeName: string;
|
14
14
|
readonly previousSibling: INode;
|
15
15
|
readonly nextSibling: INode;
|
16
16
|
readonly firstChild: INode;
|
17
17
|
readonly lastChild: INode;
|
18
|
+
nodeValue: string;
|
18
19
|
textContent: string;
|
19
20
|
connectedCallback?(): void;
|
20
21
|
disconnectedCallback?(): void;
|
package/src/nodes/node/Node.ts
CHANGED
@@ -0,0 +1,16 @@
|
|
1
|
+
import INodeList from './INodeList';
|
2
|
+
import INode from './INode';
|
3
|
+
|
4
|
+
/**
|
5
|
+
* Class list.
|
6
|
+
*/
|
7
|
+
export default class NodeList extends Array implements INodeList<INode> {
|
8
|
+
/**
|
9
|
+
* Returns item by index.
|
10
|
+
*
|
11
|
+
* @param index Index.
|
12
|
+
*/
|
13
|
+
public item(index: number): INode {
|
14
|
+
return index >= 0 && this[index] ? this[index] : null;
|
15
|
+
}
|
16
|
+
}
|
package/src/nodes/text/IText.ts
CHANGED