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