Skip to content

Commit 5503ecd

Browse files
committed
cargo fmt
1 parent 6b5ac8b commit 5503ecd

File tree

6 files changed

+80
-66
lines changed

6 files changed

+80
-66
lines changed

src/context.rs

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ use std::collections::HashSet;
22

33
use crate::compat::Feature;
44
use crate::declaration::DeclarationBlock;
5-
use crate::media_query::{MediaCondition, MediaFeatureId, MediaFeatureName, MediaFeatureValue, MediaList, MediaQuery, MediaType, QueryFeature};
5+
use crate::media_query::{
6+
MediaCondition, MediaFeatureId, MediaFeatureName, MediaFeatureValue, MediaList, MediaQuery, MediaType,
7+
QueryFeature,
8+
};
69
use crate::properties::custom::UnparsedProperty;
710
use crate::properties::Property;
811
use crate::rules::media::MediaRule;
@@ -126,31 +129,25 @@ impl<'i, 'o> PropertyHandlerContext<'i, 'o> {
126129
if !self.dark.is_empty() {
127130
dest.push(CssRule::Media(MediaRule {
128131
query: MediaList {
129-
media_queries: vec![
130-
MediaQuery {
131-
qualifier: None,
132-
media_type: MediaType::All,
133-
condition: Some(MediaCondition::Feature(
134-
QueryFeature::Plain {
135-
name: MediaFeatureName::Standard(MediaFeatureId::PrefersColorScheme),
136-
value: MediaFeatureValue::Ident(Ident("dark".into()))
137-
}
138-
))
139-
}
140-
],
132+
media_queries: vec![MediaQuery {
133+
qualifier: None,
134+
media_type: MediaType::All,
135+
condition: Some(MediaCondition::Feature(QueryFeature::Plain {
136+
name: MediaFeatureName::Standard(MediaFeatureId::PrefersColorScheme),
137+
value: MediaFeatureValue::Ident(Ident("dark".into())),
138+
})),
139+
}],
141140
},
142-
rules: CssRuleList(vec![
143-
CssRule::Style(StyleRule {
144-
selectors: style_rule.selectors.clone(),
145-
vendor_prefix: VendorPrefix::None,
146-
declarations: DeclarationBlock {
147-
declarations: self.dark.clone(),
148-
important_declarations: vec![],
149-
},
150-
rules: CssRuleList(vec![]),
151-
loc: style_rule.loc.clone(),
152-
})
153-
]),
141+
rules: CssRuleList(vec![CssRule::Style(StyleRule {
142+
selectors: style_rule.selectors.clone(),
143+
vendor_prefix: VendorPrefix::None,
144+
declarations: DeclarationBlock {
145+
declarations: self.dark.clone(),
146+
important_declarations: vec![],
147+
},
148+
rules: CssRuleList(vec![]),
149+
loc: style_rule.loc.clone(),
150+
})]),
154151
loc: style_rule.loc.clone(),
155152
}))
156153
}

src/error.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
33
use crate::properties::custom::Token;
44
use crate::rules::Location;
5-
#[cfg(feature = "into_owned")]
6-
use static_self::IntoOwned;
75
use crate::values::string::CowArcStr;
86
use cssparser::{BasicParseErrorKind, ParseError, ParseErrorKind};
97
use parcel_selectors::parser::SelectorParseErrorKind;
108
#[cfg(any(feature = "serde", feature = "nodejs"))]
119
use serde::Serialize;
10+
#[cfg(feature = "into_owned")]
11+
use static_self::IntoOwned;
1212
use std::fmt;
1313

1414
/// An error with a source location.

src/lib.rs

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26944,9 +26944,15 @@ mod tests {
2694426944
minify_test(".foo { color-scheme: dark light; }", ".foo{color-scheme:light dark}");
2694526945
minify_test(".foo { color-scheme: only light; }", ".foo{color-scheme:light only}");
2694626946
minify_test(".foo { color-scheme: only dark; }", ".foo{color-scheme:dark only}");
26947-
minify_test(".foo { color-scheme: dark light only; }", ".foo{color-scheme:light dark only}");
26947+
minify_test(
26948+
".foo { color-scheme: dark light only; }",
26949+
".foo{color-scheme:light dark only}",
26950+
);
2694826951
minify_test(".foo { color-scheme: foo bar light; }", ".foo{color-scheme:light}");
26949-
minify_test(".foo { color-scheme: only foo dark bar; }", ".foo{color-scheme:dark only}");
26952+
minify_test(
26953+
".foo { color-scheme: only foo dark bar; }",
26954+
".foo{color-scheme:dark only}",
26955+
);
2695026956
prefix_test(
2695126957
".foo { color-scheme: dark; }",
2695226958
indoc! { r#"
@@ -26959,7 +26965,7 @@ mod tests {
2695926965
Browsers {
2696026966
chrome: Some(90 << 16),
2696126967
..Browsers::default()
26962-
}
26968+
},
2696326969
);
2696426970
prefix_test(
2696526971
".foo { color-scheme: light; }",
@@ -26973,7 +26979,7 @@ mod tests {
2697326979
Browsers {
2697426980
chrome: Some(90 << 16),
2697526981
..Browsers::default()
26976-
}
26982+
},
2697726983
);
2697826984
prefix_test(
2697926985
".foo { color-scheme: light dark; }",
@@ -26994,7 +27000,7 @@ mod tests {
2699427000
Browsers {
2699527001
chrome: Some(90 << 16),
2699627002
..Browsers::default()
26997-
}
27003+
},
2699827004
);
2699927005
prefix_test(
2700027006
".foo { color-scheme: light dark; }",
@@ -27006,11 +27012,17 @@ mod tests {
2700627012
Browsers {
2700727013
firefox: Some(120 << 16),
2700827014
..Browsers::default()
27009-
}
27015+
},
2701027016
);
2701127017

27012-
minify_test(".foo { color: light-dark(yellow, red); }", ".foo{color:light-dark(#ff0,red)}");
27013-
minify_test(".foo { color: light-dark(rgb(0, 0, 255), hsl(120deg, 50%, 50%)); }", ".foo{color:light-dark(#00f,#40bf40)}");
27018+
minify_test(
27019+
".foo { color: light-dark(yellow, red); }",
27020+
".foo{color:light-dark(#ff0,red)}",
27021+
);
27022+
minify_test(
27023+
".foo { color: light-dark(rgb(0, 0, 255), hsl(120deg, 50%, 50%)); }",
27024+
".foo{color:light-dark(#00f,#40bf40)}",
27025+
);
2701427026
prefix_test(
2701527027
".foo { color: light-dark(oklch(40% 0.1268735435 34.568626), oklab(59.686% 0.1009 0.1192)); }",
2701627028
indoc! { r#"
@@ -27022,7 +27034,7 @@ mod tests {
2702227034
Browsers {
2702327035
chrome: Some(90 << 16),
2702427036
..Browsers::default()
27025-
}
27037+
},
2702627038
);
2702727039
prefix_test(
2702827040
".foo { color: light-dark(oklch(40% 0.1268735435 34.568626), oklab(59.686% 0.1009 0.1192)); }",
@@ -27034,7 +27046,7 @@ mod tests {
2703427046
Browsers {
2703527047
firefox: Some(120 << 16),
2703627048
..Browsers::default()
27037-
}
27049+
},
2703827050
);
2703927051
prefix_test(
2704027052
".foo { color: light-dark(var(--light), var(--dark)); }",
@@ -27046,7 +27058,7 @@ mod tests {
2704627058
Browsers {
2704727059
chrome: Some(90 << 16),
2704827060
..Browsers::default()
27049-
}
27061+
},
2705027062
);
2705127063
}
2705227064
}

src/properties/custom.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1525,7 +1525,7 @@ pub enum UnresolvedColor<'i> {
15251525
light: TokenList<'i>,
15261526
/// The dark value.
15271527
dark: TokenList<'i>,
1528-
}
1528+
},
15291529
}
15301530

