cssstyle 5.2.0 → 5.3.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 +250 -254
- package/lib/generated/allProperties.js +39 -1
- package/lib/generated/implementedProperties.js +2219 -80
- package/lib/generated/properties.js +5253 -1904
- package/lib/normalize.js +1417 -0
- package/lib/parsers.js +372 -389
- package/lib/properties/background.js +76 -63
- package/lib/properties/backgroundAttachment.js +37 -22
- package/lib/properties/backgroundClip.js +37 -22
- package/lib/properties/backgroundColor.js +35 -15
- package/lib/properties/backgroundImage.js +49 -19
- package/lib/properties/backgroundOrigin.js +37 -22
- package/lib/properties/backgroundPosition.js +145 -128
- package/lib/properties/backgroundRepeat.js +55 -48
- package/lib/properties/backgroundSize.js +86 -46
- package/lib/properties/border.js +139 -22
- package/lib/properties/borderBottom.js +137 -21
- package/lib/properties/borderBottomColor.js +41 -16
- package/lib/properties/borderBottomStyle.js +39 -30
- package/lib/properties/borderBottomWidth.js +49 -16
- package/lib/properties/borderCollapse.js +32 -8
- package/lib/properties/borderColor.js +96 -23
- package/lib/properties/borderLeft.js +137 -21
- package/lib/properties/borderLeftColor.js +41 -16
- package/lib/properties/borderLeftStyle.js +39 -30
- package/lib/properties/borderLeftWidth.js +49 -16
- package/lib/properties/borderRight.js +137 -21
- package/lib/properties/borderRightColor.js +41 -16
- package/lib/properties/borderRightStyle.js +39 -30
- package/lib/properties/borderRightWidth.js +49 -16
- package/lib/properties/borderSpacing.js +42 -25
- package/lib/properties/borderStyle.js +96 -34
- package/lib/properties/borderTop.js +131 -15
- package/lib/properties/borderTopColor.js +41 -16
- package/lib/properties/borderTopStyle.js +39 -30
- package/lib/properties/borderTopWidth.js +49 -16
- package/lib/properties/borderWidth.js +108 -23
- package/lib/properties/bottom.js +40 -12
- package/lib/properties/clear.js +32 -22
- package/lib/properties/clip.js +46 -32
- package/lib/properties/color.js +34 -13
- package/lib/properties/display.js +169 -179
- package/lib/properties/flex.js +137 -38
- package/lib/properties/flexBasis.js +43 -14
- package/lib/properties/flexGrow.js +42 -9
- package/lib/properties/flexShrink.js +42 -9
- package/lib/properties/float.js +32 -9
- package/lib/properties/floodColor.js +34 -13
- package/lib/properties/font.js +145 -44
- package/lib/properties/fontFamily.js +66 -67
- package/lib/properties/fontSize.js +43 -26
- package/lib/properties/fontStyle.js +42 -11
- package/lib/properties/fontVariant.js +52 -15
- package/lib/properties/fontWeight.js +47 -15
- package/lib/properties/height.js +40 -13
- package/lib/properties/left.js +40 -12
- package/lib/properties/lightingColor.js +34 -13
- package/lib/properties/lineHeight.js +45 -18
- package/lib/properties/margin.js +73 -36
- package/lib/properties/marginBottom.js +43 -19
- package/lib/properties/marginLeft.js +43 -19
- package/lib/properties/marginRight.js +43 -19
- package/lib/properties/marginTop.js +43 -19
- package/lib/properties/opacity.js +41 -28
- package/lib/properties/outlineColor.js +34 -13
- package/lib/properties/padding.js +71 -36
- package/lib/properties/paddingBottom.js +44 -21
- package/lib/properties/paddingLeft.js +44 -19
- package/lib/properties/paddingRight.js +44 -19
- package/lib/properties/paddingTop.js +44 -19
- package/lib/properties/right.js +40 -12
- package/lib/properties/stopColor.js +34 -13
- package/lib/properties/top.js +40 -12
- package/lib/properties/webkitBorderAfterColor.js +34 -13
- package/lib/properties/webkitBorderBeforeColor.js +34 -13
- package/lib/properties/webkitBorderEndColor.js +34 -13
- package/lib/properties/webkitBorderStartColor.js +34 -13
- package/lib/properties/webkitColumnRuleColor.js +34 -13
- package/lib/properties/webkitTapHighlightColor.js +34 -13
- package/lib/properties/webkitTextEmphasisColor.js +34 -13
- package/lib/properties/webkitTextFillColor.js +34 -13
- package/lib/properties/webkitTextStrokeColor.js +34 -13
- package/lib/properties/width.js +40 -13
- package/lib/{allWebkitProperties.js → utils/allExtraProperties.js} +42 -1
- package/lib/utils/propertyDescriptors.js +6 -3
- package/package.json +11 -10
- package/lib/allExtraProperties.js +0 -49
- package/lib/shorthandProperties.js +0 -21
|
@@ -2,37 +2,64 @@
|
|
|
2
2
|
|
|
3
3
|
const parsers = require("../parsers");
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
if (val) {
|
|
8
|
-
return val;
|
|
9
|
-
}
|
|
10
|
-
const num = parsers.parseNumber(v, true);
|
|
11
|
-
if (num) {
|
|
12
|
-
return num;
|
|
13
|
-
}
|
|
14
|
-
return parsers.parseMeasurement(v, true);
|
|
15
|
-
};
|
|
5
|
+
const property = "line-height";
|
|
6
|
+
const shorthand = "font";
|
|
16
7
|
|
|
17
|
-
module.exports.
|
|
8
|
+
module.exports.parse = function parse(v, opt = {}) {
|
|
9
|
+
const { globalObject } = opt;
|
|
18
10
|
if (v === "") {
|
|
19
|
-
return
|
|
11
|
+
return v;
|
|
12
|
+
}
|
|
13
|
+
const value = parsers.parsePropertyValue(property, v, {
|
|
14
|
+
globalObject,
|
|
15
|
+
inArray: true
|
|
16
|
+
});
|
|
17
|
+
if (Array.isArray(value) && value.length === 1) {
|
|
18
|
+
const [{ name, type, value: itemValue }] = value;
|
|
19
|
+
switch (type) {
|
|
20
|
+
case "Calc": {
|
|
21
|
+
return `${name}(${itemValue})`;
|
|
22
|
+
}
|
|
23
|
+
case "GlobalKeyword":
|
|
24
|
+
case "Identifier": {
|
|
25
|
+
return name;
|
|
26
|
+
}
|
|
27
|
+
case "Number": {
|
|
28
|
+
return parsers.parseNumber(value, {
|
|
29
|
+
min: 0
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
default: {
|
|
33
|
+
return parsers.parseLengthPercentage(value, {
|
|
34
|
+
min: 0
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
} else if (typeof value === "string") {
|
|
39
|
+
return value;
|
|
20
40
|
}
|
|
21
|
-
return typeof module.exports.parse(v) === "string";
|
|
22
41
|
};
|
|
23
42
|
|
|
24
43
|
module.exports.definition = {
|
|
25
44
|
set(v) {
|
|
26
45
|
v = parsers.prepareValue(v, this._global);
|
|
27
46
|
if (parsers.hasVarFunc(v)) {
|
|
28
|
-
this._setProperty(
|
|
29
|
-
this._setProperty(
|
|
47
|
+
this._setProperty(shorthand, "");
|
|
48
|
+
this._setProperty(property, v);
|
|
30
49
|
} else {
|
|
31
|
-
|
|
50
|
+
const val = module.exports.parse(v, {
|
|
51
|
+
globalObject: this._global
|
|
52
|
+
});
|
|
53
|
+
if (typeof val === "string") {
|
|
54
|
+
const shorthandPriority = this._priorities.get(shorthand);
|
|
55
|
+
const prior = this._priorities.get(property) ?? "";
|
|
56
|
+
const priority = shorthandPriority && prior ? "" : prior;
|
|
57
|
+
this._setProperty(property, val, priority);
|
|
58
|
+
}
|
|
32
59
|
}
|
|
33
60
|
},
|
|
34
61
|
get() {
|
|
35
|
-
return this.getPropertyValue(
|
|
62
|
+
return this.getPropertyValue(property);
|
|
36
63
|
},
|
|
37
64
|
enumerable: true,
|
|
38
65
|
configurable: true
|
package/lib/properties/margin.js
CHANGED
|
@@ -1,57 +1,94 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
const parsers = require("../parsers");
|
|
4
|
+
const marginTop = require("./marginTop");
|
|
5
|
+
const marginRight = require("./marginRight");
|
|
6
|
+
const marginBottom = require("./marginBottom");
|
|
7
|
+
const marginLeft = require("./marginLeft");
|
|
4
8
|
|
|
5
|
-
const
|
|
9
|
+
const property = "margin";
|
|
6
10
|
|
|
7
|
-
module.exports.
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
module.exports.position = "edges";
|
|
12
|
+
|
|
13
|
+
module.exports.shorthandFor = new Map([
|
|
14
|
+
["margin-top", marginTop],
|
|
15
|
+
["margin-right", marginRight],
|
|
16
|
+
["margin-bottom", marginBottom],
|
|
17
|
+
["margin-left", marginLeft]
|
|
18
|
+
]);
|
|
14
19
|
|
|
15
|
-
module.exports.
|
|
20
|
+
module.exports.parse = function parse(v, opt = {}) {
|
|
21
|
+
const { globalObject } = opt;
|
|
16
22
|
if (v === "") {
|
|
17
|
-
return
|
|
23
|
+
return v;
|
|
24
|
+
}
|
|
25
|
+
const values = parsers.parsePropertyValue(property, v, {
|
|
26
|
+
globalObject,
|
|
27
|
+
inArray: true
|
|
28
|
+
});
|
|
29
|
+
const parsedValues = [];
|
|
30
|
+
if (Array.isArray(values) && values.length) {
|
|
31
|
+
if (values.length > 4) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
for (const value of values) {
|
|
35
|
+
const { isNumber, name, type, value: itemValue } = value;
|
|
36
|
+
switch (type) {
|
|
37
|
+
case "Calc": {
|
|
38
|
+
if (isNumber) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
parsedValues.push(`${name}(${itemValue})`);
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
case "GlobalKeyword": {
|
|
45
|
+
if (values.length !== 1) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
parsedValues.push(name);
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
case "Identifier": {
|
|
52
|
+
parsedValues.push(name);
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
default: {
|
|
56
|
+
const parsedValue = parsers.parseLengthPercentage([value]);
|
|
57
|
+
if (!parsedValue) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
parsedValues.push(parsedValue);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
} else if (typeof values === "string") {
|
|
65
|
+
parsedValues.push(values);
|
|
66
|
+
}
|
|
67
|
+
if (parsedValues.length) {
|
|
68
|
+
return parsedValues;
|
|
18
69
|
}
|
|
19
|
-
return typeof module.exports.parse(v) === "string";
|
|
20
70
|
};
|
|
21
71
|
|
|
22
72
|
module.exports.definition = {
|
|
23
73
|
set(v) {
|
|
24
74
|
v = parsers.prepareValue(v, this._global);
|
|
25
75
|
if (parsers.hasVarFunc(v)) {
|
|
26
|
-
|
|
27
|
-
"
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
module.exports.isValid,
|
|
31
|
-
module.exports.parse,
|
|
32
|
-
positions
|
|
33
|
-
);
|
|
34
|
-
this._setProperty("margin", v);
|
|
76
|
+
for (const [longhand] of module.exports.shorthandFor) {
|
|
77
|
+
this._setProperty(longhand, "");
|
|
78
|
+
}
|
|
79
|
+
this._setProperty(property, v);
|
|
35
80
|
} else {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
);
|
|
81
|
+
const val = module.exports.parse(v, {
|
|
82
|
+
globalObject: this._global
|
|
83
|
+
});
|
|
84
|
+
if (Array.isArray(val) || typeof val === "string") {
|
|
85
|
+
const priority = this._priorities.get(property) ?? "";
|
|
86
|
+
this._positionShorthandSetter(property, val, priority);
|
|
87
|
+
}
|
|
44
88
|
}
|
|
45
89
|
},
|
|
46
90
|
get() {
|
|
47
|
-
|
|
48
|
-
if (val === "") {
|
|
49
|
-
return this.getPropertyValue("margin");
|
|
50
|
-
}
|
|
51
|
-
if (parsers.hasVarFunc(val)) {
|
|
52
|
-
return "";
|
|
53
|
-
}
|
|
54
|
-
return val;
|
|
91
|
+
return this.getPropertyValue(property);
|
|
55
92
|
},
|
|
56
93
|
enumerable: true,
|
|
57
94
|
configurable: true
|
|
@@ -2,38 +2,62 @@
|
|
|
2
2
|
|
|
3
3
|
const parsers = require("../parsers");
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
return parsers.parseKeyword(v, ["auto"]);
|
|
11
|
-
};
|
|
5
|
+
const property = "margin-bottom";
|
|
6
|
+
const shorthand = "margin";
|
|
7
|
+
|
|
8
|
+
module.exports.position = "bottom";
|
|
12
9
|
|
|
13
|
-
module.exports.
|
|
10
|
+
module.exports.parse = function parse(v, opt = {}) {
|
|
11
|
+
const { globalObject } = opt;
|
|
14
12
|
if (v === "") {
|
|
15
|
-
return
|
|
13
|
+
return v;
|
|
14
|
+
}
|
|
15
|
+
const value = parsers.parsePropertyValue(property, v, {
|
|
16
|
+
globalObject,
|
|
17
|
+
inArray: true
|
|
18
|
+
});
|
|
19
|
+
if (Array.isArray(value) && value.length === 1) {
|
|
20
|
+
const [{ isNumber, name, type, value: itemValue }] = value;
|
|
21
|
+
switch (type) {
|
|
22
|
+
case "Calc": {
|
|
23
|
+
if (isNumber) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
return `${name}(${itemValue})`;
|
|
27
|
+
}
|
|
28
|
+
case "GlobalKeyword":
|
|
29
|
+
case "Identifier": {
|
|
30
|
+
return name;
|
|
31
|
+
}
|
|
32
|
+
default: {
|
|
33
|
+
return parsers.parseLengthPercentage(value);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
} else if (typeof value === "string") {
|
|
37
|
+
return value;
|
|
16
38
|
}
|
|
17
|
-
return typeof module.exports.parse(v) === "string";
|
|
18
39
|
};
|
|
19
40
|
|
|
20
41
|
module.exports.definition = {
|
|
21
42
|
set(v) {
|
|
22
43
|
v = parsers.prepareValue(v, this._global);
|
|
23
44
|
if (parsers.hasVarFunc(v)) {
|
|
24
|
-
this._setProperty(
|
|
25
|
-
this._setProperty(
|
|
45
|
+
this._setProperty(shorthand, "");
|
|
46
|
+
this._setProperty(property, v);
|
|
26
47
|
} else {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
48
|
+
const val = module.exports.parse(v, {
|
|
49
|
+
globalObject: this._global
|
|
50
|
+
});
|
|
51
|
+
if (typeof val === "string") {
|
|
52
|
+
const shorthandPriority = this._priorities.get(shorthand);
|
|
53
|
+
const prior = this._priorities.get(property) ?? "";
|
|
54
|
+
const priority = shorthandPriority && prior ? "" : prior;
|
|
55
|
+
this._positionLonghandSetter(property, val, priority, shorthand);
|
|
56
|
+
}
|
|
33
57
|
}
|
|
34
58
|
},
|
|
35
59
|
get() {
|
|
36
|
-
return this.getPropertyValue(
|
|
60
|
+
return this.getPropertyValue(property);
|
|
37
61
|
},
|
|
38
62
|
enumerable: true,
|
|
39
63
|
configurable: true
|
|
@@ -2,38 +2,62 @@
|
|
|
2
2
|
|
|
3
3
|
const parsers = require("../parsers");
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
return parsers.parseKeyword(v, ["auto"]);
|
|
11
|
-
};
|
|
5
|
+
const property = "margin-left";
|
|
6
|
+
const shorthand = "margin";
|
|
7
|
+
|
|
8
|
+
module.exports.position = "left";
|
|
12
9
|
|
|
13
|
-
module.exports.
|
|
10
|
+
module.exports.parse = function parse(v, opt = {}) {
|
|
11
|
+
const { globalObject } = opt;
|
|
14
12
|
if (v === "") {
|
|
15
|
-
return
|
|
13
|
+
return v;
|
|
14
|
+
}
|
|
15
|
+
const value = parsers.parsePropertyValue(property, v, {
|
|
16
|
+
globalObject,
|
|
17
|
+
inArray: true
|
|
18
|
+
});
|
|
19
|
+
if (Array.isArray(value) && value.length === 1) {
|
|
20
|
+
const [{ isNumber, name, type, value: itemValue }] = value;
|
|
21
|
+
switch (type) {
|
|
22
|
+
case "Calc": {
|
|
23
|
+
if (isNumber) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
return `${name}(${itemValue})`;
|
|
27
|
+
}
|
|
28
|
+
case "GlobalKeyword":
|
|
29
|
+
case "Identifier": {
|
|
30
|
+
return name;
|
|
31
|
+
}
|
|
32
|
+
default: {
|
|
33
|
+
return parsers.parseLengthPercentage(value);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
} else if (typeof value === "string") {
|
|
37
|
+
return value;
|
|
16
38
|
}
|
|
17
|
-
return typeof module.exports.parse(v) === "string";
|
|
18
39
|
};
|
|
19
40
|
|
|
20
41
|
module.exports.definition = {
|
|
21
42
|
set(v) {
|
|
22
43
|
v = parsers.prepareValue(v, this._global);
|
|
23
44
|
if (parsers.hasVarFunc(v)) {
|
|
24
|
-
this._setProperty(
|
|
25
|
-
this._setProperty(
|
|
45
|
+
this._setProperty(shorthand, "");
|
|
46
|
+
this._setProperty(property, v);
|
|
26
47
|
} else {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
48
|
+
const val = module.exports.parse(v, {
|
|
49
|
+
globalObject: this._global
|
|
50
|
+
});
|
|
51
|
+
if (typeof val === "string") {
|
|
52
|
+
const shorthandPriority = this._priorities.get(shorthand);
|
|
53
|
+
const prior = this._priorities.get(property) ?? "";
|
|
54
|
+
const priority = shorthandPriority && prior ? "" : prior;
|
|
55
|
+
this._positionLonghandSetter(property, val, priority, shorthand);
|
|
56
|
+
}
|
|
33
57
|
}
|
|
34
58
|
},
|
|
35
59
|
get() {
|
|
36
|
-
return this.getPropertyValue(
|
|
60
|
+
return this.getPropertyValue(property);
|
|
37
61
|
},
|
|
38
62
|
enumerable: true,
|
|
39
63
|
configurable: true
|
|
@@ -2,38 +2,62 @@
|
|
|
2
2
|
|
|
3
3
|
const parsers = require("../parsers");
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
return parsers.parseKeyword(v, ["auto"]);
|
|
11
|
-
};
|
|
5
|
+
const property = "margin-right";
|
|
6
|
+
const shorthand = "margin";
|
|
7
|
+
|
|
8
|
+
module.exports.position = "right";
|
|
12
9
|
|
|
13
|
-
module.exports.
|
|
10
|
+
module.exports.parse = function parse(v, opt = {}) {
|
|
11
|
+
const { globalObject } = opt;
|
|
14
12
|
if (v === "") {
|
|
15
|
-
return
|
|
13
|
+
return v;
|
|
14
|
+
}
|
|
15
|
+
const value = parsers.parsePropertyValue(property, v, {
|
|
16
|
+
globalObject,
|
|
17
|
+
inArray: true
|
|
18
|
+
});
|
|
19
|
+
if (Array.isArray(value) && value.length === 1) {
|
|
20
|
+
const [{ isNumber, name, type, value: itemValue }] = value;
|
|
21
|
+
switch (type) {
|
|
22
|
+
case "Calc": {
|
|
23
|
+
if (isNumber) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
return `${name}(${itemValue})`;
|
|
27
|
+
}
|
|
28
|
+
case "GlobalKeyword":
|
|
29
|
+
case "Identifier": {
|
|
30
|
+
return name;
|
|
31
|
+
}
|
|
32
|
+
default: {
|
|
33
|
+
return parsers.parseLengthPercentage(value);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
} else if (typeof value === "string") {
|
|
37
|
+
return value;
|
|
16
38
|
}
|
|
17
|
-
return typeof module.exports.parse(v) === "string";
|
|
18
39
|
};
|
|
19
40
|
|
|
20
41
|
module.exports.definition = {
|
|
21
42
|
set(v) {
|
|
22
43
|
v = parsers.prepareValue(v, this._global);
|
|
23
44
|
if (parsers.hasVarFunc(v)) {
|
|
24
|
-
this._setProperty(
|
|
25
|
-
this._setProperty(
|
|
45
|
+
this._setProperty(shorthand, "");
|
|
46
|
+
this._setProperty(property, v);
|
|
26
47
|
} else {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
48
|
+
const val = module.exports.parse(v, {
|
|
49
|
+
globalObject: this._global
|
|
50
|
+
});
|
|
51
|
+
if (typeof val === "string") {
|
|
52
|
+
const shorthandPriority = this._priorities.get(shorthand);
|
|
53
|
+
const prior = this._priorities.get(property) ?? "";
|
|
54
|
+
const priority = shorthandPriority && prior ? "" : prior;
|
|
55
|
+
this._positionLonghandSetter(property, val, priority, shorthand);
|
|
56
|
+
}
|
|
33
57
|
}
|
|
34
58
|
},
|
|
35
59
|
get() {
|
|
36
|
-
return this.getPropertyValue(
|
|
60
|
+
return this.getPropertyValue(property);
|
|
37
61
|
},
|
|
38
62
|
enumerable: true,
|
|
39
63
|
configurable: true
|
|
@@ -2,38 +2,62 @@
|
|
|
2
2
|
|
|
3
3
|
const parsers = require("../parsers");
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
return parsers.parseKeyword(v, ["auto"]);
|
|
11
|
-
};
|
|
5
|
+
const property = "margin-top";
|
|
6
|
+
const shorthand = "margin";
|
|
7
|
+
|
|
8
|
+
module.exports.position = "top";
|
|
12
9
|
|
|
13
|
-
module.exports.
|
|
10
|
+
module.exports.parse = function parse(v, opt = {}) {
|
|
11
|
+
const { globalObject } = opt;
|
|
14
12
|
if (v === "") {
|
|
15
|
-
return
|
|
13
|
+
return v;
|
|
14
|
+
}
|
|
15
|
+
const value = parsers.parsePropertyValue(property, v, {
|
|
16
|
+
globalObject,
|
|
17
|
+
inArray: true
|
|
18
|
+
});
|
|
19
|
+
if (Array.isArray(value) && value.length === 1) {
|
|
20
|
+
const [{ isNumber, name, type, value: itemValue }] = value;
|
|
21
|
+
switch (type) {
|
|
22
|
+
case "Calc": {
|
|
23
|
+
if (isNumber) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
return `${name}(${itemValue})`;
|
|
27
|
+
}
|
|
28
|
+
case "GlobalKeyword":
|
|
29
|
+
case "Identifier": {
|
|
30
|
+
return name;
|
|
31
|
+
}
|
|
32
|
+
default: {
|
|
33
|
+
return parsers.parseLengthPercentage(value);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
} else if (typeof value === "string") {
|
|
37
|
+
return value;
|
|
16
38
|
}
|
|
17
|
-
return typeof module.exports.parse(v) === "string";
|
|
18
39
|
};
|
|
19
40
|
|
|
20
41
|
module.exports.definition = {
|
|
21
42
|
set(v) {
|
|
22
43
|
v = parsers.prepareValue(v, this._global);
|
|
23
44
|
if (parsers.hasVarFunc(v)) {
|
|
24
|
-
this._setProperty(
|
|
25
|
-
this._setProperty(
|
|
45
|
+
this._setProperty(shorthand, "");
|
|
46
|
+
this._setProperty(property, v);
|
|
26
47
|
} else {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
48
|
+
const val = module.exports.parse(v, {
|
|
49
|
+
globalObject: this._global
|
|
50
|
+
});
|
|
51
|
+
if (typeof val === "string") {
|
|
52
|
+
const shorthandPriority = this._priorities.get(shorthand);
|
|
53
|
+
const prior = this._priorities.get(property) ?? "";
|
|
54
|
+
const priority = shorthandPriority && prior ? "" : prior;
|
|
55
|
+
this._positionLonghandSetter(property, val, priority, shorthand);
|
|
56
|
+
}
|
|
33
57
|
}
|
|
34
58
|
},
|
|
35
59
|
get() {
|
|
36
|
-
return this.getPropertyValue(
|
|
60
|
+
return this.getPropertyValue(property);
|
|
37
61
|
},
|
|
38
62
|
enumerable: true,
|
|
39
63
|
configurable: true
|
|
@@ -2,44 +2,57 @@
|
|
|
2
2
|
|
|
3
3
|
const parsers = require("../parsers");
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
let num = parsers.parseNumber(v);
|
|
7
|
-
if (num) {
|
|
8
|
-
num = parseFloat(num);
|
|
9
|
-
if (num < 0) {
|
|
10
|
-
return "0";
|
|
11
|
-
} else if (num > 1) {
|
|
12
|
-
return "1";
|
|
13
|
-
}
|
|
14
|
-
return `${num}`;
|
|
15
|
-
}
|
|
16
|
-
let pct = parsers.parsePercent(v);
|
|
17
|
-
if (pct) {
|
|
18
|
-
pct = parseFloat(pct);
|
|
19
|
-
if (pct < 0) {
|
|
20
|
-
return "0%";
|
|
21
|
-
} else if (pct > 100) {
|
|
22
|
-
return "100%";
|
|
23
|
-
}
|
|
24
|
-
return `${pct}%`;
|
|
25
|
-
}
|
|
26
|
-
return parsers.parseKeyword(v);
|
|
27
|
-
};
|
|
5
|
+
const property = "opacity";
|
|
28
6
|
|
|
29
|
-
module.exports.
|
|
7
|
+
module.exports.parse = function parse(v, opt = {}) {
|
|
8
|
+
const { globalObject } = opt;
|
|
30
9
|
if (v === "") {
|
|
31
|
-
return
|
|
10
|
+
return v;
|
|
11
|
+
}
|
|
12
|
+
const value = parsers.parsePropertyValue(property, v, {
|
|
13
|
+
globalObject,
|
|
14
|
+
inArray: true
|
|
15
|
+
});
|
|
16
|
+
if (Array.isArray(value) && value.length === 1) {
|
|
17
|
+
const [{ name, type, value: itemValue }] = value;
|
|
18
|
+
switch (type) {
|
|
19
|
+
case "Calc": {
|
|
20
|
+
return `${name}(${itemValue})`;
|
|
21
|
+
}
|
|
22
|
+
case "GlobalKeyword":
|
|
23
|
+
case "Identifier": {
|
|
24
|
+
return name;
|
|
25
|
+
}
|
|
26
|
+
case "Number": {
|
|
27
|
+
return parsers.parseNumber(value);
|
|
28
|
+
}
|
|
29
|
+
case "Percentage": {
|
|
30
|
+
return parsers.parsePercentage(value);
|
|
31
|
+
}
|
|
32
|
+
default:
|
|
33
|
+
}
|
|
34
|
+
} else if (typeof value === "string") {
|
|
35
|
+
return value;
|
|
32
36
|
}
|
|
33
|
-
return typeof module.exports.parse(v) === "string";
|
|
34
37
|
};
|
|
35
38
|
|
|
36
39
|
module.exports.definition = {
|
|
37
40
|
set(v) {
|
|
38
41
|
v = parsers.prepareValue(v, this._global);
|
|
39
|
-
|
|
42
|
+
if (parsers.hasVarFunc(v)) {
|
|
43
|
+
this._setProperty(property, v);
|
|
44
|
+
} else {
|
|
45
|
+
const val = module.exports.parse(v, {
|
|
46
|
+
globalObject: this._global
|
|
47
|
+
});
|
|
48
|
+
if (typeof val === "string") {
|
|
49
|
+
const priority = this._priorities.get(property) ?? "";
|
|
50
|
+
this._setProperty(property, val, priority);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
40
53
|
},
|
|
41
54
|
get() {
|
|
42
|
-
return this.getPropertyValue(
|
|
55
|
+
return this.getPropertyValue(property);
|
|
43
56
|
},
|
|
44
57
|
enumerable: true,
|
|
45
58
|
configurable: true
|
|
@@ -2,28 +2,49 @@
|
|
|
2
2
|
|
|
3
3
|
const parsers = require("../parsers");
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
const val = parsers.parseColor(v);
|
|
7
|
-
if (val) {
|
|
8
|
-
return val;
|
|
9
|
-
}
|
|
10
|
-
return parsers.parseKeyword(v);
|
|
11
|
-
};
|
|
5
|
+
const property = "outline-color";
|
|
12
6
|
|
|
13
|
-
module.exports.
|
|
14
|
-
|
|
15
|
-
|
|
7
|
+
module.exports.parse = function parse(v, opt = {}) {
|
|
8
|
+
const { globalObject } = opt;
|
|
9
|
+
if (v === "") {
|
|
10
|
+
return v;
|
|
11
|
+
}
|
|
12
|
+
const value = parsers.parsePropertyValue(property, v, {
|
|
13
|
+
globalObject,
|
|
14
|
+
inArray: true
|
|
15
|
+
});
|
|
16
|
+
if (Array.isArray(value) && value.length === 1) {
|
|
17
|
+
const [{ name, type }] = value;
|
|
18
|
+
switch (type) {
|
|
19
|
+
case "GlobalKeyword": {
|
|
20
|
+
return name;
|
|
21
|
+
}
|
|
22
|
+
default: {
|
|
23
|
+
return parsers.parseColor(value);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
} else if (typeof value === "string") {
|
|
27
|
+
return value;
|
|
16
28
|
}
|
|
17
|
-
return parsers.isValidColor(v);
|
|
18
29
|
};
|
|
19
30
|
|
|
20
31
|
module.exports.definition = {
|
|
21
32
|
set(v) {
|
|
22
33
|
v = parsers.prepareValue(v, this._global);
|
|
23
|
-
|
|
34
|
+
if (parsers.hasVarFunc(v)) {
|
|
35
|
+
this._setProperty(property, v);
|
|
36
|
+
} else {
|
|
37
|
+
const val = module.exports.parse(v, {
|
|
38
|
+
globalObject: this._global
|
|
39
|
+
});
|
|
40
|
+
if (typeof val === "string") {
|
|
41
|
+
const priority = this._priorities.get(property) ?? "";
|
|
42
|
+
this._setProperty(property, val, priority);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
24
45
|
},
|
|
25
46
|
get() {
|
|
26
|
-
return this.getPropertyValue(
|
|
47
|
+
return this.getPropertyValue(property);
|
|
27
48
|
},
|
|
28
49
|
enumerable: true,
|
|
29
50
|
configurable: true
|