2026-11-03 16:49:56 +05:30
|
|
|
'use client';
|
|
|
|
|
|
2026-11-03 18:34:29 +05:30
|
|
|
import React, { useRef, useCallback } 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 18:34:29 +05:30
|
|
|
const textRef = useRef<HTMLDivElement>(null);
|
2026-11-03 16:49:56 +05:30
|
|
|
|
2026-11-03 17:23:03 +05:30
|
|
|
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;
|
2026-11-03 18:34:29 +05:30
|
|
|
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)`;
|
2026-11-03 17:23:03 +05:30
|
|
|
}, []);
|
2026-11-03 17:08:23 +05:30
|
|
|
|
2026-11-03 17:23:03 +05:30
|
|
|
const handleMouseLeave = useCallback(() => {
|
2026-11-03 18:34:29 +05:30
|
|
|
if (textRef.current) textRef.current.style.transform = 'perspective(1000px) rotateX(0deg) rotateY(0deg)';
|
2026-11-03 16:49:56 +05:30
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
return (
|
2026-11-03 17:23:03 +05:30
|
|
|
<div
|
|
|
|
|
ref={containerRef}
|
|
|
|
|
onMouseMove={handleMouseMove}
|
|
|
|
|
onMouseLeave={handleMouseLeave}
|
|
|
|
|
className={`relative select-none ${className}`}
|
|
|
|
|
>
|
2026-11-03 16:49:56 +05:30
|
|
|
<div
|
2026-11-03 18:34:29 +05:30
|
|
|
ref={textRef}
|
|
|
|
|
className="transition-transform duration-300 ease-out will-change-transform"
|
|
|
|
|
style={{ transform: 'perspective(1000px) rotateX(0deg) rotateY(0deg)', transformStyle: 'preserve-3d' }}
|
2026-11-03 16:49:56 +05:30
|
|
|
>
|
2026-11-03 17:23:03 +05:30
|
|
|
{/* 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">
|
|
|
|
|
<span className="inline-block text-slate-900">{primaryText}</span>{' '}
|
2026-11-03 17:08:23 +05:30
|
|
|
<br className="hidden sm:inline" />
|
2026-11-03 16:49:56 +05:30
|
|
|
{highlightText && (
|
2026-11-03 17:23:03 +05:30
|
|
|
<span className="relative inline-block mt-1 sm:mt-0">
|
|
|
|
|
<span className="text-transparent bg-clip-text bg-gradient-to-r from-blue-700 via-indigo-600 to-amber-600 inline-block font-black">
|
2026-11-03 16:49:56 +05:30
|
|
|
{highlightText}
|
|
|
|
|
</span>
|
|
|
|
|
</span>
|
|
|
|
|
)}
|
|
|
|
|
</h1>
|
|
|
|
|
|
2026-11-03 17:23:03 +05:30
|
|
|
{/* Subtitle (100% Visible & Crisp) */}
|
2026-11-03 16:49:56 +05:30
|
|
|
{subtitle && (
|
2026-11-03 17:23:03 +05:30
|
|
|
<p className="mt-6 text-base sm:text-lg lg:text-xl text-slate-600 leading-relaxed max-w-2xl mx-auto font-normal">
|
2026-11-03 16:49:56 +05:30
|
|
|
{subtitle}
|
|
|
|
|
</p>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|