mirror of
https://github.com/storytold/figcraft.git
synced 2026-11-17 15:47:34 +00:00
#1011: single-call Tailwind variables, rem only where it converts
This commit is contained in:
1 parent
9361b230b5
commit
647e5f17d9
3 files changed
+24
-3
No files matched your search
@@ -99,9 +99,10 @@ impl CodeLang {
|
||||
CodeLang::Compose => "Compose",
|
||||
}
|
||||
}
|
||||
/// Languages whose lengths are CSS pixels (they can be shown in rem).
|
||||
/// Languages whose lengths are CSS pixels that can be shown in rem (not Tailwind: its lengths
|
||||
/// are utility classes).
|
||||
pub fn is_web(self) -> bool {
|
||||
matches!(self, CodeLang::Css | CodeLang::Html | CodeLang::React | CodeLang::Leptos | CodeLang::Tailwind)
|
||||
matches!(self, CodeLang::Css | CodeLang::Html | CodeLang::React | CodeLang::Leptos)
|
||||
}
|
||||
pub fn from_id(s: &str) -> Option<CodeLang> {
|
||||
if s.eq_ignore_ascii_case("tsx") || s.eq_ignore_ascii_case("jsx") {
|
||||
|
||||
@@ -105,9 +105,22 @@ fn arb(v: &str) -> String {
|
||||
format!("[{}]", v.trim().replace('_', "\\_").replace(' ', "_"))
|
||||
}
|
||||
|
||||
/// The custom property a `var(--name, fallback)` value reads.
|
||||
/// The custom property a `var(--name, fallback)` value reads, when that one call is the whole
|
||||
/// value (not `var(--a, 4px) 8px`, four corners of which only the first is a variable).
|
||||
fn var_name(v: &str) -> Option<&str> {
|
||||
let inner = v.trim().strip_prefix("var(")?;
|
||||
let mut depth = 1usize;
|
||||
let close = inner.char_indices().find_map(|(i, c)| {
|
||||
match c {
|
||||
'(' => depth += 1,
|
||||
')' => depth -= 1,
|
||||
_ => {}
|
||||
}
|
||||
(depth == 0).then_some(i)
|
||||
})?;
|
||||
if close + 1 != inner.len() {
|
||||
return None;
|
||||
}
|
||||
Some(inner.split([',', ')']).next()?.trim())
|
||||
}
|
||||
|
||||
|
||||
@@ -333,3 +333,10 @@ fn review_desktop_without_fill_clears_a_mobile_image_or_gradient() {
|
||||
let got = merge(Some(&[("background".to_string(), "[background:url(image.png)_center_/_cover]".to_string())]), &[]);
|
||||
assert!(got.contains(&"lg:bg-none".to_string()) && got.contains(&"lg:bg-transparent".to_string()), "{got:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn per_corner_radii_with_a_variable_first_keep_every_corner() {
|
||||
let got: Vec<String> =
|
||||
classes("border-radius: var(--radius-a, 4px) 8px 8px 8px;\nborder-radius: var(--radius-card, 4px);\n").into_iter().map(|(_, c)| c).collect();
|
||||
assert_eq!(got, ["rounded-[var(--radius-a,_4px)_8px_8px_8px]", "rounded-card"]);
|
||||
}
|
||||
Reference in new issue
Block a user