1use crate::{CssBorder, CssColor, CssFontFamily, CssFontStyle, CssNumber};
2use std::fmt;
3use std::fmt::Display;
4
5#[derive(Debug, Clone)]
6pub enum CssValue {
7 Avoid,
8 Block,
9 Border(CssBorder),
10 Center,
11 Color(CssColor),
12 Column,
13 Flex,
14 FlexStart,
15 FontFamily(CssFontFamily),
16 FontStyle(CssFontStyle),
17 Grid,
18 Hidden,
19 InlineBlock,
20 Integer(i64),
21 Left,
22 None,
23 Num1(CssNumber),
24 Num2(CssNumber, CssNumber),
25 Num3(CssNumber, CssNumber, CssNumber),
26 Num4(CssNumber, CssNumber, CssNumber, CssNumber),
27 Relative,
28 Right,
29 Row,
30 Start,
31 Unset,
32 Zero,
33}
34
35impl Display for CssValue {
36 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
37 write!(
38 f,
39 "{}",
40 match self {
41 CssValue::Avoid => "avoid".to_string(),
42 CssValue::Block => "block".to_string(),
43 CssValue::Border(border) => border.to_string(),
44 CssValue::Center => "center".to_string(),
45 CssValue::Color(color) => color.to_string(),
46 CssValue::Column => "column".to_string(),
47 CssValue::Flex => "flex".to_string(),
48 CssValue::FlexStart => "flex-start".to_string(),
49 CssValue::FontFamily(family) => family.to_string(),
50 CssValue::FontStyle(style) => style.to_string(),
51 CssValue::Grid => "grid".to_string(),
52 CssValue::Hidden => "hidden".to_string(),
53 CssValue::InlineBlock => "inline-block".to_string(),
54 CssValue::Integer(value) => format!("{}", value),
55 CssValue::Left => "left".to_string(),
56 CssValue::None => "none".to_string(),
57 CssValue::Num1(n1) => n1.to_string(),
58 CssValue::Num2(n1, n2) => format!("{} {}", n1, n2),
59 CssValue::Num3(n1, n2, n3) => format!("{} {} {}", n1, n2, n3),
60 CssValue::Num4(n1, n2, n3, n4) => format!("{} {} {} {}", n1, n2, n3, n4),
61 CssValue::Relative => "relative".to_string(),
62 CssValue::Right => "right".to_string(),
63 CssValue::Row => "row".to_string(),
64 CssValue::Start => "start".to_string(),
65 CssValue::Unset => "unset".to_string(),
66 CssValue::Zero => "0".to_string(),
67 }
68 )
69 }
70}
71
72impl From<CssBorder> for CssValue {
73 fn from(value: CssBorder) -> Self {
74 CssValue::Border(value)
75 }
76}
77
78impl From<CssColor> for CssValue {
79 fn from(value: CssColor) -> Self {
80 CssValue::Color(value)
81 }
82}
83
84impl From<CssFontFamily> for CssValue {
85 fn from(value: CssFontFamily) -> Self {
86 CssValue::FontFamily(value)
87 }
88}
89
90impl From<CssFontStyle> for CssValue {
91 fn from(value: CssFontStyle) -> Self {
92 CssValue::FontStyle(value)
93 }
94}
95
96impl From<CssNumber> for CssValue {
97 fn from(value: CssNumber) -> Self {
98 CssValue::Num1(value)
99 }
100}
101
102impl From<(CssNumber, CssNumber)> for CssValue {
103 fn from((n1, n2): (CssNumber, CssNumber)) -> Self {
104 CssValue::Num2(n1, n2)
105 }
106}
107
108impl From<(CssNumber, CssNumber, CssNumber)> for CssValue {
109 fn from((n1, n2, n3): (CssNumber, CssNumber, CssNumber)) -> Self {
110 CssValue::Num3(n1, n2, n3)
111 }
112}
113
114impl From<(CssNumber, CssNumber, CssNumber, CssNumber)> for CssValue {
115 fn from((n1, n2, n3, n4): (CssNumber, CssNumber, CssNumber, CssNumber)) -> Self {
116 CssValue::Num4(n1, n2, n3, n4)
117 }
118}
119
120impl From<u8> for CssValue {
121 fn from(value: u8) -> Self {
122 CssValue::Integer(value as i64)
123 }
124}
125
126impl From<i8> for CssValue {
127 fn from(value: i8) -> Self {
128 CssValue::Integer(value as i64)
129 }
130}
131
132impl From<u16> for CssValue {
133 fn from(value: u16) -> Self {
134 CssValue::Integer(value as i64)
135 }
136}
137
138impl From<i16> for CssValue {
139 fn from(value: i16) -> Self {
140 CssValue::Integer(value as i64)
141 }
142}
143
144impl From<u32> for CssValue {
145 fn from(value: u32) -> Self {
146 CssValue::Integer(value as i64)
147 }
148}
149
150impl From<i32> for CssValue {
151 fn from(value: i32) -> Self {
152 CssValue::Integer(value as i64)
153 }
154}
155
156impl From<u64> for CssValue {
157 fn from(value: u64) -> Self {
158 CssValue::Integer(value as i64)
159 }
160}
161
162impl From<i64> for CssValue {
163 fn from(value: i64) -> Self {
164 CssValue::Integer(value)
165 }
166}