Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changepacks/changepack_log_PpYddWjTwrwPJmblUAlm_.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"changes": { "bindings/devup-ui-wasm/package.json": "Patch" },
"note": "Optimize theme interface support deep colors",
"date": "2025-12-26T12:30:04.669317200Z"
}
159 changes: 25 additions & 134 deletions bindings/devup-ui-wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,6 @@ pub fn get_theme_interface(
}
#[cfg(test)]
mod tests {
use std::collections::HashMap;

use super::*;
use insta::assert_debug_snapshot;
use rstest::rstest;
Expand Down Expand Up @@ -341,7 +339,7 @@ mod tests {
let mut color_theme = ColorTheme::default();
color_theme.add_color("primary", "#000");

assert_eq!(color_theme.0.keys().count(), 1);
assert_eq!(color_theme.css_keys().count(), 1);

theme.add_color_theme("default", color_theme);
let mut color_theme = ColorTheme::default();
Expand Down Expand Up @@ -391,151 +389,44 @@ mod tests {
);
assert_eq!(theme.to_css(), "");

let mut theme = Theme::default();
theme.add_color_theme(
"default",
ColorTheme({
let mut map = HashMap::new();
map.insert("primary".to_string(), "#000".to_string());
map
}),
);
// Helper to create a ColorTheme with a single color
fn make_color_theme(name: &str, value: &str) -> ColorTheme {
let mut ct = ColorTheme::default();
ct.add_color(name, value);
ct
}

theme.add_color_theme(
"dark",
ColorTheme({
let mut map = HashMap::new();
map.insert("primary".to_string(), "#000".to_string());
map
}),
);
let mut theme = Theme::default();
theme.add_color_theme("default", make_color_theme("primary", "#000"));
theme.add_color_theme("dark", make_color_theme("primary", "#000"));
assert_debug_snapshot!(theme.to_css());

let mut theme = Theme::default();
theme.add_color_theme(
"light",
ColorTheme({
let mut map = HashMap::new();
map.insert("primary".to_string(), "#000".to_string());
map
}),
);

theme.add_color_theme(
"dark",
ColorTheme({
let mut map = HashMap::new();
map.insert("primary".to_string(), "#000".to_string());
map
}),
);
theme.add_color_theme("light", make_color_theme("primary", "#000"));
theme.add_color_theme("dark", make_color_theme("primary", "#000"));
assert_debug_snapshot!(theme.to_css());

let mut theme = Theme::default();
theme.add_color_theme(
"a",
ColorTheme({
let mut map = HashMap::new();
map.insert("primary".to_string(), "#000".to_string());
map
}),
);

theme.add_color_theme(
"b",
ColorTheme({
let mut map = HashMap::new();
map.insert("primary".to_string(), "#000".to_string());
map
}),
);
theme.add_color_theme("a", make_color_theme("primary", "#000"));
theme.add_color_theme("b", make_color_theme("primary", "#000"));
assert_debug_snapshot!(theme.to_css());

let mut theme = Theme::default();
theme.add_color_theme(
"light",
ColorTheme({
let mut map = HashMap::new();
map.insert("primary".to_string(), "#000".to_string());
map
}),
);

theme.add_color_theme(
"b",
ColorTheme({
let mut map = HashMap::new();
map.insert("primary".to_string(), "#000".to_string());
map
}),
);

theme.add_color_theme(
"a",
ColorTheme({
let mut map = HashMap::new();
map.insert("primary".to_string(), "#000".to_string());
map
}),
);

theme.add_color_theme(
"c",
ColorTheme({
let mut map = HashMap::new();
map.insert("primary".to_string(), "#000".to_string());
map
}),
);
theme.add_color_theme("light", make_color_theme("primary", "#000"));
theme.add_color_theme("b", make_color_theme("primary", "#000"));
theme.add_color_theme("a", make_color_theme("primary", "#000"));
theme.add_color_theme("c", make_color_theme("primary", "#000"));
assert_debug_snapshot!(theme.to_css());

let mut theme = Theme::default();
theme.add_color_theme(
"light",
ColorTheme({
let mut map = HashMap::new();
map.insert("primary".to_string(), "#000".to_string());
map
}),
);
theme.add_color_theme("light", make_color_theme("primary", "#000"));
assert_debug_snapshot!(theme.to_css());

let mut theme = Theme::default();
theme.add_color_theme(
"light",
ColorTheme({
let mut map = HashMap::new();
map.insert("primary".to_string(), "#000".to_string());
map
}),
);

theme.add_color_theme(
"b",
ColorTheme({
let mut map = HashMap::new();
map.insert("primary".to_string(), "#001".to_string());
map
}),
);

theme.add_color_theme(
"a",
ColorTheme({
let mut map = HashMap::new();
map.insert("primary".to_string(), "#002".to_string());
map
}),
);

theme.add_color_theme(
"c",
ColorTheme({
let mut map = HashMap::new();
map.insert("primary".to_string(), "#000".to_string());
map
}),
);
theme.add_color_theme("light", make_color_theme("primary", "#000"));
theme.add_color_theme("b", make_color_theme("primary", "#001"));
theme.add_color_theme("a", make_color_theme("primary", "#002"));
theme.add_color_theme("c", make_color_theme("primary", "#000"));
assert_debug_snapshot!(theme.to_css());
}

Expand Down Expand Up @@ -584,7 +475,7 @@ mod tests {
"TypographyInterface",
"ThemeInterface"
),
"import \"package\";declare module \"package\"{interface ColorInterface{$primary:null;}interface TypographyInterface{}interface ThemeInterface{dark:null;}}"
"import \"package\";declare module \"package\"{interface ColorInterface{$primary:null}interface TypographyInterface{}interface ThemeInterface{dark:null}}"
);

// test wrong case
Expand Down Expand Up @@ -612,7 +503,7 @@ mod tests {
"TypographyInterface",
"ThemeInterface"
),
"import \"package\";declare module \"package\"{interface ColorInterface{[`$(primary)`]:null;}interface TypographyInterface{[`prim\\`\\`ary`]:null;}interface ThemeInterface{dark:null;}}"
"import \"package\";declare module \"package\"{interface ColorInterface{[`$(primary)`]:null}interface TypographyInterface{[`prim\\`\\`ary`]:null}interface ThemeInterface{dark:null}}"
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,24 @@ expression: theme
---
Theme {
colors: {
"dark": ColorTheme(
{
"primary": "#fff",
"dark": ColorTheme {
entries: {
"primary": ColorEntry {
interface_key: "primary",
css_key: "primary",
value: "#fff",
},
},
),
"default": ColorTheme(
{
"primary": "#000",
},
"default": ColorTheme {
entries: {
"primary": ColorEntry {
interface_key: "primary",
css_key: "primary",
value: "#000",
},
},
),
},
},
breakpoints: [
0,
Expand Down
2 changes: 1 addition & 1 deletion libs/sheet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ edition = "2024"
[dependencies]
css = { path = "../css" }
serde = { version = "1.0.228", features = ["derive"] }
serde_json = "1.0.146"
regex = "1.12.2"
once_cell = "1.21.3"
extractor = { path = "../extractor" }

[dev-dependencies]
insta = "1.45.0"
serde_json = "1.0.146"
criterion = { version = "0.8", features = ["html_reports"] }
rstest = "0.26.1"

Expand Down
Loading