Compare commits
11 Commits
0d9c11b4fb
...
main
Author | SHA1 | Date | |
---|---|---|---|
|
3f2e655b1c | ||
|
ae37903673 | ||
|
d88eebe356 | ||
|
f6ff4b10e6 | ||
|
1e4a9fd858 | ||
|
034f12c99b | ||
|
61ff3eff5c | ||
|
3bed5a97c5 | ||
|
ab4af06fd1 | ||
|
ec93cd5678 | ||
|
38b11dcd85 |
@@ -12,7 +12,10 @@ use crate::{
|
||||
errors,
|
||||
schemes::{
|
||||
q_style::{ColorExpand, NeutralSwatch, SchemeSetting},
|
||||
q_style_2::{color_set::ColorSet, swatch::Swatch},
|
||||
q_style_2::{
|
||||
color_set::ColorSet,
|
||||
swatch::{Swatch, generate_neutral_swatch_list},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
@@ -46,7 +49,10 @@ impl ColorUnit {
|
||||
let mut css_variables = Vec::new();
|
||||
|
||||
css_variables.extend(self.root.to_css_variables(prefix, name));
|
||||
css_variables.extend(self.surface.to_css_variables(prefix, name));
|
||||
css_variables.extend(
|
||||
self.surface
|
||||
.to_css_variables(prefix, &format!("{name}-surface")),
|
||||
);
|
||||
css_variables.extend(self.swatch.to_css_variables(prefix, name));
|
||||
|
||||
css_variables
|
||||
@@ -56,7 +62,10 @@ impl ColorUnit {
|
||||
let mut css_auto_scheme_collection = LinkedHashMap::new();
|
||||
|
||||
css_auto_scheme_collection.extend(self.root.to_css_auto_scheme_collection(name));
|
||||
css_auto_scheme_collection.extend(self.surface.to_css_auto_scheme_collection(name));
|
||||
css_auto_scheme_collection.extend(
|
||||
self.surface
|
||||
.to_css_auto_scheme_collection(&format!("{name}-surface")),
|
||||
);
|
||||
css_auto_scheme_collection.extend(self.swatch.to_css_auto_scheme_collection(name));
|
||||
|
||||
css_auto_scheme_collection
|
||||
@@ -66,7 +75,10 @@ impl ColorUnit {
|
||||
let mut scss_variables = Vec::new();
|
||||
|
||||
scss_variables.extend(self.root.to_scss_variables(prefix, name));
|
||||
scss_variables.extend(self.surface.to_scss_variables(prefix, name));
|
||||
scss_variables.extend(
|
||||
self.surface
|
||||
.to_scss_variables(prefix, &format!("{name}-surface")),
|
||||
);
|
||||
scss_variables.extend(self.swatch.to_scss_variables(prefix, name));
|
||||
|
||||
scss_variables
|
||||
@@ -76,7 +88,7 @@ impl ColorUnit {
|
||||
let mut js_object_fields = Vec::new();
|
||||
|
||||
js_object_fields.extend(self.root.to_javascript_fields(name));
|
||||
js_object_fields.extend(self.surface.to_javascript_fields(name));
|
||||
js_object_fields.extend(self.surface.to_javascript_fields(&format!("{name}Surface")));
|
||||
js_object_fields.extend(self.swatch.to_javascript_fields(name));
|
||||
|
||||
js_object_fields
|
||||
@@ -195,13 +207,10 @@ impl Baseline {
|
||||
neutral_lightest.l
|
||||
};
|
||||
let neutral_swatch = Arc::new(NeutralSwatch::new(*neutral_lightest, *neutral_darkest));
|
||||
let outline_color =
|
||||
neutral_swatch.get(neutral_lightest.l * if is_dark { 0.5 } else { 0.7 });
|
||||
let outline_variant_color =
|
||||
neutral_swatch.get(neutral_lightest.l * if is_dark { 0.3 } else { 0.8 });
|
||||
let outline_color = neutral_swatch.get(if is_dark { 0.25 } else { 0.7 });
|
||||
let outline_variant_color = neutral_swatch.get(if is_dark { 0.2 } else { 0.8 });
|
||||
let shadow_color = neutral_swatch.get(0.1);
|
||||
let overlay_color =
|
||||
neutral_swatch.get(neutral_lightest.l * if is_dark { 0.4 } else { 0.5 });
|
||||
let overlay_color = neutral_swatch.get(0.3);
|
||||
|
||||
let neutral_color = neutral_swatch.get(if is_dark { 0.35 } else { 0.65 });
|
||||
let neutral_variant_color = neutral_swatch.get(if is_dark { 0.45 } else { 0.55 });
|
||||
@@ -301,6 +310,11 @@ impl Baseline {
|
||||
if let Some(accent) = &self.accent {
|
||||
css_variables.extend(accent.to_css_variables(scheme_mode, "accent"));
|
||||
}
|
||||
|
||||
css_variables.extend(self.danger.to_css_variables(scheme_mode, "danger"));
|
||||
css_variables.extend(self.success.to_css_variables(scheme_mode, "success"));
|
||||
css_variables.extend(self.warn.to_css_variables(scheme_mode, "warn"));
|
||||
css_variables.extend(self.info.to_css_variables(scheme_mode, "info"));
|
||||
css_variables.extend(self.neutral.to_css_variables(scheme_mode, "neutral"));
|
||||
css_variables.extend(
|
||||
self.neutral_variant
|
||||
@@ -311,10 +325,11 @@ impl Baseline {
|
||||
self.surface_variant
|
||||
.to_css_variables(scheme_mode, "surface-variant"),
|
||||
);
|
||||
css_variables.extend(self.danger.to_css_variables(scheme_mode, "danger"));
|
||||
css_variables.extend(self.success.to_css_variables(scheme_mode, "success"));
|
||||
css_variables.extend(self.warn.to_css_variables(scheme_mode, "warn"));
|
||||
css_variables.extend(self.info.to_css_variables(scheme_mode, "info"));
|
||||
|
||||
let neutral_swatch = generate_neutral_swatch_list(&self.neutral_swatch);
|
||||
for (n, c) in neutral_swatch {
|
||||
css_variables.push(format!("--color-{scheme_mode}-swatch-neutral-{n}: #{c};"));
|
||||
}
|
||||
|
||||
css_variables.push(format!(
|
||||
"--color-{scheme_mode}-shadow: #{};",
|
||||
@@ -334,7 +349,8 @@ impl Baseline {
|
||||
));
|
||||
|
||||
for (name, color_unit) in &self.custom_colors {
|
||||
css_variables.extend(color_unit.to_css_variables(scheme_mode, name));
|
||||
let lowercased_name = name.to_lowercase();
|
||||
css_variables.extend(color_unit.to_css_variables(scheme_mode, &lowercased_name));
|
||||
}
|
||||
|
||||
css_variables
|
||||
@@ -353,6 +369,10 @@ impl Baseline {
|
||||
if let Some(accent) = &self.accent {
|
||||
css_variables.extend(accent.to_css_auto_scheme_collection("accent"));
|
||||
}
|
||||
css_variables.extend(self.danger.to_css_auto_scheme_collection("danger"));
|
||||
css_variables.extend(self.success.to_css_auto_scheme_collection("success"));
|
||||
css_variables.extend(self.warn.to_css_auto_scheme_collection("warn"));
|
||||
css_variables.extend(self.info.to_css_auto_scheme_collection("info"));
|
||||
css_variables.extend(self.neutral.to_css_auto_scheme_collection("neutral"));
|
||||
css_variables.extend(
|
||||
self.neutral_variant
|
||||
@@ -364,6 +384,11 @@ impl Baseline {
|
||||
.to_css_auto_scheme_collection("surface-variant"),
|
||||
);
|
||||
|
||||
let neutral_swatch = generate_neutral_swatch_list(&self.neutral_swatch);
|
||||
for (n, c) in neutral_swatch {
|
||||
css_variables.insert(format!("swatch-neutral-{n}"), c);
|
||||
}
|
||||
|
||||
css_variables.insert("shadow".to_string(), map_oklch_to_srgb_hex(&self.shadow));
|
||||
css_variables.insert("overlay".to_string(), map_oklch_to_srgb_hex(&self.overlay));
|
||||
css_variables.insert("outline".to_string(), map_oklch_to_srgb_hex(&self.outline));
|
||||
@@ -373,7 +398,8 @@ impl Baseline {
|
||||
);
|
||||
|
||||
for (name, color) in &self.custom_colors {
|
||||
css_variables.extend(color.to_css_auto_scheme_collection(name));
|
||||
let lowercased_name = name.to_lowercase();
|
||||
css_variables.extend(color.to_css_auto_scheme_collection(&lowercased_name));
|
||||
}
|
||||
|
||||
css_variables
|
||||
@@ -393,6 +419,10 @@ impl Baseline {
|
||||
if let Some(accent) = &self.accent {
|
||||
scss_variables.extend(accent.to_scss_variables(scheme_mode, "accent"));
|
||||
}
|
||||
scss_variables.extend(self.danger.to_scss_variables(scheme_mode, "danger"));
|
||||
scss_variables.extend(self.success.to_scss_variables(scheme_mode, "success"));
|
||||
scss_variables.extend(self.warn.to_scss_variables(scheme_mode, "warn"));
|
||||
scss_variables.extend(self.info.to_scss_variables(scheme_mode, "info"));
|
||||
|
||||
scss_variables.extend(self.neutral.to_scss_variables(scheme_mode, "neutral"));
|
||||
scss_variables.extend(
|
||||
@@ -405,23 +435,33 @@ impl Baseline {
|
||||
.to_scss_variables(scheme_mode, "surface-variant"),
|
||||
);
|
||||
|
||||
let neutral_swatch = generate_neutral_swatch_list(&self.neutral_swatch);
|
||||
for (n, c) in neutral_swatch {
|
||||
scss_variables.push(format!("$color-{scheme_mode}-swatch-neutral-{n}: #{c};"));
|
||||
}
|
||||
|
||||
scss_variables.push(format!(
|
||||
"--color-{scheme_mode}-shadow: #{};",
|
||||
"$color-{scheme_mode}-shadow: #{};",
|
||||
map_oklch_to_srgb_hex(&self.shadow)
|
||||
));
|
||||
scss_variables.push(format!(
|
||||
"--color-{scheme_mode}-overlay: #{};",
|
||||
"$color-{scheme_mode}-overlay: #{};",
|
||||
map_oklch_to_srgb_hex(&self.overlay)
|
||||
));
|
||||
scss_variables.push(format!(
|
||||
"--color-{scheme_mode}-outlint: #{};",
|
||||
"$color-{scheme_mode}-outlint: #{};",
|
||||
map_oklch_to_srgb_hex(&self.outline)
|
||||
));
|
||||
scss_variables.push(format!(
|
||||
"--color-{scheme_mode}-outline-variant: #{};",
|
||||
"$color-{scheme_mode}-outline-variant: #{};",
|
||||
map_oklch_to_srgb_hex(&self.outline_variant)
|
||||
));
|
||||
|
||||
for (name, color) in &self.custom_colors {
|
||||
let lowercased_name = name.to_lowercase();
|
||||
scss_variables.extend(color.to_scss_variables(scheme_mode, &lowercased_name));
|
||||
}
|
||||
|
||||
scss_variables
|
||||
}
|
||||
|
||||
@@ -463,6 +503,18 @@ impl Baseline {
|
||||
javascript_fields.push(format!("{indent}{line:4}"));
|
||||
}
|
||||
|
||||
for line in self.danger.to_javascript_fields("danger").iter() {
|
||||
javascript_fields.push(format!("{indent}{line:4}"));
|
||||
}
|
||||
for line in self.success.to_javascript_fields("success").iter() {
|
||||
javascript_fields.push(format!("{indent}{line:4}"));
|
||||
}
|
||||
for line in self.warn.to_javascript_fields("warn").iter() {
|
||||
javascript_fields.push(format!("{indent}{line:4}"));
|
||||
}
|
||||
for line in self.info.to_javascript_fields("info").iter() {
|
||||
javascript_fields.push(format!("{indent}{line:4}"));
|
||||
}
|
||||
for line in self.neutral.to_javascript_fields("neutral").iter() {
|
||||
javascript_fields.push(format!("{indent}{line:4}"));
|
||||
}
|
||||
@@ -484,6 +536,11 @@ impl Baseline {
|
||||
javascript_fields.push(format!("{indent}{line:4}"));
|
||||
}
|
||||
|
||||
let neurtal_swatch = generate_neutral_swatch_list(&self.neutral_swatch);
|
||||
for (n, c) in neurtal_swatch {
|
||||
javascript_fields.push(format!("{indent}neutralSwatch{n}: '#{c}',"));
|
||||
}
|
||||
|
||||
javascript_fields.push(format!(
|
||||
"{indent}shadow: '#{}',",
|
||||
map_oklch_to_srgb_hex(&self.shadow)
|
||||
@@ -502,7 +559,8 @@ impl Baseline {
|
||||
));
|
||||
|
||||
for (name, color) in &self.custom_colors {
|
||||
let color_lines = color.to_javascript_fields(name);
|
||||
let lowercased_name = name.to_lowercase();
|
||||
let color_lines = color.to_javascript_fields(&lowercased_name);
|
||||
javascript_fields.extend(color_lines.iter().map(|s| format!("{indent}{s}")));
|
||||
}
|
||||
|
||||
|
@@ -51,7 +51,7 @@ impl Swatch {
|
||||
let mut collection = LinkedHashMap::new();
|
||||
|
||||
for l in SWATCH_LIGHTINGS {
|
||||
collection.insert(format!("{name}-{l:02}"), self.get_hex(l));
|
||||
collection.insert(format!("swatch-{name}-{l:02}"), self.get_hex(l));
|
||||
}
|
||||
|
||||
collection
|
||||
@@ -98,6 +98,19 @@ impl Serialize for Swatch {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn generate_neutral_swatch_list(swatch: &Arc<NeutralSwatch>) -> LinkedHashMap<String, String> {
|
||||
let swatch = swatch.clone();
|
||||
let mut collection = LinkedHashMap::new();
|
||||
|
||||
for l in SWATCH_LIGHTINGS {
|
||||
let color = swatch.get((l as f32) / 100.0);
|
||||
let color = map_oklch_to_srgb_hex(&color);
|
||||
collection.insert(format!("{l:02}"), color);
|
||||
}
|
||||
|
||||
collection
|
||||
}
|
||||
|
||||
pub fn serialize_neutral_swatch<S>(
|
||||
swatch: &Arc<NeutralSwatch>,
|
||||
serailizer: S,
|
||||
|
@@ -203,7 +203,6 @@ export function Q2SchemeBuilder({ scheme, onBuildCompleted }: Q2SchemeBuilderPro
|
||||
|
||||
try {
|
||||
const [source, settings] = collectSchemeSource(formData);
|
||||
console.log('[Collected form data]', source, settings);
|
||||
const generatedScheme = colorFn?.generate_q_scheme_2_manually(
|
||||
source.primary ?? '',
|
||||
isEmpty(source.secondary) ? undefined : source.secondary,
|
||||
|
@@ -107,7 +107,7 @@ interface PreviewBlockProps {
|
||||
|
||||
const PreviewBlock: FC<PreviewBlockProps> = ({ baseline, title }) => {
|
||||
const customSets = useMemo(() => {
|
||||
const colors = keys(baseline.customColors);
|
||||
const colors = keys(baseline.customColors).sort();
|
||||
const elements: ReactNode[] = [];
|
||||
|
||||
for (const key of colors) {
|
||||
@@ -122,9 +122,9 @@ const PreviewBlock: FC<PreviewBlockProps> = ({ baseline, title }) => {
|
||||
<div className={styles.preview_block} style={{ backgroundColor: `#${baseline.surface.root}` }}>
|
||||
<h2 style={{ color: `#${baseline.surface.onRoot}` }}>{title}</h2>
|
||||
<PreviewSet name="Primary" colorUnit={baseline.primary} />
|
||||
<PreviewSet name="Secondary" colorUnit={baseline.secondary} />
|
||||
<PreviewSet name="Tertiary" colorUnit={baseline.tertiary} />
|
||||
<PreviewSet name="Accent" colorUnit={baseline.accent} />
|
||||
{baseline.secondary && <PreviewSet name="Secondary" colorUnit={baseline.secondary} />}
|
||||
{baseline.tertiary && <PreviewSet name="Tertiary" colorUnit={baseline.tertiary} />}
|
||||
{baseline.accent && <PreviewSet name="Accent" colorUnit={baseline.accent} />}
|
||||
<PreviewSet name="Danger" colorUnit={baseline.danger} />
|
||||
<PreviewSet name="Success" colorUnit={baseline.success} />
|
||||
<PreviewSet name="Warn" colorUnit={baseline.warn} />
|
||||
@@ -134,10 +134,10 @@ const PreviewBlock: FC<PreviewBlockProps> = ({ baseline, title }) => {
|
||||
<PreviewLine name="Surface" unit={baseline.surface} />
|
||||
<PreviewLine name="Surface Variant" unit={baseline.surfaceVariant} />
|
||||
<div className={styles.preview_indi_block}>
|
||||
<PreviewCell bg={baseline.shadow} fg={baseline.surface.onRoot}>
|
||||
<PreviewCell bg={baseline.shadow} fg={baseline.neutralVariant.onRoot}>
|
||||
Shadow
|
||||
</PreviewCell>
|
||||
<PreviewCell bg={baseline.overlay} fg={baseline.surface.onRoot}>
|
||||
<PreviewCell bg={baseline.overlay} fg={baseline.neutralVariant.onRoot}>
|
||||
Overlay
|
||||
</PreviewCell>
|
||||
<PreviewCell bg={baseline.outline} fg={baseline.surface.onRoot}>
|
||||
|
Reference in New Issue
Block a user