animatePopup = (instance, popup, container, returnFocus, didClose) => {
  globalState.swalCloseEventFinishedCallback = removePopupAndResetState.bind(
    null,
    instance,
    container,
    returnFocus,
    didClose
  )
  /**
   * @param {AnimationEvent | TransitionEvent} e
   */
  const swalCloseAnimationFinished = function (e) {
    if (e.target === popup) {
      globalState.swalCloseEventFinishedCallback?.()
      delete globalState.swalCloseEventFinishedCallback
      popup.removeEventListener('animationend', swalCloseAnimationFinished)
      popup.removeEventListener('transitionend', swalCloseAnimationFinished)
    }
  }
  popup.addEventListener('animationend', swalCloseAnimationFinished)
  popup.addEventListener('transitionend', swalCloseAnimationFinished)
}
@param {SweetAlert} instance
@param {HTMLElement} popup
@param {HTMLElement} container
@param {boolean} returnFocus
@param {Function} didClose