cssstyle 4.3.1 → 4.5.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 +545 -206
- package/lib/allExtraProperties.js +42 -60
- package/lib/allWebkitProperties.js +107 -187
- package/lib/generated/allProperties.js +615 -0
- package/lib/{implementedProperties.js → generated/implementedProperties.js} +11 -18
- package/lib/generated/properties.js +2661 -0
- package/lib/parsers.js +382 -547
- package/lib/properties/background.js +40 -13
- package/lib/properties/backgroundAttachment.js +23 -15
- package/lib/properties/backgroundColor.js +21 -19
- package/lib/properties/backgroundImage.js +19 -14
- package/lib/properties/backgroundPosition.js +35 -41
- package/lib/properties/backgroundRepeat.js +20 -20
- package/lib/properties/border.js +34 -25
- package/lib/properties/borderBottom.js +34 -11
- package/lib/properties/borderBottomColor.js +27 -8
- package/lib/properties/borderBottomStyle.js +42 -13
- package/lib/properties/borderBottomWidth.js +28 -8
- package/lib/properties/borderCollapse.js +16 -16
- package/lib/properties/borderColor.js +32 -18
- package/lib/properties/borderLeft.js +34 -11
- package/lib/properties/borderLeftColor.js +27 -8
- package/lib/properties/borderLeftStyle.js +42 -13
- package/lib/properties/borderLeftWidth.js +28 -8
- package/lib/properties/borderRight.js +34 -11
- package/lib/properties/borderRightColor.js +27 -8
- package/lib/properties/borderRightStyle.js +42 -13
- package/lib/properties/borderRightWidth.js +28 -8
- package/lib/properties/borderSpacing.js +31 -27
- package/lib/properties/borderStyle.js +43 -27
- package/lib/properties/borderTop.js +34 -11
- package/lib/properties/borderTopColor.js +27 -8
- package/lib/properties/borderTopStyle.js +42 -13
- package/lib/properties/borderTopWidth.js +28 -9
- package/lib/properties/borderWidth.js +32 -34
- package/lib/properties/bottom.js +23 -7
- package/lib/properties/clear.js +32 -8
- package/lib/properties/clip.js +33 -27
- package/lib/properties/color.js +23 -7
- package/lib/properties/flex.js +59 -29
- package/lib/properties/flexBasis.js +21 -16
- package/lib/properties/flexGrow.js +19 -10
- package/lib/properties/flexShrink.js +19 -10
- package/lib/properties/float.js +21 -6
- package/lib/properties/floodColor.js +23 -7
- package/lib/properties/font.js +185 -33
- package/lib/properties/fontFamily.js +73 -21
- package/lib/properties/fontSize.js +37 -28
- package/lib/properties/fontStyle.js +23 -9
- package/lib/properties/fontVariant.js +26 -8
- package/lib/properties/fontWeight.js +26 -23
- package/lib/properties/height.js +21 -14
- package/lib/properties/left.js +23 -7
- package/lib/properties/lightingColor.js +23 -7
- package/lib/properties/lineHeight.js +29 -16
- package/lib/properties/margin.js +42 -57
- package/lib/properties/marginBottom.js +34 -7
- package/lib/properties/marginLeft.js +34 -7
- package/lib/properties/marginRight.js +34 -7
- package/lib/properties/marginTop.js +34 -7
- package/lib/properties/opacity.js +39 -7
- package/lib/properties/outlineColor.js +23 -7
- package/lib/properties/padding.js +43 -51
- package/lib/properties/paddingBottom.js +36 -7
- package/lib/properties/paddingLeft.js +34 -7
- package/lib/properties/paddingRight.js +34 -7
- package/lib/properties/paddingTop.js +34 -7
- package/lib/properties/right.js +23 -7
- package/lib/properties/stopColor.js +23 -7
- package/lib/properties/top.js +23 -7
- package/lib/properties/webkitBorderAfterColor.js +23 -7
- package/lib/properties/webkitBorderBeforeColor.js +23 -7
- package/lib/properties/webkitBorderEndColor.js +23 -7
- package/lib/properties/webkitBorderStartColor.js +23 -7
- package/lib/properties/webkitColumnRuleColor.js +23 -7
- package/lib/properties/webkitTapHighlightColor.js +23 -7
- package/lib/properties/webkitTextEmphasisColor.js +23 -7
- package/lib/properties/webkitTextFillColor.js +23 -7
- package/lib/properties/webkitTextStrokeColor.js +23 -7
- package/lib/properties/width.js +21 -14
- package/lib/utils/camelize.js +35 -0
- package/lib/utils/propertyDescriptors.js +16 -0
- package/package.json +5 -4
- package/lib/allProperties.js +0 -529
- package/lib/constants.js +0 -6
- package/lib/named_colors.json +0 -152
- package/lib/properties/azimuth.js +0 -64
- package/lib/properties/cssFloat.js +0 -12
- package/lib/properties/textLineThroughColor.js +0 -14
- package/lib/properties/textOverlineColor.js +0 -14
- package/lib/properties/textUnderlineColor.js +0 -14
- package/lib/properties/webkitMatchNearestMailBlockquoteColor.js +0 -14
- package/lib/properties.js +0 -1672
- package/lib/utils/getBasicPropertyDescriptor.js +0 -14
package/lib/properties/flex.js
CHANGED
|
@@ -1,43 +1,73 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
const parsers = require("../parsers");
|
|
4
|
+
const flexGrow = require("./flexGrow");
|
|
5
|
+
const flexShrink = require("./flexShrink");
|
|
6
|
+
const flexBasis = require("./flexBasis");
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
const shorthandFor = new Map([
|
|
9
|
+
["flex-grow", flexGrow],
|
|
10
|
+
["flex-shrink", flexShrink],
|
|
11
|
+
["flex-basis", flexBasis]
|
|
12
|
+
]);
|
|
12
13
|
|
|
13
|
-
|
|
14
|
+
module.exports.parse = function parse(v) {
|
|
15
|
+
const key = parsers.parseKeyword(v, ["auto", "none"]);
|
|
16
|
+
if (key) {
|
|
17
|
+
if (key === "auto") {
|
|
18
|
+
return "1 1 auto";
|
|
19
|
+
}
|
|
20
|
+
if (key === "none") {
|
|
21
|
+
return "0 0 auto";
|
|
22
|
+
}
|
|
23
|
+
if (key === "initial") {
|
|
24
|
+
return "0 1 auto";
|
|
25
|
+
}
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const obj = parsers.parseShorthand(v, shorthandFor);
|
|
29
|
+
if (obj) {
|
|
30
|
+
const flex = {
|
|
31
|
+
"flex-grow": "1",
|
|
32
|
+
"flex-shrink": "1",
|
|
33
|
+
"flex-basis": "0%"
|
|
34
|
+
};
|
|
35
|
+
const items = Object.entries(obj);
|
|
36
|
+
for (const [property, value] of items) {
|
|
37
|
+
flex[property] = value;
|
|
38
|
+
}
|
|
39
|
+
return [...Object.values(flex)].join(" ");
|
|
40
|
+
}
|
|
41
|
+
};
|
|
14
42
|
|
|
15
43
|
module.exports.isValid = function isValid(v) {
|
|
16
|
-
|
|
44
|
+
if (v === "") {
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
return typeof module.exports.parse(v) === "string";
|
|
17
48
|
};
|
|
18
49
|
|
|
19
50
|
module.exports.definition = {
|
|
20
|
-
set
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
51
|
+
set(v) {
|
|
52
|
+
v = parsers.prepareValue(v, this._global);
|
|
53
|
+
if (parsers.hasVarFunc(v)) {
|
|
54
|
+
this._shorthandSetter("flex", "", shorthandFor);
|
|
55
|
+
this._setProperty("flex", v);
|
|
56
|
+
} else {
|
|
57
|
+
this._shorthandSetter("flex", module.exports.parse(v), shorthandFor);
|
|
26
58
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
59
|
+
},
|
|
60
|
+
get() {
|
|
61
|
+
let val = this.getPropertyValue("flex");
|
|
62
|
+
if (parsers.hasVarFunc(val)) {
|
|
63
|
+
return val;
|
|
30
64
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
this.setProperty('flex-basis', normalizedValue);
|
|
35
|
-
return;
|
|
65
|
+
val = this._shorthandGetter("flex", shorthandFor);
|
|
66
|
+
if (parsers.hasVarFunc(val)) {
|
|
67
|
+
return "";
|
|
36
68
|
}
|
|
37
|
-
|
|
38
|
-
myShorthandSetter.call(this, v);
|
|
69
|
+
return val;
|
|
39
70
|
},
|
|
40
|
-
get: shorthandGetter('flex', shorthand_for),
|
|
41
71
|
enumerable: true,
|
|
42
|
-
configurable: true
|
|
72
|
+
configurable: true
|
|
43
73
|
};
|
|
@@ -1,28 +1,33 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
const parsers = require("../parsers");
|
|
4
4
|
|
|
5
|
-
function parse(v) {
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
module.exports.parse = function parse(v) {
|
|
6
|
+
const val = parsers.parseMeasurement(v);
|
|
7
|
+
if (val) {
|
|
8
|
+
return val;
|
|
8
9
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
return parseMeasurement(v);
|
|
13
|
-
}
|
|
10
|
+
const keywords = ["content", "auto", "min-content", "max-content"];
|
|
11
|
+
return parsers.parseKeyword(v, keywords);
|
|
12
|
+
};
|
|
14
13
|
|
|
15
14
|
module.exports.isValid = function isValid(v) {
|
|
16
|
-
return parse(v)
|
|
15
|
+
return typeof module.exports.parse(v) === "string";
|
|
17
16
|
};
|
|
18
17
|
|
|
19
18
|
module.exports.definition = {
|
|
20
|
-
set
|
|
21
|
-
|
|
19
|
+
set(v) {
|
|
20
|
+
v = parsers.prepareValue(v, this._global);
|
|
21
|
+
if (parsers.hasVarFunc(v)) {
|
|
22
|
+
this._setProperty("flex", "");
|
|
23
|
+
this._setProperty("flex-basis", v);
|
|
24
|
+
} else {
|
|
25
|
+
this._setProperty("flex-basis", module.exports.parse(v));
|
|
26
|
+
}
|
|
22
27
|
},
|
|
23
|
-
get
|
|
24
|
-
return this.getPropertyValue(
|
|
28
|
+
get() {
|
|
29
|
+
return this.getPropertyValue("flex-basis");
|
|
25
30
|
},
|
|
26
31
|
enumerable: true,
|
|
27
|
-
configurable: true
|
|
32
|
+
configurable: true
|
|
28
33
|
};
|
|
@@ -1,19 +1,28 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
var POSITION_AT_SHORTHAND = require('../constants').POSITION_AT_SHORTHAND;
|
|
3
|
+
const parsers = require("../parsers");
|
|
5
4
|
|
|
6
|
-
module.exports.
|
|
7
|
-
return parseNumber(v)
|
|
5
|
+
module.exports.parse = function parse(v) {
|
|
6
|
+
return parsers.parseNumber(v, true);
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
module.exports.isValid = function isValid(v) {
|
|
10
|
+
return typeof module.exports.parse(v) === "string";
|
|
8
11
|
};
|
|
9
12
|
|
|
10
13
|
module.exports.definition = {
|
|
11
|
-
set
|
|
12
|
-
|
|
14
|
+
set(v) {
|
|
15
|
+
v = parsers.prepareValue(v, this._global);
|
|
16
|
+
if (parsers.hasVarFunc(v)) {
|
|
17
|
+
this._setProperty("flex", "");
|
|
18
|
+
this._setProperty("flex-grow", v);
|
|
19
|
+
} else {
|
|
20
|
+
this._setProperty("flex-grow", module.exports.parse(v));
|
|
21
|
+
}
|
|
13
22
|
},
|
|
14
|
-
get
|
|
15
|
-
return this.getPropertyValue(
|
|
23
|
+
get() {
|
|
24
|
+
return this.getPropertyValue("flex-grow");
|
|
16
25
|
},
|
|
17
26
|
enumerable: true,
|
|
18
|
-
configurable: true
|
|
27
|
+
configurable: true
|
|
19
28
|
};
|
|
@@ -1,19 +1,28 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
var POSITION_AT_SHORTHAND = require('../constants').POSITION_AT_SHORTHAND;
|
|
3
|
+
const parsers = require("../parsers");
|
|
5
4
|
|
|
6
|
-
module.exports.
|
|
7
|
-
return parseNumber(v)
|
|
5
|
+
module.exports.parse = function parse(v) {
|
|
6
|
+
return parsers.parseNumber(v, true);
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
module.exports.isValid = function isValid(v) {
|
|
10
|
+
return typeof module.exports.parse(v) === "string";
|
|
8
11
|
};
|
|
9
12
|
|
|
10
13
|
module.exports.definition = {
|
|
11
|
-
set
|
|
12
|
-
|
|
14
|
+
set(v) {
|
|
15
|
+
v = parsers.prepareValue(v, this._global);
|
|
16
|
+
if (parsers.hasVarFunc(v)) {
|
|
17
|
+
this._setProperty("flex", "");
|
|
18
|
+
this._setProperty("flex-shrink", v);
|
|
19
|
+
} else {
|
|
20
|
+
this._setProperty("flex-shrink", module.exports.parse(v));
|
|
21
|
+
}
|
|
13
22
|
},
|
|
14
|
-
get
|
|
15
|
-
return this.getPropertyValue(
|
|
23
|
+
get() {
|
|
24
|
+
return this.getPropertyValue("flex-shrink");
|
|
16
25
|
},
|
|
17
26
|
enumerable: true,
|
|
18
|
-
configurable: true
|
|
27
|
+
configurable: true
|
|
19
28
|
};
|
package/lib/properties/float.js
CHANGED
|
@@ -1,12 +1,27 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const parsers = require("../parsers");
|
|
4
|
+
|
|
5
|
+
module.exports.parse = function parse(v) {
|
|
6
|
+
const keywords = ["left", "right", "none", "inline-start", "inline-end"];
|
|
7
|
+
return parsers.parseKeyword(v, keywords);
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
module.exports.isValid = function isValid(v) {
|
|
11
|
+
if (v === "") {
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
return typeof module.exports.parse(v) === "string";
|
|
15
|
+
};
|
|
2
16
|
|
|
3
17
|
module.exports.definition = {
|
|
4
|
-
set
|
|
5
|
-
|
|
18
|
+
set(v) {
|
|
19
|
+
v = parsers.prepareValue(v, this._global);
|
|
20
|
+
this._setProperty("float", module.exports.parse(v));
|
|
6
21
|
},
|
|
7
|
-
get
|
|
8
|
-
return this.getPropertyValue(
|
|
22
|
+
get() {
|
|
23
|
+
return this.getPropertyValue("float");
|
|
9
24
|
},
|
|
10
25
|
enumerable: true,
|
|
11
|
-
configurable: true
|
|
26
|
+
configurable: true
|
|
12
27
|
};
|
|
@@ -1,14 +1,30 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
const parsers = require("../parsers");
|
|
4
|
+
|
|
5
|
+
module.exports.parse = function parse(v) {
|
|
6
|
+
const val = parsers.parseColor(v);
|
|
7
|
+
if (val) {
|
|
8
|
+
return val;
|
|
9
|
+
}
|
|
10
|
+
return parsers.parseKeyword(v);
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
module.exports.isValid = function isValid(v) {
|
|
14
|
+
if (v === "" || typeof parsers.parseKeyword(v) === "string") {
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
return parsers.isValidColor(v);
|
|
18
|
+
};
|
|
4
19
|
|
|
5
20
|
module.exports.definition = {
|
|
6
|
-
set
|
|
7
|
-
|
|
21
|
+
set(v) {
|
|
22
|
+
v = parsers.prepareValue(v, this._global);
|
|
23
|
+
this._setProperty("flood-color", module.exports.parse(v));
|
|
8
24
|
},
|
|
9
|
-
get
|
|
10
|
-
return this.getPropertyValue(
|
|
25
|
+
get() {
|
|
26
|
+
return this.getPropertyValue("flood-color");
|
|
11
27
|
},
|
|
12
28
|
enumerable: true,
|
|
13
|
-
configurable: true
|
|
29
|
+
configurable: true
|
|
14
30
|
};
|
package/lib/properties/font.js
CHANGED
|
@@ -1,43 +1,195 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
const parsers = require("../parsers");
|
|
4
|
+
const fontStyle = require("./fontStyle");
|
|
5
|
+
const fontVariant = require("./fontVariant");
|
|
6
|
+
const fontWeight = require("./fontWeight");
|
|
7
|
+
const fontSize = require("./fontSize");
|
|
8
|
+
const lineHeight = require("./lineHeight");
|
|
9
|
+
const fontFamily = require("./fontFamily");
|
|
8
10
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
var static_fonts = [
|
|
19
|
-
'caption',
|
|
20
|
-
'icon',
|
|
21
|
-
'menu',
|
|
22
|
-
'message-box',
|
|
23
|
-
'small-caption',
|
|
24
|
-
'status-bar',
|
|
25
|
-
'inherit',
|
|
26
|
-
];
|
|
11
|
+
const shorthandFor = new Map([
|
|
12
|
+
["font-style", fontStyle],
|
|
13
|
+
["font-variant", fontVariant],
|
|
14
|
+
["font-weight", fontWeight],
|
|
15
|
+
["font-size", fontSize],
|
|
16
|
+
["line-height", lineHeight],
|
|
17
|
+
["font-family", fontFamily]
|
|
18
|
+
]);
|
|
27
19
|
|
|
28
|
-
|
|
20
|
+
module.exports.parse = function parse(v) {
|
|
21
|
+
const keywords = ["caption", "icon", "menu", "message-box", "small-caption", "status-bar"];
|
|
22
|
+
const key = parsers.parseKeyword(v, keywords);
|
|
23
|
+
if (key) {
|
|
24
|
+
return key;
|
|
25
|
+
}
|
|
26
|
+
const [fontBlock, ...families] = parsers.splitValue(v, {
|
|
27
|
+
delimiter: ","
|
|
28
|
+
});
|
|
29
|
+
const [fontBlockA, fontBlockB] = parsers.splitValue(fontBlock, {
|
|
30
|
+
delimiter: "/"
|
|
31
|
+
});
|
|
32
|
+
const font = {
|
|
33
|
+
"font-style": "normal",
|
|
34
|
+
"font-variant": "normal",
|
|
35
|
+
"font-weight": "normal"
|
|
36
|
+
};
|
|
37
|
+
const fontFamilies = new Set();
|
|
38
|
+
if (fontBlockB) {
|
|
39
|
+
const [lineB, ...familiesB] = fontBlockB.trim().split(" ");
|
|
40
|
+
if (!lineB || !lineHeight.isValid(lineB) || !familiesB.length) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const lineHeightB = lineHeight.parse(lineB);
|
|
44
|
+
const familyB = familiesB.join(" ");
|
|
45
|
+
if (fontFamily.isValid(familyB)) {
|
|
46
|
+
fontFamilies.add(fontFamily.parse(familyB));
|
|
47
|
+
} else {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const parts = parsers.splitValue(fontBlockA.trim());
|
|
51
|
+
const properties = ["font-style", "font-variant", "font-weight", "font-size"];
|
|
52
|
+
for (const part of parts) {
|
|
53
|
+
if (part === "normal") {
|
|
54
|
+
continue;
|
|
55
|
+
} else {
|
|
56
|
+
for (const property of properties) {
|
|
57
|
+
switch (property) {
|
|
58
|
+
case "font-style":
|
|
59
|
+
case "font-variant":
|
|
60
|
+
case "font-weight": {
|
|
61
|
+
const value = shorthandFor.get(property);
|
|
62
|
+
if (value.isValid(part)) {
|
|
63
|
+
font[property] = value.parse(part);
|
|
64
|
+
}
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
case "font-size": {
|
|
68
|
+
const value = shorthandFor.get(property);
|
|
69
|
+
if (value.isValid(part)) {
|
|
70
|
+
font[property] = value.parse(part);
|
|
71
|
+
}
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
default:
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (Object.hasOwn(font, "font-size")) {
|
|
80
|
+
font["line-height"] = lineHeightB;
|
|
81
|
+
} else {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
} else {
|
|
85
|
+
// FIXME: Switch to toReversed() when we can drop Node.js 18 support.
|
|
86
|
+
const revParts = [...parsers.splitValue(fontBlockA.trim())].reverse();
|
|
87
|
+
const revFontFamily = [];
|
|
88
|
+
const properties = ["font-style", "font-variant", "font-weight", "line-height"];
|
|
89
|
+
font["font-style"] = "normal";
|
|
90
|
+
font["font-variant"] = "normal";
|
|
91
|
+
font["font-weight"] = "normal";
|
|
92
|
+
font["line-height"] = "normal";
|
|
93
|
+
let fontSizeA;
|
|
94
|
+
for (const part of revParts) {
|
|
95
|
+
if (fontSizeA) {
|
|
96
|
+
if (part === "normal") {
|
|
97
|
+
continue;
|
|
98
|
+
} else {
|
|
99
|
+
for (const property of properties) {
|
|
100
|
+
switch (property) {
|
|
101
|
+
case "font-style":
|
|
102
|
+
case "font-variant":
|
|
103
|
+
case "font-weight":
|
|
104
|
+
case "line-height": {
|
|
105
|
+
const value = shorthandFor.get(property);
|
|
106
|
+
if (value.isValid(part)) {
|
|
107
|
+
font[property] = value.parse(part);
|
|
108
|
+
}
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
default:
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
} else if (fontSize.isValid(part)) {
|
|
116
|
+
fontSizeA = fontSize.parse(part);
|
|
117
|
+
} else if (fontFamily.isValid(part)) {
|
|
118
|
+
revFontFamily.push(part);
|
|
119
|
+
} else {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
const family = revFontFamily.reverse().join(" ");
|
|
124
|
+
if (fontSizeA && fontFamily.isValid(family)) {
|
|
125
|
+
font["font-size"] = fontSizeA;
|
|
126
|
+
fontFamilies.add(fontFamily.parse(family));
|
|
127
|
+
} else {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
for (const family of families) {
|
|
132
|
+
if (fontFamily.isValid(family)) {
|
|
133
|
+
fontFamilies.add(fontFamily.parse(family));
|
|
134
|
+
} else {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
font["font-family"] = [...fontFamilies].join(", ");
|
|
139
|
+
return font;
|
|
140
|
+
};
|
|
29
141
|
|
|
30
142
|
module.exports.definition = {
|
|
31
|
-
set
|
|
32
|
-
|
|
33
|
-
if (
|
|
34
|
-
|
|
143
|
+
set(v) {
|
|
144
|
+
v = parsers.prepareValue(v, this._global);
|
|
145
|
+
if (v === "" || parsers.hasVarFunc(v)) {
|
|
146
|
+
for (const [key] of shorthandFor) {
|
|
147
|
+
this._setProperty(key, "");
|
|
148
|
+
}
|
|
149
|
+
this._setProperty("font", v);
|
|
150
|
+
} else {
|
|
151
|
+
const obj = module.exports.parse(v);
|
|
152
|
+
if (!obj) {
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
const str = new Set();
|
|
156
|
+
for (const [key] of shorthandFor) {
|
|
157
|
+
const val = obj[key];
|
|
158
|
+
if (typeof val === "string") {
|
|
159
|
+
this._setProperty(key, val);
|
|
160
|
+
if (val && val !== "normal" && !str.has(val)) {
|
|
161
|
+
if (key === "line-height") {
|
|
162
|
+
str.add(`/ ${val}`);
|
|
163
|
+
} else {
|
|
164
|
+
str.add(val);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
this._setProperty("font", [...str].join(" "));
|
|
170
|
+
}
|
|
171
|
+
},
|
|
172
|
+
get() {
|
|
173
|
+
const val = this.getPropertyValue("font");
|
|
174
|
+
if (parsers.hasVarFunc(val)) {
|
|
175
|
+
return val;
|
|
35
176
|
}
|
|
36
|
-
|
|
37
|
-
|
|
177
|
+
const str = new Set();
|
|
178
|
+
for (const [key] of shorthandFor) {
|
|
179
|
+
const v = this.getPropertyValue(key);
|
|
180
|
+
if (parsers.hasVarFunc(v)) {
|
|
181
|
+
return "";
|
|
182
|
+
}
|
|
183
|
+
if (v && v !== "normal" && !str.has(v)) {
|
|
184
|
+
if (key === "line-height") {
|
|
185
|
+
str.add(`/ ${v}`);
|
|
186
|
+
} else {
|
|
187
|
+
str.add(`${v}`);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
38
190
|
}
|
|
191
|
+
return [...str].join(" ");
|
|
39
192
|
},
|
|
40
|
-
get: shorthandGetter('font', shorthand_for),
|
|
41
193
|
enumerable: true,
|
|
42
|
-
configurable: true
|
|
194
|
+
configurable: true
|
|
43
195
|
};
|
|
@@ -1,33 +1,85 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
var valueType = require('../parsers').valueType;
|
|
3
|
+
const parsers = require("../parsers");
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
return true;
|
|
5
|
+
module.exports.parse = function parse(v) {
|
|
6
|
+
if (v === "") {
|
|
7
|
+
return v;
|
|
10
8
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
9
|
+
const keywords = [
|
|
10
|
+
"serif",
|
|
11
|
+
"sans-serif",
|
|
12
|
+
"cursive",
|
|
13
|
+
"fantasy",
|
|
14
|
+
"monospace",
|
|
15
|
+
"system-ui",
|
|
16
|
+
"math",
|
|
17
|
+
"ui-serif",
|
|
18
|
+
"ui-sans-serif",
|
|
19
|
+
"ui-monospace",
|
|
20
|
+
"ui-rounded"
|
|
21
|
+
];
|
|
22
|
+
const val = parsers.splitValue(v, {
|
|
23
|
+
delimiter: ","
|
|
24
|
+
});
|
|
25
|
+
const font = [];
|
|
26
|
+
let valid = false;
|
|
27
|
+
for (const i of val) {
|
|
28
|
+
const str = parsers.parseString(i);
|
|
29
|
+
if (str) {
|
|
30
|
+
font.push(str);
|
|
31
|
+
valid = true;
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
const key = parsers.parseKeyword(i, keywords);
|
|
35
|
+
if (key) {
|
|
36
|
+
font.push(key);
|
|
37
|
+
valid = true;
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
// This implementation does not strictly follow the specification.
|
|
41
|
+
// The spec does not require the first letter of the font-family to be
|
|
42
|
+
// capitalized, and unquoted font-family names are not restricted to ASCII.
|
|
43
|
+
// However, in the real world, the first letter of the ASCII font-family
|
|
44
|
+
// names are capitalized, and unquoted font-family names do not contain
|
|
45
|
+
// spaces, e.g. `Times`. And non-ASCII font-family names are quoted even
|
|
46
|
+
// without spaces, e.g. `"メイリオ"`.
|
|
47
|
+
// @see https://drafts.csswg.org/css-fonts/#font-family-prop
|
|
48
|
+
if (
|
|
49
|
+
i !== "undefined" &&
|
|
50
|
+
/^(?:[A-Z][A-Za-z\d-]+(?:\s+[A-Z][A-Za-z\d-]+)*|-?[a-z][a-z-]+)$/.test(i)
|
|
51
|
+
) {
|
|
52
|
+
font.push(i.trim());
|
|
53
|
+
valid = true;
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
if (!valid) {
|
|
57
|
+
return;
|
|
19
58
|
}
|
|
20
59
|
}
|
|
21
|
-
return
|
|
60
|
+
return font.join(", ");
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
module.exports.isValid = function isValid(v) {
|
|
64
|
+
if (v === "") {
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
return typeof module.exports.parse(v) === "string";
|
|
22
68
|
};
|
|
23
69
|
|
|
24
70
|
module.exports.definition = {
|
|
25
|
-
set
|
|
26
|
-
|
|
71
|
+
set(v) {
|
|
72
|
+
v = parsers.prepareValue(v, this._global);
|
|
73
|
+
if (parsers.hasVarFunc(v)) {
|
|
74
|
+
this._setProperty("font", "");
|
|
75
|
+
this._setProperty("font-family", v);
|
|
76
|
+
} else {
|
|
77
|
+
this._setProperty("font-family", module.exports.parse(v));
|
|
78
|
+
}
|
|
27
79
|
},
|
|
28
|
-
get
|
|
29
|
-
return this.getPropertyValue(
|
|
80
|
+
get() {
|
|
81
|
+
return this.getPropertyValue("font-family");
|
|
30
82
|
},
|
|
31
83
|
enumerable: true,
|
|
32
|
-
configurable: true
|
|
84
|
+
configurable: true
|
|
33
85
|
};
|