README

mizchi/crater-css/cascade does not have a README file

#
CSSRule

pub struct CSSRule {
selector_text : String
selector :
ComplexSelector

declarations : Array[Declaration]
source_order : Int
media_query :
MediaQueryList
?
}

A CSS rule: selector + declarations

#
CascadedValues

pub struct CascadedValues {
values : Map[String, Declaration]
}

Cascaded values for an element Maps property names to their winning declaration

#
CascadedValues::each

fn CascadedValues::each(self : CascadedValues, f : (String, Declaration) -> Unit) -> Unit

Iterate cascaded declarations without allocating an intermediate key array.

#
CascadedValues::get

fn CascadedValues::get(self : CascadedValues, property : String) -> Declaration?

Get the cascaded value for a property

#
CascadedValues::get_value

fn CascadedValues::get_value(self : CascadedValues, property : String) -> String?

Get the raw value string for a property

#
CascadedValues::has

fn CascadedValues::has(self : CascadedValues, property : String) -> Bool

Check if a property has a cascaded value

#
CascadedValues::new

#
CascadedValues::properties

fn CascadedValues::properties(self : CascadedValues) -> Array[String]

Get all property names that have cascaded values

#
Declaration

pub(all) struct Declaration {
property : String
value : PropertyValue
origin : Origin
importance : Importance
specificity :
Specificity

source_order : Int
}

A CSS declaration with cascade metadata
impl Show for Declaration

#
Declaration::from_inline

fn Declaration::from_inline(property : String, value : String, importance : Importance) -> Declaration

Create a declaration from inline style (highest specificity)

#
Declaration::new

fn Declaration::new(property : String, value : String) -> Declaration

Create a new declaration with default values

#
Declaration::with_metadata

fn Declaration::with_metadata(property : String, value : PropertyValue, origin : Origin, importance : Importance, specificity :
Specificity
, source_order : Int) -> Declaration

Create a declaration with full metadata

#
Importance

pub(all) enum Importance {
Normal
Important
}

Importance of a declaration
impl Show for Importance

#
IndexedStylesheet

pub struct IndexedStylesheet {
stylesheet : Stylesheet
index : SelectorIndex
}

Indexed stylesheet for fast matching

#
IndexedStylesheet::match_element

Match all rules against an element using the index

#
IndexedStylesheet::match_element_with_media

Match all rules against an element with media query evaluation using the index

#
IndexedStylesheet::new

#
Origin

pub(all) enum Origin {
UserAgent
User
Author
}

Origin of a CSS declaration Ordered from lowest to highest precedence for normal declarations
impl Show for Origin

#
PropertyValue

pub(all) enum PropertyValue {
Value(String)
Inherit
Initial
Unset
Revert
RevertLayer
}

A CSS property value that can be a specific value or a keyword

#
RuleMatch

pub(all) struct RuleMatch {
specificity :
Specificity

declarations : Array[Declaration]
source_order : Int
}

Collect declarations from matching rules for an element This is a helper to build the input for cascade()

#
SelectorIndex

pub(all) struct SelectorIndex {
by_id : Map[String, Array[Int]]
by_class : Map[String, Array[Int]]
by_tag : Map[String, Array[Int]]
universal : Array[Int]
}

Index for fast rule lookup Rules are indexed by the rightmost compound selector's:
  • ID selectors
  • Class selectors
  • Tag name
  • Universal selectors (matched against all elements)

#
SelectorIndex::from_stylesheet

fn SelectorIndex::from_stylesheet(stylesheet : Stylesheet) -> SelectorIndex

Build index for a stylesheet

#
SelectorIndex::get_candidates

fn SelectorIndex::get_candidates(self : SelectorIndex, element :
Element
) -> Array[Int]

Get candidate rule indices for an element Returns indices of rules that might match (need full selector check)

#
SelectorIndex::new

#
Stylesheet

pub struct Stylesheet {
rules : Array[CSSRule]
origin : Origin
}

A stylesheet: collection of rules

#
Stylesheet::add_rule

fn Stylesheet::add_rule(self : Stylesheet, selector_text : String, selector :
ComplexSelector
, declarations : Array[Declaration]) -> Unit

Add a rule to the stylesheet

#
Stylesheet::add_rule_with_media

fn Stylesheet::add_rule_with_media(self : Stylesheet, selector_text : String, selector :
ComplexSelector
, declarations : Array[Declaration], media_query :
MediaQueryList
) -> Unit

Add a rule with a media query to the stylesheet

#
Stylesheet::match_element

Match all rules against an element and return matched rules

#
Stylesheet::match_element_with_media

Match all rules against an element with media query evaluation

#
Stylesheet::new

fn Stylesheet::new(origin : Origin) -> Stylesheet

#
cascade

fn cascade(declarations : Array[Declaration]) -> CascadedValues

Cascade a list of declarations into final values Declarations should be for a single element

#
cascade_element

fn cascade_element(element :
Element
, stylesheets : Array[Stylesheet], inline_style : Array[Declaration]) -> CascadedValues

Cascade styles for an element from multiple stylesheets

#
cascade_element_indexed

Cascade styles using indexed stylesheets for better performance

#
cascade_element_with_forced_states

Cascade styles for an element with forced pseudo-class states. This evaluates CSS rules as if the specified pseudo-class states (:hover, :focus, :active) were active on the element.

#
cascade_element_with_media

fn cascade_element_with_media(element :
Element
, stylesheets : Array[Stylesheet], inline_style : Array[Declaration], media_env :
MediaEnvironment
?) -> CascadedValues

Cascade styles for an element with media query evaluation

Powered by MoonBit

Site sourceReport issuePackagesBuild queueSkillsStatistics

© 2026 mooncakes.io