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,