Skip to content

Commit 9122ab3

Browse files
committed
Support variable on typography
1 parent 0c85499 commit 9122ab3

File tree

4 files changed

+129
-56
lines changed

4 files changed

+129
-56
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"changes":{"bindings/devup-ui-wasm/package.json":"Patch"},"note":"Support variable on typography","date":"2026-04-07T04:23:57.883285900Z"}

Cargo.lock

Lines changed: 42 additions & 42 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

libs/extractor/Cargo.toml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ version = "0.1.0"
44
edition = "2024"
55

66
[dependencies]
7-
oxc_parser = "0.123.0"
8-
oxc_syntax = "0.123.0"
9-
oxc_span = "0.123.0"
10-
oxc_allocator = "0.123.0"
11-
oxc_ast = "0.123.0"
12-
oxc_ast_visit = "0.123.0"
13-
oxc_codegen = "0.123.0"
14-
oxc_transformer = "0.123.0"
15-
oxc_semantic = "0.123.0"
7+
oxc_parser = "0.124.0"
8+
oxc_syntax = "0.124.0"
9+
oxc_span = "0.124.0"
10+
oxc_allocator = "0.124.0"
11+
oxc_ast = "0.124.0"
12+
oxc_ast_visit = "0.124.0"
13+
oxc_codegen = "0.124.0"
14+
oxc_transformer = "0.124.0"
15+
oxc_semantic = "0.124.0"
1616
css = { path = "../css" }
1717
phf = "0.13"
1818
strum = "0.28.0"

libs/sheet/src/theme.rs

Lines changed: 77 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -675,26 +675,33 @@ impl Theme {
675675
for ty in self.typography.iter() {
676676
for (idx, t) in ty.1.0.iter().enumerate() {
677677
if let Some(t) = t {
678+
let resolve = |v: &str| -> String {
679+
if let Some(token) = v.strip_prefix('$') {
680+
format!("var(--{})", token)
681+
} else {
682+
optimize_value(v)
683+
}
684+
};
678685
let css_content = [
679686
t.font_family
680687
.as_ref()
681-
.map(|v| format!("font-family:{}", optimize_value(v)))
688+
.map(|v| format!("font-family:{}", resolve(v)))
682689
.unwrap_or_default(),
683690
t.font_size
684691
.as_ref()
685-
.map(|v| format!("font-size:{}", optimize_value(v)))
692+
.map(|v| format!("font-size:{}", resolve(v)))
686693
.unwrap_or_default(),
687694
t.font_weight
688695
.as_ref()
689-
.map(|v| format!("font-weight:{}", optimize_value(v)))
696+
.map(|v| format!("font-weight:{}", resolve(v)))
690697
.unwrap_or_default(),
691698
t.line_height
692699
.as_ref()
693-
.map(|v| format!("line-height:{}", optimize_value(v)))
700+
.map(|v| format!("line-height:{}", resolve(v)))
694701
.unwrap_or_default(),
695702
t.letter_spacing
696703
.as_ref()
697-
.map(|v| format!("letter-spacing:{}", optimize_value(v)))
704+
.map(|v| format!("letter-spacing:{}", resolve(v)))
698705
.unwrap_or_default(),
699706
]
700707
.iter()
@@ -1380,6 +1387,71 @@ mod tests {
13801387
assert!(err.contains("cannot start with an array"));
13811388
}
13821389

1390+
#[test]
1391+
fn test_typography_variable_reference() {
1392+
let theme: Theme = serde_json::from_str(
1393+
r##"{
1394+
"typography": {
1395+
"body": {
1396+
"fontSize": "$text",
1397+
"lineHeight": "$leading",
1398+
"fontWeight": 400
1399+
}
1400+
}
1401+
}"##,
1402+
)
1403+
.unwrap();
1404+
1405+
let css = theme.to_css();
1406+
assert!(
1407+
css.contains("font-size:var(--text)"),
1408+
"Expected font-size:var(--text), got: {}",
1409+
css
1410+
);
1411+
assert!(
1412+
css.contains("line-height:var(--leading)"),
1413+
"Expected line-height:var(--leading), got: {}",
1414+
css
1415+
);
1416+
assert!(css.contains("font-weight:400"));
1417+
}
1418+
1419+
#[test]
1420+
fn test_typography_variable_reference_responsive() {
1421+
let theme: Theme = serde_json::from_str(
1422+
r##"{
1423+
"typography": {
1424+
"heading": [
1425+
{
1426+
"fontSize": "$textSm",
1427+
"fontWeight": 700
1428+
},
1429+
null,
1430+
null,
1431+
null,
1432+
{
1433+
"fontSize": "$textLg",
1434+
"fontWeight": 700
1435+
}
1436+
]
1437+
}
1438+
}"##,
1439+
)
1440+
.unwrap();
1441+
1442+
let css = theme.to_css();
1443+
assert!(
1444+
css.contains("font-size:var(--textSm)"),
1445+
"Expected font-size:var(--textSm), got: {}",
1446+
css
1447+
);
1448+
assert!(
1449+
css.contains("font-size:var(--textLg)"),
1450+
"Expected font-size:var(--textLg), got: {}",
1451+
css
1452+
);
1453+
}
1454+
13831455
#[test]
13841456
fn test_mixed_typography_formats() {
13851457
// Test that both formats can coexist in the same theme

0 commit comments

Comments
 (0)