happy-dom 14.8.0 → 14.8.2

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 (46) hide show
  1. package/cjs/index.cjs +6 -4
  2. package/cjs/index.cjs.map +1 -1
  3. package/cjs/index.d.ts +2 -1
  4. package/cjs/index.d.ts.map +1 -1
  5. package/cjs/nodes/document/Document.cjs +1 -1
  6. package/cjs/nodes/document/Document.cjs.map +1 -1
  7. package/cjs/nodes/document/Document.d.ts +1 -1
  8. package/cjs/nodes/document/Document.d.ts.map +1 -1
  9. package/cjs/nodes/element/DOMRect.cjs +56 -22
  10. package/cjs/nodes/element/DOMRect.cjs.map +1 -1
  11. package/cjs/nodes/element/DOMRect.d.ts +11 -18
  12. package/cjs/nodes/element/DOMRect.d.ts.map +1 -1
  13. package/cjs/nodes/element/DOMRectReadOnly.cjs +95 -0
  14. package/cjs/nodes/element/DOMRectReadOnly.cjs.map +1 -0
  15. package/cjs/nodes/element/DOMRectReadOnly.d.ts +38 -0
  16. package/cjs/nodes/element/DOMRectReadOnly.d.ts.map +1 -0
  17. package/cjs/window/BrowserWindow.cjs +2 -0
  18. package/cjs/window/BrowserWindow.cjs.map +1 -1
  19. package/cjs/window/BrowserWindow.d.ts +2 -0
  20. package/cjs/window/BrowserWindow.d.ts.map +1 -1
  21. package/lib/index.d.ts +2 -1
  22. package/lib/index.d.ts.map +1 -1
  23. package/lib/index.js +2 -1
  24. package/lib/index.js.map +1 -1
  25. package/lib/nodes/document/Document.d.ts +1 -1
  26. package/lib/nodes/document/Document.d.ts.map +1 -1
  27. package/lib/nodes/document/Document.js +1 -1
  28. package/lib/nodes/document/Document.js.map +1 -1
  29. package/lib/nodes/element/DOMRect.d.ts +11 -18
  30. package/lib/nodes/element/DOMRect.d.ts.map +1 -1
  31. package/lib/nodes/element/DOMRect.js +30 -22
  32. package/lib/nodes/element/DOMRect.js.map +1 -1
  33. package/lib/nodes/element/DOMRectReadOnly.d.ts +38 -0
  34. package/lib/nodes/element/DOMRectReadOnly.d.ts.map +1 -0
  35. package/lib/nodes/element/DOMRectReadOnly.js +70 -0
  36. package/lib/nodes/element/DOMRectReadOnly.js.map +1 -0
  37. package/lib/window/BrowserWindow.d.ts +2 -0
  38. package/lib/window/BrowserWindow.d.ts.map +1 -1
  39. package/lib/window/BrowserWindow.js +2 -0
  40. package/lib/window/BrowserWindow.js.map +1 -1
  41. package/package.json +1 -1
  42. package/src/index.ts +2 -0
  43. package/src/nodes/document/Document.ts +2 -2
  44. package/src/nodes/element/DOMRect.ts +40 -23
  45. package/src/nodes/element/DOMRectReadOnly.ts +86 -0
  46. package/src/window/BrowserWindow.ts +2 -0
package/src/index.ts CHANGED
@@ -70,6 +70,7 @@ import DocumentFragment from './nodes/document-fragment/DocumentFragment.js';
70
70
  import DocumentType from './nodes/document-type/DocumentType.js';
71
71
  import Document from './nodes/document/Document.js';
72
72
  import DOMRect from './nodes/element/DOMRect.js';
73
+ import DOMRectReadOnly from './nodes/element/DOMRectReadOnly.js';
73
74
  import Element from './nodes/element/Element.js';
74
75
  import HTMLCollection from './nodes/element/HTMLCollection.js';
75
76
  import HTMLAnchorElement from './nodes/html-anchor-element/HTMLAnchorElement.js';
