css

CSS parser, selector, cascade, and computed-style core maintained for Milky2018/svg

css
parser
selector
cascade
computed
moon add Milky2018/css@0.5.2
Download zip
Author
Version
0.5.2
License
Apache-2.0
Last updated
24 days ago
Downloads
151
README

#Milky2018/css

A reusable static CSS core for MoonBit and the computed-style engine used by Milky2018/svg.

#Install

moon add Milky2018/css

#Supported Boundary

The module owns:

  • CSS tokenization and stylesheet or inline-declaration parsing
  • selector parsing and matching
  • author-origin cascade, specificity, source order, and !important
  • media-query parsing and evaluation against a supplied environment
  • computed values, inheritance, CSS-wide keywords, and custom properties
  • CSS Color 3 values and the color functions used by the SVG renderer

The root package exposes the common parser, selector, cascade, media, and computed-style APIs through one import. Embedders can use resolve_custom_property_value for extension properties and cascade_element_with_media_and_validator to reject invalid extension declarations before they win the cascade.

The module does not provide a DOM, layout engine, browser environment, dynamic restyling, animation timeline, transition runtime, or generic browser support diagnostics. Static animation and transition syntax may be parsed and stored, but it is not executed.

@import rules are retained as structured Stylesheet.imports entries. The CSS module never fetches them; an embedding renderer resolves the URI, applies its media condition, and parses the supplied text.

#SVG Integration

Milky2018/svg is the first acceptance consumer, not the only permitted consumer. Generic CSS behavior belongs here; SVG-specific presentation attributes, paint semantics, and rendering remain in the SVG module.

#Source Origin

The initial source was copied from mizchi/css version 0.7.3:

Generated WPT fixtures and benchmarks were not imported. Retained unit and white-box tests cover the static core, while the SVG test suite provides integration coverage for renderer-facing behavior.

The module is distributed under Apache-2.0. See NOTICE for the attribution that accompanies this distribution.

#
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

#
CompoundSelector

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

#
ComputeContext

Computed values context for resolving relative units

#
CssColorValue

Result of parsing a CSS color value

#
Declaration

A CSS declaration with cascade metadata

#
Element

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

#
ForcedPseudoStates

#
Importance

Importance of a declaration

#
IndexedStylesheet

Indexed stylesheet for fast matching

#
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

#
Origin

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

#
PropertyValue

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

#
PseudoClass

Pseudo-class selector

#
PseudoElement

Pseudo-element selector

#
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

#
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

#
apply_property_direct

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

#
compute_inline_raw

#
compute_inline_style

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

#
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

#
resolve_custom_property_value

fn resolve_custom_property_value(value : String, custom_properties : Map[String, String]) -> String?

Source Files

Powered by MoonBit

Site sourceReport issuePackagesBuild queueSkillsStatistics

© 2026 mooncakes.io