pub const ACCENT: (u8, u8, u8) = (214, 137, 58);
pub const WORDMARK_TOP: (u8, u8, u8) = (255, 231, 200);
pub const WORDMARK_FOOT: (u8, u8, u8) = (232, 147, 64);
pub const USER: (u8, u8, u8) = (126, 176, 199);
pub const OK: (u8, u8, u8) = (126, 170, 126);
pub const BAD: (u8, u8, u8) = (198, 96, 96);
pub const WARN: (u8, u8, u8) = (214, 176, 90);
pub const DIM: (u8, u8, u8) = (128, 128, 128);
pub const FAINT: (u8, u8, u8) = (96, 96, 96);
pub const MUTED: (u8, u8, u8) = (150, 146, 140);
pub const RULE: (u8, u8, u8) = (112, 108, 102);
pub const FG: (u8, u8, u8) = (230, 233, 238);
pub const BG: (u8, u8, u8) = (17, 20, 24);
pub const PANEL: (u8, u8, u8) = (26, 31, 38);
pub const LINE: (u8, u8, u8) = (42, 49, 59);
pub const HOVER: (u8, u8, u8) = (34, 42, 52);
pub const INK: (u8, u8, u8) = (4, 16, 31);
pub fn luminance((r, g, b): (u8, u8, u8)) -> f64 {
fn channel(value: u8) -> f64 {
let c = f64::from(value) / 255.0;
if c <= 0.039_28 {
c / 12.92
} else {
((c + 0.055) / 1.055).powf(2.4)
}
}
0.2126 * channel(r) + 0.7152 * channel(g) + 0.0722 * channel(b)
}
pub fn contrast(a: (u8, u8, u8), b: (u8, u8, u8)) -> f64 {
let (la, lb) = (luminance(a), luminance(b));
let (lighter, darker) = if la > lb { (la, lb) } else { (lb, la) };
(lighter + 0.05) / (darker + 0.05)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn the_page_is_readable_at_aa() {
let body = contrast(FG, BG);
assert!(body >= 4.5, "body text on the page: {body:.2}:1");
let muted = contrast(MUTED, BG);
assert!(muted >= 4.5, "secondary text on the page: {muted:.2}:1");
let muted_on_panel = contrast(MUTED, PANEL);
assert!(
muted_on_panel >= 4.5,
"secondary text on a panel: {muted_on_panel:.2}:1"
);
let rule = contrast(RULE, BG);
assert!(rule >= 3.0, "a hairline on the page: {rule:.2}:1");
let accent = contrast(ACCENT, BG);
assert!(accent >= 3.0, "the accent on the page: {accent:.2}:1");
let accent_on_panel = contrast(ACCENT, PANEL);
assert!(
accent_on_panel >= 3.0,
"the accent on a panel: {accent_on_panel:.2}:1"
);
let ok = contrast(OK, BG);
assert!(ok >= 3.0, "the ok mark on the page: {ok:.2}:1");
let bad = contrast(BAD, BG);
assert!(bad >= 3.0, "the failed mark on the page: {bad:.2}:1");
let warn = contrast(WARN, BG);
assert!(warn >= 3.0, "the warning mark on the page: {warn:.2}:1");
let ink = contrast(INK, ACCENT);
assert!(ink >= 4.5, "text on an accent button: {ink:.2}:1");
}
#[test]
fn the_accent_is_the_warm_one_and_stays_warm() {
let (r, g, b) = ACCENT;
assert!(r > g && g > b, "amber, not a tint of blue: {ACCENT:?}");
assert!(
f64::from(r) - f64::from(b) > 100.0,
"enough of a difference to read as amber: {ACCENT:?}"
);
}
}