cssstyle 5.3.6 → 5.3.7
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 +4 -3
- package/lib/generated/implementedProperties.js +1 -1
- package/lib/generated/properties.js +78 -79
- package/lib/generated/propertyDefinitions.js +1 -1
- package/lib/normalize.js +60 -67
- package/lib/parsers.js +7 -31
- package/lib/properties/background.js +1 -1
- package/lib/properties/backgroundAttachment.js +1 -1
- package/lib/properties/backgroundClip.js +1 -1
- package/lib/properties/backgroundColor.js +1 -1
- package/lib/properties/backgroundImage.js +1 -1
- package/lib/properties/backgroundOrigin.js +1 -1
- package/lib/properties/backgroundPosition.js +1 -1
- package/lib/properties/backgroundRepeat.js +1 -1
- package/lib/properties/backgroundSize.js +1 -1
- package/lib/properties/border.js +1 -1
- package/lib/properties/borderBottom.js +1 -1
- package/lib/properties/borderBottomColor.js +1 -1
- package/lib/properties/borderBottomStyle.js +1 -1
- package/lib/properties/borderBottomWidth.js +1 -1
- package/lib/properties/borderCollapse.js +1 -1
- package/lib/properties/borderColor.js +1 -1
- package/lib/properties/borderLeft.js +1 -1
- package/lib/properties/borderLeftColor.js +1 -1
- package/lib/properties/borderLeftStyle.js +1 -1
- package/lib/properties/borderLeftWidth.js +1 -1
- package/lib/properties/borderRight.js +1 -1
- package/lib/properties/borderRightColor.js +1 -1
- package/lib/properties/borderRightStyle.js +1 -1
- package/lib/properties/borderRightWidth.js +1 -1
- package/lib/properties/borderSpacing.js +1 -1
- package/lib/properties/borderStyle.js +1 -1
- package/lib/properties/borderTop.js +1 -1
- package/lib/properties/borderTopColor.js +1 -1
- package/lib/properties/borderTopStyle.js +1 -1
- package/lib/properties/borderTopWidth.js +1 -1
- package/lib/properties/borderWidth.js +1 -1
- package/lib/properties/bottom.js +1 -1
- package/lib/properties/clear.js +1 -1
- package/lib/properties/clip.js +1 -1
- package/lib/properties/color.js +1 -1
- package/lib/properties/display.js +1 -1
- package/lib/properties/flex.js +1 -1
- package/lib/properties/flexBasis.js +1 -1
- package/lib/properties/flexGrow.js +1 -1
- package/lib/properties/flexShrink.js +1 -1
- package/lib/properties/float.js +1 -1
- package/lib/properties/floodColor.js +1 -1
- package/lib/properties/font.js +1 -1
- package/lib/properties/fontFamily.js +1 -1
- package/lib/properties/fontSize.js +1 -1
- package/lib/properties/fontStyle.js +1 -1
- package/lib/properties/fontVariant.js +1 -1
- package/lib/properties/fontWeight.js +1 -1
- package/lib/properties/height.js +1 -1
- package/lib/properties/left.js +1 -1
- package/lib/properties/lightingColor.js +1 -1
- package/lib/properties/lineHeight.js +1 -1
- package/lib/properties/margin.js +1 -1
- package/lib/properties/marginBottom.js +1 -1
- package/lib/properties/marginLeft.js +1 -1
- package/lib/properties/marginRight.js +1 -1
- package/lib/properties/marginTop.js +1 -1
- package/lib/properties/opacity.js +1 -1
- package/lib/properties/outlineColor.js +1 -1
- package/lib/properties/padding.js +1 -1
- package/lib/properties/paddingBottom.js +1 -1
- package/lib/properties/paddingLeft.js +1 -1
- package/lib/properties/paddingRight.js +1 -1
- package/lib/properties/paddingTop.js +1 -1
- package/lib/properties/right.js +1 -1
- package/lib/properties/stopColor.js +1 -1
- package/lib/properties/top.js +1 -2
- package/lib/properties/webkitBorderAfterColor.js +1 -1
- package/lib/properties/webkitBorderBeforeColor.js +1 -1
- package/lib/properties/webkitBorderEndColor.js +1 -1
- package/lib/properties/webkitBorderStartColor.js +1 -1
- package/lib/properties/webkitColumnRuleColor.js +1 -1
- package/lib/properties/webkitTapHighlightColor.js +1 -1
- package/lib/properties/webkitTextEmphasisColor.js +1 -1
- package/lib/properties/webkitTextFillColor.js +1 -1
- package/lib/properties/webkitTextStrokeColor.js +1 -1
- package/lib/properties/width.js +1 -1
- package/lib/utils/propertyDescriptors.js +1 -1
- package/package.json +1 -1
package/lib/normalize.js
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
const propertyDefinitions = require("./generated/propertyDefinitions");
|
|
4
4
|
const { hasVarFunc, isGlobalKeyword, isValidPropertyValue, splitValue } = require("./parsers");
|
|
5
5
|
const background = require("./properties/background");
|
|
6
|
+
const backgroundColor = require("./properties/backgroundColor");
|
|
7
|
+
const backgroundSize = require("./properties/backgroundSize");
|
|
6
8
|
const border = require("./properties/border");
|
|
7
9
|
const borderWidth = require("./properties/borderWidth");
|
|
8
10
|
const borderStyle = require("./properties/borderStyle");
|
|
@@ -17,18 +19,7 @@ const margin = require("./properties/margin");
|
|
|
17
19
|
const padding = require("./properties/padding");
|
|
18
20
|
|
|
19
21
|
/* constants */
|
|
20
|
-
const BACKGROUND = "background";
|
|
21
|
-
const BACKGROUND_COLOR = "background-color";
|
|
22
|
-
const BACKGROUND_SIZE = "background-size";
|
|
23
|
-
const BORDER = "border";
|
|
24
|
-
const BORDER_BOTTOM = "border-bottom";
|
|
25
|
-
const BORDER_COLOR = "border-color";
|
|
26
22
|
const BORDER_IMAGE = "border-image";
|
|
27
|
-
const BORDER_LEFT = "border-left";
|
|
28
|
-
const BORDER_RIGHT = "border-right";
|
|
29
|
-
const BORDER_STYLE = "border-style";
|
|
30
|
-
const BORDER_TOP = "border-top";
|
|
31
|
-
const BORDER_WIDTH = "border-width";
|
|
32
23
|
const TOP = "top";
|
|
33
24
|
const RIGHT = "right";
|
|
34
25
|
const BOTTOM = "bottom";
|
|
@@ -46,9 +37,9 @@ const TRBL_INDICES = {
|
|
|
46
37
|
|
|
47
38
|
/* shorthands */
|
|
48
39
|
const shorthandProperties = new Map([
|
|
49
|
-
[
|
|
40
|
+
[background.property, background],
|
|
50
41
|
[
|
|
51
|
-
|
|
42
|
+
border.property,
|
|
52
43
|
{
|
|
53
44
|
definition: border.definition,
|
|
54
45
|
parse: border.parse,
|
|
@@ -59,13 +50,13 @@ const shorthandProperties = new Map([
|
|
|
59
50
|
])
|
|
60
51
|
}
|
|
61
52
|
],
|
|
62
|
-
[
|
|
63
|
-
[
|
|
64
|
-
[
|
|
65
|
-
[
|
|
66
|
-
[
|
|
67
|
-
[
|
|
68
|
-
[
|
|
53
|
+
[borderWidth.property, borderWidth],
|
|
54
|
+
[borderStyle.property, borderStyle],
|
|
55
|
+
[borderColor.property, borderColor],
|
|
56
|
+
[borderTop.property, borderTop],
|
|
57
|
+
[borderRight.property, borderRight],
|
|
58
|
+
[borderBottom.property, borderBottom],
|
|
59
|
+
[borderLeft.property, borderLeft],
|
|
69
60
|
["flex", flex],
|
|
70
61
|
["font", font],
|
|
71
62
|
["margin", margin],
|
|
@@ -74,7 +65,7 @@ const shorthandProperties = new Map([
|
|
|
74
65
|
|
|
75
66
|
/* borders */
|
|
76
67
|
const borderProperties = new Set([
|
|
77
|
-
|
|
68
|
+
border.property,
|
|
78
69
|
BORDER_IMAGE,
|
|
79
70
|
...border.shorthandFor.keys(),
|
|
80
71
|
...border.positionShorthandFor.keys(),
|
|
@@ -199,10 +190,10 @@ const replaceBackgroundShorthand = (property, properties, opt) => {
|
|
|
199
190
|
const values = splitValue(parsedValue, {
|
|
200
191
|
delimiter: ","
|
|
201
192
|
});
|
|
202
|
-
const { value: shorthandValue } = properties.get(
|
|
193
|
+
const { value: shorthandValue } = properties.get(background.property);
|
|
203
194
|
const bgValues = background.parse(shorthandValue, opt);
|
|
204
195
|
const bgLength = bgValues.length;
|
|
205
|
-
if (property ===
|
|
196
|
+
if (property === backgroundColor.property) {
|
|
206
197
|
bgValues[bgLength - 1][property] = parsedValue[0];
|
|
207
198
|
} else {
|
|
208
199
|
for (let i = 0; i < bgLength; i++) {
|
|
@@ -216,7 +207,7 @@ const replaceBackgroundShorthand = (property, properties, opt) => {
|
|
|
216
207
|
if (!value || value === background.initialValues.get(longhand)) {
|
|
217
208
|
continue;
|
|
218
209
|
}
|
|
219
|
-
if (longhand ===
|
|
210
|
+
if (longhand === backgroundSize.property) {
|
|
220
211
|
bg.push(`/ ${value}`);
|
|
221
212
|
} else {
|
|
222
213
|
bg.push(value);
|
|
@@ -526,7 +517,7 @@ const prepareBorderStringValue = ({
|
|
|
526
517
|
globalObject,
|
|
527
518
|
options
|
|
528
519
|
};
|
|
529
|
-
const shorthandItem = getPropertyItem(
|
|
520
|
+
const shorthandItem = getPropertyItem(border.property, properties);
|
|
530
521
|
const imageItem = getPropertyItem(BORDER_IMAGE, properties);
|
|
531
522
|
// Handle longhand properties.
|
|
532
523
|
if (prop3) {
|
|
@@ -570,7 +561,7 @@ const prepareBorderStringValue = ({
|
|
|
570
561
|
positionItem.value = "";
|
|
571
562
|
}
|
|
572
563
|
}
|
|
573
|
-
borderItems.set(
|
|
564
|
+
borderItems.set(border.property, shorthandItem);
|
|
574
565
|
borderItems.set(BORDER_IMAGE, imageItem);
|
|
575
566
|
borderItems.set(lineProperty, lineItem);
|
|
576
567
|
borderItems.set(positionProperty, positionItem);
|
|
@@ -639,7 +630,7 @@ const prepareBorderStringValue = ({
|
|
|
639
630
|
longhandItem.priority = priority;
|
|
640
631
|
borderItems.set(longhandProperty, longhandItem);
|
|
641
632
|
}
|
|
642
|
-
borderItems.set(
|
|
633
|
+
borderItems.set(border.property, shorthandItem);
|
|
643
634
|
borderItems.set(BORDER_IMAGE, imageItem);
|
|
644
635
|
borderItems.set(lineWidthProperty, lineWidthItem);
|
|
645
636
|
borderItems.set(lineStyleProperty, lineStyleItem);
|
|
@@ -678,7 +669,7 @@ const prepareBorderStringValue = ({
|
|
|
678
669
|
borderItems.set(positionProperty, positionItem);
|
|
679
670
|
borderItems.set(longhandProperty, longhandItem);
|
|
680
671
|
}
|
|
681
|
-
borderItems.set(
|
|
672
|
+
borderItems.set(border.property, shorthandItem);
|
|
682
673
|
borderItems.set(BORDER_IMAGE, imageItem);
|
|
683
674
|
borderItems.set(lineProperty, lineItem);
|
|
684
675
|
// Handle border shorthand.
|
|
@@ -732,7 +723,7 @@ const prepareBorderArrayValue = ({ value, priority, properties, parts, opt, bord
|
|
|
732
723
|
if (!value.length || !borderLines.has(prop2)) {
|
|
733
724
|
return;
|
|
734
725
|
}
|
|
735
|
-
const shorthandItem = getPropertyItem(
|
|
726
|
+
const shorthandItem = getPropertyItem(border.property, properties);
|
|
736
727
|
const imageItem = getPropertyItem(BORDER_IMAGE, properties);
|
|
737
728
|
const lineProperty = `${prop1}-${prop2}`;
|
|
738
729
|
const lineItem = getPropertyItem(lineProperty, properties);
|
|
@@ -803,7 +794,7 @@ const prepareBorderArrayValue = ({ value, priority, properties, parts, opt, bord
|
|
|
803
794
|
borderItems.set(positionProperty, positionItem);
|
|
804
795
|
borderItems.set(longhandProperty, longhandItem);
|
|
805
796
|
}
|
|
806
|
-
borderItems.set(
|
|
797
|
+
borderItems.set(border.property, shorthandItem);
|
|
807
798
|
borderItems.set(BORDER_IMAGE, imageItem);
|
|
808
799
|
borderItems.set(lineProperty, lineItem);
|
|
809
800
|
};
|
|
@@ -841,7 +832,7 @@ const prepareBorderObjectValue = ({
|
|
|
841
832
|
if (!borderPositions.has(prop2)) {
|
|
842
833
|
return;
|
|
843
834
|
}
|
|
844
|
-
const shorthandItem = getPropertyItem(
|
|
835
|
+
const shorthandItem = getPropertyItem(border.property, properties);
|
|
845
836
|
const lineWidthProperty = `${prop1}-width`;
|
|
846
837
|
const lineWidthItem = getPropertyItem(lineWidthProperty, properties);
|
|
847
838
|
const lineStyleProperty = `${prop1}-style`;
|
|
@@ -889,7 +880,7 @@ const prepareBorderObjectValue = ({
|
|
|
889
880
|
longhandItem.priority = priority;
|
|
890
881
|
borderItems.set(longhandProperty, longhandItem);
|
|
891
882
|
}
|
|
892
|
-
borderItems.set(
|
|
883
|
+
borderItems.set(border.property, shorthandItem);
|
|
893
884
|
borderItems.set(BORDER_IMAGE, imageItem);
|
|
894
885
|
borderItems.set(lineWidthProperty, lineWidthItem);
|
|
895
886
|
borderItems.set(lineStyleProperty, lineStyleItem);
|
|
@@ -967,17 +958,17 @@ const prepareBorderProperties = (property, value, priority, properties, opt = {}
|
|
|
967
958
|
if (typeof property !== "string" || value === null) {
|
|
968
959
|
return;
|
|
969
960
|
}
|
|
970
|
-
if (!property.startsWith(
|
|
961
|
+
if (!property.startsWith(border.property)) {
|
|
971
962
|
return;
|
|
972
963
|
}
|
|
973
964
|
let prop2, prop3;
|
|
974
|
-
if (property.length >
|
|
965
|
+
if (property.length > border.property.length) {
|
|
975
966
|
// Check if next char is '-'
|
|
976
|
-
if (property.charCodeAt(
|
|
967
|
+
if (property.charCodeAt(border.property.length) !== 45) {
|
|
977
968
|
return;
|
|
978
969
|
}
|
|
979
970
|
// property is like "border-..."
|
|
980
|
-
const remainder = property.substring(
|
|
971
|
+
const remainder = property.substring(border.property.length + 1);
|
|
981
972
|
const hyphenIndex = remainder.indexOf("-");
|
|
982
973
|
if (hyphenIndex !== -1) {
|
|
983
974
|
prop2 = remainder.substring(0, hyphenIndex);
|
|
@@ -993,7 +984,7 @@ const prepareBorderProperties = (property, value, priority, properties, opt = {}
|
|
|
993
984
|
return;
|
|
994
985
|
}
|
|
995
986
|
const parts = {
|
|
996
|
-
prop1:
|
|
987
|
+
prop1: border.property,
|
|
997
988
|
prop2,
|
|
998
989
|
prop3
|
|
999
990
|
};
|
|
@@ -1028,22 +1019,22 @@ const prepareBorderProperties = (property, value, priority, properties, opt = {}
|
|
|
1028
1019
|
borderItems
|
|
1029
1020
|
});
|
|
1030
1021
|
}
|
|
1031
|
-
if (!borderItems.has(
|
|
1022
|
+
if (!borderItems.has(border.property)) {
|
|
1032
1023
|
return;
|
|
1033
1024
|
}
|
|
1034
|
-
const borderProps = new Map([[
|
|
1025
|
+
const borderProps = new Map([[border.property, borderItems.get(border.property)]]);
|
|
1035
1026
|
for (const line of borderLines) {
|
|
1036
|
-
const lineProperty = `${
|
|
1027
|
+
const lineProperty = `${border.property}-${line}`;
|
|
1037
1028
|
const lineItem = borderItems.get(lineProperty) ?? getPropertyItem(lineProperty, properties);
|
|
1038
1029
|
borderProps.set(lineProperty, lineItem);
|
|
1039
1030
|
}
|
|
1040
1031
|
for (const position of borderPositions) {
|
|
1041
|
-
const positionProperty = `${
|
|
1032
|
+
const positionProperty = `${border.property}-${position}`;
|
|
1042
1033
|
const positionItem =
|
|
1043
1034
|
borderItems.get(positionProperty) ?? getPropertyItem(positionProperty, properties);
|
|
1044
1035
|
borderProps.set(positionProperty, positionItem);
|
|
1045
1036
|
for (const line of borderLines) {
|
|
1046
|
-
const longhandProperty = `${
|
|
1037
|
+
const longhandProperty = `${border.property}-${position}-${line}`;
|
|
1047
1038
|
const longhandItem =
|
|
1048
1039
|
borderItems.get(longhandProperty) ?? getPropertyItem(longhandProperty, properties);
|
|
1049
1040
|
borderProps.set(longhandProperty, longhandItem);
|
|
@@ -1108,31 +1099,31 @@ const generateBorderShorthand = (items, property, priority = "") => {
|
|
|
1108
1099
|
|
|
1109
1100
|
const borderCollectionConfig = {
|
|
1110
1101
|
[WIDTH]: {
|
|
1111
|
-
shorthand:
|
|
1102
|
+
shorthand: borderWidth.property,
|
|
1112
1103
|
generator: generateBorderLineShorthand
|
|
1113
1104
|
},
|
|
1114
1105
|
[STYLE]: {
|
|
1115
|
-
shorthand:
|
|
1106
|
+
shorthand: borderStyle.property,
|
|
1116
1107
|
generator: generateBorderLineShorthand
|
|
1117
1108
|
},
|
|
1118
1109
|
[COLOR]: {
|
|
1119
|
-
shorthand:
|
|
1110
|
+
shorthand: borderColor.property,
|
|
1120
1111
|
generator: generateBorderLineShorthand
|
|
1121
1112
|
},
|
|
1122
1113
|
[TOP]: {
|
|
1123
|
-
shorthand:
|
|
1114
|
+
shorthand: borderTop.property,
|
|
1124
1115
|
generator: generateBorderPositionShorthand
|
|
1125
1116
|
},
|
|
1126
1117
|
[RIGHT]: {
|
|
1127
|
-
shorthand:
|
|
1118
|
+
shorthand: borderRight.property,
|
|
1128
1119
|
generator: generateBorderPositionShorthand
|
|
1129
1120
|
},
|
|
1130
1121
|
[BOTTOM]: {
|
|
1131
|
-
shorthand:
|
|
1122
|
+
shorthand: borderBottom.property,
|
|
1132
1123
|
generator: generateBorderPositionShorthand
|
|
1133
1124
|
},
|
|
1134
1125
|
[LEFT]: {
|
|
1135
|
-
shorthand:
|
|
1126
|
+
shorthand: borderLeft.property,
|
|
1136
1127
|
generator: generateBorderPositionShorthand
|
|
1137
1128
|
}
|
|
1138
1129
|
};
|
|
@@ -1217,7 +1208,7 @@ const prepareBorderShorthands = (properties) => {
|
|
|
1217
1208
|
const mixedPriorities = shorthandItems.length && shorthandPriorityItems.length;
|
|
1218
1209
|
const imageItem = createPropertyItem(BORDER_IMAGE, NONE);
|
|
1219
1210
|
if (shorthandItems.length === 4) {
|
|
1220
|
-
const [property, item] = generateBorderShorthand(shorthandItems,
|
|
1211
|
+
const [property, item] = generateBorderShorthand(shorthandItems, border.property) ?? [];
|
|
1221
1212
|
if (property && item) {
|
|
1222
1213
|
properties.set(property, item);
|
|
1223
1214
|
properties.delete(BORDER_IMAGE);
|
|
@@ -1225,7 +1216,7 @@ const prepareBorderShorthands = (properties) => {
|
|
|
1225
1216
|
}
|
|
1226
1217
|
} else if (shorthandPriorityItems.length === 4) {
|
|
1227
1218
|
const [property, item] =
|
|
1228
|
-
generateBorderShorthand(shorthandPriorityItems,
|
|
1219
|
+
generateBorderShorthand(shorthandPriorityItems, border.property, "important") ?? [];
|
|
1229
1220
|
if (property && item) {
|
|
1230
1221
|
properties.set(property, item);
|
|
1231
1222
|
properties.delete(BORDER_IMAGE);
|
|
@@ -1326,7 +1317,7 @@ const processBorderProperties = (borders, parseOpt) => {
|
|
|
1326
1317
|
for (const [property, item] of borders) {
|
|
1327
1318
|
if (shorthandProperties.has(property)) {
|
|
1328
1319
|
const { value, priority } = item;
|
|
1329
|
-
if (property ===
|
|
1320
|
+
if (property === border.property) {
|
|
1330
1321
|
const lineItems = border.parse(value, parseOpt);
|
|
1331
1322
|
for (const [key, initialValue] of border.initialValues) {
|
|
1332
1323
|
if (!Object.hasOwn(lineItems, key)) {
|
|
@@ -1482,7 +1473,7 @@ const prepareProperties = (properties, opt = {}) => {
|
|
|
1482
1473
|
}
|
|
1483
1474
|
}
|
|
1484
1475
|
if (!omitShorthandProperty) {
|
|
1485
|
-
if (property ===
|
|
1476
|
+
if (property === background.property) {
|
|
1486
1477
|
hasPrecedingBackground = true;
|
|
1487
1478
|
}
|
|
1488
1479
|
parsedProperties.set(property, createPropertyItem(property, value, priority));
|
|
@@ -1490,17 +1481,19 @@ const prepareProperties = (properties, opt = {}) => {
|
|
|
1490
1481
|
} else {
|
|
1491
1482
|
parsedProperties.set(property, createPropertyItem(property, value, priority));
|
|
1492
1483
|
if (hasPrecedingBackground) {
|
|
1493
|
-
const { value: shorthandValue, priority: shorthandPriority } = properties.get(
|
|
1484
|
+
const { value: shorthandValue, priority: shorthandPriority } = properties.get(
|
|
1485
|
+
background.property
|
|
1486
|
+
);
|
|
1494
1487
|
if ((!shorthandPriority || priority) && !hasVarFunc(shorthandValue)) {
|
|
1495
1488
|
const replacedShorthandValue = replaceBackgroundShorthand(
|
|
1496
1489
|
property,
|
|
1497
1490
|
parsedProperties,
|
|
1498
1491
|
parseOpt
|
|
1499
1492
|
);
|
|
1500
|
-
properties.delete(
|
|
1493
|
+
properties.delete(background.property);
|
|
1501
1494
|
properties.set(
|
|
1502
|
-
|
|
1503
|
-
createPropertyItem(
|
|
1495
|
+
background.property,
|
|
1496
|
+
createPropertyItem(background.property, replacedShorthandValue, shorthandPriority)
|
|
1504
1497
|
);
|
|
1505
1498
|
}
|
|
1506
1499
|
}
|
|
@@ -1528,35 +1521,35 @@ const prepareProperties = (properties, opt = {}) => {
|
|
|
1528
1521
|
* @returns {Map} The normalized properties map.
|
|
1529
1522
|
*/
|
|
1530
1523
|
const normalizeProperties = (properties) => {
|
|
1531
|
-
if (properties.has(
|
|
1524
|
+
if (properties.has(border.property)) {
|
|
1532
1525
|
for (const line of borderLines) {
|
|
1533
|
-
properties.delete(`${
|
|
1526
|
+
properties.delete(`${border.property}-${line}`);
|
|
1534
1527
|
}
|
|
1535
1528
|
for (const position of borderPositions) {
|
|
1536
|
-
properties.delete(`${
|
|
1529
|
+
properties.delete(`${border.property}-${position}`);
|
|
1537
1530
|
for (const line of borderLines) {
|
|
1538
|
-
properties.delete(`${
|
|
1531
|
+
properties.delete(`${border.property}-${position}-${line}`);
|
|
1539
1532
|
}
|
|
1540
1533
|
}
|
|
1541
|
-
properties.delete(`${
|
|
1534
|
+
properties.delete(`${border.property}-image`);
|
|
1542
1535
|
}
|
|
1543
1536
|
for (const line of borderLines) {
|
|
1544
|
-
const lineProperty = `${
|
|
1537
|
+
const lineProperty = `${border.property}-${line}`;
|
|
1545
1538
|
if (properties.has(lineProperty)) {
|
|
1546
1539
|
for (const position of borderPositions) {
|
|
1547
|
-
const positionProperty = `${
|
|
1548
|
-
const longhandProperty = `${
|
|
1540
|
+
const positionProperty = `${border.property}-${position}`;
|
|
1541
|
+
const longhandProperty = `${border.property}-${position}-${line}`;
|
|
1549
1542
|
properties.delete(positionProperty);
|
|
1550
1543
|
properties.delete(longhandProperty);
|
|
1551
1544
|
}
|
|
1552
1545
|
}
|
|
1553
1546
|
}
|
|
1554
1547
|
for (const position of borderPositions) {
|
|
1555
|
-
const positionProperty = `${
|
|
1548
|
+
const positionProperty = `${border.property}-${position}`;
|
|
1556
1549
|
if (properties.has(positionProperty)) {
|
|
1557
1550
|
const longhandProperties = [];
|
|
1558
1551
|
for (const line of borderLines) {
|
|
1559
|
-
const longhandProperty = `${
|
|
1552
|
+
const longhandProperty = `${border.property}-${position}-${line}`;
|
|
1560
1553
|
longhandProperties.push(longhandProperty);
|
|
1561
1554
|
}
|
|
1562
1555
|
if (longhandProperties.length === 3) {
|
package/lib/parsers.js
CHANGED
|
@@ -96,33 +96,15 @@ const lruCache = new LRUCache({
|
|
|
96
96
|
* Prepares a stringified value.
|
|
97
97
|
*
|
|
98
98
|
* @param {string|number|null|undefined} value - The value to prepare.
|
|
99
|
-
* @param {object} [globalObject=globalThis] - The global object.
|
|
100
99
|
* @returns {string} The prepared value.
|
|
101
100
|
*/
|
|
102
|
-
const prepareValue = (value
|
|
101
|
+
const prepareValue = (value) => {
|
|
103
102
|
// `null` is converted to an empty string.
|
|
104
103
|
// @see https://webidl.spec.whatwg.org/#LegacyNullToEmptyString
|
|
105
104
|
if (value === null) {
|
|
106
105
|
return "";
|
|
107
106
|
}
|
|
108
|
-
|
|
109
|
-
switch (type) {
|
|
110
|
-
case "string":
|
|
111
|
-
return value.trim();
|
|
112
|
-
case "number":
|
|
113
|
-
return value.toString();
|
|
114
|
-
case "undefined":
|
|
115
|
-
return "undefined";
|
|
116
|
-
case "symbol":
|
|
117
|
-
throw new globalObject.TypeError("Can not convert symbol to string.");
|
|
118
|
-
default: {
|
|
119
|
-
const str = value.toString();
|
|
120
|
-
if (typeof str === "string") {
|
|
121
|
-
return str.trim();
|
|
122
|
-
}
|
|
123
|
-
throw new globalObject.TypeError(`Can not convert ${type} to string.`);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
107
|
+
return `${value}`.trim();
|
|
126
108
|
};
|
|
127
109
|
|
|
128
110
|
/**
|
|
@@ -164,9 +146,7 @@ const hasCalcFunc = (val) => {
|
|
|
164
146
|
* @returns {object} The AST or a plain object.
|
|
165
147
|
*/
|
|
166
148
|
const parseCSS = (val, opt, toObject = false) => {
|
|
167
|
-
|
|
168
|
-
val = prepareValue(val);
|
|
169
|
-
}
|
|
149
|
+
val = prepareValue(val);
|
|
170
150
|
const ast = cssTree.parse(val, opt);
|
|
171
151
|
if (toObject) {
|
|
172
152
|
return cssTree.toPlainObject(ast);
|
|
@@ -183,9 +163,7 @@ const parseCSS = (val, opt, toObject = false) => {
|
|
|
183
163
|
* @returns {boolean} True if the value is valid, false otherwise.
|
|
184
164
|
*/
|
|
185
165
|
const isValidPropertyValue = (prop, val) => {
|
|
186
|
-
|
|
187
|
-
val = prepareValue(val);
|
|
188
|
-
}
|
|
166
|
+
val = prepareValue(val);
|
|
189
167
|
if (val === "") {
|
|
190
168
|
return true;
|
|
191
169
|
}
|
|
@@ -225,9 +203,7 @@ const isValidPropertyValue = (prop, val) => {
|
|
|
225
203
|
* @returns {string|undefined} The resolved value.
|
|
226
204
|
*/
|
|
227
205
|
const resolveCalc = (val, opt = { format: "specifiedValue" }) => {
|
|
228
|
-
|
|
229
|
-
val = prepareValue(val);
|
|
230
|
-
}
|
|
206
|
+
val = prepareValue(val);
|
|
231
207
|
if (val === "" || hasVarFunc(val) || !hasCalcFunc(val)) {
|
|
232
208
|
return val;
|
|
233
209
|
}
|
|
@@ -276,8 +252,8 @@ const resolveCalc = (val, opt = { format: "specifiedValue" }) => {
|
|
|
276
252
|
* @returns {string|Array<object>|undefined} The parsed value.
|
|
277
253
|
*/
|
|
278
254
|
const parsePropertyValue = (prop, val, opt = {}) => {
|
|
279
|
-
const { caseSensitive,
|
|
280
|
-
val = prepareValue(val
|
|
255
|
+
const { caseSensitive, inArray } = opt;
|
|
256
|
+
val = prepareValue(val);
|
|
281
257
|
if (val === "" || hasVarFunc(val)) {
|
|
282
258
|
return val;
|
|
283
259
|
} else if (hasCalcFunc(val)) {
|
|
@@ -247,7 +247,7 @@ module.exports.parse = (v, opt = {}) => {
|
|
|
247
247
|
|
|
248
248
|
module.exports.definition = {
|
|
249
249
|
set(v) {
|
|
250
|
-
v = parsers.prepareValue(v
|
|
250
|
+
v = parsers.prepareValue(v);
|
|
251
251
|
if (v === "" || parsers.hasVarFunc(v)) {
|
|
252
252
|
for (const [key] of module.exports.shorthandFor) {
|
|
253
253
|
this._setProperty(key, "");
|
|
@@ -34,7 +34,7 @@ module.exports.parse = (v, opt = {}) => {
|
|
|
34
34
|
|
|
35
35
|
module.exports.definition = {
|
|
36
36
|
set(v) {
|
|
37
|
-
v = parsers.prepareValue(v
|
|
37
|
+
v = parsers.prepareValue(v);
|
|
38
38
|
if (parsers.hasVarFunc(v)) {
|
|
39
39
|
this._setProperty(shorthand, "");
|
|
40
40
|
this._setProperty(property, v);
|
|
@@ -34,7 +34,7 @@ module.exports.parse = (v, opt = {}) => {
|
|
|
34
34
|
|
|
35
35
|
module.exports.definition = {
|
|
36
36
|
set(v) {
|
|
37
|
-
v = parsers.prepareValue(v
|
|
37
|
+
v = parsers.prepareValue(v);
|
|
38
38
|
if (parsers.hasVarFunc(v)) {
|
|
39
39
|
this._setProperty(shorthand, "");
|
|
40
40
|
this._setProperty(property, v);
|
|
@@ -23,7 +23,7 @@ module.exports.parse = (v, opt = {}) => {
|
|
|
23
23
|
|
|
24
24
|
module.exports.definition = {
|
|
25
25
|
set(v) {
|
|
26
|
-
v = parsers.prepareValue(v
|
|
26
|
+
v = parsers.prepareValue(v);
|
|
27
27
|
if (parsers.hasVarFunc(v)) {
|
|
28
28
|
this._setProperty(shorthand, "");
|
|
29
29
|
this._setProperty(property, v);
|
|
@@ -36,7 +36,7 @@ module.exports.parse = (v, opt = {}) => {
|
|
|
36
36
|
|
|
37
37
|
module.exports.definition = {
|
|
38
38
|
set(v) {
|
|
39
|
-
v = parsers.prepareValue(v
|
|
39
|
+
v = parsers.prepareValue(v);
|
|
40
40
|
if (parsers.hasVarFunc(v)) {
|
|
41
41
|
this._setProperty(shorthand, "");
|
|
42
42
|
this._setProperty(property, v);
|
|
@@ -34,7 +34,7 @@ module.exports.parse = (v, opt = {}) => {
|
|
|
34
34
|
|
|
35
35
|
module.exports.definition = {
|
|
36
36
|
set(v) {
|
|
37
|
-
v = parsers.prepareValue(v
|
|
37
|
+
v = parsers.prepareValue(v);
|
|
38
38
|
if (parsers.hasVarFunc(v)) {
|
|
39
39
|
this._setProperty(shorthand, "");
|
|
40
40
|
this._setProperty(property, v);
|
|
@@ -177,7 +177,7 @@ module.exports.parse = (v, opt = {}) => {
|
|
|
177
177
|
|
|
178
178
|
module.exports.definition = {
|
|
179
179
|
set(v) {
|
|
180
|
-
v = parsers.prepareValue(v
|
|
180
|
+
v = parsers.prepareValue(v);
|
|
181
181
|
if (parsers.hasVarFunc(v)) {
|
|
182
182
|
this._setProperty(shorthand, "");
|
|
183
183
|
this._setProperty(property, v);
|
|
@@ -66,7 +66,7 @@ module.exports.parse = (v, opt = {}) => {
|
|
|
66
66
|
|
|
67
67
|
module.exports.definition = {
|
|
68
68
|
set(v) {
|
|
69
|
-
v = parsers.prepareValue(v
|
|
69
|
+
v = parsers.prepareValue(v);
|
|
70
70
|
if (parsers.hasVarFunc(v)) {
|
|
71
71
|
this._setProperty(shorthand, "");
|
|
72
72
|
this._setProperty(property, v);
|
|
@@ -99,7 +99,7 @@ module.exports.parse = (v, opt = {}) => {
|
|
|
99
99
|
|
|
100
100
|
module.exports.definition = {
|
|
101
101
|
set(v) {
|
|
102
|
-
v = parsers.prepareValue(v
|
|
102
|
+
v = parsers.prepareValue(v);
|
|
103
103
|
if (parsers.hasVarFunc(v)) {
|
|
104
104
|
this._setProperty(shorthand, "");
|
|
105
105
|
this._setProperty(property, v);
|
package/lib/properties/border.js
CHANGED