( el: Element, expectedType?: TransitionProps['type'], )
| 399 | | `${typeof TRANSITION}Property` |
| 400 | |
| 401 | export function getTransitionInfo( |
| 402 | el: Element, |
| 403 | expectedType?: TransitionProps['type'], |
| 404 | ): CSSTransitionInfo { |
| 405 | const styles = window.getComputedStyle(el) as Pick< |
| 406 | CSSStyleDeclaration, |
| 407 | StylePropertiesKey |
| 408 | > |
| 409 | // JSDOM may return undefined for transition properties |
| 410 | const getStyleProperties = (key: StylePropertiesKey) => |
| 411 | (styles[key] || '').split(', ') |
| 412 | const transitionDelays = getStyleProperties(`${TRANSITION}Delay`) |
| 413 | const transitionDurations = getStyleProperties(`${TRANSITION}Duration`) |
| 414 | const transitionTimeout = getTimeout(transitionDelays, transitionDurations) |
| 415 | const animationDelays = getStyleProperties(`${ANIMATION}Delay`) |
| 416 | const animationDurations = getStyleProperties(`${ANIMATION}Duration`) |
| 417 | const animationTimeout = getTimeout(animationDelays, animationDurations) |
| 418 | |
| 419 | let type: CSSTransitionInfo['type'] = null |
| 420 | let timeout = 0 |
| 421 | let propCount = 0 |
| 422 | if (expectedType === TRANSITION) { |
| 423 | if (transitionTimeout > 0) { |
| 424 | type = TRANSITION |
| 425 | timeout = transitionTimeout |
| 426 | propCount = transitionDurations.length |
| 427 | } |
| 428 | } else if (expectedType === ANIMATION) { |
| 429 | if (animationTimeout > 0) { |
| 430 | type = ANIMATION |
| 431 | timeout = animationTimeout |
| 432 | propCount = animationDurations.length |
| 433 | } |
| 434 | } else { |
| 435 | timeout = Math.max(transitionTimeout, animationTimeout) |
| 436 | type = |
| 437 | timeout > 0 |
| 438 | ? transitionTimeout > animationTimeout |
| 439 | ? TRANSITION |
| 440 | : ANIMATION |
| 441 | : null |
| 442 | propCount = type |
| 443 | ? type === TRANSITION |
| 444 | ? transitionDurations.length |
| 445 | : animationDurations.length |
| 446 | : 0 |
| 447 | } |
| 448 | const hasTransform = |
| 449 | type === TRANSITION && |
| 450 | /\b(?:transform|all)(?:,|$)/.test( |
| 451 | getStyleProperties(`${TRANSITION}Property`).toString(), |
| 452 | ) |
| 453 | return { |
| 454 | type, |
| 455 | timeout, |
| 456 | propCount, |
| 457 | hasTransform, |
| 458 | } |
no test coverage detected