Compare commits
No commits in common. "c4a2f6f6387e4aed26c1b8848ac14e5f868fdb5b" and "7fba372d08b557aaee18b974dbf34546e9807ef9" have entirely different histories.
c4a2f6f638
...
7fba372d08
|
@ -81,22 +81,6 @@ impl M2BaselineColors {
|
||||||
variable_lines
|
variable_lines
|
||||||
}
|
}
|
||||||
|
|
||||||
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"));
|
|
||||||
variables.extend(self.error.to_css_auto_scheme_collection("error"));
|
|
||||||
variables.extend(self.background.to_css_auto_scheme_collection("background"));
|
|
||||||
variables.extend(self.surface.to_css_auto_scheme_collection("surface"));
|
|
||||||
variables.insert("shadow".to_string(), self.shadow.clone());
|
|
||||||
for (name, color_set) in &self.custom_colors {
|
|
||||||
variables.extend(color_set.to_css_auto_scheme_collection(&name.to_lowercase()));
|
|
||||||
}
|
|
||||||
|
|
||||||
variables
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn to_scss_variable(&self) -> Vec<String> {
|
pub fn to_scss_variable(&self) -> Vec<String> {
|
||||||
let mut variable_lines = Vec::new();
|
let mut variable_lines = Vec::new();
|
||||||
let prefix = if self.dark_set { "dark" } else { "light" };
|
let prefix = if self.dark_set { "dark" } else { "light" };
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
use std::collections::HashMap;
|
|
||||||
|
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
use crate::{convert::map_hsl_to_srgb_hex, errors};
|
use crate::{convert::map_hsl_to_srgb_hex, errors};
|
||||||
|
@ -84,16 +82,6 @@ impl M2ColorSet {
|
||||||
variable_lines
|
variable_lines
|
||||||
}
|
}
|
||||||
|
|
||||||
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());
|
|
||||||
variables.insert(format!("on-{}", name), self.on.clone());
|
|
||||||
|
|
||||||
variables
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn to_scss_variable(&self, prefix: &str, name: &str) -> Vec<String> {
|
pub fn to_scss_variable(&self, prefix: &str, name: &str) -> Vec<String> {
|
||||||
let mut variable_lines = Vec::new();
|
let mut variable_lines = Vec::new();
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
use std::collections::HashSet;
|
|
||||||
|
|
||||||
use baseline::M2BaselineColors;
|
use baseline::M2BaselineColors;
|
||||||
use palette::Hsl;
|
use palette::Hsl;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
@ -50,34 +48,6 @@ impl SchemeExport for MaterialDesign2Scheme {
|
||||||
css_variables.join("\n")
|
css_variables.join("\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn output_css_auto_scheme_variables(&self) -> String {
|
|
||||||
let mut auto_scheme_variables = Vec::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());
|
|
||||||
keys.extend(dark_baseline.keys());
|
|
||||||
for key in keys {
|
|
||||||
match (light_baseline.get(key), dark_baseline.get(key)) {
|
|
||||||
(Some(light), Some(dark)) => {
|
|
||||||
auto_scheme_variables.push(format!(
|
|
||||||
"--color-{}: light-dark(#{}, #{}):",
|
|
||||||
key, light, dark
|
|
||||||
));
|
|
||||||
}
|
|
||||||
(Some(color), None) | (None, Some(color)) => {
|
|
||||||
auto_scheme_variables.push(format!("--color-{}: #{};", key, color));
|
|
||||||
}
|
|
||||||
(None, None) => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
auto_scheme_variables.join("\n")
|
|
||||||
}
|
|
||||||
|
|
||||||
fn output_scss_variables(&self) -> String {
|
fn output_scss_variables(&self) -> String {
|
||||||
let mut scss_variables = Vec::new();
|
let mut scss_variables = Vec::new();
|
||||||
|
|
||||||
|
|
|
@ -131,25 +131,6 @@ impl M3BaselineColors {
|
||||||
css_variables
|
css_variables
|
||||||
}
|
}
|
||||||
|
|
||||||
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"));
|
|
||||||
collection.extend(self.tertiary.to_css_auto_scheme_collection("tertiary"));
|
|
||||||
collection.extend(self.error.to_css_auto_scheme_collection("error"));
|
|
||||||
collection.extend(self.surface.to_css_auto_scheme_collection());
|
|
||||||
collection.insert("outline".to_string(), self.outline.clone());
|
|
||||||
collection.insert("outline-variant".to_string(), self.outline_variant.clone());
|
|
||||||
collection.insert("scrim".to_string(), self.scrim.clone());
|
|
||||||
collection.insert("shadow".to_string(), self.shadow.clone());
|
|
||||||
for (name, color_set) in &self.customs {
|
|
||||||
collection.extend(color_set.to_css_auto_scheme_collection(&name.to_lowercase()));
|
|
||||||
}
|
|
||||||
|
|
||||||
collection
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn to_scss_variables(&self) -> Vec<String> {
|
pub fn to_scss_variables(&self) -> Vec<String> {
|
||||||
let mut scss_variables = Vec::new();
|
let mut scss_variables = Vec::new();
|
||||||
let prefix = if self.dark_set { "dark" } else { "light" };
|
let prefix = if self.dark_set { "dark" } else { "light" };
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
use std::collections::HashMap;
|
|
||||||
|
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
use crate::convert::map_lch_to_srgb_hex;
|
use crate::convert::map_lch_to_srgb_hex;
|
||||||
|
@ -108,25 +106,6 @@ impl M3ColorSet {
|
||||||
variable_lines
|
variable_lines
|
||||||
}
|
}
|
||||||
|
|
||||||
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());
|
|
||||||
variables.insert(format!("{}-container", name), self.container.clone());
|
|
||||||
variables.insert(format!("on-{}-container", name), self.on_container.clone());
|
|
||||||
variables.insert(format!("{}-fixed", name), self.fixed.clone());
|
|
||||||
variables.insert(format!("{}-fixed-dim", name), self.fixed_dim.clone());
|
|
||||||
variables.insert(format!("on-{}-fixed", name), self.on_fixed.clone());
|
|
||||||
variables.insert(
|
|
||||||
format!("on-{}-fixed-variant", name),
|
|
||||||
self.fixed_variant.clone(),
|
|
||||||
);
|
|
||||||
variables.insert(format!("inverse-{}", name), self.inverse.clone());
|
|
||||||
|
|
||||||
variables
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn to_scss_variables(&self, prefix: &str, name: &str) -> Vec<String> {
|
pub fn to_scss_variables(&self, prefix: &str, name: &str) -> Vec<String> {
|
||||||
let mut variable_lines = Vec::new();
|
let mut variable_lines = Vec::new();
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::HashMap;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
pub use baseline::M3BaselineColors;
|
pub use baseline::M3BaselineColors;
|
||||||
|
@ -111,37 +111,6 @@ impl SchemeExport for MaterialDesign3Scheme {
|
||||||
css_variables.join("\n")
|
css_variables.join("\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn output_css_auto_scheme_variables(&self) -> String {
|
|
||||||
let mut auto_scheme_variables = Vec::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());
|
|
||||||
keys.extend(dark_baseline.keys());
|
|
||||||
for key in keys {
|
|
||||||
match (light_baseline.get(key), dark_baseline.get(key)) {
|
|
||||||
(Some(light), Some(dark)) => {
|
|
||||||
auto_scheme_variables.push(format!(
|
|
||||||
"--color-{}: light-dark(#{}, #{}):",
|
|
||||||
key, light, dark
|
|
||||||
));
|
|
||||||
}
|
|
||||||
(Some(color), None) | (None, Some(color)) => {
|
|
||||||
auto_scheme_variables.push(format!("--color-{}: #{};", key, color));
|
|
||||||
}
|
|
||||||
(None, None) => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (name, swatch) in &self.swatches {
|
|
||||||
auto_scheme_variables.extend(swatch.to_css_variables(name));
|
|
||||||
}
|
|
||||||
|
|
||||||
auto_scheme_variables.join("\n")
|
|
||||||
}
|
|
||||||
|
|
||||||
fn output_scss_variables(&self) -> String {
|
fn output_scss_variables(&self) -> String {
|
||||||
let mut scss_variables = Vec::new();
|
let mut scss_variables = Vec::new();
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
use std::collections::HashMap;
|
|
||||||
|
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
use crate::convert::map_lch_to_srgb_hex;
|
use crate::convert::map_lch_to_srgb_hex;
|
||||||
|
@ -138,35 +136,6 @@ impl M3SurfaceSet {
|
||||||
css_variables
|
css_variables
|
||||||
}
|
}
|
||||||
|
|
||||||
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());
|
|
||||||
auto_scheme_collection.insert(format!("surface-bright"), self.bright.clone());
|
|
||||||
auto_scheme_collection.insert(format!("surface-variant"), self.variant.clone());
|
|
||||||
auto_scheme_collection.insert(format!("surface-container"), self.container.clone());
|
|
||||||
auto_scheme_collection.insert(
|
|
||||||
format!("surface-container-lowest"),
|
|
||||||
self.container_lowest.clone(),
|
|
||||||
);
|
|
||||||
auto_scheme_collection.insert(format!("surface-container-low"), self.container_low.clone());
|
|
||||||
auto_scheme_collection.insert(
|
|
||||||
format!("surface-container-high"),
|
|
||||||
self.container_high.clone(),
|
|
||||||
);
|
|
||||||
auto_scheme_collection.insert(
|
|
||||||
format!("surface-container-highest"),
|
|
||||||
self.container_highest.clone(),
|
|
||||||
);
|
|
||||||
auto_scheme_collection.insert(format!("on-surface"), self.on_root.clone());
|
|
||||||
auto_scheme_collection.insert(format!("on-surface-variant"), self.on_root_variant.clone());
|
|
||||||
auto_scheme_collection.insert(format!("inverse-surface"), self.inverse.clone());
|
|
||||||
auto_scheme_collection.insert(format!("inverse-on-surface"), self.on_inverse.clone());
|
|
||||||
|
|
||||||
auto_scheme_collection
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn to_scss_variables(&self, prefix: &str) -> Vec<String> {
|
pub fn to_scss_variables(&self, prefix: &str) -> Vec<String> {
|
||||||
let mut scss_variables = Vec::new();
|
let mut scss_variables = Vec::new();
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,6 @@ pub mod swatch_style;
|
||||||
|
|
||||||
pub trait SchemeExport {
|
pub trait SchemeExport {
|
||||||
fn output_css_variables(&self) -> String;
|
fn output_css_variables(&self) -> String;
|
||||||
fn output_css_auto_scheme_variables(&self) -> String;
|
|
||||||
fn output_scss_variables(&self) -> String;
|
fn output_scss_variables(&self) -> String;
|
||||||
fn output_javascript_object(&self) -> String;
|
fn output_javascript_object(&self) -> String;
|
||||||
}
|
}
|
||||||
|
@ -37,7 +36,6 @@ pub fn generate_material_design_3_scheme(
|
||||||
Ok(serde_wasm_bindgen::to_value(&(
|
Ok(serde_wasm_bindgen::to_value(&(
|
||||||
scheme.clone(),
|
scheme.clone(),
|
||||||
scheme.output_css_variables(),
|
scheme.output_css_variables(),
|
||||||
scheme.output_css_auto_scheme_variables(),
|
|
||||||
scheme.output_scss_variables(),
|
scheme.output_scss_variables(),
|
||||||
scheme.output_javascript_object(),
|
scheme.output_javascript_object(),
|
||||||
))
|
))
|
||||||
|
@ -60,7 +58,6 @@ pub fn generate_material_design_2_scheme(
|
||||||
Ok(serde_wasm_bindgen::to_value(&(
|
Ok(serde_wasm_bindgen::to_value(&(
|
||||||
scheme.clone(),
|
scheme.clone(),
|
||||||
scheme.output_css_variables(),
|
scheme.output_css_variables(),
|
||||||
scheme.output_css_auto_scheme_variables(),
|
|
||||||
scheme.output_scss_variables(),
|
scheme.output_scss_variables(),
|
||||||
scheme.output_javascript_object(),
|
scheme.output_javascript_object(),
|
||||||
))
|
))
|
||||||
|
@ -91,7 +88,6 @@ pub fn generate_q_scheme_automatically(
|
||||||
Ok(serde_wasm_bindgen::to_value(&(
|
Ok(serde_wasm_bindgen::to_value(&(
|
||||||
scheme.clone(),
|
scheme.clone(),
|
||||||
scheme.output_css_variables(),
|
scheme.output_css_variables(),
|
||||||
scheme.output_css_auto_scheme_variables(),
|
|
||||||
scheme.output_scss_variables(),
|
scheme.output_scss_variables(),
|
||||||
scheme.output_javascript_object(),
|
scheme.output_javascript_object(),
|
||||||
))
|
))
|
||||||
|
@ -128,7 +124,6 @@ pub fn generate_q_scheme_manually(
|
||||||
Ok(serde_wasm_bindgen::to_value(&(
|
Ok(serde_wasm_bindgen::to_value(&(
|
||||||
scheme.clone(),
|
scheme.clone(),
|
||||||
scheme.output_css_variables(),
|
scheme.output_css_variables(),
|
||||||
scheme.output_css_auto_scheme_variables(),
|
|
||||||
scheme.output_scss_variables(),
|
scheme.output_scss_variables(),
|
||||||
scheme.output_javascript_object(),
|
scheme.output_javascript_object(),
|
||||||
))
|
))
|
||||||
|
@ -144,7 +139,6 @@ pub fn generate_swatch_scheme(
|
||||||
Ok(serde_wasm_bindgen::to_value(&(
|
Ok(serde_wasm_bindgen::to_value(&(
|
||||||
scheme.swatches(),
|
scheme.swatches(),
|
||||||
scheme.output_css_variables(),
|
scheme.output_css_variables(),
|
||||||
scheme.output_css_auto_scheme_variables(),
|
|
||||||
scheme.output_scss_variables(),
|
scheme.output_scss_variables(),
|
||||||
scheme.output_javascript_object(),
|
scheme.output_javascript_object(),
|
||||||
))
|
))
|
||||||
|
@ -192,7 +186,6 @@ pub fn generate_material_design_3_dynamic_scheme(
|
||||||
Ok(serde_wasm_bindgen::to_value(&(
|
Ok(serde_wasm_bindgen::to_value(&(
|
||||||
scheme.clone(),
|
scheme.clone(),
|
||||||
scheme.output_css_variables(),
|
scheme.output_css_variables(),
|
||||||
scheme.output_css_auto_scheme_variables(),
|
|
||||||
scheme.output_scss_variables(),
|
scheme.output_scss_variables(),
|
||||||
scheme.output_javascript_object(),
|
scheme.output_javascript_object(),
|
||||||
))
|
))
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
use std::collections::HashMap;
|
|
||||||
|
|
||||||
use palette::{
|
use palette::{
|
||||||
color_theory::{Analogous, Complementary, SplitComplementary, Tetradic, Triadic},
|
color_theory::{Analogous, Complementary, SplitComplementary, Tetradic, Triadic},
|
||||||
Oklch, ShiftHue,
|
Oklch, ShiftHue,
|
||||||
|
@ -160,37 +158,6 @@ impl Baseline {
|
||||||
variables
|
variables
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
|
||||||
collection.extend(secondary.to_css_auto_scheme_collection("secondary"));
|
|
||||||
}
|
|
||||||
if let Some(tertiary) = &self.tertiary {
|
|
||||||
collection.extend(tertiary.to_css_auto_scheme_collection("tertiary"));
|
|
||||||
}
|
|
||||||
if let Some(accent) = &self.accent {
|
|
||||||
collection.extend(accent.to_css_auto_scheme_collection("accent"));
|
|
||||||
}
|
|
||||||
collection.extend(self.neutral.to_css_auto_scheme_collection("neutral"));
|
|
||||||
collection.extend(self.danger.to_css_auto_scheme_collection("danger"));
|
|
||||||
collection.extend(self.success.to_css_auto_scheme_collection("success"));
|
|
||||||
collection.extend(self.warning.to_css_auto_scheme_collection("warning"));
|
|
||||||
collection.extend(self.info.to_css_auto_scheme_collection("info"));
|
|
||||||
collection.extend(self.outline.to_css_auto_scheme_collection("outline"));
|
|
||||||
collection.insert(
|
|
||||||
"foreground".to_string(),
|
|
||||||
map_oklch_to_srgb_hex(&self.foreground),
|
|
||||||
);
|
|
||||||
collection.insert(
|
|
||||||
"background".to_string(),
|
|
||||||
map_oklch_to_srgb_hex(&self.background),
|
|
||||||
);
|
|
||||||
|
|
||||||
collection
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn to_scss_variables(&self, prefix: &str) -> Vec<String> {
|
pub fn to_scss_variables(&self, prefix: &str) -> Vec<String> {
|
||||||
let mut variables = Vec::new();
|
let mut variables = Vec::new();
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
use std::collections::HashMap;
|
|
||||||
|
|
||||||
use palette::{color_difference::Wcag21RelativeContrast, luma::Luma, Oklch};
|
use palette::{color_difference::Wcag21RelativeContrast, luma::Luma, Oklch};
|
||||||
use serde::{ser::SerializeStruct, Serialize};
|
use serde::{ser::SerializeStruct, Serialize};
|
||||||
|
|
||||||
|
@ -181,47 +179,6 @@ impl ColorSet {
|
||||||
variables
|
variables
|
||||||
}
|
}
|
||||||
|
|
||||||
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(
|
|
||||||
format!("{}-hover", name),
|
|
||||||
map_oklch_to_srgb_hex(&self.hover),
|
|
||||||
);
|
|
||||||
collection.insert(
|
|
||||||
format!("{}-active", name),
|
|
||||||
map_oklch_to_srgb_hex(&self.active),
|
|
||||||
);
|
|
||||||
collection.insert(
|
|
||||||
format!("{}-focus", name),
|
|
||||||
map_oklch_to_srgb_hex(&self.focus),
|
|
||||||
);
|
|
||||||
collection.insert(
|
|
||||||
format!("{}-disabled", name),
|
|
||||||
map_oklch_to_srgb_hex(&self.disabled),
|
|
||||||
);
|
|
||||||
collection.insert(format!("on-{}", name), map_oklch_to_srgb_hex(&self.on_root));
|
|
||||||
collection.insert(
|
|
||||||
format!("on-{}-hover", name),
|
|
||||||
map_oklch_to_srgb_hex(&self.on_hover),
|
|
||||||
);
|
|
||||||
collection.insert(
|
|
||||||
format!("on-{}-active", name),
|
|
||||||
map_oklch_to_srgb_hex(&self.on_active),
|
|
||||||
);
|
|
||||||
collection.insert(
|
|
||||||
format!("on-{}-focus", name),
|
|
||||||
map_oklch_to_srgb_hex(&self.on_focus),
|
|
||||||
);
|
|
||||||
collection.insert(
|
|
||||||
format!("on-{}-disabled", name),
|
|
||||||
map_oklch_to_srgb_hex(&self.on_disabled),
|
|
||||||
);
|
|
||||||
|
|
||||||
collection
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn to_scss_variables(&self, prefix: &str, name: &str) -> Vec<String> {
|
pub fn to_scss_variables(&self, prefix: &str, name: &str) -> Vec<String> {
|
||||||
let mut variables = Vec::new();
|
let mut variables = Vec::new();
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use std::{collections::HashSet, str::FromStr};
|
use std::str::FromStr;
|
||||||
|
|
||||||
use baseline::Baseline;
|
use baseline::Baseline;
|
||||||
use palette::FromColor;
|
use palette::FromColor;
|
||||||
|
@ -130,32 +130,6 @@ impl SchemeExport for QScheme {
|
||||||
variables.join("\n")
|
variables.join("\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn output_css_auto_scheme_variables(&self) -> String {
|
|
||||||
let mut collection = Vec::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());
|
|
||||||
keys.extend(dark_collection.keys());
|
|
||||||
for key in keys {
|
|
||||||
match (light_collection.get(key), dark_collection.get(key)) {
|
|
||||||
(Some(light), Some(dark)) => {
|
|
||||||
collection.push(format!(
|
|
||||||
"--color-{}: light-dark(#{}, #{});",
|
|
||||||
key, light, dark
|
|
||||||
));
|
|
||||||
}
|
|
||||||
(Some(color), None) | (None, Some(color)) => {
|
|
||||||
collection.push(format!("--color-{}: #{}", key, color));
|
|
||||||
}
|
|
||||||
(None, None) => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
collection.join("\n")
|
|
||||||
}
|
|
||||||
|
|
||||||
fn output_scss_variables(&self) -> String {
|
fn output_scss_variables(&self) -> String {
|
||||||
let mut variables = Vec::new();
|
let mut variables = Vec::new();
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use palette::FromColor;
|
use palette::FromColor;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::HashMap;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
pub use setting::SwatchSchemeSetting;
|
pub use setting::SwatchSchemeSetting;
|
||||||
|
@ -93,49 +93,6 @@ impl SchemeExport for SwatchScheme {
|
||||||
variables.join("\n")
|
variables.join("\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn output_css_auto_scheme_variables(&self) -> String {
|
|
||||||
let mut variables = Vec::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 {
|
|
||||||
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 {
|
|
||||||
let collection = swatch.to_css_auto_scheme_collection(&name);
|
|
||||||
keys.extend(collection.keys().cloned());
|
|
||||||
dark_collections.insert(name.clone(), collection.clone());
|
|
||||||
}
|
|
||||||
|
|
||||||
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) => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
variables.join("\n")
|
|
||||||
}
|
|
||||||
|
|
||||||
fn output_scss_variables(&self) -> String {
|
fn output_scss_variables(&self) -> String {
|
||||||
let mut variables = Vec::new();
|
let mut variables = Vec::new();
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
use std::collections::HashMap;
|
|
||||||
|
|
||||||
use palette::Oklch;
|
use palette::Oklch;
|
||||||
|
|
||||||
use crate::convert::map_oklch_to_srgb_hex;
|
use crate::convert::map_oklch_to_srgb_hex;
|
||||||
|
@ -96,17 +94,6 @@ impl Swatch {
|
||||||
variables
|
variables
|
||||||
}
|
}
|
||||||
|
|
||||||
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),
|
|
||||||
map_oklch_to_srgb_hex(color),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
collection
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn to_scss_variables(&self, prefix: &str, name: &str) -> Vec<String> {
|
pub fn to_scss_variables(&self, prefix: &str, name: &str) -> Vec<String> {
|
||||||
let mut variables = Vec::new();
|
let mut variables = Vec::new();
|
||||||
for (i, color) in self.swatch().iter().enumerate() {
|
for (i, color) in self.swatch().iter().enumerate() {
|
||||||
|
|
|
@ -32,7 +32,6 @@ export type MaterialDesign2SchemeStorage = {
|
||||||
source?: MaterialDesign2SchemeSource;
|
source?: MaterialDesign2SchemeSource;
|
||||||
scheme?: MaterialDesign2Scheme;
|
scheme?: MaterialDesign2Scheme;
|
||||||
cssVariables?: string;
|
cssVariables?: string;
|
||||||
cssAutoSchemeVariables?: string;
|
|
||||||
scssVariables?: string;
|
scssVariables?: string;
|
||||||
jsVariables?: string;
|
jsVariables?: string;
|
||||||
};
|
};
|
||||||
|
|
|
@ -72,7 +72,6 @@ export type MaterialDesign3DynamicSchemeStorage = {
|
||||||
source?: MaterialDesign3DynamicSchemeSource;
|
source?: MaterialDesign3DynamicSchemeSource;
|
||||||
scheme?: MaterialDesign3Scheme;
|
scheme?: MaterialDesign3Scheme;
|
||||||
cssVariables?: string;
|
cssVariables?: string;
|
||||||
cssAutoSchemeVariables?: string;
|
|
||||||
scssVariables?: string;
|
scssVariables?: string;
|
||||||
jsVariables?: string;
|
jsVariables?: string;
|
||||||
};
|
};
|
||||||
|
|
|
@ -8,7 +8,6 @@ import styles from './Export.module.css';
|
||||||
|
|
||||||
const exportOptions: Option[] = [
|
const exportOptions: Option[] = [
|
||||||
{ label: 'CSS', value: 'css' },
|
{ label: 'CSS', value: 'css' },
|
||||||
{ label: 'CSS Auto Scheme', value: 'css-auto' },
|
|
||||||
{ label: 'SCSS', value: 'scss' },
|
{ label: 'SCSS', value: 'scss' },
|
||||||
{ label: 'Javascript Object', value: 'js_object' },
|
{ label: 'Javascript Object', value: 'js_object' },
|
||||||
];
|
];
|
||||||
|
@ -23,8 +22,6 @@ export function SchemeExport({ scheme }: SchemeExportProps) {
|
||||||
switch (activeExport) {
|
switch (activeExport) {
|
||||||
case 'css':
|
case 'css':
|
||||||
return scheme.schemeStorage.cssVariables;
|
return scheme.schemeStorage.cssVariables;
|
||||||
case 'css-auto':
|
|
||||||
return scheme.schemeStorage.cssAutoSchemeVariables;
|
|
||||||
case 'scss':
|
case 'scss':
|
||||||
return scheme.schemeStorage.scssVariables;
|
return scheme.schemeStorage.scssVariables;
|
||||||
case 'js_object':
|
case 'js_object':
|
||||||
|
|
|
@ -79,9 +79,8 @@ export function M2SchemeBuilder({ scheme, onBuildComplete }: M2SchemeBuilderProp
|
||||||
dark: { custom_colors: mapToObject(generatedScheme[0].dark.custom_colors) },
|
dark: { custom_colors: mapToObject(generatedScheme[0].dark.custom_colors) },
|
||||||
});
|
});
|
||||||
prev.schemeStorage.cssVariables = generatedScheme[1];
|
prev.schemeStorage.cssVariables = generatedScheme[1];
|
||||||
prev.schemeStorage.cssAutoSchemeVariables = generatedScheme[2];
|
prev.schemeStorage.scssVariables = generatedScheme[2];
|
||||||
prev.schemeStorage.scssVariables = generatedScheme[3];
|
prev.schemeStorage.jsVariables = generatedScheme[3];
|
||||||
prev.schemeStorage.jsVariables = generatedScheme[4];
|
|
||||||
return prev;
|
return prev;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -103,9 +103,8 @@ export function M3DynamicSchemeBuilder({ scheme, onBuildCompleted }: M3DynamicSc
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
prev.schemeStorage.cssVariables = generate_scheme[1];
|
prev.schemeStorage.cssVariables = generate_scheme[1];
|
||||||
prev.schemeStorage.cssAutoSchemeVariables = generate_scheme[2];
|
prev.schemeStorage.scssVariables = generate_scheme[2];
|
||||||
prev.schemeStorage.scssVariables = generate_scheme[3];
|
prev.schemeStorage.jsVariables = generate_scheme[3];
|
||||||
prev.schemeStorage.jsVariables = generate_scheme[4];
|
|
||||||
return prev;
|
return prev;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -83,9 +83,8 @@ export function M3SchemeBuilder({ scheme, onBuildCompleted }: M3SchemeBuilderPro
|
||||||
},
|
},
|
||||||
} as MaterialDesign3Scheme;
|
} as MaterialDesign3Scheme;
|
||||||
prev.schemeStorage.cssVariables = generatedScheme[1];
|
prev.schemeStorage.cssVariables = generatedScheme[1];
|
||||||
prev.schemeStorage.cssAutoSchemeVariables = generatedScheme[2];
|
prev.schemeStorage.scssVariables = generatedScheme[2];
|
||||||
prev.schemeStorage.scssVariables = generatedScheme[3];
|
prev.schemeStorage.jsVariables = generatedScheme[3];
|
||||||
prev.schemeStorage.jsVariables = generatedScheme[4];
|
|
||||||
return prev;
|
return prev;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -163,9 +163,8 @@ export function QSchemeBuilder({ scheme, onBuildCompleted }: QSchemeBuilderProps
|
||||||
prev.schemeStorage.source = source;
|
prev.schemeStorage.source = source;
|
||||||
prev.schemeStorage.scheme = generatedScheme[0];
|
prev.schemeStorage.scheme = generatedScheme[0];
|
||||||
prev.schemeStorage.cssVariables = generatedScheme[1];
|
prev.schemeStorage.cssVariables = generatedScheme[1];
|
||||||
prev.schemeStorage.cssAutoSchemeVariables = generatedScheme[2];
|
prev.schemeStorage.scssVariables = generatedScheme[2];
|
||||||
prev.schemeStorage.scssVariables = generatedScheme[3];
|
prev.schemeStorage.jsVariables = generatedScheme[3];
|
||||||
prev.schemeStorage.jsVariables = generatedScheme[4];
|
|
||||||
return prev;
|
return prev;
|
||||||
});
|
});
|
||||||
onBuildCompleted?.();
|
onBuildCompleted?.();
|
||||||
|
|
|
@ -123,9 +123,8 @@ export function SwatchSchemeBuilder({ scheme, onBuildCompleted }: SwatchSchemeBu
|
||||||
};
|
};
|
||||||
prev.schemeStorage.scheme = mapToObject(generatedScheme[0]) as SwatchScheme;
|
prev.schemeStorage.scheme = mapToObject(generatedScheme[0]) as SwatchScheme;
|
||||||
prev.schemeStorage.cssVariables = generatedScheme[1];
|
prev.schemeStorage.cssVariables = generatedScheme[1];
|
||||||
prev.schemeStorage.cssAutoSchemeVariables = generatedScheme[2];
|
prev.schemeStorage.scssVariables = generatedScheme[2];
|
||||||
prev.schemeStorage.scssVariables = generatedScheme[3];
|
prev.schemeStorage.jsVariables = generatedScheme[3];
|
||||||
prev.schemeStorage.jsVariables = generatedScheme[4];
|
|
||||||
return prev;
|
return prev;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -55,7 +55,6 @@ export type QSchemeStorage = {
|
||||||
source?: QSchemeSource;
|
source?: QSchemeSource;
|
||||||
scheme?: QScheme;
|
scheme?: QScheme;
|
||||||
cssVariables?: string;
|
cssVariables?: string;
|
||||||
cssAutoSchemeVariables?: string;
|
|
||||||
scssVariables?: string;
|
scssVariables?: string;
|
||||||
jsVariables?: string;
|
jsVariables?: string;
|
||||||
};
|
};
|
||||||
|
|
|
@ -21,7 +21,6 @@ export type SwatchSchemeStorage = {
|
||||||
source?: SwatchSchemeSource;
|
source?: SwatchSchemeSource;
|
||||||
scheme?: SwatchScheme;
|
scheme?: SwatchScheme;
|
||||||
cssVariables?: string;
|
cssVariables?: string;
|
||||||
cssAutoSchemeVariables?: string;
|
|
||||||
scssVariables?: string;
|
scssVariables?: string;
|
||||||
jsVariables?: string;
|
jsVariables?: string;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue
Block a user