feat: container queries, style() and scroll-state() - #59
Open
Kristofer Baxter (kristofer-baxter) wants to merge 1 commit into
Open
feat: container queries, style() and scroll-state()#59Kristofer Baxter (kristofer-baxter) wants to merge 1 commit into
Kristofer Baxter (kristofer-baxter) wants to merge 1 commit into
Conversation
Adds scopes for `@container`: the container name, size features, logical operators, `style()` queries and `scroll-state()` queries, including grouped and boolean forms. The body carries `meta.at-rule.container.body.css` and both of its braces are scoped, matching the other block at-rules. A query in parentheses may itself be a parenthesised query, so the groups nest rather than close at the first bracket, and `<general-enclosed>` is parsed so a bracket inside a string is not read as one. A `<style-query>` is parsed recursively, so `not`, grouped queries and ranges are not read as a declaration list. A feature value is a component value, so a function may stand in for a keyword. `style()` holds a `<declaration-value>`, where a `;` nested in brackets or a balanced block is part of the value. Its declaration-value region therefore ends only at `}` or `)`, so `style(--x: [a;b])` keeps the whole value. The container name is a `<custom-ident>`, so it may begin with an escape. Only `none`, `and`, `not` and `or` are reserved, so `style` and `scroll-state` are names in their own right and only a bracket straight after either one makes it a query function. The query is optional, so a name may run into the body, and the prelude is a comma-separated list, so a name may start at a comma. The cost of a prelude is linear in its length: doubling a 12.5 KB prelude twice roughly doubles the time each step, and 50 KB takes under half a second, which is far past any real stylesheet. An unknown query function is `<general-enclosed>` wherever a query is valid, not only inside parentheses. A `)` separates the identifier that follows it, so `)and(` needs no whitespace. A style range may be written without spaces, value first, or chained, and its custom property name stops at the comparison. A size container feature takes a length or a ratio, and only `orientation` takes a keyword, so the values `@media` accepts are not query values here: `@container (width: fullscreen)` reads `fullscreen` as no more than an identifier. A malformed prelude leaks its header scope to the rest of the file, which is what `@media` already does. `@container` has no semicolon form, so `@container nonsense;` leaks with the rest of them.
Kristofer Baxter (kristofer-baxter)
force-pushed
the
oss/container-queries
branch
from
September 2, 2026 01:00
ea169c0 to
8582b5a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
1 of 6. This one applies to
mainon its own and is ready for review.It is the first of six commits that split #57. Each adds one kind of scope, and each stands on its own: no error recovery, and no change to how the grammar reads anything it already read. The five behind it are open as drafts, because a pull request from a fork can only be based on
main, and their diffs would otherwise include this one's changes.Adds scopes for
@container: the container name, size features, logical operators,style()queries andscroll-state()queries, including grouped and boolean forms. The body carriesmeta.at-rule.container.body.css, and both of its braces are scoped, matching the other block at-rules.A query in parentheses may itself be a parenthesised query, so groups nest instead of closing at the first bracket, and
<general-enclosed>is parsed so a bracket inside a string is not read as one. A<style-query>is parsed recursively, sonot, grouped queries and ranges are not read as a declaration list. A feature value is a component value, so a function may stand in for a keyword.style()holds a<declaration-value>, where a;nested in brackets or a balanced block is part of the value. Its declaration-value region therefore ends only at}or), sostyle(--x: [a;b])keeps the whole value.The container name is a
<custom-ident>, so it may begin with an escape. Onlynone,and,notandorare reserved, sostyleandscroll-stateare names in their own right, and only a bracket straight after either one makes it a query function. The query is optional, so a name may run into the body, and the prelude is a comma-separated list, so a name may start at a comma. The cost of a prelude is linear in its length: doubling a 12.5 KB prelude twice roughly doubles the time at each step, and 50 KB takes under half a second, which is well past any real stylesheet.An unknown query function is
<general-enclosed>wherever a query is valid, not only inside parentheses. A)separates the identifier that follows it, so)and(needs no whitespace. A style range may be written without spaces, value first, or chained, and its custom property name stops at the comparison.A size container feature takes a length or a ratio, and only
orientationtakes a keyword, so the values@mediaaccepts are not query values here:@container (width: fullscreen)readsfullscreenas no more than an identifier.A malformed prelude leaks its header scope to the rest of the file, which is what
@mediaalready does.@containerhas no semicolon form, so@container nonsense;leaks along with the rest.