增加从WASM中生成Material Design 3主题样式的功能。

This commit is contained in:
徐涛
2025-01-17 15:41:44 +08:00
parent c9626f3b8e
commit d07fe9d41a
9 changed files with 845 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
use palette::{
cam16::{Cam16Jch, Parameters},
convert::FromColorUnclamped,
IsWithinBounds, Srgb,
};
pub fn map_cam16jch_to_srgb(origin: &Cam16Jch<f32>) -> Srgb {
let mut new_original = Cam16Jch::new(origin.lightness, origin.chroma, origin.hue);
const FACTOR: f32 = 0.99;
loop {
let new_srgb =
Srgb::from_color_unclamped(new_original.into_xyz(Parameters::default_static_wp(40.0)));
if new_srgb.is_within_bounds() {
break new_srgb;
}
new_original = Cam16Jch::new(
new_original.lightness,
new_original.chroma * FACTOR,
new_original.hue,
);
}
}
pub fn map_cam16jch_to_srgb_hex(origin: &Cam16Jch<f32>) -> String {
format!("{:x}", map_cam16jch_to_srgb(origin).into_format::<u8>())
}