summaryrefslogtreecommitdiff
path: root/node_modules/swup/src/modules/animatePageIn.ts
blob: fc384b73f8030a0242bbfbcb78d4449c1acafbd8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import type Swup from '../Swup.js';
import { nextTick } from '../utils.js';
import type { Visit } from './Visit.js';

/**
 * Perform the in/enter animation of the next page.
 * @returns Promise<void>
 */
export const animatePageIn = async function (this: Swup, visit: Visit) {
	// Check if failed/aborted in the meantime
	if (visit.done) return;

	const animation = this.hooks.call(
		'animation:in:await',
		visit,
		{ skip: false },
		(visit, { skip }) => {
			if (skip) return;
			return this.awaitAnimations({ selector: visit.animation.selector });
		}
	);

	await nextTick();

	await this.hooks.call('animation:in:start', visit, undefined, () => {
		this.classes.remove('is-animating');
	});

	await animation;

	await this.hooks.call('animation:in:end', visit, undefined);
};