my-animated-components 1.5.1 → 1.5.2

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 (2) hide show
  1. package/dist/index.js +15 -4
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -2821,12 +2821,13 @@ const ImageEditor = ({ imageFile, onSave, onCancel, className = "" }) => {
2821
2821
  !isMobile && React.createElement("span", { style: { marginLeft: 6 } }, tab.label)))))))), document.body);
2822
2822
  };
2823
2823
 
2824
- const Carousel = ({ images, navigationStyle = 'both', size = 'lg', autoPlay = 0, autoPlayDirection = 'forward', showPlayPause = true, loop = true, enableSwipe = true, swipeThreshold = 10000, direction = 'horizontal', motionVariant = 'fadeIn', customVariants, transitionDuration = 0.5, customTransition, customClasses = {}, customSizeClasses, aspectRatio = '16/9', showOverlay = true, overlayPosition = 'bottom', onSlideChange, initialSlide = 0, baseClassName, unstyled = false, className = '', lazyLoad = true, preloadImages = 2, customIcons, thumbnailSize = 'md', arrowPosition = 'inside', dotStyle = 'line', pauseOnHover = true, keyboard = true, slidesPerView = 1, spaceBetween = 0, centeredSlides = false, }) => {
2824
+ const Carousel = ({ images, navigationStyle = 'both', size = 'lg', autoPlay = 0, autoPlayDirection = 'forward', showPlayPause = true, loop = true, enableSwipe = true, swipeThreshold = 10000, direction = 'horizontal', motionVariant = 'fadeIn', customVariants, transitionDuration = 0.5, customTransition, customClasses = {}, customSizeClasses, aspectRatio = '16/9', showOverlay = true, overlayPosition = 'bottom', onSlideChange, initialSlide = 0, baseClassName, unstyled = false, className = '', lazyLoad = false, preloadImages = 2, customIcons, thumbnailSize = 'md', arrowPosition = 'inside', dotStyle = 'line', pauseOnHover = true, keyboard = true, slidesPerView = 1, spaceBetween = 0, centeredSlides = false, }) => {
2825
2825
  const [currentIndex, setCurrentIndex] = React.useState(initialSlide);
2826
2826
  const [isPlaying, setIsPlaying] = React.useState(autoPlay > 0);
2827
2827
  const [dir, setDir] = React.useState(0);
2828
2828
  const [loadedImages, setLoadedImages] = React.useState(new Set([initialSlide]));
2829
2829
  const containerRef = React.useRef(null);
2830
+ const autoPlayRef = React.useRef(null);
2830
2831
  const defaultSizeClasses = {
2831
2832
  xs: 'max-w-sm h-48',
2832
2833
  sm: 'max-w-md h-64',
@@ -2869,14 +2870,24 @@ const Carousel = ({ images, navigationStyle = 'both', size = 'lg', autoPlay = 0,
2869
2870
  }
2870
2871
  setLoadedImages(imagesToLoad);
2871
2872
  }
2872
- }, [currentIndex, lazyLoad, preloadImages, images.length, loop, loadedImages]);
2873
+ else {
2874
+ setLoadedImages(new Set(images.map((_, i) => i)));
2875
+ }
2876
+ }, [currentIndex, lazyLoad, preloadImages, images.length, loop]);
2873
2877
  React.useEffect(() => {
2878
+ if (autoPlayRef.current) {
2879
+ clearInterval(autoPlayRef.current);
2880
+ }
2874
2881
  if (autoPlay > 0 && isPlaying) {
2875
- const interval = setInterval(() => {
2882
+ autoPlayRef.current = setInterval(() => {
2876
2883
  paginate(autoPlayDirection === 'forward' ? 1 : -1);
2877
2884
  }, autoPlay);
2878
- return () => clearInterval(interval);
2879
2885
  }
2886
+ return () => {
2887
+ if (autoPlayRef.current) {
2888
+ clearInterval(autoPlayRef.current);
2889
+ }
2890
+ };
2880
2891
  }, [autoPlay, isPlaying, paginate, autoPlayDirection]);
2881
2892
  React.useEffect(() => {
2882
2893
  onSlideChange?.(currentIndex);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "my-animated-components",
3
- "version": "1.5.1",
3
+ "version": "1.5.2",
4
4
  "type": "module",
5
5
  "description": "",
6
6
  "main": "dist/index.js",