tailwind_rs_postcss/purger/
types.rs

1//! Types and data structures for CSS purging
2
3use std::collections::HashSet;
4use thiserror::Error;
5
6/// Configuration for CSS purging
7#[derive(Debug, Clone)]
8pub struct PurgeConfig {
9    pub content_paths: Vec<String>,
10    pub safelist: Vec<String>,
11    pub blocklist: Vec<String>,
12    pub preserve_comments: bool,
13    pub preserve_keyframes: bool,
14    pub preserve_media_queries: bool,
15}
16
17impl Default for PurgeConfig {
18    fn default() -> Self {
19        Self {
20            content_paths: Vec::new(),
21            safelist: Vec::new(),
22            blocklist: Vec::new(),
23            preserve_comments: true,
24            preserve_keyframes: true,
25            preserve_media_queries: true,
26        }
27    }
28}
29
30/// Advanced purge options
31#[derive(Debug, Clone)]
32pub struct PurgeOptions {
33    pub include_patterns: Vec<String>,
34    pub exclude_patterns: Vec<String>,
35    pub custom_extractors: Vec<String>,
36    pub preserve_whitespace: bool,
37    pub minify_output: bool,
38}
39
40impl Default for PurgeOptions {
41    fn default() -> Self {
42        Self {
43            include_patterns: Vec::new(),
44            exclude_patterns: Vec::new(),
45            custom_extractors: Vec::new(),
46            preserve_whitespace: false,
47            minify_output: true,
48        }
49    }
50}
51
52/// Result of CSS purging
53#[derive(Debug, Clone)]
54pub struct PurgeResult {
55    pub purged_css: String,
56    pub used_classes: usize,
57    pub removed_classes: usize,
58    pub original_size: usize,
59    pub purged_size: usize,
60    pub size_reduction_percentage: f64,
61    pub processing_time: std::time::Duration,
62}
63
64/// Purge statistics
65#[derive(Debug, Clone)]
66pub struct PurgeStatistics {
67    pub total_purges: usize,
68    pub average_size_reduction: f64,
69    pub processing_time: std::time::Duration,
70}
71
72/// Content file information
73#[derive(Debug, Clone)]
74pub struct ContentFile {
75    pub path: String,
76    pub content: String,
77    pub file_type: FileType,
78    pub classes: HashSet<String>,
79}
80
81/// File type for content scanning
82#[derive(Debug, Clone, PartialEq)]
83pub enum FileType {
84    Html,
85    JavaScript,
86    TypeScript,
87    Rust,
88    Vue,
89    Svelte,
90    Other(String),
91}
92
93/// Class extraction result
94#[derive(Debug, Clone)]
95pub struct ClassExtractionResult {
96    pub classes: HashSet<String>,
97    pub extraction_time: std::time::Duration,
98}
99
100/// Rule filtering result
101#[derive(Debug, Clone)]
102pub struct RuleFilterResult {
103    pub filtered_css: String,
104    pub rules_removed: usize,
105    pub rules_kept: usize,
106    pub filtering_time: std::time::Duration,
107}
108
109/// Error types for CSS purging
110#[derive(Debug, Error)]
111pub enum PurgeError {
112    #[error("Content scanning failed: {error}")]
113    ContentScanningFailed { error: String },
114    
115    #[error("Class extraction failed: {error}")]
116    ClassExtractionFailed { error: String },
117    
118    #[error("Rule filtering failed: {error}")]
119    RuleFilteringFailed { error: String },
120    
121    #[error("File reading failed: {path} - {error}")]
122    FileReadingFailed { path: String, error: String },
123    
124    #[error("Invalid configuration: {error}")]
125    InvalidConfiguration { error: String },
126    
127    #[error("Memory limit exceeded")]
128    MemoryLimitExceeded,
129    
130    #[error("Processing timeout")]
131    ProcessingTimeout,
132}