rustyle_css/tokens/
mod.rs

1//! Design token system for Rustyle
2//!
3//! This module provides a comprehensive design token system that serves as the
4//! foundation for type-safe styling. Design tokens define the visual language
5//! of your application in a centralized, maintainable way.
6
7pub mod animation;
8pub mod border;
9pub mod color;
10pub mod shadow;
11pub mod spacing;
12pub mod typography;
13pub mod validation;
14
15pub use animation::AnimationTokens;
16pub use border::BorderTokens;
17pub use color::ColorTokens;
18pub use shadow::ShadowTokens;
19pub use spacing::SpacingTokens;
20pub use typography::TypographyTokens;
21pub use validation::{TokenInheritance, TokenRuntime, TokenValidator, ValidationResult};
22
23// Design tokens don't need direct CSS type imports
24
25/// Comprehensive design token system
26///
27/// Aggregates all design tokens into a single, cohesive system.
28/// This is the foundation for building consistent, type-safe styles.
29#[derive(Clone, Debug)]
30pub struct DesignTokens {
31    /// Color tokens (primary, secondary, semantic colors)
32    pub colors: ColorTokens,
33    /// Spacing tokens (consistent spacing scale)
34    pub spacing: SpacingTokens,
35    /// Typography tokens (fonts, sizes, weights)
36    pub typography: TypographyTokens,
37    /// Shadow tokens (elevation system)
38    pub shadows: ShadowTokens,
39    /// Border tokens (widths, styles, radius)
40    pub borders: BorderTokens,
41    /// Animation tokens (durations, easing)
42    pub animations: AnimationTokens,
43}
44
45impl DesignTokens {
46    /// Create a new design token system with default values
47    pub fn new() -> Self {
48        Self {
49            colors: ColorTokens::default(),
50            spacing: SpacingTokens::default(),
51            typography: TypographyTokens::default(),
52            shadows: ShadowTokens::default(),
53            borders: BorderTokens::default(),
54            animations: AnimationTokens::default(),
55        }
56    }
57
58    /// Create a custom design token system
59    pub fn custom(
60        colors: ColorTokens,
61        spacing: SpacingTokens,
62        typography: TypographyTokens,
63        shadows: ShadowTokens,
64        borders: BorderTokens,
65        animations: AnimationTokens,
66    ) -> Self {
67        Self {
68            colors,
69            spacing,
70            typography,
71            shadows,
72            borders,
73            animations,
74        }
75    }
76
77    /// Convert design tokens to CSS custom properties
78    pub fn to_css_vars(&self) -> String {
79        let mut vars = String::from(":root {\n");
80
81        // Color variables
82        vars.push_str(&self.colors.to_css_vars());
83
84        // Spacing variables
85        vars.push_str(&self.spacing.to_css_vars());
86
87        // Typography variables
88        vars.push_str(&self.typography.to_css_vars());
89
90        // Shadow variables
91        vars.push_str(&self.shadows.to_css_vars());
92
93        // Border variables
94        vars.push_str(&self.borders.to_css_vars());
95
96        // Animation variables
97        vars.push_str(&self.animations.to_css_vars());
98
99        vars.push_str("}\n");
100        vars
101    }
102}
103
104impl Default for DesignTokens {
105    fn default() -> Self {
106        Self::new()
107    }
108}