-
-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathconstant.rs
More file actions
160 lines (147 loc) · 4.86 KB
/
constant.rs
File metadata and controls
160 lines (147 loc) · 4.86 KB
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
use std::collections::HashMap;
use once_cell::sync::Lazy;
use phf::{phf_map, phf_set};
use regex::Regex;
pub(super) static SELECTOR_ORDER_MAP: Lazy<HashMap<String, u8>> = Lazy::new(|| {
let mut map = HashMap::new();
for (idx, selector) in [
"hover",
"focus-visible",
"focus",
"active",
"selected",
"disabled",
]
.into_iter()
.enumerate()
{
map.insert(format!(":{selector}"), idx as u8);
}
map
});
pub(super) static GLOBAL_STYLE_PROPERTY: phf::Map<&str, &[&str]> = phf_map! {
"bg" => &["background"],
"bgAttachment" => &["background-attachment"],
"bgClip" => &["background-clip"],
"bgColor" => &["background-color"],
"bgImage" => &["background-image"],
"bgOrigin" => &["background-origin"],
"bgPosition" => &["background-position"],
"bgPositionX" => &["background-position-x"],
"bgPositionY" => &["background-position-y"],
"bgPos" => &["background-position"],
"bgPosX" => &["background-position-x"],
"bgPosY" => &["background-position-y"],
"bgRepeat" => &["background-repeat"],
"bgSize" => &["background-size"],
"bgBlendMode" => &["background-blend-mode"],
"animationDir" => &["animation-direction"],
"flexDir" => &["flex-direction"],
"pos" => &["position"],
"m" => &["margin"],
"mt" => &["margin-top"],
"mr" => &["margin-right"],
"mb" => &["margin-bottom"],
"ml" => &["margin-left"],
"p" => &["padding"],
"pt" => &["padding-top"],
"pr" => &["padding-right"],
"pb" => &["padding-bottom"],
"pl" => &["padding-left"],
"w" => &["width"],
"h" => &["height"],
"minW" => &["min-width"],
"minH" => &["min-height"],
"maxW" => &["max-width"],
"maxH" => &["max-height"],
"mx" => &["margin-left", "margin-right"],
"my" => &["margin-top", "margin-bottom"],
"px" => &["padding-left", "padding-right"],
"py" => &["padding-top", "padding-bottom"],
"boxSize" => &["width", "height"],
"borderBottomRadius" => &["border-bottom-left-radius", "border-bottom-right-radius"],
"borderTopRadius" => &["border-top-left-radius", "border-top-right-radius"],
"borderLeftRadius" => &["border-top-left-radius", "border-bottom-left-radius"],
"borderRightRadius" => &["border-top-right-radius", "border-bottom-right-radius"],
"objectPos" => &["object-position"],
"offsetPos" => &["offset-position"],
};
pub(super) static OPTIMIZE_MULTI_CSS_VALUE_PROPERTY: phf::Set<&str> = phf_set! {
"font-family",
"src",
"content",
"animation-name",
};
pub(super) static DOUBLE_SEPARATOR: phf::Set<&str> = phf_set! {
"after",
"backdrop",
"before",
"checkmark",
"cue",
"cue-region",
"details-content",
"file-selector-button",
"first-letter",
"first-line",
"grammar-error",
"marker",
"picker-icon",
"placeholder",
"scroll-marker",
"scroll-marker-group",
"selection",
"spelling-error",
"target-text",
"view-transition"
};
pub(super) static ZERO_PERCENT_FUNCTION: phf::Set<&str> = phf_set! {
"abs(",
"acos(",
"asin(",
"atan(",
"atan2(",
"calc(",
"calc-size(",
"clamp(",
"cos(",
"exp(",
"hypot(",
"log(",
"max(",
"min(",
"mod(",
"pow(",
"rem(",
"round(",
"sign(",
"sin(",
"sqrt(",
"tan(",
};
pub(super) static F_SPACE_RE: Lazy<Regex> = Lazy::new(|| Regex::new(r"\s*,\s*").unwrap());
pub(super) static CSS_FUNCTION_RE: Lazy<Regex> =
Lazy::new(|| Regex::new(r"^[a-zA-Z-]+(\(.*\))").unwrap());
pub(super) static CHECK_QUOTES_RE: Lazy<Regex> = Lazy::new(|| Regex::new(r"[()\s]").unwrap());
pub(super) static CSS_COMMENT_RE: Lazy<Regex> =
Lazy::new(|| Regex::new(r"/\*[\s\S]*?\*/").unwrap());
pub(super) static F_DOT_RE: Lazy<Regex> = Lazy::new(|| Regex::new(r"(\b|,)0\.(\d+)").unwrap());
pub(super) static DOT_ZERO_RE: Lazy<Regex> =
Lazy::new(|| Regex::new(r"(\b|,)-?0\.0+([^\d])").unwrap());
pub(super) static COLOR_HASH: Lazy<Regex> = Lazy::new(|| Regex::new(r"#([0-9a-zA-Z]+)").unwrap());
pub(super) static INNER_TRIM_RE: Lazy<Regex> =
Lazy::new(|| Regex::new(r"\(\s*([^)]*?)\s*\)").unwrap());
pub(super) static RM_MINUS_ZERO_RE: Lazy<Regex> = Lazy::new(|| {
Regex::new(r"-0(px|em|rem|vh|vw|%|dvh|dvw|vmax|vmin|mm|cm|in|pt|pc|lh|ic|deg|\)|,)").unwrap()
});
pub(super) static NUM_TRIM_RE: Lazy<Regex> = Lazy::new(|| {
Regex::new(r"(\d(px|em|rem|vh|vw|%|dvh|dvw|vmax|vmin|mm|cm|in|pt|pc|lh|ic|deg)?)\s+(\d)")
.unwrap()
});
pub(super) static ZERO_RE: Lazy<Regex> = Lazy::new(|| {
Regex::new(r"(\b|,|\(|^|\s)-?0(px|em|rem|vh|vw|%|dvh|dvw|vmax|vmin|mm|cm|in|pt|pc|lh|ic|deg)")
.unwrap()
});
pub(super) static F_RGBA_RE: Lazy<Regex> =
Lazy::new(|| Regex::new(r"rgba\((\d+),(\d+),(\d+),(\d*\.?\d*)\)").unwrap());
pub(super) static F_RGB_RE: Lazy<Regex> =
Lazy::new(|| Regex::new(r"rgb\((\d+),(\d+),(\d+)\)").unwrap());