@@ -39,12 +39,10 @@ export const colorNames = [
3939] ;
4040
4141/**
42- * Generate theme colors (ex. { primary: hsl(var(--color-primary) / <alpha-value> ), ... })
42+ * Generate theme colors (ex. { primary: hsl(var(--color-primary)), ... })
4343 */
4444export function createThemeColors ( colorSpace : SupportedColorSpace ) {
45- return fromEntries (
46- colorNames . map ( ( color ) => [ color , `${ colorSpace } (var(--color-${ color } ) / <alpha-value>)` ] )
47- ) ;
45+ return fromEntries ( colorNames . map ( ( color ) => [ color , `${ colorSpace } (var(--color-${ color } ))` ] ) ) ;
4846}
4947
5048/**
@@ -153,8 +151,8 @@ export function processThemeColors(themeColors: NestedColors, colorSpace: Suppor
153151 const result = fromEntries (
154152 entries ( colors ) . map ( ( [ name , value ] ) => {
155153 if ( colorNames . includes ( String ( name ) ) ) {
156- // Add space separated color variables for each color
157- return [ `--color-${ name } ` , colorVariableValue ( value , colorSpace ) ] ;
154+ // Convert each color to common colorspace and add variable
155+ return [ `--color-${ name } ` , convertColor ( value , colorSpace ) ] ;
158156 } else {
159157 // Additional properties such as `color-scheme` or CSS variable
160158 return [ name , value ] ;
@@ -212,29 +210,25 @@ function darkenColor(color: Color | string, percentage: number) {
212210/**
213211 * Convert color to space separated components string
214212 */
215- export function colorVariableValue (
216- color : Color | string ,
217- colorSpace : SupportedColorSpace ,
218- decimals = 4
219- ) {
213+ export function convertColor ( color : Color | string , colorSpace : SupportedColorSpace , decimals = 4 ) {
220214 try {
221215 if ( colorSpace === 'rgb' ) {
222216 const computedColor = typeof color === 'string' ? rgb ( color ) : ( color as Rgb ) ;
223217 if ( computedColor ) {
224218 const { r, g, b } = computedColor ;
225- return `${ round ( r * 255 , decimals ) } ${ round ( g * 255 , decimals ) } ${ round ( b * 255 , decimals ) } ` ;
219+ return `rgb( ${ round ( r * 255 , decimals ) } ${ round ( g * 255 , decimals ) } ${ round ( b * 255 , decimals ) } ) ` ;
226220 }
227221 } else if ( colorSpace === 'hsl' ) {
228222 const computedColor = typeof color === 'string' ? hsl ( clampRgb ( color ) ) : ( color as Hsl ) ;
229223 if ( computedColor ) {
230224 const { h, s, l } = computedColor ;
231- return `${ round ( h ?? 0 , decimals ) } ${ round ( s * 100 , decimals ) } % ${ round ( l * 100 , decimals ) } %` ;
225+ return `hsl( ${ round ( h ?? 0 , decimals ) } ${ round ( s * 100 , decimals ) } % ${ round ( l * 100 , decimals ) } %) ` ;
232226 }
233227 } else if ( colorSpace === 'oklch' ) {
234228 const computedColor = typeof color === 'string' ? oklch ( clampRgb ( color ) ) : ( color as Oklch ) ;
235229 if ( computedColor ) {
236230 const { l, c, h } = computedColor ;
237- return `${ round ( l , decimals ) } ${ round ( c , decimals ) } ${ round ( h ?? 0 , decimals ) } ` ;
231+ return `oklch( ${ round ( l , decimals ) } ${ round ( c , decimals ) } ${ round ( h ?? 0 , decimals ) } ) ` ;
238232 }
239233 }
240234 } catch ( e ) {
0 commit comments