'use strict' ; import type AnimationOptions from './AnimationOptions' ; import type Chart from '../Chart/Chart' ; import type CSSObject from '../Renderer/CSSObject' ; import type { HTMLDOMElement } from '../Renderer/DOMElementType' ; import type Series from '../Series/Series' ; import type SVGAttributes from '../Renderer/SVG/SVGAttributes' ; import type SVGElement from '../Renderer/SVG/SVGElement' ; import Fx from './Fx.js' ; import U from '../Utilities.js' ; const { defined , getStyle , isArray , isNumber , isObject , merge , objectEach , pick } = U ; function param { boolean | Partial < Highcharts . AnimationOptionsObject > | undefined } animation param { Highcharts . Chart } chart todo function setAnimation ( animation , chart ) { chart . renderer . globalAnimation = pick ( animation , chart . options . chart . animation , true ) ; } function param { boolean | Highcharts . AnimationOptionsObject } animation return { Highcharts . AnimationOptionsObject } function animObject ( animation ? ) { return isObject ( animation ) ? merge ( { duration : 500 , defer : 0 } , animation as AnimationOptions ) as any : { duration : animation as boolean ? 500 : 0 , defer : 0 } ; } function param { Highcharts . Chart } chart param { boolean | Highcharts . AnimationOptionsObject } animation param { Highcharts . Series } series return { number } function getDeferredAnimation ( chart , animation , series ? ) { const labelAnimation = animObject ( animation ) , s = series ? [ series ] : chart . series ; let defer = 0 , duration = 0 ; s . forEach ( ( series ) : void => { const seriesAnim = animObject ( series . options . animation ) ; defer = animation && defined ( animation . defer ) ? labelAnimation . defer : Math . max ( defer , seriesAnim . duration + seriesAnim . defer ) ; duration = Math . min ( labelAnimation . duration , seriesAnim . duration ) ; } ) ; if ( chart . renderer . forExport ) { defer = 0 ; } const anim = { defer : Math . max ( 0 , defer - duration ) , duration : Math . min ( defer , duration ) } ; return anim ; } function param { Highcharts . HTMLDOMElement | Highcharts . SVGElement } el param { Highcharts . CSSObject | Highcharts . SVGAttributes } params param { Partial < Highcharts . AnimationOptionsObject > } opt return { void } function animate ( el , params , opt ? ) { let start , unit = '' , end , fx , args ; if ( ! isObject ( opt ) ) { args = arguments ; opt = { duration : args [ 2 ] , easing : args [ 3 ] , complete : args [ 4 ] } ; } if ( ! isNumber ( opt . duration ) ) { opt . duration = 400 ; } opt . easing = typeof opt . easing === 'function' ? opt . easing : ( Math [ opt . easing as keyof Math ] || Math . easeInOutSine ) as any ; opt . curAnim = merge ( params ) as any ; objectEach ( params , function ( val , prop ) : void { stop ( el as any , prop ) ; fx = new Fx ( el as any , opt as any , prop ) ; end = void 0 ; if ( ( prop as any ) === 'd' && isArray ( ( params as any ) . d ) ) { fx . paths = fx . initPath ( el as any , ( el as any ) . pathArray , ( params as any ) . d ) ; fx . toD = ( params as any ) . d ; start = 0 ; end = 1 ; } else if ( ( el as any ) . attr ) { start = ( el as any ) . attr ( prop ) ; } else { start = parseFloat ( getStyle ( el as any , prop ) as any ) || 0 ; if ( prop !== 'opacity' ) { unit = 'px' ; } } if ( ! end ) { end = val ; } if ( typeof end === 'string' && end . match ( 'px' ) ) { end = end . replace ( /px/g , '' ) ; } fx . run ( start as any , end as any , unit ) ; } ) ; } function param { Highcharts . SVGElement } el param { string } prop return { void } todo function stop ( el , prop ? ) { let i = Fx . timers . length ; while ( i -- ) { if ( Fx . timers [ i ] . elem === el && ( ! prop || prop === Fx . timers [ i ] . prop ) ) { Fx . timers [ i ] . stopped = true ; } } } const animationExports = { animate , animObject , getDeferredAnimation , setAnimation , stop } ; export default animationExports ;