import { useRef, useLayoutEffect } from 'react';

let stashedTime;
function useSynchronizedAnimation(animationName) {
  const ref = useRef();
  useLayoutEffect(() => {
    const animations = document.getAnimations().filter((animation) => animation.animationName === animationName);
    const myAnimation = animations.find(
      (animation) => (animation == null ? void 0 : animation.effect).target === ref.current
    );
    if (myAnimation && myAnimation === animations[0] && stashedTime) {
      myAnimation.currentTime = stashedTime;
    }
    if (myAnimation && myAnimation !== animations[0]) {
      myAnimation.currentTime = animations[0].currentTime;
    }
    return () => {
      if (myAnimation && myAnimation === animations[0] && myAnimation.currentTime) {
        stashedTime = myAnimation.currentTime;
      }
    };
  }, [animationName]);
  return ref;
}

export { useSynchronizedAnimation as default };
//# sourceMappingURL=useSynchronizedAnimation.js.map
