happy-dom 6.0.4 → 7.0.1
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.
- package/lib/css/CSSParser.js +12 -6
- package/lib/css/CSSParser.js.map +1 -1
- package/lib/css/CSSRule.d.ts +15 -13
- package/lib/css/CSSRule.js +18 -13
- package/lib/css/CSSRule.js.map +1 -1
- package/lib/css/CSSRuleTypeEnum.d.ts +17 -0
- package/lib/css/CSSRuleTypeEnum.js +21 -0
- package/lib/css/CSSRuleTypeEnum.js.map +1 -0
- package/lib/css/CSSStyleSheet.d.ts +6 -16
- package/lib/css/CSSStyleSheet.js +11 -19
- package/lib/css/CSSStyleSheet.js.map +1 -1
- package/lib/css/declaration/AbstractCSSStyleDeclaration.d.ts +76 -0
- package/lib/css/declaration/AbstractCSSStyleDeclaration.js +182 -0
- package/lib/css/declaration/AbstractCSSStyleDeclaration.js.map +1 -0
- package/lib/css/declaration/CSSStyleDeclaration.d.ts +1194 -0
- package/lib/css/declaration/CSSStyleDeclaration.js +3566 -0
- package/lib/css/declaration/CSSStyleDeclaration.js.map +1 -0
- package/lib/css/declaration/utilities/CSSStyleDeclarationCSSParser.d.ts +12 -0
- package/lib/css/declaration/utilities/CSSStyleDeclarationCSSParser.js +34 -0
- package/lib/css/declaration/utilities/CSSStyleDeclarationCSSParser.js.map +1 -0
- package/lib/css/declaration/utilities/CSSStyleDeclarationElementDefaultCSS.d.ts +131 -0
- package/lib/css/declaration/utilities/CSSStyleDeclarationElementDefaultCSS.js +133 -0
- package/lib/css/declaration/utilities/CSSStyleDeclarationElementDefaultCSS.js.map +1 -0
- package/lib/css/declaration/utilities/CSSStyleDeclarationElementInheritedProperties.d.ts +40 -0
- package/lib/css/declaration/utilities/CSSStyleDeclarationElementInheritedProperties.js +42 -0
- package/lib/css/declaration/utilities/CSSStyleDeclarationElementInheritedProperties.js.map +1 -0
- package/lib/css/declaration/utilities/CSSStyleDeclarationElementStyle.d.ts +49 -0
- package/lib/css/declaration/utilities/CSSStyleDeclarationElementStyle.js +244 -0
- package/lib/css/declaration/utilities/CSSStyleDeclarationElementStyle.js.map +1 -0
- package/lib/css/declaration/utilities/CSSStyleDeclarationPropertyGetParser.d.ts +167 -0
- package/lib/css/declaration/utilities/CSSStyleDeclarationPropertyGetParser.js +537 -0
- package/lib/css/declaration/utilities/CSSStyleDeclarationPropertyGetParser.js.map +1 -0
- package/lib/css/declaration/utilities/CSSStyleDeclarationPropertyManager.d.ts +65 -0
- package/lib/css/declaration/utilities/CSSStyleDeclarationPropertyManager.js +565 -0
- package/lib/css/declaration/utilities/CSSStyleDeclarationPropertyManager.js.map +1 -0
- package/lib/css/declaration/utilities/CSSStyleDeclarationPropertySetParser.d.ts +809 -0
- package/lib/css/declaration/utilities/CSSStyleDeclarationPropertySetParser.js +2303 -0
- package/lib/css/declaration/utilities/CSSStyleDeclarationPropertySetParser.js.map +1 -0
- package/lib/css/declaration/utilities/CSSStyleDeclarationValueParser.d.ts +127 -0
- package/lib/css/declaration/utilities/CSSStyleDeclarationValueParser.js +411 -0
- package/lib/css/declaration/utilities/CSSStyleDeclarationValueParser.js.map +1 -0
- package/lib/css/declaration/utilities/ICSSStyleDeclarationPropertyValue.d.ts +4 -0
- package/lib/css/declaration/utilities/ICSSStyleDeclarationPropertyValue.js +3 -0
- package/lib/css/declaration/utilities/ICSSStyleDeclarationPropertyValue.js.map +1 -0
- package/lib/css/rules/CSSContainerRule.d.ts +15 -0
- package/lib/css/rules/CSSContainerRule.js +31 -0
- package/lib/css/rules/CSSContainerRule.js.map +1 -0
- package/lib/css/rules/CSSFontFaceRule.d.ts +10 -3
- package/lib/css/rules/CSSFontFaceRule.js +16 -0
- package/lib/css/rules/CSSFontFaceRule.js.map +1 -1
- package/lib/css/rules/CSSKeyframeRule.d.ts +10 -3
- package/lib/css/rules/CSSKeyframeRule.js +16 -0
- package/lib/css/rules/CSSKeyframeRule.js.map +1 -1
- package/lib/css/rules/CSSKeyframesRule.d.ts +1 -1
- package/lib/css/rules/CSSKeyframesRule.js +1 -1
- package/lib/css/rules/CSSKeyframesRule.js.map +1 -1
- package/lib/css/rules/CSSMediaRule.d.ts +1 -1
- package/lib/css/rules/CSSStyleRule.d.ts +10 -3
- package/lib/css/rules/CSSStyleRule.js +16 -0
- package/lib/css/rules/CSSStyleRule.js.map +1 -1
- package/lib/event/Event.d.ts +2 -3
- package/lib/event/Event.js.map +1 -1
- package/lib/event/events/IMediaQueryListInit.d.ts +5 -0
- package/lib/event/events/IMediaQueryListInit.js +3 -0
- package/lib/event/events/IMediaQueryListInit.js.map +1 -0
- package/lib/event/events/MediaQueryListEvent.d.ts +16 -0
- package/lib/event/events/MediaQueryListEvent.js +28 -0
- package/lib/event/events/MediaQueryListEvent.js.map +1 -0
- package/lib/exception/DOMException.js +5 -3
- package/lib/exception/DOMException.js.map +1 -1
- package/lib/exception/DOMExceptionNameEnum.d.ts +2 -1
- package/lib/exception/DOMExceptionNameEnum.js +1 -0
- package/lib/exception/DOMExceptionNameEnum.js.map +1 -1
- package/lib/file/Blob.d.ts +9 -0
- package/lib/file/Blob.js +14 -0
- package/lib/file/Blob.js.map +1 -1
- package/lib/index.d.ts +9 -2
- package/lib/index.js +16 -2
- package/lib/index.js.map +1 -1
- package/lib/match-media/MediaQueryList.d.ts +19 -8
- package/lib/match-media/MediaQueryList.js +56 -13
- package/lib/match-media/MediaQueryList.js.map +1 -1
- package/lib/{attribute → nodes/attr}/Attr.d.ts +8 -7
- package/lib/{attribute → nodes/attr}/Attr.js +12 -5
- package/lib/nodes/attr/Attr.js.map +1 -0
- package/lib/nodes/attr/IAttr.d.ts +14 -0
- package/lib/nodes/attr/IAttr.js +3 -0
- package/lib/nodes/attr/IAttr.js.map +1 -0
- package/lib/nodes/child-node/ChildNodeUtility.js +2 -1
- package/lib/nodes/child-node/ChildNodeUtility.js.map +1 -1
- package/lib/nodes/document/Document.d.ts +4 -4
- package/lib/nodes/document/Document.js +5 -8
- package/lib/nodes/document/Document.js.map +1 -1
- package/lib/nodes/document/IDocument.d.ts +3 -3
- package/lib/nodes/element/Element.d.ts +11 -9
- package/lib/nodes/element/Element.js +2 -1
- package/lib/nodes/element/Element.js.map +1 -1
- package/lib/nodes/element/IElement.d.ts +10 -8
- package/lib/nodes/html-element/HTMLElement.d.ts +21 -5
- package/lib/nodes/html-element/HTMLElement.js +74 -11
- package/lib/nodes/html-element/HTMLElement.js.map +1 -1
- package/lib/nodes/html-element/IHTMLElement.d.ts +5 -1
- package/lib/nodes/html-link-element/HTMLLinkElement.d.ts +2 -2
- package/lib/nodes/html-link-element/HTMLLinkElement.js.map +1 -1
- package/lib/nodes/html-script-element/HTMLScriptElement.d.ts +2 -2
- package/lib/nodes/html-script-element/HTMLScriptElement.js.map +1 -1
- package/lib/nodes/html-select-element/HTMLSelectElement.js +1 -1
- package/lib/nodes/html-select-element/HTMLSelectElement.js.map +1 -1
- package/lib/nodes/html-style-element/HTMLStyleElement.js +1 -1
- package/lib/nodes/html-style-element/HTMLStyleElement.js.map +1 -1
- package/lib/nodes/node/INode.d.ts +2 -0
- package/lib/nodes/node/Node.d.ts +5 -1
- package/lib/nodes/node/Node.js +7 -1
- package/lib/nodes/node/Node.js.map +1 -1
- package/lib/nodes/node/NodeTypeEnum.d.ts +2 -0
- package/lib/nodes/node/NodeTypeEnum.js +2 -0
- package/lib/nodes/node/NodeTypeEnum.js.map +1 -1
- package/lib/nodes/svg-element/ISVGElement.d.ts +1 -1
- package/lib/nodes/svg-element/SVGElement.d.ts +4 -4
- package/lib/nodes/svg-element/SVGElement.js +2 -2
- package/lib/nodes/svg-element/SVGElement.js.map +1 -1
- package/lib/window/IWindow.d.ts +23 -3
- package/lib/window/Window.d.ts +35 -6
- package/lib/window/Window.js +58 -23
- package/lib/window/Window.js.map +1 -1
- package/package.json +2 -2
- package/src/css/CSSParser.ts +14 -6
- package/src/css/CSSRule.ts +15 -13
- package/src/css/CSSRuleTypeEnum.ts +18 -0
- package/src/css/CSSStyleSheet.ts +12 -22
- package/src/css/declaration/AbstractCSSStyleDeclaration.ts +202 -0
- package/src/css/declaration/CSSStyleDeclaration.ts +4743 -0
- package/src/css/declaration/utilities/CSSStyleDeclarationCSSParser.ts +35 -0
- package/src/css/declaration/utilities/CSSStyleDeclarationElementDefaultCSS.ts +130 -0
- package/src/css/declaration/utilities/CSSStyleDeclarationElementInheritedProperties.ts +39 -0
- package/src/css/declaration/utilities/CSSStyleDeclarationElementStyle.ts +282 -0
- package/src/css/declaration/utilities/CSSStyleDeclarationPropertyGetParser.ts +743 -0
- package/src/css/declaration/utilities/CSSStyleDeclarationPropertyManager.ts +592 -0
- package/src/css/declaration/utilities/CSSStyleDeclarationPropertySetParser.ts +3026 -0
- package/src/css/declaration/utilities/CSSStyleDeclarationValueParser.ts +437 -0
- package/src/css/declaration/utilities/ICSSStyleDeclarationPropertyValue.ts +4 -0
- package/src/css/rules/CSSContainerRule.ts +23 -0
- package/src/css/rules/CSSFontFaceRule.ts +17 -2
- package/src/css/rules/CSSKeyframeRule.ts +17 -2
- package/src/css/rules/CSSKeyframesRule.ts +1 -1
- package/src/css/rules/CSSStyleRule.ts +17 -2
- package/src/event/Event.ts +2 -3
- package/src/event/events/IMediaQueryListInit.ts +6 -0
- package/src/event/events/MediaQueryListEvent.ts +25 -0
- package/src/exception/DOMException.ts +3 -3
- package/src/exception/DOMExceptionNameEnum.ts +2 -1
- package/src/file/Blob.ts +16 -0
- package/src/index.ts +15 -1
- package/src/match-media/MediaQueryList.ts +63 -10
- package/src/{attribute → nodes/attr}/Attr.ts +11 -8
- package/src/nodes/attr/IAttr.ts +15 -0
- package/src/nodes/child-node/ChildNodeUtility.ts +2 -1
- package/src/nodes/document/Document.ts +8 -10
- package/src/nodes/document/IDocument.ts +3 -3
- package/src/nodes/element/Element.ts +13 -10
- package/src/nodes/element/IElement.ts +8 -8
- package/src/nodes/html-element/HTMLElement.ts +94 -16
- package/src/nodes/html-element/IHTMLElement.ts +3 -1
- package/src/nodes/html-link-element/HTMLLinkElement.ts +2 -2
- package/src/nodes/html-script-element/HTMLScriptElement.ts +2 -2
- package/src/nodes/html-select-element/HTMLSelectElement.ts +1 -1
- package/src/nodes/html-style-element/HTMLStyleElement.ts +1 -1
- package/src/nodes/node/INode.ts +2 -0
- package/src/nodes/node/Node.ts +7 -1
- package/src/nodes/node/NodeTypeEnum.ts +2 -0
- package/src/nodes/svg-element/ISVGElement.ts +1 -1
- package/src/nodes/svg-element/SVGElement.ts +5 -5
- package/src/window/IWindow.ts +23 -3
- package/src/window/Window.ts +51 -11
- package/lib/attribute/Attr.js.map +0 -1
- package/lib/css/CSSStyleDeclaration.d.ts +0 -3017
- package/lib/css/CSSStyleDeclaration.js +0 -4643
- package/lib/css/CSSStyleDeclaration.js.map +0 -1
- package/src/css/CSSStyleDeclaration.ts +0 -5026
@@ -0,0 +1,437 @@
|
|
1
|
+
const COLOR_REGEXP =
|
2
|
+
/^#([0-9a-fA-F]{3,4}){1,2}$|^rgb\(([^)]*)\)$|^rgba\(([^)]*)\)$|^hsla?\(\s*(-?\d+|-?\d*.\d+)\s*,\s*(-?\d+|-?\d*.\d+)%\s*,\s*(-?\d+|-?\d*.\d+)%\s*(,\s*(-?\d+|-?\d*.\d+)\s*)?\)/;
|
3
|
+
|
4
|
+
const LENGTH_REGEXP = /^(0|[-+]?[0-9]*\.?[0-9]+(in|cm|em|mm|pt|pc|px|ex|rem|vh|vw|ch))$/;
|
5
|
+
const PERCENTAGE_REGEXP = /^[-+]?[0-9]*\.?[0-9]+%$/;
|
6
|
+
const DEGREE_REGEXP = /^[0-9]+deg$/;
|
7
|
+
const URL_REGEXP = /^url\(\s*([^)]*)\s*\)$/;
|
8
|
+
const INTEGER_REGEXP = /^[0-9]+$/;
|
9
|
+
const FLOAT_REGEXP = /^[0-9.]+$/;
|
10
|
+
const CALC_REGEXP = /^calc\([^^)]+\)$/;
|
11
|
+
const CSS_VARIABLE_REGEXP = /^var\( *(--[^) ]+)\)$/;
|
12
|
+
const FIT_CONTENT_REGEXP = /^fit-content\([^^)]+\)$/;
|
13
|
+
const GRADIENT_REGEXP =
|
14
|
+
/^(repeating-linear|linear|radial|repeating-radial|conic|repeating-conic)-gradient\([^)]+\)$/;
|
15
|
+
const GLOBALS = ['inherit', 'initial', 'unset', 'revert'];
|
16
|
+
const COLORS = [
|
17
|
+
'currentcolor',
|
18
|
+
'transparent',
|
19
|
+
'silver',
|
20
|
+
'gray',
|
21
|
+
'white',
|
22
|
+
'maroon',
|
23
|
+
'red',
|
24
|
+
'purple',
|
25
|
+
'fuchsia',
|
26
|
+
'green',
|
27
|
+
'lime',
|
28
|
+
'olive',
|
29
|
+
'yellow',
|
30
|
+
'navy',
|
31
|
+
'blue',
|
32
|
+
'teal',
|
33
|
+
'aqua',
|
34
|
+
'antiquewhite',
|
35
|
+
'aquamarine',
|
36
|
+
'azure',
|
37
|
+
'beige',
|
38
|
+
'bisque',
|
39
|
+
'blanchedalmond',
|
40
|
+
'blueviolet',
|
41
|
+
'brown',
|
42
|
+
'burlywood',
|
43
|
+
'cadetblue',
|
44
|
+
'chartreuse',
|
45
|
+
'chocolate',
|
46
|
+
'coral',
|
47
|
+
'cornflowerblue',
|
48
|
+
'cornsilk',
|
49
|
+
'crimson',
|
50
|
+
'darkblue',
|
51
|
+
'darkcyan',
|
52
|
+
'darkgoldenrod',
|
53
|
+
'darkgray',
|
54
|
+
'darkgreen',
|
55
|
+
'darkgrey',
|
56
|
+
'darkkhaki',
|
57
|
+
'darkmagenta',
|
58
|
+
'darkolivegreen',
|
59
|
+
'darkorange',
|
60
|
+
'darkorchid',
|
61
|
+
'darkred',
|
62
|
+
'darksalmon',
|
63
|
+
'darkseagreen',
|
64
|
+
'darkslateblue',
|
65
|
+
'darkslategray',
|
66
|
+
'darkslategrey',
|
67
|
+
'darkturquoise',
|
68
|
+
'darkviolet',
|
69
|
+
'deeppink',
|
70
|
+
'deepskyblue',
|
71
|
+
'dimgray',
|
72
|
+
'dimgrey',
|
73
|
+
'dodgerblue',
|
74
|
+
'firebrick',
|
75
|
+
'floralwhite',
|
76
|
+
'forestgreen',
|
77
|
+
'gainsboro',
|
78
|
+
'ghostwhite',
|
79
|
+
'gold',
|
80
|
+
'goldenrod',
|
81
|
+
'greenyellow',
|
82
|
+
'grey',
|
83
|
+
'honeydew',
|
84
|
+
'hotpink',
|
85
|
+
'indianred',
|
86
|
+
'indigo',
|
87
|
+
'ivory',
|
88
|
+
'khaki',
|
89
|
+
'lavender',
|
90
|
+
'lavenderblush',
|
91
|
+
'lawngreen',
|
92
|
+
'lemonchiffon',
|
93
|
+
'lightblue',
|
94
|
+
'lightcoral',
|
95
|
+
'lightcyan',
|
96
|
+
'lightgoldenrodyellow',
|
97
|
+
'lightgray',
|
98
|
+
'lightgreen',
|
99
|
+
'lightgrey',
|
100
|
+
'lightpink',
|
101
|
+
'lightsalmon',
|
102
|
+
'lightseagreen',
|
103
|
+
'lightskyblue',
|
104
|
+
'lightslategray',
|
105
|
+
'lightslategrey',
|
106
|
+
'lightsteelblue',
|
107
|
+
'lightyellow',
|
108
|
+
'limegreen',
|
109
|
+
'linen',
|
110
|
+
'mediumaquamarine',
|
111
|
+
'mediumblue',
|
112
|
+
'mediumorchid',
|
113
|
+
'mediumpurple',
|
114
|
+
'mediumseagreen',
|
115
|
+
'mediumslateblue',
|
116
|
+
'mediumspringgreen',
|
117
|
+
'mediumturquoise',
|
118
|
+
'mediumvioletred',
|
119
|
+
'midnightblue',
|
120
|
+
'mintcream',
|
121
|
+
'mistyrose',
|
122
|
+
'moccasin',
|
123
|
+
'navajowhite',
|
124
|
+
'oldlace',
|
125
|
+
'olivedrab',
|
126
|
+
'orangered',
|
127
|
+
'orchid',
|
128
|
+
'palegoldenrod',
|
129
|
+
'palegreen',
|
130
|
+
'paleturquoise',
|
131
|
+
'palevioletred',
|
132
|
+
'papayawhip',
|
133
|
+
'peachpuff',
|
134
|
+
'peru',
|
135
|
+
'pink',
|
136
|
+
'plum',
|
137
|
+
'powderblue',
|
138
|
+
'rosybrown',
|
139
|
+
'royalblue',
|
140
|
+
'saddlebrown',
|
141
|
+
'salmon',
|
142
|
+
'sandybrown',
|
143
|
+
'seagreen',
|
144
|
+
'seashell',
|
145
|
+
'sienna',
|
146
|
+
'skyblue',
|
147
|
+
'slateblue',
|
148
|
+
'slategray',
|
149
|
+
'slategrey',
|
150
|
+
'snow',
|
151
|
+
'springgreen',
|
152
|
+
'steelblue',
|
153
|
+
'tan',
|
154
|
+
'thistle',
|
155
|
+
'tomato',
|
156
|
+
'turquoise',
|
157
|
+
'violet',
|
158
|
+
'wheat',
|
159
|
+
'whitesmoke',
|
160
|
+
'yellowgreen'
|
161
|
+
];
|
162
|
+
|
163
|
+
/**
|
164
|
+
* Style declaration value parser.
|
165
|
+
*/
|
166
|
+
export default class CSSStyleDeclarationValueParser {
|
167
|
+
/**
|
168
|
+
* Returns length.
|
169
|
+
*
|
170
|
+
* @param value Value.
|
171
|
+
* @returns Parsed value.
|
172
|
+
*/
|
173
|
+
public static getLength(value: string): string {
|
174
|
+
if (value === '0') {
|
175
|
+
return '0px';
|
176
|
+
}
|
177
|
+
if (LENGTH_REGEXP.test(value)) {
|
178
|
+
return value;
|
179
|
+
}
|
180
|
+
return null;
|
181
|
+
}
|
182
|
+
|
183
|
+
/**
|
184
|
+
* Returns percentance.
|
185
|
+
*
|
186
|
+
* @param value Value.
|
187
|
+
* @returns Parsed value.
|
188
|
+
*/
|
189
|
+
public static getPercentage(value: string): string {
|
190
|
+
if (value === '0') {
|
191
|
+
return '0%';
|
192
|
+
}
|
193
|
+
if (PERCENTAGE_REGEXP.test(value)) {
|
194
|
+
return value;
|
195
|
+
}
|
196
|
+
return null;
|
197
|
+
}
|
198
|
+
|
199
|
+
/**
|
200
|
+
* Returns degree.
|
201
|
+
*
|
202
|
+
* @param value Value.
|
203
|
+
* @returns Parsed value.
|
204
|
+
*/
|
205
|
+
public static getDegree(value: string): string {
|
206
|
+
if (value === '0') {
|
207
|
+
return '0deg';
|
208
|
+
}
|
209
|
+
if (DEGREE_REGEXP.test(value)) {
|
210
|
+
return value;
|
211
|
+
}
|
212
|
+
return null;
|
213
|
+
}
|
214
|
+
|
215
|
+
/**
|
216
|
+
* Returns calc.
|
217
|
+
*
|
218
|
+
* @param value Value.
|
219
|
+
* @returns Parsed value.
|
220
|
+
*/
|
221
|
+
public static getCalc(value: string): string {
|
222
|
+
if (CALC_REGEXP.test(value)) {
|
223
|
+
return value;
|
224
|
+
}
|
225
|
+
return null;
|
226
|
+
}
|
227
|
+
|
228
|
+
/**
|
229
|
+
* Returns fit content.
|
230
|
+
*
|
231
|
+
* @param value Value.
|
232
|
+
* @returns Parsed value.
|
233
|
+
*/
|
234
|
+
public static getFitContent(value: string): string {
|
235
|
+
const lowerValue = value.toLowerCase();
|
236
|
+
if (
|
237
|
+
lowerValue === 'auto' ||
|
238
|
+
lowerValue === 'max-content' ||
|
239
|
+
lowerValue === 'min-content' ||
|
240
|
+
lowerValue === 'fit-content'
|
241
|
+
) {
|
242
|
+
return lowerValue;
|
243
|
+
}
|
244
|
+
if (FIT_CONTENT_REGEXP.test(lowerValue)) {
|
245
|
+
return lowerValue;
|
246
|
+
}
|
247
|
+
return null;
|
248
|
+
}
|
249
|
+
|
250
|
+
/**
|
251
|
+
* Returns measurement.
|
252
|
+
*
|
253
|
+
* @param value Value.
|
254
|
+
* @returns Parsed value.
|
255
|
+
*/
|
256
|
+
public static getMeasurement(value: string): string {
|
257
|
+
return this.getLength(value) || this.getPercentage(value);
|
258
|
+
}
|
259
|
+
|
260
|
+
/**
|
261
|
+
* Returns measurement or auto, min-content, max-content or fit-content.
|
262
|
+
*
|
263
|
+
* @param value Value.
|
264
|
+
* @returns Parsed value.
|
265
|
+
*/
|
266
|
+
public static getContentMeasurement(value: string): string {
|
267
|
+
return this.getFitContent(value) || this.getMeasurement(value);
|
268
|
+
}
|
269
|
+
|
270
|
+
/**
|
271
|
+
* Returns measurement or auto, min-content, max-content or fit-content.
|
272
|
+
*
|
273
|
+
* @param value Value.
|
274
|
+
* @returns Parsed value.
|
275
|
+
*/
|
276
|
+
public static getAutoMeasurement(value: string): string {
|
277
|
+
if (value.toLocaleLowerCase() === 'auto') {
|
278
|
+
return 'auto';
|
279
|
+
}
|
280
|
+
return this.getMeasurement(value);
|
281
|
+
}
|
282
|
+
|
283
|
+
/**
|
284
|
+
* Returns integer.
|
285
|
+
*
|
286
|
+
* @param value Value.
|
287
|
+
* @returns Parsed value.
|
288
|
+
*/
|
289
|
+
public static getInteger(value: string): string {
|
290
|
+
if (INTEGER_REGEXP.test(value)) {
|
291
|
+
return value;
|
292
|
+
}
|
293
|
+
return null;
|
294
|
+
}
|
295
|
+
|
296
|
+
/**
|
297
|
+
* Returns float.
|
298
|
+
*
|
299
|
+
* @param value Value.
|
300
|
+
* @returns Parsed value.
|
301
|
+
*/
|
302
|
+
public static getFloat(value: string): string {
|
303
|
+
if (FLOAT_REGEXP.test(value)) {
|
304
|
+
return value;
|
305
|
+
}
|
306
|
+
return null;
|
307
|
+
}
|
308
|
+
|
309
|
+
/**
|
310
|
+
* Returns gradient.
|
311
|
+
*
|
312
|
+
* @param value Value.
|
313
|
+
* @returns Parsed value.
|
314
|
+
*/
|
315
|
+
public static getGradient(value: string): string {
|
316
|
+
if (GRADIENT_REGEXP.test(value)) {
|
317
|
+
return value;
|
318
|
+
}
|
319
|
+
return null;
|
320
|
+
}
|
321
|
+
|
322
|
+
/**
|
323
|
+
* Returns color.
|
324
|
+
*
|
325
|
+
* @param value Value.
|
326
|
+
* @returns Parsed value.
|
327
|
+
*/
|
328
|
+
public static getColor(value: string): string {
|
329
|
+
const lowerValue = value.toLowerCase();
|
330
|
+
if (COLORS.includes(lowerValue)) {
|
331
|
+
return lowerValue;
|
332
|
+
}
|
333
|
+
if (COLOR_REGEXP.test(value)) {
|
334
|
+
return value.replace(/,([^ ])/g, ', $1');
|
335
|
+
}
|
336
|
+
return null;
|
337
|
+
}
|
338
|
+
|
339
|
+
/**
|
340
|
+
* Returns URL.
|
341
|
+
*
|
342
|
+
* Based on:
|
343
|
+
* https://github.com/jsdom/cssstyle/blob/master/lib/parsers.js#L222
|
344
|
+
*
|
345
|
+
* @param value Value.
|
346
|
+
* @returns Parsed value.
|
347
|
+
*/
|
348
|
+
public static getURL(value: string): string {
|
349
|
+
if (!value) {
|
350
|
+
return null;
|
351
|
+
}
|
352
|
+
|
353
|
+
if (value.toLowerCase() === 'none') {
|
354
|
+
return 'none';
|
355
|
+
}
|
356
|
+
|
357
|
+
const result = URL_REGEXP.exec(value);
|
358
|
+
|
359
|
+
if (!result) {
|
360
|
+
return null;
|
361
|
+
}
|
362
|
+
|
363
|
+
let url = result[1];
|
364
|
+
|
365
|
+
if ((url[0] === '"' || url[0] === "'") && url[0] !== url[url.length - 1]) {
|
366
|
+
return null;
|
367
|
+
}
|
368
|
+
|
369
|
+
if (url[0] === '"' || url[0] === "'") {
|
370
|
+
url = url.substring(1, url.length - 1);
|
371
|
+
}
|
372
|
+
|
373
|
+
for (let i = 0; i < url.length; i++) {
|
374
|
+
switch (url[i]) {
|
375
|
+
case '(':
|
376
|
+
case ')':
|
377
|
+
case ' ':
|
378
|
+
case '\t':
|
379
|
+
case '\n':
|
380
|
+
case "'":
|
381
|
+
case '"':
|
382
|
+
return null;
|
383
|
+
case '\\':
|
384
|
+
i++;
|
385
|
+
break;
|
386
|
+
}
|
387
|
+
}
|
388
|
+
|
389
|
+
return `url("${url}")`;
|
390
|
+
}
|
391
|
+
|
392
|
+
/**
|
393
|
+
* Returns global initial value.
|
394
|
+
*
|
395
|
+
* @param value Value.
|
396
|
+
* @returns Parsed value.
|
397
|
+
*/
|
398
|
+
public static getInitial(value: string): string {
|
399
|
+
return value.toLowerCase() === 'initial' ? 'initial' : null;
|
400
|
+
}
|
401
|
+
|
402
|
+
/**
|
403
|
+
* Returns CSS variable.
|
404
|
+
*
|
405
|
+
* @param value Value.
|
406
|
+
* @returns Parsed value.
|
407
|
+
*/
|
408
|
+
public static getVariable(value: string): string {
|
409
|
+
const cssVariableMatch = value.match(CSS_VARIABLE_REGEXP);
|
410
|
+
if (cssVariableMatch) {
|
411
|
+
return `var(${cssVariableMatch[1]})`;
|
412
|
+
}
|
413
|
+
return null;
|
414
|
+
}
|
415
|
+
|
416
|
+
/**
|
417
|
+
* Returns global.
|
418
|
+
*
|
419
|
+
* @param value Value.
|
420
|
+
* @returns Parsed value.
|
421
|
+
*/
|
422
|
+
public static getGlobal(value: string): string {
|
423
|
+
const lowerValue = value.toLowerCase();
|
424
|
+
return GLOBALS.includes(lowerValue) ? lowerValue : null;
|
425
|
+
}
|
426
|
+
|
427
|
+
/**
|
428
|
+
* Returns global, unless it is not set to 'initial' as it is sometimes treated different.
|
429
|
+
*
|
430
|
+
* @param value Value.
|
431
|
+
* @returns Parsed value.
|
432
|
+
*/
|
433
|
+
public static getGlobalExceptInitial(value: string): string {
|
434
|
+
const lowerValue = value.toLowerCase();
|
435
|
+
return lowerValue !== 'initial' && GLOBALS.includes(lowerValue) ? lowerValue : null;
|
436
|
+
}
|
437
|
+
}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
import CSSRule from '../CSSRule';
|
2
|
+
|
3
|
+
/**
|
4
|
+
* CSSRule interface.
|
5
|
+
*/
|
6
|
+
export default class CSSContainerRule extends CSSRule {
|
7
|
+
public readonly type = CSSRule.CONTAINER_RULE;
|
8
|
+
public readonly cssRules: CSSRule[] = [];
|
9
|
+
public readonly conditionalText = '';
|
10
|
+
|
11
|
+
/**
|
12
|
+
* Returns css text.
|
13
|
+
*
|
14
|
+
* @returns CSS text.
|
15
|
+
*/
|
16
|
+
public get cssText(): string {
|
17
|
+
let cssText = '';
|
18
|
+
for (const cssRule of this.cssRules) {
|
19
|
+
cssText += cssRule.cssText;
|
20
|
+
}
|
21
|
+
return `@container ${this.conditionalText} { ${cssText} }`;
|
22
|
+
}
|
23
|
+
}
|
@@ -1,10 +1,25 @@
|
|
1
1
|
import CSSRule from '../CSSRule';
|
2
|
-
import CSSStyleDeclaration from '../CSSStyleDeclaration';
|
2
|
+
import CSSStyleDeclaration from '../declaration/CSSStyleDeclaration';
|
3
3
|
|
4
4
|
/**
|
5
5
|
* CSSRule interface.
|
6
6
|
*/
|
7
7
|
export default class CSSFontFaceRule extends CSSRule {
|
8
8
|
public readonly type = CSSRule.FONT_FACE_RULE;
|
9
|
-
public
|
9
|
+
public _cssText = '';
|
10
|
+
private _style: CSSStyleDeclaration = null;
|
11
|
+
|
12
|
+
/**
|
13
|
+
* Returns style.
|
14
|
+
*
|
15
|
+
* @returns Style.
|
16
|
+
*/
|
17
|
+
public get style(): CSSStyleDeclaration {
|
18
|
+
if (!this._style) {
|
19
|
+
this._style = new CSSStyleDeclaration();
|
20
|
+
(<CSSRule>this._style.parentRule) = this;
|
21
|
+
this._style.cssText = this._cssText;
|
22
|
+
}
|
23
|
+
return this._style;
|
24
|
+
}
|
10
25
|
}
|
@@ -1,13 +1,28 @@
|
|
1
1
|
import CSSRule from '../CSSRule';
|
2
|
-
import CSSStyleDeclaration from '../CSSStyleDeclaration';
|
2
|
+
import CSSStyleDeclaration from '../declaration/CSSStyleDeclaration';
|
3
3
|
|
4
4
|
/**
|
5
5
|
* CSSRule interface.
|
6
6
|
*/
|
7
7
|
export default class CSSKeyframeRule extends CSSRule {
|
8
8
|
public readonly type = CSSRule.KEYFRAME_RULE;
|
9
|
-
public readonly style: CSSStyleDeclaration;
|
10
9
|
public readonly keyText: string;
|
10
|
+
public _cssText = '';
|
11
|
+
private _style: CSSStyleDeclaration = null;
|
12
|
+
|
13
|
+
/**
|
14
|
+
* Returns style.
|
15
|
+
*
|
16
|
+
* @returns Style.
|
17
|
+
*/
|
18
|
+
public get style(): CSSStyleDeclaration {
|
19
|
+
if (!this._style) {
|
20
|
+
this._style = new CSSStyleDeclaration();
|
21
|
+
(<CSSRule>this._style.parentRule) = this;
|
22
|
+
this._style.cssText = this._cssText;
|
23
|
+
}
|
24
|
+
return this._style;
|
25
|
+
}
|
11
26
|
|
12
27
|
/**
|
13
28
|
* Returns css text.
|
@@ -1,14 +1,29 @@
|
|
1
1
|
import CSSRule from '../CSSRule';
|
2
|
-
import CSSStyleDeclaration from '../CSSStyleDeclaration';
|
2
|
+
import CSSStyleDeclaration from '../declaration/CSSStyleDeclaration';
|
3
3
|
|
4
4
|
/**
|
5
5
|
* CSSRule interface.
|
6
6
|
*/
|
7
7
|
export default class CSSStyleRule extends CSSRule {
|
8
8
|
public readonly type = CSSRule.STYLE_RULE;
|
9
|
-
public readonly style: CSSStyleDeclaration;
|
10
9
|
public readonly selectorText = '';
|
11
10
|
public readonly styleMap = new Map();
|
11
|
+
public _cssText = '';
|
12
|
+
private _style: CSSStyleDeclaration = null;
|
13
|
+
|
14
|
+
/**
|
15
|
+
* Returns style.
|
16
|
+
*
|
17
|
+
* @returns Style.
|
18
|
+
*/
|
19
|
+
public get style(): CSSStyleDeclaration {
|
20
|
+
if (!this._style) {
|
21
|
+
this._style = new CSSStyleDeclaration();
|
22
|
+
(<CSSRule>this._style.parentRule) = this;
|
23
|
+
this._style.cssText = this._cssText;
|
24
|
+
}
|
25
|
+
return this._style;
|
26
|
+
}
|
12
27
|
|
13
28
|
/**
|
14
29
|
* Returns css text.
|
package/src/event/Event.ts
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
import IEventInit from './IEventInit';
|
2
|
-
import EventTarget from './EventTarget';
|
3
2
|
import INode from '../nodes/node/INode';
|
4
3
|
import IWindow from '../window/IWindow';
|
5
4
|
import IShadowRoot from '../nodes/shadow-root/IShadowRoot';
|
@@ -10,8 +9,8 @@ import IEventTarget from './IEventTarget';
|
|
10
9
|
*/
|
11
10
|
export default class Event {
|
12
11
|
public composed = false;
|
13
|
-
public currentTarget:
|
14
|
-
public target:
|
12
|
+
public currentTarget: IEventTarget = null;
|
13
|
+
public target: IEventTarget = null;
|
15
14
|
public bubbles = false;
|
16
15
|
public cancelable = false;
|
17
16
|
public defaultPrevented = false;
|
@@ -0,0 +1,25 @@
|
|
1
|
+
import Event from '../Event';
|
2
|
+
import IMediaQueryListInit from './IMediaQueryListInit';
|
3
|
+
|
4
|
+
/**
|
5
|
+
*
|
6
|
+
*/
|
7
|
+
export default class MediaQueryListEvent extends Event {
|
8
|
+
public readonly matches: boolean = false;
|
9
|
+
public readonly media: string = '';
|
10
|
+
|
11
|
+
/**
|
12
|
+
* Constructor.
|
13
|
+
*
|
14
|
+
* @param type Event type.
|
15
|
+
* @param [eventInit] Event init.
|
16
|
+
*/
|
17
|
+
constructor(type: string, eventInit: IMediaQueryListInit = null) {
|
18
|
+
super(type, eventInit);
|
19
|
+
|
20
|
+
if (eventInit) {
|
21
|
+
this.matches = eventInit.matches || false;
|
22
|
+
this.media = eventInit.media || '';
|
23
|
+
}
|
24
|
+
}
|
25
|
+
}
|
@@ -1,3 +1,5 @@
|
|
1
|
+
import DOMExceptionNameEnum from './DOMExceptionNameEnum';
|
2
|
+
|
1
3
|
/**
|
2
4
|
* DOM Exception.
|
3
5
|
*
|
@@ -14,8 +16,6 @@ export default class DOMException extends Error {
|
|
14
16
|
constructor(message: string, name: string = null) {
|
15
17
|
super(message);
|
16
18
|
|
17
|
-
|
18
|
-
this.name = name;
|
19
|
-
}
|
19
|
+
this.name = name || DOMExceptionNameEnum.domException;
|
20
20
|
}
|
21
21
|
}
|
@@ -7,6 +7,7 @@ enum DOMExceptionNameEnum {
|
|
7
7
|
wrongDocumentError = 'WrongDocumentError',
|
8
8
|
invalidNodeTypeError = 'InvalidNodeTypeError',
|
9
9
|
invalidCharacterError = 'InvalidCharacterError',
|
10
|
-
notFoundError = 'NotFoundError'
|
10
|
+
notFoundError = 'NotFoundError',
|
11
|
+
domException = 'DOMException'
|
11
12
|
}
|
12
13
|
export default DOMExceptionNameEnum;
|
package/src/file/Blob.ts
CHANGED
@@ -110,6 +110,22 @@ export default class Blob implements IBlob {
|
|
110
110
|
return blob;
|
111
111
|
}
|
112
112
|
|
113
|
+
/**
|
114
|
+
* Returns a Promise that resolves to a ArrayBuffer.
|
115
|
+
*
|
116
|
+
* @returns ArrayBuffer.
|
117
|
+
*/
|
118
|
+
|
119
|
+
// Reference:
|
120
|
+
// https://github.com/web-std/io/blob/c88170bf24f064adfbb3586a21fb76650ca5a9ab/packages/blob/src/blob.js#L139-L148
|
121
|
+
// https://stackoverflow.com/questions/8609289/convert-a-binary-nodejs-buffer-to-javascript-arraybuffer
|
122
|
+
/**
|
123
|
+
*
|
124
|
+
*/
|
125
|
+
public async arrayBuffer(): Promise<ArrayBuffer> {
|
126
|
+
return new Uint8Array(this._buffer).buffer;
|
127
|
+
}
|
128
|
+
|
113
129
|
/**
|
114
130
|
* Returns a Promise that resolves to a text.
|
115
131
|
*
|
package/src/index.ts
CHANGED
@@ -13,7 +13,7 @@ import File from './file/File';
|
|
13
13
|
import FileReader from './file/FileReader';
|
14
14
|
import DOMException from './exception/DOMException';
|
15
15
|
import History from './history/History';
|
16
|
-
import CSSStyleDeclaration from './css/CSSStyleDeclaration';
|
16
|
+
import CSSStyleDeclaration from './css/declaration/CSSStyleDeclaration';
|
17
17
|
import Screen from './screen/Screen';
|
18
18
|
import AsyncTaskManager from './async-task-manager/AsyncTaskManager';
|
19
19
|
import NodeFilter from './tree-walker/NodeFilter';
|
@@ -100,6 +100,13 @@ import CustomElementRegistry from './custom-element/CustomElementRegistry';
|
|
100
100
|
import XMLParser from './xml-parser/XMLParser';
|
101
101
|
import XMLSerializer from './xml-serializer/XMLSerializer';
|
102
102
|
import CSSStyleSheet from './css/CSSStyleSheet';
|
103
|
+
import CSSRule from './css/CSSRule';
|
104
|
+
import CSSContainerRule from './css/rules/CSSContainerRule';
|
105
|
+
import CSSFontFaceRule from './css/rules/CSSFontFaceRule';
|
106
|
+
import CSSKeyframeRule from './css/rules/CSSKeyframeRule';
|
107
|
+
import CSSKeyframesRule from './css/rules/CSSKeyframesRule';
|
108
|
+
import CSSMediaRule from './css/rules/CSSMediaRule';
|
109
|
+
import CSSStyleRule from './css/rules/CSSStyleRule';
|
103
110
|
import Storage from './storage/Storage';
|
104
111
|
import DOMRect from './nodes/element/DOMRect';
|
105
112
|
import { URLSearchParams } from 'url';
|
@@ -211,6 +218,13 @@ export {
|
|
211
218
|
XMLParser,
|
212
219
|
XMLSerializer,
|
213
220
|
CSSStyleSheet,
|
221
|
+
CSSRule,
|
222
|
+
CSSContainerRule,
|
223
|
+
CSSFontFaceRule,
|
224
|
+
CSSKeyframeRule,
|
225
|
+
CSSKeyframesRule,
|
226
|
+
CSSMediaRule,
|
227
|
+
CSSStyleRule,
|
214
228
|
Storage,
|
215
229
|
DOMRect,
|
216
230
|
URLSearchParams,
|