source: imaps-frontend/node_modules/inline-style-prefixer/es/generator/generatePrefixMap.js

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 2.1 KB
Line 
1import { getSupport } from 'caniuse-api';
2
3import propertyMap from './maps/propertyMap';
4
5var 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
21function 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
31export 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}
Note: See TracBrowser for help on using the repository browser.