iced_core/theme/
palette.rs

1//! Define the colors of a theme.
2use crate::{color, Color};
3
4use once_cell::sync::Lazy;
5use palette::color_difference::Wcag21RelativeContrast;
6use palette::rgb::Rgb;
7use palette::{FromColor, Hsl, Mix};
8
9/// A color palette.
10#[derive(Debug, Clone, Copy, PartialEq)]
11pub struct Palette {
12    /// The background [`Color`] of the [`Palette`].
13    pub background: Color,
14    /// The text [`Color`] of the [`Palette`].
15    pub text: Color,
16    /// The primary [`Color`] of the [`Palette`].
17    pub primary: Color,
18    /// The success [`Color`] of the [`Palette`].
19    pub success: Color,
20    /// The danger [`Color`] of the [`Palette`].
21    pub danger: Color,
22}
23
24impl Palette {
25    /// The built-in light variant of a [`Palette`].
26    pub const LIGHT: Self = Self {
27        background: Color::WHITE,
28        text: Color::BLACK,
29        primary: Color::from_rgb(
30            0x5E as f32 / 255.0,
31            0x7C as f32 / 255.0,
32            0xE2 as f32 / 255.0,
33        ),
34        success: Color::from_rgb(
35            0x12 as f32 / 255.0,
36            0x66 as f32 / 255.0,
37            0x4F as f32 / 255.0,
38        ),
39        danger: Color::from_rgb(
40            0xC3 as f32 / 255.0,
41            0x42 as f32 / 255.0,
42            0x3F as f32 / 255.0,
43        ),
44    };
45
46    /// The built-in dark variant of a [`Palette`].
47    pub const DARK: Self = Self {
48        background: Color::from_rgb(
49            0x20 as f32 / 255.0,
50            0x22 as f32 / 255.0,
51            0x25 as f32 / 255.0,
52        ),
53        text: Color::from_rgb(0.90, 0.90, 0.90),
54        primary: Color::from_rgb(
55            0x5E as f32 / 255.0,
56            0x7C as f32 / 255.0,
57            0xE2 as f32 / 255.0,
58        ),
59        success: Color::from_rgb(
60            0x12 as f32 / 255.0,
61            0x66 as f32 / 255.0,
62            0x4F as f32 / 255.0,
63        ),
64        danger: Color::from_rgb(
65            0xC3 as f32 / 255.0,
66            0x42 as f32 / 255.0,
67            0x3F as f32 / 255.0,
68        ),
69    };
70
71    /// The built-in [Dracula] variant of a [`Palette`].
72    ///
73    /// [Dracula]: https://draculatheme.com
74    pub const DRACULA: Self = Self {
75        background: color!(0x282A36), // BACKGROUND
76        text: color!(0xf8f8f2),       // FOREGROUND
77        primary: color!(0xbd93f9),    // PURPLE
78        success: color!(0x50fa7b),    // GREEN
79        danger: color!(0xff5555),     // RED
80    };
81
82    /// The built-in [Nord] variant of a [`Palette`].
83    ///
84    /// [Nord]: https://www.nordtheme.com/docs/colors-and-palettes
85    pub const NORD: Self = Self {
86        background: color!(0x2e3440), // nord0
87        text: color!(0xeceff4),       // nord6
88        primary: color!(0x8fbcbb),    // nord7
89        success: color!(0xa3be8c),    // nord14
90        danger: color!(0xbf616a),     // nord11
91    };
92
93    /// The built-in [Solarized] Light variant of a [`Palette`].
94    ///
95    /// [Solarized]: https://ethanschoonover.com/solarized
96    pub const SOLARIZED_LIGHT: Self = Self {
97        background: color!(0xfdf6e3), // base3
98        text: color!(0x657b83),       // base00
99        primary: color!(0x2aa198),    // cyan
100        success: color!(0x859900),    // green
101        danger: color!(0xdc322f),     // red
102    };
103
104    /// The built-in [Solarized] Dark variant of a [`Palette`].
105    ///
106    /// [Solarized]: https://ethanschoonover.com/solarized
107    pub const SOLARIZED_DARK: Self = Self {
108        background: color!(0x002b36), // base03
109        text: color!(0x839496),       // base0
110        primary: color!(0x2aa198),    // cyan
111        success: color!(0x859900),    // green
112        danger: color!(0xdc322f),     // red
113    };
114
115    /// The built-in [Gruvbox] Light variant of a [`Palette`].
116    ///
117    /// [Gruvbox]: https://github.com/morhetz/gruvbox
118    pub const GRUVBOX_LIGHT: Self = Self {
119        background: color!(0xfbf1c7), // light BG_0
120        text: color!(0x282828),       // light FG0_29
121        primary: color!(0x458588),    // light BLUE_4
122        success: color!(0x98971a),    // light GREEN_2
123        danger: color!(0xcc241d),     // light RED_1
124    };
125
126    /// The built-in [Gruvbox] Dark variant of a [`Palette`].
127    ///
128    /// [Gruvbox]: https://github.com/morhetz/gruvbox
129    pub const GRUVBOX_DARK: Self = Self {
130        background: color!(0x282828), // dark BG_0
131        text: color!(0xfbf1c7),       // dark FG0_29
132        primary: color!(0x458588),    // dark BLUE_4
133        success: color!(0x98971a),    // dark GREEN_2
134        danger: color!(0xcc241d),     // dark RED_1
135    };
136
137    /// The built-in [Catppuccin] Latte variant of a [`Palette`].
138    ///
139    /// [Catppuccin]: https://github.com/catppuccin/catppuccin
140    pub const CATPPUCCIN_LATTE: Self = Self {
141        background: color!(0xeff1f5), // Base
142        text: color!(0x4c4f69),       // Text
143        primary: color!(0x1e66f5),    // Blue
144        success: color!(0x40a02b),    // Green
145        danger: color!(0xd20f39),     // Red
146    };
147
148    /// The built-in [Catppuccin] Frappé variant of a [`Palette`].
149    ///
150    /// [Catppuccin]: https://github.com/catppuccin/catppuccin
151    pub const CATPPUCCIN_FRAPPE: Self = Self {
152        background: color!(0x303446), // Base
153        text: color!(0xc6d0f5),       // Text
154        primary: color!(0x8caaee),    // Blue
155        success: color!(0xa6d189),    // Green
156        danger: color!(0xe78284),     // Red
157    };
158
159    /// The built-in [Catppuccin] Macchiato variant of a [`Palette`].
160    ///
161    /// [Catppuccin]: https://github.com/catppuccin/catppuccin
162    pub const CATPPUCCIN_MACCHIATO: Self = Self {
163        background: color!(0x24273a), // Base
164        text: color!(0xcad3f5),       // Text
165        primary: color!(0x8aadf4),    // Blue
166        success: color!(0xa6da95),    // Green
167        danger: color!(0xed8796),     // Red
168    };
169
170    /// The built-in [Catppuccin] Mocha variant of a [`Palette`].
171    ///
172    /// [Catppuccin]: https://github.com/catppuccin/catppuccin
173    pub const CATPPUCCIN_MOCHA: Self = Self {
174        background: color!(0x1e1e2e), // Base
175        text: color!(0xcdd6f4),       // Text
176        primary: color!(0x89b4fa),    // Blue
177        success: color!(0xa6e3a1),    // Green
178        danger: color!(0xf38ba8),     // Red
179    };
180
181    /// The built-in [Tokyo Night] variant of a [`Palette`].
182    ///
183    /// [Tokyo Night]: https://github.com/enkia/tokyo-night-vscode-theme
184    pub const TOKYO_NIGHT: Self = Self {
185        background: color!(0x1a1b26), // Background (Night)
186        text: color!(0x9aa5ce),       // Text
187        primary: color!(0x2ac3de),    // Blue
188        success: color!(0x9ece6a),    // Green
189        danger: color!(0xf7768e),     // Red
190    };
191
192    /// The built-in [Tokyo Night] Storm variant of a [`Palette`].
193    ///
194    /// [Tokyo Night]: https://github.com/enkia/tokyo-night-vscode-theme
195    pub const TOKYO_NIGHT_STORM: Self = Self {
196        background: color!(0x24283b), // Background (Storm)
197        text: color!(0x9aa5ce),       // Text
198        primary: color!(0x2ac3de),    // Blue
199        success: color!(0x9ece6a),    // Green
200        danger: color!(0xf7768e),     // Red
201    };
202
203    /// The built-in [Tokyo Night] Light variant of a [`Palette`].
204    ///
205    /// [Tokyo Night]: https://github.com/enkia/tokyo-night-vscode-theme
206    pub const TOKYO_NIGHT_LIGHT: Self = Self {
207        background: color!(0xd5d6db), // Background
208        text: color!(0x565a6e),       // Text
209        primary: color!(0x166775),    // Blue
210        success: color!(0x485e30),    // Green
211        danger: color!(0x8c4351),     // Red
212    };
213
214    /// The built-in [Kanagawa] Wave variant of a [`Palette`].
215    ///
216    /// [Kanagawa]: https://github.com/rebelot/kanagawa.nvim
217    pub const KANAGAWA_WAVE: Self = Self {
218        background: color!(0x363646), // Sumi Ink 3
219        text: color!(0xCD7BA),        // Fuji White
220        primary: color!(0x2D4F67),    // Wave Blue 2
221        success: color!(0x76946A),    // Autumn Green
222        danger: color!(0xC34043),     // Autumn Red
223    };
224
225    /// The built-in [Kanagawa] Dragon variant of a [`Palette`].
226    ///
227    /// [Kanagawa]: https://github.com/rebelot/kanagawa.nvim
228    pub const KANAGAWA_DRAGON: Self = Self {
229        background: color!(0x181616), // Dragon Black 3
230        text: color!(0xc5c9c5),       // Dragon White
231        primary: color!(0x223249),    // Wave Blue 1
232        success: color!(0x8a9a7b),    // Dragon Green 2
233        danger: color!(0xc4746e),     // Dragon Red
234    };
235
236    /// The built-in [Kanagawa] Lotus variant of a [`Palette`].
237    ///
238    /// [Kanagawa]: https://github.com/rebelot/kanagawa.nvim
239    pub const KANAGAWA_LOTUS: Self = Self {
240        background: color!(0xf2ecbc), // Lotus White 3
241        text: color!(0x545464),       // Lotus Ink 1
242        primary: color!(0xc9cbd1),    // Lotus Violet 3
243        success: color!(0x6f894e),    // Lotus Green
244        danger: color!(0xc84053),     // Lotus Red
245    };
246
247    /// The built-in [Moonfly] variant of a [`Palette`].
248    ///
249    /// [Moonfly]: https://github.com/bluz71/vim-moonfly-colors
250    pub const MOONFLY: Self = Self {
251        background: color!(0x080808), // Background
252        text: color!(0xbdbdbd),       // Foreground
253        primary: color!(0x80a0ff),    // Blue (normal)
254        success: color!(0x8cc85f),    // Green (normal)
255        danger: color!(0xff5454),     // Red (normal)
256    };
257
258    /// The built-in [Nightfly] variant of a [`Palette`].
259    ///
260    /// [Nightfly]: https://github.com/bluz71/vim-nightfly-colors
261    pub const NIGHTFLY: Self = Self {
262        background: color!(0x011627), // Background
263        text: color!(0xbdc1c6),       // Foreground
264        primary: color!(0x82aaff),    // Blue (normal)
265        success: color!(0xa1cd5e),    // Green (normal)
266        danger: color!(0xfc514e),     // Red (normal)
267    };
268
269    /// The built-in [Oxocarbon] variant of a [`Palette`].
270    ///
271    /// [Oxocarbon]: https://github.com/nyoom-engineering/oxocarbon.nvim
272    pub const OXOCARBON: Self = Self {
273        background: color!(0x232323),
274        text: color!(0xd0d0d0),
275        primary: color!(0x00b4ff),
276        success: color!(0x00c15a),
277        danger: color!(0xf62d0f),
278    };
279
280    /// The built-in [Ferra] variant of a [`Palette`].
281    ///
282    /// [Ferra]: https://github.com/casperstorm/ferra
283    pub const FERRA: Self = Self {
284        background: color!(0x2b292d),
285        text: color!(0xfecdb2),
286        primary: color!(0xd1d1e0),
287        success: color!(0xb1b695),
288        danger: color!(0xe06b75),
289    };
290}
291
292/// An extended set of colors generated from a [`Palette`].
293#[derive(Debug, Clone, Copy, PartialEq)]
294pub struct Extended {
295    /// The set of background colors.
296    pub background: Background,
297    /// The set of primary colors.
298    pub primary: Primary,
299    /// The set of secondary colors.
300    pub secondary: Secondary,
301    /// The set of success colors.
302    pub success: Success,
303    /// The set of danger colors.
304    pub danger: Danger,
305    /// Whether the palette is dark or not.
306    pub is_dark: bool,
307}
308
309/// The built-in light variant of an [`Extended`] palette.
310pub static EXTENDED_LIGHT: Lazy<Extended> =
311    Lazy::new(|| Extended::generate(Palette::LIGHT));
312
313/// The built-in dark variant of an [`Extended`] palette.
314pub static EXTENDED_DARK: Lazy<Extended> =
315    Lazy::new(|| Extended::generate(Palette::DARK));
316
317/// The built-in Dracula variant of an [`Extended`] palette.
318pub static EXTENDED_DRACULA: Lazy<Extended> =
319    Lazy::new(|| Extended::generate(Palette::DRACULA));
320
321/// The built-in Nord variant of an [`Extended`] palette.
322pub static EXTENDED_NORD: Lazy<Extended> =
323    Lazy::new(|| Extended::generate(Palette::NORD));
324
325/// The built-in Solarized Light variant of an [`Extended`] palette.
326pub static EXTENDED_SOLARIZED_LIGHT: Lazy<Extended> =
327    Lazy::new(|| Extended::generate(Palette::SOLARIZED_LIGHT));
328
329/// The built-in Solarized Dark variant of an [`Extended`] palette.
330pub static EXTENDED_SOLARIZED_DARK: Lazy<Extended> =
331    Lazy::new(|| Extended::generate(Palette::SOLARIZED_DARK));
332
333/// The built-in Gruvbox Light variant of an [`Extended`] palette.
334pub static EXTENDED_GRUVBOX_LIGHT: Lazy<Extended> =
335    Lazy::new(|| Extended::generate(Palette::GRUVBOX_LIGHT));
336
337/// The built-in Gruvbox Dark variant of an [`Extended`] palette.
338pub static EXTENDED_GRUVBOX_DARK: Lazy<Extended> =
339    Lazy::new(|| Extended::generate(Palette::GRUVBOX_DARK));
340
341/// The built-in Catppuccin Latte variant of an [`Extended`] palette.
342pub static EXTENDED_CATPPUCCIN_LATTE: Lazy<Extended> =
343    Lazy::new(|| Extended::generate(Palette::CATPPUCCIN_LATTE));
344
345/// The built-in Catppuccin Frappé variant of an [`Extended`] palette.
346pub static EXTENDED_CATPPUCCIN_FRAPPE: Lazy<Extended> =
347    Lazy::new(|| Extended::generate(Palette::CATPPUCCIN_FRAPPE));
348
349/// The built-in Catppuccin Macchiato variant of an [`Extended`] palette.
350pub static EXTENDED_CATPPUCCIN_MACCHIATO: Lazy<Extended> =
351    Lazy::new(|| Extended::generate(Palette::CATPPUCCIN_MACCHIATO));
352
353/// The built-in Catppuccin Mocha variant of an [`Extended`] palette.
354pub static EXTENDED_CATPPUCCIN_MOCHA: Lazy<Extended> =
355    Lazy::new(|| Extended::generate(Palette::CATPPUCCIN_MOCHA));
356
357/// The built-in Tokyo Night variant of an [`Extended`] palette.
358pub static EXTENDED_TOKYO_NIGHT: Lazy<Extended> =
359    Lazy::new(|| Extended::generate(Palette::TOKYO_NIGHT));
360
361/// The built-in Tokyo Night Storm variant of an [`Extended`] palette.
362pub static EXTENDED_TOKYO_NIGHT_STORM: Lazy<Extended> =
363    Lazy::new(|| Extended::generate(Palette::TOKYO_NIGHT_STORM));
364
365/// The built-in Tokyo Night variant of an [`Extended`] palette.
366pub static EXTENDED_TOKYO_NIGHT_LIGHT: Lazy<Extended> =
367    Lazy::new(|| Extended::generate(Palette::TOKYO_NIGHT_LIGHT));
368
369/// The built-in Kanagawa Wave variant of an [`Extended`] palette.
370pub static EXTENDED_KANAGAWA_WAVE: Lazy<Extended> =
371    Lazy::new(|| Extended::generate(Palette::KANAGAWA_WAVE));
372
373/// The built-in Kanagawa Dragon variant of an [`Extended`] palette.
374pub static EXTENDED_KANAGAWA_DRAGON: Lazy<Extended> =
375    Lazy::new(|| Extended::generate(Palette::KANAGAWA_DRAGON));
376
377/// The built-in Kanagawa Lotus variant of an [`Extended`] palette.
378pub static EXTENDED_KANAGAWA_LOTUS: Lazy<Extended> =
379    Lazy::new(|| Extended::generate(Palette::KANAGAWA_LOTUS));
380
381/// The built-in Moonfly variant of an [`Extended`] palette.
382pub static EXTENDED_MOONFLY: Lazy<Extended> =
383    Lazy::new(|| Extended::generate(Palette::MOONFLY));
384
385/// The built-in Nightfly variant of an [`Extended`] palette.
386pub static EXTENDED_NIGHTFLY: Lazy<Extended> =
387    Lazy::new(|| Extended::generate(Palette::NIGHTFLY));
388
389/// The built-in Oxocarbon variant of an [`Extended`] palette.
390pub static EXTENDED_OXOCARBON: Lazy<Extended> =
391    Lazy::new(|| Extended::generate(Palette::OXOCARBON));
392
393/// The built-in Ferra variant of an [`Extended`] palette.
394pub static EXTENDED_FERRA: Lazy<Extended> =
395    Lazy::new(|| Extended::generate(Palette::FERRA));
396
397impl Extended {
398    /// Generates an [`Extended`] palette from a simple [`Palette`].
399    pub fn generate(palette: Palette) -> Self {
400        Self {
401            background: Background::new(palette.background, palette.text),
402            primary: Primary::generate(
403                palette.primary,
404                palette.background,
405                palette.text,
406            ),
407            secondary: Secondary::generate(palette.background, palette.text),
408            success: Success::generate(
409                palette.success,
410                palette.background,
411                palette.text,
412            ),
413            danger: Danger::generate(
414                palette.danger,
415                palette.background,
416                palette.text,
417            ),
418            is_dark: is_dark(palette.background),
419        }
420    }
421}
422
423/// Recommended background, icon, and text [`Color`].
424#[derive(Debug, Clone, Copy, PartialEq)]
425pub struct Pair {
426    /// The background color.
427    pub color: Color,
428
429    /// The icon color, which defaults to the text color.
430    pub icon: Color,
431
432    /// The text color.
433    ///
434    /// It's guaranteed to be readable on top of the background [`color`].
435    ///
436    /// [`color`]: Self::color
437    pub text: Color,
438}
439
440impl Pair {
441    /// Creates a new [`Pair`] from a background [`Color`] and some text [`Color`].
442    pub fn new(color: Color, text: Color) -> Self {
443        let text = readable(color, text);
444
445        Self {
446            color,
447            icon: text,
448            text,
449        }
450    }
451}
452
453/// A set of background colors.
454#[derive(Debug, Clone, Copy, PartialEq)]
455pub struct Background {
456    /// The base background color.
457    pub base: Pair,
458    /// A weaker version of the base background color.
459    pub weak: Pair,
460    /// A stronger version of the base background color.
461    pub strong: Pair,
462}
463
464impl Background {
465    /// Generates a set of [`Background`] colors from the base and text colors.
466    pub fn new(base: Color, text: Color) -> Self {
467        let weak = mix(base, text, 0.15);
468        let strong = mix(base, text, 0.40);
469
470        Self {
471            base: Pair::new(base, text),
472            weak: Pair::new(weak, text),
473            strong: Pair::new(strong, text),
474        }
475    }
476}
477
478/// A set of primary colors.
479#[derive(Debug, Clone, Copy, PartialEq)]
480pub struct Primary {
481    /// The base primary color.
482    pub base: Pair,
483    /// A weaker version of the base primary color.
484    pub weak: Pair,
485    /// A stronger version of the base primary color.
486    pub strong: Pair,
487}
488
489impl Primary {
490    /// Generates a set of [`Primary`] colors from the base, background, and text colors.
491    pub fn generate(base: Color, background: Color, text: Color) -> Self {
492        let weak = mix(base, background, 0.4);
493        let strong = deviate(base, 0.1);
494
495        Self {
496            base: Pair::new(base, text),
497            weak: Pair::new(weak, text),
498            strong: Pair::new(strong, text),
499        }
500    }
501}
502
503/// A set of secondary colors.
504#[derive(Debug, Clone, Copy, PartialEq)]
505pub struct Secondary {
506    /// The base secondary color.
507    pub base: Pair,
508    /// A weaker version of the base secondary color.
509    pub weak: Pair,
510    /// A stronger version of the base secondary color.
511    pub strong: Pair,
512}
513
514impl Secondary {
515    /// Generates a set of [`Secondary`] colors from the base and text colors.
516    pub fn generate(base: Color, text: Color) -> Self {
517        let base = mix(base, text, 0.2);
518        let weak = mix(base, text, 0.1);
519        let strong = mix(base, text, 0.3);
520
521        Self {
522            base: Pair::new(base, text),
523            weak: Pair::new(weak, text),
524            strong: Pair::new(strong, text),
525        }
526    }
527}
528
529/// A set of success colors.
530#[derive(Debug, Clone, Copy, PartialEq)]
531pub struct Success {
532    /// The base success color.
533    pub base: Pair,
534    /// A weaker version of the base success color.
535    pub weak: Pair,
536    /// A stronger version of the base success color.
537    pub strong: Pair,
538}
539
540impl Success {
541    /// Generates a set of [`Success`] colors from the base, background, and text colors.
542    pub fn generate(base: Color, background: Color, text: Color) -> Self {
543        let weak = mix(base, background, 0.4);
544        let strong = deviate(base, 0.1);
545
546        Self {
547            base: Pair::new(base, text),
548            weak: Pair::new(weak, text),
549            strong: Pair::new(strong, text),
550        }
551    }
552}
553
554/// A set of danger colors.
555#[derive(Debug, Clone, Copy, PartialEq)]
556pub struct Danger {
557    /// The base danger color.
558    pub base: Pair,
559    /// A weaker version of the base danger color.
560    pub weak: Pair,
561    /// A stronger version of the base danger color.
562    pub strong: Pair,
563}
564
565impl Danger {
566    /// Generates a set of [`Danger`] colors from the base, background, and text colors.
567    pub fn generate(base: Color, background: Color, text: Color) -> Self {
568        let weak = mix(base, background, 0.4);
569        let strong = deviate(base, 0.1);
570
571        Self {
572            base: Pair::new(base, text),
573            weak: Pair::new(weak, text),
574            strong: Pair::new(strong, text),
575        }
576    }
577}
578
579fn darken(color: Color, amount: f32) -> Color {
580    let mut hsl = to_hsl(color);
581
582    hsl.lightness = if hsl.lightness - amount < 0.0 {
583        0.0
584    } else {
585        hsl.lightness - amount
586    };
587
588    from_hsl(hsl)
589}
590
591fn lighten(color: Color, amount: f32) -> Color {
592    let mut hsl = to_hsl(color);
593
594    hsl.lightness = if hsl.lightness + amount > 1.0 {
595        1.0
596    } else {
597        hsl.lightness + amount
598    };
599
600    from_hsl(hsl)
601}
602
603fn deviate(color: Color, amount: f32) -> Color {
604    if is_dark(color) {
605        lighten(color, amount)
606    } else {
607        darken(color, amount)
608    }
609}
610
611fn mix(a: Color, b: Color, factor: f32) -> Color {
612    let a_lin = Rgb::from(a).into_linear();
613    let b_lin = Rgb::from(b).into_linear();
614
615    let mixed = a_lin.mix(b_lin, factor);
616    Rgb::from_linear(mixed).into()
617}
618
619fn readable(background: Color, text: Color) -> Color {
620    if is_readable(background, text) {
621        text
622    } else {
623        let white_contrast = relative_contrast(background, Color::WHITE);
624        let black_contrast = relative_contrast(background, Color::BLACK);
625
626        if white_contrast >= black_contrast {
627            Color::WHITE
628        } else {
629            Color::BLACK
630        }
631    }
632}
633
634fn is_dark(color: Color) -> bool {
635    to_hsl(color).lightness < 0.6
636}
637
638fn is_readable(a: Color, b: Color) -> bool {
639    let a_srgb = Rgb::from(a);
640    let b_srgb = Rgb::from(b);
641
642    a_srgb.has_enhanced_contrast_text(b_srgb)
643}
644
645fn relative_contrast(a: Color, b: Color) -> f32 {
646    let a_srgb = Rgb::from(a);
647    let b_srgb = Rgb::from(b);
648
649    a_srgb.relative_contrast(b_srgb)
650}
651
652fn to_hsl(color: Color) -> Hsl {
653    Hsl::from_color(Rgb::from(color))
654}
655
656fn from_hsl(hsl: Hsl) -> Color {
657    Rgb::from_color(hsl).into()
658}