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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
use crate::{append_property::AppendProperty, prelude::*, Property};

crate::macros::easy_enum! {border-collapse separate collapse}
crate::macros::easy_enum! {box-decoration-break slice clone}
crate::macros::easy_enum! {outline-width medium thin thick [unit]}
crate::macros::easy_enum! {outline-style none hidden dotted dashed solid double groove ridge inset outset}
crate::macros::easy_enum! {border-image-slice fill [raw]} // TODO:
crate::macros::easy_enum! {border-image-width auto [raw]} // TODO:
crate::macros::easy_enum! {border-image-outset [raw]} // TODO:
crate::macros::easy_enum! {border-image-repeat stretch repeat round space}
crate::macros::easy_color! {outline-color}

#[derive(Debug, PartialEq, Eq, Hash, Clone, PartialOrd, Ord)]
pub enum BorderImageSource {
	None,
	Initial,
	Inherit,
	Unset,
	Some(Vec<crate::Image>),
}

impl std::fmt::Display for BorderImageSource {
	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
		match self {
			Self::None    => "border-image-source:none;".fmt(f),
			Self::Initial => "border-image-source:initial;".fmt(f),
			Self::Inherit => "border-image-source:inherit;".fmt(f),
			Self::Unset   => "border-image-source:unset;".fmt(f),
			Self::Some(images) => {
				"border-image-source:".fmt(f)?;
				if let Some((first, rest)) = images.split_first() {
					write!(f, "{}", first)?;
					for image in rest {
						write!(f, ",{}", image)?;
					}
				}
				";".fmt(f)
			},
		}
	}
}

#[rustfmt::skip]
#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy, strum::Display, PartialOrd, Ord)]
pub enum BorderStyle {
	#[strum(to_string = "none")] None,
	#[strum(to_string = "hidden")] Hidden,
	#[strum(to_string = "dotted")] Dotted,
	#[strum(to_string = "dashed")] Dashed,
	#[strum(to_string = "solid")] Solid,
	#[strum(to_string = "double")] Double,
	#[strum(to_string = "groove")] Groove,
	#[strum(to_string = "ridge")] Ridge,
	#[strum(to_string = "inset")] Inset,
	#[strum(to_string = "outset")] Outset,
	#[strum(to_string = "initial")] Initial,
	#[strum(to_string = "inherit")] Inherit,
	#[strum(to_string = "unset")] Unset,
}

#[derive(Debug, PartialEq, Eq, Hash, Clone, PartialOrd, Ord)]
pub enum BorderWidth {
	Medium,
	Thin,
	Thick,
	Some(crate::Unit),
	Initial,
	Inherit,
	Unset,
}

#[rustfmt::skip]
impl std::fmt::Display for BorderWidth {
	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
		match self {
			Self::Medium  => "medium".fmt(f),
			Self::Thin    => "thin".fmt(f),
			Self::Thick   => "thick".fmt(f),
			Self::Some(x) => x.fmt(f),
			Self::Initial => "initial".fmt(f),
			Self::Inherit => "inherit".fmt(f),
			Self::Unset   => "unset".fmt(f),
		}
	}
}

#[derive(Debug, PartialEq, Eq, Hash, Clone, Default, PartialOrd, Ord)]
pub struct BoxShadowEffect {
	pub inset: bool,
	pub offset_x: Unit,
	pub offset_y: Unit,
	pub blur_radius: Unit,
	pub spread_radius: Unit,
	pub color: crate::Color,
}

impl std::fmt::Display for BoxShadowEffect {
	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
		if self.inset { "inset ".fmt(f)? }
		write!(f, "{} {} {} {} {}", self.offset_x, self.offset_y, self.blur_radius, self.spread_radius, self.color)
	}
}

impl AppendProperty for BoxShadowEffect {
	fn append_property(self, props: &mut Vec<Property>) { BoxShadow::Some(vec![self]).append_property(props) }
}

#[derive(Debug, PartialEq, Eq, Hash, Clone, PartialOrd, Ord)]
pub enum BoxShadow {
	None,
	Initial,
	Inherit,
	Unset,
	Some(Vec<BoxShadowEffect>),
}

impl std::fmt::Display for BoxShadow {
	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
		match self {
			Self::None    => "box-shadow:none;".fmt(f),
			Self::Initial => "box-shadow:initial;".fmt(f),
			Self::Inherit => "box-shadow:inherit;".fmt(f),
			Self::Unset   => "box-shadow:unset;".fmt(f),
			Self::Some(effects) => {
				"box-shadow:".fmt(f)?;
				if let Some((first, rest)) = effects.split_first() {
					write!(f, "{}", first)?;
					for effect in rest {
						write!(f, ",{}", effect)?;
					}
				}
				";".fmt(f)
			},
		}
	}
}

