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,215 +2,205 @@
|
|
|
2
2
|
|
|
3
3
|
const parsers = require("../parsers");
|
|
4
4
|
|
|
5
|
+
const property = "display";
|
|
6
|
+
|
|
5
7
|
/* keywords */
|
|
6
8
|
const displayOutside = ["block", "inline", "run-in"];
|
|
7
9
|
const displayFlow = ["flow", "flow-root"];
|
|
8
|
-
const displayInside = ["table", "flex", "grid", "ruby", ...displayFlow];
|
|
9
|
-
const displayListItem = ["list-item"];
|
|
10
|
-
const displayInternal = [
|
|
11
|
-
"table-row-group",
|
|
12
|
-
"table-header-group",
|
|
13
|
-
"table-footer-group",
|
|
14
|
-
"table-row",
|
|
15
|
-
"table-cell",
|
|
16
|
-
"table-column-group",
|
|
17
|
-
"table-column",
|
|
18
|
-
"table-caption",
|
|
19
|
-
"ruby-base",
|
|
20
|
-
"ruby-text",
|
|
21
|
-
"ruby-base-container",
|
|
22
|
-
"ruby-text-container"
|
|
23
|
-
];
|
|
24
|
-
const displayBox = ["contents", "none"];
|
|
25
|
-
const displayLegacy = ["inline-block", "inline-table", "inline-flex", "inline-grid"];
|
|
26
|
-
const keywords = [
|
|
27
|
-
...displayOutside,
|
|
28
|
-
...displayInside,
|
|
29
|
-
...displayListItem,
|
|
30
|
-
...displayInternal,
|
|
31
|
-
...displayBox,
|
|
32
|
-
...displayLegacy
|
|
33
|
-
];
|
|
34
10
|
|
|
35
|
-
module.exports.parse = function parse(v) {
|
|
11
|
+
module.exports.parse = function parse(v, opt = {}) {
|
|
12
|
+
const { globalObject } = opt;
|
|
36
13
|
if (v === "") {
|
|
37
14
|
return v;
|
|
38
15
|
}
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
break;
|
|
51
|
-
}
|
|
52
|
-
case 2: {
|
|
53
|
-
let [v1, v2] = values;
|
|
54
|
-
v1 = parsers.parseKeyword(v1, keywords);
|
|
55
|
-
v2 = parsers.parseKeyword(v2, keywords);
|
|
56
|
-
if (!v1 || !v2) {
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
let outerValue = "";
|
|
60
|
-
let innerValue = "";
|
|
61
|
-
if (v1 === "list-item") {
|
|
62
|
-
outerValue = v2;
|
|
63
|
-
innerValue = v1;
|
|
64
|
-
} else if (v2 === "list-item") {
|
|
65
|
-
outerValue = v1;
|
|
66
|
-
innerValue = v2;
|
|
67
|
-
} else if (displayOutside.includes(v1)) {
|
|
68
|
-
outerValue = v1;
|
|
69
|
-
innerValue = v2;
|
|
70
|
-
} else if (displayOutside.includes(v2)) {
|
|
71
|
-
outerValue = v2;
|
|
72
|
-
innerValue = v1;
|
|
73
|
-
}
|
|
74
|
-
if (innerValue === "list-item") {
|
|
75
|
-
switch (outerValue) {
|
|
76
|
-
case "block":
|
|
77
|
-
case "flow": {
|
|
78
|
-
return innerValue;
|
|
79
|
-
}
|
|
80
|
-
case "flow-root":
|
|
81
|
-
case "inline":
|
|
82
|
-
case "run-in": {
|
|
83
|
-
return `${outerValue} ${innerValue}`;
|
|
84
|
-
}
|
|
85
|
-
default:
|
|
86
|
-
}
|
|
87
|
-
} else if (outerValue === "block") {
|
|
88
|
-
switch (innerValue) {
|
|
89
|
-
case "flow": {
|
|
90
|
-
return outerValue;
|
|
16
|
+
const value = parsers.parsePropertyValue(property, v, {
|
|
17
|
+
globalObject,
|
|
18
|
+
inArray: true
|
|
19
|
+
});
|
|
20
|
+
if (Array.isArray(value) && value.length) {
|
|
21
|
+
switch (value.length) {
|
|
22
|
+
case 1: {
|
|
23
|
+
const [{ name, type }] = value;
|
|
24
|
+
switch (type) {
|
|
25
|
+
case "GlobalKeyword": {
|
|
26
|
+
return name;
|
|
91
27
|
}
|
|
92
|
-
case "
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
return
|
|
97
|
-
}
|
|
98
|
-
case "ruby": {
|
|
99
|
-
return `${outerValue} ${innerValue}`;
|
|
100
|
-
}
|
|
101
|
-
default:
|
|
102
|
-
}
|
|
103
|
-
} else if (outerValue === "inline") {
|
|
104
|
-
switch (innerValue) {
|
|
105
|
-
case "flow": {
|
|
106
|
-
return outerValue;
|
|
107
|
-
}
|
|
108
|
-
case "flow-root": {
|
|
109
|
-
return `${outerValue}-block`;
|
|
110
|
-
}
|
|
111
|
-
case "flex":
|
|
112
|
-
case "grid":
|
|
113
|
-
case "table": {
|
|
114
|
-
return `${outerValue}-${innerValue}`;
|
|
115
|
-
}
|
|
116
|
-
case "ruby": {
|
|
117
|
-
return innerValue;
|
|
28
|
+
case "Identifier": {
|
|
29
|
+
if (name === "flow") {
|
|
30
|
+
return "block";
|
|
31
|
+
}
|
|
32
|
+
return name;
|
|
118
33
|
}
|
|
119
34
|
default:
|
|
120
35
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
case 2: {
|
|
39
|
+
const [part1, part2] = value;
|
|
40
|
+
const val1 = part1.type === "Identifier" && part1.name;
|
|
41
|
+
const val2 = part2.type === "Identifier" && part2.name;
|
|
42
|
+
if (val1 && val2) {
|
|
43
|
+
let outerValue = "";
|
|
44
|
+
let innerValue = "";
|
|
45
|
+
if (val1 === "list-item") {
|
|
46
|
+
outerValue = val2;
|
|
47
|
+
innerValue = val1;
|
|
48
|
+
} else if (val2 === "list-item") {
|
|
49
|
+
outerValue = val1;
|
|
50
|
+
innerValue = val2;
|
|
51
|
+
} else if (displayOutside.includes(val1)) {
|
|
52
|
+
outerValue = val1;
|
|
53
|
+
innerValue = val2;
|
|
54
|
+
} else if (displayOutside.includes(val2)) {
|
|
55
|
+
outerValue = val2;
|
|
56
|
+
innerValue = val1;
|
|
125
57
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
58
|
+
if (innerValue === "list-item") {
|
|
59
|
+
switch (outerValue) {
|
|
60
|
+
case "block":
|
|
61
|
+
case "flow": {
|
|
62
|
+
return innerValue;
|
|
63
|
+
}
|
|
64
|
+
case "flow-root":
|
|
65
|
+
case "inline":
|
|
66
|
+
case "run-in": {
|
|
67
|
+
return `${outerValue} ${innerValue}`;
|
|
68
|
+
}
|
|
69
|
+
default:
|
|
70
|
+
}
|
|
71
|
+
} else if (outerValue === "block") {
|
|
72
|
+
switch (innerValue) {
|
|
73
|
+
case "flow": {
|
|
74
|
+
return outerValue;
|
|
75
|
+
}
|
|
76
|
+
case "flow-root":
|
|
77
|
+
case "flex":
|
|
78
|
+
case "grid":
|
|
79
|
+
case "table": {
|
|
80
|
+
return innerValue;
|
|
81
|
+
}
|
|
82
|
+
case "ruby": {
|
|
83
|
+
return `${outerValue} ${innerValue}`;
|
|
84
|
+
}
|
|
85
|
+
default:
|
|
86
|
+
}
|
|
87
|
+
} else if (outerValue === "inline") {
|
|
88
|
+
switch (innerValue) {
|
|
89
|
+
case "flow": {
|
|
90
|
+
return outerValue;
|
|
91
|
+
}
|
|
92
|
+
case "flow-root": {
|
|
93
|
+
return `${outerValue}-block`;
|
|
94
|
+
}
|
|
95
|
+
case "flex":
|
|
96
|
+
case "grid":
|
|
97
|
+
case "table": {
|
|
98
|
+
return `${outerValue}-${innerValue}`;
|
|
99
|
+
}
|
|
100
|
+
case "ruby": {
|
|
101
|
+
return innerValue;
|
|
102
|
+
}
|
|
103
|
+
default:
|
|
104
|
+
}
|
|
105
|
+
} else if (outerValue === "run-in") {
|
|
106
|
+
switch (innerValue) {
|
|
107
|
+
case "flow": {
|
|
108
|
+
return outerValue;
|
|
109
|
+
}
|
|
110
|
+
case "flow-root":
|
|
111
|
+
case "flex":
|
|
112
|
+
case "grid":
|
|
113
|
+
case "table":
|
|
114
|
+
case "ruby": {
|
|
115
|
+
return `${outerValue} ${innerValue}`;
|
|
116
|
+
}
|
|
117
|
+
default:
|
|
118
|
+
}
|
|
132
119
|
}
|
|
133
|
-
default:
|
|
134
120
|
}
|
|
121
|
+
break;
|
|
135
122
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
outerValue = v2;
|
|
172
|
-
} else if (displayFlow.includes(v2)) {
|
|
173
|
-
flowValue = v2;
|
|
174
|
-
outerValue = v1;
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
if (outerValue && flowValue && listItemValue) {
|
|
178
|
-
switch (outerValue) {
|
|
179
|
-
case "block": {
|
|
180
|
-
if (flowValue === "flow") {
|
|
181
|
-
return listItemValue;
|
|
123
|
+
case 3: {
|
|
124
|
+
const [part1, part2, part3] = value;
|
|
125
|
+
const val1 = part1.type === "Identifier" && part1.name;
|
|
126
|
+
const val2 = part2.type === "Identifier" && part2.name;
|
|
127
|
+
const val3 = part3.type === "Identifier" && part3.name;
|
|
128
|
+
if (val1 && val2 && part3) {
|
|
129
|
+
let outerValue = "";
|
|
130
|
+
let flowValue = "";
|
|
131
|
+
let listItemValue = "";
|
|
132
|
+
if (val1 === "list-item") {
|
|
133
|
+
listItemValue = val1;
|
|
134
|
+
if (displayFlow.includes(val2)) {
|
|
135
|
+
flowValue = val2;
|
|
136
|
+
outerValue = val3;
|
|
137
|
+
} else if (displayFlow.includes(val3)) {
|
|
138
|
+
flowValue = val3;
|
|
139
|
+
outerValue = val2;
|
|
140
|
+
}
|
|
141
|
+
} else if (val2 === "list-item") {
|
|
142
|
+
listItemValue = val2;
|
|
143
|
+
if (displayFlow.includes(val1)) {
|
|
144
|
+
flowValue = val1;
|
|
145
|
+
outerValue = val3;
|
|
146
|
+
} else if (displayFlow.includes(val3)) {
|
|
147
|
+
flowValue = val3;
|
|
148
|
+
outerValue = val1;
|
|
149
|
+
}
|
|
150
|
+
} else if (val3 === "list-item") {
|
|
151
|
+
listItemValue = val3;
|
|
152
|
+
if (displayFlow.includes(val1)) {
|
|
153
|
+
flowValue = val1;
|
|
154
|
+
outerValue = val2;
|
|
155
|
+
} else if (displayFlow.includes(val2)) {
|
|
156
|
+
flowValue = val2;
|
|
157
|
+
outerValue = val1;
|
|
182
158
|
}
|
|
183
|
-
return `${flowValue} ${listItemValue}`;
|
|
184
159
|
}
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
160
|
+
if (outerValue && flowValue && listItemValue) {
|
|
161
|
+
switch (outerValue) {
|
|
162
|
+
case "block": {
|
|
163
|
+
if (flowValue === "flow") {
|
|
164
|
+
return listItemValue;
|
|
165
|
+
}
|
|
166
|
+
return `${flowValue} ${listItemValue}`;
|
|
167
|
+
}
|
|
168
|
+
case "inline":
|
|
169
|
+
case "run-in": {
|
|
170
|
+
if (flowValue === "flow") {
|
|
171
|
+
return `${outerValue} ${listItemValue}`;
|
|
172
|
+
}
|
|
173
|
+
return `${outerValue} ${flowValue} ${listItemValue}`;
|
|
174
|
+
}
|
|
189
175
|
}
|
|
190
|
-
return `${outerValue} ${flowValue} ${listItemValue}`;
|
|
191
176
|
}
|
|
192
177
|
}
|
|
178
|
+
break;
|
|
193
179
|
}
|
|
194
|
-
|
|
180
|
+
default:
|
|
195
181
|
}
|
|
196
|
-
|
|
182
|
+
} else if (typeof value === "string") {
|
|
183
|
+
return value;
|
|
197
184
|
}
|
|
198
185
|
};
|
|
199
186
|
|
|
200
|
-
module.exports.isValid = function isValid(v) {
|
|
201
|
-
if (v === "") {
|
|
202
|
-
return true;
|
|
203
|
-
}
|
|
204
|
-
return typeof module.exports.parse(v) === "string";
|
|
205
|
-
};
|
|
206
|
-
|
|
207
187
|
module.exports.definition = {
|
|
208
188
|
set(v) {
|
|
209
189
|
v = parsers.prepareValue(v, this._global);
|
|
210
|
-
|
|
190
|
+
if (parsers.hasVarFunc(v)) {
|
|
191
|
+
this._setProperty(property, v);
|
|
192
|
+
} else {
|
|
193
|
+
const val = module.exports.parse(v, {
|
|
194
|
+
globalObject: this._global
|
|
195
|
+
});
|
|
196
|
+
if (typeof val === "string") {
|
|
197
|
+
const priority = this._priorities.get(property) ?? "";
|
|
198
|
+
this._setProperty(property, val, priority);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
211
201
|
},
|
|
212
202
|
get() {
|
|
213
|
-
return this.getPropertyValue(
|
|
203
|
+
return this.getPropertyValue(property);
|
|
214
204
|
},
|
|
215
205
|
enumerable: true,
|
|
216
206
|
configurable: true
|
package/lib/properties/flex.js
CHANGED
|
@@ -5,68 +5,167 @@ const flexGrow = require("./flexGrow");
|
|
|
5
5
|
const flexShrink = require("./flexShrink");
|
|
6
6
|
const flexBasis = require("./flexBasis");
|
|
7
7
|
|
|
8
|
+
const property = "flex";
|
|
9
|
+
|
|
10
|
+
module.exports.initialValues = new Map([
|
|
11
|
+
["flex-grow", "0"],
|
|
12
|
+
["flex-shrink", "1"],
|
|
13
|
+
["flex-basis", "auto"]
|
|
14
|
+
]);
|
|
15
|
+
|
|
8
16
|
module.exports.shorthandFor = new Map([
|
|
9
17
|
["flex-grow", flexGrow],
|
|
10
18
|
["flex-shrink", flexShrink],
|
|
11
19
|
["flex-basis", flexBasis]
|
|
12
20
|
]);
|
|
13
21
|
|
|
14
|
-
module.exports.parse = function parse(v) {
|
|
15
|
-
const
|
|
16
|
-
if (
|
|
17
|
-
|
|
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;
|
|
22
|
+
module.exports.parse = function parse(v, opt = {}) {
|
|
23
|
+
const { globalObject } = opt;
|
|
24
|
+
if (v === "") {
|
|
25
|
+
return v;
|
|
27
26
|
}
|
|
28
|
-
const
|
|
29
|
-
|
|
27
|
+
const value = parsers.parsePropertyValue(property, v, {
|
|
28
|
+
globalObject,
|
|
29
|
+
inArray: true
|
|
30
|
+
});
|
|
31
|
+
if (Array.isArray(value) && value.length) {
|
|
30
32
|
const flex = {
|
|
31
33
|
"flex-grow": "1",
|
|
32
34
|
"flex-shrink": "1",
|
|
33
35
|
"flex-basis": "0%"
|
|
34
36
|
};
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
37
|
+
if (value.length === 1) {
|
|
38
|
+
const [{ isNumber, name, type, unit, value: itemValue }] = value;
|
|
39
|
+
switch (type) {
|
|
40
|
+
case "Calc": {
|
|
41
|
+
if (isNumber) {
|
|
42
|
+
flex["flex-grow"] = `${name}(${itemValue})`;
|
|
43
|
+
return flex;
|
|
44
|
+
}
|
|
45
|
+
flex["flex-basis"] = `${name}(${itemValue})`;
|
|
46
|
+
return flex;
|
|
47
|
+
}
|
|
48
|
+
case "Dimension": {
|
|
49
|
+
flex["flex-basis"] = `${itemValue}${unit}`;
|
|
50
|
+
return flex;
|
|
51
|
+
}
|
|
52
|
+
case "GlobalKeyword": {
|
|
53
|
+
return name;
|
|
54
|
+
}
|
|
55
|
+
case "Identifier": {
|
|
56
|
+
if (name === "auto") {
|
|
57
|
+
flex["flex-basis"] = name;
|
|
58
|
+
return flex;
|
|
59
|
+
} else if (name === "none") {
|
|
60
|
+
return {
|
|
61
|
+
"flex-grow": "0",
|
|
62
|
+
"flex-shrink": "0",
|
|
63
|
+
"flex-basis": "auto"
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
case "Number": {
|
|
69
|
+
flex["flex-grow"] = itemValue;
|
|
70
|
+
return flex;
|
|
71
|
+
}
|
|
72
|
+
case "Percentage": {
|
|
73
|
+
flex["flex-basis"] = `${itemValue}%`;
|
|
74
|
+
return flex;
|
|
75
|
+
}
|
|
76
|
+
default:
|
|
77
|
+
}
|
|
78
|
+
} else {
|
|
79
|
+
const [val1, val2, val3] = value;
|
|
80
|
+
if (val1.type === "Calc" && val1.isNumber) {
|
|
81
|
+
flex["flex-grow"] = `${val1.name}(${val1.value})`;
|
|
82
|
+
} else if (val1.type === "Number") {
|
|
83
|
+
flex["flex-grow"] = val1.value;
|
|
84
|
+
} else {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
if (val3) {
|
|
88
|
+
if (val2.type === "Calc" && val2.isNumber) {
|
|
89
|
+
flex["flex-shrink"] = `${val2.name}(${val2.value})`;
|
|
90
|
+
} else if (val2.type === "Number") {
|
|
91
|
+
flex["flex-shrink"] = val2.value;
|
|
92
|
+
} else {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
if (val3.type === "Calc" && !val3.isNumber) {
|
|
96
|
+
flex["flex-basis"] = `${val3.name}(${val3.value})`;
|
|
97
|
+
} else if (val3.type === "Dimension") {
|
|
98
|
+
flex["flex-basis"] = `${val3.value}${val3.unit}`;
|
|
99
|
+
} else if (val3.type === "Percentage") {
|
|
100
|
+
flex["flex-basis"] = `${val3.value}%`;
|
|
101
|
+
} else {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
} else {
|
|
105
|
+
switch (val2.type) {
|
|
106
|
+
case "Calc": {
|
|
107
|
+
if (val2.isNumber) {
|
|
108
|
+
flex["flex-shrink"] = `${val2.name}(${val2.value})`;
|
|
109
|
+
} else {
|
|
110
|
+
flex["flex-basis"] = `${val2.name}(${val2.value})`;
|
|
111
|
+
}
|
|
112
|
+
break;
|
|
113
|
+
}
|
|
114
|
+
case "Dimension": {
|
|
115
|
+
flex["flex-basis"] = `${val2.value}${val2.unit}`;
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
case "Number": {
|
|
119
|
+
flex["flex-shrink"] = val2.value;
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
case "Percentage": {
|
|
123
|
+
flex["flex-basis"] = `${val2.value}%`;
|
|
124
|
+
break;
|
|
125
|
+
}
|
|
126
|
+
default: {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return flex;
|
|
132
|
+
// return [...Object.values(flex)].join(" ");
|
|
38
133
|
}
|
|
39
|
-
|
|
134
|
+
} else if (typeof value === "string") {
|
|
135
|
+
return value;
|
|
40
136
|
}
|
|
41
137
|
};
|
|
42
138
|
|
|
43
|
-
module.exports.isValid = function isValid(v) {
|
|
44
|
-
if (v === "") {
|
|
45
|
-
return true;
|
|
46
|
-
}
|
|
47
|
-
return typeof module.exports.parse(v) === "string";
|
|
48
|
-
};
|
|
49
|
-
|
|
50
139
|
module.exports.definition = {
|
|
51
140
|
set(v) {
|
|
52
141
|
v = parsers.prepareValue(v, this._global);
|
|
53
142
|
if (parsers.hasVarFunc(v)) {
|
|
54
|
-
|
|
55
|
-
|
|
143
|
+
for (const [longhand] of module.exports.shorthandFor) {
|
|
144
|
+
this._setProperty(longhand, "");
|
|
145
|
+
}
|
|
146
|
+
this._setProperty(property, v);
|
|
56
147
|
} else {
|
|
57
|
-
|
|
148
|
+
const val = module.exports.parse(v, {
|
|
149
|
+
globalObject: this._global
|
|
150
|
+
});
|
|
151
|
+
const priority = this._priorities.get(property) ?? "";
|
|
152
|
+
if (typeof val === "string") {
|
|
153
|
+
for (const [longhand] of module.exports.shorthandFor) {
|
|
154
|
+
this._setProperty(longhand, val, priority);
|
|
155
|
+
}
|
|
156
|
+
this._setProperty(property, val, priority);
|
|
157
|
+
} else if (val) {
|
|
158
|
+
const values = [];
|
|
159
|
+
for (const [longhand, value] of Object.entries(val)) {
|
|
160
|
+
values.push(value);
|
|
161
|
+
this._setProperty(longhand, value, priority);
|
|
162
|
+
}
|
|
163
|
+
this._setProperty(property, values.join(" "), priority);
|
|
164
|
+
}
|
|
58
165
|
}
|
|
59
166
|
},
|
|
60
167
|
get() {
|
|
61
|
-
|
|
62
|
-
if (parsers.hasVarFunc(val)) {
|
|
63
|
-
return val;
|
|
64
|
-
}
|
|
65
|
-
val = this._shorthandGetter("flex", module.exports.shorthandFor);
|
|
66
|
-
if (parsers.hasVarFunc(val)) {
|
|
67
|
-
return "";
|
|
68
|
-
}
|
|
69
|
-
return val;
|
|
168
|
+
return this.getPropertyValue(property);
|
|
70
169
|
},
|
|
71
170
|
enumerable: true,
|
|
72
171
|
configurable: true
|
|
@@ -2,31 +2,60 @@
|
|
|
2
2
|
|
|
3
3
|
const parsers = require("../parsers");
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
if (val) {
|
|
8
|
-
return val;
|
|
9
|
-
}
|
|
10
|
-
const keywords = ["content", "auto", "min-content", "max-content"];
|
|
11
|
-
return parsers.parseKeyword(v, keywords);
|
|
12
|
-
};
|
|
5
|
+
const property = "flex-basis";
|
|
6
|
+
const shorthand = "flex";
|
|
13
7
|
|
|
14
|
-
module.exports.
|
|
15
|
-
|
|
8
|
+
module.exports.parse = function parse(v, opt = {}) {
|
|
9
|
+
const { globalObject } = opt;
|
|
10
|
+
if (v === "") {
|
|
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 [{ isNumber, name, type, value: itemValue }] = value;
|
|
19
|
+
switch (type) {
|
|
20
|
+
case "Calc": {
|
|
21
|
+
if (isNumber) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
return `${name}(${itemValue})`;
|
|
25
|
+
}
|
|
26
|
+
case "GlobalKeyword":
|
|
27
|
+
case "Identifier": {
|
|
28
|
+
return name;
|
|
29
|
+
}
|
|
30
|
+
default: {
|
|
31
|
+
return parsers.parseLengthPercentage(value);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
} else if (typeof value === "string") {
|
|
35
|
+
return value;
|
|
36
|
+
}
|
|
16
37
|
};
|
|
17
38
|
|
|
18
39
|
module.exports.definition = {
|
|
19
40
|
set(v) {
|
|
20
41
|
v = parsers.prepareValue(v, this._global);
|
|
21
42
|
if (parsers.hasVarFunc(v)) {
|
|
22
|
-
this._setProperty(
|
|
23
|
-
this._setProperty(
|
|
43
|
+
this._setProperty(shorthand, "");
|
|
44
|
+
this._setProperty(property, v);
|
|
24
45
|
} else {
|
|
25
|
-
|
|
46
|
+
const val = module.exports.parse(v, {
|
|
47
|
+
globalObject: this._global
|
|
48
|
+
});
|
|
49
|
+
if (typeof val === "string") {
|
|
50
|
+
const shorthandPriority = this._priorities.get(shorthand);
|
|
51
|
+
const prior = this._priorities.get(property) ?? "";
|
|
52
|
+
const priority = shorthandPriority && prior ? "" : prior;
|
|
53
|
+
this._flexBoxSetter(property, val, priority, shorthand);
|
|
54
|
+
}
|
|
26
55
|
}
|
|
27
56
|
},
|
|
28
57
|
get() {
|
|
29
|
-
return this.getPropertyValue(
|
|
58
|
+
return this.getPropertyValue(property);
|
|
30
59
|
},
|
|
31
60
|
enumerable: true,
|
|
32
61
|
configurable: true
|