From b20fd307877621c7437874e888efacd07a1068ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E6=B6=9B?= Date: Thu, 15 Jan 2026 08:39:22 +0800 Subject: [PATCH] =?UTF-8?q?feat(baseline):=20=E6=B7=BB=E5=8A=A0=20foregrou?= =?UTF-8?q?nd=20=E5=92=8C=20background=20=E5=AD=97=E6=AE=B5=EF=BC=8C?= =?UTF-8?q?=E5=B9=B6=E5=9C=A8=E7=9B=B8=E5=85=B3=E6=96=B9=E6=B3=95=E4=B8=AD?= =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E5=92=8C=E4=BD=BF=E7=94=A8=E5=AE=83?= =?UTF-8?q?=E4=BB=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/schemes/q_style_2/baseline.rs | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) 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();