Compare commits

..

No commits in common. "3b0600e64a9725e349ad48d9567c75577b2a3ca5" and "c4a2f6f6387e4aed26c1b8848ac14e5f868fdb5b" have entirely different histories.

13 changed files with 76 additions and 67 deletions

View File

@ -9,8 +9,6 @@ crate-type = ["cdylib"]
[dependencies]
color-name = "1.1.0"
enum-iterator = "2.1.0"
linked-hash-map = { version = "0.5.6", features = ["serde", "serde_impl"] }
linked_hash_set = { version = "0.1.5", features = ["serde"] }
palette = { version = "0.7.6", features = ["serde"] }
serde = { version = "1.0.216", features = ["derive"] }
serde-wasm-bindgen = "0.6.5"

View File

@ -1,6 +1,5 @@
use std::collections::HashMap;
use linked_hash_map::LinkedHashMap;
use serde::{ser::SerializeStruct, Serialize};
use crate::{convert::map_hsl_to_srgb_hex, errors, schemes::material_design_2::swatch::M2Swatch};
@ -82,8 +81,8 @@ impl M2BaselineColors {
variable_lines
}
pub fn to_css_auto_scheme_collection(&self) -> LinkedHashMap<String, String> {
let mut variables = LinkedHashMap::new();
pub fn to_css_auto_scheme_collection(&self) -> HashMap<String, String> {
let mut variables = HashMap::new();
variables.extend(self.primary.to_css_auto_scheme_collection("primary"));
variables.extend(self.secondary.to_css_auto_scheme_collection("secondary"));

View File

@ -1,4 +1,5 @@
use linked_hash_map::LinkedHashMap;
use std::collections::HashMap;
use serde::Serialize;
use crate::{convert::map_hsl_to_srgb_hex, errors};
@ -83,8 +84,8 @@ impl M2ColorSet {
variable_lines
}
pub fn to_css_auto_scheme_collection(&self, name: &str) -> LinkedHashMap<String, String> {
let mut variables = LinkedHashMap::new();
pub fn to_css_auto_scheme_collection(&self, name: &str) -> HashMap<String, String> {
let mut variables = HashMap::new();
variables.insert(format!("{}", name), self.root.clone());
variables.insert(format!("{}-variant", name), self.variant.clone());

View File

@ -1,5 +1,6 @@
use std::collections::HashSet;
use baseline::M2BaselineColors;
use linked_hash_set::LinkedHashSet;
use palette::Hsl;
use serde::Serialize;
@ -51,20 +52,20 @@ impl SchemeExport for MaterialDesign2Scheme {
fn output_css_auto_scheme_variables(&self) -> String {
let mut auto_scheme_variables = Vec::new();
let mut keys = LinkedHashSet::new();
let mut keys = HashSet::new();
let light_baseline = self.light.to_css_auto_scheme_collection();
let dark_baseline = self.dark.to_css_auto_scheme_collection();
auto_scheme_variables.push(format!("--color-white: #{};", self.white));
auto_scheme_variables.push(format!("--color-black: #{};", self.black));
keys.extend(light_baseline.keys().cloned());
keys.extend(dark_baseline.keys().cloned());
keys.extend(light_baseline.keys());
keys.extend(dark_baseline.keys());
for key in keys {
match (light_baseline.get(&key), dark_baseline.get(&key)) {
match (light_baseline.get(key), dark_baseline.get(key)) {
(Some(light), Some(dark)) => {
auto_scheme_variables.push(format!(
"--color-{}: light-dark(#{}, #{});",
"--color-{}: light-dark(#{}, #{}):",
key, light, dark
));
}

View File

@ -1,6 +1,5 @@
use std::collections::HashMap;
use linked_hash_map::LinkedHashMap;
use serde::Serialize;
use crate::convert::map_lch_to_srgb_hex;
@ -132,8 +131,8 @@ impl M3BaselineColors {
css_variables
}
pub fn to_css_auto_scheme_collection(&self) -> LinkedHashMap<String, String> {
let mut collection = LinkedHashMap::new();
pub fn to_css_auto_scheme_collection(&self) -> HashMap<String, String> {
let mut collection = HashMap::new();
collection.extend(self.primary.to_css_auto_scheme_collection("primary"));
collection.extend(self.secondary.to_css_auto_scheme_collection("secondary"));

View File

@ -1,4 +1,5 @@
use linked_hash_map::LinkedHashMap;
use std::collections::HashMap;
use serde::Serialize;
use crate::convert::map_lch_to_srgb_hex;
@ -107,8 +108,8 @@ impl M3ColorSet {
variable_lines
}
pub fn to_css_auto_scheme_collection(&self, name: &str) -> LinkedHashMap<String, String> {
let mut variables = LinkedHashMap::new();
pub fn to_css_auto_scheme_collection(&self, name: &str) -> HashMap<String, String> {
let mut variables = HashMap::new();
variables.insert(format!("{}", name), self.root.clone());
variables.insert(format!("on-{}", name), self.on_root.clone());

View File

@ -1,9 +1,8 @@
use std::collections::HashMap;
use std::collections::{HashMap, HashSet};
use std::str::FromStr;
pub use baseline::M3BaselineColors;
pub use color_set::M3ColorSet;
use linked_hash_set::LinkedHashSet;
use palette::{IntoColor, Lch, Srgb};
use serde::Serialize;
pub use surface::M3SurfaceSet;
@ -114,19 +113,19 @@ impl SchemeExport for MaterialDesign3Scheme {
fn output_css_auto_scheme_variables(&self) -> String {
let mut auto_scheme_variables = Vec::new();
let mut keys = LinkedHashSet::new();
let mut keys = HashSet::new();
let light_baseline = self.light_baseline.to_css_auto_scheme_collection();
let dark_baseline = self.dark_baseline.to_css_auto_scheme_collection();
auto_scheme_variables.push(format!("--color-white: #{};", self.white));
auto_scheme_variables.push(format!("--color-black: #{};", self.black));
keys.extend(light_baseline.keys().cloned());
keys.extend(dark_baseline.keys().cloned());
keys.extend(light_baseline.keys());
keys.extend(dark_baseline.keys());
for key in keys {
match (light_baseline.get(&key), dark_baseline.get(&key)) {
match (light_baseline.get(key), dark_baseline.get(key)) {
(Some(light), Some(dark)) => {
auto_scheme_variables.push(format!(
"--color-{}: light-dark(#{}, #{});",
"--color-{}: light-dark(#{}, #{}):",
key, light, dark
));
}

View File

@ -1,4 +1,5 @@
use linked_hash_map::LinkedHashMap;
use std::collections::HashMap;
use serde::Serialize;
use crate::convert::map_lch_to_srgb_hex;
@ -137,8 +138,8 @@ impl M3SurfaceSet {
css_variables
}
pub fn to_css_auto_scheme_collection(&self) -> LinkedHashMap<String, String> {
let mut auto_scheme_collection = LinkedHashMap::new();
pub fn to_css_auto_scheme_collection(&self) -> HashMap<String, String> {
let mut auto_scheme_collection = HashMap::new();
auto_scheme_collection.insert(format!("surface"), self.root.clone());
auto_scheme_collection.insert(format!("surface-dim"), self.dim.clone());

View File

@ -1,4 +1,5 @@
use linked_hash_map::LinkedHashMap;
use std::collections::HashMap;
use palette::{
color_theory::{Analogous, Complementary, SplitComplementary, Tetradic, Triadic},
Oklch, ShiftHue,
@ -159,8 +160,8 @@ impl Baseline {
variables
}
pub fn to_css_auto_scheme_collection(&self) -> LinkedHashMap<String, String> {
let mut collection = LinkedHashMap::new();
pub fn to_css_auto_scheme_collection(&self) -> HashMap<String, String> {
let mut collection = HashMap::new();
collection.extend(self.primary.to_css_auto_scheme_collection("primary"));
if let Some(secondary) = &self.secondary {

View File

@ -1,4 +1,5 @@
use linked_hash_map::LinkedHashMap;
use std::collections::HashMap;
use palette::{color_difference::Wcag21RelativeContrast, luma::Luma, Oklch};
use serde::{ser::SerializeStruct, Serialize};
@ -180,8 +181,8 @@ impl ColorSet {
variables
}
pub fn to_css_auto_scheme_collection(&self, name: &str) -> LinkedHashMap<String, String> {
let mut collection = LinkedHashMap::new();
pub fn to_css_auto_scheme_collection(&self, name: &str) -> HashMap<String, String> {
let mut collection = HashMap::new();
collection.insert(format!("{}", name), map_oklch_to_srgb_hex(&self.root));
collection.insert(

View File

@ -1,7 +1,6 @@
use std::str::FromStr;
use std::{collections::HashSet, str::FromStr};
use baseline::Baseline;
use linked_hash_set::LinkedHashSet;
use palette::FromColor;
use scheme_setting::{ColorExpand, WACGSetting};
use serde::Serialize;
@ -133,14 +132,14 @@ impl SchemeExport for QScheme {
fn output_css_auto_scheme_variables(&self) -> String {
let mut collection = Vec::new();
let mut keys = LinkedHashSet::new();
let mut keys = HashSet::new();
let light_collection = self.light.to_css_auto_scheme_collection();
let dark_collection = self.dark.to_css_auto_scheme_collection();
keys.extend(light_collection.keys().cloned());
keys.extend(dark_collection.keys().cloned());
keys.extend(light_collection.keys());
keys.extend(dark_collection.keys());
for key in keys {
match (light_collection.get(&key), dark_collection.get(&key)) {
match (light_collection.get(key), dark_collection.get(key)) {
(Some(light), Some(dark)) => {
collection.push(format!(
"--color-{}: light-dark(#{}, #{});",

View File

@ -1,8 +1,6 @@
use linked_hash_map::LinkedHashMap;
use linked_hash_set::LinkedHashSet;
use palette::FromColor;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::collections::{HashMap, HashSet};
use std::str::FromStr;
pub use setting::SwatchSchemeSetting;
@ -97,32 +95,42 @@ impl SchemeExport for SwatchScheme {
fn output_css_auto_scheme_variables(&self) -> String {
let mut variables = Vec::new();
let mut keys = LinkedHashSet::new();
let mut light_collections = LinkedHashMap::new();
let mut dark_collections = LinkedHashMap::new();
let mut keys = HashSet::new();
let mut names = HashSet::new();
let mut light_collections = HashMap::new();
let mut dark_collections = HashMap::new();
names.extend(self.light.keys());
names.extend(self.dark.keys());
for (name, swatch) in &self.light {
light_collections.extend(swatch.to_css_auto_scheme_collection(&name.to_lowercase()));
let collection = swatch.to_css_auto_scheme_collection(&name);
keys.extend(collection.keys().cloned());
light_collections.insert(name.clone(), collection.clone());
}
for (name, swatch) in &self.dark {
dark_collections.extend(swatch.to_css_auto_scheme_collection(&name.to_lowercase()));
let collection = swatch.to_css_auto_scheme_collection(&name);
keys.extend(collection.keys().cloned());
dark_collections.insert(name.clone(), collection.clone());
}
keys.extend(light_collections.keys().cloned());
keys.extend(dark_collections.keys().cloned());
for key in keys.iter() {
match (light_collections.get(key), dark_collections.get(key)) {
(Some(light), Some(dark)) => {
variables.push(format!(
"--color-{}: light-dark(#{}, #{});",
key, light, dark
));
for name in names {
for key in keys.iter() {
match (
light_collections.get(name).and_then(|lc| lc.get(key)),
dark_collections.get(name).and_then(|dc| dc.get(key)),
) {
(Some(light), Some(dark)) => {
variables.push(format!(
"--color-{}-{}: light-dark(#{}, #{});",
name, key, light, dark
));
}
(Some(color), None) | (None, Some(color)) => {
variables.push(format!("--color-{}-{}: #{};", name, key, color));
}
(None, None) => {}
}
(Some(color), None) | (None, Some(color)) => {
variables.push(format!("--color-{}: #{};", key, color));
}
(None, None) => {}
}
}
variables.join("\n")

View File

@ -1,4 +1,5 @@
use linked_hash_map::LinkedHashMap;
use std::collections::HashMap;
use palette::Oklch;
use crate::convert::map_oklch_to_srgb_hex;
@ -95,8 +96,8 @@ impl Swatch {
variables
}
pub fn to_css_auto_scheme_collection(&self, name: &str) -> LinkedHashMap<String, String> {
let mut collection = LinkedHashMap::new();
pub fn to_css_auto_scheme_collection(&self, name: &str) -> HashMap<String, String> {
let mut collection = HashMap::new();
for (i, color) in self.swatch().iter().enumerate() {
collection.insert(
format!("{}-{}", name, i * 100),