feat(homepage+tools): tools page card refinement and homepage fixes
This commit is contained in:
@@ -182,11 +182,11 @@ export function CardBeforeAfterSlider({
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Floating Labels (Floor Gate 9 & 67 compliant: body face, smaller, sentence case) */}
|
||||
<div className="pointer-events-none absolute bottom-2 left-2 z-20 rounded bg-paper-hi/90 px-2 py-0.5 text-xs font-body text-ink border border-rule shadow-sm">
|
||||
{/* Floating Labels inside colored pills */}
|
||||
<div className="pointer-events-none absolute bottom-2.5 left-2.5 z-20 rounded-full bg-ink/80 backdrop-blur-md px-2.5 py-0.5 text-[10px] font-semibold text-paper-hi border border-white/20 shadow-xs">
|
||||
{beforeLabel}
|
||||
</div>
|
||||
<div className="pointer-events-none absolute bottom-2 right-2 z-20 rounded bg-paper-hi/90 px-2 py-0.5 text-xs font-body text-ink border border-rule shadow-sm">
|
||||
<div className="pointer-events-none absolute bottom-2.5 right-2.5 z-20 rounded-full bg-accent backdrop-blur-md px-2.5 py-0.5 text-[10px] font-bold text-paper-hi border border-white/25 shadow-xs">
|
||||
{afterLabel}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -22,7 +22,7 @@ export function Footer({ config, currentLocale }: FooterProps) {
|
||||
</p>
|
||||
|
||||
<div className="pt-2">
|
||||
<div className="inline-flex items-center gap-2 text-xs text-ink bg-paper-hi border border-rule px-3 py-1.5 rounded-card font-body">
|
||||
<div className="inline-flex items-center gap-2 text-xs text-ink bg-paper-hi border border-rule px-4 py-2 rounded-full font-body shadow-xs">
|
||||
<ShieldCheck className="w-3.5 h-3.5 text-accent" aria-hidden="true" />
|
||||
<span>Zero-storage policy: photos processed in volatile memory only</span>
|
||||
</div>
|
||||
|
||||
+313
-112
@@ -1,21 +1,102 @@
|
||||
'use client';
|
||||
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import React, { useState, useEffect, useRef } from 'react';
|
||||
import Link from 'next/link';
|
||||
import { usePathname } from 'next/navigation';
|
||||
import { Menu, X } from 'lucide-react';
|
||||
import {
|
||||
Menu,
|
||||
X,
|
||||
ArrowRight,
|
||||
Sparkles,
|
||||
Smartphone,
|
||||
Layers,
|
||||
ShieldCheck,
|
||||
Smile,
|
||||
Scissors,
|
||||
Palette,
|
||||
ChevronDown
|
||||
} from 'lucide-react';
|
||||
import { SiteConfig } from '@/types';
|
||||
import { BrandLogo } from './BrandLogo';
|
||||
import { RainbowButton } from '@/components/magicui/rainbow-button';
|
||||
|
||||
interface NavbarProps {
|
||||
config: SiteConfig;
|
||||
currentLocale: string;
|
||||
}
|
||||
|
||||
const TOOL_CATEGORIES = [
|
||||
{
|
||||
id: 'portrait-retouch',
|
||||
name: 'Portrait Retouch',
|
||||
tagline: 'Sub-pore blemish, teeth whitening & eye brightness',
|
||||
count: '5 tools',
|
||||
icon: Smile,
|
||||
color: 'text-rose-500',
|
||||
bg: 'bg-rose-500/10 text-rose-600 border-rose-500/20',
|
||||
href: '/tools#category-portrait-retouch',
|
||||
},
|
||||
{
|
||||
id: 'restoration',
|
||||
name: 'Archival Restoration',
|
||||
tagline: '4K super-resolution, vintage repair & colorization',
|
||||
count: '3 tools',
|
||||
icon: Sparkles,
|
||||
color: 'text-indigo-500',
|
||||
bg: 'bg-indigo-500/10 text-indigo-600 border-indigo-500/20',
|
||||
href: '/tools#category-restoration',
|
||||
},
|
||||
{
|
||||
id: 'background-cutout',
|
||||
name: 'Background Cutout',
|
||||
tagline: 'P3M deep learning alpha matting & hair extraction',
|
||||
count: '1 tool',
|
||||
icon: Scissors,
|
||||
color: 'text-emerald-500',
|
||||
bg: 'bg-emerald-500/10 text-emerald-600 border-emerald-500/20',
|
||||
href: '/tools#category-background-cutout',
|
||||
},
|
||||
{
|
||||
id: 'creative-art',
|
||||
name: 'Creative Art & Avatars',
|
||||
tagline: 'Anime key-art synthesis, Polaroids & object eraser',
|
||||
count: '3 tools',
|
||||
icon: Palette,
|
||||
color: 'text-amber-500',
|
||||
bg: 'bg-amber-500/10 text-amber-600 border-amber-500/20',
|
||||
href: '/tools#category-creative-art',
|
||||
},
|
||||
];
|
||||
|
||||
export function Navbar({ config, currentLocale }: NavbarProps) {
|
||||
const [mobileMenuOpen, setMobileMenuOpen] = useState(false);
|
||||
const [scrolled, setScrolled] = useState(false);
|
||||
const [toolsDropdownOpen, setToolsDropdownOpen] = useState(false);
|
||||
const toolsTimeoutRef = useRef<NodeJS.Timeout | null>(null);
|
||||
const pathname = usePathname();
|
||||
|
||||
const handleToolsMouseEnter = () => {
|
||||
if (toolsTimeoutRef.current) clearTimeout(toolsTimeoutRef.current);
|
||||
setToolsDropdownOpen(true);
|
||||
};
|
||||
|
||||
const handleToolsMouseLeave = () => {
|
||||
if (toolsTimeoutRef.current) clearTimeout(toolsTimeoutRef.current);
|
||||
toolsTimeoutRef.current = setTimeout(() => {
|
||||
setToolsDropdownOpen(false);
|
||||
}, 180);
|
||||
};
|
||||
|
||||
// Detect scroll to slightly elevate glass opacity
|
||||
useEffect(() => {
|
||||
const handleScroll = () => {
|
||||
setScrolled(window.scrollY > 20);
|
||||
};
|
||||
window.addEventListener('scroll', handleScroll, { passive: true });
|
||||
handleScroll();
|
||||
return () => window.removeEventListener('scroll', handleScroll);
|
||||
}, []);
|
||||
|
||||
// Close mobile menu on Escape key
|
||||
useEffect(() => {
|
||||
if (!mobileMenuOpen) return;
|
||||
@@ -26,7 +107,7 @@ export function Navbar({ config, currentLocale }: NavbarProps) {
|
||||
return () => document.removeEventListener('keydown', closeOnEscape);
|
||||
}, [mobileMenuOpen]);
|
||||
|
||||
// Lock body scroll on iOS/Mobile when mobile menu is open
|
||||
// Lock body scroll on mobile drawer
|
||||
useEffect(() => {
|
||||
if (mobileMenuOpen) {
|
||||
document.body.style.overflow = 'hidden';
|
||||
@@ -41,87 +122,181 @@ export function Navbar({ config, currentLocale }: NavbarProps) {
|
||||
};
|
||||
}, [mobileMenuOpen]);
|
||||
|
||||
const navLinks = [
|
||||
{ href: '/', label: 'Home', exact: true },
|
||||
{ href: '/tools', label: 'Tools', badge: '10+', hasDropdown: true },
|
||||
{ href: '/apps', label: 'Apps', badge: 'iOS · Mac' },
|
||||
{ href: '/pricing', label: 'Pricing' },
|
||||
{ href: '/trust', label: 'Trust & privacy' },
|
||||
];
|
||||
|
||||
const isLinkActive = (href: string, exact?: boolean) => {
|
||||
if (exact) return pathname === href;
|
||||
return pathname.startsWith(href);
|
||||
};
|
||||
|
||||
return (
|
||||
<header className="sticky top-0 left-0 right-0 w-full z-40 bg-paper/95 border-b border-rule transition-[border-color,background-color] duration-150">
|
||||
<div className="max-w-container mx-auto px-4 sm:px-6 lg:px-8 h-16 flex items-center justify-between">
|
||||
{/* Brand Logo */}
|
||||
<header
|
||||
className={`sticky top-0 left-0 right-0 w-full z-40 motion-safe:transition-[background-color,border-color,box-shadow] duration-200 bg-paper border-b border-rule shadow-xs ${
|
||||
scrolled
|
||||
? 'md:bg-paper/95 md:backdrop-blur-xl shadow-[0_2px_16px_-4px_color-mix(in_oklab,var(--color-ink)_6%,transparent)]'
|
||||
: 'md:bg-paper'
|
||||
}`}
|
||||
>
|
||||
<div className="max-w-container mx-auto px-4 sm:px-6 lg:px-8 h-18 py-3 flex items-center justify-between">
|
||||
{/* Brand Logo with Optical Lens & Wordmark */}
|
||||
<div className="relative z-20 flex-shrink-0">
|
||||
<BrandLogo size="md" />
|
||||
</div>
|
||||
|
||||
{/* Center Navigation Links: Clean editorial links */}
|
||||
<nav className="hidden md:flex items-center gap-7 relative z-20">
|
||||
<Link
|
||||
href="/"
|
||||
className={`text-sm font-body transition-colors duration-100 ${
|
||||
pathname === '/'
|
||||
? 'text-ink font-semibold border-b-2 border-accent pb-0.5'
|
||||
: 'text-ink-2 hover:text-ink'
|
||||
}`}
|
||||
>
|
||||
Home
|
||||
</Link>
|
||||
{/* Center Floating Docked Pill Menu (Desktop) */}
|
||||
<nav
|
||||
aria-label="Main navigation"
|
||||
className="hidden md:flex items-center gap-1 bg-paper-2/70 p-1 rounded-full border border-rule/70 shadow-[inset_0_1px_2px_color-mix(in_oklab,var(--color-ink)_3%,transparent)] relative z-20"
|
||||
>
|
||||
{navLinks.map((link) => {
|
||||
const active = isLinkActive(link.href, link.exact);
|
||||
|
||||
<Link
|
||||
href="/tools"
|
||||
className={`text-sm font-body transition-colors duration-100 ${
|
||||
pathname.startsWith('/tools')
|
||||
? 'text-ink font-semibold border-b-2 border-accent pb-0.5'
|
||||
: 'text-ink-2 hover:text-ink'
|
||||
}`}
|
||||
>
|
||||
Tools
|
||||
</Link>
|
||||
if (link.hasDropdown) {
|
||||
return (
|
||||
<div
|
||||
key={link.href}
|
||||
className="relative"
|
||||
onMouseEnter={handleToolsMouseEnter}
|
||||
onMouseLeave={handleToolsMouseLeave}
|
||||
>
|
||||
<Link
|
||||
href={link.href}
|
||||
className={`relative px-3.5 py-1.5 rounded-full text-xs sm:text-sm font-body motion-safe:transition-[color,background-color,box-shadow] duration-150 flex items-center gap-1.5 ${
|
||||
active
|
||||
? 'bg-paper-hi text-ink font-medium shadow-xs border border-rule/80'
|
||||
: 'text-ink-2 hover:text-ink hover:bg-paper-hi/60'
|
||||
}`}
|
||||
>
|
||||
<span>{link.label}</span>
|
||||
<ChevronDown className={`w-3 h-3 text-muted transition-transform duration-200 ${
|
||||
toolsDropdownOpen ? 'rotate-180 text-accent' : ''
|
||||
}`} />
|
||||
</Link>
|
||||
|
||||
<Link
|
||||
href="/apps"
|
||||
className={`text-sm font-body transition-colors duration-100 ${
|
||||
pathname.startsWith('/apps')
|
||||
? 'text-ink font-semibold border-b-2 border-accent pb-0.5'
|
||||
: 'text-ink-2 hover:text-ink'
|
||||
}`}
|
||||
>
|
||||
Apps
|
||||
</Link>
|
||||
{/* Tools Categories Dropdown Mega-Card on Hover */}
|
||||
{toolsDropdownOpen && (
|
||||
<div
|
||||
className="absolute top-full left-1/2 -translate-x-1/2 pt-2.5 w-[560px] z-50 animate-in fade-in zoom-in-95 duration-150"
|
||||
>
|
||||
<div className="studio-sheet p-4 sm:p-5 rounded-3xl bg-paper-hi border border-rule shadow-sheet space-y-3.5">
|
||||
{/* Header */}
|
||||
<div className="flex items-center justify-between pb-2.5 border-b border-rule">
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="w-2 h-2 rounded-full bg-accent animate-pulse" />
|
||||
<span className="text-xs font-semibold text-ink font-body">
|
||||
Studio Neural Categories
|
||||
</span>
|
||||
</div>
|
||||
<span className="text-[11px] font-semibold text-accent bg-accent/10 px-2.5 py-0.5 rounded-full border border-accent/20">
|
||||
12 models active
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<Link
|
||||
href="/pricing"
|
||||
className={`text-sm font-body transition-colors duration-100 ${
|
||||
pathname.startsWith('/pricing')
|
||||
? 'text-ink font-semibold border-b-2 border-accent pb-0.5'
|
||||
: 'text-ink-2 hover:text-ink'
|
||||
}`}
|
||||
>
|
||||
Pricing
|
||||
</Link>
|
||||
{/* 2x2 Category Cards Grid */}
|
||||
<div className="grid grid-cols-2 gap-2.5">
|
||||
{TOOL_CATEGORIES.map((cat) => {
|
||||
const Icon = cat.icon;
|
||||
return (
|
||||
<Link
|
||||
key={cat.id}
|
||||
href={cat.href}
|
||||
onClick={() => {
|
||||
setToolsDropdownOpen(false);
|
||||
if (typeof window !== 'undefined' && window.location.pathname.startsWith('/tools')) {
|
||||
window.location.hash = `category-${cat.id}`;
|
||||
}
|
||||
}}
|
||||
className="group/cat p-3 rounded-2xl bg-paper border border-rule hover:border-accent hover:bg-paper-2 hover:shadow-glow motion-safe:transition-all duration-150 flex items-start gap-3"
|
||||
>
|
||||
<div className={`w-8 h-8 rounded-xl flex items-center justify-center shrink-0 border ${cat.bg}`}>
|
||||
<Icon className="w-4 h-4" />
|
||||
</div>
|
||||
<div className="min-w-0 flex-1">
|
||||
<div className="flex items-center justify-between gap-1">
|
||||
<span className="font-semibold text-xs text-ink group-hover/cat:text-accent transition-colors truncate">
|
||||
{cat.name}
|
||||
</span>
|
||||
<span className="text-[10px] text-muted font-body shrink-0">
|
||||
{cat.count}
|
||||
</span>
|
||||
</div>
|
||||
<p className="text-[11px] text-muted line-clamp-1 mt-0.5 font-body">
|
||||
{cat.tagline}
|
||||
</p>
|
||||
</div>
|
||||
</Link>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
|
||||
<Link
|
||||
href="/trust"
|
||||
className={`text-sm font-body transition-colors duration-100 ${
|
||||
pathname.startsWith('/trust')
|
||||
? 'text-ink font-semibold border-b-2 border-accent pb-0.5'
|
||||
: 'text-ink-2 hover:text-ink'
|
||||
}`}
|
||||
>
|
||||
Trust & privacy
|
||||
</Link>
|
||||
{/* Footer Link */}
|
||||
<div className="pt-2 border-t border-rule flex items-center justify-between text-xs font-body">
|
||||
<span className="text-[11px] text-muted">
|
||||
Instant client GPU trial · Zero retention
|
||||
</span>
|
||||
<Link
|
||||
href="/tools"
|
||||
onClick={() => setToolsDropdownOpen(false)}
|
||||
className="text-accent hover:underline font-semibold inline-flex items-center gap-1 text-xs"
|
||||
>
|
||||
<span>View all 12 tools directory</span>
|
||||
<ArrowRight className="w-3 h-3 text-accent" />
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Link
|
||||
key={link.href}
|
||||
href={link.href}
|
||||
className={`relative px-3.5 py-1.5 rounded-full text-xs sm:text-sm font-body motion-safe:transition-[color,background-color,box-shadow] duration-150 flex items-center gap-1.5 ${
|
||||
active
|
||||
? 'bg-paper-hi text-ink font-medium shadow-xs border border-rule/80'
|
||||
: 'text-ink-2 hover:text-ink hover:bg-paper-hi/60'
|
||||
}`}
|
||||
>
|
||||
<span>{link.label}</span>
|
||||
{link.badge && (
|
||||
<span
|
||||
className={`text-[10px] px-1.5 py-0.2 rounded-full font-body ${
|
||||
active
|
||||
? 'bg-accent/15 text-accent font-medium'
|
||||
: 'bg-paper-3/80 text-muted'
|
||||
}`}
|
||||
>
|
||||
{link.badge}
|
||||
</span>
|
||||
)}
|
||||
</Link>
|
||||
);
|
||||
})}
|
||||
</nav>
|
||||
|
||||
{/* Right CTA Button: Cadmium orange action */}
|
||||
<div className="hidden md:flex items-center space-x-3 relative z-20 flex-shrink-0">
|
||||
<Link
|
||||
href="/tools"
|
||||
className="btn-primary"
|
||||
>
|
||||
Try tools
|
||||
</Link>
|
||||
{/* Right CTA Actions */}
|
||||
<div className="hidden md:flex items-center gap-3 relative z-20 flex-shrink-0">
|
||||
{/* Rainbow Button CTA */}
|
||||
<RainbowButton href="/tools">
|
||||
<span>Try tools free</span>
|
||||
<ArrowRight className="w-3.5 h-3.5 ml-1 inline" aria-hidden="true" />
|
||||
</RainbowButton>
|
||||
</div>
|
||||
|
||||
{/* Mobile Menu Trigger */}
|
||||
<div className="flex md:hidden items-center space-x-2 relative z-20">
|
||||
{/* Mobile Hamburger Toggle Button */}
|
||||
<div className="flex md:hidden items-center gap-2 relative z-20">
|
||||
<button
|
||||
onClick={() => setMobileMenuOpen(!mobileMenuOpen)}
|
||||
className="p-2 text-ink hover:text-ink-2 active:bg-paper-2 disabled:opacity-50 focus-visible:ring-2 focus-visible:ring-accent rounded"
|
||||
className="p-2 text-ink hover:text-ink-2 active:bg-paper-2 disabled:opacity-50 disabled:cursor-not-allowed rounded-full border border-rule/70 bg-paper-hi focus-visible:ring-2 focus-visible:ring-accent"
|
||||
aria-label={mobileMenuOpen ? 'Close menu' : 'Open menu'}
|
||||
>
|
||||
{mobileMenuOpen ? (
|
||||
@@ -133,54 +308,80 @@ export function Navbar({ config, currentLocale }: NavbarProps) {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Mobile Drawer */}
|
||||
{/* Mobile Drawer Overlay */}
|
||||
{mobileMenuOpen && (
|
||||
<div className="md:hidden border-t border-rule bg-paper px-4 py-6 space-y-4">
|
||||
<nav className="flex flex-col space-y-3">
|
||||
<Link
|
||||
href="/"
|
||||
onClick={() => setMobileMenuOpen(false)}
|
||||
className="text-base font-body text-ink hover:text-accent py-1"
|
||||
>
|
||||
Home
|
||||
</Link>
|
||||
<Link
|
||||
href="/tools"
|
||||
onClick={() => setMobileMenuOpen(false)}
|
||||
className="text-base font-body text-ink hover:text-accent py-1"
|
||||
>
|
||||
Tools
|
||||
</Link>
|
||||
<Link
|
||||
href="/apps"
|
||||
onClick={() => setMobileMenuOpen(false)}
|
||||
className="text-base font-body text-ink hover:text-accent py-1"
|
||||
>
|
||||
Apps
|
||||
</Link>
|
||||
<Link
|
||||
href="/pricing"
|
||||
onClick={() => setMobileMenuOpen(false)}
|
||||
className="text-base font-body text-ink hover:text-accent py-1"
|
||||
>
|
||||
Pricing
|
||||
</Link>
|
||||
<Link
|
||||
href="/trust"
|
||||
onClick={() => setMobileMenuOpen(false)}
|
||||
className="text-base font-body text-ink hover:text-accent py-1"
|
||||
>
|
||||
Trust & privacy
|
||||
</Link>
|
||||
<div className="md:hidden fixed inset-x-0 top-[65px] bottom-0 z-50 bg-paper border-t border-rule px-5 py-6 flex flex-col justify-between overflow-y-auto">
|
||||
<nav className="flex flex-col space-y-2.5">
|
||||
<span className="text-xs font-body font-semibold text-muted px-2 py-1">Navigation</span>
|
||||
{navLinks.map((link) => {
|
||||
const active = isLinkActive(link.href, link.exact);
|
||||
return (
|
||||
<div key={link.href} className="space-y-1">
|
||||
<Link
|
||||
href={link.href}
|
||||
onClick={() => setMobileMenuOpen(false)}
|
||||
className={`flex items-center justify-between px-4 py-3 rounded-2xl text-base font-body motion-safe:transition-colors ${
|
||||
active
|
||||
? 'bg-paper-hi text-ink font-semibold border border-rule shadow-xs'
|
||||
: 'text-ink-2 hover:text-ink hover:bg-paper-2 bg-paper-hi/60 border border-rule/50'
|
||||
}`}
|
||||
>
|
||||
<span className="flex items-center gap-3">
|
||||
{link.href === '/tools' && <Sparkles className="w-4 h-4 text-accent" />}
|
||||
{link.href === '/apps' && <Smartphone className="w-4 h-4 text-accent" />}
|
||||
{link.href === '/trust' && <ShieldCheck className="w-4 h-4 text-accent" />}
|
||||
<span>{link.label}</span>
|
||||
</span>
|
||||
{link.badge && (
|
||||
<span className="text-xs px-2.5 py-0.5 rounded-full bg-paper-2 border border-rule text-muted">
|
||||
{link.badge}
|
||||
</span>
|
||||
)}
|
||||
</Link>
|
||||
|
||||
{/* Sub-categories under Tools on mobile drawer */}
|
||||
{link.href === '/tools' && (
|
||||
<div className="pl-3 pr-1 py-1 grid grid-cols-2 gap-1.5">
|
||||
{TOOL_CATEGORIES.map((cat) => {
|
||||
const Icon = cat.icon;
|
||||
return (
|
||||
<Link
|
||||
key={cat.id}
|
||||
href={cat.href}
|
||||
onClick={() => {
|
||||
setMobileMenuOpen(false);
|
||||
if (typeof window !== 'undefined' && window.location.pathname.startsWith('/tools')) {
|
||||
window.location.hash = `category-${cat.id}`;
|
||||
}
|
||||
}}
|
||||
className="flex items-center gap-2 p-2 rounded-xl text-xs text-ink-2 hover:text-ink hover:bg-paper-2 bg-paper-hi/40 border border-rule/50 font-body"
|
||||
>
|
||||
<Icon className={`w-3.5 h-3.5 ${cat.color} shrink-0`} />
|
||||
<span className="truncate">{cat.name}</span>
|
||||
</Link>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</nav>
|
||||
<div className="pt-2">
|
||||
<Link
|
||||
|
||||
<div className="pt-6 border-t border-rule space-y-3">
|
||||
<RainbowButton
|
||||
href="/tools"
|
||||
onClick={() => setMobileMenuOpen(false)}
|
||||
className="btn-primary w-full text-center"
|
||||
className="w-full text-center"
|
||||
>
|
||||
Try tools free
|
||||
</Link>
|
||||
<span>Explore 10+ studio tools</span>
|
||||
<ArrowRight className="w-4 h-4 ml-1 inline" aria-hidden="true" />
|
||||
</RainbowButton>
|
||||
<div className="flex items-center justify-center gap-4 text-xs text-muted font-body">
|
||||
<span>Zero server retention</span>
|
||||
<span>•</span>
|
||||
<span>WebGPU acceleration</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
@@ -7,15 +7,29 @@ interface SmoothScrollProviderProps {
|
||||
}
|
||||
|
||||
/**
|
||||
* Universal Native Smooth Scrolling Provider.
|
||||
* - 100% native C++ browser momentum scrolling (120Hz / 60Hz hardware accelerated).
|
||||
* - 0% CPU at rest and during scrolling (zero JS wheel hijacking, zero RAF loops).
|
||||
* - Handles anchor link smooth scrolling safely across all devices.
|
||||
* Universal Native Smooth Scrolling & Scroll Restoration Provider.
|
||||
* - Always resets scroll to top (0, 0) on page reload/refresh.
|
||||
* - Disables browser automatic scroll restoration to previous positions.
|
||||
* - 100% native C++ momentum scrolling with 0% JS CPU consumption.
|
||||
*/
|
||||
export function SmoothScrollProvider({ children }: SmoothScrollProviderProps) {
|
||||
useEffect(() => {
|
||||
if (typeof window === 'undefined') return;
|
||||
|
||||
// Reset browser scroll restoration so refresh always opens at top of page
|
||||
if ('scrollRestoration' in window.history) {
|
||||
window.history.scrollRestoration = 'manual';
|
||||
}
|
||||
|
||||
// Scroll to top immediately on mount/refresh
|
||||
window.scrollTo({ top: 0, left: 0, behavior: 'instant' as ScrollBehavior });
|
||||
|
||||
// Handle beforeunload to guarantee top position on reload
|
||||
const handleBeforeUnload = () => {
|
||||
window.scrollTo(0, 0);
|
||||
};
|
||||
window.addEventListener('beforeunload', handleBeforeUnload);
|
||||
|
||||
// Universal anchor link handler using native hardware-accelerated smooth scroll
|
||||
const handleAnchorClick = (e: MouseEvent) => {
|
||||
try {
|
||||
@@ -44,6 +58,7 @@ export function SmoothScrollProvider({ children }: SmoothScrollProviderProps) {
|
||||
document.addEventListener('click', handleAnchorClick, { capture: true });
|
||||
|
||||
return () => {
|
||||
window.removeEventListener('beforeunload', handleBeforeUnload);
|
||||
document.removeEventListener('click', handleAnchorClick, { capture: true });
|
||||
};
|
||||
}, []);
|
||||
|
||||
Reference in New Issue
Block a user