gadenbuie / countdown

⏲ countdown timer for R Markdown slides and HTML docs
https://pkg.garrickadenbuie.com/countdown
150 stars 15 forks source link

Implementing `choose_light_or_dark()` outside of R #51

Open coatless opened 9 months ago

coatless commented 9 months ago

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}:

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?

gadenbuie commented 9 months ago

In Python, two popular packages we could use appear to be:

  1. colour
  2. basic-colormath

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.

coatless commented 9 months ago

@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:

Glancing at dependencies, we also have:

Lastly, for releases, we have:

Maybe we opt for basic-colormath over colour as we don't need that extensive of features?