Skip to main content

Module css

Module css 

Source
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.
AncestorInfo
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_style asks 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.
CascadeDivergence
One diff finding emitted by cascade_lint.
CompoundSelector
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: value pair.
LegacySelectorShim
Back-compat shim - see Rule::selector.
MatchedRuleInfo
One stylesheet rule that matched an element, with its cascade provenance, for the dynamic DOM matched_rules() inspection getter.
MediaContext
Runtime view of the OS-level theme + viewport state. Passed to apply_css_with_media so @media blocks resolve consistently.
MediaQuery
@media condition.
RestyleWalk
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).
SelectorBuf
Compiled selector: a chain of compound selectors joined by combinators.
SiblingPosition
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§

ColorSchemePreference
prefers-color-scheme value.
Combinator
Connector between two adjacent compounds in a selector chain.
ContrastPreference
prefers-contrast value.
MediaFeature
One (feature: value) test inside an @media query.
MotionPreference
prefers-reduced-motion value.
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 ordered UserAgent < Author and the cascade sort keys on origin first.
PseudoClass
All pseudo-classes the engine recognises.

Constants§

CARRIED_AT_RULES
At-rule names a Stylesheet carries verbatim instead of dropping. Every other at-rule warns and is skipped.
COMPUTED_STYLE_PROPERTIES
Property names computed_style_map enumerates for the full-map computed_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 through canonical_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_css but honours @media blocks against the given MediaContext.
apply_inline_declaration
Apply one inline-style declaration (element.style layer) onto attrs, overriding whatever the stylesheet cascade resolved. A restyle passes these to RestyleWalk after the markup’s own, so an inline value beats every author / UA rule, mirroring DOM inline-style precedence. Returns Ok(true) when the property was recognized and applied, Ok(false) for an unknown property (ignored), Err for an unparseable value.
apply_markup_declaration
Give an element a style as its markup would: the value lands in attrs, and the declaration joins Attributes::markup_styles under 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 name under, or None when it is not a style property at all.
cascade_lint
Scan a parsed stylesheet and emit one CascadeDivergence per (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 attrs as a canonical string, for the dynamic DOM computed_style("prop") getter. Covers the common layout / paint / text properties; an unmodeled property returns None. Colors render as #rrggbb / #rrggbbaa, lengths as Npx / N% / auto, scalars as their decimal form.
computed_style_map
Every resolved property in COMPUTED_STYLE_PROPERTIES that the cascade set on attrs, as (name, value) pairs: the full-map form of computed_property backing the dynamic DOM computed_style() getter. An inspection call, not a per-frame path.
is_style_property
true when name is 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 --custom property, a typo) answers false.
matched_rules_for
Rules that match subject given its ancestors (root-first), with cascade provenance, ascending in cascade order (last wins). Reuses the cascade matcher’s own collect_matching_rules, so this is the same match set the restyle pass resolves; no second selector engine. An inspection call backing matched_rules().
media_query_to_css
Serialize a MediaQuery back to the condition text that follows @media, the at-rule counterpart of selector_to_css. Features keep the spelling the parser accepts and are and-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::Palette light/dark theme: a base :root block from Palette::adwaita_light plus its differences wrapped in @media (prefers-color-scheme: dark) from Palette::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 (Nms or Ns) into whole milliseconds. Shared by every duration-valued property in the cascade (transition-duration, caret-blink, scrollbar-fade-delay, scrollbar-fade-duration, …); pub so 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. CSS span <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 same SelectorBuf chain 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’s computed_style answers with.
selector_matches
Test whether sel matches subject, consulting ancestors (root-first, the same order RestyleWalk::new takes) for descendant / child combinators. Wraps the cascade matcher ([match_selector]) so query() and traversal share the exact match semantics of the live cascade.
selector_to_css
Serialize a compiled SelectorBuf back to CSS-ish text for the dynamic DOM matched_rules() provenance view. Reconstructs tag#id.class:pseudo compounds joined by their combinators. Pseudo arguments (:nth-child(2n), :is(...)) render their canonical form.
selector_to_web
Serialize a compiled SelectorBuf as the selector that picks the same elements out of an emitted HTML document.