auditmysite 1.7.2

Resource-efficient WCAG 2.2 AA Accessibility Checker in Rust
Documentation
//! `AuditModule` implementation for Dark-mode collection (#332).

use async_trait::async_trait;
use tracing::warn;

use crate::audit::module::{AuditModule, ModuleContext, ModuleData};
use crate::audit::PipelineConfig;
use crate::error::Result;

use super::analyze_dark_mode_with_base_media;

pub struct DarkModeModule;

#[async_trait]
impl AuditModule for DarkModeModule {
    fn id(&self) -> &'static str {
        "dark_mode"
    }

    fn label(&self) -> &'static str {
        "Dark Mode"
    }

    fn is_enabled(&self, cfg: &PipelineConfig) -> bool {
        cfg.check_dark_mode
    }

    async fn collect(&self, ctx: &ModuleContext<'_>) -> Result<ModuleData> {
        let base = crate::display::media_features(ctx.pipeline_config.display_mode);
        match analyze_dark_mode_with_base_media(ctx.page, ctx.pipeline_config.wcag_level, &base)
            .await
        {
            Ok(dm) => Ok(ModuleData::DarkMode(Box::new(dm))),
            Err(e) => {
                warn!("Dark mode analysis failed: {}", e);
                Ok(ModuleData::None)
            }
        }
    }
}