Repository navigation
feat(css): style() ranges and cq units weren't worked out - #109
Merged
Merged
Conversation
Range syntax in style() queries was read as unknown, so style(--gap > 1em) never held. Each value is now substituted from the container's custom properties, typed as a number or dimension and computed on the container, then compared; a value that isn't one, or two of different types, makes the range false (CSS Conditional 5 6.2). A stray ; in a style() feature makes it unknown. The cq* units fell back to the viewport everywhere. Each element now carries the width and height its nearest size containers give on each axis, inline-size containment following the container's writing mode, with the small viewport when there's none; cqi and cqb follow the element's own writing mode. In a @container prelude they're the container's own. Size queries also compute calc() with em and rem against the container, and vw against the viewport instead of the container. ContainerQuery::evaluate takes a QueryLengths and a callback for range values in place of the font size. WPT cascade and at-rules: 1,198 of 1,345 pass, from 1,141.
This was referenced Nov 19, 2026
Closed
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.
Problem
#99 left three parts of container queries out of the cascade (#100):
style()read a range likestyle(--gap > 1em)as unknown, so it never held.cqw,cqh,cqi,cqb,cqminandcqmaxalways used the viewport, even when there was a container around them.Change
All of it is in
crates/parsec-css. There are no new dependencies.Ranges in
style(), CSS Conditional 5 §6.2. You can compare two values or three, and three must all point the same way. Each value can be a custom property's name or any value withvar()in it. A value is substituted from the container's custom properties, typed as a number, percentage, length, angle, time, frequency or resolution, and computed on the container, soemis the container's. If a value can't be typed, or two values have different types, the range is false, not unknown. A unitless zero counts as a length when compared with one. A;in astyle()feature now makes the feature unknown, as WPT expects.Container query units, at computed-value time. Each element keeps the width and height of its nearest size container on each axis. With no container, it keeps the small viewport's (the environment's).
inline-sizecontainment follows the container's own writing mode, andcqiandcqbfollow the element's. Inside a@containerprelude, the units are the container's own. Ifcontainer_sizesgives no size for a container, the units look past it to the next one out. It costs a few hash lookups per element.Size queries:
calc()that mixespxwithemorremis now computed against the container.vwand the other viewport units now use the viewport, not the container.API:
ContainerQuery::evaluatetakes amedia::QueryLengths(font size, viewport, container units, writing mode) and a callback for range values, in place of the bare font size.Feature::evaluate_withis the media feature evaluator with those lengths.Shadow DOM: not done, so this is only part of Container queries: style() ranges, container query units, shadow DOM #100. The 27 shadow-tree cases build their trees with declarative shadow roots (
<template shadowrootmode>).crates/parsec's tree builder doesn't attach those: a<template>always gets an ordinary contents fragment, and the DOM has no shadow root node. That's a core change, Netweir first. The core would need:templatestart-tag steps that attach a declarative shadow root, with an option to allow them, which the fragment parser leaves off;:host,:host(),:host-context()and::slotted().After that, the cascade needs per-tree sheets, flat-tree inheritance and container lookup, and tree-scoped container names.
Tests
WPT cascade and at-rules: 1,198 of 1,345, up from 1,141. 57 cases leave
known-failures.txt:at-container-style-parsing.html;query-evaluation-style.html;container-units-in-at-container.html;calc()size queries.None started failing. Still failing in Container queries: style() ranges, container query units, shadow DOM #100's scope:
Stylerdoesn't style pseudo-elements;@keyframes, sampled part-way through an animation: there are no animations;container-units-auto.html, whose container iswidth: auto, so the runner can't size it without layout.Media queries (1,370 of 1,370), computed values and CSS parsing are unchanged.
New unit tests:
cq*units through nestedsizeandinline-sizecontainers, and the viewport fallback;em, and a type mismatch giving false;Fuzzing: the target now evaluates container queries with a range-value callback and with none, and its page has a vertical size container. It ran clean for 5 minutes: 113,816 inputs.
Cascade bench.
cargo run --release --manifest-path bench/Cargo.toml -- css, all 13 pages, median of 5 on an M2 Max. Runs were interleaved, and each started with the one-minute load under 2.8:Most of run 2's difference is
whatwg-full, and the load rose to 3.6 during that run. I read both as within noise.cargo fmt --all,cargo clippy --workspace --all-targets -- -D warnings,cargo test --workspaceandcargo deny checkpass.Part of #100