tailwind-rs-core 0.8.1

Core types and utilities for tailwind-rs
Documentation
# ๐ŸŽจ Tailwind-RS Core

[![Crates.io](https://img.shields.io/crates/v/tailwind-rs-core.svg)](https://crates.io/crates/tailwind-rs-core)
[![Documentation](https://docs.rs/tailwind-rs-core/badge.svg)](https://docs.rs/tailwind-rs-core)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Rust](https://img.shields.io/badge/rust-1.70+-orange.svg)](https://www.rust-lang.org)
[![WASM](https://img.shields.io/badge/WASM-compatible-green.svg)](https://webassembly.org/)

The **core library** for type-safe Tailwind CSS utilities in Rust. This crate provides the fundamental building blocks for creating Tailwind CSS classes with compile-time type safety and runtime validation.

## ๐ŸŒ **Current Status: Production Ready v0.8.1**

> **๐Ÿš€ Production Ready**: Complete implementation with real configuration system, theme management, tree-shaking, and CSS optimization.  
> **๐Ÿ“… Last Updated**: December 2024

### โœ… **What's Complete**

- **๐Ÿ—๏ธ Core Architecture**: Type-safe class building system with full validation
- **๐ŸŽจ Complete Utilities**: All major Tailwind CSS utility categories implemented
- **๐Ÿ“ฑ Responsive Design**: Complete breakpoint system (sm, md, lg, xl, 2xl)
- **๐ŸŽฏ State Variants**: All interactive states (hover, focus, active, disabled)
- **๐Ÿ›ก๏ธ Type Safety**: 100% compile-time validation of class combinations
- **๐Ÿงช Testing**: 593/593 tests passing (100% pass rate) with comprehensive coverage
- **โš™๏ธ Configuration System**: Real TOML parsing with type-safe validation
- **๐Ÿ”ง CSS Optimization**: Real optimization algorithms with accurate statistics
- **๐ŸŒณ Tree Shaking**: Actual unused code removal with detailed metrics
- **๐Ÿ“Š Statistics Tracking**: Complete metrics for optimization and tree-shaking
- **๐ŸŽจ Theme System**: Complete theme management with FromStr implementations
- **๐Ÿงน Code Quality**: Clean codebase with minimal warnings and no dead code

## ๐Ÿ“ฆ **Installation**

Add to your `Cargo.toml`:

```toml
[dependencies]
tailwind-rs-core = "0.8.1"
```

## ๐ŸŽฏ **Quick Start**

### Basic Usage

```rust
use tailwind_rs_core::*;

// Create a class builder
let classes = ClassBuilder::new()
    .padding(SpacingValue::Integer(4))
    .background_color(Color::new(ColorPalette::Blue, ColorShade::Shade500))
    .text_color(Color::new(ColorPalette::White, ColorShade::Shade500))
    .rounded_lg()
    .hover(|b| b.background_color(Color::new(ColorPalette::Blue, ColorShade::Shade600)))
    .build();

// Convert to CSS classes
let css_classes = classes.to_string();
// Result: "p-4 bg-blue-500 text-white rounded-lg hover:bg-blue-600"
```

### Configuration System

```rust
use tailwind_rs_core::config::*;

// Load configuration from TOML file
let config = TailwindConfig::from_file("tailwind.toml")?;

// Validate configuration
config.validate()?;

// Use configuration
let theme = &config.theme;
let color = theme.get_color("primary")?;
```

### Theme System

```rust
use tailwind_rs_core::theme::*;

// Parse colors from strings
let color = Color::from_str("#3b82f6")?; // Hex
let color = Color::from_str("rgb(59, 130, 246)")?; // RGB
let color = Color::from_str("hsl(217, 91%, 60%)")?; // HSL

// Parse spacing values
let spacing = Spacing::from_str("1rem")?; // Rem
let spacing = Spacing::from_str("16px")?; // Pixels
let spacing = Spacing::from_str("4")?; // Tailwind units

// Parse border radius
let radius = BorderRadius::from_str("8px")?; // Pixels
let radius = BorderRadius::from_str("0.5rem")?; // Rem
```

### Tree Shaking

```rust
use tailwind_rs_core::tree_shaker::*;

// Create tree shaker
let mut tree_shaker = TreeShaker::new();

// Configure tree shaking
let mut config = TreeShakeConfig::default();
config.remove_unused_responsive = true;
config.remove_unused_conditional = true;
tree_shaker.set_config(config);

// Perform tree shaking
let results = tree_shaker.shake(&source_paths, &mut css_generator)?;

// Get statistics
println!("Removed {} classes", results.stats.classes_removed);
println!("Removed {} responsive variants", results.stats.responsive_removed);
println!("Size reduction: {:.1}%", results.reduction_percentage);
```

### CSS Optimization

```rust
use tailwind_rs_core::css_optimizer::*;

// Create CSS optimizer
let optimizer = CssOptimizer::new();

// Configure optimization
let mut config = OptimizationConfig::default();
config.remove_empty_rules = true;
config.remove_duplicates = true;
config.optimize_properties = true;
let optimizer = CssOptimizer::with_config(config);

// Optimize CSS
let results = optimizer.optimize(&mut css_generator)?;

// Get statistics
println!("Removed {} empty rules", results.stats.empty_rules_removed);
println!("Removed {} duplicate properties", results.stats.duplicate_properties_removed);
println!("Size reduction: {:.1}%", results.reduction_percentage);
```

## ๐Ÿ—๏ธ **Architecture**

### Core Components

- **`ClassBuilder`**: Type-safe class construction with fluent API
- **`ClassSet`**: Efficient class management and caching
- **`SpacingValue`**: Type-safe spacing utilities (px, rem, em, %, auto)
- **`Color`**: Complete color palette system with hex, RGB, HSL support
- **`ResponsiveBuilder`**: Responsive design utilities with breakpoints
- **`TailwindConfig`**: Configuration management with TOML parsing
- **`Theme`**: Theme system with color, spacing, and custom values
- **`TreeShaker`**: Unused code removal with detailed statistics
- **`CssOptimizer`**: CSS optimization with rule merging and minification

### Utility Categories

| Category | Coverage | Status |
|----------|----------|---------|
| **Spacing** | 100% | โœ… Complete |
| **Layout** | 100% | โœ… Complete |
| **Sizing** | 100% | โœ… Complete |
| **Typography** | 100% | โœ… Complete |
| **Colors** | 100% | โœ… Complete |
| **Flexbox** | 100% | โœ… Complete |
| **Grid** | 100% | โœ… Complete |
| **Borders** | 100% | โœ… Complete |
| **Backgrounds** | 100% | โœ… Complete |
| **Effects** | 100% | โœ… Complete |
| **Filters** | 100% | โœ… Complete |
| **Transforms** | 100% | โœ… Complete |
| **Transitions** | 100% | โœ… Complete |
| **Animations** | 100% | โœ… Complete |
| **Interactivity** | 100% | โœ… Complete |
| **Responsive** | 100% | โœ… Complete |
| **State Variants** | 100% | โœ… Complete |
| **Arbitrary Values** | 100% | โœ… Complete |

## ๐Ÿงช **Testing**

Run the test suite:

```bash
cargo test --lib
```

Current test coverage: **593/593 passing tests (100% pass rate)** with comprehensive property-based testing, integration tests, performance tests, and visual regression tests.

## ๐Ÿ“š **API Reference**

### Core Types

- **`ClassBuilder`**: Main class construction API
- **`ClassSet`**: Class collection and management
- **`SpacingValue`**: Spacing utilities (px, rem, em, %, auto)
- **`Color`**: Color system with palette and shade support
- **`ResponsiveBuilder`**: Responsive design utilities

### Configuration Types

- **`TailwindConfig`**: Main configuration structure
- **`BuildConfig`**: Build-specific settings
- **`TailwindConfigToml`**: TOML configuration parsing
- **`Theme`**: Theme management system

### Optimization Types

- **`TreeShaker`**: Unused code removal
- **`CssOptimizer`**: CSS optimization
- **`TreeShakeResults`**: Tree-shaking statistics
- **`OptimizationResults`**: CSS optimization statistics

### Theme Types

- **`Color`**: Color values (hex, RGB, HSL, named)
- **`Spacing`**: Spacing values (px, rem, em, %, auto)
- **`BorderRadius`**: Border radius values
- **`BoxShadow`**: Box shadow properties
- **`ThemeValue`**: Generic theme values

## ๐Ÿ› ๏ธ **Development**

### Prerequisites

- Rust 1.70+
- Cargo

### Building

```bash
git clone https://github.com/yourusername/tailwind-rs.git
cd tailwind-rs/crates/tailwind-rs-core
cargo build
```

### Running Tests

```bash
cargo test --lib
```

### Running Examples

```bash
cargo run --example basic_usage
cargo run --example configuration
cargo run --example theme_system
```

## ๐Ÿค **Contributing**

We welcome contributions! Please see our [Contributing Guide](../../docs/contributing.md) for details.

## ๐Ÿ“„ **License**

This project is licensed under the MIT License - see the [LICENSE](../../LICENSE) file for details.

## ๐Ÿ™ **Acknowledgments**

- [Tailwind CSS]https://tailwindcss.com/ for the original design system
- [Leptos]https://leptos.dev/ for the reactive framework
- [Yew]https://yew.rs/ for the component framework
- [Dioxus]https://dioxuslabs.com/ for cross-platform UI

---

**๐ŸŽ‰ Production Ready**: This core library provides a complete, type-safe implementation of Tailwind CSS utilities in Rust with real configuration system, theme management, tree-shaking, and CSS optimization.