react-spring-carousel 2.0.19 → 3.0.0-beta001

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/dist/cjs/index.js +1 -1
  2. package/dist/cjs/index.js.map +1 -1
  3. package/dist/esm/index.js +1 -1
  4. package/dist/esm/index2.js +1 -1
  5. package/dist/esm/index2.js.map +1 -1
  6. package/dist/esm/useSpringCarousel.js +2 -0
  7. package/dist/esm/useSpringCarousel.js.map +1 -0
  8. package/dist/esm/useThumbsModule-ce69c348.js +2 -0
  9. package/dist/esm/useThumbsModule-ce69c348.js.map +1 -0
  10. package/dist/types/index.d.ts +0 -1
  11. package/dist/types/mockedItems.d.ts +10 -0
  12. package/dist/types/modules/index.d.ts +1 -1
  13. package/dist/types/modules/useEventsModule.d.ts +44 -0
  14. package/dist/types/modules/useFullscreenModule.d.ts +6 -6
  15. package/dist/types/modules/useThumbsModule.d.ts +7 -13
  16. package/dist/types/types/common.d.ts +2 -0
  17. package/dist/types/types/index.d.ts +8 -49
  18. package/dist/types/types/internals.d.ts +82 -0
  19. package/dist/types/useSpringCarousel.d.ts +7 -0
  20. package/dist/umd/index.js +1 -1
  21. package/dist/umd/index.js.map +1 -1
  22. package/package.json +48 -75
  23. package/dist/esm/index3.js +0 -2
  24. package/dist/esm/index3.js.map +0 -1
  25. package/dist/esm/index4.js +0 -2
  26. package/dist/esm/index4.js.map +0 -1
  27. package/dist/esm/useThumbsModule-0944decf.js +0 -2
  28. package/dist/esm/useThumbsModule-0944decf.js.map +0 -1
  29. package/dist/types/modules/useCustomEventsModule.d.ts +0 -5
  30. package/dist/types/types/useSpringCarousel.d.ts +0 -124
  31. package/dist/types/types/useTransitionCarousel.d.ts +0 -39
  32. package/dist/types/useSpringCarousel/index.d.ts +0 -8
  33. package/dist/types/useTransitionCarousel/index.d.ts +0 -24
  34. package/dist/types/utils.d.ts +0 -5
