happy-dom 10.3.2 → 10.5.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 (34) hide show
  1. package/cjs/css/CSSParser.cjs +4 -1
  2. package/cjs/css/CSSParser.cjs.map +1 -1
  3. package/cjs/css/CSSParser.d.ts.map +1 -1
  4. package/cjs/css/declaration/css-parser/CSSStyleDeclarationCSSParser.cjs +9 -15
  5. package/cjs/css/declaration/css-parser/CSSStyleDeclarationCSSParser.cjs.map +1 -1
  6. package/cjs/css/declaration/css-parser/CSSStyleDeclarationCSSParser.d.ts.map +1 -1
  7. package/cjs/css/declaration/property-manager/CSSStyleDeclarationPropertySetParser.cjs +6 -5
  8. package/cjs/css/declaration/property-manager/CSSStyleDeclarationPropertySetParser.cjs.map +1 -1
  9. package/cjs/css/declaration/property-manager/CSSStyleDeclarationPropertySetParser.d.ts.map +1 -1
  10. package/cjs/event/events/IMouseEventInit.d.ts +2 -0
  11. package/cjs/event/events/IMouseEventInit.d.ts.map +1 -1
  12. package/cjs/event/events/MouseEvent.cjs +2 -0
  13. package/cjs/event/events/MouseEvent.cjs.map +1 -1
  14. package/cjs/event/events/MouseEvent.d.ts.map +1 -1
  15. package/lib/css/CSSParser.d.ts.map +1 -1
  16. package/lib/css/CSSParser.js +4 -1
  17. package/lib/css/CSSParser.js.map +1 -1
  18. package/lib/css/declaration/css-parser/CSSStyleDeclarationCSSParser.d.ts.map +1 -1
  19. package/lib/css/declaration/css-parser/CSSStyleDeclarationCSSParser.js +9 -15
  20. package/lib/css/declaration/css-parser/CSSStyleDeclarationCSSParser.js.map +1 -1
  21. package/lib/css/declaration/property-manager/CSSStyleDeclarationPropertySetParser.d.ts.map +1 -1
  22. package/lib/css/declaration/property-manager/CSSStyleDeclarationPropertySetParser.js +6 -5
  23. package/lib/css/declaration/property-manager/CSSStyleDeclarationPropertySetParser.js.map +1 -1
  24. package/lib/event/events/IMouseEventInit.d.ts +2 -0
  25. package/lib/event/events/IMouseEventInit.d.ts.map +1 -1
  26. package/lib/event/events/MouseEvent.d.ts.map +1 -1
  27. package/lib/event/events/MouseEvent.js +2 -0
  28. package/lib/event/events/MouseEvent.js.map +1 -1
  29. package/package.json +1 -1
  30. package/src/css/CSSParser.ts +4 -1
  31. package/src/css/declaration/css-parser/CSSStyleDeclarationCSSParser.ts +11 -17
  32. package/src/css/declaration/property-manager/CSSStyleDeclarationPropertySetParser.ts +6 -5
  33. package/src/event/events/IMouseEventInit.ts +2 -0
  34. package/src/event/events/MouseEvent.ts +2 -0
@@ -1,3 +1,10 @@
1
+ // PropName => \s*([^:;]+?)\s*:
2
+ // PropValue => \s*((?:[^(;]*?(?:\([^)]*\))?)*?) <- will match any non ';' char except inside (), nested parentheses are not supported
3
+ // !important => \s*(!important)?
4
+ // EndOfRule => \s*(?:$|;)
5
+ const SPLIT_RULES_REGEXP =
6
+ /\s*([^:;]+?)\s*:\s*((?:[^(;]*?(?:\([^)]*\))?)*?)\s*(!important)?\s*(?:$|;)/g;
7
+
1
8
  /**
2
9
  * CSS parser.
3
10
  */
