cssstyle 2.3.0 → 4.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.
- package/README.md +3 -3
- package/lib/CSSStyleDeclaration.js +31 -25
- package/lib/CSSStyleDeclaration.test.js +187 -6
- package/lib/allProperties.js +66 -9
- package/lib/allWebkitProperties.js +1 -1
- package/lib/implementedProperties.js +1 -1
- package/lib/parsers.js +43 -30
- package/lib/parsers.test.js +8 -1
- package/lib/properties/azimuth.js +3 -6
- package/lib/properties/backgroundAttachment.js +2 -2
- package/lib/properties/backgroundColor.js +2 -2
- package/lib/properties/backgroundImage.js +2 -2
- package/lib/properties/backgroundPosition.js +3 -3
- package/lib/properties/backgroundRepeat.js +2 -2
- package/lib/properties/border.js +1 -1
- package/lib/properties/borderBottomColor.js +2 -2
- package/lib/properties/borderBottomStyle.js +2 -2
- package/lib/properties/borderBottomWidth.js +2 -2
- package/lib/properties/borderCollapse.js +2 -2
- package/lib/properties/borderColor.js +2 -2
- package/lib/properties/borderLeftColor.js +2 -2
- package/lib/properties/borderLeftStyle.js +2 -2
- package/lib/properties/borderLeftWidth.js +2 -2
- package/lib/properties/borderRightColor.js +2 -2
- package/lib/properties/borderRightStyle.js +2 -2
- package/lib/properties/borderRightWidth.js +2 -2
- package/lib/properties/borderSpacing.js +3 -3
- package/lib/properties/borderStyle.js +2 -2
- package/lib/properties/borderTopColor.js +2 -2
- package/lib/properties/borderTopStyle.js +2 -2
- package/lib/properties/borderTopWidth.js +2 -2
- package/lib/properties/borderWidth.js +2 -2
- package/lib/properties/bottom.js +2 -2
- package/lib/properties/clear.js +2 -2
- package/lib/properties/clip.js +4 -4
- package/lib/properties/color.js +2 -2
- package/lib/properties/cssFloat.js +2 -2
- package/lib/properties/flex.js +2 -4
- package/lib/properties/flexBasis.js +2 -2
- package/lib/properties/flexGrow.js +2 -2
- package/lib/properties/flexShrink.js +2 -2
- package/lib/properties/float.js +2 -2
- package/lib/properties/floodColor.js +2 -2
- package/lib/properties/font.js +1 -1
- package/lib/properties/fontFamily.js +2 -2
- package/lib/properties/fontSize.js +4 -4
- package/lib/properties/fontStyle.js +3 -3
- package/lib/properties/fontVariant.js +2 -2
- package/lib/properties/fontWeight.js +2 -2
- package/lib/properties/height.js +2 -2
- package/lib/properties/left.js +2 -2
- package/lib/properties/lightingColor.js +2 -2
- package/lib/properties/lineHeight.js +2 -2
- package/lib/properties/margin.js +10 -6
- package/lib/properties/marginBottom.js +1 -1
- package/lib/properties/marginLeft.js +1 -1
- package/lib/properties/marginRight.js +1 -1
- package/lib/properties/marginTop.js +1 -1
- package/lib/properties/opacity.js +2 -2
- package/lib/properties/outlineColor.js +2 -2
- package/lib/properties/padding.js +10 -6
- package/lib/properties/paddingBottom.js +1 -1
- package/lib/properties/paddingLeft.js +1 -1
- package/lib/properties/paddingRight.js +1 -1
- package/lib/properties/paddingTop.js +1 -1
- package/lib/properties/right.js +2 -2
- package/lib/properties/stopColor.js +2 -2
- package/lib/properties/textLineThroughColor.js +2 -2
- package/lib/properties/textOverlineColor.js +2 -2
- package/lib/properties/textUnderlineColor.js +2 -2
- package/lib/properties/top.js +2 -2
- package/lib/properties/webkitBorderAfterColor.js +2 -2
- package/lib/properties/webkitBorderBeforeColor.js +2 -2
- package/lib/properties/webkitBorderEndColor.js +2 -2
- package/lib/properties/webkitBorderStartColor.js +2 -2
- package/lib/properties/webkitColumnRuleColor.js +2 -2
- package/lib/properties/webkitMatchNearestMailBlockquoteColor.js +2 -2
- package/lib/properties/webkitTapHighlightColor.js +2 -2
- package/lib/properties/webkitTextEmphasisColor.js +2 -2
- package/lib/properties/webkitTextFillColor.js +2 -2
- package/lib/properties/webkitTextStrokeColor.js +2 -2
- package/lib/properties/width.js +2 -2
- package/lib/properties.js +11 -3
- package/lib/utils/colorSpace.js +13 -15
- package/lib/utils/getBasicPropertyDescriptor.js +2 -2
- package/package.json +14 -15
package/README.md
CHANGED
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
A Node JS implementation of the CSS Object Model [CSSStyleDeclaration interface](https://www.w3.org/TR/cssom-1/#the-cssstyledeclaration-interface).
|
|
4
4
|
|
|
5
|
-
[](https://www.npmjs.com/package/cssstyle) [](https://www.npmjs.com/package/cssstyle) [](https://travis-ci.org/jsdom/cssstyle) [](https://codecov.io/gh/jsdom/cssstyle)
|
|
6
6
|
|
|
7
7
|
---
|
|
8
8
|
|
|
9
9
|
#### Background
|
|
10
10
|
|
|
11
|
-
This package is an extension of the CSSStyleDeclaration class in Nikita Vasilyev's [CSSOM](https://github.com/NV/CSSOM) with added support for CSS 2 & 3 properties. The primary use case is for testing browser code in a Node environment.
|
|
11
|
+
This package is an extension of the CSSStyleDeclaration class in Nikita Vasilyev's [CSSOM](https://github.com/NV/CSSOM) with added support for CSS 2 & 3 properties. The primary use case is for testing browser code in a Node environment.
|
|
12
12
|
|
|
13
|
-
It was originally created by Chad Walker, it is now
|
|
13
|
+
It was originally created by Chad Walker, it is now maintained by the jsdom community.
|
|
14
14
|
|
|
15
15
|
Bug reports and pull requests are welcome.
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* https://github.com/NV/CSSOM
|
|
4
4
|
********************************************************************/
|
|
5
5
|
'use strict';
|
|
6
|
-
var CSSOM = require('cssom');
|
|
6
|
+
var CSSOM = require('rrweb-cssom');
|
|
7
7
|
var allProperties = require('./allProperties');
|
|
8
8
|
var allExtraProperties = require('./allExtraProperties');
|
|
9
9
|
var implementedProperties = require('./implementedProperties');
|
|
@@ -18,11 +18,8 @@ var CSSStyleDeclaration = function CSSStyleDeclaration(onChangeCallback) {
|
|
|
18
18
|
this._values = {};
|
|
19
19
|
this._importants = {};
|
|
20
20
|
this._length = 0;
|
|
21
|
-
this._onChange =
|
|
22
|
-
|
|
23
|
-
function() {
|
|
24
|
-
return;
|
|
25
|
-
};
|
|
21
|
+
this._onChange = onChangeCallback;
|
|
22
|
+
this._setInProgress = false;
|
|
26
23
|
};
|
|
27
24
|
CSSStyleDeclaration.prototype = {
|
|
28
25
|
constructor: CSSStyleDeclaration,
|
|
@@ -34,7 +31,7 @@ CSSStyleDeclaration.prototype = {
|
|
|
34
31
|
* @return {string} the value of the property if it has been explicitly set for this declaration block.
|
|
35
32
|
* Returns the empty string if the property has not been set.
|
|
36
33
|
*/
|
|
37
|
-
getPropertyValue: function(name) {
|
|
34
|
+
getPropertyValue: function (name) {
|
|
38
35
|
if (!this._values.hasOwnProperty(name)) {
|
|
39
36
|
return '';
|
|
40
37
|
}
|
|
@@ -48,7 +45,7 @@ CSSStyleDeclaration.prototype = {
|
|
|
48
45
|
* @param {string} [priority=null] "important" or null
|
|
49
46
|
* @see http://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-CSSStyleDeclaration-setProperty
|
|
50
47
|
*/
|
|
51
|
-
setProperty: function(name, value, priority) {
|
|
48
|
+
setProperty: function (name, value, priority) {
|
|
52
49
|
if (value === undefined) {
|
|
53
50
|
return;
|
|
54
51
|
}
|
|
@@ -69,7 +66,7 @@ CSSStyleDeclaration.prototype = {
|
|
|
69
66
|
this[lowercaseName] = value;
|
|
70
67
|
this._importants[lowercaseName] = priority;
|
|
71
68
|
},
|
|
72
|
-
_setProperty: function(name, value, priority) {
|
|
69
|
+
_setProperty: function (name, value, priority) {
|
|
73
70
|
if (value === undefined) {
|
|
74
71
|
return;
|
|
75
72
|
}
|
|
@@ -77,6 +74,7 @@ CSSStyleDeclaration.prototype = {
|
|
|
77
74
|
this.removeProperty(name);
|
|
78
75
|
return;
|
|
79
76
|
}
|
|
77
|
+
var originalText = this.cssText;
|
|
80
78
|
if (this._values[name]) {
|
|
81
79
|
// Property already exist. Overwrite it.
|
|
82
80
|
var index = Array.prototype.indexOf.call(this, name);
|
|
@@ -91,7 +89,9 @@ CSSStyleDeclaration.prototype = {
|
|
|
91
89
|
}
|
|
92
90
|
this._values[name] = value;
|
|
93
91
|
this._importants[name] = priority;
|
|
94
|
-
this._onChange
|
|
92
|
+
if (this._onChange && this.cssText !== originalText && !this._setInProgress) {
|
|
93
|
+
this._onChange(this.cssText);
|
|
94
|
+
}
|
|
95
95
|
},
|
|
96
96
|
|
|
97
97
|
/**
|
|
@@ -101,7 +101,7 @@ CSSStyleDeclaration.prototype = {
|
|
|
101
101
|
* @return {string} the value of the property if it has been explicitly set for this declaration block.
|
|
102
102
|
* Returns the empty string if the property has not been set or the property name does not correspond to a known CSS property.
|
|
103
103
|
*/
|
|
104
|
-
removeProperty: function(name) {
|
|
104
|
+
removeProperty: function (name) {
|
|
105
105
|
if (!this._values.hasOwnProperty(name)) {
|
|
106
106
|
return '';
|
|
107
107
|
}
|
|
@@ -121,7 +121,9 @@ CSSStyleDeclaration.prototype = {
|
|
|
121
121
|
// That's what Firefox does
|
|
122
122
|
//this[index] = ""
|
|
123
123
|
|
|
124
|
-
this._onChange
|
|
124
|
+
if (this._onChange) {
|
|
125
|
+
this._onChange(this.cssText);
|
|
126
|
+
}
|
|
125
127
|
return prevValue;
|
|
126
128
|
},
|
|
127
129
|
|
|
@@ -129,11 +131,11 @@ CSSStyleDeclaration.prototype = {
|
|
|
129
131
|
*
|
|
130
132
|
* @param {String} name
|
|
131
133
|
*/
|
|
132
|
-
getPropertyPriority: function(name) {
|
|
134
|
+
getPropertyPriority: function (name) {
|
|
133
135
|
return this._importants[name] || '';
|
|
134
136
|
},
|
|
135
137
|
|
|
136
|
-
getPropertyCSSValue: function() {
|
|
138
|
+
getPropertyCSSValue: function () {
|
|
137
139
|
//FIXME
|
|
138
140
|
return;
|
|
139
141
|
},
|
|
@@ -143,12 +145,12 @@ CSSStyleDeclaration.prototype = {
|
|
|
143
145
|
* element.style.getPropertyShorthand("overflow-x")
|
|
144
146
|
* -> "overflow"
|
|
145
147
|
*/
|
|
146
|
-
getPropertyShorthand: function() {
|
|
148
|
+
getPropertyShorthand: function () {
|
|
147
149
|
//FIXME
|
|
148
150
|
return;
|
|
149
151
|
},
|
|
150
152
|
|
|
151
|
-
isPropertyImplicit: function() {
|
|
153
|
+
isPropertyImplicit: function () {
|
|
152
154
|
//FIXME
|
|
153
155
|
return;
|
|
154
156
|
},
|
|
@@ -156,7 +158,7 @@ CSSStyleDeclaration.prototype = {
|
|
|
156
158
|
/**
|
|
157
159
|
* http://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-CSSStyleDeclaration-item
|
|
158
160
|
*/
|
|
159
|
-
item: function(index) {
|
|
161
|
+
item: function (index) {
|
|
160
162
|
index = parseInt(index, 10);
|
|
161
163
|
if (index < 0 || index >= this._length) {
|
|
162
164
|
return '';
|
|
@@ -167,7 +169,7 @@ CSSStyleDeclaration.prototype = {
|
|
|
167
169
|
|
|
168
170
|
Object.defineProperties(CSSStyleDeclaration.prototype, {
|
|
169
171
|
cssText: {
|
|
170
|
-
get: function() {
|
|
172
|
+
get: function () {
|
|
171
173
|
var properties = [];
|
|
172
174
|
var i;
|
|
173
175
|
var name;
|
|
@@ -184,7 +186,7 @@ Object.defineProperties(CSSStyleDeclaration.prototype, {
|
|
|
184
186
|
}
|
|
185
187
|
return properties.join(' ');
|
|
186
188
|
},
|
|
187
|
-
set: function(value) {
|
|
189
|
+
set: function (value) {
|
|
188
190
|
var i;
|
|
189
191
|
this._values = {};
|
|
190
192
|
Array.prototype.splice.call(this, 0, this._length);
|
|
@@ -196,6 +198,7 @@ Object.defineProperties(CSSStyleDeclaration.prototype, {
|
|
|
196
198
|
// malformed css, just return
|
|
197
199
|
return;
|
|
198
200
|
}
|
|
201
|
+
this._setInProgress = true;
|
|
199
202
|
var rule_length = dummyRule.length;
|
|
200
203
|
var name;
|
|
201
204
|
for (i = 0; i < rule_length; ++i) {
|
|
@@ -206,20 +209,23 @@ Object.defineProperties(CSSStyleDeclaration.prototype, {
|
|
|
206
209
|
dummyRule.getPropertyPriority(name)
|
|
207
210
|
);
|
|
208
211
|
}
|
|
209
|
-
this.
|
|
212
|
+
this._setInProgress = false;
|
|
213
|
+
if (this._onChange) {
|
|
214
|
+
this._onChange(this.cssText);
|
|
215
|
+
}
|
|
210
216
|
},
|
|
211
217
|
enumerable: true,
|
|
212
218
|
configurable: true,
|
|
213
219
|
},
|
|
214
220
|
parentRule: {
|
|
215
|
-
get: function() {
|
|
221
|
+
get: function () {
|
|
216
222
|
return null;
|
|
217
223
|
},
|
|
218
224
|
enumerable: true,
|
|
219
225
|
configurable: true,
|
|
220
226
|
},
|
|
221
227
|
length: {
|
|
222
|
-
get: function() {
|
|
228
|
+
get: function () {
|
|
223
229
|
return this._length;
|
|
224
230
|
},
|
|
225
231
|
/**
|
|
@@ -227,7 +233,7 @@ Object.defineProperties(CSSStyleDeclaration.prototype, {
|
|
|
227
233
|
* length. If the new length is more, it does nothing, the new indices
|
|
228
234
|
* will be undefined until set.
|
|
229
235
|
**/
|
|
230
|
-
set: function(value) {
|
|
236
|
+
set: function (value) {
|
|
231
237
|
var i;
|
|
232
238
|
for (i = value; i < this._length; i++) {
|
|
233
239
|
delete this[i];
|
|
@@ -241,7 +247,7 @@ Object.defineProperties(CSSStyleDeclaration.prototype, {
|
|
|
241
247
|
|
|
242
248
|
require('./properties')(CSSStyleDeclaration.prototype);
|
|
243
249
|
|
|
244
|
-
allProperties.forEach(function(property) {
|
|
250
|
+
allProperties.forEach(function (property) {
|
|
245
251
|
if (!implementedProperties.has(property)) {
|
|
246
252
|
var declaration = getBasicPropertyDescriptor(property);
|
|
247
253
|
Object.defineProperty(CSSStyleDeclaration.prototype, property, declaration);
|
|
@@ -249,7 +255,7 @@ allProperties.forEach(function(property) {
|
|
|
249
255
|
}
|
|
250
256
|
});
|
|
251
257
|
|
|
252
|
-
allExtraProperties.forEach(function(property) {
|
|
258
|
+
allExtraProperties.forEach(function (property) {
|
|
253
259
|
if (!implementedProperties.has(property)) {
|
|
254
260
|
var declaration = getBasicPropertyDescriptor(property);
|
|
255
261
|
Object.defineProperty(CSSStyleDeclaration.prototype, property, declaration);
|
|
@@ -10,7 +10,7 @@ var parsers = require('./parsers');
|
|
|
10
10
|
var dashedProperties = [...allProperties, ...allExtraProperties];
|
|
11
11
|
var allowedProperties = dashedProperties.map(parsers.dashedToCamelCase);
|
|
12
12
|
implementedProperties = Array.from(implementedProperties).map(parsers.dashedToCamelCase);
|
|
13
|
-
var invalidProperties = implementedProperties.filter(prop => !allowedProperties.includes(prop));
|
|
13
|
+
var invalidProperties = implementedProperties.filter((prop) => !allowedProperties.includes(prop));
|
|
14
14
|
|
|
15
15
|
describe('CSSStyleDeclaration', () => {
|
|
16
16
|
test('has only valid properties implemented', () => {
|
|
@@ -19,7 +19,7 @@ describe('CSSStyleDeclaration', () => {
|
|
|
19
19
|
|
|
20
20
|
test('has all properties', () => {
|
|
21
21
|
var style = new CSSStyleDeclaration();
|
|
22
|
-
allProperties.forEach(property => {
|
|
22
|
+
allProperties.forEach((property) => {
|
|
23
23
|
expect(style.__lookupGetter__(property)).toBeTruthy();
|
|
24
24
|
expect(style.__lookupSetter__(property)).toBeTruthy();
|
|
25
25
|
});
|
|
@@ -27,7 +27,7 @@ describe('CSSStyleDeclaration', () => {
|
|
|
27
27
|
|
|
28
28
|
test('has dashed properties', () => {
|
|
29
29
|
var style = new CSSStyleDeclaration();
|
|
30
|
-
dashedProperties.forEach(property => {
|
|
30
|
+
dashedProperties.forEach((property) => {
|
|
31
31
|
expect(style.__lookupGetter__(property)).toBeTruthy();
|
|
32
32
|
expect(style.__lookupSetter__(property)).toBeTruthy();
|
|
33
33
|
});
|
|
@@ -302,7 +302,7 @@ describe('CSSStyleDeclaration', () => {
|
|
|
302
302
|
test('padding and margin should set/clear shorthand properties', () => {
|
|
303
303
|
var style = new CSSStyleDeclaration();
|
|
304
304
|
var parts = ['Top', 'Right', 'Bottom', 'Left'];
|
|
305
|
-
var testParts = function(name, v, V) {
|
|
305
|
+
var testParts = function (name, v, V) {
|
|
306
306
|
style[name] = v;
|
|
307
307
|
for (var i = 0; i < 4; i++) {
|
|
308
308
|
var part = name + parts[i];
|
|
@@ -329,7 +329,7 @@ describe('CSSStyleDeclaration', () => {
|
|
|
329
329
|
test('padding and margin shorthands should set main properties', () => {
|
|
330
330
|
var style = new CSSStyleDeclaration();
|
|
331
331
|
var parts = ['Top', 'Right', 'Bottom', 'Left'];
|
|
332
|
-
var testParts = function(name, v, V) {
|
|
332
|
+
var testParts = function (name, v, V) {
|
|
333
333
|
var expected;
|
|
334
334
|
for (var i = 0; i < 4; i++) {
|
|
335
335
|
style[name] = v;
|
|
@@ -346,6 +346,114 @@ describe('CSSStyleDeclaration', () => {
|
|
|
346
346
|
testParts('margin', '1px 2px 3px 4px', 'auto');
|
|
347
347
|
});
|
|
348
348
|
|
|
349
|
+
test('setting individual padding and margin properties to an empty string should clear them', () => {
|
|
350
|
+
var style = new CSSStyleDeclaration();
|
|
351
|
+
|
|
352
|
+
var properties = ['padding', 'margin'];
|
|
353
|
+
var parts = ['Top', 'Right', 'Bottom', 'Left'];
|
|
354
|
+
for (var i = 0; i < properties.length; i++) {
|
|
355
|
+
for (var j = 0; j < parts.length; j++) {
|
|
356
|
+
var property = properties[i] + parts[j];
|
|
357
|
+
style[property] = '12px';
|
|
358
|
+
expect(style[property]).toEqual('12px');
|
|
359
|
+
|
|
360
|
+
style[property] = '';
|
|
361
|
+
expect(style[property]).toEqual('');
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
test('removing and setting individual margin properties updates the combined property accordingly', () => {
|
|
367
|
+
var style = new CSSStyleDeclaration();
|
|
368
|
+
style.margin = '1px 2px 3px 4px';
|
|
369
|
+
|
|
370
|
+
style.marginTop = '';
|
|
371
|
+
expect(style.margin).toEqual('');
|
|
372
|
+
expect(style.marginRight).toEqual('2px');
|
|
373
|
+
expect(style.marginBottom).toEqual('3px');
|
|
374
|
+
expect(style.marginLeft).toEqual('4px');
|
|
375
|
+
|
|
376
|
+
style.marginBottom = '';
|
|
377
|
+
expect(style.margin).toEqual('');
|
|
378
|
+
expect(style.marginRight).toEqual('2px');
|
|
379
|
+
expect(style.marginLeft).toEqual('4px');
|
|
380
|
+
|
|
381
|
+
style.marginBottom = '5px';
|
|
382
|
+
expect(style.margin).toEqual('');
|
|
383
|
+
expect(style.marginRight).toEqual('2px');
|
|
384
|
+
expect(style.marginBottom).toEqual('5px');
|
|
385
|
+
expect(style.marginLeft).toEqual('4px');
|
|
386
|
+
|
|
387
|
+
style.marginTop = '6px';
|
|
388
|
+
expect(style.cssText).toEqual('margin: 6px 2px 5px 4px;');
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
test.each(['padding', 'margin'])(
|
|
392
|
+
'removing an individual %s property should remove the combined property and replace it with the remaining individual ones',
|
|
393
|
+
(property) => {
|
|
394
|
+
var style = new CSSStyleDeclaration();
|
|
395
|
+
var parts = ['Top', 'Right', 'Bottom', 'Left'];
|
|
396
|
+
var partValues = ['1px', '2px', '3px', '4px'];
|
|
397
|
+
|
|
398
|
+
for (var j = 0; j < parts.length; j++) {
|
|
399
|
+
var partToRemove = parts[j];
|
|
400
|
+
style[property] = partValues.join(' ');
|
|
401
|
+
style[property + partToRemove] = '';
|
|
402
|
+
|
|
403
|
+
// Main property should have been removed
|
|
404
|
+
expect(style[property]).toEqual('');
|
|
405
|
+
|
|
406
|
+
// Expect other parts to still be there
|
|
407
|
+
for (var k = 0; k < parts.length; k++) {
|
|
408
|
+
var propertyCss = property + '-' + parts[k].toLowerCase() + ': ' + partValues[k] + ';';
|
|
409
|
+
if (k === j) {
|
|
410
|
+
expect(style[property + parts[k]]).toEqual('');
|
|
411
|
+
expect(style.cssText).not.toContain(propertyCss);
|
|
412
|
+
} else {
|
|
413
|
+
expect(style[property + parts[k]]).toEqual(partValues[k]);
|
|
414
|
+
expect(style.cssText).toContain(propertyCss);
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
);
|
|
420
|
+
|
|
421
|
+
test.each(['margin', 'padding'])(
|
|
422
|
+
'setting additional %s properties keeps important status of others',
|
|
423
|
+
(property) => {
|
|
424
|
+
var style = new CSSStyleDeclaration();
|
|
425
|
+
var importantProperty = property + '-top: 3px !important;';
|
|
426
|
+
style.cssText = importantProperty;
|
|
427
|
+
expect(style.cssText).toContain(importantProperty);
|
|
428
|
+
|
|
429
|
+
style[property + 'Right'] = '4px';
|
|
430
|
+
style[property + 'Bottom'] = '5px';
|
|
431
|
+
style[property + 'Left'] = '6px';
|
|
432
|
+
|
|
433
|
+
expect(style.cssText).toContain(importantProperty);
|
|
434
|
+
expect(style.cssText).toContain(property + '-right: 4px;');
|
|
435
|
+
expect(style.cssText).toContain(property + '-bottom: 5px;');
|
|
436
|
+
expect(style.cssText).toContain(property + '-left: 6px;');
|
|
437
|
+
expect(style.cssText).not.toContain('margin:');
|
|
438
|
+
}
|
|
439
|
+
);
|
|
440
|
+
|
|
441
|
+
test.each(['margin', 'padding'])(
|
|
442
|
+
'setting individual %s keeps important status of others',
|
|
443
|
+
(property) => {
|
|
444
|
+
var style = new CSSStyleDeclaration();
|
|
445
|
+
style.cssText = property + ': 3px !important;';
|
|
446
|
+
|
|
447
|
+
style[property + 'Top'] = '4px';
|
|
448
|
+
|
|
449
|
+
expect(style.cssText).toContain(property + '-top: 4px;');
|
|
450
|
+
expect(style.cssText).toContain(property + '-right: 3px !important;');
|
|
451
|
+
expect(style.cssText).toContain(property + '-bottom: 3px !important;');
|
|
452
|
+
expect(style.cssText).toContain(property + '-left: 3px !important;');
|
|
453
|
+
expect(style.cssText).not.toContain('margin:');
|
|
454
|
+
}
|
|
455
|
+
);
|
|
456
|
+
|
|
349
457
|
test('setting a value to 0 should return the string value', () => {
|
|
350
458
|
var style = new CSSStyleDeclaration();
|
|
351
459
|
style.setProperty('fill-opacity', 0);
|
|
@@ -353,10 +461,46 @@ describe('CSSStyleDeclaration', () => {
|
|
|
353
461
|
});
|
|
354
462
|
|
|
355
463
|
test('onchange callback should be called when the csstext changes', () => {
|
|
356
|
-
var
|
|
464
|
+
var called = 0;
|
|
465
|
+
var style = new CSSStyleDeclaration(function (cssText) {
|
|
466
|
+
called++;
|
|
357
467
|
expect(cssText).toEqual('opacity: 0;');
|
|
358
468
|
});
|
|
469
|
+
style.cssText = 'opacity: 0;';
|
|
470
|
+
expect(called).toEqual(1);
|
|
471
|
+
style.cssText = 'opacity: 0;';
|
|
472
|
+
expect(called).toEqual(2);
|
|
473
|
+
});
|
|
474
|
+
|
|
475
|
+
test('onchange callback should be called only once when multiple properties were added', () => {
|
|
476
|
+
var called = 0;
|
|
477
|
+
var style = new CSSStyleDeclaration(function (cssText) {
|
|
478
|
+
called++;
|
|
479
|
+
expect(cssText).toEqual('width: 100px; height: 100px;');
|
|
480
|
+
});
|
|
481
|
+
style.cssText = 'width: 100px;height:100px;';
|
|
482
|
+
expect(called).toEqual(1);
|
|
483
|
+
});
|
|
484
|
+
|
|
485
|
+
test('onchange callback should not be called when property is set to the same value', () => {
|
|
486
|
+
var called = 0;
|
|
487
|
+
var style = new CSSStyleDeclaration(function () {
|
|
488
|
+
called++;
|
|
489
|
+
});
|
|
490
|
+
|
|
491
|
+
style.setProperty('opacity', 0);
|
|
492
|
+
expect(called).toEqual(1);
|
|
359
493
|
style.setProperty('opacity', 0);
|
|
494
|
+
expect(called).toEqual(1);
|
|
495
|
+
});
|
|
496
|
+
|
|
497
|
+
test('onchange callback should not be called when removeProperty was called on non-existing property', () => {
|
|
498
|
+
var called = 0;
|
|
499
|
+
var style = new CSSStyleDeclaration(function () {
|
|
500
|
+
called++;
|
|
501
|
+
});
|
|
502
|
+
style.removeProperty('opacity');
|
|
503
|
+
expect(called).toEqual(0);
|
|
360
504
|
});
|
|
361
505
|
|
|
362
506
|
test('setting float should work the same as cssfloat', () => {
|
|
@@ -402,6 +546,43 @@ describe('CSSStyleDeclaration', () => {
|
|
|
402
546
|
expect(style.marginTop).toEqual('0.5ex');
|
|
403
547
|
});
|
|
404
548
|
|
|
549
|
+
test('setting empty string and null to a padding or margin works', () => {
|
|
550
|
+
var style = new CSSStyleDeclaration();
|
|
551
|
+
var parts = ['Top', 'Right', 'Bottom', 'Left'];
|
|
552
|
+
function testParts(base, nullValue) {
|
|
553
|
+
var props = [base].concat(parts.map((part) => base + part));
|
|
554
|
+
for (let prop of props) {
|
|
555
|
+
expect(style[prop]).toEqual('');
|
|
556
|
+
style[prop] = '10px';
|
|
557
|
+
expect(style[prop]).toEqual('10px');
|
|
558
|
+
style[prop] = nullValue;
|
|
559
|
+
expect(style[prop]).toEqual('');
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
testParts('margin', '');
|
|
564
|
+
testParts('margin', null);
|
|
565
|
+
testParts('padding', '');
|
|
566
|
+
testParts('padding', null);
|
|
567
|
+
});
|
|
568
|
+
|
|
569
|
+
test('setting undefined to a padding or margin does nothing', () => {
|
|
570
|
+
var style = new CSSStyleDeclaration();
|
|
571
|
+
var parts = ['Top', 'Right', 'Bottom', 'Left'];
|
|
572
|
+
function testParts(base) {
|
|
573
|
+
var props = [base].concat(parts.map((part) => base + part));
|
|
574
|
+
for (let prop of props) {
|
|
575
|
+
style[prop] = '10px';
|
|
576
|
+
expect(style[prop]).toEqual('10px');
|
|
577
|
+
style[prop] = undefined;
|
|
578
|
+
expect(style[prop]).toEqual('10px');
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
testParts('margin');
|
|
583
|
+
testParts('padding');
|
|
584
|
+
});
|
|
585
|
+
|
|
405
586
|
test('setting null to background works', () => {
|
|
406
587
|
var style = new CSSStyleDeclaration();
|
|
407
588
|
style.background = 'red';
|
package/lib/allProperties.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
// autogenerated -
|
|
3
|
+
// autogenerated - 1/22/2023
|
|
4
4
|
|
|
5
5
|
/*
|
|
6
6
|
*
|
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
module.exports = new Set([
|
|
11
|
+
'-webkit-line-clamp',
|
|
12
|
+
'accent-color',
|
|
11
13
|
'align-content',
|
|
12
14
|
'align-items',
|
|
13
15
|
'align-self',
|
|
@@ -15,15 +17,20 @@ module.exports = new Set([
|
|
|
15
17
|
'all',
|
|
16
18
|
'animation',
|
|
17
19
|
'animation-delay',
|
|
20
|
+
'animation-delay-end',
|
|
21
|
+
'animation-delay-start',
|
|
18
22
|
'animation-direction',
|
|
19
23
|
'animation-duration',
|
|
20
24
|
'animation-fill-mode',
|
|
21
25
|
'animation-iteration-count',
|
|
22
26
|
'animation-name',
|
|
23
27
|
'animation-play-state',
|
|
28
|
+
'animation-range',
|
|
24
29
|
'animation-timing-function',
|
|
25
30
|
'appearance',
|
|
31
|
+
'aspect-ratio',
|
|
26
32
|
'azimuth',
|
|
33
|
+
'backface-visibility',
|
|
27
34
|
'background',
|
|
28
35
|
'background-attachment',
|
|
29
36
|
'background-blend-mode',
|
|
@@ -35,7 +42,8 @@ module.exports = new Set([
|
|
|
35
42
|
'background-repeat',
|
|
36
43
|
'background-size',
|
|
37
44
|
'baseline-shift',
|
|
38
|
-
'
|
|
45
|
+
'baseline-source',
|
|
46
|
+
'block-ellipsis',
|
|
39
47
|
'block-size',
|
|
40
48
|
'bookmark-label',
|
|
41
49
|
'bookmark-level',
|
|
@@ -134,7 +142,16 @@ module.exports = new Set([
|
|
|
134
142
|
'column-width',
|
|
135
143
|
'columns',
|
|
136
144
|
'contain',
|
|
145
|
+
'contain-intrinsic-block-size',
|
|
146
|
+
'contain-intrinsic-height',
|
|
147
|
+
'contain-intrinsic-inline-size',
|
|
148
|
+
'contain-intrinsic-size',
|
|
149
|
+
'contain-intrinsic-width',
|
|
150
|
+
'container',
|
|
151
|
+
'container-name',
|
|
152
|
+
'container-type',
|
|
137
153
|
'content',
|
|
154
|
+
'content-visibility',
|
|
138
155
|
'continue',
|
|
139
156
|
'counter-increment',
|
|
140
157
|
'counter-reset',
|
|
@@ -218,9 +235,9 @@ module.exports = new Set([
|
|
|
218
235
|
'image-orientation',
|
|
219
236
|
'image-rendering',
|
|
220
237
|
'image-resolution',
|
|
221
|
-
'initial-
|
|
222
|
-
'initial-
|
|
223
|
-
'initial-
|
|
238
|
+
'initial-letter',
|
|
239
|
+
'initial-letter-align',
|
|
240
|
+
'initial-letter-wrap',
|
|
224
241
|
'inline-size',
|
|
225
242
|
'inline-sizing',
|
|
226
243
|
'inset',
|
|
@@ -234,6 +251,7 @@ module.exports = new Set([
|
|
|
234
251
|
'justify-content',
|
|
235
252
|
'justify-items',
|
|
236
253
|
'justify-self',
|
|
254
|
+
'leading-trim',
|
|
237
255
|
'left',
|
|
238
256
|
'letter-spacing',
|
|
239
257
|
'lighting-color',
|
|
@@ -258,6 +276,7 @@ module.exports = new Set([
|
|
|
258
276
|
'margin-left',
|
|
259
277
|
'margin-right',
|
|
260
278
|
'margin-top',
|
|
279
|
+
'margin-trim',
|
|
261
280
|
'marker-side',
|
|
262
281
|
'mask',
|
|
263
282
|
'mask-border',
|
|
@@ -284,6 +303,7 @@ module.exports = new Set([
|
|
|
284
303
|
'min-block-size',
|
|
285
304
|
'min-height',
|
|
286
305
|
'min-inline-size',
|
|
306
|
+
'min-intrinsic-sizing',
|
|
287
307
|
'min-width',
|
|
288
308
|
'mix-blend-mode',
|
|
289
309
|
'nav-down',
|
|
@@ -293,15 +313,11 @@ module.exports = new Set([
|
|
|
293
313
|
'object-fit',
|
|
294
314
|
'object-position',
|
|
295
315
|
'offset',
|
|
296
|
-
'offset-after',
|
|
297
316
|
'offset-anchor',
|
|
298
|
-
'offset-before',
|
|
299
317
|
'offset-distance',
|
|
300
|
-
'offset-end',
|
|
301
318
|
'offset-path',
|
|
302
319
|
'offset-position',
|
|
303
320
|
'offset-rotate',
|
|
304
|
-
'offset-start',
|
|
305
321
|
'opacity',
|
|
306
322
|
'order',
|
|
307
323
|
'orphans',
|
|
@@ -311,7 +327,19 @@ module.exports = new Set([
|
|
|
311
327
|
'outline-style',
|
|
312
328
|
'outline-width',
|
|
313
329
|
'overflow',
|
|
330
|
+
'overflow-anchor',
|
|
314
331
|
'overflow-block',
|
|
332
|
+
'overflow-clip-margin',
|
|
333
|
+
'overflow-clip-margin-block',
|
|
334
|
+
'overflow-clip-margin-block-end',
|
|
335
|
+
'overflow-clip-margin-block-start',
|
|
336
|
+
'overflow-clip-margin-bottom',
|
|
337
|
+
'overflow-clip-margin-inline',
|
|
338
|
+
'overflow-clip-margin-inline-end',
|
|
339
|
+
'overflow-clip-margin-inline-start',
|
|
340
|
+
'overflow-clip-margin-left',
|
|
341
|
+
'overflow-clip-margin-right',
|
|
342
|
+
'overflow-clip-margin-top',
|
|
315
343
|
'overflow-inline',
|
|
316
344
|
'overflow-wrap',
|
|
317
345
|
'overflow-x',
|
|
@@ -334,6 +362,8 @@ module.exports = new Set([
|
|
|
334
362
|
'pause',
|
|
335
363
|
'pause-after',
|
|
336
364
|
'pause-before',
|
|
365
|
+
'perspective',
|
|
366
|
+
'perspective-origin',
|
|
337
367
|
'pitch',
|
|
338
368
|
'pitch-range',
|
|
339
369
|
'place-content',
|
|
@@ -341,6 +371,7 @@ module.exports = new Set([
|
|
|
341
371
|
'place-self',
|
|
342
372
|
'play-during',
|
|
343
373
|
'position',
|
|
374
|
+
'print-color-adjust',
|
|
344
375
|
'quotes',
|
|
345
376
|
'region-fragment',
|
|
346
377
|
'resize',
|
|
@@ -349,11 +380,14 @@ module.exports = new Set([
|
|
|
349
380
|
'rest-before',
|
|
350
381
|
'richness',
|
|
351
382
|
'right',
|
|
383
|
+
'rotate',
|
|
352
384
|
'row-gap',
|
|
353
385
|
'ruby-align',
|
|
354
386
|
'ruby-merge',
|
|
387
|
+
'ruby-overhang',
|
|
355
388
|
'ruby-position',
|
|
356
389
|
'running',
|
|
390
|
+
'scale',
|
|
357
391
|
'scroll-behavior',
|
|
358
392
|
'scroll-margin',
|
|
359
393
|
'scroll-margin-block',
|
|
@@ -380,6 +414,12 @@ module.exports = new Set([
|
|
|
380
414
|
'scroll-snap-align',
|
|
381
415
|
'scroll-snap-stop',
|
|
382
416
|
'scroll-snap-type',
|
|
417
|
+
'scroll-timeline',
|
|
418
|
+
'scroll-timeline-axis',
|
|
419
|
+
'scroll-timeline-name',
|
|
420
|
+
'scrollbar-color',
|
|
421
|
+
'scrollbar-gutter',
|
|
422
|
+
'scrollbar-width',
|
|
383
423
|
'shape-image-threshold',
|
|
384
424
|
'shape-inside',
|
|
385
425
|
'shape-margin',
|
|
@@ -404,10 +444,19 @@ module.exports = new Set([
|
|
|
404
444
|
'text-decoration',
|
|
405
445
|
'text-decoration-color',
|
|
406
446
|
'text-decoration-line',
|
|
447
|
+
'text-decoration-skip',
|
|
448
|
+
'text-decoration-skip-box',
|
|
449
|
+
'text-decoration-skip-ink',
|
|
450
|
+
'text-decoration-skip-inset',
|
|
451
|
+
'text-decoration-skip-self',
|
|
452
|
+
'text-decoration-skip-spaces',
|
|
407
453
|
'text-decoration-style',
|
|
454
|
+
'text-decoration-thickness',
|
|
455
|
+
'text-edge',
|
|
408
456
|
'text-emphasis',
|
|
409
457
|
'text-emphasis-color',
|
|
410
458
|
'text-emphasis-position',
|
|
459
|
+
'text-emphasis-skip',
|
|
411
460
|
'text-emphasis-style',
|
|
412
461
|
'text-group-align',
|
|
413
462
|
'text-indent',
|
|
@@ -419,20 +468,28 @@ module.exports = new Set([
|
|
|
419
468
|
'text-space-trim',
|
|
420
469
|
'text-spacing',
|
|
421
470
|
'text-transform',
|
|
471
|
+
'text-underline-offset',
|
|
422
472
|
'text-underline-position',
|
|
423
473
|
'text-wrap',
|
|
424
474
|
'top',
|
|
425
475
|
'transform',
|
|
426
476
|
'transform-box',
|
|
427
477
|
'transform-origin',
|
|
478
|
+
'transform-style',
|
|
428
479
|
'transition',
|
|
429
480
|
'transition-delay',
|
|
430
481
|
'transition-duration',
|
|
431
482
|
'transition-property',
|
|
432
483
|
'transition-timing-function',
|
|
484
|
+
'translate',
|
|
433
485
|
'unicode-bidi',
|
|
434
486
|
'user-select',
|
|
435
487
|
'vertical-align',
|
|
488
|
+
'view-timeline',
|
|
489
|
+
'view-timeline-axis',
|
|
490
|
+
'view-timeline-inset',
|
|
491
|
+
'view-timeline-name',
|
|
492
|
+
'view-transition-name',
|
|
436
493
|
'visibility',
|
|
437
494
|
'voice-balance',
|
|
438
495
|
'voice-duration',
|