1use core::fmt;
11
12use crate::data_type::CssString;
13use crate::to_css::{write_number, ToCss};
14
15#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
17pub enum AnimationDirection {
18 Normal,
20 Reverse,
22 Alternate,
24 AlternateReverse,
26}
27
28impl ToCss for AnimationDirection {
29 fn to_css(&self, dest: &mut dyn fmt::Write) -> fmt::Result {
30 dest.write_str(match self {
31 AnimationDirection::Normal => "normal",
32 AnimationDirection::Reverse => "reverse",
33 AnimationDirection::Alternate => "alternate",
34 AnimationDirection::AlternateReverse => "alternate-reverse",
35 })
36 }
37}
38
39#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
42pub enum AnimationFillMode {
43 None,
45 Forwards,
48 Backwards,
51 Both,
53}
54
55impl ToCss for AnimationFillMode {
56 fn to_css(&self, dest: &mut dyn fmt::Write) -> fmt::Result {
57 dest.write_str(match self {
58 AnimationFillMode::None => "none",
59 AnimationFillMode::Forwards => "forwards",
60 AnimationFillMode::Backwards => "backwards",
61 AnimationFillMode::Both => "both",
62 })
63 }
64}
65
66#[derive(Copy, Clone, Debug, PartialEq)]
69pub enum AnimationIterationCount {
70 Infinite,
72 Count(f32),
74}
75
76impl ToCss for AnimationIterationCount {
77 fn to_css(&self, dest: &mut dyn fmt::Write) -> fmt::Result {
78 match self {
79 AnimationIterationCount::Infinite => dest.write_str("infinite"),
80 AnimationIterationCount::Count(n) => write_number(dest, *n),
81 }
82 }
83}
84
85#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
87pub enum AnimationPlayState {
88 Running,
90 Paused,
92}
93
94impl ToCss for AnimationPlayState {
95 fn to_css(&self, dest: &mut dyn fmt::Write) -> fmt::Result {
96 dest.write_str(match self {
97 AnimationPlayState::Running => "running",
98 AnimationPlayState::Paused => "paused",
99 })
100 }
101}
102
103#[derive(Clone, Debug, PartialEq, Eq, Hash)]
106pub enum TransitionPropertyKind {
107 All,
109 None,
111 Name(CssString),
113}
114
115impl TransitionPropertyKind {
116 pub fn name(s: impl Into<String>) -> Self {
118 Self::Name(CssString::new(s))
119 }
120}
121
122impl ToCss for TransitionPropertyKind {
123 fn to_css(&self, dest: &mut dyn fmt::Write) -> fmt::Result {
124 match self {
125 TransitionPropertyKind::All => dest.write_str("all"),
126 TransitionPropertyKind::None => dest.write_str("none"),
127 TransitionPropertyKind::Name(n) => dest.write_str(n.as_str()),
130 }
131 }
132}
133
134#[cfg(test)]
135mod tests {
136 use super::*;
137
138 #[test]
139 fn animation_direction_all() {
140 let cases = [
141 (AnimationDirection::Normal, "normal"),
142 (AnimationDirection::Reverse, "reverse"),
143 (AnimationDirection::Alternate, "alternate"),
144 (AnimationDirection::AlternateReverse, "alternate-reverse"),
145 ];
146 for (k, expected) in cases {
147 assert_eq!(k.to_css_string(), expected);
148 }
149 }
150
151 #[test]
152 fn animation_fill_mode_all() {
153 let cases = [
154 (AnimationFillMode::None, "none"),
155 (AnimationFillMode::Forwards, "forwards"),
156 (AnimationFillMode::Backwards, "backwards"),
157 (AnimationFillMode::Both, "both"),
158 ];
159 for (k, expected) in cases {
160 assert_eq!(k.to_css_string(), expected);
161 }
162 }
163
164 #[test]
165 fn iteration_count_keyword() {
166 assert_eq!(
167 AnimationIterationCount::Infinite.to_css_string(),
168 "infinite"
169 );
170 }
171
172 #[test]
173 fn iteration_count_number() {
174 assert_eq!(AnimationIterationCount::Count(2.0).to_css_string(), "2");
175 assert_eq!(AnimationIterationCount::Count(0.5).to_css_string(), "0.5");
176 }
177
178 #[test]
179 fn play_state_all() {
180 assert_eq!(AnimationPlayState::Running.to_css_string(), "running");
181 assert_eq!(AnimationPlayState::Paused.to_css_string(), "paused");
182 }
183
184 #[test]
185 fn transition_property_all() {
186 assert_eq!(TransitionPropertyKind::All.to_css_string(), "all");
187 assert_eq!(TransitionPropertyKind::None.to_css_string(), "none");
188 assert_eq!(
189 TransitionPropertyKind::name("opacity").to_css_string(),
190 "opacity"
191 );
192 }
193}