gsap-react-marquee 0.1.4 → 0.1.5
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 +26 -0
- package/dist/index.cjs.css +1 -1
- package/dist/index.cjs.js +59 -2
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +27 -1
- package/dist/index.esm.css +1 -1
- package/dist/index.esm.js +60 -4
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
|
@@ -11,6 +11,32 @@ import type { GSAPReactMarqueeProps } from "./gsap-react-marquee.type";
|
|
|
11
11
|
* @returns Merged and deduplicated class string
|
|
12
12
|
*/
|
|
13
13
|
export declare const cn: (...inputs: ClassValue[]) => string;
|
|
14
|
+
/**
|
|
15
|
+
* Traverses the DOM tree upward to find the first non-transparent background color
|
|
16
|
+
*
|
|
17
|
+
* This function walks up the element hierarchy starting from the given element,
|
|
18
|
+
* checking each parent's computed backgroundColor style until it finds a visible
|
|
19
|
+
* (non-transparent) background color. This is useful for automatically detecting
|
|
20
|
+
* the effective background behind an element for gradient overlays.
|
|
21
|
+
*
|
|
22
|
+
* The traversal stops at the first element with a visible background color,
|
|
23
|
+
* which could be the element itself or any of its ancestors up to the document root.
|
|
24
|
+
*
|
|
25
|
+
* @param el - The HTMLElement to start the background color search from
|
|
26
|
+
* @returns The first non-transparent background color found in the hierarchy,
|
|
27
|
+
* or "transparent" if no visible background is found
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* // Element with white parent background
|
|
31
|
+
* const color = getEffectiveBackgroundColor(marqueeElement);
|
|
32
|
+
* // Returns: "rgb(255, 255, 255)" or "#ffffff"
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* // Element with no background set anywhere in hierarchy
|
|
36
|
+
* const color = getEffectiveBackgroundColor(marqueeElement);
|
|
37
|
+
* // Returns: "transparent"
|
|
38
|
+
*/
|
|
39
|
+
export declare const getEffectiveBackgroundColor: (el: HTMLElement) => string;
|
|
14
40
|
/**
|
|
15
41
|
* Sets up container styles and rotation handling for the marquee
|
|
16
42
|
*
|
package/dist/index.cjs.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
.gsap-react-marquee{flex:1;height:max-content;width:auto}.gsap-react-marquee,.gsap-react-marquee-content{display:flex;line-height:100%;white-space:preserve nowrap}.gsap-react-marquee-content{overflow:hidden;width:max-content}
|
|
1
|
+
.gsap-react-marquee-container:after{background:linear-gradient(270deg,hsla(0,0%,100%,0) 0,var(--gradient-color) 75%);content:"";height:100%;left:0;position:absolute;top:0;width:15%;z-index:10}.gsap-react-marquee-container:before{background:linear-gradient(90deg,hsla(0,0%,100%,0) 0,var(--gradient-color) 75%);content:"";height:100%;position:absolute;right:0;top:0;width:15%;z-index:10}.gsap-react-marquee{flex:1;height:max-content;width:auto}.gsap-react-marquee,.gsap-react-marquee-content{display:flex;line-height:100%;white-space:preserve nowrap}.gsap-react-marquee-content{overflow:hidden;width:max-content}
|
package/dist/index.cjs.js
CHANGED
|
@@ -3636,6 +3636,43 @@ const twMerge = /*#__PURE__*/createTailwindMerge(getDefaultConfig);
|
|
|
3636
3636
|
const cn = (...inputs) => {
|
|
3637
3637
|
return twMerge(clsx(inputs));
|
|
3638
3638
|
};
|
|
3639
|
+
/**
|
|
3640
|
+
* Traverses the DOM tree upward to find the first non-transparent background color
|
|
3641
|
+
*
|
|
3642
|
+
* This function walks up the element hierarchy starting from the given element,
|
|
3643
|
+
* checking each parent's computed backgroundColor style until it finds a visible
|
|
3644
|
+
* (non-transparent) background color. This is useful for automatically detecting
|
|
3645
|
+
* the effective background behind an element for gradient overlays.
|
|
3646
|
+
*
|
|
3647
|
+
* The traversal stops at the first element with a visible background color,
|
|
3648
|
+
* which could be the element itself or any of its ancestors up to the document root.
|
|
3649
|
+
*
|
|
3650
|
+
* @param el - The HTMLElement to start the background color search from
|
|
3651
|
+
* @returns The first non-transparent background color found in the hierarchy,
|
|
3652
|
+
* or "transparent" if no visible background is found
|
|
3653
|
+
*
|
|
3654
|
+
* @example
|
|
3655
|
+
* // Element with white parent background
|
|
3656
|
+
* const color = getEffectiveBackgroundColor(marqueeElement);
|
|
3657
|
+
* // Returns: "rgb(255, 255, 255)" or "#ffffff"
|
|
3658
|
+
*
|
|
3659
|
+
* @example
|
|
3660
|
+
* // Element with no background set anywhere in hierarchy
|
|
3661
|
+
* const color = getEffectiveBackgroundColor(marqueeElement);
|
|
3662
|
+
* // Returns: "transparent"
|
|
3663
|
+
*/
|
|
3664
|
+
const getEffectiveBackgroundColor = (el) => {
|
|
3665
|
+
let current = el;
|
|
3666
|
+
while (current) {
|
|
3667
|
+
const bg = window.getComputedStyle(current).backgroundColor;
|
|
3668
|
+
// Check if background color is visible (not transparent or rgba(0,0,0,0))
|
|
3669
|
+
if (bg && bg !== "rgba(0, 0, 0, 0)" && bg !== "transparent") {
|
|
3670
|
+
return bg;
|
|
3671
|
+
}
|
|
3672
|
+
current = current.parentElement;
|
|
3673
|
+
}
|
|
3674
|
+
return "transparent"; // fallback when no visible background is found
|
|
3675
|
+
};
|
|
3639
3676
|
/**
|
|
3640
3677
|
* Sets up container styles and rotation handling for the marquee
|
|
3641
3678
|
*
|
|
@@ -3957,11 +3994,18 @@ const coreAnimation = (elementsToAnimate, startX, tl, isReverse, props) => {
|
|
|
3957
3994
|
};
|
|
3958
3995
|
|
|
3959
3996
|
const GSAPReactMarquee = require$$0.forwardRef((props, ref) => {
|
|
3960
|
-
const { children, className, dir = "left", loop = -1, paused = false, fill = false, followScrollDir = false, scrollSpeed = 2.5, } = props;
|
|
3997
|
+
const { children, className, dir = "left", loop = -1, paused = false, fill = false, followScrollDir = false, scrollSpeed = 2.5, gradient = false, gradientColor = null, } = props;
|
|
3961
3998
|
const rootRef = require$$0.useRef(null) || ref;
|
|
3962
3999
|
const containerRef = rootRef;
|
|
3963
4000
|
const marqueeRef = require$$0.useRef(null);
|
|
3964
4001
|
const [marqueeDuplicates, setMarqueeDuplicates] = require$$0.useState(1);
|
|
4002
|
+
const [effectivelyGradient, setEffectivelyGradient] = require$$0.useState(null);
|
|
4003
|
+
require$$0.useLayoutEffect(() => {
|
|
4004
|
+
if (!gradient || !(containerRef === null || containerRef === void 0 ? void 0 : containerRef.current))
|
|
4005
|
+
return;
|
|
4006
|
+
const effectiveBg = getEffectiveBackgroundColor(containerRef.current);
|
|
4007
|
+
setEffectivelyGradient(effectiveBg);
|
|
4008
|
+
}, [gradient]);
|
|
3965
4009
|
const isVertical = dir === "up" || dir === "down";
|
|
3966
4010
|
const isReverse = dir === "down" || dir === "right";
|
|
3967
4011
|
react.useGSAP(() => {
|
|
@@ -4051,6 +4095,16 @@ const GSAPReactMarquee = require$$0.forwardRef((props, ref) => {
|
|
|
4051
4095
|
}, {
|
|
4052
4096
|
dependencies: [marqueeDuplicates],
|
|
4053
4097
|
});
|
|
4098
|
+
const getGradientColor = () => {
|
|
4099
|
+
// Priority order: explicit gradientColor > auto-detected > fallback
|
|
4100
|
+
if (gradientColor) {
|
|
4101
|
+
return gradientColor; // User-specified color takes precedence
|
|
4102
|
+
}
|
|
4103
|
+
if (gradient && effectivelyGradient) {
|
|
4104
|
+
return effectivelyGradient; // Auto-detected background color
|
|
4105
|
+
}
|
|
4106
|
+
return "transparent"; // Default fallback
|
|
4107
|
+
};
|
|
4054
4108
|
/**
|
|
4055
4109
|
* Generate cloned marquee elements for seamless looping
|
|
4056
4110
|
*
|
|
@@ -4063,7 +4117,9 @@ const GSAPReactMarquee = require$$0.forwardRef((props, ref) => {
|
|
|
4063
4117
|
return null;
|
|
4064
4118
|
return Array.from({ length: marqueeDuplicates }, (_, i) => (jsxRuntimeExports.jsx("div", { className: cn("gsap-react-marquee"), children: jsxRuntimeExports.jsx("div", { className: cn("gsap-react-marquee-content", className), children: children }) }, i)));
|
|
4065
4119
|
}, [marqueeDuplicates, className, children]);
|
|
4066
|
-
return (jsxRuntimeExports.jsxs("div", { ref: containerRef,
|
|
4120
|
+
return (jsxRuntimeExports.jsxs("div", { ref: containerRef, style: {
|
|
4121
|
+
"--gradient-color": getGradientColor(),
|
|
4122
|
+
}, className: cn("gsap-react-marquee-container flex w-full overflow-hidden whitespace-nowrap"), children: [jsxRuntimeExports.jsx("div", { ref: marqueeRef, className: cn("gsap-react-marquee"), children: jsxRuntimeExports.jsx("div", { className: cn("gsap-react-marquee-content", className), children: children }) }), clonedMarquees] }));
|
|
4067
4123
|
});
|
|
4068
4124
|
GSAPReactMarquee.displayName = "GSAPReactMarquee";
|
|
4069
4125
|
|
|
@@ -4071,6 +4127,7 @@ exports.calculateDuplicates = calculateDuplicates;
|
|
|
4071
4127
|
exports.cn = cn;
|
|
4072
4128
|
exports.coreAnimation = coreAnimation;
|
|
4073
4129
|
exports.default = GSAPReactMarquee;
|
|
4130
|
+
exports.getEffectiveBackgroundColor = getEffectiveBackgroundColor;
|
|
4074
4131
|
exports.getMinWidth = getMinWidth;
|
|
4075
4132
|
exports.setupContainerStyles = setupContainerStyles;
|
|
4076
4133
|
//# sourceMappingURL=index.cjs.js.map
|