Skip to content

Commit 0467bc8

Browse files
committed
docs(examples): make hover-audio accessible, lazy-loaded, and guard-complete
HoverVideo now: (1) exposes a focusable button that toggles/plays sound by keyboard, touch and pointer — hover is an enhancement, not the only path; (2) gates the source behind an IntersectionObserver so offscreen cards no longer download/decode, releasing the buffer on exit; (3) still blocks autoplay under reduced motion while allowing voluntary playback via the button. Routed all 30 Thirty-Days cards through it (hasAudio={false} for the 12 silent ones) so no raw <video autoPlay> bypasses the motion guard. Flagged by Magi (P1 #4/#5/#6).
1 parent 0f6259d commit 0467bc8

2 files changed

Lines changed: 82 additions & 38 deletions

File tree

‎docs/snippets/hover-video.jsx‎

Lines changed: 70 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
export const HoverVideo = ({ src, poster, className }) => {
1+
export const HoverVideo = ({ src, poster, className, hasAudio = true }) => {
22
const videoRef = useRef(null);
3+
const wrapRef = useRef(null);
34
const [muted, setMuted] = useState(true);
5+
const [inView, setInView] = useState(false);
46

5-
// Lazy initializer, not a post-mount effect: with useState(false) the first
6-
// committed render would emit `<video src autoPlay loop>` and only then pull the
7-
// attributes, so a reduce-motion visitor has already started fetching the file.
7+
// Lazy initializer, not a post-mount effect: the preference is known on the
8+
// first committed render, so a reduce-motion visitor never autoplays first.
89
const [reduced, setReduced] = useState(
910
() =>
1011
typeof window !== "undefined" &&
@@ -18,45 +19,88 @@ export const HoverVideo = ({ src, poster, className }) => {
1819
return () => query.removeEventListener("change", onChange);
1920
}, []);
2021

21-
// React can drop src/autoPlay/loop from the DOM, but that neither pauses a
22-
// playing element nor aborts its resource: pause(), removeAttribute("src") and
23-
// load() are all required when the preference flips to reduce mid-session.
22+
// Only assign/decode a source near the viewport. Without this every card on
23+
// the page downloads and decodes its MP4 immediately, on- or off-screen.
2424
useEffect(() => {
25-
if (!reduced) return;
25+
const el = wrapRef.current;
26+
if (!el || typeof IntersectionObserver !== "function") {
27+
setInView(true);
28+
return;
29+
}
30+
const observer = new IntersectionObserver(
31+
(entries) => setInView(entries[0]?.isIntersecting ?? false),
32+
{ rootMargin: "200px" },
33+
);
34+
observer.observe(el);
35+
return () => observer.disconnect();
36+
}, []);
37+
38+
// Release the decoded resource once the card leaves the viewport. React props
39+
// alone neither pause an element nor abort its download, so pause() +
40+
// removeAttribute("src") + load() are all required. This same teardown is what
41+
// stops autoplay when the reduce-motion preference flips on mid-session.
42+
useEffect(() => {
43+
if (inView && !reduced) return;
2644
const video = videoRef.current;
2745
if (!video) return;
2846
video.pause();
29-
video.removeAttribute("src");
30-
video.load();
31-
}, [reduced]);
47+
if (!inView) {
48+
video.removeAttribute("src");
49+
video.load();
50+
setMuted(true);
51+
}
52+
}, [inView, reduced]);
3253

3354
const hear = () => {
34-
if (reduced) return;
3555
const video = videoRef.current;
36-
if (!video) return;
56+
if (!video || !hasAudio) return;
3757
setMuted(false);
3858
video.muted = false;
59+
// Voluntary playback — allowed even under reduced motion (autoplay is not).
3960
video.play().catch(() => {});
4061
};
4162
const silence = () => {
4263
setMuted(true);
4364
const video = videoRef.current;
4465
if (video) video.muted = true;
4566
};
67+
const toggle = () => (muted ? hear() : silence());
68+
69+
const autoplaying = inView && !reduced;
4670

4771
return (
48-
<video
49-
ref={videoRef}
50-
className={className}
51-
src={reduced ? undefined : src}
52-
poster={poster}
53-
autoPlay={!reduced}
54-
muted={muted}
55-
loop={!reduced}
56-
playsInline
57-
preload="none"
58-
onMouseEnter={hear}
59-
onMouseLeave={silence}
60-
/>
72+
<div ref={wrapRef} className={`relative overflow-hidden ${className ?? ""}`}>
73+
<video
74+
ref={videoRef}
75+
className="absolute inset-0 h-full w-full object-cover"
76+
src={inView ? src : undefined}
77+
poster={poster}
78+
autoPlay={autoplaying}
79+
muted={muted}
80+
loop={autoplaying}
81+
playsInline
82+
preload="none"
83+
onMouseEnter={() => {
84+
if (hasAudio && !reduced) hear();
85+
}}
86+
onMouseLeave={silence}
87+
/>
88+
{hasAudio && (
89+
<button
90+
type="button"
91+
onClick={toggle}
92+
aria-pressed={!muted}
93+
aria-label={muted ? "Play this preview with sound" : "Mute this preview"}
94+
className="absolute left-2 top-2 z-10 inline-flex items-center gap-1 rounded-full bg-black/60 px-2.5 py-1 text-xs font-medium text-white backdrop-blur transition hover:bg-black/75 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-white"
95+
>
96+
{muted ? (
97+
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M11 5 6 9H2v6h4l5 4V5z" /><line x1="23" y1="9" x2="17" y2="15" /><line x1="17" y1="9" x2="23" y2="15" /></svg>
98+
) : (
99+
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M11 5 6 9H2v6h4l5 4V5z" /><path d="M15.5 8.5a5 5 0 0 1 0 7" /><path d="M18.5 5.5a9 9 0 0 1 0 13" /></svg>
100+
)}
101+
{muted ? "Sound" : "On"}
102+
</button>
103+
)}
104+
</div>
61105
);
62106
};

