Sign in

    mizchi/crater/css/selector does not have a README file

    Attribute

    pub struct Attribute {
    name : String
    value : String
    }

    Attribute value on an element

    AttributeMatch

    pub enum AttributeMatch {
    Exists
    Exact(String)
    Includes(String)
    DashMatch(String)
    Prefix(String)
    Suffix(String)
    Substring(String)
    }

    Attribute matching mode

    AttributeSelector

    pub struct AttributeSelector {
    name : String
    match_type : AttributeMatch
    case_insensitive : Bool
    }

    Attribute selector

    Combinator

    pub enum Combinator {
    Descendant
    Child
    NextSibling
    SubsequentSibling
    }

    Combinator between compound selectors
    impl Show for Combinator

    ComplexSelector

    pub struct ComplexSelector {
    head : CompoundSelector
    tail : Array[ComplexSelectorStep]
    }

    Complex selector - compound selectors joined by combinators e.g., div > p.intro + span

    ComplexSelector::simple

    Create a complex selector from a single compound

    ComplexSelectorStep

    pub struct ComplexSelectorStep {
    combinator : Combinator
    selector : CompoundSelector
    }

    A step in a complex selector: combinator + compound selector

    CompoundSelector

    pub struct CompoundSelector {
    type_selector : SimpleSelector?
    subclasses : Array[SimpleSelector]
    }

    Compound selector - a sequence of simple selectors without combinator e.g., div.foo#bar:hover

    CompoundSelector::from_class

    fn CompoundSelector::from_class(class_name : String) -> CompoundSelector

    Create a simple compound selector with just a class selector

    CompoundSelector::from_id

    fn CompoundSelector::from_id(id : String) -> CompoundSelector

    Create a simple compound selector with just an ID selector

    CompoundSelector::from_type

    fn CompoundSelector::from_type(tag_name : String) -> CompoundSelector

    Create a simple compound selector with just a type selector

    CompoundSelector::universal

    Create a simple compound selector with universal selector

    Element

    pub(all) struct Element {
    tag_name : String
    id : String?
    classes : Array[String]
    attributes : Array[Attribute]
    parent : Element?
    prev_sibling : Element?
    next_sibling : Element?
    children : Array[Element]
    sibling_index : Int
    sibling_count : Int
    }

    Element data for selector matching This is a concrete type that can be used with or without a real DOM

    Element::add_class

    fn Element::add_class(self : Element, class_name : String) -> Element

    Element::get_attribute

    fn Element::get_attribute(self : Element, name : String) -> String?

    Get attribute value by name

    Element::has_class

    fn Element::has_class(self : Element, class_name : String) -> Bool

    Check if element has a specific class

    Element::is_first_child

    fn Element::is_first_child(self : Element) -> Bool

    Check if element is first child

    Element::is_last_child

    fn Element::is_last_child(self : Element) -> Bool

    Check if element is last child

    Element::new

    fn Element::new(tag_name : String) -> Element

    Create a new element with minimal information

    Element::set_attribute

    fn Element::set_attribute(self : Element, name : String, value : String) -> Element

    Element::set_id

    fn Element::set_id(self : Element, id : String) -> Element

    Builder for creating elements with fluent API

    Element::set_parent

    fn Element::set_parent(self : Element, parent : Element) -> Element

    Element::set_sibling_info

    fn Element::set_sibling_info(self : Element, index : Int, count : Int) -> Element

    Element::with_classes

    fn Element::with_classes(tag_name : String, classes : Array[String]) -> Element

    Create an element with classes

    Element::with_id

    fn Element::with_id(tag_name : String, id : String) -> Element

    Create an element with id

    NthExpr

    pub struct NthExpr {
    a : Int
    b : Int
    }

    Nth expression: An+B
    impl Show for NthExpr

    PseudoClass

    pub enum PseudoClass {
    FirstChild
    LastChild
    OnlyChild
    NthChild(NthExpr)
    NthLastChild(NthExpr)
    FirstOfType
    LastOfType
    OnlyOfType
    NthOfType(NthExpr)
    NthLastOfType(NthExpr)
    Root
    Empty
    Not(Array[CompoundSelector])
    Is(Array[ComplexSelector])
    Where(Array[ComplexSelector])
    Has(Array[RelativeSelector])
    Hover
    Active
    Focus
    FocusVisible
    FocusWithin
    Link
    Visited
    AnyLink
    Enabled
    Disabled
    Checked
    Indeterminate
    Required
    Optional
    Valid
    Invalid
    ReadOnly
    ReadWrite
    }

    Pseudo-class selector
    impl Show for PseudoClass

    PseudoElement

    pub enum PseudoElement {
    Before
    After
    FirstLine
    FirstLetter
    Marker
    Placeholder
    Selection
    }

    Pseudo-element selector

    RelativeSelector

    pub struct RelativeSelector {
    combinator : Combinator?
    selector : ComplexSelector
    }

    Relative selector for :has()

    SelectorList

    pub struct SelectorList {
    selectors : Array[ComplexSelector]
    }

    Selector list - comma-separated selectors

    SimpleSelector

    pub enum SimpleSelector {
    Type(String)
    Universal
    Id(String)
    Class(String)
    Attribute(AttributeSelector)
    PseudoClass(PseudoClass)
    PseudoElement(PseudoElement)
    }

    Simple selector - a single component

    Specificity

    pub(all) struct Specificity {
    a : Int
    b : Int
    c : Int
    }

    Specificity as (a, b, c) tuple a: ID selectors count b: class selectors, attribute selectors, pseudo-classes count c: type selectors, pseudo-elements count
    impl Eq for Specificity
    impl Show for Specificity

    Specificity::add

    fn Specificity::add(self : Specificity, other : Specificity) -> Specificity

    Specificity::compare_to

    fn Specificity::compare_to(self : Specificity, other : Specificity) -> Int

    Compare specificities for cascade ordering Returns positive if self > other, negative if self < other, 0 if equal

    Specificity::zero

    fn Specificity::zero() -> Specificity

    complex_specificity

    fn complex_specificity(sel : ComplexSelector) -> Specificity

    Calculate specificity of a complex selector

    matches_complex

    fn matches_complex(element : Element, selector : ComplexSelector) -> Bool

    Check if an element matches a complex selector

    matches_selector_list

    fn matches_selector_list(element : Element, list : SelectorList) -> Bool

    Check if an element matches any selector in a list

    parse_selector_list_text

    fn parse_selector_list_text(css : String) -> SelectorList?

    Convenience function to parse a selector list from CSS text

    parse_selector_text

    fn parse_selector_text(css : String) -> ComplexSelector?

    Convenience function to parse a selector from CSS text