From 8cec9692dcfa90ed42f5ae279b93ef3d5e039e93 Mon Sep 17 00:00:00 2001 From: vshnosngh Date: Tue, 3 Nov 2026 17:31:00 +0530 Subject: [PATCH] feat(showcase): completely rewrite horizontal showcase into native GPU-accelerated filmstrip with zero scroll hijacking --- .../CinematicHorizontalScrollSection.tsx | 529 +++++++++--------- 1 file changed, 253 insertions(+), 276 deletions(-) diff --git a/src/components/sections/CinematicHorizontalScrollSection.tsx b/src/components/sections/CinematicHorizontalScrollSection.tsx index b535ccc..f38d045 100644 --- a/src/components/sections/CinematicHorizontalScrollSection.tsx +++ b/src/components/sections/CinematicHorizontalScrollSection.tsx @@ -1,8 +1,8 @@ 'use client'; -import React, { useRef, useEffect, useState, useCallback } from 'react'; +import React, { useRef, useState, useEffect, useCallback } from 'react'; import Link from 'next/link'; -import { Sparkles, ArrowRight, Smartphone, ChevronLeft, ChevronRight } from 'lucide-react'; +import { Sparkles, ArrowRight, Smartphone, ChevronLeft, ChevronRight, Layers } from 'lucide-react'; import { Cinematic3DComparison } from '@/components/ui/Cinematic3DComparison'; interface ShowcaseCard { @@ -74,327 +74,304 @@ const showcaseCards: ShowcaseCard[] = [ ]; export function CinematicHorizontalScrollSection() { - const containerRef = useRef(null); - const trackRef = useRef(null); - const bgTextRef = useRef(null); - const progressBarRef = useRef(null); - const progressTextRef = useRef(null); - const [activeCardIndex, setActiveCardIndex] = useState(0); + const scrollRef = useRef(null); + const [activeIndex, setActiveIndex] = useState(0); + const [isDragging, setIsDragging] = useState(false); + const [dragStartX, setDragStartX] = useState(0); + const [dragScrollLeft, setDragScrollLeft] = useState(0); + // Smoothly scroll to a specific card index 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' }); + if (!scrollRef.current) return; + const container = scrollRef.current; + const card = container.children[index] as HTMLElement | undefined; + if (card) { + const containerWidth = container.offsetWidth; + const cardWidth = card.offsetWidth; + const cardLeft = card.offsetLeft; + // Center the card in the viewport + const targetLeft = cardLeft - (containerWidth - cardWidth) / 2; + container.scrollTo({ + left: Math.max(0, targetLeft), + behavior: 'smooth', + }); + setActiveIndex(index); + } }, []); - const navigateStep = useCallback((delta: number) => { - const nextIdx = Math.max(0, Math.min(2, activeCardIndex + delta)); - scrollToCard(nextIdx); - }, [activeCardIndex, scrollToCard]); + const handlePrev = useCallback(() => { + scrollToCard(Math.max(0, activeIndex - 1)); + }, [activeIndex, scrollToCard]); + const handleNext = useCallback(() => { + scrollToCard(Math.min(showcaseCards.length - 1, activeIndex + 1)); + }, [activeIndex, scrollToCard]); + + // Update active index based on scroll position via lightweight scroll listener useEffect(() => { - let ticking = false; - let containerTop = 0; - let scrollableDistance = 1; - let maxTranslate = 1; - let cardStep = 780; - let screenCenter = window.innerWidth / 2; - - 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 - } - }; - - 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 container = scrollRef.current; + if (!container) return; + let timeoutId: NodeJS.Timeout; const handleScroll = () => { - if (!ticking) { - ticking = true; - requestAnimationFrame(() => { - updatePosition(); - ticking = false; - }); - } - }; + clearTimeout(timeoutId); + timeoutId = setTimeout(() => { + if (!container) return; + const scrollLeft = container.scrollLeft; + const containerCenter = scrollLeft + container.offsetWidth / 2; - // 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' }); + let closestIdx = 0; + let minDiff = Infinity; + + for (let i = 0; i < container.children.length; i++) { + const child = container.children[i] as HTMLElement; + const childCenter = child.offsetLeft + child.offsetWidth / 2; + const diff = Math.abs(containerCenter - childCenter); + if (diff < minDiff) { + minDiff = diff; + closestIdx = i; + } } - } + + setActiveIndex(closestIdx); + }, 50); }; - window.addEventListener('scroll', handleScroll, { passive: true }); - window.addEventListener('wheel', handleWheel, { passive: true }); - // Initial sync - updatePosition(); - + container.addEventListener('scroll', handleScroll, { passive: true }); return () => { - window.removeEventListener('resize', measure); - window.removeEventListener('scroll', handleScroll); - window.removeEventListener('wheel', handleWheel); + clearTimeout(timeoutId); + container.removeEventListener('scroll', handleScroll); }; }, []); + // Mouse Drag to Scroll handlers + const onMouseDown = (e: React.MouseEvent) => { + // Only drag when clicking background/card frame, not when interacting with inputs/buttons + const target = e.target as HTMLElement; + if (target.closest('button') || target.closest('a') || target.closest('input')) return; + + if (!scrollRef.current) return; + setIsDragging(true); + setDragStartX(e.pageX - scrollRef.current.offsetLeft); + setDragScrollLeft(scrollRef.current.scrollLeft); + }; + + const onMouseMove = (e: React.MouseEvent) => { + if (!isDragging || !scrollRef.current) return; + e.preventDefault(); + const x = e.pageX - scrollRef.current.offsetLeft; + const walk = (x - dragStartX) * 1.5; // Drag speed multiplier + scrollRef.current.scrollLeft = dragScrollLeft - walk; + }; + + const onMouseUp = () => { + setIsDragging(false); + }; + return (
- {/* Sticky Fullscreen Camera Viewport */} -
- {/* Massive 3D Kinetic Background Typography Ribbon (Parallax Drift) */} - + {/* Subtle Ambient Background Gradient */} +
+
- {/* Ambient Subtle Gradients */} -
-
+ {/* Massive Typographic Watermark (Lightweight CSS) */} + - {/* Section Top Header & Navigation Telemetry with 3D Depth */} -
-
-
+
+ {/* Header Row: Title & Editorial Badge */} +
+
+
- HORIZONTAL 3D CINEMATIC ARCHIVE + FLAGSHIP TRANSFORMATION MODELS
-

- Flagship Transformations In Real-Time +

+ Interactive Model Showcase

-
- {/* Quick Card Jump Pills */} -
- {showcaseCards.map((c, i) => ( - - ))} + {/* Navigation Controls: Tabs & Arrow Buttons */} +
+ {/* Quick Model Tabs */} +
+ {showcaseCards.map((card, idx) => { + const isActive = activeIndex === idx; + return ( + + ); + })}
- {/* Quick Step Controls */} -
+ {/* Prev / Next Arrows */} +
- - {/* Progress Badge */} -
- - PROGRESS 0% -
+
- {/* Horizontal Sliding Filmstrip Track (Zero CSS transition conflicts, 100% hardware GPU translation) */} -
-
- {showcaseCards.map((card) => ( -
- {/* Card Top Metadata Bar (translateZ 30px) */} -
-
- - {card.index} - - - - {card.category} - -
-
- - {card.latency} - -
+ {/* Panoramic Native Scroll Filmstrip (100% GPU-accelerated, Zero Lag, Native Touch & Drag) */} +
+ {showcaseCards.map((card, idx) => { + const isActive = activeIndex === idx; + return ( +
+ {/* Card Header Metadata Bar */} +
+
+ + {card.index} + + + + {card.category} +
- {/* 3D Cinematic Comparison Viewport (autoSlide false to save CPU/GPU cycles during horizontal pan) */} -
- -
- - {/* Card 3D Stereoscopic Typography Stack */} -
- {/* Headline at translateZ 45px with 3D Chiseled Extrusion */} -

- {card.title} -

- - {/* Description at translateZ 25px */} -

- {card.description} -

- - {/* Specs Chips at translateZ 35px */} -
- {card.specs.map((spec, i) => ( - - ✓ {spec} - - ))} -
- - {/* Actions at translateZ 50px */} -
- - Launch Interactive Studio - - - - - - {card.appName} - -
+
+ + {card.model} + + + {card.latency} +
- ))} + + {/* Interactive Comparison Viewport */} +
+ +
+ + {/* Card Editorial Content & Specifications */} +
+
+

+ {card.title} +

+ + {card.tagline} + +
+ +

+ {card.description} +

+ + {/* Specs Chips */} +
+ {card.specs.map((spec, i) => ( + + ✓ {spec} + + ))} +
+ + {/* Direct Action Links */} +
+ + Launch Online Studio + + + + + + {card.appName} + +
+
+
+ ); + })} +
+ + {/* Bottom Progress Bar Indicator */} +
+
+
+
-
- {/* Bottom Cinematic Control & Progress Rail */} -
-
- {/* Visual Progress Bar Track */} -
-
-
- - {/* Model Metadata Tags */} -
- ARCHIVE: VOL. 26 - • - NEURAL VISION ACCELERATOR -
+
+ MODEL {activeIndex + 1} OF {showcaseCards.length} + • + SWIPE OR DRAG TO EXPLORE