MCPcopy
hub / github.com/xiaolin/react-image-gallery / computeTargetDisplayIndex

Function computeTargetDisplayIndex

src/components/utils/swipe.ts:113–131  ·  view source on GitHub ↗
(
  slideTo: number,
  totalSlides: number,
  totalDisplaySlides: number,
  infinite: boolean
)

Source from the content-addressed store, hash-verified

111 * Mirrors the logic in slideToIndexCore from useGalleryNavigation.
112 */
113export function computeTargetDisplayIndex(
114 slideTo: number,
115 totalSlides: number,
116 totalDisplaySlides: number,
117 infinite: boolean
118): number {
119 const slideCount = totalSlides - 1;
120
121 if (slideTo < 0) {
122 // Wrapping start (going past first slide)
123 return 0;
124 }
125 if (slideTo > slideCount) {
126 // Wrapping end (going past last slide)
127 return infinite && totalSlides > 1 ? totalDisplaySlides - 1 : slideCount;
128 }
129 // Normal navigation
130 return infinite && totalSlides > 1 ? slideTo + 1 : slideTo;
131}
132
133/**
134 * Computes the CSS transition duration based on the swipe velocity,

Callers 2

ImageGallery.tsxFile · 0.90
swipe.test.tsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected