parse_color/
tailwind.rs

1#[allow(non_upper_case_globals)]
2mod colors {
3    pub static slate: [[u8; 4]; 11] = [
4        0xf8fafcffu32.to_be_bytes(),
5        0xf1f5f9ffu32.to_be_bytes(),
6        0xe2e8f0ffu32.to_be_bytes(),
7        0xcbd5e1ffu32.to_be_bytes(),
8        0x94a3b8ffu32.to_be_bytes(),
9        0x64748bffu32.to_be_bytes(),
10        0x475569ffu32.to_be_bytes(),
11        0x334155ffu32.to_be_bytes(),
12        0x1e293bffu32.to_be_bytes(),
13        0x0f172affu32.to_be_bytes(),
14        0x020617ffu32.to_be_bytes(),
15    ];
16    pub static gray: [[u8; 4]; 11] = [
17        0xf9fafbffu32.to_be_bytes(),
18        0xf3f4f6ffu32.to_be_bytes(),
19        0xe5e7ebffu32.to_be_bytes(),
20        0xd1d5dbffu32.to_be_bytes(),
21        0x9ca3afffu32.to_be_bytes(),
22        0x6b7280ffu32.to_be_bytes(),
23        0x4b5563ffu32.to_be_bytes(),
24        0x374151ffu32.to_be_bytes(),
25        0x1f2937ffu32.to_be_bytes(),
26        0x111827ffu32.to_be_bytes(),
27        0x030712ffu32.to_be_bytes(),
28    ];
29    pub static zinc: [[u8; 4]; 11] = [
30        0xfafafaffu32.to_be_bytes(),
31        0xf4f4f5ffu32.to_be_bytes(),
32        0xe4e4e7ffu32.to_be_bytes(),
33        0xd4d4d8ffu32.to_be_bytes(),
34        0xa1a1aaffu32.to_be_bytes(),
35        0x71717affu32.to_be_bytes(),
36        0x52525bffu32.to_be_bytes(),
37        0x3f3f46ffu32.to_be_bytes(),
38        0x27272affu32.to_be_bytes(),
39        0x18181bffu32.to_be_bytes(),
40        0x09090bffu32.to_be_bytes(),
41    ];
42    pub static neutral: [[u8; 4]; 11] = [
43        0xfafafaffu32.to_be_bytes(),
44        0xf5f5f5ffu32.to_be_bytes(),
45        0xe5e5e5ffu32.to_be_bytes(),
46        0xd4d4d4ffu32.to_be_bytes(),
47        0xa3a3a3ffu32.to_be_bytes(),
48        0x737373ffu32.to_be_bytes(),
49        0x525252ffu32.to_be_bytes(),
50        0x404040ffu32.to_be_bytes(),
51        0x262626ffu32.to_be_bytes(),
52        0x171717ffu32.to_be_bytes(),
53        0x0a0a0affu32.to_be_bytes(),
54    ];
55    pub static stone: [[u8; 4]; 11] = [
56        0xfafaf9ffu32.to_be_bytes(),
57        0xf5f5f4ffu32.to_be_bytes(),
58        0xe7e5e4ffu32.to_be_bytes(),
59        0xd6d3d1ffu32.to_be_bytes(),
60        0xa8a29effu32.to_be_bytes(),
61        0x78716cffu32.to_be_bytes(),
62        0x57534effu32.to_be_bytes(),
63        0x44403cffu32.to_be_bytes(),
64        0x292524ffu32.to_be_bytes(),
65        0x1c1917ffu32.to_be_bytes(),
66        0x0c0a09ffu32.to_be_bytes(),
67    ];
68    pub static red: [[u8; 4]; 11] = [
69        0xfef2f2ffu32.to_be_bytes(),
70        0xfee2e2ffu32.to_be_bytes(),
71        0xfecacaffu32.to_be_bytes(),
72        0xfca5a5ffu32.to_be_bytes(),
73        0xf87171ffu32.to_be_bytes(),
74        0xef4444ffu32.to_be_bytes(),
75        0xdc2626ffu32.to_be_bytes(),
76        0xb91c1cffu32.to_be_bytes(),
77        0x991b1bffu32.to_be_bytes(),
78        0x7f1d1dffu32.to_be_bytes(),
79        0x450a0affu32.to_be_bytes(),
80    ];
81    pub static orange: [[u8; 4]; 11] = [
82        0xfff7edffu32.to_be_bytes(),
83        0xffedd5ffu32.to_be_bytes(),
84        0xfed7aaffu32.to_be_bytes(),
85        0xfdba74ffu32.to_be_bytes(),
86        0xfb923cffu32.to_be_bytes(),
87        0xf97316ffu32.to_be_bytes(),
88        0xea580cffu32.to_be_bytes(),
89        0xc2410cffu32.to_be_bytes(),
90        0x9a3412ffu32.to_be_bytes(),
91        0x7c2d12ffu32.to_be_bytes(),
92        0x431407ffu32.to_be_bytes(),
93    ];
94    pub static amber: [[u8; 4]; 11] = [
95        0xfffbebffu32.to_be_bytes(),
96        0xfef3c7ffu32.to_be_bytes(),
97        0xfde68affu32.to_be_bytes(),
98        0xfcd34dffu32.to_be_bytes(),
99        0xfbbf24ffu32.to_be_bytes(),
100        0xf59e0bffu32.to_be_bytes(),
101        0xd97706ffu32.to_be_bytes(),
102        0xb45309ffu32.to_be_bytes(),
103        0x92400effu32.to_be_bytes(),
104        0x78350fffu32.to_be_bytes(),
105        0x451a03ffu32.to_be_bytes(),
106    ];
107    pub static yellow: [[u8; 4]; 11] = [
108        0xfefce8ffu32.to_be_bytes(),
109        0xfef9c3ffu32.to_be_bytes(),
110        0xfef08affu32.to_be_bytes(),
111        0xfde047ffu32.to_be_bytes(),
112        0xfacc15ffu32.to_be_bytes(),
113        0xeab308ffu32.to_be_bytes(),
114        0xca8a04ffu32.to_be_bytes(),
115        0xa16207ffu32.to_be_bytes(),
116        0x854d0effu32.to_be_bytes(),
117        0x713f12ffu32.to_be_bytes(),
118        0x422006ffu32.to_be_bytes(),
119    ];
120    pub static lime: [[u8; 4]; 11] = [
121        0xf7fee7ffu32.to_be_bytes(),
122        0xecfccbffu32.to_be_bytes(),
123        0xd9f99dffu32.to_be_bytes(),
124        0xbef264ffu32.to_be_bytes(),
125        0xa3e635ffu32.to_be_bytes(),
126        0x84cc16ffu32.to_be_bytes(),
127        0x65a30dffu32.to_be_bytes(),
128        0x4d7c0fffu32.to_be_bytes(),
129        0x3f6212ffu32.to_be_bytes(),
130        0x365314ffu32.to_be_bytes(),
131        0x1a2e05ffu32.to_be_bytes(),
132    ];
133    pub static green: [[u8; 4]; 11] = [
134        0xf0fdf4ffu32.to_be_bytes(),
135        0xdcfce7ffu32.to_be_bytes(),
136        0xbbf7d0ffu32.to_be_bytes(),
137        0x86efacffu32.to_be_bytes(),
138        0x4ade80ffu32.to_be_bytes(),
139        0x22c55effu32.to_be_bytes(),
140        0x16a34affu32.to_be_bytes(),
141        0x15803dffu32.to_be_bytes(),
142        0x166534ffu32.to_be_bytes(),
143        0x14532dffu32.to_be_bytes(),
144        0x052e16ffu32.to_be_bytes(),
145    ];
146    pub static emerald: [[u8; 4]; 11] = [
147        0xecfdf5ffu32.to_be_bytes(),
148        0xd1fae5ffu32.to_be_bytes(),
149        0xa7f3d0ffu32.to_be_bytes(),
150        0x6ee7b7ffu32.to_be_bytes(),
151        0x34d399ffu32.to_be_bytes(),
152        0x10b981ffu32.to_be_bytes(),
153        0x059669ffu32.to_be_bytes(),
154        0x047857ffu32.to_be_bytes(),
155        0x065f46ffu32.to_be_bytes(),
156        0x064e3bffu32.to_be_bytes(),
157        0x022c22ffu32.to_be_bytes(),
158    ];
159    pub static teal: [[u8; 4]; 11] = [
160        0xf0fdfaffu32.to_be_bytes(),
161        0xccfbf1ffu32.to_be_bytes(),
162        0x99f6e4ffu32.to_be_bytes(),
163        0x5eead4ffu32.to_be_bytes(),
164        0x2dd4bfffu32.to_be_bytes(),
165        0x14b8a6ffu32.to_be_bytes(),
166        0x0d9488ffu32.to_be_bytes(),
167        0x0f766effu32.to_be_bytes(),
168        0x115e59ffu32.to_be_bytes(),
169        0x134e4affu32.to_be_bytes(),
170        0x042f2effu32.to_be_bytes(),
171    ];
172    pub static cyan: [[u8; 4]; 11] = [
173        0xecfeffffu32.to_be_bytes(),
174        0xcffafeffu32.to_be_bytes(),
175        0xa5f3fcffu32.to_be_bytes(),
176        0x67e8f9ffu32.to_be_bytes(),
177        0x22d3eeffu32.to_be_bytes(),
178        0x06b6d4ffu32.to_be_bytes(),
179        0x0891b2ffu32.to_be_bytes(),
180        0x0e7490ffu32.to_be_bytes(),
181        0x155e75ffu32.to_be_bytes(),
182        0x164e63ffu32.to_be_bytes(),
183        0x083344ffu32.to_be_bytes(),
184    ];
185    pub static sky: [[u8; 4]; 11] = [
186        0xf0f9ffffu32.to_be_bytes(),
187        0xe0f2feffu32.to_be_bytes(),
188        0xbae6fdffu32.to_be_bytes(),
189        0x7dd3fcffu32.to_be_bytes(),
190        0x38bdf8ffu32.to_be_bytes(),
191        0x0ea5e9ffu32.to_be_bytes(),
192        0x0284c7ffu32.to_be_bytes(),
193        0x0369a1ffu32.to_be_bytes(),
194        0x075985ffu32.to_be_bytes(),
195        0x0c4a6effu32.to_be_bytes(),
196        0x082f49ffu32.to_be_bytes(),
197    ];
198    pub static blue: [[u8; 4]; 11] = [
199        0xeff6ffffu32.to_be_bytes(),
200        0xdbeafeffu32.to_be_bytes(),
201        0xbfdbfeffu32.to_be_bytes(),
202        0x93c5fdffu32.to_be_bytes(),
203        0x60a5faffu32.to_be_bytes(),
204        0x3b82f6ffu32.to_be_bytes(),
205        0x2563ebffu32.to_be_bytes(),
206        0x1d4ed8ffu32.to_be_bytes(),
207        0x1e40afffu32.to_be_bytes(),
208        0x1e3a8affu32.to_be_bytes(),
209        0x172554ffu32.to_be_bytes(),
210    ];
211    pub static indigo: [[u8; 4]; 11] = [
212        0xeef2ffffu32.to_be_bytes(),
213        0xe0e7ffffu32.to_be_bytes(),
214        0xc7d2feffu32.to_be_bytes(),
215        0xa5b4fcffu32.to_be_bytes(),
216        0x818cf8ffu32.to_be_bytes(),
217        0x6366f1ffu32.to_be_bytes(),
218        0x4f46e5ffu32.to_be_bytes(),
219        0x4338caffu32.to_be_bytes(),
220        0x3730a3ffu32.to_be_bytes(),
221        0x312e81ffu32.to_be_bytes(),
222        0x1e1b4bffu32.to_be_bytes(),
223    ];
224    pub static violet: [[u8; 4]; 11] = [
225        0xf5f3ffffu32.to_be_bytes(),
226        0xede9feffu32.to_be_bytes(),
227        0xddd6feffu32.to_be_bytes(),
228        0xc4b5fdffu32.to_be_bytes(),
229        0xa78bfaffu32.to_be_bytes(),
230        0x8b5cf6ffu32.to_be_bytes(),
231        0x7c3aedffu32.to_be_bytes(),
232        0x6d28d9ffu32.to_be_bytes(),
233        0x5b21b6ffu32.to_be_bytes(),
234        0x4c1d95ffu32.to_be_bytes(),
235        0x2e1065ffu32.to_be_bytes(),
236    ];
237    pub static purple: [[u8; 4]; 11] = [
238        0xfaf5ffffu32.to_be_bytes(),
239        0xf3e8ffffu32.to_be_bytes(),
240        0xe9d5ffffu32.to_be_bytes(),
241        0xd8b4feffu32.to_be_bytes(),
242        0xc084fcffu32.to_be_bytes(),
243        0xa855f7ffu32.to_be_bytes(),
244        0x9333eaffu32.to_be_bytes(),
245        0x7e22ceffu32.to_be_bytes(),
246        0x6b21a8ffu32.to_be_bytes(),
247        0x581c87ffu32.to_be_bytes(),
248        0x3b0764ffu32.to_be_bytes(),
249    ];
250    pub static fuchsia: [[u8; 4]; 11] = [
251        0xfdf4ffffu32.to_be_bytes(),
252        0xfae8ffffu32.to_be_bytes(),
253        0xf5d0feffu32.to_be_bytes(),
254        0xf0abfcffu32.to_be_bytes(),
255        0xe879f9ffu32.to_be_bytes(),
256        0xd946efffu32.to_be_bytes(),
257        0xc026d3ffu32.to_be_bytes(),
258        0xa21cafffu32.to_be_bytes(),
259        0x86198fffu32.to_be_bytes(),
260        0x701a75ffu32.to_be_bytes(),
261        0x4a044effu32.to_be_bytes(),
262    ];
263    pub static pink: [[u8; 4]; 11] = [
264        0xfdf2f8ffu32.to_be_bytes(),
265        0xfce7f3ffu32.to_be_bytes(),
266        0xfbcfe8ffu32.to_be_bytes(),
267        0xf9a8d4ffu32.to_be_bytes(),
268        0xf472b6ffu32.to_be_bytes(),
269        0xec4899ffu32.to_be_bytes(),
270        0xdb2777ffu32.to_be_bytes(),
271        0xbe185dffu32.to_be_bytes(),
272        0x9d174dffu32.to_be_bytes(),
273        0x831843ffu32.to_be_bytes(),
274        0x500724ffu32.to_be_bytes(),
275    ];
276    pub static rose: [[u8; 4]; 11] = [
277        0xfff1f2ffu32.to_be_bytes(),
278        0xffe4e6ffu32.to_be_bytes(),
279        0xfecdd3ffu32.to_be_bytes(),
280        0xfda4afffu32.to_be_bytes(),
281        0xfb7185ffu32.to_be_bytes(),
282        0xf43f5effu32.to_be_bytes(),
283        0xe11d48ffu32.to_be_bytes(),
284        0xbe123cffu32.to_be_bytes(),
285        0x9f1239ffu32.to_be_bytes(),
286        0x881337ffu32.to_be_bytes(),
287        0x4c0519ffu32.to_be_bytes(),
288    ];
289}
290
291/// Parse a TailwindCSS color name into a `[u8;4]` in the order of `RGBA`.
292pub fn parse_tailwind(name: &str, index: usize) -> Option<[u8; 4]>{
293    let s: String = name.chars().filter_map(|c|
294        match c {
295            'A'..='Z' => Some(c.to_ascii_lowercase()),
296            'a'..='z' => Some(c),
297            _ => None,
298        }
299    ).collect();
300    parse_tailwind_flat_lower(&s, index)
301}
302
303/// Parse a TailwindCSS color name into a `[u8;4]` in the order of `RGBA`.
304///
305/// This is a non-allocating version of [`parse_tailwind`], 
306/// will fail if the string is not `flatlowercase`.
307pub fn parse_tailwind_flat_lower(name: &str, index: usize) -> Option<[u8; 4]>{
308    match name {
309        "none" => return Some([0, 0, 0, 0]),
310        "transparent" => return Some([0, 0, 0, 0]),
311        "black" => return Some([0, 0, 0, 255]),
312        "white" => return Some([255, 255, 255, 255]),
313        _ => (),
314    };
315    let index = match index {
316        50 => 0,
317        100 => 1,
318        200 => 2,
319        300 => 3,
320        400 => 4,
321        500 => 5,
322        600 => 6,
323        700 => 7,
324        800 => 8,
325        900 => 9,
326        950 => 10,
327        _ => return None
328    };
329    let item = match name {
330        "slate" => colors::slate[index],
331        "grey" => colors::gray[index],
332        "gray" => colors::gray[index],
333        "zinc" => colors::zinc[index],
334        "neutral" => colors::neutral[index],
335        "stone" => colors::stone[index],
336        "red" => colors::red[index],
337        "orange" => colors::orange[index],
338        "amber" => colors::amber[index],
339        "yellow" => colors::yellow[index],
340        "lime" => colors::lime[index],
341        "green" => colors::green[index],
342        "emerald" => colors::emerald[index],
343        "teal" => colors::teal[index],
344        "cyan" => colors::cyan[index],
345        "sky" => colors::sky[index],
346        "blue" => colors::blue[index],
347        "indigo" => colors::indigo[index],
348        "purple" => colors::purple[index],
349        "fuchsia" => colors::fuchsia[index],
350        "pink" => colors::pink[index],
351        "rose" => colors::rose[index],
352        _ => return None,
353    };
354    return Some(item);
355}