hyperframes 0.5.0-alpha.8 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/dist/cli.js +7518 -5457
  2. package/dist/commands/contrast-audit.browser.js +2 -0
  3. package/dist/docs/compositions.md +35 -7
  4. package/dist/docs/rendering.md +4 -1
  5. package/dist/hyperframe-runtime.js +82 -32
  6. package/dist/hyperframe.manifest.json +1 -1
  7. package/dist/hyperframe.runtime.iife.js +82 -32
  8. package/dist/skills/gsap/SKILL.md +30 -1
  9. package/dist/skills/hyperframes/SKILL.md +165 -39
  10. package/dist/skills/hyperframes/house-style.md +3 -1
  11. package/dist/skills/hyperframes/patterns.md +73 -0
  12. package/dist/skills/hyperframes/references/beat-direction.md +102 -0
  13. package/dist/skills/hyperframes/references/design-picker.md +117 -0
  14. package/dist/skills/hyperframes/references/motion-principles.md +73 -0
  15. package/dist/skills/hyperframes/references/narration.md +92 -0
  16. package/dist/skills/hyperframes/references/prompt-expansion.md +68 -0
  17. package/dist/skills/hyperframes/references/techniques.md +387 -0
  18. package/dist/skills/hyperframes/references/transcript-guide.md +1 -45
  19. package/dist/skills/hyperframes/references/video-composition.md +62 -0
  20. package/dist/skills/hyperframes/scripts/contrast-report.mjs +10 -0
  21. package/dist/skills/hyperframes/templates/design-picker.html +1432 -0
  22. package/dist/skills/hyperframes/visual-styles.md +339 -107
  23. package/dist/skills/hyperframes-cli/SKILL.md +21 -27
  24. package/dist/studio/assets/hyperframes-player-CoI5h1xv.js +353 -0
  25. package/dist/studio/assets/index-BKjcNNNd.css +1 -0
  26. package/dist/studio/assets/index-CqiisJmo.js +93 -0
  27. package/dist/studio/index.html +2 -2
  28. package/dist/templates/_shared/AGENTS.md +7 -7
  29. package/dist/templates/_shared/CLAUDE.md +15 -7
  30. package/package.json +4 -2
  31. package/dist/skills/hyperframes/references/tts.md +0 -75
  32. package/dist/studio/assets/hyperframes-player-vibA20NC.js +0 -198
  33. package/dist/studio/assets/index-0Zt0t13W.css +0 -1
  34. package/dist/studio/assets/index-C9f5eif8.js +0 -105
