forked from mui/material-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauto-prefix.js
51 lines (37 loc) · 1.37 KB
/
auto-prefix.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
const isBrowser = typeof window !== 'undefined';
const Modernizr = isBrowser ? require('../utils/modernizr.custom') : undefined;
//Keep track of already prefixed keys so we can skip Modernizr prefixing
let prefixedKeys = {};
module.exports = {
all(styles) {
let prefixedStyle = {};
for (let key in styles) {
prefixedStyle[this.single(key)] = styles[key];
}
return prefixedStyle;
},
set(style, key, value) {
style[this.single(key)] = value;
},
single(key) {
//If a browser doesn't exist, we can't prefix with Modernizr so
//just return the key
if (!isBrowser) return key;
//Check if we've prefixed this key before, just return it
if (prefixedKeys.hasOwnProperty(key)) return prefixedKeys[key];
//Key hasn't been prefixed yet, prefix with Modernizr
const prefKey = Modernizr.prefixed(key);
// Windows 7 Firefox has an issue with the implementation of Modernizr.prefixed
// and is capturing 'false' as the CSS property name instead of the non-prefixed version.
if (prefKey === false) return key;
//Save the key off for the future and return the prefixed key
prefixedKeys[key] = prefKey;
return prefKey;
},
singleHyphened(key) {
let str = this.single(key);
return !str ? key : str.replace(/([A-Z])/g, (str, m1) => {
return '-' + m1.toLowerCase();
}).replace(/^ms-/, '-ms-');
},
};