@@ -128,10 +128,7 @@ where
128128#[ serde( tag = "type" , rename_all = "kebab-case" ) ]
129129#[ cfg_attr( feature = "jsonschema" , derive( schemars:: JsonSchema ) ) ]
130130enum 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