@@ -100,6 +100,11 @@ const DEL = "__aa_del"
100100 */
101101const NEW = "__aa_new"
102102
103+ /**
104+ * Track elements that have had an off-viewport initialization update.
105+ */
106+ const seen = new WeakSet < Element > ( )
107+
103108/**
104109 * Callback for handling all mutations.
105110 * @param mutations - A mutation list
@@ -148,7 +153,13 @@ function observePosition(el: Element) {
148153 . map ( ( px ) => `${ - 1 * Math . floor ( px ) } px` )
149154 . join ( " " )
150155 const observer = new IntersectionObserver (
151- ( ) => {
156+ ( entries ) => {
157+ const entry = entries [ 0 ]
158+ if ( entry && entry . target === el && ! entry . isIntersecting && ! seen . has ( el ) ) {
159+ seen . add ( el )
160+ updatePos ( el )
161+ return
162+ }
152163 ++ invocations > 1 && updatePos ( el )
153164 } ,
154165 {
@@ -442,7 +453,21 @@ export function getTransitionSizes(
442453function getOptions ( el : Element ) : AutoAnimateOptions | AutoAnimationPlugin {
443454 return TGT in el && options . has ( ( el as Element & { __aa_tgt : Element } ) [ TGT ] )
444455 ? options . get ( ( el as Element & { __aa_tgt : Element } ) [ TGT ] ) !
445- : { duration : 250 , easing : "ease-in-out" }
456+ : defaultOptions
457+ }
458+
459+ /**
460+ * Global default options used when none are provided.
461+ */
462+ let defaultOptions : AutoAnimateOptions = { duration : 250 , easing : "ease-in-out" }
463+
464+ /**
465+ * Allows consumers to configure library-wide default options.
466+ */
467+ export function setAutoAnimateDefaults (
468+ opts : Partial < AutoAnimateOptions >
469+ ) : void {
470+ defaultOptions = { ...defaultOptions , ...opts }
446471}
447472
448473/**
@@ -812,7 +837,7 @@ export interface AutoAnimationPlugin {
812837 * @param el - A parent element to add animations to.
813838 * @param options - An optional object of options.
814839 */
815- export default function autoAnimate (
840+ export function autoAnimate (
816841 el : HTMLElement ,
817842 config : Partial < AutoAnimateOptions > | AutoAnimationPlugin = { }
818843) : AnimationController {
@@ -831,7 +856,7 @@ export default function autoAnimate(
831856 if ( isPlugin ( config ) ) {
832857 options . set ( el , config )
833858 } else {
834- options . set ( el , { duration : 250 , easing : "ease-in-out" , ...config } )
859+ options . set ( el , { ... defaultOptions , ...config } )
835860 }
836861 mutations . observe ( el , { childList : true } )
837862 parents . add ( el )
@@ -844,6 +869,11 @@ export default function autoAnimate(
844869 } ,
845870 disable : ( ) => {
846871 enabled . delete ( el )
872+ // Cancel in-flight animations and immediate timers
873+ forEach ( el , ( child ) => {
874+ animations . get ( child ) ?. cancel ( )
875+ clearTimeout ( debounces . get ( child ) )
876+ } )
847877 } ,
848878 isEnabled : ( ) => enabled . has ( el ) ,
849879 } )
0 commit comments