mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-03 20:37:30 +00:00
* feat(catalog): add the seven 3D-motion pieces as installable registry blocks Each piece ships as a registry block with a CDN poster and preview, a live catalog detail page and its source. Scripts travel inside the catalog payload (shared vendor libraries fetched once, item scripts inline, the one HDR as a data URI) because the docs host only serves fonts, images and JSON. NO_ESSAY_COMMENTS_OK: the long comment blocks are in vendored libraries and the ported frost source under registry/blocks, not hand-written here. HF_MAX_NONLFS_KB=6000: four hosted texture PNGs under docs/public/catalog/items are runtime assets the docs host must serve as files. fallow skipped locally: it audits against origin/main and this branch is stacked on an older main. * chore(catalog): regenerate gallery data and nav after rebasing onto main * fix(catalog): read the install manifest through the bounded project reader * fix(catalog): a script the inliner missed fails the payload instead of shipping a dead URL * refactor(catalog): the leftover-script check reuses the reference finder * fix(catalog): frost and glass textures load from the CDN and the iteration presets are gone * chore(catalog): regenerate the frost and glass payloads and nav * fix(catalog): frost and glass textures are hosted through the registry url field, not hardcoded * chore(catalog): regenerate the frost and glass payloads against the hosted texture URLs * fix(catalog): the hosted-reference rewrite refuses a bare name it cannot safely replace * ci(catalog): verify changed catalog payloads in headless Chrome and check the docs catalog * feat(catalog): every item page follows the shared layout with a Tune panel and tabs * fix(catalog): let the texture-mask item host its masks so its tile plays live * chore(catalog): regenerate item pages, gallery data and the texture-mask payload * chore(catalog): regenerate item pages after merging main * fix(catalog): declared-only variables get the Tune panel, Code and Docs tabs capped * feat(catalog): give the blend-difference caption a demo scene so its tile plays live * chore(catalog): live payload for the blend-difference caption * perf(catalog): heavy 3d pieces compile and draw before ready, not on the first visible frame * feat(catalog): the avatar promo card hosts its videos, audio and fonts on the CDN * feat(catalog): the avatar promo card tile plays live from its CDN-hosted media * chore(catalog): the avatar promo card plays live, no allowlist left * chore(catalog): shorten two comment blocks * chore(catalog): trim first-party comment blocks to the comment-check limits * chore(catalog): shorten two frost source comments * fix(catalog): the Docs tab renders as prose again, and the detail page honours reduced motion Frame-mode pages carry no prose wrapper, and the detail component sat inside not-prose, so the Docs slot's headings, paragraphs, links and lists had no styling at all. The slots now carry their own prose classes and the chrome around them keeps not-prose. The recorded clip also gets the reduced-motion guard the docs-snippet check requires, and the generator reads stability from the source metadata type so the scripts typecheck passes. * fix(catalog): docs-tab paragraphs render as blocks Mintlify emits paragraphs as inline spans, so two paragraphs in the Docs slot ran together. * fix(ci): drop the duplicate docs_catalog job output git's line-based auto-merge silently duplicated the outputs key when main and this branch each added it on non-adjacent lines during the rebase; oxfmt's yaml parser rejects the repeated map key. * fix(catalog): close four CodeQL alerts in the frost source * chore(catalog): allowlist the avatar-promo-card CDN asset deletions, format sync-docs-catalog check-no-main-deletions.mjs was rejecting 11 local mp4/font files this branch already deleted in favor of CDN hosting; scripts/sync-docs-catalog.mjs had one line over the 100-col print width from an earlier edit in this branch. * fix(catalog): detail tabs use docs prose spacing, Install first; previews skip no-WebGPU runners * fix(catalog): the docs tab scrolls with the page instead of a capped inner box * refactor(catalog): split the payload asset and verify scripts into single-purpose helpers * refactor(catalog): split the preview generator into single-purpose helpers * ci(catalog): fail when the committed catalog differs from generator output The docs host serves the committed catalog and nothing regenerates it, so a stale copy shipped silently. The catalog payloads job now generates into a temp dir and compares it with the committed tree. * chore(catalog): regenerate docs/public/catalog with the refactored scripts One full regeneration from an empty output tree with the current scripts. The tree grows from 58.4 MB to 65.1 MB. Two hosted assets are about 2 MB each (an avatar png and a wav); the same bytes are already committed under assets/, so HF_MAX_NONLFS_KB is raised for this commit only. * fix(catalog): run the catalog script tests under the runner they are written for The rebase put three node:test files in the vitest half of test:scripts, where they report "No test suite found". They now sit in the node --test list. * fix(catalog): a WebGPU item without an adapter shows its recorded clip and says why * ci(catalog): the drift check runs from a committed fetch mirror with no network Generation now serves every font and CDN script fetch from scripts/catalog-fetch-mirror and fails when a fetch is not in it, even if the caller swallowed the error. CATALOG_FETCH_MIRROR=record refreshes the mirror from the live network. The docs_catalog filter also watches packages/core, packages/producer and the mirror, and the 13 re-hashed font files are listed in ALLOWED_DELETIONS. * chore(catalog): clean up the temp font cache and sort the mirror index without a locale * fix(catalog): hide Tune when the clip stands in, time out the adapter request, share one check * fix(catalog): the adapter probe survives a sync throw and a hang; test the clip guard * fix(catalog): keep the adapter probe inside the component, Mintlify evaluates only exports * fix(catalog): run the detail and page generator tests in CI; no Tune flash while probing WebGPU * docs(catalog): credit vendored libraries and make each SKILL.md list what the block installs CREDITS.md names every vendored dependency with its upstream and licence, and flags the two leaf textures whose origin is still to be confirmed. Each SKILL.md Files table now comes from the block manifest and its install and render paths point at compositions/<name>/. A test checks that every path a SKILL.md names is a manifest file that exists. * fix(catalog): a declared WebGPU item passes verify by its manifest tag, not by console wording verify-catalog-payloads forgave a missing adapter only by matching the markup and the message, which library-reported errors and widgets never satisfy. The webgpu tag in the item manifest is now the owner: a tagged item ignores its page and console errors, an untagged one gets no forgiveness, and a marker payload with no html is listed instead of crashing the run. * docs(catalog): correct the credits per block and guard the mount and render paths CREDITS.md states the three.js version and vendored-or-CDN status per block, adds d3-delaunay, Clipper on the CDN and the Google Fonts loads, and lists every texture with no known origin. The SKILL.md test now also checks the mount and render paths against the manifest composition. * test(catalog): read each block manifest once in the SKILL.md file test The two checks shared a copied manifest read, which fallow flagged as a clone with a high score. * fix(catalog): commit the hosted item files a gitignore rule kept out, and check git not the disk The compositions/ and *-ad/ ignore rules matched folder names under docs/public/catalog/items, so 33 hosted fonts, textures and marks were generated but never committed and would 404 on the docs host. The rules now have a negation for that tree and the files are added. The drift check read the checkout, where git-ignored files still exist, so it passed locally and failed only in CI. It now unpacks HEAD with git archive and compares that. * fix(catalog): a tile keeps its poster until the composition has painted * fix(catalog): a tagged WebGPU item forgives only the adapter-absent error, and test the wiring The manifest webgpu tag now decides whether an item may lack an adapter, and the error wording decides which lines are that absence. Any other page or console error on the item, and every failed request, still fails. The per-item decision is one exported function the tests drive, marker payloads are parsed by a tested helper, and the SKILL.md variable counts are checked against their tables (cuboid-carousel said forty-nine for forty). * fix(catalog): the pinned group's posters load eagerly at high priority * fix(catalog): type the tile reveal test so the scripts typecheck passes * fix(catalog): stop the adapter signature matching an unrelated failed adapter request failed to request .*adapter also matched errors about other adapters. It now matches only a request for the WebGPU adapter, so a tagged item cannot hide an unrelated failure behind it. * test(catalog): a tagged item still fails on an error about some other adapter * feat(catalog): the install command sits above the preview, as on the live catalog * fix(catalog): find the install slot through Mintlify's child wrapper * fix(docs): catalog copy buttons keep their size when the label swaps to Copied * refactor(docs): name the shown copy label once in the catalog copy button * fix(docs): primary catalog button keeps a readable label on hover and after copy * fix(docs): inset the catalog tab strip and tab content to match the boxed panels
644 lines
28 KiB
Plaintext
644 lines
28 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."
|
|
mode: "frame"
|
|
---
|
|
|
|
import { CatalogDetail, CatalogSlot } from "/snippets/catalog-detail.jsx";
|
|
import { InstallCommand } from "/snippets/install-command.jsx";
|
|
|
|
<CatalogDetail
|
|
previewSrc="/public/catalog/components/code-terminal-run.json"
|
|
compositionId="code-terminal-run"
|
|
compositionSrc="compositions/components/code-terminal-run.html"
|
|
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."
|
|
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"}]}]}
|
|
meta={{"category":"Product Demo","badge":"Stable","codeLines":560}}
|
|
attribution={{"path":"registry/components/code-terminal-run","tags":["motion-primitive","product-demo","terminal","typing","deterministic"]}}
|
|
hasCode
|
|
rawUrl="https://raw.githubusercontent.com/heygen-com/hyperframes/main/registry/components/code-terminal-run/code-terminal-run.html"
|
|
>
|
|
|
|
<CatalogSlot slot="code">
|
|
|
|
```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>
|
|
```
|
|
|
|
</CatalogSlot>
|
|
|
|
<CatalogSlot slot="install">
|
|
|
|
<InstallCommand command="npx hyperframes add code-terminal-run" item="code-terminal-run" />
|
|
|
|
That writes one file: `compositions/components/code-terminal-run.html`.
|
|
|
|
</CatalogSlot>
|
|
|
|
<CatalogSlot slot="docs">
|
|
|
|
## 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>
|
|
```
|
|
|
|
{/* 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)
|
|
|
|
</CatalogSlot>
|
|
|
|
</CatalogDetail>
|