Expand description
CSS data model (AST) + Cascade-5 application, extracted from lumenc’s
parse::css front-end so the parser-free runtime and every other IR
consumer share the same cascade without pulling in the markup parser.
The hand-rolled front-end (parse_css and its lexer) still lives in
lumenc::parse::css and produces the Stylesheet type defined here;
this crate owns the data + the code that applies it.
§Cascade ordering
Per CSS Cascade-5 section 6.4: origin -> importance -> specificity -> source
order, and later rules win at equal weight (section 6.4.4). Within
apply_css, HTML inline attrs (origin: inline) beat CSS attrs
(origin: user/UA) - preserving the long-standing rule that
<tile width="50px"/> overrides .t { width: 100px }. Inline
!important is not authorable; user !important lifts a CSS
declaration above its origin’s normal block.
Structs§
- AnB
:nth-child(an+b)coefficients.- Ancestor
Info - One element of a live tree as the cascade sees it: what selectors match
on, and what the element itself declares. The runtime builds these from
an entity’s components to re-resolve it, and to walk the ancestors of
the element a selector query or
computed_styleasks about. - AtRule
- An at-rule the cascade does not implement, kept as authored for a consumer that does. The desktop cascade reads none of these; the web target writes them back out.
- Cascade
Divergence - One diff finding emitted by
cascade_lint. - Compound
Selector - One compound selector -
tag#id.cls:pseudo. - CssWarning
- A skipped declaration, surfaced to the CLI / hot-reload log / LSP instead of aborting the stylesheet.
- Declaration
- One
property: valuepair. - Legacy
Selector Shim - Back-compat shim - see
Rule::selector. - Matched
Rule Info - One stylesheet rule that matched an element, with its cascade
provenance, for the dynamic DOM
matched_rules()inspection getter. - Media
Context - Runtime view of the OS-level theme + viewport state. Passed to
apply_css_with_mediaso@mediablocks resolve consistently. - Media
Query @mediacondition.- Restyle
Walk - A walk down a live tree that resolves each element from scratch: from its identity, its place in the tree, and what it declares about itself, against the stylesheet. It is the first cascade’s walk over the document, one element at a time, so an element resolved here comes out as it did then, and a property nothing sets any more is unset.
- Rule
- One CSS rule (one
selector_list { decl* }block). - Selector
Buf - Compiled selector: a chain of compound selectors joined by combinators.
- Sibling
Position - Where an element sits among its element siblings. The structural
pseudo-classes (
:first-child,:last-child,:only-child,:nth-child()) are decided from this, so a caller that re-runs the cascade for a single element has to supply it: a wrong position is a rule matching the wrong sibling, not a rule that quietly fails. - Siblings
- The element siblings sharing one parent, in document order: what a
+or~step walks leftwards through. Built once per parent and shared by every child of it. - Specificity
(a, b, c)triple, lexicographically ordered for cascade sort.- Stylesheet
- A parsed stylesheet.
- WebNames
- The names a browser knows a Lumen element by.
Enums§
- Color
Scheme Preference prefers-color-schemevalue.- Combinator
- Connector between two adjacent compounds in a selector chain.
- Contrast
Preference prefers-contrastvalue.- Media
Feature - One
(feature: value)test inside an@mediaquery. - Motion
Preference prefers-reduced-motionvalue.- Origin
- Cascade origin per CSS Cascade 4 section 6.1. Lumen models the two
origins it actually mixes: the built-in skin sheet ships as the
user-agent origin, and the app’s own CSS is the author
origin. For normal (non-
!important) declarations author beats user-agent regardless of specificity, so the variants are orderedUserAgent < Authorand the cascade sort keys on origin first. - Pseudo
Class - All pseudo-classes the engine recognises.
Constants§
- CARRIED_
AT_ RULES - At-rule names a
Stylesheetcarries verbatim instead of dropping. Every other at-rule warns and is skipped. - COMPUTED_
STYLE_ PROPERTIES - Property names
computed_style_mapenumerates for the full-mapcomputed_style()getter. Covers the layout / paint / text properties the cascade models; unmodeled CSS properties are absent from the map. - STYLE_
PROPERTIES - Every property name [
apply_declaration] applies, in the canonical spelling its match arms use; alias spellings reach this list throughcanonical_property_name. A property added to the cascade is added here in the same change, or a consumer that sorts declarations by kind takes it for something the cascade ignores.
Functions§
- apply_
css - Apply a stylesheet to a
LayoutIR. Each property follows(origin, !important, specificity, source_order)ordering and the last matching declaration wins. HTML inline attrs always beat CSS (origin precedence: inline > user/UA). - apply_
css_ with_ media - Same as
apply_cssbut honours@mediablocks against the givenMediaContext. - apply_
inline_ declaration - Apply one inline-style declaration (
element.stylelayer) ontoattrs, overriding whatever the stylesheet cascade resolved. A restyle passes these toRestyleWalkafter the markup’s own, so an inline value beats every author / UA rule, mirroring DOM inline-style precedence. ReturnsOk(true)when the property was recognized and applied,Ok(false)for an unknown property (ignored),Errfor an unparseable value. - apply_
markup_ declaration - Give an element a style as its markup would: the value lands in
attrs, and the declaration joinsAttributes::markup_stylesunder the spelling the cascade files it under. - canonical_
property_ name - Map standard CSS property names onto Lumen’s native slots so real-world stylesheets work as written. The Lumen short names stay accepted.
- canonical_
style_ property - The one spelling the cascade files
nameunder, orNonewhen it is not a style property at all. - cascade_
lint - Scan a parsed stylesheet and emit one
CascadeDivergenceper (selector x property) pair whose resolved value differs between the old first-wins ordering and the new last-wins ordering. - computed_
property - Read one resolved CSS property off
attrsas a canonical string, for the dynamic DOMcomputed_style("prop")getter. Covers the common layout / paint / text properties; an unmodeled property returnsNone. Colors render as#rrggbb/#rrggbbaa, lengths asNpx/N%/auto, scalars as their decimal form. - computed_
style_ map - Every resolved property in
COMPUTED_STYLE_PROPERTIESthat the cascade set onattrs, as(name, value)pairs: the full-map form ofcomputed_propertybacking the dynamic DOMcomputed_style()getter. An inspection call, not a per-frame path. - is_
style_ property truewhennameis a style property the cascade applies, under either its Lumen spelling or its standard-CSS one. Consumers that sort authored declarations by kind ask this before they hand one to the cascade; anything else in a rule (a--customproperty, a typo) answersfalse.- matched_
rules_ for - Rules that match
subjectgiven itsancestors(root-first), with cascade provenance, ascending in cascade order (last wins). Reuses the cascade matcher’s owncollect_matching_rules, so this is the same match set the restyle pass resolves; no second selector engine. An inspection call backingmatched_rules(). - media_
query_ to_ css - Serialize a
MediaQueryback to the condition text that follows@media, the at-rule counterpart ofselector_to_css. Features keep the spelling the parser accepts and areand-joined in source order, so the result parses back to the same query. - palette_
root_ css - Synthetic CSS source for the built-in
lumen_core::palette::Palettelight/dark theme: a base:rootblock fromPalette::adwaita_lightplus its differences wrapped in@media (prefers-color-scheme: dark)fromPalette::adwaita_dark- the same light-first-with-dark-override shape every shipped skin file uses (core/runtime/src/skins/*.css). - parse_
duration_ ms - Parse a CSS duration (
NmsorNs) into whole milliseconds. Shared by every duration-valued property in the cascade (transition-duration,caret-blink,scrollbar-fade-delay,scrollbar-fade-duration, …);pubso the markup parser (lumenc::parse::html, a separate crate) reuses the same parser instead of duplicating the unit handling for its mirrored inline-attribute table. - parse_
grid_ line_ pair - Parse
grid-row/grid-column<start>[/<end>]values. A single integer = start only, end auto-placed. A pair separated by/= explicit start + end line numbers. CSSspan <N>and named lines are out of scope for the W5.9 subset. - parse_
selector_ list - Parse a CSS selector list (
"#save, .row > .cell") into the sameSelectorBufchain the stylesheet front-end builds. The runtime query engine (query(sel)) calls this so a script selector runs through the one selector grammar Lumen already speaks; there is no second engine. - reapply_
detached - Resolve a detached element (one with no ancestors to hand it a scope,
such as a
<for>row being built before it joins the tree) against the stylesheet, and write what the cascade resolved over its attributes. - resolve_
element - Resolve one element of a live tree from scratch, given its ancestors
root-first; see
RestyleWalk. What the dynamic DOM’scomputed_styleanswers with. - selector_
matches - Test whether
selmatchessubject, consultingancestors(root-first, the same orderRestyleWalk::newtakes) for descendant / child combinators. Wraps the cascade matcher ([match_selector]) soquery()and traversal share the exact match semantics of the live cascade. - selector_
to_ css - Serialize a compiled
SelectorBufback to CSS-ish text for the dynamic DOMmatched_rules()provenance view. Reconstructstag#id.class:pseudocompounds joined by their combinators. Pseudo arguments (:nth-child(2n),:is(...)) render their canonical form. - selector_
to_ web - Serialize a compiled
SelectorBufas the selector that picks the same elements out of an emitted HTML document.