1- import { camelToKebabCase , exception , pseudo } from '..' ;
2- import type { CustomCSSProperties , PropertyType } from '..' ;
1+ import { camelToKebabCase , pseudo , applyCssValue } from '..' ;
2+ import type { CustomCSSProperties , PropertyType , PropertyValue } from '..' ;
33
44export function styleCompiler < T extends CustomCSSProperties > ( object : T , base62Hash ?: string , root ?: string ) {
55 const classNameType = ( ) => {
@@ -8,15 +8,19 @@ export function styleCompiler<T extends CustomCSSProperties>(object: T, base62Ha
88 } ;
99 let bigIndent = false ;
1010
11- const stringConverter = ( className : string , properties : CustomCSSProperties , indentLevel = 0 ) : { mainRules : string ; pseudoRules : string ; media : string } => {
11+ const stringConverter = (
12+ className : string ,
13+ properties : PropertyValue | CustomCSSProperties ,
14+ indentLevel = 0
15+ ) : { mainRules : string ; pseudoRules : string ; media : string } => {
1216 let mainRules = '' ;
1317 let pseudoRules = '' ;
1418 let mediaQueries = '' ;
1519
1620 const indent = ' ' . repeat ( indentLevel ) ;
1721
18- for ( const property in properties ) {
19- const value = ( properties as unknown as PropertyType ) [ property ] ;
22+ for ( const property in properties as CustomCSSProperties ) {
23+ const value = ( properties as PropertyType ) [ property ] ;
2024
2125 if (
2226 pseudo . classes . includes ( property ) ||
@@ -32,18 +36,18 @@ export function styleCompiler<T extends CustomCSSProperties>(object: T, base62Ha
3236 CSSProp = pseudo . classes . includes ( property ) ? `:${ CSSProp } ` : `::${ CSSProp } ` ;
3337 }
3438 const pseudoSelector = property . includes ( '&' ) ? `${ CSSProp } ` : CSSProp ;
35- const pseudoRuleSet = stringConverter ( className + pseudoSelector , value as never , indentLevel + 1 ) ;
39+ const pseudoRuleSet = stringConverter ( className + pseudoSelector , value , indentLevel + 1 ) ;
3640 pseudoRules += `${ indent } ${ className } ${ pseudoSelector } {\n${ pseudoRuleSet . mainRules } ${ pseudoRuleSet . pseudoRules } ${ indent } }\n` ;
3741 mediaQueries += pseudoRuleSet . media ;
3842 } else if ( property . startsWith ( '@media' ) ) {
3943 bigIndent = true ;
40- const mediaRule = stringConverter ( className , value as never , indentLevel + 1 ) ;
44+ const mediaRule = stringConverter ( className , value , indentLevel + 1 ) ;
4145 const mainRule = mediaRule . mainRules ? `{\n ${ className } {\n${ mediaRule . mainRules } }` : '{' ;
4246 mediaQueries += `\n${ property } ${ mainRule } \n${ mediaRule . pseudoRules } ${ mediaRule . media } }\n` ;
4347 bigIndent = false ;
4448 } else if ( typeof value === 'string' || typeof value === 'number' ) {
4549 const CSSProp = camelToKebabCase ( property ) ;
46- const applyValue = typeof value === 'number' && exception . includes ( CSSProp ) ? value : typeof value === 'number' ? value + 'px' : value ;
50+ const applyValue = applyCssValue ( value , CSSProp ) ;
4751 mainRules += `${ bigIndent ? ' ' : ' ' } ${ CSSProp } : ${ applyValue } ;\n` ;
4852 }
4953 }
0 commit comments