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
// Authors: Robert Lopez
/// Create a `Style` from `css`, rendering it to the DOM as a `<style>` in `<head>`.
/// The `css` is formatted, minfied, and small errors like invalid semi-colons can be
/// corrected, however invalid CSS itself is not handled by the parser.
///
/// Effects remain there order as defined, but their inner fields, as well as the Style's
/// fields will be ordered in a deterministic fashion to avoid duplication.
///
/// *Note*: Trailing semi-colons are required.
///
/// Returns error if missing access to: `Head`, `Crypto`(If generating a random ID),
/// `Window`, `Document`.
///
/// ---
/// Example Usage:
/// ```
///
/// let style: Style = style!(
/// "
/// font-size: {}px;
///
/// &:hover {
/// background-color: rgba(111, 111, 111, 0.1);
/// }
///
/// @media (max-width: 800px) {
/// font-size: {}px;
/// }
/// ",
/// 18, 12
/// )?;
/// ```
/// Create a `Style` from `css` with a `css_name`, rendering it to the DOM as a `<style>` in `<head>`.
/// The `css` is formatted, minfied, and small errors like invalid semi-colons can be
/// corrected, however invalid CSS itself is not handled by the parser.
///
/// Effects remain there order as defined, but their inner fields, as well as the Style's
/// fields will be ordered in a deterministic fashion to avoid duplication.
///
/// *Note*: Trailing semi-colons are required.
///
/// Returns error if missing access to: `Head`, `Crypto`(If generating a random ID),
/// `Window`, `Document`.
///
/// ---
/// Example Usage:
/// ```
///
/// let style: Style = named_style!(
/// ".my_class",
/// "
/// font-size: {}px;
///
/// &:hover {
/// background-color: rgba(111, 111, 111, 0.1);
/// }
///
/// @media (max-width: 800px) {
/// font-size: {}px;
/// }
/// ",
/// 18, 12
/// )?;
/// ```
/// Extend `Style` with `css`, re-rendering if `new_css` is not empty.
///
/// Returns error if missing access to: `Head`, `Window`, `Document`.
///
/// ---
/// Example Usage:
/// ```
///
/// let mut style = named_style!(".my_class", "font-size: {}px;", 12)?;
///
/// extend_style_from_css!(
/// &mut style,
/// "
/// gap: 2rem;
/// display: flex;
/// "
/// )?;
/// ```
/// Reduce a `Style` by removing `keys`, re-rendering if at-least one key is removed.
///
/// Returns error if missing access to: `Head`, `Window`, `Document`.
///
/// ---
/// Example Usage:
/// ```
///
/// let mut style = named_style!(
/// ".my_class",
/// "
/// gap: 1rem;
/// font-size: {}px;
///
/// &:hover {{
/// background-color: red;
/// }}
/// ",
/// 12
/// )?;
///
/// reduce_style!(&mut style, "gap", "&:hover")?;
/// ```