将枚举换成整型值的输出。
This commit is contained in:
@@ -8,6 +8,7 @@ crate-type = ["cdylib"]
|
||||
|
||||
[dependencies]
|
||||
color-name = "1.1.0"
|
||||
enum-iterator = "2.1.0"
|
||||
palette = { version = "0.7.6", features = ["serde"] }
|
||||
serde = { version = "1.0.216", features = ["derive"] }
|
||||
serde-wasm-bindgen = "0.6.5"
|
||||
|
@@ -4,7 +4,6 @@ use baseline::Baseline;
|
||||
use palette::FromColor;
|
||||
use scheme_setting::{ColorExpand, WACGSetting};
|
||||
use serde::Serialize;
|
||||
use strum::IntoEnumIterator;
|
||||
use wasm_bindgen::{prelude::wasm_bindgen, JsValue};
|
||||
|
||||
use crate::{errors, parse_option_to_oklch, parse_to_oklch};
|
||||
@@ -169,11 +168,11 @@ impl SchemeExport for QScheme {
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn q_scheme_color_expanding_methods() -> Result<JsValue, String> {
|
||||
let methods = ColorExpand::iter()
|
||||
let methods = enum_iterator::all::<ColorExpand>()
|
||||
.map(|variant| {
|
||||
serde_json::json!({
|
||||
"label": variant.label(),
|
||||
"value": variant.to_string(),
|
||||
"value": variant as u8,
|
||||
})
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
@@ -183,11 +182,11 @@ pub fn q_scheme_color_expanding_methods() -> Result<JsValue, String> {
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn q_scheme_wacg_settings() -> Result<JsValue, String> {
|
||||
let settings = WACGSetting::iter()
|
||||
let settings = enum_iterator::all::<WACGSetting>()
|
||||
.map(|setting| {
|
||||
serde_json::json!({
|
||||
"label": setting.label(),
|
||||
"value": setting.to_string(),
|
||||
"value": setting as u8,
|
||||
})
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
@@ -1,8 +1,9 @@
|
||||
use std::ops::Mul;
|
||||
|
||||
use enum_iterator::Sequence;
|
||||
use palette::Oklch;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use strum::{Display, EnumIter, EnumString};
|
||||
use strum::Display;
|
||||
use wasm_bindgen::prelude::wasm_bindgen;
|
||||
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
|
||||
@@ -68,9 +69,9 @@ pub struct SchemeSetting {
|
||||
pub wacg_follows: WACGSetting,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, Display, EnumString, EnumIter, Serialize, Deserialize)]
|
||||
#[strum(serialize_all = "lowercase")]
|
||||
#[derive(Debug, Clone, Copy, Display, Sequence, Serialize, Deserialize)]
|
||||
#[wasm_bindgen]
|
||||
#[repr(u8)]
|
||||
pub enum ColorExpand {
|
||||
Complementary,
|
||||
Analogous,
|
||||
@@ -95,9 +96,9 @@ impl ColorExpand {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, Display, EnumString, EnumIter, Serialize, Deserialize)]
|
||||
#[strum(serialize_all = "lowercase")]
|
||||
#[derive(Debug, Clone, Copy, Display, Sequence, Serialize, Deserialize)]
|
||||
#[wasm_bindgen]
|
||||
#[repr(u8)]
|
||||
pub enum WACGSetting {
|
||||
Fixed,
|
||||
AutomaticAA,
|
||||
|
Reference in New Issue
Block a user