tailwind-rs-postcss 0.15.4

PostCSS integration for Tailwind-RS Core
Documentation
//! Source map generation for PostCSS integration
//!
//! This module provides source map generation capabilities.

use crate::error::Result;
use serde::{Deserialize, Serialize};

/// Source map generator
#[derive(Debug)]
pub struct SourceMapGenerator;

/// Source map representation
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SourceMap {
    pub version: u32,
    pub sources: Vec<String>,
    pub names: Vec<String>,
    pub mappings: String,
    pub file: Option<String>,
    pub source_root: Option<String>,
    pub sources_content: Option<Vec<String>>,
}

/// Source map options
#[derive(Debug, Clone)]
pub struct SourceMapOptions {
    pub inline: bool,
    pub file: Option<String>,
    pub source_root: Option<String>,
    pub sources_content: bool,
}

impl SourceMapGenerator {
    /// Create a new source map generator
    pub fn new() -> Self {
        Self
    }

    /// Generate source map
    pub fn generate(
        &self,
        input: &str,
        output: &str,
        options: &SourceMapOptions,
    ) -> Result<SourceMap> {
        // Generate a basic source map
        let sources = if options.sources_content {
            vec![input.to_string()]
        } else {
            vec![]
        };

        let sources_content = if options.sources_content {
            Some(vec![input.to_string()])
        } else {
            None
        };

        // Generate basic mappings (1:1 mapping for now)
        let mappings = self.generate_mappings(input, output);

        Ok(SourceMap {
            version: 3,
            sources,
            names: Vec::new(),
            mappings,
            file: options.file.clone(),
            source_root: options.source_root.clone(),
            sources_content,
        })
    }

    /// Generate basic source map mappings
    fn generate_mappings(&self, input: &str, output: &str) -> String {
        // For now, generate a simple 1:1 mapping
        // In a real implementation, this would track the actual transformations
        let input_lines = input.lines().count();
        let output_lines = output.lines().count();

        if input_lines == output_lines {
            // Simple 1:1 mapping
            format!("AAAA;{}", input_lines)
        } else {
            // More complex mapping would be needed
            "AAAA".to_string()
        }
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_source_map_generator() {
        let generator = SourceMapGenerator::new();
        let options = SourceMapOptions {
            inline: false,
            file: None,
            source_root: None,
            sources_content: true,
        };

        let result = generator.generate("input", "output", &options);
        assert!(result.is_ok());
    }
}