This repository has been archived by the owner on Sep 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
/
index.js
118 lines (104 loc) · 2.8 KB
/
index.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
let prefix = (function () {
if (typeof window === "undefined") {
return {};
}
var styles = window.getComputedStyle(document.documentElement, ''),
pre = (Array.prototype.slice
.call(styles)
.join('')
.match(/-(moz|webkit|ms)-/) || (styles.OLink === '' && ['', 'o'])
)[1];
return {
dom: pre === 'ms' ? 'MS' : pre,
lowercase: pre,
css: '-' + pre + '-',
js: pre === 'ms' ? pre : pre[0].toUpperCase() + pre.substr(1)
};
}());
let vendorSpecificProperties = [
'animation',
'animationDelay',
'animationDirection',
'animationDuration',
'animationFillMode',
'animationIterationCount',
'animationName',
'animationPlayState',
'animationTimingFunction',
'appearance',
'backfaceVisibility',
'backgroundClip',
'borderImage',
'borderImageSlice',
'boxSizing',
'boxShadow',
'contentColumns',
'transform',
'transformOrigin',
'transformStyle',
'transition',
'transitionDelay',
'transitionDuration',
'transitionProperty',
'transitionTimingFunction',
'perspective',
'perspectiveOrigin',
'userSelect',
];
function prefixName(name) {
return prefix.js + name[0].toUpperCase() + name.substr(1);
}
function prefixStyle(properties) {
return Object.keys(properties).reduce((previous, property) => {
if(vendorSpecificProperties.indexOf(property) !== -1) {
previous[prefixName(property)] = properties[property];
} else {
previous[property] = properties[property];
}
return previous;
}, {});
}
function flexbox(properties) {
var ua = navigator.userAgent.toLowerCase();
// polyfill for safari
let iOS = false;
if (navigator.platform) {
iOS = ['iPad', 'iPhone', 'iPod'].indexOf(navigator.platform.replace(' Simulator', '')) > -1;
}
if ((ua.indexOf('safari') !== -1 || iOS ) && ua.indexOf('chrome') === -1) {
let rename = function(obj, from, to) {
if(obj[from] !== undefined && obj[from] !== null) {
obj[to] = obj[from];
delete obj[from];
}
}
if(properties.display === 'flex') {
properties.display = '-webkit-flex';
}
['alignItems', 'justifyContent', 'flexDirection', 'flex', 'flexWrap'].forEach((prop) => {
rename(properties, prop, prefixName(prop));
});
// polyfil for IE10
} else if (navigator.appVersion.indexOf("MSIE 10") !== -1) {
if(properties.display === 'flex') {
properties.display = '-ms-flexbox';
}
// @TODO: implement 2012 flexbox syntax
}
return properties;
}
function prefixStyles(styles) {
if (typeof window === "undefined") {
return styles;
}
return Object.keys(styles).reduce((previous, current) => {
previous[current] = flexbox(prefixStyle(styles[current]));
return previous;
}, {});
};
exports.prefix = prefixStyles;
/*
* var styles = VendorPrefix.prefix({
* animation: '0.25 ease',
* });
*/