@@ -1 +1 @@
1
- {"version":3,"file":"index2.js","sources":["../../src/useSpringCarousel/index.tsx"],"sourcesContent":["import { useRef, createContext, useContext } from 'react'\nimport { useSpring, config, animated } from 'react-spring'\nimport { useDrag } from '@use-gesture/react'\nimport { useCustomEventsModule, useFullscreenModule, useThumbsModule } from '../modules'\nimport {\n SlideToItemFnProps,\n SlideActionType,\n UseSpringFixedSlideTypeReturnProps,\n} from '../types'\nimport { useIsomorphicLayoutEffect, useIsomorphicMount } from '../utils'\nimport {\n UseSpringCarouselProps,\n ReactSpringCarouselItemWithThumbs,\n UseSpringFluidSlideTypeReturnProps,\n UseSpringCarouselBaseProps,\n UseSpringCarouselWithThumbs,\n UseSpringCarouselFluidType,\n DisableGesturesProps,\n WithLoopProps,\n UseSpringCarouselWithNoThumbs,\n EnableGesturesProps,\n WithNoLoop,\n UseSpringCarouselFixedSlideType,\n} from '../types/useSpringCarousel'\n\ntype ReturnType<T> = T extends 'fixed'\n ? UseSpringFixedSlideTypeReturnProps\n : UseSpringFluidSlideTypeReturnProps\ntype ContextTypes<T> = Omit<ReturnType<T>, 'carouselFragment' | 'thumbsFragment'>\n\nconst Context = createContext<ContextTypes<'fixed' | 'fluid'> | undefined>(undefined)\n\nconst defaultDragSpringConfig = {\n ...config.default,\n mass: 1,\n velocity: 0,\n}\n\nfunction useSpringCarousel(\n props: UseSpringCarouselBaseProps &\n UseSpringCarouselFluidType &\n (UseSpringCarouselWithThumbs | UseSpringCarouselWithNoThumbs) &\n (DisableGesturesProps | EnableGesturesProps) &\n (WithLoopProps | WithNoLoop),\n): ReturnType<'fluid'>\nfunction useSpringCarousel(\n props: UseSpringCarouselBaseProps &\n UseSpringCarouselFixedSlideType &\n (UseSpringCarouselWithThumbs | UseSpringCarouselWithNoThumbs) &\n (DisableGesturesProps | EnableGesturesProps) &\n (WithLoopProps | WithNoLoop),\n): ReturnType<'fixed'>\n\nfunction useSpringCarousel({\n items,\n withLoop = false,\n draggingSlideTreshold,\n springConfig = config.default,\n shouldResizeOnWindowResize = true,\n withThumbs = false,\n enableThumbsWrapperScroll = true,\n slideWhenThresholdIsReached = true,\n carouselSlideAxis = 'x',\n thumbsSlideAxis = 'x',\n prepareThumbsData,\n initialActiveItem = 0,\n initialStartingPosition,\n disableGestures = false,\n gutter = 0,\n startEndGutter = 0,\n touchAction,\n slideAmount,\n freeScroll = false,\n enableFreeScrollDrag,\n itemsPerSlide = 1,\n slideType = 'fixed',\n}: UseSpringCarouselProps): ReturnType<'fixed' | 'fluid'> {\n function getItems() {\n if (withLoop) {\n if (items.length === itemsPerSlide) {\n return [...items, ...items, ...items, ...items, ...items]\n }\n return [...items, ...items, ...items]\n }\n return items\n }\n\n const isFirstMount = useRef(true)\n const slideActionType = useRef<SlideActionType>('initial' as SlideActionType)\n const internalItems = getItems()\n const activeItem = useRef(initialActiveItem)\n const mainCarouselWrapperRef = useRef<HTMLDivElement | null>(null)\n const carouselTrackWrapperRef = useRef<HTMLDivElement | null>(null)\n const isDragging = useRef(false)\n const isAnimating = useRef(false)\n const windowIsHidden = useRef(false)\n const fluidTotalWrapperScrollValue = useRef(0)\n const slideEndReached = useRef(false)\n const currentWindowWidth = useRef(0)\n const initialWindowWidth = useRef(0)\n const prevSlidedValue = useRef(0)\n const prevItems = useRef(items)\n\n /**\n * Instead of raw values, we store it in\n * useRef for performances reasons during external rerenders\n */\n const draggingSlideTresholdRef = useRef<number>(draggingSlideTreshold ?? 0)\n const itemsPerSlideRef = useRef(itemsPerSlide)\n const gutterRef = useRef(gutter)\n const startEndGutterRef = useRef(startEndGutter)\n const initialActiveItemRef = useRef(initialActiveItem)\n const initialStartingPositionRef = useRef(initialStartingPosition)\n const carouselSlideAxisRef = useRef(carouselSlideAxis)\n\n /**\n * Update inner values during external rerenders!\n */\n itemsPerSlideRef.current = itemsPerSlide\n gutterRef.current = gutter\n startEndGutterRef.current = startEndGutter\n initialActiveItemRef.current = initialActiveItem\n initialStartingPositionRef.current = initialStartingPosition\n carouselSlideAxisRef.current = carouselSlideAxis\n\n const [carouselStyles, setCarouselStyles] = useSpring(() => ({\n y: 0,\n x: 0,\n onChange: ({ value }) => {\n if (mainCarouselWrapperRef.current && freeScroll) {\n mainCarouselWrapperRef.current[\n carouselSlideAxisRef.current === 'x' ? 'scrollLeft' : 'scrollTop'\n ] = Math.abs(value[carouselSlideAxisRef.current])\n }\n },\n }))\n\n useIsomorphicLayoutEffect(() => {\n if (draggingSlideTreshold) {\n draggingSlideTresholdRef.current = draggingSlideTreshold\n } else {\n draggingSlideTresholdRef.current = Math.floor(getSlideValue() / 2 / 2)\n }\n\n resize()\n }, [\n draggingSlideTreshold,\n itemsPerSlide,\n gutter,\n startEndGutter,\n initialActiveItem,\n initialStartingPosition,\n carouselSlideAxis,\n thumbsSlideAxis,\n ])\n\n function getCarouselItem() {\n return carouselTrackWrapperRef.current?.querySelector('.use-spring-carousel-item')\n }\n function getMainCarouselWrapperWidth() {\n if (!mainCarouselWrapperRef.current) {\n throw new Error('mainCarouselWrapperRef is not available')\n }\n return mainCarouselWrapperRef.current.getBoundingClientRect()[\n carouselSlideAxisRef.current === 'x' ? 'width' : 'height'\n ]\n }\n function getCarouselItemWidth() {\n const carouselItem = getCarouselItem()\n if (!carouselItem) {\n throw Error('No carousel items available!')\n }\n return (\n carouselItem.getBoundingClientRect()[\n carouselSlideAxisRef.current === 'x' ? 'width' : 'height'\n ] + gutterRef.current\n )\n }\n function getCurrentSlidedValue() {\n return carouselStyles[carouselSlideAxisRef.current].get()\n }\n function getIfItemsNotFillTheCarousel() {\n return getCarouselItemWidth() * items.length < getMainCarouselWrapperWidth()\n }\n function getFluidWrapperScrollValue() {\n return Math.round(\n Number(\n carouselTrackWrapperRef.current?.[\n carouselSlideAxisRef.current === 'x' ? 'scrollWidth' : 'scrollHeight'\n ],\n ) -\n carouselTrackWrapperRef.current!.getBoundingClientRect()[\n carouselSlideAxisRef.current === 'x' ? 'width' : 'height'\n ],\n )\n }\n function getIsFirstItem() {\n return getCurrentActiveItem() === 0\n }\n function getSlideValue() {\n if (!carouselTrackWrapperRef.current) {\n return 0\n }\n const itemVal = getCarouselItemWidth()\n\n if (slideType === 'fluid' && typeof slideAmount === 'number') {\n if (slideAmount < itemVal) {\n throw new Error('slideAmount must be greater than the width of a single item.')\n }\n return slideAmount\n }\n return itemVal\n }\n function adjustCarouselWrapperPosition(\n ref: HTMLDivElement,\n _initialActiveItem?: number,\n ) {\n const positionProperty = carouselSlideAxisRef.current === 'x' ? 'left' : 'top'\n function getDefaultPositionValue() {\n return getCarouselItemWidth() * items.length\n }\n function setPosition(v: number) {\n if (withLoop) {\n ref.style.top = '0px'\n ref.style[positionProperty] = `-${v - startEndGutterRef.current}px`\n } else {\n ref.style.left = '0px'\n ref.style.top = '0px'\n if (_initialActiveItem && isFirstMount.current) {\n ref.style[positionProperty] = `calc(-${_initialActiveItem} * 100%)`\n }\n }\n }\n function setStartPosition() {\n setPosition(getDefaultPositionValue())\n }\n\n if (slideType === 'fixed') {\n function setCenterPosition(i: number) {\n setPosition(\n getDefaultPositionValue() -\n getSlideValue() * Math.round(((i as number) - 1) / 2),\n )\n }\n function setEndPosition(i: number) {\n setPosition(\n getDefaultPositionValue() - getSlideValue() * Math.round((i as number) - 1),\n )\n }\n\n if (itemsPerSlideRef.current > 1) {\n switch (initialStartingPositionRef.current) {\n default:\n case 'start': {\n setStartPosition()\n break\n }\n case 'center': {\n setCenterPosition(itemsPerSlideRef.current)\n break\n }\n case 'end': {\n setEndPosition(itemsPerSlideRef.current)\n break\n }\n }\n } else {\n setStartPosition()\n }\n } else {\n setStartPosition()\n }\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n function resize() {\n currentWindowWidth.current = window.innerWidth\n\n if (slideType === 'fluid') {\n if (getIfItemsNotFillTheCarousel()) {\n setCarouselStyles.start({\n immediate: true,\n [carouselSlideAxisRef.current]: 0,\n })\n return\n }\n fluidTotalWrapperScrollValue.current = getFluidWrapperScrollValue()\n\n if (slideEndReached.current) {\n const nextValue = -fluidTotalWrapperScrollValue.current\n setCarouselStyles.start({\n immediate: true,\n [carouselSlideAxisRef.current]: nextValue,\n })\n }\n\n initialWindowWidth.current = window.innerWidth\n } else {\n setCarouselStyles.start({\n immediate: true,\n [carouselSlideAxisRef.current]: -(getSlideValue() * getCurrentActiveItem()),\n })\n }\n\n fluidTotalWrapperScrollValue.current = getFluidWrapperScrollValue()\n adjustCarouselWrapperPosition(carouselTrackWrapperRef.current!)\n }\n function handleResize() {\n if (window.innerWidth === currentWindowWidth.current || freeScroll) {\n return\n }\n resize()\n }\n // Custom modules\n const { useListenToCustomEvent, emitObservable } = useCustomEventsModule<'use-spring'>()\n const { enterFullscreen, exitFullscreen, getIsFullscreen } =\n useFullscreenModule<'use-spring'>({\n mainCarouselWrapperRef,\n emitObservable,\n handleResize,\n })\n const { thumbsFragment: _thumbsFragment, handleThumbsScroll } = useThumbsModule({\n withThumbs,\n items: items as ReactSpringCarouselItemWithThumbs[],\n thumbsSlideAxis,\n springConfig,\n prepareThumbsData,\n slideType,\n getFluidWrapperScrollValue,\n getSlideValue,\n })\n\n function getWrapperScrollDirection() {\n if (!mainCarouselWrapperRef.current) {\n throw new Error('Missing mainCarouselWrapperRef.current')\n }\n return mainCarouselWrapperRef.current[\n carouselSlideAxisRef.current === 'x' ? 'scrollLeft' : 'scrollTop'\n ]\n }\n function getIfShouldEnableFluidDrag() {\n if (typeof enableFreeScrollDrag === 'boolean') {\n return enableFreeScrollDrag\n } else if (typeof enableFreeScrollDrag === 'function') {\n return enableFreeScrollDrag()\n }\n return false\n }\n\n const bindDrag = useDrag(\n props => {\n const isDragging = props.dragging\n const movement = props.offset[carouselSlideAxisRef.current === 'x' ? 0 : 1]\n const currentMovement = props.movement[carouselSlideAxisRef.current === 'x' ? 0 : 1]\n const prevItemTreshold = currentMovement > draggingSlideTresholdRef.current\n const nextItemTreshold = currentMovement < -draggingSlideTresholdRef.current\n const direction = props.direction[carouselSlideAxisRef.current === 'x' ? 0 : 1]\n function cancelDrag() {\n props.cancel()\n }\n function setDragDirection() {\n if (direction > 0) {\n setSlideActionType('prev')\n } else {\n setSlideActionType('next')\n }\n }\n function emitDragObservable() {\n emitObservable({\n eventName: 'onDrag',\n slideActionType: getSlideActionType(),\n ...props,\n })\n }\n function resetAnimation() {\n if (slideType === 'fluid') {\n if (\n getIfItemsNotFillTheCarousel() ||\n (getIsFirstItem() && getSlideActionType() === 'prev')\n ) {\n setCarouselStyles.start({\n [carouselSlideAxisRef.current]: 0,\n config: {\n velocity: props.velocity,\n ...springConfig,\n },\n })\n } else if (slideEndReached.current && getSlideActionType() === 'next') {\n setCarouselStyles.start({\n [carouselSlideAxisRef.current]: -fluidTotalWrapperScrollValue.current,\n config: {\n velocity: props.velocity,\n ...springConfig,\n },\n })\n } else {\n setCarouselStyles.start({\n [carouselSlideAxisRef.current]: prevSlidedValue.current,\n config: {\n velocity: props.velocity,\n ...springConfig,\n },\n })\n }\n } else {\n setCarouselStyles.start({\n [carouselSlideAxisRef.current]: -(getCurrentActiveItem() * getSlideValue()),\n config: {\n velocity: props.velocity,\n ...springConfig,\n },\n })\n }\n }\n function checkBounds() {\n const nextItemWillExceed =\n Math.abs(getCurrentSlidedValue()) + 100 >= fluidTotalWrapperScrollValue.current\n\n if (nextItemWillExceed && getSlideActionType() === 'next') {\n slideEndReached.current = true\n }\n if (getSlideActionType() === 'prev') {\n slideEndReached.current = false\n }\n }\n\n if (freeScroll && getIfShouldEnableFluidDrag()) {\n if (isDragging) {\n if (!getIsDragging()) {\n setIsDragging(true)\n }\n\n setDragDirection()\n emitDragObservable()\n checkBounds()\n }\n\n setCarouselStyles.start({\n from: {\n [carouselSlideAxisRef.current]: getWrapperScrollDirection(),\n },\n to: {\n [carouselSlideAxisRef.current]: -movement,\n },\n config: {\n velocity: props.velocity,\n friction: 50,\n tension: 1400,\n },\n })\n\n if (getWrapperScrollDirection() === 0 && getSlideActionType() === 'prev') {\n cancelDrag()\n return\n }\n if (props.last) {\n if (getSlideActionType() === 'prev') {\n slideToPrevItem(props.velocity)\n } else {\n slideToNextItem(props.velocity)\n }\n setIsDragging(false)\n }\n return\n }\n\n if (isDragging) {\n if (!getIsDragging()) {\n setIsDragging(true)\n }\n\n emitDragObservable()\n setDragDirection()\n checkBounds()\n\n if (freeScroll) {\n if (getIfShouldEnableFluidDrag()) {\n if (getWrapperScrollDirection() === 0 && getSlideActionType() === 'prev') {\n cancelDrag()\n return\n } else {\n setCarouselStyles.start({\n config: {\n velocity: props.velocity,\n friction: 50,\n tension: 1400,\n },\n from: {\n [carouselSlideAxisRef.current]: getWrapperScrollDirection(),\n },\n to: {\n [carouselSlideAxisRef.current]: -movement,\n },\n })\n }\n }\n return\n } else {\n setCarouselStyles.start({\n [carouselSlideAxisRef.current]: movement,\n config: {\n velocity: props.velocity,\n friction: 50,\n tension: 1000,\n },\n })\n }\n\n if (\n (prevItemTreshold || nextItemTreshold) &&\n getIfItemsNotFillTheCarousel() &&\n slideType === 'fluid'\n ) {\n cancelDrag()\n resetAnimation()\n } else if (\n slideEndReached.current &&\n getSlideActionType() === 'next' &&\n nextItemTreshold\n ) {\n slideEndReached.current = false\n cancelDrag()\n setCarouselStyles.start({\n [carouselSlideAxisRef.current]: -fluidTotalWrapperScrollValue.current,\n })\n } else if (slideWhenThresholdIsReached) {\n if (nextItemTreshold) {\n cancelDrag()\n if (!withLoop && getIsLastItem()) {\n resetAnimation()\n } else {\n slideToNextItem(props.velocity)\n }\n return\n } else if (prevItemTreshold) {\n cancelDrag()\n if (!withLoop && getIsFirstItem()) {\n resetAnimation()\n } else {\n slideToPrevItem(props.velocity)\n }\n return\n }\n }\n }\n\n if (\n props.last &&\n !slideWhenThresholdIsReached &&\n (nextItemTreshold || prevItemTreshold) &&\n !freeScroll\n ) {\n setIsDragging(false)\n if (nextItemTreshold) {\n if (!withLoop && getIsLastItem()) {\n resetAnimation()\n } else {\n slideToNextItem(props.velocity)\n }\n } else if (prevItemTreshold) {\n if (!withLoop && getIsFirstItem()) {\n resetAnimation()\n } else {\n slideToPrevItem(props.velocity)\n }\n }\n return\n }\n\n if (props.last && !nextItemTreshold && !prevItemTreshold) {\n if (!freeScroll) {\n resetAnimation()\n emitObservable({\n eventName: 'onDrag',\n slideActionType: getSlideActionType(),\n ...props,\n })\n }\n }\n },\n {\n enabled: !disableGestures,\n axis: carouselSlideAxisRef.current,\n from: () => {\n if (freeScroll) {\n if (carouselSlideAxisRef.current === 'x') {\n return [-getWrapperScrollDirection(), 0]\n }\n return [0, -getWrapperScrollDirection()]\n }\n return [carouselStyles.x.get(), carouselStyles.y.get()]\n },\n },\n )\n\n function setSlideActionType(type: SlideActionType) {\n slideActionType.current = type\n }\n function getSlideActionType() {\n return slideActionType.current\n }\n function setActiveItem(newItem: number) {\n activeItem.current = newItem\n }\n function getCurrentActiveItem() {\n return activeItem.current\n }\n function getIsAnimating() {\n return isAnimating.current\n }\n function setIsAnimating(val: boolean) {\n isAnimating.current = val\n }\n function setIsDragging(val: boolean) {\n isDragging.current = val\n }\n function getIsDragging() {\n return isDragging.current\n }\n function getPrevItem() {\n const currentActiveItem = getCurrentActiveItem()\n if (currentActiveItem === 0) {\n return items.length - 1\n }\n return currentActiveItem - 1\n }\n function getNextItem() {\n const currentActiveItem = getCurrentActiveItem()\n if (currentActiveItem === items.length - 1) {\n return 0\n }\n return currentActiveItem + 1\n }\n function getIsNextItem(id: string) {\n const itemIndex = findItemIndex(id)\n const activeItem = getCurrentActiveItem()\n if (withLoop && activeItem === items.length - 1) {\n return itemIndex === 0\n }\n return itemIndex === activeItem + 1\n }\n function getIsPrevItem(id: string) {\n const itemIndex = findItemIndex(id)\n const activeItem = getCurrentActiveItem()\n if (withLoop && activeItem === 0) {\n return itemIndex === items.length - 1\n }\n return itemIndex === activeItem - 1\n }\n function findItemIndex(id: string) {\n return items.findIndex(item => item.id === id)\n }\n function getFromValue(from: SlideToItemFnProps['from']) {\n if (typeof from === 'number') {\n return {\n from: {\n [carouselSlideAxisRef.current]: from,\n },\n }\n }\n return {}\n }\n function getToValue(\n customTo: SlideToItemFnProps['customTo'],\n to: SlideToItemFnProps['to'],\n ) {\n if (typeof customTo === 'number') {\n return {\n [carouselSlideAxisRef.current]: customTo,\n }\n }\n if (typeof to !== 'number') {\n throw new Error(`to values is not a number!`)\n }\n return {\n [carouselSlideAxisRef.current]: -(getSlideValue() * to!),\n }\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n function slideToItem({\n from,\n to = -1,\n customTo,\n immediate = false,\n onRest = () => {},\n velocity,\n }: SlideToItemFnProps) {\n if (!immediate) {\n setActiveItem(to)\n setIsAnimating(true)\n emitObservable({\n eventName: 'onSlideStartChange',\n slideActionType: getSlideActionType(),\n nextItem: {\n index: slideType === 'fluid' ? -1 : to,\n id: slideType === 'fluid' ? '' : items[to].id,\n },\n })\n }\n prevSlidedValue.current = getToValue(customTo, to)[carouselSlideAxis]\n setCarouselStyles.start({\n ...getFromValue(from),\n to: getToValue(customTo, to),\n ...(velocity\n ? {\n config: {\n ...defaultDragSpringConfig,\n velocity,\n friction: undefined,\n tension: undefined,\n },\n }\n : {\n config: {\n velocity: 0,\n ...springConfig,\n },\n }),\n immediate,\n onRest: val => {\n if (val.finished) {\n setIsDragging(false)\n setIsAnimating(false)\n onRest()\n if (!immediate) {\n emitObservable({\n eventName: 'onSlideChange',\n slideActionType: getSlideActionType(),\n currentItem: {\n index: slideType === 'fluid' ? -1 : getCurrentActiveItem(),\n id: slideType === 'fluid' ? '' : items[getCurrentActiveItem()].id,\n },\n })\n }\n }\n },\n })\n if (enableThumbsWrapperScroll && withThumbs && !immediate) {\n handleThumbsScroll(to, getSlideActionType())\n }\n }\n function getIsLastItem() {\n return getCurrentActiveItem() === items.length - 1\n }\n function slideToPrevItem(velocity?: number[]) {\n setSlideActionType('prev')\n slideEndReached.current = false\n\n if (slideType === 'fluid') {\n slideEndReached.current = false\n\n if (getIfItemsNotFillTheCarousel()) {\n return\n }\n const nextPrevValue = getCurrentSlidedValue() + getSlideValue() + 200\n\n if (freeScroll) {\n const nextValue = mainCarouselWrapperRef.current!.scrollLeft - getSlideValue()\n slideToItem({\n customTo: nextValue < 0 ? 0 : nextValue,\n from: mainCarouselWrapperRef.current!.scrollLeft,\n velocity,\n })\n } else if (nextPrevValue >= 0) {\n if (withLoop) {\n slideToItem({\n from: getCurrentSlidedValue() - getCarouselItemWidth() * items.length,\n velocity,\n customTo:\n getCurrentSlidedValue() -\n getCarouselItemWidth() * items.length +\n getSlideValue(),\n })\n } else {\n slideToItem({\n customTo: 0,\n velocity,\n })\n }\n } else {\n slideToItem({\n customTo: getCurrentSlidedValue() + getSlideValue(),\n velocity,\n })\n }\n } else {\n if ((!withLoop && getCurrentActiveItem() === 0) || windowIsHidden.current) {\n return\n }\n\n if (getIsFirstItem()) {\n slideToItem({\n from: getCurrentSlidedValue() - getSlideValue() * items.length,\n to: items.length - 1,\n velocity,\n })\n } else {\n slideToItem({\n to: getPrevItem(),\n velocity,\n })\n }\n }\n }\n function slideToNextItem(velocity?: number[]) {\n setSlideActionType('next')\n\n if (slideType === 'fluid') {\n if (getIfItemsNotFillTheCarousel()) {\n return\n }\n\n const nextItemWillExceed =\n Math.abs(getCurrentSlidedValue() - getSlideValue()) + 100 >=\n fluidTotalWrapperScrollValue.current\n\n if (freeScroll) {\n const nextValue = mainCarouselWrapperRef.current!.scrollLeft + getSlideValue()\n const willExceed = nextValue > fluidTotalWrapperScrollValue.current\n const val = mainCarouselWrapperRef.current!.scrollLeft + getSlideValue()\n\n slideToItem({\n velocity,\n customTo: willExceed ? fluidTotalWrapperScrollValue.current : val,\n from: mainCarouselWrapperRef.current!.scrollLeft,\n })\n } else if (\n withLoop &&\n Math.abs(getCurrentSlidedValue() - getSlideValue()) >=\n items.length * getCarouselItemWidth()\n ) {\n const currentWidth = getCarouselItemWidth() * items.length\n slideToItem({\n from: getCurrentSlidedValue() + currentWidth,\n customTo: getCurrentSlidedValue() + currentWidth - getSlideValue(),\n velocity,\n })\n } else if (slideEndReached.current) {\n return\n } else if (nextItemWillExceed) {\n slideEndReached.current = true\n slideToItem({\n customTo: -fluidTotalWrapperScrollValue.current,\n velocity,\n })\n } else {\n slideToItem({\n customTo: getCurrentSlidedValue() - getSlideValue(),\n velocity,\n })\n }\n } else {\n if (\n (!withLoop && getCurrentActiveItem() === internalItems.length - 1) ||\n windowIsHidden.current\n ) {\n return\n }\n\n const nextItemWillExceed =\n Math.abs(getCurrentSlidedValue() - getSlideValue() + 25) >\n fluidTotalWrapperScrollValue.current\n\n if (nextItemWillExceed && !getIsDragging()) {\n slideEndReached.current = true\n } else if (slideEndReached.current) {\n slideToItem({\n to: items.length - itemsPerSlideRef.current,\n velocity,\n })\n } else if (getIsLastItem()) {\n slideToItem({\n from: getCurrentSlidedValue() + getSlideValue() * items.length,\n to: 0,\n velocity,\n })\n } else {\n slideToItem({\n to: getNextItem(),\n velocity,\n })\n }\n }\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n function _slideToItem(item: string | number) {\n let itemIndex = 0\n\n if (typeof item === 'string') {\n itemIndex = items.findIndex(_item => _item.id === item)\n } else {\n itemIndex = item\n }\n\n if (itemIndex >= items.length) {\n throw Error(\n `The item you want to slide to doesn't exist. This could be due to the fact that \n you provide a wrong id or a higher numeric index.`,\n )\n }\n\n if (\n itemIndex === getCurrentActiveItem() ||\n (items.length !== prevItems.current.length && getCurrentActiveItem() < items.length)\n ) {\n return\n }\n\n const currentItem = findItemIndex(prevItems.current[getCurrentActiveItem()].id)\n const newActiveItem = findItemIndex(items[itemIndex].id)\n\n if (newActiveItem > currentItem) {\n setSlideActionType('next')\n } else {\n setSlideActionType('prev')\n }\n\n slideToItem({\n to: itemIndex,\n })\n }\n function getItemStyles(_itemsPerSlide: number) {\n if (slideType === 'fixed') {\n return {\n ...(carouselSlideAxisRef.current === 'x'\n ? { marginRight: `${gutterRef.current}px` }\n : { marginBottom: `${gutterRef.current}px` }),\n flex: `1 0 calc(100% / ${_itemsPerSlide} - ${\n (gutterRef.current * (_itemsPerSlide - 1)) / _itemsPerSlide\n }px)`,\n }\n }\n return {\n ...(carouselSlideAxisRef.current === 'x'\n ? { marginRight: `${gutterRef.current}px` }\n : { marginBottom: `${gutterRef.current}px` }),\n }\n }\n function getAnimatedWrapperStyles() {\n const percentValue = `calc(100% - ${startEndGutterRef.current * 2}px)`\n return {\n width: carouselSlideAxisRef.current === 'x' ? percentValue : '100%',\n height: carouselSlideAxisRef.current === 'y' ? percentValue : '100%',\n }\n }\n function getOverflowStyles() {\n if (freeScroll) {\n if (carouselSlideAxisRef.current === 'x') {\n return {\n overflowX: 'auto',\n }\n }\n return {\n overflowY: 'auto',\n }\n }\n return {}\n }\n function getWheelEvent() {\n if (freeScroll) {\n return {\n onWheel() {\n carouselStyles[carouselSlideAxisRef.current].stop()\n },\n }\n }\n return {}\n }\n function getTouchAction() {\n if (disableGestures) {\n return 'unset'\n } else if (!touchAction) {\n if (carouselSlideAxisRef.current === 'x') {\n return 'pan-y'\n }\n return 'pan-x'\n }\n return touchAction\n }\n // Perform some check on first mount\n useIsomorphicMount(() => {\n if (itemsPerSlide % 2 === 0 && initialStartingPositionRef.current) {\n throw new Error(\n `initialStartingPosition can be only used if itemsPerSlide is an even value.`,\n )\n }\n if (draggingSlideTresholdRef.current < 0) {\n throw new Error('draggingSlideTreshold must be greater than 0')\n }\n if (draggingSlideTresholdRef.current > getSlideValue() / 2) {\n throw new Error(\n `draggingSlideTreshold must be equal or less than the half of the width of an item, which is ${Math.floor(\n getSlideValue() / 2,\n )}`,\n )\n }\n if (itemsPerSlideRef.current < 1) {\n throw new Error(`The itemsPerSlide prop can't be less than 1.`)\n }\n if (itemsPerSlideRef.current > items.length) {\n throw new Error(\n `The itemsPerSlide prop can't be greater than the total length of the items you provide.`,\n )\n }\n if (initialActiveItemRef.current < 0) {\n throw new Error('The initialActiveItem cannot be less than 0.')\n }\n if (initialActiveItemRef.current > items.length) {\n throw new Error(\n 'The initialActiveItem cannot be greater than the total length of the items you provide.',\n )\n }\n if (!shouldResizeOnWindowResize) {\n console.warn(\n 'You set shouldResizeOnWindowResize={false}; be aware that the carousel could behave in a strange way if you also use the fullscreen functionality or if you change the mobile orientation.',\n )\n }\n })\n useIsomorphicMount(() => {\n function handleVisibilityChange() {\n if (document.hidden) {\n windowIsHidden.current = true\n } else {\n windowIsHidden.current = false\n }\n }\n document.addEventListener('visibilitychange', handleVisibilityChange)\n return () => {\n document.removeEventListener('visibilitychange', handleVisibilityChange)\n }\n })\n useIsomorphicMount(() => {\n isFirstMount.current = false\n fluidTotalWrapperScrollValue.current = getFluidWrapperScrollValue()\n initialWindowWidth.current = window.innerWidth\n currentWindowWidth.current = window.innerWidth\n\n if (initialActiveItem > 0) {\n slideToItem({\n to: initialActiveItem,\n immediate: true,\n })\n setActiveItem(initialActiveItem)\n if (!withLoop && carouselTrackWrapperRef.current) {\n carouselTrackWrapperRef.current.style.top = '0px'\n carouselTrackWrapperRef.current.style.left = '0px'\n }\n }\n })\n useIsomorphicLayoutEffect(() => {\n if (initialActiveItem < items.length && initialActiveItem !== activeItem.current) {\n slideToItem({\n to: initialActiveItem,\n immediate: true,\n })\n setActiveItem(initialActiveItem)\n }\n }, [initialActiveItem])\n useIsomorphicLayoutEffect(() => {\n if (shouldResizeOnWindowResize) {\n window.addEventListener('resize', handleResize)\n return () => {\n window.removeEventListener('resize', handleResize)\n }\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [shouldResizeOnWindowResize])\n useIsomorphicLayoutEffect(() => {\n if (carouselTrackWrapperRef.current) {\n if (carouselSlideAxisRef.current === 'x') {\n carouselTrackWrapperRef.current.style.top = '0px'\n }\n if (carouselSlideAxisRef.current === 'y') {\n carouselTrackWrapperRef.current.style.left = '0px'\n }\n }\n }, [carouselSlideAxis])\n useIsomorphicLayoutEffect(() => {\n fluidTotalWrapperScrollValue.current = getFluidWrapperScrollValue()\n const itemsAreEqual = items.length === prevItems.current.length\n\n if (!itemsAreEqual && items.length < prevItems.current.length) {\n _slideToItem(items.length - 1)\n }\n\n prevItems.current = items\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [getFluidWrapperScrollValue, items])\n\n const contextProps = {\n useListenToCustomEvent,\n getIsFullscreen,\n enterFullscreen,\n exitFullscreen,\n getIsAnimating,\n getIsDragging,\n getIsNextItem,\n getIsPrevItem,\n slideToPrevItem() {\n slideToPrevItem()\n },\n slideToNextItem() {\n slideToNextItem()\n },\n ...(slideType === 'fixed'\n ? {\n slideToItem: _slideToItem,\n getIsActiveItem: (id: string) => {\n return findItemIndex(id) === getCurrentActiveItem()\n },\n getCurrentActiveItem: () => ({\n id: items[getCurrentActiveItem()].id,\n index: getCurrentActiveItem(),\n }),\n }\n : {}),\n }\n\n const handleCarouselFragmentRef = (ref: HTMLDivElement | null) => {\n if (ref) {\n carouselTrackWrapperRef.current = ref\n adjustCarouselWrapperPosition(ref, initialActiveItemRef.current)\n }\n }\n\n function getInitialStyles() {\n const totalValue = (items.length / itemsPerSlide) * 100\n const singleItemValue = 100 / itemsPerSlide\n const cssProp = carouselSlideAxisRef.current === 'x' ? 'left' : 'y'\n const quantityToMove = Math.floor(50 / singleItemValue)\n\n if (slideType === 'fixed') {\n if (initialStartingPositionRef.current === 'center') {\n return {\n [cssProp]: `calc(-${totalValue}% + ${singleItemValue * quantityToMove}%)`,\n }\n }\n if (initialStartingPositionRef.current === 'end') {\n return {\n [cssProp]: `calc(-${totalValue}% + ${singleItemValue * (quantityToMove * 2)}%)`,\n }\n }\n }\n return {\n [cssProp]: `0px`,\n }\n }\n\n const carouselFragment = (\n <Context.Provider value={contextProps}>\n <div\n ref={mainCarouselWrapperRef}\n className=\"use-spring-carousel-main-wrapper\"\n data-testid=\"use-spring-carousel-wrapper\"\n {...getWheelEvent()}\n // @ts-ignore\n style={{\n display: 'flex',\n position: 'relative',\n width: '100%',\n height: '100%',\n ...getOverflowStyles(),\n }}\n >\n <animated.div\n {...bindDrag()}\n className=\"use-spring-carousel-track-wrapper\"\n data-testid=\"use-spring-carousel-animated-wrapper\"\n ref={handleCarouselFragmentRef}\n style={{\n display: 'flex',\n position: 'relative',\n touchAction: getTouchAction(),\n flexDirection: carouselSlideAxisRef.current === 'x' ? 'row' : 'column',\n ...getAnimatedWrapperStyles(),\n ...getInitialStyles(),\n ...(freeScroll ? {} : carouselStyles),\n }}\n >\n {internalItems.map(({ id, renderItem }, index) => {\n return (\n <div\n key={`${id}-${index}`}\n className=\"use-spring-carousel-item\"\n data-testid=\"use-spring-carousel-item-wrapper\"\n style={{\n display: 'flex',\n position: 'relative',\n ...getItemStyles(itemsPerSlideRef.current),\n }}\n >\n {renderItem}\n </div>\n )\n })}\n </animated.div>\n </div>\n </Context.Provider>\n )\n const thumbsFragment = (\n <Context.Provider value={contextProps}>{_thumbsFragment}</Context.Provider>\n )\n\n return {\n ...contextProps,\n carouselFragment,\n thumbsFragment,\n }\n}\n\nfunction useSpringCarouselContext<T = 'fixed' | 'fluid'>() {\n const context = useContext(Context)\n if (!context) {\n throw new Error(\n 'useSpringCarouselContext must be used only inside a component that is rendered inside the Carousel.',\n )\n }\n return context as ContextTypes<T>\n}\n\nexport { useSpringCarousel, useSpringCarouselContext }\n"],"names":["Context","createContext","undefined","defaultDragSpringConfig","config","default","mass","velocity","useSpringCarousel","items","withLoop","draggingSlideTreshold","springConfig","shouldResizeOnWindowResize","withThumbs","enableThumbsWrapperScroll","slideWhenThresholdIsReached","carouselSlideAxis","thumbsSlideAxis","prepareThumbsData","initialActiveItem","initialStartingPosition","disableGestures","gutter","startEndGutter","touchAction","slideAmount","freeScroll","enableFreeScrollDrag","itemsPerSlide","slideType","isFirstMount","useRef","slideActionType","internalItems","length","activeItem","mainCarouselWrapperRef","carouselTrackWrapperRef","isDragging","isAnimating","windowIsHidden","fluidTotalWrapperScrollValue","slideEndReached","currentWindowWidth","initialWindowWidth","prevSlidedValue","prevItems","draggingSlideTresholdRef","itemsPerSlideRef","gutterRef","startEndGutterRef","initialActiveItemRef","initialStartingPositionRef","carouselSlideAxisRef","current","carouselStyles","setCarouselStyles","useSpring","y","x","onChange","value","Math","abs","getCarouselItemWidth","carouselItem","querySelector","Error","getBoundingClientRect","getCurrentSlidedValue","get","getIfItemsNotFillTheCarousel","getMainCarouselWrapperWidth","getFluidWrapperScrollValue","round","Number","getIsFirstItem","getCurrentActiveItem","getSlideValue","itemVal","adjustCarouselWrapperPosition","ref","_initialActiveItem","positionProperty","getDefaultPositionValue","setPosition","v","style","top","left","setStartPosition","i","setEndPosition","resize","window","innerWidth","start","immediate","[object Object]","nextValue","handleResize","useIsomorphicLayoutEffect","floor","useListenToCustomEvent","emitObservable","useCustomEventsModule","enterFullscreen","exitFullscreen","getIsFullscreen","useFullscreenModule","thumbsFragment","_thumbsFragment","handleThumbsScroll","useThumbsModule","getWrapperScrollDirection","getIfShouldEnableFluidDrag","bindDrag","useDrag","props","dragging","movement","offset","currentMovement","prevItemTreshold","nextItemTreshold","direction","cancelDrag","cancel","setDragDirection","setSlideActionType","emitDragObservable","eventName","getSlideActionType","resetAnimation","checkBounds","getIsDragging","setIsDragging","from","to","friction","tension","last","slideToPrevItem","slideToNextItem","getIsLastItem","enabled","axis","type","setActiveItem","newItem","setIsAnimating","val","getPrevItem","currentActiveItem","getNextItem","findItemIndex","id","findIndex","item","getToValue","customTo","slideToItem","onRest","nextItem","index","getFromValue","finished","currentItem","nextPrevValue","scrollLeft","nextItemWillExceed","willExceed","currentWidth","_slideToItem","itemIndex","_item","useIsomorphicMount","console","warn","handleVisibilityChange","document","hidden","addEventListener","removeEventListener","contextProps","getIsAnimating","getIsNextItem","getIsPrevItem","getIsActiveItem","carouselFragment","_jsx","Provider","className","stop","display","position","width","height","overflowX","overflowY","animated","div","flexDirection","percentValue","getAnimatedWrapperStyles","totalValue","singleItemValue","cssProp","quantityToMove","getInitialStyles","map","renderItem","_itemsPerSlide","marginRight","marginBottom","flex","useSpringCarouselContext","context","useContext"],"mappings":"mUA8BA,MAAMA,EAAUC,OAA2DC,GAErEC,iCACDC,EAAOC,UACVC,KAAM,EACNC,SAAU,IAkBZ,SAASC,GAAkBC,MACzBA,EAAK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BC,QACrB,CAAE+J,YAAa,GAAGpK,EAAUK,aAC5B,CAAEgK,aAAc,GAAGrK,EAAUK,2BAgQtB6J,IATI,GAAGvD,KAAMQ,KArQ5B,IAAuBgD,cAsRjBtG,GACJgF,EAAC/L,EAAQgM,wBAASlI,MAAO2H,cAAezE,MAG1C,sCACKyE,KACHK,iBAAAA,GACA/E,eAAAA,KAIJ,SAAS0G,IACP,MAAMC,EAAUC,EAAW3N,GAC3B,IAAK0N,EACH,MAAM,IAAItJ,MACR,uGAGJ,OAAOsJ"}
1
+ {"version":3,"file":"index2.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ import{jsx as e}from"react/jsx-runtime";import{useSpring as t,config as r}from"@react-spring/web";import{createContext as n,useRef as i,useCallback as c,useEffect as o,useLayoutEffect as s,useContext as l}from"react";import{u,a,b as d}from"./useThumbsModule-ce69c348.js";import{useDrag as f}from"@use-gesture/react";import"screenfull";function g({items:n,init:l=!0,withThumbs:g,thumbsSlideAxis:m="x",itemsPerSlide:v=1,slideType:h="fixed",gutter:x=0,withLoop:p=!1,startEndGutter:b=0,carouselSlideAxis:y="x",disableGestures:w=!1,draggingSlideTreshold:T,slideWhenThresholdIsReached:I=!1,freeScroll:j,enableFreeScrollDrag:O,initialStartingPosition:M,prepareThumbsData:A,initialActiveItem:S=0}){const L=i(0),R=i(null!=T?T:0),$=i("initial"),C=i("initial"),E=i(0),[F,N]=t((()=>({val:0,pause:!l,onChange({value:e}){j&&P.current?(ce(),"x"===y?P.current.scrollLeft=Math.abs(e.val):P.current.scrollTop=Math.abs(e.val)):z.current&&(z.current.style.transform="x"===y?`translate3d(${e.val}px, 0px,0px)`:`translate3d(0px,${e.val}px,0px)`)}}))),W=i(S),k=i(0===S),D=i(!1),P=i(null),z=i(null),B=c((()=>p?[...n.map((e=>Object.assign(Object.assign({},e),{id:`prev-repeated-item-${e.id}`}))),...n,...n.map((e=>Object.assign(Object.assign({},e),{id:`next-repeated-item-${e.id}`})))]:[...n]),[n,p])(),{emitEvent:q,useListenToCustomEvent:G}=u(),{thumbsFragment:H,handleScroll:X}=a({withThumbs:!!g,thumbsSlideAxis:m,prepareThumbsData:A,items:n}),{enterFullscreen:Y,exitFullscreen:J,getIsFullscreen:K}=d({mainCarouselWrapperRef:P,emitEvent:q,handleResize:()=>_()});function Q(){var e;const t=null===(e=P.current)||void 0===e?void 0:e.querySelector(".use-spring-carousel-item");if(!t)throw Error("No carousel items available!");return t.getBoundingClientRect()["x"===y?"width":"height"]+x}function U({from:e,to:t,nextActiveItem:i,immediate:c=!1,slideMode:o}){C.current=o,"number"==typeof i&&(j||(W.current=i),q({eventName:"onSlideStartChange",slideActionType:$.current,slideMode:C.current,nextItem:{startReached:k.current,endReached:D.current,index:j?-1:W.current,id:j?"":n[W.current].id}})),E.current=t,N.start({immediate:c,from:{val:e},to:{val:t},config:Object.assign(Object.assign({},r.default),{velocity:F.val.velocity}),onRest(e){!c&&e.finished&&q({eventName:"onSlideChange",slideActionType:$.current,slideMode:C.current,currentItem:{startReached:k.current,endReached:D.current,index:j?-1:W.current,id:j?"":n[W.current].id}})}}),g&&!c&&X(W.current)}function V(){var e;return p?Q()*n.length:Math.round(Number(null===(e=z.current)||void 0===e?void 0:e["x"===y?"scrollWidth":"scrollHeight"])-z.current.getBoundingClientRect()["x"===y?"width":"height"])}function Z(){var e;const t=null===(e=z.current)||void 0===e?void 0:e.querySelector(".use-spring-carousel-item");if(!t)throw Error("No carousel items available!");return t.getBoundingClientRect()["x"===y?"width":"height"]+x}function _(){const e="x"===y?"left":"top";function t(t){const r=z.current;r&&(p?(r.style.top="0px",r.style.left="0px",r.style[e]=`-${t-b}px`):(r.style.left="0px",r.style.top="0px"))}const r=Math.abs(ee());if(r<V()&&D.current&&(D.current=!1),r>V()){const e=-V();return D.current=!0,E.current=e,void N.start({immediate:!0,val:e})}if(t("center"===M?Z()*n.length-Q()*Math.round((v-1)/2):"end"===M?Z()*n.length-Q()*Math.round(v-1):Z()*n.length),!j&&"fixed"===h){const e=-Q()*W.current;E.current=e,N.start({immediate:!0,val:e})}}function ee(){return j&&P.current?P.current["x"===y?"scrollLeft":"scrollTop"]:F.val.get()}function te(e,t){if(j&&"next"===e){const e=E.current+Q();return e>V()?V():e}if(j&&"prev"===e){const e=E.current-Q();return e<0?0:e}return"next"===e?t?-t*Q():E.current-Q():t?-t*Q():E.current+Q()}function re(e="click",t){if(!l||k.current&&!p)return;$.current="prev",D.current=!1;const r=t||W.current-1;if(!p){const r=te("prev",t)+Q()/3>0;if(k.current)return;if(r)return k.current=!0,D.current=!1,void U({slideMode:e,from:ee(),to:0,nextActiveItem:0})}if(p&&k.current)return k.current=!1,D.current=!0,void U({slideMode:e,from:ee()-Q()*n.length,to:-Q()*n.length+Q(),nextActiveItem:n.length-1});0===r&&(k.current=!0),r!==n.length-1&&-1!==r||(D.current=!0),U({slideMode:e,from:ee(),to:te("prev",t),nextActiveItem:r})}function ne(e="click",t){if(!l||D.current&&!p)return;$.current="next",k.current=!1;const r=t||W.current+1;if(!p){const n=Math.abs(te("next",t))>V()-Q()/3;if(D.current)return;if(n)return k.current=!1,D.current=!0,void U({slideMode:e,from:ee(),to:-V(),nextActiveItem:r})}if(p&&D.current)return D.current=!1,k.current=!0,void U({slideMode:e,from:ee()+Q()*n.length,to:0,nextActiveItem:0});0===r&&(k.current=!0),r===n.length-1&&(D.current=!0),U({slideMode:e,from:ee(),to:te("next",t),nextActiveItem:r})}o((()=>{L.current=window.innerWidth}),[]),o((()=>{_()}),[M,v,p,b,x,j,h,l]),s((()=>{z.current&&_()}),[]),o((()=>{R.current=T||Math.floor(Q()/2/2)}),[T]),o((()=>{function e(){window.innerWidth!==L.current&&(L.current=window.innerWidth,_())}return window.addEventListener("resize",e),()=>{window.removeEventListener("resize",e)}}),[]);const ie=f((e=>{const t=e.dragging,n=e.offset["x"===y?0:1],i=e.movement["x"===y?0:1],c=e.direction["x"===y?0:1],o=i>R.current,s=i<-R.current;if(t)return $.current=c>0?"prev":"next",q(Object.assign(Object.assign({},e),{eventName:"onDrag",slideActionType:$.current})),j?"prev"===$.current&&n>0?(e.cancel(),void N.start({from:{val:ee()},to:{val:0},config:{velocity:e.velocity,friction:50,tension:1e3}})):void N.start({from:{val:ee()},to:{val:-n},config:{velocity:e.velocity,friction:50,tension:1e3}}):(N.start({val:n,config:{velocity:e.velocity,friction:50,tension:1e3}}),void(I&&s?(ne("drag"),e.cancel()):I&&o&&(re("drag"),e.cancel())));e.last&&!e.canceled&&j&&("prev"===$.current&&re("drag"),"next"===$.current&&ne("drag")),!e.last||e.canceled||j||(s?!p&&D.current?N.start({val:-V(),config:Object.assign(Object.assign({},r.default),{velocity:e.velocity})}):ne("drag"):o?!p&&k.current?N.start({val:0,config:Object.assign(Object.assign({},r.default),{velocity:e.velocity})}):re("drag"):N.start({val:E.current,config:Object.assign(Object.assign({},r.default),{velocity:e.velocity})}))}),{enabled:l&&!w&&!j||!!j&&!!O,axis:y,from:()=>j&&P.current?[-P.current.scrollLeft,-P.current.scrollTop]:[F.val.get(),F.val.get()]});function ce(){P.current&&(E.current=P.current["x"===y?"scrollLeft":"scrollTop"],0===P.current["x"===y?"scrollLeft":"scrollTop"]&&(k.current=!0,D.current=!1),P.current["x"===y?"scrollLeft":"scrollTop"]>0&&P.current["x"===y?"scrollLeft":"scrollTop"]<V()&&(k.current=!1,D.current=!1),P.current["x"===y?"scrollLeft":"scrollTop"]===V()&&(k.current=!1,D.current=!0))}function oe(e){return n.findIndex((t=>t.id===e))}function se(e,t){let r=0;if(r="string"==typeof e?n.findIndex((t=>t.id===e)):e,r<0||r>=n.length)throw new Error(t);return r}return{useListenToCustomEvent:G,carouselFragment:e("div",Object.assign({ref:P},j?{onWheel(){F.val.stop(),ce()}}:{},{style:Object.assign({display:"flex",position:"relative",width:"100%",height:"100%"},j?"x"===y?{overflowX:"auto"}:{overflowY:"auto"}:{})},{children:e("div",Object.assign({ref:z},ie(),{style:Object.assign({position:"relative",display:"flex",flexDirection:"x"===y?"row":"column",touchAction:"none"},function(){const e=`calc(100% - ${2*b}px)`;return{width:"x"===y?e:"100%",height:"y"===y?e:"100%"}}())},{children:B.map(((t,r)=>e("div",Object.assign({className:"use-spring-carousel-item","data-testid":"use-spring-carousel-item-wrapper",style:Object.assign({display:"flex",position:"relative",flex:"1"},"fixed"!==h||j?Object.assign({marginRight:`${x}px`}):{marginRight:`${x}px`,flex:`1 0 calc(100% / ${v} - ${x*(v-1)/v}px)`})},{children:t.renderItem}),`${t.id}-${r}`)))}))})),enterFullscreen:Y,exitFullscreen:J,getIsFullscreen:K,thumbsFragment:H,slideToItem:function(e){if(!l)return;k.current=!1,D.current=!1;const t=se(e,"The item you want to slide to doesn't exist; please check che item id or the index you're passing to.");if(t===W.current)return;const r=oe(n[W.current].id),i=oe(n[t].id);i>r?ne("click",i):re("click",i)},getIsNextItem:function(e){const t=oe(e),r=W.current;return p&&r===n.length-1?0===t:t===r+1},getIsPrevItem:function(e){const t=oe(e),r=W.current;return p&&0===r?t===n.length-1:t===r-1},slideToPrevItem:()=>re(),slideToNextItem:()=>ne(),getIsActiveItem:e=>se(e,"The item you want to check doesn't exist")===W.current}}const m=n(void 0);function v(){const e=l(m);if(!e)throw new Error("useSpringCarouselContext must be used within the carousel.");return e}export{g as useSpringCarousel,v as useSpringCarouselContext};
2
+ //# sourceMappingURL=useSpringCarousel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useSpringCarousel.js","sources":["../../src/useSpringCarousel.tsx"],"sourcesContent":["import { config, useSpring } from \"@react-spring/web\";\nimport React, {\n createContext,\n useCallback,\n useContext,\n useEffect,\n useLayoutEffect,\n useRef,\n} from \"react\";\n\nimport { SlideActionType, SlideMode } from \"./types/common\";\nimport { useEventsModule } from \"./modules/useEventsModule\";\nimport { useDrag } from \"@use-gesture/react\";\nimport { useFullscreenModule } from \"./modules/useFullscreenModule\";\nimport { useThumbsModule } from \"./modules/useThumbsModule\";\nimport {\n UseSpringReturnType,\n UseSpringCarouselWithThumbs,\n UseSpringCarouselComplete,\n UseSpringCarouselWithNoThumbs,\n UseSpringCarouselWithFixedItems,\n UseSpringCarouselWithNoFixedItems,\n SpringCarouselWithThumbs,\n} from \"./types/internals\";\n\nfunction useSpringCarousel(\n props: UseSpringCarouselWithThumbs\n): UseSpringReturnType;\nfunction useSpringCarousel(\n props: UseSpringCarouselWithNoThumbs\n): UseSpringReturnType;\nfunction useSpringCarousel(\n props: UseSpringCarouselWithFixedItems\n): UseSpringReturnType;\nfunction useSpringCarousel(\n props: UseSpringCarouselWithNoFixedItems\n): UseSpringReturnType;\n\nfunction useSpringCarousel({\n items,\n init = true,\n withThumbs,\n thumbsSlideAxis = \"x\",\n itemsPerSlide = 1,\n slideType = \"fixed\",\n gutter = 0,\n withLoop = false,\n startEndGutter = 0,\n carouselSlideAxis = \"x\",\n disableGestures = false,\n draggingSlideTreshold: _draggingSlideTreshold,\n slideWhenThresholdIsReached = false,\n freeScroll,\n enableFreeScrollDrag,\n initialStartingPosition,\n prepareThumbsData,\n initialActiveItem = 0,\n}: UseSpringCarouselComplete) {\n const prevWindowWidth = useRef(0);\n const draggingSlideTreshold = useRef(_draggingSlideTreshold ?? 0);\n const slideActionType = useRef<SlideActionType>(\"initial\");\n const slideModeType = useRef<SlideMode>(\"initial\");\n const prevSlidedValue = useRef(0);\n const [spring, setSpring] = useSpring(() => ({\n val: 0,\n pause: !init,\n onChange({ value }) {\n if (freeScroll && mainCarouselWrapperRef.current) {\n setStartEndItemReachedOnFreeScroll();\n if (carouselSlideAxis === \"x\") {\n mainCarouselWrapperRef.current.scrollLeft = Math.abs(value.val);\n } else {\n mainCarouselWrapperRef.current.scrollTop = Math.abs(value.val);\n }\n } else if (carouselTrackWrapperRef.current) {\n if (carouselSlideAxis === \"x\") {\n carouselTrackWrapperRef.current.style.transform = `translate3d(${value.val}px, 0px,0px)`;\n } else {\n carouselTrackWrapperRef.current.style.transform = `translate3d(0px,${value.val}px,0px)`;\n }\n }\n },\n }));\n const activeItem = useRef(initialActiveItem);\n const firstItemReached = useRef(initialActiveItem === 0);\n const lastItemReached = useRef(false);\n const mainCarouselWrapperRef = useRef<HTMLDivElement | null>(null);\n const carouselTrackWrapperRef = useRef<HTMLDivElement | null>(null);\n\n const getItems = useCallback(() => {\n if (withLoop) {\n return [\n ...items.map((i) => ({\n ...i,\n id: `prev-repeated-item-${i.id}`,\n })),\n ...items,\n ...items.map((i) => ({\n ...i,\n id: `next-repeated-item-${i.id}`,\n })),\n ];\n }\n return [...items];\n }, [items, withLoop]);\n const internalItems = getItems();\n\n const { emitEvent, useListenToCustomEvent } = useEventsModule();\n const { thumbsFragment, handleScroll } = useThumbsModule({\n withThumbs: !!withThumbs,\n thumbsSlideAxis,\n prepareThumbsData,\n items: items as SpringCarouselWithThumbs[\"items\"],\n });\n const { enterFullscreen, exitFullscreen, getIsFullscreen } =\n useFullscreenModule({\n mainCarouselWrapperRef,\n emitEvent,\n handleResize: () => adjustCarouselWrapperPosition(),\n });\n\n function getItemStyles() {\n if (slideType === \"fixed\" && !freeScroll) {\n return {\n marginRight: `${gutter}px`,\n flex: `1 0 calc(100% / ${itemsPerSlide} - ${\n (gutter * (itemsPerSlide - 1)) / itemsPerSlide\n }px)`,\n };\n }\n return {\n ...{ marginRight: `${gutter}px` },\n };\n }\n\n function getSlideValue() {\n const carouselItem = mainCarouselWrapperRef.current?.querySelector(\n \".use-spring-carousel-item\"\n );\n\n if (!carouselItem) {\n throw Error(\"No carousel items available!\");\n }\n\n return (\n carouselItem.getBoundingClientRect()[\n carouselSlideAxis === \"x\" ? \"width\" : \"height\"\n ] + gutter\n );\n }\n\n type SlideToItem = {\n from: number;\n to: number;\n nextActiveItem?: number;\n immediate?: boolean;\n slideMode: \"click\" | \"drag\";\n };\n\n function slideToItem({\n from,\n to,\n nextActiveItem,\n immediate = false,\n slideMode,\n }: SlideToItem) {\n slideModeType.current = slideMode;\n\n if (typeof nextActiveItem === \"number\") {\n if (!freeScroll) {\n activeItem.current = nextActiveItem;\n }\n emitEvent({\n eventName: \"onSlideStartChange\",\n slideActionType: slideActionType.current,\n slideMode: slideModeType.current,\n nextItem: {\n startReached: firstItemReached.current,\n endReached: lastItemReached.current,\n index: freeScroll ? -1 : activeItem.current,\n id: freeScroll ? \"\" : items[activeItem.current].id,\n },\n });\n }\n\n prevSlidedValue.current = to;\n setSpring.start({\n immediate,\n from: {\n val: from,\n },\n to: {\n val: to,\n },\n config: {\n ...config.default,\n velocity: spring.val.velocity,\n },\n onRest(value) {\n if (!immediate && value.finished) {\n emitEvent({\n eventName: \"onSlideChange\",\n slideActionType: slideActionType.current,\n slideMode: slideModeType.current,\n currentItem: {\n startReached: firstItemReached.current,\n endReached: lastItemReached.current,\n index: freeScroll ? -1 : activeItem.current,\n id: freeScroll ? \"\" : items[activeItem.current].id,\n },\n });\n }\n },\n });\n if (withThumbs && !immediate) {\n handleScroll(activeItem.current);\n }\n }\n\n function getTotalScrollValue() {\n if (withLoop) {\n return getSlideValue() * items.length;\n }\n return Math.round(\n Number(\n carouselTrackWrapperRef.current?.[\n carouselSlideAxis === \"x\" ? \"scrollWidth\" : \"scrollHeight\"\n ]\n ) -\n carouselTrackWrapperRef.current!.getBoundingClientRect()[\n carouselSlideAxis === \"x\" ? \"width\" : \"height\"\n ]\n );\n }\n function getAnimatedWrapperStyles() {\n const percentValue = `calc(100% - ${startEndGutter * 2}px)`;\n return {\n width: carouselSlideAxis === \"x\" ? percentValue : \"100%\",\n height: carouselSlideAxis === \"y\" ? percentValue : \"100%\",\n };\n }\n\n function getCarouselItemWidth() {\n const carouselItem = carouselTrackWrapperRef.current?.querySelector(\n \".use-spring-carousel-item\"\n );\n if (!carouselItem) {\n throw Error(\"No carousel items available!\");\n }\n return (\n carouselItem.getBoundingClientRect()[\n carouselSlideAxis === \"x\" ? \"width\" : \"height\"\n ] + gutter\n );\n }\n function adjustCarouselWrapperPosition() {\n const positionProperty = carouselSlideAxis === \"x\" ? \"left\" : \"top\";\n\n function setPosition(v: number) {\n const ref = carouselTrackWrapperRef.current;\n if (!ref) return;\n\n if (withLoop) {\n ref.style.top = \"0px\";\n ref.style.left = \"0px\";\n ref.style[positionProperty] = `-${v - startEndGutter}px`;\n } else {\n ref.style.left = \"0px\";\n ref.style.top = \"0px\";\n }\n }\n\n const currentFromValue = Math.abs(getFromValue());\n\n if (currentFromValue < getTotalScrollValue() && lastItemReached.current) {\n lastItemReached.current = false;\n }\n if (currentFromValue > getTotalScrollValue()) {\n const val = -getTotalScrollValue();\n lastItemReached.current = true;\n prevSlidedValue.current = val;\n setSpring.start({\n immediate: true,\n val,\n });\n return;\n }\n\n if (initialStartingPosition === \"center\") {\n setPosition(\n getCarouselItemWidth() * items.length -\n getSlideValue() * Math.round((itemsPerSlide - 1) / 2)\n );\n } else if (initialStartingPosition === \"end\") {\n setPosition(\n getCarouselItemWidth() * items.length -\n getSlideValue() * Math.round(itemsPerSlide - 1)\n );\n } else {\n setPosition(getCarouselItemWidth() * items.length);\n }\n\n if (!freeScroll && slideType === \"fixed\") {\n const val = -(getSlideValue() * activeItem.current);\n prevSlidedValue.current = val;\n setSpring.start({\n immediate: true,\n val,\n });\n }\n }\n\n function getFromValue() {\n if (freeScroll && mainCarouselWrapperRef.current) {\n return mainCarouselWrapperRef.current[\n carouselSlideAxis === \"x\" ? \"scrollLeft\" : \"scrollTop\"\n ];\n }\n return spring.val.get();\n }\n function getToValue(type: \"next\" | \"prev\", index?: number) {\n if (freeScroll && type === \"next\") {\n const next = prevSlidedValue.current + getSlideValue();\n if (next > getTotalScrollValue()) {\n return getTotalScrollValue();\n }\n return next;\n }\n\n if (freeScroll && type === \"prev\") {\n const next = prevSlidedValue.current - getSlideValue();\n if (next < 0) {\n return 0;\n }\n return next;\n }\n\n if (type === \"next\") {\n if (index) {\n return -(index * getSlideValue());\n }\n return prevSlidedValue.current - getSlideValue();\n }\n\n if (index) {\n return -(index * getSlideValue());\n }\n return prevSlidedValue.current + getSlideValue();\n }\n function slideToPrevItem(\n type: Exclude<SlideMode, \"initial\"> = \"click\",\n index?: number\n ) {\n if (!init || (firstItemReached.current && !withLoop)) return;\n\n slideActionType.current = \"prev\";\n lastItemReached.current = false;\n\n const nextItem = index || activeItem.current - 1;\n\n if (!withLoop) {\n const nextItemWillExceed =\n getToValue(\"prev\", index) + getSlideValue() / 3 > 0;\n\n if (firstItemReached.current) return;\n if (nextItemWillExceed) {\n firstItemReached.current = true;\n lastItemReached.current = false;\n\n slideToItem({\n slideMode: type,\n from: getFromValue(),\n to: 0,\n nextActiveItem: 0,\n });\n return;\n }\n }\n if (withLoop && firstItemReached.current) {\n firstItemReached.current = false;\n lastItemReached.current = true;\n slideToItem({\n slideMode: type,\n from: getFromValue() - getSlideValue() * items.length,\n to: -(getSlideValue() * items.length) + getSlideValue(),\n nextActiveItem: items.length - 1,\n });\n return;\n }\n if (nextItem === 0) {\n firstItemReached.current = true;\n }\n if (nextItem === items.length - 1 || nextItem === -1) {\n lastItemReached.current = true;\n }\n slideToItem({\n slideMode: type,\n from: getFromValue(),\n to: getToValue(\"prev\", index),\n nextActiveItem: nextItem,\n });\n }\n function slideToNextItem(\n type: Exclude<SlideMode, \"initial\"> = \"click\",\n index?: number\n ) {\n if (!init || (lastItemReached.current && !withLoop)) return;\n\n slideActionType.current = \"next\";\n firstItemReached.current = false;\n\n const nextItem = index || activeItem.current + 1;\n\n if (!withLoop) {\n const nextItemWillExceed =\n Math.abs(getToValue(\"next\", index)) >\n getTotalScrollValue() - getSlideValue() / 3;\n\n if (lastItemReached.current) return;\n if (nextItemWillExceed) {\n firstItemReached.current = false;\n lastItemReached.current = true;\n\n slideToItem({\n slideMode: type,\n from: getFromValue(),\n to: -getTotalScrollValue(),\n nextActiveItem: nextItem,\n });\n return;\n }\n }\n if (withLoop && lastItemReached.current) {\n lastItemReached.current = false;\n firstItemReached.current = true;\n slideToItem({\n slideMode: type,\n from: getFromValue() + getSlideValue() * items.length,\n to: 0,\n nextActiveItem: 0,\n });\n return;\n }\n if (nextItem === 0) {\n firstItemReached.current = true;\n }\n if (nextItem === items.length - 1) {\n lastItemReached.current = true;\n }\n slideToItem({\n slideMode: type,\n from: getFromValue(),\n to: getToValue(\"next\", index),\n nextActiveItem: nextItem,\n });\n }\n\n useEffect(() => {\n prevWindowWidth.current = window.innerWidth;\n }, []);\n useEffect(() => {\n adjustCarouselWrapperPosition();\n }, [\n initialStartingPosition,\n itemsPerSlide,\n withLoop,\n startEndGutter,\n gutter,\n freeScroll,\n slideType,\n init,\n ]);\n useLayoutEffect(() => {\n /**\n * Set initial track position\n */\n if (carouselTrackWrapperRef.current) {\n adjustCarouselWrapperPosition();\n }\n }, []);\n useEffect(() => {\n if (_draggingSlideTreshold) {\n draggingSlideTreshold.current = _draggingSlideTreshold;\n } else {\n draggingSlideTreshold.current = Math.floor(getSlideValue() / 2 / 2);\n }\n }, [_draggingSlideTreshold]);\n useEffect(() => {\n function handleResize() {\n if (window.innerWidth === prevWindowWidth.current) return;\n prevWindowWidth.current = window.innerWidth;\n adjustCarouselWrapperPosition();\n }\n window.addEventListener(\"resize\", handleResize);\n return () => {\n window.removeEventListener(\"resize\", handleResize);\n };\n }, []);\n\n const bindDrag = useDrag(\n (state) => {\n const isDragging = state.dragging;\n const movement = state.offset[carouselSlideAxis === \"x\" ? 0 : 1];\n const currentMovement = state.movement[carouselSlideAxis === \"x\" ? 0 : 1];\n const direction = state.direction[carouselSlideAxis === \"x\" ? 0 : 1];\n\n const prevItemTreshold = currentMovement > draggingSlideTreshold.current;\n const nextItemTreshold = currentMovement < -draggingSlideTreshold.current;\n\n if (isDragging) {\n if (direction > 0) {\n slideActionType.current = \"prev\";\n } else {\n slideActionType.current = \"next\";\n }\n\n emitEvent({\n ...state,\n eventName: \"onDrag\",\n slideActionType: slideActionType.current,\n });\n\n if (freeScroll) {\n if (slideActionType.current === \"prev\" && movement > 0) {\n state.cancel();\n setSpring.start({\n from: {\n val: getFromValue(),\n },\n to: {\n val: 0,\n },\n config: {\n velocity: state.velocity,\n friction: 50,\n tension: 1000,\n },\n });\n return;\n }\n\n setSpring.start({\n from: {\n val: getFromValue(),\n },\n to: {\n val: -movement,\n },\n config: {\n velocity: state.velocity,\n friction: 50,\n tension: 1000,\n },\n });\n return;\n }\n\n setSpring.start({\n val: movement,\n config: {\n velocity: state.velocity,\n friction: 50,\n tension: 1000,\n },\n });\n\n if (slideWhenThresholdIsReached && nextItemTreshold) {\n slideToNextItem(\"drag\");\n state.cancel();\n } else if (slideWhenThresholdIsReached && prevItemTreshold) {\n slideToPrevItem(\"drag\");\n state.cancel();\n }\n return;\n }\n\n if (state.last && !state.canceled && freeScroll) {\n if (slideActionType.current === \"prev\") {\n slideToPrevItem(\"drag\");\n }\n if (slideActionType.current === \"next\") {\n slideToNextItem(\"drag\");\n }\n }\n\n if (state.last && !state.canceled && !freeScroll) {\n if (nextItemTreshold) {\n if (!withLoop && lastItemReached.current) {\n setSpring.start({\n val: -getTotalScrollValue(),\n config: {\n ...config.default,\n velocity: state.velocity,\n },\n });\n } else {\n slideToNextItem(\"drag\");\n }\n } else if (prevItemTreshold) {\n if (!withLoop && firstItemReached.current) {\n setSpring.start({\n val: 0,\n config: {\n ...config.default,\n velocity: state.velocity,\n },\n });\n } else {\n slideToPrevItem(\"drag\");\n }\n } else {\n setSpring.start({\n val: prevSlidedValue.current,\n config: {\n ...config.default,\n velocity: state.velocity,\n },\n });\n }\n }\n },\n {\n enabled:\n (init && !disableGestures && !freeScroll) ||\n (!!freeScroll && !!enableFreeScrollDrag),\n axis: carouselSlideAxis,\n from: () => {\n if (freeScroll && mainCarouselWrapperRef.current) {\n return [\n -mainCarouselWrapperRef.current.scrollLeft,\n -mainCarouselWrapperRef.current.scrollTop,\n ];\n }\n if (carouselSlideAxis === \"x\") {\n return [spring.val.get(), spring.val.get()];\n }\n return [spring.val.get(), spring.val.get()];\n },\n }\n );\n\n function getWrapperOverflowStyles() {\n if (freeScroll) {\n if (carouselSlideAxis === \"x\") {\n return {\n overflowX: \"auto\",\n };\n }\n return {\n overflowY: \"auto\",\n };\n }\n return {};\n }\n\n function setStartEndItemReachedOnFreeScroll() {\n if (mainCarouselWrapperRef.current) {\n prevSlidedValue.current =\n mainCarouselWrapperRef.current[\n carouselSlideAxis === \"x\" ? \"scrollLeft\" : \"scrollTop\"\n ];\n if (\n mainCarouselWrapperRef.current[\n carouselSlideAxis === \"x\" ? \"scrollLeft\" : \"scrollTop\"\n ] === 0\n ) {\n firstItemReached.current = true;\n lastItemReached.current = false;\n }\n if (\n mainCarouselWrapperRef.current[\n carouselSlideAxis === \"x\" ? \"scrollLeft\" : \"scrollTop\"\n ] > 0 &&\n mainCarouselWrapperRef.current[\n carouselSlideAxis === \"x\" ? \"scrollLeft\" : \"scrollTop\"\n ] < getTotalScrollValue()\n ) {\n firstItemReached.current = false;\n lastItemReached.current = false;\n }\n if (\n mainCarouselWrapperRef.current[\n carouselSlideAxis === \"x\" ? \"scrollLeft\" : \"scrollTop\"\n ] === getTotalScrollValue()\n ) {\n firstItemReached.current = false;\n lastItemReached.current = true;\n }\n }\n }\n function getScrollHandlers() {\n if (freeScroll) {\n return {\n onWheel() {\n spring.val.stop();\n setStartEndItemReachedOnFreeScroll();\n },\n };\n }\n return {};\n }\n function findItemIndex(id: string) {\n return items.findIndex((item) => item.id === id);\n }\n function findItemIndexById(id: string | number, error: string) {\n let itemIndex = 0;\n if (typeof id === \"string\") {\n itemIndex = items.findIndex((_item) => _item.id === id);\n } else {\n itemIndex = id;\n }\n\n if (itemIndex < 0 || itemIndex >= items.length) {\n throw new Error(error);\n }\n\n return itemIndex;\n }\n function internalSlideToItem(id: string | number) {\n if (!init) return;\n\n firstItemReached.current = false;\n lastItemReached.current = false;\n\n const itemIndex = findItemIndexById(\n id,\n \"The item you want to slide to doesn't exist; please check che item id or the index you're passing to.\"\n );\n\n if (itemIndex === activeItem.current) {\n return;\n }\n\n const currentItem = findItemIndex(items[activeItem.current].id);\n const newActiveItem = findItemIndex(items[itemIndex].id);\n\n if (newActiveItem > currentItem) {\n slideToNextItem(\"click\", newActiveItem);\n } else {\n slideToPrevItem(\"click\", newActiveItem);\n }\n }\n function getIsNextItem(id: string) {\n const itemIndex = findItemIndex(id);\n const _activeItem = activeItem.current;\n if (withLoop && _activeItem === items.length - 1) {\n return itemIndex === 0;\n }\n return itemIndex === _activeItem + 1;\n }\n function getIsPrevItem(id: string) {\n const itemIndex = findItemIndex(id);\n const _activeItem = activeItem.current;\n if (withLoop && _activeItem === 0) {\n return itemIndex === items.length - 1;\n }\n return itemIndex === _activeItem - 1;\n }\n\n const carouselFragment = (\n <div\n ref={mainCarouselWrapperRef}\n {...getScrollHandlers()}\n style={{\n display: \"flex\",\n position: \"relative\",\n width: \"100%\",\n height: \"100%\",\n ...(getWrapperOverflowStyles() as React.CSSProperties),\n }}\n >\n <div\n ref={carouselTrackWrapperRef}\n {...bindDrag()}\n style={{\n position: \"relative\",\n display: \"flex\",\n flexDirection: carouselSlideAxis === \"x\" ? \"row\" : \"column\",\n touchAction: \"none\",\n ...getAnimatedWrapperStyles(),\n }}\n >\n {internalItems.map((item, index) => {\n return (\n <div\n key={`${item.id}-${index}`}\n className=\"use-spring-carousel-item\"\n data-testid=\"use-spring-carousel-item-wrapper\"\n style={{\n display: \"flex\",\n position: \"relative\",\n flex: \"1\",\n ...getItemStyles(),\n }}\n >\n {item.renderItem}\n </div>\n );\n })}\n </div>\n </div>\n );\n\n return {\n useListenToCustomEvent,\n carouselFragment,\n enterFullscreen,\n exitFullscreen,\n getIsFullscreen,\n thumbsFragment,\n slideToItem: internalSlideToItem,\n getIsNextItem,\n getIsPrevItem,\n slideToPrevItem: () => slideToPrevItem(),\n slideToNextItem: () => slideToNextItem(),\n getIsActiveItem: (id: string | number) => {\n return (\n findItemIndexById(id, \"The item you want to check doesn't exist\") ===\n activeItem.current\n );\n },\n };\n}\n\nconst Context =\n createContext<\n Omit<UseSpringReturnType, \"carouselFragment\" | \"thumbsFragment\"> | undefined\n >(undefined);\n\nfunction useSpringCarouselContext() {\n const context = useContext(Context);\n if (!context) {\n throw new Error(\n \"useSpringCarouselContext must be used within the carousel.\"\n );\n }\n return context;\n}\n\nexport { useSpringCarousel, useSpringCarouselContext };\n"],"names":["useSpringCarousel","items","init","withThumbs","thumbsSlideAxis","itemsPerSlide","slideType","gutter","withLoop","startEndGutter","carouselSlideAxis","disableGestures","draggingSlideTreshold","_draggingSlideTreshold","slideWhenThresholdIsReached","freeScroll","enableFreeScrollDrag","initialStartingPosition","prepareThumbsData","initialActiveItem","prevWindowWidth","useRef","slideActionType","slideModeType","prevSlidedValue","spring","setSpring","useSpring","val","pause","onChange","value","mainCarouselWrapperRef","current","setStartEndItemReachedOnFreeScroll","scrollLeft","Math","abs","scrollTop","carouselTrackWrapperRef","style","transform","activeItem","firstItemReached","lastItemReached","internalItems","useCallback","map","i","Object","assign","id","getItems","emitEvent","useListenToCustomEvent","useEventsModule","thumbsFragment","handleScroll","useThumbsModule","enterFullscreen","exitFullscreen","getIsFullscreen","useFullscreenModule","handleResize","adjustCarouselWrapperPosition","getSlideValue","carouselItem","_a","querySelector","Error","getBoundingClientRect","slideToItem","from","to","nextActiveItem","immediate","slideMode","eventName","nextItem","startReached","endReached","index","start","config","default","velocity","onRest","finished","currentItem","getTotalScrollValue","length","round","Number","getCarouselItemWidth","positionProperty","setPosition","v","ref","top","left","currentFromValue","getFromValue","get","getToValue","type","next","slideToPrevItem","nextItemWillExceed","slideToNextItem","useEffect","window","innerWidth","useLayoutEffect","floor","addEventListener","removeEventListener","bindDrag","useDrag","state","isDragging","dragging","movement","offset","currentMovement","direction","prevItemTreshold","nextItemTreshold","cancel","friction","tension","last","canceled","enabled","axis","findItemIndex","findIndex","item","findItemIndexById","error","itemIndex","_item","carouselFragment","_jsx","onWheel","stop","display","position","width","height","overflowX","overflowY","flexDirection","touchAction","percentValue","getAnimatedWrapperStyles","children","className","flex","marginRight","renderItem","newActiveItem","getIsNextItem","_activeItem","getIsPrevItem","getIsActiveItem","Context","createContext","undefined","useSpringCarouselContext","context","useContext"],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EC,GAEJ,SAASC,IACP,MAAMC,EAAUC,EAAWL,GAC3B,IAAKI,EACH,MAAM,IAAIpG,MACR,8DAGJ,OAAOoG,CACT"}
@@ -0,0 +1,2 @@
1
+ import{useRef as e,useEffect as n}from"react";import t from"screenfull";import{jsx as r}from"react/jsx-runtime";import{useSpring as i}from"@react-spring/web";function u(){const t=e(null);return n((()=>{t.current=document.createElement("div")}),[]),{useListenToCustomEvent:function(e){n((()=>{function n(n){e(n.detail)}if(t.current)return t.current.addEventListener("RSC::Event",n,!1),()=>{var e;null===(e=t.current)||void 0===e||e.removeEventListener("RSC::Event",n,!1)}}),[])},emitEvent:function(e){if(t.current){const n=new CustomEvent("RSC::Event",{detail:e});t.current.dispatchEvent(n)}}}}function l({mainCarouselWrapperRef:r,emitEvent:i,handleResize:u}){const l=e(!1);function o(e){l.current=e}return n((()=>{function e(){document.fullscreenElement&&(o(!0),i({eventName:"onFullscreenChange",isFullscreen:!0}),u&&u()),document.fullscreenElement||(o(!1),i({eventName:"onFullscreenChange",isFullscreen:!1}),u&&u())}if(t.isEnabled)return t.on("change",e),()=>{t.isEnabled&&t.off("change",e)}}),[]),{enterFullscreen:function(e){t.isEnabled&&t.request(e||r.current)},exitFullscreen:function(){t.isEnabled&&t.exit()},getIsFullscreen:function(){return l.current}}}function o({thumbsSlideAxis:n="x",withThumbs:t=!1,prepareThumbsData:u,items:l}){const o=e(null),[c,s]=i((()=>({val:0})));function a(){var e;return Math.round(Number(null===(e=o.current)||void 0===e?void 0:e["x"===n?"scrollWidth":"scrollHeight"])-o.current.getBoundingClientRect()["x"===n?"width":"height"])}return{thumbsFragment:t?r("div",Object.assign({className:"use-spring-carousel-thumbs-wrapper",ref:o,onWheel:()=>c.val.stop(),style:Object.assign({display:"flex",flex:"1",position:"relative",width:"100%",height:"100%",flexDirection:"x"===n?"row":"column"},"x"===n?{overflowX:"auto"}:{overflowY:"auto",maxHeight:"100%"})},{children:function(){function e(e){return e.map((e=>({id:e.id,renderThumb:e.renderThumb})))}return u?u(e(l)):e(l)}().map((({id:e,renderThumb:n})=>{const t=`thumb-item-${e}`;return r("div",Object.assign({id:t,className:"thumb-item"},{children:n}),t)}))})):null,handleScroll:function(e){var t,r;const i=o.current?o.current.querySelector(`#thumb-item-${l[e].id}`):null;if(i&&o.current&&!function(e){const n=e.getBoundingClientRect();return n.top>=0&&n.left>=0&&n.bottom<=(window.innerHeight||document.documentElement.clientHeight)&&n.right<=(window.innerWidth||document.documentElement.clientWidth)}(i)){const e=i.offsetLeft,u=e>a()?a():e;s.start({from:{val:null!==(r=null===(t=o.current)||void 0===t?void 0:t["x"===n?"scrollLeft":"scrollTop"])&&void 0!==r?r:0},to:{val:u},onChange:({value:e})=>{o.current&&(o.current["x"===n?"scrollLeft":"scrollTop"]=Math.abs(e.val))}})}}}}export{o as a,l as b,u};
2
+ //# sourceMappingURL=useThumbsModule-ce69c348.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useThumbsModule-ce69c348.js","sources":["../../src/modules/useEventsModule.ts","../../src/modules/useFullscreenModule.ts","../../src/modules/useThumbsModule.tsx"],"sourcesContent":["import { FullGestureState } from \"@use-gesture/react\";\nimport { useEffect, useRef } from \"react\";\nimport { SlideActionType, SlideMode } from \"../types/common\";\n\nconst eventLabel = \"RSC::Event\";\n\ntype OnSlideStartChange = {\n eventName: \"onSlideStartChange\";\n slideActionType: SlideActionType;\n slideMode: SlideMode;\n nextItem: {\n index: number;\n id: string;\n startReached: boolean;\n endReached: boolean;\n };\n};\ntype OnSlideChange = {\n eventName: \"onSlideChange\";\n slideActionType: SlideActionType;\n slideMode: SlideMode;\n currentItem: {\n index: number;\n id: string;\n startReached: boolean;\n endReached: boolean;\n };\n};\ntype OnFullscreenChange = {\n eventName: \"onFullscreenChange\";\n isFullscreen: boolean;\n};\ntype OnDrag = Omit<FullGestureState<\"drag\">, \"event\"> & {\n eventName: \"onDrag\";\n slideActionType: SlideActionType;\n};\n\ntype Events = OnSlideStartChange | OnSlideChange | OnDrag | OnFullscreenChange;\n\ntype EventHandler = (props: Events) => void;\n\nexport type EmitEvent = (event: Events) => void;\nexport type UseListenToCustomEvent = {\n useListenToCustomEvent: (eventHandler: EventHandler) => void;\n emitEvent: (event: Events) => void;\n};\n\nexport function useEventsModule() {\n const targetEvent = useRef<HTMLDivElement | null>(null);\n\n useEffect(() => {\n targetEvent.current = document.createElement(\"div\");\n }, []);\n\n function useListenToCustomEvent(eventHandler: EventHandler) {\n useEffect(() => {\n function handleEvent(event: CustomEvent<Events>) {\n eventHandler(event.detail);\n }\n\n if (targetEvent.current) {\n // @ts-ignore\n targetEvent.current.addEventListener(eventLabel, handleEvent, false);\n return () => {\n // @ts-ignore\n targetEvent.current?.removeEventListener(\n eventLabel,\n handleEvent,\n false\n );\n };\n }\n }, []);\n }\n function emitEvent(event: Events) {\n if (targetEvent.current) {\n const newEvent = new CustomEvent(eventLabel, {\n detail: event,\n });\n targetEvent.current.dispatchEvent(newEvent);\n }\n }\n\n return {\n useListenToCustomEvent,\n emitEvent,\n };\n}\n","import { useRef, MutableRefObject, useEffect } from \"react\";\nimport screenfull from \"screenfull\";\nimport { EmitEvent } from \"./useEventsModule\";\n\ntype FullscreenModule = {\n mainCarouselWrapperRef: MutableRefObject<HTMLDivElement | null>;\n emitEvent: EmitEvent;\n handleResize?(): void;\n};\n\nexport function useFullscreenModule({\n mainCarouselWrapperRef,\n emitEvent,\n handleResize,\n}: FullscreenModule) {\n const isFullscreen = useRef(false);\n\n useEffect(() => {\n function handleFullscreenChange() {\n if (document.fullscreenElement) {\n setIsFullscreen(true);\n emitEvent({\n eventName: \"onFullscreenChange\",\n isFullscreen: true,\n });\n\n handleResize && handleResize();\n }\n\n if (!document.fullscreenElement) {\n setIsFullscreen(false);\n emitEvent({\n eventName: \"onFullscreenChange\",\n isFullscreen: false,\n });\n handleResize && handleResize();\n }\n }\n\n if (screenfull.isEnabled) {\n screenfull.on(\"change\", handleFullscreenChange);\n return () => {\n if (screenfull.isEnabled) {\n screenfull.off(\"change\", handleFullscreenChange);\n }\n };\n }\n }, []);\n\n function setIsFullscreen(_isFullscreen: boolean) {\n isFullscreen.current = _isFullscreen;\n }\n\n function getIsFullscreen() {\n return isFullscreen.current;\n }\n\n function enterFullscreen(elementRef?: HTMLElement) {\n if (screenfull.isEnabled) {\n screenfull.request(\n (elementRef || mainCarouselWrapperRef.current) as Element\n );\n }\n }\n\n function exitFullscreen() {\n screenfull.isEnabled && screenfull.exit();\n }\n\n return {\n enterFullscreen,\n exitFullscreen,\n getIsFullscreen,\n };\n}\n","import { useSpring } from \"@react-spring/web\";\nimport { useRef } from \"react\";\nimport {\n SpringCarouselWithThumbs,\n PrepareThumbsData,\n} from \"src/types/internals\";\n\ntype Props = {\n withThumbs?: boolean;\n thumbsSlideAxis: SpringCarouselWithThumbs[\"thumbsSlideAxis\"];\n prepareThumbsData?: PrepareThumbsData;\n items: SpringCarouselWithThumbs[\"items\"];\n};\n\nfunction isInViewport(el: HTMLElement) {\n const rect = el.getBoundingClientRect();\n return (\n rect.top >= 0 &&\n rect.left >= 0 &&\n rect.bottom <=\n (window.innerHeight || document.documentElement.clientHeight) &&\n rect.right <= (window.innerWidth || document.documentElement.clientWidth)\n );\n}\n\nexport function useThumbsModule({\n thumbsSlideAxis = \"x\",\n withThumbs = false,\n prepareThumbsData,\n items,\n}: Props) {\n const wrapperRef = useRef<HTMLDivElement | null>(null);\n const [spring, setSpring] = useSpring(() => ({\n val: 0,\n }));\n\n function getTotalScrollValue() {\n return Math.round(\n Number(\n wrapperRef.current?.[\n thumbsSlideAxis === \"x\" ? \"scrollWidth\" : \"scrollHeight\"\n ]\n ) -\n wrapperRef.current!.getBoundingClientRect()[\n thumbsSlideAxis === \"x\" ? \"width\" : \"height\"\n ]\n );\n }\n\n function handleScroll(activeItem: number) {\n function getThumbNode() {\n if (wrapperRef.current) {\n return wrapperRef.current.querySelector(\n `#thumb-item-${items[activeItem].id}`\n ) as HTMLElement;\n }\n return null;\n }\n\n const thumbNode = getThumbNode();\n if (thumbNode && wrapperRef.current) {\n if (!isInViewport(thumbNode)) {\n const offset = thumbNode.offsetLeft;\n const val =\n offset > getTotalScrollValue() ? getTotalScrollValue() : offset;\n\n setSpring.start({\n from: {\n val:\n wrapperRef.current?.[\n thumbsSlideAxis === \"x\" ? \"scrollLeft\" : \"scrollTop\"\n ] ?? 0,\n },\n to: {\n val,\n },\n onChange: ({ value }) => {\n if (wrapperRef.current) {\n wrapperRef.current[\n thumbsSlideAxis === \"x\" ? \"scrollLeft\" : \"scrollTop\"\n ] = Math.abs(value.val);\n }\n },\n });\n }\n }\n }\n\n function handlePrepareThumbsData() {\n function getPreparedItems(\n _items: ReturnType<PrepareThumbsData>\n ): ReturnType<PrepareThumbsData> {\n return _items.map((i) => ({\n id: i.id,\n renderThumb: i.renderThumb,\n }));\n }\n\n if (prepareThumbsData) {\n return prepareThumbsData(getPreparedItems(items));\n }\n return getPreparedItems(items);\n }\n\n const thumbsFragment = withThumbs ? (\n <div\n className=\"use-spring-carousel-thumbs-wrapper\"\n ref={wrapperRef}\n onWheel={() => spring.val.stop()}\n style={{\n display: \"flex\",\n flex: \"1\",\n position: \"relative\",\n width: \"100%\",\n height: \"100%\",\n flexDirection: thumbsSlideAxis === \"x\" ? \"row\" : \"column\",\n ...(thumbsSlideAxis === \"x\"\n ? { overflowX: \"auto\" }\n : {\n overflowY: \"auto\",\n maxHeight: \"100%\",\n }),\n }}\n >\n {handlePrepareThumbsData().map(({ id, renderThumb }) => {\n const thumbId = `thumb-item-${id}`;\n return (\n <div key={thumbId} id={thumbId} className=\"thumb-item\">\n {renderThumb}\n </div>\n );\n })}\n </div>\n ) : null;\n\n return {\n thumbsFragment,\n handleScroll,\n };\n}\n"],"names":["useEventsModule","targetEvent","useRef","useEffect","current","document","createElement","useListenToCustomEvent","eventHandler","handleEvent","event","detail","addEventListener","_a","removeEventListener","emitEvent","newEvent","CustomEvent","dispatchEvent","useFullscreenModule","mainCarouselWrapperRef","handleResize","isFullscreen","setIsFullscreen","_isFullscreen","handleFullscreenChange","fullscreenElement","eventName","screenfull","isEnabled","on","off","enterFullscreen","elementRef","request","exitFullscreen","exit","getIsFullscreen","useThumbsModule","thumbsSlideAxis","withThumbs","prepareThumbsData","items","wrapperRef","spring","setSpring","useSpring","val","getTotalScrollValue","Math","round","Number","getBoundingClientRect","thumbsFragment","_jsx","Object","assign","className","ref","onWheel","stop","style","display","flex","position","width","height","flexDirection","overflowX","overflowY","maxHeight","children","getPreparedItems","_items","map","i","id","renderThumb","handlePrepareThumbsData","thumbId","handleScroll","activeItem","thumbNode","querySelector","el","rect","top","left","bottom","window","innerHeight","documentElement","clientHeight","right","innerWidth","clientWidth","isInViewport","offset","offsetLeft","start","from","to","onChange","value","abs"],"mappings":"uKA+CgBA,IACd,MAAMC,EAAcC,EAA8B,MAmClD,OAjCAC,GAAU,KACRF,EAAYG,QAAUC,SAASC,cAAc,MAAM,GAClD,IA+BI,CACLC,uBA9BF,SAAgCC,GAC9BL,GAAU,KACR,SAASM,EAAYC,GACnBF,EAAaE,EAAMC,OACpB,CAED,GAAIV,EAAYG,QAGd,OADAH,EAAYG,QAAQQ,iBA1DT,aA0DsCH,GAAa,GACvD,WAEc,QAAnBI,EAAAZ,EAAYG,eAAO,IAAAS,GAAAA,EAAEC,oBA7DZ,aA+DPL,GACA,EACD,CAEJ,GACA,GACJ,EAYCM,UAXF,SAAmBL,GACjB,GAAIT,EAAYG,QAAS,CACvB,MAAMY,EAAW,IAAIC,YAxER,aAwEgC,CAC3CN,OAAQD,IAEVT,EAAYG,QAAQc,cAAcF,EACnC,CACF,EAMH,CC7EM,SAAUG,GAAoBC,uBAClCA,EAAsBL,UACtBA,EAASM,aACTA,IAEA,MAAMC,EAAepB,GAAO,GAkC5B,SAASqB,EAAgBC,GACvBF,EAAalB,QAAUoB,CACxB,CAkBD,OApDArB,GAAU,KACR,SAASsB,IACHpB,SAASqB,oBACXH,GAAgB,GAChBR,EAAU,CACRY,UAAW,qBACXL,cAAc,IA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ErC8B,EAAiB9B,EACzB,CAsBIoC,GAA0BJ,KAAI,EAAGE,KAAIC,kBACpC,MAAME,EAAU,cAAcH,IAC9B,OACEtB,EAAA,MAAAC,OAAAC,OAAA,CAAmBoB,GAAIG,EAAStB,UAAU,wBACvCoB,IADOE,EAGV,OAGJ,KAIFC,aAxFF,SAAsBC,WAUpB,MAAMC,EARAvC,EAAWvC,QACNuC,EAAWvC,QAAQ+E,cACxB,eAAezC,EAAMuC,GAAYL,MAG9B,KAIT,GAAIM,GAAavC,EAAWvC,UA9ChC,SAAsBgF,GACpB,MAAMC,EAAOD,EAAGhC,wBAChB,OACEiC,EAAKC,KAAO,GACZD,EAAKE,MAAQ,GACbF,EAAKG,SACFC,OAAOC,aAAerF,SAASsF,gBAAgBC,eAClDP,EAAKQ,QAAUJ,OAAOK,YAAczF,SAASsF,gBAAgBI,YAEjE,CAsCWC,CAAad,GAAY,CAC5B,MAAMe,EAASf,EAAUgB,WACnBnD,EACJkD,EAASjD,IAAwBA,IAAwBiD,EAE3DpD,EAAUsD,MAAM,CACdC,KAAM,CACJrD,cACoB,QAAlBlC,EAAA8B,EAAWvC,eAAO,IAAAS,OAAA,EAAAA,EACI,MAApB0B,EAA0B,aAAe,4BACtC,GAET8D,GAAI,CACFtD,OAEFuD,SAAU,EAAGC,YACP5D,EAAWvC,UACbuC,EAAWvC,QACW,MAApBmC,EAA0B,aAAe,aACvCU,KAAKuD,IAAID,EAAMxD,KACpB,GAGN,CAEJ,EAqDH"}
@@ -1,2 +1 @@
1
1
  export * from './useSpringCarousel';
2
- export * from './useTransitionCarousel';
@@ -0,0 +1,10 @@
1
+ /// <reference types="react" />
2
+ export declare const mockedItems: ({
3
+ id: string;
4
+ renderThumb: JSX.Element;
5
+ renderItem: JSX.Element;
6
+ } | {
7
+ id: string;
8
+ renderItem: JSX.Element;
9
+ renderThumb?: undefined;
10
+ })[];
@@ -1,3 +1,3 @@
1
- export * from './useCustomEventsModule';
1
+ export * from './useEventsModule';
2
2
  export * from './useFullscreenModule';
3
3
  export * from './useThumbsModule';
@@ -0,0 +1,44 @@
1
+ import { FullGestureState } from "@use-gesture/react";
2
+ import { SlideActionType, SlideMode } from "../types/common";
3
+ declare type OnSlideStartChange = {
4
+ eventName: "onSlideStartChange";
5
+ slideActionType: SlideActionType;
6
+ slideMode: SlideMode;
7
+ nextItem: {
8
+ index: number;
9
+ id: string;
10
+ startReached: boolean;
11
+ endReached: boolean;
12
+ };
13
+ };
14
+ declare type OnSlideChange = {
15
+ eventName: "onSlideChange";
16
+ slideActionType: SlideActionType;
17
+ slideMode: SlideMode;
18
+ currentItem: {
19
+ index: number;
20
+ id: string;
21
+ startReached: boolean;
22
+ endReached: boolean;
23
+ };
24
+ };
25
+ declare type OnFullscreenChange = {
26
+ eventName: "onFullscreenChange";
27
+ isFullscreen: boolean;
28
+ };
29
+ declare type OnDrag = Omit<FullGestureState<"drag">, "event"> & {
30
+ eventName: "onDrag";
31
+ slideActionType: SlideActionType;
32
+ };
33
+ declare type Events = OnSlideStartChange | OnSlideChange | OnDrag | OnFullscreenChange;
34
+ declare type EventHandler = (props: Events) => void;
35
+ export declare type EmitEvent = (event: Events) => void;
36
+ export declare type UseListenToCustomEvent = {
37
+ useListenToCustomEvent: (eventHandler: EventHandler) => void;
38
+ emitEvent: (event: Events) => void;
39
+ };
40
+ export declare function useEventsModule(): {
41
+ useListenToCustomEvent: (eventHandler: EventHandler) => void;
42
+ emitEvent: (event: Events) => void;
43
+ };
44
+ export {};
@@ -1,12 +1,12 @@
1
- import { MutableRefObject } from 'react';
2
- import { EmitObservableFn } from '../types';
3
- declare type FullscreenModule<T> = {
1
+ import { MutableRefObject } from "react";
2
+ import { EmitEvent } from "./useEventsModule";
3
+ declare type FullscreenModule = {
4
4
  mainCarouselWrapperRef: MutableRefObject<HTMLDivElement | null>;
5
- emitObservable: EmitObservableFn<T>;
5
+ emitEvent: EmitEvent;
6
6
  handleResize?(): void;
7
7
  };
8
- export declare function useFullscreenModule<T>({ mainCarouselWrapperRef, emitObservable, handleResize, }: FullscreenModule<T>): {
9
- enterFullscreen: (elementRef?: HTMLElement | undefined) => void;
8
+ export declare function useFullscreenModule({ mainCarouselWrapperRef, emitEvent, handleResize, }: FullscreenModule): {
9
+ enterFullscreen: (elementRef?: HTMLElement) => void;
10
10
  exitFullscreen: () => void;
11
11
  getIsFullscreen: () => boolean;
12
12
  };
@@ -1,19 +1,13 @@
1
1
  /// <reference types="react" />
2
- import { SpringConfig } from 'react-spring';
3
- import { UseSpringCarouselProps, SlideActionType } from '../types';
4
- import { ReactSpringCarouselItemWithThumbs } from '../types/useSpringCarousel';
2
+ import { SpringCarouselWithThumbs, PrepareThumbsData } from "src/types/internals";
5
3
  declare type Props = {
6
- items: ReactSpringCarouselItemWithThumbs[];
7
- withThumbs: boolean;
8
- slideType: UseSpringCarouselProps['slideType'];
9
- thumbsSlideAxis: UseSpringCarouselProps['thumbsSlideAxis'];
10
- springConfig: SpringConfig;
11
- prepareThumbsData?: UseSpringCarouselProps['prepareThumbsData'];
12
- getFluidWrapperScrollValue?(): number;
13
- getSlideValue?(): number;
4
+ withThumbs?: boolean;
5
+ thumbsSlideAxis: SpringCarouselWithThumbs["thumbsSlideAxis"];
6
+ prepareThumbsData?: PrepareThumbsData;
7
+ items: SpringCarouselWithThumbs["items"];
14
8
  };
15
- export declare function useThumbsModule({ items, withThumbs, thumbsSlideAxis, springConfig, prepareThumbsData, getFluidWrapperScrollValue, getSlideValue, slideType, }: Props): {
9
+ export declare function useThumbsModule({ thumbsSlideAxis, withThumbs, prepareThumbsData, items, }: Props): {
16
10
  thumbsFragment: JSX.Element | null;
17
- handleThumbsScroll: (activeItem: number, actionType?: SlideActionType | undefined) => void;
11
+ handleScroll: (activeItem: number) => void;
18
12
  };
19
13
  export {};
@@ -0,0 +1,2 @@
1
+ export declare type SlideActionType = "prev" | "next" | "initial";
2
+ export declare type SlideMode = "drag" | "click" | "initial";
@@ -1,51 +1,10 @@
1
- import { FullGestureState } from '@use-gesture/react';
2
- import { ReactSpringCarouselItemWithThumbs } from './useSpringCarousel';
3
- export declare type PrepareThumbsData = (items: Omit<ReactSpringCarouselItemWithThumbs, 'renderItem'>[]) => Omit<ReactSpringCarouselItemWithThumbs, 'renderItem'>[];
4
- export declare type SlideToItemFnProps = {
5
- from?: number;
6
- to?: number;
7
- newIndex?: number;
8
- immediate?: boolean;
9
- customTo?: number;
10
- velocity?: number[];
11
- onRest?(): void;
1
+ import { ReactNode } from "react";
2
+ export declare type ItemWithThumb = {
3
+ id: string;
4
+ renderItem: ReactNode;
5
+ renderThumb: ReactNode;
12
6
  };
13
- export declare type SlideActionType = 'prev' | 'next';
14
- declare type OnSlideStartChange = {
15
- eventName: 'onSlideStartChange';
16
- slideActionType: SlideActionType;
17
- nextItem: {
18
- index: number;
19
- id: string;
20
- };
7
+ export declare type ItemWithNoThumb = {
8
+ id: string;
9
+ renderItem: ReactNode;
21
10
  };
22
- declare type OnSlideChange = {
23
- eventName: 'onSlideChange';
24
- slideActionType: SlideActionType;
25
- currentItem: {
26
- index: number;
27
- id: string;
28
- };
29
- };
30
- declare type OnDrag = Omit<FullGestureState<'drag'>, 'event'> & {
31
- eventName: 'onDrag';
32
- slideActionType: SlideActionType;
33
- };
34
- declare type OnFullscreenChange = {
35
- eventName: 'onFullscreenChange';
36
- isFullscreen: boolean;
37
- };
38
- declare type OnLeftSwipe = {
39
- eventName: 'onLeftSwipe';
40
- };
41
- declare type OnRightSwipe = {
42
- eventName: 'onRightSwipe';
43
- };
44
- export declare type UseSpringCarouselEventsObservableProps = OnSlideStartChange | OnSlideChange | OnDrag | OnFullscreenChange;
45
- export declare type UseTransitionCarouselEventsObservableProps = OnSlideStartChange | OnSlideChange | OnFullscreenChange | OnLeftSwipe | OnRightSwipe;
46
- declare type CombinedProps<T> = T extends 'use-spring' ? UseSpringCarouselEventsObservableProps : UseTransitionCarouselEventsObservableProps;
47
- export declare type EmitObservableFn<T> = (data: CombinedProps<T>) => void;
48
- export declare type ObservableCallbackFn<T> = (data: CombinedProps<T>) => void;
49
- export declare type UseListenToCustomEvent<T> = (fn: ObservableCallbackFn<T>) => void;
50
- export * from './useSpringCarousel';
51
- export * from './useTransitionCarousel';
@@ -0,0 +1,82 @@
1
+ import { ReactNode } from "react";
2
+ import { ItemWithThumb, ItemWithNoThumb } from "./";
3
+ import { UseListenToCustomEvent } from "../modules/useEventsModule";
4
+ export declare type UseSpringReturnType = {
5
+ carouselFragment: ReactNode;
6
+ thumbsFragment: ReactNode;
7
+ useListenToCustomEvent: UseListenToCustomEvent["useListenToCustomEvent"];
8
+ getIsFullscreen(): boolean;
9
+ getIsPrevItem(id: string): boolean;
10
+ getIsNextItem(id: string): boolean;
11
+ enterFullscreen(ref?: HTMLElement): void;
12
+ exitFullscreen(): void;
13
+ slideToNextItem(): void;
14
+ slideToPrevItem(): void;
15
+ slideToItem(item: string | number): void;
16
+ getIsActiveItem(id: string): boolean;
17
+ };
18
+ export declare type PrepareThumbsData = (items: Omit<ItemWithThumb, "renderItem">[]) => Omit<ItemWithThumb, "renderItem">[];
19
+ export declare type SpringCarouselWithThumbs = {
20
+ withThumbs: true;
21
+ thumbsSlideAxis?: "x" | "y";
22
+ items: ItemWithThumb[];
23
+ prepareThumbsData?: PrepareThumbsData;
24
+ };
25
+ export declare type SpringCarouselWithNoThumbs = {
26
+ withThumbs?: false | undefined;
27
+ thumbsSlideAxis?: never;
28
+ items: ItemWithNoThumb[];
29
+ prepareThumbsData?: never;
30
+ };
31
+ export declare type SpringCarouselWithFixedItems = {
32
+ slideType?: "fixed";
33
+ itemsPerSlide?: number;
34
+ startEndGutter?: number;
35
+ initialStartingPosition?: "start" | "center" | "end";
36
+ initialActiveItem?: number;
37
+ };
38
+ export declare type SpringCarouselWithNoFixedItems = {
39
+ slideType?: "fluid";
40
+ startEndGutter?: never;
41
+ initialStartingPosition?: never;
42
+ initialActiveItem?: never;
43
+ itemsPerSlide?: never;
44
+ };
45
+ export declare type SpringCarouselWithLoop = {
46
+ withLoop?: true;
47
+ };
48
+ export declare type SpringCarouselWithNoLoop = {
49
+ withLoop?: false;
50
+ };
51
+ export declare type SpringCarouselFreeScroll = {
52
+ freeScroll?: true;
53
+ withLoop?: never;
54
+ slideType?: never;
55
+ enableFreeScrollDrag?: true;
56
+ };
57
+ export declare type SpringCarouselNoFreeScroll = {
58
+ freeScroll?: never;
59
+ withLoop?: boolean;
60
+ slideType?: "fixed" | "fluid";
61
+ enableFreeScrollDrag?: never;
62
+ };
63
+ export declare type BaseProps = {
64
+ init?: boolean;
65
+ gutter?: number;
66
+ carouselSlideAxis?: "x" | "y";
67
+ draggingSlideTreshold?: number;
68
+ slideWhenThresholdIsReached?: boolean;
69
+ disableGestures?: boolean;
70
+ };
71
+ export declare type UseSpringCarouselWithThumbs = BaseProps & SpringCarouselWithThumbs & (SpringCarouselWithFixedItems | SpringCarouselWithNoFixedItems) & (SpringCarouselWithLoop | SpringCarouselWithNoLoop) & (SpringCarouselFreeScroll | SpringCarouselNoFreeScroll);
72
+ export declare type UseSpringCarouselWithNoThumbs = BaseProps & SpringCarouselWithNoThumbs & (SpringCarouselWithFixedItems | SpringCarouselWithNoFixedItems) & (SpringCarouselWithLoop | SpringCarouselWithNoLoop) & (SpringCarouselFreeScroll | SpringCarouselNoFreeScroll);
73
+ export declare type UseSpringCarouselWithFixedItems = BaseProps & (SpringCarouselWithThumbs | SpringCarouselWithNoThumbs) & SpringCarouselWithFixedItems & (SpringCarouselWithLoop | SpringCarouselWithNoLoop) & (SpringCarouselFreeScroll | SpringCarouselNoFreeScroll);
74
+ export declare type UseSpringCarouselWithNoFixedItems = BaseProps & (SpringCarouselWithThumbs | SpringCarouselWithNoThumbs) & SpringCarouselWithNoFixedItems & (SpringCarouselWithLoop | SpringCarouselWithNoLoop) & (SpringCarouselFreeScroll | SpringCarouselNoFreeScroll);
75
+ export declare type UseSpringCarouselComplete = BaseProps & {
76
+ thumbsSlideAxis?: "x" | "y";
77
+ itemsPerSlide?: number;
78
+ startEndGutter?: number;
79
+ initialStartingPosition?: "start" | "center" | "end";
80
+ prepareThumbsData?: PrepareThumbsData;
81
+ initialActiveItem?: number;
82
+ } & (SpringCarouselWithThumbs | SpringCarouselWithNoThumbs) & (SpringCarouselWithFixedItems | SpringCarouselWithNoFixedItems) & (SpringCarouselWithLoop | SpringCarouselWithNoLoop) & (SpringCarouselFreeScroll | SpringCarouselNoFreeScroll);
@@ -0,0 +1,7 @@
1
+ import { UseSpringReturnType, UseSpringCarouselWithThumbs, UseSpringCarouselWithNoThumbs, UseSpringCarouselWithFixedItems, UseSpringCarouselWithNoFixedItems } from "./types/internals";
2
+ declare function useSpringCarousel(props: UseSpringCarouselWithThumbs): UseSpringReturnType;
3
+ declare function useSpringCarousel(props: UseSpringCarouselWithNoThumbs): UseSpringReturnType;
4
+ declare function useSpringCarousel(props: UseSpringCarouselWithFixedItems): UseSpringReturnType;
5
+ declare function useSpringCarousel(props: UseSpringCarouselWithNoFixedItems): UseSpringReturnType;
6
+ declare function useSpringCarouselContext(): Omit<UseSpringReturnType, "thumbsFragment" | "carouselFragment">;
7
+ export { useSpringCarousel, useSpringCarouselContext };