happy-dom 2.27.3 → 2.30.1

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 (58) hide show
  1. package/lib/event/NonImplementedEventTypes.js +0 -1
  2. package/lib/event/NonImplementedEventTypes.js.map +1 -1
  3. package/lib/event/events/CustomEvent.d.ts +10 -0
  4. package/lib/event/events/CustomEvent.js +18 -0
  5. package/lib/event/events/CustomEvent.js.map +1 -1
  6. package/lib/event/events/IStorageEventInit.d.ts +8 -0
  7. package/lib/event/events/IStorageEventInit.js +3 -0
  8. package/lib/event/events/IStorageEventInit.js.map +1 -0
  9. package/lib/event/events/StorageEvent.d.ts +19 -0
  10. package/lib/event/events/StorageEvent.js +51 -0
  11. package/lib/event/events/StorageEvent.js.map +1 -0
  12. package/lib/nodes/character-data/CharacterData.d.ts +137 -0
  13. package/lib/nodes/character-data/CharacterData.js +265 -0
  14. package/lib/nodes/character-data/CharacterData.js.map +1 -0
  15. package/lib/nodes/character-data/ICharacterData.d.ts +3 -2
  16. package/lib/nodes/comment/Comment.d.ts +2 -121
  17. package/lib/nodes/comment/Comment.js +5 -221
  18. package/lib/nodes/comment/Comment.js.map +1 -1
  19. package/lib/nodes/comment/IComment.d.ts +1 -1
  20. package/lib/nodes/document/Document.d.ts +10 -5
  21. package/lib/nodes/document/Document.js +15 -2
  22. package/lib/nodes/document/Document.js.map +1 -1
  23. package/lib/nodes/element/HTMLCollection.d.ts +13 -0
  24. package/lib/nodes/element/HTMLCollection.js +37 -0
  25. package/lib/nodes/element/HTMLCollection.js.map +1 -0
  26. package/lib/nodes/node/INode.d.ts +3 -2
  27. package/lib/nodes/node/Node.d.ts +4 -0
  28. package/lib/nodes/node/Node.js +6 -0
  29. package/lib/nodes/node/Node.js.map +1 -1
  30. package/lib/nodes/node/NodeList.d.ts +13 -0
  31. package/lib/nodes/node/NodeList.js +37 -0
  32. package/lib/nodes/node/NodeList.js.map +1 -0
  33. package/lib/nodes/text/IText.d.ts +1 -1
  34. package/lib/nodes/text/Text.d.ts +2 -121
  35. package/lib/nodes/text/Text.js +5 -221
  36. package/lib/nodes/text/Text.js.map +1 -1
  37. package/lib/window/IWindow.d.ts +12 -0
  38. package/lib/window/Window.d.ts +8 -0
  39. package/lib/window/Window.js +8 -0
  40. package/lib/window/Window.js.map +1 -1
  41. package/package.json +2 -2
  42. package/src/event/NonImplementedEventTypes.ts +0 -1
  43. package/src/event/events/CustomEvent.ts +21 -0
  44. package/src/event/events/IStorageEventInit.ts +9 -0
  45. package/src/event/events/StorageEvent.ts +30 -0
  46. package/src/nodes/character-data/CharacterData.ts +221 -0
  47. package/src/nodes/character-data/ICharacterData.ts +3 -2
  48. package/src/nodes/comment/Comment.ts +3 -202
  49. package/src/nodes/comment/IComment.ts +1 -1
  50. package/src/nodes/document/Document.ts +22 -5
  51. package/src/nodes/element/HTMLCollection.ts +16 -0
  52. package/src/nodes/node/INode.ts +3 -2
  53. package/src/nodes/node/Node.ts +7 -0
  54. package/src/nodes/node/NodeList.ts +16 -0
  55. package/src/nodes/text/IText.ts +1 -1
  56. package/src/nodes/text/Text.ts +3 -202
  57. package/src/window/IWindow.ts +12 -0
  58. package/src/window/Window.ts +8 -0
