@udixio/ui-react 2.5.0 → 2.5.2

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.
@@ -1 +1 @@
1
- {"version":3,"file":"AnimateOnScroll.d.ts","sourceRoot":"","sources":["../../../src/lib/effects/AnimateOnScroll.ts"],"names":[],"mappings":"AAkLA,MAAM,MAAM,sBAAsB,GAAG;IACnC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB,CAAC;AAEF,wBAAgB,mBAAmB,CACjC,OAAO,GAAE,sBAA2B,GACnC,MAAM,IAAI,CAgIZ;AAGD,eAAO,MAAM,mBAAmB,4BAAsB,CAAC;AACvD,eAAO,MAAM,eAAe,4BAAsB,CAAC"}
1
+ {"version":3,"file":"AnimateOnScroll.d.ts","sourceRoot":"","sources":["../../../src/lib/effects/AnimateOnScroll.ts"],"names":[],"mappings":"AAoNA,MAAM,MAAM,sBAAsB,GAAG;IACnC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB,CAAC;AAEF,wBAAgB,mBAAmB,CACjC,OAAO,GAAE,sBAA2B,GACnC,MAAM,IAAI,CAsIZ;AAGD,eAAO,MAAM,mBAAmB,4BAAsB,CAAC;AACvD,eAAO,MAAM,eAAe,4BAAsB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@udixio/ui-react",
3
- "version": "2.5.0",
3
+ "version": "2.5.2",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -176,6 +176,40 @@ function resetRunFlags(el: HTMLElement, prefix: string): void {
176
176
  // IO thresholds centralized for clarity
177
177
  const IO_THRESHOLD: number[] = [0, 0.2];
178
178
 
179
+ // Track which elements have animation lifecycle listeners attached
180
+ const listenersAttached = new WeakSet<Element>();
181
+
182
+ function addAnimationLifecycle(el: HTMLElement, prefix: string): void {
183
+ if (listenersAttached.has(el)) return;
184
+ listenersAttached.add(el);
185
+
186
+ const onStart = (e: AnimationEvent) => {
187
+ if (e.target !== el) return;
188
+ // Only mark as animating if this animation was initiated by our run flags.
189
+ // This avoids setting data-{prefix}-animating during hydration or passive CSS animations
190
+ // which would block the initial in/out trigger from IntersectionObserver.
191
+ if (
192
+ el.hasAttribute(`data-${prefix}-in-run`) ||
193
+ el.hasAttribute(`data-${prefix}-out-run`)
194
+ ) {
195
+ el.setAttribute(`data-${prefix}-animating`, ``);
196
+ }
197
+ };
198
+
199
+ const onEndOrCancel = (e: AnimationEvent) => {
200
+ if (e.target !== el) return;
201
+ el.removeAttribute(`data-${prefix}-animating`);
202
+ // Clear directional run flags so a new trigger can happen after completion
203
+ el.removeAttribute(`data-${prefix}-in-run`);
204
+ el.removeAttribute(`data-${prefix}-out-run`);
205
+ // Note: keep generic data-{prefix}-run for style stability
206
+ };
207
+
208
+ el.addEventListener('animationstart', onStart as EventListener);
209
+ el.addEventListener('animationend', onEndOrCancel as EventListener);
210
+ el.addEventListener('animationcancel', onEndOrCancel as EventListener);
211
+ }
212
+
179
213
  export type AnimateOnScrollOptions = {
180
214
  prefix?: string;
181
215
  once?: boolean;
@@ -202,6 +236,9 @@ export function initAnimateOnScroll(
202
236
 
203
237
  if (!isJsObserverCandidate(el)) continue;
204
238
 
239
+ // If an animation is in progress, avoid re-triggering or flipping direction
240
+ if (el.hasAttribute(`data-${prefix}-animating`)) continue;
241
+
205
242
  const isOut = el.classList.contains(`${prefix}-out`);
206
243
 
207
244
  if (!isOut && entry.isIntersecting) {
@@ -211,6 +248,7 @@ export function initAnimateOnScroll(
211
248
  setRunFlag(el, prefix, 'out');
212
249
  if (once) io.unobserve(el);
213
250
  } else if (!once) {
251
+ // Only reset flags if not currently animating (already checked), to prevent rapid restarts
214
252
  resetRunFlags(el, prefix);
215
253
  }
216
254
  }
@@ -224,6 +262,7 @@ export function initAnimateOnScroll(
224
262
  if (observed.has(el)) continue;
225
263
  observed.add(el);
226
264
  io.observe(el);
265
+ addAnimationLifecycle(el, prefix);
227
266
  }
228
267
  };
229
268
 
@@ -258,6 +297,7 @@ export function initAnimateOnScroll(
258
297
  if (!observed.has(t)) {
259
298
  observed.add(t);
260
299
  io.observe(t);
300
+ addAnimationLifecycle(t as HTMLElement, prefix);
261
301
  }
262
302
  }
263
303
  }