/
animation.js
41 lines (36 loc) · 1.15 KB
/
animation.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
import parseAnimationValue from '../util/parseAnimationValue'
export default function () {
return function ({ matchUtilities, theme, variants, prefix }) {
let prefixName = (name) => prefix(`.${name}`).slice(1)
let keyframes = Object.fromEntries(
Object.entries(theme('keyframes')).map(([key, value]) => {
return [
key,
[
{
[`@keyframes ${prefixName(key)}`]: value,
},
{ respectVariants: false },
],
]
})
)
matchUtilities(
{
animate: (value, { includeRules }) => {
let { name: animationName } = parseAnimationValue(value)
if (keyframes[animationName] !== undefined) {
includeRules(keyframes[animationName], { respectImportant: false })
}
if (animationName === undefined || keyframes[animationName] === undefined) {
return { animation: value }
}
return {
animation: value.replace(animationName, prefixName(animationName)),
}
},
},
{ values: theme('animation'), variants: variants('animation') }
)
}
}