‎docs/thirty-days.mdx‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ Days 1 to 9 cover the inputs: a repo, a track, a topic, a speaker, a design file
1919

2020
<CardGroup cols={2}>
2121
<Card title="Day 1 — Install HyperFrames" href="https://x.com/HeyGen/status/2074176916819685648">
22-
<video className="w-full aspect-video rounded-lg object-cover bg-zinc-100 dark:bg-zinc-900" src="https://static.heygen.ai/hyperframes-oss/docs/images/showcase/thirty-days-day-01.mp4" poster="https://static.heygen.ai/hyperframes-oss/docs/images/showcase/thirty-days-day-01.jpg" autoPlay muted loop playsInline preload="none" />
22+
<HoverVideo className="w-full aspect-video rounded-lg object-cover bg-zinc-100 dark:bg-zinc-900" src="https://static.heygen.ai/hyperframes-oss/docs/images/showcase/thirty-days-day-01.mp4" poster="https://static.heygen.ai/hyperframes-oss/docs/images/showcase/thirty-days-day-01.jpg" hasAudio={false} />
2323

2424
Give your coding agent the HyperFrames skills. One router reads the request and picks the workflow.
2525

2626
</Card>
2727
<Card title="Day 2 — Give your brand a motion language" href="https://x.com/HeyGen/status/2074574265714905167">
28-
<video className="w-full aspect-video rounded-lg object-cover bg-zinc-100 dark:bg-zinc-900" src="https://static.heygen.ai/hyperframes-oss/docs/images/showcase/thirty-days-day-02.mp4" poster="https://static.heygen.ai/hyperframes-oss/docs/images/showcase/thirty-days-day-02.jpg" autoPlay muted loop playsInline preload="none" />
28+
<HoverVideo className="w-full aspect-video rounded-lg object-cover bg-zinc-100 dark:bg-zinc-900" src="https://static.heygen.ai/hyperframes-oss/docs/images/showcase/thirty-days-day-02.mp4" poster="https://static.heygen.ai/hyperframes-oss/docs/images/showcase/thirty-days-day-02.jpg" hasAudio={false} />
2929

3030
Turn a visual identity into reusable motion direction, written down once as `FRAME.md` and read on every later build.
3131

@@ -55,7 +55,7 @@ Days 1 to 9 cover the inputs: a repo, a track, a topic, a speaker, a design file
5555

5656
</Card>
5757
<Card title="Day 7 — Motion graphics" href="https://x.com/HeyGen/status/2076381187640324427">
58-
<video className="w-full aspect-video rounded-lg object-cover bg-zinc-100 dark:bg-zinc-900" src="https://static.heygen.ai/hyperframes-oss/docs/images/showcase/thirty-days-day-07.mp4" poster="https://static.heygen.ai/hyperframes-oss/docs/images/showcase/thirty-days-day-07.jpg" autoPlay muted loop playsInline preload="none" />
58+
<HoverVideo className="w-full aspect-video rounded-lg object-cover bg-zinc-100 dark:bg-zinc-900" src="https://static.heygen.ai/hyperframes-oss/docs/images/showcase/thirty-days-day-07.mp4" poster="https://static.heygen.ai/hyperframes-oss/docs/images/showcase/thirty-days-day-07.jpg" hasAudio={false} />
5959

6060
Make a short, design-led animation where the motion carries the message.
6161

@@ -67,7 +67,7 @@ Days 1 to 9 cover the inputs: a repo, a track, a topic, a speaker, a design file
6767

