fix(ui): restore tool links and reduce animation overhead
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
'use client';
|
||||
|
||||
import React, { useRef, useState, useCallback } from 'react';
|
||||
import React, { useRef, useCallback } from 'react';
|
||||
|
||||
interface Kinetic3DTextProps {
|
||||
primaryText: string;
|
||||
@@ -15,23 +15,22 @@ export function Kinetic3DText({
|
||||
subtitle,
|
||||
className = '',
|
||||
}: Kinetic3DTextProps) {
|
||||
const [tilt, setTilt] = useState({ rx: 0, ry: 0, active: false });
|
||||
const containerRef = useRef<HTMLDivElement>(null);
|
||||
const textRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
const handleMouseMove = useCallback((e: React.MouseEvent<HTMLDivElement>) => {
|
||||
if (!containerRef.current) return;
|
||||
const rect = containerRef.current.getBoundingClientRect();
|
||||
const nx = (e.clientX - rect.left) / rect.width - 0.5;
|
||||
const ny = (e.clientY - rect.top) / rect.height - 0.5;
|
||||
setTilt({
|
||||
rx: Math.max(Math.min(-ny * 10, 8), -8),
|
||||
ry: Math.max(Math.min(nx * 12, 10), -10),
|
||||
active: true,
|
||||
});
|
||||
if (!textRef.current || window.matchMedia('(prefers-reduced-motion: reduce)').matches) return;
|
||||
const rx = Math.max(Math.min(-ny * 3, 2.5), -2.5);
|
||||
const ry = Math.max(Math.min(nx * 4, 3), -3);
|
||||
textRef.current.style.transform = `perspective(1000px) rotateX(${rx}deg) rotateY(${ry}deg)`;
|
||||
}, []);
|
||||
|
||||
const handleMouseLeave = useCallback(() => {
|
||||
setTilt({ rx: 0, ry: 0, active: false });
|
||||
if (textRef.current) textRef.current.style.transform = 'perspective(1000px) rotateX(0deg) rotateY(0deg)';
|
||||
}, []);
|
||||
|
||||
return (
|
||||
@@ -40,16 +39,11 @@ export function Kinetic3DText({
|
||||
onMouseMove={handleMouseMove}
|
||||
onMouseLeave={handleMouseLeave}
|
||||
className={`relative select-none ${className}`}
|
||||
style={{ perspective: 1000 }}
|
||||
>
|
||||
<div
|
||||
className="transition-transform duration-200 ease-out"
|
||||
style={{
|
||||
transform: tilt.active
|
||||
? `rotateX(${tilt.rx.toFixed(2)}deg) rotateY(${tilt.ry.toFixed(2)}deg)`
|
||||
: 'rotateX(0deg) rotateY(0deg)',
|
||||
transformStyle: 'preserve-3d',
|
||||
}}
|
||||
ref={textRef}
|
||||
className="transition-transform duration-300 ease-out will-change-transform"
|
||||
style={{ transform: 'perspective(1000px) rotateX(0deg) rotateY(0deg)', transformStyle: 'preserve-3d' }}
|
||||
>
|
||||
{/* Main Floating Headline (100% Visible, Crisp, Zero Disappearance) */}
|
||||
<h1 className="text-4xl sm:text-5xl lg:text-6xl xl:text-7xl font-display font-black text-slate-900 tracking-tight leading-[1.08] relative z-10">
|
||||
|
||||
@@ -9,10 +9,10 @@ export function SectionEntrance({ children, id }: { children: React.ReactNode; i
|
||||
return (
|
||||
<motion.div
|
||||
data-section-entrance={id}
|
||||
initial={reduceMotion ? false : { opacity: 0, y: 22, filter: 'blur(5px)' }}
|
||||
whileInView={{ opacity: 1, y: 0, filter: 'blur(0px)' }}
|
||||
viewport={{ once: true, amount: 0.12, margin: '0px 0px -48px 0px' }}
|
||||
transition={{ duration: 0.65, ease: [0.22, 1, 0.36, 1] }}
|
||||
initial={reduceMotion ? false : { opacity: 0, y: 14 }}
|
||||
whileInView={{ opacity: 1, y: 0 }}
|
||||
viewport={{ once: true, amount: 0.08, margin: '0px 0px -24px 0px' }}
|
||||
transition={{ duration: 0.42, ease: [0.22, 1, 0.36, 1] }}
|
||||
>
|
||||
{children}
|
||||
</motion.div>
|
||||
|
||||
@@ -1,58 +1,6 @@
|
||||
'use client';
|
||||
|
||||
import { useEffect } from 'react';
|
||||
import Lenis from 'lenis';
|
||||
|
||||
/** Keep native browser scrolling: it is interruptible, accessible, and avoids a permanent RAF loop. */
|
||||
export function SmoothScroll() {
|
||||
useEffect(() => {
|
||||
// Check prefers-reduced-motion
|
||||
if (window.matchMedia('(prefers-reduced-motion: reduce)').matches) return;
|
||||
|
||||
const lenis = new Lenis({
|
||||
duration: 0.75, // Extra smooth, luxurious gliding friction
|
||||
easing: (t) => Math.min(1, 1.001 - Math.pow(2, -10 * t)),
|
||||
orientation: 'vertical',
|
||||
gestureOrientation: 'vertical',
|
||||
smoothWheel: true,
|
||||
syncTouch: false,
|
||||
wheelMultiplier: 1.05,
|
||||
touchMultiplier: 1.0,
|
||||
});
|
||||
|
||||
let rafId: number;
|
||||
function raf(time: number) {
|
||||
lenis.raf(time);
|
||||
rafId = requestAnimationFrame(raf);
|
||||
}
|
||||
|
||||
rafId = requestAnimationFrame(raf);
|
||||
|
||||
// Smooth scroll for anchor clicks (e.g. #studio-suite, #flagship-models)
|
||||
const handleAnchorClick = (e: MouseEvent) => {
|
||||
const target = e.target as HTMLElement;
|
||||
const anchor = target.closest('a');
|
||||
if (!anchor) return;
|
||||
const href = anchor.getAttribute('href');
|
||||
if (href && href.startsWith('#') && href.length > 1) {
|
||||
const targetEl = document.querySelector(href);
|
||||
if (targetEl) {
|
||||
e.preventDefault();
|
||||
lenis.scrollTo(targetEl as HTMLElement, { offset: -90, duration: 0.75 });
|
||||
}
|
||||
}
|
||||
};
|
||||
document.addEventListener('click', handleAnchorClick);
|
||||
|
||||
// Expose lenis to window for external triggers
|
||||
(window as any).lenis = lenis;
|
||||
|
||||
return () => {
|
||||
cancelAnimationFrame(rafId);
|
||||
document.removeEventListener('click', handleAnchorClick);
|
||||
lenis.destroy();
|
||||
delete (window as any).lenis;
|
||||
};
|
||||
}, []);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user