Repository navigation
feat(css): nothing cascaded stylesheets onto a document - #94
Merged
Merged
Conversation
parsec_css::media parses a <media-query-list> as Media Queries 5 has it (types, not and only, and/or/not conditions, plain, boolean and range features including the two-sided form, ratios and math), writes it back as CSSOM's mediaText does, and evaluates it against an Environment the caller gives, with the spec's three-valued logic so an unknown feature makes its query false. parsec_css::supports evaluates @supports and CSS.supports(): declarations through the property table, selector() through Parsec's selector engine, font-format() and font-tech(). WPT's media query tests run in cargo test: scripts/wpt-media-cases.js runs each file in a Node sandbox where what a test asks the browser goes through a probe, and the Mozilla suite's viewport changes are recorded with each case. All 1,370 cases pass.
values::convert has CSS Color 4's conversions between every space (the sample code's matrices and transfer functions, through XYZ) with missing channels carried as §12.2 says, and CSS Color 5's relative colours and color-mix() worked out from them, any number of colours, premultiplied, with each hue method. Color::absolute gives a colour's channels; color-mix() keeps what it mixes, and contrast-color() and alpha(from …) parse. Also: flex's left-out parts expand to 1, 1 and 0% and white-space's legacy keywords to their longhands, which eight WPT shorthand cases now pass; Math can substitute keywords and map its leaves, which the computed values build on.
parsec_css::cascade styles a Parsec document: user agent, user and author sheets, `<style media>`, @media and @supports evaluated against the environment, @layer with nesting and anonymous layers, CSS Nesting desugared to :is(), specificity per complex selector, !important with origins and layers reversed, style="" as element-attached, then every element's computed values in tree order: inheritance, initial, inherit, unset, revert and revert-layer, `all`, custom properties resolved with the parent's and var() substituted, invalid-at-computed-value-time as unset, lengths absolute, colours worked out, and the per-property rules (font-size and font-weight keywords, line-height, border widths with no style, display blockification, opacity, filters, positions and gradients). The HTML Standard's user agent stylesheet comes with it. Rules are bucketed by their rightmost id, class, type or attribute. WPT in cargo test, each runner parsing the vendored test file itself: computed values (test_computed_value, the colour tests and the inheritance tests), 10,974 of 12,041; and css-cascade's static cases, 104 of 123. Failures are listed in each known-failures.txt. The fuzz target also parses media queries and supports conditions and cascades its input onto a small page.
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
parsec-css could type a value but not say which value an element gets: no cascade, no media query evaluation, no computed values (#30). Lexbor has none of the last two either (discussion #265).
Change
Three new modules in
parsec-html-css, which now depends onparsec-htmlfor the document and its selector engine:media:<media-query-list>per Media Queries 5 (types withnot/only,and/or/notconditions, plain, boolean and one- and two-sided range features, ratios, math), written back asmediaText, and evaluated against anEnvironmentyou give with three-valued logic, so an unknown feature makes its query false.supports:@supportsandCSS.supports(): declarations through the property table,selector()through Parsec's selector engine,font-format(),font-tech().cascade:Stylerstyles a Parsec document.HTML_UA_STYLESHEET), user and author,<style media>,@mediaand@supports.style=""as element-attached, then@layer(statements, nesting, anonymous layers, reversed for!important), then specificity per complex selector, then order of appearance.:is(), shorthands split as they cascade, andall.initial/inherit/unset/revert/revert-layer, custom properties resolved with the parent's andvar()substituted (invalid at computed-value time isunset), absolute lengths, canonical angles and times, colours worked out, and the common per-property rules (font-size and font-weight keywords, line-height, border/outline widths when no style draws them, blockification, opacity, filters, positions, gradients).Styled::get(element, property)gives the value asgetComputedStyle()writes it;style_elementstyles one element and its ancestors.values: conversion between every CSS Color 4 space (its sample code's matrices and transfer functions), missing channels carried per §12.2. CSS Color 5's relative colours andcolor-mix()(any number of colours, premultiplied, every hue method) are worked out from them. Alsocontrast-color()andalpha(from …).flex's left-out parts expand to1 1 0%, andwhite-space's legacy keywords expand to their longhands.bench/: a cascade table: every element of the 13 real pages styled.Not done, and on the wiki page: anything needing layout (
width: 50%as pixels, grid tracks,transform-originas pixels),@container,@scope,@property,@keyframes,@counter-style, and fetching@import.Tests
Three more WPT suites in
cargo test, at the same pinned commit (1a2a0c5) as #91, each extracted by a Node vm-sandbox script incrates/parsec-css/scripts(probes stand in for what a test asks the browser), each with aknown-failures.txtthe run checks both ways.scripts/fetch-wpt-cascade.sh COMMITrefreshes all three.css/mediaqueries, mostly the Mozilla suite, with its viewport changes recorded per case. 1,370 of 1,370 (applies 1,052, parses 283, serializes 35); 14 skipped (they probe more than once in a test).test_computed_value,fuzzy_test_computed_colorandinheritance-testcommon.jsfromcss/*/parsingandcss/*/inheritance*. The runner parses each vendored test file with Parsec, applies its<style>s and the UA sheet, sets#target's style as the test does in an 800×600 viewport, and checks the value and its round trip. 10,974 of 12,041 (computed 10,525/11,563, inherited 229/239, initial 220/239); 357 skipped. The failures are mostly values that need layout (156 are grid tracks) and per-property computed forms not done yet.css/css-cascadetests that add<style>from script and read a computed style (the layer tests, mostly). 104 of 123; the 19 are@scope(13) and the tentativerevert-rule(6).flexandwhite-spaceexpansion).revert,revert-layerandall, inheritance and units,var()with fallbacks and invalid-at-computed-time, media/supports/nesting, buckets, supports conditions) and new doctests.bench -- css, twice on an M2 Max, each started with the load under 2.8, cascade over the 13 real pages, median of 5, run 2:<style>CSSRun 1 totalled 2,770.5. Most pages
<link>their CSS, which isn't fetched, so they're timed with the UA sheet alone. There's no Lexbor row because Lexbor computes no values. The syntax and typed-value rows are unchanged from #91.cargo fmt --all,cargo clippy --workspace --all-targets -- -D warnings,cargo test --workspace,cargo deny checkand the bench's clippy pass.Closes #30