cssstyle 4.3.0 → 4.4.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 +2574 -0
- package/lib/parsers.js +400 -544
- 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 +120 -33
- package/lib/properties/fontFamily.js +59 -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,130 @@
|
|
|
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
|
+
let blockA, blockB;
|
|
30
|
+
if (fontBlock.includes("/")) {
|
|
31
|
+
[blockA, blockB] = parsers.splitValue(fontBlock, {
|
|
32
|
+
delimiter: "/"
|
|
33
|
+
});
|
|
34
|
+
} else {
|
|
35
|
+
blockA = fontBlock.trim();
|
|
36
|
+
}
|
|
37
|
+
const obj = parsers.parseShorthand(blockA, shorthandFor, true);
|
|
38
|
+
if (!obj) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const font = {};
|
|
42
|
+
const fontFamilies = new Set();
|
|
43
|
+
for (const [property, value] of Object.entries(obj)) {
|
|
44
|
+
if (property === "font-family") {
|
|
45
|
+
if (!blockB) {
|
|
46
|
+
fontFamilies.add(value);
|
|
47
|
+
}
|
|
48
|
+
} else {
|
|
49
|
+
font[property] = value;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
// blockB, if matched, includes line-height and first font-family
|
|
53
|
+
if (blockB) {
|
|
54
|
+
const [lineheight, family] = parsers.splitValue(blockB);
|
|
55
|
+
if (lineHeight.isValid(lineheight)) {
|
|
56
|
+
font["line-height"] = lineHeight.parse(lineheight);
|
|
57
|
+
} else {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
if (fontFamily.isValid(family)) {
|
|
61
|
+
fontFamilies.add(fontFamily.parse(family));
|
|
62
|
+
} else {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
for (const family of families) {
|
|
67
|
+
if (fontFamily.isValid(family)) {
|
|
68
|
+
fontFamilies.add(fontFamily.parse(family));
|
|
69
|
+
} else {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
font["font-family"] = [...fontFamilies].join(", ");
|
|
74
|
+
return font;
|
|
75
|
+
};
|
|
29
76
|
|
|
30
77
|
module.exports.definition = {
|
|
31
|
-
set
|
|
32
|
-
|
|
33
|
-
if (
|
|
34
|
-
|
|
78
|
+
set(v) {
|
|
79
|
+
v = parsers.prepareValue(v, this._global);
|
|
80
|
+
if (parsers.hasVarFunc(v)) {
|
|
81
|
+
for (const [key] of shorthandFor) {
|
|
82
|
+
this._setProperty(key, "");
|
|
83
|
+
}
|
|
84
|
+
this._setProperty("font", v);
|
|
85
|
+
} else {
|
|
86
|
+
const obj = module.exports.parse(v);
|
|
87
|
+
if (!obj) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const str = new Set();
|
|
91
|
+
for (const [key] of shorthandFor) {
|
|
92
|
+
const val = obj[key];
|
|
93
|
+
if (typeof val === "string") {
|
|
94
|
+
this._setProperty(key, val);
|
|
95
|
+
if (val && !str.has(val)) {
|
|
96
|
+
if (key === "line-height") {
|
|
97
|
+
str.add(`/ ${val}`);
|
|
98
|
+
} else {
|
|
99
|
+
str.add(val);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
this._setProperty("font", [...str].join(" "));
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
get() {
|
|
108
|
+
const val = this.getPropertyValue("font");
|
|
109
|
+
if (parsers.hasVarFunc(val)) {
|
|
110
|
+
return val;
|
|
35
111
|
}
|
|
36
|
-
|
|
37
|
-
|
|
112
|
+
const str = new Set();
|
|
113
|
+
for (const [key] of shorthandFor) {
|
|
114
|
+
const v = this.getPropertyValue(key);
|
|
115
|
+
if (parsers.hasVarFunc(v)) {
|
|
116
|
+
return "";
|
|
117
|
+
}
|
|
118
|
+
if (v && !str.has(v)) {
|
|
119
|
+
if (key === "line-height") {
|
|
120
|
+
str.add(`/ ${v}`);
|
|
121
|
+
} else {
|
|
122
|
+
str.add(`${v}`);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
38
125
|
}
|
|
126
|
+
return [...str].join(" ");
|
|
39
127
|
},
|
|
40
|
-
get: shorthandGetter('font', shorthand_for),
|
|
41
128
|
enumerable: true,
|
|
42
|
-
configurable: true
|
|
129
|
+
configurable: true
|
|
43
130
|
};
|
|
@@ -1,33 +1,71 @@
|
|
|
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 = ["serif", "sans-serif", "system-ui", "cursive", "fantasy", "monospace"];
|
|
10
|
+
const val = parsers.splitValue(v, {
|
|
11
|
+
delimiter: ","
|
|
12
|
+
});
|
|
13
|
+
const font = [];
|
|
14
|
+
let valid = false;
|
|
15
|
+
for (const i of val) {
|
|
16
|
+
const str = parsers.parseString(i);
|
|
17
|
+
if (str) {
|
|
18
|
+
font.push(str);
|
|
19
|
+
valid = true;
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
const key = parsers.parseKeyword(i, keywords);
|
|
23
|
+
if (key) {
|
|
24
|
+
font.push(key);
|
|
25
|
+
valid = true;
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
// This implementation does not strictly follow the specification. The spec
|
|
29
|
+
// does not require the first letter of the font-family to be capitalized.
|
|
30
|
+
// Also, unquoted font-family names are not restricted to ASCII only.
|
|
31
|
+
// However, in the real world, the first letter of the ASCII font-family
|
|
32
|
+
// names are always capitalized, and unquoted font-family names do not
|
|
33
|
+
// contain spaces, e.g. `Times`, and AFAIK, non-ASCII font-family names are
|
|
34
|
+
// always quoted even without spaces, e.g. `"メイリオ"`.
|
|
35
|
+
// Therefore, it is unlikely that this implementation will cause problems.
|
|
36
|
+
// @see https://drafts.csswg.org/css-fonts/#font-family-prop
|
|
37
|
+
if (/^\s*(?:[A-Z][A-Za-z\d\s-]+)\s*$/.test(i)) {
|
|
38
|
+
font.push(i.trim());
|
|
39
|
+
valid = true;
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
if (!valid) {
|
|
43
|
+
return;
|
|
19
44
|
}
|
|
20
45
|
}
|
|
21
|
-
return
|
|
46
|
+
return font.join(", ");
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
module.exports.isValid = function isValid(v) {
|
|
50
|
+
if (v === "") {
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
return typeof module.exports.parse(v) === "string";
|
|
22
54
|
};
|
|
23
55
|
|
|
24
56
|
module.exports.definition = {
|
|
25
|
-
set
|
|
26
|
-
|
|
57
|
+
set(v) {
|
|
58
|
+
v = parsers.prepareValue(v, this._global);
|
|
59
|
+
if (parsers.hasVarFunc(v)) {
|
|
60
|
+
this._setProperty("font", "");
|
|
61
|
+
this._setProperty("font-family", v);
|
|
62
|
+
} else {
|
|
63
|
+
this._setProperty("font-family", module.exports.parse(v));
|
|
64
|
+
}
|
|
27
65
|
},
|
|
28
|
-
get
|
|
29
|
-
return this.getPropertyValue(
|
|
66
|
+
get() {
|
|
67
|
+
return this.getPropertyValue("font-family");
|
|
30
68
|
},
|
|
31
69
|
enumerable: true,
|
|
32
|
-
configurable: true
|
|
70
|
+
configurable: true
|
|
33
71
|
};
|
|
@@ -1,38 +1,47 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
var valueType = require('../parsers').valueType;
|
|
5
|
-
var parseMeasurement = require('../parsers').parseMeasurement;
|
|
3
|
+
const parsers = require("../parsers");
|
|
6
4
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
5
|
+
module.exports.parse = function parse(v) {
|
|
6
|
+
const val = parsers.parseMeasurement(v, true);
|
|
7
|
+
if (val) {
|
|
8
|
+
return val;
|
|
9
|
+
}
|
|
10
|
+
const keywords = [
|
|
11
|
+
"xx-small",
|
|
12
|
+
"x-small",
|
|
13
|
+
"small",
|
|
14
|
+
"medium",
|
|
15
|
+
"large",
|
|
16
|
+
"x-large",
|
|
17
|
+
"xx-large",
|
|
18
|
+
"xxx-large",
|
|
19
|
+
"smaller",
|
|
20
|
+
"larger"
|
|
21
|
+
];
|
|
22
|
+
return parsers.parseKeyword(v, keywords);
|
|
18
23
|
};
|
|
19
24
|
|
|
20
|
-
function
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return isOptionalArgument ? valueAsString : parseMeasurement(v);
|
|
27
|
-
}
|
|
25
|
+
module.exports.isValid = function isValid(v) {
|
|
26
|
+
if (v === "") {
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
return typeof module.exports.parse(v) === "string";
|
|
30
|
+
};
|
|
28
31
|
|
|
29
32
|
module.exports.definition = {
|
|
30
|
-
set
|
|
31
|
-
|
|
33
|
+
set(v) {
|
|
34
|
+
v = parsers.prepareValue(v, this._global);
|
|
35
|
+
if (parsers.hasVarFunc(v)) {
|
|
36
|
+
this._setProperty("font", "");
|
|
37
|
+
this._setProperty("font-size", v);
|
|
38
|
+
} else {
|
|
39
|
+
this._setProperty("font-size", module.exports.parse(v));
|
|
40
|
+
}
|
|
32
41
|
},
|
|
33
|
-
get
|
|
34
|
-
return this.getPropertyValue(
|
|
42
|
+
get() {
|
|
43
|
+
return this.getPropertyValue("font-size");
|
|
35
44
|
},
|
|
36
45
|
enumerable: true,
|
|
37
|
-
configurable: true
|
|
46
|
+
configurable: true
|
|
38
47
|
};
|