swc icon indicating copy to clipboard operation
swc copied to clipboard

Improve parsing of CSS `@container`

Open yisibl opened this issue 3 years ago • 11 comments

Describe the feature

Container Query is a very important new CSS feature that browsers are actively implementing. Currently, Chrome 105+ and Safari 16+ are shipped.

  • https://caniuse.com/css-container-queries
  • Spec https://drafts.csswg.org/css-contain-3/#container-rule
  • Disallow and/not/or from https://chromium-review.googlesource.com/c/chromium/src/+/3698402
@supports ( container-type: size ) {
  @container ( width <= 150px ) {
    #inner {
      background-color: skyblue;
    }
  }
}

yisibl avatar Aug 07 '22 03:08 yisibl

Hm, but we already supported this, do you check this?

We only need to improve Containters units (new in spec) here

alexander-akait avatar Aug 10 '22 12:08 alexander-akait

@alexander-akait It seems to parse into PreservedToken in many places. https://swc-css.netlify.app/?code=eJxzSM7PK0nMzEstUtBQKM9MKclQsLFVMDQ1KKhQ0FSoruXS11IoK1bQ0udyyE1NyUzErgoA8PIUcw

@container ( width <= 150px ) {}
/* vs */
@media ( width <= 150px ) {}

yisibl avatar Aug 10 '22 13:08 yisibl

hm, I see, I will look at this

alexander-akait avatar Aug 10 '22 13:08 alexander-akait

That's great.

I have a table documenting the differences between the different parsers, please help to see if there are any errors or omissions.

image

yisibl avatar Aug 10 '22 13:08 yisibl

Thank you for the table, @font-feature-values is already in my todo (today/tomorrow), can you provide link on

  • @scroll-timeline
  • @position-fallback

alexander-akait avatar Aug 10 '22 13:08 alexander-akait

Yes, see https://www.yuque.com/docs/share/593d42c7-14c7-4be4-8af2-fe15b1bdb889?#rNXU password: rn5p

Both of these are very unstable. I think the current swc has no need to implement them.

yisibl avatar Aug 10 '22 13:08 yisibl

Add a special case:

both of these are valid, with not being part of the condition rather than the name. If implementations are getting that wrong, we should at least create a WPT, and file bugs - and potentially clarify the spec. https://github.com/w3c/csswg-drafts/issues/7203#issuecomment-1183737711

@container not (width <= 500px ) { … }
@container name not (width <= 500px) { … }

yisibl avatar Aug 13 '22 04:08 yisibl

WIP in @container

alexander-akait avatar Sep 27 '22 02:09 alexander-akait

Latest spec https://drafts.csswg.org/css-contain-3/#container-rule

alexander-akait avatar Oct 06 '22 21:10 alexander-akait

Hi @alexander-akait Are you still going to work on this?

yisibl avatar Aug 18 '23 07:08 yisibl