Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions src/components/Carousel/Carousel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -702,13 +702,17 @@
let accumulatedSize = 0
let index = 0 - clonedSlidesCount.value.before
const offset = Math.abs(scrolledOffset.value + clonedSlidesOffset.value)
let iterations = 0
const maxIterations = slides.length * 2

Check warning on line 706 in src/components/Carousel/Carousel.ts

View workflow job for this annotation

GitHub Actions / coverage-report

These lines are not covered by a test

while (accumulatedSize <= offset) {
while (accumulatedSize <= offset && iterations < maxIterations) {
const normalizedIndex =
((index % slides.length) + slides.length) % slides.length
accumulatedSize +=
slidesRect.value[normalizedIndex]?.[dimension.value] + config.gap
const slideSize = slidesRect.value[normalizedIndex]?.[dimension.value] || 0
if (slideSize <= 0) break
accumulatedSize += slideSize + config.gap

Check warning on line 713 in src/components/Carousel/Carousel.ts

View workflow job for this annotation

GitHub Actions / coverage-report

These lines are not covered by a test
index++
iterations++

Check warning on line 715 in src/components/Carousel/Carousel.ts

View workflow job for this annotation

GitHub Actions / coverage-report

This line is not covered by a test
}
minIndex = index - 1
}
Expand All @@ -717,6 +721,9 @@
{
let index = minIndex
let accumulatedSize = 0
let iterations = 0
const maxIterations = slides.length * 2

Check warning on line 725 in src/components/Carousel/Carousel.ts

View workflow job for this annotation

GitHub Actions / coverage-report

These lines are not covered by a test

if (index < 0) {
accumulatedSize =
slidesRect.value
Expand All @@ -731,12 +738,14 @@
Math.abs(scrolledOffset.value)
}

while (accumulatedSize < viewportRect.value[dimension.value]) {
while (accumulatedSize < viewportRect.value[dimension.value] && iterations < maxIterations) {
const normalizedIndex =
((index % slides.length) + slides.length) % slides.length
accumulatedSize +=
slidesRect.value[normalizedIndex]?.[dimension.value] + config.gap
const slideSize = slidesRect.value[normalizedIndex]?.[dimension.value] || 0
if (slideSize <= 0) break
accumulatedSize += slideSize + config.gap

Check warning on line 746 in src/components/Carousel/Carousel.ts

View workflow job for this annotation

GitHub Actions / coverage-report

These lines are not covered by a test
index++
iterations++

Check warning on line 748 in src/components/Carousel/Carousel.ts

View workflow job for this annotation

GitHub Actions / coverage-report

This line is not covered by a test
}
maxIndex = index - 1
}
Expand Down
2 changes: 1 addition & 1 deletion src/composables/useDrag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@

const moveEvent = isTouch ? 'touchmove' : 'mousemove'
const endEvent = isTouch ? 'touchend' : 'mouseup'
document.addEventListener(moveEvent, handleDrag, { passive: false })
document.addEventListener(moveEvent, handleDrag, { passive: isTouch })

Check warning on line 57 in src/composables/useDrag.ts

View workflow job for this annotation

GitHub Actions / coverage-report

This line is not covered by a test
document.addEventListener(endEvent, handleDragEnd, { passive: true })

options.onDragStart?.()
Expand Down
6 changes: 4 additions & 2 deletions src/utils/calculateAverage.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
export function calculateAverage(numbers: number[]) {
if (numbers.length === 0) return 0
const sum = numbers.reduce((acc, num) => acc + num, 0)
return sum / numbers.length
const validNumbers = numbers.filter(num => typeof num === 'number' && !isNaN(num) && isFinite(num))
if (validNumbers.length === 0) return 0
const sum = validNumbers.reduce((acc, num) => acc + num, 0)
return sum / validNumbers.length
}