Support keyframes in JS theme config#14594
Conversation
| @keyframes enter { | ||
| from { | ||
| opacity: var(--tw-enter-opacity, 1); | ||
| transform: translate3d(var(--tw-enter-translate-x, 0), var(--tw-enter-translate-y, 0), 0) scale3d(var(--tw-enter-scale, 1), var(--tw-enter-scale, 1), var(--tw-enter-scale, 1)) rotate(var(--tw-enter-rotate, 0)); | ||
| } | ||
| } | ||
| @keyframes exit { | ||
| to { | ||
| opacity: var(--tw-exit-opacity, 1); | ||
| transform: translate3d(var(--tw-exit-translate-x, 0), var(--tw-exit-translate-y, 0), 0) scale3d(var(--tw-exit-scale, 1), var(--tw-exit-scale, 1), var(--tw-exit-scale, 1)) rotate(var(--tw-exit-rotate, 0)); | ||
| } | ||
| } |
There was a problem hiding this comment.
Uh oh wait what.
There was a problem hiding this comment.
This is interesting, in v3, plugins require an addBase to add the keyframes but if it was part of the JS config theme, it would be added automatically. That's lovely:
https://play.tailwindcss.com/YQLQchsWWW?file=config
There was a problem hiding this comment.
In v3 the way this worked was keyframes were not emitted until used. So you had to do @keyframes …: theme('keyframes.whatever`) in your utility function. And we handle that already.
There was a problem hiding this comment.
Or we do in addUtilities at least. I don't think we do in matchUtilities which we should I think.
There was a problem hiding this comment.
Or at least I'm like 95% sure it works that way. Maybe we just de-duped them…
There was a problem hiding this comment.
Oh gotch you're right they're only added when used! If you use addBase and use it with an animate-* variable, it is emitted twice in v3 (at the end of the stylesheet).
I guess it's fine if we always emit keyframes for compat now (we do this for v4 keyframes too!). However unsure if we should then guard against this case. Maybe it's ok if the keyframes are emitted twice here since it does no harm? WDYT?
There was a problem hiding this comment.
yeah it's probably fine — would be nice to dedupe them but that can be an optimization done later. They should still be de-duped when minifying with lightingcss.
Adds support for defining
keyframesvia the v3 JS config file. E.g.: