增加从WASM中生成Material Design 3主题样式的功能。
This commit is contained in:
26
color-module/src/convert/mod.rs
Normal file
26
color-module/src/convert/mod.rs
Normal 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>())
|
||||
}
|
||||
Reference in New Issue
Block a user