Open source CapCut alternative.
TypeScript
feat(site): capture timeline frames into chat
David Lebbd2f6199d07
diff --git a/site/src/cut/components/AiPanel.tsx b/site/src/cut/components/AiPanel.tsxindex 1514520d..39f16004 100644--- a/site/src/cut/components/AiPanel.tsx+++ b/site/src/cut/components/AiPanel.tsx@@ -1,6 +1,6 @@"use client";-import { Fragment, memo, useCallback, useEffect, useMemo, useRef, useState } from "react";+import { Fragment, memo, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState, type ReactNode } from "react";import { useChat } from "@ai-sdk/react";import { DefaultChatTransport, type ChatTransport, type UIMessage } from "ai";import {@@ -47,6 +47,8 @@ import { localBackend } from "@/cut/lib/backend/local";import { buildAiContext } from "@/cut/lib/aiContext";import { runAiTool } from "@/cut/lib/aiTools";import { setAssetDragData } from "@/cut/lib/assetDrag";+import { registerChatIntake } from "@/cut/lib/chatIntake";+import { videoModel } from "@/cut/lib/videoModels";import {readActiveChat,readRawThreads,@@ -497,6 +499,43 @@ export function AiPanel({);}+/** Animates the composer's chip area to its content height, so every growth —+ * the first attachment opening the row, a full row wrapping a new one open —+ * raises the box smoothly instead of snapping. While growing, the box is+ * shorter than its content and clips it; settled, it relaxes so chip hover+ * cards and moment pickers can pop outside. Shrinks (a removed chip, the+ * emptied row collapsing) animate too — their content already fits, so they+ * never need the clip. */+function ChipsReveal({ open, children }: { open: boolean; children: ReactNode }) {+ const outer = useRef<HTMLDivElement>(null);+ const inner = useRef<HTMLDivElement>(null);+ const [h, setH] = useState(0);+ useEffect(() => {+ const el = inner.current;+ if (!el) return;+ const ro = new ResizeObserver(() => setH(el.offsetHeight));+ ro.observe(el);+ return () => ro.disconnect();+ }, []);+ const target = open ? h : 0;+ useLayoutEffect(() => {+ const el = outer.current;+ if (el && el.offsetHeight < target) el.style.overflow = "hidden";+ }, [target]);+ return (+ <div+ ref={outer}+ className="transition-[height] duration-300 ease-[cubic-bezier(0.32,0.72,0,1)]"+ style={{ height: target }}+ onTransitionEnd={(e) => {+ if (e.propertyName === "height" && outer.current) outer.current.style.overflow = "";+ }}+ >+ <div ref={inner}>{children}</div>+ </div>+ );+}+/** One chat with the agent. Remounts per active thread; its messages and* provider session are restored from the saved thread on open. */function ChatSession({@@ -565,6 +604,51 @@ function ChatSession({(ref) => setAttachments((prev) => addRefOnce(prev, ref)),attachFiles,);+ // A transient warning in the folder tab above the composer — the same slot+ // the credits tab uses — for refusals like the frame capacity below.+ const [notice, setNotice] = useState<string | null>(null);+ const noticeTimer = useRef<ReturnType<typeof setTimeout> | null>(null);+ const showNotice = (msg: string) => {+ setNotice(msg);+ if (noticeTimer.current) clearTimeout(noticeTimer.current);+ noticeTimer.current = setTimeout(() => setNotice(null), 5000);+ };+ useEffect(+ () => () => {+ if (noticeTimer.current) clearTimeout(noticeTimer.current);+ },+ [],+ );+ // The timeline's "Add video frame to chat" lands its pinned ref here; the+ // registration follows the composer box's lifetime (absent on read-only+ // shares, where there is no composer to receive it). `incoming` marks a+ // frame still in flight, opening the chip row ahead of the landing.+ // Grabbed frames stop at the render models' reference capacity, read from+ // the registry, so every attached frame actually rides a render.+ const composerBoxRef = useRef<HTMLDivElement>(null);+ const [incoming, setIncoming] = useState(false);+ const attachmentsRef = useRef(attachments);+ useEffect(() => {+ attachmentsRef.current = attachments;+ }, [attachments]);+ useEffect(() => {+ const el = composerBoxRef.current;+ if (!el) return;+ const isFrame = (r: AssetRef) => r.scope === "file" && r.kind === "image";+ const cap = videoModel("omni").maxReferenceImages;+ return registerChatIntake({+ el,+ add: (ref) => setAttachments((p) => upsertRef(p, ref)),+ expect: setIncoming,+ acceptFrame: () => {+ if (attachmentsRef.current.filter(isFrame).length < cap) return true;+ showNotice(+ `Renders read up to ${cap} reference frames — remove one to add another.`,+ );+ return false;+ },+ });+ }, [readOnly]);const sessionKeyRef = useRef<string | null>(null);// Resume from the saved thread when this id exists in history.const [initialThread] = useState<ChatThread | undefined>(() =>@@ -949,7 +1033,16 @@ function ChatSession({</span></a>)}+ {!outOfCredits && notice && (+ // The credits tab's folder shape, borrowed for transient+ // refusals; the credits warning outranks it when both apply.+ <div className="ai-notice-tab absolute inset-x-1.5 bottom-full -mb-1 flex items-center gap-1.5 rounded-t-lg border border-b-0 border-amber-500/30 bg-amber-50 px-3 pt-1.5 pb-2.5 text-[11px] text-amber-800">+ <TriangleAlert className="size-3 shrink-0" />+ <span>{notice}</span>+ </div>+ )}<div+ ref={composerBoxRef}className={cn("relative rounded-xl border bg-background transition-colors",dropActive@@ -966,16 +1059,23 @@ function ChatSession({)}{mic.state === "idle" ? (<>- <RefChips- refs={attachments}- onRemove={(ref) =>- setAttachments((p) => p.filter((x) => !sameRef(x, ref)))- }- onUpdate={(ref) =>- setAttachments((p) => p.map((x) => (sameRef(x, ref) ? ref : x)))- }- className="px-2.5 pt-2.5"- />+ <ChipsReveal open={attachments.length > 0 || incoming}>+ <RefChips+ refs={attachments}+ onRemove={(ref) =>+ setAttachments((p) => p.filter((x) => !sameRef(x, ref)))+ }+ onUpdate={(ref) =>+ setAttachments((p) => p.map((x) => (sameRef(x, ref) ? ref : x)))+ }+ className="px-2.5 pt-2.5"+ // Chip-sized spacer riding the chip row while a frame is+ // in flight: it claims the arriving chip's exact slot —+ // opening the row, or wrapping a fresh one when the row+ // is full — so the space is ready before the landing.+ trailing={incoming ? <div className="size-14" /> : undefined}+ />+ </ChipsReveal><MentionTextareaclassName="ai-input max-h-56 w-full resize-none overflow-y-auto bg-transparent px-3 pt-2 text-[12.5px] leading-relaxed outline-none placeholder:text-muted-foreground/70"rows={5}diff --git a/site/src/cut/components/AssetRefs.tsx b/site/src/cut/components/AssetRefs.tsxindex 4ba8bb13..2debcd05 100644--- a/site/src/cut/components/AssetRefs.tsx+++ b/site/src/cut/components/AssetRefs.tsx@@ -1,6 +1,6 @@"use client";-import { useEffect, useLayoutEffect, useMemo, useRef, useState, type RefObject } from "react";+import { useEffect, useLayoutEffect, useMemo, useRef, useState, type ReactNode, type RefObject } from "react";import { Check, Copy, FileText, X } from "lucide-react";import {highlightMentions,@@ -271,6 +271,7 @@ export function RefChips({className,peekSide = "top",thumbClassName = "size-14",+ trailing,}: {refs: AssetRef[];onRemove: (ref: AssetRef) => void;@@ -281,9 +282,13 @@ export function RefChips({peekSide?: "top" | "bottom";/** Thumbnail size, e.g. "size-12" for a compact in-input composer. */thumbClassName?: string;+ /** Extra node laid out in the chip row after the chips — the composer's+ * incoming-frame spacer reserves the next slot there, wrapping to a fresh+ * row exactly when the arriving chip would. */+ trailing?: ReactNode;}) {const candidates = useRefCandidates();- if (refs.length === 0) return null;+ if (refs.length === 0 && !trailing) return null;return (<div className={cn("flex flex-wrap gap-2", className)}>{refs.map((r) => {@@ -301,6 +306,7 @@ export function RefChips({/>);})}+ {trailing}</div>);}diff --git a/site/src/cut/components/Timeline.tsx b/site/src/cut/components/Timeline.tsxindex 053a8844..1379aeca 100644--- a/site/src/cut/components/Timeline.tsx+++ b/site/src/cut/components/Timeline.tsx@@ -1,7 +1,7 @@"use client";import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore, type ReactNode } from "react";-import { ArrowDown, ArrowDownToLine, ArrowLeft, ArrowLeftToLine, ArrowRight, ArrowRightToLine, ArrowUp, ArrowUpToLine, AudioLines, Blend, Check, Circle, Clapperboard, Droplets, EllipsisVertical, Expand, Eye, EyeOff, FolderOpen, FolderPlus, FoldHorizontal, Loader2, Moon, MoreHorizontal, Pause, Play, Scissors, SkipBack, Sun, Target, Trash2, Type, UnfoldHorizontal, Volume2, VolumeX, type LucideIcon } from "lucide-react";+import { ArrowDown, ArrowDownToLine, ArrowLeft, ArrowLeftToLine, ArrowRight, ArrowRightToLine, ArrowUp, ArrowUpToLine, AudioLines, Blend, Check, Circle, Clapperboard, Droplets, EllipsisVertical, Expand, Eye, EyeOff, FolderOpen, FolderPlus, FoldHorizontal, Fullscreen, Loader2, Moon, MoreHorizontal, Pause, Play, Scissors, SkipBack, Sun, Target, Trash2, Type, UnfoldHorizontal, Volume2, VolumeX, type LucideIcon } from "lucide-react";import { Button } from "@/components/ui/button";import {DropdownMenu,@@ -22,7 +22,8 @@ import {hasLibraryDrag,hasTemplateDrag,} from "@/cut/lib/assetDrag";-import { audioClipRefs, draggingRef, hasRefDrag, type AssetRef } from "@/cut/lib/assetRef";+import { audioClipRefs, draggingRef, hasRefDrag, refFromAsset, type AssetRef } from "@/cut/lib/assetRef";+import { sendFrameToChat, type FrameGrabOrigin } from "@/cut/lib/chatIntake";import { useCutCaps } from "@/cut/lib/backend/hooks";import {addProjectTemplateToTimeline,@@ -234,6 +235,10 @@ export function Timeline() {const fileDropHint = useEditor((s) => s.dropActive === "media");const scrollRef = useRef<HTMLDivElement>(null);const innerRef = useRef<HTMLDivElement>(null);+ const timeAt = (clientX: number) => {+ const rect = innerRef.current!.getBoundingClientRect();+ return (clientX - rect.left) / pps;+ };// The static ruler band behind the scroller follows vertical scroll so it// stays glued under the in-content ruler; overscroll can't move it, so the// band runs unbroken through the bounce. (Horizontal position is moot — the@@ -496,6 +501,59 @@ export function Timeline() {return () => window.removeEventListener("keydown", close);}, [gapMenu]);+ // Right-click on a video clip: a one-item popover that grabs the frame+ // under the pointer into the chat composer. The menu carries the grab —+ // the asset, the source second under the pointer, and the spot the flight+ // starts from — and the held skimmer line stands at `t` while it is open.+ const readOnly = useEditor((s) => s.readOnly);+ const [frameMenu, setFrameMenu] = useState<+ { x: number; y: number; t: number; asset: MediaAsset; srcT: number; from: FrameGrabOrigin } | null+ >(null);+ useEffect(() => {+ if (!frameMenu) return;+ const close = (e: KeyboardEvent) => {+ if (e.key === "Escape") setFrameMenu(null);+ };+ window.addEventListener("keydown", close);+ return () => window.removeEventListener("keydown", close);+ }, [frameMenu]);+ const openFrameMenu = (+ e: React.MouseEvent,+ grab: { asset: MediaAsset; srcT: number; from: FrameGrabOrigin }+ ) => {+ if (readOnly) return;+ e.preventDefault();+ e.stopPropagation();+ const s = useEditor.getState();+ if (s.playing) s.setPlaying(false);+ setFrameMenu({ x: e.clientX, y: e.clientY, t: timeAt(e.clientX), ...grab });+ };+ // While the menu is open, the skimmer holds at the grab time in its darker+ // held state — the preview shows the frame the line marks, and HoverLine's+ // pointer listeners stand down so crossing onto the menu can't yank it.+ // On close the skimmer resumes right under the pointer (tracked while the+ // menu was up), or clears when the pointer has left the timeline.+ const menuPointer = useRef<{ x: number; y: number } | null>(null);+ useEffect(() => {+ if (!frameMenu) return;+ const scrollEl = scrollRef.current;+ menuPointer.current = { x: frameMenu.x, y: frameMenu.y };+ const track = (e: PointerEvent) => {+ menuPointer.current = { x: e.clientX, y: e.clientY };+ };+ window.addEventListener("pointermove", track);+ useEditor.getState().setSkimTime(frameMenu.t);+ return () => {+ window.removeEventListener("pointermove", track);+ const p = menuPointer.current;+ const r = scrollEl?.getBoundingClientRect();+ const inside =+ !!p && !!r && p.x >= r.left && p.x <= r.right && p.y >= r.top && p.y <= r.bottom;+ useEditor.getState().setSkimTime(inside ? Math.max(0, timeAt(p.x)) : null);+ };+ // eslint-disable-next-line react-hooks/exhaustive-deps -- timeAt reads live refs+ }, [frameMenu]);+// Title tracks: overlays carry a `lane`; used lanes compact to contiguous// display rows, so empty tracks disappear on their own.const overlayLanes = useMemo(() => {@@ -603,11 +661,6 @@ export function Timeline() {[audioLanes.count]);- const timeAt = (clientX: number) => {- const rect = innerRef.current!.getBoundingClientRect();- return (clientX - rect.left) / pps;- };-// Where a dropped asset should land. An empty timeline has no arrangement to// read a position against, so the drop starts the film at 0 no matter where// the cursor released.@@ -1260,6 +1313,7 @@ export function Timeline() {onCrossMove={previewCross}onCrossDrop={onOverlayCrossDrop}onDragActive={setVideoDragging}+ onFrameMenu={openFrameMenu}/>))}{laneDrag?.kind !== "overlayClip" && (@@ -1344,6 +1398,7 @@ export function Timeline() {onCrossMove={previewCross}onCrossDrop={onClipCrossDrop}onDragActive={setVideoDragging}+ onFrameMenu={openFrameMenu}/>))}{laneDrag?.kind !== "clip" && (@@ -1550,7 +1605,12 @@ export function Timeline() {style={{ left: snapX }}/>)}- <HoverLine scrollRef={scrollRef} innerRef={innerRef} pps={pps} />+ <HoverLine+ scrollRef={scrollRef}+ innerRef={innerRef}+ pps={pps}+ hold={frameMenu !== null}+ /><Playhead pps={pps} scrollRef={scrollRef} onScrub={scrub} /></div></div>@@ -1717,6 +1777,62 @@ export function Timeline() {</div></div>)}+ {frameMenu && (+ <div+ className="fixed inset-0 z-50"+ onPointerDown={() => setFrameMenu(null)}+ onContextMenu={(e) => {+ e.preventDefault();+ setFrameMenu(null);+ }}+ >+ {/* A snug bubble beside the held marker line, speech-balloon style:+ its tapered tip sits on the side edge facing the line, apex+ touching it at the grab point. The bubble hangs to the line's+ right and flips left when the window edge is close. */}+ {(() => {+ const flip = frameMenu.x + 240 > window.innerWidth;+ return (+ <div+ className={cn(+ "group absolute -translate-y-1/2",+ flip ? "pr-[6px]" : "pl-[6px]"+ )}+ style={{+ top: frameMenu.y,+ ...(flip+ ? { right: window.innerWidth - frameMenu.x }+ : { left: frameMenu.x }),+ }}+ onPointerDown={(e) => e.stopPropagation()}+ >+ <button+ className="flex items-center gap-2 rounded-lg border bg-popover px-3 py-1.5 text-sm whitespace-nowrap text-popover-foreground shadow-md group-hover:bg-accent group-hover:text-accent-foreground"+ onClick={() => {+ void sendFrameToChat(+ { ...refFromAsset(frameMenu.asset), t: frameMenu.srcT },+ frameMenu.from+ );+ setFrameMenu(null);+ }}+ >+ <Fullscreen className="size-3.5 text-muted-foreground" /> Capture frame+ </button>+ {/* Drawn after the bubble so the diamond's inner half covers+ its border along the notch, leaving one seamless outline. */}+ <div+ className={cn(+ "pointer-events-none absolute top-1/2 size-2.5 -translate-y-1/2 rotate-45 bg-popover group-hover:bg-accent",+ flip+ ? "right-[2px] rounded-tr-[2px] border-t border-r"+ : "left-[2px] rounded-bl-[2px] border-b border-l"+ )}+ />+ </div>+ );+ })()}+ </div>+ )}</footer>);}@@ -1729,15 +1845,20 @@ function HoverLine({scrollRef,innerRef,pps,+ hold,}: {scrollRef: React.RefObject<HTMLDivElement | null>;innerRef: React.RefObject<HTMLDivElement | null>;pps: number;+ /** The frame-grab menu owns the skim: the skimmer neither moves nor clears+ * it, and the line darkens — the marker is the skimmer, held. */+ hold: boolean;}) {const skimTime = useEditor((s) => s.skimTime);+ useEffect(() => () => useEditor.getState().setSkimTime(null), []);useEffect(() => {const el = scrollRef.current;- if (!el) return;+ if (!el || hold) return;const move = (e: PointerEvent) => {const inner = innerRef.current;const s = useEditor.getState();@@ -1751,13 +1872,15 @@ function HoverLine({return () => {el.removeEventListener("pointermove", move);el.removeEventListener("pointerleave", leave);- useEditor.getState().setSkimTime(null);};- }, [scrollRef, innerRef]);+ }, [scrollRef, innerRef, hold]);if (skimTime === null) return null;return (<div- className="tl-hover-line pointer-events-none absolute top-0 bottom-0 z-30 w-px bg-foreground/30"+ className={cn(+ "tl-hover-line pointer-events-none absolute top-0 bottom-0 z-30 w-px",+ hold ? "bg-foreground/70" : "bg-foreground/30"+ )}style={{ transform: `translateX(${skimTime * pps}px)` }}/>);@@ -2139,6 +2262,7 @@ function ClipView({onCrossMove,onCrossDrop,onDragActive,+ onFrameMenu,}: {span: ClipSpan;/** Cross-dissolve overlap of the previous clip into this one, timeline@@ -2164,6 +2288,11 @@ function ClipView({onCrossDrop: (id: string, target: TrackTarget, start: number) => void;/** Toggle the between-track insertion zones while this clip is dragging. */onDragActive: (active: boolean) => void;+ /** Right-click: offer the frame under the pointer to the chat composer. */+ onFrameMenu: (+ e: React.MouseEvent,+ grab: { asset: MediaAsset; srcT: number; from: FrameGrabOrigin }+ ) => void;}) {const { clip, asset } = span;const speed = clipSpeed(clip);@@ -2234,6 +2363,15 @@ function ClipView({zIndex: drag ? 20 : undefined,}}onPointerDown={(e) => startLaneMove(e, "clip", clip.id, ui)}+ onContextMenu={(e) => {+ if (asset.type !== "video") return;+ const rect = e.currentTarget.getBoundingClientRect();+ onFrameMenu(e, {+ asset,+ srcT: filmIn + ((e.clientX - rect.left) / pps) * speed,+ from: { x: e.clientX, top: rect.top, height: rect.height },+ });+ }}><Filmstrip frames={filmstrip} grade={clip.grade} />{selected && (@@ -2759,6 +2897,7 @@ function OverlayClipView({onCrossMove,onCrossDrop,onDragActive,+ onFrameMenu,}: {clip: VideoClip;asset: MediaAsset | undefined;@@ -2779,6 +2918,11 @@ function OverlayClipView({onCrossMove: (target: TrackTarget | null, start?: number, len?: number) => void;onCrossDrop: (id: string, target: TrackTarget, start: number) => void;onDragActive: (active: boolean) => void;+ /** Right-click: offer the frame under the pointer to the chat composer. */+ onFrameMenu: (+ e: React.MouseEvent,+ grab: { asset: MediaAsset; srcT: number; from: FrameGrabOrigin }+ ) => void;}) {// A cross-dissolve overlaps two clips; inset each box by half the overlap// so the pair meets at the overlap midpoint with the same CLIP_GAP gutter@@ -2851,6 +2995,15 @@ function OverlayClipView({zIndex: drag ? 20 : undefined,}}onPointerDown={(e) => startLaneMove(e, "overlayClip", clip.id, ui)}+ onContextMenu={(e) => {+ if (asset.type !== "video") return;+ const rect = e.currentTarget.getBoundingClientRect();+ onFrameMenu(e, {+ asset,+ srcT: filmIn + ((e.clientX - rect.left) / pps) * speed,+ from: { x: e.clientX, top: rect.top, height: rect.height },+ });+ }}><Filmstrip frames={filmstrip} grade={clip.grade} />{selected && (diff --git a/site/src/cut/lib/chatIntake.ts b/site/src/cut/lib/chatIntake.tsnew file mode 100644index 00000000..207dcca5--- /dev/null+++ b/site/src/cut/lib/chatIntake.ts@@ -0,0 +1,173 @@+"use client";++import type { AssetRef } from "./assetRef";+import { refToInlineImage } from "./refMedia";+import { useEditor } from "./store";+import { formatTime } from "./time";++// The chat composer registers itself here so surfaces outside the AI panel —+// the timeline's "Add video frame to chat" — can land a ref among the open+// thread's attachments and aim the hand-off animation at the composer box.++interface ChatIntake {+ el: HTMLElement;+ add: (ref: AssetRef) => void;+ /** Signal that a grab is in flight, so the composer opens its chip row+ * early — rising in anticipation to catch the frame before it lands. */+ expect?: (incoming: boolean) => void;+ /** Whether the composer takes another grabbed frame. At the render models'+ * reference capacity it declines — surfacing why in its own notice tab —+ * and the grab ends before any capture or flight. */+ acceptFrame?: () => boolean;+}++let intake: ChatIntake | null = null;++/** Mount the open chat composer as the intake; returns the unregister. */+export function registerChatIntake(entry: ChatIntake): () => void {+ intake = entry;+ return () => {+ if (intake === entry) intake = null;+ };+}++/** The composer once it exists. Opening the AI panel mounts it a beat later,+ * so a grab waits briefly; a read-only share never mounts one and times out. */+function waitForIntake(timeoutMs = 1500): Promise<ChatIntake | null> {+ return new Promise((resolve) => {+ const t0 = performance.now();+ const check = () => {+ if (intake) return resolve(intake);+ if (performance.now() - t0 > timeoutMs) return resolve(null);+ requestAnimationFrame(check);+ };+ check();+ });+}++/** Where the flight starts: the grab point and the clip box's vertical+ * extent, viewport coordinates. */+export interface FrameGrabOrigin {+ x: number;+ top: number;+ height: number;+}++const FLY_MS = 520;+// The chip the frame settles into: RefChips' size-14 thumb, sitting inside+// the composer box's padding.+const CHIP = 56;+const CHIP_INSET = 10;+// RefChips' gap-2, between chips and between wrapped rows.+const CHIP_GAP = 8;++/** Where the incoming chip will mount, in the coordinates the composer will+ * occupy once its anticipation growth (the row opening for this very grab)+ * has finished — the box is bottom-anchored, so growing raises its top edge.+ * Measured before the chip mounts, so the flight ends exactly where the list+ * is about to grow: after the last chip in its row, or — when the row is+ * full — at the head of the wrapped row, which lands where the last row+ * stood once the box has risen by one row. The first chip's slot is the+ * opened row's padding corner, one row above today's top edge. */+function nextChipSlot(box: DOMRect, composer: HTMLElement): { left: number; top: number } {+ const chips = composer.querySelectorAll(".ref-chip");+ const last = chips[chips.length - 1]?.getBoundingClientRect();+ if (!last) return { left: box.left + CHIP_INSET, top: box.top - CHIP };+ if (last.right + CHIP_GAP + CHIP > box.right - CHIP_INSET) {+ return { left: box.left + CHIP_INSET, top: last.top };+ }+ return { left: last.right + CHIP_GAP, top: last.top };+}++/** Land the frame `ref` pins among the chat composer's attachments, flying it+ * from the timeline into the composer on the way. Each grab delivers its own+ * image attachment — the captured frame riding inline, named by its video and+ * timestamp — so several frames of the same video sit side by side as chips.+ * Opens the AI panel when it is closed. */+export async function sendFrameToChat(ref: AssetRef, from: FrameGrabOrigin): Promise<void> {+ const s = useEditor.getState();+ if (!s.aiOpen) s.setAiOpen(true);+ const target = await waitForIntake();+ if (!target) return;+ if (target.acceptFrame && !target.acceptFrame()) return;+ // Capture before the flight so it shows the exact frame it delivers.+ const frame = await refToInlineImage(ref).catch(() => null);+ if (!frame) {+ target.add(ref);+ return;+ }+ const frameRef: AssetRef = {+ scope: "file",+ id: crypto.randomUUID().slice(0, 8),+ name: `${ref.name} @ ${formatTime(ref.t ?? 0)}`,+ kind: "image",+ url: `data:${frame.mimeType};base64,${frame.data}`,+ };++ const img = new Image();+ img.src = `data:${frame.mimeType};base64,${frame.data}`;+ await img.decode().catch(() => {});+ const aspect =+ img.naturalWidth > 0 && img.naturalHeight > 0 ? img.naturalWidth / img.naturalHeight : 16 / 9;++ const h0 = from.height;+ const w0 = h0 * aspect;+ // Measure before the row starts opening, then tell the composer a frame is+ // inbound: it rises to present the slot while the frame is still flying.+ const box = target.el.getBoundingClientRect();+ const slot = nextChipSlot(box, target.el);+ target.expect?.(true);+ const fly = document.createElement("div");+ Object.assign(fly.style, {+ position: "fixed",+ left: `${from.x - w0 / 2}px`,+ top: `${from.top}px`,+ width: `${w0}px`,+ height: `${h0}px`,+ zIndex: "100",+ pointerEvents: "none",+ overflow: "hidden",+ borderRadius: "8px",+ boxShadow: "0 12px 32px rgba(0,0,0,0.35)",+ background: "#000",+ });+ Object.assign(img.style, {+ display: "block",+ width: "100%",+ height: "100%",+ objectFit: "cover",+ });+ fly.appendChild(img);+ document.body.appendChild(fly);++ const flight = fly.animate(+ [+ {+ left: `${from.x - w0 / 2}px`,+ top: `${from.top}px`,+ width: `${w0}px`,+ height: `${h0}px`,+ borderRadius: "8px",+ },+ {+ left: `${slot.left}px`,+ top: `${slot.top}px`,+ width: `${CHIP}px`,+ height: `${CHIP}px`,+ borderRadius: "10px",+ },+ ],+ { duration: FLY_MS, easing: "cubic-bezier(0.32, 0.72, 0, 1)", fill: "forwards" }+ );+ await flight.finished.catch(() => {});+ // The chip mounts under the settled thumb, then the thumb fades off it.+ target.add(frameRef);+ target.expect?.(false);+ const fade = fly.animate([{ opacity: 1 }, { opacity: 0 }], {+ duration: 160,+ easing: "ease-out",+ fill: "forwards",+ });+ await fade.finished.catch(() => {});+ fly.remove();+}diff --git a/site/src/cut/lib/laneTracks.ts b/site/src/cut/lib/laneTracks.tsindex b2ab59ee..679af118 100644--- a/site/src/cut/lib/laneTracks.ts+++ b/site/src/cut/lib/laneTracks.ts@@ -345,6 +345,9 @@ export function startLaneMove<V = unknown>(id: string,ui: LaneMoveUI<V>) {+ // Primary button only: a right-click belongs to the clip's context menu and+ // must leave selection and the playhead where they are.+ if (e.button !== 0) return;settleSnapBack();const s = useEditor.getState();if (e.metaKey || e.shiftKey) {@@ -588,6 +591,8 @@ export function startLaneTrim(side: "l" | "r",ui: LaneTrimUI) {+ // Primary button only, same as the move grab.+ if (e.button !== 0) return;settleSnapBack();const s = useEditor.getState();if (s.readOnly) return;