Add light-dark() support - #26
Conversation
| theme. If user want to use dark theme, you set `html.is-dark` class. | ||
| If user want to force light theme, you use `html.is-light`. | ||
|
|
||
| This plugin also supports the [light-dark()](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/light-dark) color function: |
There was a problem hiding this comment.
Too complex. Just add lines to the main example.
| return string.replace(new RegExp(escapeRegExp(find), 'g'), replace) | ||
| } | ||
|
|
||
| function addColorSchemeMedia(isDark, color, postcss, declaration) { |
There was a problem hiding this comment.
Let’s move postcss at the end, since it is complex arg
| function addColorSchemeMedia(isDark, color, postcss, declaration) { | ||
| let mediaQuery = postcss.atRule({ | ||
| name: 'media', | ||
| params: `(prefers-color-scheme: ${isDark ? 'dark' : 'light'})` |
There was a problem hiding this comment.
Space will not work if you apply it after minification.
Do we have it originally? If not, let’s just remove space.
| } | ||
| }, | ||
| DeclarationExit: (declaration, { postcss }) => { | ||
| if (!declaration.value.startsWith('light-dark(')) return |
There was a problem hiding this comment.
I am not sure that all decl should start from ligh-dark().
What about: border-color: black light-dark(black, white)
| DeclarationExit: (declaration, { postcss }) => { | ||
| if (!declaration.value.startsWith('light-dark(')) return | ||
|
|
||
| let matches = [...declaration.value.matchAll(LIGHT_DARK)][0] |
There was a problem hiding this comment.
Can we have multiple light-dark() in the value?
There was a problem hiding this comment.
indeed, we might have something like radial-gradient() which can include multiple light-dark()
we can also have light-dark() inside strings, in which case we should not touch it
Co-authored-by: Andrey Sitnik <andrey@sitnik.ru>
Co-authored-by: Andrey Sitnik <andrey@sitnik.ru>
|
Thanks! Do you have Twitter and Mastodon to mention you? |
yes, I have Twitter: https://twitter.com/VladBrok99 |
Closes #25
If we try to convert code from this:
To this:
Then it will not respect the user's preferred color scheme specified via system settings.
So we also need to use
prefers-color-schememedia query.This plugin already can transform
prefers-color-scheme, so if we convert this:To this:
then the current plugin code will run and we will get the following: