diff --git a/src/components/sections/CinematicHorizontalScrollSection.tsx b/src/components/sections/CinematicHorizontalScrollSection.tsx index 09adbd5..b535ccc 100644 --- a/src/components/sections/CinematicHorizontalScrollSection.tsx +++ b/src/components/sections/CinematicHorizontalScrollSection.tsx @@ -1,8 +1,8 @@ 'use client'; -import React, { useRef, useState, useEffect } from 'react'; +import React, { useRef, useEffect, useState, useCallback } from 'react'; import Link from 'next/link'; -import { Sparkles, ArrowRight, Smartphone } from 'lucide-react'; +import { Sparkles, ArrowRight, Smartphone, ChevronLeft, ChevronRight } from 'lucide-react'; import { Cinematic3DComparison } from '@/components/ui/Cinematic3DComparison'; interface ShowcaseCard { @@ -79,74 +79,116 @@ export function CinematicHorizontalScrollSection() { const bgTextRef = useRef(null); const progressBarRef = useRef(null); const progressTextRef = useRef(null); + const [activeCardIndex, setActiveCardIndex] = useState(0); + + const scrollToCard = useCallback((index: number) => { + if (!containerRef.current) return; + const rect = containerRef.current.getBoundingClientRect(); + const containerTop = rect.top + window.scrollY; + const scrollableDistance = Math.max(containerRef.current.offsetHeight - window.innerHeight, 1); + const targetY = containerTop + (index / 2) * scrollableDistance; + window.scrollTo({ top: targetY, behavior: 'smooth' }); + }, []); + + const navigateStep = useCallback((delta: number) => { + const nextIdx = Math.max(0, Math.min(2, activeCardIndex + delta)); + scrollToCard(nextIdx); + }, [activeCardIndex, scrollToCard]); useEffect(() => { - let rafId: number; - let targetX = 0; - let currentX = 0; - let isTracking = true; + let ticking = false; + let containerTop = 0; + let scrollableDistance = 1; + let maxTranslate = 1; + let cardStep = 780; + let screenCenter = window.innerWidth / 2; - // High-precision lerp animation loop (eliminates CSS transition conflicts for butter-smooth 120 FPS glide) - const updateMotion = () => { - if (!isTracking) return; - - if (containerRef.current && trackRef.current) { - const rect = containerRef.current.getBoundingClientRect(); - const totalScrollable = containerRef.current.offsetHeight - window.innerHeight; - - if (totalScrollable > 0) { - const rawProgress = Math.min(Math.max(-rect.top / totalScrollable, 0), 1); - const maxTranslate = trackRef.current.scrollWidth - window.innerWidth; - - if (maxTranslate > 0) { - targetX = rawProgress * maxTranslate; - } - - // Smooth exponential damping (lerp factor 0.085) - currentX += (targetX - currentX) * 0.085; - - // Apply 100% GPU compositor transform without CSS transition lag - trackRef.current.style.transform = `translate3d(-${currentX.toFixed(2)}px, 0, 0)`; - - // Parallax 3D background typography ribbon drifting in opposite perspective - if (bgTextRef.current) { - bgTextRef.current.style.transform = `translate3d(-${(currentX * 0.4).toFixed(2)}px, 0, 0) rotateX(10deg)`; - } - - // Update Progress Indicator directly in DOM (zero React re-renders) - const liveProgress = Math.min(Math.max(currentX / (maxTranslate || 1), 0), 1); - if (progressBarRef.current) { - progressBarRef.current.style.width = `${Math.max(liveProgress * 100, 4).toFixed(1)}%`; - } - if (progressTextRef.current) { - progressTextRef.current.textContent = `PROGRESS ${Math.round(liveProgress * 100)}%`; - } - - // 3D Perspective rotational offset on individual cards - const cards = trackRef.current.children; - const screenCenter = window.innerWidth / 2; - - for (let i = 0; i < cards.length; i++) { - const card = cards[i] as HTMLElement; - const cardRect = card.getBoundingClientRect(); - const cardCenter = cardRect.left + cardRect.width / 2; - const dist = (cardCenter - screenCenter) / (window.innerWidth * 0.6); - const rotY = Math.max(Math.min(dist * -8, 14), -14); - const scale = Math.max(1 - Math.abs(dist) * 0.04, 0.94); - - card.style.transform = `perspective(1200px) rotateY(${rotY.toFixed(2)}deg) scale3d(${scale.toFixed(3)}, ${scale.toFixed(3)}, 1)`; - } - } + const measure = () => { + if (!containerRef.current || !trackRef.current) return; + const rect = containerRef.current.getBoundingClientRect(); + containerTop = rect.top + window.scrollY; + scrollableDistance = Math.max(containerRef.current.offsetHeight - window.innerHeight, 1); + maxTranslate = Math.max(trackRef.current.scrollWidth - window.innerWidth, 1); + screenCenter = window.innerWidth / 2; + const firstCard = trackRef.current.children[0] as HTMLElement | undefined; + if (firstCard) { + cardStep = firstCard.offsetWidth + 48; // card width + gap } - - rafId = requestAnimationFrame(updateMotion); }; - rafId = requestAnimationFrame(updateMotion); + measure(); + window.addEventListener('resize', measure, { passive: true }); + + // Ultra-fast direct 1:1 synchronization with smooth scroll (Zero double-damping lag) + const updatePosition = () => { + const sy = window.scrollY; + const offset = sy - containerTop; + const progress = Math.min(Math.max(offset / scrollableDistance, 0), 1); + const currentX = progress * maxTranslate; + + if (trackRef.current) { + // Direct GPU compositor translation (100% synchronized with Lenis) + trackRef.current.style.transform = `translate3d(-${currentX.toFixed(1)}px, 0, 0)`; + + if (bgTextRef.current) { + bgTextRef.current.style.transform = `translate3d(-${(currentX * 0.35).toFixed(1)}px, 0, 0) rotateX(8deg)`; + } + + if (progressBarRef.current) { + progressBarRef.current.style.width = `${Math.max(progress * 100, 4).toFixed(1)}%`; + } + if (progressTextRef.current) { + progressTextRef.current.textContent = `PROGRESS ${Math.round(progress * 100)}%`; + } + + const currentActive = Math.min(Math.round(progress * 2), 2); + setActiveCardIndex(currentActive); + + // Arithmetic 3D perspective rotation (zero forced reflows) + const cards = trackRef.current.children; + const padLeft = window.innerWidth > 640 ? 48 : 24; + for (let i = 0; i < cards.length; i++) { + const card = cards[i] as HTMLElement; + const cardCenter = padLeft + i * cardStep + (cardStep - 48) / 2 - currentX; + const dist = (cardCenter - screenCenter) / (screenCenter * 1.2); + const rotY = Math.max(Math.min(dist * -6, 9), -9); + const scale = Math.max(1 - Math.abs(dist) * 0.03, 0.96); + + card.style.transform = `perspective(1100px) rotateY(${rotY.toFixed(2)}deg) scale3d(${scale.toFixed(3)}, ${scale.toFixed(3)}, 1)`; + } + } + }; + + const handleScroll = () => { + if (!ticking) { + ticking = true; + requestAnimationFrame(() => { + updatePosition(); + ticking = false; + }); + } + }; + + // Trackpad horizontal swipe listener (converts two-finger deltaX directly into scroll) + const handleWheel = (e: WheelEvent) => { + if (!containerRef.current) return; + const rect = containerRef.current.getBoundingClientRect(); + if (rect.top <= 20 && rect.bottom >= window.innerHeight - 20) { + if (Math.abs(e.deltaX) > Math.abs(e.deltaY) && Math.abs(e.deltaX) > 2) { + window.scrollBy({ top: e.deltaX * 0.9, behavior: 'instant' }); + } + } + }; + + window.addEventListener('scroll', handleScroll, { passive: true }); + window.addEventListener('wheel', handleWheel, { passive: true }); + // Initial sync + updatePosition(); return () => { - isTracking = false; - cancelAnimationFrame(rafId); + window.removeEventListener('resize', measure); + window.removeEventListener('scroll', handleScroll); + window.removeEventListener('wheel', handleWheel); }; }, []); @@ -154,14 +196,14 @@ export function CinematicHorizontalScrollSection() {
{/* Sticky Fullscreen Camera Viewport */} -
+
{/* Massive 3D Kinetic Background Typography Ribbon (Parallax Drift) */} -
- - SCROLL DOWN TO PAN HORIZONTALLY - -
+
+ {/* Quick Card Jump Pills */} +
+ {showcaseCards.map((c, i) => ( + + ))} +
+ + {/* Quick Step Controls */} +
+ + +
+ + {/* Progress Badge */} +
PROGRESS 0%
@@ -200,7 +277,7 @@ export function CinematicHorizontalScrollSection() {
{showcaseCards.map((card) => (
- {/* 3D Cinematic Comparison Viewport */} + {/* 3D Cinematic Comparison Viewport (autoSlide false to save CPU/GPU cycles during horizontal pan) */}
@@ -289,7 +367,7 @@ export function CinematicHorizontalScrollSection() { href={`/apps/${card.appSlug}`} className="inline-flex items-center gap-1.5 px-3 py-1.5 rounded-full bg-slate-900 text-white text-xs font-bold hover:bg-blue-700 transition-colors shadow-sm" > - + {card.appName}
@@ -299,14 +377,24 @@ export function CinematicHorizontalScrollSection() {
- {/* Section Bottom Progress Indicator Bar */} + {/* Bottom Cinematic Control & Progress Rail */}
-
-
+
+ {/* Visual Progress Bar Track */} +
+
+
+ + {/* Model Metadata Tags */} +
+ ARCHIVE: VOL. 26 + • + NEURAL VISION ACCELERATOR +
diff --git a/src/components/ui/Cinematic3DTextEngine.tsx b/src/components/ui/Cinematic3DTextEngine.tsx index e578909..969cc69 100644 --- a/src/components/ui/Cinematic3DTextEngine.tsx +++ b/src/components/ui/Cinematic3DTextEngine.tsx @@ -8,8 +8,6 @@ export function Cinematic3DTextEngine() { if (window.matchMedia('(prefers-reduced-motion: reduce)').matches) return; let rafId: number; - let mouseX = 0; - let mouseY = 0; let targetMouseX = 0; let targetMouseY = 0; let currentMouseX = 0; @@ -32,14 +30,13 @@ export function Cinematic3DTextEngine() { const sy = window.scrollY || 0; const delta = sy - lastScrollY; lastScrollY = sy; - // Scroll velocity pitch tilt (leans on scroll) - targetScrollPitch = Math.max(Math.min(delta * 0.2, 8), -8); + targetScrollPitch = Math.max(Math.min(delta * 0.18, 7), -7); }; window.addEventListener('mousemove', handleMouseMove, { passive: true }); window.addEventListener('scroll', handleScroll, { passive: true }); - // Selector targeting all headings, display titles, stats, badges, and card titles across the whole website + // Target headings, badges, card titles, and stats const selector = [ 'h1:not([data-no3d])', 'h2:not([data-no3d])', @@ -51,58 +48,59 @@ export function Cinematic3DTextEngine() { '[data-3d-text]', ].join(', '); + // Use IntersectionObserver to track visible elements with ZERO per-frame DOM reads + const visibleElements = new Set(); + + const observer = new IntersectionObserver( + (entries) => { + entries.forEach((entry) => { + const el = entry.target as HTMLElement; + if (entry.isIntersecting) { + visibleElements.add(el); + // Ensure inline elements can be 3D transformed + if (window.getComputedStyle(el).display === 'inline') { + el.style.display = 'inline-block'; + } + el.style.transformStyle = 'preserve-3d'; + el.style.willChange = 'transform'; + } else { + visibleElements.delete(el); + } + }); + }, + { rootMargin: '100px 0px 100px 0px', threshold: 0 } + ); + + const allElements = document.querySelectorAll(selector); + allElements.forEach((el) => { + if (!el.closest('canvas') && !el.closest('[data-no3d-container]')) { + observer.observe(el); + } + }); + const tick = () => { - clock += 0.022; + clock += 0.024; - // Inertial smoothing lerps - currentMouseX += (targetMouseX - currentMouseX) * 0.075; - currentMouseY += (targetMouseY - currentMouseY) * 0.075; - currentScrollPitch += (targetScrollPitch - currentScrollPitch) * 0.1; - targetScrollPitch *= 0.88; // Damping decay + // Fast, responsive lerps (0.12 factor eliminates input lag) + currentMouseX += (targetMouseX - currentMouseX) * 0.12; + currentMouseY += (targetMouseY - currentMouseY) * 0.12; + currentScrollPitch += (targetScrollPitch - currentScrollPitch) * 0.15; + targetScrollPitch *= 0.85; - // Update root CSS variables for global CSS animation pairing - document.documentElement.style.setProperty('--3d-mouse-x', currentMouseX.toFixed(3)); - document.documentElement.style.setProperty('--3d-mouse-y', currentMouseY.toFixed(3)); - document.documentElement.style.setProperty('--3d-scroll-pitch', `${currentScrollPitch.toFixed(2)}deg`); + let idx = 0; + visibleElements.forEach((el) => { + idx++; + const phase = idx * 0.5; + const waveX = Math.sin(clock * 1.4 + phase) * 3.4; + const waveY = Math.cos(clock * 1.1 + phase) * 4.0; + const waveZ = Math.sin(clock * 1.8 + phase) * 6; - const elements = document.querySelectorAll(selector); - const vh = window.innerHeight; - const vw = window.innerWidth; - - elements.forEach((el, index) => { - // Skip canvas or explicitly opted-out elements - if (el.closest('canvas') || el.closest('[data-no3d-container]')) return; - - const rect = el.getBoundingClientRect(); - // Skip elements far outside viewport for performance - if (rect.bottom < -200 || rect.top > vh + 200) return; - - // Ensure element can receive 3D transform (inline elements cannot be transformed) - const computedDisplay = window.getComputedStyle(el).display; - if (computedDisplay === 'inline') { - el.style.display = 'inline-block'; - } - - const elCenterX = rect.left + rect.width / 2; - const elCenterY = rect.top + rect.height / 2; - - // Parallax coordinates relative to viewport center - const dx = (elCenterX - vw / 2) / (vw / 2); - const dy = (elCenterY - vh / 2) / (vh / 2); - - // Individual organic phase offset for each element - const phase = index * 0.45; - const waveX = Math.sin(clock * 1.3 + phase) * 3.2; - const waveY = Math.cos(clock * 1.0 + phase) * 3.8; - const waveZ = Math.sin(clock * 1.6 + phase) * 6; - - // Hierarchical depth based on tag importance const tagName = el.tagName.toLowerCase(); let baseZ = 16; let rotMultiplier = 1; if (tagName === 'h1') { - baseZ = 30; + baseZ = 32; rotMultiplier = 1.3; } else if (tagName === 'h2') { baseZ = 24; @@ -111,21 +109,19 @@ export function Cinematic3DTextEngine() { baseZ = 18; rotMultiplier = 1.0; } else if (el.classList.contains('stat-value')) { - baseZ = 26; - rotMultiplier = 1.2; + baseZ = 28; + rotMultiplier = 1.25; } else if (tagName === 'h4') { baseZ = 14; rotMultiplier = 0.9; } - // Calculate 3D perspective pitch, yaw, and translation - const rotX = (-(currentMouseY * 6 + dy * 3.5) + currentScrollPitch + waveX) * rotMultiplier; - const rotY = (currentMouseX * 7 + dx * 4 + waveY) * rotMultiplier; - const transZ = Math.max(baseZ + waveZ - Math.hypot(dx, dy) * 4, 6); + const rotX = (-currentMouseY * 6 + currentScrollPitch + waveX) * rotMultiplier; + const rotY = (currentMouseX * 7 + waveY) * rotMultiplier; + const transZ = Math.max(baseZ + waveZ, 6); + // Batch write directly to GPU transform matrix (ZERO DOM READS!) el.style.transform = `perspective(950px) rotateX(${rotX.toFixed(2)}deg) rotateY(${rotY.toFixed(2)}deg) translateZ(${transZ.toFixed(1)}px)`; - el.style.transformStyle = 'preserve-3d'; - el.style.willChange = 'transform'; }); rafId = requestAnimationFrame(tick); @@ -135,6 +131,7 @@ export function Cinematic3DTextEngine() { return () => { cancelAnimationFrame(rafId); + observer.disconnect(); window.removeEventListener('mousemove', handleMouseMove); window.removeEventListener('scroll', handleScroll); }; diff --git a/src/components/ui/SmoothScroll.tsx b/src/components/ui/SmoothScroll.tsx index 5f84ae9..3318664 100644 --- a/src/components/ui/SmoothScroll.tsx +++ b/src/components/ui/SmoothScroll.tsx @@ -9,13 +9,13 @@ export function SmoothScroll() { if (window.matchMedia('(prefers-reduced-motion: reduce)').matches) return; const lenis = new Lenis({ - duration: 1.15, + duration: 0.95, easing: (t) => Math.min(1, 1.001 - Math.pow(2, -10 * t)), orientation: 'vertical', - gestureOrientation: 'vertical', + gestureOrientation: 'both', // Allows trackpad horizontal and vertical gestures smoothWheel: true, syncTouch: false, // Preserves hardware 120Hz momentum touch scrolling on phones & tablets - wheelMultiplier: 0.95, + wheelMultiplier: 1.0, touchMultiplier: 1.0, });