|
@@ -10,14 +10,16 @@ import {
|
|
|
warn,
|
|
warn,
|
|
|
watch,
|
|
watch,
|
|
|
} from '@vue/runtime-core'
|
|
} from '@vue/runtime-core'
|
|
|
-import { NOOP, ShapeFlags } from '@vue/shared'
|
|
|
|
|
|
|
+import { NOOP, ShapeFlags, normalizeCssVarValue } from '@vue/shared'
|
|
|
|
|
|
|
|
export const CSS_VAR_TEXT: unique symbol = Symbol(__DEV__ ? 'CSS_VAR_TEXT' : '')
|
|
export const CSS_VAR_TEXT: unique symbol = Symbol(__DEV__ ? 'CSS_VAR_TEXT' : '')
|
|
|
/**
|
|
/**
|
|
|
* Runtime helper for SFC's CSS variable injection feature.
|
|
* Runtime helper for SFC's CSS variable injection feature.
|
|
|
* @private
|
|
* @private
|
|
|
*/
|
|
*/
|
|
|
-export function useCssVars(getter: (ctx: any) => Record<string, string>): void {
|
|
|
|
|
|
|
+export function useCssVars(
|
|
|
|
|
+ getter: (ctx: any) => Record<string, unknown>,
|
|
|
|
|
+): void {
|
|
|
if (!__BROWSER__ && !__TEST__) return
|
|
if (!__BROWSER__ && !__TEST__) return
|
|
|
|
|
|
|
|
const instance = getCurrentInstance()
|
|
const instance = getCurrentInstance()
|
|
@@ -64,7 +66,7 @@ export function useCssVars(getter: (ctx: any) => Record<string, string>): void {
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-function setVarsOnVNode(vnode: VNode, vars: Record<string, string>) {
|
|
|
|
|
|
|
+function setVarsOnVNode(vnode: VNode, vars: Record<string, unknown>) {
|
|
|
if (__FEATURE_SUSPENSE__ && vnode.shapeFlag & ShapeFlags.SUSPENSE) {
|
|
if (__FEATURE_SUSPENSE__ && vnode.shapeFlag & ShapeFlags.SUSPENSE) {
|
|
|
const suspense = vnode.suspense!
|
|
const suspense = vnode.suspense!
|
|
|
vnode = suspense.activeBranch!
|
|
vnode = suspense.activeBranch!
|
|
@@ -94,13 +96,14 @@ function setVarsOnVNode(vnode: VNode, vars: Record<string, string>) {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-function setVarsOnNode(el: Node, vars: Record<string, string>) {
|
|
|
|
|
|
|
+function setVarsOnNode(el: Node, vars: Record<string, unknown>) {
|
|
|
if (el.nodeType === 1) {
|
|
if (el.nodeType === 1) {
|
|
|
const style = (el as HTMLElement).style
|
|
const style = (el as HTMLElement).style
|
|
|
let cssText = ''
|
|
let cssText = ''
|
|
|
for (const key in vars) {
|
|
for (const key in vars) {
|
|
|
- style.setProperty(`--${key}`, vars[key])
|
|
|
|
|
- cssText += `--${key}: ${vars[key]};`
|
|
|
|
|
|
|
+ const value = normalizeCssVarValue(vars[key])
|
|
|
|
|
+ style.setProperty(`--${key}`, value)
|
|
|
|
|
+ cssText += `--${key}: ${value};`
|
|
|
}
|
|
}
|
|
|
;(style as any)[CSS_VAR_TEXT] = cssText
|
|
;(style as any)[CSS_VAR_TEXT] = cssText
|
|
|
}
|
|
}
|