1 | 'use strict';
|
---|
2 |
|
---|
3 | Object.defineProperty(exports, "__esModule", {
|
---|
4 | value: true
|
---|
5 | });
|
---|
6 | exports.default = generatePrefixMap;
|
---|
7 |
|
---|
8 | var _caniuseApi = require('caniuse-api');
|
---|
9 |
|
---|
10 | var _propertyMap = require('./maps/propertyMap');
|
---|
11 |
|
---|
12 | var _propertyMap2 = _interopRequireDefault(_propertyMap);
|
---|
13 |
|
---|
14 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
---|
15 |
|
---|
16 | var prefixBrowserMap = {
|
---|
17 | chrome: 'Webkit',
|
---|
18 | safari: 'Webkit',
|
---|
19 | firefox: 'Moz',
|
---|
20 | opera: 'Webkit',
|
---|
21 | ie: 'ms',
|
---|
22 | edge: 'ms',
|
---|
23 | ios_saf: 'Webkit',
|
---|
24 | android: 'Webkit',
|
---|
25 | and_chr: 'Webkit',
|
---|
26 | and_uc: 'Webkit',
|
---|
27 | op_mini: 'Webkit'
|
---|
28 |
|
---|
29 | // remove flexprops from IE
|
---|
30 | };var flexPropsIE = ['alignContent', 'alignSelf', 'alignItems', 'justifyContent', 'order', 'flexGrow', 'flexShrink', 'flexBasis'];
|
---|
31 |
|
---|
32 | function filterAndRemoveIfEmpty(map, property, filter) {
|
---|
33 | if (map[property]) {
|
---|
34 | map[property] = map[property].filter(filter);
|
---|
35 |
|
---|
36 | if (map[property].length === 0) {
|
---|
37 | delete map[property];
|
---|
38 | }
|
---|
39 | }
|
---|
40 | }
|
---|
41 |
|
---|
42 | function generatePrefixMap(browserList) {
|
---|
43 | var prefixMap = {};
|
---|
44 |
|
---|
45 | for (var browser in prefixBrowserMap) {
|
---|
46 | var prefix = prefixBrowserMap[browser];
|
---|
47 |
|
---|
48 | for (var keyword in _propertyMap2.default) {
|
---|
49 | var keywordProperties = [].concat(_propertyMap2.default[keyword]);
|
---|
50 | var versions = (0, _caniuseApi.getSupport)(keyword);
|
---|
51 |
|
---|
52 | for (var i = 0, len = keywordProperties.length; i < len; ++i) {
|
---|
53 | if (versions[browser]) {
|
---|
54 | if (versions[browser].x >= browserList[browser]) {
|
---|
55 | var property = keywordProperties[i];
|
---|
56 |
|
---|
57 | if (!prefixMap[property]) {
|
---|
58 | prefixMap[property] = [];
|
---|
59 | }
|
---|
60 |
|
---|
61 | if (prefixMap[property].indexOf(prefix) === -1) {
|
---|
62 | prefixMap[property].push(prefix);
|
---|
63 | }
|
---|
64 | }
|
---|
65 | }
|
---|
66 | }
|
---|
67 | }
|
---|
68 | }
|
---|
69 |
|
---|
70 | // remove flexProps from IE and Firefox due to alternative syntax
|
---|
71 | for (var _i = 0, _len = flexPropsIE.length; _i < _len; ++_i) {
|
---|
72 | filterAndRemoveIfEmpty(prefixMap, flexPropsIE[_i], function (prefix) {
|
---|
73 | return prefix !== 'ms' && prefix !== 'Moz';
|
---|
74 | });
|
---|
75 | }
|
---|
76 |
|
---|
77 | // remove transition from Moz and Webkit as they are handled
|
---|
78 | // specially by the transition plugins
|
---|
79 | filterAndRemoveIfEmpty(prefixMap, 'transition', function (prefix) {
|
---|
80 | return prefix !== 'Moz' && prefix !== 'Webkit';
|
---|
81 | });
|
---|
82 |
|
---|
83 | // remove WebkitFlexDirection as it does not exist
|
---|
84 | filterAndRemoveIfEmpty(prefixMap, 'flexDirection', function (prefix) {
|
---|
85 | return prefix !== 'Moz';
|
---|
86 | });
|
---|
87 |
|
---|
88 | return prefixMap;
|
---|
89 | } |
---|