@udixio/ui-react 2.5.0 → 2.5.1
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/CHANGELOG.md +10 -0
- package/dist/index.cjs +2 -2
- package/dist/index.js +422 -412
- package/dist/lib/effects/AnimateOnScroll.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/lib/effects/AnimateOnScroll.ts +41 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AnimateOnScroll.d.ts","sourceRoot":"","sources":["../../../src/lib/effects/AnimateOnScroll.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"AnimateOnScroll.d.ts","sourceRoot":"","sources":["../../../src/lib/effects/AnimateOnScroll.ts"],"names":[],"mappings":"AAqNA,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.
|
|
3
|
+
"version": "2.5.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -36,8 +36,8 @@
|
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"react": "^19.1.1",
|
|
38
38
|
"react-dom": "^19.1.1",
|
|
39
|
-
"@udixio/
|
|
40
|
-
"@udixio/
|
|
39
|
+
"@udixio/theme": "2.1.2",
|
|
40
|
+
"@udixio/tailwind": "2.3.7"
|
|
41
41
|
},
|
|
42
42
|
"repository": {
|
|
43
43
|
"type": "git",
|
|
@@ -176,6 +176,41 @@ 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
|
+
el.hasAttribute(`data-${prefix}-run`)
|
|
195
|
+
) {
|
|
196
|
+
el.setAttribute(`data-${prefix}-animating`, ``);
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
const onEndOrCancel = (e: AnimationEvent) => {
|
|
201
|
+
if (e.target !== el) return;
|
|
202
|
+
el.removeAttribute(`data-${prefix}-animating`);
|
|
203
|
+
// Clear directional run flags so a new trigger can happen after completion
|
|
204
|
+
el.removeAttribute(`data-${prefix}-in-run`);
|
|
205
|
+
el.removeAttribute(`data-${prefix}-out-run`);
|
|
206
|
+
// Note: keep generic data-{prefix}-run for style stability
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
el.addEventListener('animationstart', onStart as EventListener);
|
|
210
|
+
el.addEventListener('animationend', onEndOrCancel as EventListener);
|
|
211
|
+
el.addEventListener('animationcancel', onEndOrCancel as EventListener);
|
|
212
|
+
}
|
|
213
|
+
|
|
179
214
|
export type AnimateOnScrollOptions = {
|
|
180
215
|
prefix?: string;
|
|
181
216
|
once?: boolean;
|
|
@@ -202,6 +237,9 @@ export function initAnimateOnScroll(
|
|
|
202
237
|
|
|
203
238
|
if (!isJsObserverCandidate(el)) continue;
|
|
204
239
|
|
|
240
|
+
// If an animation is in progress, avoid re-triggering or flipping direction
|
|
241
|
+
if (el.hasAttribute(`data-${prefix}-animating`)) continue;
|
|
242
|
+
|
|
205
243
|
const isOut = el.classList.contains(`${prefix}-out`);
|
|
206
244
|
|
|
207
245
|
if (!isOut && entry.isIntersecting) {
|
|
@@ -211,6 +249,7 @@ export function initAnimateOnScroll(
|
|
|
211
249
|
setRunFlag(el, prefix, 'out');
|
|
212
250
|
if (once) io.unobserve(el);
|
|
213
251
|
} else if (!once) {
|
|
252
|
+
// Only reset flags if not currently animating (already checked), to prevent rapid restarts
|
|
214
253
|
resetRunFlags(el, prefix);
|
|
215
254
|
}
|
|
216
255
|
}
|
|
@@ -224,6 +263,7 @@ export function initAnimateOnScroll(
|
|
|
224
263
|
if (observed.has(el)) continue;
|
|
225
264
|
observed.add(el);
|
|
226
265
|
io.observe(el);
|
|
266
|
+
addAnimationLifecycle(el, prefix);
|
|
227
267
|
}
|
|
228
268
|
};
|
|
229
269
|
|
|
@@ -258,6 +298,7 @@ export function initAnimateOnScroll(
|
|
|
258
298
|
if (!observed.has(t)) {
|
|
259
299
|
observed.add(t);
|
|
260
300
|
io.observe(t);
|
|
301
|
+
addAnimationLifecycle(t as HTMLElement, prefix);
|
|
261
302
|
}
|
|
262
303
|
}
|
|
263
304
|
}
|