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.
package/dist/index.d.ts CHANGED
@@ -87,8 +87,9 @@ type GSAPReactMarqueeProps = {
87
87
  */
88
88
  followScrollDir?: boolean;
89
89
  /**
90
- * @description Speed factor when syncing with page scroll
90
+ * @description Speed factor when syncing with page scroll, max value is 4
91
91
  * @type {number}
92
+ * @default 2.5
92
93
  */
93
94
  scrollSpeed?: number;
94
95
  };
@@ -97,24 +98,119 @@ declare const GSAPReactMarquee: react.ForwardRefExoticComponent<GSAPReactMarquee
97
98
 
98
99
  /**
99
100
  * Utility function to merge Tailwind classes with clsx
101
+ *
102
+ * Combines clsx for conditional classes with tailwind-merge to handle
103
+ * conflicting Tailwind classes by keeping the last occurrence.
104
+ * This prevents issues like "p-4 p-2" where both would be applied.
105
+ *
106
+ * @param inputs - Array of class values (strings, conditionals, objects)
107
+ * @returns Merged and deduplicated class string
100
108
  */
101
109
  declare const cn: (...inputs: ClassValue[]) => string;
102
110
  /**
103
- * Sets up container styles and rotation handling
111
+ * Traverses the DOM tree upward to find the first non-transparent background color
112
+ *
113
+ * This function walks up the element hierarchy starting from the given element,
114
+ * checking each parent's computed backgroundColor style until it finds a visible
115
+ * (non-transparent) background color. This is useful for automatically detecting
116
+ * the effective background behind an element for gradient overlays.
117
+ *
118
+ * The traversal stops at the first element with a visible background color,
119
+ * which could be the element itself or any of its ancestors up to the document root.
120
+ *
121
+ * @param el - The HTMLElement to start the background color search from
122
+ * @returns The first non-transparent background color found in the hierarchy,
123
+ * or "transparent" if no visible background is found
124
+ *
125
+ * @example
126
+ * // Element with white parent background
127
+ * const color = getEffectiveBackgroundColor(marqueeElement);
128
+ * // Returns: "rgb(255, 255, 255)" or "#ffffff"
129
+ *
130
+ * @example
131
+ * // Element with no background set anywhere in hierarchy
132
+ * const color = getEffectiveBackgroundColor(marqueeElement);
133
+ * // Returns: "transparent"
134
+ */
135
+ declare const getEffectiveBackgroundColor: (el: HTMLElement) => string;
136
+ /**
137
+ * Sets up container styles and rotation handling for the marquee
138
+ *
139
+ * This function handles the complex styling requirements for different marquee orientations:
140
+ *
141
+ * 1. **Basic Setup**: Applies gap spacing and rotation for vertical marquees
142
+ * 2. **Vertical Mode**: Rotates container 90° and adjusts width to parent height
143
+ * 3. **Rotation Alignment**: Special mode for vertical text that remains readable
144
+ *
145
+ * @param containerMarquee - The main container element that holds all marquee instances
146
+ * @param marquees - Array of individual marquee wrapper elements
147
+ * @param marqueesChildren - Array of content container elements within each marquee
148
+ * @param isVertical - Boolean indicating if marquee moves up/down instead of left/right
149
+ * @param props - Configuration object containing spacing and alignment options
104
150
  */
105
151
  declare const setupContainerStyles: (containerMarquee: HTMLElement, marquees: HTMLElement[], marqueesChildren: HTMLElement[], isVertical: boolean, props: GSAPReactMarqueeProps) => void;
