@@ -115,22 +115,31 @@ export interface MaterialsOptions {
115115}
116116
117117const generateCssString = ( pageOptions : PageOptions , materialsOptions : MaterialsOptions ) => {
118- if ( ! pageOptions ?. pageBaseStyle ?. className || ! pageOptions ?. pageBaseStyle ?. style ) {
119- return ''
118+ let cssObject : Record < string , any > = { }
119+ const parseStyle = ( styleString : string ) => {
120+ const styleObj : Record < string , string > = { }
121+ const styleItems = styleString . split ( ';' )
122+ styleItems . forEach ( ( item : string ) => {
123+ if ( item ) {
124+ const stylekeyValue = item . split ( ':' )
125+ styleObj [ stylekeyValue [ 0 ] . trim ( ) ] = stylekeyValue [ 1 ] . trim ( )
126+ }
127+ } )
128+ return styleObj
129+ }
130+ if ( pageOptions ?. pageBaseStyle ?. className && pageOptions ?. pageBaseStyle ?. style ) {
131+ cssObject [ `.${ pageOptions . pageBaseStyle . className } ` ] = parseStyle ( pageOptions . pageBaseStyle . style )
120132 }
121133
122- const formatCssRule = ( className : string , style : string ) => `.${ className } {\n ${ style . trim ( ) } \n}\n`
123- const baseStyle = `.${ pageOptions . pageBaseStyle . className } {\r\n ${ pageOptions . pageBaseStyle . style } \r\n}\r\n`
124-
125- if ( ! materialsOptions . useBaseStyle ) {
126- return baseStyle
134+ if ( materialsOptions . useBaseStyle ) {
135+ cssObject = {
136+ ...cssObject ,
137+ [ `.${ materialsOptions . blockBaseStyle . className } ` ] : parseStyle ( materialsOptions . blockBaseStyle . style ) ,
138+ [ `.${ materialsOptions . componentBaseStyle . className } ` ] : parseStyle ( materialsOptions . componentBaseStyle . style )
139+ }
127140 }
128141
129- return [
130- formatCssRule ( pageOptions . pageBaseStyle . className , pageOptions . pageBaseStyle . style ) ,
131- formatCssRule ( materialsOptions . blockBaseStyle . className , materialsOptions . blockBaseStyle . style ) ,
132- formatCssRule ( materialsOptions . componentBaseStyle . className , materialsOptions . componentBaseStyle . style )
133- ] . join ( '\n' )
142+ return cssObject
134143}
135144
136145const getDefaultPage = ( ) => {
0 commit comments