11import { ThemeConfig } from "https://esm.sh/[email protected] /types/config.d.ts" ; 22
33import hexToRgb from "./hex-rgb.ts" ;
4+ import { ThemesConfig } from "./types.ts" ;
45
56export function getThemeTokens ( themes ?: Partial < ThemeConfig [ "colors" ] > ) {
67 const tokens : string [ ] = [ ] ;
@@ -13,12 +14,10 @@ export function getThemeTokens(themes?: Partial<ThemeConfig["colors"]>) {
1314 }
1415 }
1516
16- console . log ( Array . from ( new Set ( tokens . flat ( ) ) ) ) ;
17-
1817 return Array . from ( new Set ( tokens . flat ( ) ) ) ;
1918}
2019
21- export function getTailwindCssVariables ( tokens ) {
20+ export function getTailwindCssVariables ( tokens : string [ ] ) {
2221 return tokens . reduce ( ( acc , token ) => {
2322 return {
2423 ...acc ,
@@ -27,20 +26,26 @@ export function getTailwindCssVariables(tokens) {
2726 } , { } ) ;
2827}
2928
30- export function getRgbThemeConfig ( config , prefix ) {
31- let rgbThemeConfig = { } ;
29+ export function getRgbThemeConfig (
30+ config : ThemesConfig ,
31+ prefix : string
32+ ) : ThemesConfig {
33+ const classString = `.` ;
34+ const rgbThemeConfig : ThemesConfig = { } ;
3235
3336 // Loop through user themes to apply theme prefix and convert hex to rgb
3437 for ( const [ userThemeName , userThemeValues ] of Object . entries ( config ) ) {
35- let updatedThemeConfig = [ ] ;
38+ const updatedThemeConfig : string [ ] [ ] = [ ] ;
3639
3740 // Loop through each value of theme to convert hex to rgb
3841 for ( const [ token , hex ] of Object . entries ( userThemeValues ) ) {
39- updatedThemeConfig . push ( [ `--${ token } ` , hexToRgb ( hex ) ] ) ;
42+ if ( hex ) {
43+ updatedThemeConfig . push ( [ `--${ token } ` , hexToRgb ( hex ) ] ) ;
44+ }
4045 }
4146
4247 const updatedTheme = {
43- [ `. ${ prefix . concat ( userThemeName ) } ` ] : Object . fromEntries (
48+ [ classString . concat ( prefix , userThemeName ) ] : Object . fromEntries (
4449 new Map ( updatedThemeConfig )
4550 ) ,
4651 } ;
0 commit comments