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>
1196 lines
51 KiB
Plaintext
1196 lines
51 KiB
Plaintext
---
|
|
title: "Code Terminal Run"
|
|
description: "A token-chrome terminal panel runs one command: the prompt line types deterministically behind an integer-cycle caret, executes after a beat, and output lines print one per cue before a fresh prompt appears."
|
|
---
|
|
|
|
import { InstallCommand } from "/snippets/install-command.jsx";
|
|
import { VariablesExplorer } from "/snippets/variables-explorer.jsx";
|
|
|
|
<VariablesExplorer
|
|
previewSrc="/public/catalog/components/code-terminal-run.json"
|
|
compositionId="code-terminal-run"
|
|
compositionSrc="compositions/components/code-terminal-run.html"
|
|
variables={[{"id":"prompt_glyph","type":"string","role":"style","label":"Prompt glyph","description":"Leading glyph before the command and the trailing prompt. Empty string hides it.","default":"$"},{"id":"cadence","type":"enum","role":"timing","label":"Cadence","description":"Keystroke rhythm: uniform fixed steps or seeded human chunks.","default":"human","options":[{"value":"uniform","label":"Uniform"},{"value":"human","label":"Human"}]},{"id":"cues","type":"string","role":"timing","label":"Cues","description":"Comma-separated seconds relative to mount start; cue N sets when output line N prints. Empty uses the authored rhythm.","default":""},{"id":"accent","type":"enum","role":"style","label":"Accent","description":"Color of the prompt glyph and caret.","default":"green","options":[{"value":"green","label":"Green"},{"value":"blue","label":"Blue"},{"value":"violet","label":"Violet"}]},{"id":"exit","type":"enum","role":"timing","label":"Exit","description":"Outgoing transition. Frame roots own transitions; none holds the end frame.","default":"none","options":[{"value":"none","label":"None"},{"value":"fade","label":"Fade"},{"value":"up","label":"Up"}]}]}
|
|
>
|
|
|
|
```html code-terminal-run.html
|
|
<!doctype html>
|
|
<!--
|
|
code-terminal-run: HyperFrames video primitive (product demo / terminal)
|
|
|
|
A token-chrome terminal panel runs one command: the prompt line types itself
|
|
deterministically (the typed-prompt law: one text-at-time row table built
|
|
synchronously before the timeline registers, an integer-cycle blinking
|
|
caret), the command "executes" after a beat, and output lines print one per
|
|
cue with a leading beat. A fresh prompt line with a solid caret appears once
|
|
the run completes, then the panel holds still.
|
|
|
|
Token coloring is authored, not parsed: the slot content carries plain spans
|
|
(ct-str, ct-flag, ct-path, ct-ok, ct-muted) and CSS routes each class to a
|
|
contract token. Typing preserves those spans by revealing characters across
|
|
the command element's text nodes in document order, so the same character
|
|
count always renders the same colored string in either seek direction.
|
|
|
|
Slot (see README.md for a worked example):
|
|
- [data-slot="content"]: the authored command + output lines. Replace the
|
|
children of this element in your installed copy. It must contain one
|
|
[data-terminal="command"] element (inline spans allowed) and any number
|
|
of [data-terminal="output"] elements, in print order. Default: a generic
|
|
build-tool sample, no product branding.
|
|
|
|
Variables (declared in data-composition-variables below):
|
|
- prompt_glyph (string, default "$"): leading glyph on the command and the
|
|
trailing prompt line; empty string hides it.
|
|
- cadence ("uniform" | "human", default "human"): keystroke rhythm.
|
|
uniform = one character per fixed step; human = seeded 1-3 char chunks
|
|
with varied gaps (fixed LCG seed, fully deterministic).
|
|
- cues (string, default ""): comma-separated seconds relative to mount
|
|
start; cue N sets when output line N prints. Empty = authored rhythm
|
|
(a leading beat after execute, then one line per step).
|
|
- accent (green | blue | violet, default "green"): glyph + caret color.
|
|
- exit ("none" | "fade" | "up", default "none"): frame roots own
|
|
transitions; none holds the end frame.
|
|
|
|
Envelope, authored 5s, fixed IN/OUT with elastic HOLD only (never
|
|
gsap.timeScale()): panel settles over 0.5s, typing runs from 0.4s at its
|
|
natural cadence, execute beat, output prints, trailing prompt; the whole
|
|
schedule compresses proportionally only if it would overflow
|
|
duration - OUT. HOLD absorbs all extra duration (solid caret, barely-there
|
|
drift ending in stillness). OUT exists only when exit != none.
|
|
|
|
Mount contract: mountable sub-composition; the runtime clones only this
|
|
<template>. #root is elastic (no data-width/height, container-type: size),
|
|
styled via #root only, and registers one paused timeline under the literal
|
|
"code-terminal-run" key.
|
|
-->
|
|
<html
|
|
lang="en"
|
|
data-composition-id="code-terminal-run"
|
|
data-composition-duration="5"
|
|
data-composition-variables='[
|
|
{ "id": "prompt_glyph", "type": "string", "role": "style", "label": "Prompt glyph", "description": "Leading glyph before the command and the trailing prompt. Empty string hides it.", "default": "$" },
|
|
{ "id": "cadence", "type": "enum", "role": "timing", "label": "Cadence", "description": "Keystroke rhythm: uniform fixed steps or seeded human chunks.", "default": "human", "options": [{ "value": "uniform", "label": "Uniform" }, { "value": "human", "label": "Human" }] },
|
|
{ "id": "cues", "type": "string", "role": "timing", "label": "Cues", "description": "Comma-separated seconds relative to mount start; cue N sets when output line N prints. Empty uses the authored rhythm.", "default": "" },
|
|
{ "id": "accent", "type": "enum", "role": "style", "label": "Accent", "description": "Color of the prompt glyph and caret.", "default": "green", "options": [{ "value": "green", "label": "Green" }, { "value": "blue", "label": "Blue" }, { "value": "violet", "label": "Violet" }] },
|
|
{ "id": "exit", "type": "enum", "role": "timing", "label": "Exit", "description": "Outgoing transition. Frame roots own transitions; none holds the end frame.", "default": "none", "options": [{ "value": "none", "label": "None" }, { "value": "fade", "label": "Fade" }, { "value": "up", "label": "Up" }] }
|
|
]'
|
|
>
|
|
<head>
|
|
<meta charset="UTF-8" />
|
|
<title>Code Terminal Run</title>
|
|
</head>
|
|
<body>
|
|
<template>
|
|
<div id="root" data-composition-id="code-terminal-run" data-duration="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-mono, ui-monospace, "SF Mono", Menlo, Consolas, monospace);
|
|
pointer-events: none;
|
|
}
|
|
|
|
.ctr-clip {
|
|
position: absolute;
|
|
inset: 0;
|
|
display: grid;
|
|
place-items: center;
|
|
overflow: hidden;
|
|
background: var(--bg, transparent);
|
|
}
|
|
|
|
.ctr-stage {
|
|
width: 84cqw;
|
|
max-width: 84cqw;
|
|
will-change: transform, opacity;
|
|
}
|
|
|
|
.ctr-panel {
|
|
overflow: hidden;
|
|
border: 0.16cqmin solid color-mix(in srgb, var(--border, #475569) 72%, transparent);
|
|
border-radius: var(--radius, 2.4cqmin);
|
|
background: color-mix(in srgb, var(--surface, #0b1016) 96%, var(--ctr-accent));
|
|
box-shadow: 0 3cqh 9cqh color-mix(in srgb, var(--bg, #000000) 38%, transparent);
|
|
}
|
|
|
|
.ctr-bar {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: var(--space-1, 1.2cqw);
|
|
padding: var(--space-1, 1.6cqh) var(--space-2, 2.4cqw);
|
|
border-bottom: 0.14cqmin solid
|
|
color-mix(in srgb, var(--border, #475569) 55%, transparent);
|
|
background: color-mix(in srgb, var(--surface, #0b1016) 88%, var(--bg, #000000));
|
|
}
|
|
|
|
.ctr-dot {
|
|
width: 1.5cqmin;
|
|
aspect-ratio: 1;
|
|
border-radius: 50%;
|
|
background: color-mix(in srgb, var(--muted, #94a3b8) 52%, transparent);
|
|
}
|
|
|
|
.ctr-body {
|
|
padding: var(--space-2, 3cqh) var(--space-2, 3cqw);
|
|
min-height: 40cqh;
|
|
}
|
|
|
|
.ctr-slot {
|
|
display: block;
|
|
}
|
|
|
|
[data-terminal="command"],
|
|
[data-terminal="output"],
|
|
.ctr-tail {
|
|
font-size: var(--ctr-font-size, min(2.6cqw, 5.4cqh));
|
|
font-weight: 500;
|
|
line-height: 1.6;
|
|
white-space: pre-wrap;
|
|
overflow-wrap: anywhere;
|
|
}
|
|
|
|
[data-terminal="command"]::before,
|
|
.ctr-tail::before {
|
|
content: var(--ctr-glyph, "$");
|
|
margin-right: var(--ctr-glyph-gap, 0.9ch);
|
|
color: var(--ctr-accent);
|
|
font-weight: 600;
|
|
}
|
|
|
|
/* Authored token coloring: spans in the slot content, no parser.
|
|
Each class routes to one contract token. */
|
|
.ct-str {
|
|
color: var(--brand, #71f5a7);
|
|
}
|
|
|
|
.ct-flag {
|
|
color: var(--ctr-accent-token, var(--accent, #61a8ff));
|
|
}
|
|
|
|
.ct-path {
|
|
color: var(--accent-2, #c5a3ff);
|
|
}
|
|
|
|
.ct-ok {
|
|
color: var(--brand, #71f5a7);
|
|
font-weight: 600;
|
|
}
|
|
|
|
.ct-muted {
|
|
color: var(--muted, #94a3b8);
|
|
}
|
|
|
|
.ctr-caret {
|
|
display: inline-block;
|
|
width: 0.55ch;
|
|
height: 1.05em;
|
|
margin-left: 0.08ch;
|
|
background: var(--ctr-accent);
|
|
vertical-align: text-bottom;
|
|
will-change: opacity;
|
|
}
|
|
</style>
|
|
|
|
<div
|
|
id="code-terminal-run-clip"
|
|
class="ctr-clip clip"
|
|
data-start="0"
|
|
data-duration="5"
|
|
data-track-index="0"
|
|
>
|
|
<div class="ctr-stage" role="img">
|
|
<div class="ctr-panel">
|
|
<div class="ctr-bar" aria-hidden="true">
|
|
<span class="ctr-dot"></span>
|
|
<span class="ctr-dot"></span>
|
|
<span class="ctr-dot"></span>
|
|
</div>
|
|
<div class="ctr-body">
|
|
<div class="ctr-slot" data-slot="content">
|
|
<!-- SLOT "content": replace the children of this element with
|
|
your own command + output lines. Keep one
|
|
[data-terminal="command"] and any number of
|
|
[data-terminal="output"] elements, in print order. -->
|
|
<div data-terminal="command">
|
|
run build <span class="ct-path">src/app</span>
|
|
<span class="ct-flag">--minify</span> <span class="ct-flag">--out</span>
|
|
<span class="ct-str">"dist/app"</span>
|
|
</div>
|
|
<div data-terminal="output">
|
|
<span class="ct-muted">-</span> resolving 128 modules
|
|
</div>
|
|
<div data-terminal="output">
|
|
<span class="ct-muted">-</span> bundling <span class="ct-path">src/app</span>
|
|
</div>
|
|
<div data-terminal="output">
|
|
<span class="ct-ok">ok</span> 128 modules in 412 ms
|
|
</div>
|
|
<div data-terminal="output">
|
|
<span class="ct-ok">ok</span> wrote <span class="ct-path">dist/app</span>
|
|
<span class="ct-muted">(96 kB)</span>
|
|
</div>
|
|
</div>
|
|
<div class="ctr-tail" aria-hidden="true"><span class="ctr-caret"></span></div>
|
|
</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(".ctr-stage");
|
|
var slot = root.querySelector('[data-slot="content"]');
|
|
var commandElement = slot ? slot.querySelector('[data-terminal="command"]') : null;
|
|
var outputElements = slot
|
|
? Array.prototype.slice.call(slot.querySelectorAll('[data-terminal="output"]'))
|
|
: [];
|
|
var tailElement = root.querySelector(".ctr-tail");
|
|
var vars =
|
|
window.__hyperframes && window.__hyperframes.getVariables
|
|
? window.__hyperframes.getVariables()
|
|
: {};
|
|
|
|
var promptGlyph = vars.prompt_glyph == null ? "$" : String(vars.prompt_glyph);
|
|
var cadence = vars.cadence === "uniform" ? "uniform" : "human";
|
|
var exitMode = vars.exit === "fade" || vars.exit === "up" ? vars.exit : "none";
|
|
|
|
// The runtime mirrors every composition variable as a --<id>
|
|
// custom property (host inline style + a compiled rule), so the
|
|
// accent VARIABLE shadows the --accent contract TOKEN with its
|
|
// enum keyword whenever the caller passes variables. Theme packs
|
|
// re-declare --accent with !important on the same elements and
|
|
// stay clean; only the unthemed mirror leaks through. Detect
|
|
// exactly that leak (the computed token IS an enum keyword) and
|
|
// pin the token's exact contract fallback instead, keeping live
|
|
// var() resolution everywhere else.
|
|
var accentToken = "var(--accent, #61a8ff)";
|
|
var computedAccent = getComputedStyle(root).getPropertyValue("--accent").trim();
|
|
if (
|
|
computedAccent === "green" ||
|
|
computedAccent === "blue" ||
|
|
computedAccent === "violet"
|
|
) {
|
|
accentToken = "#61a8ff";
|
|
}
|
|
root.style.setProperty("--ctr-accent-token", accentToken);
|
|
|
|
// Each enum choice routes to a DIFFERENT contract token so the
|
|
// variable stays meaningful under a theme.
|
|
var accentColors = {
|
|
green: "var(--brand, #71f5a7)",
|
|
blue: accentToken,
|
|
violet: "var(--accent-2, #c5a3ff)",
|
|
};
|
|
var accent = Object.prototype.hasOwnProperty.call(accentColors, vars.accent)
|
|
? vars.accent
|
|
: "green";
|
|
root.style.setProperty("--ctr-accent", accentColors[accent]);
|
|
// JSON.stringify yields a valid CSS quoted string for content:.
|
|
root.style.setProperty("--ctr-glyph", JSON.stringify(promptGlyph));
|
|
if (promptGlyph === "") root.style.setProperty("--ctr-glyph-gap", "0ch");
|
|
|
|
var cueList = String(vars.cues == null ? "" : vars.cues)
|
|
.split(",")
|
|
.map(function (token) {
|
|
return parseFloat(token);
|
|
})
|
|
.filter(function (value) {
|
|
return isFinite(value) && value >= 0;
|
|
})
|
|
.sort(function (a, b) {
|
|
return a - b;
|
|
});
|
|
|
|
var ENTER = 0.5;
|
|
var TYPE_START = 0.4;
|
|
var EXEC_BEAT = 0.22;
|
|
var LEAD_BEAT = 0.3;
|
|
var OUT_STEP = 0.3;
|
|
var TAIL_GAP = 0.35;
|
|
var PRINT = 0.12;
|
|
var OUT_BASE = 0.45;
|
|
var STILLNESS = 0.3;
|
|
var duration = Math.max(0.001, parseFloat(root.dataset.duration || "5"));
|
|
var OUT = exitMode === "none" ? 0 : Math.min(OUT_BASE, duration * 0.2);
|
|
var maxEnd = Math.max(TYPE_START + 0.3, duration - OUT - STILLNESS);
|
|
|
|
// Fixed-seed LCG: the only randomness source, consumed in one
|
|
// deterministic order during this synchronous build.
|
|
var lcgState = 0x51ec0ded;
|
|
function rnd() {
|
|
lcgState = (Math.imul(1664525, lcgState) + 1013904223) >>> 0;
|
|
return lcgState / 4294967296;
|
|
}
|
|
function chunksOf(word) {
|
|
if (cadence === "uniform") return Array.from(word);
|
|
var out = [];
|
|
var i = 0;
|
|
while (i < word.length) {
|
|
var n = 1 + Math.floor(rnd() * 3);
|
|
out.push(word.slice(i, i + n));
|
|
i += n;
|
|
}
|
|
return out;
|
|
}
|
|
function chunkGap(chunk) {
|
|
if (cadence === "uniform") return chunk.length * 0.05;
|
|
return chunk.length * (0.04 + rnd() * 0.03);
|
|
}
|
|
|
|
// Typing preserves the authored coloring spans: characters reveal
|
|
// across the command's text nodes in document order, so a given
|
|
// count always renders the same colored string in either seek
|
|
// direction. The caret is appended last, after node collection,
|
|
// so empty trailing nodes keep it hugging the visible end.
|
|
var textNodes = [];
|
|
if (commandElement) {
|
|
var walker = document.createTreeWalker(commandElement, NodeFilter.SHOW_TEXT, null);
|
|
while (walker.nextNode()) {
|
|
textNodes.push({ node: walker.currentNode, full: walker.currentNode.data });
|
|
}
|
|
}
|
|
var fullText = textNodes
|
|
.map(function (entry) {
|
|
return entry.full;
|
|
})
|
|
.join("");
|
|
function showChars(count) {
|
|
var remaining = count;
|
|
for (var i = 0; i < textNodes.length; i += 1) {
|
|
var entry = textNodes[i];
|
|
var take = Math.min(entry.full.length, Math.max(0, remaining));
|
|
entry.node.data = entry.full.slice(0, take);
|
|
remaining -= entry.full.length;
|
|
}
|
|
}
|
|
var caretElement = null;
|
|
if (commandElement) {
|
|
caretElement = document.createElement("span");
|
|
caretElement.className = "ctr-caret";
|
|
caretElement.setAttribute("aria-hidden", "true");
|
|
commandElement.appendChild(caretElement);
|
|
}
|
|
stage.setAttribute("aria-label", (promptGlyph + " " + fullText).trim());
|
|
|
|
// The complete chars-at-time table. Built exactly once; the
|
|
// timeline only ever reads it (the typed-prompt law).
|
|
var rows = [{ t: 0, n: 0 }];
|
|
(function buildRows() {
|
|
var t = TYPE_START;
|
|
var n = 0;
|
|
fullText.split(/(\s+)/).forEach(function (segment) {
|
|
if (segment === "") return;
|
|
if (/^\s+$/.test(segment)) {
|
|
t += cadence === "uniform" ? 0.11 : 0.1 + rnd() * 0.1;
|
|
n += segment.length;
|
|
rows.push({ t: t, n: n });
|
|
return;
|
|
}
|
|
chunksOf(segment).forEach(function (chunk) {
|
|
t += chunkGap(chunk);
|
|
n += chunk.length;
|
|
rows.push({ t: t, n: n });
|
|
});
|
|
});
|
|
})();
|
|
|
|
// Natural schedule: type, execute beat, one output per step after
|
|
// a leading beat, then the trailing prompt.
|
|
var typeEnd = Math.max(rows[rows.length - 1].t, TYPE_START + 0.01);
|
|
var execAt = typeEnd + EXEC_BEAT;
|
|
var outAts = outputElements.map(function (element, index) {
|
|
return execAt + LEAD_BEAT + index * OUT_STEP;
|
|
});
|
|
var tailAt = (outAts.length > 0 ? outAts[outAts.length - 1] : execAt) + TAIL_GAP;
|
|
|
|
// Compress the whole schedule proportionally only if it would
|
|
// overflow the window before OUT; extra duration becomes HOLD,
|
|
// never timeScale.
|
|
var naturalEnd = tailAt + PRINT;
|
|
if (naturalEnd > maxEnd) {
|
|
var factor = (maxEnd - TYPE_START) / (naturalEnd - TYPE_START);
|
|
var squeeze = function (time) {
|
|
return time <= TYPE_START ? time : TYPE_START + (time - TYPE_START) * factor;
|
|
};
|
|
rows.forEach(function (row) {
|
|
row.t = squeeze(row.t);
|
|
});
|
|
typeEnd = Math.max(rows[rows.length - 1].t, TYPE_START + 0.01);
|
|
execAt = squeeze(execAt);
|
|
outAts = outAts.map(squeeze);
|
|
tailAt = squeeze(tailAt);
|
|
}
|
|
|
|
// Cue overrides: cue N pins output line N, clamped after execute
|
|
// and inside the window; un-cued lines follow the previous line.
|
|
if (cueList.length > 0) {
|
|
var previous = execAt + LEAD_BEAT - OUT_STEP;
|
|
outAts = outAts.map(function (defaultAt, index) {
|
|
var at = cueList[index] != null ? cueList[index] : previous + OUT_STEP;
|
|
at = Math.max(execAt + 0.05, Math.min(maxEnd - PRINT, at));
|
|
at = Math.max(at, previous + 0.05);
|
|
previous = at;
|
|
return at;
|
|
});
|
|
tailAt = (outAts.length > 0 ? outAts[outAts.length - 1] : execAt) + TAIL_GAP;
|
|
}
|
|
tailAt = Math.max(execAt + 0.1, Math.min(maxEnd - PRINT, tailAt));
|
|
|
|
// 1ms tolerance: GSAP snaps a tween's end value below the row
|
|
// table's accumulated float times, far under one frame.
|
|
function charsAt(time) {
|
|
for (var i = rows.length - 1; i >= 0; i -= 1) {
|
|
if (time >= rows[i].t - 0.001) return rows[i].n;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
// Fit the mono size to the widest line and the line count.
|
|
var lineElements = [commandElement].concat(outputElements, [tailElement]);
|
|
var maxLength = lineElements.reduce(function (best, element) {
|
|
if (!element) return best;
|
|
var length = (element === commandElement ? fullText : element.textContent).length;
|
|
return Math.max(best, length + promptGlyph.length + 3);
|
|
}, 12);
|
|
var fittedCqw = Math.max(2, Math.min(3.2, 108 / maxLength));
|
|
var cappedCqh = Math.max(3.2, Math.min(6.4, 46 / (lineElements.length * 1.6)));
|
|
root.style.setProperty(
|
|
"--ctr-font-size",
|
|
"min(" + fittedCqw.toFixed(3) + "cqw, " + cappedCqh.toFixed(3) + "cqh)",
|
|
);
|
|
|
|
gsap.set(stage, { opacity: 0, y: "2.6cqh" });
|
|
if (outputElements.length > 0) gsap.set(outputElements, { opacity: 0 });
|
|
if (tailElement) gsap.set(tailElement, { opacity: 0 });
|
|
showChars(0);
|
|
|
|
var tl = gsap.timeline({ paused: true });
|
|
|
|
// IN: one panel settle, then the table drives every typed frame.
|
|
tl.to(stage, { opacity: 1, duration: ENTER, ease: "power2.out" }, 0);
|
|
tl.to(stage, { y: "0cqh", duration: ENTER, ease: "power3.out" }, 0);
|
|
|
|
var typeDriver = { t: 0 };
|
|
tl.to(
|
|
typeDriver,
|
|
{
|
|
t: typeEnd,
|
|
duration: typeEnd,
|
|
ease: "none",
|
|
onUpdate: function () {
|
|
showChars(charsAt(typeDriver.t));
|
|
},
|
|
},
|
|
0,
|
|
);
|
|
|
|
// Caret: integer sine cycles across exactly the typing window,
|
|
// then a pin to solid, then hidden at execute (the command has
|
|
// been submitted; the trailing prompt owns the caret from there).
|
|
if (caretElement) {
|
|
var cycles = Math.max(1, Math.round(typeEnd / 0.9));
|
|
var blink = { p: 0 };
|
|
tl.to(
|
|
blink,
|
|
{
|
|
p: Math.PI * 2 * cycles,
|
|
duration: typeEnd,
|
|
ease: "none",
|
|
onUpdate: function () {
|
|
// >= 0 keeps phase 0 identical to the caret's unrendered
|
|
// initial state (opacity 1) for forward vs backward seeks.
|
|
caretElement.style.opacity = Math.sin(blink.p) >= 0 ? "1" : "0";
|
|
},
|
|
},
|
|
0,
|
|
);
|
|
tl.set(caretElement, { opacity: 1 }, typeEnd);
|
|
tl.set(caretElement, { opacity: 0 }, execAt);
|
|
}
|
|
|
|
// Output lines print on their cues: a print-fast fade, no motion.
|
|
outputElements.forEach(function (element, index) {
|
|
tl.fromTo(
|
|
element,
|
|
{ opacity: 0 },
|
|
{ opacity: 1, duration: PRINT, ease: "none" },
|
|
outAts[index],
|
|
);
|
|
});
|
|
|
|
// The run completes: a fresh prompt with a solid caret appears.
|
|
if (tailElement) {
|
|
tl.fromTo(
|
|
tailElement,
|
|
{ opacity: 0 },
|
|
{ opacity: 1, duration: PRINT, ease: "none" },
|
|
tailAt,
|
|
);
|
|
}
|
|
|
|
// HOLD: barely-there drift ending at exactly zero, then authored
|
|
// stillness before any departure.
|
|
var OUT_START = duration - OUT;
|
|
var settleEnd = tailAt + PRINT;
|
|
var holdSpan = OUT_START - settleEnd;
|
|
if (holdSpan > 0.9) {
|
|
var driftHalf = (holdSpan - STILLNESS) / 2;
|
|
tl.to(stage, { y: "-0.45cqh", duration: driftHalf, ease: "sine.inOut" }, settleEnd);
|
|
tl.to(
|
|
stage,
|
|
{ y: "0cqh", duration: driftHalf, ease: "sine.inOut" },
|
|
settleEnd + driftHalf,
|
|
);
|
|
}
|
|
|
|
// OUT: only when the exit variable asks for one.
|
|
if (exitMode !== "none") {
|
|
tl.to(stage, { opacity: 0, duration: OUT, ease: "power2.in" }, OUT_START);
|
|
if (exitMode === "up") {
|
|
tl.to(stage, { y: "-4cqh", duration: OUT, ease: "power2.in" }, OUT_START);
|
|
}
|
|
}
|
|
|
|
tl.seek(0);
|
|
window.__timelines = window.__timelines || {};
|
|
window.__timelines["code-terminal-run"] = tl;
|
|
})();
|
|
</script>
|
|
</div>
|
|
</template>
|
|
</body>
|
|
</html>
|
|
```
|
|
|
|
</VariablesExplorer>
|
|
|
|
## Install
|
|
|
|
<InstallCommand command="npx hyperframes add code-terminal-run" item="code-terminal-run" />
|
|
|
|
That writes one file: `compositions/components/code-terminal-run.html`.
|
|
|
|
## Paste it into your composition
|
|
|
|
Open `compositions/components/code-terminal-run.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 |
|
|
| --- | --- | --- | --- |
|
|
| `prompt_glyph` | `$` | string | Leading glyph before the command and the trailing prompt. Empty string hides it. |
|
|
| `cadence` | `human` | `uniform`, `human` | Keystroke rhythm: uniform fixed steps or seeded human chunks. |
|
|
| `cues` | `` | string | Comma-separated seconds relative to mount start; cue N sets when output line N prints. Empty uses the authored rhythm. |
|
|
| `accent` | `green` | `green`, `blue`, `violet` | Color of the prompt glyph and caret. |
|
|
| `exit` | `none` | `none`, `fade`, `up` | Outgoing transition. Frame roots own transitions; none holds the end frame. |
|
|
|
|
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="code-terminal-run"
|
|
data-composition-src="compositions/components/code-terminal-run.html"
|
|
data-variable-values='{"prompt_glyph":"$","cadence":"human","cues":"","accent":"green","exit":"none"}'
|
|
></div>
|
|
```
|
|
|
|
## Source
|
|
|
|
<Accordion title={`code-terminal-run.html`}>
|
|
|
|
```html
|
|
<!doctype html>
|
|
<!--
|
|
code-terminal-run: HyperFrames video primitive (product demo / terminal)
|
|
|
|
A token-chrome terminal panel runs one command: the prompt line types itself
|
|
deterministically (the typed-prompt law: one text-at-time row table built
|
|
synchronously before the timeline registers, an integer-cycle blinking
|
|
caret), the command "executes" after a beat, and output lines print one per
|
|
cue with a leading beat. A fresh prompt line with a solid caret appears once
|
|
the run completes, then the panel holds still.
|
|
|
|
Token coloring is authored, not parsed: the slot content carries plain spans
|
|
(ct-str, ct-flag, ct-path, ct-ok, ct-muted) and CSS routes each class to a
|
|
contract token. Typing preserves those spans by revealing characters across
|
|
the command element's text nodes in document order, so the same character
|
|
count always renders the same colored string in either seek direction.
|
|
|
|
Slot (see README.md for a worked example):
|
|
- [data-slot="content"]: the authored command + output lines. Replace the
|
|
children of this element in your installed copy. It must contain one
|
|
[data-terminal="command"] element (inline spans allowed) and any number
|
|
of [data-terminal="output"] elements, in print order. Default: a generic
|
|
build-tool sample, no product branding.
|
|
|
|
Variables (declared in data-composition-variables below):
|
|
- prompt_glyph (string, default "$"): leading glyph on the command and the
|
|
trailing prompt line; empty string hides it.
|
|
- cadence ("uniform" | "human", default "human"): keystroke rhythm.
|
|
uniform = one character per fixed step; human = seeded 1-3 char chunks
|
|
with varied gaps (fixed LCG seed, fully deterministic).
|
|
- cues (string, default ""): comma-separated seconds relative to mount
|
|
start; cue N sets when output line N prints. Empty = authored rhythm
|
|
(a leading beat after execute, then one line per step).
|
|
- accent (green | blue | violet, default "green"): glyph + caret color.
|
|
- exit ("none" | "fade" | "up", default "none"): frame roots own
|
|
transitions; none holds the end frame.
|
|
|
|
Envelope, authored 5s, fixed IN/OUT with elastic HOLD only (never
|
|
gsap.timeScale()): panel settles over 0.5s, typing runs from 0.4s at its
|
|
natural cadence, execute beat, output prints, trailing prompt; the whole
|
|
schedule compresses proportionally only if it would overflow
|
|
duration - OUT. HOLD absorbs all extra duration (solid caret, barely-there
|
|
drift ending in stillness). OUT exists only when exit != none.
|
|
|
|
Mount contract: mountable sub-composition; the runtime clones only this
|
|
<template>. #root is elastic (no data-width/height, container-type: size),
|
|
styled via #root only, and registers one paused timeline under the literal
|
|
"code-terminal-run" key.
|
|
-->
|
|
<html
|
|
lang="en"
|
|
data-composition-id="code-terminal-run"
|
|
data-composition-duration="5"
|
|
data-composition-variables='[
|
|
{ "id": "prompt_glyph", "type": "string", "role": "style", "label": "Prompt glyph", "description": "Leading glyph before the command and the trailing prompt. Empty string hides it.", "default": "$" },
|
|
{ "id": "cadence", "type": "enum", "role": "timing", "label": "Cadence", "description": "Keystroke rhythm: uniform fixed steps or seeded human chunks.", "default": "human", "options": [{ "value": "uniform", "label": "Uniform" }, { "value": "human", "label": "Human" }] },
|
|
{ "id": "cues", "type": "string", "role": "timing", "label": "Cues", "description": "Comma-separated seconds relative to mount start; cue N sets when output line N prints. Empty uses the authored rhythm.", "default": "" },
|
|
{ "id": "accent", "type": "enum", "role": "style", "label": "Accent", "description": "Color of the prompt glyph and caret.", "default": "green", "options": [{ "value": "green", "label": "Green" }, { "value": "blue", "label": "Blue" }, { "value": "violet", "label": "Violet" }] },
|
|
{ "id": "exit", "type": "enum", "role": "timing", "label": "Exit", "description": "Outgoing transition. Frame roots own transitions; none holds the end frame.", "default": "none", "options": [{ "value": "none", "label": "None" }, { "value": "fade", "label": "Fade" }, { "value": "up", "label": "Up" }] }
|
|
]'
|
|
>
|
|
<head>
|
|
<meta charset="UTF-8" />
|
|
<title>Code Terminal Run</title>
|
|
</head>
|
|
<body>
|
|
<template>
|
|
<div id="root" data-composition-id="code-terminal-run" data-duration="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-mono, ui-monospace, "SF Mono", Menlo, Consolas, monospace);
|
|
pointer-events: none;
|
|
}
|
|
|
|
.ctr-clip {
|
|
position: absolute;
|
|
inset: 0;
|
|
display: grid;
|
|
place-items: center;
|
|
overflow: hidden;
|
|
background: var(--bg, transparent);
|
|
}
|
|
|
|
.ctr-stage {
|
|
width: 84cqw;
|
|
max-width: 84cqw;
|
|
will-change: transform, opacity;
|
|
}
|
|
|
|
.ctr-panel {
|
|
overflow: hidden;
|
|
border: 0.16cqmin solid color-mix(in srgb, var(--border, #475569) 72%, transparent);
|
|
border-radius: var(--radius, 2.4cqmin);
|
|
background: color-mix(in srgb, var(--surface, #0b1016) 96%, var(--ctr-accent));
|
|
box-shadow: 0 3cqh 9cqh color-mix(in srgb, var(--bg, #000000) 38%, transparent);
|
|
}
|
|
|
|
.ctr-bar {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: var(--space-1, 1.2cqw);
|
|
padding: var(--space-1, 1.6cqh) var(--space-2, 2.4cqw);
|
|
border-bottom: 0.14cqmin solid
|
|
color-mix(in srgb, var(--border, #475569) 55%, transparent);
|
|
background: color-mix(in srgb, var(--surface, #0b1016) 88%, var(--bg, #000000));
|
|
}
|
|
|
|
.ctr-dot {
|
|
width: 1.5cqmin;
|
|
aspect-ratio: 1;
|
|
border-radius: 50%;
|
|
background: color-mix(in srgb, var(--muted, #94a3b8) 52%, transparent);
|
|
}
|
|
|
|
.ctr-body {
|
|
padding: var(--space-2, 3cqh) var(--space-2, 3cqw);
|
|
min-height: 40cqh;
|
|
}
|
|
|
|
.ctr-slot {
|
|
display: block;
|
|
}
|
|
|
|
[data-terminal="command"],
|
|
[data-terminal="output"],
|
|
.ctr-tail {
|
|
font-size: var(--ctr-font-size, min(2.6cqw, 5.4cqh));
|
|
font-weight: 500;
|
|
line-height: 1.6;
|
|
white-space: pre-wrap;
|
|
overflow-wrap: anywhere;
|
|
}
|
|
|
|
[data-terminal="command"]::before,
|
|
.ctr-tail::before {
|
|
content: var(--ctr-glyph, "$");
|
|
margin-right: var(--ctr-glyph-gap, 0.9ch);
|
|
color: var(--ctr-accent);
|
|
font-weight: 600;
|
|
}
|
|
|
|
/* Authored token coloring: spans in the slot content, no parser.
|
|
Each class routes to one contract token. */
|
|
.ct-str {
|
|
color: var(--brand, #71f5a7);
|
|
}
|
|
|
|
.ct-flag {
|
|
color: var(--ctr-accent-token, var(--accent, #61a8ff));
|
|
}
|
|
|
|
.ct-path {
|
|
color: var(--accent-2, #c5a3ff);
|
|
}
|
|
|
|
.ct-ok {
|
|
color: var(--brand, #71f5a7);
|
|
font-weight: 600;
|
|
}
|
|
|
|
.ct-muted {
|
|
color: var(--muted, #94a3b8);
|
|
}
|
|
|
|
.ctr-caret {
|
|
display: inline-block;
|
|
width: 0.55ch;
|
|
height: 1.05em;
|
|
margin-left: 0.08ch;
|
|
background: var(--ctr-accent);
|
|
vertical-align: text-bottom;
|
|
will-change: opacity;
|
|
}
|
|
</style>
|
|
|
|
<div
|
|
id="code-terminal-run-clip"
|
|
class="ctr-clip clip"
|
|
data-start="0"
|
|
data-duration="5"
|
|
data-track-index="0"
|
|
>
|
|
<div class="ctr-stage" role="img">
|
|
<div class="ctr-panel">
|
|
<div class="ctr-bar" aria-hidden="true">
|
|
<span class="ctr-dot"></span>
|
|
<span class="ctr-dot"></span>
|
|
<span class="ctr-dot"></span>
|
|
</div>
|
|
<div class="ctr-body">
|
|
<div class="ctr-slot" data-slot="content">
|
|
<!-- SLOT "content": replace the children of this element with
|
|
your own command + output lines. Keep one
|
|
[data-terminal="command"] and any number of
|
|
[data-terminal="output"] elements, in print order. -->
|
|
<div data-terminal="command">
|
|
run build <span class="ct-path">src/app</span>
|
|
<span class="ct-flag">--minify</span> <span class="ct-flag">--out</span>
|
|
<span class="ct-str">"dist/app"</span>
|
|
</div>
|
|
<div data-terminal="output">
|
|
<span class="ct-muted">-</span> resolving 128 modules
|
|
</div>
|
|
<div data-terminal="output">
|
|
<span class="ct-muted">-</span> bundling <span class="ct-path">src/app</span>
|
|
</div>
|
|
<div data-terminal="output">
|
|
<span class="ct-ok">ok</span> 128 modules in 412 ms
|
|
</div>
|
|
<div data-terminal="output">
|
|
<span class="ct-ok">ok</span> wrote <span class="ct-path">dist/app</span>
|
|
<span class="ct-muted">(96 kB)</span>
|
|
</div>
|
|
</div>
|
|
<div class="ctr-tail" aria-hidden="true"><span class="ctr-caret"></span></div>
|
|
</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(".ctr-stage");
|
|
var slot = root.querySelector('[data-slot="content"]');
|
|
var commandElement = slot ? slot.querySelector('[data-terminal="command"]') : null;
|
|
var outputElements = slot
|
|
? Array.prototype.slice.call(slot.querySelectorAll('[data-terminal="output"]'))
|
|
: [];
|
|
var tailElement = root.querySelector(".ctr-tail");
|
|
var vars =
|
|
window.__hyperframes && window.__hyperframes.getVariables
|
|
? window.__hyperframes.getVariables()
|
|
: {};
|
|
|
|
var promptGlyph = vars.prompt_glyph == null ? "$" : String(vars.prompt_glyph);
|
|
var cadence = vars.cadence === "uniform" ? "uniform" : "human";
|
|
var exitMode = vars.exit === "fade" || vars.exit === "up" ? vars.exit : "none";
|
|
|
|
// The runtime mirrors every composition variable as a --<id>
|
|
// custom property (host inline style + a compiled rule), so the
|
|
// accent VARIABLE shadows the --accent contract TOKEN with its
|
|
// enum keyword whenever the caller passes variables. Theme packs
|
|
// re-declare --accent with !important on the same elements and
|
|
// stay clean; only the unthemed mirror leaks through. Detect
|
|
// exactly that leak (the computed token IS an enum keyword) and
|
|
// pin the token's exact contract fallback instead, keeping live
|
|
// var() resolution everywhere else.
|
|
var accentToken = "var(--accent, #61a8ff)";
|
|
var computedAccent = getComputedStyle(root).getPropertyValue("--accent").trim();
|
|
if (
|
|
computedAccent === "green" ||
|
|
computedAccent === "blue" ||
|
|
computedAccent === "violet"
|
|
) {
|
|
accentToken = "#61a8ff";
|
|
}
|
|
root.style.setProperty("--ctr-accent-token", accentToken);
|
|
|
|
// Each enum choice routes to a DIFFERENT contract token so the
|
|
// variable stays meaningful under a theme.
|
|
var accentColors = {
|
|
green: "var(--brand, #71f5a7)",
|
|
blue: accentToken,
|
|
violet: "var(--accent-2, #c5a3ff)",
|
|
};
|
|
var accent = Object.prototype.hasOwnProperty.call(accentColors, vars.accent)
|
|
? vars.accent
|
|
: "green";
|
|
root.style.setProperty("--ctr-accent", accentColors[accent]);
|
|
// JSON.stringify yields a valid CSS quoted string for content:.
|
|
root.style.setProperty("--ctr-glyph", JSON.stringify(promptGlyph));
|
|
if (promptGlyph === "") root.style.setProperty("--ctr-glyph-gap", "0ch");
|
|
|
|
var cueList = String(vars.cues == null ? "" : vars.cues)
|
|
.split(",")
|
|
.map(function (token) {
|
|
return parseFloat(token);
|
|
})
|
|
.filter(function (value) {
|
|
return isFinite(value) && value >= 0;
|
|
})
|
|
.sort(function (a, b) {
|
|
return a - b;
|
|
});
|
|
|
|
var ENTER = 0.5;
|
|
var TYPE_START = 0.4;
|
|
var EXEC_BEAT = 0.22;
|
|
var LEAD_BEAT = 0.3;
|
|
var OUT_STEP = 0.3;
|
|
var TAIL_GAP = 0.35;
|
|
var PRINT = 0.12;
|
|
var OUT_BASE = 0.45;
|
|
var STILLNESS = 0.3;
|
|
var duration = Math.max(0.001, parseFloat(root.dataset.duration || "5"));
|
|
var OUT = exitMode === "none" ? 0 : Math.min(OUT_BASE, duration * 0.2);
|
|
var maxEnd = Math.max(TYPE_START + 0.3, duration - OUT - STILLNESS);
|
|
|
|
// Fixed-seed LCG: the only randomness source, consumed in one
|
|
// deterministic order during this synchronous build.
|
|
var lcgState = 0x51ec0ded;
|
|
function rnd() {
|
|
lcgState = (Math.imul(1664525, lcgState) + 1013904223) >>> 0;
|
|
return lcgState / 4294967296;
|
|
}
|
|
function chunksOf(word) {
|
|
if (cadence === "uniform") return Array.from(word);
|
|
var out = [];
|
|
var i = 0;
|
|
while (i < word.length) {
|
|
var n = 1 + Math.floor(rnd() * 3);
|
|
out.push(word.slice(i, i + n));
|
|
i += n;
|
|
}
|
|
return out;
|
|
}
|
|
function chunkGap(chunk) {
|
|
if (cadence === "uniform") return chunk.length * 0.05;
|
|
return chunk.length * (0.04 + rnd() * 0.03);
|
|
}
|
|
|
|
// Typing preserves the authored coloring spans: characters reveal
|
|
// across the command's text nodes in document order, so a given
|
|
// count always renders the same colored string in either seek
|
|
// direction. The caret is appended last, after node collection,
|
|
// so empty trailing nodes keep it hugging the visible end.
|
|
var textNodes = [];
|
|
if (commandElement) {
|
|
var walker = document.createTreeWalker(commandElement, NodeFilter.SHOW_TEXT, null);
|
|
while (walker.nextNode()) {
|
|
textNodes.push({ node: walker.currentNode, full: walker.currentNode.data });
|
|
}
|
|
}
|
|
var fullText = textNodes
|
|
.map(function (entry) {
|
|
return entry.full;
|
|
})
|
|
.join("");
|
|
function showChars(count) {
|
|
var remaining = count;
|
|
for (var i = 0; i < textNodes.length; i += 1) {
|
|
var entry = textNodes[i];
|
|
var take = Math.min(entry.full.length, Math.max(0, remaining));
|
|
entry.node.data = entry.full.slice(0, take);
|
|
remaining -= entry.full.length;
|
|
}
|
|
}
|
|
var caretElement = null;
|
|
if (commandElement) {
|
|
caretElement = document.createElement("span");
|
|
caretElement.className = "ctr-caret";
|
|
caretElement.setAttribute("aria-hidden", "true");
|
|
commandElement.appendChild(caretElement);
|
|
}
|
|
stage.setAttribute("aria-label", (promptGlyph + " " + fullText).trim());
|
|
|
|
// The complete chars-at-time table. Built exactly once; the
|
|
// timeline only ever reads it (the typed-prompt law).
|
|
var rows = [{ t: 0, n: 0 }];
|
|
(function buildRows() {
|
|
var t = TYPE_START;
|
|
var n = 0;
|
|
fullText.split(/(\s+)/).forEach(function (segment) {
|
|
if (segment === "") return;
|
|
if (/^\s+$/.test(segment)) {
|
|
t += cadence === "uniform" ? 0.11 : 0.1 + rnd() * 0.1;
|
|
n += segment.length;
|
|
rows.push({ t: t, n: n });
|
|
return;
|
|
}
|
|
chunksOf(segment).forEach(function (chunk) {
|
|
t += chunkGap(chunk);
|
|
n += chunk.length;
|
|
rows.push({ t: t, n: n });
|
|
});
|
|
});
|
|
})();
|
|
|
|
// Natural schedule: type, execute beat, one output per step after
|
|
// a leading beat, then the trailing prompt.
|
|
var typeEnd = Math.max(rows[rows.length - 1].t, TYPE_START + 0.01);
|
|
var execAt = typeEnd + EXEC_BEAT;
|
|
var outAts = outputElements.map(function (element, index) {
|
|
return execAt + LEAD_BEAT + index * OUT_STEP;
|
|
});
|
|
var tailAt = (outAts.length > 0 ? outAts[outAts.length - 1] : execAt) + TAIL_GAP;
|
|
|
|
// Compress the whole schedule proportionally only if it would
|
|
// overflow the window before OUT; extra duration becomes HOLD,
|
|
// never timeScale.
|
|
var naturalEnd = tailAt + PRINT;
|
|
if (naturalEnd > maxEnd) {
|
|
var factor = (maxEnd - TYPE_START) / (naturalEnd - TYPE_START);
|
|
var squeeze = function (time) {
|
|
return time <= TYPE_START ? time : TYPE_START + (time - TYPE_START) * factor;
|
|
};
|
|
rows.forEach(function (row) {
|
|
row.t = squeeze(row.t);
|
|
});
|
|
typeEnd = Math.max(rows[rows.length - 1].t, TYPE_START + 0.01);
|
|
execAt = squeeze(execAt);
|
|
outAts = outAts.map(squeeze);
|
|
tailAt = squeeze(tailAt);
|
|
}
|
|
|
|
// Cue overrides: cue N pins output line N, clamped after execute
|
|
// and inside the window; un-cued lines follow the previous line.
|
|
if (cueList.length > 0) {
|
|
var previous = execAt + LEAD_BEAT - OUT_STEP;
|
|
outAts = outAts.map(function (defaultAt, index) {
|
|
var at = cueList[index] != null ? cueList[index] : previous + OUT_STEP;
|
|
at = Math.max(execAt + 0.05, Math.min(maxEnd - PRINT, at));
|
|
at = Math.max(at, previous + 0.05);
|
|
previous = at;
|
|
return at;
|
|
});
|
|
tailAt = (outAts.length > 0 ? outAts[outAts.length - 1] : execAt) + TAIL_GAP;
|
|
}
|
|
tailAt = Math.max(execAt + 0.1, Math.min(maxEnd - PRINT, tailAt));
|
|
|
|
// 1ms tolerance: GSAP snaps a tween's end value below the row
|
|
// table's accumulated float times, far under one frame.
|
|
function charsAt(time) {
|
|
for (var i = rows.length - 1; i >= 0; i -= 1) {
|
|
if (time >= rows[i].t - 0.001) return rows[i].n;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
// Fit the mono size to the widest line and the line count.
|
|
var lineElements = [commandElement].concat(outputElements, [tailElement]);
|
|
var maxLength = lineElements.reduce(function (best, element) {
|
|
if (!element) return best;
|
|
var length = (element === commandElement ? fullText : element.textContent).length;
|
|
return Math.max(best, length + promptGlyph.length + 3);
|
|
}, 12);
|
|
var fittedCqw = Math.max(2, Math.min(3.2, 108 / maxLength));
|
|
var cappedCqh = Math.max(3.2, Math.min(6.4, 46 / (lineElements.length * 1.6)));
|
|
root.style.setProperty(
|
|
"--ctr-font-size",
|
|
"min(" + fittedCqw.toFixed(3) + "cqw, " + cappedCqh.toFixed(3) + "cqh)",
|
|
);
|
|
|
|
gsap.set(stage, { opacity: 0, y: "2.6cqh" });
|
|
if (outputElements.length > 0) gsap.set(outputElements, { opacity: 0 });
|
|
if (tailElement) gsap.set(tailElement, { opacity: 0 });
|
|
showChars(0);
|
|
|
|
var tl = gsap.timeline({ paused: true });
|
|
|
|
// IN: one panel settle, then the table drives every typed frame.
|
|
tl.to(stage, { opacity: 1, duration: ENTER, ease: "power2.out" }, 0);
|
|
tl.to(stage, { y: "0cqh", duration: ENTER, ease: "power3.out" }, 0);
|
|
|
|
var typeDriver = { t: 0 };
|
|
tl.to(
|
|
typeDriver,
|
|
{
|
|
t: typeEnd,
|
|
duration: typeEnd,
|
|
ease: "none",
|
|
onUpdate: function () {
|
|
showChars(charsAt(typeDriver.t));
|
|
},
|
|
},
|
|
0,
|
|
);
|
|
|
|
// Caret: integer sine cycles across exactly the typing window,
|
|
// then a pin to solid, then hidden at execute (the command has
|
|
// been submitted; the trailing prompt owns the caret from there).
|
|
if (caretElement) {
|
|
var cycles = Math.max(1, Math.round(typeEnd / 0.9));
|
|
var blink = { p: 0 };
|
|
tl.to(
|
|
blink,
|
|
{
|
|
p: Math.PI * 2 * cycles,
|
|
duration: typeEnd,
|
|
ease: "none",
|
|
onUpdate: function () {
|
|
// >= 0 keeps phase 0 identical to the caret's unrendered
|
|
// initial state (opacity 1) for forward vs backward seeks.
|
|
caretElement.style.opacity = Math.sin(blink.p) >= 0 ? "1" : "0";
|
|
},
|
|
},
|
|
0,
|
|
);
|
|
tl.set(caretElement, { opacity: 1 }, typeEnd);
|
|
tl.set(caretElement, { opacity: 0 }, execAt);
|
|
}
|
|
|
|
// Output lines print on their cues: a print-fast fade, no motion.
|
|
outputElements.forEach(function (element, index) {
|
|
tl.fromTo(
|
|
element,
|
|
{ opacity: 0 },
|
|
{ opacity: 1, duration: PRINT, ease: "none" },
|
|
outAts[index],
|
|
);
|
|
});
|
|
|
|
// The run completes: a fresh prompt with a solid caret appears.
|
|
if (tailElement) {
|
|
tl.fromTo(
|
|
tailElement,
|
|
{ opacity: 0 },
|
|
{ opacity: 1, duration: PRINT, ease: "none" },
|
|
tailAt,
|
|
);
|
|
}
|
|
|
|
// HOLD: barely-there drift ending at exactly zero, then authored
|
|
// stillness before any departure.
|
|
var OUT_START = duration - OUT;
|
|
var settleEnd = tailAt + PRINT;
|
|
var holdSpan = OUT_START - settleEnd;
|
|
if (holdSpan > 0.9) {
|
|
var driftHalf = (holdSpan - STILLNESS) / 2;
|
|
tl.to(stage, { y: "-0.45cqh", duration: driftHalf, ease: "sine.inOut" }, settleEnd);
|
|
tl.to(
|
|
stage,
|
|
{ y: "0cqh", duration: driftHalf, ease: "sine.inOut" },
|
|
settleEnd + driftHalf,
|
|
);
|
|
}
|
|
|
|
// OUT: only when the exit variable asks for one.
|
|
if (exitMode !== "none") {
|
|
tl.to(stage, { opacity: 0, duration: OUT, ease: "power2.in" }, OUT_START);
|
|
if (exitMode === "up") {
|
|
tl.to(stage, { y: "-4cqh", duration: OUT, ease: "power2.in" }, OUT_START);
|
|
}
|
|
}
|
|
|
|
tl.seek(0);
|
|
window.__timelines = window.__timelines || {};
|
|
window.__timelines["code-terminal-run"] = tl;
|
|
})();
|
|
</script>
|
|
</div>
|
|
</template>
|
|
</body>
|
|
</html>
|
|
```
|
|
|
|
</Accordion>
|
|
|
|
{/* hf:generated-footer */}
|
|
|
|
Tagged `motion-primitive` `product-demo` `terminal` `typing` `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)
|