import type { OnPageTransitionStartAsync } from "vike/types"; import { getPacmanWindow } from "@/lib/pacman"; import { setPendingNavigation } from "@/lib/navigation"; // Must match --transition-duration in layouts/tailwind.css const TRANSITION_DURATION = 200; export const onPageTransitionStart: OnPageTransitionStartAsync = async (pageContext) => { console.log("Page transition start"); setPendingNavigation(pageContext.urlPathname); document.querySelector("body")?.classList.add("page-is-transitioning"); // Stop the game loop when navigating away from the game page const win = getPacmanWindow(); if (win.Module?._stop_game) { console.log("Stopping game loop for page transition"); win.Module._stop_game(); } // Wait for fade-out animation to complete before page content changes await new Promise((resolve) => setTimeout(resolve, TRANSITION_DURATION)); };