happy-dom 2.30.0 → 2.32.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 (51) hide show
  1. package/README.md +1 -1
  2. package/lib/config/ElementTag.d.ts +2 -0
  3. package/lib/config/ElementTag.js +2 -0
  4. package/lib/config/ElementTag.js.map +1 -1
  5. package/lib/event/EventTarget.js +5 -1
  6. package/lib/event/EventTarget.js.map +1 -1
  7. package/lib/event/NonImplementedEventTypes.js +0 -1
  8. package/lib/event/NonImplementedEventTypes.js.map +1 -1
  9. package/lib/event/events/IStorageEventInit.d.ts +8 -0
  10. package/lib/event/events/IStorageEventInit.js +3 -0
  11. package/lib/event/events/IStorageEventInit.js.map +1 -0
  12. package/lib/event/events/StorageEvent.d.ts +19 -0
  13. package/lib/event/events/StorageEvent.js +51 -0
  14. package/lib/event/events/StorageEvent.js.map +1 -0
  15. package/lib/match-media/MediaQueryList.d.ts +39 -0
  16. package/lib/match-media/MediaQueryList.js +82 -0
  17. package/lib/match-media/MediaQueryList.js.map +1 -0
  18. package/lib/nodes/document/Document.d.ts +4 -0
  19. package/lib/nodes/document/Document.js +10 -0
  20. package/lib/nodes/document/Document.js.map +1 -1
  21. package/lib/nodes/element/Element.d.ts +12 -0
  22. package/lib/nodes/element/Element.js +20 -0
  23. package/lib/nodes/element/Element.js.map +1 -1
  24. package/lib/nodes/element/IElement.d.ts +1 -0
  25. package/lib/nodes/html-slot-element/HTMLSlotElement.d.ts +59 -0
  26. package/lib/nodes/html-slot-element/HTMLSlotElement.js +126 -0
  27. package/lib/nodes/html-slot-element/HTMLSlotElement.js.map +1 -0
  28. package/lib/nodes/html-slot-element/IHTMLSlotElement.d.ts +46 -0
  29. package/lib/nodes/html-slot-element/IHTMLSlotElement.js +3 -0
  30. package/lib/nodes/html-slot-element/IHTMLSlotElement.js.map +1 -0
  31. package/lib/nodes/node/Node.js +0 -4
  32. package/lib/nodes/node/Node.js.map +1 -1
  33. package/lib/window/IWindow.d.ts +2 -0
  34. package/lib/window/Window.d.ts +11 -0
  35. package/lib/window/Window.js +15 -0
  36. package/lib/window/Window.js.map +1 -1
  37. package/package.json +3 -3
  38. package/src/config/ElementTag.ts +2 -0
  39. package/src/event/EventTarget.ts +7 -1
  40. package/src/event/NonImplementedEventTypes.ts +0 -1
  41. package/src/event/events/IStorageEventInit.ts +9 -0
  42. package/src/event/events/StorageEvent.ts +30 -0
  43. package/src/match-media/MediaQueryList.ts +52 -0
  44. package/src/nodes/document/Document.ts +13 -0
  45. package/src/nodes/element/Element.ts +18 -0
  46. package/src/nodes/element/IElement.ts +1 -0
  47. package/src/nodes/html-slot-element/HTMLSlotElement.ts +110 -0
  48. package/src/nodes/html-slot-element/IHTMLSlotElement.ts +47 -0
  49. package/src/nodes/node/Node.ts +0 -6
  50. package/src/window/IWindow.ts +2 -0
  51. package/src/window/Window.ts +16 -0
