Comments (7)
Yeah. We have a drafts
option in the API for this, which is where the option to enable nesting is. I think we could put this in there as well.
One other question I had from reading the spec is whether the @custom-media
declaration needs to come before it is used, or if something like this is valid:
@media (--modern) and (width > 1024px) {
.a { color: green; }
}
@custom-media --modern (color), (hover);
If that's the case, we'll need a two pass system for transforming rather than doing it during parsing.
from lightningcss.
Looked into it. There are some complicated corner cases here. For example:
@custom-media --color-print print and (color);
@custom-media --color-screen screen and (color);
@media (--color-print) or (--color-screen) {}
This would need to become two media queries since media types cannot be combined in a single query:
@media print and (color), screen and (color) {}
And if an and
were used instead, the queries would need to be nested:
@custom-media --not-print not print and (color);
@custom-media --not-screen not screen and (color);
@media (--not-print) and (--not-screen) {}
to:
@media not print and (color) {
@media not screen and (color) {}
}
In the general case, rules within the media query may even need to be duplicated:
@custom-media --not-print not print and (color);
@custom-media --not-screen not screen and (color);
@media ((script) or ((--not-print) and (--not-screen))) {
.a {
color: green;
}
}
would need to become:
@media (script) {
.a {
color: green;
}
}
@media not print and (color) {
@media not screen and (color) {
.a {
color: green;
}
}
}
This seems quite difficult to implement. The PostCSS plugin doesn't seem to do it correctly either. I might simply error on boolean logic with media types for now. Not sure how widely used that will be. The common case (e.g. open props) is to use media conditions rather than media types, which can be done with a simple substitution.
from lightningcss.
Makes sense. Do you know what the state of that spec is? How close is it to being done, and/or how likely is the syntax to change at this point?
from lightningcss.
Ohh, I wish I did! The fact that it's being used as prominently as it is in open-props
(made by chrome devrel folks) has me feeling somewhat optimistic about how far along it is.
Maybe the actual transform in parcel-css
could be exposed behind a feature flag (e.g. unstable_custom_media
) until the spec is elevated beyond the "working draft" stage?
from lightningcss.
One other question I had from reading the spec is whether the
@custom-media
declaration needs to come before it is used, or if something like this is valid:
Afaict all test cases for the PostCSS plugin define @custom-media
before it's used. I think we should follow that behavior for now, in part to be compatible with postcss
, but also because allowing use-before-declare semantics is backwards compatible 1. Which luckily is also the simpler variant to implement.
Footnotes
-
If we allow it without the spec specifically stating this is allowed, we could run into compatibility issues with the actual browser implementations later on too. ↩
from lightningcss.
Makes sense. I filed an issue on the spec to get it clarified as well: w3c/csswg-drafts#6956
from lightningcss.
Hey @devongovett, you can use @import with custom-media queries if add postcss-import
to your config. You mentioned in #60 that @import would be problem so this solution seems too easy. There are probably other complexities, but I thought I should note this for others just in case. :)
Either way, it would be nice for support this to built in so it "just worked". Until / unless this Chromium issue adds support for @custom-media
this spec looks to be moribund so maybe it doesn't matter, which is a shame since it's so useful.
from lightningcss.
Related Issues (20)
- Error: Cannot find module 'lightningcss.win32-arm64-msvc.node'
- A message about ignoring properties like postcss HOT 1
- Minifier Breaks Black Translucent Colors HOT 2
- Using Lightning as a code generator HOT 2
- Moving back to upstream `selectors`? HOT 2
- transcribes OKLCH poorly HOT 1
- Sourcemap @include paths not updated HOT 2
- Allow use of "resolver" when using through vite HOT 1
- Minification strips required whitespace between consecutive `var(...)` calls HOT 3
- Color value format HOT 4
- Lightningcss randomly drops a selector, breaking styling
- cli: mis-match between --version and npm package version HOT 1
- [Feature Request]: Support `generate(ast)` API like `csstree`
- Support `overlay` property
- Position of `all` property is not maintained HOT 3
- Add support for custom import resolvers in synchronous bundle API
- Use browserslist entry in package.json (vite)
- lots of :lang() in output HOT 3
- Lightning with Astro: Can't resolve background-image path HOT 1
- Unexpected Token Error with "all" property HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lightningcss.