Skip to content

Commit 5366aeb

Browse files
committed
移除 useViewTransition 函数封装
1 parent 9ce9f36 commit 5366aeb

File tree

4 files changed

+43
-50
lines changed

4 files changed

+43
-50
lines changed

src/assets/styles/globals.css

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/* 页面布局 CSS 变量 */
22
:root {
3+
color-scheme: light;
4+
35
/* 头部高度 */
46
--g-header-height: 60px;
57

@@ -16,42 +18,44 @@
1618

1719
/* 工具栏高度 */
1820
--g-toolbar-height: 50px;
21+
22+
/* 滚动条颜色 */
23+
--scrollbar-color: 240 5.9% 90%;
24+
25+
&.dark {
26+
color-scheme: dark;
27+
28+
--scrollbar-color: 240 3.7% 15.9%;
29+
}
1930
}
2031

2132
/* 明暗模式 CSS 变量 */
22-
/* stylelint-disable-next-line no-duplicate-selectors */
23-
:root {
24-
color-scheme: light;
33+
::view-transition-old(root),
34+
::view-transition-new(root) {
35+
mix-blend-mode: normal;
36+
animation: none;
37+
}
2538

26-
&::view-transition-old(root),
27-
&::view-transition-new(root) {
28-
mix-blend-mode: normal;
29-
animation: none;
30-
}
39+
::view-transition-old(root) {
40+
z-index: 0;
41+
}
3142

43+
::view-transition-new(root) {
44+
z-index: 1;
45+
}
46+
47+
.dark {
3248
&::view-transition-old(root) {
3349
z-index: 1;
3450
}
3551

3652
&::view-transition-new(root) {
37-
z-index: 9999;
38-
}
39-
40-
&.dark {
41-
color-scheme: dark;
42-
43-
&::view-transition-old(root) {
44-
z-index: 9999;
45-
}
46-
47-
&::view-transition-new(root) {
48-
z-index: 1;
49-
}
53+
z-index: 0;
5054
}
5155
}
5256

5357
* {
54-
scrollbar-color: hsl(var(--border)) transparent;
58+
scrollbar-color: hsl(var(--scrollbar-color)) transparent;
5559
scrollbar-width: thin;
5660
}
5761

src/layouts/components/Topbar/Toolbar/ColorScheme/index.vue

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,33 @@ defineOptions({
88
const settingsStore = useSettingsStore()
99
1010
function toggleColorScheme(event: MouseEvent) {
11-
const { startViewTransition } = useViewTransition(() => {
11+
if (!document.startViewTransition || window.matchMedia('(prefers-reduced-motion: reduce)').matches) {
1212
settingsStore.currentColorScheme && settingsStore.setColorScheme(settingsStore.currentColorScheme === 'dark' ? 'light' : 'dark')
13+
return
14+
}
15+
const x = event.clientX
16+
const y = event.clientY
17+
const endRadius = Math.hypot(
18+
Math.max(x, innerWidth - x),
19+
Math.max(y, innerHeight - y),
20+
)
21+
const transition = document.startViewTransition(async () => {
22+
settingsStore.currentColorScheme && settingsStore.setColorScheme(settingsStore.currentColorScheme === 'dark' ? 'light' : 'dark')
23+
await nextTick()
1324
})
14-
startViewTransition()?.ready.then(() => {
15-
const x = event.clientX
16-
const y = event.clientY
17-
const endRadius = Math.hypot(
18-
Math.max(x, innerWidth - x),
19-
Math.max(y, innerHeight - y),
20-
)
25+
transition.ready.then(() => {
2126
const clipPath = [
2227
`circle(0px at ${x}px ${y}px)`,
2328
`circle(${endRadius}px at ${x}px ${y}px)`,
2429
]
2530
document.documentElement.animate(
2631
{
27-
clipPath: settingsStore.settings.app.colorScheme !== 'dark' ? clipPath : clipPath.reverse(),
32+
clipPath: settingsStore.currentColorScheme === 'light' ? clipPath : clipPath.reverse(),
2833
},
2934
{
30-
duration: 300,
31-
easing: 'ease-out',
32-
pseudoElement: settingsStore.settings.app.colorScheme !== 'dark' ? '::view-transition-new(root)' : '::view-transition-old(root)',
35+
duration: 500,
36+
easing: 'ease-in-out',
37+
pseudoElement: settingsStore.currentColorScheme === 'light' ? '::view-transition-new(root)' : '::view-transition-old(root)',
3338
},
3439
)
3540
})

src/types/auto-imports.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ declare global {
8080
const useSlots: typeof import('vue')['useSlots']
8181
const useTabbar: typeof import('../utils/composables/useTabbar')['default']
8282
const useTemplateRef: typeof import('vue')['useTemplateRef']
83-
const useViewTransition: typeof import('../utils/composables/useViewTransition')['default']
8483
const watch: typeof import('vue')['watch']
8584
const watchEffect: typeof import('vue')['watchEffect']
8685
const watchPostEffect: typeof import('vue')['watchPostEffect']

src/utils/composables/useViewTransition.ts

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)