tailwind_rs_postcss/lib.rs
1//! # tailwind-rs-postcss
2//!
3//! PostCSS integration for Tailwind-RS Core, providing advanced CSS processing
4//! capabilities with plugin ecosystem compatibility.
5//!
6//! This crate provides the foundation for PostCSS integration, enabling:
7//! - Advanced CSS processing with AST manipulation
8//! - Plugin ecosystem compatibility (NPM plugins)
9//! - Source map generation
10//! - Performance optimization
11//!
12//! ## Features
13//!
14//! - **PostCSS Engine**: Full PostCSS integration with Rust bindings
15//! - **Plugin System**: Support for NPM plugins and native Rust plugins
16//! - **AST Processing**: Advanced CSS AST parsing and manipulation
17//! - **Source Maps**: Complete source map generation and support
18//! - **Performance**: Optimized for large-scale CSS processing
19//!
20//! ## Example
21//!
22//! ```rust
23//! use tailwind_rs_postcss::*;
24//!
25//! #[tokio::main]
26//! async fn main() -> Result<()> {
27//! let engine = PostCSSEngine::new(PostCSSConfig::default())?;
28//!
29//! let input_css = "@tailwind base; @tailwind components; @tailwind utilities;";
30//! let result = engine.process_css(input_css).await?;
31//!
32//! println!("Generated CSS: {}", result.css);
33//! println!("Source map: {:?}", result.source_map);
34//!
35//! Ok(())
36//! }
37//! ```
38
39pub mod engine;
40pub mod ast;
41pub mod parser;
42pub mod transformer;
43pub mod js_bridge;
44pub mod plugin_loader;
45pub mod source_map;
46pub mod error;
47pub mod test_integration;
48
49// Re-export main types
50pub use engine::{PostCSSEngine, PostCSSConfig, ProcessedCSS};
51pub use ast::{CSSNode, CSSRule, CSSDeclaration, CSSAtRule};
52pub use parser::{CSSParser, ParseOptions};
53pub use transformer::{CSSTransformer, TransformOptions};
54pub use js_bridge::{JSBridge, JSRuntime};
55pub use plugin_loader::{PluginLoader, PluginConfig, PluginResult};
56pub use source_map::{SourceMapGenerator, SourceMap};
57pub use error::{PostCSSError, Result};
58
59/// Version information
60pub const VERSION: &str = env!("CARGO_PKG_VERSION");
61
62/// Default configuration for PostCSS processing
63pub fn default_config() -> PostCSSConfig {
64 PostCSSConfig::default()
65}
66
67/// Create a new PostCSS engine with default configuration
68pub fn new_engine() -> Result<PostCSSEngine> {
69 PostCSSEngine::new(PostCSSConfig::default())
70}
71
72/// Process CSS with PostCSS using default configuration
73pub async fn process_css(input: &str) -> Result<ProcessedCSS> {
74 let engine = new_engine()?;
75 engine.process_css(input).await
76}
77
78#[cfg(test)]
79mod tests {
80 use super::*;
81
82 #[test]
83 fn test_version_constant() {
84 assert!(!VERSION.is_empty());
85 assert!(VERSION.chars().any(|c| c.is_ascii_digit()));
86 }
87
88 #[test]
89 fn test_default_config() {
90 let config = default_config();
91 assert!(config.plugins.is_empty());
92 assert!(config.source_map);
93 }
94
95 #[tokio::test]
96 async fn test_process_css() {
97 let input = ".test { color: red; }";
98 let result = process_css(input).await;
99 assert!(result.is_ok());
100
101 let css = result.unwrap();
102 assert!(css.css.contains(".test"));
103 assert!(css.css.contains("color: red"));
104 }
105}