ไธไธช้ซๆง่ฝใ็ฑปๅๅฎๅ จ็Rust CSS-in-JS่งฃๅณๆนๆก๏ผไธไธบ็ฐไปฃWebๅผๅ่ฎพ่ฎกใ
- ็ฑปๅๅฎๅ จ: ๅฉ็จRust็็ฑปๅ็ณป็ป็กฎไฟCSS็ๆญฃ็กฎๆง
- ้ซๆง่ฝ็ผๅญ: ๆบ่ฝLRU็ผๅญๆบๅถ๏ผๆฏๆๅค็ง็ผๅญ็ญ็ฅ
- ๆต่งๅจๅ ผๅฎนๆง: ่ชๅจๆฃๆตๅ็ๆCSSๅ้ๆนๆก
- ๅ ๅญ็ฎก็: ๅ ่ฟ็ๅ ๅญๅๅ็ๆงๅ่ชๅจๆธ ็
- ๆง่ฝ็ๆง: ่ฏฆ็ป็ๆง่ฝๆๆ ๅ็ผๅญๅฝไธญ็็ป่ฎก
- ๅ ผๅฎนๆงๆฃๆต: ๆฏๆChromeใFirefoxใSafariใEdge็ญไธปๆตๆต่งๅจ
- ่ชๅจๅ้: ไธบไธๆฏๆ็CSS็นๆง่ชๅจ็ๆๅ้ไปฃ็
- ๅๅๅ็ผ: ๆบ่ฝๆทปๅ ๅไผๅๅๅๅ็ผ
- ็นๆงๆฃๆต: ๆฏๆFlexboxใGridใContainer Queries็ญ็ฐไปฃCSS็นๆง
- ๆบ่ฝ็ผๅญ: ๆฏๆLRUใLFUใTTLใ่ช้ๅบ็ญๅค็ง็ผๅญ็ญ็ฅ
- CSSๅ็ผฉ: ่ชๅจ็งป้ค็ฉบ็ฝๅๆณจ้
- ๅ็ผไผๅ: ๆ นๆฎ็ฎๆ ๆต่งๅจ็งป้คไธๅฟ ่ฆ็ๅๅๅ็ผ
- ๅ ๅญ็ๆง: ๅฎๆถ็ๆงๅ ๅญไฝฟ็จๆ ๅต๏ผ่ชๅจๆง่กๆธ ็็ญ็ฅ
css-in-rust/
โโโ crates/
โ โโโ css-in-rust-core/ # ๆ ธๅฟๅ่ฝๅบ
โ โ โโโ src/
โ โ โ โโโ cache/ # ็ผๅญ็ณป็ป
โ โ โ โ โโโ entity.rs # ็ผๅญๅฎไฝๅLRUๅฎ็ฐ
โ โ โ โ โโโ manager.rs # ็ผๅญ็ฎก็ๅจ
โ โ โ โ โโโ strategy.rs # ้ซ็บง็ผๅญ็ญ็ฅ
โ โ โ โ โโโ mod.rs
โ โ โ โโโ integration.rs # ้ๆ็ณป็ป
โ โ โ โโโ lib.rs
โ โ โโโ Cargo.toml
โ โโโ css-in-rust-utils/ # ๅทฅๅ
ทๅบ
โ โโโ src/
โ โ โโโ browser.rs # ๆต่งๅจๅ
ผๅฎนๆงๆฃๆต
โ โ โโโ lib.rs
โ โโโ Cargo.toml
โโโ examples/
โ โโโ integrated_system_demo.rs # ๅฎๆดๅ่ฝๆผ็คบ
โโโ Cargo.toml # ๅทฅไฝๅบ้
็ฝฎ
โโโ README.md
ๅฐไปฅไธๅ
ๅฎนๆทปๅ ๅฐไฝ ็ Cargo.toml
:
[dependencies]
css-in-rust-core = { path = "crates/css-in-rust-core" }
css-in-rust-utils = { path = "crates/css-in-rust-utils" }
use css_in_rust::styled;
use dioxus::prelude::*;
#[styled]
struct ButtonStyles {
base: &'static str = "
padding: 8px 16px;
border-radius: 4px;
border: none;
cursor: pointer;
font-weight: 500;
transition: all 0.2s ease;
",
variants: ButtonVariants {
primary: "background: #007bff; color: white;",
secondary: "background: #6c757d; color: white;",
},
}
#[derive(Props)]
struct ButtonProps {
variant: ButtonVariant,
children: Element,
}
fn Button(cx: Scope<ButtonProps>) -> Element {
let styles = use_style_register(cx, ButtonStyles::new());
render! {
button {
class: "{styles.base} {styles.variant(props.variant)}",
{&props.children}
}
}
}
fn App(cx: Scope) -> Element {
render! {
div {
Button {
variant: ButtonVariant::Primary,
"Click me!"
}
}
}
}
use css_in_rust_theme::{ThemeProvider, use_theme};
fn App(cx: Scope) -> Element {
render! {
ThemeProvider {
theme: create_theme(),
Router {}
}
}
}
fn ThemedComponent(cx: Scope) -> Element {
let theme = use_theme(cx);
let styles = use_style_register(cx, |
color: theme.colors.primary,
padding: theme.spacing.md,
border_radius: theme.radii.sm,
|);
render! {
div { class: "{styles}", "Themed content" }
}
}
CSS-in-Rust is built with a modular architecture:
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Application Layer โ
โ (Dioxus Components) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Integration Layer โ
โ (Dioxus Hooks & Providers) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ API Layer โ
โ (CSS-in-Rust Macros) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Core Engine โ
โ (Style Processing & Caching) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Foundation Layer โ
โ (Lightning CSS + Utilities) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
css-in-rust-core
: Core style processing enginecss-in-rust-macro
: Procedural macros for compile-time CSS generationcss-in-rust-theme
: Theme system and design tokenscss-in-rust-dioxus
: Dioxus integration with hooks and providerscss-in-rust-cli
: Development tools and utilities
CSS-in-Rust is designed for maximum performance:
- Compile-time CSS generation: Zero runtime CSS parsing
- Lightning CSS optimization: Automatic vendor prefixing and minification
- Efficient caching: Multi-level caching strategy
- Small bundle size: <50KB core library
- SSR optimized: Critical CSS extraction and hydration
Feature | CSS-in-Rust | styled-components | emotion |
---|---|---|---|
Runtime Performance | โญโญโญโญโญ | โญโญโญ | โญโญโญโญ |
Type Safety | โญโญโญโญโญ | โญโญ | โญโญ |
Bundle Size | โญโญโญโญโญ | โญโญโญ | โญโญโญโญ |
Developer Experience | โญโญโญโญ | โญโญโญโญโญ | โญโญโญโญ |
SSR Support | โญโญโญโญโญ | โญโญโญโญ | โญโญโญโญ |
Explore our examples directory for comprehensive usage examples:
- Basic Styling: Simple component styling
- Theme System: Advanced theming with design tokens
- Responsive Design: Mobile-first responsive components
- SSR Application: Server-side rendering setup
- Performance Demo: Benchmarking and optimization
- User Guide - Comprehensive usage guide
- API Reference - Complete API documentation
- Migration Guide - Migrating from CSS-in-JS
- Performance Guide - Optimization techniques
๐ง This project is currently in active development (Sprint 0/20)
- Project setup and architecture design
- Rust workspace initialization
- Core type system implementation
- Lightning CSS integration
- Dioxus hooks development
- Theme system implementation
- SSR support
- Development tools
- Documentation and examples
- Performance optimization
- Testing and release
See our detailed iteration plan for the complete roadmap.
We welcome contributions! Please see our Contributing Guide for details.
# Clone the repository
git clone https://github.com/css-in-rust/css-in-rust.git
cd css-in-rust
# Install Rust toolchain
rustup component add rustfmt clippy
rustup target add wasm32-unknown-unknown
# Install development tools
cargo install cargo-watch wasm-pack trunk
# Run tests
cargo test
# Run examples
cd examples/basic
trunk serve
This project is licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
- Lightning CSS - High-performance CSS parser and transformer
- Dioxus - Elegant React-like library for Rust
- styled-components - CSS-in-JS inspiration
- Ant Design - Design system reference
Built with โค๏ธ for the Rust and Dioxus community