UNPKG

1.58 kBJavaScriptView Raw
1import define from '../../define';
2import * as util from '../../util';
3import stepAll from './step-all';
4
5let corefn = ({
6
7 // pull in animation functions
8 animate: define.animate(),
9 animation: define.animation(),
10 animated: define.animated(),
11 clearQueue: define.clearQueue(),
12 delay: define.delay(),
13 delayAnimation: define.delayAnimation(),
14 stop: define.stop(),
15
16 addToAnimationPool: function( eles ){
17 let cy = this;
18
19 if( !cy.styleEnabled() ){ return; } // save cycles when no style used
20
21 cy._private.aniEles.merge( eles );
22 },
23
24 stopAnimationLoop: function(){
25 this._private.animationsRunning = false;
26 },
27
28 startAnimationLoop: function(){
29 let cy = this;
30
31 cy._private.animationsRunning = true;
32
33 if( !cy.styleEnabled() ){ return; } // save cycles when no style used
34
35 // NB the animation loop will exec in headless environments if style enabled
36 // and explicit cy.destroy() is necessary to stop the loop
37
38 function headlessStep(){
39 if( !cy._private.animationsRunning ){ return; }
40
41 util.requestAnimationFrame( function animationStep( now ){
42 stepAll( now, cy );
43 headlessStep();
44 } );
45 }
46
47 let renderer = cy.renderer();
48
49 if( renderer && renderer.beforeRender ){ // let the renderer schedule animations
50 renderer.beforeRender( function rendererAnimationStep( willDraw, now ){
51 stepAll( now, cy );
52 }, renderer.beforeRenderPriorities.animations );
53 } else { // manage the animation loop ourselves
54 headlessStep(); // first call
55 }
56 }
57
58});
59
60export default corefn;