mirror of
https://github.com/idanoo/GoScrobble.git
synced 2024-11-25 09:55:15 +00:00
60 lines
1.5 KiB
JavaScript
60 lines
1.5 KiB
JavaScript
|
import { supportedKeyframes, supportedValue, supportedProperty } from 'css-vendor';
|
||
|
import { toCssValue } from 'jss';
|
||
|
|
||
|
/**
|
||
|
* Add vendor prefix to a property name when needed.
|
||
|
*
|
||
|
* @api public
|
||
|
*/
|
||
|
|
||
|
function jssVendorPrefixer() {
|
||
|
function onProcessRule(rule) {
|
||
|
if (rule.type === 'keyframes') {
|
||
|
var atRule = rule;
|
||
|
atRule.at = supportedKeyframes(atRule.at);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function prefixStyle(style) {
|
||
|
for (var prop in style) {
|
||
|
var value = style[prop];
|
||
|
|
||
|
if (prop === 'fallbacks' && Array.isArray(value)) {
|
||
|
style[prop] = value.map(prefixStyle);
|
||
|
continue;
|
||
|
}
|
||
|
|
||
|
var changeProp = false;
|
||
|
var supportedProp = supportedProperty(prop);
|
||
|
if (supportedProp && supportedProp !== prop) changeProp = true;
|
||
|
var changeValue = false;
|
||
|
var supportedValue$1 = supportedValue(supportedProp, toCssValue(value));
|
||
|
if (supportedValue$1 && supportedValue$1 !== value) changeValue = true;
|
||
|
|
||
|
if (changeProp || changeValue) {
|
||
|
if (changeProp) delete style[prop];
|
||
|
style[supportedProp || prop] = supportedValue$1 || value;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return style;
|
||
|
}
|
||
|
|
||
|
function onProcessStyle(style, rule) {
|
||
|
if (rule.type !== 'style') return style;
|
||
|
return prefixStyle(style);
|
||
|
}
|
||
|
|
||
|
function onChangeValue(value, prop) {
|
||
|
return supportedValue(prop, toCssValue(value)) || value;
|
||
|
}
|
||
|
|
||
|
return {
|
||
|
onProcessRule: onProcessRule,
|
||
|
onProcessStyle: onProcessStyle,
|
||
|
onChangeValue: onChangeValue
|
||
|
};
|
||
|
}
|
||
|
|
||
|
export default jssVendorPrefixer;
|