feat(baseline): 添加 foreground 和 background 字段,并在相关方法中初始化和使用它们
This commit is contained in:
@@ -120,6 +120,10 @@ pub struct Baseline {
|
|||||||
pub outline: Oklch,
|
pub outline: Oklch,
|
||||||
#[serde(serialize_with = "crate::foreign_serializer::serialize_oklch_to_hex")]
|
#[serde(serialize_with = "crate::foreign_serializer::serialize_oklch_to_hex")]
|
||||||
pub outline_variant: Oklch,
|
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)]
|
#[serde(skip)]
|
||||||
pub neutral_lightness: f32,
|
pub neutral_lightness: f32,
|
||||||
#[serde(skip)]
|
#[serde(skip)]
|
||||||
@@ -300,6 +304,19 @@ impl Baseline {
|
|||||||
let warn_unit = ColorUnit::new(warn, &neutral_swatch, reference_lightness, settings);
|
let warn_unit = ColorUnit::new(warn, &neutral_swatch, reference_lightness, settings);
|
||||||
let info_unit = ColorUnit::new(info, &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 {
|
Self {
|
||||||
primary: primary_unit,
|
primary: primary_unit,
|
||||||
secondary: secondary_unit,
|
secondary: secondary_unit,
|
||||||
@@ -318,6 +335,8 @@ impl Baseline {
|
|||||||
overlay: overlay_color,
|
overlay: overlay_color,
|
||||||
outline: outline_color,
|
outline: outline_color,
|
||||||
outline_variant: outline_variant_color,
|
outline_variant: outline_variant_color,
|
||||||
|
foreground,
|
||||||
|
background,
|
||||||
neutral_lightness: reference_lightness,
|
neutral_lightness: reference_lightness,
|
||||||
scheme_settings: settings.clone(),
|
scheme_settings: settings.clone(),
|
||||||
is_dark,
|
is_dark,
|
||||||
@@ -392,6 +411,14 @@ impl Baseline {
|
|||||||
"--color-{scheme_mode}-outline-variant: #{};",
|
"--color-{scheme_mode}-outline-variant: #{};",
|
||||||
map_oklch_to_srgb_hex(&self.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 {
|
for (name, color_unit) in &self.custom_colors {
|
||||||
let lowercased_name = name.to_lowercase();
|
let lowercased_name = name.to_lowercase();
|
||||||
@@ -442,6 +469,14 @@ impl Baseline {
|
|||||||
"outline-variant".to_string(),
|
"outline-variant".to_string(),
|
||||||
map_oklch_to_srgb_hex(&self.outline_variant),
|
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 {
|
for (name, color) in &self.custom_colors {
|
||||||
let lowercased_name = name.to_lowercase();
|
let lowercased_name = name.to_lowercase();
|
||||||
@@ -503,6 +538,14 @@ impl Baseline {
|
|||||||
"$color-{scheme_mode}-outline-variant: #{};",
|
"$color-{scheme_mode}-outline-variant: #{};",
|
||||||
map_oklch_to_srgb_hex(&self.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 {
|
for (name, color) in &self.custom_colors {
|
||||||
let lowercased_name = name.to_lowercase();
|
let lowercased_name = name.to_lowercase();
|
||||||
@@ -604,6 +647,14 @@ impl Baseline {
|
|||||||
"{indent}outlineVariant: '#{}',",
|
"{indent}outlineVariant: '#{}',",
|
||||||
map_oklch_to_srgb_hex(&self.outline_variant)
|
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 {
|
for (name, color) in &self.custom_colors {
|
||||||
let lowercased_name = name.to_lowercase();
|
let lowercased_name = name.to_lowercase();
|
||||||
|
|||||||
Reference in New Issue
Block a user