happy-dom 2.37.0 → 2.40.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 (85) hide show
  1. package/lib/config/ElementTag.d.ts +2 -0
  2. package/lib/config/ElementTag.js +3 -1
  3. package/lib/config/ElementTag.js.map +1 -1
  4. package/lib/cookie/CookieUtility.js +2 -2
  5. package/lib/cookie/CookieUtility.js.map +1 -1
  6. package/lib/css/CSS.d.ts +29 -0
  7. package/lib/css/CSS.js +53 -0
  8. package/lib/css/CSS.js.map +1 -0
  9. package/lib/css/CSSStyleDeclaration.js +5 -5
  10. package/lib/css/CSSStyleDeclaration.js.map +1 -1
  11. package/lib/css/CSSUnitValue.d.ts +14 -0
  12. package/lib/css/CSSUnitValue.js +32 -0
  13. package/lib/css/CSSUnitValue.js.map +1 -0
  14. package/lib/css/CSSUnits.d.ts +2 -0
  15. package/lib/css/CSSUnits.js +34 -0
  16. package/lib/css/CSSUnits.js.map +1 -0
  17. package/lib/css/rules/CSSKeyframeRule.js +1 -1
  18. package/lib/css/rules/CSSKeyframeRule.js.map +1 -1
  19. package/lib/css/rules/CSSKeyframesRule.js +1 -1
  20. package/lib/css/rules/CSSKeyframesRule.js.map +1 -1
  21. package/lib/css/rules/CSSMediaRule.js +1 -1
  22. package/lib/css/rules/CSSMediaRule.js.map +1 -1
  23. package/lib/css/rules/CSSStyleRule.js +1 -1
  24. package/lib/css/rules/CSSStyleRule.js.map +1 -1
  25. package/lib/dom-parser/DOMParser.js +1 -1
  26. package/lib/dom-parser/DOMParser.js.map +1 -1
  27. package/lib/fetch/ResourceFetcher.js +2 -2
  28. package/lib/fetch/ResourceFetcher.js.map +1 -1
  29. package/lib/file/FileReader.js +1 -1
  30. package/lib/file/FileReader.js.map +1 -1
  31. package/lib/index.d.ts +3 -1
  32. package/lib/index.js +4 -2
  33. package/lib/index.js.map +1 -1
  34. package/lib/location/URL.js +1 -1
  35. package/lib/location/URL.js.map +1 -1
  36. package/lib/nodes/character-data/CharacterData.js +11 -7
  37. package/lib/nodes/character-data/CharacterData.js.map +1 -1
  38. package/lib/nodes/document/Document.js +11 -7
  39. package/lib/nodes/document/Document.js.map +1 -1
  40. package/lib/nodes/document-fragment/DocumentFragment.js +11 -7
  41. package/lib/nodes/document-fragment/DocumentFragment.js.map +1 -1
  42. package/lib/nodes/element/ClassList.js +1 -1
  43. package/lib/nodes/element/ClassList.js.map +1 -1
  44. package/lib/nodes/element/Element.js +14 -10
  45. package/lib/nodes/element/Element.js.map +1 -1
  46. package/lib/nodes/html-input-element/HTMLInputElement.d.ts +12 -0
  47. package/lib/nodes/html-input-element/HTMLInputElement.js +28 -5
  48. package/lib/nodes/html-input-element/HTMLInputElement.js.map +1 -1
  49. package/lib/nodes/html-input-element/HTMLInputElementValueStepping.d.ts +15 -0
  50. package/lib/nodes/html-input-element/HTMLInputElementValueStepping.js +41 -0
  51. package/lib/nodes/html-input-element/HTMLInputElementValueStepping.js.map +1 -0
  52. package/lib/nodes/html-input-element/IHTMLInputElement.d.ts +12 -0
  53. package/lib/nodes/html-meta-element/HTMLMetaElement.d.ts +58 -0
  54. package/lib/nodes/html-meta-element/HTMLMetaElement.js +116 -0
  55. package/lib/nodes/html-meta-element/HTMLMetaElement.js.map +1 -0
  56. package/lib/nodes/html-meta-element/IHTMLMetaElement.d.ts +13 -0
  57. package/lib/nodes/html-meta-element/IHTMLMetaElement.js +3 -0
  58. package/lib/nodes/html-meta-element/IHTMLMetaElement.js.map +1 -0
  59. package/lib/nodes/node/Node.js +1 -1
  60. package/lib/nodes/node/Node.js.map +1 -1
  61. package/lib/nodes/parent-node/ParentNodeUtility.js +9 -5
  62. package/lib/nodes/parent-node/ParentNodeUtility.js.map +1 -1
  63. package/lib/query-selector/SelectorItem.js +5 -5
  64. package/lib/query-selector/SelectorItem.js.map +1 -1
  65. package/lib/window/IWindow.d.ts +7 -1
  66. package/lib/window/Window.d.ts +12 -1
  67. package/lib/window/Window.js +18 -1
  68. package/lib/window/Window.js.map +1 -1
  69. package/lib/xml-parser/XMLParser.js +1 -1
  70. package/lib/xml-parser/XMLParser.js.map +1 -1
  71. package/lib/xml-serializer/XMLSerializer.js +8 -8
  72. package/lib/xml-serializer/XMLSerializer.js.map +1 -1
  73. package/package.json +3 -2
  74. package/src/config/ElementTag.ts +3 -1
  75. package/src/css/CSS.ts +43 -0
  76. package/src/css/CSSUnitValue.ts +26 -0
  77. package/src/css/CSSUnits.ts +31 -0
  78. package/src/index.ts +4 -0
  79. package/src/nodes/html-input-element/HTMLInputElement.ts +25 -0
  80. package/src/nodes/html-input-element/HTMLInputElementValueStepping.ts +34 -0
  81. package/src/nodes/html-input-element/IHTMLInputElement.ts +14 -0
  82. package/src/nodes/html-meta-element/HTMLMetaElement.ts +81 -0
  83. package/src/nodes/html-meta-element/IHTMLMetaElement.ts +14 -0
  84. package/src/window/IWindow.ts +7 -1
  85. package/src/window/Window.ts +15 -1
