The open creative studio on ComfyUI: images, video, 3D and audio on open weights, on your own GPU or the cloud. Camera motions, effects, apps, Cinema, Layers, Image to 3D and an AI agent.
TypeScript ai-videocomfyuicreative-toolsgenerative-aiideogramimage-generationimage-to-3dimage-to-videoltx-videominimax-h3nextjsopen-sourceopen-weightsqwen-imagetext-to-imagevideo-generationwan
Pickers: camera motions, Mix and Cinema's moves show their real covers
Adarsh7f757189a1e8
diff --git a/scripts/eval/README.md b/scripts/eval/README.mdindex a6f1a2a3..d99d9f03 100644--- a/scripts/eval/README.md+++ b/scripts/eval/README.md@@ -457,7 +457,9 @@ metric) and makes it that preset's cover. A still becomes a JPEG of at most 768first 4 seconds, muted, at most 512 px, with its first frame as the poster. They go to`public/previews/<suite>/`, and `src/lib/preset-previews.generated.ts` lists them by preset id (aDoP preset, `effect-thunder-god`) or look id (`v1-general`). The gallery cards play a listed cover-instead of their procedural preview.+instead of their procedural preview. Next to it, `src/lib/preset-covers.generated.ts` says only which+presets have a cover and a clip: the pickers (camera motions, Mix, Cinema Studio's moves) read that in+the browser.- `--variant catalog` takes that variant's renders for every case instead, such as what ships today.- `--dry-run` lists what it would pick.diff --git a/scripts/eval/lib/covers.mjs b/scripts/eval/lib/covers.mjsindex 71dfd50a..af42146e 100644--- a/scripts/eval/lib/covers.mjs+++ b/scripts/eval/lib/covers.mjs@@ -65,10 +65,30 @@ export function readManifest(file = MANIFEST_FILE) {}}+const SLIM_HEADER = `/**+ * Which presets have a real cover, for the pickers in the browser (read through presetCover, preset-covers.ts):+ * 1 for a clip at /previews/presets/<id>.mp4 with its poster at <id>.jpg, 0 for a still there, or the files of a+ * cover kept elsewhere. The slim side of preset-previews.generated.ts, whose provenance stays on the server.+ * Generated with it by pnpm eval:covers: run it again rather than editing.+ */+export type PresetCoverEntry = 0 | 1 | { poster: string; video?: string };++export const PRESET_COVERS: Record<string, PresetCoverEntry> = `;++/** A manifest entry as the slim map lists it. */+function slimEntry(id, e) {+ const base = `/previews/presets/${id}`;+ if (e.poster === `${base}.jpg` && (e.video === undefined || e.video === `${base}.mp4`)) return e.video ? 1 : 0;+ return { poster: e.poster, ...(e.video && { video: e.video }) };+}++/** Write the manifest, and the slim covers map the pickers read next to it (preset-covers.generated.ts). */export function writeManifest(entries, file = MANIFEST_FILE) {const sorted = Object.fromEntries(Object.entries(entries).sort(([a], [b]) => a.localeCompare(b)));fs.mkdirSync(path.dirname(file), { recursive: true });fs.writeFileSync(file, `${HEADER}${JSON.stringify(sorted, null, 2)};\n`);+ const slim = Object.fromEntries(Object.entries(sorted).map(([id, e]) => [id, slimEntry(id, e)]));+ fs.writeFileSync(path.join(path.dirname(file), "preset-covers.generated.ts"), `${SLIM_HEADER}${JSON.stringify(slim, null, 2)};\n`);}/** The preset a case's cover belongs to: a DoP preset id, a Soul look's Fuobe id, else the case id. */diff --git a/src/components/cinema/camera-moves.tsx b/src/components/cinema/camera-moves.tsxindex 99f4c77c..d82b1e09 100644--- a/src/components/cinema/camera-moves.tsx+++ b/src/components/cinema/camera-moves.tsx@@ -1,12 +1,14 @@"use client";import { ArrowDownAZ, Check, Hash, ListOrdered, X } from "lucide-react";-import { useMemo, useState } from "react";+import { useMemo, useRef, useState } from "react";+import { CoverScrollBox, CoverTile, usePickerPlayback } from "@/components/cover-tile";import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList } from "@/components/ui/command";import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";import { CAMERA_MOVES, cinemaMoveRoute, moveBySlug, type CameraMove } from "@/lib/catalog/cinema";import type { Engine } from "@/lib/catalog/types";+import { moveCover } from "@/lib/preset-covers";import { cn } from "@/lib/utils";/** Name matches first (prefix, then word start, then anywhere), the slug and the hint after. */@@ -28,6 +30,37 @@ function routeBadge(m: CameraMove, engine: Engine, civitai?: boolean): string |return r.via === "camera-lora" ? "Camera LoRA" : r.via === "lora" ? "LoRA" : r.via === "fun-camera" ? "Fun Camera" : r.via === "hosted-move" ? "Focus move" : null;}+/**+ * One move: the cover of the camera motion it runs (its clip plays while the row is highlighted, by the pointer or+ * the arrow keys), with its place in the shot's order on it once picked; the move's name, how it runs and its hint.+ */+function MoveRow({ move: m, badge, order, highlighted, onPick }: { move: CameraMove; badge: string | null; order: number; highlighted: boolean; onPick: () => void }) {+ const { playing } = usePickerPlayback(m.slug, { highlighted });+ return (+ <CommandItem value={m.name} keywords={[m.slug, m.hint]} onSelect={onPick} className="group/move items-start gap-2.5 py-2">+ <CoverTile+ cover={moveCover(m)}+ playing={playing}+ picked={order >= 0 ? order + 1 : undefined}+ className="mt-0.5 h-9 w-12 rounded-md"+ fallback={+ <span className="absolute inset-0 grid place-items-center text-muted-foreground">+ <Hash className="size-3.5" />+ </span>+ }+ />+ <span className="min-w-0 flex-1">+ <span className="flex items-center gap-1.5 text-[13px] font-medium">+ {m.name}+ {badge && <span className="rounded-full bg-brand-faint px-1.5 py-px text-[10px] font-medium text-brand-text">{badge}</span>}+ </span>+ <span className="block text-[12px] leading-snug text-muted-foreground">{m.hint}</span>+ </span>+ <span className="mt-0.5 shrink-0 text-[11px] font-medium text-brand-text opacity-0 group-data-[selected=true]/move:opacity-100">Use</span>+ </CommandItem>+ );+}+export function MoveList({engine,badges = true,@@ -50,9 +83,12 @@ export function MoveList({}) {const [sort, setSort] = useState<"default" | "name">("default");const [query, setQuery] = useState(defaultQuery ?? "");+ // The highlighted row (its value, the move's name): controlled, as cmdk only reports it then.+ const [highlighted, setHighlighted] = useState("");+ const box = useRef<HTMLDivElement>(null);const moves = useMemo(() => (sort === "name" ? [...CAMERA_MOVES].sort((a, b) => a.name.localeCompare(b.name)) : CAMERA_MOVES), [sort]);return (- <Command loop className="bg-transparent" filter={moveScore}>+ <Command loop className="bg-transparent" filter={moveScore} value={highlighted} onValueChange={setHighlighted}><div className="flex items-center gap-1 pr-1"><div className="min-w-0 flex-1"><CommandInput placeholder="Search camera moves…" value={query} onValueChange={setQuery} autoFocus={autoFocus} />@@ -71,30 +107,23 @@ export function MoveList({<TooltipContent>{sort === "default" ? "Sort: Name (A–Z)" : "Sort: Default"}</TooltipContent></Tooltip></div>- <CommandList className="max-h-[min(52vh,360px)]">- <CommandEmpty>No camera moves match your search</CommandEmpty>- <CommandGroup>- {moves.map((m) => {- const badge = badges ? routeBadge(m, engine, civitai) : null;- const n = selected.indexOf(m.slug);- return (- <CommandItem key={m.slug} value={m.name} keywords={[m.slug, m.hint]} onSelect={() => onPick(m.slug)} className="group/move items-start gap-2.5 py-2">- <span className={cn("mt-0.5 grid size-6 shrink-0 place-items-center rounded-md text-[11px] font-semibold", n >= 0 ? "bg-primary text-primary-foreground" : "bg-muted text-muted-foreground")}>- {n >= 0 ? n + 1 : <Hash className="size-3" />}- </span>- <span className="min-w-0 flex-1">- <span className="flex items-center gap-1.5 text-[13px] font-medium">- {m.name}- {badge && <span className="rounded-full bg-brand-faint px-1.5 py-px text-[10px] font-medium text-brand-text">{badge}</span>}- </span>- <span className="block text-[12px] leading-snug text-muted-foreground">{m.hint}</span>- </span>- <span className="mt-0.5 shrink-0 text-[11px] font-medium text-brand-text opacity-0 group-data-[selected=true]/move:opacity-100">Use</span>- </CommandItem>- );- })}- </CommandGroup>- </CommandList>+ <CoverScrollBox value={box}>+ <CommandList ref={box} className="max-h-[min(52vh,360px)]">+ <CommandEmpty>No camera moves match your search</CommandEmpty>+ <CommandGroup>+ {moves.map((m) => (+ <MoveRow+ key={m.slug}+ move={m}+ badge={badges ? routeBadge(m, engine, civitai) : null}+ order={selected.indexOf(m.slug)}+ highlighted={highlighted === m.name}+ onPick={() => onPick(m.slug)}+ />+ ))}+ </CommandGroup>+ </CommandList>+ </CoverScrollBox></Command>);}diff --git a/src/components/cover-tile.tsx b/src/components/cover-tile.tsxnew file mode 100644index 00000000..f0918b2a--- /dev/null+++ b/src/components/cover-tile.tsx@@ -0,0 +1,130 @@+"use client";++import { Check } from "lucide-react";+import { createContext, useContext, useEffect, useRef, useState, useSyncExternalStore } from "react";+import { PresetPreview } from "@/components/preset-preview";+import { createPickerPlayback } from "@/lib/picker-playback";+import type { PresetCover } from "@/lib/preset-covers";+import { browserPlaybackEnv } from "@/lib/preview-playback";+import { cn } from "@/lib/utils";++/** One picker tile plays at a time, across every picker (rules in lib/picker-playback.ts). */+const playback = createPickerPlayback(browserPlaybackEnv);++/**+ * Whether a picker's tile plays its clip, and the handlers to spread on it: hovered with a mouse or focused from the+ * keyboard, after a short rest; `highlighted`, a list's active row (where the device can hover: a list highlights its+ * first row by itself, which on a phone would play unasked); else, while none of those plays, `picked`.+ */+export function usePickerPlayback(id: string, { picked = false, highlighted = false } = {}) {+ const playing = useSyncExternalStore(+ playback.subscribe,+ () => playback.plays(id, picked),+ () => false,+ );+ useEffect(() => {+ if (!highlighted || !playback.canHover()) return;+ playback.play(id);+ return () => playback.stop(id);+ }, [id, highlighted]);+ useEffect(() => () => playback.stop(id), [id]);+ return {+ playing,+ handlers: {+ onPointerEnter: (e: React.PointerEvent) => e.pointerType === "mouse" && playback.play(id),+ onPointerLeave: (e: React.PointerEvent) => e.pointerType === "mouse" && playback.stop(id),+ // Keyboard focus only: a tap (or click) focuses the tile too.+ onFocus: (e: React.FocusEvent) => e.currentTarget.matches(":focus-visible") && playback.play(id),+ onBlur: () => playback.stop(id),+ },+ };+}++/**+ * The scroll box a picker's tiles sit in. Native lazy loading measures from the screen (over a thousand pixels+ * around it), so a small box of a hundred tiles would load most of their posters at once: a tile in a box waits+ * until it is within one box height of the part in view instead.+ */+const ScrollBox = createContext<React.RefObject<HTMLElement | null> | null>(null);+export const CoverScrollBox = ScrollBox.Provider;++/** One observer per scroll box, for all its tiles. */+const boxes = new WeakMap<Element, { io: IntersectionObserver; near: Map<Element, () => void> }>();++function whenNear(el: Element, box: Element, onNear: () => void): () => void {+ let b = boxes.get(box);+ if (!b) {+ const near = new Map<Element, () => void>();+ const io = new IntersectionObserver(+ (entries) => {+ for (const e of entries) if (e.isIntersecting) near.get(e.target)?.();+ },+ { root: box, rootMargin: "100% 0px" },+ );+ b = { io, near };+ boxes.set(box, b);+ }+ const { io, near } = b;+ near.set(el, onNear);+ io.observe(el);+ return () => {+ io.unobserve(el);+ near.delete(el);+ };+}++/**+ * A preset's picture in a picker (the camera motion and Mix grids, Cinema Studio's moves, the chips): its real+ * cover, the one its gallery card shows (presetCover), else `fallback`, the drawn tile. The poster loads lazily and+ * the clip goes over it only while `playing` (usePickerPlayback: hovered, keyboard-focused, highlighted or picked,+ * one at a time). `className` gives the box its size or aspect ratio, so nothing shifts while the poster loads. A+ * picked tile is marked on the picture: a check, or its place in an order.+ */+export function CoverTile({+ cover,+ playing = false,+ picked,+ fallback,+ className,+}: {+ cover: PresetCover | undefined;+ playing?: boolean;+ picked?: boolean | number;+ fallback?: React.ReactNode;+ className?: string;+}) {+ const ref = useRef<HTMLSpanElement>(null);+ const box = useContext(ScrollBox);+ // Differs on the server (no IntersectionObserver), which is fine: a picker mounts when it opens, never by hydration.+ const [near, setNear] = useState(() => !box || typeof IntersectionObserver === "undefined");+ const hasCover = !!cover;+ useEffect(() => {+ const el = ref.current;+ const root = box?.current;+ if (near || !hasCover || !el || !root) return;+ return whenNear(el, root, () => setNear(true));+ }, [near, hasCover, box]);+ return (+ <span ref={ref} className={cn("relative block shrink-0 overflow-hidden bg-muted", className)}>+ {cover+ ? near && (+ <>+ {/* eslint-disable-next-line @next/next/no-img-element */}+ <img src={cover.poster} alt="" draggable={false} loading="lazy" decoding="async" className="absolute inset-0 size-full object-cover" aria-hidden />+ {/* A cover is drawn as rendered: the scene is only for procedural previews. */}+ {cover.video && playing && <PresetPreview preview={{ ...cover, scene: "portrait" }} hue={0} playing />}+ </>+ )+ : fallback}+ {picked !== undefined && picked !== false && (+ <span+ data-picked=""+ aria-hidden+ className="absolute top-1 right-1 grid size-4 place-items-center rounded-full bg-primary text-[10px] font-semibold text-primary-foreground shadow-sm ring-1 ring-black/15"+ >+ {picked === true ? <Check className="size-3" strokeWidth={3} /> : picked}+ </span>+ )}+ </span>+ );+}diff --git a/src/components/studio/preset-chips.tsx b/src/components/studio/preset-chips.tsxindex c45b0420..b289eec8 100644--- a/src/components/studio/preset-chips.tsx+++ b/src/components/studio/preset-chips.tsx@@ -1,22 +1,49 @@"use client";import { Ban, Film, Loader2, Shuffle } from "lucide-react";-import { useState } from "react";+import { useRef, useState } from "react";import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";import { Slider } from "@/components/ui/slider";import type { Preset } from "@/lib/catalog/types";+import { presetCover } from "@/lib/preset-covers";import { cn } from "@/lib/utils";+import { CoverScrollBox, CoverTile, usePickerPlayback } from "@/components/cover-tile";import { PRESET_ICONS } from "@/components/preset-icons";import { loadFullCatalog, useCatalog } from "./catalog";import { Chip, ClearableChip } from "./chip";/**- * Camera-motion / effect picker and Mix. Loaded as its own chunk (with the preset icons), and- * the preset lists come from the full catalog chunk, fetched on first hover or open.+ * Camera-motion / effect picker and Mix. Loaded as its own chunk (with the preset icons and the slim+ * covers map), and the preset lists come from the full catalog chunk, fetched on first hover or open.+ * A preset shows its real cover, as in the galleries, else its drawn tile.*/-function PresetGrid({ list, value, onPick, noneLabel }: { list: Preset[] | null; value?: string; onPick: (id: string | undefined) => void; noneLabel: string }) {+const tileClass = "group flex flex-col items-start gap-1 overflow-hidden rounded-lg p-1 text-left ring-primary transition hover:bg-accent";++function PresetTile({ preset: p, picked, onPick }: { preset: Preset; picked: boolean; onPick: () => void }) {+ const { playing, handlers } = usePickerPlayback(p.id, { picked });+ const PI = PRESET_ICONS[p.look.icon] ?? Film;+ return (+ <button type="button" aria-pressed={picked} onClick={onPick} {...handlers} className={cn(tileClass, picked && "ring-2")}>+ <CoverTile+ cover={presetCover(p.id)}+ playing={playing}+ picked={picked}+ className="aspect-video w-full rounded-md"+ fallback={+ <span className="absolute inset-0 grid place-items-center text-white" style={{ background: `linear-gradient(135deg, ${p.look.from}, ${p.look.to})` }}>+ <PI className="size-5 transition-transform duration-300 group-hover:scale-125" />+ </span>+ }+ />+ <span className="w-full truncate px-0.5 text-[12px] font-medium">{p.name}</span>+ </button>+ );+}++export function PresetGrid({ list, value, onPick, noneLabel }: { list: Preset[] | null; value?: string; onPick: (id: string | undefined) => void; noneLabel: string }) {const [cat, setCat] = useState<string>("All");+ const box = useRef<HTMLDivElement>(null);if (!list)return (<div className="grid h-40 place-items-center" role="status" aria-label="Loading presets">@@ -39,35 +66,30 @@ function PresetGrid({ list, value, onPick, noneLabel }: { list: Preset[] | null;</button>))}</div>- <div className="grid max-h-72 grid-cols-3 gap-1.5 overflow-y-auto">- {cat === "All" && (- <button type="button" aria-pressed={!value} onClick={() => onPick(undefined)} className={cn("group flex flex-col items-start gap-1 overflow-hidden rounded-lg p-1 text-left ring-primary transition hover:bg-accent", !value && "ring-2")}>- <span className="grid aspect-video w-full place-items-center rounded-md bg-muted text-muted-foreground">- <Ban className="size-5" />- </span>- <span className="truncate px-0.5 text-[12px] font-medium">{noneLabel}</span>- </button>- )}- {list- .filter((p) => cat === "All" || p.category === cat)- .map((p) => {- const PI = PRESET_ICONS[p.look.icon] ?? Film;- return (- <button- key={p.id}- type="button"- aria-pressed={value === p.id}- onClick={() => onPick(p.id)}- className={cn("group flex flex-col items-start gap-1 overflow-hidden rounded-lg p-1 text-left ring-primary transition hover:bg-accent", value === p.id && "ring-2")}- >- <span className="grid aspect-video w-full place-items-center rounded-md text-white" style={{ background: `linear-gradient(135deg, ${p.look.from}, ${p.look.to})` }}>- <PI className="size-5 transition-transform duration-300 group-hover:scale-125" />- </span>- <span className="truncate px-0.5 text-[12px] font-medium">{p.name}</span>- </button>- );- })}- </div>+ <CoverScrollBox value={box}>+ <div ref={box} className="grid max-h-72 grid-cols-3 gap-1.5 overflow-y-auto">+ {cat === "All" && (+ <button type="button" aria-pressed={!value} onClick={() => onPick(undefined)} className={cn(tileClass, !value && "ring-2")}>+ <CoverTile+ cover={undefined}+ picked={!value}+ className="aspect-video w-full rounded-md"+ fallback={+ <span className="absolute inset-0 grid place-items-center text-muted-foreground">+ <Ban className="size-5" />+ </span>+ }+ />+ <span className="w-full truncate px-0.5 text-[12px] font-medium">{noneLabel}</span>+ </button>+ )}+ {list+ .filter((p) => cat === "All" || p.category === cat)+ .map((p) => (+ <PresetTile key={p.id} preset={p} picked={value === p.id} onPick={() => onPick(p.id)} />+ ))}+ </div>+ </CoverScrollBox></>);}@@ -79,7 +101,9 @@ export function PresetChip({ type, value, onChange }: { type: "motion" | "effectconst catalog = useCatalog();const list = catalog.presets?.[type] ?? null;const selected = value ? catalog.getPreset(value) : undefined;- const Icon = selected ? (PRESET_ICONS[selected.look.icon] ?? Film) : value && !catalog.complete ? Loader2 : Film;+ // The picked preset's poster in place of its icon, as the Look chip shows its look.+ const cover = selected && presetCover(selected.id);+ const Icon = cover ? undefined : selected ? (PRESET_ICONS[selected.look.icon] ?? Film) : value && !catalog.complete ? Loader2 : Film;const noun = type === "motion" ? "camera motion" : "effect";return (<ClearableChip active={!!value} onClear={() => onChange(undefined)} clearLabel={`Clear ${selected?.name ?? noun}`}>@@ -92,6 +116,7 @@ export function PresetChip({ type, value, onChange }: { type: "motion" | "effect><PopoverTrigger asChild><Chip icon={Icon} active={!!value} onPointerEnter={prefetch} onFocus={prefetch} className={cn(value && !selected && "[&>svg]:animate-spin")}>+ {cover && <CoverTile cover={cover} className="size-4 rounded-full" />}{selected?.name ?? (value ? "Loading…" : type === "motion" ? "Camera motion" : "Effect")}</Chip></PopoverTrigger>@@ -128,6 +153,7 @@ export function MixChip({const [open, setOpen] = useState(false);const catalog = useCatalog();const second = mix ? catalog.getPreset(mix.presetId) : undefined;+ const cover = second && presetCover(second.id);const mixable = catalog.presets ? [...catalog.presets.motion, ...catalog.presets.effect].filter((p) => p.id !== primary.id && !p.inputs.some((i) => i.key === "endImage")) : null;return (<ClearableChip active={!!mix} onClear={() => onChange({ mix: undefined })} clearLabel="Remove the mix">@@ -139,7 +165,8 @@ export function MixChip({}}><PopoverTrigger asChild>- <Chip icon={Shuffle} active={!!mix} onPointerEnter={prefetch} onFocus={prefetch}>+ <Chip icon={cover ? undefined : Shuffle} active={!!mix} onPointerEnter={prefetch} onFocus={prefetch}>+ {cover && <CoverTile cover={cover} className="size-4 rounded-full" />}{second ? `+ ${second.name}` : "Mix"}</Chip></PopoverTrigger>diff --git a/src/lib/picker-playback.ts b/src/lib/picker-playback.tsnew file mode 100644index 00000000..4a5b7cbf--- /dev/null+++ b/src/lib/picker-playback.ts@@ -0,0 +1,77 @@+/**+ * Which tile of a picker plays its clip (cover-tile.tsx: the camera motion and Mix grids, Cinema Studio's moves). One+ * at a time: the tile hovered or keyboard-focused, once it has had the pointer for a moment (HOVER_INTENT, as in the+ * galleries), or the row a list highlights; while there is none, the picked tile. Unlike a gallery, nothing plays for+ * being in view: a picker shows dozens of tiles at once.+ *+ * The picked tile plays unasked, so not with Save-Data or on 2G, and only once no other tile has played for+ * PICKED_RESUME (moving the pointer from tile to tile doesn't restart it each time). Nothing plays when the user+ * prefers reduced motion.+ *+ * Pure apart from the environment it's given, so the rules are testable without a browser.+ */+import { HOVER_INTENT, type PlaybackEnv } from "./preview-playback";++/** How long after the last hovered tile stops before the picked tile plays again, in ms. */+export const PICKED_RESUME = 400;++export function createPickerPlayback(env: Pick<PlaybackEnv, "matches" | "delay" | "saveData">) {+ const listeners = new Set<() => void>();+ /** The tile hovered, focused or highlighted. */+ let asked: string | null = null;+ /** No tile has played for a moment: the picked one may. */+ let resting = true;+ /** The tile a hover is about to play, and what calls that off. */+ let pending: { id: string; cancel: () => void } | null = null;+ let resume: (() => void) | null = null;++ const notify = () => listeners.forEach((l) => l());+ const reducedMotion = () => env.matches("(prefers-reduced-motion: reduce)");+ const cancelPending = () => {+ pending?.cancel();+ pending = null;+ };+ const cancelResume = () => {+ resume?.();+ resume = null;+ };++ return {+ subscribe(l: () => void) {+ listeners.add(l);+ return () => {+ listeners.delete(l);+ };+ },+ /** Whether `id` plays: the hovered, focused or highlighted tile, else the picked one (see above). */+ plays: (id: string, picked = false) => !reducedMotion() && (asked === id || (picked && asked === null && resting && !env.saveData())),+ canHover: () => env.matches("(hover: hover) and (pointer: fine)"),+ /** Hover, keyboard focus or highlight: play this one once it has had the pointer for HOVER_INTENT. */+ play(id: string) {+ cancelPending();+ cancelResume();+ if (reducedMotion()) return;+ const cancel = env.delay(() => {+ pending = null;+ asked = id;+ resting = false;+ notify();+ }, HOVER_INTENT);+ pending = { id, cancel };+ },+ /** Stop this one, if it's the one playing (or about to); the picked tile plays again after PICKED_RESUME. */+ stop(id: string) {+ if (pending?.id === id) cancelPending();+ if (asked === id) {+ asked = null;+ notify();+ }+ if (asked === null && !pending && !resting && !resume)+ resume = env.delay(() => {+ resume = null;+ resting = true;+ notify();+ }, PICKED_RESUME);+ },+ };+}diff --git a/src/lib/preset-covers.generated.ts b/src/lib/preset-covers.generated.tsnew file mode 100644index 00000000..f948e1ea--- /dev/null+++ b/src/lib/preset-covers.generated.ts@@ -0,0 +1,493 @@+/**+ * Which presets have a real cover, for the pickers in the browser (read through presetCover, preset-covers.ts):+ * 1 for a clip at /previews/presets/<id>.mp4 with its poster at <id>.jpg, 0 for a still there, or the files of a+ * cover kept elsewhere. The slim side of preset-previews.generated.ts, whose provenance stays on the server.+ * Generated with it by pnpm eval:covers: run it again rather than editing.+ */+export type PresetCoverEntry = 0 | 1 | { poster: string; video?: string };++export const PRESET_COVERS: Record<string, PresetCoverEntry> = {+ "app-3d-figure": 0,+ "app-3d-render": 0,+ "app-3d-rotation": 0,+ "app-60s-cafe": 0,+ "app-ad-creative": 0,+ "app-age-shift": 1,+ "app-ai-influencer": 0,+ "app-ai-stylist": 1,+ "app-angles": 1,+ "app-asmr-add-on": 0,+ "app-asmr-classic": 0,+ "app-asmr-host": 0,+ "app-asmr-promo": 0,+ "app-banana-eating": 0,+ "app-behind-the-scenes": 1,+ "app-billboard-ad": 0,+ "app-breakdown": 1,+ "app-brick-cube": 0,+ "app-bring-to-life": 0,+ "app-bullet-time-scene": 0,+ "app-bullet-time-splash": 0,+ "app-bullet-time-white": 0,+ "app-burning-sunset": 0,+ "app-chameleon": 0,+ "app-change-background": 1,+ "app-character-swap": 1,+ "app-click-to-ad": 1,+ "app-clipcut": 0,+ "app-cloud-surf": 0,+ "app-color-grading": 1,+ "app-colorize": 1,+ "app-comic-book": 0,+ "app-commercial-faces": 1,+ "app-dance": 0,+ "app-expand-image": 0,+ "app-expression-edit": 0,+ "app-face-swap": 1,+ "app-figurine": 0,+ "app-fridge-ad": 0,+ "app-game-dump": 1,+ "app-ghoulgao": 0,+ "app-giallo-horror": 0,+ "app-giant-product": 0,+ "app-glitter-sticker": 1,+ "app-graffiti-ad": 0,+ "app-gtai": 0,+ "app-hairstyle-try-on": 1,+ "app-headshot-generator": 1,+ "app-hook-frame": 1,+ "app-hug": 0,+ "app-idol": 0,+ "app-image-to-3d": 0,+ "app-j-magazine": 0,+ "app-j-poster": 0,+ "app-japanese-show": 1,+ "app-kick-ad": 0,+ "app-latex": 0,+ "app-link-to-video-ad": 0,+ "app-macro-scene": 0,+ "app-macroshot-product": 0,+ "app-magic-button": 0,+ "app-makeup-studio": 1,+ "app-mascot": 0,+ "app-match-colors": 1,+ "app-match-lighting": 1,+ "app-melting-doodle": 0,+ "app-meme-generator": 1,+ "app-micro-beasts": 1,+ "app-mugshot": 0,+ "app-mukbang": 0,+ "app-nano-strike": 0,+ "app-nano-theft": 0,+ "app-object-remover": 1,+ "app-outfit-shot": 1,+ "app-outfit-swap": 1,+ "app-outfit-vending": 1,+ "app-packshot": 1,+ "app-paint-app": 1,+ "app-pixel-game": 0,+ "app-plushies": 1,+ "app-poster": 0,+ "app-product-360": 0,+ "app-product-placement": 1,+ "app-product-shot": 1,+ "app-rap-god": 0,+ "app-recast": 0,+ "app-relight": 1,+ "app-remove-background": 1,+ "app-renaissance": 0,+ "app-restore-photo": 1,+ "app-roller-coaster": 0,+ "app-sand-worm": 0,+ "app-shots": 1,+ "app-signboard": 0,+ "app-similarity-score": 1,+ "app-simlife": 0,+ "app-sketch-to-real": 1,+ "app-skibidi": 0,+ "app-skin-enhancer": 1,+ "app-social-media-icon": 0,+ "app-steal-the-look": 1,+ "app-sticker-match-cut": 0,+ "app-sticker-pack": 1,+ "app-storm-creature": 0,+ "app-style-snap": 1,+ "app-style-transfer": 1,+ "app-text-edit": 1,+ "app-this-is-fine": 0,+ "app-transitions": 0,+ "app-truck-ad": 0,+ "app-unboxing-video": 0,+ "app-upscale": 1,+ "app-urban-cuts": 0,+ "app-vectorize": 1,+ "app-victory-card": 0,+ "app-video-background-remover": 0,+ "app-video-face-swap": 0,+ "app-virtual-try-on": 1,+ "app-volcano-ad": 0,+ "app-what-s-next": 0,+ "app-yes-kiss": 0,+ "app-zoom-out": 0,+ "app-zooms": 1,+ "effect-acid": 0,+ "effect-act-natural": 0,+ "effect-agamemnon": 0,+ "effect-agent-reveal": 0,+ "effect-air-bending": 0,+ "effect-akrill": 0,+ "effect-angel-wings": 0,+ "effect-angry-mode": 0,+ "effect-animalization": 0,+ "effect-aquarium": 0,+ "effect-architecture-wave": 0,+ "effect-atomic": 0,+ "effect-attack-of-clones": 0,+ "effect-ballet": 0,+ "effect-balloon": 0,+ "effect-beach-ride": 0,+ "effect-beast-appearance": 0,+ "effect-black-gloss": 0,+ "effect-black-tears": 0,+ "effect-bleach-bypass": 0,+ "effect-bleached-warm": 0,+ "effect-bloom-mouth": 0,+ "effect-blue-depth": 0,+ "effect-boarding-pass": 0,+ "effect-boiling-point": 0,+ "effect-broken-mirror": 0,+ "effect-bubbles": 0,+ "effect-buddy": 0,+ "effect-building-explosion": 1,+ "effect-burning-man": 0,+ "effect-cakeify": 0,+ "effect-candy-pink": 0,+ "effect-cannabis": 0,+ "effect-canvas": 0,+ "effect-car-drive": 0,+ "effect-car-explosion": 1,+ "effect-censorship": 0,+ "effect-classic-bw": 0,+ "effect-clone-explosion": 0,+ "effect-clones": 0,+ "effect-clothes-rain": 0,+ "effect-cold-steel": 0,+ "effect-cold-vision": 0,+ "effect-color-rain": 0,+ "effect-column-wipe": 0,+ "effect-comic": 0,+ "effect-contre-jour": 0,+ "effect-cotton-cloud": 0,+ "effect-crimson-vigil": 0,+ "effect-crush": 0,+ "effect-crying": 0,+ "effect-cutout": 0,+ "effect-cyborg": 0,+ "effect-cyclope": 0,+ "effect-datamosh": 0,+ "effect-deflate": 0,+ "effect-diamond": 0,+ "effect-dirty-lens": 0,+ "effect-disintegration": 0,+ "effect-display-transition": 0,+ "effect-dolphin-ride": 0,+ "effect-dream-date": 0,+ "effect-drunk-master": 0,+ "effect-duplicate": 0,+ "effect-earth-element": 1,+ "effect-earth-wave": 1,+ "effect-earth-zoom-out": 0,+ "effect-eating": 0,+ "effect-exploded-view": 0,+ "effect-explosion": 0,+ "effect-fairies-around": 0,+ "effect-fairytale-castle": 0,+ "effect-fallen-angel": 0,+ "effect-film-colors": 0,+ "effect-fire-breath": 0,+ "effect-fire-element": 1,+ "effect-firelava": 1,+ "effect-firework": 0,+ "effect-fix-and-pose": 0,+ "effect-flame-on": 1,+ "effect-flame-transition": 0,+ "effect-flash-comic": 0,+ "effect-flashback": 0,+ "effect-floating-fall": 0,+ "effect-floating-fish": 0,+ "effect-flood": 0,+ "effect-floral-eyes": 0,+ "effect-fragments": 0,+ "effect-freezing": 1,+ "effect-frozen-in-motion": 0,+ "effect-garden-bloom": 0,+ "effect-gas-transformation": 0,+ "effect-giant": 0,+ "effect-giant-grab": 0,+ "effect-giant-people": 0,+ "effect-glitch": 0,+ "effect-glow-trace": 0,+ "effect-glowing-fish": 0,+ "effect-glowshift": 0,+ "effect-gorilla-transfer": 0,+ "effect-group-photo": 0,+ "effect-hair-style": 0,+ "effect-hand-paint": 0,+ "effect-hand-transition": 0,+ "effect-handheld-run": 0,+ "effect-happy": 0,+ "effect-happy-mode": 0,+ "effect-head-explosion": 1,+ "effect-head-off": 1,+ "effect-helicopter-escape": 0,+ "effect-hero-flight": 0,+ "effect-high-flip": 0,+ "effect-hole-transition": 0,+ "effect-horror-face": 0,+ "effect-hyper-neon": 0,+ "effect-i-can-fly": 0,+ "effect-ice-rose": 0,+ "effect-infinite-clones": 0,+ "effect-inflate": 0,+ "effect-innerlight": 0,+ "effect-invisible": 0,+ "effect-jelly-drift": 0,+ "effect-jump-transition": 0,+ "effect-lacewalker": 0,+ "effect-lava": 0,+ "effect-layer-mixed-media": 0,+ "effect-lens-crack": 1,+ "effect-lens-flare": 0,+ "effect-levitation": 1,+ "effect-lidar-transition": 0,+ "effect-lime-jam": 0,+ "effect-live-concert": 0,+ "effect-look-boom": 0,+ "effect-lsd": 0,+ "effect-luminous-gaze": 0,+ "effect-magazine": 0,+ "effect-marble": 0,+ "effect-medusa-gorgona": 0,+ "effect-melt-transition": 0,+ "effect-melting": 0,+ "effect-mighty-fighter": 0,+ "effect-modern": 0,+ "effect-monet-muse": 0,+ "effect-money-rain": 0,+ "effect-monster-dab": 0,+ "effect-monstrosity": 0,+ "effect-moonwalk": 0,+ "effect-morning-routine": 0,+ "effect-morphskin": 0,+ "effect-motor-ride": 0,+ "effect-multiverse": 0,+ "effect-muscle-up": 0,+ "effect-mystification": 0,+ "effect-naturalistic-clean": 0,+ "effect-nature-bloom": 0,+ "effect-noir": 0,+ "effect-northern-lights": 0,+ "effect-nostalgic-blue": 0,+ "effect-objects-around": 0,+ "effect-ocean": 0,+ "effect-oni-mask": 0,+ "effect-origami": 0,+ "effect-outfit-check": 0,+ "effect-outfit-switch": 0,+ "effect-overexposed": 0,+ "effect-overhead-fall": 0,+ "effect-overtime": 0,+ "effect-paint-splash": 0,+ "effect-palette": 0,+ "effect-paparazzi": 0,+ "effect-paper": 0,+ "effect-particles": 0,+ "effect-peak-moment": 0,+ "effect-pearl-earring": 0,+ "effect-pigeons": 0,+ "effect-pixelated-face": 0,+ "effect-pizza-fall": 0,+ "effect-plasma-explosion": 0,+ "effect-plate-check": 0,+ "effect-point-cloud": 0,+ "effect-polygon": 0,+ "effect-pool-jump": 0,+ "effect-portal": 0,+ "effect-powder-explosion": 1,+ "effect-practicals": 0,+ "effect-push-to-glass": 0,+ "effect-random-glow": 0,+ "effect-raven-transition": 0,+ "effect-red-carpet": 0,+ "effect-saint-glow": 0,+ "effect-sakura-petals": 0,+ "effect-sand-cut": 0,+ "effect-sand-storm": 1,+ "effect-scrapbook-collage": 0,+ "effect-seamless-transition": 0,+ "effect-selfception": 0,+ "effect-selfie": 0,+ "effect-selfie-outfit": 0,+ "effect-selfie-posing": 0,+ "effect-set-on-fire": 1,+ "effect-shadow-smoke": 0,+ "effect-shocked": 0,+ "effect-silhouette": 0,+ "effect-skatedog": 0,+ "effect-sketch": 0,+ "effect-skin-surge": 0,+ "effect-smash-and-grab": 0,+ "effect-smoke-transition": 0,+ "effect-sodium-decay": 0,+ "effect-soft-cross": 0,+ "effect-soft-palette": 0,+ "effect-soul-jump": 0,+ "effect-spiders-from-mouth": 0,+ "effect-spirit-animal": 0,+ "effect-splash-transition": 0,+ "effect-squish": 0,+ "effect-starship-troopers": 0,+ "effect-static-posing": 0,+ "effect-stop-world": 0,+ "effect-street-colossus": 0,+ "effect-studio-slide": 0,+ "effect-sunglasses": 0,+ "effect-super-fast-run": 0,+ "effect-super-saiyan": 0,+ "effect-superstar": 0,+ "effect-tattoo-animation": 0,+ "effect-teal-orange-epic": 0,+ "effect-tentacles": 0,+ "effect-thunder-god": 1,+ "effect-tiny-planet": 0,+ "effect-toxic": 0,+ "effect-tracking": 0,+ "effect-train-rush": 0,+ "effect-trucksition": 0,+ "effect-turn-into-statue": 0,+ "effect-turning-metal": 1,+ "effect-turning-monkey": 0,+ "effect-two-color": 0,+ "effect-ultraviolet": 0,+ "effect-vanish": 0,+ "effect-vintage": 0,+ "effect-visor-x": 0,+ "effect-water-bending": 1,+ "effect-water-element": 1,+ "effect-water-splash": 0,+ "effect-werewolf": 0,+ "effect-wild-ride": 0,+ "effect-wind-to-face": 1,+ "effect-window": 0,+ "effect-windows": 0,+ "effect-wireframe": 0,+ "effect-wonderland": 0,+ "effect-world-morphing": 0,+ "effect-x-ray": 0,+ "effect-yacht": 0,+ "motion-360-orbit": 1,+ "motion-action-run": 1,+ "motion-aerial-pullback": 0,+ "motion-arc-left": 1,+ "motion-arc-right": 1,+ "motion-baseball-kick": 1,+ "motion-basketball-dunks": 1,+ "motion-boxing": 1,+ "motion-bts": 1,+ "motion-bullet-time": 1,+ "motion-car-chasing": 1,+ "motion-car-grip": 1,+ "motion-catwalk": 1,+ "motion-classic-static": 1,+ "motion-crane-down": 1,+ "motion-crane-over-the-head": 1,+ "motion-crane-up": 1,+ "motion-crash-zoom-in": 1,+ "motion-crash-zoom-out": 1,+ "motion-documentary-snap": 1,+ "motion-dolly-in": 1,+ "motion-dolly-left": 1,+ "motion-dolly-out": 1,+ "motion-dolly-right": 1,+ "motion-dolly-zoom-in": 1,+ "motion-double-dolly": 1,+ "motion-downhill-pov": 0,+ "motion-dreamy-flow": 1,+ "motion-drone-reveal": 0,+ "motion-dutch-angle": 1,+ "motion-earth-zoom-out": 0,+ "motion-eating-zoom": 1,+ "motion-epic-scale": 1,+ "motion-eyes-in": 1,+ "motion-face-punch": 1,+ "motion-fisheye": 0,+ "motion-flying": 1,+ "motion-flying-cam-transition": 0,+ "motion-focus-change": 1,+ "motion-fpv-drone": 1,+ "motion-general": 1,+ "motion-glam": 1,+ "motion-handheld": 1,+ "motion-head-tracking": 1,+ "motion-helicopter-shot": 1,+ "motion-hero-cam": 1,+ "motion-hyperlapse": 1,+ "motion-impossible-camera": 1,+ "motion-incline": 1,+ "motion-intimate-observer": 1,+ "motion-jib-down": 1,+ "motion-jib-up": 1,+ "motion-kiss": 1,+ "motion-lazy-orbit": 1,+ "motion-lazy-susan": 1,+ "motion-low-shutter": 1,+ "motion-moonwalk-left": 1,+ "motion-moonwalk-right": 0,+ "motion-mouth-in": 1,+ "motion-object-pov": 1,+ "motion-one-take": 1,+ "motion-overhead": 1,+ "motion-pan": 1,+ "motion-pan-left": 1,+ "motion-pan-right": 1,+ "motion-pedestal-down": 1,+ "motion-pov": 1,+ "motion-rap-flex": 1,+ "motion-rapid-zoom-in": 1,+ "motion-rapid-zoom-out": 1,+ "motion-raw-chaos": 0,+ "motion-road-rush": 0,+ "motion-robo-arm": 0,+ "motion-robot-arm": 0,+ "motion-roll-transition": 0,+ "motion-silent-machine": 1,+ "motion-skate-cruise": 1,+ "motion-skateboard-glide": 1,+ "motion-skateboard-ollie": 1,+ "motion-ski-carving": 1,+ "motion-ski-powder": 1,+ "motion-slow-motion": 1,+ "motion-snorricam": 0,+ "motion-snowboard-carving": 1,+ "motion-snowboard-powder": 1,+ "motion-static": 1,+ "motion-super-dolly-in": 1,+ "motion-super-dolly-out": 1,+ "motion-through-object-in": 1,+ "motion-through-object-out": 1,+ "motion-tilt-down": 1,+ "motion-tilt-up": 1,+ "motion-timelapse": 1,+ "motion-timelapse-glam": 1,+ "motion-timelapse-human": 1,+ "motion-timelapse-landscape": 1,+ "motion-tracking": 0,+ "motion-truck-left": 1,+ "motion-truck-right": 1,+ "motion-whip-pan": 0,+ "motion-wiggle": 1,+ "motion-yoyo-zoom": 1,+ "motion-zoom": 1,+ "motion-zoom-in": 1,+ "motion-zoom-out": 1+};diff --git a/src/lib/preset-covers.ts b/src/lib/preset-covers.tsnew file mode 100644index 00000000..0b45b898--- /dev/null+++ b/src/lib/preset-covers.ts@@ -0,0 +1,32 @@+/**+ * A preset's real cover for the pickers (camera motions, effects, Mix, Cinema Studio's moves): the same still and+ * clip its gallery card shows. Reads the slim covers map (preset-covers.generated.ts: which presets have a cover,+ * and a clip), never the manifest with its provenance (preset-previews.generated.ts), so client code can import it.+ * Keep it to the pickers' own chunks all the same: tests/preset-covers.test.ts checks the importers.+ */+import type { CameraMove } from "./catalog/cinema";+import { PRESET_COVERS } from "./preset-covers.generated";++export interface PresetCover {+ /** The still (a clip's first frame), shown at rest. */+ poster: string;+ /** The short muted clip, played only while the tile is hovered, focused or picked. */+ video?: string;+}++export function presetCover(id: string | undefined): PresetCover | undefined {+ if (!id || !Object.hasOwn(PRESET_COVERS, id)) return undefined;+ const c = PRESET_COVERS[id];+ if (typeof c === "object") return c;+ const base = `/previews/presets/${id}`;+ return c ? { poster: `${base}.jpg`, video: `${base}.mp4` } : { poster: `${base}.jpg` };+}++/**+ * Moves whose camera motion shows another shot than the name says: Drone Orbit runs 360 Orbit, whose clip circles+ * a dancer at ground level, not from the air.+ */+const OTHER_SHOT = new Set(["drone-orbit"]);++/** A Cinema Studio move's cover: the one of the camera motion it runs (catalog/cinema.ts, MOVE_MOTION). */+export const moveCover = (m: Pick<CameraMove, "slug" | "motionId">) => (OTHER_SHOT.has(m.slug) ? undefined : presetCover(m.motionId));diff --git a/tests/covers-from-masters.test.ts b/tests/covers-from-masters.test.tsindex ae7d5d25..12134748 100644--- a/tests/covers-from-masters.test.ts+++ b/tests/covers-from-masters.test.ts@@ -131,6 +131,24 @@ describe("covers from masters", () => {expect(() => coversFromMasters(masters, { ...PROVENANCE, dryRun: true, manifest: broken })).toThrow(/isn't a covers manifest/);});+ it("writes the slim covers map the pickers read next to the manifest: 1 for a clip, 0 for a still, files kept elsewhere in full", () => {+ const manifest = path.join(dir, "slim", "manifest.ts");+ const elsewhere = { poster: "/previews/dop/effect-thunder-god.jpg", video: "/previews/dop/effect-thunder-god.mp4", run: "r1", engine: "open", model: "m", variant: "v" };+ writeManifest(+ {+ "motion-zoom-in": { poster: "/previews/presets/motion-zoom-in.jpg", video: "/previews/presets/motion-zoom-in.mp4", run: "r", engine: "comfyui", model: "m", variant: "v" },+ "effect-thunder-god": elsewhere,+ "app-headshot-generator": { poster: "/previews/presets/app-headshot-generator.jpg", run: "r", engine: "comfyui", model: "m", variant: "v" },+ },+ manifest,+ );+ const text = fs.readFileSync(path.join(dir, "slim", "preset-covers.generated.ts"), "utf8");+ expect(text).not.toMatch(/"run"|"engine"|"model"|"variant"/);+ const slim = JSON.parse(text.slice(text.indexOf("=", text.indexOf("export const PRESET_COVERS")) + 1).trim().replace(/;\s*$/, ""));+ expect(slim).toEqual({ "app-headshot-generator": 0, "effect-thunder-god": { poster: elsewhere.poster, video: elsewhere.video }, "motion-zoom-in": 1 });+ expect(Object.keys(slim)).toEqual(["app-headshot-generator", "effect-thunder-god", "motion-zoom-in"]);+ });+it("makes a clip loop without a jump: its last frames fade into its first, which it then starts after (unless it loops already)", () => {const frames = Array.from({ length: 20 }, (_, i) => Buffer.from([i * 10, i * 10]));const out = seamless(frames, 4);diff --git a/tests/picker-covers.test.ts b/tests/picker-covers.test.tsnew file mode 100644index 00000000..16047b8c--- /dev/null+++ b/tests/picker-covers.test.ts@@ -0,0 +1,255 @@+import { createElement } from "react";+import { renderToStaticMarkup } from "react-dom/server";+import { describe, expect, it } from "vitest";+import { MoveList } from "@/components/cinema/camera-moves";+import { CoverTile } from "@/components/cover-tile";+import { PresetGrid } from "@/components/studio/preset-chips";+import { TooltipProvider } from "@/components/ui/tooltip";+import { EFFECTS, MOTIONS } from "@/lib/catalog";+import { CAMERA_MOVES } from "@/lib/catalog/cinema";+import type { Preset } from "@/lib/catalog/types";+import { createPickerPlayback, PICKED_RESUME } from "@/lib/picker-playback";+import { moveCover, presetCover } from "@/lib/preset-covers";+import { PRESET_PREVIEWS } from "@/lib/preset-previews.generated";+import { HOVER_INTENT } from "@/lib/preview-playback";++/*+ * The pickers show the same real covers as the galleries (the camera motion and Mix grids, Cinema Studio's moves),+ * rendered on the server as they first paint: posters only, every clip waits for a hover, focus or pick.+ */++const grid = (list: Preset[], value?: string) => renderToStaticMarkup(createElement(PresetGrid, { list, value, noneLabel: "None", onPick: () => {} }));+/** The grid's tiles (not its category tabs), each as its markup. */+const tiles = (html: string) =>+ html+ .split("<button")+ .slice(1)+ .filter((b) => !b.includes('role="tab"'));+const covered = (list: Preset[]) => list.filter((p) => PRESET_PREVIEWS[p.id]);+const count = (html: string, s: string) => html.split(s).length - 1;+const mixable = [...MOTIONS, ...EFFECTS].filter((p) => !p.inputs.some((i) => i.key === "endImage"));++describe("the camera motion picker", () => {+ const html = grid(MOTIONS);+ const all = tiles(html);+ const tile = (p: Preset) => all.find((t) => t.includes(`>${p.name.replaceAll("&", "&").replaceAll("'", "'")}</span>`))!;++ it("shows every motion's cover where it has one, as a lazy poster; the others and None keep their drawn tile", () => {+ expect(all).toHaveLength(MOTIONS.length + 1);+ for (const p of MOTIONS) {+ const t = tile(p);+ expect(t, p.id).toBeDefined();+ const cover = PRESET_PREVIEWS[p.id];+ if (cover) {+ expect(t, p.id).toContain(`src="${cover.poster}"`);+ expect(t, p.id).toMatch(/<img[^>]*loading="lazy"[^>]*decoding="async"/);+ expect(t, p.id).not.toContain("linear-gradient");+ } else {+ expect(t, p.id).toContain("linear-gradient");+ expect(t, p.id).not.toContain("<img");+ }+ }+ const none = all[0];+ expect(none).toContain(">None</span>");+ expect(none).not.toContain("<img");+ expect(none).toContain('aria-pressed="true"');+ expect(count(html, "<img")).toBe(covered(MOTIONS).length);+ expect(covered(MOTIONS).length).toBeGreaterThan(MOTIONS.length * 0.9);+ });++ it("never borrows another move's cover: Dolly Zoom Out isn't shown with Dolly Zoom In's opposite move", () => {+ const out = MOTIONS.find((p) => p.id === "motion-dolly-zoom-out")!;+ expect(tile(out)).not.toContain("motion-dolly-zoom-in");+ });++ it("loads no clip until one is hovered, focused or picked", () => {+ expect(html).not.toContain("<video");+ expect(html).not.toContain(".mp4");+ });++ it("marks the picked motion on its picture, and only that one", () => {+ const picked = covered(MOTIONS).find((p) => PRESET_PREVIEWS[p.id].video)!;+ const html = grid(MOTIONS, picked.id);+ const marked = tiles(html).filter((t) => t.includes('aria-pressed="true"'));+ expect(marked).toHaveLength(1);+ expect(marked[0]).toContain(`src="${PRESET_PREVIEWS[picked.id].poster}"`);+ expect(marked[0]).toContain('data-picked=""');+ expect(count(html, "data-picked")).toBe(1);+ });+});++describe("the Mix picker", () => {+ it("shows the cover of every motion and effect that has one, posters only", () => {+ const html = grid(mixable);+ for (const p of covered(mixable)) expect(html, p.id).toContain(`src="${PRESET_PREVIEWS[p.id].poster}"`);+ expect(count(html, "<img")).toBe(covered(mixable).length);+ expect(count(html, "linear-gradient")).toBe(mixable.length - covered(mixable).length);+ expect(html).not.toContain("<video");+ });+});++describe("the cover tile", () => {+ const clip = { poster: "/previews/presets/motion-zoom-in.jpg", video: "/previews/presets/motion-zoom-in.mp4" };+ const tile = (props: Partial<React.ComponentProps<typeof CoverTile>>) =>+ renderToStaticMarkup(createElement(CoverTile, { cover: clip, playing: false, className: "aspect-video", ...props }));++ it("shows the poster at rest, lazily, filling its box without shifting anything", () => {+ const html = tile({});+ expect(html).toMatch(/<span class="[^"]*relative[^"]*aspect-video[^"]*"/);+ expect(html).toMatch(/<img [^>]*src="\/previews\/presets\/motion-zoom-in\.jpg"/);+ expect(html).toMatch(/loading="lazy"/);+ expect(html).toMatch(/class="absolute inset-0 size-full object-cover"/);+ expect(html).not.toContain("<video");+ });++ it("adds the clip only while it plays, and never for a cover that is a still", () => {+ expect(tile({ playing: true })).toMatch(/<video [^>]*src="\/previews\/presets\/motion-zoom-in\.mp4"/);+ expect(tile({ playing: true, cover: { poster: clip.poster } })).not.toContain("<video");+ });++ it("draws the fallback when there is no cover", () => {+ const html = tile({ cover: undefined, fallback: createElement("i", { className: "drawn" }), playing: true });+ expect(html).toContain('<i class="drawn"></i>');+ expect(html).not.toContain("<img");+ expect(html).not.toContain("<video");+ });++ it("marks a picked tile with a check, or with its place in an order", () => {+ expect(tile({})).not.toContain("data-picked");+ expect(tile({ picked: true })).toMatch(/data-picked=""[^>]*>.*<svg/);+ expect(tile({ picked: 2 })).toMatch(/data-picked=""[^>]*>2</);+ });+});++describe("Cinema Studio's camera moves", () => {+ it("show the cover of the camera motion each move runs, but Drone Orbit's ground-level orbit isn't a drone shot", () => {+ for (const m of CAMERA_MOVES) {+ if (m.slug === "drone-orbit") expect(moveCover(m), m.slug).toBeUndefined();+ else expect(moveCover(m), m.slug).toEqual(presetCover(m.motionId));+ }+ // Pedestal Up rises like Jib Up, whose clip it shows.+ expect(moveCover(CAMERA_MOVES.find((m) => m.slug === "pedestal-up")!)?.poster).toBe("/previews/presets/motion-jib-up.jpg");+ expect(CAMERA_MOVES.filter((m) => moveCover(m)).length).toBeGreaterThan(30);+ });++ it("list them with their poster, and the order number on it once picked", () => {+ const html = renderToStaticMarkup(createElement(TooltipProvider, null, createElement(MoveList, { engine: "open", selected: ["dolly-in"], onPick: () => {} })));+ const rows = html.split('cmdk-item=""').slice(1);+ expect(rows).toHaveLength(CAMERA_MOVES.length);+ for (const m of CAMERA_MOVES) {+ const row = rows.find((r) => r.includes(`>${m.name}<`))!;+ const cover = moveCover(m);+ if (cover) expect(row, m.slug).toContain(`src="${cover.poster}"`);+ else expect(row, m.slug).not.toContain("<img");+ }+ expect(html).not.toContain("<video");+ expect(rows.find((r) => r.includes(">Dolly In<"))).toMatch(/data-picked=""[^>]*>1</);+ });+});++/** The browser as the picker's playback sees it, with a clock that only moves when told. */+function fakeEnv({ reduced = false, saveData = false, hover = true } = {}) {+ let now = 0;+ const timers = new Set<{ at: number; cb: () => void }>();+ const next = () => [...timers].sort((a, b) => a.at - b.at)[0];+ const advance = (ms: number) => {+ const end = now + ms;+ for (let due = next(); due && due.at <= end; due = next()) {+ timers.delete(due);+ now = due.at;+ due.cb();+ }+ now = end;+ };+ const env = {+ matches: (q: string) => (q.includes("reduced-motion") ? reduced : q.includes("hover") ? hover : false),+ delay: (cb: () => void, ms: number) => {+ const t = { at: now + ms, cb };+ timers.add(t);+ return () => void timers.delete(t);+ },+ saveData: () => saveData,+ };+ return { env, advance };+}++describe("which picker tile plays", () => {+ it("plays the picked tile when the picker opens, and the hovered one instead once the pointer rests on it", () => {+ const { env, advance } = fakeEnv();+ const p = createPickerPlayback(env);+ expect(p.plays("picked", true)).toBe(true);+ expect(p.plays("other")).toBe(false);+ p.play("other");+ advance(HOVER_INTENT - 1);+ expect([p.plays("picked", true), p.plays("other")]).toEqual([true, false]);+ advance(1);+ expect([p.plays("picked", true), p.plays("other")]).toEqual([false, true]);+ });++ it("doesn't restart the picked tile while the pointer moves from tile to tile, only once it has left them", () => {+ const { env, advance } = fakeEnv();+ const p = createPickerPlayback(env);+ p.play("a");+ advance(HOVER_INTENT);+ p.stop("a");+ expect(p.plays("picked", true)).toBe(false);+ advance(PICKED_RESUME / 2);+ p.play("b");+ advance(HOVER_INTENT);+ expect([p.plays("picked", true), p.plays("a"), p.plays("b")]).toEqual([false, false, true]);+ // Passing over a tile without resting on it doesn't play it, and doesn't hold the picked one off for good.+ p.stop("b");+ p.play("c");+ p.stop("c");+ advance(PICKED_RESUME - 1);+ expect([p.plays("picked", true), p.plays("c")]).toEqual([false, false]);+ advance(1);+ expect(p.plays("picked", true)).toBe(true);+ });++ it("keeps the picked tile playing while the pointer rests on it", () => {+ const { env, advance } = fakeEnv();+ const p = createPickerPlayback(env);+ p.play("picked");+ advance(HOVER_INTENT);+ expect(p.plays("picked", true)).toBe(true);+ p.stop("picked");+ advance(PICKED_RESUME);+ expect(p.plays("picked", true)).toBe(true);+ });++ it("plays one tile at a time, the last one asked for", () => {+ const { env, advance } = fakeEnv();+ const p = createPickerPlayback(env);+ p.play("a");+ advance(HOVER_INTENT);+ p.play("b");+ advance(HOVER_INTENT);+ expect([p.plays("a"), p.plays("b")]).toEqual([false, true]);+ p.stop("a");+ expect(p.plays("b")).toBe(true);+ });++ it("keeps the picked tile on its poster with Save-Data or on 2G (it plays unasked), but plays a hovered one", () => {+ const { env, advance } = fakeEnv({ saveData: true });+ const p = createPickerPlayback(env);+ expect(p.plays("picked", true)).toBe(false);+ p.play("other");+ advance(HOVER_INTENT);+ expect(p.plays("other")).toBe(true);+ });++ it("plays nothing when the user prefers reduced motion", () => {+ const { env, advance } = fakeEnv({ reduced: true });+ const p = createPickerPlayback(env);+ expect(p.plays("picked", true)).toBe(false);+ p.play("other");+ advance(HOVER_INTENT);+ expect(p.plays("other")).toBe(false);+ });++ it("tells a device that can hover from a phone (a list's highlighted row plays only where it can)", () => {+ expect(createPickerPlayback(fakeEnv().env).canHover()).toBe(true);+ expect(createPickerPlayback(fakeEnv({ hover: false }).env).canHover()).toBe(false);+ });+});diff --git a/tests/preset-covers.test.ts b/tests/preset-covers.test.tsindex 6916633d..68df2ac2 100644--- a/tests/preset-covers.test.ts+++ b/tests/preset-covers.test.ts@@ -6,6 +6,8 @@ import { APPS, EFFECTS, MOTIONS } from "@/lib/catalog";import { SOUL_LOOK_CARDS } from "@/lib/catalog/soul-looks.generated";import { toPresetCard } from "@/lib/preset-card-data";import { isCover } from "@/lib/preset-cards";+import { presetCover } from "@/lib/preset-covers";+import { PRESET_COVERS } from "@/lib/preset-covers.generated";import { PRESET_PREVIEWS } from "@/lib/preset-previews.generated";/*@@ -57,6 +59,14 @@ describe("the preset covers manifest", () => {expect(JSON.stringify(EFFECTS.map(toPresetCard)).length).toBeLessThan(100_000);});+ it("gives the pickers every cover through the slim map, with the same files, and nothing else", () => {+ // Written with the manifest by pnpm eval:covers (scripts/eval/lib/covers.mjs): a manifest changed without it fails here.+ expect(Object.keys(PRESET_COVERS)).toEqual(entries.map(([k]) => k));+ for (const [id, e] of entries) expect(presetCover(id), id).toEqual({ poster: e.poster, ...(e.video && { video: e.video }) });+ for (const p of [...APPS, ...MOTIONS, ...EFFECTS]) if (!PRESET_PREVIEWS[p.id]) expect(presetCover(p.id), p.id).toBeUndefined();+ for (const id of [undefined, "", "toString", "constructor", "__proto__"]) expect(presetCover(id), String(id)).toBeUndefined();+ });+it("is read only on the server and in the preset header's own chunk", () => {// Client chunks keep whatever client code uses from a module. preset-cards.ts is in the galleries',// home's, shorts' and mixed media's chunks, so importing the manifest there (or preset-card-data.ts,@@ -76,6 +86,13 @@ describe("the preset covers manifest", () => {"app/(studio)/page.tsx","components/preset-header.tsx",]);+ // The slim map (which presets have a cover, and a clip: a few KB) is for the pickers, each in its studio's code:+ // the camera motion and Mix pickers (their own chunk, next/dynamic in composer.tsx) and Cinema Studio's moves.+ expect(importers(/from "[^"]*preset-covers\.generated"/)).toEqual(["lib/preset-covers.ts"]);+ // (A type is no code: the cover tile takes a cover without importing the map.)+ expect(importers(/^import (?!type )[^;]*from "[^"]*preset-covers";/m)).toEqual(["components/cinema/camera-moves.tsx", "components/studio/preset-chips.tsx"]);+ const composer = fs.readFileSync(path.join(root, "src", "components", "studio", "composer.tsx"), "utf8");+ expect(composer).toMatch(/dynamic\(\(\) => import\("\.\/preset-chips"\)/);const header = fs.readFileSync(path.join(root, "src", "components", "studio", "studio-page.tsx"), "utf8");expect(header).toMatch(/dynamic\(\(\) => import\("@\/components\/preset-header"\)/);});