@@ -4,6 +4,11 @@ import { assert } from "tsafe/assert";
44import type { Equals } from "tsafe" ;
55import { exclude } from "tsafe/exclude" ;
66import memoize from "memoizee" ;
7+ import type { ColorScheme } from "./colorOptions" ;
8+
9+ const orderedColorScheme = [ "light" , "dark" ] as const ;
10+
11+ assert < Equals < typeof orderedColorScheme [ number ] , ColorScheme > > ( ) ;
712
813export type CssVariableValue = Record <
914 "root" | keyof MediaQueryByBreakpoint ,
@@ -28,7 +33,7 @@ export const createGetCssVariable = memoize((rawCssCode: string) => {
2833 orderedBreakpoints . forEach ( breakpoint => {
2934 const rules = rulesByBreakpoint [ breakpoint ] ;
3035
31- ( [ "light" , "dark" ] as const ) . forEach ( colorScheme => {
36+ orderedColorScheme . forEach ( colorScheme => {
3237 const [ declaration ] = rules
3338 . filter (
3439 ( rule : any ) =>
@@ -60,8 +65,6 @@ export const createGetCssVariable = memoize((rawCssCode: string) => {
6065 ) ;
6166 }
6267
63- //TODO: Fix! It's more complex than that!
64-
6568 const value = declaration ?. value as string | undefined ;
6669
6770 if ( value === undefined ) {
@@ -70,10 +73,26 @@ export const createGetCssVariable = memoize((rawCssCode: string) => {
7073
7174 const match = value . match ( / ^ v a r \( ( - - [ ^ ) ] + ) \) $ / ) ;
7275
73- cssVariableValue [ breakpoint ] [ colorScheme ] =
74- match === null
75- ? value
76- : getCssVariable ( match [ 1 ] as any ) [ breakpoint ] [ colorScheme ] ;
76+ for (
77+ let i = orderedBreakpoints . indexOf ( breakpoint ) ;
78+ i < orderedBreakpoints . length ;
79+ i ++
80+ ) {
81+ const breakpoint = orderedBreakpoints [ i ] ;
82+
83+ for (
84+ let j = orderedColorScheme . indexOf ( colorScheme ) ;
85+ j < orderedColorScheme . length ;
86+ j ++
87+ ) {
88+ const colorScheme = orderedColorScheme [ j ] ;
89+
90+ ( cssVariableValue [ breakpoint ] ??= { } as any ) [ colorScheme ] =
91+ match === null
92+ ? value
93+ : getCssVariable ( match [ 1 ] as any ) [ breakpoint ] [ colorScheme ] ;
94+ }
95+ }
7796 } ) ;
7897 } ) ;
7998
0 commit comments