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
Elements: clip elements show a still of their clip everywhere they are listed
Adarshb68f0787887e
diff --git a/src/components/assist/project-view.tsx b/src/components/assist/project-view.tsxindex ef8b611e..d2b32cab 100644--- a/src/components/assist/project-view.tsx+++ b/src/components/assist/project-view.tsx@@ -60,6 +60,7 @@ import { useModeChoice } from "./mode-picker";import { ProjectDialog } from "./project-dialog";import { ScheduledView } from "./scheduled-view";import { ProjectDot, RailButton } from "./shell";+import { ElementThumb } from "@/components/element-thumb";const SOURCE_ICON: Record<SourceKind, typeof FileText> = { link: Link2, file: FileText, image: ImageIcon, video: Video, audio: AudioLines, element: AtSign, text: NotebookPen };@@ -364,8 +365,7 @@ function Sources({ p }: { p: AssistProject }) {className="flex w-full items-center gap-2.5 rounded-lg px-2 py-1.5 text-left hover:bg-accent disabled:opacity-50">{el.references[0] ? (- // eslint-disable-next-line @next/next/no-img-element- <img src={el.references[0]} alt="" className="size-8 shrink-0 rounded-md object-cover" />+ <ElementThumb src={el.references[0]} mark="small" className="size-8 shrink-0 rounded-md object-cover" />) : (<span className="grid size-8 place-items-center rounded-md bg-muted"><AtSign className="size-4" />diff --git a/src/components/canvas/nodes.tsx b/src/components/canvas/nodes.tsxindex f762b1b9..5dc3ed3e 100644--- a/src/components/canvas/nodes.tsx+++ b/src/components/canvas/nodes.tsx@@ -138,6 +138,7 @@ import { ExactOrbitControls } from "@/components/exact-orbit-controls";import { PATH_PRESETS } from "@/lib/camera-path";import { exactDefaults } from "@/lib/exact-orbit";import { EXAMPLE_FEATURE, NodeIcon, PORT_COLOR, useEditorActions, useEditorGlobals, useEditorSelector, useNodeResults, useNodeView, type EditorSnapshot, type NodeResults } from "./canvas-context";+import { ElementThumb } from "@/components/element-thumb";/** A node on the board: a graph node, or a group, comment pin or drawing (./board.tsx). */export type FlowNode = Node<CanvasNodeData, CanvasNodeType | BoardType>;@@ -1561,8 +1562,7 @@ function ElementList({ current, onPick }: { current?: string; onPick: (patch: PaclassName={cn("flex w-full items-center gap-2.5 rounded-lg px-2 py-1.5 text-left hover:bg-accent", e.id === current && "bg-brand-faint")}><span className="size-8 shrink-0 overflow-hidden rounded-md bg-muted">- {/* eslint-disable-next-line @next/next/no-img-element */}- {e.references[0] && <img src={e.references[0]} alt="" className="size-full object-cover" />}+ {e.references[0] && <ElementThumb src={e.references[0]} mark="small" className="size-full object-cover" />}</span><span className="min-w-0 flex-1"><span className="block truncate text-[13px] font-medium">{e.name}</span>@@ -1586,8 +1586,7 @@ const ElementNode = memo(function ElementNode({ id, type, data, selected }: Node{data.handle ? (<div className="flex items-center gap-2.5"><span className="size-12 shrink-0 overflow-hidden rounded-lg bg-muted">- {/* eslint-disable-next-line @next/next/no-img-element */}- {data.preview && <img src={data.preview} alt="" className="size-full object-cover" />}+ {data.preview && <ElementThumb src={data.preview} mark="small" className="size-full object-cover" />}</span><span className="min-w-0"><span className="block truncate text-[13px] font-medium">{data.name ?? data.handle}</span>diff --git a/src/components/cinema/blockout-panel.tsx b/src/components/cinema/blockout-panel.tsxindex 98f93685..d1c93d43 100644--- a/src/components/cinema/blockout-panel.tsx+++ b/src/components/cinema/blockout-panel.tsx@@ -23,6 +23,7 @@ import { cn } from "@/lib/utils";import type { BuiltBlockout } from "./blockout-builder";import { useCinemaGenerate } from "./hooks";import { mediaDuration } from "./media";+import { firstPhoto } from "@/lib/clip-thumb";/*** Blockout to film in Cinema's take composer (package blockout-film): the blockout (an uploaded grey-box render from any@@ -466,15 +467,15 @@ export function BlockoutPanel(props: BlockoutPanelProps) {<button type="button" onClick={() => refInput.current?.click()} className="flex w-full items-center gap-2 rounded-lg px-2 py-2 text-left text-[13px] font-medium hover:bg-accent"><Upload className="size-4" /> Upload a picture</button>- {!!elements.data?.some((e) => e.references.length && e.kind !== "voice") && <p className="px-2 pt-2 pb-1 text-[11px] font-medium tracking-wide text-muted-foreground uppercase">Elements · Soul Cast · Soul Location</p>}+ {!!elements.data?.some((e) => firstPhoto(e.references) && e.kind !== "voice") && <p className="px-2 pt-2 pb-1 text-[11px] font-medium tracking-wide text-muted-foreground uppercase">Elements · Soul Cast · Soul Location</p>}<div className="max-h-40 space-y-0.5 overflow-y-auto">{(elements.data ?? [])- .filter((e) => e.references.length && e.kind !== "voice")+ .filter((e) => firstPhoto(e.references) && e.kind !== "voice").slice(0, 30).map((e) => (- <button key={e.id} type="button" onClick={() => addRef({ url: e.references[0], role: roleFor({ category: e.kind }), name: e.name })} className="flex w-full items-center gap-2 rounded-md px-2 py-1 text-left text-[13px] hover:bg-accent">+ <button key={e.id} type="button" onClick={() => addRef({ url: firstPhoto(e.references)!, role: roleFor({ category: e.kind }), name: e.name })} className="flex w-full items-center gap-2 rounded-md px-2 py-1 text-left text-[13px] hover:bg-accent">{/* eslint-disable-next-line @next/next/no-img-element */}- <img src={e.references[0]} alt="" className="size-7 rounded object-cover" />+ <img src={firstPhoto(e.references)} alt="" className="size-7 rounded object-cover" /><span className="min-w-0 flex-1 truncate">{e.name}</span><span className="text-[11.5px] text-muted-foreground capitalize">{e.kind}</span></button>diff --git a/src/components/cinema/director-panel.tsx b/src/components/cinema/director-panel.tsxindex 9ae6bdfe..8ac1bebd 100644--- a/src/components/cinema/director-panel.tsx+++ b/src/components/cinema/director-panel.tsx@@ -37,6 +37,7 @@ import { cn } from "@/lib/utils";import { onAttr, TAB_PILL, TabRow } from "@/components/ui/tab-row";import { MoveChips, MoveList, prefetchMoves } from "./camera-moves";import { PaletteEditor } from "./palette-editor";+import { ClipAvatar, ElementThumb } from "@/components/element-thumb";type Patch = (p: Partial<DirectorSettings>) => void;@@ -600,10 +601,11 @@ export function EmotionChip({ settings, onChange, characters }: { settings: Direreturn (<div key={c.id} className="space-y-1.5"><div className="flex items-center gap-2">- <span className="grid size-6 place-items-center overflow-hidden rounded-full bg-muted" style={step ? { boxShadow: `0 0 0 2px ${step.color}` } : undefined}>- {/* eslint-disable-next-line @next/next/no-img-element */}- {c.references[0] ? <img src={c.references[0]} alt="" className="size-full object-cover" /> : null}- </span>+ <ClipAvatar src={c.references[0]}>+ <span className="grid size-6 place-items-center overflow-hidden rounded-full bg-muted" style={step ? { boxShadow: `0 0 0 2px ${step.color}` } : undefined}>+ {c.references[0] ? <ElementThumb src={c.references[0]} mark="none" className="size-full object-cover" /> : null}+ </span>+ </ClipAvatar><span className="text-[13px] font-medium">@{c.handle}</span>{step && <span className="truncate text-[12px] text-muted-foreground">{step.prompt}</span>}</div>diff --git a/src/components/cinema/elements-panel.tsx b/src/components/cinema/elements-panel.tsxindex 42da3b0a..473df9c6 100644--- a/src/components/cinema/elements-panel.tsx+++ b/src/components/cinema/elements-panel.tsx@@ -7,6 +7,7 @@ import { Skeleton } from "@/components/ui/skeleton";import { ELEMENT_ICONS } from "@/components/studio/prompt-input";import { useElements } from "@/lib/api";import { ELEMENT_KINDS, type StudioElement } from "@/lib/catalog/elements";+import { ElementThumb } from "@/components/element-thumb";/** "My Elements": the characters, locations and props every shot can @mention. */export function ElementsPanel({ onMention, onCast, onLocation }: { onMention: (el: StudioElement) => void; onCast: () => void; onLocation: () => void }) {@@ -56,8 +57,7 @@ export function ElementsPanel({ onMention, onCast, onLocation }: { onMention: (e<button type="button" onClick={() => onMention(el)} className="block w-full text-left outline-none focus-visible:ring-2 focus-visible:ring-ring" aria-label={`Add @${el.handle} to the prompt`}><div className="aspect-[4/3] bg-muted">{el.references[0] ? (- // eslint-disable-next-line @next/next/no-img-element- <img src={el.references[0]} alt="" loading="lazy" className="size-full object-cover" />+ <ElementThumb src={el.references[0]} loading="lazy" className="size-full object-cover" />) : (<Icon className="m-auto mt-[22%] size-6 text-muted-foreground" />)}diff --git a/src/components/cinema/prompt-bar.tsx b/src/components/cinema/prompt-bar.tsxindex cb341afa..7a9742a7 100644--- a/src/components/cinema/prompt-bar.tsx+++ b/src/components/cinema/prompt-bar.tsx@@ -37,8 +37,8 @@ import {planCinema,type DirectorSettings,} from "@/lib/catalog/cinema";-import { applyMentions, findMentions, isClipRef, type StudioElement } from "@/lib/catalog/elements";-import { ClipMark, ElementThumb } from "@/components/element-thumb";+import { applyMentions, findMentions, type StudioElement } from "@/lib/catalog/elements";+import { ClipAvatar, ElementThumb } from "@/components/element-thumb";import { referenceWindow, trimLine, trimTarget, windowProblem, type ClipWindow } from "@/lib/av/reference-fit";import { ListFit } from "@/components/av/fit-list";import { ElementClipFix, useElementClipCheck } from "@/components/av/element-clip-fit";@@ -791,22 +791,14 @@ export function PromptBar(props: PromptBarProps) {{mentions.map((el) => {const Icon = ELEMENT_ICONS[el.kind];const emo = settings.emotions?.[el.handle.toLowerCase()];- const face = (- <span className="grid size-6 place-items-center overflow-hidden rounded-full bg-muted">- {el.references[0] ? <ElementThumb src={el.references[0]} mark="none" className="size-full object-cover" /> : <Icon className="size-3.5" />}- </span>- );return (<span key={el.id} className="inline-flex h-7 items-center gap-1.5 rounded-full border bg-background pr-2.5 pl-0.5 text-[12px] font-medium">{/* A clip element: a still of its clip, with the clip mark on the circle's edge. */}- {el.references[0] && isClipRef(el.references[0]) ? (- <span className="relative shrink-0">- {face}- <ClipMark size="xs" className="absolute -right-1 -bottom-0.5" />+ <ClipAvatar src={el.references[0]}>+ <span className="grid size-6 place-items-center overflow-hidden rounded-full bg-muted">+ {el.references[0] ? <ElementThumb src={el.references[0]} mark="none" className="size-full object-cover" /> : <Icon className="size-3.5" />}</span>- ) : (- face- )}+ </ClipAvatar>{el.name}{emo && <span className="text-[11px] text-muted-foreground">· {emo.family}</span>}</span>diff --git a/src/components/element-studio.tsx b/src/components/element-studio.tsxindex 553f963c..ab2c3f42 100644--- a/src/components/element-studio.tsx+++ b/src/components/element-studio.tsx@@ -14,6 +14,7 @@ import { TurnaroundButton, useCharacterPictures } from "@/components/turnaround/import { Button } from "@/components/ui/button";import { useElement } from "@/lib/api";import { loraFamily, TRAINING_FAMILIES } from "@/lib/catalog/training";+import { isClipRef } from "@/lib/catalog/elements";const NO_REFS: string[] = [];@@ -27,7 +28,7 @@ export function ElementStudio({ id }: { id: string }) {const [training, setTraining] = useState(false);const el = q.data;// A character's pictures (a wide one is its sheet) for "Fly around this character".- const pictures = useCharacterPictures(el?.kind === "character" ? el.references.slice(0, 12) : NO_REFS);+ const pictures = useCharacterPictures(el?.kind === "character" ? el.references.filter((r) => !isClipRef(r)).slice(0, 12) : NO_REFS);const config = useMemo<StudioConfig | null>(() => {if (!el) return null;// A trained Soul ID runs on its family's lead model (Fuobe Soul, Soul HD, FLUX…): start there, on each engine it has.diff --git a/src/components/element-thumb.tsx b/src/components/element-thumb.tsxindex 49038240..a622b44f 100644--- a/src/components/element-thumb.tsx+++ b/src/components/element-thumb.tsx@@ -1,8 +1,9 @@"use client";import { Video } from "lucide-react";-import { useEffect, useState } from "react";+import { useEffect, useState, type ReactNode } from "react";import { CLIP_FRAME_AT, frameSize, stillCache, thumbSource } from "@/lib/clip-thumb";+import { isClipRef } from "@/lib/catalog/elements";import { cn } from "@/lib/utils";/** One frame of a clip, scaled down and kept as a JPEG object URL; null when this browser can't read the clip. */@@ -67,8 +68,9 @@ export function ClipMark({ className, size = "sm" }: { className?: string; size?/*** An element's reference drawn as a thumbnail. A photo is the same <img> as ever (`className` on it). A clip shows a still* of itself (its `poster` when one is known, else a frame grabbed in the browser), in a box that takes `className`, with- * the clip mark in its corner (`mark="none"` leaves it to the caller, as a chip too small for it does). A clip that can't- * be read shows the mark alone, never a broken image.+ * the clip mark in its corner: `corner` on cards, `small` on tiles of about 28-48 px, `none` when the caller places it (a+ * round avatar: ClipAvatar). `markClassName` moves the mark (away from a caption). A clip that can't be read shows a+ * camera alone, never a broken image.*/export function ElementThumb({src,@@ -77,23 +79,41 @@ export function ElementThumb({className,loading,mark = "corner",+ markClassName,}: {src: string;poster?: string | null;alt?: string;className?: string;loading?: "lazy" | "eager";- mark?: "corner" | "none";+ mark?: "corner" | "small" | "none";+ markClassName?: string;}) {const s = thumbSource(src, poster);if (s.kind === "image") {// eslint-disable-next-line @next/next/no-img-elementreturn <img src={s.src} alt={alt} loading={loading} className={className} />;}- return <ClipStill clip={s.clip} poster={s.poster} alt={alt} className={className} loading={loading} mark={mark} />;+ return <ClipStill clip={s.clip} poster={s.poster} alt={alt} className={className} loading={loading} mark={mark} markClassName={markClassName} />;}-function ClipStill({ clip, poster, alt, className, loading, mark }: { clip: string; poster?: string; alt: string; className?: string; loading?: "lazy" | "eager"; mark: "corner" | "none" }) {+function ClipStill({+ clip,+ poster,+ alt,+ className,+ loading,+ mark,+ markClassName,+}: {+ clip: string;+ poster?: string;+ alt: string;+ className?: string;+ loading?: "lazy" | "eager";+ mark: "corner" | "small" | "none";+ markClassName?: string;+}) {// The poster first; if it fails to load, a frame from the clip.const [posterFailed, setPosterFailed] = useState(false);const usePoster = !!poster && !posterFailed;@@ -121,10 +141,26 @@ function ClipStill({ clip, poster, alt, className, loading, mark }: { clip: stri)}{!usePoster && still === null && (<span className="absolute inset-0 grid place-items-center text-muted-foreground">- <Video className={mark === "corner" ? "size-7" : "size-3.5"} />+ <Video className={mark === "corner" ? "size-7" : "size-4"} /></span>)}- {mark === "corner" && (usePoster || still !== null) && <ClipMark className="absolute right-1.5 bottom-1.5" />}+ {mark !== "none" && (usePoster || still !== null) && (+ <ClipMark size={mark === "small" ? "xs" : "sm"} className={cn("absolute", mark === "small" ? "right-0.5 bottom-0.5" : "right-1.5 bottom-1.5", markClassName)} />+ )}+ </span>+ );+}++/**+ * A round avatar (a chip's face) that may show a clip: the clip mark sits on the circle's edge, outside its clipping. A photo+ * (or no reference) gets the avatar alone, as before.+ */+export function ClipAvatar({ src, children, className }: { src?: string | null; children: ReactNode; className?: string }) {+ if (!src || !isClipRef(src)) return <>{children}</>;+ return (+ <span className={cn("relative inline-flex shrink-0", className)}>+ {children}+ <ClipMark size="xs" className="absolute -right-1 -bottom-0.5" /></span>);}diff --git a/src/components/faceless/settings-form.tsx b/src/components/faceless/settings-form.tsxindex ad4b722c..dad00f8c 100644--- a/src/components/faceless/settings-form.tsx+++ b/src/components/faceless/settings-form.tsx@@ -24,6 +24,7 @@ import { ClipBed } from "./clip-bed";import { Section, Segmented, ToggleRow } from "./controls";import { NarratorList } from "./narrator";import { StyleGrid } from "./style-art";+import { ClipAvatar, ElementThumb } from "@/components/element-thumb";/** Up to 3 style reference images (they replace the preset); `max` is what the engine's picture model reads. */export function StyleRefs({ value, onChange, max = MAX_STYLE_REFS }: { value: string[]; onChange: (urls: string[]) => void; max?: number }) {@@ -98,8 +99,9 @@ export function ElementsPicker({ value, onChange }: { value: string[]; onChange:)}>{e.references[0] ? (- // eslint-disable-next-line @next/next/no-img-element- <img src={e.references[0]} alt="" className="size-6 rounded-full object-cover" />+ <ClipAvatar src={e.references[0]}>+ <ElementThumb src={e.references[0]} mark="none" className="size-6 rounded-full object-cover" />+ </ClipAvatar>) : (<AtSign className="ml-1 size-3.5" />)}diff --git a/src/components/marketing/pickers.tsx b/src/components/marketing/pickers.tsxindex e83306ec..2d17d56b 100644--- a/src/components/marketing/pickers.tsx+++ b/src/components/marketing/pickers.tsx@@ -17,6 +17,7 @@ import type { ModelDef } from "@/lib/catalog/types";import { cn } from "@/lib/utils";import type { ModelInfo } from "./model-info";import { useProducts } from "./hooks";+import { firstPhoto } from "@/lib/clip-thumb";/** The product a run uses: a saved product, or a one-off photo. */export interface ProductChoice {@@ -122,7 +123,10 @@ export function ProductSlot({ value, onChange, required, brandId, pulse }: { valexport function AvatarSlot({ value, onChange, pulse }: { value: SlotValue | null; onChange: (v: SlotValue | null) => void; pulse?: boolean }) {const [open, setOpen] = useState(false);const elements = useElements();- const people = (elements.data ?? []).filter((e) => e.kind === "character" && e.references[0]);+ const people = (elements.data ?? []).flatMap((e) => {+ const photo = e.kind === "character" ? firstPhoto(e.references) : undefined;+ return photo ? [{ ...e, photo }] : [];+ });const [busy, setBusy] = useState(false);const input = useRef<HTMLInputElement>(null);const choose = (v: SlotValue) => {@@ -175,9 +179,9 @@ export function AvatarSlot({ value, onChange, pulse }: { value: SlotValue | null{people.length ? (<div className="grid grid-cols-4 gap-2">{people.map((e) => (- <button key={e.id} type="button" onClick={() => choose({ ref: e.references[0], preview: e.references[0], kind: "image", name: e.name })} className={cn("min-w-0 rounded-lg p-1 hover:bg-accent", value?.ref === e.references[0] && "bg-brand-faint")}>+ <button key={e.id} type="button" onClick={() => choose({ ref: e.photo, preview: e.photo, kind: "image", name: e.name })} className={cn("min-w-0 rounded-lg p-1 hover:bg-accent", value?.ref === e.photo && "bg-brand-faint")}>{/* eslint-disable-next-line @next/next/no-img-element */}- <img src={e.references[0]} alt="" className="aspect-square w-full rounded-md object-cover" />+ <img src={e.photo} alt="" className="aspect-square w-full rounded-md object-cover" /><span className="mt-1 block truncate text-[11px]">{e.name}</span></button>))}diff --git a/src/components/photodump/subject.tsx b/src/components/photodump/subject.tsxindex 4d91cab8..4e9d7912 100644--- a/src/components/photodump/subject.tsx+++ b/src/components/photodump/subject.tsx@@ -15,12 +15,14 @@ import { SOUL_ID_COPY, SOUL_ID_PHOTOS } from "@/lib/catalog/training";import { cn } from "@/lib/utils";import { toastError } from "@/lib/refusals";import { usePhotoCharacters, useSaveCharacter } from "./hooks";+import { ElementThumb } from "@/components/element-thumb";+import { referenceWords } from "@/lib/clip-thumb";-/** What a character brings: a trained Soul ID (Fuobe Soul), an older one to retrain, or just photos. */+/** What a character brings: a trained Soul ID (Fuobe Soul), an older one to retrain, or just its photos and clips. */export function identityLabel(el: StudioElement): string {if (el.loras.some((l) => !l.referenceId && !l.demo)) return "Soul ID";if (el.loras.some((l) => l.referenceId)) return "Retrain Soul ID";- return `${el.references.length} photo${el.references.length === 1 ? "" : "s"}`;+ return referenceWords(el.references) || "0 photos";}/** The character-creation copy (src/lib/catalog/training.ts SOUL_ID_COPY, the researched rules): saving is the consent. */@@ -158,8 +160,7 @@ export function CharacterPicker({ value, onChange }: { value?: string; onChange:><span className="block aspect-[3/4]">{el.references[0] ? (- // eslint-disable-next-line @next/next/no-img-element- <img src={el.references[0]} alt="" loading="lazy" className="size-full object-cover" />+ <ElementThumb src={el.references[0]} loading="lazy" markClassName="top-1.5 bottom-auto" className="size-full object-cover" />) : (<span className="grid size-full place-items-center text-muted-foreground"><UserRound className="size-6" />diff --git a/src/components/studio/prompt-input.tsx b/src/components/studio/prompt-input.tsxindex f0d012b8..a90eaef6 100644--- a/src/components/studio/prompt-input.tsx+++ b/src/components/studio/prompt-input.tsx@@ -6,6 +6,8 @@ import { forwardRef, useEffect, useImperativeHandle, useLayoutEffect, useMemo, uimport { elementKindInfo, mentionAtCaret, type ElementKind, type StudioElement } from "@/lib/catalog/elements";import { hasMention } from "@/lib/composer";import { cn } from "@/lib/utils";+import { ElementThumb } from "@/components/element-thumb";+import { referenceWords } from "@/lib/clip-thumb";export const ELEMENT_ICONS: Record<ElementKind, typeof ScanFace> = {character: ScanFace,@@ -236,8 +238,7 @@ export const PromptInput = forwardRef<><span className="grid size-8 shrink-0 place-items-center overflow-hidden rounded-md bg-muted text-muted-foreground">{el.references[0] ? (- // eslint-disable-next-line @next/next/no-img-element- <img src={el.references[0]} alt="" className="size-full object-cover" />+ <ElementThumb src={el.references[0]} mark="small" className="size-full object-cover" />) : (<Icon className="size-4" />)}@@ -246,7 +247,7 @@ export const PromptInput = forwardRef<<span className="block truncate text-[13px] font-medium">@{el.handle}</span><span className="block truncate text-[11px] text-muted-foreground">{elementKindInfo(el.kind).label}- {el.references.length ? ` · ${el.references.length} photo${el.references.length > 1 ? "s" : ""}` : ""}+ {el.references.length ? ` · ${referenceWords(el.references)}` : ""}{el.loras.length ? " · trained" : ""}</span></span>diff --git a/src/lib/clip-thumb.ts b/src/lib/clip-thumb.tsindex 06988f29..f70e6ce9 100644--- a/src/lib/clip-thumb.ts+++ b/src/lib/clip-thumb.ts@@ -11,6 +11,11 @@ export function thumbSource(ref: string, poster?: string | null): ThumbSource {return poster && !isClipRef(poster) ? { kind: "clip", clip: ref, poster } : { kind: "clip", clip: ref };}+/** An element's first photo (not a clip): what goes where a picture is needed, such as an avatar or an image reference. */+export function firstPhoto(references: readonly string[]): string | undefined {+ return references.find((r) => !isClipRef(r));+}+/** Where in a clip its still is taken (seconds): just past the start, as the Video studio's chip shows it. */export const CLIP_FRAME_AT = 0.1;@@ -66,3 +71,11 @@ export function stillCache(grab: (clip: string) => Promise<string | null>, limit},};}++/** An element's references in words for a menu row: "2 photos", "1 clip", "3 photos · 1 clip" ("" for none). */+export function referenceWords(references: readonly string[]): string {+ const clips = references.filter(isClipRef).length;+ const photos = references.length - clips;+ const words = [photos && `${photos} photo${photos > 1 ? "s" : ""}`, clips && `${clips} clip${clips > 1 ? "s" : ""}`].filter(Boolean);+ return words.join(" · ");+}diff --git a/tests/clip-thumb.test.ts b/tests/clip-thumb.test.tsindex 67542129..577e61cd 100644--- a/tests/clip-thumb.test.ts+++ b/tests/clip-thumb.test.ts@@ -1,5 +1,5 @@import { describe, expect, it } from "vitest";-import { frameSize, stillCache, thumbSource } from "@/lib/clip-thumb";+import { firstPhoto, frameSize, referenceWords, stillCache, thumbSource } from "@/lib/clip-thumb";describe("thumbSource", () => {it("draws a photo as itself", () => {@@ -57,3 +57,22 @@ describe("stillCache", () => {expect(calls).toHaveLength(5);});});++describe("firstPhoto", () => {+ it("gives the first reference that is not a clip", () => {+ expect(firstPhoto(["/api/files/a.mp4", "/api/files/b.jpg", "/api/files/c.png"])).toBe("/api/files/b.jpg");+ expect(firstPhoto(["/api/files/b.jpg"])).toBe("/api/files/b.jpg");+ expect(firstPhoto(["/api/files/a.mp4", "/api/files/a.mov"])).toBeUndefined();+ expect(firstPhoto([])).toBeUndefined();+ });+});++describe("referenceWords", () => {+ it("counts photos and clips apart", () => {+ expect(referenceWords(["/a.jpg"])).toBe("1 photo");+ expect(referenceWords(["/a.jpg", "/b.png"])).toBe("2 photos");+ expect(referenceWords(["/a.mp4"])).toBe("1 clip");+ expect(referenceWords(["/a.mp4", "/b.jpg", "/c.webm", "/d.jpg", "/e.jpg"])).toBe("3 photos · 2 clips");+ expect(referenceWords([])).toBe("");+ });+});