Initialisation newer version
This commit is contained in:
@@ -0,0 +1,193 @@
|
||||
.card-nav-container {
|
||||
position: absolute;
|
||||
top: 2em;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
width: 90%;
|
||||
max-width: 800px;
|
||||
z-index: 99;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.card-nav {
|
||||
display: block;
|
||||
height: 60px;
|
||||
padding: 0;
|
||||
background-color: var(--clr-surface);
|
||||
border: 1px solid var(--clr-border);
|
||||
color: var(--clr-text);
|
||||
border-radius: var(--radius);
|
||||
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
will-change: height;
|
||||
}
|
||||
|
||||
.card-nav-top {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
height: 60px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 0.5rem 0.8rem; /* Ajusté pour laisser de la place */
|
||||
z-index: 2;
|
||||
}
|
||||
|
||||
/* --- HAMBURGER --- */
|
||||
.hamburger-menu {
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
cursor: pointer;
|
||||
gap: 6px;
|
||||
color: var(--clr-text);
|
||||
width: 40px;
|
||||
}
|
||||
|
||||
.hamburger-menu:hover .hamburger-line {
|
||||
opacity: 0.75;
|
||||
}
|
||||
|
||||
.hamburger-line {
|
||||
width: 24px;
|
||||
height: 2px;
|
||||
background-color: currentColor;
|
||||
transition:
|
||||
transform 0.25s ease,
|
||||
opacity 0.2s ease;
|
||||
transform-origin: 50% 50%;
|
||||
}
|
||||
|
||||
.hamburger-menu.open .hamburger-line:first-child {
|
||||
transform: translateY(4px) rotate(45deg);
|
||||
}
|
||||
|
||||
.hamburger-menu.open .hamburger-line:last-child {
|
||||
transform: translateY(-4px) rotate(-45deg);
|
||||
}
|
||||
|
||||
/* --- CENTRE : TITRE --- */
|
||||
.center-title-container {
|
||||
position: absolute;
|
||||
left: 50%;
|
||||
top: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
pointer-events: none; /* Laisse cliquer au travers si besoin */
|
||||
}
|
||||
|
||||
.site-title {
|
||||
/* Ou ta font perso */
|
||||
font-weight: 700;
|
||||
font-size: 1.2rem;
|
||||
letter-spacing: -0.02em;
|
||||
color: var(--clr-text);
|
||||
transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
|
||||
cursor: default;
|
||||
pointer-events: auto;
|
||||
}
|
||||
|
||||
/* Animation Hover Titre */
|
||||
.site-title:hover {
|
||||
transform: scale(1.05);
|
||||
color: var(--clr-accent); /* Petit bonus : change de couleur au survol */
|
||||
}
|
||||
|
||||
/* --- DROITE : LOGO BOUTON --- */
|
||||
.right-logo-btn {
|
||||
height: 100%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: transparent;
|
||||
border: none;
|
||||
padding: 0 0.5rem;
|
||||
cursor: pointer;
|
||||
text-decoration: none;
|
||||
transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
|
||||
}
|
||||
|
||||
.nav-logo-img {
|
||||
height: 36px;
|
||||
width: auto;
|
||||
display: block;
|
||||
}
|
||||
|
||||
/* Animation Hover Logo */
|
||||
.right-logo-btn:hover {
|
||||
transform: scale(1.15);
|
||||
}
|
||||
|
||||
/* --- CONTENU DU MENU --- */
|
||||
.card-nav-content {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
right: 0;
|
||||
top: 60px;
|
||||
bottom: 0;
|
||||
padding: 0;
|
||||
display: block;
|
||||
visibility: hidden;
|
||||
pointer-events: none;
|
||||
z-index: 1;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.card-nav.open .card-nav-content {
|
||||
visibility: visible;
|
||||
pointer-events: auto;
|
||||
}
|
||||
|
||||
/* --- MOBILE --- */
|
||||
@media (max-width: 768px) {
|
||||
.card-nav-container {
|
||||
width: 95%;
|
||||
top: 1em;
|
||||
}
|
||||
|
||||
.card-nav-top {
|
||||
padding: 0.5rem 1rem;
|
||||
}
|
||||
|
||||
.center-title-container {
|
||||
position: static;
|
||||
transform: none;
|
||||
flex-grow: 1;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.site-title {
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
.right-logo-btn {
|
||||
padding-right: 0;
|
||||
}
|
||||
|
||||
.nav-logo-img {
|
||||
height: 28px;
|
||||
}
|
||||
|
||||
.card-nav-content {
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
gap: 8px;
|
||||
padding: 0.5rem;
|
||||
bottom: 0;
|
||||
justify-content: flex-start;
|
||||
}
|
||||
|
||||
.nav-card {
|
||||
height: auto;
|
||||
min-height: 80px;
|
||||
flex: 1 1 auto;
|
||||
max-height: none;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,202 @@
|
||||
import { useLayoutEffect, useRef, useState, useCallback, useMemo } from "react";
|
||||
import { Link, useNavigate, useLocation } from "react-router-dom";
|
||||
import { gsap } from "gsap";
|
||||
import InfiniteMenu from "./InfiniteMenu";
|
||||
import Lanyard from "./Lanyard";
|
||||
import "./CardNav.css";
|
||||
|
||||
const CardNav = ({
|
||||
logo = "/images/logo.png",
|
||||
logoAlt = "Esiah Logo",
|
||||
className = "",
|
||||
ease = "power3.out",
|
||||
}) => {
|
||||
const [isHamburgerOpen, setIsHamburgerOpen] = useState(false);
|
||||
const [isExpanded, setIsExpanded] = useState(false);
|
||||
const [showLanyard, setShowLanyard] = useState(false);
|
||||
const navRef = useRef(null);
|
||||
const tlRef = useRef(null);
|
||||
const location = useLocation();
|
||||
|
||||
const navigate = useNavigate();
|
||||
const handleCardClick = (link) => {
|
||||
if (!link) return;
|
||||
const cleanLink = link.replace("_blank", "").trim();
|
||||
if (link.includes("_blank") || cleanLink.startsWith("http")) {
|
||||
window.open(cleanLink, "_blank", "noopener,noreferrer");
|
||||
} else {
|
||||
navigate(cleanLink);
|
||||
}
|
||||
toggleMenu();
|
||||
};
|
||||
|
||||
const handleCohaiseClick = () => {
|
||||
if (location.pathname === "/cohaise") {
|
||||
setShowLanyard(true);
|
||||
setTimeout(() => setShowLanyard(false), 5000);
|
||||
}
|
||||
};
|
||||
|
||||
const menuItems = useMemo(() => {
|
||||
if (location.pathname.startsWith("/projects")) {
|
||||
return [
|
||||
{
|
||||
image: "/images/Projects.png",
|
||||
link: "/projects",
|
||||
title: "All my Projects",
|
||||
description: "To discover all my creations",
|
||||
},
|
||||
{
|
||||
image: "/images/NTR.png",
|
||||
link: "/projects/neo-tokyo-rush",
|
||||
title: "Neo Tokyo Rush",
|
||||
description: "Cyberpunk-inspired beat 'em All game",
|
||||
},
|
||||
{
|
||||
image: "/images/PortfolioE1.png",
|
||||
link: "https://portfolio-xesiahs-projects.vercel.app/",
|
||||
title: "Protfolio 2024",
|
||||
description: "Portfolio that gathers all my first year's projects",
|
||||
},
|
||||
{
|
||||
image: "/images/MC.png",
|
||||
link: "_blank https://metzcampus.fr/",
|
||||
title: "Metz Campus",
|
||||
description:
|
||||
"Website crafted for the Metz Campus organization during my first-year internship.",
|
||||
},
|
||||
{
|
||||
image: "/images/Zatyshok.png",
|
||||
link: "/projects/zatyshok",
|
||||
title: "Затишок",
|
||||
description: "Moodboard application",
|
||||
},
|
||||
{
|
||||
image: "/images/SPRotD.png",
|
||||
link: "/projects/shadow-purge-rite-of-the-demon",
|
||||
title: "Shadow Purge - Rite of the Demon",
|
||||
description: "Hack n'slash RPG",
|
||||
},
|
||||
{
|
||||
image: "/images/EotLS.png",
|
||||
link: "/projects/echoes-of-the-last-stop",
|
||||
title: "Echoes of the Last Stop",
|
||||
description: "Thriller game project in collaboration with my partner",
|
||||
},
|
||||
];
|
||||
}
|
||||
return [
|
||||
{
|
||||
image: "/images/Projects.png",
|
||||
link: "/projects",
|
||||
title: "All my Projects",
|
||||
description: "To discover all my creations",
|
||||
},
|
||||
{
|
||||
image: "/images/Contact.jpg",
|
||||
link: "/contact",
|
||||
title: "Contact",
|
||||
description: "Any requests? Feel free to reach out!",
|
||||
},
|
||||
{
|
||||
image: "/images/Cohaise.jpg",
|
||||
link: "/cohaise",
|
||||
title: "Co Hai Se",
|
||||
description: "About us",
|
||||
},
|
||||
];
|
||||
}, [location.pathname]);
|
||||
|
||||
const calculateHeight = useCallback(() => {
|
||||
return window.matchMedia("(max-width: 768px)").matches
|
||||
? window.innerHeight - 40
|
||||
: 600;
|
||||
}, []);
|
||||
|
||||
const createTimeline = useCallback(() => {
|
||||
const navEl = navRef.current;
|
||||
if (!navEl) return null;
|
||||
gsap.set(navEl, { height: 60, overflow: "hidden" });
|
||||
const tl = gsap.timeline({ paused: true });
|
||||
tl.to(navEl, { height: calculateHeight, duration: 0.5, ease: ease });
|
||||
return tl;
|
||||
}, [calculateHeight, ease]);
|
||||
|
||||
useLayoutEffect(() => {
|
||||
const tl = createTimeline();
|
||||
tlRef.current = tl;
|
||||
return () => tl?.kill();
|
||||
}, [createTimeline]);
|
||||
|
||||
const toggleMenu = () => {
|
||||
const tl = tlRef.current;
|
||||
if (!tl) return;
|
||||
if (!isExpanded) {
|
||||
setIsHamburgerOpen(true);
|
||||
setIsExpanded(true);
|
||||
tl.play();
|
||||
} else {
|
||||
setIsHamburgerOpen(false);
|
||||
tl.reverse();
|
||||
tl.eventCallback("onReverseComplete", () => setIsExpanded(false));
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className={`card-nav-container ${className}`}>
|
||||
<nav ref={navRef} className={`card-nav ${isExpanded ? "open" : ""}`}>
|
||||
<div className="card-nav-top">
|
||||
<div
|
||||
className={`hamburger-menu cursor-target ${isHamburgerOpen ? "open" : ""}`}
|
||||
onClick={toggleMenu}
|
||||
role="button"
|
||||
tabIndex={0}
|
||||
>
|
||||
<div className="hamburger-line" />
|
||||
<div className="hamburger-line" />
|
||||
</div>
|
||||
|
||||
<div className="center-title-container">
|
||||
<Link to="/" className="site-title cursor-target">
|
||||
Esiah's Universe
|
||||
</Link>
|
||||
</div>
|
||||
|
||||
<Link
|
||||
to="/cohaise"
|
||||
onClick={handleCohaiseClick}
|
||||
className="right-logo-btn cursor-target"
|
||||
>
|
||||
<img
|
||||
src={logo}
|
||||
alt={logoAlt}
|
||||
className="nav-logo-img"
|
||||
onError={(e) => {
|
||||
e.target.style.display = "none";
|
||||
}}
|
||||
/>
|
||||
</Link>
|
||||
</div>
|
||||
|
||||
<div
|
||||
className="card-nav-content"
|
||||
style={{
|
||||
opacity: isExpanded || isHamburgerOpen ? 1 : 0,
|
||||
transition: "opacity 0.3s ease 0.1s",
|
||||
}}
|
||||
>
|
||||
<InfiniteMenu
|
||||
items={menuItems}
|
||||
scale={0.8}
|
||||
onClose={toggleMenu}
|
||||
onItemClick={handleCardClick}
|
||||
/>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<Lanyard show={showLanyard} />
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default CardNav;
|
||||
@@ -0,0 +1,200 @@
|
||||
:root {
|
||||
--border-subtle: rgba(255, 255, 255, 0.15);
|
||||
--text-dim: rgba(255, 255, 255, 0.5);
|
||||
}
|
||||
|
||||
/* 1. CONFIGURATION LAYOUT & POINTER EVENTS */
|
||||
.menu-wrap {
|
||||
width: 100vw;
|
||||
margin-left: calc(-50vw + 50%); /* Full width hack */
|
||||
margin-right: calc(-50vw + 50%);
|
||||
margin-top: 8rem;
|
||||
margin-bottom: 8rem;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
position: relative;
|
||||
left: 0;
|
||||
will-change: height;
|
||||
/* CRUCIAL : La souris passe à travers pour atteindre le background (parallaxe) */
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.menu {
|
||||
width: 100%;
|
||||
max-width: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding: 0;
|
||||
/* CRUCIAL : La souris passe à travers */
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.menu__item {
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
border-top: 1px solid var(--border-subtle);
|
||||
transition: background-color 0.4s ease;
|
||||
/* CRUCIAL : La souris passe à travers */
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.menu__item:last-child {
|
||||
border-bottom: 1px solid var(--border-subtle);
|
||||
}
|
||||
|
||||
/* 2. ÉLÉMENTS INTERACTIFS (On réactive la souris) */
|
||||
.menu__item-link {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
height: 140px;
|
||||
padding: 0 4vw;
|
||||
position: relative;
|
||||
z-index: 2;
|
||||
cursor: pointer;
|
||||
text-decoration: none;
|
||||
font-weight: 300;
|
||||
font-size: clamp(2rem, 4vw, 3.5rem);
|
||||
letter-spacing: -1px;
|
||||
color: #fff;
|
||||
transition: all 0.5s cubic-bezier(0.23, 1, 0.32, 1);
|
||||
pointer-events: auto;
|
||||
}
|
||||
|
||||
.menu__item-link.link-active {
|
||||
background-color: #0808083b;
|
||||
backdrop-filter: blur(10px);
|
||||
border-left: 4px solid var(--accent-red);
|
||||
padding-left: 5vw;
|
||||
}
|
||||
|
||||
.menu__item-link:hover {
|
||||
padding-left: 6vw;
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
/* --- ACCORDÉON (DETAILS) --- */
|
||||
.service-details-wrapper {
|
||||
width: 100%;
|
||||
background-color: rgba(0, 0, 0, 0.4);
|
||||
border-bottom: 1px solid var(--border-subtle);
|
||||
min-height: 0;
|
||||
pointer-events: auto;
|
||||
}
|
||||
|
||||
.details-inner {
|
||||
padding: 4rem 4vw;
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 2fr;
|
||||
gap: 4rem;
|
||||
align-items: start;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.details-inner {
|
||||
grid-template-columns: 1fr;
|
||||
gap: 2rem;
|
||||
}
|
||||
}
|
||||
|
||||
.service-detail-content h3 {
|
||||
font-size: 1.5rem;
|
||||
font-weight: 400;
|
||||
color: #fff;
|
||||
margin-bottom: 1.5rem;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 2px;
|
||||
opacity: 0.8;
|
||||
}
|
||||
|
||||
.service-detail-content p {
|
||||
color: var(--text-dim);
|
||||
font-size: 1.2rem;
|
||||
line-height: 1.6;
|
||||
max-width: 800px;
|
||||
}
|
||||
|
||||
.service-detail-content ul {
|
||||
display: flex;
|
||||
gap: 1rem;
|
||||
margin-top: 3rem;
|
||||
padding: 0;
|
||||
list-style: none;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.service-detail-content li {
|
||||
padding: 10px 24px;
|
||||
border: 1px solid var(--border-subtle);
|
||||
border-radius: 50px;
|
||||
font-size: 0.9rem;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 1px;
|
||||
color: #fff;
|
||||
background: transparent;
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
.service-detail-content li:hover {
|
||||
background: #fff;
|
||||
color: #000;
|
||||
border-color: #fff;
|
||||
}
|
||||
|
||||
/* --- MARQUEE --- */
|
||||
.marquee {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
pointer-events: none;
|
||||
|
||||
/* CORRECTIF FILTRE : Plus clair (0.4) pour plus de légèreté */
|
||||
background: rgba(10, 10, 10, 0.4);
|
||||
backdrop-filter: blur(6px);
|
||||
|
||||
transform: translate3d(0, 101%, 0);
|
||||
border-bottom: 1px solid rgba(255, 255, 255, 0.3);
|
||||
}
|
||||
|
||||
.marquee__inner-wrap {
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.marquee__inner {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
position: relative;
|
||||
height: 100%;
|
||||
width: fit-content; /* Laisse le contenu s'étendre */
|
||||
will-change: transform;
|
||||
flex-wrap: nowrap;
|
||||
}
|
||||
|
||||
.marquee__part {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-shrink: 0; /* Empêche l'écrasement */
|
||||
padding-right: 4vw;
|
||||
}
|
||||
|
||||
.marquee span {
|
||||
font-size: clamp(2rem, 4vw, 3.5rem);
|
||||
font-weight: 300;
|
||||
padding: 0 2vw;
|
||||
color: rgba(255, 255, 255, 0.6);
|
||||
}
|
||||
|
||||
.marquee__img {
|
||||
width: 350px;
|
||||
height: 100px;
|
||||
margin: 0 3vw;
|
||||
border-radius: 4px;
|
||||
filter: grayscale(100%) contrast(1.2);
|
||||
opacity: 0.8;
|
||||
background-size: cover;
|
||||
background-position: center;
|
||||
}
|
||||
@@ -0,0 +1,201 @@
|
||||
/* eslint-disable no-unused-vars */
|
||||
import { useRef, useEffect, useState } from "react";
|
||||
import { gsap } from "gsap";
|
||||
import "./FlowingMenu.css";
|
||||
import { ScrollToPlugin } from "gsap/ScrollToPlugin";
|
||||
gsap.registerPlugin(ScrollToPlugin);
|
||||
|
||||
function FlowingMenu({
|
||||
items = [],
|
||||
speed = 15,
|
||||
textColor = "#fff",
|
||||
bgColor = "transparent",
|
||||
marqueeBgColor = "rgba(0,0,0,0.8)", // Sera écrasé par le CSS pour le glassmorphism
|
||||
marqueeTextColor = "#fff",
|
||||
borderColor = "rgba(255,255,255,0.1)",
|
||||
}) {
|
||||
const [activeIdx, setActiveIdx] = useState(null);
|
||||
|
||||
const toggleItem = (idx) => {
|
||||
setActiveIdx(activeIdx === idx ? null : idx);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="menu-wrap" style={{ backgroundColor: bgColor }}>
|
||||
<nav className="menu">
|
||||
{items.map((item, idx) => (
|
||||
<MenuItem
|
||||
key={idx}
|
||||
{...item}
|
||||
isOpen={activeIdx === idx}
|
||||
onClick={() => toggleItem(idx)}
|
||||
speed={speed}
|
||||
textColor={textColor}
|
||||
marqueeBgColor={marqueeBgColor}
|
||||
marqueeTextColor={marqueeTextColor}
|
||||
borderColor={borderColor}
|
||||
/>
|
||||
))}
|
||||
</nav>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function MenuItem({
|
||||
text,
|
||||
image,
|
||||
speed,
|
||||
textColor,
|
||||
marqueeBgColor,
|
||||
marqueeTextColor,
|
||||
borderColor,
|
||||
isOpen,
|
||||
onClick,
|
||||
Component,
|
||||
}) {
|
||||
const itemRef = useRef(null);
|
||||
const marqueeRef = useRef(null);
|
||||
const marqueeInnerRef = useRef(null);
|
||||
const contentRef = useRef(null);
|
||||
|
||||
const [repetitions, setRepetitions] = useState(2);
|
||||
|
||||
useEffect(() => {
|
||||
const calculateRepetitions = () => {
|
||||
if (!marqueeInnerRef.current) return;
|
||||
|
||||
const singlePart =
|
||||
marqueeInnerRef.current.querySelector(".marquee__part");
|
||||
if (!singlePart) return;
|
||||
|
||||
const partWidth = singlePart.offsetWidth;
|
||||
const windowWidth = window.innerWidth;
|
||||
|
||||
if (partWidth > 0) {
|
||||
const needed = Math.ceil(windowWidth / partWidth) + 4;
|
||||
setRepetitions(needed);
|
||||
}
|
||||
};
|
||||
|
||||
calculateRepetitions();
|
||||
window.addEventListener("resize", calculateRepetitions);
|
||||
return () => window.removeEventListener("resize", calculateRepetitions);
|
||||
}, [text]);
|
||||
|
||||
useEffect(() => {
|
||||
const marqueeContent =
|
||||
marqueeInnerRef.current?.querySelector(".marquee__part");
|
||||
if (!marqueeContent) return;
|
||||
|
||||
const contentWidth = marqueeContent.offsetWidth;
|
||||
if (contentWidth === 0) return;
|
||||
|
||||
const tl = gsap.to(marqueeInnerRef.current, {
|
||||
x: -contentWidth,
|
||||
duration: speed,
|
||||
ease: "none",
|
||||
repeat: -1,
|
||||
});
|
||||
|
||||
return () => tl.kill();
|
||||
}, [speed, repetitions]);
|
||||
|
||||
useEffect(() => {
|
||||
if (isOpen) {
|
||||
gsap.to(contentRef.current, {
|
||||
height: "auto",
|
||||
opacity: 1,
|
||||
duration: 0.6,
|
||||
ease: "power3.out",
|
||||
});
|
||||
gsap.to(window, {
|
||||
duration: 1,
|
||||
delay: 0.4,
|
||||
scrollTo: {
|
||||
y: itemRef.current,
|
||||
offsetY: 60,
|
||||
autoKill: true,
|
||||
},
|
||||
ease: "power3.inOut",
|
||||
});
|
||||
|
||||
gsap.to(marqueeRef.current, {
|
||||
y: "101%",
|
||||
duration: 0.4,
|
||||
ease: "power2.out",
|
||||
});
|
||||
} else {
|
||||
gsap.to(contentRef.current, {
|
||||
height: 0,
|
||||
opacity: 0,
|
||||
duration: 0.4,
|
||||
ease: "power3.in",
|
||||
});
|
||||
}
|
||||
}, [isOpen]);
|
||||
|
||||
const handleMouseEnter = () => {
|
||||
if (isOpen) return;
|
||||
|
||||
gsap.to(marqueeRef.current, { y: "0%", duration: 0.6, ease: "expo" });
|
||||
gsap.set(marqueeInnerRef.current, { force3D: true });
|
||||
};
|
||||
|
||||
const handleMouseLeave = () => {
|
||||
gsap.to(marqueeRef.current, { y: "101%", duration: 0.6, ease: "expo" });
|
||||
};
|
||||
|
||||
return (
|
||||
<div
|
||||
className={`menu__item ${isOpen ? "is-open" : ""}`}
|
||||
ref={itemRef}
|
||||
style={{ borderColor }}
|
||||
>
|
||||
<div
|
||||
className={`menu__item-link ${isOpen ? "link-active" : ""}`}
|
||||
onMouseEnter={handleMouseEnter}
|
||||
onMouseLeave={handleMouseLeave}
|
||||
onClick={onClick}
|
||||
>
|
||||
{text}
|
||||
</div>
|
||||
|
||||
{/* ZONE DÉTAILS */}
|
||||
<div
|
||||
className="service-details-wrapper"
|
||||
ref={contentRef}
|
||||
style={{ height: 0, overflow: "hidden", opacity: 0 }}
|
||||
>
|
||||
<div className="details-inner">{Component && <Component />}</div>
|
||||
</div>
|
||||
|
||||
{/* MARQUEE */}
|
||||
{/* Note : Le background est géré par le CSS pour le glassmorphism */}
|
||||
<div className="marquee" ref={marqueeRef}>
|
||||
<div className="marquee__inner-wrap">
|
||||
<div
|
||||
className="marquee__inner"
|
||||
ref={marqueeInnerRef}
|
||||
aria-hidden="true"
|
||||
>
|
||||
{[...Array(repetitions)].map((_, idx) => (
|
||||
<div
|
||||
className="marquee__part"
|
||||
key={idx}
|
||||
style={{ color: marqueeTextColor }}
|
||||
>
|
||||
<span>{text}</span>
|
||||
<div
|
||||
className="marquee__img"
|
||||
style={{ backgroundImage: `url(${image})` }}
|
||||
/>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default FlowingMenu;
|
||||
@@ -0,0 +1,161 @@
|
||||
/* src/components/InfiniteMenu.css */
|
||||
|
||||
#infinite-grid-menu-canvas {
|
||||
cursor: grab;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
outline: none;
|
||||
display: block;
|
||||
}
|
||||
|
||||
#infinite-grid-menu-canvas:active {
|
||||
cursor: grabbing;
|
||||
}
|
||||
|
||||
/* Conteneur pour centrer les éléments par dessus le canvas */
|
||||
.infinite-menu-overlay {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
pointer-events: none;
|
||||
z-index: 2;
|
||||
}
|
||||
.infinite-menu-overlay::before {
|
||||
content: "";
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
background: radial-gradient(
|
||||
circle at center,
|
||||
rgba(0, 0, 0, 0.4) 10%,
|
||||
transparent 70%
|
||||
);
|
||||
z-index: -1;
|
||||
pointer-events: none;
|
||||
transition: opacity 0.3s ease;
|
||||
}
|
||||
|
||||
.face-title.inactive ~ ::before {
|
||||
opacity: 0;
|
||||
}
|
||||
.action-button {
|
||||
position: absolute;
|
||||
left: 50%;
|
||||
bottom: 8%; /* Un peu plus bas pour laisser respirer le texte */
|
||||
z-index: 10;
|
||||
|
||||
/* Dimensions de la bannière */
|
||||
padding: 12px 32px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
|
||||
/* Style visuel */
|
||||
background: var(--clr-accent-600);
|
||||
border: 1px solid rgba(255, 255, 255, 0.3);
|
||||
border-radius: 40px; /* Forme pilule */
|
||||
cursor: pointer;
|
||||
|
||||
/* Animation d'entrée */
|
||||
transform: translateX(-50%) translateY(20px);
|
||||
opacity: 0;
|
||||
pointer-events: none;
|
||||
transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
|
||||
}
|
||||
|
||||
.action-button.active {
|
||||
transform: translateX(-50%) translateY(0);
|
||||
opacity: 1;
|
||||
pointer-events: auto;
|
||||
}
|
||||
|
||||
/* Texte à l'intérieur */
|
||||
.action-button-text {
|
||||
color: #fff;
|
||||
|
||||
font-weight: 600;
|
||||
font-size: 0.95rem;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 1px;
|
||||
}
|
||||
|
||||
.action-button-arrow {
|
||||
color: #fff;
|
||||
font-size: 1.2rem;
|
||||
transition: transform 0.3s ease;
|
||||
}
|
||||
|
||||
/* --- EFFET HOVER --- */
|
||||
.action-button:hover {
|
||||
background: #fff;
|
||||
box-shadow: 0 0 20px rgba(255, 255, 255, 0.4);
|
||||
}
|
||||
|
||||
.action-button:hover .action-button-text,
|
||||
.action-button:hover .action-button-arrow {
|
||||
color: var(--clr-accent-600);
|
||||
}
|
||||
|
||||
.action-button:hover .action-button-arrow {
|
||||
transform: translateX(5px);
|
||||
}
|
||||
|
||||
.action-button.inactive {
|
||||
opacity: 0;
|
||||
transform: translateX(-50%) translateY(10px) scale(0.9);
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.face-title {
|
||||
position: absolute;
|
||||
top: 40%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
|
||||
font-weight: 900;
|
||||
font-size: 3rem;
|
||||
color: #fff;
|
||||
text-shadow: 0 4px 10px rgba(0, 0, 0, 0.5);
|
||||
text-align: center;
|
||||
width: 100%;
|
||||
|
||||
opacity: 0;
|
||||
pointer-events: none;
|
||||
transition: 0.1s ease;
|
||||
}
|
||||
|
||||
.face-title.active {
|
||||
opacity: 1;
|
||||
pointer-events: auto;
|
||||
transition: 0.5s ease;
|
||||
}
|
||||
|
||||
.face-description {
|
||||
position: absolute;
|
||||
top: 55%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
font-size: 1rem;
|
||||
color: #ccc;
|
||||
text-align: center;
|
||||
max-width: 80%;
|
||||
|
||||
opacity: 0;
|
||||
pointer-events: none;
|
||||
transition: 0.1s ease;
|
||||
}
|
||||
|
||||
.face-description.active {
|
||||
opacity: 1;
|
||||
pointer-events: auto;
|
||||
transition: 0.5s ease;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.face-title {
|
||||
font-size: 2rem;
|
||||
}
|
||||
.face-description {
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,30 @@
|
||||
.lanyard-root-container {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100vw;
|
||||
height: 100vh;
|
||||
z-index: 99999;
|
||||
pointer-events: none;
|
||||
background: transparent;
|
||||
|
||||
/* Animation d'entrée douce */
|
||||
animation: lanyardFadeIn 0.8s ease-out forwards;
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
@keyframes lanyardFadeIn {
|
||||
from {
|
||||
opacity: 0;
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
.lanyard-root-container canvas {
|
||||
pointer-events: auto !important;
|
||||
display: block;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
@@ -0,0 +1,231 @@
|
||||
"use client";
|
||||
import {
|
||||
useRef,
|
||||
useState,
|
||||
useMemo,
|
||||
Suspense,
|
||||
useSyncExternalStore,
|
||||
} from "react";
|
||||
import { createPortal } from "react-dom";
|
||||
import { Canvas, extend, useFrame, useThree } from "@react-three/fiber";
|
||||
import {
|
||||
useGLTF,
|
||||
useTexture,
|
||||
Environment,
|
||||
Lightformer,
|
||||
} from "@react-three/drei";
|
||||
import {
|
||||
BallCollider,
|
||||
CuboidCollider,
|
||||
Physics,
|
||||
RigidBody,
|
||||
useRopeJoint,
|
||||
useSphericalJoint,
|
||||
} from "@react-three/rapier";
|
||||
import { MeshLineGeometry, MeshLineMaterial } from "meshline";
|
||||
import * as THREE from "three";
|
||||
|
||||
import "./Lanyard.css";
|
||||
|
||||
extend({ MeshLineGeometry, MeshLineMaterial });
|
||||
|
||||
// Détection propre du client (Standard React 19) pour éviter les erreurs ESLint
|
||||
const subscribe = () => () => {};
|
||||
function useIsClient() {
|
||||
return useSyncExternalStore(
|
||||
subscribe,
|
||||
() => true,
|
||||
() => false,
|
||||
);
|
||||
}
|
||||
|
||||
export default function Lanyard({ show, gravity = [0, -20, 0], fov = 20 }) {
|
||||
const isClient = useIsClient();
|
||||
if (!show || !isClient) return null;
|
||||
|
||||
return createPortal(
|
||||
<div className="lanyard-root-container">
|
||||
<Canvas
|
||||
camera={{ position: [0, 0, 20], fov }}
|
||||
gl={{ alpha: true, antialias: true }}
|
||||
onCreated={({ gl }) => gl.setClearColor(new THREE.Color(0x000000), 0)}
|
||||
>
|
||||
<Suspense fallback={null}>
|
||||
<Physics gravity={gravity} interpolate={true}>
|
||||
<Band />
|
||||
</Physics>
|
||||
</Suspense>
|
||||
<Environment blur={0.75}>
|
||||
<Lightformer
|
||||
intensity={10}
|
||||
color="white"
|
||||
position={[-10, 0, 14]}
|
||||
rotation={[0, Math.PI / 2, Math.PI / 3]}
|
||||
scale={[100, 10, 1]}
|
||||
/>
|
||||
</Environment>
|
||||
</Canvas>
|
||||
</div>,
|
||||
document.body,
|
||||
);
|
||||
}
|
||||
|
||||
function Band() {
|
||||
const { size } = useThree();
|
||||
const band = useRef(),
|
||||
fixed = useRef(),
|
||||
j1 = useRef(),
|
||||
j2 = useRef(),
|
||||
j3 = useRef(),
|
||||
card = useRef();
|
||||
const vec = new THREE.Vector3(),
|
||||
dir = new THREE.Vector3();
|
||||
|
||||
const { nodes, materials } = useGLTF("/3d/card.glb");
|
||||
|
||||
const texture = useTexture("/3d/lanyard.png", (t) => {
|
||||
t.wrapS = t.wrapT = THREE.RepeatWrapping;
|
||||
t.repeat.set(-4, 1);
|
||||
t.anisotropy = 16;
|
||||
});
|
||||
|
||||
const cardTexture = useTexture("/3d/badge_texture.png", (t) => {
|
||||
t.flipY = false;
|
||||
t.anisotropy = 16;
|
||||
});
|
||||
|
||||
const curve = useMemo(
|
||||
() =>
|
||||
new THREE.CatmullRomCurve3(
|
||||
new Array(4).fill(null).map(() => new THREE.Vector3()),
|
||||
),
|
||||
[],
|
||||
);
|
||||
const [dragged, drag] = useState(false);
|
||||
|
||||
// JOINTS PHYSIQUES
|
||||
useRopeJoint(fixed, j1, [[0, 0, 0], [0, 0, 0], 1.2]);
|
||||
useRopeJoint(j1, j2, [[0, 0, 0], [0, 0, 0], 1.2]);
|
||||
useRopeJoint(j2, j3, [[0, 0, 0], [0, 0, 0], 1.2]);
|
||||
|
||||
// CONNEXION PHYSIQUE : L'ancre j3 est soudée au haut du collider de la carte
|
||||
useSphericalJoint(j3, card, [
|
||||
[0, 0, 0],
|
||||
[0, 1.1, 0],
|
||||
]);
|
||||
|
||||
useFrame((state, delta) => {
|
||||
if (dragged) {
|
||||
vec.set(state.pointer.x, state.pointer.y, 0.5).unproject(state.camera);
|
||||
dir.copy(vec).sub(state.camera.position).normalize();
|
||||
vec.add(dir.multiplyScalar(state.camera.position.length()));
|
||||
[card, j1, j2, j3, fixed].forEach((ref) => ref.current?.wakeUp());
|
||||
card.current?.setNextKinematicTranslation({
|
||||
x: vec.x - dragged.x,
|
||||
y: vec.y - dragged.y,
|
||||
z: vec.z - dragged.z,
|
||||
});
|
||||
}
|
||||
|
||||
if (fixed.current) {
|
||||
[j1, j2].forEach((ref) => {
|
||||
if (!ref.current.lerped)
|
||||
ref.current.lerped = new THREE.Vector3().copy(
|
||||
ref.current.translation(),
|
||||
);
|
||||
ref.current.lerped.lerp(ref.current.translation(), delta * 20);
|
||||
});
|
||||
|
||||
const cardPos = card.current.translation();
|
||||
curve.points[0].set(cardPos.x, cardPos.y + 0.8, cardPos.z);
|
||||
curve.points[1].copy(j2.current.lerped);
|
||||
curve.points[2].copy(j1.current.lerped);
|
||||
curve.points[3].copy(fixed.current.translation());
|
||||
band.current.geometry.setPoints(curve.getPoints(32));
|
||||
}
|
||||
});
|
||||
|
||||
const physicsProps = {
|
||||
type: "dynamic",
|
||||
linearDamping: 4,
|
||||
angularDamping: 4,
|
||||
friction: 0.5,
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<group position={[4, 5, 0]}>
|
||||
<RigidBody ref={fixed} type="fixed" />
|
||||
<RigidBody position={[0, 2, 0]} ref={j1} {...physicsProps}>
|
||||
<BallCollider args={[0.1]} />
|
||||
</RigidBody>
|
||||
<RigidBody position={[0, 2, 0]} ref={j2} {...physicsProps}>
|
||||
<BallCollider args={[0.1]} />
|
||||
</RigidBody>
|
||||
<RigidBody position={[0, 2, 0]} ref={j3} {...physicsProps}>
|
||||
<BallCollider args={[0.1]} />
|
||||
</RigidBody>
|
||||
|
||||
<RigidBody
|
||||
ref={card}
|
||||
{...physicsProps}
|
||||
type={dragged ? "kinematicPosition" : "dynamic"}
|
||||
position={[0, 2, 0]}
|
||||
>
|
||||
<CuboidCollider args={[0.8, 1.125, 0.01]} />
|
||||
<group
|
||||
scale={2.25}
|
||||
position={[0, -1.2, 0]}
|
||||
onPointerDown={(e) => {
|
||||
e.target.setPointerCapture(e.pointerId);
|
||||
drag(
|
||||
new THREE.Vector3()
|
||||
.copy(e.point)
|
||||
.sub(vec.copy(card.current.translation())),
|
||||
);
|
||||
}}
|
||||
onPointerUp={(e) => (
|
||||
e.target.releasePointerCapture(e.pointerId),
|
||||
drag(false)
|
||||
)}
|
||||
>
|
||||
{/* renderOrder={2} : La carte passe DEVANT la lanière */}
|
||||
<mesh
|
||||
geometry={nodes.card.geometry}
|
||||
rotation={[Math.PI / 2, 0, 0]}
|
||||
renderOrder={2}
|
||||
>
|
||||
<meshPhysicalMaterial
|
||||
map={cardTexture}
|
||||
clearcoat={1}
|
||||
roughness={0.3}
|
||||
metalness={0.2}
|
||||
/>
|
||||
</mesh>
|
||||
{nodes.clip && (
|
||||
<mesh
|
||||
geometry={nodes.clip.geometry}
|
||||
material={materials.metal}
|
||||
renderOrder={2}
|
||||
/>
|
||||
)}
|
||||
</group>
|
||||
</RigidBody>
|
||||
</group>
|
||||
|
||||
{/* renderOrder={1} : Dessiné en premier (derrière) */}
|
||||
<mesh ref={band} renderOrder={1}>
|
||||
<meshLineGeometry />
|
||||
<meshLineMaterial
|
||||
transparent
|
||||
depthTest={false}
|
||||
resolution={[size.width, size.height]}
|
||||
useMap
|
||||
map={texture}
|
||||
repeat={[-4, 1]}
|
||||
lineWidth={1.2}
|
||||
/>
|
||||
</mesh>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,183 @@
|
||||
.logoloop {
|
||||
position: relative;
|
||||
|
||||
--logoloop-gap: 32px;
|
||||
--logoloop-logoHeight: 28px;
|
||||
--logoloop-fadeColorAuto: #ffffff;
|
||||
}
|
||||
|
||||
.logoloop--vertical {
|
||||
height: 100%;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.logoloop--scale-hover {
|
||||
padding-top: calc(var(--logoloop-logoHeight) * 0.1);
|
||||
padding-bottom: calc(var(--logoloop-logoHeight) * 0.1);
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
.logoloop {
|
||||
--logoloop-fadeColorAuto: #0b0b0b;
|
||||
}
|
||||
}
|
||||
|
||||
.logoloop__track {
|
||||
display: flex;
|
||||
width: max-content;
|
||||
will-change: transform;
|
||||
user-select: none;
|
||||
position: relative;
|
||||
z-index: 0;
|
||||
}
|
||||
|
||||
.logoloop--vertical .logoloop__track {
|
||||
flex-direction: column;
|
||||
height: max-content;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.logoloop__list {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.logoloop--vertical .logoloop__list {
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.logoloop__item {
|
||||
flex: 0 0 auto;
|
||||
margin-right: var(--logoloop-gap);
|
||||
font-size: var(--logoloop-logoHeight);
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.logoloop--vertical .logoloop__item {
|
||||
margin-right: 0;
|
||||
margin-bottom: var(--logoloop-gap);
|
||||
}
|
||||
|
||||
.logoloop__item:last-child {
|
||||
margin-right: var(--logoloop-gap);
|
||||
}
|
||||
|
||||
.logoloop--vertical .logoloop__item:last-child {
|
||||
margin-right: 0;
|
||||
margin-bottom: var(--logoloop-gap);
|
||||
}
|
||||
|
||||
.logoloop__node {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.logoloop__item img {
|
||||
height: var(--logoloop-logoHeight);
|
||||
width: auto;
|
||||
display: block;
|
||||
object-fit: contain;
|
||||
image-rendering: -webkit-optimize-contrast;
|
||||
-webkit-user-drag: none;
|
||||
pointer-events: none;
|
||||
transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
||||
}
|
||||
|
||||
.logoloop--scale-hover .logoloop__item {
|
||||
overflow: visible;
|
||||
}
|
||||
|
||||
.logoloop--scale-hover .logoloop__item:hover img,
|
||||
.logoloop--scale-hover .logoloop__item:hover .logoloop__node {
|
||||
transform: scale(1.2);
|
||||
transform-origin: center center;
|
||||
}
|
||||
|
||||
.logoloop--scale-hover .logoloop__node {
|
||||
transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
||||
}
|
||||
|
||||
.logoloop__link {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
text-decoration: none;
|
||||
border-radius: 4px;
|
||||
transition: opacity 0.2s ease;
|
||||
}
|
||||
|
||||
.logoloop__link:hover {
|
||||
opacity: 0.8;
|
||||
}
|
||||
|
||||
.logoloop__link:focus-visible {
|
||||
outline: 2px solid currentColor;
|
||||
outline-offset: 2px;
|
||||
}
|
||||
|
||||
.logoloop--fade::before,
|
||||
.logoloop--fade::after {
|
||||
content: "";
|
||||
position: absolute;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
width: clamp(24px, 8%, 120px);
|
||||
pointer-events: none;
|
||||
z-index: 10;
|
||||
}
|
||||
|
||||
.logoloop--fade::before {
|
||||
left: 0;
|
||||
background: linear-gradient(
|
||||
to right,
|
||||
var(--logoloop-fadeColor, var(--logoloop-fadeColorAuto)) 0%,
|
||||
rgba(0, 0, 0, 0) 100%
|
||||
);
|
||||
}
|
||||
|
||||
.logoloop--fade::after {
|
||||
right: 0;
|
||||
background: linear-gradient(
|
||||
to left,
|
||||
var(--logoloop-fadeColor, var(--logoloop-fadeColorAuto)) 0%,
|
||||
rgba(0, 0, 0, 0) 100%
|
||||
);
|
||||
}
|
||||
|
||||
.logoloop--vertical.logoloop--fade::before,
|
||||
.logoloop--vertical.logoloop--fade::after {
|
||||
left: 0;
|
||||
right: 0;
|
||||
width: 100%;
|
||||
height: clamp(24px, 8%, 120px);
|
||||
}
|
||||
|
||||
.logoloop--vertical.logoloop--fade::before {
|
||||
top: 0;
|
||||
bottom: auto;
|
||||
background: linear-gradient(
|
||||
to bottom,
|
||||
var(--logoloop-fadeColor, var(--logoloop-fadeColorAuto)) 0%,
|
||||
rgba(0, 0, 0, 0) 100%
|
||||
);
|
||||
}
|
||||
|
||||
.logoloop--vertical.logoloop--fade::after {
|
||||
bottom: 0;
|
||||
top: auto;
|
||||
background: linear-gradient(
|
||||
to top,
|
||||
var(--logoloop-fadeColor, var(--logoloop-fadeColorAuto)) 0%,
|
||||
rgba(0, 0, 0, 0) 100%
|
||||
);
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.logoloop__track {
|
||||
transform: translate3d(0, 0, 0) !important;
|
||||
}
|
||||
|
||||
.logoloop__item img,
|
||||
.logoloop__node {
|
||||
transition: none !important;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,382 @@
|
||||
import { useCallback, useEffect, useMemo, useRef, useState, memo } from "react";
|
||||
import "./LogoLoop.css";
|
||||
|
||||
const ANIMATION_CONFIG = { SMOOTH_TAU: 0.25, MIN_COPIES: 2, COPY_HEADROOM: 2 };
|
||||
|
||||
const toCssLength = (value) =>
|
||||
typeof value === "number" ? `${value}px` : (value ?? undefined);
|
||||
|
||||
const useResizeObserver = (callback, elements, dependencies) => {
|
||||
useEffect(() => {
|
||||
if (!window.ResizeObserver) {
|
||||
const handleResize = () => callback();
|
||||
window.addEventListener("resize", handleResize);
|
||||
callback();
|
||||
return () => window.removeEventListener("resize", handleResize);
|
||||
}
|
||||
const observers = elements.map((ref) => {
|
||||
if (!ref.current) return null;
|
||||
const observer = new ResizeObserver(callback);
|
||||
observer.observe(ref.current);
|
||||
return observer;
|
||||
});
|
||||
callback();
|
||||
return () => {
|
||||
observers.forEach((observer) => observer?.disconnect());
|
||||
};
|
||||
}, [callback, elements, dependencies]);
|
||||
};
|
||||
|
||||
const useImageLoader = (seqRef, onLoad, dependencies) => {
|
||||
useEffect(() => {
|
||||
const images = seqRef.current?.querySelectorAll("img") ?? [];
|
||||
if (images.length === 0) {
|
||||
onLoad();
|
||||
return;
|
||||
}
|
||||
let remainingImages = images.length;
|
||||
const handleImageLoad = () => {
|
||||
remainingImages -= 1;
|
||||
if (remainingImages === 0) onLoad();
|
||||
};
|
||||
images.forEach((img) => {
|
||||
const htmlImg = img;
|
||||
if (htmlImg.complete) {
|
||||
handleImageLoad();
|
||||
} else {
|
||||
htmlImg.addEventListener("load", handleImageLoad, { once: true });
|
||||
htmlImg.addEventListener("error", handleImageLoad, { once: true });
|
||||
}
|
||||
});
|
||||
return () => {
|
||||
images.forEach((img) => {
|
||||
img.removeEventListener("load", handleImageLoad);
|
||||
img.removeEventListener("error", handleImageLoad);
|
||||
});
|
||||
};
|
||||
}, [onLoad, seqRef, dependencies]);
|
||||
};
|
||||
|
||||
const useAnimationLoop = (
|
||||
trackRef,
|
||||
targetVelocity,
|
||||
seqWidth,
|
||||
seqHeight,
|
||||
isHovered,
|
||||
hoverSpeed,
|
||||
isVertical,
|
||||
) => {
|
||||
const rafRef = useRef(null);
|
||||
const lastTimestampRef = useRef(null);
|
||||
const offsetRef = useRef(0);
|
||||
const velocityRef = useRef(0);
|
||||
|
||||
useEffect(() => {
|
||||
const track = trackRef.current;
|
||||
if (!track) return;
|
||||
|
||||
const seqSize = isVertical ? seqHeight : seqWidth;
|
||||
|
||||
if (seqSize > 0) {
|
||||
offsetRef.current = ((offsetRef.current % seqSize) + seqSize) % seqSize;
|
||||
const transformValue = isVertical
|
||||
? `translate3d(0, ${-offsetRef.current}px, 0)`
|
||||
: `translate3d(${-offsetRef.current}px, 0, 0)`;
|
||||
track.style.transform = transformValue;
|
||||
}
|
||||
|
||||
const animate = (timestamp) => {
|
||||
if (lastTimestampRef.current === null) {
|
||||
lastTimestampRef.current = timestamp;
|
||||
}
|
||||
|
||||
const deltaTime =
|
||||
Math.max(0, timestamp - lastTimestampRef.current) / 1000;
|
||||
lastTimestampRef.current = timestamp;
|
||||
|
||||
const target =
|
||||
isHovered && hoverSpeed !== undefined ? hoverSpeed : targetVelocity;
|
||||
|
||||
const easingFactor =
|
||||
1 - Math.exp(-deltaTime / ANIMATION_CONFIG.SMOOTH_TAU);
|
||||
velocityRef.current += (target - velocityRef.current) * easingFactor;
|
||||
|
||||
if (seqSize > 0) {
|
||||
let nextOffset = offsetRef.current + velocityRef.current * deltaTime;
|
||||
nextOffset = ((nextOffset % seqSize) + seqSize) % seqSize;
|
||||
offsetRef.current = nextOffset;
|
||||
|
||||
const transformValue = isVertical
|
||||
? `translate3d(0, ${-offsetRef.current}px, 0)`
|
||||
: `translate3d(${-offsetRef.current}px, 0, 0)`;
|
||||
track.style.transform = transformValue;
|
||||
}
|
||||
|
||||
rafRef.current = requestAnimationFrame(animate);
|
||||
};
|
||||
|
||||
rafRef.current = requestAnimationFrame(animate);
|
||||
|
||||
return () => {
|
||||
if (rafRef.current !== null) {
|
||||
cancelAnimationFrame(rafRef.current);
|
||||
rafRef.current = null;
|
||||
}
|
||||
lastTimestampRef.current = null;
|
||||
};
|
||||
}, [
|
||||
targetVelocity,
|
||||
seqWidth,
|
||||
seqHeight,
|
||||
isHovered,
|
||||
hoverSpeed,
|
||||
isVertical,
|
||||
trackRef,
|
||||
]);
|
||||
};
|
||||
|
||||
export const LogoLoop = memo(
|
||||
({
|
||||
logos,
|
||||
speed = 120,
|
||||
direction = "left",
|
||||
width = "100%",
|
||||
logoHeight = 28,
|
||||
gap = 32,
|
||||
pauseOnHover,
|
||||
hoverSpeed,
|
||||
fadeOut = false,
|
||||
fadeOutColor,
|
||||
scaleOnHover = false,
|
||||
renderItem,
|
||||
ariaLabel = "Partner logos",
|
||||
className,
|
||||
style,
|
||||
}) => {
|
||||
const containerRef = useRef(null);
|
||||
const trackRef = useRef(null);
|
||||
const seqRef = useRef(null);
|
||||
|
||||
const [seqWidth, setSeqWidth] = useState(0);
|
||||
const [seqHeight, setSeqHeight] = useState(0);
|
||||
const [copyCount, setCopyCount] = useState(ANIMATION_CONFIG.MIN_COPIES);
|
||||
const [isHovered, setIsHovered] = useState(false);
|
||||
|
||||
const effectiveHoverSpeed = useMemo(() => {
|
||||
if (hoverSpeed !== undefined) return hoverSpeed;
|
||||
if (pauseOnHover === true) return 0;
|
||||
if (pauseOnHover === false) return undefined;
|
||||
return 0;
|
||||
}, [hoverSpeed, pauseOnHover]);
|
||||
|
||||
const isVertical = direction === "up" || direction === "down";
|
||||
|
||||
const targetVelocity = useMemo(() => {
|
||||
const magnitude = Math.abs(speed);
|
||||
let directionMultiplier;
|
||||
if (isVertical) {
|
||||
directionMultiplier = direction === "up" ? 1 : -1;
|
||||
} else {
|
||||
directionMultiplier = direction === "left" ? 1 : -1;
|
||||
}
|
||||
const speedMultiplier = speed < 0 ? -1 : 1;
|
||||
return magnitude * directionMultiplier * speedMultiplier;
|
||||
}, [speed, direction, isVertical]);
|
||||
|
||||
const updateDimensions = useCallback(() => {
|
||||
const containerWidth = containerRef.current?.clientWidth ?? 0;
|
||||
const sequenceRect = seqRef.current?.getBoundingClientRect?.();
|
||||
const sequenceWidth = sequenceRect?.width ?? 0;
|
||||
const sequenceHeight = sequenceRect?.height ?? 0;
|
||||
if (isVertical) {
|
||||
const parentHeight =
|
||||
containerRef.current?.parentElement?.clientHeight ?? 0;
|
||||
if (containerRef.current && parentHeight > 0) {
|
||||
const targetHeight = Math.ceil(parentHeight);
|
||||
if (containerRef.current.style.height !== `${targetHeight}px`)
|
||||
containerRef.current.style.height = `${targetHeight}px`;
|
||||
}
|
||||
if (sequenceHeight > 0) {
|
||||
setSeqHeight(Math.ceil(sequenceHeight));
|
||||
const viewport =
|
||||
containerRef.current?.clientHeight ??
|
||||
parentHeight ??
|
||||
sequenceHeight;
|
||||
const copiesNeeded =
|
||||
Math.ceil(viewport / sequenceHeight) +
|
||||
ANIMATION_CONFIG.COPY_HEADROOM;
|
||||
setCopyCount(Math.max(ANIMATION_CONFIG.MIN_COPIES, copiesNeeded));
|
||||
}
|
||||
} else if (sequenceWidth > 0) {
|
||||
setSeqWidth(Math.ceil(sequenceWidth));
|
||||
const copiesNeeded =
|
||||
Math.ceil(containerWidth / sequenceWidth) +
|
||||
ANIMATION_CONFIG.COPY_HEADROOM;
|
||||
setCopyCount(Math.max(ANIMATION_CONFIG.MIN_COPIES, copiesNeeded));
|
||||
}
|
||||
}, [isVertical]);
|
||||
|
||||
useResizeObserver(
|
||||
updateDimensions,
|
||||
[containerRef, seqRef],
|
||||
[logos, gap, logoHeight, isVertical],
|
||||
);
|
||||
|
||||
useImageLoader(seqRef, updateDimensions, [
|
||||
logos,
|
||||
gap,
|
||||
logoHeight,
|
||||
isVertical,
|
||||
]);
|
||||
|
||||
useAnimationLoop(
|
||||
trackRef,
|
||||
targetVelocity,
|
||||
seqWidth,
|
||||
seqHeight,
|
||||
isHovered,
|
||||
effectiveHoverSpeed,
|
||||
isVertical,
|
||||
);
|
||||
|
||||
const cssVariables = useMemo(
|
||||
() => ({
|
||||
"--logoloop-gap": `${gap}px`,
|
||||
"--logoloop-logoHeight": `${logoHeight}px`,
|
||||
...(fadeOutColor && { "--logoloop-fadeColor": fadeOutColor }),
|
||||
}),
|
||||
[gap, logoHeight, fadeOutColor],
|
||||
);
|
||||
|
||||
const rootClassName = useMemo(
|
||||
() =>
|
||||
[
|
||||
"logoloop",
|
||||
isVertical ? "logoloop--vertical" : "logoloop--horizontal",
|
||||
fadeOut && "logoloop--fade",
|
||||
scaleOnHover && "logoloop--scale-hover",
|
||||
className,
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join(" "),
|
||||
[isVertical, fadeOut, scaleOnHover, className],
|
||||
);
|
||||
|
||||
const handleMouseEnter = useCallback(() => {
|
||||
if (effectiveHoverSpeed !== undefined) setIsHovered(true);
|
||||
}, [effectiveHoverSpeed]);
|
||||
const handleMouseLeave = useCallback(() => {
|
||||
if (effectiveHoverSpeed !== undefined) setIsHovered(false);
|
||||
}, [effectiveHoverSpeed]);
|
||||
|
||||
const renderLogoItem = useCallback(
|
||||
(item, key) => {
|
||||
if (renderItem) {
|
||||
return (
|
||||
<li className="logoloop__item" key={key} role="listitem">
|
||||
{renderItem(item, key)}
|
||||
</li>
|
||||
);
|
||||
}
|
||||
const isNodeItem = "node" in item;
|
||||
const content = isNodeItem ? (
|
||||
<span
|
||||
className="logoloop__node"
|
||||
aria-hidden={!!item.href && !item.ariaLabel}
|
||||
>
|
||||
{item.node}
|
||||
</span>
|
||||
) : (
|
||||
<img
|
||||
src={item.src}
|
||||
srcSet={item.srcSet}
|
||||
sizes={item.sizes}
|
||||
width={item.width}
|
||||
height={item.height}
|
||||
alt={item.alt ?? ""}
|
||||
title={item.title}
|
||||
loading="lazy"
|
||||
decoding="async"
|
||||
draggable={false}
|
||||
/>
|
||||
);
|
||||
const itemAriaLabel = isNodeItem
|
||||
? (item.ariaLabel ?? item.title)
|
||||
: (item.alt ?? item.title);
|
||||
const itemContent = item.href ? (
|
||||
<a
|
||||
className="logoloop__link"
|
||||
href={item.href}
|
||||
aria-label={itemAriaLabel || "logo link"}
|
||||
target="_blank"
|
||||
rel="noreferrer noopener"
|
||||
>
|
||||
{content}
|
||||
</a>
|
||||
) : (
|
||||
content
|
||||
);
|
||||
return (
|
||||
<li className="logoloop__item" key={key} role="listitem">
|
||||
{itemContent}
|
||||
</li>
|
||||
);
|
||||
},
|
||||
[renderItem],
|
||||
);
|
||||
|
||||
const logoLists = useMemo(
|
||||
() =>
|
||||
Array.from({ length: copyCount }, (_, copyIndex) => (
|
||||
<ul
|
||||
className="logoloop__list"
|
||||
key={`copy-${copyIndex}`}
|
||||
role="list"
|
||||
aria-hidden={copyIndex > 0}
|
||||
ref={copyIndex === 0 ? seqRef : undefined}
|
||||
>
|
||||
{logos.map((item, itemIndex) =>
|
||||
renderLogoItem(item, `${copyIndex}-${itemIndex}`),
|
||||
)}
|
||||
</ul>
|
||||
)),
|
||||
[copyCount, logos, renderLogoItem],
|
||||
);
|
||||
|
||||
const containerStyle = useMemo(
|
||||
() => ({
|
||||
width: isVertical
|
||||
? toCssLength(width) === "100%"
|
||||
? undefined
|
||||
: toCssLength(width)
|
||||
: (toCssLength(width) ?? "100%"),
|
||||
...cssVariables,
|
||||
...style,
|
||||
}),
|
||||
[width, cssVariables, style, isVertical],
|
||||
);
|
||||
|
||||
return (
|
||||
<div
|
||||
ref={containerRef}
|
||||
className={rootClassName}
|
||||
style={containerStyle}
|
||||
role="region"
|
||||
aria-label={ariaLabel}
|
||||
>
|
||||
<div
|
||||
className="logoloop__track"
|
||||
ref={trackRef}
|
||||
onMouseEnter={handleMouseEnter}
|
||||
onMouseLeave={handleMouseLeave}
|
||||
>
|
||||
{logoLists}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
LogoLoop.displayName = "LogoLoop";
|
||||
|
||||
export default LogoLoop;
|
||||
@@ -0,0 +1,139 @@
|
||||
:root {
|
||||
--white: #ffffff;
|
||||
--accent-primary: rgba(183, 28, 28, 1);
|
||||
--accent-glow: rgba(183, 28, 28, 0.3);
|
||||
--border-color: #1a0505;
|
||||
--background-dark: #050000;
|
||||
}
|
||||
|
||||
.card-grid {
|
||||
display: grid;
|
||||
gap: 0.75em;
|
||||
padding: 1em;
|
||||
max-width: 60em;
|
||||
margin: 0 auto;
|
||||
font-size: clamp(1rem, 0.9rem + 0.5vw, 1.5rem);
|
||||
}
|
||||
|
||||
.magic-bento-card {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: space-between;
|
||||
position: relative;
|
||||
aspect-ratio: 4/3;
|
||||
min-height: 220px;
|
||||
width: 100%;
|
||||
padding: 1.5em;
|
||||
border-radius: 20px;
|
||||
border: 1px solid var(--border-color);
|
||||
background-color: var(--background-dark);
|
||||
background-size: cover;
|
||||
background-position: center;
|
||||
overflow: hidden;
|
||||
transition:
|
||||
transform 0.3s ease,
|
||||
box-shadow 0.3s ease;
|
||||
z-index: 1;
|
||||
|
||||
--glow-x: 50%;
|
||||
--glow-y: 50%;
|
||||
--glow-intensity: 0;
|
||||
--glow-radius: 500px; /* Augmenté pour couvrir toute la carte */
|
||||
}
|
||||
|
||||
/* OVERLAY IMAGE (Assombrissement) */
|
||||
.magic-bento-card::before {
|
||||
content: "";
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
background: linear-gradient(
|
||||
to bottom,
|
||||
rgba(0, 0, 0, 0.4),
|
||||
rgba(0, 0, 0, 0.8)
|
||||
);
|
||||
z-index: 0;
|
||||
}
|
||||
|
||||
/* BORDURE ÉPAISSE & SPOTLIGHT */
|
||||
.magic-bento-card--border-glow::after {
|
||||
content: "";
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
|
||||
/* --- ÉPAISSEUR DE LA BORDURE --- */
|
||||
padding: 6px;
|
||||
|
||||
background: radial-gradient(
|
||||
var(--glow-radius) circle at var(--glow-x) var(--glow-y),
|
||||
rgba(183, 28, 28, calc(var(--glow-intensity) * 1)) 0%,
|
||||
rgba(183, 28, 28, calc(var(--glow-intensity) * 0.4)) 50%,
|
||||
transparent 80%
|
||||
);
|
||||
border-radius: inherit;
|
||||
-webkit-mask:
|
||||
linear-gradient(#fff 0 0) content-box,
|
||||
linear-gradient(#fff 0 0);
|
||||
mask:
|
||||
linear-gradient(#fff 0 0) content-box,
|
||||
linear-gradient(#fff 0 0);
|
||||
-webkit-mask-composite: xor;
|
||||
mask-composite: exclude;
|
||||
|
||||
pointer-events: none;
|
||||
opacity: 1;
|
||||
transition: opacity 0.3s ease;
|
||||
z-index: 3;
|
||||
}
|
||||
|
||||
.magic-bento-card:hover {
|
||||
transform: translateY(-5px);
|
||||
/* Lueur externe supplémentaire au survol */
|
||||
box-shadow: 0 0 30px rgba(183, 28, 28, 0.2);
|
||||
}
|
||||
|
||||
.magic-bento-card__header,
|
||||
.magic-bento-card__content {
|
||||
z-index: 4;
|
||||
position: relative;
|
||||
color: var(--white);
|
||||
}
|
||||
|
||||
/* Typographie */
|
||||
.magic-bento-card__label {
|
||||
font-size: 1rem;
|
||||
font-weight: 700;
|
||||
color: var(--accent-primary);
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 2px;
|
||||
}
|
||||
|
||||
.magic-bento-card__title {
|
||||
font-size: 1.5rem;
|
||||
font-weight: 600;
|
||||
margin-top: 0.5rem;
|
||||
}
|
||||
|
||||
.magic-bento-card__description {
|
||||
font-size: 1rem;
|
||||
opacity: 0.7;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
/* Grille Layout (Modèle original) */
|
||||
@media (min-width: 1024px) {
|
||||
.card-grid {
|
||||
grid-template-columns: repeat(4, 1fr);
|
||||
}
|
||||
.magic-bento-card:nth-child(3) {
|
||||
grid-column: span 2;
|
||||
grid-row: span 2;
|
||||
}
|
||||
.magic-bento-card:nth-child(4) {
|
||||
grid-column: 1 / span 2;
|
||||
grid-row: 2 / span 2;
|
||||
}
|
||||
.magic-bento-card:nth-child(6) {
|
||||
grid-column: 4;
|
||||
grid-row: 3;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,193 @@
|
||||
import { useRef, useEffect, useCallback } from "react";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { gsap } from "gsap";
|
||||
import "./MagicBento.css";
|
||||
|
||||
const DEFAULT_GLOW_COLOR = "183, 28, 28";
|
||||
|
||||
const cardData = [
|
||||
{
|
||||
title: "Metz Campus",
|
||||
image: "/images/MC.png",
|
||||
description: "Web platform for students.",
|
||||
label: "Web site",
|
||||
link: "https://metzcampus.fr",
|
||||
},
|
||||
{
|
||||
title: "Neo Tokyo Rush",
|
||||
image: "/images/NTR.png",
|
||||
description: "Cyberpunk-inspired beat 'em All game.",
|
||||
label: "Gamedev",
|
||||
link: "/projects/neo-tokyo-rush",
|
||||
},
|
||||
{
|
||||
title: "About Co Hai Se",
|
||||
image: "/images/Cohaise.jpg",
|
||||
description: "Crafting the Web of Your Ambitions.",
|
||||
label: "Identity",
|
||||
link: "/cohaise",
|
||||
},
|
||||
{
|
||||
title: "Contact",
|
||||
image: "/images/Contact.jpg",
|
||||
description: "Reach out to me.",
|
||||
label: "Network",
|
||||
link: "/contact",
|
||||
},
|
||||
{
|
||||
title: "Затишок",
|
||||
image: "/images/Zatyshok.png",
|
||||
description: "Moodboard developped with love.",
|
||||
label: "Desktop App",
|
||||
link: "/projects/zatyshok",
|
||||
},
|
||||
{
|
||||
title: "Shadow Purge - Rite of the Demon",
|
||||
image: "/images/SPRotD.png",
|
||||
description: "Hack n'slash RPG.",
|
||||
label: "Gamedev",
|
||||
link: "/projects/shadow-purge-rite-of-the-demon",
|
||||
},
|
||||
];
|
||||
|
||||
const createParticleElement = (x, y, color) => {
|
||||
const el = document.createElement("div");
|
||||
el.className = "particle";
|
||||
el.style.cssText = `position: absolute; width: 3px; height: 3px; border-radius: 50%; background: rgba(${color}, 1); box-shadow: 0 0 6px rgba(${color}, 0.6); pointer-events: none; z-index: 10; left: ${x}px; top: ${y}px;`;
|
||||
return el;
|
||||
};
|
||||
|
||||
const ParticleCard = ({ children, className, glowColor, onClick, style }) => {
|
||||
const cardRef = useRef(null);
|
||||
const particlesRef = useRef([]);
|
||||
const timeoutsRef = useRef([]);
|
||||
|
||||
const clearParticles = useCallback(() => {
|
||||
timeoutsRef.current.forEach(clearTimeout);
|
||||
timeoutsRef.current = [];
|
||||
particlesRef.current.forEach((p) => {
|
||||
gsap.to(p, {
|
||||
scale: 0,
|
||||
opacity: 0,
|
||||
duration: 0.3,
|
||||
onComplete: () => p.parentNode?.removeChild(p),
|
||||
});
|
||||
});
|
||||
particlesRef.current = [];
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
const el = cardRef.current;
|
||||
if (!el) return;
|
||||
|
||||
const handleMove = (e) => {
|
||||
const r = el.getBoundingClientRect();
|
||||
el.style.setProperty(
|
||||
"--glow-x",
|
||||
`${((e.clientX - r.left) / r.width) * 100}%`,
|
||||
);
|
||||
el.style.setProperty(
|
||||
"--glow-y",
|
||||
`${((e.clientY - r.top) / r.height) * 100}%`,
|
||||
);
|
||||
};
|
||||
|
||||
const handleEnter = () => {
|
||||
el.style.setProperty("--glow-intensity", "1");
|
||||
for (let i = 0; i < 8; i++) {
|
||||
const timeout = setTimeout(() => {
|
||||
if (!el) return;
|
||||
const p = createParticleElement(
|
||||
Math.random() * el.offsetWidth,
|
||||
Math.random() * el.offsetHeight,
|
||||
glowColor,
|
||||
);
|
||||
el.appendChild(p);
|
||||
particlesRef.current.push(p);
|
||||
gsap.fromTo(
|
||||
p,
|
||||
{ scale: 0, opacity: 0 },
|
||||
{ scale: 1, opacity: 1, duration: 0.3 },
|
||||
);
|
||||
gsap.to(p, {
|
||||
x: "+=" + (Math.random() - 0.5) * 40,
|
||||
y: "+=" + (Math.random() - 0.5) * 40,
|
||||
duration: 1.5 + Math.random(),
|
||||
repeat: -1,
|
||||
yoyo: true,
|
||||
ease: "sine.inOut",
|
||||
});
|
||||
}, i * 100);
|
||||
timeoutsRef.current.push(timeout);
|
||||
}
|
||||
};
|
||||
|
||||
const handleLeave = () => {
|
||||
el.style.setProperty("--glow-intensity", "0");
|
||||
clearParticles();
|
||||
};
|
||||
|
||||
el.addEventListener("mousemove", handleMove);
|
||||
el.addEventListener("mouseenter", handleEnter);
|
||||
el.addEventListener("mouseleave", handleLeave);
|
||||
return () => {
|
||||
el.removeEventListener("mousemove", handleMove);
|
||||
el.removeEventListener("mouseenter", handleEnter);
|
||||
el.removeEventListener("mouseleave", handleLeave);
|
||||
clearParticles();
|
||||
};
|
||||
}, [glowColor, clearParticles]);
|
||||
|
||||
return (
|
||||
<div
|
||||
ref={cardRef}
|
||||
onClick={onClick}
|
||||
className={`${className} cursor-target`}
|
||||
style={style}
|
||||
>
|
||||
{children}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default function MagicBento({
|
||||
enableBorderGlow = true,
|
||||
glowColor = DEFAULT_GLOW_COLOR,
|
||||
}) {
|
||||
const navigate = useNavigate();
|
||||
|
||||
const handleCardClick = (link) => {
|
||||
if (link.startsWith("http")) window.open(link, "_blank");
|
||||
else navigate(link);
|
||||
};
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className="card-grid bento-section">
|
||||
{cardData.map((card, i) => (
|
||||
<ParticleCard
|
||||
key={i}
|
||||
onClick={() => handleCardClick(card.link)}
|
||||
className={`magic-bento-card ${enableBorderGlow ? "magic-bento-card--border-glow" : ""}`}
|
||||
glowColor={glowColor}
|
||||
style={{
|
||||
backgroundImage: card.image ? `url(${card.image})` : "none",
|
||||
backgroundColor: card.color || "#060010",
|
||||
}}
|
||||
>
|
||||
{card.image && <div className="magic-bento-card-overlay" />}
|
||||
<div className="magic-bento-card__header">
|
||||
<div className="magic-bento-card__label">{card.label}</div>
|
||||
</div>
|
||||
<div className="magic-bento-card__content">
|
||||
<h3 className="magic-bento-card__title">{card.title}</h3>
|
||||
<p className="magic-bento-card__description">
|
||||
{card.description}
|
||||
</p>
|
||||
</div>
|
||||
</ParticleCard>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
export const WebService = () => (
|
||||
<div className="service-detail-content">
|
||||
<h3>Modern & Fast Websites</h3>
|
||||
<p>
|
||||
Building clean, responsive websites using Next.js and React. I focus on
|
||||
speed, visibility, and converting visitors into clients.
|
||||
</p>
|
||||
<ul>
|
||||
<li>Showcase Websites (Landing Pages)</li>
|
||||
<li>SEO & Performance Optimization</li>
|
||||
<li>CMS Integration (Content Management)</li>
|
||||
</ul>
|
||||
</div>
|
||||
);
|
||||
|
||||
export const MobileService = () => (
|
||||
<div className="service-detail-content">
|
||||
<h3>iOS & Android Apps</h3>
|
||||
<p>
|
||||
Turning your ideas into real mobile apps. Using React Native to create
|
||||
smooth experiences that work perfectly on all phones.
|
||||
</p>
|
||||
<ul>
|
||||
<li>Cross-Platform Apps</li>
|
||||
<li>App Store Submission Help</li>
|
||||
<li>User-Friendly Interfaces</li>
|
||||
</ul>
|
||||
</div>
|
||||
);
|
||||
|
||||
export const DesignService = () => (
|
||||
<div className="service-detail-content">
|
||||
<h3>UI/UX Design</h3>
|
||||
<p>
|
||||
Simple and effective designs. I create interfaces that look good and help
|
||||
users find what they need effortlessly.
|
||||
</p>
|
||||
<ul>
|
||||
<li>Wireframing & Prototyping</li>
|
||||
<li>Mobile-First Design</li>
|
||||
<li>Visual Identity Basics</li>
|
||||
</ul>
|
||||
</div>
|
||||
);
|
||||
|
||||
export const SoftwareService = () => (
|
||||
<div className="service-detail-content">
|
||||
<h3>Custom Solutions</h3>
|
||||
<p>
|
||||
Need something specific? I build custom tools and dashboards to help
|
||||
automate your daily tasks and save you time.
|
||||
</p>
|
||||
<ul>
|
||||
<li>Custom Web Tools</li>
|
||||
<li>Desktop Web App</li>
|
||||
<li>Dashboard Creation</li>
|
||||
<li>API Connections</li>
|
||||
</ul>
|
||||
</div>
|
||||
);
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,75 @@
|
||||
import { useLocation } from "react-router-dom";
|
||||
import Galaxy from "./Galaxy";
|
||||
import LightPillar from "./LightPillar";
|
||||
import SplashCursor from "../cursors/SplashCursor";
|
||||
import TargetCursor from "../cursors/TargetCursor";
|
||||
|
||||
export default function BackgroundWrapper() {
|
||||
const location = useLocation();
|
||||
const isCohaise = location.pathname === "/cohaise";
|
||||
|
||||
return (
|
||||
<>
|
||||
{/* 1. COUCHE CURSEURS */}
|
||||
<div
|
||||
className="fixed inset-0 pointer-events-none"
|
||||
style={{
|
||||
zIndex: isCohaise ? -5 : 99999,
|
||||
}}
|
||||
>
|
||||
{isCohaise ? (
|
||||
<SplashCursor />
|
||||
) : (
|
||||
<TargetCursor
|
||||
spinDuration={4}
|
||||
hideDefaultCursor={true}
|
||||
parallaxOn={true}
|
||||
hoverDuration={1}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* 2. COUCHE BACKGROUNDS */}
|
||||
<div
|
||||
className="fixed inset-0 bg-[#0e0e11] pointer-events-none"
|
||||
style={{ zIndex: -10 }}
|
||||
>
|
||||
{isCohaise ? (
|
||||
<div className="w-full h-full relative">
|
||||
<LightPillar
|
||||
topColor="#8a1414"
|
||||
bottomColor="#060010"
|
||||
intensity={1.5}
|
||||
rotationSpeed={0.2}
|
||||
glowAmount={0.004}
|
||||
pillarWidth={8}
|
||||
pillarHeight={1}
|
||||
noiseIntensity={0.5}
|
||||
pillarRotation={20}
|
||||
interactive
|
||||
mixBlendMode="screen"
|
||||
quality="high"
|
||||
/>
|
||||
</div>
|
||||
) : (
|
||||
<div className="w-full h-full relative">
|
||||
<Galaxy
|
||||
mouseRepulsion={true}
|
||||
mouseInteraction={true}
|
||||
density={1.7}
|
||||
glowIntensity={0.4}
|
||||
saturation={0}
|
||||
hueShift={360}
|
||||
twinkleIntensity={0.3}
|
||||
rotationSpeed={0.1}
|
||||
repulsionStrength={3.5}
|
||||
autoCenterRepulsion={0}
|
||||
starSpeed={1}
|
||||
speed={1}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,343 @@
|
||||
import { Renderer, Program, Mesh, Color, Triangle } from "ogl";
|
||||
import { useEffect, useRef } from "react";
|
||||
|
||||
const vertexShader = `
|
||||
attribute vec2 uv;
|
||||
attribute vec2 position;
|
||||
|
||||
varying vec2 vUv;
|
||||
|
||||
void main() {
|
||||
vUv = uv;
|
||||
gl_Position = vec4(position, 0, 1);
|
||||
}
|
||||
`;
|
||||
|
||||
const fragmentShader = `
|
||||
precision highp float;
|
||||
|
||||
uniform float uTime;
|
||||
uniform vec3 uResolution;
|
||||
uniform vec2 uFocal;
|
||||
uniform vec2 uRotation;
|
||||
uniform float uStarSpeed;
|
||||
uniform float uDensity;
|
||||
uniform float uHueShift;
|
||||
uniform float uSpeed;
|
||||
uniform vec2 uMouse;
|
||||
uniform float uGlowIntensity;
|
||||
uniform float uSaturation;
|
||||
uniform bool uMouseRepulsion;
|
||||
uniform float uTwinkleIntensity;
|
||||
uniform float uRotationSpeed;
|
||||
uniform float uRepulsionStrength;
|
||||
uniform float uMouseActiveFactor;
|
||||
uniform float uAutoCenterRepulsion;
|
||||
uniform bool uTransparent;
|
||||
|
||||
varying vec2 vUv;
|
||||
|
||||
#define NUM_LAYER 4.0
|
||||
#define STAR_COLOR_CUTOFF 0.2
|
||||
#define MAT45 mat2(0.7071, -0.7071, 0.7071, 0.7071)
|
||||
#define PERIOD 3.0
|
||||
|
||||
float Hash21(vec2 p) {
|
||||
p = fract(p * vec2(123.34, 456.21));
|
||||
p += dot(p, p + 45.32);
|
||||
return fract(p.x * p.y);
|
||||
}
|
||||
|
||||
float tri(float x) {
|
||||
return abs(fract(x) * 2.0 - 1.0);
|
||||
}
|
||||
|
||||
float tris(float x) {
|
||||
float t = fract(x);
|
||||
return 1.0 - smoothstep(0.0, 1.0, abs(2.0 * t - 1.0));
|
||||
}
|
||||
|
||||
float trisn(float x) {
|
||||
float t = fract(x);
|
||||
return 2.0 * (1.0 - smoothstep(0.0, 1.0, abs(2.0 * t - 1.0))) - 1.0;
|
||||
}
|
||||
|
||||
vec3 hsv2rgb(vec3 c) {
|
||||
vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
|
||||
vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
|
||||
return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
|
||||
}
|
||||
|
||||
float Star(vec2 uv, float flare) {
|
||||
float d = length(uv);
|
||||
float m = (0.05 * uGlowIntensity) / d;
|
||||
float rays = smoothstep(0.0, 1.0, 1.0 - abs(uv.x * uv.y * 1000.0));
|
||||
m += rays * flare * uGlowIntensity;
|
||||
uv *= MAT45;
|
||||
rays = smoothstep(0.0, 1.0, 1.0 - abs(uv.x * uv.y * 1000.0));
|
||||
m += rays * 0.3 * flare * uGlowIntensity;
|
||||
m *= smoothstep(1.0, 0.2, d);
|
||||
return m;
|
||||
}
|
||||
|
||||
vec3 StarLayer(vec2 uv) {
|
||||
vec3 col = vec3(0.0);
|
||||
|
||||
vec2 gv = fract(uv) - 0.5;
|
||||
vec2 id = floor(uv);
|
||||
|
||||
for (int y = -1; y <= 1; y++) {
|
||||
for (int x = -1; x <= 1; x++) {
|
||||
vec2 offset = vec2(float(x), float(y));
|
||||
vec2 si = id + vec2(float(x), float(y));
|
||||
float seed = Hash21(si);
|
||||
float size = fract(seed * 345.32);
|
||||
float glossLocal = tri(uStarSpeed / (PERIOD * seed + 1.0));
|
||||
float flareSize = smoothstep(0.9, 1.0, size) * glossLocal;
|
||||
|
||||
float red = smoothstep(STAR_COLOR_CUTOFF, 1.0, Hash21(si + 1.0)) + STAR_COLOR_CUTOFF;
|
||||
float blu = smoothstep(STAR_COLOR_CUTOFF, 1.0, Hash21(si + 3.0)) + STAR_COLOR_CUTOFF;
|
||||
float grn = min(red, blu) * seed;
|
||||
vec3 base = vec3(red, grn, blu);
|
||||
|
||||
float hue = atan(base.g - base.r, base.b - base.r) / (2.0 * 3.14159) + 0.5;
|
||||
hue = fract(hue + uHueShift / 360.0);
|
||||
float sat = length(base - vec3(dot(base, vec3(0.299, 0.587, 0.114)))) * uSaturation;
|
||||
float val = max(max(base.r, base.g), base.b);
|
||||
base = hsv2rgb(vec3(hue, sat, val));
|
||||
|
||||
vec2 pad = vec2(tris(seed * 34.0 + uTime * uSpeed / 10.0), tris(seed * 38.0 + uTime * uSpeed / 30.0)) - 0.5;
|
||||
|
||||
float star = Star(gv - offset - pad, flareSize);
|
||||
vec3 color = base;
|
||||
|
||||
float twinkle = trisn(uTime * uSpeed + seed * 6.2831) * 0.5 + 1.0;
|
||||
twinkle = mix(1.0, twinkle, uTwinkleIntensity);
|
||||
star *= twinkle;
|
||||
|
||||
col += star * size * color;
|
||||
}
|
||||
}
|
||||
|
||||
return col;
|
||||
}
|
||||
|
||||
void main() {
|
||||
vec2 focalPx = uFocal * uResolution.xy;
|
||||
vec2 uv = (vUv * uResolution.xy - focalPx) / uResolution.y;
|
||||
|
||||
vec2 mouseNorm = uMouse - vec2(0.5);
|
||||
|
||||
if (uAutoCenterRepulsion > 0.0) {
|
||||
vec2 centerUV = vec2(0.0, 0.0);
|
||||
float centerDist = length(uv - centerUV);
|
||||
vec2 repulsion = normalize(uv - centerUV) * (uAutoCenterRepulsion / (centerDist + 0.1));
|
||||
uv += repulsion * 0.05;
|
||||
} else if (uMouseRepulsion) {
|
||||
vec2 mousePosUV = (uMouse * uResolution.xy - focalPx) / uResolution.y;
|
||||
float mouseDist = length(uv - mousePosUV);
|
||||
vec2 repulsion = normalize(uv - mousePosUV) * (uRepulsionStrength / (mouseDist + 0.1));
|
||||
uv += repulsion * 0.05 * uMouseActiveFactor;
|
||||
} else {
|
||||
vec2 mouseOffset = mouseNorm * 0.1 * uMouseActiveFactor;
|
||||
uv += mouseOffset;
|
||||
}
|
||||
|
||||
float autoRotAngle = uTime * uRotationSpeed;
|
||||
mat2 autoRot = mat2(cos(autoRotAngle), -sin(autoRotAngle), sin(autoRotAngle), cos(autoRotAngle));
|
||||
uv = autoRot * uv;
|
||||
|
||||
uv = mat2(uRotation.x, -uRotation.y, uRotation.y, uRotation.x) * uv;
|
||||
|
||||
vec3 col = vec3(0.0);
|
||||
|
||||
for (float i = 0.0; i < 1.0; i += 1.0 / NUM_LAYER) {
|
||||
float depth = fract(i + uStarSpeed * uSpeed);
|
||||
float scale = mix(20.0 * uDensity, 0.5 * uDensity, depth);
|
||||
float fade = depth * smoothstep(1.0, 0.9, depth);
|
||||
col += StarLayer(uv * scale + i * 453.32) * fade;
|
||||
}
|
||||
|
||||
if (uTransparent) {
|
||||
float alpha = length(col);
|
||||
alpha = smoothstep(0.0, 0.3, alpha);
|
||||
alpha = min(alpha, 1.0);
|
||||
gl_FragColor = vec4(col, alpha);
|
||||
} else {
|
||||
gl_FragColor = vec4(col, 1.0);
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
export default function Galaxy({
|
||||
focal = [0.5, 0.5],
|
||||
rotation = [0.5, 0.5],
|
||||
starSpeed = 0.5,
|
||||
density = 1,
|
||||
hueShift = 1,
|
||||
disableAnimation = false,
|
||||
speed = 1.0,
|
||||
mouseInteraction = true,
|
||||
glowIntensity = 0.8,
|
||||
saturation = 0.0,
|
||||
mouseRepulsion = true,
|
||||
repulsionStrength = 0,
|
||||
twinkleIntensity = 0.8,
|
||||
rotationSpeed = 0.1,
|
||||
autoCenterRepulsion = 10,
|
||||
transparent = true,
|
||||
...rest
|
||||
}) {
|
||||
const ctnDom = useRef(null);
|
||||
const targetMousePos = useRef({ x: 0.5, y: 0.5 });
|
||||
const smoothMousePos = useRef({ x: 0.5, y: 0.5 });
|
||||
const targetMouseActive = useRef(0.0);
|
||||
const smoothMouseActive = useRef(0.0);
|
||||
|
||||
useEffect(() => {
|
||||
if (!ctnDom.current) return;
|
||||
const ctn = ctnDom.current;
|
||||
const renderer = new Renderer({
|
||||
alpha: transparent,
|
||||
premultipliedAlpha: false,
|
||||
});
|
||||
const gl = renderer.gl;
|
||||
|
||||
if (transparent) {
|
||||
gl.enable(gl.BLEND);
|
||||
gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
|
||||
gl.clearColor(0, 0, 0, 0);
|
||||
} else {
|
||||
gl.clearColor(0, 0, 0, 1);
|
||||
}
|
||||
|
||||
let program;
|
||||
|
||||
function resize() {
|
||||
const scale = 1;
|
||||
renderer.setSize(ctn.offsetWidth * scale, ctn.offsetHeight * scale);
|
||||
if (program) {
|
||||
program.uniforms.uResolution.value = new Color(
|
||||
gl.canvas.width,
|
||||
gl.canvas.height,
|
||||
gl.canvas.width / gl.canvas.height,
|
||||
);
|
||||
}
|
||||
}
|
||||
window.addEventListener("resize", resize, false);
|
||||
resize();
|
||||
|
||||
const geometry = new Triangle(gl);
|
||||
program = new Program(gl, {
|
||||
vertex: vertexShader,
|
||||
fragment: fragmentShader,
|
||||
uniforms: {
|
||||
uTime: { value: 0 },
|
||||
uResolution: {
|
||||
value: new Color(
|
||||
gl.canvas.width,
|
||||
gl.canvas.height,
|
||||
gl.canvas.width / gl.canvas.height,
|
||||
),
|
||||
},
|
||||
uFocal: { value: new Float32Array(focal) },
|
||||
uRotation: { value: new Float32Array(rotation) },
|
||||
uStarSpeed: { value: starSpeed },
|
||||
uDensity: { value: density },
|
||||
uHueShift: { value: hueShift },
|
||||
uSpeed: { value: speed },
|
||||
uMouse: {
|
||||
value: new Float32Array([
|
||||
smoothMousePos.current.x,
|
||||
smoothMousePos.current.y,
|
||||
]),
|
||||
},
|
||||
uGlowIntensity: { value: glowIntensity },
|
||||
uSaturation: { value: saturation },
|
||||
uMouseRepulsion: { value: mouseRepulsion },
|
||||
uTwinkleIntensity: { value: twinkleIntensity },
|
||||
uRotationSpeed: { value: rotationSpeed },
|
||||
uRepulsionStrength: { value: repulsionStrength },
|
||||
uMouseActiveFactor: { value: 0.0 },
|
||||
uAutoCenterRepulsion: { value: autoCenterRepulsion },
|
||||
uTransparent: { value: transparent },
|
||||
},
|
||||
});
|
||||
|
||||
const mesh = new Mesh(gl, { geometry, program });
|
||||
let animateId;
|
||||
|
||||
function update(t) {
|
||||
animateId = requestAnimationFrame(update);
|
||||
if (!disableAnimation) {
|
||||
program.uniforms.uTime.value = t * 0.001;
|
||||
program.uniforms.uStarSpeed.value = (t * 0.001 * starSpeed) / 10.0;
|
||||
}
|
||||
|
||||
const lerpFactor = 0.05;
|
||||
smoothMousePos.current.x +=
|
||||
(targetMousePos.current.x - smoothMousePos.current.x) * lerpFactor;
|
||||
smoothMousePos.current.y +=
|
||||
(targetMousePos.current.y - smoothMousePos.current.y) * lerpFactor;
|
||||
|
||||
smoothMouseActive.current +=
|
||||
(targetMouseActive.current - smoothMouseActive.current) * lerpFactor;
|
||||
|
||||
program.uniforms.uMouse.value[0] = smoothMousePos.current.x;
|
||||
program.uniforms.uMouse.value[1] = smoothMousePos.current.y;
|
||||
program.uniforms.uMouseActiveFactor.value = smoothMouseActive.current;
|
||||
|
||||
renderer.render({ scene: mesh });
|
||||
}
|
||||
animateId = requestAnimationFrame(update);
|
||||
ctn.appendChild(gl.canvas);
|
||||
|
||||
// --- CORRECTION MAJEURE ICI ---
|
||||
function handleMouseMove(e) {
|
||||
// On calcule par rapport à la fenêtre globale
|
||||
const x = e.clientX / window.innerWidth;
|
||||
const y = 1.0 - e.clientY / window.innerHeight;
|
||||
|
||||
targetMousePos.current = { x, y };
|
||||
targetMouseActive.current = 1.0;
|
||||
}
|
||||
|
||||
if (mouseInteraction) {
|
||||
window.addEventListener("mousemove", handleMouseMove);
|
||||
}
|
||||
|
||||
return () => {
|
||||
cancelAnimationFrame(animateId);
|
||||
window.removeEventListener("resize", resize);
|
||||
|
||||
// NETTOYAGE CORRECT : On enlève l'écouteur de window, pas de ctn
|
||||
if (mouseInteraction) {
|
||||
window.removeEventListener("mousemove", handleMouseMove);
|
||||
}
|
||||
|
||||
if (ctn.contains(gl.canvas)) {
|
||||
ctn.removeChild(gl.canvas);
|
||||
}
|
||||
gl.getExtension("WEBGL_lose_context")?.loseContext();
|
||||
};
|
||||
}, [
|
||||
focal,
|
||||
rotation,
|
||||
starSpeed,
|
||||
density,
|
||||
hueShift,
|
||||
disableAnimation,
|
||||
speed,
|
||||
mouseInteraction,
|
||||
glowIntensity,
|
||||
saturation,
|
||||
mouseRepulsion,
|
||||
twinkleIntensity,
|
||||
rotationSpeed,
|
||||
repulsionStrength,
|
||||
autoCenterRepulsion,
|
||||
transparent,
|
||||
]);
|
||||
|
||||
return <div ref={ctnDom} className="w-full h-full relative" {...rest} />;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
.light-pillar-fallback {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background-color: rgba(0, 0, 0, 0.1);
|
||||
color: #888;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.light-pillar-container {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
}
|
||||
@@ -0,0 +1,384 @@
|
||||
/* eslint-disable react-hooks/set-state-in-effect */
|
||||
import { useRef, useEffect, useState } from "react";
|
||||
import * as THREE from "three";
|
||||
import "./LightPillar.css";
|
||||
|
||||
const LightPillar = ({
|
||||
topColor = "#5227FF",
|
||||
bottomColor = "#FF9FFC",
|
||||
intensity = 1.0,
|
||||
rotationSpeed = 0.3,
|
||||
interactive = true,
|
||||
className = "",
|
||||
glowAmount = 0.005,
|
||||
pillarWidth = 3.0,
|
||||
pillarHeight = 0.4,
|
||||
noiseIntensity = 0.5,
|
||||
mixBlendMode = "screen",
|
||||
pillarRotation = 0,
|
||||
quality = "high",
|
||||
}) => {
|
||||
const containerRef = useRef(null);
|
||||
const rafRef = useRef(null);
|
||||
const rendererRef = useRef(null);
|
||||
const materialRef = useRef(null);
|
||||
const sceneRef = useRef(null);
|
||||
const cameraRef = useRef(null);
|
||||
const geometryRef = useRef(null);
|
||||
const mouseRef = useRef(new THREE.Vector2(0, 0));
|
||||
const timeRef = useRef(0);
|
||||
const [webGLSupported, setWebGLSupported] = useState(true);
|
||||
|
||||
useEffect(() => {
|
||||
const canvas = document.createElement("canvas");
|
||||
const gl =
|
||||
canvas.getContext("webgl") || canvas.getContext("experimental-webgl");
|
||||
if (!gl) {
|
||||
setWebGLSupported(false);
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (!containerRef.current || !webGLSupported) return;
|
||||
|
||||
const container = containerRef.current;
|
||||
const width = container.clientWidth;
|
||||
const height = container.clientHeight;
|
||||
|
||||
const scene = new THREE.Scene();
|
||||
sceneRef.current = scene;
|
||||
const camera = new THREE.OrthographicCamera(-1, 1, 1, -1, 0, 1);
|
||||
cameraRef.current = camera;
|
||||
|
||||
const isMobile =
|
||||
/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
|
||||
navigator.userAgent,
|
||||
);
|
||||
const isLowEndDevice =
|
||||
isMobile ||
|
||||
(navigator.hardwareConcurrency && navigator.hardwareConcurrency <= 4);
|
||||
|
||||
let effectiveQuality = quality;
|
||||
if (isLowEndDevice && quality === "high") effectiveQuality = "medium";
|
||||
if (isMobile && quality !== "low") effectiveQuality = "low";
|
||||
|
||||
const qualitySettings = {
|
||||
low: {
|
||||
iterations: 24,
|
||||
waveIterations: 1,
|
||||
pixelRatio: 0.5,
|
||||
precision: "mediump",
|
||||
stepMultiplier: 1.5,
|
||||
},
|
||||
medium: {
|
||||
iterations: 40,
|
||||
waveIterations: 2,
|
||||
pixelRatio: 0.65,
|
||||
precision: "mediump",
|
||||
stepMultiplier: 1.2,
|
||||
},
|
||||
high: {
|
||||
iterations: 80,
|
||||
waveIterations: 4,
|
||||
pixelRatio: Math.min(window.devicePixelRatio, 2),
|
||||
precision: "highp",
|
||||
stepMultiplier: 1.0,
|
||||
},
|
||||
};
|
||||
|
||||
const settings =
|
||||
qualitySettings[effectiveQuality] || qualitySettings.medium;
|
||||
|
||||
let renderer;
|
||||
try {
|
||||
renderer = new THREE.WebGLRenderer({
|
||||
antialias: false,
|
||||
alpha: true,
|
||||
powerPreference:
|
||||
effectiveQuality === "high" ? "high-performance" : "low-power",
|
||||
precision: settings.precision,
|
||||
stencil: false,
|
||||
depth: false,
|
||||
});
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
} catch (error) {
|
||||
setWebGLSupported(false);
|
||||
return;
|
||||
}
|
||||
|
||||
renderer.setSize(width, height);
|
||||
renderer.setPixelRatio(settings.pixelRatio);
|
||||
container.appendChild(renderer.domElement);
|
||||
rendererRef.current = renderer;
|
||||
|
||||
const parseColor = (hex) => {
|
||||
const color = new THREE.Color(hex);
|
||||
return new THREE.Vector3(color.r, color.g, color.b);
|
||||
};
|
||||
|
||||
const vertexShader = `
|
||||
varying vec2 vUv;
|
||||
void main() {
|
||||
vUv = uv;
|
||||
gl_Position = vec4(position, 1.0);
|
||||
}
|
||||
`;
|
||||
|
||||
const fragmentShader = `
|
||||
precision ${settings.precision} float;
|
||||
|
||||
uniform float uTime;
|
||||
uniform vec2 uResolution;
|
||||
uniform vec2 uMouse;
|
||||
uniform vec3 uTopColor;
|
||||
uniform vec3 uBottomColor;
|
||||
uniform float uIntensity;
|
||||
uniform bool uInteractive;
|
||||
uniform float uGlowAmount;
|
||||
uniform float uPillarWidth;
|
||||
uniform float uPillarHeight;
|
||||
uniform float uNoiseIntensity;
|
||||
uniform float uRotCos;
|
||||
uniform float uRotSin;
|
||||
uniform float uPillarRotCos;
|
||||
uniform float uPillarRotSin;
|
||||
uniform float uWaveSin;
|
||||
uniform float uWaveCos;
|
||||
varying vec2 vUv;
|
||||
|
||||
const float STEP_MULT = ${settings.stepMultiplier.toFixed(1)};
|
||||
const int MAX_ITER = ${settings.iterations};
|
||||
const int WAVE_ITER = ${settings.waveIterations};
|
||||
|
||||
void main() {
|
||||
vec2 uv = (vUv * 2.0 - 1.0) * vec2(uResolution.x / uResolution.y, 1.0);
|
||||
uv = vec2(uPillarRotCos * uv.x - uPillarRotSin * uv.y, uPillarRotSin * uv.x + uPillarRotCos * uv.y);
|
||||
|
||||
vec3 ro = vec3(0.0, 0.0, -10.0);
|
||||
vec3 rd = normalize(vec3(uv, 1.0));
|
||||
|
||||
float rotC = uRotCos;
|
||||
float rotS = uRotSin;
|
||||
if(uInteractive && (uMouse.x != 0.0 || uMouse.y != 0.0)) {
|
||||
float a = uMouse.x * 6.283185;
|
||||
rotC = cos(a);
|
||||
rotS = sin(a);
|
||||
}
|
||||
|
||||
vec3 col = vec3(0.0);
|
||||
float t = 0.1;
|
||||
|
||||
for(int i = 0; i < MAX_ITER; i++) {
|
||||
vec3 p = ro + rd * t;
|
||||
p.xz = vec2(rotC * p.x - rotS * p.z, rotS * p.x + rotC * p.z);
|
||||
|
||||
vec3 q = p;
|
||||
q.y = p.y * uPillarHeight + uTime;
|
||||
|
||||
float freq = 1.0;
|
||||
float amp = 1.0;
|
||||
for(int j = 0; j < WAVE_ITER; j++) {
|
||||
q.xz = vec2(uWaveCos * q.x - uWaveSin * q.z, uWaveSin * q.x + uWaveCos * q.z);
|
||||
q += cos(q.zxy * freq - uTime * float(j) * 2.0) * amp;
|
||||
freq *= 2.0;
|
||||
amp *= 0.5;
|
||||
}
|
||||
|
||||
float d = length(cos(q.xz)) - 0.2;
|
||||
float bound = length(p.xz) - uPillarWidth;
|
||||
float k = 4.0;
|
||||
float h = max(k - abs(d - bound), 0.0);
|
||||
d = max(d, bound) + h * h * 0.0625 / k;
|
||||
d = abs(d) * 0.15 + 0.01;
|
||||
|
||||
float grad = clamp((15.0 - p.y) / 30.0, 0.0, 1.0);
|
||||
col += mix(uBottomColor, uTopColor, grad) / d;
|
||||
|
||||
t += d * STEP_MULT;
|
||||
if(t > 50.0) break;
|
||||
}
|
||||
|
||||
float widthNorm = uPillarWidth / 3.0;
|
||||
col = tanh(col * uGlowAmount / widthNorm);
|
||||
|
||||
col -= fract(sin(dot(gl_FragCoord.xy, vec2(12.9898, 78.233))) * 43758.5453) / 15.0 * uNoiseIntensity;
|
||||
|
||||
gl_FragColor = vec4(col * uIntensity, 1.0);
|
||||
}
|
||||
`;
|
||||
|
||||
const pillarRotRad = (pillarRotation * Math.PI) / 180;
|
||||
const waveSin = Math.sin(0.4);
|
||||
const waveCos = Math.cos(0.4);
|
||||
|
||||
const material = new THREE.ShaderMaterial({
|
||||
vertexShader,
|
||||
fragmentShader,
|
||||
uniforms: {
|
||||
uTime: { value: 0 },
|
||||
uResolution: { value: new THREE.Vector2(width, height) },
|
||||
uMouse: { value: mouseRef.current },
|
||||
uTopColor: { value: parseColor(topColor) },
|
||||
uBottomColor: { value: parseColor(bottomColor) },
|
||||
uIntensity: { value: intensity },
|
||||
uInteractive: { value: interactive },
|
||||
uGlowAmount: { value: glowAmount },
|
||||
uPillarWidth: { value: pillarWidth },
|
||||
uPillarHeight: { value: pillarHeight },
|
||||
uNoiseIntensity: { value: noiseIntensity },
|
||||
uRotCos: { value: 1.0 },
|
||||
uRotSin: { value: 0.0 },
|
||||
uPillarRotCos: { value: Math.cos(pillarRotRad) },
|
||||
uPillarRotSin: { value: Math.sin(pillarRotRad) },
|
||||
uWaveSin: { value: waveSin },
|
||||
uWaveCos: { value: waveCos },
|
||||
},
|
||||
transparent: true,
|
||||
depthWrite: false,
|
||||
depthTest: false,
|
||||
});
|
||||
materialRef.current = material;
|
||||
|
||||
const geometry = new THREE.PlaneGeometry(2, 2);
|
||||
geometryRef.current = geometry;
|
||||
const mesh = new THREE.Mesh(geometry, material);
|
||||
scene.add(mesh);
|
||||
|
||||
let mouseMoveTimeout = null;
|
||||
const handleMouseMove = (event) => {
|
||||
if (!interactive) return;
|
||||
|
||||
if (mouseMoveTimeout) return;
|
||||
|
||||
mouseMoveTimeout = window.setTimeout(() => {
|
||||
mouseMoveTimeout = null;
|
||||
}, 16);
|
||||
|
||||
const rect = container.getBoundingClientRect();
|
||||
const x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
|
||||
const y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
|
||||
mouseRef.current.set(x, y);
|
||||
};
|
||||
|
||||
if (interactive) {
|
||||
container.addEventListener("mousemove", handleMouseMove, {
|
||||
passive: true,
|
||||
});
|
||||
}
|
||||
|
||||
let lastTime = performance.now();
|
||||
const targetFPS = effectiveQuality === "low" ? 30 : 60;
|
||||
const frameTime = 1000 / targetFPS;
|
||||
|
||||
const animate = (currentTime) => {
|
||||
if (
|
||||
!materialRef.current ||
|
||||
!rendererRef.current ||
|
||||
!sceneRef.current ||
|
||||
!cameraRef.current
|
||||
)
|
||||
return;
|
||||
|
||||
const deltaTime = currentTime - lastTime;
|
||||
|
||||
if (deltaTime >= frameTime) {
|
||||
timeRef.current += 0.016 * rotationSpeed;
|
||||
const t = timeRef.current;
|
||||
materialRef.current.uniforms.uTime.value = t;
|
||||
materialRef.current.uniforms.uRotCos.value = Math.cos(t * 0.3);
|
||||
materialRef.current.uniforms.uRotSin.value = Math.sin(t * 0.3);
|
||||
rendererRef.current.render(sceneRef.current, cameraRef.current);
|
||||
lastTime = currentTime - (deltaTime % frameTime);
|
||||
}
|
||||
|
||||
rafRef.current = requestAnimationFrame(animate);
|
||||
};
|
||||
rafRef.current = requestAnimationFrame(animate);
|
||||
|
||||
let resizeTimeout = null;
|
||||
const handleResize = () => {
|
||||
if (resizeTimeout) {
|
||||
clearTimeout(resizeTimeout);
|
||||
}
|
||||
|
||||
resizeTimeout = window.setTimeout(() => {
|
||||
if (
|
||||
!rendererRef.current ||
|
||||
!materialRef.current ||
|
||||
!containerRef.current
|
||||
)
|
||||
return;
|
||||
const newWidth = containerRef.current.clientWidth;
|
||||
const newHeight = containerRef.current.clientHeight;
|
||||
rendererRef.current.setSize(newWidth, newHeight);
|
||||
materialRef.current.uniforms.uResolution.value.set(newWidth, newHeight);
|
||||
}, 150);
|
||||
};
|
||||
|
||||
window.addEventListener("resize", handleResize, { passive: true });
|
||||
|
||||
return () => {
|
||||
window.removeEventListener("resize", handleResize);
|
||||
if (interactive) {
|
||||
container.removeEventListener("mousemove", handleMouseMove);
|
||||
}
|
||||
if (rafRef.current) {
|
||||
cancelAnimationFrame(rafRef.current);
|
||||
}
|
||||
if (rendererRef.current) {
|
||||
rendererRef.current.dispose();
|
||||
rendererRef.current.forceContextLoss();
|
||||
if (container.contains(rendererRef.current.domElement)) {
|
||||
container.removeChild(rendererRef.current.domElement);
|
||||
}
|
||||
}
|
||||
if (materialRef.current) {
|
||||
materialRef.current.dispose();
|
||||
}
|
||||
if (geometryRef.current) {
|
||||
geometryRef.current.dispose();
|
||||
}
|
||||
|
||||
rendererRef.current = null;
|
||||
materialRef.current = null;
|
||||
sceneRef.current = null;
|
||||
cameraRef.current = null;
|
||||
geometryRef.current = null;
|
||||
rafRef.current = null;
|
||||
};
|
||||
}, [
|
||||
topColor,
|
||||
bottomColor,
|
||||
intensity,
|
||||
rotationSpeed,
|
||||
interactive,
|
||||
glowAmount,
|
||||
pillarWidth,
|
||||
pillarHeight,
|
||||
noiseIntensity,
|
||||
pillarRotation,
|
||||
webGLSupported,
|
||||
quality,
|
||||
]);
|
||||
|
||||
if (!webGLSupported) {
|
||||
return (
|
||||
<div
|
||||
className={`light-pillar-fallback ${className}`}
|
||||
style={{ mixBlendMode }}
|
||||
>
|
||||
WebGL not supported
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
ref={containerRef}
|
||||
className={`light-pillar-container ${className}`}
|
||||
style={{ mixBlendMode }}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
export default LightPillar;
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,57 @@
|
||||
.target-cursor-wrapper {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 0;
|
||||
height: 0;
|
||||
pointer-events: none;
|
||||
z-index: 9999;
|
||||
mix-blend-mode: difference;
|
||||
transform: translate(-50%, -50%);
|
||||
}
|
||||
|
||||
.target-cursor-dot {
|
||||
position: absolute;
|
||||
left: 50%;
|
||||
top: 50%;
|
||||
width: 4px;
|
||||
height: 4px;
|
||||
background: #fff;
|
||||
border-radius: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
will-change: transform;
|
||||
}
|
||||
|
||||
.target-cursor-corner {
|
||||
position: absolute;
|
||||
left: 50%;
|
||||
top: 50%;
|
||||
width: 12px;
|
||||
height: 12px;
|
||||
border: 3px solid #fff;
|
||||
will-change: transform;
|
||||
}
|
||||
|
||||
.corner-tl {
|
||||
transform: translate(-150%, -150%);
|
||||
border-right: none;
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.corner-tr {
|
||||
transform: translate(50%, -150%);
|
||||
border-left: none;
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.corner-br {
|
||||
transform: translate(50%, 50%);
|
||||
border-left: none;
|
||||
border-top: none;
|
||||
}
|
||||
|
||||
.corner-bl {
|
||||
transform: translate(-150%, 50%);
|
||||
border-right: none;
|
||||
border-top: none;
|
||||
}
|
||||
@@ -0,0 +1,366 @@
|
||||
import { useEffect, useRef, useCallback, useMemo } from "react";
|
||||
import { gsap } from "gsap";
|
||||
import "./TargetCursor.css";
|
||||
|
||||
const TargetCursor = ({
|
||||
targetSelector = ".cursor-target",
|
||||
spinDuration = 2,
|
||||
hideDefaultCursor = true,
|
||||
hoverDuration = 0.2,
|
||||
parallaxOn = true,
|
||||
}) => {
|
||||
const cursorRef = useRef(null);
|
||||
const cornersRef = useRef(null);
|
||||
const spinTl = useRef(null);
|
||||
const dotRef = useRef(null);
|
||||
|
||||
const isActiveRef = useRef(false);
|
||||
const targetCornerPositionsRef = useRef(null);
|
||||
const tickerFnRef = useRef(null);
|
||||
const activeStrengthRef = useRef(0);
|
||||
|
||||
const isMobile = useMemo(() => {
|
||||
const hasTouchScreen =
|
||||
"ontouchstart" in window || navigator.maxTouchPoints > 0;
|
||||
const isSmallScreen = window.innerWidth <= 768;
|
||||
const userAgent = navigator.userAgent || navigator.vendor || window.opera;
|
||||
const mobileRegex =
|
||||
/android|webos|iphone|ipad|ipod|blackberry|iemobile|opera mini/i;
|
||||
const isMobileUserAgent = mobileRegex.test(userAgent.toLowerCase());
|
||||
return (hasTouchScreen && isSmallScreen) || isMobileUserAgent;
|
||||
}, []);
|
||||
|
||||
const constants = useMemo(
|
||||
() => ({
|
||||
borderWidth: 3,
|
||||
cornerSize: 12,
|
||||
}),
|
||||
[],
|
||||
);
|
||||
|
||||
const moveCursor = useCallback((x, y) => {
|
||||
if (!cursorRef.current) return;
|
||||
gsap.to(cursorRef.current, {
|
||||
x,
|
||||
y,
|
||||
duration: 0.1,
|
||||
ease: "power3.out",
|
||||
});
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (isMobile || !cursorRef.current) return;
|
||||
|
||||
const originalCursor = document.body.style.cursor;
|
||||
if (hideDefaultCursor) {
|
||||
document.body.style.cursor = "none";
|
||||
}
|
||||
|
||||
const cursor = cursorRef.current;
|
||||
cornersRef.current = cursor.querySelectorAll(".target-cursor-corner");
|
||||
|
||||
let activeTarget = null;
|
||||
let currentLeaveHandler = null;
|
||||
let resumeTimeout = null;
|
||||
|
||||
const cleanupTarget = (target) => {
|
||||
if (currentLeaveHandler) {
|
||||
target.removeEventListener("mouseleave", currentLeaveHandler);
|
||||
}
|
||||
currentLeaveHandler = null;
|
||||
};
|
||||
|
||||
gsap.set(cursor, {
|
||||
xPercent: -50,
|
||||
yPercent: -50,
|
||||
x: window.innerWidth / 2,
|
||||
y: window.innerHeight / 2,
|
||||
});
|
||||
|
||||
const createSpinTimeline = () => {
|
||||
if (spinTl.current) {
|
||||
spinTl.current.kill();
|
||||
}
|
||||
spinTl.current = gsap
|
||||
.timeline({ repeat: -1 })
|
||||
.to(cursor, {
|
||||
rotation: "+=360",
|
||||
duration: spinDuration,
|
||||
ease: "none",
|
||||
});
|
||||
};
|
||||
|
||||
createSpinTimeline();
|
||||
|
||||
const tickerFn = () => {
|
||||
if (
|
||||
!targetCornerPositionsRef.current ||
|
||||
!cursorRef.current ||
|
||||
!cornersRef.current
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
const strength = activeStrengthRef.current;
|
||||
if (strength === 0) return;
|
||||
|
||||
const cursorX = gsap.getProperty(cursorRef.current, "x");
|
||||
const cursorY = gsap.getProperty(cursorRef.current, "y");
|
||||
|
||||
const corners = Array.from(cornersRef.current);
|
||||
corners.forEach((corner, i) => {
|
||||
const currentX = gsap.getProperty(corner, "x");
|
||||
const currentY = gsap.getProperty(corner, "y");
|
||||
|
||||
const targetX = targetCornerPositionsRef.current[i].x - cursorX;
|
||||
const targetY = targetCornerPositionsRef.current[i].y - cursorY;
|
||||
|
||||
const finalX = currentX + (targetX - currentX) * strength;
|
||||
const finalY = currentY + (targetY - currentY) * strength;
|
||||
|
||||
const duration = strength >= 0.99 ? (parallaxOn ? 0.2 : 0) : 0.05;
|
||||
|
||||
gsap.to(corner, {
|
||||
x: finalX,
|
||||
y: finalY,
|
||||
duration: duration,
|
||||
ease: duration === 0 ? "none" : "power1.out",
|
||||
overwrite: "auto",
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
tickerFnRef.current = tickerFn;
|
||||
|
||||
const moveHandler = (e) => moveCursor(e.clientX, e.clientY);
|
||||
window.addEventListener("mousemove", moveHandler);
|
||||
|
||||
const scrollHandler = () => {
|
||||
if (!activeTarget || !cursorRef.current) return;
|
||||
const mouseX = gsap.getProperty(cursorRef.current, "x");
|
||||
const mouseY = gsap.getProperty(cursorRef.current, "y");
|
||||
const elementUnderMouse = document.elementFromPoint(mouseX, mouseY);
|
||||
const isStillOverTarget =
|
||||
elementUnderMouse &&
|
||||
(elementUnderMouse === activeTarget ||
|
||||
elementUnderMouse.closest(targetSelector) === activeTarget);
|
||||
if (!isStillOverTarget) {
|
||||
if (currentLeaveHandler) {
|
||||
currentLeaveHandler();
|
||||
}
|
||||
}
|
||||
};
|
||||
window.addEventListener("scroll", scrollHandler, { passive: true });
|
||||
|
||||
const mouseDownHandler = () => {
|
||||
if (!dotRef.current) return;
|
||||
gsap.to(dotRef.current, { scale: 0.7, duration: 0.3 });
|
||||
gsap.to(cursorRef.current, { scale: 0.9, duration: 0.2 });
|
||||
};
|
||||
|
||||
const mouseUpHandler = () => {
|
||||
if (!dotRef.current) return;
|
||||
gsap.to(dotRef.current, { scale: 1, duration: 0.3 });
|
||||
gsap.to(cursorRef.current, { scale: 1, duration: 0.2 });
|
||||
};
|
||||
|
||||
window.addEventListener("mousedown", mouseDownHandler);
|
||||
window.addEventListener("mouseup", mouseUpHandler);
|
||||
|
||||
const enterHandler = (e) => {
|
||||
const directTarget = e.target;
|
||||
const allTargets = [];
|
||||
let current = directTarget;
|
||||
while (current && current !== document.body) {
|
||||
if (current.matches(targetSelector)) {
|
||||
allTargets.push(current);
|
||||
}
|
||||
current = current.parentElement;
|
||||
}
|
||||
const target = allTargets[0] || null;
|
||||
if (!target || !cursorRef.current || !cornersRef.current) return;
|
||||
if (activeTarget === target) return;
|
||||
if (activeTarget) {
|
||||
cleanupTarget(activeTarget);
|
||||
}
|
||||
if (resumeTimeout) {
|
||||
clearTimeout(resumeTimeout);
|
||||
resumeTimeout = null;
|
||||
}
|
||||
|
||||
activeTarget = target;
|
||||
const corners = Array.from(cornersRef.current);
|
||||
corners.forEach((corner) => gsap.killTweensOf(corner));
|
||||
|
||||
gsap.killTweensOf(cursorRef.current, "rotation");
|
||||
spinTl.current?.pause();
|
||||
gsap.set(cursorRef.current, { rotation: 0 });
|
||||
|
||||
const rect = target.getBoundingClientRect();
|
||||
const { borderWidth, cornerSize } = constants;
|
||||
const cursorX = gsap.getProperty(cursorRef.current, "x");
|
||||
const cursorY = gsap.getProperty(cursorRef.current, "y");
|
||||
|
||||
targetCornerPositionsRef.current = [
|
||||
{ x: rect.left - borderWidth, y: rect.top - borderWidth },
|
||||
{ x: rect.right + borderWidth - cornerSize, y: rect.top - borderWidth },
|
||||
{
|
||||
x: rect.right + borderWidth - cornerSize,
|
||||
y: rect.bottom + borderWidth - cornerSize,
|
||||
},
|
||||
{
|
||||
x: rect.left - borderWidth,
|
||||
y: rect.bottom + borderWidth - cornerSize,
|
||||
},
|
||||
];
|
||||
|
||||
isActiveRef.current = true;
|
||||
gsap.ticker.add(tickerFnRef.current);
|
||||
|
||||
gsap.to(activeStrengthRef, {
|
||||
current: 1,
|
||||
duration: hoverDuration,
|
||||
ease: "power2.out",
|
||||
});
|
||||
|
||||
corners.forEach((corner, i) => {
|
||||
gsap.to(corner, {
|
||||
x: targetCornerPositionsRef.current[i].x - cursorX,
|
||||
y: targetCornerPositionsRef.current[i].y - cursorY,
|
||||
duration: 0.2,
|
||||
ease: "power2.out",
|
||||
});
|
||||
});
|
||||
|
||||
const leaveHandler = () => {
|
||||
gsap.ticker.remove(tickerFnRef.current);
|
||||
|
||||
isActiveRef.current = false;
|
||||
targetCornerPositionsRef.current = null;
|
||||
gsap.set(activeStrengthRef, { current: 0, overwrite: true });
|
||||
activeTarget = null;
|
||||
|
||||
if (cornersRef.current) {
|
||||
const corners = Array.from(cornersRef.current);
|
||||
gsap.killTweensOf(corners);
|
||||
const { cornerSize } = constants;
|
||||
const positions = [
|
||||
{ x: -cornerSize * 1.5, y: -cornerSize * 1.5 },
|
||||
{ x: cornerSize * 0.5, y: -cornerSize * 1.5 },
|
||||
{ x: cornerSize * 0.5, y: cornerSize * 0.5 },
|
||||
{ x: -cornerSize * 1.5, y: cornerSize * 0.5 },
|
||||
];
|
||||
const tl = gsap.timeline();
|
||||
corners.forEach((corner, index) => {
|
||||
tl.to(
|
||||
corner,
|
||||
{
|
||||
x: positions[index].x,
|
||||
y: positions[index].y,
|
||||
duration: 0.3,
|
||||
ease: "power3.out",
|
||||
},
|
||||
0,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
resumeTimeout = setTimeout(() => {
|
||||
if (!activeTarget && cursorRef.current && spinTl.current) {
|
||||
const currentRotation = gsap.getProperty(
|
||||
cursorRef.current,
|
||||
"rotation",
|
||||
);
|
||||
const normalizedRotation = currentRotation % 360;
|
||||
spinTl.current.kill();
|
||||
spinTl.current = gsap
|
||||
.timeline({ repeat: -1 })
|
||||
.to(cursorRef.current, {
|
||||
rotation: "+=360",
|
||||
duration: spinDuration,
|
||||
ease: "none",
|
||||
});
|
||||
gsap.to(cursorRef.current, {
|
||||
rotation: normalizedRotation + 360,
|
||||
duration: spinDuration * (1 - normalizedRotation / 360),
|
||||
ease: "none",
|
||||
onComplete: () => {
|
||||
spinTl.current?.restart();
|
||||
},
|
||||
});
|
||||
}
|
||||
resumeTimeout = null;
|
||||
}, 50);
|
||||
|
||||
cleanupTarget(target);
|
||||
};
|
||||
|
||||
currentLeaveHandler = leaveHandler;
|
||||
target.addEventListener("mouseleave", leaveHandler);
|
||||
};
|
||||
|
||||
window.addEventListener("mouseover", enterHandler, { passive: true });
|
||||
|
||||
return () => {
|
||||
if (tickerFnRef.current) {
|
||||
gsap.ticker.remove(tickerFnRef.current);
|
||||
}
|
||||
|
||||
window.removeEventListener("mousemove", moveHandler);
|
||||
window.removeEventListener("mouseover", enterHandler);
|
||||
window.removeEventListener("scroll", scrollHandler);
|
||||
window.removeEventListener("mousedown", mouseDownHandler);
|
||||
window.removeEventListener("mouseup", mouseUpHandler);
|
||||
|
||||
if (activeTarget) {
|
||||
cleanupTarget(activeTarget);
|
||||
}
|
||||
|
||||
spinTl.current?.kill();
|
||||
document.body.style.cursor = originalCursor;
|
||||
|
||||
isActiveRef.current = false;
|
||||
targetCornerPositionsRef.current = null;
|
||||
activeStrengthRef.current = 0;
|
||||
};
|
||||
}, [
|
||||
targetSelector,
|
||||
spinDuration,
|
||||
moveCursor,
|
||||
constants,
|
||||
hideDefaultCursor,
|
||||
isMobile,
|
||||
hoverDuration,
|
||||
parallaxOn,
|
||||
]);
|
||||
|
||||
useEffect(() => {
|
||||
if (isMobile || !cursorRef.current || !spinTl.current) return;
|
||||
if (spinTl.current.isActive()) {
|
||||
spinTl.current.kill();
|
||||
spinTl.current = gsap
|
||||
.timeline({ repeat: -1 })
|
||||
.to(cursorRef.current, {
|
||||
rotation: "+=360",
|
||||
duration: spinDuration,
|
||||
ease: "none",
|
||||
});
|
||||
}
|
||||
}, [spinDuration, isMobile]);
|
||||
|
||||
if (isMobile) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<div ref={cursorRef} className="target-cursor-wrapper">
|
||||
<div ref={dotRef} className="target-cursor-dot" />
|
||||
<div className="target-cursor-corner corner-tl" />
|
||||
<div className="target-cursor-corner corner-tr" />
|
||||
<div className="target-cursor-corner corner-br" />
|
||||
<div className="target-cursor-corner corner-bl" />
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default TargetCursor;
|
||||
Reference in New Issue
Block a user