mirror of
https://github.com/protesilaos/modus-themes.git
synced 2026-09-10 07:16:30 -04:00
Refine modus-themes-wcag-formula and write a test for it
This commit is contained in:
parent
f062c8d99a
commit
953ec93841
|
|
@ -3764,12 +3764,12 @@ ready (per <https://github.com/protesilaos/modus-themes/issues/198>)."
|
|||
(defun modus-themes-wcag-formula (hex-color)
|
||||
"Get WCAG value of color value HEX-COLOR.
|
||||
The value is defined in hexadecimal RGB notation, such #123456."
|
||||
(let ((channels (modus-themes--hex-to-rgb hex-color))
|
||||
(weights '(0.2126 0.7152 0.0722))
|
||||
(contribution nil))
|
||||
(while channels
|
||||
(push (modus-themes--wcag-contribution (pop channels) (pop weights)) contribution))
|
||||
(apply #'+ contribution)))
|
||||
(when-let* ((channels (modus-themes--hex-to-rgb hex-color)))
|
||||
(let ((weights '(0.2126 0.7152 0.0722))
|
||||
(contribution nil))
|
||||
(while channels
|
||||
(push (modus-themes--wcag-contribution (pop channels) (pop weights)) contribution))
|
||||
(apply #'+ contribution))))
|
||||
|
||||
;;;###autoload
|
||||
(defun modus-themes-contrast (hex-color-1 hex-color-2)
|
||||
|
|
|
|||
|
|
@ -63,6 +63,12 @@
|
|||
(should-not (modus-themes--hex-to-rgb "#gggggg"))
|
||||
(should-error (modus-themes--hex-to-rgb (list 1.0 1.0 1.0))))
|
||||
|
||||
(ert-deftest mtt-modus-themes-wcag-formula ()
|
||||
"Test that `modus-themes-wcag-formula' does the right thing.
|
||||
Also see `modus-themes-test--modus-themes--hex-to-rgb'."
|
||||
(should (= (modus-themes-wcag-formula "#ffffff") 1.0))
|
||||
(should (= (modus-themes-wcag-formula "#000000") 0.0))
|
||||
(should-not (modus-themes-wcag-formula "#00000")))
|
||||
(ert-deftest mtt-inheritance ()
|
||||
"Ensure all faces inherit from valid faces."
|
||||
;; Third-party packages, loaded if possible to better test face inheritance.
|
||||
|
|
|
|||
Loading…
Reference in a new issue