1- import { pseudo , camelToKebabCase , isClassesObjectType , exception } from '..' ;
1+ import { pseudo , camelToKebabCase , isClassesObjectType , applyCssValue } from '..' ;
22import type { PropertyType , ClassesObjectType , CustomCSSProperties , CustomHTMLType } from '..' ;
33
44export function sheetCompiler ( object : ClassesObjectType | CustomHTMLType , base62Hash ?: string , core ?: string ) {
@@ -40,13 +40,13 @@ export function sheetCompiler(object: ClassesObjectType | CustomHTMLType, base62
4040
4141 if ( typeof value === 'string' || typeof value === 'number' ) {
4242 const CSSProp = camelToKebabCase ( property ) ;
43- const applyValue = typeof value === 'number' && exception . includes ( CSSProp ) ? value : typeof value === 'number' ? value + 'px' : value ;
43+ const applyValue = applyCssValue ( value , CSSProp ) ;
4444 cssRule += `${ bigIndent ? ' ' : ' ' } ${ CSSProp } : ${ applyValue } ;\n` ;
4545 } else if ( isPseudoOrMediaClass ) {
4646 if ( isClassInc ) colon = ':' ;
4747 if ( isElementInc ) colon = '::' ;
48- const kebabPseudoClass = camelToKebabCase ( property . replace ( '&' , '' ) ) ;
49- const styles = stringConverter ( className + colon + kebabPseudoClass , value , indentLevel + 1 ) ;
48+ const kebabPseudoSelector = camelToKebabCase ( property . replace ( '&' , '' ) ) ;
49+ const styles = stringConverter ( className + colon + kebabPseudoSelector , value , indentLevel + 1 ) ;
5050 Object . assign ( classSelector , styles ) ;
5151 } else if ( property . startsWith ( '@media' ) ) {
5252 const mediaRule = property ;
@@ -55,25 +55,30 @@ export function sheetCompiler(object: ClassesObjectType | CustomHTMLType, base62
5555
5656 for ( const mediaProp in value as PropertyType ) {
5757 if ( Object . prototype . hasOwnProperty . call ( value , mediaProp ) ) {
58- const mediaValue = value [ mediaProp ] as PropertyType ;
58+ const mediaValue = value [ mediaProp ] ;
5959 const mediaClassIndex = pseudo . classes . indexOf ( mediaProp ) ;
6060 const isMediaClassInc = pseudo . classes . includes ( mediaProp ) ;
6161 const isMediaElementInc = pseudo . elements . includes ( mediaProp ) ;
62- if ( mediaProp . startsWith ( 'not' ) || mediaProp . startsWith ( 'lang' ) ? mediaClassIndex : isMediaClassInc || isMediaElementInc ) {
62+ const isAndInc = mediaProp . startsWith ( '&' ) ;
63+ if ( mediaProp . startsWith ( 'not' ) || mediaProp . startsWith ( 'lang' ) ? mediaClassIndex : isMediaClassInc || isMediaElementInc || isAndInc ) {
6364 if ( isMediaClassInc ) colon = ':' ;
6465 if ( isMediaElementInc ) colon = '::' ;
65- const kebabMediaProp = camelToKebabCase ( mediaProp ) ;
66+ const kebabMediaProp = camelToKebabCase ( mediaProp . replace ( '&' , '' ) ) ;
6667 let pseudoClassRule = '' ;
67- for ( const pseudoProp in mediaValue ) {
68- if ( Object . prototype . hasOwnProperty . call ( mediaValue , pseudoProp ) ) {
69- pseudoClassRule += rules ( innerIndent + ' ' , mediaValue , pseudoProp ) ;
68+
69+ if ( typeof mediaValue === 'object' && mediaValue !== null ) {
70+ for ( const pseudoProp in mediaValue ) {
71+ if ( Object . prototype . hasOwnProperty . call ( mediaValue , pseudoProp ) ) {
72+ const CSSProp = camelToKebabCase ( pseudoProp ) ;
73+ const applyValue = applyCssValue ( mediaValue [ pseudoProp ] as string | number , CSSProp ) ;
74+ pseudoClassRule += rules ( innerIndent + ' ' , { [ pseudoProp ] : applyValue } , pseudoProp ) ;
75+ }
7076 }
7177 }
7278 nestedRules += selector ( indent + className , colon + kebabMediaProp , pseudoClassRule , innerIndent ) ;
7379 } else {
7480 const CSSProp = camelToKebabCase ( mediaProp ) ;
75- const applyValue =
76- typeof mediaValue === 'number' && exception . includes ( CSSProp ) ? mediaValue : typeof mediaValue === 'number' ? mediaValue + 'px' : mediaValue ;
81+ const applyValue = applyCssValue ( mediaValue as string | number , CSSProp ) ;
7782 regularRules += rules ( innerIndent + ' ' , { [ mediaProp ] : applyValue } , mediaProp ) ;
7883 }
7984 }
0 commit comments