@@ -0,0 +1,26 @@
1
+ import CSSUnits from './CSSUnits';
2
+
3
+ /**
4
+ * CSS unit value.
5
+ */
6
+ export default class CSSUnitValue {
7
+ public unit: string = null;
8
+ public value: number = null;
9
+
10
+ /**
11
+ * Constructor.
12
+ *
13
+ * @param value Value.
14
+ * @param unit Unit.
15
+ */
16
+ constructor(value: number, unit: string) {
17
+ if (typeof value !== 'number') {
18
+ throw new TypeError('The provided double value is non-finite');
19
+ }
20
+ if (!CSSUnits.includes(unit)) {
21
+ throw new TypeError('Invalid unit: ' + unit);
22
+ }
23
+ this.value = value;
24
+ this.unit = unit;
25
+ }
26
+ }
@@ -0,0 +1,31 @@
1
+ export default [
2
+ 'Hz',
3
+ 'Q',
4
+ 'ch',
5
+ 'cm',
6
+ 'deg',
7
+ 'dpcm',
8
+ 'dpi',
9
+ 'dppx',
10
+ 'em',
11
+ 'ex',
12
+ 'fr',
13
+ 'grad',
14
+ 'in',
15
+ 'kHz',
16
+ 'mm',
17
+ 'ms',
18
+ 'number',
19
+ 'pc',
20
+ 'percent',
21
+ 'pt',
22
+ 'px',
23
+ 'rad',
24
+ 'rem',
25
+ 's',
26
+ 'turn',
27
+ 'vh',
28
+ 'vmax',
29
+ 'vmin',
30
+ 'vw'
31
+ ];
package/src/index.ts CHANGED
@@ -74,6 +74,8 @@ import HTMLSlotElement from './nodes/html-slot-element/HTMLSlotElement';
74
74
  import IHTMLSlotElement from './nodes/html-slot-element/IHTMLSlotElement';
75
75
  import HTMLLabelElement from './nodes/html-label-element/HTMLLabelElement';
76
76
  import IHTMLLabelElement from './nodes/html-label-element/IHTMLLabelElement';
77
+ import HTMLMetaElement from './nodes/html-meta-element/HTMLMetaElement';
78
+ import IHTMLMetaElement from './nodes/html-meta-element/IHTMLMetaElement';
77
79
  import SVGElement from './nodes/svg-element/SVGElement';
78
80
  import ISVGElement from './nodes/svg-element/ISVGElement';
