gsap-react-marquee 0.1.7 → 0.1.8
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.cjs.js +70 -42
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +70 -42
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -7898,9 +7898,9 @@ const coreAnimation = (elementsToAnimate, startX, tl, isReverse, draggableTrigge
|
|
|
7898
7898
|
|
|
7899
7899
|
gsap$4.registerPlugin(useGSAP, Observer, InertiaPlugin, Draggable);
|
|
7900
7900
|
const GSAPReactMarquee = forwardRef((props, ref) => {
|
|
7901
|
-
const { children, className, dir = "left", loop = -1, paused = false, fill = false, followScrollDir = false, scrollSpeed = 2.5, gradient = false, gradientColor = null, } = props;
|
|
7902
|
-
const rootRef = useRef(null)
|
|
7903
|
-
const containerRef = rootRef;
|
|
7901
|
+
const { children, className, dir = "left", loop = -1, paused = false, fill = false, followScrollDir = false, scrollSpeed = 2.5, gradient = false, gradientColor = null, pauseOnHover = false, } = props;
|
|
7902
|
+
const rootRef = useRef(null);
|
|
7903
|
+
const containerRef = ref || rootRef;
|
|
7904
7904
|
const marqueeRef = useRef(null);
|
|
7905
7905
|
const [marqueeDuplicates, setMarqueeDuplicates] = useState(1);
|
|
7906
7906
|
const [effectivelyGradient, setEffectivelyGradient] = useState(null);
|
|
@@ -7912,8 +7912,8 @@ const GSAPReactMarquee = forwardRef((props, ref) => {
|
|
|
7912
7912
|
}, [gradient]);
|
|
7913
7913
|
const isVertical = dir === "up" || dir === "down";
|
|
7914
7914
|
const isReverse = dir === "down" || dir === "right";
|
|
7915
|
-
useGSAP(() => {
|
|
7916
|
-
if (!(marqueeRef === null || marqueeRef === void 0 ? void 0 : marqueeRef.current) || !containerRef.current)
|
|
7915
|
+
useGSAP((_, contextSafe) => {
|
|
7916
|
+
if (!(marqueeRef === null || marqueeRef === void 0 ? void 0 : marqueeRef.current) || !containerRef.current || !contextSafe)
|
|
7917
7917
|
return;
|
|
7918
7918
|
const containerMarquee = containerRef === null || containerRef === void 0 ? void 0 : containerRef.current;
|
|
7919
7919
|
const marquees = gsap$4.utils.toArray(containerMarquee.querySelectorAll(".gsap-react-marquee"));
|
|
@@ -7936,6 +7936,7 @@ const GSAPReactMarquee = forwardRef((props, ref) => {
|
|
|
7936
7936
|
const containerMarqueeWidth = containerMarquee.offsetWidth;
|
|
7937
7937
|
const marqueeChildrenWidth = marqueesChildren[0].offsetWidth;
|
|
7938
7938
|
const startX = marqueesChildren[0].offsetLeft;
|
|
7939
|
+
let obs = null;
|
|
7939
7940
|
// Clamp scrollSpeed to valid range (1.1 to 4.0)
|
|
7940
7941
|
const clampedScrollSpeed = Math.min(4, Math.max(1.1, scrollSpeed));
|
|
7941
7942
|
setMarqueeDuplicates(calculateDuplicates(marqueeChildrenWidth, containerMarqueeWidth, isVertical, props));
|
|
@@ -7962,45 +7963,72 @@ const GSAPReactMarquee = forwardRef((props, ref) => {
|
|
|
7962
7963
|
* - Speed changes are smoothly animated with acceleration and deceleration phases
|
|
7963
7964
|
* - ScrollSpeed multiplier is applied and clamped to valid range
|
|
7964
7965
|
*/
|
|
7965
|
-
|
|
7966
|
-
|
|
7967
|
-
|
|
7968
|
-
|
|
7969
|
-
|
|
7970
|
-
|
|
7971
|
-
|
|
7972
|
-
|
|
7973
|
-
|
|
7974
|
-
|
|
7975
|
-
|
|
7976
|
-
|
|
7977
|
-
|
|
7978
|
-
|
|
7979
|
-
|
|
7980
|
-
|
|
7981
|
-
|
|
7982
|
-
|
|
7983
|
-
|
|
7984
|
-
|
|
7985
|
-
|
|
7986
|
-
|
|
7987
|
-
|
|
7988
|
-
|
|
7989
|
-
}
|
|
7990
|
-
|
|
7991
|
-
|
|
7992
|
-
|
|
7993
|
-
|
|
7994
|
-
|
|
7995
|
-
|
|
7996
|
-
|
|
7997
|
-
|
|
7998
|
-
|
|
7999
|
-
},
|
|
8000
|
-
}
|
|
7966
|
+
if (followScrollDir) {
|
|
7967
|
+
obs = Observer.create({
|
|
7968
|
+
onChangeY(self) {
|
|
7969
|
+
let factor = clampedScrollSpeed * (isReverse ? -1 : 1);
|
|
7970
|
+
if (self.deltaY < 0) {
|
|
7971
|
+
factor *= -1;
|
|
7972
|
+
}
|
|
7973
|
+
/**
|
|
7974
|
+
* Create smooth speed transition animation
|
|
7975
|
+
*
|
|
7976
|
+
* Phase 1: Quick acceleration to new speed (0.2s)
|
|
7977
|
+
* - timeScale: Controls timeline playback speed (higher = faster)
|
|
7978
|
+
* - factor * clampedScrollSpeed: Initial speed boost for responsive feel
|
|
7979
|
+
* - overwrite: Cancels any previous speed animations
|
|
7980
|
+
*
|
|
7981
|
+
* Phase 2: Gradual deceleration to sustained speed (1s delay + 1s duration)
|
|
7982
|
+
* - factor / clampedScrollSpeed: Settle to a more moderate sustained speed
|
|
7983
|
+
* - "+=0.3": Wait 0.3 seconds before starting deceleration
|
|
7984
|
+
*/
|
|
7985
|
+
gsap$4
|
|
7986
|
+
.timeline({
|
|
7987
|
+
defaults: {
|
|
7988
|
+
ease: "none",
|
|
7989
|
+
},
|
|
7990
|
+
})
|
|
7991
|
+
.to(tl, {
|
|
7992
|
+
timeScale: factor * clampedScrollSpeed,
|
|
7993
|
+
duration: 0.2,
|
|
7994
|
+
overwrite: true,
|
|
7995
|
+
})
|
|
7996
|
+
.to(tl, {
|
|
7997
|
+
timeScale: factor / clampedScrollSpeed,
|
|
7998
|
+
duration: 1,
|
|
7999
|
+
}, "+=0.3");
|
|
8000
|
+
},
|
|
8001
|
+
});
|
|
8002
|
+
}
|
|
8003
|
+
const onMouseEnter = contextSafe(() => {
|
|
8004
|
+
tl.timeScale(0);
|
|
8005
|
+
});
|
|
8006
|
+
const onMouseLeave = contextSafe(() => {
|
|
8007
|
+
tl.timeScale(1);
|
|
8001
8008
|
});
|
|
8009
|
+
if (pauseOnHover) {
|
|
8010
|
+
containerMarquee.addEventListener("mouseenter", onMouseEnter);
|
|
8011
|
+
containerMarquee.addEventListener("mouseleave", onMouseLeave);
|
|
8012
|
+
}
|
|
8013
|
+
return () => {
|
|
8014
|
+
containerMarquee.removeEventListener("mouseenter", onMouseEnter);
|
|
8015
|
+
containerMarquee.removeEventListener("mouseleave", onMouseLeave);
|
|
8016
|
+
tl.kill();
|
|
8017
|
+
obs === null || obs === void 0 ? void 0 : obs.kill();
|
|
8018
|
+
};
|
|
8002
8019
|
}, {
|
|
8003
|
-
dependencies: [
|
|
8020
|
+
dependencies: [
|
|
8021
|
+
marqueeDuplicates,
|
|
8022
|
+
dir,
|
|
8023
|
+
loop,
|
|
8024
|
+
paused,
|
|
8025
|
+
fill,
|
|
8026
|
+
followScrollDir,
|
|
8027
|
+
scrollSpeed,
|
|
8028
|
+
gradient,
|
|
8029
|
+
gradientColor,
|
|
8030
|
+
pauseOnHover,
|
|
8031
|
+
],
|
|
8004
8032
|
});
|
|
8005
8033
|
const getGradientColor = () => {
|
|
8006
8034
|
// Priority order: explicit gradientColor > auto-detected > fallback
|