@@ -12,9 +12,11 @@ import { isObject, toNumber, extend, isArray } from '@vue/shared'
12
12
const TRANSITION = 'transition'
13
13
const ANIMATION = 'animation'
14
14
15
+ type AnimationTypes = typeof TRANSITION | typeof ANIMATION
16
+
15
17
export interface TransitionProps extends BaseTransitionProps < Element > {
16
18
name ?: string
17
- type ?: typeof TRANSITION | typeof ANIMATION
19
+ type ?: AnimationTypes
18
20
css ?: boolean
19
21
duration ?: number | { enter : number ; leave : number }
20
22
// custom transition classes
@@ -368,24 +370,33 @@ function whenTransitionEnds(
368
370
}
369
371
370
372
interface CSSTransitionInfo {
371
- type : typeof TRANSITION | typeof ANIMATION | null
373
+ type : AnimationTypes | null
372
374
propCount : number
373
375
timeout : number
374
376
hasTransform : boolean
375
377
}
376
378
379
+ type AnimationProperties = 'Delay' | 'Duration'
380
+ type StylePropertiesKey =
381
+ | `${AnimationTypes } ${AnimationProperties } `
382
+ | `${typeof TRANSITION } Property`
383
+
377
384
export function getTransitionInfo (
378
385
el : Element ,
379
386
expectedType ?: TransitionProps [ 'type' ]
380
387
) : CSSTransitionInfo {
381
- const styles : any = window . getComputedStyle ( el )
388
+ const styles = window . getComputedStyle ( el ) as Pick <
389
+ CSSStyleDeclaration ,
390
+ StylePropertiesKey
391
+ >
382
392
// JSDOM may return undefined for transition properties
383
- const getStyleProperties = ( key : string ) => ( styles [ key ] || '' ) . split ( ', ' )
384
- const transitionDelays = getStyleProperties ( TRANSITION + 'Delay' )
385
- const transitionDurations = getStyleProperties ( TRANSITION + 'Duration' )
393
+ const getStyleProperties = ( key : StylePropertiesKey ) =>
394
+ ( styles [ key ] || '' ) . split ( ', ' )
395
+ const transitionDelays = getStyleProperties ( `${ TRANSITION } Delay` )
396
+ const transitionDurations = getStyleProperties ( `${ TRANSITION } Duration` )
386
397
const transitionTimeout = getTimeout ( transitionDelays , transitionDurations )
387
- const animationDelays = getStyleProperties ( ANIMATION + ' Delay' )
388
- const animationDurations = getStyleProperties ( ANIMATION + ' Duration' )
398
+ const animationDelays = getStyleProperties ( ` ${ ANIMATION } Delay` )
399
+ const animationDurations = getStyleProperties ( ` ${ ANIMATION } Duration` )
389
400
const animationTimeout = getTimeout ( animationDelays , animationDurations )
390
401
391
402
let type : CSSTransitionInfo [ 'type' ] = null
@@ -420,7 +431,9 @@ export function getTransitionInfo(
420
431
}
421
432
const hasTransform =
422
433
type === TRANSITION &&
423
- / \b ( t r a n s f o r m | a l l ) ( , | $ ) / . test ( styles [ TRANSITION + 'Property' ] )
434
+ / \b ( t r a n s f o r m | a l l ) ( , | $ ) / . test (
435
+ getStyleProperties ( `${ TRANSITION } Property` ) . toString ( )
436
+ )
424
437
return {
425
438
type,
426
439
timeout,
0 commit comments