@@ -19,46 +19,64 @@ const renderGlobalStyles = ( blockLayouts, setStyles, breakDesktop = 1024, break
1919 let css = ''
2020
2121 const desktopCss = [ ]
22- const tabletMobileCss = [ ]
2322 const tabletCss = [ ]
2423 const mobileCss = [ ]
2524
26- const getDeclaration = ( property , value ) => {
27- if ( typeof value === 'object' ) {
28- return `${ property } : ${ value . top } px ${ value . right } px ${ value . left } px ${ value . bottom } px;`
29- }
30-
31- return `${ property } : ${ value } ;`
25+ const getUnit = ( property , state ) => {
26+ return blockLayouts [ property ] [ `${ state } Unit` ] ?? 'px'
3227 }
3328
34- Object . keys ( blockLayouts ) . forEach ( property => {
35- const desktop = blockLayouts [ property ] . desktop
36- const tablet = blockLayouts [ property ] . tablet
37- const mobile = blockLayouts [ property ] . mobile
29+ const getValue = ( _property , state , value , unit ) => {
30+ let property = _property
3831
39- if ( desktop ) {
40- desktopCss . push ( getDeclaration ( property , desktop ) )
32+ if ( state . indexOf ( 'ParentHover' ) !== - 1 ) {
33+ property += '-parent-hover'
34+ } else if ( state . indexOf ( 'Hover' ) !== - 1 ) {
35+ property += '-hover'
4136 }
4237
43- if ( tablet && mobile ) {
44- tabletCss . push ( getDeclaration ( property , tablet ) )
45- } else if ( tablet && ! mobile ) {
46- tabletMobileCss . push ( getDeclaration ( property , tablet ) )
38+ if ( property . indexOf ( 'shadow' ) !== - 1 ) {
39+ return `${ property } : ${ value } ;`
4740 }
4841
49- if ( mobile ) {
50- mobileCss . push ( getDeclaration ( property , mobile ) )
42+ if ( typeof value === 'object' ) {
43+ return ` ${ property } : ${ value . top } ${ unit } ${ value . right } ${ unit } ${ value . left } ${ unit } ${ value . bottom } ${ unit } ;`
5144 }
45+
46+ return `${ property } : ${ value } ${ unit } ;`
47+ }
48+
49+ Object . keys ( blockLayouts ) . forEach ( property => {
50+ const values = Object . keys ( blockLayouts [ property ] )
51+ . filter ( key => key . indexOf ( 'Unit' ) === - 1 )
52+ . reduce ( ( obj , key ) => {
53+ return {
54+ ...obj ,
55+ [ key ] : blockLayouts [ property ] [ key ] ,
56+ }
57+ } , { } )
58+
59+ Object . entries ( values ) . forEach ( ( [ state , value ] ) => {
60+ const unit = getUnit ( property , state )
61+
62+ if ( state . indexOf ( 'desktop' ) !== - 1 ) {
63+ desktopCss . push ( getValue ( property , state , value , unit ) )
64+ }
65+
66+ if ( state . indexOf ( 'tablet' ) !== - 1 ) {
67+ tabletCss . push ( getValue ( property , state , value , unit ) )
68+ }
69+
70+ if ( state . indexOf ( 'mobile' ) !== - 1 ) {
71+ mobileCss . push ( getValue ( property , state , value , unit ) )
72+ }
73+ } )
5274 } )
5375
5476 css += `:root { ${ compact ( desktopCss ) . join ( '' ) } }`
5577
56- if ( tabletMobileCss . length > 0 ) {
57- css += `@media screen and (max-width: ${ breakDesktop - 1 } px){ :root { ${ compact ( tabletMobileCss ) . join ( '' ) } } }`
58- }
59-
6078 if ( tabletCss . length > 0 ) {
61- css += `@media screen and (min-width: ${ breakTablet } px) and ( max-width: ${ breakDesktop - 1 } px){:root { ${ compact ( tabletCss ) . join ( '' ) } }}`
79+ css += `@media screen and (max-width: ${ breakDesktop - 1 } px){ :root { ${ compact ( tabletCss ) . join ( '' ) } } }`
6280 }
6381
6482 if ( mobileCss . length > 0 ) {
0 commit comments