> ## Documentation Index
> Fetch the complete documentation index at: https://hyperframes.heygen.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Code Terminal Run

> 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.

export const InstallCommand = ({command}) => {
  const [copied, setCopied] = React.useState(false);
  const copy = async () => {
    try {
      if (navigator.clipboard && window.isSecureContext) {
        await navigator.clipboard.writeText(command);
      } else {
        const previous = document.activeElement;
        const scratch = document.createElement("textarea");
        scratch.value = command;
        scratch.setAttribute("readonly", "");
        scratch.style.position = "fixed";
        scratch.style.opacity = "0";
        document.body.appendChild(scratch);
        scratch.select();
        document.execCommand("copy");
        document.body.removeChild(scratch);
        previous?.focus?.();
      }
      setCopied(true);
      setTimeout(() => setCopied(false), 2000);
    } catch {}
  };
  return <div className="hf-install-command not-prose my-4 flex items-stretch overflow-hidden rounded-xl border border-zinc-200 bg-zinc-50 dark:border-zinc-800 dark:bg-zinc-900">
      <code className="flex-1 overflow-x-auto whitespace-nowrap border-r border-zinc-200 px-4 py-3 font-mono text-sm text-zinc-800 dark:border-zinc-800 dark:text-zinc-100">
        {command}
      </code>
      <button type="button" onClick={copy} data-copied={copied ? "true" : "false"} aria-label={`Copy ${command} to the clipboard`} className="hf-install-copy">
        <svg className="hf-install-copy-clipboard" xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 18 18" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">
          <path d="M14.25 5.25H7.25C6.14543 5.25 5.25 6.14543 5.25 7.25V14.25C5.25 15.3546 6.14543 16.25 7.25 16.25H14.25C15.3546 16.25 16.25 15.3546 16.25 14.25V7.25C16.25 6.14543 15.3546 5.25 14.25 5.25Z" />
          <path d="M2.80103 11.998L1.77203 5.07397C1.61003 3.98097 2.36403 2.96397 3.45603 2.80197L10.38 1.77297C11.313 1.63397 12.19 2.16297 12.528 3.00097" />
        </svg>
        <svg className="hf-install-copy-check" xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 18 18" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">
          <path d="M2.75 9.5L6.5 13.25L15.25 4.5" />
        </svg>
      </button>
      <span className="hf-install-copy-status" role="status" aria-live="polite">
        {copied ? "Copied" : ""}
      </span>
    </div>;
};

<iframe className="w-full aspect-video rounded-xl border-0 bg-zinc-100 dark:bg-zinc-800" title="code-terminal-run preview" loading="lazy" srcDoc={`<!doctype html><html><head><meta charset="utf-8"><style>html,body{margin:0;height:100%;overflow:hidden;background:transparent}hyperframes-player{display:block;width:100%;height:100%}</style><script src="https://cdn.jsdelivr.net/npm/@hyperframes/player@0.7/dist/hyperframes-player.global.js"><\/script></head><body><script>fetch("/public/catalog/components/code-terminal-run.json").then(function(r){return r.json()}).then(function(d){var p=document.createElement("hyperframes-player");p.setAttribute("srcdoc",d.html);p.setAttribute("controls","");p.setAttribute("autoplay","");p.setAttribute("loop","");p.setAttribute("muted","");p.setAttribute("poster","https://static.heygen.ai/hyperframes-oss/docs/images/catalog/components/code-terminal-run.png");document.body.appendChild(p)});<\/script></body></html>`} />

## Install

<InstallCommand command="npx hyperframes add 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 theme={null}
<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 theme={null}
  <!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>

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)


## Related topics

- [Code animations](/prompting/code-blocks.md)
- [Get unstuck](/help.md)
- [CLI](/packages/cli.md)
