Implementing `choose_light_or_dark()` outside of R
In the R version of {countdown}, there's a quick comparison of values to select either a dark or light color value depending on what a user specifies. The relevant functions being used in R for this decision are from {prismatic}:
-
prismatic::clr_lighten()(Show stopper) -
prismatic::clr_darken()(depends onclr_lighten()) -
prismatic::best_contrast()
With #36, the CSS countdown variables now have a darkening characteristic applied:
https://github.com/gadenbuie/countdown/blob/9ee6b7fa18aadc3540031184d72a812abcd85381/lib/countdown.css#L4
From discussions in #35 we have:
I went with shading (darkening) in the CSS, but we could have tinted (lightend) as well with rgba(255, 255, 255, 0.1) or similar.
The question is how we'd know whether we should lighten or darken. But I'm okay waiting on that as well and working it out in follow up PRs.
If the CSS property color-contrast was implemented in browsers, then this would be a non-issue.
Options in the interim: JavaScript? Re-implement {prismatic} in the different languages? Wait for browser updates?
In Python, two popular packages we could use appear to be:
In Quarto, I need to play with the shortcode a little more, but I have the sense we could address this with a class, like .dark. The current assumption in the CSS is that we have dark text on a light background, and a .dark class could flip that around. Those would only work for people who only want to pick three-four colors for the states, otherwise they'd have to specify all the colors. That seems like a reasonable compromise to me.
@gadenbuie okidokie, I like both options!
Any thoughts as to the quarto-specific parameter option? color_darken: true?
Do you have any preference on the Python package? Glancing at py-htmltools, neither package suggested is being used.
https://github.com/posit-dev/py-htmltools/blob/a3a98259ee4c5164763a6f70b86e531c13a5bcc1/pyproject.toml#L30-L33
So, going over to usage statistics, we have:
-
colour: ~ 825,673 downloads last month -
basic-colormath: ~ 104 downloads last month
Glancing at dependencies, we also have:
-
colour: python, imageio, numpy, scipy, and typing-extensions. -
basic-colormathjust python.
Lastly, for releases, we have:
-
colour: Nov 19, 2017 with version 0.1.5 -
basic-colormath: May 1, 2023 with version 0.1.0
Maybe we opt for basic-colormath over colour as we don't need that extensive of features?