forked from robinweser/inline-style-prefixer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtransition.js
More file actions
42 lines (36 loc) · 1.25 KB
/
transition.js
File metadata and controls
42 lines (36 loc) · 1.25 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
/* @flow */
import hyphenateProperty from 'css-in-js-utils/lib/hyphenateProperty'
import type { PluginMetaData } from '../../../flowtypes/PluginMetaData'
const properties = {
transition: true,
transitionProperty: true,
WebkitTransition: true,
WebkitTransitionProperty: true,
MozTransition: true,
MozTransitionProperty: true
}
let requiresPrefixDashCased: Array<string>
export default function transition(
property: string,
value: any,
style: Object,
{ cssPrefix, keepUnprefixed, requiresPrefix }: PluginMetaData
): ?Array<any> | ?any {
if (typeof value === 'string' && properties.hasOwnProperty(property)) {
// memoize the prefix array for later use
if (!requiresPrefixDashCased) {
requiresPrefixDashCased = Object.keys(requiresPrefix).map(prop => hyphenateProperty(prop))
}
// only split multi values, not cubic beziers
const multipleValues = value.split(/,(?![^()]*(?:\([^()]*\))?\))/g)
requiresPrefixDashCased.forEach((prop) => {
multipleValues.forEach((val, index) => {
if (val.indexOf(prop) > -1 && prop !== 'order') {
multipleValues[index] = val.replace(prop, cssPrefix + prop) +
(keepUnprefixed ? `,${val}` : '')
}
})
})
return multipleValues.join(',')
}
}