@sugarat/theme 0.2.18 → 0.2.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sugarat/theme",
3
- "version": "0.2.18",
3
+ "version": "0.2.20",
4
4
  "description": "简约风的 Vitepress 博客主题,sugarat vitepress blog theme",
5
5
  "author": "sugar",
6
6
  "license": "MIT",
@@ -42,9 +42,10 @@
42
42
  "gray-matter": "^4.0.3",
43
43
  "markdown-it-task-checkbox": "^1.0.6",
44
44
  "mermaid": "^10.2.4",
45
+ "swiper": "^11.0.5",
45
46
  "vitepress-markdown-timeline": "^1.2.1",
46
47
  "vitepress-plugin-mermaid": "2.0.13",
47
- "vitepress-plugin-pagefind": "0.2.10",
48
+ "vitepress-plugin-pagefind": "0.2.11",
48
49
  "vitepress-plugin-rss": "0.2.1",
49
50
  "vitepress-plugin-tabs": "0.2.0"
50
51
  },
@@ -1,7 +1,8 @@
1
1
  <script lang="ts" setup>
2
2
  import { ElAvatar } from 'element-plus'
3
- import { useDark } from '@vueuse/core'
4
- import { computed } from 'vue'
3
+ import { useDark, useIntervalFn } from '@vueuse/core'
4
+ import { computed, onMounted, onUnmounted, ref } from 'vue'
5
+ import Swiper from 'swiper'
5
6
  import { useBlogConfig } from '../composables/config/blog'
6
7
  import { getImageUrl, shuffleArray } from '../utils/client'
7
8
  import type { Theme } from '../'
@@ -18,7 +19,6 @@ const friendConfig = computed<Theme.FriendConfig>(() => ({
18
19
  ...(Array.isArray(friend) ? { list: friend } : friend)
19
20
  }))
20
21
 
21
- // TODO: 待优化
22
22
  const limit = computed(() => {
23
23
  const { limit } = friendConfig.value
24
24
  return (!limit || limit <= 0) ? 0 : limit || Number.MAX_SAFE_INTEGER
@@ -26,7 +26,7 @@ const limit = computed(() => {
26
26
 
27
27
  const scrollSpeed = computed(() => {
28
28
  const { scrollSpeed } = friendConfig.value
29
- return (!scrollSpeed || scrollSpeed <= 0) ? (friendConfig.value.list.length - 1) * (friendConfig.value.list.length / limit.value) * 1000 : scrollSpeed
29
+ return scrollSpeed ?? 1500
30
30
  })
31
31
 
32
32
  const openScroll = computed(() => {
@@ -58,18 +58,37 @@ const friendList = computed(() => {
58
58
  alt
59
59
  }
60
60
  })
61
- return openScroll.value ? [...list, ...list] : list
61
+ return list
62
62
  })
63
63
 
64
- const cardHeight = 83
64
+ const cardHeight = 76
65
65
  const scrollWrapperHeight = computed(() => {
66
66
  return openScroll.value ? limit.value * cardHeight : 0
67
67
  })
68
68
  const containerHeight = computed(() => {
69
69
  return scrollWrapperHeight.value ? `${scrollWrapperHeight.value}px` : 'auto'
70
70
  })
71
- const scrollTop = computed(() => {
72
- return `-${scrollWrapperHeight.value * 2}px`
71
+
72
+ const swiper = ref<Swiper>()
73
+ const { resume, pause } = useIntervalFn(() => {
74
+ swiper.value?.slideNext()
75
+ }, scrollSpeed.value)
76
+
77
+ onMounted(() => {
78
+ pause()
79
+ if (openScroll.value) {
80
+ // eslint-disable-next-line no-new
81
+ swiper.value = new Swiper('.scroll-wrapper', {
82
+ direction: 'vertical',
83
+ slidesPerView: limit.value,
84
+ loop: true,
85
+ })
86
+ resume()
87
+ }
88
+ })
89
+
90
+ onUnmounted(() => {
91
+ pause()
73
92
  })
74
93
  </script>
75
94
 
@@ -102,17 +121,11 @@ const scrollTop = computed(() => {
102
121
  height: containerHeight,
103
122
  }"
104
123
  >
105
- <ol
106
- class="friend-list" :style="{
107
- animationPlayState: openScroll ? 'running' : 'paused',
108
- animationDuration: `${scrollSpeed / 1000}s`,
109
- }
110
- "
111
- >
112
- <li v-for="(v, idx) in friendList" :key="idx">
124
+ <ol class="friend-list swiper-wrapper">
125
+ <li v-for=" (v, idx) in friendList" :key="idx" class="swiper-slide">
113
126
  <a :href="v.url" target="_blank">
114
127
  <ElAvatar :size="50" :src="v.avatar" :alt="v.alt" />
115
- <div>
128
+ <div class="info-wrapper">
116
129
  <span class="nickname">{{ v.nickname }}</span>
117
130
  <p class="des">{{ v.des }}</p>
118
131
  </div>
@@ -159,15 +172,6 @@ const scrollTop = computed(() => {
159
172
  flex-direction: column;
160
173
  }
161
174
 
162
- @keyframes scrollList {
163
- 0% {
164
- top: 0;
165
- }
166
- 100% {
167
- top: v-bind(scrollTop);
168
- }
169
- }
170
-
171
175
  .scroll-wrapper {
172
176
  overflow: hidden;
173
177
  position: relative;
@@ -178,35 +182,35 @@ const scrollTop = computed(() => {
178
182
  flex-direction: column;
179
183
  list-style: none;
180
184
  margin: 0;
181
- padding: 0 10px 0 0px;
185
+ padding: 10px 10px 0 0px;
182
186
  width: 100%;
183
187
 
184
188
  position: relative;
185
189
  width: 100%;
186
- animation-name: scrollList;
187
- animation-timing-function:linear;
188
- animation-iteration-count:infinite;
189
-
190
- &:hover {
191
- animation-play-state: paused !important;
192
- }
193
190
 
194
191
  li {
195
- padding: 6px;
196
- margin-top: 10px;
197
-
192
+ box-sizing: border-box;
193
+ padding: 0 5px;
194
+ height: 76px;
198
195
  .el-avatar {
199
196
  min-width: 50px;
200
197
  }
201
198
 
202
199
  a {
203
200
  display: flex;
201
+ align-items: center;
204
202
  }
205
203
 
206
204
  div {
207
205
  padding-left: 10px;
208
206
  }
209
207
 
208
+ .info-wrapper {
209
+ display: flex;
210
+ flex-direction: column;
211
+ overflow: hidden;
212
+ }
213
+
210
214
  .nickname {
211
215
  font-size: 16px;
212
216
  font-weight: 450;
@@ -215,6 +219,9 @@ const scrollTop = computed(() => {
215
219
  .des {
216
220
  color: var(--vp-c-text-2);
217
221
  font-size: 14px;
222
+ overflow: hidden;
223
+ white-space: nowrap;
224
+ text-overflow: ellipsis;
218
225
  }
219
226
  }
220
227
  }
@@ -353,6 +353,9 @@ function handleSelect(target: any) {
353
353
  justify-content: center;
354
354
  padding: 6px;
355
355
  box-sizing: border-box;
356
+ border: 1px solid transparent;
357
+ border-radius: 6px;
358
+ transition: .2s border;
356
359
 
357
360
  .metaKey {
358
361
  margin-left: 10px;