@@ -41,8 +41,15 @@ interface ThemeValue {
41
41
export function presetTheme < T extends Record < string , any > > ( options : PresetThemeOptions < T > ) : Preset < T > {
42
42
const { prefix = '--un-preset-theme' , theme } = options
43
43
const selectors : Selectors = { light : ':root' , ...options . selectors }
44
- if ( ! theme . light )
44
+ let originalThemeKey : 'dark' | 'light' = 'light'
45
+ if ( ! theme . dark ) {
46
+ theme . dark = { } as T
47
+ originalThemeKey = 'dark'
48
+ }
49
+ if ( ! theme . light ) {
45
50
theme . light = { } as T
51
+ originalThemeKey = 'light'
52
+ }
46
53
const keys = Object . keys ( theme )
47
54
const varsRE = new RegExp ( `var\\((${ prefix } [\\w-]*)\\)` )
48
55
const themeValues = new Map < string , ThemeValue > ( )
@@ -62,7 +69,7 @@ export function presetTheme<T extends Record<string, any>>(options: PresetThemeO
62
69
( obj , key ) => {
63
70
let themeValue
64
71
= getThemeVal ( theme [ key ] , themeKeys , index )
65
- || ( key === 'light' ? getThemeVal ( originalTheme , themeKeys ) : null )
72
+ || ( key === originalThemeKey ? getThemeVal ( originalTheme , themeKeys ) : null )
66
73
if ( themeValue ) {
67
74
if ( isColor ) {
68
75
const cssColor = parseCssColor ( themeValue )
@@ -230,7 +237,7 @@ export function presetTheme<T extends Record<string, any>>(options: PresetThemeO
230
237
231
238
return res
232
239
. sort ( ( a , b ) => {
233
- const regexStr = `^${ selectors . light } |^@media \\(prefers-color-scheme:`
240
+ const regexStr = `^${ selectors [ originalThemeKey ] } |^@media \\(prefers-color-scheme:`
234
241
if ( a . match ( regexStr ) ?. length )
235
242
return b . match ( regexStr ) ?. length ? 0 : - 1
236
243
return 1
0 commit comments