function createAnimation()

in blocks/main/latest-news/mascot/index.tsx [21:51]


function createAnimation(
    lottie: LottiePlayer,
    node: Element,
    animationData: Record<string, unknown>
): [AnimationItem, () => Promise<void>] {
    const animation = lottie.loadAnimation({
        container: node,
        renderer: 'svg',
        loop: false,
        autoplay: false,
        animationData,
    });

    const animationComplete = new Promise<void>((resolve) => {
        function done() {
            animation.removeEventListener('complete', done);
            resolve();
        }

        animation.addEventListener('complete', done);
    });

    return [
        animation,
        async () => {
            animation.play();
            await animationComplete;
            animation.destroy();
        },
    ];
}