mirror of
https://github.com/Sped0n/bridget.git
synced 2026-04-14 10:09:31 -07:00
Extract image, desktop, mobile, and config state into separate context providers to improve modularity and reduce unnecessary re-renders. Signed-off-by: Sped0n <hi@sped0n.com>
27 lines
620 B
TypeScript
27 lines
620 B
TypeScript
import { type Swiper } from 'swiper'
|
|
|
|
import type { Vector } from '../utils'
|
|
|
|
export async function loadSwiper(): Promise<typeof Swiper> {
|
|
const swiper = await import('swiper')
|
|
return swiper.Swiper
|
|
}
|
|
|
|
export function getActiveImageIndexes(
|
|
currentIndex: number,
|
|
length: number,
|
|
navigateVector: Vector
|
|
): number[] {
|
|
const nextIndex = Math.min(currentIndex + 1, length - 1)
|
|
const prevIndex = Math.max(currentIndex - 1, 0)
|
|
|
|
switch (navigateVector) {
|
|
case 'next':
|
|
return [nextIndex]
|
|
case 'prev':
|
|
return [prevIndex]
|
|
case 'none':
|
|
return [currentIndex, nextIndex, prevIndex]
|
|
}
|
|
}
|