happy-dom 17.1.0 → 17.1.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.
Files changed (176) hide show
  1. package/cjs/PropertySymbol.cjs +2 -1
  2. package/cjs/PropertySymbol.cjs.map +1 -1
  3. package/cjs/PropertySymbol.d.ts +1 -0
  4. package/cjs/PropertySymbol.d.ts.map +1 -1
  5. package/cjs/browser/DefaultBrowserSettings.cjs +2 -1
  6. package/cjs/browser/DefaultBrowserSettings.cjs.map +1 -1
  7. package/cjs/browser/DefaultBrowserSettings.d.ts.map +1 -1
  8. package/cjs/browser/types/IBrowserSettings.d.ts +1 -0
  9. package/cjs/browser/types/IBrowserSettings.d.ts.map +1 -1
  10. package/cjs/browser/types/IOptionalBrowserSettings.d.ts +1 -0
  11. package/cjs/browser/types/IOptionalBrowserSettings.d.ts.map +1 -1
  12. package/cjs/browser/utilities/BrowserFrameNavigator.cjs +2 -1
  13. package/cjs/browser/utilities/BrowserFrameNavigator.cjs.map +1 -1
  14. package/cjs/browser/utilities/BrowserFrameNavigator.d.ts.map +1 -1
  15. package/cjs/css/CSSRule.cjs.map +1 -1
  16. package/cjs/css/CSSRule.d.ts +1 -1
  17. package/cjs/css/CSSRule.d.ts.map +1 -1
  18. package/cjs/css/CSSStyleSheet.cjs +16 -7
  19. package/cjs/css/CSSStyleSheet.cjs.map +1 -1
  20. package/cjs/css/CSSStyleSheet.d.ts.map +1 -1
  21. package/cjs/css/rules/CSSContainerRule.cjs +2 -1
  22. package/cjs/css/rules/CSSContainerRule.cjs.map +1 -1
  23. package/cjs/css/rules/CSSContainerRule.d.ts +2 -1
  24. package/cjs/css/rules/CSSContainerRule.d.ts.map +1 -1
  25. package/cjs/css/rules/CSSFontFaceRule.cjs +2 -1
  26. package/cjs/css/rules/CSSFontFaceRule.cjs.map +1 -1
  27. package/cjs/css/rules/CSSFontFaceRule.d.ts +2 -1
  28. package/cjs/css/rules/CSSFontFaceRule.d.ts.map +1 -1
  29. package/cjs/css/rules/CSSKeyframeRule.cjs +2 -1
  30. package/cjs/css/rules/CSSKeyframeRule.cjs.map +1 -1
  31. package/cjs/css/rules/CSSKeyframeRule.d.ts +2 -1
  32. package/cjs/css/rules/CSSKeyframeRule.d.ts.map +1 -1
  33. package/cjs/css/rules/CSSKeyframesRule.cjs +2 -1
  34. package/cjs/css/rules/CSSKeyframesRule.cjs.map +1 -1
  35. package/cjs/css/rules/CSSKeyframesRule.d.ts +2 -1
  36. package/cjs/css/rules/CSSKeyframesRule.d.ts.map +1 -1
  37. package/cjs/css/rules/CSSMediaRule.cjs +2 -1
  38. package/cjs/css/rules/CSSMediaRule.cjs.map +1 -1
  39. package/cjs/css/rules/CSSMediaRule.d.ts +2 -1
  40. package/cjs/css/rules/CSSMediaRule.d.ts.map +1 -1
  41. package/cjs/css/rules/CSSStyleRule.cjs +2 -1
  42. package/cjs/css/rules/CSSStyleRule.cjs.map +1 -1
  43. package/cjs/css/rules/CSSStyleRule.d.ts +2 -1
  44. package/cjs/css/rules/CSSStyleRule.d.ts.map +1 -1
  45. package/cjs/css/rules/CSSSupportsRule.cjs +2 -1
  46. package/cjs/css/rules/CSSSupportsRule.cjs.map +1 -1
  47. package/cjs/css/rules/CSSSupportsRule.d.ts +2 -1
  48. package/cjs/css/rules/CSSSupportsRule.d.ts.map +1 -1
  49. package/cjs/css/utilities/CSSParser.cjs +106 -56
  50. package/cjs/css/utilities/CSSParser.cjs.map +1 -1
  51. package/cjs/css/utilities/CSSParser.d.ts.map +1 -1
  52. package/cjs/fetch/AbortController.cjs.map +1 -1
  53. package/cjs/fetch/AbortController.d.ts +1 -1
  54. package/cjs/fetch/AbortController.d.ts.map +1 -1
  55. package/cjs/fetch/AbortSignal.cjs +49 -15
  56. package/cjs/fetch/AbortSignal.cjs.map +1 -1
  57. package/cjs/fetch/AbortSignal.d.ts +28 -4
  58. package/cjs/fetch/AbortSignal.d.ts.map +1 -1
  59. package/cjs/fetch/Fetch.cjs +8 -5
  60. package/cjs/fetch/Fetch.cjs.map +1 -1
  61. package/cjs/fetch/Fetch.d.ts.map +1 -1
  62. package/cjs/fetch/SyncFetch.cjs +5 -2
  63. package/cjs/fetch/SyncFetch.cjs.map +1 -1
  64. package/cjs/fetch/SyncFetch.d.ts.map +1 -1
  65. package/cjs/match-media/MediaQueryItem.cjs +5 -0
  66. package/cjs/match-media/MediaQueryItem.cjs.map +1 -1
  67. package/cjs/match-media/MediaQueryItem.d.ts.map +1 -1
  68. package/cjs/nodes/html-link-element/HTMLLinkElement.cjs +1 -2
  69. package/cjs/nodes/html-link-element/HTMLLinkElement.cjs.map +1 -1
  70. package/cjs/nodes/html-link-element/HTMLLinkElement.d.ts.map +1 -1
  71. package/cjs/nodes/html-style-element/HTMLStyleElement.cjs +1 -2
  72. package/cjs/nodes/html-style-element/HTMLStyleElement.cjs.map +1 -1
  73. package/cjs/nodes/html-style-element/HTMLStyleElement.d.ts.map +1 -1
  74. package/cjs/nodes/svg-style-element/SVGStyleElement.cjs +1 -2
  75. package/cjs/nodes/svg-style-element/SVGStyleElement.cjs.map +1 -1
  76. package/cjs/nodes/svg-style-element/SVGStyleElement.d.ts.map +1 -1
  77. package/lib/PropertySymbol.d.ts +1 -0
  78. package/lib/PropertySymbol.d.ts.map +1 -1
  79. package/lib/PropertySymbol.js +1 -0
  80. package/lib/PropertySymbol.js.map +1 -1
  81. package/lib/browser/DefaultBrowserSettings.d.ts.map +1 -1
  82. package/lib/browser/DefaultBrowserSettings.js +2 -1
  83. package/lib/browser/DefaultBrowserSettings.js.map +1 -1
  84. package/lib/browser/types/IBrowserSettings.d.ts +1 -0
  85. package/lib/browser/types/IBrowserSettings.d.ts.map +1 -1
  86. package/lib/browser/types/IOptionalBrowserSettings.d.ts +1 -0
  87. package/lib/browser/types/IOptionalBrowserSettings.d.ts.map +1 -1
  88. package/lib/browser/utilities/BrowserFrameNavigator.d.ts.map +1 -1
  89. package/lib/browser/utilities/BrowserFrameNavigator.js +2 -1
  90. package/lib/browser/utilities/BrowserFrameNavigator.js.map +1 -1
  91. package/lib/css/CSSRule.d.ts +1 -1
  92. package/lib/css/CSSRule.d.ts.map +1 -1
  93. package/lib/css/CSSRule.js.map +1 -1
  94. package/lib/css/CSSStyleSheet.d.ts.map +1 -1
  95. package/lib/css/CSSStyleSheet.js +16 -7
  96. package/lib/css/CSSStyleSheet.js.map +1 -1
  97. package/lib/css/rules/CSSContainerRule.d.ts +2 -1
  98. package/lib/css/rules/CSSContainerRule.d.ts.map +1 -1
  99. package/lib/css/rules/CSSContainerRule.js +2 -1
  100. package/lib/css/rules/CSSContainerRule.js.map +1 -1
  101. package/lib/css/rules/CSSFontFaceRule.d.ts +2 -1
  102. package/lib/css/rules/CSSFontFaceRule.d.ts.map +1 -1
  103. package/lib/css/rules/CSSFontFaceRule.js +2 -1
  104. package/lib/css/rules/CSSFontFaceRule.js.map +1 -1
  105. package/lib/css/rules/CSSKeyframeRule.d.ts +2 -1
  106. package/lib/css/rules/CSSKeyframeRule.d.ts.map +1 -1
  107. package/lib/css/rules/CSSKeyframeRule.js +2 -1
  108. package/lib/css/rules/CSSKeyframeRule.js.map +1 -1
  109. package/lib/css/rules/CSSKeyframesRule.d.ts +2 -1
  110. package/lib/css/rules/CSSKeyframesRule.d.ts.map +1 -1
  111. package/lib/css/rules/CSSKeyframesRule.js +2 -1
  112. package/lib/css/rules/CSSKeyframesRule.js.map +1 -1
  113. package/lib/css/rules/CSSMediaRule.d.ts +2 -1
  114. package/lib/css/rules/CSSMediaRule.d.ts.map +1 -1
  115. package/lib/css/rules/CSSMediaRule.js +2 -1
  116. package/lib/css/rules/CSSMediaRule.js.map +1 -1
  117. package/lib/css/rules/CSSStyleRule.d.ts +2 -1
  118. package/lib/css/rules/CSSStyleRule.d.ts.map +1 -1
  119. package/lib/css/rules/CSSStyleRule.js +2 -1
  120. package/lib/css/rules/CSSStyleRule.js.map +1 -1
  121. package/lib/css/rules/CSSSupportsRule.d.ts +2 -1
  122. package/lib/css/rules/CSSSupportsRule.d.ts.map +1 -1
  123. package/lib/css/rules/CSSSupportsRule.js +2 -1
  124. package/lib/css/rules/CSSSupportsRule.js.map +1 -1
  125. package/lib/css/utilities/CSSParser.d.ts.map +1 -1
  126. package/lib/css/utilities/CSSParser.js +106 -56
  127. package/lib/css/utilities/CSSParser.js.map +1 -1
  128. package/lib/fetch/AbortController.d.ts +1 -1
  129. package/lib/fetch/AbortController.d.ts.map +1 -1
  130. package/lib/fetch/AbortController.js.map +1 -1
  131. package/lib/fetch/AbortSignal.d.ts +28 -4
  132. package/lib/fetch/AbortSignal.d.ts.map +1 -1
  133. package/lib/fetch/AbortSignal.js +49 -15
  134. package/lib/fetch/AbortSignal.js.map +1 -1
  135. package/lib/fetch/Fetch.d.ts.map +1 -1
  136. package/lib/fetch/Fetch.js +8 -5
  137. package/lib/fetch/Fetch.js.map +1 -1
  138. package/lib/fetch/SyncFetch.d.ts.map +1 -1
  139. package/lib/fetch/SyncFetch.js +5 -2
  140. package/lib/fetch/SyncFetch.js.map +1 -1
  141. package/lib/match-media/MediaQueryItem.d.ts.map +1 -1
  142. package/lib/match-media/MediaQueryItem.js +5 -0
  143. package/lib/match-media/MediaQueryItem.js.map +1 -1
  144. package/lib/nodes/html-link-element/HTMLLinkElement.d.ts.map +1 -1
  145. package/lib/nodes/html-link-element/HTMLLinkElement.js +1 -2
  146. package/lib/nodes/html-link-element/HTMLLinkElement.js.map +1 -1
  147. package/lib/nodes/html-style-element/HTMLStyleElement.d.ts.map +1 -1
  148. package/lib/nodes/html-style-element/HTMLStyleElement.js +1 -2
  149. package/lib/nodes/html-style-element/HTMLStyleElement.js.map +1 -1
  150. package/lib/nodes/svg-style-element/SVGStyleElement.d.ts.map +1 -1
  151. package/lib/nodes/svg-style-element/SVGStyleElement.js +1 -2
  152. package/lib/nodes/svg-style-element/SVGStyleElement.js.map +1 -1
  153. package/package.json +1 -1
  154. package/src/PropertySymbol.ts +1 -0
  155. package/src/browser/DefaultBrowserSettings.ts +2 -1
  156. package/src/browser/types/IBrowserSettings.ts +1 -0
  157. package/src/browser/types/IOptionalBrowserSettings.ts +1 -0
  158. package/src/browser/utilities/BrowserFrameNavigator.ts +8 -1
  159. package/src/css/CSSRule.ts +1 -1
  160. package/src/css/CSSStyleSheet.ts +26 -10
  161. package/src/css/rules/CSSContainerRule.ts +2 -1
  162. package/src/css/rules/CSSFontFaceRule.ts +2 -1
  163. package/src/css/rules/CSSKeyframeRule.ts +2 -1
  164. package/src/css/rules/CSSKeyframesRule.ts +2 -1
  165. package/src/css/rules/CSSMediaRule.ts +2 -1
  166. package/src/css/rules/CSSStyleRule.ts +2 -1
  167. package/src/css/rules/CSSSupportsRule.ts +2 -1
  168. package/src/css/utilities/CSSParser.ts +121 -64
  169. package/src/fetch/AbortController.ts +1 -1
  170. package/src/fetch/AbortSignal.ts +61 -25
  171. package/src/fetch/Fetch.ts +10 -7
  172. package/src/fetch/SyncFetch.ts +6 -3
  173. package/src/match-media/MediaQueryItem.ts +7 -0
  174. package/src/nodes/html-link-element/HTMLLinkElement.ts +3 -1
  175. package/src/nodes/html-style-element/HTMLStyleElement.ts +3 -1
  176. package/src/nodes/svg-style-element/SVGStyleElement.ts +3 -1
