Branchwell

AI Resource Pro / website · airesourcepro.com / src / components / home / home-motion.tsx

1"use client";
2
3import { useEffect, useRef } from "react";
4
5// The home page's moving parts: the WebGL particle field, smooth scroll, reveals, the custom cursor and
6// the section dots. The libraries load after the page renders so the copy is readable without them.
7export function HomeMotion({ sections }: { sections: string[] }) {
8 const canvasRef = useRef<HTMLCanvasElement>(null);
9
10 useEffect(() => {
11 let cancelled = false;
12 let stop: (() => void) | null = null;
13
14 (async () => {
15 const root = document.querySelector<HTMLElement>(".xp");
16 try {
17 const [{ gsap }, { ScrollTrigger }, { default: Lenis }, { startMotion }] = await Promise.all([
18 import("gsap"),
19 import("gsap/ScrollTrigger"),
20 import("lenis"),
21 import("./start-motion"),
22 ]);
23 if (cancelled || !root) return;
24 const motion = startMotion(root, { gsap, ScrollTrigger, Lenis });
25 stop = motion.stop;
26
27 // The glyph shapes are drawn in Geist Mono, so build the field once fonts are in
28 const [{ createParticleField }] = await Promise.all([
29 import("./particle-field"),
30 Promise.race([document.fonts?.ready, new Promise((r) => setTimeout(r, 1500))]),
31 ]);
32 if (cancelled || !canvasRef.current) return;
33 const mono = getComputedStyle(document.documentElement).getPropertyValue("--font-mono").trim() || "monospace";
34 motion.setField(createParticleField(canvasRef.current, mono));
35 } catch (e) {
36 console.error("Home page motion failed to start:", e);
37 root?.classList.remove("xp-wait");
38 }
39 })();
40
41 return () => {
42 cancelled = true;
43 stop?.();
44 };
45 }, []);
46
47 return (
48 <>
49 <canvas ref={canvasRef} className="xp-gl" aria-hidden />
50 <div className="xp-cur" aria-hidden>
51 <div className="c-ring" />
52 <div className="c-dot" />
53 </div>
54 <nav className="xp-dots" aria-label="Sections">
55 {sections.map((label, i) => (
56 <button key={label} type="button" data-go={i}>
57 <span>{label}</span>
58 <i />
59 </button>
60 ))}
61 </nav>
62 </>
63 );
64}