gsap-react-marquee 0.1.1 → 0.1.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.
@@ -16,11 +16,7 @@ export declare const calculateDuplicates: (marqueeChildrenWidth: number, contain
16
16
  * Determines the minimum width for marquee elements
17
17
  */
18
18
  export declare const getMinWidth: (marqueesChildren: HTMLElement[], totalWidth: number, containerMarqueeWidth: number, props: GSAPReactMarqueeProps) => string | number;
19
- /**
20
- * Creates a simple infinite marquee animation
21
- */
22
- export declare const simpleAnimation: (marquees: HTMLElement[], marqueeChildrenDimension: number, isReverse: boolean, props: GSAPReactMarqueeProps) => void;
23
19
  /**
24
20
  * Creates a complex fill-based marquee animation with seamless looping
25
21
  */
26
- export declare const fillAnimation: (marqueesChildren: HTMLElement[], startX: number, tl: gsap.core.Timeline, isReverse: boolean, props: GSAPReactMarqueeProps) => void;
22
+ export declare const coreAnimation: (elementsToAnimate: HTMLElement[], startX: number, tl: gsap.core.Timeline, isReverse: boolean, props: GSAPReactMarqueeProps) => void;
package/dist/index.cjs.js CHANGED
@@ -2935,7 +2935,13 @@ const setupContainerStyles = (containerMarquee, marquees, marqueesChildren, isVe
2935
2935
  rotate: isVertical ? 90 : "0",
2936
2936
  });
2937
2937
  if (isVertical) {
2938
- gsap.set(containerMarquee, { width: window.innerHeight });
2938
+ const parent = containerMarquee.parentNode;
2939
+ gsap.set(containerMarquee, {
2940
+ width: parent.offsetHeight,
2941
+ });
2942
+ gsap.set(marqueesChildren, {
2943
+ overflow: "visible",
2944
+ });
2939
2945
  }
2940
2946
  if (alignRotationWithY && marquees.length > 0) {
2941
2947
  const marqueeHeight = marquees[0].offsetHeight;
@@ -2944,12 +2950,16 @@ const setupContainerStyles = (containerMarquee, marquees, marqueesChildren, isVe
2944
2950
  });
2945
2951
  gsap.set(marqueesChildren, {
2946
2952
  rotate: -90,
2953
+ x: (containerMarquee.offsetWidth - spacing) / 2 - spacing,
2947
2954
  display: "flex",
2948
2955
  flexWrap: "wrap",
2949
2956
  width: marqueeHeight,
2950
2957
  wordBreak: "break-all",
2951
2958
  whiteSpace: "break-spaces",
2952
2959
  });
2960
+ gsap.set(marquees, {
2961
+ height: containerMarquee.offsetWidth - spacing,
2962
+ });
2953
2963
  }
2954
2964
  };
2955
2965
  /**
@@ -2977,37 +2987,16 @@ const getMinWidth = (marqueesChildren, totalWidth, containerMarqueeWidth, props)
2977
2987
  return "100%";
2978
2988
  return `${totalWidth}px`;
2979
2989
  };
2980
- /**
2981
- * Creates a simple infinite marquee animation
2982
- */
2983
- const simpleAnimation = (marquees, marqueeChildrenDimension, isReverse, props) => {
2984
- const { spacing = 16, speed = 100, loop = -1 } = props;
2985
- const tween = gsap.to(marquees, {
2986
- xPercent: (_, el) => {
2987
- const w = parseFloat(String(gsap.getProperty(el, "width", "px")));
2988
- const xPercent = ((w + spacing) / w) * 100;
2989
- return -xPercent;
2990
- },
2991
- duration: (marqueeChildrenDimension - spacing) / speed,
2992
- repeat: loop,
2993
- ease: "none",
2994
- });
2995
- tween.play();
2996
- if (isReverse) {
2997
- tween.totalTime(tween.rawTime() + tween.duration() * 100);
2998
- tween.reverse();
2999
- }
3000
- };
3001
2990
  /**
3002
2991
  * Creates a complex fill-based marquee animation with seamless looping
3003
2992
  */