@@ -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 ICharacterData from '../character-data/ICharacterData';
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): ICharacterData {
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): ICharacterData {
593
+ public createComment(data?: string): IComment {
593
594
  Comment.ownerDocument = this;
594
595
  return new Comment(data);
595
596
  }
@@ -619,10 +620,13 @@ export default class Document extends Node implements IDocument {
619
620
  * Creates an event.
620
621
  *
621
622
  * @deprecated
622
- * @param _type Type.
623
+ * @param type Type.
623
624
  * @returns Event.
624
625
  */
625
- public createEvent(_type: string): Event {
626
+ public createEvent(type: string): Event {
627
+ if (this.defaultView[type]) {
628
+ return new this.defaultView[type]('init');
629
+ }
626
630
  return new Event('init');
627
631
  }
628
632
 
@@ -685,4 +689,17 @@ export default class Document extends Node implements IDocument {
685
689
  (<Document>adopted.ownerDocument) = this;
686
690
  return adopted;
687
691
  }
692
+
693
+ /**
694
+ * @override
695
+ */
696
+ public dispatchEvent(event: Event): boolean {
697
+ const returnValue = super.dispatchEvent(event);
698
+
699
+ if (event.bubbles && !event._propagationStopped) {
700
+ return this.defaultView.dispatchEvent(event);
701
+ }
702
+
703
+ return returnValue;
704
+ }
688
705
  }
@@ -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
+ }
@@ -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;
@@ -67,6 +67,13 @@ export default class Node extends EventTarget implements INode {
67
67
  return null;
68
68
  }
69
69
 
70
+ /**
71
+ * Sets node value.
72
+ */
73
+ public set nodeValue(_nodeValue: string) {
74
+ // Do nothing
75
+ }
76
+
70
77
  /**
71
78
  * Node name.
72
79
  *
@@ -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
+ }
@@ -8,5 +8,5 @@ export default interface IText extends ICharacterData {
8
8
  * @param [deep=false] "true" to clone deep.
9
9
  * @returns Cloned node.
10
10
  */
11
- cloneNode(deep: boolean): IText;
11
+ cloneNode(deep?: boolean): IText;
12
12
  }
@@ -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';
@@ -47,6 +49,7 @@ import DataTransferItemList from '../event/DataTransferItemList';
47
49
  import InputEvent from '../event/events/InputEvent';
48
50
  import UIEvent from '../event/UIEvent';
49
51
  import ErrorEvent from '../event/events/ErrorEvent';
52
+ import StorageEvent from '../event/events/StorageEvent';
50
53
  import Screen from '../screen/Screen';
51
54
  import AsyncTaskManager from './AsyncTaskManager';
52
55
  import IResponse from './IResponse';
@@ -56,6 +59,9 @@ import HTMLStyleElement from '../nodes/html-style-element/HTMLStyleElement';
56
59
  import IFetchOptions from './IFetchOptions';
57
60
  import NodeFilter from '../tree-walker/NodeFilter';
58
61
  import Window from './Window';
62
+ import URLSearchParams from '../url-search-params/URLSearchParams';
63
+ import HTMLCollection from '../nodes/element/HTMLCollection';
64
+ import NodeList from '../nodes/node/NodeList';
59
65
 
