diff --git a/color-module/src/schemes/q_style_2/baseline.rs b/color-module/src/schemes/q_style_2/baseline.rs index 7ce8f08..f716a87 100644 --- a/color-module/src/schemes/q_style_2/baseline.rs +++ b/color-module/src/schemes/q_style_2/baseline.rs @@ -120,6 +120,10 @@ pub struct Baseline { pub outline: Oklch, #[serde(serialize_with = "crate::foreign_serializer::serialize_oklch_to_hex")] pub outline_variant: Oklch, + #[serde(serialize_with = "crate::foreign_serializer::serialize_oklch_to_hex")] + pub foreground: Oklch, + #[serde(serialize_with = "crate::foreign_serializer::serialize_oklch_to_hex")] + pub background: Oklch, #[serde(skip)] pub neutral_lightness: f32, #[serde(skip)] @@ -300,6 +304,19 @@ impl Baseline { let warn_unit = ColorUnit::new(warn, &neutral_swatch, reference_lightness, settings); let info_unit = ColorUnit::new(info, &neutral_swatch, reference_lightness, settings); + // Initialize foreground and background + let (foreground, background) = if is_dark { + // Dark mode: foreground = neutral_lightest, background = neutral_darkest with +10% lightness + let background_darkest = Oklch { + l: (neutral_darkest.l * 1.1).min(1.0), + ..*neutral_darkest + }; + (*neutral_lightest, background_darkest) + } else { + // Light mode: foreground = neutral_darkest, background = neutral_lightest + (*neutral_darkest, *neutral_lightest) + }; + Self { primary: primary_unit, secondary: secondary_unit, @@ -318,6 +335,8 @@ impl Baseline { overlay: overlay_color, outline: outline_color, outline_variant: outline_variant_color, + foreground, + background, neutral_lightness: reference_lightness, scheme_settings: settings.clone(), is_dark, @@ -392,6 +411,14 @@ impl Baseline { "--color-{scheme_mode}-outline-variant: #{};", map_oklch_to_srgb_hex(&self.outline_variant) )); + css_variables.push(format!( + "--color-{scheme_mode}-foreground: #{};", + map_oklch_to_srgb_hex(&self.foreground) + )); + css_variables.push(format!( + "--color-{scheme_mode}-background: #{};", + map_oklch_to_srgb_hex(&self.background) + )); for (name, color_unit) in &self.custom_colors { let lowercased_name = name.to_lowercase(); @@ -442,6 +469,14 @@ impl Baseline { "outline-variant".to_string(), map_oklch_to_srgb_hex(&self.outline_variant), ); + css_variables.insert( + "foreground".to_string(), + map_oklch_to_srgb_hex(&self.foreground), + ); + css_variables.insert( + "background".to_string(), + map_oklch_to_srgb_hex(&self.background), + ); for (name, color) in &self.custom_colors { let lowercased_name = name.to_lowercase(); @@ -503,6 +538,14 @@ impl Baseline { "$color-{scheme_mode}-outline-variant: #{};", map_oklch_to_srgb_hex(&self.outline_variant) )); + scss_variables.push(format!( + "$color-{scheme_mode}-foreground: #{};", + map_oklch_to_srgb_hex(&self.foreground) + )); + scss_variables.push(format!( + "$color-{scheme_mode}-background: #{};", + map_oklch_to_srgb_hex(&self.background) + )); for (name, color) in &self.custom_colors { let lowercased_name = name.to_lowercase(); @@ -604,6 +647,14 @@ impl Baseline { "{indent}outlineVariant: '#{}',", map_oklch_to_srgb_hex(&self.outline_variant) )); + javascript_fields.push(format!( + "{indent}foreground: '#{}',", + map_oklch_to_srgb_hex(&self.foreground) + )); + javascript_fields.push(format!( + "{indent}background: '#{}',", + map_oklch_to_srgb_hex(&self.background) + )); for (name, color) in &self.custom_colors { let lowercased_name = name.to_lowercase();