mcu-scheme 0.2.2

Color scheme variants (TonalSpot, Vibrant, Expressive, etc.)
Documentation
// <FILE>crates/mcu-scheme/src/scheme_content.rs</FILE> - <DESC>Content-based color scheme</DESC>
// <VERS>VERSION: 2.0.0</VERS>
// <WCTX>Full implementation of content scheme wrapper</WCTX>
// <CLOG>Implement SchemeContent wrapping DynamicScheme with Variant::Content</CLOG>

use mcu_dynamiccolor::{DynamicScheme, DynamicSchemeOptions, Platform, SpecVersion, Variant};
use mcu_hct::Hct;
use std::ops::Deref;

/// A content-based color scheme that extracts dominant colors from images.
///
/// Designed to work with extracted colors from images or artwork.
/// Adapts to the dominant colors in visual content.
///
/// # Example
///
/// ```
/// use mcu_scheme::SchemeContent;
/// use mcu_hct::Hct;
///
/// let source = Hct::from_int(0xFF0000FF); // Blue
/// let scheme = SchemeContent::new(source, false, 0.0);
/// assert!(!scheme.is_dark);
/// ```
pub struct SchemeContent {
    scheme: DynamicScheme,
}

impl SchemeContent {
    /// Create a new content scheme.
    ///
    /// # Arguments
    ///
    /// * `source_color_hct` - The source color in HCT color space
    /// * `is_dark` - Whether to generate a dark mode scheme
    /// * `contrast_level` - Contrast level from -1.0 (minimum) to 1.0 (maximum), 0.0 is standard
    pub fn new(source_color_hct: Hct, is_dark: bool, contrast_level: f64) -> Self {
        let scheme = DynamicScheme::new(DynamicSchemeOptions::new(
            source_color_hct,
            Variant::Content,
            contrast_level,
            is_dark,
        ));
        Self { scheme }
    }

    /// Create a new content scheme with full options.
    ///
    /// # Arguments
    ///
    /// * `source_color_hct` - The source color in HCT color space
    /// * `is_dark` - Whether to generate a dark mode scheme
    /// * `contrast_level` - Contrast level from -1.0 (minimum) to 1.0 (maximum), 0.0 is standard
    /// * `platform` - Target platform (Phone or Watch)
    /// * `spec_version` - Design spec version (2021 or 2025)
    pub fn with_options(
        source_color_hct: Hct,
        is_dark: bool,
        contrast_level: f64,
        platform: Platform,
        spec_version: SpecVersion,
    ) -> Self {
        let mut options =
            DynamicSchemeOptions::new(source_color_hct, Variant::Content, contrast_level, is_dark);
        options.platform = Some(platform);
        options.spec_version = Some(spec_version);
        Self {
            scheme: DynamicScheme::new(options),
        }
    }
}

impl Deref for SchemeContent {
    type Target = DynamicScheme;

    fn deref(&self) -> &Self::Target {
        &self.scheme
    }
}

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

    #[test]
    fn test_new_light_mode() {
        let source = Hct::from_int(0xFF0000FF);
        let scheme = SchemeContent::new(source, false, 0.0);

        assert_eq!(scheme.variant, Variant::Content);
        assert!(!scheme.is_dark);
        assert_eq!(scheme.contrast_level, 0.0);
    }

    #[test]
    fn test_new_dark_mode() {
        let source = Hct::from_int(0xFF0000FF);
        let scheme = SchemeContent::new(source, true, 0.0);

        assert_eq!(scheme.variant, Variant::Content);
        assert!(scheme.is_dark);
    }

    #[test]
    fn test_contrast_levels() {
        let source = Hct::from_int(0xFF0000FF);

        let low = SchemeContent::new(source, false, -1.0);
        assert_eq!(low.contrast_level, -1.0);

        let high = SchemeContent::new(source, false, 1.0);
        assert_eq!(high.contrast_level, 1.0);
    }

    #[test]
    fn test_with_options() {
        let source = Hct::from_int(0xFF0000FF);
        let scheme =
            SchemeContent::with_options(source, true, 0.5, Platform::Watch, SpecVersion::Spec2025);

        assert_eq!(scheme.variant, Variant::Content);
        assert!(scheme.is_dark);
        assert_eq!(scheme.contrast_level, 0.5);
        assert_eq!(scheme.platform, Platform::Watch);
        // Content variant falls back to Spec2021 as it doesn't support 2025
        assert_eq!(scheme.spec_version, SpecVersion::Spec2021);
    }

    #[test]
    fn test_deref_access() {
        let source = Hct::from_int(0xFF0000FF);
        let scheme = SchemeContent::new(source, false, 0.0);

        // Access DynamicScheme fields through Deref
        let _primary = &scheme.primary_palette;
        let _secondary = &scheme.secondary_palette;
        let _argb = scheme.source_color_argb;
    }
}

// <FILE>crates/mcu-scheme/src/scheme_content.rs</FILE> - <DESC>Content-based color scheme</DESC>
// <VERS>END OF VERSION: 2.0.0</VERS>