react-spring-carousel 2.0.19 → 3.0.0-beta-1.0.0

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 (65) hide show
  1. package/.storybook/main.ts +17 -0
  2. package/.storybook/preview.ts +15 -0
  3. package/README.md +39 -43
  4. package/eslint.config.js +28 -0
  5. package/index.html +13 -0
  6. package/lib/events.ts +39 -0
  7. package/lib/index.tsx +980 -0
  8. package/lib/types.ts +44 -0
  9. package/lib/useEventsModule.ts +51 -0
  10. package/lib/utils.ts +42 -0
  11. package/lib/vite-env.d.ts +1 -0
  12. package/package.json +41 -99
  13. package/src/stories/Button.stories.ts +52 -0
  14. package/src/stories/Button.tsx +48 -0
  15. package/src/stories/Configure.mdx +364 -0
  16. package/src/stories/Main.stories.ts +14 -0
  17. package/src/stories/Main.tsx +87 -0
  18. package/src/stories/assets/accessibility.png +0 -0
  19. package/src/stories/assets/accessibility.svg +1 -0
  20. package/src/stories/assets/addon-library.png +0 -0
  21. package/src/stories/assets/assets.png +0 -0
  22. package/src/stories/assets/avif-test-image.avif +0 -0
  23. package/src/stories/assets/context.png +0 -0
  24. package/src/stories/assets/discord.svg +1 -0
  25. package/src/stories/assets/docs.png +0 -0
  26. package/src/stories/assets/figma-plugin.png +0 -0
  27. package/src/stories/assets/github.svg +1 -0
  28. package/src/stories/assets/share.png +0 -0
  29. package/src/stories/assets/styling.png +0 -0
  30. package/src/stories/assets/testing.png +0 -0
  31. package/src/stories/assets/theming.png +0 -0
  32. package/src/stories/assets/tutorials.svg +1 -0
  33. package/src/stories/assets/youtube.svg +1 -0
  34. package/src/stories/button.css +30 -0
  35. package/src/stories/main.css +37 -0
  36. package/src/storybook.global.styles.css +5 -0
  37. package/tsconfig.app.json +24 -0
  38. package/tsconfig.json +7 -0
  39. package/tsconfig.node.json +22 -0
  40. package/vite.config.ts +30 -0
  41. package/dist/cjs/index.js +0 -2
  42. package/dist/cjs/index.js.map +0 -1
  43. package/dist/esm/index.js +0 -2
  44. package/dist/esm/index.js.map +0 -1
  45. package/dist/esm/index2.js +0 -2
  46. package/dist/esm/index2.js.map +0 -1
  47. package/dist/esm/index3.js +0 -2
  48. package/dist/esm/index3.js.map +0 -1
  49. package/dist/esm/index4.js +0 -2
  50. package/dist/esm/index4.js.map +0 -1
  51. package/dist/esm/useThumbsModule-0944decf.js +0 -2
  52. package/dist/esm/useThumbsModule-0944decf.js.map +0 -1
  53. package/dist/types/index.d.ts +0 -2
  54. package/dist/types/modules/index.d.ts +0 -3
  55. package/dist/types/modules/useCustomEventsModule.d.ts +0 -5
  56. package/dist/types/modules/useFullscreenModule.d.ts +0 -13
  57. package/dist/types/modules/useThumbsModule.d.ts +0 -19
  58. package/dist/types/types/index.d.ts +0 -51
  59. package/dist/types/types/useSpringCarousel.d.ts +0 -124
  60. package/dist/types/types/useTransitionCarousel.d.ts +0 -39
  61. package/dist/types/useSpringCarousel/index.d.ts +0 -8
  62. package/dist/types/useTransitionCarousel/index.d.ts +0 -24
  63. package/dist/types/utils.d.ts +0 -5
  64. package/dist/umd/index.js +0 -2
  65. package/dist/umd/index.js.map +0 -1
