@@ -49,7 +49,7 @@ export interface CarouselOptions extends BaseOptions{
4949 onCycleTo : ( current : Element , dragged : boolean ) => void ;
5050}
5151
52- let _defaults : CarouselOptions = {
52+ const _defaults : CarouselOptions = {
5353 duration : 200 , // ms
5454 dist : - 100 , // zoom scale TODO: make this more intuitive as an option
5555 shift : 0 , // spacing for center image
@@ -72,25 +72,25 @@ export class Carousel extends Component<CarouselOptions> {
7272 offset : number ;
7373 target : number ;
7474 images : HTMLElement [ ] ;
75- itemWidth : any ;
76- itemHeight : any ;
75+ itemWidth : number ;
76+ itemHeight : number ;
7777 dim : number ;
78- _indicators : any ;
78+ _indicators : HTMLUListElement ;
7979 count : number ;
8080 xform : string ;
8181 verticalDragged : boolean ;
82- reference : any ;
83- referenceY : any ;
82+ reference : number ;
83+ referenceY : number ;
8484 velocity : number ;
8585 frame : number ;
8686 timestamp : number ;
8787 ticker : string | number | NodeJS . Timeout ;
8888 amplitude : number ;
8989 /** The index of the center carousel item. */
9090 center : number = 0 ;
91- imageHeight : any ;
92- scrollingTimeout : any ;
93- oneTimeCallback : any ;
91+ imageHeight : number ;
92+ scrollingTimeout : number | NodeJS . Timeout ;
93+ oneTimeCallback : ( current : Element , dragged : boolean ) => void | null ;
9494
9595 constructor ( el : HTMLElement , options : Partial < CarouselOptions > ) {
9696 super ( el , options , Carousel ) ;
@@ -152,7 +152,7 @@ export class Carousel extends Component<CarouselOptions> {
152152 // Setup cross browser string
153153 this . xform = 'transform' ;
154154 [ 'webkit' , 'Moz' , 'O' , 'ms' ] . every ( ( prefix ) => {
155- var e = prefix + 'Transform' ;
155+ const e = prefix + 'Transform' ;
156156 if ( typeof document . body . style [ e ] !== 'undefined' ) {
157157 this . xform = e ;
158158 return false ;
@@ -446,13 +446,16 @@ export class Carousel extends Component<CarouselOptions> {
446446 }
447447
448448 _track = ( ) => {
449- let now : number , elapsed : number , delta : number , v : number ;
450- now = Date . now ( ) ;
451- elapsed = now - this . timestamp ;
449+ const now : number = Date . now ( ) ,
450+ elapsed : number = now - this . timestamp ,
451+ delta : number = this . offset - this . frame ,
452+ v : number = ( 1000 * delta ) / ( 1 + elapsed ) ;
453+ // now = Date.now();
454+ // elapsed = now - this.timestamp;
452455 this . timestamp = now ;
453- delta = this . offset - this . frame ;
456+ // delta = this.offset - this.frame;
454457 this . frame = this . offset ;
455- v = ( 1000 * delta ) / ( 1 + elapsed ) ;
458+ // v = (1000 * delta) / (1 + elapsed);
456459 this . velocity = 0.8 * v + 0.2 * this . velocity ;
457460 }
458461
@@ -476,33 +479,33 @@ export class Carousel extends Component<CarouselOptions> {
476479 this . el . classList . add ( 'scrolling' ) ;
477480 }
478481 if ( this . scrollingTimeout != null ) {
479- window . clearTimeout ( this . scrollingTimeout ) ;
482+ clearTimeout ( this . scrollingTimeout ) ;
480483 }
481- this . scrollingTimeout = window . setTimeout ( ( ) => {
484+ this . scrollingTimeout = setTimeout ( ( ) => {
482485 this . el . classList . remove ( 'scrolling' ) ;
483486 } , this . options . duration ) ;
484487
485488 // Start actual scroll
489+ this . offset = typeof x === 'number' ? x : this . offset ;
490+ this . center = Math . floor ( ( this . offset + this . dim / 2 ) / this . dim ) ;
491+
492+ const half : number = this . count >> 1 ,
493+ delta : number = this . offset - this . center * this . dim ,
494+ dir : number = delta < 0 ? 1 : - 1 ,
495+ tween : number = ( - dir * delta * 2 ) / this . dim ;
486496 let i : number ,
487- half : number ,
488- delta : number ,
489- dir : number ,
490- tween : number ,
491497 el : HTMLElement ,
492498 alignment : string ,
493499 zTranslation : number ,
494500 tweenedOpacity : number ,
495501 centerTweenedOpacity : number ;
496- let lastCenter = this . center ;
497- let numVisibleOffset = 1 / this . options . numVisible ;
498-
499- this . offset = typeof x === 'number' ? x : this . offset ;
500- this . center = Math . floor ( ( this . offset + this . dim / 2 ) / this . dim ) ;
502+ const lastCenter = this . center ;
503+ const numVisibleOffset = 1 / this . options . numVisible ;
501504
502- delta = this . offset - this . center * this . dim ;
503- dir = delta < 0 ? 1 : - 1 ;
504- tween = ( - dir * delta * 2 ) / this . dim ;
505- half = this . count >> 1 ;
505+ // delta = this.offset - this.center * this.dim;
506+ // dir = delta < 0 ? 1 : -1;
507+ // tween = (-dir * delta * 2) / this.dim;
508+ // half = this.count >> 1;
506509
507510 if ( this . options . fullWidth ) {
508511 alignment = 'translateX(0)' ;
@@ -537,7 +540,7 @@ export class Carousel extends Component<CarouselOptions> {
537540 el . classList . add ( 'active' ) ;
538541 }
539542
540- let transformString = `${ alignment } translateX(${ - delta / 2 } px) translateX(${ dir *
543+ const transformString = `${ alignment } translateX(${ - delta / 2 } px) translateX(${ dir *
541544 this . options . shift *
542545 tween *
543546 i } px) translateZ(${ this . options . dist * tween } px)`;
@@ -556,7 +559,7 @@ export class Carousel extends Component<CarouselOptions> {
556559 // Don't show wrapped items.
557560 if ( ! this . noWrap || this . center + i < this . count ) {
558561 el = this . images [ this . _wrap ( this . center + i ) ] ;
559- let transformString = `${ alignment } translateX(${ this . options . shift +
562+ const transformString = `${ alignment } translateX(${ this . options . shift +
560563 ( this . dim * i - delta ) / 2 } px) translateZ(${ zTranslation } px)`;
561564 this . _updateItemStyle ( el , tweenedOpacity , - i , transformString ) ;
562565 }
@@ -571,7 +574,7 @@ export class Carousel extends Component<CarouselOptions> {
571574 // Don't show wrapped items.
572575 if ( ! this . noWrap || this . center - i >= 0 ) {
573576 el = this . images [ this . _wrap ( this . center - i ) ] ;
574- let transformString = `${ alignment } translateX(${ - this . options . shift +
577+ const transformString = `${ alignment } translateX(${ - this . options . shift +
575578 ( - this . dim * i - delta ) / 2 } px) translateZ(${ zTranslation } px)`;
576579 this . _updateItemStyle ( el , tweenedOpacity , - i , transformString ) ;
577580 }
@@ -580,7 +583,7 @@ export class Carousel extends Component<CarouselOptions> {
580583 // Don't show wrapped items.
581584 if ( ! this . noWrap || ( this . center >= 0 && this . center < this . count ) ) {
582585 el = this . images [ this . _wrap ( this . center ) ] ;
583- let transformString = `${ alignment } translateX(${ - delta / 2 } px) translateX(${ dir *
586+ const transformString = `${ alignment } translateX(${ - delta / 2 } px) translateX(${ dir *
584587 this . options . shift *
585588 tween } px) translateZ(${ this . options . dist * tween } px)`;
586589 this . _updateItemStyle ( el , centerTweenedOpacity , 0 , transformString ) ;
0 commit comments