Skip to content

Commit ecd9cae

Browse files
committed
refactor(vapor): rename vaporUseCssVars to useVaporCssVars and update related references
1 parent ca5715e commit ecd9cae

File tree

5 files changed

+24
-17
lines changed

5 files changed

+24
-17
lines changed

packages/compiler-sfc/src/style/cssVars.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ import {
1010
import type { SFCDescriptor } from '../parse'
1111
import type { PluginCreator } from 'postcss'
1212
import hash from 'hash-sum'
13-
import { capitalize, getEscapedCssVarName } from '@vue/shared'
13+
import { getEscapedCssVarName } from '@vue/shared'
1414

1515
export const CSS_VARS_HELPER = `useCssVars`
1616

1717
export function getCssVarsHelper(vapor: boolean | undefined): string {
18-
return vapor ? `vapor${capitalize(CSS_VARS_HELPER)}` : CSS_VARS_HELPER
18+
return vapor ? `useVaporCssVars` : CSS_VARS_HELPER
1919
}
2020

2121
export function genCssVarsFromList(

packages/runtime-dom/src/helpers/useCssVars.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ function setVarsOnVNode(vnode: VNode, vars: Record<string, string>) {
7171
}
7272
}
7373

74+
/**
75+
* @internal
76+
* shared between vdom and vapor
77+
*/
7478
export function baseUseCssVars(
7579
instance: GenericComponentInstance | null,
7680
getParentNode: () => Node,
@@ -86,7 +90,7 @@ export function baseUseCssVars(
8690
/* v8 ignore stop */
8791

8892
if (__DEV__) {
89-
instance.getCssVars = () => getVars()
93+
instance.getCssVars = getVars
9094
}
9195

9296
const updateTeleports = (instance.ut = (vars = getVars()) => {
@@ -116,6 +120,10 @@ export function baseUseCssVars(
116120
})
117121
}
118122

123+
/**
124+
* @internal
125+
* shared between vdom and vapor
126+
*/
119127
export function setVarsOnNode(el: Node, vars: Record<string, string>): void {
120128
if (el.nodeType === 1) {
121129
const style = (el as HTMLElement).style

packages/runtime-vapor/__tests__/helpers/useCssVars.spec.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ import {
55
renderEffect,
66
setStyle,
77
template,
8-
vaporUseCssVars,
8+
useVaporCssVars,
99
} from '@vue/runtime-vapor'
1010
import { nextTick, onMounted, reactive, ref } from '@vue/runtime-core'
1111
import { makeRender } from '../_utils'
1212
import type { VaporComponent } from '../../src/component'
1313

1414
const define = makeRender()
1515

16-
describe('vaporUseCssVars', () => {
16+
describe('useVaporCssVars', () => {
1717
async function assertCssVars(getApp: (state: any) => VaporComponent) {
1818
const state = reactive({ color: 'red' })
1919
const App = getApp(state)
@@ -35,7 +35,7 @@ describe('vaporUseCssVars', () => {
3535
const t0 = template('<div></div>')
3636
await assertCssVars(state => ({
3737
setup() {
38-
vaporUseCssVars(() => state)
38+
useVaporCssVars(() => state)
3939
const n0 = t0()
4040
return n0
4141
},
@@ -46,7 +46,7 @@ describe('vaporUseCssVars', () => {
4646
const t0 = template('<div></div>')
4747
await assertCssVars(state => ({
4848
setup() {
49-
vaporUseCssVars(() => state)
49+
useVaporCssVars(() => state)
5050
const n0 = t0()
5151
const n1 = t0()
5252
return [n0, n1]
@@ -64,7 +64,7 @@ describe('vaporUseCssVars', () => {
6464
})
6565
await assertCssVars(state => ({
6666
setup() {
67-
vaporUseCssVars(() => state)
67+
useVaporCssVars(() => state)
6868
return createComponent(Child)
6969
},
7070
}))
@@ -82,7 +82,7 @@ describe('vaporUseCssVars', () => {
8282

8383
define({
8484
setup() {
85-
vaporUseCssVars(() => state)
85+
useVaporCssVars(() => state)
8686
const n0 = createIf(
8787
() => value.value,
8888
() => {
@@ -125,7 +125,7 @@ describe('vaporUseCssVars', () => {
125125
const t0 = template('<div></div>')
126126
define({
127127
setup() {
128-
vaporUseCssVars(() => state)
128+
useVaporCssVars(() => state)
129129
return createComponent(Child, null, {
130130
default: () => {
131131
return createIf(
@@ -174,7 +174,7 @@ describe('vaporUseCssVars', () => {
174174

175175
define({
176176
setup() {
177-
vaporUseCssVars(() => state)
177+
useVaporCssVars(() => state)
178178
const n0 = t0() as any
179179
renderEffect(() =>
180180
setStyle(n0, state.color ? 'pointer-events: none' : undefined),
@@ -214,7 +214,7 @@ describe('vaporUseCssVars', () => {
214214

215215
define({
216216
setup() {
217-
vaporUseCssVars(() => state)
217+
useVaporCssVars(() => state)
218218
return createIf(
219219
() => value.value,
220220
() => createComponent(Child),
@@ -246,7 +246,7 @@ describe('vaporUseCssVars', () => {
246246

247247
define({
248248
setup() {
249-
vaporUseCssVars(() => state)
249+
useVaporCssVars(() => state)
250250
onMounted(() => {
251251
colorInOnMount = (
252252
root.children[0] as HTMLElement

packages/runtime-vapor/src/helpers/useCssVars.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@ import { type VaporComponentInstance, isVaporComponent } from '../component'
77
import { isArray } from '@vue/shared'
88
import type { Block } from '../block'
99

10-
export function vaporUseCssVars(getter: () => Record<string, string>): void {
10+
export function useVaporCssVars(getter: () => Record<string, string>): void {
1111
if (!__BROWSER__ && !__TEST__) return
12-
1312
const instance = currentInstance as VaporComponentInstance
1413
baseUseCssVars(
1514
instance,
1615
() => resolveParentNode(instance.block),
17-
() => getter(),
16+
getter,
1817
vars => setVarsOnBlock(instance.block, vars),
1918
)
2019
}

packages/runtime-vapor/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export {
5454
getDefaultValue,
5555
} from './apiCreateFor'
5656
export { createTemplateRefSetter } from './apiTemplateRef'
57-
export { vaporUseCssVars } from './helpers/useCssVars'
57+
export { useVaporCssVars } from './helpers/useCssVars'
5858
export { createDynamicComponent } from './apiCreateDynamicComponent'
5959
export { applyVShow } from './directives/vShow'
6060
export {

0 commit comments

Comments
 (0)