Skip to content
This repository was archived by the owner on Jan 6, 2025. It is now read-only.

Commit 435fe61

Browse files
fix(auto-prefixer): resolve perf impacts as reported by LightHouse
Updated based on output from https://autoprefixer.github.io/
1 parent beb5ed0 commit 435fe61

File tree

2 files changed

+30
-34
lines changed

2 files changed

+30
-34
lines changed

src/lib/utils/auto-prefixer.spec.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,11 @@ describe('auto-prefixer for ', () => {
2727
let actual = applyCssPrefixes(input);
2828
expect(Array.isArray(actual['display'])).toBeTruthy();
2929
expect(actual['display'][0]).toEqual('-webkit-box');
30-
expect(actual['display'][4]).toEqual('flex');
30+
31+
// `display:flex` should be last
32+
expect(actual['display'][2]).toEqual('flex');
3133
});
34+
3235
});
3336

3437
/**

src/lib/utils/auto-prefixer.ts

+26-33
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,23 @@
1010
export function applyCssPrefixes(target) {
1111
for (let key in target) {
1212

13-
let value = target[key];
13+
let value = target[key] || "";
14+
let boxValue = toBoxValue(value);
15+
let boxDirection = toBoxDirection(value);
16+
let boxOrient = toBoxOrient(value);
1417

1518
switch (key) {
1619
case 'display':
1720
if (value === 'flex') {
1821
target['display'] = [
1922
'-webkit-box',
20-
'-moz-box',
2123
'-ms-flexbox',
22-
'-webkit-flex',
2324
'flex'
2425
];
2526
} else if (value === 'inline-flex') {
2627
target['display'] = [
2728
'-webkit-inline-box',
28-
'-moz-inline-box',
2929
'-ms-inline-flexbox',
30-
'-webkit-inline-flex',
3130
'inline-flex'
3231
];
3332
} else {
@@ -37,77 +36,72 @@ export function applyCssPrefixes(target) {
3736

3837
case 'flex':
3938
target['-ms-flex'] = value;
40-
target['-webkit-flex'] = value;
4139
target['-webkit-box-flex'] = value.split(" ")[0];
42-
target['-moz-box-flex'] = value.split(" ")[0];
4340
break;
4441

4542
case 'flex-direction':
4643
value = value || "row";
47-
target['flex-direction'] = value;
44+
target['-webkit-box-orient'] = boxOrient;
45+
target['-webkit-box-direction'] = boxDirection;
4846
target['-ms-flex-direction'] = value;
49-
target['-webkit-flex-direction'] = value;
50-
target['-webkit-box-orient'] = toBoxOrient(value);
51-
target['-moz-box-orient'] = toBoxOrient(value);
52-
target['-webkit-box-direction'] = toBoxDirection(value);
53-
target['-moz-box-direction'] = toBoxDirection(value);
47+
target['flex-direction'] = value;
5448
break;
5549

5650
case 'flex-wrap':
5751
target['-ms-flex-wrap'] = value;
58-
target['-webkit-flex-wrap'] = value;
5952
break;
6053

6154
case 'flex-grow':
62-
target['-webkit-flex-grow'] = value;
55+
target['-webkit-box-flex'] = value;
56+
target['-ms-flex-positive'] = value;
6357
break;
6458

6559
case 'flex-shrink':
66-
target['-webkit-flex-shrink'] = value;
60+
target['-ms-flex-negative'] = value;
6761
break;
6862

6963
case 'flex-basis':
70-
target['-webkit-flex-basis'] = value;
64+
target['-ms-flex-preferred-size'] = value;
7165
break;
7266

7367
case 'flex-flow':
74-
target['-webkit-flex-flow'] = value;
68+
target['-ms-flex-flow'] = value;
69+
target['-webkit-box-orient'] = boxOrient;
70+
target['-webkit-box-direction'] = boxDirection;
71+
target['-ms-flex-flow'] = value;
72+
7573
break;
7674

7775
case 'order':
7876
if (isNaN(value)) {
7977
value = "0";
8078
}
81-
target['order'] = value;
82-
target['-webkit-order'] = value;
8379
target['-ms-flex-order'] = value;
84-
target['-moz-box-ordinal-group'] = toBoxOrdinal(value);
8580
target['-webkit-box-ordinal-group'] = toBoxOrdinal(value);
81+
target['order'] = value;
8682
break;
8783

8884
case 'justify-content':
89-
target['-ms-flex-pack'] = toBoxValue(value);
90-
target['-webkit-box-pack'] = toBoxValue(value);
91-
target['-moz-box-pack'] = toBoxValue(value);
92-
target['-webkit-justify-content'] = value;
85+
target['-ms-flex-pack'] = boxValue;
86+
target['-webkit-box-pack'] = boxValue;
87+
target[key] = value;
9388
break;
9489

9590
case 'align-items':
96-
target['-ms-flex-align'] = toBoxValue(value);
97-
target['-webkit-box-align'] = toBoxValue(value);
98-
target['-moz-box-align'] = toBoxValue(value);
99-
target['-webkit-align-items'] = toBoxValue(value);
91+
target['-ms-flex-align'] = boxValue;
92+
target['-webkit-box-align'] = boxValue;
93+
target[key] = value;
10094
break;
10195

10296
case 'align-self':
103-
target['-ms-flex-item-align'] = toBoxValue(value);
10497
target['-webkit-align-self'] = value;
98+
target['-ms-flex-item-align'] = boxValue;
99+
target[key] = value;
105100
break;
106101

107102
case 'align-content':
108-
target['-ms-align-content'] = toAlignContentValue(value);
109103
target['-ms-flex-line-pack'] = toAlignContentValue(value);
110-
target['-webkit-align-content'] = value;
104+
target[key] = value;
111105
break;
112106
}
113107
}
@@ -137,7 +131,6 @@ export function toBoxOrient(flexDirection = 'row') {
137131

138132
/** Convert flex Direction to Box direction type */
139133
export function toBoxDirection(flexDirection = 'row') {
140-
141134
return flexDirection.indexOf('reverse') !== -1 ? 'reverse' : 'normal';
142135
}
143136

0 commit comments

Comments
 (0)