mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-09-01 19:42:03 +00:00
* 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>
695 lines
31 KiB
Plaintext
695 lines
31 KiB
Plaintext
---
|
|
title: "Line Swap"
|
|
description: "A masked full-line beat replacement: line A holds center then exits up through an overflow-hidden mask as line B enters bottom-up on the same beat, with an optional accent underline drawing beneath one word of line B."
|
|
---
|
|
|
|
import { InstallCommand } from "/snippets/install-command.jsx";
|
|
import { VariablesExplorer } from "/snippets/variables-explorer.jsx";
|
|
|
|
<VariablesExplorer
|
|
previewSrc="/public/catalog/components/line-swap.json"
|
|
compositionId="line-swap"
|
|
compositionSrc="compositions/components/line-swap.html"
|
|
variables={[{"id":"line_a","type":"string","role":"content","label":"Line A","description":"First line; holds center inside the mask, then exits up on the swap beat.","default":"Everyone promised you AI."},{"id":"line_b","type":"string","role":"content","label":"Line B","description":"Replacement line; enters bottom-up on the swap beat and holds.","default":"Almost nobody promised you control."},{"id":"swap_at","type":"number","role":"timing","label":"Swap at","description":"Second (from mount start) of the beat replacement. Clamped so the swap and underline complete before any exit.","default":1.5,"min":0,"step":0.1,"unit":"s"},{"id":"underline_word","type":"string","role":"content","label":"Underline word","description":"First case-insensitive substring match in line B gets the accent underline after landing. Empty disables it.","default":"control"},{"id":"accent","type":"enum","role":"style","label":"Accent","description":"Underline color from the contract token map.","default":"green","options":[{"value":"green","label":"Green"},{"value":"blue","label":"Blue"},{"value":"violet","label":"Violet"}]},{"id":"exit","type":"enum","role":"timing","label":"Exit","description":"Optional departure. Default none: the landed line holds until the frame cuts.","default":"none","options":[{"value":"none","label":"None"},{"value":"fade","label":"Fade"},{"value":"up","label":"Up"}]}]}
|
|
>
|
|
|
|
```html line-swap.html
|
|
<!doctype html>
|
|
<!--
|
|
line-swap: HyperFrames video primitive (text effects / beat replacement)
|
|
|
|
A masked full-line beat replacement, generalizing flagship frame 01: line_a
|
|
rises into an overflow-hidden mask and holds center, then on the swap beat
|
|
it exits up through the mask as line_b enters bottom-up on the same beat.
|
|
One restrained slam, smooth ease, no overshoot. Optionally an accent
|
|
underline draws left to right beneath underline_word of line_b after it
|
|
lands (scaleX from a left origin, the flagship bar draw).
|
|
|
|
Variables:
|
|
line_a (string): the first line, replaced on the beat.
|
|
line_b (string): the line that lands and holds.
|
|
swap_at (seconds): the beat, relative to mount start. Clamped so line_a
|
|
finishes entering first and line_b plus the underline complete before
|
|
any exit begins.
|
|
underline_word (string): first case-insensitive substring match inside
|
|
line_b gets the underline. Empty or unmatched disables it.
|
|
accent (green | blue | violet): underline color via the contract token map.
|
|
exit (none | fade | up, default none): frame roots own transitions;
|
|
holds end films.
|
|
|
|
Envelope, fixed IN and OUT with elastic HOLD only (never time-scaled):
|
|
IN_A_BASE = 0.50s line_a enters bottom-up through the mask
|
|
SWAP span = 0.72s line_a up-and-out (0.35s) overlapping line_b in
|
|
(starts 0.22s after the beat, lands 0.50s later)
|
|
UL span = 0.60s 0.15s beat after the land, then a 0.45s draw
|
|
(0 when underline_word is empty or unmatched)
|
|
HOLD = max(0, D - phases), completely still
|
|
OUT_BASE = 0s for exit none, otherwise 0.45s
|
|
If D is shorter than the fixed phases, they compress together.
|
|
|
|
Mount contract: the runtime clones only this template. #root fills the host
|
|
box, establishes the container query basis, has no data-width or
|
|
data-height, and registers one paused timeline under the literal
|
|
line-swap key.
|
|
-->
|
|
<html
|
|
lang="en"
|
|
data-composition-id="line-swap"
|
|
data-composition-duration="3.5"
|
|
data-composition-variables='[
|
|
{ "id": "line_a", "type": "string", "role": "content", "label": "Line A", "description": "First line; holds center inside the mask, then exits up on the swap beat.", "default": "Everyone promised you AI." },
|
|
{ "id": "line_b", "type": "string", "role": "content", "label": "Line B", "description": "Replacement line; enters bottom-up on the swap beat and holds.", "default": "Almost nobody promised you control." },
|
|
{ "id": "swap_at", "type": "number", "role": "timing", "label": "Swap at", "description": "Second (from mount start) of the beat replacement. Clamped so the swap and underline complete before any exit.", "default": 1.5, "min": 0, "step": 0.1, "unit": "s" },
|
|
{ "id": "underline_word", "type": "string", "role": "content", "label": "Underline word", "description": "First case-insensitive substring match in line B gets the accent underline after landing. Empty disables it.", "default": "control" },
|
|
{ "id": "accent", "type": "enum", "role": "style", "label": "Accent", "description": "Underline color from the contract token map.", "default": "green", "options": [{ "value": "green", "label": "Green" }, { "value": "blue", "label": "Blue" }, { "value": "violet", "label": "Violet" }] },
|
|
{ "id": "exit", "type": "enum", "role": "timing", "label": "Exit", "description": "Optional departure. Default none: the landed line holds until the frame cuts.", "default": "none", "options": [{ "value": "none", "label": "None" }, { "value": "fade", "label": "Fade" }, { "value": "up", "label": "Up" }] }
|
|
]'
|
|
>
|
|
<head>
|
|
<meta charset="UTF-8" />
|
|
<title>Line Swap</title>
|
|
</head>
|
|
<body>
|
|
<template>
|
|
<div id="root" data-composition-id="line-swap" data-duration="3.5" data-fps="30">
|
|
<style>
|
|
*,
|
|
*::before,
|
|
*::after {
|
|
box-sizing: border-box;
|
|
}
|
|
|
|
#root {
|
|
position: absolute;
|
|
inset: 0;
|
|
overflow: hidden;
|
|
container-type: size;
|
|
isolation: isolate;
|
|
background: var(--bg, #0b0c0e);
|
|
color: var(--fg, #f8fafc);
|
|
font-family: var(--font-display, Inter, system-ui, sans-serif);
|
|
pointer-events: none;
|
|
}
|
|
|
|
.ls-clip {
|
|
position: absolute;
|
|
inset: 0;
|
|
display: grid;
|
|
place-items: center;
|
|
overflow: hidden;
|
|
}
|
|
|
|
.ls-stage {
|
|
width: 94cqw;
|
|
will-change: transform, opacity;
|
|
}
|
|
|
|
/* Beat mask: both lines live inside; the swap slides through it. */
|
|
.ls-mask {
|
|
position: relative;
|
|
width: 100%;
|
|
height: calc(var(--ls-font-size, min(7cqw, 16cqh)) * 1.42);
|
|
overflow: hidden;
|
|
}
|
|
|
|
.ls-line {
|
|
position: absolute;
|
|
inset: 0;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
font-size: var(--ls-font-size, min(7cqw, 16cqh));
|
|
font-weight: 600;
|
|
line-height: 1;
|
|
letter-spacing: -0.02em;
|
|
white-space: nowrap;
|
|
will-change: transform;
|
|
}
|
|
|
|
/* One inline wrapper per line: a bare text node next to the
|
|
underline span would become separate flex items and the boundary
|
|
space would collapse ("youcontrol."). */
|
|
.ls-line-inner {
|
|
display: inline;
|
|
}
|
|
|
|
.ls-ul-wrap {
|
|
position: relative;
|
|
display: inline-block;
|
|
white-space: nowrap;
|
|
}
|
|
|
|
.ls-underline {
|
|
position: absolute;
|
|
left: 0.02em;
|
|
right: 0.02em;
|
|
bottom: -0.14em;
|
|
height: 0.055em;
|
|
border-radius: 0.03em;
|
|
transform-origin: left center;
|
|
}
|
|
</style>
|
|
|
|
<div
|
|
id="line-swap-clip"
|
|
class="ls-clip clip"
|
|
data-start="0"
|
|
data-duration="3.5"
|
|
data-track-index="0"
|
|
>
|
|
<div class="ls-stage" role="img">
|
|
<div class="ls-mask">
|
|
<div class="ls-line ls-line-a"><span class="ls-line-inner"></span></div>
|
|
<div class="ls-line ls-line-b"><span class="ls-line-inner"></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");
|
|
// Literal key: the flattening step strips data-composition-id off
|
|
// the mounted root, so reading it back would register "null".
|
|
var compositionId = "line-swap";
|
|
var stage = root.querySelector(".ls-stage");
|
|
var lineAEl = root.querySelector(".ls-line-a");
|
|
var lineBEl = root.querySelector(".ls-line-b");
|
|
var lineAInner = lineAEl.querySelector(".ls-line-inner");
|
|
var lineBInner = lineBEl.querySelector(".ls-line-inner");
|
|
var vars =
|
|
window.__hyperframes && window.__hyperframes.getVariables
|
|
? window.__hyperframes.getVariables()
|
|
: {};
|
|
|
|
function asLine(value, fallback) {
|
|
return value == null ? fallback : String(value).trim().replace(/\s+/g, " ");
|
|
}
|
|
var lineA = asLine(vars.line_a, "Everyone promised you AI.");
|
|
var lineB = asLine(vars.line_b, "Almost nobody promised you control.");
|
|
var underlineWord = asLine(vars.underline_word, "control");
|
|
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 exit = vars.exit === "fade" || vars.exit === "up" ? vars.exit : "none";
|
|
|
|
lineAInner.textContent = lineA;
|
|
|
|
// Split line_b around the first case-insensitive underline match.
|
|
// textContent nodes only, never innerHTML.
|
|
var matchIndex =
|
|
underlineWord.length > 0
|
|
? lineB.toLowerCase().indexOf(underlineWord.toLowerCase())
|
|
: -1;
|
|
var underlineEl = null;
|
|
if (matchIndex >= 0) {
|
|
var before = lineB.slice(0, matchIndex);
|
|
var matched = lineB.slice(matchIndex, matchIndex + underlineWord.length);
|
|
var after = lineB.slice(matchIndex + underlineWord.length);
|
|
if (before) lineBInner.appendChild(document.createTextNode(before));
|
|
|
|
var wrap = document.createElement("span");
|
|
wrap.className = "ls-ul-wrap";
|
|
wrap.appendChild(document.createTextNode(matched));
|
|
underlineEl = document.createElement("span");
|
|
underlineEl.className = "ls-underline";
|
|
underlineEl.setAttribute("aria-hidden", "true");
|
|
// style.background, not a class: var() resolves at point of use.
|
|
underlineEl.style.background = accentColors[accent];
|
|
wrap.appendChild(underlineEl);
|
|
lineBInner.appendChild(wrap);
|
|
if (after) lineBInner.appendChild(document.createTextNode(after));
|
|
} else {
|
|
lineBInner.textContent = lineB;
|
|
}
|
|
stage.setAttribute("aria-label", lineA + " " + lineB);
|
|
|
|
// Deterministic character-count fit against the longer line; both
|
|
// lines are nowrap, so the fit keeps them inside the stage.
|
|
var characters = Math.max(1, Array.from(lineA).length, Array.from(lineB).length);
|
|
var fitted = Math.max(3.4, Math.min(9, 168 / characters));
|
|
root.style.setProperty("--ls-font-size", "min(" + fitted.toFixed(3) + "cqw, 16cqh)");
|
|
|
|
// RETIME RANGE: fixed phases; HOLD is the only elastic span.
|
|
var IN_A_BASE = 0.5;
|
|
var EXIT_A_BASE = 0.35;
|
|
var LAG_BASE = 0.22; // line_b starts this long after the beat
|
|
var IN_B_BASE = 0.5;
|
|
var UL_BEAT_BASE = 0.15;
|
|
var UL_BASE = underlineEl ? 0.45 : 0;
|
|
var OUT_BASE = exit === "none" ? 0 : 0.45;
|
|
var duration = Math.max(0.001, parseFloat(root.dataset.duration || "3.5"));
|
|
var swapSpanBase = LAG_BASE + IN_B_BASE;
|
|
var ulSpanBase = underlineEl ? UL_BEAT_BASE + UL_BASE : 0;
|
|
var totalBase = IN_A_BASE + swapSpanBase + ulSpanBase + OUT_BASE;
|
|
var scale = duration < totalBase ? duration / totalBase : 1;
|
|
var IN_A = IN_A_BASE * scale;
|
|
var EXIT_A = EXIT_A_BASE * scale;
|
|
var LAG = LAG_BASE * scale;
|
|
var IN_B = IN_B_BASE * scale;
|
|
var UL_BEAT = UL_BEAT_BASE * scale;
|
|
var UL = UL_BASE * scale;
|
|
var OUT = OUT_BASE * scale;
|
|
var OUT_START = duration - OUT;
|
|
|
|
var swapAtRaw = Number(vars.swap_at);
|
|
var swapAt = Number.isFinite(swapAtRaw) ? Math.max(0, swapAtRaw) : 1.5;
|
|
// line_a fully arrives before the beat; the swap and the
|
|
// underline always complete before the exit begins.
|
|
swapAt = Math.min(swapAt, Math.max(IN_A, OUT_START - (LAG + IN_B + UL_BEAT + UL)));
|
|
swapAt = Math.max(swapAt, IN_A);
|
|
var landB = swapAt + LAG + IN_B;
|
|
|
|
gsap.set(lineBEl, { yPercent: 115 });
|
|
if (underlineEl) gsap.set(underlineEl, { scaleX: 0 });
|
|
|
|
var tl = gsap.timeline({ paused: true });
|
|
|
|
// IN: line_a enters bottom-up through the mask. One move.
|
|
tl.fromTo(
|
|
lineAEl,
|
|
{ yPercent: 115 },
|
|
{ yPercent: 0, duration: IN_A, ease: "power4.out" },
|
|
0,
|
|
);
|
|
|
|
// SWAP: the beat replacement. line_a exits up through the mask as
|
|
// line_b slides in bottom-up. Single restrained slam, smooth ease.
|
|
tl.fromTo(
|
|
lineAEl,
|
|
{ yPercent: 0 },
|
|
{ yPercent: -115, duration: EXIT_A, ease: "power2.in", immediateRender: false },
|
|
swapAt,
|
|
);
|
|
tl.fromTo(
|
|
lineBEl,
|
|
{ yPercent: 115 },
|
|
{ yPercent: 0, duration: IN_B, ease: "power4.out" },
|
|
swapAt + LAG,
|
|
);
|
|
|
|
// UNDERLINE: accent bar draws left to right after line_b lands.
|
|
if (underlineEl) {
|
|
tl.fromTo(
|
|
underlineEl,
|
|
{ scaleX: 0 },
|
|
{ scaleX: 1, duration: UL, ease: "power2.out" },
|
|
landB + UL_BEAT,
|
|
);
|
|
}
|
|
|
|
// HOLD: completely still.
|
|
|
|
// OUT: optional departure; exit none holds until the frame cuts.
|
|
if (exit === "fade") {
|
|
tl.to(stage, { opacity: 0, duration: OUT, ease: "power2.in" }, OUT_START);
|
|
} else if (exit === "up") {
|
|
tl.to(stage, { opacity: 0, y: "-7cqh", duration: OUT, ease: "power2.in" }, OUT_START);
|
|
}
|
|
|
|
tl.seek(0);
|
|
window.__timelines = window.__timelines || {};
|
|
window.__timelines[compositionId] = tl;
|
|
})();
|
|
</script>
|
|
</div>
|
|
</template>
|
|
</body>
|
|
</html>
|
|
```
|
|
|
|
</VariablesExplorer>
|
|
|
|
## Install
|
|
|
|
<InstallCommand command="npx hyperframes add line-swap" item="line-swap" />
|
|
|
|
That writes one file: `compositions/components/line-swap.html`.
|
|
|
|
## Paste it into your composition
|
|
|
|
Open `compositions/components/line-swap.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 |
|
|
| --- | --- | --- | --- |
|
|
| `line_a` | `Everyone promised you AI.` | string | First line; holds center inside the mask, then exits up on the swap beat. |
|
|
| `line_b` | `Almost nobody promised you control.` | string | Replacement line; enters bottom-up on the swap beat and holds. |
|
|
| `swap_at` | `1.5` | number | Second (from mount start) of the beat replacement. Clamped so the swap and underline complete before any exit. |
|
|
| `underline_word` | `control` | string | First case-insensitive substring match in line B gets the accent underline after landing. Empty disables it. |
|
|
| `accent` | `green` | `green`, `blue`, `violet` | Underline color from the contract token map. |
|
|
| `exit` | `none` | `none`, `fade`, `up` | Optional departure. Default none: the landed line holds until the frame cuts. |
|
|
|
|
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="line-swap"
|
|
data-composition-src="compositions/components/line-swap.html"
|
|
data-variable-values='{"line_a":"Everyone promised you AI.","line_b":"Almost nobody promised you control.","swap_at":1.5,"underline_word":"control","accent":"green","exit":"none"}'
|
|
></div>
|
|
```
|
|
|
|
## Source
|
|
|
|
<Accordion title={`line-swap.html`}>
|
|
|
|
```html
|
|
<!doctype html>
|
|
<!--
|
|
line-swap: HyperFrames video primitive (text effects / beat replacement)
|
|
|
|
A masked full-line beat replacement, generalizing flagship frame 01: line_a
|
|
rises into an overflow-hidden mask and holds center, then on the swap beat
|
|
it exits up through the mask as line_b enters bottom-up on the same beat.
|
|
One restrained slam, smooth ease, no overshoot. Optionally an accent
|
|
underline draws left to right beneath underline_word of line_b after it
|
|
lands (scaleX from a left origin, the flagship bar draw).
|
|
|
|
Variables:
|
|
line_a (string): the first line, replaced on the beat.
|
|
line_b (string): the line that lands and holds.
|
|
swap_at (seconds): the beat, relative to mount start. Clamped so line_a
|
|
finishes entering first and line_b plus the underline complete before
|
|
any exit begins.
|
|
underline_word (string): first case-insensitive substring match inside
|
|
line_b gets the underline. Empty or unmatched disables it.
|
|
accent (green | blue | violet): underline color via the contract token map.
|
|
exit (none | fade | up, default none): frame roots own transitions;
|
|
holds end films.
|
|
|
|
Envelope, fixed IN and OUT with elastic HOLD only (never time-scaled):
|
|
IN_A_BASE = 0.50s line_a enters bottom-up through the mask
|
|
SWAP span = 0.72s line_a up-and-out (0.35s) overlapping line_b in
|
|
(starts 0.22s after the beat, lands 0.50s later)
|
|
UL span = 0.60s 0.15s beat after the land, then a 0.45s draw
|
|
(0 when underline_word is empty or unmatched)
|
|
HOLD = max(0, D - phases), completely still
|
|
OUT_BASE = 0s for exit none, otherwise 0.45s
|
|
If D is shorter than the fixed phases, they compress together.
|
|
|
|
Mount contract: the runtime clones only this template. #root fills the host
|
|
box, establishes the container query basis, has no data-width or
|
|
data-height, and registers one paused timeline under the literal
|
|
line-swap key.
|
|
-->
|
|
<html
|
|
lang="en"
|
|
data-composition-id="line-swap"
|
|
data-composition-duration="3.5"
|
|
data-composition-variables='[
|
|
{ "id": "line_a", "type": "string", "role": "content", "label": "Line A", "description": "First line; holds center inside the mask, then exits up on the swap beat.", "default": "Everyone promised you AI." },
|
|
{ "id": "line_b", "type": "string", "role": "content", "label": "Line B", "description": "Replacement line; enters bottom-up on the swap beat and holds.", "default": "Almost nobody promised you control." },
|
|
{ "id": "swap_at", "type": "number", "role": "timing", "label": "Swap at", "description": "Second (from mount start) of the beat replacement. Clamped so the swap and underline complete before any exit.", "default": 1.5, "min": 0, "step": 0.1, "unit": "s" },
|
|
{ "id": "underline_word", "type": "string", "role": "content", "label": "Underline word", "description": "First case-insensitive substring match in line B gets the accent underline after landing. Empty disables it.", "default": "control" },
|
|
{ "id": "accent", "type": "enum", "role": "style", "label": "Accent", "description": "Underline color from the contract token map.", "default": "green", "options": [{ "value": "green", "label": "Green" }, { "value": "blue", "label": "Blue" }, { "value": "violet", "label": "Violet" }] },
|
|
{ "id": "exit", "type": "enum", "role": "timing", "label": "Exit", "description": "Optional departure. Default none: the landed line holds until the frame cuts.", "default": "none", "options": [{ "value": "none", "label": "None" }, { "value": "fade", "label": "Fade" }, { "value": "up", "label": "Up" }] }
|
|
]'
|
|
>
|
|
<head>
|
|
<meta charset="UTF-8" />
|
|
<title>Line Swap</title>
|
|
</head>
|
|
<body>
|
|
<template>
|
|
<div id="root" data-composition-id="line-swap" data-duration="3.5" data-fps="30">
|
|
<style>
|
|
*,
|
|
*::before,
|
|
*::after {
|
|
box-sizing: border-box;
|
|
}
|
|
|
|
#root {
|
|
position: absolute;
|
|
inset: 0;
|
|
overflow: hidden;
|
|
container-type: size;
|
|
isolation: isolate;
|
|
background: var(--bg, #0b0c0e);
|
|
color: var(--fg, #f8fafc);
|
|
font-family: var(--font-display, Inter, system-ui, sans-serif);
|
|
pointer-events: none;
|
|
}
|
|
|
|
.ls-clip {
|
|
position: absolute;
|
|
inset: 0;
|
|
display: grid;
|
|
place-items: center;
|
|
overflow: hidden;
|
|
}
|
|
|
|
.ls-stage {
|
|
width: 94cqw;
|
|
will-change: transform, opacity;
|
|
}
|
|
|
|
/* Beat mask: both lines live inside; the swap slides through it. */
|
|
.ls-mask {
|
|
position: relative;
|
|
width: 100%;
|
|
height: calc(var(--ls-font-size, min(7cqw, 16cqh)) * 1.42);
|
|
overflow: hidden;
|
|
}
|
|
|
|
.ls-line {
|
|
position: absolute;
|
|
inset: 0;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
font-size: var(--ls-font-size, min(7cqw, 16cqh));
|
|
font-weight: 600;
|
|
line-height: 1;
|
|
letter-spacing: -0.02em;
|
|
white-space: nowrap;
|
|
will-change: transform;
|
|
}
|
|
|
|
/* One inline wrapper per line: a bare text node next to the
|
|
underline span would become separate flex items and the boundary
|
|
space would collapse ("youcontrol."). */
|
|
.ls-line-inner {
|
|
display: inline;
|
|
}
|
|
|
|
.ls-ul-wrap {
|
|
position: relative;
|
|
display: inline-block;
|
|
white-space: nowrap;
|
|
}
|
|
|
|
.ls-underline {
|
|
position: absolute;
|
|
left: 0.02em;
|
|
right: 0.02em;
|
|
bottom: -0.14em;
|
|
height: 0.055em;
|
|
border-radius: 0.03em;
|
|
transform-origin: left center;
|
|
}
|
|
</style>
|
|
|
|
<div
|
|
id="line-swap-clip"
|
|
class="ls-clip clip"
|
|
data-start="0"
|
|
data-duration="3.5"
|
|
data-track-index="0"
|
|
>
|
|
<div class="ls-stage" role="img">
|
|
<div class="ls-mask">
|
|
<div class="ls-line ls-line-a"><span class="ls-line-inner"></span></div>
|
|
<div class="ls-line ls-line-b"><span class="ls-line-inner"></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");
|
|
// Literal key: the flattening step strips data-composition-id off
|
|
// the mounted root, so reading it back would register "null".
|
|
var compositionId = "line-swap";
|
|
var stage = root.querySelector(".ls-stage");
|
|
var lineAEl = root.querySelector(".ls-line-a");
|
|
var lineBEl = root.querySelector(".ls-line-b");
|
|
var lineAInner = lineAEl.querySelector(".ls-line-inner");
|
|
var lineBInner = lineBEl.querySelector(".ls-line-inner");
|
|
var vars =
|
|
window.__hyperframes && window.__hyperframes.getVariables
|
|
? window.__hyperframes.getVariables()
|
|
: {};
|
|
|
|
function asLine(value, fallback) {
|
|
return value == null ? fallback : String(value).trim().replace(/\s+/g, " ");
|
|
}
|
|
var lineA = asLine(vars.line_a, "Everyone promised you AI.");
|
|
var lineB = asLine(vars.line_b, "Almost nobody promised you control.");
|
|
var underlineWord = asLine(vars.underline_word, "control");
|
|
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 exit = vars.exit === "fade" || vars.exit === "up" ? vars.exit : "none";
|
|
|
|
lineAInner.textContent = lineA;
|
|
|
|
// Split line_b around the first case-insensitive underline match.
|
|
// textContent nodes only, never innerHTML.
|
|
var matchIndex =
|
|
underlineWord.length > 0
|
|
? lineB.toLowerCase().indexOf(underlineWord.toLowerCase())
|
|
: -1;
|
|
var underlineEl = null;
|
|
if (matchIndex >= 0) {
|
|
var before = lineB.slice(0, matchIndex);
|
|
var matched = lineB.slice(matchIndex, matchIndex + underlineWord.length);
|
|
var after = lineB.slice(matchIndex + underlineWord.length);
|
|
if (before) lineBInner.appendChild(document.createTextNode(before));
|
|
|
|
var wrap = document.createElement("span");
|
|
wrap.className = "ls-ul-wrap";
|
|
wrap.appendChild(document.createTextNode(matched));
|
|
underlineEl = document.createElement("span");
|
|
underlineEl.className = "ls-underline";
|
|
underlineEl.setAttribute("aria-hidden", "true");
|
|
// style.background, not a class: var() resolves at point of use.
|
|
underlineEl.style.background = accentColors[accent];
|
|
wrap.appendChild(underlineEl);
|
|
lineBInner.appendChild(wrap);
|
|
if (after) lineBInner.appendChild(document.createTextNode(after));
|
|
} else {
|
|
lineBInner.textContent = lineB;
|
|
}
|
|
stage.setAttribute("aria-label", lineA + " " + lineB);
|
|
|
|
// Deterministic character-count fit against the longer line; both
|
|
// lines are nowrap, so the fit keeps them inside the stage.
|
|
var characters = Math.max(1, Array.from(lineA).length, Array.from(lineB).length);
|
|
var fitted = Math.max(3.4, Math.min(9, 168 / characters));
|
|
root.style.setProperty("--ls-font-size", "min(" + fitted.toFixed(3) + "cqw, 16cqh)");
|
|
|
|
// RETIME RANGE: fixed phases; HOLD is the only elastic span.
|
|
var IN_A_BASE = 0.5;
|
|
var EXIT_A_BASE = 0.35;
|
|
var LAG_BASE = 0.22; // line_b starts this long after the beat
|
|
var IN_B_BASE = 0.5;
|
|
var UL_BEAT_BASE = 0.15;
|
|
var UL_BASE = underlineEl ? 0.45 : 0;
|
|
var OUT_BASE = exit === "none" ? 0 : 0.45;
|
|
var duration = Math.max(0.001, parseFloat(root.dataset.duration || "3.5"));
|
|
var swapSpanBase = LAG_BASE + IN_B_BASE;
|
|
var ulSpanBase = underlineEl ? UL_BEAT_BASE + UL_BASE : 0;
|
|
var totalBase = IN_A_BASE + swapSpanBase + ulSpanBase + OUT_BASE;
|
|
var scale = duration < totalBase ? duration / totalBase : 1;
|
|
var IN_A = IN_A_BASE * scale;
|
|
var EXIT_A = EXIT_A_BASE * scale;
|
|
var LAG = LAG_BASE * scale;
|
|
var IN_B = IN_B_BASE * scale;
|
|
var UL_BEAT = UL_BEAT_BASE * scale;
|
|
var UL = UL_BASE * scale;
|
|
var OUT = OUT_BASE * scale;
|
|
var OUT_START = duration - OUT;
|
|
|
|
var swapAtRaw = Number(vars.swap_at);
|
|
var swapAt = Number.isFinite(swapAtRaw) ? Math.max(0, swapAtRaw) : 1.5;
|
|
// line_a fully arrives before the beat; the swap and the
|
|
// underline always complete before the exit begins.
|
|
swapAt = Math.min(swapAt, Math.max(IN_A, OUT_START - (LAG + IN_B + UL_BEAT + UL)));
|
|
swapAt = Math.max(swapAt, IN_A);
|
|
var landB = swapAt + LAG + IN_B;
|
|
|
|
gsap.set(lineBEl, { yPercent: 115 });
|
|
if (underlineEl) gsap.set(underlineEl, { scaleX: 0 });
|
|
|
|
var tl = gsap.timeline({ paused: true });
|
|
|
|
// IN: line_a enters bottom-up through the mask. One move.
|
|
tl.fromTo(
|
|
lineAEl,
|
|
{ yPercent: 115 },
|
|
{ yPercent: 0, duration: IN_A, ease: "power4.out" },
|
|
0,
|
|
);
|
|
|
|
// SWAP: the beat replacement. line_a exits up through the mask as
|
|
// line_b slides in bottom-up. Single restrained slam, smooth ease.
|
|
tl.fromTo(
|
|
lineAEl,
|
|
{ yPercent: 0 },
|
|
{ yPercent: -115, duration: EXIT_A, ease: "power2.in", immediateRender: false },
|
|
swapAt,
|
|
);
|
|
tl.fromTo(
|
|
lineBEl,
|
|
{ yPercent: 115 },
|
|
{ yPercent: 0, duration: IN_B, ease: "power4.out" },
|
|
swapAt + LAG,
|
|
);
|
|
|
|
// UNDERLINE: accent bar draws left to right after line_b lands.
|
|
if (underlineEl) {
|
|
tl.fromTo(
|
|
underlineEl,
|
|
{ scaleX: 0 },
|
|
{ scaleX: 1, duration: UL, ease: "power2.out" },
|
|
landB + UL_BEAT,
|
|
);
|
|
}
|
|
|
|
// HOLD: completely still.
|
|
|
|
// OUT: optional departure; exit none holds until the frame cuts.
|
|
if (exit === "fade") {
|
|
tl.to(stage, { opacity: 0, duration: OUT, ease: "power2.in" }, OUT_START);
|
|
} else if (exit === "up") {
|
|
tl.to(stage, { opacity: 0, y: "-7cqh", duration: OUT, ease: "power2.in" }, OUT_START);
|
|
}
|
|
|
|
tl.seek(0);
|
|
window.__timelines = window.__timelines || {};
|
|
window.__timelines[compositionId] = tl;
|
|
})();
|
|
</script>
|
|
</div>
|
|
</template>
|
|
</body>
|
|
</html>
|
|
```
|
|
|
|
</Accordion>
|
|
|
|
{/* hf:generated-footer */}
|
|
|
|
Tagged `motion-primitive` `text-effects` `swap` `beat` `deterministic`.
|
|
|
|
## Related topics
|
|
|
|
- [Browse the complete Catalog](/catalog)
|
|
- [Add assets and Catalog items in Studio](/studio/assets-and-blocks)
|
|
- [Build a richer composition](/go-further)
|