@@ -0,0 +1,387 @@
1
+ # Visual Techniques Reference
2
+
3
+ 10 proven techniques from production HyperFrames videos. Use these in your storyboard and compositions to create visually rich, professional output. Each technique includes a minimal code pattern you can adapt.
4
+
5
+ These are NOT advanced — they're standard motion design patterns that every composition should use at least 2-3 of.
6
+
7
+ ---
8
+
9
+ ## 1. SVG Path Drawing
10
+
11
+ A path draws itself in real-time, like someone tracing with a pen. Use for revealing diagrams, arrows, connector lines, or brand marks.
12
+
13
+ ```html
14
+ <svg viewBox="0 0 400 200">
15
+ <path
16
+ class="draw-path"
17
+ d="M 50 100 L 200 50 L 350 100"
18
+ stroke="#c84f1c"
19
+ stroke-width="4"
20
+ fill="none"
21
+ stroke-linecap="round"
22
+ />
23
+ </svg>
24
+ <style>
25
+ .draw-path {
26
+ stroke-dasharray: 280;
27
+ stroke-dashoffset: 280;
28
+ }
29
+ </style>
30
+ <script>
31
+ tl.to(".draw-path", { strokeDashoffset: 0, duration: 0.7, ease: "power2.out" }, 0.5);
32
+ </script>
33
+ ```
34
+
35
+ Use `path.getTotalLength()` to calculate the dasharray value dynamically.
36
+
37
+ ---
38
+
39
+ ## 2. Canvas 2D Procedural Art
40
+
41
+ Animated noise, particle fields, data visualizations — anything that evolves frame-by-frame. Drive it with a GSAP proxy.
42
+
43
+ ```html
44
+ <canvas id="proc-canvas" width="1920" height="1080"></canvas>
45
+ <script>
46
+ var canvas = document.getElementById("proc-canvas");
47
+ var ctx = canvas.getContext("2d");
48
+
49
+ function hash(x, y) {
50
+ var n = x * 374761393 + y * 668265263;
51
+ n = (n ^ (n >> 13)) * 1274126177;
52
+ return ((n ^ (n >> 16)) & 0x7fffffff) / 0x7fffffff;
53
+ }
54
+
55
+ function drawFrame(t) {
56
+ ctx.fillStyle = "#0a0a0a";
57
+ ctx.fillRect(0, 0, 1920, 1080);
58
+ for (var i = 0; i < 200; i++) {
59
+ var x = hash(i, 0) * 1920;
60
+ var y = hash(i, 1) * 1080;
61
+ var brightness = hash(i, Math.floor(t * 10)) * 255;
62
+ ctx.fillStyle = "rgba(255, 255, 255, " + brightness / 255 + ")";
63
+ ctx.beginPath();
64
+ ctx.arc(x, y, 2, 0, Math.PI * 2);
65
+ ctx.fill();
66
+ }
67
+ }
68
+
69
+ var proxy = { time: 0 };
70
+ tl.to(
71
+ proxy,
72
+ {
73
+ time: 5,
74
+ duration: 5,
75
+ ease: "none",
76
+ onUpdate: function () {
77
+ drawFrame(proxy.time);
78
+ },
79
+ },
80
+ 0,
81
+ );
82
+ </script>
83
+ ```
84
+
85
+ The `hash()` function is deterministic — same frame renders identically every time.
86
+
87
+ ---
88
+
89
+ ## 3. CSS 3D Transforms
90
+
91
+ Perspective rotations create depth. Use for product showcases, card flips, architectural reveals.
92
+
93
+ ```html
94
+ <div class="stage" style="perspective: 900px;">
95
+ <div class="card-3d" style="transform-style: preserve-3d;">
96
+ <div class="face front">Product</div>
97
+ <div class="face back" style="transform: rotateY(180deg);">Details</div>
98
+ </div>
99
+ </div>
100
+ <script>
101
+ tl.to(".card-3d", { rotationY: 360, rotationX: 15, duration: 1.2, ease: "sine.inOut" }, 0);
102
+ </script>
103
+ ```
104
+
105
+ Always set `perspective` on the parent, `transform-style: preserve-3d` on the animated element.
106
+
107
+ ---
108
+
109
+ ## 4. Per-Word Kinetic Typography
110
+
111
+ Words appear one-by-one, synced to transcript.json timestamps. The core technique for narration-driven videos.
112
+
113
+ ```html
114
+ <div class="headline">
115
+ <span class="word w-0">Anything</span>
116
+ <span class="word w-1">a</span>
117
+ <span class="word w-2">browser</span>
118
+ <span class="word w-3">can</span>
119
+ <span class="word w-4">render</span>
120
+ </div>
121
+ <style>
122
+ .word {
123
+ display: inline-block;
124
+ opacity: 0;
125
+ margin: 0 0.12em;
126
+ }
127
+ </style>
128
+ <script>
129
+ // Word onset times from transcript.json (seconds relative to beat start)
130
+ var timings = [0.0, 0.23, 0.28, 0.63, 0.78];
131
+ var slides = [80, 60, 50, 25, 12]; // horizontal slide decay (px)
132
+
133
+ document.querySelectorAll(".word").forEach(function (word, i) {
134
+ tl.from(
135
+ word,
136
+ {
137
+ x: slides[i],
138
+ y: 14,
139
+ opacity: 0,
140
+ duration: 0.35,
141
+ ease: "power2.out",
142
+ },
143
+ timings[i],
144
+ );
145
+ });
146
+ </script>
147
+ ```
148
+
149
+ The slide distance DECAYS per word (80→12px) — mimics a camera settling.
150
+
151
+ ---
152
+
153
+ ## 5. Lottie Animation
154
+
155
+ Vector animations that play inside a composition. Use for logos, character animations, icons.
156
+
157
+ ```html
158
+ <script src="https://cdn.jsdelivr.net/npm/@dotlottie/player-component@2.7.12/dist/dotlottie-player.js"></script>
159
+ <dotlottie-player
160
+ class="lottie"
161
+ src="../capture/assets/lottie/animation-0.json"
162
+ autoplay
163
+ loop
164
+ speed="1.5"
165
+ style="width:500px;height:500px;"
166
+ >
167
+ </dotlottie-player>
168
+ <script>
169
+ gsap.set(".lottie", { scale: 0.3, opacity: 0 });
170
+ tl.to(".lottie", { scale: 1, opacity: 1, duration: 0.35, ease: "back.out(1.6)" }, 0.2);
171
+ </script>
172
+ ```
173
+
174
+ Or use lottie-web for more control:
175
+
176
+ ```javascript
177
+ var anim = lottie.loadAnimation({
178
+ container: document.getElementById("anim"),
179
+ renderer: "svg",
180
+ loop: false,
181
+ autoplay: false,
182
+ path: "../capture/assets/lottie/animation-0.json",
183
+ });
184
+ ```
185
+
186
+ ---
187
+
188
+ ## 6. Video Compositing
189
+
190
+ Embed real video footage inside compositions. Videos must be `muted` with `playsinline`.
191
+
192
+ ```html
193
+ <div class="video-frame" style="width:680px;height:840px;border-radius:16px;overflow:hidden;">
194
+ <video
195
+ id="footage"
196
+ src="../capture/assets/videos/clip.mp4"
197
+ muted
198
+ playsinline
199
+ style="width:100%;height:100%;object-fit:cover;"
200
+ ></video>
201
+ </div>
202
+ <script>
203
+ // Video playback is controlled by the framework — don't call play() manually
204
+ tl.from(".video-frame", { scale: 0.9, opacity: 0, duration: 0.3, ease: "power2.out" }, 0);
205
+ </script>
206
+ ```
207
+
208
+ The HyperFrames runtime handles video seeking and playback.
209
+
210
+ ---
211
+
212
+ ## 7. Character-by-Character Typing
213
+
214
+ Terminal typing effect using `tl.call()` to update text content character by character.
215
+
216
+ ```html
217
+ <div class="terminal-line">
218
+ <span class="prompt">❯</span>
219
+ <span class="typed" id="typed-text"></span>
220
+ <span class="cursor" style="width:11px;height:22px;background:#333;display:inline-block;"></span>
221
+ </div>
222
+ <script>
223
+ var CMD = "npx hyperframes init";
224
+ var typed = document.getElementById("typed-text");
225
+
226
+ // Cursor blinks
227
+ tl.to(".cursor", { opacity: 0, duration: 0.12, yoyo: true, repeat: 20, ease: "steps(1)" }, 0);
228
+
229
+ // Type each character
230
+ for (var i = 0; i < CMD.length; i++) {
231
+ (function (idx) {
232
+ tl.call(
233
+ function () {
234
+ typed.textContent = CMD.substring(0, idx + 1);
235
+ },
236
+ null,
237
+ (idx / CMD.length) * 0.9,
238
+ );
239
+ })(i);
240
+ }
241
+ </script>
242
+ ```
243
+
244
+ Use `ease: "steps(1)"` for cursor blink — creates discrete on/off.
245
+
246
+ ---
247
+
248
+ ## 8. Variable Font Axis Animation
249
+
250
+ Animate font-variation-settings to reshape glyphs in real-time. Works with variable fonts that have axes like optical size (opsz), weight (wght), softness (SOFT).
251
+
252
+ ```html
253
+ <style>
254
+ /* Load the captured local variable font — do NOT use Google Fonts @import.
255
+ Replace this placeholder with an @font-face pointing to ../capture/assets/fonts/. */
256
+ @font-face {
257
+ font-family: "Fraunces";
258
+ src: url("../capture/assets/fonts/Fraunces-Variable.woff2") format("woff2");
259
+ font-weight: 100 900;
260
+ font-style: normal;
261
+ font-display: block;
262
+ }
263
+ .wordmark {
264
+ --opsz: 144;
265
+ --wght: 440;
266
+ font-family: "Fraunces", serif;
267
+ font-variation-settings:
268
+ "opsz" var(--opsz),
269
+ "wght" var(--wght);
270
+ font-size: 200px;
271
+ }
272
+ </style>
273
+ <script>
274
+ tl.to(".wordmark", { "--opsz": 72, "--wght": 300, duration: 0.45, ease: "power2.out" }, 0);
275
+ </script>
276
+ ```
277
+
278
+ The glyph subtly reshapes as axes animate — optical size adjusts detail, weight changes thickness.
279
+
280
+ ---
281
+
282
+ ## 9. GSAP MotionPathPlugin
283
+
284
+ Animate an element along an arbitrary SVG path. Use for sliders following curves, particles along trajectories, guided reveals.
285
+
286
+ ```html
287
+ <script src="https://cdn.jsdelivr.net/npm/gsap@3.14.2/dist/MotionPathPlugin.min.js"></script>
288
+ <div class="dot" style="width:20px;height:20px;background:#2a8a7c;border-radius:50%;"></div>
289
+ <script>
290
+ gsap.registerPlugin(MotionPathPlugin);
291
+ tl.to(
292
+ ".dot",
293
+ {
294
+ motionPath: { path: "M 12 300 C 280 280 520 80 820 50 S 1200 48 1308 38" },
295
+ duration: 1.5,
296
+ ease: "power2.out",
297
+ },
298
+ 0,
299
+ );
300
+ </script>
301
+ ```
302
+
303
+ ---
304
+
305
+ ## 10. Velocity-Matched Transitions
306
+
307
+ Exit one beat and enter the next with matched velocities — creates perceived continuous motion.
308
+
309
+ ```javascript
310
+ // EXIT (in outgoing composition): accelerating with blur
311
+ tl.to(
312
+ ".content",
313
+ {
314
+ y: -150,
315
+ filter: "blur(30px)",
316
+ opacity: 0,
317
+ duration: 0.33,
318
+ ease: "power2.in", // accelerates
319
+ },
320
+ beatDuration - 0.33,
321
+ );
322
+
323
+ // ENTRY (in incoming composition): decelerating from blur
324
+ gsap.set(".content", { y: 150, filter: "blur(30px)" });
325
+ tl.to(
326
+ ".content",
327
+ {
328
+ y: 0,
329
+ filter: "blur(0px)",
330
+ duration: 1.0,
331
+ ease: "power2.out", // decelerates
332
+ },
333
+ 0,
334
+ );
335
+ ```
336
+
337
+ The fastest point of both curves meets at the cut — the viewer perceives smooth camera motion. Match ease families: `.in` for exits, `.out` for entries.
338
+
339
+ ---
340
+
341
+ ## 11. Audio-Reactive Animation
342
+
343
+ Drive any GSAP-tweenable property from the playing audio. Bass pulses a logo on kick drums. Treble glows a CTA on cymbals. Amplitude breathes a background during quiet phrases. The result: motion that feels locked to the track in a way pre-authored tweens never can.
344
+
345
+ **When to use:** Any video with music or dramatic narration — brand reels, product launches, hype edits. Skip for calm/tutorial pacing.
346
+
347
+ **How it works:** Pre-extract audio frequency bands into a JSON file, then sample per-frame via `tl.call()`:
348
+
349
+ ```js
350
+ // audio-data.json: { fps: 30, totalFrames: 900, frames: [{ bands: [0.82, 0.45, 0.31, ...] }, ...] }
351
+ for (var f = 0; f < AUDIO_DATA.totalFrames; f++) {
352
+ tl.call(
353
+ (function (frame) {
354
+ return function () {
355
+ var bass = frame.bands[0]; // 0–1
356
+ var treble = frame.bands[13];
357
+ gsap.set(".logo", { scale: 1 + bass * 0.04 }); // 3–4% pulse on bass
358
+ gsap.set(".cta", { filter: `drop-shadow(0 0 ${treble * 24}px #00C3FF)` });
359
+ };
360
+ })(AUDIO_DATA.frames[f]),
361
+ [],
362
+ f / AUDIO_DATA.fps,
363
+ );
364
+ }
365
+ ```
366
+
367
+ Per-frame sampling is required — a single tween will not react. Use the extract script:
368
+
369
+ ```bash
370
+ python3 skills/gsap/scripts/extract-audio-data.py narration.wav --fps 30 --bands 16 -o audio-data.json
371
+ ```
372
+
373
+ Keep text/logo intensity subtle (≤5% scale, ≤30% glow) — audio-reactive motion on tiny elements reads as jitter. Bigger backgrounds can push to 10–30%.
374
+
375
+ **Never do:** equalizer bars, spectrum analyzers, waveform displays, strobing, rainbow color cycling. The audio provides _timing and intensity_; the visual vocabulary still comes from the brand. See `skills/hyperframes/references/audio-reactive.md` for the full API and anti-patterns.
376
+
377
+ ---
378
+
379
+ ## When to Use What
380
+
381
+ | Video energy | Techniques to combine |
382
+ | ------------------------------ | --------------------------------------------------------------- |
383
+ | High impact (launches, promos) | Per-word typography + velocity transitions + counter animations |
384
+ | Cinematic (tours, stories) | SVG path drawing + video compositing + 3D transforms |
385
+ | Technical (dev tools, APIs) | Character typing + Canvas 2D procedural + MotionPath |
386
+ | Premium (luxury, enterprise) | Variable font animation + Lottie + slow velocity transitions |
387
+ | Data-driven (stats, metrics) | Canvas 2D procedural + counter animations + SVG path drawing |
@@ -1,24 +1,6 @@
1
1
  # Transcript Guide
2
2
 
3
- ## How Transcripts Are Generated
4
-
5
- `hyperframes transcribe` handles both transcription and format conversion:
6
-
7
- ```bash
8
- # Transcribe audio/video (uses whisper.cpp locally, no API key needed)
9
- npx hyperframes transcribe audio.mp3
10
-
11
- # Use a larger model for better accuracy
12
- npx hyperframes transcribe audio.mp3 --model medium.en
13
-
14
- # Filter to English only (skips non-English speech)
15
- npx hyperframes transcribe audio.mp3 --language en
16
-
17
- # Import an existing transcript from another tool
18
- npx hyperframes transcribe captions.srt
19
- npx hyperframes transcribe captions.vtt
20
- npx hyperframes transcribe openai-response.json
21
- ```
3
+ For the `transcribe` CLI invocation, the `.en`-translates-non-English rule, and whisper model selection, see the `hyperframes-media` skill. This file covers what to do with the resulting transcript when authoring captions: input formats, mandatory quality checks, cleaning code, external-API fallbacks.
22
4
 
23
5
  ## Supported Input Formats
24
6
 
@@ -34,32 +16,6 @@ The CLI auto-detects and normalizes these formats:
34
16
 
35
17
  **Word-level timestamps produce better captions.** SRT/VTT give phrase-level timing, which works but can't do per-word animation effects.
36
18
 
37
- ## Whisper Model Guide
38
-
39
- The default model (`small.en`) balances accuracy and speed. For better results, use a larger model:
40
-
41
- | Model | Size | Speed | Accuracy | When to use |
42
- | ---------- | ------ | -------- | --------- | ------------------------------------- |
43
- | `tiny` | 75 MB | Fastest | Low | Quick previews, testing pipeline |
44
- | `base` | 142 MB | Fast | Fair | Short clips, clear audio |
45
- | `small` | 466 MB | Moderate | Good | **Default** — good for most content |
46
- | `medium` | 1.5 GB | Slow | Very good | Important content, noisy audio, music |
47
- | `large-v3` | 3.1 GB | Slowest | Best | Production quality |
48
-
49
- **Only add `.en` suffix when the user explicitly says the audio is English.** `.en` models are slightly more accurate for English but will TRANSLATE non-English audio instead of transcribing it.
50
-
51
- **Critical: `.en` models translate non-English audio into English** — they don't transcribe it. If the audio might not be English, always use a model without the `.en` suffix and pass `--language` to specify the source language. If you're unsure of the language, use `small` (not `small.en`) without `--language` — whisper will auto-detect.
52
-
53
- ```bash
54
- # Spanish audio
55
- npx hyperframes transcribe audio.mp3 --model small --language es
56
-
57
- # Unknown language — let whisper auto-detect
58
- npx hyperframes transcribe audio.mp3 --model small
59
- ```
60
-
61
- **Music and vocals over instrumentation**: `small.en` will misidentify lyrics — use `medium.en` as the minimum, or import lyrics manually. Even `medium.en` struggles with heavily produced tracks; for music videos, providing known lyrics as an SRT/VTT and importing with `hyperframes transcribe lyrics.srt` will always beat automated transcription.
62
-
63
19
  ## Transcript Quality Check (Mandatory)
64
20
 
65
21
  After every transcription, **read the transcript and check for quality issues before proceeding.** Bad transcripts produce nonsensical captions. Never skip this step.
@@ -0,0 +1,62 @@
1
+ # Video Composition
2
+
3
+ Video frames are not web pages. These rules apply to every composition regardless of brand, style, or design.md.
4
+
5
+ ## design.md Is Brand, Not Layout
6
+
7
+ design.md defines what the brand looks like: colors, fonts, personality, constraints. It does NOT define how to compose a video frame. Use brand colors at video-appropriate intensity — not at web-UI opacity.
8
+
9
+ **Strict from design.md:** hex values (including background color), font families, weight relationships, Do's and Don'ts. If the user chose a light canvas, use a light canvas. If they chose dark, use dark. Do not override their palette.
10
+
11
+ **Adapt for video:** type sizes, spacing, decorative opacity, border weight, component treatments. A web UI card at `border: 1px solid #e2e3e6` with `box-shadow: 0 2px 4px rgba(0,0,0,0.06)` is invisible on video. The brand color is sacred; the application is yours.
12
+
13
+ ## Density
14
+
15
+ A beat with 3 elements looks empty. A beat with 8-10 feels alive.
16
+
17
+ Every scene needs:
18
+
19
+ - **Background texture** — radial glow, oversized ghost type, color panel, grain, grid. Never solid flat color.
20
+ - **Midground content** — the actual message. Cards, stats, code blocks, images.
21
+ - **Foreground accents** — dividers, labels, data bars, registration marks, monospace metadata. The details that make it feel produced, not generated.
22
+
23
+ Aim for 8-10 visual elements per scene. Two of those should be decorative elements the user didn't ask for — you add them because empty frames look broken.
24
+
25
+ ## Color Presence
26
+
27
+ Muted is fine. Flat is not. Every scene should have at least one color that pulls the eye.
28
+
29
+ - Brand accent should be VISIBLE — not a 5% opacity glow lost in compression. 15-25% for atmospheric, full saturation for focal elements.
30
+ - **Light canvases work differently than dark.** On dark: accent glows pop naturally. On light: use bolder borders (2px+ solid), stronger structural elements (rules, dividers), and full-saturation accent hits. Light backgrounds need texture (subtle grain, patterns) to avoid the "blank slide" feel. Don't switch to dark — make light cinematic.
31
+ - Tint neutrals toward the brand hue. Dead gray reads as undesigned.
32
+
33
+ ## Scale
34
+
35
+ Web sizes are invisible on video. Everything scales up.
36
+
37
+ | Element | Web | Video |
38
+ | ------------------ | ------- | -------- |
39
+ | Headlines | 32-48px | 64-120px |
40
+ | Body text | 14-16px | 28-42px |
41
+ | Labels | 12px | 18-24px |
42
+ | Decorative opacity | 3-8% | 12-25% |
43
+ | Borders | 1px | 2-4px |
44
+ | Padding | 16-32px | 60-140px |
45
+
46
+ If you're writing a font-size under 24px in a video composition, justify it. If you're writing decorative opacity under 10%, it's invisible.
47
+
48
+ ## Motion Intensity
49
+
50
+ Subtle reads as static at 30fps. Err toward more movement than feels safe.
51
+
52
+ - Every decorative element should have ambient motion: breathe, drift, pulse, orbit. Static decoratives feel dead.
53
+ - Vary motion per scene — don't repeat the same ambient pattern.
54
+ - Scene entrances should use 3+ different eases and directions. If every element enters from `y: 30, opacity: 0`, the scene has no choreography.
55
+
56
+ ## Frame Composition
57
+
58
+ - **Two focal points minimum.** The eye needs somewhere to travel.
59
+ - **Fill the frame.** Hero text: 60-80% of frame width.
60
+ - **Anchor to edges.** Pin content to left/top or right/bottom. Centered-and-floating is a web layout pattern.
61
+ - **Split frames.** Data panel left, content right. Top bar with metadata, full-width below. Zone-based layouts over centered stacks.
62
+ - **Structural elements.** Rules, dividers, border panels. They create visual paths and animate well (`scaleX: 0` → `1`).
@@ -156,7 +156,9 @@ async function annotateFrame(pngBuf, elements) {
156
156
 
157
157
  const measured = [];
158
158
  for (const el of elements) {
159
+ if (isBBoxOutsideFrame(el.bbox, width, height)) continue;
159
160
  const bg = sampleRingMedian(raw, width, height, channels, el.bbox);
161
+ if (!bg) continue;
160
162
  const fg = compositeOver(el.fg, bg); // flatten any alpha against measured bg
161
163
  const ratio = wcagRatio(fg, bg);
162
164
  const large = isLargeText(el.fontSize, el.fontWeight);
@@ -167,6 +169,8 @@ async function annotateFrame(pngBuf, elements) {
167
169
  el.wcagAAA = large ? ratio >= 4.5 : ratio >= 7;
168
170
  measured.push(el);
169
171
  }
172
+ elements.length = 0;
173
+ elements.push(...measured);
170
174
 
171
175
  // Draw boxes + ratio labels as an SVG overlay (sharp composite).
172
176
  const svg = buildOverlaySVG(measured, width, height);
@@ -186,6 +190,7 @@ function sampleRingMedian(raw, width, height, channels, bbox) {
186
190
  const y0 = Math.max(0, Math.floor(bbox.y) - 4);
187
191
  const y1 = Math.min(height - 1, Math.ceil(bbox.y + bbox.h) + 4);
188
192
  const pushPixel = (x, y) => {
193
+ if (x < 0 || x >= width || y < 0 || y >= height) return;
189
194
  const i = (y * width + x) * channels;
190
195
  r.push(raw[i]);
191
196
  g.push(raw[i + 1]);
@@ -199,9 +204,14 @@ function sampleRingMedian(raw, width, height, channels, bbox) {
199
204
  pushPixel(x0, y);
200
205
  pushPixel(x1, y);
201
206
  }
207
+ if (r.length === 0) return null;
202
208
  return [median(r), median(g), median(b), 1];
203
209
  }
204
210
 
211
+ function isBBoxOutsideFrame(bbox, width, height) {
212
+ return bbox.x + bbox.w <= 0 || bbox.y + bbox.h <= 0 || bbox.x >= width || bbox.y >= height;
213
+ }
214
+
205
215
  function median(arr) {
206
216
  const s = [...arr].sort((a, b) => a - b);
207
217
  return s[Math.floor(s.length / 2)];