Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions src/pages/events/Events.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import styles from "./Events.module.scss";
import BackButton from "../components/backButton/BackButton";
import { navContext } from "../../App";
import EventHouse from "../components/eventHouse/EventHouse";
import { isTouchDevice } from "../../utils/debounce";

gsap.registerPlugin(ScrollTrigger);

Expand Down Expand Up @@ -86,6 +87,7 @@ export default function Events() {
const timelineRef = useRef<HTMLDivElement>(null);
const progressRef = useRef<HTMLDivElement>(null);
const cardRefs = useRef<(HTMLDivElement | null)[]>([]);
const isMobile = isTouchDevice();

useGSAP(() => {
if (!bgRef.current || !containerRef.current) return;
Expand Down Expand Up @@ -152,7 +154,7 @@ export default function Events() {

{/* Environmental Animation Layer - Sakura & Lanterns */}
<div className={styles.particleContainer}>
{[...Array(25)].map((_, i) => (
{[...Array(isMobile ? 10 : 25)].map((_, i) => (
<div
key={`sakura-${i}`}
className={styles.sakura}
Expand All @@ -167,7 +169,7 @@ export default function Events() {
/>
))}

{[...Array(6)].map((_, i) => (
{[...Array(isMobile ? 2 : 6)].map((_, i) => (
<div
key={`lantern-${i}`}
className={styles.driftingLantern}
Expand Down
31 changes: 18 additions & 13 deletions src/pages/invasion/Invasion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import gsap from "gsap";
import { useGSAP } from "@gsap/react";
import EventLayout from "../components/eventLayout/EventLayout";
import styles from "./SamuraiBackground.module.scss";
import { isTouchDevice } from "../../utils/debounce";

const SamuraiBackground = () => {
const containerRef = useRef<HTMLDivElement>(null);
Expand All @@ -22,6 +23,8 @@ const SamuraiBackground = () => {
},
});

const isMobile = isTouchDevice();

// Function to create drifting particles (petals, embers, ash)
const createParticles = (className: string, count: number, direction: 'up' | 'down') => {
for (let i = 0; i < count; i++) {
Expand Down Expand Up @@ -72,21 +75,23 @@ const SamuraiBackground = () => {
};

// Create different particle types
createParticles(styles.petal, 20, 'down'); // Falling petals
createParticles(styles.ember, 40, 'up'); // More rising embers
createParticles(styles.ash, 60, 'up'); // Doubled ash count
createParticles(styles.petal, isMobile ? 8 : 20, 'down'); // Falling petals
createParticles(styles.ember, isMobile ? 15 : 40, 'up'); // More rising embers
createParticles(styles.ash, isMobile ? 20 : 60, 'up'); // Doubled ash count

// Add a flickering effect specifically for embers
const embers = particlesRef.current?.querySelectorAll(`.${styles.ember}`);
embers?.forEach(ember => {
gsap.to(ember, {
opacity: 0.4,
repeat: -1,
yoyo: true,
duration: 0.2 + Math.random() * 0.3,
ease: "sine.inOut"
// Add a flickering effect specifically for embers (skip on mobile to save CPU)
if (!isMobile) {
const embers = particlesRef.current?.querySelectorAll(`.${styles.ember}`);
embers?.forEach(ember => {
gsap.to(ember, {
opacity: 0.4,
repeat: -1,
yoyo: true,
duration: 0.2 + Math.random() * 0.3,
ease: "sine.inOut"
});
});
});
}

}, { scope: containerRef });

Expand Down
21 changes: 16 additions & 5 deletions src/pages/landingRevamp/LandingRevamp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import useOverlayStore from "../../utils/store";
import Lenis from "lenis";
import { gsap } from "gsap";
import { ScrollTrigger } from "gsap/ScrollTrigger";
import { isTouchDevice } from "../../utils/debounce";

const Navbar = lazy(() => import("../components/navbar/Navbar"));
const MainHam = lazy(() => import("../components/mainHam/mainHam"));
Expand Down Expand Up @@ -289,12 +290,13 @@ export default function LandingRevamp({
return () => cancelAnimationFrame(rafIdRef.current);
}, []);

// ─── Canvas resize (DPR capped at 2) ──────────────────────────────────────
// ─── Canvas resize (DPR capped at 1 on mobile, 2 on desktop) ─────────────
useEffect(() => {
const handleResize = () => {
const canvas = canvasRef.current;
if (!canvas) return;
const dpr = Math.min(window.devicePixelRatio || 1, 2);
const isMobile = window.innerWidth < 768;
const dpr = isMobile ? 1 : Math.min(window.devicePixelRatio || 1, 2);
canvas.width = window.innerWidth * dpr;
canvas.height = window.innerHeight * dpr;
Comment on lines +298 to 301

Copilot AI Mar 25, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The DPR cap uses window.innerWidth < 768 to decide β€œmobile”, which excludes many iPads/tablets (often >= 768px wide). If the goal is to reduce canvas GPU memory on iPad too, consider basing the DPR cap on isTouchDevice() (or a max pixel budget) instead of only viewport width so tablets don’t still allocate at DPR 2.

Copilot uses AI. Check for mistakes.
drawFrame(Math.round(currentFrameRef.current));
Expand All @@ -306,21 +308,30 @@ export default function LandingRevamp({

// ─── Lenis smooth scroll ──────────────────────────────────────────────────
useEffect(() => {
// Disable Lenis on touch/mobile devices β€” native scroll is sufficient
// and smooth scroll adds significant CPU overhead that can crash mobile browsers.
if (isTouchDevice()) return;

lenisRef.current = new Lenis({
duration: 1.8,
easing: (t) => Math.min(1, 1.001 - Math.pow(2, -10 * t)),
smoothWheel: true,
wheelMultiplier: 1.5,
});

let lenisRafId: number;
const raf = (time: number) => {
lenisRef.current?.raf(time);
requestAnimationFrame(raf);
lenisRafId = requestAnimationFrame(raf);
};
requestAnimationFrame(raf);
lenisRafId = requestAnimationFrame(raf);

lenisRef.current.on("scroll", ScrollTrigger.update);

return () => lenisRef.current?.destroy();
return () => {
cancelAnimationFrame(lenisRafId);
lenisRef.current?.destroy();
};
}, []);

// ─── Scroll listener ─────────────────────────────────────────────────────
Expand Down
9 changes: 8 additions & 1 deletion src/utils/debounce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,11 @@ const debouncedHandler = (callback: () => void, period: number) => {
};
}

export default debouncedHandler;
export default debouncedHandler;

/**
* Returns true when the device is a touch-primary device (phone/tablet).
* Evaluated once per call β€” callers should cache the result where needed.
*/
export const isTouchDevice = (): boolean =>
window.matchMedia("(hover: none) and (pointer: coarse)").matches;
Comment on lines +17 to +18

Copilot AI Mar 25, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isTouchDevice() assumes window.matchMedia is always available. This will throw in non-browser contexts (SSR, some test runners) or if matchMedia is missing. Add a typeof window !== "undefined" / typeof window.matchMedia === "function" guard and a safe fallback (e.g., navigator.maxTouchPoints > 0) so callers can use it without crashing.

Suggested change
export const isTouchDevice = (): boolean =>
window.matchMedia("(hover: none) and (pointer: coarse)").matches;
export const isTouchDevice = (): boolean => {
// Guard against non-browser environments (SSR, some test runners)
if (typeof window === "undefined") {
return false;
}
// Prefer navigator.maxTouchPoints when available
if (typeof navigator !== "undefined" && typeof navigator.maxTouchPoints === "number") {
if (navigator.maxTouchPoints > 0) {
return true;
}
}
// Fallback to matchMedia when supported
if (typeof window.matchMedia === "function") {
try {
return window.matchMedia("(hover: none) and (pointer: coarse)").matches;
} catch {
// If matchMedia throws for any reason, fall through to default
}
}
// Conservative default when we cannot reliably detect touch capability
return false;
};

Copilot uses AI. Check for mistakes.
Loading