From 3ad637e1fa7700b756f019fcccb95244b3a245d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E6=B6=9B?= Date: Wed, 22 Jan 2025 16:15:29 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=8F=98QScheme=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E5=86=85=E5=AE=B9=E7=9A=84=E5=AF=BC=E5=87=BA=E6=96=B9=E5=BC=8F?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- color-module/src/schemes/mod.rs | 13 +++++-------- color-module/src/schemes/q_style/mod.rs | 2 +- color-module/src/schemes/q_style/scheme_setting.rs | 5 +++++ 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/color-module/src/schemes/mod.rs b/color-module/src/schemes/mod.rs index 77adca7..e1ac790 100644 --- a/color-module/src/schemes/mod.rs +++ b/color-module/src/schemes/mod.rs @@ -10,6 +10,7 @@ use crate::errors; pub mod material_design_2; pub mod material_design_3; pub mod q_style; +pub mod swatch_style; pub trait SchemeExport { fn output_css_variables(&self) -> String; @@ -69,10 +70,8 @@ pub fn generate_q_scheme_automatically( info_color: &str, fg_color: &str, bg_color: &str, - setting: JsValue, + setting: SchemeSetting, ) -> Result { - let settings: SchemeSetting = serde_wasm_bindgen::from_value(setting) - .map_err(|_| errors::ColorError::UnableToParseArgument)?; let scheme = QScheme::new( primary_color, danger_color, @@ -81,7 +80,7 @@ pub fn generate_q_scheme_automatically( info_color, fg_color, bg_color, - settings, + setting, )?; Ok(serde_wasm_bindgen::to_value(&( scheme.clone(), @@ -104,10 +103,8 @@ pub fn generate_q_scheme_manually( info_color: &str, fg_color: &str, bg_color: &str, - setting: JsValue, + setting: SchemeSetting, ) -> Result { - let settings: SchemeSetting = serde_wasm_bindgen::from_value(setting) - .map_err(|_| errors::ColorError::UnableToParseArgument)?; let scheme = QScheme::custom( primary_color, secondary_color.as_deref(), @@ -119,7 +116,7 @@ pub fn generate_q_scheme_manually( info_color, fg_color, bg_color, - settings, + setting, )?; Ok(serde_wasm_bindgen::to_value(&( scheme.clone(), diff --git a/color-module/src/schemes/q_style/mod.rs b/color-module/src/schemes/q_style/mod.rs index c8696de..5b71828 100644 --- a/color-module/src/schemes/q_style/mod.rs +++ b/color-module/src/schemes/q_style/mod.rs @@ -16,7 +16,7 @@ mod color_set; mod neutral_swatch; mod scheme_setting; -pub use scheme_setting::SchemeSetting; +pub use scheme_setting::{ColorShifting, SchemeSetting}; #[derive(Debug, Clone, Serialize)] pub struct QScheme { diff --git a/color-module/src/schemes/q_style/scheme_setting.rs b/color-module/src/schemes/q_style/scheme_setting.rs index f3d470f..cb79063 100644 --- a/color-module/src/schemes/q_style/scheme_setting.rs +++ b/color-module/src/schemes/q_style/scheme_setting.rs @@ -3,8 +3,10 @@ use std::ops::Mul; use palette::Oklch; use serde::{Deserialize, Serialize}; use strum::{Display, EnumIter, EnumString}; +use wasm_bindgen::prelude::wasm_bindgen; #[derive(Debug, Clone, Copy, Serialize, Deserialize)] +#[wasm_bindgen] pub struct ColorShifting { pub chroma: f32, pub lightness: f32, @@ -55,6 +57,7 @@ impl Mul for &Oklch { } #[derive(Debug, Clone, Copy, Serialize, Deserialize)] +#[wasm_bindgen] pub struct SchemeSetting { pub hover: ColorShifting, pub active: ColorShifting, @@ -67,6 +70,7 @@ pub struct SchemeSetting { #[derive(Debug, Clone, Copy, Display, EnumString, EnumIter, Serialize, Deserialize)] #[strum(serialize_all = "lowercase")] +#[wasm_bindgen] pub enum ColorExpand { Complementary, Analogous, @@ -93,6 +97,7 @@ impl ColorExpand { #[derive(Debug, Clone, Copy, Display, EnumString, EnumIter, Serialize, Deserialize)] #[strum(serialize_all = "lowercase")] +#[wasm_bindgen] pub enum WACGSetting { Fixed, AutomaticAA,