Claude's answers, rendered: Markdown, math, charts and diagrams drawn in the Claude Code terminal. Independent project, not affiliated with Anthropic.
TypeScript claude-code-mod
<!doctype html>
<html lang="en" data-theme="dark">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Intelligent UI for Claude Code</title>
<meta name="description" content="Claude's answers, rendered. Real Markdown, LaTeX math, charts and diagrams, right in your terminal.">
<meta property="og:type" content="website">
<meta property="og:url" content="https://intelligentui.art/">
<link rel="canonical" href="https://intelligentui.art/">
<meta property="og:title" content="Intelligent UI for Claude Code">
<meta property="og:description" content="Claude's answers, rendered. Real Markdown, math, charts and diagrams, right in your terminal.">
<meta property="og:image" content="https://intelligentui.art/assets/og.jpg">
<meta name="twitter:card" content="summary_large_image">
<link rel="icon" href="assets/logo.svg" type="image/svg+xml">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Instrument+Serif:ital@0;1&family=Geist:wght@400;500;600&family=JetBrains+Mono:wght@400;700&display=swap" rel="stylesheet">
<script>
// The theme before the first paint: the saved choice, else the system's.
(() => {
let t = null;
try { t = localStorage.getItem("iui-theme"); } catch {}
if (t !== "dark" && t !== "light") t = matchMedia("(prefers-color-scheme: light)").matches ? "light" : "dark";
document.documentElement.dataset.theme = t;
})();
</script>
<style>
/* ---------- Page colours: flat, no gradient ---------- */
:root {
--serif: "Instrument Serif", "Iowan Old Style", Georgia, serif;
--sans: "Geist", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
--ui: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Helvetica Neue", "Geist", sans-serif;
--mono: "MesloLGS NF", Menlo, "JetBrains Mono", ui-monospace, monospace;
--clay: #d97757;
--gutter: clamp(16px, 4vw, 40px);
}
:root[data-theme="dark"] {
color-scheme: dark;
--bg: #14161f;
--ink: #f3ece2;
--muted: #9b948c;
--line: rgba(243, 236, 226, 0.12);
--chip: rgba(243, 236, 226, 0.06);
--accent: #f0a07f;
--shadow: 0 30px 70px -30px rgba(0, 0, 0, 0.7);
/* Claude Code 2.1.301, dark (outcomes/frame.typ) */
--t-bg: #283237; --t-fg: #ffffff; --t-dim: #a7a5a5; --t-bar: #21211f; --t-title: #b6b6b4;
--t-edge: #3c4448; --t-sep: #7a7b7c; --t-ask: #343e43; --t-green: #52c96a; --t-mode: #ffd301;
}
:root[data-theme="light"] {
color-scheme: light;
--bg: #fdf6ee;
--ink: #1d1d1f;
--muted: #6d6863;
--line: rgba(29, 29, 31, 0.12);
--chip: rgba(29, 29, 31, 0.05);
--accent: #c25a38;
--shadow: 0 30px 70px -30px rgba(0, 0, 0, 0.22);
/* Claude Code 2.1.301, light (outcomes/frame.typ) */
--t-bg: #ffffff; --t-fg: #1f1f1f; --t-dim: #6e6e6e; --t-bar: #ececec; --t-title: #4d4d4d;
--t-edge: #d4d4d4; --t-sep: #b5b5b5; --t-ask: #f0f0f0; --t-green: #2f9e4b; --t-mode: #a07400;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
margin: 0; min-height: 100vh; overflow-x: hidden;
background: var(--bg); color: var(--ink);
font: 400 16px/1.55 var(--sans);
-webkit-font-smoothing: antialiased;
}
a { color: inherit; }
img { display: block; }
:focus-visible { outline: 2px solid var(--clay); outline-offset: 3px; border-radius: 6px; }
.wrap { width: min(100% - 2 * var(--gutter), 1120px); margin-inline: auto; }
/* ---------- Nav ---------- */
.nav { position: absolute; inset: 0 0 auto; z-index: 10; }
.nav .wrap { display: flex; align-items: center; justify-content: space-between; height: 68px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; text-decoration: none; letter-spacing: -0.01em; }
.brand img { width: 26px; height: 26px; border-radius: 7px; display: block; }
.nav-r { display: flex; gap: 6px; }
.icon-btn {
display: inline-flex; align-items: center; gap: 8px; height: 38px; padding: 0 14px;
border-radius: 999px; border: 1px solid var(--line); background: var(--chip); color: var(--ink);
font: 500 14px/1 var(--sans); text-decoration: none; cursor: pointer;
}
.icon-btn:hover { border-color: var(--muted); }
.icon-btn svg { width: 16px; height: 16px; }
.icon-btn.sq { width: 38px; padding: 0; justify-content: center; }
:root[data-theme="dark"] .sun, :root[data-theme="light"] .moon { display: none; }
/* ---------- Hero ---------- */
.hero { padding: 64px 0 0; text-align: center; }
h1 { margin: 0 0 clamp(14px, 1.8vw, 22px); font: 400 clamp(34px, 4.8vw, 60px)/0.95 var(--serif); letter-spacing: -0.025em; }
h1 em { font-style: italic; padding-right: 0.05em; color: var(--clay); }
.cmd {
display: inline-flex; align-items: center; gap: 10px; max-width: 100%;
margin-top: 22px; padding: 6px 6px 6px 16px; border-radius: 12px;
background: var(--chip); border: 1px solid var(--line);
font: 400 13.5px/1.3 var(--mono);
}
.cmd code { font: inherit; white-space: nowrap; overflow-x: auto; scrollbar-width: none; min-width: 0; }
.cmd code::-webkit-scrollbar { display: none; }
.cmd b { color: var(--clay); font-weight: 400; }
.copy {
flex: none; height: 30px; padding: 0 11px; border-radius: 8px; cursor: pointer;
border: 1px solid var(--line); background: var(--chip); color: var(--ink); font: 500 12.5px/1 var(--sans);
}
.copy:hover { border-color: var(--muted); }
.copy.done { color: #52c96a; }
/* Four dots: one per answer; the one on shows its time left. Under the window when
the screen is tall; in the middle of the window's last line when it is wide. */
.hero-box { position: relative; }
.dock { margin: 12px 0 0; }
@media (orientation: landscape) {
.dock { position: absolute; left: 50%; top: var(--dock-y, auto); bottom: auto; margin: 0; z-index: 5; transform: translate(-50%, -50%); }
}
.tabs { display: inline-flex; gap: 2px; }
.tab { position: relative; cursor: pointer; border: 0; padding: 8px 4px; background: none; }
.tab .bar { display: block; width: 8px; height: 8px; border-radius: 999px; overflow: hidden; background: var(--line); transition: width 0.3s, background 0.2s; }
.tab:hover .bar { background: var(--muted); }
.tab[aria-selected="true"] .bar { width: 28px; background: color-mix(in srgb, var(--clay) 30%, var(--line)); }
.tab .bar i { display: block; height: 100%; width: calc(var(--p, 0) * 100%); background: var(--clay); }
.tab:not([aria-selected="true"]) .bar i { display: none; }
.tab:focus-visible { outline: 2px solid var(--clay); outline-offset: 2px; border-radius: 999px; }
.stage { position: relative; width: min(100%, 860px); margin: 0 auto; }
.stage > .t-wrap {
position: absolute; inset: 0 0 auto; opacity: 0; transform: translateY(10px) scale(0.99); pointer-events: none;
transition: opacity 0.5s, transform 0.7s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.stage > .t-wrap.on { position: relative; opacity: 1; transform: none; pointer-events: auto; }
/* ---------- The terminal (outcomes/frame.typ; sizes in pt of the frame) ---------- */
.t-wrap { container-type: inline-size; text-align: left; }
.term {
--pt: calc(100cqw / var(--f));
background: var(--t-bg); color: var(--t-fg);
border: max(1px, calc(var(--pt) * 0.6)) solid var(--t-edge);
border-radius: calc(var(--pt) * 10); overflow: hidden;
box-shadow: var(--shadow);
font: 400 calc(var(--pt) * 8.5)/1.42 var(--mono);
}
.t-bar {
display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: calc(var(--pt) * 12);
padding: calc(var(--pt) * 8) calc(var(--pt) * 10); background: var(--t-bar); font-family: var(--ui);
}
.t-lights { display: flex; gap: calc(var(--pt) * 6); }
.t-lights i { width: calc(var(--pt) * 8.4); height: calc(var(--pt) * 8.4); border-radius: 50%; background: #ff5f57; }
.t-lights i:nth-child(2) { background: #febc2e; }
.t-lights i:nth-child(3) { background: #28c840; }
.t-title { font-size: calc(var(--pt) * 9); font-weight: 600; color: var(--t-title); }
.t-key { font-size: calc(var(--pt) * 8); color: var(--t-dim); }
.t-body { padding: calc(var(--pt) * 12) calc(var(--pt) * 8) calc(var(--pt) * 8); }
.t-head { display: flex; align-items: center; gap: calc(var(--pt) * 9); line-height: 1.3; margin-bottom: calc(var(--pt) * 14); }
.t-head svg { width: calc(var(--pt) * 31.5); flex: none; }
.t-dim { color: var(--t-dim); }
.t-green { color: var(--t-green); }
.t-ask { background: var(--t-ask); padding: calc(var(--pt) * 4); white-space: pre; overflow: hidden; }
.t-answer { position: relative; display: grid; grid-template-columns: calc(var(--pt) * 12) auto; margin-top: calc(var(--pt) * 12); }
.t-dot { position: absolute; left: calc(var(--pt) * 3); top: var(--dot); transform: translateY(-50%); font-size: calc(var(--pt) * 8); line-height: 1; }
.t-spin { position: absolute; left: 0; top: var(--dot); transform: translateY(-50%); line-height: 1; white-space: nowrap; color: var(--t-dim); }
.t-spin b { font-weight: 400; color: var(--clay); display: inline-block; width: 1ch; }
.t-spin i { font-style: normal; color: var(--clay); }
.t-pic { grid-column: 2; position: relative; width: calc(var(--pt) * var(--w)); aspect-ratio: var(--ar); }
.t-pic img { position: absolute; inset: 0; width: 100%; height: 100%; }
.t-brew { margin-top: calc(var(--pt) * 10); color: var(--t-dim); }
.t-status { margin-top: auto; padding-top: calc(var(--pt) * 26); text-align: right; color: var(--t-dim); }
.t-rule { height: max(1px, calc(var(--pt) * 0.5)); background: var(--t-sep); }
.t-input { padding: calc(var(--pt) * 2) 0; white-space: pre; }
.t-cur {
display: inline-block; width: calc(var(--pt) * 5.2); height: calc(var(--pt) * 9);
background: var(--t-fg); vertical-align: calc(var(--pt) * -1.5); animation: blink 1.05s steps(1) infinite;
}
.term.typing .t-cur { animation: none; }
.t-cur[hidden] { display: none; }
@keyframes blink { 50% { opacity: 0; } }
.t-mode { padding-top: calc(var(--pt) * 2); color: var(--t-dim); }
.t-mode b { font-weight: 400; color: var(--t-mode); }
.t-mode svg { width: calc(var(--pt) * 4.2); height: calc(var(--pt) * 5.2); fill: var(--t-mode); margin-right: calc(var(--pt) * 0.8); }
/* The answer, step by step: typing → asked → working (spinner) → answered (the picture draws) → done */
.t-head + .t-ask, .t-dot, .t-spin, .t-brew { opacity: 0; transition: opacity 0.3s; }
.term.asked .t-ask { opacity: 1; }
.term.working .t-spin, .term.answered .t-dot, .term.done .t-brew { opacity: 1; }
.t-pic { clip-path: inset(0 0 100% 0); opacity: 0; }
.term.answered .t-pic {
clip-path: inset(0 0 0 0); opacity: 1;
transition: opacity 0.35s;
}
/* A window keeps one height: the answer fills it from the top, the input box stays at the bottom. */
.term.full { display: flex; flex-direction: column; }
.term.full .t-body { flex: 1; min-height: 0; display: flex; flex-direction: column; }
/* The transcript follows a tall answer as it draws, as a terminal does; then you can scroll it. */
.term.full .t-scroll {
flex: 1; min-height: 0; overflow-y: auto;
scrollbar-width: thin; scrollbar-color: var(--t-sep) transparent;
}
/* ---------- Gallery ---------- */
.gallery { padding: clamp(96px, 14vw, 160px) 0 40px; }
.gallery .kicker { text-align: center; margin: 0 0 44px; font: italic 400 clamp(30px, 4vw, 44px)/1 var(--serif); color: var(--muted); }
/* All the cards have one height (the tallest's); a shorter answer leaves room under it, as a terminal does. */
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 400px), 1fr)); grid-auto-rows: 1fr; gap: 32px 28px; }
.card { margin: 0; display: flex; flex-direction: column; }
.card > .t-wrap { flex: 1; display: flex; flex-direction: column; }
.card .term { flex: 1; display: flex; flex-direction: column; }
.card .t-body { flex: 1; }
.card figcaption {
margin-top: 12px; display: flex; justify-content: space-between; align-items: center; gap: 12px;
font: 500 12px/1 var(--mono); letter-spacing: 0.05em; text-transform: uppercase; color: var(--muted);
}
.replay {
cursor: pointer; padding: 6px 10px; border-radius: 8px; border: 1px solid var(--line);
background: var(--chip); color: var(--ink); font: inherit; letter-spacing: inherit; text-transform: inherit;
}
.replay:hover { border-color: var(--muted); }
/* ---------- Footer ---------- */
footer { padding: 72px 0 56px; text-align: center; }
footer .big { margin: 0; font: 400 clamp(36px, 5vw, 60px)/1 var(--serif); }
footer .big em { font-style: italic; color: var(--accent); }
.install { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; justify-items: center; margin-top: 28px; }
.install .cmd { margin: 0; }
.install .or { margin: 0; color: var(--muted); font-size: 13px; }
.links { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; margin-top: 28px; }
.fine { margin: 40px auto 0; max-width: 620px; color: var(--muted); font-size: 13px; }
@media (prefers-reduced-motion: reduce) {
.stage > .t-wrap, .term.answered .t-pic { transition: none !important; }
.t-cur { animation: none !important; }
}
</style>
</head>
<body>
<header class="nav">
<div class="wrap">
<a class="brand" href="./"><img src="assets/logo.svg" alt="" width="26" height="26">Intelligent UI</a>
<div class="nav-r">
<button class="icon-btn sq" id="theme" type="button" aria-label="Switch light or dark">
<svg class="moon" viewBox="0 0 16 16" fill="currentColor" aria-hidden="true"><path d="M6.2 1.5a6.5 6.5 0 108.3 8.3A5.5 5.5 0 016.2 1.5z"/></svg>
<svg class="sun" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" aria-hidden="true"><circle cx="8" cy="8" r="3"/><path d="M8 1v1.5M8 13.5V15M1 8h1.5M13.5 8H15M3 3l1 1M12 12l1 1M3 13l1-1M12 4l1-1"/></svg>
</button>
<a class="icon-btn" href="https://github.com/razorback16/cc-intelligent-ui">
<svg viewBox="0 0 16 16" fill="currentColor" aria-hidden="true"><path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0016 8c0-4.42-3.58-8-8-8z"/></svg>
GitHub
</a>
</div>
</div>
</header>
<main>
<section class="hero">
<div class="wrap">
<h1>Claude’s answers, <em>rendered.</em></h1>
<div class="hero-box" id="hero-box">
<div class="stage" id="stage"></div>
<div class="dock" id="dock"><div class="tabs" role="tablist" aria-label="Example answers" id="tabs"></div></div>
</div>
<div><div class="cmd">
<code><b>$ </b>curl -fsSL https://intelligentui.art/install.sh | bash</code>
<button class="copy" type="button" data-copy="curl -fsSL https://intelligentui.art/install.sh | bash">Copy</button>
</div></div>
</div>
</section>
<section class="gallery" aria-label="More answers">
<div class="wrap">
<p class="kicker">and more, drawn live</p>
<div class="grid" id="grid"></div>
</div>
</section>
</main>
<footer>
<div class="wrap">
<p class="big">Ask once. <em>See it.</em></p>
<div class="install">
<div class="cmd"><code><b>$ </b>curl -fsSL https://intelligentui.art/install.sh | bash</code><button class="copy" type="button" data-copy="curl -fsSL https://intelligentui.art/install.sh | bash">Copy</button></div>
<p class="or">or by hand</p>
<div class="cmd"><code><b>$ </b>brew install typst</code><button class="copy" type="button" data-copy="brew install typst">Copy</button></div>
<div class="cmd"><code><b>/</b>plugin install cc-intelligent-ui --marketplace razorback16/cc-intelligent-ui</code><button class="copy" type="button" data-copy="/plugin install cc-intelligent-ui --marketplace razorback16/cc-intelligent-ui">Copy</button></div>
</div>
<div class="links">
<a class="icon-btn" href="https://github.com/razorback16/cc-intelligent-ui">GitHub</a>
<a class="icon-btn" href="install.sh">install.sh</a>
<a class="icon-btn" href="https://github.com/razorback16/cc-intelligent-ui/blob/main/docs/install.md">Install guide</a>
</div>
<p class="fine">Needs Claude Code 2.1.298 or later, Typst 0.15, and macOS or Linux. An independent, community-made mod, not affiliated with or endorsed by Anthropic. Claude and Claude Code are trademarks of Anthropic, PBC. MIT licence.</p>
</div>
</footer>
<script src="assets/answers.js?v=c207e323"></script>
<script>
(() => {
const answers = window.IUI_ANSWERS;
const reduce = matchMedia("(prefers-reduced-motion: reduce)").matches;
const root = document.documentElement;
const theme = () => root.dataset.theme;
const src = (a, t = theme()) => `assets/render/${a.name}-${t}.webp?v=${a.v}`;
const esc = (s) => s.replace(/[&<>"]/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """ }[c]));
// The Claude Code mascot and the mode line's triangle (outcomes/frame.typ).
const mascot = '<svg viewBox="0 0 75 48" aria-hidden="true"><g fill="#d77757"><rect x="9" width="57" height="36"/><rect y="20" width="75" height="8"/><rect x="9" y="36" width="4" height="12"/><rect x="18" y="36" width="4" height="12"/><rect x="52" y="36" width="4" height="12"/><rect x="61" y="36" width="4" height="12"/></g><g fill="#050302"><rect x="18" y="8" width="4" height="12"/><rect x="52" y="8" width="4" height="12"/></g></svg>';
const tri = '<svg viewBox="0 0 4.2 5.2" aria-hidden="true"><path d="M0 0l4.2 2.6L0 5.2z"/></svg>';
/* ---------- A Claude Code window around one answer ---------- */
// full: the header, the input box and the mode line, as in outcomes/frame.typ.
// Else the title bar, the prompt and the answer only; the prompt types in place.
function terminal(a, full) {
const wrap = document.createElement("div");
wrap.className = "t-wrap";
wrap.innerHTML = `
<div class="term" style="--f:${a.frame + 40};--w:${a.frame};--h:${a.frame * a.ratio};--ar:${1 / a.ratio};--dot:calc(var(--pt) * ${a.frame * a.bullet})">
<div class="t-bar" aria-hidden="true"><span class="t-lights"><i></i><i></i><i></i></span><span class="t-title">Claude Code</span><span class="t-key">⌥⌘1</span></div>
<div class="t-body"><div class="t-scroll"${full ? ' tabindex="0" aria-label="Transcript"' : ""}>
${full ? `<div class="t-head" aria-hidden="true">${mascot}<div><b>Claude Code</b> <span class="t-dim">v2.1.301</span><br><span class="t-dim">Opus 5.5 with high effort · Claude Max</span><br><span class="t-dim">~/projects/cc-intelligent-ui ·</span> <span class="t-green">/rc</span></div></div>` : ""}
<div class="t-ask">❯ <span class="q"></span>${full ? "" : '<span class="t-cur"></span>'}</div>
<div class="t-answer">
<span class="t-spin" aria-hidden="true"><b>✻</b> <i>Brewing…</i> <span></span></span>
<span class="t-dot" aria-hidden="true">●</span>
<div class="t-pic"><img src="${src(a)}" alt="Claude's answer to “${esc(a.ask)}”, drawn by Intelligent UI" decoding="async"></div>
</div>
<div class="t-brew">✻ Brewed for ${a.brew}s</div></div>
${full ? `<div class="t-status">● high · /effort</div><div class="t-rule"></div><div class="t-input">❯ <span class="in"></span><span class="t-cur"></span></div><div class="t-rule"></div><div class="t-mode"><b>${tri}${tri} auto mode on</b> (shift+tab to cycle)</div>` : ""}
</div>
</div>`;
const t = wrap.firstElementChild;
const q = t.querySelector(".q"), input = t.querySelector(".in") || q;
const cur = full ? null : t.querySelector(".t-ask .t-cur");
const spin = t.querySelector(".t-spin b"), secs = t.querySelector(".t-spin span");
const box = t.querySelector(".t-scroll"), pic = t.querySelector(".t-pic");
// A scroll by the reader stops the transcript from following the drawing.
let manual = false;
for (const e of ["wheel", "touchmove", "keydown"]) box.addEventListener(e, () => { manual = true; }, { passive: true });
let run = 0;
// The steps' times (ms); length is the whole animation, for the hero's timer.
const key = (i) => 30 + (i % 3) * 8, draw = 1000 + a.ratio * 600;
const length = 450 + [...a.ask].reduce((n, _, i) => n + key(i), 0) + 320 + 12 * 110 + draw;
const show = (...cls) => { t.className = ["term", full && "full", ...cls].filter(Boolean).join(" "); };
const reset = () => { run++; q.textContent = ""; if (input !== q) input.textContent = ""; if (cur) cur.hidden = false; pic.style.clipPath = ""; box.scrollTop = 0; full ? show() : show("asked"); };
const final = () => { run++; q.textContent = a.ask; if (input !== q) input.textContent = ""; if (cur) cur.hidden = true; show("asked", "answered", "done"); };
// The answer as it happens: type the prompt, send it, think, draw.
async function play() {
if (reduce) return final();
reset();
const id = run;
const wait = (ms) => new Promise((r) => setTimeout(r, ms)).then(() => { if (id !== run) throw 0; });
try {
await wait(450);
show(full ? "typing" : "asked typing");
for (const [i, ch] of [...a.ask].entries()) { input.textContent += ch; await wait(key(i)); }
await wait(320);
if (input !== q) input.textContent = "";
if (cur) cur.hidden = true;
q.textContent = a.ask;
show("asked", "working");
const glyphs = "·✢✳✶✻✽✻✶✳✢";
for (let i = 0; i < 12; i++) {
spin.textContent = glyphs[i % glyphs.length];
secs.textContent = `(${1 + Math.floor(i / 9)}s · esc to interrupt)`;
await wait(110);
}
// Draw the picture from the top, and keep its edge in view.
manual = false;
const ms = 900 + a.ratio * 600, over = box.scrollHeight - box.clientHeight, t0 = performance.now();
const ease = (p) => (p < 0.5 ? 4 * p ** 3 : 1 - (2 - 2 * p) ** 3 / 2);
pic.style.clipPath = "inset(0 0 100% 0)";
show("asked", "answered");
await new Promise((done) => requestAnimationFrame(function step(now) {
if (id !== run) return done();
const e = ease(Math.min((now - t0) / ms, 1));
pic.style.clipPath = `inset(0 0 ${(1 - e) * 100}% 0)`;
if (!manual && over > 0) box.scrollTop = e * over;
if (e < 1) requestAnimationFrame(step); else { pic.style.clipPath = ""; done(); }
}));
await wait(draw - ms);
show("asked", "answered", "done");
} catch {}
}
return { el: wrap, term: t, a, length, play, reset, final, img: t.querySelector("img") };
}
/* ---------- Hero: four answers that take turns ---------- */
const tabsEl = document.getElementById("tabs"), stage = document.getElementById("stage");
const heroes = answers.filter((a) => a.group === "hero").map((a) => terminal(a, true));
const tabs = heroes.map((h, i) => {
const b = document.createElement("button");
b.className = "tab"; b.type = "button"; b.id = `tab-${i}`;
b.setAttribute("role", "tab");
b.innerHTML = `<span class="bar" aria-hidden="true"><i></i></span>`;
b.setAttribute("aria-label", h.a.label); b.title = h.a.label;
h.el.id = `panel-${i}`;
h.el.setAttribute("role", "tabpanel");
h.el.setAttribute("aria-labelledby", b.id);
b.setAttribute("aria-controls", h.el.id);
tabsEl.append(b); stage.append(h.el);
return b;
});
// All four windows have one height, so nothing moves when the tab changes: the tallest
// answer's, but no more than fits on the screen (and the dots, when under it), so the input box shows.
const wide = matchMedia("(orientation: landscape)");
const box = document.getElementById("hero-box"), dock = document.getElementById("dock");
// On a wide screen the dots sit on the middle of the last line ("auto mode on").
const placeDock = () => {
if (!wide.matches) return;
const r = heroes[Math.max(at, 0)].el.querySelector(".t-mode").getBoundingClientRect();
dock.style.setProperty("--dock-y", `${r.top + r.height / 2 - box.getBoundingClientRect().top}px`);
};
const level = () => {
heroes.forEach((h) => { h.term.style.height = ""; });
const tallest = Math.max(...heroes.map((h) => h.term.offsetHeight));
const room = innerHeight - (stage.getBoundingClientRect().top + scrollY) - (wide.matches ? 24 : 60);
const px = Math.min(tallest, Math.max(380, room));
heroes.forEach((h) => { h.term.style.height = px + "px"; });
placeDock();
};
let at = -1;
level();
wide.addEventListener("change", level);
document.fonts?.ready.then(placeDock);
// Not for the small height changes of a phone's address bar, which would make it jump.
let size = [innerWidth, innerHeight];
addEventListener("resize", () => {
if (innerWidth === size[0] && Math.abs(innerHeight - size[1]) < 150) return;
size = [innerWidth, innerHeight];
level();
});
const HOLD = 3000; // the finished answer stays this long
let elapsed = 0, hover = false;
// Take turns only while the hero is on screen.
let seen = true;
if ("IntersectionObserver" in window) new IntersectionObserver(([e]) => { seen = e.isIntersecting; }, { threshold: 0.2 }).observe(stage);
function select(i, focus) {
i = (i + heroes.length) % heroes.length;
const old = heroes[at];
if (old && at !== i) setTimeout(() => { if (!old.el.classList.contains("on")) old.reset(); }, 600);
at = i; elapsed = 0;
heroes.forEach((h, j) => {
const on = j === i;
h.el.classList.toggle("on", on);
h.el.toggleAttribute("inert", !on);
tabs[j].setAttribute("aria-selected", on);
tabs[j].tabIndex = on ? 0 : -1;
tabs[j].style.setProperty("--p", 0);
});
heroes[i].play();
if (focus) tabs[i].focus();
}
tabs.forEach((b, i) => {
b.addEventListener("click", () => select(i));
b.addEventListener("keydown", (e) => {
const k = { ArrowRight: 1, ArrowLeft: -1 }[e.key];
if (k) { e.preventDefault(); select(at + k, true); }
});
});
stage.addEventListener("pointerenter", (e) => { if (e.pointerType === "mouse") hover = true; });
stage.addEventListener("pointerleave", (e) => { if (e.pointerType === "mouse") hover = false; });
// On a touch screen there is no hover: a touch stops the turns for 8 s.
let touchHold = 0;
stage.addEventListener("touchstart", () => {
hover = true; clearTimeout(touchHold);
touchHold = setTimeout(() => { hover = false; }, 8000);
}, { passive: true });
let last = performance.now();
function tick(now) {
const dt = Math.min(now - last, 100); last = now;
if (!reduce && !hover && seen && !document.hidden) {
elapsed += dt;
const total = heroes[at].length + HOLD;
tabs[at].style.setProperty("--p", Math.min(elapsed / total, 1));
if (elapsed >= total) select(at + 1);
}
requestAnimationFrame(tick);
}
heroes.forEach((h) => h.reset());
select(0);
requestAnimationFrame((t) => { last = t; tick(t); });
/* ---------- Gallery: each answer shows finished; Replay plays it again ---------- */
const grid = document.getElementById("grid");
const cards = answers.filter((a) => a.group === "gallery").map((a) => {
const t = terminal(a, false);
t.img.loading = "lazy";
const fig = document.createElement("figure");
fig.className = "card";
fig.append(t.el);
fig.insertAdjacentHTML("beforeend", `<figcaption><span>${esc(a.label)}</span><button class="replay" type="button" aria-label="Replay ${esc(a.label)}">↻ Replay</button></figcaption>`);
fig.querySelector(".replay").addEventListener("click", () => t.play());
t.final();
grid.append(fig);
return { fig, t };
});
/* ---------- Light or dark: the page, the terminals and the pictures ---------- */
const all = [...heroes, ...cards.map((c) => c.t)];
document.getElementById("theme").addEventListener("click", () => {
root.dataset.theme = theme() === "dark" ? "light" : "dark";
try { localStorage.setItem("iui-theme", theme()); } catch {}
all.forEach((t) => { t.img.src = src(t.a); });
});
// Warm the other theme's hero pictures, so the switch is instant.
addEventListener("load", () => heroes.forEach((h) => { new Image().src = src(h.a, theme() === "dark" ? "light" : "dark"); }));
/* ---------- Copy ---------- */
document.querySelectorAll("[data-copy]").forEach((b) => b.addEventListener("click", async () => {
try { await navigator.clipboard.writeText(b.dataset.copy); } catch {
const ta = Object.assign(document.createElement("textarea"), { value: b.dataset.copy });
document.body.append(ta); ta.select();
try { document.execCommand("copy"); } catch {}
ta.remove();
}
b.classList.add("done"); b.textContent = "Copied";
setTimeout(() => { b.classList.remove("done"); b.textContent = "Copy"; }, 1500);
}));
})();
</script>
</body>
</html>