@@ -2,13 +2,13 @@ use std::{cell::RefCell, collections::HashMap, convert::Infallible, hash::Hash,
22
33use lightningcss:: {
44 declaration:: DeclarationBlock ,
5- properties:: Property ,
5+ properties:: { Property , border :: { LineStyle , BorderSideWidth } } ,
66 rules:: CssRule ,
77 stylesheet:: { ParserOptions , PrinterOptions , StyleSheet } ,
88 targets:: { Features , Targets } ,
99 traits:: ToCss ,
1010 visit_types,
11- visitor:: { Visit , VisitTypes , Visitor } ,
11+ visitor:: { Visit , VisitTypes , Visitor } , values :: color :: CssColor ,
1212} ;
1313
1414use crate :: {
@@ -31,8 +31,7 @@ use crate::{
3131 } ,
3232 margin_padding:: MarginPadding ,
3333 style_value_type:: StyleValueType ,
34- text_decoration:: TextDecoration ,
35- transform:: transform:: Transform , constraint_size:: ConstraintSize , border:: { border_width:: BorderWidth , border_color:: BorderColor , border_radius:: BorderRadius , border_style:: BorderStyle } , text:: { line_height:: LineHeight , letter_spacing:: LetterSpacing , text_align:: TextAlign , text_overflow:: TextOverflow , font_weight:: FontWeight } ,
34+ transform:: transform:: Transform , constraint_size:: ConstraintSize , border:: { border_width:: { BorderWidth , parse_border_width_item} , border_color:: { BorderColor , parse_border_color_item} , border_radius:: BorderRadius , border_style:: { BorderStyle , parse_border_style_item} , border:: Border } , text:: { line_height:: LineHeight , letter_spacing:: LetterSpacing , text_align:: TextAlign , text_overflow:: TextOverflow , font_weight:: FontWeight , font_style:: FontStyle , text_decoration:: { TextDecoration } } ,
3635 } ,
3736 utils:: {
3837 to_camel_case,
@@ -106,8 +105,6 @@ impl<'i> Visitor<'i> for StyleVisitor<'i> {
106105pub fn parse_style_properties ( properties : & Vec < ( String , Property < ' _ > ) > ) -> StyleValue {
107106 let mut final_properties = HashMap :: new ( ) ;
108107
109- let mut text_decoration = None ;
110- let mut color = None ;
111108 let mut flex_options = FlexOptions :: new ( ) ;
112109 let mut constrant_size = ConstraintSize :: new ( ) ;
113110
@@ -159,7 +156,116 @@ pub fn parse_style_properties(properties: &Vec<(String, Property<'_>)>) -> Style
159156 _ => { }
160157 }
161158 }
162- }
159+ } ,
160+ "border" => {
161+ let border = Border :: from ( value) ;
162+ let border_width = final_properties
163+ . entry ( prefix_style_key ( "borderWidth" ) )
164+ . or_insert ( StyleValueType :: BorderWidth ( BorderWidth :: new ( ) ) ) ;
165+ if let StyleValueType :: BorderWidth ( border_width) = border_width {
166+ if let Some ( width) = border. width . top {
167+ border_width. set_all ( width. as_str ( ) ) ;
168+ }
169+ }
170+ let border_color = final_properties
171+ . entry ( prefix_style_key ( "borderColor" ) )
172+ . or_insert ( StyleValueType :: BorderColor ( BorderColor :: new ( ) ) ) ;
173+ if let StyleValueType :: BorderColor ( border_color) = border_color {
174+ if let Some ( color) = border. color . top {
175+ border_color. set_all ( color. as_str ( ) ) ;
176+ }
177+ }
178+ let border_style = final_properties
179+ . entry ( prefix_style_key ( "borderStyle" ) )
180+ . or_insert ( StyleValueType :: BorderStyle ( BorderStyle :: new ( ) ) ) ;
181+ if let StyleValueType :: BorderStyle ( border_style) = border_style {
182+ if let Some ( style) = border. style . top {
183+ border_style. set_all ( style. as_str ( ) ) ;
184+ }
185+ }
186+ } ,
187+ "borderLeft" | "borderRight" | "borderTop" | "borderBottom" => {
188+ let mut width: Option < BorderSideWidth > = None ;
189+ let mut style: Option < LineStyle > = None ;
190+ let mut color: Option < CssColor > = None ;
191+ match & value {
192+ Property :: BorderLeft ( value) => {
193+ width = Some ( value. width . to_owned ( ) ) ;
194+ style = Some ( value. style ) ;
195+ color = Some ( value. color . to_owned ( ) ) ;
196+ } ,
197+ Property :: BorderRight ( value) => {
198+ width = Some ( value. width . to_owned ( ) ) ;
199+ style = Some ( value. style ) ;
200+ color = Some ( value. color . to_owned ( ) ) ;
201+ } ,
202+ Property :: BorderTop ( value) => {
203+ width = Some ( value. width . to_owned ( ) ) ;
204+ style = Some ( value. style ) ;
205+ color = Some ( value. color . to_owned ( ) ) ;
206+ } ,
207+ Property :: BorderBottom ( value) => {
208+ width = Some ( value. width . to_owned ( ) ) ;
209+ style = Some ( value. style ) ;
210+ color = Some ( value. color . to_owned ( ) ) ;
211+ } ,
212+ _ => { }
213+ } ;
214+
215+ if let Some ( width) = width {
216+ let width_item = parse_border_width_item ( & width) ;
217+ if let Some ( width_item) = width_item {
218+ let border_width = final_properties
219+ . entry ( prefix_style_key ( "borderWidth" ) )
220+ . or_insert ( StyleValueType :: BorderWidth ( BorderWidth :: new ( ) ) ) ;
221+ if let StyleValueType :: BorderWidth ( border_width) = border_width {
222+ match property_name {
223+ "borderLeft" => border_width. set_left ( width_item. left . unwrap ( ) . as_str ( ) ) ,
224+ "borderRight" => border_width. set_right ( width_item. right . unwrap ( ) . as_str ( ) ) ,
225+ "borderTop" => border_width. set_top ( width_item. top . unwrap ( ) . as_str ( ) ) ,
226+ "borderBottom" => border_width. set_bottom ( width_item. bottom . unwrap ( ) . as_str ( ) ) ,
227+ _ => { }
228+ }
229+ }
230+ }
231+
232+ }
233+ if let Some ( color) = color {
234+ let color_item = parse_border_color_item ( & color) ;
235+ if let Some ( color_item) = color_item {
236+ let border_color = final_properties
237+ . entry ( prefix_style_key ( "borderColor" ) )
238+ . or_insert ( StyleValueType :: BorderColor ( BorderColor :: new ( ) ) ) ;
239+ if let StyleValueType :: BorderColor ( border_color) = border_color {
240+ match property_name {
241+ "borderLeft" => border_color. set_left ( color_item. left . unwrap ( ) . as_str ( ) ) ,
242+ "borderRight" => border_color. set_right ( color_item. right . unwrap ( ) . as_str ( ) ) ,
243+ "borderTop" => border_color. set_top ( color_item. top . unwrap ( ) . as_str ( ) ) ,
244+ "borderBottom" => border_color. set_bottom ( color_item. bottom . unwrap ( ) . as_str ( ) ) ,
245+ _ => { }
246+ }
247+ }
248+ }
249+
250+ }
251+ if let Some ( style) = style {
252+ let style_item = parse_border_style_item ( & style) ;
253+ if let Some ( style_item) = style_item {
254+ let border_style = final_properties
255+ . entry ( prefix_style_key ( "borderStyle" ) )
256+ . or_insert ( StyleValueType :: BorderStyle ( BorderStyle :: new ( ) ) ) ;
257+ if let StyleValueType :: BorderStyle ( border_style) = border_style {
258+ match property_name {
259+ "borderLeft" => border_style. set_left ( style_item. left . unwrap ( ) . as_str ( ) ) ,
260+ "borderRight" => border_style. set_right ( style_item. right . unwrap ( ) . as_str ( ) ) ,
261+ "borderTop" => border_style. set_top ( style_item. top . unwrap ( ) . as_str ( ) ) ,
262+ "borderBottom" => border_style. set_bottom ( style_item. bottom . unwrap ( ) . as_str ( ) ) ,
263+ _ => { }
264+ }
265+ }
266+ }
267+ }
268+ } ,
163269 "borderWidth" => {
164270 let border_width = BorderWidth :: from ( value) ;
165271 if border_width. is_zero ( ) {
@@ -324,14 +430,24 @@ pub fn parse_style_properties(properties: &Vec<(String, Property<'_>)>) -> Style
324430 StyleValueType :: FontWeight ( font_weight) ,
325431 ) ;
326432 }
433+ "fontStyle" => {
434+ let font_style = FontStyle :: from ( value) ;
435+ final_properties. insert (
436+ prefix_style_key ( "fontStyle" ) ,
437+ StyleValueType :: FontStyle ( font_style) ,
438+ ) ;
439+ }
327440 "textDecoration" => {
328- text_decoration = Some ( value) ;
441+ let text_decoration = TextDecoration :: from ( value) ;
442+ final_properties. insert (
443+ prefix_style_key ( "decoration" ) ,
444+ StyleValueType :: TextDecoration ( text_decoration) ,
445+ ) ;
329446 }
330447 "color" => {
331- color = Some ( value) ;
332448 final_properties. insert (
333449 prefix_style_key ( id) ,
334- StyleValueType :: Normal (
450+ StyleValueType :: Color (
335451 value
336452 . value_to_css_string ( PrinterOptions {
337453 minify : false ,
@@ -577,13 +693,6 @@ pub fn parse_style_properties(properties: &Vec<(String, Property<'_>)>) -> Style
577693 }
578694 }
579695 }
580- if let Some ( text_decoration) = text_decoration {
581- let text_decoration = TextDecoration :: from ( ( text_decoration, color) ) ;
582- final_properties. insert (
583- prefix_style_key ( "decoration" ) ,
584- StyleValueType :: TextDecoration ( text_decoration) ,
585- ) ;
586- }
587696
588697 if constrant_size. max_height . is_some ( )
589698 || constrant_size. max_width . is_some ( )
0 commit comments