Expand description
§StyleX CSS Parser
A high-performance CSS value parser for StyleX, written in Rust.
This crate provides comprehensive CSS value parsing capabilities with excellent performance and type safety.
§Features
- Token Parser Combinators: Monadic parser combinators for building complex parsers
- CSS Type Parsers: Support for all CSS value types (colors, lengths, angles, calc expressions, etc.)
- Property Parsers: Specialized parsers for complex CSS properties (transform, box-shadow, border-radius)
- Media Query Support: Complete media query parsing and transformation
- Type Safety: Full Rust type safety with comprehensive error handling
- Performance: High-performance parsing with minimal allocations
§Usage Examples
ⓘ
use stylex_css_parser::{tokenParser, properties, last_media_query_wins_transform};
use stylex_css_parser::css_types::{Color, Length, Calc};
use swc_core::ecma::ast::{KeyValueProp, PropName, Expr, Lit};
// Parse CSS values
let color = Color::parse(); // CSS color parser
let length = Length::parser(); // CSS length parser
let calc = Calc::parse(); // CSS calc() expression parser
// Property parsers
let transform = properties::Transform::parser();
let box_shadow = properties::BoxShadow::parser();
let border_radius = properties::BorderRadiusShorthand::parser();
// Media query transformation
let queries = &[KeyValueProp{
key: PropName::Ident("key".into()),
value: Box::new(Expr::Lit(Lit::Str("value".into()))),
}];
let transformed = last_media_query_wins_transform(queries);§Module Organization
tokenParser- Core parser combinator libraryproperties- Property-specific parserscss_types- Individual CSS type parsers (color, length, angle, etc.)at_queries- Media query and at-rule parsingbase_types- Base utility types (SubString, etc.)token_types- Tokenization utilities
Re-exports§
pub use at_queries::last_media_query_wins_transform;pub use token_parser as tokenParser;pub use css_value::CssValue;pub use flex_parser::FlexCombinators;pub use flex_parser::FlexParser;
Modules§
- at_
queries - At-rule parsing functionality.
- base_
types - Base types and utilities for CSS parsing.
- css_
types - CSS type parsers.
- css_
value - Universal CSS Value System for Dynamic Parsing
- flex_
parser - Flexible Parser System for Advanced CSS Parsing
- properties
- CSS property parsers.
- token_
parser - Token parser combinators for CSS parsing.
- token_
types - Token types and tokenization utilities for CSS parsing.
Enums§
- CssParse
Error - Main error type for CSS parsing operations
Type Aliases§
- CssResult
- Result type for CSS parsing operations