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
use utils::extract_args_by_type;
use properties::parse::{
TransformFunction,
GradientStopRepr,
GradientFunction,
FilterFunction,
LengthRepr,
AngleRepr,
UnitRepr,
};
use properties::{
SharedUnit,
Transform,
Filter,
};
impl<'a> From<FilterFunction<'a>> for Filter {
fn from(value: FilterFunction) -> Filter {
match value.name {
"brightness" => Filter::Brightness(value.value),
"grayscale" => Filter::Grayscale(value.value),
"hueRotate" => Filter::HueRotate(value.value),
"saturate" => Filter::Saturate(value.value),
"contrast" => Filter::Contrast(value.value),
"invert" => Filter::Invert(value.value),
"sepia" => Filter::Sepia(value.value),
"blur" => Filter::Blur(value.value),
_ => Filter::None,
}
}
}
impl<'a, 'b, 'c> From<TransformFunction<'a, 'b, 'c>> for Transform {
fn from(value: TransformFunction) -> Transform {
let units: Vec<SharedUnit> = value.args.iter().cloned().map(Into::into).collect();
extract_args_by_type(value.name, &units)
}
}
impl<'a, 'b, 'c> From<TransformFunction<'a, 'b, 'c>> for String {
fn from(value: TransformFunction) -> String {
let args = value.args.into_iter().map(|s| String::from(s)).collect::<Vec<_>>().join(",");
format!("{}({})", value.name, args)
}
}
impl From<GradientStopRepr> for String {
fn from(value: GradientStopRepr) -> String {
format!("{} {}%", value.color.to_string(), value.offset as u32)
}
}
impl<'a, 'b> From<GradientFunction<'a, 'b>> for String {
fn from(value: GradientFunction) -> String {
let stops = value.stops.into_iter().map(|s| String::from(s)).collect::<Vec<_>>().join(",");
format!("{}, {}", String::from(value.angle), stops)
}
}
impl<'a> From<FilterFunction<'a>> for String {
fn from(value: FilterFunction) -> String {
format!("{}({})", value.name, value.value as u32)
}
}
impl<'a, 'b> From<LengthRepr<'a, 'b>> for String {
fn from(value: LengthRepr) -> String {
format!("{}{}", value.value, value.unit)
}
}
impl<'a, 'b> From<AngleRepr<'a, 'b>> for String {
fn from(value: AngleRepr) -> String {
format!("{}{}", value.value, value.angle)
}
}
impl<'a, 'b> From<UnitRepr<'a, 'b>> for String {
fn from(value: UnitRepr) -> String {
match value {
UnitRepr::Angle(v) => v.into(),
UnitRepr::Length(v) => v.into(),
}
}
}