"use client"; import { useRef, useState, type ReactNode } from "react"; import { useTranslations } from "next-intl"; import { AlignCenter, Bookmark, Captions, Clapperboard, Crop, Highlighter, Info, Palette, Play, Plus, RotateCcw, Trash2, Volume2, } from "lucide-react"; import { toast } from "sonner"; import { Alert, AlertDescription } from "@/components/ui/alert"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select"; import { Switch } from "@/components/ui/switch"; import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; import { Textarea } from "@/components/ui/textarea"; import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group"; import { DEFAULT_EFFECTS, captionAt, captionKey, captionTransform, clamp, replaceWords, setCaptionVisualSize, textTransform, uid, type EditDocument, type CaptionStyle, type CaptionTransform, type EditorState, } from "@/lib/editor/document"; import { cn } from "@/lib/utils"; import { editorMessage, Field, Panel, Range, Section } from "./studio-ui"; import { BRollPanel } from "./broll-panel"; export type InspectorTab = "captions" | "framing" | "broll" | "audio" | "effects"; const TABS = [ ["captions", Captions], ["framing", Crop], ["broll", Clapperboard], ["audio", Volume2], ["effects", Palette], ] as const; function ColorField({ label, inputLabel, value, onChange, }: { label: string; inputLabel: string; value: string; onChange: (value: string) => void; }) { return (
onChange(e.target.value)} className="size-6 shrink-0 cursor-pointer rounded border-0 ring-1 ring-border bg-transparent p-0 outline-none [&::-moz-color-swatch]:rounded [&::-moz-color-swatch]:border-0 [&::-webkit-color-swatch]:rounded [&::-webkit-color-swatch]:border-0 [&::-webkit-color-swatch-wrapper]:p-0" /> {value}
); } function SwitchRow({ id, label, checked, onChange, }: { id: string; label: ReactNode; checked: boolean; onChange: (checked: boolean) => void; }) { return (
); } interface Props { doc: EditDocument; asset: EditorState; tab: InspectorTab; setTab: (tab: InspectorTab) => void; time: number; editTime: number; seek: (value: number) => void; update: (change: (doc: EditDocument) => EditDocument, group?: string) => void; applyAll: (style: CaptionStyle) => Promise; endpoint: string; brollId: string | null; selectBroll: (id: string | null) => void; } export function Inspector({ doc, asset, tab, setTab, time, editTime, seek, update, applyAll, endpoint, brollId, selectBroll, }: Props) { const t = useTranslations("editor"); const activeCaption = captionAt(doc, editTime); const captionId = activeCaption ? captionKey(doc, activeCaption) : undefined; const placement: CaptionTransform = activeCaption ? captionTransform(doc, activeCaption) : textTransform(doc, "captions"); const captionSize = (placement.size ?? doc.captions.size) * placement.scale; const scriptWords = useRef(doc.words); const [script, setScript] = useState(null), [applying, setApplying] = useState(false); const caption = (change: Partial, group = "caption-style") => update((d) => ({ ...d, captions: { ...d.captions, ...change } }), group); return ( setTab(value as InspectorTab)} className="gap-0 lg:min-h-0 lg:flex-1" >
{TABS.map(([id, Icon]) => ( {t(`tabs.${id}`)} ))}
caption({ enabled })} /> } >
{( [ ["clean", false, "#FFFFFF"], ["highlight", true, "#FACC15"], ["pop", true, "#A3E635"], ] as const ).map(([name, background, accent]) => { const active = doc.captions.background === background && doc.captions.accent.toUpperCase() === accent; return ( ); })}
update(current => setCaptionVisualSize(current, size, captionId), `caption-size:${captionId ?? "all"}`)} /> update(current => { const transform = { ...(captionId ? current.captionTransforms?.[captionId] : undefined) ?? textTransform(current, "captions"), y: y / 100 - current.captions.y }; return captionId ? { ...current, captionTransforms: { ...current.captionTransforms, [captionId]: transform } } : { ...current, textTransforms: { ...current.textTransforms, captions: transform } }; }, `caption-position:${captionId ?? "all"}`)} />
caption({ color })} /> caption({ accent })} />
caption({ background })} /> caption({ karaoke })} /> caption({ uppercase })} />
{ const hookTitle = e.target.value; update((d) => ({ ...d, hookTitle }), "hook-title"); }} />
{t("captions.transcript")}{" "} · {t("captions.wordCount", { count: doc.words.length })} } description={t("captions.transcriptDescription")} action={ } > {script !== null && (