60
66
  /**
61
67
  * Window.
@@ -86,6 +92,7 @@ export default interface IWindow {
86
92
  readonly ShadowRoot: typeof ShadowRoot;
87
93
  readonly Element: typeof Element;
88
94
  readonly DocumentFragment: typeof DocumentFragment;
95
+ readonly CharacterData: typeof CharacterData;
89
96
  readonly NodeFilter: typeof NodeFilter;
90
97
  readonly TreeWalker: typeof TreeWalker;
91
98
  readonly DOMParser: typeof DOMParser;
@@ -99,11 +106,13 @@ export default interface IWindow {
99
106
  readonly CustomEvent: typeof CustomEvent;
100
107
  readonly AnimationEvent: typeof AnimationEvent;
101
108
  readonly KeyboardEvent: typeof KeyboardEvent;
109
+ readonly PointerEvent: typeof PointerEvent;
102
110
  readonly MouseEvent: typeof MouseEvent;
103
111
  readonly FocusEvent: typeof FocusEvent;
104
112
  readonly WheelEvent: typeof WheelEvent;
105
113
  readonly InputEvent: typeof InputEvent;
106
114
  readonly ErrorEvent: typeof ErrorEvent;
115
+ readonly StorageEvent: typeof StorageEvent;
107
116
  readonly ProgressEvent: typeof ProgressEvent;
108
117
  readonly EventTarget: typeof EventTarget;
109
118
  readonly DataTransfer: typeof DataTransfer;
@@ -124,6 +133,9 @@ export default interface IWindow {
124
133
  readonly History: typeof History;
125
134
  readonly Screen: typeof Screen;
126
135
  readonly Storage: typeof Storage;
136
+ readonly URLSearchParams: typeof URLSearchParams;
137
+ readonly HTMLCollection: typeof HTMLCollection;
138
+ readonly NodeList: typeof NodeList;
127
139
 
128
140
  // Events
129
141
  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';
@@ -51,6 +52,7 @@ import DataTransferItemList from '../event/DataTransferItemList';
51
52
  import InputEvent from '../event/events/InputEvent';
52
53
  import UIEvent from '../event/UIEvent';
53
54
  import ErrorEvent from '../event/events/ErrorEvent';
55
+ import StorageEvent from '../event/events/StorageEvent';
54
56
  import Screen from '../screen/Screen';
55
57
  import AsyncTaskManager from './AsyncTaskManager';
56
58
  import IResponse from './IResponse';
@@ -62,6 +64,8 @@ import HTMLStyleElement from '../nodes/html-style-element/HTMLStyleElement';
62
64
  import IFetchOptions from './IFetchOptions';
63
65
  import IWindow from './IWindow';
64
66
  import URLSearchParams from '../url-search-params/URLSearchParams';
67
+ import HTMLCollection from '../nodes/element/HTMLCollection';
68
+ import NodeList from '../nodes/node/NodeList';
65
69
 
66
70
  const FETCH_RESPONSE_TYPE_METHODS = ['blob', 'json', 'text'];
67
71
 
@@ -98,6 +102,7 @@ export default class Window extends EventTarget implements IWindow, NodeJS.Globa
98
102
  public readonly ShadowRoot = ShadowRoot;
99
103
  public readonly Element = Element;
100
104
  public readonly DocumentFragment = DocumentFragment;
105
+ public readonly CharacterData = CharacterData;
101
106
  public readonly NodeFilter = NodeFilter;
102
107
  public readonly TreeWalker = TreeWalker;
103
108
  public readonly DOMParser = DOMParser;
@@ -117,6 +122,7 @@ export default class Window extends EventTarget implements IWindow, NodeJS.Globa
117
122
  public readonly WheelEvent = WheelEvent;
118
123
  public readonly InputEvent = InputEvent;
119
124
  public readonly ErrorEvent = ErrorEvent;
125
+ public readonly StorageEvent = StorageEvent;
120
126
  public readonly ProgressEvent = ProgressEvent;
121
127
  public readonly EventTarget = EventTarget;
122
128
  public readonly DataTransfer = DataTransfer;
@@ -138,6 +144,8 @@ export default class Window extends EventTarget implements IWindow, NodeJS.Globa
138
144
  public readonly Screen = Screen;
139
145
  public readonly Storage = Storage;
140
146
  public readonly URLSearchParams = URLSearchParams;
147
+ public readonly HTMLCollection = HTMLCollection;
148
+ public readonly NodeList = NodeList;
141
149
 
142
150
  // Events
143
151
  public onload: (event: Event) => void = null;