feat(ui): add Three.js 3D neural prism, 3D tilt cards, cursor aura, and flagship banners
This commit is contained in:
@@ -10,6 +10,7 @@ interface BeforeAfterSliderProps {
|
||||
afterLabel?: string;
|
||||
caption?: string;
|
||||
aspectRatio?: string;
|
||||
autoSlide?: boolean;
|
||||
}
|
||||
|
||||
export function BeforeAfterSlider({
|
||||
@@ -19,10 +20,37 @@ export function BeforeAfterSlider({
|
||||
afterLabel = 'CRE AI Result',
|
||||
caption,
|
||||
aspectRatio = 'aspect-[4/3] sm:aspect-[16/10]',
|
||||
autoSlide = true,
|
||||
}: BeforeAfterSliderProps) {
|
||||
const [sliderPosition, setSliderPosition] = useState(50);
|
||||
const [isDragging, setIsDragging] = useState(false);
|
||||
const [isUserInteracting, setIsUserInteracting] = useState(false);
|
||||
const containerRef = useRef<HTMLDivElement>(null);
|
||||
const animFrameRef = useRef<number | null>(null);
|
||||
const resumeTimerRef = useRef<NodeJS.Timeout | null>(null);
|
||||
const startTimeRef = useRef<number>(Date.now());
|
||||
|
||||
// Auto-slide animation loop using RAF
|
||||
useEffect(() => {
|
||||
if (!autoSlide || isDragging || isUserInteracting) {
|
||||
if (animFrameRef.current) cancelAnimationFrame(animFrameRef.current);
|
||||
return;
|
||||
}
|
||||
|
||||
const animate = () => {
|
||||
const elapsed = Date.now() - startTimeRef.current;
|
||||
// Smooth sine wave between 24% and 76% (period ~4 seconds)
|
||||
const newPos = 50 + 26 * Math.sin(elapsed * 0.0016);
|
||||
setSliderPosition(newPos);
|
||||
animFrameRef.current = requestAnimationFrame(animate);
|
||||
};
|
||||
|
||||
animFrameRef.current = requestAnimationFrame(animate);
|
||||
|
||||
return () => {
|
||||
if (animFrameRef.current) cancelAnimationFrame(animFrameRef.current);
|
||||
};
|
||||
}, [autoSlide, isDragging, isUserInteracting]);
|
||||
|
||||
const handleMove = useCallback((clientX: number) => {
|
||||
if (!containerRef.current) return;
|
||||
@@ -61,12 +89,33 @@ export function BeforeAfterSlider({
|
||||
};
|
||||
}, [isDragging, handleMouseMove, handleMouseUp, handleTouchMove]);
|
||||
|
||||
const handleMouseEnter = () => {
|
||||
setIsUserInteracting(true);
|
||||
if (resumeTimerRef.current) clearTimeout(resumeTimerRef.current);
|
||||
};
|
||||
|
||||
const handleMouseLeave = () => {
|
||||
if (resumeTimerRef.current) clearTimeout(resumeTimerRef.current);
|
||||
resumeTimerRef.current = setTimeout(() => {
|
||||
setIsUserInteracting(false);
|
||||
startTimeRef.current = Date.now();
|
||||
}, 2500);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="w-full">
|
||||
<div
|
||||
ref={containerRef}
|
||||
onMouseDown={() => setIsDragging(true)}
|
||||
onTouchStart={() => setIsDragging(true)}
|
||||
onMouseEnter={handleMouseEnter}
|
||||
onMouseLeave={handleMouseLeave}
|
||||
onMouseDown={() => {
|
||||
setIsDragging(true);
|
||||
setIsUserInteracting(true);
|
||||
}}
|
||||
onTouchStart={() => {
|
||||
setIsDragging(true);
|
||||
setIsUserInteracting(true);
|
||||
}}
|
||||
className={`relative w-full ${aspectRatio} rounded-2xl sm:rounded-3xl overflow-hidden select-none cursor-ew-resize shadow-md border border-slate-900/[0.08] bg-slate-950 group`}
|
||||
style={{ touchAction: 'pan-y' }}
|
||||
>
|
||||
@@ -121,9 +170,19 @@ export function BeforeAfterSlider({
|
||||
<span>{afterLabel}</span>
|
||||
</div>
|
||||
|
||||
{/* Bottom Helper Hint */}
|
||||
<div className="absolute bottom-3 left-1/2 -translate-x-1/2 bg-black/60 backdrop-blur-md px-3 py-1 rounded-full text-[10px] font-mono text-white/90 pointer-events-none opacity-0 group-hover:opacity-100 transition-opacity duration-200">
|
||||
Drag horizontally to inspect pore texture
|
||||
{/* Animated Sliding Status Pill */}
|
||||
<div className="absolute bottom-3 left-1/2 -translate-x-1/2 bg-slate-900/85 backdrop-blur-md px-3.5 py-1 rounded-full text-[10px] font-mono font-semibold text-white pointer-events-none border border-white/10 shadow-sm flex items-center gap-1.5">
|
||||
{autoSlide && !isUserInteracting ? (
|
||||
<>
|
||||
<span className="w-1.5 h-1.5 rounded-full bg-cyan-400 animate-pulse" />
|
||||
<span>Auto-Scanning Difference (Hover to Drag)</span>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<span className="w-1.5 h-1.5 rounded-full bg-blue-400" />
|
||||
<span>Interactive Drag Mode</span>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
'use client';
|
||||
|
||||
import React, { useEffect, useRef, useState } from 'react';
|
||||
|
||||
export function CursorAura() {
|
||||
const [mounted, setMounted] = useState<boolean>(false);
|
||||
const posRef = useRef({ targetX: -500, targetY: -500, currentX: -500, currentY: -500 });
|
||||
const auraRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
useEffect(() => {
|
||||
// Only enable on pointer-fine (mouse/trackpad) and when not reduced-motion
|
||||
if (window.matchMedia('(pointer: coarse)').matches) return;
|
||||
if (window.matchMedia('(prefers-reduced-motion: reduce)').matches) return;
|
||||
|
||||
setMounted(true);
|
||||
|
||||
const onMouseMove = (e: MouseEvent) => {
|
||||
posRef.current.targetX = e.clientX;
|
||||
posRef.current.targetY = e.clientY;
|
||||
};
|
||||
|
||||
window.addEventListener('mousemove', onMouseMove, { passive: true });
|
||||
|
||||
let animId: number;
|
||||
|
||||
const render = () => {
|
||||
const pos = posRef.current;
|
||||
// Damped lerp follower
|
||||
pos.currentX += (pos.targetX - pos.currentX) * 0.08;
|
||||
pos.currentY += (pos.targetY - pos.currentY) * 0.08;
|
||||
|
||||
if (auraRef.current) {
|
||||
auraRef.current.style.transform = `translate3d(${pos.currentX - 250}px, ${pos.currentY - 250}px, 0)`;
|
||||
}
|
||||
|
||||
animId = requestAnimationFrame(render);
|
||||
};
|
||||
|
||||
animId = requestAnimationFrame(render);
|
||||
|
||||
return () => {
|
||||
cancelAnimationFrame(animId);
|
||||
window.removeEventListener('mousemove', onMouseMove);
|
||||
};
|
||||
}, []);
|
||||
|
||||
if (!mounted) return null;
|
||||
|
||||
return (
|
||||
<div
|
||||
aria-hidden="true"
|
||||
className="pointer-events-none fixed inset-0 z-0 overflow-hidden hidden [@media(hover:hover)]:block"
|
||||
>
|
||||
<div
|
||||
ref={auraRef}
|
||||
className="absolute top-0 left-0 w-[500px] h-[500px] rounded-full will-change-transform opacity-60"
|
||||
style={{
|
||||
background:
|
||||
'radial-gradient(circle, rgba(59, 130, 246, 0.09) 0%, rgba(99, 102, 241, 0.05) 35%, rgba(168, 85, 247, 0.02) 60%, transparent 80%)',
|
||||
filter: 'blur(35px)',
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
'use client';
|
||||
|
||||
import React, { useRef, useState, useCallback, MouseEvent } from 'react';
|
||||
|
||||
interface TiltCardProps {
|
||||
children: React.ReactNode;
|
||||
className?: string;
|
||||
maxTilt?: number; // Maximum tilt angle in degrees (default: 8)
|
||||
scale?: number; // Scale on hover (default: 1.015)
|
||||
showGlare?: boolean; // Enable dynamic specular shine reflection (default: true)
|
||||
}
|
||||
|
||||
export function TiltCard({
|
||||
children,
|
||||
className = '',
|
||||
maxTilt = 7,
|
||||
scale = 1.015,
|
||||
showGlare = true,
|
||||
}: TiltCardProps) {
|
||||
const cardRef = useRef<HTMLDivElement>(null);
|
||||
const [transformStyle, setTransformStyle] = useState<string>('');
|
||||
const [glareStyle, setGlareStyle] = useState<{ opacity: number; background: string }>({
|
||||
opacity: 0,
|
||||
background: '',
|
||||
});
|
||||
const [isHovered, setIsHovered] = useState<boolean>(false);
|
||||
|
||||
const handleMouseMove = useCallback(
|
||||
(e: MouseEvent<HTMLDivElement>) => {
|
||||
const card = cardRef.current;
|
||||
if (!card) return;
|
||||
|
||||
const rect = card.getBoundingClientRect();
|
||||
const x = e.clientX - rect.left;
|
||||
const y = e.clientY - rect.top;
|
||||
|
||||
const width = rect.width;
|
||||
const height = rect.height;
|
||||
|
||||
// Normalized coordinates from -1 to 1
|
||||
const normalizedX = (x / width) * 2 - 1;
|
||||
const normalizedY = (y / height) * 2 - 1;
|
||||
|
||||
// Tilt angles (negative Y rotates along X axis)
|
||||
const rotateX = -normalizedY * maxTilt;
|
||||
const rotateY = normalizedX * maxTilt;
|
||||
|
||||
setTransformStyle(
|
||||
`perspective(1000px) rotateX(${rotateX.toFixed(2)}deg) rotateY(${rotateY.toFixed(2)}deg) scale3d(${scale}, ${scale}, ${scale})`
|
||||
);
|
||||
|
||||
if (showGlare) {
|
||||
const glareX = (x / width) * 100;
|
||||
const glareY = (y / height) * 100;
|
||||
|
||||
setGlareStyle({
|
||||
opacity: 0.18,
|
||||
background: `radial-gradient(circle 350px at ${glareX}% ${glareY}%, rgba(255, 255, 255, 0.7) 0%, rgba(255, 255, 255, 0.05) 50%, transparent 80%)`,
|
||||
});
|
||||
}
|
||||
},
|
||||
[maxTilt, scale, showGlare]
|
||||
);
|
||||
|
||||
const handleMouseEnter = useCallback(() => {
|
||||
setIsHovered(true);
|
||||
}, []);
|
||||
|
||||
const handleMouseLeave = useCallback(() => {
|
||||
setIsHovered(false);
|
||||
setTransformStyle('perspective(1000px) rotateX(0deg) rotateY(0deg) scale3d(1, 1, 1)');
|
||||
setGlareStyle((prev) => ({ ...prev, opacity: 0 }));
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div
|
||||
ref={cardRef}
|
||||
onMouseMove={handleMouseMove}
|
||||
onMouseEnter={handleMouseEnter}
|
||||
onMouseLeave={handleMouseLeave}
|
||||
style={{
|
||||
transform: transformStyle || undefined,
|
||||
transformStyle: 'preserve-3d',
|
||||
transition: isHovered
|
||||
? 'transform 0.1s ease-out'
|
||||
: 'transform 0.5s cubic-bezier(0.16, 1, 0.3, 1)',
|
||||
}}
|
||||
className={`relative will-change-transform ${className}`}
|
||||
>
|
||||
{children}
|
||||
|
||||
{/* Dynamic Specular Glare Reflection */}
|
||||
{showGlare && (
|
||||
<div
|
||||
className="absolute inset-0 rounded-[inherit] pointer-events-none transition-opacity duration-300 z-30 overflow-hidden"
|
||||
style={{
|
||||
opacity: glareStyle.opacity,
|
||||
background: glareStyle.background,
|
||||
}}
|
||||
aria-hidden="true"
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user