{
  "$schema": "../../schema.json",
  "version": "1.0.0",
  "license": "MIT",
  "id": "terminal-run",
  "type": "block",
  "title": "Terminal run",
  "summary": "A command types itself, a spinner works, the output streams in with its checks and the file it made lights up.",
  "tags": [
    "block",
    "code",
    "terminal",
    "cli",
    "install",
    "developer"
  ],
  "params": [
    {
      "name": "background",
      "type": "string",
      "default": "",
      "description": "a background id from the registry; empty uses the brand's first",
      "group": "advanced",
      "control": "select"
    },
    {
      "name": "cwd",
      "type": "string",
      "default": "~/launch",
      "description": "cwd",
      "group": "main",
      "control": "text"
    },
    {
      "name": "command",
      "type": "string",
      "default": "npx paper-motion add push-in",
      "description": "command",
      "group": "main",
      "control": "text"
    },
    {
      "name": "working",
      "type": "string",
      "default": "Resolving push-in",
      "description": "working",
      "group": "main",
      "control": "text"
    },
    {
      "name": "format",
      "type": "enum",
      "default": "1920x1080",
      "options": [
        "1920x1080",
        "1080x1920",
        "1080x1080"
      ],
      "description": "output size; the layout recomposes for each",
      "group": "main",
      "control": "segmented"
    }
  ],
  "install": {
    "kind": "scene"
  },
  "files": [
    {
      "path": "pieces/terminal-run/scene.html",
      "content": "<!doctype html>\n<html>\n<head>\n<meta charset=\"utf-8\">\n<title>terminal-run</title>\n<!--\n  Code · terminal run (6.2 s). A command types itself at a prompt and runs: a spinner works, then the output streams\n  in line by line with its checks popping on, and the file it made lights up. The camera starts close on the prompt,\n  rides the output down and pushes in on the result.\n  Arrive 0–0.6 s · Type 0.6–1.5 s · Run 1.65–2.5 s · Output 2.5–3.7 s · Result 4.0 s · Hold to 6.2 s.\n  Vertical/square: the terminal is sized from the short side (vertical: ~31 columns, lines wrap like a real terminal,\n  taller window); the camera fits its width, follows the output's bottom edge and pushes in on the result, anchored left.\n-->\n<style>\n  #stage { overflow: hidden; }\n  .abs { position: absolute; box-sizing: border-box; }\n  #term { position: absolute; box-sizing: border-box; overflow: hidden; display: flex; flex-direction: column; }\n  .bar { display: flex; align-items: center; gap: 0.45em; padding: 0 1.2em; }\n  #out { position: relative; padding: 1.4em 1.8em; }\n  .ln { height: 1.8em; line-height: 1.8em; white-space: pre; position: relative; }\n  .ck { display: inline-block; width: 1.4em; }\n  .hl { position: absolute; left: -0.5em; top: 0.1em; bottom: 0.1em; border-radius: 0.3em; transform-origin: 0 50%; z-index: -1; }\n  .narrow .ln { height: auto; min-height: 1.8em; white-space: pre-wrap; }\n  .narrow .ln.ckr { display: flex; }\n  .narrow .ln.ckr > span:last-child { flex: 1; }\n  #caret { display: inline-block; width: 0.55em; height: 1.1em; vertical-align: -0.15em; }\n</style>\n</head>\n<body>\n<main id=\"stage\">\n  <div id=\"bg\" class=\"abs\" style=\"inset:0\"></div>\n  <div id=\"world\"><div id=\"term\"><div class=\"bar\" id=\"bar\"></div><div id=\"out\"></div></div></div>\n</main>\n<script type=\"module\">\nimport { scene, progress, ease, spring } from 'paper-motion';\nimport { camera } from 'paper-motion/kit';\nimport { loadBrand } from 'paper-motion/brand';\n\nconst CONFIG = {\n  background: null,                      // a shader-set id, or null for the brand's first entry\n  cwd: '~/launch',\n  command: 'npx paper-motion add push-in',\n  working: 'Resolving push-in',\n  output: [                              // [check?, text]; a line with `result: true` lights up at the end\n    { check: true, text: 'Found push-in · shot · 4 s' },\n    { check: true, text: 'scene.html  → pieces/push-in/scene.html', result: true },\n    { check: true, text: 'brief.md    → pieces/push-in/brief.md' },\n    { check: true, text: 'Brand applied: paper-motion' },\n    { text: '' },\n    { text: 'Done in 0.8 s. Render it with', muted: true },\n    { text: '  npx paper-motion render pieces/push-in', accent: true },\n  ],\n  format: [1920, 1080],\n};\n\nconst B = await loadBrand();\nconst [W, H] = CONFIG.format, SHORT = Math.min(W, H), D = 6.2;\nconst s = scene({ width: W, height: H, fps: 30, duration: D, background: B.color('ground') });\nconst bgId = CONFIG.background ?? B.set.entries.find((e) => e.shader && !e.image)?.id;\nif (bgId) B.shader(s, '#bg', bgId);\ndocument.querySelector('#bg').style.opacity = 0.3;\nconst $ = (id) => document.getElementById(id);\n\nconst DIST = SHORT * 0.62, K = 1 + DIST / (SHORT * 1.7);\nconst cam = camera($('stage'), $('world'), { perspective: SHORT * 1.7 });\nconst wide = W / H > 1.2, tall = H > W;\nconst FS = SHORT * (tall ? 0.031 : 0.026);                            // non-wide: the terminal's type size in the world\nconst term = $('term'), cw = wide ? W * 0.62 * K : FS * (tall ? 31 * 0.6 + 4.2 : 44 * 0.6 + 4.2); let ch = wide ? cw * 0.58 : cw * 0.7; const R = (B.tokens?.shape?.radius ?? 12) * (SHORT / 1080) * K;\n// a terminal is always dark, so its type is always light, whatever the brand's mode\nconst ground = B.color('ground'), muted = B.color('muted'), figure = '#EDEAE3', accent = B.color('accent', '#E9E4D8');\nconst GREEN = '#8fbf8f';\nObject.assign(term.style, { width: `${cw}px`, height: `${ch}px`, borderRadius: `${R}px`, background: '#070707', border: `1.5px solid ${muted}55`, boxShadow: `0 ${SHORT * 0.04}px ${SHORT * 0.12}px rgba(0,0,0,0.55)`, fontSize: `${wide ? cw * 0.022 : FS}px`, fontFamily: B.font('mono'), color: figure });\n$('bar').style.height = '2.6em'; $('bar').style.borderBottom = `1px solid ${muted}22`;\n$('bar').innerHTML = ['#ffffff33', '#ffffff22', '#ffffff18'].map((c) => `<i style=\"display:block;width:0.7em;height:0.7em;border-radius:50%;background:${c}\"></i>`).join('') + `<span style=\"margin:auto;color:${muted};font-size:0.75em\">zsh — ${CONFIG.cwd}</span>`;\nconst out = $('out');\nconst row = (html) => { const d = document.createElement('div'); d.className = 'ln'; d.innerHTML = html; out.append(d); return d; };\nconst prompt = row(`<span style=\"color:${muted}\">${CONFIG.cwd} </span><span style=\"color:${accent}\">$ </span><span id=\"cmd\"></span><span id=\"caret\" style=\"background:${accent}\"></span>`);\nconst work = row(`<span id=\"spin\" style=\"color:${accent}\"></span> <span style=\"color:${muted}\">${CONFIG.working}…</span>`);\nconst lines = CONFIG.output.map((o) => {\n  const d = row(`${o.check ? `<span class=\"ck\" style=\"color:${GREEN}\">✓</span>` : ''}<span style=\"color:${o.muted ? muted : o.accent ? accent : figure}\">${wide ? o.text : o.text.replace(/\\S+/g, (w) => `<span style=\"white-space:nowrap\">${w}</span>`)}</span>`);\n  if (o.result) { const h = document.createElement('div'); h.className = 'hl'; h.style.background = `${accent}26`; h.style.boxShadow = `inset 0.16em 0 0 ${accent}`; h.style.right = '-0.5em'; d.prepend(h); d.style.zIndex = 0; }\n  if (o.check) d.classList.add('ckr');\n  return d;\n});\nif (!wide) term.classList.add('narrow');\ncam.place(term, { x: 0, y: 0, z: 0 });\nawait document.fonts.ready;\n\nconst T = { type: [0.6, 1.5], enter: 1.65, done: 2.5, line: 0.2, result: 4.0 };\nconst lineAt = lines.map((_, i) => T.done + i * T.line + (i >= 4 ? 0.15 : 0));\nconst lineH = prompt.offsetHeight, outTop = out.offsetTop + parseFloat(getComputedStyle(out).paddingTop);\nconst SPIN = '⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏';\nconst cmd = $('cmd'), caret = $('caret'), spin = $('spin');\nconst shown = (u) => { let k = progress(u, T.enter, T.enter + 0.4, ease.inOutSine); lineAt.forEach((a) => { k += progress(u, a, a + 0.6, ease.inOutSine); }); return k; };   // continuous, so the camera glides   // rows visible after the prompt\nconst resIdx = CONFIG.output.findIndex((o) => o.result);\n// non-wide: measure the finished output once (every line shown), then the camera follows a continuous bottom edge\nconst P = SHORT * 1.7, pad = parseFloat(getComputedStyle(out).paddingTop);\nwork.style.display = 'none';\nconst lineHs = lines.map((d) => d.offsetHeight), resTop = out.offsetTop + lines[resIdx].offsetTop + lines[resIdx].offsetHeight / 2;\nif (!wide) { ch = Math.max(out.offsetTop + out.offsetHeight + lineH, tall ? (H * 0.86) / ((W * 0.94) / cw) : cw * 0.62); term.style.height = `${ch}px`; }\nconst bottomAt = (u) => {\n  let b = out.offsetTop + prompt.offsetTop + lineH * Math.round(prompt.offsetHeight / lineH) + lineH * progress(u, T.enter, T.enter + 0.4, ease.inOutSine) * (1 - progress(u, T.done, T.done + 0.6, ease.inOutSine));\n  lineAt.forEach((a, i) => { b += lineHs[i] * progress(u, a, a + 0.6, ease.inOutSine); });\n  return b;\n};\n\ns.update((t) => {\n  // the command, typed with a slightly uneven hand\n  const p = progress(t, ...T.type);\n  const n = Math.round(CONFIG.command.length * (p + 0.04 * Math.sin(p * 17) * (1 - p)) );\n  cmd.textContent = CONFIG.command.slice(0, Math.max(0, Math.min(CONFIG.command.length, n)));\n  caret.style.opacity = t < T.enter ? (t < T.type[0] || t > T.type[1] ? (Math.sin(t * 10) > 0 ? '1' : '0') : '1') : '0';\n  // the run: a spinner that turns into the first check\n  work.style.display = t >= T.enter ? '' : 'none';\n  work.style.opacity = t >= T.done ? '0' : '1';\n  work.style.height = t >= T.done ? '0' : '';\n  spin.textContent = SPIN[Math.floor(t * 14) % SPIN.length];\n  // the output, line by line, each check popping on a spring\n  lines.forEach((d, i) => {\n    const a = lineAt[i], v = t >= a;\n    d.style.display = v ? '' : 'none';\n    const e = progress(t, a, a + 0.15, ease.outCubic);\n    d.style.opacity = String(e); d.style.transform = `translateY(${(1 - e) * 0.3}em)`;\n    const ck = d.querySelector('.ck');\n    if (ck) ck.style.transform = `scale(${v ? 0.4 + 0.6 * spring(t - a, { stiffness: 380, damping: 14 }) : 0})`;\n  });\n  // the result lights up\n  const hl = lines[resIdx]?.querySelector('.hl');\n  if (hl) hl.style.transform = `scaleX(${progress(t, T.result, T.result + 0.45, ease.outCubic)})`;\n  // the camera: close on the prompt, riding the output down (smoothed), then onto the result\n  const arrive = progress(t, 0, 0.6, ease.outCubic), focus = progress(t, T.result - 0.2, T.result + 1.2, ease.inOutCubic);\n  let ry = 0; for (let j = 0; j < 8; j++) ry += Math.max(3.5, shown(t - j * 0.07)); ry /= 8;\n  const rideY = outTop + lineH * (ry - 2.5) - ch / 2;\n  const resY = outTop + (lines[resIdx].offsetTop - prompt.offsetTop) + lineH * 1.8 - ch / 2;\n  const y = rideY + (resY - rideY) * focus;\n  if (!wide) {\n    const sNow = ((W * 0.94) / cw) * (0.74 + 0.26 * arrive) * (1 + 0.05 * progress(t, 0.6, T.result, ease.inOutSine)) * (1 + (tall ? 0.05 : 0.07) * focus), half = H / (2 * sNow);\n    const x = Math.min(0, -cw / 2 + (W / 2) / sNow - FS * 0.6);\n    const lo = -ch / 2 + half - H * 0.06 / sNow, hi = ch / 2 - half + H * 0.04 / sNow;\n    const follow = bottomAt(t) - ch / 2 - half * 0.45, fy = follow + ((resTop + bottomAt(D)) / 2 - ch / 2 - follow) * focus;\n    const ny = lo <= hi ? Math.min(hi, Math.max(lo, fy)) : (lo + hi) / 2;\n    cam.at({ x, y: ny, z: P / sNow - P, yaw: -6 * (1 - arrive) + 1.5 * focus, pitch: 3 * (1 - arrive) });\n  } else\n  cam.at({ x: -cw * 0.2, y, z: DIST + SHORT * 0.3 * (1 - arrive) - SHORT * 1.0 - SHORT * 0.3 * focus, yaw: -6 * (1 - arrive) + 2 * focus, pitch: 3 * (1 - arrive) });\n  term.style.opacity = String(progress(t, 0, 0.3));\n});\nB.cue(s, 'transition', 0); B.cue(s, 'text', T.type[0]); B.cue(s, 'land', T.enter); B.cue(s, 'text', T.done); B.cue(s, 'land', T.result);\nB.sound(s);\nawait s.start();\n</script>\n</body>\n</html>\n"
    },
    {
      "path": "pieces/terminal-run/brief.md",
      "content": "# Terminal run\n\nBlock: terminal-run (6.2 s), from paper-motion.app. The look, fonts and sound come from `brand/`.\n\nA command types itself, a spinner works, the output streams in with its checks and the file it made lights up.\n\nA block is one ready-made moment. Edit `CONFIG` (its words, numbers and format: 16:9, 9:16 or 1:1, the layout recomposes for each); check `npx paper-motion still` at 0.6 and 1.5 s; render.\n"
    }
  ],
  "requires": {
    "engine": ">=0.2.6"
  },
  "usage": "npx paper-motion add terminal-run --name my-terminal-run\n# edit CONFIG in pieces/my-terminal-run/scene.html, then:\nnpx paper-motion render pieces/my-terminal-run/scene.html --motion-blur 5",
  "notes": [
    "Wired to the brand folder: needs brand/tokens.json (a palette and a font pair work) and, for the field, a shader-set entry.",
    "Recomposes for 16:9, 9:16 and 1:1: set `format` and the layout and camera follow."
  ],
  "related": [
    "code-type",
    "toast-stack"
  ],
  "preview": {
    "video": "previews/terminal-run.webm",
    "poster": "previews/terminal-run.jpg",
    "at": 5.4,
    "values": {
      "command": "npx paper-motion add push-in"
    }
  },
  "mood": [
    "technical"
  ],
  "duration": 6.2,
  "formats": [
    "16:9",
    "9:16",
    "1:1"
  ],
  "beats": [
    {
      "name": "Arrive",
      "from": 0,
      "to": 0.6,
      "what": "arrive"
    },
    {
      "name": "Type",
      "from": 0.6,
      "to": 1.5,
      "what": "type"
    },
    {
      "name": "Run",
      "from": 1.65,
      "to": 2.5,
      "what": "run"
    },
    {
      "name": "Output",
      "from": 2.5,
      "to": 3.7,
      "what": "output"
    },
    {
      "name": "Result",
      "from": 4,
      "to": 4.6,
      "what": "result"
    },
    {
      "name": "Hold",
      "from": 4.6,
      "to": 6.2,
      "what": "hold"
    }
  ],
  "when": [
    "install and run steps",
    "a CLI doing its job"
  ],
  "needs": [
    {
      "kind": "command",
      "fill": {
        "cwd": "$cwd",
        "command": "$command",
        "working": "$working",
        "output": "$output"
      }
    }
  ]
}