CodeCard
Dark code card that types each line in place at a steady character rate, one line after another.
Loading preview…
Install
npx shadcn@latest add @jbm/code-cardNeeds the @jbm entry in components.json; see Install once.
Also installs @jbm/card, @jbm/tokens.
Needs Remotion: render inside a Remotion <Composition> or <Player>, not a plain React tree. Timing values are in seconds.
- Docs
Usage
import { CodeCard } from "@/jbm/motion/code-card"<CodeCard title="hello.ts" charsPerSecond={32} lines={[ { t: "const idea = \"simple\"", at: 0.2 }, { t: "render(idea)", at: 0.7, color: "#FF8A6A" },]} />import { codeTypingSchedule } from "@/jbm/motion/code-card-timing"const fps = 30const schedule = codeTypingSchedule(lines, fps, 32)const durationInFrames = (schedule.at(-1)?.end ?? 0) + 1API
- Stage px
- Declared at the documented defaults
- Landscape
900 by 520- Vertical
900 by 520- Basis
The card is border-box with width
w(900) and heighth(520) at the defaults, regardless of content. Scene specs pass w = min(usable width, 1200) and h 480 in landscape, the usable width (936) and h 520 in vertical, and the available height in illustration layouts. Long lines do not wrap; they clip at the card edge.
CodeCardcomponent
Fixed-size dark Card with three window dots, an optional mono title, and mono code lines. Each line starts typing at its at cue or when the previous line finishes, whichever is later, at charsPerSecond; empty rows keep their line height so the layout never jumps.
| Prop | Type | Default | Description |
|---|---|---|---|
lines | CodeLine[] | required | Code lines in order: t is the text (whitespace preserved, no wrapping), at is the earliest start in seconds relative to the enclosing Sequence, and optional color overrides the cream text color. |
w | number | 900 | Card width in stage pixels. |
h | number | 520 | Card height in stage pixels; content beyond it is clipped. |
size | number | 24 | Code font size in stage pixels; lines are 1.55 × size tall. |
title | string | none | Optional mono file name beside the window dots. |
charsPerSecond | number | 32 | Typing rate in characters per second; must be positive and finite or the schedule throws. |
codeTypingSchedulefunction
Builds the sequential typing schedule CodeCard uses, in frames. Use it in the host to budget scene duration: the last entry's end plus one terminal frame.
| Param | Type | Default | Description |
|---|---|---|---|
lines | { t: string; at: number }[] | required | The same { t, at } lines passed to CodeCard; at in seconds. |
fps | number | required | Composition frames per second. |
charsPerSecond | number | none | Typing rate; throws a RangeError unless positive and finite. |
Returns One { characters, start, end } per line: the line split into characters (code points) and its start and end frames.
typedCodefunction
The visible prefix of one scheduled line at a given frame.
| Param | Type | Default | Description |
|---|---|---|---|
line | CodeTypingLine | required | One entry from codeTypingSchedule. |
frame | number | required | Current frame relative to the enclosing Sequence. |
fps | number | required | Composition frames per second. |
charsPerSecond | number | none | Typing rate; must match the value used for the schedule. |
Returns The typed text so far: empty before start, the full line from end on.
QA checks
- Step to the first frame (empty rows at full height), mid-typing (a partially typed line, earlier lines complete), and the last frame (every line complete).
- Give two lines overlapping
atcues: the second waits for the first to finish instead of typing in parallel. - Check the longest line and the line count fit inside
w×hat the chosensize; overflow is clipped, not wrapped. - Inspect the dark surface border and shadow at display scale (docs/surface-depth.md).