Skip to content

Commit

Permalink
Add support for container queries
Browse files Browse the repository at this point in the history
  • Loading branch information
notriddle committed Oct 13, 2023
1 parent 7a0211f commit 143bb88
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/css/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,13 @@ fn check_calc() {
assert_eq!(minify(s).expect("minify failed").to_string(), expected);
}

#[test]
fn check_container() {
let s = "@container rustdoc (min-width: 1250px) { .foo { width: 100px; } }";
let expected = "@container rustdoc (min-width:1250px){.foo{width:100px;}}";
assert_eq!(minify(s).expect("minify failed").to_string(), expected);
}

#[test]
fn check_spaces() {
let s = ".line-numbers .line-highlighted { color: #0a042f !important; }";
Expand Down
6 changes: 6 additions & 0 deletions src/css/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,7 @@ fn clean_tokens(mut v: Vec<Token<'_>>) -> Vec<Token<'_>> {
// Index of the previous retained token, if there is one.
let mut ip: Option<usize> = None;
let mut is_in_calc = false;
let mut is_in_container = false;
let mut paren = 0;
// A vector of bools indicating which elements are to be retained.
let mut b = Vec::with_capacity(v.len());
Expand All @@ -594,6 +595,9 @@ fn clean_tokens(mut v: Vec<Token<'_>>) -> Vec<Token<'_>> {
paren += 1;
}
}
if v[i] == Token::SelectorElement(SelectorElement::Media("container")) {
is_in_container = true;
}

let mut retain = true;
if v[i].is_useless() {
Expand All @@ -609,6 +613,8 @@ fn clean_tokens(mut v: Vec<Token<'_>>) -> Vec<Token<'_>> {
// retain the space after "and", "or" or "not"
} else if is_in_calc && v[ip.unwrap()].is_useless() {
retain = false;
} else if is_in_container && matches!(v[ip.unwrap()], Token::Other(_)) {
// retain spaces between keywords in container queryes
} else if !is_in_calc
&& ((ip.is_some() && {
let prev = &v[ip.unwrap()];
Expand Down

0 comments on commit 143bb88

Please sign in to comment.