Files
hyperframes/docs/catalog/components/scroll-camera-story.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

1686 lines
65 KiB
Plaintext

---
title: "Scroll Camera Story"
description: "A compressed forced-scroll cinematic pass: a tall scene of slotted sections travels past the camera top to bottom, depth layers parallax at different rates, each section rises as the camera reaches it, and the pass decelerates into a held final section."
---
import { InstallCommand } from "/snippets/install-command.jsx";
import { VariablesExplorer } from "/snippets/variables-explorer.jsx";
<VariablesExplorer
previewSrc="/public/catalog/components/scroll-camera-story.json"
compositionId="scroll-camera-story"
compositionSrc="compositions/components/scroll-camera-story.html"
variables={[{"id":"sections","type":"number","role":"content","label":"Sections","description":"How many skeleton sections ride the pass. A sections slot overrides this with its own child count.","default":3,"min":2,"max":4,"step":1},{"id":"travel","type":"number","role":"content","label":"Travel","description":"Total camera travel in cqh. The world is 100 + travel cqh tall.","default":220,"min":100,"max":400,"step":10,"unit":"cqh"},{"id":"cues","type":"string","role":"timing","label":"Cues","description":"Comma-separated seconds: arrival times for the sections after the first. Empty keeps the authored default rhythm.","default":""},{"id":"accent","type":"enum","role":"style","label":"Accent","description":"Token the skeleton accents and foreground motes ride.","default":"green","options":[{"value":"green","label":"Green"},{"value":"blue","label":"Blue"},{"value":"violet","label":"Violet"}]},{"id":"exit","type":"enum","role":"style","label":"Exit","description":"Optional departure. None holds the final section.","default":"none","options":[{"value":"none","label":"None"},{"value":"fade","label":"Fade"},{"value":"up","label":"Up"}]}]}
>
```html scroll-camera-story.html
<!doctype html>
<!--
scroll-camera-story -- HyperFrames video primitive (camera)
A compressed forced-scroll cinematic pass: a tall authored scene travels
past the camera top to bottom. Four depth layers move at different rates
(far slowest, foreground fastest), sections enter with a soft rise as the
camera reaches them, and the pass decelerates into a held final section.
Camera-servo law: all camera state lives in ONE plain object (cam.t, the
pass progress 0 to 1) plus a drift object, and every layer transform is a
pure function of that state written by one applyCamera() writer. The world
wrapper carries the camera translate; depth layers carry derived parallax
offsets computed in the same writer, so any seek in any order reproduces
the exact frame. Micro-drift runs INTEGER sine cycles (2 on x-phase, 3 on
y-phase) that end at exactly zero when the final section lands, so the
held final section is byte-still.
Seek-safety trap (banked): cq-unit transform tweens blow up under seeks.
Nothing here tweens a cq unit. The world height is set ONCE at mount in
cqh; every tweened transform is percent-based (translate percent of the
element's own box, gsap yPercent on section cards) derived from plain
numbers, so no container-query re-resolution ever happens inside a tween.
Sections are SLOTS. Callers supply content by placing an inert template
at HOST DOCUMENT level (templates never render, and the runtime wipes the
host clip's own children on mount):
<template data-slot="scroll-camera-story-sections">
<div>first section content</div>
<div>second section content</div>
</template>
Each direct child of the template becomes one section's card content, in
order (clamped to 2-4 sections). Sections without a slot child keep their
token skeleton default. Without a slot, the `sections` variable picks how
many skeleton sections ride the pass.
Variables (declared in data-composition-variables below):
- sections (number 2-4, default 3): skeleton section count; a sections
slot overrides it with its own child count.
- travel (number cqh, default 220): total camera travel. The world is
(100 + travel) cqh tall; sections spread evenly along the travel.
- cues (string, default ""): comma-separated seconds, arrival times for
the sections AFTER the first (the first section is on screen at
mount). Empty keeps the authored default rhythm. If one extra value
is supplied, the first is treated as the mount section's and dropped.
- accent ("green" | "blue" | "violet", default "green"): green rides
--brand, blue rides --accent, violet rides --accent-2.
- exit ("none" | "fade" | "up", default "none"): frame roots own
transitions; the default holds the final section to the last pixel.
Envelope, fixed IN and OUT with elastic HOLD only (never timeScale):
IN_BASE = 0.85s stage fade + first section rise
PASS = camera moves ending on each arrival cue, quiet register
(power2.inOut, longer final move: the pass decelerates)
HOLD = elastic; drift ends at zero on the last arrival, then the
held final section is dead still
OUT_BASE = 0.50s only when exit != none
If D is too short the fixed phases compress together.
Wave K laws: L1, camera segments never overlap (each move starts after
the previous ends, so no mid-motion redirect exists to snap velocity);
L2, the quiet register is the only register here, no percussive variant.
Mount contract: the runtime clones only this template. #root fills the
host box (no data-width/data-height, container-type: size, cq units in
static styles only), is styled via #root only, and registers one paused
timeline under the LITERAL "scroll-camera-story" key.
-->
<html
lang="en"
data-composition-id="scroll-camera-story"
data-composition-duration="5.5"
data-composition-variables='[
{ "id": "sections", "type": "number", "role": "content", "label": "Sections", "description": "How many skeleton sections ride the pass. A sections slot overrides this with its own child count.", "default": 3, "min": 2, "max": 4, "step": 1 },
{ "id": "travel", "type": "number", "role": "content", "label": "Travel", "description": "Total camera travel in cqh. The world is 100 + travel cqh tall.", "default": 220, "min": 100, "max": 400, "step": 10, "unit": "cqh" },
{ "id": "cues", "type": "string", "role": "timing", "label": "Cues", "description": "Comma-separated seconds: arrival times for the sections after the first. Empty keeps the authored default rhythm.", "default": "" },
{ "id": "accent", "type": "enum", "role": "style", "label": "Accent", "description": "Token the skeleton accents and foreground motes ride.", "default": "green", "options": [{ "value": "green", "label": "Green" }, { "value": "blue", "label": "Blue" }, { "value": "violet", "label": "Violet" }] },
{ "id": "exit", "type": "enum", "role": "style", "label": "Exit", "description": "Optional departure. None holds the final section.", "default": "none", "options": [{ "value": "none", "label": "None" }, { "value": "fade", "label": "Fade" }, { "value": "up", "label": "Up" }] }
]'
>
<head>
<meta charset="UTF-8" />
<title>Scroll Camera Story</title>
</head>
<body>
<template>
<div id="root" data-composition-id="scroll-camera-story" data-duration="5.5" data-fps="30">
<style>
*,
*::before,
*::after {
box-sizing: border-box;
}
#root {
position: absolute;
inset: 0;
overflow: hidden;
container-type: size;
isolation: isolate;
color: var(--fg, #f8fafc);
font-family: var(--font-body, ui-sans-serif, system-ui, sans-serif);
pointer-events: none;
}
.scs-clip {
position: absolute;
inset: 0;
overflow: hidden;
background: var(--bg, transparent);
}
.scs-stage {
position: absolute;
inset: 0;
overflow: hidden;
background:
radial-gradient(
ellipse 120% 70% at 50% 0%,
color-mix(in srgb, var(--scs-accent) 6%, transparent) 0%,
transparent 60%
),
var(--bg, #0b0c0e);
will-change: transform, opacity;
}
/* ONE world wrapper: the camera translate lives here; depth layers
below carry derived parallax offsets from the same writer. */
.scs-world {
position: absolute;
top: 0;
right: 0;
left: 0;
will-change: transform;
}
.scs-layer {
position: absolute;
inset: 0;
will-change: transform;
}
/* far layer: large soft washes, slowest */
.scs-blob {
position: absolute;
width: 64cqmin;
height: 64cqmin;
border-radius: 50%;
background: radial-gradient(
circle,
color-mix(in srgb, var(--scs-accent) 11%, transparent) 0%,
color-mix(in srgb, var(--scs-accent) 5%, transparent) 45%,
transparent 70%
);
}
.scs-blob:nth-child(1) {
top: 2%;
left: -14cqmin;
}
.scs-blob:nth-child(2) {
top: 17%;
right: -18cqmin;
width: 78cqmin;
height: 78cqmin;
background: radial-gradient(
circle,
color-mix(in srgb, var(--fg, #f8fafc) 6%, transparent) 0%,
color-mix(in srgb, var(--fg, #f8fafc) 3%, transparent) 45%,
transparent 70%
);
}
.scs-blob:nth-child(3) {
top: 34%;
left: 6cqw;
}
.scs-blob:nth-child(4) {
top: 48%;
right: 2cqw;
width: 56cqmin;
height: 56cqmin;
}
/* mid layer: hairline geometry */
.scs-ring {
position: absolute;
width: 16cqmin;
height: 16cqmin;
border: 0.16cqmin solid color-mix(in srgb, var(--fg, #f8fafc) 12%, transparent);
border-radius: 50%;
}
.scs-rule {
position: absolute;
width: 12cqmin;
height: 0.16cqmin;
background: color-mix(in srgb, var(--fg, #f8fafc) 14%, transparent);
}
.scs-plus {
position: absolute;
width: 3.4cqmin;
height: 3.4cqmin;
}
.scs-plus::before,
.scs-plus::after {
position: absolute;
content: "";
background: color-mix(in srgb, var(--fg, #f8fafc) 18%, transparent);
}
.scs-plus::before {
top: 0;
bottom: 0;
left: calc(50% - 0.08cqmin);
width: 0.16cqmin;
}
.scs-plus::after {
top: calc(50% - 0.08cqmin);
right: 0;
left: 0;
height: 0.16cqmin;
}
.scs-ring:nth-of-type(1) {
top: 6%;
right: 12cqw;
}
.scs-ring:nth-of-type(2) {
top: 30%;
left: 9cqw;
width: 10cqmin;
height: 10cqmin;
}
.scs-ring:nth-of-type(3) {
top: 52%;
right: 8cqw;
width: 22cqmin;
height: 22cqmin;
border-color: color-mix(in srgb, var(--fg, #f8fafc) 8%, transparent);
}
.scs-rule:nth-of-type(1) {
top: 14%;
left: 12cqw;
transform: rotate(90deg);
}
.scs-rule:nth-of-type(2) {
top: 40%;
right: 16cqw;
}
.scs-plus:nth-of-type(1) {
top: 22%;
right: 22cqw;
}
.scs-plus:nth-of-type(2) {
top: 47%;
left: 18cqw;
}
.scs-plus:nth-of-type(3) {
top: 9%;
left: 30cqw;
}
/* foreground layer: small accent motes, fastest */
.scs-mote {
position: absolute;
width: 1cqmin;
height: 1cqmin;
border-radius: 50%;
background: color-mix(in srgb, var(--scs-accent) 55%, transparent);
}
.scs-mote:nth-child(1) {
top: 7%;
left: 8cqw;
}
.scs-mote:nth-child(2) {
top: 21%;
right: 10cqw;
width: 0.7cqmin;
height: 0.7cqmin;
}
.scs-mote:nth-child(3) {
top: 43%;
left: 6cqw;
width: 1.3cqmin;
height: 1.3cqmin;
background: color-mix(in srgb, var(--scs-accent) 40%, transparent);
}
.scs-mote:nth-child(4) {
top: 66%;
right: 7cqw;
}
.scs-mote:nth-child(5) {
top: 88%;
left: 4cqw;
width: 0.8cqmin;
height: 0.8cqmin;
}
/* sections: a static positioner zone per section, a rising card in it */
.scs-section {
position: absolute;
right: 10cqw;
left: 10cqw;
display: grid;
place-items: center;
height: 84cqh;
}
.scs-card {
display: flex;
flex-direction: column;
gap: var(--space-2, 2.2cqmin);
width: min(64cqw, 150cqh);
max-height: 76cqh;
padding: var(--space-3, 3.4cqmin);
overflow: hidden;
border: 0.16cqmin solid color-mix(in srgb, var(--border, #475569) 70%, transparent);
border-radius: var(--radius, 2cqmin);
background: color-mix(in srgb, var(--surface, #0b1016) 88%, var(--bg, #05070c));
box-shadow: 0 2.4cqh 7cqh color-mix(in srgb, var(--bg, #000000) 34%, transparent);
will-change: transform, opacity;
}
.scs-chiprow {
display: flex;
align-items: center;
gap: var(--space-1, 1.6cqmin);
}
.scs-chip {
padding: 0.7cqmin 1.5cqmin;
border: 0.14cqmin solid color-mix(in srgb, var(--scs-accent) 45%, transparent);
border-radius: 999px;
color: color-mix(in srgb, var(--scs-accent) 80%, var(--fg, #f8fafc));
font-family: var(--font-mono, ui-monospace, "SF Mono", Menlo, Consolas, monospace);
font-size: 2cqmin;
font-weight: 600;
letter-spacing: 0.14em;
line-height: 1;
}
.scs-chiprule {
flex: 1;
height: 0.14cqmin;
background: color-mix(in srgb, var(--border, #475569) 60%, transparent);
}
.scs-bar {
height: 1.4cqmin;
border-radius: 999px;
background: color-mix(in srgb, var(--fg, #f8fafc) 12%, transparent);
}
.scs-bar.scs-heading {
width: 62%;
height: 3.4cqmin;
background: color-mix(in srgb, var(--fg, #f8fafc) 24%, transparent);
}
.scs-bar.scs-sub {
width: 44%;
}
.scs-minis {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 2cqmin;
margin-top: 0.6cqmin;
}
.scs-mini {
display: flex;
flex-direction: column;
gap: 1.4cqmin;
padding: 2cqmin;
border: 0.14cqmin solid color-mix(in srgb, var(--border, #475569) 55%, transparent);
border-radius: calc(var(--radius, 2cqmin) * 0.7);
background: color-mix(in srgb, var(--bg, #05070c) 32%, transparent);
}
.scs-mini .scs-bar {
width: 62%;
}
.scs-mini-block {
height: 7cqmin;
border-radius: calc(var(--radius, 2cqmin) * 0.5);
background: color-mix(in srgb, var(--fg, #f8fafc) 7%, transparent);
}
.scs-mini:nth-child(2) .scs-mini-block {
background: color-mix(in srgb, var(--scs-accent) 18%, transparent);
}
.scs-rowline {
display: flex;
align-items: center;
gap: var(--space-1, 1.6cqmin);
}
.scs-dot {
flex: 0 0 auto;
width: 1.5cqmin;
height: 1.5cqmin;
border-radius: 50%;
background: color-mix(in srgb, var(--fg, #f8fafc) 22%, transparent);
}
.scs-rowline:nth-of-type(2) .scs-dot {
background: color-mix(in srgb, var(--scs-accent) 70%, transparent);
}
.scs-rowline .scs-bar {
flex: 1;
max-width: 72%;
}
.scs-section[data-close] .scs-card {
align-items: center;
text-align: center;
}
.scs-section[data-close] .scs-bar.scs-heading {
width: 52%;
}
.scs-section[data-close] .scs-bar.scs-sub {
width: 34%;
}
.scs-pill {
margin-top: 1.2cqmin;
padding: 1.4cqmin 3.4cqmin;
border-radius: 999px;
background: color-mix(in srgb, var(--scs-accent) 82%, var(--surface, #0b1016));
color: var(--bg, #0b0c0e);
font-family: var(--font-mono, ui-monospace, "SF Mono", Menlo, Consolas, monospace);
font-size: 2.1cqmin;
font-weight: 600;
letter-spacing: 0.12em;
line-height: 1;
}
</style>
<div
id="scroll-camera-story-clip"
class="scs-clip clip"
data-start="0"
data-duration="5.5"
data-track-index="0"
>
<div class="scs-stage" role="img" aria-label="Cinematic scroll pass over a tall scene">
<div class="scs-world">
<div class="scs-layer scs-far" aria-hidden="true">
<span class="scs-blob"></span>
<span class="scs-blob"></span>
<span class="scs-blob"></span>
<span class="scs-blob"></span>
</div>
<div class="scs-layer scs-mid" aria-hidden="true">
<span class="scs-ring"></span>
<span class="scs-ring"></span>
<span class="scs-ring"></span>
<span class="scs-rule"></span>
<span class="scs-rule"></span>
<span class="scs-plus"></span>
<span class="scs-plus"></span>
<span class="scs-plus"></span>
</div>
<div class="scs-layer scs-content">
<div class="scs-section" aria-hidden="true">
<div class="scs-card">
<div class="scs-chiprow">
<span class="scs-chip">01</span>
<span class="scs-chiprule"></span>
</div>
<span class="scs-bar scs-heading"></span>
<span class="scs-bar" style="width: 74%"></span>
<span class="scs-bar scs-sub"></span>
</div>
</div>
<div class="scs-section" aria-hidden="true">
<div class="scs-card">
<div class="scs-chiprow">
<span class="scs-chip">02</span>
<span class="scs-chiprule"></span>
</div>
<span class="scs-bar scs-heading" style="width: 46%"></span>
<div class="scs-minis">
<div class="scs-mini">
<span class="scs-bar"></span>
<span class="scs-mini-block"></span>
</div>
<div class="scs-mini">
<span class="scs-bar"></span>
<span class="scs-mini-block"></span>
</div>
<div class="scs-mini">
<span class="scs-bar"></span>
<span class="scs-mini-block"></span>
</div>
</div>
</div>
</div>
<div class="scs-section" aria-hidden="true">
<div class="scs-card">
<div class="scs-chiprow">
<span class="scs-chip">03</span>
<span class="scs-chiprule"></span>
</div>
<span class="scs-bar scs-heading" style="width: 40%"></span>
<div class="scs-rowline">
<span class="scs-dot"></span>
<span class="scs-bar"></span>
</div>
<div class="scs-rowline">
<span class="scs-dot"></span>
<span class="scs-bar" style="max-width: 58%"></span>
</div>
<div class="scs-rowline">
<span class="scs-dot"></span>
<span class="scs-bar" style="max-width: 66%"></span>
</div>
</div>
</div>
<div class="scs-section" data-close aria-hidden="true">
<div class="scs-card">
<div class="scs-chiprow" style="align-self: stretch">
<span class="scs-chip">04</span>
<span class="scs-chiprule"></span>
</div>
<span class="scs-bar scs-heading"></span>
<span class="scs-bar scs-sub"></span>
<span class="scs-pill">&gt;_</span>
</div>
</div>
</div>
<div class="scs-layer scs-fore" aria-hidden="true">
<span class="scs-mote"></span>
<span class="scs-mote"></span>
<span class="scs-mote"></span>
<span class="scs-mote"></span>
<span class="scs-mote"></span>
</div>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/gsap@3.14.2/dist/gsap.min.js"></script>
<script>
(function () {
"use strict";
var root = document.getElementById("root");
var stage = root.querySelector(".scs-stage");
var world = root.querySelector(".scs-world");
var layerFar = root.querySelector(".scs-far");
var layerMid = root.querySelector(".scs-mid");
var layerFore = root.querySelector(".scs-fore");
var sectionElements = Array.prototype.slice.call(root.querySelectorAll(".scs-section"));
var vars =
window.__hyperframes && window.__hyperframes.getVariables
? window.__hyperframes.getVariables()
: {};
function num(value, fallback, min, max) {
var parsed = parseFloat(value);
if (!isFinite(parsed)) parsed = fallback;
return Math.min(max, Math.max(min, parsed));
}
var travel = num(vars.travel, 220, 100, 400);
var sectionsVar = Math.round(num(vars.sections, 3, 2, 4));
// Each enum choice routes to a DIFFERENT contract token so the
// variable stays meaningful under a theme.
var accentColors = {
green: "var(--brand, #71f5a7)",
blue: "var(--accent, #61a8ff)",
violet: "var(--accent-2, #c5a3ff)",
};
var accent = Object.prototype.hasOwnProperty.call(accentColors, vars.accent)
? vars.accent
: "green";
var exitMode = vars.exit === "fade" || vars.exit === "up" ? vars.exit : "none";
root.style.setProperty("--scs-accent", accentColors[accent]);
// SLOT. Caller templates live at HOST DOCUMENT level (the mount
// wipes host-clip children, and templates never render). Each
// direct child of the slot template becomes one section's card
// content, in order.
var hostDoc = root.ownerDocument;
var slotChildren = [];
try {
var slotTemplate = hostDoc.querySelector(
'template[data-slot="scroll-camera-story-sections"]',
);
if (slotTemplate)
slotChildren = Array.prototype.slice.call(slotTemplate.content.children);
} catch (error) {
slotChildren = [];
}
var count = Math.min(4, Math.max(2, slotChildren.length || sectionsVar));
sectionElements.forEach(function (section, index) {
if (index >= count) {
section.remove();
return;
}
if (slotChildren[index]) {
var card = section.querySelector(".scs-card");
while (card.firstChild) card.removeChild(card.firstChild);
card.appendChild(hostDoc.importNode(slotChildren[index], true));
}
});
var sections = sectionElements.slice(0, count);
var cards = sections.map(function (section) {
return section.querySelector(".scs-card");
});
// World geometry, set ONCE at mount in cqh (static style, never
// tweened; the seek trap is cq units INSIDE tweens). Section i
// centers at camera progress i / (count - 1) along the travel.
world.style.height = (100 + travel).toFixed(2) + "cqh";
sections.forEach(function (section, index) {
var progress = index / (count - 1);
section.style.top = (50 + progress * travel - 42).toFixed(2) + "cqh";
});
/* ===== Camera (camera-servo law): one plain state object, one
writer. cam.t is the pass progress 0..1. The world translates
by percent of its OWN height (a pure number: travel out of
100 + travel), and each depth layer gets a derived parallax
offset so its net rate is RATE x the camera rate. No cq units
are ever tweened. ===== */
var F = (100 * travel) / (100 + travel); // percent of world height per full pass
var RATE_FAR = 0.35;
var RATE_MID = 0.65;
var RATE_FORE = 1.12;
var cam = { t: 0 };
var drift = { p: 0, dx: 0, dy: 0 };
function applyCamera() {
var y = -cam.t * F;
world.style.transform = "translate(" + drift.dx + "%, " + (y + drift.dy) + "%)";
layerFar.style.transform = "translateY(" + cam.t * F * (1 - RATE_FAR) + "%)";
layerMid.style.transform = "translateY(" + cam.t * F * (1 - RATE_MID) + "%)";
layerFore.style.transform = "translateY(" + cam.t * F * (1 - RATE_FORE) + "%)";
}
applyCamera();
// Envelope: fixed IN/OUT, elastic HOLD, never time-scaled.
var IN_BASE = 0.85;
var OUT_BASE = exitMode === "none" ? 0 : 0.5;
var PASS_MIN = 1.2;
var duration = Math.max(0.001, parseFloat(root.dataset.duration || "5.5"));
var totalBase = IN_BASE + PASS_MIN + OUT_BASE;
var scale = duration < totalBase ? duration / totalBase : 1;
var IN = IN_BASE * scale;
var OUT = OUT_BASE * scale;
var usable = duration - OUT;
// Arrival schedule: defaults decelerate into a held final
// section; the cues variable overrides arrivals for sections
// after the first.
var HOLD_MIN = Math.min(1.3, Math.max(0.45, usable * 0.24));
var lastDefault = Math.max(IN + 0.9 * scale, usable - HOLD_MIN);
var firstDefault = Math.min(lastDefault, IN + 1.15 * scale);
var arrivals = [];
var index;
for (index = 1; index < count; index += 1) {
arrivals.push(
count === 2
? lastDefault
: firstDefault + ((index - 1) / (count - 2)) * (lastDefault - firstDefault),
);
}
var cueValues = String(vars.cues == null ? "" : vars.cues)
.split(",")
.map(function (part) {
return parseFloat(part);
})
.filter(function (value) {
return isFinite(value);
});
// Lenient by one: a list with an extra leading value is treated
// as including the mount section's arrival.
if (cueValues.length === count) cueValues = cueValues.slice(1);
if (cueValues.length >= count - 1) {
arrivals = cueValues.slice(0, count - 1);
}
var floor = IN + 0.35 * scale;
for (index = 0; index < arrivals.length; index += 1) {
var clamped = Math.min(usable - 0.3 * scale, Math.max(floor, arrivals[index]));
arrivals[index] = clamped;
floor = clamped + 0.4 * scale;
}
var lastArrival = arrivals.length > 0 ? arrivals[arrivals.length - 1] : IN;
var tl = gsap.timeline({ paused: true });
// IN: the stage fades up while the first section rises.
tl.fromTo(
stage,
{ opacity: 0 },
{ opacity: 1, duration: Math.min(0.6 * scale, IN), ease: "power2.out" },
0,
);
// Section rises: each card lands exactly on its arrival cue.
// yPercent only (percent of the card's own box), never cq units.
cards.forEach(function (card, cardIndex) {
var arrive = cardIndex === 0 ? IN : arrivals[cardIndex - 1];
var rise = Math.min(
0.75 * scale,
Math.max(0.25, arrive - (cardIndex === 0 ? 0.1 : 0)),
);
tl.fromTo(
card,
{ opacity: 0, yPercent: 10 },
{ opacity: 1, yPercent: 0, duration: rise, ease: "power3.out" },
arrive - rise,
);
});
// Camera pass: one non-overlapping segment per arrival, quiet
// register (L2). Each move ends exactly on its cue; the final
// move runs longer, so the pass decelerates into the hold. No
// segment starts before the previous ends (L1: no mid-motion
// redirect exists to snap velocity).
var previousEnd = IN * 0.7;
arrivals.forEach(function (arrive, arriveIndex) {
var isLast = arriveIndex === arrivals.length - 1;
var gap = arrive - previousEnd - 0.1 * scale;
var move = Math.max(0.3, Math.min(isLast ? 1.7 : 1.25, gap));
tl.to(
cam,
{
t: (arriveIndex + 1) / (count - 1),
duration: move,
ease: "power2.inOut",
onUpdate: applyCamera,
},
arrive - move,
);
previousEnd = arrive;
});
// Micro-drift: 2 and 3 INTEGER sine cycles ending at exactly
// zero when the final section lands, so the held final section
// is byte-still and every seek reproduces the same frame.
if (lastArrival >= 1.2) {
tl.to(
drift,
{
p: Math.PI * 2 * 2,
duration: lastArrival,
ease: "none",
onUpdate: function () {
drift.dx = Math.sin(drift.p) * 0.06;
drift.dy = Math.sin(drift.p * 1.5) * 0.08;
applyCamera();
},
},
0,
);
}
// OUT: only when exit != none; the default holds the last frame.
if (exitMode !== "none") {
var outStart = duration - OUT;
tl.to(stage, { opacity: 0, duration: OUT, ease: "power2.in" }, outStart);
if (exitMode === "up") {
tl.to(stage, { yPercent: -4, duration: OUT, ease: "power2.in" }, outStart);
}
}
tl.seek(0);
window.__timelines = window.__timelines || {};
window.__timelines["scroll-camera-story"] = tl;
})();
</script>
</div>
</template>
</body>
</html>
```
</VariablesExplorer>
## Install
<InstallCommand command="npx hyperframes add scroll-camera-story" item="scroll-camera-story" />
That writes one file: `compositions/components/scroll-camera-story.html`.
## Paste it into your composition
Open `compositions/components/scroll-camera-story.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 |
| --- | --- | --- | --- |
| `sections` | `3` | 2 to 4, step 1 | How many skeleton sections ride the pass. A sections slot overrides this with its own child count. |
| `travel` | `220` | 100cqh to 400cqh, step 10cqh | Total camera travel in cqh. The world is 100 + travel cqh tall. |
| `cues` | `` | string | Comma-separated seconds: arrival times for the sections after the first. Empty keeps the authored default rhythm. |
| `accent` | `green` | `green`, `blue`, `violet` | Token the skeleton accents and foreground motes ride. |
| `exit` | `none` | `none`, `fade`, `up` | Optional departure. None holds the final section. |
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="scroll-camera-story"
data-composition-src="compositions/components/scroll-camera-story.html"
data-variable-values='{"sections":3,"travel":220,"cues":"","accent":"green","exit":"none"}'
></div>
```
## Source
<Accordion title={`scroll-camera-story.html`}>
```html
<!doctype html>
<!--
scroll-camera-story -- HyperFrames video primitive (camera)
A compressed forced-scroll cinematic pass: a tall authored scene travels
past the camera top to bottom. Four depth layers move at different rates
(far slowest, foreground fastest), sections enter with a soft rise as the
camera reaches them, and the pass decelerates into a held final section.
Camera-servo law: all camera state lives in ONE plain object (cam.t, the
pass progress 0 to 1) plus a drift object, and every layer transform is a
pure function of that state written by one applyCamera() writer. The world
wrapper carries the camera translate; depth layers carry derived parallax
offsets computed in the same writer, so any seek in any order reproduces
the exact frame. Micro-drift runs INTEGER sine cycles (2 on x-phase, 3 on
y-phase) that end at exactly zero when the final section lands, so the
held final section is byte-still.
Seek-safety trap (banked): cq-unit transform tweens blow up under seeks.
Nothing here tweens a cq unit. The world height is set ONCE at mount in
cqh; every tweened transform is percent-based (translate percent of the
element's own box, gsap yPercent on section cards) derived from plain
numbers, so no container-query re-resolution ever happens inside a tween.
Sections are SLOTS. Callers supply content by placing an inert template
at HOST DOCUMENT level (templates never render, and the runtime wipes the
host clip's own children on mount):
<template data-slot="scroll-camera-story-sections">
<div>first section content</div>
<div>second section content</div>
</template>
Each direct child of the template becomes one section's card content, in
order (clamped to 2-4 sections). Sections without a slot child keep their
token skeleton default. Without a slot, the `sections` variable picks how
many skeleton sections ride the pass.
Variables (declared in data-composition-variables below):
- sections (number 2-4, default 3): skeleton section count; a sections
slot overrides it with its own child count.
- travel (number cqh, default 220): total camera travel. The world is
(100 + travel) cqh tall; sections spread evenly along the travel.
- cues (string, default ""): comma-separated seconds, arrival times for
the sections AFTER the first (the first section is on screen at
mount). Empty keeps the authored default rhythm. If one extra value
is supplied, the first is treated as the mount section's and dropped.
- accent ("green" | "blue" | "violet", default "green"): green rides
--brand, blue rides --accent, violet rides --accent-2.
- exit ("none" | "fade" | "up", default "none"): frame roots own
transitions; the default holds the final section to the last pixel.
Envelope, fixed IN and OUT with elastic HOLD only (never timeScale):
IN_BASE = 0.85s stage fade + first section rise
PASS = camera moves ending on each arrival cue, quiet register
(power2.inOut, longer final move: the pass decelerates)
HOLD = elastic; drift ends at zero on the last arrival, then the
held final section is dead still
OUT_BASE = 0.50s only when exit != none
If D is too short the fixed phases compress together.
Wave K laws: L1, camera segments never overlap (each move starts after
the previous ends, so no mid-motion redirect exists to snap velocity);
L2, the quiet register is the only register here, no percussive variant.
Mount contract: the runtime clones only this template. #root fills the
host box (no data-width/data-height, container-type: size, cq units in
static styles only), is styled via #root only, and registers one paused
timeline under the LITERAL "scroll-camera-story" key.
-->
<html
lang="en"
data-composition-id="scroll-camera-story"
data-composition-duration="5.5"
data-composition-variables='[
{ "id": "sections", "type": "number", "role": "content", "label": "Sections", "description": "How many skeleton sections ride the pass. A sections slot overrides this with its own child count.", "default": 3, "min": 2, "max": 4, "step": 1 },
{ "id": "travel", "type": "number", "role": "content", "label": "Travel", "description": "Total camera travel in cqh. The world is 100 + travel cqh tall.", "default": 220, "min": 100, "max": 400, "step": 10, "unit": "cqh" },
{ "id": "cues", "type": "string", "role": "timing", "label": "Cues", "description": "Comma-separated seconds: arrival times for the sections after the first. Empty keeps the authored default rhythm.", "default": "" },
{ "id": "accent", "type": "enum", "role": "style", "label": "Accent", "description": "Token the skeleton accents and foreground motes ride.", "default": "green", "options": [{ "value": "green", "label": "Green" }, { "value": "blue", "label": "Blue" }, { "value": "violet", "label": "Violet" }] },
{ "id": "exit", "type": "enum", "role": "style", "label": "Exit", "description": "Optional departure. None holds the final section.", "default": "none", "options": [{ "value": "none", "label": "None" }, { "value": "fade", "label": "Fade" }, { "value": "up", "label": "Up" }] }
]'
>
<head>
<meta charset="UTF-8" />
<title>Scroll Camera Story</title>
</head>
<body>
<template>
<div id="root" data-composition-id="scroll-camera-story" data-duration="5.5" data-fps="30">
<style>
*,
*::before,
*::after {
box-sizing: border-box;
}
#root {
position: absolute;
inset: 0;
overflow: hidden;
container-type: size;
isolation: isolate;
color: var(--fg, #f8fafc);
font-family: var(--font-body, ui-sans-serif, system-ui, sans-serif);
pointer-events: none;
}
.scs-clip {
position: absolute;
inset: 0;
overflow: hidden;
background: var(--bg, transparent);
}
.scs-stage {
position: absolute;
inset: 0;
overflow: hidden;
background:
radial-gradient(
ellipse 120% 70% at 50% 0%,
color-mix(in srgb, var(--scs-accent) 6%, transparent) 0%,
transparent 60%
),
var(--bg, #0b0c0e);
will-change: transform, opacity;
}
/* ONE world wrapper: the camera translate lives here; depth layers
below carry derived parallax offsets from the same writer. */
.scs-world {
position: absolute;
top: 0;
right: 0;
left: 0;
will-change: transform;
}
.scs-layer {
position: absolute;
inset: 0;
will-change: transform;
}
/* far layer: large soft washes, slowest */
.scs-blob {
position: absolute;
width: 64cqmin;
height: 64cqmin;
border-radius: 50%;
background: radial-gradient(
circle,
color-mix(in srgb, var(--scs-accent) 11%, transparent) 0%,
color-mix(in srgb, var(--scs-accent) 5%, transparent) 45%,
transparent 70%
);
}
.scs-blob:nth-child(1) {
top: 2%;
left: -14cqmin;
}
.scs-blob:nth-child(2) {
top: 17%;
right: -18cqmin;
width: 78cqmin;
height: 78cqmin;
background: radial-gradient(
circle,
color-mix(in srgb, var(--fg, #f8fafc) 6%, transparent) 0%,
color-mix(in srgb, var(--fg, #f8fafc) 3%, transparent) 45%,
transparent 70%
);
}
.scs-blob:nth-child(3) {
top: 34%;
left: 6cqw;
}
.scs-blob:nth-child(4) {
top: 48%;
right: 2cqw;
width: 56cqmin;
height: 56cqmin;
}
/* mid layer: hairline geometry */
.scs-ring {
position: absolute;
width: 16cqmin;
height: 16cqmin;
border: 0.16cqmin solid color-mix(in srgb, var(--fg, #f8fafc) 12%, transparent);
border-radius: 50%;
}
.scs-rule {
position: absolute;
width: 12cqmin;
height: 0.16cqmin;
background: color-mix(in srgb, var(--fg, #f8fafc) 14%, transparent);
}
.scs-plus {
position: absolute;
width: 3.4cqmin;
height: 3.4cqmin;
}
.scs-plus::before,
.scs-plus::after {
position: absolute;
content: "";
background: color-mix(in srgb, var(--fg, #f8fafc) 18%, transparent);
}
.scs-plus::before {
top: 0;
bottom: 0;
left: calc(50% - 0.08cqmin);
width: 0.16cqmin;
}
.scs-plus::after {
top: calc(50% - 0.08cqmin);
right: 0;
left: 0;
height: 0.16cqmin;
}
.scs-ring:nth-of-type(1) {
top: 6%;
right: 12cqw;
}
.scs-ring:nth-of-type(2) {
top: 30%;
left: 9cqw;
width: 10cqmin;
height: 10cqmin;
}
.scs-ring:nth-of-type(3) {
top: 52%;
right: 8cqw;
width: 22cqmin;
height: 22cqmin;
border-color: color-mix(in srgb, var(--fg, #f8fafc) 8%, transparent);
}
.scs-rule:nth-of-type(1) {
top: 14%;
left: 12cqw;
transform: rotate(90deg);
}
.scs-rule:nth-of-type(2) {
top: 40%;
right: 16cqw;
}
.scs-plus:nth-of-type(1) {
top: 22%;
right: 22cqw;
}
.scs-plus:nth-of-type(2) {
top: 47%;
left: 18cqw;
}
.scs-plus:nth-of-type(3) {
top: 9%;
left: 30cqw;
}
/* foreground layer: small accent motes, fastest */
.scs-mote {
position: absolute;
width: 1cqmin;
height: 1cqmin;
border-radius: 50%;
background: color-mix(in srgb, var(--scs-accent) 55%, transparent);
}
.scs-mote:nth-child(1) {
top: 7%;
left: 8cqw;
}
.scs-mote:nth-child(2) {
top: 21%;
right: 10cqw;
width: 0.7cqmin;
height: 0.7cqmin;
}
.scs-mote:nth-child(3) {
top: 43%;
left: 6cqw;
width: 1.3cqmin;
height: 1.3cqmin;
background: color-mix(in srgb, var(--scs-accent) 40%, transparent);
}
.scs-mote:nth-child(4) {
top: 66%;
right: 7cqw;
}
.scs-mote:nth-child(5) {
top: 88%;
left: 4cqw;
width: 0.8cqmin;
height: 0.8cqmin;
}
/* sections: a static positioner zone per section, a rising card in it */
.scs-section {
position: absolute;
right: 10cqw;
left: 10cqw;
display: grid;
place-items: center;
height: 84cqh;
}
.scs-card {
display: flex;
flex-direction: column;
gap: var(--space-2, 2.2cqmin);
width: min(64cqw, 150cqh);
max-height: 76cqh;
padding: var(--space-3, 3.4cqmin);
overflow: hidden;
border: 0.16cqmin solid color-mix(in srgb, var(--border, #475569) 70%, transparent);
border-radius: var(--radius, 2cqmin);
background: color-mix(in srgb, var(--surface, #0b1016) 88%, var(--bg, #05070c));
box-shadow: 0 2.4cqh 7cqh color-mix(in srgb, var(--bg, #000000) 34%, transparent);
will-change: transform, opacity;
}
.scs-chiprow {
display: flex;
align-items: center;
gap: var(--space-1, 1.6cqmin);
}
.scs-chip {
padding: 0.7cqmin 1.5cqmin;
border: 0.14cqmin solid color-mix(in srgb, var(--scs-accent) 45%, transparent);
border-radius: 999px;
color: color-mix(in srgb, var(--scs-accent) 80%, var(--fg, #f8fafc));
font-family: var(--font-mono, ui-monospace, "SF Mono", Menlo, Consolas, monospace);
font-size: 2cqmin;
font-weight: 600;
letter-spacing: 0.14em;
line-height: 1;
}
.scs-chiprule {
flex: 1;
height: 0.14cqmin;
background: color-mix(in srgb, var(--border, #475569) 60%, transparent);
}
.scs-bar {
height: 1.4cqmin;
border-radius: 999px;
background: color-mix(in srgb, var(--fg, #f8fafc) 12%, transparent);
}
.scs-bar.scs-heading {
width: 62%;
height: 3.4cqmin;
background: color-mix(in srgb, var(--fg, #f8fafc) 24%, transparent);
}
.scs-bar.scs-sub {
width: 44%;
}
.scs-minis {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 2cqmin;
margin-top: 0.6cqmin;
}
.scs-mini {
display: flex;
flex-direction: column;
gap: 1.4cqmin;
padding: 2cqmin;
border: 0.14cqmin solid color-mix(in srgb, var(--border, #475569) 55%, transparent);
border-radius: calc(var(--radius, 2cqmin) * 0.7);
background: color-mix(in srgb, var(--bg, #05070c) 32%, transparent);
}
.scs-mini .scs-bar {
width: 62%;
}
.scs-mini-block {
height: 7cqmin;
border-radius: calc(var(--radius, 2cqmin) * 0.5);
background: color-mix(in srgb, var(--fg, #f8fafc) 7%, transparent);
}
.scs-mini:nth-child(2) .scs-mini-block {
background: color-mix(in srgb, var(--scs-accent) 18%, transparent);
}
.scs-rowline {
display: flex;
align-items: center;
gap: var(--space-1, 1.6cqmin);
}
.scs-dot {
flex: 0 0 auto;
width: 1.5cqmin;
height: 1.5cqmin;
border-radius: 50%;
background: color-mix(in srgb, var(--fg, #f8fafc) 22%, transparent);
}
.scs-rowline:nth-of-type(2) .scs-dot {
background: color-mix(in srgb, var(--scs-accent) 70%, transparent);
}
.scs-rowline .scs-bar {
flex: 1;
max-width: 72%;
}
.scs-section[data-close] .scs-card {
align-items: center;
text-align: center;
}
.scs-section[data-close] .scs-bar.scs-heading {
width: 52%;
}
.scs-section[data-close] .scs-bar.scs-sub {
width: 34%;
}
.scs-pill {
margin-top: 1.2cqmin;
padding: 1.4cqmin 3.4cqmin;
border-radius: 999px;
background: color-mix(in srgb, var(--scs-accent) 82%, var(--surface, #0b1016));
color: var(--bg, #0b0c0e);
font-family: var(--font-mono, ui-monospace, "SF Mono", Menlo, Consolas, monospace);
font-size: 2.1cqmin;
font-weight: 600;
letter-spacing: 0.12em;
line-height: 1;
}
</style>
<div
id="scroll-camera-story-clip"
class="scs-clip clip"
data-start="0"
data-duration="5.5"
data-track-index="0"
>
<div class="scs-stage" role="img" aria-label="Cinematic scroll pass over a tall scene">
<div class="scs-world">
<div class="scs-layer scs-far" aria-hidden="true">
<span class="scs-blob"></span>
<span class="scs-blob"></span>
<span class="scs-blob"></span>
<span class="scs-blob"></span>
</div>
<div class="scs-layer scs-mid" aria-hidden="true">
<span class="scs-ring"></span>
<span class="scs-ring"></span>
<span class="scs-ring"></span>
<span class="scs-rule"></span>
<span class="scs-rule"></span>
<span class="scs-plus"></span>
<span class="scs-plus"></span>
<span class="scs-plus"></span>
</div>
<div class="scs-layer scs-content">
<div class="scs-section" aria-hidden="true">
<div class="scs-card">
<div class="scs-chiprow">
<span class="scs-chip">01</span>
<span class="scs-chiprule"></span>
</div>
<span class="scs-bar scs-heading"></span>
<span class="scs-bar" style="width: 74%"></span>
<span class="scs-bar scs-sub"></span>
</div>
</div>
<div class="scs-section" aria-hidden="true">
<div class="scs-card">
<div class="scs-chiprow">
<span class="scs-chip">02</span>
<span class="scs-chiprule"></span>
</div>
<span class="scs-bar scs-heading" style="width: 46%"></span>
<div class="scs-minis">
<div class="scs-mini">
<span class="scs-bar"></span>
<span class="scs-mini-block"></span>
</div>
<div class="scs-mini">
<span class="scs-bar"></span>
<span class="scs-mini-block"></span>
</div>
<div class="scs-mini">
<span class="scs-bar"></span>
<span class="scs-mini-block"></span>
</div>
</div>
</div>
</div>
<div class="scs-section" aria-hidden="true">
<div class="scs-card">
<div class="scs-chiprow">
<span class="scs-chip">03</span>
<span class="scs-chiprule"></span>
</div>
<span class="scs-bar scs-heading" style="width: 40%"></span>
<div class="scs-rowline">
<span class="scs-dot"></span>
<span class="scs-bar"></span>
</div>
<div class="scs-rowline">
<span class="scs-dot"></span>
<span class="scs-bar" style="max-width: 58%"></span>
</div>
<div class="scs-rowline">
<span class="scs-dot"></span>
<span class="scs-bar" style="max-width: 66%"></span>
</div>
</div>
</div>
<div class="scs-section" data-close aria-hidden="true">
<div class="scs-card">
<div class="scs-chiprow" style="align-self: stretch">
<span class="scs-chip">04</span>
<span class="scs-chiprule"></span>
</div>
<span class="scs-bar scs-heading"></span>
<span class="scs-bar scs-sub"></span>
<span class="scs-pill">&gt;_</span>
</div>
</div>
</div>
<div class="scs-layer scs-fore" aria-hidden="true">
<span class="scs-mote"></span>
<span class="scs-mote"></span>
<span class="scs-mote"></span>
<span class="scs-mote"></span>
<span class="scs-mote"></span>
</div>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/gsap@3.14.2/dist/gsap.min.js"></script>
<script>
(function () {
"use strict";
var root = document.getElementById("root");
var stage = root.querySelector(".scs-stage");
var world = root.querySelector(".scs-world");
var layerFar = root.querySelector(".scs-far");
var layerMid = root.querySelector(".scs-mid");
var layerFore = root.querySelector(".scs-fore");
var sectionElements = Array.prototype.slice.call(root.querySelectorAll(".scs-section"));
var vars =
window.__hyperframes && window.__hyperframes.getVariables
? window.__hyperframes.getVariables()
: {};
function num(value, fallback, min, max) {
var parsed = parseFloat(value);
if (!isFinite(parsed)) parsed = fallback;
return Math.min(max, Math.max(min, parsed));
}
var travel = num(vars.travel, 220, 100, 400);
var sectionsVar = Math.round(num(vars.sections, 3, 2, 4));
// Each enum choice routes to a DIFFERENT contract token so the
// variable stays meaningful under a theme.
var accentColors = {
green: "var(--brand, #71f5a7)",
blue: "var(--accent, #61a8ff)",
violet: "var(--accent-2, #c5a3ff)",
};
var accent = Object.prototype.hasOwnProperty.call(accentColors, vars.accent)
? vars.accent
: "green";
var exitMode = vars.exit === "fade" || vars.exit === "up" ? vars.exit : "none";
root.style.setProperty("--scs-accent", accentColors[accent]);
// SLOT. Caller templates live at HOST DOCUMENT level (the mount
// wipes host-clip children, and templates never render). Each
// direct child of the slot template becomes one section's card
// content, in order.
var hostDoc = root.ownerDocument;
var slotChildren = [];
try {
var slotTemplate = hostDoc.querySelector(
'template[data-slot="scroll-camera-story-sections"]',
);
if (slotTemplate)
slotChildren = Array.prototype.slice.call(slotTemplate.content.children);
} catch (error) {
slotChildren = [];
}
var count = Math.min(4, Math.max(2, slotChildren.length || sectionsVar));
sectionElements.forEach(function (section, index) {
if (index >= count) {
section.remove();
return;
}
if (slotChildren[index]) {
var card = section.querySelector(".scs-card");
while (card.firstChild) card.removeChild(card.firstChild);
card.appendChild(hostDoc.importNode(slotChildren[index], true));
}
});
var sections = sectionElements.slice(0, count);
var cards = sections.map(function (section) {
return section.querySelector(".scs-card");
});
// World geometry, set ONCE at mount in cqh (static style, never
// tweened; the seek trap is cq units INSIDE tweens). Section i
// centers at camera progress i / (count - 1) along the travel.
world.style.height = (100 + travel).toFixed(2) + "cqh";
sections.forEach(function (section, index) {
var progress = index / (count - 1);
section.style.top = (50 + progress * travel - 42).toFixed(2) + "cqh";
});
/* ===== Camera (camera-servo law): one plain state object, one
writer. cam.t is the pass progress 0..1. The world translates
by percent of its OWN height (a pure number: travel out of
100 + travel), and each depth layer gets a derived parallax
offset so its net rate is RATE x the camera rate. No cq units
are ever tweened. ===== */
var F = (100 * travel) / (100 + travel); // percent of world height per full pass
var RATE_FAR = 0.35;
var RATE_MID = 0.65;
var RATE_FORE = 1.12;
var cam = { t: 0 };
var drift = { p: 0, dx: 0, dy: 0 };
function applyCamera() {
var y = -cam.t * F;
world.style.transform = "translate(" + drift.dx + "%, " + (y + drift.dy) + "%)";
layerFar.style.transform = "translateY(" + cam.t * F * (1 - RATE_FAR) + "%)";
layerMid.style.transform = "translateY(" + cam.t * F * (1 - RATE_MID) + "%)";
layerFore.style.transform = "translateY(" + cam.t * F * (1 - RATE_FORE) + "%)";
}
applyCamera();
// Envelope: fixed IN/OUT, elastic HOLD, never time-scaled.
var IN_BASE = 0.85;
var OUT_BASE = exitMode === "none" ? 0 : 0.5;
var PASS_MIN = 1.2;
var duration = Math.max(0.001, parseFloat(root.dataset.duration || "5.5"));
var totalBase = IN_BASE + PASS_MIN + OUT_BASE;
var scale = duration < totalBase ? duration / totalBase : 1;
var IN = IN_BASE * scale;
var OUT = OUT_BASE * scale;
var usable = duration - OUT;
// Arrival schedule: defaults decelerate into a held final
// section; the cues variable overrides arrivals for sections
// after the first.
var HOLD_MIN = Math.min(1.3, Math.max(0.45, usable * 0.24));
var lastDefault = Math.max(IN + 0.9 * scale, usable - HOLD_MIN);
var firstDefault = Math.min(lastDefault, IN + 1.15 * scale);
var arrivals = [];
var index;
for (index = 1; index < count; index += 1) {
arrivals.push(
count === 2
? lastDefault
: firstDefault + ((index - 1) / (count - 2)) * (lastDefault - firstDefault),
);
}
var cueValues = String(vars.cues == null ? "" : vars.cues)
.split(",")
.map(function (part) {
return parseFloat(part);
})
.filter(function (value) {
return isFinite(value);
});
// Lenient by one: a list with an extra leading value is treated
// as including the mount section's arrival.
if (cueValues.length === count) cueValues = cueValues.slice(1);
if (cueValues.length >= count - 1) {
arrivals = cueValues.slice(0, count - 1);
}
var floor = IN + 0.35 * scale;
for (index = 0; index < arrivals.length; index += 1) {
var clamped = Math.min(usable - 0.3 * scale, Math.max(floor, arrivals[index]));
arrivals[index] = clamped;
floor = clamped + 0.4 * scale;
}
var lastArrival = arrivals.length > 0 ? arrivals[arrivals.length - 1] : IN;
var tl = gsap.timeline({ paused: true });
// IN: the stage fades up while the first section rises.
tl.fromTo(
stage,
{ opacity: 0 },
{ opacity: 1, duration: Math.min(0.6 * scale, IN), ease: "power2.out" },
0,
);
// Section rises: each card lands exactly on its arrival cue.
// yPercent only (percent of the card's own box), never cq units.
cards.forEach(function (card, cardIndex) {
var arrive = cardIndex === 0 ? IN : arrivals[cardIndex - 1];
var rise = Math.min(
0.75 * scale,
Math.max(0.25, arrive - (cardIndex === 0 ? 0.1 : 0)),
);
tl.fromTo(
card,
{ opacity: 0, yPercent: 10 },
{ opacity: 1, yPercent: 0, duration: rise, ease: "power3.out" },
arrive - rise,
);
});
// Camera pass: one non-overlapping segment per arrival, quiet
// register (L2). Each move ends exactly on its cue; the final
// move runs longer, so the pass decelerates into the hold. No
// segment starts before the previous ends (L1: no mid-motion
// redirect exists to snap velocity).
var previousEnd = IN * 0.7;
arrivals.forEach(function (arrive, arriveIndex) {
var isLast = arriveIndex === arrivals.length - 1;
var gap = arrive - previousEnd - 0.1 * scale;
var move = Math.max(0.3, Math.min(isLast ? 1.7 : 1.25, gap));
tl.to(
cam,
{
t: (arriveIndex + 1) / (count - 1),
duration: move,
ease: "power2.inOut",
onUpdate: applyCamera,
},
arrive - move,
);
previousEnd = arrive;
});
// Micro-drift: 2 and 3 INTEGER sine cycles ending at exactly
// zero when the final section lands, so the held final section
// is byte-still and every seek reproduces the same frame.
if (lastArrival >= 1.2) {
tl.to(
drift,
{
p: Math.PI * 2 * 2,
duration: lastArrival,
ease: "none",
onUpdate: function () {
drift.dx = Math.sin(drift.p) * 0.06;
drift.dy = Math.sin(drift.p * 1.5) * 0.08;
applyCamera();
},
},
0,
);
}
// OUT: only when exit != none; the default holds the last frame.
if (exitMode !== "none") {
var outStart = duration - OUT;
tl.to(stage, { opacity: 0, duration: OUT, ease: "power2.in" }, outStart);
if (exitMode === "up") {
tl.to(stage, { yPercent: -4, duration: OUT, ease: "power2.in" }, outStart);
}
}
tl.seek(0);
window.__timelines = window.__timelines || {};
window.__timelines["scroll-camera-story"] = tl;
})();
</script>
</div>
</template>
</body>
</html>
```
</Accordion>
{/* hf:generated-footer */}
Tagged `camera` `scroll` `parallax` `story` `sections` `slot` `servo`.
## Related topics
- [Browse the complete Catalog](/catalog)
- [Add assets and Catalog items in Studio](/studio/assets-and-blocks)
- [Build a richer composition](/go-further)