mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-09-07 01:56:04 +00:00
* chore(skills): remove 1,685 lines of redundant and irrelevant skill content - Remove 5 GSAP references irrelevant to HyperFrames (scrolltrigger, plugins, react, frameworks, utils) — no scroll, no frameworks, no interactive plugins in video compositions - Remove shader-setup.md and shader-transitions.md — duplicated by @hyperframes/shader-transitions package (packages/shader-transitions/) - Remove marker-highlight.md and examples.md — JS library docs superseded by css-patterns.md (deterministic, GSAP-driven, fully seekable) - Trim CLAUDE.md to dev-only instructions — move product docs (transcription, TTS, player) to skills where they belong - Deduplicate house-style.md typography/motion sections — point to dedicated references instead of repeating rules - Clean up stale references to deleted files across SKILL.md and catalog.md - Update gsap skill description to reflect HyperFrames-only scope Skills: 5,230 → 3,714 lines (29% reduction) CLAUDE.md: 204 → 50 lines (75% reduction) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix(skills): update broken marker-highlight.md references in captions.md Point to css-patterns.md instead of deleted marker-highlight.md. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix(skills): update stale shader CSS rule to reference package API BG_COLOR was from the old manual setup. Now it's bgColor in the @hyperframes/shader-transitions init() config. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix(skills): address 6 doc gaps surfaced by eval agents P0: Document HyperShader as IIFE global name in shader-transitions README P1: Replace async fetch() with sync XHR in effects.md audio data loading (fetch violates synchronous timeline construction rule in SKILL.md) P1: Change <div> to <span> in css-patterns.md marker highlight patterns (<div> inside <p> is invalid HTML, breaks layout in inline contexts) P2: Clarify bgColor as fallback color in shader-transitions README P2: Add data-start to Composition Clips table in SKILL.md (root composition element needs data-start="0", linter enforces it) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix(templates): update init templates to match trimmed skill scope - Remove ScrollTrigger/plugins/React/Vue/Svelte from gsap skill description - Replace class="clip" with accurate pattern examples in skill intro text (class="clip" is still in Key Rules where it belongs) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix(skills): remove contradictory 5:1 contrast threshold from house-style house-style.md said 5:1 minimum, but hyperframes validate enforces WCAG AA (4.5:1 normal text, 3:1 large text). Now defers to validate instead of stating a conflicting number. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
298 lines
8.6 KiB
Markdown
298 lines
8.6 KiB
Markdown
# GSAP Effects for HyperFrames
|
|
|
|
Drop-in animation patterns for HyperFrames compositions. Each effect is self-contained with HTML, CSS, and code.
|
|
|
|
All effects follow HyperFrames composition rules — deterministic, no randomness, timelines registered via `window.__timelines`.
|
|
|
|
## Table of Contents
|
|
|
|
- [Typewriter](#typewriter)
|
|
- [Audio Visualizer](#audio-visualizer)
|
|
|
|
---
|
|
|
|
## Typewriter
|
|
|
|
Reveal text character by character using GSAP's TextPlugin.
|
|
|
|
### Required Plugin
|
|
|
|
```html
|
|
<script src="https://cdn.jsdelivr.net/npm/gsap@3.14.2/dist/gsap.min.js"></script>
|
|
<script src="https://cdn.jsdelivr.net/npm/gsap@3.14.2/dist/TextPlugin.min.js"></script>
|
|
<script>
|
|
gsap.registerPlugin(TextPlugin);
|
|
</script>
|
|
```
|
|
|
|
### Basic Typewriter
|
|
|
|
```js
|
|
const text = "Hello, world!";
|
|
const cps = 10; // chars per second: 3-5 dramatic, 8-12 conversational, 15-20 energetic
|
|
tl.to(
|
|
"#typed-text",
|
|
{ text: { value: text }, duration: text.length / cps, ease: "none" },
|
|
startTime,
|
|
);
|
|
```
|
|
|
|
### With Blinking Cursor
|
|
|
|
Three rules:
|
|
|
|
1. **One cursor visible at a time** — hide previous before showing next.
|
|
2. **Cursor must blink when idle** — after typing, during pauses.
|
|
3. **No gap between text and cursor** — elements must be flush in HTML.
|
|
|
|
```html
|
|
<span id="typed-text"></span><span id="cursor" class="cursor-blink">|</span>
|
|
```
|
|
|
|
```css
|
|
@keyframes blink {
|
|
0%,
|
|
100% {
|
|
opacity: 1;
|
|
}
|
|
50% {
|
|
opacity: 0;
|
|
}
|
|
}
|
|
.cursor-blink {
|
|
animation: blink 0.8s step-end infinite;
|
|
}
|
|
.cursor-solid {
|
|
animation: none;
|
|
opacity: 1;
|
|
}
|
|
.cursor-hide {
|
|
animation: none;
|
|
opacity: 0;
|
|
}
|
|
```
|
|
|
|
Pattern: blink → solid (typing starts) → type → solid → blink (typing done).
|
|
|
|
```js
|
|
tl.call(() => cursor.classList.replace("cursor-blink", "cursor-solid"), [], startTime);
|
|
tl.to("#typed-text", { text: { value: text }, duration: dur, ease: "none" }, startTime);
|
|
tl.call(() => cursor.classList.replace("cursor-solid", "cursor-blink"), [], startTime + dur);
|
|
```
|
|
|
|
### Backspacing
|
|
|
|
TextPlugin removes from front — wrong for backspace. Use manual substring removal:
|
|
|
|
```js
|
|
function backspace(tl, selector, word, startTime, cps) {
|
|
const el = document.querySelector(selector);
|
|
const interval = 1 / cps;
|
|
for (let i = word.length - 1; i >= 0; i--) {
|
|
tl.call(
|
|
() => {
|
|
el.textContent = word.slice(0, i);
|
|
},
|
|
[],
|
|
startTime + (word.length - i) * interval,
|
|
);
|
|
}
|
|
return word.length * interval;
|
|
}
|
|
```
|
|
|
|
### Spacing with Static Text
|
|
|
|
When a typewriter word sits next to static text, use `margin-left` on a wrapper span. Don't use flex gap (spaces cursor from text) or trailing space in static text (collapses when dynamic is empty).
|
|
|
|
```html
|
|
<div style="display:flex; align-items:baseline;">
|
|
<span style="font-size:40px; color:#555;">Ship something</span>
|
|
<span style="margin-left:14px;"><span id="word"></span><span id="cursor">|</span></span>
|
|
</div>
|
|
```
|
|
|
|
### Word Rotation
|
|
|
|
Type → hold → backspace → next word. Cursor blinks during every idle moment (holds, after backspace).
|
|
|
|
```js
|
|
words.forEach((word, i) => {
|
|
const typeDur = word.length / 10;
|
|
// Solid while typing
|
|
tl.call(() => cursor.classList.replace("cursor-blink", "cursor-solid"), [], offset);
|
|
tl.to("#typed-text", { text: { value: word }, duration: typeDur, ease: "none" }, offset);
|
|
// Blink during hold
|
|
tl.call(() => cursor.classList.replace("cursor-solid", "cursor-blink"), [], offset + typeDur);
|
|
offset += typeDur + 1.5; // hold
|
|
|
|
if (i < words.length - 1) {
|
|
tl.call(() => cursor.classList.replace("cursor-blink", "cursor-solid"), [], offset);
|
|
const clearDur = backspace(tl, el, word, offset, 20);
|
|
tl.call(() => cursor.classList.replace("cursor-solid", "cursor-blink"), [], offset + clearDur);
|
|
offset += clearDur + 0.3;
|
|
}
|
|
});
|
|
```
|
|
|
|
### Appending Words
|
|
|
|
Build a sentence word-by-word into the same element:
|
|
|
|
```js
|
|
let accumulated = "";
|
|
words.forEach((word) => {
|
|
const target = accumulated + (accumulated ? " " : "") + word;
|
|
const newChars = target.length - accumulated.length;
|
|
tl.to("#typed-text", { text: { value: target }, duration: newChars / 10, ease: "none" }, offset);
|
|
accumulated = target;
|
|
offset += newChars / 10 + 0.3;
|
|
});
|
|
```
|
|
|
|
### Multi-Line Cursor Handoff
|
|
|
|
When handing off between typewriter lines: hide previous → blink new → pause → solid when typing. Never go hidden→solid (skips idle state).
|
|
|
|
```js
|
|
tl.call(
|
|
() => {
|
|
prevCursor.classList.replace("cursor-blink", "cursor-hide");
|
|
nextCursor.classList.replace("cursor-hide", "cursor-blink");
|
|
},
|
|
[],
|
|
handoffTime,
|
|
);
|
|
|
|
const typeStart = handoffTime + 0.5; // brief blink pause
|
|
tl.call(() => nextCursor.classList.replace("cursor-blink", "cursor-solid"), [], typeStart);
|
|
tl.to("#next-text", { text: { value: text }, duration: dur, ease: "none" }, typeStart);
|
|
tl.call(() => nextCursor.classList.replace("cursor-solid", "cursor-blink"), [], typeStart + dur);
|
|
```
|
|
|
|
### Timing Guide
|
|
|
|
| CPS | Feel | Good for |
|
|
| ----- | ---------------- | -------------------------- |
|
|
| 3-5 | Slow, deliberate | Dramatic reveals, suspense |
|
|
| 8-12 | Natural typing | Dialogue, narration |
|
|
| 15-20 | Fast, energetic | Tech demos, code |
|
|
| 30+ | Near-instant | Filling long blocks |
|
|
|
|
---
|
|
|
|
## Audio Visualizer
|
|
|
|
Pre-extract audio data, drive canvas/DOM rendering from GSAP timeline.
|
|
|
|
### Extract Audio Data
|
|
|
|
```bash
|
|
python scripts/extract-audio-data.py audio.mp3 -o audio-data.json
|
|
python scripts/extract-audio-data.py video.mp4 --fps 30 --bands 16 -o audio-data.json
|
|
```
|
|
|
|
Requires ffmpeg and numpy.
|
|
|
|
### Data Format
|
|
|
|
```json
|
|
{
|
|
"fps": 30, "totalFrames": 5415,
|
|
"frames": [{ "time": 0.0, "rms": 0.42, "bands": [0.8, 0.6, 0.3, ...] }]
|
|
}
|
|
```
|
|
|
|
- **rms** (0-1): overall loudness, normalized across track
|
|
- **bands[]** (0-1): frequency magnitudes. Index 0 = bass, higher = treble. Each normalized independently.
|
|
|
|
### Loading the Data
|
|
|
|
```js
|
|
// Option A: inline (small files, under ~500KB)
|
|
var AUDIO_DATA = {
|
|
/* paste audio-data.json contents */
|
|
};
|
|
|
|
// Option B: sync XHR (large files — must be synchronous for deterministic timeline construction)
|
|
var xhr = new XMLHttpRequest();
|
|
xhr.open("GET", "audio-data.json", false);
|
|
xhr.send();
|
|
var AUDIO_DATA = JSON.parse(xhr.responseText);
|
|
```
|
|
|
|
**Do NOT use async `fetch()` to load audio data.** HyperFrames requires synchronous timeline construction — the capture engine reads `window.__timelines` synchronously after page load. Building timelines inside `.then()` callbacks means the timeline isn't ready when capture starts.
|
|
|
|
### Rendering Approaches
|
|
|
|
**Canvas 2D** (most common — bars, waveforms, circles, gradients):
|
|
|
|
```js
|
|
for (let f = 0; f < AUDIO_DATA.totalFrames; f++) {
|
|
tl.call(
|
|
() => {
|
|
const frame = AUDIO_DATA.frames[f];
|
|
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
// draw using frame.rms and frame.bands
|
|
},
|
|
[],
|
|
f / AUDIO_DATA.fps,
|
|
);
|
|
}
|
|
```
|
|
|
|
**WebGL / Three.js** — HyperFrames patches `THREE.Clock` for deterministic time. Update uniforms from audio data each frame.
|
|
|
|
**DOM Elements** — fine for < 20 elements, less performant than Canvas for many.
|
|
|
|
### Spatial Mapping
|
|
|
|
- **Horizontal**: bass left, treble right (iterate bands left-to-right)
|
|
- **Vertical**: bass bottom, treble top
|
|
- **Circular**: bass at 12 o'clock, wrap clockwise; mirror for full circle
|
|
|
|
### Smoothing
|
|
|
|
```js
|
|
let prev = null;
|
|
const smoothing = 0.25; // 0.1-0.2 snappy, 0.3-0.5 flowing
|
|
function smooth(f) {
|
|
const raw = AUDIO_DATA.frames[f];
|
|
if (!prev) {
|
|
prev = { rms: raw.rms, bands: [...raw.bands] };
|
|
return prev;
|
|
}
|
|
prev = {
|
|
rms: prev.rms * smoothing + raw.rms * (1 - smoothing),
|
|
bands: raw.bands.map((b, i) => prev.bands[i] * smoothing + b * (1 - smoothing)),
|
|
};
|
|
return prev;
|
|
}
|
|
```
|
|
|
|
### Motion Principles
|
|
|
|
- **Bass drives big moves** — scale, glow, position shifts
|
|
- **Treble drives detail** — shimmer, flicker, edge effects
|
|
- **RMS drives globals** — background brightness, overall energy
|
|
- Pick 2-3 properties to animate. More looks noisy.
|
|
- Keep minimums above zero — quiet sections need life.
|
|
|
|
### Band Count
|
|
|
|
| Bands | Detail | Good for |
|
|
| ----- | --------- | -------------------------- |
|
|
| 4 | Low | Background glow, pulsing |
|
|
| 8 | Medium | Bar charts, basic spectrum |
|
|
| 16 | High | Detailed EQ (default) |
|
|
| 32 | Very high | Dense radial layouts |
|
|
|
|
### Layering
|
|
|
|
Layer multiple canvases with CSS z-index for depth — a background layer driven by bass/rms and a foreground layer driven by individual bands creates depth without complexity.
|
|
|
|
```html
|
|
<canvas id="bg-layer" style="position:absolute;top:0;left:0;z-index:1;"></canvas>
|
|
<canvas id="main-layer" style="position:absolute;top:0;left:0;z-index:2;"></canvas>
|
|
```
|