From ee01a2b4210efa300ff6944a67906eb955b6e5cf Mon Sep 17 00:00:00 2001 From: Martin Ball <98639962+benandez@users.noreply.github.com> Date: Mon, 23 Nov 2026 13:48:29 +0000 Subject: [PATCH] theme: dark-mode accent buttons show a visible hover (wordcraft#7317 C7-14) (#3124) * theme: dark-mode accent buttons show a visible hover (wordcraft#7317 C7-14) accent.strong_hover/pressed offset the rest fill by the ramp distance from accent.solid to accent.hover/pressed. A light dark-mode seed leaves those ramp steps 0.01 OKLCH-L apart, so the hover was invisible; and a fill near white or black clamped. The offset now has a floor (hover 0.06, pressed 0.10) and flips toward the text when there is no room away from it. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01FypgCZhHKRuRB5wZUiw6BE * theme: explain names the shift's floor and flip Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01FypgCZhHKRuRB5wZUiw6BE * wordcraft#7317 C7-14: test that explaining the dark accent hover names its base and its lightness floor Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01FypgCZhHKRuRB5wZUiw6BE --------- Co-authored-by: Claude Opus 5.5 --- crates/theme/src/derive.rs | 24 ++++---- crates/theme/src/explain.rs | 10 +++- crates/theme/src/values.rs | 16 +++++- .../tokens/adwaita-light-high-comfortable.txt | 4 +- .../tokens/adwaita-light-high-compact.txt | 4 +- .../adwaita-light-standard-comfortable.txt | 4 +- .../tokens/adwaita-light-standard-compact.txt | 4 +- .../tokens/artcraft-dark-high-comfortable.txt | 4 +- .../tokens/artcraft-dark-high-compact.txt | 4 +- .../artcraft-dark-standard-comfortable.txt | 4 +- .../tokens/artcraft-dark-standard-compact.txt | 4 +- .../tokens/breeze-dark-high-comfortable.txt | 4 +- .../dumps/tokens/breeze-dark-high-compact.txt | 4 +- .../breeze-dark-standard-comfortable.txt | 4 +- .../tokens/breeze-dark-standard-compact.txt | 4 +- .../tokens/graphite-dark-high-comfortable.txt | 4 +- .../tokens/graphite-dark-high-compact.txt | 4 +- .../graphite-dark-standard-comfortable.txt | 4 +- .../tokens/graphite-dark-standard-compact.txt | 4 +- .../tokens/pro-dark-high-comfortable.txt | 4 +- .../dumps/tokens/pro-dark-high-compact.txt | 4 +- ...ro-dark-standard-comfortable-app-sizes.txt | 4 +- .../tokens/pro-dark-standard-comfortable.txt | 4 +- .../tokens/pro-dark-standard-compact.txt | 4 +- .../tokens/soft-dark-high-comfortable.txt | 4 +- .../dumps/tokens/soft-dark-high-compact.txt | 4 +- .../tokens/soft-dark-standard-comfortable.txt | 4 +- .../tokens/soft-dark-standard-compact.txt | 4 +- .../tokens/soft-light-high-comfortable.txt | 2 +- .../dumps/tokens/soft-light-high-compact.txt | 2 +- .../soft-light-standard-comfortable.txt | 2 +- .../tokens/soft-light-standard-compact.txt | 2 +- .../tokens/studio-dark-high-comfortable.txt | 4 +- .../dumps/tokens/studio-dark-high-compact.txt | 4 +- .../studio-dark-standard-comfortable.txt | 4 +- .../tokens/studio-dark-standard-compact.txt | 4 +- crates/theme/tests/main.rs | 1 + crates/theme/tests/strong_hover.rs | 55 +++++++++++++++++++ 38 files changed, 153 insertions(+), 77 deletions(-) create mode 100644 crates/theme/tests/strong_hover.rs diff --git a/crates/theme/src/derive.rs b/crates/theme/src/derive.rs index 2c3a1f2a4..95b4eca58 100644 --- a/crates/theme/src/derive.rs +++ b/crates/theme/src/derive.rs @@ -201,8 +201,8 @@ fn derived_values(unpinned: &ColorTokens, before_pass: &ColorTokens, pinned: &BT } Source::Same(other) | Source::SolidFrom(other) => unpinned.get(other), Source::Faded(other, a) => unpinned.get(other).with_alpha(a), - Source::ShiftedFrom { base, from, to, away_from } => { - shifted(unpinned.get(base), unpinned.get(from), unpinned.get(to), unpinned.get(away_from)) + Source::ShiftedFrom { base, from, to, away_from, min } => { + shifted(unpinned.get(base), unpinned.get(from), unpinned.get(to), unpinned.get(away_from), min) } // Lit like the anchored greys: from the panel's own value, pinned or not. Source::Lighting(amount) => lighting(before_pass.surface.panel, amount), @@ -411,8 +411,8 @@ fn follow(c: &mut ColorTokens, ramp: &ColorTokens, pinned: &BTreeSet Source::Faded(other, a) => c.set(t, c.get(other).with_alpha(a)), Source::Lighting(amount) => c.set(t, lighting(c.surface.panel, amount)), Source::SolidFrom(other) if on_solid => c.set(t, c.get(other)), - Source::ShiftedFrom { base, from, to, away_from } if on_solid => { - c.set(t, shifted(c.get(base), ramp.get(from), ramp.get(to), c.get(away_from))) + Source::ShiftedFrom { base, from, to, away_from, min } if on_solid => { + c.set(t, shifted(c.get(base), ramp.get(from), ramp.get(to), c.get(away_from), min)) } Source::OnSolid(solids) if on_solid => c.set(t, best_extreme(c, solids)), _ => {} @@ -435,11 +435,15 @@ fn lighting(panel: Rgba, amount: f64) -> Rgba { } /// `base` with its OKLCH lightness moved by the distance between `from` and `to`, away from -/// `text`: darker under lighter text, lighter under darker. Clamped to 0..=1, hue and chroma kept. -fn shifted(base: Rgba, from: Rgba, to: Rgba, text: Rgba) -> Rgba { +/// `text`: darker under lighter text, lighter under darker, by at least `min`. Toward `text` instead when there is no room. Clamped to 0..=1, hue and chroma kept. +fn shifted(base: Rgba, from: Rgba, to: Rgba, text: Rgba, min: f64) -> Rgba { let o = base.to_oklch(); - let step = (to.to_oklch().l - from.to_oklch().l).abs(); - let sign = if relative_luminance(text) >= relative_luminance(base) { -1.0 } else { 1.0 }; + let step = (to.to_oklch().l - from.to_oklch().l).abs().max(min); + let mut sign = if relative_luminance(text) >= relative_luminance(base) { -1.0 } else { 1.0 }; + // A base too close to white or black to move that far away from the text moves toward it. + if !(0.0..=1.0).contains(&(o.l + sign * step)) { + sign = -sign; + } Oklch { l: (o.l + sign * step).clamp(0.0, 1.0), ..o }.to_rgba().with_alpha(base.a()) } @@ -512,8 +516,8 @@ fn fix_rule(c: &mut ColorTokens, pass: &Pass, rule: &PairRule, done: &[PairRule] { match values::source(t, pass.mode) { Source::SolidFrom(other) => c.set(t, c.get(other)), - Source::ShiftedFrom { base, from, to, away_from } => { - c.set(t, shifted(c.get(base), pass.ramp.get(from), pass.ramp.get(to), c.get(away_from))); + Source::ShiftedFrom { base, from, to, away_from, min } => { + c.set(t, shifted(c.get(base), pass.ramp.get(from), pass.ramp.get(to), c.get(away_from), min)); } _ => {} } diff --git a/crates/theme/src/explain.rs b/crates/theme/src/explain.rs index 06d16ed5d..39e717cde 100644 --- a/crates/theme/src/explain.rs +++ b/crates/theme/src/explain.rs @@ -126,9 +126,13 @@ fn source_words(source: ColorSource, anchored_on: Option) -> String ColorSource::Fixed(c) => format!("fixed {}", c.to_hex()), ColorSource::Oklch(l, c, h) => format!("oklch {l} {c} {h}"), ColorSource::Same(t) | ColorSource::SolidFrom(t) => format!("= {}", t.path()), - ColorSource::ShiftedFrom { base, from, to, away_from } => { - format!("= {} moved away from {} as far as {} lies from {}", base.path(), away_from.path(), to.path(), from.path()) - } + ColorSource::ShiftedFrom { base, from, to, away_from, min } => format!( + "= {} moved away from {} as far as {} lies from {}, at least {min} lightness (toward it when there is no room)", + base.path(), + away_from.path(), + to.path(), + from.path() + ), ColorSource::OnSolid([only]) => format!("white or black on {}", only.path()), ColorSource::OnSolid(solids) => match solids.first() { Some(first) => format!("white or black on {} and {} more solids", first.path(), solids.len() - 1), diff --git a/crates/theme/src/values.rs b/crates/theme/src/values.rs index 88c236806..d7e547f67 100644 --- a/crates/theme/src/values.rs +++ b/crates/theme/src/values.rs @@ -98,6 +98,9 @@ pub enum ColorSource { to: ColorToken, /// The text the fill moves away from. away_from: ColorToken, + /// The least OKLCH lightness distance from `base`, so a variant under a seed whose ramp + /// steps lie close together (a light dark-mode accent) still shows. + min: f64, }, /// White or black, whichever has the higher lowest contrast on all of these tokens. OnSolid(&'static [ColorToken]), @@ -137,6 +140,11 @@ const SOLID_HOVER: usize = 10; /// `status..solid_pressed`). const SOLID_PRESSED: (usize, usize, f64) = (10, 11, 0.5); +/// The least OKLCH lightness a hovered `accent.strong` moves from rest, and a pressed one. The +/// dark ramp's steps 9 and 10 lie 0.01 apart for a light seed, which hides the hover. +const STRONG_HOVER_MIN: f64 = 0.06; +const STRONG_PRESSED_MIN: f64 = 0.10; + /// How far a bevel's lit edge (`edge.light`) lies above `surface.panel` in OKLCH lightness, in /// either mode. Windows 2000's #d4d0c8 face (L 0.86) has a white lit edge. pub const BEVEL_LIT: f64 = 0.15; @@ -225,8 +233,12 @@ pub(super) fn source(token: ColorToken, mode: Mode) -> ColorSource { T::AccentHover => Accent(SOLID_HOVER), T::AccentPressed => AccentMix { from: pressed_from, to: pressed_to, t: pressed_t }, T::AccentStrong => SolidFrom(T::AccentSolid), - T::AccentStrongHover => ShiftedFrom { base: T::AccentStrong, from: T::AccentSolid, to: T::AccentHover, away_from: T::TextOnStrong }, - T::AccentStrongPressed => ShiftedFrom { base: T::AccentStrong, from: T::AccentSolid, to: T::AccentPressed, away_from: T::TextOnStrong }, + T::AccentStrongHover => { + ShiftedFrom { base: T::AccentStrong, from: T::AccentSolid, to: T::AccentHover, away_from: T::TextOnStrong, min: STRONG_HOVER_MIN } + } + T::AccentStrongPressed => { + ShiftedFrom { base: T::AccentStrong, from: T::AccentSolid, to: T::AccentPressed, away_from: T::TextOnStrong, min: STRONG_PRESSED_MIN } + } T::AccentSoft => Accent(pick(4, 3)), T::AccentBorder => Same(T::AccentSolid), T::AccentText => Accent(11), diff --git a/crates/theme/tests/dumps/tokens/adwaita-light-high-comfortable.txt b/crates/theme/tests/dumps/tokens/adwaita-light-high-comfortable.txt index ba22ece3c..a5df8335a 100644 --- a/crates/theme/tests/dumps/tokens/adwaita-light-high-comfortable.txt +++ b/crates/theme/tests/dumps/tokens/adwaita-light-high-comfortable.txt @@ -29,8 +29,8 @@ accent.solid = #0058adff accent.hover = #0058adff accent.pressed = #0958abff accent.strong = #0058adff -accent.strong_hover = #004c98ff -accent.strong_pressed = #004182ff +accent.strong_hover = #00488fff +accent.strong_pressed = #003d7cff accent.soft = #3584e428 accent.border = #486c99ff accent.text = #034d98ff diff --git a/crates/theme/tests/dumps/tokens/adwaita-light-high-compact.txt b/crates/theme/tests/dumps/tokens/adwaita-light-high-compact.txt index 3554b2ce5..e8795b6cb 100644 --- a/crates/theme/tests/dumps/tokens/adwaita-light-high-compact.txt +++ b/crates/theme/tests/dumps/tokens/adwaita-light-high-compact.txt @@ -29,8 +29,8 @@ accent.solid = #0058adff accent.hover = #0058adff accent.pressed = #0958abff accent.strong = #0058adff -accent.strong_hover = #004c98ff -accent.strong_pressed = #004182ff +accent.strong_hover = #00488fff +accent.strong_pressed = #003d7cff accent.soft = #3584e428 accent.border = #486c99ff accent.text = #034d98ff diff --git a/crates/theme/tests/dumps/tokens/adwaita-light-standard-comfortable.txt b/crates/theme/tests/dumps/tokens/adwaita-light-standard-comfortable.txt index 63fe211c0..c065544ae 100644 --- a/crates/theme/tests/dumps/tokens/adwaita-light-standard-comfortable.txt +++ b/crates/theme/tests/dumps/tokens/adwaita-light-standard-comfortable.txt @@ -29,8 +29,8 @@ accent.solid = #3584e4ff accent.hover = #2977d3ff accent.pressed = #226abeff accent.strong = #2676d5ff -accent.strong_hover = #1569c7ff -accent.strong_pressed = #005bb6ff +accent.strong_hover = #0b63c1ff +accent.strong_pressed = #0058b0ff accent.soft = #3584e428 accent.border = #3584e482 accent.text = #1b5daaff diff --git a/crates/theme/tests/dumps/tokens/adwaita-light-standard-compact.txt b/crates/theme/tests/dumps/tokens/adwaita-light-standard-compact.txt index 23dc33c17..d9bc4ccb0 100644 --- a/crates/theme/tests/dumps/tokens/adwaita-light-standard-compact.txt +++ b/crates/theme/tests/dumps/tokens/adwaita-light-standard-compact.txt @@ -29,8 +29,8 @@ accent.solid = #3584e4ff accent.hover = #2977d3ff accent.pressed = #226abeff accent.strong = #2676d5ff -accent.strong_hover = #1569c7ff -accent.strong_pressed = #005bb6ff +accent.strong_hover = #0b63c1ff +accent.strong_pressed = #0058b0ff accent.soft = #3584e428 accent.border = #3584e482 accent.text = #1b5daaff diff --git a/crates/theme/tests/dumps/tokens/artcraft-dark-high-comfortable.txt b/crates/theme/tests/dumps/tokens/artcraft-dark-high-comfortable.txt index b0d40cfd8..2f3fbcc18 100644 --- a/crates/theme/tests/dumps/tokens/artcraft-dark-high-comfortable.txt +++ b/crates/theme/tests/dumps/tokens/artcraft-dark-high-comfortable.txt @@ -29,8 +29,8 @@ accent.solid = #bbdaffff accent.hover = #7cb0f8ff accent.pressed = #88b8fcff accent.strong = #405b7aff -accent.strong_hover = #3d5877ff -accent.strong_pressed = #375170ff +accent.strong_hover = #304a68ff +accent.strong_pressed = #26405dff accent.soft = #595959ff accent.border = #bbdaffff accent.text = #ffffffff diff --git a/crates/theme/tests/dumps/tokens/artcraft-dark-high-compact.txt b/crates/theme/tests/dumps/tokens/artcraft-dark-high-compact.txt index 5b977fb8e..0a385ba6a 100644 --- a/crates/theme/tests/dumps/tokens/artcraft-dark-high-compact.txt +++ b/crates/theme/tests/dumps/tokens/artcraft-dark-high-compact.txt @@ -29,8 +29,8 @@ accent.solid = #bbdaffff accent.hover = #7cb0f8ff accent.pressed = #88b8fcff accent.strong = #405b7aff -accent.strong_hover = #3d5877ff -accent.strong_pressed = #375170ff +accent.strong_hover = #304a68ff +accent.strong_pressed = #26405dff accent.soft = #595959ff accent.border = #bbdaffff accent.text = #ffffffff diff --git a/crates/theme/tests/dumps/tokens/artcraft-dark-standard-comfortable.txt b/crates/theme/tests/dumps/tokens/artcraft-dark-standard-comfortable.txt index b49f3d406..22be22a74 100644 --- a/crates/theme/tests/dumps/tokens/artcraft-dark-standard-comfortable.txt +++ b/crates/theme/tests/dumps/tokens/artcraft-dark-standard-comfortable.txt @@ -29,8 +29,8 @@ accent.solid = #378ef0ff accent.hover = #7cb0f8ff accent.pressed = #88b8fcff accent.strong = #1b77d7ff -accent.strong_hover = #1674d4ff -accent.strong_pressed = #066ccbff +accent.strong_hover = #0065c0ff +accent.strong_pressed = #005aacff accent.soft = #6e6e6eff accent.border = #378ef0ff accent.text = #bad6ffff diff --git a/crates/theme/tests/dumps/tokens/artcraft-dark-standard-compact.txt b/crates/theme/tests/dumps/tokens/artcraft-dark-standard-compact.txt index 0ba56544c..4e730d0c7 100644 --- a/crates/theme/tests/dumps/tokens/artcraft-dark-standard-compact.txt +++ b/crates/theme/tests/dumps/tokens/artcraft-dark-standard-compact.txt @@ -29,8 +29,8 @@ accent.solid = #378ef0ff accent.hover = #7cb0f8ff accent.pressed = #88b8fcff accent.strong = #1b77d7ff -accent.strong_hover = #1674d4ff -accent.strong_pressed = #066ccbff +accent.strong_hover = #0065c0ff +accent.strong_pressed = #005aacff accent.soft = #6e6e6eff accent.border = #378ef0ff accent.text = #bad6ffff diff --git a/crates/theme/tests/dumps/tokens/breeze-dark-high-comfortable.txt b/crates/theme/tests/dumps/tokens/breeze-dark-high-comfortable.txt index 63232a4a9..ebe84fb81 100644 --- a/crates/theme/tests/dumps/tokens/breeze-dark-high-comfortable.txt +++ b/crates/theme/tests/dumps/tokens/breeze-dark-high-comfortable.txt @@ -29,8 +29,8 @@ accent.solid = #3aace8ff accent.hover = #42afeaff accent.pressed = #5bbcf4ff accent.strong = #005d92ff -accent.strong_hover = #005a8eff -accent.strong_pressed = #004e7cff +accent.strong_hover = #004c78ff +accent.strong_pressed = #004168ff accent.soft = #3aace828 accent.border = #5199c2ff accent.text = #59c1f7ff diff --git a/crates/theme/tests/dumps/tokens/breeze-dark-high-compact.txt b/crates/theme/tests/dumps/tokens/breeze-dark-high-compact.txt index 0396a31f7..0135cd446 100644 --- a/crates/theme/tests/dumps/tokens/breeze-dark-high-compact.txt +++ b/crates/theme/tests/dumps/tokens/breeze-dark-high-compact.txt @@ -29,8 +29,8 @@ accent.solid = #3aace8ff accent.hover = #42afeaff accent.pressed = #5bbcf4ff accent.strong = #005d92ff -accent.strong_hover = #005a8eff -accent.strong_pressed = #004e7cff +accent.strong_hover = #004c78ff +accent.strong_pressed = #004168ff accent.soft = #3aace828 accent.border = #5199c2ff accent.text = #59c1f7ff diff --git a/crates/theme/tests/dumps/tokens/breeze-dark-standard-comfortable.txt b/crates/theme/tests/dumps/tokens/breeze-dark-standard-comfortable.txt index 7ed21e9d8..8272db54d 100644 --- a/crates/theme/tests/dumps/tokens/breeze-dark-standard-comfortable.txt +++ b/crates/theme/tests/dumps/tokens/breeze-dark-standard-comfortable.txt @@ -29,8 +29,8 @@ accent.solid = #3aace8ff accent.hover = #42afeaff accent.pressed = #5bbcf4ff accent.strong = #1e76b0ff -accent.strong_hover = #1a73adff -accent.strong_pressed = #00669fff +accent.strong_hover = #00649cff +accent.strong_pressed = #00588aff accent.soft = #3aace828 accent.border = #3aace8a0 accent.text = #50b8eeff diff --git a/crates/theme/tests/dumps/tokens/breeze-dark-standard-compact.txt b/crates/theme/tests/dumps/tokens/breeze-dark-standard-compact.txt index a7302c03a..24ec62b73 100644 --- a/crates/theme/tests/dumps/tokens/breeze-dark-standard-compact.txt +++ b/crates/theme/tests/dumps/tokens/breeze-dark-standard-compact.txt @@ -29,8 +29,8 @@ accent.solid = #3aace8ff accent.hover = #42afeaff accent.pressed = #5bbcf4ff accent.strong = #1e76b0ff -accent.strong_hover = #1a73adff -accent.strong_pressed = #00669fff +accent.strong_hover = #00649cff +accent.strong_pressed = #00588aff accent.soft = #3aace828 accent.border = #3aace8a0 accent.text = #50b8eeff diff --git a/crates/theme/tests/dumps/tokens/graphite-dark-high-comfortable.txt b/crates/theme/tests/dumps/tokens/graphite-dark-high-comfortable.txt index c555f0968..a7d4050fd 100644 --- a/crates/theme/tests/dumps/tokens/graphite-dark-high-comfortable.txt +++ b/crates/theme/tests/dumps/tokens/graphite-dark-high-comfortable.txt @@ -29,8 +29,8 @@ accent.solid = #5394feff accent.hover = #5796feff accent.pressed = #78abffff accent.strong = #1354b9ff -accent.strong_hover = #054aaeff -accent.strong_pressed = #003a90ff +accent.strong_hover = #0042a2ff +accent.strong_pressed = #00398dff accent.soft = #12284cff accent.border = #5394feff accent.text = #98bfffff diff --git a/crates/theme/tests/dumps/tokens/graphite-dark-high-compact.txt b/crates/theme/tests/dumps/tokens/graphite-dark-high-compact.txt index fc1b901b6..922fd9372 100644 --- a/crates/theme/tests/dumps/tokens/graphite-dark-high-compact.txt +++ b/crates/theme/tests/dumps/tokens/graphite-dark-high-compact.txt @@ -29,8 +29,8 @@ accent.solid = #5394feff accent.hover = #5796feff accent.pressed = #78abffff accent.strong = #1354b9ff -accent.strong_hover = #054aaeff -accent.strong_pressed = #003a90ff +accent.strong_hover = #0042a2ff +accent.strong_pressed = #00398dff accent.soft = #12284cff accent.border = #5394feff accent.text = #98bfffff diff --git a/crates/theme/tests/dumps/tokens/graphite-dark-standard-comfortable.txt b/crates/theme/tests/dumps/tokens/graphite-dark-standard-comfortable.txt index 562581bf6..6afa4a9a6 100644 --- a/crates/theme/tests/dumps/tokens/graphite-dark-standard-comfortable.txt +++ b/crates/theme/tests/dumps/tokens/graphite-dark-standard-comfortable.txt @@ -29,8 +29,8 @@ accent.solid = #4b8bf5ff accent.hover = #5796feff accent.pressed = #78abffff accent.strong = #3573dbff -accent.strong_hover = #2b69d0ff -accent.strong_pressed = #1856bbff +accent.strong_hover = #2360c7ff +accent.strong_pressed = #1554b9ff accent.soft = #12284cff accent.border = #4b8bf5ff accent.text = #98bfffff diff --git a/crates/theme/tests/dumps/tokens/graphite-dark-standard-compact.txt b/crates/theme/tests/dumps/tokens/graphite-dark-standard-compact.txt index e32cb92a0..1abb09722 100644 --- a/crates/theme/tests/dumps/tokens/graphite-dark-standard-compact.txt +++ b/crates/theme/tests/dumps/tokens/graphite-dark-standard-compact.txt @@ -29,8 +29,8 @@ accent.solid = #4b8bf5ff accent.hover = #5796feff accent.pressed = #78abffff accent.strong = #3573dbff -accent.strong_hover = #2b69d0ff -accent.strong_pressed = #1856bbff +accent.strong_hover = #2360c7ff +accent.strong_pressed = #1554b9ff accent.soft = #12284cff accent.border = #4b8bf5ff accent.text = #98bfffff diff --git a/crates/theme/tests/dumps/tokens/pro-dark-high-comfortable.txt b/crates/theme/tests/dumps/tokens/pro-dark-high-comfortable.txt index ba90588d1..f1c1f78c0 100644 --- a/crates/theme/tests/dumps/tokens/pro-dark-high-comfortable.txt +++ b/crates/theme/tests/dumps/tokens/pro-dark-high-comfortable.txt @@ -29,8 +29,8 @@ accent.solid = #60a9ffff accent.hover = #469afbff accent.pressed = #6caefdff accent.strong = #0359a8ff -accent.strong_hover = #004f97ff -accent.strong_pressed = #003f7bff +accent.strong_hover = #00498cff +accent.strong_pressed = #003e79ff accent.soft = #4e4e4eff accent.border = #60a9ffff accent.text = #add1ffff diff --git a/crates/theme/tests/dumps/tokens/pro-dark-high-compact.txt b/crates/theme/tests/dumps/tokens/pro-dark-high-compact.txt index 260b9d332..122b9d21e 100644 --- a/crates/theme/tests/dumps/tokens/pro-dark-high-compact.txt +++ b/crates/theme/tests/dumps/tokens/pro-dark-high-compact.txt @@ -29,8 +29,8 @@ accent.solid = #60a9ffff accent.hover = #469afbff accent.pressed = #6caefdff accent.strong = #0359a8ff -accent.strong_hover = #004f97ff -accent.strong_pressed = #003f7bff +accent.strong_hover = #00498cff +accent.strong_pressed = #003e79ff accent.soft = #4e4e4eff accent.border = #60a9ffff accent.text = #add1ffff diff --git a/crates/theme/tests/dumps/tokens/pro-dark-standard-comfortable-app-sizes.txt b/crates/theme/tests/dumps/tokens/pro-dark-standard-comfortable-app-sizes.txt index cd99f2f3c..025871c49 100644 --- a/crates/theme/tests/dumps/tokens/pro-dark-standard-comfortable-app-sizes.txt +++ b/crates/theme/tests/dumps/tokens/pro-dark-standard-comfortable-app-sizes.txt @@ -29,8 +29,8 @@ accent.solid = #378ef0ff accent.hover = #469afbff accent.pressed = #6caefdff accent.strong = #1b77d7ff -accent.strong_hover = #056bcaff -accent.strong_pressed = #005baeff +accent.strong_hover = #0065c0ff +accent.strong_pressed = #005aacff accent.soft = #4e4e4eff accent.border = #378ef0ff accent.text = #8fc1ffff diff --git a/crates/theme/tests/dumps/tokens/pro-dark-standard-comfortable.txt b/crates/theme/tests/dumps/tokens/pro-dark-standard-comfortable.txt index 8d3cc6e7c..7860f2963 100644 --- a/crates/theme/tests/dumps/tokens/pro-dark-standard-comfortable.txt +++ b/crates/theme/tests/dumps/tokens/pro-dark-standard-comfortable.txt @@ -29,8 +29,8 @@ accent.solid = #378ef0ff accent.hover = #469afbff accent.pressed = #6caefdff accent.strong = #1b77d7ff -accent.strong_hover = #056bcaff -accent.strong_pressed = #005baeff +accent.strong_hover = #0065c0ff +accent.strong_pressed = #005aacff accent.soft = #4e4e4eff accent.border = #378ef0ff accent.text = #8fc1ffff diff --git a/crates/theme/tests/dumps/tokens/pro-dark-standard-compact.txt b/crates/theme/tests/dumps/tokens/pro-dark-standard-compact.txt index 4d1db34a0..dea952299 100644 --- a/crates/theme/tests/dumps/tokens/pro-dark-standard-compact.txt +++ b/crates/theme/tests/dumps/tokens/pro-dark-standard-compact.txt @@ -29,8 +29,8 @@ accent.solid = #378ef0ff accent.hover = #469afbff accent.pressed = #6caefdff accent.strong = #1b77d7ff -accent.strong_hover = #056bcaff -accent.strong_pressed = #005baeff +accent.strong_hover = #0065c0ff +accent.strong_pressed = #005aacff accent.soft = #4e4e4eff accent.border = #378ef0ff accent.text = #8fc1ffff diff --git a/crates/theme/tests/dumps/tokens/soft-dark-high-comfortable.txt b/crates/theme/tests/dumps/tokens/soft-dark-high-comfortable.txt index 18952e53c..b07dcff40 100644 --- a/crates/theme/tests/dumps/tokens/soft-dark-high-comfortable.txt +++ b/crates/theme/tests/dumps/tokens/soft-dark-high-comfortable.txt @@ -29,8 +29,8 @@ accent.solid = #97a8f7ff accent.hover = #8d9deaff accent.pressed = #9babf4ff accent.strong = #4251abff -accent.strong_hover = #404ea8ff -accent.strong_pressed = #35429aff +accent.strong_hover = #333f98ff +accent.strong_pressed = #2a338bff accent.soft = #8a9ae830 accent.border = #9eaadfff accent.text = #cbd4ffff diff --git a/crates/theme/tests/dumps/tokens/soft-dark-high-compact.txt b/crates/theme/tests/dumps/tokens/soft-dark-high-compact.txt index ab780edda..3d41ec819 100644 --- a/crates/theme/tests/dumps/tokens/soft-dark-high-compact.txt +++ b/crates/theme/tests/dumps/tokens/soft-dark-high-compact.txt @@ -29,8 +29,8 @@ accent.solid = #97a8f7ff accent.hover = #8d9deaff accent.pressed = #9babf4ff accent.strong = #4251abff -accent.strong_hover = #404ea8ff -accent.strong_pressed = #35429aff +accent.strong_hover = #333f98ff +accent.strong_pressed = #2a338bff accent.soft = #8a9ae830 accent.border = #9eaadfff accent.text = #cbd4ffff diff --git a/crates/theme/tests/dumps/tokens/soft-dark-standard-comfortable.txt b/crates/theme/tests/dumps/tokens/soft-dark-standard-comfortable.txt index 8fd908bc1..50eb8c6ad 100644 --- a/crates/theme/tests/dumps/tokens/soft-dark-standard-comfortable.txt +++ b/crates/theme/tests/dumps/tokens/soft-dark-standard-comfortable.txt @@ -29,8 +29,8 @@ accent.solid = #8a9ae8ff accent.hover = #8d9deaff accent.pressed = #9babf4ff accent.strong = #5668c4ff -accent.strong_hover = #5465c1ff -accent.strong_pressed = #4859b3ff +accent.strong_hover = #4656b0ff +accent.strong_pressed = #3c4aa3ff accent.soft = #8a9ae830 accent.border = #8a9ae896 accent.text = #bec8fcff diff --git a/crates/theme/tests/dumps/tokens/soft-dark-standard-compact.txt b/crates/theme/tests/dumps/tokens/soft-dark-standard-compact.txt index a25084682..0f42013cc 100644 --- a/crates/theme/tests/dumps/tokens/soft-dark-standard-compact.txt +++ b/crates/theme/tests/dumps/tokens/soft-dark-standard-compact.txt @@ -29,8 +29,8 @@ accent.solid = #8a9ae8ff accent.hover = #8d9deaff accent.pressed = #9babf4ff accent.strong = #5668c4ff -accent.strong_hover = #5465c1ff -accent.strong_pressed = #4859b3ff +accent.strong_hover = #4656b0ff +accent.strong_pressed = #3c4aa3ff accent.soft = #8a9ae830 accent.border = #8a9ae896 accent.text = #bec8fcff diff --git a/crates/theme/tests/dumps/tokens/soft-light-high-comfortable.txt b/crates/theme/tests/dumps/tokens/soft-light-high-comfortable.txt index e850c359a..f3c746a9d 100644 --- a/crates/theme/tests/dumps/tokens/soft-light-high-comfortable.txt +++ b/crates/theme/tests/dumps/tokens/soft-light-high-comfortable.txt @@ -29,7 +29,7 @@ accent.solid = #4551a5ff accent.hover = #4552a4ff accent.pressed = #46539fff accent.strong = #4151acff -accent.strong_hover = #33409aff +accent.strong_hover = #323f99ff accent.strong_pressed = #29338bff accent.soft = #6e80d82c accent.border = #6069a1ff diff --git a/crates/theme/tests/dumps/tokens/soft-light-high-compact.txt b/crates/theme/tests/dumps/tokens/soft-light-high-compact.txt index 97af99785..c947c98fd 100644 --- a/crates/theme/tests/dumps/tokens/soft-light-high-compact.txt +++ b/crates/theme/tests/dumps/tokens/soft-light-high-compact.txt @@ -29,7 +29,7 @@ accent.solid = #4551a5ff accent.hover = #4552a4ff accent.pressed = #46539fff accent.strong = #4151acff -accent.strong_hover = #33409aff +accent.strong_hover = #323f99ff accent.strong_pressed = #29338bff accent.soft = #6e80d82c accent.border = #6069a1ff diff --git a/crates/theme/tests/dumps/tokens/soft-light-standard-comfortable.txt b/crates/theme/tests/dumps/tokens/soft-light-standard-comfortable.txt index 42712d91f..2a4df05e2 100644 --- a/crates/theme/tests/dumps/tokens/soft-light-standard-comfortable.txt +++ b/crates/theme/tests/dumps/tokens/soft-light-standard-comfortable.txt @@ -29,7 +29,7 @@ accent.solid = #6e80d8ff accent.hover = #5f6fc4ff accent.pressed = #5463b0ff accent.strong = #5062beff -accent.strong_hover = #4151abff +accent.strong_hover = #4050aaff accent.strong_pressed = #36449dff accent.soft = #6e80d82c accent.border = #6e80d8aa diff --git a/crates/theme/tests/dumps/tokens/soft-light-standard-compact.txt b/crates/theme/tests/dumps/tokens/soft-light-standard-compact.txt index a6fdd365c..61a63b6c2 100644 --- a/crates/theme/tests/dumps/tokens/soft-light-standard-compact.txt +++ b/crates/theme/tests/dumps/tokens/soft-light-standard-compact.txt @@ -29,7 +29,7 @@ accent.solid = #6e80d8ff accent.hover = #5f6fc4ff accent.pressed = #5463b0ff accent.strong = #5062beff -accent.strong_hover = #4151abff +accent.strong_hover = #4050aaff accent.strong_pressed = #36449dff accent.soft = #6e80d82c accent.border = #6e80d8aa diff --git a/crates/theme/tests/dumps/tokens/studio-dark-high-comfortable.txt b/crates/theme/tests/dumps/tokens/studio-dark-high-comfortable.txt index 5d1ac5086..f348e88dc 100644 --- a/crates/theme/tests/dumps/tokens/studio-dark-high-comfortable.txt +++ b/crates/theme/tests/dumps/tokens/studio-dark-high-comfortable.txt @@ -29,8 +29,8 @@ accent.solid = #9385ffff accent.hover = #9385fdff accent.pressed = #a49cfeff accent.strong = #f6f6f8ff -accent.strong_hover = #fefeffff -accent.strong_pressed = #ffffffff +accent.strong_hover = #e2e2e4ff +accent.strong_pressed = #d5d5d7ff accent.soft = #8b7cf62e accent.border = #8884b7ff accent.text = #d6d0ffff diff --git a/crates/theme/tests/dumps/tokens/studio-dark-high-compact.txt b/crates/theme/tests/dumps/tokens/studio-dark-high-compact.txt index 9b85b13c1..e30abfb03 100644 --- a/crates/theme/tests/dumps/tokens/studio-dark-high-compact.txt +++ b/crates/theme/tests/dumps/tokens/studio-dark-high-compact.txt @@ -29,8 +29,8 @@ accent.solid = #9385ffff accent.hover = #9385fdff accent.pressed = #a49cfeff accent.strong = #f6f6f8ff -accent.strong_hover = #fefeffff -accent.strong_pressed = #ffffffff +accent.strong_hover = #e2e2e4ff +accent.strong_pressed = #d5d5d7ff accent.soft = #8b7cf62e accent.border = #8884b7ff accent.text = #d6d0ffff diff --git a/crates/theme/tests/dumps/tokens/studio-dark-standard-comfortable.txt b/crates/theme/tests/dumps/tokens/studio-dark-standard-comfortable.txt index f45f88d4d..c7dcf6cf3 100644 --- a/crates/theme/tests/dumps/tokens/studio-dark-standard-comfortable.txt +++ b/crates/theme/tests/dumps/tokens/studio-dark-standard-comfortable.txt @@ -29,8 +29,8 @@ accent.solid = #8b7cf6ff accent.hover = #9284fcff accent.pressed = #a49cfeff accent.strong = #f6f6f8ff -accent.strong_hover = #fefeffff -accent.strong_pressed = #ffffffff +accent.strong_hover = #e2e2e4ff +accent.strong_pressed = #d5d5d7ff accent.soft = #8b7cf62e accent.border = #a094ff6e accent.text = #d6d0ffff diff --git a/crates/theme/tests/dumps/tokens/studio-dark-standard-compact.txt b/crates/theme/tests/dumps/tokens/studio-dark-standard-compact.txt index 76aaa5738..464f14958 100644 --- a/crates/theme/tests/dumps/tokens/studio-dark-standard-compact.txt +++ b/crates/theme/tests/dumps/tokens/studio-dark-standard-compact.txt @@ -29,8 +29,8 @@ accent.solid = #8b7cf6ff accent.hover = #9284fcff accent.pressed = #a49cfeff accent.strong = #f6f6f8ff -accent.strong_hover = #fefeffff -accent.strong_pressed = #ffffffff +accent.strong_hover = #e2e2e4ff +accent.strong_pressed = #d5d5d7ff accent.soft = #8b7cf62e accent.border = #a094ff6e accent.text = #d6d0ffff diff --git a/crates/theme/tests/main.rs b/crates/theme/tests/main.rs index 93a7bd1fa..4d6775696 100644 --- a/crates/theme/tests/main.rs +++ b/crates/theme/tests/main.rs @@ -2,3 +2,4 @@ mod dumps; mod selection; +mod strong_hover; diff --git a/crates/theme/tests/strong_hover.rs b/crates/theme/tests/strong_hover.rs new file mode 100644 index 000000000..3714b11f6 --- /dev/null +++ b/crates/theme/tests/strong_hover.rs @@ -0,0 +1,55 @@ +//! Primary / accent buttons (`accent.strong`) must show hover and press in every built-in theme, +//! in both modes, without the text on them dropping below the text minimum (wordcraft#7317 C7-14). + +use craft_theme::contrast::contrast_ratio; +use craft_theme::{Appearance, Contrast, Mode, Size, TextSize, Variants, builtins, resolve}; + +/// Least OKLCH lightness change of hover and of press from rest. Below about 0.05 a fill change is +/// hard to see next to a neighbouring control. +const HOVER_MIN: f64 = 0.05; +const PRESSED_MIN: f64 = 0.08; + +#[test] +fn strong_accent_hover_and_pressed_are_visible_and_keep_text_contrast() { + for theme in builtins() { + // Classic pins all three states to one grey: its bevel, not the fill, shows the state. + if theme.name == "Classic" { + continue; + } + let modes = match theme.variants { + Variants::Both => vec![Mode::Light, Mode::Dark], + Variants::LightOnly => vec![Mode::Light], + Variants::DarkOnly => vec![Mode::Dark], + }; + for mode in modes { + let appearance = + Appearance { mode, contrast: Contrast::Standard, size: Size::Comfortable, text_size: TextSize::Small, reduced_motion: false }; + let c = resolve(theme, appearance, None).tokens.color; + let (rest, hover, pressed) = (c.accent.strong, c.accent.strong_hover, c.accent.strong_pressed); + let l = |x: craft_theme::color::Rgba| x.to_oklch().l; + let who = format!("{} {mode:?}", theme.name); + assert!((l(hover) - l(rest)).abs() >= HOVER_MIN, "{who}: hover barely differs from rest"); + assert!((l(pressed) - l(rest)).abs() >= PRESSED_MIN, "{who}: pressed barely differs from rest"); + for (state, fill) in [("rest", rest), ("hover", hover), ("pressed", pressed)] { + let ratio = contrast_ratio(c.text.on_strong, fill); + assert!(ratio >= 4.5, "{who}: text.on_strong on {state} is {ratio:.2}"); + } + } + } +} + +/// A user asking why the hover fill differs from rest is told which token it starts from and how much +/// lightness it moves at least; the floor shown is the one the colour is held to. +#[test] +fn explaining_strong_hover_names_its_base_and_the_lightness_floor() { + use craft_theme::{ColorSource, ColorToken, explain}; + let theme = builtins().iter().find(|t| t.name != "Classic" && t.variants != Variants::LightOnly).unwrap(); + let appearance = + Appearance { mode: Mode::Dark, contrast: Contrast::Standard, size: Size::Comfortable, text_size: TextSize::Small, reduced_motion: false }; + let e = explain(theme, appearance, None); + let origin = e.color(ColorToken::AccentStrongHover).unwrap(); + let ColorSource::ShiftedFrom { min, .. } = origin.source else { panic!("hover is a shifted colour: {:?}", origin.source) }; + let words = origin.source_words(); + assert!(words.contains(ColorToken::AccentStrong.path()), "names the base token: {words}"); + assert!(words.contains(&min.to_string()), "names the floor {min}: {words}"); +}