@@ -211,6 +212,7 @@ export {
211
212
  DOMException,
212
213
  DOMParser,
213
214
  DOMRect,
215
+ DOMRectReadOnly,
214
216
  DataTransfer,
215
217
  DataTransferItem,
216
218
  DataTransferItemList,
@@ -318,8 +318,8 @@ export default class Document extends Node {
318
318
  /**
319
319
  * Returns a collection of all form elements in a document.
320
320
  */
321
- public get forms(): NodeList<HTMLFormElement> {
322
- return this.querySelectorAll('form');
321
+ public get forms(): HTMLCollection<HTMLFormElement> {
322
+ return this.getElementsByTagName('form');
323
323
  }
324
324
 
325
325
  /**
@@ -1,30 +1,47 @@
1
+ import DOMRectReadOnly, { IDOMRectInit } from './DOMRectReadOnly.js';
2
+ import * as PropertySymbol from '../../PropertySymbol.js';
3
+
4
+ /* eslint-disable jsdoc/require-jsdoc */
5
+
1
6
  /**
2
7
  * Bounding rect object.
3
8
  *
4
9
  * @see https://developer.mozilla.org/en-US/docs/Web/API/DOMRect
5
10
  */
6
- export default class DOMRect {
7
- public x = 0;
8
- public y = 0;
9
- public width = 0;
10
- public height = 0;
11
- public top = 0;
12
- public right = 0;
13
- public bottom = 0;
14
- public left = 0;
15
-
16
- /**
17
- * Constructor.
18
- *
19
- * @param [x] X position.
20
- * @param [y] Y position.
21
- * @param [width] Width.
22
- * @param [height] Height.
23
- */
24
- constructor(x?, y?, width?, height?) {
25
- this.x = x || 0;
26
- this.y = y || 0;
27
- this.width = width || 0;
28
- this.height = height || 0;
11
+ export default class DOMRect extends DOMRectReadOnly {
12
+ public set x(value: number) {
13
+ this[PropertySymbol.x] = value;
14
+ }
15
+
16
+ public get x(): number {
17
+ return this[PropertySymbol.x];
18
+ }
19
+
20
+ public set y(value: number) {
21
+ this[PropertySymbol.y] = value;
22
+ }
23
+
24
+ public get y(): number {
25
+ return this[PropertySymbol.y];
26
+ }
27
+
28
+ public set width(value: number) {
29
+ this[PropertySymbol.width] = value;
30
+ }
31
+
32
+ public get width(): number {
33
+ return this[PropertySymbol.width];
34
+ }
35
+
36
+ public set height(value: number) {
37
+ this[PropertySymbol.height] = value;
38
+ }
39
+
40
+ public get height(): number {
41
+ return this[PropertySymbol.height];
42
+ }
43
+
44
+ public static fromRect(other: IDOMRectInit): DOMRect {
45
+ return new DOMRect(other.x, other.y, other.width, other.height);
29
46
  }
30
47
  }
@@ -0,0 +1,86 @@
1
+ import * as PropertySymbol from '../../PropertySymbol.js';
2
+
3
+ /* eslint-disable jsdoc/require-jsdoc */
4
+
5
+ /**
6
+ * Bounding rect readonly object.
7
+ *
8
+ * @see https://drafts.fxtf.org/geometry/#DOMRect
9
+ */
10
+ export default class DOMRectReadOnly implements IDOMRectInit {
11
+ protected [PropertySymbol.x]: number = 0;
12
+ protected [PropertySymbol.y]: number = 0;
13
+ protected [PropertySymbol.width]: number = 0;
14
+ protected [PropertySymbol.height]: number = 0;
15
+
16
+ /**
17
+ * Constructor.
18
+ *
19
+ * @param [x] X position.
20
+ * @param [y] Y position.
21
+ * @param [width] Width.
22
+ * @param [height] Height.
23
+ */
24
+ constructor(x?: number | null, y?: number | null, width?: number | null, height?: number | null) {
25
+ this[PropertySymbol.x] = x !== undefined && x !== null ? Number(x) : 0;
26
+ this[PropertySymbol.y] = y !== undefined && y !== null ? Number(y) : 0;
27
+ this[PropertySymbol.width] = width !== undefined && width !== null ? Number(width) : 0;
28
+ this[PropertySymbol.height] = height !== undefined && height !== null ? Number(height) : 0;
29
+ }
30
+
31
+ public get x(): number {
32
+ return this[PropertySymbol.x];
33
+ }
34
+
35
+ public get y(): number {
36
+ return this[PropertySymbol.y];
37
+ }
38
+
39
+ public get width(): number {
40
+ return this[PropertySymbol.width];
41
+ }
42
+
43
+ public get height(): number {
44
+ return this[PropertySymbol.height];
45
+ }
46
+
47
+ public get top(): number {
48
+ return Math.min(this[PropertySymbol.y], this[PropertySymbol.y] + this[PropertySymbol.height]);
49
+ }
50
+
51
+ public get right(): number {
52
+ return Math.max(this[PropertySymbol.x], this[PropertySymbol.x] + this[PropertySymbol.width]);
53
+ }
54
+
55
+ public get bottom(): number {
56
+ return Math.max(this[PropertySymbol.y], this[PropertySymbol.y] + this[PropertySymbol.height]);
57
+ }
58
+
59
+ public get left(): number {
60
+ return Math.min(this[PropertySymbol.x], this[PropertySymbol.x] + this[PropertySymbol.width]);
61
+ }
62
+
63
+ public toJSON(): object {
64
+ return {
65
+ x: this.x,
66
+ y: this.y,
67
+ width: this.width,
68
+ height: this.height,
69
+ top: this.top,
70
+ right: this.right,
71
+ bottom: this.bottom,
72
+ left: this.left
73
+ };
74
+ }
75
+
76
+ public static fromRect(other: IDOMRectInit): DOMRectReadOnly {
77
+ return new DOMRectReadOnly(other.x, other.y, other.width, other.height);
78
+ }
79
+ }
80
+
81
+ export interface IDOMRectInit {
82
+ readonly x: number;
83
+ readonly y: number;
84
+ readonly width: number;
85
+ readonly height: number;
86
+ }
@@ -97,6 +97,7 @@ import Plugin from '../navigator/Plugin.js';
97
97
  import PluginArray from '../navigator/PluginArray.js';
98
98
  import Fetch from '../fetch/Fetch.js';
99
99
  import DOMRect from '../nodes/element/DOMRect.js';
100
+ import DOMRectReadOnly from '../nodes/element/DOMRectReadOnly.js';
100
101
  import VMGlobalPropertyScript from './VMGlobalPropertyScript.js';
101
102
  import VM from 'vm';
102
103
  import { Buffer } from 'buffer';
@@ -372,6 +373,7 @@ export default class BrowserWindow extends EventTarget implements INodeJSGlobal
372
373
  public readonly PluginArray = PluginArray;
373
374
  public readonly FileList = FileList;
374
375
  public readonly DOMRect = DOMRect;
376
+ public readonly DOMRectReadOnly = DOMRectReadOnly;
375
377
  public readonly RadioNodeList = RadioNodeList;
376
378
  public readonly ValidityState = ValidityState;
377
379
  public readonly Headers = Headers;