Sign in

    css

    Standalone CSS parser, selector, cascade and computed-style engine for MoonBit

    css
    parser
    selector
    cascade
    computed
    Download zip
    Author
    Version
    0.7.4
    License
    Apache-2.0
    Last updated
    14 hours ago
    Downloads
    22K

    #mizchi/css

    Standalone CSS parser, selector matcher, cascade resolver, and computed-style engine for MoonBit.

    Originally extracted from mizchi/crater (a CSS layout / browser engine) so the CSS pipeline can be reused by other tools (linters, formatters, static analyzers, alternative layout engines).

    #Packages

    PackageResponsibility
    mizchi/css/valuesCSS value primitives (Color, Length, Dimension, Display, Position, Overflow, BoxSizing, FlexDirection, grid track sizing, etc.)
    mizchi/css/styleComputed Style struct (resolved declarations + per-element style)
    mizchi/css/tokenCSS tokenizer
    mizchi/css/selectorSelector parser and matcher
    mizchi/css/cascadeCascade rules, rule indexing, importance, origin handling
    mizchi/css/media@media queries, evaluation
    mizchi/css/diagnosticsParse / cascade diagnostics
    mizchi/css/parserStylesheet parser (declarations, at-rules, selectors)
    mizchi/css/computedComputed-style resolution (cascade output → Style)
    mizchi/css/animationWeb Animations timing model and numeric keyframe sampling
    mizchi/cssFacade re-exporting the most-used types

    #Easing Values

    mizchi/css/values includes easing primitives that are independent from a specific animation engine:

    • parse_easing("ease-in-out"), parse_easing("cubic-bezier(...)"), parse_easing("steps(...)"), and CSS Easing Level 2 linear(...).
    • Easing::sample(progress) returns the eased progress for normalized input.
    • Easing::apply(from, to, progress) returns an interpolated numeric value.
    • Easing::frame(from, to, progress) and Easing::frames(from, to, count) expose intermediate progress, eased_progress, and value triples.

    The parser accepts CSS keywords plus common named Penner/easings.net aliases such as ease-in-sine, easeOutBack, and ease_in_out_bounce. sample clamps input progress to [0, 1]; overshooting curves such as back/elastic can still produce eased progress outside that range.

    #Web Animations

    mizchi/css/animation provides a small, DOM-independent subset of the Web Animations timing model. It models effect timing fields such as delay, fill, iterations, duration, direction, and easing, and can sample numeric keyframe effects:

    • EffectTiming::new(duration).at(local_time) returns phase, progress, current iteration, directed progress, and transformed progress.
    • NumericKeyframeEffect::new(keyframes, timing) validates explicit offsets from 0.0 to 1.0.
    • NumericKeyframeEffect::sample(local_time) returns the interpolated numeric value or None when the effect is outside its active interval without fill.
    • NumericKeyframeEffect::sample_with_underlying(local_time, value) applies numeric add / accumulate composition against an underlying value.

    This is the timing/interpolation foundation only. DOM playback, CSS property specific interpolation, and timeline scheduling are left to higher layers.

    #Web Platform Tests

    wpt/ ships a runner that converts upstream WPT selector-parsing tests (css/selectors/parsing/**) into MoonBit test cases. After node wpt/extract.mjs && node wpt/gen-mbt.mjs, the suite is exercised with moon test --package mizchi/css/wpt — 215 / 215 tests passing (100%) against upstream WPT. See wpt/README.md.

    #License

    Apache-2.0.

    AnimationPhase

    Attribute

    Attribute value on an element

    AttributeMatch

    Attribute matching mode

    AttributeSelector

    Attribute selector

    CSSRule

    A CSS rule: selector + declarations

    CascadedValues

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

    ColorScheme

    Color scheme preference

    Combinator

    Combinator between compound selectors

    ComplexSelector

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

    ComplexSelectorStep

    A step in a complex selector: combinator + compound selector

    CompositeOperation

    CompoundSelector

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

    ComputeContext

    Computed values context for resolving relative units

    ComputedEffectTiming

    CssColorValue

    Result of parsing a CSS color value

    Declaration

    A CSS declaration with cascade metadata

    Diagnostic

    A single diagnostic entry

    DiagnosticSummary

    Summary statistics for diagnostics

    DiagnosticsCollector

    Collector for CSS diagnostics

    EffectTiming

    Element

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

    FillMode

    ForcedPseudoStates

    Importance

    Importance of a declaration

    IndexedStylesheet

    Indexed stylesheet for fast matching

    IterationCompositeOperation

    MediaEnvironment

    Environment for evaluating media queries

    MediaFeature

    Media feature (e.g., width, height, color, etc.)

    MediaQuery

    A complete media query

    MediaQueryList

    A list of media queries (comma-separated in CSS)

    MediaType

    Media type (screen, print, all, etc.)

    MediaValue

    Media feature value

    NthExpr

    Nth expression: An+B

    NumericKeyframe

    NumericKeyframeEffect

    Origin

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

    ParseResult

    Parse result with diagnostics

    PlaybackDirection

    PropertyValue

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

    PseudoClass

    Pseudo-class selector

    PseudoElement

    Pseudo-element selector

    RangeOp

    using @mizchi/css/media { type RangeOp }

    Comparison operator for range queries

    RelativeSelector

    Relative selector for :has()

    RuleMatch

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

    SelectorIndex

    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)

    SelectorList

    Selector list - comma-separated selectors

    Severity

    Severity level for diagnostics

    ShadowContext

    Shadow DOM scoping information for selector matching.

    host is the shadow host for the current styling scope. host_ancestors is the light-tree ancestor chain used by :host-context(). If it is empty, the matcher falls back to walking host.parent. assigned_slot is the slot assigned to the element currently being matched by ::slotted().

    SimpleSelector

    Simple selector - a single component

    Specificity

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

    Stylesheet

    A stylesheet: collection of rules

    SupportLevel

    Support level for a CSS property

    affects_layout

    fn affects_layout(level :
    SupportLevel
    ) -> Bool

    apply_property_direct

    fn apply_property_direct(style :
    Style
    , property : String, value : String, ctx :
    ComputeContext
    ) ->
    Style

    compute_inline_raw

    fn compute_inline_raw(inline_css : String, ctx :
    ComputeContext
    ) ->
    Style

    compute_inline_style

    fn compute_inline_style(inline_css : String, ctx :
    ComputeContext
    ) ->
    Style

    compute_style_with_vars

    matches_selector

    matches_selector_list

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

    matches_selector_list_with_shadow_context

    fn matches_selector_list_with_shadow_context(element :
    Element
    , selector_list :
    SelectorList
    , context :
    ShadowContext
    ?) -> Bool

    matches_selector_with_shadow_context

    parse_color

    fn parse_color(value : String) ->
    CssColorValue

    parse_inline_style

    fn parse_inline_style(css : String) ->
    Style

    parse_media_query_list

    fn parse_media_query_list(input : String) ->
    MediaQueryList

    parse_selector

    fn parse_selector(css : String) ->
    ComplexSelector
    ?

    parse_selector_list

    fn parse_selector_list(css : String) ->
    SelectorList
    ?

    parse_stylesheet

    fn parse_stylesheet(css : String) ->
    Stylesheet

    parse_stylesheet_with_diagnostics

    fn parse_stylesheet_with_diagnostics(css : String) ->
    ParseResult

    Source Files