@digital-b2c/coreui-kit 0.29.1 → 0.29.3

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.
package/dist/index.mjs CHANGED
@@ -601,7 +601,7 @@ var BrandsStrip = ({
601
601
  }) => {
602
602
  const [show, setShow] = useState(false);
603
603
  const [shouldAnimate, setShouldAnimate] = useState(false);
604
- const { is } = useViewPort_default();
604
+ const { is, device } = useViewPort_default();
605
605
  const isTabletBelow = is("tablet", "below");
606
606
  const containerRef = useRef(null);
607
607
  const marqueeRef = useRef(null);
@@ -659,33 +659,42 @@ var BrandsStrip = ({
659
659
  };
660
660
  useGSAP(
661
661
  () => {
662
+ let frameId;
662
663
  const refreshCalculations = () => {
664
+ var _a;
663
665
  if (!marqueeRef.current || !containerRef.current || logos.length === 0) return;
664
666
  const items = gsap.utils.toArray(marqueeRef.current.children);
665
667
  if (items.length === 0) return;
668
+ (_a = timeline.current) == null ? void 0 : _a.kill();
669
+ timeline.current = null;
670
+ gsap.set(items, { x: 0, xPercent: 0 });
666
671
  const itemWidth = items[0].clientWidth;
667
- const calculatedTotalWidth = shouldAnimate ? itemWidth * items.length + 120 * (items.length - 1) / 2 : itemWidth * items.length + 120 * (items.length - 1);
668
672
  const containerWidth = containerRef.current.clientWidth;
669
673
  if (containerWidth === 0) {
670
- requestAnimationFrame(refreshCalculations);
674
+ frameId = requestAnimationFrame(refreshCalculations);
671
675
  return;
672
676
  }
673
- if (containerWidth < calculatedTotalWidth) {
674
- setShouldAnimate(true);
675
- const ctx = gsap.context(() => {
676
- const loop = horizontalLoop(items, {
677
- repeat: -1,
678
- speed: 1,
679
- paddingRight: 120
680
- });
681
- timeline.current = loop;
682
- }, containerRef);
683
- return () => ctx.revert();
677
+ const calculatedTotalWidth = itemWidth * logos.length + 120 * (logos.length - 1);
678
+ const needsAnimation = containerWidth < calculatedTotalWidth;
679
+ if (needsAnimation !== shouldAnimate) {
680
+ setShouldAnimate(needsAnimation);
681
+ return;
684
682
  }
683
+ timeline.current = needsAnimation ? horizontalLoop(items, {
684
+ repeat: -1,
685
+ speed: 1,
686
+ paddingRight: 120
687
+ }) : null;
685
688
  };
686
689
  refreshCalculations();
690
+ return () => {
691
+ var _a;
692
+ if (frameId) cancelAnimationFrame(frameId);
693
+ (_a = timeline.current) == null ? void 0 : _a.kill();
694
+ timeline.current = null;
695
+ };
687
696
  },
688
- { scope: containerRef, dependencies: [logos] }
697
+ { scope: containerRef, dependencies: [logos, device, shouldAnimate] }
689
698
  );
690
699
  const handleMouseEnter = () => {
691
700
  setShow(true);
@@ -703,7 +712,7 @@ var BrandsStrip = ({
703
712
  if (logos.length === 0) return [];
704
713
  if (!shouldAnimate) return [...logos];
705
714
  return [...logos, ...logos];
706
- }, [logos]);
715
+ }, [logos, shouldAnimate]);
707
716
  return /* @__PURE__ */ jsxs(
708
717
  "div",
709
718
  {
@@ -718,7 +727,7 @@ var BrandsStrip = ({
718
727
  onMouseLeave: handleMouseLeave,
719
728
  children: [
720
729
  /* @__PURE__ */ jsxs("div", { className: clsx72(BrandsStrip_module_default.container, { [BrandsStrip_module_default.blurred]: show && logos.length > 1 }), children: [
721
- title && logos.length === 1 && /* @__PURE__ */ jsx("h2", { className: clsx72("body", BrandsStrip_module_default.title), children: title }),
730
+ title && logos.length === 1 && /* @__PURE__ */ jsx("span", { className: clsx72("body", BrandsStrip_module_default.title), children: title }),
722
731
  logos.length > 0 && /* @__PURE__ */ jsx(
723
732
  "div",
724
733
  {