106
152
  /**
107
- * Calculates the number of duplicates needed to fill the container
153
+ * Calculates the number of content duplicates needed for seamless looping
154
+ *
155
+ * For smooth infinite scrolling, we need enough content copies to fill the visible area
156
+ * plus buffer space. This prevents gaps when content loops back to the beginning.
157
+ *
158
+ * Algorithm:
159
+ * 1. If not in fill mode, only one copy is needed (content already spans container)
160
+ * 2. Determine target width (viewport height for vertical, container width for horizontal)
161
+ * 3. Calculate how many copies fit in the target space, rounding up for complete coverage
162
+ *
163
+ * @param marqueeChildrenWidth - Width of a single content instance
164
+ * @param containerMarqueeWidth - Width of the marquee container
165
+ * @param isVertical - Whether the marquee scrolls vertically
166
+ * @param props - Configuration object containing fill mode setting
167
+ * @returns Number of content duplicates needed (minimum 1)
108
168
  */
109
169
  declare const calculateDuplicates: (marqueeChildrenWidth: number, containerMarqueeWidth: number, isVertical: boolean, props: GSAPReactMarqueeProps) => number;
110
170
  /**
111
- * Determines the minimum width for marquee elements
171
+ * Determines the minimum width for marquee elements based on content and container
172
+ *
173
+ * This function ensures marquee elements have appropriate dimensions for their content
174
+ * and container context, handling different modes and orientations.
175
+ *
176
+ * Width determination logic:
177
+ * 1. **Fill mode**: Auto width lets content size naturally
178
+ * 2. **Rotation alignment**: Use content height as width (rotated dimensions)
179
+ * 3. **Undersized content**: Stretch to 100% to fill container
180
+ * 4. **Oversized content**: Use actual content width for overflow scrolling
181
+ *
182
+ * @param marqueesChildren - Array of content elements for dimension measurement
183
+ * @param totalWidth - Combined width of all content elements
184
+ * @param containerMarqueeWidth - Available container width
185
+ * @param props - Configuration object containing fill and alignment settings
186
+ * @returns CSS width value (string with units or number for pixels)
112
187
  */
113
188
  declare const getMinWidth: (marqueesChildren: HTMLElement[], totalWidth: number, containerMarqueeWidth: number, props: GSAPReactMarqueeProps) => string | number;
114
189
  /**
115
190
  * Creates a complex fill-based marquee animation with seamless looping
191
+ *
192
+ * This is the core animation engine that creates smooth, continuous scrolling.
193
+ * It handles the complex math required for seamless looping by calculating
194
+ * precise positions and durations for each content element.
195
+ *
196
+ * Animation Strategy:
197
+ * 1. **Position Calculation**: Convert pixel positions to percentages for responsive scaling
198
+ * 2. **Seamless Looping**: Calculate track length and loop points to prevent gaps
199
+ * 3. **Staggered Animation**: Each element starts at different times for smooth flow
200
+ * 4. **Direction Handling**: Support forward and reverse directions with proper timing
201
+ *
202
+ * Technical Details:
203
+ * - Uses xPercent for percentage-based positioning (responsive to element width changes)
204
+ * - Creates two-part animation: main movement + seamless loop reset
205
+ * - Calculates precise durations based on distance and speed for consistent motion
206
+ *
207
+ * @param elementsToAnimate - Array of DOM elements to animate (content or containers)
208
+ * @param startX - Starting X position reference point
209
+ * @param tl - GSAP timeline to add animations to
210
+ * @param isReverse - Whether animation should play in reverse direction
211
+ * @param props - Configuration object with spacing, speed, delay, and other settings
116
212
  */
117
213
  declare const coreAnimation: (elementsToAnimate: HTMLElement[], startX: number, tl: gsap.core.Timeline, isReverse: boolean, props: GSAPReactMarqueeProps) => void;
118
214
 
119
- export { calculateDuplicates, cn, coreAnimation, GSAPReactMarquee as default, getMinWidth, setupContainerStyles };
215
+ export { calculateDuplicates, cn, coreAnimation, GSAPReactMarquee as default, getEffectiveBackgroundColor, getMinWidth, setupContainerStyles };
120
216
  export type { GSAPReactMarqueeProps };
@@ -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}