6868
</Card>
6969
<Card title="Day 9 — Figma to HyperFrames" href="https://x.com/HeyGen/status/2077072141309382770">
70-
<video className="w-full aspect-video rounded-lg object-cover bg-zinc-100 dark:bg-zinc-900" src="https://static.heygen.ai/hyperframes-oss/docs/images/showcase/thirty-days-day-09.mp4" poster="https://static.heygen.ai/hyperframes-oss/docs/images/showcase/thirty-days-day-09.jpg" autoPlay muted loop playsInline preload="none" />
70+
<HoverVideo className="w-full aspect-video rounded-lg object-cover bg-zinc-100 dark:bg-zinc-900" src="https://static.heygen.ai/hyperframes-oss/docs/images/showcase/thirty-days-day-09.mp4" poster="https://static.heygen.ai/hyperframes-oss/docs/images/showcase/thirty-days-day-09.jpg" hasAudio={false} />
7171

7272
Turn an existing design into a video composition — as live HTML, not a flattened export.
7373

@@ -80,7 +80,7 @@ Days 10 to 19 are about steering: how you ask, what you inspect, and what you fi
8080

8181
<CardGroup cols={2}>
8282
<Card title="Day 10 — Anatomy of a prompt" href="https://x.com/HeyGen/status/2077438104982667282">
83-
<video className="w-full aspect-video rounded-lg object-cover bg-zinc-100 dark:bg-zinc-900" src="https://static.heygen.ai/hyperframes-oss/docs/images/showcase/thirty-days-day-10.mp4" poster="https://static.heygen.ai/hyperframes-oss/docs/images/showcase/thirty-days-day-10.jpg" autoPlay muted loop playsInline preload="none" />
83+
<HoverVideo className="w-full aspect-video rounded-lg object-cover bg-zinc-100 dark:bg-zinc-900" src="https://static.heygen.ai/hyperframes-oss/docs/images/showcase/thirty-days-day-10.mp4" poster="https://static.heygen.ai/hyperframes-oss/docs/images/showcase/thirty-days-day-10.jpg" hasAudio={false} />
8484

8585
Structure a request so the agent gets the important intent right the first time.
8686

@@ -98,19 +98,19 @@ Days 10 to 19 are about steering: how you ask, what you inspect, and what you fi
9898

9999
</Card>
100100
<Card title="Day 13 — Studio preview, part 1" href="https://x.com/HeyGen/status/2078589328562016559">
101-
<video className="w-full aspect-video rounded-lg object-cover bg-zinc-100 dark:bg-zinc-900" src="https://static.heygen.ai/hyperframes-oss/docs/images/showcase/thirty-days-day-13.mp4" poster="https://static.heygen.ai/hyperframes-oss/docs/images/showcase/thirty-days-day-13.jpg" autoPlay muted loop playsInline preload="none" />
101+
<HoverVideo className="w-full aspect-video rounded-lg object-cover bg-zinc-100 dark:bg-zinc-900" src="https://static.heygen.ai/hyperframes-oss/docs/images/showcase/thirty-days-day-13.mp4" poster="https://static.heygen.ai/hyperframes-oss/docs/images/showcase/thirty-days-day-13.jpg" hasAudio={false} />
102102

103103
Inspect a composition before rendering — in Studio, through your agent, or from the terminal.
104104

105105
</Card>
106106
<Card title="Day 14 — Studio preview, part 2: keyframes" href="https://x.com/HeyGen/status/2078945075787452660">
107-
<video className="w-full aspect-video rounded-lg object-cover bg-zinc-100 dark:bg-zinc-900" src="https://static.heygen.ai/hyperframes-oss/docs/images/showcase/thirty-days-day-14.mp4" poster="https://static.heygen.ai/hyperframes-oss/docs/images/showcase/thirty-days-day-14.jpg" autoPlay muted loop playsInline preload="none" />
107+
<HoverVideo className="w-full aspect-video rounded-lg object-cover bg-zinc-100 dark:bg-zinc-900" src="https://static.heygen.ai/hyperframes-oss/docs/images/showcase/thirty-days-day-14.mp4" poster="https://static.heygen.ai/hyperframes-oss/docs/images/showcase/thirty-days-day-14.jpg" hasAudio={false} />
108108

109109
Adjust motion with visible keyframe controls, one lane per animated property.
110110

111111
</Card>
112112
<Card title="Day 15 — Sample the web" href="https://x.com/HeyGen/status/2079251321484722675">
113-
<video className="w-full aspect-video rounded-lg object-cover bg-zinc-100 dark:bg-zinc-900" src="https://static.heygen.ai/hyperframes-oss/docs/images/showcase/thirty-days-day-15.mp4" poster="https://static.heygen.ai/hyperframes-oss/docs/images/showcase/thirty-days-day-15.jpg" autoPlay muted loop playsInline preload="none" />
113+
<HoverVideo className="w-full aspect-video rounded-lg object-cover bg-zinc-100 dark:bg-zinc-900" src="https://static.heygen.ai/hyperframes-oss/docs/images/showcase/thirty-days-day-15.mp4" poster="https://static.heygen.ai/hyperframes-oss/docs/images/showcase/thirty-days-day-15.jpg" hasAudio={false} />
114114