@@ -57,18 +57,17 @@ export default class CSSStyleSheet {
57
57
  * @returns The newly inserterted rule's index.
58
58
  */
59
59
  public insertRule(rule: string, index?: number): number {
60
- const rules = CSSParser.parseFromString(this, rule);
61
-
62
- if (rules.length === 0) {
63
- throw new this[PropertySymbol.window].DOMException(
64
- 'Invalid CSS rule.',
65
- DOMExceptionNameEnum.hierarchyRequestError
60
+ if (arguments.length === 0) {
61
+ throw new this[PropertySymbol.window].TypeError(
62
+ `Failed to execute 'insertRule' on 'CSSStyleSheet': 1 argument required, but only 0 present.`
66
63
  );
67
64
  }
68
65
 
69
- if (rules.length > 1) {
66
+ const rules = CSSParser.parseFromString(this, rule);
67
+
68
+ if (rules.length === 0 || rules.length > 1) {
70
69
  throw new this[PropertySymbol.window].DOMException(
71
- 'Only one rule is allowed to be added.',
70
+ `Failed to execute 'insertRule' on 'CSSStyleSheet': Failed to parse the rule '${rule}'.`,
72
71
  DOMExceptionNameEnum.syntaxError
73
72
  );
74
73
  }
@@ -76,7 +75,9 @@ export default class CSSStyleSheet {
76
75
  if (index !== undefined) {
77
76
  if (index > this.cssRules.length) {
78
77
  throw new this[PropertySymbol.window].DOMException(
79
- 'Index is more than the length of CSSRuleList.',
78
+ `Failed to execute 'insertRule' on 'CSSStyleSheet': The index provided (${index}) is larger than the maximum index (${
79
+ this.cssRules.length - 1
80
+ }).`,
80
81
  DOMExceptionNameEnum.indexSizeError
81
82
  );
82
83
  }
@@ -98,7 +99,12 @@ export default class CSSStyleSheet {
98
99
  * @param index Index.
99
100
  */
100
101
  public deleteRule(index: number): void {
101
- delete this.cssRules[index];
102
+ if (arguments.length === 0) {
103
+ throw new this[PropertySymbol.window].TypeError(
104
+ `Failed to execute 'deleteRule' on 'CSSStyleSheet': 1 argument required, but only 0 present.`
105
+ );
106
+ }
107
+ this.cssRules.splice(index, 1);
102
108
  }
103
109
 
104
110
  /**
@@ -109,6 +115,11 @@ export default class CSSStyleSheet {
109
115
  * @returns Promise.
110
116
  */
111
117
  public async replace(text: string): Promise<void> {
118
+ if (arguments.length === 0) {
119
+ throw new this[PropertySymbol.window].TypeError(
120
+ `Failed to execute 'replace' on 'CSSStyleSheet': 1 argument required, but only 0 present.`
121
+ );
122
+ }
112
123
  this.replaceSync(text);
113
124
  }
114
125
 
@@ -119,6 +130,11 @@ export default class CSSStyleSheet {
119
130
  * @param text CSS text.
120
131
  */
121
132
  public replaceSync(text: string): void {
133
+ if (arguments.length === 0) {
134
+ throw new this[PropertySymbol.window].TypeError(
135
+ `Failed to execute 'replaceSync' on 'CSSStyleSheet': 1 argument required, but only 0 present.`
136
+ );
137
+ }
122
138
  if (this.#currentText !== text) {
123
139
  this.#currentText = text;
124
140
  (<CSSRule[]>this.cssRules) = CSSParser.parseFromString(this, text);
@@ -1,10 +1,11 @@
1
1
  import CSSRule from '../CSSRule.js';
2
+ import CSSRuleTypeEnum from '../CSSRuleTypeEnum.js';
2
3
 
3
4
  /**
4
5
  * CSSRule interface.
5
6
  */
6
7
  export default class CSSContainerRule extends CSSRule {
7
- public readonly type = CSSRule.CONTAINER_RULE;
8
+ public readonly type = CSSRuleTypeEnum.containerRule;
8
9
  public readonly cssRules: CSSRule[] = [];
9
10
  public readonly conditionText = '';
10
11
 
@@ -1,12 +1,13 @@
1
1
  import CSSRule from '../CSSRule.js';
2
2
  import * as PropertySymbol from '../../PropertySymbol.js';
3
3
  import CSSStyleDeclaration from '../declaration/CSSStyleDeclaration.js';
4
+ import CSSRuleTypeEnum from '../CSSRuleTypeEnum.js';
4
5
 
5
6
  /**
6
7
  * CSSRule interface.
7
8
  */
8
9
  export default class CSSFontFaceRule extends CSSRule {
9
- public readonly type = CSSRule.FONT_FACE_RULE;
10
+ public readonly type = CSSRuleTypeEnum.fontFaceRule;
10
11
  public [PropertySymbol.cssText] = '';
11
12
  #style: CSSStyleDeclaration | null = null;
12
13
 
@@ -1,12 +1,13 @@
1
1
  import CSSRule from '../CSSRule.js';
2
2
  import * as PropertySymbol from '../../PropertySymbol.js';
3
3
  import CSSStyleDeclaration from '../declaration/CSSStyleDeclaration.js';
4
+ import CSSRuleTypeEnum from '../CSSRuleTypeEnum.js';
4
5
 
5
6
  /**
6
7
  * CSSRule interface.
7
8
  */
8
9
  export default class CSSKeyframeRule extends CSSRule {
9
- public readonly type = CSSRule.KEYFRAME_RULE;
10
+ public readonly type = CSSRuleTypeEnum.keyframeRule;
10
11
  public readonly keyText: string;
11
12
  public [PropertySymbol.cssText] = '';
12
13
  #style: CSSStyleDeclaration | null = null;
@@ -2,6 +2,7 @@ import CSSRule from '../CSSRule.js';
2
2
  import CSSStyleDeclaration from '../declaration/CSSStyleDeclaration.js';
3
3
  import CSSKeyframeRule from './CSSKeyframeRule.js';
4
4
  import * as PropertySymbol from '../../PropertySymbol.js';
5
+ import CSSRuleTypeEnum from '../CSSRuleTypeEnum.js';
5
6
 
6
7
  const CSS_RULE_REGEXP = /([^{]+){([^}]+)}/;
7
8
 
@@ -9,7 +10,7 @@ const CSS_RULE_REGEXP = /([^{]+){([^}]+)}/;
9
10
  * CSSRule interface.
10
11
  */
11
12
  export default class CSSKeyframesRule extends CSSRule {
12
- public readonly type = CSSRule.KEYFRAMES_RULE;
13
+ public readonly type = CSSRuleTypeEnum.keyframesRule;
13
14
  public readonly cssRules: CSSKeyframeRule[] = [];
14
15
  public readonly name: string = null;
15
16
 
@@ -1,11 +1,12 @@
1
1
  import CSSRule from '../CSSRule.js';
2
+ import CSSRuleTypeEnum from '../CSSRuleTypeEnum.js';
2
3
  import MediaList from '../MediaList.js';
3
4
 
4
5
  /**
5
6
  * CSSRule interface.
6
7
  */
7
8
  export default class CSSMediaRule extends CSSRule {
8
- public readonly type = CSSRule.MEDIA_RULE;
9
+ public readonly type = CSSRuleTypeEnum.mediaRule;
9
10
  public readonly cssRules: CSSRule[] = [];
10
11
  public readonly media = new MediaList();
11
12
 
@@ -1,12 +1,13 @@
1
1
  import CSSRule from '../CSSRule.js';
2
2
  import * as PropertySymbol from '../../PropertySymbol.js';
3
3
  import CSSStyleDeclaration from '../declaration/CSSStyleDeclaration.js';
4
+ import CSSRuleTypeEnum from '../CSSRuleTypeEnum.js';
4
5
 
5
6
  /**
6
7
  * CSSRule interface.
7
8
  */
8
9
  export default class CSSStyleRule extends CSSRule {
9
- public readonly type = CSSRule.STYLE_RULE;
10
+ public readonly type = CSSRuleTypeEnum.styleRule;
10
11
  public readonly styleMap = new Map();
11
12
  public selectorText = '';
12
13
  public [PropertySymbol.cssText] = '';
@@ -1,10 +1,11 @@
1
1
  import CSSRule from '../CSSRule.js';
2
+ import CSSRuleTypeEnum from '../CSSRuleTypeEnum.js';
2
3
 
3
4
  /**
4
5
  * CSSRule interface.
5
6
  */
6
7
  export default class CSSSupportsRule extends CSSRule {
7
- public readonly type = CSSRule.SUPPORTS_RULE;
8
+ public readonly type = CSSRuleTypeEnum.supportsRule;
8
9
  public readonly cssRules: CSSRule[] = [];
9
10
  public readonly conditionText = '';
10
11
 
@@ -9,6 +9,7 @@ import CSSContainerRule from '../rules/CSSContainerRule.js';
9
9
  import CSSSupportsRule from '../rules/CSSSupportsRule.js';
10
10
  import CSSFontFaceRule from '../rules/CSSFontFaceRule.js';
11
11
  import SelectorParser from '../../query-selector/SelectorParser.js';
12
+ import CSSRuleTypeEnum from '../CSSRuleTypeEnum.js';
12
13
 
13
14
  const COMMENT_REGEXP = /\/\*[\s\S]*?\*\//gm;
14
15
 
@@ -29,7 +30,7 @@ export default class CSSParser {
29
30
  const cssRules = [];
30
31
  const regExp = /{|}/gm;
31
32
  const stack: CSSRule[] = [];
32
- let parentRule: CSSRule = null;
33
+ let parentRule: CSSRule | null = null;
33
34
  let lastIndex = 0;
34
35
  let match: RegExpMatchArray;
35
36
 
@@ -37,64 +38,120 @@ export default class CSSParser {
37
38
  if (match[0] === '{') {
38
39
  const selectorText = css.substring(lastIndex, match.index).trim();
39
40
 
40
- if (
41
- selectorText.startsWith('@keyframes') ||
42
- selectorText.startsWith('@-webkit-keyframes')
43
- ) {
44
- const newRule = new CSSKeyframesRule(PropertySymbol.illegalConstructor, window);
45
-
46
- (<string>newRule.name) = selectorText.replace(/@(-webkit-){0,1}keyframes +/, '');
47
- newRule.parentStyleSheet = parentStyleSheet;
48
- cssRules.push(newRule);
49
- parentRule = newRule;
50
- } else if (selectorText.startsWith('@media')) {
51
- const mediums = selectorText.replace('@media', '').split(',');
52
- const newRule = new CSSMediaRule(PropertySymbol.illegalConstructor, window);
53
-
54
- for (const medium of mediums) {
55
- newRule.media.appendMedium(medium.trim());
41
+ if (selectorText[0] === '@') {
42
+ const ruleParts = selectorText.split(' ');
43
+ const ruleType = ruleParts[0];
44
+ const ruleParameters = ruleParts.slice(1).join(' ').trim();
45
+
46
+ switch (ruleType) {
47
+ case '@keyframes':
48
+ case '@-webkit-keyframes':
49
+ const keyframesRule = new CSSKeyframesRule(PropertySymbol.illegalConstructor, window);
50
+
51
+ (<string>keyframesRule.name) = ruleParameters;
52
+ keyframesRule.parentStyleSheet = parentStyleSheet;
53
+ if (parentRule) {
54
+ if (
55
+ parentRule.type === CSSRuleTypeEnum.mediaRule ||
56
+ parentRule.type === CSSRuleTypeEnum.containerRule ||
57
+ parentRule.type === CSSRuleTypeEnum.supportsRule
58
+ ) {
59
+ (<CSSMediaRule>parentRule).cssRules.push(keyframesRule);
60
+ }
61
+ } else {
62
+ cssRules.push(keyframesRule);
63
+ }
64
+ parentRule = keyframesRule;
65
+ break;
66
+ case '@media':
67
+ const mediums = ruleParameters.split(',');
68
+ const mediaRule = new CSSMediaRule(PropertySymbol.illegalConstructor, window);
69
+
70
+ for (const medium of mediums) {
71
+ mediaRule.media.appendMedium(medium.trim());
72
+ }
73
+
74
+ mediaRule.parentStyleSheet = parentStyleSheet;
75
+ if (parentRule) {
76
+ if (
77
+ parentRule.type === CSSRuleTypeEnum.mediaRule ||
78
+ parentRule.type === CSSRuleTypeEnum.containerRule ||
79
+ parentRule.type === CSSRuleTypeEnum.supportsRule
80
+ ) {
81
+ (<CSSMediaRule>parentRule).cssRules.push(mediaRule);
82
+ }
83
+ } else {
84
+ cssRules.push(mediaRule);
85
+ }
86
+ parentRule = mediaRule;
87
+ break;
88
+ case '@container':
89
+ case '@-webkit-container':
90
+ const containerRule = new CSSContainerRule(PropertySymbol.illegalConstructor, window);
91
+
92
+ (<string>containerRule.conditionText) = ruleParameters;
93
+ containerRule.parentStyleSheet = parentStyleSheet;
94
+
95
+ if (parentRule) {
96
+ if (
97
+ parentRule.type === CSSRuleTypeEnum.mediaRule ||
98
+ parentRule.type === CSSRuleTypeEnum.containerRule ||
99
+ parentRule.type === CSSRuleTypeEnum.supportsRule
100
+ ) {
101
+ (<CSSMediaRule>parentRule).cssRules.push(containerRule);
102
+ }
103
+ } else {
104
+ cssRules.push(containerRule);
105
+ }
106
+
107
+ parentRule = containerRule;
108
+ break;
109
+ case '@supports':
110
+ case '@-webkit-supports':
111
+ const supportsRule = new CSSSupportsRule(PropertySymbol.illegalConstructor, window);
112
+
113
+ (<string>supportsRule.conditionText) = ruleParameters;
114
+ supportsRule.parentStyleSheet = parentStyleSheet;
115
+ if (parentRule) {
116
+ if (
117
+ parentRule.type === CSSRuleTypeEnum.mediaRule ||
118
+ parentRule.type === CSSRuleTypeEnum.containerRule ||
119
+ parentRule.type === CSSRuleTypeEnum.supportsRule
120
+ ) {
121
+ (<CSSMediaRule>parentRule).cssRules.push(supportsRule);
122
+ }
123
+ } else {
124
+ cssRules.push(supportsRule);
125
+ }
126
+ parentRule = supportsRule;
127
+ break;
128
+ case '@font-face':
129
+ const fontFaceRule = new CSSFontFaceRule(PropertySymbol.illegalConstructor, window);
130
+
131
+ fontFaceRule[PropertySymbol.cssText] = ruleParameters;
132
+ fontFaceRule.parentStyleSheet = parentStyleSheet;
133
+ if (parentRule) {
134
+ if (
135
+ parentRule.type === CSSRuleTypeEnum.mediaRule ||
136
+ parentRule.type === CSSRuleTypeEnum.containerRule ||
137
+ parentRule.type === CSSRuleTypeEnum.supportsRule
138
+ ) {
139
+ (<CSSMediaRule>parentRule).cssRules.push(fontFaceRule);
140
+ }
141
+ } else {
142
+ cssRules.push(fontFaceRule);
143
+ }
144
+ parentRule = fontFaceRule;
145
+ break;
146
+ default:
147
+ // Unknown rule.
148
+ // We will create a new rule to let it grab its content, but we will not add it to the cssRules array.
149
+ const newRule = new CSSRule(PropertySymbol.illegalConstructor, window);
150
+ newRule.parentStyleSheet = parentStyleSheet;
151
+ parentRule = newRule;
152
+ break;
56
153
  }
57
-
58
- newRule.parentStyleSheet = parentStyleSheet;
59
- cssRules.push(newRule);
60
- parentRule = newRule;
61
- } else if (
62
- selectorText.startsWith('@container') ||
63
- selectorText.startsWith('@-webkit-container')
64
- ) {
65
- const conditionText = selectorText.replace(/@(-webkit-){0,1}container +/, '');
66
- const newRule = new CSSContainerRule(PropertySymbol.illegalConstructor, window);
67
-
68
- (<string>newRule.conditionText) = conditionText;
69
- newRule.parentStyleSheet = parentStyleSheet;
70
- cssRules.push(newRule);
71
- parentRule = newRule;
72
- } else if (
73
- selectorText.startsWith('@supports') ||
74
- selectorText.startsWith('@-webkit-supports')
75
- ) {
76
- const conditionText = selectorText.replace(/@(-webkit-){0,1}supports +/, '');
77
- const newRule = new CSSSupportsRule(PropertySymbol.illegalConstructor, window);
78
-
79
- (<string>newRule.conditionText) = conditionText;
80
- newRule.parentStyleSheet = parentStyleSheet;
81
- cssRules.push(newRule);
82
- parentRule = newRule;
83
- } else if (selectorText.startsWith('@font-face')) {
84
- const conditionText = selectorText.replace('@font-face', '');
85
- const newRule = new CSSFontFaceRule(PropertySymbol.illegalConstructor, window);
86
-
87
- newRule[PropertySymbol.cssText] = conditionText;
88
- newRule.parentStyleSheet = parentStyleSheet;
89
- cssRules.push(newRule);
90
- parentRule = newRule;
91
- } else if (selectorText[0] === '@') {
92
- // Unknown rule.
93
- // We will create a new rule to let it grab its content, but we will not add it to the cssRules array.
94
- const newRule = new CSSRule(PropertySymbol.illegalConstructor, window);
95
- newRule.parentStyleSheet = parentStyleSheet;
96
- parentRule = newRule;
97
- } else if (parentRule && parentRule.type === CSSRule.KEYFRAMES_RULE) {
154
+ } else if (parentRule && parentRule.type === CSSRuleTypeEnum.keyframesRule) {
98
155
  const newRule = new CSSKeyframeRule(PropertySymbol.illegalConstructor, window);
99
156
  (<string>newRule.keyText) = selectorText.trim();
100
157
  newRule.parentStyleSheet = parentStyleSheet;
@@ -104,9 +161,9 @@ export default class CSSParser {
104
161
  parentRule = newRule;
105
162
  } else if (
106
163
  parentRule &&
107
- (parentRule.type === CSSRule.MEDIA_RULE ||
108
- parentRule.type === CSSRule.CONTAINER_RULE ||
109
- parentRule.type === CSSRule.SUPPORTS_RULE)
164
+ (parentRule.type === CSSRuleTypeEnum.mediaRule ||
165
+ parentRule.type === CSSRuleTypeEnum.containerRule ||
166
+ parentRule.type === CSSRuleTypeEnum.supportsRule)
110
167
  ) {
111
168
  if (this.validateSelectorText(selectorText)) {
112
169
  const newRule = new CSSStyleRule(PropertySymbol.illegalConstructor, window);
@@ -139,9 +196,9 @@ export default class CSSParser {
139
196
  .trim()
140
197
  .replace(/([^;])$/, '$1;'); // Ensure last semicolon
141
198
  switch (parentRule.type) {
142
- case CSSRule.FONT_FACE_RULE:
143
- case CSSRule.KEYFRAME_RULE:
144
- case CSSRule.STYLE_RULE:
199
+ case CSSRuleTypeEnum.fontFaceRule:
200
+ case CSSRuleTypeEnum.keyframeRule:
201
+ case CSSRuleTypeEnum.styleRule:
145
202
  (<CSSStyleRule>parentRule)[PropertySymbol.cssText] = cssText;
146
203
  break;
147
204
  }
@@ -19,7 +19,7 @@ export default class AbortController {
19
19
  *
20
20
  * @param [reason] Reason.
21
21
  */
22
- public abort(reason?: Error): void {
22
+ public abort(reason?: any): void {
23
23
  this.signal[PropertySymbol.abort](reason);
24
24
  }
25
25
  }
@@ -14,9 +14,9 @@ export default class AbortSignal extends EventTarget {
14
14
  protected declare static [PropertySymbol.window]: BrowserWindow;
15
15
  protected declare [PropertySymbol.window]: BrowserWindow;
16
16
 
17
- // Public properties
18
- public readonly aborted: boolean = false;
19
- public readonly reason: Error | null = null;
17
+ // Internal properties
18
+ public [PropertySymbol.aborted]: boolean = false;
19
+ public [PropertySymbol.reason]: any = undefined;
20
20
 
21
21
  // Events
22
22
  public onabort: ((this: AbortSignal, event: Event) => void) | null = null;
@@ -28,9 +28,7 @@ export default class AbortSignal extends EventTarget {
28
28
  super();
29
29
 
30
30
  if (!this[PropertySymbol.window]) {
31
- throw new TypeError(
32
- `Failed to construct '${this.constructor.name}': '${this.constructor.name}' was constructed outside a Window context.`
33
- );
31
+ throw new TypeError(`Failed to construct 'AbortSignal': Illegal constructor`);
34
32
  }
35
33
  }
36
34
 
@@ -41,22 +39,59 @@ export default class AbortSignal extends EventTarget {
41
39
  return 'AbortSignal';
42
40
  }
43
41
 
42
+ /**
43
+ * Returns true if the signal has been aborted.
44
+ *
45
+ * @returns True if the signal has been aborted.
46
+ */
47
+ public get aborted(): boolean {
48
+ return this[PropertySymbol.aborted];
49
+ }
50
+
51
+ /**
52
+ * Setter for aborted. Value will be ignored as the property is read-only.
53
+ *
54
+ * @param _value Aborted.
55
+ */
56
+ public set aborted(_value: boolean) {
57
+ // Do nothing
58
+ }
59
+
60
+ /**
61
+ * Returns the reason the signal was aborted.
62
+ *
63
+ * @returns Reason.
64
+ */
65
+ public get reason(): any {
66
+ return this[PropertySymbol.reason];
67
+ }
68
+
69
+ /**
70
+ * Setter for reason. Value will be ignored as the property is read-only.
71
+ *
72
+ * @param _value Reason.
73
+ */
74
+ public set reason(_value: any) {
75
+ // Do nothing
76
+ }
77
+
44
78
  /**
45
79
  * Aborts the signal.
46
80
  *
47
81
  * @param [reason] Reason.
48
82
  */
49
- public [PropertySymbol.abort](reason?: Error): void {
83
+ public [PropertySymbol.abort](reason?: any): void {
50
84
  if (this.aborted) {
51
85
  return;
52
86
  }
53
- (<Error>this.reason) =
54
- reason ||
55
- new this[PropertySymbol.window].DOMException(
56
- 'signal is aborted without reason',
57
- DOMExceptionNameEnum.abortError
58
- );
59
- (<boolean>this.aborted) = true;
87
+ this[PropertySymbol.reason] =
88
+ reason !== undefined
89
+ ? reason
90
+ : new this[PropertySymbol.window].DOMException(
91
+ 'signal is aborted without reason',
92
+ DOMExceptionNameEnum.abortError
93
+ );
94
+ this[PropertySymbol.aborted] = true;
60
95
  this.dispatchEvent(new Event('abort'));
61
96
  }
62
97
 
@@ -75,15 +110,16 @@ export default class AbortSignal extends EventTarget {
75
110
  * @param [reason] Reason.
76
111
  * @returns AbortSignal instance.
77
112
  */
78
- public static abort(reason?: Error): AbortSignal {
113
+ public static abort(reason?: any): AbortSignal {
79
114
  const signal = new this();
80
- (<Error>signal.reason) =
81
- reason ||
82
- new this[PropertySymbol.window].DOMException(
83
- 'signal is aborted without reason',
84
- DOMExceptionNameEnum.abortError
85
- );
86
- (<boolean>signal.aborted) = true;
115
+ signal[PropertySymbol.reason] =
116
+ reason !== undefined
117
+ ? reason
118
+ : new this[PropertySymbol.window].DOMException(
119
+ 'signal is aborted without reason',
120
+ DOMExceptionNameEnum.abortError
121
+ );
122
+ signal[PropertySymbol.aborted] = true;
87
123
  return signal;
88
124
  }
89
125
 
@@ -118,8 +154,8 @@ export default class AbortSignal extends EventTarget {
118
154
  */
119
155
  public static any(signals: AbortSignal[]): AbortSignal {
120
156
  for (const signal of signals) {
121
- if (signal.aborted) {
122
- return this.abort(signal.reason);
157
+ if (signal[PropertySymbol.aborted]) {
158
+ return this.abort(signal[PropertySymbol.reason]);
123
159
  }
124
160
  }
125
161
 
@@ -135,7 +171,7 @@ export default class AbortSignal extends EventTarget {
135
171
  for (const signal of signals) {
136
172
  const handler = (): void => {
137
173
  stopListening();
138
- anySignal[PropertySymbol.abort](signal.reason);
174
+ anySignal[PropertySymbol.abort](signal[PropertySymbol.reason]);
139
175
  };
140
176
  handlers.set(signal, handler);
141
177
  signal.addEventListener('abort', handler);
@@ -134,9 +134,12 @@ export default class Fetch {
134
134
 
135
135
  FetchRequestValidationUtility.validateSchema(this.request);
136
136
 
137
- if (this.request.signal.aborted) {
138
- throw new this.#window.DOMException(
139
- 'The operation was aborted.',
137
+ if (this.request.signal[PropertySymbol.aborted]) {
138
+ if (this.request.signal[PropertySymbol.reason] !== undefined) {
139
+ throw this.request.signal[PropertySymbol.reason];
140
+ }
141
+ throw new this[PropertySymbol.window].DOMException(
142
+ 'signal is aborted without reason',
140
143
  DOMExceptionNameEnum.abortError
141
144
  );
142
145
  }
@@ -947,8 +950,8 @@ export default class Fetch {
947
950
  headers.delete('cookie2');
948
951
  }
949
952
 
950
- if (this.request.signal.aborted) {
951
- this.abort();
953
+ if (this.request.signal[PropertySymbol.aborted]) {
954
+ this.abort(this.request.signal[PropertySymbol.reason]);
952
955
  return true;
953
956
  }
954
957
 
@@ -1006,7 +1009,7 @@ export default class Fetch {
1006
1009
  *
1007
1010
  * @param reason Reason.
1008
1011
  */
1009
- private abort(reason?: Error): void {
1012
+ private abort(reason?: any): void {
1010
1013
  const error = new this.#window.DOMException(
1011
1014
  'The operation was aborted.' + (reason ? ' ' + reason.toString() : ''),
1012
1015
  DOMExceptionNameEnum.abortError
@@ -1034,7 +1037,7 @@ export default class Fetch {
1034
1037
  }
1035
1038
 
1036
1039
  if (this.reject) {
1037
- this.reject(error);
1040
+ this.reject(reason !== undefined ? reason : error);
1038
1041
  }
1039
1042
  }
1040
1043
  }
@@ -113,9 +113,12 @@ export default class SyncFetch {
113
113
 
114
114
  FetchRequestValidationUtility.validateSchema(this.request);
115
115
 
116
- if (this.request.signal.aborted) {
117
- throw new this.#window.DOMException(
118
- 'The operation was aborted.',
116
+ if (this.request.signal[PropertySymbol.aborted]) {
117
+ if (this.request.signal[PropertySymbol.reason] !== undefined) {
118
+ throw this.request.signal[PropertySymbol.reason];
119
+ }
120
+ throw new this[PropertySymbol.window].DOMException(
121
+ 'signal is aborted without reason',
119
122
  DOMExceptionNameEnum.abortError
120
123
  );
121
124
  }
@@ -226,6 +226,8 @@ export default class MediaQueryItem {
226
226
  return true;
227
227
  case 'prefers-reduced-motion':
228
228
  return settings.device.prefersReducedMotion === 'reduce';
229
+ case 'forced-colors':
230
+ return settings.device.forcedColors === 'active';
229
231
  }
230
232
  return false;
231
233
  }
@@ -257,6 +259,11 @@ export default class MediaQueryItem {
257
259
  return rule.value === settings.device.prefersColorScheme;
258
260
  case 'prefers-reduced-motion':
259
261
  return rule.value === settings.device.prefersReducedMotion;
262
+ case 'forced-colors':
263
+ return (
264
+ (rule.value === 'none' || rule.value === 'active') &&
265
+ rule.value === settings.device.forcedColors
266
+ );
260
267
  case 'any-hover':
261
268
  case 'hover':
262
269
  if (rule.value === 'none') {
@@ -455,7 +455,9 @@ export default class HTMLLinkElement extends HTMLElement {
455
455
  browserFrame.page?.console.error(error);
456
456
  this.dispatchEvent(new Event('error'));
457
457
  } else {
458
- const styleSheet = new CSSStyleSheet();
458
+ const styleSheet = new this[PropertySymbol.ownerDocument][
459
+ PropertySymbol.window
460
+ ].CSSStyleSheet();
459
461
  styleSheet.replaceSync(code);
460
462
  this[PropertySymbol.sheet] = styleSheet;
461
463
 
@@ -79,7 +79,9 @@ export default class HTMLStyleElement extends HTMLElement {
79
79
  return null;
80
80
  }
81
81
  if (!this[PropertySymbol.sheet]) {
82
- this[PropertySymbol.sheet] = new CSSStyleSheet();
82
+ this[PropertySymbol.sheet] = new this[PropertySymbol.ownerDocument][
83
+ PropertySymbol.window
84
+ ].CSSStyleSheet();
83
85
  this[PropertySymbol.sheet].replaceSync(this.textContent);
84
86
  }
85
87
  return this[PropertySymbol.sheet];
@@ -97,7 +97,9 @@ export default class SVGStyleElement extends SVGElement {
97
97
  return null;
98
98
  }
99
99
  if (!this[PropertySymbol.sheet]) {
100
- this[PropertySymbol.sheet] = new CSSStyleSheet();
100
+ this[PropertySymbol.sheet] = new this[PropertySymbol.ownerDocument][
101
+ PropertySymbol.window
102
+ ].CSSStyleSheet();
101
103
  this[PropertySymbol.sheet].replaceSync(this.textContent);
102
104
  }
103
105
  return this[PropertySymbol.sheet];