@@ -45,8 +45,12 @@ export function removeTransitionClass (el: any, cls: string) {
45
45
removeClass ( el , cls )
46
46
}
47
47
48
- export function whenTransitionEnds ( el : Element , cb : Function ) {
49
- const { type, timeout, propCount } = getTransitionInfo ( el )
48
+ export function whenTransitionEnds (
49
+ el : Element ,
50
+ expectedType : ?stirng ,
51
+ cb : Function
52
+ ) {
53
+ const { type, timeout, propCount } = getTransitionInfo ( el , expectedType )
50
54
if ( ! type ) return cb ( )
51
55
const event = type === TRANSITION ? transitionEndEvent : animationEndEvent
52
56
let ended = 0
@@ -69,34 +73,56 @@ export function whenTransitionEnds (el: Element, cb: Function) {
69
73
70
74
const transformRE = / \b ( t r a n s f o r m | a l l ) ( , | $ ) /
71
75
72
- export function getTransitionInfo ( el : Element ) : {
73
- type: ?string ,
74
- propCount : number ,
75
- timeout : number
76
+ export function getTransitionInfo ( el : Element , expectedType ?: ? string ) : {
77
+ type : ?string ;
78
+ propCount : number ;
79
+ timeout : number ;
76
80
} {
77
81
const styles = window . getComputedStyle ( el )
78
- const transitionProps = styles [ transitionProp + 'Property' ]
79
82
const transitioneDelays = styles [ transitionProp + 'Delay' ] . split ( ', ' )
80
83
const transitionDurations = styles [ transitionProp + 'Duration' ] . split ( ', ' )
84
+ const transitionTimeout = getTimeout ( transitioneDelays , transitionDurations )
81
85
const animationDelays = styles [ animationProp + 'Delay' ] . split ( ', ' )
82
86
const animationDurations = styles [ animationProp + 'Duration' ] . split ( ', ' )
83
- const transitionTimeout = getTimeout ( transitioneDelays , transitionDurations )
84
87
const animationTimeout = getTimeout ( animationDelays , animationDurations )
85
- const timeout = Math . max ( transitionTimeout , animationTimeout )
86
- const type = timeout > 0
87
- ? transitionTimeout > animationTimeout
88
- ? TRANSITION
89
- : ANIMATION
90
- : null
91
- return {
92
- type,
93
- timeout,
94
- propCount : type
88
+
89
+ let type
90
+ let timeout = 0
91
+ let propCount = 0
92
+ /* istanbul ignore if */
93
+ if ( expectedType === TRANSITION ) {
94
+ if ( transitionTimeout > 0 ) {
95
+ type = TRANSITION
96
+ timeout = transitionTimeout
97
+ propCount = transitionDurations . length
98
+ }
99
+ } else if ( expectedType === ANIMATION ) {
100
+ if ( animationTimeout > 0 ) {
101
+ type = ANIMATION
102
+ timeout = animationTimeout
103
+ propCount = animationDurations . length
104
+ }
105
+ } else {
106
+ timeout = Math . max ( transitionTimeout , animationTimeout )
107
+ type = timeout > 0
108
+ ? transitionTimeout > animationTimeout
109
+ ? TRANSITION
110
+ : ANIMATION
111
+ : null
112
+ propCount = type
95
113
? type === TRANSITION
96
114
? transitionDurations . length
97
115
: animationDurations . length
98
- : 0 ,
99
- hasTransform : type === TRANSITION && transformRE . test ( transitionProps )
116
+ : 0
117
+ }
118
+ const hasTransform =
119
+ type === TRANSITION &&
120
+ transformRE . test ( styles [ transitionProp + 'Property' ] )
121
+ return {
122
+ type,
123
+ timeout,
124
+ propCount,
125
+ hasTransform
100
126
}
101
127
}
102
128
0 commit comments