Description
Bug description
When using the light-dark
function without the postcss plugin applied and using color-scheme: normal
(or unset as this is the default), the light color is used:
https://jsfiddle.net/b0pd1yLc/2/
However, when applying the plugin output, the dark color is used:
https://jsfiddle.net/b0pd1yLc/3/
I'm aware this will be because the plugin will be wanting an explicit instruction, I think it's an error for the css result to output the dark option. I think this should instead be light by default or (perhaps preferrably) have the default passed in by an option (with light being the default).
The normal
value appears to find its value from either a page's meta tag (which this plugin won't have access to) or the browser's default color scheme (I'm not aware of any browser that has a "dark" default color-scheme). The possible requirement of the meta tag could be a good reason for the optional input parameter here.
Source CSS
:root {
color-scheme: normal;
--color-on-light: #000000;
--color-on-dark: #ffffff;
--color: light-dark(var(--color-on-light), var(--color-on-dark));
}
body {
color: var(--color);
background: red;
}
Expected CSS
:root {
--csstools-color-scheme--dark: ;
color-scheme: normal;
--color-on-light: #000000;
--color-on-dark: #ffffff;
--csstools-light-dark-toggle--0: var(--csstools-color-scheme--dark) var(--color-on-light);
--color: var(--csstools-light-dark-toggle--0, var(--color-on-dark));
}
@supports (color: light-dark(red, red)) {
:root {
--color: light-dark(var(--color-on-light), var(--color-on-dark));
}
}
:root * {
--csstools-light-dark-toggle--0: var(--csstools-color-scheme--dark) var(--color-on-light);
--color: var(--csstools-light-dark-toggle--0, var(--color-on-dark));
}
body {
color: var(--color);
background: red;
}
Actual CSS
:root {
color-scheme: normal;
--color-on-light: #000000;
--color-on-dark: #ffffff;
--csstools-light-dark-toggle--0: var(--csstools-color-scheme--dark) var(--color-on-light);
--color: var(--csstools-light-dark-toggle--0, var(--color-on-dark));
}
@supports (color: light-dark(red, red)) {
:root {
--color: light-dark(var(--color-on-light), var(--color-on-dark));
}
}
:root * {
--csstools-light-dark-toggle--0: var(--csstools-color-scheme--dark) var(--color-on-light);
--color: var(--csstools-light-dark-toggle--0, var(--color-on-dark));
}
body {
color: var(--color);
background: red;
}
Playgound example
Does it happen with npx @csstools/csstools-cli <plugin-name> minimal-example.css
?
None
Debug output
No response
Extra config
No response
What plugin are you experiencing this issue on?
PostCSS Light Dark Function
Plugin version
2.0.1
What OS are you experiencing this on?
Windows
Node Version
18.20.3
Validations
- Follow our Code of Conduct
- Check that there isn't already an issue that request the same feature to avoid creating a duplicate.
Would you like to open a PR for this bug?
- I'm willing to open a PR
Activity