@@ -1 +0,0 @@
1
- {"version":3,"file":"useThumbsModule-0944decf.js","sources":["../../src/modules/useCustomEventsModule.tsx","../../src/utils.ts","../../src/modules/useFullscreenModule.tsx","../../src/modules/useThumbsModule.tsx"],"sourcesContent":["import { useEffect, useRef } from 'react'\nimport { Subject } from 'rxjs'\nimport {\n UseSpringCarouselEventsObservableProps,\n UseTransitionCarouselEventsObservableProps,\n ObservableCallbackFn,\n EmitObservableFn,\n} from '../types'\n\nexport function useCustomEventsModule<T>() {\n const eventsObserverRef = useRef(\n new Subject<\n T extends 'use-spring'\n ? UseSpringCarouselEventsObservableProps\n : UseTransitionCarouselEventsObservableProps\n >(),\n )\n\n function useListenToCustomEvent(fn: ObservableCallbackFn<T>) {\n useEffect(() => {\n const subscribe = eventsObserverRef.current.subscribe(fn)\n return () => subscribe.unsubscribe()\n }, [fn])\n }\n\n const emitObservable: EmitObservableFn<T> = data => {\n eventsObserverRef.current.next(data)\n }\n\n return {\n useListenToCustomEvent,\n emitObservable,\n }\n}\n","import { useRef, useLayoutEffect, useEffect } from 'react'\n\ntype Callback = () => void | (() => void)\n\nconst useIsomorphicLayoutEffect =\n typeof window !== 'undefined' ? useLayoutEffect : useEffect\n\nfunction useIsomorphicMount(callback: Callback) {\n const isMounted = useRef(false)\n\n useIsomorphicLayoutEffect(() => {\n if (!isMounted.current) {\n const clean = callback()\n isMounted.current = true\n\n return () => {\n clean && clean()\n }\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [])\n}\n\nexport { useIsomorphicLayoutEffect, useIsomorphicMount }\n","import { useRef, MutableRefObject } from 'react'\nimport screenfull from 'screenfull'\nimport { EmitObservableFn } from '../types'\nimport { useIsomorphicMount } from '../utils'\n\ntype FullscreenModule<T> = {\n mainCarouselWrapperRef: MutableRefObject<HTMLDivElement | null>\n emitObservable: EmitObservableFn<T>\n handleResize?(): void\n}\n\nexport function useFullscreenModule<T>({\n mainCarouselWrapperRef,\n emitObservable,\n handleResize,\n}: FullscreenModule<T>) {\n const isFullscreen = useRef(false)\n\n useIsomorphicMount(() => {\n function handleFullscreenChange() {\n if (document.fullscreenElement) {\n setIsFullscreen(true)\n emitObservable({\n eventName: 'onFullscreenChange',\n isFullscreen: true,\n })\n\n handleResize && handleResize()\n }\n\n if (!document.fullscreenElement) {\n setIsFullscreen(false)\n emitObservable({\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((elementRef || mainCarouselWrapperRef.current) as Element)\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 { useRef } from 'react'\nimport { useSpring, SpringConfig, animated } from 'react-spring'\nimport { useIsomorphicMount } from 'src/utils'\nimport { UseSpringCarouselProps, SlideActionType } from '../types'\nimport { ReactSpringCarouselItemWithThumbs } from '../types/useSpringCarousel'\nimport { PrepareThumbsData } from '../types/index'\n\ntype OffsetDimension = 'offsetWidth' | 'offsetHeight'\ntype OffsetDirection = 'offsetLeft' | 'offsetTop'\ntype ScrollDirection = 'scrollLeft' | 'scrollTop'\n\ntype Props = {\n items: ReactSpringCarouselItemWithThumbs[]\n withThumbs: boolean\n slideType: UseSpringCarouselProps['slideType']\n thumbsSlideAxis: UseSpringCarouselProps['thumbsSlideAxis']\n springConfig: SpringConfig\n prepareThumbsData?: UseSpringCarouselProps['prepareThumbsData']\n getFluidWrapperScrollValue?(): number\n getSlideValue?(): number\n}\n\nexport function useThumbsModule({\n items,\n withThumbs,\n thumbsSlideAxis = 'x',\n springConfig,\n prepareThumbsData,\n getFluidWrapperScrollValue = () => 0,\n getSlideValue = () => 0,\n slideType,\n}: Props) {\n const internalThumbsWrapperRef = useRef<HTMLDivElement | null>(null)\n const [thumbListStyles, setThumbListStyles] = useSpring(() => ({\n x: 0,\n y: 0,\n config: springConfig,\n onChange: ({ value }) => {\n if (internalThumbsWrapperRef.current && slideType === 'fluid') {\n internalThumbsWrapperRef.current[\n thumbsSlideAxis === 'x' ? 'scrollLeft' : 'scrollTop'\n ] = Math.abs(value[thumbsSlideAxis])\n }\n },\n }))\n\n useIsomorphicMount(() => {\n if (withThumbs && !internalThumbsWrapperRef.current) {\n throw new Error(\n \"The thumbs wrapper is not defined. If you've passed a Functional component, be sure to wrap your component in forwardRef.\",\n )\n }\n })\n\n function getCurrentThumbScrollValue() {\n return internalThumbsWrapperRef.current![\n thumbsSlideAxis === 'x' ? 'scrollLeft' : 'scrollTop'\n ]\n }\n function getThumbsTotalScrollableValue() {\n return Math.round(\n Number(\n internalThumbsWrapperRef.current?.[\n thumbsSlideAxis === 'x' ? 'scrollWidth' : 'scrollHeight'\n ],\n ) -\n internalThumbsWrapperRef.current!.getBoundingClientRect()[\n thumbsSlideAxis === 'x' ? 'width' : 'height'\n ],\n )\n }\n\n function getThumbSlideValue() {\n const thumbSlideTotal = Math.round(getFluidWrapperScrollValue() / getSlideValue())\n const totalScrollableValue = getThumbsTotalScrollableValue()\n return totalScrollableValue / thumbSlideTotal\n }\n\n function handleThumbsScroll(activeItem: number, actionType?: SlideActionType) {\n if (slideType === 'fluid') {\n const totalScrollableValue = getThumbsTotalScrollableValue()\n\n if (actionType === 'next') {\n const nextValue = getCurrentThumbScrollValue() + getThumbSlideValue()\n setThumbListStyles.start({\n from: {\n [thumbsSlideAxis]: getCurrentThumbScrollValue(),\n },\n to: {\n [thumbsSlideAxis]:\n nextValue > totalScrollableValue ? totalScrollableValue : nextValue,\n },\n })\n }\n if (actionType === 'prev') {\n const nextValue = getCurrentThumbScrollValue() - getThumbSlideValue()\n setThumbListStyles.start({\n from: {\n [thumbsSlideAxis]: getCurrentThumbScrollValue(),\n },\n to: {\n [thumbsSlideAxis]: nextValue < 0 ? 0 : nextValue,\n },\n })\n }\n } else {\n function getOffsetDirection() {\n return thumbsSlideAxis === 'x' ? 'offsetLeft' : 'offsetTop'\n }\n function getOffsetDimension() {\n return thumbsSlideAxis === 'x' ? 'offsetWidth' : 'offsetHeight'\n }\n function getScrollDirecton() {\n return thumbsSlideAxis === 'x' ? 'scrollLeft' : 'scrollTop'\n }\n function getThumbNode() {\n return internalThumbsWrapperRef.current!.querySelector(\n `#thumb-${items[activeItem].id}`,\n ) as HTMLElement\n }\n function getThumbOffsetPosition({\n thumbNode,\n offsetDirection,\n offsetDimension,\n }: {\n thumbNode: HTMLElement\n offsetDirection: OffsetDirection\n offsetDimension: OffsetDimension\n }) {\n return thumbNode[offsetDirection] + thumbNode[offsetDimension] / 2\n }\n function getThumbScrollDimension({\n thumbWrapper,\n offsetDimension,\n }: {\n thumbWrapper: HTMLDivElement\n offsetDimension: OffsetDimension\n }) {\n return thumbWrapper[offsetDimension] / 2\n }\n function getScrollFromValue({\n thumbWrapper,\n scrollDirection,\n }: {\n thumbWrapper: HTMLDivElement\n scrollDirection: ScrollDirection\n }) {\n return thumbWrapper[scrollDirection]\n }\n function getScrollToValue({\n thumbWrapper,\n thumbOffsetPosition,\n thumbScrollDimension,\n offsetDimension,\n }: {\n thumbWrapper: HTMLDivElement\n thumbOffsetPosition: number\n thumbScrollDimension: number\n offsetDimension: OffsetDimension\n }) {\n const scrollDimensionProperty =\n thumbsSlideAxis === 'x' ? 'scrollWidth' : 'scrollHeight'\n\n if (\n activeItem === items.length - 1 ||\n thumbOffsetPosition - thumbScrollDimension >\n thumbWrapper[scrollDimensionProperty] - thumbWrapper[offsetDimension]\n ) {\n return thumbWrapper[scrollDimensionProperty] - thumbWrapper[offsetDimension]\n }\n if (activeItem === 0) {\n return 0\n }\n\n return thumbOffsetPosition - thumbScrollDimension\n }\n\n const thumbNode = getThumbNode()\n\n if (thumbNode) {\n const thumbWrapper = internalThumbsWrapperRef.current!\n const offsetDirection = getOffsetDirection()\n const offsetDimension = getOffsetDimension()\n const scrollDirection = getScrollDirecton()\n const thumbOffsetPosition = getThumbOffsetPosition({\n thumbNode,\n offsetDimension,\n offsetDirection,\n })\n const thumbScrollDimension = getThumbScrollDimension({\n thumbWrapper,\n offsetDimension,\n })\n\n const fromValue = getScrollFromValue({\n thumbWrapper,\n scrollDirection,\n })\n const toValue = getScrollToValue({\n thumbWrapper,\n thumbOffsetPosition,\n thumbScrollDimension,\n offsetDimension,\n })\n\n setThumbListStyles.start({\n from: {\n [thumbsSlideAxis]: fromValue,\n },\n to: {\n [thumbsSlideAxis]: actionType === 'prev' && toValue < 0 ? 0 : toValue,\n },\n onChange: ({ value }) => {\n if (thumbsSlideAxis === 'x') {\n internalThumbsWrapperRef!.current!.scrollLeft = value.x\n } else {\n internalThumbsWrapperRef!.current!.scrollTop = value.y\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 <animated.div\n ref={internalThumbsWrapperRef}\n className=\"use-spring-carousel-thumbs-wrapper\"\n onWheel={() => {\n thumbListStyles[thumbsSlideAxis].stop()\n }}\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-${id}`\n return (\n <div key={thumbId} id={thumbId} className=\"thumb-item\">\n {renderThumb}\n </div>\n )\n })}\n </animated.div>\n ) : null\n\n return {\n thumbsFragment,\n handleThumbsScroll,\n }\n}\n"],"names":["useCustomEventsModule","eventsObserverRef","useRef","Subject","useListenToCustomEvent","fn","useEffect","subscribe","current","unsubscribe","emitObservable","data","next","useIsomorphicLayoutEffect","window","useLayoutEffect","useIsomorphicMount","callback","isMounted","clean","useFullscreenModule","mainCarouselWrapperRef","handleResize","isFullscreen","setIsFullscreen","_isFullscreen","handleFullscreenChange","document","fullscreenElement","eventName","screenfull","isEnabled","on","off","enterFullscreen","elementRef","request","exitFullscreen","exit","getIsFullscreen","useThumbsModule","items","withThumbs","thumbsSlideAxis","springConfig","prepareThumbsData","getFluidWrapperScrollValue","getSlideValue","slideType","internalThumbsWrapperRef","thumbListStyles","setThumbListStyles","useSpring","x","y","config","onChange","value","Math","abs","getCurrentThumbScrollValue","getThumbsTotalScrollableValue","round","Number","getBoundingClientRect","getThumbSlideValue","thumbSlideTotal","Error","thumbsFragment","_jsx","animated","div","ref","className","onWheel","stop","style","display","flex","position","width","height","flexDirection","overflowX","overflowY","maxHeight","getPreparedItems","_items","map","i","id","renderThumb","handlePrepareThumbsData","thumbId","handleThumbsScroll","activeItem","actionType","totalScrollableValue","nextValue","start","from","[object Object]","to","thumbNode","querySelector","thumbWrapper","offsetDimension","scrollDirection","thumbOffsetPosition","offsetDirection","getThumbOffsetPosition","thumbScrollDimension","getThumbScrollDimension","fromValue","getScrollFromValue","toValue","scrollDimensionProperty","length","getScrollToValue","scrollLeft","scrollTop"],"mappings":"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"}
@@ -1,2 +0,0 @@
1
- export * from './useSpringCarousel';
2
- export * from './useTransitionCarousel';
@@ -1,3 +0,0 @@
1
- export * from './useCustomEventsModule';
2
- export * from './useFullscreenModule';
3
- export * from './useThumbsModule';
@@ -1,5 +0,0 @@
1
- import { ObservableCallbackFn, EmitObservableFn } from '../types';
2
- export declare function useCustomEventsModule<T>(): {
3
- useListenToCustomEvent: (fn: ObservableCallbackFn<T>) => void;
4
- emitObservable: EmitObservableFn<T>;
5
- };
@@ -1,13 +0,0 @@
1
- import { MutableRefObject } from 'react';
2
- import { EmitObservableFn } from '../types';
3
- declare type FullscreenModule<T> = {
4
- mainCarouselWrapperRef: MutableRefObject<HTMLDivElement | null>;
5
- emitObservable: EmitObservableFn<T>;
6
- handleResize?(): void;
7
- };
8
- export declare function useFullscreenModule<T>({ mainCarouselWrapperRef, emitObservable, handleResize, }: FullscreenModule<T>): {
9
- enterFullscreen: (elementRef?: HTMLElement | undefined) => void;
10
- exitFullscreen: () => void;
11
- getIsFullscreen: () => boolean;
12
- };
13
- export {};
@@ -1,19 +0,0 @@
1
- /// <reference types="react" />
2
- import { SpringConfig } from 'react-spring';
3
- import { UseSpringCarouselProps, SlideActionType } from '../types';
4
- import { ReactSpringCarouselItemWithThumbs } from '../types/useSpringCarousel';
5
- 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;
14
- };
15
- export declare function useThumbsModule({ items, withThumbs, thumbsSlideAxis, springConfig, prepareThumbsData, getFluidWrapperScrollValue, getSlideValue, slideType, }: Props): {
16
- thumbsFragment: JSX.Element | null;
17
- handleThumbsScroll: (activeItem: number, actionType?: SlideActionType | undefined) => void;
18
- };
19
- export {};
@@ -1,51 +0,0 @@
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;
12
- };
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
- };
21
- };
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';
@@ -1,124 +0,0 @@
1
- import { ReactNode } from 'react';
2
- import { SpringConfig } from 'react-spring';
3
- import { PrepareThumbsData, UseListenToCustomEvent } from './index';
4
- export declare type UseSpringCarouselBaseProps = {
5
- disableGestures?: boolean;
6
- draggingSlideTreshold?: number;
7
- slideWhenThresholdIsReached?: boolean;
8
- springConfig?: Omit<SpringConfig, 'velocity'>;
9
- carouselSlideAxis?: 'x' | 'y';
10
- gutter?: number;
11
- shouldResizeOnWindowResize?: boolean;
12
- };
13
- /**
14
- * Types based on withThums prop
15
- */
16
- export declare type ReactSpringCarouselItem = {
17
- id: string;
18
- renderItem: ReactNode;
19
- renderThumb?: never;
20
- };
21
- export declare type ReactSpringCarouselItemWithThumbs = {
22
- id: string;
23
- renderItem: ReactNode;
24
- renderThumb: ReactNode;
25
- };
26
- export declare type UseSpringCarouselWithThumbs = {
27
- withThumbs?: true;
28
- thumbsSlideAxis?: 'x' | 'y';
29
- items: ReactSpringCarouselItemWithThumbs[];
30
- enableThumbsWrapperScroll?: boolean;
31
- prepareThumbsData?: PrepareThumbsData;
32
- };
33
- export declare type UseSpringCarouselWithNoThumbs = {
34
- withThumbs?: false;
35
- items: ReactSpringCarouselItem[];
36
- thumbsSlideAxis?: never;
37
- enableThumbsWrapperScroll?: never;
38
- prepareThumbsData?: never;
39
- };
40
- export declare type ThumbsProps = UseSpringCarouselWithThumbs | UseSpringCarouselWithNoThumbs;
41
- /**
42
- * Types based on slideType
43
- */
44
- export declare type UseSpringCarouselFluidType = {
45
- slideType: 'fluid';
46
- slideAmount?: number;
47
- freeScroll?: boolean;
48
- enableFreeScrollDrag?: boolean | (() => boolean);
49
- itemsPerSlide?: never;
50
- initialActiveItem?: never;
51
- initialStartingPosition?: never;
52
- };
53
- export declare type UseSpringCarouselFixedSlideType = {
54
- slideType?: 'fixed';
55
- itemsPerSlide?: number;
56
- initialActiveItem?: number;
57
- slideAmount?: never;
58
- initialStartingPosition?: 'start' | 'center' | 'end';
59
- freeScroll?: never;
60
- enableFreeScrollDrag?: never;
61
- };
62
- declare type SlideTypes = UseSpringCarouselFluidType | UseSpringCarouselFixedSlideType;
63
- /**
64
- * Types based on gestures activation
65
- */
66
- export declare type DisableGesturesProps = {
67
- disableGestures?: true;
68
- touchAction?: never;
69
- };
70
- export declare type EnableGesturesProps = {
71
- disableGestures?: false;
72
- touchAction?: string;
73
- };
74
- export declare type Gestures = DisableGesturesProps | EnableGesturesProps;
75
- /**
76
- * Types based on loop functionality
77
- */
78
- export declare type WithLoopProps = {
79
- withLoop?: true;
80
- initialStartingPosition?: 'start' | 'center' | 'end';
81
- startEndGutter?: number;
82
- };
83
- export declare type WithNoLoop = {
84
- withLoop?: false;
85
- initialStartingPosition?: never;
86
- startEndGutter?: never;
87
- };
88
- declare type LoopProps = WithLoopProps | WithNoLoop;
89
- export declare type UseSpringCarouselProps = UseSpringCarouselBaseProps & ThumbsProps & SlideTypes & Gestures & LoopProps;
90
- export declare type UseSpringFluidSlideTypeReturnProps = {
91
- carouselFragment: ReactNode;
92
- thumbsFragment: ReactNode;
93
- useListenToCustomEvent: UseListenToCustomEvent<'use-spring'>;
94
- getIsFullscreen(): boolean;
95
- getIsPrevItem(id: string): boolean;
96
- getIsNextItem(id: string): boolean;
97
- enterFullscreen(elementRef?: HTMLElement): void;
98
- exitFullscreen(): void;
99
- slideToNextItem(): void;
100
- slideToPrevItem(): void;
101
- getIsAnimating(): boolean;
102
- getIsDragging(): boolean;
103
- };
104
- export declare type UseSpringFixedSlideTypeReturnProps = {
105
- carouselFragment: ReactNode;
106
- thumbsFragment: ReactNode;
107
- useListenToCustomEvent: UseListenToCustomEvent<'use-spring'>;
108
- getIsFullscreen(): boolean;
109
- getIsPrevItem(id: string): boolean;
110
- getIsNextItem(id: string): boolean;
111
- enterFullscreen(elementRef?: HTMLElement): void;
112
- exitFullscreen(): void;
113
- slideToNextItem(): void;
114
- slideToPrevItem(): void;
115
- getIsAnimating(): boolean;
116
- slideToItem(item: string | number): void;
117
- getIsActiveItem(id: string): boolean;
118
- getIsDragging(): boolean;
119
- getCurrentActiveItem(): {
120
- id: string;
121
- index: number;
122
- };
123
- };
124
- export {};
@@ -1,39 +0,0 @@
1
- import { TransitionFrom, TransitionTo } from 'react-spring';
2
- import { UseListenToCustomEvent } from './index';
3
- import { UseSpringCarouselBaseProps, ThumbsProps } from './useSpringCarousel';
4
- declare type ReactSpringCarouselItem = {
5
- id: string;
6
- };
7
- export declare type SpringAnimationProps = {
8
- initial: TransitionFrom<ReactSpringCarouselItem>;
9
- from: TransitionFrom<ReactSpringCarouselItem>;
10
- enter: TransitionTo<ReactSpringCarouselItem>;
11
- leave: TransitionTo<ReactSpringCarouselItem>;
12
- };
13
- export declare type UseTransitionCarouselProps = UseSpringCarouselBaseProps & ThumbsProps & {
14
- toPrevItemSpringProps?: SpringAnimationProps;
15
- toNextItemSpringProps?: SpringAnimationProps;
16
- springAnimationProps?: SpringAnimationProps;
17
- withLoop?: boolean;
18
- exitBeforeEnter?: boolean;
19
- trail?: number;
20
- };
21
- export declare type UseTransitionCarouselContextProps = {
22
- useListenToCustomEvent: UseListenToCustomEvent<'use-transition'>;
23
- activeItem: number;
24
- getIsFullscreen(): boolean;
25
- getIsPrevItem(id: string): boolean;
26
- getIsNextItem(id: string): boolean;
27
- enterFullscreen(elementRef?: HTMLElement): void;
28
- exitFullscreen(): void;
29
- slideToNextItem(): void;
30
- slideToPrevItem(): void;
31
- getIsAnimating(): boolean;
32
- slideToItem(item: string | number): void;
33
- getIsActiveItem(id: string): boolean;
34
- getCurrentActiveItem(): {
35
- id: string;
36
- index: number;
37
- };
38
- };
39
- export {};
@@ -1,8 +0,0 @@
1
- import { UseSpringFixedSlideTypeReturnProps } from '../types';
2
- import { UseSpringFluidSlideTypeReturnProps, UseSpringCarouselBaseProps, UseSpringCarouselWithThumbs, UseSpringCarouselFluidType, DisableGesturesProps, WithLoopProps, UseSpringCarouselWithNoThumbs, EnableGesturesProps, WithNoLoop, UseSpringCarouselFixedSlideType } from '../types/useSpringCarousel';
3
- declare type ReturnType<T> = T extends 'fixed' ? UseSpringFixedSlideTypeReturnProps : UseSpringFluidSlideTypeReturnProps;
4
- declare type ContextTypes<T> = Omit<ReturnType<T>, 'carouselFragment' | 'thumbsFragment'>;
5
- declare function useSpringCarousel(props: UseSpringCarouselBaseProps & UseSpringCarouselFluidType & (UseSpringCarouselWithThumbs | UseSpringCarouselWithNoThumbs) & (DisableGesturesProps | EnableGesturesProps) & (WithLoopProps | WithNoLoop)): ReturnType<'fluid'>;
6
- declare function useSpringCarousel(props: UseSpringCarouselBaseProps & UseSpringCarouselFixedSlideType & (UseSpringCarouselWithThumbs | UseSpringCarouselWithNoThumbs) & (DisableGesturesProps | EnableGesturesProps) & (WithLoopProps | WithNoLoop)): ReturnType<'fixed'>;
7
- declare function useSpringCarouselContext<T = 'fixed' | 'fluid'>(): ContextTypes<T>;
8
- export { useSpringCarousel, useSpringCarouselContext };
@@ -1,24 +0,0 @@
1
- /// <reference types="react" />
2
- import { UseTransitionCarouselContextProps, UseTransitionCarouselProps } from '../types/useTransitionCarousel';
3
- declare function useTransitionCarouselContext(): UseTransitionCarouselContextProps;
4
- declare function useTransitionCarousel({ items, withLoop, withThumbs, springConfig, thumbsSlideAxis, enableThumbsWrapperScroll, draggingSlideTreshold, prepareThumbsData, toPrevItemSpringProps, toNextItemSpringProps, disableGestures, trail, exitBeforeEnter, springAnimationProps, }: UseTransitionCarouselProps): {
5
- useListenToCustomEvent: import("../types").UseListenToCustomEvent<"use-transition">;
6
- activeItem: number;
7
- getIsFullscreen(): boolean;
8
- getIsPrevItem(id: string): boolean;
9
- getIsNextItem(id: string): boolean;
10
- enterFullscreen(elementRef?: HTMLElement | undefined): void;
11
- exitFullscreen(): void;
12
- slideToNextItem(): void;
13
- slideToPrevItem(): void;
14
- getIsAnimating(): boolean;
15
- slideToItem(item: string | number): void;
16
- getIsActiveItem(id: string): boolean;
17
- getCurrentActiveItem(): {
18
- id: string;
19
- index: number;
20
- };
21
- carouselFragment: JSX.Element;
22
- thumbsFragment: JSX.Element;
23
- };
24
- export { useTransitionCarouselContext, useTransitionCarousel };
@@ -1,5 +0,0 @@
1
- import { useLayoutEffect } from 'react';
2
- declare type Callback = () => void | (() => void);
3
- declare const useIsomorphicLayoutEffect: typeof useLayoutEffect;
4
- declare function useIsomorphicMount(callback: Callback): void;
5
- export { useIsomorphicLayoutEffect, useIsomorphicMount };
package/dist/umd/index.js DELETED
@@ -1,2 +0,0 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react/jsx-runtime"),require("react"),require("react-spring"),require("@use-gesture/react"),require("rxjs"),require("screenfull")):"function"==typeof define&&define.amd?define(["exports","react/jsx-runtime","react","react-spring","@use-gesture/react","rxjs","screenfull"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ReactSpringCarousel={},e.ReactJSXRuntime,e.React,e.ReactSpring,e.UseGestureReact,e.rxjs,e.Screenfull)}(this,(function(e,t,n,r,i,o,s){"use strict";function u(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var c=u(s);function l(){const e=n.useRef(new o.Subject);return{useListenToCustomEvent:function(t){n.useEffect((()=>{const n=e.current.subscribe(t);return()=>n.unsubscribe()}),[t])},emitObservable:t=>{e.current.next(t)}}}const a="undefined"!=typeof window?n.useLayoutEffect:n.useEffect;function f(e){const t=n.useRef(!1);a((()=>{if(!t.current){const n=e();return t.current=!0,()=>{n&&n()}}}),[])}function d({mainCarouselWrapperRef:e,emitObservable:t,handleResize:r}){const i=n.useRef(!1);function o(e){i.current=e}return f((()=>{function e(){document.fullscreenElement&&(o(!0),t({eventName:"onFullscreenChange",isFullscreen:!0}),r&&r()),document.fullscreenElement||(o(!1),t({eventName:"onFullscreenChange",isFullscreen:!1}),r&&r())}if(c.default.isEnabled)return c.default.on("change",e),()=>{c.default.isEnabled&&c.default.off("change",e)}})),{enterFullscreen:function(t){c.default.isEnabled&&c.default.request(t||e.current)},exitFullscreen:function(){c.default.isEnabled&&c.default.exit()},getIsFullscreen:function(){return i.current}}}function h({items:e,withThumbs:i,thumbsSlideAxis:o="x",springConfig:s,prepareThumbsData:u,getFluidWrapperScrollValue:c=(()=>0),getSlideValue:l=(()=>0),slideType:a}){const d=n.useRef(null),[h,g]=r.useSpring((()=>({x:0,y:0,config:s,onChange:({value:e})=>{d.current&&"fluid"===a&&(d.current["x"===o?"scrollLeft":"scrollTop"]=Math.abs(e[o]))}})));function m(){return d.current["x"===o?"scrollLeft":"scrollTop"]}function p(){var e;return Math.round(Number(null===(e=d.current)||void 0===e?void 0:e["x"===o?"scrollWidth":"scrollHeight"])-d.current.getBoundingClientRect()["x"===o?"width":"height"])}function b(){const e=Math.round(c()/l());return p()/e}f((()=>{if(i&&!d.current)throw new Error("The thumbs wrapper is not defined. If you've passed a Functional component, be sure to wrap your component in forwardRef.")}));return{thumbsFragment:i?t.jsx(r.animated.div,Object.assign({ref:d,className:"use-spring-carousel-thumbs-wrapper",onWheel:()=>{h[o].stop()},style:Object.assign({display:"flex",flex:1,position:"relative",width:"100%",height:"100%",flexDirection:"x"===o?"row":"column"},"x"===o?{overflowX:"auto"}:{overflowY:"auto",maxHeight:"100%"})},{children:function(){function t(e){return e.map((e=>({id:e.id,renderThumb:e.renderThumb})))}return u?u(t(e)):t(e)}().map((({id:e,renderThumb:n})=>{const r=`thumb-${e}`;return t.jsx("div",Object.assign({id:r,className:"thumb-item"},{children:n}),r)}))})):null,handleThumbsScroll:function(t,n){if("fluid"===a){const e=p();if("next"===n){const t=m()+b();g.start({from:{[o]:m()},to:{[o]:t>e?e:t}})}if("prev"===n){const e=m()-b();g.start({from:{[o]:m()},to:{[o]:e<0?0:e}})}}else{const r=d.current.querySelector(`#thumb-${e[t].id}`);if(r){const i=d.current,s="x"===o?"offsetWidth":"offsetHeight",u="x"===o?"scrollLeft":"scrollTop",c=function({thumbNode:e,offsetDirection:t,offsetDimension:n}){return e[t]+e[n]/2}({thumbNode:r,offsetDimension:s,offsetDirection:"x"===o?"offsetLeft":"offsetTop"}),l=function({thumbWrapper:e,offsetDimension:t}){return e[t]/2}({thumbWrapper:i,offsetDimension:s}),a=function({thumbWrapper:e,scrollDirection:t}){return e[t]}({thumbWrapper:i,scrollDirection:u}),f=function({thumbWrapper:n,thumbOffsetPosition:r,thumbScrollDimension:i,offsetDimension:s}){const u="x"===o?"scrollWidth":"scrollHeight";return t===e.length-1||r-i>n[u]-n[s]?n[u]-n[s]:0===t?0:r-i}({thumbWrapper:i,thumbOffsetPosition:c,thumbScrollDimension:l,offsetDimension:s});g.start({from:{[o]:a},to:{[o]:"prev"===n&&f<0?0:f},onChange:({value:e})=>{"x"===o?d.current.scrollLeft=e.x:d.current.scrollTop=e.y}})}}}}}const g=n.createContext(void 0),m=Object.assign(Object.assign({},r.config.default),{mass:1,velocity:0});const p=n.createContext(void 0);e.useSpringCarousel=function({items:e,withLoop:o=!1,draggingSlideTreshold:s,springConfig:u=r.config.default,shouldResizeOnWindowResize:c=!0,withThumbs:p=!1,enableThumbsWrapperScroll:b=!0,slideWhenThresholdIsReached:v=!0,carouselSlideAxis:x="x",thumbsSlideAxis:y="x",prepareThumbsData:w,initialActiveItem:T=0,initialStartingPosition:j,disableGestures:O=!1,gutter:S=0,startEndGutter:R=0,touchAction:C,slideAmount:I,freeScroll:E=!1,enableFreeScrollDrag:A,itemsPerSlide:N=1,slideType:F="fixed"}){const W=n.useRef(!0),D=n.useRef("initial"),L=o?e.length===N?[...e,...e,...e,...e,...e]:[...e,...e,...e]:e,P=n.useRef(T),$=n.useRef(null),M=n.useRef(null),q=n.useRef(!1),z=n.useRef(!1),B=n.useRef(!1),H=n.useRef(0),k=n.useRef(!1),G=n.useRef(0),V=n.useRef(0),X=n.useRef(0),Y=n.useRef(e),_=n.useRef(null!=s?s:0),J=n.useRef(N),U=n.useRef(S),K=n.useRef(R),Q=n.useRef(T),Z=n.useRef(j),ee=n.useRef(x);J.current=N,U.current=S,K.current=R,Q.current=T,Z.current=j,ee.current=x;const[te,ne]=r.useSpring((()=>({y:0,x:0,onChange:({value:e})=>{$.current&&E&&($.current["x"===ee.current?"scrollLeft":"scrollTop"]=Math.abs(e[ee.current]))}})));function re(){const e=null===(t=M.current)||void 0===t?void 0:t.querySelector(".use-spring-carousel-item");var t;if(!e)throw Error("No carousel items available!");return e.getBoundingClientRect()["x"===ee.current?"width":"height"]+U.current}function ie(){return te[ee.current].get()}function oe(){return re()*e.length<function(){if(!$.current)throw new Error("mainCarouselWrapperRef is not available");return $.current.getBoundingClientRect()["x"===ee.current?"width":"height"]}()}function se(){var e;return Math.round(Number(null===(e=M.current)||void 0===e?void 0:e["x"===ee.current?"scrollWidth":"scrollHeight"])-M.current.getBoundingClientRect()["x"===ee.current?"width":"height"])}function ue(){return 0===Se()}function ce(){if(!M.current)return 0;const e=re();if("fluid"===F&&"number"==typeof I){if(I<e)throw new Error("slideAmount must be greater than the width of a single item.");return I}return e}function le(t,n){const r="x"===ee.current?"left":"top";function i(){return re()*e.length}function s(e){o?(t.style.top="0px",t.style[r]=`-${e-K.current}px`):(t.style.left="0px",t.style.top="0px",n&&W.current&&(t.style[r]=`calc(-${n} * 100%)`))}function u(){s(i())}if("fixed"===F){if(J.current>1)switch(Z.current){default:case"start":u();break;case"center":c=J.current,s(i()-ce()*Math.round((c-1)/2));break;case"end":!function(e){s(i()-ce()*Math.round(e-1))}(J.current)}else u()}else u();var c}function ae(){if(G.current=window.innerWidth,"fluid"===F){if(oe())return void ne.start({immediate:!0,[ee.current]:0});if(H.current=se(),k.current){const e=-H.current;ne.start({immediate:!0,[ee.current]:e})}V.current=window.innerWidth}else ne.start({immediate:!0,[ee.current]:-ce()*Se()});H.current=se(),le(M.current)}function fe(){window.innerWidth===G.current||E||ae()}a((()=>{_.current=s||Math.floor(ce()/2/2),ae()}),[s,N,S,R,T,j,x,y]);const{useListenToCustomEvent:de,emitObservable:he}=l(),{enterFullscreen:ge,exitFullscreen:me,getIsFullscreen:pe}=d({mainCarouselWrapperRef:$,emitObservable:he,handleResize:fe}),{thumbsFragment:be,handleThumbsScroll:ve}=h({withThumbs:p,items:e,thumbsSlideAxis:y,springConfig:u,prepareThumbsData:w,slideType:F,getFluidWrapperScrollValue:se,getSlideValue:ce});function xe(){if(!$.current)throw new Error("Missing mainCarouselWrapperRef.current");return $.current["x"===ee.current?"scrollLeft":"scrollTop"]}function ye(){return"boolean"==typeof A?A:"function"==typeof A&&A()}const we=i.useDrag((e=>{const t=e.dragging,n=e.offset["x"===ee.current?0:1],r=e.movement["x"===ee.current?0:1],i=r>_.current,s=r<-_.current,c=e.direction["x"===ee.current?0:1];function l(){e.cancel()}function a(){Te(c>0?"prev":"next")}function f(){he(Object.assign({eventName:"onDrag",slideActionType:je()},e))}function d(){"fluid"===F?oe()||ue()&&"prev"===je()?ne.start({[ee.current]:0,config:Object.assign({velocity:e.velocity},u)}):k.current&&"next"===je()?ne.start({[ee.current]:-H.current,config:Object.assign({velocity:e.velocity},u)}):ne.start({[ee.current]:X.current,config:Object.assign({velocity:e.velocity},u)}):ne.start({[ee.current]:-Se()*ce(),config:Object.assign({velocity:e.velocity},u)})}function h(){Math.abs(ie())+100>=H.current&&"next"===je()&&(k.current=!0),"prev"===je()&&(k.current=!1)}if(E&&ye())return t&&(Ie()||Ce(!0),a(),f(),h()),ne.start({from:{[ee.current]:xe()},to:{[ee.current]:-n},config:{velocity:e.velocity,friction:50,tension:1400}}),0===xe()&&"prev"===je()?void l():void(e.last&&("prev"===je()?Le(e.velocity):Pe(e.velocity),Ce(!1)));if(t){if(Ie()||Ce(!0),f(),a(),h(),E){if(ye()){if(0===xe()&&"prev"===je())return void l();ne.start({config:{velocity:e.velocity,friction:50,tension:1400},from:{[ee.current]:xe()},to:{[ee.current]:-n}})}return}if(ne.start({[ee.current]:n,config:{velocity:e.velocity,friction:50,tension:1e3}}),(i||s)&&oe()&&"fluid"===F)l(),d();else if(k.current&&"next"===je()&&s)k.current=!1,l(),ne.start({[ee.current]:-H.current});else if(v){if(s)return l(),void(!o&&De()?d():Pe(e.velocity));if(i)return l(),void(!o&&ue()?d():Le(e.velocity))}}if(e.last&&!v&&(s||i)&&!E)return Ce(!1),void(s?!o&&De()?d():Pe(e.velocity):i&&(!o&&ue()?d():Le(e.velocity)));!e.last||s||i||E||(d(),he(Object.assign({eventName:"onDrag",slideActionType:je()},e)))}),{enabled:!O,axis:ee.current,from:()=>E?"x"===ee.current?[-xe(),0]:[0,-xe()]:[te.x.get(),te.y.get()]});function Te(e){D.current=e}function je(){return D.current}function Oe(e){P.current=e}function Se(){return P.current}function Re(e){z.current=e}function Ce(e){q.current=e}function Ie(){return q.current}function Ee(){const t=Se();return 0===t?e.length-1:t-1}function Ae(){const t=Se();return t===e.length-1?0:t+1}function Ne(t){return e.findIndex((e=>e.id===t))}function Fe(e,t){if("number"==typeof e)return{[ee.current]:e};if("number"!=typeof t)throw new Error("to values is not a number!");return{[ee.current]:-ce()*t}}function We({from:t,to:n=-1,customTo:r,immediate:i=!1,onRest:o=(()=>{}),velocity:s}){i||(Oe(n),Re(!0),he({eventName:"onSlideStartChange",slideActionType:je(),nextItem:{index:"fluid"===F?-1:n,id:"fluid"===F?"":e[n].id}})),X.current=Fe(r,n)[x],ne.start(Object.assign(Object.assign(Object.assign(Object.assign({},function(e){return"number"==typeof e?{from:{[ee.current]:e}}:{}}(t)),{to:Fe(r,n)}),s?{config:Object.assign(Object.assign({},m),{velocity:s,friction:void 0,tension:void 0})}:{config:Object.assign({velocity:0},u)}),{immediate:i,onRest:t=>{t.finished&&(Ce(!1),Re(!1),o(),i||he({eventName:"onSlideChange",slideActionType:je(),currentItem:{index:"fluid"===F?-1:Se(),id:"fluid"===F?"":e[Se()].id}}))}})),b&&p&&!i&&ve(n,je())}function De(){return Se()===e.length-1}function Le(t){if(Te("prev"),k.current=!1,"fluid"===F){if(k.current=!1,oe())return;const n=ie()+ce()+200;if(E){const e=$.current.scrollLeft-ce();We({customTo:e<0?0:e,from:$.current.scrollLeft,velocity:t})}else We(n>=0?o?{from:ie()-re()*e.length,velocity:t,customTo:ie()-re()*e.length+ce()}:{customTo:0,velocity:t}:{customTo:ie()+ce(),velocity:t})}else{if(!o&&0===Se()||B.current)return;ue()?We({from:ie()-ce()*e.length,to:e.length-1,velocity:t}):We({to:Ee(),velocity:t})}}function Pe(t){if(Te("next"),"fluid"===F){if(oe())return;const n=Math.abs(ie()-ce())+100>=H.current;if(E){const e=$.current.scrollLeft+ce()>H.current,n=$.current.scrollLeft+ce();We({velocity:t,customTo:e?H.current:n,from:$.current.scrollLeft})}else if(o&&Math.abs(ie()-ce())>=e.length*re()){const n=re()*e.length;We({from:ie()+n,customTo:ie()+n-ce(),velocity:t})}else{if(k.current)return;n?(k.current=!0,We({customTo:-H.current,velocity:t})):We({customTo:ie()-ce(),velocity:t})}}else{if(!o&&Se()===L.length-1||B.current)return;Math.abs(ie()-ce()+25)>H.current&&!Ie()?k.current=!0:k.current?We({to:e.length-J.current,velocity:t}):De()?We({from:ie()+ce()*e.length,to:0,velocity:t}):We({to:Ae(),velocity:t})}}function $e(t){let n=0;if(n="string"==typeof t?e.findIndex((e=>e.id===t)):t,n>=e.length)throw Error("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.");if(n===Se()||e.length!==Y.current.length&&Se()<e.length)return;const r=Ne(Y.current[Se()].id);Te(Ne(e[n].id)>r?"next":"prev"),We({to:n})}f((()=>{if(N%2==0&&Z.current)throw new Error("initialStartingPosition can be only used if itemsPerSlide is an even value.");if(_.current<0)throw new Error("draggingSlideTreshold must be greater than 0");if(_.current>ce()/2)throw new Error(`draggingSlideTreshold must be equal or less than the half of the width of an item, which is ${Math.floor(ce()/2)}`);if(J.current<1)throw new Error("The itemsPerSlide prop can't be less than 1.");if(J.current>e.length)throw new Error("The itemsPerSlide prop can't be greater than the total length of the items you provide.");if(Q.current<0)throw new Error("The initialActiveItem cannot be less than 0.");if(Q.current>e.length)throw new Error("The initialActiveItem cannot be greater than the total length of the items you provide.");c||console.warn("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.")})),f((()=>{function e(){document.hidden?B.current=!0:B.current=!1}return document.addEventListener("visibilitychange",e),()=>{document.removeEventListener("visibilitychange",e)}})),f((()=>{W.current=!1,H.current=se(),V.current=window.innerWidth,G.current=window.innerWidth,T>0&&(We({to:T,immediate:!0}),Oe(T),!o&&M.current&&(M.current.style.top="0px",M.current.style.left="0px"))})),a((()=>{T<e.length&&T!==P.current&&(We({to:T,immediate:!0}),Oe(T))}),[T]),a((()=>{if(c)return window.addEventListener("resize",fe),()=>{window.removeEventListener("resize",fe)}}),[c]),a((()=>{M.current&&("x"===ee.current&&(M.current.style.top="0px"),"y"===ee.current&&(M.current.style.left="0px"))}),[x]),a((()=>{H.current=se();!(e.length===Y.current.length)&&e.length<Y.current.length&&$e(e.length-1),Y.current=e}),[se,e]);const Me=Object.assign({useListenToCustomEvent:de,getIsFullscreen:pe,enterFullscreen:ge,exitFullscreen:me,getIsAnimating:function(){return z.current},getIsDragging:Ie,getIsNextItem:function(t){const n=Ne(t),r=Se();return o&&r===e.length-1?0===n:n===r+1},getIsPrevItem:function(t){const n=Ne(t),r=Se();return o&&0===r?n===e.length-1:n===r-1},slideToPrevItem(){Le()},slideToNextItem(){Pe()}},"fixed"===F?{slideToItem:$e,getIsActiveItem:e=>Ne(e)===Se(),getCurrentActiveItem:()=>({id:e[Se()].id,index:Se()})}:{}),qe=t.jsx(g.Provider,Object.assign({value:Me},{children:t.jsx("div",Object.assign({ref:$,className:"use-spring-carousel-main-wrapper","data-testid":"use-spring-carousel-wrapper"},E?{onWheel(){te[ee.current].stop()}}:{},{style:Object.assign({display:"flex",position:"relative",width:"100%",height:"100%"},E?"x"===ee.current?{overflowX:"auto"}:{overflowY:"auto"}:{})},{children:t.jsx(r.animated.div,Object.assign({},we(),{className:"use-spring-carousel-track-wrapper","data-testid":"use-spring-carousel-animated-wrapper",ref:e=>{e&&(M.current=e,le(e,Q.current))},style:Object.assign(Object.assign(Object.assign({display:"flex",position:"relative",touchAction:O?"unset":C||("x"===ee.current?"pan-y":"pan-x"),flexDirection:"x"===ee.current?"row":"column"},function(){const e=`calc(100% - ${2*K.current}px)`;return{width:"x"===ee.current?e:"100%",height:"y"===ee.current?e:"100%"}}()),function(){const t=e.length/N*100,n=100/N,r="x"===ee.current?"left":"y",i=Math.floor(50/n);if("fixed"===F){if("center"===Z.current)return{[r]:`calc(-${t}% + ${n*i}%)`};if("end"===Z.current)return{[r]:`calc(-${t}% + ${n*(2*i)}%)`}}return{[r]:"0px"}}()),E?{}:te)},{children:L.map((({id:e,renderItem:n},r)=>{return t.jsx("div",Object.assign({className:"use-spring-carousel-item","data-testid":"use-spring-carousel-item-wrapper",style:Object.assign({display:"flex",position:"relative"},(i=J.current,"fixed"===F?Object.assign(Object.assign({},"x"===ee.current?{marginRight:`${U.current}px`}:{marginBottom:`${U.current}px`}),{flex:`1 0 calc(100% / ${i} - ${U.current*(i-1)/i}px)`}):Object.assign({},"x"===ee.current?{marginRight:`${U.current}px`}:{marginBottom:`${U.current}px`})))},{children:n}),`${e}-${r}`);var i}))}))}))})),ze=t.jsx(g.Provider,Object.assign({value:Me},{children:be}));return Object.assign(Object.assign({},Me),{carouselFragment:qe,thumbsFragment:ze})},e.useSpringCarouselContext=function(){const e=n.useContext(g);if(!e)throw new Error("useSpringCarouselContext must be used only inside a component that is rendered inside the Carousel.");return e},e.useTransitionCarousel=function({items:e,withLoop:o=!1,withThumbs:s=!1,springConfig:u=r.config.default,thumbsSlideAxis:c="x",enableThumbsWrapperScroll:a=!0,draggingSlideTreshold:f=50,prepareThumbsData:g,toPrevItemSpringProps:m,toNextItemSpringProps:b,disableGestures:v=!1,trail:x,exitBeforeEnter:y=!1,springAnimationProps:w={initial:{opacity:1,position:"absolute"},from:{opacity:0,position:"absolute"},enter:{opacity:1,position:"absolute"},leave:{opacity:0,position:"absolute"}}}){const T=n.useRef("next"),j=n.useRef(null),O=n.useRef(!1),[S,R]=n.useState(0),{emitObservable:C,useListenToCustomEvent:I}=l(),{enterFullscreen:E,exitFullscreen:A,getIsFullscreen:N}=d({emitObservable:C,mainCarouselWrapperRef:j}),{thumbsFragment:F,handleThumbsScroll:W}=h({items:e,withThumbs:s,thumbsSlideAxis:c,springConfig:u,prepareThumbsData:g,slideType:"fixed"}),D=i.useDrag((({last:t,movement:[n]})=>{if(!P()&&t){const t=n>f,r=n<-f,i=0===S,s=S===e.length-1;if(r){if(!o&&s)return;z(),C({eventName:"onLeftSwipe"})}else if(t){if(!o&&i)return;B(),C({eventName:"onRightSwipe"})}}}),{enabled:!v}),L=r.useTransition(S,Object.assign(Object.assign({config:u},function(){const e=q();return"prev"===e&&m?{initial:Object.assign({},w.initial),from:Object.assign({},m.from),enter:Object.assign({},m.enter),leave:Object.assign({},m.leave)}:"next"===e&&b?{initial:Object.assign({},w.initial),from:Object.assign({},b.from),enter:Object.assign({},b.enter),leave:Object.assign({},b.leave)}:{initial:Object.assign({},w.initial),from:Object.assign({},w.from),enter:Object.assign({},w.enter),leave:Object.assign({},w.leave)}}()),{onStart:()=>$(!0),trail:x,exitBeforeEnter:y,key:e[S].id,onRest:t=>{t.finished&&($(!1),C({eventName:"onSlideChange",slideActionType:q(),currentItem:{index:S,id:e[S].id}}))}}))(((n,i)=>t.jsx(r.animated.div,Object.assign({style:Object.assign(Object.assign({},n),{flex:"1 0 100%",width:"100%",height:"100%"})},{children:e[i].renderItem}))));function P(){return O.current}function $(e){O.current=e}function M(e){T.current=e}function q(){return T.current}function z(){const t=S===e.length-1;o?(M("next"),t?(C({eventName:"onSlideStartChange",slideActionType:q(),nextItem:{index:0,id:e[0].id}}),R(0)):(C({eventName:"onSlideStartChange",slideActionType:q(),nextItem:{index:S+1,id:e[S+1].id}}),R(S+1))):t||(C({eventName:"onSlideStartChange",slideActionType:q(),nextItem:{index:S+1,id:e[S+1].id}}),M("next"),R(S+1))}function B(){const t=0===S;o?(M("prev"),t?(C({eventName:"onSlideStartChange",slideActionType:q(),nextItem:{index:e.length-1,id:e[e.length-1].id}}),R(e.length-1)):(C({eventName:"onSlideStartChange",slideActionType:q(),nextItem:{index:S-1,id:e[S-1].id}}),R(S-1))):t||(M("prev"),C({eventName:"onSlideStartChange",slideActionType:q(),nextItem:{index:S-1,id:e[S-1].id}}),R(S-1))}function H(t){return e.findIndex((e=>e.id===t))}const k={activeItem:S,slideToItem:function(t){let n=0;if(n="string"==typeof t?e.findIndex((e=>e.id===t)):t,n>=e.length)throw Error("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.");if(n===S)return;const r=H(e[S].id),i=H(e[n].id);C({eventName:"onSlideStartChange",slideActionType:q(),nextItem:{index:i,id:e[n].id}}),M(i>r?"next":"prev"),R(n),a&&s&&W(n)},slideToNextItem:z,slideToPrevItem:B,enterFullscreen:E,exitFullscreen:A,useListenToCustomEvent:I,getIsNextItem:function(t){const n=H(t);return o&&S===e.length-1?0===n:n===S+1},getIsPrevItem:function(t){const n=H(t);return o&&0===S?n===e.length-1:n===S-1},getIsAnimating:P,getIsFullscreen:N,getIsActiveItem:e=>H(e)===S,getCurrentActiveItem:()=>({id:e[S].id,index:S})},G=t.jsx(p.Provider,Object.assign({value:k},{children:t.jsx("div",Object.assign({ref:j},D(),{style:{display:"flex",position:"relative",width:"100%",height:"100%",overflow:"hidden"}},{children:L}))})),V=t.jsx(p.Provider,Object.assign({value:k},{children:F}));return Object.assign({carouselFragment:G,thumbsFragment:V},k)},e.useTransitionCarouselContext=function(){const e=n.useContext(p);if(!e)throw new Error("useTransitionCarouselContext isn't being used within the useTransitionCarousel context; \n use the context only inside a component that is rendered within the Carousel.");return e},Object.defineProperty(e,"__esModule",{value:!0})}));
2
- //# sourceMappingURL=index.js.map