Skip to content

Commit f150771

Browse files
committed
✨ refactor: add view-transitions typings and allow to import vue components
1 parent 206bf7d commit f150771

File tree

3 files changed

+19
-14
lines changed

3 files changed

+19
-14
lines changed

docs/.vitepress/global.d.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// ![INFO] add types because view-transitions-api is experimental - https://developer.mozilla.org/en-US/docs/Web/API/Document/startViewTransition
2+
/// <reference types="view-transitions-api-types" />
3+
4+
// [INFO] allow to import vue components - https://stackoverflow.com/questions/42002394/importing-vue-components-in-typescript-file
5+
declare module '*.vue' {
6+
import { DefineComponent } from 'vue'
7+
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types
8+
const component: DefineComponent<{}, {}, any>
9+
export default component
10+
}

docs/.vitepress/theme/index.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
// https://vitepress.dev/guide/custom-theme
2-
import { h } from 'vue'
32
import DefaultTheme from 'vitepress/theme'
4-
// @ts-ignore
5-
import Layout from '../../.vitepress/theme/layout.vue'
3+
import Layout from './layout.vue'
64
import './custom.css'
5+
import { Theme } from 'vitepress'
76

87
export default {
98
extends: DefaultTheme,
109
Layout
11-
}
10+
} satisfies Theme

docs/.vitepress/theme/layout.vue

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<script setup lang="ts">
2+
3+
24
import DefaultTheme from 'vitepress/theme'
35
import { nextTick, provide } from 'vue'
46
@@ -18,7 +20,6 @@ provide('toggle-appearance', async ({ clientX: x, clientY: y }: MouseEvent) => {
1820
darkTheme.value = !darkTheme.value
1921
return
2022
}
21-
2223
const clipPath = [
2324
`circle(0px at ${x}px ${y}px)`,
2425
`circle(${Math.hypot(
@@ -27,8 +28,7 @@ provide('toggle-appearance', async ({ clientX: x, clientY: y }: MouseEvent) => {
2728
)}px at ${x}px ${y}px)`
2829
]
2930
30-
// @ts-ignore
31-
await document.startViewTransition(async () => {
31+
if (document.startViewTransition !== undefined) await document.startViewTransition(async () => {
3232
darkTheme.value = !darkTheme.value
3333
await nextTick()
3434
}).ready
@@ -38,9 +38,8 @@ provide('toggle-appearance', async ({ clientX: x, clientY: y }: MouseEvent) => {
3838
{
3939
duration: 300,
4040
easing: 'ease-in',
41-
pseudoElement: `::view-transition-${
42-
isDark.value ? 'old' : 'new'
43-
}(root)`
41+
pseudoElement: `::view-transition-${isDark.value ? 'old' : 'new'
42+
}(root)`
4443
}
4544
)
4645
})
@@ -49,10 +48,7 @@ provide('toggle-appearance', async ({ clientX: x, clientY: y }: MouseEvent) => {
4948
<template>
5049
<DefaultTheme.Layout>
5150
<template #doc-top>
52-
<Ray
53-
class="h-[220px] top-0 left-0 z-[100] opacity-25 dark:opacity-[.55] pointer-events-none"
54-
static
55-
/>
51+
<Ray class="h-[220px] top-0 left-0 z-[100] opacity-25 dark:opacity-[.55] pointer-events-none" static />
5652
</template>
5753
</DefaultTheme.Layout>
5854
</template>

0 commit comments

Comments
 (0)