]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
refactor(vapor): rename vaporUseCssVars to useVaporCssVars and update related references
authordaiwei <daiwei521@126.com>
Mon, 10 Nov 2025 07:00:08 +0000 (15:00 +0800)
committerdaiwei <daiwei521@126.com>
Mon, 10 Nov 2025 07:03:46 +0000 (15:03 +0800)
packages/compiler-sfc/src/style/cssVars.ts
packages/runtime-dom/src/helpers/useCssVars.ts
packages/runtime-vapor/__tests__/helpers/useCssVars.spec.ts
packages/runtime-vapor/src/helpers/useCssVars.ts
packages/runtime-vapor/src/index.ts

index 2a0c53305ac0d4553ac02f0640d09c96b9e7240e..b626663b51874d37150f4c1b53d73cdeccb6e13d 100644 (file)
@@ -10,12 +10,12 @@ import {
 import type { SFCDescriptor } from '../parse'
 import type { PluginCreator } from 'postcss'
 import hash from 'hash-sum'
-import { capitalize, getEscapedCssVarName } from '@vue/shared'
+import { getEscapedCssVarName } from '@vue/shared'
 
 export const CSS_VARS_HELPER = `useCssVars`
 
 export function getCssVarsHelper(vapor: boolean | undefined): string {
-  return vapor ? `vapor${capitalize(CSS_VARS_HELPER)}` : CSS_VARS_HELPER
+  return vapor ? `useVaporCssVars` : CSS_VARS_HELPER
 }
 
 export function genCssVarsFromList(
index 64ac46ae480603d22d4460b227042e3af9ef6f5b..a569e688a7dbe994ed5c57a8de35cca24abc8bd1 100644 (file)
@@ -71,6 +71,10 @@ function setVarsOnVNode(vnode: VNode, vars: Record<string, string>) {
   }
 }
 
+/**
+ * @internal
+ * shared between vdom and vapor
+ */
 export function baseUseCssVars(
   instance: GenericComponentInstance | null,
   getParentNode: () => Node,
@@ -86,7 +90,7 @@ export function baseUseCssVars(
   /* v8 ignore stop */
 
   if (__DEV__) {
-    instance.getCssVars = () => getVars()
+    instance.getCssVars = getVars
   }
 
   const updateTeleports = (instance.ut = (vars = getVars()) => {
@@ -116,6 +120,10 @@ export function baseUseCssVars(
   })
 }
 
+/**
+ * @internal
+ * shared between vdom and vapor
+ */
 export function setVarsOnNode(el: Node, vars: Record<string, string>): void {
   if (el.nodeType === 1) {
     const style = (el as HTMLElement).style
index a82091495aa722812e621b6576afff79396024a2..1352760d1371a65e30a0c424f06cb47ee7400c89 100644 (file)
@@ -5,7 +5,7 @@ import {
   renderEffect,
   setStyle,
   template,
-  vaporUseCssVars,
+  useVaporCssVars,
 } from '@vue/runtime-vapor'
 import { nextTick, onMounted, reactive, ref } from '@vue/runtime-core'
 import { makeRender } from '../_utils'
@@ -13,7 +13,7 @@ import type { VaporComponent } from '../../src/component'
 
 const define = makeRender()
 
-describe('vaporUseCssVars', () => {
+describe('useVaporCssVars', () => {
   async function assertCssVars(getApp: (state: any) => VaporComponent) {
     const state = reactive({ color: 'red' })
     const App = getApp(state)
@@ -35,7 +35,7 @@ describe('vaporUseCssVars', () => {
     const t0 = template('<div></div>')
     await assertCssVars(state => ({
       setup() {
-        vaporUseCssVars(() => state)
+        useVaporCssVars(() => state)
         const n0 = t0()
         return n0
       },
@@ -46,7 +46,7 @@ describe('vaporUseCssVars', () => {
     const t0 = template('<div></div>')
     await assertCssVars(state => ({
       setup() {
-        vaporUseCssVars(() => state)
+        useVaporCssVars(() => state)
         const n0 = t0()
         const n1 = t0()
         return [n0, n1]
@@ -64,7 +64,7 @@ describe('vaporUseCssVars', () => {
     })
     await assertCssVars(state => ({
       setup() {
-        vaporUseCssVars(() => state)
+        useVaporCssVars(() => state)
         return createComponent(Child)
       },
     }))
@@ -82,7 +82,7 @@ describe('vaporUseCssVars', () => {
 
     define({
       setup() {
-        vaporUseCssVars(() => state)
+        useVaporCssVars(() => state)
         const n0 = createIf(
           () => value.value,
           () => {
@@ -125,7 +125,7 @@ describe('vaporUseCssVars', () => {
     const t0 = template('<div></div>')
     define({
       setup() {
-        vaporUseCssVars(() => state)
+        useVaporCssVars(() => state)
         return createComponent(Child, null, {
           default: () => {
             return createIf(
@@ -174,7 +174,7 @@ describe('vaporUseCssVars', () => {
 
     define({
       setup() {
-        vaporUseCssVars(() => state)
+        useVaporCssVars(() => state)
         const n0 = t0() as any
         renderEffect(() =>
           setStyle(n0, state.color ? 'pointer-events: none' : undefined),
@@ -214,7 +214,7 @@ describe('vaporUseCssVars', () => {
 
     define({
       setup() {
-        vaporUseCssVars(() => state)
+        useVaporCssVars(() => state)
         return createIf(
           () => value.value,
           () => createComponent(Child),
@@ -246,7 +246,7 @@ describe('vaporUseCssVars', () => {
 
     define({
       setup() {
-        vaporUseCssVars(() => state)
+        useVaporCssVars(() => state)
         onMounted(() => {
           colorInOnMount = (
             root.children[0] as HTMLElement
index 0f5fa2b0407280cb36b9f708a8fffd0aa2e587ae..9a67ae6bfd0e0a9a00aba891cd7bd899e4dc16a7 100644 (file)
@@ -7,14 +7,13 @@ import { type VaporComponentInstance, isVaporComponent } from '../component'
 import { isArray } from '@vue/shared'
 import type { Block } from '../block'
 
-export function vaporUseCssVars(getter: () => Record<string, string>): void {
+export function useVaporCssVars(getter: () => Record<string, string>): void {
   if (!__BROWSER__ && !__TEST__) return
-
   const instance = currentInstance as VaporComponentInstance
   baseUseCssVars(
     instance,
     () => resolveParentNode(instance.block),
-    () => getter(),
+    getter,
     vars => setVarsOnBlock(instance.block, vars),
   )
 }
index e6d0eacaf2165a98d27fbc244efb95142f82f79d..ed2c63812c2ab984f8197ad00a88b8ea9292a8a1 100644 (file)
@@ -54,7 +54,7 @@ export {
   getDefaultValue,
 } from './apiCreateFor'
 export { createTemplateRefSetter } from './apiTemplateRef'
-export { vaporUseCssVars } from './helpers/useCssVars'
+export { useVaporCssVars } from './helpers/useCssVars'
 export { createDynamicComponent } from './apiCreateDynamicComponent'
 export { applyVShow } from './directives/vShow'
 export {