增加Material Design 2主题样式的生成和导出。

This commit is contained in:
徐涛
2025-01-20 11:04:16 +08:00
parent d07fe9d41a
commit 119436608a
6 changed files with 686 additions and 1 deletions

View File

@@ -1,7 +1,7 @@
use palette::{
cam16::{Cam16Jch, Parameters},
convert::FromColorUnclamped,
IsWithinBounds, Srgb,
Hsl, IsWithinBounds, Srgb,
};
pub fn map_cam16jch_to_srgb(origin: &Cam16Jch<f32>) -> Srgb {
@@ -24,3 +24,23 @@ pub fn map_cam16jch_to_srgb(origin: &Cam16Jch<f32>) -> Srgb {
pub fn map_cam16jch_to_srgb_hex(origin: &Cam16Jch<f32>) -> String {
format!("{:x}", map_cam16jch_to_srgb(origin).into_format::<u8>())
}
pub fn map_hsl_to_srgb(origin: &Hsl) -> Srgb {
let mut new_original = Hsl::new(origin.hue, origin.saturation, origin.lightness);
const FACTOR: f32 = 0.99;
loop {
let new_srgb = Srgb::from_color_unclamped(new_original);
if new_srgb.is_within_bounds() {
break new_srgb;
}
new_original = Hsl::new(
new_original.hue,
new_original.saturation * FACTOR,
new_original.lightness,
);
}
}
pub fn map_hsl_to_srgb_hex(origin: &Hsl) -> String {
format!("{:x}", map_hsl_to_srgb(origin).into_format::<u8>())
}