From f03a6d0cbe44b45cd6575acccdecfeb0710ed38d Mon Sep 17 00:00:00 2001 From: Vadim Date: Fri, 10 Sep 2021 20:21:28 +0300 Subject: [PATCH] #69 : Rename --- src/components/Carousel/Carousel.svelte | 25 +++++++++++++++---------- src/utils/page.js | 12 ++++++------ 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/components/Carousel/Carousel.svelte b/src/components/Carousel/Carousel.svelte index 7458996..bb65908 100644 --- a/src/components/Carousel/Carousel.svelte +++ b/src/components/Carousel/Carousel.svelte @@ -17,18 +17,20 @@ applyParticleSizes, getCurrentPageIndex, getPartialPageSize, - getPagesCount, + getPagesCountByParticlesCount, getParticleIndexByPageIndex, } from '../../utils/page' import { getClones, applyClones, - getPagesCountWithoutClones, getClonesCount, } from '../../utils/clones' import { getAdjacentIndexes, } from '../../utils/lazy' + import { + getValueInRange, + } from '../../utils/math' import { get } from '../../utils/object' import { ProgressManager } from '../../utils/ProgressManager' import { wait } from '../../utils/interval' @@ -164,10 +166,10 @@ $: dispatch('pageChange', currentPageIndex) let particlesCount = 0 - let pagesCountWithoutClones = 1 - $: pagesCount = getPagesCount({ + let particlesCountWithoutClones = 1 + $: pagesCount = getPagesCountByParticlesCount({ infinite, - pagesCountWithoutClones, + particlesCountWithoutClones, particlesToScroll, }) @@ -203,7 +205,7 @@ infinite, pageIndex: currentPageIndex, pagesCount, - particlesCount: pagesCountWithoutClones, + particlesCount: particlesCountWithoutClones, particlesToShow, particlesToScroll, }).particleIndexes @@ -271,18 +273,21 @@ })) cleanupFns.push(() => progressManager.reset()) if (particlesContainer && pageWindowElement) { - pagesCountWithoutClones = particlesContainer.children.length + particlesCountWithoutClones = particlesContainer.children.length + + particlesToShow = getValueInRange(1, particlesToShow, particlesCountWithoutClones) + particlesToScroll = getValueInRange(1, particlesToScroll, particlesCountWithoutClones) + initialPageIndex = getValueInRange(0, initialPageIndex, particlesCountWithoutClones - 1) partialPageSize = getPartialPageSize({ particlesToScroll, particlesToShow, - pagesCountWithoutClones, + particlesCountWithoutClones, }) await tick() infinite && addClones() - // TODO: validate initialPageIndex store.init(getParticleIndexByPageIndex({ infinite, pageIndex: initialPageIndex, @@ -482,7 +487,7 @@