@@ -9,7 +9,6 @@ use super::parse_style_properties::parse_style_properties;
99pub type StyleValue = Vec < StyleValueType > ;
1010
1111pub struct StyleData < ' i > {
12- pub style_record : Rc < RefCell < HashMap < SpanKey , Vec < ( String , Property < ' i > ) > > > > ,
1312 pub pesudo_style_record : Rc < RefCell < HashMap < SpanKey , Vec < ( String , Vec < ( String , Property < ' i > ) > ) > > > > ,
1413 pub all_style : Rc < RefCell < HashMap < String , StyleValue > > > ,
1514 pub has_nesting : bool
@@ -46,7 +45,7 @@ impl<'i> Visitor<'i> for StyleVisitor<'i> {
4645 let selectors_str = style. selectors . to_string ( ) ;
4746 let selectors: Vec < & str > = selectors_str. split ( "," ) . collect :: < Vec < & str > > ( ) ;
4847 for index in 0 ..selectors. len ( ) {
49- let selector = selectors[ index] . trim ( ) . replace ( "." , "" ) ;
48+ let selector = selectors[ index] . trim ( ) . to_string ( ) ;
5049 let mut all_style = self . all_style . borrow_mut ( ) ;
5150 let decorations = all_style. iter_mut ( ) . find ( |( id, _) | id == & selector) ;
5251 if let Some ( ( _, declarations) ) = decorations {
@@ -118,7 +117,7 @@ impl<'i> StyleParser<'i> {
118117 } )
119118 . collect :: < Vec < ( _ , _ ) > > ( ) ; // Specify the lifetime of the tuple elements to match the input data
120119 // 判断是否含有嵌套选择器
121- if selector. contains ( " " ) {
120+ if selector. contains ( " " ) || selector . chars ( ) . filter ( | & c| c == '.' ) . count ( ) > 1 {
122121 has_nesting = true
123122 }
124123 ( selector. to_owned ( ) , properties)
@@ -168,35 +167,9 @@ impl<'i> StyleParser<'i> {
168167 } )
169168 . collect :: < HashMap < _ , _ > > ( ) ;
170169
171-
172- let final_style_record = style_record
173- . iter_mut ( )
174- . map ( |( selector, style_value) | {
175- (
176- selector. to_owned ( ) ,
177- style_value
178- . iter_mut ( )
179- . reduce ( |a, b| {
180- for ( key, value) in b. iter ( ) {
181- let has_property_index = a. iter ( ) . position ( |property| property. 0 == key. to_owned ( ) ) ;
182- if let Some ( index) = has_property_index {
183- a[ index] = ( key. to_owned ( ) , value. clone ( ) ) ;
184- } else {
185- a. push ( ( key. to_owned ( ) , value. clone ( ) ) ) ;
186- }
187- }
188- a
189- } )
190- . unwrap ( )
191- . to_owned ( )
192- )
193- } )
194- . collect :: < HashMap < _ , _ > > ( ) ;
195-
196- let final_pesudo_style_record = pesudo_style_record;
170+ let final_pesudo_style_record = pesudo_style_record;
197171
198172 StyleData {
199- style_record : Rc :: new ( RefCell :: new ( final_style_record) ) ,
200173 pesudo_style_record : Rc :: new ( RefCell :: new ( final_pesudo_style_record) ) ,
201174 all_style : Rc :: new ( RefCell :: new ( final_all_style) ) ,
202175 has_nesting
0 commit comments