encre_css/plugins/transition/
mod.rs

1//! Transition and animation utilities
2pub mod animation;
3pub mod transition_delay;
4pub mod transition_duration;
5pub mod transition_property;
6pub mod transition_timing_function;
7
8#[cfg(test)]
9mod tests {
10    use crate::{generate, utils::testing::base_config};
11
12    use pretty_assertions::assert_eq;
13
14    #[test]
15    fn animation() {
16        assert_eq!(
17            generate(["animate-none"], &base_config()),
18            ".animate-none {
19  -webkit-animation: none;
20  animation: none;
21}"
22        );
23        assert_eq!(
24            generate(["animate-spin"], &base_config()),
25            "@-webkit-keyframes spin {
26  to {
27    transform: rotate(360deg);
28  }
29}
30
31@keyframes spin {
32  from {
33    transform: rotate(0deg);
34  }
35  to {
36    transform: rotate(360deg);
37  }
38}
39
40.animate-spin {
41  -webkit-animation: spin 1s linear infinite;
42  animation: spin 1s linear infinite;
43}"
44        );
45        assert_eq!(
46            generate(["animate-ping"], &base_config()),
47            "@-webkit-keyframes ping {
48  75%, 100% {
49    transform: scale(2);
50    opacity: 0;
51  }
52}
53
54@keyframes ping {
55  75%, 100% {
56    transform: scale(2);
57    opacity: 0;
58  }
59}
60
61.animate-ping {
62  -webkit-animation: ping 1s cubic-bezier(0, 0, 0.2, 1) infinite;
63  animation: ping 1s cubic-bezier(0, 0, 0.2, 1) infinite;
64}"
65        );
66        assert_eq!(
67            generate(["animate-pulse"], &base_config()),
68            "@-webkit-keyframes pulse {
69  50% {
70    opacity: .5;
71  }
72}
73
74@keyframes pulse {
75  0%, 100% {
76    opacity: 1;
77  }
78  50% {
79    opacity: .5;
80  }
81}
82
83.animate-pulse {
84  -webkit-animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
85  animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
86}"
87        );
88        assert_eq!(
89            generate(["animate-bounce"], &base_config()),
90            "@-webkit-keyframes bounce {
91  0%, 100% {
92    transform: translateY(-25%);
93    -webkit-animation-timing-function: cubic-bezier(0.8,0,1,1);
94    animation-timing-function: cubic-bezier(0.8,0,1,1);
95  }
96
97  50% {
98    transform: none;
99    -webkit-animation-timing-function: cubic-bezier(0,0,0.2,1);
100    animation-timing-function: cubic-bezier(0,0,0.2,1);
101  }
102}
103
104@keyframes bounce {
105  0%, 100% {
106    transform: translateY(-25%);
107    -webkit-animation-timing-function: cubic-bezier(0.8,0,1,1);
108    animation-timing-function: cubic-bezier(0.8, 0, 1, 1);
109  }
110  50% {
111    transform: translateY(0);
112    -webkit-animation-timing-function: cubic-bezier(0,0,0.2,1);
113    animation-timing-function: cubic-bezier(0, 0, 0.2, 1);
114  }
115}
116
117.animate-bounce {
118  -webkit-animation: bounce 1s infinite;
119  animation: bounce 1s infinite;
120}"
121        );
122    }
123
124    #[test]
125    fn transition_delay() {
126        assert_eq!(
127            generate(["delay-12"], &base_config()),
128            ".delay-12 {
129  transition-delay: 12ms;
130}"
131        );
132        assert_eq!(
133            generate(["delay-[4.3ms]"], &base_config()),
134            r".delay-\[4\.3ms\] {
135  transition-delay: 4.3ms;
136}"
137        );
138    }
139
140    #[test]
141    fn transition_duration() {
142        assert_eq!(
143            generate(["duration-12"], &base_config()),
144            ".duration-12 {
145  transition-duration: 12ms;
146}"
147        );
148        assert_eq!(
149            generate(["duration-[4.3ms]"], &base_config()),
150            r".duration-\[4\.3ms\] {
151  transition-duration: 4.3ms;
152}"
153        );
154    }
155
156    #[test]
157    fn transition_property() {
158        assert_eq!(
159            generate(["transition"], &base_config()),
160            ".transition {
161  transition-property: color, background-color, border-color, text-decoration-color, fill, stroke, opacity, box-shadow, transform, filter, backdrop-filter;
162  transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
163  transition-duration: 150ms;
164}"
165        );
166        assert_eq!(
167            generate(["transition-none"], &base_config()),
168            ".transition-none {
169  transition-property: none;
170}"
171        );
172        assert_eq!(
173            generate(["transition-all"], &base_config()),
174            ".transition-all {
175  transition-property: all;
176  transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
177  transition-duration: 150ms;
178}"
179        );
180        assert_eq!(
181            generate(["transition-colors"], &base_config()),
182            ".transition-colors {
183  transition-property: color, background-color, border-color, text-decoration-color, fill, stroke;
184  transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
185  transition-duration: 150ms;
186}"
187        );
188        assert_eq!(
189            generate(["transition-opacity"], &base_config()),
190            ".transition-opacity {
191  transition-property: opacity;
192  transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
193  transition-duration: 150ms;
194}"
195        );
196        assert_eq!(
197            generate(["transition-shadow"], &base_config()),
198            ".transition-shadow {
199  transition-property: box-shadow;
200  transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
201  transition-duration: 150ms;
202}"
203        );
204        assert_eq!(
205            generate(["transition-transform"], &base_config()),
206            ".transition-transform {
207  transition-property: transform;
208  transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
209  transition-duration: 150ms;
210}"
211        );
212        assert_eq!(
213            generate(["transition-[custom]"], &base_config()),
214            r".transition-\[custom\] {
215  transition-property: custom;
216}"
217        );
218    }
219
220    #[test]
221    fn transition_timing_function() {
222        assert_eq!(
223            generate(["ease-linear"], &base_config()),
224            ".ease-linear {
225  transition-timing-function: linear;
226}"
227        );
228        assert_eq!(
229            generate(["ease-in"], &base_config()),
230            ".ease-in {
231  transition-timing-function: cubic-bezier(0.4, 0, 1, 1);
232}"
233        );
234        assert_eq!(
235            generate(["ease-out"], &base_config()),
236            ".ease-out {
237  transition-timing-function: cubic-bezier(0, 0, 0.2, 1);
238}"
239        );
240        assert_eq!(
241            generate(["ease-in-out"], &base_config()),
242            ".ease-in-out {
243  transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
244}"
245        );
246        assert_eq!(
247            generate(["ease-[steps(4,_jump-end)]"], &base_config()),
248            r".ease-\[steps\(4\,_jump-end\)\] {
249  transition-timing-function: steps(4, jump-end);
250}"
251        );
252    }
253}