Activity mark
FreeWhat an agent is doing right now, acted out on a 5 by 5 grid at 16px or larger: a radar sweep while it searches, a reading head through text, a question mark when it needs you. 36 activities.
npx shadcn@latest add https://pixilui.com/r/thinking-mark.jsonPreview
import { ThinkingMark, thinkingMarkName, thinkingMarkStates, useThinkingMarkSimulation, type ThinkingMarkState, type ThinkingMarkStep } from "@/components/pixilui/thinking-mark";
// The first option of each knob is the demo's default; the docs preview starts there. Every one of the 36 marks, in
// the lock's order (thinkingMarkGroups), after the lock's "Play through all 36".
export const knobs = {
state: [
"play through all 36",
"thinking", "planning", "remembering", "comparing", "brainstorming", "deciding",
"searching", "reading", "browsing", "indexing", "fetching", "analyzing",
"writing", "editing", "summarizing", "translating", "generating", "compacting",
"running", "testing", "debugging", "building", "deploying", "merging",
"listening", "speaking", "asking", "waiting", "calling", "delegating",
"idle", "queued", "paused", "retrying", "done", "failed",
],
variant: ["blocks", "grid"],
} as const;
// the lock's play-through: each mark in turn, 2.6s apiece
const ALL: ThinkingMarkStep[] = thinkingMarkStates.map((s) => ({ state: s.id, ms: 2600 }));
/** The mark at the lock's live size (176), and beside its name at 16px as a working line leads with it: all 36 in turn, or one held. */
export default function ThinkingMarkDemo({ state = "play through all 36", variant = "blocks" }: KnobValues<typeof knobs>) {
const all = state === "play through all 36";
const run = useThinkingMarkSimulation({ steps: ALL, autoplay: all });
const now: ThinkingMarkState = all ? run.state : state;
return (
<div className="flex w-full max-w-md flex-col items-center gap-6 rounded-panel bg-surface p-8 elevation-raised">
<ThinkingMark state={now} size={176} variant={variant} />
<div className="flex items-center gap-2 type-label">
<ThinkingMark state={now} size={16} variant={variant} />
<span className="text-foreground">{thinkingMarkName(now)}</span>
</div>
</div>
);
}When to use
Use it when
- Leading the reasoning trail's folded working line: the mark, what it is doing in words ("Reading 2 of 2 sources") and the time.
- A tool call or a run row that is working: the 16px mark next to its words.
- Any of the 36 activities: thinking, planning, remembering, comparing, brainstorming, deciding; searching, reading, browsing, indexing, fetching, analyzing; writing, editing, summarizing, translating, generating, compacting; running, testing, debugging, building, deploying, merging; listening, speaking, asking, waiting, calling, delegating; idle, queued, paused, retrying, done, failed.
Use something else when
- The agent's face: use the agent avatar. The mark doesn't sit beside it.
- A run's status in a pill: use agent status.
- Decoration: it means the agent is doing that thing now.
Installation
npx shadcn@latest add https://pixilui.com/r/thinking-mark.jsonAdds thinking-mark.tsx, and installs clsx and tailwind-merge. The URL works in any app with a components.json, with no registry to add first.
"use client";
import { forwardRef, useEffect, useImperativeHandle, useLayoutEffect, useRef, useState, type ComponentPropsWithoutRef } from "react";
import { cn } from "./lib/utils";
/*
The agent activity mark (H1, locked 30 Nov 2026): 36 animated marks for what an agent is doing, drawn on a 5 by 5
grid of cells on a canvas. A port of the locked activity-mark.js: every state is a pure function of time, rasterised
onto the 25 cells, so motion between cells is a hand-off of brightness. Its colours and shared timings are the locked
tokens in foundation.css section 8 (--pixilui-activity-mark-*); each state's own loop (its periods and easing) is part
of its drawing and stays here, as in the lock. The lock wins over the token and motion rules for this renderer, as it
does for the animated icons: the canvas is painted with colour strings it builds itself.
Two styles. 'blocks' (default): lit cells butt together into one shape and are told apart only by small shifts of tone
between neighbours; at large sizes the shape's outside corners are rounded and its inside corners get a matching
fillet. 'grid': cells sit apart in visible sockets. At 16 to 28px the pitch is a whole number of device pixels, so every
cell is a crisp pixel block.
A state is a function of time (seconds) returning marks [x, y, v, kind, family?] in cell units (fractional allowed):
v 0..1 intensity
kind 'sq' lit cell, 'dot' a dimmer light, 'ring' a slot (keeps a window), 'bar' text (joined into a line in grid style)
family optional override of the state's colour for that one cell (a failing test, a bug, a selection)
*/
/** The 36 activities, in board order. */
export type ThinkingMarkState =
| "thinking" | "planning" | "remembering" | "comparing" | "brainstorming" | "deciding"
| "searching" | "reading" | "browsing" | "indexing" | "fetching" | "analyzing"
| "writing" | "editing" | "summarizing" | "translating" | "generating" | "compacting"
| "running" | "testing" | "debugging" | "building" | "deploying" | "merging"
| "listening" | "speaking" | "asking" | "waiting" | "calling" | "delegating"
| "idle" | "queued" | "paused" | "retrying" | "done" | "failed";
/** The colour families: thinking periwinkle, finding sky, writing orange, coding teal, with-you pink, done mint, failed coral, status grey. */
export type ThinkingMarkFamily = "think" | "find" | "make" | "wait" | "done" | "fail" | "code" | "idle";
export type ThinkingMarkTheme = "light" | "dark";
/** blocks: one moulded shape (default). grid: cells in visible sockets. */
export type ThinkingMarkStyle = "blocks" | "grid";
type Kind = "dot" | "sq" | "ring" | "bar";
type Mark = [number, number, number, Kind] | [number, number, number, Kind, ThinkingMarkFamily];
type RGB = [number, number, number];
type Pt = [number, number];
/** One activity: its id, its English name, its family and its drawing. */
export type ThinkingMarkStateDef = { id: ThinkingMarkState; name: string; fam: ThinkingMarkFamily; f: (t: number) => Mark[] };
const N = 5;
const PI = Math.PI, TAU = PI * 2;
const hash = (i: number) => { const t = Math.sin(i * 127.1 + 311.7) * 43758.5453; return t - Math.floor(t); };
const clamp = (v: number, a = 0, b = 1) => Math.max(a, Math.min(b, v));
const ss = (a: number, b: number, x: number) => { const t = clamp((x - a) / (b - a)); return t * t * (3 - 2 * t); };
const eio = (t: number) => t < .5 ? 4 * t * t * t : 1 - Math.pow(-2 * t + 2, 3) / 2;
const pop = (t: number, d = .12) => t <= 0 ? 0 : t >= d ? 1 : (t / d) * (1 + .3 * Math.sin(PI * t / d));
// The colour families: one hue each, five tones from dim to bright, per theme. Dark reads up the ramp toward the pale
// tone; light reads up toward the deep tone, so the brightest cell always has the most contrast with its page. The tones
// are the locked tokens --pixilui-activity-mark-<family>-light and -dark (foundation.css section 8), read per theme.
const NAMES: Record<ThinkingMarkFamily, string> = { think: 'Thinking', find: 'Finding', make: 'Writing', wait: 'With you', done: 'Done', fail: 'Failed', code: 'Coding', idle: 'Status' };
const cssTones = (fam: ThinkingMarkFamily, theme: ThinkingMarkTheme): string[] => { if (typeof document === 'undefined') return []; const v = getComputedStyle(document.documentElement).getPropertyValue(`--pixilui-activity-mark-${fam}-${theme}`).trim();
const t = v ? v.split(/[\s,]+/).filter(Boolean) : []; return t.length === 5 ? t : []; };
const FAM = Object.fromEntries((Object.keys(NAMES) as ThinkingMarkFamily[]).map((k) => [k, { name: NAMES[k], get tones() { return { dark: cssTones(k, 'dark'), light: cssTones(k, 'light') }; } }])) as Record<ThinkingMarkFamily, { name: string; readonly tones: { dark: string[]; light: string[] } }>;
/** The eight colour families: their names, and their five tones per theme (read from the foundation's tokens). */
export const thinkingMarkFamilies = FAM;
// a small swatch of the family for chips and labels next to the marks
export const thinkingMarkSwatch = (fam: ThinkingMarkFamily, theme: ThinkingMarkTheme) => { const t = FAM[fam].tones[theme === 'dark' ? 'dark' : 'light']; return theme === 'dark' ? `linear-gradient(135deg, ${t[3]!}, ${t[2]!})` : `linear-gradient(135deg, ${t[2]!}, ${t[3]!})`; };
const hex = (h: string): RGB => [1, 3, 5].map((i) => parseInt(h.slice(i, i + 2), 16)) as RGB;
const mix = (a: RGB, b: RGB, t: number): RGB => a.map((v, i) => v + (b[i]! - v) * t) as RGB;
const paint = (c: RGB) => `rgb(${c.map(Math.round).join(',')})`; // check-registry-ignore: the locked renderer paints a canvas
// the grid style's sockets, and the dark ring's window: the locked renderer's own values
const SOCKET_DARK = hex('#1B1A22'); // check-registry-ignore: the locked renderer paints a canvas
const SOCKET_LIGHT = hex('#E9E6EE'); // check-registry-ignore: the locked renderer paints a canvas
const RING_DARK: RGB = [13, 12, 16];
const WHITE: RGB = [255, 255, 255];
// ───────── the sixteen states ─────────
const RIM = (() => { const p: [number, number][] = []; for (let i = 0; i < 4; i++) p.push([i, 0]); for (let j = 0; j < 4; j++) p.push([4, j]); for (let i = 4; i > 0; i--) p.push([i, 4]); for (let j = 4; j > 0; j--) p.push([0, j]); return p; })();
// Thinking: one spark wandering in a circle, mirrored eight ways; the mark keeps finding new symmetric figures
const spark = (t: number): [number, number] => { const r = 1.15 + .85 * Math.sin(t * .93), a = t * 1.25 + .7 * Math.sin(t * .61); return [2 + r * Math.cos(a), 2 + r * Math.sin(a)]; };
const D4 = ([x, y]: [number, number]): [number, number][] => [[x, y], [4 - x, y], [x, 4 - y], [4 - x, 4 - y], [y, x], [4 - y, x], [y, 4 - x], [4 - y, 4 - x]];
function thinking(t: number): Mark[] { const o: Mark[] = [];
for (let k = 0; k < 7; k++) { const w = Math.pow(1 - k / 7, 1.4); for (const p of D4(spark(t - k * .085))) o.push([p[0], p[1], w, k ? 'dot' : 'sq']); }
o.push([2, 2, .14, 'dot']); return o; }
// Planning: three lines drafted top to bottom, then each box is ticked in turn
function planning(t: number): Mark[] { const P = 4.2, u = t % P, o: Mark[] = [], f = 1 - ss(3.75, 4.1, u);
for (let r = 0; r < 3; r++) { const y = r * 2, t0 = r * .38, tick = 1.9 + r * .42, done = u > tick, b = pop(u - t0, .16) * f; if (b <= 0) continue;
o.push([0, y, done ? 1 : .75 * b, done ? 'sq' : 'ring']);
const len = [3, 2, 3][r]!; for (let c = 0; c < len; c++) { const v = pop(u - t0 - .12 - c * .07) * f; if (v > 0) o.push([2 + c, y, (done ? .38 : .7) * v, 'bar']); } }
return o; }
// Remembering: pieces come in from the edge, pack into a block, and the block folds into one bright cell
const SRC: Pt[] = [[2, 0], [4, 0], [4, 2], [4, 4], [2, 4], [0, 4], [0, 2], [0, 0]], DST: Pt[] = [[2, 1], [3, 1], [3, 2], [3, 3], [2, 3], [1, 3], [1, 2], [1, 1]];
function remembering(t: number): Mark[] { const P = 2.8, u = t % P, o: Mark[] = [], fold = eio(ss(1.7, 2.25, u)), gone = ss(2.35, 2.7, u);
SRC.forEach((s, q) => { const g = eio(ss(q * .05, q * .05 + .55, u)), d = DST[q]!, x = s[0]! + (d[0]! - s[0]!) * g, y = s[1]! + (d[1]! - s[1]!) * g;
const fx = x + (2 - x) * fold, fy = y + (2 - y) * fold; o.push([fx, fy, (g < 1 ? .55 + .3 * g : .85) * (1 - gone), g >= 1 ? 'sq' : 'dot']); });
const c = ss(.85, 1.0, u); if (c > 0) o.push([2, 2, (c * .9 + .1 * Math.sin(u * 9)) * (1 - gone) + fold * .2, 'sq']);
return o; }
// Comparing: five options as columns, swapped into order one pair at a time
const SORTS: { steps: number[][]; sw: number[] }[] = []; for (let k = 0; k < 8; k++) { const a = [1, 2, 3, 4, 5]; for (let i = 4; i > 0; i--) { const j = Math.floor(hash(k * 31 + i) * (i + 1)); [a[i], a[j]] = [a[j]!, a[i]!]; }
if (a.every((v, i) => v === i + 1)) [a[0], a[4]] = [a[4]!, a[0]!]; const steps = [a.slice()], sw: number[] = [], b = a.slice();
for (let i = 0; i < 5; i++) for (let j = 0; j < 4 - i; j++) if (b[j]! > b[j + 1]!) { [b[j], b[j + 1]] = [b[j + 1]!, b[j]!]; sw.push(j); steps.push(b.slice()); } SORTS.push({ steps, sw }); }
function comparing(t: number): Mark[] { const STEP = .26, HOLD = 1; let tt = t % 1e4, k = 0;
for (let n = 0; n < 1e4; n++) { const S = SORTS[k % SORTS.length]!, D = S.sw.length * STEP + HOLD; if (tt < D) break; tt -= D; k++; }
const S = SORTS[k % SORTS.length]!, s = Math.min(S.sw.length, Math.floor(tt / STEP)), f = s < S.sw.length ? eio(clamp((tt - s * STEP) / STEP)) : 0, cur = S.steps[s]!, j = S.sw[s]!, o: Mark[] = [], sorted = s >= S.sw.length;
for (let c = 0; c < 5; c++) { const mv = !sorted && (c === j || c === j + 1), x = mv ? (c === j ? c + f : c - f) : c, h = cur[c]!;
for (let r = 0; r < h; r++) o.push([x, 4 - r, mv ? .95 : sorted ? .3 + .7 * h / 5 : .42, r === h - 1 ? 'sq' : 'dot']); }
return o; }
// Searching: a sweep turns round the disc; a result rings as it passes
function searching(t: number): Mark[] { const P = 1.6, k = Math.floor(t / P), a = ((t % P) / P) * TAU, o: Mark[] = [];
const hit = (() => { const ang = hash(k * 7.7) * TAU, r = 1.4 + hash(k * 2.1) * .7; return [Math.round(2 + Math.cos(ang) * r), Math.round(2 + Math.sin(ang) * r)]; })();
for (let j = 0; j < N; j++) for (let i = 0; i < N; i++) { const dx = i - 2, dy = j - 2, r = Math.hypot(dx, dy); if (r > 2.3) continue;
if (!r) { o.push([i, j, .85, 'sq']); continue; }
let ang = Math.atan2(dy, dx); if (ang < 0) ang += TAU; const d = ((a - ang) % TAU + TAU) % TAU;
if (i === hit[0]! && j === hit[1]! && ang <= a) o.push([i, j, Math.max(.45, 1 - d / TAU * 1.1), 'ring']);
else { const v = Math.exp(-d * .75); o.push([i, j, Math.max(.09, v), v > .6 ? 'sq' : 'dot']); } }
return o; }
// Reading: the text is there, faint; a reading head moves through it and leaves it lit
const READ = [5, 4, 5];
function reading(t: number): Mark[] { const S = 14, sp = 7.5, P = S / sp + .6, h = (t % P) * sp, o: Mark[] = []; let k = 0;
READ.forEach((len, r) => { for (let c = 0; c < len; c++, k++) { const y = r * 2;
if (k === Math.floor(h) && h < S) o.push([c, y, 1, 'sq']); else if (k < h) o.push([c, y, .3 + .55 * Math.exp(-(h - k) / 2), 'bar']); else o.push([c, y, .17, 'bar']); } });
return o; }
// Browsing: a globe turning: the rim, the equator, and a meridian sweeping across
const GLOBE: Pt[] = [[1, 0], [2, 0], [3, 0], [4, 1], [4, 2], [4, 3], [3, 4], [2, 4], [1, 4], [0, 3], [0, 2], [0, 1]];
function browsing(t: number): Mark[] { const o: Mark[] = GLOBE.map(([x, y]): Mark => [x, y, .5, 'dot']); for (let i = 1; i <= 3; i++) o.push([i, 2, .26, 'dot']);
for (const ph of [0, PI]) { const s = Math.sin(t * 1.5 + ph), front = Math.cos(t * 1.5 + ph); if (front < 0) continue;
for (let y = 1; y <= 3; y++) o.push([2 + 1.75 * s, y, .55 + .45 * front, 'sq']); }
return o; }
// Listening: five bands of the voice, opening from the middle row
function listening(t: number): Mark[] { const o: Mark[] = [];
for (let c = 0; c < N; c++) { const n1 = Math.sin(t * 7.1 + c * 1.9), n2 = Math.sin(t * 4.3 - c * 2.7 + 1), n3 = Math.sin(t * 1.7 + c * .8);
const lvl = clamp(.5 + .32 * n1 + .22 * n2 + .2 * n3) * (c === 0 || c === 4 ? .55 : c === 2 ? 1 : .85), h = Math.round(lvl * 2.4 * 2) / 2;
for (let j = 0; j < N; j++) { const d = Math.abs(j - 2); if (d > h) continue; o.push([c, j, d === 0 ? .9 : .55 + .35 * (1 - d / 2), d === 0 ? 'sq' : 'dot']); } }
return o; }
// Writing: text appears where there was none, cell by cell, the cursor ahead of it
function writing(t: number): Mark[] { const P = 3.6, k = Math.floor(t / P), u = t % P, o: Mark[] = [], rate = 9, f = 1 - ss(3.2, 3.55, u);
const L = [5, 3 + Math.floor(hash(k * 3.1) * 2), 1 + Math.floor(hash(k * 5.3) * 3)]; let i = 0, caret: Pt | null = null; const typed = u * rate;
L.forEach((len, r) => { for (let c = 0; c < len; c++, i++) { const v = pop((typed - i) / rate, .1); if (v > 0) o.push([c, r * 2, .78 * v * f, 'bar']); else if (!caret) caret = [c, r * 2]; } });
if (!caret) caret = [Math.min(4, L[2]!), 4]; if ((Math.floor(u * 3) % 2 === 0) || typed < i) o.push([caret[0]!, caret[1]!, f, 'sq']);
return o; }
// Running code: a run laps the edge; the centre flashes once per lap
function running(t: number): Mark[] { const lap = 1.05, h = (t / lap) * 16, o: Mark[] = [];
RIM.forEach(([x, y], q) => { const d = ((h - q) % 16 + 16) % 16, v = Math.exp(-d / 2.4); if (d < 1) o.push([x, y, 1, 'sq']); else if (v > .07) o.push([x, y, v * .9, 'dot']); });
const ph = (t / lap) % 1; o.push([2, 2, .35 + .65 * Math.exp(-ph * 7), 'sq']);
return o; }
// Calling a tool: a request crosses on the top lane, the service lights, the answer returns on the bottom lane
function calling(t: number): Mark[] { const P = 1.8, u = t % P, o: Mark[] = [], go = eio(ss(0, .55, u)), back = eio(ss(.8, 1.35, u)), atS = u > .5 && u < .95, home = u > 1.3 && u < 1.7;
for (let j = 1; j <= 3; j++) { o.push([0, j, home ? 1 : .55, 'sq']); o.push([4, j, atS ? 1 : .42, atS ? 'sq' : 'ring']); }
if (u < .6) o.push([1 + go * 2, 1, .95, 'sq']);
if (u > .78 && u < 1.4) o.push([3 - back * 2, 3, .95, 'sq']);
for (let i = 1; i <= 3; i++) o.push([i, 2, .1, 'dot']);
return o; }
// Delegating: the lead sends work to four helpers in the corners; they work at their own pace; results come home
function delegating(t: number): Mark[] { const P = 2.6, u = t % P, o: Mark[] = [], W: Pt[] = [[0, 0], [4, 0], [4, 4], [0, 4]], send = eio(ss(0, .45, u)), ret = eio(ss(1.75, 2.2, u)), flash = u > 2.2 ? 1 - ss(2.2, 2.6, u) : 0;
o.push([2, 2, .6 + .4 * flash, 'sq']); if (flash > .05) for (const [x, y] of [[2, 1], [1, 2], [3, 2], [2, 3]] as Pt[]) o.push([x, y, .6 * flash, 'dot']);
W.forEach(([x, y], q) => { const busy = u > .45 && u < 1.8; const v = busy ? .5 + .5 * (hash(q * 9 + Math.floor(u * (5 + q))) > .45 ? 1 : .2) : .3;
o.push([x, y, v, busy ? 'sq' : 'ring']);
if (u < .5) o.push([2 + (x - 2) * send, 2 + (y - 2) * send, .95, 'sq']);
if (u > 1.72 && u < 2.25) o.push([x + (2 - x) * ret, y + (2 - y) * ret, 1, 'sq']); });
return o; }
// Compacting: a long context is pressed into a short one, denser and brighter
const LONG = [4, 5, 3, 5, 4];
function compacting(t: number): Mark[] { const P = 3, u = t % P, c = eio(ss(.55, 1.3, u)), f = 1 - ss(2.6, 2.95, u), a = ss(0, .25, u), o: Mark[] = [];
LONG.forEach((len, r) => { for (let i = 0; i < len; i++) { const ty = 1 + Math.floor(r * 3 / 5), tx = Math.min(2, Math.floor(i * .6)), x = i + (tx - i) * c, y = r + (ty - r) * c;
o.push([x, y, (.32 + .62 * c) * f * a, c > .95 ? 'sq' : 'bar']); } });
return o; }
// Waiting for you: one steady cell, and a slow ripple asking for attention
function waiting(t: number): Mark[] { const o: Mark[] = [], P = 2.2;
for (let j = 0; j < N; j++) for (let i = 0; i < N; i++) { const r = Math.hypot(i - 2, j - 2); if (!r) continue; let v = 0;
for (const off of [0, .5]) { const R = (((t / P) + off) % 1) * 3.3; v = Math.max(v, Math.exp(-Math.pow((r - R) / .55, 2)) * (1 - R / 3.5)); }
if (v > .05) o.push([i, j, v * .92, 'dot']); }
o.push([2, 2, .82 + .18 * Math.sin(t * TAU / P), 'sq']); return o; }
// Done: the cells draw a tick, a light runs along it once, and it lets go
const TICK: Pt[] = [[0, 2], [1, 3], [2, 2], [3, 1], [4, 0]];
function done(t: number): Mark[] { const P = 2.8, u = t % P, o: Mark[] = [], f = 1 - ss(2.45, 2.75, u);
TICK.forEach(([x, y], q) => { const v = pop(u - q * .085, .16); if (v <= 0) return; const sh = Math.exp(-Math.pow((u - 1 - q * .08) / .09, 2)); o.push([x, y, Math.min(1, (.74 + .26 * sh) * v) * f, 'sq']); });
return o; }
// Failed: a cross that holds, then slips out of register for a moment
const CROSS: Pt[] = [[0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [4, 0], [3, 1], [1, 3], [0, 4]];
function failed(t: number): Mark[] { const P = 1.8, u = t % P, k = Math.floor(t / P), gl = u > 1.15 && u < 1.42, st = Math.floor(u * 20), o: Mark[] = [];
CROSS.forEach(([x, y], q) => { const dx = gl ? Math.round((hash(y * 3.1 + st * 1.7 + k) - .5) * 2.2) : 0; o.push([clamp(x + dx, 0, 4), y, gl ? .55 + .45 * hash(q + st) : .92, 'sq']); });
return o; }
// ───────── more states ─────────
// pixel pictures as strings: '.' off, digits 1–4 are shade
const PIC = (str: string): [number, number, number][] => str.trim().split(/\s+/).flatMap((row, j) => [...row].flatMap((ch, i): [number, number, number][] => (ch === '.' ? [] : [[i, j, +ch / 4]])));
// Brainstorming: ideas pop up anywhere, each a small burst that fades
function brainstorming(t: number): Mark[] { const o: Mark[] = [], rate = 5.5, n = Math.floor(t * rate);
for (let k = n - 6; k <= n; k++) { const age = t - k / rate; if (age < 0 || age > 1.1) continue; const i = Math.floor(hash(k * 3.7) * 5), j = Math.floor(hash(k * 9.1 + 2) * 5);
o.push([i, j, age < .08 ? age / .08 : 1 - ss(.1, 1.1, age), 'sq']);
if (age < .4) for (const [dx, dy] of [[1, 0], [-1, 0], [0, 1], [0, -1]] as Pt[]) o.push([i + dx, j + dy, (1 - age / .4) * .55, 'dot']); }
return o; }
// Deciding: two options weighed, faster and faster, until one locks in
const OPT_A: Pt[] = [[0, 1], [1, 1], [0, 2], [1, 2], [0, 3], [1, 3]], OPT_B = OPT_A.map(([x, y]): Pt => [4 - x, y]);
function deciding(t: number): Mark[] { const P = 3.4, k = Math.floor(t / P), u = t % P, o: Mark[] = [], f = 1 - ss(3.0, 3.35, u), win = hash(k * 4.4) > .5;
if (u < 1.9) { const w = Math.sin(TAU * (u * .9 + u * u * 1.5)); OPT_A.forEach(([x, y]) => o.push([x, y, (.4 + .55 * Math.max(0, w)) * f, 'sq'])); OPT_B.forEach(([x, y]) => o.push([x, y, (.4 + .55 * Math.max(0, -w)) * f, 'sq'])); o.push([2, 2, .3, 'dot']); }
else { const lock = ss(1.9, 2.05, u), out = 1 - ss(1.95, 2.3, u); (win ? OPT_A : OPT_B).forEach(([x, y]) => o.push([x, y, (.75 + .25 * lock) * f, 'sq'])); (win ? OPT_B : OPT_A).forEach(([x, y]) => o.push([x, y, .4 * out * f, 'sq']));
o.push([2, 2, .9 * f, 'sq']); o.push([win ? 1.5 : 2.5, 2, 0, 'dot']); }
return o; }
// Indexing: a scan runs row by row and leaves a map behind it; the map flashes once complete
function indexing(t: number): Mark[] { const P = 2.9, u = t % P, o: Mark[] = [], h = (u / 1.7) * 25, f = 1 - ss(2.5, 2.85, u), flash = Math.exp(-Math.pow((u - 1.85) / .12, 2));
for (let q = 0; q < 25; q++) { const i = q % 5, j = (q / 5) | 0; if (q > h) continue; const head = q > h - 1; o.push([i, j, (head ? 1 : .42 + .45 * flash) * f, 'sq']); }
return o; }
// Fetching: pieces drop from above and land in a tray; a full tray flashes and empties
function fetching(t: number): Mark[] { const P = 2.8, u = t % P, o: Mark[] = [], f = 1 - ss(2.45, 2.75, u), flash = Math.exp(-Math.pow((u - 2.25) / .1, 2));
for (let k = 0; k < 5; k++) { const s0 = .12 + k * .4, a = u - s0; if (a < 0) continue; const fall = clamp(a / .34), y = -.6 + 4.6 * fall * fall;
o.push([k, Math.min(4, y), (fall < 1 ? .95 : .62 + .38 * flash) * f, 'sq']); }
return o; }
// Analyzing: a chart of a live series scrolls past, its line bright, the area under it dim
const SERIES = (n: number) => 1 + Math.round(3 * (.5 + .5 * Math.sin(n * .83) * Math.cos(n * .31 + 1)));
function analyzing(t: number): Mark[] { const o: Mark[] = [], sp = 1.7, n0 = Math.floor(t * sp), fr = t * sp - n0;
for (let c = -1; c <= 5; c++) { const h = SERIES(n0 + c), x = c - fr; if (x < -.6 || x > 4.6) continue;
for (let r = 0; r < h; r++) o.push([x, 4 - r, r === h - 1 ? 1 : .34, r === h - 1 ? 'sq' : 'dot']); }
return o; }
// Editing: a span of a line is selected (in selection blue), removed, and new text is typed in its place
function editing(t: number): Mark[] { const P = 3.5, u = t % P, o: Mark[] = [], f = 1 - ss(3.15, 3.45, u);
for (const y of [0, 4]) for (let x = 0; x < 5; x++) o.push([x, y, .4 * f, 'bar']);
for (let x = 0; x < 5; x++) { const inSpan = x >= 1 && x <= 3, sel = inSpan && u > .45 + (x - 1) * .12, gone = inSpan && u > 1.25, typed = inSpan && u > 1.55 + (x - 1) * .16;
if (!inSpan) { o.push([x, 2, .55 * f, 'bar']); continue; }
if (typed) o.push([x, 2, .82 * pop(u - 1.55 - (x - 1) * .16) * f, 'sq']); else if (sel && !gone) o.push([x, 2, .85, 'sq', 'find']); else if (!gone) o.push([x, 2, .55, 'bar']); }
if (u > 1.25 && u < 2.2) { const cx = 1 + clamp((u - 1.55) / .48) * 3; if (Math.floor(u * 6) % 2 === 0) o.push([Math.min(4, Math.round(cx)), 1, .7, 'dot']); }
return o; }
// Summarizing: five lines of text draw together into one short bright line
const SUMLEN = [5, 4, 5, 3, 4];
function summarizing(t: number): Mark[] { const P = 3.2, u = t % P, o: Mark[] = [], c = eio(ss(.6, 1.35, u)), f = 1 - ss(2.8, 3.15, u), a = ss(0, .25, u);
SUMLEN.forEach((len, r) => { for (let x = 0; x < len; x++) { const keep = x < 3, y = r + (2 - r) * c, v = keep ? .45 + .55 * c : .45 * (1 - c); o.push([x, y, v * f * a, c > .97 ? 'sq' : 'bar']); } });
return o; }
// Translating: a line drops, word by word, and lands rearranged as a new line
function translating(t: number): Mark[] { const P = 3.2, k = Math.floor(t / P), u = t % P, o: Mark[] = [], f = 1 - ss(2.8, 3.15, u), perm = [0, 1, 2, 3, 4].sort((a, b) => hash(k * 7 + a) - hash(k * 7 + b));
for (let x = 0; x < 5; x++) { const s0 = .45 + x * .14, g = eio(ss(s0, s0 + .45, u)), tx = perm[x]!;
o.push([x + (tx - x) * g, 1 + 2 * g, (g < 1 ? .7 : .95) * f, g >= 1 ? 'sq' : 'bar']); if (g > 0) o.push([x, 1, .22 * (1 - g) * f, 'bar']); }
return o; }
// Generating an image: noise resolves, cell by cell, into a small picture; then dissolves back
const PICS = [PIC(`.4.4. 44444 34443 .343. ..3..`), PIC(`...44 ...44 ..3.. .333. 33333`), PIC(`..4.. .343. 34443 .2.2. .222.`), PIC(`.444. 4.4.4 44444 4.4.4 .444.`)];
function generating(t: number): Mark[] { const P = 4.4, k = Math.floor(t / P), u = t % P, o: Mark[] = [], pic = PICS[k % PICS.length]!, target = new Float32Array(25); for (const [i, j, v] of pic) target[j * 5 + i] = v;
const tick = Math.floor(t * 11);
for (let q = 0; q < 25; q++) { const i = q % 5, j = (q / 5) | 0, settle = 1 + hash(q * 3.3 + k) * 1.1, unsettle = 3.6 + hash(q * 5.1 + k) * .6, noise = .2 + .55 * hash(q * 1.7 + tick * 3.1);
const v = u < settle || u > unsettle ? noise : target[q]!; if (v > .02) o.push([i, j, v, 'sq']); }
return o; }
// Testing: tests run one after another; most pass, one fails in coral
function testing(t: number): Mark[] { const P = 3.4, k = Math.floor(t / P), u = t % P, o: Mark[] = [], f = 1 - ss(3.0, 3.35, u), bad = Math.floor(hash(k * 6.1) * 15);
for (let n = 0; n < 15; n++) { const x = n % 5, y = ((n / 5) | 0) * 2, s0 = .15 + n * .13;
if (u < s0) { o.push([x, y, .2 * f, 'dot']); continue; }
if (u < s0 + .12) { o.push([x, y, .65, 'sq']); continue; }
if (n === bad) o.push([x, y, (Math.floor(u * 5) % 2 ? .75 : 1) * f, 'sq', 'fail']); else o.push([x, y, .82 * f, 'sq']); }
return o; }
// Debugging: a bug darts about; a scanner closes in, catches it, and both flash
function debugging(t: number): Mark[] { const P = 2.8, u = t % P, o: Mark[] = [], bug = [2 + 1.7 * Math.sin(t * 2.3) * Math.cos(t * .7), 2 + 1.7 * Math.sin(t * 1.6 + 1) * Math.cos(t * .9 + 2)].map(v => clamp(Math.round(v), 0, 4));
const caught = u > 1.9 && u < 2.5, sc = caught ? bug : [clamp(Math.round(2 + 1.4 * Math.sin((t - .4) * 2.3) * Math.cos((t - .4) * .7)), 1, 3), clamp(Math.round(2 + 1.4 * Math.sin((t - .4) * 1.6 + 1) * Math.cos((t - .4) * .9 + 2)), 1, 3)];
const tight = caught ? ss(1.9, 2.1, u) : 0, flash = caught ? Math.exp(-Math.pow((u - 2.15) / .1, 2)) : 0;
for (const [dx, dy] of [[-1, -1], [0, -1], [1, -1], [-1, 0], [1, 0], [-1, 1], [0, 1], [1, 1]] as Pt[]) { const x = sc[0]! + dx * (1 - tight), y = sc[1]! + dy * (1 - tight); o.push([x, y, .5 + .5 * flash, 'sq']); }
o.push([bug[0]!, bug[1]!, caught ? 1 - ss(2.2, 2.5, u) : 1, 'sq', 'fail']);
return o; }
// Building: blocks drop into place, filling the frame from the bottom; the finished build flashes and clears
function building(t: number): Mark[] { const P = 3.6, u = t % P, o: Mark[] = [], flash = Math.exp(-Math.pow((u - 2.9) / .1, 2)), clear = ss(3.05, 3.5, u);
for (let k = 0; k < 25; k++) { const i = k % 5, row = 4 - ((k / 5) | 0), s0 = .1 + k * .1, a = u - s0; if (a < 0) continue; const fall = clamp(a / .24), y = -1 + (row + 1) * fall * fall;
if (clear > row / 5) continue; o.push([i, y, fall < 1 ? .95 : .55 + .45 * flash, 'sq']); }
return o; }
// Deploying: a small rocket lifts off the pad and leaves the frame, trailing light
function deploying(t: number): Mark[] { const P = 2.4, u = t % P, o: Mark[] = [], lift = clamp((u - .35) / 1.1), y = 3 - 5.5 * lift * lift, pad = .35 + .6 * Math.exp(-Math.pow((u - .4) / .12, 2));
for (let x = 0; x < 5; x++) o.push([x, 4, x === 2 ? Math.max(pad, .5) : pad * .8, 'sq']);
if (u < 1.5) { o.push([2, y, 1, 'sq']); o.push([1, y + 1, .8, 'sq']); o.push([3, y + 1, .8, 'sq']); o.push([2, y + 1, .9, 'sq']); if (lift > 0) { o.push([2, y + 2, .55, 'dot']); o.push([2, y + 3, .3, 'dot']); } }
return o; }
// Merging: two branches carry changes up into one line
const BR_L: Pt[] = [[1, 4], [1, 3], [2, 2], [2, 1], [2, 0]], BR_R: Pt[] = [[3, 4], [3, 3], [2, 2], [2, 1], [2, 0]];
function merging(t: number): Mark[] { const o: Mark[] = [], P = 1.6, u = t % P;
for (const [x, y] of [...BR_L, [3, 4], [3, 3]] as Pt[]) o.push([x, y, .38, 'sq']);
for (const [br, off] of [[BR_L, 0], [BR_R, .35]] as [Pt[], number][]) { const p = ((u - off + P) % P) / 1.1 * 4; if (p > 4.2) continue; const k = Math.min(3, Math.floor(p)), fr = p - k, a = br[k]!, b = br[Math.min(4, k + 1)]!;
o.push([a[0] + (b[0] - a[0]) * fr, a[1] + (b[1] - a[1]) * fr, 1, 'sq']); }
return o; }
// Speaking: sound leaves a source on the left in widening arcs
function speaking(t: number): Mark[] { const o: Mark[] = []; for (let j = 1; j <= 3; j++) o.push([0, j, j === 2 ? 1 : .7, 'sq']);
for (let j = 0; j < 5; j++) for (let i = 1; i < 5; i++) { const d = Math.hypot(i + .4, (j - 2) * 1.15); let v = 0;
for (const off of [0, .5]) { const R = (((t * .95) + off) % 1) * 5 + .6; v = Math.max(v, Math.exp(-Math.pow((d - R) / .45, 2)) * (1 - R / 6)); }
if (v > .08) o.push([i, j, v, 'sq']); }
return o; }
// Asking: a question mark draws itself, then its dot keeps asking
const QMARK: Pt[] = [[1, 0], [2, 0], [3, 0], [3, 1], [2, 2]];
function asking(t: number): Mark[] { const P = 3, u = t % P, o: Mark[] = [], f = 1 - ss(2.7, 2.95, u);
QMARK.forEach(([x, y], q) => { const v = pop(u - q * .09, .14); if (v > 0) o.push([x, y, .85 * v * f, 'sq']); });
if (u > .6) o.push([2, 4, (.55 + .45 * Math.abs(Math.sin((u - .6) * 4.2))) * f, 'sq']);
return o; }
// Idle: one cell breathing slowly, its neighbours barely there
function idle(t: number): Mark[] { const b = .5 + .5 * Math.sin(t * TAU / 3.4), o: Mark[] = [[2, 2, .45 + .5 * b, 'sq']];
if (b > .55) for (const [x, y] of [[1, 2], [3, 2], [2, 1], [2, 3]] as Pt[]) o.push([x, y, (b - .55) * .9, 'sq']);
return o; }
// Queued: a line of jobs steps forward one place at a time toward the gate
function queued(t: number): Mark[] { const o: Mark[] = [], step = .6, n = Math.floor(t / step), fr = eio(clamp((t / step - n) / .45));
for (const y of [1, 3]) o.push([4, y, .45, 'sq']);
for (let k = 0; k < 5; k++) { const x = k - 1 + fr; if (x < -.6 || x > 4.6) continue; const front = x > 2.6; o.push([x, 2, front ? 1 - clamp((x - 3.2) / 1.2) * .7 : .6, 'sq']); }
return o; }
// Paused: two bars, holding, breathing very slightly
function paused(t: number): Mark[] { const b = .86 + .14 * Math.sin(t * TAU / 2.6), o: Mark[] = []; for (let y = 0; y < 5; y++) { o.push([1, y, b, 'sq']); o.push([3, y, b, 'sq']); } return o; }
// Retrying: the first try runs into a wall and bounces; the second gets through
function retrying(t: number): Mark[] { const P = 3, u = t % P, o: Mark[] = [], f = 1 - ss(2.7, 2.95, u), wallOpen = ss(1.5, 1.75, u), hit = Math.exp(-Math.pow((u - .55) / .09, 2));
for (let y = 1; y <= 3; y++) o.push([4, y, (.6 + .4 * hit) * (1 - wallOpen * .85) * f, 'sq', 'fail']);
let x; if (u < .55) x = 3 * eio(u / .55); else if (u < 1.2) x = 3 - 3 * eio((u - .55) / .65); else x = 5.2 * eio(clamp((u - 1.35) / 1));
if (x < 4.6) o.push([x, 2, f, 'sq']);
return o; }
export const thinkingMarkGroups: readonly (readonly [string, readonly ThinkingMarkState[]])[] = [
['Thinking', ['thinking', 'planning', 'remembering', 'comparing', 'brainstorming', 'deciding']],
['Finding', ['searching', 'reading', 'browsing', 'indexing', 'fetching', 'analyzing']],
['Writing', ['writing', 'editing', 'summarizing', 'translating', 'generating', 'compacting']],
['Coding', ['running', 'testing', 'debugging', 'building', 'deploying', 'merging']],
['With you', ['listening', 'speaking', 'asking', 'waiting', 'calling', 'delegating']],
['Status', ['idle', 'queued', 'paused', 'retrying', 'done', 'failed']],
];
const DEF: Record<ThinkingMarkState, [string, ThinkingMarkFamily, (t: number) => Mark[]]> = {
thinking: ['Thinking', 'think', thinking], planning: ['Planning', 'think', planning], remembering: ['Remembering', 'think', remembering], comparing: ['Comparing', 'think', comparing], brainstorming: ['Brainstorming', 'think', brainstorming], deciding: ['Deciding', 'think', deciding],
searching: ['Searching', 'find', searching], reading: ['Reading', 'find', reading], browsing: ['Browsing', 'find', browsing], indexing: ['Indexing', 'find', indexing], fetching: ['Fetching', 'find', fetching], analyzing: ['Analyzing', 'find', analyzing],
writing: ['Writing', 'make', writing], editing: ['Editing', 'make', editing], summarizing: ['Summarizing', 'make', summarizing], translating: ['Translating', 'make', translating], generating: ['Generating an image', 'make', generating], compacting: ['Compacting', 'make', compacting],
running: ['Running code', 'code', running], testing: ['Testing', 'code', testing], debugging: ['Debugging', 'code', debugging], building: ['Building', 'code', building], deploying: ['Deploying', 'code', deploying], merging: ['Merging', 'code', merging],
listening: ['Listening', 'wait', listening], speaking: ['Speaking', 'wait', speaking], asking: ['Asking you', 'wait', asking], waiting: ['Waiting for you', 'wait', waiting], calling: ['Calling a tool', 'wait', calling], delegating: ['Delegating', 'wait', delegating],
idle: ['Idle', 'idle', idle], queued: ['Queued', 'idle', queued], paused: ['Paused', 'idle', paused], retrying: ['Retrying', 'fail', retrying], done: ['Done', 'done', done], failed: ['Failed', 'fail', failed],
};
export const thinkingMarkStates: readonly ThinkingMarkStateDef[] = thinkingMarkGroups.flatMap(([, ids]) => ids.map((id) => ({ id, name: DEF[id][0], fam: DEF[id][1], f: DEF[id][2] })));
const byId = Object.fromEntries(thinkingMarkStates.map((s) => [s.id, s])) as Record<ThinkingMarkState, ThinkingMarkStateDef>;
// the locked agent avatar's eleven states, and the mark that goes with each
export const thinkingMarkAvatarState: Record<string, ThinkingMarkState> = { idle: 'idle', thinking: 'thinking', searching: 'searching', reading: 'reading', writing: 'writing', browsing: 'browsing', running: 'running', waiting: 'asking', done: 'done', failed: 'failed', stopped: 'paused' };
// states that settle instead of looping: the tick draws once and holds (1.5 s in)
const HOLD_STATES: ThinkingMarkState[] = ['done']; // settle instead of looping: the tick draws once and holds (--activity-mark-hold)
// reduced motion: one representative moment per state (seconds), drawn still
const STILL: Record<ThinkingMarkState, number> = { thinking: 1.4, planning: 2.6, remembering: 1.2, comparing: 1.6, brainstorming: 1.3, deciding: 2.9, searching: .5, reading: 1.2, browsing: .8, indexing: 1.2, fetching: 1.6, analyzing: 1, writing: 2.2, editing: .9, summarizing: 1.6, translating: 1.6, generating: 2.6, compacting: 1.6, running: .4, testing: 2, debugging: 2, building: 2.4, deploying: .9, merging: 1, listening: .6, speaking: .5, asking: 2, waiting: .6, calling: .7, delegating: 1, idle: 1.2, queued: .3, paused: 1, retrying: 2, done: 1.5, failed: .6 };
const reduce = typeof matchMedia !== 'undefined' ? matchMedia('(prefers-reduced-motion: reduce)') : { matches: false };
// shared timings, named in activity-mark.css: the hand-off between states, the drifting band, how long done takes to settle
const secs = (n: string, d: number) => { if (typeof document === 'undefined') return d; const v = getComputedStyle(document.documentElement).getPropertyValue(n).trim(); return v ? parseFloat(v) * (v.endsWith('ms') ? .001 : 1) : d; };
let TIME: { step: number; dur: number; keep: number; band: number; hold: number } | undefined; const time = () => TIME || (TIME = { step: secs('--pixilui-activity-mark-handoff-step', .07), dur: secs('--pixilui-activity-mark-handoff', .26), keep: secs('--pixilui-activity-mark-handoff-max', .7), band: secs('--pixilui-activity-mark-band-period', 3.8), hold: secs('--pixilui-activity-mark-hold', 1.5) });
// marks → 25 cells. A mark between cells lights its neighbours by distance, so movement is a hand-off between LEDs.
const KIND: Record<Kind, number> = { dot: 0, sq: 1, ring: 2, bar: 3 }, KINDS: Kind[] = ['dot', 'sq', 'ring', 'bar'];
function raster(marks: Mark[]) { const V = new Float32Array(25), K = new Uint8Array(25), F: (ThinkingMarkFamily | null)[] = new Array(25).fill(null);
for (const [x, y, v0, kind, fam] of marks) { const v = clamp(v0); if (v < .02) continue; const fx = Math.abs(x - Math.round(x)) < .02, fy = Math.abs(y - Math.round(y)) < .02;
if (fx && fy) { const i = Math.round(x), j = Math.round(y); if (i < 0 || j < 0 || i > 4 || j > 4) continue; const q = j * 5 + i; if (v > V[q]!) { V[q] = v; K[q] = KIND[kind]; F[q] = fam || null; } continue; }
for (let j = Math.floor(y); j <= Math.ceil(y); j++) for (let i = Math.floor(x); i <= Math.ceil(x); i++) { if (i < 0 || j < 0 || i > 4 || j > 4) continue;
const w = Math.pow(clamp(1 - Math.hypot(i - x, j - y)), 1.25), vv = v * w, q = j * 5 + i; if (vv > V[q]!) { V[q] = vv; K[q] = KIND[kind]; F[q] = fam || null; } } }
return { V, K, F }; }
// ───────── drawing ─────────
/** Options of one drawn mark. */
export type ThinkingMarkGlyphOptions = { size?: number; theme?: ThinkingMarkTheme; style?: ThinkingMarkStyle; dpr?: number };
/**
* One mark on a canvas (the locked Glyph). `draw(t)` draws the frame at time t (seconds); `setState` hands over cell by
* cell from the centre; `set` switches at once. Use it directly for a canvas you own; the component wraps it.
*/
export class ThinkingMarkGlyph {
c: HTMLCanvasElement; theme: ThinkingMarkTheme; dark: boolean; size: number; dpr: number; blocks: boolean; sockets: boolean; small: boolean;
start: number; prev: { s: ThinkingMarkStateDef; start: number; at: number } | null; s: ThinkingMarkStateDef;
S: number; P: number; off: number; g: CanvasRenderingContext2D | null; sock: RGB; ramps: Record<ThinkingMarkFamily, RGB[]>; jit: number[];
// style 'grid': cells with gaps in visible sockets. style 'blocks': no gaps, no sockets, one combined shape whose cells
// are told apart only by small shifts of tone between neighbours.
constructor(canvas: HTMLCanvasElement, state: ThinkingMarkState | ThinkingMarkStateDef, { size = 96, theme = 'light', style = 'blocks', dpr = Math.min(3, (typeof devicePixelRatio === 'number' ? devicePixelRatio : 1) || 1) }: ThinkingMarkGlyphOptions = {}) {
this.c = canvas; this.theme = theme; this.dark = theme === 'dark'; this.size = size; this.dpr = dpr; this.blocks = style === 'blocks'; this.sockets = !this.blocks;
this.small = size <= 28; this.start = 0; this.prev = null; this.s = typeof state === 'string' ? byId[state] : state;
const px = Math.round(size * dpr); this.S = px;
// small: an integer pitch so every cell is a whole number of device pixels
this.P = this.small ? Math.floor(px / N) : px / N; this.off = this.small ? Math.floor((px - this.P * N) / 2) : 0;
canvas.width = px; canvas.height = px; canvas.style.width = size + 'px'; canvas.style.height = size + 'px';
this.g = canvas.getContext('2d');
this.sock = this.dark ? SOCKET_DARK : SOCKET_LIGHT;
this.ramps = {} as Record<ThinkingMarkFamily, RGB[]>; for (const k in FAM) this.ramps[k as ThinkingMarkFamily] = FAM[k as ThinkingMarkFamily].tones[this.dark ? 'dark' : 'light'].map(hex);
// each cell's fixed tone offset: alternating like a checkerboard, plus a little of its own, so neighbours never match
this.jit = Array.from({ length: 25 }, (_, q) => { const i = q % 5, j = (q / 5) | 0; return .62 * ((i + j) % 2 ? 1 : -1) + .38 * (hash(i * 5.3 + j * 13.1 + 7) * 2 - 1); });
}
/** Switch state at time `at`: the cells hand over from the centre outward. */
setState(state: ThinkingMarkState | ThinkingMarkStateDef, at = 0) { const s = typeof state === 'string' ? byId[state] : state; if (s === this.s) return; this.prev = { s: this.s, start: this.start, at }; this.s = s; this.start = at; }
/** Switch at once, the new state's loop starting at `start`. */
set(state: ThinkingMarkState | ThinkingMarkStateDef, start = 0) { this.s = typeof state === 'string' ? byId[state] : state; this.start = start; this.prev = null; }
// a cell's colour: its intensity read along the family's five tones, nudged by the cell's own offset
tone(fam: ThinkingMarkFamily, i: number, j: number, v: number): RGB { const R = this.ramps[fam], e = Math.pow(clamp(v), .85), amt = this.blocks ? .2 : .1, pos = clamp(e + this.jit[j * 5 + i]! * amt * (.4 + .6 * e)) * (R.length - 1);
const k = Math.min(R.length - 2, Math.floor(pos)), c = mix(R[k]!, R[k + 1]!, pos - k); return this.blocks ? c : mix(this.sock, c, clamp(v / .1)); }
/** Draw the frame at time `t` (seconds). Call every frame, ideally from one shared clock. */
draw(t: number) {
const g = this.g; if (!g || this.ramps.idle.length !== 5) return;
const still = reduce.matches; if (still) this.prev = null;
const TM = time(), local = still ? (STILL[this.s.id] ?? 1.2) : Math.min(t - this.start, HOLD_STATES.includes(this.s.id) ? TM.hold : Infinity);
const { P, off, small, dark, blocks } = this, X = this.c.width, cur = raster(this.s.f(local));
let pre: ReturnType<typeof raster> | null = null, at = 0; if (this.prev) { if (t - this.prev.at > TM.keep) this.prev = null; else { pre = raster(this.prev.s.f(t - this.prev.start)); at = this.prev.at; } }
g.clearRect(0, 0, X, X);
// a soft band of lighter tone drifts across the lit cells, corner to corner, every few seconds
const band = still ? -9 : ((t / TM.band) % 1) * 1.9 - .45;
const V = new Float32Array(25), C: RGB[] = [], K: Kind[] = [];
for (let q = 0; q < 25; q++) { const i = q % 5, j = (q / 5) | 0; let v = cur.V[q]!, kind = KINDS[cur.K[q]!]!, c = this.tone(cur.F[q] || this.s.fam, i, j, v);
if (pre && this.prev) { const d = Math.hypot(i - 2, j - 2), k = eio(clamp((t - at - d * TM.step) / TM.dur)), pv = pre.V[q]!;
c = mix(this.tone(pre.F[q] || this.prev.s.fam, i, j, pv), c, k); v = pv + (v - pv) * k; kind = k < .5 ? KINDS[pre.K[q]!]! : kind; }
const sweep = Math.exp(-Math.pow(((i + j) / 8 - band) / .13, 2)) * (small ? .1 : .16) * clamp(v * 1.4);
V[q] = v; C[q] = mix(c, WHITE, sweep); K[q] = kind; }
if (blocks) return this.drawBlocks(V, C, K);
const gap = small ? (P >= 5 ? 1 : 0) : P * .17, sz = P - gap, rad = small ? (P >= 6 ? 1 : 0) : P * .26;
for (let j = 0; j < N; j++) for (let i = 0; i < N; i++) { const q = j * 5 + i, x = off + i * P + (small ? 0 : gap / 2), y = off + j * P + (small ? 0 : gap / 2);
g.fillStyle = paint(this.sock); g.beginPath(); if (rad) g.roundRect(x, y, sz, sz, rad); else g.rect(x, y, sz, sz); g.fill();
const v = V[q]!, kind = K[q]; if (v < .03) continue; g.fillStyle = paint(C[q]!); g.strokeStyle = paint(C[q]!);
if (kind === 'bar') { const h = small ? Math.max(2, Math.round(sz * .55)) : sz * .46, yy = y + Math.round((sz - h) / 2); g.beginPath(); if (small) g.rect(off + i * P, yy, P, h); else g.roundRect(x - gap / 2, yy, P, h, h / 2); g.fill(); continue; }
if (kind === 'ring') { if (small) { g.fillRect(x, y, sz, sz); g.fillStyle = paint(this.sock); g.fillRect(x + 1, y + 1, sz - 2, sz - 2); } else { const lw = P * .14; g.lineWidth = lw; g.beginPath(); g.roundRect(x + lw / 2, y + lw / 2, sz - lw, sz - lw, Math.max(0, rad - lw / 2)); g.stroke(); } continue; }
if (kind === 'dot' && v < .55) { const s2 = small ? Math.max(2, sz - 2) : sz * (.42 + .3 * v), d0 = (sz - s2) / 2; g.beginPath(); if (small) g.rect(x + Math.floor(d0), y + Math.floor(d0), s2, s2); else g.roundRect(x + d0, y + d0, s2, s2, s2 * .32); g.fill(); continue; }
g.beginPath(); if (rad) g.roundRect(x, y, sz, sz, rad); else g.rect(x, y, sz, sz); g.fill();
if (!small && v > .5) { const gr = g.createLinearGradient(0, y, 0, y + sz); gr.addColorStop(0, `rgba(255,255,255,${(dark ? .2 : .16) * v})`); gr.addColorStop(.5, 'rgba(255,255,255,0)'); gr.addColorStop(1, `rgba(0,0,0,${(dark ? .1 : .06) * v})`); // check-registry-ignore: the locked renderer paints a canvas
g.fillStyle = gr; g.beginPath(); g.roundRect(x, y, sz, sz, rad); g.fill(); } }
}
// blocks: lit cells butt into one shape, cells told apart only by tone. At large sizes the shape's outside corners are
// rounded, its inside corners get a matching fillet (so an L reads as one moulded piece), and a cell arriving grows in.
drawBlocks(V: Float32Array, C: RGB[], K: Kind[]) { const { P, off, small } = this, g = this.g!, TH = .15, r = small ? 0 : P * .24, grow = (q: number) => small ? 1 : eio(clamp((V[q]! - TH) / .22));
const on = (i: number, j: number) => i >= 0 && j >= 0 && i < 5 && j < 5 && V[j * 5 + i]! >= TH && grow(j * 5 + i) > .98;
for (let j = 0; j < N; j++) for (let i = 0; i < N; i++) { const q = j * 5 + i; if (V[q]! < TH) continue; const x = off + i * P, y = off + j * P, gq = grow(q);
g.fillStyle = paint(C[q]!); g.beginPath();
if (gq < .98) { const s2 = P * (.5 + .5 * gq), d0 = (P - s2) / 2; g.roundRect(x + d0, y + d0, s2, s2, r * (.6 + .4 * gq)); g.fill(); }
else { const L = on(i - 1, j), R = on(i + 1, j), T = on(i, j - 1), B = on(i, j + 1), e = small ? 0 : .6, w = P + (R ? e : 0), h = P + (B ? e : 0);
if (r) g.roundRect(x, y, w, h, [!L && !T ? r : 0, !R && !T ? r : 0, !R && !B ? r : 0, !L && !B ? r : 0]); else g.rect(x, y, w, h); g.fill(); }
if (K[q] === 'ring') { const s2 = small ? Math.max(2, P - 4) : P * .42, d0 = (P - s2) / 2; g.fillStyle = paint(this.dark ? mix(C[q]!, RING_DARK, .55) : mix(C[q]!, WHITE, .55)); g.beginPath(); if (small) g.rect(x + Math.round(d0), y + Math.round(d0), s2, s2); else g.roundRect(x + d0, y + d0, s2, s2, s2 * .25); g.fill(); } }
// inside corners: where an empty cell's corner is hugged by two lit neighbours, fill a small concave fillet
if (!r) return; const fr = r * .9;
for (let j = 0; j < N; j++) for (let i = 0; i < N; i++) { if (on(i, j)) continue; const x = off + i * P, y = off + j * P;
for (const [sx, sy, cx, cy] of [[-1, -1, x, y], [1, -1, x + P, y], [1, 1, x + P, y + P], [-1, 1, x, y + P]] as const) {
if (!on(i + sx, j) || !on(i, j + sy) || !on(i + sx, j + sy)) continue; const a = C[j * 5 + i + sx]!, b = C[(j + sy) * 5 + i]!; g.fillStyle = paint(mix(a, b, .5));
const ox = cx - sx * fr, oy = cy - sy * fr; g.beginPath(); g.moveTo(cx, cy); g.lineTo(cx, oy); g.arc(ox, oy, fr, sx < 0 ? PI : 0, sy < 0 ? -PI / 2 : PI / 2, sx * sy < 0); g.closePath(); g.fill(); } }
}
}
/** A state's English name ("Reading", "Generating an image"), for its label. */
export const thinkingMarkName = (state: ThinkingMarkState) => byId[state].name;
/* ------------------------------------------------------------------ one clock for many (the locked run) */
type Drawer = (t: number) => void;
const drawers = new Set<Drawer>();
let origin = 0;
let frame = 0;
/** Seconds on the shared clock: every mark on the page reads the same time, so a hand-off starts where the loop is. */
const now = () => (origin ? (performance.now() - origin) / 1000 : 0);
const tick = () => {
const t = now();
for (const d of drawers) d(t);
frame = drawers.size ? requestAnimationFrame(tick) : 0;
};
function join(d: Drawer) {
if (!origin) origin = performance.now();
drawers.add(d);
if (!frame) frame = requestAnimationFrame(tick);
return () => {
drawers.delete(d);
if (!drawers.size && frame) {
cancelAnimationFrame(frame);
frame = 0;
}
};
}
/** The theme a canvas sits in: the foundation's --pixilui-dark (1 under .dark or data-theme="dark"). */
const themeOf = (el: Element): ThinkingMarkTheme => (getComputedStyle(el).getPropertyValue("--pixilui-dark").trim() === "1" ? "dark" : "light");
export type ThinkingMarkProps = Omit<ComponentPropsWithoutRef<"canvas">, "children" | "width" | "height"> & {
/** What the agent is doing: one of the 36 activities ("searching", "writing", "asking", "done"). */
state: ThinkingMarkState;
/** CSS pixels. 16 to 28 draws crisp pixel blocks; larger rounds the corners. */
size?: number;
/** blocks: one moulded shape (default). grid: cells in visible sockets. */
variant?: ThinkingMarkStyle;
/** Seconds added to the shared clock, so neighbours don't pulse together (index times .37). */
offset?: number;
/** Hold one frame at this time (seconds) instead of playing, for stills and tests. */
at?: number;
/** The mark's accessible name ("Searching"). Without it the mark is decorative: put the words next to it. */
label?: string;
};
/**
* What an agent is doing, acted out on a 5 by 5 grid: a radar sweep while it searches, a reading head moving through text,
* a question mark drawing itself when it needs you. Changing state hands over cell by cell from the centre.
*/
export const ThinkingMark = forwardRef<HTMLCanvasElement, ThinkingMarkProps>(function ThinkingMark(
{ state, size = 16, variant = "blocks", offset = 0, at, label, className, ...rest },
ref,
) {
const canvas = useRef<HTMLCanvasElement>(null);
useImperativeHandle(ref, () => canvas.current!, []);
const glyph = useRef<ThinkingMarkGlyph | null>(null);
const shown = useRef<ThinkingMarkState>(state);
const props = useRef({ offset, at });
useLayoutEffect(() => {
props.current = { offset, at };
}, [offset, at]);
// the glyph for this canvas, size, style and theme; rebuilt when the theme changes
useLayoutEffect(() => {
const c = canvas.current;
if (!c) return;
const build = () => {
const prev = glyph.current;
glyph.current = new ThinkingMarkGlyph(c, shown.current, { size, style: variant, theme: themeOf(c) });
if (prev) glyph.current.set(prev.s, prev.start);
paint();
};
const paint = () => {
const { offset: o, at: a } = props.current;
glyph.current?.draw((a ?? now()) + o);
};
build();
const watch = new MutationObserver(() => {
if (glyph.current && themeOf(c) !== glyph.current.theme) build();
});
for (const el of [document.documentElement, document.body]) watch.observe(el, { attributes: true, attributeFilter: ["class", "data-theme"] });
return () => watch.disconnect();
}, [size, variant]);
// a new state hands over from the centre, starting now on the shared clock
useEffect(() => {
if (state === shown.current) return;
shown.current = state;
const g = glyph.current;
if (!g) return;
if (props.current.at !== undefined) g.set(state, 0);
else g.setState(state, now() + props.current.offset);
g.draw((props.current.at ?? now()) + props.current.offset);
}, [state]);
// play on the shared clock while on screen; a held frame (at) or reduced motion draws once
useEffect(() => {
const c = canvas.current;
if (!c) return;
if (at !== undefined || reduce.matches) {
glyph.current?.draw((at ?? now()) + offset);
return;
}
let leave: (() => void) | null = null;
const play = () => (leave ??= join((t) => glyph.current?.draw(t + props.current.offset)));
const pause = () => {
leave?.();
leave = null;
};
if (typeof IntersectionObserver === "undefined") {
play();
return pause;
}
const io = new IntersectionObserver(([e]) => (e?.isIntersecting ? play() : pause()));
io.observe(c);
return () => {
io.disconnect();
pause();
};
}, [at, offset, state]);
return (
<canvas
ref={canvas}
className={cn("pixilui-activity-mark", className)}
data-state={state}
role={label ? "img" : undefined}
aria-label={label}
aria-hidden={label ? undefined : true}
{...rest}
/>
);
});
/* ------------------------------------------------------------------ simulation */
/** One step of a simulated run: the activity, and how long it lasts (ms). */
export type ThinkingMarkStep = { state: ThinkingMarkState; ms: number };
const RUN: ThinkingMarkStep[] = [
{ state: "thinking", ms: 2200 },
{ state: "searching", ms: 2400 },
{ state: "reading", ms: 2600 },
{ state: "analyzing", ms: 2000 },
{ state: "writing", ms: 2800 },
{ state: "done", ms: 3000 },
];
/**
* Plays a believable run for demos and tests, at human speed: thinking, searching, reading, analyzing, writing, done, then
* again. Pass your own steps. With autoplay false it holds the first step and runs no timers.
*/
export function useThinkingMarkSimulation({ steps = RUN, autoplay = true, loop = true }: { steps?: ThinkingMarkStep[]; autoplay?: boolean; loop?: boolean } = {}) {
const [at, setAt] = useState(0);
useEffect(() => {
if (!autoplay) return;
const step = steps[at];
if (!step || (!loop && at === steps.length - 1)) return;
const timer = setTimeout(() => setAt((i) => (i + 1) % steps.length), step.ms);
return () => clearTimeout(timer);
}, [at, autoplay, loop, steps]);
const state = steps[at]?.state ?? "idle";
return { state, name: thinkingMarkName(state), index: at };
}
Then npm i clsx tailwind-merge, and add the foundation once per app, as in Installation.
Usage
import { ThinkingMark } from "@/components/pixilui/thinking-mark";
<ThinkingMark state={state} />Any size in CSS pixels. At 16 to 28 each cell is a whole number of device pixels with square corners; larger, corners round with matching inside fillets.
API reference
stateRequired"thinking" | "planning" | "remembering" | "comparing" | "brainstorming" | "deciding" | "searching" | "reading" | "browsing" | "indexing" | "fetching" | "analyzing" | "writing" | "editing" | "summarizing" | "translating" | "generating" | "compacting" | "running" | "testing" | "debugging" | "building" | "deploying" | "merging" | "listening" | "speaking" | "asking" | "waiting" | "calling" | "delegating" | "idle" | "queued" | "paused" | "retrying" | "done" | "failed"–What the agent is doing: one of the 36 activities ("searching", "writing", "asking", "done").sizenumber16CSS pixels. 16 to 28 draws crisp pixel blocks; larger rounds the corners.variant"blocks" | "grid""blocks"blocks: one moulded shape (default). grid: cells in visible sockets.offsetnumber0Seconds added to the shared clock, so neighbours don't pulse together (index times .37).atnumber–Hold one frame at this time (seconds) instead of playing, for stills and tests.labelstring–The mark's accessible name ("Searching"). Without it the mark is decorative: put the words next to it.Also takes every native <canvas> attribute except width, height, and a ref.
Keyboard
Accessibility
- Decorative by default (aria-hidden): put the activity in words next to it. With label it is role img with that name.
- Color is never the only signal: every activity has its own drawing.
- Reduced motion: one representative frame per activity, drawn still, and no hand-off.
Motion
- Each activity loops its own drawing (0.6 to 4.4s), rasterised onto 25 cells: brightness hands over between cells, nothing slides.
- A new state hands over from the centre out: .26s per cell, .07s later per cell of distance.
- Done draws its tick and holds from 1.5s. A soft lighter band drifts corner to corner every 3.8s. No glow.
- Every mark on the page shares one clock; give neighbours an offset (index times .37s) so they don't pulse together. Off screen, a mark stops drawing.
- Reduced motion: one still frame per activity.