#[rustfmt::skip]
#[macro_export]
#[doc(hidden)]
macro_rules! __border_width {
	($side:ident, medium)      => {$crate::paste::item!{$crate::Property::[<Border $side Width>]($crate::BorderWidth::Medium)}};
	($side:ident, thin)        => {$crate::paste::item!{$crate::Property::[<Border $side Width>]($crate::BorderWidth::Thin)}};
	($side:ident, thick)       => {$crate::paste::item!{$crate::Property::[<Border $side Width>]($crate::BorderWidth::Thick)}};
	($side:ident, initial)     => {$crate::paste::item!{$crate::Property::[<Border $side Width>]($crate::BorderWidth::Initial)}};
	($side:ident, inherit)     => {$crate::paste::item!{$crate::Property::[<Border $side Width>]($crate::BorderWidth::Inherit)}};
	($side:ident, unset)       => {$crate::paste::item!{$crate::Property::[<Border $side Width>]($crate::BorderWidth::Unset)}};
	($side:ident, $($val:tt)+) => {$crate::paste::item!{$crate::Property::[<Border $side Width>]($crate::BorderWidth::Some($crate::unit!($($val)+)))}};
}

#[macro_export] macro_rules! border_left_width {($($tt:tt)+)   => {$crate::__border_width!(Left, $($tt)+)}}
#[macro_export] macro_rules! border_right_width {($($tt:tt)+)  => {$crate::__border_width!(Right, $($tt)+)}}
#[macro_export] macro_rules! border_top_width {($($tt:tt)+)    => {$crate::__border_width!(Top, $($tt)+)}}
#[macro_export] macro_rules! border_bottom_width {($($tt:tt)+) => {$crate::__border_width!(Bottom, $($tt)+)}}
#[macro_export] macro_rules! border_width {($($tt:tt)+) => {
	vec![
		$crate::border_left_width!($($tt)+),
		$crate::border_right_width!($($tt)+),
		$crate::border_top_width!($($tt)+),
		$crate::border_bottom_width!($($tt)+),
	]
}}

#[rustfmt::skip]
#[macro_export]
#[doc(hidden)]
macro_rules! __border_style {
	($side:ident, none)    => {$crate::paste::item!{$crate::Property::[<Border $side Style>]($crate::BorderStyle::None)}};
	($side:ident, hidden)  => {$crate::paste::item!{$crate::Property::[<Border $side Style>]($crate::BorderStyle::Hidden)}};
	($side:ident, dotted)  => {$crate::paste::item!{$crate::Property::[<Border $side Style>]($crate::BorderStyle::Dotted)}};
	($side:ident, dashed)  => {$crate::paste::item!{$crate::Property::[<Border $side Style>]($crate::BorderStyle::Dashed)}};
	($side:ident, solid)   => {$crate::paste::item!{$crate::Property::[<Border $side Style>]($crate::BorderStyle::Solid)}};
	($side:ident, double)  => {$crate::paste::item!{$crate::Property::[<Border $side Style>]($crate::BorderStyle::Double)}};
	($side:ident, groove)  => {$crate::paste::item!{$crate::Property::[<Border $side Style>]($crate::BorderStyle::Groove)}};
	($side:ident, ridge)   => {$crate::paste::item!{$crate::Property::[<Border $side Style>]($crate::BorderStyle::Ridge)}};
	($side:ident, inset)   => {$crate::paste::item!{$crate::Property::[<Border $side Style>]($crate::BorderStyle::Inset)}};
	($side:ident, outset)  => {$crate::paste::item!{$crate::Property::[<Border $side Style>]($crate::BorderStyle::Outset)}};
	($side:ident, initial) => {$crate::paste::item!{$crate::Property::[<Border $side Style>]($crate::BorderStyle::Initial)}};
	($side:ident, inherit) => {$crate::paste::item!{$crate::Property::[<Border $side Style>]($crate::BorderStyle::Inherit)}};
	($side:ident, unset)   => {$crate::paste::item!{$crate::Property::[<Border $side Style>]($crate::BorderStyle::Unset)}};
}

