cssstyle 4.0.1 → 4.2.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/lib/CSSStyleDeclaration.js +3 -1
- package/lib/allProperties.js +27 -17
- package/lib/implementedProperties.js +84 -88
- package/lib/parsers.js +32 -170
- package/lib/properties/margin.js +1 -0
- package/lib/properties/padding.js +1 -0
- package/lib/properties.js +4 -171
- package/package.json +16 -15
- package/lib/CSSStyleDeclaration.test.js +0 -737
- package/lib/parsers.test.js +0 -146
- package/lib/utils/colorSpace.js +0 -19
|
@@ -53,7 +53,9 @@ CSSStyleDeclaration.prototype = {
|
|
|
53
53
|
this.removeProperty(name);
|
|
54
54
|
return;
|
|
55
55
|
}
|
|
56
|
-
var isCustomProperty =
|
|
56
|
+
var isCustomProperty =
|
|
57
|
+
name.indexOf('--') === 0 ||
|
|
58
|
+
(typeof value === 'string' && /^var\(--[-\w]+,?.*\)$/.test(value));
|
|
57
59
|
if (isCustomProperty) {
|
|
58
60
|
this._setProperty(name, value, priority);
|
|
59
61
|
return;
|
package/lib/allProperties.js
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
/*
|
|
6
|
-
*
|
|
7
|
-
* https://www.w3.org/Style/CSS/all-properties.en.html
|
|
8
|
-
*/
|
|
2
|
+
// autogenerated - 2024-09-07
|
|
3
|
+
// https://www.w3.org/Style/CSS/all-properties.en.html
|
|
9
4
|
|
|
10
5
|
module.exports = new Set([
|
|
11
6
|
'-webkit-line-clamp',
|
|
@@ -15,10 +10,11 @@ module.exports = new Set([
|
|
|
15
10
|
'align-self',
|
|
16
11
|
'alignment-baseline',
|
|
17
12
|
'all',
|
|
13
|
+
'anchor-name',
|
|
14
|
+
'anchor-scope',
|
|
18
15
|
'animation',
|
|
16
|
+
'animation-composition',
|
|
19
17
|
'animation-delay',
|
|
20
|
-
'animation-delay-end',
|
|
21
|
-
'animation-delay-start',
|
|
22
18
|
'animation-direction',
|
|
23
19
|
'animation-duration',
|
|
24
20
|
'animation-fill-mode',
|
|
@@ -26,6 +22,9 @@ module.exports = new Set([
|
|
|
26
22
|
'animation-name',
|
|
27
23
|
'animation-play-state',
|
|
28
24
|
'animation-range',
|
|
25
|
+
'animation-range-end',
|
|
26
|
+
'animation-range-start',
|
|
27
|
+
'animation-timeline',
|
|
29
28
|
'animation-timing-function',
|
|
30
29
|
'appearance',
|
|
31
30
|
'aspect-ratio',
|
|
@@ -122,7 +121,6 @@ module.exports = new Set([
|
|
|
122
121
|
'caret',
|
|
123
122
|
'caret-color',
|
|
124
123
|
'caret-shape',
|
|
125
|
-
'chains',
|
|
126
124
|
'clear',
|
|
127
125
|
'clip',
|
|
128
126
|
'clip-path',
|
|
@@ -176,7 +174,6 @@ module.exports = new Set([
|
|
|
176
174
|
'float',
|
|
177
175
|
'flood-color',
|
|
178
176
|
'flood-opacity',
|
|
179
|
-
'flow',
|
|
180
177
|
'flow-from',
|
|
181
178
|
'flow-into',
|
|
182
179
|
'font',
|
|
@@ -191,6 +188,7 @@ module.exports = new Set([
|
|
|
191
188
|
'font-stretch',
|
|
192
189
|
'font-style',
|
|
193
190
|
'font-synthesis',
|
|
191
|
+
'font-synthesis-position',
|
|
194
192
|
'font-synthesis-small-caps',
|
|
195
193
|
'font-synthesis-style',
|
|
196
194
|
'font-synthesis-weight',
|
|
@@ -204,6 +202,7 @@ module.exports = new Set([
|
|
|
204
202
|
'font-variant-position',
|
|
205
203
|
'font-variation-settings',
|
|
206
204
|
'font-weight',
|
|
205
|
+
'font-width',
|
|
207
206
|
'footnote-display',
|
|
208
207
|
'footnote-policy',
|
|
209
208
|
'forced-color-adjust',
|
|
@@ -241,6 +240,7 @@ module.exports = new Set([
|
|
|
241
240
|
'inline-size',
|
|
242
241
|
'inline-sizing',
|
|
243
242
|
'inset',
|
|
243
|
+
'inset-area',
|
|
244
244
|
'inset-block',
|
|
245
245
|
'inset-block-end',
|
|
246
246
|
'inset-block-start',
|
|
@@ -251,12 +251,12 @@ module.exports = new Set([
|
|
|
251
251
|
'justify-content',
|
|
252
252
|
'justify-items',
|
|
253
253
|
'justify-self',
|
|
254
|
-
'leading-trim',
|
|
255
254
|
'left',
|
|
256
255
|
'letter-spacing',
|
|
257
256
|
'lighting-color',
|
|
258
257
|
'line-break',
|
|
259
258
|
'line-clamp',
|
|
259
|
+
'line-fit-edge',
|
|
260
260
|
'line-grid',
|
|
261
261
|
'line-height',
|
|
262
262
|
'line-padding',
|
|
@@ -371,6 +371,10 @@ module.exports = new Set([
|
|
|
371
371
|
'place-self',
|
|
372
372
|
'play-during',
|
|
373
373
|
'position',
|
|
374
|
+
'position-anchor',
|
|
375
|
+
'position-try',
|
|
376
|
+
'position-try-options',
|
|
377
|
+
'position-try-order',
|
|
374
378
|
'print-color-adjust',
|
|
375
379
|
'quotes',
|
|
376
380
|
'region-fragment',
|
|
@@ -440,6 +444,10 @@ module.exports = new Set([
|
|
|
440
444
|
'text-align',
|
|
441
445
|
'text-align-all',
|
|
442
446
|
'text-align-last',
|
|
447
|
+
'text-autospace',
|
|
448
|
+
'text-box',
|
|
449
|
+
'text-box-edge',
|
|
450
|
+
'text-box-trim',
|
|
443
451
|
'text-combine-upright',
|
|
444
452
|
'text-decoration',
|
|
445
453
|
'text-decoration-color',
|
|
@@ -452,7 +460,6 @@ module.exports = new Set([
|
|
|
452
460
|
'text-decoration-skip-spaces',
|
|
453
461
|
'text-decoration-style',
|
|
454
462
|
'text-decoration-thickness',
|
|
455
|
-
'text-edge',
|
|
456
463
|
'text-emphasis',
|
|
457
464
|
'text-emphasis-color',
|
|
458
465
|
'text-emphasis-position',
|
|
@@ -464,13 +471,15 @@ module.exports = new Set([
|
|
|
464
471
|
'text-orientation',
|
|
465
472
|
'text-overflow',
|
|
466
473
|
'text-shadow',
|
|
467
|
-
'text-space-collapse',
|
|
468
|
-
'text-space-trim',
|
|
469
474
|
'text-spacing',
|
|
475
|
+
'text-spacing-trim',
|
|
470
476
|
'text-transform',
|
|
471
477
|
'text-underline-offset',
|
|
472
478
|
'text-underline-position',
|
|
473
479
|
'text-wrap',
|
|
480
|
+
'text-wrap-mode',
|
|
481
|
+
'text-wrap-style',
|
|
482
|
+
'timeline-scope',
|
|
474
483
|
'top',
|
|
475
484
|
'transform',
|
|
476
485
|
'transform-box',
|
|
@@ -501,12 +510,13 @@ module.exports = new Set([
|
|
|
501
510
|
'voice-volume',
|
|
502
511
|
'volume',
|
|
503
512
|
'white-space',
|
|
513
|
+
'white-space-collapse',
|
|
514
|
+
'white-space-trim',
|
|
504
515
|
'widows',
|
|
505
516
|
'width',
|
|
506
517
|
'will-change',
|
|
507
|
-
'word-boundary-detection',
|
|
508
|
-
'word-boundary-expansion',
|
|
509
518
|
'word-break',
|
|
519
|
+
'word-space-transform',
|
|
510
520
|
'word-spacing',
|
|
511
521
|
'word-wrap',
|
|
512
522
|
'wrap-after',
|
|
@@ -1,90 +1,86 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
// autogenerated - 12/28/2023
|
|
4
1
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
*/
|
|
2
|
+
'use strict';
|
|
3
|
+
// autogenerated - 2025-01-09
|
|
4
|
+
// https://www.w3.org/Style/CSS/all-properties.en.html
|
|
9
5
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
6
|
+
module.exports = new Set([
|
|
7
|
+
"azimuth",
|
|
8
|
+
"background",
|
|
9
|
+
"background-attachment",
|
|
10
|
+
"background-color",
|
|
11
|
+
"background-image",
|
|
12
|
+
"background-position",
|
|
13
|
+
"background-repeat",
|
|
14
|
+
"border",
|
|
15
|
+
"border-bottom",
|
|
16
|
+
"border-bottom-color",
|
|
17
|
+
"border-bottom-style",
|
|
18
|
+
"border-bottom-width",
|
|
19
|
+
"border-collapse",
|
|
20
|
+
"border-color",
|
|
21
|
+
"border-left",
|
|
22
|
+
"border-left-color",
|
|
23
|
+
"border-left-style",
|
|
24
|
+
"border-left-width",
|
|
25
|
+
"border-right",
|
|
26
|
+
"border-right-color",
|
|
27
|
+
"border-right-style",
|
|
28
|
+
"border-right-width",
|
|
29
|
+
"border-spacing",
|
|
30
|
+
"border-style",
|
|
31
|
+
"border-top",
|
|
32
|
+
"border-top-color",
|
|
33
|
+
"border-top-style",
|
|
34
|
+
"border-top-width",
|
|
35
|
+
"border-width",
|
|
36
|
+
"bottom",
|
|
37
|
+
"clear",
|
|
38
|
+
"clip",
|
|
39
|
+
"color",
|
|
40
|
+
"css-float",
|
|
41
|
+
"flex",
|
|
42
|
+
"flex-basis",
|
|
43
|
+
"flex-grow",
|
|
44
|
+
"flex-shrink",
|
|
45
|
+
"float",
|
|
46
|
+
"flood-color",
|
|
47
|
+
"font",
|
|
48
|
+
"font-family",
|
|
49
|
+
"font-size",
|
|
50
|
+
"font-style",
|
|
51
|
+
"font-variant",
|
|
52
|
+
"font-weight",
|
|
53
|
+
"height",
|
|
54
|
+
"left",
|
|
55
|
+
"lighting-color",
|
|
56
|
+
"line-height",
|
|
57
|
+
"margin",
|
|
58
|
+
"margin-bottom",
|
|
59
|
+
"margin-left",
|
|
60
|
+
"margin-right",
|
|
61
|
+
"margin-top",
|
|
62
|
+
"opacity",
|
|
63
|
+
"outline-color",
|
|
64
|
+
"padding",
|
|
65
|
+
"padding-bottom",
|
|
66
|
+
"padding-left",
|
|
67
|
+
"padding-right",
|
|
68
|
+
"padding-top",
|
|
69
|
+
"right",
|
|
70
|
+
"stop-color",
|
|
71
|
+
"text-line-through-color",
|
|
72
|
+
"text-overline-color",
|
|
73
|
+
"text-underline-color",
|
|
74
|
+
"top",
|
|
75
|
+
"webkit-border-after-color",
|
|
76
|
+
"webkit-border-before-color",
|
|
77
|
+
"webkit-border-end-color",
|
|
78
|
+
"webkit-border-start-color",
|
|
79
|
+
"webkit-column-rule-color",
|
|
80
|
+
"webkit-match-nearest-mail-blockquote-color",
|
|
81
|
+
"webkit-tap-highlight-color",
|
|
82
|
+
"webkit-text-emphasis-color",
|
|
83
|
+
"webkit-text-fill-color",
|
|
84
|
+
"webkit-text-stroke-color",
|
|
85
|
+
"width"
|
|
86
|
+
]);
|
package/lib/parsers.js
CHANGED
|
@@ -4,8 +4,7 @@
|
|
|
4
4
|
********************************************************************/
|
|
5
5
|
'use strict';
|
|
6
6
|
|
|
7
|
-
const
|
|
8
|
-
const { hslToRgb } = require('./utils/colorSpace');
|
|
7
|
+
const { cssCalc, isColor, resolve } = require('@asamuzakjp/css-color');
|
|
9
8
|
|
|
10
9
|
exports.TYPES = {
|
|
11
10
|
INTEGER: 1,
|
|
@@ -19,22 +18,24 @@ exports.TYPES = {
|
|
|
19
18
|
KEYWORD: 9,
|
|
20
19
|
NULL_OR_EMPTY_STR: 10,
|
|
21
20
|
CALC: 11,
|
|
21
|
+
VAR: 12,
|
|
22
22
|
};
|
|
23
23
|
|
|
24
|
-
//
|
|
25
|
-
var
|
|
26
|
-
var
|
|
27
|
-
var
|
|
28
|
-
var
|
|
24
|
+
// regular expressions
|
|
25
|
+
var DIGIT = '(?:0|[1-9]\\d*)';
|
|
26
|
+
var NUMBER = `[+-]?(?:${DIGIT}(?:\\.\\d*)?|\\.\\d+)(?:e-?${DIGIT})?`;
|
|
27
|
+
var integerRegEx = new RegExp(`^[+-]?${DIGIT}$`);
|
|
28
|
+
var numberRegEx = new RegExp(`^${NUMBER}$`);
|
|
29
|
+
var lengthRegEx = new RegExp(
|
|
30
|
+
`^${NUMBER}(?:[cm]m|[dls]?v(?:[bhiw]|max|min)|in|p[ctx]|q|r?(?:[cl]h|cap|e[mx]|ic))$`
|
|
31
|
+
);
|
|
32
|
+
var percentRegEx = new RegExp(`^${NUMBER}%$`);
|
|
33
|
+
var angleRegEx = new RegExp(`^${NUMBER}(?:deg|g?rad|turn)$`);
|
|
29
34
|
var urlRegEx = /^url\(\s*([^)]*)\s*\)$/;
|
|
30
35
|
var stringRegEx = /^("[^"]*"|'[^']*')$/;
|
|
31
|
-
var
|
|
32
|
-
var
|
|
33
|
-
|
|
34
|
-
var calcRegEx = /^calc\(([^)]*)\)$/;
|
|
35
|
-
var colorRegEx4 =
|
|
36
|
-
/^hsla?\(\s*(-?\d+|-?\d*.\d+)\s*,\s*(-?\d+|-?\d*.\d+)%\s*,\s*(-?\d+|-?\d*.\d+)%\s*(,\s*(-?\d+|-?\d*.\d+)\s*)?\)/;
|
|
37
|
-
var angleRegEx = /^([-+]?[0-9]*\.?[0-9]+)(deg|grad|rad)$/;
|
|
36
|
+
var varRegEx = /^var\(|(?<=[*/\s(])var\(/;
|
|
37
|
+
var calcRegEx =
|
|
38
|
+
/^(?:a?(?:cos|sin|tan)|abs|atan2|calc|clamp|exp|hypot|log|max|min|mod|pow|rem|round|sign|sqrt)\(/;
|
|
38
39
|
|
|
39
40
|
// This will return one of the above types based on the passed in string
|
|
40
41
|
exports.valueType = function valueType(val) {
|
|
@@ -44,11 +45,9 @@ exports.valueType = function valueType(val) {
|
|
|
44
45
|
if (typeof val === 'number') {
|
|
45
46
|
val = val.toString();
|
|
46
47
|
}
|
|
47
|
-
|
|
48
48
|
if (typeof val !== 'string') {
|
|
49
49
|
return undefined;
|
|
50
50
|
}
|
|
51
|
-
|
|
52
51
|
if (integerRegEx.test(val)) {
|
|
53
52
|
return exports.TYPES.INTEGER;
|
|
54
53
|
}
|
|
@@ -64,6 +63,9 @@ exports.valueType = function valueType(val) {
|
|
|
64
63
|
if (urlRegEx.test(val)) {
|
|
65
64
|
return exports.TYPES.URL;
|
|
66
65
|
}
|
|
66
|
+
if (varRegEx.test(val)) {
|
|
67
|
+
return exports.TYPES.VAR;
|
|
68
|
+
}
|
|
67
69
|
if (calcRegEx.test(val)) {
|
|
68
70
|
return exports.TYPES.CALC;
|
|
69
71
|
}
|
|
@@ -73,54 +75,11 @@ exports.valueType = function valueType(val) {
|
|
|
73
75
|
if (angleRegEx.test(val)) {
|
|
74
76
|
return exports.TYPES.ANGLE;
|
|
75
77
|
}
|
|
76
|
-
if (
|
|
78
|
+
if (isColor(val)) {
|
|
77
79
|
return exports.TYPES.COLOR;
|
|
78
80
|
}
|
|
79
81
|
|
|
80
|
-
|
|
81
|
-
var parts;
|
|
82
|
-
if (res !== null) {
|
|
83
|
-
parts = res[1].split(/\s*,\s*/);
|
|
84
|
-
if (parts.length !== 3) {
|
|
85
|
-
return undefined;
|
|
86
|
-
}
|
|
87
|
-
if (
|
|
88
|
-
parts.every(percentRegEx.test.bind(percentRegEx)) ||
|
|
89
|
-
parts.every(integerRegEx.test.bind(integerRegEx))
|
|
90
|
-
) {
|
|
91
|
-
return exports.TYPES.COLOR;
|
|
92
|
-
}
|
|
93
|
-
return undefined;
|
|
94
|
-
}
|
|
95
|
-
res = colorRegEx3.exec(val);
|
|
96
|
-
if (res !== null) {
|
|
97
|
-
parts = res[1].split(/\s*,\s*/);
|
|
98
|
-
if (parts.length !== 4) {
|
|
99
|
-
return undefined;
|
|
100
|
-
}
|
|
101
|
-
if (
|
|
102
|
-
parts.slice(0, 3).every(percentRegEx.test.bind(percentRegEx)) ||
|
|
103
|
-
parts.slice(0, 3).every(integerRegEx.test.bind(integerRegEx))
|
|
104
|
-
) {
|
|
105
|
-
if (numberRegEx.test(parts[3])) {
|
|
106
|
-
return exports.TYPES.COLOR;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
return undefined;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
if (colorRegEx4.test(val)) {
|
|
113
|
-
return exports.TYPES.COLOR;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
// could still be a color, one of the standard keyword colors
|
|
117
|
-
val = val.toLowerCase();
|
|
118
|
-
|
|
119
|
-
if (namedColors.includes(val)) {
|
|
120
|
-
return exports.TYPES.COLOR;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
switch (val) {
|
|
82
|
+
switch (val.toLowerCase()) {
|
|
124
83
|
// the following are deprecated in CSS3
|
|
125
84
|
case 'activeborder':
|
|
126
85
|
case 'activecaption':
|
|
@@ -209,9 +168,14 @@ exports.parsePercent = function parsePercent(val) {
|
|
|
209
168
|
// either a length or a percent
|
|
210
169
|
exports.parseMeasurement = function parseMeasurement(val) {
|
|
211
170
|
var type = exports.valueType(val);
|
|
212
|
-
if (type === exports.TYPES.
|
|
171
|
+
if (type === exports.TYPES.VAR) {
|
|
213
172
|
return val;
|
|
214
173
|
}
|
|
174
|
+
if (type === exports.TYPES.CALC) {
|
|
175
|
+
return cssCalc(val, {
|
|
176
|
+
format: 'specifiedValue',
|
|
177
|
+
});
|
|
178
|
+
}
|
|
215
179
|
|
|
216
180
|
var length = exports.parseLength(val);
|
|
217
181
|
if (length !== undefined) {
|
|
@@ -291,116 +255,14 @@ exports.parseColor = function parseColor(val) {
|
|
|
291
255
|
if (type === exports.TYPES.NULL_OR_EMPTY_STR) {
|
|
292
256
|
return val;
|
|
293
257
|
}
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
blue,
|
|
297
|
-
hue,
|
|
298
|
-
saturation,
|
|
299
|
-
lightness,
|
|
300
|
-
alpha = 1;
|
|
301
|
-
var parts;
|
|
302
|
-
var res = colorRegEx1.exec(val);
|
|
303
|
-
// is it #aaa, #ababab, #aaaa, #abababaa
|
|
304
|
-
if (res) {
|
|
305
|
-
var defaultHex = val.substr(1);
|
|
306
|
-
var hex = val.substr(1);
|
|
307
|
-
if (hex.length === 3 || hex.length === 4) {
|
|
308
|
-
hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2];
|
|
309
|
-
|
|
310
|
-
if (defaultHex.length === 4) {
|
|
311
|
-
hex = hex + defaultHex[3] + defaultHex[3];
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
red = parseInt(hex.substr(0, 2), 16);
|
|
315
|
-
green = parseInt(hex.substr(2, 2), 16);
|
|
316
|
-
blue = parseInt(hex.substr(4, 2), 16);
|
|
317
|
-
if (hex.length === 8) {
|
|
318
|
-
var hexAlpha = hex.substr(6, 2);
|
|
319
|
-
var hexAlphaToRgbaAlpha = Number((parseInt(hexAlpha, 16) / 255).toFixed(3));
|
|
320
|
-
|
|
321
|
-
return 'rgba(' + red + ', ' + green + ', ' + blue + ', ' + hexAlphaToRgbaAlpha + ')';
|
|
322
|
-
}
|
|
323
|
-
return 'rgb(' + red + ', ' + green + ', ' + blue + ')';
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
res = colorRegEx2.exec(val);
|
|
327
|
-
if (res) {
|
|
328
|
-
parts = res[1].split(/\s*,\s*/);
|
|
329
|
-
if (parts.length !== 3) {
|
|
330
|
-
return undefined;
|
|
331
|
-
}
|
|
332
|
-
if (parts.every(percentRegEx.test.bind(percentRegEx))) {
|
|
333
|
-
red = Math.floor((parseFloat(parts[0].slice(0, -1)) * 255) / 100);
|
|
334
|
-
green = Math.floor((parseFloat(parts[1].slice(0, -1)) * 255) / 100);
|
|
335
|
-
blue = Math.floor((parseFloat(parts[2].slice(0, -1)) * 255) / 100);
|
|
336
|
-
} else if (parts.every(integerRegEx.test.bind(integerRegEx))) {
|
|
337
|
-
red = parseInt(parts[0], 10);
|
|
338
|
-
green = parseInt(parts[1], 10);
|
|
339
|
-
blue = parseInt(parts[2], 10);
|
|
340
|
-
} else {
|
|
341
|
-
return undefined;
|
|
342
|
-
}
|
|
343
|
-
red = Math.min(255, Math.max(0, red));
|
|
344
|
-
green = Math.min(255, Math.max(0, green));
|
|
345
|
-
blue = Math.min(255, Math.max(0, blue));
|
|
346
|
-
return 'rgb(' + red + ', ' + green + ', ' + blue + ')';
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
res = colorRegEx3.exec(val);
|
|
350
|
-
if (res) {
|
|
351
|
-
parts = res[1].split(/\s*,\s*/);
|
|
352
|
-
if (parts.length !== 4) {
|
|
353
|
-
return undefined;
|
|
354
|
-
}
|
|
355
|
-
if (parts.slice(0, 3).every(percentRegEx.test.bind(percentRegEx))) {
|
|
356
|
-
red = Math.floor((parseFloat(parts[0].slice(0, -1)) * 255) / 100);
|
|
357
|
-
green = Math.floor((parseFloat(parts[1].slice(0, -1)) * 255) / 100);
|
|
358
|
-
blue = Math.floor((parseFloat(parts[2].slice(0, -1)) * 255) / 100);
|
|
359
|
-
alpha = parseFloat(parts[3]);
|
|
360
|
-
} else if (parts.slice(0, 3).every(integerRegEx.test.bind(integerRegEx))) {
|
|
361
|
-
red = parseInt(parts[0], 10);
|
|
362
|
-
green = parseInt(parts[1], 10);
|
|
363
|
-
blue = parseInt(parts[2], 10);
|
|
364
|
-
alpha = parseFloat(parts[3]);
|
|
365
|
-
} else {
|
|
366
|
-
return undefined;
|
|
367
|
-
}
|
|
368
|
-
if (isNaN(alpha)) {
|
|
369
|
-
alpha = 1;
|
|
370
|
-
}
|
|
371
|
-
red = Math.min(255, Math.max(0, red));
|
|
372
|
-
green = Math.min(255, Math.max(0, green));
|
|
373
|
-
blue = Math.min(255, Math.max(0, blue));
|
|
374
|
-
alpha = Math.min(1, Math.max(0, alpha));
|
|
375
|
-
if (alpha === 1) {
|
|
376
|
-
return 'rgb(' + red + ', ' + green + ', ' + blue + ')';
|
|
377
|
-
}
|
|
378
|
-
return 'rgba(' + red + ', ' + green + ', ' + blue + ', ' + alpha + ')';
|
|
258
|
+
if (/^[a-z]+$/i.test(val) && type === exports.TYPES.COLOR) {
|
|
259
|
+
return val;
|
|
379
260
|
}
|
|
380
|
-
|
|
381
|
-
|
|
261
|
+
var res = resolve(val, {
|
|
262
|
+
format: 'specifiedValue',
|
|
263
|
+
});
|
|
382
264
|
if (res) {
|
|
383
|
-
|
|
384
|
-
const _alpha = parseFloat(_alphaString.replace(',', '').trim());
|
|
385
|
-
if (!_hue || !_saturation || !_lightness) {
|
|
386
|
-
return undefined;
|
|
387
|
-
}
|
|
388
|
-
hue = parseFloat(_hue);
|
|
389
|
-
saturation = parseInt(_saturation, 10);
|
|
390
|
-
lightness = parseInt(_lightness, 10);
|
|
391
|
-
if (_alpha && numberRegEx.test(_alpha)) {
|
|
392
|
-
alpha = parseFloat(_alpha);
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
const [r, g, b] = hslToRgb(hue, saturation / 100, lightness / 100);
|
|
396
|
-
if (!_alphaString || alpha === 1) {
|
|
397
|
-
return 'rgb(' + r + ', ' + g + ', ' + b + ')';
|
|
398
|
-
}
|
|
399
|
-
return 'rgba(' + r + ', ' + g + ', ' + b + ', ' + alpha + ')';
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
if (type === exports.TYPES.COLOR) {
|
|
403
|
-
return val;
|
|
265
|
+
return res;
|
|
404
266
|
}
|
|
405
267
|
return undefined;
|
|
406
268
|
};
|
package/lib/properties/margin.js
CHANGED