@@ -12,23 +19,10 @@ export default class CSSStyleDeclarationCSSParser {
12
19
  cssText: string,
13
20
  callback: (name: string, value: string, important: boolean) => void
14
21
  ): void {
15
- const parts = cssText.split(';');
16
-
17
- for (const part of parts) {
18
- if (part) {
19
- const [name, value]: string[] = part.trim().split(':');
20
- if (value) {
21
- const trimmedName = name.trim();
22
- const trimmedValue = value.trim();
23
- if (trimmedName && trimmedValue) {
24
- const important = trimmedValue.endsWith(' !important');
25
- const valueWithoutImportant = trimmedValue.replace(' !important', '');
26
-
27
- if (valueWithoutImportant) {
28
- callback(trimmedName, valueWithoutImportant, important);
29
- }
30
- }
31
- }
22
+ const rules = Array.from(cssText.matchAll(SPLIT_RULES_REGEXP));
23
+ for (const [, key, value, important] of rules) {
24
+ if (key && value) {
25
+ callback(key.trim(), value.trim(), !!important);
32
26
  }
33
27
  }
34
28
  }
@@ -2,6 +2,7 @@ import CSSStyleDeclarationValueParser from './CSSStyleDeclarationValueParser.js'
2
2
  import ICSSStyleDeclarationPropertyValue from './ICSSStyleDeclarationPropertyValue.js';
3
3
 
4
4
  const RECT_REGEXP = /^rect\((.*)\)$/i;
5
+ const SPLIT_PARTS_REGEXP = /,(?=(?:(?:(?!\))[\s\S])*\()|[^\(\)]*$)/; // Split on commas that are outside of parentheses
5
6
  const BORDER_STYLE = [
6
7
  'none',
7
8
  'hidden',
@@ -2383,7 +2384,7 @@ export default class CSSStyleDeclarationPropertySetParser {
2383
2384
  return { 'background-size': { value: lowerValue, important } };
2384
2385
  }
2385
2386
 
2386
- const imageParts = lowerValue.split(',');
2387
+ const imageParts = lowerValue.split(SPLIT_PARTS_REGEXP);
2387
2388
  const parsed = [];
2388
2389
 
2389
2390
  for (const imagePart of imageParts) {
@@ -2554,7 +2555,7 @@ export default class CSSStyleDeclarationPropertySetParser {
2554
2555
  };
2555
2556
  }
2556
2557
 
2557
- const imageParts = value.replace(/ *, */g, ',').split(',');
2558
+ const imageParts = value.split(SPLIT_PARTS_REGEXP);
2558
2559
  let x = '';
2559
2560
  let y = '';
2560
2561
 
@@ -2667,7 +2668,7 @@ export default class CSSStyleDeclarationPropertySetParser {
2667
2668
  return { 'background-position-x': { value: lowerValue, important } };
2668
2669
  }
2669
2670
 
2670
- const imageParts = lowerValue.replace(/ *, */g, ',').split(',');
2671
+ const imageParts = lowerValue.split(SPLIT_PARTS_REGEXP);
2671
2672
  let parsedValue = '';
2672
2673
 
2673
2674
  for (const imagePart of imageParts) {
@@ -2718,7 +2719,7 @@ export default class CSSStyleDeclarationPropertySetParser {
2718
2719
  return { 'background-position-y': { value: lowerValue, important } };
2719
2720
  }
2720
2721
 
2721
- const imageParts = lowerValue.replace(/ *, */g, ',').split(',');
2722
+ const imageParts = lowerValue.split(SPLIT_PARTS_REGEXP);
2722
2723
  let parsedValue = '';
2723
2724
 
2724
2725
  for (const imagePart of imageParts) {
@@ -2794,7 +2795,7 @@ export default class CSSStyleDeclarationPropertySetParser {
2794
2795
  return { 'background-image': { value: lowerValue, important } };
2795
2796
  }
2796
2797
 
2797
- const parts = value.replace(/ *, */g, ',').split(',');
2798
+ const parts = value.split(SPLIT_PARTS_REGEXP);
2798
2799
  const parsed = [];
2799
2800
 
2800
2801
  for (const part of parts) {
@@ -10,6 +10,8 @@ export default interface IMouseEventInit extends IUIEventInit {
10
10
  shiftKey?: boolean;
11
11
  altKey?: boolean;
12
12
  metaKey?: boolean;
13
+ movementX?: number;
14
+ movementY?: number;
13
15
  button?: number;
14
16
  buttons?: number;
15
17
  relatedTarget?: EventTarget;
@@ -40,6 +40,8 @@ export default class MouseEvent extends UIEvent {
40
40
  this.clientY = eventInit.clientY !== undefined ? eventInit.clientY : 0;
41
41
  this.ctrlKey = eventInit.ctrlKey || false;
42
42
  this.metaKey = eventInit.metaKey || false;
43
+ this.movementX = eventInit.movementX || 0;
44
+ this.movementY = eventInit.movementY || 0;
43
45
  this.region = eventInit.region || '';
44
46
  this.relatedTarget = eventInit.relatedTarget || null;
45
47
  this.screenX = eventInit.screenX !== undefined ? eventInit.screenX : 0;