11<script setup lang="ts">
22import { useEventListener , useVirtualList } from ' @vueuse/core'
33import { computed , ref , watchEffect } from ' vue'
4+ import type { SlideRoute } from ' @slidev/types'
45import { breakpoints , showOverview , windowSize } from ' ../state'
56import { currentOverviewPage , overviewRowCount } from ' ../logic/overview'
67import { createFixedClicks } from ' ../composables/useClicks'
@@ -23,51 +24,45 @@ function go(page: number) {
2324 close ()
2425}
2526
26- function focus(page : number ) {
27- if (page === currentOverviewPage .value )
28- return true
29- return false
30- }
31-
3227const xs = breakpoints .smaller (' xs' )
3328const sm = breakpoints .smaller (' sm' )
3429
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+
3734const cardWidth = computed (() => {
3835 if (xs .value )
39- return windowSize .width .value - padding
36+ return windowSize .width .value - paddingX
4037 else if (sm .value )
41- return (windowSize .width .value - padding - gap ) / 2
38+ return (windowSize .width .value - paddingX - gapX ) / 2
4239 return 300
4340})
4441
4542const cardHeight = computed (() => cardWidth .value / slideAspect .value )
4643
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 ))
4946})
5047
5148const numOfRows = computed (() => {
52- return Math .ceil (slides .value .length / rowCount .value )
49+ return Math .ceil (slides .value .length / numOfCols .value )
5350})
5451
5552const slideRows = computed (() => {
56- const cols = rowCount .value
57- const slideRows = []
53+ const cols = numOfCols .value
54+ const rows : {route : SlideRoute , idx : number }[][] = []
5855 for (let i = 0 ; i < numOfRows .value ; i ++ ) {
5956 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 })))
6158 }
62- return slideRows
59+ return rows
6360})
6461
6562const { list : vList, containerProps, wrapperProps } = useVirtualList (
6663 slideRows ,
6764 {
68- itemHeight: cardHeight .value + gap ,
69- itemWidth: (cardWidth .value + gap ) * rowCount .value ,
70- overscan: 3 ,
65+ itemHeight: cardHeight .value + gapY ,
7166 },
7267)
7368
@@ -121,7 +116,7 @@ watchEffect(() => {
121116 // we focus on the right page.
122117 currentOverviewPage .value = currentSlideNo .value
123118 // Watch rowCount, make sure up and down shortcut work correctly.
124- overviewRowCount .value = rowCount .value
119+ overviewRowCount .value = numOfCols .value
125120})
126121
127122const activeSlidesLoaded = ref (false )
@@ -141,7 +136,7 @@ setTimeout(() => {
141136 v-if =" showOverview || activeSlidesLoaded"
142137 v-show =" showOverview"
143138 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"
145140 @click =" close"
146141 >
147142 <div v-bind =" wrapperProps" >
@@ -157,7 +152,7 @@ setTimeout(() => {
157152 >
158153 <div
159154 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'"
161156 @click =" go(route.no)"
162157 >
163158 <SlideContainer
0 commit comments