79
81
  import SVGGraphicsElement from './nodes/svg-element/SVGGraphicsElement';
@@ -181,6 +183,8 @@ export {
181
183
  IHTMLSlotElement,
182
184
  HTMLLabelElement,
183
185
  IHTMLLabelElement,
186
+ HTMLMetaElement,
187
+ IHTMLMetaElement,
184
188
  SVGElement,
185
189
  ISVGElement,
186
190
  SVGGraphicsElement,
@@ -10,6 +10,7 @@ import HTMLInputElementSelectionDirectionEnum from './HTMLInputElementSelectionD
10
10
  import IHTMLInputElement from './IHTMLInputElement';
11
11
  import IHTMLFormElement from '../html-form-element/IHTMLFormElement';
12
12
  import IHTMLElement from '../html-element/IHTMLElement';
13
+ import HTMLInputElementValueStepping from './HTMLInputElementValueStepping';
13
14
 
14
15
  /**
15
16
  * HTML Input Element.
@@ -903,6 +904,30 @@ export default class HTMLInputElement extends HTMLElement implements IHTMLInputE
903
904
  return true;
904
905
  }
905
906
 
907
+ /**
908
+ * Steps up.
909
+ *
910
+ * @param [increment] Increment.
911
+ */
912
+ public stepUp(increment?: number): void {
913
+ const newValue = HTMLInputElementValueStepping.step(this.type, this.value, 1, increment);
914
+ if (newValue !== null) {
915
+ this.value = newValue;
916
+ }
917
+ }
918
+
919
+ /**
920
+ * Steps down.
921
+ *
922
+ * @param [increment] Increment.
923
+ */
924
+ public stepDown(increment?: number): void {
925
+ const newValue = HTMLInputElementValueStepping.step(this.type, this.value, -1, increment);
926
+ if (newValue !== null) {
927
+ this.value = newValue;
928
+ }
929
+ }
930
+
906
931
  /**
907
932
  * Clones a node.
908
933
  *
@@ -0,0 +1,34 @@
1
+ import DOMException from '../../exception/DOMException';
2
+
3
+ /**
4
+ * HTML input element value stepping.
5
+ */
6
+ export default class HTMLInputElementValueStepping {
7
+ /**
8
+ * Steps up or down.
9
+ *
10
+ * @param type Type.
11
+ * @param value Value.
12
+ * @param direction Direction.
13
+ * @param [increment] Increment.
14
+ * @returns New value.
15
+ */
16
+ public static step(type: string, value: string, direction: -1 | 1, increment?: number): string {
17
+ switch (type) {
18
+ case 'number':
19
+ return String(
20
+ Number(value) + (increment !== undefined ? increment * direction : direction)
21
+ );
22
+ case 'date':
23
+ case 'month':
24
+ case 'week':
25
+ case 'time':
26
+ case 'datetime-local':
27
+ case 'range':
28
+ // TODO: Implement support for additional types
29
+ return null;
30
+ default:
31
+ throw new DOMException('This form element is not steppable.');
32
+ }
33
+ }
34
+ }
@@ -84,6 +84,20 @@ export default interface IHTMLInputElement extends IHTMLElement {
84
84
  */
85
85
  checkValidity(): boolean;
86
86
 
87
+ /**
88
+ * Steps up.
89
+ *
90
+ * @param [increment] Increment.
91
+ */
92
+ stepUp(increment?: number): void;
93
+
94
+ /**
95
+ * Steps up.
96
+ *
97
+ * @param [increment] Increment.
98
+ */
99
+ stepDown(increment?: number): void;
100
+
87
101
  /**
88
102
  * Clones a node.
89
103
  *
@@ -0,0 +1,81 @@
1
+ import IHTMLMetaElement from './IHTMLMetaElement';
2
+ import HTMLElement from '../html-element/HTMLElement';
3
+
4
+ /**
5
+ * HTML Meta Element.
6
+ *
7
+ * Reference:
8
+ * https://developer.mozilla.org/en-US/docs/Web/API/HTMLMetaElement.
9
+ */
10
+ export default class HTMLMetaElement extends HTMLElement implements IHTMLMetaElement {
11
+ /**
12
+ * Returns content.
13
+ *
14
+ * @returns Content.
15
+ */
16
+ public get content(): string {
17
+ return this.getAttributeNS(null, 'content') || '';
18
+ }
19
+
20
+ /**
21
+ * Sets content.
22
+ *
23
+ * @param content Content.
24
+ */
25
+ public set content(content: string) {
26
+ this.setAttributeNS(null, 'content', content);
27
+ }
28
+
29
+ /**
30
+ * Returns httpEquiv.
31
+ *
32
+ * @returns HttpEquiv.
33
+ */
34
+ public get httpEquiv(): string {
35
+ return this.getAttributeNS(null, 'http-equiv') || '';
36
+ }
37
+
38
+ /**
39
+ * Sets httpEquiv.
40
+ *
41
+ * @param httpEquiv HttpEquiv.
42
+ */
43
+ public set httpEquiv(httpEquiv: string) {
44
+ this.setAttributeNS(null, 'http-equiv', httpEquiv);
45
+ }
46
+
47
+ /**
48
+ * Returns name.
49
+ *
50
+ * @returns Name.
51
+ */
52
+ public get name(): string {
53
+ return this.getAttributeNS(null, 'name') || '';
54
+ }
55
+
56
+ /**
57
+ * Sets name.
58
+ *
59
+ * @param name Name.
60
+ */
61
+ public set name(name: string) {
62
+ this.setAttributeNS(null, 'name', name);
63
+ }
64
+ /**
65
+ * Returns scheme.
66
+ *
67
+ * @returns Name.
68
+ */
69
+ public get scheme(): string {
70
+ return this.getAttributeNS(null, 'scheme') || '';
71
+ }
72
+
73
+ /**
74
+ * Sets scheme.
75
+ *
76
+ * @param scheme Scheme.
77
+ */
78
+ public set scheme(scheme: string) {
79
+ this.setAttributeNS(null, 'scheme', scheme);
80
+ }
81
+ }
@@ -0,0 +1,14 @@
1
+ import IHTMLElement from '../html-element/IHTMLElement';
2
+
3
+ /**
4
+ * HTML Meta Element.
5
+ *
6
+ * Reference:
7
+ * https://developer.mozilla.org/en-US/docs/Web/API/HTMLMetaElement.
8
+ */
9
+ export default interface IHTMLMetaElement extends IHTMLElement {
10
+ content: string;
11
+ httpEquiv: string;
12
+ name: string;
13
+ scheme: string;
14
+ }
@@ -17,6 +17,7 @@ import HTMLLinkElement from '../nodes/html-link-element/HTMLLinkElement';
17
17
  import HTMLStyleElement from '../nodes/html-style-element/HTMLStyleElement';
18
18
  import HTMLSlotElement from '../nodes/html-slot-element/HTMLSlotElement';
19
19
  import HTMLLabelElement from '../nodes/html-label-element/HTMLLabelElement';
20
+ import HTMLMetaElement from '../nodes/html-meta-element/HTMLMetaElement';
20
21
  import SVGSVGElement from '../nodes/svg-element/SVGSVGElement';
21
22
  import SVGElement from '../nodes/svg-element/SVGElement';
22
23
  import HTMLScriptElement from '../nodes/html-script-element/HTMLScriptElement';
@@ -37,13 +38,15 @@ import MutationObserver from '../mutation-observer/MutationObserver';
37
38
  import DOMParser from '../dom-parser/DOMParser';
38
39
  import XMLSerializer from '../xml-serializer/XMLSerializer';
39
40
  import ResizeObserver from '../resize-observer/ResizeObserver';
40
- import CSSStyleSheet from '../css/CSSStyleSheet';
41
41
  import Blob from '../file/Blob';
42
42
  import File from '../file/File';
43
43
  import DOMException from '../exception/DOMException';
44
44
  import FileReader from '../file/FileReader';
45
45
  import History from '../history/History';
46
+ import CSSStyleSheet from '../css/CSSStyleSheet';
46
47
  import CSSStyleDeclaration from '../css/CSSStyleDeclaration';
48
+ import CSS from '../css/CSS';
49
+ import CSSUnitValue from '../css/CSSUnitValue';
47
50
  import PointerEvent from '../event/events/PointerEvent';
48
51
  import MouseEvent from '../event/events/MouseEvent';
49
52
  import FocusEvent from '../event/events/FocusEvent';
@@ -90,6 +93,7 @@ export default interface IWindow {
90
93
  readonly HTMLStyleElement: typeof HTMLStyleElement;
91
94
  readonly HTMLSlotElement: typeof HTMLSlotElement;
92
95
  readonly HTMLLabelElement: typeof HTMLLabelElement;
96
+ readonly HTMLMetaElement: typeof HTMLMetaElement;
93
97
  readonly SVGSVGElement: typeof SVGSVGElement;
94
98
  readonly SVGElement: typeof SVGElement;
95
99
  readonly Image: typeof Image;
@@ -142,6 +146,8 @@ export default interface IWindow {
142
146
  readonly URLSearchParams: typeof URLSearchParams;
143
147
  readonly HTMLCollection: typeof HTMLCollection;
144
148
  readonly NodeList: typeof NodeList;
149
+ readonly CSSUnitValue: typeof CSSUnitValue;
150
+ readonly CSS: CSS;
145
151
 
146
152
  // Events
147
153
  onload: (event: Event) => void;
@@ -18,6 +18,7 @@ import HTMLLinkElement from '../nodes/html-link-element/HTMLLinkElement';
18
18
  import HTMLStyleElement from '../nodes/html-style-element/HTMLStyleElement';
19
19
  import HTMLSlotElement from '../nodes/html-slot-element/HTMLSlotElement';
20
20
  import HTMLLabelElement from '../nodes/html-label-element/HTMLLabelElement';
21
+ import HTMLMetaElement from '../nodes/html-meta-element/HTMLMetaElement';
21
22
  import SVGSVGElement from '../nodes/svg-element/SVGSVGElement';
22
23
  import SVGElement from '../nodes/svg-element/SVGElement';
23
24
  import HTMLScriptElement from '../nodes/html-script-element/HTMLScriptElement';
@@ -40,13 +41,15 @@ import ElementClass from '../config/ElementClass';
40
41
  import DOMParser from '../dom-parser/DOMParser';
41
42
  import XMLSerializer from '../xml-serializer/XMLSerializer';
42
43
  import ResizeObserver from '../resize-observer/ResizeObserver';
43
- import CSSStyleSheet from '../css/CSSStyleSheet';
44
44
  import Blob from '../file/Blob';
45
45
  import File from '../file/File';
46
46
  import DOMException from '../exception/DOMException';
47
47
  import FileReader from '../file/FileReader';
48
48
  import History from '../history/History';
49
+ import CSSStyleSheet from '../css/CSSStyleSheet';
49
50
  import CSSStyleDeclaration from '../css/CSSStyleDeclaration';
51
+ import CSS from '../css/CSS';
52
+ import CSSUnitValue from '../css/CSSUnitValue';
50
53
  import MouseEvent from '../event/events/MouseEvent';
51
54
  import PointerEvent from '../event/events/PointerEvent';
52
55
  import FocusEvent from '../event/events/FocusEvent';
@@ -103,6 +106,7 @@ export default class Window extends EventTarget implements IWindow, NodeJS.Globa
103
106
  public readonly HTMLStyleElement = HTMLStyleElement;
104
107
  public readonly HTMLLabelElement = HTMLLabelElement;
105
108
  public readonly HTMLSlotElement = HTMLSlotElement;
109
+ public readonly HTMLMetaElement = HTMLMetaElement;
106
110
  public readonly SVGSVGElement = SVGSVGElement;
107
111
  public readonly SVGElement = SVGElement;
108
112
  public readonly Text = Text;
@@ -155,6 +159,7 @@ export default class Window extends EventTarget implements IWindow, NodeJS.Globa
155
159
  public readonly HTMLCollection = HTMLCollection;
156
160
  public readonly NodeList = NodeList;
157
161
  public readonly MediaQueryList = MediaQueryList;
162
+ public readonly CSSUnitValue = CSSUnitValue;
158
163
 
159
164
  // Events
160
165
  public onload: (event: Event) => void = null;
@@ -278,6 +283,15 @@ export default class Window extends EventTarget implements IWindow, NodeJS.Globa
278
283
  }
279
284
  }
280
285
 
286
+ /**
287
+ * The CSS interface holds useful CSS-related methods.
288
+ *
289
+ * @returns CSS interface.
290
+ */
291
+ public get CSS(): CSS {
292
+ return new CSS();
293
+ }
294
+
281
295
  /**
282
296
  * Evaluates code.
283
297
  *