use crate::presentation::styles::CssProcessor;
use anyhow::Result;
use lightningcss::stylesheet::{MinifyOptions, PrinterOptions, StyleSheet};
use std::collections::HashSet;
pub fn apply_minification(stylesheet: &mut StyleSheet, processor: &CssProcessor) -> Result<()> {
if processor.minify {
let minify_options = MinifyOptions {
targets: processor.targets,
#[allow(clippy::if_same_then_else)]
unused_symbols: if processor.remove_unused {
HashSet::new() } else {
HashSet::new() },
};
stylesheet
.minify(minify_options)
.map_err(|e| anyhow::anyhow!("Failed to minify CSS: {}", e))?;
}
Ok(())
}
pub fn serialize_stylesheet(
stylesheet: &StyleSheet,
processor: &CssProcessor,
filename: &str,
) -> Result<String> {
let result = stylesheet
.to_css(PrinterOptions {
minify: processor.minify,
source_map: None, targets: processor.targets,
..PrinterOptions::default()
})
.map_err(|e| anyhow::anyhow!("Failed to serialize CSS from {}: {}", filename, e))?;
if processor.source_maps {
eprintln!("⚠️ Source maps requested but not yet implemented in Lightning CSS integration");
}
Ok(result.code)
}