timeline
ui · paida medium's time as tracks under one ruler that zooms: chapters, stills, claims
npx shadcn add @ag/timelineA paid item: its source installs with a licence key, kept in .env.local as AG_LICENCE_KEY and sent from components.json. The source stays in your project and out of any public repository. The licence
{
"registries": {
"@ag": {
"url": "https://ui.adriangalilea.com/r/{name}.json",
"headers": { "Authorization": "Bearer ${AG_LICENCE_KEY}" }
}
}
}Already installed? Preview an update
npx shadcn add @ag/timeline --dry-runYour installed source stays unchanged until you update it. How updates work
- Changed (breaking): a timeline's rows are tracks:
TimelineRow,TimelineClaimRow,TimelineCurveRowareTimelineTrack,TimelineClaimTrack,TimelineCurveTrack;Timeline'srowsistracks;TimelineAnswer'srowistrack;lib/timeline-rowsislib/timeline-tracks; the editing actionsrow-upandrow-downaretrack-upandtrack-down. Migration: deletetimeline-rows.ts, import fromlib/timeline-tracks, rename the types and the prop.
also called video editor
shelf motion
comes with timeline-view
uses playable, span, image, timebase, playback, button, kbd, keys, key-router, material, card
the demo above, verbatim
"use client"
import * as React from "react"
import { Sample } from "@/app/samples"
// #region interview-media
import INTERVIEW_FACES from "@/public/apollo-11/cronkite-aldrin.faces.json"
// #endregion
// #region speech-media
import MOON_FACES from "@/public/kennedy/moon.faces.json"
import MOON_SAID from "@/public/kennedy/moon.transcript.json"
import INTERVIEW_LOUDNESS from "@/public/timeline/cronkite-aldrin.loudness.json"
import MOON_LOUDNESS from "@/public/timeline/moon.loudness.json"
// #endregion
import type { Chapter, Playable } from "@/registry/base-nova/lib/playable"
import { MaterialProvider } from "@/registry/base-nova/ui/material"
import { Playback } from "@/registry/base-nova/ui/playback"
import { PlayerChrome, PlayerTransport } from "@/registry/base-nova/ui/player"
import {
type CurvePoint,
Timeline,
type TimelineAnswer,
type TimelineClaim,
} from "@/registry/base-nova/ui/timeline"
import {
VideoPicture,
VideoPlayback,
} from "@/registry/base-nova/ui/video-playback"
// #region claims
/** A face found every half second (`[from, to, x, y, r]`, perceive's samples) as the
* spans the face is on screen: samples that touch join into one claim, the machine's. */
function onScreen(who: string, samples: number[][]): TimelineClaim[] {
const spans: { from: number; to: number }[] = []
for (const [from, to] of samples) {
if (from === undefined || to === undefined)
throw new Error(`${who}: a face sample is short`)
const last = spans[spans.length - 1]
if (last && from - last.to <= 500) last.to = to
else spans.push({ from, to })
}
return spans.map((when, i) => ({
id: `${who}-${i}`,
when,
answer: who,
by: "machine",
}))
}
/** A loudness file's `[ms, value]` pairs as a curve. */
const curveOf = (pairs: number[][]): CurvePoint[] =>
pairs.map(([at, value]) => ({ at: at as number, value: value as number }))
// #endregion
// #region interview
// Walter Cronkite questions Buzz Aldrin, 5 July 1969 (NASA, public domain): the camera
// cuts between them; perceive found their faces, the sound is the file's own.
const INTERVIEW_FPS = 30000 / 1001
const TURNS: Chapter[] = [
{ start: 0, title: "is the public overconfident?" },
{ start: 33_000, title: "the reaction we hoped for" },
{ start: 60_800, title: "if, or when?" },
{ start: 76_500, title: "when we land, not if" },
]
const CRONKITE = onScreen("cronkite", INTERVIEW_FACES.cronkite)
const ALDRIN = onScreen("aldrin", INTERVIEW_FACES.aldrin)
/** Where the picture cuts to the other man: every on-screen span's start but the
* first, an instant each. */
const CUTS: TimelineClaim[] = [...CRONKITE, ...ALDRIN]
.map((c) => ("from" in c.when ? c.when.from : c.when.at))
.filter((at) => at > 0)
.sort((a, b) => a - b)
.map((at) => ({ id: `cut-${at}`, when: { at }, by: "machine" }))
/** Who speaks, as a person said it so far: the first two turns. */
const SAID_SO_FAR: TimelineClaim[] = [
{
id: "said-0",
when: { from: 640, to: 32_000 },
answer: "cronkite",
by: "person",
},
{
id: "said-1",
when: { from: 33_220, to: 60_000 },
answer: "aldrin",
by: "person",
},
]
// #endregion
function Interview() {
const [said, setSaid] = React.useState(SAID_SO_FAR)
// A person's answer becomes their claim: kept here, handed back in the track.
const answer = ({ when, answer }: TimelineAnswer) =>
setSaid((was) => [
...was,
{ id: `said-${was.length}`, when, answer, by: "person" },
])
return (
<VideoPlayback
src="/apollo-11/cronkite-aldrin.mp4"
poster="/apollo-11/cronkite-aldrin.jpg"
label="Cronkite questions Aldrin, July 1969"
fps={INTERVIEW_FPS}
chapters={TURNS}
>
<div className="flex flex-col gap-3">
<VideoPicture
aspect="626 / 476"
className="mx-auto w-full max-w-sm rounded-xl"
>
<PlayerChrome>
<PlayerTransport only={["play"]} />
</PlayerChrome>
</VideoPicture>
<Timeline
label="Cronkite questions Aldrin"
filmstrip={{
still: (ms) =>
`/gallery-stills/cronkite-aldrin/${Math.min(108, Math.floor(ms / 1000))}.jpg`,
every: 1000,
aspect: 626 / 476,
}}
tracks={[
{
id: "speaks",
kind: "claims",
label: "who speaks",
claims: said,
answers: ["cronkite", "aldrin"],
},
{
id: "cronkite",
kind: "claims",
label: "cronkite on screen",
claims: CRONKITE,
},
{
id: "aldrin",
kind: "claims",
label: "aldrin on screen",
claims: ALDRIN,
},
{ id: "cuts", kind: "claims", label: "cuts", claims: CUTS },
{
id: "loud",
kind: "curve",
label: "loudness",
points: curveOf(INTERVIEW_LOUDNESS),
},
]}
onAnswer={answer}
/>
</div>
</VideoPlayback>
)
}
// #region speech
// John F. Kennedy at Rice University, 12 September 1962: his words as listen timed
// them, his face where perceive found it (the camera leaves him for the crowd).
const MOON_FPS = 24000 / 1001
const MOON_PARTS: Chapter[] = [
{ start: 0, title: "why climb the highest mountain" },
{ start: 9_060, title: "we choose to go to the moon" },
{ start: 19_860, title: "because they are hard" },
{ start: 39_720, title: "and we intend to win" },
]
const WORDS: TimelineClaim[] = MOON_SAID.map((u, i) => ({
id: `said-${i}`,
when: u.span,
answer: u.text,
}))
const KENNEDY = onScreen("kennedy", MOON_FACES.kennedy)
// #endregion
function Speech() {
return (
<VideoPlayback
src="/kennedy/moon.mp4"
poster="/kennedy/moon.jpg"
label="John F. Kennedy, September 1962"
fps={MOON_FPS}
chapters={MOON_PARTS}
>
<div className="flex flex-col gap-3">
<VideoPicture
aspect="640 / 480"
className="mx-auto w-full max-w-xs rounded-xl"
>
<PlayerChrome>
<PlayerTransport only={["play"]} />
</PlayerChrome>
</VideoPicture>
<Timeline
label="We choose to go to the Moon"
filmstrip={{
still: (ms) =>
`/timeline/moon/${Math.min(49, Math.floor(ms / 1000))}.jpg`,
every: 1000,
aspect: 640 / 480,
}}
tracks={[
{ id: "said", kind: "claims", label: "said", claims: WORDS },
{
id: "kennedy",
kind: "claims",
label: "kennedy on screen",
claims: KENNEDY,
},
{
id: "loud",
kind: "curve",
label: "loudness",
points: curveOf(MOON_LOUDNESS),
},
]}
/>
</div>
</VideoPlayback>
)
}
// #region many
// An hour of drawn time with ten thousand machine claims and a value every 100 ms:
// what a long recording's detections look like. Seeded, so every visit is the same.
const HOUR: Playable = {
duration: 3_600_000,
chapters: [0, 1, 2, 3].map((q) => ({
start: q * 900_000,
title: `quarter ${q + 1}`,
})),
}
const seeded = (seed: number) => () => {
seed = (seed * 1_103_515_245 + 12_345) % 2 ** 31
return seed / 2 ** 31
}
const random = seeded(11)
const GUESSES: TimelineClaim[] = Array.from({ length: 10_000 }, (_, i) => {
const from = Math.floor(random() * 3_590_000)
return {
id: `guess-${i}`,
when: { from, to: from + 500 + Math.floor(random() * 8_000) },
answer: "a ball",
by: "machine",
}
})
// #endregion
function Many() {
return (
<Playback playable={HOUR} autoPlay={false}>
<Timeline
label="an hour of detections"
tracks={[
{ id: "ball", kind: "claims", label: "ball seen", claims: GUESSES },
]}
/>
</Playback>
)
}
export default function TimelineDemo() {
return (
<div className="space-y-8">
<Sample
name="interview"
title="an interview, every track"
description="Click in the timeline and the keys are an editor's: J K L shuttle, ← → a frame, ⌥ ← → the next edge, I and O set the selection, 1 and 2 say who speaks over it, R repeats it, B goes back to where you were. A pinch zooms at the hand down to the frame; a drag selects, snapping to every edge."
with="interview-media claims interview"
>
<Interview />
</Sample>
<Sample
name="speech"
title="a speech, in glass"
with="speech-media claims speech"
>
<MaterialProvider material="glass">
<div className="rounded-2xl bg-[url(/lightbox/peaks.jpg)] bg-cover bg-center p-4 sm:p-8">
<Speech />
</div>
</MaterialProvider>
</Sample>
<Sample
name="many"
glance="wide"
title="ten thousand claims"
description="The whole hour paints the track; zoom in and it becomes claims you can point at, each drawn only while it is in view."
with="many"
>
<Many />
</Sample>
</div>
)
}
