@@ -32,7 +32,7 @@ type CSSVariableOptions<TValue> = { value: TValue | CSSVariable<TValue> };
3232 * For those cases this counter provides a very basic fallback to generate
3333 * different ids.
3434 */
35- let fallbackId = ( - 2 ) >>> 0 ;
35+ let fallbackId = 9 ** 9 ;
3636
3737export class CSSVariable < TValue = string > extends (
3838 // Inherit from String to be compatible to most CSS-in-JS solutions
@@ -41,7 +41,8 @@ export class CSSVariable<TValue = string> extends (
4141) {
4242 /** Name e.g. `--baseSize` */
4343 readonly name : string ;
44-
44+ /** Value e.g. `var(--baseSize, 12px)` */
45+ readonly val : string ;
4546 /**
4647 * Creates a new CSS Variable with a unique autogenerated name
4748 *
@@ -80,7 +81,9 @@ export class CSSVariable<TValue = string> extends (
8081 ( args . filter ( ( arg ) : arg is string => typeof arg === "string" ) . join ( '-' ) . toLowerCase ( ) ||
8182 // Fallback if babel plugin is missing
8283 ( fallbackId ++ ) . toString ( 16 ) ) ;
83- super ( `var(${ name } ${ optionArg ? `, ${ optionArg . value } ` : "" } )` ) ;
84+ const val = `var(${ name } ${ optionArg ? `, ${ optionArg . value } ` : "" } )` ;
85+ super ( val ) ;
86+ this . val = val ;
8487 this . name = name ;
8588 }
8689 /** Returns the variable name e.g. `--baseSize` */
@@ -95,10 +98,6 @@ export class CSSVariable<TValue = string> extends (
9598 toCSS ( newValue : TValue | CSSVariable < TValue > ) {
9699 return `${ this . name } :${ newValue } ;` ;
97100 }
98- /** Returns the variable value e.g. `var(--baseSize, 12px)` */
99- get val ( ) {
100- return String ( this ) ;
101- }
102101}
103102
104103
@@ -108,13 +107,13 @@ type ICreateVar = {
108107 *
109108 * E.g. `var(--1isaui4-0)`
110109 */
111- < TValue = string > ( ) : CSSVariable < TValue > ;
110+ < TValue = string > ( ) : CSSVariable < TValue > ;
112111 /**
113112 * Creates a new CSS Variable with a custom defined name
114113 *
115114 * E.g. `var(--baseSize)`
116115 */
117- < TValue = string > ( uniqueName : string ) : CSSVariable < TValue > ;
116+ < TValue = string > ( uniqueName : string ) : CSSVariable < TValue > ;
118117 /**
119118 * Creates a new CSS Variable with a unique autogenerated name
120119 * and a fallback value
@@ -202,7 +201,7 @@ export const assignVars = <TTheme extends ThemeStructure>(
202201 . join ( "" ) ;
203202
204203/**
205- * Serialize all CSS Variable values for an entire Theme Contract
204+ * Serialize all CSS Variable values for an entire nested or flat Theme Contract
206205 *
207206 * @example
208207 * ```js
@@ -225,4 +224,4 @@ export const assignVars = <TTheme extends ThemeStructure>(
225224 */
226225export const createGlobalTheme = < TTheme extends ThemeStructure > ( scope : string | undefined | null ,
227226 cssVariables : TTheme ,
228- cssVariableValues : ThemeValues < TTheme > ) => `${ scope ? `${ scope } {` : '' } ${ assignVars ( cssVariables , cssVariableValues as DeepPartial < ThemeValues < TTheme > > ) } ${ scope ? '}' : '' } ` ;
227+ cssVariableValues : ThemeValues < TTheme > ) : string => `${ scope ? `${ scope } {` : '' } ${ assignVars ( cssVariables , cssVariableValues as DeepPartial < ThemeValues < TTheme > > ) } ${ scope ? '}' : '' } ` ;
0 commit comments