1+ "use strict" ;
2+
3+ Object . defineProperty ( exports , "__esModule" , {
4+ value : true
5+ } ) ;
6+ exports . default = void 0 ;
7+
8+ function _classCallCheck ( instance , Constructor ) { if ( ! ( instance instanceof Constructor ) ) { throw new TypeError ( "Cannot call a class as a function" ) ; } }
9+
10+ function _defineProperties ( target , props ) { for ( var i = 0 ; i < props . length ; i ++ ) { var descriptor = props [ i ] ; descriptor . enumerable = descriptor . enumerable || false ; descriptor . configurable = true ; if ( "value" in descriptor ) descriptor . writable = true ; Object . defineProperty ( target , descriptor . key , descriptor ) ; } }
11+
12+ function _createClass ( Constructor , protoProps , staticProps ) { if ( protoProps ) _defineProperties ( Constructor . prototype , protoProps ) ; if ( staticProps ) _defineProperties ( Constructor , staticProps ) ; return Constructor ; }
13+
14+ var loopIsActive = false ;
15+ var animationFrame = null ;
16+ var loopRegister = [ ] ;
17+
18+ var LoopController =
19+ /*#__PURE__*/
20+ function ( ) {
21+ function LoopController ( ) {
22+ _classCallCheck ( this , LoopController ) ;
23+
24+ this . rafStep = this . rafStep . bind ( this ) ;
25+ }
26+
27+ _createClass ( LoopController , [ {
28+ key : "getRegisteredItems" ,
29+ value : function getRegisteredItems ( ) {
30+ return loopRegister . concat ( ) ;
31+ }
32+ } , {
33+ key : "registerScrollbar" ,
34+ value : function registerScrollbar ( scrollbar ) {
35+ if ( ! loopRegister . includes ( scrollbar ) ) {
36+ loopRegister . push ( scrollbar ) ;
37+ this . start ( ) ;
38+ }
39+
40+ return this ;
41+ }
42+ } , {
43+ key : "unregisterScrollbar" ,
44+ value : function unregisterScrollbar ( scrollbar ) {
45+ var index = loopRegister . indexOf ( scrollbar ) ;
46+
47+ if ( index !== - 1 ) {
48+ loopRegister . length === 1 && this . stop ( ) ;
49+ loopRegister . splice ( index , 1 ) ;
50+ }
51+
52+ return this ;
53+ }
54+ } , {
55+ key : "start" ,
56+ value : function start ( ) {
57+ if ( ! loopIsActive ) {
58+ loopIsActive = true ;
59+ animationFrame && cancelAnimationFrame ( animationFrame ) ;
60+ animationFrame = requestAnimationFrame ( this . rafStep ) ;
61+ }
62+
63+ return this ;
64+ }
65+ } , {
66+ key : "rafStep" ,
67+ value : function rafStep ( ) {
68+ if ( ! loopIsActive ) {
69+ return ;
70+ }
71+
72+ for ( var i = 0 ; i < loopRegister . length ; i ++ ) {
73+ loopRegister [ i ] . update ( ) ;
74+ }
75+
76+ animationFrame = requestAnimationFrame ( this . rafStep ) ;
77+ }
78+ } , {
79+ key : "stop" ,
80+ value : function stop ( ) {
81+ if ( loopIsActive ) {
82+ loopIsActive = false ;
83+ animationFrame && cancelAnimationFrame ( animationFrame ) ;
84+ }
85+
86+ return this ;
87+ }
88+ } ] ) ;
89+
90+ return LoopController ;
91+ } ( ) ;
92+
93+ var instance = new LoopController ( ) ;
94+ var _default = instance ;
95+ exports . default = _default ;
0 commit comments