@@ -10,14 +10,16 @@ import {
10
10
warn ,
11
11
watch ,
12
12
} from '@vue/runtime-core'
13
- import { NOOP , ShapeFlags } from '@vue/shared'
13
+ import { NOOP , ShapeFlags , normalizeCssVarValue } from '@vue/shared'
14
14
15
15
export const CSS_VAR_TEXT : unique symbol = Symbol ( __DEV__ ? 'CSS_VAR_TEXT' : '' )
16
16
/**
17
17
* Runtime helper for SFC's CSS variable injection feature.
18
18
* @private
19
19
*/
20
- export function useCssVars ( getter : ( ctx : any ) => Record < string , string > ) : void {
20
+ export function useCssVars (
21
+ getter : ( ctx : any ) => Record < string , unknown > ,
22
+ ) : void {
21
23
if ( ! __BROWSER__ && ! __TEST__ ) return
22
24
23
25
const instance = getCurrentInstance ( )
@@ -64,7 +66,7 @@ export function useCssVars(getter: (ctx: any) => Record<string, string>): void {
64
66
} )
65
67
}
66
68
67
- function setVarsOnVNode ( vnode : VNode , vars : Record < string , string > ) {
69
+ function setVarsOnVNode ( vnode : VNode , vars : Record < string , unknown > ) {
68
70
if ( __FEATURE_SUSPENSE__ && vnode . shapeFlag & ShapeFlags . SUSPENSE ) {
69
71
const suspense = vnode . suspense !
70
72
vnode = suspense . activeBranch !
@@ -94,13 +96,14 @@ function setVarsOnVNode(vnode: VNode, vars: Record<string, string>) {
94
96
}
95
97
}
96
98
97
- function setVarsOnNode ( el : Node , vars : Record < string , string > ) {
99
+ function setVarsOnNode ( el : Node , vars : Record < string , unknown > ) {
98
100
if ( el . nodeType === 1 ) {
99
101
const style = ( el as HTMLElement ) . style
100
102
let cssText = ''
101
103
for ( const key in vars ) {
102
- style . setProperty ( `--${ key } ` , vars [ key ] )
103
- cssText += `--${ key } : ${ vars [ key ] } ;`
104
+ const value = normalizeCssVarValue ( vars [ key ] )
105
+ style . setProperty ( `--${ key } ` , value )
106
+ cssText += `--${ key } : ${ value } ;`
104
107
}
105
108
; ( style as any ) [ CSS_VAR_TEXT ] = cssText
106
109
}
0 commit comments