You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.2 KiB
44 lines
1.2 KiB
import type { ItemCoords } from '../types'
|
|
|
|
export const getShiftIndex = (itemsInSlide = 0, itemsOffset = 0) => itemsInSlide + itemsOffset
|
|
|
|
export const getStartIndex = (index = 0, itemsCount = 0) => {
|
|
if (itemsCount) {
|
|
if (index >= itemsCount) {
|
|
return itemsCount - 1
|
|
}
|
|
|
|
if (index > 0) {
|
|
return index
|
|
}
|
|
}
|
|
|
|
return 0
|
|
}
|
|
|
|
export const getActiveIndex = ({
|
|
infinite = false,
|
|
itemsCount = 0,
|
|
startIndex = 0,
|
|
}) => (infinite ? startIndex : getStartIndex(startIndex, itemsCount))
|
|
|
|
export const getUpdateSlidePositionIndex = (activeIndex: number, itemsCount: number) => {
|
|
if (activeIndex < 0) return itemsCount - 1
|
|
if (activeIndex >= itemsCount) return 0
|
|
|
|
return activeIndex
|
|
}
|
|
|
|
export const shouldRecalculateSlideIndex = (activeIndex: number, itemsCount: number) => (
|
|
activeIndex < 0 || activeIndex >= itemsCount
|
|
)
|
|
|
|
export const shouldCancelSlideAnimation = (activeIndex: number, itemsCount: number) => (
|
|
activeIndex < 0 || activeIndex >= itemsCount
|
|
)
|
|
|
|
export const getTransformationItemIndex = (
|
|
transformationSet: Array<ItemCoords> = [],
|
|
position = 0,
|
|
) => transformationSet.findIndex((item) => item.position >= Math.abs(position))
|
|
|
|
|