MCPcopy Create free account
hub / github.com/angular/angular / isLongestAnimation

Function isLongestAnimation

packages/core/src/animation/utils.ts:354–398  ·  view source on GitHub ↗
(
  event: AnimationEvent | TransitionEvent,
  nativeElement: HTMLElement,
)

Source from the content-addressed store, hash-verified

352 * @returns
353 */
354export function isLongestAnimation(
355 event: AnimationEvent | TransitionEvent,
356 nativeElement: HTMLElement,
357): boolean {
358 const longestAnimation = longestAnimations.get(nativeElement);
359 // If we don't have any record of a longest animation, then we shouldn't
360 // block the animationend/transitionend event from doing its work.
361 if (longestAnimation === undefined) return true;
362
363 if (nativeElement !== getEventTarget(event)) return false;
364
365 // Distinct CSS animations can share a name. Chrome 151 stable exposes their instance:
366 // https://developer.chrome.com/release-notes/151#animation_accessor_on_animation_and_transition_events
367 const eventAnimation = (
368 event as (AnimationEvent | TransitionEvent) & {readonly animation?: Animation | null}
369 ).animation;
370
371 // Compare the event animation's duration instead of retaining the Animation object. This also
372 // disambiguates records obtained from computed styles when getAnimations() was empty.
373 if (eventAnimation) {
374 const eventAnimationDuration = getAnimationDuration(eventAnimation);
375 // CSSOM can round serialized times while Web Animations retains more precision. Only reject an
376 // event when it is shorter by more than the tolerance so the longest event is not ignored.
377 if (
378 eventAnimationDuration !== undefined &&
379 eventAnimationDuration + ANIMATION_DURATION_TOLERANCE_MS < longestAnimation.duration
380 ) {
381 return false;
382 }
383 }
384
385 // Fall back to strings for older browsers.
386 if (longestAnimation.animationName !== undefined) {
387 return (event as AnimationEvent).animationName === longestAnimation.animationName;
388 }
389
390 if (longestAnimation.propertyName !== undefined) {
391 return (
392 longestAnimation.propertyName === 'all' ||
393 (event as TransitionEvent).propertyName === longestAnimation.propertyName
394 );
395 }
396
397 return false;
398}
399
400/**
401 * Stores a given animation function in the LView's animation map for later execution

Callers 4

handleEnterAnimationEndFunction · 0.90
enterAnimationEndFunction · 0.90
handleOutAnimationEndFunction · 0.90

Calls 3

getAnimationDurationFunction · 0.90
getEventTargetFunction · 0.85
getMethod · 0.65

Tested by

no test coverage detected