-
-
Notifications
You must be signed in to change notification settings - Fork 389
Expand file tree
/
Copy pathindex.js
More file actions
53 lines (44 loc) · 1.44 KB
/
index.js
File metadata and controls
53 lines (44 loc) · 1.44 KB
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
// @flow
import * as vendor from 'css-vendor'
import {toCssValue, type Plugin, type KeyframesRule} from 'jss'
/**
* Add vendor prefix to a property name when needed.
*
* @api public
*/
export default function jssVendorPrefixer(): Plugin {
function onProcessRule(rule) {
if (rule.type === 'keyframes') {
const atRule: KeyframesRule = (rule: any)
atRule.at = vendor.supportedKeyframes(atRule.at)
}
}
function prefixStyle(style) {
for (const prop in style) {
const value = style[prop]
if (prop === 'fallbacks' && Array.isArray(value)) {
style[prop] = value.map(prefixStyle)
continue
}
let changeProp = false
const supportedProp = vendor.supportedProperty(prop)
if (supportedProp && supportedProp !== prop) changeProp = true
let changeValue = false
const supportedValue = vendor.supportedValue(supportedProp, toCssValue(value))
if (supportedValue && supportedValue !== value) changeValue = true
if (changeProp || changeValue) {
if (changeProp) delete style[prop]
style[supportedProp || prop] = supportedValue || value
}
}
return style
}
function onProcessStyle(style, rule) {
if (rule.type !== 'style') return style
return prefixStyle(style)
}
function onChangeValue(value, prop) {
return vendor.supportedValue(prop, toCssValue(value)) || value
}
return {onProcessRule, onProcessStyle, onChangeValue}
}