swup 3.0.6 → 3.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -35,31 +35,35 @@ export function getAnimationPromises(
35
35
 
36
36
  const animatedElements = queryAll(selector, document.body);
37
37
 
38
- // Warn if no animated containers found on page, but keep things going
38
+ // Warn if no elements match the animationSelector, but keep things going
39
39
  if (!animatedElements.length) {
40
- console.warn(`[swup] No animated elements found by selector ${selector}`);
40
+ console.warn(`[swup] No elements found matching animationSelector \`${selector}\``);
41
41
  return [Promise.resolve()];
42
42
  }
43
43
 
44
- return animatedElements.map((element) => getAnimationPromiseForElement(element, selector));
44
+ const animationPromises = animatedElements
45
+ .map((element) => getAnimationPromiseForElement(element))
46
+ .filter(Boolean) as Promise<void>[];
47
+
48
+ if (!animationPromises.length) {
49
+ console.warn(
50
+ `[swup] No CSS animation duration defined on elements matching \`${selector}\``
51
+ );
52
+ return [Promise.resolve()];
53
+ }
54
+
55
+ return animationPromises;
45
56
  }
46
57
 
47
58
  const isTransitionOrAnimationEvent = (event: any): event is TransitionEvent | AnimationEvent =>
48
- !!event.elapsedTime;
59
+ [transitionEndEvent, animationEndEvent].includes(event.type);
49
60
 
50
- function getAnimationPromiseForElement(
51
- element: Element,
52
- selector: string,
53
- expectedType: 'animation' | 'transition' | null = null
54
- ): Promise<void> {
55
- const { type, timeout, propCount } = getTransitionInfo(element, expectedType);
61
+ function getAnimationPromiseForElement(element: Element): Promise<void> | undefined {
62
+ const { type, timeout, propCount } = getTransitionInfo(element);
56
63
 
57
64
  // Resolve immediately if no transition defined
58
65
  if (!type || !timeout) {
59
- console.warn(
60
- `[swup] No CSS transition duration defined for element of selector ${selector}`
61
- );
62
- return Promise.resolve();
66
+ return undefined;
63
67
  }
64
68
 
65
69
  return new Promise((resolve) => {