diff --git a/apps/web/public/hero/001.jpg b/apps/web/public/hero/001.jpg new file mode 100644 index 0000000..d0d7642 Binary files /dev/null and b/apps/web/public/hero/001.jpg differ diff --git a/apps/web/public/hero/001.webp b/apps/web/public/hero/001.webp new file mode 100644 index 0000000..e0a0cc7 Binary files /dev/null and b/apps/web/public/hero/001.webp differ diff --git a/apps/web/public/hero/002.jpg b/apps/web/public/hero/002.jpg new file mode 100644 index 0000000..2150cd5 Binary files /dev/null and b/apps/web/public/hero/002.jpg differ diff --git a/apps/web/public/hero/002.webp b/apps/web/public/hero/002.webp new file mode 100644 index 0000000..fbd08aa Binary files /dev/null and b/apps/web/public/hero/002.webp differ diff --git a/apps/web/public/hero/003.jpg b/apps/web/public/hero/003.jpg new file mode 100644 index 0000000..9b4ec99 Binary files /dev/null and b/apps/web/public/hero/003.jpg differ diff --git a/apps/web/public/hero/003.webp b/apps/web/public/hero/003.webp new file mode 100644 index 0000000..3e16ad6 Binary files /dev/null and b/apps/web/public/hero/003.webp differ diff --git a/apps/web/public/hero/004.jpg b/apps/web/public/hero/004.jpg new file mode 100644 index 0000000..dbeace9 Binary files /dev/null and b/apps/web/public/hero/004.jpg differ diff --git a/apps/web/public/hero/004.webp b/apps/web/public/hero/004.webp new file mode 100644 index 0000000..f0213bd Binary files /dev/null and b/apps/web/public/hero/004.webp differ diff --git a/apps/web/public/hero/005.jpg b/apps/web/public/hero/005.jpg new file mode 100644 index 0000000..849bdc7 Binary files /dev/null and b/apps/web/public/hero/005.jpg differ diff --git a/apps/web/public/hero/005.webp b/apps/web/public/hero/005.webp new file mode 100644 index 0000000..5c71251 Binary files /dev/null and b/apps/web/public/hero/005.webp differ diff --git a/apps/web/public/hero/006.jpg b/apps/web/public/hero/006.jpg new file mode 100644 index 0000000..5b2baac Binary files /dev/null and b/apps/web/public/hero/006.jpg differ diff --git a/apps/web/public/hero/006.webp b/apps/web/public/hero/006.webp new file mode 100644 index 0000000..2658db2 Binary files /dev/null and b/apps/web/public/hero/006.webp differ diff --git a/apps/web/public/hero/007.jpg b/apps/web/public/hero/007.jpg new file mode 100644 index 0000000..6fdb2cb Binary files /dev/null and b/apps/web/public/hero/007.jpg differ diff --git a/apps/web/public/hero/007.webp b/apps/web/public/hero/007.webp new file mode 100644 index 0000000..c944f25 Binary files /dev/null and b/apps/web/public/hero/007.webp differ diff --git a/apps/web/public/hero/008.jpg b/apps/web/public/hero/008.jpg new file mode 100644 index 0000000..424f359 Binary files /dev/null and b/apps/web/public/hero/008.jpg differ diff --git a/apps/web/public/hero/008.webp b/apps/web/public/hero/008.webp new file mode 100644 index 0000000..ceff619 Binary files /dev/null and b/apps/web/public/hero/008.webp differ diff --git a/apps/web/public/hero/009.jpg b/apps/web/public/hero/009.jpg new file mode 100644 index 0000000..3b2c54c Binary files /dev/null and b/apps/web/public/hero/009.jpg differ diff --git a/apps/web/public/hero/009.webp b/apps/web/public/hero/009.webp new file mode 100644 index 0000000..9a2cee0 Binary files /dev/null and b/apps/web/public/hero/009.webp differ diff --git a/apps/web/public/hero/010.jpg b/apps/web/public/hero/010.jpg new file mode 100644 index 0000000..7e3228c Binary files /dev/null and b/apps/web/public/hero/010.jpg differ diff --git a/apps/web/public/hero/010.webp b/apps/web/public/hero/010.webp new file mode 100644 index 0000000..ed771a6 Binary files /dev/null and b/apps/web/public/hero/010.webp differ diff --git a/apps/web/public/hero/011.jpg b/apps/web/public/hero/011.jpg new file mode 100644 index 0000000..a11ad56 Binary files /dev/null and b/apps/web/public/hero/011.jpg differ diff --git a/apps/web/public/hero/011.webp b/apps/web/public/hero/011.webp new file mode 100644 index 0000000..6cade8a Binary files /dev/null and b/apps/web/public/hero/011.webp differ diff --git a/apps/web/public/hero/012.jpg b/apps/web/public/hero/012.jpg new file mode 100644 index 0000000..e651644 Binary files /dev/null and b/apps/web/public/hero/012.jpg differ diff --git a/apps/web/public/hero/012.webp b/apps/web/public/hero/012.webp new file mode 100644 index 0000000..281dd67 Binary files /dev/null and b/apps/web/public/hero/012.webp differ diff --git a/apps/web/public/hero/013.jpg b/apps/web/public/hero/013.jpg new file mode 100644 index 0000000..4198b4a Binary files /dev/null and b/apps/web/public/hero/013.jpg differ diff --git a/apps/web/public/hero/013.webp b/apps/web/public/hero/013.webp new file mode 100644 index 0000000..591ead6 Binary files /dev/null and b/apps/web/public/hero/013.webp differ diff --git a/apps/web/public/hero/014.jpg b/apps/web/public/hero/014.jpg new file mode 100644 index 0000000..920575d Binary files /dev/null and b/apps/web/public/hero/014.jpg differ diff --git a/apps/web/public/hero/014.webp b/apps/web/public/hero/014.webp new file mode 100644 index 0000000..893279e Binary files /dev/null and b/apps/web/public/hero/014.webp differ diff --git a/apps/web/public/hero/015.jpg b/apps/web/public/hero/015.jpg new file mode 100644 index 0000000..df178ec Binary files /dev/null and b/apps/web/public/hero/015.jpg differ diff --git a/apps/web/public/hero/015.webp b/apps/web/public/hero/015.webp new file mode 100644 index 0000000..323e2f5 Binary files /dev/null and b/apps/web/public/hero/015.webp differ diff --git a/apps/web/public/hero/016.jpg b/apps/web/public/hero/016.jpg new file mode 100644 index 0000000..d06d5b2 Binary files /dev/null and b/apps/web/public/hero/016.jpg differ diff --git a/apps/web/public/hero/016.webp b/apps/web/public/hero/016.webp new file mode 100644 index 0000000..f498881 Binary files /dev/null and b/apps/web/public/hero/016.webp differ diff --git a/apps/web/public/hero/manifest.json b/apps/web/public/hero/manifest.json new file mode 100644 index 0000000..2341dd8 --- /dev/null +++ b/apps/web/public/hero/manifest.json @@ -0,0 +1,18 @@ +[ + {"jpg":"/hero/001.jpg","webp":"/hero/001.webp"}, + {"jpg":"/hero/002.jpg","webp":"/hero/002.webp"}, + {"jpg":"/hero/003.jpg","webp":"/hero/003.webp"}, + {"jpg":"/hero/004.jpg","webp":"/hero/004.webp"}, + {"jpg":"/hero/005.jpg","webp":"/hero/005.webp"}, + {"jpg":"/hero/006.jpg","webp":"/hero/006.webp"}, + {"jpg":"/hero/007.jpg","webp":"/hero/007.webp"}, + {"jpg":"/hero/008.jpg","webp":"/hero/008.webp"}, + {"jpg":"/hero/009.jpg","webp":"/hero/009.webp"}, + {"jpg":"/hero/010.jpg","webp":"/hero/010.webp"}, + {"jpg":"/hero/011.jpg","webp":"/hero/011.webp"}, + {"jpg":"/hero/012.jpg","webp":"/hero/012.webp"}, + {"jpg":"/hero/013.jpg","webp":"/hero/013.webp"}, + {"jpg":"/hero/014.jpg","webp":"/hero/014.webp"}, + {"jpg":"/hero/015.jpg","webp":"/hero/015.webp"}, + {"jpg":"/hero/016.jpg","webp":"/hero/016.webp"} +] diff --git a/apps/web/scripts/optimize-hero-photos.sh b/apps/web/scripts/optimize-hero-photos.sh new file mode 100755 index 0000000..7afc0ab --- /dev/null +++ b/apps/web/scripts/optimize-hero-photos.sh @@ -0,0 +1,93 @@ +#!/usr/bin/env bash +# Optimize a directory of source photos into the hero slideshow asset set. +# +# Usage: bash apps/web/scripts/optimize-hero-photos.sh +# Output: apps/web/public/hero/NNN.jpg, NNN.webp, manifest.json +# +# Re-running clears the existing hero directory and regenerates everything +# from scratch so the output is deterministic for any given input set. + +set -euo pipefail + +if [[ $# -ne 1 ]]; then + echo "Usage: $0 " >&2 + exit 64 +fi + +input_dir="$1" + +if [[ ! -d "$input_dir" ]]; then + echo "Error: input directory not found: $input_dir" >&2 + exit 66 +fi + +script_dir="$(cd "$(dirname "$0")" && pwd)" +output_dir="$script_dir/../public/hero" + +if ! command -v magick >/dev/null 2>&1; then + echo "Error: ImageMagick 'magick' not found in PATH." >&2 + echo "Install with: brew install imagemagick webp" >&2 + exit 69 +fi + +mkdir -p "$output_dir" + +find "$output_dir" -maxdepth 1 -type f \ + \( -name '*.jpg' -o -name '*.webp' -o -name 'manifest.json' \) -delete + +inputs=() +while IFS= read -r -d '' path; do + inputs+=("$path") +done < <(find "$input_dir" -maxdepth 1 -type f \ + \( -iname '*.jpg' -o -iname '*.jpeg' -o -iname '*.png' \) -print0 | sort -z) + +if [[ ${#inputs[@]} -eq 0 ]]; then + echo "Error: no .jpg/.jpeg/.png files found in $input_dir" >&2 + exit 65 +fi + +echo "Optimizing ${#inputs[@]} photo(s) → $output_dir" + +manifest_tmp="$output_dir/manifest.json.tmp" +: > "$manifest_tmp" +printf '[\n' >> "$manifest_tmp" + +i=0 +last_idx=$((${#inputs[@]} - 1)) +for src in "${inputs[@]}"; do + num=$(printf '%03d' "$((i + 1))") + jpg_out="$output_dir/$num.jpg" + webp_out="$output_dir/$num.webp" + + magick "$src" \ + -auto-orient \ + -resize '1920x1280^' \ + -gravity Center -extent '1920x1280' \ + -strip \ + -interlace JPEG \ + -sampling-factor 4:2:0 \ + -quality 82 \ + "$jpg_out" + + magick "$jpg_out" \ + -define webp:method=6 \ + -quality 80 \ + "$webp_out" + + jpg_kb=$(( $(wc -c < "$jpg_out") / 1024 )) + webp_kb=$(( $(wc -c < "$webp_out") / 1024 )) + printf ' %s — jpg %dKB · webp %dKB\n' "$num" "$jpg_kb" "$webp_kb" + + if [[ $i -eq $last_idx ]]; then + printf ' {"jpg":"/hero/%s.jpg","webp":"/hero/%s.webp"}\n' "$num" "$num" >> "$manifest_tmp" + else + printf ' {"jpg":"/hero/%s.jpg","webp":"/hero/%s.webp"},\n' "$num" "$num" >> "$manifest_tmp" + fi + + i=$((i + 1)) +done + +printf ']\n' >> "$manifest_tmp" +mv "$manifest_tmp" "$output_dir/manifest.json" + +echo "Wrote $output_dir/manifest.json (${#inputs[@]} entries)" diff --git a/apps/web/src/components/HeroSlideshow.tsx b/apps/web/src/components/HeroSlideshow.tsx new file mode 100644 index 0000000..aeeb9e7 --- /dev/null +++ b/apps/web/src/components/HeroSlideshow.tsx @@ -0,0 +1,177 @@ +import { useEffect, useState, type CSSProperties } from 'react'; +import { usePrefersReducedMotion } from '@/hooks/usePrefersReducedMotion'; +import { cn } from '@/lib/utils'; + +type Photo = { jpg: string; webp: string }; +type PanVector = { fromX: number; fromY: number; toX: number; toY: number }; + +const VISIBLE_MS = 8000; +const CROSSFADE_MS = 1500; +const LAYER_LIFETIME_MS = CROSSFADE_MS + VISIBLE_MS + CROSSFADE_MS; +const PRELOAD_TIMEOUT_MS = 3000; +const PAN_RANGE_PCT = 2; + +function shuffle(arr: readonly T[]): T[] { + const out = arr.slice(); + for (let i = out.length - 1; i > 0; i--) { + const j = Math.floor(Math.random() * (i + 1)); + const tmp = out[i] as T; + out[i] = out[j] as T; + out[j] = tmp; + } + return out; +} + +function randomVector(): PanVector { + const r = () => (Math.random() * 2 - 1) * PAN_RANGE_PCT; + return { fromX: r(), fromY: r(), toX: r(), toY: r() }; +} + +function preload(url: string): Promise { + return new Promise((resolve) => { + const img = new Image(); + let settled = false; + const done = () => { + if (settled) return; + settled = true; + resolve(); + }; + img.onload = done; + img.onerror = done; + img.src = url; + setTimeout(done, PRELOAD_TIMEOUT_MS); + }); +} + +interface PanLayerProps { + photo: Photo; + vector: PanVector; + fadingIn: boolean; + fadingOut: boolean; + reducedMotion: boolean; +} + +function PanLayer({ photo, vector, fadingIn, fadingOut, reducedMotion }: PanLayerProps) { + const [appeared, setAppeared] = useState(!fadingIn); + + useEffect(() => { + if (!fadingIn) return; + const id = requestAnimationFrame(() => { + requestAnimationFrame(() => setAppeared(true)); + }); + return () => cancelAnimationFrame(id); + }, [fadingIn]); + + const opacity = fadingOut ? 0 : appeared ? 1 : 0; + + const style = { + opacity, + transition: `opacity ${CROSSFADE_MS}ms ease-in-out`, + animation: reducedMotion ? 'none' : `hero-ken-burns ${LAYER_LIFETIME_MS}ms linear forwards`, + transformOrigin: 'center center', + willChange: 'transform, opacity', + '--kb-from-x': `${vector.fromX}%`, + '--kb-from-y': `${vector.fromY}%`, + '--kb-to-x': `${vector.toX}%`, + '--kb-to-y': `${vector.toY}%`, + } as CSSProperties; + + return ( + + + + + ); +} + +interface HeroSlideshowProps { + className?: string; +} + +export function HeroSlideshow({ className }: HeroSlideshowProps) { + const reducedMotion = usePrefersReducedMotion(); + const [photos, setPhotos] = useState([]); + const [tick, setTick] = useState(0); + const [currentVector, setCurrentVector] = useState(randomVector); + const [nextVector, setNextVector] = useState(null); + + useEffect(() => { + let cancelled = false; + fetch('/hero/manifest.json') + .then((r) => (r.ok ? (r.json() as Promise) : [])) + .catch(() => [] as Photo[]) + .then((data) => { + if (cancelled) return; + if (Array.isArray(data) && data.length > 0) { + setPhotos(shuffle(data)); + } + }); + return () => { + cancelled = true; + }; + }, []); + + useEffect(() => { + if (photos.length === 0) return; + let cancelled = false; + const timers: ReturnType[] = []; + + const visibleTimer = setTimeout(() => { + if (cancelled) return; + const nextIdx = (tick + 1) % photos.length; + const nextPhoto = photos[nextIdx]; + if (!nextPhoto) return; + preload(nextPhoto.jpg).then(() => { + if (cancelled) return; + const v = randomVector(); + setNextVector(v); + const settleTimer = setTimeout(() => { + if (cancelled) return; + setCurrentVector(v); + setNextVector(null); + setTick((prev) => prev + 1); + }, CROSSFADE_MS); + timers.push(settleTimer); + }); + }, VISIBLE_MS); + timers.push(visibleTimer); + + return () => { + cancelled = true; + timers.forEach(clearTimeout); + }; + }, [photos, tick]); + + if (photos.length === 0) { + return