happy-dom 2.26.0 → 2.28.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/ClassList.d.ts +8 -0
- package/lib/nodes/element/ClassList.js +22 -0
- package/lib/nodes/element/ClassList.js.map +1 -1
- 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 +1 -1
- 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/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/Window.d.ts +2 -0
- package/lib/window/Window.js +2 -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/ClassList.ts +24 -0
- package/src/nodes/html-style-element/HTMLStyleElement.ts +7 -3
- package/src/nodes/node/INode.ts +1 -1
- package/src/nodes/node/Node.ts +7 -0
- package/src/nodes/text/IText.ts +1 -1
- package/src/nodes/text/Text.ts +3 -202
- package/src/window/Window.ts +2 -0
- package/src/xml-serializer/XMLSerializer.ts +2 -2
package/src/nodes/text/Text.ts
CHANGED
@@ -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 NonDocumentChildNodeUtility from '../child-node/NonDocumentChildNodeUtility';
|
6
|
-
import ChildNodeUtility from '../child-node/ChildNodeUtility';
|
7
|
-
import IElement from '../element/IElement';
|
2
|
+
import CharacterData from '../character-data/CharacterData';
|
8
3
|
import IText from './IText';
|
9
4
|
|
10
5
|
/**
|
11
6
|
* Text node.
|
12
7
|
*/
|
13
|
-
export default class Text extends
|
8
|
+
export default class Text extends CharacterData implements IText {
|
14
9
|
public readonly nodeType = Node.TEXT_NODE;
|
15
|
-
private _data = '';
|
16
|
-
|
17
|
-
/**
|
18
|
-
* Constructor.
|
19
|
-
*
|
20
|
-
* @param [text] Text.
|
21
|
-
*/
|
22
|
-
constructor(text?: string) {
|
23
|
-
super();
|
24
|
-
|
25
|
-
if (text) {
|
26
|
-
this._data = text;
|
27
|
-
}
|
28
|
-
}
|
29
10
|
|
30
11
|
/**
|
31
12
|
* Node name.
|
@@ -36,82 +17,6 @@ export default class Text extends Node implements IText {
|
|
36
17
|
return '#text';
|
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
20
|
/**
|
116
21
|
* Converts to string.
|
117
22
|
*
|
@@ -121,108 +26,6 @@ export default class Text extends Node implements IText {
|
|
121
26
|
return '[object Text]';
|
122
27
|
}
|
123
28
|
|
124
|
-
/**
|
125
|
-
* Previous element sibling.
|
126
|
-
*
|
127
|
-
* @returns Element.
|
128
|
-
*/
|
129
|
-
public get previousElementSibling(): IElement {
|
130
|
-
return NonDocumentChildNodeUtility.previousElementSibling(this);
|
131
|
-
}
|
132
|
-
|
133
|
-
/**
|
134
|
-
* Next element sibling.
|
135
|
-
*
|
136
|
-
* @returns Element.
|
137
|
-
*/
|
138
|
-
public get nextElementSibling(): IElement {
|
139
|
-
return NonDocumentChildNodeUtility.nextElementSibling(this);
|
140
|
-
}
|
141
|
-
|
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 Text extends Node implements IText {
|
|
231
34
|
* @returns Cloned node.
|
232
35
|
*/
|
233
36
|
public cloneNode(deep = false): IText {
|
234
|
-
|
235
|
-
clone._data = this._data;
|
236
|
-
return clone;
|
37
|
+
return <Text>super.cloneNode(deep);
|
237
38
|
}
|
238
39
|
}
|
package/src/window/Window.ts
CHANGED
@@ -19,6 +19,7 @@ import SVGElement from '../nodes/svg-element/SVGElement';
|
|
19
19
|
import HTMLScriptElement from '../nodes/html-script-element/HTMLScriptElement';
|
20
20
|
import HTMLImageElement from '../nodes/html-image-element/HTMLImageElement';
|
21
21
|
import DocumentFragment from '../nodes/document-fragment/DocumentFragment';
|
22
|
+
import CharacterData from '../nodes/character-data/CharacterData';
|
22
23
|
import TreeWalker from '../tree-walker/TreeWalker';
|
23
24
|
import Event from '../event/Event';
|
24
25
|
import CustomEvent from '../event/events/CustomEvent';
|
@@ -98,6 +99,7 @@ export default class Window extends EventTarget implements IWindow, NodeJS.Globa
|
|
98
99
|
public readonly ShadowRoot = ShadowRoot;
|
99
100
|
public readonly Element = Element;
|
100
101
|
public readonly DocumentFragment = DocumentFragment;
|
102
|
+
public readonly CharacterData = CharacterData;
|
101
103
|
public readonly NodeFilter = NodeFilter;
|
102
104
|
public readonly TreeWalker = TreeWalker;
|
103
105
|
public readonly DOMParser = DOMParser;
|
@@ -3,7 +3,7 @@ import Node from '../nodes/node/Node';
|
|
3
3
|
import SelfClosingElements from '../config/SelfClosingElements';
|
4
4
|
import UnclosedElements from '../config/UnclosedElements';
|
5
5
|
import DocumentType from '../nodes/document-type/DocumentType';
|
6
|
-
import {
|
6
|
+
import { escape } from 'he';
|
7
7
|
import INode from '../nodes/node/INode';
|
8
8
|
import IElement from '../nodes/element/IElement';
|
9
9
|
|
@@ -70,7 +70,7 @@ export default class XMLSerializer {
|
|
70
70
|
let attributeString = '';
|
71
71
|
for (const attribute of Object.values((<Element>element)._attributes)) {
|
72
72
|
if (attribute.value !== null) {
|
73
|
-
attributeString += ' ' + attribute.name + '="' +
|
73
|
+
attributeString += ' ' + attribute.name + '="' + escape(attribute.value) + '"';
|
74
74
|
}
|
75
75
|
}
|
76
76
|
return attributeString;
|