fix(performance): eliminate device thermal throttling and remove expand icon from trendy bento
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
'use client';
|
||||
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import React from 'react';
|
||||
import {
|
||||
Sparkles,
|
||||
Wand2,
|
||||
@@ -103,15 +103,6 @@ export function HowItWorks3DSection({
|
||||
// Card 1: Upload Your Picture (Super Warm & Visual)
|
||||
// -------------------------------------------------------------
|
||||
function StepUploadCard() {
|
||||
const [bounce, setBounce] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
const timer = setInterval(() => {
|
||||
setBounce((prev) => !prev);
|
||||
}, 2000);
|
||||
return () => clearInterval(timer);
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div className="group relative flex flex-col justify-between rounded-[36px] bg-white border border-slate-200/90 p-7 shadow-cream-sm hover:shadow-cream-lg transition-all duration-300 hover:-translate-y-1.5 hover:border-blue-400/60">
|
||||
<div>
|
||||
@@ -127,12 +118,8 @@ function StepUploadCard() {
|
||||
<div className="relative w-full h-[230px] rounded-3xl bg-gradient-to-b from-blue-50/70 to-indigo-50/40 border border-blue-100 overflow-hidden flex flex-col items-center justify-center p-4 select-none">
|
||||
{/* Animated floating dashed dropzone */}
|
||||
<div className="w-full h-full border-2 border-dashed border-blue-300/80 rounded-2xl flex flex-col items-center justify-center p-4 relative">
|
||||
{/* Playful Floating Photo Frame */}
|
||||
<div
|
||||
className={`w-36 h-28 rounded-2xl bg-white shadow-xl border-2 border-white overflow-hidden p-1.5 transition-transform duration-700 ${
|
||||
bounce ? 'translate-y-0 rotate-1 scale-105' : '-translate-y-2 -rotate-2 scale-100'
|
||||
}`}
|
||||
>
|
||||
{/* Playful Floating Photo Frame (GPU-composited CSS float, 0% JS overhead) */}
|
||||
<div className="w-36 h-28 rounded-2xl bg-white shadow-xl border-2 border-white overflow-hidden p-1.5 animate-float-slow transform-gpu">
|
||||
<img
|
||||
src="/management/pages/home/sections/how-it-works/media/before.jpg"
|
||||
alt="Your Photo"
|
||||
@@ -185,15 +172,6 @@ function StepUploadCard() {
|
||||
// Card 2: The Magic Happens (Playful & Magical)
|
||||
// -------------------------------------------------------------
|
||||
function StepMagicCard() {
|
||||
const [sparkleRot, setSparkleRot] = useState(0);
|
||||
|
||||
useEffect(() => {
|
||||
const interval = setInterval(() => {
|
||||
setSparkleRot((prev) => (prev + 30) % 360);
|
||||
}, 250);
|
||||
return () => clearInterval(interval);
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div className="group relative flex flex-col justify-between rounded-[36px] bg-white border border-slate-200/90 p-7 shadow-cream-sm hover:shadow-cream-lg transition-all duration-300 hover:-translate-y-1.5 hover:border-amber-400/60">
|
||||
<div>
|
||||
@@ -216,10 +194,10 @@ function StepMagicCard() {
|
||||
<Wand2 className="w-10 h-10 text-amber-500 animate-bounce" />
|
||||
</div>
|
||||
|
||||
{/* Orbiting Stars & Sparkles */}
|
||||
{/* Orbiting Stars & Sparkles (Pure CSS 60/120fps hardware rotation - 0% JS intervals!) */}
|
||||
<div
|
||||
className="absolute inset-[-20px] pointer-events-none transition-transform duration-300"
|
||||
style={{ transform: `rotate(${sparkleRot}deg)` }}
|
||||
className="absolute inset-[-20px] pointer-events-none animate-spin"
|
||||
style={{ animationDuration: '8s' }}
|
||||
>
|
||||
<span className="absolute top-0 left-1/2 -translate-x-1/2 text-amber-400 text-base">✨</span>
|
||||
<span className="absolute bottom-0 left-1/2 -translate-x-1/2 text-purple-400 text-sm">⭐</span>
|
||||
|
||||
@@ -288,15 +288,47 @@ function ToolWindowMedia({ item, isHovered }: { item: ToolMediaItem; isHovered:
|
||||
}
|
||||
}, []);
|
||||
|
||||
// Continuous Autoplay Muted Loop (Plays all the time on phones and desktop without requiring hover)
|
||||
// Continuous Autoplay Muted Loop when visible in viewport
|
||||
// Pauses automatically when scrolled out of view or tab is hidden to save GPU/battery and eliminate device heating
|
||||
useEffect(() => {
|
||||
if (item.mediaType === 'video' && videoRef.current) {
|
||||
const video = videoRef.current;
|
||||
video.muted = true;
|
||||
video.defaultMuted = true;
|
||||
video.playsInline = true;
|
||||
video.play().catch(() => {});
|
||||
}
|
||||
if (item.mediaType !== 'video') return;
|
||||
const video = videoRef.current;
|
||||
if (!video) return;
|
||||
|
||||
video.muted = true;
|
||||
video.defaultMuted = true;
|
||||
video.playsInline = true;
|
||||
|
||||
let isIntersecting = false;
|
||||
|
||||
const updatePlayState = () => {
|
||||
if (isIntersecting && !document.hidden) {
|
||||
video.play().catch(() => {});
|
||||
} else {
|
||||
video.pause();
|
||||
}
|
||||
};
|
||||
|
||||
const observer = new IntersectionObserver(
|
||||
([entry]) => {
|
||||
isIntersecting = entry.isIntersecting;
|
||||
updatePlayState();
|
||||
},
|
||||
{ threshold: 0.05 }
|
||||
);
|
||||
|
||||
observer.observe(video);
|
||||
|
||||
const handleVisibility = () => {
|
||||
updatePlayState();
|
||||
};
|
||||
document.addEventListener('visibilitychange', handleVisibility);
|
||||
|
||||
return () => {
|
||||
observer.disconnect();
|
||||
document.removeEventListener('visibilitychange', handleVisibility);
|
||||
video.pause();
|
||||
};
|
||||
}, [item.mediaType]);
|
||||
|
||||
// When unhovered, reset slider smoothly to 50%
|
||||
|
||||
@@ -11,8 +11,6 @@ import {
|
||||
SunMedium,
|
||||
Layers,
|
||||
ArrowRight,
|
||||
Maximize2,
|
||||
Minimize2,
|
||||
GripHorizontal,
|
||||
Smile,
|
||||
Camera,
|
||||
@@ -40,7 +38,6 @@ interface TileItem {
|
||||
badge: string;
|
||||
icon: React.ElementType;
|
||||
imageUrl: string;
|
||||
isWide?: boolean;
|
||||
}
|
||||
|
||||
const CATEGORIES: { id: EffectCategory; label: string }[] = [
|
||||
@@ -170,24 +167,13 @@ export function TrendyBentoSection({
|
||||
subtitle = 'Discover our collection of viral AI effects. Tap any category to explore specialized tools.',
|
||||
}: TrendyBentoSectionProps) {
|
||||
const [activeCategory, setActiveCategory] = useState<EffectCategory>('all');
|
||||
const [tiles, setTiles] = useState<TileItem[]>(INITIAL_TILES);
|
||||
const tiles = INITIAL_TILES;
|
||||
|
||||
// Filtered tiles based on category
|
||||
const displayedTiles = activeCategory === 'all'
|
||||
? tiles
|
||||
: tiles.filter((t) => t.category === activeCategory);
|
||||
|
||||
// Toggle individual tile width (1x1 to 2x1)
|
||||
const toggleTileSize = (id: string, e: React.MouseEvent) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
setTiles((prev) =>
|
||||
prev.map((tile) =>
|
||||
tile.id === id ? { ...tile, isWide: !tile.isWide } : tile
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<section id="trendy-effects" className="py-14 sm:py-20 px-4 sm:px-6 md:px-8 lg:px-10 bg-[#FAF8F5] relative overflow-hidden border-t border-slate-900/[0.06]">
|
||||
{/* Symbolic Elemental Ambient Background Animation */}
|
||||
@@ -252,9 +238,7 @@ export function TrendyBentoSection({
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-6">
|
||||
{displayedTiles.map((tile) => {
|
||||
const Icon = tile.icon;
|
||||
const tileClasses = tile.isWide
|
||||
? 'col-span-1 sm:col-span-2 aspect-[16/9] sm:aspect-[2/1] rounded-[36px] sm:rounded-[42px]'
|
||||
: 'col-span-1 aspect-square rounded-[36px] sm:rounded-[42px]';
|
||||
const tileClasses = 'col-span-1 aspect-square rounded-[36px] sm:rounded-[42px]';
|
||||
|
||||
return (
|
||||
<Link
|
||||
@@ -279,25 +263,11 @@ export function TrendyBentoSection({
|
||||
{/* Vignette Overlay for Readability (GPU Opacity) */}
|
||||
<div className="absolute inset-0 bg-gradient-to-t from-slate-950/90 via-slate-950/30 to-slate-950/20 opacity-100 group-hover:opacity-85 transition-opacity duration-500 ease-[cubic-bezier(0.16,1,0.3,1)] pointer-events-none" />
|
||||
|
||||
{/* Top Tile Bar: Badge and Quick-Settings Resize Button */}
|
||||
{/* Top Tile Bar: Badge */}
|
||||
<div className="relative z-20 flex items-center justify-between p-5">
|
||||
<span className="px-3 py-1 rounded-full text-[10px] font-mono font-bold tracking-wider uppercase bg-black/60 backdrop-blur-md text-cyan-400 border border-cyan-500/30 shadow-sm">
|
||||
{tile.badge}
|
||||
</span>
|
||||
|
||||
{/* Android Quick Settings Size Toggle Button (1x1 to 2x1) */}
|
||||
<button
|
||||
type="button"
|
||||
onClick={(e) => toggleTileSize(tile.id, e)}
|
||||
title={tile.isWide ? 'Shrink tile' : 'Expand tile'}
|
||||
className="w-9 h-9 rounded-2xl bg-white/90 hover:bg-white text-slate-800 shadow-md flex items-center justify-center transition-[transform,background-color] duration-200 ease-[cubic-bezier(0.16,1,0.3,1)] hover:scale-110 active:scale-95 z-30"
|
||||
>
|
||||
{tile.isWide ? (
|
||||
<Minimize2 className="w-4 h-4 text-blue-600" />
|
||||
) : (
|
||||
<Maximize2 className="w-4 h-4 text-blue-600" />
|
||||
)}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* Bottom Tile Info & Link */}
|
||||
|
||||
Reference in New Issue
Block a user