@@ -46,11 +46,14 @@ interface InternalThemeOptions {
46
46
cspNonce ?: string
47
47
isDisabled : boolean
48
48
defaultTheme : string
49
+ prefix : string
49
50
variations : false | VariationsOptions
50
51
themes : Record < string , InternalThemeDefinition >
51
52
stylesheetId : string
52
53
scope ?: string
54
+ scoped : boolean
53
55
unimportant : boolean
56
+ utilities : boolean
54
57
}
55
58
56
59
interface VariationsOptions {
@@ -102,6 +105,7 @@ export interface ThemeInstance {
102
105
readonly name : Readonly < Ref < string > >
103
106
readonly current : DeepReadonly < Ref < InternalThemeDefinition > >
104
107
readonly computedThemes : DeepReadonly < Ref < Record < string , InternalThemeDefinition > > >
108
+ readonly prefix : string
105
109
106
110
readonly themeClasses : Readonly < Ref < string | undefined > >
107
111
readonly styles : Readonly < Ref < string > >
@@ -121,6 +125,7 @@ export const makeThemeProps = propsFactory({
121
125
function genDefaults ( ) {
122
126
return {
123
127
defaultTheme : 'light' ,
128
+ prefix : 'v-' ,
124
129
variations : { colors : [ ] , lighten : 0 , darken : 0 } ,
125
130
themes : {
126
131
light : {
@@ -199,7 +204,9 @@ function genDefaults () {
199
204
} ,
200
205
} ,
201
206
stylesheetId : 'vuetify-theme-stylesheet' ,
207
+ scoped : false ,
202
208
unimportant : false ,
209
+ utilities : true ,
203
210
}
204
211
}
205
212
@@ -230,23 +237,23 @@ function createCssClass (lines: string[], selector: string, content: string[], s
230
237
)
231
238
}
232
239
233
- function genCssVariables ( theme : InternalThemeDefinition ) {
240
+ function genCssVariables ( theme : InternalThemeDefinition , prefix : string ) {
234
241
const lightOverlay = theme . dark ? 2 : 1
235
242
const darkOverlay = theme . dark ? 1 : 2
236
243
237
244
const variables : string [ ] = [ ]
238
245
for ( const [ key , value ] of Object . entries ( theme . colors ) ) {
239
246
const rgb = parseColor ( value )
240
- variables . push ( `--v- theme-${ key } : ${ rgb . r } ,${ rgb . g } ,${ rgb . b } ` )
247
+ variables . push ( `--${ prefix } theme-${ key } : ${ rgb . r } ,${ rgb . g } ,${ rgb . b } ` )
241
248
if ( ! key . startsWith ( 'on-' ) ) {
242
- variables . push ( `--v- theme-${ key } -overlay-multiplier: ${ getLuma ( value ) > 0.18 ? lightOverlay : darkOverlay } ` )
249
+ variables . push ( `--${ prefix } theme-${ key } -overlay-multiplier: ${ getLuma ( value ) > 0.18 ? lightOverlay : darkOverlay } ` )
243
250
}
244
251
}
245
252
246
253
for ( const [ key , value ] of Object . entries ( theme . variables ) ) {
247
254
const color = typeof value === 'string' && value . startsWith ( '#' ) ? parseColor ( value ) : undefined
248
255
const rgb = color ? `${ color . r } , ${ color . g } , ${ color . b } ` : undefined
249
- variables . push ( `--v- ${ key } : ${ rgb ?? value } ` )
256
+ variables . push ( `--${ prefix } ${ key } : ${ rgb ?? value } ` )
250
257
}
251
258
252
259
return variables
@@ -361,44 +368,47 @@ export function createTheme (options?: ThemeOptions): ThemeInstance & { install:
361
368
const styles = computed ( ( ) => {
362
369
const lines : string [ ] = [ ]
363
370
const important = parsedOptions . unimportant ? '' : ' !important'
371
+ const scoped = parsedOptions . scoped ? parsedOptions . prefix : ''
364
372
365
373
if ( current . value ?. dark ) {
366
374
createCssClass ( lines , ':root' , [ 'color-scheme: dark' ] , parsedOptions . scope )
367
375
}
368
376
369
- createCssClass ( lines , ':root' , genCssVariables ( current . value ) , parsedOptions . scope )
377
+ createCssClass ( lines , ':root' , genCssVariables ( current . value , parsedOptions . prefix ) , parsedOptions . scope )
370
378
371
379
for ( const [ themeName , theme ] of Object . entries ( computedThemes . value ) ) {
372
- createCssClass ( lines , `.v- theme--${ themeName } ` , [
380
+ createCssClass ( lines , `.${ parsedOptions . prefix } theme--${ themeName } ` , [
373
381
`color-scheme: ${ theme . dark ? 'dark' : 'normal' } ` ,
374
- ...genCssVariables ( theme ) ,
382
+ ...genCssVariables ( theme , parsedOptions . prefix ) ,
375
383
] , parsedOptions . scope )
376
384
}
377
385
378
- const bgLines : string [ ] = [ ]
379
- const fgLines : string [ ] = [ ]
386
+ if ( parsedOptions . utilities ) {
387
+ const bgLines : string [ ] = [ ]
388
+ const fgLines : string [ ] = [ ]
380
389
381
- const colors = new Set ( Object . values ( computedThemes . value ) . flatMap ( theme => Object . keys ( theme . colors ) ) )
382
- for ( const key of colors ) {
383
- if ( key . startsWith ( 'on-' ) ) {
384
- createCssClass ( fgLines , `.${ key } ` , [ `color: rgb(var(--v-theme-${ key } ))${ important } ` ] , parsedOptions . scope )
385
- } else {
386
- createCssClass ( bgLines , `.bg-${ key } ` , [
387
- `--v-theme-overlay-multiplier: var(--v-theme-${ key } -overlay-multiplier)` ,
388
- `background-color: rgb(var(--v-theme-${ key } ))${ important } ` ,
389
- `color: rgb(var(--v-theme-on-${ key } ))${ important } ` ,
390
- ] , parsedOptions . scope )
391
- createCssClass ( fgLines , `.text-${ key } ` , [ `color: rgb(var(--v-theme-${ key } ))${ important } ` ] , parsedOptions . scope )
392
- createCssClass ( fgLines , `.border-${ key } ` , [ `--v-border-color: var(--v-theme-${ key } )` ] , parsedOptions . scope )
390
+ const colors = new Set ( Object . values ( computedThemes . value ) . flatMap ( theme => Object . keys ( theme . colors ) ) )
391
+ for ( const key of colors ) {
392
+ if ( key . startsWith ( 'on-' ) ) {
393
+ createCssClass ( fgLines , `.${ key } ` , [ `color: rgb(var(--${ parsedOptions . prefix } theme-${ key } ))${ important } ` ] , parsedOptions . scope )
394
+ } else {
395
+ createCssClass ( bgLines , `.${ scoped } bg-${ key } ` , [
396
+ `--${ parsedOptions . prefix } theme-overlay-multiplier: var(--${ parsedOptions . prefix } theme-${ key } -overlay-multiplier)` ,
397
+ `background-color: rgb(var(--${ parsedOptions . prefix } theme-${ key } ))${ important } ` ,
398
+ `color: rgb(var(--${ parsedOptions . prefix } theme-on-${ key } ))${ important } ` ,
399
+ ] , parsedOptions . scope )
400
+ createCssClass ( fgLines , `.${ scoped } text-${ key } ` , [ `color: rgb(var(--${ parsedOptions . prefix } theme-${ key } ))${ important } ` ] , parsedOptions . scope )
401
+ createCssClass ( fgLines , `.${ scoped } border-${ key } ` , [ `--${ parsedOptions . prefix } border-color: var(--${ parsedOptions . prefix } theme-${ key } )` ] , parsedOptions . scope )
402
+ }
393
403
}
394
- }
395
404
396
- lines . push ( ...bgLines , ...fgLines )
405
+ lines . push ( ...bgLines , ...fgLines )
406
+ }
397
407
398
408
return lines . map ( ( str , i ) => i === 0 ? str : ` ${ str } ` ) . join ( '' )
399
409
} )
400
410
401
- const themeClasses = computed ( ( ) => parsedOptions . isDisabled ? undefined : `v- theme--${ name . value } ` )
411
+ const themeClasses = computed ( ( ) => parsedOptions . isDisabled ? undefined : `${ parsedOptions . prefix } theme--${ name . value } ` )
402
412
const themeNames = computed ( ( ) => Object . keys ( computedThemes . value ) )
403
413
404
414
function install ( app : App ) {
@@ -486,6 +496,7 @@ export function createTheme (options?: ThemeOptions): ThemeInstance & { install:
486
496
themes,
487
497
current,
488
498
computedThemes,
499
+ prefix : parsedOptions . prefix ,
489
500
themeClasses,
490
501
styles,
491
502
global : {
@@ -505,7 +516,7 @@ export function provideTheme (props: { theme?: string }) {
505
516
const name = computed ( ( ) => props . theme ?? theme . name . value )
506
517
const current = computed ( ( ) => theme . themes . value [ name . value ] )
507
518
508
- const themeClasses = computed ( ( ) => theme . isDisabled ? undefined : `v- theme--${ name . value } ` )
519
+ const themeClasses = computed ( ( ) => theme . isDisabled ? undefined : `${ theme . prefix } theme--${ name . value } ` )
509
520
510
521
const newTheme : ThemeInstance = {
511
522
...theme ,
0 commit comments