Implement our own "dark-p" which relies on our WCAG formula test

This way I can more easily reason about the return value.
This commit is contained in:
Protesilaos Stavrou 2026-01-31 09:58:21 +02:00
parent 4b4fd65336
commit 4ecefd924f
No known key found for this signature in database
GPG key ID: 99BD6459CD5CA3EA

View file

@ -4205,6 +4205,11 @@ Run `modus-themes-after-load-theme-hook' after loading a theme."
;;;;; Preview a theme palette
(defun modus-themes-color-dark-p (hex-color)
"Return non-nil if hexadecimal RGB HEX-COLOR is dark.
Test that HEX-COLOR has more contrast against white than black."
(> (modus-themes-contrast hex-color "#ffffff")
(modus-themes-contrast hex-color "#000000")))
(defun modus-themes--list-colors-get-mappings (palette)
"Get the semantic palette entries in PALETTE.
PALETTE is the value of a variable like `modus-operandi-palette'."
@ -7719,7 +7724,7 @@ rest come from CORE-PALETTE."
(unless (and bg-main fg-main)
(error "The palette must define at least a bg-main and fg-main entry with their values"))
(let* ((bg-main (car bg-main))
(bg-main-dark-p (color-dark-p (color-name-to-rgb bg-main)))
(bg-main-dark-p (modus-themes-color-dark-p bg-main))
(fg-main (car fg-main))
(six-colors (seq-filter
(lambda (color)