2026-11-03 16:49:56 +05:30
|
|
|
'use client';
|
|
|
|
|
|
2026-11-03 17:08:23 +05:30
|
|
|
import React, { useRef, useEffect } from 'react';
|
2026-11-03 16:49:56 +05:30
|
|
|
|
|
|
|
|
interface Kinetic3DTextProps {
|
|
|
|
|
primaryText: string;
|
|
|
|
|
highlightText?: string;
|
|
|
|
|
subtitle?: string;
|
|
|
|
|
className?: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function Kinetic3DText({
|
|
|
|
|
primaryText,
|
|
|
|
|
highlightText,
|
|
|
|
|
subtitle,
|
|
|
|
|
className = '',
|
|
|
|
|
}: Kinetic3DTextProps) {
|
|
|
|
|
const containerRef = useRef<HTMLDivElement>(null);
|
2026-11-03 17:08:23 +05:30
|
|
|
const headlineRef = useRef<HTMLHeadingElement>(null);
|
|
|
|
|
const shadowRef = useRef<HTMLDivElement>(null);
|
|
|
|
|
const subtitleRef = useRef<HTMLParagraphElement>(null);
|
2026-11-03 16:49:56 +05:30
|
|
|
|
|
|
|
|
useEffect(() => {
|
2026-11-03 17:08:23 +05:30
|
|
|
// Check prefers-reduced-motion
|
|
|
|
|
if (window.matchMedia('(prefers-reduced-motion: reduce)').matches) return;
|
|
|
|
|
|
2026-11-03 16:49:56 +05:30
|
|
|
let rafId: number;
|
|
|
|
|
let targetRx = 0;
|
|
|
|
|
let targetRy = 0;
|
|
|
|
|
let currentRx = 0;
|
|
|
|
|
let currentRy = 0;
|
2026-11-03 17:08:23 +05:30
|
|
|
let clock = 0;
|
2026-11-03 16:49:56 +05:30
|
|
|
|
|
|
|
|
const handleMouseMove = (e: MouseEvent) => {
|
2026-11-03 17:08:23 +05:30
|
|
|
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;
|
2026-11-03 16:49:56 +05:30
|
|
|
|
2026-11-03 17:08:23 +05:30
|
|
|
targetRy = nx * 14; // Horizontal tilt up to 14 deg
|
|
|
|
|
targetRx = -ny * 12; // Vertical tilt up to 12 deg
|
2026-11-03 16:49:56 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const updateLoop = () => {
|
2026-11-03 17:08:23 +05:30
|
|
|
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;
|
2026-11-03 16:49:56 +05:30
|
|
|
|
|
|
|
|
if (containerRef.current) {
|
2026-11-03 17:08:23 +05:30
|
|
|
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)`;
|
2026-11-03 16:49:56 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rafId = requestAnimationFrame(updateLoop);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
window.addEventListener('mousemove', handleMouseMove, { passive: true });
|
|
|
|
|
rafId = requestAnimationFrame(updateLoop);
|
|
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
|
window.removeEventListener('mousemove', handleMouseMove);
|
|
|
|
|
cancelAnimationFrame(rafId);
|
|
|
|
|
};
|
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className={`relative perspective-1000 select-none ${className}`}>
|
|
|
|
|
{/* 3D Stereoscopic Kinetic Text Stage */}
|
|
|
|
|
<div
|
|
|
|
|
ref={containerRef}
|
2026-11-03 17:08:23 +05:30
|
|
|
className="preserve-3d will-change-transform"
|
2026-11-03 16:49:56 +05:30
|
|
|
>
|
2026-11-03 17:08:23 +05:30
|
|
|
{/* Layer 1: Ambient 3D Text Holographic Depth Reflection */}
|
2026-11-03 16:49:56 +05:30
|
|
|
<div
|
2026-11-03 17:08:23 +05:30
|
|
|
ref={shadowRef}
|
|
|
|
|
className="absolute inset-0 select-none pointer-events-none opacity-25 blur-lg will-change-transform"
|
2026-11-03 16:49:56 +05:30
|
|
|
aria-hidden="true"
|
|
|
|
|
>
|
2026-11-03 17:08:23 +05:30
|
|
|
<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">
|
2026-11-03 16:49:56 +05:30
|
|
|
{primaryText} <br className="hidden sm:inline" />
|
|
|
|
|
{highlightText}
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
|
2026-11-03 17:08:23 +05:30
|
|
|
{/* Layer 2: Main Floating 3D Headline with Chiseled Extrusion */}
|
2026-11-03 16:49:56 +05:30
|
|
|
<h1
|
2026-11-03 17:08:23 +05:30
|
|
|
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"
|
2026-11-03 16:49:56 +05:30
|
|
|
>
|
2026-11-03 17:08:23 +05:30
|
|
|
<span className="inline-block preserve-3d">{primaryText}</span>{' '}
|
|
|
|
|
<br className="hidden sm:inline" />
|
2026-11-03 16:49:56 +05:30
|
|
|
{highlightText && (
|
2026-11-03 17:08:23 +05:30
|
|
|
<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">
|
2026-11-03 16:49:56 +05:30
|
|
|
{highlightText}
|
|
|
|
|
</span>
|
|
|
|
|
</span>
|
|
|
|
|
)}
|
|
|
|
|
</h1>
|
|
|
|
|
|
2026-11-03 17:08:23 +05:30
|
|
|
{/* Layer 3: Elevated 3D Subtitle */}
|
2026-11-03 16:49:56 +05:30
|
|
|
{subtitle && (
|
|
|
|
|
<p
|
2026-11-03 17:08:23 +05:30
|
|
|
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"
|
2026-11-03 16:49:56 +05:30
|
|
|
>
|
|
|
|
|
{subtitle}
|
|
|
|
|
</p>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|