115115
Bring useful web motion into a composition by capturing the real page.
116116

@@ -147,13 +147,13 @@ Days 20 to 30 move from one composition to a repeatable pipeline: reusable block
147147

148148
<CardGroup cols={2}>
149149
<Card title="Day 20 — Claude Design" href="https://x.com/HyperFrames_/status/2081184676430160379">
150-
<video className="w-full aspect-video rounded-lg object-cover bg-zinc-100 dark:bg-zinc-900" src="https://static.heygen.ai/hyperframes-oss/docs/images/showcase/thirty-days-day-20.mp4" poster="https://static.heygen.ai/hyperframes-oss/docs/images/showcase/thirty-days-day-20.jpg" autoPlay muted loop playsInline preload="none" />
150+
<HoverVideo className="w-full aspect-video rounded-lg object-cover bg-zinc-100 dark:bg-zinc-900" src="https://static.heygen.ai/hyperframes-oss/docs/images/showcase/thirty-days-day-20.mp4" poster="https://static.heygen.ai/hyperframes-oss/docs/images/showcase/thirty-days-day-20.jpg" hasAudio={false} />
151151

152152
Take a design direction into a HyperFrames project without redrawing it by hand.
153153

154154
</Card>
155155
<Card title="Day 21 — Cloud rendering" href="https://x.com/HyperFrames_/status/2081491370485952790">
156-
<video className="w-full aspect-video rounded-lg object-cover bg-zinc-100 dark:bg-zinc-900" src="https://static.heygen.ai/hyperframes-oss/docs/images/showcase/thirty-days-day-21.mp4" poster="https://static.heygen.ai/hyperframes-oss/docs/images/showcase/thirty-days-day-21.jpg" autoPlay muted loop playsInline preload="none" />
156+
<HoverVideo className="w-full aspect-video rounded-lg object-cover bg-zinc-100 dark:bg-zinc-900" src="https://static.heygen.ai/hyperframes-oss/docs/images/showcase/thirty-days-day-21.mp4" poster="https://static.heygen.ai/hyperframes-oss/docs/images/showcase/thirty-days-day-21.jpg" hasAudio={false} />
157157

158158
Render without making one local computer the bottleneck. Two commands hand the job to the cloud.
159159

@@ -183,7 +183,7 @@ Days 20 to 30 move from one composition to a repeatable pipeline: reusable block
183183

184184
</Card>
185185
<Card title="Day 26 — Media effects and overlays" href="https://x.com/HyperFrames_/status/2083324288632045910">
186-
<video className="w-full aspect-video rounded-lg object-cover bg-zinc-100 dark:bg-zinc-900" src="https://static.heygen.ai/hyperframes-oss/docs/images/showcase/thirty-days-day-26.mp4" poster="https://static.heygen.ai/hyperframes-oss/docs/images/showcase/thirty-days-day-26.jpg" autoPlay muted loop playsInline preload="none" />
186+
<HoverVideo className="w-full aspect-video rounded-lg object-cover bg-zinc-100 dark:bg-zinc-900" src="https://static.heygen.ai/hyperframes-oss/docs/images/showcase/thirty-days-day-26.mp4" poster="https://static.heygen.ai/hyperframes-oss/docs/images/showcase/thirty-days-day-26.jpg" hasAudio={false} />
187187

188188
Add designed treatments to real media. Two to six authored colour ramps change the whole visual language.
189189

@@ -207,7 +207,7 @@ Days 20 to 30 move from one composition to a repeatable pipeline: reusable block
207207

208208
</Card>
209209
<Card title="Day 30 — Thirty for thirty">
210-
<video className="w-full aspect-video rounded-lg object-cover bg-zinc-100 dark:bg-zinc-900" src="https://static.heygen.ai/hyperframes-oss/docs/images/showcase/thirty-days-day-30.mp4" poster="https://static.heygen.ai/hyperframes-oss/docs/images/showcase/thirty-days-day-30.jpg" autoPlay muted loop playsInline preload="none" />
210+
<HoverVideo className="w-full aspect-video rounded-lg object-cover bg-zinc-100 dark:bg-zinc-900" src="https://static.heygen.ai/hyperframes-oss/docs/images/showcase/thirty-days-day-30.mp4" poster="https://static.heygen.ai/hyperframes-oss/docs/images/showcase/thirty-days-day-30.jpg" hasAudio={false} />
211211

212212
Thirty days in one cut — a second from every lesson, back to back. From install on Day 1 to the whole series here.
213213

0 commit comments

Comments
 (0)