#[macro_export] macro_rules! border_left_style {($($tt:tt)+)   => {$crate::__border_style!(Left, $($tt)+)}}
#[macro_export] macro_rules! border_right_style {($($tt:tt)+)  => {$crate::__border_style!(Right, $($tt)+)}}
#[macro_export] macro_rules! border_top_style {($($tt:tt)+)    => {$crate::__border_style!(Top, $($tt)+)}}
#[macro_export] macro_rules! border_bottom_style {($($tt:tt)+) => {$crate::__border_style!(Bottom, $($tt)+)}}
#[macro_export] macro_rules! border_style {($($tt:tt)+) => {
	vec![
		$crate::border_left_style!($($tt)+),
		$crate::border_right_style!($($tt)+),
		$crate::border_top_style!($($tt)+),
		$crate::border_bottom_style!($($tt)+),
	]
}}

crate::macros::easy_color! {border_left_color}
crate::macros::easy_color! {border_right_color}
crate::macros::easy_color! {border_top_color}
crate::macros::easy_color! {border_bottom_color}
#[macro_export] macro_rules! border_color {($($tt:tt)+) => {
	vec![
		$crate::border_left_color!($($tt)+),
		$crate::border_right_color!($($tt)+),
		$crate::border_top_color!($($tt)+),
		$crate::border_bottom_color!($($tt)+),
	]
}}

crate::macros::unit_value_macro! {border_top_left_radius BorderTopLeftRadius}
crate::macros::unit_value_macro! {border_top_right_radius BorderTopRightRadius}
crate::macros::unit_value_macro! {border_bottom_left_radius BorderBottomLeftRadius}
crate::macros::unit_value_macro! {border_bottom_right_radius BorderBottomRightRadius}
#[macro_export] macro_rules! border_radius {($($tt:tt)+) => {
	vec![
		$crate::border_top_left_radius!($($tt)+),
		$crate::border_top_right_radius!($($tt)+),
		$crate::border_bottom_left_radius!($($tt)+),
		$crate::border_bottom_right_radius!($($tt)+),
	]
}}

#[test]
fn border_width_values() {
	assert_eq!(__border_width!(Left, medium).to_string(), "border-left-width:medium;");
	assert_eq!(__border_width!(Left, thin).to_string(), "border-left-width:thin;");
	assert_eq!(__border_width!(Left, thick).to_string(), "border-left-width:thick;");
	assert_eq!(__border_width!(Left, initial).to_string(), "border-left-width:initial;");
	assert_eq!(__border_width!(Left, inherit).to_string(), "border-left-width:inherit;");
	assert_eq!(__border_width!(Left, unset).to_string(), "border-left-width:unset;");

	assert_eq!(__border_width!(Right, medium).to_string(), "border-right-width:medium;");
	assert_eq!(__border_width!(Right, thin).to_string(), "border-right-width:thin;");
	assert_eq!(__border_width!(Right, thick).to_string(), "border-right-width:thick;");
	assert_eq!(__border_width!(Right, initial).to_string(), "border-right-width:initial;");
	assert_eq!(__border_width!(Right, inherit).to_string(), "border-right-width:inherit;");
	assert_eq!(__border_width!(Right, unset).to_string(), "border-right-width:unset;");

	assert_eq!(__border_width!(Top, medium).to_string(), "border-top-width:medium;");
	assert_eq!(__border_width!(Top, thin).to_string(), "border-top-width:thin;");
	assert_eq!(__border_width!(Top, thick).to_string(), "border-top-width:thick;");
	assert_eq!(__border_width!(Top, initial).to_string(), "border-top-width:initial;");
	assert_eq!(__border_width!(Top, inherit).to_string(), "border-top-width:inherit;");
	assert_eq!(__border_width!(Top, unset).to_string(), "border-top-width:unset;");

	assert_eq!(__border_width!(Bottom, medium).to_string(), "border-bottom-width:medium;");
	assert_eq!(__border_width!(Bottom, thin).to_string(), "border-bottom-width:thin;");
	assert_eq!(__border_width!(Bottom, thick).to_string(), "border-bottom-width:thick;");
	assert_eq!(__border_width!(Bottom, initial).to_string(), "border-bottom-width:initial;");
	assert_eq!(__border_width!(Bottom, inherit).to_string(), "border-bottom-width:inherit;");
	assert_eq!(__border_width!(Bottom, unset).to_string(), "border-bottom-width:unset;");
}

