| 1 |
// A block entering on scroll measures where the animation starts. |
| 2 |
export const whenAnimationsSettle = (el, onSettled) => { |
| 3 |
const running = el?.getAnimations?.({ subtree: true }) ?? []; |
| 4 |
if (!running.length) return () => {}; |
| 5 |
let dropped = false; |
| 6 |
Promise.all(running.map((animation) => animation.finished)) |
| 7 |
.then(() => !dropped && onSettled()) |
| 8 |
// A cancelled animation rejects, and means nothing landed to re-measure. |
| 9 |
.catch(() => {}); |
| 10 |
return () => { |
| 11 |
dropped = true; |
| 12 |
}; |
| 13 |
}; |
| 14 |
|