const preact = require('preact'); const { Component } = require('preact'); const anime = require('animejs').default; const { TIMES } = require('../../constants'); class Bash extends Component { constructor() { super(); this.animations = []; } render() { return ( ); } componentDidMount() { this.animations.push(anime({ targets: ['#bash'], opacity: [ { value: 1, delay: TIMES.TARGET_FADE_IN_DELAY, duration: TIMES.TARGET_FADE_IN_DURATION }, // this is badly behaved, nfi why { value: 0, delay: TIMES.FADE_DELAY_MS / 2, duration: TIMES.FADE_OUT_DURATION }, ], easing: 'easeInOutSine', })); this.animations.push(anime({ targets: ['#bash'], scale: { value: 1, delay: TIMES.TARGET_FADE_IN_DELAY, duration: TIMES.TARGET_DURATION_MS * 0.2, easing: 'easeInExpo', }, keyframes: [ { translateX: 0, translateY: 0 }, { translateX: -5, translateY: 0 }, { translateX: 0, translateY: -5 }, { translateX: 5, translateY: 0 }, { translateX: 0, translateY: 5 }, { translateX: -2, translateY: 0 }, { translateX: 0, translateY: -2 }, { translateX: 2, translateY: 0 }, { translateX: 0, translateY: 2 }, ], delay: TIMES.TARGET_FADE_IN_DELAY + TIMES.TARGET_DURATION_MS * 0.1, duration: TIMES.TARGET_DURATION_MS * 0.2, easing: 'easeOutSine', })); this.animations.push(anime({ targets: ['#bashFilter feTurbulence', '#bashFilter feDisplacementMap'], baseFrequency: 2, scale: 10, numOctaves: 5, easing: 'easeOutSine', delay: TIMES.TARGET_FADE_IN_DELAY, duration: TIMES.RESOLUTION_TOTAL_MS, })); } // this is necessary because // skipping / timing / unmounting race conditions // can cause the animations to cut short, this will ensure the values are reset // because preact will recycle all these components componentWillUnmount() { for (let i = this.animations.length - 1; i >= 0; i--) { this.animations[i].reset(); } } } module.exports = Bash;