Capítulo 185 de 411
GSAP has no built-in onReverse() callback; this helper detects direction changes on any animation (even deeply nested inside parent timelines whose own reversal/negative timeScale affects it) by comparing each frame's totalTime() to the previous one.
trackDirection({ animation, onUpdate, onToggle }) (or pass a plain callback as value for direct onUpdate usage) hooks the animation's onUpdate via eventCallback.this.direction (1 or -1) on the animation every frame; onToggle fires only when the direction actually flips, onUpdate fires every frame.totalTime() trend, not from assumptions about its parent.