feat(3d): complete site-wide autonomous and interactive 3d cinematic typography overhaul

This commit is contained in:
2026-11-03 17:08:23 +05:30
parent c764ffca14
commit 6cba2256b4
14 changed files with 340 additions and 72 deletions
+58 -29
View File
@@ -1,6 +1,6 @@
'use client';
import React, { useState, useRef, useEffect } from 'react';
import React, { useRef, useEffect } from 'react';
interface Kinetic3DTextProps {
primaryText: string;
@@ -15,37 +15,64 @@ export function Kinetic3DText({
subtitle,
className = '',
}: Kinetic3DTextProps) {
const [tilt, setTilt] = useState({ rx: 0, ry: 0, active: false });
const containerRef = useRef<HTMLDivElement>(null);
const headlineRef = useRef<HTMLHeadingElement>(null);
const shadowRef = useRef<HTMLDivElement>(null);
const subtitleRef = useRef<HTMLParagraphElement>(null);
useEffect(() => {
// Check prefers-reduced-motion
if (window.matchMedia('(prefers-reduced-motion: reduce)').matches) return;
let rafId: number;
let targetRx = 0;
let targetRy = 0;
let currentRx = 0;
let currentRy = 0;
let clock = 0;
const handleMouseMove = (e: MouseEvent) => {
if (!containerRef.current) return;
const rect = containerRef.current.getBoundingClientRect();
const centerX = rect.left + rect.width / 2;
const centerY = rect.top + rect.height / 2;
const vw = window.innerWidth;
const vh = window.innerHeight;
// Normalized coordinates -1 to +1 centered on screen
const nx = (e.clientX / vw) * 2 - 1;
const ny = (e.clientY / vh) * 2 - 1;
// Normalized coordinates -1 to +1
const nx = (e.clientX - centerX) / (window.innerWidth * 0.5);
const ny = (e.clientY - centerY) / (window.innerHeight * 0.5);
targetRy = Math.max(Math.min(nx * 10, 12), -12);
targetRx = Math.max(Math.min(-ny * 8, 10), -10);
targetRy = nx * 14; // Horizontal tilt up to 14 deg
targetRx = -ny * 12; // Vertical tilt up to 12 deg
};
const updateLoop = () => {
// Smooth inertial lerp
currentRx += (targetRx - currentRx) * 0.1;
currentRy += (targetRy - currentRy) * 0.1;
clock += 0.025;
// Inertial damping lerp for mouse response
currentRx += (targetRx - currentRx) * 0.085;
currentRy += (targetRy - currentRy) * 0.085;
// Autonomous continuous 3D breathing wave (always alive)
const waveRx = Math.sin(clock * 1.4) * 3.5;
const waveRy = Math.cos(clock * 1.1) * 4.2;
const waveZ = Math.sin(clock * 1.8) * 8;
const totalRx = currentRx + waveRx;
const totalRy = currentRy + waveRy;
if (containerRef.current) {
containerRef.current.style.transform = `rotateX(${currentRx.toFixed(2)}deg) rotateY(${currentRy.toFixed(2)}deg)`;
containerRef.current.style.transform = `perspective(1100px) rotateX(${totalRx.toFixed(2)}deg) rotateY(${totalRy.toFixed(2)}deg) translateZ(${waveZ.toFixed(1)}px)`;
}
if (headlineRef.current) {
// Multi-tier parallax elevation
headlineRef.current.style.transform = `translateZ(42px) rotateX(${(totalRx * 0.3).toFixed(2)}deg)`;
}
if (shadowRef.current) {
// Holographic blur shadow projected behind
shadowRef.current.style.transform = `translateZ(-28px) translate(${(totalRy * 1.8).toFixed(1)}px, ${(totalRx * 1.8).toFixed(1)}px) scale(1.05)`;
}
if (subtitleRef.current) {
subtitleRef.current.style.transform = `translateZ(24px) rotateX(${(totalRx * 0.2).toFixed(2)}deg)`;
}
rafId = requestAnimationFrame(updateLoop);
@@ -65,39 +92,41 @@ export function Kinetic3DText({
{/* 3D Stereoscopic Kinetic Text Stage */}
<div
ref={containerRef}
className="preserve-3d transition-transform duration-75 ease-out will-change-transform"
className="preserve-3d will-change-transform"
>
{/* Layer 1: Ambient 3D Text Holographic Depth Shadow */}
{/* Layer 1: Ambient 3D Text Holographic Depth Reflection */}
<div
className="absolute inset-0 select-none pointer-events-none opacity-20 blur-md transform translate-z-[-20px] scale-[1.03]"
ref={shadowRef}
className="absolute inset-0 select-none pointer-events-none opacity-25 blur-lg will-change-transform"
aria-hidden="true"
>
<span className="text-4xl sm:text-5xl lg:text-6xl xl:text-7xl font-display font-black text-blue-700 leading-[1.08] tracking-tight block">
<span className="text-4xl sm:text-5xl lg:text-6xl xl:text-7xl font-display font-black text-blue-600 leading-[1.08] tracking-tight block">
{primaryText} <br className="hidden sm:inline" />
{highlightText}
</span>
</div>
{/* Layer 2: Main Floating 3D Headline */}
{/* Layer 2: Main Floating 3D Headline with Chiseled Extrusion */}
<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 preserve-3d"
style={{ transform: 'translateZ(35px)' }}
ref={headlineRef}
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 preserve-3d will-change-transform text-3d-chiseled"
>
<span>{primaryText}</span> <br className="hidden sm:inline" />
<span className="inline-block preserve-3d">{primaryText}</span>{' '}
<br className="hidden sm:inline" />
{highlightText && (
<span className="relative inline-block mt-1 sm:mt-0 preserve-3d">
<span className="text-transparent bg-clip-text bg-gradient-to-r from-blue-700 via-indigo-600 to-amber-600 drop-shadow-[0_4px_12px_rgba(37,99,235,0.25)]">
<span className="relative inline-block mt-2 sm:mt-1 preserve-3d">
<span className="text-transparent bg-clip-text bg-gradient-to-r from-blue-700 via-indigo-600 to-amber-600 text-3d-gradient inline-block">
{highlightText}
</span>
</span>
)}
</h1>
{/* Layer 3: Elevated Subtitle */}
{/* Layer 3: Elevated 3D Subtitle */}
{subtitle && (
<p
className="mt-6 text-base sm:text-lg lg:text-xl text-slate-600 leading-relaxed max-w-2xl mx-auto font-normal preserve-3d"
style={{ transform: 'translateZ(20px)' }}
ref={subtitleRef}
className="mt-6 text-base sm:text-lg lg:text-xl text-slate-600 leading-relaxed max-w-2xl mx-auto font-normal preserve-3d will-change-transform"
>
{subtitle}
</p>