film-mosaic
ui · paida film as a mosaic of tiles all playing, in its player's box: pinch into time
npx shadcn add @ag/film-mosaicA 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/film-mosaic --dry-runYour installed source stays unchanged until you update it. How updates work
- Declares
timeline-view, which its zoom imported.
also called storyboard, contact sheet, filmstrip mosaic, video wall, zui, zoomable film, video scrubber
shelf media
uses span, timebase, timeline-view, playback, video, player, media-line, film-stills, lightbox-motion, audible, remembered, switch, menu, portal, button, key-router, material, tooltip
the demo above, verbatim
"use client"
import * as React from "react"
import { Sample } from "@/app/samples"
import type { Captions } from "@/registry/base-nova/lib/captions"
import { frameStills } from "@/registry/base-nova/lib/film-stills-core"
import { spanWords } from "@/registry/base-nova/lib/film-tiles"
import type { Span } from "@/registry/base-nova/lib/span"
import { FilmMosaic } from "@/registry/base-nova/ui/film-mosaic"
import { useSeekStills, useStills } from "@/registry/base-nova/ui/film-stills"
import {
FilmWall,
FilmWallMotion,
FilmWallToggle,
} from "@/registry/base-nova/ui/film-wall"
import { MaterialProvider } from "@/registry/base-nova/ui/material"
import {
PlayerBar,
PlayerCaptions,
PlayerChrome,
PlayerFoot,
PlayerTransport,
} from "@/registry/base-nova/ui/player"
import {
VideoPicture,
VideoPlayback,
} from "@/registry/base-nova/ui/video-playback"
// #region films
// Each film's facts as its prepared media asset states them (lib/media-asset): its
// length, its frame's size, and the stills cut along it, one a second.
interface Film {
label: string
src: string
duration: number
width: number
height: number
captions?: readonly Captions[]
frames?: { every: number; count: number; src: string }
}
const INTERVIEW: Film = {
label: "Cronkite questions Aldrin, July 1969",
src: "/apollo-11/cronkite-aldrin.mp4",
duration: 109_009,
width: 626,
height: 476,
frames: {
every: 1,
count: 109,
src: "/gallery-stills/cronkite-aldrin/{i}.jpg",
},
}
const KEYNOTE: Film = {
label: "Steve Jobs introduces the iPhone, 2007",
src: "/jobs/iphone.mp4",
duration: 118_500,
width: 640,
height: 352,
}
const PORTRAIT: Film = {
label: "Stay hungry, stay foolish (portrait cut)",
src: "/jobs/hungry-portrait.mp4",
duration: 40_006,
width: 360,
height: 640,
}
const MOON: Film = {
label: "We choose to go to the Moon",
src: "/kennedy/moon.mp4",
duration: 50_050,
width: 640,
height: 480,
captions: [
{
src: "/kennedy/moon.en.vtt",
lang: "en",
label: "English",
default: true,
},
{ src: "/kennedy/moon.es.vtt", lang: "es", label: "español" },
],
}
const CDN = "https://cdn.untitled.garden/media/ui/gallery"
/** From the gallery's corpus (Wikimedia Commons), on its CDN. */
const SHELF: Film[] = [
{
label: "one small step",
src: `${CDN}/461a38825c3d7b1172c6d6b2.mp4`,
duration: 56_112,
width: 16,
height: 9,
frames: {
every: 1,
count: 56,
src: `${CDN}/461a38825c3d7b1172c6d6b2.frame-{i}.jpg`,
},
},
{
label: "Le Déjeuner des Minet (1906)",
src: `${CDN}/e141b3900933b1fd907b5d25.mp4`,
duration: 20_003,
width: 16,
height: 9,
frames: {
every: 1,
count: 20,
src: `${CDN}/e141b3900933b1fd907b5d25.frame-{i}.jpg`,
},
},
{
label: "a braided river in Tibet",
src: `${CDN}/ebfc8d8f94158250db14b476.mp4`,
duration: 20_000,
width: 16,
height: 9,
frames: {
every: 1,
count: 20,
src: `${CDN}/ebfc8d8f94158250db14b476.frame-{i}.jpg`,
},
},
]
// #endregion
// #region stills
/** Each film's stills source, made once (a new one each render is a new cache). */
const SECONDS = new Map(
[INTERVIEW, ...SHELF].map((f) => [
f.src,
frameStills(f.frames as NonNullable<Film["frames"]>),
]),
)
const stillsOf = (src: string) => {
const source = SECONDS.get(src)
if (!source) throw new Error(`no stills for ${src}`)
return source
}
// #endregion
// #region player
/** The registry's player, in the mosaic's box, started where the pressed tile was; the
* mosaic's toggle in its bar comes back. */
function playerFor(film: Film) {
return (start: number) => (
<VideoPlayback
src={film.src}
label={film.label}
width={film.width}
height={film.height}
captions={film.captions}
start={start}
autoPlay
>
<VideoPicture>
<PlayerChrome>
<PlayerTransport />
<PlayerFoot>
<PlayerBar label={film.label} playButton={false}>
{film.captions && <PlayerCaptions />}
<FilmWallToggle />
</PlayerBar>
</PlayerFoot>
</PlayerChrome>
</VideoPicture>
</VideoPlayback>
)
}
// #endregion
// #region mosaic
/** The film as a mosaic: every tile playing, the switch for that at the end of its
* bar. */
function Mosaic() {
const stills = useStills([stillsOf(INTERVIEW.src)])
return (
<FilmWall {...INTERVIEW} stills={stills} player={playerFor(INTERVIEW)}>
<FilmWallMotion />
</FilmWall>
)
}
// #endregion
// #region shelf
/** One film a row, as a strip: a pass over many without leaving the list. */
function Shelf() {
return (
<div className="flex w-full flex-col gap-4">
{SHELF.map((film) => (
<ShelfRow key={film.src} film={film} />
))}
</div>
)
}
function ShelfRow({ film }: { film: Film }) {
const stills = useStills([stillsOf(film.src)])
return (
<div className="flex flex-col gap-1.5">
<span className="font-medium text-[13px]">{film.label}</span>
<FilmMosaic
tile={120}
label={film.label}
duration={film.duration}
aspect={film.width / film.height}
src={film.src}
stills={stills}
/>
</div>
)
}
// #endregion
// #region owner
/** Under its player: a press hands the span to it, the tile it is playing is lit. */
function WithPlayer() {
const stills = useStills([stillsOf(INTERVIEW.src)])
return (
<VideoPlayback
src={INTERVIEW.src}
label={INTERVIEW.label}
poster="/apollo-11/cronkite-aldrin.jpg"
>
<div className="flex w-full flex-col gap-2">
<VideoPicture aspect="626 / 476" className="rounded-xl">
<PlayerChrome>
<PlayerTransport only={["play"]} />
<PlayerFoot>
<PlayerBar label={INTERVIEW.label} />
</PlayerFoot>
</PlayerChrome>
</VideoPicture>
<FilmMosaic
label={INTERVIEW.label}
duration={INTERVIEW.duration}
aspect={INTERVIEW.width / INTERVIEW.height}
src={INTERVIEW.src}
stills={stills}
tile={110}
/>
</div>
</VideoPlayback>
)
}
// #endregion
// #region chosen
/** No player around: the page hears the span. */
function Chosen() {
const stills = useStills([stillsOf(INTERVIEW.src)])
const [span, setSpan] = React.useState<Span | null>(null)
return (
<div className="flex w-full flex-col gap-2">
<FilmMosaic
label={INTERVIEW.label}
duration={INTERVIEW.duration}
aspect={INTERVIEW.width / INTERVIEW.height}
view={{ from: 30_000, to: 60_000 }}
src={INTERVIEW.src}
stills={stills}
tile={100}
onPlay={setSpan}
/>
<span className="font-mono text-[11px] text-foreground/60">
{span
? `chosen: ${spanWords(span)}`
: "half a minute of it, 0:30 to 1:00"}
</span>
</div>
)
}
// #endregion
// #region decoded
/** Nothing prepared: every tile decoded on the page, its rate measured. */
function Decoded() {
const decoded = useSeekStills(MOON.src, { width: 320 })
const stills = useStills([decoded.source])
return (
<FilmMosaic
label={MOON.label}
duration={MOON.duration}
aspect={MOON.width / MOON.height}
src={MOON.src}
stills={stills}
tile={120}
className="w-full"
/>
)
}
// #endregion
export default function FilmMosaicDemo() {
return (
<div className="space-y-8">
<Sample
name="mosaic"
glance="large"
title="a film as a mosaic"
description="Every tile plays its own stretch at once (as many as the machine keeps up with; the rest wait their turn on their first picture); the switch above turns that to only the tile under the hand. Spread two fingers on a tile (or its zoom) and its stretch becomes the mosaic; close them (or Esc) to go back out; swipe sideways, or the arrows, for the next stretch. A tile's play opens the player there, in the same box; its grid button comes back."
with="films stills player mosaic"
>
<Mosaic />
</Sample>
<Sample
name="captions"
title="every tile captioned"
description="Captions are the one choice every player shares: on here (C), every tile says its own line, and the player it opens shows them too."
with="films player"
>
<FilmWall {...MOON} player={playerFor(MOON)} />
</Sample>
<Sample
name="portrait"
title="a portrait film"
description="A square grid cuts a box of the film's shape into cells of that shape: every tile is the whole frame, tall or wide."
with="films player"
>
<div className="mx-auto w-full max-w-sm">
<FilmWall {...PORTRAIT} player={playerFor(PORTRAIT)} />
</div>
</Sample>
<Sample
name="grid"
title="any grid, cover or contain"
description="Four across, two down: the cells no longer have the film's shape, so cover crops each frame round its centre and contain shows it whole with bars. No stills: a tile is black until its first frame."
with="films player"
>
<div className="grid w-full gap-6 lg:grid-cols-2">
<FilmWall
{...KEYNOTE}
grid={{ cols: 4, rows: 2 }}
player={playerFor(KEYNOTE)}
/>
<FilmWall
{...KEYNOTE}
grid={{ cols: 4, rows: 2 }}
fit="contain"
player={playerFor(KEYNOTE)}
/>
</div>
</Sample>
<Sample name="glass" title="in glass" with="films player">
<MaterialProvider material="glass">
<div className="w-full rounded-2xl bg-[url(/lightbox/peaks.jpg)] bg-cover bg-center p-4 sm:p-8">
<FilmWall {...KEYNOTE} player={playerFor(KEYNOTE)} />
</div>
</MaterialProvider>
</Sample>
<Sample
name="shelf"
title="a shelf of strips"
description="Many films, one a row: each a strip of stills, the tile under the hand playing. The count follows the row's width."
with="films stills shelf"
>
<Shelf />
</Sample>
<Sample
name="player"
title="a strip under its player"
description="A press hands the span to the player; the tile it is playing wears the playhead."
with="films stills owner"
>
<WithPlayer />
</Sample>
<Sample name="part" title="a part of a film" with="films stills chosen">
<Chosen />
</Sample>
<Sample
name="decoded"
title="nothing prepared"
description="A film with no stills cut: each tile is decoded here, one hidden video seeking, the film's rate timed first."
with="films decoded"
>
<Decoded />
</Sample>
</div>
)
}