|
| 1 | +"use client"; |
| 2 | + |
| 3 | +import { useEffect, useRef, useState } from "react"; |
| 4 | + |
| 5 | +import { useMotionEnabled } from "@/components/experience-provider"; |
| 6 | +import { cn } from "@/lib/utils"; |
| 7 | +import { EDITION_GUTTER } from "@/components/edition"; |
| 8 | + |
| 9 | +// Clip opens and closes on pure black: `lighten` turns that black into the ink surface colour and the |
| 10 | +// edge mask feathers the frame, so the first/last frames are indistinguishable from the page. |
| 11 | +const FADE = |
| 12 | + "linear-gradient(to right, transparent, #000 10%, #000 90%, transparent), linear-gradient(to bottom, transparent, #000 12%, #000 88%, transparent)"; |
| 13 | + |
| 14 | +export function AboutFilm() { |
| 15 | + const ref = useRef<HTMLVideoElement>(null); |
| 16 | + const motion = useMotionEnabled(); |
| 17 | + const [muted, setMuted] = useState(true); |
| 18 | + |
| 19 | + // Play only while on screen; nothing loads until it is near the viewport. |
| 20 | + useEffect(() => { |
| 21 | + const v = ref.current; |
| 22 | + if (!v || !motion) return; |
| 23 | + const io = new IntersectionObserver( |
| 24 | + ([e]) => { |
| 25 | + if (e.isIntersecting) { |
| 26 | + v.preload = "auto"; |
| 27 | + v.play().catch(() => {}); |
| 28 | + } else v.pause(); |
| 29 | + }, |
| 30 | + { threshold: 0.35 }, |
| 31 | + ); |
| 32 | + io.observe(v); |
| 33 | + return () => io.disconnect(); |
| 34 | + }, [motion]); |
| 35 | + |
| 36 | + return ( |
| 37 | + <section data-surface="ink" aria-label="Film" className="tone-ink relative py-16 md:py-24"> |
| 38 | + <div className={cn("relative mx-auto max-w-[1600px] px-4 md:px-8", EDITION_GUTTER)}> |
| 39 | + <video |
| 40 | + ref={ref} |
| 41 | + className="aspect-[23/12.5] w-full bg-transparent object-cover" |
| 42 | + style={{ maskImage: FADE, WebkitMaskImage: FADE, maskComposite: "intersect", WebkitMaskComposite: "source-in", mixBlendMode: "lighten" }} |
| 43 | + muted={muted} |
| 44 | + loop |
| 45 | + playsInline |
| 46 | + preload="none" |
| 47 | + controls={!motion} |
| 48 | + aria-label="Short film from the bits&bytes™ community" |
| 49 | + > |
| 50 | + <source src="/video/ash-no-cash-960.mp4" type="video/mp4" media="(max-width: 768px)" /> |
| 51 | + <source src="/video/ash-no-cash.mp4" type="video/mp4" /> |
| 52 | + </video> |
| 53 | + {motion ? ( |
| 54 | + <button |
| 55 | + type="button" |
| 56 | + onClick={() => { |
| 57 | + setMuted((m) => !m); |
| 58 | + ref.current?.play().catch(() => {}); |
| 59 | + }} |
| 60 | + className="absolute bottom-2 right-4 font-mono text-xs font-bold uppercase tracking-[0.2em] text-paper/70 hover:text-signal md:right-8" |
| 61 | + > |
| 62 | + [{muted ? "Sound on" : "Sound off"}] |
| 63 | + </button> |
| 64 | + ) : null} |
| 65 | + </div> |
| 66 | + </section> |
| 67 | + ); |
| 68 | +} |
0 commit comments