#[test]
fn border_style_values() {
	assert_eq!(__border_style!(Left, none).to_string(), "border-left-style:none;");
	assert_eq!(__border_style!(Left, hidden).to_string(), "border-left-style:hidden;");
	assert_eq!(__border_style!(Left, dotted).to_string(), "border-left-style:dotted;");
	assert_eq!(__border_style!(Left, dashed).to_string(), "border-left-style:dashed;");
	assert_eq!(__border_style!(Left, solid).to_string(), "border-left-style:solid;");
	assert_eq!(__border_style!(Left, double).to_string(), "border-left-style:double;");
	assert_eq!(__border_style!(Left, groove).to_string(), "border-left-style:groove;");
	assert_eq!(__border_style!(Left, ridge).to_string(), "border-left-style:ridge;");
	assert_eq!(__border_style!(Left, inset).to_string(), "border-left-style:inset;");
	assert_eq!(__border_style!(Left, outset).to_string(), "border-left-style:outset;");
	assert_eq!(__border_style!(Left, initial).to_string(), "border-left-style:initial;");
	assert_eq!(__border_style!(Left, inherit).to_string(), "border-left-style:inherit;");
	assert_eq!(__border_style!(Left, unset).to_string(), "border-left-style:unset;");

	assert_eq!(__border_style!(Right, none).to_string(), "border-right-style:none;");
	assert_eq!(__border_style!(Right, hidden).to_string(), "border-right-style:hidden;");
	assert_eq!(__border_style!(Right, dotted).to_string(), "border-right-style:dotted;");
	assert_eq!(__border_style!(Right, dashed).to_string(), "border-right-style:dashed;");
	assert_eq!(__border_style!(Right, solid).to_string(), "border-right-style:solid;");
	assert_eq!(__border_style!(Right, double).to_string(), "border-right-style:double;");
	assert_eq!(__border_style!(Right, groove).to_string(), "border-right-style:groove;");
	assert_eq!(__border_style!(Right, ridge).to_string(), "border-right-style:ridge;");
	assert_eq!(__border_style!(Right, inset).to_string(), "border-right-style:inset;");
	assert_eq!(__border_style!(Right, outset).to_string(), "border-right-style:outset;");
	assert_eq!(__border_style!(Right, initial).to_string(), "border-right-style:initial;");
	assert_eq!(__border_style!(Right, inherit).to_string(), "border-right-style:inherit;");
	assert_eq!(__border_style!(Right, unset).to_string(), "border-right-style:unset;");

	assert_eq!(__border_style!(Top, none).to_string(), "border-top-style:none;");
	assert_eq!(__border_style!(Top, hidden).to_string(), "border-top-style:hidden;");
	assert_eq!(__border_style!(Top, dotted).to_string(), "border-top-style:dotted;");
	assert_eq!(__border_style!(Top, dashed).to_string(), "border-top-style:dashed;");
	assert_eq!(__border_style!(Top, solid).to_string(), "border-top-style:solid;");
	assert_eq!(__border_style!(Top, double).to_string(), "border-top-style:double;");
	assert_eq!(__border_style!(Top, groove).to_string(), "border-top-style:groove;");
	assert_eq!(__border_style!(Top, ridge).to_string(), "border-top-style:ridge;");
	assert_eq!(__border_style!(Top, inset).to_string(), "border-top-style:inset;");
	assert_eq!(__border_style!(Top, outset).to_string(), "border-top-style:outset;");
	assert_eq!(__border_style!(Top, initial).to_string(), "border-top-style:initial;");
	assert_eq!(__border_style!(Top, inherit).to_string(), "border-top-style:inherit;");
	assert_eq!(__border_style!(Top, unset).to_string(), "border-top-style:unset;");

	assert_eq!(__border_style!(Bottom, none).to_string(), "border-bottom-style:none;");
	assert_eq!(__border_style!(Bottom, hidden).to_string(), "border-bottom-style:hidden;");
	assert_eq!(__border_style!(Bottom, dotted).to_string(), "border-bottom-style:dotted;");
	assert_eq!(__border_style!(Bottom, dashed).to_string(), "border-bottom-style:dashed;");
	assert_eq!(__border_style!(Bottom, solid).to_string(), "border-bottom-style:solid;");
	assert_eq!(__border_style!(Bottom, double).to_string(), "border-bottom-style:double;");
	assert_eq!(__border_style!(Bottom, groove).to_string(), "border-bottom-style:groove;");
	assert_eq!(__border_style!(Bottom, ridge).to_string(), "border-bottom-style:ridge;");
	assert_eq!(__border_style!(Bottom, inset).to_string(), "border-bottom-style:inset;");
	assert_eq!(__border_style!(Bottom, outset).to_string(), "border-bottom-style:outset;");
	assert_eq!(__border_style!(Bottom, initial).to_string(), "border-bottom-style:initial;");
	assert_eq!(__border_style!(Bottom, inherit).to_string(), "border-bottom-style:inherit;");
	assert_eq!(__border_style!(Bottom, unset).to_string(), "border-bottom-style:unset;");
}