"use client"; /** * RouteTransitionOverlay — 1:1 port of the original orchestrator (chunk * 3c6cc5b2fcccdee5.js `function M`, module 34841), simplified to the pixel * wipe without the WebGL mask material: * * startNavigation(href) * → phase "cover" : b1-colored fixed layer wipes IN over the page * (0.8s, cubic-bezier(0.66, 0, 0.01, 1)); on complete → router.push * (or replace) to the target href. * → phase "wait" : new page mounts; heavy assets may still load. * → phase "reveal" : layer wipes OUT (same easing), then → idle and * the overlay unmounts; scramble lines re-enabled 100ms in. * * The b1 background matches the page body so the wipe reads as the page * turning into a blank sheet — the original achieves the same look via the * WebGL mask + grid colors. */ import { useEffect, useMemo, useRef, useState } from "react"; import { usePathname, useRouter } from "next/navigation"; import { useRouteTransitionController } from "@/lib/routeTransition"; type Phase = "wait" | "cover" | "reveal"; type Mode = "idle" | "entry" | "route"; const DURATION_MS = 800; const EASING = "cubic-bezier(0.66, 0, 0.01, 1)"; const BG = "var(--color-b1)"; export default function RouteTransitionOverlay() { const router = useRouter(); const pathname = usePathname(); const { targetHref, navigationReplace, clearNavigation, setAllowScrambleLines } = useRouteTransitionController(); const routeFrom = useRef<{ path: string | null; coverDone: boolean }>({ path: null, coverDone: false, }); const [mode, setMode] = useState("idle"); const [phase, setPhase] = useState("wait"); const navigateRef = useRef<() => void>(() => {}); navigateRef.current = () => { if (mode === "route" && phase === "cover") { routeFrom.current.coverDone = true; setAllowScrambleLines(false); if (targetHref) { if (navigationReplace) router.replace(targetHref); else router.push(targetHref); } setPhase("wait"); } }; const targetPath = useMemo(() => { if (!targetHref) return null; if (targetHref.startsWith("/")) { const [p] = targetHref.split("?"); return p || "/"; } try { return new URL(targetHref, window.location.origin).pathname || "/"; } catch { return null; } }, [targetHref]); // Intent → start cover. useEffect(() => { if (targetHref && mode === "idle") { routeFrom.current.path = pathname; routeFrom.current.coverDone = false; setMode("route"); setPhase("cover"); } }, [targetHref, mode, pathname]); // New page mounted → reveal. useEffect(() => { if ( mode === "route" && phase === "wait" && routeFrom.current.coverDone && routeFrom.current.path && pathname !== routeFrom.current.path ) { setPhase("reveal"); } }, [mode, phase, pathname]); // Reveal finished → idle. const onRevealComplete = () => { if (mode !== "idle" && phase === "reveal") { setMode("idle"); clearNavigation(); routeFrom.current.path = null; routeFrom.current.coverDone = false; } }; // Scramble lines gate (original: idle → true immediately; 100ms after // a reveal starts). useEffect(() => { if (mode === "idle") { setAllowScrambleLines(true); return; } if (phase !== "reveal") return; const t = window.setTimeout(() => setAllowScrambleLines(true), 100); return () => window.clearTimeout(t); }, [mode, phase, setAllowScrambleLines]); const overlayVisible = mode !== "idle" && phase !== "wait"; const wipeIn = phase === "cover"; return (
{ if (e.animationName !== "route-wipe") return; if (wipeIn) navigateRef.current(); else onRevealComplete(); }} > {/* 16px checker texture (original pixelSize:16 maskCells) */}
); }