Files
hyperframes/docs/catalog/components/caption-camera-follow.mdx
Miguel ÁngelandMiguel Angel Simon Sierra 1ae2067b8d feat(catalog): put the variables panel back, on payloads (#3199)
* feat(catalog): put the variables panel back, on payloads

The panel drove its preview by loading an .html from docs/public, a type the
host does not publish, so it showed an empty frame in production and was
parked when the catalog was re-landed.

It now mounts the same JSON payload the plain player uses and re-mounts it as
values change, injecting them as window.__hfVariables into the composition head
before any of its scripts run, which is where the runtime reads overrides from.
Doing it in the markup rather than after load is what stops the composition
initialising with the wrong values first.

172 items with variables get the panel back; the playhead carries across a
change so a tweak mid-shot does not jump back to frame zero.

* fix(docs): drop the unused url form and the needless escapes

* fix(docs): the panel cannot reference a binding beside the export

* feat(catalog): make importing an SVG the obvious move

A reader arrives at this control with a shape, not with path data, and the
panel asked for the coordinates first. Import is now the primary action in a
drop target you can see is a drop target, and the raw path sits behind a
disclosure for anyone who wants it.

* feat(cli): let a fruitless catalog search report the gap

An agent that searches by meaning and finds nothing worth installing knows
something we do not: the name of a move the catalog is missing. There was no
way to tell us, so that knowledge was lost at the end of every run.

hyperframes feedback --search-miss "<query>" --wanted "<the move>" records it.
It carries no rating, so it never lands in the rating metric, and it is a
separate deliberate command rather than something catalog --query does on its
own: plain search still sends nothing, which is what the CLI promises.

--rating stops being required at the arg level, since a miss has no rating to
give. The check moved into the run body, where an absent one is now handled
rather than crashing on undefined.

* feat(cli): carry tuned variable values into the install snippet

Someone who tunes a block on its catalog page had no way to keep those values:
the install command was the same one everybody gets, and the tuning stayed on
the page.

hyperframes add <item> --vars '<json>' now prints a mount element carrying
data-variable-values, so the values land where the block is used.

They ride on the host rather than being written into the installed file. That
keeps the composition on disk byte-identical to the registry's, so a later
reinstall can still tell an edit from an update, and it lets two mounts of the
same block carry different values.

* fix(catalog): serve the item's own directory so runtime paths resolve

Some compositions assemble their asset URLs at run time —
"compositions/components/" + texture + ".png" for the texture masks, a font the
compiler pulled into _remote_media — and no scan of the markup can see a string
that does not exist until a script concatenates it. Those items either rendered
black or were dropped to a video that had never been uploaded.

Each item that needs it now has its prepared directory published, and its
payload carries a <base> pointing at it, so any relative path the composition
invents resolves. caption-texture renders its masks again, and
variable-font-flex has a preview at all for the first time: its MP4 and poster
are both 403.

Both layouts are published, because which one a composition asks for differs
per item, and a directory only earns that if it is under 2 MB. The 12 MB
texture sheet keeps the recorded video it already had.

* fix(catalog): let the variables panel actually drive the composition

Every control on the panel was inert. The values reached the composition and
nothing repainted, because the payload had already been compiled: compiling
inlines a mounted component and resolves its variables into the markup and CSS,
so by the time a reader turns a knob there is nothing left to change.

An item that declares variables now ships uncompiled, keeping the mount the
runtime loads at run time, which is the only state where data-variable-values
still means anything. The component travels inline as a data URI rather than a
sibling file, because .html is the one type the docs host will not publish. The
demo's own pinned values come off, so the reader's choices reach the mount
instead of losing to the values the demo picked to show itself off.

Measured on the rendered frame rather than the DOM: green rgb(98,207,144),
blue rgb(6,6,199), violet rgb(177,147,230), and back to green.

docs/public/catalog drops from 48 MB to 35 MB along the way, since an
uncompiled payload carries far less than an inlined one.

* feat(catalog): keep variable changes in the url

A reader who tuned a piece lost it on reload, and had nothing to send anyone.
The values now live in the query string, scoped by composition id so two links
never read each other,and only the ones that differ from the defaults are
written, so changing one knob gives a short URL rather than every variable
spelled out.

replaceState rather than pushState: dragging a slider should not leave a trail
of history entries. An unreadable value is ignored rather than thrown, so a
truncated or hand-edited link opens the piece at its defaults.

* fix(catalog): only rewrite the url when a value actually changed

* refactor(catalog): memoise the declared defaults on their content

* feat(catalog): offer an install command carrying the tuned values

The Install block is generated before anyone touches a knob, so it can only
ever print the plain command. Someone who spent a minute tuning a piece copied
it and got the defaults back.

The panel now carries its own command in the Snippet tab, with --vars holding
exactly the values that differ. An untouched piece still offers the same short
command, so nothing gets noisier for the common case.

* fix(catalog): a piece with nothing to render is a skip, not a failure

caption-blend-difference is a stylesheet and a paragraph of prose — a class you
add to your own captions, with no standalone scene to show. The generator
treated that as a build failure, so every run ended by reporting something
broken when nothing was.

It now reports the shape it is and keeps its recorded video, which is the only
honest preview such an item has. A genuine render failure still throws.

* fix(catalog): restore variables from the url on a cold load

A shared link opened at the defaults. The first render happens on the server,
where there is no window to read the query string from, and React then hydrates
against that markup and never revisits it — so the values only appeared once you
touched a control.

The URL is read again after mount, which is the first moment it exists. The
value is also escaped once now rather than twice: URLSearchParams already
decodes on the way out, and decoding a second time turned an SVG path full of
percent-escapes into something that no longer parsed, besides doubling the
length of every link.

* fix(catalog): mount the preview with the values a link carried

The frame was built from the declared defaults and the shared values were
posted to it afterwards, which is too late for anything the composition reads
once at init: a path arrived after the mark had already been drawn from the
default one, so a link looked right in the panel and wrong on screen.

* feat(catalog): the install command follows the values you tuned

Copying the Install line gave the plain command back, because that block is
generated before anyone touches a knob and had no way to know what changed. The
tuned command only existed in the panel Snippet tab, which is not where anyone
looks for it.

The line now reads the same query string the panel writes, so the two agree
without either component knowing the other exists, and a shared link carries the
right command too. replaceState fires no event, so the panel announces its own
writes.

* fix(catalog): send a text variable to the preview once it is finished

Every other control in the explorer reports a whole value on every event: a
slider at any position is a position, a swatch is a colour. A text field is
not. Typing v3 into a badge posted v first, so the preview remounted and
rendered a composition built from half a word.

The post now waits while a text field has focus and goes out when the edit is
committed, with Enter or by clicking away. The field itself is unchanged and
still tracks every keystroke.

---------

Co-authored-by: Miguel Angel Simon Sierra <miguelangelsi07@gmail.com>
2026-08-10 22:40:01 -04:00

936 lines
38 KiB
Plaintext

---
title: "Camera Follow Captions"
description: "One sentence written across a world far larger than the frame. Each word is sized against everything already written, so the block grows geometrically and the camera pulls back at a steady rate to keep landing the new word at the same size. Old words stay lit and simply become small."
---
import { InstallCommand } from "/snippets/install-command.jsx";
import { VariablesExplorer } from "/snippets/variables-explorer.jsx";
<VariablesExplorer
previewSrc="/public/catalog/components/caption-camera-follow.json"
compositionId="caption-camera-follow"
compositionSrc="compositions/components/caption-camera-follow.html"
variables={[{"id":"accent","type":"enum","role":"style","label":"Accent","description":"Colour of the highlighted words. gold is the original.","default":"gold","options":[{"value":"gold","label":"Gold"},{"value":"green","label":"Green"},{"value":"blue","label":"Blue"},{"value":"violet","label":"Violet"}]},{"id":"framing","type":"enum","role":"style","label":"Framing","description":"Air the camera leaves around the written block, so the words land larger or smaller in frame.","default":"standard","options":[{"value":"tight","label":"Tight"},{"value":"standard","label":"Standard"},{"value":"wide","label":"Wide"}]},{"id":"smear","type":"enum","role":"style","label":"Smear","description":"Scales the radial motion blur each camera move carries, from none to a heavy streak.","default":"standard","options":[{"value":"off","label":"Off"},{"value":"subtle","label":"Subtle"},{"value":"standard","label":"Standard"},{"value":"heavy","label":"Heavy"}]}]}
>
```html caption-camera-follow.html
<!doctype html>
<!--
caption-camera-follow: the words do not move, the camera does.
One sentence. Layout is self similar: every new word is sized as a fraction of the
bounding box of everything written so far, and is dropped either to the right of that
box or onto a new line below it, alternating. Because each word is measured against a
box that keeps growing, the box grows geometrically, so the camera pulls back at a
steady exponential rate and every word arrives at roughly the same size on screen. Old
words stay lit and simply become small, piling up toward the top left the way
handwriting fills a page. The last beat carries the same pull back all the way out
until the whole sentence is readable at once.
Variables. The script reads each one, falls back to the declared default on
anything missing or unrecognised, and applies it before the timeline is built.
Duration, word order and cadence are untouched by them.
- accent (gold | green | blue | violet, default gold): the colour of the
highlighted words.
- framing (tight | standard | wide, default standard): the air the camera
leaves around the written block. tight lands each word larger in frame,
wide sits further back. Every move and the closing pull back scale
together, so the shot stays one continuous camera.
- smear (off | subtle | standard | heavy, default standard): scales the
radial motion blur each move carries. off renders every frame sharp.
On every default the result is identical to the original: gold highlights, a
1.36 margin around the block and a peak smear of 2.6 percent of frame width.
Every ease is a cubic bezier written out by hand and solved in this file. No preset is
used anywhere. Motion blur is radial, the way it reads in real camera footage: each word
carries its own blur share, scaled by how far that word sits from the centre of the move,
so the frame smears outward from the point the camera is pushing toward. One shared
amount variable is tweened per move and every word multiplies it by its own distance
share, so the whole radial pulse costs one tween instead of fourteen.
Mount contract: everything lives inside <template>, styles and scripts included, and the
scripts sit INSIDE the composition root. A host clones template content into its own
mount and only runs scripts found inside the root; markup left outside is copied without
its behaviour, which renders a black card with no timeline at all.
-->
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Camera Follow Captions</title>
</head>
<body>
<template>
<div
id="root"
class="clip cf-root"
data-composition-id="caption-camera-follow"
data-duration="9"
data-fps="30"
data-composition-variables='[
{ "id": "accent", "type": "enum", "role": "style", "label": "Accent", "description": "Colour of the highlighted words. gold is the original.", "default": "gold", "options": [{ "value": "gold", "label": "Gold" }, { "value": "green", "label": "Green" }, { "value": "blue", "label": "Blue" }, { "value": "violet", "label": "Violet" }] },
{ "id": "framing", "type": "enum", "role": "style", "label": "Framing", "description": "Air the camera leaves around the written block, so the words land larger or smaller in frame.", "default": "standard", "options": [{ "value": "tight", "label": "Tight" }, { "value": "standard", "label": "Standard" }, { "value": "wide", "label": "Wide" }] },
{ "id": "smear", "type": "enum", "role": "style", "label": "Smear", "description": "Scales the radial motion blur each camera move carries, from none to a heavy streak.", "default": "standard", "options": [{ "value": "off", "label": "Off" }, { "value": "subtle", "label": "Subtle" }, { "value": "standard", "label": "Standard" }, { "value": "heavy", "label": "Heavy" }] }
]'
>
<style>
[data-composition-id="caption-camera-follow"] {
--cf-accent: #ffd84d;
--ink: #ffffff;
position: absolute;
inset: 0;
overflow: hidden;
background: transparent;
pointer-events: none;
}
#cf-stage {
position: absolute;
inset: 0;
overflow: hidden;
}
#cf-world {
position: absolute;
left: 0;
top: 0;
width: 0;
height: 0;
--amt: 0px;
}
.cf-word {
position: absolute;
white-space: nowrap;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-weight: 700;
text-transform: uppercase;
letter-spacing: 0.005em;
line-height: 0.78;
color: var(--ink);
opacity: 0;
--k: 0;
filter: blur(calc(var(--k) * var(--amt)));
}
.cf-word.is-accent {
color: var(--cf-accent);
}
#cf-vignette {
position: absolute;
inset: 0;
background: radial-gradient(
ellipse at 50% 50%,
rgba(0, 0, 0, 0) 42%,
rgba(0, 0, 0, 0.55) 100%
);
}
</style>
<div id="cf-stage">
<div id="cf-world"></div>
</div>
<div id="cf-vignette"></div>
<script src="https://cdn.jsdelivr.net/npm/gsap@3.14.2/dist/gsap.min.js"></script>
<script>
(function () {
gsap.defaults({ immediateRender: false });
/* Cubic bezier solver. Newton first, bisection as the fallback, so it is
exact and deterministic for every input. */
function bezier(x1, y1, x2, y2) {
function curve(t, a1, a2) {
var A = 1 - 3 * a2 + 3 * a1;
var B = 3 * a2 - 6 * a1;
var C = 3 * a1;
return ((A * t + B) * t + C) * t;
}
function slope(t, a1, a2) {
var A = 1 - 3 * a2 + 3 * a1;
var B = 3 * a2 - 6 * a1;
var C = 3 * a1;
return (3 * A * t + 2 * B) * t + C;
}
return function (p) {
if (p <= 0) return 0;
if (p >= 1) return 1;
var t = p;
for (var i = 0; i < 8; i++) {
var d = slope(t, x1, x2);
if (Math.abs(d) < 1e-6) break;
var e = curve(t, x1, x2) - p;
if (Math.abs(e) < 1e-7) return curve(t, y1, y2);
t -= e / d;
}
var lo = 0;
var hi = 1;
t = p;
for (var j = 0; j < 24; j++) {
var x = curve(t, x1, x2);
if (Math.abs(x - p) < 1e-7) break;
if (x > p) hi = t;
else lo = t;
t = (lo + hi) / 2;
}
return curve(t, y1, y2);
};
}
/* Leaves the mark fast, spends most of its time arriving. */
var EASE_STEP = bezier(0.31, 0, 0.11, 1);
/* The closing pull back: slower to leave, glides a long way out. */
var EASE_WIDE = bezier(0.42, 0, 0.14, 1);
/* Word ink coming up. */
var EASE_INK = bezier(0.2, 0.7, 0.3, 1);
/* Blur rising into the move and wiped off out of it. */
var EASE_BLUR_UP = bezier(0.2, 0.8, 0.4, 1);
var EASE_BLUR_DOWN = bezier(0.5, 0, 0.2, 1);
var vars =
window.__hyperframes && window.__hyperframes.getVariables
? window.__hyperframes.getVariables()
: {};
/* Unrecognised overrides return to their declared defaults. */
function pick(table, value, fallback) {
return Object.prototype.hasOwnProperty.call(table, value) ? value : fallback;
}
var ACCENTS = {
gold: "#ffd84d",
green: "#34d399",
blue: "#38bdf8",
violet: "#a78bfa",
};
/* Framing scales the margin every camera pose is fitted with, so one
number moves the whole shot in or out without touching cadence. */
var FRAMINGS = { tight: 0.82, standard: 1, wide: 1.25 };
var SMEARS = { off: 0, subtle: 0.5, standard: 1, heavy: 1.9 };
var ACCENT = ACCENTS[pick(ACCENTS, vars.accent, "gold")];
var FRAMING = FRAMINGS[pick(FRAMINGS, vars.framing, "standard")];
var SMEAR = SMEARS[pick(SMEARS, vars.smear, "standard")];
var DUR = 9;
var STEP = 0.52;
var MOVE = 0.4;
var WORDS = [
{ text: "write" },
{ text: "the" },
{ text: "html", accent: true },
{ text: "and" },
{ text: "the" },
{ text: "video", accent: true },
{ text: "renders" },
{ text: "itself" },
{ text: "no" },
{ text: "timeline" },
{ text: "no" },
{ text: "keyframes", accent: true },
{ text: "just" },
{ text: "code", accent: true },
];
var world = document.getElementById("cf-world");
var stage = document.getElementById("cf-stage");
/* The runtime strips the root id on clone, so reach the root through a
descendant instead of getElementById. */
var root = stage.parentElement;
var FRAME_W = root.clientWidth || 1080;
var FRAME_H = root.clientHeight || 1920;
root.style.setProperty("--cf-accent", ACCENT);
/* Base size is picked so the opening shot sits near 1:1. Everything after it
is a pull back, so the world is only ever scaled down and type stays crisp. */
var BASE = Math.max(FRAME_W, FRAME_H) * 0.16;
/* Each new word is this fraction of the current box height. */
var RATIO = 0.72;
var MARGIN = 1.36 * FRAMING;
var ruler = document.createElement("div");
ruler.style.cssText =
"position:absolute;left:-99999px;top:0;white-space:nowrap;visibility:hidden;" +
'font-family:"Helvetica Neue",Helvetica,Arial,sans-serif;font-weight:700;' +
"text-transform:uppercase;letter-spacing:0.005em;line-height:0.78";
world.appendChild(ruler);
var box = null;
WORDS.forEach(function (wd, i) {
var fs = i === 0 ? BASE : (box.y1 - box.y0) * RATIO;
ruler.style.fontSize = fs + "px";
ruler.textContent = wd.text;
var w = ruler.getBoundingClientRect().width;
var h = fs * 0.78;
var gap = fs * 0.07;
var x, y;
if (i === 0) {
x = 0;
y = 0;
} else if ((box.x1 - box.x0) / (box.y1 - box.y0) < FRAME_W / FRAME_H) {
/* block is narrower than the frame, so grow sideways: to the right of
everything, sitting on the same baseline */
x = box.x1 + gap;
y = box.y1 - h;
} else {
/* block is already wide enough, so grow downward: onto a new line under
everything, left edges aligned */
x = box.x0;
y = box.y1 + gap;
}
wd.fs = fs;
wd.x = x;
wd.y = y;
box = box
? {
x0: Math.min(box.x0, x),
y0: Math.min(box.y0, y),
x1: Math.max(box.x1, x + w),
y1: Math.max(box.y1, y + h),
}
: { x0: x, y0: y, x1: x + w, y1: y + h };
wd.box = { x0: box.x0, y0: box.y0, x1: box.x1, y1: box.y1 };
});
world.removeChild(ruler);
var FULL = box;
function poseFor(b, margin) {
var bw = (b.x1 - b.x0) * margin;
var bh = (b.y1 - b.y0) * margin;
var s = Math.min(FRAME_W / bw, FRAME_H / bh);
return {
x: FRAME_W / 2 - (s * (b.x0 + b.x1)) / 2,
y: FRAME_H / 2 - (s * (b.y0 + b.y1)) / 2,
scale: s,
};
}
var els = WORDS.map(function (wd) {
var el = document.createElement("div");
el.className = "cf-word" + (wd.accent ? " is-accent" : "");
el.textContent = wd.text;
el.style.left = wd.x + "px";
el.style.top = wd.y + "px";
el.style.fontSize = wd.fs + "px";
world.appendChild(el);
return el;
});
/* Re-derive every framing box from what the browser actually laid out, so
the camera is fitted to real ink and never to arithmetic that drifted. */
var run = null;
els.forEach(function (el, i) {
var r = {
x0: el.offsetLeft,
y0: el.offsetTop,
x1: el.offsetLeft + el.offsetWidth,
y1: el.offsetTop + el.offsetHeight,
};
run = run
? {
x0: Math.min(run.x0, r.x0),
y0: Math.min(run.y0, r.y0),
x1: Math.max(run.x1, r.x1),
y1: Math.max(run.y1, r.y1),
}
: r;
WORDS[i].box = { x0: run.x0, y0: run.y0, x1: run.x1, y1: run.y1 };
});
FULL = run;
/* Rest state is pinned outside the timeline. */
var first = poseFor(WORDS[0].box, MARGIN);
gsap.set(world, {
transformOrigin: "0 0",
x: first.x,
y: first.y,
scale: first.scale,
});
gsap.set(els, { opacity: 0, "--k": 0 });
gsap.set(world, { "--amt": "0px" });
/* The first word is already on the page when the shot opens, so frame zero
is never empty. */
gsap.set(els[0], { opacity: 1 });
var tl = gsap.timeline({ paused: true });
/* Peak smear at the rim of the frame, in screen pixels. */
var BLUR = FRAME_W * 0.026 * SMEAR;
var HALF_DIAG = Math.sqrt(FRAME_W * FRAME_W + FRAME_H * FRAME_H) / 2;
/* Radial blur, the way a real zoom smears: a point far from the centre of
the move sweeps across more of the frame than one sitting on it, so it
streaks more. Each word gets its own share, --k, of one shared amount,
--amt, which is the only thing that animates. The share is fixed for the
length of a move and set with the camera, so this stays one tween per
move rather than one per word per move. --amt is authored in world units,
because a filter on a scaled child is applied before the scale, so the
screen blur has to be divided back out by the camera scale. */
function smear(centre, scale, count, at, up, down, peak) {
for (var j = 0; j < count; j++) {
var el = els[j];
var cx = el.offsetLeft + el.offsetWidth / 2;
var cy = el.offsetTop + el.offsetHeight / 2;
var d =
(scale *
Math.sqrt(
(cx - centre.x) * (cx - centre.x) + (cy - centre.y) * (cy - centre.y),
)) /
HALF_DIAG;
tl.set(el, { "--k": (0.2 + 1.15 * Math.min(1, d)).toFixed(3) }, at);
}
var amt = peak / scale;
tl.fromTo(
world,
{ "--amt": "0px" },
{ "--amt": amt + "px", duration: up, ease: EASE_BLUR_UP },
at,
);
tl.to(world, { "--amt": "0px", duration: down, ease: EASE_BLUR_DOWN }, at + up);
}
WORDS.forEach(function (wd, i) {
var t = i * STEP;
if (i === 0) return;
tl.fromTo(els[i], { opacity: 0 }, { opacity: 1, duration: 0.16, ease: EASE_INK }, t);
var p = poseFor(wd.box, MARGIN);
tl.to(world, { x: p.x, y: p.y, scale: p.scale, duration: MOVE, ease: EASE_STEP }, t);
smear(
{ x: (wd.box.x0 + wd.box.x1) / 2, y: (wd.box.y0 + wd.box.y1) / 2 },
p.scale,
i + 1,
t,
MOVE * 0.24,
MOVE * 0.44,
BLUR,
);
});
/* The resolve: the same pull back, carried all the way out. */
var wide = poseFor(FULL, 1.2 * FRAMING);
var wideAt = (WORDS.length - 1) * STEP + 0.62;
tl.to(
world,
{
x: wide.x,
y: wide.y,
scale: wide.scale,
duration: 0.94,
ease: EASE_WIDE,
},
wideAt,
);
smear(
{ x: (FULL.x0 + FULL.x1) / 2, y: (FULL.y0 + FULL.y1) / 2 },
wide.scale,
els.length,
wideAt,
0.3,
0.58,
BLUR * 0.8,
);
tl.set({}, {}, DUR);
tl.seek(0);
window.__timelines = window.__timelines || {};
window.__timelines["caption-camera-follow"] = tl;
})();
</script>
</div>
</template>
</body>
</html>
```
</VariablesExplorer>
## Install
<InstallCommand command="npx hyperframes add caption-camera-follow" item="caption-camera-follow" />
That writes one file: `compositions/components/caption-camera-follow.html`.
## Paste it into your composition
Open `compositions/components/caption-camera-follow.html` and copy what is inside into your own composition.
A component has no size or duration of its own. It takes both from the composition
you paste it into.
## Variables
Every one of these has a default, so the piece works untouched. Set the ones you
want to change on the element:
| Variable | Default | Accepts | What it does |
| --- | --- | --- | --- |
| `accent` | `gold` | `gold`, `green`, `blue`, `violet` | Colour of the highlighted words. gold is the original. |
| `framing` | `standard` | `tight`, `standard`, `wide` | Air the camera leaves around the written block, so the words land larger or smaller in frame. |
| `smear` | `standard` | `off`, `subtle`, `standard`, `heavy` | Scales the radial motion blur each camera move carries, from none to a heavy streak. |
Set them with `data-variable-values` on the element that mounts it. These are the
defaults, so this behaves exactly like the preview above until you change one:
```html wrap
<div
data-composition-id="caption-camera-follow"
data-composition-src="compositions/components/caption-camera-follow.html"
data-variable-values='{"accent":"gold","framing":"standard","smear":"standard"}'
></div>
```
## Source
<Accordion title={`caption-camera-follow.html`}>
```html
<!doctype html>
<!--
caption-camera-follow: the words do not move, the camera does.
One sentence. Layout is self similar: every new word is sized as a fraction of the
bounding box of everything written so far, and is dropped either to the right of that
box or onto a new line below it, alternating. Because each word is measured against a
box that keeps growing, the box grows geometrically, so the camera pulls back at a
steady exponential rate and every word arrives at roughly the same size on screen. Old
words stay lit and simply become small, piling up toward the top left the way
handwriting fills a page. The last beat carries the same pull back all the way out
until the whole sentence is readable at once.
Variables. The script reads each one, falls back to the declared default on
anything missing or unrecognised, and applies it before the timeline is built.
Duration, word order and cadence are untouched by them.
- accent (gold | green | blue | violet, default gold): the colour of the
highlighted words.
- framing (tight | standard | wide, default standard): the air the camera
leaves around the written block. tight lands each word larger in frame,
wide sits further back. Every move and the closing pull back scale
together, so the shot stays one continuous camera.
- smear (off | subtle | standard | heavy, default standard): scales the
radial motion blur each move carries. off renders every frame sharp.
On every default the result is identical to the original: gold highlights, a
1.36 margin around the block and a peak smear of 2.6 percent of frame width.
Every ease is a cubic bezier written out by hand and solved in this file. No preset is
used anywhere. Motion blur is radial, the way it reads in real camera footage: each word
carries its own blur share, scaled by how far that word sits from the centre of the move,
so the frame smears outward from the point the camera is pushing toward. One shared
amount variable is tweened per move and every word multiplies it by its own distance
share, so the whole radial pulse costs one tween instead of fourteen.
Mount contract: everything lives inside <template>, styles and scripts included, and the
scripts sit INSIDE the composition root. A host clones template content into its own
mount and only runs scripts found inside the root; markup left outside is copied without
its behaviour, which renders a black card with no timeline at all.
-->
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Camera Follow Captions</title>
</head>
<body>
<template>
<div
id="root"
class="clip cf-root"
data-composition-id="caption-camera-follow"
data-duration="9"
data-fps="30"
data-composition-variables='[
{ "id": "accent", "type": "enum", "role": "style", "label": "Accent", "description": "Colour of the highlighted words. gold is the original.", "default": "gold", "options": [{ "value": "gold", "label": "Gold" }, { "value": "green", "label": "Green" }, { "value": "blue", "label": "Blue" }, { "value": "violet", "label": "Violet" }] },
{ "id": "framing", "type": "enum", "role": "style", "label": "Framing", "description": "Air the camera leaves around the written block, so the words land larger or smaller in frame.", "default": "standard", "options": [{ "value": "tight", "label": "Tight" }, { "value": "standard", "label": "Standard" }, { "value": "wide", "label": "Wide" }] },
{ "id": "smear", "type": "enum", "role": "style", "label": "Smear", "description": "Scales the radial motion blur each camera move carries, from none to a heavy streak.", "default": "standard", "options": [{ "value": "off", "label": "Off" }, { "value": "subtle", "label": "Subtle" }, { "value": "standard", "label": "Standard" }, { "value": "heavy", "label": "Heavy" }] }
]'
>
<style>
[data-composition-id="caption-camera-follow"] {
--cf-accent: #ffd84d;
--ink: #ffffff;
position: absolute;
inset: 0;
overflow: hidden;
background: transparent;
pointer-events: none;
}
#cf-stage {
position: absolute;
inset: 0;
overflow: hidden;
}
#cf-world {
position: absolute;
left: 0;
top: 0;
width: 0;
height: 0;
--amt: 0px;
}
.cf-word {
position: absolute;
white-space: nowrap;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-weight: 700;
text-transform: uppercase;
letter-spacing: 0.005em;
line-height: 0.78;
color: var(--ink);
opacity: 0;
--k: 0;
filter: blur(calc(var(--k) * var(--amt)));
}
.cf-word.is-accent {
color: var(--cf-accent);
}
#cf-vignette {
position: absolute;
inset: 0;
background: radial-gradient(
ellipse at 50% 50%,
rgba(0, 0, 0, 0) 42%,
rgba(0, 0, 0, 0.55) 100%
);
}
</style>
<div id="cf-stage">
<div id="cf-world"></div>
</div>
<div id="cf-vignette"></div>
<script src="https://cdn.jsdelivr.net/npm/gsap@3.14.2/dist/gsap.min.js"></script>
<script>
(function () {
gsap.defaults({ immediateRender: false });
/* Cubic bezier solver. Newton first, bisection as the fallback, so it is
exact and deterministic for every input. */
function bezier(x1, y1, x2, y2) {
function curve(t, a1, a2) {
var A = 1 - 3 * a2 + 3 * a1;
var B = 3 * a2 - 6 * a1;
var C = 3 * a1;
return ((A * t + B) * t + C) * t;
}
function slope(t, a1, a2) {
var A = 1 - 3 * a2 + 3 * a1;
var B = 3 * a2 - 6 * a1;
var C = 3 * a1;
return (3 * A * t + 2 * B) * t + C;
}
return function (p) {
if (p <= 0) return 0;
if (p >= 1) return 1;
var t = p;
for (var i = 0; i < 8; i++) {
var d = slope(t, x1, x2);
if (Math.abs(d) < 1e-6) break;
var e = curve(t, x1, x2) - p;
if (Math.abs(e) < 1e-7) return curve(t, y1, y2);
t -= e / d;
}
var lo = 0;
var hi = 1;
t = p;
for (var j = 0; j < 24; j++) {
var x = curve(t, x1, x2);
if (Math.abs(x - p) < 1e-7) break;
if (x > p) hi = t;
else lo = t;
t = (lo + hi) / 2;
}
return curve(t, y1, y2);
};
}
/* Leaves the mark fast, spends most of its time arriving. */
var EASE_STEP = bezier(0.31, 0, 0.11, 1);
/* The closing pull back: slower to leave, glides a long way out. */
var EASE_WIDE = bezier(0.42, 0, 0.14, 1);
/* Word ink coming up. */
var EASE_INK = bezier(0.2, 0.7, 0.3, 1);
/* Blur rising into the move and wiped off out of it. */
var EASE_BLUR_UP = bezier(0.2, 0.8, 0.4, 1);
var EASE_BLUR_DOWN = bezier(0.5, 0, 0.2, 1);
var vars =
window.__hyperframes && window.__hyperframes.getVariables
? window.__hyperframes.getVariables()
: {};
/* Unrecognised overrides return to their declared defaults. */
function pick(table, value, fallback) {
return Object.prototype.hasOwnProperty.call(table, value) ? value : fallback;
}
var ACCENTS = {
gold: "#ffd84d",
green: "#34d399",
blue: "#38bdf8",
violet: "#a78bfa",
};
/* Framing scales the margin every camera pose is fitted with, so one
number moves the whole shot in or out without touching cadence. */
var FRAMINGS = { tight: 0.82, standard: 1, wide: 1.25 };
var SMEARS = { off: 0, subtle: 0.5, standard: 1, heavy: 1.9 };
var ACCENT = ACCENTS[pick(ACCENTS, vars.accent, "gold")];
var FRAMING = FRAMINGS[pick(FRAMINGS, vars.framing, "standard")];
var SMEAR = SMEARS[pick(SMEARS, vars.smear, "standard")];
var DUR = 9;
var STEP = 0.52;
var MOVE = 0.4;
var WORDS = [
{ text: "write" },
{ text: "the" },
{ text: "html", accent: true },
{ text: "and" },
{ text: "the" },
{ text: "video", accent: true },
{ text: "renders" },
{ text: "itself" },
{ text: "no" },
{ text: "timeline" },
{ text: "no" },
{ text: "keyframes", accent: true },
{ text: "just" },
{ text: "code", accent: true },
];
var world = document.getElementById("cf-world");
var stage = document.getElementById("cf-stage");
/* The runtime strips the root id on clone, so reach the root through a
descendant instead of getElementById. */
var root = stage.parentElement;
var FRAME_W = root.clientWidth || 1080;
var FRAME_H = root.clientHeight || 1920;
root.style.setProperty("--cf-accent", ACCENT);
/* Base size is picked so the opening shot sits near 1:1. Everything after it
is a pull back, so the world is only ever scaled down and type stays crisp. */
var BASE = Math.max(FRAME_W, FRAME_H) * 0.16;
/* Each new word is this fraction of the current box height. */
var RATIO = 0.72;
var MARGIN = 1.36 * FRAMING;
var ruler = document.createElement("div");
ruler.style.cssText =
"position:absolute;left:-99999px;top:0;white-space:nowrap;visibility:hidden;" +
'font-family:"Helvetica Neue",Helvetica,Arial,sans-serif;font-weight:700;' +
"text-transform:uppercase;letter-spacing:0.005em;line-height:0.78";
world.appendChild(ruler);
var box = null;
WORDS.forEach(function (wd, i) {
var fs = i === 0 ? BASE : (box.y1 - box.y0) * RATIO;
ruler.style.fontSize = fs + "px";
ruler.textContent = wd.text;
var w = ruler.getBoundingClientRect().width;
var h = fs * 0.78;
var gap = fs * 0.07;
var x, y;
if (i === 0) {
x = 0;
y = 0;
} else if ((box.x1 - box.x0) / (box.y1 - box.y0) < FRAME_W / FRAME_H) {
/* block is narrower than the frame, so grow sideways: to the right of
everything, sitting on the same baseline */
x = box.x1 + gap;
y = box.y1 - h;
} else {
/* block is already wide enough, so grow downward: onto a new line under
everything, left edges aligned */
x = box.x0;
y = box.y1 + gap;
}
wd.fs = fs;
wd.x = x;
wd.y = y;
box = box
? {
x0: Math.min(box.x0, x),
y0: Math.min(box.y0, y),
x1: Math.max(box.x1, x + w),
y1: Math.max(box.y1, y + h),
}
: { x0: x, y0: y, x1: x + w, y1: y + h };
wd.box = { x0: box.x0, y0: box.y0, x1: box.x1, y1: box.y1 };
});
world.removeChild(ruler);
var FULL = box;
function poseFor(b, margin) {
var bw = (b.x1 - b.x0) * margin;
var bh = (b.y1 - b.y0) * margin;
var s = Math.min(FRAME_W / bw, FRAME_H / bh);
return {
x: FRAME_W / 2 - (s * (b.x0 + b.x1)) / 2,
y: FRAME_H / 2 - (s * (b.y0 + b.y1)) / 2,
scale: s,
};
}
var els = WORDS.map(function (wd) {
var el = document.createElement("div");
el.className = "cf-word" + (wd.accent ? " is-accent" : "");
el.textContent = wd.text;
el.style.left = wd.x + "px";
el.style.top = wd.y + "px";
el.style.fontSize = wd.fs + "px";
world.appendChild(el);
return el;
});
/* Re-derive every framing box from what the browser actually laid out, so
the camera is fitted to real ink and never to arithmetic that drifted. */
var run = null;
els.forEach(function (el, i) {
var r = {
x0: el.offsetLeft,
y0: el.offsetTop,
x1: el.offsetLeft + el.offsetWidth,
y1: el.offsetTop + el.offsetHeight,
};
run = run
? {
x0: Math.min(run.x0, r.x0),
y0: Math.min(run.y0, r.y0),
x1: Math.max(run.x1, r.x1),
y1: Math.max(run.y1, r.y1),
}
: r;
WORDS[i].box = { x0: run.x0, y0: run.y0, x1: run.x1, y1: run.y1 };
});
FULL = run;
/* Rest state is pinned outside the timeline. */
var first = poseFor(WORDS[0].box, MARGIN);
gsap.set(world, {
transformOrigin: "0 0",
x: first.x,
y: first.y,
scale: first.scale,
});
gsap.set(els, { opacity: 0, "--k": 0 });
gsap.set(world, { "--amt": "0px" });
/* The first word is already on the page when the shot opens, so frame zero
is never empty. */
gsap.set(els[0], { opacity: 1 });
var tl = gsap.timeline({ paused: true });
/* Peak smear at the rim of the frame, in screen pixels. */
var BLUR = FRAME_W * 0.026 * SMEAR;
var HALF_DIAG = Math.sqrt(FRAME_W * FRAME_W + FRAME_H * FRAME_H) / 2;
/* Radial blur, the way a real zoom smears: a point far from the centre of
the move sweeps across more of the frame than one sitting on it, so it
streaks more. Each word gets its own share, --k, of one shared amount,
--amt, which is the only thing that animates. The share is fixed for the
length of a move and set with the camera, so this stays one tween per
move rather than one per word per move. --amt is authored in world units,
because a filter on a scaled child is applied before the scale, so the
screen blur has to be divided back out by the camera scale. */
function smear(centre, scale, count, at, up, down, peak) {
for (var j = 0; j < count; j++) {
var el = els[j];
var cx = el.offsetLeft + el.offsetWidth / 2;
var cy = el.offsetTop + el.offsetHeight / 2;
var d =
(scale *
Math.sqrt(
(cx - centre.x) * (cx - centre.x) + (cy - centre.y) * (cy - centre.y),
)) /
HALF_DIAG;
tl.set(el, { "--k": (0.2 + 1.15 * Math.min(1, d)).toFixed(3) }, at);
}
var amt = peak / scale;
tl.fromTo(
world,
{ "--amt": "0px" },
{ "--amt": amt + "px", duration: up, ease: EASE_BLUR_UP },
at,
);
tl.to(world, { "--amt": "0px", duration: down, ease: EASE_BLUR_DOWN }, at + up);
}
WORDS.forEach(function (wd, i) {
var t = i * STEP;
if (i === 0) return;
tl.fromTo(els[i], { opacity: 0 }, { opacity: 1, duration: 0.16, ease: EASE_INK }, t);
var p = poseFor(wd.box, MARGIN);
tl.to(world, { x: p.x, y: p.y, scale: p.scale, duration: MOVE, ease: EASE_STEP }, t);
smear(
{ x: (wd.box.x0 + wd.box.x1) / 2, y: (wd.box.y0 + wd.box.y1) / 2 },
p.scale,
i + 1,
t,
MOVE * 0.24,
MOVE * 0.44,
BLUR,
);
});
/* The resolve: the same pull back, carried all the way out. */
var wide = poseFor(FULL, 1.2 * FRAMING);
var wideAt = (WORDS.length - 1) * STEP + 0.62;
tl.to(
world,
{
x: wide.x,
y: wide.y,
scale: wide.scale,
duration: 0.94,
ease: EASE_WIDE,
},
wideAt,
);
smear(
{ x: (FULL.x0 + FULL.x1) / 2, y: (FULL.y0 + FULL.y1) / 2 },
wide.scale,
els.length,
wideAt,
0.3,
0.58,
BLUR * 0.8,
);
tl.set({}, {}, DUR);
tl.seek(0);
window.__timelines = window.__timelines || {};
window.__timelines["caption-camera-follow"] = tl;
})();
</script>
</div>
</template>
</body>
</html>
```
</Accordion>
{/* hf:generated-footer */}
Tagged `captions` `caption-style` `camera` `typography` `motion-primitive` `portrait`.
## Related topics
- [Browse the complete Catalog](/catalog)
- [Add assets and Catalog items in Studio](/studio/assets-and-blocks)
- [Build a richer composition](/go-further)