From 61f55e2568ad0e4b81f95397717f81327db7b582 Mon Sep 17 00:00:00 2001 From: Johan Sandoval Date: Thu, 8 Oct 2026 16:28:16 +0000 Subject: [PATCH] Mixed-media redesign, Chicago transit system and motion Use real public-domain photos throughout (Chicago skyline, CTA signage, Marina City, Union Station, guitars, synths, cassette, Game Boy and floppy stickers, daisies, clouds, flowers, a vintage postcard and stamp), credited on a new /credits page. Lean into Chicago: CTA 'L' line colors for sections and categories, a Chicago star logo, flag footer, a CTA platform work page with split-flap board and arrival rows, and a Greetings from Chicago postcard on contact. Add GSAP + Lenis scroll motion and React Bits components (split-flap, ticker, circular badge, count-up, sticker peel, scrambled text, halftone reveal, CRT terminal, staggered mobile menu). Rebuild pages mobile-first, drop the katakana, and lazy-load the 3D viewer. --- README.md | 51 +- package-lock.json | 108 ++- package.json | 4 + src/assets/photos/botanical.jpg | Bin 0 -> 82152 bytes src/assets/photos/cassette.jpg | Bin 0 -> 162274 bytes src/assets/photos/chicago-aerial.jpg | Bin 0 -> 182644 bytes src/assets/photos/chicago-skyline-red.jpg | Bin 0 -> 94117 bytes src/assets/photos/cloud.jpg | Bin 0 -> 107118 bytes src/assets/photos/computers-pile.jpg | Bin 0 -> 232253 bytes src/assets/photos/computers-room.jpg | Bin 0 -> 99041 bytes src/assets/photos/cta-sign.jpg | Bin 0 -> 202823 bytes src/assets/photos/daisies.jpg | Bin 0 -> 72421 bytes src/assets/photos/floppies-sticker.png | Bin 0 -> 301290 bytes src/assets/photos/forest.jpg | Bin 0 -> 118053 bytes src/assets/photos/gba-sticker.png | Bin 0 -> 537967 bytes src/assets/photos/grass-top.jpg | Bin 0 -> 319424 bytes src/assets/photos/guitar-hollow.jpg | Bin 0 -> 90957 bytes src/assets/photos/guitar-strat.jpg | Bin 0 -> 113481 bytes src/assets/photos/hibiscus.jpg | Bin 0 -> 54849 bytes src/assets/photos/lily.jpg | Bin 0 -> 97372 bytes src/assets/photos/marina-city-river.jpg | Bin 0 -> 299247 bytes src/assets/photos/marina-city.jpg | Bin 0 -> 513708 bytes src/assets/photos/motorcycle.jpg | Bin 0 -> 188241 bytes src/assets/photos/paper-crumpled.jpg | Bin 0 -> 96583 bytes src/assets/photos/paper-kraft.jpg | Bin 0 -> 163786 bytes src/assets/photos/pedalboard.jpg | Bin 0 -> 192350 bytes src/assets/photos/postcard-back.jpg | Bin 0 -> 337671 bytes src/assets/photos/railroad-postcard.jpg | Bin 0 -> 215326 bytes src/assets/photos/server-rack.jpg | Bin 0 -> 691528 bytes src/assets/photos/subway-map.jpg | Bin 0 -> 225161 bytes src/assets/photos/synth.jpg | Bin 0 -> 87924 bytes src/assets/photos/tv.jpg | Bin 0 -> 136424 bytes src/assets/photos/union-station.jpg | Bin 0 -> 142229 bytes src/components/ChicagoStar.astro | 18 + src/components/Footer.astro | 53 +- src/components/MobileMenu.css | 116 ++++ src/components/MobileMenu.tsx | 53 ++ src/components/ModelViewer.astro | 31 +- src/components/Nav.astro | 97 +-- src/components/bits/CircularText.css | 24 + src/components/bits/CircularText.tsx | 124 ++++ src/components/bits/CountUp.tsx | 125 ++++ src/components/bits/FaultyTerminal.css | 6 + src/components/bits/FaultyTerminal.tsx | 439 ++++++++++++ src/components/bits/HalftoneReveal.css | 14 + src/components/bits/HalftoneReveal.tsx | 385 +++++++++++ src/components/bits/ScrambledText.css | 12 + src/components/bits/ScrambledText.tsx | 90 +++ src/components/bits/ScrollVelocity.css | 26 + src/components/bits/ScrollVelocity.tsx | 182 +++++ src/components/bits/SplitFlapText.css | 170 +++++ src/components/bits/SplitFlapText.tsx | 355 ++++++++++ src/components/bits/StaggeredMenu.css | 356 ++++++++++ src/components/bits/StaggeredMenu.tsx | 498 +++++++++++++ src/components/bits/StickerPeel.css | 157 +++++ src/components/bits/StickerPeel.tsx | 309 +++++++++ src/components/deco/Clipping.astro | 170 +++++ src/data/photo-credits.json | 242 +++++++ src/layouts/Base.astro | 6 +- src/lib/disciplines.ts | 16 +- src/lib/site.ts | 12 +- src/pages/about.astro | 96 ++- src/pages/blog/index.astro | 186 +++-- src/pages/contact.astro | 95 ++- src/pages/credits.astro | 53 ++ src/pages/index.astro | 807 ++++++++++++++++------ src/pages/models.astro | 281 +++++++- src/pages/music.astro | 90 ++- src/pages/work/index.astro | 271 ++++++-- src/scripts/motion.ts | 75 ++ src/styles/global.css | 5 + src/styles/tokens.css | 27 +- 72 files changed, 5729 insertions(+), 506 deletions(-) create mode 100644 src/assets/photos/botanical.jpg create mode 100644 src/assets/photos/cassette.jpg create mode 100644 src/assets/photos/chicago-aerial.jpg create mode 100644 src/assets/photos/chicago-skyline-red.jpg create mode 100644 src/assets/photos/cloud.jpg create mode 100644 src/assets/photos/computers-pile.jpg create mode 100644 src/assets/photos/computers-room.jpg create mode 100644 src/assets/photos/cta-sign.jpg create mode 100644 src/assets/photos/daisies.jpg create mode 100644 src/assets/photos/floppies-sticker.png create mode 100644 src/assets/photos/forest.jpg create mode 100644 src/assets/photos/gba-sticker.png create mode 100644 src/assets/photos/grass-top.jpg create mode 100644 src/assets/photos/guitar-hollow.jpg create mode 100644 src/assets/photos/guitar-strat.jpg create mode 100644 src/assets/photos/hibiscus.jpg create mode 100644 src/assets/photos/lily.jpg create mode 100644 src/assets/photos/marina-city-river.jpg create mode 100644 src/assets/photos/marina-city.jpg create mode 100644 src/assets/photos/motorcycle.jpg create mode 100644 src/assets/photos/paper-crumpled.jpg create mode 100644 src/assets/photos/paper-kraft.jpg create mode 100644 src/assets/photos/pedalboard.jpg create mode 100644 src/assets/photos/postcard-back.jpg create mode 100644 src/assets/photos/railroad-postcard.jpg create mode 100644 src/assets/photos/server-rack.jpg create mode 100644 src/assets/photos/subway-map.jpg create mode 100644 src/assets/photos/synth.jpg create mode 100644 src/assets/photos/tv.jpg create mode 100644 src/assets/photos/union-station.jpg create mode 100644 src/components/ChicagoStar.astro create mode 100644 src/components/MobileMenu.css create mode 100644 src/components/MobileMenu.tsx create mode 100644 src/components/bits/CircularText.css create mode 100644 src/components/bits/CircularText.tsx create mode 100644 src/components/bits/CountUp.tsx create mode 100644 src/components/bits/FaultyTerminal.css create mode 100644 src/components/bits/FaultyTerminal.tsx create mode 100644 src/components/bits/HalftoneReveal.css create mode 100644 src/components/bits/HalftoneReveal.tsx create mode 100644 src/components/bits/ScrambledText.css create mode 100644 src/components/bits/ScrambledText.tsx create mode 100644 src/components/bits/ScrollVelocity.css create mode 100644 src/components/bits/ScrollVelocity.tsx create mode 100644 src/components/bits/SplitFlapText.css create mode 100644 src/components/bits/SplitFlapText.tsx create mode 100644 src/components/bits/StaggeredMenu.css create mode 100644 src/components/bits/StaggeredMenu.tsx create mode 100644 src/components/bits/StickerPeel.css create mode 100644 src/components/bits/StickerPeel.tsx create mode 100644 src/components/deco/Clipping.astro create mode 100644 src/data/photo-credits.json create mode 100644 src/pages/credits.astro create mode 100644 src/scripts/motion.ts diff --git a/README.md b/README.md index 8fa057a..3ac0efa 100644 --- a/README.md +++ b/README.md @@ -36,29 +36,44 @@ Every field is typed in `src/content.config.ts`, so the build fails loudly when ## Styling -Each page has its own look, built on one shared palette and a "subway line" color system -(every section and project category has a line color + badge, see `src/lib/disciplines.ts`). +Each page has its own look, drawn from 80s–90s print and retro-tech references, tied together by +Chicago: every section and project category rides a CTA 'L' line color (`src/lib/disciplines.ts`, +`--cta-*` tokens), and the footer carries the Chicago flag. | Theme | Used on | Feel | |---|---|---| -| `magazine` (default) | Home | 90s magazine cover / print ad | -| `transit` | Work index | Subway map, transit cards | -| `spec` | Project pages | Technical exhibition poster | -| `desktop` | Blog, 404 | Late-90s desktop windows | -| `radio` | Music | College-radio flyer, dot-matrix type | -| `vector` | 3D models | 80s computer graphics, wireframes | -| `garden` | About | Grass, cream blobs, lowercase type | -| `postcard` | Contact | Postcard + stamp | +| `magazine` (default) | Home | Maximalist magazine cover: photo collage, stickers, cover lines | +| `transit` | Work index | CTA platform: station sign, split-flap board, arrival rows | +| `spec` | Project pages, credits | Technical exhibition poster | +| `desktop` | Blog, 404 | 90s desktop windows, pixelated photo wallpaper | +| `radio` | Music | Radio flyer, halftone photo, dot-matrix type | +| `vector` | 3D models | CRT terminal, wireframe cube, data panels | +| `garden` | About | Daisies, cream blobs, seed packets | +| `postcard` | Contact | "Greetings from Chicago" postcard + stamp | | `terminal` | (available) | Green-phosphor CRT | -- `src/styles/tokens.css`: raw palette (paper, ink, lime, red, cobalt, yellow, emerald...), font stacks, type scale, spacing. -- `src/styles/themes/*.css`: each theme maps the palette onto semantic tokens (`--bg`, `--fg`, `--accent`, - `--font-display`, heading weight/case/width, border, shadow, grain, scanlines). -- Use a theme on a page: ``, or `theme: vector` in a project/post's frontmatter - (projects default to `spec`, posts to `desktop`). Use it on one section: `
`. -- New theme: copy a theme file, rename the selector, import it in `themes/index.css`, add the name to `src/lib/themes.ts`. -- Page-specific flourishes live in each page's own ` diff --git a/src/components/MobileMenu.css b/src/components/MobileMenu.css new file mode 100644 index 0000000..e1d880f --- /dev/null +++ b/src/components/MobileMenu.css @@ -0,0 +1,116 @@ +/* Overrides for React Bits' StaggeredMenu: CTA station list on cream stock. */ +.yo-menu.staggered-menu-wrapper.fixed-wrapper { + z-index: 200; + height: 100dvh; + width: 100%; +} +.yo-menu .staggered-menu-header { + height: 3.75rem; + padding: 0 var(--gutter); +} +.yo-menu .sm-toggle { + min-height: 44px; + padding: 0 0.85rem; + gap: 0.5rem; + border: 2px solid #141412; + border-radius: 999px; + background: #fffdf7; + font-family: var(--ff-grotesk); + font-weight: 700; + font-size: 0.95rem; +} +.yo-menu .sm-prelayers, +.yo-menu .staggered-menu-panel { + width: 100%; +} +.yo-menu .staggered-menu-panel { + background: #f4f1e8; + padding: 5.5rem var(--gutter) 2rem; + backdrop-filter: none; +} +.yo-menu .sm-panel-list { + position: relative; + gap: 0; + padding-left: 2.6rem; +} +.yo-menu .sm-panel-list::before { + content: ''; + position: absolute; + left: 0.85rem; + top: 1.2rem; + bottom: 1.2rem; + width: 6px; + border-radius: 3px; + background: #141412; +} +.yo-menu .sm-panel-itemWrap { + overflow: visible; +} +.yo-menu .sm-panel-item { + display: flex; + align-items: center; + min-height: 3.6rem; + padding: 0.35rem 0; + font-family: var(--ff-grotesk); + font-weight: 800; + font-size: clamp(2.3rem, 11vw, 3.4rem); + letter-spacing: -0.04em; + text-transform: none; + color: #141412; +} +.yo-menu .sm-panel-item::before { + content: ''; + position: absolute; + left: -2.6rem; + top: 50%; + width: 1.4rem; + height: 1.4rem; + margin-left: 0.3rem; + translate: 0 -50%; + border-radius: 50%; + background: var(--item-color, #141412); + border: 4px solid #141412; + box-sizing: border-box; +} +.yo-menu .sm-panel-item[aria-current='page'] { + color: var(--item-color); +} +.yo-menu .sm-panel-item[aria-current='page']::before { + background: #fff; + border-color: var(--item-color); +} +.yo-menu .sm-panel-item:hover { + color: var(--item-color, #c60c30); +} +.yo-menu-foot { + margin-top: auto; + padding-top: 2rem; + display: grid; + gap: 0.4rem; + font-family: var(--ff-mono); + font-size: 0.9rem; + color: #141412; +} +.yo-menu-foot a { + color: #141412; + text-decoration-color: #c60c30; +} +.yo-menu-status { + display: flex; + align-items: center; + gap: 0.5rem; +} +.yo-menu-status span { + width: 0.6rem; + height: 0.6rem; + border-radius: 50%; + background: #2fd36b; +} +html.menu-open { + overflow: hidden; +} +@media (min-width: 56.01rem) { + .yo-menu { + display: none; + } +} diff --git a/src/components/MobileMenu.tsx b/src/components/MobileMenu.tsx new file mode 100644 index 0000000..27e0d06 --- /dev/null +++ b/src/components/MobileMenu.tsx @@ -0,0 +1,53 @@ +import StaggeredMenu from './bits/StaggeredMenu'; +import './MobileMenu.css'; + +interface Props { + items: { href: string; label: string; hex: string }[]; + current: string; + email: string; + status: string; +} + +type LenisLike = { stop: () => void; start: () => void } | null; +const lenis = (): LenisLike => (window as unknown as { __lenis?: () => LenisLike }).__lenis?.() ?? null; + +/** Full-screen mobile menu: each section is a stop on its 'L' line color. */ +export default function MobileMenu({ items, current, email, status }: Props) { + return ( + ({ + label: i.label, + ariaLabel: `Go to ${i.label}`, + link: i.href, + color: i.hex, + current: current === i.href || current.startsWith(i.href + '/'), + }))} + onMenuOpen={() => { + document.documentElement.classList.add('menu-open'); + lenis()?.stop(); + }} + onMenuClose={() => { + document.documentElement.classList.remove('menu-open'); + lenis()?.start(); + }} + footer={ +
+

+

+ {email} +
+ } + /> + ); +} diff --git a/src/components/ModelViewer.astro b/src/components/ModelViewer.astro index f14b49e..7aa5c97 100644 --- a/src/components/ModelViewer.astro +++ b/src/components/ModelViewer.astro @@ -34,17 +34,36 @@ const { src, alt, poster, ratio = '16 / 10' } = Astro.props; diff --git a/src/components/bits/CircularText.css b/src/components/bits/CircularText.css new file mode 100644 index 0000000..ea728ec --- /dev/null +++ b/src/components/bits/CircularText.css @@ -0,0 +1,24 @@ +.circular-text { + margin: 0 auto; + border-radius: 50%; + width: 200px; + height: 200px; + font-weight: bold; + color: #fff; + font-weight: 900; + text-align: center; + cursor: pointer; + transform-origin: 50% 50%; + -webkit-transform-origin: 50% 50%; +} + +.circular-text span { + position: absolute; + display: inline-block; + left: 0; + right: 0; + top: 0; + bottom: 0; + font-size: 24px; + transition: all 0.5s cubic-bezier(0, 0, 0, 1); +} diff --git a/src/components/bits/CircularText.tsx b/src/components/bits/CircularText.tsx new file mode 100644 index 0000000..f0a7c10 --- /dev/null +++ b/src/components/bits/CircularText.tsx @@ -0,0 +1,124 @@ +// CircularText — from React Bits (https://github.com/DavidHDev/react-bits) +// Copyright (c) 2026 David Haz. MIT + Commons Clause. Adapted for yoyos.sh. +'use client'; + +import React, { useEffect } from 'react'; +import { motion, useAnimation, useMotionValue, MotionValue, type Transition } from 'motion/react'; + +import './CircularText.css'; +interface CircularTextProps { + text: string; + spinDuration?: number; + onHover?: 'slowDown' | 'speedUp' | 'pause' | 'goBonkers'; + className?: string; +} + +const getRotationTransition = (duration: number, from: number, loop: boolean = true) => ({ + from, + to: from + 360, + ease: 'linear' as const, + duration, + type: 'tween' as const, + repeat: loop ? Infinity : 0 +}); + +const getTransition = (duration: number, from: number) => ({ + rotate: getRotationTransition(duration, from), + scale: { + type: 'spring' as const, + damping: 20, + stiffness: 300 + } +}); + +const CircularText: React.FC = ({ + text, + spinDuration = 20, + onHover = 'speedUp', + className = '' +}) => { + const letters = Array.from(text); + const controls = useAnimation(); + const rotation: MotionValue = useMotionValue(0); + + useEffect(() => { + const start = rotation.get(); + controls.start({ + rotate: start + 360, + scale: 1, + transition: getTransition(spinDuration, start) + }); + }, [spinDuration, text, onHover, controls]); + + const handleHoverStart = () => { + const start = rotation.get(); + + if (!onHover) return; + + let transitionConfig: ReturnType | Transition; + let scaleVal = 1; + + switch (onHover) { + case 'slowDown': + transitionConfig = getTransition(spinDuration * 2, start); + break; + case 'speedUp': + transitionConfig = getTransition(spinDuration / 4, start); + break; + case 'pause': + transitionConfig = { + rotate: { type: 'spring', damping: 20, stiffness: 300 }, + scale: { type: 'spring', damping: 20, stiffness: 300 } + }; + break; + case 'goBonkers': + transitionConfig = getTransition(spinDuration / 20, start); + scaleVal = 0.8; + break; + default: + transitionConfig = getTransition(spinDuration, start); + } + + controls.start({ + rotate: start + 360, + scale: scaleVal, + transition: transitionConfig + }); + }; + + const handleHoverEnd = () => { + const start = rotation.get(); + controls.start({ + rotate: start + 360, + scale: 1, + transition: getTransition(spinDuration, start) + }); + }; + + return ( + + {letters.map((letter, i) => { + const rotationDeg = (360 / letters.length) * i; + const factor = Math.PI / letters.length; + const x = factor * i; + const y = factor * i; + const transform = `rotateZ(${rotationDeg}deg) translate3d(${x}px, ${y}px, 0)`; + + return ( + + {letter} + + ); + })} + + ); +}; + +export default CircularText; diff --git a/src/components/bits/CountUp.tsx b/src/components/bits/CountUp.tsx new file mode 100644 index 0000000..17efa2b --- /dev/null +++ b/src/components/bits/CountUp.tsx @@ -0,0 +1,125 @@ +// CountUp — from React Bits (https://github.com/DavidHDev/react-bits) +// Copyright (c) 2026 David Haz. MIT + Commons Clause. Adapted for yoyos.sh. +'use client'; + +import { useInView, useMotionValue, useReducedMotion, useSpring } from 'motion/react'; +import { useCallback, useEffect, useRef } from 'react'; + +interface CountUpProps { + to: number; + from?: number; + direction?: 'up' | 'down'; + delay?: number; + duration?: number; + className?: string; + startWhen?: boolean; + separator?: string; + onStart?: () => void; + onEnd?: () => void; +} + +export default function CountUp({ + to, + from = 0, + direction = 'up', + delay = 0, + duration = 2, + className = '', + startWhen = true, + separator = '', + onStart, + onEnd +}: CountUpProps) { + const ref = useRef(null); + const motionValue = useMotionValue(direction === 'down' ? to : from); + + const damping = 20 + 40 * (1 / duration); + const stiffness = 100 * (1 / duration); + + const springValue = useSpring(motionValue, { + damping, + stiffness + }); + + const isInView = useInView(ref, { once: true, margin: '0px' }); + const reduceMotion = useReducedMotion(); + + const getDecimalPlaces = (num: number): number => { + const str = num.toString(); + if (str.includes('.')) { + const decimals = str.split('.')[1]; + if (parseInt(decimals) !== 0) { + return decimals.length; + } + } + return 0; + }; + + const maxDecimals = Math.max(getDecimalPlaces(from), getDecimalPlaces(to)); + + const formatValue = useCallback( + (latest: number) => { + const hasDecimals = maxDecimals > 0; + + const options: Intl.NumberFormatOptions = { + useGrouping: !!separator, + minimumFractionDigits: hasDecimals ? maxDecimals : 0, + maximumFractionDigits: hasDecimals ? maxDecimals : 0 + }; + + const formattedNumber = Intl.NumberFormat('en-US', options).format(latest); + + return separator ? formattedNumber.replace(/,/g, separator) : formattedNumber; + }, + [maxDecimals, separator] + ); + + useEffect(() => { + if (ref.current && !reduceMotion) { + ref.current.textContent = formatValue(direction === 'down' ? to : from); + } + }, [from, to, direction, formatValue, reduceMotion]); + + useEffect(() => { + if (isInView && startWhen && !reduceMotion) { + if (typeof onStart === 'function') { + onStart(); + } + + const timeoutId = setTimeout(() => { + motionValue.set(direction === 'down' ? from : to); + }, delay * 1000); + + const durationTimeoutId = setTimeout( + () => { + if (typeof onEnd === 'function') { + onEnd(); + } + }, + delay * 1000 + duration * 1000 + ); + + return () => { + clearTimeout(timeoutId); + clearTimeout(durationTimeoutId); + }; + } + }, [isInView, startWhen, reduceMotion, motionValue, direction, from, to, delay, onStart, onEnd, duration]); + + useEffect(() => { + const unsubscribe = springValue.on('change', (latest: number) => { + if (ref.current) { + ref.current.textContent = formatValue(latest); + } + }); + + return () => unsubscribe(); + }, [springValue, formatValue]); + + // Render the final value on the server so it's readable before hydration and without JS. + return ( + + {formatValue(direction === 'down' ? from : to)} + + ); +} diff --git a/src/components/bits/FaultyTerminal.css b/src/components/bits/FaultyTerminal.css new file mode 100644 index 0000000..dacc2fd --- /dev/null +++ b/src/components/bits/FaultyTerminal.css @@ -0,0 +1,6 @@ +.faulty-terminal-container { + width: 100%; + height: 100%; + position: relative; + overflow: hidden; +} diff --git a/src/components/bits/FaultyTerminal.tsx b/src/components/bits/FaultyTerminal.tsx new file mode 100644 index 0000000..cd9c5f0 --- /dev/null +++ b/src/components/bits/FaultyTerminal.tsx @@ -0,0 +1,439 @@ +// FaultyTerminal — from React Bits (https://github.com/DavidHDev/react-bits) +// Copyright (c) 2026 David Haz. MIT + Commons Clause. Adapted for yoyos.sh. +'use client'; + +import { Renderer, Program, Mesh, Color, Triangle } from 'ogl'; +import React, { useEffect, useRef, useMemo, useCallback } from 'react'; +import './FaultyTerminal.css'; + +type Vec2 = [number, number]; + +export interface FaultyTerminalProps extends React.HTMLAttributes { + scale?: number; + gridMul?: Vec2; + digitSize?: number; + timeScale?: number; + pause?: boolean; + scanlineIntensity?: number; + glitchAmount?: number; + flickerAmount?: number; + noiseAmp?: number; + chromaticAberration?: number; + dither?: number | boolean; + curvature?: number; + tint?: string; + mouseReact?: boolean; + mouseStrength?: number; + dpr?: number; + pageLoadAnimation?: boolean; + brightness?: number; + lightMode?: boolean; +} + +const vertexShader = ` +attribute vec2 position; +attribute vec2 uv; +varying vec2 vUv; +void main() { + vUv = uv; + gl_Position = vec4(position, 0.0, 1.0); +} +`; + +const fragmentShader = ` +precision mediump float; + +varying vec2 vUv; + +uniform float iTime; +uniform vec3 iResolution; +uniform float uScale; + +uniform vec2 uGridMul; +uniform float uDigitSize; +uniform float uScanlineIntensity; +uniform float uGlitchAmount; +uniform float uFlickerAmount; +uniform float uNoiseAmp; +uniform float uChromaticAberration; +uniform float uDither; +uniform float uCurvature; +uniform vec3 uTint; +uniform vec2 uMouse; +uniform float uMouseStrength; +uniform float uUseMouse; +uniform float uPageLoadProgress; +uniform float uUsePageLoadAnimation; +uniform float uBrightness; +uniform float uLightMode; + +float time; + +float hash21(vec2 p){ + p = fract(p * 234.56); + p += dot(p, p + 34.56); + return fract(p.x * p.y); +} + +float noise(vec2 p) +{ + return sin(p.x * 10.0) * sin(p.y * (3.0 + sin(time * 0.090909))) + 0.2; +} + +mat2 rotate(float angle) +{ + float c = cos(angle); + float s = sin(angle); + return mat2(c, -s, s, c); +} + +float fbm(vec2 p) +{ + p *= 1.1; + float f = 0.0; + float amp = 0.5 * uNoiseAmp; + + mat2 modify0 = rotate(time * 0.02); + f += amp * noise(p); + p = modify0 * p * 2.0; + amp *= 0.454545; + + mat2 modify1 = rotate(time * 0.02); + f += amp * noise(p); + p = modify1 * p * 2.0; + amp *= 0.454545; + + mat2 modify2 = rotate(time * 0.08); + f += amp * noise(p); + + return f; +} + +float pattern(vec2 p, out vec2 q, out vec2 r) { + vec2 offset1 = vec2(1.0); + vec2 offset0 = vec2(0.0); + mat2 rot01 = rotate(0.1 * time); + mat2 rot1 = rotate(0.1); + + q = vec2(fbm(p + offset1), fbm(rot01 * p + offset1)); + r = vec2(fbm(rot1 * q + offset0), fbm(q + offset0)); + return fbm(p + r); +} + +float digit(vec2 p){ + vec2 grid = uGridMul * 15.0; + vec2 s = floor(p * grid) / grid; + p = p * grid; + vec2 q, r; + float intensity = pattern(s * 0.1, q, r) * 1.3 - 0.03; + + if(uUseMouse > 0.5){ + vec2 mouseWorld = uMouse * uScale; + float distToMouse = distance(s, mouseWorld); + float mouseInfluence = exp(-distToMouse * 8.0) * uMouseStrength * 10.0; + intensity += mouseInfluence; + + float ripple = sin(distToMouse * 20.0 - iTime * 5.0) * 0.1 * mouseInfluence; + intensity += ripple; + } + + if(uUsePageLoadAnimation > 0.5){ + float cellRandom = fract(sin(dot(s, vec2(12.9898, 78.233))) * 43758.5453); + float cellDelay = cellRandom * 0.8; + float cellProgress = clamp((uPageLoadProgress - cellDelay) / 0.2, 0.0, 1.0); + + float fadeAlpha = smoothstep(0.0, 1.0, cellProgress); + intensity *= fadeAlpha; + } + + p = fract(p); + p *= uDigitSize; + + float px5 = p.x * 5.0; + float py5 = (1.0 - p.y) * 5.0; + float x = fract(px5); + float y = fract(py5); + + float i = floor(py5) - 2.0; + float j = floor(px5) - 2.0; + float n = i * i + j * j; + float f = n * 0.0625; + + float isOn = step(0.1, intensity - f); + float brightness = isOn * (0.2 + y * 0.8) * (0.75 + x * 0.25); + + return step(0.0, p.x) * step(p.x, 1.0) * step(0.0, p.y) * step(p.y, 1.0) * brightness; +} + +float onOff(float a, float b, float c) +{ + return step(c, sin(iTime + a * cos(iTime * b))) * uFlickerAmount; +} + +float displace(vec2 look) +{ + float y = look.y - mod(iTime * 0.25, 1.0); + float window = 1.0 / (1.0 + 50.0 * y * y); + return sin(look.y * 20.0 + iTime) * 0.0125 * onOff(4.0, 2.0, 0.8) * (1.0 + cos(iTime * 60.0)) * window; +} + +vec3 getColor(vec2 p){ + + float bar = step(mod(p.y + time * 20.0, 1.0), 0.2) * 0.4 + 1.0; + bar *= uScanlineIntensity; + + float displacement = displace(p); + p.x += displacement; + + if (uGlitchAmount != 1.0) { + float extra = displacement * (uGlitchAmount - 1.0); + p.x += extra; + } + + float middle = digit(p); + + const float off = 0.002; + float sum = digit(p + vec2(-off, -off)) + digit(p + vec2(0.0, -off)) + digit(p + vec2(off, -off)) + + digit(p + vec2(-off, 0.0)) + digit(p + vec2(0.0, 0.0)) + digit(p + vec2(off, 0.0)) + + digit(p + vec2(-off, off)) + digit(p + vec2(0.0, off)) + digit(p + vec2(off, off)); + + vec3 baseColor = vec3(0.9) * middle + sum * 0.1 * vec3(1.0) * bar; + return baseColor; +} + +vec2 barrel(vec2 uv){ + vec2 c = uv * 2.0 - 1.0; + float r2 = dot(c, c); + c *= 1.0 + uCurvature * r2; + return c * 0.5 + 0.5; +} + +void main() { + time = iTime * 0.333333; + vec2 uv = vUv; + + if(uCurvature != 0.0){ + uv = barrel(uv); + } + + vec2 p = uv * uScale; + vec3 col = getColor(p); + + if(uChromaticAberration != 0.0){ + vec2 ca = vec2(uChromaticAberration) / iResolution.xy; + col.r = getColor(p + ca).r; + col.b = getColor(p - ca).b; + } + + col *= uTint; + col *= uBrightness; + + if(uDither > 0.0){ + float rnd = hash21(gl_FragCoord.xy); + col += (rnd - 0.5) * (uDither * 0.003922); + } + + if (uLightMode > 0.5) { + float energy = max(max(col.r, col.g), col.b); + float coverage = clamp(smoothstep(0.0, 0.72, energy) * 0.9, 0.0, 0.9); + vec3 ink = clamp(col * 0.42, 0.0, 0.76); + col = mix(vec3(1.0), ink, coverage); + } + + gl_FragColor = vec4(col, 1.0); +} +`; + +function hexToRgb(hex: string): [number, number, number] { + let h = hex.replace('#', '').trim(); + if (h.length === 3) + h = h + .split('') + .map(c => c + c) + .join(''); + const num = parseInt(h.slice(0, 6), 16); + return [((num >> 16) & 255) / 255, ((num >> 8) & 255) / 255, (num & 255) / 255]; +} + +export default function FaultyTerminal({ + scale = 1, + gridMul = [2, 1], + digitSize = 1.5, + timeScale = 0.3, + pause = false, + scanlineIntensity = 0.3, + glitchAmount = 1, + flickerAmount = 1, + noiseAmp = 1, + chromaticAberration = 0, + dither = 0, + curvature = 0.2, + tint = '#ffffff', + mouseReact = true, + mouseStrength = 0.2, + dpr = Math.min(window.devicePixelRatio || 1, 2), + pageLoadAnimation = true, + brightness = 1, + lightMode = false, + className, + style, + ...rest +}: FaultyTerminalProps) { + const containerRef = useRef(null); + const programRef = useRef(null); + const rendererRef = useRef(null); + const mouseRef = useRef({ x: 0.5, y: 0.5 }); + const smoothMouseRef = useRef({ x: 0.5, y: 0.5 }); + const frozenTimeRef = useRef(0); + const rafRef = useRef(0); + const loadAnimationStartRef = useRef(0); + const timeOffsetRef = useRef(Math.random() * 100); + + const tintVec = useMemo(() => hexToRgb(tint), [tint]); + + const ditherValue = useMemo(() => (typeof dither === 'boolean' ? (dither ? 1 : 0) : dither), [dither]); + + const handleMouseMove = useCallback((e: MouseEvent) => { + const ctn = containerRef.current; + if (!ctn) return; + const rect = ctn.getBoundingClientRect(); + const x = (e.clientX - rect.left) / rect.width; + const y = 1 - (e.clientY - rect.top) / rect.height; + mouseRef.current = { x, y }; + }, []); + + useEffect(() => { + const ctn = containerRef.current; + if (!ctn) return; + + const renderer = new Renderer({ dpr }); + rendererRef.current = renderer; + const gl = renderer.gl; + gl.clearColor(lightMode ? 1 : 0, lightMode ? 1 : 0, lightMode ? 1 : 0, 1); + + const geometry = new Triangle(gl); + + const program = new Program(gl, { + vertex: vertexShader, + fragment: fragmentShader, + uniforms: { + iTime: { value: 0 }, + iResolution: { + value: new Color(gl.canvas.width, gl.canvas.height, gl.canvas.width / gl.canvas.height) + }, + uScale: { value: scale }, + + uGridMul: { value: new Float32Array(gridMul) }, + uDigitSize: { value: digitSize }, + uScanlineIntensity: { value: scanlineIntensity }, + uGlitchAmount: { value: glitchAmount }, + uFlickerAmount: { value: flickerAmount }, + uNoiseAmp: { value: noiseAmp }, + uChromaticAberration: { value: chromaticAberration }, + uDither: { value: ditherValue }, + uCurvature: { value: curvature }, + uTint: { value: new Color(tintVec[0], tintVec[1], tintVec[2]) }, + uMouse: { + value: new Float32Array([smoothMouseRef.current.x, smoothMouseRef.current.y]) + }, + uMouseStrength: { value: mouseStrength }, + uUseMouse: { value: mouseReact ? 1 : 0 }, + uPageLoadProgress: { value: pageLoadAnimation ? 0 : 1 }, + uUsePageLoadAnimation: { value: pageLoadAnimation ? 1 : 0 }, + uBrightness: { value: brightness }, + uLightMode: { value: lightMode ? 1 : 0 } + } + }); + programRef.current = program; + + const mesh = new Mesh(gl, { geometry, program }); + + function resize() { + if (!ctn || !renderer) return; + renderer.setSize(ctn.offsetWidth, ctn.offsetHeight); + program.uniforms.iResolution.value = new Color( + gl.canvas.width, + gl.canvas.height, + gl.canvas.width / gl.canvas.height + ); + } + + const resizeObserver = new ResizeObserver(() => resize()); + resizeObserver.observe(ctn); + resize(); + + const update = (t: number) => { + rafRef.current = requestAnimationFrame(update); + + if (pageLoadAnimation && loadAnimationStartRef.current === 0) { + loadAnimationStartRef.current = t; + } + + if (!pause) { + const elapsed = (t * 0.001 + timeOffsetRef.current) * timeScale; + program.uniforms.iTime.value = elapsed; + frozenTimeRef.current = elapsed; + } else { + program.uniforms.iTime.value = frozenTimeRef.current; + } + + if (pageLoadAnimation && loadAnimationStartRef.current > 0) { + const animationDuration = 2000; + const animationElapsed = t - loadAnimationStartRef.current; + const progress = Math.min(animationElapsed / animationDuration, 1); + program.uniforms.uPageLoadProgress.value = progress; + } + + if (mouseReact) { + const dampingFactor = 0.08; + const smoothMouse = smoothMouseRef.current; + const mouse = mouseRef.current; + smoothMouse.x += (mouse.x - smoothMouse.x) * dampingFactor; + smoothMouse.y += (mouse.y - smoothMouse.y) * dampingFactor; + + const mouseUniform = program.uniforms.uMouse.value as Float32Array; + mouseUniform[0] = smoothMouse.x; + mouseUniform[1] = smoothMouse.y; + } + + renderer.render({ scene: mesh }); + }; + rafRef.current = requestAnimationFrame(update); + ctn.appendChild(gl.canvas); + + if (mouseReact) ctn.addEventListener('mousemove', handleMouseMove); + + return () => { + cancelAnimationFrame(rafRef.current); + resizeObserver.disconnect(); + if (mouseReact) ctn.removeEventListener('mousemove', handleMouseMove); + if (gl.canvas.parentElement === ctn) ctn.removeChild(gl.canvas); + gl.getExtension('WEBGL_lose_context')?.loseContext(); + loadAnimationStartRef.current = 0; + timeOffsetRef.current = Math.random() * 100; + }; + }, [ + dpr, + pause, + timeScale, + scale, + gridMul, + digitSize, + scanlineIntensity, + glitchAmount, + flickerAmount, + noiseAmp, + chromaticAberration, + ditherValue, + curvature, + tintVec, + mouseReact, + mouseStrength, + pageLoadAnimation, + brightness, + lightMode, + handleMouseMove + ]); + + return
; +} diff --git a/src/components/bits/HalftoneReveal.css b/src/components/bits/HalftoneReveal.css new file mode 100644 index 0000000..4003cc4 --- /dev/null +++ b/src/components/bits/HalftoneReveal.css @@ -0,0 +1,14 @@ +.halftone-reveal { + position: relative; + width: 100%; + height: 100%; + overflow: hidden; + touch-action: none; + cursor: crosshair; +} + +.halftone-reveal canvas { + display: block; + width: 100%; + height: 100%; +} diff --git a/src/components/bits/HalftoneReveal.tsx b/src/components/bits/HalftoneReveal.tsx new file mode 100644 index 0000000..0b4150a --- /dev/null +++ b/src/components/bits/HalftoneReveal.tsx @@ -0,0 +1,385 @@ +// HalftoneReveal — from React Bits (https://github.com/DavidHDev/react-bits) +// Copyright (c) 2026 David Haz. MIT + Commons Clause. Adapted for yoyos.sh. +'use client'; + +import { useRef, useEffect, type CSSProperties } from 'react'; +import { Renderer, Program, Triangle, Mesh, Texture } from 'ogl'; + +import './HalftoneReveal.css'; + +const DEFAULT_SRC = 'https://picsum.photos/seed/halftone-reveal/1200/800'; + +const hexToRgb = (hex: string): [number, number, number] => { + const m = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex || ''); + return m ? [parseInt(m[1], 16) / 255, parseInt(m[2], 16) / 255, parseInt(m[3], 16) / 255] : [0, 0, 0]; +}; + +type Mode = 'mono' | 'duotone' | 'color'; +type Shape = 'circle' | 'square' | 'diamond' | 'line'; +type Trigger = 'off' | 'hover' | 'always'; + +const MODES: Record = { mono: 0, duotone: 1, color: 2 }; +const SHAPES: Record = { circle: 0, square: 1, diamond: 2, line: 3 }; +const TRIGGERS: Record = { off: 0, hover: 1, always: 2 }; + +export interface HalftoneRevealProps { + src?: string; + inkColor?: string; + paperColor?: string; + mode?: Mode; + dotSize?: number; + dotDensity?: number; + angle?: number; + shape?: Shape; + contrast?: number; + invert?: boolean; + revealRadius?: number; + edge?: number; + follow?: number; + idleReveal?: number; + trigger?: Trigger; + borderRadius?: string; + className?: string; + style?: CSSProperties; +} + +const vertex = `#version 300 es +in vec2 position; +out vec2 vUv; +void main() { + vUv = position * 0.5 + 0.5; + gl_Position = vec4(position, 0.0, 1.0); +} +`; + +const fragment = `#version 300 es +precision highp float; + +uniform sampler2D tMap; +uniform vec2 iResolution; +uniform vec2 uImageSize; +uniform vec2 uMouse; +uniform float uActivity; + +uniform float uDotSize; +uniform float uDensity; +uniform float uAngle; +uniform int uShape; +uniform vec3 uInk; +uniform vec3 uPaper; +uniform int uMode; +uniform float uContrast; +uniform float uInvert; + +uniform float uRevealRadius; +uniform float uEdge; +uniform float uIdleReveal; +uniform int uTrigger; + +in vec2 vUv; +out vec4 fragColor; + +vec2 uAspect() { + return vec2(iResolution.x / max(iResolution.y, 1.0), 1.0); +} + +vec2 coverUv(vec2 uv) { + float ia = uImageSize.x / max(uImageSize.y, 1.0); + float pa = iResolution.x / max(iResolution.y, 1.0); + vec2 s = pa > ia ? vec2(1.0, ia / pa) : vec2(pa / ia, 1.0); + return (uv - 0.5) * s + 0.5; +} + +vec3 gradeRGB(vec3 c) { + c = clamp((c - 0.5) * uContrast + 0.5, 0.0, 1.0); + return mix(c, 1.0 - c, uInvert); +} + +float shapeDist(vec2 f) { + if (uShape == 1) return max(abs(f.x), abs(f.y)); + if (uShape == 2) return abs(f.x) + abs(f.y); + if (uShape == 3) return abs(f.y); + return length(f); +} + +mat2 rot(float a) { + float c = cos(a); + float s = sin(a); + return mat2(c, -s, s, c); +} + +vec4 sampleCell(vec2 st, float dens, float ang) { + vec2 rp = rot(ang) * st * dens; + vec2 center = floor(rp) + 0.5; + vec2 stC = rot(-ang) * (center / dens); + vec2 uvC = stC / uAspect(); + return texture(tMap, clamp(coverUv(uvC), 0.0, 1.0)); +} + +float coverage(vec2 st, float dens, float ang, float ink, float rscale) { + vec2 rp = rot(ang) * st * dens; + vec2 f = fract(rp) - 0.5; + float d = shapeDist(f); + float r = sqrt(clamp(ink, 0.0, 1.0)) * 0.72 * rscale * uDotSize; + float w = length(fwidth(rp)) * 0.6 + 1e-4; + return smoothstep(r + w, r - w, d); +} + +void main() { + vec2 aspect = uAspect(); + vec2 st = vUv * aspect; + float ang = radians(uAngle); + + vec2 duv = (vUv - uMouse) * aspect; + float dist = length(duv); + + float act = uTrigger == 2 ? 1.0 : (uTrigger == 0 ? 0.0 : uActivity); + float radius = max(uRevealRadius, 1e-4) * mix(0.4, 1.0, act); + + float px = 1.4 / max(iResolution.y, 1.0); + float band = max(px, radius * (1.0 - clamp(uEdge, 0.0, 1.0)) * 0.45); + float loupe = 1.0 - smoothstep(radius - band, radius + band, dist); + float focus = clamp(max(loupe * act, uIdleReveal), 0.0, 1.0); + + float dens = uDensity; + + vec3 print; + if (uMode == 2) { + vec3 gc = gradeRGB(sampleCell(st, dens, ang + radians(15.0)).rgb); + vec3 gm = gradeRGB(sampleCell(st, dens, ang + radians(75.0)).rgb); + vec3 gy = gradeRGB(sampleCell(st, dens, ang).rgb); + vec3 gk = gradeRGB(sampleCell(st, dens, ang + radians(45.0)).rgb); + float c = 1.0 - gc.r; + float m = 1.0 - gm.g; + float y = 1.0 - gy.b; + float k = 1.0 - dot(gk, vec3(0.299, 0.587, 0.114)); + float gcr = min(min(c, m), y) * 0.5; + c = clamp(c - gcr, 0.0, 1.0); + m = clamp(m - gcr, 0.0, 1.0); + y = clamp(y - gcr, 0.0, 1.0); + k = clamp(max(gcr, k * k * 0.9), 0.0, 1.0); + float covC = coverage(st, dens, ang + radians(15.0), c, 0.82); + float covM = coverage(st, dens, ang + radians(75.0), m, 0.82); + float covY = coverage(st, dens, ang, y, 0.82); + float covK = coverage(st, dens, ang + radians(45.0), k, 0.78); + print = uPaper; + print = mix(print, print * vec3(0.10, 0.72, 0.90), covC); + print = mix(print, print * vec3(0.92, 0.10, 0.52), covM); + print = mix(print, print * vec3(0.98, 0.86, 0.10), covY); + print = mix(print, print * vec3(0.08), covK); + } else if (uMode == 1) { + vec3 ink2 = mix(uInk.gbr, vec3(0.90, 0.24, 0.30), 0.7); + float lumA = dot(gradeRGB(sampleCell(st, dens, ang).rgb), vec3(0.299, 0.587, 0.114)); + float lumB = dot(gradeRGB(sampleCell(st, dens, ang + radians(38.0)).rgb), vec3(0.299, 0.587, 0.114)); + float covA = coverage(st, dens, ang, 1.0 - lumA, 1.0); + float covB = coverage(st, dens, ang + radians(38.0), pow(1.0 - lumB, 1.4), 0.92); + print = uPaper; + print = mix(print, ink2, covB * 0.85); + print = mix(print, uInk, covA); + } else { + float lum = dot(gradeRGB(sampleCell(st, dens, ang).rgb), vec3(0.299, 0.587, 0.114)); + float cov = coverage(st, dens, ang, 1.0 - lum, 1.0); + print = mix(uPaper, uInk, cov); + } + + float t = clamp(dist / radius, 0.0, 1.0); + float bend = t * t * t * t; + vec2 dir = dist > 1e-5 ? duv / dist : vec2(0.0); + vec2 off = dir * bend * radius * 0.22 / aspect; + vec2 ca = dir * bend * 0.0045 / aspect; + vec3 sharp = gradeRGB(vec3( + texture(tMap, clamp(coverUv(vUv - off - ca), 0.0, 1.0)).r, + texture(tMap, clamp(coverUv(vUv - off), 0.0, 1.0)).g, + texture(tMap, clamp(coverUv(vUv - off + ca), 0.0, 1.0)).b + )); + + vec3 col = mix(print, sharp, focus); + fragColor = vec4(col, 1.0); +} +`; + +const HalftoneReveal = ({ + src = DEFAULT_SRC, + inkColor = '#141414', + paperColor = '#fff7e6', + mode = 'mono', + dotSize = 1, + dotDensity = 71, + angle = 45, + shape = 'circle', + contrast = 1.15, + invert = false, + revealRadius = 0.4, + edge = 0.8, + follow = 0.37, + idleReveal = 0, + trigger = 'hover', + borderRadius = '16px', + className = '', + style +}: HalftoneRevealProps) => { + const containerRef = useRef(null); + const rendererRef = useRef(null); + const uniformsRef = useRef | null>(null); + const rafRef = useRef(null); + const followRef = useRef(follow); + const mouseRef = useRef({ x: 0.5, y: 0.5, sx: 0.5, sy: 0.5, active: 0, target: 0 }); + + useEffect(() => { + followRef.current = follow; + }, [follow]); + + useEffect(() => { + const container = containerRef.current; + if (!container) return; + + const reduced = + typeof window !== 'undefined' && + window.matchMedia && + window.matchMedia('(prefers-reduced-motion: reduce)').matches; + + const renderer = new Renderer({ + dpr: Math.min(window.devicePixelRatio || 1, 2), + alpha: false, + antialias: true + }); + rendererRef.current = renderer; + const gl = renderer.gl; + gl.clearColor(0, 0, 0, 1); + gl.canvas.style.width = '100%'; + gl.canvas.style.height = '100%'; + gl.canvas.style.display = 'block'; + container.appendChild(gl.canvas); + + const texture = new Texture(gl, { generateMipmaps: false }); + + const uniforms = { + tMap: { value: texture }, + iResolution: { value: [1, 1] }, + uImageSize: { value: [1, 1] }, + uMouse: { value: [0.5, 0.5] }, + uActivity: { value: 0 }, + uDotSize: { value: dotSize }, + uDensity: { value: dotDensity }, + uAngle: { value: angle }, + uShape: { value: SHAPES[shape] ?? 0 }, + uInk: { value: hexToRgb(inkColor) }, + uPaper: { value: hexToRgb(paperColor) }, + uMode: { value: MODES[mode] ?? 0 }, + uContrast: { value: contrast }, + uInvert: { value: invert ? 1 : 0 }, + uRevealRadius: { value: revealRadius }, + uEdge: { value: edge }, + uIdleReveal: { value: idleReveal }, + uTrigger: { value: TRIGGERS[trigger] ?? 1 } + }; + uniformsRef.current = uniforms; + + const program = new Program(gl, { vertex, fragment, uniforms }); + const mesh = new Mesh(gl, { geometry: new Triangle(gl), program }); + + const img = new Image(); + img.crossOrigin = 'anonymous'; + img.src = src; + img.onload = () => { + texture.image = img; + uniforms.uImageSize.value = [img.naturalWidth, img.naturalHeight]; + }; + + const resize = () => { + const w = container.clientWidth || 1; + const h = container.clientHeight || 1; + renderer.setSize(w, h); + uniforms.iResolution.value = [gl.canvas.width, gl.canvas.height]; + }; + resize(); + const ro = new ResizeObserver(resize); + ro.observe(container); + + const onMove = (e: PointerEvent) => { + const rect = container.getBoundingClientRect(); + mouseRef.current.x = (e.clientX - rect.left) / rect.width; + mouseRef.current.y = 1 - (e.clientY - rect.top) / rect.height; + mouseRef.current.target = reduced ? 0 : 1; + }; + const onLeave = () => { + mouseRef.current.target = 0; + }; + container.addEventListener('pointermove', onMove, { passive: true }); + container.addEventListener('pointerenter', onMove, { passive: true }); + container.addEventListener('pointerleave', onLeave, { passive: true }); + + let prev = performance.now(); + const loop = (now: number) => { + rafRef.current = requestAnimationFrame(loop); + const dt = Math.min(0.05, Math.max(0.001, (now - prev) / 1000)); + prev = now; + + const m = mouseRef.current; + const a = 1 - Math.exp(-dt / Math.max(0.001, followRef.current)); + m.sx += (m.x - m.sx) * a; + m.sy += (m.y - m.sy) * a; + const ba = 1 - Math.exp(-dt / 0.18); + m.active += (m.target - m.active) * ba; + + uniforms.uMouse.value[0] = m.sx; + uniforms.uMouse.value[1] = m.sy; + uniforms.uActivity.value = m.active; + + renderer.render({ scene: mesh }); + }; + rafRef.current = requestAnimationFrame(loop); + + return () => { + if (rafRef.current) cancelAnimationFrame(rafRef.current); + ro.disconnect(); + container.removeEventListener('pointermove', onMove); + container.removeEventListener('pointerenter', onMove); + container.removeEventListener('pointerleave', onLeave); + const ext = gl.getExtension('WEBGL_lose_context'); + if (ext) ext.loseContext(); + if (gl.canvas.parentNode) gl.canvas.parentNode.removeChild(gl.canvas); + rendererRef.current = null; + uniformsRef.current = null; + }; + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [src]); + + useEffect(() => { + const u = uniformsRef.current; + if (!u) return; + u.uDotSize.value = dotSize; + u.uDensity.value = dotDensity; + u.uAngle.value = angle; + u.uShape.value = SHAPES[shape] ?? 0; + u.uInk.value = hexToRgb(inkColor); + u.uPaper.value = hexToRgb(paperColor); + u.uMode.value = MODES[mode] ?? 0; + u.uContrast.value = contrast; + u.uInvert.value = invert ? 1 : 0; + u.uRevealRadius.value = revealRadius; + u.uEdge.value = edge; + u.uIdleReveal.value = idleReveal; + u.uTrigger.value = TRIGGERS[trigger] ?? 1; + }, [ + dotSize, + dotDensity, + angle, + shape, + inkColor, + paperColor, + mode, + contrast, + invert, + revealRadius, + edge, + idleReveal, + trigger + ]); + + return ( +
+ ); +}; + +export default HalftoneReveal; diff --git a/src/components/bits/ScrambledText.css b/src/components/bits/ScrambledText.css new file mode 100644 index 0000000..243e8f0 --- /dev/null +++ b/src/components/bits/ScrambledText.css @@ -0,0 +1,12 @@ +.text-block { + margin: 7vw; + max-width: 800px; + font-family: monospace; + font-size: clamp(14px, 4vw, 32px); + color: #fff; +} + +.char { + will-change: transform; + display: inline-block; +} diff --git a/src/components/bits/ScrambledText.tsx b/src/components/bits/ScrambledText.tsx new file mode 100644 index 0000000..5330134 --- /dev/null +++ b/src/components/bits/ScrambledText.tsx @@ -0,0 +1,90 @@ +// ScrambledText — from React Bits (https://github.com/DavidHDev/react-bits) +// Copyright (c) 2026 David Haz. MIT + Commons Clause. Adapted for yoyos.sh. +'use client'; + +import React, { useEffect, useRef } from 'react'; +import { gsap } from 'gsap'; +import { SplitText } from 'gsap/SplitText'; +import { ScrambleTextPlugin } from 'gsap/ScrambleTextPlugin'; + +import './ScrambledText.css'; + +gsap.registerPlugin(SplitText, ScrambleTextPlugin); + +export interface ScrambledTextProps { + radius?: number; + duration?: number; + speed?: number; + scrambleChars?: string; + className?: string; + style?: React.CSSProperties; + children: React.ReactNode; +} + +const ScrambledText: React.FC = ({ + radius = 100, + duration = 1.2, + speed = 0.5, + scrambleChars = '.:', + className = '', + style = {}, + children +}) => { + const rootRef = useRef(null); + const charsRef = useRef([]); + + useEffect(() => { + if (!rootRef.current) return; + + const split = SplitText.create(rootRef.current.querySelector('p'), { + type: 'chars', + charsClass: 'char' + }); + charsRef.current = split.chars as HTMLElement[]; + + charsRef.current.forEach(c => { + gsap.set(c, { + display: 'inline-block', + attr: { 'data-content': c.innerHTML } + }); + }); + + const handleMove = (e: PointerEvent) => { + charsRef.current.forEach(c => { + const { left, top, width, height } = c.getBoundingClientRect(); + const dx = e.clientX - (left + width / 2); + const dy = e.clientY - (top + height / 2); + const dist = Math.hypot(dx, dy); + + if (dist < radius) { + gsap.to(c, { + overwrite: true, + duration: duration * (1 - dist / radius), + scrambleText: { + text: (c as HTMLElement).dataset.content || '', + chars: scrambleChars, + speed + }, + ease: 'none' + }); + } + }); + }; + + const el = rootRef.current; + el.addEventListener('pointermove', handleMove); + + return () => { + el.removeEventListener('pointermove', handleMove); + split.revert(); + }; + }, [radius, duration, speed, scrambleChars]); + + return ( +
+

{children}

+
+ ); +}; + +export default ScrambledText; diff --git a/src/components/bits/ScrollVelocity.css b/src/components/bits/ScrollVelocity.css new file mode 100644 index 0000000..21159a2 --- /dev/null +++ b/src/components/bits/ScrollVelocity.css @@ -0,0 +1,26 @@ +.parallax { + position: relative; + overflow: hidden; +} + +.scroller { + display: flex; + white-space: nowrap; + text-align: center; + font-family: sans-serif; + font-size: 2.25rem; + font-weight: bold; + letter-spacing: -0.02em; + filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.1)); +} + +.scroller span { + flex-shrink: 0; +} + +@media (min-width: 768px) { + .scroller { + font-size: 5rem; + line-height: 5rem; + } +} diff --git a/src/components/bits/ScrollVelocity.tsx b/src/components/bits/ScrollVelocity.tsx new file mode 100644 index 0000000..8d01797 --- /dev/null +++ b/src/components/bits/ScrollVelocity.tsx @@ -0,0 +1,182 @@ +// ScrollVelocity — from React Bits (https://github.com/DavidHDev/react-bits) +// Copyright (c) 2026 David Haz. MIT + Commons Clause. Adapted for yoyos.sh. +'use client'; + +import React, { useRef, useLayoutEffect, useState } from 'react'; +import { + motion, + useScroll, + useSpring, + useTransform, + useMotionValue, + useVelocity, + useAnimationFrame +} from 'motion/react'; +import './ScrollVelocity.css'; + +interface VelocityMapping { + input: [number, number]; + output: [number, number]; +} + +interface VelocityTextProps { + children: React.ReactNode; + baseVelocity: number; + scrollContainerRef?: React.RefObject; + className?: string; + damping?: number; + stiffness?: number; + numCopies?: number; + velocityMapping?: VelocityMapping; + parallaxClassName?: string; + scrollerClassName?: string; + parallaxStyle?: React.CSSProperties; + scrollerStyle?: React.CSSProperties; +} + +interface ScrollVelocityProps { + scrollContainerRef?: React.RefObject; + texts: React.ReactNode[]; + velocity?: number; + className?: string; + damping?: number; + stiffness?: number; + numCopies?: number; + velocityMapping?: VelocityMapping; + parallaxClassName?: string; + scrollerClassName?: string; + parallaxStyle?: React.CSSProperties; + scrollerStyle?: React.CSSProperties; +} + +function useElementWidth(ref: React.RefObject): number { + const [width, setWidth] = useState(0); + + useLayoutEffect(() => { + function updateWidth() { + if (ref.current) { + setWidth(ref.current.offsetWidth); + } + } + updateWidth(); + window.addEventListener('resize', updateWidth); + return () => window.removeEventListener('resize', updateWidth); + }, [ref]); + + return width; +} + +export const ScrollVelocity: React.FC = ({ + scrollContainerRef, + texts = [], + velocity = 100, + className = '', + damping = 50, + stiffness = 400, + numCopies = 6, + velocityMapping = { input: [0, 1000], output: [0, 5] }, + parallaxClassName = 'parallax', + scrollerClassName = 'scroller', + parallaxStyle, + scrollerStyle +}) => { + function VelocityText({ + children, + baseVelocity = velocity, + scrollContainerRef, + className = '', + damping, + stiffness, + numCopies, + velocityMapping, + parallaxClassName, + scrollerClassName, + parallaxStyle, + scrollerStyle + }: VelocityTextProps) { + const baseX = useMotionValue(0); + const scrollOptions = scrollContainerRef ? { container: scrollContainerRef } : {}; + const { scrollY } = useScroll(scrollOptions); + const scrollVelocity = useVelocity(scrollY); + const smoothVelocity = useSpring(scrollVelocity, { + damping: damping ?? 50, + stiffness: stiffness ?? 400 + }); + const velocityFactor = useTransform( + smoothVelocity, + velocityMapping?.input || [0, 1000], + velocityMapping?.output || [0, 5], + { clamp: false } + ); + + const copyRef = useRef(null); + const copyWidth = useElementWidth(copyRef); + + function wrap(min: number, max: number, v: number): number { + const range = max - min; + const mod = (((v - min) % range) + range) % range; + return mod + min; + } + + const x = useTransform(baseX, v => { + if (copyWidth === 0) return '0px'; + return `${wrap(-copyWidth, 0, v)}px`; + }); + + const directionFactor = useRef(1); + useAnimationFrame((t, delta) => { + let moveBy = directionFactor.current * baseVelocity * (delta / 1000); + + if (velocityFactor.get() < 0) { + directionFactor.current = -1; + } else if (velocityFactor.get() > 0) { + directionFactor.current = 1; + } + + moveBy += directionFactor.current * moveBy * velocityFactor.get(); + baseX.set(baseX.get() + moveBy); + }); + + const spans = []; + for (let i = 0; i < (numCopies ?? 6); i++) { + spans.push( + + {children}  + + ); + } + + return ( +
+ + {spans} + +
+ ); + } + + return ( +
+ {texts.map((text, index) => ( + + {text} + + ))} +
+ ); +}; + +export default ScrollVelocity; diff --git a/src/components/bits/SplitFlapText.css b/src/components/bits/SplitFlapText.css new file mode 100644 index 0000000..3e8a737 --- /dev/null +++ b/src/components/bits/SplitFlapText.css @@ -0,0 +1,170 @@ +.split-flap-text { + display: inline-flex; + align-items: center; + gap: var(--split-flap-gap, 6px); + color: var(--split-flap-text-color, #f8fafc); + font-family: 'SFMono-Regular', 'Roboto Mono', 'Cascadia Code', 'Liberation Mono', Menlo, monospace; + font-size: var(--split-flap-font-size, 52px); + font-weight: 760; + line-height: 1; + letter-spacing: 0.035em; + white-space: pre; + user-select: none; + font-variant-numeric: tabular-nums; +} + +.split-flap-text__tile { + position: relative; + width: 0.78em; + height: 1.08em; + overflow: hidden; + border-radius: var(--split-flap-radius, 8px); + background: + radial-gradient(circle at 50% 0%, rgba(255, 255, 255, 0.16), transparent 44%), + linear-gradient( + 180deg, + color-mix(in srgb, var(--split-flap-tile-color, #111827) 82%, white), + var(--split-flap-tile-color, #111827) + ); + box-shadow: + 0 0.035em 0.08em rgba(255, 255, 255, 0.08) inset, + 0 -0.05em 0.1em rgba(0, 0, 0, 0.38) inset, + 0 0.16em 0.38em rgba(0, 0, 0, 0.28); + perspective: 520px; + transform-style: preserve-3d; + isolation: isolate; +} + +.split-flap-text__tile::before { + content: ''; + position: absolute; + z-index: 8; + top: calc(50% - 0.5px); + left: 0; + width: 100%; + height: 1px; + background: linear-gradient( + 90deg, + transparent, + rgba(255, 255, 255, 0.18) 18%, + rgba(0, 0, 0, 0.64) 50%, + rgba(255, 255, 255, 0.14) 82%, + transparent + ); + box-shadow: + 0 -1px 0 rgba(255, 255, 255, 0.08), + 0 1px 0 rgba(0, 0, 0, 0.5); + pointer-events: none; +} + +.split-flap-text__tile::after { + content: ''; + position: absolute; + inset: 0; + z-index: 9; + border: 1px solid rgba(255, 255, 255, 0.08); + border-radius: inherit; + box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.2) inset; + pointer-events: none; +} + +.split-flap-text__half, +.split-flap-text__flap { + position: absolute; + left: 0; + width: 100%; + height: 50%; + overflow: hidden; + background: + linear-gradient(180deg, rgba(255, 255, 255, 0.07), transparent 34%), var(--split-flap-tile-color, #111827); + backface-visibility: hidden; +} + +.split-flap-text__half--top, +.split-flap-text__flap--front { + top: 0; +} + +.split-flap-text__half--bottom, +.split-flap-text__flap--back { + bottom: 0; +} + +.split-flap-text__half--bottom, +.split-flap-text__flap--back { + background: + linear-gradient(0deg, rgba(255, 255, 255, 0.06), transparent 38%), + color-mix(in srgb, var(--split-flap-tile-color, #111827) 92%, black); +} + +.split-flap-text__char { + position: absolute; + left: 0; + width: 100%; + height: 200%; + display: flex; + align-items: center; + justify-content: center; + color: var(--split-flap-text-color, #f8fafc); + text-shadow: + 0 0.025em 0 rgba(255, 255, 255, 0.16), + 0 0.09em 0.16em rgba(0, 0, 0, 0.42); +} + +.split-flap-text__half--top .split-flap-text__char, +.split-flap-text__flap--front .split-flap-text__char { + top: 0; +} + +.split-flap-text__half--bottom .split-flap-text__char, +.split-flap-text__flap--back .split-flap-text__char { + bottom: 0; +} + +.split-flap-text__flap { + z-index: 6; + will-change: transform, filter; + transform-style: preserve-3d; +} + +.split-flap-text__flap--front { + transform-origin: center bottom; + animation: split-flap-front var(--split-flap-flip-duration, 0.12s) cubic-bezier(0.23, 1, 0.32, 1) both; +} + +.split-flap-text__flap--back { + transform-origin: center top; + transform: rotateX(90deg); + animation: split-flap-back var(--split-flap-flip-duration, 0.12s) cubic-bezier(0.23, 1, 0.32, 1) both; +} + +@keyframes split-flap-front { + 0% { + transform: rotateX(0deg); + filter: brightness(1.08); + } + + 100% { + transform: rotateX(-90deg); + filter: brightness(0.52); + } +} + +@keyframes split-flap-back { + 0%, + 45% { + transform: rotateX(90deg); + filter: brightness(0.58); + } + + 100% { + transform: rotateX(0deg); + filter: brightness(1); + } +} + +@media (prefers-reduced-motion: reduce) { + .split-flap-text__flap { + animation: none !important; + } +} diff --git a/src/components/bits/SplitFlapText.tsx b/src/components/bits/SplitFlapText.tsx new file mode 100644 index 0000000..140dd8c --- /dev/null +++ b/src/components/bits/SplitFlapText.tsx @@ -0,0 +1,355 @@ +// SplitFlapText — from React Bits (https://github.com/DavidHDev/react-bits) +// Copyright (c) 2026 David Haz. MIT + Commons Clause. Adapted for yoyos.sh. +'use client'; + +import { type CSSProperties, type HTMLAttributes, useEffect, useMemo, useRef, useState } from 'react'; +import './SplitFlapText.css'; + +type TileState = { + current: string; + next: string; + flipping: boolean; + tick: number; +}; + +type AnimationPlan = { + index: number; + from: string; + target: string; + sequence: string[]; + start: number; + step: number; + done: boolean; +}; + +type TileUpdate = { + index: number; + current: string; + next: string; + done: boolean; +}; + +export interface SplitFlapTextProps extends HTMLAttributes { + words?: string[]; + text?: string; + flipDuration?: number; + stagger?: number; + cycleDelay?: number; + charset?: 'alpha' | 'alphanumeric' | 'numeric' | (string & {}); + flipsPerChar?: number; + tileColor?: string; + textColor?: string; + tileRadius?: number | string; + gap?: number | string; + fontSize?: number | string; + loop?: boolean; + padTo?: number; +} + +const DEFAULT_WORDS = ['LAUNCH READY', 'SYNC ONLINE', 'SIGNAL LIVE']; + +const CHARSETS: Record = { + alpha: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', + alphanumeric: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789', + numeric: '0123456789' +}; + +const toCssUnit = (value: number | string) => (typeof value === 'number' ? `${value}px` : value); + +const resolveCharset = (charset: SplitFlapTextProps['charset']) => { + if (charset && CHARSETS[charset]) return CHARSETS[charset]; + return typeof charset === 'string' && charset.length > 0 ? charset : CHARSETS.alphanumeric; +}; + +const normalizePhrase = (phrase: string, width: number) => { + const safe = String(phrase ?? ''); + return safe.padEnd(width, ' ').slice(0, width); +}; + +const createTiles = (phrase: string): TileState[] => + phrase.split('').map(char => ({ + current: char, + next: char, + flipping: false, + tick: 0 + })); + +const sampleChar = (charset: string) => charset.charAt(Math.floor(Math.random() * charset.length)) || ' '; + +const buildSequence = (target: string, flips: number, charset: string) => { + const steps: string[] = []; + for (let i = 0; i < flips; i += 1) { + steps.push(sampleChar(charset)); + } + steps.push(target); + return steps; +}; + +const usePrefersReducedMotion = () => { + const [prefersReduced, setPrefersReduced] = useState(false); + + useEffect(() => { + if (typeof window === 'undefined' || !window.matchMedia) return; + + const mediaQuery = window.matchMedia('(prefers-reduced-motion: reduce)'); + const handleChange = () => setPrefersReduced(mediaQuery.matches); + + handleChange(); + mediaQuery.addEventListener('change', handleChange); + + return () => mediaQuery.removeEventListener('change', handleChange); + }, []); + + return prefersReduced; +}; + +const SplitFlapText = ({ + words = ['LAUNCH READY', 'SYNC ONLINE', 'SIGNAL LIVE'], + text, + flipDuration = 0.12, + stagger = 0.06, + cycleDelay = 2400, + charset = 'alphanumeric', + flipsPerChar = 8, + tileColor = '#111827', + textColor = '#f8fafc', + tileRadius = 8, + gap = 6, + fontSize = 52, + loop = true, + padTo = 12, + className = '', + style = {}, + ...props +}: SplitFlapTextProps) => { + const prefersReducedMotion = usePrefersReducedMotion(); + const rafRef = useRef(null); + const cycleTimerRef = useRef(null); + const currentTextRef = useRef(''); + + const sourceWords = Array.isArray(words) && words.length > 0 ? words : DEFAULT_WORDS; + const phrasesKey = typeof text === 'string' ? text : sourceWords.map(word => String(word ?? '')).join('\u001f'); + const phrases = useMemo(() => phrasesKey.split('\u001f'), [phrasesKey]); + + const width = useMemo(() => { + const longest = phrases.reduce((max, phrase) => Math.max(max, phrase.length), 1); + return Math.max(1, Math.ceil(Number(padTo) || 0), longest); + }, [padTo, phrases]); + + const normalizedPhrases = useMemo(() => phrases.map(phrase => normalizePhrase(phrase, width)), [phrases, width]); + + const [tiles, setTiles] = useState(() => createTiles(normalizedPhrases[0] || '')); + + useEffect(() => { + const clearAnimation = () => { + if (rafRef.current) { + cancelAnimationFrame(rafRef.current); + rafRef.current = null; + } + + if (cycleTimerRef.current) { + clearTimeout(cycleTimerRef.current); + cycleTimerRef.current = null; + } + }; + + clearAnimation(); + + const firstPhrase = normalizedPhrases[0] || ''; + currentTextRef.current = firstPhrase; + setTiles(createTiles(firstPhrase)); + + if (normalizedPhrases.length <= 1 || typeof window === 'undefined') { + return clearAnimation; + } + + let phraseIndex = 0; + let cancelled = false; + + const safeFlipMs = Math.max(40, (Number(flipDuration) || 0.12) * 1000); + const safeStaggerMs = Math.max(0, (Number(stagger) || 0) * 1000); + const safeCycleDelay = Math.max(400, Number(cycleDelay) || 2400); + const safeFlips = Math.max(0, Math.floor(Number(flipsPerChar) || 0)); + const activeCharset = resolveCharset(charset); + + const animateTo = (targetPhrase: string) => { + if (prefersReducedMotion) { + currentTextRef.current = targetPhrase; + setTiles(createTiles(targetPhrase)); + return 0; + } + + const fromPhrase = normalizePhrase(currentTextRef.current, width); + const targetChars = targetPhrase.split(''); + + const plans = targetChars + .map((targetChar, index) => { + const fromChar = fromPhrase[index] || ' '; + if (fromChar === targetChar) return null; + + return { + index, + from: fromChar, + target: targetChar, + sequence: buildSequence(targetChar, safeFlips, activeCharset), + start: index * safeStaggerMs, + step: -1, + done: false + }; + }) + .filter((plan): plan is AnimationPlan => plan !== null); + + if (!plans.length) { + currentTextRef.current = targetPhrase; + setTiles(createTiles(targetPhrase)); + return 0; + } + + const totalDuration = plans.reduce( + (max, plan) => Math.max(max, plan.start + plan.sequence.length * safeFlipMs), + 0 + ); + const startedAt = performance.now(); + + const updateTiles = (updates: TileUpdate[]) => { + setTiles(previous => { + const nextTiles = [...previous]; + updates.forEach(update => { + const tile = nextTiles[update.index]; + if (!tile) return; + + nextTiles[update.index] = { + current: update.current, + next: update.next, + flipping: !update.done, + tick: tile.tick + 1 + }; + }); + return nextTiles; + }); + }; + + const tick = (now: number) => { + if (cancelled) return; + + const elapsed = now - startedAt; + const updates: TileUpdate[] = []; + let shouldContinue = false; + + plans.forEach(plan => { + const localElapsed = elapsed - plan.start; + + if (localElapsed < 0) { + shouldContinue = true; + return; + } + + const step = Math.floor(localElapsed / safeFlipMs); + + if (step < plan.sequence.length) { + shouldContinue = true; + + if (step !== plan.step) { + plan.step = step; + updates.push({ + index: plan.index, + current: step === 0 ? plan.from : plan.sequence[step - 1], + next: plan.sequence[step], + done: false + }); + } + } else if (!plan.done) { + plan.done = true; + updates.push({ + index: plan.index, + current: plan.target, + next: plan.target, + done: true + }); + } + }); + + if (updates.length > 0) updateTiles(updates); + + if (shouldContinue) { + rafRef.current = requestAnimationFrame(tick); + } else { + currentTextRef.current = targetPhrase; + rafRef.current = null; + } + }; + + rafRef.current = requestAnimationFrame(tick); + return totalDuration; + }; + + const scheduleNext = (delay: number) => { + cycleTimerRef.current = window.setTimeout(() => { + if (cancelled) return; + + const nextIndex = phraseIndex + 1; + + if (nextIndex >= normalizedPhrases.length && !loop) return; + + phraseIndex = nextIndex % normalizedPhrases.length; + const animationDuration = animateTo(normalizedPhrases[phraseIndex]); + scheduleNext(safeCycleDelay + animationDuration); + }, delay); + }; + + scheduleNext(safeCycleDelay); + + return () => { + cancelled = true; + clearAnimation(); + }; + }, [normalizedPhrases, width, loop, cycleDelay, flipDuration, stagger, flipsPerChar, charset, prefersReducedMotion]); + + const settledText = tiles + .map(tile => tile.current) + .join('') + .trimEnd(); + const componentStyle: CSSProperties & Record = { + '--split-flap-tile-color': tileColor, + '--split-flap-text-color': textColor, + '--split-flap-radius': toCssUnit(tileRadius), + '--split-flap-gap': toCssUnit(gap), + '--split-flap-font-size': toCssUnit(fontSize), + '--split-flap-flip-duration': `${Math.max(0.04, Number(flipDuration) || 0.12)}s`, + ...style + }; + + return ( +
+ {tiles.map((tile, index) => ( + + ))} +
+ ); +}; + +export default SplitFlapText; diff --git a/src/components/bits/StaggeredMenu.css b/src/components/bits/StaggeredMenu.css new file mode 100644 index 0000000..ab63058 --- /dev/null +++ b/src/components/bits/StaggeredMenu.css @@ -0,0 +1,356 @@ +.staggered-menu-wrapper { + position: relative; + width: 100%; + height: 100%; + z-index: 40; + pointer-events: none; +} + +.staggered-menu-wrapper.fixed-wrapper { + position: fixed; + top: 0; + left: 0; + width: 100vw; + height: 100vh; + z-index: 40; + overflow: hidden; +} + +.staggered-menu-header { + position: absolute; + top: 0; + left: 0; + width: 100%; + display: flex; + align-items: center; + justify-content: space-between; + padding: 2em; + background: transparent; + pointer-events: none; + z-index: 20; +} + +.staggered-menu-header > * { + pointer-events: auto; +} + +.sm-logo { + display: flex; + align-items: center; + user-select: none; +} + +.sm-logo-img { + display: block; + height: 32px; + width: auto; + object-fit: contain; +} + +.sm-toggle { + position: relative; + display: inline-flex; + align-items: center; + gap: 0.3rem; + background: transparent; + border: none; + cursor: pointer; + color: #e9e9ef; + font-weight: 500; + line-height: 1; + overflow: visible; +} + +.sm-toggle:focus-visible { + outline: 2px solid #ffffffaa; + outline-offset: 4px; + border-radius: 4px; +} + +.sm-line:last-of-type { + margin-top: 6px; +} + +.sm-toggle-textWrap { + position: relative; + display: inline-block; + height: 1em; + overflow: hidden; + white-space: nowrap; + width: var(--sm-toggle-width, auto); + min-width: var(--sm-toggle-width, auto); +} + +.sm-toggle-textInner { + display: flex; + flex-direction: column; + line-height: 1; +} + +.sm-toggle-line { + display: block; + height: 1em; + line-height: 1; +} + +.sm-icon { + position: relative; + width: 14px; + height: 14px; + flex: 0 0 14px; + display: inline-flex; + align-items: center; + justify-content: center; + will-change: transform; +} + +.sm-panel-itemWrap { + position: relative; + overflow: hidden; + line-height: 1; +} + +.sm-icon-line { + position: absolute; + left: 50%; + top: 50%; + width: 100%; + height: 2px; + background: currentColor; + border-radius: 2px; + transform: translate(-50%, -50%); + will-change: transform; +} + +.sm-line { + display: none !important; +} + +.staggered-menu-panel { + position: absolute; + top: 0; + right: 0; + width: clamp(260px, 38vw, 420px); + height: 100%; + background: white; + backdrop-filter: blur(12px); + -webkit-backdrop-filter: blur(12px); + display: flex; + flex-direction: column; + padding: 6em 2em 2em 2em; + overflow-y: auto; + z-index: 10; + pointer-events: auto; + opacity: 0; +} + +[data-position='left'] .staggered-menu-panel { + right: auto; + left: 0; +} + +.sm-prelayers { + position: absolute; + top: 0; + right: 0; + bottom: 0; + width: clamp(260px, 38vw, 420px); + pointer-events: none; + z-index: 5; + opacity: 0; +} + +[data-position='left'] .sm-prelayers { + right: auto; + left: 0; +} + +.sm-prelayer { + position: absolute; + top: 0; + right: 0; + height: 100%; + width: 100%; + transform: translateX(0); + opacity: 0; +} + +.sm-panel-inner { + flex: 1; + display: flex; + flex-direction: column; + gap: 1.25rem; +} + +.sm-socials { + margin-top: auto; + padding-top: 2rem; + display: flex; + flex-direction: column; + gap: 0.75rem; +} + +.sm-socials-title { + margin: 0; + font-size: 1rem; + font-weight: 500; + color: var(--sm-accent, #ff0000); +} + +.sm-socials-list { + list-style: none; + margin: 0; + padding: 0; + display: flex; + flex-direction: row; + align-items: center; + gap: 1rem; + flex-wrap: wrap; +} + +.sm-socials-list .sm-socials-link { + opacity: 1; +} + +.sm-socials-list:hover .sm-socials-link { + opacity: 0.35; +} + +.sm-socials-list:hover .sm-socials-link:hover { + opacity: 1; +} + +.sm-socials-link:focus-visible { + outline: 2px solid var(--sm-accent, #ff0000); + outline-offset: 3px; +} + +.sm-socials-list:focus-within .sm-socials-link { + opacity: 0.35; +} + +.sm-socials-list:focus-within .sm-socials-link:focus-visible { + opacity: 1; +} + +.sm-socials-link { + font-size: 1.2rem; + font-weight: 500; + color: #111; + text-decoration: none; + position: relative; + padding: 2px 0; + display: inline-block; + transition: + color 0.3s ease, + opacity 0.3s ease; +} + +.sm-socials-link:hover { + color: var(--sm-accent, #ff0000); +} + +.sm-panel-title { + margin: 0; + font-size: 1rem; + font-weight: 600; + color: #fff; + text-transform: uppercase; +} + +.sm-panel-list { + list-style: none; + margin: 0; + padding: 0; + display: flex; + flex-direction: column; + gap: 0.5rem; +} + +.sm-panel-item { + position: relative; + color: #000; + font-weight: 600; + font-size: 4rem; + cursor: pointer; + line-height: 1; + letter-spacing: -2px; + text-transform: uppercase; + transition: + background 0.25s, + color 0.25s; + display: inline-block; + text-decoration: none; + padding-right: 1.4em; +} + +.staggered-menu-panel .sm-socials-list .sm-socials-link { + opacity: 1; + transition: opacity 0.3s ease; +} + +.staggered-menu-panel .sm-socials-list:hover .sm-socials-link:not(:hover) { + opacity: 0.35; +} + +.staggered-menu-panel .sm-socials-list:focus-within .sm-socials-link:not(:focus-visible) { + opacity: 0.35; +} + +.staggered-menu-panel .sm-socials-list .sm-socials-link:hover, +.staggered-menu-panel .sm-socials-list .sm-socials-link:focus-visible { + opacity: 1; +} + +.sm-panel-itemLabel { + display: inline-block; + will-change: transform; + transform-origin: 50% 100%; +} + +.sm-panel-item:hover { + color: var(--sm-accent, #5227ff); +} + +.sm-panel-list[data-numbering] { + counter-reset: smItem; +} + +.sm-panel-list[data-numbering] .sm-panel-item::after { + counter-increment: smItem; + content: counter(smItem, decimal-leading-zero); + position: absolute; + top: 0.1em; + right: 3.2em; + font-size: 18px; + font-weight: 400; + color: var(--sm-accent, #5227ff); + letter-spacing: 0; + pointer-events: none; + user-select: none; + opacity: var(--sm-num-opacity, 0); +} + +@media (max-width: 1024px) { + .staggered-menu-panel { + width: 100%; + left: 0; + right: 0; + } + + .staggered-menu-wrapper[data-open] .sm-logo-img { + filter: invert(100%); + } +} + +@media (max-width: 640px) { + .staggered-menu-panel { + width: 100%; + left: 0; + right: 0; + } + + .staggered-menu-wrapper[data-open] .sm-logo-img { + filter: invert(100%); + } +} diff --git a/src/components/bits/StaggeredMenu.tsx b/src/components/bits/StaggeredMenu.tsx new file mode 100644 index 0000000..aea86f1 --- /dev/null +++ b/src/components/bits/StaggeredMenu.tsx @@ -0,0 +1,498 @@ +// StaggeredMenu — from React Bits (https://github.com/DavidHDev/react-bits) +// Copyright (c) 2026 David Haz. MIT + Commons Clause. Adapted for yoyos.sh. + +import React, { useCallback, useLayoutEffect, useRef, useState } from 'react'; +import { gsap } from 'gsap'; +import './StaggeredMenu.css'; + +export interface StaggeredMenuItem { + label: string; + ariaLabel: string; + link: string; + color?: string; + current?: boolean; +} + +export interface StaggeredMenuSocialItem { + label: string; + link: string; +} + +export interface StaggeredMenuProps { + position?: 'left' | 'right'; + colors?: string[]; + items?: StaggeredMenuItem[]; + socialItems?: StaggeredMenuSocialItem[]; + displaySocials?: boolean; + displayItemNumbering?: boolean; + className?: string; + logoUrl?: string; + menuButtonColor?: string; + openMenuButtonColor?: string; + accentColor?: string; + changeMenuColorOnOpen?: boolean; + closeOnClickAway?: boolean; + onMenuOpen?: () => void; + onMenuClose?: () => void; + isFixed?: boolean; + footer?: React.ReactNode; +} + +export const StaggeredMenu: React.FC = ({ + position = 'right', + colors = ['#B497CF', '#5227FF'], + items = [], + socialItems = [], + displaySocials = true, + displayItemNumbering = true, + className, + logoUrl = '', + menuButtonColor = '#fff', + openMenuButtonColor = '#fff', + changeMenuColorOnOpen = true, + accentColor = '#5227FF', + isFixed = false, + closeOnClickAway = true, + onMenuOpen, + onMenuClose, + footer +}: StaggeredMenuProps) => { + const [open, setOpen] = useState(false); + const openRef = useRef(false); + const panelRef = useRef(null); + const preLayersRef = useRef(null); + const preLayerElsRef = useRef([]); + const plusHRef = useRef(null); + const plusVRef = useRef(null); + const iconRef = useRef(null); + const textInnerRef = useRef(null); + const textWrapRef = useRef(null); + const [textLines, setTextLines] = useState(['Menu', 'Close']); + + const openTlRef = useRef(null); + const closeTweenRef = useRef(null); + const spinTweenRef = useRef(null); + const textCycleAnimRef = useRef(null); + const colorTweenRef = useRef(null); + const toggleBtnRef = useRef(null); + const busyRef = useRef(false); + const itemEntranceTweenRef = useRef(null); + + useLayoutEffect(() => { + const ctx = gsap.context(() => { + const panel = panelRef.current; + const preContainer = preLayersRef.current; + const plusH = plusHRef.current; + const plusV = plusVRef.current; + const icon = iconRef.current; + const textInner = textInnerRef.current; + if (!panel || !plusH || !plusV || !icon || !textInner) return; + + let preLayers: HTMLElement[] = []; + if (preContainer) { + preLayers = Array.from(preContainer.querySelectorAll('.sm-prelayer')) as HTMLElement[]; + } + preLayerElsRef.current = preLayers; + + const offscreen = position === 'left' ? -100 : 100; + gsap.set([panel, ...preLayers], { xPercent: offscreen, opacity: 1 }); + if (preContainer) { + gsap.set(preContainer, { xPercent: 0, opacity: 1 }); + } + gsap.set(plusH, { transformOrigin: '50% 50%', rotate: 0 }); + gsap.set(plusV, { transformOrigin: '50% 50%', rotate: 90 }); + gsap.set(icon, { rotate: 0, transformOrigin: '50% 50%' }); + gsap.set(textInner, { yPercent: 0 }); + if (toggleBtnRef.current) gsap.set(toggleBtnRef.current, { color: menuButtonColor }); + }); + return () => ctx.revert(); + }, [menuButtonColor, position]); + + const buildOpenTimeline = useCallback(() => { + const panel = panelRef.current; + const layers = preLayerElsRef.current; + if (!panel) return null; + + openTlRef.current?.kill(); + if (closeTweenRef.current) { + closeTweenRef.current.kill(); + closeTweenRef.current = null; + } + itemEntranceTweenRef.current?.kill(); + + const itemEls = Array.from(panel.querySelectorAll('.sm-panel-itemLabel')) as HTMLElement[]; + const numberEls = Array.from( + panel.querySelectorAll('.sm-panel-list[data-numbering] .sm-panel-item') + ) as HTMLElement[]; + const socialTitle = panel.querySelector('.sm-socials-title') as HTMLElement | null; + const socialLinks = Array.from(panel.querySelectorAll('.sm-socials-link')) as HTMLElement[]; + + const offscreen = position === 'left' ? -100 : 100; + const layerStates = layers.map(el => ({ el, start: offscreen })); + const panelStart = offscreen; + + if (itemEls.length) { + gsap.set(itemEls, { yPercent: 140, rotate: 10 }); + } + if (numberEls.length) { + gsap.set(numberEls, { '--sm-num-opacity': 0 }); + } + if (socialTitle) { + gsap.set(socialTitle, { opacity: 0 }); + } + if (socialLinks.length) { + gsap.set(socialLinks, { y: 25, opacity: 0 }); + } + + const tl = gsap.timeline({ paused: true }); + + layerStates.forEach((ls, i) => { + tl.fromTo(ls.el, { xPercent: ls.start }, { xPercent: 0, duration: 0.5, ease: 'power4.out' }, i * 0.07); + }); + const lastTime = layerStates.length ? (layerStates.length - 1) * 0.07 : 0; + const panelInsertTime = lastTime + (layerStates.length ? 0.08 : 0); + const panelDuration = 0.65; + tl.fromTo( + panel, + { xPercent: panelStart }, + { xPercent: 0, duration: panelDuration, ease: 'power4.out' }, + panelInsertTime + ); + + if (itemEls.length) { + const itemsStartRatio = 0.15; + const itemsStart = panelInsertTime + panelDuration * itemsStartRatio; + tl.to( + itemEls, + { + yPercent: 0, + rotate: 0, + duration: 1, + ease: 'power4.out', + stagger: { each: 0.1, from: 'start' } + }, + itemsStart + ); + if (numberEls.length) { + tl.to( + numberEls, + { + duration: 0.6, + ease: 'power2.out', + '--sm-num-opacity': 1, + stagger: { each: 0.08, from: 'start' } + }, + itemsStart + 0.1 + ); + } + } + + if (socialTitle || socialLinks.length) { + const socialsStart = panelInsertTime + panelDuration * 0.4; + if (socialTitle) { + tl.to( + socialTitle, + { + opacity: 1, + duration: 0.5, + ease: 'power2.out' + }, + socialsStart + ); + } + if (socialLinks.length) { + tl.to( + socialLinks, + { + y: 0, + opacity: 1, + duration: 0.55, + ease: 'power3.out', + stagger: { each: 0.08, from: 'start' }, + onComplete: () => { + gsap.set(socialLinks, { clearProps: 'opacity' }); + } + }, + socialsStart + 0.04 + ); + } + } + + openTlRef.current = tl; + return tl; + }, [position]); + + const playOpen = useCallback(() => { + if (busyRef.current) return; + busyRef.current = true; + const tl = buildOpenTimeline(); + if (tl) { + tl.eventCallback('onComplete', () => { + busyRef.current = false; + }); + tl.play(0); + } else { + busyRef.current = false; + } + }, [buildOpenTimeline]); + + const playClose = useCallback(() => { + openTlRef.current?.kill(); + openTlRef.current = null; + itemEntranceTweenRef.current?.kill(); + + const panel = panelRef.current; + const layers = preLayerElsRef.current; + if (!panel) return; + + const all: HTMLElement[] = [...layers, panel]; + closeTweenRef.current?.kill(); + const offscreen = position === 'left' ? -100 : 100; + closeTweenRef.current = gsap.to(all, { + xPercent: offscreen, + duration: 0.32, + ease: 'power3.in', + overwrite: 'auto', + onComplete: () => { + const itemEls = Array.from(panel.querySelectorAll('.sm-panel-itemLabel')) as HTMLElement[]; + if (itemEls.length) { + gsap.set(itemEls, { yPercent: 140, rotate: 10 }); + } + const numberEls = Array.from( + panel.querySelectorAll('.sm-panel-list[data-numbering] .sm-panel-item') + ) as HTMLElement[]; + if (numberEls.length) { + gsap.set(numberEls, { '--sm-num-opacity': 0 }); + } + const socialTitle = panel.querySelector('.sm-socials-title') as HTMLElement | null; + const socialLinks = Array.from(panel.querySelectorAll('.sm-socials-link')) as HTMLElement[]; + if (socialTitle) gsap.set(socialTitle, { opacity: 0 }); + if (socialLinks.length) gsap.set(socialLinks, { y: 25, opacity: 0 }); + busyRef.current = false; + } + }); + }, [position]); + + const animateIcon = useCallback((opening: boolean) => { + const icon = iconRef.current; + if (!icon) return; + spinTweenRef.current?.kill(); + if (opening) { + spinTweenRef.current = gsap.to(icon, { rotate: 225, duration: 0.8, ease: 'power4.out', overwrite: 'auto' }); + } else { + spinTweenRef.current = gsap.to(icon, { rotate: 0, duration: 0.35, ease: 'power3.inOut', overwrite: 'auto' }); + } + }, []); + + const animateColor = useCallback( + (opening: boolean) => { + const btn = toggleBtnRef.current; + if (!btn) return; + colorTweenRef.current?.kill(); + if (changeMenuColorOnOpen) { + const targetColor = opening ? openMenuButtonColor : menuButtonColor; + colorTweenRef.current = gsap.to(btn, { + color: targetColor, + delay: 0.18, + duration: 0.3, + ease: 'power2.out' + }); + } else { + gsap.set(btn, { color: menuButtonColor }); + } + }, + [openMenuButtonColor, menuButtonColor, changeMenuColorOnOpen] + ); + + React.useEffect(() => { + if (toggleBtnRef.current) { + if (changeMenuColorOnOpen) { + const targetColor = openRef.current ? openMenuButtonColor : menuButtonColor; + gsap.set(toggleBtnRef.current, { color: targetColor }); + } else { + gsap.set(toggleBtnRef.current, { color: menuButtonColor }); + } + } + }, [changeMenuColorOnOpen, menuButtonColor, openMenuButtonColor]); + + const animateText = useCallback((opening: boolean) => { + const inner = textInnerRef.current; + if (!inner) return; + textCycleAnimRef.current?.kill(); + + const currentLabel = opening ? 'Menu' : 'Close'; + const targetLabel = opening ? 'Close' : 'Menu'; + const cycles = 3; + const seq: string[] = [currentLabel]; + let last = currentLabel; + for (let i = 0; i < cycles; i++) { + last = last === 'Menu' ? 'Close' : 'Menu'; + seq.push(last); + } + if (last !== targetLabel) seq.push(targetLabel); + seq.push(targetLabel); + setTextLines(seq); + + gsap.set(inner, { yPercent: 0 }); + const lineCount = seq.length; + const finalShift = ((lineCount - 1) / lineCount) * 100; + textCycleAnimRef.current = gsap.to(inner, { + yPercent: -finalShift, + duration: 0.5 + lineCount * 0.07, + ease: 'power4.out' + }); + }, []); + + const toggleMenu = useCallback(() => { + const target = !openRef.current; + openRef.current = target; + setOpen(target); + if (target) { + onMenuOpen?.(); + playOpen(); + } else { + onMenuClose?.(); + playClose(); + } + animateIcon(target); + animateColor(target); + animateText(target); + }, [playOpen, playClose, animateIcon, animateColor, animateText]); + + const closeMenu = useCallback(() => { + if (openRef.current) { + openRef.current = false; + setOpen(false); + onMenuClose?.(); + playClose(); + animateIcon(false); + animateColor(false); + animateText(false); + } + }, [playClose, animateIcon, animateColor, animateText, onMenuClose]); + + React.useEffect(() => { + if (!closeOnClickAway || !open) return; + + const handleClickOutside = (event: MouseEvent) => { + if ( + panelRef.current && + !panelRef.current.contains(event.target as Node) && + toggleBtnRef.current && + !toggleBtnRef.current.contains(event.target as Node) + ) { + closeMenu(); + } + }; + + const handleKey = (event: KeyboardEvent) => { + if (event.key === 'Escape') closeMenu(); + }; + document.addEventListener('mousedown', handleClickOutside); + document.addEventListener('keydown', handleKey); + return () => { + document.removeEventListener('mousedown', handleClickOutside); + document.removeEventListener('keydown', handleKey); + }; + }, [closeOnClickAway, open, closeMenu]); + + return ( +
+ + ); +}; + +export default StaggeredMenu; diff --git a/src/components/bits/StickerPeel.css b/src/components/bits/StickerPeel.css new file mode 100644 index 0000000..b04ee61 --- /dev/null +++ b/src/components/bits/StickerPeel.css @@ -0,0 +1,157 @@ +:root { + --sticker-rotate: 30deg; + --sticker-p: 10px; + --sticker-peelback-hover: 30%; + --sticker-peelback-active: 40%; + --sticker-peel-easing: power3.out; + --sticker-peel-hover-easing: power2.out; + --sticker-start: calc(-1 * var(--sticker-p)); + --sticker-end: calc(100% + var(--sticker-p)); + --sticker-shadow-opacity: 0.6; + --sticker-lighting-constant: 0.1; + --peel-direction: 0deg; +} + +.sticker-container { + position: relative; + transform: rotate(var(--peel-direction)); + transform-origin: center; +} + +.sticker-container * { + -webkit-user-select: none; + user-select: none; + -webkit-touch-callout: none; + -webkit-tap-highlight-color: transparent; +} + +.sticker-main { + clip-path: polygon( + var(--sticker-start) var(--sticker-start), + var(--sticker-end) var(--sticker-start), + var(--sticker-end) var(--sticker-end), + var(--sticker-start) var(--sticker-end) + ); + transition: clip-path 0.6s ease-out; + filter: url(#dropShadow); +} + +.sticker-main > * { + transform: rotate(calc(-1 * var(--peel-direction))); +} + +.sticker-lighting { + filter: url(#pointLight); +} + +.sticker-container:hover .sticker-main, +.sticker-container.touch-active .sticker-main { + clip-path: polygon( + var(--sticker-start) var(--sticker-peelback-hover), + var(--sticker-end) var(--sticker-peelback-hover), + var(--sticker-end) var(--sticker-end), + var(--sticker-start) var(--sticker-end) + ); +} + +.sticker-container:active .sticker-main { + clip-path: polygon( + var(--sticker-start) var(--sticker-peelback-active), + var(--sticker-end) var(--sticker-peelback-active), + var(--sticker-end) var(--sticker-end), + var(--sticker-start) var(--sticker-end) + ); +} + +.sticker-image { + transform: rotate(var(--sticker-rotate)); +} + +.flap { + position: absolute; + width: 100%; + height: 100%; + left: 0; + top: calc(-100% - var(--sticker-p) - var(--sticker-p)); + clip-path: polygon( + var(--sticker-start) var(--sticker-start), + var(--sticker-end) var(--sticker-start), + var(--sticker-end) var(--sticker-start), + var(--sticker-start) var(--sticker-start) + ); + transform: scaleY(-1); + transition: all 0.6s ease-out; +} + +.flap > * { + transform: rotate(calc(-1 * var(--peel-direction))); +} + +.sticker-container:hover .flap, +.sticker-container.touch-active .flap { + clip-path: polygon( + var(--sticker-start) var(--sticker-start), + var(--sticker-end) var(--sticker-start), + var(--sticker-end) var(--sticker-peelback-hover), + var(--sticker-start) var(--sticker-peelback-hover) + ); + top: calc(-100% + 2 * var(--sticker-peelback-hover) - 1px); +} + +.sticker-container:active .flap { + clip-path: polygon( + var(--sticker-start) var(--sticker-start), + var(--sticker-end) var(--sticker-start), + var(--sticker-end) var(--sticker-peelback-active), + var(--sticker-start) var(--sticker-peelback-active) + ); + top: calc(-100% + 2 * var(--sticker-peelback-active) - 1px); +} + +.flap-lighting { + filter: url(#pointLightFlipped); +} + +.flap-image { + transform: rotate(var(--sticker-rotate)); + filter: url(#expandAndFill); +} + +.draggable { + position: absolute; + cursor: grab; + -webkit-transform: translateZ(0); + transform: translateZ(0); +} + +.draggable:active { + cursor: grabbing; +} + +@media (hover: none) and (pointer: coarse) { + .draggable { + cursor: default; + } + + .sticker-container { + touch-action: none; + } +} + +.sticker-image, +.flap-image { + width: var(--sticker-width, 200px); +} + +.sticker-main, +.flap { + will-change: clip-path, transform; +} + +.sticker-ripple { + position: absolute; + border-radius: 50%; + background: rgba(255, 255, 255, 0.6); + pointer-events: none; + z-index: 10; +} diff --git a/src/components/bits/StickerPeel.tsx b/src/components/bits/StickerPeel.tsx new file mode 100644 index 0000000..8c115cf --- /dev/null +++ b/src/components/bits/StickerPeel.tsx @@ -0,0 +1,309 @@ +// StickerPeel — from React Bits (https://github.com/DavidHDev/react-bits) +// Copyright (c) 2026 David Haz. MIT + Commons Clause. Adapted for yoyos.sh. +'use client'; + +import { useRef, useEffect, useMemo, type CSSProperties } from 'react'; +import { gsap } from 'gsap'; +import { Draggable } from 'gsap/Draggable'; +import './StickerPeel.css'; + +gsap.registerPlugin(Draggable); + +interface StickerPeelProps { + imageSrc: string; + rotate?: number; + peelBackHoverPct?: number; + peelBackActivePct?: number; + peelEasing?: string; + peelHoverEasing?: string; + width?: number; + shadowIntensity?: number; + lightingIntensity?: number; + initialPosition?: 'center' | 'random' | { x: number; y: number }; + peelDirection?: number; + className?: string; +} + +interface CSSVars extends CSSProperties { + '--sticker-rotate'?: string; + '--sticker-p'?: string; + '--sticker-peelback-hover'?: string; + '--sticker-peelback-active'?: string; + '--sticker-peel-easing'?: string; + '--sticker-peel-hover-easing'?: string; + '--sticker-width'?: string; + '--sticker-shadow-opacity'?: number; + '--sticker-lighting-constant'?: number; + '--peel-direction'?: string; +} + +const StickerPeel: React.FC = ({ + imageSrc, + rotate = 30, + peelBackHoverPct = 30, + peelBackActivePct = 40, + peelEasing = 'power3.out', + peelHoverEasing = 'power2.out', + width = 200, + shadowIntensity = 0.6, + lightingIntensity = 0.1, + initialPosition = 'center', + peelDirection = 0, + className = '' +}) => { + const containerRef = useRef(null); + const dragTargetRef = useRef(null); + const pointLightRef = useRef(null); + const pointLightFlippedRef = useRef(null); + const draggableInstanceRef = useRef(null); + + const defaultPadding = 10; + + useEffect(() => { + const target = dragTargetRef.current; + if (!target) return; + + let startX = 0, + startY = 0; + + if (initialPosition === 'center') { + return; + } + + if (typeof initialPosition === 'object' && initialPosition.x !== undefined && initialPosition.y !== undefined) { + startX = initialPosition.x; + startY = initialPosition.y; + } + + gsap.set(target, { x: startX, y: startY }); + }, [initialPosition]); + + useEffect(() => { + const target = dragTargetRef.current; + if (!target) return; + + const boundsEl = target.parentNode as HTMLElement; + + const draggable = Draggable.create(target, { + type: 'x,y', + bounds: boundsEl, + inertia: true, + onDrag(this: Draggable) { + const rot = gsap.utils.clamp(-24, 24, this.deltaX * 0.4); + gsap.to(target, { rotation: rot, duration: 0.15, ease: 'power1.out' }); + }, + onDragEnd() { + const rotationEase = 'power2.out'; + const duration = 0.8; + gsap.to(target, { rotation: 0, duration, ease: rotationEase }); + } + }); + + draggableInstanceRef.current = draggable[0]; + + const handleResize = () => { + if (draggableInstanceRef.current) { + draggableInstanceRef.current.update(); + + const currentX = gsap.getProperty(target, 'x') as number; + const currentY = gsap.getProperty(target, 'y') as number; + + const boundsRect = boundsEl.getBoundingClientRect(); + const targetRect = target.getBoundingClientRect(); + + const maxX = boundsRect.width - targetRect.width; + const maxY = boundsRect.height - targetRect.height; + + const newX = Math.max(0, Math.min(currentX, maxX)); + const newY = Math.max(0, Math.min(currentY, maxY)); + + if (newX !== currentX || newY !== currentY) { + gsap.to(target, { + x: newX, + y: newY, + duration: 0.3, + ease: 'power2.out' + }); + } + } + }; + + window.addEventListener('resize', handleResize); + window.addEventListener('orientationchange', handleResize); + + return () => { + window.removeEventListener('resize', handleResize); + window.removeEventListener('orientationchange', handleResize); + if (draggableInstanceRef.current) { + draggableInstanceRef.current.kill(); + } + }; + }, []); + + useEffect(() => { + const updateLight = (e: Event) => { + const mouseEvent = e as MouseEvent; + const rect = containerRef.current?.getBoundingClientRect(); + if (!rect) return; + + const x = mouseEvent.clientX - rect.left; + const y = mouseEvent.clientY - rect.top; + + if (pointLightRef.current) { + gsap.set(pointLightRef.current, { attr: { x, y } }); + } + + const normalizedAngle = Math.abs(peelDirection % 360); + if (pointLightFlippedRef.current) { + if (normalizedAngle !== 180) { + gsap.set(pointLightFlippedRef.current, { + attr: { x, y: rect.height - y } + }); + } else { + gsap.set(pointLightFlippedRef.current, { + attr: { x: -1000, y: -1000 } + }); + } + } + }; + + const container = containerRef.current; + const eventType = 'mousemove'; + + if (container) { + container.addEventListener(eventType, updateLight); + return () => container.removeEventListener(eventType, updateLight); + } + }, [peelDirection]); + + useEffect(() => { + const container = containerRef.current; + if (!container) return; + + const handleTouchStart = () => { + container.classList.add('touch-active'); + }; + + const handleTouchEnd = () => { + container.classList.remove('touch-active'); + }; + + container.addEventListener('touchstart', handleTouchStart); + container.addEventListener('touchend', handleTouchEnd); + container.addEventListener('touchcancel', handleTouchEnd); + + return () => { + container.removeEventListener('touchstart', handleTouchStart); + container.removeEventListener('touchend', handleTouchEnd); + container.removeEventListener('touchcancel', handleTouchEnd); + }; + }, []); + + const cssVars: CSSVars = useMemo( + () => ({ + '--sticker-rotate': `${rotate}deg`, + '--sticker-p': `${defaultPadding}px`, + '--sticker-peelback-hover': `${peelBackHoverPct}%`, + '--sticker-peelback-active': `${peelBackActivePct}%`, + '--sticker-peel-easing': peelEasing, + '--sticker-peel-hover-easing': peelHoverEasing, + '--sticker-width': `${width}px`, + '--sticker-shadow-opacity': shadowIntensity, + '--sticker-lighting-constant': lightingIntensity, + '--peel-direction': `${peelDirection}deg` + }), + [ + rotate, + peelBackHoverPct, + peelBackActivePct, + peelEasing, + peelHoverEasing, + width, + shadowIntensity, + lightingIntensity, + peelDirection + ] + ); + + return ( +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+ e.preventDefault()} + /> +
+
+ +
+
+ e.preventDefault()} + /> +
+
+
+
+ ); +}; + +export default StickerPeel; diff --git a/src/components/deco/Clipping.astro b/src/components/deco/Clipping.astro new file mode 100644 index 0000000..67ab872 --- /dev/null +++ b/src/components/deco/Clipping.astro @@ -0,0 +1,170 @@ +--- +/** + * A real photo treated like a magazine clipping: optional tape, tilt, torn + * edge and print treatments (duotone / halftone / b&w). + */ +import { Image } from 'astro:assets'; +import type { ImageMetadata } from 'astro'; + +interface Props { + src: ImageMetadata; + alt?: string; + rotate?: number; + tape?: 'top' | 'corners' | 'none'; + treatment?: 'none' | 'duotone' | 'halftone' | 'bw' | 'riso'; + /** duotone/riso ink color */ + ink?: string; + torn?: boolean; + border?: boolean; + ratio?: string; + position?: string; + widths?: number[]; + sizes?: string; + loading?: 'lazy' | 'eager'; + class?: string; + caption?: string; + [attr: string]: unknown; +} +const { + src, + alt = '', + rotate = 0, + tape = 'none', + treatment = 'none', + ink = 'var(--cta-red)', + torn = false, + border = true, + ratio, + position = 'center', + widths = [360, 640, 960], + sizes = '(min-width: 60rem) 40vw, 90vw', + loading = 'lazy', + class: cls, + caption, + ...rest +} = Astro.props; +--- + +
+
+ {alt} +
+ {caption &&
{caption}
} +
+ + diff --git a/src/data/photo-credits.json b/src/data/photo-credits.json new file mode 100644 index 0000000..35a7583 --- /dev/null +++ b/src/data/photo-credits.json @@ -0,0 +1,242 @@ +[ + { + "file": "botanical", + "title": "Japanese cherry blossom branch C.J", + "creator": "rijksmuseum", + "license": "CC0 1.0 (public domain dedication)", + "source": "rawpixel", + "url": "https://www.rawpixel.com/image/503781/free-illustration-image-sakura-cherry-blossoms-background" + }, + { + "file": "cassette", + "title": "Free vintage cassette tape image", + "creator": "Unknown", + "license": "CC0 1.0 (public domain dedication)", + "source": "rawpixel", + "url": "https://www.rawpixel.com/image/5907587/photo-image-tape-public-domain-black" + }, + { + "file": "chicago-aerial", + "title": "Chicago Skyline lakefront. Original image", + "creator": "Carol M Highsmith", + "license": "CC0 1.0 (public domain dedication)", + "source": "rawpixel", + "url": "https://www.rawpixel.com/image/433891/free-photo-image-chicago-city-illinois-lakes" + }, + { + "file": "chicago-skyline-red", + "title": "Chicago's skyline appears silhouette sunset", + "creator": "Carol M Highsmith", + "license": "CC0 1.0 (public domain dedication)", + "source": "rawpixel", + "url": "https://www.rawpixel.com/image/3094116/free-photo-image-night-sunset-background-chicago" + }, + { + "file": "cloud", + "title": "Cumulus Clouds", + "creator": "Free Nature Stock", + "license": "CC0 1.0 (public domain dedication)", + "source": "stocksnap", + "url": "https://stocksnap.io/photo/cumulus-clouds-RNUVHVEM6Q" + }, + { + "file": "computers-pile", + "title": "Free pile old computers", + "creator": "Unknown", + "license": "CC0 1.0 (public domain dedication)", + "source": "rawpixel", + "url": "https://www.rawpixel.com/image/5906713/photo-image-aesthetic-public-domain-computer" + }, + { + "file": "computers-room", + "title": "Free bunch old computers image", + "creator": "Unknown", + "license": "CC0 1.0 (public domain dedication)", + "source": "rawpixel", + "url": "https://www.rawpixel.com/image/5905997/photo-image-public-domain-shadow-technology" + }, + { + "file": "cta-sign", + "title": "Scratched sign for the Chicago El Red Line to 95/Dan Ryan at North/Clybourne on a white pillar with a train moving in the background.", + "creator": "Aaron Jorbin", + "license": "CC0 1.0 (public domain dedication)", + "source": "wordpress", + "url": "https://wordpress.org/photos/photo/97765b5444/" + }, + { + "file": "daisies", + "title": "Daisies Flower", + "creator": "Bob Richards", + "license": "CC0 1.0 (public domain dedication)", + "source": "stocksnap", + "url": "https://stocksnap.io/photo/daisies-flower-M5XV7XMR6W" + }, + { + "file": "floppies-sticker", + "title": "Old computer disk", + "creator": "Unknown", + "license": "CC0 1.0 (public domain dedication)", + "source": "rawpixel", + "url": "https://www.rawpixel.com/image/6040633/old-computer-disk-free-public-domain-cc0-photo" + }, + { + "file": "forest", + "title": "Forest Mountain", + "creator": "Matt Bango", + "license": "CC0 1.0 (public domain dedication)", + "source": "stocksnap", + "url": "https://stocksnap.io/photo/forest-mountain-NXXYL23EIL" + }, + { + "file": "gba-sticker", + "title": "Nintendo-Game-Boy-Advance-Purple-FL", + "creator": "Evan-Amos", + "license": "CC0 1.0 (public domain dedication)", + "source": "wikimedia", + "url": "https://commons.wikimedia.org/w/index.php?curid=122403889" + }, + { + "file": "grass-top", + "title": "Grass Daisies", + "creator": "Eric Lagergren", + "license": "CC0 1.0 (public domain dedication)", + "source": "stocksnap", + "url": "https://stocksnap.io/photo/grass-daisies-6ADE4054B3" + }, + { + "file": "guitar-hollow", + "title": "Electric Guitar", + "creator": "Thomas Kelley", + "license": "CC0 1.0 (public domain dedication)", + "source": "stocksnap", + "url": "https://stocksnap.io/photo/electric-guitar-SQ2DL1GFQF" + }, + { + "file": "guitar-strat", + "title": "Electric Guitar", + "creator": "Markus Spiske", + "license": "CC0 1.0 (public domain dedication)", + "source": "stocksnap", + "url": "https://stocksnap.io/photo/electric-guitar-UIT62UUU5X" + }, + { + "file": "hibiscus", + "title": "Hibiscus flower", + "creator": "U.S. National Archives", + "license": "CC0 1.0 (public domain dedication)", + "source": "rawpixel", + "url": "https://www.rawpixel.com/image/8799471/photo-image-flower-plant-vintage" + }, + { + "file": "lily", + "title": "Isolated Flower Black Background", + "creator": "Unknown", + "license": "CC0 1.0 (public domain dedication)", + "source": "rawpixel", + "url": "https://www.rawpixel.com/image/5967321/isolated-flower-black-background" + }, + { + "file": "marina-city", + "title": "Chicago-river-st-patricks-day-pd-pictures", + "creator": "Dave Zab", + "license": "CC0 1.0 (public domain dedication)", + "source": "wikimedia", + "url": "https://commons.wikimedia.org/w/index.php?curid=79847237" + }, + { + "file": "marina-city-river", + "title": "Chicago River downtown Chicago", + "creator": "Carol M Highsmith", + "license": "CC0 1.0 (public domain dedication)", + "source": "rawpixel", + "url": "https://www.rawpixel.com/image/433928/free-photo-image-chicago-architecture-building" + }, + { + "file": "motorcycle", + "title": "Motorcycle Honda", + "creator": "Andrew James Kovalsky", + "license": "CC0 1.0 (public domain dedication)", + "source": "stocksnap", + "url": "https://stocksnap.io/photo/motorcycle-honda-DWKVL4HHDU" + }, + { + "file": "paper-crumpled", + "title": "Free crumpled paper texture background", + "creator": "Unknown", + "license": "CC0 1.0 (public domain dedication)", + "source": "rawpixel", + "url": "https://www.rawpixel.com/image/5904241/photo-image-background-texture-public-domain" + }, + { + "file": "paper-kraft", + "title": "Free old paper texture image", + "creator": "Unknown", + "license": "CC0 1.0 (public domain dedication)", + "source": "rawpixel", + "url": "https://www.rawpixel.com/image/5913072/image-paper-texture-old" + }, + { + "file": "pedalboard", + "title": "Telecaster Thinline type guitar with pedalboard (SecretPreamp,MXR10BandEQ,Supa-Trem,POG2,SP Comp,Tuner,BigSky,SeaMachine,GigaDelay,TimmyOverdrive,Broadcast,VolumPedal) - The Smith Center, Las Vegas (2017-04-29 10.28.27 piqsels.com en)", + "creator": "Unknown authorUnknown author", + "license": "CC0 1.0 (public domain dedication)", + "source": "wikimedia", + "url": "https://commons.wikimedia.org/w/index.php?curid=116006535" + }, + { + "file": "postcard-back", + "title": "Postcard - South East Facade, Exhibition Building, JW Lindt, Melbourne, circa 1905", + "creator": "Unknown", + "license": "Public Domain Mark", + "source": "museumsvictoria", + "url": "https://collections.museumsvictoria.com.au/items/255268" + }, + { + "file": "railroad-postcard", + "title": "Chicago- Railroad center world", + "creator": "Unknown", + "license": "CC0 1.0 (public domain dedication)", + "source": "rawpixel", + "url": "https://www.rawpixel.com/image/8906028/image-texture-arts-vintage" + }, + { + "file": "server-rack", + "title": "File:Rear of rack at NERSC data center - closeup.jpg", + "creator": "Derrick Coetzee from Berkeley, CA, USA", + "license": "CC0 1.0 (public domain dedication)", + "source": "wikimedia", + "url": "https://commons.wikimedia.org/w/index.php?curid=17460421" + }, + { + "file": "subway-map", + "title": "Plate 80 Plan Chicago, 1909:", + "creator": "artinstitutechicago", + "license": "CC0 1.0 (public domain dedication)", + "source": "rawpixel", + "url": "https://www.rawpixel.com/image/8937739/image-roads-map-plate" + }, + { + "file": "synth", + "title": "Synthesizer Keyboard", + "creator": "Skitter Photo", + "license": "CC0 1.0 (public domain dedication)", + "source": "stocksnap", + "url": "https://stocksnap.io/photo/synthesizer-keyboard-QVZN44GAXB" + }, + { + "file": "tv", + "title": "Vintage television", + "creator": "Unknown", + "license": "CC0 1.0 (public domain dedication)", + "source": "rawpixel", + "url": "https://www.rawpixel.com/image/5904973/vintage-television-free-public-domain-cc0-photo" + }, + { + "file": "union-station", + "title": "Chicago, Illinois. waiting room Union", + "creator": "Unknown", + "license": "CC0 1.0 (public domain dedication)", + "source": "rawpixel", + "url": "https://www.rawpixel.com/image/8718166/photo-image-vintage-public-domain-person" + } +] \ No newline at end of file diff --git a/src/layouts/Base.astro b/src/layouts/Base.astro index 742c2c8..ecbf158 100644 --- a/src/layouts/Base.astro +++ b/src/layouts/Base.astro @@ -46,7 +46,8 @@ const person = { - + + {fullTitle} @@ -73,6 +74,9 @@ const person = {