happy-dom 6.0.4 → 7.0.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.
- 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,592 @@
|
|
1
|
+
import ICSSStyleDeclarationPropertyValue from './ICSSStyleDeclarationPropertyValue';
|
2
|
+
import CSSStyleDeclarationPropertySetParser from './CSSStyleDeclarationPropertySetParser';
|
3
|
+
import CSSStyleDeclarationValueParser from './CSSStyleDeclarationValueParser';
|
4
|
+
import CSSStyleDeclarationPropertyGetParser from './CSSStyleDeclarationPropertyGetParser';
|
5
|
+
import CSSStyleDeclarationCSSParser from './CSSStyleDeclarationCSSParser';
|
6
|
+
|
7
|
+
const TO_STRING_SHORTHAND_PROPERTIES = [
|
8
|
+
['margin'],
|
9
|
+
['padding'],
|
10
|
+
['border', ['border-width', 'border-style', 'border-color', 'border-image']],
|
11
|
+
['border-radius'],
|
12
|
+
['background', 'background-position'],
|
13
|
+
['font']
|
14
|
+
];
|
15
|
+
|
16
|
+
/**
|
17
|
+
* Computed this.properties property parser.
|
18
|
+
*/
|
19
|
+
export default class CSSStyleDeclarationPropertyManager {
|
20
|
+
public properties: {
|
21
|
+
[k: string]: ICSSStyleDeclarationPropertyValue;
|
22
|
+
} = {};
|
23
|
+
private definedPropertyNames: { [k: string]: boolean } = {};
|
24
|
+
|
25
|
+
/**
|
26
|
+
* Class construtor.
|
27
|
+
*
|
28
|
+
* @param [options] Options.
|
29
|
+
* @param [options.cssText] CSS string.
|
30
|
+
*/
|
31
|
+
constructor(options?: { cssText?: string }) {
|
32
|
+
if (options?.cssText) {
|
33
|
+
CSSStyleDeclarationCSSParser.parse(options.cssText, (name, value, important) => {
|
34
|
+
if (important || !this.get(name)?.important) {
|
35
|
+
this.set(name, value, important);
|
36
|
+
}
|
37
|
+
});
|
38
|
+
}
|
39
|
+
}
|
40
|
+
|
41
|
+
/**
|
42
|
+
* Returns property value.
|
43
|
+
*
|
44
|
+
* @param name Property name.
|
45
|
+
* @returns Property value.
|
46
|
+
*/
|
47
|
+
public get(name: string): ICSSStyleDeclarationPropertyValue {
|
48
|
+
if (this.properties[name]) {
|
49
|
+
return this.properties[name];
|
50
|
+
}
|
51
|
+
switch (name) {
|
52
|
+
case 'margin':
|
53
|
+
return CSSStyleDeclarationPropertyGetParser.getMargin(this.properties);
|
54
|
+
case 'padding':
|
55
|
+
return CSSStyleDeclarationPropertyGetParser.getPadding(this.properties);
|
56
|
+
case 'border':
|
57
|
+
return CSSStyleDeclarationPropertyGetParser.getBorder(this.properties);
|
58
|
+
case 'border-top':
|
59
|
+
return CSSStyleDeclarationPropertyGetParser.getBorderTop(this.properties);
|
60
|
+
case 'border-right':
|
61
|
+
return CSSStyleDeclarationPropertyGetParser.getBorderRight(this.properties);
|
62
|
+
case 'border-bottom':
|
63
|
+
return CSSStyleDeclarationPropertyGetParser.getBorderBottom(this.properties);
|
64
|
+
case 'border-left':
|
65
|
+
return CSSStyleDeclarationPropertyGetParser.getBorderLeft(this.properties);
|
66
|
+
case 'border-color':
|
67
|
+
return CSSStyleDeclarationPropertyGetParser.getBorderColor(this.properties);
|
68
|
+
case 'border-style':
|
69
|
+
return CSSStyleDeclarationPropertyGetParser.getBorderStyle(this.properties);
|
70
|
+
case 'border-width':
|
71
|
+
return CSSStyleDeclarationPropertyGetParser.getBorderWidth(this.properties);
|
72
|
+
case 'border-radius':
|
73
|
+
return CSSStyleDeclarationPropertyGetParser.getBorderRadius(this.properties);
|
74
|
+
case 'border-image':
|
75
|
+
return CSSStyleDeclarationPropertyGetParser.getBorderImage(this.properties);
|
76
|
+
case 'background':
|
77
|
+
return CSSStyleDeclarationPropertyGetParser.getBackground(this.properties);
|
78
|
+
case 'background-position':
|
79
|
+
return CSSStyleDeclarationPropertyGetParser.getBackgroundPosition(this.properties);
|
80
|
+
case 'flex':
|
81
|
+
return CSSStyleDeclarationPropertyGetParser.getFlex(this.properties);
|
82
|
+
case 'font':
|
83
|
+
return CSSStyleDeclarationPropertyGetParser.getFont(this.properties);
|
84
|
+
}
|
85
|
+
|
86
|
+
return this.properties[name] || null;
|
87
|
+
}
|
88
|
+
|
89
|
+
/**
|
90
|
+
* Removes a property.
|
91
|
+
*
|
92
|
+
* @param name Property name.
|
93
|
+
*/
|
94
|
+
public remove(name: string): void {
|
95
|
+
delete this.properties[name];
|
96
|
+
delete this.definedPropertyNames[name];
|
97
|
+
|
98
|
+
switch (name) {
|
99
|
+
case 'border':
|
100
|
+
delete this.properties['border-top-width'];
|
101
|
+
delete this.properties['border-right-width'];
|
102
|
+
delete this.properties['border-bottom-width'];
|
103
|
+
delete this.properties['border-left-width'];
|
104
|
+
delete this.properties['border-top-style'];
|
105
|
+
delete this.properties['border-right-style'];
|
106
|
+
delete this.properties['border-bottom-style'];
|
107
|
+
delete this.properties['border-left-style'];
|
108
|
+
delete this.properties['border-top-color'];
|
109
|
+
delete this.properties['border-right-color'];
|
110
|
+
delete this.properties['border-bottom-color'];
|
111
|
+
delete this.properties['border-left-color'];
|
112
|
+
delete this.properties['border-image-source'];
|
113
|
+
delete this.properties['border-image-slice'];
|
114
|
+
delete this.properties['border-image-width'];
|
115
|
+
delete this.properties['border-image-outset'];
|
116
|
+
delete this.properties['border-image-repeat'];
|
117
|
+
break;
|
118
|
+
case 'border-top':
|
119
|
+
delete this.properties['border-top-width'];
|
120
|
+
delete this.properties['border-top-style'];
|
121
|
+
delete this.properties['border-top-color'];
|
122
|
+
delete this.properties['border-image-source'];
|
123
|
+
delete this.properties['border-image-slice'];
|
124
|
+
delete this.properties['border-image-width'];
|
125
|
+
delete this.properties['border-image-outset'];
|
126
|
+
delete this.properties['border-image-repeat'];
|
127
|
+
break;
|
128
|
+
case 'border-right':
|
129
|
+
delete this.properties['border-right-width'];
|
130
|
+
delete this.properties['border-right-style'];
|
131
|
+
delete this.properties['border-right-color'];
|
132
|
+
delete this.properties['border-image-source'];
|
133
|
+
delete this.properties['border-image-slice'];
|
134
|
+
delete this.properties['border-image-width'];
|
135
|
+
delete this.properties['border-image-outset'];
|
136
|
+
delete this.properties['border-image-repeat'];
|
137
|
+
break;
|
138
|
+
case 'border-bottom':
|
139
|
+
delete this.properties['border-bottom-width'];
|
140
|
+
delete this.properties['border-bottom-style'];
|
141
|
+
delete this.properties['border-bottom-color'];
|
142
|
+
delete this.properties['border-image-source'];
|
143
|
+
delete this.properties['border-image-slice'];
|
144
|
+
delete this.properties['border-image-width'];
|
145
|
+
delete this.properties['border-image-outset'];
|
146
|
+
delete this.properties['border-image-repeat'];
|
147
|
+
break;
|
148
|
+
case 'border-left':
|
149
|
+
delete this.properties['border-left-width'];
|
150
|
+
delete this.properties['border-left-style'];
|
151
|
+
delete this.properties['border-left-color'];
|
152
|
+
delete this.properties['border-image-source'];
|
153
|
+
delete this.properties['border-image-slice'];
|
154
|
+
delete this.properties['border-image-width'];
|
155
|
+
delete this.properties['border-image-outset'];
|
156
|
+
delete this.properties['border-image-repeat'];
|
157
|
+
break;
|
158
|
+
case 'border-width':
|
159
|
+
delete this.properties['border-top-width'];
|
160
|
+
delete this.properties['border-right-width'];
|
161
|
+
delete this.properties['border-bottom-width'];
|
162
|
+
delete this.properties['border-left-width'];
|
163
|
+
break;
|
164
|
+
case 'border-style':
|
165
|
+
delete this.properties['border-top-style'];
|
166
|
+
delete this.properties['border-right-style'];
|
167
|
+
delete this.properties['border-bottom-style'];
|
168
|
+
delete this.properties['border-left-style'];
|
169
|
+
break;
|
170
|
+
case 'border-color':
|
171
|
+
delete this.properties['border-top-color'];
|
172
|
+
delete this.properties['border-right-color'];
|
173
|
+
delete this.properties['border-bottom-color'];
|
174
|
+
delete this.properties['border-left-color'];
|
175
|
+
break;
|
176
|
+
case 'border-image':
|
177
|
+
delete this.properties['border-image-source'];
|
178
|
+
delete this.properties['border-image-slice'];
|
179
|
+
delete this.properties['border-image-width'];
|
180
|
+
delete this.properties['border-image-outset'];
|
181
|
+
delete this.properties['border-image-repeat'];
|
182
|
+
break;
|
183
|
+
case 'border-radius':
|
184
|
+
delete this.properties['border-top-left-radius'];
|
185
|
+
delete this.properties['border-top-right-radius'];
|
186
|
+
delete this.properties['border-bottom-right-radius'];
|
187
|
+
delete this.properties['border-bottom-left-radius'];
|
188
|
+
break;
|
189
|
+
case 'background':
|
190
|
+
delete this.properties['background-color'];
|
191
|
+
delete this.properties['background-image'];
|
192
|
+
delete this.properties['background-repeat'];
|
193
|
+
delete this.properties['background-attachment'];
|
194
|
+
delete this.properties['background-position-x'];
|
195
|
+
delete this.properties['background-position-y'];
|
196
|
+
delete this.properties['background-size'];
|
197
|
+
delete this.properties['background-origin'];
|
198
|
+
delete this.properties['background-clip'];
|
199
|
+
break;
|
200
|
+
case 'background-position':
|
201
|
+
delete this.properties['background-position-x'];
|
202
|
+
delete this.properties['background-position-y'];
|
203
|
+
break;
|
204
|
+
case 'flex':
|
205
|
+
delete this.properties['flex-grow'];
|
206
|
+
delete this.properties['flex-shrink'];
|
207
|
+
delete this.properties['flex-basis'];
|
208
|
+
break;
|
209
|
+
case 'font':
|
210
|
+
delete this.properties['font-style'];
|
211
|
+
delete this.properties['font-variant'];
|
212
|
+
delete this.properties['font-weight'];
|
213
|
+
delete this.properties['font-stretch'];
|
214
|
+
delete this.properties['font-size'];
|
215
|
+
delete this.properties['line-height'];
|
216
|
+
delete this.properties['font-family'];
|
217
|
+
break;
|
218
|
+
case 'padding':
|
219
|
+
delete this.properties['padding-top'];
|
220
|
+
delete this.properties['padding-right'];
|
221
|
+
delete this.properties['padding-bottom'];
|
222
|
+
delete this.properties['padding-left'];
|
223
|
+
break;
|
224
|
+
case 'margin':
|
225
|
+
delete this.properties['margin-top'];
|
226
|
+
delete this.properties['margin-right'];
|
227
|
+
delete this.properties['margin-bottom'];
|
228
|
+
delete this.properties['margin-left'];
|
229
|
+
break;
|
230
|
+
}
|
231
|
+
}
|
232
|
+
|
233
|
+
/**
|
234
|
+
* Sets a property
|
235
|
+
*
|
236
|
+
* @param name Name.
|
237
|
+
* @param value Value.
|
238
|
+
* @param important Important.
|
239
|
+
*/
|
240
|
+
public set(name: string, value: string, important: boolean): void {
|
241
|
+
if (value === null) {
|
242
|
+
this.remove(name);
|
243
|
+
return;
|
244
|
+
}
|
245
|
+
|
246
|
+
let properties = null;
|
247
|
+
|
248
|
+
switch (name) {
|
249
|
+
case 'border':
|
250
|
+
properties = CSSStyleDeclarationPropertySetParser.getBorder(value, important);
|
251
|
+
break;
|
252
|
+
case 'border-top':
|
253
|
+
properties = CSSStyleDeclarationPropertySetParser.getBorderTop(value, important);
|
254
|
+
break;
|
255
|
+
case 'border-right':
|
256
|
+
properties = CSSStyleDeclarationPropertySetParser.getBorderRight(value, important);
|
257
|
+
break;
|
258
|
+
case 'border-bottom':
|
259
|
+
properties = CSSStyleDeclarationPropertySetParser.getBorderBottom(value, important);
|
260
|
+
break;
|
261
|
+
case 'border-left':
|
262
|
+
properties = CSSStyleDeclarationPropertySetParser.getBorderLeft(value, important);
|
263
|
+
break;
|
264
|
+
case 'border-width':
|
265
|
+
properties = CSSStyleDeclarationPropertySetParser.getBorderWidth(value, important);
|
266
|
+
break;
|
267
|
+
case 'border-style':
|
268
|
+
properties = CSSStyleDeclarationPropertySetParser.getBorderStyle(value, important);
|
269
|
+
break;
|
270
|
+
case 'border-color':
|
271
|
+
properties = CSSStyleDeclarationPropertySetParser.getBorderColor(value, important);
|
272
|
+
break;
|
273
|
+
case 'border-image':
|
274
|
+
properties = CSSStyleDeclarationPropertySetParser.getBorderImage(value, important);
|
275
|
+
break;
|
276
|
+
case 'border-image-source':
|
277
|
+
properties = CSSStyleDeclarationPropertySetParser.getBorderImageSource(value, important);
|
278
|
+
break;
|
279
|
+
case 'border-image-slice':
|
280
|
+
properties = CSSStyleDeclarationPropertySetParser.getBorderImageSlice(value, important);
|
281
|
+
break;
|
282
|
+
case 'border-image-width':
|
283
|
+
properties = CSSStyleDeclarationPropertySetParser.getBorderImageWidth(value, important);
|
284
|
+
break;
|
285
|
+
case 'border-image-outset':
|
286
|
+
properties = CSSStyleDeclarationPropertySetParser.getBorderImageOutset(value, important);
|
287
|
+
break;
|
288
|
+
case 'border-image-repeat':
|
289
|
+
properties = CSSStyleDeclarationPropertySetParser.getBorderImageRepeat(value, important);
|
290
|
+
break;
|
291
|
+
case 'border-top-width':
|
292
|
+
properties = CSSStyleDeclarationPropertySetParser.getBorderTopWidth(value, important);
|
293
|
+
break;
|
294
|
+
case 'border-right-width':
|
295
|
+
properties = CSSStyleDeclarationPropertySetParser.getBorderRightWidth(value, important);
|
296
|
+
break;
|
297
|
+
case 'border-bottom-width':
|
298
|
+
properties = CSSStyleDeclarationPropertySetParser.getBorderBottomWidth(value, important);
|
299
|
+
break;
|
300
|
+
case 'border-left-width':
|
301
|
+
properties = CSSStyleDeclarationPropertySetParser.getBorderLeftWidth(value, important);
|
302
|
+
break;
|
303
|
+
case 'border-top-color':
|
304
|
+
properties = CSSStyleDeclarationPropertySetParser.getBorderTopColor(value, important);
|
305
|
+
break;
|
306
|
+
case 'border-right-color':
|
307
|
+
properties = CSSStyleDeclarationPropertySetParser.getBorderRightColor(value, important);
|
308
|
+
break;
|
309
|
+
case 'border-bottom-color':
|
310
|
+
properties = CSSStyleDeclarationPropertySetParser.getBorderBottomColor(value, important);
|
311
|
+
break;
|
312
|
+
case 'border-left-color':
|
313
|
+
properties = CSSStyleDeclarationPropertySetParser.getBorderLeftColor(value, important);
|
314
|
+
break;
|
315
|
+
case 'border-top-style':
|
316
|
+
properties = CSSStyleDeclarationPropertySetParser.getBorderTopStyle(value, important);
|
317
|
+
break;
|
318
|
+
case 'border-right-style':
|
319
|
+
properties = CSSStyleDeclarationPropertySetParser.getBorderRightStyle(value, important);
|
320
|
+
break;
|
321
|
+
case 'border-bottom-style':
|
322
|
+
properties = CSSStyleDeclarationPropertySetParser.getBorderBottomStyle(value, important);
|
323
|
+
break;
|
324
|
+
case 'border-left-style':
|
325
|
+
properties = CSSStyleDeclarationPropertySetParser.getBorderLeftStyle(value, important);
|
326
|
+
break;
|
327
|
+
case 'border-radius':
|
328
|
+
properties = CSSStyleDeclarationPropertySetParser.getBorderRadius(value, important);
|
329
|
+
break;
|
330
|
+
case 'border-top-left-radius':
|
331
|
+
properties = CSSStyleDeclarationPropertySetParser.getBorderTopLeftRadius(value, important);
|
332
|
+
break;
|
333
|
+
case 'border-top-right-radius':
|
334
|
+
properties = CSSStyleDeclarationPropertySetParser.getBorderTopRightRadius(value, important);
|
335
|
+
break;
|
336
|
+
case 'border-bottom-right-radius':
|
337
|
+
properties = CSSStyleDeclarationPropertySetParser.getBorderBottomRightRadius(
|
338
|
+
value,
|
339
|
+
important
|
340
|
+
);
|
341
|
+
break;
|
342
|
+
case 'border-bottom-right-radius':
|
343
|
+
properties = CSSStyleDeclarationPropertySetParser.getBorderBottomLeftRadius(
|
344
|
+
value,
|
345
|
+
important
|
346
|
+
);
|
347
|
+
break;
|
348
|
+
case 'border-collapse':
|
349
|
+
properties = CSSStyleDeclarationPropertySetParser.getBorderCollapse(value, important);
|
350
|
+
break;
|
351
|
+
case 'clear':
|
352
|
+
properties = CSSStyleDeclarationPropertySetParser.getClear(value, important);
|
353
|
+
break;
|
354
|
+
case 'clip':
|
355
|
+
properties = CSSStyleDeclarationPropertySetParser.getClip(value, important);
|
356
|
+
break;
|
357
|
+
case 'css-float':
|
358
|
+
properties = CSSStyleDeclarationPropertySetParser.getCSSFloat(value, important);
|
359
|
+
break;
|
360
|
+
case 'float':
|
361
|
+
properties = CSSStyleDeclarationPropertySetParser.getFloat(value, important);
|
362
|
+
break;
|
363
|
+
case 'display':
|
364
|
+
properties = CSSStyleDeclarationPropertySetParser.getDisplay(value, important);
|
365
|
+
break;
|
366
|
+
case 'direction':
|
367
|
+
properties = CSSStyleDeclarationPropertySetParser.getDirection(value, important);
|
368
|
+
break;
|
369
|
+
case 'flex':
|
370
|
+
properties = CSSStyleDeclarationPropertySetParser.getFlex(value, important);
|
371
|
+
break;
|
372
|
+
case 'flex-shrink':
|
373
|
+
properties = CSSStyleDeclarationPropertySetParser.getFlexShrink(value, important);
|
374
|
+
break;
|
375
|
+
case 'flex-grow':
|
376
|
+
properties = CSSStyleDeclarationPropertySetParser.getFlexGrow(value, important);
|
377
|
+
break;
|
378
|
+
case 'flex-basis':
|
379
|
+
properties = CSSStyleDeclarationPropertySetParser.getFlexBasis(value, important);
|
380
|
+
break;
|
381
|
+
case 'padding':
|
382
|
+
properties = CSSStyleDeclarationPropertySetParser.getPadding(value, important);
|
383
|
+
break;
|
384
|
+
case 'padding-top':
|
385
|
+
properties = CSSStyleDeclarationPropertySetParser.getPaddingTop(value, important);
|
386
|
+
break;
|
387
|
+
case 'padding-right':
|
388
|
+
properties = CSSStyleDeclarationPropertySetParser.getPaddingRight(value, important);
|
389
|
+
break;
|
390
|
+
case 'padding-bottom':
|
391
|
+
properties = CSSStyleDeclarationPropertySetParser.getPaddingBottom(value, important);
|
392
|
+
break;
|
393
|
+
case 'padding-left':
|
394
|
+
properties = CSSStyleDeclarationPropertySetParser.getPaddingLeft(value, important);
|
395
|
+
break;
|
396
|
+
case 'margin':
|
397
|
+
properties = CSSStyleDeclarationPropertySetParser.getMargin(value, important);
|
398
|
+
break;
|
399
|
+
case 'margin-top':
|
400
|
+
properties = CSSStyleDeclarationPropertySetParser.getMarginTop(value, important);
|
401
|
+
break;
|
402
|
+
case 'margin-right':
|
403
|
+
properties = CSSStyleDeclarationPropertySetParser.getMarginRight(value, important);
|
404
|
+
break;
|
405
|
+
case 'margin-bottom':
|
406
|
+
properties = CSSStyleDeclarationPropertySetParser.getMarginBottom(value, important);
|
407
|
+
break;
|
408
|
+
case 'margin-left':
|
409
|
+
properties = CSSStyleDeclarationPropertySetParser.getMarginLeft(value, important);
|
410
|
+
break;
|
411
|
+
case 'background':
|
412
|
+
properties = CSSStyleDeclarationPropertySetParser.getBackground(value, important);
|
413
|
+
break;
|
414
|
+
case 'background-image':
|
415
|
+
properties = CSSStyleDeclarationPropertySetParser.getBackgroundImage(value, important);
|
416
|
+
break;
|
417
|
+
case 'background-color':
|
418
|
+
properties = CSSStyleDeclarationPropertySetParser.getBackgroundColor(value, important);
|
419
|
+
break;
|
420
|
+
case 'background-repeat':
|
421
|
+
properties = CSSStyleDeclarationPropertySetParser.getBackgroundRepeat(value, important);
|
422
|
+
break;
|
423
|
+
case 'background-attachment':
|
424
|
+
properties = CSSStyleDeclarationPropertySetParser.getBackgroundAttachment(value, important);
|
425
|
+
break;
|
426
|
+
case 'background-position':
|
427
|
+
properties = CSSStyleDeclarationPropertySetParser.getBackgroundPosition(value, important);
|
428
|
+
break;
|
429
|
+
case 'width':
|
430
|
+
properties = CSSStyleDeclarationPropertySetParser.getWidth(value, important);
|
431
|
+
break;
|
432
|
+
case 'top':
|
433
|
+
properties = CSSStyleDeclarationPropertySetParser.getTop(value, important);
|
434
|
+
break;
|
435
|
+
case 'right':
|
436
|
+
properties = CSSStyleDeclarationPropertySetParser.getRight(value, important);
|
437
|
+
break;
|
438
|
+
case 'bottom':
|
439
|
+
properties = CSSStyleDeclarationPropertySetParser.getBottom(value, important);
|
440
|
+
break;
|
441
|
+
case 'left':
|
442
|
+
properties = CSSStyleDeclarationPropertySetParser.getLeft(value, important);
|
443
|
+
break;
|
444
|
+
case 'font':
|
445
|
+
properties = CSSStyleDeclarationPropertySetParser.getFont(value, important);
|
446
|
+
break;
|
447
|
+
case 'font-style':
|
448
|
+
properties = CSSStyleDeclarationPropertySetParser.getFontStyle(value, important);
|
449
|
+
break;
|
450
|
+
case 'font-variant':
|
451
|
+
properties = CSSStyleDeclarationPropertySetParser.getFontVariant(value, important);
|
452
|
+
break;
|
453
|
+
case 'font-weight':
|
454
|
+
properties = CSSStyleDeclarationPropertySetParser.getFontWeight(value, important);
|
455
|
+
break;
|
456
|
+
case 'font-stretch':
|
457
|
+
properties = CSSStyleDeclarationPropertySetParser.getFontStretch(value, important);
|
458
|
+
break;
|
459
|
+
case 'font-size':
|
460
|
+
properties = CSSStyleDeclarationPropertySetParser.getFontSize(value, important);
|
461
|
+
break;
|
462
|
+
case 'line-height':
|
463
|
+
properties = CSSStyleDeclarationPropertySetParser.getLineHeight(value, important);
|
464
|
+
break;
|
465
|
+
case 'font-family':
|
466
|
+
properties = CSSStyleDeclarationPropertySetParser.getFontFamily(value, important);
|
467
|
+
break;
|
468
|
+
case 'color':
|
469
|
+
properties = CSSStyleDeclarationPropertySetParser.getColor(value, important);
|
470
|
+
break;
|
471
|
+
case 'flood-color':
|
472
|
+
properties = CSSStyleDeclarationPropertySetParser.getFloodColor(value, important);
|
473
|
+
break;
|
474
|
+
case 'text-transform':
|
475
|
+
properties = CSSStyleDeclarationPropertySetParser.getTextTransform(value, important);
|
476
|
+
break;
|
477
|
+
case 'visibility':
|
478
|
+
properties = CSSStyleDeclarationPropertySetParser.getVisibility(value, important);
|
479
|
+
break;
|
480
|
+
default:
|
481
|
+
const trimmedValue = value.trim();
|
482
|
+
if (trimmedValue) {
|
483
|
+
const globalValue = CSSStyleDeclarationValueParser.getGlobal(trimmedValue);
|
484
|
+
properties = {
|
485
|
+
[name]: { value: globalValue || trimmedValue, important }
|
486
|
+
};
|
487
|
+
}
|
488
|
+
break;
|
489
|
+
}
|
490
|
+
|
491
|
+
if (properties !== null && Object.keys(properties).length > 0) {
|
492
|
+
this.definedPropertyNames[name] = true;
|
493
|
+
Object.assign(this.properties, properties);
|
494
|
+
}
|
495
|
+
}
|
496
|
+
|
497
|
+
/**
|
498
|
+
* Returns a clone.
|
499
|
+
*
|
500
|
+
* @returns Clone.
|
501
|
+
*/
|
502
|
+
public clone(): CSSStyleDeclarationPropertyManager {
|
503
|
+
const _class = <typeof CSSStyleDeclarationPropertyManager>this.constructor;
|
504
|
+
const clone: CSSStyleDeclarationPropertyManager = new _class();
|
505
|
+
|
506
|
+
clone.properties = JSON.parse(JSON.stringify(this.properties));
|
507
|
+
clone.definedPropertyNames = Object.assign({}, this.definedPropertyNames);
|
508
|
+
|
509
|
+
return clone;
|
510
|
+
}
|
511
|
+
|
512
|
+
/**
|
513
|
+
* Returns size.
|
514
|
+
*
|
515
|
+
* @returns Size.
|
516
|
+
*/
|
517
|
+
public size(): number {
|
518
|
+
return Object.keys(this.properties).length;
|
519
|
+
}
|
520
|
+
|
521
|
+
/**
|
522
|
+
* Returns property name.
|
523
|
+
*
|
524
|
+
* @param index Index.
|
525
|
+
* @returns Property name.
|
526
|
+
*/
|
527
|
+
public item(index: number): string {
|
528
|
+
return Object.keys(this.properties)[index] || '';
|
529
|
+
}
|
530
|
+
|
531
|
+
/**
|
532
|
+
* Converts properties to string.
|
533
|
+
*
|
534
|
+
* @returns String.
|
535
|
+
*/
|
536
|
+
public toString(): string {
|
537
|
+
const result = [];
|
538
|
+
const clone = this.clone();
|
539
|
+
const properties = {};
|
540
|
+
|
541
|
+
for (const shorthandPropertyGroup of TO_STRING_SHORTHAND_PROPERTIES) {
|
542
|
+
for (const shorthandProperty of shorthandPropertyGroup) {
|
543
|
+
if (Array.isArray(shorthandProperty)) {
|
544
|
+
let isMatch = false;
|
545
|
+
for (const childShorthandProperty of shorthandProperty) {
|
546
|
+
const property = clone.get(childShorthandProperty);
|
547
|
+
if (property) {
|
548
|
+
properties[childShorthandProperty] = property;
|
549
|
+
clone.remove(childShorthandProperty);
|
550
|
+
isMatch = true;
|
551
|
+
}
|
552
|
+
}
|
553
|
+
if (isMatch) {
|
554
|
+
break;
|
555
|
+
}
|
556
|
+
} else {
|
557
|
+
const property = clone.get(shorthandProperty);
|
558
|
+
if (property) {
|
559
|
+
properties[shorthandProperty] = property;
|
560
|
+
clone.remove(shorthandProperty);
|
561
|
+
break;
|
562
|
+
}
|
563
|
+
}
|
564
|
+
}
|
565
|
+
}
|
566
|
+
|
567
|
+
for (const name of Object.keys(clone.properties)) {
|
568
|
+
properties[name] = clone.get(name);
|
569
|
+
}
|
570
|
+
|
571
|
+
for (const definedPropertyName of Object.keys(this.definedPropertyNames)) {
|
572
|
+
const property = properties[definedPropertyName];
|
573
|
+
if (property) {
|
574
|
+
result.push(
|
575
|
+
`${definedPropertyName}: ${property.value}${property.important ? ' !important' : ''};`
|
576
|
+
);
|
577
|
+
delete properties[definedPropertyName];
|
578
|
+
}
|
579
|
+
}
|
580
|
+
|
581
|
+
for (const propertyName of Object.keys(properties)) {
|
582
|
+
const property = properties[propertyName];
|
583
|
+
if (property) {
|
584
|
+
result.push(
|
585
|
+
`${propertyName}: ${property.value}${property.important ? ' !important' : ''};`
|
586
|
+
);
|
587
|
+
}
|
588
|
+
}
|
589
|
+
|
590
|
+
return result.join(' ');
|
591
|
+
}
|
592
|
+
}
|