返回 slidev
ThemeInfo.vue
根目录 / docs / .vitepress / theme / components / ThemeInfo.vue
1 <script setup lang="ts">
2 import type { ThemeInfo } from '../../themes'
3 import { isClient, useIntervalFn } from '@vueuse/core'
4 import { ref } from 'vue'
5
6 const props = defineProps<{
7 theme: ThemeInfo
8 }>()
9
10 const index = ref(0)
11
12 if (props.theme.previews.length > 1 && isClient) {
13 const { resume } = useIntervalFn(() => {
14 index.value = (index.value + 1) % props.theme.previews.length
15 }, 3000, { immediate: false })
16 // add random defer so they don't starts together
17 setTimeout(resume, Math.round(1000 * Math.random()))
18 }
19 </script>
20
21 <template>
22 <div>
23 <a
24 :href="theme.link || theme.repo"
25 target="_blank"
26 class="block mb-1.5 w-full overflow-hidden relative aspect-16/9 transition duration-300"
27 border="~ rounded gray-400 opacity-20"
28 hover="shadow-xl"
29 >
30 <img
31 v-for="url, idx in theme.previews"
32 :key="idx"
33 :src="url"
34 class="absolute top-0 bottom-0 left-0 right-0 transition-transform transform duration-500"
35 :style="{ transform: idx > index ? 'scale(1.05) translate(110%)' : 'scale(1.05) translate(0)' }"
36 loading="lazy"
37 >
38 </a>
39 <a :href="theme.link || theme.repo" class="font-bold !text-$vp-c-text-1 !decoration-none">
40 {{ theme.name }}
41 </a>
42 <div
43 class="text-current text-xs opacity-75 whitespace-nowrap overflow-hidden text-ellipsis"
44 :title="theme.description"
45 >
46 {{ theme.description }}
47 </div>
48 <div class="mt-2 flex">
49 <a
50 v-if="theme.author?.link"
51 :href="theme.author.link"
52 class="text-current text-sm opacity-60 hover:opacity-100"
53 target="_blank"
54 >{{ theme.author.name }}</a>
55 <div v-else-if="theme.author?.name" class="text-current text-sm opacity-60 hover:opacity-100">
56 {{ theme.author.name }}
57 </div>
58 <div class="flex-auto" />
59 <a
60 v-if="theme.id"
61 :href="`https://npmjs.com/package/${theme.id}`"
62 class="ml-2 text-current opacity-40 text-sm hover:opacity-100"
63 target="_blank"
64 >
65 <simple-icons-npm />
66 </a>
67 <a
68 v-if="theme.repo"
69 :href="theme.repo"
70 class="ml-2 text-current opacity-40 text-sm hover:opacity-100"
71 target="_blank"
72 >
73 <simple-icons-github />
74 </a>
75 </div>
76 </div>
77 </template>
78
78 lines Plain Text