3004
- const fillAnimation = (marqueesChildren, startX, tl, isReverse, props) => {
3005
- const { spacing = 16, speed = 100 } = props;
2993
+ const coreAnimation = (elementsToAnimate, startX, tl, isReverse, props) => {
2994
+ const { spacing = 16, speed = 100, delay = 0, paused = false, alignRotationWithY = false, } = props;
3006
2995
  const widths = [];
3007
2996
  const xPercents = [];
3008
- const latestPos = marqueesChildren.length - 1;
2997
+ const latestPos = elementsToAnimate.length - 1;
3009
2998
  // Set initial positions and calculate percentages
3010
- gsap.set(marqueesChildren, {
2999
+ gsap.set(elementsToAnimate, {
3011
3000
  xPercent: (i, el) => {
3012
3001
  const w = (widths[i] = parseFloat(String(gsap.getProperty(el, "width", "px"))));
3013
3002
  xPercents[i] =
@@ -3016,18 +3005,20 @@ const fillAnimation = (marqueesChildren, startX, tl, isReverse, props) => {
3016
3005
  return xPercents[i];
3017
3006
  },
3018
3007
  });
3019
- gsap.set(marqueesChildren, { x: 0 });
3020
- // Calculate the total track length for seamless looping
3021
- const trackLength = marqueesChildren[latestPos].offsetLeft +
3008
+ gsap.set(elementsToAnimate, { x: 0 });
3009
+ //Calculate the total track length for seamless looping
3010
+ const trackLength = elementsToAnimate[latestPos].offsetLeft +
3022
3011
  (xPercents[latestPos] / 100) * widths[latestPos] -
3023
3012
  startX +
3024
- marqueesChildren[latestPos].offsetWidth +
3013
+ elementsToAnimate[latestPos].offsetWidth +
3025
3014
  spacing;
3026
3015
  // Create animation timeline for each element
3027
- marqueesChildren.forEach((item, i) => {
3016
+ elementsToAnimate.forEach((item, i) => {
3028
3017
  const curX = (xPercents[i] / 100) * widths[i];
3029
3018
  const distanceToStart = item.offsetLeft + curX - startX;
3030
- const distanceToLoop = distanceToStart + widths[i];
3019
+ const distanceToLoop = alignRotationWithY
3020
+ ? distanceToStart + item.offsetHeight - spacing
3021
+ : distanceToStart + widths[i];
3031
3022
  tl.to(item, {
3032
3023
  xPercent: ((curX - distanceToLoop) / widths[i]) * 100,
3033
3024
  duration: distanceToLoop / speed,
@@ -3039,16 +3030,24 @@ const fillAnimation = (marqueesChildren, startX, tl, isReverse, props) => {
3039
3030
  immediateRender: false,
3040
3031
  }, distanceToLoop / speed);
3041
3032
  });
3042
- // Pre-render for performance optimization
3043
- tl.progress(1, true).progress(0, true);
3033
+ tl.delay(delay);
3044
3034
  if (isReverse) {
3045
- tl.totalTime(tl.rawTime() + tl.duration() * 100);
3046
- tl.reverse();
3035
+ if (paused) {
3036
+ tl.pause();
3037
+ return;
3038
+ }
3039
+ tl.progress(1).pause();
3040
+ gsap.delayedCall(delay, () => {
3041
+ tl.reverse();
3042
+ tl.eventCallback("onReverseComplete", () => {
3043
+ tl.totalTime(tl.rawTime() + tl.duration() * 100);
3044
+ });
3045
+ });
3047
3046
  }
3048
3047
  };
3049
3048
 
3050
3049
  const GSAPReactMarquee = require$$0.forwardRef((props, ref) => {
3051
- const { children, className, dir = "left", loop = -1, paused = false, fill = false, alignRotationWithY, } = props;
3050
+ const { children, className, dir = "left", loop = -1, paused = false, fill = false, } = props;
3052
3051
  const rootRef = require$$0.useRef(null) || ref;
3053
3052
  const containerRef = rootRef;
3054
3053
  const marqueeRef = require$$0.useRef(null);
@@ -3065,8 +3064,8 @@ const GSAPReactMarquee = require$$0.forwardRef((props, ref) => {
3065
3064
  if (!marquee || !marqueesChildren)
3066
3065
  return;
3067
3066
  const tl = gsap.timeline({
3068
- repeat: loop,
3069
3067
  paused: paused,
3068
+ repeat: loop,
3070
3069
  defaults: { ease: "none" },
3071
3070
  onReverseComplete() {
3072
3071
  // start the animation from the end, when scrolling in reverse (up)
@@ -3077,7 +3076,7 @@ const GSAPReactMarquee = require$$0.forwardRef((props, ref) => {
3077
3076
  setupContainerStyles(containerMarquee, marquees, marqueesChildren, isVertical, props);
3078
3077
  // Calculate dimensions and duplicates
3079
3078
  const containerMarqueeWidth = containerMarquee.offsetWidth;
3080
- const marqueeHeight = marquees[0].offsetHeight;
3079
+ // const marqueeHeight = marquees[0].offsetHeight;
3081
3080
  const marqueeChildrenWidth = marqueesChildren[0].offsetWidth;
3082
3081
  const startX = marqueesChildren[0].offsetLeft;
3083
3082
  setMarqueeDuplicates(calculateDuplicates(marqueeChildrenWidth, containerMarqueeWidth, isVertical, props));
@@ -3091,15 +3090,10 @@ const GSAPReactMarquee = require$$0.forwardRef((props, ref) => {
3091
3090
  flex: fill ? "0 0 auto" : "1",
3092
3091
  });
3093
3092
  // Create appropriate animation based on fill setting
3094
- if (fill) {
3095
- fillAnimation(marqueesChildren, startX, tl, isReverse, props);
3096
- }
3097
- else {
3098
- simpleAnimation(marquees, isVertical && alignRotationWithY
3099
- ? marqueeHeight
3100
- : marqueeChildrenWidth, isReverse, props);
3101
- }
3102
- }, { dependencies: [marqueeDuplicates] });
3093
+ coreAnimation(fill ? marqueesChildren : marquees, startX, tl, isReverse, props);
3094
+ }, {
3095
+ dependencies: [marqueeDuplicates],
3096
+ });
3103
3097
  const clonedMarquees = require$$0.useMemo(() => {
3104
3098
  if (!Number.isFinite(marqueeDuplicates) || marqueeDuplicates <= 0)
3105
3099
  return null;
@@ -3111,9 +3105,8 @@ GSAPReactMarquee.displayName = "GSAPReactMarquee";
3111
3105
 
3112
3106
  exports.calculateDuplicates = calculateDuplicates;
3113
3107
  exports.cn = cn;
3108
+ exports.coreAnimation = coreAnimation;
3114
3109
  exports.default = GSAPReactMarquee;
3115
- exports.fillAnimation = fillAnimation;
3116
3110
  exports.getMinWidth = getMinWidth;
3117
3111
  exports.setupContainerStyles = setupContainerStyles;
3118
- exports.simpleAnimation = simpleAnimation;
3119
3112
  //# sourceMappingURL=index.cjs.js.map