Skip to main content

leptos_css/
color_adjust.rs

1use std::fmt;
2
3use crate::checked_value::impl_checked_value;
4use crate::serialization::CssWriteTo;
5
6/// Values for the modern `forced-color-adjust` property.
7///
8/// [CSS Color Adjustment § 3.2]: https://www.w3.org/TR/css-color-adjust-1/#forced-color-adjust-prop
9#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
10#[non_exhaustive]
11pub enum ForcedColorAdjust {
12    /// Allow the user agent to adjust colors in forced-colors mode.
13    Auto,
14    /// Prevent automatic color adjustment.
15    None,
16    /// Preserve the parent's used color while otherwise behaving like `none`.
17    PreserveParentColor,
18}
19
20impl CssWriteTo for ForcedColorAdjust {
21    fn css_fmt<W: fmt::Write>(&self, w: &mut W) -> fmt::Result {
22        w.write_str(match self {
23            Self::Auto => "auto",
24            Self::None => "none",
25            Self::PreserveParentColor => "preserve-parent-color",
26        })
27    }
28}
29
30/// Values for the modern `print-color-adjust` property.
31///
32/// [CSS Color Adjustment § 4.1]: https://www.w3.org/TR/css-color-adjust-1/#print-color-adjust
33#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
34#[non_exhaustive]
35pub enum PrintColorAdjust {
36    /// Allow output-device economy adjustments.
37    Economy,
38    /// Preserve the specified colors and styling where possible.
39    Exact,
40}
41
42impl CssWriteTo for PrintColorAdjust {
43    fn css_fmt<W: fmt::Write>(&self, w: &mut W) -> fmt::Result {
44        w.write_str(match self {
45            Self::Economy => "economy",
46            Self::Exact => "exact",
47        })
48    }
49}
50
51impl_checked_value!(ForcedColorAdjust, PrintColorAdjust);