@@ -10,7 +10,7 @@ export class Animation {
10
10
private _cL : number ;
11
11
private _e : HTMLElement [ ] ;
12
12
private _eL : number ;
13
- private _fx : { [ key : string ] : EffectProperty } ;
13
+ private _fx : EffectProperty [ ] ;
14
14
private _dur : number = null ;
15
15
private _es : string = null ;
16
16
private _bfSty : { [ property : string ] : any ; } ;
@@ -159,26 +159,39 @@ export class Animation {
159
159
* @private
160
160
* NO DOM
161
161
*/
162
+
163
+ private _getProp ( name : string ) : EffectProperty {
164
+ if ( this . _fx ) {
165
+ return this . _fx . find ( ( prop ) => prop . name === name ) ;
166
+ } else {
167
+ this . _fx = [ ] ;
168
+ }
169
+ return null ;
170
+ }
171
+
162
172
private _addProp ( state : string , prop : string , val : any ) : EffectProperty {
163
- this . _fx = this . _fx || { } ;
164
- let fxProp = this . _fx [ prop ] ;
173
+ let fxProp = this . _getProp ( prop ) ;
165
174
166
175
if ( ! fxProp ) {
167
176
// first time we've see this EffectProperty
168
- fxProp = this . _fx [ prop ] = {
169
- trans : ( TRANSFORMS [ prop ] === 1 )
170
- } ;
177
+ var shouldTrans = ( TRANSFORMS [ prop ] === 1 ) ;
178
+ fxProp = {
179
+ name : prop ,
180
+ trans : shouldTrans ,
171
181
172
- // add the will-change property for transforms or opacity
173
- fxProp . wc = ( fxProp . trans ? CSS . transform : prop ) ;
182
+ // add the will-change property for transforms or opacity
183
+ wc : ( shouldTrans ? CSS . transform : prop )
184
+ } ;
185
+ this . _fx . push ( fxProp ) ;
174
186
}
175
187
176
188
// add from/to EffectState to the EffectProperty
177
- let fxState : EffectState = ( < any > fxProp ) [ state ] = {
189
+ let fxState : EffectState = {
178
190
val : val ,
179
191
num : null ,
180
192
unit : '' ,
181
193
} ;
194
+ fxProp [ state ] = fxState ;
182
195
183
196
if ( typeof val === 'string' && val . indexOf ( ' ' ) < 0 ) {
184
197
let r = val . match ( CSS_VALUE_REGEX ) ;
@@ -594,72 +607,72 @@ export class Animation {
594
607
*/
595
608
_progress ( stepValue : number ) {
596
609
// bread 'n butter
597
- var val : any ;
610
+ let val : any ;
611
+ let effects = this . _fx ;
612
+ let nuElements = this . _eL ;
598
613
599
- if ( this . _fx && this . _eL ) {
600
- // flip the number if we're going in reverse
601
- if ( this . _rv ) {
602
- stepValue = ( ( stepValue * - 1 ) + 1 ) ;
603
- }
604
- var transforms : string [ ] = [ ] ;
605
- var effects = this . _fx ;
606
- var elements = this . _e ;
607
- for ( var prop in effects ) {
608
- var fx = effects [ prop ] ;
609
-
610
- if ( fx . from && fx . to ) {
611
- var fromNum = fx . from . num ;
612
- var toNum = fx . to . num ;
613
- var tweenEffect = ( fromNum !== toNum ) ;
614
- if ( tweenEffect ) {
615
- this . _twn = true ;
616
- }
614
+ if ( ! effects || ! nuElements ) {
615
+ return ;
616
+ }
617
617
618
- if ( stepValue === 0 ) {
619
- // FROM
620
- val = fx . from . val ;
618
+ // flip the number if we're going in reverse
619
+ if ( this . _rv ) {
620
+ stepValue = ( ( stepValue * - 1 ) + 1 ) ;
621
+ }
622
+ var i , j ;
623
+ var finalTransform : string = '' ;
624
+ var elements = this . _e ;
625
+ for ( i = 0 ; i < effects . length ; i ++ ) {
626
+ var fx = effects [ i ] ;
627
+
628
+ if ( fx . from && fx . to ) {
629
+ var fromNum = fx . from . num ;
630
+ var toNum = fx . to . num ;
631
+ var tweenEffect = ( fromNum !== toNum ) ;
632
+ if ( tweenEffect ) {
633
+ this . _twn = true ;
634
+ }
621
635
622
- } else if ( stepValue === 1 ) {
623
- // TO
624
- val = fx . to . val ;
636
+ if ( stepValue === 0 ) {
637
+ // FROM
638
+ val = fx . from . val ;
625
639
626
- } else if ( tweenEffect ) {
627
- // EVERYTHING IN BETWEEN
628
- val = ( ( ( toNum - fromNum ) * stepValue ) + fromNum ) + fx . to . unit ;
640
+ } else if ( stepValue === 1 ) {
641
+ // TO
642
+ val = fx . to . val ;
629
643
630
- } else {
631
- val = null ;
632
- }
644
+ } else if ( tweenEffect ) {
645
+ // EVERYTHING IN BETWEEN
646
+ val = ( ( ( toNum - fromNum ) * stepValue ) + fromNum ) + fx . to . unit ;
647
+ }
633
648
634
- if ( val !== null ) {
635
- if ( fx . trans ) {
636
- transforms . push ( prop + '(' + val + ')' ) ;
649
+ if ( val !== null ) {
650
+ var prop = fx . name ;
651
+ if ( fx . trans ) {
652
+ finalTransform += prop + '(' + val + ') ' ;
637
653
638
- } else {
639
- for ( var i = 0 ; i < this . _eL ; i ++ ) {
640
- // ******** DOM WRITE ****************
641
- elements [ i ] . style [ prop ] = val ;
642
- }
654
+ } else {
655
+ for ( j = 0 ; j < nuElements ; j ++ ) {
656
+ // ******** DOM WRITE ****************
657
+ elements [ j ] . style [ prop ] = val ;
643
658
}
644
659
}
645
660
}
646
661
}
662
+ }
647
663
648
- // place all transforms on the same property
649
- if ( transforms . length ) {
650
- if ( ! this . _rv && stepValue !== 1 || this . _rv && stepValue !== 0 ) {
651
- transforms . push ( 'translateZ(0px)' ) ;
652
- }
664
+ // place all transforms on the same property
665
+ if ( finalTransform . length ) {
666
+ if ( ! this . _rv && stepValue !== 1 || this . _rv && stepValue !== 0 ) {
667
+ finalTransform += 'translateZ(0px)' ;
668
+ }
653
669
654
- var transformString = transforms . join ( ' ' ) ;
655
- var cssTransform = CSS . transform ;
656
- for ( var i = 0 ; i < this . _eL ; i ++ ) {
657
- // ******** DOM WRITE ****************
658
- elements [ i ] . style [ cssTransform ] = transformString ;
659
- }
670
+ var cssTransform = CSS . transform ;
671
+ for ( i = 0 ; i < elements . length ; i ++ ) {
672
+ // ******** DOM WRITE ****************
673
+ elements [ i ] . style [ cssTransform ] = finalTransform ;
660
674
}
661
675
}
662
-
663
676
}
664
677
665
678
/**
@@ -900,15 +913,16 @@ export class Animation {
900
913
*/
901
914
_willChg ( addWillChange : boolean ) {
902
915
let wc : string [ ] ;
903
-
904
- if ( addWillChange ) {
916
+ var effects = this . _fx ;
917
+ if ( addWillChange && effects ) {
905
918
wc = [ ] ;
906
- for ( var prop in this . _fx ) {
907
- if ( this . _fx [ prop ] . wc === 'webkitTransform' ) {
919
+ for ( var i = 0 ; i < effects . length ; i ++ ) {
920
+ var propWC = effects [ i ] . wc ;
921
+ if ( propWC === 'webkitTransform' ) {
908
922
wc . push ( 'transform' , '-webkit-transform' ) ;
909
923
910
924
} else {
911
- wc . push ( this . _fx [ prop ] . wc ) ;
925
+ wc . push ( propWC ) ;
912
926
}
913
927
}
914
928
}
@@ -1164,6 +1178,7 @@ export interface PlayOptions {
1164
1178
}
1165
1179
1166
1180
export interface EffectProperty {
1181
+ name : string ;
1167
1182
trans : boolean ;
1168
1183
wc ?: string ;
1169
1184
to ?: EffectState ;
0 commit comments