feat(color-module): 添加 q_scheme_select_options 方法以支持 SchemeSelect 选项

This commit is contained in:
徐涛
2026-01-15 09:42:33 +08:00
parent b7ef02e7c3
commit d79a014916

View File

@@ -4,7 +4,7 @@ use baseline::Baseline;
use linked_hash_set::LinkedHashSet; use linked_hash_set::LinkedHashSet;
use palette::FromColor; use palette::FromColor;
use serde::Serialize; use serde::Serialize;
use wasm_bindgen::{prelude::wasm_bindgen, JsValue}; use wasm_bindgen::{JsValue, prelude::wasm_bindgen};
use crate::{errors, parse_option_to_oklch, parse_to_oklch}; use crate::{errors, parse_option_to_oklch, parse_to_oklch};
@@ -16,7 +16,7 @@ mod neutral_swatch;
mod scheme_setting; mod scheme_setting;
pub use neutral_swatch::NeutralSwatch; pub use neutral_swatch::NeutralSwatch;
pub use scheme_setting::{ColorExpand, ColorShifting, SchemeSetting, WACGSetting}; pub use scheme_setting::{ColorExpand, ColorShifting, SchemeSelect, SchemeSetting, WACGSetting};
#[derive(Debug, Clone, Serialize)] #[derive(Debug, Clone, Serialize)]
pub struct QScheme { pub struct QScheme {
@@ -221,6 +221,20 @@ pub fn q_scheme_wacg_settings() -> Result<JsValue, String> {
serde_wasm_bindgen::to_value(&settings).map_err(|e| e.to_string()) serde_wasm_bindgen::to_value(&settings).map_err(|e| e.to_string())
} }
#[wasm_bindgen]
pub fn q_scheme_select_options() -> Result<JsValue, String> {
let options = enum_iterator::all::<SchemeSelect>()
.map(|option| {
serde_json::json!({
"label": option.label(),
"value": option as u8,
})
})
.collect::<Vec<_>>();
serde_wasm_bindgen::to_value(&options).map_err(|e| e.to_string())
}
#[wasm_bindgen] #[wasm_bindgen]
pub fn q_scheme_default_settings() -> SchemeSetting { pub fn q_scheme_default_settings() -> SchemeSetting {
SchemeSetting::default() SchemeSetting::default()