import type { EventPlugin } from './plugin' ; import type { Timeline } from './timeline' ; export const chunk = ( array , size ) => { if ( ! array . length || ! size ) { return [ ] ; } let index = 0 ; let resIndex = 0 ; const result = new Array ( Math . ceil ( array . length / size ) ) ; while ( index < array . length ) { result [ resIndex ++ ] = array . slice ( index , ( index += size ) ) ; } return result ; } ; export const getAllPlugins = ( timeline ) => { const allPlugins = Object . values ( timeline . plugins ) ; if ( allPlugins . length ) { return allPlugins . reduce ( ( prev = [ ] , curr = [ ] ) => prev . concat ( curr ) ) ; } return [ ] ; } ; export const getPluginsWithFlush = ( timeline ) => { if ( ! timeline ) { return [ ] ; } const allPlugins = getAllPlugins ( timeline ) ; const eventPlugins = allPlugins ?. filter ( ( f ) => ( f as EventPlugin ) . flush ) as EventPlugin [ ] ; return eventPlugins ; } ;