diff --git a/src/components/Carousel/Carousel.svelte b/src/components/Carousel/Carousel.svelte index 4acc138..5880e58 100644 --- a/src/components/Carousel/Carousel.svelte +++ b/src/components/Carousel/Carousel.svelte @@ -264,7 +264,8 @@ await tick() infinite && addClones() - store.init(initialPageIndex + clonesCount.head) + // TODO: validate initialPageIndex, initialPageIndex is an initialScrollIndex + store.init(initialPageIndex * pagesToScroll + clonesCount.head) initPageSizes() } diff --git a/src/utils/page.js b/src/utils/page.js index ac14ff3..6a531ef 100644 --- a/src/utils/page.js +++ b/src/utils/page.js @@ -5,7 +5,12 @@ export function getNextPageIndexLimited({ clonesCountTail, }) { if (pagesCount < 1) throw new Error('pagesCount must be at least 1') - return Math.min(Math.max(currentPageIndex + pagesToScroll, 0), pagesCount - 1) + return Math.min( + Math.max(currentPageIndex + + Math.min(pagesCount - clonesCountTail - currentPageIndex, pagesToScroll), + 0), + pagesCount - 1 + ) } export function getNextPageIndexInfinte({ @@ -29,7 +34,12 @@ export function getPrevPageIndexLimited({ pagesToScroll, }) { if (pagesCount < 1) throw new Error('pagesCount must be at least 1') - return Math.max(Math.min(currentPageIndex - pagesToScroll, pagesCount - 1), 0) + return Math.max( + Math.min( + currentPageIndex - Math.min(currentPageIndex, pagesToScroll), + pagesCount - 1 + ), + 0) } export function getPrevPageIndexInfinte({