gsap-react-marquee 0.1.3 → 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.
@@ -84,8 +84,9 @@ export type GSAPReactMarqueeProps = {
84
84
  */
85
85
  followScrollDir?: boolean;
86
86
  /**
87
- * @description Speed factor when syncing with page scroll
87
+ * @description Speed factor when syncing with page scroll, max value is 4
88
88
  * @type {number}
89
+ * @default 2.5
89
90
  */
90
91
  scrollSpeed?: number;
91
92
  };
@@ -2,21 +2,116 @@ import { type ClassValue } from "clsx";
2
2
  import type { GSAPReactMarqueeProps } from "./gsap-react-marquee.type";
3
3
  /**
4
4
  * Utility function to merge Tailwind classes with clsx
5
+ *
6
+ * Combines clsx for conditional classes with tailwind-merge to handle
7
+ * conflicting Tailwind classes by keeping the last occurrence.
8
+ * This prevents issues like "p-4 p-2" where both would be applied.
9
+ *
10
+ * @param inputs - Array of class values (strings, conditionals, objects)
11
+ * @returns Merged and deduplicated class string
5
12
  */
6
13
  export declare const cn: (...inputs: ClassValue[]) => string;
7
14
  /**
8
- * Sets up container styles and rotation handling
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;
40
+ /**
41
+ * Sets up container styles and rotation handling for the marquee
42
+ *
43
+ * This function handles the complex styling requirements for different marquee orientations:
44
+ *
45
+ * 1. **Basic Setup**: Applies gap spacing and rotation for vertical marquees
46
+ * 2. **Vertical Mode**: Rotates container 90° and adjusts width to parent height
47
+ * 3. **Rotation Alignment**: Special mode for vertical text that remains readable
48
+ *
49
+ * @param containerMarquee - The main container element that holds all marquee instances
50
+ * @param marquees - Array of individual marquee wrapper elements
51
+ * @param marqueesChildren - Array of content container elements within each marquee
52
+ * @param isVertical - Boolean indicating if marquee moves up/down instead of left/right
53
+ * @param props - Configuration object containing spacing and alignment options
9
54
  */
10
55
  export declare const setupContainerStyles: (containerMarquee: HTMLElement, marquees: HTMLElement[], marqueesChildren: HTMLElement[], isVertical: boolean, props: GSAPReactMarqueeProps) => void;
11
56
  /**
12
- * Calculates the number of duplicates needed to fill the container
57
+ * Calculates the number of content duplicates needed for seamless looping
58
+ *
59
+ * For smooth infinite scrolling, we need enough content copies to fill the visible area
60
+ * plus buffer space. This prevents gaps when content loops back to the beginning.
61
+ *
62
+ * Algorithm:
63
+ * 1. If not in fill mode, only one copy is needed (content already spans container)
64
+ * 2. Determine target width (viewport height for vertical, container width for horizontal)
65
+ * 3. Calculate how many copies fit in the target space, rounding up for complete coverage
66
+ *
67
+ * @param marqueeChildrenWidth - Width of a single content instance
68
+ * @param containerMarqueeWidth - Width of the marquee container
69
+ * @param isVertical - Whether the marquee scrolls vertically
70
+ * @param props - Configuration object containing fill mode setting
71
+ * @returns Number of content duplicates needed (minimum 1)
13
72
  */
14
73
  export declare const calculateDuplicates: (marqueeChildrenWidth: number, containerMarqueeWidth: number, isVertical: boolean, props: GSAPReactMarqueeProps) => number;
15
74
  /**
16
- * Determines the minimum width for marquee elements
75
+ * Determines the minimum width for marquee elements based on content and container
76
+ *
77
+ * This function ensures marquee elements have appropriate dimensions for their content
78
+ * and container context, handling different modes and orientations.
79
+ *
80
+ * Width determination logic:
81
+ * 1. **Fill mode**: Auto width lets content size naturally
82
+ * 2. **Rotation alignment**: Use content height as width (rotated dimensions)
83
+ * 3. **Undersized content**: Stretch to 100% to fill container
84
+ * 4. **Oversized content**: Use actual content width for overflow scrolling
85
+ *
86
+ * @param marqueesChildren - Array of content elements for dimension measurement
87
+ * @param totalWidth - Combined width of all content elements
88
+ * @param containerMarqueeWidth - Available container width
89
+ * @param props - Configuration object containing fill and alignment settings
90
+ * @returns CSS width value (string with units or number for pixels)
17
91
  */
18
92
  export declare const getMinWidth: (marqueesChildren: HTMLElement[], totalWidth: number, containerMarqueeWidth: number, props: GSAPReactMarqueeProps) => string | number;
19
93
  /**
20
94
  * Creates a complex fill-based marquee animation with seamless looping
95
+ *
96
+ * This is the core animation engine that creates smooth, continuous scrolling.
97
+ * It handles the complex math required for seamless looping by calculating
98
+ * precise positions and durations for each content element.
99
+ *
100
+ * Animation Strategy:
101
+ * 1. **Position Calculation**: Convert pixel positions to percentages for responsive scaling
102
+ * 2. **Seamless Looping**: Calculate track length and loop points to prevent gaps
103
+ * 3. **Staggered Animation**: Each element starts at different times for smooth flow
104
+ * 4. **Direction Handling**: Support forward and reverse directions with proper timing
105
+ *
106
+ * Technical Details:
107
+ * - Uses xPercent for percentage-based positioning (responsive to element width changes)
108
+ * - Creates two-part animation: main movement + seamless loop reset
109
+ * - Calculates precise durations based on distance and speed for consistent motion
110
+ *
111
+ * @param elementsToAnimate - Array of DOM elements to animate (content or containers)
112
+ * @param startX - Starting X position reference point
113
+ * @param tl - GSAP timeline to add animations to
114
+ * @param isReverse - Whether animation should play in reverse direction
115
+ * @param props - Configuration object with spacing, speed, delay, and other settings
21
116
  */
22
117
  export declare const coreAnimation: (elementsToAnimate: HTMLElement[], startX: number, tl: gsap.core.Timeline, isReverse: boolean, props: GSAPReactMarqueeProps) => void;
@@ -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}