cssstyle 5.2.1 → 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
package/lib/normalize.js
ADDED
|
@@ -0,0 +1,1417 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const implementedProperties = require("./generated/implementedProperties");
|
|
4
|
+
const { hasVarFunc, isGlobalKeyword, isValidPropertyValue, splitValue } = require("./parsers");
|
|
5
|
+
const background = require("./properties/background");
|
|
6
|
+
const border = require("./properties/border");
|
|
7
|
+
const borderWidth = require("./properties/borderWidth");
|
|
8
|
+
const borderStyle = require("./properties/borderStyle");
|
|
9
|
+
const borderColor = require("./properties/borderColor");
|
|
10
|
+
const borderTop = require("./properties/borderTop");
|
|
11
|
+
const borderRight = require("./properties/borderRight");
|
|
12
|
+
const borderBottom = require("./properties/borderBottom");
|
|
13
|
+
const borderLeft = require("./properties/borderLeft");
|
|
14
|
+
const flex = require("./properties/flex");
|
|
15
|
+
const font = require("./properties/font");
|
|
16
|
+
const margin = require("./properties/margin");
|
|
17
|
+
const padding = require("./properties/padding");
|
|
18
|
+
|
|
19
|
+
const borderImageProperty = "border-image";
|
|
20
|
+
|
|
21
|
+
exports.shorthandProperties = new Map([
|
|
22
|
+
["background", background],
|
|
23
|
+
[
|
|
24
|
+
"border",
|
|
25
|
+
{
|
|
26
|
+
definition: border.definition,
|
|
27
|
+
parse: border.parse,
|
|
28
|
+
shorthandFor: new Map([
|
|
29
|
+
...border.shorthandFor,
|
|
30
|
+
...border.positionShorthandFor,
|
|
31
|
+
[borderImageProperty, null]
|
|
32
|
+
])
|
|
33
|
+
}
|
|
34
|
+
],
|
|
35
|
+
["border-width", borderWidth],
|
|
36
|
+
["border-style", borderStyle],
|
|
37
|
+
["border-color", borderColor],
|
|
38
|
+
["border-top", borderTop],
|
|
39
|
+
["border-right", borderRight],
|
|
40
|
+
["border-bottom", borderBottom],
|
|
41
|
+
["border-left", borderLeft],
|
|
42
|
+
["flex", flex],
|
|
43
|
+
["font", font],
|
|
44
|
+
["margin", margin],
|
|
45
|
+
["padding", padding]
|
|
46
|
+
]);
|
|
47
|
+
|
|
48
|
+
exports.borderProperties = new Set([
|
|
49
|
+
"border",
|
|
50
|
+
borderImageProperty,
|
|
51
|
+
...border.shorthandFor.keys(),
|
|
52
|
+
...border.positionShorthandFor.keys(),
|
|
53
|
+
...borderTop.shorthandFor.keys(),
|
|
54
|
+
...borderRight.shorthandFor.keys(),
|
|
55
|
+
...borderBottom.shorthandFor.keys(),
|
|
56
|
+
...borderLeft.shorthandFor.keys()
|
|
57
|
+
]);
|
|
58
|
+
|
|
59
|
+
exports.getPositionValue = (positionValues, position) => {
|
|
60
|
+
switch (positionValues.length) {
|
|
61
|
+
case 1: {
|
|
62
|
+
const [val1] = positionValues;
|
|
63
|
+
return val1;
|
|
64
|
+
}
|
|
65
|
+
case 2: {
|
|
66
|
+
const [val1, val2] = positionValues;
|
|
67
|
+
switch (position) {
|
|
68
|
+
case "top": {
|
|
69
|
+
return val1;
|
|
70
|
+
}
|
|
71
|
+
case "right": {
|
|
72
|
+
return val2;
|
|
73
|
+
}
|
|
74
|
+
case "bottom": {
|
|
75
|
+
return val1;
|
|
76
|
+
}
|
|
77
|
+
case "left": {
|
|
78
|
+
return val2;
|
|
79
|
+
}
|
|
80
|
+
default: {
|
|
81
|
+
if (val1 === val2) {
|
|
82
|
+
return val1;
|
|
83
|
+
}
|
|
84
|
+
return `${val1} ${val2}`;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
case 3: {
|
|
89
|
+
const [val1, val2, val3] = positionValues;
|
|
90
|
+
switch (position) {
|
|
91
|
+
case "top": {
|
|
92
|
+
return val1;
|
|
93
|
+
}
|
|
94
|
+
case "right": {
|
|
95
|
+
return val2;
|
|
96
|
+
}
|
|
97
|
+
case "bottom": {
|
|
98
|
+
return val3;
|
|
99
|
+
}
|
|
100
|
+
case "left": {
|
|
101
|
+
return val2;
|
|
102
|
+
}
|
|
103
|
+
default: {
|
|
104
|
+
if (val1 === val3) {
|
|
105
|
+
if (val1 === val2) {
|
|
106
|
+
return val1;
|
|
107
|
+
}
|
|
108
|
+
return `${val1} ${val2}`;
|
|
109
|
+
}
|
|
110
|
+
return `${val1} ${val2} ${val3}`;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
case 4: {
|
|
115
|
+
const [val1, val2, val3, val4] = positionValues;
|
|
116
|
+
switch (position) {
|
|
117
|
+
case "top": {
|
|
118
|
+
return val1;
|
|
119
|
+
}
|
|
120
|
+
case "right": {
|
|
121
|
+
return val2;
|
|
122
|
+
}
|
|
123
|
+
case "bottom": {
|
|
124
|
+
return val3;
|
|
125
|
+
}
|
|
126
|
+
case "left": {
|
|
127
|
+
return val4;
|
|
128
|
+
}
|
|
129
|
+
default: {
|
|
130
|
+
if (val2 === val4) {
|
|
131
|
+
if (val1 === val3) {
|
|
132
|
+
if (val1 === val2) {
|
|
133
|
+
return val1;
|
|
134
|
+
}
|
|
135
|
+
return `${val1} ${val2}`;
|
|
136
|
+
}
|
|
137
|
+
return `${val1} ${val2} ${val3}`;
|
|
138
|
+
}
|
|
139
|
+
return `${val1} ${val2} ${val3} ${val4}`;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
default:
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
const borderElements = {
|
|
148
|
+
name: "border",
|
|
149
|
+
positions: ["top", "right", "bottom", "left"],
|
|
150
|
+
lines: ["width", "style", "color"]
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
const getPropertyItem = (property, properties) => {
|
|
154
|
+
const propertyItem = properties.get(property) ?? {
|
|
155
|
+
property,
|
|
156
|
+
value: "",
|
|
157
|
+
priority: ""
|
|
158
|
+
};
|
|
159
|
+
return propertyItem;
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
const matchesBorderShorthandValue = (property, value, shorthandValue, opt = {}) => {
|
|
163
|
+
const { globalObject } = opt;
|
|
164
|
+
const obj = border.parse(shorthandValue, {
|
|
165
|
+
globalObject
|
|
166
|
+
});
|
|
167
|
+
if (Object.hasOwn(obj, property)) {
|
|
168
|
+
return value === obj[property];
|
|
169
|
+
}
|
|
170
|
+
return value === border.initialValues.get(property);
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
const replaceBorderShorthandValue = (value, shorthandValue, opt = {}) => {
|
|
174
|
+
const { globalObject } = opt;
|
|
175
|
+
const borderFirstInitialKey = border.initialValues.keys().next().value;
|
|
176
|
+
const borderFirstInitialValue = border.initialValues.get(borderFirstInitialKey);
|
|
177
|
+
const valueObj = border.parse(value, {
|
|
178
|
+
globalObject
|
|
179
|
+
});
|
|
180
|
+
const shorthandObj = shorthandValue
|
|
181
|
+
? border.parse(shorthandValue, {
|
|
182
|
+
globalObject
|
|
183
|
+
})
|
|
184
|
+
: {
|
|
185
|
+
[borderFirstInitialKey]: borderFirstInitialValue
|
|
186
|
+
};
|
|
187
|
+
const keys = border.shorthandFor.keys();
|
|
188
|
+
for (const key of keys) {
|
|
189
|
+
const initialValue = border.initialValues.get(key);
|
|
190
|
+
let parsedValue = initialValue;
|
|
191
|
+
if (Object.hasOwn(valueObj, key)) {
|
|
192
|
+
parsedValue = valueObj[key];
|
|
193
|
+
}
|
|
194
|
+
if (parsedValue === initialValue) {
|
|
195
|
+
if (key === borderFirstInitialKey) {
|
|
196
|
+
if (!Object.hasOwn(shorthandObj, key)) {
|
|
197
|
+
shorthandObj[key] = parsedValue;
|
|
198
|
+
}
|
|
199
|
+
} else {
|
|
200
|
+
delete shorthandObj[key];
|
|
201
|
+
}
|
|
202
|
+
} else {
|
|
203
|
+
shorthandObj[key] = parsedValue;
|
|
204
|
+
if (
|
|
205
|
+
shorthandObj[borderFirstInitialKey] &&
|
|
206
|
+
shorthandObj[borderFirstInitialKey] === borderFirstInitialValue
|
|
207
|
+
) {
|
|
208
|
+
delete shorthandObj[borderFirstInitialKey];
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
return Object.values(shorthandObj).join(" ");
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
const replacePositionValue = (value, positionValues, position) => {
|
|
216
|
+
switch (positionValues.length) {
|
|
217
|
+
case 1: {
|
|
218
|
+
const [val1] = positionValues;
|
|
219
|
+
if (val1 === value) {
|
|
220
|
+
return positionValues.join(" ");
|
|
221
|
+
}
|
|
222
|
+
switch (position) {
|
|
223
|
+
case "top": {
|
|
224
|
+
return [value, val1, val1].join(" ");
|
|
225
|
+
}
|
|
226
|
+
case "right": {
|
|
227
|
+
return [val1, value, val1, val1].join(" ");
|
|
228
|
+
}
|
|
229
|
+
case "bottom": {
|
|
230
|
+
return [val1, val1, value].join(" ");
|
|
231
|
+
}
|
|
232
|
+
case "left": {
|
|
233
|
+
return [val1, val1, val1, value].join(" ");
|
|
234
|
+
}
|
|
235
|
+
default:
|
|
236
|
+
}
|
|
237
|
+
break;
|
|
238
|
+
}
|
|
239
|
+
case 2: {
|
|
240
|
+
const [val1, val2] = positionValues;
|
|
241
|
+
if (val1 === val2) {
|
|
242
|
+
return replacePositionValue(value, [val1], position);
|
|
243
|
+
}
|
|
244
|
+
switch (position) {
|
|
245
|
+
case "top": {
|
|
246
|
+
if (val1 === value) {
|
|
247
|
+
return positionValues.join(" ");
|
|
248
|
+
}
|
|
249
|
+
return [value, val2, val1].join(" ");
|
|
250
|
+
}
|
|
251
|
+
case "right": {
|
|
252
|
+
if (val2 === value) {
|
|
253
|
+
return positionValues.join(" ");
|
|
254
|
+
}
|
|
255
|
+
return [val1, value, val1, val2].join(" ");
|
|
256
|
+
}
|
|
257
|
+
case "bottom": {
|
|
258
|
+
if (val1 === value) {
|
|
259
|
+
return positionValues.join(" ");
|
|
260
|
+
}
|
|
261
|
+
return [val1, val2, value].join(" ");
|
|
262
|
+
}
|
|
263
|
+
case "left": {
|
|
264
|
+
if (val2 === value) {
|
|
265
|
+
return positionValues.join(" ");
|
|
266
|
+
}
|
|
267
|
+
return [val1, val2, val1, value].join(" ");
|
|
268
|
+
}
|
|
269
|
+
default:
|
|
270
|
+
}
|
|
271
|
+
break;
|
|
272
|
+
}
|
|
273
|
+
case 3: {
|
|
274
|
+
const [val1, val2, val3] = positionValues;
|
|
275
|
+
if (val1 === val3) {
|
|
276
|
+
return replacePositionValue(value, [val1, val2], position);
|
|
277
|
+
}
|
|
278
|
+
switch (position) {
|
|
279
|
+
case "top": {
|
|
280
|
+
if (val1 === value) {
|
|
281
|
+
return positionValues.join(" ");
|
|
282
|
+
} else if (val3 === value) {
|
|
283
|
+
return [value, val2].join(" ");
|
|
284
|
+
}
|
|
285
|
+
return [value, val2, val3].join(" ");
|
|
286
|
+
}
|
|
287
|
+
case "right": {
|
|
288
|
+
if (val2 === value) {
|
|
289
|
+
return positionValues.join(" ");
|
|
290
|
+
}
|
|
291
|
+
return [val1, value, val3, val2].join(" ");
|
|
292
|
+
}
|
|
293
|
+
case "bottom": {
|
|
294
|
+
if (val3 === value) {
|
|
295
|
+
return positionValues.join(" ");
|
|
296
|
+
} else if (val1 === value) {
|
|
297
|
+
return [val1, val2].join(" ");
|
|
298
|
+
}
|
|
299
|
+
return [val1, val2, value].join(" ");
|
|
300
|
+
}
|
|
301
|
+
case "left": {
|
|
302
|
+
if (val2 === value) {
|
|
303
|
+
return positionValues.join(" ");
|
|
304
|
+
}
|
|
305
|
+
return [val1, val2, val3, value].join(" ");
|
|
306
|
+
}
|
|
307
|
+
default:
|
|
308
|
+
}
|
|
309
|
+
break;
|
|
310
|
+
}
|
|
311
|
+
case 4: {
|
|
312
|
+
const [val1, val2, val3, val4] = positionValues;
|
|
313
|
+
if (val2 === val4) {
|
|
314
|
+
return replacePositionValue(value, [val1, val2, val3], position);
|
|
315
|
+
}
|
|
316
|
+
switch (position) {
|
|
317
|
+
case "top": {
|
|
318
|
+
if (val1 === value) {
|
|
319
|
+
return positionValues.join(" ");
|
|
320
|
+
}
|
|
321
|
+
return [value, val2, val3, val4].join(" ");
|
|
322
|
+
}
|
|
323
|
+
case "right": {
|
|
324
|
+
if (val2 === value) {
|
|
325
|
+
return positionValues.join(" ");
|
|
326
|
+
} else if (val4 === value) {
|
|
327
|
+
return [val1, value, val3].join(" ");
|
|
328
|
+
}
|
|
329
|
+
return [val1, value, val3, val4].join(" ");
|
|
330
|
+
}
|
|
331
|
+
case "bottom": {
|
|
332
|
+
if (val3 === value) {
|
|
333
|
+
return positionValues.join(" ");
|
|
334
|
+
}
|
|
335
|
+
return [val1, val2, value, val4].join(" ");
|
|
336
|
+
}
|
|
337
|
+
case "left": {
|
|
338
|
+
if (val4 === value) {
|
|
339
|
+
return positionValues.join(" ");
|
|
340
|
+
} else if (val2 === value) {
|
|
341
|
+
return [val1, val2, val3].join(" ");
|
|
342
|
+
}
|
|
343
|
+
return [val1, val2, val3, value].join(" ");
|
|
344
|
+
}
|
|
345
|
+
default:
|
|
346
|
+
}
|
|
347
|
+
break;
|
|
348
|
+
}
|
|
349
|
+
default:
|
|
350
|
+
}
|
|
351
|
+
};
|
|
352
|
+
|
|
353
|
+
exports.prepareBorderProperties = (property, value, priority, properties, opt = {}) => {
|
|
354
|
+
if (typeof property !== "string" || value === null) {
|
|
355
|
+
return;
|
|
356
|
+
}
|
|
357
|
+
const { globalObject } = opt;
|
|
358
|
+
const { lines, name, positions } = borderElements;
|
|
359
|
+
const [prop1, prop2, prop3] = property.split("-");
|
|
360
|
+
if (prop1 !== name) {
|
|
361
|
+
return;
|
|
362
|
+
} else if (positions.includes(prop2)) {
|
|
363
|
+
if (prop3) {
|
|
364
|
+
if (!lines.includes(prop3)) {
|
|
365
|
+
return;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
} else if (lines.includes(prop2)) {
|
|
369
|
+
if (prop3) {
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
const borderItems = new Map();
|
|
374
|
+
const nameProperty = prop1;
|
|
375
|
+
// Empty string, global keywords, var(), value of longhands.
|
|
376
|
+
if (typeof value === "string") {
|
|
377
|
+
// longhand properties
|
|
378
|
+
if (prop3) {
|
|
379
|
+
const nameItem = getPropertyItem(nameProperty, properties);
|
|
380
|
+
const imageItem = getPropertyItem(borderImageProperty, properties);
|
|
381
|
+
const lineProperty = `${prop1}-${prop3}`;
|
|
382
|
+
const lineItem = getPropertyItem(lineProperty, properties);
|
|
383
|
+
const positionProperty = `${prop1}-${prop2}`;
|
|
384
|
+
const positionItem = getPropertyItem(positionProperty, properties);
|
|
385
|
+
const longhandProperty = `${prop1}-${prop2}-${prop3}`;
|
|
386
|
+
const longhandItem = getPropertyItem(longhandProperty, properties);
|
|
387
|
+
longhandItem.value = value;
|
|
388
|
+
longhandItem.priority = priority;
|
|
389
|
+
const propertyValue = hasVarFunc(value) ? "" : value;
|
|
390
|
+
if (propertyValue === "") {
|
|
391
|
+
nameItem.value = "";
|
|
392
|
+
lineItem.value = "";
|
|
393
|
+
positionItem.value = "";
|
|
394
|
+
} else if (isGlobalKeyword(propertyValue)) {
|
|
395
|
+
if (nameItem.value !== propertyValue) {
|
|
396
|
+
nameItem.value = "";
|
|
397
|
+
}
|
|
398
|
+
if (lineItem.value !== propertyValue) {
|
|
399
|
+
lineItem.value = "";
|
|
400
|
+
}
|
|
401
|
+
if (positionItem.value !== propertyValue) {
|
|
402
|
+
positionItem.value = "";
|
|
403
|
+
}
|
|
404
|
+
} else {
|
|
405
|
+
if (
|
|
406
|
+
nameItem.value &&
|
|
407
|
+
!matchesBorderShorthandValue(lineProperty, propertyValue, nameItem.value, {
|
|
408
|
+
globalObject
|
|
409
|
+
})
|
|
410
|
+
) {
|
|
411
|
+
nameItem.value = "";
|
|
412
|
+
}
|
|
413
|
+
if (lineItem.value) {
|
|
414
|
+
lineItem.value = replacePositionValue(propertyValue, splitValue(lineItem.value), prop2);
|
|
415
|
+
}
|
|
416
|
+
if (
|
|
417
|
+
positionItem.value &&
|
|
418
|
+
!matchesBorderShorthandValue(lineProperty, propertyValue, positionItem.value, {
|
|
419
|
+
globalObject
|
|
420
|
+
})
|
|
421
|
+
) {
|
|
422
|
+
positionItem.value = "";
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
borderItems.set(nameProperty, nameItem);
|
|
426
|
+
borderItems.set(borderImageProperty, imageItem);
|
|
427
|
+
borderItems.set(lineProperty, lineItem);
|
|
428
|
+
borderItems.set(positionProperty, positionItem);
|
|
429
|
+
borderItems.set(longhandProperty, longhandItem);
|
|
430
|
+
// border-top, border-right, border-bottom, border-left shorthands
|
|
431
|
+
} else if (prop2 && positions.includes(prop2)) {
|
|
432
|
+
const nameItem = getPropertyItem(nameProperty, properties);
|
|
433
|
+
const imageItem = getPropertyItem(borderImageProperty, properties);
|
|
434
|
+
const lineWidthProperty = `${prop1}-width`;
|
|
435
|
+
const lineWidthItem = getPropertyItem(lineWidthProperty, properties);
|
|
436
|
+
const lineStyleProperty = `${prop1}-style`;
|
|
437
|
+
const lineStyleItem = getPropertyItem(lineStyleProperty, properties);
|
|
438
|
+
const lineColorProperty = `${prop1}-color`;
|
|
439
|
+
const lineColorItem = getPropertyItem(lineColorProperty, properties);
|
|
440
|
+
const positionProperty = `${prop1}-${prop2}`;
|
|
441
|
+
const positionItem = getPropertyItem(positionProperty, properties);
|
|
442
|
+
positionItem.value = value;
|
|
443
|
+
positionItem.priority = priority;
|
|
444
|
+
const propertyValue = hasVarFunc(value) ? "" : value;
|
|
445
|
+
if (propertyValue === "") {
|
|
446
|
+
nameItem.value = "";
|
|
447
|
+
lineWidthItem.value = "";
|
|
448
|
+
lineStyleItem.value = "";
|
|
449
|
+
lineColorItem.value = "";
|
|
450
|
+
} else if (isGlobalKeyword(propertyValue)) {
|
|
451
|
+
if (nameItem.value !== propertyValue) {
|
|
452
|
+
nameItem.value = "";
|
|
453
|
+
}
|
|
454
|
+
if (lineWidthItem.value !== propertyValue) {
|
|
455
|
+
lineWidthItem.value = "";
|
|
456
|
+
}
|
|
457
|
+
if (lineStyleItem.value !== propertyValue) {
|
|
458
|
+
lineStyleItem.value = "";
|
|
459
|
+
}
|
|
460
|
+
if (lineColorItem.value !== propertyValue) {
|
|
461
|
+
lineColorItem.value = "";
|
|
462
|
+
}
|
|
463
|
+
} else {
|
|
464
|
+
if (
|
|
465
|
+
nameItem.value &&
|
|
466
|
+
!matchesBorderShorthandValue(property, propertyValue, nameItem.value, {
|
|
467
|
+
globalObject
|
|
468
|
+
})
|
|
469
|
+
) {
|
|
470
|
+
nameItem.value = "";
|
|
471
|
+
}
|
|
472
|
+
if (lineWidthItem.value && isValidPropertyValue(lineWidthProperty, propertyValue)) {
|
|
473
|
+
lineWidthItem.value = propertyValue;
|
|
474
|
+
}
|
|
475
|
+
if (lineStyleItem.value && isValidPropertyValue(lineStyleProperty, propertyValue)) {
|
|
476
|
+
lineStyleItem.value = propertyValue;
|
|
477
|
+
}
|
|
478
|
+
if (lineColorItem.value && isValidPropertyValue(lineColorProperty, propertyValue)) {
|
|
479
|
+
lineColorItem.value = propertyValue;
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
for (const line of lines) {
|
|
483
|
+
const longhandProperty = `${prop1}-${prop2}-${line}`;
|
|
484
|
+
const longhandItem = getPropertyItem(longhandProperty, properties);
|
|
485
|
+
longhandItem.value = propertyValue;
|
|
486
|
+
longhandItem.priority = priority;
|
|
487
|
+
borderItems.set(longhandProperty, longhandItem);
|
|
488
|
+
}
|
|
489
|
+
borderItems.set(nameProperty, nameItem);
|
|
490
|
+
borderItems.set(borderImageProperty, imageItem);
|
|
491
|
+
borderItems.set(lineWidthProperty, lineWidthItem);
|
|
492
|
+
borderItems.set(lineStyleProperty, lineStyleItem);
|
|
493
|
+
borderItems.set(lineColorProperty, lineColorItem);
|
|
494
|
+
borderItems.set(positionProperty, positionItem);
|
|
495
|
+
// border-width, border-style, border-color
|
|
496
|
+
} else if (prop2 && lines.includes(prop2)) {
|
|
497
|
+
const nameItem = getPropertyItem(nameProperty, properties);
|
|
498
|
+
const imageItem = getPropertyItem(borderImageProperty, properties);
|
|
499
|
+
const lineProperty = `${prop1}-${prop2}`;
|
|
500
|
+
const lineItem = getPropertyItem(lineProperty, properties);
|
|
501
|
+
lineItem.value = value;
|
|
502
|
+
lineItem.priority = priority;
|
|
503
|
+
const propertyValue = hasVarFunc(value) ? "" : value;
|
|
504
|
+
if (propertyValue === "") {
|
|
505
|
+
nameItem.value = "";
|
|
506
|
+
} else if (isGlobalKeyword(propertyValue)) {
|
|
507
|
+
if (nameItem.value !== propertyValue) {
|
|
508
|
+
nameItem.value = "";
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
for (const position of positions) {
|
|
512
|
+
const positionProperty = `${prop1}-${position}`;
|
|
513
|
+
const positionItem = getPropertyItem(positionProperty, properties);
|
|
514
|
+
const longhandProperty = `${prop1}-${position}-${prop2}`;
|
|
515
|
+
const longhandItem = getPropertyItem(longhandProperty, properties);
|
|
516
|
+
if (propertyValue) {
|
|
517
|
+
positionItem.value = replaceBorderShorthandValue(propertyValue, positionItem.value, {
|
|
518
|
+
globalObject
|
|
519
|
+
});
|
|
520
|
+
} else {
|
|
521
|
+
positionItem.value = "";
|
|
522
|
+
}
|
|
523
|
+
longhandItem.value = propertyValue;
|
|
524
|
+
longhandItem.priority = priority;
|
|
525
|
+
borderItems.set(positionProperty, positionItem);
|
|
526
|
+
borderItems.set(longhandProperty, longhandItem);
|
|
527
|
+
}
|
|
528
|
+
borderItems.set(nameProperty, nameItem);
|
|
529
|
+
borderItems.set(borderImageProperty, imageItem);
|
|
530
|
+
borderItems.set(lineProperty, lineItem);
|
|
531
|
+
// border shorthand
|
|
532
|
+
} else {
|
|
533
|
+
const nameItem = getPropertyItem(nameProperty, properties);
|
|
534
|
+
const imageItem = getPropertyItem(borderImageProperty, properties);
|
|
535
|
+
const propertyValue = hasVarFunc(value) ? "" : value;
|
|
536
|
+
imageItem.value = propertyValue ? "none" : "";
|
|
537
|
+
for (const line of lines) {
|
|
538
|
+
const lineProperty = `${prop1}-${line}`;
|
|
539
|
+
const lineItem = getPropertyItem(lineProperty, properties);
|
|
540
|
+
lineItem.value = propertyValue;
|
|
541
|
+
lineItem.priority = priority;
|
|
542
|
+
borderItems.set(lineProperty, lineItem);
|
|
543
|
+
}
|
|
544
|
+
for (const position of positions) {
|
|
545
|
+
const positionProperty = `${prop1}-${position}`;
|
|
546
|
+
const positionItem = getPropertyItem(positionProperty, properties);
|
|
547
|
+
positionItem.value = propertyValue;
|
|
548
|
+
positionItem.priority = priority;
|
|
549
|
+
borderItems.set(positionProperty, positionItem);
|
|
550
|
+
for (const line of lines) {
|
|
551
|
+
const longhandProperty = `${positionProperty}-${line}`;
|
|
552
|
+
const longhandItem = getPropertyItem(longhandProperty, properties);
|
|
553
|
+
longhandItem.value = propertyValue;
|
|
554
|
+
longhandItem.priority = priority;
|
|
555
|
+
borderItems.set(longhandProperty, longhandItem);
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
borderItems.set(property, nameItem);
|
|
559
|
+
borderItems.set(borderImageProperty, imageItem);
|
|
560
|
+
}
|
|
561
|
+
// Values of border-width, border-style, border-color
|
|
562
|
+
} else if (Array.isArray(value)) {
|
|
563
|
+
if (!value.length || !lines.includes(prop2)) {
|
|
564
|
+
return;
|
|
565
|
+
}
|
|
566
|
+
const nameItem = getPropertyItem(nameProperty, properties);
|
|
567
|
+
const imageItem = getPropertyItem(borderImageProperty, properties);
|
|
568
|
+
const lineProperty = `${prop1}-${prop2}`;
|
|
569
|
+
const lineItem = getPropertyItem(lineProperty, properties);
|
|
570
|
+
if (value.length === 1) {
|
|
571
|
+
const [propertyValue] = value;
|
|
572
|
+
if (nameItem.value && propertyValue) {
|
|
573
|
+
nameItem.value = replaceBorderShorthandValue(propertyValue, nameItem.value, {
|
|
574
|
+
globalObject
|
|
575
|
+
});
|
|
576
|
+
}
|
|
577
|
+
} else {
|
|
578
|
+
nameItem.value = "";
|
|
579
|
+
}
|
|
580
|
+
lineItem.value = value.join(" ");
|
|
581
|
+
lineItem.priority = priority;
|
|
582
|
+
const positionValues = {};
|
|
583
|
+
switch (value.length) {
|
|
584
|
+
case 1: {
|
|
585
|
+
const [val1] = value;
|
|
586
|
+
positionValues.top = val1;
|
|
587
|
+
positionValues.right = val1;
|
|
588
|
+
positionValues.bottom = val1;
|
|
589
|
+
positionValues.left = val1;
|
|
590
|
+
break;
|
|
591
|
+
}
|
|
592
|
+
case 2: {
|
|
593
|
+
const [val1, val2] = value;
|
|
594
|
+
positionValues.top = val1;
|
|
595
|
+
positionValues.right = val2;
|
|
596
|
+
positionValues.bottom = val1;
|
|
597
|
+
positionValues.left = val2;
|
|
598
|
+
break;
|
|
599
|
+
}
|
|
600
|
+
case 3: {
|
|
601
|
+
const [val1, val2, val3] = value;
|
|
602
|
+
positionValues.top = val1;
|
|
603
|
+
positionValues.right = val2;
|
|
604
|
+
positionValues.bottom = val3;
|
|
605
|
+
positionValues.left = val2;
|
|
606
|
+
break;
|
|
607
|
+
}
|
|
608
|
+
case 4: {
|
|
609
|
+
const [val1, val2, val3, val4] = value;
|
|
610
|
+
positionValues.top = val1;
|
|
611
|
+
positionValues.right = val2;
|
|
612
|
+
positionValues.bottom = val3;
|
|
613
|
+
positionValues.left = val4;
|
|
614
|
+
break;
|
|
615
|
+
}
|
|
616
|
+
default: {
|
|
617
|
+
return;
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
for (const position of positions) {
|
|
621
|
+
const positionProperty = `${prop1}-${position}`;
|
|
622
|
+
const positionItem = getPropertyItem(positionProperty, properties);
|
|
623
|
+
if (positionItem.value && positionValues[position]) {
|
|
624
|
+
positionItem.value = replaceBorderShorthandValue(
|
|
625
|
+
positionValues[position],
|
|
626
|
+
positionItem.value,
|
|
627
|
+
{
|
|
628
|
+
globalObject
|
|
629
|
+
}
|
|
630
|
+
);
|
|
631
|
+
}
|
|
632
|
+
const longhandProperty = `${positionProperty}-${prop2}`;
|
|
633
|
+
const longhandItem = getPropertyItem(longhandProperty, properties);
|
|
634
|
+
longhandItem.value = positionValues[position];
|
|
635
|
+
longhandItem.priority = priority;
|
|
636
|
+
borderItems.set(positionProperty, positionItem);
|
|
637
|
+
borderItems.set(longhandProperty, longhandItem);
|
|
638
|
+
}
|
|
639
|
+
borderItems.set(nameProperty, nameItem);
|
|
640
|
+
borderItems.set(borderImageProperty, imageItem);
|
|
641
|
+
borderItems.set(lineProperty, lineItem);
|
|
642
|
+
// Values of border, border-top, border-right, border-bottom, border-top.
|
|
643
|
+
} else if (value && typeof value === "object") {
|
|
644
|
+
// position shorthands
|
|
645
|
+
if (prop2) {
|
|
646
|
+
if (!positions.includes(prop2)) {
|
|
647
|
+
return;
|
|
648
|
+
}
|
|
649
|
+
const nameItem = getPropertyItem(nameProperty, properties);
|
|
650
|
+
const imageItem = getPropertyItem(borderImageProperty, properties);
|
|
651
|
+
const lineWidthProperty = `${prop1}-width`;
|
|
652
|
+
const lineWidthItem = getPropertyItem(lineWidthProperty, properties);
|
|
653
|
+
const lineStyleProperty = `${prop1}-style`;
|
|
654
|
+
const lineStyleItem = getPropertyItem(lineStyleProperty, properties);
|
|
655
|
+
const lineColorProperty = `${prop1}-color`;
|
|
656
|
+
const lineColorItem = getPropertyItem(lineColorProperty, properties);
|
|
657
|
+
const positionProperty = `${prop1}-${prop2}`;
|
|
658
|
+
const positionItem = getPropertyItem(positionProperty, properties);
|
|
659
|
+
if (nameItem.value) {
|
|
660
|
+
for (const positionValue of Object.values(value)) {
|
|
661
|
+
if (
|
|
662
|
+
!matchesBorderShorthandValue(property, positionValue, nameItem.value, {
|
|
663
|
+
globalObject
|
|
664
|
+
})
|
|
665
|
+
) {
|
|
666
|
+
nameItem.value = "";
|
|
667
|
+
break;
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
positionItem.value = Object.values(value).join(" ");
|
|
672
|
+
positionItem.priority = priority;
|
|
673
|
+
for (const line of lines) {
|
|
674
|
+
const longhandProperty = `${prop1}-${prop2}-${line}`;
|
|
675
|
+
const longhandItem = getPropertyItem(longhandProperty, properties);
|
|
676
|
+
if (Object.hasOwn(value, longhandProperty)) {
|
|
677
|
+
const itemValue = value[longhandProperty];
|
|
678
|
+
if (line === "width") {
|
|
679
|
+
if (lineWidthItem.value) {
|
|
680
|
+
lineWidthItem.value = replacePositionValue(
|
|
681
|
+
itemValue,
|
|
682
|
+
splitValue(lineWidthItem.value),
|
|
683
|
+
prop2
|
|
684
|
+
);
|
|
685
|
+
}
|
|
686
|
+
} else if (line === "style") {
|
|
687
|
+
if (lineStyleItem.value) {
|
|
688
|
+
lineStyleItem.value = replacePositionValue(
|
|
689
|
+
itemValue,
|
|
690
|
+
splitValue(lineStyleItem.value),
|
|
691
|
+
prop2
|
|
692
|
+
);
|
|
693
|
+
}
|
|
694
|
+
} else if (line === "color") {
|
|
695
|
+
if (lineColorItem.value) {
|
|
696
|
+
lineColorItem.value = replacePositionValue(
|
|
697
|
+
itemValue,
|
|
698
|
+
splitValue(lineColorItem.value),
|
|
699
|
+
prop2
|
|
700
|
+
);
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
longhandItem.value = itemValue;
|
|
704
|
+
longhandItem.priority = priority;
|
|
705
|
+
} else {
|
|
706
|
+
const itemValue = border.initialValues.get(`${prop1}-${line}`);
|
|
707
|
+
if (line === "width") {
|
|
708
|
+
if (lineWidthItem.value) {
|
|
709
|
+
lineWidthItem.value = replacePositionValue(
|
|
710
|
+
itemValue,
|
|
711
|
+
splitValue(lineWidthItem.value),
|
|
712
|
+
prop2
|
|
713
|
+
);
|
|
714
|
+
}
|
|
715
|
+
} else if (line === "style") {
|
|
716
|
+
if (lineStyleItem.value) {
|
|
717
|
+
lineStyleItem.value = replacePositionValue(
|
|
718
|
+
itemValue,
|
|
719
|
+
splitValue(lineStyleItem.value),
|
|
720
|
+
prop2
|
|
721
|
+
);
|
|
722
|
+
}
|
|
723
|
+
} else if (line === "color") {
|
|
724
|
+
if (lineColorItem.value) {
|
|
725
|
+
lineColorItem.value = replacePositionValue(
|
|
726
|
+
itemValue,
|
|
727
|
+
splitValue(lineColorItem.value),
|
|
728
|
+
prop2
|
|
729
|
+
);
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
longhandItem.value = itemValue;
|
|
733
|
+
longhandItem.priority = priority;
|
|
734
|
+
}
|
|
735
|
+
borderItems.set(longhandProperty, longhandItem);
|
|
736
|
+
}
|
|
737
|
+
borderItems.set(nameProperty, nameItem);
|
|
738
|
+
borderItems.set(borderImageProperty, imageItem);
|
|
739
|
+
borderItems.set(lineWidthProperty, lineWidthItem);
|
|
740
|
+
borderItems.set(lineStyleProperty, lineStyleItem);
|
|
741
|
+
borderItems.set(lineColorProperty, lineColorItem);
|
|
742
|
+
borderItems.set(positionProperty, positionItem);
|
|
743
|
+
// border shorthand
|
|
744
|
+
} else {
|
|
745
|
+
const nameItem = getPropertyItem(prop1, properties);
|
|
746
|
+
const imageItem = getPropertyItem(borderImageProperty, properties);
|
|
747
|
+
const lineWidthProperty = `${prop1}-width`;
|
|
748
|
+
const lineWidthItem = getPropertyItem(lineWidthProperty, properties);
|
|
749
|
+
const lineStyleProperty = `${prop1}-style`;
|
|
750
|
+
const lineStyleItem = getPropertyItem(lineStyleProperty, properties);
|
|
751
|
+
const lineColorProperty = `${prop1}-color`;
|
|
752
|
+
const lineColorItem = getPropertyItem(lineColorProperty, properties);
|
|
753
|
+
const propertyValue = Object.values(value).join(" ");
|
|
754
|
+
nameItem.value = propertyValue;
|
|
755
|
+
nameItem.priority = priority;
|
|
756
|
+
imageItem.value = propertyValue ? "none" : "";
|
|
757
|
+
if (Object.hasOwn(value, lineWidthProperty)) {
|
|
758
|
+
lineWidthItem.value = value[lineWidthProperty];
|
|
759
|
+
} else {
|
|
760
|
+
lineWidthItem.value = border.initialValues.get(lineWidthProperty);
|
|
761
|
+
}
|
|
762
|
+
lineWidthItem.priority = priority;
|
|
763
|
+
if (Object.hasOwn(value, lineStyleProperty)) {
|
|
764
|
+
lineStyleItem.value = value[lineStyleProperty];
|
|
765
|
+
} else {
|
|
766
|
+
lineStyleItem.value = border.initialValues.get(lineStyleProperty);
|
|
767
|
+
}
|
|
768
|
+
lineStyleItem.priority = priority;
|
|
769
|
+
if (Object.hasOwn(value, lineColorProperty)) {
|
|
770
|
+
lineColorItem.value = value[lineColorProperty];
|
|
771
|
+
} else {
|
|
772
|
+
lineColorItem.value = border.initialValues.get(lineColorProperty);
|
|
773
|
+
}
|
|
774
|
+
lineColorItem.priority = priority;
|
|
775
|
+
for (const position of positions) {
|
|
776
|
+
const positionProperty = `${prop1}-${position}`;
|
|
777
|
+
const positionItem = getPropertyItem(positionProperty, properties);
|
|
778
|
+
positionItem.value = propertyValue;
|
|
779
|
+
positionItem.priority = priority;
|
|
780
|
+
for (const line of lines) {
|
|
781
|
+
const longhandProperty = `${positionProperty}-${line}`;
|
|
782
|
+
const longhandItem = getPropertyItem(longhandProperty, properties);
|
|
783
|
+
const lineProperty = `${prop1}-${line}`;
|
|
784
|
+
if (Object.hasOwn(value, lineProperty)) {
|
|
785
|
+
longhandItem.value = value[lineProperty];
|
|
786
|
+
} else {
|
|
787
|
+
longhandItem.value = border.initialValues.get(lineProperty);
|
|
788
|
+
}
|
|
789
|
+
longhandItem.priority = priority;
|
|
790
|
+
borderItems.set(longhandProperty, longhandItem);
|
|
791
|
+
}
|
|
792
|
+
borderItems.set(positionProperty, positionItem);
|
|
793
|
+
}
|
|
794
|
+
borderItems.set(property, nameItem);
|
|
795
|
+
borderItems.set(borderImageProperty, imageItem);
|
|
796
|
+
borderItems.set(lineWidthProperty, lineWidthItem);
|
|
797
|
+
borderItems.set(lineStyleProperty, lineStyleItem);
|
|
798
|
+
borderItems.set(lineColorProperty, lineColorItem);
|
|
799
|
+
}
|
|
800
|
+
} else {
|
|
801
|
+
return;
|
|
802
|
+
}
|
|
803
|
+
if (!borderItems.has(name)) {
|
|
804
|
+
return;
|
|
805
|
+
}
|
|
806
|
+
const borderProperties = new Map([[name, borderItems.get(name)]]);
|
|
807
|
+
for (const line of lines) {
|
|
808
|
+
const lineProperty = `${name}-${line}`;
|
|
809
|
+
const lineItem = borderItems.get(lineProperty) ??
|
|
810
|
+
properties.get(lineProperty) ?? {
|
|
811
|
+
property: lineProperty,
|
|
812
|
+
value: "",
|
|
813
|
+
priority: ""
|
|
814
|
+
};
|
|
815
|
+
borderProperties.set(lineProperty, lineItem);
|
|
816
|
+
}
|
|
817
|
+
for (const position of positions) {
|
|
818
|
+
const positionProperty = `${name}-${position}`;
|
|
819
|
+
const positionItem = borderItems.get(positionProperty) ??
|
|
820
|
+
properties.get(positionProperty) ?? {
|
|
821
|
+
property: positionProperty,
|
|
822
|
+
value: "",
|
|
823
|
+
priority: ""
|
|
824
|
+
};
|
|
825
|
+
borderProperties.set(positionProperty, positionItem);
|
|
826
|
+
for (const line of lines) {
|
|
827
|
+
const longhandProperty = `${name}-${position}-${line}`;
|
|
828
|
+
const longhandItem = borderItems.get(longhandProperty) ??
|
|
829
|
+
properties.get(longhandProperty) ?? {
|
|
830
|
+
property: longhandProperty,
|
|
831
|
+
value: "",
|
|
832
|
+
priority: ""
|
|
833
|
+
};
|
|
834
|
+
borderProperties.set(longhandProperty, longhandItem);
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
const borderImageItem = borderItems.get(borderImageProperty) ?? {
|
|
838
|
+
property: borderImageProperty,
|
|
839
|
+
value: "",
|
|
840
|
+
priority: ""
|
|
841
|
+
};
|
|
842
|
+
borderProperties.set(borderImageProperty, borderImageItem);
|
|
843
|
+
return borderProperties;
|
|
844
|
+
};
|
|
845
|
+
|
|
846
|
+
const generateBorderLineShorthand = (items, property, prior) => {
|
|
847
|
+
const values = [];
|
|
848
|
+
for (const [, item] of items) {
|
|
849
|
+
const { value: itemValue } = item;
|
|
850
|
+
values.push(itemValue);
|
|
851
|
+
}
|
|
852
|
+
const value = exports.getPositionValue(values);
|
|
853
|
+
const priority = prior ? prior : "";
|
|
854
|
+
return [property, { property, value, priority }];
|
|
855
|
+
};
|
|
856
|
+
|
|
857
|
+
const generateBorderPositionShorthand = (items, property, prior) => {
|
|
858
|
+
const values = [];
|
|
859
|
+
for (const [, item] of items) {
|
|
860
|
+
const { value: itemValue } = item;
|
|
861
|
+
values.push(itemValue);
|
|
862
|
+
}
|
|
863
|
+
const value = values.join(" ");
|
|
864
|
+
const priority = prior ? prior : "";
|
|
865
|
+
return [property, { property, value, priority }];
|
|
866
|
+
};
|
|
867
|
+
|
|
868
|
+
const generateBorderNameShorthand = (items, property, prior) => {
|
|
869
|
+
const values = new Set(items);
|
|
870
|
+
if (values.size === 1) {
|
|
871
|
+
const value = values.keys().next().value;
|
|
872
|
+
const priority = prior ? prior : "";
|
|
873
|
+
return [property, { property, value, priority }];
|
|
874
|
+
}
|
|
875
|
+
};
|
|
876
|
+
|
|
877
|
+
const prepareBorderShorthands = (properties) => {
|
|
878
|
+
const lineWidthItems = new Map();
|
|
879
|
+
const lineWidthPriorItems = new Map();
|
|
880
|
+
const lineStyleItems = new Map();
|
|
881
|
+
const lineStylePriorItems = new Map();
|
|
882
|
+
const lineColorItems = new Map();
|
|
883
|
+
const lineColorPriorItems = new Map();
|
|
884
|
+
const positionTopItems = new Map();
|
|
885
|
+
const positionTopPriorItems = new Map();
|
|
886
|
+
const positionRightItems = new Map();
|
|
887
|
+
const positionRightPriorItems = new Map();
|
|
888
|
+
const positionBottomItems = new Map();
|
|
889
|
+
const positionBottomPriorItems = new Map();
|
|
890
|
+
const positionLeftItems = new Map();
|
|
891
|
+
const positionLeftPriorItems = new Map();
|
|
892
|
+
for (const [property, { priority, value }] of properties) {
|
|
893
|
+
const [, positionPart, linePart] = property.split("-");
|
|
894
|
+
switch (linePart) {
|
|
895
|
+
case "width": {
|
|
896
|
+
if (priority) {
|
|
897
|
+
lineWidthPriorItems.set(property, { property, value, priority });
|
|
898
|
+
} else {
|
|
899
|
+
lineWidthItems.set(property, { property, value, priority });
|
|
900
|
+
}
|
|
901
|
+
break;
|
|
902
|
+
}
|
|
903
|
+
case "style": {
|
|
904
|
+
if (priority) {
|
|
905
|
+
lineStylePriorItems.set(property, { property, value, priority });
|
|
906
|
+
} else {
|
|
907
|
+
lineStyleItems.set(property, { property, value, priority });
|
|
908
|
+
}
|
|
909
|
+
break;
|
|
910
|
+
}
|
|
911
|
+
case "color": {
|
|
912
|
+
if (priority) {
|
|
913
|
+
lineColorPriorItems.set(property, { property, value, priority });
|
|
914
|
+
} else {
|
|
915
|
+
lineColorItems.set(property, { property, value, priority });
|
|
916
|
+
}
|
|
917
|
+
break;
|
|
918
|
+
}
|
|
919
|
+
default:
|
|
920
|
+
}
|
|
921
|
+
switch (positionPart) {
|
|
922
|
+
case "top": {
|
|
923
|
+
if (priority) {
|
|
924
|
+
positionTopPriorItems.set(property, { property, value, priority });
|
|
925
|
+
} else {
|
|
926
|
+
positionTopItems.set(property, { property, value, priority });
|
|
927
|
+
}
|
|
928
|
+
break;
|
|
929
|
+
}
|
|
930
|
+
case "right": {
|
|
931
|
+
if (priority) {
|
|
932
|
+
positionRightPriorItems.set(property, { property, value, priority });
|
|
933
|
+
} else {
|
|
934
|
+
positionRightItems.set(property, { property, value, priority });
|
|
935
|
+
}
|
|
936
|
+
break;
|
|
937
|
+
}
|
|
938
|
+
case "bottom": {
|
|
939
|
+
if (priority) {
|
|
940
|
+
positionBottomPriorItems.set(property, { property, value, priority });
|
|
941
|
+
} else {
|
|
942
|
+
positionBottomItems.set(property, { property, value, priority });
|
|
943
|
+
}
|
|
944
|
+
break;
|
|
945
|
+
}
|
|
946
|
+
case "left": {
|
|
947
|
+
if (priority) {
|
|
948
|
+
positionLeftPriorItems.set(property, { property, value, priority });
|
|
949
|
+
} else {
|
|
950
|
+
positionLeftItems.set(property, { property, value, priority });
|
|
951
|
+
}
|
|
952
|
+
break;
|
|
953
|
+
}
|
|
954
|
+
default:
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
if (lineWidthItems.size === 4) {
|
|
958
|
+
const [property, item] = generateBorderLineShorthand(lineWidthItems, "border-width") ?? [];
|
|
959
|
+
if (property && item) {
|
|
960
|
+
properties.set(property, item);
|
|
961
|
+
}
|
|
962
|
+
} else if (lineWidthPriorItems.size === 4) {
|
|
963
|
+
const [property, item] =
|
|
964
|
+
generateBorderLineShorthand(lineWidthPriorItems, "border-width", "important") ?? [];
|
|
965
|
+
if (property && item) {
|
|
966
|
+
properties.set(property, item);
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
if (lineStyleItems.size === 4) {
|
|
970
|
+
const [property, item] = generateBorderLineShorthand(lineStyleItems, "border-style") ?? [];
|
|
971
|
+
if (property && item) {
|
|
972
|
+
properties.set(property, item);
|
|
973
|
+
}
|
|
974
|
+
} else if (lineStylePriorItems.size === 4) {
|
|
975
|
+
const [property, item] =
|
|
976
|
+
generateBorderLineShorthand(lineStylePriorItems, "border-style", "important") ?? [];
|
|
977
|
+
if (property && item) {
|
|
978
|
+
properties.set(property, item);
|
|
979
|
+
}
|
|
980
|
+
}
|
|
981
|
+
if (lineColorItems.size === 4) {
|
|
982
|
+
const [property, item] = generateBorderLineShorthand(lineColorItems, "border-color") ?? [];
|
|
983
|
+
if (property && item) {
|
|
984
|
+
properties.set(property, item);
|
|
985
|
+
}
|
|
986
|
+
} else if (lineColorPriorItems.size === 4) {
|
|
987
|
+
const [property, item] =
|
|
988
|
+
generateBorderLineShorthand(lineColorPriorItems, "border-color", "important") ?? [];
|
|
989
|
+
if (property && item) {
|
|
990
|
+
properties.set(property, item);
|
|
991
|
+
}
|
|
992
|
+
}
|
|
993
|
+
const nameItems = [];
|
|
994
|
+
const namePriorItems = [];
|
|
995
|
+
if (positionTopItems.size === 3) {
|
|
996
|
+
const [property, item] = generateBorderPositionShorthand(positionTopItems, "border-top") ?? [];
|
|
997
|
+
if (property && item) {
|
|
998
|
+
properties.set(property, item);
|
|
999
|
+
if (properties.has(borderImageProperty)) {
|
|
1000
|
+
const { value: imageValue } = properties.get(borderImageProperty);
|
|
1001
|
+
if (imageValue === "none") {
|
|
1002
|
+
const { value: itemValue } = item;
|
|
1003
|
+
nameItems.push(itemValue);
|
|
1004
|
+
}
|
|
1005
|
+
}
|
|
1006
|
+
}
|
|
1007
|
+
} else if (positionTopPriorItems.size === 3) {
|
|
1008
|
+
const [property, item] =
|
|
1009
|
+
generateBorderPositionShorthand(positionTopPriorItems, "border-top", "important") ?? [];
|
|
1010
|
+
if (property && item) {
|
|
1011
|
+
properties.set(property, item);
|
|
1012
|
+
if (properties.has(borderImageProperty)) {
|
|
1013
|
+
const { value: imageValue } = properties.get(borderImageProperty);
|
|
1014
|
+
if (imageValue === "none") {
|
|
1015
|
+
const { value: itemValue } = item;
|
|
1016
|
+
namePriorItems.push(itemValue);
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1020
|
+
}
|
|
1021
|
+
if (positionRightItems.size === 3) {
|
|
1022
|
+
const [property, item] =
|
|
1023
|
+
generateBorderPositionShorthand(positionRightItems, "border-right") ?? [];
|
|
1024
|
+
if (property && item) {
|
|
1025
|
+
properties.set(property, item);
|
|
1026
|
+
if (properties.has(borderImageProperty)) {
|
|
1027
|
+
const { value: imageValue } = properties.get(borderImageProperty);
|
|
1028
|
+
if (imageValue === "none") {
|
|
1029
|
+
const { value: itemValue } = item;
|
|
1030
|
+
nameItems.push(itemValue);
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
} else if (positionRightPriorItems.size === 3) {
|
|
1035
|
+
const [property, item] =
|
|
1036
|
+
generateBorderPositionShorthand(positionRightPriorItems, "border-right", "important") ?? [];
|
|
1037
|
+
if (property && item) {
|
|
1038
|
+
properties.set(property, item);
|
|
1039
|
+
if (properties.has(borderImageProperty)) {
|
|
1040
|
+
const { value: imageValue } = properties.get(borderImageProperty);
|
|
1041
|
+
if (imageValue === "none") {
|
|
1042
|
+
const { value: itemValue } = item;
|
|
1043
|
+
nameItems.push(itemValue);
|
|
1044
|
+
}
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1048
|
+
if (positionBottomItems.size === 3) {
|
|
1049
|
+
const [property, item] =
|
|
1050
|
+
generateBorderPositionShorthand(positionBottomItems, "border-bottom") ?? [];
|
|
1051
|
+
if (property && item) {
|
|
1052
|
+
properties.set(property, item);
|
|
1053
|
+
if (properties.has(borderImageProperty)) {
|
|
1054
|
+
const { value: imageValue } = properties.get(borderImageProperty);
|
|
1055
|
+
if (imageValue === "none") {
|
|
1056
|
+
const { value: itemValue } = item;
|
|
1057
|
+
nameItems.push(itemValue);
|
|
1058
|
+
}
|
|
1059
|
+
}
|
|
1060
|
+
}
|
|
1061
|
+
} else if (positionBottomPriorItems.size === 3) {
|
|
1062
|
+
const [property, item] =
|
|
1063
|
+
generateBorderPositionShorthand(positionBottomPriorItems, "border-bottom", "important") ?? [];
|
|
1064
|
+
if (property && item) {
|
|
1065
|
+
properties.set(property, item);
|
|
1066
|
+
if (properties.has(borderImageProperty)) {
|
|
1067
|
+
const { value: imageValue } = properties.get(borderImageProperty);
|
|
1068
|
+
if (imageValue === "none") {
|
|
1069
|
+
const { value: itemValue } = item;
|
|
1070
|
+
nameItems.push(itemValue);
|
|
1071
|
+
}
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
}
|
|
1075
|
+
if (positionLeftItems.size === 3) {
|
|
1076
|
+
const [property, item] =
|
|
1077
|
+
generateBorderPositionShorthand(positionLeftItems, "border-left") ?? [];
|
|
1078
|
+
if (property && item) {
|
|
1079
|
+
properties.set(property, item);
|
|
1080
|
+
if (properties.has(borderImageProperty)) {
|
|
1081
|
+
const { value: imageValue } = properties.get(borderImageProperty);
|
|
1082
|
+
if (imageValue === "none") {
|
|
1083
|
+
const { value: itemValue } = item;
|
|
1084
|
+
nameItems.push(itemValue);
|
|
1085
|
+
}
|
|
1086
|
+
}
|
|
1087
|
+
}
|
|
1088
|
+
} else if (positionLeftPriorItems.size === 3) {
|
|
1089
|
+
const [property, item] =
|
|
1090
|
+
generateBorderPositionShorthand(positionLeftPriorItems, "border-left", "important") ?? [];
|
|
1091
|
+
if (property && item) {
|
|
1092
|
+
properties.set(property, item);
|
|
1093
|
+
if (properties.has(borderImageProperty)) {
|
|
1094
|
+
const { value: imageValue } = properties.get(borderImageProperty);
|
|
1095
|
+
if (imageValue === "none") {
|
|
1096
|
+
const { value: itemValue } = item;
|
|
1097
|
+
nameItems.push(itemValue);
|
|
1098
|
+
}
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1101
|
+
}
|
|
1102
|
+
const mixedPriorities = nameItems.length && namePriorItems.length;
|
|
1103
|
+
const imageItem = {
|
|
1104
|
+
property: borderImageProperty,
|
|
1105
|
+
value: "none",
|
|
1106
|
+
priority: ""
|
|
1107
|
+
};
|
|
1108
|
+
if (nameItems.length === 4) {
|
|
1109
|
+
const [property, item] = generateBorderNameShorthand(nameItems, "border") ?? [];
|
|
1110
|
+
if (property && item) {
|
|
1111
|
+
properties.set(property, item);
|
|
1112
|
+
properties.delete(borderImageProperty);
|
|
1113
|
+
properties.set(borderImageProperty, imageItem);
|
|
1114
|
+
}
|
|
1115
|
+
} else if (namePriorItems.length === 4) {
|
|
1116
|
+
const [property, item] =
|
|
1117
|
+
generateBorderNameShorthand(namePriorItems, "border", "important") ?? [];
|
|
1118
|
+
if (property && item) {
|
|
1119
|
+
properties.set(property, item);
|
|
1120
|
+
properties.delete(borderImageProperty);
|
|
1121
|
+
properties.set(borderImageProperty, imageItem);
|
|
1122
|
+
}
|
|
1123
|
+
} else if (properties.has(borderImageProperty)) {
|
|
1124
|
+
const { value: imageValue } = properties.get(borderImageProperty);
|
|
1125
|
+
if (imageValue === "none") {
|
|
1126
|
+
if (mixedPriorities) {
|
|
1127
|
+
properties.delete(borderImageProperty);
|
|
1128
|
+
properties.set(borderImageProperty, imageItem);
|
|
1129
|
+
} else {
|
|
1130
|
+
properties.delete(borderImageProperty);
|
|
1131
|
+
}
|
|
1132
|
+
}
|
|
1133
|
+
}
|
|
1134
|
+
if (mixedPriorities) {
|
|
1135
|
+
const items = [];
|
|
1136
|
+
const priorItems = [];
|
|
1137
|
+
for (const item of properties) {
|
|
1138
|
+
const [, { priority }] = item;
|
|
1139
|
+
if (priority) {
|
|
1140
|
+
priorItems.push(item);
|
|
1141
|
+
} else {
|
|
1142
|
+
items.push(item);
|
|
1143
|
+
}
|
|
1144
|
+
}
|
|
1145
|
+
const firstPropertyKey = properties.keys().next().value;
|
|
1146
|
+
const { priority: firstPropertyPriority } = properties.get(firstPropertyKey);
|
|
1147
|
+
if (firstPropertyPriority) {
|
|
1148
|
+
return new Map([...priorItems, ...items]);
|
|
1149
|
+
}
|
|
1150
|
+
return new Map([...items, ...priorItems]);
|
|
1151
|
+
}
|
|
1152
|
+
if (properties.has(borderImageProperty)) {
|
|
1153
|
+
properties.delete(borderImageProperty);
|
|
1154
|
+
properties.set(borderImageProperty, imageItem);
|
|
1155
|
+
}
|
|
1156
|
+
return properties;
|
|
1157
|
+
};
|
|
1158
|
+
|
|
1159
|
+
exports.prepareProperties = (properties, opt = {}) => {
|
|
1160
|
+
const { globalObject } = opt;
|
|
1161
|
+
const { positions } = borderElements;
|
|
1162
|
+
const parsedProperties = new Map();
|
|
1163
|
+
const prepareShorthands = new Map();
|
|
1164
|
+
const borderProperties = new Map();
|
|
1165
|
+
for (const [property, item] of properties) {
|
|
1166
|
+
const { value, priority } = item;
|
|
1167
|
+
const { logicalPropertyGroup: shorthandProperty } = implementedProperties.get(property) ?? {};
|
|
1168
|
+
if (exports.borderProperties.has(property)) {
|
|
1169
|
+
borderProperties.set(property, { property, value, priority });
|
|
1170
|
+
} else if (exports.shorthandProperties.has(shorthandProperty)) {
|
|
1171
|
+
if (!prepareShorthands.has(shorthandProperty)) {
|
|
1172
|
+
prepareShorthands.set(shorthandProperty, new Map());
|
|
1173
|
+
}
|
|
1174
|
+
const longhandItems = prepareShorthands.get(shorthandProperty);
|
|
1175
|
+
if (longhandItems.size) {
|
|
1176
|
+
const firstPropertyKey = longhandItems.keys().next().value;
|
|
1177
|
+
const { priority: firstPropertyPriority } = longhandItems.get(firstPropertyKey);
|
|
1178
|
+
if (priority === firstPropertyPriority) {
|
|
1179
|
+
longhandItems.set(property, { property, value, priority });
|
|
1180
|
+
prepareShorthands.set(shorthandProperty, longhandItems);
|
|
1181
|
+
} else {
|
|
1182
|
+
parsedProperties.delete(shorthandProperty);
|
|
1183
|
+
}
|
|
1184
|
+
} else {
|
|
1185
|
+
longhandItems.set(property, { property, value, priority });
|
|
1186
|
+
prepareShorthands.set(shorthandProperty, longhandItems);
|
|
1187
|
+
}
|
|
1188
|
+
parsedProperties.set(property, item);
|
|
1189
|
+
} else if (exports.shorthandProperties.has(property)) {
|
|
1190
|
+
const shorthandItem = exports.shorthandProperties.get(property);
|
|
1191
|
+
const parsedValues = shorthandItem.parse(value, {
|
|
1192
|
+
globalObject
|
|
1193
|
+
});
|
|
1194
|
+
let omitShorthandProperty = false;
|
|
1195
|
+
if (Array.isArray(parsedValues)) {
|
|
1196
|
+
const [parsedValue] = parsedValues;
|
|
1197
|
+
if (typeof parsedValue === "string") {
|
|
1198
|
+
for (const [longhandProperty, longhandItem] of shorthandItem.shorthandFor) {
|
|
1199
|
+
if (!priority && properties.has(longhandProperty)) {
|
|
1200
|
+
const { priority: longhandPriority } = properties.get(longhandProperty);
|
|
1201
|
+
if (longhandPriority) {
|
|
1202
|
+
omitShorthandProperty = true;
|
|
1203
|
+
continue;
|
|
1204
|
+
}
|
|
1205
|
+
}
|
|
1206
|
+
const { position } = longhandItem;
|
|
1207
|
+
const longhandValue = exports.getPositionValue([parsedValue], position);
|
|
1208
|
+
parsedProperties.set(longhandProperty, {
|
|
1209
|
+
property: longhandProperty,
|
|
1210
|
+
value: longhandValue,
|
|
1211
|
+
priority
|
|
1212
|
+
});
|
|
1213
|
+
}
|
|
1214
|
+
} else if (parsedValue) {
|
|
1215
|
+
for (const longhandProperty of Object.keys(parsedValue)) {
|
|
1216
|
+
const longhandValue = parsedValue[longhandProperty];
|
|
1217
|
+
parsedProperties.set(longhandProperty, {
|
|
1218
|
+
property: longhandProperty,
|
|
1219
|
+
value: longhandValue,
|
|
1220
|
+
priority
|
|
1221
|
+
});
|
|
1222
|
+
}
|
|
1223
|
+
}
|
|
1224
|
+
} else if (parsedValues) {
|
|
1225
|
+
for (const longhandProperty of Object.keys(parsedValues)) {
|
|
1226
|
+
const longhandValue = parsedValues[longhandProperty];
|
|
1227
|
+
parsedProperties.set(longhandProperty, {
|
|
1228
|
+
property: longhandProperty,
|
|
1229
|
+
value: longhandValue,
|
|
1230
|
+
priority
|
|
1231
|
+
});
|
|
1232
|
+
}
|
|
1233
|
+
}
|
|
1234
|
+
if (!omitShorthandProperty) {
|
|
1235
|
+
parsedProperties.set(property, { property, value, priority });
|
|
1236
|
+
}
|
|
1237
|
+
} else {
|
|
1238
|
+
parsedProperties.set(property, { property, value, priority });
|
|
1239
|
+
}
|
|
1240
|
+
}
|
|
1241
|
+
if (prepareShorthands.size) {
|
|
1242
|
+
for (const [property, item] of prepareShorthands) {
|
|
1243
|
+
const shorthandItem = exports.shorthandProperties.get(property);
|
|
1244
|
+
if (item.size === shorthandItem.shorthandFor.size) {
|
|
1245
|
+
if (shorthandItem.position) {
|
|
1246
|
+
const positionValues = [];
|
|
1247
|
+
let priority = "";
|
|
1248
|
+
for (const { value: longhandValue, priority: longhandPriority } of item.values()) {
|
|
1249
|
+
positionValues.push(longhandValue);
|
|
1250
|
+
if (longhandPriority) {
|
|
1251
|
+
priority = longhandPriority;
|
|
1252
|
+
}
|
|
1253
|
+
}
|
|
1254
|
+
const value = exports.getPositionValue(positionValues, shorthandItem.position);
|
|
1255
|
+
parsedProperties.set(property, {
|
|
1256
|
+
property,
|
|
1257
|
+
value,
|
|
1258
|
+
priority
|
|
1259
|
+
});
|
|
1260
|
+
}
|
|
1261
|
+
}
|
|
1262
|
+
}
|
|
1263
|
+
}
|
|
1264
|
+
if (borderProperties.size) {
|
|
1265
|
+
const longhandProperties = new Map();
|
|
1266
|
+
for (const [property, item] of borderProperties) {
|
|
1267
|
+
if (exports.shorthandProperties.has(property)) {
|
|
1268
|
+
const { value, priority } = item;
|
|
1269
|
+
if (property === "border") {
|
|
1270
|
+
const lineItems = border.parse(value, {
|
|
1271
|
+
globalObject
|
|
1272
|
+
});
|
|
1273
|
+
for (const [key, initialValue] of border.initialValues) {
|
|
1274
|
+
if (!Object.hasOwn(lineItems, key)) {
|
|
1275
|
+
lineItems[key] = initialValue;
|
|
1276
|
+
}
|
|
1277
|
+
}
|
|
1278
|
+
for (const lineProperty of Object.keys(lineItems)) {
|
|
1279
|
+
const [namePart, linePart] = lineProperty.split("-");
|
|
1280
|
+
const lineValue = lineItems[lineProperty];
|
|
1281
|
+
for (const position of positions) {
|
|
1282
|
+
const longhandProperty = `${namePart}-${position}-${linePart}`;
|
|
1283
|
+
const longhandItem = {
|
|
1284
|
+
property: longhandProperty,
|
|
1285
|
+
value: lineValue,
|
|
1286
|
+
priority
|
|
1287
|
+
};
|
|
1288
|
+
if (longhandProperties.has(longhandProperty)) {
|
|
1289
|
+
const { priority: longhandPriority } = longhandProperties.get(longhandProperty);
|
|
1290
|
+
if (!longhandPriority) {
|
|
1291
|
+
longhandProperties.delete(longhandProperty);
|
|
1292
|
+
longhandProperties.set(longhandProperty, longhandItem);
|
|
1293
|
+
}
|
|
1294
|
+
} else {
|
|
1295
|
+
longhandProperties.set(longhandProperty, longhandItem);
|
|
1296
|
+
}
|
|
1297
|
+
}
|
|
1298
|
+
}
|
|
1299
|
+
if (value) {
|
|
1300
|
+
longhandProperties.set(borderImageProperty, {
|
|
1301
|
+
property: borderImageProperty,
|
|
1302
|
+
value: "none",
|
|
1303
|
+
priority
|
|
1304
|
+
});
|
|
1305
|
+
}
|
|
1306
|
+
} else {
|
|
1307
|
+
const shorthandItem = exports.shorthandProperties.get(property);
|
|
1308
|
+
const parsedItem = shorthandItem.parse(value, {
|
|
1309
|
+
globalObject
|
|
1310
|
+
});
|
|
1311
|
+
if (Array.isArray(parsedItem)) {
|
|
1312
|
+
const [namePart, linePart] = property.split("-");
|
|
1313
|
+
for (const position of positions) {
|
|
1314
|
+
const longhandProperty = `${namePart}-${position}-${linePart}`;
|
|
1315
|
+
const longhandValue = exports.getPositionValue(parsedItem, position);
|
|
1316
|
+
const longhandItem = {
|
|
1317
|
+
property: longhandProperty,
|
|
1318
|
+
value: longhandValue,
|
|
1319
|
+
priority
|
|
1320
|
+
};
|
|
1321
|
+
if (longhandProperties.has(longhandProperty)) {
|
|
1322
|
+
const { priority: longhandPriority } = longhandProperties.get(longhandProperty);
|
|
1323
|
+
if (!longhandPriority) {
|
|
1324
|
+
longhandProperties.delete(longhandProperty);
|
|
1325
|
+
longhandProperties.set(longhandProperty, longhandItem);
|
|
1326
|
+
}
|
|
1327
|
+
} else {
|
|
1328
|
+
longhandProperties.set(longhandProperty, longhandItem);
|
|
1329
|
+
}
|
|
1330
|
+
}
|
|
1331
|
+
} else if (parsedItem) {
|
|
1332
|
+
for (const [key, initialValue] of shorthandItem.initialValues) {
|
|
1333
|
+
if (!Object.hasOwn(parsedItem, key)) {
|
|
1334
|
+
parsedItem[key] = initialValue;
|
|
1335
|
+
}
|
|
1336
|
+
}
|
|
1337
|
+
for (const longhandProperty of Object.keys(parsedItem)) {
|
|
1338
|
+
const longhandValue = parsedItem[longhandProperty];
|
|
1339
|
+
const longhandItem = {
|
|
1340
|
+
property: longhandProperty,
|
|
1341
|
+
value: longhandValue,
|
|
1342
|
+
priority
|
|
1343
|
+
};
|
|
1344
|
+
if (longhandProperties.has(longhandProperty)) {
|
|
1345
|
+
const { priority: longhandPriority } = longhandProperties.get(longhandProperty);
|
|
1346
|
+
if (!longhandPriority) {
|
|
1347
|
+
longhandProperties.delete(longhandProperty);
|
|
1348
|
+
longhandProperties.set(longhandProperty, longhandItem);
|
|
1349
|
+
}
|
|
1350
|
+
} else {
|
|
1351
|
+
longhandProperties.set(longhandProperty, longhandItem);
|
|
1352
|
+
}
|
|
1353
|
+
}
|
|
1354
|
+
}
|
|
1355
|
+
}
|
|
1356
|
+
} else if (longhandProperties.has(property)) {
|
|
1357
|
+
const { priority } = longhandProperties.get(property);
|
|
1358
|
+
if (!priority) {
|
|
1359
|
+
longhandProperties.delete(property);
|
|
1360
|
+
longhandProperties.set(property, item);
|
|
1361
|
+
}
|
|
1362
|
+
} else {
|
|
1363
|
+
longhandProperties.set(property, item);
|
|
1364
|
+
}
|
|
1365
|
+
}
|
|
1366
|
+
const normalizedProperties = prepareBorderShorthands(longhandProperties);
|
|
1367
|
+
for (const [property, item] of normalizedProperties) {
|
|
1368
|
+
parsedProperties.set(property, item);
|
|
1369
|
+
}
|
|
1370
|
+
}
|
|
1371
|
+
return parsedProperties;
|
|
1372
|
+
};
|
|
1373
|
+
|
|
1374
|
+
exports.normalizeBorderProperties = (properties) => {
|
|
1375
|
+
const { lines, name, positions } = borderElements;
|
|
1376
|
+
if (properties.has(name)) {
|
|
1377
|
+
for (const line of lines) {
|
|
1378
|
+
properties.delete(`${name}-${line}`);
|
|
1379
|
+
}
|
|
1380
|
+
for (const position of positions) {
|
|
1381
|
+
properties.delete(`${name}-${position}`);
|
|
1382
|
+
for (const line of lines) {
|
|
1383
|
+
properties.delete(`${name}-${position}-${line}`);
|
|
1384
|
+
}
|
|
1385
|
+
}
|
|
1386
|
+
properties.delete(`${name}-image`);
|
|
1387
|
+
}
|
|
1388
|
+
for (const line of lines) {
|
|
1389
|
+
const lineProperty = `${name}-${line}`;
|
|
1390
|
+
if (properties.has(lineProperty)) {
|
|
1391
|
+
for (const position of positions) {
|
|
1392
|
+
const positionProperty = `${name}-${position}`;
|
|
1393
|
+
const longhandProperty = `${name}-${position}-${line}`;
|
|
1394
|
+
properties.delete(positionProperty);
|
|
1395
|
+
properties.delete(longhandProperty);
|
|
1396
|
+
}
|
|
1397
|
+
}
|
|
1398
|
+
}
|
|
1399
|
+
for (const position of positions) {
|
|
1400
|
+
const positionProperty = `${name}-${position}`;
|
|
1401
|
+
if (properties.has(positionProperty)) {
|
|
1402
|
+
const longhandProperties = [];
|
|
1403
|
+
for (const line of lines) {
|
|
1404
|
+
const longhandProperty = `${name}-${position}-${line}`;
|
|
1405
|
+
longhandProperties.push(longhandProperty);
|
|
1406
|
+
}
|
|
1407
|
+
if (longhandProperties.length === 3) {
|
|
1408
|
+
for (const longhandProperty of longhandProperties) {
|
|
1409
|
+
properties.delete(longhandProperty);
|
|
1410
|
+
}
|
|
1411
|
+
} else {
|
|
1412
|
+
properties.delete(positionProperty);
|
|
1413
|
+
}
|
|
1414
|
+
}
|
|
1415
|
+
}
|
|
1416
|
+
return properties;
|
|
1417
|
+
};
|