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.

Files changed (48) hide show
  1. package/lib/nodes/character-data/CharacterData.d.ts +137 -0
  2. package/lib/nodes/character-data/CharacterData.js +265 -0
  3. package/lib/nodes/character-data/CharacterData.js.map +1 -0
  4. package/lib/nodes/character-data/ICharacterData.d.ts +3 -2
  5. package/lib/nodes/comment/Comment.d.ts +2 -121
  6. package/lib/nodes/comment/Comment.js +5 -221
  7. package/lib/nodes/comment/Comment.js.map +1 -1
  8. package/lib/nodes/comment/IComment.d.ts +1 -1
  9. package/lib/nodes/document/Document.d.ts +4 -3
  10. package/lib/nodes/document/Document.js.map +1 -1
  11. package/lib/nodes/element/HTMLCollection.d.ts +13 -0
  12. package/lib/nodes/element/HTMLCollection.js +37 -0
  13. package/lib/nodes/element/HTMLCollection.js.map +1 -0
  14. package/lib/nodes/html-style-element/HTMLStyleElement.d.ts +1 -0
  15. package/lib/nodes/html-style-element/HTMLStyleElement.js +8 -4
  16. package/lib/nodes/html-style-element/HTMLStyleElement.js.map +1 -1
  17. package/lib/nodes/node/INode.d.ts +3 -2
  18. package/lib/nodes/node/Node.d.ts +4 -0
  19. package/lib/nodes/node/Node.js +6 -0
  20. package/lib/nodes/node/Node.js.map +1 -1
  21. package/lib/nodes/node/NodeList.d.ts +13 -0
  22. package/lib/nodes/node/NodeList.js +37 -0
  23. package/lib/nodes/node/NodeList.js.map +1 -0
  24. package/lib/nodes/text/IText.d.ts +1 -1
  25. package/lib/nodes/text/Text.d.ts +2 -121
  26. package/lib/nodes/text/Text.js +5 -221
  27. package/lib/nodes/text/Text.js.map +1 -1
  28. package/lib/window/IWindow.d.ts +10 -0
  29. package/lib/window/Window.d.ts +6 -0
  30. package/lib/window/Window.js +6 -0
  31. package/lib/window/Window.js.map +1 -1
  32. package/lib/xml-serializer/XMLSerializer.js +1 -1
  33. package/package.json +2 -2
  34. package/src/nodes/character-data/CharacterData.ts +221 -0
  35. package/src/nodes/character-data/ICharacterData.ts +3 -2
  36. package/src/nodes/comment/Comment.ts +3 -202
  37. package/src/nodes/comment/IComment.ts +1 -1
  38. package/src/nodes/document/Document.ts +4 -3
  39. package/src/nodes/element/HTMLCollection.ts +16 -0
  40. package/src/nodes/html-style-element/HTMLStyleElement.ts +7 -3
  41. package/src/nodes/node/INode.ts +3 -2
  42. package/src/nodes/node/Node.ts +7 -0
  43. package/src/nodes/node/NodeList.ts +16 -0
  44. package/src/nodes/text/IText.ts +1 -1
  45. package/src/nodes/text/Text.ts +3 -202
  46. package/src/window/IWindow.ts +10 -0
  47. package/src/window/Window.ts +6 -0
  48. package/src/xml-serializer/XMLSerializer.ts +2 -2
@@ -1,31 +1,12 @@
1
1
  import Node from '../node/Node';
2
- import MutationRecord from '../../mutation-observer/MutationRecord';
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 Node implements IText {
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
- const clone = <Text>super.cloneNode(deep);
235
- clone._data = this._data;
236
- return clone;
37
+ return <Text>super.cloneNode(deep);
237
38
  }
238
39
  }
@@ -18,6 +18,7 @@ import SVGElement from '../nodes/svg-element/SVGElement';
18
18
  import HTMLScriptElement from '../nodes/html-script-element/HTMLScriptElement';
19
19
  import HTMLImageElement from '../nodes/html-image-element/HTMLImageElement';
20
20
  import DocumentFragment from '../nodes/document-fragment/DocumentFragment';
21
+ import CharacterData from '../nodes/character-data/CharacterData';
21
22
  import TreeWalker from '../tree-walker/TreeWalker';
22
23
  import Event from '../event/Event';
23
24
  import CustomEvent from '../event/events/CustomEvent';
