2015-09-05 21:16:15 +03:00
|
|
|
const WEBKIT = 'Webkit';
|
|
|
|
const MICROSOFT = 'Ms';
|
|
|
|
|
|
|
|
const properties = {
|
2017-01-26 20:05:32 +03:00
|
|
|
transform: [WEBKIT, MICROSOFT],
|
2015-09-05 21:16:15 +03:00
|
|
|
};
|
|
|
|
|
2017-01-26 20:05:32 +03:00
|
|
|
function capitalize(string) {
|
2015-09-05 21:16:15 +03:00
|
|
|
return string.charAt(0).toUpperCase() + string.substr(1);
|
|
|
|
}
|
|
|
|
|
2017-01-26 20:05:32 +03:00
|
|
|
function getPrefixes(property, value) {
|
|
|
|
return properties[property].reduce((acc, item) => {
|
|
|
|
acc[`${item}${capitalize(property)}`] = value; // eslint-disable-line no-param-reassign
|
2015-09-05 21:16:15 +03:00
|
|
|
return acc;
|
|
|
|
}, {});
|
|
|
|
}
|
|
|
|
|
2017-01-26 20:05:32 +03:00
|
|
|
function addPrefixesTo(style, property, value) {
|
2015-11-05 04:14:21 +03:00
|
|
|
const vendor = getPrefixes(property, value);
|
2017-01-26 20:05:32 +03:00
|
|
|
for (const prefix in vendor) { // eslint-disable-line no-restricted-syntax
|
|
|
|
if ({}.hasOwnProperty.call(vendor, prefix)) {
|
|
|
|
style[prefix] = vendor[prefix]; // eslint-disable-line no-param-reassign
|
|
|
|
}
|
2015-11-05 04:14:21 +03:00
|
|
|
}
|
2015-09-05 21:16:15 +03:00
|
|
|
|
2015-11-05 04:14:21 +03:00
|
|
|
return style;
|
|
|
|
}
|
|
|
|
|
2017-01-26 20:05:32 +03:00
|
|
|
function prefixer(style, defaultValue = {}) {
|
2015-11-21 14:23:24 +03:00
|
|
|
const _style = defaultValue;
|
2017-01-26 20:05:32 +03:00
|
|
|
for (const property in style) { // eslint-disable-line no-restricted-syntax
|
|
|
|
if ({}.hasOwnProperty.call(style, property)) {
|
|
|
|
_style[property] = style[property];
|
|
|
|
if (properties[property]) {
|
|
|
|
addPrefixesTo(_style, property, style[property]);
|
|
|
|
}
|
2015-09-05 21:16:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return _style;
|
|
|
|
}
|
|
|
|
|
2015-11-21 16:26:17 +03:00
|
|
|
export default prefixer;
|