/**
 * Animation utility functions. Performs css based transition animations
 */ import { CSSProperties } from "react" ; import { Placement } from "./Airr" ; import { prepareElementForAnimaton , refreshElement , resetElementTransition , setElementTransitions , setElementTransforms } from "./FXHelpers" ; export interface TransitionAnimationConfig { element : HTMLElement ; startProps : CSSProperties ; transitionProps : string [ ] ; endProps : CSSProperties ; preAnimationCallback ? : ( ) => void ; endAfter ? : number ; endCallback ? : ( ) => void ; } /**
 * Animate passed HTML element with power of css transitions
 */ export function doTransitionAnimation ( config ) { const { element , startProps , transitionProps , endProps , preAnimationCallback , endAfter , endCallback } = config ; resetElementTransition ( element ) ; refreshElement ( element ) ; prepareElementForAnimaton ( element , startProps ) ; if ( typeof preAnimationCallback === "function" ) { preAnimationCallback ( ) ; } refreshElement ( element ) ; setElementTransitions ( element , transitionProps ) ; refreshElement ( element ) ; setElementTransforms ( element , endProps ) ; if ( typeof endCallback === "function" && endAfter ) { setTimeout ( function ( ) : void { endCallback && endCallback ( ) ; } , endAfter ) ; } } param { HTMLElement } element param { int } scrollDuration param { string } direction returns { void } export function doVerticalScrollAnimation ( element , scrollDuration , direction ) { if ( [ "top" , "bottom" ] . indexOf ( direction ) === - 1 ) { throw new Error ( "Invalid direction parameter speciefied" ) ; } let scrollHeight = element . scrollHeight , scrollStep = Math . PI / ( scrollDuration / 15 ) , cosParameter = scrollHeight / 2 , scrollCount = 0 , scrollMargin , scrollEnd = direction === "top" ? 0 : scrollHeight - element . parentElement . clientHeight ; let scrollInterval = setInterval ( ( ) : void => { if ( element . scrollTop !== scrollEnd ) { scrollCount += 1 ; scrollMargin = cosParameter - cosParameter * Math . cos ( scrollCount * scrollStep ) ; if ( direction === "top" ) { element . scrollTop = element . scrollTop - scrollMargin ; } else { element . scrollTop = element . scrollTop + scrollMargin ; } } else { clearInterval ( scrollInterval ) ; } } , 15 ) ; }