15311531
impl<'i> UnresolvedColor<'i> {
@@ -1640,7 +1640,7 @@ impl<'i> UnresolvedColor<'i> {
16401640
dest.write_str("var(--lightningcss-dark")?;
16411641
dest.delim(',', false)?;
16421642
dark.to_css(dest, is_custom_property)?;
1643-
return dest.write_char(')')
1643+
return dest.write_char(')');
16441644
}
16451645

16461646
dest.write_str("light-dark(")?;

src/properties/ui.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ use crate::values::string::CowArcStr;
1515
use crate::values::url::Url;
1616
#[cfg(feature = "visitor")]
1717
use crate::visitor::Visit;
18+
use bitflags::bitflags;
1819
use cssparser::*;
1920
use smallvec::SmallVec;
20-
use bitflags::bitflags;
2121

2222
use super::custom::Token;
2323
use super::{CustomProperty, CustomPropertyName, TokenList, TokenOrValue};
@@ -489,10 +489,11 @@ impl<'i> Parse<'i> for ColorScheme {
489489

490490
impl ToCss for ColorScheme {
491491
fn to_css<W>(&self, dest: &mut Printer<W>) -> Result<(), PrinterError>
492-
where
493-
W: std::fmt::Write {
492+
where
493+
W: std::fmt::Write,
494+
{
494495
if self.is_empty() {
495-
return dest.write_str("normal")
496+
return dest.write_str("normal");
496497
}
497498

498499
if self.contains(ColorScheme::Light) {
@@ -587,7 +588,7 @@ impl<'i> PropertyHandler<'i> for ColorSchemeHandler {
587588
dest.push(property.clone());
588589
true
589590
}
590-
_ => false
591+
_ => false,
591592
}
592593
}
593594

@@ -598,8 +599,6 @@ impl<'i> PropertyHandler<'i> for ColorSchemeHandler {
598599
fn define_var<'i>(name: &'static str, value: Token<'static>) -> Property<'i> {
599600
Property::Custom(CustomProperty {
600601
name: CustomPropertyName::Custom(name.into()),
601-
value: TokenList(vec![
602-
TokenOrValue::Token(value)
603-
])
602+
value: TokenList(vec![TokenOrValue::Token(value)]),
604603
})
605604
}

src/values/color.rs

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,7 @@ where
128128
#[serde(tag = "type", rename_all = "kebab-case")]
129129
#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))]
130130
enum LightDark {
131-
LightDark {
132-
light: CssColor,
133-
dark: CssColor
134-
},
131+
LightDark { light: CssColor, dark: CssColor },
135132
}
136133

137134
#[cfg(feature = "serde")]
@@ -142,7 +139,7 @@ impl<'de> LightDark {
142139
{
143140
let wrapper = LightDark::LightDark {
144141
light: (**light).clone(),
145-
dark: (**dark).clone()
142+
dark: (**dark).clone(),
146143
};
147144
serde::Serialize::serialize(&wrapper, serializer)
148145
}
@@ -153,9 +150,7 @@ impl<'de> LightDark {
153150
{
154151
let v: LightDark = serde::Deserialize::deserialize(deserializer)?;
155152
match v {
156-
LightDark::LightDark { light, dark } => {
157-
Ok((Box::new(light), Box::new(dark)))
158-
}
153+
LightDark::LightDark { light, dark } => Ok((Box::new(light), Box::new(dark))),
159154
}
160155
}
161156
}
@@ -334,24 +329,30 @@ impl CssColor {
334329
/// Converts the color to RGBA.
335330
pub fn to_rgb(&self) -> Result<CssColor, ()> {
336331
match self {
337-
CssColor::LightDark(light, dark) => Ok(CssColor::LightDark(Box::new(light.to_rgb()?), Box::new(dark.to_rgb()?))),
338-
_ => Ok(RGBA::try_from(self)?.into())
332+
CssColor::LightDark(light, dark) => {
333+
Ok(CssColor::LightDark(Box::new(light.to_rgb()?), Box::new(dark.to_rgb()?)))
334+
}
335+
_ => Ok(RGBA::try_from(self)?.into()),
339336
}
340337
}
341338

342339
/// Converts the color to the LAB color space.
343340
pub fn to_lab(&self) -> Result<CssColor, ()> {
344341
match self {
345-
CssColor::LightDark(light, dark) => Ok(CssColor::LightDark(Box::new(light.to_lab()?), Box::new(dark.to_lab()?))),
346-
_ => Ok(LAB::try_from(self)?.into())
342+
CssColor::LightDark(light, dark) => {
343+
Ok(CssColor::LightDark(Box::new(light.to_lab()?), Box::new(dark.to_lab()?)))
344+
}
345+
_ => Ok(LAB::try_from(self)?.into()),
347346
}
348347
}
349348

350349
/// Converts the color to the P3 color space.
351350
pub fn to_p3(&self) -> Result<CssColor, ()> {
352351
match self {
353-
CssColor::LightDark(light, dark) => Ok(CssColor::LightDark(Box::new(light.to_p3()?), Box::new(dark.to_p3()?))),
354-
_ => Ok(P3::try_from(self)?.into())
352+
CssColor::LightDark(light, dark) => {
353+
Ok(CssColor::LightDark(Box::new(light.to_p3()?), Box::new(dark.to_p3()?)))
354+
}
355+
_ => Ok(P3::try_from(self)?.into()),
355356
}
356357
}
357358

@@ -593,7 +594,7 @@ impl ToCss for CssColor {
593594
dest.write_str("var(--lightningcss-dark")?;
594595
dest.delim(',', false)?;
595596
dark.to_css(dest)?;
596-
return dest.write_char(')')
597+
return dest.write_char(')');
597598
}
598599

599600
dest.write_str("light-dark(")?;
@@ -3157,7 +3158,7 @@ impl CssColor {
31573158
fn to_light_dark(&self) -> CssColor {
31583159
match self {
31593160
CssColor::LightDark(..) => self.clone(),
3160-
_ => CssColor::LightDark(Box::new(self.clone()), Box::new(self.clone()))
3161+
_ => CssColor::LightDark(Box::new(self.clone()), Box::new(self.clone())),
31613162
}
31623163
}
31633164

@@ -3186,8 +3187,13 @@ impl CssColor {
31863187
}
31873188

31883189
if matches!(self, CssColor::LightDark(..)) || matches!(other, CssColor::LightDark(..)) {
3189-
if let (CssColor::LightDark(al, ad), CssColor::LightDark(bl, bd)) = (self.to_light_dark(), other.to_light_dark()) {
3190-
return Ok(CssColor::LightDark(Box::new(al.interpolate::<T>(p1, &bl, p2, method)?), Box::new(ad.interpolate::<T>(p1, &bd, p2, method)?)))
3190+
if let (CssColor::LightDark(al, ad), CssColor::LightDark(bl, bd)) =
3191+
(self.to_light_dark(), other.to_light_dark())
3192+
{
3193+
return Ok(CssColor::LightDark(
3194+
Box::new(al.interpolate::<T>(p1, &bl, p2, method)?),
3195+
Box::new(ad.interpolate::<T>(p1, &bd, p2, method)?),
3196+
));
31913197
}
31923198
}
31933199

0 commit comments

Comments
 (0)