11pub mod theme;
22
33use crate :: theme:: Theme ;
4- use css:: { convert_property, PropertyType } ;
4+ use css:: { convert_property, to_kebab_case , PropertyType } ;
55use std:: collections:: { BTreeMap , HashSet } ;
66
77trait ExtractStyle {
@@ -19,7 +19,7 @@ pub struct StyleSheetProperty {
1919impl ExtractStyle for StyleSheetProperty {
2020 fn extract ( & self ) -> String {
2121 let selector = if let Some ( selector) = & self . selector {
22- format ! ( ":{}" , selector)
22+ format ! ( ":{}" , to_kebab_case ( selector) )
2323 } else {
2424 String :: new ( )
2525 } ;
@@ -71,6 +71,7 @@ pub struct StyleSheet {
7171 /// level -> properties
7272 pub properties : BTreeMap < u8 , HashSet < StyleSheetProperty > > ,
7373 pub css : HashSet < StyleSheetCss > ,
74+ theme : Theme ,
7475 theme_declaration : String ,
7576}
7677
@@ -86,6 +87,7 @@ impl StyleSheet {
8687 properties : BTreeMap :: new ( ) ,
8788 css : HashSet :: new ( ) ,
8889 theme_declaration : String :: new ( ) ,
90+ theme : Theme :: new ( ) ,
8991 }
9092 }
9193
@@ -114,13 +116,20 @@ impl StyleSheet {
114116 pub fn set_theme ( & mut self , theme : Theme ) {
115117 let mut theme_declaration = String :: new ( ) ;
116118 theme_declaration. push_str ( theme. colors . to_css ( ) . as_str ( ) ) ;
119+ self . theme = theme;
117120 self . theme_declaration = theme_declaration;
118121 }
119122
120- pub fn create_css ( & self , break_points : Vec < u16 > ) -> String {
123+ pub fn create_css ( & self ) -> String {
121124 let mut css = self . theme_declaration . clone ( ) ;
122125 for ( level, props) in self . properties . iter ( ) {
123- let inner_css = props
126+ // If has a selector property, move it to the back
127+ let ( mut select_props, other_props) : ( Vec < _ > , Vec < _ > ) =
128+ props. iter ( ) . partition ( |prop| prop. selector . is_some ( ) ) ;
129+ let mut sorted_props = other_props;
130+ sorted_props. append ( & mut select_props) ;
131+
132+ let inner_css = sorted_props
124133 . iter ( )
125134 . map ( |prop| prop. extract ( ) )
126135 . collect :: < Vec < String > > ( )
@@ -131,12 +140,18 @@ impl StyleSheet {
131140 css. push_str (
132141 format ! (
133142 "\n @media (min-width:{}px){{{}}}" ,
134- break_points
143+ self . theme
144+ . break_points
135145 . iter( )
136146 . enumerate( )
137147 . find( |( idx, _) | ( * idx as u8 ) == * level)
138148 . map( |( _, bp) | * bp)
139- . unwrap_or_else( || break_points. last( ) . cloned( ) . unwrap_or( 0 ) ) ,
149+ . unwrap_or_else( || self
150+ . theme
151+ . break_points
152+ . last( )
153+ . cloned( )
154+ . unwrap_or( 0 ) ) ,
140155 inner_css
141156 )
142157 . as_str ( ) ,
0 commit comments