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

Commit bc0c900

Browse files
ThomasBurlesontinayuangao
authored andcommitted
fix(auto-prefixer): resolve perf impacts as reported by LightHouse (#283)
* Updated based on output from https://autoprefixer.github.io/ * Removed Mozilla Firefox prefixes as not required for the evergreen browser * Remove support for IE10 prefixes (`-ms-`); as only IE 11 and Edge are supported * Remove support for `-webkit-box` required for OLD iOS , Safari 3, BB7 * Fix value transforms for flex-related keys Fixes #282
1 parent f5558de commit bc0c900

File tree

3 files changed

+73
-188
lines changed

3 files changed

+73
-188
lines changed

src/lib/flexbox/api/flex.spec.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ describe('flex directive', () => {
305305
`)
306306
.not.toHaveCssStyle({
307307
'flex-direction': 'row',
308+
'flex': '1 1 100%',
308309
'max-height': '37%',
309310
});
310311
});
@@ -318,18 +319,21 @@ describe('flex directive', () => {
318319

319320
expectDomForQuery(template, "[fxFlex]")
320321
.toHaveCssStyle({
322+
'flex': '1 1 100%',
321323
'max-height': '37%',
322324
});
323325
});
324326

325327
it('should set max-width for `fxFlex="<%val>"`', () => {
326328
expectDOMFrom(`<div fxFlex="37%"></div>`).toHaveCssStyle({
329+
'flex': '1 1 100%',
327330
'max-width': '37%',
328331
});
329332
});
330333

331334
it('should set max-width for `fxFlex="2%"` usage', () => {
332335
expectDOMFrom(`<div fxFlex="2%"></div>`).toHaveCssStyle({
336+
'flex': '1 1 100%',
333337
'max-width': '2%',
334338
});
335339
});
@@ -351,15 +355,15 @@ describe('flex directive', () => {
351355
fixture.detectChanges();
352356

353357
expectNativeEl(fixture).toHaveCssStyle({
354-
'flex': '1 1 50%',
358+
'flex': '1 1 100%',
355359
'max-width': '50%'
356360
});
357361

358362
matchMedia.activate('sm', true);
359363
fixture.detectChanges();
360364

361365
expectNativeEl(fixture).toHaveCssStyle({
362-
'flex': '1 1 33%',
366+
'flex': '1 1 100%',
363367
'max-width': '33%'
364368
});
365369
});

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

Lines changed: 42 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,14 @@ describe('auto-prefixer for ', () => {
2525
it('should apply prefixes for display', () => {
2626
let input = {"display": "flex"};
2727
let actual = applyCssPrefixes(input);
28+
2829
expect(Array.isArray(actual['display'])).toBeTruthy();
29-
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'][0]).toEqual('-webkit-flex');
33+
expect(actual['display'][1]).toEqual('flex');
3134
});
35+
3236
});
3337

3438
/**
@@ -39,8 +43,7 @@ describe('auto-prefixer for ', () => {
3943
it('should apply prefixes for single values', () => {
4044
let input = {"flex": "100"};
4145
let expected = extendObject({}, input, {
42-
'-ms-flex': "100",
43-
'-webkit-box-flex': "100"
46+
'-webkit-flex': "100"
4447
});
4548
let actual = applyCssPrefixes(input);
4649
checkCssPrefix("flex", actual, expected);
@@ -49,8 +52,7 @@ describe('auto-prefixer for ', () => {
4952
it('should apply prefixes for multiple values', () => {
5053
let input = {"flex": "2 1 50%"};
5154
let expected = extendObject({}, input, {
52-
'-ms-flex': "2 1 50%",
53-
'-webkit-box-flex': "2"
55+
'-webkit-flex': "2 1 50%"
5456
});
5557
let actual = applyCssPrefixes(input);
5658
checkCssPrefix("flex", actual, expected);
@@ -66,9 +68,7 @@ describe('auto-prefixer for ', () => {
6668
it('should apply prefixes for value == "row"', () => {
6769
let input = {"flex-direction": "row"};
6870
let expected = extendObject({}, input, {
69-
'-ms-flex-direction': "row",
70-
'-webkit-box-orient': "horizontal",
71-
'-webkit-box-direction': "normal"
71+
'-webkit-flex-direction': "row"
7272
});
7373
let actual = applyCssPrefixes(input);
7474
checkCssPrefix("flex-direction", actual, expected);
@@ -77,9 +77,7 @@ describe('auto-prefixer for ', () => {
7777
it('should apply prefixes for value == "row-reverse"', () => {
7878
let input = {"flex-direction": "row-reverse"};
7979
let expected = extendObject({}, input, {
80-
'-ms-flex-direction': "row-reverse",
81-
'-webkit-box-orient': "horizontal",
82-
'-webkit-box-direction': "reverse"
80+
'-webkit-flex-direction': "row-reverse"
8381
});
8482
let actual = applyCssPrefixes(input);
8583
checkCssPrefix("flex-direction", actual, expected);
@@ -88,9 +86,7 @@ describe('auto-prefixer for ', () => {
8886
it('should apply prefixes for value == "column"', () => {
8987
let input = {"flex-direction": "column"};
9088
let expected = extendObject({}, input, {
91-
'-ms-flex-direction': "column",
92-
'-webkit-box-orient': "vertical",
93-
'-webkit-box-direction': "normal"
89+
'-webkit-flex-direction': "column"
9490
});
9591
let actual = applyCssPrefixes(input);
9692
checkCssPrefix("flex-direction", actual, expected);
@@ -99,9 +95,7 @@ describe('auto-prefixer for ', () => {
9995
it('should apply prefixes for value == "column-reverse"', () => {
10096
let input = {"flex-direction": "column-reverse"};
10197
let expected = extendObject({}, input, {
102-
'-ms-flex-direction': "column-reverse",
103-
'-webkit-box-orient': "vertical",
104-
'-webkit-box-direction': "reverse"
98+
'-webkit-flex-direction': "column-reverse"
10599
});
106100
let actual = applyCssPrefixes(input);
107101
checkCssPrefix("flex-direction", actual, expected);
@@ -117,7 +111,7 @@ describe('auto-prefixer for ', () => {
117111
it('should apply a prefix', () => {
118112
let input = {"flex-wrap": "nowrap"};
119113
let expected = extendObject({}, input, {
120-
"-ms-flex-wrap": "nowrap"
114+
'-webkit-flex-wrap' : 'nowrap'
121115
});
122116
let actual = applyCssPrefixes(input);
123117
checkCssPrefix("flex-wrap", actual, expected);
@@ -132,8 +126,7 @@ describe('auto-prefixer for ', () => {
132126
it('should apply a prefix', () => {
133127
let input = {"order": "1"};
134128
let expected = extendObject({}, input, {
135-
"-ms-flex-order": "1",
136-
"-webkit-box-ordinal-group": "2"
129+
'-webkit-order' : '1'
137130
});
138131
let actual = applyCssPrefixes(input);
139132
checkCssPrefix("order", actual, expected);
@@ -143,8 +136,7 @@ describe('auto-prefixer for ', () => {
143136
let input = {"order": "invalid"};
144137
let expected = extendObject({}, input, {
145138
"order": "0",
146-
"-ms-flex-order": "0",
147-
"-webkit-box-ordinal-group": "1"
139+
'-webkit-order' : "0"
148140
});
149141
let actual = applyCssPrefixes(input);
150142
checkCssPrefix("order", actual, expected);
@@ -161,8 +153,7 @@ describe('auto-prefixer for ', () => {
161153
it('should apply a prefix', () => {
162154
let input = {"justify-content": "flex-start"};
163155
let expected = extendObject({}, input, {
164-
"-ms-flex-pack": "start",
165-
"-webkit-box-pack": "start"
156+
"-webkit-justify-content": "flex-start"
166157
});
167158
let actual = applyCssPrefixes(input);
168159
checkCssPrefix("justify-content", actual, expected);
@@ -171,8 +162,7 @@ describe('auto-prefixer for ', () => {
171162
it('should apply a prefix', () => {
172163
let input = {"justify-content": "flex-end"};
173164
let expected = extendObject({}, input, {
174-
"-ms-flex-pack": "end",
175-
"-webkit-box-pack": "end"
165+
"-webkit-justify-content": "flex-end"
176166
});
177167
let actual = applyCssPrefixes(input);
178168
checkCssPrefix("justify-content", actual, expected);
@@ -181,8 +171,7 @@ describe('auto-prefixer for ', () => {
181171
it('should apply a prefix', () => {
182172
let input = {"justify-content": "center"};
183173
let expected = extendObject({}, input, {
184-
"-ms-flex-pack": "center",
185-
"-webkit-box-pack": "center"
174+
"-webkit-justify-content": "center"
186175
});
187176
let actual = applyCssPrefixes(input);
188177
checkCssPrefix("justify-content", actual, expected);
@@ -197,8 +186,7 @@ describe('auto-prefixer for ', () => {
197186
it('should apply a prefix', () => {
198187
let input = {"align-items": "flex-start"};
199188
let expected = extendObject({}, input, {
200-
"-ms-flex-align": "start",
201-
"-webkit-box-align": "start"
189+
"-webkit-align-items": "flex-start"
202190
});
203191
let actual = applyCssPrefixes(input);
204192
checkCssPrefix("align-items", actual, expected);
@@ -207,8 +195,7 @@ describe('auto-prefixer for ', () => {
207195
it('should apply a prefix', () => {
208196
let input = {"align-items": "flex-end"};
209197
let expected = extendObject({}, input, {
210-
"-ms-flex-align": "end",
211-
"-webkit-box-align": "end"
198+
"-webkit-align-items": "flex-end"
212199
});
213200
let actual = applyCssPrefixes(input);
214201
checkCssPrefix("align-items", actual, expected);
@@ -217,8 +204,7 @@ describe('auto-prefixer for ', () => {
217204
it('should apply a prefix', () => {
218205
let input = {"align-items": "center"};
219206
let expected = extendObject({}, input, {
220-
"-ms-flex-align": "center",
221-
"-webkit-box-align": "center"
207+
"-webkit-align-items": "center"
222208
});
223209
let actual = applyCssPrefixes(input);
224210
checkCssPrefix("align-items", actual, expected);
@@ -236,7 +222,7 @@ describe('auto-prefixer for ', () => {
236222
it('should apply a prefix', () => {
237223
let input = {"align-self": "flex-start"};
238224
let expected = extendObject({}, input, {
239-
"-ms-flex-item-align": "start"
225+
'-webkit-align-self' : 'flex-start'
240226
});
241227
let actual = applyCssPrefixes(input);
242228
checkCssPrefix("align-self", actual, expected);
@@ -245,7 +231,7 @@ describe('auto-prefixer for ', () => {
245231
it('should apply a prefix', () => {
246232
let input = {"align-self": "flex-end"};
247233
let expected = extendObject({}, input, {
248-
"-ms-flex-item-align": "end"
234+
'-webkit-align-self' : 'flex-end'
249235
});
250236
let actual = applyCssPrefixes(input);
251237
checkCssPrefix("align-self", actual, expected);
@@ -254,7 +240,7 @@ describe('auto-prefixer for ', () => {
254240
it('should apply a prefix', () => {
255241
let input = {"align-self": "center"};
256242
let expected = extendObject({}, input, {
257-
"-ms-flex-item-align": "center"
243+
'-webkit-align-self' : 'center'
258244
});
259245
let actual = applyCssPrefixes(input);
260246
checkCssPrefix("align-self", actual, expected);
@@ -270,7 +256,7 @@ describe('auto-prefixer for ', () => {
270256
it('should apply a prefix', () => {
271257
let input = {"align-content": "flex-start"};
272258
let expected = extendObject({}, input, {
273-
"-ms-flex-line-pack": "start"
259+
'-webkit-align-content': 'flex-start'
274260
});
275261
let actual = applyCssPrefixes(input);
276262
checkCssPrefix("align-content", actual, expected);
@@ -279,7 +265,7 @@ describe('auto-prefixer for ', () => {
279265
it('should apply a prefix', () => {
280266
let input = {"align-content": "flex-end"};
281267
let expected = extendObject({}, input, {
282-
"-ms-flex-line-pack": "end"
268+
'-webkit-align-content' : 'flex-end'
283269
});
284270
let actual = applyCssPrefixes(input);
285271
checkCssPrefix("align-content", actual, expected);
@@ -288,7 +274,7 @@ describe('auto-prefixer for ', () => {
288274
it('should apply a prefix', () => {
289275
let input = {"align-content": "center"};
290276
let expected = extendObject({}, input, {
291-
"-ms-flex-line-pack": "center"
277+
'-webkit-align-content': 'center'
292278
});
293279
let actual = applyCssPrefixes(input);
294280
checkCssPrefix("align-content", actual, expected);
@@ -297,7 +283,7 @@ describe('auto-prefixer for ', () => {
297283
it('should apply a prefix', () => {
298284
let input = {"align-content": "stretch"};
299285
let expected = extendObject({}, input, {
300-
"-ms-flex-line-pack": "stretch"
286+
'-webkit-align-content': 'stretch'
301287
});
302288
let actual = applyCssPrefixes(input);
303289
checkCssPrefix("align-content", actual, expected);
@@ -310,50 +296,26 @@ describe('auto-prefixer for ', () => {
310296
/**
311297
* Internal checks to `expect().toEqual()`
312298
*/
313-
function checkCssPrefix(iKey, actual, expected) {
314-
expect(actual[iKey]).toEqual(expected[iKey]);
315-
switch (iKey) {
299+
function checkCssPrefix(key, actual, expected) {
300+
expect(actual[key]).toEqual(expected[key]);
301+
switch (key) {
316302
case 'display':
317-
expect(actual['display']).toEqual(expected[iKey]);
318-
break;
319-
case 'flex':
320-
expect(actual['-ms-flex']).toEqual(expected['-ms-flex']);
321-
expect(actual['-webkit-box-flex']).toEqual(expected['-webkit-box-flex'].split(" ")[0]);
322-
break;
323-
324-
case 'flex-direction':
325-
expect(actual['-ms-flex-direction']).toEqual(expected['-ms-flex-direction']);
326-
expect(actual['-webkit-box-orient']).toEqual(expected['-webkit-box-orient']);
327-
expect(actual['-webkit-box-direction']).toEqual(expected['-webkit-box-direction']);
328-
break;
329-
330-
case 'flex-wrap':
331-
expect(actual['-ms-flex-wrap']).toEqual(expected['-ms-flex-wrap']);
332-
break;
333-
334-
case 'order':
335-
expect(actual['-ms-flex-order']).toEqual(expected['-ms-flex-order']);
336-
expect(actual['-webkit-box-ordinal-group']).toEqual(expected['-webkit-box-ordinal-group']);
337-
break;
338-
339-
case 'justify-content':
340-
expect(actual['-ms-flex-pack']).toEqual(expected['-ms-flex-pack']);
341-
expect(actual['-webkit-box-pack']).toEqual(expected['-webkit-box-pack']);
303+
expect(actual['display']).toEqual(expected[key]);
342304
break;
343305

344306
case 'align-items':
345-
expect(actual['-ms-flex-align']).toEqual(expected['-ms-flex-align']);
346-
expect(actual['-webkit-box-align']).toEqual(expected['-webkit-box-align']);
347-
break;
348-
349307
case 'align-self':
350-
expect(actual['-ms-flex-item-align']).toEqual(expected['-ms-flex-item-align']);
351-
break;
352-
353308
case 'align-content':
354-
expect(actual['-ms-flex-line-pack']).toEqual(expected['-ms-flex-line-pack']);
309+
case 'flex':
310+
case 'flex-direction':
311+
case 'flex-wrap':
312+
case 'flex-grow':
313+
case 'flex-shrink':
314+
case 'flex-basis':
315+
case 'flex-flow':
316+
case 'justify-content':
317+
case 'order':
318+
expect(actual[key]).toEqual(expected['-webkit-' + key]);
355319
break;
356-
357-
358320
}
359321
}

0 commit comments

Comments
 (0)