@@ -38,6 +39,7 @@ import DOMException from '../exception/DOMException';
38
39
  import FileReader from '../file/FileReader';
39
40
  import History from '../history/History';
40
41
  import CSSStyleDeclaration from '../css/CSSStyleDeclaration';
42
+ import PointerEvent from '../event/events/PointerEvent';
41
43
  import MouseEvent from '../event/events/MouseEvent';
42
44
  import FocusEvent from '../event/events/FocusEvent';
43
45
  import WheelEvent from '../event/events/WheelEvent';
@@ -56,6 +58,9 @@ import HTMLStyleElement from '../nodes/html-style-element/HTMLStyleElement';
56
58
  import IFetchOptions from './IFetchOptions';
57
59
  import NodeFilter from '../tree-walker/NodeFilter';
58
60
  import Window from './Window';
61
+ import URLSearchParams from '../url-search-params/URLSearchParams';
62
+ import HTMLCollection from '../nodes/element/HTMLCollection';
63
+ import NodeList from '../nodes/node/NodeList';
59
64
 
60
65
  /**
61
66
  * Window.
@@ -86,6 +91,7 @@ export default interface IWindow {
86
91
  readonly ShadowRoot: typeof ShadowRoot;
87
92
  readonly Element: typeof Element;
88
93
  readonly DocumentFragment: typeof DocumentFragment;
94
+ readonly CharacterData: typeof CharacterData;
89
95
  readonly NodeFilter: typeof NodeFilter;
90
96
  readonly TreeWalker: typeof TreeWalker;
91
97
  readonly DOMParser: typeof DOMParser;
@@ -99,6 +105,7 @@ export default interface IWindow {
99
105
  readonly CustomEvent: typeof CustomEvent;
100
106
  readonly AnimationEvent: typeof AnimationEvent;
101
107
  readonly KeyboardEvent: typeof KeyboardEvent;
108
+ readonly PointerEvent: typeof PointerEvent;
102
109
  readonly MouseEvent: typeof MouseEvent;
103
110
  readonly FocusEvent: typeof FocusEvent;
104
111
  readonly WheelEvent: typeof WheelEvent;
@@ -124,6 +131,9 @@ export default interface IWindow {
124
131
  readonly History: typeof History;
125
132
  readonly Screen: typeof Screen;
126
133
  readonly Storage: typeof Storage;
134
+ readonly URLSearchParams: typeof URLSearchParams;
135
+ readonly HTMLCollection: typeof HTMLCollection;
136
+ readonly NodeList: typeof NodeList;
127
137
 
128
138
  // Events
129
139
  onload: (event: Event) => void;
@@ -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';
@@ -62,6 +63,8 @@ import HTMLStyleElement from '../nodes/html-style-element/HTMLStyleElement';
62
63
  import IFetchOptions from './IFetchOptions';
63
64
  import IWindow from './IWindow';
64
65
  import URLSearchParams from '../url-search-params/URLSearchParams';
66
+ import HTMLCollection from '../nodes/element/HTMLCollection';
67
+ import NodeList from '../nodes/node/NodeList';
65
68
 
66
69
  const FETCH_RESPONSE_TYPE_METHODS = ['blob', 'json', 'text'];
67
70
 
@@ -98,6 +101,7 @@ export default class Window extends EventTarget implements IWindow, NodeJS.Globa
98
101
  public readonly ShadowRoot = ShadowRoot;
99
102
  public readonly Element = Element;
100
103
  public readonly DocumentFragment = DocumentFragment;
104
+ public readonly CharacterData = CharacterData;
101
105
  public readonly NodeFilter = NodeFilter;
102
106
  public readonly TreeWalker = TreeWalker;
103
107
  public readonly DOMParser = DOMParser;
@@ -138,6 +142,8 @@ export default class Window extends EventTarget implements IWindow, NodeJS.Globa
138
142
  public readonly Screen = Screen;
139
143
  public readonly Storage = Storage;
140
144
  public readonly URLSearchParams = URLSearchParams;
145
+ public readonly HTMLCollection = HTMLCollection;
146
+ public readonly NodeList = NodeList;
141
147
 
142
148
  // Events
143
149
  public onload: (event: Event) => void = null;
@@ -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 { encode } from 'he';
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 + '="' + encode(attribute.value) + '"';
73
+ attributeString += ' ' + attribute.name + '="' + escape(attribute.value) + '"';
74
74
  }
75
75
  }
76
76
  return attributeString;