jbmui

CodeCard

  • Motion
  • replayable
  • video player

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

Needs 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

Type a short file
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" },]} />
Budget the scene length
import { codeTypingSchedule } from "@/jbm/motion/code-card-timing"const fps = 30const schedule = codeTypingSchedule(lines, fps, 32)const durationInFrames = (schedule.at(-1)?.end ?? 0) + 1

API

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 height h (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.

PropTypeDefaultDescription
linesCodeLine[]requiredCode 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.
wnumber900Card width in stage pixels.
hnumber520Card height in stage pixels; content beyond it is clipped.
sizenumber24Code font size in stage pixels; lines are 1.55 × size tall.
titlestringnoneOptional mono file name beside the window dots.
charsPerSecondnumber32Typing 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.

ParamTypeDefaultDescription
lines{ t: string; at: number }[]requiredThe same { t, at } lines passed to CodeCard; at in seconds.
fpsnumberrequiredComposition frames per second.
charsPerSecondnumbernoneTyping 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.

ParamTypeDefaultDescription
lineCodeTypingLinerequiredOne entry from codeTypingSchedule.
framenumberrequiredCurrent frame relative to the enclosing Sequence.
fpsnumberrequiredComposition frames per second.
charsPerSecondnumbernoneTyping 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 at cues: the second waits for the first to finish instead of typing in parallel.
  • Check the longest line and the line count fit inside w × h at the chosen size; overflow is clipped, not wrapped.
  • Inspect the dark surface border and shadow at display scale (docs/surface-depth.md).