Skip to content

Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.

1.1 KB
Raw Blame
/**
 * Wait for real browser animations before visual assertions; visible elements can still be mid-transition and yield
 * false contrast failures.
 */

/**
 * Skip infinite iterations/duration, paused animations, and zero playback rate; each can leave finished pending
 * forever.
 */
const willFinish = (animation: Animation): boolean => {
  const timing = animation.effect?.getComputedTiming();
  const duration = typeof timing?.duration === 'number' ? timing.duration : 0;

  return (
    timing?.iterations !== Infinity &&
    Number.isFinite(duration) &&
    animation.playbackRate !== 0 &&
    animation.playState !== 'paused'
  );
};

/**
 * Settle the whole document by default, including sibling backdrops and portals. Ignore nonterminating animations; use
 * allSettled because removal cancels CSS animations and rejects finished.
 */
export const settleAnimations = async (root: Document | Element = document): Promise<void> => {
  await Promise.allSettled(
    root
      .getAnimations({ subtree: true })
      .filter(willFinish)
      .map((animation) => animation.finished)
  );
};