1
1
<script setup lang="ts">
2
2
import { useEventListener , useVirtualList } from ' @vueuse/core'
3
3
import { computed , ref , watchEffect } from ' vue'
4
+ import type { SlideRoute } from ' @slidev/types'
4
5
import { breakpoints , showOverview , windowSize } from ' ../state'
5
6
import { currentOverviewPage , overviewRowCount } from ' ../logic/overview'
6
7
import { createFixedClicks } from ' ../composables/useClicks'
@@ -23,51 +24,45 @@ function go(page: number) {
23
24
close ()
24
25
}
25
26
26
- function focus(page : number ) {
27
- if (page === currentOverviewPage .value )
28
- return true
29
- return false
30
- }
31
-
32
27
const xs = breakpoints .smaller (' xs' )
33
28
const sm = breakpoints .smaller (' sm' )
34
29
35
- const padding = 4 * 16 * 2
36
- const gap = 2 * 16
30
+ const paddingX = 4 * 16 * 2 // px-16
31
+ const gapX = 2 * 16
32
+ const gapY = 4 * 8 // mb-8
33
+
37
34
const cardWidth = computed (() => {
38
35
if (xs .value )
39
- return windowSize .width .value - padding
36
+ return windowSize .width .value - paddingX
40
37
else if (sm .value )
41
- return (windowSize .width .value - padding - gap ) / 2
38
+ return (windowSize .width .value - paddingX - gapX ) / 2
42
39
return 300
43
40
})
44
41
45
42
const cardHeight = computed (() => cardWidth .value / slideAspect .value )
46
43
47
- const rowCount = computed (() => {
48
- return Math .floor ((windowSize .width .value - padding ) / (cardWidth .value + 2 * gap ))
44
+ const numOfCols = computed (() => {
45
+ return Math .floor ((windowSize .width .value - paddingX ) / (cardWidth .value + 2 * gapX ))
49
46
})
50
47
51
48
const numOfRows = computed (() => {
52
- return Math .ceil (slides .value .length / rowCount .value )
49
+ return Math .ceil (slides .value .length / numOfCols .value )
53
50
})
54
51
55
52
const slideRows = computed (() => {
56
- const cols = rowCount .value
57
- const slideRows = []
53
+ const cols = numOfCols .value
54
+ const rows : {route : SlideRoute , idx : number }[][] = []
58
55
for (let i = 0 ; i < numOfRows .value ; i ++ ) {
59
56
const row = slides .value .slice (i * cols , (i + 1 ) * cols )
60
- slideRows .push (row .map ((route , j ) => ({ route , idx: i * cols + j })))
57
+ rows .push (row .map ((route , j ) => ({ route , idx: i * cols + j })))
61
58
}
62
- return slideRows
59
+ return rows
63
60
})
64
61
65
62
const { list : vList, containerProps, wrapperProps } = useVirtualList (
66
63
slideRows ,
67
64
{
68
- itemHeight: cardHeight .value + gap ,
69
- itemWidth: (cardWidth .value + gap ) * rowCount .value ,
70
- overscan: 3 ,
65
+ itemHeight: cardHeight .value + gapY ,
71
66
},
72
67
)
73
68
@@ -121,7 +116,7 @@ watchEffect(() => {
121
116
// we focus on the right page.
122
117
currentOverviewPage .value = currentSlideNo .value
123
118
// Watch rowCount, make sure up and down shortcut work correctly.
124
- overviewRowCount .value = rowCount .value
119
+ overviewRowCount .value = numOfCols .value
125
120
})
126
121
127
122
const activeSlidesLoaded = ref (false )
@@ -141,7 +136,7 @@ setTimeout(() => {
141
136
v-if =" showOverview || activeSlidesLoaded"
142
137
v-show =" showOverview"
143
138
v-bind =" containerProps"
144
- class =" fixed left-0 right-0 top-0 h-[calc(var(--vh,1vh)*100)] z-20 bg-main !bg-opacity-75 p -16 py-20 overflow-y-auto backdrop-blur-5px"
139
+ class =" fixed left-0 right-0 top-0 h-[calc(var(--vh,1vh)*100)] z-20 bg-main !bg-opacity-75 px -16 py-20 overflow-y-auto backdrop-blur-5px"
145
140
@click =" close"
146
141
>
147
142
<div v-bind =" wrapperProps" >
@@ -157,7 +152,7 @@ setTimeout(() => {
157
152
>
158
153
<div
159
154
class =" inline-block border rounded overflow-hidden bg-main hover:border-primary transition"
160
- :class =" (focus(idx + 1) || currentOverviewPage === idx + 1) ? 'border-primary' : 'border-main'"
155
+ :class =" currentOverviewPage === idx + 1 ? 'border-primary' : 'border-main'"
161
156
@click =" go(route.no)"
162
157
>
163
158
<SlideContainer
0 commit comments