@@ -0,0 +1,110 @@
1
+ import HTMLElement from '../html-element/HTMLElement';
2
+ import IShadowRoot from '../shadow-root/IShadowRoot';
3
+ import IHTMLSlotElement from './IHTMLSlotElement';
4
+ import IText from '../text/IText';
5
+ import IElement from '../element/IElement';
6
+ import INode from '../node/INode';
7
+
8
+ /**
9
+ * HTML Slot Element.
10
+ *
11
+ * Reference:
12
+ * https://developer.mozilla.org/en-US/docs/Web/API/HTMLSlotElement.
13
+ */
14
+ export default class HTMLSlotElement extends HTMLElement implements IHTMLSlotElement {
15
+ /**
16
+ * Returns name.
17
+ *
18
+ * @returns Name.
19
+ */
20
+ public get name(): string {
21
+ return this.getAttributeNS(null, 'name') || '';
22
+ }
23
+
24
+ /**
25
+ * Sets name.
26
+ *
27
+ * @param name Name.
28
+ */
29
+ public set name(name: string) {
30
+ this.setAttributeNS(null, 'name', name);
31
+ }
32
+
33
+ /**
34
+ * Sets the slot's manually assigned nodes to an ordered set of slottables.
35
+ *
36
+ * @param _nodes Nodes.
37
+ */
38
+ public assign(..._nodes: Array<IText | IElement>): void {
39
+ // TODO: Do nothing for now. We need to find an example of how it is expected to work before it can be implemented.
40
+ }
41
+
42
+ /**
43
+ * Returns assigned nodes.
44
+ *
45
+ * @param [options] Options.
46
+ * @param [options.flatten] A boolean value indicating whether to return the assigned nodes of any available child <slot> elements (true) or not (false). Defaults to false.
47
+ * @returns Nodes.
48
+ */
49
+ public assignedNodes(options?: { flatten?: boolean }): INode[] {
50
+ const host = (<IShadowRoot>this.getRootNode())?.host;
51
+
52
+ // TODO: Add support for options.flatten. We need to find an example of how it is expected to work before it can be implemented.
53
+
54
+ if (host) {
55
+ const name = this.name;
56
+
57
+ if (name) {
58
+ return this.assignedElements(options);
59
+ }
60
+
61
+ return host.childNodes.slice();
62
+ }
63
+
64
+ return [];
65
+ }
66
+
67
+ /**
68
+ * Returns assigned elements.
69
+ *
70
+ * @param [_options] Options.
71
+ * @param [_options.flatten] A boolean value indicating whether to return the assigned elements of any available child <slot> elements (true) or not (false). Defaults to false.
72
+ * @returns Nodes.
73
+ */
74
+ public assignedElements(_options?: { flatten?: boolean }): IElement[] {
75
+ const host = (<IShadowRoot>this.getRootNode())?.host;
76
+
77
+ // TODO: Add support for options.flatten. We need to find an example of how it expected to work before it can be implemented.
78
+
79
+ if (host) {
80
+ const name = this.name;
81
+
82
+ if (name) {
83
+ const assignedElements = [];
84
+
85
+ for (const child of host.children) {
86
+ if (child.slot === name) {
87
+ assignedElements.push(child);
88
+ }
89
+ }
90
+
91
+ return assignedElements;
92
+ }
93
+
94
+ return host.children.slice();
95
+ }
96
+
97
+ return [];
98
+ }
99
+
100
+ /**
101
+ * Clones a node.
102
+ *
103
+ * @override
104
+ * @param [deep=false] "true" to clone deep.
105
+ * @returns Cloned node.
106
+ */
107
+ public cloneNode(deep = false): IHTMLSlotElement {
108
+ return <HTMLSlotElement>super.cloneNode(deep);
109
+ }
110
+ }
@@ -0,0 +1,47 @@
1
+ import IHTMLElement from '../html-element/IHTMLElement';
2
+ import IText from '../text/IText';
3
+ import IElement from '../element/IElement';
4
+ import INode from '../node/INode';
5
+
6
+ /**
7
+ * HTML Slot Element.
8
+ *
9
+ * Reference:
10
+ * https://developer.mozilla.org/en-US/docs/Web/API/HTMLSlotElement.
11
+ */
12
+ export default interface IHTMLSlotElement extends IHTMLElement {
13
+ name: string;
14
+
15
+ /**
16
+ * Sets the slot's manually assigned nodes to an ordered set of slottables.
17
+ *
18
+ * @param nodes Nodes.
19
+ */
20
+ assign(...nodes: Array<IText | IElement>): void;
21
+
22
+ /**
23
+ * Returns assigned nodes.
24
+ *
25
+ * @param [options] Options.
26
+ * @param [options.flatten] A boolean value indicating whether to return the assigned nodes of any available child <slot> elements (true) or not (false). Defaults to false.
27
+ * @returns Nodes.
28
+ */
29
+ assignedNodes(options?: { flatten?: boolean }): INode[];
30
+
31
+ /**
32
+ * Returns assigned nodes.
33
+ *
34
+ * @param [options.flatten] A boolean value indicating whether to return the assigned elements of any available child <slot> elements (true) or not (false). Defaults to false.
35
+ * @returns Nodes.
36
+ */
37
+ assignedElements(options?: { flatten?: boolean }): IElement[];
38
+
39
+ /**
40
+ * Clones a node.
41
+ *
42
+ * @override
43
+ * @param [deep=false] "true" to clone deep.
44
+ * @returns Cloned node.
45
+ */
46
+ cloneNode(deep: boolean): IHTMLSlotElement;
47
+ }
@@ -387,12 +387,6 @@ export default class Node extends EventTarget implements INode {
387
387
  * @override
388
388
  */
389
389
  public dispatchEvent(event: Event): boolean {
390
- const onEventName = 'on' + event.type.toLowerCase();
391
-
392
- if (typeof this[onEventName] === 'function') {
393
- this[onEventName].call(this, event);
394
- }
395
-
396
390
  const returnValue = super.dispatchEvent(event);
397
391
 
398
392
  if (event.bubbles && !event._propagationStopped) {
@@ -49,6 +49,7 @@ import DataTransferItemList from '../event/DataTransferItemList';
49
49
  import InputEvent from '../event/events/InputEvent';
50
50
  import UIEvent from '../event/UIEvent';
51
51
  import ErrorEvent from '../event/events/ErrorEvent';
52
+ import StorageEvent from '../event/events/StorageEvent';
52
53
  import Screen from '../screen/Screen';
53
54
  import AsyncTaskManager from './AsyncTaskManager';
54
55
  import IResponse from './IResponse';
@@ -111,6 +112,7 @@ export default interface IWindow {
111
112
  readonly WheelEvent: typeof WheelEvent;
112
113
  readonly InputEvent: typeof InputEvent;
113
114
  readonly ErrorEvent: typeof ErrorEvent;
115
+ readonly StorageEvent: typeof StorageEvent;
114
116
  readonly ProgressEvent: typeof ProgressEvent;
115
117
  readonly EventTarget: typeof EventTarget;
116
118
  readonly DataTransfer: typeof DataTransfer;
@@ -52,6 +52,7 @@ import DataTransferItemList from '../event/DataTransferItemList';
52
52
  import InputEvent from '../event/events/InputEvent';
53
53
  import UIEvent from '../event/UIEvent';
54
54
  import ErrorEvent from '../event/events/ErrorEvent';
55
+ import StorageEvent from '../event/events/StorageEvent';
55
56
  import Screen from '../screen/Screen';
56
57
  import AsyncTaskManager from './AsyncTaskManager';
57
58
  import IResponse from './IResponse';
@@ -65,6 +66,7 @@ import IWindow from './IWindow';
65
66
  import URLSearchParams from '../url-search-params/URLSearchParams';
66
67
  import HTMLCollection from '../nodes/element/HTMLCollection';
67
68
  import NodeList from '../nodes/node/NodeList';
69
+ import MediaQueryList from '../match-media/MediaQueryList';
68
70
 
69
71
  const FETCH_RESPONSE_TYPE_METHODS = ['blob', 'json', 'text'];
70
72
 
@@ -121,6 +123,7 @@ export default class Window extends EventTarget implements IWindow, NodeJS.Globa
121
123
  public readonly WheelEvent = WheelEvent;
122
124
  public readonly InputEvent = InputEvent;
123
125
  public readonly ErrorEvent = ErrorEvent;
126
+ public readonly StorageEvent = StorageEvent;
124
127
  public readonly ProgressEvent = ProgressEvent;
125
128
  public readonly EventTarget = EventTarget;
126
129
  public readonly DataTransfer = DataTransfer;
@@ -163,6 +166,7 @@ export default class Window extends EventTarget implements IWindow, NodeJS.Globa
163
166
  public readonly screen = new Screen();
164
167
  public readonly innerWidth = 1024;
165
168
  public readonly innerHeight = 768;
169
+ public readonly devicePixelRatio = 1;
166
170
  public readonly sessionStorage = new Storage();
167
171
  public readonly localStorage = new Storage();
168
172
 
@@ -344,6 +348,18 @@ export default class Window extends EventTarget implements IWindow, NodeJS.Globa
344
348
  this.scroll(x, y);
345
349
  }
346
350
 
351
+ /**
352
+ * Returns a new MediaQueryList object that can then be used to determine if the document matches the media query string.
353
+ *
354
+ * @param mediaQueryString A string specifying the media query to parse into a MediaQueryList.
355
+ * @returns A new MediaQueryList.
356
+ */
357
+ public matchMedia(mediaQueryString: string): MediaQueryList {
358
+ const mediaQueryList = new MediaQueryList();
359
+ mediaQueryList._media = mediaQueryString;
360
+ return mediaQueryList;
361
+ }
362
+
347
363
  /**
348
364
  * Sets a timer which executes a function once the timer expires.
349
365
  *