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